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 | |
| parent | 2c4b02249ec4355a73b826909ab1889e45871faf (diff) | |
Source bump.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
22 files changed, 190 insertions, 183 deletions
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 330dc96a..cd131a2d 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -133,7 +133,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast<VoidPtr*>(&mp)); - handoverHdrPtr->f_MultiProcessingEnabled = mp != nullptr; handoverHdrPtr->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(mp); kHandoverHeader = handoverHdrPtr; @@ -150,6 +149,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, CGDrawString("NEWOSLDR (C) ZKA TECHNOLOGIES.", 10, 10, RGB(0xFF, 0xFF, 0xFF)); CGDrawString((cnt_enabled > 1) ? "MULTIPROCESSOR SYSTEM." : "UNIPROCESSOR SYSTEM.", 20, 10, RGB(0xFF, 0xFF, 0xFF)); + handoverHdrPtr->f_MultiProcessingEnabled = cnt_enabled > 1 + ; // Fill handover header now. BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc); diff --git a/dev/ZKA/ArchKit/ArchKit.hxx b/dev/ZKA/ArchKit/ArchKit.hxx index 2c9a951e..97a4c17a 100644 --- a/dev/ZKA/ArchKit/ArchKit.hxx +++ b/dev/ZKA/ArchKit/ArchKit.hxx @@ -107,4 +107,5 @@ inline Kernel::Array<HAL_SYSCALL_RECORD, kKerncalls; EXTERN_C Kernel::HAL::StackFramePtr mp_get_current_context(); -EXTERN_C Kernel::Void mp_do_context_switch(Kernel::HAL::StackFramePtr stack_frame); +/// @note The context gives out the return address in return register. +EXTERN_C Kernel::UIntPtr mp_do_context_switch(Kernel::VoidPtr image, Kernel::UInt8* stack_ptr, Kernel::HAL::StackFramePtr stackPtr); diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx index 1f233e08..f022b5e5 100644 --- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx +++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx @@ -5,6 +5,7 @@ ------------------------------------------- */ #include <Modules/ACPI/ACPIFactoryInterface.hxx> +#include <KernelKit/UserProcessScheduler.hxx> #include <HALKit/AMD64/Processor.hxx> #include <NewKit/KernelCheck.hxx> #include <ArchKit/ArchKit.hxx> @@ -133,13 +134,13 @@ namespace Kernel::HAL Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector); } - EXTERN_C Void hal_switch_context(HAL::StackFramePtr stack_frame); + EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame); /// @brief Called when the AP is ready. /// @internal EXTERN_C Void hal_on_ap_startup(HAL::StackFramePtr stack_frame) { - hal_switch_context(stack_frame); + mp_register_process(stack_frame); ke_stop(RUNTIME_CHECK_FAILED); } @@ -147,20 +148,24 @@ namespace Kernel::HAL { UserProcessPtr f_Process; HAL::StackFramePtr f_Frame; - } fBlocks[cMaxHWThreads] = {0}; + } fBlocks[kSchedProcessLimitPerTeam] = {0}; EXTERN_C HAL::StackFramePtr _hal_leak_current_context(Void) { - return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Frame; + return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame; } - EXTERN_C Void hal_switch_context(HAL::StackFramePtr stack_frame) + EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame) { if (kSMPAware) { - fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak(); - fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Frame = stack_frame; + fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak(); + fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame = stack_frame; + + return true; } + + return false; } /***********************************************************************************/ diff --git a/dev/ZKA/HALKit/AMD64/HalHart.cxx b/dev/ZKA/HALKit/AMD64/HalHart.cxx deleted file mode 100644 index b438f303..00000000 --- a/dev/ZKA/HALKit/AMD64/HalHart.cxx +++ /dev/null @@ -1,33 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <ArchKit/ArchKit.hxx> - -// bugs = 0 - -namespace Kernel -{ - /// @brief wakes up thread. - /// wakes up thread from hang. - void mp_wakeup_thread(HAL::StackFrame* stack) - { - HAL::rt_cli(); - - mp_do_context_switch(stack); - - HAL::rt_sti(); - } - - /// @brief makes the thread sleep on a loop. - /// hooks and hangs thread to prevent code from executing. - void mp_hang_thread(HAL::StackFrame* stack) - { - while (true) - { - /* nohing, code is spinning */ - } - } -} // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index e2331ba6..31a47f00 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -52,7 +52,7 @@ namespace Kernel::HAL { /// @brief Gets the system cores using the MADT. /// @param rsdPtr The 'RSD PTR' data structure. - EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr); + EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr) noexcept; } // namespace Kernel::HAL /* GDT. */ diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index 6b3ed33a..98dbfa02 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -11,24 +11,43 @@ [global mp_get_current_context] [global mp_do_context_switch] -[global _hal_spin_core] [extern _hal_switch_context] [extern _hal_leak_current_context] section .text -;; writes to rdx the stackframe inside rcx. -;; rcx: Stack Pointer -;; rdx: SMP core address. +;; Does a user mode switch, and then loads the task to be run. +;; rcx: code ptr. +;; rdx: stack ptr. mp_do_context_switch: - jmp $ + mov r11, rdx + mov r12, rcx + + ; Enable SCE that enables sysret and syscall + mov rcx, 0xc0000082 + wrmsr + mov rcx, 0xc0000080 + rdmsr + or eax, 1 + wrmsr + mov rcx, 0xc0000081 + rdmsr + mov edx, 0x00180008 + wrmsr + + mov rcx, r11 + mov rdx, r12 + mov r11, 0x202 + + ;; rcx and rdx already set. + o64 sysret ret +mp_do_context_switch_fail: + jmp $ + + ;; @brief Gets the current stack frame. mp_get_current_context: call _hal_leak_current_context ret - -_hal_spin_core: - jmp $ - ret diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx index cad215b2..4e1b500c 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx @@ -97,7 +97,20 @@ namespace Kernel kAllocationInProgress = false; - return reinterpret_cast<VoidPtr>(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER)); + auto result = reinterpret_cast<VoidPtr>(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER)); + + VoidPtr cr3_value; + + asm volatile( + "mov %%cr3, %0" // Move CR3 into the variable + : "=r"(cr3_value) // Output operand, cr3 page directory. + : // No input operands + : "memory" + ); + + mm_update_page(cr3_value, 0, (UIntPtr)result, eFlagsPresent | (rw ? eFlagsRw : 0) | (user ? eFlagsUser : 0)); + + return result; } /// @brief Allocate a new page to be used by the OS. diff --git a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx index cb849150..a63328ab 100644 --- a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx +++ b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx @@ -4,17 +4,28 @@ ------------------------------------------- */ +#include <HALKit/AMD64/Processor.hxx> #include <KernelKit/UserProcessScheduler.hxx> using namespace Kernel; -Void UserProcess::SetEntrypoint(UIntPtr& imageStart) noexcept +Void UserProcess::SetEntrypoint(VoidPtr imageStart) noexcept { - if (imageStart == 0) + if (imageStart == nullptr) this->Crash(); - this->StackFrame->BP = imageStart; - this->StackFrame->SP = this->StackFrame->BP; + + VoidPtr cr3_pd; + + asm volatile( + "mov %%cr3, %0" // Move CR3 into the variable + : "=r"(cr3_pd) // Output operand, cr3 page directory. + : // No input operands + : "memory"); + + HAL::mm_update_page(cr3_pd, 0, (UIntPtr)imageStart, HAL::eFlagsPresent | HAL::eFlagsRw | HAL::eFlagsUser); + + this->Image = imageStart; } namespace Kernel @@ -29,4 +40,21 @@ namespace Kernel return true; } + + /// @brief Wakes up thread. + /// Wakes up thread from the hang state. + Void mp_wakeup_thread(HAL::StackFrame* stack) + { + mp_do_context_switch((VoidPtr)stack->BP, (UInt8*)stack->SP, stack); + } + + /// @brief makes the thread sleep on a loop. + /// hooks and hangs thread to prevent code from executing. + Void mp_hang_thread(HAL::StackFrame* stack) + { + while (Yes) + { + /* Nothing to do, code is spinning */ + } + } } // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index b307e0f2..94490e4e 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -128,18 +128,23 @@ namespace Kernel::HAL }; using RawRegister = UInt64; - - using InterruptId = UInt16; /* For each element in the IVT */ - - typedef UIntPtr Reg; + using Reg = RawRegister; + using InterruptId = UInt16; /* For each element in the IVT */ + /// @brief Stack frame (as retrieved from assembly.) struct PACKED StackFrame final { - Reg IntNum, Exception; - Reg A0, A2, BP, SP, A3, A4, A5, A6; - Reg R8, R9, R10, R11, R12, R13, R14, R15; - Reg Gs, Fs; + UIntPtr R8{0}; + UIntPtr R9{0}; + UIntPtr R10{0}; + UIntPtr R11{0}; + UIntPtr R12{0}; + UIntPtr R13{0}; + UIntPtr R14{0}; + UIntPtr R15{0}; + UIntPtr BP{0}; + UIntPtr SP{0}; }; typedef StackFrame* StackFramePtr; diff --git a/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx deleted file mode 100644 index 20c39684..00000000 --- a/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include <ArchKit/ArchKit.hxx> - -// bugs = 0 - -namespace Kernel -{ - /// @brief Wakes up thread. - /// Wakes up thread from the hang state. - Void mp_wakeup_thread(HAL::StackFrame* stack) - { - mp_do_context_switch(stack); - } - - /// @brief makes the thread sleep on a loop. - /// hooks and hangs thread to prevent code from executing. - Void mp_hang_thread(HAL::StackFrame* stack) - { - while (Yes) - { - /* Nothing to do, code is spinning */ - } - } -} // namespace Kernel diff --git a/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx b/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx index 00eaed27..74e37d91 100644 --- a/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx +++ b/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx @@ -28,4 +28,21 @@ namespace Kernel return true; } + + /// @brief Wakes up thread. + /// Wakes up thread from the hang state. + Void mp_wakeup_thread(HAL::StackFrame* stack) + { + mp_do_context_switch(stack); + } + + /// @brief makes the thread sleep on a loop. + /// hooks and hangs thread to prevent code from executing. + Void mp_hang_thread(HAL::StackFrame* stack) + { + while (Yes) + { + /* Nothing to do, code is spinning */ + } + } } // namespace Kernel diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx index 985dfe64..7660dd5b 100644 --- a/dev/ZKA/HALKit/ARM64/Processor.hxx +++ b/dev/ZKA/HALKit/ARM64/Processor.hxx @@ -33,10 +33,16 @@ namespace Kernel::HAL /// @note let's keep the same name as AMD64 HAL. struct PACKED StackFrame final { - Reg IntNum, Exception; - Reg A0, A2, BP, SP, A3, A4, A5, A6; - Reg R8, R9, R10, R11, R12, R13, R14, R15; - Reg Gs, Fs; + Reg R8{0}; + Reg R9{0}; + Reg R10{0}; + Reg R11{0}; + Reg R12{0}; + Reg R13{0}; + Reg R14{0}; + Reg R15{0}; + Reg BP{0}; + Reg SP{0}; }; typedef StackFrame* StackFramePtr; diff --git a/dev/ZKA/HALKit/POWER/Processor.hxx b/dev/ZKA/HALKit/POWER/Processor.hxx index 4b03af4b..ca11bf08 100644 --- a/dev/ZKA/HALKit/POWER/Processor.hxx +++ b/dev/ZKA/HALKit/POWER/Processor.hxx @@ -21,10 +21,16 @@ namespace Kernel::HAL /// @brief Stack frame (as retrieved from assembly.) struct PACKED StackFrame final { - Reg IntNum, Exception; - Reg A0, A2, BP, SP, A3, A4, A5, A6; - Reg R8, R9, R10, R11, R12, R13, R14, R15; - Reg Gs, Fs; + Reg R8{0}; + Reg R9{0}; + Reg R10{0}; + Reg R11{0}; + Reg R12{0}; + Reg R13{0}; + Reg R14{0}; + Reg R15{0}; + Reg BP{0}; + Reg SP{0}; }; typedef StackFrame* StackFramePtr; diff --git a/dev/ZKA/KernelKit/MP.hxx b/dev/ZKA/KernelKit/MP.hxx index 03b8b6fa..6de796ea 100644 --- a/dev/ZKA/KernelKit/MP.hxx +++ b/dev/ZKA/KernelKit/MP.hxx @@ -59,17 +59,17 @@ namespace Kernel void Busy(const bool busy = false) noexcept; public: - bool Switch(HAL::StackFrame* stack); + bool Switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr frame); bool IsWakeup() noexcept; public: - HAL::StackFrame* StackFrame() noexcept; + HAL::StackFramePtr StackFrame() noexcept; const ThreadKind& Kind() noexcept; bool IsBusy() noexcept; const ThreadID& ID() noexcept; private: - HAL::StackFrame* fStack{nullptr}; + HAL::StackFramePtr fStack{nullptr}; ThreadKind fKind{ThreadKind::kHartStandard}; ThreadID fID{0}; ProcessID fSourcePID{-1}; @@ -95,7 +95,6 @@ namespace Kernel ZKA_COPY_DEFAULT(HardwareThreadScheduler); public: - bool Switch(HAL::StackFramePtr the); HAL::StackFramePtr Leak() noexcept; public: diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index f0c19423..fafe474c 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -14,7 +14,7 @@ #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) -#define cMaxStackSz (4096) /* Max stack sz */ +#define kSchedMaxStackSz (4096) /* Max stack sz */ #define kSchedProcessLimitPerTeam (16U) //////////////////////////////////////////////////// @@ -138,7 +138,7 @@ namespace Kernel ZKA_COPY_DEFAULT(UserProcess) public: - void SetEntrypoint(UIntPtr& imageStart) noexcept; + void SetEntrypoint(VoidPtr imageStart) noexcept; const UInt32& GetExitCode() noexcept; public: @@ -286,7 +286,7 @@ namespace Kernel class ProcessHelper final { public: - STATIC bool Switch(HAL::StackFramePtr new_stack, const PID& new_pid); + STATIC bool Switch(VoidPtr image_ptr, UInt8* stack, HAL::StackFramePtr frame_ptr, const PID& new_pid); STATIC bool CanBeScheduled(UserProcess& process); STATIC PID& TheCurrentPID(); STATIC SizeT StartScheduling(); 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<VoidPtr>(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 <KernelKit/DLLInterface.hxx> #include <KernelKit/DebugOutput.hxx> +#include <KernelKit/UserProcessScheduler.hxx> + 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<HAL::StackFrame*>( - 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<HAL::Reg>(process.Image); - process.StackFrame->SP = reinterpret_cast<HAL::Reg>(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<HAL::Reg>(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); diff --git a/dev/ZKA/arm64-efi.make b/dev/ZKA/arm64-efi.make index 47563ec4..65f3a0ae 100644 --- a/dev/ZKA/arm64-efi.make +++ b/dev/ZKA/arm64-efi.make @@ -50,7 +50,7 @@ link-arm64-epm: .PHONY: all all: newos-arm64-epm link-arm64-epm - @echo "Krnl => OK." + @echo "Kernel => OK." .PHONY: help help: |
