From a5851dfaa65d15f44f52b2aed1aa0179291b46fc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 12 Jun 2025 02:54:29 +0200 Subject: feat: libSystem, kernel: finalizing the hash and routing system of libSystem's handlers. feat: Rework TTY, and CD-ROM API too. Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/System.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'dev/libSystem') diff --git a/dev/libSystem/SystemKit/System.h b/dev/libSystem/SystemKit/System.h index 91899efe..421868ae 100644 --- a/dev/libSystem/SystemKit/System.h +++ b/dev/libSystem/SystemKit/System.h @@ -309,16 +309,20 @@ IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); // CD-ROM API. // ------------------------------------------------------------------------------------------ // -IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); +#define kCDDevicePath "/devices/dvd{}" -IMPORT_C SInt32 CdOpenTray(Void); +IMPORT_C IORef CdOpenTray(Void); + +IMPORT_C SInt32 CdEjectDrive(_Input IORef cdrom); IMPORT_C SInt32 CdCloseTray(Void); // ------------------------------------------------------------------------------------------ // -// Printer API. +// TTY API. // ------------------------------------------------------------------------------------------ // +#define kPrintDevicePath "/devices/tty{}" + IMPORT_C SInt32 PrintOut(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); IMPORT_C SInt32 PrintIn(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); -- cgit v1.2.3 From c336b4fe6f6488e14a3238a36d571d7645794971 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 12 Jun 2025 03:05:25 +0200 Subject: feat: Use `.dll` extension for `libSystem` instead of `.sys` Signed-off-by: Amlal El Mahrouss --- dev/boot/amd64-ci.make | 2 +- dev/boot/amd64-desktop.make | 2 +- dev/libSystem/libSystem.json | 2 +- dev/libSystem/src/Makefile | 2 +- dev/libSystem/src/SystemAPI.cc | 94 ++++++++++++++++++++++++++++++++++++++++ dev/libSystem/src/SystemImpl.cc | 94 ---------------------------------------- docs/drawio/SYSTEM_DESIGN.drawio | 2 +- 7 files changed, 99 insertions(+), 99 deletions(-) create mode 100644 dev/libSystem/src/SystemAPI.cc delete mode 100644 dev/libSystem/src/SystemImpl.cc (limited to 'dev/libSystem') diff --git a/dev/boot/amd64-ci.make b/dev/boot/amd64-ci.make index f4f76a59..12e6407b 100644 --- a/dev/boot/amd64-ci.make +++ b/dev/boot/amd64-ci.make @@ -73,7 +73,7 @@ BOOTLOADER=ne_bootz KERNEL=ne_kernel SYSCHK=chk.efi BOOTNET=net.efi -SCIKIT=libSystem.sys +SCIKIT=libSystem.dll .PHONY: invalid-recipe invalid-recipe: diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 2e487f94..4b6a879c 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -75,7 +75,7 @@ BOOTLOADER=ne_bootz KERNEL=ne_kernel SYSCHK=chk.efi BOOTNET=net.efi -SCIKIT=libSystem.sys +SCIKIT=libSystem.dll DDK=ddk.sys .PHONY: invalid-recipe diff --git a/dev/libSystem/libSystem.json b/dev/libSystem/libSystem.json index fdcd2a56..9df1b8f0 100644 --- a/dev/libSystem/libSystem.json +++ b/dev/libSystem/libSystem.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./"], "sources_path": ["src/*.cc", "src/*.stub.obj"], - "output_name": "libSystem.sys", + "output_name": "libSystem.dll", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/dev/libSystem/src/Makefile b/dev/libSystem/src/Makefile index 39af446b..64ef02cc 100644 --- a/dev/libSystem/src/Makefile +++ b/dev/libSystem/src/Makefile @@ -1,6 +1,6 @@ ################################################## # (c) Amlal El Mahrouss, all rights reserved. -# This file is for libSystem.sys's syscall stubs. +# This file is for libSystem.dll's syscall stubs. ################################################## ASM=nasm diff --git a/dev/libSystem/src/SystemAPI.cc b/dev/libSystem/src/SystemAPI.cc new file mode 100644 index 00000000..d0682830 --- /dev/null +++ b/dev/libSystem/src/SystemAPI.cc @@ -0,0 +1,94 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/// @file SystemAPI.cc +/// @brief System wide API for NeKernel. + +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; +} + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { + return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), + reinterpret_cast(const_cast(path)), + reinterpret_cast(const_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(2, desc); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { + auto ret = (volatile UInt64*) libsys_syscall_arg_3( + SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), reinterpret_cast(&off)); + + MUST_PASS((*ret) != ~0UL); + return *ret; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) { + auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), + reinterpret_cast(desc)); + return *ret; +} + +IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + + auto ret = (volatile UInt64*) libsys_syscall_arg_4( + SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), + reinterpret_cast(const_cast(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); + + libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break')); + } +} diff --git a/dev/libSystem/src/SystemImpl.cc b/dev/libSystem/src/SystemImpl.cc deleted file mode 100644 index d0682830..00000000 --- a/dev/libSystem/src/SystemImpl.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/// @file SystemAPI.cc -/// @brief System wide API for NeKernel. - -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; -} - -IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), - reinterpret_cast(const_cast(path)), - reinterpret_cast(const_cast(drv_letter))); -} - -IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(2, desc); -} - -IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (volatile UInt64*) libsys_syscall_arg_3( - SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), reinterpret_cast(&off)); - - MUST_PASS((*ret) != ~0UL); - return *ret; -} - -IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), - reinterpret_cast(desc)); - return *ret; -} - -IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { - va_list args; - - va_start(args, fmt); - - auto ret = (volatile UInt64*) libsys_syscall_arg_4( - SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), - reinterpret_cast(const_cast(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); - - libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break')); - } -} diff --git a/docs/drawio/SYSTEM_DESIGN.drawio b/docs/drawio/SYSTEM_DESIGN.drawio index c428d137..ffc625d4 100644 --- a/docs/drawio/SYSTEM_DESIGN.drawio +++ b/docs/drawio/SYSTEM_DESIGN.drawio @@ -4,7 +4,7 @@ - + -- cgit v1.2.3