bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 1 | /* General "disassemble this chunk" code. Used for debugging. */ |
bellard | 5bbe929 | 2003-06-09 19:38:38 +0000 | [diff] [blame] | 2 | #include "config.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" |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 6 | #include <errno.h> |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 7 | |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 8 | #include "cpu.h" |
Paolo Bonzini | 76cad71 | 2012-10-24 11:12:21 +0200 | [diff] [blame] | 9 | #include "disas/disas.h" |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 10 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 11 | typedef struct CPUDebug { |
| 12 | struct disassemble_info info; |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 13 | CPUState *cpu; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 14 | } CPUDebug; |
| 15 | |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 16 | /* Filled in by elfload.c. Simplistic, but will do for now. */ |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 17 | struct syminfo *syminfos = NULL; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 18 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 19 | /* Get LENGTH bytes from info's buffer, at target address memaddr. |
| 20 | Transfer them to myaddr. */ |
| 21 | int |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 22 | buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, |
| 23 | struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 24 | { |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 25 | if (memaddr < info->buffer_vma |
| 26 | || memaddr + length > info->buffer_vma + info->buffer_length) |
| 27 | /* Out of bounds. Use EIO because GDB uses it. */ |
| 28 | return EIO; |
| 29 | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); |
| 30 | return 0; |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 31 | } |
| 32 | |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 33 | /* Get LENGTH bytes from info's buffer, at target address memaddr. |
| 34 | Transfer them to myaddr. */ |
| 35 | static int |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 36 | target_read_memory (bfd_vma memaddr, |
| 37 | bfd_byte *myaddr, |
| 38 | int length, |
| 39 | struct disassemble_info *info) |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 40 | { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 41 | CPUDebug *s = container_of(info, CPUDebug, info); |
| 42 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 43 | cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | } |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 46 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 47 | /* Print an error message. We can assume that this is in response to |
| 48 | an error return from buffer_read_memory. */ |
| 49 | void |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 50 | perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 51 | { |
| 52 | if (status != EIO) |
| 53 | /* Can't happen. */ |
| 54 | (*info->fprintf_func) (info->stream, "Unknown error %d\n", status); |
| 55 | else |
| 56 | /* Actually, address between memaddr and memaddr + len was |
| 57 | out of bounds. */ |
| 58 | (*info->fprintf_func) (info->stream, |
bellard | 26a7646 | 2006-06-25 18:15:32 +0000 | [diff] [blame] | 59 | "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Jim Meyering | a31f053 | 2012-05-09 05:12:04 +0000 | [diff] [blame] | 62 | /* This could be in a separate file, to save minuscule amounts of space |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 63 | in statically linked executables. */ |
| 64 | |
| 65 | /* Just print the address is hex. This is included for completeness even |
| 66 | though both GDB and objdump provide their own (to print symbolic |
| 67 | addresses). */ |
| 68 | |
| 69 | void |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 70 | generic_print_address (bfd_vma addr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 71 | { |
bellard | 26a7646 | 2006-06-25 18:15:32 +0000 | [diff] [blame] | 72 | (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr); |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Peter Maydell | 636bd28 | 2012-06-25 04:55:55 +0000 | [diff] [blame] | 75 | /* Print address in hex, truncated to the width of a target virtual address. */ |
| 76 | static void |
| 77 | generic_print_target_address(bfd_vma addr, struct disassemble_info *info) |
| 78 | { |
| 79 | uint64_t mask = ~0ULL >> (64 - TARGET_VIRT_ADDR_SPACE_BITS); |
| 80 | generic_print_address(addr & mask, info); |
| 81 | } |
| 82 | |
| 83 | /* Print address in hex, truncated to the width of a host virtual address. */ |
| 84 | static void |
| 85 | generic_print_host_address(bfd_vma addr, struct disassemble_info *info) |
| 86 | { |
| 87 | uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8)); |
| 88 | generic_print_address(addr & mask, info); |
| 89 | } |
| 90 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 91 | /* Just return the given address. */ |
| 92 | |
| 93 | int |
pbrook | 3a742b7 | 2008-10-22 15:55:18 +0000 | [diff] [blame] | 94 | generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info) |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 95 | { |
| 96 | return 1; |
| 97 | } |
| 98 | |
Aurelien Jarno | 903ec55 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 99 | bfd_vma bfd_getl64 (const bfd_byte *addr) |
| 100 | { |
| 101 | unsigned long long v; |
| 102 | |
| 103 | v = (unsigned long long) addr[0]; |
| 104 | v |= (unsigned long long) addr[1] << 8; |
| 105 | v |= (unsigned long long) addr[2] << 16; |
| 106 | v |= (unsigned long long) addr[3] << 24; |
| 107 | v |= (unsigned long long) addr[4] << 32; |
| 108 | v |= (unsigned long long) addr[5] << 40; |
| 109 | v |= (unsigned long long) addr[6] << 48; |
| 110 | v |= (unsigned long long) addr[7] << 56; |
| 111 | return (bfd_vma) v; |
| 112 | } |
| 113 | |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 114 | bfd_vma bfd_getl32 (const bfd_byte *addr) |
| 115 | { |
| 116 | unsigned long v; |
| 117 | |
| 118 | v = (unsigned long) addr[0]; |
| 119 | v |= (unsigned long) addr[1] << 8; |
| 120 | v |= (unsigned long) addr[2] << 16; |
| 121 | v |= (unsigned long) addr[3] << 24; |
| 122 | return (bfd_vma) v; |
| 123 | } |
| 124 | |
| 125 | bfd_vma bfd_getb32 (const bfd_byte *addr) |
| 126 | { |
| 127 | unsigned long v; |
| 128 | |
| 129 | v = (unsigned long) addr[0] << 24; |
| 130 | v |= (unsigned long) addr[1] << 16; |
| 131 | v |= (unsigned long) addr[2] << 8; |
| 132 | v |= (unsigned long) addr[3]; |
| 133 | return (bfd_vma) v; |
| 134 | } |
| 135 | |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 136 | bfd_vma bfd_getl16 (const bfd_byte *addr) |
| 137 | { |
| 138 | unsigned long v; |
| 139 | |
| 140 | v = (unsigned long) addr[0]; |
| 141 | v |= (unsigned long) addr[1] << 8; |
| 142 | return (bfd_vma) v; |
| 143 | } |
| 144 | |
| 145 | bfd_vma bfd_getb16 (const bfd_byte *addr) |
| 146 | { |
| 147 | unsigned long v; |
| 148 | |
| 149 | v = (unsigned long) addr[0] << 24; |
| 150 | v |= (unsigned long) addr[1] << 16; |
| 151 | return (bfd_vma) v; |
| 152 | } |
| 153 | |
bellard | c2d551f | 2005-04-27 20:15:00 +0000 | [diff] [blame] | 154 | #ifdef TARGET_ARM |
| 155 | static int |
| 156 | print_insn_thumb1(bfd_vma pc, disassemble_info *info) |
| 157 | { |
| 158 | return print_insn_arm(pc | 1, info); |
| 159 | } |
| 160 | #endif |
| 161 | |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 162 | static int print_insn_objdump(bfd_vma pc, disassemble_info *info, |
| 163 | const char *prefix) |
| 164 | { |
| 165 | int i, n = info->buffer_length; |
| 166 | uint8_t *buf = g_malloc(n); |
| 167 | |
| 168 | info->read_memory_func(pc, buf, n, info); |
| 169 | |
| 170 | for (i = 0; i < n; ++i) { |
| 171 | if (i % 32 == 0) { |
| 172 | info->fprintf_func(info->stream, "\n%s: ", prefix); |
| 173 | } |
| 174 | info->fprintf_func(info->stream, "%02x", buf[i]); |
| 175 | } |
| 176 | |
| 177 | g_free(buf); |
| 178 | return n; |
| 179 | } |
| 180 | |
| 181 | static int print_insn_od_host(bfd_vma pc, disassemble_info *info) |
| 182 | { |
| 183 | return print_insn_objdump(pc, info, "OBJD-H"); |
| 184 | } |
| 185 | |
| 186 | static int print_insn_od_target(bfd_vma pc, disassemble_info *info) |
| 187 | { |
| 188 | return print_insn_objdump(pc, info, "OBJD-T"); |
| 189 | } |
| 190 | |
ths | e91c8a7 | 2007-06-03 13:35:16 +0000 | [diff] [blame] | 191 | /* Disassemble this for me please... (debugging). 'flags' has the following |
bellard | c2d551f | 2005-04-27 20:15:00 +0000 | [diff] [blame] | 192 | values: |
Frediano Ziglio | e99722f | 2011-08-25 09:14:38 +0200 | [diff] [blame] | 193 | i386 - 1 means 16 bit code, 2 means 64 bit code |
Claudio Fontana | 999b53e | 2014-02-05 17:27:28 +0000 | [diff] [blame] | 194 | arm - bit 0 = thumb, bit 1 = reverse endian, bit 2 = A64 |
Tom Musta | e13951f | 2014-04-09 14:53:23 -0500 | [diff] [blame] | 195 | ppc - bits 0:15 specify (optionally) the machine instruction set; |
| 196 | bit 16 indicates little endian. |
bellard | c2d551f | 2005-04-27 20:15:00 +0000 | [diff] [blame] | 197 | other targets - unused |
| 198 | */ |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 199 | void target_disas(FILE *out, CPUState *cpu, target_ulong code, |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 200 | target_ulong size, int flags) |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 201 | { |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame^] | 202 | CPUClass *cc = CPU_GET_CLASS(cpu); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 203 | target_ulong pc; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 204 | int count; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 205 | CPUDebug s; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 206 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 207 | INIT_DISASSEMBLE_INFO(s.info, out, fprintf); |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 208 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 209 | s.cpu = cpu; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 210 | s.info.read_memory_func = target_read_memory; |
| 211 | s.info.buffer_vma = code; |
| 212 | s.info.buffer_length = size; |
| 213 | s.info.print_address_func = generic_print_target_address; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 214 | |
| 215 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 216 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 217 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 218 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 219 | #endif |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame^] | 220 | |
| 221 | if (cc->disas_set_info) { |
| 222 | cc->disas_set_info(cpu, &s.info); |
| 223 | } |
| 224 | |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 225 | #if defined(TARGET_I386) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 226 | if (flags == 2) { |
| 227 | s.info.mach = bfd_mach_x86_64; |
| 228 | } else if (flags == 1) { |
| 229 | s.info.mach = bfd_mach_i386_i8086; |
| 230 | } else { |
| 231 | s.info.mach = bfd_mach_i386_i386; |
| 232 | } |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 233 | s.info.print_insn = print_insn_i386; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 234 | #elif defined(TARGET_ARM) |
Claudio Fontana | 999b53e | 2014-02-05 17:27:28 +0000 | [diff] [blame] | 235 | if (flags & 4) { |
| 236 | /* We might not be compiled with the A64 disassembler |
| 237 | * because it needs a C++ compiler; in that case we will |
| 238 | * fall through to the default print_insn_od case. |
| 239 | */ |
| 240 | #if defined(CONFIG_ARM_A64_DIS) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 241 | s.info.print_insn = print_insn_arm_a64; |
Claudio Fontana | 999b53e | 2014-02-05 17:27:28 +0000 | [diff] [blame] | 242 | #endif |
| 243 | } else if (flags & 1) { |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 244 | s.info.print_insn = print_insn_thumb1; |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 245 | } else { |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 246 | s.info.print_insn = print_insn_arm; |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 247 | } |
| 248 | if (flags & 2) { |
| 249 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 250 | s.info.endian = BFD_ENDIAN_LITTLE; |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 251 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 252 | s.info.endian = BFD_ENDIAN_BIG; |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 253 | #endif |
| 254 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 255 | #elif defined(TARGET_SPARC) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 256 | s.info.print_insn = print_insn_sparc; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 257 | #ifdef TARGET_SPARC64 |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 258 | s.info.mach = bfd_mach_sparc_v9b; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 259 | #endif |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 260 | #elif defined(TARGET_PPC) |
Tom Musta | e13951f | 2014-04-09 14:53:23 -0500 | [diff] [blame] | 261 | if ((flags >> 16) & 1) { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 262 | s.info.endian = BFD_ENDIAN_LITTLE; |
| 263 | } |
j_mayer | 237c0af | 2007-09-29 12:01:46 +0000 | [diff] [blame] | 264 | if (flags & 0xFFFF) { |
Tom Musta | e13951f | 2014-04-09 14:53:23 -0500 | [diff] [blame] | 265 | /* If we have a precise definition of the instruction set, use it. */ |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 266 | s.info.mach = flags & 0xFFFF; |
j_mayer | 237c0af | 2007-09-29 12:01:46 +0000 | [diff] [blame] | 267 | } else { |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 268 | #ifdef TARGET_PPC64 |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 269 | s.info.mach = bfd_mach_ppc64; |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 270 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 271 | s.info.mach = bfd_mach_ppc; |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 272 | #endif |
j_mayer | 237c0af | 2007-09-29 12:01:46 +0000 | [diff] [blame] | 273 | } |
Aurelien Jarno | 88770fe | 2013-04-20 08:56:14 +0000 | [diff] [blame] | 274 | s.info.disassembler_options = (char *)"any"; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 275 | s.info.print_insn = print_insn_ppc; |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 276 | #elif defined(TARGET_M68K) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 277 | s.info.print_insn = print_insn_m68k; |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 278 | #elif defined(TARGET_MIPS) |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 279 | #ifdef TARGET_WORDS_BIGENDIAN |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 280 | s.info.print_insn = print_insn_big_mips; |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 281 | #else |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 282 | s.info.print_insn = print_insn_little_mips; |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 283 | #endif |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 284 | #elif defined(TARGET_SH4) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 285 | s.info.mach = bfd_mach_sh4; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 286 | s.info.print_insn = print_insn_sh; |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 287 | #elif defined(TARGET_ALPHA) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 288 | s.info.mach = bfd_mach_alpha_ev6; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 289 | s.info.print_insn = print_insn_alpha; |
ths | a25fd13 | 2007-10-08 12:46:58 +0000 | [diff] [blame] | 290 | #elif defined(TARGET_CRIS) |
Edgar E. Iglesias | b09cd07 | 2011-01-10 22:31:09 +0100 | [diff] [blame] | 291 | if (flags != 32) { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 292 | s.info.mach = bfd_mach_cris_v0_v10; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 293 | s.info.print_insn = print_insn_crisv10; |
Edgar E. Iglesias | b09cd07 | 2011-01-10 22:31:09 +0100 | [diff] [blame] | 294 | } else { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 295 | s.info.mach = bfd_mach_cris_v32; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 296 | s.info.print_insn = print_insn_crisv32; |
Edgar E. Iglesias | b09cd07 | 2011-01-10 22:31:09 +0100 | [diff] [blame] | 297 | } |
Ulrich Hecht | db50060 | 2011-03-29 15:29:32 +0200 | [diff] [blame] | 298 | #elif defined(TARGET_S390X) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 299 | s.info.mach = bfd_mach_s390_64; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 300 | s.info.print_insn = print_insn_s390; |
Edgar E. Iglesias | e90e390 | 2009-05-20 20:07:38 +0200 | [diff] [blame] | 301 | #elif defined(TARGET_MICROBLAZE) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 302 | s.info.mach = bfd_arch_microblaze; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 303 | s.info.print_insn = print_insn_microblaze; |
Anthony Green | bd86a88 | 2013-03-18 15:49:23 -0400 | [diff] [blame] | 304 | #elif defined(TARGET_MOXIE) |
| 305 | s.info.mach = bfd_arch_moxie; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 306 | s.info.print_insn = print_insn_moxie; |
Michael Walle | 79368f4 | 2012-03-31 19:54:20 +0200 | [diff] [blame] | 307 | #elif defined(TARGET_LM32) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 308 | s.info.mach = bfd_mach_lm32; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 309 | s.info.print_insn = print_insn_lm32; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 310 | #endif |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 311 | if (s.info.print_insn == NULL) { |
| 312 | s.info.print_insn = print_insn_od_target; |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 313 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 314 | |
blueswir1 | 7e000c2 | 2009-02-13 21:44:41 +0000 | [diff] [blame] | 315 | for (pc = code; size > 0; pc += count, size -= count) { |
bellard | fa15e03 | 2005-01-31 23:32:31 +0000 | [diff] [blame] | 316 | fprintf(out, "0x" TARGET_FMT_lx ": ", pc); |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 317 | count = s.info.print_insn(pc, &s.info); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 318 | #if 0 |
| 319 | { |
| 320 | int i; |
| 321 | uint8_t b; |
| 322 | fprintf(out, " {"); |
| 323 | for(i = 0; i < count; i++) { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 324 | target_read_memory(pc + i, &b, 1, &s.info); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 325 | fprintf(out, " %02x", b); |
| 326 | } |
| 327 | fprintf(out, " }"); |
| 328 | } |
| 329 | #endif |
| 330 | fprintf(out, "\n"); |
| 331 | if (count < 0) |
| 332 | break; |
malc | 754d00a | 2009-04-21 22:26:22 +0000 | [diff] [blame] | 333 | if (size < count) { |
| 334 | fprintf(out, |
| 335 | "Disassembler disagrees with translator over instruction " |
| 336 | "decoding\n" |
| 337 | "Please report this to qemu-devel@nongnu.org\n"); |
| 338 | break; |
| 339 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
| 343 | /* Disassemble this for me please... (debugging). */ |
| 344 | void disas(FILE *out, void *code, unsigned long size) |
| 345 | { |
Stefan Weil | b0b0f1c | 2012-04-12 15:44:35 +0200 | [diff] [blame] | 346 | uintptr_t pc; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 347 | int count; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 348 | CPUDebug s; |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 349 | int (*print_insn)(bfd_vma pc, disassemble_info *info) = NULL; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 350 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 351 | INIT_DISASSEMBLE_INFO(s.info, out, fprintf); |
| 352 | s.info.print_address_func = generic_print_host_address; |
bellard | c6105c0 | 2003-10-27 21:13:58 +0000 | [diff] [blame] | 353 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 354 | s.info.buffer = code; |
| 355 | s.info.buffer_vma = (uintptr_t)code; |
| 356 | s.info.buffer_length = size; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 357 | |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 358 | #ifdef HOST_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 359 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 360 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 361 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 362 | #endif |
Stefan Weil | 5826e51 | 2011-10-05 20:03:53 +0200 | [diff] [blame] | 363 | #if defined(CONFIG_TCG_INTERPRETER) |
| 364 | print_insn = print_insn_tci; |
| 365 | #elif defined(__i386__) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 366 | s.info.mach = bfd_mach_i386_i386; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 367 | print_insn = print_insn_i386; |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 368 | #elif defined(__x86_64__) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 369 | s.info.mach = bfd_mach_x86_64; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 370 | print_insn = print_insn_i386; |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 371 | #elif defined(_ARCH_PPC) |
Richard Henderson | 66d4f6a | 2013-01-31 11:16:21 -0800 | [diff] [blame] | 372 | s.info.disassembler_options = (char *)"any"; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 373 | print_insn = print_insn_ppc; |
Claudio Fontana | 999b53e | 2014-02-05 17:27:28 +0000 | [diff] [blame] | 374 | #elif defined(__aarch64__) && defined(CONFIG_ARM_A64_DIS) |
| 375 | print_insn = print_insn_arm_a64; |
bellard | a993ba8 | 2003-05-11 12:25:45 +0000 | [diff] [blame] | 376 | #elif defined(__alpha__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 377 | print_insn = print_insn_alpha; |
bellard | aa0aa4f | 2003-06-09 15:23:31 +0000 | [diff] [blame] | 378 | #elif defined(__sparc__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 379 | print_insn = print_insn_sparc; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 380 | s.info.mach = bfd_mach_sparc_v9b; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 381 | #elif defined(__arm__) |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 382 | print_insn = print_insn_arm; |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 383 | #elif defined(__MIPSEB__) |
| 384 | print_insn = print_insn_big_mips; |
| 385 | #elif defined(__MIPSEL__) |
| 386 | print_insn = print_insn_little_mips; |
bellard | 48024e4 | 2005-11-06 16:52:11 +0000 | [diff] [blame] | 387 | #elif defined(__m68k__) |
| 388 | print_insn = print_insn_m68k; |
ths | 8f860bb | 2007-07-31 23:44:21 +0000 | [diff] [blame] | 389 | #elif defined(__s390__) |
| 390 | print_insn = print_insn_s390; |
aurel32 | f54b3f9 | 2008-04-12 20:14:54 +0000 | [diff] [blame] | 391 | #elif defined(__hppa__) |
| 392 | print_insn = print_insn_hppa; |
Aurelien Jarno | 903ec55 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 393 | #elif defined(__ia64__) |
| 394 | print_insn = print_insn_ia64; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 395 | #endif |
Richard Henderson | c46ffd5 | 2013-08-16 23:29:45 -0700 | [diff] [blame] | 396 | if (print_insn == NULL) { |
| 397 | print_insn = print_insn_od_host; |
| 398 | } |
Stefan Weil | b0b0f1c | 2012-04-12 15:44:35 +0200 | [diff] [blame] | 399 | for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { |
| 400 | fprintf(out, "0x%08" PRIxPTR ": ", pc); |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 401 | count = print_insn(pc, &s.info); |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 402 | fprintf(out, "\n"); |
| 403 | if (count < 0) |
| 404 | break; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /* Look up symbol for debugging purpose. Returns "" if unknown. */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 409 | const char *lookup_symbol(target_ulong orig_addr) |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 410 | { |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 411 | const char *symbol = ""; |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 412 | struct syminfo *s; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 413 | |
bellard | e80cfcf | 2004-12-19 23:18:01 +0000 | [diff] [blame] | 414 | for (s = syminfos; s; s = s->next) { |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 415 | symbol = s->lookup_symbol(s, orig_addr); |
| 416 | if (symbol[0] != '\0') { |
| 417 | break; |
| 418 | } |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 419 | } |
pbrook | 49918a7 | 2008-10-22 15:11:31 +0000 | [diff] [blame] | 420 | |
| 421 | return symbol; |
bellard | b9adb4a | 2003-04-29 20:41:16 +0000 | [diff] [blame] | 422 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 423 | |
| 424 | #if !defined(CONFIG_USER_ONLY) |
| 425 | |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 426 | #include "monitor/monitor.h" |
bellard | 3d2cfdf | 2004-08-01 21:49:07 +0000 | [diff] [blame] | 427 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 428 | static int monitor_disas_is_physical; |
| 429 | |
| 430 | static int |
blueswir1 | a5f1b96 | 2008-08-17 20:21:51 +0000 | [diff] [blame] | 431 | monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length, |
| 432 | struct disassemble_info *info) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 433 | { |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 434 | CPUDebug *s = container_of(info, CPUDebug, info); |
| 435 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 436 | if (monitor_disas_is_physical) { |
Stefan Weil | 54f7b4a | 2011-04-10 18:23:39 +0200 | [diff] [blame] | 437 | cpu_physical_memory_read(memaddr, myaddr, length); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 438 | } else { |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 439 | cpu_memory_rw_debug(s->cpu, memaddr, myaddr, length, 0); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 440 | } |
| 441 | return 0; |
| 442 | } |
| 443 | |
Stefan Weil | 8b7968f | 2010-09-23 21:28:05 +0200 | [diff] [blame] | 444 | static int GCC_FMT_ATTR(2, 3) |
| 445 | monitor_fprintf(FILE *stream, const char *fmt, ...) |
bellard | 3d2cfdf | 2004-08-01 21:49:07 +0000 | [diff] [blame] | 446 | { |
| 447 | va_list ap; |
| 448 | va_start(ap, fmt); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 449 | monitor_vprintf((Monitor *)stream, fmt, ap); |
bellard | 3d2cfdf | 2004-08-01 21:49:07 +0000 | [diff] [blame] | 450 | va_end(ap); |
| 451 | return 0; |
| 452 | } |
| 453 | |
Tom Musta | 1c38f84 | 2014-04-09 14:53:24 -0500 | [diff] [blame] | 454 | /* Disassembler for the monitor. |
| 455 | See target_disas for a description of flags. */ |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 456 | void monitor_disas(Monitor *mon, CPUState *cpu, |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 457 | target_ulong pc, int nb_insn, int is_physical, int flags) |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 458 | { |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame^] | 459 | CPUClass *cc = CPU_GET_CLASS(cpu); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 460 | int count, i; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 461 | CPUDebug s; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 462 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 463 | INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 464 | |
Peter Crosthwaite | d49190c | 2015-05-24 14:20:41 -0700 | [diff] [blame] | 465 | s.cpu = cpu; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 466 | monitor_disas_is_physical = is_physical; |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 467 | s.info.read_memory_func = monitor_read_memory; |
| 468 | s.info.print_address_func = generic_print_target_address; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 469 | |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 470 | s.info.buffer_vma = pc; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 471 | |
| 472 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 473 | s.info.endian = BFD_ENDIAN_BIG; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 474 | #else |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 475 | s.info.endian = BFD_ENDIAN_LITTLE; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 476 | #endif |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame^] | 477 | |
| 478 | if (cc->disas_set_info) { |
| 479 | cc->disas_set_info(cpu, &s.info); |
| 480 | } |
| 481 | |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 482 | #if defined(TARGET_I386) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 483 | if (flags == 2) { |
| 484 | s.info.mach = bfd_mach_x86_64; |
| 485 | } else if (flags == 1) { |
| 486 | s.info.mach = bfd_mach_i386_i8086; |
| 487 | } else { |
| 488 | s.info.mach = bfd_mach_i386_i386; |
| 489 | } |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 490 | s.info.print_insn = print_insn_i386; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 491 | #elif defined(TARGET_ARM) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 492 | s.info.print_insn = print_insn_arm; |
ths | cbd669d | 2007-12-25 00:26:36 +0000 | [diff] [blame] | 493 | #elif defined(TARGET_ALPHA) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 494 | s.info.print_insn = print_insn_alpha; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 495 | #elif defined(TARGET_SPARC) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 496 | s.info.print_insn = print_insn_sparc; |
blueswir1 | 682c4f1 | 2007-04-09 15:14:57 +0000 | [diff] [blame] | 497 | #ifdef TARGET_SPARC64 |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 498 | s.info.mach = bfd_mach_sparc_v9b; |
blueswir1 | 682c4f1 | 2007-04-09 15:14:57 +0000 | [diff] [blame] | 499 | #endif |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 500 | #elif defined(TARGET_PPC) |
Tom Musta | 1c38f84 | 2014-04-09 14:53:24 -0500 | [diff] [blame] | 501 | if (flags & 0xFFFF) { |
| 502 | /* If we have a precise definition of the instruction set, use it. */ |
| 503 | s.info.mach = flags & 0xFFFF; |
| 504 | } else { |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 505 | #ifdef TARGET_PPC64 |
Tom Musta | 1c38f84 | 2014-04-09 14:53:24 -0500 | [diff] [blame] | 506 | s.info.mach = bfd_mach_ppc64; |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 507 | #else |
Tom Musta | 1c38f84 | 2014-04-09 14:53:24 -0500 | [diff] [blame] | 508 | s.info.mach = bfd_mach_ppc; |
bellard | a245862 | 2005-07-23 22:39:53 +0000 | [diff] [blame] | 509 | #endif |
Tom Musta | 1c38f84 | 2014-04-09 14:53:24 -0500 | [diff] [blame] | 510 | } |
| 511 | if ((flags >> 16) & 1) { |
| 512 | s.info.endian = BFD_ENDIAN_LITTLE; |
| 513 | } |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 514 | s.info.print_insn = print_insn_ppc; |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 515 | #elif defined(TARGET_M68K) |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 516 | s.info.print_insn = print_insn_m68k; |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 517 | #elif defined(TARGET_MIPS) |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 518 | #ifdef TARGET_WORDS_BIGENDIAN |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 519 | s.info.print_insn = print_insn_big_mips; |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 520 | #else |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 521 | s.info.print_insn = print_insn_little_mips; |
bellard | 76b3030 | 2005-12-17 01:10:04 +0000 | [diff] [blame] | 522 | #endif |
Magnus Damm | b4e1f07 | 2009-11-13 18:54:22 +0900 | [diff] [blame] | 523 | #elif defined(TARGET_SH4) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 524 | s.info.mach = bfd_mach_sh4; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 525 | s.info.print_insn = print_insn_sh; |
Ulrich Hecht | db50060 | 2011-03-29 15:29:32 +0200 | [diff] [blame] | 526 | #elif defined(TARGET_S390X) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 527 | s.info.mach = bfd_mach_s390_64; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 528 | s.info.print_insn = print_insn_s390; |
Anthony Green | bd86a88 | 2013-03-18 15:49:23 -0400 | [diff] [blame] | 529 | #elif defined(TARGET_MOXIE) |
| 530 | s.info.mach = bfd_arch_moxie; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 531 | s.info.print_insn = print_insn_moxie; |
Michael Walle | 79368f4 | 2012-03-31 19:54:20 +0200 | [diff] [blame] | 532 | #elif defined(TARGET_LM32) |
Blue Swirl | f4359b9 | 2012-09-08 12:40:00 +0000 | [diff] [blame] | 533 | s.info.mach = bfd_mach_lm32; |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 534 | s.info.print_insn = print_insn_lm32; |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 535 | #endif |
Peter Crosthwaite | 37b9de4 | 2015-06-23 20:57:33 -0700 | [diff] [blame^] | 536 | if (!s.info.print_insn) { |
| 537 | monitor_printf(mon, "0x" TARGET_FMT_lx |
| 538 | ": Asm output not supported on this arch\n", pc); |
| 539 | return; |
| 540 | } |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 541 | |
| 542 | for(i = 0; i < nb_insn; i++) { |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 543 | monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); |
Peter Crosthwaite | 2de295c | 2015-06-23 20:57:32 -0700 | [diff] [blame] | 544 | count = s.info.print_insn(pc, &s.info); |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 545 | monitor_printf(mon, "\n"); |
bellard | 9307c4c | 2004-04-04 12:57:25 +0000 | [diff] [blame] | 546 | if (count < 0) |
| 547 | break; |
| 548 | pc += count; |
| 549 | } |
| 550 | } |
| 551 | #endif |