aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-10 16:05:31 +0000
committerMatteo Gmür <matteo.gmuer1@ost.ch>2025-03-10 16:05:31 +0000
commit52fffdf2c76def4a875e0328eb45d74c6e97e805 (patch)
tree39e712ac4eaa968dd0d3adf4110aa7493cd58713
parentc5151739698620e77622423c109e638f903f01c4 (diff)
downloadteachos-52fffdf2c76def4a875e0328eb45d74c6e97e805.tar.xz
teachos-52fffdf2c76def4a875e0328eb45d74c6e97e805.zip
Adjust segment descriptor to use defined helpers
-rw-r--r--arch/x86_64/CMakeLists.txt1
-rw-r--r--arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp54
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp13
3 files changed, 41 insertions, 27 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index 19c71be..1b8349a 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -89,6 +89,7 @@ target_sources("_context" PRIVATE
"src/context_switching/descriptor_table/gdt_flags.cpp"
"src/context_switching/descriptor_table/access_byte.cpp"
"src/context_switching/descriptor_table/type_field.cpp"
+ "src/context_switching/descriptor_table/segment_descriptor.cpp"
)
#[============================================================================[
diff --git a/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp
index b7665d9..59f99f6 100644
--- a/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp
+++ b/arch/x86_64/include/arch/context_switching/descriptor_table/segment_descriptor.hpp
@@ -1,44 +1,44 @@
#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_HPP
#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_HPP
+#include "arch/context_switching/descriptor_table/access_byte.hpp"
#include "arch/context_switching/descriptor_table/gdt_flags.hpp"
-
-#include <bitset>
+#include "arch/context_switching/descriptor_table/segment_descriptor_type.hpp"
+#include "arch/context_switching/descriptor_table/type_field.hpp"
namespace teachos::arch::context_switching::descriptor_table
{
+ __extension__ typedef __int128 int128_t;
+ __extension__ typedef unsigned __int128 uint128_t;
- /*
- TODO: Lookup segment_descriptor in intel manual chapter 3.4.5
- */
-
+ /**
+ * @brief Defines helper function for all states and the actual data the segment descriptor can have.
+ */
struct segment_descriptor
{
/**
- * @brief Possible set bits in our underlying std::bitset and the meaning when they are set.
+ * @brief Constructor.
+ *
+ * @note Created segment descriptor copies the given bytes into theese components ending with a 32 bit reserved
+ * field that has to be used, because the 64-bit segment descriptor needs to be big enough for two 32-bit segment
+ * descriptor.
+ * - 8 bit Access Type
+ * - 4 bit Flags
+ * - 64 bit Base Address
+ * - 20 bit Limit
+ *
+ * @param flags Copies the bits set from the given data into the individual components of a segment
+ * descriptor.
*/
- enum bitset : uint64_t
- {
- BASE = 1U << 0U,
- FLAGS = 1U << 8U,
- LIMIT = 1U << 12U,
- ACCESS_BYTE = 1U << 16U,
- BASE = 1U << 32U,
- BASE = 1U << 40U,
- LIMIT = 1U << 56U
- };
-
- explicit segment_descriptor(uint64_t flags)
- : flags(flags)
- {
- // Nothing to do
- }
+ explicit segment_descriptor(uint128_t flags);
private:
- std::uint8_t base1;
- gdt_flags flags;
- std::bitset<64U> flags; ///< Underlying bitset used to read the flags from
+ uint32_t _reserved;
+ access_byte _access;
+ gdt_flags _flag;
+ uint64_t _base;
+ std::bitset<20U> _limit;
};
} // namespace teachos::arch::context_switching::descriptor_table
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_HPP \ No newline at end of file
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_HPP
diff --git a/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp b/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
new file mode 100644
index 0000000..fb9c034
--- /dev/null
+++ b/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
@@ -0,0 +1,13 @@
+#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
+
+namespace teachos::arch::context_switching::descriptor_table
+{
+ segment_descriptor::segment_descriptor(uint128_t flags)
+ : _reserved(flags)
+ , _access(flags)
+ , _flag(flags, segment_descriptor_type::SYSTEM_SEGMENT)
+ , _base(flags)
+ , _limit(flags)
+ {
+ }
+} // namespace teachos::arch::context_switching::descriptor_table