Move PML4 initialization into the VirtualMemory class.
This commit is contained in:
parent
f22dd66c8d
commit
1db93e5b12
11 changed files with 39 additions and 25 deletions
|
|
@ -174,15 +174,15 @@ void EnsureResident(uint64_t addr, uint64_t size) {
|
|||
}
|
||||
}
|
||||
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size, uint64_t dest_cr3,
|
||||
uint64_t dest_virt) {
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt) {
|
||||
if (size > 0x1000) {
|
||||
panic("Unimplemented NR copy > 1 page");
|
||||
}
|
||||
if (dest_virt & 0xFFF) {
|
||||
panic("Unimplemented NR copy to non page aligned");
|
||||
}
|
||||
uint64_t phys = AllocatePageIfNecessary(dest_virt, dest_cr3);
|
||||
uint64_t phys = AllocatePageIfNecessary(dest_virt, dest_proc.vmm().cr3());
|
||||
uint8_t* src = reinterpret_cast<uint8_t*>(base);
|
||||
uint8_t* dest =
|
||||
reinterpret_cast<uint8_t*>(phys + boot::GetHigherHalfDirectMap());
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "scheduler/process.h"
|
||||
|
||||
void InitializePml4(uint64_t pml4_physical_addr);
|
||||
|
||||
uint64_t AllocatePageIfNecessary(uint64_t addr, uint64_t cr3 = 0);
|
||||
void EnsureResident(uint64_t addr, uint64_t size);
|
||||
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size, uint64_t dest_cr3,
|
||||
uint64_t dest_virt);
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,22 @@
|
|||
#include "memory/virtual_memory.h"
|
||||
|
||||
#include "memory/kernel_stack_manager.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "memory/physical_memory.h"
|
||||
|
||||
extern KernelStackManager* gKernelStackManager;
|
||||
|
||||
VirtualMemory VirtualMemory::ForRoot() {
|
||||
uint64_t cr3 = 0;
|
||||
asm volatile("mov %%cr3, %0;" : "=r"(cr3));
|
||||
return {cr3};
|
||||
}
|
||||
|
||||
VirtualMemory::VirtualMemory() {
|
||||
cr3_ = phys_mem::AllocatePage();
|
||||
InitializePml4(cr3_);
|
||||
}
|
||||
|
||||
uint64_t* VirtualMemory::AllocateKernelStack() {
|
||||
return gKernelStackManager->AllocateKernelStack();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,16 +38,21 @@ class VirtualMemory {
|
|||
KERNEL_STACK,
|
||||
};
|
||||
|
||||
VirtualMemory() {}
|
||||
static VirtualMemory ForRoot();
|
||||
|
||||
VirtualMemory();
|
||||
VirtualMemory(const VirtualMemory&) = delete;
|
||||
VirtualMemory(VirtualMemory&&) = delete;
|
||||
|
||||
uint64_t cr3() { return cr3_; }
|
||||
|
||||
uint64_t GetNextMemMapAddr(uint64_t size);
|
||||
|
||||
// Kernel
|
||||
uint64_t* AllocateKernelStack();
|
||||
|
||||
private:
|
||||
VirtualMemory(uint64_t cr3) : cr3_(cr3) {}
|
||||
uint64_t cr3_ = 0;
|
||||
|
||||
uint64_t next_memmap_addr_ = 0x20'00000000;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue