25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_sparc.c,v 1.39 2006/12/30 13:30:55 debug Exp $ |
* $Id: cpu_sparc.c,v 1.44 2007/03/26 02:18:44 debug Exp $ |
29 |
* |
* |
30 |
* SPARC CPU emulation. |
* SPARC CPU emulation. |
31 |
*/ |
*/ |
139 |
cpu->cd.sparc.tick |= SPARC_TICK_NPT; |
cpu->cd.sparc.tick |= SPARC_TICK_NPT; |
140 |
|
|
141 |
/* Insert number of Windows and Trap levels into the version reg.: */ |
/* Insert number of Windows and Trap levels into the version reg.: */ |
142 |
cpu->cd.sparc.ver |= MAXWIN | (MAXTL << SPARC_VER_MAXTL_SHIFT); |
cpu->cd.sparc.ver |= N_REG_WINDOWS | (MAXTL << SPARC_VER_MAXTL_SHIFT); |
143 |
|
|
144 |
/* Misc. initial settings suitable for userland emulation: */ |
/* Misc. initial settings suitable for userland emulation: */ |
145 |
cpu->cd.sparc.cansave = cpu->cd.sparc.cpu_type.nwindows - 1; |
cpu->cd.sparc.cansave = cpu->cd.sparc.cpu_type.nwindows - 2; |
146 |
cpu->cd.sparc.cleanwin = cpu->cd.sparc.cpu_type.nwindows / 2; |
cpu->cd.sparc.canrestore = 0; |
147 |
|
cpu->cd.sparc.cleanwin = 1; |
148 |
|
cpu->cd.sparc.otherwin = 0; |
149 |
|
|
150 |
|
if (cpu->cd.sparc.cansave + cpu->cd.sparc.canrestore |
151 |
|
+ cpu->cd.sparc.otherwin != cpu->cd.sparc.cpu_type.nwindows - 2) { |
152 |
|
fatal("Fatal internal error: inconsistent windowing " |
153 |
|
"parameters!\n"); |
154 |
|
exit(1); |
155 |
|
} |
156 |
|
|
157 |
if (cpu->cd.sparc.cpu_type.nwindows >= MAXWIN) { |
if (cpu->cd.sparc.cpu_type.nwindows > N_REG_WINDOWS) { |
158 |
fatal("Fatal internal error: nwindows = %1 is more than %i\n", |
fatal("Fatal internal error: nwindows = %1 is more than %i\n", |
159 |
cpu->cd.sparc.cpu_type.nwindows, MAXWIN); |
cpu->cd.sparc.cpu_type.nwindows, N_REG_WINDOWS); |
160 |
exit(1); |
exit(1); |
161 |
} |
} |
162 |
|
|
296 |
} |
} |
297 |
} |
} |
298 |
} |
} |
299 |
|
|
300 |
|
if (coprocs & 1) { |
301 |
|
int sum; |
302 |
|
|
303 |
|
debug("cpu%i: cwp = 0x%02x\n", x, cpu->cd.sparc.cwp); |
304 |
|
debug("cpu%i: cansave = 0x%02x\n", x, cpu->cd.sparc.cansave); |
305 |
|
debug("cpu%i: canrestore = 0x%02x\n", x, |
306 |
|
cpu->cd.sparc.canrestore); |
307 |
|
debug("cpu%i: otherwin = 0x%02x\n", x, |
308 |
|
cpu->cd.sparc.otherwin); |
309 |
|
debug("cpu%i: cleanwin = 0x%02x\n", x, |
310 |
|
cpu->cd.sparc.cleanwin); |
311 |
|
|
312 |
|
sum = cpu->cd.sparc.cansave + cpu->cd.sparc.canrestore + |
313 |
|
cpu->cd.sparc.otherwin; |
314 |
|
debug("cpu%i: cansave + canrestore + otherwin = %i + %i + %i" |
315 |
|
" = %i", x, cpu->cd.sparc.cansave, cpu->cd.sparc.canrestore, |
316 |
|
cpu->cd.sparc.otherwin, sum); |
317 |
|
if (sum == cpu->cd.sparc.cpu_type.nwindows - 2) |
318 |
|
debug(" (consistent)\n"); |
319 |
|
else |
320 |
|
debug(" (INCONSISTENT!)\n"); |
321 |
|
|
322 |
|
debug("cpu%i: wstate: other = %i, normal = %i\n", |
323 |
|
x, (cpu->cd.sparc.wstate & SPARC_WSTATE_OTHER_MASK) |
324 |
|
>> SPARC_WSTATE_OTHER_SHIFT, cpu->cd.sparc.wstate & |
325 |
|
SPARC_WSTATE_NORMAL_MASK); |
326 |
|
|
327 |
|
debug("cpu%i: asi = 0x%02x\n", x, cpu->cd.sparc.asi); |
328 |
|
debug("cpu%i: tl = 0x%02x\n", x, cpu->cd.sparc.tl); |
329 |
|
debug("cpu%i: pil = 0x%02x\n", x, cpu->cd.sparc.pil); |
330 |
|
|
331 |
|
for (i=0; i<MAXTL; i++) { |
332 |
|
debug("cpu%i: tpc[%i] = 0x", x, i); |
333 |
|
if (bits32) |
334 |
|
debug("%08"PRIx32"\n", |
335 |
|
(uint32_t) cpu->cd.sparc.tpc[i]); |
336 |
|
else |
337 |
|
debug("%016"PRIx64"\n", |
338 |
|
(uint64_t) cpu->cd.sparc.tpc[i]); |
339 |
|
|
340 |
|
debug("cpu%i: tnpc[%i] = 0x", x, i); |
341 |
|
if (bits32) |
342 |
|
debug("%08"PRIx32"\n", |
343 |
|
(uint32_t) cpu->cd.sparc.tnpc[i]); |
344 |
|
else |
345 |
|
debug("%016"PRIx64"\n", |
346 |
|
(uint64_t) cpu->cd.sparc.tnpc[i]); |
347 |
|
|
348 |
|
debug("cpu%i: tstate[%i] = 0x", x, i); |
349 |
|
if (bits32) |
350 |
|
debug("%08"PRIx32"\n", |
351 |
|
(uint32_t) cpu->cd.sparc.tstate[i]); |
352 |
|
else |
353 |
|
debug("%016"PRIx64"\n", |
354 |
|
(uint64_t) cpu->cd.sparc.tstate[i]); |
355 |
|
|
356 |
|
debug("cpu%i: ttype[%i] = 0x"PRIx32"\n", |
357 |
|
x, i, cpu->cd.sparc.ttype[i]); |
358 |
|
} |
359 |
|
|
360 |
|
debug("cpu%i: tba = 0x", x); |
361 |
|
if (bits32) |
362 |
|
debug("%08"PRIx32"\n", (uint32_t) cpu->cd.sparc.tba); |
363 |
|
else |
364 |
|
debug("%016"PRIx64"\n", (uint64_t) cpu->cd.sparc.tba); |
365 |
|
} |
366 |
} |
} |
367 |
|
|
368 |
|
|
380 |
} |
} |
381 |
|
|
382 |
|
|
|
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); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* sparc_cpu_gdb_stub(): |
|
|
* |
|
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
|
|
* on success, NULL on failure. |
|
|
*/ |
|
|
char *sparc_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'; |
|
|
/* TODO */ |
|
|
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 = sizeof(uint32_t); |
|
|
/* TODO: 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 < N_SPARC_REG) { |
|
|
add_response_word(cpu, r, |
|
|
cpu->cd.sparc.r[regnr], len, wlen); |
|
|
} else if (regnr == 0x44) { |
|
|
add_response_word(cpu, r, cpu->pc, len, wlen); |
|
|
/* TODO: |
|
|
20..3f = f0..f31 |
|
|
40 = y |
|
|
41 = psr |
|
|
42 = wim |
|
|
43 = tbr |
|
|
45 = npc |
|
|
46 = fsr |
|
|
47 = csr |
|
|
*/ |
|
|
} else { |
|
|
/* Unimplemented: */ |
|
|
add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); |
|
|
} |
|
|
return r; |
|
|
} |
|
|
|
|
|
fatal("sparc_cpu_gdb_stub(): TODO\n"); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* sparc_cpu_interrupt(): |
|
|
*/ |
|
|
int sparc_cpu_interrupt(struct cpu *cpu, uint64_t irq_nr) |
|
|
{ |
|
|
fatal("sparc_cpu_interrupt(): TODO\n"); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* sparc_cpu_interrupt_ack(): |
|
|
*/ |
|
|
int sparc_cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr) |
|
|
{ |
|
|
/* fatal("sparc_cpu_interrupt_ack(): TODO\n"); */ |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
383 |
/* |
/* |
384 |
* sparc_cpu_instruction_has_delayslot(): |
* sparc_cpu_instruction_has_delayslot(): |
385 |
* |
* |