From f5f62b145d472a2a2c388c385be9d1c4e5b5d84c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 13 May 2025 08:46:49 +0200 Subject: feat(kernel): see below for the commit's details. what? - UserProcessScheduler and CoreProcessScheduler have been extended for FILE_TREE and also HEAP_TREE structures. - DDK device's API will use dk_ calls instead of sk_ calls. - SIGTRAP and Interrupt handlers have been fixed to handle when no process is being run, and the kernel is instead raising the interrupt. - Add file for HeFS formating in DiskImage.fwrk - Replace generic handler with breakpoint handler in int 3. why? - These changes are bug fixes and improvements. Signed-off-by: Amlal El Mahrouss --- .../DiskImage.fwrk/src/DiskImage+HeFS.cc | 32 ++++++++++++++++++++++ .../DiskImage.fwrk/src/DiskImage+NeFS.cc | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc (limited to 'public/frameworks') diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc new file mode 100644 index 00000000..39f53a7a --- /dev/null +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + FILE: DiskImage+NeFS.cc + PURPOSE: Disk Imaging framework. + + ------------------------------------------- */ + +#include + +#include +#include + +/// @brief format HeFS over an EPM disk. +/// @param img disk image structure. +/// @return Status code upon completion. +SInt32 DI::DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept { + if (!img.sector_sz || (img.sector_sz % 512 != 0)) return kDIFailureStatus; + + if (*img.out_name == 0 || *img.disk_name == 0) return kDIFailureStatus; + + IORef handle = IoOpenFile(img.out_name, nullptr); + + if (!handle) return kDIFailureStatus; + + ::IoCloseFile(handle); + + handle = nullptr; + + return kDISuccessStatus; +} \ No newline at end of file diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc index bee84cca..9f5aa12b 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc @@ -12,7 +12,7 @@ #include #include -/// @brief NeFS format over EPM. +/// @brief format NeFS over an EPM disk. /// @param img disk image structure. /// @return Status code upon completion. SInt32 DI::DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept { -- 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 'public/frameworks') 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 ae3cd5cde93702305fe68b38e052d1f936ee5c93 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 10:18:04 +0200 Subject: feat(DiskImage.fwrk): Fix duplicate symbols link error. Signed-off-by: Amlal El Mahrouss --- public/frameworks/DiskImage.fwrk/headers/DiskImage.h | 5 +++++ public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'public/frameworks') diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h index 78b39bf8..04b460b2 100644 --- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h +++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h @@ -46,4 +46,9 @@ SInt32 DIFormatPartitionEPM(struct DI_DISK_IMAGE& img) noexcept; /// @return Status code upon completion. SInt32 DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept; +/// @brief HeFS format over EPM. +/// @param img disk image structure. +/// @return Status code upon completion. +SInt32 DIFormatFilesystemHeFS(struct DI_DISK_IMAGE& img) noexcept; + } // namespace DI diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc index 39f53a7a..c14c2ed0 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc @@ -15,7 +15,7 @@ /// @brief format HeFS over an EPM disk. /// @param img disk image structure. /// @return Status code upon completion. -SInt32 DI::DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept { +SInt32 DI::DIFormatFilesystemHeFS(struct DI_DISK_IMAGE& img) noexcept { if (!img.sector_sz || (img.sector_sz % 512 != 0)) return kDIFailureStatus; if (*img.out_name == 0 || *img.disk_name == 0) return kDIFailureStatus; -- cgit v1.2.3 From 2254f391e710d9c357d1b806b47786270d77d2b7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 14 May 2025 12:47:30 +0200 Subject: feat(kernel): Improved DiskImage.fwrk's Format functions, don't assume that 512B is always what we want when formating a disk. Signed-off-by: Amlal El Mahrouss --- dev/ddk/DDKKit/ifs.h | 17 ----------------- public/frameworks/DiskImage.fwrk/headers/DiskImage.h | 5 +++++ public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc | 4 ++-- public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) delete mode 100644 dev/ddk/DDKKit/ifs.h (limited to 'public/frameworks') diff --git a/dev/ddk/DDKKit/ifs.h b/dev/ddk/DDKKit/ifs.h deleted file mode 100644 index f03ed53c..00000000 --- a/dev/ddk/DDKKit/ifs.h +++ /dev/null @@ -1,17 +0,0 @@ -/* ------------------------------------------- - - Copyright 2025 Amlal El Mahrouss, all right reserved. - - FILE: ifs.h - PURPOSE: IFS model base header. - -------------------------------------------- */ - -#pragma once - -#include - -struct DDK_IFS_MANIFEST; - -/// @brief IFS hooks to plug into the FileMgr. -/// why? because we don't need to implement filesystem on the kernel directly. diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h index 04b460b2..fc37ab59 100644 --- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h +++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h @@ -11,7 +11,12 @@ #include +#ifndef __DISK_IMAGE_CDROM__ #define kDISectorSz (512) +#else +#define kDISectorSz (2048) +#endif // __DISK_IMAGE_CDROM__ + #define kDIMinDiskSz mib_cast(1) #define kDIDefaultOutputName "disk.eimg" #define kDIDefaultDiskName "Disk" diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc index c14c2ed0..7f917052 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+HeFS.cc @@ -2,7 +2,7 @@ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - FILE: DiskImage+NeFS.cc + FILE: DiskImage+HeFS.cc PURPOSE: Disk Imaging framework. ------------------------------------------- */ @@ -16,7 +16,7 @@ /// @param img disk image structure. /// @return Status code upon completion. SInt32 DI::DIFormatFilesystemHeFS(struct DI_DISK_IMAGE& img) noexcept { - if (!img.sector_sz || (img.sector_sz % 512 != 0)) return kDIFailureStatus; + if (!img.sector_sz || (img.sector_sz % kDISectorSz != 0)) return kDIFailureStatus; if (*img.out_name == 0 || *img.disk_name == 0) return kDIFailureStatus; diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc index 9f5aa12b..c4f32c95 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+NeFS.cc @@ -16,7 +16,7 @@ /// @param img disk image structure. /// @return Status code upon completion. SInt32 DI::DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept { - if (!img.sector_sz || (img.sector_sz % 512 != 0)) return kDIFailureStatus; + if (!img.sector_sz || (img.sector_sz % kDISectorSz != 0)) return kDIFailureStatus; if (*img.out_name == 0 || *img.disk_name == 0) return kDIFailureStatus; -- cgit v1.2.3 From fc67c4af554189c941c811486a0b2b21aa3f54ea Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 23 May 2025 04:07:12 +0200 Subject: feat!(kernel): Rename NewKit to NeKit. Signed-off-by: Amlal El Mahrouss --- dev/boot/BootKit/BootKit.h | 2 +- dev/boot/modules/SysChk/SysChk.cc | 4 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 4 +- dev/boot/src/HEL/ARM64/BootEFI.cc | 4 +- dev/generic_kits/BenchKit/Chrono.h | 2 +- dev/kernel/ArchKit/ArchKit.h | 6 +- dev/kernel/CFKit/GUIDWizard.h | 14 +- dev/kernel/CFKit/GUIDWrapper.h | 6 +- dev/kernel/CFKit/Property.h | 8 +- dev/kernel/CompilerKit/Detail.h | 2 +- dev/kernel/FSKit/Defines.h | 2 +- dev/kernel/FSKit/Ext2.h | 4 +- dev/kernel/FSKit/HeFS.h | 6 +- dev/kernel/FSKit/NeFS.h | 4 +- dev/kernel/FirmwareKit/CoreBoot/BootNet.h | 2 +- dev/kernel/FirmwareKit/CoreBoot/CoreBoot.h | 2 +- dev/kernel/FirmwareKit/EFI/EFI.h | 2 +- dev/kernel/FirmwareKit/EFI/NS.h | 2 +- dev/kernel/FirmwareKit/EPM.h | 2 +- dev/kernel/FirmwareKit/GPT.h | 2 +- dev/kernel/FirmwareKit/Handover.h | 2 +- dev/kernel/GfxKit/FB.h | 17 +- dev/kernel/HALKit/AMD64/CPUID.h | 2 +- dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc | 2 +- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 2 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 2 +- dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 4 +- dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc | 4 +- dev/kernel/HALKit/AMD64/HalKernelPanic.cc | 6 +- dev/kernel/HALKit/AMD64/Hypervisor.h | 2 +- dev/kernel/HALKit/AMD64/Paging.h | 2 +- dev/kernel/HALKit/AMD64/Processor.h | 6 +- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 2 +- dev/kernel/HALKit/ARM64/ApplicationProcessor.h | 2 +- dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc | 2 +- dev/kernel/HALKit/ARM64/HalDebugOutput.cc | 4 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/ARM64/HalKernelPanic.cc | 6 +- dev/kernel/HALKit/ARM64/Paging.h | 2 +- dev/kernel/HALKit/ARM64/Processor.h | 6 +- dev/kernel/HALKit/POWER/AP.h | 2 +- dev/kernel/HALKit/POWER/Processor.h | 4 +- dev/kernel/HALKit/RISCV/AP.h | 2 +- dev/kernel/KernelKit/BinaryMutex.h | 2 +- dev/kernel/KernelKit/CoreProcessScheduler.h | 4 +- dev/kernel/KernelKit/DebugOutput.h | 6 +- dev/kernel/KernelKit/Defines.h | 9 +- dev/kernel/KernelKit/DeviceMgr.h | 4 +- dev/kernel/KernelKit/DriveMgr.h | 6 +- dev/kernel/KernelKit/FileMgr.h | 6 +- dev/kernel/KernelKit/HardwareThreadScheduler.h | 2 +- dev/kernel/KernelKit/IDylibObject.h | 2 +- dev/kernel/KernelKit/IPEFDylibObject.h | 2 +- dev/kernel/KernelKit/KPC.h | 2 +- dev/kernel/KernelKit/LoaderInterface.h | 4 +- dev/kernel/KernelKit/LockDelegate.h | 4 +- dev/kernel/KernelKit/MSDOS.h | 2 +- dev/kernel/KernelKit/MemoryMgr.h | 2 +- dev/kernel/KernelKit/PCI/DMA.h | 6 +- dev/kernel/KernelKit/PCI/Database.h | 2 +- dev/kernel/KernelKit/PCI/Device.h | 2 +- dev/kernel/KernelKit/PCI/Express.h | 2 +- dev/kernel/KernelKit/PCI/IO.h | 6 +- dev/kernel/KernelKit/PCI/Iterator.h | 6 +- dev/kernel/KernelKit/PCI/PCI.h | 2 +- dev/kernel/KernelKit/PE.h | 2 +- dev/kernel/KernelKit/PECodeMgr.h | 4 +- dev/kernel/KernelKit/PEF.h | 2 +- dev/kernel/KernelKit/PEFCodeMgr.h | 4 +- dev/kernel/KernelKit/Semaphore.h | 2 +- dev/kernel/KernelKit/ThreadLocalStorage.h | 4 +- dev/kernel/KernelKit/User.h | 4 +- dev/kernel/KernelKit/UserProcessScheduler.h | 2 +- dev/kernel/KernelKit/XCOFF.h | 2 +- dev/kernel/NeKit/Array.h | 46 +++++ dev/kernel/NeKit/ArrayList.h | 44 +++++ dev/kernel/NeKit/Atom.h | 33 ++++ dev/kernel/NeKit/Crc32.h | 22 +++ dev/kernel/NeKit/CxxAbi.h | 26 +++ dev/kernel/NeKit/Defines.h | 176 ++++++++++++++++++ dev/kernel/NeKit/ErrorOr.h | 56 ++++++ dev/kernel/NeKit/Function.h | 51 ++++++ dev/kernel/NeKit/Json.h | 129 +++++++++++++ dev/kernel/NeKit/KString.h | 82 +++++++++ dev/kernel/NeKit/KernelPanic.h | 69 +++++++ dev/kernel/NeKit/Macros.h | 148 +++++++++++++++ dev/kernel/NeKit/MutableArray.h | 203 +++++++++++++++++++++ dev/kernel/NeKit/NeKit.h | 20 ++ dev/kernel/NeKit/New.h | 20 ++ dev/kernel/NeKit/OwnPtr.h | 68 +++++++ dev/kernel/NeKit/PageMgr.h | 76 ++++++++ dev/kernel/NeKit/Pair.h | 13 ++ dev/kernel/NeKit/Pmm.h | 39 ++++ dev/kernel/NeKit/Ref.h | 79 ++++++++ dev/kernel/NeKit/Stream.h | 45 +++++ dev/kernel/NeKit/Utils.h | 34 ++++ dev/kernel/NeKit/Variant.h | 61 +++++++ dev/kernel/NetworkKit/IP.h | 6 +- dev/kernel/NetworkKit/IPC.h | 4 +- dev/kernel/NetworkKit/LTE.h | 4 +- dev/kernel/NetworkKit/MAC.h | 6 +- dev/kernel/NewKit/Array.h | 46 ----- dev/kernel/NewKit/ArrayList.h | 44 ----- dev/kernel/NewKit/Atom.h | 33 ---- dev/kernel/NewKit/Crc32.h | 22 --- dev/kernel/NewKit/CxxAbi.h | 26 --- dev/kernel/NewKit/Defines.h | 176 ------------------ dev/kernel/NewKit/ErrorOr.h | 56 ------ dev/kernel/NewKit/Function.h | 40 ---- dev/kernel/NewKit/Json.h | 129 ------------- dev/kernel/NewKit/KString.h | 82 --------- dev/kernel/NewKit/KernelPanic.h | 69 ------- dev/kernel/NewKit/Macros.h | 148 --------------- dev/kernel/NewKit/MutableArray.h | 203 --------------------- dev/kernel/NewKit/New.h | 20 -- dev/kernel/NewKit/NewKit.h | 20 -- dev/kernel/NewKit/OwnPtr.h | 68 ------- dev/kernel/NewKit/PageMgr.h | 76 -------- dev/kernel/NewKit/Pair.h | 13 -- dev/kernel/NewKit/Pmm.h | 39 ---- dev/kernel/NewKit/Ref.h | 79 -------- dev/kernel/NewKit/Stream.h | 45 ----- dev/kernel/NewKit/Utils.h | 34 ---- dev/kernel/NewKit/Variant.h | 61 ------- dev/kernel/SignalKit/Signals.h | 2 +- dev/kernel/StorageKit/AHCI.h | 2 +- dev/kernel/StorageKit/ATA.h | 4 +- dev/kernel/StorageKit/PRDT.h | 2 +- dev/kernel/SwapKit/DiskSwap.h | 2 +- dev/kernel/src/ACPIFactoryInterface.cc | 2 +- dev/kernel/src/Array.cc | 2 +- dev/kernel/src/ArrayList.cc | 2 +- dev/kernel/src/Atom.cc | 2 +- dev/kernel/src/BitMapMgr.cc | 2 +- dev/kernel/src/CodeMgr.cc | 2 +- dev/kernel/src/Crc32.cc | 2 +- dev/kernel/src/CxxAbi-AMD64.cc | 2 +- dev/kernel/src/CxxAbi-ARM64.cc | 2 +- dev/kernel/src/Defines.cc | 2 +- dev/kernel/src/DriveMgr.cc | 2 +- dev/kernel/src/ErrorOr.cc | 2 +- dev/kernel/src/FS/Ext2+FileSystemParser.cc | 8 +- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 8 +- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 8 +- dev/kernel/src/FileMgr.cc | 2 +- dev/kernel/src/GUIDWizard.cc | 2 +- dev/kernel/src/IPEFDylibObject.cc | 2 +- dev/kernel/src/IndexableProperty.cc | 4 +- dev/kernel/src/Json.cc | 2 +- dev/kernel/src/KPC.cc | 2 +- dev/kernel/src/KString.cc | 4 +- dev/kernel/src/MemoryMgr.cc | 6 +- dev/kernel/src/MutableArray.cc | 2 +- dev/kernel/src/Network/IPAddr.cc | 2 +- dev/kernel/src/Network/NetworkDevice.cc | 2 +- dev/kernel/src/New+Delete.cc | 2 +- dev/kernel/src/OwnPtr.cc | 2 +- dev/kernel/src/PEFCodeMgr.cc | 8 +- dev/kernel/src/PRDT.cc | 2 +- dev/kernel/src/PageMgr.cc | 2 +- dev/kernel/src/Pmm.cc | 2 +- dev/kernel/src/Ref.cc | 2 +- dev/kernel/src/Stream.cc | 2 +- dev/kernel/src/ThreadLocalStorage.cc | 2 +- dev/kernel/src/User.cc | 2 +- dev/kernel/src/UserProcessScheduler.cc | 4 +- dev/kernel/src/UtfUtils.cc | 2 +- dev/kernel/src/Utils.cc | 2 +- dev/kernel/src/Variant.cc | 2 +- dev/modules/ACPI/ACPI.h | 2 +- dev/modules/ACPI/ACPIFactoryInterface.h | 6 +- dev/modules/AHCI/AHCI.h | 2 +- dev/modules/APM/APM.h | 2 +- dev/modules/ATA/ATA.h | 2 +- dev/modules/CoreGfx/CoreAccess.h | 2 +- dev/modules/CoreGfx/CoreGfx.h | 2 +- dev/modules/CoreGfx/TextGfx.h | 2 +- dev/modules/HPET/Defines.h | 2 +- dev/modules/LTE/LTE.h | 4 +- dev/modules/MBCI/MBCI.h | 2 +- dev/modules/NVME/NVME.h | 2 +- dev/modules/Power/PowerFactory.h | 6 +- dev/modules/SCSI/SCSI.h | 2 +- dev/modules/XHCI/XHCI.h | 2 +- .../KernelTest.fwrk/headers/KernelTest.h | 4 +- 185 files changed, 1776 insertions(+), 1757 deletions(-) create mode 100644 dev/kernel/NeKit/Array.h create mode 100644 dev/kernel/NeKit/ArrayList.h create mode 100644 dev/kernel/NeKit/Atom.h create mode 100644 dev/kernel/NeKit/Crc32.h create mode 100644 dev/kernel/NeKit/CxxAbi.h create mode 100644 dev/kernel/NeKit/Defines.h create mode 100644 dev/kernel/NeKit/ErrorOr.h create mode 100644 dev/kernel/NeKit/Function.h create mode 100644 dev/kernel/NeKit/Json.h create mode 100644 dev/kernel/NeKit/KString.h create mode 100644 dev/kernel/NeKit/KernelPanic.h create mode 100644 dev/kernel/NeKit/Macros.h create mode 100644 dev/kernel/NeKit/MutableArray.h create mode 100644 dev/kernel/NeKit/NeKit.h create mode 100644 dev/kernel/NeKit/New.h create mode 100644 dev/kernel/NeKit/OwnPtr.h create mode 100644 dev/kernel/NeKit/PageMgr.h create mode 100644 dev/kernel/NeKit/Pair.h create mode 100644 dev/kernel/NeKit/Pmm.h create mode 100644 dev/kernel/NeKit/Ref.h create mode 100644 dev/kernel/NeKit/Stream.h create mode 100644 dev/kernel/NeKit/Utils.h create mode 100644 dev/kernel/NeKit/Variant.h delete mode 100644 dev/kernel/NewKit/Array.h delete mode 100644 dev/kernel/NewKit/ArrayList.h delete mode 100644 dev/kernel/NewKit/Atom.h delete mode 100644 dev/kernel/NewKit/Crc32.h delete mode 100644 dev/kernel/NewKit/CxxAbi.h delete mode 100644 dev/kernel/NewKit/Defines.h delete mode 100644 dev/kernel/NewKit/ErrorOr.h delete mode 100644 dev/kernel/NewKit/Function.h delete mode 100644 dev/kernel/NewKit/Json.h delete mode 100644 dev/kernel/NewKit/KString.h delete mode 100644 dev/kernel/NewKit/KernelPanic.h delete mode 100644 dev/kernel/NewKit/Macros.h delete mode 100644 dev/kernel/NewKit/MutableArray.h delete mode 100644 dev/kernel/NewKit/New.h delete mode 100644 dev/kernel/NewKit/NewKit.h delete mode 100644 dev/kernel/NewKit/OwnPtr.h delete mode 100644 dev/kernel/NewKit/PageMgr.h delete mode 100644 dev/kernel/NewKit/Pair.h delete mode 100644 dev/kernel/NewKit/Pmm.h delete mode 100644 dev/kernel/NewKit/Ref.h delete mode 100644 dev/kernel/NewKit/Stream.h delete mode 100644 dev/kernel/NewKit/Utils.h delete mode 100644 dev/kernel/NewKit/Variant.h (limited to 'public/frameworks') diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 85de8d86..68e4b484 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -24,7 +24,7 @@ /// Include other APIs. /***********************************************************************************/ -#include +#include #include #include diff --git a/dev/boot/modules/SysChk/SysChk.cc b/dev/boot/modules/SysChk/SysChk.cc index 1601148e..ea3b1d6f 100644 --- a/dev/boot/modules/SysChk/SysChk.cc +++ b/dev/boot/modules/SysChk/SysChk.cc @@ -16,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 33dfd3ca..1d46b731 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 1e5b62f3..be2d8acd 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/dev/generic_kits/BenchKit/Chrono.h b/dev/generic_kits/BenchKit/Chrono.h index 98f3d980..b4010460 100644 --- a/dev/generic_kits/BenchKit/Chrono.h +++ b/dev/generic_kits/BenchKit/Chrono.h @@ -7,7 +7,7 @@ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. #ifndef BENCHKIT_CHRONO_H #define BENCHKIT_CHRONO_H -#include +#include namespace Kernel { class ChronoInterface; diff --git a/dev/kernel/ArchKit/ArchKit.h b/dev/kernel/ArchKit/ArchKit.h index d511658f..3254bae7 100644 --- a/dev/kernel/ArchKit/ArchKit.h +++ b/dev/kernel/ArchKit/ArchKit.h @@ -6,9 +6,9 @@ #pragma once -#include -#include -#include +#include +#include +#include #include diff --git a/dev/kernel/CFKit/GUIDWizard.h b/dev/kernel/CFKit/GUIDWizard.h index ae62b8fc..c7cb18ac 100644 --- a/dev/kernel/CFKit/GUIDWizard.h +++ b/dev/kernel/CFKit/GUIDWizard.h @@ -7,13 +7,13 @@ #pragma once #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace CF::XRN::Version1 { using namespace Kernel; diff --git a/dev/kernel/CFKit/GUIDWrapper.h b/dev/kernel/CFKit/GUIDWrapper.h index cc01bfad..a3920357 100644 --- a/dev/kernel/CFKit/GUIDWrapper.h +++ b/dev/kernel/CFKit/GUIDWrapper.h @@ -6,9 +6,9 @@ #pragma once -#include -#include -#include +#include +#include +#include /* GUID for C++ classes. */ diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h index 4dde15f9..9d35dc60 100644 --- a/dev/kernel/CFKit/Property.h +++ b/dev/kernel/CFKit/Property.h @@ -8,10 +8,10 @@ #define CFKIT_PROPS_H #include -#include -#include -#include -#include +#include +#include +#include +#include #define kMaxPropLen (256U) diff --git a/dev/kernel/CompilerKit/Detail.h b/dev/kernel/CompilerKit/Detail.h index 863ca145..a86f4dd3 100644 --- a/dev/kernel/CompilerKit/Detail.h +++ b/dev/kernel/CompilerKit/Detail.h @@ -7,7 +7,7 @@ #pragma once #ifdef __NEOSKRNL__ -#include +#include #endif // ifdef __NEOSKRNL__ #define NE_COPY_DELETE(KLASS) \ diff --git a/dev/kernel/FSKit/Defines.h b/dev/kernel/FSKit/Defines.h index c4c4e497..9e22a638 100644 --- a/dev/kernel/FSKit/Defines.h +++ b/dev/kernel/FSKit/Defines.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #define FSKIT_VERSION "1.0.0" #define FSKIT_VERSION_BCD 0x0100 diff --git a/dev/kernel/FSKit/Ext2.h b/dev/kernel/FSKit/Ext2.h index 17645139..35129dcd 100644 --- a/dev/kernel/FSKit/Ext2.h +++ b/dev/kernel/FSKit/Ext2.h @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include #include /// @file Ext2.h diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 5f0dcddf..17a174e3 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -9,9 +9,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include /// @file HeFS.h diff --git a/dev/kernel/FSKit/NeFS.h b/dev/kernel/FSKit/NeFS.h index 588cbe69..f265c4a6 100644 --- a/dev/kernel/FSKit/NeFS.h +++ b/dev/kernel/FSKit/NeFS.h @@ -18,8 +18,8 @@ default. #include #include -#include -#include +#include +#include #include /** diff --git a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h index 6639d9e3..b05f382e 100644 --- a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h +++ b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #define kBootNetINetMagic "NETB" #define kBootNetINetMagicLength (4) diff --git a/dev/kernel/FirmwareKit/CoreBoot/CoreBoot.h b/dev/kernel/FirmwareKit/CoreBoot/CoreBoot.h index 2b274f21..9e756a70 100644 --- a/dev/kernel/FirmwareKit/CoreBoot/CoreBoot.h +++ b/dev/kernel/FirmwareKit/CoreBoot/CoreBoot.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Firmware::Detail::CoreBoot { using namespace Kernel; diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index e2fa3843..3512191a 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -11,7 +11,7 @@ @brief Implementation of the main EFI protocols. */ -#include +#include using namespace Kernel; diff --git a/dev/kernel/FirmwareKit/EFI/NS.h b/dev/kernel/FirmwareKit/EFI/NS.h index f5a28e10..910b2c36 100644 --- a/dev/kernel/FirmwareKit/EFI/NS.h +++ b/dev/kernel/FirmwareKit/EFI/NS.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Firmware::Detail::EFI { using namespace Kernel; diff --git a/dev/kernel/FirmwareKit/EPM.h b/dev/kernel/FirmwareKit/EPM.h index 27d635f3..05291929 100644 --- a/dev/kernel/FirmwareKit/EPM.h +++ b/dev/kernel/FirmwareKit/EPM.h @@ -11,7 +11,7 @@ #ifndef FIRMWAREKIT_EPM_H #define FIRMWAREKIT_EPM_H -#include +#include #define kEPMNameLength (32) #define kEPMFilesystemLength (16) diff --git a/dev/kernel/FirmwareKit/GPT.h b/dev/kernel/FirmwareKit/GPT.h index 7e5a910b..370f2517 100644 --- a/dev/kernel/FirmwareKit/GPT.h +++ b/dev/kernel/FirmwareKit/GPT.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #define kSectorAlignGPT_PartTbl (420U) #define kSectorAlignGPT_PartEntry (72U) diff --git a/dev/kernel/FirmwareKit/Handover.h b/dev/kernel/FirmwareKit/Handover.h index cda27e52..7689f38c 100644 --- a/dev/kernel/FirmwareKit/Handover.h +++ b/dev/kernel/FirmwareKit/Handover.h @@ -18,7 +18,7 @@ #pragma once #include -#include +#include #define kHandoverMagic (0xBADCC) #define kHandoverVersion (0x0117) diff --git a/dev/kernel/GfxKit/FB.h b/dev/kernel/GfxKit/FB.h index 33895ce6..e30f1800 100644 --- a/dev/kernel/GfxKit/FB.h +++ b/dev/kernel/GfxKit/FB.h @@ -13,16 +13,21 @@ namespace Kernel { class FBDeviceInterface; struct FBDevicePacket; +typedef UInt32 FBCoord2x2; +typedef UInt32 FBDim2x2; +typedef UInt32 FBColorProfile; +typedef UInt32 FBFlags; + /// @brief Framebuffer device interface packet. /// @details This structure is used to send and receive data from the framebuffer device. /// @note The structure is packed to ensure that the data is aligned correctly for the device. struct PACKED FBDevicePacket final { - UInt32 fX; - UInt32 fY; - UInt32 fWidth; - UInt32 fHeight; - UInt32 fColor; - UInt32 fFlags; + FBCoord2x2 fX; + FBCoord2x2 fY; + FBDim2x2 fWidth; + FBDim2x2 fHeight; + FBColorProfile fColor; + FBFlags fFlags; }; /// @brief Framebuffer device interface. diff --git a/dev/kernel/HALKit/AMD64/CPUID.h b/dev/kernel/HALKit/AMD64/CPUID.h index 8250dfad..cc3bd25e 100644 --- a/dev/kernel/HALKit/AMD64/CPUID.h +++ b/dev/kernel/HALKit/AMD64/CPUID.h @@ -13,7 +13,7 @@ #pragma once -#include +#include EXTERN_C { #include diff --git a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc index f4dd1347..e2b89765 100644 --- a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc +++ b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include namespace Kernel { diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index ada2ee3f..17d4690f 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index 633adccb..9da31800 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip); diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index 5d14f214..b0463eb5 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc index 95d7a8ca..f9749946 100644 --- a/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc +++ b/dev/kernel/HALKit/AMD64/HalDescriptorLoader.cc @@ -27,7 +27,7 @@ Void IDTLoader::Load(Register64& idt) { #ifndef __NE_MODULAR_KERNEL_COMPONENTS__ rt_cli(); - volatile ::Kernel::UIntPtr** ptr_ivt = (volatile ::Kernel::UIntPtr**) idt.Base; + volatile UIntPtr** ptr_ivt = (volatile UIntPtr**) idt.Base; for (SizeT idt_indx = 0; idt_indx < kKernelIdtSize; ++idt_indx) { Detail::kInterruptVectorTable[idt_indx].Selector = kIDTSelector; @@ -47,7 +47,7 @@ Void IDTLoader::Load(Register64& idt) { hal_load_idt(idt); rt_sti(); -#endif // __NE_MODULAR_KERNEL_COMPONENTS__ +#endif // __NE_MODULAR_KERNEL_COMPONENTS__ return; } diff --git a/dev/kernel/HALKit/AMD64/HalKernelPanic.cc b/dev/kernel/HALKit/AMD64/HalKernelPanic.cc index 76b92574..374c7302 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelPanic.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelPanic.cc @@ -9,9 +9,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/dev/kernel/HALKit/AMD64/Hypervisor.h b/dev/kernel/HALKit/AMD64/Hypervisor.h index df88b02b..5702c8e2 100644 --- a/dev/kernel/HALKit/AMD64/Hypervisor.h +++ b/dev/kernel/HALKit/AMD64/Hypervisor.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Kernel { MAKE_STRING_ENUM(HYPERVISOR) diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index b73b8604..079acde4 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -14,7 +14,7 @@ ------------------------------------------------------- */ -#include +#include #ifndef kPageMax #define kPageMax (0x200) diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index 3bf0ad3e..5a70b465 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -17,9 +17,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 246c2e02..b530a730 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h index 06a8e2a8..3d472bf0 100644 --- a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h +++ b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include /************************************************** */ /* INITIALIZE THE GIC ON THE CURRENT CORE. */ diff --git a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc index 31f5a4f2..660110b2 100644 --- a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc +++ b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc index 7ec90c6e..3c518e2f 100644 --- a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include namespace Kernel { EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index c92b12cd..6f3f3d12 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc index c3d3175c..5feb6c75 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc @@ -9,9 +9,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/dev/kernel/HALKit/ARM64/Paging.h b/dev/kernel/HALKit/ARM64/Paging.h index 88eedcd8..5001871b 100644 --- a/dev/kernel/HALKit/ARM64/Paging.h +++ b/dev/kernel/HALKit/ARM64/Paging.h @@ -14,7 +14,7 @@ #ifdef __NE_ARM64__ -#include +#include #ifndef kPageMax #define kPageMax (0x200) diff --git a/dev/kernel/HALKit/ARM64/Processor.h b/dev/kernel/HALKit/ARM64/Processor.h index ba1ed11e..38669b2f 100644 --- a/dev/kernel/HALKit/ARM64/Processor.h +++ b/dev/kernel/HALKit/ARM64/Processor.h @@ -9,9 +9,9 @@ #ifdef __NE_ARM64__ #include -#include -#include -#include +#include +#include +#include #define kCPUBackendName "aarch64" diff --git a/dev/kernel/HALKit/POWER/AP.h b/dev/kernel/HALKit/POWER/AP.h index f938d6a1..92007da3 100644 --- a/dev/kernel/HALKit/POWER/AP.h +++ b/dev/kernel/HALKit/POWER/AP.h @@ -13,7 +13,7 @@ #pragma once -#include +#include namespace Kernel { struct HAL_HARDWARE_THREAD; diff --git a/dev/kernel/HALKit/POWER/Processor.h b/dev/kernel/HALKit/POWER/Processor.h index d50c4ff2..8b75bcc8 100644 --- a/dev/kernel/HALKit/POWER/Processor.h +++ b/dev/kernel/HALKit/POWER/Processor.h @@ -8,8 +8,8 @@ #pragma once -#include -#include +#include +#include #define rtl_nop_op() asm volatile("mr 0, 0") #define kHalPPCAlignment __attribute__((aligned(4))) diff --git a/dev/kernel/HALKit/RISCV/AP.h b/dev/kernel/HALKit/RISCV/AP.h index 0e94fd97..79b0d038 100644 --- a/dev/kernel/HALKit/RISCV/AP.h +++ b/dev/kernel/HALKit/RISCV/AP.h @@ -13,7 +13,7 @@ #pragma once -#include +#include namespace Kernel { typedef Int64 hal_ap_kind; diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index a1cd5b7c..45d4bd8d 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Kernel { class USER_PROCESS; diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index 6ac55424..5ba29d3a 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index cf9378a9..9598f590 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -8,9 +8,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define kDebugUnboundPort 0x0FEED diff --git a/dev/kernel/KernelKit/Defines.h b/dev/kernel/KernelKit/Defines.h index 2c170940..975520b6 100644 --- a/dev/kernel/KernelKit/Defines.h +++ b/dev/kernel/KernelKit/Defines.h @@ -6,11 +6,14 @@ #pragma once -#include +#include -#define KERNELKIT_VERSION "0.0.1" +#define KERNELKIT_VERSION "0.0.1-kernelkit" #define KERNELKIT_VERSION_BCD 0x0001 +namespace Kernel { class UserProcessScheduler; class IDylibObject; -class Process; +class USER_PROCESS; +class KERNEL_TASK; +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 210cef2a..8d749ec9 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -19,8 +19,8 @@ /* @file KernelKit/DeviceMgr.h */ /* @brief Device abstraction and I/O buffer. */ -#include -#include +#include +#include #define kDeviceMgrRootDirPath "/devices/" diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 7972ac74..684e2e5c 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -12,9 +12,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #define kDriveMaxCount (4U) #define kDriveSectorSz (512U) diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 32c30b70..86354d7f 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -30,9 +30,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include /// @brief Filesystem manager, abstraction over mounted filesystem. diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index 11347c7e..a10d3a9e 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -9,7 +9,7 @@ #include #include -#include +#include /// @note Last Rev Sun 28 Jul CET 2024 /// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM diff --git a/dev/kernel/KernelKit/IDylibObject.h b/dev/kernel/KernelKit/IDylibObject.h index 7a7cd913..da6c3a7a 100644 --- a/dev/kernel/KernelKit/IDylibObject.h +++ b/dev/kernel/KernelKit/IDylibObject.h @@ -10,7 +10,7 @@ #pragma once #include -#include +#include #define NE_DYLIB_OBJECT : public IDylibObject diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h index 42ed1830..f4461a69 100644 --- a/dev/kernel/KernelKit/IPEFDylibObject.h +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace Kernel { /** diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index 4c48b53a..944c8efc 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -6,7 +6,7 @@ #pragma once -#include +#include /// @file KPC.h /// @brief Kernel Procedure Code. diff --git a/dev/kernel/KernelKit/LoaderInterface.h b/dev/kernel/KernelKit/LoaderInterface.h index 2b38ddbf..1f9b1e56 100644 --- a/dev/kernel/KernelKit/LoaderInterface.h +++ b/dev/kernel/KernelKit/LoaderInterface.h @@ -7,8 +7,8 @@ #pragma once #include -#include -#include +#include +#include #include namespace Kernel { diff --git a/dev/kernel/KernelKit/LockDelegate.h b/dev/kernel/KernelKit/LockDelegate.h index 18ab0cf5..a8162897 100644 --- a/dev/kernel/KernelKit/LockDelegate.h +++ b/dev/kernel/KernelKit/LockDelegate.h @@ -6,8 +6,8 @@ #pragma once -#include -#include +#include +#include namespace Kernel { enum { diff --git a/dev/kernel/KernelKit/MSDOS.h b/dev/kernel/KernelKit/MSDOS.h index a0751a6f..b4ffeff2 100644 --- a/dev/kernel/KernelKit/MSDOS.h +++ b/dev/kernel/KernelKit/MSDOS.h @@ -15,7 +15,7 @@ #define __MSDOS_EXEC__ #include -#include +#include // Last Rev // Sat Feb 24 CET 2024 diff --git a/dev/kernel/KernelKit/MemoryMgr.h b/dev/kernel/KernelKit/MemoryMgr.h index bf389955..7ca7da90 100644 --- a/dev/kernel/KernelKit/MemoryMgr.h +++ b/dev/kernel/KernelKit/MemoryMgr.h @@ -12,7 +12,7 @@ /// @brief: Memory allocation support for the NeKernel. #include -#include +#include #include namespace Kernel { diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index cad27a7a..7e7d3f0c 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -8,9 +8,9 @@ #include #include -#include -#include -#include +#include +#include +#include namespace Kernel { enum class DmaKind { diff --git a/dev/kernel/KernelKit/PCI/Database.h b/dev/kernel/KernelKit/PCI/Database.h index 6da653dd..093338da 100644 --- a/dev/kernel/KernelKit/PCI/Database.h +++ b/dev/kernel/KernelKit/PCI/Database.h @@ -6,7 +6,7 @@ #pragma once #include -#include +#include namespace Kernel { namespace Types { diff --git a/dev/kernel/KernelKit/PCI/Device.h b/dev/kernel/KernelKit/PCI/Device.h index d9bb4e70..f41e0575 100644 --- a/dev/kernel/KernelKit/PCI/Device.h +++ b/dev/kernel/KernelKit/PCI/Device.h @@ -5,7 +5,7 @@ ------------------------------------------- */ #pragma once -#include +#include namespace Kernel::PCI { enum class PciConfigKind : UShort { diff --git a/dev/kernel/KernelKit/PCI/Express.h b/dev/kernel/KernelKit/PCI/Express.h index 4d94830c..c9d65da7 100644 --- a/dev/kernel/KernelKit/PCI/Express.h +++ b/dev/kernel/KernelKit/PCI/Express.h @@ -7,6 +7,6 @@ #pragma once #include -#include +#include #define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/dev/kernel/KernelKit/PCI/IO.h b/dev/kernel/KernelKit/PCI/IO.h index bd5751ec..a7abc163 100644 --- a/dev/kernel/KernelKit/PCI/IO.h +++ b/dev/kernel/KernelKit/PCI/IO.h @@ -7,9 +7,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include namespace Kernel { template diff --git a/dev/kernel/KernelKit/PCI/Iterator.h b/dev/kernel/KernelKit/PCI/Iterator.h index 10924bc8..d4c89404 100644 --- a/dev/kernel/KernelKit/PCI/Iterator.h +++ b/dev/kernel/KernelKit/PCI/Iterator.h @@ -9,9 +9,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define NE_BUS_COUNT (256) #define NE_DEVICE_COUNT (33) diff --git a/dev/kernel/KernelKit/PCI/PCI.h b/dev/kernel/KernelKit/PCI/PCI.h index 7b30d455..d8805a0c 100644 --- a/dev/kernel/KernelKit/PCI/PCI.h +++ b/dev/kernel/KernelKit/PCI/PCI.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #define kPCIConfigAddressPort (0xCF8) #define kPCIConfigDataPort (0xCFC) diff --git a/dev/kernel/KernelKit/PE.h b/dev/kernel/KernelKit/PE.h index b961e901..df5047a3 100644 --- a/dev/kernel/KernelKit/PE.h +++ b/dev/kernel/KernelKit/PE.h @@ -14,7 +14,7 @@ #ifndef __KERNELKIT_INC_PE_H__ #define __KERNELKIT_INC_PE_H__ -#include +#include #define kPeSignature (0x00004550) diff --git a/dev/kernel/KernelKit/PECodeMgr.h b/dev/kernel/KernelKit/PECodeMgr.h index 05a2674c..15c2b7ee 100644 --- a/dev/kernel/KernelKit/PECodeMgr.h +++ b/dev/kernel/KernelKit/PECodeMgr.h @@ -22,8 +22,8 @@ #include #include #include -#include -#include +#include +#include #ifndef INC_PROCESS_SCHEDULER_H #include diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index 9381e491..c28c8f8c 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -16,7 +16,7 @@ #include #include -#include +#include #define kPefMagic "Joy!" #define kPefMagicFat "yoJ!" diff --git a/dev/kernel/KernelKit/PEFCodeMgr.h b/dev/kernel/KernelKit/PEFCodeMgr.h index a637892f..18041f8f 100644 --- a/dev/kernel/KernelKit/PEFCodeMgr.h +++ b/dev/kernel/KernelKit/PEFCodeMgr.h @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #ifndef INC_PROCESS_SCHEDULER_H #include diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 9a66b9fe..a1b5ecad 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Kernel { typedef Int64 Semaphore; diff --git a/dev/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index bf34f39a..6c764221 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -7,8 +7,8 @@ #ifndef KERNELKIT_TLS_H #define KERNELKIT_TLS_H -#include -#include +#include +#include ///! @brief Thread Local Storage for neoskrnl. diff --git a/dev/kernel/KernelKit/User.h b/dev/kernel/KernelKit/User.h index 2a12e41e..b7e7ac1d 100644 --- a/dev/kernel/KernelKit/User.h +++ b/dev/kernel/KernelKit/User.h @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include ///! We got the Super, Standard (%s format) and Guest user, ///! all are used to make authorization operations on the OS. diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index a15e8e38..1815a558 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////// // Last revision date is: Fri Mar 28 2025 // diff --git a/dev/kernel/KernelKit/XCOFF.h b/dev/kernel/KernelKit/XCOFF.h index 7b15782b..9cfe8ded 100644 --- a/dev/kernel/KernelKit/XCOFF.h +++ b/dev/kernel/KernelKit/XCOFF.h @@ -14,7 +14,7 @@ #ifndef INC_XOCFF_H #define INC_XOCFF_H -#include +#include #define kXCOFF64Magic (0x01F7) #define kXCOFF64ForkNameLen (256U) diff --git a/dev/kernel/NeKit/Array.h b/dev/kernel/NeKit/Array.h new file mode 100644 index 00000000..12c062cb --- /dev/null +++ b/dev/kernel/NeKit/Array.h @@ -0,0 +1,46 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel { +template +class Array final { + public: + explicit Array() = default; + ~Array() = default; + + Array& operator=(const Array&) = default; + Array(const Array&) = default; + + T& operator[](SizeT at) { return fArray[at]; } + + Boolean Empty() { return this->Count() > 0; } + + SizeT Capacity() { return N; } + + SizeT Count() { + const static SizeT kArrCnt = N; + return kArrCnt; // avoid constexpr error. + } + + const T* CData() { return fArray; } + + operator bool() { return !Empty(); } + + private: + T fArray[N]; +}; + +template +auto make_list(ValueType val) { + return Array{val}; +} +} // namespace Kernel diff --git a/dev/kernel/NeKit/ArrayList.h b/dev/kernel/NeKit/ArrayList.h new file mode 100644 index 00000000..1f5226f4 --- /dev/null +++ b/dev/kernel/NeKit/ArrayList.h @@ -0,0 +1,44 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +template +class ArrayList final { + public: + explicit ArrayList(T* list, SizeT length) : fList(reinterpret_cast(list)) {} + + ~ArrayList() = default; + + ArrayList& operator=(const ArrayList&) = default; + ArrayList(const ArrayList&) = default; + + T* Data() { return fList; } + + const T* CData() { return fList; } + + T& operator[](SizeT index) const { + MUST_PASS(index < this->Count()); + return fList[index]; + } + + operator bool() { return fList; } + + SizeT Count() const { return fLen; } + + private: + T* fList{nullptr}; + SizeT fLen{0}; +}; + +template +ArrayList make_list(ValueType val) { + return ArrayList{val}; +} +} // namespace Kernel diff --git a/dev/kernel/NeKit/Atom.h b/dev/kernel/NeKit/Atom.h new file mode 100644 index 00000000..fce5e93d --- /dev/null +++ b/dev/kernel/NeKit/Atom.h @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ +#pragma once + +#include + +namespace Kernel { +template +class Atom final { + public: + explicit Atom() = default; + ~Atom() = default; + + public: + Atom& operator=(const Atom&) = delete; + Atom(const Atom&) = delete; + + public: + T operator[](Size bit) { return (fArrayOfAtoms & (1 << bit)); } + + void operator|(Size bit) { fArrayOfAtoms |= (1 << bit); } + + friend Boolean operator==(Atom& atomic, const T& idx) { return atomic[idx] == idx; } + + friend Boolean operator!=(Atom& atomic, const T& idx) { return atomic[idx] == idx; } + + private: + T fArrayOfAtoms; +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/Crc32.h b/dev/kernel/NeKit/Crc32.h new file mode 100644 index 00000000..8988f828 --- /dev/null +++ b/dev/kernel/NeKit/Crc32.h @@ -0,0 +1,22 @@ +/* + * ======================================================== + * + * NeKernel + * Date Added: 13/02/2023 + * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + * + * ======================================================== + */ + +#ifndef CRC32_H +#define CRC32_H + +#include + +#define kCrcCnt (256) + +namespace Kernel { +UInt32 ke_calculate_crc32(const Char* crc, Int32 len) noexcept; +} // namespace Kernel + +#endif // !CRC32_H diff --git a/dev/kernel/NeKit/CxxAbi.h b/dev/kernel/NeKit/CxxAbi.h new file mode 100644 index 00000000..164a257d --- /dev/null +++ b/dev/kernel/NeKit/CxxAbi.h @@ -0,0 +1,26 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ +#pragma once + +#include + +#ifndef __TOOLCHAINKIT__ + +#define kAtExitMacDestructors (128) + +struct atexit_func_entry_t { + void (*destructor_func)(); + void* obj_ptr; + void* dso_handle; +}; + +typedef unsigned uarch_t; + +namespace cxxabiv1 { +typedef void* __guard; +} + +#endif // __GNUC__ diff --git a/dev/kernel/NeKit/Defines.h b/dev/kernel/NeKit/Defines.h new file mode 100644 index 00000000..0f9a7c4a --- /dev/null +++ b/dev/kernel/NeKit/Defines.h @@ -0,0 +1,176 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +#define NEWKIT_VERSION_STR "0.0.1" +#define NEWKIT_VERSION_BCD 0x0001 + +#ifndef __cplusplus +#error Kernel compiles with a C++ compiler. +#endif + +#if __cplusplus <= 201703L +#define char8_t char +#endif + +#ifdef __has_feature +#if !__has_feature(cxx_nullptr) +#if !__has_nullptr +#error !!! You must at least have nullptr featured on your C++ compiler. !!! +#endif +#endif +#endif + +/// @brief The **Kernel** namespace. +namespace Kernel { +using voidPtr = void*; +using VoidPtr = void*; +using nullPtr = decltype(nullptr); +using NullPtr = decltype(nullptr); + +using Int = int; +using Int32 = int; +using UShort = unsigned short; +using UInt16 = unsigned short; +using Short = short; +using Int16 = short; +using UInt = unsigned int; +using UInt32 = unsigned int; +using Long = __INT64_TYPE__; +using Int64 = __INT64_TYPE__; +using ULong = __UINT64_TYPE__; +using UInt64 = __UINT64_TYPE__; +using Boolean = bool; +using Bool = bool; +using Char = char; +using UChar = unsigned char; +using UInt8 = unsigned char; + +using SSize = Int64; +using SSizeT = Int64; +using Size = __SIZE_TYPE__; +using SizeT = __SIZE_TYPE__; +using IntPtr = __INTPTR_TYPE__; +using UIntPtr = __UINTPTR_TYPE__; +using IntFast = __INT_FAST32_TYPE__; +using IntFast64 = __INT_FAST64_TYPE__; +using PtrDiff = __PTRDIFF_TYPE__; + +using SInt16 = Int16; +using SInt32 = Int32; +using SInt64 = Int64; + +typedef UIntPtr* Ptr64; +typedef UInt32* Ptr32; +typedef UInt8* Ptr8; + +using Utf8Char = char8_t; +using Utf16Char = char16_t; +using WideChar = wchar_t; +using Utf32Char = char32_t; + +using LongDouble = long double; +using Double = double; +using Float = float; + +typedef UInt32 PhysicalAddressKind; +typedef UIntPtr VirtualAddressKind; + +using Void = void; + +using Lba = UInt64; + +using Char16 = char16_t; + +enum class Endian : UInt8 { kEndianInvalid, kEndianBig, kEndianLittle, kEndianMixed, kEndianCount }; + +/// @brief Forward object. +/// @tparam Args the object type. +/// @param arg the object. +/// @return object's rvalue +template +inline Args&& forward(Args& arg) { + return static_cast(arg); +} + +/// @brief Move object. +/// @tparam Args the object type. +/// @param arg the object. +/// @return object's rvalue +template +inline Args&& move(Args&& arg) { + return static_cast(arg); +} + +/// @brief Encoding interface, used as a proxy to convert T to Char* +/// Used to cast A to B or B to A. +class ICodec { + public: + explicit ICodec() = default; + virtual ~ICodec() = default; + + ICodec& operator=(const ICodec&) = default; + ICodec(const ICodec&) = default; + + public: + /// @brief Convert type to bytes. + /// @tparam T the type. + /// @param type (a1) the data. + /// @return a1 as Char* + template + const Char* AsBytes(T type) noexcept { + NE_UNUSED(type); + return nullptr; + } + + /// @brief Construct from type to class. + /// @tparam T the type to convert. + /// @param type (a1) the data. + /// @return a1 as Char* + template + OutputClass* Construct(Char* type) noexcept { + FactoryClass class_fac; + return class_fac.template From(type); + } + + /// @brief Convert T class to Y class. + /// @tparam T the class type of type. + /// @tparam Y the result class. + /// @param type the class to cast. + /// @return the class as Y. + template + Y As(T type) noexcept { + if (type.template IsSerializable()) { + return reinterpret_cast(type); + } + + return type.template As(); + } +}; + +/// \brief Scheduler interface, represents a scheduler object. +/// @note This is used to schedule tasks, such as threads, drivers, user threads, etc. +class ISchedulable { + public: + explicit ISchedulable() = default; + virtual ~ISchedulable() = default; + + ISchedulable& operator=(const ISchedulable&) = default; + ISchedulable(const ISchedulable&) = default; + + /// @brief Is this object only accepting user tasks? + virtual Bool IsUser() { return NO; } + + /// @brief Is this object only accepting kernel tasks? + virtual Bool IsKernel() { return NO; } + + /// @brief Is this object offloading to another CPU? + virtual Bool HasMP() { return NO; } +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h new file mode 100644 index 00000000..d7751b7e --- /dev/null +++ b/dev/kernel/NeKit/ErrorOr.h @@ -0,0 +1,56 @@ +/* + * ======================================================== + * + * NeKernel + * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include +#include + +namespace Kernel { +using ErrorT = UInt; + +template +class ErrorOr final { + public: + ErrorOr() = default; + ~ErrorOr() = default; + + public: + explicit ErrorOr(Int32 err) : mId(err) {} + + explicit ErrorOr(nullPtr Null) {} + + explicit ErrorOr(T* Class) : mRef(Class) {} + + explicit ErrorOr(T Class) : mRef(Class) {} + + ErrorOr& operator=(const ErrorOr&) = default; + ErrorOr(const ErrorOr&) = default; + + ErrorOr& operator=(const Ref& refErr) { + mRef = refErr; + return *this; + } + + Ref& Leak() { return mRef; } + + Int32 Error() { return mId; } + + operator bool() { return mRef; } + + BOOL HasError() { return this->mId > 0; } + + private: + Ref mRef; + UInt32 mId{0}; +}; + +using ErrorOrAny = ErrorOr; + +} // namespace Kernel diff --git a/dev/kernel/NeKit/Function.h b/dev/kernel/NeKit/Function.h new file mode 100644 index 00000000..e5d56cee --- /dev/null +++ b/dev/kernel/NeKit/Function.h @@ -0,0 +1,51 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + + +#ifndef _INC_FUNCTION_H_ +#define _INC_FUNCTION_H_ + +#include +#include + +namespace Kernel { +template +class Function final { + public: + Function() = default; + + public: + explicit Function(T (*Fn)(Args... args)) : fFn(Fn) {} + + ~Function() = default; + + Function& operator=(const Function&) = default; + Function(const Function&) = default; + + template + T operator()(Args&&... args) { + return fFn(args...); + } + + template + T Call(Args&&... args) { + return fFn(args...); + } + + operator bool() { return fFn; } + + bool operator!() { return !fFn; } + + private: + T(*fFn) + (Args... args); +}; + +template +using FunctionOr = ErrorOr>; +} // namespace Kernel + +#endif // !_INC_FUNCTION_H__ diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h new file mode 100644 index 00000000..2b2c9c04 --- /dev/null +++ b/dev/kernel/NeKit/Json.h @@ -0,0 +1,129 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +// last-rev: 02/04/25 + +#include +#include +#include +#include +#include + +#define kJSONMaxLen (8196) +#define kJSONLen (256) +#define kJSONNullArr "[]" +#define kJSONNullObj "{}" + +namespace Kernel { +/// @brief JavaScript object class +class Json final { + public: + explicit Json() { + auto len = kJSONMaxLen; + KString key = KString(len); + key += kJSONNullObj; + + this->AsKey() = key; + this->AsValue() = key; + } + + explicit Json(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} + + ~Json() = default; + + NE_COPY_DEFAULT(Json) + + Bool& IsUndefined() { return fUndefined; } + + private: + Bool fUndefined; // is this instance undefined? + KString fKey; + KString fValue; + + public: + /// @brief returns the key of the json + /// @return the key as string view. + KString& AsKey() { return fKey; } + + /// @brief returns the value of the json. + /// @return the key as string view. + KString& AsValue() { return fValue; } + + static Json kNull; +}; + +/// @brief Json stream reader helper. +struct JsonStreamReader final { + STATIC Json In(const Char* full_array) { + auto start_val = '{'; + auto end_val = '}'; + Boolean probe_value = false; + + if (full_array[0] != start_val) { + if (full_array[0] != '[') return Json::kNull; + + start_val = '['; + end_val = ']'; + + probe_value = true; + } + + SizeT len = rt_string_len(full_array); + + SizeT key_len = 0; + SizeT value_len = 0; + + Json type(kJSONMaxLen, kJSONMaxLen); + + for (SizeT i = 1; i < len; ++i) { + if (full_array[i] == '\r' || full_array[i] == '\n') continue; + + if (probe_value) { + if (full_array[i] == end_val || full_array[i] == ',') { + probe_value = false; + + ++value_len; + } else { + if (full_array[i] == '\'') { + type.AsValue().Data()[value_len] = 0; + break; + } + + type.AsValue().Data()[value_len] = full_array[i]; + + ++value_len; + } + } else { + if (start_val == '[') continue; + + if (full_array[i] == ':') { + type.AsKey().Data()[key_len] = 0; + ++key_len; + + ++i; + + while (full_array[i] == ' ' || full_array[i] == '\t') ++i; + + probe_value = true; + } else { + type.AsKey().Data()[key_len] = full_array[i]; + + ++key_len; + } + } + } + + type.AsValue().Data()[value_len] = 0; + + return type; + } +}; + +using JsonStream = Stream; +} // namespace Kernel diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h new file mode 100644 index 00000000..16b09a78 --- /dev/null +++ b/dev/kernel/NeKit/KString.h @@ -0,0 +1,82 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include + +#define kMinimumStringSize (8196U) + +namespace Kernel { +/// @brief Kernel string class, not dynamic. +class KString final { + public: + explicit KString() { + fDataSz = kMinimumStringSize; + + fData = new Char[fDataSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fDataSz); + } + + explicit KString(SizeT Sz) : fDataSz(Sz) { + MUST_PASS(Sz > 1); + + fData = new Char[Sz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); + } + + ~KString() { + if (fData) { + delete[] fData; + fData = nullptr; + } + } + + NE_COPY_DEFAULT(KString) + + Char* Data(); + const Char* CData() const; + Size Length() const; + + bool operator==(const Char* rhs) const; + bool operator!=(const Char* rhs) const; + + bool operator==(const KString& rhs) const; + bool operator!=(const KString& rhs) const; + + KString& operator+=(const Char* rhs); + KString& operator+=(const KString& rhs); + + operator bool() { return fData; } + + bool operator!() { return fData; } + + private: + Char* fData{nullptr}; + Size fDataSz{0}; + Size fCur{0}; + + friend class KStringBuilder; +}; + +class KStringBuilder final { + public: + static ErrorOr Construct(const Char* data); + static const Char* FromBool(const Char* fmt, bool n); + static const Char* Format(const Char* fmt, const Char* from); + static bool Equals(const Char* lhs, const Char* rhs); + static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); + static bool Equals(const WideChar* lhs, const WideChar* rhs); +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/KernelPanic.h b/dev/kernel/NeKit/KernelPanic.h new file mode 100644 index 00000000..753b18de --- /dev/null +++ b/dev/kernel/NeKit/KernelPanic.h @@ -0,0 +1,69 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +void ke_runtime_check(bool expr, const Char* file, const Char* line); +} + +#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG) + +#ifdef TRY +#undef TRY +#endif + +#define TRY(X) \ + { \ + auto fn = X; \ + if ((fn()) == NO) { \ + MUST_PASS(NO); \ + } \ + } + +#ifdef __MUST_PASS +#undef __MUST_PASS +#endif + +#define __MUST_PASS(EXPR, FILE, LINE) Kernel::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE)) + +#ifdef __DEBUG__ +#define MUST_PASS(EXPR) __MUST_PASS((EXPR), __FILE__, __LINE__) +#define assert(EXPR) MUST_PASS(EXPR) +#else +#define MUST_PASS(EXPR) (Kernel::Void)(EXPR) +#define assert(EXPR) (Kernel::Void)(EXPR) +#endif + +enum RUNTIME_CHECK { + RUNTIME_CHECK_FAILED = 1111, + RUNTIME_CHECK_POINTER, + RUNTIME_CHECK_EXPRESSION, + RUNTIME_CHECK_FILE, + RUNTIME_CHECK_IPC, + RUNTIME_CHECK_TLS, + RUNTIME_CHECK_HANDSHAKE, + RUNTIME_CHECK_ACPI, + RUNTIME_CHECK_INVALID_PRIVILEGE, + RUNTIME_CHECK_PROCESS, + RUNTIME_CHECK_BAD_BEHAVIOR, + RUNTIME_CHECK_BOOTSTRAP, + RUNTIME_CHECK_UNEXCPECTED, + RUNTIME_CHECK_FILESYSTEM, + RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM, + RUNTIME_CHECK_PAGE, + RUNTIME_CHECK_INVALID, + RUNTIME_CHECK_COUNT, +}; + +typedef enum RUNTIME_CHECK RTL_RUNTIME_CHECK; + +namespace Kernel { +void ke_panic(const Int32& id, const Char* message = nullptr); +} // namespace Kernel diff --git a/dev/kernel/NeKit/Macros.h b/dev/kernel/NeKit/Macros.h new file mode 100644 index 00000000..5147863a --- /dev/null +++ b/dev/kernel/NeKit/Macros.h @@ -0,0 +1,148 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +/***********************************************************************************/ +/// @file NeKit/Macros.h +/// @brief Core Types and Macros. +/***********************************************************************************/ + +#ifndef KIB +#define KIB(X) (Kernel::UInt64)((X) / 1024) +#endif + +#ifndef kib_cast +#define kib_cast(X) (Kernel::UInt64)((X) *1024) +#endif + +#ifndef MIB +#define MIB(X) (Kernel::UInt64)((Kernel::UInt64) KIB(X) / 1024) +#endif + +#ifndef mib_cast +#define mib_cast(X) (Kernel::UInt64)((Kernel::UInt64) kib_cast(X) * 1024) +#endif + +#ifndef GIB +#define GIB(X) (Kernel::UInt64)((Kernel::UInt64) MIB(X) / 1024) +#endif + +#ifndef gib_cast +#define gib_cast(X) (Kernel::UInt64)((Kernel::UInt64) mib_cast(X) * 1024) +#endif + +#ifndef TIB +#define TIB(X) (Kernel::UInt64)((Kernel::UInt64) GIB(X) / 1024) +#endif + +#ifndef tib_cast +#define tib_cast(X) ((Kernel::UInt64) gib_cast(X) * 1024) +#endif + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) \ + (((sizeof(a) / sizeof(*(a))) / (static_cast(!(sizeof(a) % sizeof(*(a))))))) +#endif + +#define DEPRECATED ATTRIBUTE(deprecated) + +#ifndef ALIGN +#define ALIGN(X) __attribute__((aligned(X))) +#endif // #ifndef ALIGN + +#ifndef ATTRIBUTE +#define ATTRIBUTE(...) __attribute__((__VA_ARGS__)) +#endif // #ifndef ATTRIBUTE + +#ifndef __NE_VER__ +#define __NE_VER__ (2024) +#endif // !__NE_VER__ + +#ifndef EXTERN +#define EXTERN extern +#endif + +#ifndef EXTERN_C +#define EXTERN_C extern "C" +#endif + +#ifndef MAKE_ENUM +#define MAKE_ENUM(NAME) enum NAME { +#endif + +#ifndef END_ENUM +#define END_ENUM() \ + } \ + ; +#endif + +#ifndef MAKE_STRING_ENUM +#define MAKE_STRING_ENUM(NAME) namespace NAME { +#endif + +#ifndef ENUM_STRING +#define ENUM_STRING(NAME, VAL) inline constexpr const char* e##NAME = VAL +#endif + +#ifndef END_STRING_ENUM +#define END_STRING_ENUM() } +#endif + +#ifndef RTL_ALLOCA +#define RTL_ALLOCA(sz) __builtin_alloca(sz) +#endif // #ifndef RTL_ALLOCA + +#ifndef CANT_REACH +#define CANT_REACH() __builtin_unreachable() +#endif + +#define kInvalidAddress 0xFBFBFBFBFBFBFBFB +#define kBadAddress 0x0000000000000000 +#define kMaxAddr 0xFFFFFFFFFFFFFFFF +#define kPathLen 0x100 + +#define PACKED ATTRIBUTE(packed) +#define NO_EXEC ATTRIBUTE(noexec) + +#define EXTERN extern +#define STATIC static + +#define CONST const + +#define STRINGIFY(X) #X +#define NE_UNUSED(X) ((Kernel::Void) X) + +#ifndef RGB +#define RGB(R, G, B) ((Kernel::UInt32)((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B))) +#endif // !RGB + +#ifdef __NE_AMD64__ +#define dbg_break_point() asm volatile("int $3") +#else +#define dbg_break_point() ((Kernel::Void) 0) +#endif + +#define RTL_ENDIAN(address, value) \ + (((reinterpret_cast(address)[0]) == (value)) ? (Kernel::Endian::kEndianBig) \ + : (Kernel::Endian::kEndianLittle)) + +#define Yes true +#define No false + +#define YES true +#define NO false + +#define TRUE true +#define FALSE false + +#define BOOL Kernel::Boolean + +#ifdef RTL_INIT_OBJECT +#undef RTL_INIT_OBJECT +#endif // ifdef RTL_INIT_OBJECT + +#define RTL_INIT_OBJECT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__) diff --git a/dev/kernel/NeKit/MutableArray.h b/dev/kernel/NeKit/MutableArray.h new file mode 100644 index 00000000..8dee6e03 --- /dev/null +++ b/dev/kernel/NeKit/MutableArray.h @@ -0,0 +1,203 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ +#pragma once + +#include +#include +#include + +#define TRY_FIND_NODE(NAME, NODE) \ + auto* NAME = NODE; \ + while (NAME) { \ + if (NAME->fIndex == Index) return NAME->fVal; \ + NAME = NAME->fNext; \ + } + +#define TRY_FIND_NODE2(NAME, NODE) \ + auto* NAME = NODE; \ + while (NAME) { \ + if (NAME->fIndex == Index) return Ref{NAME->fVal}; \ + NAME = NAME->fNext; \ + } + +#define TRY_REMOVE_NODE(NODE) \ + if (NODE && NODE->fIndex == Index) { \ + NODE->fUsed = false; \ + NODE->fIndex = 0; \ + \ + return true; \ + } + +// FIXME: this is a shitty algorithm, which is consumer hungry. +// Remove and occurences of that, and remove that class. +namespace Kernel { +template +class MutableArray; + +template +class NullableMutableArray; + +template +class MutableLinkedList { + public: + T fVal; + SizeT fIndex{0}; + Boolean fUsed{false}; + + MutableLinkedList* fPrev{nullptr}; + MutableLinkedList* fNext{nullptr}; +}; + +template +class NullableMutableArray { + public: + // explicit this. + explicit NullableMutableArray() : fFirstNode(new MutableLinkedList()) {} + + /* + * We free all the nodes allocated by the array + * and store the next one inside "NextIt" + */ + + virtual ~NullableMutableArray() { + auto* It = fFirstNode; + MutableLinkedList* NextIt = nullptr; + + while (It) { + NextIt = It->fNext; + delete It; + + It = NextIt; + } + } + + NullableMutableArray& operator=(const NullableMutableArray&) = default; + NullableMutableArray(const NullableMutableArray&) = default; + + operator bool() { return Count() > 1; } + + public: + T operator[](SizeT Index) const { + TRY_FIND_NODE(first, fFirstNode); + TRY_FIND_NODE(last, fLastNode); + + return _PlaceHolderValue; + } + + SizeT Count() const { return fNodeCount; } + + public: + Boolean Remove(SizeT Index) { + TRY_REMOVE_NODE(fFirstNode); + TRY_REMOVE_NODE(fLastNode); + + return false; + } + + Boolean Add(const T val) { + auto* iterationNode = fFirstNode; + MUST_PASS(iterationNode); + + while (iterationNode) { + if (!iterationNode->fUsed) { + iterationNode->fVal = val; + iterationNode->fIndex = 0; + + iterationNode->fUsed = true; + + ++fNodeCount; + + return true; + } + + iterationNode = iterationNode->fNext; + } + + return false; + } + + private: + /* Avoid useless lookups */ + MutableLinkedList* fLastNode{nullptr}; + MutableLinkedList* fFirstNode{nullptr}; + + /* Number of nodes inside of this dynamic array. */ + Kernel::SizeT fNodeCount{0}; + + private: + // don't remove that + friend MutableArray; +}; + +template +class MutableArray : public NullableMutableArray { + public: + // explicit this. + explicit MutableArray() = default; + virtual ~MutableArray() = default; + + NE_COPY_DEFAULT(MutableArray) + + public: + Boolean Add(const T val) { + auto* iterationNode = fFirstNode; + + if (!iterationNode) { + fFirstNode = new MutableLinkedList(); + iterationNode = fFirstNode; + } + + MUST_PASS(iterationNode); + + while (iterationNode) { + if (!iterationNode->fUsed) { + iterationNode->fVal = val; + iterationNode->fIndex = 0; + + iterationNode->fUsed = true; + + ++fNodeCount; + + return true; + } + + iterationNode = iterationNode->fNext; + } + + return false; + } + + public: + Ref operator[](SizeT Index) const { + TRY_FIND_NODE2(first, fFirstNode); + TRY_FIND_NODE2(last, fLastNode); + + return {}; + } + + SizeT Count() const { return fNodeCount; } + + bool Contains(T& value) noexcept { + MutableLinkedList* first = fFirstNode; + + while (first) { + if (first->fVal == value && first->fUsed) return true; + + first = first->fNext; + } + + return false; + } + + private: + /* Avoid useless lookups */ + MutableLinkedList* fLastNode{nullptr}; + MutableLinkedList* fFirstNode{nullptr}; + + /* Number of nodes inside of this dynamic array. */ + Kernel::SizeT fNodeCount{0}; +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/NeKit.h b/dev/kernel/NeKit/NeKit.h new file mode 100644 index 00000000..909e1311 --- /dev/null +++ b/dev/kernel/NeKit/NeKit.h @@ -0,0 +1,20 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/dev/kernel/NeKit/New.h b/dev/kernel/NeKit/New.h new file mode 100644 index 00000000..de242141 --- /dev/null +++ b/dev/kernel/NeKit/New.h @@ -0,0 +1,20 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @note compatible with tk too. +typedef __SIZE_TYPE__ size_t; + +void* operator new(size_t ptr); +void* operator new[](size_t ptr); + +void operator delete(void* ptr); +void operator delete(void* ptr, unsigned long); +void operator delete[](void* ptr); diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h new file mode 100644 index 00000000..674f9ff3 --- /dev/null +++ b/dev/kernel/NeKit/OwnPtr.h @@ -0,0 +1,68 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace Kernel { +template +class OwnPtr; + +template +class NonNullRefPtr; + +template +class OwnPtr final { + public: + OwnPtr() {} + ~OwnPtr() { this->Delete(); } + + OwnPtr& operator=(const OwnPtr&) = default; + OwnPtr(const OwnPtr&) = default; + + public: + template + bool New(Args&&... arg) { + if (fCls) { + return false; + } + + fCls = new T(arg...); + return fCls; + } + + void Delete() { + if (fCls) delete fCls; + + fCls = nullptr; + } + + T* operator->() const { return fCls; } + + T* Raw() { return fCls; } + + Ref AsRef() { return Ref(fCls); } + + operator bool() { return fCls; } + bool operator!() { return !fCls; } + + private: + T* fCls; +}; + +template +inline OwnPtr mm_make_own_ptr(Args... args) { + OwnPtr ret; + ret.template New(forward(args)...); + MUST_PASS(ret); + + return ret; +} +} // namespace Kernel diff --git a/dev/kernel/NeKit/PageMgr.h b/dev/kernel/NeKit/PageMgr.h new file mode 100644 index 00000000..ae74a6b6 --- /dev/null +++ b/dev/kernel/NeKit/PageMgr.h @@ -0,0 +1,76 @@ +// a way to create and find our pages. +// I'm thinking about a separate way of getting a paged area. + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel { +class PageMgr; + +class PTEWrapper final { + public: + explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, + UIntPtr Address = 0); + + ~PTEWrapper(); + + PTEWrapper& operator=(const PTEWrapper&) = default; + PTEWrapper(const PTEWrapper&) = default; + + public: + UIntPtr VirtualAddress(); + + Void NoExecute(const bool enable = false); + Bool NoExecute(); + + operator bool() { return fVirtAddr; } + + bool Reclaim(); + bool Shareable(); + bool Present(); + bool Access(); + + private: + Boolean fRw; + Boolean fUser; + Boolean fExecDisable; + UIntPtr fVirtAddr; + Boolean fCache; + Boolean fShareable; + Boolean fWt; + Boolean fPresent; + Boolean fAccessed; + + private: + friend class PageMgr; + friend class Pmm; +}; + +struct PageMgr final { + public: + PageMgr() = default; + ~PageMgr() = default; + + PageMgr& operator=(const PageMgr&) = default; + PageMgr(const PageMgr&) = default; + + public: + PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz, SizeT Pad); + bool Free(Ref& wrapper); + + private: + void FlushTLB(); + + private: + friend PTEWrapper; + friend class Pmm; +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/Pair.h b/dev/kernel/NeKit/Pair.h new file mode 100644 index 00000000..aeeeb8a2 --- /dev/null +++ b/dev/kernel/NeKit/Pair.h @@ -0,0 +1,13 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +class Pair; +} // namespace Kernel diff --git a/dev/kernel/NeKit/Pmm.h b/dev/kernel/NeKit/Pmm.h new file mode 100644 index 00000000..f84bd9f2 --- /dev/null +++ b/dev/kernel/NeKit/Pmm.h @@ -0,0 +1,39 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel { +class Pmm; +class PTEWrapper; + +class Pmm final { + public: + explicit Pmm(); + ~Pmm(); + + Pmm& operator=(const Pmm&) = delete; + Pmm(const Pmm&) = default; + + Ref RequestPage(Boolean user = false, Boolean readWrite = false); + Boolean FreePage(Ref refPage); + + Boolean ToggleRw(Ref refPage, Boolean enable = true); + Boolean TogglePresent(Ref refPage, Boolean enable = true); + Boolean ToggleUser(Ref refPage, Boolean enable = true); + Boolean ToggleShare(Ref refPage, Boolean enable = true); + + /// @brief Get the page manager of this. + Ref& Leak() { return fPageMgr; } + + private: + Ref fPageMgr; +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h new file mode 100644 index 00000000..489c51de --- /dev/null +++ b/dev/kernel/NeKit/Ref.h @@ -0,0 +1,79 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef _NEWKIT_REF_H_ +#define _NEWKIT_REF_H_ + +#include +#include +#include + +namespace Kernel { +template +class Ref final { + public: + Ref() = default; + + ~Ref() { + if (mm_is_valid_ptr(fClass)) delete fClass; + } + + public: + Ref(T* cls) : fClass(cls) {} + + Ref(T cls) : fClass(nullptr) { fClass = new T(cls); } + + Ref& operator=(T ref) { + if (!fClass) return *this; + + fClass = &ref; + return *this; + } + + public: + T operator->() const { + MUST_PASS(*fClass); + return *fClass; + } + + T& Leak() noexcept { return *fClass; } + + T& TryLeak() const noexcept { + MUST_PASS(*fClass); + return *fClass; + } + + T operator*() { return *fClass; } + + operator bool() noexcept { return fClass; } + + private: + T* fClass{nullptr}; +}; + +template +class NonNullRef final { + public: + NonNullRef() = delete; + NonNullRef(nullPtr) = delete; + + NonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } + + Ref& operator->() { + MUST_PASS(fRef); + return fRef; + } + + NonNullRef& operator=(const NonNullRef& ref) = delete; + NonNullRef(const NonNullRef& ref) = default; + + private: + Ref fRef{nullptr}; +}; +} // namespace Kernel + +#endif // ifndef _NEWKIT_REF_H_ diff --git a/dev/kernel/NeKit/Stream.h b/dev/kernel/NeKit/Stream.h new file mode 100644 index 00000000..26fc46fc --- /dev/null +++ b/dev/kernel/NeKit/Stream.h @@ -0,0 +1,45 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel { +template +class Stream final { + public: + explicit Stream(Ref ref) : fStream(ref) {} + + ~Stream() = default; + + Stream& operator=(const Stream&) = default; + Stream(const Stream&) = default; + + template + friend Stream& operator>>(Stream& Ks, Ref& Buf) { + Ks.fKind = Ks.fStream->In(Buf); + return *Ks; + } + + template + friend Stream& operator<<(Stream& Ks, Ref& Buf) { + Ks.fKind = Buf; + Ks.fStream->Out(Buf.Leak()); + return *Ks; + } + + Ref& AsStreamTrait() { return fStream; } + + Ref& AsType() { return fKind; } + + private: + Ref fStream; + Ref fKind; +}; +} // namespace Kernel diff --git a/dev/kernel/NeKit/Utils.h b/dev/kernel/NeKit/Utils.h new file mode 100644 index 00000000..cdfcfe56 --- /dev/null +++ b/dev/kernel/NeKit/Utils.h @@ -0,0 +1,34 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace Kernel { +Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len); +Int rt_move_memory(const voidPtr src, voidPtr dst, Size len); +voidPtr rt_set_memory(voidPtr dst, UInt32 val, Size len); +void rt_zero_memory(voidPtr pointer, Size len); +Int rt_string_cmp(const Char* src, const Char* cmp, Size len); +const Char* rt_alloc_string(const Char* text); +Size rt_string_len(const Char* str); +Size rt_string_len(const Char* str, SizeT _len); +Boolean rt_to_string(Char* str_out, UInt64 base, Int32 limit); +Boolean rt_is_newln(Char chr); +Boolean rt_is_space(Char chr); +Int32 rt_is_alnum(Int32 character); +Int rt_to_uppercase(Int c); +Int rt_to_lower(Int c); +voidPtr rt_string_in_string(const Char* in, const Char* needle); +char* rt_string_has_char(Char* str, Char chr); + +Int urt_string_cmp(const Char* src, const Char* cmp, Size len); +Void urt_set_memory(const voidPtr src, UInt32 dst, Size len); +Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len); +Size urt_string_len(const Utf8Char* str); +} // namespace Kernel diff --git a/dev/kernel/NeKit/Variant.h b/dev/kernel/NeKit/Variant.h new file mode 100644 index 00000000..51548272 --- /dev/null +++ b/dev/kernel/NeKit/Variant.h @@ -0,0 +1,61 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +namespace Kernel { +class Variant final { + public: + enum class VariantKind { + kString, + kBlob, + kNull, + kJson, + kXML, + kSwap, + kInvalid, + }; + + public: + explicit Variant() = delete; + + public: + NE_COPY_DEFAULT(Variant) + + ~Variant() = default; + + public: + explicit Variant(KString* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} + + explicit Variant(Json* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + + explicit Variant(nullPtr ptr) : fPtr(ptr), fKind(VariantKind::kNull) {} + + explicit Variant(SWAP_DISK_HEADER* ptr) : fPtr(ptr), fKind(VariantKind::kSwap) {} + + explicit Variant(VoidPtr ptr) : fPtr(ptr), fKind(VariantKind::kBlob) {} + + public: + const Char* ToString(); + VoidPtr Leak(); + + template + T* As() { + return reinterpret_cast(fPtr); + } + + VariantKind& Kind(); + + private: + voidPtr fPtr{nullptr}; + VariantKind fKind{VariantKind::kNull}; +}; +} // namespace Kernel diff --git a/dev/kernel/NetworkKit/IP.h b/dev/kernel/NetworkKit/IP.h index bf3b24ff..0b872352 100644 --- a/dev/kernel/NetworkKit/IP.h +++ b/dev/kernel/NetworkKit/IP.h @@ -7,9 +7,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include namespace Kernel { class RawIPAddress6; diff --git a/dev/kernel/NetworkKit/IPC.h b/dev/kernel/NetworkKit/IPC.h index 43b58d35..0dd8a1f1 100644 --- a/dev/kernel/NetworkKit/IPC.h +++ b/dev/kernel/NetworkKit/IPC.h @@ -10,8 +10,8 @@ #ifndef INC_IPC_H #define INC_IPC_H -#include -#include +#include +#include #include /// @file IPC.h diff --git a/dev/kernel/NetworkKit/LTE.h b/dev/kernel/NetworkKit/LTE.h index 71254cbf..030f9955 100644 --- a/dev/kernel/NetworkKit/LTE.h +++ b/dev/kernel/NetworkKit/LTE.h @@ -10,7 +10,7 @@ #ifndef _INC_NETWORK_LTE_H_ #define _INC_NETWORK_LTE_H_ -#include -#include +#include +#include #endif // ifndef _INC_NETWORK_LTE_H_ diff --git a/dev/kernel/NetworkKit/MAC.h b/dev/kernel/NetworkKit/MAC.h index 8520037e..805f7259 100644 --- a/dev/kernel/NetworkKit/MAC.h +++ b/dev/kernel/NetworkKit/MAC.h @@ -6,9 +6,9 @@ #pragma once -#include -#include -#include +#include +#include +#include #define kMACAddrLen (32) diff --git a/dev/kernel/NewKit/Array.h b/dev/kernel/NewKit/Array.h deleted file mode 100644 index 2b6d31f3..00000000 --- a/dev/kernel/NewKit/Array.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel { -template -class Array final { - public: - explicit Array() = default; - ~Array() = default; - - Array& operator=(const Array&) = default; - Array(const Array&) = default; - - T& operator[](SizeT at) { return fArray[at]; } - - Boolean Empty() { return this->Count() > 0; } - - SizeT Capacity() { return N; } - - SizeT Count() { - const static SizeT kArrCnt = N; - return kArrCnt; // avoid constexpr error. - } - - const T* CData() { return fArray; } - - operator bool() { return !Empty(); } - - private: - T fArray[N]; -}; - -template -auto make_list(ValueType val) { - return Array{val}; -} -} // namespace Kernel diff --git a/dev/kernel/NewKit/ArrayList.h b/dev/kernel/NewKit/ArrayList.h deleted file mode 100644 index d07e534c..00000000 --- a/dev/kernel/NewKit/ArrayList.h +++ /dev/null @@ -1,44 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace Kernel { -template -class ArrayList final { - public: - explicit ArrayList(T* list, SizeT length) : fList(reinterpret_cast(list)) {} - - ~ArrayList() = default; - - ArrayList& operator=(const ArrayList&) = default; - ArrayList(const ArrayList&) = default; - - T* Data() { return fList; } - - const T* CData() { return fList; } - - T& operator[](SizeT index) const { - MUST_PASS(index < this->Count()); - return fList[index]; - } - - operator bool() { return fList; } - - SizeT Count() const { return fLen; } - - private: - T* fList{nullptr}; - SizeT fLen{0}; -}; - -template -ArrayList make_list(ValueType val) { - return ArrayList{val}; -} -} // namespace Kernel diff --git a/dev/kernel/NewKit/Atom.h b/dev/kernel/NewKit/Atom.h deleted file mode 100644 index 4b23c933..00000000 --- a/dev/kernel/NewKit/Atom.h +++ /dev/null @@ -1,33 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ -#pragma once - -#include - -namespace Kernel { -template -class Atom final { - public: - explicit Atom() = default; - ~Atom() = default; - - public: - Atom& operator=(const Atom&) = delete; - Atom(const Atom&) = delete; - - public: - T operator[](Size bit) { return (fArrayOfAtoms & (1 << bit)); } - - void operator|(Size bit) { fArrayOfAtoms |= (1 << bit); } - - friend Boolean operator==(Atom& atomic, const T& idx) { return atomic[idx] == idx; } - - friend Boolean operator!=(Atom& atomic, const T& idx) { return atomic[idx] == idx; } - - private: - T fArrayOfAtoms; -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/Crc32.h b/dev/kernel/NewKit/Crc32.h deleted file mode 100644 index b6f33714..00000000 --- a/dev/kernel/NewKit/Crc32.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * ======================================================== - * - * NeKernel - * Date Added: 13/02/2023 - * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - * - * ======================================================== - */ - -#ifndef CRC32_H -#define CRC32_H - -#include - -#define kCrcCnt (256) - -namespace Kernel { -UInt32 ke_calculate_crc32(const Char* crc, Int32 len) noexcept; -} // namespace Kernel - -#endif // !CRC32_H diff --git a/dev/kernel/NewKit/CxxAbi.h b/dev/kernel/NewKit/CxxAbi.h deleted file mode 100644 index 8fb93bf8..00000000 --- a/dev/kernel/NewKit/CxxAbi.h +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ -#pragma once - -#include - -#ifndef __TOOLCHAINKIT__ - -#define kAtExitMacDestructors (128) - -struct atexit_func_entry_t { - void (*destructor_func)(); - void* obj_ptr; - void* dso_handle; -}; - -typedef unsigned uarch_t; - -namespace cxxabiv1 { -typedef void* __guard; -} - -#endif // __GNUC__ diff --git a/dev/kernel/NewKit/Defines.h b/dev/kernel/NewKit/Defines.h deleted file mode 100644 index 0d2f830f..00000000 --- a/dev/kernel/NewKit/Defines.h +++ /dev/null @@ -1,176 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -#define NEWKIT_VERSION_STR "0.0.1" -#define NEWKIT_VERSION_BCD 0x0001 - -#ifndef __cplusplus -#error Kernel compiles with a C++ compiler. -#endif - -#if __cplusplus <= 201703L -#define char8_t char -#endif - -#ifdef __has_feature -#if !__has_feature(cxx_nullptr) -#if !__has_nullptr -#error !!! You must at least have nullptr featured on your C++ compiler. !!! -#endif -#endif -#endif - -/// @brief The **Kernel** namespace. -namespace Kernel { -using voidPtr = void*; -using VoidPtr = void*; -using nullPtr = decltype(nullptr); -using NullPtr = decltype(nullptr); - -using Int = int; -using Int32 = int; -using UShort = unsigned short; -using UInt16 = unsigned short; -using Short = short; -using Int16 = short; -using UInt = unsigned int; -using UInt32 = unsigned int; -using Long = __INT64_TYPE__; -using Int64 = __INT64_TYPE__; -using ULong = __UINT64_TYPE__; -using UInt64 = __UINT64_TYPE__; -using Boolean = bool; -using Bool = bool; -using Char = char; -using UChar = unsigned char; -using UInt8 = unsigned char; - -using SSize = Int64; -using SSizeT = Int64; -using Size = __SIZE_TYPE__; -using SizeT = __SIZE_TYPE__; -using IntPtr = __INTPTR_TYPE__; -using UIntPtr = __UINTPTR_TYPE__; -using IntFast = __INT_FAST32_TYPE__; -using IntFast64 = __INT_FAST64_TYPE__; -using PtrDiff = __PTRDIFF_TYPE__; - -using SInt16 = Int16; -using SInt32 = Int32; -using SInt64 = Int64; - -typedef UIntPtr* Ptr64; -typedef UInt32* Ptr32; -typedef UInt8* Ptr8; - -using Utf8Char = char8_t; -using Utf16Char = char16_t; -using WideChar = wchar_t; -using Utf32Char = char32_t; - -using LongDouble = long double; -using Double = double; -using Float = float; - -typedef UInt32 PhysicalAddressKind; -typedef UIntPtr VirtualAddressKind; - -using Void = void; - -using Lba = UInt64; - -using Char16 = char16_t; - -enum class Endian : UInt8 { kEndianInvalid, kEndianBig, kEndianLittle, kEndianMixed, kEndianCount }; - -/// @brief Forward object. -/// @tparam Args the object type. -/// @param arg the object. -/// @return object's rvalue -template -inline Args&& forward(Args& arg) { - return static_cast(arg); -} - -/// @brief Move object. -/// @tparam Args the object type. -/// @param arg the object. -/// @return object's rvalue -template -inline Args&& move(Args&& arg) { - return static_cast(arg); -} - -/// @brief Encoding interface, used as a proxy to convert T to Char* -/// Used to cast A to B or B to A. -class ICodec { - public: - explicit ICodec() = default; - virtual ~ICodec() = default; - - ICodec& operator=(const ICodec&) = default; - ICodec(const ICodec&) = default; - - public: - /// @brief Convert type to bytes. - /// @tparam T the type. - /// @param type (a1) the data. - /// @return a1 as Char* - template - const Char* AsBytes(T type) noexcept { - NE_UNUSED(type); - return nullptr; - } - - /// @brief Construct from type to class. - /// @tparam T the type to convert. - /// @param type (a1) the data. - /// @return a1 as Char* - template - OutputClass* Construct(Char* type) noexcept { - FactoryClass class_fac; - return class_fac.template From(type); - } - - /// @brief Convert T class to Y class. - /// @tparam T the class type of type. - /// @tparam Y the result class. - /// @param type the class to cast. - /// @return the class as Y. - template - Y As(T type) noexcept { - if (type.template IsSerializable()) { - return reinterpret_cast(type); - } - - return type.template As(); - } -}; - -/// \brief Scheduler interface, represents a scheduler object. -/// @note This is used to schedule tasks, such as threads, drivers, user threads, etc. -class ISchedulable { - public: - explicit ISchedulable() = default; - virtual ~ISchedulable() = default; - - ISchedulable& operator=(const ISchedulable&) = default; - ISchedulable(const ISchedulable&) = default; - - /// @brief Is this object only accepting user tasks? - virtual Bool IsUser() { return NO; } - - /// @brief Is this object only accepting kernel tasks? - virtual Bool IsKernel() { return NO; } - - /// @brief Is this object offloading to another CPU? - virtual Bool HasMP() { return NO; } -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/ErrorOr.h b/dev/kernel/NewKit/ErrorOr.h deleted file mode 100644 index f2de3432..00000000 --- a/dev/kernel/NewKit/ErrorOr.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ======================================================== - * - * NeKernel - * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include -#include - -namespace Kernel { -using ErrorT = UInt; - -template -class ErrorOr final { - public: - ErrorOr() = default; - ~ErrorOr() = default; - - public: - explicit ErrorOr(Int32 err) : mId(err) {} - - explicit ErrorOr(nullPtr Null) {} - - explicit ErrorOr(T* Class) : mRef(Class) {} - - explicit ErrorOr(T Class) : mRef(Class) {} - - ErrorOr& operator=(const ErrorOr&) = default; - ErrorOr(const ErrorOr&) = default; - - ErrorOr& operator=(const Ref& refErr) { - mRef = refErr; - return *this; - } - - Ref& Leak() { return mRef; } - - Int32 Error() { return mId; } - - operator bool() { return mRef; } - - BOOL HasError() { return this->mId > 0; } - - private: - Ref mRef; - UInt32 mId{0}; -}; - -using ErrorOrAny = ErrorOr; - -} // namespace Kernel diff --git a/dev/kernel/NewKit/Function.h b/dev/kernel/NewKit/Function.h deleted file mode 100644 index e0af5842..00000000 --- a/dev/kernel/NewKit/Function.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _INC_FUNCTION_H__ -#define _INC_FUNCTION_H__ - -#include - -namespace Kernel { -template -class Function final { - public: - Function() = default; - - public: - explicit Function(T (*Fn)(Args... args)) : fFn(Fn) {} - - ~Function() = default; - - Function& operator=(const Function&) = default; - Function(const Function&) = default; - - template - T operator()(Args... args) { - return fFn(args...); - } - - template - T Call(Args... args) { - return fFn(args...); - } - - operator bool() { return fFn; } - - bool operator!() { return !fFn; } - - private: - T(*fFn) - (Args... args); -}; -} // namespace Kernel - -#endif // !_INC_FUNCTION_H__ diff --git a/dev/kernel/NewKit/Json.h b/dev/kernel/NewKit/Json.h deleted file mode 100644 index 6af71b72..00000000 --- a/dev/kernel/NewKit/Json.h +++ /dev/null @@ -1,129 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -// last-rev: 02/04/25 - -#include -#include -#include -#include -#include - -#define kJSONMaxLen (8196) -#define kJSONLen (256) -#define kJSONNullArr "[]" -#define kJSONNullObj "{}" - -namespace Kernel { -/// @brief JavaScript object class -class Json final { - public: - explicit Json() { - auto len = kJSONMaxLen; - KString key = KString(len); - key += kJSONNullObj; - - this->AsKey() = key; - this->AsValue() = key; - } - - explicit Json(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} - - ~Json() = default; - - NE_COPY_DEFAULT(Json) - - Bool& IsUndefined() { return fUndefined; } - - private: - Bool fUndefined; // is this instance undefined? - KString fKey; - KString fValue; - - public: - /// @brief returns the key of the json - /// @return the key as string view. - KString& AsKey() { return fKey; } - - /// @brief returns the value of the json. - /// @return the key as string view. - KString& AsValue() { return fValue; } - - static Json kNull; -}; - -/// @brief Json stream reader helper. -struct JsonStreamReader final { - STATIC Json In(const Char* full_array) { - auto start_val = '{'; - auto end_val = '}'; - Boolean probe_value = false; - - if (full_array[0] != start_val) { - if (full_array[0] != '[') return Json::kNull; - - start_val = '['; - end_val = ']'; - - probe_value = true; - } - - SizeT len = rt_string_len(full_array); - - SizeT key_len = 0; - SizeT value_len = 0; - - Json type(kJSONMaxLen, kJSONMaxLen); - - for (SizeT i = 1; i < len; ++i) { - if (full_array[i] == '\r' || full_array[i] == '\n') continue; - - if (probe_value) { - if (full_array[i] == end_val || full_array[i] == ',') { - probe_value = false; - - ++value_len; - } else { - if (full_array[i] == '\'') { - type.AsValue().Data()[value_len] = 0; - break; - } - - type.AsValue().Data()[value_len] = full_array[i]; - - ++value_len; - } - } else { - if (start_val == '[') continue; - - if (full_array[i] == ':') { - type.AsKey().Data()[key_len] = 0; - ++key_len; - - ++i; - - while (full_array[i] == ' ' || full_array[i] == '\t') ++i; - - probe_value = true; - } else { - type.AsKey().Data()[key_len] = full_array[i]; - - ++key_len; - } - } - } - - type.AsValue().Data()[value_len] = 0; - - return type; - } -}; - -using JsonStream = Stream; -} // namespace Kernel diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h deleted file mode 100644 index 08f783c0..00000000 --- a/dev/kernel/NewKit/KString.h +++ /dev/null @@ -1,82 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include -#include - -#define kMinimumStringSize (8196U) - -namespace Kernel { -/// @brief Kernel string class, not dynamic. -class KString final { - public: - explicit KString() { - fDataSz = kMinimumStringSize; - - fData = new Char[fDataSz]; - MUST_PASS(fData); - - rt_set_memory(fData, 0, fDataSz); - } - - explicit KString(SizeT Sz) : fDataSz(Sz) { - MUST_PASS(Sz > 1); - - fData = new Char[Sz]; - MUST_PASS(fData); - - rt_set_memory(fData, 0, Sz); - } - - ~KString() { - if (fData) { - delete[] fData; - fData = nullptr; - } - } - - NE_COPY_DEFAULT(KString) - - Char* Data(); - const Char* CData() const; - Size Length() const; - - bool operator==(const Char* rhs) const; - bool operator!=(const Char* rhs) const; - - bool operator==(const KString& rhs) const; - bool operator!=(const KString& rhs) const; - - KString& operator+=(const Char* rhs); - KString& operator+=(const KString& rhs); - - operator bool() { return fData; } - - bool operator!() { return fData; } - - private: - Char* fData{nullptr}; - Size fDataSz{0}; - Size fCur{0}; - - friend class KStringBuilder; -}; - -class KStringBuilder final { - public: - static ErrorOr Construct(const Char* data); - static const Char* FromBool(const Char* fmt, bool n); - static const Char* Format(const Char* fmt, const Char* from); - static bool Equals(const Char* lhs, const Char* rhs); - static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); - static bool Equals(const WideChar* lhs, const WideChar* rhs); -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/KernelPanic.h b/dev/kernel/NewKit/KernelPanic.h deleted file mode 100644 index 6d7f4d23..00000000 --- a/dev/kernel/NewKit/KernelPanic.h +++ /dev/null @@ -1,69 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace Kernel { -void ke_runtime_check(bool expr, const Char* file, const Char* line); -} - -#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG) - -#ifdef TRY -#undef TRY -#endif - -#define TRY(X) \ - { \ - auto fn = X; \ - if ((fn()) == NO) { \ - MUST_PASS(NO); \ - } \ - } - -#ifdef __MUST_PASS -#undef __MUST_PASS -#endif - -#define __MUST_PASS(EXPR, FILE, LINE) Kernel::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE)) - -#ifdef __DEBUG__ -#define MUST_PASS(EXPR) __MUST_PASS((EXPR), __FILE__, __LINE__) -#define assert(EXPR) MUST_PASS(EXPR) -#else -#define MUST_PASS(EXPR) (Kernel::Void)(EXPR) -#define assert(EXPR) (Kernel::Void)(EXPR) -#endif - -enum RUNTIME_CHECK { - RUNTIME_CHECK_FAILED = 1111, - RUNTIME_CHECK_POINTER, - RUNTIME_CHECK_EXPRESSION, - RUNTIME_CHECK_FILE, - RUNTIME_CHECK_IPC, - RUNTIME_CHECK_TLS, - RUNTIME_CHECK_HANDSHAKE, - RUNTIME_CHECK_ACPI, - RUNTIME_CHECK_INVALID_PRIVILEGE, - RUNTIME_CHECK_PROCESS, - RUNTIME_CHECK_BAD_BEHAVIOR, - RUNTIME_CHECK_BOOTSTRAP, - RUNTIME_CHECK_UNEXCPECTED, - RUNTIME_CHECK_FILESYSTEM, - RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM, - RUNTIME_CHECK_PAGE, - RUNTIME_CHECK_INVALID, - RUNTIME_CHECK_COUNT, -}; - -typedef enum RUNTIME_CHECK RTL_RUNTIME_CHECK; - -namespace Kernel { -void ke_panic(const Int32& id, const Char* message = nullptr); -} // namespace Kernel diff --git a/dev/kernel/NewKit/Macros.h b/dev/kernel/NewKit/Macros.h deleted file mode 100644 index ef4742d3..00000000 --- a/dev/kernel/NewKit/Macros.h +++ /dev/null @@ -1,148 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -/***********************************************************************************/ -/// @file NewKit/Macros.h -/// @brief Core Types and Macros. -/***********************************************************************************/ - -#ifndef KIB -#define KIB(X) (Kernel::UInt64)((X) / 1024) -#endif - -#ifndef kib_cast -#define kib_cast(X) (Kernel::UInt64)((X) *1024) -#endif - -#ifndef MIB -#define MIB(X) (Kernel::UInt64)((Kernel::UInt64) KIB(X) / 1024) -#endif - -#ifndef mib_cast -#define mib_cast(X) (Kernel::UInt64)((Kernel::UInt64) kib_cast(X) * 1024) -#endif - -#ifndef GIB -#define GIB(X) (Kernel::UInt64)((Kernel::UInt64) MIB(X) / 1024) -#endif - -#ifndef gib_cast -#define gib_cast(X) (Kernel::UInt64)((Kernel::UInt64) mib_cast(X) * 1024) -#endif - -#ifndef TIB -#define TIB(X) (Kernel::UInt64)((Kernel::UInt64) GIB(X) / 1024) -#endif - -#ifndef tib_cast -#define tib_cast(X) ((Kernel::UInt64) gib_cast(X) * 1024) -#endif - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) \ - (((sizeof(a) / sizeof(*(a))) / (static_cast(!(sizeof(a) % sizeof(*(a))))))) -#endif - -#define DEPRECATED ATTRIBUTE(deprecated) - -#ifndef ALIGN -#define ALIGN(X) __attribute__((aligned(X))) -#endif // #ifndef ALIGN - -#ifndef ATTRIBUTE -#define ATTRIBUTE(...) __attribute__((__VA_ARGS__)) -#endif // #ifndef ATTRIBUTE - -#ifndef __NE_VER__ -#define __NE_VER__ (2024) -#endif // !__NE_VER__ - -#ifndef EXTERN -#define EXTERN extern -#endif - -#ifndef EXTERN_C -#define EXTERN_C extern "C" -#endif - -#ifndef MAKE_ENUM -#define MAKE_ENUM(NAME) enum NAME { -#endif - -#ifndef END_ENUM -#define END_ENUM() \ - } \ - ; -#endif - -#ifndef MAKE_STRING_ENUM -#define MAKE_STRING_ENUM(NAME) namespace NAME { -#endif - -#ifndef ENUM_STRING -#define ENUM_STRING(NAME, VAL) inline constexpr const char* e##NAME = VAL -#endif - -#ifndef END_STRING_ENUM -#define END_STRING_ENUM() } -#endif - -#ifndef RTL_ALLOCA -#define RTL_ALLOCA(sz) __builtin_alloca(sz) -#endif // #ifndef RTL_ALLOCA - -#ifndef CANT_REACH -#define CANT_REACH() __builtin_unreachable() -#endif - -#define kInvalidAddress 0xFBFBFBFBFBFBFBFB -#define kBadAddress 0x0000000000000000 -#define kMaxAddr 0xFFFFFFFFFFFFFFFF -#define kPathLen 0x100 - -#define PACKED ATTRIBUTE(packed) -#define NO_EXEC ATTRIBUTE(noexec) - -#define EXTERN extern -#define STATIC static - -#define CONST const - -#define STRINGIFY(X) #X -#define NE_UNUSED(X) ((Kernel::Void) X) - -#ifndef RGB -#define RGB(R, G, B) ((Kernel::UInt32)((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B))) -#endif // !RGB - -#ifdef __NE_AMD64__ -#define dbg_break_point() asm volatile("int $3") -#else -#define dbg_break_point() ((void) 0) -#endif - -#define RTL_ENDIAN(address, value) \ - (((reinterpret_cast(address)[0]) == (value)) ? (Kernel::Endian::kEndianBig) \ - : (Kernel::Endian::kEndianLittle)) - -#define Yes true -#define No false - -#define YES true -#define NO false - -#define TRUE true -#define FALSE false - -#define BOOL Kernel::Boolean - -#ifdef RTL_INIT_OBJECT -#undef RTL_INIT_OBJECT -#endif // ifdef RTL_INIT_OBJECT - -#define RTL_INIT_OBJECT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__) diff --git a/dev/kernel/NewKit/MutableArray.h b/dev/kernel/NewKit/MutableArray.h deleted file mode 100644 index 08c8cbf5..00000000 --- a/dev/kernel/NewKit/MutableArray.h +++ /dev/null @@ -1,203 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ -#pragma once - -#include -#include -#include - -#define TRY_FIND_NODE(NAME, NODE) \ - auto* NAME = NODE; \ - while (NAME) { \ - if (NAME->fIndex == Index) return NAME->fVal; \ - NAME = NAME->fNext; \ - } - -#define TRY_FIND_NODE2(NAME, NODE) \ - auto* NAME = NODE; \ - while (NAME) { \ - if (NAME->fIndex == Index) return Ref{NAME->fVal}; \ - NAME = NAME->fNext; \ - } - -#define TRY_REMOVE_NODE(NODE) \ - if (NODE && NODE->fIndex == Index) { \ - NODE->fUsed = false; \ - NODE->fIndex = 0; \ - \ - return true; \ - } - -// FIXME: this is a shitty algorithm, which is consumer hungry. -// Remove and occurences of that, and remove that class. -namespace Kernel { -template -class MutableArray; - -template -class NullableMutableArray; - -template -class MutableLinkedList { - public: - T fVal; - SizeT fIndex{0}; - Boolean fUsed{false}; - - MutableLinkedList* fPrev{nullptr}; - MutableLinkedList* fNext{nullptr}; -}; - -template -class NullableMutableArray { - public: - // explicit this. - explicit NullableMutableArray() : fFirstNode(new MutableLinkedList()) {} - - /* - * We free all the nodes allocated by the array - * and store the next one inside "NextIt" - */ - - virtual ~NullableMutableArray() { - auto* It = fFirstNode; - MutableLinkedList* NextIt = nullptr; - - while (It) { - NextIt = It->fNext; - delete It; - - It = NextIt; - } - } - - NullableMutableArray& operator=(const NullableMutableArray&) = default; - NullableMutableArray(const NullableMutableArray&) = default; - - operator bool() { return Count() > 1; } - - public: - T operator[](SizeT Index) const { - TRY_FIND_NODE(first, fFirstNode); - TRY_FIND_NODE(last, fLastNode); - - return _PlaceHolderValue; - } - - SizeT Count() const { return fNodeCount; } - - public: - Boolean Remove(SizeT Index) { - TRY_REMOVE_NODE(fFirstNode); - TRY_REMOVE_NODE(fLastNode); - - return false; - } - - Boolean Add(const T val) { - auto* iterationNode = fFirstNode; - MUST_PASS(iterationNode); - - while (iterationNode) { - if (!iterationNode->fUsed) { - iterationNode->fVal = val; - iterationNode->fIndex = 0; - - iterationNode->fUsed = true; - - ++fNodeCount; - - return true; - } - - iterationNode = iterationNode->fNext; - } - - return false; - } - - private: - /* Avoid useless lookups */ - MutableLinkedList* fLastNode{nullptr}; - MutableLinkedList* fFirstNode{nullptr}; - - /* Number of nodes inside of this dynamic array. */ - Kernel::SizeT fNodeCount{0}; - - private: - // don't remove that - friend MutableArray; -}; - -template -class MutableArray : public NullableMutableArray { - public: - // explicit this. - explicit MutableArray() = default; - virtual ~MutableArray() = default; - - NE_COPY_DEFAULT(MutableArray) - - public: - Boolean Add(const T val) { - auto* iterationNode = fFirstNode; - - if (!iterationNode) { - fFirstNode = new MutableLinkedList(); - iterationNode = fFirstNode; - } - - MUST_PASS(iterationNode); - - while (iterationNode) { - if (!iterationNode->fUsed) { - iterationNode->fVal = val; - iterationNode->fIndex = 0; - - iterationNode->fUsed = true; - - ++fNodeCount; - - return true; - } - - iterationNode = iterationNode->fNext; - } - - return false; - } - - public: - Ref operator[](SizeT Index) const { - TRY_FIND_NODE2(first, fFirstNode); - TRY_FIND_NODE2(last, fLastNode); - - return {}; - } - - SizeT Count() const { return fNodeCount; } - - bool Contains(T& value) noexcept { - MutableLinkedList* first = fFirstNode; - - while (first) { - if (first->fVal == value && first->fUsed) return true; - - first = first->fNext; - } - - return false; - } - - private: - /* Avoid useless lookups */ - MutableLinkedList* fLastNode{nullptr}; - MutableLinkedList* fFirstNode{nullptr}; - - /* Number of nodes inside of this dynamic array. */ - Kernel::SizeT fNodeCount{0}; -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/New.h b/dev/kernel/NewKit/New.h deleted file mode 100644 index de242141..00000000 --- a/dev/kernel/NewKit/New.h +++ /dev/null @@ -1,20 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @note compatible with tk too. -typedef __SIZE_TYPE__ size_t; - -void* operator new(size_t ptr); -void* operator new[](size_t ptr); - -void operator delete(void* ptr); -void operator delete(void* ptr, unsigned long); -void operator delete[](void* ptr); diff --git a/dev/kernel/NewKit/NewKit.h b/dev/kernel/NewKit/NewKit.h deleted file mode 100644 index 66ca2bb3..00000000 --- a/dev/kernel/NewKit/NewKit.h +++ /dev/null @@ -1,20 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/dev/kernel/NewKit/OwnPtr.h b/dev/kernel/NewKit/OwnPtr.h deleted file mode 100644 index 14b2fe39..00000000 --- a/dev/kernel/NewKit/OwnPtr.h +++ /dev/null @@ -1,68 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include - -namespace Kernel { -template -class OwnPtr; - -template -class NonNullRefPtr; - -template -class OwnPtr final { - public: - OwnPtr() {} - ~OwnPtr() { this->Delete(); } - - OwnPtr& operator=(const OwnPtr&) = default; - OwnPtr(const OwnPtr&) = default; - - public: - template - bool New(Args&&... arg) { - if (fCls) { - return false; - } - - fCls = new T(arg...); - return fCls; - } - - void Delete() { - if (fCls) delete fCls; - - fCls = nullptr; - } - - T* operator->() const { return fCls; } - - T* Raw() { return fCls; } - - Ref AsRef() { return Ref(fCls); } - - operator bool() { return fCls; } - bool operator!() { return !fCls; } - - private: - T* fCls; -}; - -template -inline OwnPtr mm_make_own_ptr(Args... args) { - OwnPtr ret; - ret.template New(forward(args)...); - MUST_PASS(ret); - - return ret; -} -} // namespace Kernel diff --git a/dev/kernel/NewKit/PageMgr.h b/dev/kernel/NewKit/PageMgr.h deleted file mode 100644 index 3aef2733..00000000 --- a/dev/kernel/NewKit/PageMgr.h +++ /dev/null @@ -1,76 +0,0 @@ -// a way to create and find our pages. -// I'm thinking about a separate way of getting a paged area. - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -namespace Kernel { -class PageMgr; - -class PTEWrapper final { - public: - explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, - UIntPtr Address = 0); - - ~PTEWrapper(); - - PTEWrapper& operator=(const PTEWrapper&) = default; - PTEWrapper(const PTEWrapper&) = default; - - public: - UIntPtr VirtualAddress(); - - Void NoExecute(const bool enable = false); - Bool NoExecute(); - - operator bool() { return fVirtAddr; } - - bool Reclaim(); - bool Shareable(); - bool Present(); - bool Access(); - - private: - Boolean fRw; - Boolean fUser; - Boolean fExecDisable; - UIntPtr fVirtAddr; - Boolean fCache; - Boolean fShareable; - Boolean fWt; - Boolean fPresent; - Boolean fAccessed; - - private: - friend class PageMgr; - friend class Pmm; -}; - -struct PageMgr final { - public: - PageMgr() = default; - ~PageMgr() = default; - - PageMgr& operator=(const PageMgr&) = default; - PageMgr(const PageMgr&) = default; - - public: - PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz, SizeT Pad); - bool Free(Ref& wrapper); - - private: - void FlushTLB(); - - private: - friend PTEWrapper; - friend class Pmm; -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/Pair.h b/dev/kernel/NewKit/Pair.h deleted file mode 100644 index 28512831..00000000 --- a/dev/kernel/NewKit/Pair.h +++ /dev/null @@ -1,13 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace Kernel { -class Pair; -} // namespace Kernel diff --git a/dev/kernel/NewKit/Pmm.h b/dev/kernel/NewKit/Pmm.h deleted file mode 100644 index 41d988e1..00000000 --- a/dev/kernel/NewKit/Pmm.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -namespace Kernel { -class Pmm; -class PTEWrapper; - -class Pmm final { - public: - explicit Pmm(); - ~Pmm(); - - Pmm& operator=(const Pmm&) = delete; - Pmm(const Pmm&) = default; - - Ref RequestPage(Boolean user = false, Boolean readWrite = false); - Boolean FreePage(Ref refPage); - - Boolean ToggleRw(Ref refPage, Boolean enable = true); - Boolean TogglePresent(Ref refPage, Boolean enable = true); - Boolean ToggleUser(Ref refPage, Boolean enable = true); - Boolean ToggleShare(Ref refPage, Boolean enable = true); - - /// @brief Get the page manager of this. - Ref& Leak() { return fPageMgr; } - - private: - Ref fPageMgr; -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/Ref.h b/dev/kernel/NewKit/Ref.h deleted file mode 100644 index 31ad16f8..00000000 --- a/dev/kernel/NewKit/Ref.h +++ /dev/null @@ -1,79 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifndef _NEWKIT_REF_H_ -#define _NEWKIT_REF_H_ - -#include -#include -#include - -namespace Kernel { -template -class Ref final { - public: - Ref() = default; - - ~Ref() { - if (mm_is_valid_ptr(fClass)) delete fClass; - } - - public: - Ref(T* cls) : fClass(cls) {} - - Ref(T cls) : fClass(nullptr) { fClass = new T(cls); } - - Ref& operator=(T ref) { - if (!fClass) return *this; - - fClass = &ref; - return *this; - } - - public: - T operator->() const { - MUST_PASS(*fClass); - return *fClass; - } - - T& Leak() noexcept { return *fClass; } - - T& TryLeak() const noexcept { - MUST_PASS(*fClass); - return *fClass; - } - - T operator*() { return *fClass; } - - operator bool() noexcept { return fClass; } - - private: - T* fClass{nullptr}; -}; - -template -class NonNullRef final { - public: - NonNullRef() = delete; - NonNullRef(nullPtr) = delete; - - NonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } - - Ref& operator->() { - MUST_PASS(fRef); - return fRef; - } - - NonNullRef& operator=(const NonNullRef& ref) = delete; - NonNullRef(const NonNullRef& ref) = default; - - private: - Ref fRef{nullptr}; -}; -} // namespace Kernel - -#endif // ifndef _NEWKIT_REF_H_ diff --git a/dev/kernel/NewKit/Stream.h b/dev/kernel/NewKit/Stream.h deleted file mode 100644 index 8b72046c..00000000 --- a/dev/kernel/NewKit/Stream.h +++ /dev/null @@ -1,45 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -namespace Kernel { -template -class Stream final { - public: - explicit Stream(Ref ref) : fStream(ref) {} - - ~Stream() = default; - - Stream& operator=(const Stream&) = default; - Stream(const Stream&) = default; - - template - friend Stream& operator>>(Stream& Ks, Ref& Buf) { - Ks.fKind = Ks.fStream->In(Buf); - return *Ks; - } - - template - friend Stream& operator<<(Stream& Ks, Ref& Buf) { - Ks.fKind = Buf; - Ks.fStream->Out(Buf.Leak()); - return *Ks; - } - - Ref& AsStreamTrait() { return fStream; } - - Ref& AsType() { return fKind; } - - private: - Ref fStream; - Ref fKind; -}; -} // namespace Kernel diff --git a/dev/kernel/NewKit/Utils.h b/dev/kernel/NewKit/Utils.h deleted file mode 100644 index cd36654a..00000000 --- a/dev/kernel/NewKit/Utils.h +++ /dev/null @@ -1,34 +0,0 @@ - -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -namespace Kernel { -Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len); -Int rt_move_memory(const voidPtr src, voidPtr dst, Size len); -voidPtr rt_set_memory(voidPtr dst, UInt32 val, Size len); -void rt_zero_memory(voidPtr pointer, Size len); -Int rt_string_cmp(const Char* src, const Char* cmp, Size len); -const Char* rt_alloc_string(const Char* text); -Size rt_string_len(const Char* str); -Size rt_string_len(const Char* str, SizeT _len); -Boolean rt_to_string(Char* str_out, UInt64 base, Int32 limit); -Boolean rt_is_newln(Char chr); -Boolean rt_is_space(Char chr); -Int32 rt_is_alnum(Int32 character); -Int rt_to_uppercase(Int c); -Int rt_to_lower(Int c); -voidPtr rt_string_in_string(const Char* in, const Char* needle); -char* rt_string_has_char(Char* str, Char chr); - -Int urt_string_cmp(const Char* src, const Char* cmp, Size len); -Void urt_set_memory(const voidPtr src, UInt32 dst, Size len); -Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len); -Size urt_string_len(const Utf8Char* str); -} // namespace Kernel diff --git a/dev/kernel/NewKit/Variant.h b/dev/kernel/NewKit/Variant.h deleted file mode 100644 index 83602602..00000000 --- a/dev/kernel/NewKit/Variant.h +++ /dev/null @@ -1,61 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include - -namespace Kernel { -class Variant final { - public: - enum class VariantKind { - kString, - kBlob, - kNull, - kJson, - kXML, - kSwap, - kInvalid, - }; - - public: - explicit Variant() = delete; - - public: - NE_COPY_DEFAULT(Variant) - - ~Variant() = default; - - public: - explicit Variant(KString* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} - - explicit Variant(Json* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} - - explicit Variant(nullPtr ptr) : fPtr(ptr), fKind(VariantKind::kNull) {} - - explicit Variant(SWAP_DISK_HEADER* ptr) : fPtr(ptr), fKind(VariantKind::kSwap) {} - - explicit Variant(VoidPtr ptr) : fPtr(ptr), fKind(VariantKind::kBlob) {} - - public: - const Char* ToString(); - VoidPtr Leak(); - - template - T* As() { - return reinterpret_cast(fPtr); - } - - VariantKind& Kind(); - - private: - voidPtr fPtr{nullptr}; - VariantKind fKind{VariantKind::kNull}; -}; -} // namespace Kernel diff --git a/dev/kernel/SignalKit/Signals.h b/dev/kernel/SignalKit/Signals.h index ba0b80cb..142ed3ab 100644 --- a/dev/kernel/SignalKit/Signals.h +++ b/dev/kernel/SignalKit/Signals.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #define SIGKILL 0 #define SIGPAUS 1 diff --git a/dev/kernel/StorageKit/AHCI.h b/dev/kernel/StorageKit/AHCI.h index d40feb36..e2220719 100644 --- a/dev/kernel/StorageKit/AHCI.h +++ b/dev/kernel/StorageKit/AHCI.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Kernel { /// @brief AHCIDeviceInterface class diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h index 5887c579..abf255a5 100644 --- a/dev/kernel/StorageKit/ATA.h +++ b/dev/kernel/StorageKit/ATA.h @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include namespace Kernel { /// @brief ATA device interface class. diff --git a/dev/kernel/StorageKit/PRDT.h b/dev/kernel/StorageKit/PRDT.h index f67cad05..f277897f 100644 --- a/dev/kernel/StorageKit/PRDT.h +++ b/dev/kernel/StorageKit/PRDT.h @@ -8,7 +8,7 @@ #include #include -#include +#include #define kPrdtTransferSize (sizeof(Kernel::UShort)) diff --git a/dev/kernel/SwapKit/DiskSwap.h b/dev/kernel/SwapKit/DiskSwap.h index 1832923f..40b3adb0 100644 --- a/dev/kernel/SwapKit/DiskSwap.h +++ b/dev/kernel/SwapKit/DiskSwap.h @@ -8,7 +8,7 @@ #pragma once #include -#include +#include #include #define kSwapBlockMaxSize (mib_cast(16)) diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index 47a81f38..def6f517 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include namespace Kernel { diff --git a/dev/kernel/src/Array.cc b/dev/kernel/src/Array.cc index 7cb1b156..36a8e744 100644 --- a/dev/kernel/src/Array.cc +++ b/dev/kernel/src/Array.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/ArrayList.cc b/dev/kernel/src/ArrayList.cc index 269dc47e..39291935 100644 --- a/dev/kernel/src/ArrayList.cc +++ b/dev/kernel/src/ArrayList.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/Atom.cc b/dev/kernel/src/Atom.cc index 8968a2c2..6e84d7d5 100644 --- a/dev/kernel/src/Atom.cc +++ b/dev/kernel/src/Atom.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include // @file Atom.cpp // @brief Atomic primitives diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc index dfd29770..994a2ba8 100644 --- a/dev/kernel/src/BitMapMgr.cc +++ b/dev/kernel/src/BitMapMgr.cc @@ -11,7 +11,7 @@ #endif #include -#include +#include #define kBitMapMagic (0x10210U) diff --git a/dev/kernel/src/CodeMgr.cc b/dev/kernel/src/CodeMgr.cc index c4ac011c..6146682a 100644 --- a/dev/kernel/src/CodeMgr.cc +++ b/dev/kernel/src/CodeMgr.cc @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Kernel { /***********************************************************************************/ diff --git a/dev/kernel/src/Crc32.cc b/dev/kernel/src/Crc32.cc index 332faa33..fddcb095 100644 --- a/dev/kernel/src/Crc32.cc +++ b/dev/kernel/src/Crc32.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include // @file CRC32.cpp // @brief Check sequence implementation. diff --git a/dev/kernel/src/CxxAbi-AMD64.cc b/dev/kernel/src/CxxAbi-AMD64.cc index c97b99f9..5b0f7c3c 100644 --- a/dev/kernel/src/CxxAbi-AMD64.cc +++ b/dev/kernel/src/CxxAbi-AMD64.cc @@ -9,7 +9,7 @@ #include #include #include -#include +#include atexit_func_entry_t __atexit_funcs[kAtExitMacDestructors]; diff --git a/dev/kernel/src/CxxAbi-ARM64.cc b/dev/kernel/src/CxxAbi-ARM64.cc index 1605692b..02f3dbcf 100644 --- a/dev/kernel/src/CxxAbi-ARM64.cc +++ b/dev/kernel/src/CxxAbi-ARM64.cc @@ -8,7 +8,7 @@ #include #include -#include +#include atexit_func_entry_t __atexit_funcs[kAtExitMacDestructors]; diff --git a/dev/kernel/src/Defines.cc b/dev/kernel/src/Defines.cc index 7f6e571d..a06b4dd2 100644 --- a/dev/kernel/src/Defines.cc +++ b/dev/kernel/src/Defines.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index 8bb1c930..b7c181c8 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/kernel/src/ErrorOr.cc b/dev/kernel/src/ErrorOr.cc index 69668b2f..a872164c 100644 --- a/dev/kernel/src/ErrorOr.cc +++ b/dev/kernel/src/ErrorOr.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include /***********************************************************************************/ /// @file ErrorOr.cc /// diff --git a/dev/kernel/src/FS/Ext2+FileSystemParser.cc b/dev/kernel/src/FS/Ext2+FileSystemParser.cc index b6d04f46..a3acac73 100644 --- a/dev/kernel/src/FS/Ext2+FileSystemParser.cc +++ b/dev/kernel/src/FS/Ext2+FileSystemParser.cc @@ -11,10 +11,10 @@ #include #include #include -#include -#include -#include -#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 c8de1507..0f6e7355 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -12,10 +12,10 @@ #include #include #include -#include -#include -#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 84317ad4..bd6a1aee 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -13,10 +13,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/dev/kernel/src/FileMgr.cc b/dev/kernel/src/FileMgr.cc index 06d19e5b..e000965f 100644 --- a/dev/kernel/src/FileMgr.cc +++ b/dev/kernel/src/FileMgr.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include /***********************************************************************************/ /// @file FileMgr.cc diff --git a/dev/kernel/src/GUIDWizard.cc b/dev/kernel/src/GUIDWizard.cc index 48ee1ec6..46915ace 100644 --- a/dev/kernel/src/GUIDWizard.cc +++ b/dev/kernel/src/GUIDWizard.cc @@ -10,7 +10,7 @@ ------------------------------------------- */ #include -#include +#include // begin of ascii 'readable' characters. (A, C, C, 1, 2) #define kUUIDAsciiBegin 47 diff --git a/dev/kernel/src/IPEFDylibObject.cc b/dev/kernel/src/IPEFDylibObject.cc index f9cd758c..6af0718e 100644 --- a/dev/kernel/src/IPEFDylibObject.cc +++ b/dev/kernel/src/IPEFDylibObject.cc @@ -12,7 +12,7 @@ #include #include #include -#include +#include /* ------------------------------------------- diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc index a89ea92d..1d2a1ce8 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include /// @brief File indexer API for fast path access. /// BUGS: 0 diff --git a/dev/kernel/src/Json.cc b/dev/kernel/src/Json.cc index 9264b2b8..68ab55fc 100644 --- a/dev/kernel/src/Json.cc +++ b/dev/kernel/src/Json.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include /// @brief Undefined object, is null in length. RTL_INIT_OBJECT(Kernel::Json::kNull, Kernel::Json); diff --git a/dev/kernel/src/KPC.cc b/dev/kernel/src/KPC.cc index 9a76c110..f44b356b 100644 --- a/dev/kernel/src/KPC.cc +++ b/dev/kernel/src/KPC.cc @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Kernel { STATIC Bool kRaiseOnBugCheck = false; diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc index 479eb2fc..9f332cdf 100644 --- a/dev/kernel/src/KString.cc +++ b/dev/kernel/src/KString.cc @@ -4,8 +4,8 @@ ------------------------------------------- */ -#include -#include +#include +#include /// @file KString.cc /// @brief Kernel String manipulation file. diff --git a/dev/kernel/src/MemoryMgr.cc b/dev/kernel/src/MemoryMgr.cc index efb9a35f..2faa24df 100644 --- a/dev/kernel/src/MemoryMgr.cc +++ b/dev/kernel/src/MemoryMgr.cc @@ -8,9 +8,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include /* ------------------------------------------- diff --git a/dev/kernel/src/MutableArray.cc b/dev/kernel/src/MutableArray.cc index 4b07f9ae..b7aaee1c 100644 --- a/dev/kernel/src/MutableArray.cc +++ b/dev/kernel/src/MutableArray.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/Network/IPAddr.cc b/dev/kernel/src/Network/IPAddr.cc index 4437df22..beb69470 100644 --- a/dev/kernel/src/Network/IPAddr.cc +++ b/dev/kernel/src/Network/IPAddr.cc @@ -4,8 +4,8 @@ ------------------------------------------- */ +#include #include -#include namespace Kernel { Char* RawIPAddress::Address() { diff --git a/dev/kernel/src/Network/NetworkDevice.cc b/dev/kernel/src/Network/NetworkDevice.cc index 6f77a244..51c43b48 100644 --- a/dev/kernel/src/Network/NetworkDevice.cc +++ b/dev/kernel/src/Network/NetworkDevice.cc @@ -4,8 +4,8 @@ ------------------------------------------- */ +#include #include -#include namespace Kernel { /// \brief Getter for fNetworkName. diff --git a/dev/kernel/src/New+Delete.cc b/dev/kernel/src/New+Delete.cc index a6bde691..0125b7f7 100644 --- a/dev/kernel/src/New+Delete.cc +++ b/dev/kernel/src/New+Delete.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include void* operator new[](size_t sz) { if (sz == 0) ++sz; diff --git a/dev/kernel/src/OwnPtr.cc b/dev/kernel/src/OwnPtr.cc index 8fd2b985..c716c2f4 100644 --- a/dev/kernel/src/OwnPtr.cc +++ b/dev/kernel/src/OwnPtr.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index 25a25122..afc28ceb 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -8,10 +8,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include /// @brief PEF stack size symbol. #define kPefStackSizeSymbol "__PEFSizeOfReserveStack" diff --git a/dev/kernel/src/PRDT.cc b/dev/kernel/src/PRDT.cc index f7380d2d..0c84fd29 100644 --- a/dev/kernel/src/PRDT.cc +++ b/dev/kernel/src/PRDT.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include namespace Kernel { diff --git a/dev/kernel/src/PageMgr.cc b/dev/kernel/src/PageMgr.cc index f60fa57a..e78f4908 100644 --- a/dev/kernel/src/PageMgr.cc +++ b/dev/kernel/src/PageMgr.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #ifdef __NE_AMD64__ #include diff --git a/dev/kernel/src/Pmm.cc b/dev/kernel/src/Pmm.cc index 35ea4195..b9fba20e 100644 --- a/dev/kernel/src/Pmm.cc +++ b/dev/kernel/src/Pmm.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #if defined(__NE_ARM64__) #include diff --git a/dev/kernel/src/Ref.cc b/dev/kernel/src/Ref.cc index c185952b..db584d9c 100644 --- a/dev/kernel/src/Ref.cc +++ b/dev/kernel/src/Ref.cc @@ -4,4 +4,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/Stream.cc b/dev/kernel/src/Stream.cc index 8fd4dab3..e05f6e6d 100644 --- a/dev/kernel/src/Stream.cc +++ b/dev/kernel/src/Stream.cc @@ -9,4 +9,4 @@ ------------------------------------------- */ -#include +#include diff --git a/dev/kernel/src/ThreadLocalStorage.cc b/dev/kernel/src/ThreadLocalStorage.cc index e248e67c..ec315ddf 100644 --- a/dev/kernel/src/ThreadLocalStorage.cc +++ b/dev/kernel/src/ThreadLocalStorage.cc @@ -10,7 +10,7 @@ #include #include #include -#include +#include /***********************************************************************************/ /// @bugs: 0 diff --git a/dev/kernel/src/User.cc b/dev/kernel/src/User.cc index c1a5ca94..e8f30547 100644 --- a/dev/kernel/src/User.cc +++ b/dev/kernel/src/User.cc @@ -14,7 +14,7 @@ #include #include #include -#include +#include #define kStdUserType (0xEE) #define kSuperUserType (0xEF) diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index a901e6d0..0a26938a 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -19,9 +19,9 @@ #include #include #include -#include +#include #include -#include "NewKit/Macros.h" +#include "NeKit/Macros.h" ///! BUGS: 0 diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc index 1374ee86..ae17aed7 100644 --- a/dev/kernel/src/UtfUtils.cc +++ b/dev/kernel/src/UtfUtils.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include namespace Kernel { Size urt_string_len(const Utf8Char* str) { diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index 4f47849b..d7cc08af 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include namespace Kernel { Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { diff --git a/dev/kernel/src/Variant.cc b/dev/kernel/src/Variant.cc index 5dd39926..51e5f5b8 100644 --- a/dev/kernel/src/Variant.cc +++ b/dev/kernel/src/Variant.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include namespace Kernel { const Char* Variant::ToString() { diff --git a/dev/modules/ACPI/ACPI.h b/dev/modules/ACPI/ACPI.h index 40b393d5..cfa78ecc 100644 --- a/dev/modules/ACPI/ACPI.h +++ b/dev/modules/ACPI/ACPI.h @@ -11,7 +11,7 @@ https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html */ -#include +#include #define SDT_OBJECT : public Kernel::SDT diff --git a/dev/modules/ACPI/ACPIFactoryInterface.h b/dev/modules/ACPI/ACPIFactoryInterface.h index 0a10ffc2..3ff53535 100644 --- a/dev/modules/ACPI/ACPIFactoryInterface.h +++ b/dev/modules/ACPI/ACPIFactoryInterface.h @@ -8,9 +8,9 @@ #define __MOD_ACPI_H__ #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/dev/modules/AHCI/AHCI.h b/dev/modules/AHCI/AHCI.h index c6d9ac07..dcdc5faa 100644 --- a/dev/modules/AHCI/AHCI.h +++ b/dev/modules/AHCI/AHCI.h @@ -13,7 +13,7 @@ #pragma once -#include +#include #include /// @file AHCI.h diff --git a/dev/modules/APM/APM.h b/dev/modules/APM/APM.h index 3dbd5e8f..b071a770 100644 --- a/dev/modules/APM/APM.h +++ b/dev/modules/APM/APM.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace Kernel { typedef Int32 APMPowerCmd; diff --git a/dev/modules/ATA/ATA.h b/dev/modules/ATA/ATA.h index e7cf200f..34091a36 100644 --- a/dev/modules/ATA/ATA.h +++ b/dev/modules/ATA/ATA.h @@ -14,7 +14,7 @@ #pragma once #include -#include +#include ///! Status register #define ATA_SR_BSY 0x80 diff --git a/dev/modules/CoreGfx/CoreAccess.h b/dev/modules/CoreGfx/CoreAccess.h index 6417db07..f092b5a6 100644 --- a/dev/modules/CoreGfx/CoreAccess.h +++ b/dev/modules/CoreGfx/CoreAccess.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/dev/modules/CoreGfx/CoreGfx.h b/dev/modules/CoreGfx/CoreGfx.h index 2ab8d6e8..7d23c17e 100644 --- a/dev/modules/CoreGfx/CoreGfx.h +++ b/dev/modules/CoreGfx/CoreGfx.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #define fb_init() Kernel::UInt32 kCGCursor = 0 diff --git a/dev/modules/CoreGfx/TextGfx.h b/dev/modules/CoreGfx/TextGfx.h index e19b4743..1bcc1397 100644 --- a/dev/modules/CoreGfx/TextGfx.h +++ b/dev/modules/CoreGfx/TextGfx.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #define kFontSizeX 8 diff --git a/dev/modules/HPET/Defines.h b/dev/modules/HPET/Defines.h index 49f17f99..5317c11f 100644 --- a/dev/modules/HPET/Defines.h +++ b/dev/modules/HPET/Defines.h @@ -11,7 +11,7 @@ #pragma once -#include +#include #include namespace Kernel { diff --git a/dev/modules/LTE/LTE.h b/dev/modules/LTE/LTE.h index 45dec6bc..5eb09f8e 100644 --- a/dev/modules/LTE/LTE.h +++ b/dev/modules/LTE/LTE.h @@ -10,8 +10,8 @@ Purpose: LTE Standard Library. #ifndef _INC_NETWORK_LTE_H_ #define _INC_NETWORK_LTE_H_ -#include -#include +#include +#include /// @brief Long Term Evolution I/O routines. diff --git a/dev/modules/MBCI/MBCI.h b/dev/modules/MBCI/MBCI.h index 99ecf802..aa1eb959 100644 --- a/dev/modules/MBCI/MBCI.h +++ b/dev/modules/MBCI/MBCI.h @@ -7,7 +7,7 @@ #ifndef _INC_MODULE_MBCI_H_ #define _INC_MODULE_MBCI_H_ -#include +#include #include #include diff --git a/dev/modules/NVME/NVME.h b/dev/modules/NVME/NVME.h index 6572187b..c0894194 100644 --- a/dev/modules/NVME/NVME.h +++ b/dev/modules/NVME/NVME.h @@ -12,7 +12,7 @@ #ifndef __MODULE_NVME_H__ #define __MODULE_NVME_H__ -#include +#include /// @file NVME.h /// @brief Non Volatile Memory. diff --git a/dev/modules/Power/PowerFactory.h b/dev/modules/Power/PowerFactory.h index 4f224709..b7c13280 100644 --- a/dev/modules/Power/PowerFactory.h +++ b/dev/modules/Power/PowerFactory.h @@ -7,9 +7,9 @@ #pragma once #include -#include -#include -#include +#include +#include +#include #include #define NE_POWER_FACTORY : public PowerFactory diff --git a/dev/modules/SCSI/SCSI.h b/dev/modules/SCSI/SCSI.h index e0137f3c..d9ede8b4 100644 --- a/dev/modules/SCSI/SCSI.h +++ b/dev/modules/SCSI/SCSI.h @@ -6,7 +6,7 @@ #pragma once -#include +#include /// @file SCSI.h /// @brief Small Computer System Interface device. diff --git a/dev/modules/XHCI/XHCI.h b/dev/modules/XHCI/XHCI.h index 0d2851d7..8829d29b 100644 --- a/dev/modules/XHCI/XHCI.h +++ b/dev/modules/XHCI/XHCI.h @@ -14,7 +14,7 @@ #pragma once -#include +#include using namespace Kernel; diff --git a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h index ccb1a903..04e90964 100644 --- a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h +++ b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h @@ -6,13 +6,13 @@ #pragma once -#include +#include /// @brief Kernel Test Framework. /// @file KernelTest.h #define KT_TEST_VERSION_BCD (0x0001) -#define KT_TEST_VERSION "0.0.1" +#define KT_TEST_VERSION "v0.0.1-kerneltest" #define KT_TEST_FAILURE (1) -- 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 'public/frameworks') 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