aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp4
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp2
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp17
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor.hpp83
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp45
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp57
6 files changed, 98 insertions, 110 deletions
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 8748448..5be449f 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
@@ -79,11 +79,11 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table
auto operator|=(std::bitset<3U> other) -> void;
/**
- * @brief Combines all bits in the underlying data in the correct order to return a raw value containing all bits.
+ * @brief Cast the underlying data into a combined 16-bit form, that contains all data.
*
* @return Underlying value combined into it's full size.
*/
- operator uint16_t() const { return static_cast<uint64_t>(_flags) | (static_cast<uint64_t>(_index) << 3U); }
+ operator uint16_t() const;
private:
uint8_t _flags : 3 = {}; ///< Underlying bits used to read the flags from.
diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp
index 84a24a2..44f2692 100644
--- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp
+++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp
@@ -30,7 +30,7 @@ namespace teachos::arch::context_switching::segment_descriptor_table
* @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_task_state_segment_register() -> void;
+ auto update_tss_register() -> void;
} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp
index c54647d..292ff70 100644
--- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp
+++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp
@@ -1,24 +1,13 @@
#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/context_switching/segment_descriptor_table/segment_descriptor_base.hpp"
-#include "arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp"
#include "arch/stl/vector.hpp"
#include <cstdint>
namespace teachos::arch::context_switching::segment_descriptor_table
{
- struct __attribute__((packed, aligned(8))) global_descriptor_table
- {
- segment_descriptor_base null;
- segment_descriptor_base kernel_code;
- segment_descriptor_base kernel_data;
- segment_descriptor_base user_code;
- segment_descriptor_base user_data;
- segment_descriptor_base tss_low;
- segment_descriptor_extension tss_high;
- };
+ using global_descriptor_table = stl::vector<uint64_t>;
/**
* @brief Represents a pointer to the Global Descriptor Table (GDT).
@@ -36,7 +25,7 @@ namespace teachos::arch::context_switching::segment_descriptor_table
/**
* @brief Constructor.
*/
- global_descriptor_table_pointer(uint16_t table_length, seg_desc * address);
+ global_descriptor_table_pointer(uint16_t table_length, uint64_t * address);
/**
* @brief Defaulted three-way comparsion operator.
@@ -45,7 +34,7 @@ namespace teachos::arch::context_switching::segment_descriptor_table
private:
uint16_t table_length = {}; ///< The amount of segment descriptor entries in the global descriptor table - 1.
- seg_desc * address = {}; ///< Non-owning pointer to the GDT base address.
+ uint64_t * address = {}; ///< Non-owning pointer to the GDT base address.
};
} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor.hpp
deleted file mode 100644
index ccd604d..0000000
--- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor.hpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_HPP
-#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SEGMENT_DESCRIPTOR_TABLE_SEGMENT_DESCRIPTOR_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
-{
- __extension__ typedef __int128 int128_t;
- __extension__ typedef unsigned __int128 uint128_t;
-
- struct seg_desc
- {
- private:
- uint64_t : 64; ///< Makes sure the struct is 8-Bytes big
- };
-
- /**
- * @brief Defines helper function for all states and the actual data the segment descriptor can have.
- */
- struct [[gnu::packed]] segment_descriptor
- {
- /**
- * @brief Default Constructor.
- */
- segment_descriptor() = default;
-
- /**
- * @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.
- */
- explicit segment_descriptor(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(access_byte access_byte, gdt_flags flags, uint64_t base, std::bitset<20U> limit);
-
- auto get_limit_1() -> uint16_t;
- auto get_base_1() -> uint32_t;
- auto get_access() -> access_byte;
- auto get_flag() -> gdt_flags;
- auto get_base_2() -> uint64_t;
-
- /**
- * @brief Calculates the underlying segment type that this segement descriptor is describing.
- */
- auto get_segment_type() const -> segment_descriptor_type;
-
- /**
- * @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 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)
- uint64_t _base_2 : 40 = {}; ///< Second part of the base field (56 - 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_HPP
diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp
index 18c9da1..933fb4d 100644
--- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp
+++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_base.hpp
@@ -3,7 +3,6 @@
#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.hpp"
#include "arch/context_switching/segment_descriptor_table/segment_descriptor_type.hpp"
namespace teachos::arch::context_switching::segment_descriptor_table
@@ -11,7 +10,7 @@ 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 : seg_desc
+ struct [[gnu::packed]] segment_descriptor_base
{
/**
* @brief Default Constructor.
@@ -20,14 +19,54 @@ namespace teachos::arch::context_switching::segment_descriptor_table
/**
* @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.
*/
- segment_descriptor_base(segment_descriptor 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
diff --git a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp
index 0b724f2..40bcc8a 100644
--- a/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp
+++ b/arch/x86_64/include/arch/context_switching/segment_descriptor_table/segment_descriptor_extension.hpp
@@ -1,16 +1,17 @@
#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.hpp"
-
-#include <cstdint>
+#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 : seg_desc
+ struct [[gnu::packed]] segment_descriptor_extension
{
/**
* @brief Default Constructor.
@@ -19,12 +20,54 @@ namespace teachos::arch::context_switching::segment_descriptor_table
/**
* @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.
*/
- segment_descriptor_extension(segment_descriptor segment_descriptor);
+ auto operator==(segment_descriptor_extension const & other) const -> bool = default;
private:
- uint64_t _base_2 : 40 = {}; ///< Second part of the base field (56 - 95)
- uint32_t : 32; ///< Reserved field used to ensure this struct is 128 bits big (96 - 127)
+ // 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