aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/CMakeLists.txt7
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp54
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp74
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp14
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp4
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/ist_offset.hpp41
-rw-r--r--arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp74
-rw-r--r--arch/x86_64/include/arch/context_switching/main.hpp3
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/access_byte.hpp14
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/gdt_flags.hpp4
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp36
-rw-r--r--arch/x86_64/include/arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp2
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/ss.hpp39
-rw-r--r--arch/x86_64/include/arch/memory/allocator/physical_frame.hpp4
-rw-r--r--arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/multiboot/memory_map.hpp2
-rw-r--r--arch/x86_64/include/arch/memory/paging/virtual_page.hpp4
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp19
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/idt_flags.cpp15
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp24
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/ist_offset.cpp10
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/segment_selector.cpp16
-rw-r--r--arch/x86_64/src/context_switching/main.cpp7
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp105
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor.cpp10
-rw-r--r--arch/x86_64/src/kernel/cpu/ss.cpp29
26 files changed, 425 insertions, 188 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index cf92feb..5242f3d 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -94,13 +94,16 @@ target_sources("_exception" PRIVATE
target_sources("_context" PRIVATE
"src/context_switching/segment_descriptor_table/access_byte.cpp"
"src/context_switching/segment_descriptor_table/gdt_flags.cpp"
- "src/context_switching/segment_descriptor_table/global_descriptor_table.cpp"
"src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp"
+ "src/context_switching/segment_descriptor_table/global_descriptor_table.cpp"
"src/context_switching/segment_descriptor_table/segment_descriptor.cpp"
"src/context_switching/main.cpp"
"src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp"
- "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp"
+ "src/context_switching/interrupt_descriptor_table/idt_flags.cpp"
"src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp"
+ "src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp"
+ "src/context_switching/interrupt_descriptor_table/ist_offset.cpp"
+ "src/context_switching/interrupt_descriptor_table/segment_selector.cpp"
)
#[============================================================================[
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp
index 2252b7b..196430f 100644
--- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp
@@ -1,14 +1,68 @@
#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRRUPT_DESCRIPTOR_TABLE_GATE_DESCRIPTOR_HPP
#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRRUPT_DESCRIPTOR_TABLE_GATE_DESCRIPTOR_HPP
+#include "arch/context_switching/interrupt_descriptor_table/idt_flags.hpp"
+#include "arch/context_switching/interrupt_descriptor_table/ist_offset.hpp"
+#include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp"
+
+#include <bitset>
+#include <cstdint>
+
namespace teachos::arch::context_switching::interrupt_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 gate descriptor can have.
+ */
struct [[gnu::packed]] gate_descriptor
{
/**
* @brief Default Constructor.
*/
gate_descriptor() = default;
+
+ /**
+ * @brief Constructor.
+ *
+ * @note Created gate descriptor copies the given bytes into these components ending with a 32 bit reserved
+ * field that has to be used, because the 64-bit gate descriptor needs to be big enough for two 32-bit gate
+ * descriptor.
+ * - 16 bit Segment Selector
+ * - 3 bit IST
+ * - 8 bit Type and Flags
+ * - 64 bit Offset
+ *
+ * @param flags Copies the bits set from the given data into the individual components of a gate
+ * descriptor.
+ */
+ explicit gate_descriptor(uint128_t flags);
+
+ /**
+ * @brief Constructor.
+ *
+ * @param selector, ist, flags, offset Copies the bits set from the given data into the individual components of
+ * a gate descriptor.
+ */
+ gate_descriptor(segment_selector selector, ist_offset ist, idt_flags flags, uint64_t offset);
+
+ /**
+ * @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==(gate_descriptor const & other) const -> bool = default;
+
+ private:
+ // The order in private variables starts for the first variable being the rightmost bit.
+ uint16_t _offset_1 = {}; ///< First part of the offset field (0 - 15)
+ segment_selector _selector = {}; ///< Segment selector (16 - 31)
+ ist_offset _ist = {}; ///< Interrupt Stack Table offset (32 - 39)
+ idt_flags _flags = {}; ///< Gate Type and Flags (40 - 47)
+ uint64_t _offset_2 : 48 = {}; ///< Second part of the offset field (48 - 95)
+ uint32_t : 32; ///< Reserved field used to ensure this struct is 128 bits big (96 - 127)
};
} // namespace teachos::arch::context_switching::interrupt_descriptor_table
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
new file mode 100644
index 0000000..f153e36
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/idt_flags.hpp
@@ -0,0 +1,74 @@
+
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IDT_FLAGS_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IDT_FLAGS_HPP
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ /**
+ * @brief Defines helper function for all states that the access byte field of a segment descriptor can
+ * have.
+ */
+ struct [[gnu::packed]] idt_flags
+ {
+ /**
+ * @brief Possible set bits in our underlying std::bitset and the meaning when they are set.
+ */
+ enum bitset : uint8_t
+ {
+ INTERRUPT_GATE = 16U, ///< The actual type of gate segment is a interrupt gate.
+ TRAP_GATE = 17U, ///< The actual type of gate segment is a trap gate.
+ 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.
+ */
+ idt_flags() = 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.
+ */
+ idt_flags(uint8_t flags);
+
+ /**
+ * @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<8U> 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==(idt_flags const & other) const -> bool = default;
+
+ private:
+ uint8_t _flags = {}; ///< Underlying bits used to read the flags from.
+ };
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IDT_FLAGS_HPP \ No newline at end of file
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp
index ac52a39..dd55cd7 100644
--- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp
@@ -1,13 +1,17 @@
#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRRUPT_DESCRIPTOR_TABLE_INTERRUPT_DESCRIPTOR_TABLE_HPP
#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRRUPT_DESCRIPTOR_TABLE_INTERRUPT_DESCRIPTOR_TABLE_HPP
+#include "arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp"
+
namespace teachos::arch::context_switching::interrupt_descriptor_table
{
- struct interrupt_descriptor_table
- {
- };
-
- auto initialize_interrupt_descriptor_table() -> void;
+ /**
+ * @brief Initializes the interrupt_descriptor_table by loading it
+ * in the IDTR register.
+ *
+ * @return Reference to the created interrupt_descriptor_table.
+ */
+ auto initialize_interrupt_descriptor_table() -> interrupt_descriptor_table &;
} // namespace teachos::arch::context_switching::interrupt_descriptor_table
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp
index de40f90..d853ff0 100644
--- a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp
@@ -4,11 +4,9 @@
#include "arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp"
#include "arch/stl/vector.hpp"
-#include <cstdint>
-
namespace teachos::arch::context_switching::interrupt_descriptor_table
{
- typedef stl::vector<gate_descriptor> interrupt_descriptor_table;
+ using interrupt_descriptor_table = stl::vector<gate_descriptor>;
/**
* @brief Represents a pointer to the Interrupt Descriptor Table (IDT).
diff --git a/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/ist_offset.hpp b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/ist_offset.hpp
new file mode 100644
index 0000000..f31a898
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/ist_offset.hpp
@@ -0,0 +1,41 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IST_OFFSET_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IST_OFFSET_HPP
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ /**
+ * @brief Defines helper function for all states that the ist field of a gate descriptor can
+ * have. Is automatically increased to one byte in size, to include the following 5 reserved bits in the gate
+ * descriptor.
+ */
+ struct [[gnu::packed]] ist_offset
+ {
+ /**
+ * @brief Default Constructor.
+ */
+ ist_offset() = default;
+
+ /**
+ * @brief Constructor.
+ *
+ * @param index Index into local or global descriptor table.
+ */
+ ist_offset(uint8_t index);
+
+ /**
+ * @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==(ist_offset const & other) const -> bool = default;
+
+ private:
+ uint8_t _ist : 3 = {}; ///< Offset into the interrupt stack table.
+ };
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_IST_OFFSET_HPP
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
new file mode 100644
index 0000000..c31e2d0
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/interrupt_descriptor_table/segment_selector.hpp
@@ -0,0 +1,74 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_SEGMENT_SELECTOR_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_SEGMENT_SELECTOR_HPP
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ /**
+ * @brief Represents a segment selector in the x86_64 architecture, which points to a valid code segment in the global
+ * descriptor table.
+ *
+ * A segment selector is a 16-bit identifier used to select a segment descriptor
+ * from the Global Descriptor Table (GDT) or the Local Descriptor Table (LDT).
+ * It contains an index, a table indicator (TI), and a requested privilege level (RPL).
+ */
+ struct [[gnu::packed]] segment_selector
+ {
+ /**
+ * @brief Possible set bits in our underlying std::bitset and the meaning when they are set.
+ */
+ enum bitset : uint8_t
+ {
+ REQUEST_LEVEL_KERNEL =
+ 0U << 0U, ///< Highest privileged level used by the kernel to allow for full access of resources.
+ REQUEST_LEVEL_ADMIN =
+ 1U << 0U, ///< 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.
+ REQUEST_LEVEL_PRIVILEGED_USER =
+ 2U << 0U, ///< 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.
+ REQUEST_LEVEL_USER = 3U << 0U, ///< Restricts access to only application and their specific memory.
+ LOCAL_DESCRIPTOR_TABLE = 1U << 2U, ///< Wheter the index referes to an entry in the local or global descriptor
+ ///< table. If enabled the index points to a local descriptor table, if it is
+ ///< cleared it referes to a global descriptor table instead.
+ };
+
+ /**
+ * @brief Default constructor.
+ */
+ segment_selector() = default;
+
+ /**
+ * @brief Constructor.
+ *
+ * @param index Index into the local or global descriptor table.
+ * @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.
+ */
+ 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.
+ *
+ * @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<3U> other) const -> bool;
+
+ /**
+ * @brief Defaulted three-way comparsion operator.
+ */
+ auto operator<=>(segment_selector const & other) const -> std::strong_ordering = default;
+
+ private:
+ uint8_t _flags : 3 = {}; ///< Underlying bits used to read the flags from.
+ uint16_t _index : 13 = {}; ///< Index into the local or global descriptor table.
+ };
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_INTERRUPT_DESCRIPTOR_TABLE_SEGMENT_SELECTOR_HPP
diff --git a/arch/x86_64/include/arch/context_switching/main.hpp b/arch/x86_64/include/arch/context_switching/main.hpp
index ef642d6..d2243ed 100644
--- a/arch/x86_64/include/arch/context_switching/main.hpp
+++ b/arch/x86_64/include/arch/context_switching/main.hpp
@@ -7,8 +7,7 @@
namespace teachos::arch::context_switching
{
/**
- * @brief TODO
- *
+ * @brief Contains the references to the tables required for context switching
*/
struct descriptor_tables
{
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 bbf3f49..3d7862c 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
@@ -43,17 +43,17 @@ namespace teachos::arch::context_switching::segment_descriptor_table
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).
- ACCESS_LEVEL_KERNEL =
+ DESCRIPTOR_LEVEL_KERNEL =
0U << 5U, ///< Highest privileged level used by the kernel to allow for full access of resources.
- ACCESS_LEVEL_ADMIN =
+ 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.
- ACCESS_LEVEL_PRIVILEGED_USER =
+ 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.
- ACCESS_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.
+ 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.
};
/**
@@ -90,7 +90,7 @@ namespace teachos::arch::context_switching::segment_descriptor_table
auto operator==(access_byte const & other) const -> bool = default;
private:
- uint8_t _flags = {}; ///< Underlying bitset used to read the flags from.
+ uint8_t _flags = {}; ///< Underlying bits used to read the flags from.
};
} // namespace teachos::arch::context_switching::segment_descriptor_table
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 2ce5286..fdf0044 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
@@ -78,8 +78,8 @@ namespace teachos::arch::context_switching::segment_descriptor_table
auto operator==(gdt_flags const & other) const -> bool = default;
private:
- uint8_t _limit_2 : 4 = {};
- uint8_t _flags : 4 = {}; ///< Underlying bitset used to read the flags from.
+ 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
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 a111a1f..f3067ba 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
@@ -6,42 +6,6 @@
namespace teachos::arch::context_switching::segment_descriptor_table
{
- enum class access_level
- {
- KERNEL,
- USER
- };
-
- /**
- * @brief Creates a generic segment_descriptor from the passed arguments.
- *
- * @param segment_descriptor_type Defines the type of the segment descriptor.
- * @param access_level Defines the segment descriptor access level (KERNEL or USER).
- * @return Created segment_descriptor.
- */
- auto create_segment_descriptor(segment_descriptor_type segment_descriptor_type, access_level access_level)
- -> segment_descriptor;
-
- /**
- * @brief Creates a global_descriptor_table on the heap and fills it with the following segment registers:
- *
- * - Kernel Code Segment
- * - Kernel Data Segment
- * - User Code Segment
- * - User Data Segment
- *
- * @return Copy of the created global_descriptor_table.
- */
- auto create_global_descriptor_table() -> global_descriptor_table;
-
- /**
- * @brief Creates a task_state_segment segment_descriptor on the heap.
- *
- * @param tss task_state_segment whose pointer is used in the segment_descriptor
- * @return Created segment_descriptor.
- */
- auto create_task_state_segment_descriptor(task_state_segment * tss) -> segment_descriptor;
-
/**
* @brief Initializes the global_descriptor_table and task_state_segment by loading them
* in the GDTR and TR registers respectively.
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 b66070b..13d6f53 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
@@ -8,7 +8,7 @@
namespace teachos::arch::context_switching::segment_descriptor_table
{
- typedef stl::vector<segment_descriptor> global_descriptor_table;
+ using global_descriptor_table = stl::vector<segment_descriptor>;
/**
* @brief Represents a pointer to the Global Descriptor Table (GDT).
diff --git a/arch/x86_64/include/arch/kernel/cpu/ss.hpp b/arch/x86_64/include/arch/kernel/cpu/ss.hpp
index 1fb6448..b5fa5e3 100644
--- a/arch/x86_64/include/arch/kernel/cpu/ss.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/ss.hpp
@@ -1,55 +1,26 @@
#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_SS_HPP
#define TEACHOS_ARCH_X86_64_KERNEL_CPU_SS_HPP
+#include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp"
+
#include <bitset>
#include <cstdint>
namespace teachos::arch::kernel::cpu
{
/**
- * @brief Represents a segment selector in the x86_64 architecture.
- *
- * A segment selector is a 16-bit identifier used to select a segment descriptor
- * from the Global Descriptor Table (GDT) or the Local Descriptor Table (LDT).
- * It contains an index, a table indicator (TI), and a requested privilege level (RPL).
- */
- struct segment_selector
- {
- /**
- * @brief Constructs a segment selector.
- *
- * @param index The index of the segment descriptor.
- * @param table_indicator The table indicator (0 for GDT, 1 for LDT).
- * @param requested_privilege_level The requested privilege level (0-3).
- */
- segment_selector(uint16_t index, std::bitset<1U> table_indicator, std::bitset<2U> requested_privilege_level);
-
- /**
- * @brief Converts the segment selector to a 16-bit value.
- *
- * @return uint16_t The 16-bit representation of the segment selector.
- */
- auto to_uint16() const -> uint16_t;
-
- private:
- uint16_t index;
- std::bitset<1U> table_indicator;
- std::bitset<2U> requested_privilege_level;
- };
-
- /**
* @brief Reads the current value of the stack segment (SS) register.
*
- * @return uint16_t The current SS register value.
+ * @return The current SS register value.
*/
- auto read_ss() -> uint16_t;
+ auto read_ss() -> context_switching::interrupt_descriptor_table::segment_selector;
/**
* @brief Writes a new value to the stack segment (SS) register.
*
* @param selector The segment selector to be written to SS.
*/
- auto write_ss(segment_selector selector) -> void;
+ auto write_ss(context_switching::interrupt_descriptor_table::segment_selector selector) -> void;
} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp
index 7ea5517..cb6c5b3 100644
--- a/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp
+++ b/arch/x86_64/include/arch/memory/allocator/physical_frame.hpp
@@ -10,7 +10,7 @@
namespace teachos::arch::memory::allocator
{
- typedef std::size_t physical_address;
+ using physical_address = std::size_t;
std::size_t constexpr PAGE_FRAME_SIZE = 4096U; ///< Default page size of x86_84 is always 4KiB.
@@ -79,7 +79,7 @@ namespace teachos::arch::memory::allocator
{}; ///< Index number of the current physical frame, used to distinguish it from other frames.
};
- typedef stl::container<stl::forward_value_iterator<physical_frame>> frame_container;
+ using frame_container = stl::container<stl::forward_value_iterator<physical_frame>>;
} // namespace teachos::arch::memory::allocator
diff --git a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp
index 4c7470b..730bcaf 100644
--- a/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp
+++ b/arch/x86_64/include/arch/memory/multiboot/elf_symbols_section.hpp
@@ -162,7 +162,7 @@ namespace teachos::arch::memory::multiboot
///< contained in the section, to ensure byte alignment is actually 4 byte.
};
- typedef stl::container<stl::contiguous_pointer_iterator<elf_section_header>> elf_section_header_container;
+ using elf_section_header_container = stl::container<stl::contiguous_pointer_iterator<elf_section_header>>;
} // namespace teachos::arch::memory::multiboot
diff --git a/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp b/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp
index cc8db8c..68394c8 100644
--- a/arch/x86_64/include/arch/memory/multiboot/memory_map.hpp
+++ b/