From 0266d8058990a496b935abd76417abcfe4e9cffd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 18 May 2025 15:15:52 +0200 Subject: dev(sched): Improvements and work in progress fixes. what? - The main algorithm got improved for real time tasks, and SMP usage. - The SMP usage was present before, I just reintroduced it after realizing that it won't scale well from what I have right now. - Also removed weird implementations quirks from previous sketch. - Such as the core 0 being reserved for the boot core. - Also moved FS init code after IDT initalization. - To avoid weird FS format behavior. - Wrap HPET signature in a macro. next? - Work on the HAL's userspace transition mechanism. Signed-off-by: Amlal El Mahrouss --- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 30 +++++++++++++++++++--- dev/kernel/HALKit/AMD64/HalInterruptAPI.asm | 2 -- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 15 ++++++----- dev/kernel/HALKit/AMD64/HalTimerAMD64.cc | 4 ++- 4 files changed, 37 insertions(+), 14 deletions(-) (limited to 'dev/kernel/HALKit/AMD64') diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index 7e2b8957..eac6c389 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -37,6 +37,9 @@ EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "General Access Fault."); + } if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); @@ -62,6 +65,10 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "Access Fault."); + } + if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); @@ -101,6 +108,9 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "Math Fault."); + } if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); @@ -126,6 +136,10 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "Generic Fault."); + } + if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); @@ -146,10 +160,15 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { } EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) { - hal_idt_send_eoi(3); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + while (YES) + ; + } + + hal_idt_send_eoi(3); + if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); @@ -167,8 +186,6 @@ EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) { Kernel::kout << "Kernel: SIGTRAP status.\r"; process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; - - idt_handle_scheduler(rip); } /// @brief Handle #UD fault. @@ -180,6 +197,11 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + if (!process) { + while (YES) + ; + } + if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || process.Leak().Signal.SignalID == SIGTRAP) { dbg_break_point(); diff --git a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm index 667d3c5b..a6b194d3 100644 --- a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -224,8 +224,6 @@ __NE_INT_32: std - add rsp, 8 - o64 iret IntNormal 33 diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 581af60a..f4585835 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -110,24 +110,25 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { Kernel::HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - Kernel::HAL::Register64 idt_reg; - idt_reg.Base = reinterpret_cast(kInterruptVectorTable); - - Kernel::HAL::IDTLoader idt_loader; - - idt_loader.Load(idt_reg); - #ifdef __FSKIT_INCLUDES_HEFS__ if (Kernel::HeFS::fs_init_hefs()) { goto hal_spin_kernel; } #endif + if (!Kernel::NeFS::fs_init_nefs()) { kout << "NeFS cannot be formated on the disk. Aborting\r"; dbg_break_point(); } hal_spin_kernel: + Kernel::HAL::Register64 idt_reg; + idt_reg.Base = reinterpret_cast(kInterruptVectorTable); + + Kernel::HAL::IDTLoader idt_loader; + + idt_loader.Load(idt_reg); + while (YES) ; } diff --git a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc b/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc index 79165289..13573880 100644 --- a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc @@ -17,6 +17,8 @@ // timer slot 0 +#define kHPETSignature ("HPET") + #define kHPETCounterRegValue (0x00) #define kHPETConfigRegValue (0x20) #define kHPETCompRegValue (0x24) @@ -46,7 +48,7 @@ using namespace Kernel; HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); - auto hpet = (Detail::HPET_BLOCK*) power.Find("HPET").Leak().Leak(); + auto hpet = (Detail::HPET_BLOCK*) power.Find(kHPETSignature).Leak().Leak(); MUST_PASS(hpet); fDigitalTimer = (UInt8*) hpet->address.Address; -- cgit v1.2.3