aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/pre
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-01-16 17:39:23 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-01-16 17:39:23 +0100
commit7ba274d0838e5cd4e48e85f81557bbb837ed4349 (patch)
treeb792f550634b856e3401ea42dd0ee7089494be28 /arch/x86_64/pre
parentf7fc4cb67c8c7c6ec1833f6ac6f0ad3a2837251d (diff)
downloadteachos-7ba274d0838e5cd4e48e85f81557bbb837ed4349.tar.xz
teachos-7ba274d0838e5cd4e48e85f81557bbb837ed4349.zip
x86_64/cpu: port GDT reload procedure
Diffstat (limited to 'arch/x86_64/pre')
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/access_byte.hpp104
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp93
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp37
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp41
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp73
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp74
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp27
-rw-r--r--arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/task_state_segment.hpp32
-rw-r--r--arch/x86_64/pre/include/arch/kernel/cpu/gdtr.hpp27
-rw-r--r--arch/x86_64/pre/include/arch/kernel/cpu/segment_register.hpp97
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/access_byte.cpp20
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/gdt_flags.cpp26
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp109
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp11
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/segment_descriptor_base.cpp41
-rw-r--r--arch/x86_64/pre/src/context_switching/segment_descriptor_table/segment_descriptor_extension.cpp30
-rw-r--r--arch/x86_64/pre/src/kernel/cpu/gdtr.cpp19
-rw-r--r--arch/x86_64/pre/src/kernel/cpu/msr.cpp31
-rw-r--r--arch/x86_64/pre/src/kernel/cpu/segment_register.cpp98
19 files changed, 0 insertions, 990 deletions
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/access_byte.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/access_byte.hpp
deleted file mode 100644
index 7450330..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/access_byte.hpp
+++ /dev/null
@@ -1,104 +0,0 @@
-
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_ACCESS_BYTE_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_ACCESS_BYTE_HPP
-
-#include <bitset>
-#include <cstdint>
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief Defines helper function for all states that the access byte field of a segment descriptor can
- * have.
- */
- struct [[gnu::packed]] access_byte
- {
- /**
- * @brief Possible set bits in our underlying bits and the meaning when they are set.
- */
- enum bitset : uint8_t
- {
- ACCESSED =
- 1U
- << 0U, ///< Whether the segment has been accessed since the last time the operating system has cleared the
- ///< flag. If enabled it has been accessed, otherwise it has not been accessed since the last clear.
- WRITABLE = 1U << 1U, ///< Indicates if the data segment is writable or not. If enabled the code segment allows
- ///< read and write access, otherwise only read access is possible.
- READABLE = 1U << 1U, ///< Indicates if the code segment is readable or not. If enabled the code segment allows
- ///< read and execute access, otherwise only executable access is possible.
- CONFORMING =
- 1U << 2U, ///< Indicates if the code is allowed to be executed by different access levels
- ///< (higher or lower) in code segments. If enabled the code segment allows access, otherwise
- ///< access from different privilege levels with throw a General-Protectione exception.
- EXPAND_DOWN = 1U << 2U, ///< Indicates if the expansion direction is up or down in data segments. If enabled the
- ///< data segment expands downwards, otherwise it expands upwards.
- CODE_SEGMENT = 1U << 3U, ///< Further defines the actual type of the segment. If enabled this segment is a code
- ///< segment, otherwise its a data segment.
- LOCAL_DESCRIPTOR_TABLE = 2, ///< The actual type of sytem segment is a local descriptor table.
- TASK_STATE_SEGMENT_AVAILABLE =
- 9, ///< The actual type of sytem segment is a task state segment that is still available.
- TASK_STATE_SEGMENT_BUSY = 11, ///< The actual type of sytem segment is a task state segment that is currently in
- ///< use and therefore busy.
- CALL_GATE = 11, ///< The actual type of sytem segment is a call gate.
- INTERRUPT_GATE = 14, ///< The actual type of sytem segment is a interrupt gate.
- TRAP_GATE = 15, ///< The actual type of sytem segment is a trap gate.
- CODE_OR_DATA_SEGMENT = 1U << 4U, ///< Defines a system segment (if 0) or a code/data segment (if 1).
- DESCRIPTOR_LEVEL_KERNEL =
- 0U << 5U, ///< Highest privileged level used by the kernel to allow for full access of resources.
- DESCRIPTOR_LEVEL_ADMIN =
- 1U << 5U, ///< Restricts access to own application and thoose of lower privilege. Should only be used if more
- ///< than two privilege levels are required, otherwise using Level 3 and Level 0 is recommended.
- DESCRIPTOR_LEVEL_PRIVILEGED_USER =
- 2U << 5U, ///< Restricts access to own application and thoose of lower privilege. Should only be used if more
- ///< than two privilege levels are required, otherwise using Level 3 and Level 0 is recommended.
- DESCRIPTOR_LEVEL_USER = 3U << 5U, ///< Restricts access to only application and their specific memory.
- PRESENT = 1U << 7U, ///< Present bit; Allows an entry to refer to a valid segment.
- ///< Must be set (1) for any valid segment.
- };
-
- /**
- * @brief Default Constructor.
- */
- access_byte() = default;
-
- /**
- * @brief Constructor.
- *
- * @param flags Allows to set flags for the access byte field using the unscoped enum contained in this class, used
- * to allow for direct integer conversion. This value is saved and can later be used to check whether certain flags
- * are enabled or not using contains_flags method.
- */
- access_byte(uint8_t flags);
-
- /**
- * @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
- * data. Any additional bits that are set are not relevant.
- *
- * @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 data of two instances.
- *
- * @param other Other instance that we want to compare with.
- * @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.
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_ACCESS_BYTE_HPP \ No newline at end of file
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp
deleted file mode 100644
index e24b988..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp
+++ /dev/null
@@ -1,93 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GDT_FLAGS_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GDT_FLAGS_HPP
-
-#include "arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp"
-
-#include <bitset>
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief Defines helper function for all states that the flags field of a segment descriptor can
- * have.
- */
- struct [[gnu::packed]] gdt_flags
- {
- /**
- * @brief Possible set bits in our underlying bits and the meaning when they are set.
- */
- enum bitset : uint8_t
- {
- LONG_MODE = 1U << 1U, ///< Defines in IA-32e mode (64-bit code and 32-bit compatability mode) if the segment
- ///< contains 64-bit code. Otherwise this bit should always be 0. Enable if instructions
- ///< are executed in 64-bit code, otherwise they are executed in compatability 32-bit mode.
- ///< If this bit is set the 3rd bit needs to be clear (0).
- UPPER_BOUND = 1U << 2U, ///< Specifies the upper bound of the segment for expand down data segment. Enable for 4
- ///< GiB, 4 KiB otherwise.
- STACK_POINTER_SIZE = 1U << 2U, ///< Specifies the size of the Stack Pointer (SP) for stack segments used for
- ///< implicit stack operations. Enable for 32 bit, 16 bit otherwise.
- DEFAULT_LENGTH = 1U << 2U, ///< Indicates the default length for code segments with effective addresses and
- ///< operands. Enable for 32 bit, 16 bit otherwise.
- GRANULARITY = 1U << 3U, ///< Indicates the size the Limit value in the segment descriptor is scaled by 1 Byte
- ///< blocks if the bit is not set or by 4 KiB blocks if the bit is set.
- };
-
- /**
- * @brief Default Constructor.
- */
- gdt_flags() = default;
-
- /**
- * @brief Constructor.
- *
- * @param flags Allows to set flags for the flags field using the unscoped enum contained in this class, used to
- * allow for direct integer conversion. This value is saved and can later be used to check whether certain flags are
- * enabled or not using contains_flags method.
- * @param limit Does not necessarily make sense in the gdt flags type, but because the flags alone are only 4 bit
- * the type would still require the space for a complete bit. Therefore the 4 bit segment limit field before the
- * flags field is included in this type to ensure we actually contain 8 bit of data.
- */
- gdt_flags(uint8_t flags, std::bitset<20U> limit);
-
- /**
- * @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
- * data. Any additional bits that are set are not relevant.
- *
- * @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;
-
- /**
- * @brief Get part of the segment limit that is saved in the gdt flags. This does not necessarily make sense in this
- * object, but it has to be included here because a struct can not be smaller than a full byte. Therefore we include
- * the 4 bit segment limit field so that it results in a compelte byte with the addtional 4 bit of gdt flags.
- *
- * @return 4-bit limit segment
- */
- auto get_limit() const -> std::bitset<4U>;
-
- /**
- * @brief Allows to compare the underlying set bits of two instances.
- *
- * @param other Other instance that we want to compare with.
- * @return Whether the underlying set bits of both types are the same.
- */
- 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.
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GDT_FLAGS_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp
deleted file mode 100644
index 44f2692..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
-
-#include "arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp"
-#include "arch/context_switching/segment_descriptor_table/task_state_segment.hpp"
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief Creates the global descriptor table, with the minimum required configuration. If this method is called more
- * than once, the previously created instance is returned instead.
- *
- * @return Reference to the created global_descriptor_table.
- */
- auto get_or_create_gdt() -> global_descriptor_table &;
-
- /**
- * @brief Updates the GDTR with the created global descriptor table. If it has not been created yet this
- * method will create it.
- *
- * @note This method will only set the GDTR, but for the processor to actually register the change a far jump
- * has to be executed. This also has to be done before updating the TR.
- */
- auto update_gdtr() -> void;
-
- /**
- * @brief Updates the TR with the created task state segment. If it has not been created yet this
- * method will create it.
- *
- * @note This method should only be called after update_gdtr() and a far jump has been
- * executed. Because before that trying to access the segment will cause an exception.
- */
- auto update_tss_register() -> void;
-
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp
deleted file mode 100644
index 292ff70..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
-
-#include "arch/stl/vector.hpp"
-
-#include <cstdint>
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- using global_descriptor_table = stl::vector<uint64_t>;
-
- /**
- * @brief Represents a pointer to the Global Descriptor Table (GDT).
- *
- * This structure is used to store the base address and length of the GDT.
- * It is used when loading or modifying the GDT during context switching.
- */
- struct [[gnu::packed]] global_descriptor_table_pointer
- {
- /**
- * @brief Default constructor.
- */
- global_descriptor_table_pointer() = default;
-
- /**
- * @brief Constructor.
- */
- global_descriptor_table_pointer(uint16_t table_length, uint64_t * address);
-
- /**
- * @brief Defaulted three-way comparsion operator.
- */
- auto operator<=>(global_descriptor_table_pointer const & other) const -> std::strong_ordering = default;
-
- private:
- uint16_t table_length = {}; ///< The amount of segment descriptor entries in the global descriptor table - 1.
- uint64_t * address = {}; ///< Non-owning pointer to the GDT base address.
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp
deleted file mode 100644
index 933fb4d..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_BASE_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_BASE_HPP
-
-#include "arch/context_switching/segment_descriptor_table/access_byte.hpp"
-#include "arch/context_switching/segment_descriptor_table/gdt_flags.hpp"
-#include "arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp"
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief Defines helper function for all states and the actual data the segment descriptor can have.
- */
- struct [[gnu::packed]] segment_descriptor_base
- {
- /**
- * @brief Default Constructor.
- */
- segment_descriptor_base() = default;
-
- /**
- * @brief Constructor.
- *
- * @note Created segment descriptor copies the given bytes into these components requiring the space of one
- * segment descriptor entry in the global descriptor table being 64-bit.
- * - 8 bit Access Type
- * - 4 bit Flags
- * - 32 bit Base Address
- * - 20 bit Limit
- *
- * @param flags Copies the bits set from the given data into the individual components of a segment
- * descriptor.
- */
- explicit segment_descriptor_base(uint64_t flags);
-
- /**
- * @brief Constructor.
- *
- * @param access_byte, flags, base, limit Copies the bits set from the given data into the individual components of
- * a segment descriptor.
- */
- segment_descriptor_base(access_byte access_byte, gdt_flags flags, uint32_t base, std::bitset<20U> limit);
-
- /**
- * @brief Calculates the underlying segment type that this segement descriptor is describing.
- */
- auto get_segment_type() const -> segment_descriptor_type;
-
- /**
- * @brief Cast the underlying data into a combined 64-bit form, that contains all data.
- *
- * @return Underlying value combined into it's full size.
- */
- operator uint64_t() const;
-
- /**
- * @brief Allows to compare the underlying bits of two instances.
- *
- * @param other Other instance that we want to compare with.
- * @return Whether the underlying set bits of both types are the same.
- */
- auto operator==(segment_descriptor_base const & other) const -> bool = default;
-
- private:
- // The order in private variables starts for the first variable being the rightmost bit.
- uint16_t _limit_1 = {}; ///< First part of the limit field (0 - 15)
- uint32_t _base_1 : 24 = {}; ///< First part of the base field (16 - 39)
- access_byte _access = {}; ///< Access byte field (40 - 47)
- gdt_flags _flag = {}; ///< Second part of the limit field + Flags field (48 - 55)
- uint8_t _base_2 = {}; ///< Second part of the base field (56 - 63)
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_BASE_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp
deleted file mode 100644
index 40bcc8a..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_EXTENSION_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_EXTENSION_HPP
-
-#include "arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp"
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- __extension__ typedef __int128 int128_t;
- __extension__ typedef unsigned __int128 uint128_t;
-
- /**
- * @brief Defines helper function for all states and the actual data the segment descriptor can have.
- */
- struct [[gnu::packed]] segment_descriptor_extension
- {
- /**
- * @brief Default Constructor.
- */
- segment_descriptor_extension() = default;
-
- /**
- * @brief Constructor.
- *
- * @note Created segment descriptor copies the given bytes into these components requiring the space of two
- * segment descriptor entry in the global descriptor table being 128-bit. Ending with a 32 bit reserved
- * field that has to be used, because the segment descriptor needs to be big enough for two segment
- * descriptor entries.
- * - 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.
- */
- explicit segment_descriptor_extension(uint128_t flags);
-
- /**
- * @brief Constructor.
- *
- * @param access_byte, flags, base, limit Copies the bits set from the given data into the individual components of
- * a segment descriptor.
- */
- segment_descriptor_extension(access_byte access_byte, gdt_flags flags, uint64_t base, std::bitset<20U> limit);
-
- /**
- * @brief Returns the underlying base segment descriptor, being the first part of the segment descriptor consisting
- * of two entries in the global descriptor table.
- */
- auto get_first_gdt_entry() const -> segment_descriptor_base;
-
- /**
- * @brief Returns the underlying extension to the segment descriptor, being the second part of the segment
- * descriptor consiting of two entries in the global descriptor table.
- */
- auto get_second_gdt_entry() const -> uint64_t;
-
- /**
- * @brief Allows to compare the underlying bits of two instances.
- *
- * @param other Other instance that we want to compare with.
- * @return Whether the underlying set bits of both types are the same.
- */
- auto operator==(segment_descriptor_extension const & other) const -> bool = default;
-
- private:
- // The order in private variables starts for the first variable being the rightmost bit.
- segment_descriptor_base _base = {}; ///< Base Segment Descriptor representing single entry in GDT (0 - 63)
- uint32_t _base_3 = {}; ///< Third part of the base field (63 - 95)
- uint32_t : 32; ///< Reserved field used to ensure this struct is 128 bits big (96 - 127)
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_EXTENSION_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp
deleted file mode 100644
index 8770b81..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_TYPES_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_TYPES_HPP
-
-#include <cstdint>
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief Possible overlying types of the segment descriptor. Allowing to discern between the major types, which
- * result in different handling of the actual data contained in the descriptor.
- */
- enum class segment_descriptor_type : uint8_t
- {
- SYSTEM_SEGMENT, ///< The segment is of type system, is distinguished by the Descriptor Type field in the Access
- ///< Byte. Can be further distinguised to specific system segment types using the Type Field in the
- ///< Access Byte.
- DATA_SEGMENT, ///< The segment is of type data, is is distinguished by the Descriptor Type field in the Access
- ///< Byte and the first bit of the Type Field in the Access Byte. Can be further distinguised to
- ///< specific data segment types using the the remaining bits in the Type Field in the Access Byte.
- CODE_SEGMENT, ///< The segment is of type code, is is distinguished by the Descriptor Type field in
- ///< the Access Byte and the first bit of the Type Field in the Access Byte. Can be
- ///< further distinguised to specific data segment types using the the remaining bits in
- ///< the Type Field in the Access Byte.
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_TYPES_HPP
diff --git a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/task_state_segment.hpp b/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/task_state_segment.hpp
deleted file mode 100644
index d4aa5e8..0000000
--- a/arch/x86_64/pre/include/arch/context_switching/segment_descriptor_table/task_state_segment.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP
-
-#include <cstdint>
-
-namespace teachos::arch::context_switching::segment_descriptor_table
-{
- /**
- * @brief 64-bit task state segment
- */
- struct [[gnu::packed]] task_state_segment
- {
- private:
- uint32_t : 32;
- uint64_t rsp0 = {};
- uint64_t rsp1 = {};
- uint64_t rsp2 = {};
- uint64_t : 64;
- uint64_t ist1 = {};
- uint64_t ist2 = {};
- uint64_t ist3 = {};
- uint64_t ist4 = {};
- uint64_t ist5 = {};
- uint64_t ist6 = {};
- uint64_t ist7 = {};
- uint64_t : 64;
- uint16_t : 16;
- uint16_t io_map_base_address = {};
- };
-} // namespace teachos::arch::context_switching::segment_descriptor_table
-
-#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP
diff --git a/arch/x86_64/pre/include/arch/kernel/cpu/gdtr.hpp b/arch/x86_64/pre/include/arch/kernel/cpu/gdtr.hpp
deleted file mode 100644
index 68b950d..0000000
--- a/arch/x86_64/pre/include/arch/kernel/cpu/gdtr.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
-#define TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
-
-#include "arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp"
-
-#include <bitset>
-#include <cstdint>
-
-namespace teachos::arch::kernel::cpu
-{
-
- /**
- * @brief Returns the value in the GDTR register.
- *
- * @return Value of GDTR register.
- */
- auto store_global_descriptor_table() -> context_switching::segment_descriptor_table::global_descriptor_table_pointer;
-
- /**
- * @brief Loads the global_descriptor_table_pointer into the global descriptor table register (GDTR).
- */
- auto load_global_descriptor_table(
- context_switching::segment_descriptor_table::global_descriptor_table_pointer const & gdt_pointer) -> void;
-
-} // namespace teachos::arch::kernel::cpu
-
-#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
diff --git a/arch/x86_64/pre/include/arch/kernel/cpu/segment_register.hpp b/arch/x86_64/pre/include/arch/kernel/cpu/segment_register.hpp
deleted file mode 100644
index a236452..0000000
--- a/arch/x86_64/pre/include/arch/kernel/cpu/segment_register.hpp
+++ /dev/null
@@ -1,97 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_SEGMENT_REGISTER_HPP
-#define TEACHOS_ARCH_X86_64_KERNEL_CPU_SEGMENT_REGISTER_HPP
-
-#include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp"
-
-namespace teachos::arch::kernel::cpu
-{
- /**
- * @brief Clear all Data Segment registers (DS / ES / FS / GS).
- */
- auto reload_data_segment_registers() -> void;
-
- /**
- * @brief Updates the value of the Data Segment Register (DS), Extra Segment Register (ES), Thread-Local Storage
- * Registers (FS / GS).
- *
- * @note The Stack Segment Register (SS) value should also be updated, but the value can not be directly set in
- * comparsion to the other registers. This is the case because the register is used for stack management and can not
- * be directly changed, instead this has to be done by a special instruction. Therefore
- * validate_data_segment_registers should only be called after set_code_segment_register has been called as well.
- *
- * @param data_segment Value that should be loaded into the registers.
- */
- auto set_data_segment_registers(context_switching::interrupt_descriptor_table::segment_selector data_segment) -> void;
-
- /**
- * @brief Returns the Segment Selector pointing to the Code Segment that has been loaded into the Code Segment
- * Register (CS).
- *
- * @note The CS register can not be directly changed, instead a Far Return has to be executed to change it
- *
- * @return Segment Selector pointing to the currently loaded Code Segment.
- */
- [[gnu::section(".user_text")]]
- auto read_code_segment_register() -> context_switching::interrupt_descriptor_table::segment_selector;
-
- /**
- * @brief Validates that all Data Segment Registers (DS / ES / FS / GS / SS) are the same as the given Data Segment
- * and asserts and stops the application if they are not.
- *
- * @note This is only the case after set_code_segment_register has been executed as well, because it makes a far
- * return that updates the SS register.
- *
- * @param data_segment Value that should be loaded into all Data Segment Registers.
- */
- auto validate_data_segment_registers(context_switching::interrupt_descriptor_table::segment_selector data_segment)
- -> void;
-
- /**
- * @brief Validates that the Code Segment Register (CS) is the same as the given Code Segment
- * and asserts and stops the application if they are not.
- *
- * @param code_segment Value that should be loaded into the Code Segment Register.
- */
- auto validate_code_segment_register(context_switching::interrupt_descriptor_table::segment_selector code_segment)
- -> void;
-
- /**
- * @brief Simply forwards the call to validate_data_segment_registers and validate_code_segment_register and ensures
- * that all Segment Registers, have been configured correctly.
- *
- * @note If all Segment Register have been set correctly the Context Switch using the set_code_segment_register method
- * was successfull and the Privilege Level has been changed.
- *
- * @param data_segment Value that should be loaded into all Data Segment Registers.
- * @param code_segment Value that should be loaded into the Code Segment Register.
- */
- auto validate_segment_registers(context_switching::interrupt_descriptor_table::segment_selector data_segment,
- context_switching::interrupt_descriptor_table::segment_selector code_segment) -> void;
-
- /**
- * @brief Sets the value of the Code Segment Register (CS), this is achieved using a Far Return.
- *
- * @note The Far Return used by this method, will cause the context to switch, because we are changing from the
- * current Code Segment and it's associated Privilege Level to another Code Segment. The given method will then be
- * called in the new context and it should be possible to call validate_segment_registers, with the same values
- * without assertions if the switch was successful.
- *
- * To achieve this Far Return we call IRETQ, which expects the stack to be defined a certain way to achieve that we:
- * 1. Push the Data Segment Selector
- * 2. Push the current Stack Pointer
- * 3. Push Eflags
- * 4. Push Code Segment Selector
- * 5. Push Return Address
- *
- * @param data_segment Data Segment that should be loaded into the SS register.
- * @param code_segment Code Segment that should be loaded into the CS register.
- * @param address Function that we want to call in the new context created by the given Code Segment.
- */
- [[gnu::naked]]
- auto set_code_segment_register(context_switching::interrupt_descriptor_table::segment_selector data_segment,
- context_switching::interrupt_descriptor_table::segment_selector code_segment,
- uint64_t address) -> void;
-