From e8fb1d771d9aa4d1cb5b18cd0483c7e5731aeecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Mon, 31 Mar 2025 13:18:56 +0000 Subject: Improve create_segment readability --- .../interrupt_descriptor_table/idt_flags.hpp | 15 +++++++++++---- .../interrupt_descriptor_table/segment_selector.hpp | 15 +++++++++++---- .../segment_descriptor_table/access_byte.hpp | 19 +++++++++++++------ .../segment_descriptor_table/gdt_flags.hpp | 15 +++++++++++---- 4 files changed, 46 insertions(+), 18 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp index f153e36..2f8e61d 100644 --- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp +++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp @@ -48,13 +48,13 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table idt_flags(uint8_t flags); /** - * @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset. + * @brief Checks if the given std::bitset is a subset or equivalent to the underlying data. * * @note Meaning that all bits that are set in the given std::bitset also have to be set in the underlyng - * std::bitset. Any additional bits that are set are not relevant. + * data. Any additional bits that are set are not relevant. * - * @param other Flags that we want to compare against and check if the underlying std::bitset has the same bits set. - * @return Whether the given flags are a subset or equivalent with the underlying std::bitset. + * @param other Flags that we want to compare against and check if the underlying data has the same bits set. + * @return Whether the given flags are a subset or equivalent with the underlying data. */ auto contains_flags(std::bitset<8U> other) const -> bool; @@ -66,6 +66,13 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table */ auto operator==(idt_flags const & other) const -> bool = default; + /** + * @brief Combines all bits that are set in the std::bitset flags with the bits already set in the underlying data. + * + * @param other Additional bits that should be set. + */ + auto operator|=(std::bitset<8U> other) -> void; + private: uint8_t _flags = {}; ///< Underlying bits used to read the flags from. }; diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp index 73cd176..2c90152 100644 --- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp +++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp @@ -51,13 +51,13 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table segment_selector(uint16_t index, uint8_t flags); /** - * @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset. + * @brief Checks if the given std::bitset is a subset or equivalent to the underlying data. * * @note Meaning that all bits that are set in the given std::bitset also have to be set in the underlyng - * std::bitset. Any additional bits that are set are not relevant. + * data. Any additional bits that are set are not relevant. * - * @param other Flags that we want to compare against and check if the underlying std::bitset has the same bits set. - * @return Whether the given flags are a subset or equivalent with the underlying std::bitset. + * @param other Flags that we want to compare against and check if the underlying data has the same bits set. + * @return Whether the given flags are a subset or equivalent with the underlying data. */ auto contains_flags(std::bitset<3U> other) const -> bool; @@ -66,6 +66,13 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table */ auto operator<=>(segment_selector const & other) const -> std::strong_ordering = default; + /** + * @brief Combines all bits that are set in the std::bitset flags with the bits already set in the underlying data. + * + * @param other Additional bits that should be set. + */ + auto operator|=(std::bitset<3U> other) -> void; + private: uint8_t _flags : 3 = {}; ///< Underlying bits used to read the flags from. uint16_t _index : 13 = diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp index 3d7862c..621b570 100644 --- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp +++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp @@ -71,24 +71,31 @@ namespace teachos::arch::context_switching::segment_descriptor_table access_byte(uint8_t flags); /** - * @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset. + * @brief Checks if the given std::bitset is a subset or equivalent to the underlying data. * * @note Meaning that all bits that are set in the given std::bitset also have to be set in the underlyng - * std::bitset. Any additional bits that are set are not relevant. + * data. Any additional bits that are set are not relevant. * - * @param other Flags that we want to compare against and check if the underlying std::bitset has the same bits set. - * @return Whether the given flags are a subset or equivalent with the underlying std::bitset. + * @param other Flags that we want to compare against and check if the underlying data has the same bits set. + * @return Whether the given flags are a subset or equivalent with the underlying data. */ auto contains_flags(std::bitset<8U> other) const -> bool; /** - * @brief Allows to compare the underlying std::bitset of two instances. + * @brief Allows to compare the underlying data of two instances. * * @param other Other instance that we want to compare with. - * @return Whether the underlying std::bitset of both types is the same. + * @return Whether the underlying data of both types is the same. */ auto operator==(access_byte const & other) const -> bool = default; + /** + * @brief Combines all bits that are set in the std::bitset flags with the bits already set in the underlying data. + * + * @param other Additional bits that should be set. + */ + auto operator|=(std::bitset<8U> other) -> void; + private: uint8_t _flags = {}; ///< Underlying bits used to read the flags from. }; diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp index d8c3cd1..4b84035 100644 --- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp +++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp @@ -50,13 +50,13 @@ namespace teachos::arch::context_switching::segment_descriptor_table gdt_flags(uint8_t flags, std::bitset<20U> limit); /** - * @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset. + * @brief Checks if the given std::bitset is a subset or equivalent to the underlying data. * * @note Meaning that all bits that are set in the given std::bitset also have to be set in the underlyng - * std::bitset. Any additional bits that are set are not relevant. + * data. Any additional bits that are set are not relevant. * - * @param other Flags that we want to compare against and check if the underlying std::bitset has the same bits set. - * @return Whether the given flags are a subset or equivalent with the underlying std::bitset. + * @param other Flags that we want to compare against and check if the underlying data has the same bits set. + * @return Whether the given flags are a subset or equivalent with the underlying data. */ auto contains_flags(std::bitset<4U> other) const -> bool; @@ -77,6 +77,13 @@ namespace teachos::arch::context_switching::segment_descriptor_table */ auto operator==(gdt_flags const & other) const -> bool = default; + /** + * @brief Combines all bits that are set in the std::bitset flags with the bits already set in the underlying data. + * + * @param other Additional bits that should be set. + */ + auto operator|=(std::bitset<4U> other) -> void; + private: uint8_t _limit_2 : 4 = {}; ///< Second part of the limit field. uint8_t _flags : 4 = {}; ///< Underlying bits used to read the flags from. -- cgit v1.2.3