1 |
/* |
/* |
2 |
* Copyright (C) 2005-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_m68k.c,v 1.10 2006/06/16 18:31:25 debug Exp $ |
* $Id: cpu_m68k.c,v 1.18 2007/03/26 02:16:09 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; |
80 |
cpu->memory_rw = m68k_memory_rw; |
cpu->memory_rw = m68k_memory_rw; |
81 |
cpu->update_translation_table = m68k_update_translation_table; |
cpu->update_translation_table = m68k_update_translation_table; |
82 |
cpu->invalidate_translation_caches = |
cpu->invalidate_translation_caches = |
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%08x", x, (int)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 "); |
|
} |
|
|
} |
|
|
|
|
160 |
|
|
161 |
/* |
for (i=0; i<N_M68K_AREGS; i++) { |
162 |
* m68k_cpu_register_match(): |
if ((i % 4) == 0) |
163 |
*/ |
debug("cpu%i:", x); |
164 |
void m68k_cpu_register_match(struct machine *m, char *name, |
debug(" %s = 0x%08"PRIx32" ", |
165 |
int writeflag, uint64_t *valuep, int *match_register) |
m68k_aname[i], cpu->cd.m68k.a[i]); |
166 |
{ |
if ((i % 4) == 3) |
167 |
int cpunr = 0; |
debug("\n"); |
168 |
|
} |
|
/* CPU number: */ |
|
|
|
|
|
/* TODO */ |
|
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 |
|
|
193 |
} |
} |
194 |
|
|
195 |
|
|
|
/* |
|
|
* m68k_cpu_gdb_stub(): |
|
|
* |
|
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
|
|
* on success, NULL on failure. |
|
|
*/ |
|
|
char *m68k_cpu_gdb_stub(struct cpu *cpu, char *cmd) |
|
|
{ |
|
|
fatal("m68k_cpu_gdb_stub(): TODO\n"); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* m68k_cpu_interrupt(): |
|
|
*/ |
|
|
int m68k_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
|
|
{ |
|
|
fatal("m68k_cpu_interrupt(): TODO\n"); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* m68k_cpu_interrupt_ack(): |
|
|
*/ |
|
|
int m68k_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
|
|
{ |
|
|
/* fatal("m68k_cpu_interrupt_ack(): TODO\n"); */ |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
196 |
/* Helper functions: */ |
/* Helper functions: */ |
197 |
static void print_two(unsigned char *instr, int *len) |
static void print_two(unsigned char *instr, int *len) |
198 |
{ debug(" %02x%02x", instr[*len], instr[*len+1]); (*len) += 2; } |
{ debug(" %02x%02x", instr[*len], instr[*len+1]); (*len) += 2; } |
234 |
|
|
235 |
print_two(ib, &len); |
print_two(ib, &len); |
236 |
|
|
237 |
if (ib[0] == 0x48) { |
switch (ib[0] >> 4) { |
238 |
if (ib[1] >= 0x40 && ib[1] <= 0x47) { |
|
239 |
print_spaces(len); |
case 0x4: |
240 |
debug("swap\td%i\n", ib[1] & 7); |
switch (ib[0] & 0xf) { |
241 |
} else if (ib[1] >= 0x48 && ib[1] <= 0x4f) { |
|
242 |
print_spaces(len); |
case 0xe: |
243 |
debug("bkpt\t#%i\n", ib[1] & 7); |
if (ib[1] >= 0x50 && ib[1] <= 0x57) { |
244 |
} else { |
print_two(ib, &len); |
245 |
print_spaces(len); |
print_spaces(len); |
246 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
debug("linkw\t%%%s,#%i\n", |
247 |
} |
m68k_aname[ib[1] & 7], |
248 |
} else if (ib[0] == 0x4a) { |
((ib[2] << 8) + ib[3])); |
249 |
if (ib[1] == 0xfc) { |
} else if (ib[1] >= 0x58 && ib[1] <= 0x5f) { |
250 |
print_spaces(len); |
print_spaces(len); |
251 |
debug("illegal\n"); |
debug("unlk\t%%%s\n", m68k_aname[ib[1] & 7]); |
252 |
} else { |
} else if (ib[1] == 0x71) { |
253 |
print_spaces(len); |
print_spaces(len); |
254 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
debug("nop\n"); |
255 |
} |
} else if (ib[1] == 0x73) { |
256 |
} else if (ib[0] == 0x4e) { |
print_spaces(len); |
257 |
if (ib[1] >= 0x40 && ib[1] <= 0x4f) { |
debug("rte\n"); |
258 |
print_spaces(len); |
} else if (ib[1] == 0x74) { |
259 |
debug("trap\t#%i\n", ib[1] & 15); |
print_two(ib, &len); |
260 |
} else if (ib[1] >= 0x50 && ib[1] <= 0x57) { |
print_spaces(len); |
261 |
print_two(ib, &len); |
debug("rtd\t#0x%04x\n", ((ib[2] << 8) + ib[3])); |
262 |
print_spaces(len); |
} else if (ib[1] == 0x75) { |
263 |
debug("linkw\t%%%s,#%i\n", m68k_aname[ib[1] & 7], |
print_spaces(len); |
264 |
((ib[2] << 8) + ib[3])); |
debug("rts\n"); |
265 |
} else if (ib[1] >= 0x58 && ib[1] <= 0x5f) { |
} else { |
266 |
print_spaces(len); |
print_spaces(len); |
267 |
debug("unlk\t%%%s\n", m68k_aname[ib[1] & 7]); |
debug("UNIMPLEMENTED\n"); |
268 |
} else if (ib[1] == 0x70) { |
} |
269 |
print_spaces(len); |
break; |
270 |
debug("reset\n"); |
|
271 |
} else if (ib[1] == 0x71) { |
default:print_spaces(len); |
272 |
print_spaces(len); |
debug("UNIMPLEMENTED\n"); |
|
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]); |
|
273 |
} |
} |
274 |
} else { |
break; |
275 |
print_spaces(len); |
|
276 |
debug("UNIMPLEMENTED 0x%02x%02x\n", ib[0], ib[1]); |
default:print_spaces(len); |
277 |
|
debug("UNIMPLEMENTED\n"); |
278 |
} |
} |
279 |
|
|
280 |
return len; |
return len; |