From d49190c4208f2c556c3a01962a81f8a85d522bb1 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Sun, 24 May 2015 14:20:41 -0700 Subject: [PATCH] disas: Remove uses of CPU env disas does not need to access the CPU env for any reason. Change the APIs to accept CPU pointers instead. Small change pattern needs to be applied to all target translate.c. This brings us closer to making disas.o a common-obj and less architecture specific in general. Cc: Richard Henderson Cc: Peter Maydell Cc: "Edgar E. Iglesias" Cc: Paolo Bonzini Cc: Eduardo Habkost Cc: Michael Walle Cc: Aurelien Jarno Cc: Leon Alrae Cc: Jia Liu Cc: Alexander Graf Cc: Mark Cave-Ayland Cc: Bastian Koppelmann Cc: Guan Xuetao Cc: Max Filippov Reviewed-by: Richard Henderson Reviewed-by: Eduardo Habkost Signed-off-by: Peter Crosthwaite Acked-by: Luiz Capitulino Signed-off-by: Markus Armbruster --- disas.c | 14 +++++++------- include/disas/disas.h | 4 ++-- include/qemu/log.h | 4 ++-- monitor.c | 2 +- target-alpha/translate.c | 2 +- target-arm/translate-a64.c | 2 +- target-arm/translate.c | 2 +- target-cris/translate.c | 2 +- target-i386/translate.c | 2 +- target-lm32/translate.c | 2 +- target-m68k/translate.c | 2 +- target-microblaze/translate.c | 2 +- target-mips/translate.c | 2 +- target-openrisc/translate.c | 2 +- target-ppc/translate.c | 2 +- target-s390x/translate.c | 2 +- target-sh4/translate.c | 2 +- target-sparc/translate.c | 2 +- target-tricore/translate.c | 2 +- target-unicore32/translate.c | 2 +- target-xtensa/translate.c | 2 +- 21 files changed, 29 insertions(+), 29 deletions(-) diff --git a/disas.c b/disas.c index 44a019a2e7..576c6a437b 100644 --- a/disas.c +++ b/disas.c @@ -9,7 +9,7 @@ typedef struct CPUDebug { struct disassemble_info info; - CPUArchState *env; + CPUState *cpu; } CPUDebug; /* Filled in by elfload.c. Simplistic, but will do for now. */ @@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr, { CPUDebug *s = container_of(info, CPUDebug, info); - cpu_memory_rw_debug(ENV_GET_CPU(s->env), memaddr, myaddr, length, 0); + cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); return 0; } @@ -195,7 +195,7 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info) bit 16 indicates little endian. other targets - unused */ -void target_disas(FILE *out, CPUArchState *env, target_ulong code, +void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size, int flags) { target_ulong pc; @@ -205,7 +205,7 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code, INIT_DISASSEMBLE_INFO(s.info, out, fprintf); - s.env = env; + s.cpu = cpu; s.info.read_memory_func = target_read_memory; s.info.buffer_vma = code; s.info.buffer_length = size; @@ -430,7 +430,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length, if (monitor_disas_is_physical) { cpu_physical_memory_read(memaddr, myaddr, length); } else { - cpu_memory_rw_debug(ENV_GET_CPU(s->env), memaddr, myaddr, length, 0); + cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); } return 0; } @@ -447,7 +447,7 @@ monitor_fprintf(FILE *stream, const char *fmt, ...) /* Disassembler for the monitor. See target_disas for a description of flags. */ -void monitor_disas(Monitor *mon, CPUArchState *env, +void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical, int flags) { int count, i; @@ -456,7 +456,7 @@ void monitor_disas(Monitor *mon, CPUArchState *env, INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf); - s.env = env; + s.cpu = cpu; monitor_disas_is_physical = is_physical; s.info.read_memory_func = monitor_read_memory; s.info.print_address_func = generic_print_target_address; diff --git a/include/disas/disas.h b/include/disas/disas.h index c13ca9a3a4..2b9293b62a 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -6,10 +6,10 @@ #ifdef NEED_CPU_H /* Disassemble this for me please... (debugging). */ void disas(FILE *out, void *code, unsigned long size); -void target_disas(FILE *out, CPUArchState *env, target_ulong code, +void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size, int flags); -void monitor_disas(Monitor *mon, CPUArchState *env, +void monitor_disas(Monitor *mon, CPUState *cpu, target_ulong pc, int nb_insn, int is_physical, int flags); /* Look up symbol for debugging purpose. Returns "" if unknown. */ diff --git a/include/qemu/log.h b/include/qemu/log.h index 195f665c4b..f880e66dbc 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -104,10 +104,10 @@ static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags) #ifdef NEED_CPU_H /* disas() and target_disas() to qemu_logfile: */ -static inline void log_target_disas(CPUArchState *env, target_ulong start, +static inline void log_target_disas(CPUState *cpu, target_ulong start, target_ulong len, int flags) { - target_disas(qemu_logfile, env, start, len, flags); + target_disas(qemu_logfile, cpu, start, len, flags); } static inline void log_disas(void *code, unsigned long size) diff --git a/monitor.c b/monitor.c index a5ba7fe828..02b491a830 100644 --- a/monitor.c +++ b/monitor.c @@ -1158,7 +1158,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, flags = msr_le << 16; flags |= env->bfd_mach; #endif - monitor_disas(mon, mon_get_cpu_env(), addr, count, is_physical, flags); + monitor_disas(mon, mon_get_cpu(), addr, count, is_physical, flags); return; } diff --git a/target-alpha/translate.c b/target-alpha/translate.c index e9927b56b4..81d4ff827c 100644 --- a/target-alpha/translate.c +++ b/target-alpha/translate.c @@ -2939,7 +2939,7 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 1); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 1); qemu_log("\n"); } #endif diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index ffa6cb8e56..e077f2dc30 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -11128,7 +11128,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, 4 | (dc->bswap_code << 1)); qemu_log("\n"); } diff --git a/target-arm/translate.c b/target-arm/translate.c index ead08f4820..971b6db061 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -11485,7 +11485,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, dc->thumb | (dc->bswap_code << 1)); qemu_log("\n"); } diff --git a/target-cris/translate.c b/target-cris/translate.c index 687c88be28..3e59601eb4 100644 --- a/target-cris/translate.c +++ b/target-cris/translate.c @@ -3345,7 +3345,7 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, #ifdef DEBUG_DISAS #if !DISAS_CRIS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { - log_target_disas(env, pc_start, dc->pc - pc_start, + log_target_disas(cs, pc_start, dc->pc - pc_start, env->pregs[PR_VR]); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); diff --git a/target-i386/translate.c b/target-i386/translate.c index 58b1959154..7a1bdee271 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -8093,7 +8093,7 @@ done_generating: else #endif disas_flags = !dc->code32; - log_target_disas(env, pc_start, pc_ptr - pc_start, disas_flags); + log_target_disas(cs, pc_start, pc_ptr - pc_start, disas_flags); qemu_log("\n"); } #endif diff --git a/target-lm32/translate.c b/target-lm32/translate.c index 81a204f5cf..cf7042e3e0 100644 --- a/target-lm32/translate.c +++ b/target-lm32/translate.c @@ -1168,7 +1168,7 @@ void gen_intermediate_code_internal(LM32CPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); } diff --git a/target-m68k/translate.c b/target-m68k/translate.c index 4959b970ea..22ecc20410 100644 --- a/target-m68k/translate.c +++ b/target-m68k/translate.c @@ -3077,7 +3077,7 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c index 1f5fe9afcd..f4e969b29c 100644 --- a/target-microblaze/translate.c +++ b/target-microblaze/translate.c @@ -1851,7 +1851,7 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); #if DISAS_GNU - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); #endif qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); diff --git a/target-mips/translate.c b/target-mips/translate.c index 1d128eef02..a2dbad5ed2 100644 --- a/target-mips/translate.c +++ b/target-mips/translate.c @@ -19558,7 +19558,7 @@ done_generating: LOG_DISAS("\n"); if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-openrisc/translate.c b/target-openrisc/translate.c index dc76789785..a62cbf4011 100644 --- a/target-openrisc/translate.c +++ b/target-openrisc/translate.c @@ -1770,7 +1770,7 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("\n"); - log_target_disas(&cpu->env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\nisize=%d osize=%d\n", dc->pc - pc_start, tcg_op_buf_count()); } diff --git a/target-ppc/translate.c b/target-ppc/translate.c index 8f255ea5c2..84c5cead6b 100644 --- a/target-ppc/translate.c +++ b/target-ppc/translate.c @@ -11607,7 +11607,7 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, flags = env->bfd_mach; flags |= ctx.le_mode << 16; qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.nip - pc_start, flags); + log_target_disas(cs, pc_start, ctx.nip - pc_start, flags); qemu_log("\n"); } #endif diff --git a/target-s390x/translate.c b/target-s390x/translate.c index 42f52c70c6..c748290d5c 100644 --- a/target-s390x/translate.c +++ b/target-s390x/translate.c @@ -5446,7 +5446,7 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, #if defined(S390X_DEBUG_DISAS) if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc.pc - pc_start, 1); + log_target_disas(cs, pc_start, dc.pc - pc_start, 1); qemu_log("\n"); } #endif diff --git a/target-sh4/translate.c b/target-sh4/translate.c index 28259f9e14..3b4a1b5cea 100644 --- a/target-sh4/translate.c +++ b/target-sh4/translate.c @@ -1961,7 +1961,7 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN:\n"); /* , lookup_symbol(pc_start)); */ - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-sparc/translate.c b/target-sparc/translate.c index 3708c0148e..c58dd4e95b 100644 --- a/target-sparc/translate.c +++ b/target-sparc/translate.c @@ -5334,7 +5334,7 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("--------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, last_pc + 4 - pc_start, 0); + log_target_disas(cs, pc_start, last_pc + 4 - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-tricore/translate.c b/target-tricore/translate.c index 8d41239617..7dc7a325b4 100644 --- a/target-tricore/translate.c +++ b/target-tricore/translate.c @@ -8324,7 +8324,7 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, ctx.pc - pc_start, 0); + log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-unicore32/translate.c b/target-unicore32/translate.c index 9efcff5faf..2fc78e6f3e 100644 --- a/target-unicore32/translate.c +++ b/target-unicore32/translate.c @@ -2039,7 +2039,7 @@ done_generating: if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc->pc - pc_start, 0); + log_target_disas(cs, pc_start, dc->pc - pc_start, 0); qemu_log("\n"); } #endif diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c index 3d52079233..86e4849fb6 100644 --- a/target-xtensa/translate.c +++ b/target-xtensa/translate.c @@ -3138,7 +3138,7 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); - log_target_disas(env, pc_start, dc.pc - pc_start, 0); + log_target_disas(cs, pc_start, dc.pc - pc_start, 0); qemu_log("\n"); } #endif