42 for (pte = pt; pte < pt +
PGSIZE /
sizeof *pte; pte++)
68 pde = pd +
pd_no (vaddr);
85 return &pt[
pt_no (vaddr)];
167 return pte !=
NULL && (*pte &
PTE_D) != 0;
196 return pte !=
NULL && (*pte &
PTE_A) != 0;
230 asm volatile (
"movl %0, %%cr3" : :
"r" (
vtop (pd)) :
"memory");
242 asm volatile (
"movl %%cr3, %0" :
"=r" (pd));
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
uint32_t * init_page_dir
Page directory with kernel mappings only.
bool create(const char *file, unsigned initial_size)
uint32_t init_ram_pages
Amount of physical memory, in 4 kB pages.
static uint32_t * active_pd(void)
Returns the currently active page directory.
uint32_t * pagedir_create(void)
Creates a new page directory that has mappings for kernel virtual addresses, but none for user virtua...
void pagedir_set_dirty(uint32_t *pd, const void *vpage, bool dirty)
Set the dirty bit to DIRTY in the PTE for virtual page VPAGE in PD.
bool pagedir_is_dirty(uint32_t *pd, const void *vpage)
Returns true if the PTE for virtual page VPAGE in PD is dirty, that is, if the page has been modified...
void pagedir_set_accessed(uint32_t *pd, const void *vpage, bool accessed)
Sets the accessed bit to ACCESSED in the PTE for virtual page VPAGE in PD.
static uint32_t * lookup_page(uint32_t *pd, const void *vaddr, bool create)
Returns the address of the page table entry for virtual address VADDR in page directory PD.
static void invalidate_pagedir(uint32_t *)
Seom page table changes can cause the CPU's translation lookaside buffer (TLB) to become out-of-sync ...
bool pagedir_is_accessed(uint32_t *pd, const void *vpage)
Returns true if the PTE for virtual page VPAGE in PD has been accessed recently, that is,...
void pagedir_clear_page(uint32_t *pd, void *upage)
Marks user virtual page UPAGE "not present" in page directory PD.
void * pagedir_get_page(uint32_t *pd, const void *uaddr)
Looks up the physical address that corresponds to user virtual address UADDR in PD.
bool pagedir_set_page(uint32_t *pd, void *upage, void *kpage, bool writable)
Adds a mapping in page directory PD from user virtual page UPAGE to the physical frame identified by ...
void pagedir_destroy(uint32_t *pd)
Destroys page directory PD, freeing all the pages it references.
void pagedir_activate(uint32_t *pd)
Loads page directory PD into the CPU's page directory base register.
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
void palloc_free_page(void *page)
Frees the page at PAGE.
@ PAL_ZERO
Zero page contents.
static uint32_t pte_create_user(void *page, bool writable)
Returns a PTE that points to PAGE.
#define PTSHIFT
Functions and macros for working with x86 hardware page tables.
static unsigned pt_no(const void *va)
Obtains page table index from a virtual address.
static void * pte_get_page(uint32_t pte)
Returns a pointer to the page that page table entry PTE points to.
#define PTE_P
1=present, 0=not present.
static uint32_t pde_create(uint32_t *pt)
Returns a PDE that points to page table PT.
static uintptr_t pd_no(const void *va)
Obtains page directory index from a virtual address.
#define PTE_D
1=dirty, 0=not dirty (PTEs only).
static uint32_t * pde_get_pt(uint32_t pde)
Returns a pointer to the page table that page directory entry PDE, which must "present",...
#define PTE_A
1=accessed, 0=not acccessed.
void * memcpy(void *dst_, const void *src_, size_t size)
Copies SIZE bytes from SRC to DST, which must not overlap.
static uintptr_t vtop(const void *vaddr)
Returns physical address at which kernel virtual address VADDR is mapped.
#define PGSIZE
Bytes in a page.
static bool is_user_vaddr(const void *vaddr)
Returns true if VADDR is a user virtual address.
#define PHYS_BASE
Base address of the 1:1 physical-to-virtual mapping.
static unsigned pg_ofs(const void *va)
Offset within a page.
static void * ptov(uintptr_t paddr)
Returns kernel virtual address at which physical address PADDR is mapped.