Skip to contentSkip to conversation

target/hexagon: Stop using the legacy native-endian APIs

PATCH Superseded Philippe Mathieu-Daudé 1 participant 5 messages Dec 19, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover target/hexagon: Stop using the legacy native-endian APIs

Hexagon is always little-endian, making the conversion easy.

Besides a lot of preliminary cleanup are already merged:

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

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/op_helper.c             |  6 +++---
 target/hexagon/translate.c             | 11 +++++++----
 3 files changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 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
#2 lore raw

PATCH 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=be; \
    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/op_helper.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
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
#3 lore raw

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

Quoted 19 lines · 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=be; \
     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
Quoted 4 lines
---
  target/hexagon/op_helper.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

I did something wrong while rebasing... Part of the original patch is missing:
https://lore.kernel.org/qemu-devel/[email protected]/

I'll repost.

#4 lore raw

PATCH 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.

---
 configs/targets/hexagon-linux-user.mak | 1 -
 1 file changed, 1 deletion(-)
configs/targets/hexagon-linux-user.mak +0 -1
index fc09ae96a54..aec1a04d1b4 100644
@@ -3,4 +3,3 @@ 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_USE_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0