1 |
|
/* |
2 |
|
* mon_disass.cpp - Disassemblers |
3 |
|
* |
4 |
< |
* cxmon (C) 1997-2000 Christian Bauer, Marc Hellwig |
4 |
> |
* cxmon (C) 1997-2004 Christian Bauer, Marc Hellwig |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
|
|
23 |
+ |
#include <assert.h> |
24 |
|
#include <stdarg.h> |
25 |
|
|
26 |
|
#include "mon.h" |
41 |
|
extern "C" { |
42 |
|
#include "disass/dis-asm.h" |
43 |
|
|
44 |
< |
int buffer_read_memory(bfd_vma from, bfd_byte *to, int length, struct disassemble_info *info) |
44 |
> |
int buffer_read_memory(bfd_vma from, bfd_byte *to, unsigned int length, struct disassemble_info *info) |
45 |
|
{ |
46 |
|
while (length--) |
47 |
|
*to++ = mon_read_byte(from++); |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
< |
info->fprintf_func(info->stream, "$%08x", addr); |
88 |
> |
if (addr >= UVAL64(0x100000000)) |
89 |
> |
info->fprintf_func(info->stream, "$%08x%08x", (uint32)(addr >> 32), (uint32)addr); |
90 |
> |
else |
91 |
> |
info->fprintf_func(info->stream, "$%08x", (uint32)addr); |
92 |
|
} |
93 |
|
|
94 |
|
int generic_symbol_at_address(bfd_vma addr, struct disassemble_info *info) |
170 |
|
return num; |
171 |
|
} |
172 |
|
|
173 |
< |
int disass_x86(FILE *f, uint32 adr, bool i8086) |
173 |
> |
int disass_mips(FILE *f, uint32 adr, int little_endian) |
174 |
> |
{ |
175 |
> |
// Initialize info for GDB disassembler |
176 |
> |
disassemble_info info; |
177 |
> |
char buf[1024]; |
178 |
> |
SFILE sfile = {buf, buf}; |
179 |
> |
sfile.buffer = buf; |
180 |
> |
sfile.current = buf; |
181 |
> |
INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf); |
182 |
> |
|
183 |
> |
// Disassemble instruction |
184 |
> |
lookup_lowmem = false; |
185 |
> |
int num = little_endian ? print_insn_little_mips(adr, &info) : print_insn_big_mips(adr, &info); |
186 |
> |
|
187 |
> |
assert(num == 4); |
188 |
> |
for (int i=0; i<4; i++) |
189 |
> |
fprintf(f, " %02x", mon_read_byte(adr + i)); |
190 |
> |
|
191 |
> |
fprintf(f, " %s\n", buf); |
192 |
> |
|
193 |
> |
return num; |
194 |
> |
} |
195 |
> |
|
196 |
> |
int disass_x86(FILE *f, uint32 adr, uint32 bits) |
197 |
|
{ |
198 |
|
// Initialize info for GDB disassembler |
199 |
|
disassemble_info info; |
202 |
|
sfile.buffer = buf; |
203 |
|
sfile.current = buf; |
204 |
|
INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf); |
205 |
< |
if (i8086) |
205 |
> |
if (bits == 16) |
206 |
|
info.mach = bfd_mach_i386_i8086; |
207 |
+ |
else if (bits == 64) |
208 |
+ |
info.mach = bfd_mach_x86_64; |
209 |
|
|
210 |
|
// Disassemble instruction |
211 |
|
lookup_lowmem = false; |
212 |
< |
int num = print_insn_i386(adr, &info); |
212 |
> |
int num = print_insn_i386_att(adr, &info); |
213 |
|
|
214 |
|
for (int i=0; i<6; i++) { |
215 |
|
if (num > i) |