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.23 2006/09/19 10:50:08 debug Exp $ |
* $Id: cpu_alpha.c,v 1.27 2007/06/07 15:36:24 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" |
#include "settings.h" |
49 |
#include "symbol.h" |
#include "symbol.h" |
50 |
|
#include "timer.h" |
51 |
|
|
52 |
#define DYNTRANS_8K |
#define DYNTRANS_8K |
53 |
#define DYNTRANS_PAGESIZE 8192 |
#define DYNTRANS_PAGESIZE 8192 |
54 |
#include "tmp_alpha_head.c" |
#include "tmp_alpha_head.c" |
55 |
|
|
56 |
|
|
57 |
|
extern int native_code_translation_enabled; |
58 |
|
|
59 |
/* Alpha symbolic register names: */ |
/* Alpha symbolic register names: */ |
60 |
static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES; |
static char *alpha_regname[N_ALPHA_REGS] = ALPHA_REG_NAMES; |
61 |
|
|
62 |
|
void alpha_irq_interrupt_assert(struct interrupt *interrupt); |
63 |
|
void alpha_irq_interrupt_deassert(struct interrupt *interrupt); |
64 |
|
|
65 |
|
|
66 |
/* |
/* |
67 |
* alpha_cpu_new(): |
* alpha_cpu_new(): |
120 |
CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i], |
CPU_SETTINGS_ADD_REGISTER64(alpha_regname[i], |
121 |
cpu->cd.alpha.r[i]); |
cpu->cd.alpha.r[i]); |
122 |
|
|
123 |
|
/* Register the CPU interrupt pin: */ |
124 |
|
{ |
125 |
|
struct interrupt template; |
126 |
|
|
127 |
|
memset(&template, 0, sizeof(template)); |
128 |
|
template.line = 0; |
129 |
|
template.name = cpu->path; |
130 |
|
template.extra = cpu; |
131 |
|
template.interrupt_assert = alpha_irq_interrupt_assert; |
132 |
|
template.interrupt_deassert = alpha_irq_interrupt_deassert; |
133 |
|
interrupt_handler_register(&template); |
134 |
|
} |
135 |
|
|
136 |
|
if (native_code_translation_enabled) |
137 |
|
cpu->sampling_timer = timer_add(CPU_SAMPLE_TIMER_HZ, |
138 |
|
alpha_timer_sample_tick, cpu); |
139 |
|
|
140 |
return 1; |
return 1; |
141 |
} |
} |
142 |
|
|
219 |
} |
} |
220 |
|
|
221 |
|
|
|
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; |
|
|
} |
|
|
|
|
|
|
|
222 |
/* |
/* |
223 |
* alpha_cpu_interrupt(): |
* alpha_irq_interrupt_assert(): |
224 |
|
* alpha_irq_interrupt_deassert(): |
225 |
*/ |
*/ |
226 |
int alpha_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
void alpha_irq_interrupt_assert(struct interrupt *interrupt) |
227 |
{ |
{ |
228 |
fatal("alpha_cpu_interrupt(): TODO\n"); |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
229 |
return 0; |
cpu->cd.alpha.irq_asserted = 1; |
230 |
} |
} |
231 |
|
void alpha_irq_interrupt_deassert(struct interrupt *interrupt) |
|
|
|
|
/* |
|
|
* alpha_cpu_interrupt_ack(): |
|
|
*/ |
|
|
int alpha_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
|
232 |
{ |
{ |
233 |
/* fatal("alpha_cpu_interrupt_ack(): TODO\n"); */ |
struct cpu *cpu = (struct cpu *) interrupt->extra; |
234 |
return 0; |
cpu->cd.alpha.irq_asserted = 0; |
235 |
} |
} |
236 |
|
|
237 |
|
|