1 /* General "disassemble this chunk" code. Used for debugging. */
10 /* Filled in by elfload.c. Simplistic, but will do for now. */
11 struct syminfo
*syminfos
= NULL
;
13 /* Get LENGTH bytes from info's buffer, at target address memaddr.
14 Transfer them to myaddr. */
16 buffer_read_memory(bfd_vma memaddr
, bfd_byte
*myaddr
, int length
,
17 struct disassemble_info
*info
)
19 if (memaddr
< info
->buffer_vma
20 || memaddr
+ length
> info
->buffer_vma
+ info
->buffer_length
)
21 /* Out of bounds. Use EIO because GDB uses it. */
23 memcpy (myaddr
, info
->buffer
+ (memaddr
- info
->buffer_vma
), length
);
27 /* Get LENGTH bytes from info's buffer, at target address memaddr.
28 Transfer them to myaddr. */
30 target_read_memory (bfd_vma memaddr
,
33 struct disassemble_info
*info
)
35 cpu_memory_rw_debug(cpu_single_env
, memaddr
, myaddr
, length
, 0);
39 /* Print an error message. We can assume that this is in response to
40 an error return from buffer_read_memory. */
42 perror_memory (int status
, bfd_vma memaddr
, struct disassemble_info
*info
)
46 (*info
->fprintf_func
) (info
->stream
, "Unknown error %d\n", status
);
48 /* Actually, address between memaddr and memaddr + len was
50 (*info
->fprintf_func
) (info
->stream
,
51 "Address 0x%" PRIx64
" is out of bounds.\n", memaddr
);
54 /* This could be in a separate file, to save miniscule amounts of space
55 in statically linked executables. */
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
62 generic_print_address (bfd_vma addr
, struct disassemble_info
*info
)
64 (*info
->fprintf_func
) (info
->stream
, "0x%" PRIx64
, addr
);
67 /* Just return the given address. */
70 generic_symbol_at_address (bfd_vma addr
, struct disassemble_info
*info
)
75 bfd_vma
bfd_getl64 (const bfd_byte
*addr
)
79 v
= (unsigned long long) addr
[0];
80 v
|= (unsigned long long) addr
[1] << 8;
81 v
|= (unsigned long long) addr
[2] << 16;
82 v
|= (unsigned long long) addr
[3] << 24;
83 v
|= (unsigned long long) addr
[4] << 32;
84 v
|= (unsigned long long) addr
[5] << 40;
85 v
|= (unsigned long long) addr
[6] << 48;
86 v
|= (unsigned long long) addr
[7] << 56;
90 bfd_vma
bfd_getl32 (const bfd_byte
*addr
)
94 v
= (unsigned long) addr
[0];
95 v
|= (unsigned long) addr
[1] << 8;
96 v
|= (unsigned long) addr
[2] << 16;
97 v
|= (unsigned long) addr
[3] << 24;
101 bfd_vma
bfd_getb32 (const bfd_byte
*addr
)
105 v
= (unsigned long) addr
[0] << 24;
106 v
|= (unsigned long) addr
[1] << 16;
107 v
|= (unsigned long) addr
[2] << 8;
108 v
|= (unsigned long) addr
[3];
112 bfd_vma
bfd_getl16 (const bfd_byte
*addr
)
116 v
= (unsigned long) addr
[0];
117 v
|= (unsigned long) addr
[1] << 8;
121 bfd_vma
bfd_getb16 (const bfd_byte
*addr
)
125 v
= (unsigned long) addr
[0] << 24;
126 v
|= (unsigned long) addr
[1] << 16;
132 print_insn_thumb1(bfd_vma pc
, disassemble_info
*info
)
134 return print_insn_arm(pc
| 1, info
);
138 /* Disassemble this for me please... (debugging). 'flags' has the following
140 i386 - 1 means 16 bit code, 2 means 64 bit code
141 arm - nonzero means thumb code
142 ppc - nonzero means little endian
143 other targets - unused
145 void target_disas(FILE *out
, target_ulong code
, target_ulong size
, int flags
)
149 struct disassemble_info disasm_info
;
150 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
152 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
154 disasm_info
.read_memory_func
= target_read_memory
;
155 disasm_info
.buffer_vma
= code
;
156 disasm_info
.buffer_length
= size
;
158 #ifdef TARGET_WORDS_BIGENDIAN
159 disasm_info
.endian
= BFD_ENDIAN_BIG
;
161 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
163 #if defined(TARGET_I386)
165 disasm_info
.mach
= bfd_mach_x86_64
;
167 disasm_info
.mach
= bfd_mach_i386_i8086
;
169 disasm_info
.mach
= bfd_mach_i386_i386
;
170 print_insn
= print_insn_i386
;
171 #elif defined(TARGET_ARM)
173 print_insn
= print_insn_thumb1
;
175 print_insn
= print_insn_arm
;
176 #elif defined(TARGET_SPARC)
177 print_insn
= print_insn_sparc
;
178 #ifdef TARGET_SPARC64
179 disasm_info
.mach
= bfd_mach_sparc_v9b
;
181 #elif defined(TARGET_PPC)
183 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
184 if (flags
& 0xFFFF) {
185 /* If we have a precise definitions of the instructions set, use it */
186 disasm_info
.mach
= flags
& 0xFFFF;
189 disasm_info
.mach
= bfd_mach_ppc64
;
191 disasm_info
.mach
= bfd_mach_ppc
;
194 print_insn
= print_insn_ppc
;
195 #elif defined(TARGET_M68K)
196 print_insn
= print_insn_m68k
;
197 #elif defined(TARGET_MIPS)
198 #ifdef TARGET_WORDS_BIGENDIAN
199 print_insn
= print_insn_big_mips
;
201 print_insn
= print_insn_little_mips
;
203 #elif defined(TARGET_SH4)
204 disasm_info
.mach
= bfd_mach_sh4
;
205 print_insn
= print_insn_sh
;
206 #elif defined(TARGET_ALPHA)
207 disasm_info
.mach
= bfd_mach_alpha_ev6
;
208 print_insn
= print_insn_alpha
;
209 #elif defined(TARGET_CRIS)
211 disasm_info
.mach
= bfd_mach_cris_v0_v10
;
212 print_insn
= print_insn_crisv10
;
214 disasm_info
.mach
= bfd_mach_cris_v32
;
215 print_insn
= print_insn_crisv32
;
217 #elif defined(TARGET_S390X)
218 disasm_info
.mach
= bfd_mach_s390_64
;
219 print_insn
= print_insn_s390
;
220 #elif defined(TARGET_MICROBLAZE)
221 disasm_info
.mach
= bfd_arch_microblaze
;
222 print_insn
= print_insn_microblaze
;
224 fprintf(out
, "0x" TARGET_FMT_lx
225 ": Asm output not supported on this arch\n", code
);
229 for (pc
= code
; size
> 0; pc
+= count
, size
-= count
) {
230 fprintf(out
, "0x" TARGET_FMT_lx
": ", pc
);
231 count
= print_insn(pc
, &disasm_info
);
237 for(i
= 0; i
< count
; i
++) {
238 target_read_memory(pc
+ i
, &b
, 1, &disasm_info
);
239 fprintf(out
, " %02x", b
);
249 "Disassembler disagrees with translator over instruction "
251 "Please report this to qemu-devel@nongnu.org\n");
257 /* Disassemble this for me please... (debugging). */
258 void disas(FILE *out
, void *code
, unsigned long size
)
262 struct disassemble_info disasm_info
;
263 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
265 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
267 disasm_info
.buffer
= code
;
268 disasm_info
.buffer_vma
= (unsigned long)code
;
269 disasm_info
.buffer_length
= size
;
271 #ifdef HOST_WORDS_BIGENDIAN
272 disasm_info
.endian
= BFD_ENDIAN_BIG
;
274 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
276 #if defined(__i386__)
277 disasm_info
.mach
= bfd_mach_i386_i386
;
278 print_insn
= print_insn_i386
;
279 #elif defined(__x86_64__)
280 disasm_info
.mach
= bfd_mach_x86_64
;
281 print_insn
= print_insn_i386
;
282 #elif defined(_ARCH_PPC)
283 print_insn
= print_insn_ppc
;
284 #elif defined(__alpha__)
285 print_insn
= print_insn_alpha
;
286 #elif defined(__sparc__)
287 print_insn
= print_insn_sparc
;
288 #if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
289 disasm_info
.mach
= bfd_mach_sparc_v9b
;
291 #elif defined(__arm__)
292 print_insn
= print_insn_arm
;
293 #elif defined(__MIPSEB__)
294 print_insn
= print_insn_big_mips
;
295 #elif defined(__MIPSEL__)
296 print_insn
= print_insn_little_mips
;
297 #elif defined(__m68k__)
298 print_insn
= print_insn_m68k
;
299 #elif defined(__s390__)
300 print_insn
= print_insn_s390
;
301 #elif defined(__hppa__)
302 print_insn
= print_insn_hppa
;
303 #elif defined(__ia64__)
304 print_insn
= print_insn_ia64
;
306 fprintf(out
, "0x%lx: Asm output not supported on this arch\n",
310 for (pc
= (unsigned long)code
; size
> 0; pc
+= count
, size
-= count
) {
311 fprintf(out
, "0x%08lx: ", pc
);
312 count
= print_insn(pc
, &disasm_info
);
319 /* Look up symbol for debugging purpose. Returns "" if unknown. */
320 const char *lookup_symbol(target_ulong orig_addr
)
322 const char *symbol
= "";
325 for (s
= syminfos
; s
; s
= s
->next
) {
326 symbol
= s
->lookup_symbol(s
, orig_addr
);
327 if (symbol
[0] != '\0') {
335 #if !defined(CONFIG_USER_ONLY)
339 static int monitor_disas_is_physical
;
340 static CPUState
*monitor_disas_env
;
343 monitor_read_memory (bfd_vma memaddr
, bfd_byte
*myaddr
, int length
,
344 struct disassemble_info
*info
)
346 if (monitor_disas_is_physical
) {
347 cpu_physical_memory_read(memaddr
, myaddr
, length
);
349 cpu_memory_rw_debug(monitor_disas_env
, memaddr
,myaddr
, length
, 0);
354 static int GCC_FMT_ATTR(2, 3)
355 monitor_fprintf(FILE *stream
, const char *fmt
, ...)
359 monitor_vprintf((Monitor
*)stream
, fmt
, ap
);
364 void monitor_disas(Monitor
*mon
, CPUState
*env
,
365 target_ulong pc
, int nb_insn
, int is_physical
, int flags
)
368 struct disassemble_info disasm_info
;
369 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
371 INIT_DISASSEMBLE_INFO(disasm_info
, (FILE *)mon
, monitor_fprintf
);
373 monitor_disas_env
= env
;
374 monitor_disas_is_physical
= is_physical
;
375 disasm_info
.read_memory_func
= monitor_read_memory
;
377 disasm_info
.buffer_vma
= pc
;
379 #ifdef TARGET_WORDS_BIGENDIAN
380 disasm_info
.endian
= BFD_ENDIAN_BIG
;
382 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
384 #if defined(TARGET_I386)
386 disasm_info
.mach
= bfd_mach_x86_64
;
388 disasm_info
.mach
= bfd_mach_i386_i8086
;
390 disasm_info
.mach
= bfd_mach_i386_i386
;
391 print_insn
= print_insn_i386
;
392 #elif defined(TARGET_ARM)
393 print_insn
= print_insn_arm
;
394 #elif defined(TARGET_ALPHA)
395 print_insn
= print_insn_alpha
;
396 #elif defined(TARGET_SPARC)
397 print_insn
= print_insn_sparc
;
398 #ifdef TARGET_SPARC64
399 disasm_info
.mach
= bfd_mach_sparc_v9b
;
401 #elif defined(TARGET_PPC)
403 disasm_info
.mach
= bfd_mach_ppc64
;
405 disasm_info
.mach
= bfd_mach_ppc
;
407 print_insn
= print_insn_ppc
;
408 #elif defined(TARGET_M68K)
409 print_insn
= print_insn_m68k
;
410 #elif defined(TARGET_MIPS)
411 #ifdef TARGET_WORDS_BIGENDIAN
412 print_insn
= print_insn_big_mips
;
414 print_insn
= print_insn_little_mips
;
416 #elif defined(TARGET_SH4)
417 disasm_info
.mach
= bfd_mach_sh4
;
418 print_insn
= print_insn_sh
;
419 #elif defined(TARGET_S390X)
420 disasm_info
.mach
= bfd_mach_s390_64
;
421 print_insn
= print_insn_s390
;
423 monitor_printf(mon
, "0x" TARGET_FMT_lx
424 ": Asm output not supported on this arch\n", pc
);
428 for(i
= 0; i
< nb_insn
; i
++) {
429 monitor_printf(mon
, "0x" TARGET_FMT_lx
": ", pc
);
430 count
= print_insn(pc
, &disasm_info
);
431 monitor_printf(mon
, "\n");