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 (memaddr, myaddr, length, info)
21 struct disassemble_info *info;
23 if (memaddr < info->buffer_vma
24 || memaddr + length > info->buffer_vma + info->buffer_length)
25 /* Out of bounds. Use EIO because GDB uses it. */
27 memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
31 #if !defined(CONFIG_USER_ONLY)
32 /* Get LENGTH bytes from info's buffer, at target address memaddr.
33 Transfer them to myaddr. */
35 target_read_memory (memaddr, myaddr, length, info)
39 struct disassemble_info *info;
42 for(i = 0; i < length; i++) {
43 myaddr[i] = ldub_code((void *)((long)memaddr + i));
49 /* Print an error message. We can assume that this is in response to
50 an error return from buffer_read_memory. */
52 perror_memory (status, memaddr, info)
55 struct disassemble_info *info;
59 (*info->fprintf_func) (info->stream, "Unknown error %d\n", status);
61 /* Actually, address between memaddr and memaddr + len was
63 (*info->fprintf_func) (info->stream,
64 "Address 0x%llx is out of bounds.\n", memaddr);
67 /* This could be in a separate file, to save miniscule amounts of space
68 in statically linked executables. */
70 /* Just print the address is hex. This is included for completeness even
71 though both GDB and objdump provide their own (to print symbolic
75 generic_print_address (addr, info)
77 struct disassemble_info *info;
79 (*info->fprintf_func) (info->stream, "0x%llx", addr);
82 /* Just return the given address. */
85 generic_symbol_at_address (addr, info)
87 struct disassemble_info * info;
92 bfd_vma bfd_getl32 (const bfd_byte *addr)
96 v = (unsigned long) addr[0];
97 v |= (unsigned long) addr[1] << 8;
98 v |= (unsigned long) addr[2] << 16;
99 v |= (unsigned long) addr[3] << 24;
103 bfd_vma bfd_getb32 (const bfd_byte *addr)
107 v = (unsigned long) addr[0] << 24;
108 v |= (unsigned long) addr[1] << 16;
109 v |= (unsigned long) addr[2] << 8;
110 v |= (unsigned long) addr[3];
114 /* Disassemble this for me please... (debugging). 'flags' is only used
115 for i386: non zero means 16 bit code */
116 void disas(FILE *out, void *code, unsigned long size, int is_host, int flags)
120 struct disassemble_info disasm_info;
121 int (*print_insn)(bfd_vma pc, disassemble_info *info);
123 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
125 #if !defined(CONFIG_USER_ONLY)
127 disasm_info.read_memory_func = target_read_memory;
131 disasm_info.buffer = code;
132 disasm_info.buffer_vma = (unsigned long)code;
133 disasm_info.buffer_length = size;
136 #ifdef WORDS_BIGENDIAN
137 disasm_info.endian = BFD_ENDIAN_BIG;
139 disasm_info.endian = BFD_ENDIAN_LITTLE;
141 #if defined(__i386__)
142 disasm_info.mach = bfd_mach_i386_i386;
143 print_insn = print_insn_i386;
144 #elif defined(__x86_64__)
145 disasm_info.mach = bfd_mach_x86_64;
146 print_insn = print_insn_i386;
147 #elif defined(__powerpc__)
148 print_insn = print_insn_ppc;
149 #elif defined(__alpha__)
150 print_insn = print_insn_alpha;
151 #elif defined(__sparc__)
152 print_insn = print_insn_sparc;
153 #elif defined(__arm__)
154 print_insn = print_insn_arm;
156 fprintf(out, "Asm output not supported on this arch\n");
160 #ifdef TARGET_WORDS_BIGENDIAN
161 disasm_info.endian = BFD_ENDIAN_BIG;
163 disasm_info.endian = BFD_ENDIAN_LITTLE;
165 #if defined(TARGET_I386)
167 disasm_info.mach = bfd_mach_i386_i386;
169 disasm_info.mach = bfd_mach_i386_i8086;
170 print_insn = print_insn_i386;
171 #elif defined(TARGET_ARM)
172 print_insn = print_insn_arm;
173 #elif defined(TARGET_SPARC)
174 print_insn = print_insn_sparc;
175 #elif defined(TARGET_PPC)
176 print_insn = print_insn_ppc;
178 fprintf(out, "Asm output not supported on this arch\n");
183 for (pc = code; pc < (uint8_t *)code + size; pc += count) {
184 fprintf(out, "0x%08lx: ", (long)pc);
186 /* since data are included in the code, it is better to
187 display code data too */
189 fprintf(out, "%08x ", (int)bfd_getl32((const bfd_byte *)pc));
192 count = print_insn((unsigned long)pc, &disasm_info);
199 /* Look up symbol for debugging purpose. Returns "" if unknown. */
200 const char *lookup_symbol(void *orig_addr)
203 /* Hack, because we know this is x86. */
207 for (s = syminfos; s; s = s->next) {
208 sym = s->disas_symtab;
209 for (i = 0; i < s->disas_num_syms; i++) {
210 if (sym[i].st_shndx == SHN_UNDEF
211 || sym[i].st_shndx >= SHN_LORESERVE)
214 if (ELF_ST_TYPE(sym[i].st_info) != STT_FUNC)
217 if ((long)orig_addr >= sym[i].st_value
218 && (long)orig_addr < sym[i].st_value + sym[i].st_size)
219 return s->disas_strtab + sym[i].st_name;
225 #if !defined(CONFIG_USER_ONLY)
227 void term_vprintf(const char *fmt, va_list ap);
228 void term_printf(const char *fmt, ...);
230 static int monitor_disas_is_physical;
233 monitor_read_memory (memaddr, myaddr, length, info)
237 struct disassemble_info *info;
239 if (monitor_disas_is_physical) {
240 cpu_physical_memory_rw(memaddr, myaddr, length, 0);
242 cpu_memory_rw_debug(cpu_single_env, memaddr,myaddr, length, 0);
247 static int monitor_fprintf(FILE *stream, const char *fmt, ...)
251 term_vprintf(fmt, ap);
256 void monitor_disas(target_ulong pc, int nb_insn, int is_physical, int flags)
259 struct disassemble_info disasm_info;
260 int (*print_insn)(bfd_vma pc, disassemble_info *info);
262 INIT_DISASSEMBLE_INFO(disasm_info, NULL, monitor_fprintf);
264 monitor_disas_is_physical = is_physical;
265 disasm_info.read_memory_func = monitor_read_memory;
267 disasm_info.buffer_vma = pc;
269 #ifdef TARGET_WORDS_BIGENDIAN
270 disasm_info.endian = BFD_ENDIAN_BIG;
272 disasm_info.endian = BFD_ENDIAN_LITTLE;
274 #if defined(TARGET_I386)
276 disasm_info.mach = bfd_mach_i386_i386;
278 disasm_info.mach = bfd_mach_i386_i8086;
279 print_insn = print_insn_i386;
280 #elif defined(TARGET_ARM)
281 print_insn = print_insn_arm;
282 #elif defined(TARGET_SPARC)
283 print_insn = print_insn_sparc;
284 #elif defined(TARGET_PPC)
285 print_insn = print_insn_ppc;
287 term_printf("Asm output not supported on this arch\n");
291 for(i = 0; i < nb_insn; i++) {
292 term_printf("0x%08lx: ", (unsigned long)pc);
293 count = print_insn(pc, &disasm_info);