Multiple cleanups and improvements

- Cleanup exception trigger code
- Cleanup division to divide by 0
- Cleanup SRET code
- Cleanup CSR code
- Added interrupts
- Added TIMER interrupt
This commit is contained in:
2023-10-22 19:20:52 +02:00
parent a0935f0aad
commit 02114ea7d8
8 changed files with 193 additions and 56 deletions
+6 -19
View File
@@ -2,6 +2,7 @@
#include "memory/memory.h"
#include "bootloader/bootloader.h"
#include "cpu/rv32cpu.h"
#include "cpu/interrupt.h"
#include "gdbstub/gdbstub.h"
#include "devices/uart/uart.h"
@@ -31,34 +32,20 @@ int main(int argc, char** argv)
gdbstub_wait_for_connection();
}
// Initialize timer for timer interrupt
interrupt_timer_setup();
// CPU simulation : create cpu0 thread
if(!gdbstub) cpu0->sim_ticks_left = -1; // Simulate forever
pthread_t cpu0_thread;
pthread_create(&cpu0_thread, 0, (void*) cpu_loop, cpu0);
// Wait for the simulation to end
// Wait forever, until simulation end (which should be an ecall shutdown)
pthread_join(cpu0_thread, 0);
if(gdbstub)
{
pthread_join(cpu0_thread, 0);
gdbstub_stop();
}
else
{
while(1)
{
pthread_mutex_lock(&cpu0_mutex);
pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex);
if(!cpu0->sim_ticks_left && cpu0->sim_ticks_done > 0)
{
// Simulation ended
break;
}
pthread_mutex_unlock(&cpu0_mutex);
}
fprintf(stderr, "Simulation ended (in a non-debug environment)\n");
return cpu0->regs.a0;
}
return 0;
}