1 |
/* |
/* |
2 |
* Copyright (C) 2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2006 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_alpha.c,v 1.2 2005/10/22 17:24:20 debug Exp $ |
* $Id: cpu_alpha.c,v 1.17 2006/06/24 21:47:23 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_v2p = alpha_translate_v2p; |
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 |
return 1; |
return 1; |
113 |
*/ |
*/ |
114 |
void alpha_cpu_list_available_types(void) |
void alpha_cpu_list_available_types(void) |
115 |
{ |
{ |
116 |
/* TODO */ |
int i, j; |
117 |
|
struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS; |
118 |
|
|
119 |
debug("Alpha\n"); |
i = 0; |
120 |
|
while (tdefs[i].name != NULL) { |
121 |
|
debug("%s", tdefs[i].name); |
122 |
|
for (j=16 - strlen(tdefs[i].name); j>0; j--) |
123 |
|
debug(" "); |
124 |
|
i++; |
125 |
|
if ((i % 4) == 0 || tdefs[i].name == NULL) |
126 |
|
debug("\n"); |
127 |
|
} |
128 |
} |
} |
129 |
|
|
130 |
|
|
178 |
if (gprs) { |
if (gprs) { |
179 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
180 |
cpu->pc, &offset); |
cpu->pc, &offset); |
181 |
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); |
182 |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
183 |
for (i=0; i<N_ALPHA_REGS; i++) { |
for (i=0; i<N_ALPHA_REGS; i++) { |
184 |
int r = (i >> 1) + ((i & 1) << 4); |
int r = (i >> 1) + ((i & 1) << 4); |
185 |
if ((i % 2) == 0) |
if ((i % 2) == 0) |
186 |
debug("cpu%i:\t", x); |
debug("cpu%i:\t", x); |
187 |
if (r != ALPHA_ZERO) |
if (r != ALPHA_ZERO) |
188 |
debug("%3s = 0x%016llx", alpha_regname[r], |
debug("%3s = 0x%016"PRIx64, alpha_regname[r], |
189 |
(long long)cpu->cd.alpha.r[r]); |
(uint64_t) cpu->cd.alpha.r[r]); |
190 |
debug((i % 2) == 1? "\n" : " "); |
debug((i % 2) == 1? "\n" : " "); |
191 |
} |
} |
192 |
} |
} |
194 |
|
|
195 |
|
|
196 |
/* |
/* |
|
* alpha_cpu_show_full_statistics(): |
|
|
* |
|
|
* Show detailed statistics on opcode usage on each cpu. |
|
|
*/ |
|
|
void alpha_cpu_show_full_statistics(struct machine *m) |
|
|
{ |
|
|
fatal("alpha_cpu_show_full_statistics(): TODO\n"); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
197 |
* alpha_cpu_tlbdump(): |
* alpha_cpu_tlbdump(): |
198 |
* |
* |
199 |
* Called from the debugger to dump the TLB in a readable format. |
* Called from the debugger to dump the TLB in a readable format. |
204 |
*/ |
*/ |
205 |
void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) |
void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) |
206 |
{ |
{ |
207 |
fatal("alpha_cpu_tlbdump(): TODO\n"); |
} |
208 |
|
|
209 |
|
|
210 |
|
static void add_response_word(struct cpu *cpu, char *r, uint64_t value, |
211 |
|
size_t maxlen, int len) |
212 |
|
{ |
213 |
|
char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64; |
214 |
|
if (len == 4) |
215 |
|
value &= 0xffffffffULL; |
216 |
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
217 |
|
if (len == 4) { |
218 |
|
value = ((value & 0xff) << 24) + |
219 |
|
((value & 0xff00) << 8) + |
220 |
|
((value & 0xff0000) >> 8) + |
221 |
|
((value & 0xff000000) >> 24); |
222 |
|
} else { |
223 |
|
value = ((value & 0xff) << 56) + |
224 |
|
((value & 0xff00) << 40) + |
225 |
|
((value & 0xff0000) << 24) + |
226 |
|
((value & 0xff000000ULL) << 8) + |
227 |
|
((value & 0xff00000000ULL) >> 8) + |
228 |
|
((value & 0xff0000000000ULL) >> 24) + |
229 |
|
((value & 0xff000000000000ULL) >> 40) + |
230 |
|
((value & 0xff00000000000000ULL) >> 56); |
231 |
|
} |
232 |
|
} |
233 |
|
snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
/* |
238 |
|
* alpha_cpu_gdb_stub(): |
239 |
|
* |
240 |
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
241 |
|
* on success, NULL on failure. |
242 |
|
*/ |
243 |
|
char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd) |
244 |
|
{ |
245 |
|
if (strcmp(cmd, "g") == 0) { |
246 |
|
int i; |
247 |
|
char *r; |
248 |
|
size_t wlen = cpu->is_32bit? |
249 |
|
sizeof(uint32_t) : sizeof(uint64_t); |
250 |
|
size_t len = 1 + 76 * wlen; |
251 |
|
r = malloc(len); |
252 |
|
if (r == NULL) { |
253 |
|
fprintf(stderr, "out of memory\n"); |
254 |
|
exit(1); |
255 |
|
} |
256 |
|
r[0] = '\0'; |
257 |
|
for (i=0; i<128; i++) |
258 |
|
add_response_word(cpu, r, i, len, wlen); |
259 |
|
return r; |
260 |
|
} |
261 |
|
|
262 |
|
if (cmd[0] == 'p') { |
263 |
|
int regnr = strtol(cmd + 1, NULL, 16); |
264 |
|
size_t wlen = cpu->is_32bit? |
265 |
|
sizeof(uint32_t) : sizeof(uint64_t); |
266 |
|
size_t len = 2 * wlen + 1; |
267 |
|
char *r = malloc(len); |
268 |
|
r[0] = '\0'; |
269 |
|
if (regnr >= 0 && regnr <= 31) { |
270 |
|
add_response_word(cpu, r, |
271 |
|
cpu->cd.alpha.r[regnr], len, wlen); |
272 |
|
} else if (regnr >= 32 && regnr <= 62) { |
273 |
|
add_response_word(cpu, r, |
274 |
|
cpu->cd.alpha.f[regnr - 32], len, wlen); |
275 |
|
} else if (regnr == 0x3f) { |
276 |
|
add_response_word(cpu, r, cpu->cd.alpha.fpcr, |
277 |
|
len, wlen); |
278 |
|
} else if (regnr == 0x40) { |
279 |
|
add_response_word(cpu, r, cpu->pc, len, wlen); |
280 |
|
} else { |
281 |
|
/* Unimplemented: */ |
282 |
|
add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); |
283 |
|
} |
284 |
|
return r; |
285 |
|
} |
286 |
|
|
287 |
|
fatal("alpha_cpu_gdb_stub(): TODO\n"); |
288 |
|
return NULL; |
289 |
} |
} |
290 |
|
|
291 |
|
|
344 |
* cpu->pc for relative addresses. |
* cpu->pc for relative addresses. |
345 |
*/ |
*/ |
346 |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
347 |
int running, uint64_t dumpaddr, int bintrans) |
int running, uint64_t dumpaddr) |
348 |
{ |
{ |
349 |
uint32_t iw; |
uint32_t iw; |
350 |
uint64_t offset, tmp; |
uint64_t offset, tmp; |
363 |
if (cpu->machine->ncpus > 1 && running) |
if (cpu->machine->ncpus > 1 && running) |
364 |
debug("cpu%i:\t", cpu->cpu_id); |
debug("cpu%i:\t", cpu->cpu_id); |
365 |
|
|
366 |
debug("%016llx: ", (long long)dumpaddr); |
debug("%016"PRIx64": ", (uint64_t) dumpaddr); |
367 |
|
|
368 |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
369 |
debug("%08x\t", (int)iw); |
debug("%08x\t", (int)iw); |
589 |
break; |
break; |
590 |
case 0x16: |
case 0x16: |
591 |
switch (func & 0x7ff) { |
switch (func & 0x7ff) { |
592 |
|
case 0x02f: mnem = "cvttq/c"; rbrc = 1; break; |
593 |
case 0x080: mnem = "adds"; break; |
case 0x080: mnem = "adds"; break; |
594 |
case 0x081: mnem = "subs"; break; |
case 0x081: mnem = "subs"; break; |
595 |
case 0x082: mnem = "muls"; break; |
case 0x082: mnem = "muls"; break; |
596 |
case 0x083: mnem = "mult"; break; |
case 0x083: mnem = "XXXx083"; break; |
597 |
case 0x0a0: mnem = "addt"; break; |
case 0x0a0: mnem = "addt"; break; |
598 |
case 0x0a1: mnem = "subt"; break; |
case 0x0a1: mnem = "subt"; break; |
599 |
case 0x0a2: mnem = "mult"; break; |
case 0x0a2: mnem = "mult"; break; |
600 |
case 0x0a3: mnem = "divt"; break; |
case 0x0a3: mnem = "divt"; break; |
601 |
|
case 0x0a5: mnem = "cmpteq"; break; |
602 |
|
case 0x0a6: mnem = "cmptlt"; break; |
603 |
|
case 0x0a7: mnem = "cmptle"; break; |
604 |
case 0x0be: mnem = "cvtqt"; rbrc = 1; break; |
case 0x0be: mnem = "cvtqt"; rbrc = 1; break; |
605 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
606 |
opcode, func); |
opcode, func); |
615 |
case 0x17: |
case 0x17: |
616 |
switch (func & 0x7ff) { |
switch (func & 0x7ff) { |
617 |
case 0x020: mnem = "fabs"; rbrc = 1; break; |
case 0x020: mnem = "fabs"; rbrc = 1; break; |
618 |
|
case 0x021: mnem = "fneg"; rbrc = 1; break; |
619 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
620 |
opcode, func); |
opcode, func); |
621 |
} |
} |
670 |
debug("jsr"); |
debug("jsr"); |
671 |
debug("\t%s,", alpha_regname[ra]); |
debug("\t%s,", alpha_regname[ra]); |
672 |
debug("(%s),", alpha_regname[rb]); |
debug("(%s),", alpha_regname[rb]); |
673 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
674 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
675 |
tmp, &offset); |
tmp, &offset); |
676 |
if (symbol != NULL) |
if (symbol != NULL) |
692 |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
693 |
if (ra != ALPHA_ZERO) |
if (ra != ALPHA_ZERO) |
694 |
debug("%s,", alpha_regname[ra]); |
debug("%s,", alpha_regname[ra]); |
695 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
696 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
697 |
tmp, &offset); |
tmp, &offset); |
698 |
if (symbol != NULL) |
if (symbol != NULL) |
699 |
debug("\t<%s>", symbol); |
debug("\t<%s>", symbol); |
700 |
debug("\n"); |
debug("\n"); |
701 |
break; |
break; |
702 |
|
case 0x31: |
703 |
|
case 0x35: |
704 |
case 0x38: |
case 0x38: |
705 |
case 0x39: |
case 0x39: |
706 |
case 0x3a: |
case 0x3a: |
709 |
case 0x3d: |
case 0x3d: |
710 |
case 0x3e: |
case 0x3e: |
711 |
case 0x3f: |
case 0x3f: |
712 |
|
floating = 0; |
713 |
switch (opcode) { |
switch (opcode) { |
714 |
|
case 0x31: mnem = "fbeq"; floating = 1; break; |
715 |
|
case 0x35: mnem = "fbne"; floating = 1; break; |
716 |
case 0x38: mnem = "blbc"; break; |
case 0x38: mnem = "blbc"; break; |
717 |
case 0x39: mnem = "beq"; break; |
case 0x39: mnem = "beq"; break; |
718 |
case 0x3a: mnem = "blt"; break; |
case 0x3a: mnem = "blt"; break; |
727 |
tmp |= 0xffffffffffe00000ULL; |
tmp |= 0xffffffffffe00000ULL; |
728 |
tmp <<= 2; |
tmp <<= 2; |
729 |
tmp += dumpaddr + sizeof(uint32_t); |
tmp += dumpaddr + sizeof(uint32_t); |
730 |
debug("%s\t%s,", mnem, alpha_regname[ra]); |
debug("%s\t", mnem); |
731 |
debug("0x%llx", (long long)tmp); |
if (floating) |
732 |
|
debug("f%i,", ra); |
733 |
|
else |
734 |
|
debug("%s,", alpha_regname[ra]); |
735 |
|
debug("0x%"PRIx64, (uint64_t) tmp); |
736 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
737 |
tmp, &offset); |
tmp, &offset); |
738 |
if (symbol != NULL) |
if (symbol != NULL) |