From f8aaa274535b6541f376090958eedbbba3ba00ba Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 18:35:05 +0200 Subject: feat(kernel): Filesystem fixes, and others. what? - Add simple generic RTL8139 NIC driver, to be used within a NK device. - Update IVT accordingly. - Comment ARM's AP GIC init function, to tell what it's actually doing. - Cleanup Kernel Main, removed the useless pre_init_scheduler function. - Prepare new FileMgr with HeFileSystemMgr. - Fallback to NeFS when trying to format a fileysstem. Signed-off-by: Amlal El Mahrouss --- .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc (limited to 'dev/kernel/HALKit/AMD64/Network') diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc new file mode 100644 index 00000000..06c18d8b --- /dev/null +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -0,0 +1,81 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; +using namespace Kernel::HAL; + +STATIC UInt16 kIOBase = 0xFFFF; + +STATIC UInt32 kRXOffset = 0UL; +STATIC constexpr const UInt32 kRxBufferSize = 8192 + 16 + 1500; + +STATIC BOOL kTXEnabled = NO; + +STATIC UInt8* kRXUpperLayer = nullptr; +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); + + kRxBuffer = (UInt8*) rtl_dma_alloc(sizeof(UInt8) * kRxBufferSize, 0); + + MUST_PASS(kRxBuffer); + + /// Reset first. + + rt_out8(io_base + 0x37, 0x10); + + UInt16 timeout = 0U; + + while (rt_in8(io_base + 0x37) & 0x10) { + ++timeout; + if (timeout > 0x1000) break; + } + + MUST_PASS(timeout <= 0x1000); + + rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRxBuffer); + + rt_out8(io_base + 0x37, 0x0C); + + rt_out32(io_base + 0x44, 0xf | (1 << 7)); + + // Enable IRQ. + rt_out16(io_base + 0x3C, 0x0005); + + kTXEnabled = YES; +} + +EXTERN_C void rtl_rtl8139_interrupt_handler() { + if (kIOBase == 0xFFFF) return; + + UInt16 status = rt_in16(kIOBase + 0x3E); + rt_out16(kIOBase + 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); + + kRXUpperLayer[offset + 4] = *packet; + + kRXOffset += len + 4; + rt_out16(kIOBase + 0x38, (UInt16) (kRXOffset - 16)); + } + } + + if (!(status & 0x04)) { + err_global_get() = kErrorNoNetwork; + } +} \ No newline at end of file -- cgit v1.2.3