Paged memory management. More...
#include <core.h>
Go to the source code of this file.
Data Structures | |
union | page_t |
A pagetable page record. More... | |
struct | pagetable_t |
A pagetable structure. More... | |
Macros | |
#define | PAGE_SIZE 0x1000 |
#define | PAGE_SIZE_LARGE 0x200000 |
#define | PAGE_SIZE_HUGE 0x40000000 |
#define | PF_PRESENT (1 << 0) |
#define | PF_RW (1 << 1) |
#define | PF_USER (1 << 2) |
#define | PF_PWT (1 << 3) |
#define | PF_PCD (1 << 4) |
#define | PF_ACCESS (1 << 5) |
#define | PF_DIRTY (1 << 6) |
#define | PF_PS (1 << 7) |
#define | PF_GLOBAL (1 << 8) |
#define | PF_SYSTEM (1 << 9) |
#define | PGSHIFT_PML4E 39 |
#define | PGSHIFT_PDPTE 30 |
#define | PGSHIFT_PDE 21 |
#define | PGSHIFT_PTE 12 |
#define | PGMASK_ENTRY 0x1ff |
#define | PGMASK_OFFSET 0x3ff |
#define | PML4E(a) (((a) >> PGSHIFT_PML4E) & PGMASK_ENTRY) |
#define | PDPTE(a) (((a) >> PGSHIFT_PDPTE) & PGMASK_ENTRY) |
#define | PDE(a) (((a) >> PGSHIFT_PDE) & PGMASK_ENTRY) |
#define | PTE(a) (((a) >> PGSHIFT_PTE) & PGMASK_ENTRY) |
#define | PGPTR(pte) ((page_t *)((pte) & ~PGMASK_OFFSET)) |
Functions | |
void | page_init () |
Initialize the page frame database. More... | |
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. More... | |
void | pagetable_destroy (pagetable_t *pt) |
Destroy a page table. More... | |
void | pagetable_activate (pagetable_t *pt) |
Activate a page table on the CPU, so all virtual memory operations are performed relative to the page table. More... | |
void * | page_alloc (pagetable_t *pt, void *vaddr, int count) |
Allocate one or more pages contiguous in virtual memory. More... | |
void | page_free (pagetable_t *pt, void *vaddr, int count) |
Free one or more contiguous pages from virtual memory. More... | |
Paged memory management.
Definition in file paging.h.
union page_t |
struct pagetable_t |
A pagetable structure.
Holds all the page table entries that map virtual addresses to physical addresses.
#define PAGE_SIZE 0x1000 |
Definition at line 15 of file paging.h.
Referenced by acpi_init(), add_pte(), alloc_page(), cmd_test_heap(), grow_heap(), heap_create(), kmem_init(), map_range(), map_region(), next_fblock(), next_fblock_adj(), page_alloc(), page_free(), page_init(), pagetable_create(), pagetable_destroy(), and pgalloc().
#define PAGE_SIZE_LARGE 0x200000 |
Definition at line 16 of file paging.h.
Referenced by map_region(), and page_init().
#define PAGE_SIZE_HUGE 0x40000000 |
Definition at line 17 of file paging.h.
Referenced by map_region().
#define PF_PRESENT (1 << 0) |
Definition at line 20 of file paging.h.
Referenced by add_pte(), alloc_page(), get_pdflags(), get_ptflags(), map_table(), and page_alloc().
#define PF_RW (1 << 1) |
Definition at line 21 of file paging.h.
Referenced by add_pte(), alloc_page(), get_pdflags(), get_ptflags(), map_table(), and page_alloc().
#define PF_PWT (1 << 3) |
Definition at line 23 of file paging.h.
Referenced by get_pdflags(), and get_ptflags().
#define PF_PCD (1 << 4) |
Definition at line 24 of file paging.h.
Referenced by get_pdflags(), and get_ptflags().
#define PF_PS (1 << 7) |
Definition at line 27 of file paging.h.
Referenced by get_pdflags(), and is_mapped().
#define PF_GLOBAL (1 << 8) |
Definition at line 28 of file paging.h.
Referenced by get_pdflags(), and get_ptflags().
#define PF_SYSTEM (1 << 9) |
Definition at line 29 of file paging.h.
Referenced by add_pte(), alloc_page(), get_pdflags(), get_ptflags(), and pgfree_recurse().
#define PML4E | ( | a | ) | (((a) >> PGSHIFT_PML4E) & PGMASK_ENTRY) |
Definition at line 40 of file paging.h.
Referenced by add_pte(), create_huge_page(), create_large_page(), create_page(), create_small_page(), is_mapped(), and remove_pte().
#define PDPTE | ( | a | ) | (((a) >> PGSHIFT_PDPTE) & PGMASK_ENTRY) |
Definition at line 41 of file paging.h.
Referenced by add_pte(), create_huge_page(), create_large_page(), create_page(), create_small_page(), is_mapped(), and remove_pte().
#define PDE | ( | a | ) | (((a) >> PGSHIFT_PDE) & PGMASK_ENTRY) |
Definition at line 42 of file paging.h.
Referenced by add_pte(), create_large_page(), create_page(), create_small_page(), is_mapped(), and remove_pte().
#define PTE | ( | a | ) | (((a) >> PGSHIFT_PTE) & PGMASK_ENTRY) |
Definition at line 43 of file paging.h.
Referenced by add_pte(), create_page(), create_small_page(), is_mapped(), and remove_pte().
#define PGPTR | ( | pte | ) | ((page_t *)((pte) & ~PGMASK_OFFSET)) |
Definition at line 46 of file paging.h.
Referenced by add_pte(), create_huge_page(), create_large_page(), create_page(), create_small_page(), is_mapped(), pgfree_recurse(), and remove_pte().
void page_init | ( | ) |
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.
The page table includes protected mappings for kernel memory.
[in] | pt | A pointer to the pagetable structure that will hold the page table. |
[in] | vaddr | The virtual address within the new page table where the page table will be mapped. |
[in] | size | Maximum size of the page table in bytes. Must be a multiple of PAGE_SIZE. |
Definition at line 364 of file paging.c.
Referenced by cmd_test_heap().
void pagetable_destroy | ( | pagetable_t * | pt | ) |
Destroy a page table.
[in] | pt | A handle to the page table to destroy. |
Definition at line 383 of file paging.c.
Referenced by cmd_test_heap().
void pagetable_activate | ( | pagetable_t * | pt | ) |
Activate a page table on the CPU, so all virtual memory operations are performed relative to the page table.
[in] | pt | A handle to the activated page table. Pass NULL to activate the kernel page table. |
Definition at line 403 of file paging.c.
Referenced by cmd_test_heap().
void* page_alloc | ( | pagetable_t * | pt, |
void * | vaddr, | ||
int | count | ||
) |
Allocate one or more pages contiguous in virtual memory.
[in] | pt | Handle to the page table from which to allocate the page(s). |
[in] | vaddr | The virtual address of the first allocated page. |
[in] | count | The number of contiguous virtual memory pages to allocate. |
Definition at line 415 of file paging.c.
Referenced by grow_heap(), and heap_create().
void page_free | ( | pagetable_t * | pt, |
void * | vaddr, | ||
int | count | ||
) |
Free one or more contiguous pages from virtual memory.
[in] | pt | Handle to ehte page table from which to free the page(s). |
[in] | vaddr | The virtual address of the first allocated page. |
[in] | count | The number of contiguous virtual memory pages to free. |
Definition at line 425 of file paging.c.
Referenced by heap_destroy().