kernel: panic

This commit is contained in:
Matheus
2023-04-08 21:40:31 -03:00
parent e364f631e4
commit ad70e8741d
4 changed files with 34 additions and 3 deletions
+8
View File
@@ -0,0 +1,8 @@
#ifndef _PANIC_H
#define _PANIC_H
#include <arch/context.h>
__attribute__((noreturn)) void _panic(char *msg, context_t *ctx);
#endif
+7 -2
View File
@@ -2,6 +2,7 @@
#define _CONTEXT_H
#include <stdint.h>
#include <printf.h>
typedef struct {
uint64_t cr2;
@@ -32,7 +33,11 @@ typedef struct {
uint64_t ss;
} __attribute__((packed)) context_t;
#define ARCH_CTX_SP(x) x->rsp;
#define ARCH_CTX_IP(x) x->rip;
#define CTX_SP(x) x->rsp;
#define CTX_IP(x) x->rip;
#define PRINT_CTX(x) { \
printf("cr2: %016lx gs: %04x\nrax: %016lx fs: %04x\nrbx: %016lx es: %04x\nrcx: %016lx ds: %04x\nrdx: %016lx cs: %04x\n r8: %016lx ss: %04x\n r9: %016lx r10: %016lx\nr11: %016lx r12: %016lx\nr13: %016lx r14: %016lx\nr15: %016lx rdi: %016lx\nrsi: %016lx rbp: %016lx\nrip: %016lx rsp: %016lx\nerr: %016lx rfl: %016lx\n", \
x->cr2, x->gs, x->rax, x->fs, x->rbx, x->es, x->rcx, x->ds, x->rdx, x->cs, x->r8, x->ss, x->r9, x->r10, x->r11, x->r12, x->r13, x->r14, x->r15, x->rdi, x->rsi, x->rbp, x->rip, x->rsp, x->error, x->rflags); \
}
#endif
+15
View File
@@ -0,0 +1,15 @@
#include <panic.h>
#include <arch/cpu.h>
#include <printf.h>
__attribute__((noreturn)) void _panic(char *msg, context_t *ctx) {
printf("Oops.\n");
if (msg)
printf("%s\n", msg);
if (ctx)
PRINT_CTX(ctx);
for (;;);
}
+4 -1
View File
@@ -2,10 +2,13 @@
#include <logging.h>
#include <arch/cpu.h>
#include <arch/context.h>
#include <panic.h>
void interrupt_isr(int vec, context_t *ctx) {
isr_t *isr = &_cpu()->isr[vec];
__assert(isr->func);
if (isr->func == NULL)
_panic("Unregistered interrupt", ctx);
// TODO ipl check
isr->func(isr, ctx);