25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_alpha.c,v 1.5 2006/01/01 16:08:25 debug Exp $ |
* $Id: cpu_alpha.c,v 1.16 2006/06/16 18:31:25 debug Exp $ |
29 |
* |
* |
30 |
* Alpha CPU emulation. |
* Alpha CPU emulation. |
31 |
* |
* |
64 |
int alpha_cpu_new(struct cpu *cpu, struct memory *mem, |
int alpha_cpu_new(struct cpu *cpu, struct memory *mem, |
65 |
struct machine *machine, int cpu_id, char *cpu_type_name) |
struct machine *machine, int cpu_id, char *cpu_type_name) |
66 |
{ |
{ |
67 |
int i; |
int i = 0; |
68 |
|
struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS; |
69 |
|
|
70 |
if (strcasecmp(cpu_type_name, "Alpha") != 0) |
/* Scan the cpu_type_defs list for this cpu type: */ |
71 |
|
while (cpu_type_defs[i].name != NULL) { |
72 |
|
if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) { |
73 |
|
break; |
74 |
|
} |
75 |
|
i++; |
76 |
|
} |
77 |
|
if (cpu_type_defs[i].name == NULL) |
78 |
return 0; |
return 0; |
79 |
|
|
80 |
cpu->memory_rw = alpha_memory_rw; |
cpu->memory_rw = alpha_memory_rw; |
81 |
|
cpu->translate_address = alpha_translate_address; |
82 |
cpu->update_translation_table = alpha_update_translation_table; |
cpu->update_translation_table = alpha_update_translation_table; |
83 |
cpu->invalidate_translation_caches = |
cpu->invalidate_translation_caches = |
84 |
alpha_invalidate_translation_caches; |
alpha_invalidate_translation_caches; |
90 |
debug("%s", cpu->name); |
debug("%s", cpu->name); |
91 |
} |
} |
92 |
|
|
|
/* Create the default virtual->physical->host translation: */ |
|
|
cpu->cd.alpha.vph_default_page = malloc(sizeof(struct alpha_vph_page)); |
|
|
if (cpu->cd.alpha.vph_default_page == NULL) { |
|
|
fprintf(stderr, "out of memory in alpha_cpu_new()\n"); |
|
|
exit(1); |
|
|
} |
|
|
memset(cpu->cd.alpha.vph_default_page, 0, |
|
|
sizeof(struct alpha_vph_page)); |
|
|
for (i=0; i<ALPHA_LEVEL0; i++) |
|
|
cpu->cd.alpha.vph_table0[i] = cpu->cd.alpha.vph_table0_kernel[i] |
|
|
= cpu->cd.alpha.vph_default_page; |
|
|
|
|
93 |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
94 |
|
|
95 |
|
alpha_init_64bit_dummy_tables(cpu); |
96 |
|
|
97 |
return 1; |
return 1; |
98 |
} |
} |
99 |
|
|
115 |
*/ |
*/ |
116 |
void alpha_cpu_list_available_types(void) |
void alpha_cpu_list_available_types(void) |
117 |
{ |
{ |
118 |
/* TODO */ |
int i, j; |
119 |
|
struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS; |
120 |
|
|
121 |
debug("Alpha\n"); |
i = 0; |
122 |
|
while (tdefs[i].name != NULL) { |
123 |
|
debug("%s", tdefs[i].name); |
124 |
|
for (j=16 - strlen(tdefs[i].name); j>0; j--) |
125 |
|
debug(" "); |
126 |
|
i++; |
127 |
|
if ((i % 4) == 0 || tdefs[i].name == NULL) |
128 |
|
debug("\n"); |
129 |
|
} |
130 |
} |
} |
131 |
|
|
132 |
|
|
180 |
if (gprs) { |
if (gprs) { |
181 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
182 |
cpu->pc, &offset); |
cpu->pc, &offset); |
183 |
debug("cpu%i:\t pc = 0x%016llx", x, (long long)cpu->pc); |
debug("cpu%i:\t pc = 0x%016"PRIx64, x, (uint64_t) cpu->pc); |
184 |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
185 |
for (i=0; i<N_ALPHA_REGS; i++) { |
for (i=0; i<N_ALPHA_REGS; i++) { |
186 |
int r = (i >> 1) + ((i & 1) << 4); |
int r = (i >> 1) + ((i & 1) << 4); |
187 |
if ((i % 2) == 0) |
if ((i % 2) == 0) |
188 |
debug("cpu%i:\t", x); |
debug("cpu%i:\t", x); |
189 |
if (r != ALPHA_ZERO) |
if (r != ALPHA_ZERO) |
190 |
debug("%3s = 0x%016llx", alpha_regname[r], |
debug("%3s = 0x%016"PRIx64, alpha_regname[r], |
191 |
(long long)cpu->cd.alpha.r[r]); |
(uint64_t) cpu->cd.alpha.r[r]); |
192 |
debug((i % 2) == 1? "\n" : " "); |
debug((i % 2) == 1? "\n" : " "); |
193 |
} |
} |
194 |
} |
} |
196 |
|
|
197 |
|
|
198 |
/* |
/* |
199 |
|
* alpha_cpu_tlbdump(): |
200 |
|
* |
201 |
|
* Called from the debugger to dump the TLB in a readable format. |
202 |
|
* x is the cpu number to dump, or -1 to dump all CPUs. |
203 |
|
* |
204 |
|
* If rawflag is nonzero, then the TLB contents isn't formated nicely, |
205 |
|
* just dumped. |
206 |
|
*/ |
207 |
|
void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) |
208 |
|
{ |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
static void add_response_word(struct cpu *cpu, char *r, uint64_t value, |
213 |
|
size_t maxlen, int len) |
214 |
|
{ |
215 |
|
char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64; |
216 |
|
if (len == 4) |
217 |
|
value &= 0xffffffffULL; |
218 |
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
219 |
|
if (len == 4) { |
220 |
|
value = ((value & 0xff) << 24) + |
221 |
|
((value & 0xff00) << 8) + |
222 |
|
((value & 0xff0000) >> 8) + |
223 |
|
((value & 0xff000000) >> 24); |
224 |
|
} else { |
225 |
|
value = ((value & 0xff) << 56) + |
226 |
|
((value & 0xff00) << 40) + |
227 |
|
((value & 0xff0000) << 24) + |
228 |
|
((value & 0xff000000ULL) << 8) + |
229 |
|
((value & 0xff00000000ULL) >> 8) + |
230 |
|
((value & 0xff0000000000ULL) >> 24) + |
231 |
|
((value & 0xff000000000000ULL) >> 40) + |
232 |
|
((value & 0xff00000000000000ULL) >> 56); |
233 |
|
} |
234 |
|
} |
235 |
|
snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
/* |
240 |
|
* alpha_cpu_gdb_stub(): |
241 |
|
* |
242 |
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
243 |
|
* on success, NULL on failure. |
244 |
|
*/ |
245 |
|
char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd) |
246 |
|
{ |
247 |
|
if (strcmp(cmd, "g") == 0) { |
248 |
|
int i; |
249 |
|
char *r; |
250 |
|
size_t wlen = cpu->is_32bit? |
251 |
|
sizeof(uint32_t) : sizeof(uint64_t); |
252 |
|
size_t len = 1 + 76 * wlen; |
253 |
|
r = malloc(len); |
254 |
|
if (r == NULL) { |
255 |
|
fprintf(stderr, "out of memory\n"); |
256 |
|
exit(1); |
257 |
|
} |
258 |
|
r[0] = '\0'; |
259 |
|
for (i=0; i<128; i++) |
260 |
|
add_response_word(cpu, r, i, len, wlen); |
261 |
|
return r; |
262 |
|
} |
263 |
|
|
264 |
|
if (cmd[0] == 'p') { |
265 |
|
int regnr = strtol(cmd + 1, NULL, 16); |
266 |
|
size_t wlen = cpu->is_32bit? |
267 |
|
sizeof(uint32_t) : sizeof(uint64_t); |
268 |
|
size_t len = 2 * wlen + 1; |
269 |
|
char *r = malloc(len); |
270 |
|
r[0] = '\0'; |
271 |
|
if (regnr >= 0 && regnr <= 31) { |
272 |
|
add_response_word(cpu, r, |
273 |
|
cpu->cd.alpha.r[regnr], len, wlen); |
274 |
|
} else if (regnr >= 32 && regnr <= 62) { |
275 |
|
add_response_word(cpu, r, |
276 |
|
cpu->cd.alpha.f[regnr - 32], len, wlen); |
277 |
|
} else if (regnr == 0x3f) { |
278 |
|
add_response_word(cpu, r, cpu->cd.alpha.fpcr, |
279 |
|
len, wlen); |
280 |
|
} else if (regnr == 0x40) { |
281 |
|
add_response_word(cpu, r, cpu->pc, len, wlen); |
282 |
|
} else { |
283 |
|
/* Unimplemented: */ |
284 |
|
add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); |
285 |
|
} |
286 |
|
return r; |
287 |
|
} |
288 |
|
|
289 |
|
fatal("alpha_cpu_gdb_stub(): TODO\n"); |
290 |
|
return NULL; |
291 |
|
} |
292 |
|
|
293 |
|
|
294 |
|
/* |
295 |
* alpha_cpu_interrupt(): |
* alpha_cpu_interrupt(): |
296 |
*/ |
*/ |
297 |
int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
346 |
* cpu->pc for relative addresses. |
* cpu->pc for relative addresses. |
347 |
*/ |
*/ |
348 |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
349 |
int running, uint64_t dumpaddr, int bintrans) |
int running, uint64_t dumpaddr) |
350 |
{ |
{ |
351 |
uint32_t iw; |
uint32_t iw; |
352 |
uint64_t offset, tmp; |
uint64_t offset, tmp; |
365 |
if (cpu->machine->ncpus > 1 && running) |
if (cpu->machine->ncpus > 1 && running) |
366 |
debug("cpu%i:\t", cpu->cpu_id); |
debug("cpu%i:\t", cpu->cpu_id); |
367 |
|
|
368 |
debug("%016llx: ", (long long)dumpaddr); |
debug("%016"PRIx64": ", (uint64_t) dumpaddr); |
369 |
|
|
370 |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
371 |
debug("%08x\t", (int)iw); |
debug("%08x\t", (int)iw); |
672 |
debug("jsr"); |
debug("jsr"); |
673 |
debug("\t%s,", alpha_regname[ra]); |
debug("\t%s,", alpha_regname[ra]); |
674 |
debug("(%s),", alpha_regname[rb]); |
debug("(%s),", alpha_regname[rb]); |
675 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
676 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
677 |
tmp, &offset); |
tmp, &offset); |
678 |
if (symbol != NULL) |
if (symbol != NULL) |
694 |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
695 |
if (ra != ALPHA_ZERO) |
if (ra != ALPHA_ZERO) |
696 |
debug("%s,", alpha_regname[ra]); |
debug("%s,", alpha_regname[ra]); |
697 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
698 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
699 |
tmp, &offset); |
tmp, &offset); |
700 |
if (symbol != NULL) |
if (symbol != NULL) |
734 |
debug("f%i,", ra); |
debug("f%i,", ra); |
735 |
else |
else |
736 |
debug("%s,", alpha_regname[ra]); |
debug("%s,", alpha_regname[ra]); |
737 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
738 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
739 |
tmp, &offset); |
tmp, &offset); |
740 |
if (symbol != NULL) |
if (symbol != NULL) |