X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=disas.c;h=ccdcd2450e3e623a3972784fb01b12fc3545a3d4;hb=420557e8981347368427849ff89ecd3fe537dafa;hp=81ba50a964846eba026756e82543fcd45426c79a;hpb=93ac68bca5a3332ffacd7bf10e7b9c4cfdab6374;p=qemu.git diff --git a/disas.c b/disas.c index 81ba50a96..ccdcd2450 100644 --- a/disas.c +++ b/disas.c @@ -1,10 +1,13 @@ /* General "disassemble this chunk" code. Used for debugging. */ #include "config.h" #include "dis-asm.h" -#include "disas.h" #include "elf.h" #include +#include "cpu.h" +#include "exec-all.h" +#include "disas.h" + /* Filled in by elfload.c. Simplistic, but will do for now. */ unsigned int disas_num_syms; void *disas_symtab; @@ -19,13 +22,31 @@ buffer_read_memory (memaddr, myaddr, length, info) int length; struct disassemble_info *info; { - if (memaddr < info->buffer_vma - || memaddr + length > info->buffer_vma + info->buffer_length) - /* Out of bounds. Use EIO because GDB uses it. */ - return EIO; - memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); - return 0; + if (memaddr < info->buffer_vma + || memaddr + length > info->buffer_vma + info->buffer_length) + /* Out of bounds. Use EIO because GDB uses it. */ + return EIO; + memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); + return 0; +} + +#if !defined(CONFIG_USER_ONLY) +/* Get LENGTH bytes from info's buffer, at target address memaddr. + Transfer them to myaddr. */ +static int +target_read_memory (memaddr, myaddr, length, info) + bfd_vma memaddr; + bfd_byte *myaddr; + int length; + struct disassemble_info *info; +{ + int i; + for(i = 0; i < length; i++) { + myaddr[i] = ldub_code((void *)((long)memaddr + i)); + } + return 0; } +#endif /* Print an error message. We can assume that this is in response to an error return from buffer_read_memory. */ @@ -103,6 +124,12 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags) INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); +#if !defined(CONFIG_USER_ONLY) + if (!is_host) { + disasm_info.read_memory_func = target_read_memory; + } +#endif + disasm_info.buffer = code; disasm_info.buffer_vma = (unsigned long)code; disasm_info.buffer_length = size; @@ -113,9 +140,12 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags) #else disasm_info.endian = BFD_ENDIAN_LITTLE; #endif -#ifdef __i386__ +#if defined(__i386__) disasm_info.mach = bfd_mach_i386_i386; print_insn = print_insn_i386; +#elif defined(__x86_64__) + disasm_info.mach = bfd_mach_x86_64; + print_insn = print_insn_i386; #elif defined(__powerpc__) print_insn = print_insn_ppc; #elif defined(__alpha__) @@ -144,6 +174,8 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags) print_insn = print_insn_arm; #elif defined(TARGET_SPARC) print_insn = print_insn_sparc; +#elif defined(TARGET_PPC) + print_insn = print_insn_ppc; #else fprintf(out, "Asm output not supported on this arch\n"); return; @@ -187,3 +219,80 @@ const char *lookup_symbol(void *orig_addr) } return ""; } + +#if !defined(CONFIG_USER_ONLY) + +void term_vprintf(const char *fmt, va_list ap); +void term_printf(const char *fmt, ...); + +static int monitor_disas_is_physical; + +static int +monitor_read_memory (memaddr, myaddr, length, info) + bfd_vma memaddr; + bfd_byte *myaddr; + int length; + struct disassemble_info *info; +{ + if (monitor_disas_is_physical) { + cpu_physical_memory_rw(memaddr, myaddr, length, 0); + } else { + cpu_memory_rw_debug(cpu_single_env, memaddr,myaddr, length, 0); + } + return 0; +} + +static int monitor_fprintf(FILE *stream, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + term_vprintf(fmt, ap); + va_end(ap); + return 0; +} + +void monitor_disas(target_ulong pc, int nb_insn, int is_physical, int flags) +{ + int count, i; + struct disassemble_info disasm_info; + int (*print_insn)(bfd_vma pc, disassemble_info *info); + + INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf); + + monitor_disas_is_physical = is_physical; + disasm_info.read_memory_func = monitor_read_memory; + + disasm_info.buffer_vma = pc; + +#ifdef TARGET_WORDS_BIGENDIAN + disasm_info.endian = BFD_ENDIAN_BIG; +#else + disasm_info.endian = BFD_ENDIAN_LITTLE; +#endif +#if defined(TARGET_I386) + if (!flags) + disasm_info.mach = bfd_mach_i386_i386; + else + disasm_info.mach = bfd_mach_i386_i8086; + print_insn = print_insn_i386; +#elif defined(TARGET_ARM) + print_insn = print_insn_arm; +#elif defined(TARGET_SPARC) + print_insn = print_insn_sparc; +#elif defined(TARGET_PPC) + print_insn = print_insn_ppc; +#else + fprintf(out, "Asm output not supported on this arch\n"); + return; +#endif + + for(i = 0; i < nb_insn; i++) { + term_printf("0x%08lx: ", (unsigned long)pc); + count = print_insn(pc, &disasm_info); + term_printf("\n"); + if (count < 0) + break; + pc += count; + } +} +#endif