Luna/kernel/include/memory/VMM.h

45 lines
1.4 KiB
C
Raw Normal View History

2022-09-05 14:13:51 +00:00
#pragma once
2022-10-13 17:19:51 +00:00
#include "memory/AddressSpace.h"
2022-09-05 14:13:51 +00:00
#include "memory/Paging.h"
enum Flags
2022-09-05 14:13:51 +00:00
{
ReadWrite = 1 << 0,
User = 1 << 1,
Execute = 1 << 2
};
namespace VMM
{
2022-10-13 16:42:53 +00:00
void init(); // Fetch page table from cr3
2022-09-05 14:13:51 +00:00
void switch_to_user_address_space(AddressSpace& space);
2022-10-13 19:55:51 +00:00
void switch_to_previous_user_address_space();
void switch_back_to_kernel_address_space();
2022-10-13 19:55:51 +00:00
void enter_syscall_context();
void exit_syscall_context();
void apply_address_space();
bool is_using_kernel_address_space();
2022-10-13 16:42:53 +00:00
void map(uint64_t vaddr, uint64_t paddr, int flags);
void remap(uint64_t vaddr, int flags);
void unmap(uint64_t vaddr);
uint64_t get_physical(uint64_t vaddr);
uint64_t get_flags(uint64_t vaddr);
2022-09-06 11:49:17 +00:00
2022-10-13 16:42:53 +00:00
PageDirectoryEntry* find_pde(PageTable* root, uint64_t vaddr);
PageDirectoryEntry* create_pde_if_not_exists(PageTable* root, uint64_t vaddr);
2022-10-13 16:42:53 +00:00
void propagate_read_write(PageTable* root, uint64_t vaddr);
void propagate_user(PageTable* root, uint64_t vaddr);
void flush_tlb(uint64_t addr);
2022-10-13 16:15:52 +00:00
void decompose_vaddr(uint64_t vaddr, uint64_t& page_index, uint64_t& pt_index, uint64_t& pd_index,
uint64_t& pdp_index);
uint64_t recompose_vaddr(uint64_t page_index, uint64_t pt_index, uint64_t pd_index, uint64_t pdp_index);
2022-10-13 17:19:51 +00:00
void install_kernel_page_directory_into_address_space(AddressSpace& space);
};