diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-09 20:45:52 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-09 20:45:52 +0100 |
| commit | 89a0b8efb6491b93a8a373ad36c0a3872cd2ed44 (patch) | |
| tree | e75227186c7b5e1e99aa9b09da4cead2f6dfd3cc /dev/ZKAKit/HALKit | |
| parent | c72867a43cdedd28783e188b1d44d566b92b6a37 (diff) | |
IMP: PosixKit, to communicate with pureDarwin correctly.
IMP: Breakpoint interrupt has been implemented.
IMP: Interrupts handlers have been improved for AMD64 HAL.
Diffstat (limited to 'dev/ZKAKit/HALKit')
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 87 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm | 31 | ||||
| -rw-r--r-- | dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc | 4 |
3 files changed, 105 insertions, 17 deletions
diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index f6956793..149f2391 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -7,6 +7,7 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/UserProcessScheduler.h> #include <NewKit/KString.h> +#include <PosixKit/Signals.h> /// @brief Handle GPF fault. /// @param rsp @@ -21,13 +22,26 @@ EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { kcout << "Kernel: Page Fault.\r"; - Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + + kcout << "Kernel: SIGKILL set.\r"; + + auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess(); + + process.Leak().ProcessSignal.SignalIP = 0UL; + process.Leak().ProcessSignal.SignalID = SIGKILL; + process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status; + + kcout << "Kernel: PRCFROZE status set..\r"; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; + + process.Leak().Crash(); } /// @brief Handle scheduler interrupt. EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { - kcout << "Kernel: IRQ0.\r"; + kcout << "Kernel: Timer IRQ (Scheduler Notification).\r"; Kernel::UserProcessHelper::StartScheduling(); } @@ -35,16 +49,56 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { - kcout << "Kernel: Math.\r"; - Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + kcout << "Kernel: Math error (division by zero?).\r"; + + auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess(); + + process.Leak().ProcessSignal.SignalIP = 0UL; + process.Leak().ProcessSignal.SignalID = SIGKILL; + process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status; + + kcout << "Kernel: PRCFROZE status set..\r"; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; + + process.Leak().Crash(); } /// @brief Handle any generic fault. /// @param rsp EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { - kcout << "Kernel: Generic Fault.\r"; - Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + kcout << "Kernel: Generic Process Fault.\r"; + + auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess(); + + process.Leak().ProcessSignal.SignalIP = 0UL; + process.Leak().ProcessSignal.SignalID = SIGKILL; + process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status; + + kcout << "Kernel: PRCFROZE status set..\r"; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; + + process.Leak().Crash(); +} + +EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) +{ + auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess(); + + kcout << "Kernel: Process RIP: " << Kernel::number(rip) << endl; + kcout << "Kernel: Process Name: " << process.Leak().Name << endl; + + kcout << "Kernel: SIGTRAP set.\r"; + + process.Leak().ProcessSignal.SignalIP = rip; + process.Leak().ProcessSignal.SignalID = SIGTRAP; + process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status; + + kcout << "Kernel: PRCFROZE status set..\r"; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; } /// @brief Handle #UD fault. @@ -52,7 +106,18 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { kcout << "Kernel: Undefined Opcode.\r"; - Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); + + auto process = Kernel::UserProcessScheduler::The().GetCurrentProcess(); + + process.Leak().ProcessSignal.SignalIP = 0UL; + process.Leak().ProcessSignal.SignalID = SIGKILL; + process.Leak().ProcessSignal.PreviousStatus = process.Leak().Status; + + kcout << "Kernel: PRCFROZE status set..\r"; + + process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; + + process.Leak().Crash(); } /// @brief Enter syscall from assembly. @@ -91,7 +156,7 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, { if (rcx_kerncall_index < kKerncalls.Count()) { - kcout << "kerncall: Enter Kcall.\r"; + kcout << "kerncall: Enter Kernel Call List.\r"; if (kKerncalls[rcx_kerncall_index].fHooked) { @@ -101,14 +166,14 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, } else { - kcout << "kerncall: syscall isn't valid at all! (is nullptr)\r"; + kcout << "kerncall: Kernel call isn't valid at all! (is nullptr)\r"; } } else { - kcout << "kerncall: syscall isn't hooked at all! (is set to false)\r"; + kcout << "kerncall: Kernel call isn't hooked at all! (is set to false)\r"; } - kcout << "kerncall: Exit Kcall.\r"; + kcout << "kerncall: Exit Kernel Calls.\r"; } } diff --git a/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm index 9121edb9..293dafde 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKAKit/HALKit/AMD64/HalInterruptAPI.asm @@ -50,15 +50,42 @@ extern idt_handle_pf extern ke_io_write extern idt_handle_ud extern idt_handle_generic +extern idt_handle_breakpoint section .text IntNormal 0 IntNormal 1 - IntNormal 2 -IntNormal 3 +section .data + +__ZKA_INT_3_GET_RIP: + dq 0 +__ZKA_INT_3_GET_RIP_END: + +section .text + +;; @brief Triggers a breakpoint and freeze the process. RIP is also fetched. +__ZKA_INT_3: + cli + + mov al, 0x20 + out 0x20, al + out 0xA0, al + + push rax + mov rax, idt_handle_breakpoint + + lea rcx, [rel __ZKA_INT_3_GET_RIP] + mov [rcx], rcx + + call rax + pop rax + + sti + o64 iret + IntNormal 4 IntNormal 5 diff --git a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc index 8ac97a14..dd9a07b2 100644 --- a/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc +++ b/dev/ZKAKit/HALKit/AMD64/Storage/AHCI-DMA.cc @@ -242,8 +242,6 @@ Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Size { return; // Error in task file } - - kcout << Kernel::number((kAhciPort->Ci & 1)) << endl; } } @@ -311,8 +309,6 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::Siz Kernel::ke_stop(RUNTIME_CHECK_UNEXCPECTED); return; // Error in task file } - - kcout << Kernel::number((kAhciPort->Ci & 1)) << endl; } } |
