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
.global cr3_write
cr3_write:
mov cr3, rdi
.macro genrw reg
.global \reg\()_write
\reg\()_write:
mov \reg, rdi
ret
.global cr3_read
cr3_read:
mov rax, cr3
.global \reg\()_read
\reg\()_read:
mov rax, \reg
ret
.endm
.global cr4_read
cr4_read:
mov rax, cr4
ret
.global cr4_write
cr4_write:
mov cr4, rdi
ret
genrw cr1
genrw cr2
genrw cr3
genrw cr4
.global lgdt
lgdt:

View file

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <lib/stdio.h>
#include "arch/reg.h"
static const char *exception_names[] = {
"Divide-by-zero Error",
@ -38,5 +39,8 @@ static const char *exception_names[] = {
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
.endm
.macro exception_err nr
.global _exception_\nr
_exception_\nr:
mov rdi, \nr
popq rsi
call exception_handler
iretq
.endm
.macro irq nr
.global _irq_\nr
_irq_\nr: