2

When trying to set up virtual memory I'm a bit confused about where to go regarding mapping a given virtual address to a physical address. When working with x86 architecture and using IA-32E mode I have a function to map a new virtual page

    int allocate_page(page_table_entry* p)
{
    //Get Physical Block for this page table entry to point to
    void* phys = getFreeBlock();
    //Here I need to map the virtual entry to this physical page frame

}

According to the Intel Manual For a 4 level page table, the first 4 bits of the virtual address should give the Page Directory Table Pointer, the next 9 bits should give the Page Directory, the next 9 bits are used to find the Page Table, and the last 12 bits are used for the offset in the page frame, for a total of 52 bits. Does anybody have any resources or a suggestion of how I can get started implementing the rest of this function so that I can take a given virtual address and map it to a free page frame?

theDmi
  • 17,546
  • 6
  • 71
  • 138
sreisman
  • 658
  • 3
  • 9
  • 24
  • Read this for the theory http://stackoverflow.com/questions/18431261/how-does-x86-paging-work I have a minimal 32-bit example at: https://github.com/cirosantilli/x86-bare-metal-examples/blob/5c672f73884a487414b3e21bd9e579c67cd77621/paging.S If you extend it to 64-bit, send me PR, shouldn't be too hard :-) – Ciro Santilli OurBigBook.com Nov 13 '15 at 09:45

0 Answers0