[Paging] How to figure out where to place pages in memory
Posted: Thu Dec 30, 2010 9:05 am
Hi, I'm struggeling with paging atm and run into a GP fault when I try to enable it.
I figured out that the physical address of my pages is responsible for this fault (from my point of view).
So my question is: How do I find out where to place my pages in memory?
My solution would be:
- Get the address of the end section from the linker script! (As done in JamesM's tutorial)
This would be for me: 0x1068a0 hex -> 1075360 byte -> 1.02554 mega byte
So with 32mb of physical memory set in my VM there should be no problem mapping 4mb by my paging routine.
Funny thing: When I start creating my pages at 0b it works (works = I can set the cr3 to my page_directory address)
but when I start putting my pages 1075360b (behind the "end" from the linker script) I get a GP fault
when setting the paging bit to 1.
Any ideas why this happens or any hints I might not have considered?
Thanks in advance
My paging code so far:
I figured out that the physical address of my pages is responsible for this fault (from my point of view).
So my question is: How do I find out where to place my pages in memory?
My solution would be:
- Get the address of the end section from the linker script! (As done in JamesM's tutorial)
This would be for me: 0x1068a0 hex -> 1075360 byte -> 1.02554 mega byte
So with 32mb of physical memory set in my VM there should be no problem mapping 4mb by my paging routine.
Funny thing: When I start creating my pages at 0b it works (works = I can set the cr3 to my page_directory address)
but when I start putting my pages 1075360b (behind the "end" from the linker script) I get a GP fault
when setting the paging bit to 1.
Any ideas why this happens or any hints I might not have considered?
Thanks in advance
My paging code so far:
Code: Select all
#include "system.h"
unsigned long *page_directory = (unsigned long *) 0x9C000;
unsigned long *page_table = (unsigned long *) 0x9D000; // the page table comes right after the page directory
extern u32int end;
unsigned long address=(u32int)&end; // holds the physical address of where a page is <- This address does not work
unsigned int i;
void startPaging() {
putfs("Addresses will be placed at: %p\n",address);
// map the first 4MB of memory
for(i=0; i<1024; i++)
{
page_table[i] = address | 3; // attribute set to: supervisor level, read/write, present(011 in binary)
address = address + 4096; // 4096 = 4kb
};
// fill the first entry of the page directory
page_directory[0] = page_table; // attribute set to: supervisor level, read/write, present(011 in binary)
page_directory[0] = page_directory[0] | 3;
for(i=1; i<1024; i++)
{
page_directory[i] = 0 | 2; // attribute set to: supervisor level, read/write, not present(010 in binary)
};
irq_install_handler(14, page_fault);
asm volatile("mov %0, %%cr3":: "r"(page_directory));
unsigned long cr0;
asm volatile("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000;
//asm volatile("mov %0, %%cr0":: "r"(cr0));
}