diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-31 15:08:15 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-31 15:08:15 +0200 |
| commit | e2a90fce95fde6eaef50e6d99e32b902ec14cc0d (patch) | |
| tree | a7cc8f17478f9e77019beab9e524d39fe311f775 /dev/ZKA/Sources/MP.cxx | |
| parent | 2c4b02249ec4355a73b826909ab1889e45871faf (diff) | |
Source bump.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources/MP.cxx')
| -rw-r--r-- | dev/ZKA/Sources/MP.cxx | 72 |
1 files changed, 18 insertions, 54 deletions
diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx index 381f266d..5be23422 100644 --- a/dev/ZKA/Sources/MP.cxx +++ b/dev/ZKA/Sources/MP.cxx @@ -17,7 +17,7 @@ namespace Kernel { - /***********************************************************************************/ + /***********************************************************************************/ /// @brief MP object container property. /***********************************************************************************/ @@ -83,20 +83,30 @@ namespace Kernel /// @note Those symbols are needed in order to switch and validate the stack. EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr); - EXTERN_C Void hal_switch_context(HAL::StackFramePtr stackPtr); + EXTERN_C Bool mp_register_process(HAL::StackFramePtr stackPtr); /// @brief Switch to hardware thread. /// @param stack the new hardware thread. /// @retval true stack was changed, code is running. /// @retval false stack is invalid, previous code is running. - Bool HardwareThread::Switch(HAL::StackFramePtr stack) + Bool HardwareThread::Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame) { - fStack = stack; + fStack = frame; + + if (!fStack || + !image || + !stack_ptr) + return false; - hal_switch_context(fStack); - mp_do_context_switch(fStack); + auto ret = mp_register_process(fStack); + + if (!ret) + { + /// TODO: start timer to schedule another process here. + return mp_do_context_switch(image, stack_ptr, fStack) != 0; + } - return true; + return ret; } ///! @brief Tells if processor is waked up. @@ -137,54 +147,8 @@ namespace Kernel return fThreadList[fCurrentThread].fStack; } - /// @brief Finds and switch to a free core. - bool HardwareThreadScheduler::Switch(HAL::StackFramePtr stack) - { - if (stack == nullptr) - return false; - - for (SizeT idx = 0; idx < cMaxHWThreads; ++idx) - { - // stack != nullptr -> if core is used, then continue. - if (!fThreadList[idx] || - !fThreadList[idx].IsWakeup() || - fThreadList[idx].IsBusy()) - continue; - - // to avoid any null deref. - if (!fThreadList[idx].fStack) - continue; - if (fThreadList[idx].fStack->SP == 0) - continue; - if (fThreadList[idx].fStack->BP == 0) - continue; - - fThreadList[idx].Busy(true); - - fThreadList[idx].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].fStack, - sizeof(HAL::StackFrame)); - - fThreadList[idx].Switch(fThreadList[idx].fStack); - - fThreadList[idx].fSourcePID = ProcessHelper::TheCurrentPID(); - - fThreadList[idx].Busy(false); - - return true; - } - - return false; - } - /** - * Index Hardware thread + * Get Hardware thread at index. * @param idx the index * @return the reference to the hardware thread. */ |
