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).
Paging
Re: Paging
Also, where can I add my own article (not question)
Re: Paging
Article about what?SukantPal wrote:Also, where can I add my own article (not question)
Learn to read.
Re: Paging
Hi,
Note: As a new member you'll probably want to see the OSDev Wiki access FAQ.
Cheers,
Brendan
Your original post got moved out of "About This Site" and into "OS Development". You can find it here.SukantPal wrote:I am asking my first question, thus, this may be the wrong place.
It sounds like you want to add an article to the wiki. The best place for that would be the wiki.SukantPal wrote:Also, where can I add my own article (not question)
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.