LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
vmm.h
Go to the documentation of this file.
1
9
10#ifndef KERNEl_MM_VMM_H
11#define KERNEl_MM_VMM_H
12
13#include <stdint.h>
14
15#define VMM_TEST_BASE 0xFFFFC00000000000ULL // PML4 slot 384: unused by Limine (verify!)
16
18struct vmm_region {
20 uint64_t start;
22 uint64_t end;
24 uint64_t flags;
25};
26
30 uint64_t pml4_phys;
34 uint64_t region_count;
35};
36
41uint64_t get_kernel_pml4_phys(void);
42
46void vmm_init(void);
47
54void vmm_add_region(uint64_t start, uint64_t end, uint64_t flags);
55
64uint64_t vmm_map(uint64_t pml4_phys, uint64_t virtual_address, uint64_t physical_address, uint64_t flags);
65
72uint64_t vmm_unmap(uint64_t pml4_phys, uint64_t virtual_address);
73
80bool vmm_page_fault_handler(uint64_t fault_address, uint64_t error_code);
81
86inline void invlpg(void *virt)
87{
88 asm volatile("invlpg (%0)" ::"r"(virt) : "memory");
89}
90
91#endif
Represents an address space.
Definition vmm.h:28
uint64_t pml4_phys
physical address of the top-level table
Definition vmm.h:30
uint64_t region_count
number of regions in the address space
Definition vmm.h:34
struct vmm_region regions[8]
lazily mapped regions (demand paging)
Definition vmm.h:32
Represents a virtual memory region.
Definition vmm.h:18
uint64_t flags
PTE flags to use when a page of the region is mapped.
Definition vmm.h:24
uint64_t end
one past the last byte (4 KiB aligned)
Definition vmm.h:22
uint64_t start
first virtual address of the region (4 KiB aligned)
Definition vmm.h:20
void vmm_init(void)
Initialize the virtual memory manager and the kernel address space.
Definition vmm.c:24
uint64_t vmm_unmap(uint64_t pml4_phys, uint64_t virtual_address)
Unmaps a virtual address in the given address space.
Definition vmm.c:116
void vmm_add_region(uint64_t start, uint64_t end, uint64_t flags)
Add a region to the kernel address space.
Definition vmm.c:33
void invlpg(void *virt)
Invalidate a virtual address in the given address space.
Definition vmm.h:86
uint64_t get_kernel_pml4_phys(void)
Returns the physical address of the top-level table.
Definition vmm.c:19
bool vmm_page_fault_handler(uint64_t fault_address, uint64_t error_code)
Handles a page fault in the given address space (demand paging).
Definition vmm.c:163
uint64_t vmm_map(uint64_t pml4_phys, uint64_t virtual_address, uint64_t physical_address, uint64_t flags)
Maps a virtual address to a physical address in the given address space.
Definition vmm.c:47