25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_m68k.c,v 1.12 2006/07/20 21:52:59 debug Exp $ |
* $Id: cpu_m68k.c,v 1.14 2006/09/19 10:50:08 debug Exp $ |
29 |
* |
* |
30 |
* Motorola 68K CPU emulation. |
* Motorola 68K CPU emulation. |
31 |
*/ |
*/ |
39 |
#include "machine.h" |
#include "machine.h" |
40 |
#include "memory.h" |
#include "memory.h" |
41 |
#include "misc.h" |
#include "misc.h" |
42 |
|
#include "settings.h" |
43 |
#include "symbol.h" |
#include "symbol.h" |
44 |
|
|
45 |
|
|
49 |
|
|
50 |
|
|
51 |
static char *m68k_aname[] = { "a0", "a1", "a2", "a3", "a4", "a5", "fp", "a7" }; |
static char *m68k_aname[] = { "a0", "a1", "a2", "a3", "a4", "a5", "fp", "a7" }; |
52 |
|
static char *m68k_dname[] = { "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7" }; |
53 |
|
|
54 |
|
|
55 |
/* |
/* |
63 |
int m68k_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, |
int m68k_cpu_new(struct cpu *cpu, struct memory *mem, struct machine *machine, |
64 |
int cpu_id, char *cpu_type_name) |
int cpu_id, char *cpu_type_name) |
65 |
{ |
{ |
66 |
if (strcasecmp(cpu_type_name, "68020") != 0) |
int i = 0; |
67 |
|
struct m68k_cpu_type_def cpu_type_defs[] = M68K_CPU_TYPE_DEFS; |
68 |
|
|
69 |
|
/* Scan the cpu_type_defs list for this cpu type: */ |
70 |
|
while (cpu_type_defs[i].name != NULL) { |
71 |
|
if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) { |
72 |
|
break; |
73 |
|
} |
74 |
|
i++; |
75 |
|
} |
76 |
|
if (cpu_type_defs[i].name == NULL) |
77 |
return 0; |
return 0; |
78 |
|
|
79 |
cpu->run_instr = m68k_run_instr; |
cpu->run_instr = m68k_run_instr; |
83 |
m68k_invalidate_translation_caches; |
m68k_invalidate_translation_caches; |
84 |
cpu->invalidate_code_translation = m68k_invalidate_code_translation; |
cpu->invalidate_code_translation = m68k_invalidate_code_translation; |
85 |
cpu->is_32bit = 1; |
cpu->is_32bit = 1; |
|
|
|
86 |
cpu->byte_order = EMUL_BIG_ENDIAN; |
cpu->byte_order = EMUL_BIG_ENDIAN; |
87 |
|
|
88 |
|
cpu->cd.m68k.cpu_type = cpu_type_defs[i]; |
89 |
|
|
90 |
/* Only show name and caches etc for CPU nr 0 (in SMP machines): */ |
/* Only show name and caches etc for CPU nr 0 (in SMP machines): */ |
91 |
if (cpu_id == 0) { |
if (cpu_id == 0) { |
92 |
debug("%s", cpu->name); |
debug("%s", cpu->name); |
93 |
} |
} |
94 |
|
|
95 |
|
/* Add all register names to the settings: */ |
96 |
|
CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc); |
97 |
|
for (i=0; i<N_M68K_AREGS; i++) |
98 |
|
CPU_SETTINGS_ADD_REGISTER32(m68k_aname[i], cpu->cd.m68k.a[i]); |
99 |
|
/* Both "fp" and "a6" should map to the same register: */ |
100 |
|
CPU_SETTINGS_ADD_REGISTER32("a6", cpu->cd.m68k.a[6]); |
101 |
|
for (i=0; i<N_M68K_DREGS; i++) |
102 |
|
CPU_SETTINGS_ADD_REGISTER32(m68k_dname[i], cpu->cd.m68k.d[i]); |
103 |
|
|
104 |
return 1; |
return 1; |
105 |
} |
} |
106 |
|
|
112 |
*/ |
*/ |
113 |
void m68k_cpu_list_available_types(void) |
void m68k_cpu_list_available_types(void) |
114 |
{ |
{ |
115 |
debug("68020\n"); |
int i = 0, j; |
116 |
/* TODO */ |
struct m68k_cpu_type_def tdefs[] = M68K_CPU_TYPE_DEFS; |
117 |
|
|
118 |
|
while (tdefs[i].name != NULL) { |
119 |
|
debug("%s", tdefs[i].name); |
120 |
|
for (j=10 - strlen(tdefs[i].name); j>0; j--) |
121 |
|
debug(" "); |
122 |
|
i++; |
123 |
|
if ((i % 6) == 0 || tdefs[i].name == NULL) |
124 |
|
debug("\n"); |
125 |
|
} |
126 |
} |
} |
127 |
|
|
128 |
|
|
148 |
{ |
{ |
149 |
char *symbol; |
char *symbol; |
150 |
uint64_t offset; |
uint64_t offset; |
151 |
int x = cpu->cpu_id; |
int x = cpu->cpu_id, i; |
152 |
|
|
153 |
if (gprs) { |
if (gprs) { |
154 |
/* Special registers (pc, ...) first: */ |
/* Special registers (pc, ...) first: */ |
155 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
156 |
cpu->pc, &offset); |
cpu->pc, &offset); |
157 |
|
|
158 |
debug("cpu%i: pc = 0x%08"PRIx32, x, (uint32_t)cpu->pc); |
debug("cpu%i: pc = 0x%08"PRIx32, x, (uint32_t)cpu->pc); |
159 |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* m68k_cpu_register_match(): |
|
|
*/ |
|
|
void m68k_cpu_register_match(struct machine *m, char *name, |
|
|
int writeflag, uint64_t *valuep, int *match_register) |
|
|
{ |
|
|
int cpunr = 0; |
|
|
|
|
|
/* CPU number: */ |
|
160 |
|
|
161 |
/* TODO */ |
for (i=0; i<N_M68K_AREGS; i++) { |
162 |
|
if ((i % 4) == 0) |
163 |
|
debug("cpu%i:", x); |
164 |
|
debug(" %s = 0x%08"PRIx32" ", |
165 |
|
m68k_aname[i], cpu->cd.m68k.a[i]); |
166 |
|
if ((i % 4) == 3) |
167 |
|
debug("\n"); |
168 |
|
} |
169 |
|
|
170 |
/* Register name: */ |
for (i=0; i<N_M68K_DREGS; i++) { |
171 |
if (strcasecmp(name, "pc") == 0) { |
if ((i % 4) == 0) |
172 |
if (writeflag) { |
debug("cpu%i:", x); |
173 |
m->cpus[cpunr]->pc = *valuep; |
debug(" %s = 0x%08"PRIx32" ", |
174 |
} else |
m68k_dname[i], cpu->cd.m68k.d[i]); |
175 |
*valuep = m->cpus[cpunr]->pc; |
if ((i % 4) == 3) |
176 |
*match_register = 1; |
debug("\n"); |
177 |
|
} |
178 |
} |
} |
179 |
} |
} |
180 |
|
|
267 |
|
|
268 |
print_two(ib, &len); |
print_two(ib, &len); |
269 |
|
|
270 |
if (ib[0] == 0x48) { |
switch (ib[0] >> 4) { |
271 |
if (ib[1] >= 0x40 && ib[1] <= 0x47) { |
|
272 |
print_spaces(len); |
case 0x4: |
273 |
debug("swap\td%i\n", ib[1] & 7); |
switch (ib[0] & 0xf) { |
274 |
} else if (ib[1] >= 0x48 && ib[1] <= 0x4f) { |
|
275 |
print_spaces(len); |
case 0xe: |
276 |
debug("bkpt\t#%i\n", ib[1] & 7); |
if (ib[1] >= 0x50 && ib[1] <= 0x57) { |
277 |
} else { |
print_two(ib, &len); |
278 |
print_spaces(len); |
print_spaces(len); |
279 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
debug("linkw\t%%%s,#%i\n", m68k_aname[ib[1] & 7], |
280 |
} |
((ib[2] << 8) + ib[3])); |
281 |
} else if (ib[0] == 0x4a) { |
} else if (ib[1] >= 0x58 && ib[1] <= 0x5f) { |
282 |
if (ib[1] == 0xfc) { |
print_spaces(len); |
283 |
print_spaces(len); |
debug("unlk\t%%%s\n", m68k_aname[ib[1] & 7]); |
284 |
debug("illegal\n"); |
} else if (ib[1] == 0x71) { |
285 |
} else { |
print_spaces(len); |
286 |
print_spaces(len); |
debug("nop\n"); |
287 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
} else if (ib[1] == 0x73) { |
288 |
} |
print_spaces(len); |
289 |
} else if (ib[0] == 0x4e) { |
debug("rte\n"); |
290 |
if (ib[1] >= 0x40 && ib[1] <= 0x4f) { |
} else if (ib[1] == 0x74) { |
291 |
print_spaces(len); |
print_two(ib, &len); |
292 |
debug("trap\t#%i\n", ib[1] & 15); |
print_spaces(len); |
293 |
} else if (ib[1] >= 0x50 && ib[1] <= 0x57) { |
debug("rtd\t#0x%04x\n", ((ib[2] << 8) + ib[3])); |
294 |
print_two(ib, &len); |
} else if (ib[1] == 0x75) { |
295 |
print_spaces(len); |
print_spaces(len); |
296 |
debug("linkw\t%%%s,#%i\n", m68k_aname[ib[1] & 7], |
debug("rts\n"); |
297 |
((ib[2] << 8) + ib[3])); |
} else { |
298 |
} else if (ib[1] >= 0x58 && ib[1] <= 0x5f) { |
print_spaces(len); |
299 |
print_spaces(len); |
debug("UNIMPLEMENTED\n"); |
300 |
debug("unlk\t%%%s\n", m68k_aname[ib[1] & 7]); |
} |
301 |
} else if (ib[1] == 0x70) { |
break; |
302 |
print_spaces(len); |
|
303 |
debug("reset\n"); |
default:print_spaces(len); |
304 |
} else if (ib[1] == 0x71) { |
debug("UNIMPLEMENTED\n"); |
|
print_spaces(len); |
|
|
debug("nop\n"); |
|
|
} else if (ib[1] == 0x72) { |
|
|
print_two(ib, &len); |
|
|
print_spaces(len); |
|
|
debug("stop\t#0x%04x\n", ((ib[2] << 8) + ib[3])); |
|
|
} else if (ib[1] == 0x73) { |
|
|
print_spaces(len); |
|
|
debug("rte\n"); |
|
|
} else if (ib[1] == 0x74) { |
|
|
print_two(ib, &len); |
|
|
print_spaces(len); |
|
|
debug("rtd\t#0x%04x\n", ((ib[2] << 8) + ib[3])); |
|
|
} else if (ib[1] == 0x75) { |
|
|
print_spaces(len); |
|
|
debug("rts\n"); |
|
|
} else { |
|
|
print_spaces(len); |
|
|
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
|
305 |
} |
} |
306 |
} else { |
break; |
307 |
print_spaces(len); |
|
308 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
default:print_spaces(len); |
309 |
|
debug("UNIMPLEMENTED\n"); |
310 |
} |
} |
311 |
|
|
312 |
return len; |
return len; |