1 |
|
/* |
2 |
|
* mon_disass.cpp - Disassemblers |
3 |
|
* |
4 |
< |
* mon (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 |
24 |
|
|
25 |
|
#include "mon.h" |
26 |
|
#include "mon_disass.h" |
27 |
+ |
|
28 |
+ |
#include "mon_atraps.h" |
29 |
|
#include "mon_lowmem.h" |
30 |
|
|
31 |
|
|
32 |
+ |
// Flag: enable MacOS A-Trap and LM globals lookup in 68k disassembler |
33 |
+ |
bool mon_macos_mode = false; |
34 |
+ |
|
35 |
+ |
|
36 |
|
/* |
37 |
|
* GNU disassembler callbacks |
38 |
|
*/ |
40 |
|
extern "C" { |
41 |
|
#include "disass/dis-asm.h" |
42 |
|
|
43 |
< |
int buffer_read_memory(bfd_vma from, bfd_byte *to, int length, struct disassemble_info *info) |
43 |
> |
int buffer_read_memory(bfd_vma from, bfd_byte *to, unsigned int length, struct disassemble_info *info) |
44 |
|
{ |
45 |
|
while (length--) |
46 |
|
*to++ = mon_read_byte(from++); |
56 |
|
|
57 |
|
void generic_print_address(bfd_vma addr, struct disassemble_info *info) |
58 |
|
{ |
59 |
< |
if (lookup_lowmem && ((addr >= 0x100 && addr < 0x400) || (addr >= 0x800 && addr < 0xe00) || (addr >= 0x1e00 && addr < 0x3000))) { |
60 |
< |
// Look for address in low memory globals table |
61 |
< |
const lowmem_info *p = lowmem; |
62 |
< |
while (p->name) { |
63 |
< |
if (addr >= p[0].addr && addr < p[1].addr) { |
64 |
< |
if (addr == p[0].addr) |
65 |
< |
info->fprintf_func(info->stream, "%s", p->name); |
66 |
< |
else |
67 |
< |
info->fprintf_func(info->stream, "%s+%d", p->name, addr - p->addr); |
68 |
< |
return; |
59 |
> |
if (lookup_lowmem && addr >= 0x100 && addr < 0x3000) { |
60 |
> |
if (((addr >= 0x400 && addr < 0x800) || (addr >= 0xe00 && addr < 0x1e00)) && ((addr & 3) == 0)) { |
61 |
> |
// Look for address in A-Trap table |
62 |
> |
uint16 opcode = (addr < 0xe00 ? 0xa000 + (addr - 0x400) / 4 : 0xa800 + (addr - 0xe00) / 4); |
63 |
> |
uint16 mask = (addr < 0xe00 ? 0xf8ff : 0xffff); |
64 |
> |
const atrap_info *p = atraps; |
65 |
> |
while (p->word) { |
66 |
> |
if ((p->word & mask) == opcode) { |
67 |
> |
info->fprintf_func(info->stream, p->name); |
68 |
> |
return; |
69 |
> |
} |
70 |
> |
p++; |
71 |
> |
} |
72 |
> |
} else { |
73 |
> |
// Look for address in low memory globals table |
74 |
> |
const lowmem_info *p = lowmem; |
75 |
> |
while (p->name) { |
76 |
> |
if (addr >= p[0].addr && addr < p[1].addr) { |
77 |
> |
if (addr == p[0].addr) |
78 |
> |
info->fprintf_func(info->stream, "%s", p->name); |
79 |
> |
else |
80 |
> |
info->fprintf_func(info->stream, "%s+%d", p->name, addr - p->addr); |
81 |
> |
return; |
82 |
> |
} |
83 |
> |
p++; |
84 |
|
} |
64 |
– |
p++; |
85 |
|
} |
86 |
|
} |
87 |
< |
info->fprintf_func(info->stream, "$%08x", addr); |
87 |
> |
if (addr >= UVAL64(0x100000000)) |
88 |
> |
info->fprintf_func(info->stream, "$%08x%08x", (uint32)(addr >> 32), (uint32)addr); |
89 |
> |
else |
90 |
> |
info->fprintf_func(info->stream, "$%08x", (uint32)addr); |
91 |
|
} |
92 |
|
|
93 |
|
int generic_symbol_at_address(bfd_vma addr, struct disassemble_info *info) |
95 |
|
return 0; |
96 |
|
} |
97 |
|
|
98 |
+ |
void print_68k_invalid_opcode(unsigned long opcode, struct disassemble_info *info) |
99 |
+ |
{ |
100 |
+ |
if (mon_macos_mode) { |
101 |
+ |
// Look for MacOS A-Trap |
102 |
+ |
const atrap_info *p = atraps; |
103 |
+ |
while (p->word) { |
104 |
+ |
if (p->word == opcode) { |
105 |
+ |
info->fprintf_func(info->stream, p->name); |
106 |
+ |
return; |
107 |
+ |
} |
108 |
+ |
p++; |
109 |
+ |
} |
110 |
+ |
} |
111 |
+ |
info->fprintf_func(info->stream, "?"); |
112 |
+ |
} |
113 |
+ |
|
114 |
|
}; |
115 |
|
|
116 |
|
|
150 |
|
INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf); |
151 |
|
|
152 |
|
// Disassemble instruction |
153 |
< |
lookup_lowmem = true; |
153 |
> |
lookup_lowmem = mon_macos_mode; |
154 |
|
int num = print_insn_m68k(adr, &info); |
155 |
< |
if (num >= 2) |
156 |
< |
fprintf(f, "%04x ", mon_read_half(adr)); |
157 |
< |
else |
158 |
< |
fprintf(f, " "); |
159 |
< |
if (num >= 4) |
160 |
< |
fprintf(f, "%04x ", mon_read_half(adr + 2)); |
161 |
< |
else |
123 |
< |
fprintf(f, " "); |
124 |
< |
if (num >= 6) |
125 |
< |
fprintf(f, "%04x ", mon_read_half(adr + 4)); |
126 |
< |
else |
127 |
< |
fprintf(f, " "); |
155 |
> |
|
156 |
> |
for (int i=0; i<6; i+=2) { |
157 |
> |
if (num > i) |
158 |
> |
fprintf(f, "%04x ", mon_read_half(adr + i)); |
159 |
> |
else |
160 |
> |
fprintf(f, " "); |
161 |
> |
} |
162 |
|
if (num == 8) |
163 |
|
fprintf(f, "%04x\t%s\n", mon_read_half(adr + 6), buf); |
164 |
< |
else if (num >= 8) |
164 |
> |
else if (num > 8) |
165 |
|
fprintf(f, "...\t%s\n", buf); |
166 |
|
else |
167 |
|
fprintf(f, " \t%s\n", buf); |
168 |
+ |
|
169 |
|
return num; |
170 |
|
} |
171 |
|
|
172 |
< |
int disass_x86(FILE *f, uint32 adr) |
172 |
> |
int disass_x86(FILE *f, uint32 adr, uint32 bits) |
173 |
|
{ |
174 |
|
// Initialize info for GDB disassembler |
175 |
|
disassemble_info info; |
178 |
|
sfile.buffer = buf; |
179 |
|
sfile.current = buf; |
180 |
|
INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf); |
181 |
+ |
if (bits == 16) |
182 |
+ |
info.mach = bfd_mach_i386_i8086; |
183 |
+ |
else if (bits == 64) |
184 |
+ |
info.mach = bfd_mach_x86_64; |
185 |
|
|
186 |
|
// Disassemble instruction |
187 |
|
lookup_lowmem = false; |
188 |
< |
int num = print_insn_i386(adr, &info); |
189 |
< |
fprintf(f, "%s\n", buf); |
188 |
> |
int num = print_insn_i386_att(adr, &info); |
189 |
> |
|
190 |
> |
for (int i=0; i<6; i++) { |
191 |
> |
if (num > i) |
192 |
> |
fprintf(f, "%02x ", mon_read_byte(adr + i)); |
193 |
> |
else |
194 |
> |
fprintf(f, " "); |
195 |
> |
} |
196 |
> |
if (num == 7) |
197 |
> |
fprintf(f, "%02x\t%s\n", mon_read_byte(adr + 7), buf); |
198 |
> |
else if (num > 7) |
199 |
> |
fprintf(f, "..\t%s\n", buf); |
200 |
> |
else |
201 |
> |
fprintf(f, " \t%s\n", buf); |
202 |
> |
|
203 |
|
return num; |
204 |
|
} |