target/mips: Constify and remove TARGET_BIG_ENDIAN uses
cover target/mips: Constify and remove TARGET_BIG_ENDIAN uses
Patches 1-3 progressively constify CPUState, then 4 and 5 remove dependencies on TARGET_BIG_ENDIAN.
Philippe Mathieu-Daudé (5):
target/mips: Constify CPUMIPSTLBContext::map_address() handlers target/mips: Constify get_physical_address() target/mips: Constify read-only CPUMIPSState arguments target/mips: Do not use TARGET_BIG_ENDIAN in cpu.c target/mips: Use CPU endianness in MSA LD.D / ST.D helpers
target/mips/cpu.h | 4 ++-- target/mips/internal.h | 10 +++++----- target/mips/tcg/tcg-internal.h | 2 +- target/mips/cpu.c | 13 ++++++++----- target/mips/system/cp0.c | 2 +- target/mips/system/physaddr.c | 9 +++++---- target/mips/tcg/dsp_helper.c | 2 +- target/mips/tcg/exception.c | 2 +- target/mips/tcg/msa_helper.c | 18 ++++++++++++++---- target/mips/tcg/system/cp0_helper.c | 2 +- target/mips/tcg/system/tlb_helper.c | 9 +++++---- 11 files changed, 44 insertions(+), 29 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/5 target/mips: Constify CPUMIPSTLBContext::map_address() handlers
The map_address() handlers only read the CPU state, make their CPUMIPSState argument const.
--- target/mips/internal.h | 2 +- target/mips/tcg/system/tlb_helper.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)
target/mips/internal.h +1 -1
@@ -145,7 +145,7 @@ struct r4k_tlb_t {struct CPUMIPSTLBContext {uint32_t nb_tlb;uint32_t tlb_in_use; -int (*map_address)(CPUMIPSState *env,hwaddr *physical,int *prot, +int (*map_address)(const CPUMIPSState *env,hwaddr *physical,int *prot,target_ulong address,MMUAccessType access_type);void (*helper_tlbwi)(CPUMIPSState *env);void (*helper_tlbwr)(CPUMIPSState *env);
target/mips/tcg/system/tlb_helper.c +5 -4
@@ -360,8 +360,9 @@ void HELPER(ginvt)(CPUMIPSState *env, target_ulong arg, uint32_t type) }/* no MMU emulation */ -static int no_mmu_map_address (CPUMIPSState *env,hwaddr *physical,int *prot, -target_ulong address,MMUAccessType access_type) +static int no_mmu_map_address (const CPUMIPSState *env,hwaddr *physical, +int *prot,target_ulong address, +MMUAccessType access_type) { *physical = address; *prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ;
@@ -369,7 +370,7 @@ static int no_mmu_map_address(CPUMIPSState *env, hwaddr *physical, int *prot, }/* fixed mapping MMU emulation */ -static int fixed_mmu_map_address (CPUMIPSState *env,hwaddr *physical, +static int fixed_mmu_map_address (const CPUMIPSState *env,hwaddr *physical,int *prot,target_ulong address,MMUAccessType access_type) {
@@ -390,7 +391,7 @@ static int fixed_mmu_map_address(CPUMIPSState *env, hwaddr *physical, }/* MIPS32/MIPS64 R4000-style MMU emulation */ -static int r4k_map_address (CPUMIPSState *env,hwaddr *physical,int *prot, +static int r4k_map_address (const CPUMIPSState *env,hwaddr *physical,int *prot,target_ulong address,MMUAccessType access_type) {uint16_t ASID = env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask;
Signature · 1 line
2.55.0
PATCH 2/5 target/mips: Constify get_physical_address()
In reply to Philippe Mathieu-Daudéget_physical_address() and its static helpers only read the CPU state, make their CPUMIPSState argument const.
--- target/mips/internal.h | 2 +- target/mips/system/physaddr.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-)
target/mips/internal.h +1 -1
@@ -115,7 +115,7 @@ enum {TLBRET_MATCH =0 }; -int get_physical_address (CPUMIPSState *env,hwaddr *physical, +int get_physical_address (const CPUMIPSState *env,hwaddr *physical,int *prot,target_ulong real_address,MMUAccessType access_type,int mmu_idx); bool mips_cpu_translate_for_debug(CPUState *cpu, vaddr addr,
target/mips/system/physaddr.c +5 -4
@@ -75,7 +75,7 @@ static int is_seg_am_mapped(unsigned int am, bool eu, int mmu_idx) }; } -static int get_seg_physical_address(CPUMIPSState *env, hwaddr *physical, +static int get_seg_physical_address(const CPUMIPSState *env, hwaddr *physical, int *prot, target_ulong real_address, MMUAccessType access_type, int mmu_idx, unsigned int am, bool eu,
@@ -99,8 +99,9 @@ static int get_seg_physical_address(CPUMIPSState *env, hwaddr *physical, } } -static int get_segctl_physical_address (CPUMIPSState *env,hwaddr *physical, -int *prot,target_ulong real_address, +static int get_segctl_physical_address (const CPUMIPSState *env, +hwaddr *physical,int *prot, +target_ulong real_address,MMUAccessType access_type,int mmu_idx,uint16_t segctl,target_ulong segmask) {
@@ -113,7 +114,7 @@ static int get_segctl_physical_address(CPUMIPSState *env, hwaddr *physical, pa & ~(hwaddr)segmask); } -int get_physical_address (CPUMIPSState *env,hwaddr *physical, +int get_physical_address (const CPUMIPSState *env,hwaddr *physical,int *prot,target_ulong real_address,MMUAccessType access_type,int mmu_idx) {
Signature · 1 line
2.55.0
PATCH 3/5 target/mips: Constify read-only CPUMIPSState arguments
In reply to Philippe Mathieu-Daudécpu_rddsp(), exception_resume_pc(), cpu_mips_get_random(), mips_env_is_bigendian(), mo_endian_env() and sync_c0_status() only read the CPU state passed as CPUMIPSState argument, make it const.
--- target/mips/cpu.h | 4 ++-- target/mips/internal.h | 6 +++--- target/mips/tcg/tcg-internal.h | 2 +- target/mips/system/cp0.c | 2 +- target/mips/tcg/dsp_helper.c | 2 +- target/mips/tcg/exception.c | 2 +- target/mips/tcg/system/cp0_helper.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
target/mips/cpu.h +2 -2
@@ -1281,7 +1281,7 @@ struct MIPSCPUClass { };void cpu_wrdsp (uint32_t rs,uint32_t mask_num,CPUMIPSState *env); -uint32_t cpu_rddsp (uint32_t mask_num,CPUMIPSState *env); +uint32_t cpu_rddsp (uint32_t mask_num,const CPUMIPSState *env);/* * MMU modes definitions. We carefully match the indices with our
@@ -1413,7 +1413,7 @@ void cpu_mips_clock_init(MIPSCPU *cpu);#endif /* !CONFIG_USER_ONLY */ /* helper.c */ -target_ulong exception_resume_pc (CPUMIPSState *env); +target_ulong exception_resume_pc (const CPUMIPSState *env);/* fpu.c */ void cpu_mips_restore_fp_status (CPUMIPSState *env);
target/mips/internal.h +3 -3
@@ -160,7 +160,7 @@ struct CPUMIPSTLBContext { } mmu; }; -void sync_c0_status (CPUMIPSState *env,CPUMIPSState *cpu,int tc); +void sync_c0_status (const CPUMIPSState *env,CPUMIPSState *cpu,int tc);void cpu_mips_store_status (CPUMIPSState *env,target_ulong val);void cpu_mips_store_cause (CPUMIPSState *env,target_ulong val);
@@ -234,12 +234,12 @@ static inline bool mips_env_is_64bit(const CPUMIPSState *env)return env->cpu_model->insn_flags &CPU_MIPS64 ; } -static inline bool mips_env_is_bigendian (CPUMIPSState *env) +static inline bool mips_env_is_bigendian (const CPUMIPSState *env) {return extract32 (env->CP0_Config0,CP0C0_BE ,1 ); } -static inline MemOp mo_endian_env (CPUMIPSState *env) +static inline MemOp mo_endian_env (const CPUMIPSState *env) {return mips_env_is_bigendian (env) ?MO_BE :MO_LE ; }
target/mips/tcg/tcg-internal.h +1 -1
@@ -48,7 +48,7 @@ void mmu_init(CPUMIPSState *env, const mips_def_t *def);uint32_t compute_pagemask (uint32_t val);void r4k_invalidate_tlb (CPUMIPSState *env,int idx,int use_extra); -uint32_t cpu_mips_get_random (CPUMIPSState *env); +uint32_t cpu_mips_get_random (const CPUMIPSState *env);bool mips_io_recompile_replay_branch (CPUState *cs,const TranslationBlock *tb);
target/mips/system/cp0.c +1 -1
@@ -24,7 +24,7 @@#include "exec/cputlb.h" /* Called for updates to CP0_Status. */ -void sync_c0_status (CPUMIPSState *env,CPUMIPSState *cpu,int tc) +void sync_c0_status (const CPUMIPSState *env,CPUMIPSState *cpu,int tc) {int32_t tcstatus, *tcst;uint32_t v = cpu->CP0_Status;
target/mips/tcg/dsp_helper.c +1 -1
@@ -3683,7 +3683,7 @@ void HELPER(wrdsp)(target_ulong rs, target_ulong mask_num, CPUMIPSState *env)cpu_wrdsp (rs, mask_num, env); } -uint32_t cpu_rddsp (uint32_t mask_num,CPUMIPSState *env) +uint32_t cpu_rddsp (uint32_t mask_num,const CPUMIPSState *env) {uint8_t mask[6 ];uint32_t ruler, i;
target/mips/tcg/exception.c +1 -1
@@ -27,7 +27,7 @@#include "exec/translation-block.h" #include "accel/tcg/cpu-loop.h" -target_ulong exception_resume_pc (CPUMIPSState *env) +target_ulong exception_resume_pc (const CPUMIPSState *env) {target_ulong bad_pc;target_ulong isa_mode;
target/mips/tcg/system/cp0_helper.c +1 -1
@@ -202,7 +202,7 @@ static void sync_c0_entryhi(CPUMIPSState *cpu, int tc) }/* XXX: do not use a global */ -uint32_t cpu_mips_get_random (CPUMIPSState *env) +uint32_t cpu_mips_get_random (const CPUMIPSState *env) {static uint32_t seed =1 ;static uint32_t prev_idx;
Signature · 1 line
2.55.0
PATCH 4/5 target/mips: Do not use TARGET_BIG_ENDIAN in cpu.c
In reply to Philippe Mathieu-DaudéUse the vCPU endianness (CP0_Config0.BE) to select the disassembler. Default the "big-endian" property from target_big_endian() in instance_init(), as the endianness might only be known at runtime once user emulation selects it from the guest binary.
--- target/mips/cpu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
target/mips/cpu.c +8 -5
@@ -21,6 +21,7 @@#include "qemu/osdep.h" #include "qemu/cutils.h" #include "qemu/qemu-print.h" +#include "qemu/target-info.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "cpu.h"
@@ -500,10 +501,11 @@ static void mips_cpu_disas_set_info(const CPUState *cs, disassemble_info *info) info->cap_insn_split =6 ; cap_mode =CS_MODE_NANOMIPS ; }else { - info->endian =TARGET_BIG_ENDIAN ?BFD_ENDIAN_BIG - :BFD_ENDIAN_LITTLE ; - info->print_insn =TARGET_BIG_ENDIAN ? print_insn_big_mips - : print_insn_little_mips; +bool big_endian =mips_env_is_bigendian (env); + + info->endian = big_endian ?BFD_ENDIAN_BIG :BFD_ENDIAN_LITTLE ; + info->print_insn = big_endian ? print_insn_big_mips + : print_insn_little_mips;if (env->hflags &MIPS_HFLAG_M16 ) { cap_mode = (env->insn_flags & ASE_MICROMIPS
@@ -636,6 +638,7 @@ static void mips_cpu_initfn(Object *obj) cpu->count_div =clock_new (OBJECT (obj),"clk-div-count" ); cpu->count_clock =clock_new (OBJECT (obj),"clk-count" ); env->cpu_model = mcc->cpu_def; + cpu->is_big_endian =target_big_endian (); }static char *mips_cpu_type_name (const char *cpu_model)
@@ -665,7 +668,7 @@ static const struct SysemuCPUOps mips_sysemu_ops = {#endif static const Property mips_cpu_properties[] = { -DEFINE_PROP_BOOL ("big-endian" ,MIPSCPU , is_big_endian,TARGET_BIG_ENDIAN ), +DEFINE_PROP_BOOL ("big-endian" ,MIPSCPU , is_big_endian, false), };#ifdef CONFIG_TCG
Signature · 1 line
2.55.0
PATCH 5/5 target/mips: Use CPU endianness in MSA LD.D / ST.D helpers
In reply to Philippe Mathieu-Daudéhelper_msa_ld_d() and helper_msa_st_d() use the legacy cpu_ldq_data_ra() / cpu_stq_data_ra() accessors, whose endianness is fixed at build time by TARGET_BIG_ENDIAN. All other MSA load and store helpers check the vCPU endianness at runtime via mips_env_is_bigendian().
Do the same for the doubleword variants, so they keep working when the vCPU endianness differs from the build-time default.
---
We have a better conversion of the runtime helpers by translation which allows to respect atomicity, but the series isn't yet ready, so meanwhile this patch is useful enough.
--- target/mips/tcg/msa_helper.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
target/mips/tcg/msa_helper.c +14 -4
@@ -8300,8 +8300,13 @@ void HELPER(msa_ld_d)(CPUMIPSState *env, uint32_t wd,uintptr_t ra =GETPC ();uint64_t d0, d1; - d0 =cpu_ldq_data_ra (env, addr +0 , ra); - d1 =cpu_ldq_data_ra (env, addr +8 , ra); +if (mips_env_is_bigendian (env)) { + d0 =cpu_ldq_be_data_ra (env, addr +0 , ra); + d1 =cpu_ldq_be_data_ra (env, addr +8 , ra); + }else { + d0 =cpu_ldq_le_data_ra (env, addr +0 , ra); + d1 =cpu_ldq_le_data_ra (env, addr +8 , ra); + } pwd->d[0 ] = d0; pwd->d[1 ] = d1; }
@@ -8389,6 +8394,11 @@ void HELPER(msa_st_d)(CPUMIPSState *env, uint32_t wd,ensure_writable_pages (env, addr, mmu_idx,GETPC ()); -cpu_stq_data_ra (env, addr +0 , pwd->d[0 ], ra); -cpu_stq_data_ra (env, addr +8 , pwd->d[1 ], ra); +if (mips_env_is_bigendian (env)) { +cpu_stq_be_data_ra (env, addr +0 , pwd->d[0 ], ra); +cpu_stq_be_data_ra (env, addr +8 , pwd->d[1 ], ra); + }else { +cpu_stq_le_data_ra (env, addr +0 , pwd->d[0 ], ra); +cpu_stq_le_data_ra (env, addr +8 , pwd->d[1 ], ra); + } }
Signature · 1 line
2.55.0
Quoted 10 lines · Philippe Mathieu-Daudé
Patches 1-3 progressively constify CPUState, then 4 and 5 remove dependencies on
TARGET_BIG_ENDIAN.Philippe Mathieu-Daudé (5):
target/mips: ConstifyCPUMIPSTLBContext::map_address()handlers target/mips: Constifyget_physical_address()target/mips: Constify read-only CPUMIPSState arguments target/mips: Do not useTARGET_BIG_ENDIANincpu.ctarget/mips: Use CPU endianness in MSA LD.D / ST.D helpers
Quoted 13 lines
target/mips/cpu.h | 4 ++-- target/mips/internal.h | 10 +++++----- target/mips/tcg/tcg-internal.h | 2 +- target/mips/cpu.c | 13 ++++++++----- target/mips/system/cp0.c | 2 +- target/mips/system/physaddr.c | 9 +++++---- target/mips/tcg/dsp_helper.c | 2 +- target/mips/tcg/exception.c | 2 +- target/mips/tcg/msa_helper.c | 18 ++++++++++++++---- target/mips/tcg/system/cp0_helper.c | 2 +- target/mips/tcg/system/tlb_helper.c | 9 +++++---- 11 files changed, 44 insertions(+), 29 deletions(-)
Series:
Quoted 6 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (5):
target/mips: ConstifyCPUMIPSTLBContext::map_address()handlers target/mips: Constifyget_physical_address()target/mips: Constify read-only CPUMIPSState arguments target/mips: Do not useTARGET_BIG_ENDIANincpu.ctarget/mips: Use CPU endianness in MSA LD.D / ST.D helpers
r~