Skip to contentSkip to conversation

target/hexagon: Use explicit little-endian LD/ST API

PATCH In review Philippe Mathieu-Daudé 4 participants 10 messages Dec 24, 2025 – Jan 7

lore
Share & tools
lore
#0 lore raw

v3 cover target/hexagon: Use explicit little-endian LD/ST API

Hexagon is little-endian. Use the explicit 'little' endianness instead of the 'native' one. Forbid further uses of legacy APIs.

tag: https://gitlab.com/philmd/qemu/-/tags/endian_hexagon-v3
CI: https://gitlab.com/philmd/qemu/-/pipelines/2231223066

Philippe Mathieu-Daudé (3):
target/hexagon: Inline translator_ldl()
target/hexagon: Use little-endian variant of cpu_ld/st_data*() configs/targets: Forbid Hexagon to use legacy native endianness API

 configs/targets/hexagon-linux-user.mak |  1 +
 target/hexagon/macros.h                |  6 +++---
 target/hexagon/op_helper.c             |  6 +++---
 target/hexagon/translate.c             | 11 +++++++----
 4 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/3 target/hexagon: Inline translator_ldl()

translator_ldl() is defined in "exec/translator.h" as:

  198 static inline uint32_t
  199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
  200 {
  201     return translator_ldl_end(env, db, pc, MO_TE);
  202 }

Directly use the inlined form, expanding MO_TE -> MO_LE since Hexagon use little-endian order.

---
 target/hexagon/translate.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
target/hexagon/translate.c +7 -4
index 8fce219c0de..c37035c4774 100644
@@ -203,8 +203,9 @@ static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
     memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
         words[nwords] =
-            translator_ldl(env, &ctx->base,
-                           ctx->base.pc_next + nwords * sizeof(uint32_t));
+            translator_ldl_end(env, &ctx->base,
+                               ctx->base.pc_next + nwords * sizeof(uint32_t),
+                               MO_LE);
         found_end = is_packet_end(words[nwords]);
     }
     if (!found_end) {
@@ -966,8 +967,10 @@ static bool pkt_crosses_page(CPUHexagonState *env, DisasContext *ctx)
     int nwords;
 
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
-        uint32_t word = translator_ldl(env, &ctx->base,
-                            ctx->base.pc_next + nwords * sizeof(uint32_t));
+        uint32_t word = translator_ldl_end(env, &ctx->base,
+                                           ctx->base.pc_next
+                                           + nwords * sizeof(uint32_t),
+                                           MO_LE);
         found_end = is_packet_end(word);
     }
     uint32_t next_ptr =  ctx->base.pc_next + nwords * sizeof(uint32_t);
Signature · 1 line
2.52.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] target/hexagon: Inline translator_ldl()

Quoted 9 lines · Philippe Mathieu-Daudé

translator_ldl() is defined in "exec/translator.h" as:

  198 static inline uint32_t
  199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
  200 {
  201     return translator_ldl_end(env, db, pc, MO_TE);
  202 }
Quoted 5 lines

Directly use the inlined form, expanding MO_TE -> MO_LE since Hexagon use little-endian order.

---

Quoted 35 lines
 target/hexagon/translate.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
target/hexagon/translate.c +7 -5
index 8fce219c0de..c37035c4774 100644
@@ -203,8 +203,9 @@ static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
     memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
         words[nwords] =
-            translator_ldl(env, &ctx->base,
-                           ctx->base.pc_next + nwords * sizeof(uint32_t));
+            translator_ldl_end(env, &ctx->base,
+                               ctx->base.pc_next + nwords * sizeof(uint32_t),
+                               MO_LE);
         found_end = is_packet_end(words[nwords]);
     }
     if (!found_end) {
@@ -966,8 +967,10 @@ static bool pkt_crosses_page(CPUHexagonState *env, DisasContext *ctx)
     int nwords;
 
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
-        uint32_t word = translator_ldl(env, &ctx->base,
-                            ctx->base.pc_next + nwords * sizeof(uint32_t));
+        uint32_t word = translator_ldl_end(env, &ctx->base,
+                                           ctx->base.pc_next
+                                           + nwords * sizeof(uint32_t),
+                                           MO_LE);
         found_end = is_packet_end(word);
     }
     uint32_t next_ptr =  ctx->base.pc_next + nwords * sizeof(uint32_t);
--

2.52.0

Reviewed-by on v3 1/3
#3 lore raw

Re: [PATCH v3 1/3] target/hexagon: Inline translator_ldl()

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

translator_ldl() is defined in "exec/translator.h" as:

   198 static inline uint32_t
   199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
   200 {
   201     return translator_ldl_end(env, db, pc, MO_TE);
   202 }
Quoted 7 lines

Directly use the inlined form, expanding MO_TE -> MO_LE since Hexagon use little-endian order.

---
  target/hexagon/translate.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)

r~

Reviewed-by on v3 1/3
#4 lore raw

Re: [PATCH v3 1/3] target/hexagon: Inline translator_ldl()

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

translator_ldl() is defined in "exec/translator.h" as:

  198 static inline uint32_t
  199 translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
  200 {
  201     return translator_ldl_end(env, db, pc, MO_TE);
  202 }
Quoted 6 lines

Directly use the inlined form, expanding MO_TE -> MO_LE since Hexagon use little-endian order.

---

 target/hexagon/translate.c | 11 +++++++----
Quoted 39 lines
 1 file changed, 7 insertions(+), 4 deletions(-)
target/hexagon/translate.c +3 -2
index 8fce219c0de..c37035c4774 100644
@@ -203,8 +203,9 @@ static int read_packet_words(CPUHexagonState *env,
 DisasContext *ctx,
     memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
         words[nwords] =
-            translator_ldl(env, &ctx->base,
-                           ctx->base.pc_next + nwords * sizeof(uint32_t));
+            translator_ldl_end(env, &ctx->base,
+                               ctx->base.pc_next + nwords *
 sizeof(uint32_t),
+                               MO_LE);
         found_end = is_packet_end(words[nwords]);
     }
     if (!found_end) {
target/hexagon/translate.c +4 -2
@@ -966,8 +967,10 @@ static bool pkt_crosses_page(CPUHexagonState *env,
 DisasContext *ctx)
     int nwords;
 
     for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
-        uint32_t word = translator_ldl(env, &ctx->base,
-                            ctx->base.pc_next + nwords *
 sizeof(uint32_t));
+        uint32_t word = translator_ldl_end(env, &ctx->base,
+                                           ctx->base.pc_next
+                                           + nwords * sizeof(uint32_t),
+                                           MO_LE);
         found_end = is_packet_end(word);
     }
     uint32_t next_ptr =  ctx->base.pc_next + nwords * sizeof(uint32_t);

--
2.52.0

#5 lore raw

PATCH v3 2/3 target/hexagon: Use little-endian variant of cpu_ld/st_data*()

In reply to Philippe Mathieu-Daudé

We only build the Hexagon target using little endianness order, therefore the cpu_ld/st_data*() definitions expand to the little endian declarations. Use the explicit little-endian variants.

Mechanical change running:

  $ tgt=hexagon; \
    end=le; \
    for op in data mmuidx_ra; do \
      for ac in uw sw l q; do \
        sed -i -e "s/cpu_ld${ac}_${op}/cpu_ld${ac}_${end}_${op}/" \
                  $(git grep -l cpu_ target/${tgt}/); \
      done;
      for ac in w l q; do \
        sed -i -e "s/cpu_st${ac}_${op}/cpu_st${ac}_${end}_${op}/" \
                  $(git grep -l cpu_ target/${tgt}/); \
      done;
    done
---
 target/hexagon/macros.h    | 6 +++---
 target/hexagon/op_helper.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
target/hexagon/macros.h +3 -3
index 088e5961ab7..6c2862a2320 100644
@@ -519,9 +519,9 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)
 #define fLOAD(NUM, SIZE, SIGN, EA, DST) MEM_LOAD##SIZE##SIGN(DST, EA)
 #else
 #define MEM_LOAD1 cpu_ldub_data_ra
-#define MEM_LOAD2 cpu_lduw_data_ra
-#define MEM_LOAD4 cpu_ldl_data_ra
-#define MEM_LOAD8 cpu_ldq_data_ra
+#define MEM_LOAD2 cpu_lduw_le_data_ra
+#define MEM_LOAD4 cpu_ldl_le_data_ra
+#define MEM_LOAD8 cpu_ldq_le_data_ra
 
 #define fLOAD(NUM, SIZE, SIGN, EA, DST) \
     do { \
target/hexagon/op_helper.c +3 -3
index e2e80ca7efa..08db1e9c56b 100644
@@ -77,13 +77,13 @@ static void commit_store(CPUHexagonState *env, int slot_num, uintptr_t ra)
         cpu_stb_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
         break;
     case 2:
-        cpu_stw_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        cpu_stw_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
         break;
     case 4:
-        cpu_stl_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
+        cpu_stl_le_data_ra(env, va, env->mem_log_stores[slot_num].data32, ra);
         break;
     case 8:
-        cpu_stq_data_ra(env, va, env->mem_log_stores[slot_num].data64, ra);
+        cpu_stq_le_data_ra(env, va, env->mem_log_stores[slot_num].data64, ra);
         break;
     default:
         g_assert_not_reached();
Signature · 1 line
2.52.0
#6 lore raw

PATCH v3 3/3 configs/targets: Forbid Hexagon to use legacy native endianness API

In reply to Philippe Mathieu-Daudé

The qemu-hexagon binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

Preliminary commits allowing this final change:

- beb38fda0f0 target/hexagon: Replace MO_TE -> MO_LE
- fdcb7483ae0 target/hexagon: Explode MO_TExx -> MO_TE | MO_xx

---
 configs/targets/hexagon-linux-user.mak | 1 +
 1 file changed, 1 insertion(+)
configs/targets/hexagon-linux-user.mak +1 -0
index aec1a04d1b4..6763e2111d5 100644
@@ -3,3 +3,4 @@ TARGET_XML_FILES=gdb-xml/hexagon-core.xml gdb-xml/hexagon-hvx.xml
 TARGET_SYSTBL=syscall.tbl
 TARGET_SYSTBL_ABI=common,32,hexagon,time32,stat64,rlimit,renameat
 TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0
Reviewed-by on v3 3/3
#7 lore raw

Re: [PATCH v3 3/3] configs/targets: Forbid Hexagon to use legacy native endianness API

Quoted 6 lines · Philippe Mathieu-Daudé

The qemu-hexagon binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

Quoted 7 lines

Preliminary commits allowing this final change:

- beb38fda0f0 target/hexagon: Replace MO_TE -> MO_LE
- fdcb7483ae0 target/hexagon: Explode MO_TExx -> MO_TE | MO_xx

---

Quoted 15 lines
 configs/targets/hexagon-linux-user.mak | 1 +
 1 file changed, 1 insertion(+)
configs/targets/hexagon-linux-user.mak +1 -1
index aec1a04d1b4..6763e2111d5 100644
@@ -3,3 +3,4 @@ TARGET_XML_FILES=gdb-xml/hexagon-core.xml gdb-xml/hexagon-hvx.xml
 TARGET_SYSTBL=syscall.tbl
 TARGET_SYSTBL_ABI=common,32,hexagon,time32,stat64,rlimit,renameat
 TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
--

2.52.0

Reviewed-by on v3 3/3
#8 lore raw

Re: [PATCH v3 3/3] configs/targets: Forbid Hexagon to use legacy native endianness API

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

The qemu-hexagon binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

Preliminary commits allowing this final change:

Quoted 7 lines

- beb38fda0f0 target/hexagon: Replace MO_TE -> MO_LE
- fdcb7483ae0 target/hexagon: Explode MO_TExx -> MO_TE | MO_xx

---
  configs/targets/hexagon-linux-user.mak | 1 +
  1 file changed, 1 insertion(+)

r~

Reviewed-by on v3 3/3
#9 lore raw

Re: [PATCH v3 3/3] configs/targets: Forbid Hexagon to use legacy native endianness API

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

The qemu-hexagon binary is buildable without a single use of the legacy "native endian" API. Unset the transitional TARGET_USE_LEGACY_NATIVE_ENDIAN_API definition to forbid further uses of the legacy API.

Quoted 8 lines

Preliminary commits allowing this final change:

- beb38fda0f0 target/hexagon: Replace MO_TE -> MO_LE
- fdcb7483ae0 target/hexagon: Explode MO_TExx -> MO_TE | MO_xx

---

 configs/targets/hexagon-linux-user.mak | 1 +
Quoted 17 lines
 1 file changed, 1 insertion(+)
configs/targets/hexagon-linux-user.mak +0 -0
index aec1a04d1b4..6763e2111d5 100644
@@ -3,3 +3,4 @@ TARGET_XML_FILES=gdb-xml/hexagon-core.xml

gdb-xml/hexagon-hvx.xml
TARGET_SYSTBL=syscall.tbl TARGET_SYSTBL_ABI=common,32,hexagon,time32,stat64,rlimit,renameat TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
--
2.52.0