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/descriptor_table/global_descriptor_table.hpp19
-rw-r--r--arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp23
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/control_register.hpp (renamed from arch/x86_64/include/arch/memory/cpu/control_register.hpp)6
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/msr.hpp (renamed from arch/x86_64/include/arch/memory/cpu/msr.hpp)6
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/ss.hpp56
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/tlb.hpp (renamed from arch/x86_64/include/arch/memory/cpu/tlb.hpp)6
-rw-r--r--arch/x86_64/include/arch/memory/paging/active_page_table.hpp6
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp2
8 files changed, 111 insertions, 13 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 e69de29..daba1fe 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
@@ -0,0 +1,19 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_HPP
+#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/segment_descriptor.hpp"
+#include "arch/stl/vector.hpp"
+
+namespace teachos::arch::context_switching::descriptor_table
+{
+ typedef stl::vector<segment_descriptor> global_descriptor_table;
+
+ auto create_global_descriptor_table() -> global_descriptor_table;
+
+ auto load_global_descriptor_table(global_descriptor_table_pointer gdt_pointer) -> void;
+
+ 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/global_descriptor_table_pointer.hpp b/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp
new file mode 100644
index 0000000..c2925fd
--- /dev/null
+++ b/arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp
@@ -0,0 +1,23 @@
+#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
+#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
+
+#include "arch/context_switching/descriptor_table/global_descriptor_table.hpp"
+
+#include <cstdint>
+
+namespace teachos::arch::context_switching::descriptor_table
+{
+ /**
+ * @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 global_descriptor_table_pointer
+ {
+ uint16_t table_length; ///< The size of the GDT in bytes.
+ global_descriptor_table * address; ///< Pointer to the GDT base address.
+ };
+} // namespace teachos::arch::context_switching::descriptor_table
+
+#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_DESCRIPTOR_TABLE_GLOBAL_DESCRIPTOR_TABLE_POINTER_HPP
diff --git a/arch/x86_64/include/arch/memory/cpu/control_register.hpp b/arch/x86_64/include/arch/kernel/cpu/control_register.hpp
index e11813d..27c7777 100644
--- a/arch/x86_64/include/arch/memory/cpu/control_register.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/control_register.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_ARCH_X86_64_MEMORY_CPU_CR3_HPP
-#define TEACHOS_ARCH_X86_64_MEMORY_CPU_CR3_HPP
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_CR3_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_CR3_HPP
#include <cstdint>
@@ -68,4 +68,4 @@ namespace teachos::arch::memory::cpu
} // namespace teachos::arch::memory::cpu
-#endif // TEACHOS_ARCH_X86_64_MEMORY_CPU_CR3_HPP
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_CR3_HPP
diff --git a/arch/x86_64/include/arch/memory/cpu/msr.hpp b/arch/x86_64/include/arch/kernel/cpu/msr.hpp
index cda70e2..52d74bd 100644
--- a/arch/x86_64/include/arch/memory/cpu/msr.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/msr.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_ARCH_X86_64_MEMORY_CPU_NXE_HPP
-#define TEACHOS_ARCH_X86_64_MEMORY_CPU_NXE_HPP
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_NXE_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_NXE_HPP
#include <bitset>
#include <cstdint>
@@ -61,4 +61,4 @@ namespace teachos::arch::memory::cpu
} // namespace teachos::arch::memory::cpu
-#endif // TEACHOS_ARCH_X86_64_MEMORY_CPU_NXE_HPP \ No newline at end of file
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_NXE_HPP \ No newline at end of file
diff --git a/arch/x86_64/include/arch/kernel/cpu/ss.hpp b/arch/x86_64/include/arch/kernel/cpu/ss.hpp
new file mode 100644
index 0000000..2d3518e
--- /dev/null
+++ b/arch/x86_64/include/arch/kernel/cpu/ss.hpp
@@ -0,0 +1,56 @@
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_SS_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_SS_HPP
+
+#include <bitset>
+#include <cstdint>
+
+namespace teachos::arch::memory::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.
+ */
+ auto read_ss() -> uint16_t;
+
+ /**
+ * @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;
+
+} // namespace teachos::arch::memory::cpu
+
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_SS_HPP
diff --git a/arch/x86_64/include/arch/memory/cpu/tlb.hpp b/arch/x86_64/include/arch/kernel/cpu/tlb.hpp
index 075d7bb..333cd58 100644
--- a/arch/x86_64/include/arch/memory/cpu/tlb.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/tlb.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_ARCH_X86_64_MEMORY_CPU_TLB_HPP
-#define TEACHOS_ARCH_X86_64_MEMORY_CPU_TLB_HPP
+#ifndef TEACHOS_ARCH_X86_64_KERNEL_CPU_TLB_HPP
+#define TEACHOS_ARCH_X86_64_KERNEL_CPU_TLB_HPP
#include "arch/memory/paging/virtual_page.hpp"
@@ -24,4 +24,4 @@ namespace teachos::arch::memory::cpu
} // namespace teachos::arch::memory::cpu
-#endif // TEACHOS_ARCH_X86_64_MEMORY_CPU_TLB_HPP
+#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_TLB_HPP
diff --git a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
index 1b2aaed..9846a21 100644
--- a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp
@@ -2,8 +2,8 @@
#define TEACHOS_ARCH_X86_64_MEMORY_PAGING_ACTIVE_PAGE_TABLE_HPP
#include "arch/exception_handling/assert.hpp"
+#include "arch/kernel/cpu/tlb.hpp"
#include "arch/memory/allocator/concept.hpp"
-#include "arch/memory/cpu/tlb.hpp"
#include "arch/memory/paging/virtual_page.hpp"
#include <array>
@@ -75,8 +75,8 @@ namespace teachos::arch::memory::paging
* @param flags A bitset of flags that configure the page table entry for this mapping.
*/
template<allocator::FrameAllocator T>
- auto map_page_to_frame(T & allocator, virtual_page page, allocator::physical_frame frame,
- std::bitset<64U> flags) -> void
+ auto map_page_to_frame(T & allocator, virtual_page page, allocator::physical_frame frame, std::bitset<64U> flags)
+ -> void
{
auto current_handle = active_handle;
diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
index 74f1c14..b137736 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -1,7 +1,7 @@
#ifndef TEACHOS_ARCH_X86_64_MEMORY_PAGING_KERNEL_MAPPER_HPP
#define TEACHOS_ARCH_X86_64_MEMORY_PAGING_KERNEL_MAPPER_HPP
-#include "arch/memory/cpu/control_register.hpp"
+#include "arch/kernel/cpu/control_register.hpp"
#include "arch/memory/paging/active_page_table.hpp"
#include "arch/memory/paging/inactive_page_table.hpp"
#include "arch/memory/paging/temporary_page.hpp"