disas: QOMify target specific setup

Add a QOM function hook for target-specific disassembly setup. This
allows removal of the #ifdeffery currently implementing target specific
disas setup from disas.c.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Peter Crosthwaite 2015-06-23 20:57:33 -07:00 committed by Andreas Färber
parent 2de295c544
commit 37b9de463b
2 changed files with 22 additions and 4 deletions

22
disas.c
View File

@ -1,5 +1,6 @@
/* General "disassemble this chunk" code. Used for debugging. */ /* General "disassemble this chunk" code. Used for debugging. */
#include "config.h" #include "config.h"
#include "qemu-common.h"
#include "disas/bfd.h" #include "disas/bfd.h"
#include "elf.h" #include "elf.h"
#include <errno.h> #include <errno.h>
@ -198,6 +199,7 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)
void target_disas(FILE *out, CPUState *cpu, target_ulong code, void target_disas(FILE *out, CPUState *cpu, target_ulong code,
target_ulong size, int flags) target_ulong size, int flags)
{ {
CPUClass *cc = CPU_GET_CLASS(cpu);
target_ulong pc; target_ulong pc;
int count; int count;
CPUDebug s; CPUDebug s;
@ -215,6 +217,11 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
#else #else
s.info.endian = BFD_ENDIAN_LITTLE; s.info.endian = BFD_ENDIAN_LITTLE;
#endif #endif
if (cc->disas_set_info) {
cc->disas_set_info(cpu, &s.info);
}
#if defined(TARGET_I386) #if defined(TARGET_I386)
if (flags == 2) { if (flags == 2) {
s.info.mach = bfd_mach_x86_64; s.info.mach = bfd_mach_x86_64;
@ -449,6 +456,7 @@ monitor_fprintf(FILE *stream, const char *fmt, ...)
void monitor_disas(Monitor *mon, CPUState *cpu, void monitor_disas(Monitor *mon, CPUState *cpu,
target_ulong pc, int nb_insn, int is_physical, int flags) target_ulong pc, int nb_insn, int is_physical, int flags)
{ {
CPUClass *cc = CPU_GET_CLASS(cpu);
int count, i; int count, i;
CPUDebug s; CPUDebug s;
@ -466,6 +474,11 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
#else #else
s.info.endian = BFD_ENDIAN_LITTLE; s.info.endian = BFD_ENDIAN_LITTLE;
#endif #endif
if (cc->disas_set_info) {
cc->disas_set_info(cpu, &s.info);
}
#if defined(TARGET_I386) #if defined(TARGET_I386)
if (flags == 2) { if (flags == 2) {
s.info.mach = bfd_mach_x86_64; s.info.mach = bfd_mach_x86_64;
@ -519,11 +532,12 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
#elif defined(TARGET_LM32) #elif defined(TARGET_LM32)
s.info.mach = bfd_mach_lm32; s.info.mach = bfd_mach_lm32;
s.info.print_insn = print_insn_lm32; s.info.print_insn = print_insn_lm32;
#else
monitor_printf(mon, "0x" TARGET_FMT_lx
": Asm output not supported on this arch\n", pc);
return;
#endif #endif
if (!s.info.print_insn) {
monitor_printf(mon, "0x" TARGET_FMT_lx
": Asm output not supported on this arch\n", pc);
return;
}
for(i = 0; i < nb_insn; i++) { for(i = 0; i < nb_insn; i++) {
monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);

View File

@ -23,6 +23,7 @@
#include <signal.h> #include <signal.h>
#include <setjmp.h> #include <setjmp.h>
#include "hw/qdev-core.h" #include "hw/qdev-core.h"
#include "disas/bfd.h"
#include "exec/hwaddr.h" #include "exec/hwaddr.h"
#include "exec/memattrs.h" #include "exec/memattrs.h"
#include "qemu/queue.h" #include "qemu/queue.h"
@ -117,6 +118,7 @@ struct TranslationBlock;
* @cpu_exec_enter: Callback for cpu_exec preparation. * @cpu_exec_enter: Callback for cpu_exec preparation.
* @cpu_exec_exit: Callback for cpu_exec cleanup. * @cpu_exec_exit: Callback for cpu_exec cleanup.
* @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec. * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
* @disas_set_info: Setup architecture specific components of disassembly info
* *
* Represents a CPU family or model. * Represents a CPU family or model.
*/ */
@ -172,6 +174,8 @@ typedef struct CPUClass {
void (*cpu_exec_enter)(CPUState *cpu); void (*cpu_exec_enter)(CPUState *cpu);
void (*cpu_exec_exit)(CPUState *cpu); void (*cpu_exec_exit)(CPUState *cpu);
bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
} CPUClass; } CPUClass;
#ifdef HOST_WORDS_BIGENDIAN #ifdef HOST_WORDS_BIGENDIAN