Move VirtualMemory to AddressSpace Object
This commit is contained in:
parent
b5ad454ad1
commit
1fda0f3fae
|
@ -14,9 +14,9 @@ add_executable(zion
|
|||
memory/paging_util.cpp
|
||||
memory/physical_memory.cpp
|
||||
memory/user_stack_manager.cpp
|
||||
memory/virtual_memory.cpp
|
||||
object/process.cpp
|
||||
object/thread.cpp
|
||||
object/address_space.cpp
|
||||
scheduler/context_switch.s
|
||||
scheduler/jump_user_space.s
|
||||
scheduler/process_manager.cpp
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "memory/virtual_memory.h"
|
||||
#include "object/address_space.h"
|
||||
|
||||
#include "memory/kernel_stack_manager.h"
|
||||
#include "memory/paging_util.h"
|
||||
|
@ -6,22 +6,22 @@
|
|||
|
||||
extern KernelStackManager* gKernelStackManager;
|
||||
|
||||
VirtualMemory VirtualMemory::ForRoot() {
|
||||
AddressSpace AddressSpace::ForRoot() {
|
||||
uint64_t cr3 = 0;
|
||||
asm volatile("mov %%cr3, %0;" : "=r"(cr3));
|
||||
return {cr3};
|
||||
}
|
||||
|
||||
VirtualMemory::VirtualMemory() {
|
||||
AddressSpace::AddressSpace() {
|
||||
cr3_ = phys_mem::AllocatePage();
|
||||
InitializePml4(cr3_);
|
||||
}
|
||||
|
||||
uint64_t VirtualMemory::AllocateUserStack() {
|
||||
uint64_t AddressSpace::AllocateUserStack() {
|
||||
return user_stacks_.NewUserStack();
|
||||
}
|
||||
|
||||
uint64_t VirtualMemory::GetNextMemMapAddr(uint64_t size) {
|
||||
uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) {
|
||||
uint64_t addr = next_memmap_addr_;
|
||||
next_memmap_addr_ += size;
|
||||
if (next_memmap_addr_ >= 0x30'00000000) {
|
||||
|
@ -30,6 +30,6 @@ uint64_t VirtualMemory::GetNextMemMapAddr(uint64_t size) {
|
|||
return addr;
|
||||
}
|
||||
|
||||
uint64_t* VirtualMemory::AllocateKernelStack() {
|
||||
uint64_t* AddressSpace::AllocateKernelStack() {
|
||||
return gKernelStackManager->AllocateKernelStack();
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
// 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 {
|
||||
class AddressSpace {
|
||||
public:
|
||||
enum MemoryType {
|
||||
UNSPECIFIED,
|
||||
|
@ -39,11 +39,11 @@ class VirtualMemory {
|
|||
KERNEL_STACK,
|
||||
};
|
||||
|
||||
static VirtualMemory ForRoot();
|
||||
static AddressSpace ForRoot();
|
||||
|
||||
VirtualMemory();
|
||||
VirtualMemory(const VirtualMemory&) = delete;
|
||||
VirtualMemory(VirtualMemory&&) = delete;
|
||||
AddressSpace();
|
||||
AddressSpace(const AddressSpace&) = delete;
|
||||
AddressSpace(AddressSpace&&) = delete;
|
||||
|
||||
uint64_t cr3() { return cr3_; }
|
||||
|
||||
|
@ -55,7 +55,7 @@ class VirtualMemory {
|
|||
uint64_t* AllocateKernelStack();
|
||||
|
||||
private:
|
||||
VirtualMemory(uint64_t cr3) : cr3_(cr3) {}
|
||||
AddressSpace(uint64_t cr3) : cr3_(cr3) {}
|
||||
uint64_t cr3_ = 0;
|
||||
|
||||
UserStackManager user_stacks_;
|
|
@ -6,7 +6,7 @@
|
|||
#include "lib/linked_list.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "lib/shared_ptr.h"
|
||||
#include "memory/virtual_memory.h"
|
||||
#include "object/address_space.h"
|
||||
|
||||
// Forward decl due to cyclic dependency.
|
||||
class Thread;
|
||||
|
@ -23,7 +23,7 @@ class Process : public KernelObject {
|
|||
static RefPtr<Process> Create();
|
||||
|
||||
uint64_t id() const { return id_; }
|
||||
VirtualMemory& vmm() { return vmm_; }
|
||||
AddressSpace& vmm() { return vmm_; }
|
||||
|
||||
RefPtr<Thread> CreateThread();
|
||||
RefPtr<Thread> GetThread(uint64_t tid);
|
||||
|
@ -39,9 +39,9 @@ class Process : public KernelObject {
|
|||
private:
|
||||
friend class MakeRefCountedFriend<Process>;
|
||||
Process();
|
||||
Process(uint64_t id) : id_(id), vmm_(VirtualMemory::ForRoot()) {}
|
||||
Process(uint64_t id) : id_(id), vmm_(AddressSpace::ForRoot()) {}
|
||||
uint64_t id_;
|
||||
VirtualMemory vmm_;
|
||||
AddressSpace vmm_;
|
||||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
|
|
Loading…
Reference in New Issue