1 |
/* |
/* |
2 |
* Copyright (C) 2005 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_alpha.c,v 1.3 2005/11/13 00:14:07 debug Exp $ |
* $Id: cpu_alpha.c,v 1.25 2007/03/26 02:01:35 debug Exp $ |
29 |
* |
* |
30 |
* Alpha CPU emulation. |
* Alpha CPU emulation. |
31 |
* |
* |
44 |
#include "machine.h" |
#include "machine.h" |
45 |
#include "memory.h" |
#include "memory.h" |
46 |
#include "misc.h" |
#include "misc.h" |
47 |
|
#include "settings.h" |
48 |
#include "symbol.h" |
#include "symbol.h" |
49 |
|
|
50 |
#define DYNTRANS_8K |
#define DYNTRANS_8K |
65 |
int alpha_cpu_new(struct cpu *cpu, struct memory *mem, |
int alpha_cpu_new(struct cpu *cpu, struct memory *mem, |
66 |
struct machine *machine, int cpu_id, char *cpu_type_name) |
struct machine *machine, int cpu_id, char *cpu_type_name) |
67 |
{ |
{ |
68 |
int i; |
int i = 0; |
69 |
|
struct alpha_cpu_type_def cpu_type_defs[] = ALPHA_CPU_TYPE_DEFS; |
70 |
|
|
71 |
if (strcasecmp(cpu_type_name, "Alpha") != 0) |
/* Scan the cpu_type_defs list for this cpu type: */ |
72 |
|
while (cpu_type_defs[i].name != NULL) { |
73 |
|
if (strcasecmp(cpu_type_defs[i].name, cpu_type_name) == 0) { |
74 |
|
break; |
75 |
|
} |
76 |
|
i++; |
77 |
|
} |
78 |
|
if (cpu_type_defs[i].name == NULL) |
79 |
return 0; |
return 0; |
80 |
|
|
81 |
|
cpu->is_32bit = 0; |
82 |
|
cpu->byte_order = EMUL_LITTLE_ENDIAN; |
83 |
|
|
84 |
cpu->memory_rw = alpha_memory_rw; |
cpu->memory_rw = alpha_memory_rw; |
85 |
|
cpu->run_instr = alpha_run_instr; |
86 |
|
cpu->translate_v2p = alpha_translate_v2p; |
87 |
cpu->update_translation_table = alpha_update_translation_table; |
cpu->update_translation_table = alpha_update_translation_table; |
88 |
cpu->invalidate_translation_caches = |
cpu->invalidate_translation_caches = |
89 |
alpha_invalidate_translation_caches; |
alpha_invalidate_translation_caches; |
90 |
cpu->invalidate_code_translation = alpha_invalidate_code_translation; |
cpu->invalidate_code_translation = alpha_invalidate_code_translation; |
91 |
cpu->is_32bit = 0; |
|
92 |
|
cpu->cd.alpha.cpu_type = cpu_type_defs[i]; |
93 |
|
|
94 |
/* Only show name and caches etc for CPU nr 0: */ |
/* Only show name and caches etc for CPU nr 0: */ |
95 |
if (cpu_id == 0) { |
if (cpu_id == 0) { |
96 |
debug("%s", cpu->name); |
debug("%s", cpu->name); |
97 |
} |
} |
98 |
|
|
|
/* 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; |
|
|
|
|
99 |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
100 |
|
|
101 |
|
/* Set up dummy kentry pointers to something which crashes |
102 |
|
the machine: */ |
103 |
|
store_32bit_word(cpu, 0x10010, 0x3fffffc); |
104 |
|
for (i=0; i<N_ALPHA_KENTRY; i++) |
105 |
|
cpu->cd.alpha.kentry[i] = 0x10010; |
106 |
|
|
107 |
|
/* Bogus initial context (will be overwritten on first |
108 |
|
context switch): */ |
109 |
|
cpu->cd.alpha.ctx = 0x10100; |
110 |
|
|
111 |
|
CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc); |
112 |
|
for (i=0; i<N_ALPHA_REGS; i++) |
113 |
|
CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i], |
114 |
|
cpu->cd.alpha.r[i]); |
115 |
|
|
116 |
return 1; |
return 1; |
117 |
} |
} |
118 |
|
|
134 |
*/ |
*/ |
135 |
void alpha_cpu_list_available_types(void) |
void alpha_cpu_list_available_types(void) |
136 |
{ |
{ |
137 |
/* TODO */ |
int i, j; |
138 |
|
struct alpha_cpu_type_def tdefs[] = ALPHA_CPU_TYPE_DEFS; |
|
debug("Alpha\n"); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* alpha_cpu_register_match(): |
|
|
*/ |
|
|
void alpha_cpu_register_match(struct machine *m, char *name, |
|
|
int writeflag, uint64_t *valuep, int *match_register) |
|
|
{ |
|
|
int i, cpunr = 0; |
|
139 |
|
|
140 |
/* CPU number: */ |
i = 0; |
141 |
|
while (tdefs[i].name != NULL) { |
142 |
/* TODO */ |
debug("%s", tdefs[i].name); |
143 |
|
for (j=13 - strlen(tdefs[i].name); j>0; j--) |
144 |
if (strcasecmp(name, "pc") == 0) { |
debug(" "); |
145 |
if (writeflag) { |
i++; |
146 |
m->cpus[cpunr]->pc = *valuep; |
if ((i % 4) == 0 || tdefs[i].name == NULL) |
147 |
} else |
debug("\n"); |
|
*valuep = m->cpus[cpunr]->pc; |
|
|
*match_register = 1; |
|
|
} |
|
|
|
|
|
/* Register names: */ |
|
|
for (i=0; i<N_ALPHA_REGS; i++) { |
|
|
if (strcasecmp(name, alpha_regname[i]) == 0) { |
|
|
if (writeflag) |
|
|
m->cpus[cpunr]->cd.alpha.r[i] = *valuep; |
|
|
else |
|
|
*valuep = m->cpus[cpunr]->cd.alpha.r[i]; |
|
|
*match_register = 1; |
|
|
} |
|
148 |
} |
} |
149 |
} |
} |
150 |
|
|
166 |
if (gprs) { |
if (gprs) { |
167 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
168 |
cpu->pc, &offset); |
cpu->pc, &offset); |
169 |
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); |
170 |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
debug(" <%s>\n", symbol != NULL? symbol : " no symbol "); |
171 |
for (i=0; i<N_ALPHA_REGS; i++) { |
for (i=0; i<N_ALPHA_REGS; i++) { |
172 |
int r = (i >> 1) + ((i & 1) << 4); |
int r = (i >> 1) + ((i & 1) << 4); |
173 |
if ((i % 2) == 0) |
if ((i % 2) == 0) |
174 |
debug("cpu%i:\t", x); |
debug("cpu%i:\t", x); |
175 |
if (r != ALPHA_ZERO) |
if (r != ALPHA_ZERO) |
176 |
debug("%3s = 0x%016llx", alpha_regname[r], |
debug("%3s = 0x%016"PRIx64, alpha_regname[r], |
177 |
(long long)cpu->cd.alpha.r[r]); |
(uint64_t) cpu->cd.alpha.r[r]); |
178 |
debug((i % 2) == 1? "\n" : " "); |
debug((i % 2) == 1? "\n" : " "); |
179 |
} |
} |
180 |
} |
} |
182 |
|
|
183 |
|
|
184 |
/* |
/* |
185 |
* alpha_cpu_interrupt(): |
* alpha_cpu_tlbdump(): |
186 |
*/ |
* |
187 |
int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
* Called from the debugger to dump the TLB in a readable format. |
188 |
{ |
* x is the cpu number to dump, or -1 to dump all CPUs. |
189 |
fatal("alpha_cpu_interrupt(): TODO\n"); |
* |
190 |
return 0; |
* If rawflag is nonzero, then the TLB contents isn't formated nicely, |
191 |
} |
* just dumped. |
|
|
|
|
|
|
|
/* |
|
|
* alpha_cpu_interrupt_ack(): |
|
192 |
*/ |
*/ |
193 |
int alpha_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
void alpha_cpu_tlbdump(struct machine *m, int x, int rawflag) |
194 |
{ |
{ |
|
/* fatal("alpha_cpu_interrupt_ack(): TODO\n"); */ |
|
|
return 0; |
|
195 |
} |
} |
196 |
|
|
197 |
|
|
230 |
* cpu->pc for relative addresses. |
* cpu->pc for relative addresses. |
231 |
*/ |
*/ |
232 |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
int alpha_cpu_disassemble_instr(struct cpu *cpu, unsigned char *ib, |
233 |
int running, uint64_t dumpaddr, int bintrans) |
int running, uint64_t dumpaddr) |
234 |
{ |
{ |
235 |
uint32_t iw; |
uint32_t iw; |
236 |
uint64_t offset, tmp; |
uint64_t offset, tmp; |
249 |
if (cpu->machine->ncpus > 1 && running) |
if (cpu->machine->ncpus > 1 && running) |
250 |
debug("cpu%i:\t", cpu->cpu_id); |
debug("cpu%i:\t", cpu->cpu_id); |
251 |
|
|
252 |
debug("%016llx: ", (long long)dumpaddr); |
debug("%016"PRIx64": ", (uint64_t) dumpaddr); |
253 |
|
|
254 |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
iw = ib[0] + (ib[1]<<8) + (ib[2]<<16) + (ib[3]<<24); |
255 |
debug("%08x\t", (int)iw); |
debug("%08x\t", (int)iw); |
386 |
case 0x061: mnem = "amask"; break; |
case 0x061: mnem = "amask"; break; |
387 |
case 0x064: mnem = "cmovle"; break; |
case 0x064: mnem = "cmovle"; break; |
388 |
case 0x066: mnem = "cmovgt"; break; |
case 0x066: mnem = "cmovgt"; break; |
389 |
|
case 0x06c: mnem = "implver"; break; |
390 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
391 |
opcode, func); |
opcode, func); |
392 |
} |
} |
405 |
else |
else |
406 |
debug("mov\t%s,%s\n", alpha_regname[ra], |
debug("mov\t%s,%s\n", alpha_regname[ra], |
407 |
alpha_regname[rc]); |
alpha_regname[rc]); |
408 |
|
} else if (func == 0x1ec) { |
409 |
|
/* implver */ |
410 |
|
debug("%s\t%s\n", mnem, alpha_regname[rc]); |
411 |
} else if (func & 0x80) |
} else if (func & 0x80) |
412 |
debug("%s\t%s,0x%x,%s\n", mnem, |
debug("%s\t%s,0x%x,%s\n", mnem, |
413 |
alpha_regname[ra], (rb << 3) + (func >> 8), |
alpha_regname[ra], (rb << 3) + (func >> 8), |
479 |
break; |
break; |
480 |
case 0x16: |
case 0x16: |
481 |
switch (func & 0x7ff) { |
switch (func & 0x7ff) { |
482 |
|
case 0x02f: mnem = "cvttq/c"; rbrc = 1; break; |
483 |
case 0x080: mnem = "adds"; break; |
case 0x080: mnem = "adds"; break; |
484 |
case 0x081: mnem = "subs"; break; |
case 0x081: mnem = "subs"; break; |
485 |
case 0x082: mnem = "muls"; break; |
case 0x082: mnem = "muls"; break; |
486 |
case 0x083: mnem = "mult"; break; |
case 0x083: mnem = "XXXx083"; break; |
487 |
case 0x0a0: mnem = "addt"; break; |
case 0x0a0: mnem = "addt"; break; |
488 |
case 0x0a1: mnem = "subt"; break; |
case 0x0a1: mnem = "subt"; break; |
489 |
case 0x0a2: mnem = "mult"; break; |
case 0x0a2: mnem = "mult"; break; |
490 |
case 0x0a3: mnem = "divt"; break; |
case 0x0a3: mnem = "divt"; break; |
491 |
|
case 0x0a5: mnem = "cmpteq"; break; |
492 |
|
case 0x0a6: mnem = "cmptlt"; break; |
493 |
|
case 0x0a7: mnem = "cmptle"; break; |
494 |
case 0x0be: mnem = "cvtqt"; rbrc = 1; break; |
case 0x0be: mnem = "cvtqt"; rbrc = 1; break; |
495 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
496 |
opcode, func); |
opcode, func); |
505 |
case 0x17: |
case 0x17: |
506 |
switch (func & 0x7ff) { |
switch (func & 0x7ff) { |
507 |
case 0x020: mnem = "fabs"; rbrc = 1; break; |
case 0x020: mnem = "fabs"; rbrc = 1; break; |
508 |
|
case 0x021: mnem = "fneg"; rbrc = 1; break; |
509 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
510 |
opcode, func); |
opcode, func); |
511 |
} |
} |
560 |
debug("jsr"); |
debug("jsr"); |
561 |
debug("\t%s,", alpha_regname[ra]); |
debug("\t%s,", alpha_regname[ra]); |
562 |
debug("(%s),", alpha_regname[rb]); |
debug("(%s),", alpha_regname[rb]); |
563 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
564 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
565 |
tmp, &offset); |
tmp, &offset); |
566 |
if (symbol != NULL) |
if (symbol != NULL) |
582 |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
debug("%s\t", opcode==0x30? "br" : "bsr"); |
583 |
if (ra != ALPHA_ZERO) |
if (ra != ALPHA_ZERO) |
584 |
debug("%s,", alpha_regname[ra]); |
debug("%s,", alpha_regname[ra]); |
585 |
debug("0x%llx", (long long)tmp); |
debug("0x%"PRIx64, (uint64_t) tmp); |
586 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
587 |
tmp, &offset); |
tmp, &offset); |
588 |
if (symbol != NULL) |
if (symbol != NULL) |
589 |
debug("\t<%s>", symbol); |
debug("\t<%s>", symbol); |
590 |
debug("\n"); |
debug("\n"); |
591 |
break; |
break; |
592 |
|
case 0x31: |
593 |
|
case 0x35: |
594 |
case 0x38: |
case 0x38: |
595 |
case 0x39: |
case 0x39: |
596 |
case 0x3a: |
case 0x3a: |
599 |
case 0x3d: |
case 0x3d: |
600 |
case 0x3e: |
case 0x3e: |
601 |
case 0x3f: |
case 0x3f: |
602 |
|
floating = 0; |
603 |
switch (opcode) { |
switch (opcode) { |
604 |
|
case 0x31: mnem = "fbeq"; floating = 1; break; |
605 |
|
case 0x35: mnem = "fbne"; floating = 1; break; |
606 |
case 0x38: mnem = "blbc"; break; |
case 0x38: mnem = "blbc"; break; |
607 |
case 0x39: mnem = "beq"; break; |
case 0x39: mnem = "beq"; break; |
608 |
case 0x3a: mnem = "blt"; break; |
case 0x3a: mnem = "blt"; break; |
617 |
tmp |= 0xffffffffffe00000ULL; |
tmp |= 0xffffffffffe00000ULL; |
618 |
tmp <<= 2; |
tmp <<= 2; |
619 |
tmp += dumpaddr + sizeof(uint32_t); |
tmp += dumpaddr + sizeof(uint32_t); |
620 |
debug("%s\t%s,", mnem, alpha_regname[ra]); |
debug("%s\t", mnem); |
621 |
debug("0x%llx", (long long)tmp); |
if (floating) |
622 |
|
debug("f%i,", ra); |
623 |
|
else |
624 |
|
debug("%s,", alpha_regname[ra]); |
625 |
|
debug("0x%"PRIx64, (uint64_t) tmp); |
626 |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
symbol = get_symbol_name(&cpu->machine->symbol_context, |
627 |
tmp, &offset); |
tmp, &offset); |
628 |
if (symbol != NULL) |
if (symbol != NULL) |