MentOS  0.8.0
The Mentoring Operating System
Macros | Functions | Variables
vmem_map.c File Reference

Virtual memory mapping routines. More...

Macros

#define __DEBUG_HEADER__   "[VMEM ]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 
#define VIRTUAL_MEMORY_PAGES_COUNT   (VIRTUAL_MEMORY_SIZE_MB * 256)
 Number of virtual memory pages.
 
#define VIRTUAL_MAPPING_BASE   (PROCAREA_END_ADDR + 0x38000000)
 Base address for virtual memory mapping.
 
#define VIRT_PAGE_TO_ADDRESS(page)   ((((page) - virt_pages) * PAGE_SIZE) + VIRTUAL_MAPPING_BASE)
 Converts a virtual page to its address.
 
#define VIRT_ADDRESS_TO_PAGE(addr)   ((((addr) - VIRTUAL_MAPPING_BASE) / PAGE_SIZE) + virt_pages)
 Converts an address to its corresponding virtual page.
 

Functions

int virt_init (void)
 Initialize the virtual memory mapper. More...
 
static virt_map_page_t_alloc_virt_pages (uint32_t pfn_count)
 Allocates a virtual page, given the page frame count. More...
 
uint32_t virt_map_physical_pages (page_t *page, int pfn_count)
 Maps physical pages to virtual memory. More...
 
virt_map_page_tvirt_map_alloc (uint32_t size)
 Allocates virtual pages for a given size. More...
 
uint32_t virt_map_vaddress (mm_struct_t *mm, virt_map_page_t *vpage, uint32_t vaddr, uint32_t size)
 Maps a virtual address to a virtual memory area. More...
 
int virtual_check_address (uint32_t addr)
 Checks if an address belongs to the virtual memory mapping. More...
 
int virt_unmap (uint32_t addr)
 Unmaps a virtual address from the virtual memory. More...
 
int virt_unmap_pg (virt_map_page_t *page)
 Unmap a page. More...
 
void virt_memcpy (mm_struct_t *dst_mm, uint32_t dst_vaddr, mm_struct_t *src_mm, uint32_t src_vaddr, uint32_t size)
 Memcpy from different processes virtual addresses. More...
 

Variables

static virt_map_page_manager_t virt_default_mapping
 Virtual addresses manager.
 
virt_map_page_t virt_pages [VIRTUAL_MEMORY_PAGES_COUNT]
 Array of virtual pages.
 

Detailed Description

Virtual memory mapping routines.

Function Documentation

◆ _alloc_virt_pages()

static virt_map_page_t* _alloc_virt_pages ( uint32_t  pfn_count)
static

Allocates a virtual page, given the page frame count.

Parameters
pfn_countthe page frame count.
Returns
pointer to the virtual page.

◆ virt_init()

int virt_init ( void  )

Initialize the virtual memory mapper.

Returns
Returns 0 on success, or -1 if an error occurs.

◆ virt_map_alloc()

virt_map_page_t* virt_map_alloc ( uint32_t  size)

Allocates virtual pages for a given size.

Parameters
sizeThe size in bytes to allocate.
Returns
Pointer to the allocated virtual pages, or NULL on failure.

◆ virt_map_physical_pages()

uint32_t virt_map_physical_pages ( page_t page,
int  pfn_count 
)

Maps physical pages to virtual memory.

Parameters
pagePointer to the physical page.
pfn_countThe number of page frames to map.
Returns
The virtual address of the mapped pages, or 0 on failure.

◆ virt_map_vaddress()

uint32_t virt_map_vaddress ( mm_struct_t mm,
virt_map_page_t vpage,
uint32_t  vaddr,
uint32_t  size 
)

Maps a virtual address to a virtual memory area.

Parameters
mmPointer to the memory management structure.
vpagePointer to the virtual map page.
vaddrThe virtual address to map.
sizeThe size of the memory area to map.
Returns
The starting virtual address of the mapped area, or 0 on failure.

◆ virt_memcpy()

void virt_memcpy ( mm_struct_t dst_mm,
uint32_t  dst_vaddr,
mm_struct_t src_mm,
uint32_t  src_vaddr,
uint32_t  size 
)

Memcpy from different processes virtual addresses.

Parameters
dst_mmThe destination memory struct
dst_vaddrThe destination memory address
src_mmThe source memory struct
src_vaddrThe source memory address
sizeThe size in bytes of the copy

◆ virt_unmap()

int virt_unmap ( uint32_t  addr)

Unmaps a virtual address from the virtual memory.

Parameters
addrThe virtual address to unmap.
Returns
Returns 0 on success, or -1 if an error occurs.

◆ virt_unmap_pg()

int virt_unmap_pg ( virt_map_page_t page)

Unmap a page.

Parameters
pagePointer to the page to unmap.
Returns
Returns 0 on success, or -1 if an error occurs.

◆ virtual_check_address()

int virtual_check_address ( uint32_t  addr)

Checks if an address belongs to the virtual memory mapping.

Parameters
addrThe address to check.
Returns
1 if it belongs to the virtual memory mapping, 0 otherwise.