UnnamedOS
vmm.c File Reference
#include <common.h>
#include <string.h>
#include <mem/vmm.h>
#include <mem/mmu.h>
#include <interrupts/isr.h>
#include <boot/multiboot.h>
+ Include dependency graph for vmm.c:

Go to the source code of this file.

Data Structures

struct  vmm_domain_t
 We use two domains, kernel and user memory. More...
 
union  vmm_virtual_address_t
 A virtual address. More...
 

Macros

#define ENTRIES   1024
 number of entries in page directories and tables
 
#define PAGE_SIZE   (ENTRIES * sizeof(page_directory_entry_t))
 The number of bytes per page directory "happens" to equal the size of a page.
 
#define MEMORY_SIZE   0x100000000
 4GB address space
 
#define PAGE_NUMBER   (MEMORY_SIZE / PAGE_SIZE)
 total number of pages
 

Functions

static void vmm_destroy_page_table (uint16_t page_table)
 Destroys a page table in the current page directory. More...
 
page_directory_tvmm_create_page_directory ()
 Creates an empty page directory. More...
 
void vmm_destroy_page_directory (page_directory_t *dir_phys)
 Destroys a page directory. More...
 
static void vmm_refresh_page_directory (page_directory_t *dir_phys)
 Refreshes the page directory entries that are shared across page directories. More...
 
page_directory_tvmm_load_page_directory (page_directory_t *new_directory)
 Loads a new page directory. More...
 
void vmm_modify_page_directory (page_directory_t *new_directory)
 Loads a page directory for temporary modification. More...
 
void vmm_modified_page_directory ()
 Ends a page directory modification. More...
 
static page_table_entry_tvmm_get_page_table (page_directory_entry_t *dir_entry, vmm_virtual_address_t vaddr)
 Returns a virtual or physical address to a page table in memory. More...
 
static page_table_entry_tvmm_get_page_table_entry (page_directory_entry_t *dir_entry, vmm_virtual_address_t vaddr)
 Returns a virtual or physical address to a page table entry in memory. More...
 
static vmm_domain_tvmm_get_domain (vmm_flags_t flags)
 Extracts a domain from the given flags. More...
 
static uint8_t vmm_is_in_domain (void *vaddr, vmm_domain_t *domain)
 Returns whether a virtual address belongs to a given domain. More...
 
static vmm_domain_tvmm_get_domain_from_address (void *vaddr)
 Returns the domain a virtual address belongs to. More...
 
static uint8_t vmm_domain_check (void *vaddr, vmm_flags_t flags)
 Checks whether a virtual address might be accessed with the given flags. More...
 
uint8_t vmm_map (void *_vaddr, void *paddr, vmm_flags_t flags)
 Maps the given page into memory. More...
 
void vmm_unmap (void *_vaddr)
 Unmaps the given page from memory. More...
 
static void vmm_map_range_detailed (void *vaddr, void *paddr, size_t len, vmm_flags_t flags, uint8_t map)
 Maps or unmaps the given page(s) into memory. More...
 
void vmm_map_range (void *vaddr, void *paddr, size_t len, vmm_flags_t flags)
 Maps the given page(s) into memory. More...
 
void vmm_unmap_range (void *vaddr, size_t len)
 Unmaps the given page(s) from memory. More...
 
void * vmm_get_physical_address (void *_vaddr)
 Translates a virtual address into a physical address. More...
 
void vmm_dump ()
 Dumps the current page directory. More...
 
static void * vmm_find_free (size_t len, vmm_domain_t *domain)
 Finds unmapped pages. More...
 
static pmm_flags_t vmm_get_pmm_flags (vmm_flags_t flags)
 Translates VMM into PMM flags. More...
 
void * vmm_map_physical_memory (void *paddr, size_t len, vmm_flags_t flags)
 If necessary, maps the given page(s) somewhere into memory. More...
 
void vmm_unmap_physical_memory (void *vaddr, size_t len)
 If necessary, unmaps the given page(s) from memory. More...
 
void vmm_use (void *vaddr, void *paddr, size_t len, vmm_flags_t flags)
 Marks the given page(s) as used and maps them into memory. More...
 
void * vmm_use_physical_memory (void *paddr, size_t len, vmm_flags_t flags)
 Marks the given page(s) as used and maps them somewhere into memory. More...
 
void * vmm_use_virtual_memory (void *vaddr, size_t len, vmm_flags_t flags)
 Marks some page(s) as used and maps them into memory. More...
 
void * vmm_alloc (size_t len, vmm_flags_t flags)
 Marks some page(s) as used and maps them somewhere into memory. More...
 
void vmm_free (void *vaddr, size_t len)
 Frees the given page(s) and unmaps them from memory. More...
 
void vmm_enable_domain_check (uint8_t enable)
 Enables or disables domain checking. More...
 
void vmm_init ()
 Initializes the VMM. More...
 

Variables

static page_directory_tpage_directory = 0
 the current page directory
 
static page_directory_told_directory = 0
 for temporary modifications
 
static uint8_t old_interrupts = 0
 for temporary modifications
 
static vmm_domain_t kernel_domain
 We use 0-1GiB as kernel memory. More...
 
static vmm_domain_t user_domain
 The memory 1GiB-4GiB is process-specific. More...
 
static uint8_t domain_check_enabled = 0
 whether domain checking is performed