Skip to contentSkip to conversation

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

PATCH New Philippe Mathieu-Daudé 1 participant 4 messages Dec 19, 2025

lore
Share & tools
lore
#0 lore raw

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

OpenRISC is always big-endian, making the conversion easy.

Besides a lot of preliminary cleanup are already merged:

. 5b67dbf1dc3 target/openrisc: Replace target_ulong -> uint32_t
. 500708331e3 target/openrisc: Inline tcg_gen_trunc_i64_tl()
. 4f6c60683f2 target/openrisc: Replace MO_TE -> MO_BE
. 73cd283e58d target/openrisc: Introduce mo_endian() helper
. 2f737e19a4d target/openrisc: Conceal MO_TE within do_store()
. 22c36c0a20c target/openrisc: Conceal MO_TE within do_load()
. ef797ac0025 target/openrisc: Explode MO_TExx -> MO_TE | MO_xx
. 81e2fb236b7 target/openrisc: Remove 'TARGET_LONG_BITS != 32' dead code . 9dc4862dc4a target/openrisc: Use vaddr type for $pc jumps
. 2367c94cbb1 target/openrisc: Remove target_ulong use in raise_mmu_exception() . 1843e89bec5 target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers . a3c4facd395 target/openrisc: Do not use target_ulong for @mr in MTSPR helper . 2795bc52af4 target/openrisc: Replace VMSTATE_UINTTL() -> VMSTATE_UINT32()

Philippe Mathieu-Daudé (3):
target/openrisc: Use explicit big-endian LD/ST API target/openrisc: Inline translator_ldl()
configs/targets: Forbid OpenRISC to use legacy native endianness APIs

 configs/targets/or1k-linux-user.mak | 1 -
 configs/targets/or1k-softmmu.mak    | 1 -
 target/openrisc/gdbstub.c           | 2 +-
 target/openrisc/translate.c         | 3 ++-
 4 files changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/3 target/openrisc: Use explicit big-endian LD/ST API

The OpenRISC architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change running:

  $ for a in uw w l q; do \
      sed -i -e "s/ld${a}_p(/ld${a}_be_p(/" \
        $(git grep -wlE '(ld|st)u?[wlq]_p' target/openrisc/);
    done
---
 target/openrisc/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/gdbstub.c +1 -1
index 45bba80d878..ca1592c6200 100644
@@ -50,7 +50,7 @@ int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUOpenRISCState *env = cpu_env(cs);
     uint32_t tmp;
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_be_p(mem_buf);
 
     if (n < 32) {
         cpu_set_gpr(env, n, tmp);
Signature · 1 line
2.52.0
#2 lore raw

PATCH 2/3 target/openrisc: Inline translator_ldl()

In reply to 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 }

Directly use the inlined form, expanding MO_TE -> MO_BE since we only build the OpenRISC targets as big-endian.

---
 target/openrisc/translate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/openrisc/translate.c +2 -1
index 6fa4d6cfa70..a6d550bbc2e 100644
@@ -1558,7 +1558,8 @@ static void openrisc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
 static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
 {
     DisasContext *dc = container_of(dcbase, DisasContext, base);
-    uint32_t insn = translator_ldl(cpu_env(cs), &dc->base, dc->base.pc_next);
+    uint32_t insn = translator_ldl_end(cpu_env(cs), &dc->base,
+                                       dc->base.pc_next, MO_BE);
 
     if (!decode(dc, insn)) {
         gen_illegal_exception(dc);
Signature · 1 line
2.52.0
#3 lore raw

PATCH 3/3 configs/targets: Forbid OpenRISC to use legacy native endianness APIs

In reply to Philippe Mathieu-Daudé

All OpenRISC-related binaries are 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/or1k-linux-user.mak | 1 -
 configs/targets/or1k-softmmu.mak    | 1 -
 2 files changed, 2 deletions(-)
configs/targets/or1k-linux-user.mak +0 -1
index 4cc6f2a6616..810567a98f9 100644
@@ -3,4 +3,3 @@ TARGET_BIG_ENDIAN=y
 TARGET_SYSTBL_ABI=common,32,or1k,time32,stat64,rlimit,renameat
 TARGET_SYSTBL=syscall.tbl
 TARGET_LONG_BITS=32
-TARGET_USE_LEGACY_NATIVE_ENDIAN_API=y
configs/targets/or1k-softmmu.mak +0 -1
index 5a8eb66cbc5..0e47d9878b0 100644
@@ -3,4 +3,3 @@ TARGET_BIG_ENDIAN=y
 # needed by boot.c and all boards
 TARGET_NEED_FDT=y
 TARGET_LONG_BITS=32
-TARGET_USE_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0