diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-27 20:03:26 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-27 20:06:13 +0200 |
| commit | 1a44b4385b3250cd90e255d7d787ae69e987544b (patch) | |
| tree | fb637575951b8cc98834bed59daf4072583d5a17 | |
| parent | bdc831c1df0dd2af95f09fd1b86b4472c40d12b7 (diff) | |
feat: generic_kits: Add X64Chrono inside BenchKit.
refactor: libSystem: Refactored as a whole.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
37 files changed, 96 insertions, 45 deletions
@@ -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 <BenchKit/Chrono.h> 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 <generic_kits/BenchKit/Chrono.h> + +#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 <KernelKit/Timer.h> #include <NetworkKit/IPC.h> #include <StorageKit/AHCI.h> +#include <generic_kits/BenchKit/X64Chrono.h> #include <modules/ACPI/ACPIFactoryInterface.h> #include <modules/CoreGfx/TextGfx.h> 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/user/AsmProc.h b/dev/libSystem/AsmProc.h index 4b3b63c1..b707d533 100644 --- a/dev/user/AsmProc.h +++ b/dev/libSystem/AsmProc.h @@ -6,7 +6,7 @@ #pragma once -#include <user/SystemCalls.h> +#include <libSystem/System.h> #include <cstdarg> IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); diff --git a/dev/user/SystemCodes.h b/dev/libSystem/Codes.h index 90457944..0451df64 100644 --- a/dev/user/SystemCodes.h +++ b/dev/libSystem/Codes.h @@ -6,9 +6,9 @@ #pragma once -#include <user/Macros.h> +#include <libSystem/Macros.h> -/// @file ProcessCodes.h +/// @file Codes.h /// @brief Process Codes type and values. /// @author Amlal El Mahrouss (amlal@nekernel.org) diff --git a/dev/user/Macros.h b/dev/libSystem/Macros.h index 71957208..52dc904c 100644 --- a/dev/user/Macros.h +++ b/dev/libSystem/Macros.h @@ -10,7 +10,7 @@ Purpose: libsci Macros header. #pragma once /***********************************************************************************/ -/// @file user/Macros.h +/// @file libSystem/Macros.h /// @brief Macros and Core types of the SCI (System Call Interface). /***********************************************************************************/ diff --git a/dev/user/SecurityPolicy.h b/dev/libSystem/SecurityPolicy.h index a03c928b..812f52e2 100644 --- a/dev/user/SecurityPolicy.h +++ b/dev/libSystem/SecurityPolicy.h @@ -6,7 +6,7 @@ #pragma once -#include <user/SystemCalls.h> +#include <libSystem/System.h> /// @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/libSystem/System.h index d77c0b8f..920ea2b2 100644 --- a/dev/user/SystemCalls.h +++ b/dev/libSystem/System.h @@ -2,7 +2,7 @@ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
-File: SystemCalls.h
+File: System.h
Purpose: System Call Interface.
------------------------------------------- */
@@ -10,13 +10,18 @@ Purpose: System Call Interface. #ifndef SCI_SYSTEM_CALLS_H
#define SCI_SYSTEM_CALLS_H
-#include <user/Macros.h>
+#include <libSystem/Macros.h>
// ------------------------------------------------------------------------------------------ //
/// @brief Types API.
// ------------------------------------------------------------------------------------------ //
-typedef VoidPtr Ref;
+struct RefType {
+ UInt32 __hash;
+ VoidPtr __self;
+};
+
+typedef RefType* Ref;
typedef Ref IORef;
typedef Ref FSRef;
diff --git a/dev/user/docs/SPECIFICATION_SYSCALLS.md b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md index b4b11c8c..b4b11c8c 100644 --- a/dev/user/docs/SPECIFICATION_SYSCALLS.md +++ b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md diff --git a/dev/user/user.json b/dev/libSystem/libSystem.json index 2267175e..fdcd2a56 100644 --- a/dev/user/user.json +++ b/dev/libSystem/libSystem.json @@ -13,8 +13,8 @@ "-Wl,--subsystem=17" ], "cpp_macros": [ - "kSCIVersion=0x0100", - "kSCIVersionHighest=0x0100", - "kSCIVersionLowest=0x0100" + "kLibSystemVersion=0x0100", + "kLibSystemVersionHighest=0x0100", + "kLibSystemVersionLowest=0x0100" ] } diff --git a/dev/user/obj/.keep b/dev/libSystem/obj/.keep index e69de29b..e69de29b 100644 --- a/dev/user/obj/.keep +++ b/dev/libSystem/obj/.keep diff --git a/dev/user/src/GNUmakefile b/dev/libSystem/src/GNUmakefile index 9b901f9f..9b901f9f 100644 --- a/dev/user/src/GNUmakefile +++ b/dev/libSystem/src/GNUmakefile diff --git a/dev/user/src/SystemCalls.cc b/dev/libSystem/src/System.cc index f004718c..1c28303d 100644 --- a/dev/user/src/SystemCalls.cc +++ b/dev/libSystem/src/System.cc @@ -4,8 +4,8 @@ ------------------------------------------- */
-#include <user/AsmProc.h>
-#include <user/SystemCalls.h>
+#include <libSystem/AsmProc.h>
+#include <libSystem/System.h>
/// @file SystemCalls.cc
/// @brief Source file for the memory functions/syscalls for libSystem.sys
diff --git a/dev/user/src/SystemCalls+IO.asm b/dev/libSystem/src/SystemCalls+IO.asm index 097046af..097046af 100644 --- a/dev/user/src/SystemCalls+IO.asm +++ b/dev/libSystem/src/SystemCalls+IO.asm 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 <user/SystemCalls.h> +#include <libSystem/System.h> namespace CF { template <typename T, SizeT N> 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 <user/SystemCalls.h> +#include <libSystem/System.h> 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 <CoreFoundation.fwrk/headers/Ref.h> -#include <user/SystemCalls.h> +#include <libSystem/System.h> #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 <CoreFoundation.fwrk/headers/Object.h> -#include <user/SystemCalls.h> +#include <libSystem/System.h> namespace CF { template <typename T> 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 <user/SystemCalls.h> +#include <libSystem/System.h> #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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> 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 <user/SystemCalls.h> +#include <libSystem/System.h> 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 <CoreFoundation.fwrk/headers/Foundation.h> -#include <user/SystemCalls.h> +#include <libSystem/System.h> #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 <Framework.h> #include <Steps.h> -#include <user/ProcessCodes.h> +#include <libSystem/ProcessCodes.h> #include <CoreFoundation.fwrk/headers/Array.h> 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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> /// @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 <user/SystemCalls.h> +#include <libSystem/System.h> 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 <user/SystemCalls.h>\n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include <libSystem/System.h>\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 <user/SystemCalls.h>\n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include <libSystem/System.h>\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) |
