OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Can't enable paging
PostPosted: Wed Jan 12, 2022 7:32 am 
Offline

Joined: Wed Jan 12, 2022 7:20 am
Posts: 1
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:
Code:
[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


kernel.cpp:
Code:
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


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)


Top
 Profile  
 
 Post subject: Re: Can't enable paging
PostPosted: Thu Jan 13, 2022 9:53 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Code:
for (size_t i = 0x1000; i < 0x1400; i++) PageTable[i] = (i * 0x1000) | 3;

I'm pretty sure this code isn't doing what you want. How big is the PageTable array supposed to be?

Code:
PageDirectory[0] = (size_t)PageTable | 3;

Your kernel is loaded above 16MiB, but entry 0 of the page directory only covers virtual addresses between 0 and 4MiB.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 68 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group