diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 09:35:23 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-21 09:35:23 +0200 |
| commit | 0bb0eb7952edbe2d14a071abe9eeff6e8b1b51ee (patch) | |
| tree | 754cb3da25aa7a22c30beed40b417f3622c6866c /dev/zka/HALKit | |
| parent | 94bb3c0e7bdca4e5cd85a576a98b0b19847b597c (diff) | |
IMP: Improved many things, and looking at how to fix the interrupts
issue.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/zka/HALKit')
| -rw-r--r-- | dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx | 49 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx | 16 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/HalInterruptAPI.asm | 82 | ||||
| -rw-r--r-- | dev/zka/HALKit/AMD64/HalKernelMain.cxx | 13 |
4 files changed, 43 insertions, 117 deletions
diff --git a/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx b/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx index a76fde89..b6edce6e 100644 --- a/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx +++ b/dev/zka/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cxx @@ -4,25 +4,19 @@ ------------------------------------------- */ -#include "NewKit/Stop.hxx" #include <ArchKit/ArchKit.hxx> #include <KernelKit/UserProcessScheduler.hxx> #include <NewKit/String.hxx> namespace Kernel { - EXTERN UserProcessScheduler* cProcessScheduler; + EXTERN UserProcessScheduler* kProcessScheduler; } /// @brief Handle GPF fault. /// @param rsp EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) { - if (Kernel::cProcessScheduler == nullptr) - { - Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); - } - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); } @@ -30,16 +24,11 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { - if (Kernel::cProcessScheduler == nullptr) - { - Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); - } - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); } /// @brief Handle scheduler interrupt. -EXTERN_C void idt_handle_scheduler() +EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { Kernel::UserProcessHelper::StartScheduling(); } @@ -48,43 +37,21 @@ EXTERN_C void idt_handle_scheduler() /// @param rsp EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { - if (Kernel::cProcessScheduler == nullptr) - { - Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); - } - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); - - Kernel::UserProcessHelper::StartScheduling(); - Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } /// @brief Handle any generic fault. /// @param rsp EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { - if (Kernel::cProcessScheduler == nullptr) - { - Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); - } - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); - Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } /// @brief Handle #UD fault. /// @param rsp EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { - if (Kernel::cProcessScheduler == nullptr) - { - Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); - } - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); - - Kernel::UserProcessHelper::StartScheduling(); - Kernel::ke_stop(RUNTIME_CHECK_PROCESS); } /// @brief Enter syscall from assembly. @@ -92,16 +59,14 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) /// @return nothing. EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr rdx) { - Kernel::HAL::Out8(0x20, 0x20); // Acknowledge interrupt to master PIC - if (rcx <= (kSyscalls.Count() - 1)) { - kcout << "syscall: Enter Fn.\r"; + kcout << "syscall: Enter Syscall.\r"; if (kSyscalls[rcx].fHooked) (kSyscalls[rcx].fProc)((Kernel::VoidPtr)rdx); - kcout << "syscall: Exit Fn.\r"; + kcout << "syscall: Exit Syscall.\r"; } } @@ -110,15 +75,13 @@ EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr /// @return nothing. EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx, Kernel::UIntPtr rdx, Kernel::UIntPtr r8, Kernel::UIntPtr r9) { - Kernel::HAL::Out8(0x20, 0x20); // Acknowledge interrupt to master PIC - if (rcx <= (kSyscalls.Count() - 1)) { - kcout << "kerncall: Enter Fn.\r"; + kcout << "kerncall: Enter Kcall.\r"; if (kKerncalls[rcx].fHooked) (kKerncalls[rcx].fProc)((Kernel::VoidPtr)rdx); - kcout << "kerncall: Exit Fn.\r"; + kcout << "kerncall: Exit Kcall.\r"; } } diff --git a/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx index ba893515..822d7dac 100644 --- a/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx +++ b/dev/zka/HALKit/AMD64/HalDescriptorLoader.cxx @@ -14,8 +14,14 @@ namespace Kernel::HAL STATIC ::Kernel::Detail::AMD64::InterruptDescriptorAMD64 kInterruptVectorTable[kKernelIdtSize]; + STATIC void hal_set_irq_mask(UInt8 irql); + STATIC void hal_clear_irq_mask(UInt8 irql); + STATIC Void hal_enable_pit(UInt16 ticks) noexcept { + if (ticks == 0) + ticks = 1000; + // Configure PIT to receieve scheduler interrupts. UInt16 cCommonDivisor = kPITFrequency / ticks; // 100 Hz. @@ -23,6 +29,8 @@ namespace Kernel::HAL HAL::Out8(kPITControlPort, 0x36); // Command to PIT HAL::Out8(kPITChannel0Port, cCommonDivisor & 0xFF); // Send low byte HAL::Out8(kPITChannel0Port, (cCommonDivisor >> 8) & 0xFF); // Send high byte + + hal_clear_irq_mask(32); } STATIC void hal_set_irq_mask(UInt8 irql) @@ -74,9 +82,7 @@ namespace Kernel::HAL Void IDTLoader::Load(Register64& idt) { - rt_cli(); - - const auto cPITTickForScheduler = 1000; + const auto kPITTickForScheduler = 100; volatile ::Kernel::UIntPtr** ptr_ivt = (volatile ::Kernel::UIntPtr**)idt.Base; @@ -99,9 +105,7 @@ namespace Kernel::HAL hal_load_idt(idt); - Detail::hal_enable_pit(cPITTickForScheduler); - - rt_sti(); + Detail::hal_enable_pit(kPITTickForScheduler); } void GDTLoader::Load(Ref<RegisterGDT>& gdt) diff --git a/dev/zka/HALKit/AMD64/HalInterruptAPI.asm b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm index 936f71c8..e611fdf1 100644 --- a/dev/zka/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/zka/HALKit/AMD64/HalInterruptAPI.asm @@ -16,16 +16,18 @@ %macro IntExp 1 global __ZKA_INT_%1 __ZKA_INT_%1: - cli - sti + mov al, 0x20 + out 0x21, al + o64 iret %endmacro %macro IntNormal 1 global __ZKA_INT_%1 __ZKA_INT_%1: - cli - sti + mov al, 0x20 + out 0x21, al + o64 iret %endmacro @@ -54,38 +56,24 @@ IntNormal 5 ;; Invalid opcode interrupt __ZKA_INT_6: - cli - mov al, 0x20 out 0x20, al - push rax - mov rcx, rsp call idt_handle_ud - pop rax - - sti o64 iret IntNormal 7 ;; Invalid opcode interrupt __ZKA_INT_8: - cli - mov al, 0x20 out 0x21, al - push rax - mov rcx, rsp call idt_handle_generic - pop rax - - sti o64 iret IntNormal 9 @@ -95,36 +83,21 @@ IntExp 11 IntExp 12 __ZKA_INT_13: - cli - mov al, 0x20 out 0x21, al - push rax - mov rcx, rsp call idt_handle_gpf - pop rax - - sti o64 iret __ZKA_INT_14: - cli - mov al, 0x20 out 0x21, al - push rax - mov rcx, rsp call idt_handle_pf - pop rax - - sti - o64 iret IntNormal 15 @@ -153,17 +126,8 @@ __ZKA_INT_32: mov al, 0x20 out 0x21, al - push rbp - push rsp - push rcx - push rdx - push r8 - jmp idt_handle_scheduler - pop rsp - pop rbp - pop rcx - pop rdx - pop r8 + mov rcx, rsp + call idt_handle_scheduler o64 iret @@ -192,40 +156,32 @@ IntNormal 49 [extern hal_kernel_call_enter] __ZKA_INT_50: + cli + mov al, 0x20 out 0x21, al - push r8 - push r9 - push r10 - push rsp + mov rcx, r8 + mov rdx, r9 jmp hal_system_call_enter - add rsp, 16 - pop rsp - pop r10 - pop r9 - pop r8 + sti o64 iret __ZKA_INT_51: + cli + mov al, 0x20 out 0x21, al - push r8 - push r9 - push r10 - push rsp + mov rcx, r8 + mov rdx, r9 call hal_kernel_call_enter - add rsp, 16 - pop rsp - pop r10 - pop r9 - pop r8 + sti o64 iret @@ -352,6 +308,8 @@ hal_load_idt: out 0x21, al out 0xA1, al + sti + ret section .data diff --git a/dev/zka/HALKit/AMD64/HalKernelMain.cxx b/dev/zka/HALKit/AMD64/HalKernelMain.cxx index 17bd99f3..1a4fc830 100644 --- a/dev/zka/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/zka/HALKit/AMD64/HalKernelMain.cxx @@ -22,8 +22,8 @@ namespace Kernel::HAL namespace Kernel { - EXTERN UserProcessScheduler* cProcessScheduler; - EXTERN HardwareThreadScheduler* cHardwareThreadScheduler; + EXTERN UserProcessScheduler* kProcessScheduler; + EXTERN HardwareThreadScheduler* kHardwareThreadScheduler; } // namespace Kernel EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; @@ -36,8 +36,8 @@ EXTERN_C void hal_init_platform( { kHandoverHeader = HandoverHeader; - Kernel::cProcessScheduler = nullptr; - Kernel::cHardwareThreadScheduler = nullptr; + Kernel::kProcessScheduler = nullptr; + Kernel::kHardwareThreadScheduler = nullptr; if (kHandoverHeader->f_Magic != kHandoverMagic && kHandoverHeader->f_Version != kHandoverVersion) @@ -94,7 +94,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled) Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - /* Load System.exe here (TODO) */ + /* Load OSLdr.exe here (TODO) */ Kernel::HAL::Register64 idt_reg; idt_reg.Base = (Kernel::UIntPtr)kInterruptVectorTable; @@ -103,5 +103,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept Kernel::HAL::IDTLoader idt_loader; idt_loader.Load(idt_reg); - Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP); + while (Yes) + ; } |
