Do I have the right idea about paging?
Posted: Sun Jun 28, 2009 11:58 am
I'm not sure what needs to be done next to move on to some real memory management, or if the code I've written so far is correct.
Have I got the idea right, at least?
Code: Select all
#include <system.h>
/* Page Directory is an array of 1024 Entries, each pointing to a page table
*
* Page Table is an array of 1024 Entries, each pointing to a page's phys addr
*/
struct page_directory_entry
{
// pointer to a page table
struct page_table_entry *page_table[1024];
};
struct page_table_entry
{
// pointer to page's physical address.
unsigned long page;
};
struct page_directory_entry *page_directory[1024];
void init_paging()
{
__asm__ __volatile__("mov %1, %eax" :: "r"(page_directory) : "%eax");
__asm__ __volatile__("mov %eax, %cr3" ::: "%eax");
__asm__ __volatile__("mov %cr0, %eax" ::: "%eax");
__asm__ __volatile__("or %eax, 0x80000000" ::: "%eax");
__asm__ __volatile__("mov %eax, %cr0" ::: "%eax");
}