disas: Updates for capstone v6
cover disas: Updates for capstone v6
Capstone v6-alpha10 is coming along nicely, and may be able to replace some of the other disassemblers that we have.
Some targets (alpha, hppa, xtensa) that v6 purports to support are still in terrible shape. At least for alpha and hppa that is presumably because the LLVM support that these claim to be derived from is not yet in upstream LLVM.
r~
Richard Henderson (9):
target/riscv: Improve riscv_has_ext disas/capstone: Allow for cap_insn_unit > length target/riscv: Enable disassembly via capstone target/sh4: Enable disassembly via capstone target/tricore: Enable disassembly via capstone target/loongarch: Enable disassembly via capstone target/s390x: Update capstone disassembly to v6 target/m68k: Enable disassembly via capstone target/mips: Enable disassembly via capstone
include/disas/capstone.h | 115 +++++++++++++++++++++++++++++++++++++-- target/riscv/cpu.h | 2 +- disas/capstone.c | 29 +++++++++- target/loongarch/cpu.c | 8 +++ target/m68k/cpu.c | 65 +++++++++++++++++++++- target/mips/cpu.c | 60 ++++++++++++++++++-- target/riscv/cpu.c | 81 ++++++++++++++++++++++++++- target/s390x/cpu.c | 4 +- target/sh4/cpu.c | 14 +++++ target/tricore/cpu.c | 31 +++++++++++ 10 files changed, 393 insertions(+), 16 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/9 target/riscv: Improve riscv_has_ext
Constify the env pointer and return bool.
--- target/riscv/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.h +1 -1
@@ -615,7 +615,7 @@ struct RISCVCPUClass {RISCVCPUDef *def; }; -static inline int riscv_has_ext (CPURISCVState *env,uint32_t ext) +static inline bool riscv_has_ext (const CPURISCVState *env,uint32_t ext) {return (env->misa_ext & ext) !=0 ; }
Signature · 1 line
2.43.0
Re: [PATCH 1/9] target/riscv: Improve riscv_has_ext
Quoted 6 lines · Richard Henderson
Constify the env pointer and return bool.
Signed-off-by Richard Henderson <[email protected]>--- target/riscv/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 2/9 disas/capstone: Allow for cap_insn_unit > length
In reply to Richard Hendersoncap_insn_unit is designed for targets like arm thumb2 and s390x where 4 and 6-byte insns are displayed in 2-byte chunks.
For riscv, we prefer 4-byte insns to display as one 4-byte unit, rather than 2x 2-byte units. So we will want to set cap_insn_unit to 4, but allow for insns that are smaller than 4. Emit padding to match.
--- disas/capstone.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
disas/capstone.c +7 -1
@@ -107,8 +107,9 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, {fprintf_function print = info->fprintf_func;FILE *stream = info->stream; +int unit =MIN (info->cap_insn_unit, n - i); -switch (info->cap_insn_unit) { +switch (unit) {case 4 :if (info->endian ==BFD_ENDIAN_BIG ) {for (; i < n; i +=4 ) {
@@ -140,6 +141,11 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, }break ; } + +if (unit < info->cap_insn_unit) { +int width = (info->cap_insn_unit - unit) *2 ; +"%*s" , width,"" ); + } }static void cap_dump_insn (disassemble_info *info,cs_insn *insn)
Signature · 1 line
2.43.0
Re: [PATCH 2/9] disas/capstone: Allow for cap_insn_unit > length
Quoted 9 lines · Richard Henderson
cap_insn_unitis designed for targets like arm thumb2 and s390x where 4 and 6-byte insns are displayed in 2-byte chunks.For riscv, we prefer 4-byte insns to display as one 4-byte unit, rather than 2x 2-byte units. So we will want to set
cap_insn_unitto 4, but allow for insns that are smaller than 4. Emit padding to match.
Quoted 4 lines
Signed-off-by Richard Henderson <[email protected]>--- disas/capstone.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
PATCH 3/9 target/riscv: Enable disassembly via capstone
In reply to Richard HendersonIn capstone v5, riscv support is spare, but v6 is pretty good.
--- include/disas/capstone.h | 34 +++++++++++++++++ disas/capstone.c | 19 ++++++++++ target/riscv/cpu.c | 81 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 133 insertions(+), 1 deletion(-)
include/disas/capstone.h +34 -0
@@ -11,6 +11,8 @@/* Just enough to allow backends to init without ifdefs. */ +#define CS_API_MAJOR 0 +#define CS_ARCH_ARM -1#define CS_ARCH_ARM64 -1#define CS_ARCH_MIPS -1
@@ -37,4 +39,36 @@#define CS_MODE_MIPS64 0#endif /* CONFIG_CAPSTONE */ + +#if CS_API_MAJOR <5 +#define CS_ARCH_RISCV -1 +#define CS_MODE_RISCV32 0 +#define CS_MODE_RISCV64 0 +#define CS_MODE_RISCV_C 0 +#elif CS_API_MAJOR ==5 +/* The C symbol name changed between v5 and v6 */ +#define CS_MODE_RISCV_C CS_MODE_RISCVC +#endif +#if CS_API_MAJOR <6 +#define CS_MODE_RISCV_FD 0 +#define CS_MODE_RISCV_V 0 +#define CS_MODE_RISCV_ZFINX 0 +#define CS_MODE_RISCV_ZCMP_ZCMT_ZCE 0 +#define CS_MODE_RISCV_ZICFISS 0 +#define CS_MODE_RISCV_E 0 +#define CS_MODE_RISCV_A 0 +#define CS_MODE_RISCV_COREV 0 +#define CS_MODE_RISCV_THEAD 0 +#define CS_MODE_RISCV_SIFIVE 0 +#define CS_MODE_RISCV_BITMANIP 0 +#define CS_MODE_RISCV_ZBA 0 +#define CS_MODE_RISCV_ZBB 0 +#define CS_MODE_RISCV_ZBC 0 +#define CS_MODE_RISCV_ZBKB 0 +#define CS_MODE_RISCV_ZBKC 0 +#define CS_MODE_RISCV_ZBKX 0 +#define CS_MODE_RISCV_ZBS 0 +#define CS_MODE_RISCV_VENTANA 0 +#endif +#endif /* QEMU_CAPSTONE_H */
disas/capstone.c +19 -0
@@ -49,6 +49,20 @@ static const cs_opt_skipdata cap_skipdata_s390x = { .callback = cap_skipdata_s390x_cb }; +/* Similarly for RISCV */ +static size_t CAPSTONE_API +cap_skipdata_riscv_cb (const uint8_t *code,size_t code_size, +size_t offset,void *user_data) +{ +/* See insn_len() from target/riscv/internals.h */ +return (code[offset] &3 ) ==3 ?4 :2 ; +} + +static const cs_opt_skipdata cap_skipdata_riscv = { + .mnemonic =".byte" , + .callback = cap_skipdata_riscv_cb +}; +/* * Initialize the Capstone library. *
@@ -76,6 +90,11 @@ static cs_err cap_disas_start(disassemble_info *info, csh *handle)cs_option (*handle,CS_OPT_SKIPDATA ,CS_OPT_ON );switch (info->cap_arch) { +case CS_ARCH_RISCV : +cs_option (*handle,CS_OPT_SKIPDATA_SETUP , + (uintptr_t )&cap_skipdata_riscv); +break ; +case CS_ARCH_SYSZ :cs_option (*handle,CS_OPT_SKIPDATA_SETUP , (uintptr_t )&cap_skipdata_s390x);
target/riscv/cpu.c +80 -1
108 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 3/9] target/riscv: Enable disassembly via capstone
Quoted 8 lines · Richard Henderson
In capstone v5, riscv support is spare, but v6 is pretty good.
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 34 +++++++++++++++++ disas/capstone.c | 19 ++++++++++ target/riscv/cpu.c | 81 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 133 insertions(+), 1 deletion(-)
PATCH 4/9 target/sh4: Enable disassembly via capstone
In reply to Richard Henderson--- include/disas/capstone.h | 7 +++++++ target/sh4/cpu.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+)
include/disas/capstone.h +7 -0
@@ -71,4 +71,11 @@#define CS_MODE_RISCV_VENTANA 0#endif +#if CS_API_MAJOR <5 +#define CS_ARCH_SH -1 +#define CS_MODE_SHFPU 0 +#define CS_MODE_SH4 0 +#define CS_MODE_SH4A 0 +#endif +#endif /* QEMU_CAPSTONE_H */
target/sh4/cpu.c +14 -0
@@ -28,6 +28,7 @@#include "fpu/softfloat-helpers.h" #include "accel/tcg/cpu-ops.h" #include "tcg/tcg.h" +#include "disas/capstone.h" static void superh_cpu_set_pc (CPUState *cs,vaddr value) {
@@ -167,10 +168,23 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)static void superh_cpu_disas_set_info (const CPUState *cpu,disassemble_info *info) { +const CPUSH4State *env =cpu_env ((CPUState *)cpu); + info->endian =TARGET_BIG_ENDIAN ?BFD_ENDIAN_BIG :BFD_ENDIAN_LITTLE ; info->mach = bfd_mach_sh4; info->print_insn = print_insn_sh; + + info->cap_arch =CS_ARCH_SH ; + info->cap_insn_unit =2 ; + info->cap_insn_split =2 ; +/* +* Possible capstone bug: the isa levels are not additive: +* least significant bit wins, so SH4 overrides SH4A. +* Work around by settiing one or the other but not both. +*/ + info->cap_mode =CS_MODE_SHFPU + | (env->features &SH_FEATURE_SH4A ?CS_MODE_SH4A :CS_MODE_SH4 ); }static ObjectClass *superh_cpu_class_by_name (const char *cpu_model)
Signature · 1 line
2.43.0
Re: [PATCH 4/9] target/sh4: Enable disassembly via capstone
Quoted 15 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 7 +++++++ target/sh4/cpu.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+)target/sh4/cpu.c +2
-0@@ -167,10 +168,23 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)static void superh_cpu_disas_set_info (const CPUState *cpu,disassemble_info *info) { +const CPUSH4State *env =cpu_env ((CPUState *)cpu); + info->endian =TARGET_BIG_ENDIAN ?BFD_ENDIAN_BIG :BFD_ENDIAN_LITTLE ;
target/sh4/cpu.c static void superh_cpu_reset_hold(Object *obj, ResetType type) · line 184
Quoted 10 lines
target/sh4/cpu.c +8
-0info->mach = bfd_mach_sh4; info->print_insn = print_insn_sh; + + info->cap_arch =CS_ARCH_SH ; + info->cap_insn_unit =2 ; + info->cap_insn_split =2 ; +/* +* Possible capstone bug: the isa levels are not additive: +* least significant bit wins, so SH4 overrides SH4A. +* Work around by settiing one or the other but not both.
"setting"
target/sh4/cpu.c static void superh_cpu_reset_hold(Object *obj, ResetType type) · line 188
Quoted 4 lines
target/sh4/cpu.c +3
-0+*/ + info->cap_mode =CS_MODE_SHFPU + | (env->features &SH_FEATURE_SH4A ?CS_MODE_SH4A :CS_MODE_SH4 ); }
PATCH 5/9 target/tricore: Enable disassembly via capstone
In reply to Richard Henderson--- include/disas/capstone.h | 11 +++++++++++ target/tricore/cpu.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/disas/capstone.h +11 -0
@@ -78,4 +78,15 @@#define CS_MODE_SH4A 0#endif +#if CS_API_MAJOR <5 +#define CS_ARCH_TRICORE -1 +#define CS_MODE_TRICORE_110 0 +#define CS_MODE_TRICORE_120 0 +#define CS_MODE_TRICORE_130 0 +#define CS_MODE_TRICORE_131 0 +#define CS_MODE_TRICORE_160 0 +#define CS_MODE_TRICORE_161 0 +#define CS_MODE_TRICORE_162 0 +#endif +#endif /* QEMU_CAPSTONE_H */
target/tricore/cpu.c +31 -0
@@ -24,6 +24,7 @@#include "qemu/error-report.h" #include "tcg/debug-assert.h" #include "accel/tcg/cpu-ops.h" +#include "disas/capstone.h" static inline void set_feature (CPUTriCoreState *env,int feature) {
@@ -35,6 +36,35 @@ static const gchar *tricore_gdb_arch_name(CPUState *cs)return "tricore" ; } +static void tricore_disas_set_info (const CPUState *cpu,disassemble_info *info) +{ +CPUTriCoreState *env =cpu_env ((CPUState *)cpu); + + info->endian =BFD_ENDIAN_LITTLE ; + info->cap_arch =CS_ARCH_TRICORE ; + info->cap_insn_unit =4 ; + info->cap_insn_split =4 ; + +/* +* Possible capstone bug: the isa levels are not additive. +* Work around by settiing only one. +* Note that TriCore 1.3.0 is the earliest we support. +*/ +if (tricore_has_feature (env,TRICORE_FEATURE_162 )) { + info->cap_mode =CS_MODE_TRICORE_162 ; + }else if (tricore_has_feature (env,TRICORE_FEATURE_161 )) { + info->cap_mode =CS_MODE_TRICORE_161 ; + }else if (tricore_has_feature (env,TRICORE_FEATURE_16 )) { + info->cap_mode =CS_MODE_TRICORE_160 ; + }else if (tricore_has_feature (env,TRICORE_FEATURE_131 )) { + info->cap_mode =CS_MODE_TRICORE_131 ; + }else if (tricore_has_feature (env,TRICORE_FEATURE_13 )) { + info->cap_mode =CS_MODE_TRICORE_130 ; + }else { +g_assert_not_reached (); + } +} +static void tricore_cpu_set_pc (CPUState *cs,vaddr value) {cpu_env (cs)->PC = value & ~1 ;
@@ -214,6 +244,7 @@ static void tricore_cpu_class_init(ObjectClass *c, const void *data) cc->gdb_write_register = tricore_cpu_gdb_write_register; cc->gdb_num_core_regs =44 ; cc->gdb_arch_name = tricore_gdb_arch_name; + cc->disas_set_info = tricore_disas_set_info; cc->dump_state = tricore_cpu_dump_state; cc->set_pc = tricore_cpu_set_pc;
Signature · 1 line
2.43.0
Re: [PATCH 5/9] target/tricore: Enable disassembly via capstone
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 11 +++++++++++ target/tricore/cpu.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
PATCH 6/9 target/loongarch: Enable disassembly via capstone
In reply to Richard Henderson--- include/disas/capstone.h | 6 ++++++ target/loongarch/cpu.c | 8 ++++++++ 2 files changed, 14 insertions(+)
include/disas/capstone.h +6 -0
@@ -40,6 +40,12 @@#endif /* CONFIG_CAPSTONE */ +#if CS_API_MAJOR <6 +#define CS_ARCH_LOONGARCH -1 +#define CS_MODE_LOONGARCH32 0 +#define CS_MODE_LOONGARCH64 0 +#endif +#if CS_API_MAJOR <5 #define CS_ARCH_RISCV -1#define CS_MODE_RISCV32 0
target/loongarch/cpu.c +8 -0
@@ -29,6 +29,7 @@#include <linux/kvm.h> #endif #include "tcg/tcg_loongarch.h" +#include "disas/capstone.h" const char *const regnames[32 ] = {"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" ,
@@ -694,8 +695,15 @@ static void loongarch_cpu_reset_hold(Object *obj, ResetType type)static void loongarch_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) { +CPULoongArchState *env =cpu_env ((CPUState *)cs); + info->endian =BFD_ENDIAN_LITTLE ; info->print_insn = print_insn_loongarch; + + info->cap_arch =CS_ARCH_LOONGARCH ; + info->cap_insn_unit =4 ; + info->cap_insn_split =4 ; + info->cap_mode =is_la64 (env) ?CS_MODE_LOONGARCH64 :CS_MODE_LOONGARCH32 ; }static void loongarch_cpu_realizefn (DeviceState *dev,Error **errp)
Signature · 1 line
2.43.0
Re: [PATCH 6/9] target/loongarch: Enable disassembly via capstone
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 6 ++++++ target/loongarch/cpu.c | 8 ++++++++ 2 files changed, 14 insertions(+)
Re: [PATCH 6/9] target/loongarch: Enable disassembly via capstone
In reply to Richard HendersonQuoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 6 ++++++ target/loongarch/cpu.c | 8 ++++++++ 2 files changed, 14 insertions(+)
Thanks.
Song Gao
Quoted 45 lines
include/disas/capstone.h +6
-0@@ -40,6 +40,12 @@#endif /* CONFIG_CAPSTONE */ +#if CS_API_MAJOR <6 +#define CS_ARCH_LOONGARCH -1 +#define CS_MODE_LOONGARCH32 0 +#define CS_MODE_LOONGARCH64 0 +#endif +#if CS_API_MAJOR <5 #define CS_ARCH_RISCV -1#define CS_MODE_RISCV32 0target/loongarch/cpu.c +8
-0@@ -29,6 +29,7 @@#include <linux/kvm.h> #endif #include "tcg/tcg_loongarch.h" +#include "disas/capstone.h" const char *const regnames[32 ] = {"r0" ,"r1" ,"r2" ,"r3" ,"r4" ,"r5" ,"r6" ,"r7" ,@@ -694,8 +695,15 @@ static void loongarch_cpu_reset_hold(Object *obj, ResetType type)static void loongarch_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) { +CPULoongArchState *env =cpu_env ((CPUState *)cs); + info->endian =BFD_ENDIAN_LITTLE ; info->print_insn = print_insn_loongarch; + + info->cap_arch =CS_ARCH_LOONGARCH ; + info->cap_insn_unit =4 ; + info->cap_insn_split =4 ; + info->cap_mode =is_la64 (env) ?CS_MODE_LOONGARCH64 :CS_MODE_LOONGARCH32 ; }static void loongarch_cpu_realizefn (DeviceState *dev,Error **errp)
PATCH 7/9 target/s390x: Update capstone disassembly to v6
In reply to Richard HendersonIn particular, this enables many more vector insns.
--- include/disas/capstone.h | 11 +++++++++-- disas/capstone.c | 2 +- target/s390x/cpu.c | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-)
include/disas/capstone.h +9 -2
@@ -4,7 +4,6 @@#ifdef CONFIG_CAPSTONE #define CAPSTONE_AARCH64_COMPAT_HEADER -#define CAPSTONE_SYSTEMZ_COMPAT_HEADER #include <capstone.h> #else
@@ -19,7 +18,6 @@#define CS_ARCH_X86 -1#define CS_ARCH_PPC -1#define CS_ARCH_SPARC -1 -#define CS_ARCH_SYSZ -1#define CS_MODE_LITTLE_ENDIAN 0#define CS_MODE_BIG_ENDIAN 0
@@ -84,6 +82,15 @@#define CS_MODE_SH4A 0#endif +#if CS_API_MAJOR ==0 +#define CS_ARCH_SYSTEMZ -1 +#elif CS_API_MAJOR <6 +#define CS_ARCH_SYSTEMZ CS_ARCH_SYSZ +#endif +#if CS_API_MAJOR <6 +#define CS_MODE_SYSTEMZ_ARCH14 0 +#endif +#if CS_API_MAJOR <5 #define CS_ARCH_TRICORE -1#define CS_MODE_TRICORE_110 0
disas/capstone.c +1 -1
@@ -95,7 +95,7 @@ static cs_err cap_disas_start(disassemble_info *info, csh *handle) (uintptr_t)&cap_skipdata_riscv);break ; -case CS_ARCH_SYSZ : +case CS_ARCH_SYSTEMZ :cs_option (*handle,CS_OPT_SKIPDATA_SETUP , (uintptr_t )&cap_skipdata_s390x);break ;
target/s390x/cpu.c +3 -1
@@ -225,10 +225,12 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)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 ; + info->cap_arch =CS_ARCH_SYSTEMZ ; info->endian =BFD_ENDIAN_BIG ; info->cap_insn_unit =2 ; info->cap_insn_split =6 ; +/* Disassemble everything, even if the cpu would trap on the insn. */ + info->cap_mode =CS_MODE_SYSTEMZ_ARCH14 ; }static void s390_cpu_realizefn (DeviceState *dev,Error **errp)
Signature · 1 line
2.43.0
Re: [PATCH 7/9] target/s390x: Update capstone disassembly to v6
Quoted 8 lines · Richard Henderson
In particular, this enables many more vector insns.
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 11 +++++++++-- disas/capstone.c | 2 +- target/s390x/cpu.c | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-)
PATCH 8/9 target/m68k: Enable disassembly via capstone
In reply to Richard Henderson--- include/disas/capstone.h | 20 +++++++++++++ target/m68k/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-)
include/disas/capstone.h +20 -0
@@ -14,6 +14,7 @@#define CS_ARCH_ARM -1#define CS_ARCH_ARM64 -1 +#define CS_ARCH_M68K -1#define CS_ARCH_MIPS -1#define CS_ARCH_X86 -1#define CS_ARCH_PPC -1
@@ -28,6 +29,12 @@#define CS_MODE_THUMB 0#define CS_MODE_MCLASS 0#define CS_MODE_V8 0 +#define CS_MODE_M68K_000 0 +#define CS_MODE_M68K_010 0 +#define CS_MODE_M68K_020 0 +#define CS_MODE_M68K_030 0 +#define CS_MODE_M68K_040 0 +#define CS_MODE_M68K_060 0#define CS_MODE_MICRO 0#define CS_MODE_MIPS3 0#define CS_MODE_MIPS32R6 0
@@ -44,6 +51,19 @@#define CS_MODE_LOONGARCH64 0#endif +#if CS_API_MAJOR <6 +#define CS_MODE_M68K_CF_ISA_A 0 +#define CS_MODE_M68K_CF_ISA_A_PLUS 0 +#define CS_MODE_M68K_CF_ISA_B 0 +#define CS_MODE_M68K_CF_ISA_C 0 +#define CS_MODE_M68K_CF_USP 0 +#define CS_MODE_M68K_CF_DIV 0 +#define CS_MODE_M68K_CF_MAC 0 +#define CS_MODE_M68K_CF_EMAC 0 +#define CS_MODE_M68K_CF_EMAC_B 0 +#define CS_MODE_M68K_CF_FPU 0 +#endif +#if CS_API_MAJOR <5 #define CS_ARCH_RISCV -1#define CS_MODE_RISCV32 0
target/m68k/cpu.c +64 -1
80 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 8/9] target/m68k: Enable disassembly via capstone
Quoted 5 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 20 +++++++++++++ target/m68k/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-)
PATCH 9/9 target/mips: Enable disassembly via capstone
In reply to Richard Henderson--- include/disas/capstone.h | 24 ++++++++++++++-- target/mips/cpu.c | 60 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-)
include/disas/capstone.h +21 -3
@@ -29,6 +29,7 @@#define CS_MODE_THUMB 0#define CS_MODE_MCLASS 0#define CS_MODE_V8 0 +#define CS_MODE_V9 0#define CS_MODE_M68K_000 0#define CS_MODE_M68K_010 0#define CS_MODE_M68K_020 0
@@ -36,11 +37,10 @@#define CS_MODE_M68K_040 0#define CS_MODE_M68K_060 0#define CS_MODE_MICRO 0 +#define CS_MODE_MIPS2 0#define CS_MODE_MIPS3 0 -#define CS_MODE_MIPS32R6 0 -#define CS_MODE_MIPSGP64 0 -#define CS_MODE_V9 0#define CS_MODE_MIPS32 0 +#define CS_MODE_MIPS32R6 0#define CS_MODE_MIPS64 0#endif /* CONFIG_CAPSTONE */
@@ -64,6 +64,24 @@#define CS_MODE_M68K_CF_FPU 0#endif +#if CS_API_MAJOR <6 +#define CS_MODE_MIPS16 0 +#define CS_MODE_MIPS1 0 +#define CS_MODE_MIPS32R2 0 +#define CS_MODE_MIPS32R3 0 +#define CS_MODE_MIPS32R5 0 +#define CS_MODE_MIPS4 0 +#define CS_MODE_MIPS5 0 +#define CS_MODE_MIPS64R2 0 +#define CS_MODE_MIPS64R3 0 +#define CS_MODE_MIPS64R5 0 +#define CS_MODE_MIPS64R6 0 +#define CS_MODE_OCTEON 0 +#define CS_MODE_OCTEONP 0 +#define CS_MODE_NANOMIPS 0 +#define CS_MODE_MIPS_PTR64 0 +#endif +#if CS_API_MAJOR <5 #define CS_ARCH_RISCV -1#define CS_MODE_RISCV32 0
target/mips/cpu.c +56 -4
77 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 9/9] target/mips: Enable disassembly via capstone
Quoted 23 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/disas/capstone.h | 24 ++++++++++++++-- target/mips/cpu.c | 60 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-)target/mips/cpu.c +1
-0@@ -30,6 +30,7 @@#include "system/qtest.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-clock.h" +#include "disas/capstone.h" #include "fpu_helper.h" #ifndef CONFIG_USER_ONLY #include "semihosting/semihost.h" @@ -488,15 +489,66 @@ static void mips_cpu_disas_set_info(const CPUState *cs, disassemble_info *info) {const MIPSCPU *cpu =MIPS_CPU (cs);const CPUMIPSState *env = &cpu->env;
target/mips/cpu.c static void mips_cpu_disas_set_info(const CPUState *cs, disassemble_info *info) · line 500
Quoted 10 lines
target/mips/cpu.c +8
-1+bool is64 = env->hflags &MIPS_HFLAG_64 ; +int cap_mode =0 ; -if (!(env->insn_flags &ISA_NANOMIPS32 )) { +if (env->insn_flags &ISA_NANOMIPS32 ) { + info->print_insn = print_insn_nanomips; + info->endian =BFD_ENDIAN_LITTLE ; +/* nanomips has 16, 32 and 48-bit insns */ + info->cap_insn_unit =2 ; + info->cap_insn_split =6 ;
Cool.
Quoted 57 lines
target/mips/cpu.c +47
-3+ 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; - }else { - info->print_insn = print_insn_nanomips; - info->endian =BFD_ENDIAN_LITTLE ; + +if (env->hflags &MIPS_HFLAG_M16 ) { + cap_mode = (env->insn_flags &ASE_MICROMIPS + ?CS_MODE_MICRO :CS_MODE_MIPS16 ); +/* Beware unsupported capstone mode */ +if (cap_mode ==0 ) { +return ; + } + info->cap_insn_unit =2 ; + }else { + info->cap_insn_unit =4 ; + } + info->cap_insn_split =4 ; + + cap_mode |= is64 ?CS_MODE_MIPS64 :CS_MODE_MIPS32 ; +if (env->insn_flags &ISA_MIPS_R6 ) { + cap_mode |= is64 ?CS_MODE_MIPS64R6 :CS_MODE_MIPS32R6 ; + }else if (env->insn_flags &ISA_MIPS_R5 ) { + cap_mode |= is64 ?CS_MODE_MIPS64R5 :CS_MODE_MIPS32R5 ; + }else if (env->insn_flags &ISA_MIPS_R3 ) { + cap_mode |= is64 ?CS_MODE_MIPS64R3 :CS_MODE_MIPS32R3 ; + }else if (env->insn_flags &ISA_MIPS_R2 ) { + cap_mode |= is64 ?CS_MODE_MIPS64R2 :CS_MODE_MIPS32R2 ; + }else if (env->insn_flags &ISA_MIPS5 ) { + cap_mode |=CS_MODE_MIPS5 ; + }else if (env->insn_flags &ISA_MIPS4 ) { + cap_mode |=CS_MODE_MIPS4 ; + }else if (env->insn_flags &ISA_MIPS3 ) { + cap_mode |=CS_MODE_MIPS3 ; + }else if (env->insn_flags &ISA_MIPS2 ) { + cap_mode |=CS_MODE_MIPS2 ; + }else if (env->insn_flags &ISA_MIPS1 ) { + cap_mode |=CS_MODE_MIPS1 ; + } +if (env->insn_flags &INSN_OCTEON ) { + cap_mode |=CS_MODE_OCTEON |CS_MODE_OCTEONP ; + } +if (is64 && !(env->hflags &MIPS_HFLAG_AWRAP )) { + cap_mode |=CS_MODE_MIPS_PTR64 ; + } + } +/* Beware unsupported capstone mode */ +if (cap_mode) { + info->cap_arch =CS_ARCH_MIPS ; + info->cap_mode = cap_mode; } }