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

27
src/kernel/panic.c Normal file
View file

@ -0,0 +1,27 @@
#include <stddef.h>
#include <stdint.h>
#include <drivers/uart.h>
#include <syscon/syscon.h>
void kpanic(const char *reason){
kprint(reason);
poweroff();
}
void kpanic_force() {
// 1. Immediate Output
kprint("\n!!! FORCE PANIC !!!\n");
// 2. Trigger a hardware breakpoint or illegal instruction
// This allows a debugger (GDB) to stop exactly here.
// 'ebreak' is the standard RISC-V way to trigger a debug trap.
__asm__ volatile("ebreak");
// 3. If no debugger is attached or we continue, kill the VM
poweroff();
// 4. Final halt
while(1) {
__asm__ volatile("wfi");
}
}