aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/include
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-03-16 12:41:09 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-03-16 12:41:09 +0000
commit36758071881088b27a52cee4e5653f6cf6a79a78 (patch)
treed427218710530eab7e007f6adca9fe4e1710250c /arch/x86_64/include
parent48578314c1e6af15f8cc1ce48df93e352a5a18ba (diff)
downloadteachos-36758071881088b27a52cee4e5653f6cf6a79a78.tar.xz
teachos-36758071881088b27a52cee4e5653f6cf6a79a78.zip
start implementing TSS
Diffstat (limited to 'arch/x86_64/include')
-rw-r--r--arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table.hpp42
-rw-r--r--arch/x86_64/include/arch/context_switching/descriptor_table/task_state_segment.hpp39
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/gdtr.hpp (renamed from arch/x86_64/include/arch/kernel/cpu/lgdt.hpp)6
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/tr.hpp26
4 files changed, 110 insertions, 3 deletions
diff --git a/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table.hpp
index c4d0e30..ab8f1ac 100644
--- a/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table.hpp
+++ b/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table.hpp
@@ -2,12 +2,54 @@
#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
#include "arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp"
+#include "arch/context_switching/descriptor_table/task_state_segment.hpp"
namespace teachos::arch::context_switching::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 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.
+ *
+ * @return Created global_descriptor_table.
+ */
auto initialize_global_descriptor_table() -> global_descriptor_table;
+
} // namespace teachos::arch::context_switching::descriptor_table
#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
diff --git a/arch/x86_64/include/arch/context_switching/descriptor_table/task_state_segment.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/task_state_segment.hpp
new file mode 100644
index 0000000..af7ae7c
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/descriptor_table/task_state_segment.hpp
@@ -0,0 +1,39 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP
+
+#include <cstdint>
+
+namespace teachos::arch::context_switching::descriptor_table
+{
+ /**
+ * @brief 64-bit task state segment
+ */
+ struct [[gnu::packed]] task_state_segment
+ {
+ private:
+ uint16_t io_map_base_address = {};
+
+ uint16_t reserved_1 = {};
+ uint32_t reserved_2 = {};
+ uint32_t reserved_3 = {};
+
+ uint64_t ist7 = {};
+ uint64_t ist6 = {};
+ uint64_t ist5 = {};
+ uint64_t ist4 = {};
+ uint64_t ist3 = {};
+ uint64_t ist2 = {};
+ uint64_t ist1 = {};
+
+ uint32_t reserved_4 = {};
+ uint32_t reserved_5 = {};
+
+ uint64_t rsp2 = {};
+ uint64_t rsp1 = {};
+ uint64_t rsp0 = {};
+
+ uint32_t reserved_6 = {};
+ };
+} // namespace teachos::arch::context_switching::descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_TASK_STATE_SEGMENT_HPP \ No newline at end of file
diff --git a/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp b/arch/x86_64/include/arch/kernel/cpu/gdtr.hpp
index 85e2949..f9220b9 100644
--- a/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/gdtr.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_LGDT_HPP
-#define TEACHOS_ARCH_X86_64_KERNEL_CPU_LGDT_HPP
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
#include "arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp"
@@ -25,4 +25,4 @@ namespace teachos::arch::kernel::cpu
} // namespace teachos::arch::kernel::cpu
-#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_LGDT_HPP
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_GDTR_HPP
diff --git a/arch/x86_64/include/arch/kernel/cpu/tr.hpp b/arch/x86_64/include/arch/kernel/cpu/tr.hpp
new file mode 100644
index 0000000..5f99472
--- /dev/null
+++ b/arch/x86_64/include/arch/kernel/cpu/tr.hpp
@@ -0,0 +1,26 @@
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_TR_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_TR_HPP
+
+#include "arch/context_switching/descriptor_table/task_state_segment.hpp"
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::kernel::cpu
+{
+
+ /**
+ * @brief Returns the value in the LTR register.
+ *
+ * @return Value of LTR register.
+ */
+ auto store_task_register() -> uint16_t;
+
+ /**
+ * @brief Loads the tss_pointer into the task register (TR).
+ */
+ auto load_task_register(uint16_t gdt_offset) -> void;
+
+} // namespace teachos::arch::kernel::cpu
+
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_TR_HPP