OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 23, 2017 4:02 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Paging
PostPosted: Sat Jan 21, 2017 7:49 am 
Offline

Joined: Sat Jan 21, 2017 7:35 am
Posts: 14
I am asking my first question, thus, this may be the wrong place.

I am developing a OS and am stuck, kind of, on virtual memory management aka Paging. I setup a page directory (1024 u32). I also have a array of 1024 page tables - u32[1024]1024] __aligned. I map each page table to a page directory 1 to 1. After enabling paging, I add a page for 0xb8000 and use that address to print to screen but a page fault comes - Page Not Present, Write.

Code -

extern "C" void LoadDirectory(DirectoryEntry*);
extern "C" void EnablePaging(void);
extern "C" {
PageTable KernelMap[1024] __attribute__((aligned(4096)));
DirectoryEntry KernelDirectory[1024] __attribute__((aligned(4096)));
}

PagingBroker::PagingBroker() {
if(!pagingSetup){
int setupIndex = 0;
for( ; setupIndex < 1024; setupIndex++) {
KernelDirectory[setupIndex] = 0x2; // Supervisor, Read-Write, Not Present
}
pagingSetup = true;
}
}

/* Higher Half */
void PagingBroker::setupPaging() {
unsigned int pageIndex;

for(pageIndex = 0; pageIndex < 1024; pageIndex++) {
KernelMap[0][pageIndex] = (pageIndex * 0x1000) | 3;
}

for(pageIndex = 0; pageIndex < 1024; pageIndex++) {
KernelMap[1][pageIndex] = ((pageIndex + 1024) * 0x1000) | 3;
}


KernelDirectory[0] = ((DirectoryEntry) KernelMap[0]) | 3; // Identity Map First 4MB
KernelDirectory[1] = ((DirectoryEntry) KernelMap[1]) | 3; // 8MB


LoadDirectory(KernelDirectory);
EnablePaging();
}void PagingBroker::AddPage(unsigned long virtualAddress, unsigned long physicalAddress, unsigned int pflags) {
unsigned long pdIndex = virtualAddress >> 22;
unsigned long ptIndex = virtualAddress >> 12;

KernelDirectory[pdIndex] = ((DirectoryEntry) KernelDirectory[pdIndex]) | 3;

KernelMap[pdIndex][ptIndex] = physicalAddress | (pflags & 0xfff); // Present

FlushTLB(pdIndex);
}

In my Main() - {
PagingBroker pb;
pb.setupPaging();
pb.AddPage((anything more than 8mb - 'xaddr'), 0xb8000, 3);
char *write = (char*) xaddr;
*write = 'd';
write[1] = 0x7;
}

-------------------------------

I am using GCC and NASM with a linker (ld).


Top
 Profile  
 
 Post subject: Re: Paging
PostPosted: Sat Jan 21, 2017 7:52 am 
Offline

Joined: Sat Jan 21, 2017 7:35 am
Posts: 14
Also, where can I add my own article (not question)


Top
 Profile  
 
 Post subject: Re: Paging
PostPosted: Sat Jan 21, 2017 9:35 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 566
Location: Tallinn, Estonia
SukantPal wrote:
Also, where can I add my own article (not question)


Article about what?

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: Paging
PostPosted: Sat Jan 21, 2017 10:05 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 7740
Location: At his keyboard!
Hi,

SukantPal wrote:
I am asking my first question, thus, this may be the wrong place.


Your original post got moved out of "About This Site" and into "OS Development". You can find it here.

SukantPal wrote:
Also, where can I add my own article (not question)


It sounds like you want to add an article to the wiki. The best place for that would be the wiki. ;)

Note: As a new member you'll probably want to see the OSDev Wiki access FAQ.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 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