root / disas.c @ d796321b
History | View | Annotate | Download (10.4 kB)
1 | b9adb4a6 | bellard | /* General "disassemble this chunk" code. Used for debugging. */
|
---|---|---|---|
2 | 5bbe9299 | bellard | #include "config.h" |
3 | b9adb4a6 | bellard | #include "dis-asm.h" |
4 | b9adb4a6 | bellard | #include "elf.h" |
5 | aa0aa4fa | bellard | #include <errno.h> |
6 | b9adb4a6 | bellard | |
7 | c6105c0a | bellard | #include "cpu.h" |
8 | c6105c0a | bellard | #include "exec-all.h" |
9 | 9307c4c1 | bellard | #include "disas.h" |
10 | c6105c0a | bellard | |
11 | b9adb4a6 | bellard | /* Filled in by elfload.c. Simplistic, but will do for now. */
|
12 | e80cfcfc | bellard | struct syminfo *syminfos = NULL; |
13 | b9adb4a6 | bellard | |
14 | aa0aa4fa | bellard | /* Get LENGTH bytes from info's buffer, at target address memaddr.
|
15 | aa0aa4fa | bellard | Transfer them to myaddr. */
|
16 | aa0aa4fa | bellard | int
|
17 | aa0aa4fa | bellard | buffer_read_memory (memaddr, myaddr, length, info) |
18 | aa0aa4fa | bellard | bfd_vma memaddr; |
19 | aa0aa4fa | bellard | bfd_byte *myaddr; |
20 | aa0aa4fa | bellard | int length;
|
21 | aa0aa4fa | bellard | struct disassemble_info *info;
|
22 | aa0aa4fa | bellard | { |
23 | c6105c0a | bellard | if (memaddr < info->buffer_vma
|
24 | c6105c0a | bellard | || memaddr + length > info->buffer_vma + info->buffer_length) |
25 | c6105c0a | bellard | /* Out of bounds. Use EIO because GDB uses it. */
|
26 | c6105c0a | bellard | return EIO;
|
27 | c6105c0a | bellard | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); |
28 | c6105c0a | bellard | return 0; |
29 | aa0aa4fa | bellard | } |
30 | aa0aa4fa | bellard | |
31 | c6105c0a | bellard | /* Get LENGTH bytes from info's buffer, at target address memaddr.
|
32 | c6105c0a | bellard | Transfer them to myaddr. */
|
33 | c6105c0a | bellard | static int |
34 | c27004ec | bellard | target_read_memory (bfd_vma memaddr, |
35 | c27004ec | bellard | bfd_byte *myaddr, |
36 | c27004ec | bellard | int length,
|
37 | c27004ec | bellard | struct disassemble_info *info)
|
38 | c6105c0a | bellard | { |
39 | c6105c0a | bellard | int i;
|
40 | c6105c0a | bellard | for(i = 0; i < length; i++) { |
41 | c27004ec | bellard | myaddr[i] = ldub_code(memaddr + i); |
42 | c6105c0a | bellard | } |
43 | c6105c0a | bellard | return 0; |
44 | c6105c0a | bellard | } |
45 | c6105c0a | bellard | |
46 | aa0aa4fa | bellard | /* Print an error message. We can assume that this is in response to
|
47 | aa0aa4fa | bellard | an error return from buffer_read_memory. */
|
48 | aa0aa4fa | bellard | void
|
49 | aa0aa4fa | bellard | perror_memory (status, memaddr, info) |
50 | aa0aa4fa | bellard | int status;
|
51 | aa0aa4fa | bellard | bfd_vma memaddr; |
52 | aa0aa4fa | bellard | struct disassemble_info *info;
|
53 | aa0aa4fa | bellard | { |
54 | aa0aa4fa | bellard | if (status != EIO)
|
55 | aa0aa4fa | bellard | /* Can't happen. */
|
56 | aa0aa4fa | bellard | (*info->fprintf_func) (info->stream, "Unknown error %d\n", status);
|
57 | aa0aa4fa | bellard | else
|
58 | aa0aa4fa | bellard | /* Actually, address between memaddr and memaddr + len was
|
59 | aa0aa4fa | bellard | out of bounds. */
|
60 | aa0aa4fa | bellard | (*info->fprintf_func) (info->stream, |
61 | 26a76461 | bellard | "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); |
62 | aa0aa4fa | bellard | } |
63 | aa0aa4fa | bellard | |
64 | aa0aa4fa | bellard | /* This could be in a separate file, to save miniscule amounts of space
|
65 | aa0aa4fa | bellard | in statically linked executables. */
|
66 | aa0aa4fa | bellard | |
67 | aa0aa4fa | bellard | /* Just print the address is hex. This is included for completeness even
|
68 | aa0aa4fa | bellard | though both GDB and objdump provide their own (to print symbolic
|
69 | aa0aa4fa | bellard | addresses). */
|
70 | aa0aa4fa | bellard | |
71 | aa0aa4fa | bellard | void
|
72 | aa0aa4fa | bellard | generic_print_address (addr, info) |
73 | aa0aa4fa | bellard | bfd_vma addr; |
74 | aa0aa4fa | bellard | struct disassemble_info *info;
|
75 | aa0aa4fa | bellard | { |
76 | 26a76461 | bellard | (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr);
|
77 | aa0aa4fa | bellard | } |
78 | aa0aa4fa | bellard | |
79 | aa0aa4fa | bellard | /* Just return the given address. */
|
80 | aa0aa4fa | bellard | |
81 | aa0aa4fa | bellard | int
|
82 | aa0aa4fa | bellard | generic_symbol_at_address (addr, info) |
83 | aa0aa4fa | bellard | bfd_vma addr; |
84 | aa0aa4fa | bellard | struct disassemble_info * info;
|
85 | aa0aa4fa | bellard | { |
86 | aa0aa4fa | bellard | return 1; |
87 | aa0aa4fa | bellard | } |
88 | aa0aa4fa | bellard | |
89 | aa0aa4fa | bellard | bfd_vma bfd_getl32 (const bfd_byte *addr)
|
90 | aa0aa4fa | bellard | { |
91 | aa0aa4fa | bellard | unsigned long v; |
92 | aa0aa4fa | bellard | |
93 | aa0aa4fa | bellard | v = (unsigned long) addr[0]; |
94 | aa0aa4fa | bellard | v |= (unsigned long) addr[1] << 8; |
95 | aa0aa4fa | bellard | v |= (unsigned long) addr[2] << 16; |
96 | aa0aa4fa | bellard | v |= (unsigned long) addr[3] << 24; |
97 | aa0aa4fa | bellard | return (bfd_vma) v;
|
98 | aa0aa4fa | bellard | } |
99 | aa0aa4fa | bellard | |
100 | aa0aa4fa | bellard | bfd_vma bfd_getb32 (const bfd_byte *addr)
|
101 | aa0aa4fa | bellard | { |
102 | aa0aa4fa | bellard | unsigned long v; |
103 | aa0aa4fa | bellard | |
104 | aa0aa4fa | bellard | v = (unsigned long) addr[0] << 24; |
105 | aa0aa4fa | bellard | v |= (unsigned long) addr[1] << 16; |
106 | aa0aa4fa | bellard | v |= (unsigned long) addr[2] << 8; |
107 | aa0aa4fa | bellard | v |= (unsigned long) addr[3]; |
108 | aa0aa4fa | bellard | return (bfd_vma) v;
|
109 | aa0aa4fa | bellard | } |
110 | aa0aa4fa | bellard | |
111 | 6af0bf9c | bellard | bfd_vma bfd_getl16 (const bfd_byte *addr)
|
112 | 6af0bf9c | bellard | { |
113 | 6af0bf9c | bellard | unsigned long v; |
114 | 6af0bf9c | bellard | |
115 | 6af0bf9c | bellard | v = (unsigned long) addr[0]; |
116 | 6af0bf9c | bellard | v |= (unsigned long) addr[1] << 8; |
117 | 6af0bf9c | bellard | return (bfd_vma) v;
|
118 | 6af0bf9c | bellard | } |
119 | 6af0bf9c | bellard | |
120 | 6af0bf9c | bellard | bfd_vma bfd_getb16 (const bfd_byte *addr)
|
121 | 6af0bf9c | bellard | { |
122 | 6af0bf9c | bellard | unsigned long v; |
123 | 6af0bf9c | bellard | |
124 | 6af0bf9c | bellard | v = (unsigned long) addr[0] << 24; |
125 | 6af0bf9c | bellard | v |= (unsigned long) addr[1] << 16; |
126 | 6af0bf9c | bellard | return (bfd_vma) v;
|
127 | 6af0bf9c | bellard | } |
128 | 6af0bf9c | bellard | |
129 | c2d551ff | bellard | #ifdef TARGET_ARM
|
130 | c2d551ff | bellard | static int |
131 | c2d551ff | bellard | print_insn_thumb1(bfd_vma pc, disassemble_info *info) |
132 | c2d551ff | bellard | { |
133 | c2d551ff | bellard | return print_insn_arm(pc | 1, info); |
134 | c2d551ff | bellard | } |
135 | c2d551ff | bellard | #endif
|
136 | c2d551ff | bellard | |
137 | c2d551ff | bellard | /* Disassemble this for me please... (debugging). 'flags' has teh following
|
138 | c2d551ff | bellard | values:
|
139 | c2d551ff | bellard | i386 - nonzero means 16 bit code
|
140 | c2d551ff | bellard | arm - nonzero means thumb code
|
141 | 6a00d601 | bellard | ppc - nonzero means little endian
|
142 | c2d551ff | bellard | other targets - unused
|
143 | c2d551ff | bellard | */
|
144 | 83b34f8b | bellard | void target_disas(FILE *out, target_ulong code, target_ulong size, int flags) |
145 | b9adb4a6 | bellard | { |
146 | c27004ec | bellard | target_ulong pc; |
147 | b9adb4a6 | bellard | int count;
|
148 | b9adb4a6 | bellard | struct disassemble_info disasm_info;
|
149 | b9adb4a6 | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
150 | b9adb4a6 | bellard | |
151 | b9adb4a6 | bellard | INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); |
152 | b9adb4a6 | bellard | |
153 | c27004ec | bellard | disasm_info.read_memory_func = target_read_memory; |
154 | c27004ec | bellard | disasm_info.buffer_vma = code; |
155 | c27004ec | bellard | disasm_info.buffer_length = size; |
156 | c27004ec | bellard | |
157 | c27004ec | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
158 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
159 | c27004ec | bellard | #else
|
160 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
161 | c27004ec | bellard | #endif
|
162 | c27004ec | bellard | #if defined(TARGET_I386)
|
163 | c27004ec | bellard | if (flags == 2) |
164 | c27004ec | bellard | disasm_info.mach = bfd_mach_x86_64; |
165 | c27004ec | bellard | else if (flags == 1) |
166 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i8086; |
167 | c27004ec | bellard | else
|
168 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i386; |
169 | c27004ec | bellard | print_insn = print_insn_i386; |
170 | c27004ec | bellard | #elif defined(TARGET_ARM)
|
171 | c2d551ff | bellard | if (flags)
|
172 | c2d551ff | bellard | print_insn = print_insn_thumb1; |
173 | c2d551ff | bellard | else
|
174 | c2d551ff | bellard | print_insn = print_insn_arm; |
175 | c27004ec | bellard | #elif defined(TARGET_SPARC)
|
176 | c27004ec | bellard | print_insn = print_insn_sparc; |
177 | 3475187d | bellard | #ifdef TARGET_SPARC64
|
178 | 3475187d | bellard | disasm_info.mach = bfd_mach_sparc_v9b; |
179 | 3475187d | bellard | #endif
|
180 | c27004ec | bellard | #elif defined(TARGET_PPC)
|
181 | 6a00d601 | bellard | if (flags)
|
182 | 111bfab3 | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
183 | a2458627 | bellard | #ifdef TARGET_PPC64
|
184 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc64; |
185 | a2458627 | bellard | #else
|
186 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc; |
187 | a2458627 | bellard | #endif
|
188 | c27004ec | bellard | print_insn = print_insn_ppc; |
189 | 6af0bf9c | bellard | #elif defined(TARGET_MIPS)
|
190 | 76b3030c | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
191 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
192 | 76b3030c | bellard | #else
|
193 | 76b3030c | bellard | print_insn = print_insn_little_mips; |
194 | 76b3030c | bellard | #endif
|
195 | 48024e4a | bellard | #elif defined(TARGET_M68K)
|
196 | 48024e4a | bellard | print_insn = print_insn_m68k; |
197 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
198 | fdf9b3e8 | bellard | disasm_info.mach = bfd_mach_sh4; |
199 | fdf9b3e8 | bellard | print_insn = print_insn_sh; |
200 | c27004ec | bellard | #else
|
201 | b8076a74 | bellard | fprintf(out, "0x" TARGET_FMT_lx
|
202 | b8076a74 | bellard | ": Asm output not supported on this arch\n", code);
|
203 | c27004ec | bellard | return;
|
204 | c6105c0a | bellard | #endif
|
205 | c6105c0a | bellard | |
206 | c27004ec | bellard | for (pc = code; pc < code + size; pc += count) {
|
207 | fa15e030 | bellard | fprintf(out, "0x" TARGET_FMT_lx ": ", pc); |
208 | c27004ec | bellard | count = print_insn(pc, &disasm_info); |
209 | c27004ec | bellard | #if 0
|
210 | c27004ec | bellard | {
|
211 | c27004ec | bellard | int i;
|
212 | c27004ec | bellard | uint8_t b;
|
213 | c27004ec | bellard | fprintf(out, " {");
|
214 | c27004ec | bellard | for(i = 0; i < count; i++) {
|
215 | c27004ec | bellard | target_read_memory(pc + i, &b, 1, &disasm_info);
|
216 | c27004ec | bellard | fprintf(out, " %02x", b);
|
217 | c27004ec | bellard | }
|
218 | c27004ec | bellard | fprintf(out, " }");
|
219 | c27004ec | bellard | }
|
220 | c27004ec | bellard | #endif
|
221 | c27004ec | bellard | fprintf(out, "\n");
|
222 | c27004ec | bellard | if (count < 0) |
223 | c27004ec | bellard | break;
|
224 | c27004ec | bellard | } |
225 | c27004ec | bellard | } |
226 | c27004ec | bellard | |
227 | c27004ec | bellard | /* Disassemble this for me please... (debugging). */
|
228 | c27004ec | bellard | void disas(FILE *out, void *code, unsigned long size) |
229 | c27004ec | bellard | { |
230 | c27004ec | bellard | unsigned long pc; |
231 | c27004ec | bellard | int count;
|
232 | c27004ec | bellard | struct disassemble_info disasm_info;
|
233 | c27004ec | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
234 | c27004ec | bellard | |
235 | c27004ec | bellard | INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); |
236 | c27004ec | bellard | |
237 | b9adb4a6 | bellard | disasm_info.buffer = code; |
238 | b9adb4a6 | bellard | disasm_info.buffer_vma = (unsigned long)code; |
239 | b9adb4a6 | bellard | disasm_info.buffer_length = size; |
240 | b9adb4a6 | bellard | |
241 | b9adb4a6 | bellard | #ifdef WORDS_BIGENDIAN
|
242 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
243 | b9adb4a6 | bellard | #else
|
244 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
245 | b9adb4a6 | bellard | #endif
|
246 | bc51c5c9 | bellard | #if defined(__i386__)
|
247 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i386; |
248 | c27004ec | bellard | print_insn = print_insn_i386; |
249 | bc51c5c9 | bellard | #elif defined(__x86_64__)
|
250 | c27004ec | bellard | disasm_info.mach = bfd_mach_x86_64; |
251 | c27004ec | bellard | print_insn = print_insn_i386; |
252 | b9adb4a6 | bellard | #elif defined(__powerpc__)
|
253 | c27004ec | bellard | print_insn = print_insn_ppc; |
254 | a993ba85 | bellard | #elif defined(__alpha__)
|
255 | c27004ec | bellard | print_insn = print_insn_alpha; |
256 | aa0aa4fa | bellard | #elif defined(__sparc__)
|
257 | c27004ec | bellard | print_insn = print_insn_sparc; |
258 | aa0aa4fa | bellard | #elif defined(__arm__)
|
259 | c27004ec | bellard | print_insn = print_insn_arm; |
260 | 6af0bf9c | bellard | #elif defined(__MIPSEB__)
|
261 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
262 | 6af0bf9c | bellard | #elif defined(__MIPSEL__)
|
263 | 6af0bf9c | bellard | print_insn = print_insn_little_mips; |
264 | 48024e4a | bellard | #elif defined(__m68k__)
|
265 | 48024e4a | bellard | print_insn = print_insn_m68k; |
266 | b9adb4a6 | bellard | #else
|
267 | b8076a74 | bellard | fprintf(out, "0x%lx: Asm output not supported on this arch\n",
|
268 | b8076a74 | bellard | (long) code);
|
269 | c27004ec | bellard | return;
|
270 | b9adb4a6 | bellard | #endif
|
271 | c27004ec | bellard | for (pc = (unsigned long)code; pc < (unsigned long)code + size; pc += count) { |
272 | c27004ec | bellard | fprintf(out, "0x%08lx: ", pc);
|
273 | aa0aa4fa | bellard | #ifdef __arm__
|
274 | aa0aa4fa | bellard | /* since data are included in the code, it is better to
|
275 | aa0aa4fa | bellard | display code data too */
|
276 | 95cbfc64 | bellard | if (is_host) {
|
277 | aa0aa4fa | bellard | fprintf(out, "%08x ", (int)bfd_getl32((const bfd_byte *)pc)); |
278 | aa0aa4fa | bellard | } |
279 | aa0aa4fa | bellard | #endif
|
280 | c27004ec | bellard | count = print_insn(pc, &disasm_info); |
281 | b9adb4a6 | bellard | fprintf(out, "\n");
|
282 | b9adb4a6 | bellard | if (count < 0) |
283 | b9adb4a6 | bellard | break;
|
284 | b9adb4a6 | bellard | } |
285 | b9adb4a6 | bellard | } |
286 | b9adb4a6 | bellard | |
287 | b9adb4a6 | bellard | /* Look up symbol for debugging purpose. Returns "" if unknown. */
|
288 | c27004ec | bellard | const char *lookup_symbol(target_ulong orig_addr) |
289 | b9adb4a6 | bellard | { |
290 | b9adb4a6 | bellard | unsigned int i; |
291 | b9adb4a6 | bellard | /* Hack, because we know this is x86. */
|
292 | e80cfcfc | bellard | Elf32_Sym *sym; |
293 | e80cfcfc | bellard | struct syminfo *s;
|
294 | b3ecf620 | bellard | target_ulong addr; |
295 | e80cfcfc | bellard | |
296 | e80cfcfc | bellard | for (s = syminfos; s; s = s->next) {
|
297 | e80cfcfc | bellard | sym = s->disas_symtab; |
298 | e80cfcfc | bellard | for (i = 0; i < s->disas_num_syms; i++) { |
299 | e80cfcfc | bellard | if (sym[i].st_shndx == SHN_UNDEF
|
300 | e80cfcfc | bellard | || sym[i].st_shndx >= SHN_LORESERVE) |
301 | e80cfcfc | bellard | continue;
|
302 | b9adb4a6 | bellard | |
303 | e80cfcfc | bellard | if (ELF_ST_TYPE(sym[i].st_info) != STT_FUNC)
|
304 | e80cfcfc | bellard | continue;
|
305 | b9adb4a6 | bellard | |
306 | b3ecf620 | bellard | addr = sym[i].st_value; |
307 | b3ecf620 | bellard | #ifdef TARGET_ARM
|
308 | b3ecf620 | bellard | /* The bottom address bit marks a Thumb symbol. */
|
309 | b3ecf620 | bellard | addr &= ~(target_ulong)1;
|
310 | b3ecf620 | bellard | #endif
|
311 | b3ecf620 | bellard | if (orig_addr >= addr
|
312 | b3ecf620 | bellard | && orig_addr < addr + sym[i].st_size) |
313 | e80cfcfc | bellard | return s->disas_strtab + sym[i].st_name;
|
314 | e80cfcfc | bellard | } |
315 | b9adb4a6 | bellard | } |
316 | b9adb4a6 | bellard | return ""; |
317 | b9adb4a6 | bellard | } |
318 | 9307c4c1 | bellard | |
319 | 9307c4c1 | bellard | #if !defined(CONFIG_USER_ONLY)
|
320 | 9307c4c1 | bellard | |
321 | 3d2cfdf1 | bellard | void term_vprintf(const char *fmt, va_list ap); |
322 | 3d2cfdf1 | bellard | void term_printf(const char *fmt, ...); |
323 | 3d2cfdf1 | bellard | |
324 | 9307c4c1 | bellard | static int monitor_disas_is_physical; |
325 | 6a00d601 | bellard | static CPUState *monitor_disas_env;
|
326 | 9307c4c1 | bellard | |
327 | 9307c4c1 | bellard | static int |
328 | 9307c4c1 | bellard | monitor_read_memory (memaddr, myaddr, length, info) |
329 | 9307c4c1 | bellard | bfd_vma memaddr; |
330 | 9307c4c1 | bellard | bfd_byte *myaddr; |
331 | 9307c4c1 | bellard | int length;
|
332 | 9307c4c1 | bellard | struct disassemble_info *info;
|
333 | 9307c4c1 | bellard | { |
334 | 9307c4c1 | bellard | if (monitor_disas_is_physical) {
|
335 | 9307c4c1 | bellard | cpu_physical_memory_rw(memaddr, myaddr, length, 0);
|
336 | 9307c4c1 | bellard | } else {
|
337 | 6a00d601 | bellard | cpu_memory_rw_debug(monitor_disas_env, memaddr,myaddr, length, 0);
|
338 | 9307c4c1 | bellard | } |
339 | 9307c4c1 | bellard | return 0; |
340 | 9307c4c1 | bellard | } |
341 | 9307c4c1 | bellard | |
342 | 3d2cfdf1 | bellard | static int monitor_fprintf(FILE *stream, const char *fmt, ...) |
343 | 3d2cfdf1 | bellard | { |
344 | 3d2cfdf1 | bellard | va_list ap; |
345 | 3d2cfdf1 | bellard | va_start(ap, fmt); |
346 | 3d2cfdf1 | bellard | term_vprintf(fmt, ap); |
347 | 3d2cfdf1 | bellard | va_end(ap); |
348 | 3d2cfdf1 | bellard | return 0; |
349 | 3d2cfdf1 | bellard | } |
350 | 3d2cfdf1 | bellard | |
351 | 6a00d601 | bellard | void monitor_disas(CPUState *env,
|
352 | 6a00d601 | bellard | target_ulong pc, int nb_insn, int is_physical, int flags) |
353 | 9307c4c1 | bellard | { |
354 | 9307c4c1 | bellard | int count, i;
|
355 | 9307c4c1 | bellard | struct disassemble_info disasm_info;
|
356 | 9307c4c1 | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
357 | 9307c4c1 | bellard | |
358 | 3d2cfdf1 | bellard | INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf);
|
359 | 9307c4c1 | bellard | |
360 | 6a00d601 | bellard | monitor_disas_env = env; |
361 | 9307c4c1 | bellard | monitor_disas_is_physical = is_physical; |
362 | 9307c4c1 | bellard | disasm_info.read_memory_func = monitor_read_memory; |
363 | 9307c4c1 | bellard | |
364 | 9307c4c1 | bellard | disasm_info.buffer_vma = pc; |
365 | 9307c4c1 | bellard | |
366 | 9307c4c1 | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
367 | 9307c4c1 | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
368 | 9307c4c1 | bellard | #else
|
369 | 9307c4c1 | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
370 | 9307c4c1 | bellard | #endif
|
371 | 9307c4c1 | bellard | #if defined(TARGET_I386)
|
372 | fa15e030 | bellard | if (flags == 2) |
373 | fa15e030 | bellard | disasm_info.mach = bfd_mach_x86_64; |
374 | fa15e030 | bellard | else if (flags == 1) |
375 | 9307c4c1 | bellard | disasm_info.mach = bfd_mach_i386_i8086; |
376 | fa15e030 | bellard | else
|
377 | fa15e030 | bellard | disasm_info.mach = bfd_mach_i386_i386; |
378 | 9307c4c1 | bellard | print_insn = print_insn_i386; |
379 | 9307c4c1 | bellard | #elif defined(TARGET_ARM)
|
380 | 9307c4c1 | bellard | print_insn = print_insn_arm; |
381 | 9307c4c1 | bellard | #elif defined(TARGET_SPARC)
|
382 | 9307c4c1 | bellard | print_insn = print_insn_sparc; |
383 | 9307c4c1 | bellard | #elif defined(TARGET_PPC)
|
384 | a2458627 | bellard | #ifdef TARGET_PPC64
|
385 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc64; |
386 | a2458627 | bellard | #else
|
387 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc; |
388 | a2458627 | bellard | #endif
|
389 | 9307c4c1 | bellard | print_insn = print_insn_ppc; |
390 | 6af0bf9c | bellard | #elif defined(TARGET_MIPS)
|
391 | 76b3030c | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
392 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
393 | 76b3030c | bellard | #else
|
394 | 76b3030c | bellard | print_insn = print_insn_little_mips; |
395 | 76b3030c | bellard | #endif
|
396 | 48024e4a | bellard | #elif defined(TARGET_M68K)
|
397 | 48024e4a | bellard | print_insn = print_insn_m68k; |
398 | 9307c4c1 | bellard | #else
|
399 | b8076a74 | bellard | term_printf("0x" TARGET_FMT_lx
|
400 | b8076a74 | bellard | ": Asm output not supported on this arch\n", pc);
|
401 | 9307c4c1 | bellard | return;
|
402 | 9307c4c1 | bellard | #endif
|
403 | 9307c4c1 | bellard | |
404 | 9307c4c1 | bellard | for(i = 0; i < nb_insn; i++) { |
405 | fa15e030 | bellard | term_printf("0x" TARGET_FMT_lx ": ", pc); |
406 | 9307c4c1 | bellard | count = print_insn(pc, &disasm_info); |
407 | 3d2cfdf1 | bellard | term_printf("\n");
|
408 | 9307c4c1 | bellard | if (count < 0) |
409 | 9307c4c1 | bellard | break;
|
410 | 9307c4c1 | bellard | pc += count; |
411 | 9307c4c1 | bellard | } |
412 | 9307c4c1 | bellard | } |
413 | 9307c4c1 | bellard | #endif |