amd64: add extra information on fault

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-14 23:34:49 -04:00
commit 70d171fed8
3 changed files with 26 additions and 16 deletions

View file

@ -21,25 +21,22 @@ __idt:
.text .text
.global cr3_write .macro genrw reg
cr3_write: .global \reg\()_write
mov cr3, rdi \reg\()_write:
mov \reg, rdi
ret ret
.global cr3_read .global \reg\()_read
cr3_read: \reg\()_read:
mov rax, cr3 mov rax, \reg
ret ret
.endm
.global cr4_read genrw cr1
cr4_read: genrw cr2
mov rax, cr4 genrw cr3
ret genrw cr4
.global cr4_write
cr4_write:
mov cr4, rdi
ret
.global lgdt .global lgdt
lgdt: lgdt:

View file

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h> #include <kernel/common.h>
#include <lib/stdio.h> #include <lib/stdio.h>
#include "arch/reg.h"
static const char *exception_names[] = { static const char *exception_names[] = {
"Divide-by-zero Error", "Divide-by-zero Error",
@ -38,5 +39,8 @@ static const char *exception_names[] = {
void exception_handler(u64 no, u64 err) void exception_handler(u64 no, u64 err)
{ {
panic("(Exception) %s(%02xh)\n", exception_names[no], no); if (no == 0x0e)
kerr("(Page fault): 0x%16x\n", cr2_read());
if (!kernel_init_ready)
panic("(Exception) %s(%02xh)\n", exception_names[no], no);
} }

View file

@ -9,6 +9,15 @@
iretq iretq
.endm .endm
.macro exception_err nr
.global _exception_\nr
_exception_\nr:
mov rdi, \nr
popq rsi
call exception_handler
iretq
.endm
.macro irq nr .macro irq nr
.global _irq_\nr .global _irq_\nr
_irq_\nr: _irq_\nr: