diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 15:01:43 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 15:01:43 +0100 |
| commit | b157e2c472d8bd67ac1656404a6a6ee821260f4b (patch) | |
| tree | 9c4ebaee21c9ad3521f86c543dc1f29906305baa | |
| parent | c2b0bdfe3b725166f16c742cdaca7969052df382 (diff) | |
| download | teachos-b157e2c472d8bd67ac1656404a6a6ee821260f4b.tar.xz teachos-b157e2c472d8bd67ac1656404a6a6ee821260f4b.zip | |
chore: reformat source code
57 files changed, 518 insertions, 259 deletions
diff --git a/.clang-format b/.clang-format index 714f716..6d3fa9d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,80 +1,116 @@ --- -AccessModifierOffset: '-2' +AccessModifierOffset: "-2" AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: 'false' -AlignConsecutiveDeclarations: 'false' -AlignEscapedNewlines: Left -AlignOperands: 'true' -AlignTrailingComments: 'true' -AllowAllParametersOfDeclarationOnNextLine: 'true' -AllowShortBlocksOnASingleLine: 'false' -AllowShortCaseLabelsOnASingleLine: 'false' -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: 'false' -AllowShortLoopsOnASingleLine: 'false' +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignEscapedNewlines: LeftWithLastLine +AlignTrailingComments: "true" +AllowAllParametersOfDeclarationOnNextLine: "true" +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: "false" +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: "false" AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None -AlwaysBreakTemplateDeclarations: 'true' -BinPackArguments: 'true' -BinPackParameters: 'true' +AlwaysBreakTemplateDeclarations: "true" +BinPackArguments: "true" +BinPackParameters: "true" BreakBeforeBraces: Custom BraceWrapping: - AfterClass: 'true' - AfterControlStatement: 'true' - AfterEnum: 'true' - AfterFunction: 'true' - AfterNamespace: 'true' - AfterStruct: 'true' - AfterUnion: 'true' - AfterExternBlock: 'true' - BeforeCatch: 'true' - BeforeElse: 'true' - IndentBraces: 'false' -BreakBeforeInheritanceComma: 'false' + AfterClass: "true" + AfterControlStatement: "true" + AfterEnum: "true" + AfterFunction: "true" + AfterNamespace: "true" + AfterStruct: "true" + AfterUnion: "true" + AfterExternBlock: "true" + BeforeCatch: "true" + BeforeElse: "true" + IndentBraces: "false" + AfterCaseLabel: true + SplitEmptyFunction: false + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeInheritanceComma: "false" BreakConstructorInitializers: BeforeComma -BreakStringLiterals: 'true' -ColumnLimit: '120' -CompactNamespaces: 'false' -Cpp11BracedListStyle: 'true' -DerivePointerAlignment: 'false' -FixNamespaceComments: 'true' +BreakStringLiterals: "true" +ColumnLimit: "120" +CompactNamespaces: "false" +Cpp11BracedListStyle: "true" +DerivePointerAlignment: "false" +FixNamespaceComments: "true" IncludeBlocks: Regroup IncludeCategories: - # Kernel API Headers - - Regex: 'kapi/[[:alnum:]._\/]+\.hpp' + - Regex: kapi/[[:alnum:]._\/]+\.hpp Priority: 100 - # Architecture Implementation Headers - - Regex: 'x86_64/[[:alnum:]._\/]+\.hpp' + - Regex: x86_64/[[:alnum:]._\/]+\.hpp Priority: 110 - # Library Headers - - Regex: '[[:alnum:]._\/]+\.hpp' + - Regex: "[[:alnum:]._\\/]+\\.hpp" Priority: 300 - # STL Headers - - Regex: '<[[:alnum:]._]+(?!\.(h|hpp))>' + - Regex: <[[:alnum:]._]+(?!\.(h|hpp))> Priority: 900 -IndentCaseLabels: 'true' +IndentCaseLabels: "true" IndentPPDirectives: None -IndentWidth: '2' -KeepEmptyLinesAtTheStartOfBlocks: 'false' +IndentWidth: "2" +KeepEmptyLinesAtTheStartOfBlocks: "false" Language: Cpp -MaxEmptyLinesToKeep: '1' +MaxEmptyLinesToKeep: "1" NamespaceIndentation: All PointerAlignment: Middle -ReflowComments: 'true' -SortIncludes: 'true' -SortUsingDeclarations: 'true' -SpaceAfterCStyleCast: 'false' -SpaceAfterTemplateKeyword: 'false' -SpaceBeforeAssignmentOperators: 'true' +ReflowComments: "true" +SortIncludes: "true" +SortUsingDeclarations: "true" +SpaceAfterCStyleCast: "false" +SpaceAfterTemplateKeyword: "false" +SpaceBeforeAssignmentOperators: "true" SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: 'false' -SpacesBeforeTrailingComments: '2' -SpacesInAngles: 'false' -SpacesInContainerLiterals: 'false' -SpacesInCStyleCastParentheses: 'false' -SpacesInParentheses: 'false' -SpacesInSquareBrackets: 'false' -Standard: Cpp11 -TabWidth: '2' +SpaceInEmptyParentheses: "false" +SpacesBeforeTrailingComments: "2" +SpacesInAngles: "false" +SpacesInContainerLiterals: "false" +SpacesInCStyleCastParentheses: "false" +SpacesInParentheses: "false" +SpacesInSquareBrackets: "false" +Standard: Latest +TabWidth: "2" UseTab: Never -... +AlignArrayOfStructures: Right +AlignConsecutiveBitFields: {} +AllowAllArgumentsOnNextLine: false +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortCaseExpressionOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortLambdasOnASingleLine: Inline +BitFieldColonSpacing: Both +BracedInitializerIndentWidth: 2 +IntegerLiteralSeparator: + Binary: 4 + BinaryMinDigits: 8 + Decimal: 3 + DecimalMinDigits: 6 + Hex: 4 + HexMinDigits: 8 +QualifierAlignment: Custom +QualifierOrder: + - constexpr + - type + - static + - inline + - const +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/x86_64/boot/boot.hpp index 86f8ce3..3a3620d 100644 --- a/arch/x86_64/include/x86_64/boot/boot.hpp +++ b/arch/x86_64/include/x86_64/boot/boot.hpp @@ -2,6 +2,7 @@ #define TEACHOS_X86_64_BOOT_BOOT_H #ifdef __ASSEMBLER__ +/* clang-format off */ /** * @brief The number of huge pages to map during bootstrap. */ @@ -41,7 +42,7 @@ * @brief The "L" bit in a GDT entry. */ #define GDT_LONG_MODE (1 << 53) - +/* clang-format on */ #else #include <multiboot2/information.hpp> diff --git a/arch/x86_64/include/x86_64/vga/crtc.hpp b/arch/x86_64/include/x86_64/vga/crtc.hpp index e5ab9f1..be72ac4 100644 --- a/arch/x86_64/include/x86_64/vga/crtc.hpp +++ b/arch/x86_64/include/x86_64/vga/crtc.hpp @@ -22,12 +22,12 @@ namespace teachos::vga::x86_64::crtc /** * @brief The address of the Cursor Start register of the CRTC. */ - [[maybe_unused]] auto constexpr cursor_start = std::byte{0x0a}; + [[maybe_unused]] constexpr auto cursor_start = std::byte{0x0a}; /** * @brief The address of the Cursor End register of the CRTC. */ - [[maybe_unused]] auto constexpr cursor_end = std::byte{0x0b}; + [[maybe_unused]] constexpr auto cursor_end = std::byte{0x0b}; } // namespace registers } // namespace teachos::vga::x86_64::crtc diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp index c193576..858350f 100644 --- a/arch/x86_64/include/x86_64/vga/text.hpp +++ b/arch/x86_64/include/x86_64/vga/text.hpp @@ -68,25 +68,25 @@ namespace teachos::vga::x86_64::text /** * @brief Make the affected cell display with a gray foreground and black background. */ - [[maybe_unused]] auto constexpr gray_on_black = + [[maybe_unused]] constexpr auto gray_on_black = attribute{color::gray, foreground_flag::none, color::black, background_flag::none}; /** * @brief Make the affected cell display with a green foreground and black background. */ - [[maybe_unused]] auto constexpr green_on_black = + [[maybe_unused]] constexpr auto green_on_black = attribute{color::green, foreground_flag::none, color::black, background_flag::none}; /** * @brief Make the affected cell display with a green foreground and black background. */ - [[maybe_unused]] auto constexpr red_on_black = + [[maybe_unused]] constexpr auto red_on_black = attribute{color::red, foreground_flag::none, color::black, background_flag::none}; /** * @brief Make the affected cell display with a white (gray + intense) foreground and red background. */ - [[maybe_unused]] auto constexpr white_on_red = + [[maybe_unused]] constexpr auto white_on_red = attribute{color::gray, foreground_flag::intense, color::red, background_flag::none}; } // namespace common_attributes @@ -108,10 +108,22 @@ namespace teachos::vga::x86_64::text */ auto cursor(bool enabled) -> void; - auto write(std::string_view text) -> void override { write(text, common_attributes::green_on_black); } - auto writeln(std::string_view text) -> void override { writeln(text, common_attributes::green_on_black); } - auto write_error(std::string_view text) -> void override { write(text, common_attributes::red_on_black); } - auto writeln_error(std::string_view text) -> void override { writeln(text, common_attributes::red_on_black); } + auto write(std::string_view text) -> void override + { + write(text, common_attributes::green_on_black); + } + auto writeln(std::string_view text) -> void override + { + writeln(text, common_attributes::green_on_black); + } + auto write_error(std::string_view text) -> void override + { + write(text, common_attributes::red_on_black); + } + auto writeln_error(std::string_view text) -> void override + { + writeln(text, common_attributes::red_on_black); + } private: /** diff --git a/arch/x86_64/pre/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp b/arch/x86_64/pre/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp index 2a7704e..ea8c145 100644 --- a/arch/x86_64/pre/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp +++ b/arch/x86_64/pre/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp @@ -96,9 +96,9 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table private: uint8_t _flags : 3 = {}; ///< Underlying bits used to read the flags from. - uint16_t _index : 13 = - {}; ///< Index into the local or global descriptor table. Processor multiplies the index value by 16 (number of - ///< bytes in segment descriptor) and adds the result to the base address. + uint16_t _index + : 13 = {}; ///< Index into the local or global descriptor table. Processor multiplies the index value by 16 + ///< (number of bytes in segment descriptor) and adds the result to the base address. }; } // namespace teachos::arch::context_switching::interrupt_descriptor_table diff --git a/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp b/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp index 59adc13..f507c61 100644 --- a/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp +++ b/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp @@ -41,7 +41,10 @@ namespace teachos::arch::context_switching::syscall * @param e Error code that was returned by the syscall. * @return Return true if there was no error and false otherwise. */ - constexpr bool operator!(error e) { return e == error::OK; } + constexpr bool operator!(error e) + { + return e == error::OK; + } /** * @brief Maximum amount of arguments that can be passed to a syscall. Default value is 0 and arguments are only ever diff --git a/arch/x86_64/pre/include/arch/memory/allocator/tiny_frame_allocator.hpp b/arch/x86_64/pre/include/arch/memory/allocator/tiny_frame_allocator.hpp index 1ceb74d..1e4746d 100644 --- a/arch/x86_64/pre/include/arch/memory/allocator/tiny_frame_allocator.hpp +++ b/arch/x86_64/pre/include/arch/memory/allocator/tiny_frame_allocator.hpp @@ -10,7 +10,7 @@ namespace teachos::arch::memory::allocator { namespace { - uint8_t constexpr TINY_ALLOCATOR_FRAMES_COUNT = 3U; + constexpr uint8_t TINY_ALLOCATOR_FRAMES_COUNT = 3U; } /** diff --git a/arch/x86_64/pre/include/arch/memory/heap/global_heap_allocator.hpp b/arch/x86_64/pre/include/arch/memory/heap/global_heap_allocator.hpp index c98c130..480b1d0 100644 --- a/arch/x86_64/pre/include/arch/memory/heap/global_heap_allocator.hpp +++ b/arch/x86_64/pre/include/arch/memory/heap/global_heap_allocator.hpp @@ -37,7 +37,7 @@ namespace teachos::arch::memory::heap * * @param new_type Type of the heap allocation implementation we want to instantiate */ - static auto register_heap_allocator(heap_allocator_type new_type) -> void; + auto static register_heap_allocator(heap_allocator_type new_type) -> void; /** * @brief Allocates the given amount of memory and returns the pointer to the start of the allocatable memory area. @@ -46,7 +46,7 @@ namespace teachos::arch::memory::heap * @param size Amount of bytes that should be allocated * @return void* Pointer to the start of the allocatable memory area */ - static auto kmalloc(std::size_t size) -> void *; + auto static kmalloc(std::size_t size) -> void *; /** * @brief Deallocated all memory associated with the memory area starting from the given pointer address. @@ -54,7 +54,7 @@ namespace teachos::arch::memory::heap * * @param pointer Previously allocated memory area, that should now be freed */ - static auto kfree(void * pointer) noexcept -> void; + auto static kfree(void * pointer) noexcept -> void; /** * @brief Allocates the given amount of memory and returns the pointer to the start of the allocatable memory area. @@ -64,7 +64,7 @@ namespace teachos::arch::memory::heap * @return void* Pointer to the start of the allocatable memory area */ [[gnu::section(".user_text")]] - static auto malloc(std::size_t size) -> void *; + auto static malloc(std::size_t size) -> void *; /** * @brief Deallocated all memory associated with the memory area starting from the given pointer address. @@ -73,11 +73,11 @@ namespace teachos::arch::memory::heap * @param pointer Previously allocated memory area, that should now be freed */ [[gnu::section(".user_text")]] - static auto free(void * pointer) noexcept -> void; + auto static free(void * pointer) noexcept -> void; private: - static heap_allocator * kernel_allocator_instance; ///< Instance used to allocate and deallocate kernel heap memory - [[gnu::section(".user_data")]] static user_heap_allocator * + heap_allocator static * kernel_allocator_instance; ///< Instance used to allocate and deallocate kernel heap memory + [[gnu::section(".user_data")]] user_heap_allocator static * user_allocator_instance; ///< Instance used to allocate and deallocate user heap memory /** @@ -85,15 +85,14 @@ namespace teachos::arch::memory::heap * * @return Reference to the registered kernel heap allocation */ - static auto kernel() -> heap_allocator &; + auto static kernel() -> heap_allocator &; /** * @brief Either returns the previously registered heap allocated or halts further execution * * @return Reference to the registered user heap allocation */ - [[gnu::section(".user_text")]] - static auto user() -> user_heap_allocator &; + [[gnu::section(".user_text")]] auto static user() -> user_heap_allocator &; }; } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/pre/include/arch/memory/heap/heap_allocator.hpp b/arch/x86_64/pre/include/arch/memory/heap/heap_allocator.hpp index 420a1d3..6c25532 100644 --- a/arch/x86_64/pre/include/arch/memory/heap/heap_allocator.hpp +++ b/arch/x86_64/pre/include/arch/memory/heap/heap_allocator.hpp @@ -5,10 +5,10 @@ namespace teachos::arch::memory::heap { - std::size_t constexpr KERNEL_HEAP_START = 0x100000000; - std::size_t constexpr KERNEL_HEAP_SIZE = 100 * 1024; - std::size_t constexpr USER_HEAP_START = 0x100019000; // Starts directly after kernel heap - std::size_t constexpr USER_HEAP_SIZE = 100 * 1024; + constexpr std::size_t KERNEL_HEAP_START = 0x1'0000'0000; + constexpr std::size_t KERNEL_HEAP_SIZE = 100 * 1024; + constexpr std::size_t USER_HEAP_START = 0x1'0001'9000; // Starts directly after kernel heap + constexpr std::size_t USER_HEAP_SIZE = 100 * 1024; /** * @brief Heap allocator interface containing methods required to allocate and deallocate heap memory areas diff --git a/arch/x86_64/pre/include/arch/memory/heap/linked_list_allocator.hpp b/arch/x86_64/pre/include/arch/memory/heap/linked_list_allocator.hpp index bbbad19..540ff5c 100644 --- a/arch/x86_64/pre/include/arch/memory/heap/linked_list_allocator.hpp +++ b/arch/x86_64/pre/include/arch/memory/heap/linked_list_allocator.hpp @@ -3,7 +3,6 @@ #include "arch/memory/heap/heap_allocator.hpp" #include "arch/memory/heap/memory_block.hpp" - #include <kstd/mutex.hpp> namespace teachos::arch::memory::heap @@ -44,7 +43,10 @@ namespace teachos::arch::memory::heap * * @return Smallest allocatable block of heap memory. */ - auto constexpr min_allocatable_size() -> std::size_t { return sizeof(memory_block); } + constexpr auto min_allocatable_size() -> std::size_t + { + return sizeof(memory_block); + } /** * @brief Removes a free memory block from the free list and returns its address so the caller can allocate into it. diff --git a/arch/x86_64/pre/include/arch/memory/heap/user_heap_allocator.hpp b/arch/x86_64/pre/include/arch/memory/heap/user_heap_allocator.hpp index 3b47f15..15d8574 100644 --- a/arch/x86_64/pre/include/arch/memory/heap/user_heap_allocator.hpp +++ b/arch/x86_64/pre/include/arch/memory/heap/user_heap_allocator.hpp @@ -5,6 +5,7 @@ // #include <kstd/mutex.hpp> #include <kstd/mutex.hpp> + #include <optional> namespace |
