15 #define PAGE_SIZE 0x1000 16 #define PAGE_SIZE_LARGE 0x200000 17 #define PAGE_SIZE_HUGE 0x40000000 20 #define PF_PRESENT (1 << 0) // Page is present in the table 21 #define PF_RW (1 << 1) // Read-write 22 #define PF_USER (1 << 2) // User-mode (CPL==3) access allowed 23 #define PF_PWT (1 << 3) // Page write-thru 24 #define PF_PCD (1 << 4) // Cache disable 25 #define PF_ACCESS (1 << 5) // Indicates whether page was accessed 26 #define PF_DIRTY (1 << 6) // Indicates whether 4K page was written 27 #define PF_PS (1 << 7) // Page size (valid for PD and PDPT only) 28 #define PF_GLOBAL (1 << 8) // Indicates the page is globally cached 29 #define PF_SYSTEM (1 << 9) // Page used by the kernel 32 #define PGSHIFT_PML4E 39 33 #define PGSHIFT_PDPTE 30 34 #define PGSHIFT_PDE 21 35 #define PGSHIFT_PTE 12 36 #define PGMASK_ENTRY 0x1ff 37 #define PGMASK_OFFSET 0x3ff 40 #define PML4E(a) (((a) >> PGSHIFT_PML4E) & PGMASK_ENTRY) 41 #define PDPTE(a) (((a) >> PGSHIFT_PDPTE) & PGMASK_ENTRY) 42 #define PDE(a) (((a) >> PGSHIFT_PDE) & PGMASK_ENTRY) 43 #define PTE(a) (((a) >> PGSHIFT_PTE) & PGMASK_ENTRY) 46 #define PGPTR(pte) ((page_t *)((pte) & ~PGMASK_OFFSET)) 66 typedef struct pagetable
void * page_alloc(pagetable_t *pt, void *vaddr, int count)
Allocate one or more pages contiguous in virtual memory.
uint64_t proot
Physical address of root page table (PML4T) entry.
void pagetable_create(pagetable_t *pt, void *vaddr, uint64_t size)
Create a new page table that can be used to associate virtual addresses with physical addresses...
uint64_t vnext
Virtual address to use for table's next page.
void page_free(pagetable_t *pt, void *vaddr, int count)
Free one or more contiguous pages from virtual memory.
void pagetable_destroy(pagetable_t *pt)
Destroy a page table.
uint64_t vterm
Boundary of pages used to store the table.
uint64_t vroot
Virtual address of root page table (PML4T) entry.
void pagetable_activate(pagetable_t *pt)
Activate a page table on the CPU, so all virtual memory operations are performed relative to the page...
void page_init()
Initialize the page frame database.