summaryrefslogtreecommitdiffhomepage
path: root/dev/libSystem/src
diff options
context:
space:
mode:
Diffstat (limited to 'dev/libSystem/src')
-rw-r--r--dev/libSystem/src/JailCalls.cc17
-rw-r--r--dev/libSystem/src/Makefile16
-rw-r--r--dev/libSystem/src/SystemCalls.cc169
-rw-r--r--dev/libSystem/src/SystemCallsABI+AMD64.asm81
-rw-r--r--dev/libSystem/src/Utils.cc29
-rw-r--r--dev/libSystem/src/VerifyCalls.cc18
6 files changed, 0 insertions, 330 deletions
diff --git a/dev/libSystem/src/JailCalls.cc b/dev/libSystem/src/JailCalls.cc
deleted file mode 100644
index f7ca5bec..00000000
--- a/dev/libSystem/src/JailCalls.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-/* ========================================
-
- Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#include <libSystem/SystemKit/Err.h>
-#include <libSystem/SystemKit/Jail.h>
-#include <libSystem/SystemKit/Syscall.h>
-#include <libSystem/SystemKit/System.h>
-#include <libSystem/SystemKit/Verify.h>
-
-using namespace LibSystem;
-
-IMPORT_C struct JAIL* JailGetCurrent(Void) {
- return (struct JAIL*) libsys_syscall_arg_1(SYSCALL_HASH("JailGetCurrent"));
-} \ No newline at end of file
diff --git a/dev/libSystem/src/Makefile b/dev/libSystem/src/Makefile
deleted file mode 100644
index 622223b4..00000000
--- a/dev/libSystem/src/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-##################################################
-# (c) Amlal El Mahrouss and NeKernel contributors, licensed under the Apache 2.0 license.
-# This file is for libSystem.dll's syscall stubs.
-##################################################
-
-ASM=nasm
-FLAGS=-f win64
-
-.PHONY: error
-error:
- @echo "==> Invalid recipe."
- @echo "==> Use libsys_asm_io_<arch> instead."
-
-.PHONY: libsys_asm_io_x64
-libsys_asm_io_x64:
- $(ASM) $(FLAGS) SystemCallsABI+AMD64.asm -o SystemCallsABI+AMD64.stub.obj
diff --git a/dev/libSystem/src/SystemCalls.cc b/dev/libSystem/src/SystemCalls.cc
deleted file mode 100644
index 7409c9b7..00000000
--- a/dev/libSystem/src/SystemCalls.cc
+++ /dev/null
@@ -1,169 +0,0 @@
-/* ========================================
-
- Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#include <libSystem/SystemKit/Err.h>
-#include <libSystem/SystemKit/Syscall.h>
-#include <libSystem/SystemKit/System.h>
-#include <libSystem/SystemKit/Verify.h>
-
-using namespace LibSystem;
-
-IMPORT_C Char* StrFmt(const Char* fmt, ...) {
- if (!fmt || *fmt == 0) return const_cast<Char*>("(null)");
-
- return const_cast<Char*>("");
-}
-
-// memmove-style copy
-IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) {
- // handles overlap, prefers 64-bit word copies when aligned
- if (!len || !dest || !src) return nullptr;
-
- auto s = static_cast<const UInt8*>(src);
- auto d = static_cast<UInt8*>(dest);
-
- if (d == s) return dest;
-
- // decide direction
- if (d > s && d < s + len) {
- const UInt8* rs = s + len;
- UInt8* rd = d + len;
-
- // try 64-bit aligned backward copy
- if (len >= sizeof(UInt64) && (reinterpret_cast<UIntPtr>(rs) % sizeof(UInt64) == 0) &&
- (reinterpret_cast<UIntPtr>(rd) % sizeof(UInt64) == 0)) {
- auto rsw = reinterpret_cast<const UInt64*>(rs);
- auto rdw = reinterpret_cast<UInt64*>(rd);
-
- SizeT words = len / sizeof(UInt64);
-
- for (SizeT i = 0; i < words; ++i) {
- rdw[-1 - static_cast<SizeT>(i)] = rsw[-1 - static_cast<SizeT>(i)];
- }
-
- SizeT rem = len % sizeof(UInt64);
- for (SizeT i = 0; i < rem; ++i) {
- rd[-1 - i] = rs[-1 - i];
- }
- } else {
- // byte-wise backward
- for (SizeT i = 0; i < len; ++i) {
- rd[-1 - i] = rs[-1 - i];
- }
- }
- } else {
- // try 64-bit aligned forward copy
- if (len >= sizeof(UInt64) && (reinterpret_cast<UIntPtr>(s) % sizeof(UInt64) == 0) &&
- (reinterpret_cast<UIntPtr>(d) % sizeof(UInt64) == 0)) {
- auto sw = reinterpret_cast<const UInt64*>(s);
- auto dw = reinterpret_cast<UInt64*>(d);
- SizeT words = len / sizeof(UInt64);
-
- for (SizeT i = 0; i < words; ++i) {
- dw[i] = sw[i];
- }
-
- SizeT rem = len % sizeof(UInt64);
- const SizeT offset = words * sizeof(UInt64);
- for (SizeT i = 0; i < rem; ++i) {
- d[offset + i] = s[offset + i];
- }
- } else {
- for (SizeT i = 0; i < len; ++i) {
- d[i] = s[i];
- }
- }
- }
-
- return dest;
-}
-
-IMPORT_C SInt64 MmStrLen(const Char* in) {
- // strlen via pointer walk
- if (!in) return -kErrorInvalidData;
-
- const Char* p = in;
- while (*p) ++p;
-
- return static_cast<SInt64>(p - in);
-}
-
-IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) {
- if (!len || !dest) return nullptr;
-
- auto d = static_cast<UInt8*>(dest);
-
- if (len >= sizeof(UInt64) && (reinterpret_cast<UIntPtr>(d) % sizeof(UInt64)) == 0) {
- UInt64 pattern = static_cast<UInt64>(value);
- pattern |= (pattern << 8);
- pattern |= (pattern << 16);
- pattern |= (pattern << 32);
-
- auto dw = reinterpret_cast<UInt64*>(d);
- SizeT words = len / sizeof(UInt64);
-
- for (SizeT i = 0; i < words; ++i) {
- dw[i] = pattern;
- }
-
- SizeT rem = len % sizeof(UInt64);
- const SizeT offset = words * sizeof(UInt64);
- for (SizeT i = 0; i < rem; ++i) {
- d[offset + i] = value;
- }
- } else {
- for (SizeT i = 0; i < len; ++i) d[i] = value;
- }
-
- return dest;
-}
-
-IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) {
- return static_cast<Ref>(libsys_syscall_arg_3(
- SYSCALL_HASH("IoOpenFile"), Verify::sys_safe_cast(path), Verify::sys_safe_cast(drv_letter)));
-}
-
-IMPORT_C Void IoCloseFile(_Input Ref desc) {
- libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast<VoidPtr>(desc));
-}
-
-IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) {
- auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("IoSeekFile"), static_cast<VoidPtr>(desc),
- reinterpret_cast<VoidPtr>(&off));
-
- if (!ret_ptr) return ~0UL;
-
- auto ret = static_cast<volatile UInt64*>(ret_ptr);
- UInt64 result = *ret;
- MUST_PASS(result != ~0UL);
- return result;
-}
-
-IMPORT_C UInt64 IoTellFile(_Input Ref desc) {
- auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), static_cast<VoidPtr>(desc));
- if (!ret_ptr) return ~0UL;
- auto ret = static_cast<volatile UInt64*>(ret_ptr);
- return *ret;
-}
-
-IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) {
- va_list args;
- va_start(args, fmt);
-
- auto buf = StrFmt(fmt, args);
-
- va_end(args);
-
- // if truncated, `needed` >= kBufferSz; we still send truncated buffer
- auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintOut"), static_cast<VoidPtr>(desc),
- Verify::sys_safe_cast(buf));
-
- if (!ret_ptr) return -kErrorInvalidData;
-
- auto ret = static_cast<const volatile SInt32*>(ret_ptr);
-
- return *ret;
-}
diff --git a/dev/libSystem/src/SystemCallsABI+AMD64.asm b/dev/libSystem/src/SystemCallsABI+AMD64.asm
deleted file mode 100644
index dd8fc9e8..00000000
--- a/dev/libSystem/src/SystemCallsABI+AMD64.asm
+++ /dev/null
@@ -1,81 +0,0 @@
-;; /*
-;; * ========================================================
-;; *
-;; * libSystem/src/SystemCallsABI+AMD64.asm
-;; * Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-;; *
-;; * ========================================================
-;; */
-
-[bits 64]
-
-section .text
-
-global libsys_syscall_arg_1
-global libsys_syscall_arg_2
-global libsys_syscall_arg_3
-global libsys_syscall_arg_4
-
-libsys_syscall_arg_1:
- push rbp
- mov rbp, rsp
-
- mov r8, rcx
-
- xor rax, rax
-
- syscall
-
- pop rbp
-
- ret
-
-libsys_syscall_arg_2:
- push rbp
- mov rbp, rsp
-
- mov r8, rcx
- mov r9, rdx
-
- xor rax, rax
-
- syscall
-
- pop rbp
-
- ret
-
-libsys_syscall_arg_3:
- push rbp
- mov rbp, rsp
-
- mov r8, rcx
- mov r9, rdx
- mov r10, rbx
-
- xor rax, rax
-
- syscall
-
- pop rbp
-
- ret
-
-libsys_syscall_arg_4:
- push rbp
- mov rbp, rsp
-
- mov rax, r8
-
- mov r8, rcx
- mov r9, rdx
- mov r10, rbx
- mov r11, rax
-
- xor rax, rax
-
- syscall
-
- pop rbp
-
- ret
diff --git a/dev/libSystem/src/Utils.cc b/dev/libSystem/src/Utils.cc
deleted file mode 100644
index 9d0920e0..00000000
--- a/dev/libSystem/src/Utils.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ========================================
-
- Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#include <libSystem/SystemKit/Err.h>
-#include <libSystem/SystemKit/Syscall.h>
-#include <libSystem/SystemKit/System.h>
-#include <libSystem/SystemKit/Verify.h>
-
-using namespace LibSystem;
-
-/// @note This uses the FNV 64-bit variant.
-IMPORT_C UInt64 libsys_hash_64(const Char* path) {
- if (!path || *path == 0) return 0;
-
- const UInt64 kFNVSeed = 0xcbf29ce484222325ULL;
- const UInt64 kFNVPrime = 0x100000001b3ULL;
-
- UInt64 hash = kFNVSeed;
-
- while (*path) {
- hash ^= (Char) (*path++);
- hash *= kFNVPrime;
- }
-
- return hash;
-}
diff --git a/dev/libSystem/src/VerifyCalls.cc b/dev/libSystem/src/VerifyCalls.cc
deleted file mode 100644
index 1c00612f..00000000
--- a/dev/libSystem/src/VerifyCalls.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-/* ========================================
-
- Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#include <libSystem/SystemKit/Err.h>
-#include <libSystem/SystemKit/Syscall.h>
-#include <libSystem/SystemKit/Verify.h>
-
-using namespace LibSystem;
-
-IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) {
- if (!expr) {
- PrintOut(nullptr, "Assertion failed: %s\r", origin);
- libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break"));
- }
-} \ No newline at end of file