Files
KatauOS/src/kernel/isr.asm
T

48 lines
1.2 KiB
NASM

section .text
global page_fault_handler
extern handle_page_fault ; C function to process the fault
page_fault_handler:
; Save registers to preserve state
pushad ; Push EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
push ds
push es
push fs
push gs
; Set up kernel data segment
mov ax, 0x10 ; Kernel data segment selector (adjust based on your GDT)
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; Get the faulting address from CR2
mov eax, cr2
; Push parameters for the C function:
; - Faulting address (from CR2)
; - Error code (at [esp + 48], after pushed registers and segment selectors)
push eax ; Push CR2 (faulting address)
mov ebx, [esp + 48] ; Get error code (adjust offset based on stack layout)
push ebx ; Push error code
; Call the C handler
call handle_page_fault
; Clean up parameters from stack
add esp, 8 ; Remove error code and CR2
; Restore registers
pop gs
pop fs
pop es
pop ds
popad
; Remove error code from stack
add esp, 4 ; Pop error code
; Return from interrupt
iret ; Restore EIP, CS, EFLAGS (and ESP, SS if privilege change)