merge branch memory-shit into higher-half

This commit is contained in:
2025-05-10 15:48:10 +03:00
parent 65f543fa92
commit 767e74976f
14 changed files with 419 additions and 178 deletions
+47
View File
@@ -0,0 +1,47 @@
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)