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_alpha.c,v 1.16 2006/06/16 18:31:25 debug Exp $ |
* $Id: cpu_alpha.c,v 1.29 2007/06/28 13:36:46 debug Exp $ |
29 |
* |
* |
30 |
* Alpha CPU emulation. |
* Alpha CPU emulation. |
31 |
* |
* |
41 |
#include <ctype.h> |
#include <ctype.h> |
42 |
|
|
43 |
#include "cpu.h" |
#include "cpu.h" |
44 |
|
#include "interrupt.h" |
45 |
#include "machine.h" |
#include "machine.h" |
46 |
#include "memory.h" |
#include "memory.h" |
47 |
#include "misc.h" |
#include "misc.h" |
48 |
|
#include "settings.h" |
49 |
#include "symbol.h" |
#include "symbol.h" |
50 |
|
|
51 |
#define DYNTRANS_8K |
#define DYNTRANS_8K |
56 |
/* Alpha symbolic register names: */ |
/* Alpha symbolic register names: */ |
57 |
static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES; |
static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES; |
58 |
|
|
59 |
|
void alpha_irq_interrupt_assert(struct interrupt *interrupt); |
60 |
|
void alpha_irq_interrupt_deassert(struct interrupt *interrupt); |
61 |
|
|
62 |
|
|
63 |
/* |
/* |
64 |
* alpha_cpu_new(): |
* alpha_cpu_new(): |
82 |
if (cpu_type_defs[i].name == NULL) |
if (cpu_type_defs[i].name == NULL) |
83 |
return 0; |
return 0; |
84 |
|
|
85 |
|
cpu->is_32bit = 0; |
86 |
|
cpu->byte_order = EMUL_LITTLE_ENDIAN; |
87 |
|
|
88 |
cpu->memory_rw = alpha_memory_rw; |
cpu->memory_rw = alpha_memory_rw; |
89 |
cpu->translate_address = alpha_translate_address; |
cpu->run_instr = alpha_run_instr; |
90 |
|
cpu->translate_v2p = alpha_translate_v2p; |
91 |
cpu->update_translation_table = alpha_update_translation_table; |
cpu->update_translation_table = alpha_update_translation_table; |
92 |
cpu->invalidate_translation_caches = |
cpu->invalidate_translation_caches = |
93 |
alpha_invalidate_translation_caches; |
alpha_invalidate_translation_caches; |
94 |
cpu->invalidate_code_translation = alpha_invalidate_code_translation; |
cpu->invalidate_code_translation = alpha_invalidate_code_translation; |
95 |
cpu->is_32bit = 0; |
|
96 |
|
cpu->cd.alpha.cpu_type = cpu_type_defs[i]; |
97 |
|
|
98 |
/* Only show name and caches etc for CPU nr 0: */ |
/* Only show name and caches etc for CPU nr 0: */ |
99 |
if (cpu_id == 0) { |
if (cpu_id == 0) { |
102 |
|
|
103 |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
cpu->cd.alpha.r[ALPHA_SP] = 0xfffffc000000ff00ULL; |
104 |
|
|
105 |
alpha_init_64bit_dummy_tables(cpu); |
/* Set up dummy kentry pointers to something which crashes |
106 |
|
the machine: */ |
107 |
|
store_32bit_word(cpu, 0x10010, 0x3fffffc); |
108 |
|
for (i=0; i<N_ALPHA_KENTRY; i++) |
109 |
|
cpu->cd.alpha.kentry[i] = 0x10010; |
110 |
|
|
111 |
|
/* Bogus initial context (will be overwritten on first |
112 |
|
context switch): */ |
113 |
|
cpu->cd.alpha.ctx = 0x10100; |
114 |
|
|
115 |
|
CPU_SETTINGS_ADD_REGISTER64("pc", cpu->pc); |
116 |
|
for (i=0; i<N_ALPHA_REGS; i++) |
117 |
|
CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i], |
118 |
|
cpu->cd.alpha.r[i]); |
119 |
|
|
120 |
|
/* Register the CPU interrupt pin: */ |
121 |
|
{ |
122 |
|
struct interrupt template; |
123 |
|
|
124 |
|
memset(&template, 0, sizeof(template)); |
125 |
|
template.line = 0; |
126 |
|
template.name = cpu->path; |
127 |
|
template.extra = cpu; |
128 |
|
template.interrupt_assert = alpha_irq_interrupt_assert; |
129 |
|
template.interrupt_deassert = alpha_irq_interrupt_deassert; |
130 |
|
interrupt_handler_register(&template); |
131 |
|
} |
132 |
|
|
133 |
return 1; |
return 1; |
134 |
} |
} |
157 |
i = 0; |
i = 0; |
158 |
while (tdefs[i].name != NULL) { |
while (tdefs[i].name != NULL) { |
159 |
debug("%s", tdefs[i].name); |
debug("%s", tdefs[i].name); |
160 |
for (j=16 - strlen(tdefs[i].name); j>0; j--) |
for (j=13 - strlen(tdefs[i].name); j>0; j--) |
161 |
debug(" "); |
debug(" "); |
162 |
i++; |
i++; |
163 |
if ((i % 4) == 0 || tdefs[i].name == NULL) |
if ((i % 4) == 0 || tdefs[i].name == NULL) |
167 |
|
|
168 |
|
|
169 |
/* |
/* |
|
* 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; |
|
|
|
|
|
/* CPU number: */ |
|
|
|
|
|
/* TODO */ |
|
|
|
|
|
if (strcasecmp(name, "pc") == 0) { |
|
|
if (writeflag) { |
|
|
m->cpus[cpunr]->pc = *valuep; |
|
|
} else |
|
|
*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; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
170 |
* alpha_cpu_register_dump(): |
* alpha_cpu_register_dump(): |
171 |
* |
* |
172 |
* Dump cpu registers in a relatively readable format. |
* Dump cpu registers in a relatively readable format. |
212 |
} |
} |
213 |
|
|
214 |
|
|
|
static void add_response_word(struct cpu *cpu, char *r, uint64_t value, |
|
|
size_t maxlen, int len) |
|
|
{ |
|
|
char *format = (len == 4)? "%08"PRIx64 : "%016"PRIx64; |
|
|
if (len == 4) |
|
|
value &= 0xffffffffULL; |
|
|
if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { |
|
|
if (len == 4) { |
|
|
value = ((value & 0xff) << 24) + |
|
|
((value & 0xff00) << 8) + |
|
|
((value & 0xff0000) >> 8) + |
|
|
((value & 0xff000000) >> 24); |
|
|
} else { |
|
|
value = ((value & 0xff) << 56) + |
|
|
((value & 0xff00) << 40) + |
|
|
((value & 0xff0000) << 24) + |
|
|
((value & 0xff000000ULL) << 8) + |
|
|
((value & 0xff00000000ULL) >> 8) + |
|
|
((value & 0xff0000000000ULL) >> 24) + |
|
|
((value & 0xff000000000000ULL) >> 40) + |
|
|
((value & 0xff00000000000000ULL) >> 56); |
|
|
} |
|
|
} |
|
|
snprintf(r + strlen(r), maxlen - strlen(r), format, (uint64_t)value); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* alpha_cpu_gdb_stub(): |
|
|
* |
|
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
|
|
* on success, NULL on failure. |
|
|
*/ |
|
|
char *alpha_cpu_gdb_stub(struct cpu *cpu, char *cmd) |
|
|
{ |
|
|
if (strcmp(cmd, "g") == 0) { |
|
|
int i; |
|
|
char *r; |
|
|
size_t wlen = cpu->is_32bit? |
|
|
sizeof(uint32_t) : sizeof(uint64_t); |
|
|
size_t len = 1 + 76 * wlen; |
|
|
r = malloc(len); |
|
|
if (r == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
|
r[0] = '\0'; |
|
|
for (i=0; i<128; i++) |
|
|
add_response_word(cpu, r, i, len, wlen); |
|
|
return r; |
|
|
} |
|
|
|
|
|
if (cmd[0] == 'p') { |
|
|
int regnr = strtol(cmd + 1, NULL, 16); |
|
|
size_t wlen = cpu->is_32bit? |
|
|
sizeof(uint32_t) : sizeof(uint64_t); |
|
|
size_t len = 2 * wlen + 1; |
|
|
char *r = malloc(len); |
|
|
r[0] = '\0'; |
|
|
if (regnr >= 0 && regnr <= 31) { |
|
|
add_response_word(cpu, r, |
|
|
cpu->cd.alpha.r[regnr], len, wlen); |
|
|
} else if (regnr >= 32 && regnr <= 62) { |
|
|
add_response_word(cpu, r, |
|
|
cpu->cd.alpha.f[regnr - 32], len, wlen); |
|
|
} else if (regnr == 0x3f) { |
|
|
add_response_word(cpu, r, cpu->cd.alpha.fpcr, |
|
|
len, wlen); |
|
|
} else if (regnr == 0x40) { |
|
|
add_response_word(cpu, r, cpu->pc, len, wlen); |
|
|
} else { |
|
|
/* Unimplemented: */ |
|
|
add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); |
|
|
} |
|
|
return r; |
|
|
} |
|
|
|
|
|
fatal("alpha_cpu_gdb_stub(): TODO\n"); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
215 |
/* |
/* |
216 |
* alpha_cpu_interrupt(): |
* alpha_irq_interrupt_assert(): |
217 |
|
* alpha_irq_interrupt_deassert(): |
218 |
*/ |
*/ |
219 |
int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
void alpha_irq_interrupt_assert(struct interrupt *interrupt) |
220 |
{ |
{ |
221 |
fatal("alpha_cpu_interrupt(): TODO\n"); |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
222 |
return 0; |
cpu->cd.alpha.irq_asserted = 1; |
223 |
} |
} |
224 |
|
void alpha_irq_interrupt_deassert(struct interrupt *interrupt) |
|
|
|
|
/* |
|
|
* alpha_cpu_interrupt_ack(): |
|
|
*/ |
|
|
int alpha_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
|
225 |
{ |
{ |
226 |
/* fatal("alpha_cpu_interrupt_ack(): TODO\n"); */ |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
227 |
return 0; |
cpu->cd.alpha.irq_asserted = 0; |
228 |
} |
} |
229 |
|
|
230 |
|
|
419 |
case 0x061: mnem = "amask"; break; |
case 0x061: mnem = "amask"; break; |
420 |
case 0x064: mnem = "cmovle"; break; |
case 0x064: mnem = "cmovle"; break; |
421 |
case 0x066: mnem = "cmovgt"; break; |
case 0x066: mnem = "cmovgt"; break; |
422 |
|
case 0x06c: mnem = "implver"; break; |
423 |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
default:debug("UNIMPLEMENTED opcode 0x%x func 0x%x\n", |
424 |
opcode, func); |
opcode, func); |
425 |
} |
} |
438 |
else |
else |
439 |
debug("mov\t%s,%s\n", alpha_regname[ra], |
debug("mov\t%s,%s\n", alpha_regname[ra], |
440 |
alpha_regname[rc]); |
alpha_regname[rc]); |
441 |
|
} else if (func == 0x1ec) { |
442 |
|
/* implver */ |
443 |
|
debug("%s\t%s\n", mnem, alpha_regname[rc]); |
444 |
} else if (func & 0x80) |
} else if (func & 0x80) |
445 |
debug("%s\t%s,0x%x,%s\n", mnem, |
debug("%s\t%s,0x%x,%s\n", mnem, |
446 |
alpha_regname[ra], (rb << 3) + (func >> 8), |
alpha_regname[ra], (rb << 3) + (func >> 8), |
672 |
#define MEMORY_RW alpha_userland_memory_rw |
#define MEMORY_RW alpha_userland_memory_rw |
673 |
#define MEM_ALPHA |
#define MEM_ALPHA |
674 |
#define MEM_USERLAND |
#define MEM_USERLAND |
675 |
#include "../memory_rw.c" |
#include "memory_rw.c" |
676 |
#undef MEM_USERLAND |
#undef MEM_USERLAND |
677 |
#undef MEM_ALPHA |
#undef MEM_ALPHA |
678 |
#undef MEMORY_RW |
#undef MEMORY_RW |