MyOS Kernel
paging.h File Reference
#include <stddef.h>

Go to the source code of this file.

Macros

#define RUN_IN_ADDRESS_SPACE(addr_space, codeblock)
 

Functions

void map_pages (void *virt_addr_ptr, void *phys_addr_ptr, int num_pages, char usr, char wr)
 
void unmap_pages (void *start_virt, int num_pages, int free_phys)
 
void * alloc_pages (int num_pages)
 
void alloc_pages_virt (int num_pages, void *addr)
 
void dealloc_pages (int num_pages, void *addr)
 
void paging_init ()
 
void * paging_new_address_space ()
 
void load_address_space (void *address_space)
 
void * virt_to_phys (void *virt_addr)
 
void * find_free_pages (int num_pages)
 
void * get_address_space ()
 
char is_page_present (size_t page)
 

Macro Definition Documentation

◆ RUN_IN_ADDRESS_SPACE

#define RUN_IN_ADDRESS_SPACE (   addr_space,
  codeblock 
)
Value:
do { \
void* old_address_space=get_address_space(); \
load_address_space(addr_space); \
codeblock; \
load_address_space(old_address_space); \
} while(0);

Run a block of code in a different address space

Parameters
addr_spacethe address space to use
codeblockthe block of code to run

Function Documentation

◆ alloc_pages()

void* alloc_pages ( int  num_pages)

Allocate virtual pages & map them to newly allocated physical memory.

Parameters
num_pagesThe number of pages to allocate.
Returns
a pointer to the allocated pages.

◆ alloc_pages_virt()

void alloc_pages_virt ( int  num_pages,
void *  addr 
)

Allocate virtual pages at a specific address & map them to newly allocated physical memory.

Parameters
num_pagesThe number of pages to allocate.
addrThe adress to start allocation at.

◆ dealloc_pages()

void dealloc_pages ( int  num_pages,
void *  addr 
)

Deallocate the physical memory for pages and unmap them

Parameters
num_pagesThe number of pages to deallocate.
addrThe adress to start deallocation at.

◆ find_free_pages()

void* find_free_pages ( int  num_pages)

Finds free virtual pages and returns the start address

Parameters
num_pagesThe minimum size of the free area
Returns
the start of the free area

◆ get_address_space()

void* get_address_space ( )

Get the current address space

Returns
a pointer to the current address space in physical memory.

◆ is_page_present()

char is_page_present ( size_t  page)

Checks whether a page is present

Parameters
pageThe page number to check
Returns
Whether the page is present

◆ load_address_space()

void load_address_space ( void *  address_space)

Load an address space

Parameters
address_spaceThe address space to load

◆ map_pages()

void map_pages ( void *  virt_addr_ptr,
void *  phys_addr_ptr,
int  num_pages,
char  usr,
char  wr 
)

Map virtual pages to physical frames.

Parameters
virt_addr_ptrThe start of the virtual range to map.
phys_addr_ptrThe start of the physical range to map.
num_pagesThe number of pages to map.
usrAre the pages acessible by user mode code
wrAre the pages writable by user mode code (kernel always has write permissions)

◆ paging_init()

void paging_init ( )

Initialize paging

◆ paging_new_address_space()

void* paging_new_address_space ( )

Create a new address space

Returns
a pointer to the new address space in physical memory.

◆ unmap_pages()

void unmap_pages ( void *  start_virt,
int  num_pages,
int  free_phys 
)

Unmap virtual pages,

Parameters
start_virtThe start of the virtual range to unmap.
num_pagesThe number of pages to map.
free_physAlso free the physical pages the virtual pages are mapped to.

◆ virt_to_phys()

void* virt_to_phys ( void *  virt_addr)

Convert a virtual address to a physical one.

Parameters
virt_addrThe virtual address to convert
Returns
the physical adress it maps to, or NULL if it is not mapped.
get_address_space
void * get_address_space()
Definition: paging.c:231