Move the trap to panic.c

This commit is contained in:
Liam Kerr 2026-02-09 02:57:04 +00:00
parent 2564aa6aba
commit 2296179bf8
3 changed files with 24 additions and 28 deletions

View file

@ -24,3 +24,26 @@ void kpanic_force() {
__asm__ volatile("wfi");
}
}
void handle_trap() {
kprint("\n!!! HARDWARE EXCEPTION DETECTED !!!\n");
// Read the 'mcause' register to see WHY we trapped
unsigned long cause;
__asm__ volatile("csrr %0, mcause" : "=r"(cause));
switch(cause) {
case 0: kprint("Reason: Instruction Address Misaligned\n"); break;
case 1: kprint("Reason: Instruction Access Fault\n"); break;
case 2: kprint("Reason: Illegal Instruction\n"); break;
case 3: kprint("Reason: Breakpoint (ebreak)\n"); break;
case 4: kprint("Reason: Load Address Misaligned\n"); break;
case 5: kprint("Reason: Load Access Fault\n"); break;
case 6: kprint("Reason: Store/AMO Address Misaligned\n"); break;
case 7: kprint("Reason: Store/AMO Access Fault\n"); break;
default:
kprintf("Reason: Unknown Exception Code %d\n", cause);
}
poweroff();
}