1 /* General "disassemble this chunk" code. Used for debugging. */
11 /* Filled in by elfload.c. Simplistic, but will do for now. */
12 struct syminfo
*syminfos
= NULL
;
14 /* Get LENGTH bytes from info's buffer, at target address memaddr.
15 Transfer them to myaddr. */
17 buffer_read_memory(bfd_vma memaddr
, bfd_byte
*myaddr
, int length
,
18 struct disassemble_info
*info
)
20 if (memaddr
< info
->buffer_vma
21 || memaddr
+ length
> info
->buffer_vma
+ info
->buffer_length
)
22 /* Out of bounds. Use EIO because GDB uses it. */
24 memcpy (myaddr
, info
->buffer
+ (memaddr
- info
->buffer_vma
), length
);
28 /* Get LENGTH bytes from info's buffer, at target address memaddr.
29 Transfer them to myaddr. */
31 target_read_memory (bfd_vma memaddr
,
34 struct disassemble_info
*info
)
37 for(i
= 0; i
< length
; i
++) {
38 myaddr
[i
] = ldub_code(memaddr
+ i
);
43 /* Print an error message. We can assume that this is in response to
44 an error return from buffer_read_memory. */
46 perror_memory (int status
, bfd_vma memaddr
, struct disassemble_info
*info
)
50 (*info
->fprintf_func
) (info
->stream
, "Unknown error %d\n", status
);
52 /* Actually, address between memaddr and memaddr + len was
54 (*info
->fprintf_func
) (info
->stream
,
55 "Address 0x%" PRIx64
" is out of bounds.\n", memaddr
);
58 /* This could be in a separate file, to save miniscule amounts of space
59 in statically linked executables. */
61 /* Just print the address is hex. This is included for completeness even
62 though both GDB and objdump provide their own (to print symbolic
66 generic_print_address (bfd_vma addr
, struct disassemble_info
*info
)
68 (*info
->fprintf_func
) (info
->stream
, "0x%" PRIx64
, addr
);
71 /* Just return the given address. */
74 generic_symbol_at_address (bfd_vma addr
, struct disassemble_info
*info
)
79 bfd_vma
bfd_getl32 (const bfd_byte
*addr
)
83 v
= (unsigned long) addr
[0];
84 v
|= (unsigned long) addr
[1] << 8;
85 v
|= (unsigned long) addr
[2] << 16;
86 v
|= (unsigned long) addr
[3] << 24;
90 bfd_vma
bfd_getb32 (const bfd_byte
*addr
)
94 v
= (unsigned long) addr
[0] << 24;
95 v
|= (unsigned long) addr
[1] << 16;
96 v
|= (unsigned long) addr
[2] << 8;
97 v
|= (unsigned long) addr
[3];
101 bfd_vma
bfd_getl16 (const bfd_byte
*addr
)
105 v
= (unsigned long) addr
[0];
106 v
|= (unsigned long) addr
[1] << 8;
110 bfd_vma
bfd_getb16 (const bfd_byte
*addr
)
114 v
= (unsigned long) addr
[0] << 24;
115 v
|= (unsigned long) addr
[1] << 16;
121 print_insn_thumb1(bfd_vma pc
, disassemble_info
*info
)
123 return print_insn_arm(pc
| 1, info
);
127 /* Disassemble this for me please... (debugging). 'flags' has the following
129 i386 - nonzero means 16 bit code
130 arm - nonzero means thumb code
131 ppc - nonzero means little endian
132 other targets - unused
134 void target_disas(FILE *out
, target_ulong code
, target_ulong size
, int flags
)
138 struct disassemble_info disasm_info
;
139 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
141 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
143 disasm_info
.read_memory_func
= target_read_memory
;
144 disasm_info
.buffer_vma
= code
;
145 disasm_info
.buffer_length
= size
;
147 #ifdef TARGET_WORDS_BIGENDIAN
148 disasm_info
.endian
= BFD_ENDIAN_BIG
;
150 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
152 #if defined(TARGET_I386)
154 disasm_info
.mach
= bfd_mach_x86_64
;
156 disasm_info
.mach
= bfd_mach_i386_i8086
;
158 disasm_info
.mach
= bfd_mach_i386_i386
;
159 print_insn
= print_insn_i386
;
160 #elif defined(TARGET_ARM)
162 print_insn
= print_insn_thumb1
;
164 print_insn
= print_insn_arm
;
165 #elif defined(TARGET_SPARC)
166 print_insn
= print_insn_sparc
;
167 #ifdef TARGET_SPARC64
168 disasm_info
.mach
= bfd_mach_sparc_v9b
;
170 #elif defined(TARGET_PPC)
172 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
173 if (flags
& 0xFFFF) {
174 /* If we have a precise definitions of the instructions set, use it */
175 disasm_info
.mach
= flags
& 0xFFFF;
178 disasm_info
.mach
= bfd_mach_ppc64
;
180 disasm_info
.mach
= bfd_mach_ppc
;
183 print_insn
= print_insn_ppc
;
184 #elif defined(TARGET_M68K)
185 print_insn
= print_insn_m68k
;
186 #elif defined(TARGET_MIPS)
187 #ifdef TARGET_WORDS_BIGENDIAN
188 print_insn
= print_insn_big_mips
;
190 print_insn
= print_insn_little_mips
;
192 #elif defined(TARGET_SH4)
193 disasm_info
.mach
= bfd_mach_sh4
;
194 print_insn
= print_insn_sh
;
195 #elif defined(TARGET_ALPHA)
196 disasm_info
.mach
= bfd_mach_alpha
;
197 print_insn
= print_insn_alpha
;
198 #elif defined(TARGET_CRIS)
199 disasm_info
.mach
= bfd_mach_cris_v32
;
200 print_insn
= print_insn_crisv32
;
201 #elif defined(TARGET_HPPA)
202 disasm_info
.mach
= bfd_mach_hppa11
;
203 print_insn
= print_insn_hppa
;
205 fprintf(out
, "0x" TARGET_FMT_lx
206 ": Asm output not supported on this arch\n", code
);
210 for (pc
= code
; size
> 0; pc
+= count
, size
-= count
) {
211 fprintf(out
, "0x" TARGET_FMT_lx
": ", pc
);
212 count
= print_insn(pc
, &disasm_info
);
218 for(i
= 0; i
< count
; i
++) {
219 target_read_memory(pc
+ i
, &b
, 1, &disasm_info
);
220 fprintf(out
, " %02x", b
);
231 /* Disassemble this for me please... (debugging). */
232 void disas(FILE *out
, void *code
, unsigned long size
)
236 struct disassemble_info disasm_info
;
237 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
239 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
241 disasm_info
.buffer
= code
;
242 disasm_info
.buffer_vma
= (unsigned long)code
;
243 disasm_info
.buffer_length
= size
;
245 #ifdef WORDS_BIGENDIAN
246 disasm_info
.endian
= BFD_ENDIAN_BIG
;
248 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
250 #if defined(__i386__)
251 disasm_info
.mach
= bfd_mach_i386_i386
;
252 print_insn
= print_insn_i386
;
253 #elif defined(__x86_64__)
254 disasm_info
.mach
= bfd_mach_x86_64
;
255 print_insn
= print_insn_i386
;
256 #elif defined(_ARCH_PPC)
257 print_insn
= print_insn_ppc
;
258 #elif defined(__alpha__)
259 print_insn
= print_insn_alpha
;
260 #elif defined(__sparc__)
261 print_insn
= print_insn_sparc
;
262 #if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
263 disasm_info
.mach
= bfd_mach_sparc_v9b
;
265 #elif defined(__arm__)
266 print_insn
= print_insn_arm
;
267 #elif defined(__MIPSEB__)
268 print_insn
= print_insn_big_mips
;
269 #elif defined(__MIPSEL__)
270 print_insn
= print_insn_little_mips
;
271 #elif defined(__m68k__)
272 print_insn
= print_insn_m68k
;
273 #elif defined(__s390__)
274 print_insn
= print_insn_s390
;
275 #elif defined(__hppa__)
276 print_insn
= print_insn_hppa
;
278 fprintf(out
, "0x%lx: Asm output not supported on this arch\n",
282 for (pc
= (unsigned long)code
; size
> 0; pc
+= count
, size
-= count
) {
283 fprintf(out
, "0x%08lx: ", pc
);
285 /* since data is included in the code, it is better to
286 display code data too */
287 fprintf(out
, "%08x ", (int)bfd_getl32((const bfd_byte
*)pc
));
289 count
= print_insn(pc
, &disasm_info
);
296 /* Look up symbol for debugging purpose. Returns "" if unknown. */
297 const char *lookup_symbol(target_ulong orig_addr
)
299 const char *symbol
= "";
302 for (s
= syminfos
; s
; s
= s
->next
) {
303 symbol
= s
->lookup_symbol(s
, orig_addr
);
304 if (symbol
[0] != '\0') {
312 #if !defined(CONFIG_USER_ONLY)
316 static int monitor_disas_is_physical
;
317 static CPUState
*monitor_disas_env
;
320 monitor_read_memory (bfd_vma memaddr
, bfd_byte
*myaddr
, int length
,
321 struct disassemble_info
*info
)
323 if (monitor_disas_is_physical
) {
324 cpu_physical_memory_rw(memaddr
, myaddr
, length
, 0);
326 cpu_memory_rw_debug(monitor_disas_env
, memaddr
,myaddr
, length
, 0);
331 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
335 monitor_vprintf((Monitor
*)stream
, fmt
, ap
);
340 void monitor_disas(Monitor
*mon
, CPUState
*env
,
341 target_ulong pc
, int nb_insn
, int is_physical
, int flags
)
344 struct disassemble_info disasm_info
;
345 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
347 INIT_DISASSEMBLE_INFO(disasm_info
, (FILE *)mon
, monitor_fprintf
);
349 monitor_disas_env
= env
;
350 monitor_disas_is_physical
= is_physical
;
351 disasm_info
.read_memory_func
= monitor_read_memory
;
353 disasm_info
.buffer_vma
= pc
;
355 #ifdef TARGET_WORDS_BIGENDIAN
356 disasm_info
.endian
= BFD_ENDIAN_BIG
;
358 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
360 #if defined(TARGET_I386)
362 disasm_info
.mach
= bfd_mach_x86_64
;
364 disasm_info
.mach
= bfd_mach_i386_i8086
;
366 disasm_info
.mach
= bfd_mach_i386_i386
;
367 print_insn
= print_insn_i386
;
368 #elif defined(TARGET_ARM)
369 print_insn
= print_insn_arm
;
370 #elif defined(TARGET_ALPHA)
371 print_insn
= print_insn_alpha
;
372 #elif defined(TARGET_SPARC)
373 print_insn
= print_insn_sparc
;
374 #ifdef TARGET_SPARC64
375 disasm_info
.mach
= bfd_mach_sparc_v9b
;
377 #elif defined(TARGET_PPC)
379 disasm_info
.mach
= bfd_mach_ppc64
;
381 disasm_info
.mach
= bfd_mach_ppc
;
383 print_insn
= print_insn_ppc
;
384 #elif defined(TARGET_M68K)
385 print_insn
= print_insn_m68k
;
386 #elif defined(TARGET_MIPS)
387 #ifdef TARGET_WORDS_BIGENDIAN
388 print_insn
= print_insn_big_mips
;
390 print_insn
= print_insn_little_mips
;
393 monitor_printf(mon
, "0x" TARGET_FMT_lx
394 ": Asm output not supported on this arch\n", pc
);
398 for(i
= 0; i
< nb_insn
; i
++) {
399 monitor_printf(mon
, "0x" TARGET_FMT_lx
": ", pc
);
400 count
= print_insn(pc
, &disasm_info
);
401 monitor_printf(mon
, "\n");