diff options
| author | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-12 18:09:07 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlal@softwarelabs.com> | 2024-06-12 18:09:07 +0200 |
| commit | 4b58295fb04c2430817301352fadce33178f94d4 (patch) | |
| tree | fb16edeb9d81ee475200bbbf9a5125822ea2a589 /Kernel/HALKit | |
| parent | 6a3b080067ff47f84c400987982cfa44927fe7e0 (diff) | |
MHR-30: initial commit.
Signed-off-by: Amlal EL Mahrouss <amlal@softwarelabs.com>
Diffstat (limited to 'Kernel/HALKit')
| -rw-r--r-- | Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 55 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalSMPCoreManager.asm | 42 | ||||
| -rw-r--r-- | Kernel/HALKit/POWER/ppc-cpu.h | 2 |
3 files changed, 83 insertions, 16 deletions
diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 2824b176..a395305c 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -8,13 +8,21 @@ #include <HALKit/AMD64/Processor.hpp> #include <NewKit/KernelCheck.hpp> #include <ArchKit/ArchKit.hpp> +#include <KernelKit/Semaphore.hpp> +#include <KernelKit/ProcessScheduler.hxx> #define kAPIC_ICR_Low 0x300 #define kAPIC_ICR_High 0x310 #define kAPIC_SIPI_Vector 0x00500 #define kAPIC_EIPI_Vector 0x00400 -EXTERN_C void AppMain(); +/// @brief This symbol is the kernel main symbol. +EXTERN_C void KeMain(); + +/// @brief assembly routine. internal use only. +EXTERN_C void _hal_enable_smp(void); + +/// @note: _hal_switch_context /////////////////////////////////////////////////////////////////////////////////////// @@ -104,6 +112,8 @@ namespace NewOS::HAL UIntPtr Address; }; + STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame); + /////////////////////////////////////////////////////////////////////////////////////// STATIC MadtType* kApicInfoBlock = nullptr; @@ -145,8 +155,7 @@ namespace NewOS::HAL NewOS::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector); } - /// @brief assembly routine. internal use only. - EXTERN_C Void _hal_enable_smp(Void); + STATIC HAL::StackFramePtr cFramePtr = nullptr; EXTERN_C Void hal_apic_acknowledge_cont(Void) { @@ -157,30 +166,46 @@ namespace NewOS::HAL { *cProgramInitialized = false; - AppMain(); - - while (true) - { + kcout << "newoskrnl: putting thread to sleep...\r"; - } + _hal_spin_core(); } else { - kcout << "newoskrnl: putting thread to sleep...\r"; - - AppMain(); + KeMain(); - while (true) - { - } + _hal_spin_core(); } } + EXTERN_C StackFramePtr _hal_leak_current_context(Void) { return cFramePtr; } + EXTERN_C Void hal_apic_acknowledge(Void) { hal_apic_acknowledge_cont(); } + EXTERN_C Void _hal_switch_context(HAL::StackFramePtr stackFrame) + { + hal_switch_context(stackFrame); + } + + STATIC Void hal_switch_context(HAL::StackFramePtr stackFrame) + { + /// TODO: + Semaphore sem; + while (sem.IsLocked()) {} + + sem.Lock(&ProcessScheduler::The().Leak().GetCurrent().Leak()); + + cFramePtr = stackFrame; + + /// yes the exception field contains the core id. + hal_send_start_ipi(stackFrame->Exception, 0x40, cBaseAddressAPIC); + + sem.Unlock(); + } + Void hal_system_get_cores(voidPtr rsdPtr) { auto acpi = ACPIFactoryInterface(rsdPtr); @@ -194,7 +219,7 @@ namespace NewOS::HAL for (SizeT i = 2; i < cMaxProbableCores; ++i) { - if (madt->MadtRecords[i].Flags == 0x01) // if local apic. + if (madt->MadtRecords[i].Flags == kThreadLAPIC) // if local apic. { MadtType::MadtAddress& madtRecord = madt->MadtRecords[i]; // then register as a core for scheduler. diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm index 5ecc2370..c4042b50 100644 --- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm +++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm @@ -13,6 +13,8 @@ [global rt_do_context_switch] [global _hal_enable_smp] [global _hal_spin_core] +[extern _hal_switch_context] +[extern _hal_leak_current_context] section .text @@ -20,10 +22,50 @@ section .text ;; rcx: Stack Pointer ;; rdx: SMP core address. rt_do_context_switch: + push rax + push rcx + push rdx + push rbx + push rbp + push rsi + push rdi + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + + jmp _hal_switch_context + + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop rdi + pop rsi + pop rbp + pop rbx + pop rdx + pop rcx + pop rax + + mov eax, 0 + retfq ;; gets the current stack frame. rt_get_current_context: + push rdx + jmp _hal_leak_current_context + mov rdx, rax + pop rdx retfq ;; @brief enables a smp core to run. diff --git a/Kernel/HALKit/POWER/ppc-cpu.h b/Kernel/HALKit/POWER/ppc-cpu.h index b7a96767..3855b85c 100644 --- a/Kernel/HALKit/POWER/ppc-cpu.h +++ b/Kernel/HALKit/POWER/ppc-cpu.h @@ -1,7 +1,7 @@ #ifndef __ASM_PPC_PROCESSOR_H #define __ASM_PPC_PROCESSOR_H -/// ! @note The NeWS cpu is based on the e500 with 64-bit extensions, much like the 970. +/// ! @note The Zeta cpu is based on the e500 with 64-bit extensions, much like the 970. /* * Default implementation of macro that returns current |
