CS318 - Pintos
Pintos source browser for JHU CS318 course
Macros | Functions
vaddr.h File Reference
#include <debug.h>
#include <stdint.h>
#include <stdbool.h>
#include "threads/loader.h"
Include dependency graph for vaddr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define BITMASK(SHIFT, CNT)   (((1ul << (CNT)) - 1) << (SHIFT))
 Functions and macros for working with virtual addresses. More...
 
#define PGSHIFT   0
 Page offset (bits 0:12). More...
 
#define PGBITS   12
 Number of offset bits. More...
 
#define PGSIZE   (1 << PGBITS)
 Bytes in a page. More...
 
#define PGMASK   BITMASK(PGSHIFT, PGBITS)
 Page offset bits (0:12). More...
 
#define PHYS_BASE   ((void *) LOADER_PHYS_BASE)
 Base address of the 1:1 physical-to-virtual mapping. More...
 

Functions

static unsigned pg_ofs (const void *va)
 Offset within a page. More...
 
static uintptr_t pg_no (const void *va)
 Virtual page number. More...
 
static void * pg_round_up (const void *va)
 Round up to nearest page boundary. More...
 
static void * pg_round_down (const void *va)
 Round down to nearest page boundary. More...
 
static bool is_user_vaddr (const void *vaddr)
 Returns true if VADDR is a user virtual address. More...
 
static bool is_kernel_vaddr (const void *vaddr)
 Returns true if VADDR is a kernel virtual address. More...
 
static void * ptov (uintptr_t paddr)
 Returns kernel virtual address at which physical address PADDR is mapped. More...
 
static uintptr_t vtop (const void *vaddr)
 Returns physical address at which kernel virtual address VADDR is mapped. More...
 

Macro Definition Documentation

◆ BITMASK

#define BITMASK (   SHIFT,
  CNT 
)    (((1ul << (CNT)) - 1) << (SHIFT))

Functions and macros for working with virtual addresses.

See pte.h for functions and macros specifically for x86 hardware page tables.

Definition at line 15 of file vaddr.h.

◆ PGBITS

#define PGBITS   12

Number of offset bits.

Definition at line 19 of file vaddr.h.

◆ PGMASK

#define PGMASK   BITMASK(PGSHIFT, PGBITS)

Page offset bits (0:12).

Definition at line 21 of file vaddr.h.

◆ PGSHIFT

#define PGSHIFT   0

Page offset (bits 0:12).

Index of first offset bit.

Definition at line 18 of file vaddr.h.

◆ PGSIZE

#define PGSIZE   (1 << PGBITS)

Bytes in a page.

Definition at line 20 of file vaddr.h.

◆ PHYS_BASE

#define PHYS_BASE   ((void *) LOADER_PHYS_BASE)

Base address of the 1:1 physical-to-virtual mapping.

Physical memory is mapped starting at this virtual address. Thus, physical address 0 is accessible at PHYS_BASE, physical address address 0x1234 at (uint8_t *) PHYS_BASE + 0x1234, and so on.

This address also marks the end of user programs' address space. Up to this point in memory, user programs are allowed to map whatever they like. At this point and above, the virtual address space belongs to the kernel.

Definition at line 53 of file vaddr.h.

Function Documentation

◆ is_kernel_vaddr()

static bool is_kernel_vaddr ( const void *  vaddr)
inlinestatic

Returns true if VADDR is a kernel virtual address.

Definition at line 64 of file vaddr.h.

References PHYS_BASE.

Referenced by vtop().

Here is the caller graph for this function:

◆ is_user_vaddr()

static bool is_user_vaddr ( const void *  vaddr)
inlinestatic

Returns true if VADDR is a user virtual address.

Definition at line 57 of file vaddr.h.

References PHYS_BASE.

Referenced by lookup_page(), pagedir_clear_page(), pagedir_get_page(), pagedir_set_page(), and validate_segment().

Here is the caller graph for this function:

◆ pg_no()

static uintptr_t pg_no ( const void *  va)
inlinestatic

Virtual page number.

Definition at line 29 of file vaddr.h.

References PGBITS.

Referenced by page_from_pool(), and palloc_free_multiple().

Here is the caller graph for this function:

◆ pg_ofs()

static unsigned pg_ofs ( const void *  va)
inlinestatic

Offset within a page.

Definition at line 24 of file vaddr.h.

References PGMASK.

Referenced by block_size(), block_to_arena(), load_segment(), pagedir_clear_page(), pagedir_get_page(), pagedir_set_page(), palloc_free_multiple(), pde_create(), and pte_create_kernel().

Here is the caller graph for this function:

◆ pg_round_down()

static void* pg_round_down ( const void *  va)
inlinestatic

Round down to nearest page boundary.

Definition at line 39 of file vaddr.h.

References PGMASK.

Referenced by block_to_arena(), and running_thread().

Here is the caller graph for this function:

◆ pg_round_up()

static void* pg_round_up ( const void *  va)
inlinestatic

Round up to nearest page boundary.

Definition at line 34 of file vaddr.h.

References PGMASK, and PGSIZE.

◆ ptov()

static void* ptov ( uintptr_t  paddr)
inlinestatic

Returns kernel virtual address at which physical address PADDR is mapped.

Definition at line 72 of file vaddr.h.

References ASSERT, and PHYS_BASE.

Referenced by active_pd(), init(), paging_init(), palloc_init(), pde_get_pt(), pte_get_page(), and read_command_line().

Here is the caller graph for this function:

◆ vtop()

static uintptr_t vtop ( const void *  vaddr)
inlinestatic

Returns physical address at which kernel virtual address VADDR is mapped.

threads/vaddr.h

Definition at line 82 of file vaddr.h.

References ASSERT, is_kernel_vaddr(), and PHYS_BASE.

Referenced by pagedir_activate(), pagedir_set_page(), paging_init(), pde_create(), and pte_create_kernel().

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