target/openrisc: Use explicit big-endian LD/ST API
cover target/openrisc: Use explicit big-endian LD/ST API
OpenRISC is big-endian. Use the explicit 'big'
endianness instead of the 'native' one.
Forbid further uses of legacy APIs.
tag: https://gitlab.com/philmd/qemu/-/tags/endian_openrisc-v1
CI: https://gitlab.com/philmd/qemu/-/pipelines/2231223066
Philippe Mathieu-Daudé (4):
hw/intc: Mark OpenRISC-specific peripheral as big-endian 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 + hw/intc/ompic.c | 2 +- target/openrisc/gdbstub.c | 2 +- target/openrisc/translate.c | 3 ++- 5 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/4 hw/intc: Mark OpenRISC-specific peripheral as big-endian
The Open Multi-Processor Interrupt Controller (ompic) is only used by the OpenRISC target, which is only built as big-endian. Therefore the DEVICE_NATIVE_ENDIAN definition expand to DEVICE_BIG_ENDIAN (besides, the DEVICE_LITTLE_ENDIAN case isn't tested). Simplify directly using DEVICE_BIG_ENDIAN.
--- hw/intc/ompic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/ompic.c +1 -1
@@ -96,7 +96,7 @@ static void ompic_write(void *opaque, hwaddr addr, uint64_t data, unsigned size)static const MemoryRegionOps ompic_ops = { .read = ompic_read, .write = ompic_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_BIG_ENDIAN , .impl = { .max_access_size =8 , },
Signature · 1 line
2.52.0
Re: [PATCH 1/4] hw/intc: Mark OpenRISC-specific peripheral as big-endian
Quoted 9 lines · Philippe Mathieu-Daudé
The Open Multi-Processor Interrupt Controller (ompic) is only used by the OpenRISC target, which is only built as big-endian. Therefore the
DEVICE_NATIVE_ENDIANdefinition expand toDEVICE_BIG_ENDIAN(besides, theDEVICE_LITTLE_ENDIANcase isn't tested). Simplify directly usingDEVICE_BIG_ENDIAN.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 19 lines
hw/intc/ompic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/intc/ompic.c +1
-2@@ -96,7 +96,7 @@ static void ompic_write(void *opaque, hwaddr addr, uint64_t data, unsigned size)static const MemoryRegionOps ompic_ops = { .read = ompic_read, .write = ompic_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_BIG_ENDIAN , .impl = { .max_access_size =8 , }, --2.52.0
Re: [PATCH 1/4] hw/intc: Mark OpenRISC-specific peripheral as big-endian
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
The Open Multi-Processor Interrupt Controller (ompic) is only used by the OpenRISC target, which is only built as big-endian. Therefore the
DEVICE_NATIVE_ENDIANdefinition expand toDEVICE_BIG_ENDIAN(besides, theDEVICE_LITTLE_ENDIANcase isn't tested). Simplify directly usingDEVICE_BIG_ENDIAN.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/intc/ompic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 2/4 target/openrisc: Use explicit big-endian LD/ST API
In reply to Philippe Mathieu-Daudé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
@@ -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
Quoted 6 lines · Philippe Mathieu-Daudé
The OpenRISC architecture uses big endianness. Directly use the big-endian LD/ST API.
Mechanical change running:
Quoted 7 lines
$ 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/); doneSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 19 lines
target/openrisc/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/openrisc/gdbstub.c +1
-2@@ -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); --2.52.0
Quoted 10 lines · Philippe Mathieu-Daudé
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
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/openrisc/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 3/4 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
@@ -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
Re: [PATCH 3/4] target/openrisc: 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_BEsince we only build the OpenRISC targets as big-endian.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 20 lines
target/openrisc/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/openrisc/translate.c +2
-2@@ -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); --2.52.0
Re: [PATCH 3/4] target/openrisc: Inline translator_ldl()
In reply to Philippe Mathieu-DaudéQuoted 21 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 }Directly use the inlined form, expanding
MO_TE->MO_BEsince we only build the OpenRISC targets as big-endian.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/openrisc/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/openrisc/translate.c +0
-0
target/openrisc/translate.c static void openrisc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) · line 1565
Quoted 9 lines
target/openrisc/translate.c +2
-1@@ -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);
Use mo_endian(). With that,
r~
Re: [PATCH 3/4] target/openrisc: Inline translator_ldl()
Quoted 27 lines · Richard Henderson
Quoted 26 lines · Philippe Mathieu-Daudé
translator_ldl()is defined in "exec/translator.h" as:198 static inline
uint32_t
199translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)200 {
201 returntranslator_ldl_end(env, db, pc, MO_TE); 202 }Directly use the inlined form, expanding
MO_TE->MO_BEsince we only build the OpenRISC targets as big-endian.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/openrisc/translate.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)target/openrisc/translate.c +0
-1@@ -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-
Quoted 7 lines
Quoted 5 lines
target/openrisc/translate.c +2
-0>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);Use mo_endian(). With that,
Oops!
Quoted 2 lines
Reviewed-by Richard Henderson <[email protected]>
Thanks!
PATCH 4/4 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.
Preliminary commits allowing this final change:
. 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()
--- configs/targets/or1k-linux-user.mak | 1 + configs/targets/or1k-softmmu.mak | 1 + 2 files changed, 2 insertions(+)
configs/targets/or1k-linux-user.mak +1 -0
@@ -3,3 +3,4 @@ TARGET_BIG_ENDIAN=y TARGET_SYSTBL_ABI=common,32,or1k,time32,stat64,rlimit,renameat TARGET_SYSTBL=syscall.tbl TARGET_LONG_BITS=32 +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
configs/targets/or1k-softmmu.mak +1 -0
@@ -4,3 +4,4 @@ TARGET_BIG_ENDIAN=y TARGET_NEED_FDT=y TARGET_LONG_BITS=32 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0
Re: [PATCH 4/4] configs/targets: Forbid OpenRISC to use legacy native endianness APIs
Quoted 22 lines · 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_APIdefinition to forbid further uses of the legacy API.Preliminary commits allowing this final change:
.
5b67dbf1dc3target/openrisc: Replacetarget_ulong->uint32_t
.500708331e3target/openrisc: Inlinetcg_gen_trunc_i64_tl()
.4f6c60683f2target/openrisc: ReplaceMO_TE->MO_BE
.73cd283e58dtarget/openrisc: Introducemo_endian()helper
.2f737e19a4dtarget/openrisc: ConcealMO_TEwithindo_store()
.22c36c0a20ctarget/openrisc: ConcealMO_TEwithindo_load()
.ef797ac0025target/openrisc: ExplodeMO_TExx->MO_TE|MO_xx
.81e2fb236b7target/openrisc: Remove 'TARGET_LONG_BITS!= 32' dead code .9dc4862dc4atarget/openrisc: Use vaddr type for $pc jumps
.2367c94cbb1target/openrisc: Removetarget_ulonguse inraise_mmu_exception().1843e89bec5target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers .a3c4facd395target/openrisc: Do not usetarget_ulongfor @mr in MTSPR helper .2795bc52af4target/openrisc: ReplaceVMSTATE_UINTTL()->VMSTATE_UINT32()
Quoted 2 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Quoted 25 lines
configs/targets/or1k-linux-user.mak | 1 + configs/targets/or1k-softmmu.mak | 1 + 2 files changed, 2 insertions(+)configs/targets/or1k-linux-user.mak +1
-0@@ -3,3 +3,4 @@ TARGET_BIG_ENDIAN=y TARGET_SYSTBL_ABI=common,32,or1k,time32,stat64,rlimit,renameat TARGET_SYSTBL=syscall.tbl TARGET_LONG_BITS=32 +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=yconfigs/targets/or1k-softmmu.mak +1
-1@@ -4,3 +4,4 @@ TARGET_BIG_ENDIAN=y TARGET_NEED_FDT=y TARGET_LONG_BITS=32 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y --2.52.0
Re: [PATCH 4/4] configs/targets: Forbid OpenRISC to use legacy native endianness APIs
In reply to Philippe Mathieu-DaudéQuoted 21 lines · 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_APIdefinition to forbid further uses of the legacy API.Preliminary commits allowing this final change:
.
5b67dbf1dc3target/openrisc: Replacetarget_ulong->uint32_t
.500708331e3target/openrisc: Inlinetcg_gen_trunc_i64_tl()
.4f6c60683f2target/openrisc: ReplaceMO_TE->MO_BE
.73cd283e58dtarget/openrisc: Introducemo_endian()helper
.2f737e19a4dtarget/openrisc: ConcealMO_TEwithindo_store()
.22c36c0a20ctarget/openrisc: ConcealMO_TEwithindo_load()
.ef797ac0025target/openrisc: ExplodeMO_TExx->MO_TE|MO_xx
.81e2fb236b7target/openrisc: Remove 'TARGET_LONG_BITS!= 32' dead code .9dc4862dc4atarget/openrisc: Use vaddr type for $pc jumps
.2367c94cbb1target/openrisc: Removetarget_ulonguse inraise_mmu_exception().1843e89bec5target/openrisc: Remove unused cpu_openrisc_map_address_*() handlers .a3c4facd395target/openrisc: Do not usetarget_ulongfor @mr in MTSPR helper .2795bc52af4target/openrisc: ReplaceVMSTATE_UINTTL()->VMSTATE_UINT32()
Quoted 5 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- configs/targets/or1k-linux-user.mak | 1 + configs/targets/or1k-softmmu.mak | 1 + 2 files changed, 2 insertions(+)
r~