mirror of
https://git.stationery.faith/corn/corn.git
synced 2024-11-22 04:32:19 +00:00
refactor exception panic
This commit is contained in:
parent
90a6065691
commit
5bec5d9fbd
4 changed files with 17 additions and 32 deletions
|
@ -8,6 +8,3 @@
|
||||||
|
|
||||||
__attribute__((format(printf, 3, 4)))
|
__attribute__((format(printf, 3, 4)))
|
||||||
_Noreturn void _panic_impl(char *line, char *file, char *format, ...);
|
_Noreturn void _panic_impl(char *line, char *file, char *format, ...);
|
||||||
|
|
||||||
__attribute__((format(printf, 3, 4)))
|
|
||||||
_Noreturn void panic_interrupt(void *ip, void *bp, char *format, ...);
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
#include <panic.h>
|
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
|
#include "backtrace.h"
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
#include "../paging.h"
|
#include "../bindings.h"
|
||||||
#include "../drivers/pic.h"
|
#include "../drivers/pic.h"
|
||||||
|
|
||||||
#define IDT_SIZE 256
|
#define IDT_SIZE 256
|
||||||
|
@ -117,25 +118,25 @@ void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *s
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char custom[64];
|
kputs("\n\n!!! EXCEPTION !!!\n");
|
||||||
*custom = '\0';
|
kprintf("0x%02lX %s\n", exception, EXCEPTIONS[exception]);
|
||||||
|
kprintf("Error code 0x%lX\n", code);
|
||||||
|
|
||||||
|
|
||||||
// page faults store the offending address in cr2
|
// page faults store the offending address in cr2
|
||||||
if (exception == 0x0E) {
|
if (exception == 0x0E) {
|
||||||
strcat(custom, "\nPage fault address: 0x");
|
|
||||||
uint64_t cr2;
|
uint64_t cr2;
|
||||||
__asm__ volatile ("mov %%cr2, %0" : "=r"(cr2));
|
__asm__ volatile ("mov %%cr2, %0" : "=r"(cr2));
|
||||||
ultoa((size_t)cr2, custom + 23, 16);
|
kprintf("Page fault address: 0x%lX\n", cr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
panic_interrupt(
|
kputs("\n");
|
||||||
(void *)state->rip,
|
|
||||||
(void *)state->rbp,
|
log_backtrace_ex((void *)state->rip, (void *)state->rbp);
|
||||||
"Exception %s\nError code 0x%lu%s",
|
|
||||||
EXCEPTIONS[exception],
|
while (1) {
|
||||||
code,
|
halt();
|
||||||
custom
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void idt_pic_eoi(uint8_t exception) {
|
void idt_pic_eoi(uint8_t exception) {
|
||||||
|
|
|
@ -20,17 +20,3 @@ _Noreturn void _panic_impl(char *line, char *file, char *format, ...) {
|
||||||
halt();
|
halt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_Noreturn void panic_interrupt(void *ip, void *bp, char *msg, ...) {
|
|
||||||
va_list list;
|
|
||||||
va_start(list, msg);
|
|
||||||
cli();
|
|
||||||
kputs("\n\n!!! PANIC !!!\n");
|
|
||||||
kvprintf(msg, list);
|
|
||||||
kputs("\n\n");
|
|
||||||
|
|
||||||
log_backtrace_ex(ip, bp);
|
|
||||||
while (1) {
|
|
||||||
halt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,8 +20,9 @@ void kmain(struct boot_info *info) {
|
||||||
char *test = kalloc(5);
|
char *test = kalloc(5);
|
||||||
*test = 1;
|
*test = 1;
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
screen_redraw();
|
screen_redraw();
|
||||||
|
// loop so we dont halt
|
||||||
|
// this allows interrupts to fire
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue