Move PML4 initialization into the VirtualMemory class.

This commit is contained in:
Drew Galbraith 2023-05-30 21:39:19 -07:00
parent f22dd66c8d
commit 1db93e5b12
11 changed files with 39 additions and 25 deletions

View file

@ -48,7 +48,7 @@ typedef struct {
} // namespace
uint64_t LoadElfProgram(uint64_t cr3, uint64_t base, uint64_t offset) {
uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t offset) {
Elf64Header* header = reinterpret_cast<Elf64Header*>(base);
dbgln("phoff: %u phnum: %u", header->phoff, header->phnum);
Elf64ProgramHeader* programs =
@ -60,7 +60,7 @@ uint64_t LoadElfProgram(uint64_t cr3, uint64_t base, uint64_t offset) {
"filesz: %u, memsz: %u, align: %u",
program.type, program.flags, program.offset, program.vaddr,
program.paddr, program.filesz, program.memsz, program.align);
CopyIntoNonResidentProcess(base + program.offset, program.filesz, cr3,
CopyIntoNonResidentProcess(base + program.offset, program.filesz, dest_proc,
program.vaddr);
}
return header->entry;

View file

@ -2,5 +2,7 @@
#include <stdint.h>
#include "scheduler/process.h"
// Loads the elf program and returns its entry point.
uint64_t LoadElfProgram(uint64_t cr3, uint64_t base, uint64_t length);
uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t length);

View file

@ -43,12 +43,11 @@ void LoadInitProgram() {
SharedPtr<Process> proc = MakeShared<Process>();
gProcMan->InsertProcess(proc);
uint64_t entry =
LoadElfProgram(proc->cr3(), reinterpret_cast<uint64_t>(init_prog.address),
init_prog.size);
uint64_t entry = LoadElfProgram(
*proc, reinterpret_cast<uint64_t>(init_prog.address), init_prog.size);
CopyIntoNonResidentProcess(reinterpret_cast<uint64_t>(prog2.address),
prog2.size, proc->cr3(),
prog2.size, *proc,
proc->vmm().GetNextMemMapAddr(prog2.size));
proc->CreateThread(entry);