summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-24 10:59:49 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-05-24 10:59:49 +0200
commit386d9a5bffcd66633e4c3c72eb6cb25722796c92 (patch)
tree438158dbf0856bf2563cdc9e4b183e290f4bb03a
parente89d4a1402bdd32b8ad7e2ed04278b7ad54740c3 (diff)
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 <amlal@nekernel.org>
-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
-rw-r--r--dev/kernel/KernelKit/UserProcessScheduler.inl6
-rw-r--r--dev/kernel/KernelKit/ZXD.h (renamed from dev/kernel/KernelKit/Zxd.h)0
-rw-r--r--dev/user/SystemCalls.h14
-rw-r--r--dev/user/src/SystemCalls+IO.asm9
-rw-r--r--public/tools/manual/.keep0
-rw-r--r--public/tools/manual/manual.json19
-rw-r--r--public/tools/manual/src/.keep0
-rw-r--r--public/tools/manual/src/CommandLine.cc13
-rw-r--r--public/tools/manual/vendor/.keep0
-rw-r--r--public/tools/ping/.keep0
-rw-r--r--public/tools/ping/ping.json19
-rw-r--r--public/tools/ping/src/.keep0
-rw-r--r--public/tools/ping/src/CommandLine.cc29
-rw-r--r--public/tools/ping/vendor/.keep0
-rwxr-xr-xtooling/mk_app.py4
-rwxr-xr-xtooling/mk_fwrk.py4
-rwxr-xr-xtooling/mk_img.py4
20 files changed, 137 insertions, 49 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));
}
}
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 <KernelKit/UserProcessScheduler.h>
+#endif // INC_PROCESS_SCHEDULER_H
+
namespace Kernel {
/***********************************************************************************/
/** @brief Free pointer from usage. */
/***********************************************************************************/
template <typename T>
-Boolean USER_PROCESS::Delete(ErrorOr<T*> ptr) {
+BOOL USER_PROCESS::Delete(ErrorOr<T*> ptr) {
if (!ptr) return No;
if (!this->HeapTree) {
diff --git a/dev/kernel/KernelKit/Zxd.h b/dev/kernel/KernelKit/ZXD.h
index d2456f51..d2456f51 100644
--- a/dev/kernel/KernelKit/Zxd.h
+++ b/dev/kernel/KernelKit/ZXD.h
diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h
index d40dc127..e8b4e59c 100644
--- a/dev/user/SystemCalls.h
+++ b/dev/user/SystemCalls.h
@@ -331,19 +331,17 @@ IMPORT_C IORef PrintGet(const Char* path);
typedef SInt32 AffinityRef;
typedef UInt64 ProcessRef;
-IMPORT_C SInt32 SchedSetAffinity(ProcessRef, SInt32 req, AffinityRef* local);
+IMPORT_C SInt32 SchedSetAffinity(_Input ProcessRef, SInt32 req, _Input AffinityRef*);
-IMPORT_C SInt32 SchedGetAffinity(ProcessRef, AffinityRef* local);
+IMPORT_C SInt32 SchedGetAffinity(_Input ProcessRef, _InOut AffinityRef*);
-IMPORT_C SInt32 SchedFireSignal(ProcessRef, SInt32 req);
+IMPORT_C SInt32 SchedFireSignal(_Input ProcessRef, SInt32);
-IMPORT_C SInt32 SchedReadMemory(ProcessRef, SInt32 address, SInt32 data);
+IMPORT_C SInt32 SchedReadMemory(_Input ProcessRef, SInt32, SInt32);
-IMPORT_C SInt32 SchedWriteMemory(ProcessRef, SInt32 address, SInt32 data);
+IMPORT_C SInt32 SchedWriteMemory(_Input ProcessRef, SInt32, SInt32);
-/// @brief Get current ProcessRef of process.
-/// @return Current process ID.
-IMPORT_C UIntPtr RtlCurrentPID(Void);
+IMPORT_C UIntPtr SchedGetCurrentProcessID(Void);
// ------------------------------------------------------------------------------------------ //
// @brief Filesystem API.
diff --git a/dev/user/src/SystemCalls+IO.asm b/dev/user/src/SystemCalls+IO.asm
index 9126b7de..097046af 100644
--- a/dev/user/src/SystemCalls+IO.asm
+++ b/dev/user/src/SystemCalls+IO.asm
@@ -1,7 +1,7 @@
;; /*
;; * ========================================================
;; *
-;; * user/src/SystemCalls+IO.asm
+;; * libSystem/src/SystemCalls+IO.asm
;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
;; *
;; * ========================================================
@@ -9,8 +9,6 @@
[bits 64]
-;; @brief Syscall dispatch, also taking note the Microsoft's calling convention to translate it to NeKernel's ABI.
-
section .text
global sci_syscall_arg_1
@@ -44,8 +42,6 @@ sci_syscall_arg_3:
push rbp
mov rbp, rsp
- mov rbx, r8
-
mov r8, rcx
mov r9, rdx
mov r10, rbx
@@ -59,9 +55,6 @@ sci_syscall_arg_4:
push rbp
mov rbp, rsp
- mov rbx, r8
- mov rax, r9
-
mov r8, rcx
mov r9, rdx
mov r10, rbx
diff --git a/public/tools/manual/.keep b/public/tools/manual/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/manual/.keep
diff --git a/public/tools/manual/manual.json b/public/tools/manual/manual.json
new file mode 100644
index 00000000..04626145
--- /dev/null
+++ b/public/tools/manual/manual.json
@@ -0,0 +1,19 @@
+{
+ "compiler_path": "clang++",
+ "compiler_std": "c++20",
+ "headers_path": [
+ "./",
+ "../../../dev/kernel",
+ "../../../public/frameworks/",
+ "../../../dev/",
+ "./"
+ ],
+ "sources_path": [],
+ "output_name": "./dist/manual",
+ "cpp_macros": [
+ "kSampleFWVersion=0x0100",
+ "kSampleFWVersionHighest=0x0100",
+ "kSampleFWVersionLowest=0x0100",
+ "__NE_SDK__"
+ ]
+} \ No newline at end of file
diff --git a/public/tools/manual/src/.keep b/public/tools/manual/src/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/manual/src/.keep
diff --git a/public/tools/manual/src/CommandLine.cc b/public/tools/manual/src/CommandLine.cc
new file mode 100644
index 00000000..0d9c4136
--- /dev/null
+++ b/public/tools/manual/src/CommandLine.cc
@@ -0,0 +1,13 @@
+#include <user/SystemCalls.h>
+
+SInt32 _NeMain(SInt32 argc, Char* argv[]) {
+ SCI_UNUSED(argc);
+ SCI_UNUSED(argv);
+
+ if (argc < 2) {
+ PrintOut(nullptr, "HELP: manual <tutorial_name>\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+} \ No newline at end of file
diff --git a/public/tools/manual/vendor/.keep b/public/tools/manual/vendor/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/manual/vendor/.keep
diff --git a/public/tools/ping/.keep b/public/tools/ping/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/ping/.keep
diff --git a/public/tools/ping/ping.json b/public/tools/ping/ping.json
new file mode 100644
index 00000000..d8d4133a
--- /dev/null
+++ b/public/tools/ping/ping.json
@@ -0,0 +1,19 @@
+{
+ "compiler_path": "clang++",
+ "compiler_std": "c++20",
+ "headers_path": [
+ "./",
+ "../../../dev/kernel",
+ "../../../public/frameworks/",
+ "../../../dev/",
+ "./"
+ ],
+ "sources_path": [],
+ "output_name": "./dist/ping",
+ "cpp_macros": [
+ "kSampleFWVersion=0x0100",
+ "kSampleFWVersionHighest=0x0100",
+ "kSampleFWVersionLowest=0x0100",
+ "__NE_SDK__"
+ ]
+} \ No newline at end of file
diff --git a/public/tools/ping/src/.keep b/public/tools/ping/src/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/ping/src/.keep
diff --git a/public/tools/ping/src/CommandLine.cc b/public/tools/ping/src/CommandLine.cc
new file mode 100644
index 00000000..9aae0ea9
--- /dev/null
+++ b/public/tools/ping/src/CommandLine.cc
@@ -0,0 +1,29 @@
+#include <user/SystemCalls.h>
+
+SInt32 _NeMain(SInt32 argc, Char* argv[]) {
+ SCI_UNUSED(argc);
+
+ if (argc < 2) {
+ PrintOut(nullptr, "HELP: ping <hostname>\n");
+ return EXIT_FAILURE;
+ }
+
+ PrintOut(nullptr, "Pinging %s...\n", argv[1]);
+
+ for (SizeT i = 0U; i < 4; ++i) {
+ SInt32 result = 0;
+
+ if (result != 0) {
+ PrintOut(nullptr, "Request timed out.\n");
+ return EXIT_FAILURE;
+ }
+
+ SInt32 bytes = 64; // Simulated response size
+ SInt32 time = 100 + (i * 10); // Simulated response time
+ SInt32 ttl = 64;
+
+ PrintOut(nullptr, "Reply from %s: bytes=%i time=%ims TTL=%i\n", argv[1], bytes, time, ttl);
+ }
+
+ return EXIT_SUCCESS;
+} \ No newline at end of file
diff --git a/public/tools/ping/vendor/.keep b/public/tools/ping/vendor/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/public/tools/ping/vendor/.keep
diff --git a/tooling/mk_app.py b/tooling/mk_app.py
index 9418cf05..a40c6dee 100755
--- a/tooling/mk_app.py
+++ b/tooling/mk_app.py
@@ -71,10 +71,10 @@ def create_directory_structure(base_path, project_name):
if __name__ == "__main__":
if len(sys.argv) != 2:
- print("Usage: mk_app.py <project_name>")
+ print("HELP: mk_app.py <project_name>")
sys.exit(os.EX_CONFIG)
base_path = os.getcwd() # Use the current working directory as the base path
create_directory_structure(base_path, sys.argv[1])
- print("Info: Application created successfully.")
+ print("INFO: Application created successfully.")
diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py
index 3c73e88e..78659686 100755
--- a/tooling/mk_fwrk.py
+++ b/tooling/mk_fwrk.py
@@ -83,10 +83,10 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name):
if __name__ == "__main__":
if len(sys.argv) != 2:
- print("Usage: mk_fwrk.py <project_name>")
+ print("HELP: mk_fwrk.py <project_name>")
sys.exit(os.EX_CONFIG)
base_path = os.getcwd() # Use the current working directory as the base path
create_directory_structure(base_path, sys.argv[1], sys.argv[1] + '.fwrk')
- print("Info: Framework created successfully.")
+ print("INFO: Framework created successfully.")
diff --git a/tooling/mk_img.py b/tooling/mk_img.py
index 539353fc..28af22e3 100755
--- a/tooling/mk_img.py
+++ b/tooling/mk_img.py
@@ -30,7 +30,7 @@ def copy_to_fat(image_path, source_dir):
if __name__ == "__main__":
if len(sys.argv) != 3:
- print("Usage: mk_img.py <fat32_image> <source_directory>")
+ print("HELP: mk_img.py <fat32_image> <source_directory>")
sys.exit(1)
image_path = sys.argv[1]
@@ -38,4 +38,4 @@ if __name__ == "__main__":
copy_to_fat(image_path, source_dir)
- print("Info: image created successfully.")
+ print("INFO: Image created successfully.")