25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: cpu_ppc.c,v 1.67 2006/12/30 13:30:54 debug Exp $ |
* $Id: cpu_ppc.c,v 1.68 2007/03/26 02:01:36 debug Exp $ |
29 |
* |
* |
30 |
* PowerPC/POWER CPU emulation. |
* PowerPC/POWER CPU emulation. |
31 |
*/ |
*/ |
587 |
} |
} |
588 |
|
|
589 |
|
|
|
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); |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
* ppc_cpu_gdb_stub(): |
|
|
* |
|
|
* Execute a "remote GDB" command. Returns a newly allocated response string |
|
|
* on success, NULL on failure. |
|
|
*/ |
|
|
char *ppc_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.ppc.gpr[regnr], len, wlen); |
|
|
} else if (regnr == 0x40) { |
|
|
add_response_word(cpu, r, cpu->pc, len, wlen); |
|
|
} else if (regnr == 0x42) { |
|
|
add_response_word(cpu, r, cpu->cd.ppc.cr, len, wlen); |
|
|
} else if (regnr == 0x43) { |
|
|
add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_LR], |
|
|
len, wlen); |
|
|
} else if (regnr == 0x44) { |
|
|
add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_CTR], |
|
|
len, wlen); |
|
|
} else if (regnr == 0x45) { |
|
|
add_response_word(cpu, r, cpu->cd.ppc.spr[SPR_XER], |
|
|
len, wlen); |
|
|
} else { |
|
|
/* Unimplemented: */ |
|
|
add_response_word(cpu, r, 0xcc000 + regnr, len, wlen); |
|
|
} |
|
|
return r; |
|
|
} |
|
|
|
|
|
fatal("ppc_cpu_gdb_stub(): TODO\n"); |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
|
|
590 |
/* |
/* |
591 |
* ppc_irq_interrupt_assert(): |
* ppc_irq_interrupt_assert(): |
592 |
*/ |
*/ |