Files
osc2025/kernel/lib/exception.c
2025-05-03 20:45:34 +08:00

49 lines
848 B
C

#include <exception.h>
#include <errcode.h>
#include <stddef.h>
#include <logger.h>
#include <utils.h>
#include <syscall.h>
#include <interrupt.h>
void exception_init()
{
asm volatile(
"adr x0, exception_vector_table" ENDL
"msr vbar_el1, x0" ENDL
::: "x0"
);
}
void not_implemented_handler()
{
DEBUG_EXCEP("not implemented caught");
}
void synchronous_handler(trapframe_t *regs)
{
disable_interrupt();
DEBUG_EXCEP("synchronous caught");
uint64_t x0 = 0x0;
R_REG(x0, x0);
uint64_t spsr_el1 = 0x0;
R_SYSREG(spsr_el1, spsr_el1);
uint64_t elr_el1 = 0x0;
R_SYSREG(elr_el1, elr_el1);
uint64_t esr_el1 = 0x0;
R_SYSREG(esr_el1, esr_el1);
LOG(x0); LOG(spsr_el1); LOG(elr_el1); DEBUG_EXCEP(esr_el1)
switch ((esr_el1 >> 26) & 0x7f) {
case 0b010101:
syscall_handler(regs);
break;
default:
}
}