root / disas.c @ 34bb443e
History | View | Annotate | Download (12.8 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 | 9307c4c1 | bellard | #include "disas.h" |
9 | c6105c0a | bellard | |
10 | b9adb4a6 | bellard | /* Filled in by elfload.c. Simplistic, but will do for now. */
|
11 | e80cfcfc | bellard | struct syminfo *syminfos = NULL; |
12 | b9adb4a6 | bellard | |
13 | aa0aa4fa | bellard | /* Get LENGTH bytes from info's buffer, at target address memaddr.
|
14 | aa0aa4fa | bellard | Transfer them to myaddr. */
|
15 | aa0aa4fa | bellard | int
|
16 | 3a742b76 | pbrook | buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length,
|
17 | 3a742b76 | pbrook | struct disassemble_info *info)
|
18 | aa0aa4fa | bellard | { |
19 | c6105c0a | bellard | if (memaddr < info->buffer_vma
|
20 | c6105c0a | bellard | || memaddr + length > info->buffer_vma + info->buffer_length) |
21 | c6105c0a | bellard | /* Out of bounds. Use EIO because GDB uses it. */
|
22 | c6105c0a | bellard | return EIO;
|
23 | c6105c0a | bellard | memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length); |
24 | c6105c0a | bellard | return 0; |
25 | aa0aa4fa | bellard | } |
26 | aa0aa4fa | bellard | |
27 | c6105c0a | bellard | /* Get LENGTH bytes from info's buffer, at target address memaddr.
|
28 | c6105c0a | bellard | Transfer them to myaddr. */
|
29 | c6105c0a | bellard | static int |
30 | c27004ec | bellard | target_read_memory (bfd_vma memaddr, |
31 | c27004ec | bellard | bfd_byte *myaddr, |
32 | c27004ec | bellard | int length,
|
33 | c27004ec | bellard | struct disassemble_info *info)
|
34 | c6105c0a | bellard | { |
35 | e612a1f7 | Blue Swirl | cpu_memory_rw_debug(cpu_single_env, memaddr, myaddr, length, 0);
|
36 | c6105c0a | bellard | return 0; |
37 | c6105c0a | bellard | } |
38 | c6105c0a | bellard | |
39 | aa0aa4fa | bellard | /* Print an error message. We can assume that this is in response to
|
40 | aa0aa4fa | bellard | an error return from buffer_read_memory. */
|
41 | aa0aa4fa | bellard | void
|
42 | 3a742b76 | pbrook | perror_memory (int status, bfd_vma memaddr, struct disassemble_info *info) |
43 | aa0aa4fa | bellard | { |
44 | aa0aa4fa | bellard | if (status != EIO)
|
45 | aa0aa4fa | bellard | /* Can't happen. */
|
46 | aa0aa4fa | bellard | (*info->fprintf_func) (info->stream, "Unknown error %d\n", status);
|
47 | aa0aa4fa | bellard | else
|
48 | aa0aa4fa | bellard | /* Actually, address between memaddr and memaddr + len was
|
49 | aa0aa4fa | bellard | out of bounds. */
|
50 | aa0aa4fa | bellard | (*info->fprintf_func) (info->stream, |
51 | 26a76461 | bellard | "Address 0x%" PRIx64 " is out of bounds.\n", memaddr); |
52 | aa0aa4fa | bellard | } |
53 | aa0aa4fa | bellard | |
54 | a31f0531 | Jim Meyering | /* This could be in a separate file, to save minuscule amounts of space
|
55 | aa0aa4fa | bellard | in statically linked executables. */
|
56 | aa0aa4fa | bellard | |
57 | aa0aa4fa | bellard | /* Just print the address is hex. This is included for completeness even
|
58 | aa0aa4fa | bellard | though both GDB and objdump provide their own (to print symbolic
|
59 | aa0aa4fa | bellard | addresses). */
|
60 | aa0aa4fa | bellard | |
61 | aa0aa4fa | bellard | void
|
62 | 3a742b76 | pbrook | generic_print_address (bfd_vma addr, struct disassemble_info *info)
|
63 | aa0aa4fa | bellard | { |
64 | 26a76461 | bellard | (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr);
|
65 | aa0aa4fa | bellard | } |
66 | aa0aa4fa | bellard | |
67 | 636bd289 | Peter Maydell | /* Print address in hex, truncated to the width of a target virtual address. */
|
68 | 636bd289 | Peter Maydell | static void |
69 | 636bd289 | Peter Maydell | generic_print_target_address(bfd_vma addr, struct disassemble_info *info)
|
70 | 636bd289 | Peter Maydell | { |
71 | 636bd289 | Peter Maydell | uint64_t mask = ~0ULL >> (64 - TARGET_VIRT_ADDR_SPACE_BITS); |
72 | 636bd289 | Peter Maydell | generic_print_address(addr & mask, info); |
73 | 636bd289 | Peter Maydell | } |
74 | 636bd289 | Peter Maydell | |
75 | 636bd289 | Peter Maydell | /* Print address in hex, truncated to the width of a host virtual address. */
|
76 | 636bd289 | Peter Maydell | static void |
77 | 636bd289 | Peter Maydell | generic_print_host_address(bfd_vma addr, struct disassemble_info *info)
|
78 | 636bd289 | Peter Maydell | { |
79 | 636bd289 | Peter Maydell | uint64_t mask = ~0ULL >> (64 - (sizeof(void *) * 8)); |
80 | 636bd289 | Peter Maydell | generic_print_address(addr & mask, info); |
81 | 636bd289 | Peter Maydell | } |
82 | 636bd289 | Peter Maydell | |
83 | aa0aa4fa | bellard | /* Just return the given address. */
|
84 | aa0aa4fa | bellard | |
85 | aa0aa4fa | bellard | int
|
86 | 3a742b76 | pbrook | generic_symbol_at_address (bfd_vma addr, struct disassemble_info *info)
|
87 | aa0aa4fa | bellard | { |
88 | aa0aa4fa | bellard | return 1; |
89 | aa0aa4fa | bellard | } |
90 | aa0aa4fa | bellard | |
91 | 903ec55c | Aurelien Jarno | bfd_vma bfd_getl64 (const bfd_byte *addr)
|
92 | 903ec55c | Aurelien Jarno | { |
93 | 903ec55c | Aurelien Jarno | unsigned long long v; |
94 | 903ec55c | Aurelien Jarno | |
95 | 903ec55c | Aurelien Jarno | v = (unsigned long long) addr[0]; |
96 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[1] << 8; |
97 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[2] << 16; |
98 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[3] << 24; |
99 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[4] << 32; |
100 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[5] << 40; |
101 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[6] << 48; |
102 | 903ec55c | Aurelien Jarno | v |= (unsigned long long) addr[7] << 56; |
103 | 903ec55c | Aurelien Jarno | return (bfd_vma) v;
|
104 | 903ec55c | Aurelien Jarno | } |
105 | 903ec55c | Aurelien Jarno | |
106 | aa0aa4fa | bellard | bfd_vma bfd_getl32 (const bfd_byte *addr)
|
107 | aa0aa4fa | bellard | { |
108 | aa0aa4fa | bellard | unsigned long v; |
109 | aa0aa4fa | bellard | |
110 | aa0aa4fa | bellard | v = (unsigned long) addr[0]; |
111 | aa0aa4fa | bellard | v |= (unsigned long) addr[1] << 8; |
112 | aa0aa4fa | bellard | v |= (unsigned long) addr[2] << 16; |
113 | aa0aa4fa | bellard | v |= (unsigned long) addr[3] << 24; |
114 | aa0aa4fa | bellard | return (bfd_vma) v;
|
115 | aa0aa4fa | bellard | } |
116 | aa0aa4fa | bellard | |
117 | aa0aa4fa | bellard | bfd_vma bfd_getb32 (const bfd_byte *addr)
|
118 | aa0aa4fa | bellard | { |
119 | aa0aa4fa | bellard | unsigned long v; |
120 | aa0aa4fa | bellard | |
121 | aa0aa4fa | bellard | v = (unsigned long) addr[0] << 24; |
122 | aa0aa4fa | bellard | v |= (unsigned long) addr[1] << 16; |
123 | aa0aa4fa | bellard | v |= (unsigned long) addr[2] << 8; |
124 | aa0aa4fa | bellard | v |= (unsigned long) addr[3]; |
125 | aa0aa4fa | bellard | return (bfd_vma) v;
|
126 | aa0aa4fa | bellard | } |
127 | aa0aa4fa | bellard | |
128 | 6af0bf9c | bellard | bfd_vma bfd_getl16 (const bfd_byte *addr)
|
129 | 6af0bf9c | bellard | { |
130 | 6af0bf9c | bellard | unsigned long v; |
131 | 6af0bf9c | bellard | |
132 | 6af0bf9c | bellard | v = (unsigned long) addr[0]; |
133 | 6af0bf9c | bellard | v |= (unsigned long) addr[1] << 8; |
134 | 6af0bf9c | bellard | return (bfd_vma) v;
|
135 | 6af0bf9c | bellard | } |
136 | 6af0bf9c | bellard | |
137 | 6af0bf9c | bellard | bfd_vma bfd_getb16 (const bfd_byte *addr)
|
138 | 6af0bf9c | bellard | { |
139 | 6af0bf9c | bellard | unsigned long v; |
140 | 6af0bf9c | bellard | |
141 | 6af0bf9c | bellard | v = (unsigned long) addr[0] << 24; |
142 | 6af0bf9c | bellard | v |= (unsigned long) addr[1] << 16; |
143 | 6af0bf9c | bellard | return (bfd_vma) v;
|
144 | 6af0bf9c | bellard | } |
145 | 6af0bf9c | bellard | |
146 | c2d551ff | bellard | #ifdef TARGET_ARM
|
147 | c2d551ff | bellard | static int |
148 | c2d551ff | bellard | print_insn_thumb1(bfd_vma pc, disassemble_info *info) |
149 | c2d551ff | bellard | { |
150 | c2d551ff | bellard | return print_insn_arm(pc | 1, info); |
151 | c2d551ff | bellard | } |
152 | c2d551ff | bellard | #endif
|
153 | c2d551ff | bellard | |
154 | e91c8a77 | ths | /* Disassemble this for me please... (debugging). 'flags' has the following
|
155 | c2d551ff | bellard | values:
|
156 | e99722f6 | Frediano Ziglio | i386 - 1 means 16 bit code, 2 means 64 bit code
|
157 | d8fd2954 | Paul Brook | arm - bit 0 = thumb, bit 1 = reverse endian
|
158 | 6a00d601 | bellard | ppc - nonzero means little endian
|
159 | c2d551ff | bellard | other targets - unused
|
160 | c2d551ff | bellard | */
|
161 | 83b34f8b | bellard | void target_disas(FILE *out, target_ulong code, target_ulong size, int flags) |
162 | b9adb4a6 | bellard | { |
163 | c27004ec | bellard | target_ulong pc; |
164 | b9adb4a6 | bellard | int count;
|
165 | b9adb4a6 | bellard | struct disassemble_info disasm_info;
|
166 | b9adb4a6 | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
167 | b9adb4a6 | bellard | |
168 | b9adb4a6 | bellard | INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); |
169 | b9adb4a6 | bellard | |
170 | c27004ec | bellard | disasm_info.read_memory_func = target_read_memory; |
171 | c27004ec | bellard | disasm_info.buffer_vma = code; |
172 | c27004ec | bellard | disasm_info.buffer_length = size; |
173 | 636bd289 | Peter Maydell | disasm_info.print_address_func = generic_print_target_address; |
174 | c27004ec | bellard | |
175 | c27004ec | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
176 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
177 | c27004ec | bellard | #else
|
178 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
179 | c27004ec | bellard | #endif
|
180 | c27004ec | bellard | #if defined(TARGET_I386)
|
181 | c27004ec | bellard | if (flags == 2) |
182 | c27004ec | bellard | disasm_info.mach = bfd_mach_x86_64; |
183 | 5fafdf24 | ths | else if (flags == 1) |
184 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i8086; |
185 | c27004ec | bellard | else
|
186 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i386; |
187 | c27004ec | bellard | print_insn = print_insn_i386; |
188 | c27004ec | bellard | #elif defined(TARGET_ARM)
|
189 | d8fd2954 | Paul Brook | if (flags & 1) { |
190 | d8fd2954 | Paul Brook | print_insn = print_insn_thumb1; |
191 | d8fd2954 | Paul Brook | } else {
|
192 | d8fd2954 | Paul Brook | print_insn = print_insn_arm; |
193 | d8fd2954 | Paul Brook | } |
194 | d8fd2954 | Paul Brook | if (flags & 2) { |
195 | d8fd2954 | Paul Brook | #ifdef TARGET_WORDS_BIGENDIAN
|
196 | d8fd2954 | Paul Brook | disasm_info.endian = BFD_ENDIAN_LITTLE; |
197 | d8fd2954 | Paul Brook | #else
|
198 | d8fd2954 | Paul Brook | disasm_info.endian = BFD_ENDIAN_BIG; |
199 | d8fd2954 | Paul Brook | #endif
|
200 | d8fd2954 | Paul Brook | } |
201 | c27004ec | bellard | #elif defined(TARGET_SPARC)
|
202 | c27004ec | bellard | print_insn = print_insn_sparc; |
203 | 3475187d | bellard | #ifdef TARGET_SPARC64
|
204 | 3475187d | bellard | disasm_info.mach = bfd_mach_sparc_v9b; |
205 | 3b46e624 | ths | #endif
|
206 | c27004ec | bellard | #elif defined(TARGET_PPC)
|
207 | 237c0af0 | j_mayer | if (flags >> 16) |
208 | 111bfab3 | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
209 | 237c0af0 | j_mayer | if (flags & 0xFFFF) { |
210 | 237c0af0 | j_mayer | /* If we have a precise definitions of the instructions set, use it */
|
211 | 237c0af0 | j_mayer | disasm_info.mach = flags & 0xFFFF;
|
212 | 237c0af0 | j_mayer | } else {
|
213 | a2458627 | bellard | #ifdef TARGET_PPC64
|
214 | 237c0af0 | j_mayer | disasm_info.mach = bfd_mach_ppc64; |
215 | a2458627 | bellard | #else
|
216 | 237c0af0 | j_mayer | disasm_info.mach = bfd_mach_ppc; |
217 | a2458627 | bellard | #endif
|
218 | 237c0af0 | j_mayer | } |
219 | c27004ec | bellard | print_insn = print_insn_ppc; |
220 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
221 | e6e5906b | pbrook | print_insn = print_insn_m68k; |
222 | 6af0bf9c | bellard | #elif defined(TARGET_MIPS)
|
223 | 76b3030c | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
224 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
225 | 76b3030c | bellard | #else
|
226 | 76b3030c | bellard | print_insn = print_insn_little_mips; |
227 | 76b3030c | bellard | #endif
|
228 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
229 | fdf9b3e8 | bellard | disasm_info.mach = bfd_mach_sh4; |
230 | fdf9b3e8 | bellard | print_insn = print_insn_sh; |
231 | eddf68a6 | j_mayer | #elif defined(TARGET_ALPHA)
|
232 | b9bec751 | Richard Henderson | disasm_info.mach = bfd_mach_alpha_ev6; |
233 | eddf68a6 | j_mayer | print_insn = print_insn_alpha; |
234 | a25fd137 | ths | #elif defined(TARGET_CRIS)
|
235 | b09cd072 | Edgar E. Iglesias | if (flags != 32) { |
236 | b09cd072 | Edgar E. Iglesias | disasm_info.mach = bfd_mach_cris_v0_v10; |
237 | b09cd072 | Edgar E. Iglesias | print_insn = print_insn_crisv10; |
238 | b09cd072 | Edgar E. Iglesias | } else {
|
239 | b09cd072 | Edgar E. Iglesias | disasm_info.mach = bfd_mach_cris_v32; |
240 | b09cd072 | Edgar E. Iglesias | print_insn = print_insn_crisv32; |
241 | b09cd072 | Edgar E. Iglesias | } |
242 | db500609 | Ulrich Hecht | #elif defined(TARGET_S390X)
|
243 | db500609 | Ulrich Hecht | disasm_info.mach = bfd_mach_s390_64; |
244 | db500609 | Ulrich Hecht | print_insn = print_insn_s390; |
245 | e90e390c | Edgar E. Iglesias | #elif defined(TARGET_MICROBLAZE)
|
246 | e90e390c | Edgar E. Iglesias | disasm_info.mach = bfd_arch_microblaze; |
247 | e90e390c | Edgar E. Iglesias | print_insn = print_insn_microblaze; |
248 | 79368f49 | Michael Walle | #elif defined(TARGET_LM32)
|
249 | 79368f49 | Michael Walle | disasm_info.mach = bfd_mach_lm32; |
250 | 79368f49 | Michael Walle | print_insn = print_insn_lm32; |
251 | c27004ec | bellard | #else
|
252 | b8076a74 | bellard | fprintf(out, "0x" TARGET_FMT_lx
|
253 | b8076a74 | bellard | ": Asm output not supported on this arch\n", code);
|
254 | c27004ec | bellard | return;
|
255 | c6105c0a | bellard | #endif
|
256 | c6105c0a | bellard | |
257 | 7e000c2e | blueswir1 | for (pc = code; size > 0; pc += count, size -= count) { |
258 | fa15e030 | bellard | fprintf(out, "0x" TARGET_FMT_lx ": ", pc); |
259 | c27004ec | bellard | count = print_insn(pc, &disasm_info); |
260 | c27004ec | bellard | #if 0
|
261 | c27004ec | bellard | {
|
262 | c27004ec | bellard | int i;
|
263 | c27004ec | bellard | uint8_t b;
|
264 | c27004ec | bellard | fprintf(out, " {");
|
265 | c27004ec | bellard | for(i = 0; i < count; i++) {
|
266 | c27004ec | bellard | target_read_memory(pc + i, &b, 1, &disasm_info);
|
267 | c27004ec | bellard | fprintf(out, " %02x", b);
|
268 | c27004ec | bellard | }
|
269 | c27004ec | bellard | fprintf(out, " }");
|
270 | c27004ec | bellard | }
|
271 | c27004ec | bellard | #endif
|
272 | c27004ec | bellard | fprintf(out, "\n");
|
273 | c27004ec | bellard | if (count < 0) |
274 | c27004ec | bellard | break;
|
275 | 754d00ae | malc | if (size < count) {
|
276 | 754d00ae | malc | fprintf(out, |
277 | 754d00ae | malc | "Disassembler disagrees with translator over instruction "
|
278 | 754d00ae | malc | "decoding\n"
|
279 | 754d00ae | malc | "Please report this to qemu-devel@nongnu.org\n");
|
280 | 754d00ae | malc | break;
|
281 | 754d00ae | malc | } |
282 | c27004ec | bellard | } |
283 | c27004ec | bellard | } |
284 | c27004ec | bellard | |
285 | c27004ec | bellard | /* Disassemble this for me please... (debugging). */
|
286 | c27004ec | bellard | void disas(FILE *out, void *code, unsigned long size) |
287 | c27004ec | bellard | { |
288 | b0b0f1c9 | Stefan Weil | uintptr_t pc; |
289 | c27004ec | bellard | int count;
|
290 | c27004ec | bellard | struct disassemble_info disasm_info;
|
291 | c27004ec | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
292 | c27004ec | bellard | |
293 | c27004ec | bellard | INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); |
294 | 636bd289 | Peter Maydell | disasm_info.print_address_func = generic_print_host_address; |
295 | c27004ec | bellard | |
296 | b9adb4a6 | bellard | disasm_info.buffer = code; |
297 | b0b0f1c9 | Stefan Weil | disasm_info.buffer_vma = (uintptr_t)code; |
298 | b9adb4a6 | bellard | disasm_info.buffer_length = size; |
299 | b9adb4a6 | bellard | |
300 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
301 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
302 | b9adb4a6 | bellard | #else
|
303 | c27004ec | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
304 | b9adb4a6 | bellard | #endif
|
305 | 5826e519 | Stefan Weil | #if defined(CONFIG_TCG_INTERPRETER)
|
306 | 5826e519 | Stefan Weil | print_insn = print_insn_tci; |
307 | 5826e519 | Stefan Weil | #elif defined(__i386__)
|
308 | c27004ec | bellard | disasm_info.mach = bfd_mach_i386_i386; |
309 | c27004ec | bellard | print_insn = print_insn_i386; |
310 | bc51c5c9 | bellard | #elif defined(__x86_64__)
|
311 | c27004ec | bellard | disasm_info.mach = bfd_mach_x86_64; |
312 | c27004ec | bellard | print_insn = print_insn_i386; |
313 | e58ffeb3 | malc | #elif defined(_ARCH_PPC)
|
314 | c27004ec | bellard | print_insn = print_insn_ppc; |
315 | a993ba85 | bellard | #elif defined(__alpha__)
|
316 | c27004ec | bellard | print_insn = print_insn_alpha; |
317 | aa0aa4fa | bellard | #elif defined(__sparc__)
|
318 | c27004ec | bellard | print_insn = print_insn_sparc; |
319 | 6ecd4534 | blueswir1 | #if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
|
320 | 6ecd4534 | blueswir1 | disasm_info.mach = bfd_mach_sparc_v9b; |
321 | 6ecd4534 | blueswir1 | #endif
|
322 | 5fafdf24 | ths | #elif defined(__arm__)
|
323 | c27004ec | bellard | print_insn = print_insn_arm; |
324 | 6af0bf9c | bellard | #elif defined(__MIPSEB__)
|
325 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
326 | 6af0bf9c | bellard | #elif defined(__MIPSEL__)
|
327 | 6af0bf9c | bellard | print_insn = print_insn_little_mips; |
328 | 48024e4a | bellard | #elif defined(__m68k__)
|
329 | 48024e4a | bellard | print_insn = print_insn_m68k; |
330 | 8f860bb8 | ths | #elif defined(__s390__)
|
331 | 8f860bb8 | ths | print_insn = print_insn_s390; |
332 | f54b3f92 | aurel32 | #elif defined(__hppa__)
|
333 | f54b3f92 | aurel32 | print_insn = print_insn_hppa; |
334 | 903ec55c | Aurelien Jarno | #elif defined(__ia64__)
|
335 | 903ec55c | Aurelien Jarno | print_insn = print_insn_ia64; |
336 | b9adb4a6 | bellard | #else
|
337 | b8076a74 | bellard | fprintf(out, "0x%lx: Asm output not supported on this arch\n",
|
338 | b8076a74 | bellard | (long) code);
|
339 | c27004ec | bellard | return;
|
340 | b9adb4a6 | bellard | #endif
|
341 | b0b0f1c9 | Stefan Weil | for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { |
342 | b0b0f1c9 | Stefan Weil | fprintf(out, "0x%08" PRIxPTR ": ", pc); |
343 | c27004ec | bellard | count = print_insn(pc, &disasm_info); |
344 | b9adb4a6 | bellard | fprintf(out, "\n");
|
345 | b9adb4a6 | bellard | if (count < 0) |
346 | b9adb4a6 | bellard | break;
|
347 | b9adb4a6 | bellard | } |
348 | b9adb4a6 | bellard | } |
349 | b9adb4a6 | bellard | |
350 | b9adb4a6 | bellard | /* Look up symbol for debugging purpose. Returns "" if unknown. */
|
351 | c27004ec | bellard | const char *lookup_symbol(target_ulong orig_addr) |
352 | b9adb4a6 | bellard | { |
353 | 49918a75 | pbrook | const char *symbol = ""; |
354 | e80cfcfc | bellard | struct syminfo *s;
|
355 | 3b46e624 | ths | |
356 | e80cfcfc | bellard | for (s = syminfos; s; s = s->next) {
|
357 | 49918a75 | pbrook | symbol = s->lookup_symbol(s, orig_addr); |
358 | 49918a75 | pbrook | if (symbol[0] != '\0') { |
359 | 49918a75 | pbrook | break;
|
360 | 49918a75 | pbrook | } |
361 | b9adb4a6 | bellard | } |
362 | 49918a75 | pbrook | |
363 | 49918a75 | pbrook | return symbol;
|
364 | b9adb4a6 | bellard | } |
365 | 9307c4c1 | bellard | |
366 | 9307c4c1 | bellard | #if !defined(CONFIG_USER_ONLY)
|
367 | 9307c4c1 | bellard | |
368 | 376253ec | aliguori | #include "monitor.h" |
369 | 3d2cfdf1 | bellard | |
370 | 9307c4c1 | bellard | static int monitor_disas_is_physical; |
371 | 9349b4f9 | Andreas Färber | static CPUArchState *monitor_disas_env;
|
372 | 9307c4c1 | bellard | |
373 | 9307c4c1 | bellard | static int |
374 | a5f1b965 | blueswir1 | monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
|
375 | a5f1b965 | blueswir1 | struct disassemble_info *info)
|
376 | 9307c4c1 | bellard | { |
377 | 9307c4c1 | bellard | if (monitor_disas_is_physical) {
|
378 | 54f7b4a3 | Stefan Weil | cpu_physical_memory_read(memaddr, myaddr, length); |
379 | 9307c4c1 | bellard | } else {
|
380 | 6a00d601 | bellard | cpu_memory_rw_debug(monitor_disas_env, memaddr,myaddr, length, 0);
|
381 | 9307c4c1 | bellard | } |
382 | 9307c4c1 | bellard | return 0; |
383 | 9307c4c1 | bellard | } |
384 | 9307c4c1 | bellard | |
385 | 8b7968f7 | Stefan Weil | static int GCC_FMT_ATTR(2, 3) |
386 | 8b7968f7 | Stefan Weil | monitor_fprintf(FILE *stream, const char *fmt, ...) |
387 | 3d2cfdf1 | bellard | { |
388 | 3d2cfdf1 | bellard | va_list ap; |
389 | 3d2cfdf1 | bellard | va_start(ap, fmt); |
390 | 376253ec | aliguori | monitor_vprintf((Monitor *)stream, fmt, ap); |
391 | 3d2cfdf1 | bellard | va_end(ap); |
392 | 3d2cfdf1 | bellard | return 0; |
393 | 3d2cfdf1 | bellard | } |
394 | 3d2cfdf1 | bellard | |
395 | 9349b4f9 | Andreas Färber | void monitor_disas(Monitor *mon, CPUArchState *env,
|
396 | 6a00d601 | bellard | target_ulong pc, int nb_insn, int is_physical, int flags) |
397 | 9307c4c1 | bellard | { |
398 | 9307c4c1 | bellard | int count, i;
|
399 | 9307c4c1 | bellard | struct disassemble_info disasm_info;
|
400 | 9307c4c1 | bellard | int (*print_insn)(bfd_vma pc, disassemble_info *info);
|
401 | 9307c4c1 | bellard | |
402 | 376253ec | aliguori | INIT_DISASSEMBLE_INFO(disasm_info, (FILE *)mon, monitor_fprintf); |
403 | 9307c4c1 | bellard | |
404 | 6a00d601 | bellard | monitor_disas_env = env; |
405 | 9307c4c1 | bellard | monitor_disas_is_physical = is_physical; |
406 | 9307c4c1 | bellard | disasm_info.read_memory_func = monitor_read_memory; |
407 | 636bd289 | Peter Maydell | disasm_info.print_address_func = generic_print_target_address; |
408 | 9307c4c1 | bellard | |
409 | 9307c4c1 | bellard | disasm_info.buffer_vma = pc; |
410 | 9307c4c1 | bellard | |
411 | 9307c4c1 | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
412 | 9307c4c1 | bellard | disasm_info.endian = BFD_ENDIAN_BIG; |
413 | 9307c4c1 | bellard | #else
|
414 | 9307c4c1 | bellard | disasm_info.endian = BFD_ENDIAN_LITTLE; |
415 | 9307c4c1 | bellard | #endif
|
416 | 9307c4c1 | bellard | #if defined(TARGET_I386)
|
417 | fa15e030 | bellard | if (flags == 2) |
418 | fa15e030 | bellard | disasm_info.mach = bfd_mach_x86_64; |
419 | 5fafdf24 | ths | else if (flags == 1) |
420 | 9307c4c1 | bellard | disasm_info.mach = bfd_mach_i386_i8086; |
421 | fa15e030 | bellard | else
|
422 | fa15e030 | bellard | disasm_info.mach = bfd_mach_i386_i386; |
423 | 9307c4c1 | bellard | print_insn = print_insn_i386; |
424 | 9307c4c1 | bellard | #elif defined(TARGET_ARM)
|
425 | 9307c4c1 | bellard | print_insn = print_insn_arm; |
426 | cbd669da | ths | #elif defined(TARGET_ALPHA)
|
427 | cbd669da | ths | print_insn = print_insn_alpha; |
428 | 9307c4c1 | bellard | #elif defined(TARGET_SPARC)
|
429 | 9307c4c1 | bellard | print_insn = print_insn_sparc; |
430 | 682c4f15 | blueswir1 | #ifdef TARGET_SPARC64
|
431 | 682c4f15 | blueswir1 | disasm_info.mach = bfd_mach_sparc_v9b; |
432 | 682c4f15 | blueswir1 | #endif
|
433 | 9307c4c1 | bellard | #elif defined(TARGET_PPC)
|
434 | a2458627 | bellard | #ifdef TARGET_PPC64
|
435 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc64; |
436 | a2458627 | bellard | #else
|
437 | a2458627 | bellard | disasm_info.mach = bfd_mach_ppc; |
438 | a2458627 | bellard | #endif
|
439 | 9307c4c1 | bellard | print_insn = print_insn_ppc; |
440 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
441 | e6e5906b | pbrook | print_insn = print_insn_m68k; |
442 | 6af0bf9c | bellard | #elif defined(TARGET_MIPS)
|
443 | 76b3030c | bellard | #ifdef TARGET_WORDS_BIGENDIAN
|
444 | 6af0bf9c | bellard | print_insn = print_insn_big_mips; |
445 | 76b3030c | bellard | #else
|
446 | 76b3030c | bellard | print_insn = print_insn_little_mips; |
447 | 76b3030c | bellard | #endif
|
448 | b4e1f077 | Magnus Damm | #elif defined(TARGET_SH4)
|
449 | b4e1f077 | Magnus Damm | disasm_info.mach = bfd_mach_sh4; |
450 | b4e1f077 | Magnus Damm | print_insn = print_insn_sh; |
451 | db500609 | Ulrich Hecht | #elif defined(TARGET_S390X)
|
452 | db500609 | Ulrich Hecht | disasm_info.mach = bfd_mach_s390_64; |
453 | db500609 | Ulrich Hecht | print_insn = print_insn_s390; |
454 | 79368f49 | Michael Walle | #elif defined(TARGET_LM32)
|
455 | 79368f49 | Michael Walle | disasm_info.mach = bfd_mach_lm32; |
456 | 79368f49 | Michael Walle | print_insn = print_insn_lm32; |
457 | 9307c4c1 | bellard | #else
|
458 | 376253ec | aliguori | monitor_printf(mon, "0x" TARGET_FMT_lx
|
459 | 376253ec | aliguori | ": Asm output not supported on this arch\n", pc);
|
460 | 9307c4c1 | bellard | return;
|
461 | 9307c4c1 | bellard | #endif
|
462 | 9307c4c1 | bellard | |
463 | 9307c4c1 | bellard | for(i = 0; i < nb_insn; i++) { |
464 | 376253ec | aliguori | monitor_printf(mon, "0x" TARGET_FMT_lx ": ", pc); |
465 | 9307c4c1 | bellard | count = print_insn(pc, &disasm_info); |
466 | 376253ec | aliguori | monitor_printf(mon, "\n");
|
467 | 9307c4c1 | bellard | if (count < 0) |
468 | 9307c4c1 | bellard | break;
|
469 | 9307c4c1 | bellard | pc += count; |
470 | 9307c4c1 | bellard | } |
471 | 9307c4c1 | bellard | } |
472 | 9307c4c1 | bellard | #endif |