kernel panic and trapping :)

This commit is contained in:
Liam Kerr 2026-02-08 22:41:38 +00:00
parent fae2e42f8f
commit da95a4acfa
5 changed files with 70 additions and 1 deletions

20
src/kernel/trap.c Normal file
View file

@ -0,0 +1,20 @@
#include <stdint.h>
#include <stddef.h>
#include <drivers/uart.h>
#include <syscon/syscon.h>
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));
if (cause == 3) { // 3 is the code for 'breakpoint' (ebreak)
kprint("Reason: ebreak (Breakpoint)\n");
} else {
kprint("Reason: Other Exception\n");
}
poweroff();
}