PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions
pte.h File Reference
#include "threads/vaddr.h"
Include dependency graph for pte.h:
This graph shows which files directly or indirectly include this file:

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_tpde_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...
 

Macro Definition Documentation

◆ PDBITS

#define PDBITS   10

Number of page dir bits.

Definition at line 28 of file pte.h.

◆ PDMASK

#define PDMASK   BITMASK(PDSHIFT, PDBITS)

Page directory bits (22:31).

Definition at line 29 of file pte.h.

◆ PDSHIFT

#define PDSHIFT   (PTSHIFT + PTBITS)

Page directory index (bits 22:31).

First page directory bit.

Definition at line 27 of file pte.h.

◆ PTBITS

#define PTBITS   10

Number of page table bits.

Definition at line 22 of file pte.h.

◆ PTE_A

#define PTE_A   0x20

1=accessed, 0=not acccessed.

Definition at line 67 of file pte.h.

◆ PTE_ADDR

#define PTE_ADDR   0xfffff000

Address bits.

Definition at line 62 of file pte.h.

◆ PTE_AVL

#define PTE_AVL   0x00000e00

Bits available for OS use.

Definition at line 63 of file pte.h.

◆ PTE_D

#define PTE_D   0x40

1=dirty, 0=not dirty (PTEs only).

Definition at line 68 of file pte.h.

◆ PTE_FLAGS

#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.

Definition at line 61 of file pte.h.

◆ PTE_P

#define PTE_P   0x1

1=present, 0=not present.

Definition at line 64 of file pte.h.

◆ PTE_U

#define PTE_U   0x4

1=user/kernel, 0=kernel only.

Definition at line 66 of file pte.h.

◆ PTE_W

#define PTE_W   0x2

1=read/write, 0=read-only.

Definition at line 65 of file pte.h.

◆ PTMASK

#define PTMASK   BITMASK(PTSHIFT, PTBITS)

Page table bits (12:21).

Definition at line 24 of file pte.h.

◆ PTSHIFT

#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.

Definition at line 21 of file pte.h.

◆ PTSPAN

#define PTSPAN   (1 << PTBITS << PGBITS)

Bytes covered by a page table.

Definition at line 23 of file pte.h.

Function Documentation

◆ pd_no()

static uintptr_t pd_no ( const void *  va)
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().

Here is the caller graph for this function:

◆ pde_create()

static uint32_t pde_create ( uint32_t pt)
inlinestatic

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pde_get_pt()

static uint32_t * pde_get_pt ( uint32_t  pde)
inlinestatic

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pt_no()

static unsigned pt_no ( const void *  va)
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().

Here is the caller graph for this function:

◆ pte_create_kernel()

static uint32_t pte_create_kernel ( void *  page,
bool  writable 
)
inlinestatic

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_create_user()

static uint32_t pte_create_user ( void *  page,
bool  writable 
)
inlinestatic

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pte_get_page()

static void * pte_get_page ( uint32_t  pte)
inlinestatic

Returns a pointer to the page that page table entry PTE points to.

threads/pte.h

Definition at line 102 of file pte.h.

References PTE_ADDR, and ptov().

Referenced by pagedir_destroy(), and pagedir_get_page().

Here is the call graph for this function:
Here is the caller graph for this function: