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
|
|
@ -13,19 +13,14 @@ static uint64_t gNextId = 1;
|
|||
}
|
||||
|
||||
SharedPtr<Process> Process::RootProcess() {
|
||||
uint64_t pml4_addr = 0;
|
||||
asm volatile("mov %%cr3, %0;" : "=r"(pml4_addr));
|
||||
SharedPtr<Process> proc(new Process(0, pml4_addr));
|
||||
SharedPtr<Process> proc(new Process(0));
|
||||
proc->threads_.PushBack(Thread::RootThread(*proc));
|
||||
proc->next_thread_id_ = 1;
|
||||
|
||||
return proc;
|
||||
}
|
||||
|
||||
Process::Process() : id_(gNextId++), state_(RUNNING) {
|
||||
cr3_ = phys_mem::AllocatePage();
|
||||
InitializePml4(cr3_);
|
||||
}
|
||||
Process::Process() : id_(gNextId++), state_(RUNNING) {}
|
||||
|
||||
void Process::CreateThread(uint64_t entry) {
|
||||
Thread* thread = new Thread(*this, next_thread_id_++, entry);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ class Process {
|
|||
Process();
|
||||
|
||||
uint64_t id() const { return id_; }
|
||||
uint64_t cr3() const { return cr3_; }
|
||||
VirtualMemory& vmm() { return vmm_; }
|
||||
|
||||
void CreateThread(uint64_t entry);
|
||||
|
|
@ -34,10 +33,9 @@ class Process {
|
|||
State GetState() { return state_; }
|
||||
|
||||
private:
|
||||
Process(uint64_t id, uint64_t cr3) : id_(id), cr3_(cr3) {}
|
||||
Process(uint64_t id) : id_(id), vmm_(VirtualMemory::ForRoot()) {}
|
||||
uint64_t id_;
|
||||
VirtualMemory vmm_;
|
||||
uint64_t cr3_;
|
||||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ Thread::Thread(Process& proc, uint64_t tid, uint64_t entry)
|
|||
*(stack_ptr - 5) = reinterpret_cast<uint64_t>(stack_ptr + 1);
|
||||
// 6-15: rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15
|
||||
// 16: cr3
|
||||
*(stack_ptr - 16) = proc.cr3();
|
||||
*(stack_ptr - 16) = proc.vmm().cr3();
|
||||
rsp0_ = reinterpret_cast<uint64_t>(stack_ptr - 16);
|
||||
rsp0_start_ = reinterpret_cast<uint64_t>(stack_ptr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue