Move VirtualMemory to AddressSpace Object
This commit is contained in:
parent
b5ad454ad1
commit
1fda0f3fae
4 changed files with 17 additions and 17 deletions
|
|
@ -1,35 +0,0 @@
|
|||
#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::AllocateUserStack() {
|
||||
return user_stacks_.NewUserStack();
|
||||
}
|
||||
|
||||
uint64_t VirtualMemory::GetNextMemMapAddr(uint64_t size) {
|
||||
uint64_t addr = next_memmap_addr_;
|
||||
next_memmap_addr_ += size;
|
||||
if (next_memmap_addr_ >= 0x30'00000000) {
|
||||
panic("OOM: Memmap");
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
uint64_t* VirtualMemory::AllocateKernelStack() {
|
||||
return gKernelStackManager->AllocateKernelStack();
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "memory/user_stack_manager.h"
|
||||
|
||||
// VirtualMemory class holds a memory space for an individual process.
|
||||
//
|
||||
// Memory Regions are predefined for simplicity for now. However, in general
|
||||
// we try not to rely on these regions being static to allow for flexibility in
|
||||
// the future.
|
||||
//
|
||||
// User Regions (Per Process):
|
||||
// 0x00000000 00000000 - 0x0000000F FFFFFFFF : USER_CODE (64 GiB)
|
||||
// 0x00000010 00000000 - 0x0000001F FFFFFFFF : USER_HEAP (64 GiB)
|
||||
// 0x00000020 00000000 - 0x0000002F FFFFFFFF : MEM_MAP (64 GiB)
|
||||
// 0x00000040 00000000 - 0x0000004F FFFFFFFF : IPC_BUF (64 GiB)
|
||||
// 0x00007FF0 00000000 - 0x00007FFF FFFFFFFF : USER_STACK (64 GiB)
|
||||
//
|
||||
// Kernel Regions (Shared across processes):
|
||||
// 0xFFFF8000 00000000 - 0xFFFF800F FFFFFFFF : HHDM (64 GiB)
|
||||
// 0xFFFFFFFF 40000000 - 0xFFFFFFFF 7FFFFFFF : KERNEL_HEAP (1 GiB)
|
||||
// 0xFFFFFFFF 80000000 - 0xFFFFFFFF 80FFFFFF : KERNEL_CODE (16 MiB)
|
||||
// 0xFFFFFFFF 90000000 - 0xFFFFFFFF 9FFFFFFF : KERNEL_STACK (256 MiB)
|
||||
class VirtualMemory {
|
||||
public:
|
||||
enum MemoryType {
|
||||
UNSPECIFIED,
|
||||
UNMAPPED,
|
||||
USER_CODE,
|
||||
USER_HEAP,
|
||||
MEM_MAP,
|
||||
IPC_BUF,
|
||||
USER_STACK,
|
||||
HHDM,
|
||||
KERNEL_HEAP,
|
||||
KERNEL_CODE,
|
||||
KERNEL_STACK,
|
||||
};
|
||||
|
||||
static VirtualMemory ForRoot();
|
||||
|
||||
VirtualMemory();
|
||||
VirtualMemory(const VirtualMemory&) = delete;
|
||||
VirtualMemory(VirtualMemory&&) = delete;
|
||||
|
||||
uint64_t cr3() { return cr3_; }
|
||||
|
||||
// User Mappings.
|
||||
uint64_t AllocateUserStack();
|
||||
uint64_t GetNextMemMapAddr(uint64_t size);
|
||||
|
||||
// Kernel Mappings.
|
||||
uint64_t* AllocateKernelStack();
|
||||
|
||||
private:
|
||||
VirtualMemory(uint64_t cr3) : cr3_(cr3) {}
|
||||
uint64_t cr3_ = 0;
|
||||
|
||||
UserStackManager user_stacks_;
|
||||
uint64_t next_memmap_addr_ = 0x20'00000000;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue