diff options
| -rw-r--r-- | CMakeLists.txt | 7 | ||||
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/context_switching/descriptor_table/gdt_flags.hpp | 68 | ||||
| -rw-r--r-- | arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp | 6 |
4 files changed, 90 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8657cab..3717788 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,13 @@ add_library("_exception" OBJECT) add_library("teachos::exception" ALIAS "_exception") #[============================================================================[ +# The Context switching Library +#]============================================================================] + +add_library("_context" OBJECT) +add_library("teachos::context_switching" ALIAS "_context") + +#[============================================================================[ # The Shared Library #]============================================================================] diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index e9f8d5f..8cb1ca2 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -82,6 +82,15 @@ target_sources("_exception" PRIVATE ) #[============================================================================[ +# The Context switching Library +#]============================================================================] + +target_sources("_context" PRIVATE + "src/context_switching/descriptor_table/gdt_flags.cpp" + "src/context_switching/descriptor_table/access_byte.cpp" +) + +#[============================================================================[ # The Bootable ISO Image #]============================================================================] diff --git a/arch/x86_64/include/arch/context_switching/descriptor_table/gdt_flags.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/gdt_flags.hpp index e69de29..83a7c06 100644 --- a/arch/x86_64/include/arch/context_switching/descriptor_table/gdt_flags.hpp +++ b/arch/x86_64/include/arch/context_switching/descriptor_table/gdt_flags.hpp @@ -0,0 +1,68 @@ +#ifndef TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP +#define TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP + +#include <bitset> +#include <cstdint> + +namespace teachos::arch::context_switching::descriptor_table +{ + /** + * @brief Defines helper function for all states that the global descriptor flags of a segment descriptor can + * have. + * + * @note See https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html for more information. + */ + struct gdt_flags + { + /** + * @brief Possible set bits in our underlying std::bitset and the meaning when they are set. + */ + enum bitset : uint8_t + { + GRANULARITY = 1U << 0U, ///< Indicates the size the Limit value in the segement descriptor is scaled by 1 Byte + ///< blocks if the bit is not set or by 4 KiB blocks if the bit is set. + PROTECTED_MODE_SEGMENT_16_OR_32_BIT_SIZE = 1U << 1U, ///< Descriptor defines either a 16-bit protected mdoe + ///< segment if bit is not set or 32-bit if the bit is set. + ENABLE_LONG_MODE = 1U << 2U ///< If set the descriptor defines a 64-bit code segment, when set + ///< PROTECTED_MODE_SEGMENT_16_OR_32_BIT_SIZE should always be clear. For other types + ///< of segments bit should not be set. + }; + + /** + * @brief Constructor. + * + * @param flags Actual value read from the elf section header, which should be converted into a std::bitset, to + * allow reading the state of single bits more easily. Only the first 3 bit of the value will actually be converted + * into the std::bitset, because the latter 4 bits are not relevant and the 4th bit is reserved. + */ + explicit gdt_flags(uint8_t flags) + : flags(flags >> 5U) + { + // Nothing to do + } + + /** + * @brief Checks if the given std::bitset is a subset or equivalent to the underlying std::bitset. + * + * @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. + * + * @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. + */ + auto contains_flags(std::bitset<4U> other) const -> bool; + + /** + * @brief Allows to compare the underlying std::bitset 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. + */ + auto operator==(gdt_flags const & other) const -> bool = default; + + private: + std::bitset<4U> flags; ///< Underlying bitset used to read the flags from. + }; +} // namespace teachos::arch::context_switching::descriptor_table + +#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_PHYSICAL_FRAME_HPP diff --git a/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp b/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp new file mode 100644 index 0000000..8a05956 --- /dev/null +++ b/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp @@ -0,0 +1,6 @@ +#include "arch/context_switching/descriptor_table/gdt_flags.hpp" + +namespace teachos::arch::context_switching::descriptor_table +{ + auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool { return (flags & other) == other; } +} // namespace teachos::arch::context_switching::descriptor_table |
