diff options
Diffstat (limited to 'Kernel')
| -rw-r--r-- | Kernel/HALKit/AMD64/HalInterruptAPI.asm | 4 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalKernelMain.cxx | 37 | ||||
| -rw-r--r-- | Kernel/Sources/KeMain.cxx | 11 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessScheduler.cxx | 45 |
4 files changed, 52 insertions, 45 deletions
diff --git a/Kernel/HALKit/AMD64/HalInterruptAPI.asm b/Kernel/HALKit/AMD64/HalInterruptAPI.asm index 150cfc10..4832ecf3 100644 --- a/Kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/Kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -157,10 +157,10 @@ __NEW_INT_32: pop rcx pop rax - mov eax, 0 + mov rax, 0 ;; tell there local apic that we're done. - mov dword [0xFEE00000 + 0xB0], eax ; LAPIC_EOI + mov [0xFEE00000 + 0xB0], rax ; LAPIC_EOI iretq diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 9b605e1a..cafa6388 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -28,9 +28,21 @@ namespace NewOS::HAL extern void hal_system_get_cores(NewOS::voidPtr rsdPtr); } // namespace NewOS::HAL +/* GDT constant. */ +STATIC NewOS::HAL::Detail::NewOSGDT cGdt = { + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xaf, 0}, // kernel code + {0, 0, 0, 0x92, 0xaf, 0}, // kernel data + {0, 0, 0, 0x00, 0x00, 0}, // null entry + {0, 0, 0, 0x9a, 0xaf, 0}, // user code + {0, 0, 0, 0x92, 0xaf, 0}, // user data +}; + EXTERN_C void hal_init_platform( NewOS::HEL::HandoverInformationHeader* HandoverHeader) { + /* Setup globals. */ + kHandoverHeader = HandoverHeader; if (kHandoverHeader->f_Magic != kHandoverMagic && @@ -39,29 +51,17 @@ EXTERN_C void hal_init_platform( return; } - /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; kKernelVirtualStart = reinterpret_cast<NewOS::VoidPtr>( reinterpret_cast<NewOS::UIntPtr>(HandoverHeader->f_VirtualStart) + kVirtualAddressStartOffset); kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; - STATIC NewOS::HAL::Detail::NewOSGDT GDT = { - {0, 0, 0, 0x00, 0x00, 0}, // null entry - {0, 0, 0, 0x9a, 0xaf, 0}, // kernel code - {0, 0, 0, 0x92, 0xaf, 0}, // kernel data - {0, 0, 0, 0x00, 0x00, 0}, // null entry - {0, 0, 0, 0x9a, 0xaf, 0}, // user code - {0, 0, 0, 0x92, 0xaf, 0}, // user data - }; - NewOS::HAL::RegisterGDT gdtBase; - gdtBase.Base = reinterpret_cast<NewOS::UIntPtr>(&GDT); + gdtBase.Base = reinterpret_cast<NewOS::UIntPtr>(&cGdt); gdtBase.Limit = sizeof(NewOS::HAL::Detail::NewOSGDT) - 1; - /// Load GDT. - NewOS::HAL::GDTLoader gdt; gdt.Load(gdtBase); @@ -74,7 +74,7 @@ EXTERN_C void hal_init_platform( NewOS::HAL::IDTLoader idt; idt.Load(idtBase); - /// START POST + /* install basic hooks. */ constexpr auto cDummyInterrupt = 0x10; // 16 @@ -87,12 +87,9 @@ EXTERN_C void hal_init_platform( NewOS::HAL::Detail::_ke_power_on_self_test(); - auto cLoaderName = "LaunchDevil"; - NewOS::execute_from_image(KeMain, cLoaderName); + /* Call generic kernel entrypoint. */ - NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + KeMain(); - while (true) - { - } + NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP); } diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx index 58c76dc4..23e32c1d 100644 --- a/Kernel/Sources/KeMain.cxx +++ b/Kernel/Sources/KeMain.cxx @@ -203,8 +203,6 @@ namespace NewOS::Detail NewOS::Utils::execute_from_image(stageBoard, NewOS::ProcessHeader::kAppKind); - - /// TODO: now jump to user mode using the HAL. } } // namespace NewOS::Detail @@ -217,4 +215,13 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void) NewOS::Detail::FilesystemWizard wizard; // automatic. NewOS::Detail::SystemLauncher_Main(); + + // fetch system cores. + NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr); + + while (true) + { + // start scheduling. + NewOS::ProcessHelper::StartScheduling(); + } } diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index d9d013c6..dc273cf6 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -59,18 +59,20 @@ namespace NewOS VoidPtr ProcessHeader::New(const SizeT& sz) { - if (this->FreeMemory < 1) + if (this->HeapCursor) { - DbgLastError() = kErrorHeapOutOfMemory; - this->Crash(); /// out of memory. + if (this->FreeMemory < 1) + { + DbgLastError() = kErrorHeapOutOfMemory; + + /* we're going out of memory */ + this->Crash(); - return nullptr; - } + return nullptr; + } - if (this->HeapCursor) - { - VoidPtr ptr = this->HeapCursor; this->HeapCursor = (VoidPtr)((UIntPtr)this->HeapCursor + (sizeof(sz))); + VoidPtr ptr = this->HeapCursor; ++this->UsedMemory; --this->FreeMemory; @@ -206,12 +208,14 @@ namespace NewOS ke_new_ke_heap(sizeof(HAL::StackFrame), true, false)); MUST_PASS(process.Leak().StackFrame); + + process.Leak().Status = ProcessStatus::kRunning; - mTeam.AsArray().Add(process); - - process.Leak().ProcessId = mTeam.AsArray().Count() - 1; + process.Leak().ProcessId = (mTeam.AsArray().Count() - 1); process.Leak().HeapCursor = process.Leak().HeapPtr; + mTeam.AsArray().Add(process); + return mTeam.AsArray().Count() - 1; } @@ -232,17 +236,14 @@ namespace NewOS /// @return SizeT ProcessScheduler::Run() noexcept { - SizeT processIndex = 0; //! we store this guy to tell the scheduler how many + SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - for (; processIndex < mTeam.AsArray().Count(); ++processIndex) + for (; process_index < mTeam.AsArray().Count(); ++process_index) { - auto process = mTeam.AsArray()[processIndex]; - - if (!process) - continue; + auto process = mTeam.AsArray()[process_index]; - //! run any process needed to be scheduled. + //! check if process needs to be scheduled. if (ProcessHelper::CanBeScheduled(process.Leak())) { auto unwrapped_process = *process.Leak(); @@ -255,6 +256,8 @@ namespace NewOS // tell helper to find a core to schedule on. ProcessHelper::Switch(mTeam.AsRef().Leak().StackFrame, mTeam.AsRef().Leak().ProcessId); + + kcout << unwrapped_process.Name << ": process switched.\r"; } else { @@ -263,7 +266,7 @@ namespace NewOS } } - return processIndex; + return process_index; } /// @brief Gets the current scheduled team. @@ -328,8 +331,8 @@ namespace NewOS bool ProcessHelper::StartScheduling() { - auto& processRef = ProcessScheduler::The().Leak(); - SizeT ret = processRef.Run(); + auto& process_ref = ProcessScheduler::The().Leak(); + SizeT ret = process_ref.Run(); kcout << "newoskrnl: Iterated over: "; kcout.Number(ret); |
