diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-06-19 07:59:04 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-06-19 07:59:04 +0000 |
| commit | b820eb6a5a7948597d81998137b05ddc0eb0dbad (patch) | |
| tree | db4eaea0b6863076c4f1476f361e2317823a663a /Kernel/Sources/SMPManager.cxx | |
| parent | 36ff25861676cd1f5fb94b901fa59b015c614bc5 (diff) | |
| parent | 6735570c44516661260546dadb81f0f5c238d1db (diff) | |
Merged in MHR-31 (pull request #16)
MHR-31: Round robin scheduler.
Diffstat (limited to 'Kernel/Sources/SMPManager.cxx')
| -rw-r--r-- | Kernel/Sources/SMPManager.cxx | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index f0b680ce..149b1334 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -85,39 +85,29 @@ namespace NewOS bool HardwareThread::Switch(HAL::StackFramePtr stack) { if (!rt_check_stack(stack)) - return false; - - if (!fStack) - { - fStack = stack; - } - else { - /// Keep the arguments, switch the base pointer, stack pointer - /// fs and gs registers. - fStack->Rbp = stack->Rbp; - fStack->Rsp = stack->Rsp; - fStack->Fs = stack->Fs; - fStack->Gs = stack->Gs; - - // save global registers. - - fStack->R15 = stack->R15; - fStack->R14 = stack->R14; + /// provide 'nullptr' to free the stack frame. + if (stack == nullptr) + { + delete fStack; + fStack = nullptr; - fStack->R13 = stack->R13; - fStack->R12 = stack->R12; - fStack->R11 = stack->R11; + return true; + } - fStack->R10 = stack->R10; - fStack->R9 = stack->R9; - fStack->R8 = stack->R8; + return false; + } - fStack->Exception = this->fID; + if (fStack) + { + delete fStack; + fStack = nullptr; } + + fStack = stack; rt_do_context_switch(fStack); - + return true; } @@ -143,12 +133,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; + ProcessHelper::TheCurrentPID() == + fThreadList[fCurrentThread].Leak().Leak()->fPID) + return fThreadList[fCurrentThread].Leak().Leak()->fStack; return nullptr; } @@ -163,35 +153,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::TheCurrentPID(); - fThreadList[idx].Leak().Leak().Busy(false); + fThreadList[idx].Leak().Leak()->Busy(false); return true; } @@ -204,19 +194,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}; } |
