From 41703b62f9e7e83fa856fbf53101edc889502c45 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 22 Jun 2025 21:41:15 +0200 Subject: feat: use FNV in libSystem's syscall routing. fix: Add legacy string.h functions back, for GCC. Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Syscall.h | 22 +++++++-- dev/libSystem/src/SystemAPI.cc | 94 --------------------------------------- dev/libSystem/src/SystemCalls.cc | 94 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 98 deletions(-) delete mode 100644 dev/libSystem/src/SystemAPI.cc create mode 100644 dev/libSystem/src/SystemCalls.cc (limited to 'dev/libSystem') diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index 436665ae..5a840df1 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -9,11 +9,25 @@ #include #include -#ifndef SYSCALL_HASH -#define SYSCALL_HASH(str) (UInt64) str -#endif // !SYSCALL_HASH - IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); IMPORT_C VoidPtr libsys_syscall_arg_2(SizeT id, VoidPtr arg1); IMPORT_C VoidPtr libsys_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); IMPORT_C VoidPtr libsys_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); + +inline UInt64 libsys_hash_64(const Char* path) { + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; + const UInt64 FNV_PRIME = 0x100000001b3ULL; + + UInt64 hash = FNV_OFFSET_BASIS; + + while (*path) { + hash ^= (Char) (*path++); + hash *= FNV_PRIME; + } + + return hash; +} + +#ifndef SYSCALL_HASH +#define SYSCALL_HASH(str) libsys_hash_64(str) +#endif // !SYSCALL_HASH \ No newline at end of file diff --git a/dev/libSystem/src/SystemAPI.cc b/dev/libSystem/src/SystemAPI.cc deleted file mode 100644 index d0682830..00000000 --- a/dev/libSystem/src/SystemAPI.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/// @file SystemAPI.cc -/// @brief System wide API for NeKernel. - -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { - if (!len || !dest || !src) { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) { - ((Char*) dest)[i] = ((Char*) src)[i]; - } - - return dest; -} - -IMPORT_C SInt64 MmStrLen(const Char* in) { - if (!in) return 0; - - SizeT len{0}; - - do { - ++len; - } while (in[len] != '\0'); - - return len; -} - -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { - if (!len || !dest) { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) { - ((Char*) dest)[i] = value; - } - - return dest; -} - -IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), - reinterpret_cast(const_cast(path)), - reinterpret_cast(const_cast(drv_letter))); -} - -IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(2, desc); -} - -IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (volatile UInt64*) libsys_syscall_arg_3( - SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), reinterpret_cast(&off)); - - MUST_PASS((*ret) != ~0UL); - return *ret; -} - -IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), - reinterpret_cast(desc)); - return *ret; -} - -IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { - va_list args; - - va_start(args, fmt); - - auto ret = (volatile UInt64*) libsys_syscall_arg_4( - SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), - reinterpret_cast(const_cast(fmt)), args); - - va_end(args); - - return *ret; -} - -IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { - if (!expr) { - PrintOut(nullptr, "Assertion failed: %s\r", origin); - PrintOut(nullptr, "Origin: %s\r", origin); - - libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break')); - } -} diff --git a/dev/libSystem/src/SystemCalls.cc b/dev/libSystem/src/SystemCalls.cc new file mode 100644 index 00000000..6344cdac --- /dev/null +++ b/dev/libSystem/src/SystemCalls.cc @@ -0,0 +1,94 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/// @file SystemAPI.cc +/// @brief System wide API for NeKernel. + +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { + if (!len || !dest || !src) { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) { + ((Char*) dest)[i] = ((Char*) src)[i]; + } + + return dest; +} + +IMPORT_C SInt64 MmStrLen(const Char* in) { + if (!in) return 0; + + SizeT len{0}; + + do { + ++len; + } while (in[len] != '\0'); + + return len; +} + +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { + if (!len || !dest) { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) { + ((Char*) dest)[i] = value; + } + + return dest; +} + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { + return (Ref) libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), + reinterpret_cast(const_cast(path)), + reinterpret_cast(const_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(2, desc); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { + auto ret = (volatile UInt64*) libsys_syscall_arg_3( + SYSCALL_HASH("IoSeekFile"), reinterpret_cast(desc), reinterpret_cast(&off)); + + MUST_PASS((*ret) != ~0UL); + return *ret; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) { + auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), + reinterpret_cast(desc)); + return *ret; +} + +IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + + auto ret = (volatile UInt64*) libsys_syscall_arg_4( + SYSCALL_HASH("PrintOut"), reinterpret_cast(desc), + reinterpret_cast(const_cast(fmt)), args); + + va_end(args); + + return *ret; +} + +IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { + if (!expr) { + PrintOut(nullptr, "Assertion failed: %s\r", origin); + PrintOut(nullptr, "Origin: %s\r", origin); + + libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); + } +} -- cgit v1.2.3 From 34ff4ddd4ddeb4a8262dc86cdddc3677e5bfbc72 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 10 Jul 2025 02:11:33 +0200 Subject: feat: Fix FNV's pointer check. why: - It doesn't have any pointer check. - We could save cycles by also checking for `*path == 0` Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 2 ++ dev/libSystem/SystemKit/Syscall.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'dev/libSystem') diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 8092f53b..344369d5 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -89,6 +89,8 @@ namespace Detail { /// @param path the directory path. /// @return The hashed path. STATIC UInt64 hefsi_hash_64(const Utf8Char* path) { + if (!path || *path == 0) return 0; + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; const UInt64 FNV_PRIME = 0x100000001b3ULL; diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index 5a840df1..a1505b46 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -15,6 +15,8 @@ IMPORT_C VoidPtr libsys_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); IMPORT_C VoidPtr libsys_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); inline UInt64 libsys_hash_64(const Char* path) { + if (!path || *path == 0) return 0; + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; const UInt64 FNV_PRIME = 0x100000001b3ULL; -- cgit v1.2.3 From d546e35937521c868150a0807f30a2e2b1f69bb8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 29 Jul 2025 15:17:36 +0100 Subject: feat: libSystem: implement 'Jail.h' header. Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Jail.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'dev/libSystem') diff --git a/dev/libSystem/SystemKit/Jail.h b/dev/libSystem/SystemKit/Jail.h index 998173f9..4098089d 100644 --- a/dev/libSystem/SystemKit/Jail.h +++ b/dev/libSystem/SystemKit/Jail.h @@ -9,7 +9,7 @@ #include /// @file Jail.h -/// @brief NeKernel Jail System +/// @brief NeKernel Jail System, part of OpenEnclave. struct JAIL_INFO; struct JAIL; @@ -19,4 +19,17 @@ struct JAIL_INFO { SInt32 fParentID; SInt32 fJailHash; SInt64 fACL; -}; \ No newline at end of file +}; + +/// @brief Jail information (we grab a JAIL from JailGetCurrent()) +struct JAIL { + struct JAIL_INFO* fServer; + struct JAIL_INFO* fClient; + SInt32 fJailHash; + SInt32 fParentID; + SInt64 fACL; +}; + +/// @brief Get the current jail +/// @return Pointer to the current jail structure, or NULL if not in a jail +IMPORT_C struct JAIL* JailGetCurrent(Void); -- cgit v1.2.3 From f05aa7d8e5a9668b27e43c8bd2718482caa0b59e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 31 Jul 2025 15:10:21 +0100 Subject: feat: mgmt.oe: openenclave management tool. (wip) Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Jail.h | 1 + public/tools/mgmt.oe/.keep | 0 public/tools/mgmt.oe/mgmt.oe.json | 19 +++++++++++++++++++ public/tools/mgmt.oe/src/.keep | 0 public/tools/mgmt.oe/src/CommandLine.cc | 29 +++++++++++++++++++++++++++++ public/tools/mgmt.oe/vendor/.keep | 0 6 files changed, 49 insertions(+) create mode 100644 public/tools/mgmt.oe/.keep create mode 100644 public/tools/mgmt.oe/mgmt.oe.json create mode 100644 public/tools/mgmt.oe/src/.keep create mode 100644 public/tools/mgmt.oe/src/CommandLine.cc create mode 100644 public/tools/mgmt.oe/vendor/.keep (limited to 'dev/libSystem') diff --git a/dev/libSystem/SystemKit/Jail.h b/dev/libSystem/SystemKit/Jail.h index 4098089d..c23942c5 100644 --- a/dev/libSystem/SystemKit/Jail.h +++ b/dev/libSystem/SystemKit/Jail.h @@ -9,6 +9,7 @@ #include /// @file Jail.h +/// @author Amlal El Mahrouss /// @brief NeKernel Jail System, part of OpenEnclave. struct JAIL_INFO; diff --git a/public/tools/mgmt.oe/.keep b/public/tools/mgmt.oe/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.oe/mgmt.oe.json b/public/tools/mgmt.oe/mgmt.oe.json new file mode 100644 index 00000000..b4e9d586 --- /dev/null +++ b/public/tools/mgmt.oe/mgmt.oe.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "./", + "../../../dev/kernel", + "../../../public/frameworks/", + "../../../dev/", + "./" + ], + "sources_path": [], + "output_name": "./dist/mgmt.oe", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] +} \ No newline at end of file diff --git a/public/tools/mgmt.oe/src/.keep b/public/tools/mgmt.oe/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.oe/src/CommandLine.cc b/public/tools/mgmt.oe/src/CommandLine.cc new file mode 100644 index 00000000..3e8de78b --- /dev/null +++ b/public/tools/mgmt.oe/src/CommandLine.cc @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/// @author Amlal El Mahrouss +/// @brief OpenEnclave management tool + +static JAIL* kJailSrv = nullptr; + +SInt32 _NeMain(SInt32 argc, Char* argv[]) { + LIBSYS_UNUSED(argc); + LIBSYS_UNUSED(argv); + + kJailSrv = JailGetCurrent(); + + MUST_PASS(kJailSrv); + + PrintOut(nullptr, "%s", "mgmt.oe - OpenEnclave Management Tool."); + + /// @note JailGetCurrent returns client as nullptr if we're not that client (we'll not be able to access the jail then) + if (kJailSrv->fClient == nullptr) return EXIT_FAILURE; + + return EXIT_FAILURE; +} \ No newline at end of file diff --git a/public/tools/mgmt.oe/vendor/.keep b/public/tools/mgmt.oe/vendor/.keep new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From 7ada9006860084ba5d72b517649d1b2d51e4484a Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 9 Aug 2025 20:01:15 +0200 Subject: feat: warning fixes and Semaphore API patches. what: - The Semaphore API is being preppared for v0.0.4 Signed-off-by: Amlal --- dev/boot/BootKit/BootKit.h | 16 +-- dev/boot/modules/BootNet/BootNet.cc | 4 +- dev/boot/src/HEL/AMD64/BootATA.cc | 13 +- dev/boot/src/HEL/ARM64/BootPlatform.cc | 3 +- dev/boot/src/New+Delete.cc | 3 +- dev/kernel/FSKit/HeFS.h | 6 +- dev/kernel/FirmwareKit/EFI/EFI.h | 134 +++++++++++++-------- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 2 +- dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc | 3 +- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 5 +- dev/kernel/HALKit/AMD64/Paging.h | 4 +- dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 10 +- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 13 +- dev/kernel/HALKit/ARM64/CxxAbi.cc | 1 - dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc | 3 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 3 +- dev/kernel/HALKit/ARM64/Paging.h | 4 +- dev/kernel/HALKit/POWER/HalApplicationProcessor.cc | 3 +- dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc | 3 +- dev/kernel/KernelKit/CoreProcessScheduler.h | 2 +- dev/kernel/KernelKit/FileMgr.h | 1 - dev/kernel/KernelKit/HardwareThreadScheduler.h | 2 +- dev/kernel/KernelKit/KernelTaskScheduler.h | 5 +- dev/kernel/KernelKit/LoaderInterface.h | 6 +- dev/kernel/KernelKit/PCI/DMA.h | 2 +- dev/kernel/KernelKit/Semaphore.h | 5 +- dev/kernel/NeKit/Macros.h | 2 +- dev/kernel/NeKit/OwnPtr.h | 2 +- dev/kernel/NeKit/Ref.h | 2 +- dev/kernel/src/AsciiUtils.cc | 3 +- dev/kernel/src/BinaryMutex.cc | 2 +- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 6 +- dev/kernel/src/IndexableProperty.cc | 16 ++- dev/libSystem/SystemKit/Macros.h | 2 +- dev/misc/BenchKit/Chrono.h | 12 +- dev/misc/BenchKit/X64Chrono.h | 2 +- dev/modules/Power/PowerFactory.h | 2 +- .../CoreFoundation.fwrk/headers/String.h | 6 +- .../frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc | 2 +- .../KernelTest.fwrk/headers/KernelTest.h | 20 +-- public/frameworks/KernelTest.fwrk/src/UnitTests.cc | 14 +-- public/tools/diutil/vendor/Dialogs.h | 41 +++---- public/tools/mgmt.oe/src/CommandLine.cc | 3 +- tools/fsck.hefs.cc | 10 +- tools/libmkfs/mkfs.h | 8 +- tools/mkfs.hefs.cc | 44 +++---- 46 files changed, 241 insertions(+), 214 deletions(-) (limited to 'dev/libSystem') diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 68e4b484..12a5861f 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -293,16 +293,16 @@ inline Boolean BDiskFormatFactory::Format(const Char* part_name) { CopyMem(gpt_part->Signature, reinterpret_cast(const_cast(kMagicGPT)), StrLen(kMagicGPT)); - gpt_part->Revision = 0x00010000; + gpt_part->Revision = 0x00010000; gpt_part->HeaderSize = sizeof(GPT_PARTITION_TABLE); gpt_part->CRC32 = 0x00000000; - gpt_part->Reserved1 = 0x00000000; - gpt_part->LBAHeader = 0x00000000; - gpt_part->LBAAltHeader = 0x00000000; + gpt_part->Reserved1 = 0x00000000; + gpt_part->LBAHeader = 0x00000000; + gpt_part->LBAAltHeader = 0x00000000; gpt_part->FirstGPTEntry = 0x00000000; - gpt_part->LastGPTEntry = 0x00000000; + gpt_part->LastGPTEntry = 0x00000000; gpt_part->Guid.Data1 = 0x00000000; gpt_part->Guid.Data2 = 0x0000; @@ -312,10 +312,10 @@ inline Boolean BDiskFormatFactory::Format(const Char* part_name) { gpt_part->Revision = 0x00010000; - gpt_part->StartingLBA = 0x00000000; + gpt_part->StartingLBA = 0x00000000; gpt_part->NumPartitionEntries = 0x00000000; - gpt_part->SizeOfEntries = 0x00000000; - gpt_part->CRC32PartEntry = 0x00000000; + gpt_part->SizeOfEntries = 0x00000000; + gpt_part->CRC32PartEntry = 0x00000000; SetMem(gpt_part->Reserved2, 0, kSectorAlignGPT_PartTbl); diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 8236dd0d..d8ea5799 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -12,8 +12,8 @@ #include #include -STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; -STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; +STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out); diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index 25810222..e5e0d8c2 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,8 +88,7 @@ ATAInit_Retry: /// fetch serial info /// model, speed, number of sectors... - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); @@ -115,15 +114,14 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); @@ -149,15 +147,14 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); diff --git a/dev/boot/src/HEL/ARM64/BootPlatform.cc b/dev/boot/src/HEL/ARM64/BootPlatform.cc index 9dd03afe..683245fb 100644 --- a/dev/boot/src/HEL/ARM64/BootPlatform.cc +++ b/dev/boot/src/HEL/ARM64/BootPlatform.cc @@ -13,8 +13,7 @@ using namespace Boot; EXTERN_C void rt_halt() { - while (Yes) - ; + while (Yes); } EXTERN_C void rt_cli() {} diff --git a/dev/boot/src/New+Delete.cc b/dev/boot/src/New+Delete.cc index d4d5dfed..f7ad2898 100644 --- a/dev/boot/src/New+Delete.cc +++ b/dev/boot/src/New+Delete.cc @@ -17,8 +17,7 @@ void* operator new(size_t sz) { void* buf = nullptr; - while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk) - ; + while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk); return buf; } diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 845ef467..bb4e3dc0 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -259,7 +259,7 @@ inline UInt32 hefs_hour_get(ATime raw_atime) noexcept { /// @return the minute value. /// @note The minute is stored in the lower 8 bits of the ATime value. inline UInt32 hefs_minute_get(ATime raw_atime) noexcept { - return (raw_atime) &0xFF; + return (raw_atime) & 0xFF; } inline constexpr UInt32 kHeFSBaseYear = 1970; @@ -379,10 +379,10 @@ class HeFileSystemParser final { ~HeFileSystemParser() = default; public: - HeFileSystemParser(const HeFileSystemParser&) = delete; + HeFileSystemParser(const HeFileSystemParser&) = delete; HeFileSystemParser& operator=(const HeFileSystemParser&) = delete; - HeFileSystemParser(HeFileSystemParser&&) = delete; + HeFileSystemParser(HeFileSystemParser&&) = delete; HeFileSystemParser& operator=(HeFileSystemParser&&) = delete; public: diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index 97e3ad01..9b22f5b6 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -57,7 +57,7 @@ typedef Char16 EfiChar16Type; /// @brief Core Handle Kind /// Self is like NT's Win32 HANDLE type. typedef struct EfiHandle { -} * EfiHandlePtr; +}* EfiHandlePtr; /* UEFI uses wide characters by default. */ typedef WideChar EfiCharType; @@ -239,63 +239,85 @@ typedef struct EfiTableHeader { UInt32 Reserved; } EfiTableHeader; -#define EFI_ACPI_TABLE_PROTOCOL_GUID \ - { \ - 0xffe06bdd, 0x6107, 0x46a6, { 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c } \ +#define EFI_ACPI_TABLE_PROTOCOL_GUID \ + { \ + 0xffe06bdd, 0x6107, 0x46a6, { \ + 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ + } \ } -#define EFI_LOAD_FILE_PROTOCOL_GUID \ - { \ - 0x56EC3091, 0x954C, 0x11d2, { 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_LOAD_FILE_PROTOCOL_GUID \ + { \ + 0x56EC3091, 0x954C, 0x11d2, { \ + 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_LOAD_FILE2_PROTOCOL_GUID \ - { \ - 0x4006c0c1, 0xfcb3, 0x403e, { 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \ +#define EFI_LOAD_FILE2_PROTOCOL_GUID \ + { \ + 0x4006c0c1, 0xfcb3, 0x403e, { \ + 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \ + } \ } -#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ - { \ - 0x5B1B31A1, 0x9562, 0x11d2, { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \ +#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ + { \ + 0x5B1B31A1, 0x9562, 0x11d2, { \ + 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \ + } \ } -#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ - { \ - 0x9042a9de, 0x23dc, 0x4a38, { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } \ +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + { \ + 0x9042a9de, 0x23dc, 0x4a38, { \ + 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ + } \ } -#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ - { \ - 0xA19832B9, 0xAC25, 0x11D3, { 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ +#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ + { \ + 0xA19832B9, 0xAC25, 0x11D3, { \ + 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d \ + } \ } #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000 -#define EFI_IP4_PROTOCOL_GUID \ - { \ - 0x41d94cd2, 0x35b6, 0x455a, { 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd } \ +#define EFI_IP4_PROTOCOL_GUID \ + { \ + 0x41d94cd2, 0x35b6, 0x455a, { \ + 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd \ + } \ } #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0xbc62157e, 0x3e33, 0x4fec, { 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf } \ +#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0xbc62157e, 0x3e33, 0x4fec, { \ + 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \ + } \ } -#define EFI_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0x9576e91, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0x9576e91, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle); @@ -351,17 +373,17 @@ typedef struct { typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_TRANSMIT)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, IN UInt32 HeaderSize, IN UInt32 BufferSize, - IN Void* Buffer, - IN EfiMacAddress* SrcAddr OPTIONAL, + IN Void* Buffer, + IN EfiMacAddress* SrcAddr OPTIONAL, IN EfiMacAddress* DestAddr OPTIONAL, - IN UInt16* Protocol OPTIONAL); + IN UInt16* Protocol OPTIONAL); typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_RECEIVE)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, - OUT UInt32* HeaderSize OPTIONAL, + OUT UInt32* HeaderSize OPTIONAL, IN OUT UInt32* BufferSize, OUT Void* Buffer, - OUT EfiMacAddress* SrcAddr OPTIONAL, + OUT EfiMacAddress* SrcAddr OPTIONAL, OUT EfiMacAddress* DestAddr OPTIONAL, - OUT UInt16* Protocol OPTIONAL); + OUT UInt16* Protocol OPTIONAL); typedef struct EFI_SIMPLE_NETWORK_PROTOCOL { UInt64 Revision; @@ -506,9 +528,11 @@ typedef struct EFI_GUID EFI_FINAL { * Protocol stuff... */ -#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ - { \ - 0x387477c1, 0x69c7, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ + { \ + 0x387477c1, 0x69c7, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } /** some helpers */ @@ -607,7 +631,7 @@ typedef struct { } EfiInputKey; typedef EfiStatusType(EFI_API* EfiInputReadKey)(IN EfiSimpleTextInputProtocol* This, - OUT EfiInputKey* Key); + OUT EfiInputKey* Key); typedef EfiStatusType(EFI_API* EfiInputReset)(IN EfiSimpleTextInputProtocol* This, IN Boolean ExtendedChk); @@ -665,7 +689,7 @@ typedef struct EfiSystemTable { struct { EFI_GUID VendorGUID; VoidPtr VendorTable; - } * ConfigurationTable; + }* ConfigurationTable; } EfiSystemTable; #define kEfiOk 0 @@ -726,9 +750,11 @@ enum { #define EFI_EXTRA_DESCRIPTOR_SIZE 8 -#define EFI_MP_SERVICES_PROTOCOL_GUID \ - { \ - 0x3fdda605, 0xa76e, 0x4f46, { 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 } \ +#define EFI_MP_SERVICES_PROTOCOL_GUID \ + { \ + 0x3fdda605, 0xa76e, 0x4f46, { \ + 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 \ + } \ } #define PROCESSOR_AS_BSP_BIT 0x00000001 @@ -825,9 +851,11 @@ typedef struct EfiTime { UInt8 Pad2; } EfiTime; -#define EFI_FILE_INFO_GUID \ - { \ - 0x09576e92, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_FILE_INFO_GUID \ + { \ + 0x09576e92, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } struct EfiFileInfo EFI_FINAL { @@ -896,8 +924,8 @@ typedef EfiStatusType EFI_API (*EfiMpServicesStartupThisAP)( IN Void* ProcedureArgument OPTIONAL, OUT Boolean* Finished OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesDisableThisAP)(IN struct _EfiMpServicesProtocol* Self, - IN UInt32 ProcessorNumber, - IN Boolean EnableAP, + IN UInt32 ProcessorNumber, + IN Boolean EnableAP, IN UInt32* HealthFlag OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesWhoAmI)(IN struct _EfiMpServicesProtocol* Self, diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 0dbd6815..4a667549 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -116,7 +116,7 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ThreadID thrdid) if (!stack_frame) return NO; if (thrdid > kSMPCount) return NO; - + if (!kSMPAware) { sched_jump_to_task(kHWThread[thrdid].mFramePtr); diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc index b837497e..0c2d0960 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc @@ -61,8 +61,7 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { hal_idt_send_eoi(32); - while (kIsRunning) - ; + while (kIsRunning); kIsRunning = YES; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 39f7de1d..c7a87b13 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -42,7 +42,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { handover_hdr->f_HardwareTables.f_ImageHandle); kKernelVM = kHandoverHeader->f_PageStart; - + if (!kKernelVM) { MUST_PASS(kKernelVM); return kEfiFail; @@ -168,7 +168,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { idt_loader.Load(idt_reg); - while (YES) - ; + while (YES); } #endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index 079acde4..cf297632 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -57,7 +57,9 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast(reg); + } } // namespace Detail auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr; diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index 39efb7d3..4688203f 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -105,7 +105,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz - 1) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -123,8 +123,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(kATADevice.Bar(0x20) + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) - ; + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine @@ -147,7 +146,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz - 1)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -163,8 +162,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) - ; + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 6fccbdfa..9c5b3931 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -83,8 +83,7 @@ ATAInit_Retry: rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); /// fetch serial info /// model, speed, number of sectors... @@ -117,15 +116,14 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); @@ -149,15 +147,14 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); diff --git a/dev/kernel/HALKit/ARM64/CxxAbi.cc b/dev/kernel/HALKit/ARM64/CxxAbi.cc index 09898b08..964fc2f4 100644 --- a/dev/kernel/HALKit/ARM64/CxxAbi.cc +++ b/dev/kernel/HALKit/ARM64/CxxAbi.cc @@ -85,4 +85,3 @@ EXTERN_C Kernel::Void _Init_thread_header(Kernel::Int* thread_obj) { } EXTERN_C Kernel::Int _tls_index = 0UL; - diff --git a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc index 0c26f4cb..63a42de8 100644 --- a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc @@ -56,8 +56,7 @@ EXTERN_C void int_handle_scheduler(Kernel::UIntPtr rsp) { hal_int_send_eoi(32); - while (kIsRunning) - ; + while (kIsRunning); kIsRunning = YES; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 20bd3d8a..d8e6843b 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -71,7 +71,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Kernel::mp_init_cores(); - while (YES) - ; + while (YES); } #endif \ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/Paging.h b/dev/kernel/HALKit/ARM64/Paging.h index 7a022141..be9fb116 100644 --- a/dev/kernel/HALKit/ARM64/Paging.h +++ b/dev/kernel/HALKit/ARM64/Paging.h @@ -86,7 +86,9 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast(reg); + } } // namespace Detail struct PDE_4KB final { diff --git a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc index daa26e53..6059e3be 100644 --- a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc @@ -10,8 +10,7 @@ namespace Kernel::Detail { STATIC void mp_hang_fn(void) { - while (YES) - ; + while (YES); } } // namespace Kernel::Detail diff --git a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc index 31d4a62e..e6fdddfb 100644 --- a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc @@ -13,8 +13,7 @@ using namespace Kernel; namespace Kernel { namespace Detail { STATIC void mp_hang_fn(void) { - while (YES) - ; + while (YES); } } // namespace Detail diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index b92d7393..a7908b7d 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -98,7 +98,7 @@ struct PROCESS_FILE_TREE { struct PROCESS_FILE_TREE* Prev { nullptr }; - + struct PROCESS_FILE_TREE* Next { nullptr }; diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index d1334277..f925a96c 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -22,7 +22,6 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H - /// @file FileMgr.h /// @brief File Manager. /// @author Amlal El Mahrouss (amlal@nekernel.org) diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index 76327a93..168a0cc1 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -100,7 +100,7 @@ class HardwareThreadScheduler final : public ISchedulable { public: Ref operator[](SizeT idx); bool operator!() noexcept; - operator bool() noexcept; + operator bool() noexcept; Bool IsUser() override { return Yes; } diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index 222041e8..c0879769 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -29,8 +29,9 @@ class KERNEL_TASK final { UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; PROCESS_IMAGE Image{}; - /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within the kernel. - KID Kid{0}; + /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within + /// the kernel. + KID Kid{0}; }; /// @brief Equivalent of UserProcessHelper, but for kernel tasks. diff --git a/dev/kernel/KernelKit/LoaderInterface.h b/dev/kernel/KernelKit/LoaderInterface.h index 1f9b1e56..ed7d8364 100644 --- a/dev/kernel/KernelKit/LoaderInterface.h +++ b/dev/kernel/KernelKit/LoaderInterface.h @@ -23,9 +23,9 @@ class LoaderInterface { public: virtual _Output ErrorOr GetBlob() = 0; - virtual _Output const Char* AsString() = 0; - virtual _Output const Char* MIME() = 0; - virtual _Output const Char* Path() = 0; + virtual _Output const Char* AsString() = 0; + virtual _Output const Char* MIME() = 0; + virtual _Output const Char* Path() = 0; virtual _Output ErrorOr FindStart() = 0; virtual _Output ErrorOr FindSymbol(_Input const Char* name, _Input Int32 kind) = 0; }; diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index 7e7d3f0c..c4e3b61a 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -47,7 +47,7 @@ class DMAWrapper final { T* Get(UIntPtr off = 0); public: - operator bool(); + operator bool(); bool operator!(); public: diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 930b245d..705d9f18 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -28,7 +28,7 @@ typedef UInt64 SemaphoreArr[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline BOOL rtl_sem_is_valid(const SemaphoreArr& sem, UInt64 owner = 0) { - return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] >= 0; + return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; } /// @brief Releases the semaphore, resetting its owner and count. @@ -61,7 +61,8 @@ inline BOOL rtl_sem_acquire(SemaphoreArr& sem, UInt64 owner) { /// @param sem /// @param timeout /// @return -inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { +inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, + BOOL* condition = nullptr) { if (!rtl_sem_is_valid(sem, owner)) { return FALSE; } diff --git a/dev/kernel/NeKit/Macros.h b/dev/kernel/NeKit/Macros.h index b46ffaa8..e80e2e47 100644 --- a/dev/kernel/NeKit/Macros.h +++ b/dev/kernel/NeKit/Macros.h @@ -16,7 +16,7 @@ #endif #ifndef kib_cast -#define kib_cast(X) (Kernel::UInt64)((X) *1024) +#define kib_cast(X) (Kernel::UInt64)((X) * 1024) #endif #ifndef MIB diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h index 674f9ff3..f5ff4b54 100644 --- a/dev/kernel/NeKit/OwnPtr.h +++ b/dev/kernel/NeKit/OwnPtr.h @@ -50,7 +50,7 @@ class OwnPtr final { Ref AsRef() { return Ref(fCls); } - operator bool() { return fCls; } + operator bool() { return fCls; } bool operator!() { return !fCls; } private: diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 4d343bc5..46e94f88 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -29,7 +29,7 @@ class Ref final { return *this; } - NE_COPY_DEFAULT(Ref); + NE_COPY_DEFAULT(Ref) public: T operator->() const { return fClass; } diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 24e4e220..66a4aaef 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -73,8 +73,7 @@ Void rt_zero_memory(voidPtr pointer, Size len) { #ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_set_memory_safe instead")]] #endif -voidPtr -rt_set_memory(voidPtr src, UInt32 value, Size len) { +voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { if (!src) return nullptr; auto p = reinterpret_cast(src); UInt8 v = static_cast(value & 0xFF); diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc index f669d7fa..9bfb89d9 100644 --- a/dev/kernel/src/BinaryMutex.cc +++ b/dev/kernel/src/BinaryMutex.cc @@ -14,7 +14,7 @@ namespace Kernel { Bool BinaryMutex::Unlock() noexcept { if (fLockingProcess->Status == ProcessStatusKind::kRunning) { - fLockingProcess = nullptr; + fLockingProcess = nullptr; return Yes; } diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 14e0b974..7b9ebcd6 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -154,8 +154,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) { /// @return the newly found fork. /***********************************************************************************/ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - _Input Boolean is_data) { + _Input const Char* name, + _Input Boolean is_data) { if (!catalog || !name) return nullptr; auto& drive = kMountpoint.A(); @@ -217,7 +217,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { kout << "CreateCatalog(*...*)\r"; diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc index c11e328d..251d6645 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -18,13 +18,21 @@ namespace Kernel { namespace Indexer { - Index& IndexableProperty::Leak() noexcept { return fIndex; } + Index& IndexableProperty::Leak() noexcept { + return fIndex; + } - Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } + Void IndexableProperty::AddFlag(Int16 flag) { + fFlags |= flag; + } - Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } + Void IndexableProperty::RemoveFlag(Int16 flag) { + fFlags &= flag; + } - Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; } + Int16 IndexableProperty::HasFlag(Int16 flag) { + return fFlags & flag; + } /// @brief Index a file into the indexer instance. /// @param filename filesystem path to access. diff --git a/dev/libSystem/SystemKit/Macros.h b/dev/libSystem/SystemKit/Macros.h index 2bdeff9d..25bc77ba 100644 --- a/dev/libSystem/SystemKit/Macros.h +++ b/dev/libSystem/SystemKit/Macros.h @@ -94,7 +94,7 @@ typedef nullPtr NullPtr; #endif #ifndef kib_cast -#define kib_cast(X) (UInt64)((X) *1024) +#define kib_cast(X) (UInt64)((X) * 1024) #endif #ifndef MIB diff --git a/dev/misc/BenchKit/Chrono.h b/dev/misc/BenchKit/Chrono.h index c6801de5..3a82a94e 100644 --- a/dev/misc/BenchKit/Chrono.h +++ b/dev/misc/BenchKit/Chrono.h @@ -24,13 +24,17 @@ class ChronoInterface { ChronoInterface() = default; virtual ~ChronoInterface() = default; - NE_COPY_DEFAULT(ChronoInterface); + NE_COPY_DEFAULT(ChronoInterface) - virtual void Start() = 0; - virtual void Stop() = 0; - virtual void Reset() = 0; + virtual Void Start() = 0; + virtual Void Stop() = 0; + virtual Void Reset() = 0; virtual UInt64 GetElapsedTime() const = 0; }; } // namespace Kernel +namespace BenchKit { +using namespace Kernel; +} + #endif // BENCHKIT_CHRONO_H diff --git a/dev/misc/BenchKit/X64Chrono.h b/dev/misc/BenchKit/X64Chrono.h index 358c74d4..ac92ebb1 100644 --- a/dev/misc/BenchKit/X64Chrono.h +++ b/dev/misc/BenchKit/X64Chrono.h @@ -19,7 +19,7 @@ struct X64ChronoTraits { private: STATIC UInt64 TickImpl_(void) { UInt64 a = 0, d = 0; - + asm volatile("rdtsc" : "=a"(a), "=d"(d)); return (d << 32) | a; } diff --git a/dev/modules/Power/PowerFactory.h b/dev/modules/Power/PowerFactory.h index b7c13280..ba3a8da6 100644 --- a/dev/modules/Power/PowerFactory.h +++ b/dev/modules/Power/PowerFactory.h @@ -27,6 +27,6 @@ class PowerFactory { public: Bool Shutdown() { return NO; }; // shutdown - Void Reboot(){}; // soft-reboot + Void Reboot() {}; // soft-reboot }; } // namespace Kernel \ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/String.h b/public/frameworks/CoreFoundation.fwrk/headers/String.h index ea32038d..80b68536 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/String.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/String.h @@ -14,10 +14,10 @@ class CFString; class CFString final CF_OBJECT { public: - CFString() = default; + CFString() = default; ~CFString() = default; - - CFString(const CFString&) = delete; + + CFString(const CFString&) = delete; CFString& operator=(const CFString&) = delete; }; } // namespace CF \ No newline at end of file diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc index 1291a3e1..83b52905 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc @@ -38,7 +38,7 @@ SInt32 DI::DIFormatPartitionEPM(struct DI_DISK_IMAGE& img) noexcept { if (!handle) return kDIFailureStatus; ::IoWriteFile(handle, (Char*) &block, sizeof(struct ::EPM_PART_BLOCK)); - + ::IoCloseFile(handle); handle = nullptr; diff --git a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h index 9d4fd351..70b1b9b3 100644 --- a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h +++ b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h @@ -18,14 +18,18 @@ #define KT_TEST_SUCCESS (0) -#define KT_DECL_TEST(NAME, FN) \ - class KT_##NAME final { \ - public: \ - Kernel::Void Run(); \ - const Kernel::Char* ToString(); \ - }; \ - inline Kernel::Void KT_##NAME::Run() { MUST_PASS(FN() == true); } \ - inline const Kernel::Char* KT_##NAME::ToString() { return #FN; } +#define KT_DECL_TEST(NAME, FN) \ + class KT_##NAME final { \ + public: \ + Kernel::Void Run(); \ + const Kernel::Char* ToString(); \ + }; \ + inline Kernel::Void KT_##NAME::Run() { \ + MUST_PASS(FN() == true); \ + } \ + inline const Kernel::Char* KT_##NAME::ToString() { \ + return #FN; \ + } KT_DECL_TEST(ALWAYS_BREAK, []() -> bool { return false; }); KT_DECL_TEST(ALWAYS_GOOD, []() -> bool { return true; }); \ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc index a02d1499..07e7b129 100644 --- a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc +++ b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc @@ -6,14 +6,12 @@ #include -EXTERN_C Kernel::Void KT_TestBreak() -{ - KT_ALWAYS_BREAK brk; - brk.Run(); +EXTERN_C Kernel::Void KT_TestBreak() { + KT_ALWAYS_BREAK brk; + brk.Run(); } -EXTERN_C Kernel::Void KT_TestGood() -{ - KT_ALWAYS_GOOD good; - good.Run(); +EXTERN_C Kernel::Void KT_TestGood() { + KT_ALWAYS_GOOD good; + good.Run(); } \ No newline at end of file diff --git a/public/tools/diutil/vendor/Dialogs.h b/public/tools/diutil/vendor/Dialogs.h index 84e239f5..ce50b811 100644 --- a/public/tools/diutil/vendor/Dialogs.h +++ b/public/tools/diutil/vendor/Dialogs.h @@ -175,7 +175,7 @@ namespace internal { #elif __EMSCRIPTEN__ void start(int exit_code); #else - void start_process(std::vector const& command); + void start_process(std::vector const& command); #endif ~executor(); @@ -490,10 +490,10 @@ inline settings::settings(bool resync) { #if _WIN32 flags(flag::is_vista) = internal::is_vista(); #elif !__APPLE__ - flags(flag::has_zenity) = check_program("zenity"); + flags(flag::has_zenity) = check_program("zenity"); flags(flag::has_matedialog) = check_program("matedialog"); - flags(flag::has_qarma) = check_program("qarma"); - flags(flag::has_kdialog) = check_program("kdialog"); + flags(flag::has_qarma) = check_program("qarma"); + flags(flag::has_kdialog) = check_program("kdialog"); // If multiple helpers are available, try to default to the best one if (flags(flag::has_zenity) && flags(flag::has_kdialog)) { @@ -540,7 +540,7 @@ inline bool settings::check_program(std::string const& program) { (void) program; return false; #else - int exit_code = -1; + int exit_code = -1; internal::executor async; async.start_process({"/bin/sh", "-c", "which " + program}); async.result(&exit_code); @@ -604,7 +604,7 @@ inline std::string path::home() { if (size_max != -1) len = size_t(size_max); #endif std::vector buf(len); - struct passwd pwd, *result; + struct passwd pwd, *result; if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) return result->pw_dir; #endif return "/"; @@ -717,7 +717,7 @@ inline void internal::executor::start_process(std::vector const& co } close(in[1]); - m_fd = out[0]; + m_fd = out[0]; auto flags = fcntl(m_fd, F_GETFL); fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); @@ -753,7 +753,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // FIXME: do something (void) timeout; #else - char buf[BUFSIZ]; + char buf[BUFSIZ]; ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore if (received > 0) { m_stdout += std::string(buf, received); @@ -764,7 +764,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // (this happens when the calling application handles or ignores SIG_CHLD) and results in // waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for // a little while. - int status; + int status; pid_t child = waitpid(m_pid, &status, WNOHANG); if (child != m_pid && (child >= 0 || errno != ECHILD)) { // FIXME: this happens almost always at first iteration @@ -782,8 +782,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) inline void internal::executor::stop() { // Loop until the user closes the dialog - while (!ready()) - ; + while (!ready()); } // dll implementation @@ -879,11 +878,11 @@ inline std::vector internal::dialog::desktop_helper() const { #if __APPLE__ return {"osascript"}; #else - return {flags(flag::has_zenity) ? "zenity" + return {flags(flag::has_zenity) ? "zenity" : flags(flag::has_matedialog) ? "matedialog" - : flags(flag::has_qarma) ? "qarma" - : flags(flag::has_kdialog) ? "kdialog" - : "echo"}; + : flags(flag::has_qarma) ? "qarma" + : flags(flag::has_kdialog) ? "kdialog" + : "echo"}; #endif } @@ -1125,9 +1124,9 @@ inline internal::file_dialog::file_dialog(type in_type, std::string const& title // Split the pattern list to check whether "*" is in there; if it // is, we have to disable filters because there is no mechanism in // OS X for the user to override the filter. - std::regex sep("\\s+"); - std::string filter_list; - bool has_filter = true; + std::regex sep("\\s+"); + std::string filter_list; + bool has_filter = true; std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1); std::sregex_token_iterator end; for (; iter != end; ++iter) { @@ -1236,7 +1235,7 @@ inline std::vector internal::file_dialog::vector_result() { return m_vector_result; #else std::vector ret; - auto result = m_async->result(); + auto result = m_async->result(); for (;;) { // Split result along newline characters auto i = result.find('\n'); @@ -1569,7 +1568,7 @@ inline message::message(std::string const& title, std::string const& text, if_cancel = button::ok; break; } - m_mappings[1] = if_cancel; + m_mappings[1] = if_cancel; m_mappings[256] = if_cancel; // XXX: I think this was never correct script += " with icon "; switch (_icon) { @@ -1656,7 +1655,7 @@ inline message::message(std::string const& title, std::string const& text, if (_choice == choice::yes_no_cancel) flag += "cancel"; command.push_back(flag); if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) { - m_mappings[0] = button::yes; + m_mappings[0] = button::yes; m_mappings[256] = button::no; } } diff --git a/public/tools/mgmt.oe/src/CommandLine.cc b/public/tools/mgmt.oe/src/CommandLine.cc index 3888476c..3a0c192d 100644 --- a/public/tools/mgmt.oe/src/CommandLine.cc +++ b/public/tools/mgmt.oe/src/CommandLine.cc @@ -22,7 +22,8 @@ SInt32 _NeMain(SInt32 argc, Char* argv[]) { ::PrintOut(nullptr, "%s", "mgmt.oe: OpenEnclave Management Tool."); - /// @note JailGetCurrent returns client as nullptr if we're not that client (we'll not be able to access the jail then) + /// @note JailGetCurrent returns client as nullptr if we're not that client (we'll not be able to + /// access the jail then) if (kJailSrv->fClient == nullptr) return EXIT_FAILURE; return EXIT_FAILURE; diff --git a/tools/fsck.hefs.cc b/tools/fsck.hefs.cc index e3837b8a..5a41cec2 100644 --- a/tools/fsck.hefs.cc +++ b/tools/fsck.hefs.cc @@ -9,12 +9,11 @@ #include #include -static uint16_t kNumericalBase = 10; +static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { if (argc < 2) { - mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" - << "\n"; + mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" << "\n"; return EXIT_FAILURE; } @@ -25,8 +24,7 @@ int main(int argc, char** argv) { auto origin = mkfs::get_option(args, "-o"); if (opt_disk.empty()) { - mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." - << "\n"; + mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." << "\n"; return EXIT_FAILURE; } @@ -54,7 +52,7 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - + output_device.read(reinterpret_cast(&boot_node), sizeof(boot_node)); if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || diff --git a/tools/libmkfs/mkfs.h b/tools/libmkfs/mkfs.h index e729c29b..6e242293 100644 --- a/tools/libmkfs/mkfs.h +++ b/tools/libmkfs/mkfs.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include #include #define kMkFsSectorSz (512U) @@ -35,13 +35,13 @@ namespace detail { inline bool parse_signed(const std::string& opt, long& out, int base = 10) { out = 0L; - + if (opt.empty()) return true; char* endptr = nullptr; long val = std::strtol(opt.c_str(), &endptr, base); - auto err = errno; - + auto err = errno; + if (err == ERANGE || err == EINVAL) return false; if (endptr == opt.c_str() || *endptr != '\0') return false; diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index bf790598..9f70b78f 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -15,7 +15,7 @@ static size_t kDiskSize = mkfs::detail::gib_cast(4UL); static uint16_t kVersion = kHeFSVersion; static std::u8string kLabel; -static size_t kSectorSize = 512; +static size_t kSectorSize = 512; static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { @@ -91,22 +91,22 @@ int main(int argc, char** argv) { mkfs::console_out() << "hefs: error: Invalid -b argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_e, end_ind, kNumericalBase) || end_ind <= start_ind) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -e argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_bs, start_block, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -bs argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_be, end_block, kNumericalBase) || end_block <= start_block) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -be argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_is, start_in, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -is argument.\n"; return EXIT_FAILURE; @@ -133,24 +133,24 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - boot_node.version = kVersion; - boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; - boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; - boot_node.diskSize = kDiskSize; - boot_node.sectorSize = kSectorSize; + boot_node.version = kVersion; + boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; + boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; + boot_node.diskSize = kDiskSize; + boot_node.sectorSize = kSectorSize; boot_node.sectorCount = kDiskSize / kSectorSize; - boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); - boot_node.endIND = static_cast(end_ind); - boot_node.startIN = static_cast(start_in); - boot_node.endIN = static_cast(end_in); - boot_node.startBlock = static_cast(start_block); - boot_node.endBlock = static_cast(end_block); - boot_node.indCount = 0UL; - boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; + boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); + boot_node.endIND = static_cast(end_ind); + boot_node.startIN = static_cast(start_in); + boot_node.endIN = static_cast(end_in); + boot_node.startBlock = static_cast(start_block); + boot_node.endBlock = static_cast(end_block); + boot_node.indCount = 0UL; + boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; static_assert(sizeof(boot_node.magic) >= kHeFSMagicLen, "BootNode::magic too small to hold kHeFSMagicLen"); - + std::memset(boot_node.magic, 0, sizeof(boot_node.magic)); size_t magic_copy = (sizeof(boot_node.magic) < kHeFSMagicLen - 1) ? sizeof(boot_node.magic) : (kHeFSMagicLen - 1); @@ -158,15 +158,15 @@ int main(int argc, char** argv) { boot_node.magic[magic_copy] = 0; constexpr size_t vol_slots = kHeFSPartNameLen; - + std::memset(boot_node.volumeName, 0, sizeof(boot_node.volumeName)); - + size_t label_units = std::min(kLabel.size(), vol_slots - 1); for (size_t i = 0; i < label_units; ++i) { boot_node.volumeName[i] = static_cast(kLabel[i]); } - + boot_node.volumeName[label_units] = 0U; output_device.seekp(static_cast(start_ind)); -- cgit v1.2.3 From d9f1a4f656ced76df3f23eeec678e1a3be1fd432 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Sat, 9 Aug 2025 23:14:12 +0300 Subject: Update SystemCalls.cc --- dev/libSystem/src/SystemCalls.cc | 121 ++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 26 deletions(-) (limited to 'dev/libSystem') diff --git a/dev/libSystem/src/SystemCalls.cc b/dev/libSystem/src/SystemCalls.cc index 6344cdac..71eebc62 100644 --- a/dev/libSystem/src/SystemCalls.cc +++ b/dev/libSystem/src/SystemCalls.cc @@ -10,13 +10,41 @@ /// @file SystemAPI.cc /// @brief System wide API for NeKernel. +namespace Detail { + template + inline VoidPtr safe_void_cast(const T* ptr) { + return const_cast(static_cast(ptr)); + } +} + 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]; + auto src_bytes = static_cast(src); + auto dst_bytes = static_cast(dest); + + if (len >= sizeof(UInt64) && + (reinterpret_cast(src) % sizeof(UInt64)) == 0 && + (reinterpret_cast(dest) % sizeof(UInt64)) == 0) { + + auto src_words = static_cast(src); + auto dst_words = static_cast(dest); + SizeT word_count = len / sizeof(UInt64); + + for (SizeT i = 0; i < word_count; ++i) { + dst_words[i] = src_words[i]; + } + + SizeT remaining = len % sizeof(UInt64); + for (SizeT i = 0; i < remaining; ++i) { + dst_bytes[len - remaining + i] = src_bytes[len - remaining + i]; + } + } else { + for (SizeT i = 0; i < len; ++i) { + dst_bytes[i] = src_bytes[i]; + } } return dest; @@ -25,13 +53,13 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si IMPORT_C SInt64 MmStrLen(const Char* in) { if (!in) return 0; - SizeT len{0}; - - do { + SizeT len = 0; + + while (in[len] != '\0') { ++len; - } while (in[len] != '\0'); + } - return len; + return static_cast(len); } IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { @@ -39,56 +67,97 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt return nullptr; } - for (SizeT i = 0; i < len; i++) { - ((Char*) dest)[i] = value; + auto dst_bytes = static_cast(dest); + + if (len >= sizeof(UInt64) && (reinterpret_cast(dest) % sizeof(UInt64)) == 0) { + // 64-bit pattern + UInt64 pattern = static_cast(value); + pattern |= (pattern << 8); + pattern |= (pattern << 16); + pattern |= (pattern << 32); + + auto dst_words = static_cast(dest); + SizeT word_count = len / sizeof(UInt64); + + for (SizeT i = 0; i < word_count; ++i) { + dst_words[i] = pattern; + } + + SizeT remaining = len % sizeof(UInt64); + for (SizeT i = 0; i < remaining; ++i) { + dst_bytes[len - remaining + i] = value; + } + } else { + for (SizeT i = 0; i < len; ++i) { + dst_bytes[i] = value; + } } return dest; } IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return (Ref) libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), - reinterpret_cast(const_cast(path)), - reinterpret_cast(const_cast(drv_letter))); + return static_cast(libsys_syscall_arg_3( + SYSCALL_HASH("IoOpenFile"), + Detail::safe_void_cast(path), + Detail::safe_void_cast(drv_letter))); } IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(2, desc); + libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast(desc)); } IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (volatile UInt64*) libsys_syscall_arg_3( - SYSCALL_HASH("IoSeekFile"), reinterpret_cast(desc), reinterpret_cast(&off)); + auto ret_ptr = libsys_syscall_arg_3( + SYSCALL_HASH("IoSeekFile"), + static_cast(desc), + reinterpret_cast(&off)); - MUST_PASS((*ret) != ~0UL); - return *ret; + if (!ret_ptr) { + return ~0UL; + } + + auto ret = static_cast(ret_ptr); + UInt64 result = *ret; + MUST_PASS(result != ~0UL); + return result; } IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), - reinterpret_cast(desc)); + auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), + static_cast(desc)); + + if (!ret_ptr) { + return ~0UL; + } + + auto ret = static_cast(ret_ptr); return *ret; } IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { va_list args; - va_start(args, fmt); - auto ret = (volatile UInt64*) libsys_syscall_arg_4( - SYSCALL_HASH("PrintOut"), reinterpret_cast(desc), - reinterpret_cast(const_cast(fmt)), args); + auto ret_ptr = libsys_syscall_arg_4( + SYSCALL_HASH("PrintOut"), + static_cast(desc), + Detail::safe_void_cast(fmt), + static_cast(&args)); va_end(args); - + + if (!ret_ptr) { + return -1; + } + + auto ret = static_cast(ret_ptr); return *ret; } IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { if (!expr) { PrintOut(nullptr, "Assertion failed: %s\r", origin); - PrintOut(nullptr, "Origin: %s\r", origin); - libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); } } -- cgit v1.2.3 From c896d07fec6d949328a4ef09a80c47fe6f682e67 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Sun, 10 Aug 2025 15:41:43 +0300 Subject: feat(libSystem): implement memory ops with alignment & overlap handling --- dev/libSystem/src/SystemCalls.cc | 167 +++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 75 deletions(-) (limited to 'dev/libSystem') diff --git a/dev/libSystem/src/SystemCalls.cc b/dev/libSystem/src/SystemCalls.cc index 71eebc62..83569b6f 100644 --- a/dev/libSystem/src/SystemCalls.cc +++ b/dev/libSystem/src/SystemCalls.cc @@ -7,9 +7,6 @@ #include #include -/// @file SystemAPI.cc -/// @brief System wide API for NeKernel. - namespace Detail { template inline VoidPtr safe_void_cast(const T* ptr) { @@ -17,33 +14,67 @@ namespace Detail { } } +// memmove-style copy IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { - if (!len || !dest || !src) { - return nullptr; - } - - auto src_bytes = static_cast(src); - auto dst_bytes = static_cast(dest); - - if (len >= sizeof(UInt64) && - (reinterpret_cast(src) % sizeof(UInt64)) == 0 && - (reinterpret_cast(dest) % sizeof(UInt64)) == 0) { - - auto src_words = static_cast(src); - auto dst_words = static_cast(dest); - SizeT word_count = len / sizeof(UInt64); - - for (SizeT i = 0; i < word_count; ++i) { - dst_words[i] = src_words[i]; - } - - SizeT remaining = len % sizeof(UInt64); - for (SizeT i = 0; i < remaining; ++i) { - dst_bytes[len - remaining + i] = src_bytes[len - remaining + i]; + // handles overlap, prefers 64-bit word copies when aligned + if (!len || !dest || !src) return nullptr; + + auto s = static_cast(src); + auto d = static_cast(dest); + + if (d == s) return dest; + + // decide direction + if (d > s && d < s + len) { + const UInt8* rs = s + len; + UInt8* rd = d + len; + + // try 64-bit aligned backward copy + if (len >= sizeof(UInt64) && + (reinterpret_cast(rs) % sizeof(UInt64) == 0) && + (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { + + auto rsw = reinterpret_cast(rs); + auto rdw = reinterpret_cast(rd); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + rdw[-1 - static_cast(i)] = rsw[-1 - static_cast(i)]; + } + + SizeT rem = len % sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + rd[-1 - i] = rs[-1 - i]; + } + } else { + // byte-wise backward + for (SizeT i = 0; i < len; ++i) { + rd[-1 - i] = rs[-1 - i]; + } } } else { - for (SizeT i = 0; i < len; ++i) { - dst_bytes[i] = src_bytes[i]; + // try 64-bit aligned forward copy + if (len >= sizeof(UInt64) && + (reinterpret_cast(s) % sizeof(UInt64) == 0) && + (reinterpret_cast(d) % sizeof(UInt64) == 0)) { + + auto sw = reinterpret_cast(s); + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = sw[i]; + } + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = s[offset + i]; + } + } else { + for (SizeT i = 0; i < len; ++i) { + d[i] = s[i]; + } } } @@ -51,46 +82,38 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si } IMPORT_C SInt64 MmStrLen(const Char* in) { + // strlen via pointer walk if (!in) return 0; - - SizeT len = 0; - - while (in[len] != '\0') { - ++len; - } - - return static_cast(len); + const Char* p = in; + while (*p) ++p; + return static_cast(p - in); } IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { - if (!len || !dest) { - return nullptr; - } + if (!len || !dest) return nullptr; + + auto d = static_cast(dest); - auto dst_bytes = static_cast(dest); - - if (len >= sizeof(UInt64) && (reinterpret_cast(dest) % sizeof(UInt64)) == 0) { - // 64-bit pattern + if (len >= sizeof(UInt64) && (reinterpret_cast(d) % sizeof(UInt64)) == 0) { UInt64 pattern = static_cast(value); pattern |= (pattern << 8); pattern |= (pattern << 16); pattern |= (pattern << 32); - - auto dst_words = static_cast(dest); - SizeT word_count = len / sizeof(UInt64); - - for (SizeT i = 0; i < word_count; ++i) { - dst_words[i] = pattern; + + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = pattern; } - - SizeT remaining = len % sizeof(UInt64); - for (SizeT i = 0; i < remaining; ++i) { - dst_bytes[len - remaining + i] = value; + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = value; } } else { - for (SizeT i = 0; i < len; ++i) { - dst_bytes[i] = value; - } + for (SizeT i = 0; i < len; ++i) d[i] = value; } return dest; @@ -109,13 +132,11 @@ IMPORT_C Void IoCloseFile(_Input Ref desc) { IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { auto ret_ptr = libsys_syscall_arg_3( - SYSCALL_HASH("IoSeekFile"), - static_cast(desc), + SYSCALL_HASH("IoSeekFile"), + static_cast(desc), reinterpret_cast(&off)); - if (!ret_ptr) { - return ~0UL; - } + if (!ret_ptr) return ~0UL; auto ret = static_cast(ret_ptr); UInt64 result = *ret; @@ -126,31 +147,27 @@ IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { IMPORT_C UInt64 IoTellFile(_Input Ref desc) { auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), static_cast(desc)); - - if (!ret_ptr) { - return ~0UL; - } - + if (!ret_ptr) return ~0UL; auto ret = static_cast(ret_ptr); return *ret; } IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { + constexpr SizeT BUF_SZ = 1024; + char buf[BUF_SZ]; + va_list args; va_start(args, fmt); + int needed = vsnprintf(buf, BUF_SZ, fmt, args); + va_end(args); - auto ret_ptr = libsys_syscall_arg_4( - SYSCALL_HASH("PrintOut"), + // if truncated, `needed` >= BUF_SZ; we still send truncated buffer + auto ret_ptr = libsys_syscall_arg_3( + SYSCALL_HASH("PrintOut"), static_cast(desc), - Detail::safe_void_cast(fmt), - static_cast(&args)); + Detail::safe_void_cast(buf)); - va_end(args); - - if (!ret_ptr) { - return -1; - } - + if (!ret_ptr) return -1; auto ret = static_cast(ret_ptr); return *ret; } -- cgit v1.2.3 From 73e85b95355f56081a8a83e29b4ba6005bf163b2 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sun, 10 Aug 2025 23:00:00 +0200 Subject: feat(libSystem): improved 'PrintOut' to use 'StrFmt' instead of stdc's string format. Signed-off-by: Amlal --- dev/libSystem/SystemKit/System.h | 8 +- dev/libSystem/src/System.cc | 173 +++++++++++++++++++++++++++++++++++++ dev/libSystem/src/SystemCalls.cc | 180 --------------------------------------- 3 files changed, 177 insertions(+), 184 deletions(-) create mode 100644 dev/libSystem/src/System.cc delete mode 100644 dev/libSystem/src/SystemCalls.cc (limited to 'dev/libSystem') diff --git a/dev/libSystem/SystemKit/System.h b/dev/libSystem/SystemKit/System.h index 421868ae..f46fe523 100644 --- a/dev/libSystem/SystemKit/System.h +++ b/dev/libSystem/SystemKit/System.h @@ -12,6 +12,10 @@ Purpose: System Call Interface. #include +/// @brief TTY device path. +#define kPrintDevicePath "/devices/tty{}" +#define kCDDevicePath "/devices/dvd{}" + // ------------------------------------------------------------------------------------------ // /// @brief Types API. // ------------------------------------------------------------------------------------------ // @@ -309,8 +313,6 @@ IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); // CD-ROM API. // ------------------------------------------------------------------------------------------ // -#define kCDDevicePath "/devices/dvd{}" - IMPORT_C IORef CdOpenTray(Void); IMPORT_C SInt32 CdEjectDrive(_Input IORef cdrom); @@ -321,8 +323,6 @@ IMPORT_C SInt32 CdCloseTray(Void); // TTY API. // ------------------------------------------------------------------------------------------ // -#define kPrintDevicePath "/devices/tty{}" - IMPORT_C SInt32 PrintOut(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); IMPORT_C SInt32 PrintIn(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc new file mode 100644 index 00000000..3870ff18 --- /dev/null +++ b/dev/libSystem/src/System.cc @@ -0,0 +1,173 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include + +namespace Detail { +template +static VoidPtr safe_void_cast(const T* ptr) { + _rtl_assert(ptr, "safe void cast failed!"); + return static_cast(const_cast(ptr)); +} +} // namespace Detail + +IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { + if (!expr) { + PrintOut(nullptr, "Assertion failed: %s\r", origin); + libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); + } +} + +// memmove-style copy +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { + // handles overlap, prefers 64-bit word copies when aligned + if (!len || !dest || !src) return nullptr; + + auto s = static_cast(src); + auto d = static_cast(dest); + + if (d == s) return dest; + + // decide direction + if (d > s && d < s + len) { + const UInt8* rs = s + len; + UInt8* rd = d + len; + + // try 64-bit aligned backward copy + if (len >= sizeof(UInt64) && (reinterpret_cast(rs) % sizeof(UInt64) == 0) && + (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { + auto rsw = reinterpret_cast(rs); + auto rdw = reinterpret_cast(rd); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + rdw[-1 - static_cast(i)] = rsw[-1 - static_cast(i)]; + } + + SizeT rem = len % sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + rd[-1 - i] = rs[-1 - i]; + } + } else { + // byte-wise backward + for (SizeT i = 0; i < len; ++i) { + rd[-1 - i] = rs[-1 - i]; + } + } + } else { + // try 64-bit aligned forward copy + if (len >= sizeof(UInt64) && (reinterpret_cast(s) % sizeof(UInt64) == 0) && + (reinterpret_cast(d) % sizeof(UInt64) == 0)) { + auto sw = reinterpret_cast(s); + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = sw[i]; + } + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = s[offset + i]; + } + } else { + for (SizeT i = 0; i < len; ++i) { + d[i] = s[i]; + } + } + } + + return dest; +} + +IMPORT_C SInt64 MmStrLen(const Char* in) { + // strlen via pointer walk + if (!in) return 0; + const Char* p = in; + while (*p) ++p; + return static_cast(p - in); +} + +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { + if (!len || !dest) return nullptr; + + auto d = static_cast(dest); + + if (len >= sizeof(UInt64) && (reinterpret_cast(d) % sizeof(UInt64)) == 0) { + UInt64 pattern = static_cast(value); + pattern |= (pattern << 8); + pattern |= (pattern << 16); + pattern |= (pattern << 32); + + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = pattern; + } + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = value; + } + } else { + for (SizeT i = 0; i < len; ++i) d[i] = value; + } + + return dest; +} + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { + return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), + Detail::safe_void_cast(path), + Detail::safe_void_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast(desc)); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { + auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("IoSeekFile"), static_cast(desc), + reinterpret_cast(&off)); + + if (!ret_ptr) return ~0UL; + + auto ret = static_cast(ret_ptr); + UInt64 result = *ret; + MUST_PASS(result != ~0UL); + return result; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) { + auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), static_cast(desc)); + if (!ret_ptr) return ~0UL; + auto ret = static_cast(ret_ptr); + return *ret; +} + +IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) { + va_list args; + va_start(args, fmt); + + auto buf = StrFmt(fmt, args); + + va_end(args); + + // if truncated, `needed` >= kBufferSz; we still send truncated buffer + auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintOut"), static_cast(desc), + Detail::safe_void_cast(buf)); + + if (!ret_ptr) return -kErrorInvalidData; + + auto ret = static_cast(ret_ptr); + + return *ret; +} diff --git a/dev/libSystem/src/SystemCalls.cc b/dev/libSystem/src/SystemCalls.cc deleted file mode 100644 index 83569b6f..00000000 --- a/dev/libSystem/src/SystemCalls.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -namespace Detail { - template - inline VoidPtr safe_void_cast(const T* ptr) { - return const_cast(static_cast(ptr)); - } -} - -// memmove-style copy -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { - // handles overlap, prefers 64-bit word copies when aligned - if (!len || !dest || !src) return nullptr; - - auto s = static_cast(src); - auto d = static_cast(dest); - - if (d == s) return dest; - - // decide direction - if (d > s && d < s + len) { - const UInt8* rs = s + len; - UInt8* rd = d + len; - - // try 64-bit aligned backward copy - if (len >= sizeof(UInt64) && - (reinterpret_cast(rs) % sizeof(UInt64) == 0) && - (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { - - auto rsw = reinterpret_cast(rs); - auto rdw = reinterpret_cast(rd); - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - rdw[-1 - static_cast(i)] = rsw[-1 - static_cast(i)]; - } - - SizeT rem = len % sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - rd[-1 - i] = rs[-1 - i]; - } - } else { - // byte-wise backward - for (SizeT i = 0; i < len; ++i) { - rd[-1 - i] = rs[-1 - i]; - } - } - } else { - // try 64-bit aligned forward copy - if (len >= sizeof(UInt64) && - (reinterpret_cast(s) % sizeof(UInt64) == 0) && - (reinterpret_cast(d) % sizeof(UInt64) == 0)) { - - auto sw = reinterpret_cast(s); - auto dw = reinterpret_cast(d); - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - dw[i] = sw[i]; - } - - SizeT rem = len % sizeof(UInt64); - const SizeT offset = words * sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - d[offset + i] = s[offset + i]; - } - } else { - for (SizeT i = 0; i < len; ++i) { - d[i] = s[i]; - } - } - } - - return dest; -} - -IMPORT_C SInt64 MmStrLen(const Char* in) { - // strlen via pointer walk - if (!in) return 0; - const Char* p = in; - while (*p) ++p; - return static_cast(p - in); -} - -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { - if (!len || !dest) return nullptr; - - auto d = static_cast(dest); - - if (len >= sizeof(UInt64) && (reinterpret_cast(d) % sizeof(UInt64)) == 0) { - UInt64 pattern = static_cast(value); - pattern |= (pattern << 8); - pattern |= (pattern << 16); - pattern |= (pattern << 32); - - auto dw = reinterpret_cast(d); - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - dw[i] = pattern; - } - - SizeT rem = len % sizeof(UInt64); - const SizeT offset = words * sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - d[offset + i] = value; - } - } else { - for (SizeT i = 0; i < len; ++i) d[i] = value; - } - - return dest; -} - -IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return static_cast(libsys_syscall_arg_3( - SYSCALL_HASH("IoOpenFile"), - Detail::safe_void_cast(path), - Detail::safe_void_cast(drv_letter))); -} - -IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast(desc)); -} - -IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret_ptr = libsys_syscall_arg_3( - SYSCALL_HASH("IoSeekFile"), - static_cast(desc), - reinterpret_cast(&off)); - - if (!ret_ptr) return ~0UL; - - auto ret = static_cast(ret_ptr); - UInt64 result = *ret; - MUST_PASS(result != ~0UL); - return result; -} - -IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), - static_cast(desc)); - if (!ret_ptr) return ~0UL; - auto ret = static_cast(ret_ptr); - return *ret; -} - -IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { - constexpr SizeT BUF_SZ = 1024; - char buf[BUF_SZ]; - - va_list args; - va_start(args, fmt); - int needed = vsnprintf(buf, BUF_SZ, fmt, args); - va_end(args); - - // if truncated, `needed` >= BUF_SZ; we still send truncated buffer - auto ret_ptr = libsys_syscall_arg_3( - SYSCALL_HASH("PrintOut"), - static_cast(desc), - Detail::safe_void_cast(buf)); - - if (!ret_ptr) return -1; - auto ret = static_cast(ret_ptr); - return *ret; -} - -IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { - if (!expr) { - PrintOut(nullptr, "Assertion failed: %s\r", origin); - libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); - } -} -- cgit v1.2.3 From bb432453ab609ca7e8dc8e991775329d10a29e7b Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 13 Aug 2025 23:56:41 +0200 Subject: feat! Breaking changes in the DDK. Signed-off-by: Amlal --- dev/ddk/DDKKit/ddk.h | 74 ---------------------- dev/ddk/DDKKit/dev.h | 36 ----------- dev/ddk/DDKKit/io.h | 18 ------ dev/ddk/DDKKit/macros.h | 48 -------------- dev/ddk/DDKKit/net.h | 16 ----- dev/ddk/DDKKit/str.h | 17 ----- dev/ddk/DriverKit/ddk.h | 74 ++++++++++++++++++++++ dev/ddk/DriverKit/dev.h | 36 +++++++++++ dev/ddk/DriverKit/io.h | 18 ++++++ dev/ddk/DriverKit/macros.h | 48 ++++++++++++++ dev/ddk/DriverKit/net.h | 16 +++++ dev/ddk/DriverKit/str.h | 17 +++++ dev/ddk/docs/SPECIFICATION_DDK.md | 2 +- dev/ddk/src/ddk_abi_cxx.cc | 27 ++++++++ dev/ddk/src/ddk_alloc.c | 6 +- dev/ddk/src/ddk_dev.c | 8 +-- dev/ddk/src/ddk_io.c | 4 +- dev/ddk/src/ddk_kernel_call.c | 23 +++---- dev/ddk/src/ddk_kernel_call_dispatch.S | 4 +- dev/ddk/src/ddk_rt_cxx.cc | 25 -------- dev/ddk/src/ddk_str.c | 4 +- dev/ddk/src/ddk_ver.c | 4 +- dev/kernel/DmaKit/DmaPool.h | 1 - dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 4 +- dev/libSystem/docs/SPECIFICATION_SYSCALLS.md | 2 +- 25 files changed, 267 insertions(+), 265 deletions(-) delete mode 100644 dev/ddk/DDKKit/ddk.h delete mode 100644 dev/ddk/DDKKit/dev.h delete mode 100644 dev/ddk/DDKKit/io.h delete mode 100644 dev/ddk/DDKKit/macros.h delete mode 100644 dev/ddk/DDKKit/net.h delete mode 100644 dev/ddk/DDKKit/str.h create mode 100644 dev/ddk/DriverKit/ddk.h create mode 100644 dev/ddk/DriverKit/dev.h create mode 100644 dev/ddk/DriverKit/io.h create mode 100644 dev/ddk/DriverKit/macros.h create mode 100644 dev/ddk/DriverKit/net.h create mode 100644 dev/ddk/DriverKit/str.h create mode 100644 dev/ddk/src/ddk_abi_cxx.cc delete mode 100644 dev/ddk/src/ddk_rt_cxx.cc (limited to 'dev/libSystem') diff --git a/dev/ddk/DDKKit/ddk.h b/dev/ddk/DDKKit/ddk.h deleted file mode 100644 index 5a8929da..00000000 --- a/dev/ddk/DDKKit/ddk.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - FILE: ddk.h - PURPOSE: DDK Driver model base header. - -------------------------------------------- */ - -#pragma once - -#include - -struct DDK_STATUS_STRUCT; -struct DDK_OBJECT_MANIFEST; - -/// \brief Object handle manifest. -struct DDK_OBJECT_MANIFEST DDK_FINAL { - char* p_name; - int32_t p_kind; - void* p_object; -}; - -/// \brief DDK status ping structure. -struct DDK_STATUS_STRUCT DDK_FINAL { - int32_t s_action_id; - int32_t s_issuer_id; - int32_t s_group_id; - struct DDK_OBJECT_MANIFEST* s_object; -}; - -/// @brief Call Kernel procedure. -/// @param name the procedure name. -/// @param cnt number of elements in **dat** -/// @param dat data argument pointer. -/// @param sz sz of whole data argument pointer. -/// @return result of call -DDK_EXTERN void* ke_call(const char* name, int32_t cnt, void* dat, size_t sz); - -/// @brief add a system call. -/// @param slot system call slot id. -/// @param slotFn, syscall slot. -DDK_EXTERN void ke_set_syscall(const int32_t slot, void (*slotFn)(void* a0)); - -/// @brief Allocates an heap ptr. -/// @param sz size of the allocated struct/type. -/// @return the pointer allocated or **nil**. -DDK_EXTERN void* kalloc(size_t sz); - -/// @brief Frees an heap ptr. -/// @param pointer kernel pointer to free. -DDK_EXTERN void kfree(void* the_ptr); - -/// @brief Gets a Kernel object. -/// @param slot object id (can be 0) -/// @param name the property's name. -/// @return DDK_OBJECT_MANIFEST. -DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* name); - -/// @brief Set a Kernel object. -/// @param slot object id (can be 0) -/// @param name the property's name. -/// @param ddk_pr pointer to a object's DDK_OBJECT_MANIFEST. -/// @return returned object. -DDK_EXTERN void* ke_set_obj(const int32_t slot, const struct DDK_OBJECT_MANIFEST* ddk_pr); - -/// @brief The highest API version of the DDK. -DDK_EXTERN uint32_t kApiVersionHighest; - -/// @brief The lowest API version of the DDK. -DDK_EXTERN uint32_t kApiVersionLowest; - -/// @brief API version in BCD. -DDK_EXTERN uint32_t kApiVersion; diff --git a/dev/ddk/DDKKit/dev.h b/dev/ddk/DDKKit/dev.h deleted file mode 100644 index 59fb48b5..00000000 --- a/dev/ddk/DDKKit/dev.h +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - File: dev.h - Purpose: DDK device support. - -------------------------------------------- */ - -#pragma once - -#include - -struct _DDK_DEVICE; - -#define DDK_DEVICE_NAME_LEN (255) - -/// @brief Kernel Device driver. -typedef struct _DDK_DEVICE DDK_FINAL { - char d_name[DDK_DEVICE_NAME_LEN]; // the device name. Could be /./DEVICE_NAME/ - void* (*d_read)(void* arg, int len); // read from device. - void (*d_write)(void* arg, int len); - void (*d_wait)(void); // write to device. - struct _DDK_DEVICE* (*d_open)(const char* path); // open device. - void (*d_close)(struct _DDK_DEVICE* dev); // close device. - void (*d_seek)(struct _DDK_DEVICE* dev, size_t off); - size_t (*d_tell)(struct _DDK_DEVICE* dev); -} DDK_DEVICE, *DDK_DEVICE_PTR; - -/// @brief Open a new device from path. -/// @param path the device's path. -DDK_EXTERN DDK_DEVICE_PTR open(const char* path); - -/// @brief Close any device. -/// @param device valid device. -DDK_EXTERN BOOL close(DDK_DEVICE_PTR device); diff --git a/dev/ddk/DDKKit/io.h b/dev/ddk/DDKKit/io.h deleted file mode 100644 index 28396608..00000000 --- a/dev/ddk/DDKKit/io.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - Purpose: DDK Text I/O. - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief print character into UART. -DDK_EXTERN void kputc(const char ch); - -/// @brief print string to UART. -/// @param message string to transmit to UART. -DDK_EXTERN void kprint(const char* message); diff --git a/dev/ddk/DDKKit/macros.h b/dev/ddk/DDKKit/macros.h deleted file mode 100644 index 9b7b3d50..00000000 --- a/dev/ddk/DDKKit/macros.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ------------------------------------------- - - Copyright 2025 Amlal El Mahrouss. - - FILE: ddk.h - PURPOSE: DDK Driver model base header. - -------------------------------------------- */ - -#pragma once - -#include -#include - -#if defined(__cplusplus) -#define BOOL bool -#define YES true -#define NO false -#define DDK_EXTERN extern "C" __declspec(dllexport) -#define nil nullptr -#undef NULL -#define NULL 0 -#define DDK_FINAL final -#else -#define BOOL char -#define YES 1 -#define NO 0 -#define DDK_EXTERN extern __declspec(dllexport) -#define nil ((void*) 0) -#undef NULL -#define NULL ((void*) 0) -#define DDK_FINAL -#endif // defined(__cplusplus) - -#ifndef __DDK__ -#undef DDK_EXTERN -#if defined(__cplusplus) -#define DDK_EXTERN extern "C" __declspec(dllimport) -#else -#define DDK_EXTERN __declspec(dllimport) -#endif -#endif - -#define ATTRIBUTE(X) __attribute__((X)) - -#ifndef __NEOSKRNL__ -#error !!! Do not include header in EL0/Ring 3 mode !!! -#endif // __NEOSKRNL__ \ No newline at end of file diff --git a/dev/ddk/DDKKit/net.h b/dev/ddk/DDKKit/net.h deleted file mode 100644 index ea85dee7..00000000 --- a/dev/ddk/DDKKit/net.h +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - FILE: net.h - PURPOSE: Network model base header. - -------------------------------------------- */ - -#pragma once - -#include - -struct DDK_NET_MANIFEST; - -/// @brief IFS hooks to plug into the FileMgr. diff --git a/dev/ddk/DDKKit/str.h b/dev/ddk/DDKKit/str.h deleted file mode 100644 index fbf6506d..00000000 --- a/dev/ddk/DDKKit/str.h +++ /dev/null @@ -1,17 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - Purpose: DDK Strings. - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief DDK equivalent of POSIX's string.h -/// @file str.h - -DDK_EXTERN size_t kstrlen(const char* in); -DDK_EXTERN int kstrncpy(char* dst, const char* src, size_t len); diff --git a/dev/ddk/DriverKit/ddk.h b/dev/ddk/DriverKit/ddk.h new file mode 100644 index 00000000..254137f9 --- /dev/null +++ b/dev/ddk/DriverKit/ddk.h @@ -0,0 +1,74 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + +------------------------------------------- */ + +#pragma once + +#include + +struct DDK_STATUS_STRUCT; +struct DDK_OBJECT_MANIFEST; + +/// \brief Object handle manifest. +struct DDK_OBJECT_MANIFEST DDK_FINAL { + char* p_name; + int32_t p_kind; + void* p_object; +}; + +/// \brief DDK status ping structure. +struct DDK_STATUS_STRUCT DDK_FINAL { + int32_t s_action_id; + int32_t s_issuer_id; + int32_t s_group_id; + struct DDK_OBJECT_MANIFEST* s_object; +}; + +/// @brief Call Kernel procedure. +/// @param name the procedure name. +/// @param cnt number of elements in **dat** +/// @param dat data argument pointer. +/// @param sz sz of whole data argument pointer. +/// @return result of call +DDK_EXTERN void* ke_call_dispatch(const char* name, int32_t cnt, void* dat, size_t sz); + +/// @brief add a system call. +/// @param slot system call slot id. +/// @param slotFn, syscall slot. +DDK_EXTERN void ke_set_syscall(const int32_t slot, void (*slotFn)(void* a0)); + +/// @brief Allocates an heap ptr. +/// @param sz size of the allocated struct/type. +/// @return the pointer allocated or **nil**. +DDK_EXTERN void* kalloc(size_t sz); + +/// @brief Frees an heap ptr. +/// @param pointer kernel pointer to free. +DDK_EXTERN void kfree(void* the_ptr); + +/// @brief Gets a Kernel object. +/// @param slot object id (can be 0) +/// @param name the property's name. +/// @return DDK_OBJECT_MANIFEST. +DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* name); + +/// @brief Set a Kernel object. +/// @param slot object id (can be 0) +/// @param name the property's name. +/// @param ddk_pr pointer to a object's DDK_OBJECT_MANIFEST. +/// @return returned object. +DDK_EXTERN void* ke_set_obj(const int32_t slot, const struct DDK_OBJECT_MANIFEST* ddk_pr); + +/// @brief The highest API version of the DDK. +DDK_EXTERN uint32_t kApiVersionHighest; + +/// @brief The lowest API version of the DDK. +DDK_EXTERN uint32_t kApiVersionLowest; + +/// @brief API version in BCD. +DDK_EXTERN uint32_t kApiVersion; diff --git a/dev/ddk/DriverKit/dev.h b/dev/ddk/DriverKit/dev.h new file mode 100644 index 00000000..adb1c1d0 --- /dev/null +++ b/dev/ddk/DriverKit/dev.h @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss. + + File: dev.h + Purpose: DDK device support. + +------------------------------------------- */ + +#pragma once + +#include + +struct _DDK_DEVICE; + +#define DDK_DEVICE_NAME_LEN (255) + +/// @brief Kernel Device driver. +typedef struct _DDK_DEVICE DDK_FINAL { + char d_name[DDK_DEVICE_NAME_LEN]; // the device name. Could be /./DEVICE_NAME/ + void* (*d_read)(void* arg, int len); // read from device. + void (*d_write)(void* arg, int len); + void (*d_wait)(void); // write to device. + struct _DDK_DEVICE* (*d_open)(const char* path); // open device. + void (*d_close)(struct _DDK_DEVICE* dev); // close device. + void (*d_seek)(struct _DDK_DEVICE* dev, size_t off); + size_t (*d_tell)(struct _DDK_DEVICE* dev); +} DDK_DEVICE, *DDK_DEVICE_PTR; + +/// @brief Open a new device from path. +/// @param path the device's path. +DDK_EXTERN DDK_DEVICE_PTR open(const char* path); + +/// @brief Close any device. +/// @param device valid device. +DDK_EXTERN BOOL close(DDK_DEVICE_PTR device); diff --git a/dev/ddk/DriverKit/io.h b/dev/ddk/DriverKit/io.h new file mode 100644 index 00000000..805696e6 --- /dev/null +++ b/dev/ddk/DriverKit/io.h @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss. + + Purpose: DDK Text I/O. + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief print character into UART. +DDK_EXTERN void kputc(const char ch); + +/// @brief print string to UART. +/// @param message string to transmit to UART. +DDK_EXTERN void kprint(const char* message); diff --git a/dev/ddk/DriverKit/macros.h b/dev/ddk/DriverKit/macros.h new file mode 100644 index 00000000..9b7b3d50 --- /dev/null +++ b/dev/ddk/DriverKit/macros.h @@ -0,0 +1,48 @@ +/* ------------------------------------------- + + Copyright 2025 Amlal El Mahrouss. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + +------------------------------------------- */ + +#pragma once + +#include +#include + +#if defined(__cplusplus) +#define BOOL bool +#define YES true +#define NO false +#define DDK_EXTERN extern "C" __declspec(dllexport) +#define nil nullptr +#undef NULL +#define NULL 0 +#define DDK_FINAL final +#else +#define BOOL char +#define YES 1 +#define NO 0 +#define DDK_EXTERN extern __declspec(dllexport) +#define nil ((void*) 0) +#undef NULL +#define NULL ((void*) 0) +#define DDK_FINAL +#endif // defined(__cplusplus) + +#ifndef __DDK__ +#undef DDK_EXTERN +#if defined(__cplusplus) +#define DDK_EXTERN extern "C" __declspec(dllimport) +#else +#define DDK_EXTERN __declspec(dllimport) +#endif +#endif + +#define ATTRIBUTE(X) __attribute__((X)) + +#ifndef __NEOSKRNL__ +#error !!! Do not include header in EL0/Ring 3 mode !!! +#endif // __NEOSKRNL__ \ No newline at end of file diff --git a/dev/ddk/DriverKit/net.h b/dev/ddk/DriverKit/net.h new file mode 100644 index 00000000..63f89367 --- /dev/null +++ b/dev/ddk/DriverKit/net.h @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss. + + FILE: net.h + PURPOSE: Network model base header. + +------------------------------------------- */ + +#pragma once + +#include + +struct DDK_NET_MANIFEST; + +/// @brief IFS hooks to plug into the FileMgr. diff --git a/dev/ddk/DriverKit/str.h b/dev/ddk/DriverKit/str.h new file mode 100644 index 00000000..b2c0ce72 --- /dev/null +++ b/dev/ddk/DriverKit/str.h @@ -0,0 +1,17 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss. + + Purpose: DDK Strings. + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief DDK equivalent of POSIX's string.h +/// @file str.h + +DDK_EXTERN size_t kstrlen(const char* in); +DDK_EXTERN int kstrncpy(char* dst, const char* src, size_t len); diff --git a/dev/ddk/docs/SPECIFICATION_DDK.md b/dev/ddk/docs/SPECIFICATION_DDK.md index 57710d1f..d7d333d3 100644 --- a/dev/ddk/docs/SPECIFICATION_DDK.md +++ b/dev/ddk/docs/SPECIFICATION_DDK.md @@ -5,7 +5,7 @@ =================================== - Programming Language: C/C++ -- Build System: Make/BTB +- Build System: Make/NeBuild - Purpose: Driver Tool Kit, which you link against ddk.sys =================================== diff --git a/dev/ddk/src/ddk_abi_cxx.cc b/dev/ddk/src/ddk_abi_cxx.cc new file mode 100644 index 00000000..fc590c0e --- /dev/null +++ b/dev/ddk/src/ddk_abi_cxx.cc @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + DDK + Copyright Amlal El Mahrouss. + + Author: Amlal El Mahrouss + Purpose: DDK C++ ABI. + +------------------------------------------- */ + +#include + +void* operator new(size_t sz) { + return ::kalloc(sz); +} + +void operator delete(void* ptr) { + ::kfree(ptr); +} + +void* operator new[](size_t sz) { + return ::kalloc(sz); +} + +void operator delete[](void* ptr) { + ::kfree(ptr); +} diff --git a/dev/ddk/src/ddk_alloc.c b/dev/ddk/src/ddk_alloc.c index 0b428b15..08527f4d 100644 --- a/dev/ddk/src/ddk_alloc.c +++ b/dev/ddk/src/ddk_alloc.c @@ -6,7 +6,7 @@ ------------------------------------------- */ -#include +#include /** \brief Allocates a new heap on the Kernel's side. @@ -16,7 +16,7 @@ DDK_EXTERN void* kalloc(size_t sz) { if (!sz) ++sz; - void* ptr = ke_call("mm_alloc_ptr", 1, &sz, sizeof(size_t)); + void* ptr = ke_call_dispatch("mm_alloc_ptr", 1, &sz, sizeof(size_t)); return ptr; } @@ -28,5 +28,5 @@ DDK_EXTERN void* kalloc(size_t sz) { DDK_EXTERN void kfree(void* ptr) { if (!ptr) return; - ke_call("mm_free_ptr", 1, ptr, 0); + ke_call_dispatch("mm_free_ptr", 1, ptr, 0); } diff --git a/dev/ddk/src/ddk_dev.c b/dev/ddk/src/ddk_dev.c index 4cd7dcdd..32ec2442 100644 --- a/dev/ddk/src/ddk_dev.c +++ b/dev/ddk/src/ddk_dev.c @@ -6,14 +6,14 @@ ------------------------------------------- */ -#include -#include +#include +#include /// @brief Open a new binary device from path. DDK_EXTERN DDK_DEVICE_PTR open(const char* devicePath) { if (!devicePath) return nil; - return ke_call("dk_open_dev", 1, (void*) devicePath, kstrlen(devicePath)); + return ke_call_dispatch("dk_open_dev", 1, (void*) devicePath, kstrlen(devicePath)); } /// @brief Close any device. @@ -21,6 +21,6 @@ DDK_EXTERN DDK_DEVICE_PTR open(const char* devicePath) { DDK_EXTERN BOOL close(DDK_DEVICE_PTR device) { if (!device) return NO; - ke_call("dk_close_dev", 1, device, sizeof(DDK_DEVICE)); + ke_call_dispatch("dk_close_dev", 1, device, sizeof(DDK_DEVICE)); return YES; } diff --git a/dev/ddk/src/ddk_io.c b/dev/ddk/src/ddk_io.c index ba6d4e55..c6cdd457 100644 --- a/dev/ddk/src/ddk_io.c +++ b/dev/ddk/src/ddk_io.c @@ -6,14 +6,14 @@ ------------------------------------------- */ -#include +#include DDK_EXTERN void kputc(const char ch) { char assembled[2] = {0}; assembled[0] = ch; assembled[1] = 0; - ke_call("ke_put_string", 1, assembled, 1); + ke_call_dispatch("ke_put_string", 1, assembled, 1); } /// @brief print string to UART. diff --git a/dev/ddk/src/ddk_kernel_call.c b/dev/ddk/src/ddk_kernel_call.c index 10f31e18..95d2e577 100644 --- a/dev/ddk/src/ddk_kernel_call.c +++ b/dev/ddk/src/ddk_kernel_call.c @@ -1,36 +1,37 @@ /* ------------------------------------------- + DDK Copyright Amlal El Mahrouss. - Purpose: DDK Kernel call. + Author: Amlal El Mahrouss + Purpose: DDK kernel dispatch system. ------------------------------------------- */ -#include +#include #include /// @brief this is an internal call, do not use it. -DDK_EXTERN ATTRIBUTE(naked) void* ke_call_dispatch(const char* name, int32_t cnt, void* data, +DDK_EXTERN ATTRIBUTE(naked) void* __ke_call_dispatch(const char* name, int32_t cnt, void* data, size_t sz); -/// @brief Interupt Kernel and call it's RPC. +/// @brief Interrupt Kernel and call it's RPC. /// @param KernelRpcName RPC name /// @param cnt number of elements in **data** pointer. /// @param data data pointer. /// @param sz The size of the whole data pointer. /// @retval void* Kernel call was successful. /// @retval nil Kernel call failed, call KernelLastError(void) -DDK_EXTERN void* ke_call(const char* name, int32_t cnt, void* data, size_t sz) { - if (!name || *name == 0 || cnt == 0) return nil; - - return ke_call_dispatch(name, cnt, data, sz); +DDK_EXTERN void* ke_call_dispatch(const char* name, int32_t cnt, void* data, size_t sz) { + if (name == nil || *name == 0 || data == nil || cnt == 0) return nil; + return __ke_call_dispatch(name, cnt, data, sz); } /// @brief Add system call. /// @param slot system call slot /// @param slotFn, syscall slot. DDK_EXTERN void ke_set_syscall(const int slot, void (*slotFn)(void* a0)) { - ke_call("ke_set_syscall", slot, slotFn, 1); + ke_call_dispatch("ke_set_syscall", slot, slotFn, 1); } /// @brief Get a Kernel object. @@ -39,7 +40,7 @@ DDK_EXTERN void ke_set_syscall(const int slot, void (*slotFn)(void* a0)) { /// @return Object manifest. DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* name) { struct DDK_OBJECT_MANIFEST* manifest = - (struct DDK_OBJECT_MANIFEST*) ke_call("cfkit_get_kobj", slot, (void*) name, 1); + (struct DDK_OBJECT_MANIFEST*) ke_call_dispatch("cfkit_get_kobj", slot, (void*) name, 1); if (!manifest) return nil; @@ -52,5 +53,5 @@ DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* na /// @param ddk_pr pointer to a object's DDK_OBJECT_MANIFEST. /// @return property's object. DDK_EXTERN void* ke_set_obj(const int slot, const struct DDK_OBJECT_MANIFEST* ddk_pr) { - return ke_call("cfkit_set_kobj", slot, (void*) ddk_pr, 1); + return ke_call_dispatch("cfkit_set_kobj", slot, (void*) ddk_pr, 1); } diff --git a/dev/ddk/src/ddk_kernel_call_dispatch.S b/dev/ddk/src/ddk_kernel_call_dispatch.S index 9b32d0c2..c66d9d49 100644 --- a/dev/ddk/src/ddk_kernel_call_dispatch.S +++ b/dev/ddk/src/ddk_kernel_call_dispatch.S @@ -3,7 +3,7 @@ compiler: gnu */ -.globl ke_call_dispatch +.globl __ke_call_dispatch .text @@ -13,7 +13,7 @@ #if defined(__DDK_AMD64__) /* args rcx, rdx, r8, r9 */ -ke_call_dispatch: +__ke_call_dispatch: int $0x33 ret diff --git a/dev/ddk/src/ddk_rt_cxx.cc b/dev/ddk/src/ddk_rt_cxx.cc deleted file mode 100644 index 3d57e2b9..00000000 --- a/dev/ddk/src/ddk_rt_cxx.cc +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss. - - Purpose: DDK C++ runtime. - -------------------------------------------- */ - -#include - -void* operator new(size_t sz) { - return ::kalloc(sz); -} - -void operator delete(void* ptr) { - ::kfree(ptr); -} - -void* operator new[](size_t sz) { - return ::kalloc(sz); -} - -void operator delete[](void* ptr) { - ::kfree(ptr); -} diff --git a/dev/ddk/src/ddk_str.c b/dev/ddk/src/ddk_str.c index d50a5d03..514cddc7 100644 --- a/dev/ddk/src/ddk_str.c +++ b/dev/ddk/src/ddk_str.c @@ -2,11 +2,11 @@ Copyright Amlal El Mahrouss. - Purpose: DDK Strings. + Purpose: DDK String API. ------------------------------------------- */ -#include +#include DDK_EXTERN size_t kstrlen(const char* in) { if (in == nil) return 0; diff --git a/dev/ddk/src/ddk_ver.c b/dev/ddk/src/ddk_ver.c index 41c6c612..9be3134e 100644 --- a/dev/ddk/src/ddk_ver.c +++ b/dev/ddk/src/ddk_ver.c @@ -2,11 +2,11 @@ Copyright Amlal El Mahrouss. - Purpose: DDK version symbols. + Purpose: DDK version system. ------------------------------------------- */ -#include +#include #ifndef kDDKVersionHighest #define kDDKVersionHighest 1 diff --git a/dev/kernel/DmaKit/DmaPool.h b/dev/kernel/DmaKit/DmaPool.h index db12eb25..99f43725 100644 --- a/dev/kernel/DmaKit/DmaPool.h +++ b/dev/kernel/DmaKit/DmaPool.h @@ -29,7 +29,6 @@ #define kNeDMABestAlign (8) #endif - namespace Kernel { /// @brief DMA pool base pointer, here we're sure that AHCI or whatever tricky standard sees it. inline UInt8* kDmaPoolPtr = (UInt8*) kNeDMAPoolStart; diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 4a667549..64f146f3 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -32,10 +32,9 @@ #include #include -/// @note: _hal_switch_context is internal - /////////////////////////////////////////////////////////////////////////////////////// +/// @note: _hal_switch_context is internal. /// @brief The **HAL** namespace. /////////////////////////////////////////////////////////////////////////////////////// @@ -70,6 +69,7 @@ struct HAL_APIC_MADT final SDT_OBJECT { UInt8 List[1]; // Records List }; +/// @brief Local APIC Descriptor Table. struct LAPIC final { UInt8 Type; UInt8 Length; diff --git a/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md index b4b11c8c..89f61498 100644 --- a/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md +++ b/dev/libSystem/docs/SPECIFICATION_SYSCALLS.md @@ -3,7 +3,7 @@ =================================== - **Programming Language**: C / C++ -- **Build System**: Make / BTB (Build the Build) +- **Build System**: Make / NeBuild - **Purpose**: System Call Interface (SCI) for NeKernel =================================== -- cgit v1.2.3