@samitouri / QOSamiQemu / commits / 2b38607286

target/sh4: Enable disassembly via capstone

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed Aug 8, 2026 at 12:47 UTC 2b386072864da25299991c4ca3d30efdd9466376
2 files changed +21
include/disas/capstone.h
+7
@@ -71,4 +71,11 @@
71 #define CS_MODE_RISCV_VENTANA 0
72 #endif
73
74 +#if CS_API_MAJOR < 5
75 +#define CS_ARCH_SH -1
76 +#define CS_MODE_SHFPU 0
77 +#define CS_MODE_SH4 0
78 +#define CS_MODE_SH4A 0
79 +#endif
80 +
81 #endif /* QEMU_CAPSTONE_H */
target/sh4/cpu.c
+14
@@ -28,6 +28,7 @@
28 #include "fpu/softfloat-helpers.h"
29 #include "accel/tcg/cpu-ops.h"
30 #include "tcg/tcg.h"
31 +#include "disas/capstone.h"
32
33 static void superh_cpu_set_pc(CPUState *cs, vaddr value)
34 {
@@ -167,10 +168,23 @@ static void superh_cpu_reset_hold(Object *obj, ResetType type)
168 static void superh_cpu_disas_set_info(const CPUState *cpu,
169 disassemble_info *info)
170 {
171 + const CPUSH4State *env = cpu_env((CPUState *)cpu);
172 +
173 info->endian = TARGET_BIG_ENDIAN ? BFD_ENDIAN_BIG
174 : BFD_ENDIAN_LITTLE;
175 info->mach = bfd_mach_sh4;
176 info->print_insn = print_insn_sh;
177 +
178 + info->cap_arch = CS_ARCH_SH;
179 + info->cap_insn_unit = 2;
180 + info->cap_insn_split = 2;
181 + /*
182 + * Possible capstone bug: the isa levels are not additive:
183 + * least significant bit wins, so SH4 overrides SH4A.
184 + * Work around by setting one or the other but not both.
185 + */
186 + info->cap_mode = CS_MODE_SHFPU
187 + | (env->features & SH_FEATURE_SH4A ? CS_MODE_SH4A : CS_MODE_SH4);
188 }
189
190 static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)