smol-gilbraltar/kernel/exception_handler.c

32 lines
899 B
C
Raw Permalink Normal View History

2024-12-20 22:45:12 +00:00
#include <exception_handler.h>
2024-12-23 00:46:17 +00:00
#include <log.h>
#include <synchronize.h>
static const char *names[] = {"Unexpected exception", "Synchronous exception",
"System error"};
2024-12-20 22:45:12 +00:00
void gilbraltar_exception_handler(uint64_t exn, struct frame *frame) {
2024-12-23 00:46:17 +00:00
enable_fiqs();
uint64_t sp = frame->sp_el0;
if ((frame->spsr_el1 & 0xf) == 0x05)
sp = frame->sp_el1;
uint64_t ec = (frame->esr_el1 >> 26) & 0x3f;
uint64_t iss = frame->esr_el1 & 0x1ffffff;
uint64_t far = 0;
if ((0x20 <= ec && ec <= 0x25) || (0x34 <= ec && ec <= 0x35))
far = frame->far_el1;
gilbraltar_log(ERROR,
"%s (pc: 0x%lx, ec: 0x%lx, iss: 0x%lx, far: 0x%lx, sp: 0x%lx, "
"lr: 0x%lx, spsr: 0x%lx)\r\n",
names[exn], frame->elr_el1, ec, iss, far, sp, frame->x30,
frame->spsr_el1);
2024-12-20 22:45:12 +00:00
while (1)
__asm__ __volatile("wfi");
}