blob: 7b2acc9943028a7bc8372a21e4bce26c72792ec1 [file] [log] [blame]
bellardb9adb4a2003-04-29 20:41:16 +00001/* General "disassemble this chunk" code. Used for debugging. */
bellard5bbe9292003-06-09 19:38:38 +00002#include "config.h"
bellardb9adb4a2003-04-29 20:41:16 +00003#include "dis-asm.h"
bellardb9adb4a2003-04-29 20:41:16 +00004#include "elf.h"
bellardaa0aa4f2003-06-09 15:23:31 +00005#include <errno.h>
bellardb9adb4a2003-04-29 20:41:16 +00006
bellardc6105c02003-10-27 21:13:58 +00007#include "cpu.h"
bellard9307c4c2004-04-04 12:57:25 +00008#include "disas.h"
bellardc6105c02003-10-27 21:13:58 +00009
bellardb9adb4a2003-04-29 20:41:16 +000010/* Filled in by elfload.c. Simplistic, but will do for now. */
bellarde80cfcf2004-12-19 23:18:01 +000011struct syminfo *syminfos = NULL;
bellardb9adb4a2003-04-29 20:41:16 +000012
bellardaa0aa4f2003-06-09 15:23:31 +000013/* Get LENGTH bytes from info's buffer, at target address memaddr.
14 Transfer them to myaddr. */
15int
pbrook3a742b72008-10-22 15:55:18 +000016buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
17 struct disassemble_info *info)
bellardaa0aa4f2003-06-09 15:23:31 +000018{
bellardc6105c02003-10-27 21:13:58 +000019 if (memaddr < info->buffer_vma
20 || memaddr + length > info->buffer_vma + info->buffer_length)
21 /* Out of bounds. Use EIO because GDB uses it. */
22 return EIO;
23 memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
24 return 0;
bellardaa0aa4f2003-06-09 15:23:31 +000025}
26
bellardc6105c02003-10-27 21:13:58 +000027/* Get LENGTH bytes from info's buffer, at target address memaddr.
28 Transfer them to myaddr. */
29static int
bellardc27004e2005-01-03 23:35:10 +000030target_read_memory (bfd_vma memaddr,
31 bfd_byte *myaddr,
32 int length,
33 struct disassemble_info *info)
bellardc6105c02003-10-27 21:13:58 +000034{
Blue Swirle612a1f2009-05-07 17:14:07 +000035 cpu_memory_rw_debug(cpu_single_env, memaddr, myaddr, length, 0);
bellardc6105c02003-10-27 21:13:58 +000036 return 0;
37}
bellardc6105c02003-10-27 21:13:58 +000038
bellardaa0aa4f2003-06-09 15:23:31 +000039/* Print an error message. We can assume that this is in response to
40 an error return from buffer_read_memory. */
41void
pbrook3a742b72008-10-22 15:55:18 +000042perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info)
bellardaa0aa4f2003-06-09 15:23:31 +000043{
44 if (status != EIO)
45 /* Can't happen. */
46 (*info->fprintf_func) (info->stream, "Unknown error %d\n", status);
47 else
48 /* Actually, address between memaddr and memaddr + len was
49 out of bounds. */
50 (*info->fprintf_func) (info->stream,
bellard26a76462006-06-25 18:15:32 +000051 "Address 0x%" PRIx64 " is out of bounds.\n", memaddr);
bellardaa0aa4f2003-06-09 15:23:31 +000052}
53
Jim Meyeringa31f0532012-05-09 05:12:04 +000054/* This could be in a separate file, to save minuscule amounts of space
bellardaa0aa4f2003-06-09 15:23:31 +000055 in statically linked executables. */
56
57/* Just print the address is hex. This is included for completeness even
58 though both GDB and objdump provide their own (to print symbolic
59 addresses). */
60
61void
pbrook3a742b72008-10-22 15:55:18 +000062generic_print_address (bfd_vma addr, struct disassemble_info *info)
bellardaa0aa4f2003-06-09 15:23:31 +000063{
bellard26a76462006-06-25 18:15:32 +000064 (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr);
bellardaa0aa4f2003-06-09 15:23:31 +000065}
66
Peter Maydell636bd282012-06-25 04:55:55 +000067/* Print address in hex, truncated to the width of a target virtual address. */
68static void
69generic_print_target_address(bfd_vma addr, struct disassemble_info *info)
70{
71 uint64_t mask = ~0ULL >> (64 - TARGET_VIRT_ADDR_SPACE_BITS);
72 generic_print_address(addr & mask, info);
73}
74
75/* Print address in hex, truncated to the width of a host virtual address. */
76static void
77generic_print_host_address(bfd_vma addr, struct disassemble_info *info)
78{
79 uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8));
80 generic_print_address(addr & mask, info);
81}
82
bellardaa0aa4f2003-06-09 15:23:31 +000083/* Just return the given address. */
84
85int
pbrook3a742b72008-10-22 15:55:18 +000086generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info)
bellardaa0aa4f2003-06-09 15:23:31 +000087{
88 return 1;
89}
90
Aurelien Jarno903ec552010-03-29 02:12:51 +020091bfd_vma bfd_getl64 (const bfd_byte *addr)
92{
93 unsigned long long v;
94
95 v = (unsigned long long) addr[0];
96 v |= (unsigned long long) addr[1] << 8;
97 v |= (unsigned long long) addr[2] << 16;
98 v |= (unsigned long long) addr[3] << 24;
99 v |= (unsigned long long) addr[4] << 32;
100 v |= (unsigned long long) addr[5] << 40;
101 v |= (unsigned long long) addr[6] << 48;
102 v |= (unsigned long long) addr[7] << 56;
103 return (bfd_vma) v;
104}
105
bellardaa0aa4f2003-06-09 15:23:31 +0000106bfd_vma bfd_getl32 (const bfd_byte *addr)
107{
108 unsigned long v;
109
110 v = (unsigned long) addr[0];
111 v |= (unsigned long) addr[1] << 8;
112 v |= (unsigned long) addr[2] << 16;
113 v |= (unsigned long) addr[3] << 24;
114 return (bfd_vma) v;
115}
116
117bfd_vma bfd_getb32 (const bfd_byte *addr)
118{
119 unsigned long v;
120
121 v = (unsigned long) addr[0] << 24;
122 v |= (unsigned long) addr[1] << 16;
123 v |= (unsigned long) addr[2] << 8;
124 v |= (unsigned long) addr[3];
125 return (bfd_vma) v;
126}
127
bellard6af0bf92005-07-02 14:58:51 +0000128bfd_vma bfd_getl16 (const bfd_byte *addr)
129{
130 unsigned long v;
131
132 v = (unsigned long) addr[0];
133 v |= (unsigned long) addr[1] << 8;
134 return (bfd_vma) v;
135}
136
137bfd_vma bfd_getb16 (const bfd_byte *addr)
138{
139 unsigned long v;
140
141 v = (unsigned long) addr[0] << 24;
142 v |= (unsigned long) addr[1] << 16;
143 return (bfd_vma) v;
144}
145
bellardc2d551f2005-04-27 20:15:00 +0000146#ifdef TARGET_ARM
147static int
148print_insn_thumb1(bfd_vma pc, disassemble_info *info)
149{
150 return print_insn_arm(pc | 1, info);
151}
152#endif
153
thse91c8a72007-06-03 13:35:16 +0000154/* Disassemble this for me please... (debugging). 'flags' has the following
bellardc2d551f2005-04-27 20:15:00 +0000155 values:
Frediano Ziglioe99722f2011-08-25 09:14:38 +0200156 i386 - 1 means 16 bit code, 2 means 64 bit code
Paul Brookd8fd2952012-03-30 18:02:50 +0100157 arm - bit 0 = thumb, bit 1 = reverse endian
bellard6a00d602005-11-21 23:25:50 +0000158 ppc - nonzero means little endian
bellardc2d551f2005-04-27 20:15:00 +0000159 other targets - unused
160 */
bellard83b34f82005-01-23 20:26:30 +0000161void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
bellardb9adb4a2003-04-29 20:41:16 +0000162{
bellardc27004e2005-01-03 23:35:10 +0000163 target_ulong pc;
bellardb9adb4a2003-04-29 20:41:16 +0000164 int count;
165 struct disassemble_info disasm_info;
166 int (*print_insn)(bfd_vma pc, disassemble_info *info);
167
168 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
169
bellardc27004e2005-01-03 23:35:10 +0000170 disasm_info.read_memory_func = target_read_memory;
171 disasm_info.buffer_vma = code;
172 disasm_info.buffer_length = size;
Peter Maydell636bd282012-06-25 04:55:55 +0000173 disasm_info.print_address_func = generic_print_target_address;
bellardc27004e2005-01-03 23:35:10 +0000174
175#ifdef TARGET_WORDS_BIGENDIAN
176 disasm_info.endian = BFD_ENDIAN_BIG;
177#else
178 disasm_info.endian = BFD_ENDIAN_LITTLE;
bellardc6105c02003-10-27 21:13:58 +0000179#endif
bellardc27004e2005-01-03 23:35:10 +0000180#if defined(TARGET_I386)
181 if (flags == 2)
182 disasm_info.mach = bfd_mach_x86_64;
ths5fafdf22007-09-16 21:08:06 +0000183 else if (flags == 1)
bellardc27004e2005-01-03 23:35:10 +0000184 disasm_info.mach = bfd_mach_i386_i8086;
185 else
186 disasm_info.mach = bfd_mach_i386_i386;
187 print_insn = print_insn_i386;
188#elif defined(TARGET_ARM)
Paul Brookd8fd2952012-03-30 18:02:50 +0100189 if (flags & 1) {
190 print_insn = print_insn_thumb1;
191 } else {
192 print_insn = print_insn_arm;
193 }
194 if (flags & 2) {
195#ifdef TARGET_WORDS_BIGENDIAN
196 disasm_info.endian = BFD_ENDIAN_LITTLE;
197#else
198 disasm_info.endian = BFD_ENDIAN_BIG;
199#endif
200 }
bellardc27004e2005-01-03 23:35:10 +0000201#elif defined(TARGET_SPARC)
202 print_insn = print_insn_sparc;
bellard34751872005-07-02 14:31:34 +0000203#ifdef TARGET_SPARC64
204 disasm_info.mach = bfd_mach_sparc_v9b;
ths3b46e622007-09-17 08:09:54 +0000205#endif
bellardc27004e2005-01-03 23:35:10 +0000206#elif defined(TARGET_PPC)
j_mayer237c0af2007-09-29 12:01:46 +0000207 if (flags >> 16)
bellard111bfab2005-04-23 18:16:07 +0000208 disasm_info.endian = BFD_ENDIAN_LITTLE;
j_mayer237c0af2007-09-29 12:01:46 +0000209 if (flags & 0xFFFF) {
210 /* If we have a precise definitions of the instructions set, use it */
211 disasm_info.mach = flags & 0xFFFF;
212 } else {
bellarda2458622005-07-23 22:39:53 +0000213#ifdef TARGET_PPC64
j_mayer237c0af2007-09-29 12:01:46 +0000214 disasm_info.mach = bfd_mach_ppc64;
bellarda2458622005-07-23 22:39:53 +0000215#else
j_mayer237c0af2007-09-29 12:01:46 +0000216 disasm_info.mach = bfd_mach_ppc;
bellarda2458622005-07-23 22:39:53 +0000217#endif
j_mayer237c0af2007-09-29 12:01:46 +0000218 }
bellardc27004e2005-01-03 23:35:10 +0000219 print_insn = print_insn_ppc;
pbrooke6e59062006-10-22 00:18:54 +0000220#elif defined(TARGET_M68K)
221 print_insn = print_insn_m68k;
bellard6af0bf92005-07-02 14:58:51 +0000222#elif defined(TARGET_MIPS)
bellard76b30302005-12-17 01:10:04 +0000223#ifdef TARGET_WORDS_BIGENDIAN
bellard6af0bf92005-07-02 14:58:51 +0000224 print_insn = print_insn_big_mips;
bellard76b30302005-12-17 01:10:04 +0000225#else
226 print_insn = print_insn_little_mips;
227#endif
bellardfdf9b3e2006-04-27 21:07:38 +0000228#elif defined(TARGET_SH4)
229 disasm_info.mach = bfd_mach_sh4;
230 print_insn = print_insn_sh;
j_mayereddf68a2007-04-05 07:22:49 +0000231#elif defined(TARGET_ALPHA)
Richard Hendersonb9bec752011-04-10 10:31:20 -0700232 disasm_info.mach = bfd_mach_alpha_ev6;
j_mayereddf68a2007-04-05 07:22:49 +0000233 print_insn = print_insn_alpha;
thsa25fd132007-10-08 12:46:58 +0000234#elif defined(TARGET_CRIS)
Edgar E. Iglesiasb09cd072011-01-10 22:31:09 +0100235 if (flags != 32) {
236 disasm_info.mach = bfd_mach_cris_v0_v10;
237 print_insn = print_insn_crisv10;
238 } else {
239 disasm_info.mach = bfd_mach_cris_v32;
240 print_insn = print_insn_crisv32;
241 }
Ulrich Hechtdb500602011-03-29 15:29:32 +0200242#elif defined(TARGET_S390X)
243 disasm_info.mach = bfd_mach_s390_64;
244 print_insn = print_insn_s390;
Edgar E. Iglesiase90e3902009-05-20 20:07:38 +0200245#elif defined(TARGET_MICROBLAZE)
246 disasm_info.mach = bfd_arch_microblaze;
247 print_insn = print_insn_microblaze;
Michael Walle79368f42012-03-31 19:54:20 +0200248#elif defined(TARGET_LM32)
249 disasm_info.mach = bfd_mach_lm32;
250 print_insn = print_insn_lm32;
bellardc27004e2005-01-03 23:35:10 +0000251#else
bellardb8076a72005-04-07 22:20:31 +0000252 fprintf(out, "0x" TARGET_FMT_lx
253 ": Asm output not supported on this arch\n", code);
bellardc27004e2005-01-03 23:35:10 +0000254 return;
255#endif
256
blueswir17e000c22009-02-13 21:44:41 +0000257 for (pc = code; size > 0; pc += count, size -= count) {
bellardfa15e032005-01-31 23:32:31 +0000258 fprintf(out, "0x" TARGET_FMT_lx ": ", pc);
bellardc27004e2005-01-03 23:35:10 +0000259 count = print_insn(pc, &disasm_info);
260#if 0
261 {
262 int i;
263 uint8_t b;
264 fprintf(out, " {");
265 for(i = 0; i < count; i++) {
266 target_read_memory(pc + i, &b, 1, &disasm_info);
267 fprintf(out, " %02x", b);
268 }
269 fprintf(out, " }");
270 }
271#endif
272 fprintf(out, "\n");
273 if (count < 0)
274 break;
malc754d00a2009-04-21 22:26:22 +0000275 if (size < count) {
276 fprintf(out,
277 "Disassembler disagrees with translator over instruction "
278 "decoding\n"
279 "Please report this to qemu-devel@nongnu.org\n");
280 break;
281 }
bellardc27004e2005-01-03 23:35:10 +0000282 }
283}
284
285/* Disassemble this for me please... (debugging). */
286void disas(FILE *out, void *code, unsigned long size)
287{
Stefan Weilb0b0f1c2012-04-12 15:44:35 +0200288 uintptr_t pc;
bellardc27004e2005-01-03 23:35:10 +0000289 int count;
290 struct disassemble_info disasm_info;
291 int (*print_insn)(bfd_vma pc, disassemble_info *info);
292
293 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
Peter Maydell636bd282012-06-25 04:55:55 +0000294 disasm_info.print_address_func = generic_print_host_address;
bellardc6105c02003-10-27 21:13:58 +0000295
bellardb9adb4a2003-04-29 20:41:16 +0000296 disasm_info.buffer = code;
Stefan Weilb0b0f1c2012-04-12 15:44:35 +0200297 disasm_info.buffer_vma = (uintptr_t)code;
bellardb9adb4a2003-04-29 20:41:16 +0000298 disasm_info.buffer_length = size;
299
Juan Quintelae2542fe2009-07-27 16:13:06 +0200300#ifdef HOST_WORDS_BIGENDIAN
bellardc27004e2005-01-03 23:35:10 +0000301 disasm_info.endian = BFD_ENDIAN_BIG;
bellardb9adb4a2003-04-29 20:41:16 +0000302#else
bellardc27004e2005-01-03 23:35:10 +0000303 disasm_info.endian = BFD_ENDIAN_LITTLE;
bellardb9adb4a2003-04-29 20:41:16 +0000304#endif
Stefan Weil5826e512011-10-05 20:03:53 +0200305#if defined(CONFIG_TCG_INTERPRETER)
306 print_insn = print_insn_tci;
307#elif defined(__i386__)
bellardc27004e2005-01-03 23:35:10 +0000308 disasm_info.mach = bfd_mach_i386_i386;
309 print_insn = print_insn_i386;
bellardbc51c5c2004-03-17 23:46:04 +0000310#elif defined(__x86_64__)
bellardc27004e2005-01-03 23:35:10 +0000311 disasm_info.mach = bfd_mach_x86_64;
312 print_insn = print_insn_i386;
malce58ffeb2009-01-14 18:39:49 +0000313#elif defined(_ARCH_PPC)
bellardc27004e2005-01-03 23:35:10 +0000314 print_insn = print_insn_ppc;
bellarda993ba82003-05-11 12:25:45 +0000315#elif defined(__alpha__)
bellardc27004e2005-01-03 23:35:10 +0000316 print_insn = print_insn_alpha;
bellardaa0aa4f2003-06-09 15:23:31 +0000317#elif defined(__sparc__)
bellardc27004e2005-01-03 23:35:10 +0000318 print_insn = print_insn_sparc;
blueswir16ecd4532007-04-08 11:22:29 +0000319#if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
320 disasm_info.mach = bfd_mach_sparc_v9b;
321#endif
ths5fafdf22007-09-16 21:08:06 +0000322#elif defined(__arm__)
bellardc27004e2005-01-03 23:35:10 +0000323 print_insn = print_insn_arm;
bellard6af0bf92005-07-02 14:58:51 +0000324#elif defined(__MIPSEB__)
325 print_insn = print_insn_big_mips;
326#elif defined(__MIPSEL__)
327 print_insn = print_insn_little_mips;
bellard48024e42005-11-06 16:52:11 +0000328#elif defined(__m68k__)
329 print_insn = print_insn_m68k;
ths8f860bb2007-07-31 23:44:21 +0000330#elif defined(__s390__)
331 print_insn = print_insn_s390;
aurel32f54b3f92008-04-12 20:14:54 +0000332#elif defined(__hppa__)
333 print_insn = print_insn_hppa;
Aurelien Jarno903ec552010-03-29 02:12:51 +0200334#elif defined(__ia64__)
335 print_insn = print_insn_ia64;
bellardb9adb4a2003-04-29 20:41:16 +0000336#else
bellardb8076a72005-04-07 22:20:31 +0000337 fprintf(out, "0x%lx: Asm output not supported on this arch\n",
338 (long) code);
bellardc27004e2005-01-03 23:35:10 +0000339 return;
bellardb9adb4a2003-04-29 20:41:16 +0000340#endif
Stefan Weilb0b0f1c2012-04-12 15:44:35 +0200341 for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) {
342 fprintf(out, "0x%08" PRIxPTR ": ", pc);
bellardc27004e2005-01-03 23:35:10 +0000343 count = print_insn(pc, &disasm_info);
bellardb9adb4a2003-04-29 20:41:16 +0000344 fprintf(out, "\n");
345 if (count < 0)
346 break;
347 }
348}
349
350/* Look up symbol for debugging purpose. Returns "" if unknown. */
bellardc27004e2005-01-03 23:35:10 +0000351const char *lookup_symbol(target_ulong orig_addr)
bellardb9adb4a2003-04-29 20:41:16 +0000352{
pbrook49918a72008-10-22 15:11:31 +0000353 const char *symbol = "";
bellarde80cfcf2004-12-19 23:18:01 +0000354 struct syminfo *s;
ths3b46e622007-09-17 08:09:54 +0000355
bellarde80cfcf2004-12-19 23:18:01 +0000356 for (s = syminfos; s; s = s->next) {
pbrook49918a72008-10-22 15:11:31 +0000357 symbol = s->lookup_symbol(s, orig_addr);
358 if (symbol[0] != '\0') {
359 break;
360 }
bellardb9adb4a2003-04-29 20:41:16 +0000361 }
pbrook49918a72008-10-22 15:11:31 +0000362
363 return symbol;
bellardb9adb4a2003-04-29 20:41:16 +0000364}
bellard9307c4c2004-04-04 12:57:25 +0000365
366#if !defined(CONFIG_USER_ONLY)
367
aliguori376253e2009-03-05 23:01:23 +0000368#include "monitor.h"
bellard3d2cfdf2004-08-01 21:49:07 +0000369
bellard9307c4c2004-04-04 12:57:25 +0000370static int monitor_disas_is_physical;
Andreas Färber9349b4f2012-03-14 01:38:32 +0100371static CPUArchState *monitor_disas_env;
bellard9307c4c2004-04-04 12:57:25 +0000372
373static int
blueswir1a5f1b962008-08-17 20:21:51 +0000374monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
375 struct disassemble_info *info)
bellard9307c4c2004-04-04 12:57:25 +0000376{
377 if (monitor_disas_is_physical) {
Stefan Weil54f7b4a2011-04-10 18:23:39 +0200378 cpu_physical_memory_read(memaddr, myaddr, length);
bellard9307c4c2004-04-04 12:57:25 +0000379 } else {
bellard6a00d602005-11-21 23:25:50 +0000380 cpu_memory_rw_debug(monitor_disas_env, memaddr,myaddr, length, 0);
bellard9307c4c2004-04-04 12:57:25 +0000381 }
382 return 0;
383}
384
Stefan Weil8b7968f2010-09-23 21:28:05 +0200385static int GCC_FMT_ATTR(2, 3)
386monitor_fprintf(FILE *stream, const char *fmt, ...)
bellard3d2cfdf2004-08-01 21:49:07 +0000387{
388 va_list ap;
389 va_start(ap, fmt);
aliguori376253e2009-03-05 23:01:23 +0000390 monitor_vprintf((Monitor *)stream, fmt, ap);
bellard3d2cfdf2004-08-01 21:49:07 +0000391 va_end(ap);
392 return 0;
393}
394
Andreas Färber9349b4f2012-03-14 01:38:32 +0100395void monitor_disas(Monitor *mon, CPUArchState *env,
bellard6a00d602005-11-21 23:25:50 +0000396 target_ulong pc, int nb_insn, int is_physical, int flags)
bellard9307c4c2004-04-04 12:57:25 +0000397{
bellard9307c4c2004-04-04 12:57:25 +0000398 int count, i;
399 struct disassemble_info disasm_info;
400 int (*print_insn)(bfd_vma pc, disassemble_info *info);
401
aliguori376253e2009-03-05 23:01:23 +0000402 INIT_DISASSEMBLE_INFO(disasm_info, (FILE *)mon, monitor_fprintf);
bellard9307c4c2004-04-04 12:57:25 +0000403
bellard6a00d602005-11-21 23:25:50 +0000404 monitor_disas_env = env;
bellard9307c4c2004-04-04 12:57:25 +0000405 monitor_disas_is_physical = is_physical;
406 disasm_info.read_memory_func = monitor_read_memory;
Peter Maydell636bd282012-06-25 04:55:55 +0000407 disasm_info.print_address_func = generic_print_target_address;
bellard9307c4c2004-04-04 12:57:25 +0000408
409 disasm_info.buffer_vma = pc;
410
411#ifdef TARGET_WORDS_BIGENDIAN
412 disasm_info.endian = BFD_ENDIAN_BIG;
413#else
414 disasm_info.endian = BFD_ENDIAN_LITTLE;
415#endif
416#if defined(TARGET_I386)
bellardfa15e032005-01-31 23:32:31 +0000417 if (flags == 2)
418 disasm_info.mach = bfd_mach_x86_64;
ths5fafdf22007-09-16 21:08:06 +0000419 else if (flags == 1)
bellard9307c4c2004-04-04 12:57:25 +0000420 disasm_info.mach = bfd_mach_i386_i8086;
bellardfa15e032005-01-31 23:32:31 +0000421 else
422 disasm_info.mach = bfd_mach_i386_i386;
bellard9307c4c2004-04-04 12:57:25 +0000423 print_insn = print_insn_i386;
424#elif defined(TARGET_ARM)
425 print_insn = print_insn_arm;
thscbd669d2007-12-25 00:26:36 +0000426#elif defined(TARGET_ALPHA)
427 print_insn = print_insn_alpha;
bellard9307c4c2004-04-04 12:57:25 +0000428#elif defined(TARGET_SPARC)
429 print_insn = print_insn_sparc;
blueswir1682c4f12007-04-09 15:14:57 +0000430#ifdef TARGET_SPARC64
431 disasm_info.mach = bfd_mach_sparc_v9b;
432#endif
bellard9307c4c2004-04-04 12:57:25 +0000433#elif defined(TARGET_PPC)
bellarda2458622005-07-23 22:39:53 +0000434#ifdef TARGET_PPC64
435 disasm_info.mach = bfd_mach_ppc64;
436#else
437 disasm_info.mach = bfd_mach_ppc;
438#endif
bellard9307c4c2004-04-04 12:57:25 +0000439 print_insn = print_insn_ppc;
pbrooke6e59062006-10-22 00:18:54 +0000440#elif defined(TARGET_M68K)
441 print_insn = print_insn_m68k;
bellard6af0bf92005-07-02 14:58:51 +0000442#elif defined(TARGET_MIPS)
bellard76b30302005-12-17 01:10:04 +0000443#ifdef TARGET_WORDS_BIGENDIAN
bellard6af0bf92005-07-02 14:58:51 +0000444 print_insn = print_insn_big_mips;
bellard76b30302005-12-17 01:10:04 +0000445#else
446 print_insn = print_insn_little_mips;
447#endif
Magnus Dammb4e1f072009-11-13 18:54:22 +0900448#elif defined(TARGET_SH4)
449 disasm_info.mach = bfd_mach_sh4;
450 print_insn = print_insn_sh;
Ulrich Hechtdb500602011-03-29 15:29:32 +0200451#elif defined(TARGET_S390X)
452 disasm_info.mach = bfd_mach_s390_64;
453 print_insn = print_insn_s390;
Michael Walle79368f42012-03-31 19:54:20 +0200454#elif defined(TARGET_LM32)
455 disasm_info.mach = bfd_mach_lm32;
456 print_insn = print_insn_lm32;
bellard9307c4c2004-04-04 12:57:25 +0000457#else
aliguori376253e2009-03-05 23:01:23 +0000458 monitor_printf(mon, "0x" TARGET_FMT_lx
459 ": Asm output not supported on this arch\n", pc);
bellard9307c4c2004-04-04 12:57:25 +0000460 return;
461#endif
462
463 for(i = 0; i < nb_insn; i++) {
aliguori376253e2009-03-05 23:01:23 +0000464 monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc);
bellard9307c4c2004-04-04 12:57:25 +0000465 count = print_insn(pc, &disasm_info);
aliguori376253e2009-03-05 23:01:23 +0000466 monitor_printf(mon, "\n");
bellard9307c4c2004-04-04 12:57:25 +0000467 if (count < 0)
468 break;
469 pc += count;
470 }
471}
472#endif