diff options
97 files changed, 565 insertions, 457 deletions
diff --git a/.clang-format b/.clang-format index 3943f553..f9c1b5af 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,6 @@ +--- BasedOnStyle: Google +Language: Cpp IndentWidth: 2 TabWidth: 2 UseTab: Never diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..ada6f758 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ +# <Title of PR> + +<Describe briefly your PR here.> + +## Rationale: + +<Describe the rationale here> + +## Process: + +<Describe your process here> + +## Results: + +<Describe the results here> + +## Additionals: + + + @@ -1,18 +1,15 @@ - <!-- Read Me of NeKernel --> - +# 🍯 The NeKernel -<div align="center"> - <h1> - <b>The NeKernel System.</b> - </h1> - <p> - <a href="https://github.com/ne-foss-org/nekernel/actions/workflows/boot-ahci-dev.yml/badge.svg"><img src="https://github.com/ne-foss-org/nekernel/actions/workflows/boot-ahci-dev.yml/badge.svg" alt="CI"></a> - <a href="https://github.com/ne-foss-org/nekernel/actions/workflows/kernel-ahci-dev.yml/badge.svg"><img src="https://github.com/ne-foss-org/nekernel/actions/workflows/kernel-ahci-dev.yml/badge.svg" alt="CI"></a> - <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg" alt="License"></a> - </p> -</div> +<a href="https://github.com/ne-foss-org/nekernel/actions/workflows/boot-ahci-dev.yml/badge.svg"><img src="https://github.com/ne-foss-org/nekernel/actions/workflows/boot-ahci-dev.yml/badge.svg" alt="CI"></a> +<a href="https://github.com/ne-foss-org/nekernel/actions/workflows/kernel-ahci-dev.yml/badge.svg"><img src="https://github.com/ne-foss-org/nekernel/actions/workflows/kernel-ahci-dev.yml/badge.svg" alt="CI"></a> +<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg" alt="License"></a> + + +## About: + +The Base OS of the NeSystem designed for portability and scalability. A hybrid system written in modern C++ for backend systems. ## Getting Started: @@ -35,17 +32,11 @@ git clone -j8 https://github.com/ne-foss-org/nekernel.git cd nekernel ./scripts/setup_x64_project.sh ./scripts/modules_ahci_x64.sh -./scripts/debug_ahci_x64.sh # For debug generic AHCI target (QEMU, USB) +./scripts/debug_ahci_x64.sh # For debug generic AHCI target (QEMU, UDF) ``` --- -## Love our work? - -Give us a star on GitHub! - - - ## Community: Join our [Discord](https://discord.gg/uD76Qweght), we're quite active and open for contributors! @@ -2,9 +2,6 @@ THIS_PATH="$(realpath "$0")" THIS_DIR="$(dirname "$THIS_PATH")" - -FILE_LIST="$(find "$THIS_DIR" | grep -E ".*(\.cc|\.c|\.h|\.inl)$")" - -echo -e "Files found to format = \n\"\"\"\n$FILE_LIST\n\"\"\"" +FILE_LIST="$(find "$THIS_DIR" | grep -E ".*(\.cpp|\.cc|\.c|\.h|\.inl)$")" clang-format --verbose -i --style=file $FILE_LIST diff --git a/public/frameworks/KernelTest.fwrk/headers/TestCase.h b/public/frameworks/KernelTest.fwrk/headers/TestCase.h index 0a6208a8..2090f84e 100644 --- a/public/frameworks/KernelTest.fwrk/headers/TestCase.h +++ b/public/frameworks/KernelTest.fwrk/headers/TestCase.h @@ -40,7 +40,9 @@ KT_MUST_PASS(ret, ret, true); \ } \ } \ - inline const Char* KTTestCase##NAME::ToString() { return #FN; } + inline const Char* KTTestCase##NAME::ToString() { \ + return #FN; \ + } KT_DECL_TEST(AlwaysBreak, []() -> bool { KT_MUST_PASS("AlwaysBreak", YES, NO); diff --git a/public/tools/diutil/vendor/Dialogs.h b/public/tools/diutil/vendor/Dialogs.h index 28cd8fa9..d1bbd7a2 100644 --- a/public/tools/diutil/vendor/Dialogs.h +++ b/public/tools/diutil/vendor/Dialogs.h @@ -176,7 +176,7 @@ namespace internal { #elif __EMSCRIPTEN__ void start(int exit_code); #else - void start_process(std::vector<std::string> const& command); + void start_process(std::vector<std::string> const& command); #endif ~executor(); @@ -491,10 +491,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)) { @@ -541,7 +541,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); @@ -605,7 +605,7 @@ inline std::string path::home() { if (size_max != -1) len = size_t(size_max); #endif std::vector<char> 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 "/"; @@ -718,7 +718,7 @@ inline void internal::executor::start_process(std::vector<std::string> 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); @@ -754,7 +754,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); @@ -765,7 +765,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 @@ -783,8 +783,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 @@ -880,11 +879,11 @@ inline std::vector<std::string> 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 } @@ -1126,9 +1125,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) { @@ -1237,7 +1236,7 @@ inline std::vector<std::string> internal::file_dialog::vector_result() { return m_vector_result; #else std::vector<std::string> ret; - auto result = m_async->result(); + auto result = m_async->result(); for (;;) { // Split result along newline characters auto i = result.find('\n'); @@ -1570,7 +1569,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) { @@ -1657,7 +1656,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/src/boot/BootKit/BootKit.h b/src/boot/BootKit/BootKit.h index 675049d8..1cdf2032 100644 --- a/src/boot/BootKit/BootKit.h +++ b/src/boot/BootKit/BootKit.h @@ -291,16 +291,16 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { CopyMem(gpt_part->Signature, reinterpret_cast<VoidPtr>(const_cast<Char*>(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; @@ -310,10 +310,10 @@ inline Boolean BDiskFormatFactory<BootDev>::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/src/boot/modules/BootNet/BootNet.cpp b/src/boot/modules/BootNet/BootNet.cpp index e4cbd073..e31d9460 100644 --- a/src/boot/modules/BootNet/BootNet.cpp +++ b/src/boot/modules/BootNet/BootNet.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> #include <FirmwareKit/EFI/API.h> diff --git a/src/boot/modules/SysChk/SysChk.cpp b/src/boot/modules/SysChk/SysChk.cpp index 336f4814..1a93d748 100644 --- a/src/boot/modules/SysChk/SysChk.cpp +++ b/src/boot/modules/SysChk/SysChk.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> #include <BootKit/HW/SATA.h> diff --git a/src/boot/src/BootFileReader.cpp b/src/boot/src/BootFileReader.cpp index 7f6da47e..0ca48cd3 100644 --- a/src/boot/src/BootFileReader.cpp +++ b/src/boot/src/BootFileReader.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/Platform.h> #include <BootKit/Protocol.h> diff --git a/src/boot/src/BootSupport.cpp b/src/boot/src/BootSupport.cpp index 232ac965..2680e439 100644 --- a/src/boot/src/BootSupport.cpp +++ b/src/boot/src/BootSupport.cpp @@ -16,13 +16,13 @@ #define kAtExitMaxDestructors (128U) typedef struct atexit_func_entry { - void(*destructor_func)(); + void (*destructor_func)(); } atexit_func_entry_t; typedef long long uarch_t; atexit_func_entry_t __atexit_funcs[kAtExitMaxDestructors]; -uarch_t __atexit_func_count; +uarch_t __atexit_func_count; /// @note This function is a stub, not implemented by the bootloader as of right now. (AMLALE) EXTERN_C int atexit(void (*f)()) { diff --git a/src/boot/src/BootThread.cpp b/src/boot/src/BootThread.cpp index 19e87bae..16e368c3 100644 --- a/src/boot/src/BootThread.cpp +++ b/src/boot/src/BootThread.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> #include <BootKit/Support.h> diff --git a/src/boot/src/HEL/AMD64/BootEFI.cpp b/src/boot/src/HEL/AMD64/BootEFI.cpp index ffcf394c..4d004e54 100644 --- a/src/boot/src/HEL/AMD64/BootEFI.cpp +++ b/src/boot/src/HEL/AMD64/BootEFI.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> #include <FirmwareKit/EFI.h> diff --git a/src/boot/src/HEL/AMD64/BootPlatform.cpp b/src/boot/src/HEL/AMD64/BootPlatform.cpp index 85c8da57..dc52c5c1 100644 --- a/src/boot/src/HEL/AMD64/BootPlatform.cpp +++ b/src/boot/src/HEL/AMD64/BootPlatform.cpp @@ -3,25 +3,35 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/Platform.h> #include <BootKit/Protocol.h> #ifdef __BOOTZ_STANDALONE__ -/// @brief These functions are used for x64 backends only. Do not try to use the same name for other backends, use their ISA specific conventions. +/// @brief These functions are used for x64 backends only. Do not try to use the same name for other +/// backends, use their ISA specific conventions. using namespace Boot; -EXTERN_C void rt_halt() { asm volatile("hlt"); } +EXTERN_C void rt_halt() { + asm volatile("hlt"); +} -EXTERN_C void rt_cli() { asm volatile("cli"); } +EXTERN_C void rt_cli() { + asm volatile("cli"); +} -EXTERN_C void rt_sti() { asm volatile("sti"); } +EXTERN_C void rt_sti() { + asm volatile("sti"); +} -EXTERN_C void rt_cld() { asm volatile("cld"); } +EXTERN_C void rt_cld() { + asm volatile("cld"); +} -EXTERN_C void rt_std() { asm volatile("std"); } +EXTERN_C void rt_std() { + asm volatile("std"); +} #endif // __BOOTZ_STANDALONE__ diff --git a/src/boot/src/HEL/ARM64/BootEFI.cpp b/src/boot/src/HEL/ARM64/BootEFI.cpp index 9c40c9c3..936f5dfb 100644 --- a/src/boot/src/HEL/ARM64/BootEFI.cpp +++ b/src/boot/src/HEL/ARM64/BootEFI.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> #include <FirmwareKit/EFI.h> diff --git a/src/boot/src/HEL/ARM64/BootPlatform.cpp b/src/boot/src/HEL/ARM64/BootPlatform.cpp index 142ea621..238401fd 100644 --- a/src/boot/src/HEL/ARM64/BootPlatform.cpp +++ b/src/boot/src/HEL/ARM64/BootPlatform.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/Platform.h> #include <BootKit/Protocol.h> @@ -12,7 +11,9 @@ using namespace Boot; -EXTERN_C void rt_halt() { while (Yes); } +EXTERN_C void rt_halt() { + while (Yes); +} EXTERN_C void rt_cli() {} diff --git a/src/boot/src/New+Delete.cpp b/src/boot/src/New+Delete.cpp index 4d7592be..70ab1dcd 100644 --- a/src/boot/src/New+Delete.cpp +++ b/src/boot/src/New+Delete.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <BootKit/BootKit.h> #include <BootKit/Platform.h> #include <BootKit/Protocol.h> @@ -16,7 +15,7 @@ /// @return void* operator new(size_t sz) { if (sz == 0) ++sz; - + void* buf = nullptr; while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk); @@ -29,7 +28,7 @@ void* operator new(size_t sz) { /// @return void* operator new[](size_t sz) { if (sz == 0) ++sz; - + void* buf = nullptr; BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf); diff --git a/src/boot/src/boot_rsrc.rsrc b/src/boot/src/boot_rsrc.rsrc index e875fa24..b0c86e51 100644 --- a/src/boot/src/boot_rsrc.rsrc +++ b/src/boot/src/boot_rsrc.rsrc @@ -12,7 +12,7 @@ BEGIN VALUE "FileDescription", "NeKernel OS Loader." VALUE "FileVersion", BOOTLOADER_VERSION VALUE "InternalName", "bootz" - VALUE "LegalCopyright", "Copyright (C) 2024-2025, Amlal El Mahrouss licensed under the Apache 2.0 license." + VALUE "LegalCopyright", "Copyright (C) 2024-2026, Amlal El Mahrouss licensed under the Apache 2.0 license." VALUE "OriginalFilename", "ne_bootz" VALUE "ProductName", "bootz" VALUE "ProductVersion", BOOTLOADER_VERSION diff --git a/src/kernel/FSKit/Ext2+IFS.h b/src/kernel/FSKit/Ext2+IFS.h index 51767677..8c904710 100644 --- a/src/kernel/FSKit/Ext2+IFS.h +++ b/src/kernel/FSKit/Ext2+IFS.h @@ -32,7 +32,7 @@ class Ext2Context final { } } - Ext2Context(const Ext2Context&) = delete; + Ext2Context(const Ext2Context&) = delete; Ext2Context& operator=(const Ext2Context&) = delete; Ext2Context(Ext2Context&& other) : drive(other.drive), superblock(other.superblock) { diff --git a/src/kernel/FSKit/OpenHeFS.h b/src/kernel/FSKit/OpenHeFS.h index 9983f6ff..a642c299 100644 --- a/src/kernel/FSKit/OpenHeFS.h +++ b/src/kernel/FSKit/OpenHeFS.h @@ -267,7 +267,7 @@ inline UInt32 hefs_hour_get(ATime raw_atime) { /// @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) { - return (raw_atime) &0xFF; + return (raw_atime) & 0xFF; } inline constexpr UInt32 kOpenHeFSBaseYear = 1970; @@ -387,10 +387,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/src/kernel/FirmwareKit/EFI/EFI.h b/src/kernel/FirmwareKit/EFI/EFI.h index e472a0f5..4e256403 100644 --- a/src/kernel/FirmwareKit/EFI/EFI.h +++ b/src/kernel/FirmwareKit/EFI/EFI.h @@ -56,7 +56,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; @@ -238,64 +238,42 @@ 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); @@ -350,17 +328,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; @@ -505,10 +483,8 @@ 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 */ #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001 @@ -606,7 +582,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); @@ -664,7 +640,7 @@ typedef struct EfiSystemTable { struct { EFI_GUID VendorGUID; VoidPtr VendorTable; - } * ConfigurationTable; + }* ConfigurationTable; } EfiSystemTable; #define kEfiOk 0 @@ -725,10 +701,8 @@ 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 #define PROCESSOR_ENABLED_BIT 0x00000002 @@ -824,10 +798,8 @@ 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 { /// @brief Structure size. @@ -895,8 +867,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/src/kernel/HALKit/AMD64/CxxAbi.cpp b/src/kernel/HALKit/AMD64/CxxAbi.cpp index 50b6ccf2..c2487f85 100644 --- a/src/kernel/HALKit/AMD64/CxxAbi.cpp +++ b/src/kernel/HALKit/AMD64/CxxAbi.cpp @@ -11,7 +11,7 @@ #define kAtExitMaxDestructors (128U) atexit_func_entry_t __atexit_funcs[kAtExitMaxDestructors]; -uarch_t __atexit_func_count; +uarch_t __atexit_func_count; /// @brief dynamic shared object Handle. Kernel::UIntPtr __dso_handle; diff --git a/src/kernel/HALKit/AMD64/HalKernelMain.cpp b/src/kernel/HALKit/AMD64/HalKernelMain.cpp index 7468b76d..fabeb077 100644 --- a/src/kernel/HALKit/AMD64/HalKernelMain.cpp +++ b/src/kernel/HALKit/AMD64/HalKernelMain.cpp @@ -133,6 +133,8 @@ EXTERN_C Kernel::Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_h return kEfiFail; } +EXTERN_C BOOL rtl_init_nic_rtl8139(); + EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -156,11 +158,17 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { PEFLoader ldr("/system/init.out"); - if (ldr.IsLoaded()) rtl_create_user_process(ldr, UserProcess::ExecutableKind::kExecutableKind); - else ke_panic(RUNTIME_CHECK_PROCESS, "RuntimeCheck: Invalid Process Data!"); - + if (ldr.IsLoaded()) + rtl_create_user_process(ldr, UserProcess::ExecutableKind::kExecutableKind); + else + ke_panic(RUNTIME_CHECK_PROCESS, "RuntimeCheck: Invalid Process Data!"); + UserProcessScheduler::The().SwitchTeam(kMidUserTeam); +#ifdef __HALKIT_INCLUDES_BNID__ + rtl_init_nic_rtl8139(); +#endif + while (YES); } #endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ diff --git a/src/kernel/HALKit/AMD64/HalKernelPanic.cpp b/src/kernel/HALKit/AMD64/HalKernelPanic.cpp index d9afa204..a5f0b8bc 100644 --- a/src/kernel/HALKit/AMD64/HalKernelPanic.cpp +++ b/src/kernel/HALKit/AMD64/HalKernelPanic.cpp @@ -45,19 +45,18 @@ Void RecoveryFactory::Recover() { HAL::rt_cli(); HAL::rt_halt(); } - + alreadyDumped = YES; - - HeFileSystemMgr mgr; - auto node = mgr.Open("/system/dump.dmp", "wb"); + HeFileSystemMgr mgr; + auto node = mgr.Open("/system/dump.dmp", "wb"); if (node && hal_read_cr2()) mgr.Write(node, hal_read_cr2(), 0, 0x100); if (node) mm_free_ptr(node); - + node = nullptr; #endif - + while (YES) { HAL::rt_cli(); HAL::rt_halt(); diff --git a/src/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cpp b/src/kernel/HALKit/AMD64/Network/Generic+Basic+BNID.cpp index aacda36c..4c1d0f1f 100644 --- a/src/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cpp +++ b/src/kernel/HALKit/AMD64/Network/Generic+Basic+BNID.cpp @@ -5,66 +5,82 @@ #include <DmaKit/DmaPool.h> #include <HALKit/AMD64/Processor.h> +#include <KernelKit/PCI/Iterator.h> #include <modules/ACPI/ACPIFactoryInterface.h> +/// @note BNID (RTL8139' Basic Network Interface) driver + +#define kNetDevID (0x8139) +#define kNetSubClass (0x10EC) + using namespace Kernel; using namespace Kernel::HAL; STATIC UInt16 kRTLIOBase = 0xFFFF; -STATIC BOOL kTXRXEnabled = NO; - STATIC UInt32 kRXOffset = 0UL; STATIC constexpr CONST UInt32 kRXBufferSize = 8192 + 16 + 1500; STATIC UInt8* kRXUpperLayer = nullptr; STATIC UInt8* kRXBuffer = nullptr; +STATIC PCI::Device kNetDev; + /***********************************************************************************/ -///@brief RTL8139 Init routine. +///@brief BNID Init routine. /***********************************************************************************/ -EXTERN_C BOOL rtl_init_nic_rtl8139(UInt16 io_base) { +EXTERN_C BOOL rtl_init_nic_rtl8139() { + STATIC BOOL kTXRXEnabled = NO; if (kTXRXEnabled) return NO; - kRTLIOBase = io_base; + PCI::Iterator iterator(Types::PciDeviceKind::NetworkController, 0x00); - MUST_PASS(io_base != 0xFFFF); + for (SizeT device_index = 0; device_index < NE_BUS_COUNT; ++device_index) { + kNetDev = iterator[device_index].Leak(); // Leak device. - kRXBuffer = reinterpret_cast<UInt8*>(rtl_dma_alloc(sizeof(UInt8) * kRXBufferSize, 0)); + if (kNetDev.VendorId() == kNetSubClass && kNetDev.DeviceId() == kNetDevID) { + kNetDev.EnableMmio(); + kNetDev.BecomeBusMaster(); + + break; + } + } + + kRTLIOBase = kNetDev.Bar(0); - MUST_PASS(kRXBuffer); + MUST_PASS(kRTLIOBase != 0xFFFF); + + kRXBuffer = reinterpret_cast<UInt8*>(rtl_dma_alloc(sizeof(UInt8) * kRXBufferSize, 0)); /// Reset first. - rt_out8(io_base + 0x37, 0x10); + rt_out8(kRTLIOBase + 0x37, 0x10); UInt16 timeout = 0U; - while (rt_in8(io_base + 0x37) & 0x10) { + while (rt_in8(kRTLIOBase + 0x37) & 0x10) { ++timeout; if (timeout > 0x1000) break; } - if (timeout <= 0x1000) { - return NO; - } - - rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRXBuffer); + rt_out32(kRTLIOBase + 0x30, (UInt32) (UIntPtr) kRXBuffer); - rt_out8(io_base + 0x37, 0x0C); + rt_out8(kRTLIOBase + 0x37, 0x0C); - rt_out32(io_base + 0x44, 0xF | (1 << 7)); + rt_out32(kRTLIOBase + 0x44, 0xF | (1 << 7)); - rt_out16(io_base + 0x3C, 0x0005); + rt_out16(kRTLIOBase + 0x3C, 0x0005); kTXRXEnabled = YES; + kout << "The Basic Network Interface Driver (BNID) has been initialized.\r"; + return YES; } /***********************************************************************************/ -/// @brief RTL8139 I/O interrupt handler. +/// @brief BNID I/O interrupt handler. /// @param rsp stack pointer. /// @note This function is called when the device interrupts to retrieve network data. /***********************************************************************************/ @@ -105,7 +121,7 @@ EXTERN_C Void rtl_rtl8139_interrupt_handler(UIntPtr rsp) { } /***********************************************************************************/ -/// @brief RTL8139 get upper layer function +/// @brief BNID get upper layer function /// @return the upper layer. /// @retval nullptr if no upper layer is set. /// @retval pointer to the upper layer if set. @@ -116,7 +132,7 @@ EXTERN_C UInt8* rtl_rtl8139_get_upper_layer() { } /***********************************************************************************/ -/// @brief RTL8139 set upper layer function +/// @brief BNID set upper layer function /// @param layer the upper layer. /***********************************************************************************/ diff --git a/src/kernel/HALKit/AMD64/Paging.h b/src/kernel/HALKit/AMD64/Paging.h index f6ec0bf4..7b64835a 100644 --- a/src/kernel/HALKit/AMD64/Paging.h +++ b/src/kernel/HALKit/AMD64/Paging.h @@ -57,7 +57,9 @@ namespace Detail { kPageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast<UInt8>(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast<UInt8>(reg); + } } // namespace Detail auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr; diff --git a/src/kernel/HALKit/ARM64/CxxAbi.cpp b/src/kernel/HALKit/ARM64/CxxAbi.cpp index 3c7c7952..7f8c8245 100644 --- a/src/kernel/HALKit/ARM64/CxxAbi.cpp +++ b/src/kernel/HALKit/ARM64/CxxAbi.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/DebugOutput.h> #include <KernelKit/KPC.h> #include <NeKit/CxxAbi.h> diff --git a/src/kernel/HALKit/ARM64/Paging.h b/src/kernel/HALKit/ARM64/Paging.h index 71e663ae..fd04c2da 100644 --- a/src/kernel/HALKit/ARM64/Paging.h +++ b/src/kernel/HALKit/ARM64/Paging.h @@ -41,14 +41,10 @@ /// Long format address range -#define cPageMAll \ - { 0b000, 0b000 } -#define cPageMToMax(M) \ - { M, 0b000 } -#define cPageMaxToM(M) \ - { 0b000, M } -#define cPageMToN(M, N) \ - { M, N } +#define cPageMAll {0b000, 0b000} +#define cPageMToMax(M) {M, 0b000} +#define cPageMaxToM(M) {0b000, M} +#define cPageMToN(M, N) {M, N} namespace Kernel::HAL { struct PACKED PTE_4KB final { @@ -86,7 +82,9 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast<UInt8>(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast<UInt8>(reg); + } } // namespace Detail struct PDE_4KB final { diff --git a/src/kernel/KernelKit/CoreProcessScheduler.h b/src/kernel/KernelKit/CoreProcessScheduler.h index 7ed23a92..71a75e1a 100644 --- a/src/kernel/KernelKit/CoreProcessScheduler.h +++ b/src/kernel/KernelKit/CoreProcessScheduler.h @@ -59,19 +59,11 @@ struct ProcessHeapTree final { TreeKind Color{TreeKind::kBlackTreeKind}; - struct ProcessHeapTree<T>* Parent { - nullptr - }; - struct ProcessHeapTree<T>* Child { - nullptr - }; - - struct ProcessHeapTree<T>* Prev { - nullptr - }; - struct ProcessHeapTree<T>* Next { - nullptr - }; + struct ProcessHeapTree<T>* Parent{nullptr}; + struct ProcessHeapTree<T>* Child{nullptr}; + + struct ProcessHeapTree<T>* Prev{nullptr}; + struct ProcessHeapTree<T>* Next{nullptr}; }; template <typename T> @@ -86,21 +78,13 @@ struct ProcessFileTree final { TreeKind Color{TreeKind::kBlackTreeKind}; - struct ProcessFileTree<T>* Parent { - nullptr - }; + struct ProcessFileTree<T>* Parent{nullptr}; - struct ProcessFileTree<T>* Child { - nullptr - }; + struct ProcessFileTree<T>* Child{nullptr}; - struct ProcessFileTree<T>* Prev { - nullptr - }; + struct ProcessFileTree<T>* Prev{nullptr}; - struct ProcessFileTree<T>* Next { - nullptr - }; + struct ProcessFileTree<T>* Next{nullptr}; }; template <typename T> @@ -121,21 +105,13 @@ struct ProcessSpecialTree final { TreeKind Color{TreeKind::kBlackTreeKind}; - struct ProcessSpecialTree<T>* Parent { - nullptr - }; + struct ProcessSpecialTree<T>* Parent{nullptr}; - struct ProcessSpecialTree<T>* Child { - nullptr - }; + struct ProcessSpecialTree<T>* Child{nullptr}; - struct ProcessSpecialTree<T>* Prev { - nullptr - }; + struct ProcessSpecialTree<T>* Prev{nullptr}; - struct ProcessSpecialTree<T>* Next { - nullptr - }; + struct ProcessSpecialTree<T>* Next{nullptr}; }; /***********************************************************************************/ diff --git a/src/kernel/KernelKit/DriveMgr.h b/src/kernel/KernelKit/DriveMgr.h index 082ffc95..76ee5dcf 100644 --- a/src/kernel/KernelKit/DriveMgr.h +++ b/src/kernel/KernelKit/DriveMgr.h @@ -73,7 +73,7 @@ struct DriveTrait final { Void (*fOutput)(DrivePacket& packet){nullptr}; Void (*fVerify)(DrivePacket& packet){nullptr}; Void (*fInit)(DrivePacket& packet){nullptr}; - const Char* (*fProtocol)(Void){nullptr}; + const Char* (*fProtocol)(Void) {nullptr}; }; namespace Probe { diff --git a/src/kernel/KernelKit/HardwareThreadScheduler.h b/src/kernel/KernelKit/HardwareThreadScheduler.h index 53a971e5..a9183cd2 100644 --- a/src/kernel/KernelKit/HardwareThreadScheduler.h +++ b/src/kernel/KernelKit/HardwareThreadScheduler.h @@ -64,10 +64,10 @@ class HardwareThread final { BOOL IsWakeup(); public: - HAL::StackFramePtr StackFrame(); + HAL::StackFramePtr StackFrame(); _Output const ThreadKind& Kind(); BOOL IsBusy(); - _Output const ThreadID& ID(); + _Output const ThreadID& ID(); private: HAL::StackFramePtr fStack{}; @@ -102,7 +102,7 @@ class HardwareThreadScheduler final : public ISchedulable { public: Ref<HardwareThread*> operator[](SizeT idx); bool operator!(); - operator bool(); + operator bool(); Bool IsUser() override { return Yes; } diff --git a/src/kernel/KernelKit/ILoader.h b/src/kernel/KernelKit/ILoader.h index f6e13023..9291340f 100644 --- a/src/kernel/KernelKit/ILoader.h +++ b/src/kernel/KernelKit/ILoader.h @@ -26,9 +26,9 @@ class ILoader { public: virtual _Output ErrorOr<VoidPtr> GetBlob() { return ErrorOr<VoidPtr>{}; } - virtual _Output const Char* AsString() { return "(null)"; } - virtual _Output const Char* MIME() { return "*/*"; } - virtual _Output const Char* Path() { return "(null)"; } + virtual _Output const Char* AsString() { return "(null)"; } + virtual _Output const Char* MIME() { return "*/*"; } + virtual _Output const Char* Path() { return "(null)"; } virtual _Output ErrorOr<VoidPtr> FindStart() { return ErrorOr<VoidPtr>{}; } virtual _Output ErrorOr<VoidPtr> FindSymbol(_Input const Char*, _Input Int32) { return ErrorOr<VoidPtr>{}; diff --git a/src/kernel/KernelKit/PCI/DMA.h b/src/kernel/KernelKit/PCI/DMA.h index 63b284cb..f27681de 100644 --- a/src/kernel/KernelKit/PCI/DMA.h +++ b/src/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/src/kernel/KernelKit/PCI/Device.h b/src/kernel/KernelKit/PCI/Device.h index b7737385..1adc9f24 100644 --- a/src/kernel/KernelKit/PCI/Device.h +++ b/src/kernel/KernelKit/PCI/Device.h @@ -51,7 +51,7 @@ class Device final { } public: - UShort DeviceId(); + UInt16 DeviceId(); UShort VendorId(); UShort InterfaceId(); UChar Class(); diff --git a/src/kernel/KernelKit/UserProcessScheduler.h b/src/kernel/KernelKit/UserProcessScheduler.h index ab3c713e..5018f1f6 100644 --- a/src/kernel/KernelKit/UserProcessScheduler.h +++ b/src/kernel/KernelKit/UserProcessScheduler.h @@ -63,10 +63,10 @@ class UserProcess final { IDylibObject* DylibDelegate{nullptr}; SizeT MemoryCursor{0UL}; SizeT MemoryLimit{kCPSMaxMemoryLimit}; - SizeT UsedMemory{0UL}; /// AMLALE: This should be thread-safe as well. - SizeT UsedFiles{0UL}; /// AMLALE: This is a thread-safe counter to track file allocation count. - UserProcessSignal Signal; - ProcessImage Image; + SizeT UsedMemory{0UL}; /// AMLALE: This should be thread-safe as well. + SizeT UsedFiles{0UL}; /// AMLALE: This is a thread-safe counter to track file allocation count. + UserProcessSignal Signal; + ProcessImage Image; private: ProcessFileTree<Any>* FileTree{nullptr}; @@ -207,8 +207,8 @@ class UserProcessTeam final { NE_COPY_DEFAULT(UserProcessTeam) Array<UserProcess, kCPSProcessLimitPerTeam>& AsArray(); - Ref<UserProcess>& AsRef(); - ProcessID& Id(); + Ref<UserProcess>& AsRef(); + ProcessID& Id(); public: UserProcessArray mProcessList; diff --git a/src/kernel/NeKit/Config.h b/src/kernel/NeKit/Config.h index caf17ebd..a855bf2a 100644 --- a/src/kernel/NeKit/Config.h +++ b/src/kernel/NeKit/Config.h @@ -17,7 +17,7 @@ #define NE_ICODEC \ final: \ - public \ + public \ ::Kernel::ICodec /// @brief The **NeKernel** namespace. @@ -113,12 +113,12 @@ inline Args&& move(Args&& arg) { template <class Type> concept IsSerializable = requires() { - {Type::kValue}; + { Type::kValue }; }; template <class Type> concept IsNotSerializable = requires() { - {!Type::kValue}; + { !Type::kValue }; }; /// @brief Encoding interface, used as a proxy to convert T to Char* diff --git a/src/kernel/NeKit/Macros.h b/src/kernel/NeKit/Macros.h index 4fb3a736..361afbda 100644 --- a/src/kernel/NeKit/Macros.h +++ b/src/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 @@ -117,7 +117,7 @@ #define NE_UNUSED(X) ((Kernel::Void) X) #ifndef RGB -#define RGB(R, G, B) ((Kernel::UInt32)((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B))) +#define RGB(R, G, B) ((Kernel::UInt32) ((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B))) #endif // !RGB #ifdef __NE_AMD64__ diff --git a/src/kernel/NeKit/Utils.h b/src/kernel/NeKit/Utils.h index 0ac5acc5..3f387c33 100644 --- a/src/kernel/NeKit/Utils.h +++ b/src/kernel/NeKit/Utils.h @@ -55,9 +55,9 @@ inline constexpr SizeT oe_string_len(const CharType* str) { if (!str) return 0; #if __cplusplus == 202302L - if - consteval { return ARRAY_SIZE(str); } - else { + if consteval { + return ARRAY_SIZE(str); + } else { SizeT len{0}; while (str[len] != 0) ++len; return len; diff --git a/src/kernel/NeKit/Vettable.h b/src/kernel/NeKit/Vettable.h index 4cb1682d..a33a3ab3 100644 --- a/src/kernel/NeKit/Vettable.h +++ b/src/kernel/NeKit/Vettable.h @@ -16,14 +16,10 @@ namespace Kernel { template <class Type> -concept IsVettable = requires(Type) { - (Type::kVettable); -}; +concept IsVettable = requires(Type) { (Type::kVettable); }; template <class Type> -concept IsUnVettable = requires(Type) { - (Type::kUnvettable); -}; +concept IsUnVettable = requires(Type) { (Type::kUnvettable); }; } // namespace Kernel #endif // !__NE_KIT_VETTABLE_H__ diff --git a/src/kernel/amd64-ci.make b/src/kernel/amd64-ci.make index dcb1c97e..71e350e5 100644 --- a/src/kernel/amd64-ci.make +++ b/src/kernel/amd64-ci.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -D__nekernel_dma_best_align=8 -D__nekernel_max_cores=8 -c -D__NE_AMD64__ -D__NEOSKRNL__ -D__NE_VEPM__ -Werror -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEKERNEL__ -D__HAVE_NE_API__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot +CCFLAGS = -fshort-wchar -D__nekernel_dma_best_align=8 -D__HALKIT_INCLUDES_BNID__=1 -D__nekernel_max_cores=8 -c -D__NE_AMD64__ -D__NEOSKRNL__ -D__NE_VEPM__ -Werror -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEKERNEL__ -D__HAVE_NE_API__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm diff --git a/src/kernel/amd64-desktop.make b/src/kernel/amd64-desktop.make index 4afcdfd2..73bb2f43 100644 --- a/src/kernel/amd64-desktop.make +++ b/src/kernel/amd64-desktop.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -D__nekernel_dma_pool_start=0x1000000 -D__nekernel_dma_pool_size=0x1000000 \ +CCFLAGS = -fshort-wchar -D__nekernel_dma_pool_start=0x1000000 -D__HALKIT_INCLUDES_BNID__=1 -D__nekernel_dma_pool_size=0x1000000 \ -D__nekernel_halkit_include_processor="<HALKit/AMD64/Processor.h>" -D__nekernel_max_cores=8 -c -D__NE_AMD64__ -D__NEOSKRNL__ -D__NE_VEPM__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__nekernel_dma_best_align=8 -D__FSKIT_INCLUDES_OPENHEFS__ -D__FSKIT_INCLUDES_EXT2__ -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__NEKERNEL__ -D__HAVE_NE_API__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm diff --git a/src/kernel/kernel_rsrc.rsrc b/src/kernel/kernel_rsrc.rsrc index 0a43086e..e6effe51 100644 --- a/src/kernel/kernel_rsrc.rsrc +++ b/src/kernel/kernel_rsrc.rsrc @@ -12,7 +12,7 @@ BEGIN VALUE "FileDescription", "NeKernel" VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "ne_kernel" - VALUE "LegalCopyright", "(c) 2024-2025 Amlal El Mahrouss, licensed under the Apache 2.0 license." + VALUE "LegalCopyright", "(c) 2024-2026 Amlal El Mahrouss, licensed under the Apache 2.0 license." VALUE "OriginalFilename", "ne_kernel" VALUE "ProductName", "NeKernel" VALUE "ProductVersion", KERNEL_VERSION diff --git a/src/kernel/src/ACPIFactoryInterface.cpp b/src/kernel/src/ACPIFactoryInterface.cpp index 53f7b9e0..9aa4e26e 100644 --- a/src/kernel/src/ACPIFactoryInterface.cpp +++ b/src/kernel/src/ACPIFactoryInterface.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <ArchKit/ArchKit.h> #include <KernelKit/HeapMgr.h> #include <NeKit/KString.h> diff --git a/src/kernel/src/AsciiUtils.cpp b/src/kernel/src/AsciiUtils.cpp index 83caa058..10b4c756 100644 --- a/src/kernel/src/AsciiUtils.cpp +++ b/src/kernel/src/AsciiUtils.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <NeKit/Utils.h> namespace Kernel { @@ -105,9 +104,7 @@ Int32 rt_to_lower(Int ch) { } Int32 rt_is_alnum(Int ch) { - return (ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9'); + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'); } Boolean rt_is_space(Int ch) { diff --git a/src/kernel/src/CodeMgr.cpp b/src/kernel/src/CodeMgr.cpp index 8344fefc..e9eab8bd 100644 --- a/src/kernel/src/CodeMgr.cpp +++ b/src/kernel/src/CodeMgr.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/CodeMgr.h> #include <KernelKit/ProcessScheduler.h> #include <NeKit/Utils.h> diff --git a/src/kernel/src/FS/Ext2+IFS.cpp b/src/kernel/src/FS/Ext2+IFS.cpp index 30fb2f0d..4816119e 100644 --- a/src/kernel/src/FS/Ext2+IFS.cpp +++ b/src/kernel/src/FS/Ext2+IFS.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #ifndef __NE_MINIMAL_OS__ #ifdef __FSKIT_INCLUDES_EXT2__ @@ -18,17 +17,18 @@ #include <NeKit/Utils.h> /// @note There's no current maintainer of Ext2, the position is vacant. -/// @note AMLALE: @0xf00sec has written this driver, and I @amlel-el-mahrouss is currently working on adding triple indirect indices. +/// @note AMLALE: @0xf00sec has written this driver, and I @amlel-el-mahrouss is currently working +/// on adding triple indirect indices. /// @note AMLALE: This driver is too verbose, we need a complete overhaul of it. -constexpr static UInt32 EXT2_DIRECT_BLOCKS = 12; -constexpr static UInt32 EXT2_SINGLE_INDIRECT_INDEX = 12; -constexpr static UInt32 EXT2_DOUBLE_INDIRECT_INDEX = 13; -constexpr static UInt32 EXT2_TRIPLE_INDIRECT_INDEX = 14; -constexpr static UInt32 EXT2_ROOT_INODE = 2; -constexpr ATTRIBUTE(unused) static UInt32 EXT2_SUPERBLOCK_BLOCK = 1; -constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_SMALL = 2; -constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_LARGE = 1; +constexpr static UInt32 EXT2_DIRECT_BLOCKS = 12; +constexpr static UInt32 EXT2_SINGLE_INDIRECT_INDEX = 12; +constexpr static UInt32 EXT2_DOUBLE_INDIRECT_INDEX = 13; +constexpr static UInt32 EXT2_TRIPLE_INDIRECT_INDEX = 14; +constexpr static UInt32 EXT2_ROOT_INODE = 2; +constexpr ATTRIBUTE(unused) static UInt32 EXT2_SUPERBLOCK_BLOCK = 1; +constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_SMALL = 2; +constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_LARGE = 1; namespace Detail { static inline SizeT ext2_min(SizeT a, SizeT b) { @@ -521,8 +521,8 @@ static ErrorOr<Void*> ext2_set_block_address(Ext2Context* ctx, Ext2Node* node, mm_free_ptr(singlePtr); return ErrorOr<Void*>(nullptr); } else if (logicalBlockIndex < doubleStart + tripleSpan) { - UInt32 tripleLba = ext2_block_to_lba(ctx, node->inode.fBlock[EXT2_TRIPLE_INDIRECT_INDEX]); - auto triplePtrRef = ext2_read_block_ptr(ctx, node->inode.fBlock[EXT2_TRIPLE_INDIRECT_INDEX]); + UInt32 tripleLba = ext2_block_to_lba(ctx, node->inode.fBlock[EXT2_TRIPLE_INDIRECT_INDEX]); + auto triplePtrRef = ext2_read_block_ptr(ctx, node->inode.fBlock[EXT2_TRIPLE_INDIRECT_INDEX]); if (triplePtrRef.HasError()) { return ErrorOr<Void*>(kErrorDisk); @@ -536,7 +536,6 @@ static ErrorOr<Void*> ext2_set_block_address(Ext2Context* ctx, Ext2Node* node, mm_free_ptr(triplePtrRef.Leak().Leak()); } - return ErrorOr<Void*>(kErrorDisk); } diff --git a/src/kernel/src/FS/NeFS+FileMgr.cpp b/src/kernel/src/FS/NeFS+FileMgr.cpp index e42bd519..a0cf4ad0 100644 --- a/src/kernel/src/FS/NeFS+FileMgr.cpp +++ b/src/kernel/src/FS/NeFS+FileMgr.cpp @@ -50,7 +50,7 @@ NodePtr NeFileSystemMgr::Create(_Input const Char* path) { kout << "NeFS: Create called with null or empty path\n"; return nullptr; } - + return rtl_node_cast(mParser->CreateCatalog(path)); } @@ -62,7 +62,7 @@ NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { kout << "NeFS: CreateDirectory called with null or empty path\n"; return nullptr; } - + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } @@ -74,7 +74,7 @@ NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { kout << "NeFS: CreateAlias called with null or empty path\n"; return nullptr; } - + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } @@ -119,12 +119,12 @@ _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char kout << "NeFS: Open called with null or empty path\n"; return nullptr; } - + if (!r || *r == 0) { kout << "NeFS: Open called with null or empty mode string\n"; return nullptr; } - + auto catalog = mParser->GetCatalog(path); if (!catalog) { kout << "NeFS: Open could not find catalog for path\n"; diff --git a/src/kernel/src/FS/OpenHeFS+FileMgr.cpp b/src/kernel/src/FS/OpenHeFS+FileMgr.cpp index 551d69d1..a0a649eb 100644 --- a/src/kernel/src/FS/OpenHeFS+FileMgr.cpp +++ b/src/kernel/src/FS/OpenHeFS+FileMgr.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #ifndef __NE_MINIMAL_OS__ #ifdef __FSKIT_INCLUDES_OPENHEFS__ @@ -74,9 +73,7 @@ NodePtr HeFileSystemMgr::Create(_Input const Char* path) { err_local_get() = kErrorSuccess; - if (auto node = mParser->CreateINode(&mDriveTrait, 0, nullptr, out, 0); - node) - return nullptr; + if (auto node = mParser->CreateINode(&mDriveTrait, 0, nullptr, out, 0); node) return nullptr; kout << "OpenHeFS: ERROR: Check KPC.\r"; @@ -107,14 +104,12 @@ NodePtr HeFileSystemMgr::CreateDirectory(const Char* path) { err_local_get() = kErrorSuccess; - if (auto node = mParser->CreateINodeDirectory(&mDriveTrait, 0, out); - node) - return nullptr; + if (auto node = mParser->CreateINodeDirectory(&mDriveTrait, 0, out); node) return nullptr; kout << "OpenHeFS: ERROR: Check KPC.\r"; - err_local_get() = kErrorDiskIsFull; - + err_local_get() = kErrorDiskIsFull; + return nullptr; } @@ -126,7 +121,7 @@ NodePtr HeFileSystemMgr::CreateAlias(const Char* path) { kout << "OpenHeFS: CreateAlias called with null or empty path\r"; return nullptr; } - + // TODO: It needs its own helper! SizeT len = oe_string_len<Char>(path); @@ -140,14 +135,15 @@ NodePtr HeFileSystemMgr::CreateAlias(const Char* path) { err_local_get() = kErrorSuccess; - if (auto node = mParser->CreateINode(&mDriveTrait, kOpenHeFSFileKindSymbolicLink, nullptr, out, 0); - node) + if (auto node = + mParser->CreateINode(&mDriveTrait, kOpenHeFSFileKindSymbolicLink, nullptr, out, 0); + node) return nullptr; kout << "OpenHeFS: ERROR: Check KPC.\r"; - err_local_get() = kErrorDiskIsFull; - + err_local_get() = kErrorDiskIsFull; + return nullptr; } @@ -221,14 +217,14 @@ _Output VoidPtr HeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _ return nullptr; } - /// @note name is not used in OpenHeFS to mark data offsets. That's an NeFS-ism. +/// @note name is not used in OpenHeFS to mark data offsets. That's an NeFS-ism. Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { NE_UNUSED(node); - //NE_UNUSED(flags); - //NE_UNUSED(size); - //NE_UNUSED(name); - //NE_UNUSED(data); + // NE_UNUSED(flags); + // NE_UNUSED(size); + // NE_UNUSED(name); + // NE_UNUSED(data); if (!flags) return; if (!size) return; @@ -237,8 +233,8 @@ Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input static IMountpoint mnt; io_construct_main_drive(mnt.A()); - - mParser->INodeManip(&mnt.A(), (VoidPtr)data, size, u8"/", (Char8*)name, 0, NO); + + mParser->INodeManip(&mnt.A(), (VoidPtr) data, size, u8"/", (Char8*) name, 0, NO); } _Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, @@ -257,8 +253,8 @@ _Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr no static IMountpoint mnt; io_construct_main_drive(mnt.A()); - mParser->INodeManip(&mnt.A(), (VoidPtr)retBlob, sz, u8"/", (Char8*)name, 0, YES); - + mParser->INodeManip(&mnt.A(), (VoidPtr) retBlob, sz, u8"/", (Char8*) name, 0, YES); + return retBlob; } @@ -273,7 +269,7 @@ _Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) { _Output SizeT HeFileSystemMgr::Tell(NodePtr node) { if (!node) return kFileMgrNPos; SizeT pos = 0ULL; - + return pos; } diff --git a/src/kernel/src/FS/OpenHeFS+FileSystemParser.cpp b/src/kernel/src/FS/OpenHeFS+FileSystemParser.cpp index e03657f7..b923d13f 100644 --- a/src/kernel/src/FS/OpenHeFS+FileSystemParser.cpp +++ b/src/kernel/src/FS/OpenHeFS+FileSystemParser.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #ifdef __FSKIT_INCLUDES_OPENHEFS__ #include <FSKit/OpenHeFS.h> diff --git a/src/kernel/src/FileMgr.cpp b/src/kernel/src/FileMgr.cpp index 4d109bf3..4dadf288 100644 --- a/src/kernel/src/FileMgr.cpp +++ b/src/kernel/src/FileMgr.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/FileMgr.h> #include <NeKit/Utils.h> diff --git a/src/kernel/src/GUIDWizard.cpp b/src/kernel/src/GUIDWizard.cpp index ad54d4bd..fd43d861 100644 --- a/src/kernel/src/GUIDWizard.cpp +++ b/src/kernel/src/GUIDWizard.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <CFKit/GUIDWizard.h> #include <NeKit/Ref.h> diff --git a/src/kernel/src/Gfx/FBDeviceInterface.cpp b/src/kernel/src/Gfx/FBDeviceInterface.cpp index 35688966..48bc1abd 100644 --- a/src/kernel/src/Gfx/FBDeviceInterface.cpp +++ b/src/kernel/src/Gfx/FBDeviceInterface.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <GfxKit/FB.h> using namespace Kernel; diff --git a/src/kernel/src/HeapMgr.cpp b/src/kernel/src/HeapMgr.cpp index c22d6cdd..a7430824 100644 --- a/src/kernel/src/HeapMgr.cpp +++ b/src/kernel/src/HeapMgr.cpp @@ -3,15 +3,14 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <ArchKit/ArchKit.h> #include <KernelKit/DebugOutput.h> #include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> +#include <KernelKit/LockDelegate.h> #include <NeKit/Crc32.h> #include <NeKit/PageMgr.h> #include <NeKit/Utils.h> -#include <KernelKit/LockDelegate.h> /* ======================================== @@ -85,7 +84,7 @@ STATIC PageMgr kPageMgr; /// @param user User enable bit. /// @return The newly allocated pointer. _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { - static Bool locked = false; + static Bool locked = false; LockDelegate<255> lock{&locked}; auto sz_fix = sz; @@ -134,7 +133,7 @@ _Output VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { /// @brief Controls the page's heap. /// @param heap_ptr the pointer to make a page heap. /// @return kErrorSuccess if successful, otherwise an error code. - _Output Int32 mm_ctl_page(VoidPtr heap_ptr, const Bool enable) { +_Output Int32 mm_ctl_page(VoidPtr heap_ptr, const Bool enable) { if (Detail::mm_check_ptr_address(heap_ptr) == No) return kErrorHeapNotPresent; Detail::MM_INFORMATION_BLOCK_PTR heap_info_ptr = diff --git a/src/kernel/src/InitializerList.cpp b/src/kernel/src/InitializerList.cpp index 42e3db6a..fada5851 100644 --- a/src/kernel/src/InitializerList.cpp +++ b/src/kernel/src/InitializerList.cpp @@ -3,5 +3,4 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <NeKit/InitializerList.h> diff --git a/src/kernel/src/Json.cpp b/src/kernel/src/Json.cpp index 06e428e9..5cfd7c06 100644 --- a/src/kernel/src/Json.cpp +++ b/src/kernel/src/Json.cpp @@ -5,4 +5,4 @@ #include <NeKit/Json.h> -namespace Kernel {}
\ No newline at end of file +namespace Kernel {} diff --git a/src/kernel/src/KernelTask.cpp b/src/kernel/src/KernelTask.cpp index e733d64a..e73dce21 100644 --- a/src/kernel/src/KernelTask.cpp +++ b/src/kernel/src/KernelTask.cpp @@ -3,9 +3,8 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - -#include <KernelKit/KernelTask.h> #include <KernelKit/CodeMgr.h> +#include <KernelKit/KernelTask.h> /***********************************************************************************/ /// @file KernelTaskScheduler.cc @@ -14,15 +13,15 @@ /***********************************************************************************/ namespace Kernel { - + /// @internal @brief Calls the DDK stub to initialize the stack_frame of the driver. EXTERN_C Int32 kt_kernel_task_start(HAL::StackFramePtr stack_frame, VoidPtr code) { MUST_PASS(stack_frame && code); - ((rtl_kstart_kind)(code))(stack_frame); + ((rtl_kstart_kind) (code))(stack_frame); return stack_frame->R8; } - + Bool KernelTaskHelper::Start(KernelTask& task_ptr, const KID& kid) { if (!kid) return NO; diff --git a/src/kernel/src/Semaphore.cpp b/src/kernel/src/Semaphore.cpp index c353c223..8516e462 100644 --- a/src/kernel/src/Semaphore.cpp +++ b/src/kernel/src/Semaphore.cpp @@ -3,6 +3,4 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/Semaphore.h> - diff --git a/src/kernel/src/Storage/AHCIDeviceInterface.cpp b/src/kernel/src/Storage/AHCIDeviceInterface.cpp index 3e47ef45..3a48cadc 100644 --- a/src/kernel/src/Storage/AHCIDeviceInterface.cpp +++ b/src/kernel/src/Storage/AHCIDeviceInterface.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <StorageKit/AHCI.h> namespace Kernel { diff --git a/src/kernel/src/Swap/DiskSwap.cpp b/src/kernel/src/Swap/DiskSwap.cpp index 94991d20..b7733870 100644 --- a/src/kernel/src/Swap/DiskSwap.cpp +++ b/src/kernel/src/Swap/DiskSwap.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/FileMgr.h> #include <SwapKit/DiskSwap.h> diff --git a/src/kernel/src/UserMgr.cpp b/src/kernel/src/UserMgr.cpp deleted file mode 100644 index cceda53d..00000000 --- a/src/kernel/src/UserMgr.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/ne-foss-org/kernel - -#include <KernelKit/FileMgr.h> -#include <KernelKit/HeapMgr.h> -#include <KernelKit/KPC.h> -#include <KernelKit/ThreadLocalStorage.h> -#include <KernelKit/UserMgr+User.h> -#include <NeKit/KString.h> -#include <NeKit/KernelPanic.h> -#include <NeKit/Utils.h> - -/// @file UserMgr+User.cpp -/// @brief Multi-user support. - -namespace Kernel { - namespace Detail { - struct UserPermissionControl; - struct UserPermissionElevator; - } -} diff --git a/src/kernel/src/UserProcessTeam.cpp b/src/kernel/src/UserProcessTeam.cpp index 293fd45a..27ad73e7 100644 --- a/src/kernel/src/UserProcessTeam.cpp +++ b/src/kernel/src/UserProcessTeam.cpp @@ -7,7 +7,7 @@ namespace Kernel { UserProcessTeam::UserProcessTeam() { - for (SizeT i = 0U; i < this->mProcessList.Count(); ++i) { + for (SizeT i{}; i < kCPSProcessLimitPerTeam; ++i) { this->mProcessList[i] = UserProcess{}; this->mProcessList[i].PTime = 0; this->mProcessList[i].RTime = 0; @@ -15,7 +15,10 @@ UserProcessTeam::UserProcessTeam() { this->mProcessList[i].Status = ProcessStatusKind::kKilled; } - // se the cursor to zero. + // We dont know our team yet. + this->mTeamId = 0UL; + + // We dont have any running processes. this->mProcessCur = 0UL; } diff --git a/src/kernel/src/UtfUtils.cpp b/src/kernel/src/UtfUtils.cpp index 0698010c..dbf52840 100644 --- a/src/kernel/src/UtfUtils.cpp +++ b/src/kernel/src/UtfUtils.cpp @@ -8,6 +8,7 @@ /// @author Amlal El Mahrouss (amlal@nekernel.org) namespace Kernel { + Size urt_string_len(const Utf8Char* str) { if (!str) return 0; @@ -58,4 +59,5 @@ Int32 urt_copy_memory(const VoidPtr src, VoidPtr dst, Size len) { return index; } + } // namespace Kernel diff --git a/src/kernel/src/ZXDCodeMgr.cpp b/src/kernel/src/ZXDCodeMgr.cpp index 59abc3c3..29599b1e 100644 --- a/src/kernel/src/ZXDCodeMgr.cpp +++ b/src/kernel/src/ZXDCodeMgr.cpp @@ -3,8 +3,5 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <KernelKit/CodeMgr.h> #include <KernelKit/ZXD.h> - - diff --git a/src/launch/src/RuntimeMain.cpp b/src/launch/src/RuntimeMain.cpp index 833a2f55..dc379d54 100644 --- a/src/launch/src/RuntimeMain.cpp +++ b/src/launch/src/RuntimeMain.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <LaunchKit/Foundation.h> #include <libSystem/SystemKit/Err.h> #include <libSystem/SystemKit/Syscall.h> @@ -11,14 +10,14 @@ /// @note This called by _NeMain from its own runtime. IMPORT_C SInt32 launch_startup_fn(Void) { /// Start LaunchHelpers.fwrk services, and make the launcher manageable too (via mgmt.launch) - UInt32* ret = - static_cast<UInt32*>(libsys_syscall_arg_1(libsys_hash_64("__launch_register_service"))); // Register service based on program data. + UInt32* ret = static_cast<UInt32*>(libsys_syscall_arg_1( + libsys_hash_64("__launch_register_service"))); // Register service based on program data. if (ret) { switch (*ret) { case kErrorSuccess: { - ret = - static_cast<UInt32*>(libsys_syscall_arg_1(libsys_hash_64("__launch_attach_service"))); // Attach this program as the service process. + ret = static_cast<UInt32*>(libsys_syscall_arg_1(libsys_hash_64( + "__launch_attach_service"))); // Attach this program as the service process. return *ret; } default: diff --git a/src/libDDK/DriverKit/ObjectKit/Base.h b/src/libDDK/DriverKit/ObjectKit/Base.hpp index bf557352..869e6ec1 100644 --- a/src/libDDK/DriverKit/ObjectKit/Base.h +++ b/src/libDDK/DriverKit/ObjectKit/Base.hpp @@ -10,7 +10,7 @@ #define DDK_DRIVER_IMPL \ final: \ - public \ + public \ ::Kernel::DDK::IDriverBase /// @author Amlal El Mahrouss @@ -29,6 +29,7 @@ class IDriverBase { IDriverBase& operator=(const IDriverBase&) = default; IDriverBase(const IDriverBase&) = default; +public: using PtrType = void*; virtual constexpr bool IsCastable() { return false; } @@ -41,7 +42,7 @@ class IDriverBase { /// @author @amlel-el-mahrouss template <typename Driver> concept IsValidDriver = requires(Driver drv) { - {drv.IsActive() && drv.Type() > kInvalidType}; + { drv.IsActive() && drv.Type() > kInvalidType }; }; } // namespace Kernel::DDK diff --git a/src/libDDK/DriverKit/ObjectKit/Checksum.h b/src/libDDK/DriverKit/ObjectKit/Checksum.hpp index 927bbb77..d1973161 100644 --- a/src/libDDK/DriverKit/ObjectKit/Checksum.h +++ b/src/libDDK/DriverKit/ObjectKit/Checksum.hpp @@ -6,11 +6,12 @@ #ifndef DRIVERKIT_CHECKSUM_H #define DRIVERKIT_CHECKSUM_H -#include <DriverKit/ObjectKit/Base.h> +#include <DriverKit/ObjectKit/Base.hpp> namespace Kernel::DDK { -using IndexableBlob = char*; +using Blob = char*; +using IndexableBlob = Blob; using Indexable = char; /// @note This uses the FNV 64-bit variant. @@ -22,19 +23,18 @@ inline uintptr_t rtl_checksum(const IndexableBlob path) { const uintptr_t kFNVPrime = 0x100000001b3ULL; uintptr_t hash = kFNVSeed; - IndexableBlob path_ = path; while (*path_) { - hash ^= (Indexable) (*path_++); + hash ^= (Indexable) (*path_); + ++path_; + hash *= kFNVPrime; } return hash; } -using Blob = void*; - } // namespace Kernel::DDK #endif diff --git a/src/libDDK/DriverKit/ObjectKit/DriverKit.h b/src/libDDK/DriverKit/ObjectKit/DriverKit.hpp index 3fc883fa..a5604c77 100644 --- a/src/libDDK/DriverKit/ObjectKit/DriverKit.h +++ b/src/libDDK/DriverKit/ObjectKit/DriverKit.hpp @@ -3,10 +3,10 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel -#ifndef DRIVERKIT_DDK_H -#define DRIVERKIT_DDK_H +#ifndef DRIVERKIT_OBJECTKIT_DDK_H +#define DRIVERKIT_OBJECTKIT_DDK_H -#include <DriverKit/ObjectKit/Base.h> -#include <DriverKit/ObjectKit/Checksum.h> +#include <DriverKit/ObjectKit/Base.hpp> +#include <DriverKit/ObjectKit/Checksum.hpp> #endif diff --git a/src/libDDK/src/CxxABI.cpp b/src/libDDK/src/CxxABI.cpp index f1fc5034..4c5bda38 100644 --- a/src/libDDK/src/CxxABI.cpp +++ b/src/libDDK/src/CxxABI.cpp @@ -12,7 +12,9 @@ void* operator new(size_t sz) { return ::kalloc(sz); } -void operator delete(void* ptr) { ::kfree(ptr); } +void operator delete(void* ptr) { + ::kfree(ptr); +} void* operator new[](size_t sz) { if (!sz) ++sz; @@ -20,5 +22,6 @@ void* operator new[](size_t sz) { return ::kalloc(sz); } -void operator delete[](void* ptr) { ::kfree(ptr); } - +void operator delete[](void* ptr) { + ::kfree(ptr); +} diff --git a/src/libDDK/src/Version.cpp b/src/libDDK/src/DDKVersion.cpp index 5e60fbc4..eb65da89 100644 --- a/src/libDDK/src/Version.cpp +++ b/src/libDDK/src/DDKVersion.cpp @@ -7,15 +7,15 @@ #include <DriverKit/DriverKit.h>
#ifndef kDDKVersionHighest
-#define kDDKVersionHighest 1
+#define kDDKVersionHighest 0x010000
#endif // !kDDKVersionHighest
#ifndef kDDKVersionLowest
-#define kDDKVersionLowest 1
+#define kDDKVersionLowest 0x010000
#endif // !kDDKVersionLowest
#ifndef kDDKVersion
-#define kDDKVersion 1
+#define kDDKVersion 0x010000
#endif // !kDDKVersion
uint32_t kApiVersionHighest = kDDKVersionHighest;
diff --git a/src/libDDK/src/Allocator.cpp b/src/libDDK/src/KernelAllocator.cpp index f350ab22..f2dd7b45 100644 --- a/src/libDDK/src/Allocator.cpp +++ b/src/libDDK/src/KernelAllocator.cpp @@ -14,7 +14,7 @@ DDK_EXTERN void* kalloc(size_t sz) { if (!sz) ++sz; - void* ptr = ke_call_dispatch("mm_alloc_ptr", 1, &sz, sizeof(size_t)); + void* ptr = ::ke_call_dispatch("mm_alloc_ptr", 1, &sz, sizeof(size_t)); return ptr; } @@ -26,5 +26,5 @@ DDK_EXTERN void* kalloc(size_t sz) { DDK_EXTERN void kfree(void* ptr) { if (!ptr) return; - ke_call_dispatch("mm_free_ptr", 1, ptr, 0); + ::ke_call_dispatch("mm_free_ptr", 1, ptr, 0); } diff --git a/src/libDDK/src/KernelCall.cpp b/src/libDDK/src/KernelCall.cpp index bbaded64..43e4b79f 100644 --- a/src/libDDK/src/KernelCall.cpp +++ b/src/libDDK/src/KernelCall.cpp @@ -40,14 +40,14 @@ static uint64_t ddk_fnv_64(const char* path) { /// @retval nil Kernel call failed, call KernelLastError(void) 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(ddk_fnv_64(name), cnt, data, sz); + return ::__ke_call_dispatch(ddk_fnv_64(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_dispatch("ke_set_syscall", slot, (ptr_t) slotFn, 1); + ::ke_call_dispatch("ke_set_syscall", slot, (ptr_t) slotFn, 1); } /// @brief Get a Kernel object. @@ -56,7 +56,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_dispatch("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; @@ -70,5 +70,5 @@ DDK_EXTERN struct DDK_OBJECT_MANIFEST* ke_get_obj(const int slot, const char* na /// @return property's object. DDK_EXTERN void* ke_set_obj(const int slot, const struct DDK_OBJECT_MANIFEST* ddk_ptr) { if (ddk_ptr == nil) return nil; - return ke_call_dispatch("cfkit_set_kobj", slot, (void*) ddk_ptr, 1); + return ::ke_call_dispatch("cfkit_set_kobj", slot, (void*) ddk_ptr, 1); } diff --git a/src/libDDK/src/Device.cpp b/src/libDDK/src/KernelDevice.cpp index 6390f05c..50a2c9a8 100644 --- a/src/libDDK/src/Device.cpp +++ b/src/libDDK/src/KernelDevice.cpp @@ -11,8 +11,8 @@ DDK_EXTERN DDK_DEVICE_PTR kopen_dev(const char* devicePath) { if (nil == devicePath) return nil; - return (DDK_DEVICE_PTR) ke_call_dispatch("dk_open_dev", 1, (void*) devicePath, - kstrlen(devicePath)); + return (DDK_DEVICE_PTR)::ke_call_dispatch("dk_open_dev", 1, (void*) devicePath, + kstrlen(devicePath)); } /// @brief Close any device. @@ -20,6 +20,6 @@ DDK_EXTERN DDK_DEVICE_PTR kopen_dev(const char* devicePath) { DDK_EXTERN BOOL kclose_dev(DDK_DEVICE_PTR device) { if (nil == device) return NO; - ke_call_dispatch("dk_close_dev", 1, device, sizeof(DDK_DEVICE)); + ::ke_call_dispatch("dk_close_dev", 1, device, sizeof(DDK_DEVICE)); return YES; } diff --git a/src/libDDK/src/DriverBase.cpp b/src/libDDK/src/KernelDriverBase.cpp index 37b138a0..67fd7466 100644 --- a/src/libDDK/src/DriverBase.cpp +++ b/src/libDDK/src/KernelDriverBase.cpp @@ -3,6 +3,4 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel -#include <DriverKit/ObjectKit/Base.h> - - +#include <DriverKit/ObjectKit/Base.hpp> diff --git a/src/libDDK/src/IO.cpp b/src/libDDK/src/KernelIO.cpp index fc247e15..e978525d 100644 --- a/src/libDDK/src/IO.cpp +++ b/src/libDDK/src/KernelIO.cpp @@ -13,7 +13,7 @@ DDK_EXTERN void kputc(const char ch) { assembled[0] = ch; assembled[1] = 0; - ke_call_dispatch("ke_put_string", 2, assembled, 2); + ::ke_call_dispatch("ke_put_string", 2, assembled, 2); } /// @brief print string to UART. @@ -23,10 +23,10 @@ DDK_EXTERN void kprint(const char* message) { if (*message == '\0') return; size_t index = 0; - size_t len = kstrlen(message); + size_t len = ::kstrlen(message); while (index < len) { - kputc(message[index]); + ::kputc(message[index]); ++index; } } diff --git a/src/libDDK/src/String.cpp b/src/libDDK/src/KernelString.cpp index 7aee7495..7aee7495 100644 --- a/src/libDDK/src/String.cpp +++ b/src/libDDK/src/KernelString.cpp diff --git a/src/libMsg/MsgKit/Server.h b/src/libMsg/MsgKit/Server.h index 3ab8eb73..faac0b0b 100644 --- a/src/libMsg/MsgKit/Server.h +++ b/src/libMsg/MsgKit/Server.h @@ -6,6 +6,7 @@ #ifndef MSGKIT_SERVER_H #define MSGKIT_SERVER_H +#include "libSystem/SystemKit/Macros.h" #ifdef __cplusplus #include <CoreFoundation.fwrk/headers/String.h> #else @@ -25,9 +26,12 @@ struct LIBMSG_EXPR final { CF::CFString* l_value{nullptr}; #else // if we use C, we won't know about CF, so let's make those private. - VoidPtr l_private_data[2]{nullptr}; + VoidPtr l_key{nullptr}; + VoidPtr l_value{nullptr}; #endif + SizeT l_index{}; + LIBMSG_EXPR* l_head{nullptr}; LIBMSG_EXPR* l_tail{nullptr}; LIBMSG_EXPR* l_child{nullptr}; @@ -38,6 +42,6 @@ typedef Void (*libmsg_func_type)(struct LIBMSG_EXPR* self, VoidPtr arg, SizeT ar IMPORT_C Void libmsg_init_library(libmsg_func_type* funcs, SizeT cnt); IMPORT_C UInt32 libmsg_close_library(Void); -IMPORT_C UInt32 libmsg_eval_expr(struct LIBMSG_EXPR* head); +IMPORT_C UInt32 libmsg_eval_expr(struct LIBMSG_EXPR* head, VoidPtr arg, SizeT arg_size); #endif diff --git a/src/libMsg/libMsg.json b/src/libMsg/libMsg.json index 4b22534f..54f284b8 100644 --- a/src/libMsg/libMsg.json +++ b/src/libMsg/libMsg.json @@ -17,5 +17,5 @@ "kLibSystemVersionHighest=0x0100", "kLibSystemVersionLowest=0x0100" ], - "description": "OpenMessage Kit for NeKernel." + "description": "OpenMessage Kit for the NeSystem." } diff --git a/src/libMsg/scripts/window_client.json b/src/libMsg/scripts/hello-world.json index 4c8a21ba..f23a3714 100644 --- a/src/libMsg/scripts/window_client.json +++ b/src/libMsg/scripts/hello-world.json @@ -2,6 +2,6 @@ "id": 1, "pos": { "x": 100, "y": 100 }, "size": { "w": 300, "h": 200 }, - "title": "Window Client", - "on-click": "_OnClickCSymbol" + "title": "Message", + "on-init": "_PrintHelloWorld" }
\ No newline at end of file diff --git a/src/libMsg/src/Server.cpp b/src/libMsg/src/Server.cpp index 3f2e8f5a..a2f17e91 100644 --- a/src/libMsg/src/Server.cpp +++ b/src/libMsg/src/Server.cpp @@ -5,9 +5,42 @@ #include <libMsg/MsgKit/Server.h> -IMPORT_C UInt32 libmsg_close_library(Void) { return 0; } +static libmsg_func_type* kFuncs{nullptr}; +static SizeT kFuncCnt{0}; +static SemaphoreRef kSemaphore{nullptr}; -IMPORT_C UInt32 libmsg_eval_expr(struct LIBMSG_EXPR* head) { return 0; } +IMPORT_C UInt32 libmsg_close_library(Void) { + if (kSemaphore) return 0; -IMPORT_C Void libmsg_init_library(libmsg_func_type* funcs, SizeT cnt) {} + kFuncs = nullptr; + kFuncCnt = 0; + return 0; +} + +IMPORT_C UInt32 libmsg_eval_expr(struct LIBMSG_EXPR* head, VoidPtr arg, SizeT arg_size) { + if (kSemaphore) return 0; + + if (!head) return 0; + + static kSemWaitTime = 1000; + + kSemaphore = ::SemCreate(kSemWaitTime, kSemWaitTime, "libmsg_semaphore"); + + if (!kSemaphore) return 0; + + kFuncs[head->l_index](head, arg, arg_size); + + ::SemClose(kSemaphore); + kSemaphore = nullptr; + + return 0; +} + +IMPORT_C Void libmsg_init_library(libmsg_func_type* funcs, SizeT cnt) { + kFuncs = funcs; + kFuncCnt = cnt; + + MUST_PASS(kFuncs != nullptr); + MUST_PASS(kFuncCnt > 0); +} diff --git a/src/libPOSIXWrapper/POSIXKit/POSIX.h b/src/libPOSIXWrapper/POSIXKit/POSIX.h new file mode 100644 index 00000000..ea2067b3 --- /dev/null +++ b/src/libPOSIXWrapper/POSIXKit/POSIX.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/nekernel + +#ifndef LIBPOSIX_POSIXKIT_POSIX_H +#define LIBPOSIX_POSIXKIT_POSIX_H + +#include <libSystem/SystemKit/System.h> + +/// @file POSIX.h +/// @brief POSIX definitions header for the NeSystem. + +/// @brief Please use these macros to specify whether your function is thread safe or not. +#define PTHREAD_UNSAFE __THREAD_UNSAFE +#define PTHREAD_SAFE __THREAD_SAFE + +#define _POSIX_SOURCE __POSIX_SOURCE__ +#define _XOPEN_SOURCE __XOPEN_SOURCE__ + +PTHREAD_UNSAFE IMPORT_C SInt64 write(SizeT count, SInt32 fd, Void* data, SizeT sz); +PTHREAD_UNSAFE IMPORT_C SInt64 read(SizeT count, SInt32 fd, Void* data, SizeT sz); + +#endif // LIBPOSIX_POSIXKIT_POSIX_H diff --git a/src/libPOSIXWrapper/POSIXKit/unistd.h b/src/libPOSIXWrapper/POSIXKit/unistd.h index 0e133c89..96701f35 100644 --- a/src/libPOSIXWrapper/POSIXKit/unistd.h +++ b/src/libPOSIXWrapper/POSIXKit/unistd.h @@ -3,19 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel -#ifndef LIBPOSIX_POSIXKIT_UNISTD_H -#define LIBPOSIX_POSIXKIT_UNISTD_H +#pragma once -#include <libSystem/SystemKit/System.h> - -/// @file Unistd.h -/// @brief POSIX Standard Header for NeKernel. - -#define _POSIX_SOURCE __POSIX_SOURCE__ -#define _XOPEN_SOURCE __XOPEN_SOURCE__ - -IMPORT_C SInt64 write(SizeT count, SInt32 fd, Void* data, SizeT sz); - -IMPORT_C SInt64 read(SizeT count, SInt32 fd, Void* data, SizeT sz); - -#endif // LIBPOSIX_POSIXKIT_UNISTD_H +#include <libPOSIXWrapper/POSIXKit/POSIX.h> diff --git a/src/libPOSIXWrapper/src/POSIX.cpp b/src/libPOSIXWrapper/src/POSIX.cpp new file mode 100644 index 00000000..98db8e51 --- /dev/null +++ b/src/libPOSIXWrapper/src/POSIX.cpp @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/nekernel + +#include <libPOSIXWrapper/POSIXKit/POSIX.h> diff --git a/src/libPThread/PThreadKit/Thread.h b/src/libPThread/PThreadKit/Thread.h index 053885e7..7e528ab2 100644 --- a/src/libPThread/PThreadKit/Thread.h +++ b/src/libPThread/PThreadKit/Thread.h @@ -8,7 +8,15 @@ #include <libPOSIXWrapper/POSIXKit/unistd.h> -#define PTHREAD_UNSAFE /* hint */ -#define PTHREAD_SAFE /* hint */ +/// @internal Internal type, please do not rely on it for multi-platform builds. +typedef ThreadRef pthread_ref_t; + +PTHREAD_SAFE IMPORT_C SInt32 pthread_create(_Output pthread_ref_t* thread, VoidPtr attr, + VoidPtr (*start_routine)(VoidPtr), VoidPtr arg); +PTHREAD_SAFE IMPORT_C SInt32 pthread_join(pthread_ref_t thread, VoidPtr* retval); +PTHREAD_SAFE IMPORT_C SInt32 pthread_exit(SInt32 retval); +PTHREAD_SAFE IMPORT_C SInt32 pthread_detach(pthread_ref_t thread); +PTHREAD_SAFE IMPORT_C pthread_ref_t pthread_self(Void); +PTHREAD_SAFE IMPORT_C SInt32 pthread_yield(void); #endif // LIBPOSIX_POSIXKIT_THREAD_H diff --git a/src/libPThread/PThreadKit/pthread.h b/src/libPThread/PThreadKit/pthread.h new file mode 100644 index 00000000..2448c458 --- /dev/null +++ b/src/libPThread/PThreadKit/pthread.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/nekernel + +#ifndef LIBPOSIX_POSIXKIT_PTHREAD_H +#define LIBPOSIX_POSIXKIT_PTHREAD_H + +#include <libPThread/ThreadKit/Thread.h> + +#endif diff --git a/src/libPThread/src/Thread.cpp b/src/libPThread/src/Thread.cpp index 34a610cd..5324d979 100644 --- a/src/libPThread/src/Thread.cpp +++ b/src/libPThread/src/Thread.cpp @@ -5,29 +5,42 @@ #include <libPThread/PThreadKit/Thread.h> -namespace POSIXKit::Detail { +PTHREAD_SAFE SInt32 pthread_detach(ThreadRef thread) { + return ThrDetachThread(thread); +} - /// @brief Max path structure. - constexpr auto kMaxPathLen = 255; - static constexpr auto kCanaryValue = 0xf0f0488f; +PTHREAD_SAFE SInt32 pthread_yield(void) { + return ThrYieldThread(pthread_self()); +} - /// @brief Thread Information Structure. - struct ThreadFrameParams final { - SInt64 fCanary; - VoidPtr fStackPtr; - VoidPtr fCodePtr; - SizeT fCodeSz; - SizeT fStackSz; - SInt64 fThrdID; - SInt64 fUsrID, fGrpID; - SInt64* fFD{}; - SizeT fFDCnt; - Char fCWD[kMaxPathLen]; - Char fRoot[kMaxPathLen]; - ThreadRef fRef; - }; +PTHREAD_SAFE ThreadRef pthread_self(Void) { + return ThrCurrentThread(); +} -} // namespace POSIX::Detail +PTHREAD_SAFE SInt32 pthread_exit(SInt32 retval) { + return ThrExitCurrentThread(retval); +} +PTHREAD_SAFE SInt32 pthread_join(ThreadRef thread, VoidPtr* retval) { + SInt32* ret = (SInt32*) retval; + if (!ret) return -1; + *ret = ThrJoinThread(thread); + return 0; +} + +PTHREAD_SAFE SInt32 pthread_create(_Output ThreadRef* thread, VoidPtr attr, + VoidPtr (*start_routine)(VoidPtr), VoidPtr arg) { + LIBSYS_UNUSED(attr); + + if (!attr || !thread || !arg || !start_routine) return -1; + + /// @note passing zero means you'd have to read the argv until you hit a nullptr. + ThreadRef thrd = ThrCreateThread("pthread_thread", (ThrProcKind) start_routine, 0, arg, 0); + + if (!thrd) return -1; + + *thread = thrd; + return 0; +} diff --git a/src/libSoundSystem/SoundSystemKit/VirtualMixer.h b/src/libSoundSystem/SoundSystemKit/VirtualMixer.h index 69fa341a..c0883ae9 100644 --- a/src/libSoundSystem/SoundSystemKit/VirtualMixer.h +++ b/src/libSoundSystem/SoundSystemKit/VirtualMixer.h @@ -10,9 +10,11 @@ #include <libSystem/SystemKit/System.h> namespace SoundSystem { + struct VirtualMixer; struct VirtualSource; struct VirtualVolume; + } // namespace SoundSystem #endif diff --git a/src/libSoundSystem/src/VirtualMixer.cpp b/src/libSoundSystem/src/VirtualMixer.cpp index 792bb672..0316b27f 100644 --- a/src/libSoundSystem/src/VirtualMixer.cpp +++ b/src/libSoundSystem/src/VirtualMixer.cpp @@ -6,4 +6,3 @@ #include <SoundSystemKit/VirtualMixer.h> namespace SoundSystem {} - diff --git a/src/libSystem/SystemKit/Macros.h b/src/libSystem/SystemKit/Macros.h index 37150b01..1673d427 100644 --- a/src/libSystem/SystemKit/Macros.h +++ b/src/libSystem/SystemKit/Macros.h @@ -15,6 +15,9 @@ #define ATTRIBUTE(X) __attribute__((X)) +#define __THREAD_SAFE ATTRIBUTE(thread_safe) +#define __THREAD_UNSAFE + #define IMPORT_CXX extern "C++" #define IMPORT_C extern "C" @@ -91,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/src/libSystem/SystemKit/System.h b/src/libSystem/SystemKit/System.h index 4e766d9d..324aae5c 100644 --- a/src/libSystem/SystemKit/System.h +++ b/src/libSystem/SystemKit/System.h @@ -21,6 +21,8 @@ /// @brief Types API. // ------------------------------------------------------------------------------------------ // +/// @brief Reference type, used for all references in the system, such as file descriptors, dylib +/// handles, thread handles, etc. struct REF_TYPE { UInt64 __hash; /// @brief Hash of the syscall VoidPtr __self; /// @brief Syscall self value. @@ -210,12 +212,15 @@ typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); /// @param flags Thread flags. /// @return the thread object. IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, - SInt32 argument_count, SInt32 flags); + SInt32 argument_count, VoidPtr args, SInt32 flags); /// @brief Yields the current thread. /// @param thread the thread to yield. IMPORT_C SInt32 ThrYieldThread(ThreadRef thrd); +/// @brief Get the current thread's ID. +IMPORT_C ThreadRef ThrCurrentThread(Void); + /// @brief Joins a thread. /// @param thread the thread to join. IMPORT_C SInt32 ThrJoinThread(ThreadRef thrd); @@ -389,4 +394,18 @@ IMPORT_C Char* StrFmt(const Char* fmt, ...); IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); +// ------------------------------------------------------------------------------------------ // +// @brief Semaphore API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Create a semaphore. +IMPORT_C _Output SemaphoreRef SemCreate(_Input UInt32 initial_count, _Input UInt32 max_count, + _Input const Char* name); + +/// @brief Wait on a semaphore. +IMPORT_C SInt32 SemWait(_Input SemaphoreRef sem); + +/// @brief Close a semaphore. +IMPORT_C SInt32 SemClose(_Input SemaphoreRef sem); + #endif // ifndef SYSTEMKIT_SYSTEM_H diff --git a/src/libSystem/libSystem.json b/src/libSystem/libSystem.json index 16557645..14f4bfc5 100644 --- a/src/libSystem/libSystem.json +++ b/src/libSystem/libSystem.json @@ -17,5 +17,5 @@ "kLibSystemVersionHighest=0x0100", "kLibSystemVersionLowest=0x0100" ], - "description": "The System Call Kit for the NeKernel Stack." + "description": "The System Call Kit for the NeSystem." } diff --git a/src/libSystem/src/JailCalls.cpp b/src/libSystem/src/JailCalls.cpp index 674e916a..e5e11a43 100644 --- a/src/libSystem/src/JailCalls.cpp +++ b/src/libSystem/src/JailCalls.cpp @@ -11,5 +11,6 @@ using namespace LibSystem; -IMPORT_C struct JAIL* JailGetCurrent(Void) { return (struct JAIL*) libsys_syscall_arg_1(SYSCALL_HASH("JailGetCurrent")); } - +IMPORT_C struct JAIL* JailGetCurrent(Void) { + return (struct JAIL*) libsys_syscall_arg_1(SYSCALL_HASH("JailGetCurrent")); +} diff --git a/src/libSystem/src/SystemCalls.cpp b/src/libSystem/src/SystemCalls.cpp index 470bc237..c5497f91 100644 --- a/src/libSystem/src/SystemCalls.cpp +++ b/src/libSystem/src/SystemCalls.cpp @@ -3,7 +3,6 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - #include <libSystem/SystemKit/Err.h> #include <libSystem/SystemKit/Syscall.h> #include <libSystem/SystemKit/System.h> @@ -126,7 +125,9 @@ IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) Verify::sys_safe_cast<Char, Void>(drv_letter))); } -IMPORT_C Void IoCloseFile(_Input Ref desc) { libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast<VoidPtr>(desc)); } +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast<VoidPtr>(desc)); +} IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("IoSeekFile"), static_cast<VoidPtr>(desc), @@ -134,7 +135,7 @@ IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { if (!ret_ptr) return ~0UL; - auto ret = static_cast<volatile UInt64*>(ret_ptr); + auto ret = static_cast<volatile UInt64*>(ret_ptr); UInt64 result = *ret; MUST_PASS(result != ~0UL); @@ -160,7 +161,9 @@ IMPORT_C SInt32 PrintRelease(_Input IORef buf) { return static_cast<SInt32>(*ret); } -IMPORT_C IORef PrintCreate(Void) { return static_cast<IORef>(libsys_syscall_arg_1(SYSCALL_HASH("PrintCreate"))); } +IMPORT_C IORef PrintCreate(Void) { + return static_cast<IORef>(libsys_syscall_arg_1(SYSCALL_HASH("PrintCreate"))); +} IMPORT_C VoidPtr MmCreateHeap(UInt64 initial_size, UInt32 max_size) { return static_cast<VoidPtr>(libsys_syscall_arg_3(SYSCALL_HASH("MmCreateHeap"), @@ -223,4 +226,3 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) { IMPORT_C UInt64 PrintSize(IORef ref) { return *static_cast<UInt64*>(libsys_syscall_arg_2(SYSCALL_HASH("PrintSize"), ref)); } - diff --git a/test/kernel_tests/libsystem_tests/thread.test.cc b/test/kernel_tests/libsystem_tests/thread.test.cc index db248e26..28c9196c 100644 --- a/test/kernel_tests/libsystem_tests/thread.test.cc +++ b/test/kernel_tests/libsystem_tests/thread.test.cc @@ -1,6 +1,6 @@ /// \file thread.test.cc /// \brief Threading API tests. -/// \author Amlal El Mahrouss (amlal at nekernel dot org) +/// \author Amlal El Mahrouss (amlal at nekernel dot org) (2025-2026) #include <libSystem/SystemKit/System.h> #include <public/frameworks/KernelTest.fwrk/headers/TestCase.h> diff --git a/tools/chk.hefs.cpp b/tools/chk.hefs.cpp index 69a4312c..8bdbfeb8 100644 --- a/tools/chk.hefs.cpp +++ b/tools/chk.hefs.cpp @@ -3,15 +3,14 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - -#include <tools/libmkfs/mkfs.hpp> -#include <tools/libmkfs/openhefs.hpp> #include <cstdlib> #include <fstream> +#include <tools/libmkfs/mkfs.hpp> +#include <tools/libmkfs/openhefs.hpp> /// @note decimal base. static uint16_t kNumericalBase = 10; -static auto kMinArgs = 2; +static auto kMinArgs = 2; int main(int argc, char** argv) { if (argc < kMinArgs) { @@ -20,9 +19,9 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - auto args = mkfs::detail::build_args(argc, argv); + auto args = mkfs::detail::build_args(argc, argv); auto opt_disk = mkfs::get_option<char>(args, "in"); - auto origin = mkfs::get_option<char>(args, "b"); + auto origin = mkfs::get_option<char>(args, "b"); if (opt_disk.empty()) { mkfs::console_out() << "chk: hefs: error: OpenHeFS partition is empty! Exiting..." @@ -58,8 +57,8 @@ int main(int argc, char** argv) { if (strncmp(boot_node.magic, kOpenHeFSMagic, kOpenHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || boot_node.sectorSize < kMkFsSectorSz) { - mkfs::console_out() << "chk: hefs: error: Device does not contain an OpenHeFS disk: " << opt_disk - << "\n"; + mkfs::console_out() << "chk: hefs: error: Device does not contain an OpenHeFS disk: " + << opt_disk << "\n"; return EXIT_FAILURE; } diff --git a/tools/mkfs.hefs.cpp b/tools/mkfs.hefs.cpp index ad60c675..c6e528ad 100644 --- a/tools/mkfs.hefs.cpp +++ b/tools/mkfs.hefs.cpp @@ -3,14 +3,13 @@ // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel - -#include <tools/libmkfs/mkfs.hpp> -#include <tools/libmkfs/openhefs.hpp> #include <algorithm> #include <cstdlib> #include <cstring> #include <fstream> #include <limits> +#include <tools/libmkfs/mkfs.hpp> +#include <tools/libmkfs/openhefs.hpp> static std::uint16_t kVersion = kOpenHeFSVersion; static std::uint16_t kNumericalBase = 10; |
