Unusual page table reported by Bochs
Posted: Tue May 08, 2012 8:48 pm
I'm currently moving to the use of 2 MiB pages, but whenever I try to use large pages Bochs' report of my page table doesn't even make sense.
The code I use to initialize the PML4 table is:
yet Bochs' debugger reports the page table as
This happens even when I do not reload CR3.
I am in long mode and PAE as well as paging are enabled.
Am I missing something obvious?
The code I use to initialize the PML4 table is:
Code: Select all
//-----------------------------------------------------------------
// Definitions
//-----------------------------------------------------------------
#ifndef synapse_mmanager_c
#define synapse_mmanager_c
#define PAGE_PRESENT 0x01 // page is present
#define PAGE_WRITABLE 0x02 // page is writable
#define PAGE_USERACCESS 0x04 // user mode accessable
#define PAGE_WRITETHROUGH 0x08
#define PAGE_CACHEDISABLE 0x10 // disable caching for page
#define PAGE_ACCESSED 0x20 // has been accessed; set by CPU
#define PAGE_DIRTY 0x40
#define PAGE_LARGEPAGE 0x80 // page size, 0 = 4KiB
#define PAGE_GLOBALPAGE 0x100
#define PAGE_NOEXECUTE 0x8000000000000000 //disable execution
//-----------------------------------------------------------------
// Data Types
//-----------------------------------------------------------------
typedef struct
{
uint64_t present : 1;
uint64_t writable : 1;
uint64_t useraccess : 1;
uint64_t writethru : 1;
uint64_t disablecache : 1;
uint64_t accessed : 1;
uint64_t dirty : 1;
uint64_t largepage : 1;
uint64_t global : 1;
uint64_t reserved : 3;
uint64_t frame : 51;
uint64_t noexecute : 1;
} Page;
typedef struct
{
uint64_t *page[512]; // pointers to the 2 MiB page frames
} PageTable;
typedef struct
{
PageTable *table[512]; // pointers to the 1 GiB page tables
} PageDirectory;
//-----------------------------------------------------------------
// Variables
//-----------------------------------------------------------------
PageDirectory *pageDirectory;
PageTable *pageTable;
uint64_t *pages;
Code: Select all
pageDirectory = (PageDirectory *)0x2000; // define this location as PML4 base, maps 512 GiB
pageTable = (PageTable *)0x3000;
pages = (uint64_t *)0x10000;
pageDirectory->table[0] = (PageTable *)(((uint64_t)pageTable) | PAGE_PRESENT | PAGE_WRITABLE | PAGE_USERACCESS); // attributes resolve to 0x07
uint16_t i;
for (i = 0; i < 32; i++) // identity map the first 64 MiB and make it kernel elevated (can change later if needed)
{
pages[i] = (uint64_t)((i * 0x200000) | PAGE_PRESENT | PAGE_WRITABLE | PAGE_LARGEPAGE); // attributes resolve to 0x83
pageTable->page[i] = pages[i] | PAGE_PRESENT | PAGE_WRITABLE; // attributes resolve to 0x03
}
asm volatile("mov %0, %%cr3":: "r"(0x2000));
}
Code: Select all
0x00000000-0x00005fff -> 0x0000000000000000-0x0000000000005fff
0x00007000-0x00009fff -> 0x0000000000007000-0x0000000000009fff
0x00010000-0x00010fff -> 0x0000000000010000-0x0000000000010fff
0x00050000-0x00050fff -> 0x0000000000050000-0x0000000000050fff
0x000b8000-0x000b8fff -> 0x00000000000b8000-0x00000000000b8fff
0x000e0000-0x000fcfff -> 0x00000000000e0000-0x00000000000fcfff
0x00200000-0x00204fff -> 0x0000000000200000-0x0000000000204fff
0x3fff0000-0x3fff0fff -> 0x000000003fff0000-0x000000003fff0fff
I am in long mode and PAE as well as paging are enabled.
Am I missing something obvious?