Can't enable paging
Posted: Wed Jan 12, 2022 7:32 am
Hello, i'm trying to create os in c++ and i stumbled upon 1 problem: setting the paging bit causes a Triple Fault. Code here:
paging.asm:
kernel.cpp:
What am I doing wrong?
P.S. the value of the control registers after the error occurred:
CR0=0x80000011 CR2=0x01002580 CR3=0x01004000 CR4=0x00000000
The kernel is placed after 16 MB (at address 0x1000000)
paging.asm:
Code: Select all
[Bits 32]
[Global PagingLoadDirectory]
[Global PagingEnable]
PagingLoadDirectory:
push ebp
mov ebp, esp
mov eax, [esp+8]
mov cr3, eax
mov esp, ebp
pop ebp
ret
PagingEnable:
push ebp
mov ebp, esp
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
mov esp, ebp
pop ebp
ret
Code: Select all
extern "C" void PagingLoadDirectory(psize_t directory);
extern "C" void PagingEnable();
//...
psize_t PageDirectory = (psize_t)0x1004000;
psize_t PageTable = (psize_t)0x1005000;
for (size_t i = 0; i < 1024; i++) PageDirectory[i] = 0x00000002;
for (size_t i = 0x1000; i < 0x1400; i++) PageTable[i] = (i * 0x1000) | 3;
PageDirectory[0] = (size_t)PageTable | 3;
PagingLoadDirectory(PageDirectory);
PagingEnable(); //Triple Fault
P.S. the value of the control registers after the error occurred:
CR0=0x80000011 CR2=0x01002580 CR3=0x01004000 CR4=0x00000000
The kernel is placed after 16 MB (at address 0x1000000)