diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-13 19:38:29 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-13 19:38:29 +0200 |
| commit | 7327f305efb1c6678722308cc5f9645dd39f451e (patch) | |
| tree | 0e15f4ad6f275aa689f5d66641d3d9ad59d15472 /Kernel/Sources/SMPManager.cxx | |
| parent | 349fe48baf941b2d1b571d3a5d0d796823bae312 (diff) | |
MHR-31: Lots of fixes and improvements regarding the kernel.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources/SMPManager.cxx')
| -rw-r--r-- | Kernel/Sources/SMPManager.cxx | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index 99a3b025..683343ff 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -117,7 +117,7 @@ namespace NewOS } rt_do_context_switch(fStack); - + return true; } @@ -143,12 +143,12 @@ namespace NewOS } /// @brief Get Stack Frame of Core - HAL::StackFramePtr SMPManager::GetStackFrame() noexcept + HAL::StackFramePtr SMPManager::Leak() noexcept { if (fThreadList[fCurrentThread].Leak() && ProcessHelper::GetCurrentPID() == - fThreadList[fCurrentThread].Leak().Leak().fPID) - return fThreadList[fCurrentThread].Leak().Leak().fStack; + fThreadList[fCurrentThread].Leak().Leak()->fPID) + return fThreadList[fCurrentThread].Leak().Leak()->fStack; return nullptr; } @@ -163,35 +163,35 @@ namespace NewOS { // stack != nullptr -> if core is used, then continue. if (!fThreadList[idx].Leak() || - !fThreadList[idx].Leak().Leak().IsWakeup() || - fThreadList[idx].Leak().Leak().IsBusy()) + !fThreadList[idx].Leak().Leak()->IsWakeup() || + fThreadList[idx].Leak().Leak()->IsBusy()) continue; // to avoid any null deref. - if (!fThreadList[idx].Leak().Leak().fStack) + if (!fThreadList[idx].Leak().Leak()->fStack) continue; - if (fThreadList[idx].Leak().Leak().fStack->Rsp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->Rsp == 0) continue; - if (fThreadList[idx].Leak().Leak().fStack->Rbp == 0) + if (fThreadList[idx].Leak().Leak()->fStack->Rbp == 0) continue; - fThreadList[idx].Leak().Leak().Busy(true); + fThreadList[idx].Leak().Leak()->Busy(true); - fThreadList[idx].Leak().Leak().fID = idx; + fThreadList[idx].Leak().Leak()->fID = idx; /// I figured out this: /// Allocate stack /// Set APIC base to stack /// Do stuff and relocate stack based on this code. /// - Amlel - rt_copy_memory(stack, fThreadList[idx].Leak().Leak().fStack, + rt_copy_memory(stack, fThreadList[idx].Leak().Leak()->fStack, sizeof(HAL::StackFrame)); - fThreadList[idx].Leak().Leak().Switch(fThreadList[idx].Leak().Leak().fStack); + fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack); - fThreadList[idx].Leak().Leak().fPID = ProcessHelper::GetCurrentPID(); + fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::GetCurrentPID(); - fThreadList[idx].Leak().Leak().Busy(false); + fThreadList[idx].Leak().Leak()->Busy(false); return true; } @@ -204,19 +204,25 @@ namespace NewOS * @param idx the index * @return the reference to the hardware thread. */ - Ref<HardwareThread> SMPManager::operator[](const SizeT& idx) + Ref<HardwareThread*> SMPManager::operator[](const SizeT& idx) { if (idx == 0) { - if (fThreadList[idx].Leak().Leak().Kind() != kHartSystemReserved) + if (fThreadList[idx].Leak().Leak()->Kind() != kHartSystemReserved) { - fThreadList[idx].Leak().Leak().fKind = kHartBoot; + fThreadList[idx].Leak().Leak()->fKind = kHartBoot; } } else if (idx >= kMaxHarts) { - HardwareThread fakeThread; - fakeThread.fKind = kInvalidHart; + static HardwareThread* fakeThread = new HardwareThread(); + + if (!fakeThread) + { + fakeThread = new HardwareThread(); + } + + fakeThread->fKind = kInvalidHart; return {fakeThread}; } |
