From 529945c987c5107d84b627a56627df6dd40dd3da Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 Aug 2024 18:06:32 +0200 Subject: [FIX] Kernel: Fix scheduler code and improved it's inner workings. [FIX] DLLMain now spins scheduler when it's done about showing the setup window. Signed-off-by: Amlal El Mahrouss --- dev/ZBA/Sources/Thread.cxx | 2 ++ dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx | 6 ++++++ dev/ZKA/KernelKit/ProcessScheduler.hxx | 6 +++--- dev/ZKA/KernelKit/Timer.hxx | 6 +++--- dev/ZKA/NewKit/Macros.hxx | 1 + dev/ZKA/NewKit/PageManager.hxx | 4 ---- dev/ZKA/Sources/DLLMain.cxx | 22 ++++++++++++--------- dev/ZKA/Sources/ProcessScheduler.cxx | 36 ++++++++++++++++++++++------------ dev/ZKA/Sources/Timer.cxx | 2 +- 9 files changed, 52 insertions(+), 33 deletions(-) (limited to 'dev') diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx index 6290178f..c850b6ae 100644 --- a/dev/ZBA/Sources/Thread.cxx +++ b/dev/ZBA/Sources/Thread.cxx @@ -24,6 +24,8 @@ EXTERN_C{ // External boot services symbol. EXTERN EfiBootServices* BS; +/// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. + namespace Boot { BThread::BThread(VoidPtr blob) diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx index 87dd1d24..f389dd80 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx @@ -81,6 +81,12 @@ namespace Kernel vmh_header->Magic == cVMHMagic) { vmh_header = traits.Next(vmh_header); + + if (vmh_header == reinterpret_cast(kBadPtr)) + { + ke_stop(RUNTIME_CHECK_POINTER); + return nullptr; + } } vmh_header->Magic = cVMHMagic; diff --git a/dev/ZKA/KernelKit/ProcessScheduler.hxx b/dev/ZKA/KernelKit/ProcessScheduler.hxx index 826f8a89..5df9d369 100644 --- a/dev/ZKA/KernelKit/ProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/ProcessScheduler.hxx @@ -250,9 +250,9 @@ namespace Kernel /// The main class which you call to schedule an app. class ProcessScheduler final { - explicit ProcessScheduler() = default; - public: + explicit ProcessScheduler() = default; + ~ProcessScheduler() = default; ZKA_COPY_DEFAULT(ProcessScheduler) @@ -272,7 +272,7 @@ namespace Kernel SizeT Run() noexcept; public: - STATIC Ref& The(); + STATIC Ref The(); private: ProcessTeam mTeam; diff --git a/dev/ZKA/KernelKit/Timer.hxx b/dev/ZKA/KernelKit/Timer.hxx index e6afd454..ba598975 100644 --- a/dev/ZKA/KernelKit/Timer.hxx +++ b/dev/ZKA/KernelKit/Timer.hxx @@ -63,7 +63,7 @@ namespace Kernel Int64 fWaitFor{0}; }; - inline Int64 Seconds(Int64 time) + inline Int64 Milliseconds(Int64 time) { if (time < 0) return 0; @@ -71,11 +71,11 @@ namespace Kernel return 1000 * time; } - inline Int64 Milliseconds(Int64 time) + inline Int64 Seconds(Int64 time) { if (time < 0) return 0; - return 1000 * Seconds(time); + return 1000 * Milliseconds(time); } } // namespace Kernel diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index b8f316bf..e8143c2c 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -95,6 +95,7 @@ #endif #define kBadPtr 0xFBFBFBFBFBFBFBFB +#define kBadAddress 0x00000000000000 #define kMaxAddr 0xFFFFFFFFFFFFFFFF #define kPathLen 255 diff --git a/dev/ZKA/NewKit/PageManager.hxx b/dev/ZKA/NewKit/PageManager.hxx index 745395ec..249c0cc9 100644 --- a/dev/ZKA/NewKit/PageManager.hxx +++ b/dev/ZKA/NewKit/PageManager.hxx @@ -13,10 +13,6 @@ #include #include -#ifndef kBadAddress -#define kBadAddress (0) -#endif // #ifndef kBadAddress - namespace Kernel { class PageManager; diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index cecf7347..b3bcd48c 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -24,6 +24,7 @@ #include #include #include +#include EXTERN Kernel::Property cKernelVersion; @@ -180,14 +181,19 @@ namespace Kernel::Detail }; } // namespace Kernel::Detail +namespace Kernel +{ + EXTERN ProcessScheduler* cProcessScheduler; +} // namespace Kernel + /// @brief Application entrypoint. /// @param Void /// @return Void EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { - CGInit(); + CGInit(); - CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), + CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), 0, 0); CGFini(); @@ -209,16 +215,14 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) root_install_wnd->w_needs_repaint = Yes; - CG::UI_WINDOW_STRUCT* arr[] = {root_zka_wnd, root_install_wnd}; - - CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), - 0, 0); - - CGFini(); + CG::CGDrawWindowList(&root_zka_wnd, 1); + CG::CGDrawWindowList(&root_install_wnd, 1); - CG::CGDrawWindowList(arr, 2); + /// @note BThread doesn't parse the symbols so doesn't nullify them, .bss is though. + Kernel::cProcessScheduler = nullptr; while (Yes) { + Kernel::ProcessHelper::StartScheduling(); } } diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx index 1d83e519..d33c7e85 100644 --- a/dev/ZKA/Sources/ProcessScheduler.cxx +++ b/dev/ZKA/Sources/ProcessScheduler.cxx @@ -28,7 +28,10 @@ namespace Kernel /// @brief Exit Code global variable. /***********************************************************************************/ - STATIC Int32 cLastExitCode = 0U; + Int32 cLastExitCode = 0U; + + /// @brief The main process object. + ProcessScheduler* cProcessScheduler = nullptr; /// @brief Gets the last exit code. /// @note Not thread-safe. @@ -202,7 +205,7 @@ namespace Kernel } } - ProcessScheduler::The().Leak().Remove(this->ProcessId); + cProcessScheduler->Remove(this->ProcessId); } /// @brief Add process to list. @@ -278,6 +281,16 @@ namespace Kernel return (mTeam.AsArray().Count() - 1); } + /***********************************************************************************/ + + Ref ProcessScheduler::The() + { + MUST_PASS(cProcessScheduler); + return *cProcessScheduler; + } + + /***********************************************************************************/ + /// @brief Remove process from list. /// @param processSlot process slot inside team. /// @retval true process was removed. @@ -301,6 +314,8 @@ namespace Kernel /// @return SizeT ProcessScheduler::Run() noexcept { + kcout << "newoskrnl: Entering scheduler control..\r"; + SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. @@ -337,6 +352,8 @@ namespace Kernel } } + kcout << "newoskrnl: Exiting scheduler control..\r"; + return process_index; } @@ -348,14 +365,6 @@ namespace Kernel } /// @internal - STATIC Ref cSchedulerRef; - - /// @brief Shared instance of the process scheduler. - /// @return - Ref& ProcessScheduler::The() - { - return cSchedulerRef; - } /// @brief Gets current running process. /// @return @@ -369,7 +378,7 @@ namespace Kernel PID& ProcessHelper::TheCurrentPID() { kcout << "ProcessHelper::TheCurrentPID: Leaking ProcessId...\r"; - return ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId; + return cProcessScheduler->TheCurrent().Leak().ProcessId; } /// @brief Check if process can be schedulded. @@ -414,9 +423,10 @@ namespace Kernel SizeT ProcessHelper::StartScheduling() { - auto& process_ref = ProcessScheduler::The().Leak(); - SizeT ret = process_ref.Run(); + if (!cProcessScheduler) + cProcessScheduler = new ProcessScheduler(); + SizeT ret = cProcessScheduler->Run(); return ret; } diff --git a/dev/ZKA/Sources/Timer.cxx b/dev/ZKA/Sources/Timer.cxx index 7a5ebd8d..3e5f6f3d 100644 --- a/dev/ZKA/Sources/Timer.cxx +++ b/dev/ZKA/Sources/Timer.cxx @@ -41,7 +41,7 @@ Int32 SoftwareTimer::Wait() noexcept while (*fDigitalTimer < (*fDigitalTimer + fWaitFor)) { - ++fDigitalTimer; + ++(*fDigitalTimer); } return 0; -- cgit v1.2.3