disas: Have disas_set_info() take a const CPUState
cover disas: Have disas_set_info() take a const CPUState
Have the CPUClass::disas_set_info() handler take a const CPUState to be sure it is not modified. In order to do that, first constify few callees (ARM & RISCV).
Philippe Mathieu-Daudé (7):
target/arm: Have arm_feature() take a const @env argument target/arm: Have cpu_isar_feature() use a const ARMCPU object target/arm: Have is_64() take a const @env argument target/arm: Have arm_sctlr_b() take a const @env argument disas/riscv: Make rv_decode::cfg const
disas: Make disassemble_info::target_info field const
disas: Have disas_set_info() take a const CPUState
disas/riscv.h | 2 +- include/disas/dis-asm.h | 2 +- include/hw/core/cpu.h | 2 +- target/arm/cpu-features.h | 2 +- target/arm/cpu.h | 6 +++--- disas/riscv.c | 5 +++-- target/alpha/cpu.c | 3 ++- target/arm/cpu.c | 6 +++--- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 3 ++- target/hppa/cpu.c | 2 +- target/i386/cpu.c | 6 +++--- target/loongarch/cpu.c | 3 ++- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 7 +++++-- target/openrisc/cpu.c | 2 +- target/ppc/cpu_init.c | 5 +++-- target/riscv/cpu.c | 7 ++++--- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/xtensa/cpu.c | 3 ++- 24 files changed, 47 insertions(+), 35 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/7 target/arm: Have arm_feature() take a const @env argument
arm_feature() only access @env read-only, make it const.
--- target/arm/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.h +1 -1
@@ -2140,7 +2140,7 @@ enum arm_features { ARM_FEATURE_BACKCOMPAT_CNTFRQ, /* 62.5MHz timer default */ }; -static inline int arm_feature (CPUARMState *env,int feature) +static inline int arm_feature (const CPUARMState *env,int feature) {return (env->features & (1ULL << feature)) !=0 ; }
Signature · 1 line
2.52.0
PATCH 2/7 target/arm: Have cpu_isar_feature() use a const ARMCPU object
In reply to Philippe Mathieu-DaudéThe @cpu_ variable is only accessed read-only, make it const.
--- target/arm/cpu-features.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu-features.h +1 -1
@@ -1643,6 +1643,6 @@ static inline uint64_t make_ccsidr(CCSIDRFormat format, unsigned assoc,* Forward to the above feature tests given an ARMCPU pointer. */ #define cpu_isar_feature (name, cpu) \ - ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); }) + ({ const ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); })#endif
Signature · 1 line
2.52.0
PATCH 3/7 target/arm: Have is_64() take a const @env argument
In reply to Philippe Mathieu-Daudéis_64() only access @env read-only, make it const.
--- target/arm/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.h +1 -1
@@ -1345,7 +1345,7 @@ uint32_t sve_vqm1_for_el_sm(CPUARMState *env, int el, bool sm);/* Likewise, but using @sm = PSTATE.SM. */ uint32_t sve_vqm1_for_el (CPUARMState *env,int el); -static inline bool is_a64 (CPUARMState *env) +static inline bool is_a64 (const CPUARMState *env) {return env->aarch64; }
Signature · 1 line
2.52.0
PATCH 4/7 target/arm: Have arm_sctlr_b() take a const @env argument
In reply to Philippe Mathieu-Daudéarm_sctlr_b() only access @env read-only, make it const.
--- target/arm/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.h +1 -1
@@ -2385,7 +2385,7 @@ static inline bool arm_v7m_csselr_razwi(ARMCPU *cpu)return (GET_IDREG (&cpu->isar,CLIDR ) &R_V7M_CLIDR_CTYPE_ALL_MASK ) !=0 ; } -static inline bool arm_sctlr_b (CPUARMState *env) +static inline bool arm_sctlr_b (const CPUARMState *env) {return /* We need not implement SCTLR.ITD in user-mode emulation, so
Signature · 1 line
2.52.0
PATCH 5/7 disas/riscv: Make rv_decode::cfg const
In reply to Philippe Mathieu-DaudéDisassembler is not expected to alter the CPU config. Besides, all other RISC-V methods takes a const RISCVCPUConfig. Make the @cfg field of the rv_decode structure const, passing a const pointer to disasm_inst().
--- disas/riscv.h | 2 +- disas/riscv.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
disas/riscv.h +1 -1
@@ -189,7 +189,7 @@ typedef struct { } rv_opcode_data; typedef struct { - RISCVCPUConfig *cfg; + const RISCVCPUConfig *cfg; uint64_t pc; uint64_t inst; const rv_opcode_data *opcode_data;
disas/riscv.c +3 -2
@@ -5409,7 +5409,7 @@ static void decode_inst_decompress(rv_decode *dec, rv_isa isa)/* disassemble instruction */ static GString *disasm_inst (rv_isa isa,uint64_t pc,rv_inst inst, -RISCVCPUConfig *cfg) +const RISCVCPUConfig *cfg) {rv_decode dec = {0 }; dec.pc = pc;
@@ -5509,7 +5509,8 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) }g_autoptr (GString) str = -disasm_inst (isa, memaddr, inst, (RISCVCPUConfig *)info->target_info); +disasm_inst (isa, memaddr, inst, + (const RISCVCPUConfig *)info->target_info); (*info->fprintf_func)(info->stream,"%s" , str->str);return len;
Signature · 1 line
2.52.0
PATCH 6/7 disas: Make disassemble_info::target_info field const
In reply to Philippe Mathieu-DaudéDisassemblers shouldn't need writeable context, so make the disassemble_info::target_info field const.
--- include/disas/dis-asm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/disas/dis-asm.h +1 -1
@@ -397,7 +397,7 @@ typedef struct disassemble_info {bool show_opcodes;/* Field intended to be used by targets in any way they deem suitable. */ -void *target_info; +const void *target_info;/* Options for Capstone disassembly. */ int cap_arch;
Signature · 1 line
2.52.0
PATCH 7/7 disas: Have disas_set_info() take a const CPUState
In reply to Philippe Mathieu-DaudéThe CPUClass::disas_set_info() handler is meant to initialize the %disassemble_info structure; it shoudn't alter the CPU state. Enforce the CPUState can not be modified by having the handler take a const pointer.
--- include/hw/core/cpu.h | 2 +- target/alpha/cpu.c | 3 ++- target/arm/cpu.c | 6 +++--- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 3 ++- target/hppa/cpu.c | 2 +- target/i386/cpu.c | 6 +++--- target/loongarch/cpu.c | 3 ++- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 7 +++++-- target/openrisc/cpu.c | 2 +- target/ppc/cpu_init.c | 5 +++-- target/riscv/cpu.c | 7 ++++--- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/xtensa/cpu.c | 3 ++- 19 files changed, 38 insertions(+), 27 deletions(-)
include/hw/core/cpu.h +1 -1
@@ -175,7 +175,7 @@ struct CPUClass {const char * (*gdb_arch_name)(CPUState *cpu);const char * (*gdb_get_core_xml_file)(CPUState *cpu); -void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +void (*disas_set_info)(const CPUState *cpu,disassemble_info *info);const char *deprecation_note;struct AccelCPUClass *accel_cpu;
target/alpha/cpu.c +2 -1
@@ -98,7 +98,8 @@ static int alpha_cpu_mmu_index(CPUState *cs, bool ifetch)return alpha_env_mmu_index (cpu_env (cs)); } -static void alpha_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) +static void alpha_cpu_disas_set_info (const CPUState *cpu, +disassemble_info *info) { info->endian =BFD_ENDIAN_LITTLE ; info->mach = bfd_mach_alpha_ev6;
target/arm/cpu.c +3 -3
@@ -789,10 +789,10 @@ static void arm_wfxt_timer_cb(void *opaque) }#endif -static void arm_disas_set_info (CPUState *cpu,disassemble_info *info) +static void arm_disas_set_info (const CPUState *cpu,disassemble_info *info) { -ARMCPU *ac =ARM_CPU (cpu); -CPUARMState *env = &ac->env; +const ARMCPU *ac =ARM_CPU (cpu); +const CPUARMState *env = &ac->env;bool sctlr_b =arm_sctlr_b (env);if (is_a64 (env)) {
target/avr/cpu.c +1 -1
@@ -116,7 +116,7 @@ static void avr_cpu_reset_hold(Object *obj, ResetType type)memset (env->r,0 ,sizeof (env->r)); } -static void avr_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) +static void avr_cpu_disas_set_info (const CPUState *cpu,disassemble_info *info) { info->endian =BFD_ENDIAN_LITTLE ; info->mach = bfd_arch_avr;
target/hexagon/cpu.c +2 -1
@@ -301,7 +301,8 @@ static void hexagon_cpu_reset_hold(Object *obj, ResetType type)set_float_default_nan_pattern (0b11111111 , &env->fp_status); } -static void hexagon_cpu_disas_set_info (CPUState *s,disassemble_info *info) +static void hexagon_cpu_disas_set_info (const CPUState *cs, +disassemble_info *info) { info->print_insn = print_insn_hexagon; info->endian =BFD_ENDIAN_LITTLE ;
target/hppa/cpu.c +1 -1
@@ -150,7 +150,7 @@ static int hppa_cpu_mmu_index(CPUState *cs, bool ifetch)return env->psw &PSW_W ?MMU_ABS_W_IDX :MMU_ABS_IDX ; } -static void hppa_cpu_disas_set_info (CPUState *cs,disassemble_info *info) +static void hppa_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) { info->mach = bfd_mach_hppa20; info->endian =BFD_ENDIAN_BIG ;
target/i386/cpu.c +3 -3
@@ -10359,10 +10359,10 @@ static bool x86_cpu_has_work(CPUState *cs) }#endif /* !CONFIG_USER_ONLY */ -static void x86_disas_set_info (CPUState *cs,disassemble_info *info) +static void x86_disas_set_info (const CPUState *cs,disassemble_info *info) { -X86CPU *cpu =X86_CPU (cs); -CPUX86State *env = &cpu->env; +const X86CPU *cpu =X86_CPU (cs); +const CPUX86State *env = &cpu->env; info->endian =BFD_ENDIAN_LITTLE ; info->mach = (env->hflags & HF_CS64_MASK ? bfd_mach_x86_64
target/loongarch/cpu.c +2 -1
@@ -506,7 +506,8 @@ static void loongarch_cpu_reset_hold(Object *obj, ResetType type) cs->exception_index =-1 ; } -static void loongarch_cpu_disas_set_info (CPUState *s,disassemble_info *info) +static void loongarch_cpu_disas_set_info (const CPUState *cs, +disassemble_info *info) { info->endian =BFD_ENDIAN_LITTLE ; info->print_insn = print_insn_loongarch;
target/m68k/cpu.c +1 -1
@@ -176,7 +176,7 @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) env->pc =0 ; } -static void m68k_cpu_disas_set_info (CPUState *s,disassemble_info *info) +static void m68k_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) { info->print_insn = print_insn_m68k; info->endian =BFD_ENDIAN_BIG ;
target/microblaze/cpu.c +1 -1
@@ -233,7 +233,7 @@ static void mb_cpu_reset_hold(Object *obj, ResetType type)#endif } -static void mb_disas_set_info (CPUState *cpu,disassemble_info *info) +static void mb_disas_set_info (const CPUState *cpu,disassemble_info *info) { info->mach = bfd_arch_microblaze; info->print_insn = print_insn_microblaze;
target/mips/cpu.c +5 -2
@@ -422,9 +422,12 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)#endif } -static void mips_cpu_disas_set_info (CPUState *s,disassemble_info *info) +static void mips_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) { -if (!(cpu_env (s)->insn_flags &ISA_NANOMIPS32 )) { +const MIPSCPU *cpu =MIPS_CPU (cs); +const CPUMIPSState *env = &cpu->env; + +if (!(env->insn_flags &ISA_NANOMIPS32 )) { info->endian =TARGET_BIG_ENDIAN ?BFD_ENDIAN_BIG :BFD_ENDIAN_LITTLE ; info->print_insn = TARGET_BIG_ENDIAN ? print_insn_big_mips
target/openrisc/cpu.c +1 -1
@@ -94,7 +94,7 @@ static int openrisc_cpu_mmu_index(CPUState *cs, bool ifetch)return MMU_NOMMU_IDX ;/* mmu is disabled */ } -static void openrisc_disas_set_info (CPUState *cpu,disassemble_info *info) +static void openrisc_disas_set_info (const CPUState *cpu,disassemble_info *info) { info->endian =BFD_ENDIAN_BIG ; info->print_insn = print_insn_or1k;
target/ppc/cpu_init.c +3 -2
@@ -7452,9 +7452,10 @@ static bool ppc_pvr_match_default(PowerPCCPUClass *pcc, uint32_t pvr, bool best)return pcc->pvr == pvr; } -static void ppc_disas_set_info (CPUState *cs,disassemble_info *info) +static void ppc_disas_set_info (const CPUState *cs,disassemble_info *info) { -CPUPPCState *env =cpu_env (cs); +const PowerPCCPU *cpu =POWERPC_CPU (cs); +const CPUPPCState *env = &cpu->env;if ((env->hflags >>MSR_LE ) &1 ) { info->endian =BFD_ENDIAN_LITTLE ;
target/riscv/cpu.c +4 -3
@@ -795,10 +795,11 @@ static void riscv_cpu_reset_hold(Object *obj, ResetType type)#endif } -static void riscv_cpu_disas_set_info (CPUState *s,disassemble_info *info) +static void riscv_cpu_disas_set_info (const CPUState *s,disassemble_info *info) { -RISCVCPU *cpu =RISCV_CPU (s); -CPURISCVState *env = &cpu->env; +const RISCVCPU *cpu =RISCV_CPU (s); +const CPURISCVState *env = &cpu->env; + info->target_info = &cpu->cfg;/*
target/rx/cpu.c +1 -1
@@ -178,7 +178,7 @@ static void rx_cpu_set_irq(void *opaque, int no, int request) } } -static void rx_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) +static void rx_cpu_disas_set_info (const CPUState *cpu,disassemble_info *info) { info->endian =BFD_ENDIAN_LITTLE ; info->mach = bfd_mach_rx;
target/s390x/cpu.c +1 -1
@@ -222,7 +222,7 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type) } } -static void s390_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) +static void s390_cpu_disas_set_info (const CPUState *cpu,disassemble_info *info) { info->mach = bfd_mach_s390_64; info->cap_arch =CS_ARCH_SYSZ ;
target/sh4/cpu.c +2 -1
@@ -164,7 +164,8 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)set_float_ftz_detection (float_ftz_before_rounding, &env->fp_status); } -static void superh_cpu_disas_set_info (CPUState *cpu,disassemble_info *info) +static void superh_cpu_disas_set_info (const CPUState *cpu, +disassemble_info *info) { info->endian =TARGET_BIG_ENDIAN ?BFD_ENDIAN_BIG :BFD_ENDIAN_LITTLE ;
target/sparc/cpu.c +2 -1
@@ -103,7 +103,8 @@ static bool sparc_cpu_exec_interrupt(CPUState *cs, int interrupt_request) }#endif /* !CONFIG_USER_ONLY */ -static void cpu_sparc_disas_set_info (CPUState *cpu,disassemble_info *info) +static void cpu_sparc_disas_set_info (const CPUState *cpu, +disassemble_info *info) { info->print_insn = print_insn_sparc; info->endian =BFD_ENDIAN_BIG ;
target/xtensa/cpu.c +2 -1
@@ -226,7 +226,8 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model)return oc; } -static void xtensa_cpu_disas_set_info (CPUState *cs,disassemble_info *info) +static void xtensa_cpu_disas_set_info (const CPUState *cs, +disassemble_info *info) {XtensaCPU *cpu =XTENSA_CPU (cs);
Signature · 1 line
2.52.0
Quoted 19 lines · Philippe Mathieu-Daudé
The
CPUClass::disas_set_info()handler is meant to initialize the %disassemble_info structure; it shoudn't alter the CPU state. Enforce the CPUState can not be modified by having the handler take a const pointer.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/core/cpu.h | 2 +- target/alpha/cpu.c | 3 ++- target/arm/cpu.c | 6 +++--- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 3 ++- target/hppa/cpu.c | 2 +- target/i386/cpu.c | 6 +++--- target/loongarch/cpu.c | 3 ++- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 7 +++++-- target/openrisc/cpu.c | 2 +-
Quoted 8 lines
target/ppc/cpu_init.c | 5 +++-- target/riscv/cpu.c | 7 ++++--- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 3 ++- target/sparc/cpu.c | 3 ++- target/xtensa/cpu.c | 3 ++- 19 files changed, 38 insertions(+), 27 deletions(-)
Quoted 8 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (7):
target/arm: Havearm_feature()take a const @env argument target/arm: Havecpu_isar_feature()use a const ARMCPU object target/arm: Haveis_64()take a const @env argument target/arm: Havearm_sctlr_b()take a const @env argument disas/riscv: Makerv_decode::cfgconst
disas: Makedisassemble_info::target_infofield const
disas: Havedisas_set_info()take a const CPUState
r~
Quoted 4 lines · Philippe Mathieu-Daudé
Have the
CPUClass::disas_set_info()handler take a const CPUState to be sure it is not modified. In order to do that, first constify few callees (ARM & RISCV).
Quoted 8 lines
Philippe Mathieu-Daudé (7):
target/arm: Havearm_feature()take a const @env argument target/arm: Havecpu_isar_feature()use a const ARMCPU object target/arm: Haveis_64()take a const @env argument target/arm: Havearm_sctlr_b()take a const @env argument disas/riscv: Makerv_decode::cfgconst
disas: Makedisassemble_info::target_infofield const
disas: Havedisas_set_info()take a const CPUState
Series queued, thanks.