From e2a90fce95fde6eaef50e6d99e32b902ec14cc0d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 31 Aug 2024 15:08:15 +0200 Subject: Source bump. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/Sources/CodeManager.cxx | 3 +- dev/ZKA/Sources/DLLInterface.cxx | 5 ++- dev/ZKA/Sources/DLLMain.cxx | 5 +-- dev/ZKA/Sources/MP.cxx | 72 ++++++++------------------------ dev/ZKA/Sources/PEFCodeManager.cxx | 3 +- dev/ZKA/Sources/UserProcessScheduler.cxx | 27 ++++++------ 6 files changed, 42 insertions(+), 73 deletions(-) (limited to 'dev/ZKA/Sources') diff --git a/dev/ZKA/Sources/CodeManager.cxx b/dev/ZKA/Sources/CodeManager.cxx index 243e3441..f50457a4 100644 --- a/dev/ZKA/Sources/CodeManager.cxx +++ b/dev/ZKA/Sources/CodeManager.cxx @@ -19,7 +19,8 @@ namespace Kernel if (!main) return false; - UserProcess proc((VoidPtr)main); + UserProcess proc; + proc.SetEntrypoint(reinterpret_cast(main)); proc.Kind = UserProcess::kExeKind; proc.StackSize = mib_cast(1); diff --git a/dev/ZKA/Sources/DLLInterface.cxx b/dev/ZKA/Sources/DLLInterface.cxx index ed1793eb..13ee07cf 100644 --- a/dev/ZKA/Sources/DLLInterface.cxx +++ b/dev/ZKA/Sources/DLLInterface.cxx @@ -10,6 +10,8 @@ #include #include +#include + using namespace Kernel; /***********************************************************************************/ @@ -19,5 +21,6 @@ using namespace Kernel; EXTERN_C void __zka_pure_call(void) { - kcout << "newoskrnl: unimplemented symbol!\r"; + kcout << "newoskrnl: Unimplemented entrypoint symbol!\r"; + UserProcessScheduler::The().CurrentProcess().Leak().Crash(); } diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index 15a9079f..8f5d1977 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -213,13 +213,12 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 20, 10 + (FONT_SIZE_X * Kernel::rt_string_len("newoskrnl.dll: Missing catalog: ")), RGB(0, 0, 0)); } - auto hey = []() -> void { + STATIC auto main_kind = []() -> void { auto number_own = 8; - Kernel::kcout << "I have my own stack: " << Kernel::number(number_own); while (Yes); }; - Kernel::execute_from_image(hey, "ZKA Logger"); + Kernel::execute_from_image(main_kind, "ZKA Logger"); while (Yes) { 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. */ diff --git a/dev/ZKA/Sources/PEFCodeManager.cxx b/dev/ZKA/Sources/PEFCodeManager.cxx index 60b55efc..5b797ee3 100644 --- a/dev/ZKA/Sources/PEFCodeManager.cxx +++ b/dev/ZKA/Sources/PEFCodeManager.cxx @@ -199,8 +199,9 @@ namespace Kernel if (errOrStart.Error() != kErrorSuccess) return false; - UserProcess proc(errOrStart.Leak().Leak()); + UserProcess proc; + proc.SetEntrypoint(errOrStart.Leak().Leak()); proc.Kind = procKind; proc.StackSize = *(UIntPtr*)exec.FindSymbol("__STACK_SIZE", kPefData); diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index 94512913..b5d9660c 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -243,8 +243,7 @@ namespace Kernel return -kErrorProcessFault; } - process.StackFrame = reinterpret_cast( - mm_new_ke_heap(sizeof(HAL::StackFrame), Yes, Yes)); + process.StackFrame = new HAL::StackFrame(); MUST_PASS(process.StackFrame); @@ -253,15 +252,13 @@ namespace Kernel // get preferred stack size by app. const auto cMaxStackSize = process.StackSize; - process.StackFrame->BP = reinterpret_cast(process.Image); - process.StackFrame->SP = reinterpret_cast(mm_new_ke_heap(cMaxStackSize, Yes, Yes)); + process.StackReserve = (UInt8*)mm_new_ke_heap(cMaxStackSize, Yes, Yes); - if (!process.StackFrame->SP) + // if stack pointer isn't valid. + if (!process.StackReserve) { - process.StackReserve = new UInt8[cMaxStackSz]; - process.StackFrame->SP = reinterpret_cast(process.StackReserve); - - kcout << "newoskrnl: use fallback reserve.\r"; + process.StackReserve = (UInt8*)mm_new_ke_heap(kSchedMaxStackSz, Yes, Yes); + kcout << "newoskrnl: Use fallback reserve.\r"; } } else @@ -342,9 +339,13 @@ namespace Kernel kcout << process.Name << ": will be runned.\r"; // tell helper to find a core to schedule on. - if (!ProcessHelper::Switch(process.StackFrame, + if (!ProcessHelper::Switch(process.Image, process.StackReserve, process.StackFrame, process.ProcessId)) + { process.Crash(); + } + + process.Exit(); continue; } @@ -429,9 +430,9 @@ namespace Kernel * \param new_pid the process's PID. */ - bool ProcessHelper::Switch(HAL::StackFrame* the_stack, const PID& new_pid) + bool ProcessHelper::Switch(VoidPtr image_ptr, UInt8* stack, HAL::StackFramePtr frame_ptr, const PID& new_pid) { - if (!the_stack || new_pid < 0) + if (!stack || !frame_ptr || !image_ptr || new_pid < 0) return false; kcout << "newoskrnl: Finding hardware thread...\r"; @@ -455,7 +456,7 @@ namespace Kernel kcout << "newoskrnl: Found hardware thread...\r"; - bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(the_stack); + bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr); HardwareThreadScheduler::The()[index].Leak()->Busy(false); -- cgit v1.2.3