summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/HALKit')
-rw-r--r--dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc8
-rw-r--r--dev/kernel/HALKit/AMD64/HalInterruptAPI.asm4
-rw-r--r--dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc53
3 files changed, 39 insertions, 26 deletions
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<UInt8*>(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));
}
}