target/alpha: Use explicit little-endian LD/ST API
v2 cover target/alpha: Use explicit little-endian LD/ST API
Missing review: #5 & #6
Since v1: Add mo_endian() with comment
Alpha is little-endian. Use the explicit 'little'
endianness instead of the 'native' one.
Replace legacy ld/st_phys() calls. Forbid further
uses of legacy APIs.
Philippe Mathieu-Daudé (8):
hw/alpha: Use explicit little-endian LD/ST API target/alpha: Use explicit little-endian LD/ST API target/alpha: Inline cpu_ldl_code() call in do_unaligned_access() target/alpha: Inline translator_ldl()
target/alpha: Factor mo_endian() helper out target/alpha: Replace MO_TE -> MO_LE
configs/targets: Forbid Alpha to use legacy native endianness APIs target/alpha: Replace legacy ld_phys() -> address_space_ld()
configs/targets/alpha-linux-user.mak | 2 ++ configs/targets/alpha-softmmu.mak | 2 ++ hw/alpha/dp264.c | 11 +++++------ hw/alpha/typhoon.c | 4 ++-- target/alpha/helper.c | 28 +++++++++++++++++----------- target/alpha/mem_helper.c | 4 +++- target/alpha/translate.c | 13 +++++++++++-- 7 files changed, 42 insertions(+), 22 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/8 hw/alpha: Use explicit little-endian LD/ST API
The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.
Mechanical change running:
$ for a in uw w l q; do \
sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
$(git grep -wlE '(ld|st)u?[wlq]_p' hw/alpha/);
done--- hw/alpha/dp264.c | 11 +++++------ hw/alpha/typhoon.c | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-)
hw/alpha/dp264.c +5 -6
@@ -194,12 +194,11 @@ static void clipper_init(MachineState *machine)load_image_targphys (initrd_filename, initrd_base, ram_size - initrd_base,NULL ); -address_space_stq (&address_space_memory, param_offset +0x100 , - initrd_base +0xfffffc0000000000ULL , -MEMTXATTRS_UNSPECIFIED , -NULL ); -address_space_stq (&address_space_memory, param_offset +0x108 , - initrd_size,MEMTXATTRS_UNSPECIFIED ,NULL ); +address_space_stq_le (&address_space_memory, param_offset +0x100 , + initrd_base +0xfffffc0000000000ULL , +MEMTXATTRS_UNSPECIFIED ,NULL ); +address_space_stq_le (&address_space_memory, param_offset +0x108 , + initrd_size,MEMTXATTRS_UNSPECIFIED ,NULL ); } } }
hw/alpha/typhoon.c +2 -2
@@ -622,8 +622,8 @@ static bool make_iommu_tlbe(hwaddr taddr, hwaddr mask, IOMMUTLBEntry *ret)translation, given the address of the PTE. */ static bool pte_translate (hwaddr pte_addr,IOMMUTLBEntry *ret) { -uint64_t pte =address_space_ldq (&address_space_memory, pte_addr, -MEMTXATTRS_UNSPECIFIED ,NULL ); +uint64_t pte =address_space_ldq_le (&address_space_memory, pte_addr, +MEMTXATTRS_UNSPECIFIED ,NULL );/* Check valid bit. */ if ((pte &1 ) ==0 ) {
Signature · 1 line
2.52.0
PATCH v2 2/8 target/alpha: Use explicit little-endian LD/ST API
In reply to Philippe Mathieu-DaudéThe Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.
Mechanical change running:
$ for a in uw w l q; do \
sed -i -e "s/ld${a}_p(/ld${a}_le_p(/" \
$(git grep -wlE '(ld|st)u?[wlq]_p' target/alpha/);
done--- target/alpha/helper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
target/alpha/helper.c +6 -5
@@ -214,17 +214,18 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr, pt = env->ptbr; -/* TODO: rather than using ldq_phys() to read the page table we should +/* +* TODO: rather than using ldq_phys_le() to read the page table we should * use address_space_ldq() so that we can handle the case when * the page table read gives a bus fault, rather than ignoring it. -* For the existing code the zero data that ldq_phys will return for +* For the existing code the zero data that ldq_phys_le will return for * an access to invalid memory will result in our treating the page * table as invalid, which may even be the right behaviour. */ /* L1 page table read. */ index = (addr >> (TARGET_PAGE_BITS +20 )) &0x3ff ; - L1pte =ldq_phys (cs->as, pt + index*8 ); + L1pte =ldq_phys_le (cs->as, pt + index *8 );if (unlikely ((L1pte &PTE_VALID ) ==0 )) { ret =MM_K_TNV ;
@@ -237,7 +238,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,/* L2 page table read. */ index = (addr >> (TARGET_PAGE_BITS +10 )) &0x3ff ; - L2pte =ldq_phys (cs->as, pt + index*8 ); + L2pte =ldq_phys_le (cs->as, pt + index *8 );if (unlikely ((L2pte &PTE_VALID ) ==0 )) { ret =MM_K_TNV ;
@@ -250,7 +251,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,/* L3 page table read. */ index = (addr >>TARGET_PAGE_BITS ) &0x3ff ; - L3pte =ldq_phys (cs->as, pt + index*8 ); + L3pte =ldq_phys_le (cs->as, pt + index *8 ); phys = L3pte >>32 <<TARGET_PAGE_BITS ;if (unlikely ((L3pte &PTE_VALID ) ==0 )) {
Signature · 1 line
2.52.0
PATCH v2 3/8 target/alpha: Inline cpu_ldl_code() call in do_unaligned_access()
In reply to Philippe Mathieu-DaudéIn preparation of removing the cpu_ldl_code wrapper, inline it. Use the return address argument.
Since Alpha instructions are always stored in little-endian order, replace MO_TE -> MO_LE.
--- target/alpha/mem_helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/alpha/mem_helper.c +3 -1
@@ -24,13 +24,15 @@static void do_unaligned_access (CPUAlphaState *env,vaddr addr,uintptr_t retaddr) { +CPUState *cs =env_cpu (env); +MemOpIdx oi =make_memop_idx (MO_LEUL ,cpu_mmu_index (cs, true));uint64_t pc;uint32_t insn;cpu_restore_state (env_cpu (env), retaddr); pc = env->pc; - insn =cpu_ldl_code (env, pc); + insn =cpu_ldl_code_mmu (env, pc, oi, retaddr); env->trap_arg0 = addr; env->trap_arg1 = insn >>26 ;/* opcode */
Signature · 1 line
2.52.0
PATCH v2 4/8 target/alpha: 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.
--- target/alpha/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/alpha/translate.c +2 -2
@@ -2904,8 +2904,8 @@ static void alpha_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)static void alpha_tr_translate_insn (DisasContextBase *dcbase,CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base); -uint32_t insn =translator_ldl (cpu_env (cpu), &ctx->base, - ctx->base.pc_next); +uint32_t insn =translator_ldl_end (cpu_env (cpu), &ctx->base, + ctx->base.pc_next,MO_TE ); ctx->base.pc_next +=4 ; ctx->base.is_jmp =translate_one (ctx, insn);
Signature · 1 line
2.52.0
PATCH v2 5/8 target/alpha: Factor mo_endian() helper out
In reply to Philippe Mathieu-Daudé--- target/alpha/translate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/alpha/translate.c +6 -1
@@ -96,6 +96,11 @@ static TCGv cpu_lock_value;static TCGv cpu_pal_ir[31 ];#endif +static inline MemOp mo_endian (DisasContext *dc) +{ +return MO_TE ; +} +void alpha_translate_init (void ) {#define DEF_VAR (V ) { &cpu_##V, #V, offsetof(CPUAlphaState, V) }
@@ -2905,7 +2910,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base);uint32_t insn =translator_ldl_end (cpu_env (cpu), &ctx->base, - ctx->base.pc_next,MO_TE ); + ctx->base.pc_next,mo_endian (ctx)); ctx->base.pc_next +=4 ; ctx->base.is_jmp =translate_one (ctx, insn);
Signature · 1 line
2.52.0
Re: [PATCH v2 5/8] target/alpha: Factor mo_endian() helper out
Quoted 22 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/alpha/translate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)target/alpha/translate.c +5
-0@@ -96,6 +96,11 @@ static TCGv cpu_lock_value;static TCGv cpu_pal_ir[31 ];#endif +static inline MemOp mo_endian (DisasContext *dc) +{ +return MO_TE ; +} +void alpha_translate_init (void ) {#define DEF_VAR (V ) { &cpu_##V, #V, offsetof(CPUAlphaState, V) }
target/alpha/translate.c static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) · line 2916
Quoted 8 lines
target/alpha/translate.c +1
-1@@ -2905,7 +2910,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base);uint32_t insn =translator_ldl_end (cpu_env (cpu), &ctx->base, - ctx->base.pc_next,MO_TE ); + ctx->base.pc_next,mo_endian (ctx)); ctx->base.pc_next +=4 ; ctx->base.is_jmp =translate_one (ctx, insn);
I don't think we need this or the next.
The note about big-endian cray alpha was a mere curiosity.
r~
Re: [PATCH v2 5/8] target/alpha: Factor mo_endian() helper out
Quoted 25 lines · Richard Henderson
Quoted 24 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/alpha/translate.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)target/alpha/translate.c +5
-0@@ -96,6 +96,11 @@ static TCGv cpu_lock_value; static TCGv cpu_pal_ir[31]; #endif +static inline MemOp mo_endian (DisasContext *dc) +{ + return MO_TE; +} + void alpha_translate_init(void) { #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUAlphaState, V) }@@ -2905,7 +2910,7 @@ static voidalpha_tr_translate_insn (DisasContextBase *dcbase, CPUState *cpu) { DisasContext *ctx = container_of(dcbase, DisasContext, base);
Quoted 8 lines
Quoted 6 lines
target/alpha/translate.c +1
-1uint32_t insn = translator_ldl_end(cpu_env(cpu), &ctx->base, - ctx->base.pc_next, MO_TE); + ctx->base.pc_next,mo_endian (ctx)); ctx->base.pc_next += 4;
ctx->base.is_jmp=translate_one(ctx, insn);I don't think we need this or the next.
Shouldn't we define mo_endian() for each target for consistency?
Quoted 1 line
The note about big-endian cray alpha was a mere curiosity.
Well, I like it and it doesn't hurt :)
Re: [PATCH v2 5/8] target/alpha: Factor mo_endian() helper out
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Richard Henderson
Quoted 23 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/alpha/translate.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)target/alpha/translate.c +5
-0@@ -96,6 +96,11 @@ static TCGv cpu_lock_value; static TCGv cpu_pal_ir[31]; #endif +static inline MemOp mo_endian (DisasContext *dc) +{ + return MO_TE; +} + void alpha_translate_init(void) { #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUAlphaState, V) }@@ -2905,7 +2910,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) {Quoted 8 lines
target/alpha/translate.c static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) · line 2916
Quoted 6 lines
target/alpha/translate.c +1
-1DisasContext *ctx = container_of(dcbase, DisasContext, base); uint32_t insn = translator_ldl_end(cpu_env(cpu), &ctx->base, - ctx->base.pc_next, MO_TE); + ctx->base.pc_next, mo_endian(ctx)); ctx->base.pc_next += 4; ctx->base.is_jmp = translate_one(ctx, insn);I don't think we need this or the next.
Quoted 1 line
Shouldn't we define
mo_endian()for each target for consistency?
Eh. You wouldn't suggest this for x86, surely?
r~
PATCH v2 6/8 target/alpha: Replace MO_TE -> MO_LE
In reply to Philippe Mathieu-DaudéWe only build the Alpha targets using little endianness order:
$ git grep -L TARGET_BIG_ENDIAN configs/targets/alpha-* configs/targets/alpha-linux-user.mak configs/targets/alpha-softmmu.mak
Therefore the MO_TE definition always expands to MO_LE. Use the latter to simplify.
--- target/alpha/translate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
target/alpha/translate.c +5 -1
@@ -98,7 +98,11 @@ static TCGv cpu_pal_ir[31];static inline MemOp mo_endian (DisasContext *dc) { -return MO_TE ; +/* +* Technically, Alpha can be run in big-endian mode, but we don't bother. +* This was only ever used for the Cray T3[DE] machines. :-) +*/ +return MO_LE ; }void alpha_translate_init (void )
Signature · 1 line
2.52.0
Re: [PATCH v2 6/8] target/alpha: Replace MO_TE -> MO_LE
Quoted 6 lines · Philippe Mathieu-Daudé
We only build the Alpha targets using little endianness order:
$ git grep -L TARGET_BIG_ENDIAN configs/targets/alpha-* configs/targets/alpha-linux-user.mak configs/targets/alpha-softmmu.mak
Quoted 8 lines
Therefore the
MO_TEdefinition always expands toMO_LE. Use the latter to simplify.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/alpha/translate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
PATCH v2 7/8 configs/targets: Forbid Alpha to use legacy native endianness APIs
In reply to Philippe Mathieu-DaudéAll Alpha-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/alpha-linux-user.mak | 1 + configs/targets/alpha-softmmu.mak | 1 + 2 files changed, 2 insertions(+)
configs/targets/alpha-linux-user.mak +1 -0
@@ -3,3 +3,4 @@ TARGET_SYSTBL_ABI=common TARGET_SYSTBL=syscall.tbl TARGET_LONG_BITS=64 TARGET_XML_FILES= gdb-xml/alpha-core.xml +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
configs/targets/alpha-softmmu.mak +1 -0
@@ -1,3 +1,4 @@ TARGET_ARCH=alpha TARGET_LONG_BITS=64 TARGET_XML_FILES= gdb-xml/alpha-core.xml +TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
Signature · 1 line
2.52.0
PATCH v2 8/8 target/alpha: Replace legacy ld_phys() -> address_space_ld()
In reply to Philippe Mathieu-DaudéPrefer the address_space_ld/st API over the legacy ld_phys() because it allow checking for bus access fault.
Since we removed the last legacy uses of the legacy ldst_phys() API, set the TARGET_NOT_USING_LEGACY_LDST_PHYS_API variable to hide the legacy API to alpha binaries, avoiding further API uses to creep in.
--- configs/targets/alpha-linux-user.mak | 1 + configs/targets/alpha-softmmu.mak | 1 + target/alpha/helper.c | 29 ++++++++++++++++------------ 3 files changed, 19 insertions(+), 12 deletions(-)
configs/targets/alpha-linux-user.mak +1 -0
@@ -4,3 +4,4 @@ TARGET_SYSTBL=syscall.tbl TARGET_LONG_BITS=64 TARGET_XML_FILES= gdb-xml/alpha-core.xml TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y +TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
configs/targets/alpha-softmmu.mak +1 -0
@@ -2,3 +2,4 @@ TARGET_ARCH=alpha TARGET_LONG_BITS=64 TARGET_XML_FILES= gdb-xml/alpha-core.xml TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y +TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
target/alpha/helper.c +17 -12
@@ -169,6 +169,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr, int prot_need, int mmu_idx, target_ulong *pphys, int *pprot) { + const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;CPUState *cs =env_cpu (env);target_long saddr = addr;target_ulong phys =0 ;
@@ -176,6 +177,7 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,target_ulong pt, index;int prot =0 ;int ret =MM_K_ACV ; +MemTxResult txres;/* Handle physical accesses. */ if (mmu_idx ==MMU_PHYS_IDX ) {
@@ -214,18 +216,13 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr, pt = env->ptbr; -/* -* TODO: rather than using ldq_phys_le() to read the page table we should -* use address_space_ldq() so that we can handle the case when -* the page table read gives a bus fault, rather than ignoring it. -* For the existing code the zero data that ldq_phys_le will return for -* an access to invalid memory will result in our treating the page -* table as invalid, which may even be the right behaviour. -*/ -/* L1 page table read. */ index = (addr >> (TARGET_PAGE_BITS +20 )) &0x3ff ; - L1pte =ldq_phys_le (cs->as, pt + index *8 ); + L1pte =address_space_ldq_le (cs->as, pt + index *8 , attrs, &txres); +if (txres !=MEMTX_OK ) { +/* bus fault */ + goto exit; + }if (unlikely ((L1pte &PTE_VALID ) ==0 )) { ret =MM_K_TNV ;
@@ -238,7 +235,11 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,/* L2 page table read. */ index = (addr >> (TARGET_PAGE_BITS +10 )) &0x3ff ; - L2pte =ldq_phys_le (cs->as, pt + index *8 ); + L2pte =address_space_ldq_le (cs->as, pt + index *8 , attrs, &txres); +if (txres !=MEMTX_OK ) { +/* bus fault */ + goto exit; + }if (unlikely ((L2pte &PTE_VALID ) ==0 )) { ret =MM_K_TNV ;
@@ -251,7 +252,11 @@ static int get_physical_address(CPUAlphaState *env, target_ulong addr,/* L3 page table read. */ index = (addr >>TARGET_PAGE_BITS ) &0x3ff ; - L3pte =ldq_phys_le (cs->as, pt + index *8 ); + L3pte =address_space_ldq_le (cs->as, pt + index *8 , attrs, &txres); +if (txres !=MEMTX_OK ) { +/* bus fault */ + goto exit; + } phys = L3pte >>32 <<TARGET_PAGE_BITS ;if (unlikely ((L3pte &PTE_VALID ) ==0 )) {
Signature · 1 line
2.52.0