Compare commits

...

2 Commits

Author SHA1 Message Date
6b9e5c766b rv32cpu: allocated with calloc (for debug) 2023-10-08 14:09:20 +02:00
cb98752b67 gdbstub: implemented G command 2023-10-08 14:09:06 +02:00
2 changed files with 24 additions and 1 deletions

View File

@ -39,7 +39,7 @@ static void cpu_print_instruction(instruction_t* instruction);
void cpu_init() void cpu_init()
{ {
cpu0 = malloc(sizeof(rv32_cpu_t)); cpu0 = calloc(1, sizeof(rv32_cpu_t));
cpu0->regs.zero = 0; cpu0->regs.zero = 0;
} }

View File

@ -158,6 +158,7 @@ void gdbstub_thread_gdb()
} }
else if(packet[0] == 'g') else if(packet[0] == 'g')
{ {
// g : read all registers -> send back all registers
char resp[32 * 8 + 8 + 1] = {0}; char resp[32 * 8 + 8 + 1] = {0};
// All general purpose registers in host byte order as chars // All general purpose registers in host byte order as chars
@ -175,6 +176,28 @@ void gdbstub_thread_gdb()
size_t size = 32 * 8 + 8; size_t size = 32 * 8 + 8;
gdbstub_send_packet(resp, size); gdbstub_send_packet(resp, size);
} }
else if(packet[0] == 'G')
{
// G : write all registers -> read and set all registers
// All general purpose registers in host byte order as chars
for(size_t i = 1; i < 32; i++)
{
uint32_t value = 0;
sscanf(packet + 1 + i * 8, "%08x", &value);
value = ntohl(value);
cpu0->regs.x[i] = value;
}
// PC register
uint32_t pc = 0;
sscanf(packet + 1 + 32 * 8, "%08x", &pc);
pc = ntohl(pc);
cpu0->pc = pc;
gdbstub_send_packet("OK", 2);
}
else gdbstub_send_unsupported(); else gdbstub_send_unsupported();
} }
} }