diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-27 20:03:26 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-27 20:06:13 +0200 |
| commit | 1a44b4385b3250cd90e255d7d787ae69e987544b (patch) | |
| tree | fb637575951b8cc98834bed59daf4072583d5a17 /dev/libSystem/src | |
| parent | bdc831c1df0dd2af95f09fd1b86b4472c40d12b7 (diff) | |
feat: generic_kits: Add X64Chrono inside BenchKit.
refactor: libSystem: Refactored as a whole.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/libSystem/src')
| -rw-r--r-- | dev/libSystem/src/GNUmakefile | 16 | ||||
| -rw-r--r-- | dev/libSystem/src/System.cc | 94 | ||||
| -rw-r--r-- | dev/libSystem/src/SystemCalls+IO.asm | 66 |
3 files changed, 176 insertions, 0 deletions
diff --git a/dev/libSystem/src/GNUmakefile b/dev/libSystem/src/GNUmakefile new file mode 100644 index 00000000..9b901f9f --- /dev/null +++ b/dev/libSystem/src/GNUmakefile @@ -0,0 +1,16 @@ +################################################## +# (c) Amlal El Mahrouss, all rights reserved. +# This file is for libSystem.sys's syscall stubs. +################################################## + +ASM=nasm +FLAGS=-f win64 + +.PHONY: error +error: + @echo "==> Invalid rule." + @echo "==> Use sci_asm_io_<arch> instead." + +.PHONY: sci_asm_io_x64 +sci_asm_io_x64: + $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.stub.obj diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc new file mode 100644 index 00000000..1c28303d --- /dev/null +++ b/dev/libSystem/src/System.cc @@ -0,0 +1,94 @@ +/* -------------------------------------------
+
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#include <libSystem/AsmProc.h>
+#include <libSystem/System.h>
+
+/// @file SystemCalls.cc
+/// @brief Source file for the memory functions/syscalls for libSystem.sys
+
+IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) {
+ if (!len || !dest || !src) {
+ return nullptr;
+ }
+
+ for (SizeT i = 0; i < len; i++) {
+ ((Char*) dest)[i] = ((Char*) src)[i];
+ }
+
+ return dest;
+}
+
+IMPORT_C SInt64 MmStrLen(const Char* in) {
+ if (!in) return 0;
+
+ SizeT len{0};
+
+ do {
+ ++len;
+ } while (in[len] != '\0');
+
+ return len;
+}
+
+IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) {
+ if (!len || !dest) {
+ return nullptr;
+ }
+
+ for (SizeT i = 0; i < len; i++) {
+ ((Char*) dest)[i] = value;
+ }
+
+ return dest;
+}
+
+//-----------------------------------------------------------------------------------------------------------//
+/// @brief Systems Calls implementation.
+/// @internal
+//-----------------------------------------------------------------------------------------------------------//
+
+IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) {
+ return sci_syscall_arg_3(1, reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
+}
+
+IMPORT_C Void IoCloseFile(_Input Ref desc) {
+ sci_syscall_arg_2(2, desc);
+}
+
+IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) {
+ auto ret = (volatile UInt64*) sci_syscall_arg_3(3, reinterpret_cast<VoidPtr>(desc),
+ reinterpret_cast<VoidPtr>(&off));
+
+ MUST_PASS((*ret) != ~0UL);
+ return *ret;
+}
+
+IMPORT_C UInt64 IoTellFile(_Input Ref desc) {
+ auto ret = (volatile UInt64*) sci_syscall_arg_2(4, reinterpret_cast<VoidPtr>(desc));
+ return *ret;
+}
+
+IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) {
+ va_list args;
+
+ va_start(args, fmt);
+
+ auto ret = (volatile UInt64*) sci_syscall_arg_4(
+ 5, reinterpret_cast<VoidPtr>(desc), reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
+
+ va_end(args);
+
+ return *ret;
+}
+
+IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) {
+ if (!expr) {
+ PrintOut(nullptr, "Assertion failed: %s\r", origin);
+ PrintOut(nullptr, "Origin: %s\r", origin);
+ }
+}
diff --git a/dev/libSystem/src/SystemCalls+IO.asm b/dev/libSystem/src/SystemCalls+IO.asm new file mode 100644 index 00000000..097046af --- /dev/null +++ b/dev/libSystem/src/SystemCalls+IO.asm @@ -0,0 +1,66 @@ +;; /* +;; * ======================================================== +;; * +;; * libSystem/src/SystemCalls+IO.asm +;; * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. +;; * +;; * ======================================================== +;; */ + +[bits 64] + +section .text + +global sci_syscall_arg_1 +global sci_syscall_arg_2 +global sci_syscall_arg_3 +global sci_syscall_arg_4 + +sci_syscall_arg_1: + push rbp + mov rbp, rsp + + mov r8, rcx + syscall + + pop rbp + + ret + +sci_syscall_arg_2: + push rbp + mov rbp, rsp + + mov r8, rcx + mov r9, rdx + syscall + pop rbp + + ret + +sci_syscall_arg_3: + push rbp + mov rbp, rsp + + mov r8, rcx + mov r9, rdx + mov r10, rbx + + syscall + pop rbp + + ret + +sci_syscall_arg_4: + push rbp + mov rbp, rsp + + mov r8, rcx + mov r9, rdx + mov r10, rbx + mov r11, rax + + syscall + pop rbp + + ret |
