WIP: modules
This commit is contained in:
@@ -18,6 +18,10 @@ Address ExceptionsHandler(ExceptionsContext* frame, ExceptionsType type) {
|
||||
return SchedulerNext((Address)frame);
|
||||
}
|
||||
}
|
||||
|
||||
if (class == 0x15 && syndrome == 0) {
|
||||
OSPanic("Wow! We are inside EL0! Syscall caught successfully! :D");
|
||||
}
|
||||
}
|
||||
OSPanicException(frame);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <OS/Log.h>
|
||||
#include <OS/Panic.h>
|
||||
#include <OS/Scheduler.h>
|
||||
#include <OS/Modules.h>
|
||||
|
||||
void KernelMain(Bootinfo* bootinfo) {
|
||||
OSLog("Kernel started.\n");
|
||||
@@ -26,6 +27,7 @@ void KernelMain(Bootinfo* bootinfo) {
|
||||
DTBParse(bootinfo->dtb, &bootMap);
|
||||
PMMInitialize(&bootMap);
|
||||
VMMInitialize(&bootMap, bootinfo);
|
||||
bootinfo = (Bootinfo*)VMPhysToHHDM((Address)bootinfo);
|
||||
SerialUpdate(VMPhysToHHDM(bootMap.UART.base));
|
||||
HeapInitialize();
|
||||
|
||||
@@ -37,5 +39,10 @@ void KernelMain(Bootinfo* bootinfo) {
|
||||
CPUEnableInterrupts();
|
||||
SchedulerInitialize();
|
||||
|
||||
for (UInt32 i = 0; i < bootinfo->moduleCount; i++) {
|
||||
ModuleLoad(&bootinfo->modules[i]); // TODO: make some sort of priority of loading modules
|
||||
// like init first then uart then fb ...
|
||||
}
|
||||
|
||||
OSLog("Kernel initialized.\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <OS/Modules.h>
|
||||
#include <OS/Scheduler.h>
|
||||
#include <OS/Log.h>
|
||||
#include <VM/Heap.h>
|
||||
#include <VM/VMM.h>
|
||||
#include <Lib/String.h>
|
||||
#include <Arch/CPU.h>
|
||||
#include "../Common/bootinfo.h"
|
||||
|
||||
void ModuleLoad(BootModule* module) {
|
||||
OSProcess* userProc = HeapAllocate(sizeof(OSProcess));
|
||||
MemorySet(userProc, 0, sizeof(OSProcess));
|
||||
userProc->id = 1; // TODO: id gen
|
||||
userProc->state = OSTaskStateRunning;
|
||||
StringCopy(userProc->name, module->name);
|
||||
|
||||
Address userL0Phys = (Address)PMMAllocatePage();
|
||||
Address* userL0Virt = (Address*)VMPhysToHHDM(userL0Phys);
|
||||
MemorySet(userL0Virt, 0, kVMPageSize);
|
||||
userProc->l0Table = userL0Virt;
|
||||
|
||||
Address physBase = module->physicalBase;
|
||||
Address virtBase = module->virtualBase;
|
||||
Size modSize = module->size;
|
||||
|
||||
UInt64 codeFlags = kPTENormalMem | kPTEUser | kPTEAccessRW | kPTEPrivNX; // TODO: kill RWX
|
||||
|
||||
for (Size i = 0; i < modSize; i += kVMPageSize) {
|
||||
VMMMapPage((Address*)userL0Phys, physBase + i, virtBase + i, codeFlags);
|
||||
}
|
||||
|
||||
CPUCleanAndInvalidateCode((void*)VMPhysToHHDM(physBase), modSize);
|
||||
|
||||
Address stackPhys = (Address)PMMAllocatePage();
|
||||
Address userStackVirt = 0x80000000;
|
||||
UInt64 stackFlags = kPTENormalMem | kPTEUser | kPTEAccessRW | kPTEPrivNX | kPTEUserNX;
|
||||
|
||||
VMMMapPage((Address*)userL0Phys, stackPhys, userStackVirt, stackFlags);
|
||||
|
||||
void (*userEntryPoint)() = (void(*)())module->entry;
|
||||
|
||||
if ((Address)userEntryPoint == 0x0) {
|
||||
OSLog("Skipping module %s: entry point is 0x0.\n", module->name);
|
||||
return;
|
||||
}
|
||||
|
||||
SchedulerSpawn(userEntryPoint, userProc, true, userStackVirt + kVMPageSize);
|
||||
}
|
||||
Reference in New Issue
Block a user