Multiple Page directorys
Posted: Sat Jun 24, 2006 8:15 am
Hi There,
I am having some trouble with my OS's memory, I think I have misunderstood paging. Currently my OS has just two tasks, the kernel task and a shell task running in ring 3.
I have 3 system memory areas, 0x0 - 0x0FFFFFFF is where the kernel is, 0x10000000 - 0x1FFFFFFF is where memory allocated for the kernel to use goes, 0x20000000 - 0x2FFFFFFF is where I buffer file system blocks.
When I set up the shell task, I use 0x40000000 - for the program and any extra memory it needs is added to that. I use the following code to create the tasks own page directory:
The problem is, when my buffer system needs more buffers while it is in user mode, it maps into the kernel's page directory but it seems to be unavailable in the application's page directory.
However my system page faults when trying to access the newly allocated buffers.
My operating system only reloads cr3 on a task switch, so, when an irq happens cr3 is loaded with the last applications page directory.
The idea of my code above was that by copying the first 256 page tables, if i mapped a new entry in any of those first 256 areas, it would instantly change all the page tables.
Should the above code work like that? I am not sure if it is correct, my bugs must be from some other cause.
Thanks..
I am having some trouble with my OS's memory, I think I have misunderstood paging. Currently my OS has just two tasks, the kernel task and a shell task running in ring 3.
I have 3 system memory areas, 0x0 - 0x0FFFFFFF is where the kernel is, 0x10000000 - 0x1FFFFFFF is where memory allocated for the kernel to use goes, 0x20000000 - 0x2FFFFFFF is where I buffer file system blocks.
When I set up the shell task, I use 0x40000000 - for the program and any extra memory it needs is added to that. I use the following code to create the tasks own page directory:
Code: Select all
uint32_t *phys_mem_new_page_dir() {
uint32_t *new_page_dir;
int i;
int delta;
// copy master page directory's layout
delta = PAGE_SIZE;
new_page_dir = (uint32_t *)phys_mem_blk_alloc();
if (new_page_dir == NULL) return NULL;
phys_map_mem((uint32_t)new_page_dir,(uint32_t)new_page_dir,3, PAGE_SIZE);
// map the kernel area
for (i=0;i<256;i++) {
new_page_dir[i] = page_directory[i];
}
for (i=256;i<1023;i++) {
new_page_dir[i] = 0 | 2;
}
new_page_dir[1023] = (uint32_t)new_page_dir | 3;
return new_page_dir;
}
However my system page faults when trying to access the newly allocated buffers.
My operating system only reloads cr3 on a task switch, so, when an irq happens cr3 is loaded with the last applications page directory.
The idea of my code above was that by copying the first 256 page tables, if i mapped a new entry in any of those first 256 areas, it would instantly change all the page tables.
Should the above code work like that? I am not sure if it is correct, my bugs must be from some other cause.
Thanks..