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
)
36 cpu_memory_rw_debug(cpu_single_env
, memaddr
, myaddr
, length
, 0);
40 /* Print an error message. We can assume that this is in response to
41 an error return from buffer_read_memory. */
43 perror_memory (int status
, bfd_vma memaddr
, struct disassemble_info
*info
)
47 (*info
->fprintf_func
) (info
->stream
, "Unknown error %d\n", status
);
49 /* Actually, address between memaddr and memaddr + len was
51 (*info
->fprintf_func
) (info
->stream
,
52 "Address 0x%" PRIx64
" is out of bounds.\n", memaddr
);
55 /* This could be in a separate file, to save miniscule amounts of space
56 in statically linked executables. */
58 /* Just print the address is hex. This is included for completeness even
59 though both GDB and objdump provide their own (to print symbolic
63 generic_print_address (bfd_vma addr
, struct disassemble_info
*info
)
65 (*info
->fprintf_func
) (info
->stream
, "0x%" PRIx64
, addr
);
68 /* Just return the given address. */
71 generic_symbol_at_address (bfd_vma addr
, struct disassemble_info
*info
)
76 bfd_vma
bfd_getl32 (const bfd_byte
*addr
)
80 v
= (unsigned long) addr
[0];
81 v
|= (unsigned long) addr
[1] << 8;
82 v
|= (unsigned long) addr
[2] << 16;
83 v
|= (unsigned long) addr
[3] << 24;
87 bfd_vma
bfd_getb32 (const bfd_byte
*addr
)
91 v
= (unsigned long) addr
[0] << 24;
92 v
|= (unsigned long) addr
[1] << 16;
93 v
|= (unsigned long) addr
[2] << 8;
94 v
|= (unsigned long) addr
[3];
98 bfd_vma
bfd_getl16 (const bfd_byte
*addr
)
102 v
= (unsigned long) addr
[0];
103 v
|= (unsigned long) addr
[1] << 8;
107 bfd_vma
bfd_getb16 (const bfd_byte
*addr
)
111 v
= (unsigned long) addr
[0] << 24;
112 v
|= (unsigned long) addr
[1] << 16;
118 print_insn_thumb1(bfd_vma pc
, disassemble_info
*info
)
120 return print_insn_arm(pc
| 1, info
);
124 /* Disassemble this for me please... (debugging). 'flags' has the following
126 i386 - nonzero means 16 bit code
127 arm - nonzero means thumb code
128 ppc - nonzero means little endian
129 other targets - unused
131 void target_disas(FILE *out
, target_ulong code
, target_ulong size
, int flags
)
135 struct disassemble_info disasm_info
;
136 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
138 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
140 disasm_info
.read_memory_func
= target_read_memory
;
141 disasm_info
.buffer_vma
= code
;
142 disasm_info
.buffer_length
= size
;
144 #ifdef TARGET_WORDS_BIGENDIAN
145 disasm_info
.endian
= BFD_ENDIAN_BIG
;
147 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
149 #if defined(TARGET_I386)
151 disasm_info
.mach
= bfd_mach_x86_64
;
153 disasm_info
.mach
= bfd_mach_i386_i8086
;
155 disasm_info
.mach
= bfd_mach_i386_i386
;
156 print_insn
= print_insn_i386
;
157 #elif defined(TARGET_ARM)
159 print_insn
= print_insn_thumb1
;
161 print_insn
= print_insn_arm
;
162 #elif defined(TARGET_SPARC)
163 print_insn
= print_insn_sparc
;
164 #ifdef TARGET_SPARC64
165 disasm_info
.mach
= bfd_mach_sparc_v9b
;
167 #elif defined(TARGET_PPC)
169 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
170 if (flags
& 0xFFFF) {
171 /* If we have a precise definitions of the instructions set, use it */
172 disasm_info
.mach
= flags
& 0xFFFF;
175 disasm_info
.mach
= bfd_mach_ppc64
;
177 disasm_info
.mach
= bfd_mach_ppc
;
180 print_insn
= print_insn_ppc
;
181 #elif defined(TARGET_M68K)
182 print_insn
= print_insn_m68k
;
183 #elif defined(TARGET_MIPS)
184 #ifdef TARGET_WORDS_BIGENDIAN
185 print_insn
= print_insn_big_mips
;
187 print_insn
= print_insn_little_mips
;
189 #elif defined(TARGET_SH4)
190 disasm_info
.mach
= bfd_mach_sh4
;
191 print_insn
= print_insn_sh
;
192 #elif defined(TARGET_ALPHA)
193 disasm_info
.mach
= bfd_mach_alpha
;
194 print_insn
= print_insn_alpha
;
195 #elif defined(TARGET_CRIS)
196 disasm_info
.mach
= bfd_mach_cris_v32
;
197 print_insn
= print_insn_crisv32
;
199 fprintf(out
, "0x" TARGET_FMT_lx
200 ": Asm output not supported on this arch\n", code
);
204 for (pc
= code
; size
> 0; pc
+= count
, size
-= count
) {
205 fprintf(out
, "0x" TARGET_FMT_lx
": ", pc
);
206 count
= print_insn(pc
, &disasm_info
);
212 for(i
= 0; i
< count
; i
++) {
213 target_read_memory(pc
+ i
, &b
, 1, &disasm_info
);
214 fprintf(out
, " %02x", b
);
224 "Disassembler disagrees with translator over instruction "
226 "Please report this to qemu-devel@nongnu.org\n");
232 /* Disassemble this for me please... (debugging). */
233 void disas(FILE *out
, void *code
, unsigned long size
)
237 struct disassemble_info disasm_info
;
238 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
240 INIT_DISASSEMBLE_INFO(disasm_info
, out
, fprintf
);
242 disasm_info
.buffer
= code
;
243 disasm_info
.buffer_vma
= (unsigned long)code
;
244 disasm_info
.buffer_length
= size
;
246 #ifdef WORDS_BIGENDIAN
247 disasm_info
.endian
= BFD_ENDIAN_BIG
;
249 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
251 #if defined(__i386__)
252 disasm_info
.mach
= bfd_mach_i386_i386
;
253 print_insn
= print_insn_i386
;
254 #elif defined(__x86_64__)
255 disasm_info
.mach
= bfd_mach_x86_64
;
256 print_insn
= print_insn_i386
;
257 #elif defined(_ARCH_PPC)
258 print_insn
= print_insn_ppc
;
259 #elif defined(__alpha__)
260 print_insn
= print_insn_alpha
;
261 #elif defined(__sparc__)
262 print_insn
= print_insn_sparc
;
263 #if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
264 disasm_info
.mach
= bfd_mach_sparc_v9b
;
266 #elif defined(__arm__)
267 print_insn
= print_insn_arm
;
268 #elif defined(__MIPSEB__)
269 print_insn
= print_insn_big_mips
;
270 #elif defined(__MIPSEL__)
271 print_insn
= print_insn_little_mips
;
272 #elif defined(__m68k__)
273 print_insn
= print_insn_m68k
;
274 #elif defined(__s390__)
275 print_insn
= print_insn_s390
;
276 #elif defined(__hppa__)
277 print_insn
= print_insn_hppa
;
279 fprintf(out
, "0x%lx: Asm output not supported on this arch\n",
283 for (pc
= (unsigned long)code
; size
> 0; pc
+= count
, size
-= count
) {
284 fprintf(out
, "0x%08lx: ", pc
);
286 /* since data is included in the code, it is better to
287 display code data too */
288 fprintf(out
, "%08x ", (int)bfd_getl32((const bfd_byte
*)pc
));
290 count
= print_insn(pc
, &disasm_info
);
297 /* Look up symbol for debugging purpose. Returns "" if unknown. */
298 const char *lookup_symbol(target_ulong orig_addr
)
300 const char *symbol
= "";
303 for (s
= syminfos
; s
; s
= s
->next
) {
304 symbol
= s
->lookup_symbol(s
, orig_addr
);
305 if (symbol
[0] != '\0') {
313 #if !defined(CONFIG_USER_ONLY)
317 static int monitor_disas_is_physical
;
318 static CPUState
*monitor_disas_env
;
321 monitor_read_memory (bfd_vma memaddr
, bfd_byte
*myaddr
, int length
,
322 struct disassemble_info
*info
)
324 if (monitor_disas_is_physical
) {
325 cpu_physical_memory_rw(memaddr
, myaddr
, length
, 0);
327 cpu_memory_rw_debug(monitor_disas_env
, memaddr
,myaddr
, length
, 0);
332 static int monitor_fprintf(FILE *stream
, const char *fmt
, ...)
336 monitor_vprintf((Monitor
*)stream
, fmt
, ap
);
341 void monitor_disas(Monitor
*mon
, CPUState
*env
,
342 target_ulong pc
, int nb_insn
, int is_physical
, int flags
)
345 struct disassemble_info disasm_info
;
346 int (*print_insn
)(bfd_vma pc
, disassemble_info
*info
);
348 INIT_DISASSEMBLE_INFO(disasm_info
, (FILE *)mon
, monitor_fprintf
);
350 monitor_disas_env
= env
;
351 monitor_disas_is_physical
= is_physical
;
352 disasm_info
.read_memory_func
= monitor_read_memory
;
354 disasm_info
.buffer_vma
= pc
;
356 #ifdef TARGET_WORDS_BIGENDIAN
357 disasm_info
.endian
= BFD_ENDIAN_BIG
;
359 disasm_info
.endian
= BFD_ENDIAN_LITTLE
;
361 #if defined(TARGET_I386)
363 disasm_info
.mach
= bfd_mach_x86_64
;
365 disasm_info
.mach
= bfd_mach_i386_i8086
;
367 disasm_info
.mach
= bfd_mach_i386_i386
;
368 print_insn
= print_insn_i386
;
369 #elif defined(TARGET_ARM)
370 print_insn
= print_insn_arm
;
371 #elif defined(TARGET_ALPHA)
372 print_insn
= print_insn_alpha
;
373 #elif defined(TARGET_SPARC)
374 print_insn
= print_insn_sparc
;
375 #ifdef TARGET_SPARC64
376 disasm_info
.mach
= bfd_mach_sparc_v9b
;
378 #elif defined(TARGET_PPC)
380 disasm_info
.mach
= bfd_mach_ppc64
;
382 disasm_info
.mach
= bfd_mach_ppc
;
384 print_insn
= print_insn_ppc
;
385 #elif defined(TARGET_M68K)
386 print_insn
= print_insn_m68k
;
387 #elif defined(TARGET_MIPS)
388 #ifdef TARGET_WORDS_BIGENDIAN
389 print_insn
= print_insn_big_mips
;
391 print_insn
= print_insn_little_mips
;
394 monitor_printf(mon
, "0x" TARGET_FMT_lx
395 ": Asm output not supported on this arch\n", pc
);
399 for(i
= 0; i
< nb_insn
; i
++) {
400 monitor_printf(mon
, "0x" TARGET_FMT_lx
": ", pc
);
401 count
= print_insn(pc
, &disasm_info
);
402 monitor_printf(mon
, "\n");