From 386d9a5bffcd66633e4c3c72eb6cb25722796c92 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 May 2025 10:59:49 +0200 Subject: feat(kernel): Better syscall routing, also added new tools. what: - ping, manual have been added. - Rework RtlCurrentPID to SchedGetCurrentProcessID. - Cleanup codebase overall. Signed-off-by: Amlal El Mahrouss --- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 8 ++-- dev/kernel/HALKit/AMD64/HalInterruptAPI.asm | 4 ++ .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 53 +++++++++++++--------- dev/kernel/KernelKit/UserProcessScheduler.inl | 6 ++- dev/kernel/KernelKit/ZXD.h | 37 +++++++++++++++ dev/kernel/KernelKit/Zxd.h | 37 --------------- 6 files changed, 81 insertions(+), 64 deletions(-) create mode 100644 dev/kernel/KernelKit/ZXD.h delete mode 100644 dev/kernel/KernelKit/Zxd.h (limited to 'dev/kernel') diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index 54a79571..b70cd51f 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -19,15 +19,13 @@ STATIC BOOL kIsRunning = NO; /// @note STATIC void hal_idt_send_eoi(UInt8 vector) { ((volatile UInt32*) kApicBaseAddress)[0xB0 / 4] = 0; - + if (vector >= kPICCommand && vector <= 0x2F) { if (vector >= 0x28) { Kernel::HAL::rt_out8(kPIC2Command, kPICCommand); } Kernel::HAL::rt_out8(kPICCommand, kPICCommand); } - - kIsRunning = NO; } /// @brief Handle GPF fault. @@ -58,6 +56,8 @@ EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { /// @brief Handle scheduler interrupt. EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { + NE_UNUSED(rsp); + hal_idt_send_eoi(32); while (kIsRunning) @@ -65,7 +65,6 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { kIsRunning = YES; - NE_UNUSED(rsp); Kernel::UserProcessHelper::StartScheduling(); kIsRunning = NO; @@ -82,7 +81,6 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; process.Leak().Signal.Status = process.Leak().Status; - } /// @brief Handle any generic fault. diff --git a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm index 5e82f969..a0ff40dc 100644 --- a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -251,6 +251,8 @@ __NE_INT_50: mov rcx, r8 mov rdx, r9 + mov r8, r10 + mov r9, r11 call rax pop rax @@ -267,6 +269,8 @@ __NE_INT_51: mov rcx, r8 mov rdx, r9 + mov r8, r10 + mov r9, r11 call rax pop rax diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc index 38c12fee..7c611c26 100644 --- a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -11,15 +11,16 @@ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. using namespace Kernel; using namespace Kernel::HAL; -STATIC UInt16 kIOBase = 0xFFFF; - -STATIC UInt32 kRXOffset = 0UL; -STATIC constexpr CONST UInt32 kRxBufferSize = 8192 + 16 + 1500; +STATIC UInt16 kRTLIOBase = 0xFFFF; STATIC BOOL kTXEnabled = NO; +STATIC UInt32 kRXOffset = 0UL; + +STATIC constexpr CONST UInt32 kRXBufferSize = 8192 + 16 + 1500; + STATIC UInt8* kRXUpperLayer = nullptr; -STATIC UInt8* kRxBuffer = nullptr; +STATIC UInt8* kRXBuffer = nullptr; /***********************************************************************************/ ///@brief RTL8139 Init routine. @@ -28,12 +29,13 @@ STATIC UInt8* kRxBuffer = nullptr; EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { if (kTXEnabled) return; - kIOBase = io_base; - MUST_PASS(io_base); + kRTLIOBase = io_base; - kRxBuffer = (UInt8*) rtl_dma_alloc(sizeof(UInt8) * kRxBufferSize, 0); + MUST_PASS(io_base != 0xFFFF); - MUST_PASS(kRxBuffer); + kRXBuffer = reinterpret_cast(rtl_dma_alloc(sizeof(UInt8) * kRXBufferSize, 0)); + + MUST_PASS(kRXBuffer); /// Reset first. @@ -51,11 +53,11 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { return; } - rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRxBuffer); + rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRXBuffer); rt_out8(io_base + 0x37, 0x0C); - rt_out32(io_base + 0x44, 0xf | (1 << 7)); + rt_out32(io_base + 0x44, 0xF | (1 << 7)); rt_out16(io_base + 0x3C, 0x0005); @@ -68,21 +70,30 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { /***********************************************************************************/ EXTERN_C void rtl_rtl8139_interrupt_handler() { - if (kIOBase == 0xFFFF) return; + if (kRTLIOBase == 0xFFFF) return; - UInt16 status = rt_in16(kIOBase + 0x3E); - rt_out16(kIOBase + 0x3E, status); + UInt16 status = rt_in16(kRTLIOBase + 0x3E); + rt_out16(kRTLIOBase + 0x3E, status); if (status & 0x01) { - while ((rt_in8(kIOBase + 0x37) & 0x01) == 0) { - UInt32 offset = kRXOffset % kRxBufferSize; - volatile UInt8* packet = kRxBuffer + offset + 4; - UInt16 len = *(UInt16*) (kRxBuffer + offset + 2); + // While we receive data. + while ((rt_in8(kRTLIOBase + 0x37) & 0x01) == 0) { + // We grab an offset from the RX buffer. + UInt32 offset = kRXOffset % kRXBufferSize; + + // If the offset is too high, we reset it. + if (offset >= (kRXBufferSize - 16)) { + kRXOffset = 0UL; + offset = 0UL; + } + + volatile UInt8* packet = kRXBuffer + offset + 4; + UInt16 len = *(UInt16*) (kRXBuffer + offset + 2); - kRXUpperLayer[offset + 4] = *packet; + kRXUpperLayer[(offset + 4)] = *packet; + kRXOffset += (len + 4); - kRXOffset += len + 4; - rt_out16(kIOBase + 0x38, (UInt16) (kRXOffset - 16)); + rt_out16(kRTLIOBase + 0x38, (UInt16) (kRXOffset - 16)); } } diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index 156aa0b5..df35e037 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -11,13 +11,17 @@ /// @author Amlal El Mahrouss (amlal@nekernel.org) /// @date Tue Apr 22 22:01:07 CEST 2025 +#ifndef INC_PROCESS_SCHEDULER_H +#include +#endif // INC_PROCESS_SCHEDULER_H + namespace Kernel { /***********************************************************************************/ /** @brief Free pointer from usage. */ /***********************************************************************************/ template -Boolean USER_PROCESS::Delete(ErrorOr ptr) { +BOOL USER_PROCESS::Delete(ErrorOr ptr) { if (!ptr) return No; if (!this->HeapTree) { diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h new file mode 100644 index 00000000..d2456f51 --- /dev/null +++ b/dev/kernel/KernelKit/ZXD.h @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace ZXD { +using namespace Kernel; + +struct ZXD_EXEC_HEADER; +struct ZXD_STUB_HEADER; + +/// @brief ZXD executable header +/// @details This header is used to identify ZXD executable files. +struct ZXD_EXEC_HEADER { + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; +}; + +/// @brief ZXD stub header +/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the +/// offset of the stub, and the CRC32 checksum of the stub. +struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { + UInt32 fStubSize; + UInt32 fStubOffset; + UInt32 fStubCRC32; +}; +} // namespace ZXD \ No newline at end of file diff --git a/dev/kernel/KernelKit/Zxd.h b/dev/kernel/KernelKit/Zxd.h deleted file mode 100644 index d2456f51..00000000 --- a/dev/kernel/KernelKit/Zxd.h +++ /dev/null @@ -1,37 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace ZXD { -using namespace Kernel; - -struct ZXD_EXEC_HEADER; -struct ZXD_STUB_HEADER; - -/// @brief ZXD executable header -/// @details This header is used to identify ZXD executable files. -struct ZXD_EXEC_HEADER { - UInt32 fMagic; - UInt32 fVersion; - UInt32 fFlags; - UInt32 fHdrSize; - UInt32 fCRC32; - UInt32 fAssigneeSignature; - UInt32 fIssuerSingature; -}; - -/// @brief ZXD stub header -/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the -/// offset of the stub, and the CRC32 checksum of the stub. -struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { - UInt32 fStubSize; - UInt32 fStubOffset; - UInt32 fStubCRC32; -}; -} // namespace ZXD \ No newline at end of file -- cgit v1.2.3