I am writing a bootloader which boots off UEFI which requires paging to be able to load the kernel. It is built with msvc and yasm. I have set up page tables and everything, and have got functions to map virtual addresses and set attributes, but my OS hangs after I try writing the PML4 table address to cr3(assembly). I think it triple faults, somewhere in the virtualbox log it says 'VM_ERR_TRIPLE_FAULT' or something and enters 'Guru meditation'.
Also, I am not completely sure I am doing paging correct. There isn't much example code that I can use but I have made use of what I have managed to find.
Here is my code: https://pastebin.com/hQQmPC3j (it's quite big)
Here is some assembly I use:
Code: Select all
global get_paging_root
get_paging_root:
mov rax, cr3
ret
global set_paging_root
set_paging_root:
mov cr3, rcx
ret
global read_cr0
read_cr0:
mov rax, cr0
ret
global write_cr0
write_cr0:
mov cr0, rcx
ret
global enable_pae
enable_pae:
mov rax, 1
shl rax, 4
mov rbx, cr4
or rbx, rax
mov cr4, rbx
ret
global write_cr3
write_cr3:
mov cr3, rcx
ret
global get_cr4
get_cr4:
mov rax, cr4
ret
global tlbflush
tlbflush:
invlpg [rcx]
ret
global memory_barrier
memory_barrier:
mfence
ret
Apologies for being so naive, but I shall be very grateful if anyone could help me.
Thank you very much,
Heemogoblin