bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 1 | /* General "disassemble this chunk" code. Used for debugging. */ |
Peter Maydell | d38ea87 | 2016-01-29 17:50:05 +0000 | [diff] [blame] | 2 | #include "qemu/osdep.h" |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 3 | #include "qemu-common.h" |
Paolo Bonzini | 76cad71 | 2012-10-24 11:12:21 +0200 | [diff] [blame] | 4 | #include "disas/bfd.h" |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 5 | #include "elf.h" |
| 6 | |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 7 | #include "cpu.h" |
Paolo Bonzini | 76cad71 | 2012-10-24 11:12:21 +0200 | [diff] [blame] | 8 | #include "disas/disas.h" |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 9 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 10 | typedef struct CPUDebug { |
| 11 | struct disassemble_info info; |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 12 | CPUState *cpu; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 13 | } CPUDebug; |
| 14 | |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 15 | /* Filled in by elfload.c. Simplistic, but will do for now. */ |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 16 | struct syminfo *syminfos = NULL; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 17 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 18 | /* Get LENGTH bytes from info's buffer, at target address memaddr. |
| 19 | Transfer them to myaddr. */ |
| 20 | int |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 21 | buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, |
| 22 | struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 23 | { |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 24 | if (memaddr < info->buffer_vma |
| 25 | || memaddr + length > info->buffer_vma + info->buffer_length) |
| 26 | /* Out of bounds. Use EIO because GDB uses it. */ |
| 27 | return EIO; |
| 28 | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); |
| 29 | return 0; |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 30 | } |
| 31 | |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 32 | /* Get LENGTH bytes from info's buffer, at target address memaddr. |
| 33 | Transfer them to myaddr. */ |
| 34 | static int |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 35 | target_read_memory (bfd_vma memaddr, |
| 36 | bfd_byte *myaddr, |
| 37 | int length, |
| 38 | struct disassemble_info *info) |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 39 | { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 40 | CPUDebug *s = container_of(info, CPUDebug, info); |
| 41 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 42 | cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 43 | return 0; |
| 44 | } |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 45 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 46 | /* Print an error message. We can assume that this is in response to |
| 47 | an error return from buffer_read_memory. */ |
| 48 | void |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 49 | perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 50 | { |
| 51 | if (status != EIO) |
| 52 | /* Can't happen. */ |
| 53 | (*info->fprintf_func) (info->stream, "Unknown error %d\n", status); |
| 54 | else |
| 55 | /* Actually, address between memaddr and memaddr + len was |
| 56 | out of bounds. */ |
| 57 | (*info->fprintf_func) (info->stream, |
bellard | 26a7646 | 2006-06-25 18:15:32 +0000 | [diff] [blame] | 58 | "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Jim Meyering | a31f053 | 2012-05-09 05:12:04 +0000 | [diff] [blame] | 61 | /* This could be in a separate file, to save minuscule amounts of space |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 62 | in statically linked executables. */ |
| 63 | |
| 64 | /* Just print the address is hex. This is included for completeness even |
| 65 | though both GDB and objdump provide their own (to print symbolic |
| 66 | addresses). */ |
| 67 | |
| 68 | void |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 69 | generic_print_address (bfd_vma addr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 70 | { |
bellard | 26a7646 | 2006-06-25 18:15:32 +0000 | [diff] [blame] | 71 | (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr); |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Peter Maydell | 636bd28 | 2012-06-25 04:55:55 +0000 | [diff] [blame] | 74 | /* Print address in hex, truncated to the width of a host virtual address. */ |
| 75 | static void |
| 76 | generic_print_host_address(bfd_vma addr, struct disassemble_info *info) |
| 77 | { |
| 78 | uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8)); |
| 79 | generic_print_address(addr & mask, info); |
| 80 | } |
| 81 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 82 | /* Just return the given address. */ |
| 83 | |
| 84 | int |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 85 | generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 86 | { |
| 87 | return 1; |
| 88 | } |
| 89 | |
Aurelien Jarno | 903ec55 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 90 | bfd_vma bfd_getl64 (const bfd_byte *addr) |
| 91 | { |
| 92 | unsigned long long v; |
| 93 | |
| 94 | v = (unsigned long long) addr[0]; |
| 95 | v |= (unsigned long long) addr[1] << 8; |
| 96 | v |= (unsigned long long) addr[2] << 16; |
| 97 | v |= (unsigned long long) addr[3] << 24; |
| 98 | v |= (unsigned long long) addr[4] << 32; |
| 99 | v |= (unsigned long long) addr[5] << 40; |
| 100 | v |= (unsigned long long) addr[6] << 48; |
| 101 | v |= (unsigned long long) addr[7] << 56; |
| 102 | return (bfd_vma) v; |
| 103 | } |
| 104 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 105 | bfd_vma bfd_getl32 (const bfd_byte *addr) |
| 106 | { |
| 107 | unsigned long v; |
| 108 | |
| 109 | v = (unsigned long) addr[0]; |
| 110 | v |= (unsigned long) addr[1] << 8; |
| 111 | v |= (unsigned long) addr[2] << 16; |
| 112 | v |= (unsigned long) addr[3] << 24; |
| 113 | return (bfd_vma) v; |
| 114 | } |
| 115 | |
| 116 | bfd_vma bfd_getb32 (const bfd_byte *addr) |
| 117 | { |
| 118 | unsigned long v; |
| 119 | |
| 120 | v = (unsigned long) addr[0] << 24; |
| 121 | v |= (unsigned long) addr[1] << 16; |
| 122 | v |= (unsigned long) addr[2] << 8; |
| 123 | v |= (unsigned long) addr[3]; |
| 124 | return (bfd_vma) v; |
| 125 | } |
| 126 | |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 127 | bfd_vma bfd_getl16 (const bfd_byte *addr) |
| 128 | { |
| 129 | unsigned long v; |
| 130 | |
| 131 | v = (unsigned long) addr[0]; |
| 132 | v |= (unsigned long) addr[1] << 8; |
| 133 | return (bfd_vma) v; |
| 134 | } |
| 135 | |
| 136 | bfd_vma bfd_getb16 (const bfd_byte *addr) |
| 137 | { |
| 138 | unsigned long v; |
| 139 | |
| 140 | v = (unsigned long) addr[0] << 24; |
| 141 | v |= (unsigned long) addr[1] << 16; |
| 142 | return (bfd_vma) v; |
| 143 | } |
| 144 | |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 145 | static int print_insn_objdump(bfd_vma pc, disassemble_info *info, |
| 146 | const char *prefix) |
| 147 | { |
| 148 | int i, n = info->buffer_length; |
| 149 | uint8_t *buf = g_malloc(n); |
| 150 | |
| 151 | info->read_memory_func(pc, buf, n, info); |
| 152 | |
| 153 | for (i = 0; i < n; ++i) { |
| 154 | if (i % 32 == 0) { |
| 155 | info->fprintf_func(info->stream, "\n%s: ", prefix); |
| 156 | } |
| 157 | info->fprintf_func(info->stream, "%02x", buf[i]); |
| 158 | } |
| 159 | |
| 160 | g_free(buf); |
| 161 | return n; |
| 162 | } |
| 163 | |
| 164 | static int print_insn_od_host(bfd_vma pc, disassemble_info *info) |
| 165 | { |
| 166 | return print_insn_objdump(pc, info, "OBJD-H"); |
| 167 | } |
| 168 | |
| 169 | static int print_insn_od_target(bfd_vma pc, disassemble_info *info) |
| 170 | { |
| 171 | return print_insn_objdump(pc, info, "OBJD-T"); |
| 172 | } |
| 173 | |
Richard Henderson | 1d48474 | 2017-09-14 08:38:35 -0700 | [diff] [blame^] | 174 | /* Disassemble this for me please... (debugging). */ |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 175 | void target_disas(FILE *out, CPUState *cpu, target_ulong code, |
Richard Henderson | 1d48474 | 2017-09-14 08:38:35 -0700 | [diff] [blame^] | 176 | target_ulong size) |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 177 | { |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 178 | CPUClass *cc = CPU_GET_CLASS(cpu); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 179 | target_ulong pc; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 180 | int count; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 181 | CPUDebug s; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 182 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 183 | INIT_DISASSEMBLE_INFO(s.info, out, fprintf); |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 184 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 185 | s.cpu = cpu; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 186 | s.info.read_memory_func = target_read_memory; |
| 187 | s.info.buffer_vma = code; |
| 188 | s.info.buffer_length = size; |
Peter Crosthwaite | 9504c54 | 2015-07-05 13:50:32 -0700 | [diff] [blame] | 189 | s.info.print_address_func = generic_print_address; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 190 | |
| 191 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 192 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 193 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 194 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 195 | #endif |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 196 | |
| 197 | if (cc->disas_set_info) { |
| 198 | cc->disas_set_info(cpu, &s.info); |
| 199 | } |
| 200 | |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 201 | if (s.info.print_insn == NULL) { |
| 202 | s.info.print_insn = print_insn_od_target; |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 203 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 204 | |
blueswir1 | 7e000c2 | 2009-02-13 21:44:41 +0000 | [diff] [blame] | 205 | for (pc = code; size > 0; pc += count, size -= count) { |
bellard | fa15e03 | 2005-01-31 23:32:31 +0000 | [diff] [blame] | 206 | fprintf(out, "0x" TARGET_FMT_lx ": ", pc); |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 207 | count = s.info.print_insn(pc, &s.info); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 208 | #if 0 |
| 209 | { |
| 210 | int i; |
| 211 | uint8_t b; |
| 212 | fprintf(out, " {"); |
| 213 | for(i = 0; i < count; i++) { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 214 | target_read_memory(pc + i, &b, 1, &s.info); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 215 | fprintf(out, " %02x", b); |
| 216 | } |
| 217 | fprintf(out, " }"); |
| 218 | } |
| 219 | #endif |
| 220 | fprintf(out, "\n"); |
| 221 | if (count < 0) |
| 222 | break; |
malc | 754d00a | 2009-04-21 22:26:22 +0000 | [diff] [blame] | 223 | if (size < count) { |
| 224 | fprintf(out, |
| 225 | "Disassembler disagrees with translator over instruction " |
| 226 | "decoding\n" |
| 227 | "Please report this to qemu-devel@nongnu.org\n"); |
| 228 | break; |
| 229 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | /* Disassemble this for me please... (debugging). */ |
| 234 | void disas(FILE *out, void *code, unsigned long size) |
| 235 | { |
Stefan Weil | b0b0f1c | 2012-04-12 15:44:35 +0200 | [diff] [blame] | 236 | uintptr_t pc; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 237 | int count; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 238 | CPUDebug s; |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 239 | int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 240 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 241 | INIT_DISASSEMBLE_INFO(s.info, out, fprintf); |
| 242 | s.info.print_address_func = generic_print_host_address; |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 243 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 244 | s.info.buffer = code; |
| 245 | s.info.buffer_vma = (uintptr_t)code; |
| 246 | s.info.buffer_length = size; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 247 | |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 248 | #ifdef HOST_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 249 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 250 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 251 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 252 | #endif |
Stefan Weil | 5826e51 | 2011-10-05 20:03:53 +0200 | [diff] [blame] | 253 | #if defined(CONFIG_TCG_INTERPRETER) |
| 254 | print_insn = print_insn_tci; |
| 255 | #elif defined(__i386__) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 256 | s.info.mach = bfd_mach_i386_i386; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 257 | print_insn = print_insn_i386; |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 258 | #elif defined(__x86_64__) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 259 | s.info.mach = bfd_mach_x86_64; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 260 | print_insn = print_insn_i386; |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 261 | #elif defined(_ARCH_PPC) |
Richard Henderson | 66d4f6a | 2013-01-31 11:16:21 -0800 | [diff] [blame] | 262 | s.info.disassembler_options = (char *)"any"; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 263 | print_insn = print_insn_ppc; |
Claudio Fontana | 999b53e | 2014-02-05 17:27:28 +0000 | [diff] [blame] | 264 | #elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) |
| 265 | print_insn = print_insn_arm_a64; |
bellard | a993ba8 | 2003-05-11 12:25:45 +0000 | [diff] [blame] | 266 | #elif defined(__alpha__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 267 | print_insn = print_insn_alpha; |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 268 | #elif defined(__sparc__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 269 | print_insn = print_insn_sparc; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 270 | s.info.mach = bfd_mach_sparc_v9b; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 271 | #elif defined(__arm__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 272 | print_insn = print_insn_arm; |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 273 | #elif defined(__MIPSEB__) |
| 274 | print_insn = print_insn_big_mips; |
| 275 | #elif defined(__MIPSEL__) |
| 276 | print_insn = print_insn_little_mips; |
bellard | 48024e4 | 2005-11-06 16:52:11 +0000 | [diff] [blame] | 277 | #elif defined(__m68k__) |
| 278 | print_insn = print_insn_m68k; |
ths | 8f860bb | 2007-07-31 23:44:21 +0000 | [diff] [blame] | 279 | #elif defined(__s390__) |
| 280 | print_insn = print_insn_s390; |
Richard Henderson | 429b31a | 2016-09-29 10:55:53 -0700 | [diff] [blame] | 281 | #elif defined(__hppa__) |
| 282 | print_insn = print_insn_hppa; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 283 | #endif |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 284 | if (print_insn == NULL) { |
| 285 | print_insn = print_insn_od_host; |
| 286 | } |
Stefan Weil | b0b0f1c | 2012-04-12 15:44:35 +0200 | [diff] [blame] | 287 | for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { |
| 288 | fprintf(out, "0x%08" PRIxPTR ": ", pc); |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 289 | count = print_insn(pc, &s.info); |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 290 | fprintf(out, "\n"); |
| 291 | if (count < 0) |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /* Look up symbol for debugging purpose. Returns "" if unknown. */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 297 | const char *lookup_symbol(target_ulong orig_addr) |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 298 | { |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 299 | const char *symbol = ""; |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 300 | struct syminfo *s; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 301 | |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 302 | for (s = syminfos; s; s = s->next) { |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 303 | symbol = s->lookup_symbol(s, orig_addr); |
| 304 | if (symbol[0] != '\0') { |
| 305 | break; |
| 306 | } |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 307 | } |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 308 | |
| 309 | return symbol; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 310 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 311 | |
| 312 | #if !defined(CONFIG_USER_ONLY) |
| 313 | |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 314 | #include "monitor/monitor.h" |
bellard | 3d2cfdf | 2004-08-01 21:49:07 +0000 | [diff] [blame] | 315 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 316 | static int monitor_disas_is_physical; |
| 317 | |
| 318 | static int |
blueswir1 | a5f1b96 | 2008-08-17 20:21:51 +0000 | [diff] [blame] | 319 | monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length, |
| 320 | struct disassemble_info *info) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 321 | { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 322 | CPUDebug *s = container_of(info, CPUDebug, info); |
| 323 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 324 | if (monitor_disas_is_physical) { |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 325 | cpu_physical_memory_read(memaddr, myaddr, length); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 326 | } else { |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 327 | cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 328 | } |
| 329 | return 0; |
| 330 | } |
| 331 | |
Richard Henderson | 1d48474 | 2017-09-14 08:38:35 -0700 | [diff] [blame^] | 332 | /* Disassembler for the monitor. */ |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 333 | void monitor_disas(Monitor *mon, CPUState *cpu, |
Richard Henderson | 1d48474 | 2017-09-14 08:38:35 -0700 | [diff] [blame^] | 334 | target_ulong pc, int nb_insn, int is_physical) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 335 | { |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 336 | CPUClass *cc = CPU_GET_CLASS(cpu); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 337 | int count, i; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 338 | CPUDebug s; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 339 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 340 | INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 341 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 342 | s.cpu = cpu; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 343 | monitor_disas_is_physical = is_physical; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 344 | s.info.read_memory_func = monitor_read_memory; |
Peter Crosthwaite | 9504c54 | 2015-07-05 13:50:32 -0700 | [diff] [blame] | 345 | s.info.print_address_func = generic_print_address; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 346 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 347 | s.info.buffer_vma = pc; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 348 | |
| 349 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 350 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 351 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 352 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 353 | #endif |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 354 | |
| 355 | if (cc->disas_set_info) { |
| 356 | cc->disas_set_info(cpu, &s.info); |
| 357 | } |
| 358 | |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame] | 359 | if (!s.info.print_insn) { |
| 360 | monitor_printf(mon, "0x" TARGET_FMT_lx |
| 361 | ": Asm output not supported on this arch\n", pc); |
| 362 | return; |
| 363 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 364 | |
| 365 | for(i = 0; i < nb_insn; i++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 366 | monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 367 | count = s.info.print_insn(pc, &s.info); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 368 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 369 | if (count < 0) |
| 370 | break; |
| 371 | pc += count; |
| 372 | } |
| 373 | } |
| 374 | #endif |