os/kernel/cpu/paging.h

90 lines
2.6 KiB
C
Raw Normal View History

2020-07-25 16:54:37 -05:00
/**
* \file
*/
2019-02-09 12:52:45 -06:00
#ifndef PAGING_H
#define PAGING_H
/**
* Run a block of code in a different address space
* \param addr_space the address space to use
* \param codeblock the block of code to run
*/
#define RUN_IN_ADDRESS_SPACE(addr_space,codeblock) do { \
void* old_address_space=get_address_space(); \
load_address_space(addr_space); \
codeblock; \
load_address_space(old_address_space); \
} while(0);
2020-07-25 16:54:37 -05:00
/**
* Map virtual pages to physical frames.
* \param virt_addr_ptr The start of the virtual range to map.
* \param phys_addr_ptr The start of the physical range to map.
* \param num_pages The number of pages to map.
* \param usr Are the pages acessible by user mode code
* \param wr Are the pages writable by user mode code (kernel always has write permissions)
*/
2019-03-11 09:32:55 -05:00
void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,char wr);
2020-07-25 16:54:37 -05:00
/**
* Unmap virtual pages,
* \param start_virt The start of the virtual range to unmap.
* \param num_pages The number of pages to map.
*/
2020-07-23 11:50:23 -05:00
void unmap_pages(void* start_virt,int num_pages);
2020-07-25 16:54:37 -05:00
/**
* Allocate virtual pages & map them to newly allocated physical memory.
2020-07-25 16:54:37 -05:00
* \param num_pages The number of pages to allocate.
* \return a pointer to the allocated pages.
*/
2019-03-11 09:32:55 -05:00
void* alloc_pages(int num_pages);
2020-07-25 16:54:37 -05:00
/**
* Allocate virtual pages at a specific address & map them to newly allocated physical memory.
2020-07-25 16:54:37 -05:00
* \param num_pages The number of pages to allocate.
* \param addr The adress to start allocation at.
*/
2019-03-11 09:32:55 -05:00
void alloc_pages_virt(int num_pages,void* addr);
/**
* Deallocate the physical memory for pages and unmap them
* \param num_pages The number of pages to deallocate.
* \param addr The adress to start deallocation at.
*/
void dealloc_pages(int num_pages,void* addr);
2020-07-25 16:54:37 -05:00
/**
* Initialize paging
*/
2019-02-09 13:05:13 -06:00
void paging_init();
2020-07-25 16:54:37 -05:00
/**
* Create a new address space
* \return a pointer to the new address space in physical memory.
*/
2019-05-05 13:14:14 -05:00
void* paging_new_address_space();
2020-07-25 16:54:37 -05:00
/**
* Load an address space
* \param address_space The address space to load
2020-07-25 16:54:37 -05:00
*/
void load_address_space(void* address_space);
2020-07-25 16:54:37 -05:00
/**
* Convert a virtual address to a physical one.
* \param virt_addr The virtual address to convert
* \return the physical adress it maps to, or NULL if it is not mapped.
*/
2019-05-04 10:42:17 -05:00
void* virt_to_phys(void* virt_addr);
2020-07-25 16:54:37 -05:00
/**
* Finds free virtual pages and returns the start address
* \param num_pages The minimum size of the free area
* \return the start of the free area
*/
void* find_free_pages(int num_pages);
2020-07-25 16:54:37 -05:00
/**
* Get the current address space
* \return a pointer to the current address space in physical memory.
*/
void* get_address_space();
2019-05-04 10:52:38 -05:00
2019-02-09 12:52:45 -06:00
#endif