From 38a534c90e682bd4ce3d176127520f0ff513fb11 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 13 May 2025 23:49:28 +0200 Subject: feat(kernel): expand KDBG packet structure, and prefix hexadecimal numbers with 0x100, instead of 100h. Signed-off-by: Amlal El Mahrouss --- dev/user/SystemCalls.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/user') diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index 5bbe2f26..61021a01 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -7,8 +7,8 @@ Purpose: System Call Interface. ------------------------------------------- */ -#ifndef SCI_SCI_H -#define SCI_SCI_H +#ifndef SCI_SYSTEM_CALLS_H +#define SCI_SYSTEM_CALLS_H #include @@ -362,4 +362,4 @@ IMPORT_C Char* StrFmt(const Char* fmt, ...); IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); -#endif // ifndef SCI_SCI_H +#endif // ifndef SCI_SYSTEM_CALLS_H -- cgit v1.2.3 From 9fcff991059ff5cdbdf71848039e7b56ccd5bc49 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 09:53:11 +0200 Subject: feat(kernel): add ddk.sys to the build flow, finished the mk_fwrk CLI. Signed-off-by: Amlal El Mahrouss --- dev/boot/amd64-desktop.make | 2 ++ dev/ddk/src/ddk_rt_cxx.cc | 8 ++++---- dev/user/Opts.h | 15 --------------- dev/user/SciCalls.h | 15 +++++++++++++++ dev/user/src/SystemCalls.cc | 12 ++++++------ public/frameworks/CoreFoundation.fwrk/xml/app.xml | 2 +- public/frameworks/DiskImage.fwrk/xml/app.xml | 7 ++++--- public/frameworks/KernelTest.fwrk/xml/app.xml | 5 +++-- setup_x64.sh | 2 ++ tooling/mk_app.py | 2 +- tooling/mk_fwrk.py | 17 +++++++++++++---- 11 files changed, 51 insertions(+), 36 deletions(-) delete mode 100644 dev/user/Opts.h create mode 100644 dev/user/SciCalls.h (limited to 'dev/user') diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index c660df87..b5e49cb0 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -76,6 +76,7 @@ KERNEL=krnl.efi SYSCHK=chk.efi BOOTNET=net.efi SCIKIT=user.sys +DDK=ddk.sys .PHONY: invalid-recipe invalid-recipe: @@ -93,6 +94,7 @@ all: compile-amd64 $(COPY) ./modules/BootNet/$(BOOTNET) src/root/$(BOOTNET) $(COPY) ../user/$(SCIKIT) src/root/$(SCIKIT) $(COPY) src/$(BOOTLOADER) src/root/$(BOOTLOADER) + $(COPY) ../ddk/$(DDK) src/root/$(DDK) .PHONY: disk disk: diff --git a/dev/ddk/src/ddk_rt_cxx.cc b/dev/ddk/src/ddk_rt_cxx.cc index 7daf0fcc..3d57e2b9 100644 --- a/dev/ddk/src/ddk_rt_cxx.cc +++ b/dev/ddk/src/ddk_rt_cxx.cc @@ -9,17 +9,17 @@ #include void* operator new(size_t sz) { - return kalloc(sz); + return ::kalloc(sz); } void operator delete(void* ptr) { - kfree(ptr); + ::kfree(ptr); } void* operator new[](size_t sz) { - return kalloc(sz); + return ::kalloc(sz); } void operator delete[](void* ptr) { - kfree(ptr); + ::kfree(ptr); } diff --git a/dev/user/Opts.h b/dev/user/Opts.h deleted file mode 100644 index 4b3b63c1..00000000 --- a/dev/user/Opts.h +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); -IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); -IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); -IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/user/SciCalls.h b/dev/user/SciCalls.h new file mode 100644 index 00000000..4b3b63c1 --- /dev/null +++ b/dev/user/SciCalls.h @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); +IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); +IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); +IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc index f8b6d597..874f607d 100644 --- a/dev/user/src/SystemCalls.cc +++ b/dev/user/src/SystemCalls.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include #include /// @file SystemCalls.cc @@ -63,15 +63,15 @@ IMPORT_C Void IoCloseFile(_Input Ref desc) { } IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (UInt64*) sci_syscall_arg_3(3, reinterpret_cast(desc), - reinterpret_cast(&off)); + auto ret = (volatile UInt64*) sci_syscall_arg_3(3, reinterpret_cast(desc), + reinterpret_cast(&off)); MUST_PASS((*ret) != ~0UL); return *ret; } IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (UInt64*) sci_syscall_arg_2(4, reinterpret_cast(desc)); + auto ret = (volatile UInt64*) sci_syscall_arg_2(4, reinterpret_cast(desc)); return *ret; } @@ -80,8 +80,8 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { va_start(args, fmt); - auto ret = (UInt64*) sci_syscall_arg_4(5, reinterpret_cast(desc), - reinterpret_cast(const_cast(fmt)), args); + auto ret = (volatile UInt64*) sci_syscall_arg_4( + 5, reinterpret_cast(desc), reinterpret_cast(const_cast(fmt)), args); va_end(args); diff --git a/public/frameworks/CoreFoundation.fwrk/xml/app.xml b/public/frameworks/CoreFoundation.fwrk/xml/app.xml index 3a2beac4..fe112a09 100644 --- a/public/frameworks/CoreFoundation.fwrk/xml/app.xml +++ b/public/frameworks/CoreFoundation.fwrk/xml/app.xml @@ -1,3 +1,3 @@ - + diff --git a/public/frameworks/DiskImage.fwrk/xml/app.xml b/public/frameworks/DiskImage.fwrk/xml/app.xml index 29d6670f..f498d4ab 100644 --- a/public/frameworks/DiskImage.fwrk/xml/app.xml +++ b/public/frameworks/DiskImage.fwrk/xml/app.xml @@ -1,3 +1,4 @@ - - - + + + + \ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/xml/app.xml b/public/frameworks/KernelTest.fwrk/xml/app.xml index f0c48862..e3ff9424 100644 --- a/public/frameworks/KernelTest.fwrk/xml/app.xml +++ b/public/frameworks/KernelTest.fwrk/xml/app.xml @@ -1,3 +1,4 @@ - - + + + \ No newline at end of file diff --git a/setup_x64.sh b/setup_x64.sh index 6afc1633..5eeaafde 100755 --- a/setup_x64.sh +++ b/setup_x64.sh @@ -9,6 +9,8 @@ cd src make sci_asm_io_x64 cd .. btb user.json +cd ../ddk +btb ddk.json cd ../boot make -f amd64-desktop.make efi make -f amd64-desktop.make epm-img diff --git a/tooling/mk_app.py b/tooling/mk_app.py index ef2b64c9..9418cf05 100755 --- a/tooling/mk_app.py +++ b/tooling/mk_app.py @@ -77,4 +77,4 @@ if __name__ == "__main__": base_path = os.getcwd() # Use the current working directory as the base path create_directory_structure(base_path, sys.argv[1]) - print("NeKernel Application created successfully.") + print("Info: Application created successfully.") diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py index 89857347..3c73e88e 100755 --- a/tooling/mk_fwrk.py +++ b/tooling/mk_fwrk.py @@ -12,14 +12,17 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name): # Define the directory structure structure = { project_name: { + "headers": { + ".keep": None + }, "dist": { ".keep": None }, "src": { ".keep": None, - "CommandLine.cc": None, + "DylibMain.cc": None, }, - "vendor": { + "xml": { ".keep": None }, ".keep": None, @@ -65,13 +68,19 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name): with open(proj_json_path, 'w') as json_file: json.dump(manifest, json_file, indent=4) - proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/CommandLine.cc") + proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/DylibMain.cc") cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) + xml_blob = f"\n" + proj_xml_path = os.path.join(base_path_fwrk, project_name, f"xml/app.xml") + + with open(proj_xml_path, 'w') as cpp_file_io: + cpp_file_io.write(xml_blob) + if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: mk_fwrk.py ") @@ -80,4 +89,4 @@ if __name__ == "__main__": 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("NeKernel Framework created successfully.") + print("Info: Framework created successfully.") -- cgit v1.2.3 From e2bd3c7b6fcd6147fcbf699be087a475608ffdf7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 15:57:42 +0200 Subject: feat(krnl, libSystem, boot): Make space for LibSystem inside Handover boot structure. what: - Mostly related to the libSystem.sys library. - Updated the implementation of it, the specs, and added new APIs. - Fixed the hooks inside AsmProc.h Signed-off-by: Amlal El Mahrouss --- compile_flags.txt | 2 ++ dev/boot/amd64-ci.make | 2 +- dev/boot/amd64-desktop.make | 2 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 1 - dev/generic_kits/BenchKit/.keep | 0 dev/generic_kits/BenchKit/Chrono.h | 15 ++++++++ dev/generic_kits/BenchKit/HardwareChrono.h | 9 +++++ dev/kernel/FirmwareKit/Handover.h | 6 ++-- dev/system_sdk/.keep | 0 dev/user/AsmProc.h | 15 ++++++++ dev/user/ProcessCodes.h | 58 ------------------------------ dev/user/SciCalls.h | 15 -------- dev/user/SecurityPolicy.h | 12 +++++++ dev/user/SystemCalls.h | 33 +++++++++-------- dev/user/SystemCodes.h | 58 ++++++++++++++++++++++++++++++ dev/user/docs/SPECIFICATION_SYSCALLS.md | 23 ++++++++---- dev/user/src/GNUmakefile | 4 +-- dev/user/src/SystemCalls+IO.asm | 21 +++++++++++ dev/user/src/SystemCalls.cc | 6 ++-- dev/user/user.json | 4 +-- docs/drawio/OS_DESIGN.drawio | 25 +++++++------ 21 files changed, 192 insertions(+), 119 deletions(-) delete mode 100644 dev/generic_kits/BenchKit/.keep create mode 100644 dev/generic_kits/BenchKit/HardwareChrono.h create mode 100644 dev/system_sdk/.keep create mode 100644 dev/user/AsmProc.h delete mode 100644 dev/user/ProcessCodes.h delete mode 100644 dev/user/SciCalls.h create mode 100644 dev/user/SecurityPolicy.h create mode 100644 dev/user/SystemCodes.h (limited to 'dev/user') diff --git a/compile_flags.txt b/compile_flags.txt index e9a887a3..6dd6300a 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,6 +2,8 @@ -Idev/ -Idev/user -Idev/boot +-Idev/system_sdk +-Idev/generic_kits -Idev/ddk -Ipublic/tools -Ipublic/tools/mk.app diff --git a/dev/boot/amd64-ci.make b/dev/boot/amd64-ci.make index b396b0d5..d711abde 100644 --- a/dev/boot/amd64-ci.make +++ b/dev/boot/amd64-ci.make @@ -73,7 +73,7 @@ BOOTLOADER=bootz.efi KERNEL=krnl.efi SYSCHK=chk.efi BOOTNET=net.efi -SCIKIT=user.sys +SCIKIT=libSystem.sys .PHONY: invalid-recipe invalid-recipe: diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 8c227ebf..05ac5db8 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -75,7 +75,7 @@ BOOTLOADER=bootz.efi KERNEL=krnl.efi SYSCHK=chk.efi BOOTNET=net.efi -SCIKIT=user.sys +SCIKIT=libSystem.sys DDK=ddk.sys .PHONY: invalid-recipe diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 84a4d295..58610c39 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -226,7 +226,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // boot to kernel, if not bootnet this. Boot::BootFileReader reader_kernel(kernel_path, image_handle); - reader_kernel.ReadAll(0); // ------------------------------------------ // diff --git a/dev/generic_kits/BenchKit/.keep b/dev/generic_kits/BenchKit/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/generic_kits/BenchKit/Chrono.h b/dev/generic_kits/BenchKit/Chrono.h index b4010460..394f16fd 100644 --- a/dev/generic_kits/BenchKit/Chrono.h +++ b/dev/generic_kits/BenchKit/Chrono.h @@ -7,10 +7,25 @@ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. #ifndef BENCHKIT_CHRONO_H #define BENCHKIT_CHRONO_H +#include #include namespace Kernel { class ChronoInterface; + +/// @brief a Chronometer interface used for benchmarking. +class ChronoInterface { + public: + ChronoInterface() = default; + virtual ~ChronoInterface() = default; + + NE_COPY_DEFAULT(ChronoInterface); + + virtual void Start() = 0; + virtual void Stop() = 0; + virtual void Reset() = 0; + virtual UInt64 GetElapsedTime() const = 0; +}; } // namespace Kernel #endif // BENCHKIT_CHRONO_H diff --git a/dev/generic_kits/BenchKit/HardwareChrono.h b/dev/generic_kits/BenchKit/HardwareChrono.h new file mode 100644 index 00000000..f6f6fd8c --- /dev/null +++ b/dev/generic_kits/BenchKit/HardwareChrono.h @@ -0,0 +1,9 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include diff --git a/dev/kernel/FirmwareKit/Handover.h b/dev/kernel/FirmwareKit/Handover.h index 7689f38c..266953d3 100644 --- a/dev/kernel/FirmwareKit/Handover.h +++ b/dev/kernel/FirmwareKit/Handover.h @@ -61,8 +61,10 @@ struct BootInfoHeader final { VoidPtr f_KernelImage; SizeT f_KernelSz; - VoidPtr f_StartupImage; - SizeT f_StartupSz; + + VoidPtr f_LibSystemImage; + SizeT f_LibSystemSz; + VoidPtr f_StackTop; SizeT f_StackSz; diff --git a/dev/system_sdk/.keep b/dev/system_sdk/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/user/AsmProc.h b/dev/user/AsmProc.h new file mode 100644 index 00000000..4b3b63c1 --- /dev/null +++ b/dev/user/AsmProc.h @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); +IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); +IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); +IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/user/ProcessCodes.h b/dev/user/ProcessCodes.h deleted file mode 100644 index 90457944..00000000 --- a/dev/user/ProcessCodes.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file ProcessCodes.h -/// @brief Process Codes type and values. -/// @author Amlal El Mahrouss (amlal@nekernel.org) - -#define err_local_ok() (kLastError == kErrorSuccess) -#define err_local_fail() (kLastError != kErrorSuccess) -#define err_local_get() (kLastError) - -typedef SInt32 ErrRef; - -inline constexpr ErrRef kErrorSuccess = 0; -inline constexpr ErrRef kErrorExecutable = 33; -inline constexpr ErrRef kErrorExecutableLib = 34; -inline constexpr ErrRef kErrorFileNotFound = 35; -inline constexpr ErrRef kErrorDirectoryNotFound = 36; -inline constexpr ErrRef kErrorDiskReadOnly = 37; -inline constexpr ErrRef kErrorDiskIsFull = 38; -inline constexpr ErrRef kErrorProcessFault = 39; -inline constexpr ErrRef kErrorSocketHangUp = 40; -inline constexpr ErrRef kErrorThreadLocalStorage = 41; -inline constexpr ErrRef kErrorMath = 42; -inline constexpr ErrRef kErrorNoNetwork = 43; -inline constexpr ErrRef kErrorHeapOutOfMemory = 44; -inline constexpr ErrRef kErrorNoSuchDisk = 45; -inline constexpr ErrRef kErrorFileExists = 46; -inline constexpr ErrRef kErrorFormatFailed = 47; -inline constexpr ErrRef kErrorNetworkTimeout = 48; -inline constexpr ErrRef kErrorInternal = 49; -inline constexpr ErrRef kErrorForkAlreadyExists = 50; -inline constexpr ErrRef kErrorOutOfTeamSlot = 51; -inline constexpr ErrRef kErrorHeapNotPresent = 52; -inline constexpr ErrRef kErrorNoEntrypoint = 53; -inline constexpr ErrRef kErrorDiskIsCorrupted = 54; -inline constexpr ErrRef kErrorDisk = 55; -inline constexpr ErrRef kErrorInvalidData = 56; -inline constexpr ErrRef kErrorAsync = 57; -inline constexpr ErrRef kErrorNonBlocking = 58; -inline constexpr ErrRef kErrorIPC = 59; -inline constexpr ErrRef kErrorSign = 60; -inline constexpr ErrRef kErrorInvalidCreds = 61; -inline constexpr ErrRef kErrorCDTrayBroken = 62; -inline constexpr ErrRef kErrorUnrecoverableDisk = 63; -inline constexpr ErrRef kErrorFileLocked = 64; -inline constexpr ErrRef kErrorDiskIsTooTiny = 65; -inline constexpr ErrRef kErrorUnimplemented = -1; - -/// @brief The last error reported by the system to the process. -IMPORT_C ErrRef kLastError; diff --git a/dev/user/SciCalls.h b/dev/user/SciCalls.h deleted file mode 100644 index 4b3b63c1..00000000 --- a/dev/user/SciCalls.h +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); -IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); -IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); -IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/user/SecurityPolicy.h b/dev/user/SecurityPolicy.h new file mode 100644 index 00000000..a03c928b --- /dev/null +++ b/dev/user/SecurityPolicy.h @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file SecurityPolicy.h +/// @brief Hardened Security Policy, used to restrict access to certain system calls. \ No newline at end of file diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index 61021a01..c1b70513 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -112,7 +112,7 @@ IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset); /// @brief Spawns a Thread Information Block and Global Information Block inside the current /// process. /// @param process_id Target Process ID, must be valid. -/// @return > 0 error ocurred or already present, = 0 success. +/// @return > 0 error occurred or already present, = 0 success. IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id); /// @brief Spawns a process with a unique pid (stored as UIntPtr). @@ -125,10 +125,6 @@ IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** ar /// @return if it has succeeded true, otherwise false. IMPORT_C Bool RtlExitProcess(UIntPtr handle, UIntPtr exit_code); -/// @brief Get current PID of process. -/// @return Current process ID. -IMPORT_C UIntPtr RtlCurrentPID(Void); - // ------------------------------------------------------------------------ // Memory Manager API. // ------------------------------------------------------------------------ @@ -192,14 +188,15 @@ IMPORT_C SInt32 ThrExitMainThread(_Input SInt32 exit_code); IMPORT_C SInt32 ThrExitThread(_Input ThreadRef thread, _Input SInt32 exit_code); /// @brief Thread procedure function type. -typedef SInt32 (*thread_proc_kind)(SInt32 argc, Char** argv); +typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); /// @brief Creates a thread. /// @param procedure the thread procedure. /// @param argument_count number of arguments inside that thread. /// @param flags Thread flags. /// @return the thread object. -IMPORT_C ThreadRef ThrCreateThread(thread_proc_kind procedure, SInt32 argument_count, SInt32 flags); +IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, + SInt32 argument_count, SInt32 flags); /// @brief Yields the current thread. /// @param thread the thread to yield. @@ -287,8 +284,8 @@ IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr // ------------------------------------------------------------------------------------------ // enum { - kPowerCodeInvalid, - kPowerCodeShutdown, + kPowerCodeInvalid = 0, + kPowerCodeShutdown = 12, kPowerCodeReboot, kPowerCodeSleep, kPowerCodeWake, @@ -328,15 +325,21 @@ IMPORT_C IORef PrintGet(const Char* path); // ------------------------------------------------------------------------------------------ // typedef SInt32 AffinityRef; -typedef UInt64 PID; +typedef UInt64 ProcessRef; + +IMPORT_C SInt32 SchedSetAffinity(ProcessRef, SInt32 req, AffinityRef* local); -IMPORT_C SInt32 SchedAffinity(PID, SInt32 req, AffinityRef* local); +IMPORT_C SInt32 SchedGetAffinity(ProcessRef, AffinityRef* local); -IMPORT_C SInt32 SchedTrace(PID, SInt32 req, VoidPtr address, VoidPtr data); +IMPORT_C SInt32 SchedFireSignal(ProcessRef, SInt32 req); -IMPORT_C SInt32 SchedKill(PID, SInt32 req); +IMPORT_C SInt32 SchedReadMemory(ProcessRef, SInt32 address, SInt32 data); -IMPORT_C SInt32 SchedBreakPoint(Void); +IMPORT_C SInt32 SchedWriteMemory(ProcessRef, SInt32 address, SInt32 data); + +/// @brief Get current ProcessRef of process. +/// @return Current process ID. +IMPORT_C UIntPtr RtlCurrentPID(Void); // ------------------------------------------------------------------------------------------ // // @brief Filesystem API. @@ -355,7 +358,7 @@ IMPORT_C BOOL FsCreateFile(const Char* path); IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); // ------------------------------------------------------------------------------------------ // -// @brief Format API. +// @brief String API. // ------------------------------------------------------------------------------------------ // IMPORT_C Char* StrFmt(const Char* fmt, ...); diff --git a/dev/user/SystemCodes.h b/dev/user/SystemCodes.h new file mode 100644 index 00000000..90457944 --- /dev/null +++ b/dev/user/SystemCodes.h @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file ProcessCodes.h +/// @brief Process Codes type and values. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + +#define err_local_ok() (kLastError == kErrorSuccess) +#define err_local_fail() (kLastError != kErrorSuccess) +#define err_local_get() (kLastError) + +typedef SInt32 ErrRef; + +inline constexpr ErrRef kErrorSuccess = 0; +inline constexpr ErrRef kErrorExecutable = 33; +inline constexpr ErrRef kErrorExecutableLib = 34; +inline constexpr ErrRef kErrorFileNotFound = 35; +inline constexpr ErrRef kErrorDirectoryNotFound = 36; +inline constexpr ErrRef kErrorDiskReadOnly = 37; +inline constexpr ErrRef kErrorDiskIsFull = 38; +inline constexpr ErrRef kErrorProcessFault = 39; +inline constexpr ErrRef kErrorSocketHangUp = 40; +inline constexpr ErrRef kErrorThreadLocalStorage = 41; +inline constexpr ErrRef kErrorMath = 42; +inline constexpr ErrRef kErrorNoNetwork = 43; +inline constexpr ErrRef kErrorHeapOutOfMemory = 44; +inline constexpr ErrRef kErrorNoSuchDisk = 45; +inline constexpr ErrRef kErrorFileExists = 46; +inline constexpr ErrRef kErrorFormatFailed = 47; +inline constexpr ErrRef kErrorNetworkTimeout = 48; +inline constexpr ErrRef kErrorInternal = 49; +inline constexpr ErrRef kErrorForkAlreadyExists = 50; +inline constexpr ErrRef kErrorOutOfTeamSlot = 51; +inline constexpr ErrRef kErrorHeapNotPresent = 52; +inline constexpr ErrRef kErrorNoEntrypoint = 53; +inline constexpr ErrRef kErrorDiskIsCorrupted = 54; +inline constexpr ErrRef kErrorDisk = 55; +inline constexpr ErrRef kErrorInvalidData = 56; +inline constexpr ErrRef kErrorAsync = 57; +inline constexpr ErrRef kErrorNonBlocking = 58; +inline constexpr ErrRef kErrorIPC = 59; +inline constexpr ErrRef kErrorSign = 60; +inline constexpr ErrRef kErrorInvalidCreds = 61; +inline constexpr ErrRef kErrorCDTrayBroken = 62; +inline constexpr ErrRef kErrorUnrecoverableDisk = 63; +inline constexpr ErrRef kErrorFileLocked = 64; +inline constexpr ErrRef kErrorDiskIsTooTiny = 65; +inline constexpr ErrRef kErrorUnimplemented = -1; + +/// @brief The last error reported by the system to the process. +IMPORT_C ErrRef kLastError; diff --git a/dev/user/docs/SPECIFICATION_SYSCALLS.md b/dev/user/docs/SPECIFICATION_SYSCALLS.md index 607c7532..b4b11c8c 100644 --- a/dev/user/docs/SPECIFICATION_SYSCALLS.md +++ b/dev/user/docs/SPECIFICATION_SYSCALLS.md @@ -1,16 +1,25 @@ =================================== - # 0: General Information - =================================== -- Programming Language: C/C++ -- Build System: Make/BTB -- Purpose: System Call Interface +- **Programming Language**: C / C++ +- **Build System**: Make / BTB (Build the Build) +- **Purpose**: System Call Interface (SCI) for NeKernel +=================================== +# 1: How It Works =================================== -# 1: How It works +- This header provides the raw API surface for accessing NeKernel's system calls. -=================================== +- It is **not** directly used by applications. + - Instead, it is abstracted by the **SystemSDK**, which presents a stable, high-level interface. + +- At runtime: + - System calls are routed from user-space code to the **kernel syscall manager**. + - The syscall manager executes the requested operation and returns control to `libSystem`. + - Finally, the result is delivered back to the originating process. +- This separation ensures that: + - The SCI remains low-level and close to the ABI. + - `SystemSDK` provides portability and shielding from changes in syscall internals. \ No newline at end of file diff --git a/dev/user/src/GNUmakefile b/dev/user/src/GNUmakefile index 09993d16..9b901f9f 100644 --- a/dev/user/src/GNUmakefile +++ b/dev/user/src/GNUmakefile @@ -1,6 +1,6 @@ ################################################## # (c) Amlal El Mahrouss, all rights reserved. -# This file is for user.sys's syscall stubs. +# This file is for libSystem.sys's syscall stubs. ################################################## ASM=nasm @@ -13,4 +13,4 @@ error: .PHONY: sci_asm_io_x64 sci_asm_io_x64: - $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.asm.o + $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.stub.obj diff --git a/dev/user/src/SystemCalls+IO.asm b/dev/user/src/SystemCalls+IO.asm index 77e22b59..9126b7de 100644 --- a/dev/user/src/SystemCalls+IO.asm +++ b/dev/user/src/SystemCalls+IO.asm @@ -19,17 +19,31 @@ 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 rbx, r8 mov r8, rcx @@ -37,9 +51,14 @@ sci_syscall_arg_3: mov r10, rbx syscall + pop rbp + ret sci_syscall_arg_4: + push rbp + mov rbp, rsp + mov rbx, r8 mov rax, r9 @@ -49,4 +68,6 @@ sci_syscall_arg_4: mov r11, rax syscall + pop rbp + ret diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc index 874f607d..f004718c 100644 --- a/dev/user/src/SystemCalls.cc +++ b/dev/user/src/SystemCalls.cc @@ -4,11 +4,11 @@ ------------------------------------------- */ -#include +#include #include /// @file SystemCalls.cc -/// @brief Source file for the memory functions/syscalls for user.sys +/// @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) { @@ -51,8 +51,6 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt /// @internal //-----------------------------------------------------------------------------------------------------------// -constexpr auto kInvalidSyscall = 0UL; - IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { return sci_syscall_arg_3(1, reinterpret_cast(const_cast(path)), reinterpret_cast(const_cast(drv_letter))); diff --git a/dev/user/user.json b/dev/user/user.json index 05b90abf..2267175e 100644 --- a/dev/user/user.json +++ b/dev/user/user.json @@ -2,8 +2,8 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cc", "src/*.o"], - "output_name": "user.sys", + "sources_path": ["src/*.cc", "src/*.stub.obj"], + "output_name": "libSystem.sys", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/docs/drawio/OS_DESIGN.drawio b/docs/drawio/OS_DESIGN.drawio index c9276302..3a03540c 100644 --- a/docs/drawio/OS_DESIGN.drawio +++ b/docs/drawio/OS_DESIGN.drawio @@ -1,14 +1,14 @@ - + - + - + @@ -16,27 +16,30 @@ - + - + - + - + - + - - + + - + + + + -- cgit v1.2.3 From 6551964ad66de7bc7ccb636c54351be2a260612b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 23:31:58 +0200 Subject: feat(kernel/libSystem): Lots of improvements, see below. what: - Reworked NetworkDevice. - Reworked RTL8139 driver. - Don't assert fCleanup on NetworkDevice destructor. - Add new Ref types in libSystem. Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/HeFS.h | 2 +- dev/kernel/FirmwareKit/Handover.h | 2 +- .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 26 ++++- dev/kernel/KernelKit/User.h | 92 --------------- dev/kernel/KernelKit/UserMgr.h | 92 +++++++++++++++ dev/kernel/KernelKit/UserProcessScheduler.h | 2 +- dev/kernel/NetworkKit/NetworkDevice.h | 5 +- dev/kernel/NetworkKit/NetworkDevice.inl | 6 +- dev/kernel/kernel_rsrc.rsrc | 4 +- dev/kernel/src/FS/Ext2+FileSystemParser.cc | 2 +- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 2 +- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 2 +- dev/kernel/src/Network/NetworkDevice.cc | 6 +- dev/kernel/src/User.cc | 129 --------------------- dev/kernel/src/UserMgr.cc | 129 +++++++++++++++++++++ dev/kernel/src/UserProcessScheduler.cc | 1 - dev/user/SystemCalls.h | 4 + 17 files changed, 266 insertions(+), 240 deletions(-) delete mode 100644 dev/kernel/KernelKit/User.h create mode 100644 dev/kernel/KernelKit/UserMgr.h delete mode 100644 dev/kernel/src/User.cc create mode 100644 dev/kernel/src/UserMgr.cc (limited to 'dev/user') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 17a174e3..08452a2b 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/dev/kernel/FirmwareKit/Handover.h b/dev/kernel/FirmwareKit/Handover.h index 266953d3..d74194ed 100644 --- a/dev/kernel/FirmwareKit/Handover.h +++ b/dev/kernel/FirmwareKit/Handover.h @@ -61,7 +61,7 @@ struct BootInfoHeader final { VoidPtr f_KernelImage; SizeT f_KernelSz; - + VoidPtr f_LibSystemImage; SizeT f_LibSystemSz; diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc index 57f64712..38c12fee 100644 --- a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -21,6 +21,10 @@ STATIC BOOL kTXEnabled = NO; STATIC UInt8* kRXUpperLayer = nullptr; STATIC UInt8* kRxBuffer = nullptr; +/***********************************************************************************/ +///@brief RTL8139 Init routine. +/***********************************************************************************/ + EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { if (kTXEnabled) return; @@ -42,7 +46,10 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { if (timeout > 0x1000) break; } - MUST_PASS(timeout <= 0x1000); + if (timeout <= 0x1000) { + ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "RTL8139: Reset failed"); + return; + } rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRxBuffer); @@ -50,12 +57,16 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { rt_out32(io_base + 0x44, 0xf | (1 << 7)); - // Enable IRQ. rt_out16(io_base + 0x3C, 0x0005); kTXEnabled = YES; } +/***********************************************************************************/ +/// @brief RTL8139 I/O interrupt handler. +/// @note This function is called when the device interrupts to retrieve network data. +/***********************************************************************************/ + EXTERN_C void rtl_rtl8139_interrupt_handler() { if (kIOBase == 0xFFFF) return; @@ -78,4 +89,15 @@ EXTERN_C void rtl_rtl8139_interrupt_handler() { if (!(status & 0x04)) { err_global_get() = kErrorNoNetwork; } +} + +/***********************************************************************************/ +/// @brief RTL8139 get upper layer function +/// @return the upper layer. +/// @retval nullptr if no upper layer is set. +/// @retval pointer to the upper layer if set. +/***********************************************************************************/ + +EXTERN_C UInt8* rtl_rtl8139_get_upper_layer() { + return kRXUpperLayer; } \ No newline at end of file diff --git a/dev/kernel/KernelKit/User.h b/dev/kernel/KernelKit/User.h deleted file mode 100644 index b7e7ac1d..00000000 --- a/dev/kernel/KernelKit/User.h +++ /dev/null @@ -1,92 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifndef INC_USER_H -#define INC_USER_H - -/* ------------------------------------------- - - Revision History: - - 04/03/25: Set users directory as /user/ instead of /usr/ - - ------------------------------------------- */ - -#include -#include -#include -#include - -///! We got the Super, Standard (%s format) and Guest user, -///! all are used to make authorization operations on the OS. -#define kSuperUser "OS AUTHORITY/MGMT/%s" -#define kGuestUser "OS AUTHORITY/GUEST/%s" -#define kStdUser "OS AUTHORITY/STD/%s" - -#define kUsersDir "/users/" - -#define kMaxUserNameLen (256U) -#define kMaxUserTokenLen (256U) - -namespace Kernel { -class User; - -enum class UserRingKind { - kRingInvalid = 0, - kRingStdUser = 1, - kRingSuperUser = 2, - kRingGuestUser = 5, - kRingCount = 3, -}; - -typedef Char* UserPublicKey; -typedef Char UserPublicKeyType; - -/// @brief System User class. -class User final { - public: - User() = delete; - - User(const Int32& sel, const Char* username); - User(const UserRingKind& kind, const Char* username); - - ~User(); - - public: - NE_COPY_DEFAULT(User) - - public: - bool operator==(const User& lhs); - bool operator!=(const User& lhs); - - public: - /// @brief Get software ring - const UserRingKind& Ring() noexcept; - - /// @brief Get user name - Char* Name() noexcept; - - /// @brief Is he a standard user? - Bool IsStdUser() noexcept; - - /// @brief Is she a super user? - Bool IsSuperUser() noexcept; - - /// @brief Saves a password from the public key. - Bool Save(const UserPublicKey password) noexcept; - - /// @brief Checks if a password matches the **password**. - /// @param password the password to check. - Bool Login(const UserPublicKey password) noexcept; - - private: - UserRingKind mUserRing{UserRingKind::kRingStdUser}; - Char mUserName[kMaxUserNameLen] = {0}; - UInt64 mUserFNV{0UL}; -}; -} // namespace Kernel - -#endif /* ifndef INC_USER_H */ diff --git a/dev/kernel/KernelKit/UserMgr.h b/dev/kernel/KernelKit/UserMgr.h new file mode 100644 index 00000000..b7e7ac1d --- /dev/null +++ b/dev/kernel/KernelKit/UserMgr.h @@ -0,0 +1,92 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef INC_USER_H +#define INC_USER_H + +/* ------------------------------------------- + + Revision History: + + 04/03/25: Set users directory as /user/ instead of /usr/ + + ------------------------------------------- */ + +#include +#include +#include +#include + +///! We got the Super, Standard (%s format) and Guest user, +///! all are used to make authorization operations on the OS. +#define kSuperUser "OS AUTHORITY/MGMT/%s" +#define kGuestUser "OS AUTHORITY/GUEST/%s" +#define kStdUser "OS AUTHORITY/STD/%s" + +#define kUsersDir "/users/" + +#define kMaxUserNameLen (256U) +#define kMaxUserTokenLen (256U) + +namespace Kernel { +class User; + +enum class UserRingKind { + kRingInvalid = 0, + kRingStdUser = 1, + kRingSuperUser = 2, + kRingGuestUser = 5, + kRingCount = 3, +}; + +typedef Char* UserPublicKey; +typedef Char UserPublicKeyType; + +/// @brief System User class. +class User final { + public: + User() = delete; + + User(const Int32& sel, const Char* username); + User(const UserRingKind& kind, const Char* username); + + ~User(); + + public: + NE_COPY_DEFAULT(User) + + public: + bool operator==(const User& lhs); + bool operator!=(const User& lhs); + + public: + /// @brief Get software ring + const UserRingKind& Ring() noexcept; + + /// @brief Get user name + Char* Name() noexcept; + + /// @brief Is he a standard user? + Bool IsStdUser() noexcept; + + /// @brief Is she a super user? + Bool IsSuperUser() noexcept; + + /// @brief Saves a password from the public key. + Bool Save(const UserPublicKey password) noexcept; + + /// @brief Checks if a password matches the **password**. + /// @param password the password to check. + Bool Login(const UserPublicKey password) noexcept; + + private: + UserRingKind mUserRing{UserRingKind::kRingStdUser}; + Char mUserName[kMaxUserNameLen] = {0}; + UInt64 mUserFNV{0UL}; +}; +} // namespace Kernel + +#endif /* ifndef INC_USER_H */ diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 1815a558..14986ab6 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include //////////////////////////////////////////////////// diff --git a/dev/kernel/NetworkKit/NetworkDevice.h b/dev/kernel/NetworkKit/NetworkDevice.h index 7ed67bab..48fed575 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.h +++ b/dev/kernel/NetworkKit/NetworkDevice.h @@ -23,7 +23,7 @@ class NetworkDevice final : public IDeviceObject { public: NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), void (*in)(IDeviceObject*, NetworkDeviceCommand), - void (*onCleanup)(void) = nullptr); + void (*cleanup)(void) = nullptr); ~NetworkDevice() override; @@ -36,10 +36,9 @@ class NetworkDevice final : public IDeviceObject { Boolean Name(const Char* newStr); private: - static constexpr auto cNetworkNameLen = 512; + static constexpr auto kNetworkNameLen = 512; Void (*fCleanup)(void); - Char fNetworkName[cNetworkNameLen]; }; struct NetworkDeviceCommand final { diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl index 812c0248..84ec9edc 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.inl +++ b/dev/kernel/NetworkKit/NetworkDevice.inl @@ -8,6 +8,10 @@ Dtor and ctors. */ +#ifndef __INC_NETWORK_DEVICE_H__ +#include +#endif // __INC_NETWORK_DEVICE_H__ + namespace Kernel { inline NetworkDevice::NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), @@ -21,8 +25,6 @@ inline NetworkDevice::NetworkDevice(void (*out)(IDeviceObject #include #include -#include +#include #include #include #include diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 155c9b9f..a18abaf8 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index f1746a58..97b2ff36 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/kernel/src/Network/NetworkDevice.cc b/dev/kernel/src/Network/NetworkDevice.cc index 51c43b48..02cb0e73 100644 --- a/dev/kernel/src/Network/NetworkDevice.cc +++ b/dev/kernel/src/Network/NetworkDevice.cc @@ -11,7 +11,7 @@ namespace Kernel { /// \brief Getter for fNetworkName. /// \return Network device name. const Char* NetworkDevice::Name() const { - return this->fNetworkName; + return "/devices/net{}"; } /// \brief Setter for fNetworkName. @@ -20,9 +20,9 @@ Boolean NetworkDevice::Name(const Char* name) { if (*name == 0) return NO; - if (rt_string_len(name) > cNetworkNameLen) return NO; + if (rt_string_len(name) > kNetworkNameLen) return NO; - rt_copy_memory((VoidPtr) name, (VoidPtr) this->fNetworkName, rt_string_len(name)); + rt_copy_memory((VoidPtr) name, (VoidPtr) this->Name(), rt_string_len(this->Name())); return YES; } diff --git a/dev/kernel/src/User.cc b/dev/kernel/src/User.cc deleted file mode 100644 index 1859be12..00000000 --- a/dev/kernel/src/User.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* - * ======================================================== - * - * NeKernel - * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - * - * File: User.cc - * Purpose: User class, used to provide authentication and security. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include - -#define kStdUserType (0xEE) -#define kSuperUserType (0xEF) - -/// @file User.cc -/// @brief Multi-user support. - -namespace Kernel { -namespace Detail { - //////////////////////////////////////////////////////////// - /// \brief Constructs a password by hashing the password. - /// \param password password to hash. - /// \return the hashed password - //////////////////////////////////////////////////////////// - STATIC UInt64 user_fnv_generator(const Char* password, User* user) { - if (!password || !user) return 1; - if (*password == 0) return 1; - - kout << "user_fnv_generator: Hashing user password...\r"; - - const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; - const UInt64 FNV_PRIME = 0x100000001b3ULL; - - UInt64 hash = FNV_OFFSET_BASIS; - - while (*password) { - hash ^= (Utf8Char) (*password++); - hash *= FNV_PRIME; - } - - kout << "user_fnv_generator: Hashed user password.\r"; - - return 0; - } -} // namespace Detail - -//////////////////////////////////////////////////////////// -/// @brief User ring constructor. -//////////////////////////////////////////////////////////// -User::User(const Int32& sel, const Char* user_name) : mUserRing((UserRingKind) sel) { - MUST_PASS(sel >= 0); - rt_copy_memory((VoidPtr) user_name, this->mUserName, rt_string_len(user_name)); -} - -//////////////////////////////////////////////////////////// -/// @brief User ring constructor. -//////////////////////////////////////////////////////////// -User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(ring_kind) { - rt_copy_memory((VoidPtr) user_name, this->mUserName, rt_string_len(user_name)); -} - -//////////////////////////////////////////////////////////// -/// @brief User destructor class. -//////////////////////////////////////////////////////////// -User::~User() = default; - -Bool User::Save(const UserPublicKey password) noexcept { - if (!password || *password == 0) return No; - - this->mUserFNV = Detail::user_fnv_generator(password, this); - - kout << "User::Save: Saved password successfully...\r"; - - return Yes; -} - -Bool User::Login(const UserPublicKey password) noexcept { - if (!password || !*password) return No; - - // now check if the password matches. - if (this->mUserFNV == Detail::user_fnv_generator(password, this)) { - kout << "User::Login: Password matches.\r"; - return Yes; - } - - kout << "User::Login: Password doesn't match.\r"; - return No; -} - -Bool User::operator==(const User& lhs) { - return lhs.mUserRing == this->mUserRing; -} - -Bool User::operator!=(const User& lhs) { - return lhs.mUserRing != this->mUserRing; -} - -//////////////////////////////////////////////////////////// -/// @brief Returns the user's name. -//////////////////////////////////////////////////////////// - -Char* User::Name() noexcept { - return this->mUserName; -} - -//////////////////////////////////////////////////////////// -/// @brief Returns the user's ring. -/// @return The king of ring the user is attached to. -//////////////////////////////////////////////////////////// - -const UserRingKind& User::Ring() noexcept { - return this->mUserRing; -} - -Bool User::IsStdUser() noexcept { - return this->Ring() == UserRingKind::kRingStdUser; -} - -Bool User::IsSuperUser() noexcept { - return this->Ring() == UserRingKind::kRingSuperUser; -} -} // namespace Kernel diff --git a/dev/kernel/src/UserMgr.cc b/dev/kernel/src/UserMgr.cc new file mode 100644 index 00000000..c41b445b --- /dev/null +++ b/dev/kernel/src/UserMgr.cc @@ -0,0 +1,129 @@ +/* + * ======================================================== + * + * NeKernel + * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + * + * File: User.cc + * Purpose: User class, used to provide authentication and security. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include + +#define kStdUserType (0xEE) +#define kSuperUserType (0xEF) + +/// @file User.cc +/// @brief Multi-user support. + +namespace Kernel { +namespace Detail { + //////////////////////////////////////////////////////////// + /// \brief Constructs a password by hashing the password. + /// \param password password to hash. + /// \return the hashed password + //////////////////////////////////////////////////////////// + STATIC UInt64 user_fnv_generator(const Char* password, User* user) { + if (!password || !user) return 1; + if (*password == 0) return 1; + + kout << "user_fnv_generator: Hashing user password...\r"; + + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; + const UInt64 FNV_PRIME = 0x100000001b3ULL; + + UInt64 hash = FNV_OFFSET_BASIS; + + while (*password) { + hash ^= (Utf8Char) (*password++); + hash *= FNV_PRIME; + } + + kout << "user_fnv_generator: Hashed user password.\r"; + + return 0; + } +} // namespace Detail + +//////////////////////////////////////////////////////////// +/// @brief User ring constructor. +//////////////////////////////////////////////////////////// +User::User(const Int32& sel, const Char* user_name) : mUserRing((UserRingKind) sel) { + MUST_PASS(sel >= 0); + rt_copy_memory((VoidPtr) user_name, this->mUserName, rt_string_len(user_name)); +} + +//////////////////////////////////////////////////////////// +/// @brief User ring constructor. +//////////////////////////////////////////////////////////// +User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(ring_kind) { + rt_copy_memory((VoidPtr) user_name, this->mUserName, rt_string_len(user_name)); +} + +//////////////////////////////////////////////////////////// +/// @brief User destructor class. +//////////////////////////////////////////////////////////// +User::~User() = default; + +Bool User::Save(const UserPublicKey password) noexcept { + if (!password || *password == 0) return No; + + this->mUserFNV = Detail::user_fnv_generator(password, this); + + kout << "User::Save: Saved password successfully...\r"; + + return Yes; +} + +Bool User::Login(const UserPublicKey password) noexcept { + if (!password || !*password) return No; + + // now check if the password matches. + if (this->mUserFNV == Detail::user_fnv_generator(password, this)) { + kout << "User::Login: Password matches.\r"; + return Yes; + } + + kout << "User::Login: Password doesn't match.\r"; + return No; +} + +Bool User::operator==(const User& lhs) { + return lhs.mUserRing == this->mUserRing; +} + +Bool User::operator!=(const User& lhs) { + return lhs.mUserRing != this->mUserRing; +} + +//////////////////////////////////////////////////////////// +/// @brief Returns the user's name. +//////////////////////////////////////////////////////////// + +Char* User::Name() noexcept { + return this->mUserName; +} + +//////////////////////////////////////////////////////////// +/// @brief Returns the user's ring. +/// @return The king of ring the user is attached to. +//////////////////////////////////////////////////////////// + +const UserRingKind& User::Ring() noexcept { + return this->mUserRing; +} + +Bool User::IsStdUser() noexcept { + return this->Ring() == UserRingKind::kRingStdUser; +} + +Bool User::IsSuperUser() noexcept { + return this->Ring() == UserRingKind::kRingSuperUser; +} +} // namespace Kernel diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 5996adca..77421f5f 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -21,7 +21,6 @@ #include #include #include -#include "NeKit/Macros.h" ///! BUGS: 0 diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index c1b70513..d40dc127 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -23,6 +23,10 @@ typedef Ref FSRef; typedef Ref DLLRef; typedef Ref ThreadRef; typedef Ref SocketRef; +typedef Ref NetworkRef; +typedef Ref MutexRef; +typedef Ref EventRef; +typedef Ref SemaphoreRef; // ------------------------------------------------------------------------------------------ // /// @brief Dynamic Loader API. -- cgit v1.2.3 From 386d9a5bffcd66633e4c3c72eb6cb25722796c92 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 May 2025 10:59:49 +0200 Subject: 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 --- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 8 ++-- dev/kernel/HALKit/AMD64/HalInterruptAPI.asm | 4 ++ .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 53 +++++++++++++--------- dev/kernel/KernelKit/UserProcessScheduler.inl | 6 ++- dev/kernel/KernelKit/ZXD.h | 37 +++++++++++++++ dev/kernel/KernelKit/Zxd.h | 37 --------------- dev/user/SystemCalls.h | 14 +++--- dev/user/src/SystemCalls+IO.asm | 9 +--- public/tools/manual/.keep | 0 public/tools/manual/manual.json | 19 ++++++++ public/tools/manual/src/.keep | 0 public/tools/manual/src/CommandLine.cc | 13 ++++++ public/tools/manual/vendor/.keep | 0 public/tools/ping/.keep | 0 public/tools/ping/ping.json | 19 ++++++++ public/tools/ping/src/.keep | 0 public/tools/ping/src/CommandLine.cc | 29 ++++++++++++ public/tools/ping/vendor/.keep | 0 tooling/mk_app.py | 4 +- tooling/mk_fwrk.py | 4 +- tooling/mk_img.py | 4 +- 21 files changed, 174 insertions(+), 86 deletions(-) create mode 100644 dev/kernel/KernelKit/ZXD.h delete mode 100644 dev/kernel/KernelKit/Zxd.h create mode 100644 public/tools/manual/.keep create mode 100644 public/tools/manual/manual.json create mode 100644 public/tools/manual/src/.keep create mode 100644 public/tools/manual/src/CommandLine.cc create mode 100644 public/tools/manual/vendor/.keep create mode 100644 public/tools/ping/.keep create mode 100644 public/tools/ping/ping.json create mode 100644 public/tools/ping/src/.keep create mode 100644 public/tools/ping/src/CommandLine.cc create mode 100644 public/tools/ping/vendor/.keep (limited to 'dev/user') 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(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 +#endif // INC_PROCESS_SCHEDULER_H + namespace Kernel { /***********************************************************************************/ /** @brief Free pointer from usage. */ /***********************************************************************************/ template -Boolean USER_PROCESS::Delete(ErrorOr ptr) { +BOOL USER_PROCESS::Delete(ErrorOr ptr) { if (!ptr) return No; if (!this->HeapTree) { diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h new file mode 100644 index 00000000..d2456f51 --- /dev/null +++ b/dev/kernel/KernelKit/ZXD.h @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace ZXD { +using namespace Kernel; + +struct ZXD_EXEC_HEADER; +struct ZXD_STUB_HEADER; + +/// @brief ZXD executable header +/// @details This header is used to identify ZXD executable files. +struct ZXD_EXEC_HEADER { + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; +}; + +/// @brief ZXD stub header +/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the +/// offset of the stub, and the CRC32 checksum of the stub. +struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { + UInt32 fStubSize; + UInt32 fStubOffset; + UInt32 fStubCRC32; +}; +} // namespace ZXD \ No newline at end of file diff --git a/dev/kernel/KernelKit/Zxd.h b/dev/kernel/KernelKit/Zxd.h deleted file mode 100644 index d2456f51..00000000 --- a/dev/kernel/KernelKit/Zxd.h +++ /dev/null @@ -1,37 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace ZXD { -using namespace Kernel; - -struct ZXD_EXEC_HEADER; -struct ZXD_STUB_HEADER; - -/// @brief ZXD executable header -/// @details This header is used to identify ZXD executable files. -struct ZXD_EXEC_HEADER { - UInt32 fMagic; - UInt32 fVersion; - UInt32 fFlags; - UInt32 fHdrSize; - UInt32 fCRC32; - UInt32 fAssigneeSignature; - UInt32 fIssuerSingature; -}; - -/// @brief ZXD stub header -/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the -/// offset of the stub, and the CRC32 checksum of the stub. -struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { - UInt32 fStubSize; - UInt32 fStubOffset; - UInt32 fStubCRC32; -}; -} // namespace ZXD \ No newline at end of file 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 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 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 + +SInt32 _NeMain(SInt32 argc, Char* argv[]) { + SCI_UNUSED(argc); + SCI_UNUSED(argv); + + if (argc < 2) { + PrintOut(nullptr, "HELP: manual \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 diff --git a/public/tools/ping/.keep b/public/tools/ping/.keep new file mode 100644 index 00000000..e69de29b 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 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 + +SInt32 _NeMain(SInt32 argc, Char* argv[]) { + SCI_UNUSED(argc); + + if (argc < 2) { + PrintOut(nullptr, "HELP: ping \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 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 ") + print("HELP: mk_app.py ") 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 ") + print("HELP: mk_fwrk.py ") 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 ") + print("HELP: mk_img.py ") 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.") -- cgit v1.2.3 From f4babecc6d72aae688ad85fc726e22dbd1f82219 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 26 May 2025 20:29:57 +0200 Subject: feat!: Add IFS layer within DriveMgr, and IFS API. also: - Use ThreadID in AP system. - Refactor kernel according to new IFS layer. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/root/ifs.json | 10 +++ dev/kernel/ArchKit/ArchKit.h | 2 - dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 4 +- dev/kernel/KernelKit/CodeMgr.h | 4 +- dev/kernel/KernelKit/DriveMgr.h | 16 +--- dev/kernel/KernelKit/IFS.h | 25 ++++++ dev/kernel/amd64-desktop.make | 2 +- dev/kernel/src/DriveMgr+IO.cc | 89 ---------------------- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 1 + dev/kernel/src/IFS.cc | 89 ++++++++++++++++++++++ dev/kernel/src/UserProcessScheduler.cc | 1 + dev/user/SystemCalls.h | 20 +++-- 12 files changed, 148 insertions(+), 115 deletions(-) create mode 100644 dev/boot/src/root/ifs.json create mode 100644 dev/kernel/KernelKit/IFS.h delete mode 100644 dev/kernel/src/DriveMgr+IO.cc create mode 100644 dev/kernel/src/IFS.cc (limited to 'dev/user') diff --git a/dev/boot/src/root/ifs.json b/dev/boot/src/root/ifs.json new file mode 100644 index 00000000..354ab503 --- /dev/null +++ b/dev/boot/src/root/ifs.json @@ -0,0 +1,10 @@ +{ + "type": "IFS", + "sys": [ + "/~drivers/fat32.sys", + "/~drivers/ntfs.sys", + "/~drivers/ext4.sys", + "/~drivers/iso9660.sys", + "/~drivers/nfs4.sys" + ] +} \ No newline at end of file diff --git a/dev/kernel/ArchKit/ArchKit.h b/dev/kernel/ArchKit/ArchKit.h index 08e8ab88..b6637ec1 100644 --- a/dev/kernel/ArchKit/ArchKit.h +++ b/dev/kernel/ArchKit/ArchKit.h @@ -77,8 +77,6 @@ struct HalSyscallEntry final { operator bool() { return fHooked; } }; -EXTERN_C Kernel::HAL::StackFramePtr mp_get_current_task(Kernel::Int64 pid); - inline Kernel::Array kSysCalls; inline Kernel::Array kKernCalls; diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 1fbf9fea..cb1ec59b 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -101,7 +101,7 @@ Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) { /// @param thrdid The thread ID. /***********************************************************************************/ -EXTERN_C HAL::StackFramePtr mp_get_current_task(Int64 thrdid) { +EXTERN_C HAL::StackFramePtr mp_get_current_task(ThreadID thrdid) { if (thrdid > kSMPCount) return nullptr; return kHWThread[thrdid].mFramePtr; } @@ -112,7 +112,7 @@ EXTERN_C HAL::StackFramePtr mp_get_current_task(Int64 thrdid) { /// @param thrdid The thread ID. /***********************************************************************************/ -EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ProcessID thrdid) { +EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ThreadID thrdid) { if (thrdid > kSMPCount) return NO; if (!stack_frame) return NO; diff --git a/dev/kernel/KernelKit/CodeMgr.h b/dev/kernel/KernelKit/CodeMgr.h index f4d46b4b..072ba4d5 100644 --- a/dev/kernel/KernelKit/CodeMgr.h +++ b/dev/kernel/KernelKit/CodeMgr.h @@ -23,10 +23,10 @@ namespace Kernel { typedef void (*rtl_main_kind)(void); /// @brief C++ Constructor entrypoint. -typedef void (*rtl_ctor_kind)(void); +typedef void (*rtl_cxx_ctor_kind)(void); /// @brief C++ Destructor entrypoint. -typedef void (*rtl_dtor_kind)(void); +typedef void (*rtl_cxx_dtor_kind)(void); /// @brief Executes a new process from a function. Kernel code only. /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 684e2e5c..4a530deb 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -23,6 +23,8 @@ #define drv_sector_cnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) +#define kDriveHiddenPrefix '~' + namespace Kernel { enum { kInvalidDrive = -1, @@ -159,20 +161,6 @@ namespace Detect { Void io_drv_input(DriveTrait::DrivePacket pckt); Void io_drv_output(DriveTrait::DrivePacket pckt); - -/// @brief Read from IFS disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); - -/// @brief Write to IFS disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); } // namespace Kernel #endif /* ifndef INC_DRIVE_MANAGER_H */ diff --git a/dev/kernel/KernelKit/IFS.h b/dev/kernel/KernelKit/IFS.h new file mode 100644 index 00000000..5555764f --- /dev/null +++ b/dev/kernel/KernelKit/IFS.h @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +/// @brief Read from IFS disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); + +/// @brief Write to IFS disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 49593101..21488782 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -D__NE_VEPM__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_INCLUDES_HEFS__ -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot +CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -D__NE_VEPM__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_INCLUDES_HEFS__ -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm diff --git a/dev/kernel/src/DriveMgr+IO.cc b/dev/kernel/src/DriveMgr+IO.cc deleted file mode 100644 index 9137c91e..00000000 --- a/dev/kernel/src/DriveMgr+IO.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/************************************************************* - * - * File: DriveMgr+IO.cc - * Purpose: Filesystem to mountpoint interface. - * Date: 3/26/24 - * - * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - * - *************************************************************/ - -/// Useful macros regarding the IFS. - -#define fsi_ifs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(TRAITS) -#define fsi_ifs_read(DRV, TRAITS, MP) (MP->DRV()).fInput(TRAITS) - -namespace Kernel { -/// @brief Read from newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { - if (!Mnt) return 1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) { - case MountpointInterface::kDriveIndexA: { - fsi_ifs_read(A, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexB: { - fsi_ifs_read(B, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexC: { - fsi_ifs_read(C, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexD: { - fsi_ifs_read(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} - -/// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { - if (!Mnt) return 1; - - DrvTrait.fPacket.fPacketGood = false; - - switch (DrvIndex) { - case MountpointInterface::kDriveIndexA: { - fsi_ifs_write(A, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexB: { - fsi_ifs_write(B, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexC: { - fsi_ifs_write(C, DrvTrait.fPacket, Mnt); - break; - } - case MountpointInterface::kDriveIndexD: { - fsi_ifs_write(D, DrvTrait.fPacket, Mnt); - break; - } - } - - return DrvTrait.fPacket.fPacketGood; -} -} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 97b2ff36..dd0a1d9a 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff --git a/dev/kernel/src/IFS.cc b/dev/kernel/src/IFS.cc new file mode 100644 index 00000000..ba2ec8c0 --- /dev/null +++ b/dev/kernel/src/IFS.cc @@ -0,0 +1,89 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/************************************************************* + * + * File: IFS.cc + * Purpose: Filesystem to mountpoint interface. + * Date: 05/26/2025 + * + * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + * + *************************************************************/ + +/// Useful macros regarding the IFS. + +#define fsi_ifs_write(DRV, TRAITS, MP) (MP->DRV()).fOutput(TRAITS) +#define fsi_ifs_read(DRV, TRAITS, MP) (MP->DRV()).fInput(TRAITS) + +namespace Kernel { +/// @brief Read from fs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { + if (!Mnt) return kErrorDisk; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) { + case MountpointInterface::kDriveIndexA: { + fsi_ifs_read(A, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexB: { + fsi_ifs_read(B, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexC: { + fsi_ifs_read(C, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexD: { + fsi_ifs_read(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood ? kErrorSuccess : kErrorDisk; +} + +/// @brief Write to fs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) { + if (!Mnt) return kErrorDisk; + + DrvTrait.fPacket.fPacketGood = false; + + switch (DrvIndex) { + case MountpointInterface::kDriveIndexA: { + fsi_ifs_write(A, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexB: { + fsi_ifs_write(B, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexC: { + fsi_ifs_write(C, DrvTrait.fPacket, Mnt); + break; + } + case MountpointInterface::kDriveIndexD: { + fsi_ifs_write(D, DrvTrait.fPacket, Mnt); + break; + } + } + + return DrvTrait.fPacket.fPacketGood ? kErrorSuccess : kErrorDisk; +} +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index f900f984..4bbd085a 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -126,6 +126,7 @@ ErrorOr USER_PROCESS::New(SizeT sz, SizeT pad_amount) { #ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ auto vm_register = kKernelVM; + hal_write_cr3(this->VMRegister); auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h index e8b4e59c..d77c0b8f 100644 --- a/dev/user/SystemCalls.h +++ b/dev/user/SystemCalls.h @@ -20,7 +20,7 @@ typedef VoidPtr Ref; typedef Ref IORef; typedef Ref FSRef; -typedef Ref DLLRef; +typedef Ref DylibRef; typedef Ref ThreadRef; typedef Ref SocketRef; typedef Ref NetworkRef; @@ -36,18 +36,18 @@ typedef Ref SemaphoreRef; /// @param symbol the symbol to look for /// @param dll_handle the Dylib handle. /// @return the proc pointer. -IMPORT_C Ref LdrGetDLLSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); +IMPORT_C Ref LdrGetDylibSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); /// @brief Open Dylib handle. /// @param path dll path. /// @param drv driver letter. /// @return a dylib ref. -IMPORT_C Ref LdrOpenDLLHandle(_Input const Char* path, _Input const Char* drive_letter); +IMPORT_C Ref LdrOpenDylibHandle(_Input const Char* path, _Input const Char* drive_letter); /// @brief Close Dylib handle /// @param dll_handle the dylib ref. /// @return whether it closed or not. -IMPORT_C UInt32 LdrCloseDLLHandle(_Input Ref* dll_handle); +IMPORT_C UInt32 LdrCloseDylibHandle(_Input Ref* dll_handle); // ------------------------------------------------------------------------------------------ // // File API. @@ -360,7 +360,17 @@ IMPORT_C BOOL FsCreateFile(const Char* path); IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); // ------------------------------------------------------------------------------------------ // -// @brief String API. +// @brief Installable Filesystem API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C BOOL IfsMount(const Char* path, const Char* drive_letter); + +IMPORT_C BOOL IfsUnmount(const Char* drive_letter); + +IMPORT_C BOOL IfsIsMounted(const Char* drive_letter); + +// ------------------------------------------------------------------------------------------ // +// @brief String Manip API. // ------------------------------------------------------------------------------------------ // IMPORT_C Char* StrFmt(const Char* fmt, ...); -- cgit v1.2.3 From 1a44b4385b3250cd90e255d7d787ae69e987544b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 27 May 2025 20:03:26 +0200 Subject: feat: generic_kits: Add X64Chrono inside BenchKit. refactor: libSystem: Refactored as a whole. Signed-off-by: Amlal El Mahrouss --- CODEOWNERS | 2 +- dev/boot/amd64-desktop.make | 2 +- dev/generic_kits/BenchKit/HardwareChrono.h | 9 - dev/generic_kits/BenchKit/X64Chrono.h | 54 +++ dev/kernel/HALKit/AMD64/HalKernelMain.cc | 1 + dev/kernel/KernelKit/UserMgr.h | 2 +- dev/libSystem/AsmProc.h | 15 + dev/libSystem/Codes.h | 58 ++++ dev/libSystem/Macros.h | 126 +++++++ dev/libSystem/SecurityPolicy.h | 12 + dev/libSystem/System.h | 385 +++++++++++++++++++++ dev/libSystem/docs/SPECIFICATION_SYSCALLS.md | 25 ++ dev/libSystem/libSystem.json | 20 ++ dev/libSystem/obj/.keep | 0 dev/libSystem/src/GNUmakefile | 16 + dev/libSystem/src/System.cc | 94 +++++ dev/libSystem/src/SystemCalls+IO.asm | 66 ++++ dev/user/AsmProc.h | 15 - dev/user/Macros.h | 126 ------- dev/user/SecurityPolicy.h | 12 - dev/user/SystemCalls.h | 380 -------------------- dev/user/SystemCodes.h | 58 ---- dev/user/docs/SPECIFICATION_SYSCALLS.md | 25 -- dev/user/obj/.keep | 0 dev/user/src/GNUmakefile | 16 - dev/user/src/SystemCalls+IO.asm | 66 ---- dev/user/src/SystemCalls.cc | 94 ----- dev/user/user.json | 20 -- .../frameworks/CoreFoundation.fwrk/headers/Array.h | 2 +- .../CoreFoundation.fwrk/headers/Foundation.h | 2 +- .../CoreFoundation.fwrk/headers/Property.h | 2 +- .../frameworks/CoreFoundation.fwrk/headers/Ref.h | 2 +- .../frameworks/DiskImage.fwrk/headers/DiskImage.h | 2 +- public/tools/cc/src/CommandLine.cc | 2 +- public/tools/diutil/diutil.json | 2 +- public/tools/ld.dyn/src/CommandLine.cc | 2 +- public/tools/ld.fwrk/src/CommandLine.cc | 2 +- public/tools/manual/src/CommandLine.cc | 2 +- public/tools/mgmt/src/CommandLine.cc | 2 +- public/tools/mk.fwrk/Common.h | 2 +- public/tools/mk.fwrk/src/CommandLine.cc | 2 +- public/tools/mk.hefs/src/CommandLine.cc | 2 +- public/tools/mk.nefs/src/CommandLine.cc | 2 +- public/tools/open/src/CommandLine.cc | 2 +- public/tools/ping/src/CommandLine.cc | 2 +- setup_x64_project.sh | 2 +- tooling/mk_app.py | 2 +- tooling/mk_fwrk.py | 2 +- 48 files changed, 895 insertions(+), 844 deletions(-) delete mode 100644 dev/generic_kits/BenchKit/HardwareChrono.h create mode 100644 dev/generic_kits/BenchKit/X64Chrono.h create mode 100644 dev/libSystem/AsmProc.h create mode 100644 dev/libSystem/Codes.h create mode 100644 dev/libSystem/Macros.h create mode 100644 dev/libSystem/SecurityPolicy.h create mode 100644 dev/libSystem/System.h create mode 100644 dev/libSystem/docs/SPECIFICATION_SYSCALLS.md create mode 100644 dev/libSystem/libSystem.json create mode 100644 dev/libSystem/obj/.keep create mode 100644 dev/libSystem/src/GNUmakefile create mode 100644 dev/libSystem/src/System.cc create mode 100644 dev/libSystem/src/SystemCalls+IO.asm delete mode 100644 dev/user/AsmProc.h delete mode 100644 dev/user/Macros.h delete mode 100644 dev/user/SecurityPolicy.h delete mode 100644 dev/user/SystemCalls.h delete mode 100644 dev/user/SystemCodes.h delete mode 100644 dev/user/docs/SPECIFICATION_SYSCALLS.md delete mode 100644 dev/user/obj/.keep delete mode 100644 dev/user/src/GNUmakefile delete mode 100644 dev/user/src/SystemCalls+IO.asm delete mode 100644 dev/user/src/SystemCalls.cc delete mode 100644 dev/user/user.json (limited to 'dev/user') diff --git a/CODEOWNERS b/CODEOWNERS index 3d1f3e45..fa9d0ec8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,5 +1,5 @@ # boot, user, and kernel are owned by amlal@nekernel.org. /dev/kernel/ @amlel-el-mahrouss /dev/boot/ @amlel-el-mahrouss -/dev/user/ @amlel-el-mahrouss +/dev/libSystem/ @amlel-el-mahrouss # some other parts (tooling, frameworks) need ownership too. \ No newline at end of file diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 113c6295..d39c3bcd 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -92,7 +92,7 @@ all: compile-amd64 $(COPY) ../kernel/$(KERNEL) src/root/$(KERNEL) $(COPY) ./modules/SysChk/$(SYSCHK) src/root/$(SYSCHK) $(COPY) ./modules/BootNet/$(BOOTNET) src/root/$(BOOTNET) - $(COPY) ../user/$(SCIKIT) src/root/$(SCIKIT) + $(COPY) ../libSystem/$(SCIKIT) src/root/$(SCIKIT) $(COPY) src/$(BOOTLOADER) src/root/$(BOOTLOADER) $(COPY) ../ddk/$(DDK) src/root/$(DDK) diff --git a/dev/generic_kits/BenchKit/HardwareChrono.h b/dev/generic_kits/BenchKit/HardwareChrono.h deleted file mode 100644 index f6f6fd8c..00000000 --- a/dev/generic_kits/BenchKit/HardwareChrono.h +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - -Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include diff --git a/dev/generic_kits/BenchKit/X64Chrono.h b/dev/generic_kits/BenchKit/X64Chrono.h new file mode 100644 index 00000000..192d1697 --- /dev/null +++ b/dev/generic_kits/BenchKit/X64Chrono.h @@ -0,0 +1,54 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +#if defined(__NE_AMD64__) + +namespace Kernel { +class X64Chrono; +struct X64ChronoTraits; + +struct X64ChronoTraits { +private: + STATIC UInt64 TickImpl_(void) { + UInt64 a = 0, d = 0; + __asm__ volatile("rdtsc" : "=a"(a), "=d"(d)); + return (d << 32) | a; + } + + friend X64Chrono; +}; + +/// @brief X86_64 hardware chrono implementation using the `rdtsc` instruction. +class X64Chrono : public ChronoInterface { + public: + X64Chrono() = default; + ~X64Chrono() override = default; + + NE_COPY_DEFAULT(X64Chrono); + + public: + void Start() override { fStart = X64ChronoTraits::TickImpl_(); } + + void Stop() override { fStop = X64ChronoTraits::TickImpl_(); } + + void Reset() override { + fStart = 0; + fStop = 0; + } + + UInt64 GetElapsedTime() const override { return fStart - fStop; } + + private: + UInt64 fStart = 0; + UInt64 fStop = 0; +}; +} // namespace Kernel + +#endif // defined(__NE_AMD64__) \ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index e7337e62..446a1e85 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/dev/kernel/KernelKit/UserMgr.h b/dev/kernel/KernelKit/UserMgr.h index b7e7ac1d..82f8ca66 100644 --- a/dev/kernel/KernelKit/UserMgr.h +++ b/dev/kernel/KernelKit/UserMgr.h @@ -11,7 +11,7 @@ Revision History: - 04/03/25: Set users directory as /user/ instead of /usr/ + 04/03/25: Set users directory as /libSystem/ instead of /usr/ ------------------------------------------- */ diff --git a/dev/libSystem/AsmProc.h b/dev/libSystem/AsmProc.h new file mode 100644 index 00000000..b707d533 --- /dev/null +++ b/dev/libSystem/AsmProc.h @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); +IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); +IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); +IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/libSystem/Codes.h b/dev/libSystem/Codes.h new file mode 100644 index 00000000..0451df64 --- /dev/null +++ b/dev/libSystem/Codes.h @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Codes.h +/// @brief Process Codes type and values. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + +#define err_local_ok() (kLastError == kErrorSuccess) +#define err_local_fail() (kLastError != kErrorSuccess) +#define err_local_get() (kLastError) + +typedef SInt32 ErrRef; + +inline constexpr ErrRef kErrorSuccess = 0; +inline constexpr ErrRef kErrorExecutable = 33; +inline constexpr ErrRef kErrorExecutableLib = 34; +inline constexpr ErrRef kErrorFileNotFound = 35; +inline constexpr ErrRef kErrorDirectoryNotFound = 36; +inline constexpr ErrRef kErrorDiskReadOnly = 37; +inline constexpr ErrRef kErrorDiskIsFull = 38; +inline constexpr ErrRef kErrorProcessFault = 39; +inline constexpr ErrRef kErrorSocketHangUp = 40; +inline constexpr ErrRef kErrorThreadLocalStorage = 41; +inline constexpr ErrRef kErrorMath = 42; +inline constexpr ErrRef kErrorNoNetwork = 43; +inline constexpr ErrRef kErrorHeapOutOfMemory = 44; +inline constexpr ErrRef kErrorNoSuchDisk = 45; +inline constexpr ErrRef kErrorFileExists = 46; +inline constexpr ErrRef kErrorFormatFailed = 47; +inline constexpr ErrRef kErrorNetworkTimeout = 48; +inline constexpr ErrRef kErrorInternal = 49; +inline constexpr ErrRef kErrorForkAlreadyExists = 50; +inline constexpr ErrRef kErrorOutOfTeamSlot = 51; +inline constexpr ErrRef kErrorHeapNotPresent = 52; +inline constexpr ErrRef kErrorNoEntrypoint = 53; +inline constexpr ErrRef kErrorDiskIsCorrupted = 54; +inline constexpr ErrRef kErrorDisk = 55; +inline constexpr ErrRef kErrorInvalidData = 56; +inline constexpr ErrRef kErrorAsync = 57; +inline constexpr ErrRef kErrorNonBlocking = 58; +inline constexpr ErrRef kErrorIPC = 59; +inline constexpr ErrRef kErrorSign = 60; +inline constexpr ErrRef kErrorInvalidCreds = 61; +inline constexpr ErrRef kErrorCDTrayBroken = 62; +inline constexpr ErrRef kErrorUnrecoverableDisk = 63; +inline constexpr ErrRef kErrorFileLocked = 64; +inline constexpr ErrRef kErrorDiskIsTooTiny = 65; +inline constexpr ErrRef kErrorUnimplemented = -1; + +/// @brief The last error reported by the system to the process. +IMPORT_C ErrRef kLastError; diff --git a/dev/libSystem/Macros.h b/dev/libSystem/Macros.h new file mode 100644 index 00000000..52dc904c --- /dev/null +++ b/dev/libSystem/Macros.h @@ -0,0 +1,126 @@ +/* ------------------------------------------- + +Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +File: Macros.h +Purpose: libsci Macros header. + +------------------------------------------- */ + +#pragma once + +/***********************************************************************************/ +/// @file libSystem/Macros.h +/// @brief Macros and Core types of the SCI (System Call Interface). +/***********************************************************************************/ + +#include + +#define ATTRIBUTE(X) __attribute__((X)) + +#define IMPORT_CXX extern "C++" +#define IMPORT_C extern "C" + +#define DEPRECATED ATTRIBUTE(deprecated) + +#define EXIT_SUCCESS (0) +#define EXIT_FAILURE (1) + +#define FILE_MAX_LEN (256) + +#ifndef BOOL +#define BOOL bool +#endif + +typedef bool Bool; +typedef bool Boolean; +typedef void Void; + +#ifndef __cplusplus +#define true (1) +#define false (0) +#endif + +#define YES true +#define NO false + +typedef __UINT64_TYPE__ UInt64; +typedef __UINT32_TYPE__ UInt32; +typedef __UINT16_TYPE__ UInt16; +typedef __UINT8_TYPE__ UInt8; + +typedef __SIZE_TYPE__ SizeT; + +typedef __INT64_TYPE__ SInt64; +typedef __INT32_TYPE__ SInt32; +typedef __INT16_TYPE__ SInt16; +typedef __INT8_TYPE__ SInt8; + +typedef void* VoidPtr; +typedef __UINTPTR_TYPE__ UIntPtr; +typedef char Char; + +#ifdef __cplusplus +typedef decltype(nullptr) nullPtr; +typedef nullPtr NullPtr; + +#define SCI_COPY_DELETE(KLASS) \ + KLASS& operator=(const KLASS&) = delete; \ + KLASS(const KLASS&) = delete; + +#define SCI_COPY_DEFAULT(KLASS) \ + KLASS& operator=(const KLASS&) = default; \ + KLASS(const KLASS&) = default; + +#define SCI_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ + KLASS(KLASS&&) = delete; + +#define SCI_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ + KLASS(KLASS&&) = default; + +#endif + +IMPORT_C void _rtl_assert(Bool expr, const Char* origin); + +#define MUST_PASS(X) _rtl_assert(X, __FILE__) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(X) \ + (((sizeof(X) / sizeof(*(X))) / (static_cast(!(sizeof(X) % sizeof(*(X))))))) +#endif + +#ifndef KIB +#define KIB(X) (UInt64)((X) / 1024) +#endif + +#ifndef kib_cast +#define kib_cast(X) (UInt64)((X) *1024) +#endif + +#ifndef MIB +#define MIB(X) (UInt64)((UInt64) KIB(X) / 1024) +#endif + +#ifndef mib_cast +#define mib_cast(X) (UInt64)((UInt64) kib_cast(X) * 1024) +#endif + +#ifndef GIB +#define GIB(X) (UInt64)((UInt64) MIB(X) / 1024) +#endif + +#ifndef gib_cast +#define gib_cast(X) (UInt64)((UInt64) mib_cast(X) * 1024) +#endif + +#ifndef TIB +#define TIB(X) (UInt64)((UInt64) GIB(X) / 1024) +#endif + +#ifndef tib_cast +#define tib_cast(X) ((UInt64) gib_cast(X) * 1024) +#endif + +#define SCI_UNUSED(X) ((void) X) diff --git a/dev/libSystem/SecurityPolicy.h b/dev/libSystem/SecurityPolicy.h new file mode 100644 index 00000000..812f52e2 --- /dev/null +++ b/dev/libSystem/SecurityPolicy.h @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file SecurityPolicy.h +/// @brief Hardened Security Policy, used to restrict access to certain system calls. \ No newline at end of file diff --git a/dev/libSystem/System.h b/dev/libSystem/System.h new file mode 100644 index 00000000..920ea2b2 --- /dev/null +++ b/dev/libSystem/System.h @@ -0,0 +1,385 @@ +/* ------------------------------------------- + +Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +File: System.h +Purpose: System Call Interface. + +------------------------------------------- */ + +#ifndef SCI_SYSTEM_CALLS_H +#define SCI_SYSTEM_CALLS_H + +#include + +// ------------------------------------------------------------------------------------------ // +/// @brief Types API. +// ------------------------------------------------------------------------------------------ // + +struct RefType { + UInt32 __hash; + VoidPtr __self; +}; + +typedef RefType* Ref; + +typedef Ref IORef; +typedef Ref FSRef; +typedef Ref DylibRef; +typedef Ref ThreadRef; +typedef Ref SocketRef; +typedef Ref NetworkRef; +typedef Ref MutexRef; +typedef Ref EventRef; +typedef Ref SemaphoreRef; + +// ------------------------------------------------------------------------------------------ // +/// @brief Dynamic Loader API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Get function which is part of the Dylib. +/// @param symbol the symbol to look for +/// @param dll_handle the Dylib handle. +/// @return the proc pointer. +IMPORT_C Ref LdrGetDylibSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); + +/// @brief Open Dylib handle. +/// @param path dll path. +/// @param drv driver letter. +/// @return a dylib ref. +IMPORT_C Ref LdrOpenDylibHandle(_Input const Char* path, _Input const Char* drive_letter); + +/// @brief Close Dylib handle +/// @param dll_handle the dylib ref. +/// @return whether it closed or not. +IMPORT_C UInt32 LdrCloseDylibHandle(_Input Ref* dll_handle); + +// ------------------------------------------------------------------------------------------ // +// File API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Opens a file from a drive. +/// @param fs_path the filesystem path. +/// @param drive_letter drive name, use NULL to use default drive location. +/// @return the file descriptor of the file. +IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter); + +/// @brief Closes a file and flushes its content. +/// @param file_desc the file descriptor. +/// @return Function doesn't return a type. +IMPORT_C Void IoCloseFile(_Input Ref file_desc); + +/// @brief I/O control (ioctl) on a file. +/// @param file_desc the file descriptor. +/// @param ioctl_code the ioctl code. +/// @param in_data the input data. +/// @param out_data the output data. +/// @return the number of bytes written. +/// @note This function is used to control the file descriptor, introduced for HeFS. +IMPORT_C SInt32 IoCtrlFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data, + _Output VoidPtr out_data); + +/// @brief Gets the file mime (if any) +/// @param file_desc the file descriptor. +IMPORT_C const Char* IoMimeFile(_Input Ref file_desc); + +/// @brief Gets the dir DIM. +/// @param dir_desc directory descriptor. +/// @note only works in HeFS, will return nil-x/nil if used on any other filesystem. +IMPORT_C const Char* IoDimFile(_Input Ref dir_desc); + +/// @brief Write data to a file ref +/// @param file_desc the file descriptor. +/// @param out_data the data to write. +/// @param sz_data the size of the data to write. +/// @return the number of bytes written. +IMPORT_C UInt32 IoWriteFile(_Input Ref file_desc, _Output VoidPtr out_data, SizeT sz_data); + +/// @brief Read data from a file. +/// @param file_desc the file descriptor. +/// @param out_data the data to read. +/// @param sz_data the size of the data to read. +IMPORT_C UInt32 IoReadFile(_Input Ref file_desc, _Output VoidPtr* out_data, SizeT sz_data); + +/// @brief Rewind the file pointer to the beginning of the file. +/// @param file_desc the file descriptor. +/// @return the number of bytes read. +IMPORT_C UInt64 IoRewindFile(_Input Ref file_desc); + +/// @brief Tell the current position of the file pointer. +/// @param file_desc the file descriptor. +/// @return the current position of the file pointer. +IMPORT_C UInt64 IoTellFile(_Input Ref file_desc); + +/// @brief Seek file offset from file descriptor. +IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset); + +// ------------------------------------------------------------------------ +// Process API. +// ------------------------------------------------------------------------ + +/// @brief Spawns a Thread Information Block and Global Information Block inside the current +/// process. +/// @param process_id Target Process ID, must be valid. +/// @return > 0 error occurred or already present, = 0 success. +IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id); + +/// @brief Spawns a process with a unique pid (stored as UIntPtr). +/// @param process_path process filesystem path. +/// @return > 0 process was created. +IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp, + SizeT envp_len); + +/// @brief Exits a process with an exit_code. +/// @return if it has succeeded true, otherwise false. +IMPORT_C Bool RtlExitProcess(UIntPtr handle, UIntPtr exit_code); + +// ------------------------------------------------------------------------ +// Memory Manager API. +// ------------------------------------------------------------------------ + +/// @brief Creates a new heap from the process's address space. +/// @param len the length of it. +/// @param flags the flags of it. +/// @return heap pointer. +IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); + +/// @brief Destroys the pointer +/// @param heap the heap itself. +/// @return void. +IMPORT_C SInt32 MmDestroyHeap(_Input VoidPtr heap); + +/// @brief Change protection flags of a memory region. +IMPORT_C SInt32 MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); + +/// @brief Change protection flags of a memory region. +IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); + +/// @brief Fill memory region with CRC32. +IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); + +/// @brief Copy memory region. +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); + +/// @brief Compare memory regions. +IMPORT_C SInt64 MmCmpMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); + +/// @brief Fill memory region. +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); + +/// @brief Compare string regions. +IMPORT_C SInt64 MmStrCmp(_Input const Char* dest, _Input const Char* src); + +/// @brief Get length of string. +IMPORT_C SInt64 MmStrLen(const Char* str); + +// ------------------------------------------------------------------------ +// @brief Error API. +// ------------------------------------------------------------------------ + +IMPORT_C SInt32 ErrGetLastError(Void); + +// ------------------------------------------------------------------------ +// @brief Threading API. +// ------------------------------------------------------------------------ + +/// @brief Exit the current thread. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitCurrentThread(_Input SInt32 exit_code); + +/// @brief Exit the main thread. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitMainThread(_Input SInt32 exit_code); + +/// @brief Exit a thread. +/// @param thread the thread to exit. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitThread(_Input ThreadRef thread, _Input SInt32 exit_code); + +/// @brief Thread procedure function type. +typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); + +/// @brief Creates a thread. +/// @param procedure the thread procedure. +/// @param argument_count number of arguments inside that thread. +/// @param flags Thread flags. +/// @return the thread object. +IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, + SInt32 argument_count, SInt32 flags); + +/// @brief Yields the current thread. +/// @param thread the thread to yield. +IMPORT_C SInt32 ThrYieldThread(ThreadRef thrd); + +/// @brief Joins a thread. +/// @param thread the thread to join. +IMPORT_C SInt32 ThrJoinThread(ThreadRef thrd); + +/// @brief Detach a thread. +/// @param thread the thread to detach. +IMPORT_C SInt32 ThrDetachThread(ThreadRef thrd); + +// ------------------------------------------------------------------------ +// @brief Drive Management API. +// ------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------ // +/// @brief Get the default drive letter. +/// @param void. +/// @return the drive letter. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Char* DrvGetDefaultDriveLetter(Void); + +// ------------------------------------------------------------------------------------------ // +/// @brief Get the drive letter from a path. +/// @param path the path. +/// @return the drive letter. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); + +// ------------------------------------------------------------------------------------------ // +/// @brief Get a mounted drive from a letter. +/// @param letter the letter (A..Z). +/// @return the drive object. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Ref DrvGetMountedDrive(_Input Char letter); + +// ------------------------------------------------------------------------------------------ // +/// @brief Mount a drive. +/// @param path the path to mount. +/// @param letter the letter to mount. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); + +// ------------------------------------------------------------------------------------------ // +/// @brief Unmount a drive. +/// @param letter the letter to unmount. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Void DrvUnmountDrive(_Input Char letter); + +// ------------------------------------------------------------------------ +// Event handling API, use to listen to OS specific events. +// ------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------ // +/// @brief Add an event listener. +/// @param event_name the event name. +/// @param listener the listener to add. +/// @return the event listener. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input Ref listener); + +// ------------------------------------------------------------------------------------------ // +/// @brief Remove an event listener. +/// @param event_name the event name. +/// @param listener the listener to remove. +/// @return the event listener. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input Ref listener); + +// ------------------------------------------------------------------------------------------ // +/// @brief Dispatch an event. +/// @param event_name the event name. +/// @param event_data the event data. +/// @return the event data. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); + +// ------------------------------------------------------------------------------------------ // +// Power API. +// ------------------------------------------------------------------------------------------ // + +enum { + kPowerCodeInvalid = 0, + kPowerCodeShutdown = 12, + kPowerCodeReboot, + kPowerCodeSleep, + kPowerCodeWake, + kPowerCodeCount, +}; + +IMPORT_C SInt32 PwrReadCode(_Output SInt32& code); + +IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); + +// ------------------------------------------------------------------------------------------ // +// CD-ROM API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); + +IMPORT_C SInt32 CdOpenTray(Void); + +IMPORT_C SInt32 CdCloseTray(Void); + +// ------------------------------------------------------------------------------------------ // +// Printer API. +// ------------------------------------------------------------------------------------------ // + +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, ...); + +IMPORT_C IORef PrintCreate(Void); + +IMPORT_C SInt32 PrintRelease(IORef); + +IMPORT_C IORef PrintGet(const Char* path); + +// ------------------------------------------------------------------------------------------ // +// @brief Scheduler/Debug API. +// ------------------------------------------------------------------------------------------ // + +typedef SInt32 AffinityRef; +typedef UInt64 ProcessRef; + +IMPORT_C SInt32 SchedSetAffinity(_Input ProcessRef, SInt32 req, _Input AffinityRef*); + +IMPORT_C SInt32 SchedGetAffinity(_Input ProcessRef, _InOut AffinityRef*); + +IMPORT_C SInt32 SchedFireSignal(_Input ProcessRef, SInt32); + +IMPORT_C SInt32 SchedReadMemory(_Input ProcessRef, SInt32, SInt32); + +IMPORT_C SInt32 SchedWriteMemory(_Input ProcessRef, SInt32, SInt32); + +IMPORT_C UIntPtr SchedGetCurrentProcessID(Void); + +// ------------------------------------------------------------------------------------------ // +// @brief Filesystem API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C BOOL FsCopy(const Char* path, const Char* dst); + +IMPORT_C BOOL FsMove(const Char* path, const Char* dst); + +IMPORT_C BOOL FsExists(const Char* path); + +IMPORT_C BOOL FsCreateDir(const Char* path); + +IMPORT_C BOOL FsCreateFile(const Char* path); + +IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); + +// ------------------------------------------------------------------------------------------ // +// @brief Installable Filesystem API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C BOOL IfsMount(const Char* path, const Char* drive_letter); + +IMPORT_C BOOL IfsUnmount(const Char* drive_letter); + +IMPORT_C BOOL IfsIsMounted(const Char* drive_letter); + +// ------------------------------------------------------------------------------------------ // +// @brief String Manip API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Char* StrFmt(const Char* fmt, ...); + +IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); + +#endif // ifndef SCI_SYSTEM_CALLS_H diff --git a/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md new file mode 100644 index 00000000..b4b11c8c --- /dev/null +++ b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md @@ -0,0 +1,25 @@ +=================================== +# 0: General Information +=================================== + +- **Programming Language**: C / C++ +- **Build System**: Make / BTB (Build the Build) +- **Purpose**: System Call Interface (SCI) for NeKernel + +=================================== +# 1: How It Works +=================================== + +- This header provides the raw API surface for accessing NeKernel's system calls. + +- It is **not** directly used by applications. + - Instead, it is abstracted by the **SystemSDK**, which presents a stable, high-level interface. + +- At runtime: + - System calls are routed from user-space code to the **kernel syscall manager**. + - The syscall manager executes the requested operation and returns control to `libSystem`. + - Finally, the result is delivered back to the originating process. + +- This separation ensures that: + - The SCI remains low-level and close to the ABI. + - `SystemSDK` provides portability and shielding from changes in syscall internals. \ No newline at end of file diff --git a/dev/libSystem/libSystem.json b/dev/libSystem/libSystem.json new file mode 100644 index 00000000..fdcd2a56 --- /dev/null +++ b/dev/libSystem/libSystem.json @@ -0,0 +1,20 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "./"], + "sources_path": ["src/*.cc", "src/*.stub.obj"], + "output_name": "libSystem.sys", + "compiler_flags": [ + "-ffreestanding", + "-shared", + "-fPIC", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17" + ], + "cpp_macros": [ + "kLibSystemVersion=0x0100", + "kLibSystemVersionHighest=0x0100", + "kLibSystemVersionLowest=0x0100" + ] +} diff --git a/dev/libSystem/obj/.keep b/dev/libSystem/obj/.keep new file mode 100644 index 00000000..e69de29b 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_ 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 +#include + +/// @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(const_cast(path)), + reinterpret_cast(const_cast(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(desc), + reinterpret_cast(&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(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(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); + } +} 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 diff --git a/dev/user/AsmProc.h b/dev/user/AsmProc.h deleted file mode 100644 index 4b3b63c1..00000000 --- a/dev/user/AsmProc.h +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); -IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); -IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); -IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/user/Macros.h b/dev/user/Macros.h deleted file mode 100644 index 71957208..00000000 --- a/dev/user/Macros.h +++ /dev/null @@ -1,126 +0,0 @@ -/* ------------------------------------------- - -Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -File: Macros.h -Purpose: libsci Macros header. - -------------------------------------------- */ - -#pragma once - -/***********************************************************************************/ -/// @file user/Macros.h -/// @brief Macros and Core types of the SCI (System Call Interface). -/***********************************************************************************/ - -#include - -#define ATTRIBUTE(X) __attribute__((X)) - -#define IMPORT_CXX extern "C++" -#define IMPORT_C extern "C" - -#define DEPRECATED ATTRIBUTE(deprecated) - -#define EXIT_SUCCESS (0) -#define EXIT_FAILURE (1) - -#define FILE_MAX_LEN (256) - -#ifndef BOOL -#define BOOL bool -#endif - -typedef bool Bool; -typedef bool Boolean; -typedef void Void; - -#ifndef __cplusplus -#define true (1) -#define false (0) -#endif - -#define YES true -#define NO false - -typedef __UINT64_TYPE__ UInt64; -typedef __UINT32_TYPE__ UInt32; -typedef __UINT16_TYPE__ UInt16; -typedef __UINT8_TYPE__ UInt8; - -typedef __SIZE_TYPE__ SizeT; - -typedef __INT64_TYPE__ SInt64; -typedef __INT32_TYPE__ SInt32; -typedef __INT16_TYPE__ SInt16; -typedef __INT8_TYPE__ SInt8; - -typedef void* VoidPtr; -typedef __UINTPTR_TYPE__ UIntPtr; -typedef char Char; - -#ifdef __cplusplus -typedef decltype(nullptr) nullPtr; -typedef nullPtr NullPtr; - -#define SCI_COPY_DELETE(KLASS) \ - KLASS& operator=(const KLASS&) = delete; \ - KLASS(const KLASS&) = delete; - -#define SCI_COPY_DEFAULT(KLASS) \ - KLASS& operator=(const KLASS&) = default; \ - KLASS(const KLASS&) = default; - -#define SCI_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ - KLASS(KLASS&&) = delete; - -#define SCI_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ - KLASS(KLASS&&) = default; - -#endif - -IMPORT_C void _rtl_assert(Bool expr, const Char* origin); - -#define MUST_PASS(X) _rtl_assert(X, __FILE__) - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(X) \ - (((sizeof(X) / sizeof(*(X))) / (static_cast(!(sizeof(X) % sizeof(*(X))))))) -#endif - -#ifndef KIB -#define KIB(X) (UInt64)((X) / 1024) -#endif - -#ifndef kib_cast -#define kib_cast(X) (UInt64)((X) *1024) -#endif - -#ifndef MIB -#define MIB(X) (UInt64)((UInt64) KIB(X) / 1024) -#endif - -#ifndef mib_cast -#define mib_cast(X) (UInt64)((UInt64) kib_cast(X) * 1024) -#endif - -#ifndef GIB -#define GIB(X) (UInt64)((UInt64) MIB(X) / 1024) -#endif - -#ifndef gib_cast -#define gib_cast(X) (UInt64)((UInt64) mib_cast(X) * 1024) -#endif - -#ifndef TIB -#define TIB(X) (UInt64)((UInt64) GIB(X) / 1024) -#endif - -#ifndef tib_cast -#define tib_cast(X) ((UInt64) gib_cast(X) * 1024) -#endif - -#define SCI_UNUSED(X) ((void) X) diff --git a/dev/user/SecurityPolicy.h b/dev/user/SecurityPolicy.h deleted file mode 100644 index a03c928b..00000000 --- a/dev/user/SecurityPolicy.h +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file SecurityPolicy.h -/// @brief Hardened Security Policy, used to restrict access to certain system calls. \ No newline at end of file diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h deleted file mode 100644 index d77c0b8f..00000000 --- a/dev/user/SystemCalls.h +++ /dev/null @@ -1,380 +0,0 @@ -/* ------------------------------------------- - -Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -File: SystemCalls.h -Purpose: System Call Interface. - -------------------------------------------- */ - -#ifndef SCI_SYSTEM_CALLS_H -#define SCI_SYSTEM_CALLS_H - -#include - -// ------------------------------------------------------------------------------------------ // -/// @brief Types API. -// ------------------------------------------------------------------------------------------ // - -typedef VoidPtr Ref; - -typedef Ref IORef; -typedef Ref FSRef; -typedef Ref DylibRef; -typedef Ref ThreadRef; -typedef Ref SocketRef; -typedef Ref NetworkRef; -typedef Ref MutexRef; -typedef Ref EventRef; -typedef Ref SemaphoreRef; - -// ------------------------------------------------------------------------------------------ // -/// @brief Dynamic Loader API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Get function which is part of the Dylib. -/// @param symbol the symbol to look for -/// @param dll_handle the Dylib handle. -/// @return the proc pointer. -IMPORT_C Ref LdrGetDylibSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); - -/// @brief Open Dylib handle. -/// @param path dll path. -/// @param drv driver letter. -/// @return a dylib ref. -IMPORT_C Ref LdrOpenDylibHandle(_Input const Char* path, _Input const Char* drive_letter); - -/// @brief Close Dylib handle -/// @param dll_handle the dylib ref. -/// @return whether it closed or not. -IMPORT_C UInt32 LdrCloseDylibHandle(_Input Ref* dll_handle); - -// ------------------------------------------------------------------------------------------ // -// File API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Opens a file from a drive. -/// @param fs_path the filesystem path. -/// @param drive_letter drive name, use NULL to use default drive location. -/// @return the file descriptor of the file. -IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter); - -/// @brief Closes a file and flushes its content. -/// @param file_desc the file descriptor. -/// @return Function doesn't return a type. -IMPORT_C Void IoCloseFile(_Input Ref file_desc); - -/// @brief I/O control (ioctl) on a file. -/// @param file_desc the file descriptor. -/// @param ioctl_code the ioctl code. -/// @param in_data the input data. -/// @param out_data the output data. -/// @return the number of bytes written. -/// @note This function is used to control the file descriptor, introduced for HeFS. -IMPORT_C SInt32 IoCtrlFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data, - _Output VoidPtr out_data); - -/// @brief Gets the file mime (if any) -/// @param file_desc the file descriptor. -IMPORT_C const Char* IoMimeFile(_Input Ref file_desc); - -/// @brief Gets the dir DIM. -/// @param dir_desc directory descriptor. -/// @note only works in HeFS, will return nil-x/nil if used on any other filesystem. -IMPORT_C const Char* IoDimFile(_Input Ref dir_desc); - -/// @brief Write data to a file ref -/// @param file_desc the file descriptor. -/// @param out_data the data to write. -/// @param sz_data the size of the data to write. -/// @return the number of bytes written. -IMPORT_C UInt32 IoWriteFile(_Input Ref file_desc, _Output VoidPtr out_data, SizeT sz_data); - -/// @brief Read data from a file. -/// @param file_desc the file descriptor. -/// @param out_data the data to read. -/// @param sz_data the size of the data to read. -IMPORT_C UInt32 IoReadFile(_Input Ref file_desc, _Output VoidPtr* out_data, SizeT sz_data); - -/// @brief Rewind the file pointer to the beginning of the file. -/// @param file_desc the file descriptor. -/// @return the number of bytes read. -IMPORT_C UInt64 IoRewindFile(_Input Ref file_desc); - -/// @brief Tell the current position of the file pointer. -/// @param file_desc the file descriptor. -/// @return the current position of the file pointer. -IMPORT_C UInt64 IoTellFile(_Input Ref file_desc); - -/// @brief Seek file offset from file descriptor. -IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset); - -// ------------------------------------------------------------------------ -// Process API. -// ------------------------------------------------------------------------ - -/// @brief Spawns a Thread Information Block and Global Information Block inside the current -/// process. -/// @param process_id Target Process ID, must be valid. -/// @return > 0 error occurred or already present, = 0 success. -IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id); - -/// @brief Spawns a process with a unique pid (stored as UIntPtr). -/// @param process_path process filesystem path. -/// @return > 0 process was created. -IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp, - SizeT envp_len); - -/// @brief Exits a process with an exit_code. -/// @return if it has succeeded true, otherwise false. -IMPORT_C Bool RtlExitProcess(UIntPtr handle, UIntPtr exit_code); - -// ------------------------------------------------------------------------ -// Memory Manager API. -// ------------------------------------------------------------------------ - -/// @brief Creates a new heap from the process's address space. -/// @param len the length of it. -/// @param flags the flags of it. -/// @return heap pointer. -IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); - -/// @brief Destroys the pointer -/// @param heap the heap itself. -/// @return void. -IMPORT_C SInt32 MmDestroyHeap(_Input VoidPtr heap); - -/// @brief Change protection flags of a memory region. -IMPORT_C SInt32 MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); - -/// @brief Change protection flags of a memory region. -IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); - -/// @brief Fill memory region with CRC32. -IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); - -/// @brief Copy memory region. -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); - -/// @brief Compare memory regions. -IMPORT_C SInt64 MmCmpMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); - -/// @brief Fill memory region. -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); - -/// @brief Compare string regions. -IMPORT_C SInt64 MmStrCmp(_Input const Char* dest, _Input const Char* src); - -/// @brief Get length of string. -IMPORT_C SInt64 MmStrLen(const Char* str); - -// ------------------------------------------------------------------------ -// @brief Error API. -// ------------------------------------------------------------------------ - -IMPORT_C SInt32 ErrGetLastError(Void); - -// ------------------------------------------------------------------------ -// @brief Threading API. -// ------------------------------------------------------------------------ - -/// @brief Exit the current thread. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitCurrentThread(_Input SInt32 exit_code); - -/// @brief Exit the main thread. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitMainThread(_Input SInt32 exit_code); - -/// @brief Exit a thread. -/// @param thread the thread to exit. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitThread(_Input ThreadRef thread, _Input SInt32 exit_code); - -/// @brief Thread procedure function type. -typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); - -/// @brief Creates a thread. -/// @param procedure the thread procedure. -/// @param argument_count number of arguments inside that thread. -/// @param flags Thread flags. -/// @return the thread object. -IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, - SInt32 argument_count, SInt32 flags); - -/// @brief Yields the current thread. -/// @param thread the thread to yield. -IMPORT_C SInt32 ThrYieldThread(ThreadRef thrd); - -/// @brief Joins a thread. -/// @param thread the thread to join. -IMPORT_C SInt32 ThrJoinThread(ThreadRef thrd); - -/// @brief Detach a thread. -/// @param thread the thread to detach. -IMPORT_C SInt32 ThrDetachThread(ThreadRef thrd); - -// ------------------------------------------------------------------------ -// @brief Drive Management API. -// ------------------------------------------------------------------------ - -// ------------------------------------------------------------------------------------------ // -/// @brief Get the default drive letter. -/// @param void. -/// @return the drive letter. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Char* DrvGetDefaultDriveLetter(Void); - -// ------------------------------------------------------------------------------------------ // -/// @brief Get the drive letter from a path. -/// @param path the path. -/// @return the drive letter. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); - -// ------------------------------------------------------------------------------------------ // -/// @brief Get a mounted drive from a letter. -/// @param letter the letter (A..Z). -/// @return the drive object. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Ref DrvGetMountedDrive(_Input Char letter); - -// ------------------------------------------------------------------------------------------ // -/// @brief Mount a drive. -/// @param path the path to mount. -/// @param letter the letter to mount. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); - -// ------------------------------------------------------------------------------------------ // -/// @brief Unmount a drive. -/// @param letter the letter to unmount. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Void DrvUnmountDrive(_Input Char letter); - -// ------------------------------------------------------------------------ -// Event handling API, use to listen to OS specific events. -// ------------------------------------------------------------------------ - -// ------------------------------------------------------------------------------------------ // -/// @brief Add an event listener. -/// @param event_name the event name. -/// @param listener the listener to add. -/// @return the event listener. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input Ref listener); - -// ------------------------------------------------------------------------------------------ // -/// @brief Remove an event listener. -/// @param event_name the event name. -/// @param listener the listener to remove. -/// @return the event listener. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input Ref listener); - -// ------------------------------------------------------------------------------------------ // -/// @brief Dispatch an event. -/// @param event_name the event name. -/// @param event_data the event data. -/// @return the event data. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); - -// ------------------------------------------------------------------------------------------ // -// Power API. -// ------------------------------------------------------------------------------------------ // - -enum { - kPowerCodeInvalid = 0, - kPowerCodeShutdown = 12, - kPowerCodeReboot, - kPowerCodeSleep, - kPowerCodeWake, - kPowerCodeCount, -}; - -IMPORT_C SInt32 PwrReadCode(_Output SInt32& code); - -IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); - -// ------------------------------------------------------------------------------------------ // -// CD-ROM API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); - -IMPORT_C SInt32 CdOpenTray(Void); - -IMPORT_C SInt32 CdCloseTray(Void); - -// ------------------------------------------------------------------------------------------ // -// Printer API. -// ------------------------------------------------------------------------------------------ // - -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, ...); - -IMPORT_C IORef PrintCreate(Void); - -IMPORT_C SInt32 PrintRelease(IORef); - -IMPORT_C IORef PrintGet(const Char* path); - -// ------------------------------------------------------------------------------------------ // -// @brief Scheduler/Debug API. -// ------------------------------------------------------------------------------------------ // - -typedef SInt32 AffinityRef; -typedef UInt64 ProcessRef; - -IMPORT_C SInt32 SchedSetAffinity(_Input ProcessRef, SInt32 req, _Input AffinityRef*); - -IMPORT_C SInt32 SchedGetAffinity(_Input ProcessRef, _InOut AffinityRef*); - -IMPORT_C SInt32 SchedFireSignal(_Input ProcessRef, SInt32); - -IMPORT_C SInt32 SchedReadMemory(_Input ProcessRef, SInt32, SInt32); - -IMPORT_C SInt32 SchedWriteMemory(_Input ProcessRef, SInt32, SInt32); - -IMPORT_C UIntPtr SchedGetCurrentProcessID(Void); - -// ------------------------------------------------------------------------------------------ // -// @brief Filesystem API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C BOOL FsCopy(const Char* path, const Char* dst); - -IMPORT_C BOOL FsMove(const Char* path, const Char* dst); - -IMPORT_C BOOL FsExists(const Char* path); - -IMPORT_C BOOL FsCreateDir(const Char* path); - -IMPORT_C BOOL FsCreateFile(const Char* path); - -IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); - -// ------------------------------------------------------------------------------------------ // -// @brief Installable Filesystem API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C BOOL IfsMount(const Char* path, const Char* drive_letter); - -IMPORT_C BOOL IfsUnmount(const Char* drive_letter); - -IMPORT_C BOOL IfsIsMounted(const Char* drive_letter); - -// ------------------------------------------------------------------------------------------ // -// @brief String Manip API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Char* StrFmt(const Char* fmt, ...); - -IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); - -#endif // ifndef SCI_SYSTEM_CALLS_H diff --git a/dev/user/SystemCodes.h b/dev/user/SystemCodes.h deleted file mode 100644 index 90457944..00000000 --- a/dev/user/SystemCodes.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file ProcessCodes.h -/// @brief Process Codes type and values. -/// @author Amlal El Mahrouss (amlal@nekernel.org) - -#define err_local_ok() (kLastError == kErrorSuccess) -#define err_local_fail() (kLastError != kErrorSuccess) -#define err_local_get() (kLastError) - -typedef SInt32 ErrRef; - -inline constexpr ErrRef kErrorSuccess = 0; -inline constexpr ErrRef kErrorExecutable = 33; -inline constexpr ErrRef kErrorExecutableLib = 34; -inline constexpr ErrRef kErrorFileNotFound = 35; -inline constexpr ErrRef kErrorDirectoryNotFound = 36; -inline constexpr ErrRef kErrorDiskReadOnly = 37; -inline constexpr ErrRef kErrorDiskIsFull = 38; -inline constexpr ErrRef kErrorProcessFault = 39; -inline constexpr ErrRef kErrorSocketHangUp = 40; -inline constexpr ErrRef kErrorThreadLocalStorage = 41; -inline constexpr ErrRef kErrorMath = 42; -inline constexpr ErrRef kErrorNoNetwork = 43; -inline constexpr ErrRef kErrorHeapOutOfMemory = 44; -inline constexpr ErrRef kErrorNoSuchDisk = 45; -inline constexpr ErrRef kErrorFileExists = 46; -inline constexpr ErrRef kErrorFormatFailed = 47; -inline constexpr ErrRef kErrorNetworkTimeout = 48; -inline constexpr ErrRef kErrorInternal = 49; -inline constexpr ErrRef kErrorForkAlreadyExists = 50; -inline constexpr ErrRef kErrorOutOfTeamSlot = 51; -inline constexpr ErrRef kErrorHeapNotPresent = 52; -inline constexpr ErrRef kErrorNoEntrypoint = 53; -inline constexpr ErrRef kErrorDiskIsCorrupted = 54; -inline constexpr ErrRef kErrorDisk = 55; -inline constexpr ErrRef kErrorInvalidData = 56; -inline constexpr ErrRef kErrorAsync = 57; -inline constexpr ErrRef kErrorNonBlocking = 58; -inline constexpr ErrRef kErrorIPC = 59; -inline constexpr ErrRef kErrorSign = 60; -inline constexpr ErrRef kErrorInvalidCreds = 61; -inline constexpr ErrRef kErrorCDTrayBroken = 62; -inline constexpr ErrRef kErrorUnrecoverableDisk = 63; -inline constexpr ErrRef kErrorFileLocked = 64; -inline constexpr ErrRef kErrorDiskIsTooTiny = 65; -inline constexpr ErrRef kErrorUnimplemented = -1; - -/// @brief The last error reported by the system to the process. -IMPORT_C ErrRef kLastError; diff --git a/dev/user/docs/SPECIFICATION_SYSCALLS.md b/dev/user/docs/SPECIFICATION_SYSCALLS.md deleted file mode 100644 index b4b11c8c..00000000 --- a/dev/user/docs/SPECIFICATION_SYSCALLS.md +++ /dev/null @@ -1,25 +0,0 @@ -=================================== -# 0: General Information -=================================== - -- **Programming Language**: C / C++ -- **Build System**: Make / BTB (Build the Build) -- **Purpose**: System Call Interface (SCI) for NeKernel - -=================================== -# 1: How It Works -=================================== - -- This header provides the raw API surface for accessing NeKernel's system calls. - -- It is **not** directly used by applications. - - Instead, it is abstracted by the **SystemSDK**, which presents a stable, high-level interface. - -- At runtime: - - System calls are routed from user-space code to the **kernel syscall manager**. - - The syscall manager executes the requested operation and returns control to `libSystem`. - - Finally, the result is delivered back to the originating process. - -- This separation ensures that: - - The SCI remains low-level and close to the ABI. - - `SystemSDK` provides portability and shielding from changes in syscall internals. \ No newline at end of file diff --git a/dev/user/obj/.keep b/dev/user/obj/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/user/src/GNUmakefile b/dev/user/src/GNUmakefile deleted file mode 100644 index 9b901f9f..00000000 --- a/dev/user/src/GNUmakefile +++ /dev/null @@ -1,16 +0,0 @@ -################################################## -# (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_ instead." - -.PHONY: sci_asm_io_x64 -sci_asm_io_x64: - $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.stub.obj diff --git a/dev/user/src/SystemCalls+IO.asm b/dev/user/src/SystemCalls+IO.asm deleted file mode 100644 index 097046af..00000000 --- a/dev/user/src/SystemCalls+IO.asm +++ /dev/null @@ -1,66 +0,0 @@ -;; /* -;; * ======================================================== -;; * -;; * 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 diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc deleted file mode 100644 index f004718c..00000000 --- a/dev/user/src/SystemCalls.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/// @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(const_cast(path)), - reinterpret_cast(const_cast(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(desc), - reinterpret_cast(&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(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(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); - } -} diff --git a/dev/user/user.json b/dev/user/user.json deleted file mode 100644 index 2267175e..00000000 --- a/dev/user/user.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["../", "./"], - "sources_path": ["src/*.cc", "src/*.stub.obj"], - "output_name": "libSystem.sys", - "compiler_flags": [ - "-ffreestanding", - "-shared", - "-fPIC", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17" - ], - "cpp_macros": [ - "kSCIVersion=0x0100", - "kSCIVersionHighest=0x0100", - "kSCIVersionLowest=0x0100" - ] -} diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Array.h b/public/frameworks/CoreFoundation.fwrk/headers/Array.h index 0b4a8dbf..55e75e5e 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Array.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Array.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace CF { template diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h index 194b7bb7..1f295ea5 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h @@ -10,7 +10,7 @@ #pragma once -#include +#include namespace CF { class CFString; diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Property.h b/public/frameworks/CoreFoundation.fwrk/headers/Property.h index 58e881e5..4da173c7 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Property.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Property.h @@ -8,7 +8,7 @@ #define _PROPS_H #include -#include +#include #define kMaxPropLen (256U) diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h index c18c6161..cb72a034 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h @@ -9,7 +9,7 @@ #define _REF_H_ #include -#include +#include namespace CF { template diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h index fc37ab59..efc21253 100644 --- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h +++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h @@ -9,7 +9,7 @@ #pragma once -#include +#include #ifndef __DISK_IMAGE_CDROM__ #define kDISectorSz (512) diff --git a/public/tools/cc/src/CommandLine.cc b/public/tools/cc/src/CommandLine.cc index 719a1555..f1c72b64 100644 --- a/public/tools/cc/src/CommandLine.cc +++ b/public/tools/cc/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/diutil/diutil.json b/public/tools/diutil/diutil.json index a7a49697..a863634b 100644 --- a/public/tools/diutil/diutil.json +++ b/public/tools/diutil/diutil.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["./", "../../../dev/kernel", "../../../public/frameworks/", "../../../dev/", "./"], - "sources_path": ["src/CommandLine.cc", "../../../public/frameworks/DiskImage.fwrk/src/*.cc", "../../../dev/user/src/*.cc"], + "sources_path": ["src/CommandLine.cc", "../../../public/frameworks/DiskImage.fwrk/src/*.cc", "../../../dev/libSystem/src/*.cc"], "output_name": "./dist/diutil", "cpp_macros": [ "kDUTILVersion=0x0100", diff --git a/public/tools/ld.dyn/src/CommandLine.cc b/public/tools/ld.dyn/src/CommandLine.cc index 377f22fa..e76c34a7 100644 --- a/public/tools/ld.dyn/src/CommandLine.cc +++ b/public/tools/ld.dyn/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief Library loader. diff --git a/public/tools/ld.fwrk/src/CommandLine.cc b/public/tools/ld.fwrk/src/CommandLine.cc index 0fbaaf2e..e7a6e5ca 100644 --- a/public/tools/ld.fwrk/src/CommandLine.cc +++ b/public/tools/ld.fwrk/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief This program loads a code framework into Kernel's memory. diff --git a/public/tools/manual/src/CommandLine.cc b/public/tools/manual/src/CommandLine.cc index a1cd9094..0704384a 100644 --- a/public/tools/manual/src/CommandLine.cc +++ b/public/tools/manual/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { SCI_UNUSED(argc); diff --git a/public/tools/mgmt/src/CommandLine.cc b/public/tools/mgmt/src/CommandLine.cc index 45990d08..f3840d01 100644 --- a/public/tools/mgmt/src/CommandLine.cc +++ b/public/tools/mgmt/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { return EXIT_FAILURE; diff --git a/public/tools/mk.fwrk/Common.h b/public/tools/mk.fwrk/Common.h index be016be6..89e52471 100644 --- a/public/tools/mk.fwrk/Common.h +++ b/public/tools/mk.fwrk/Common.h @@ -7,6 +7,6 @@ #define APPS_COMMON_H #include -#include +#include #endif // APPS_COMMON_H diff --git a/public/tools/mk.fwrk/src/CommandLine.cc b/public/tools/mk.fwrk/src/CommandLine.cc index 202f21bb..4ef7240a 100644 --- a/public/tools/mk.fwrk/src/CommandLine.cc +++ b/public/tools/mk.fwrk/src/CommandLine.cc @@ -7,7 +7,7 @@ #include #include -#include +#include #include diff --git a/public/tools/mk.hefs/src/CommandLine.cc b/public/tools/mk.hefs/src/CommandLine.cc index dd8be97f..711009d5 100644 --- a/public/tools/mk.hefs/src/CommandLine.cc +++ b/public/tools/mk.hefs/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/mk.nefs/src/CommandLine.cc b/public/tools/mk.nefs/src/CommandLine.cc index dd8be97f..711009d5 100644 --- a/public/tools/mk.nefs/src/CommandLine.cc +++ b/public/tools/mk.nefs/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/open/src/CommandLine.cc b/public/tools/open/src/CommandLine.cc index f2378599..6fa4e2f2 100644 --- a/public/tools/open/src/CommandLine.cc +++ b/public/tools/open/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief This program opens an application from **OPEN_APP_BASE_PATH** /// @file CommandLine.cc diff --git a/public/tools/ping/src/CommandLine.cc b/public/tools/ping/src/CommandLine.cc index 7ef58e81..f5c82b80 100644 --- a/public/tools/ping/src/CommandLine.cc +++ b/public/tools/ping/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { SCI_UNUSED(argc); diff --git a/setup_x64_project.sh b/setup_x64_project.sh index a6115ba7..ba7d4b3f 100755 --- a/setup_x64_project.sh +++ b/setup_x64_project.sh @@ -8,7 +8,7 @@ cd dev/user cd src make sci_asm_io_x64 cd .. -btb user.json +btb libSystem.json cd ../ddk btb ddk.json cd ../boot diff --git a/tooling/mk_app.py b/tooling/mk_app.py index a40c6dee..5ee6d5b7 100755 --- a/tooling/mk_app.py +++ b/tooling/mk_app.py @@ -64,7 +64,7 @@ def create_directory_structure(base_path, project_name): proj_cpp_path = os.path.join(base_path, project_name, f"src/CommandLine.cc") - cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py index 78659686..e4e5d7de 100755 --- a/tooling/mk_fwrk.py +++ b/tooling/mk_fwrk.py @@ -70,7 +70,7 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name): proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/DylibMain.cc") - cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) -- cgit v1.2.3