PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
#include "threads/vaddr.h"
Go to the source code of this file.
Macros | |
#define | PTSHIFT PGBITS |
Functions and macros for working with x86 hardware page tables. More... | |
#define | PTBITS 10 |
Number of page table bits. More... | |
#define | PTSPAN (1 << PTBITS << PGBITS) |
Bytes covered by a page table. More... | |
#define | PTMASK BITMASK(PTSHIFT, PTBITS) |
Page table bits (12:21). More... | |
#define | PDSHIFT (PTSHIFT + PTBITS) |
Page directory index (bits 22:31). More... | |
#define | PDBITS 10 |
Number of page dir bits. More... | |
#define | PDMASK BITMASK(PDSHIFT, PDBITS) |
Page directory bits (22:31). More... | |
#define | PTE_FLAGS 0x00000fff |
Page directory and page table entries. More... | |
#define | PTE_ADDR 0xfffff000 |
Address bits. More... | |
#define | PTE_AVL 0x00000e00 |
Bits available for OS use. More... | |
#define | PTE_P 0x1 |
1=present, 0=not present. More... | |
#define | PTE_W 0x2 |
1=read/write, 0=read-only. More... | |
#define | PTE_U 0x4 |
1=user/kernel, 0=kernel only. More... | |
#define | PTE_A 0x20 |
1=accessed, 0=not acccessed. More... | |
#define | PTE_D 0x40 |
1=dirty, 0=not dirty (PTEs only). More... | |
Functions | |
static unsigned | pt_no (const void *va) |
Obtains page table index from a virtual address. More... | |
static uintptr_t | pd_no (const void *va) |
Obtains page directory index from a virtual address. More... | |
static uint32_t | pde_create (uint32_t *pt) |
Returns a PDE that points to page table PT. More... | |
static uint32_t * | pde_get_pt (uint32_t pde) |
Returns a pointer to the page table that page directory entry PDE, which must "present", points to. More... | |
static uint32_t | pte_create_kernel (void *page, bool writable) |
Returns a PTE that points to PAGE. More... | |
static uint32_t | pte_create_user (void *page, bool writable) |
Returns a PTE that points to PAGE. More... | |
static void * | pte_get_page (uint32_t pte) |
Returns a pointer to the page that page table entry PTE points to. More... | |
#define PTE_FLAGS 0x00000fff |
Page directory and page table entries.
For more information see the section on page tables in the Pintos reference guide chapter, or [IA32-v3a] 3.7.6 "Page-Directory and Page-Table Entries".
PDEs and PTEs share a common format:
31 12 11 0 +---------------------------------—+---------------------—+ | Physical Address | Flags | +---------------------------------—+---------------------—+
In a PDE, the physical address points to a page table. In a PTE, the physical address points to a data or code page. The important flags are listed below. When a PDE or PTE is not "present", the other flags are ignored. A PDE or PTE that is initialized to 0 will be interpreted as "not present", which is just fine. Flag bits.
#define PTSHIFT PGBITS |
Functions and macros for working with x86 hardware page tables.
See vaddr.h for more generic functions and macros for virtual addresses.
Virtual addresses are structured as follows:
31 22 21 12 11 0 +-------------------—+-------------------—+-------------------—+ | Page Directory Index | Page Table Index | Page Offset | +-------------------—+-------------------—+-------------------—+ Page table index (bits 12:21). First page table bit.
|
inlinestatic |
Obtains page directory index from a virtual address.
Definition at line 37 of file pte.h.
References PDSHIFT.
Referenced by lookup_page(), pagedir_destroy(), and paging_init().
Returns a PDE that points to page table PT.
Definition at line 71 of file pte.h.
References ASSERT, pg_ofs(), PTE_P, PTE_U, PTE_W, and vtop().
Referenced by lookup_page(), and paging_init().
Returns a pointer to the page table that page directory entry PDE, which must "present", points to.
Definition at line 78 of file pte.h.
References ASSERT, PTE_ADDR, PTE_P, and ptov().
Referenced by lookup_page(), and pagedir_destroy().
|
inlinestatic |
Obtains page table index from a virtual address.
Definition at line 32 of file pte.h.
References PTMASK, and PTSHIFT.
Referenced by lookup_page(), and paging_init().
Returns a PTE that points to PAGE.
The PTE's page is readable. If WRITABLE is true then it will be writable as well. The page will be usable only by ring 0 code (the kernel).
Definition at line 87 of file pte.h.
References ASSERT, pg_ofs(), PTE_P, PTE_W, and vtop().
Referenced by paging_init(), and pte_create_user().
Returns a PTE that points to PAGE.
The PTE's page is readable. If WRITABLE is true then it will be writable as well. The page will be usable by both user and kernel code.
Definition at line 96 of file pte.h.
References pte_create_kernel(), and PTE_U.
Referenced by pagedir_set_page().
|
inlinestatic |
Returns a pointer to the page that page table entry PTE points to.
Definition at line 102 of file pte.h.
References PTE_ADDR, and ptov().
Referenced by pagedir_destroy(), and pagedir_get_page().