aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/CMakeLists.txt1
-rw-r--r--arch/x86_64/include/arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp20
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/lgdt.hpp8
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp7
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp12
-rw-r--r--arch/x86_64/src/kernel/cpu/lgdt.cpp9
-rw-r--r--arch/x86_64/src/kernel/cpu/ss.cpp8
-rw-r--r--arch/x86_64/src/kernel/main.cpp10
8 files changed, 60 insertions, 15 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt
index 3c7068b..912daf6 100644
--- a/arch/x86_64/CMakeLists.txt
+++ b/arch/x86_64/CMakeLists.txt
@@ -91,6 +91,7 @@ target_sources("_context" PRIVATE
"src/context_switching/descriptor_table/access_byte.cpp"
"src/context_switching/descriptor_table/gdt_flags.cpp"
"src/context_switching/descriptor_table/global_descriptor_table.cpp"
+ "src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp"
"src/context_switching/descriptor_table/segment_descriptor.cpp"
)
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
index 06f40fe..ed17be3 100644
--- 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
@@ -18,8 +18,24 @@ namespace teachos::arch::context_switching::descriptor_table
*/
struct [[gnu::packed]] global_descriptor_table_pointer
{
- uint16_t table_length; ///< The amount of segment descriptor entries in the global descriptor table - 1.
- global_descriptor_table * address; ///< Pointer to the GDT base address.
+ /**
+ * @brief Default constructor.
+ */
+ global_descriptor_table_pointer() = default;
+
+ /**
+ * @brief Constructor.
+ */
+ global_descriptor_table_pointer(uint16_t table_length, global_descriptor_table * 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.
+ global_descriptor_table * address = {}; ///< Non-owning pointer to the GDT base address.
};
} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp b/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp
index b0b2048..85e2949 100644
--- a/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/lgdt.hpp
@@ -8,6 +8,14 @@
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::descriptor_table::global_descriptor_table_pointer;
+
/**
* @brief Loads the global_descriptor_table_pointer into the global descriptor table register (GDTR).
*/
diff --git a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
index cbd230b..c5554a7 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
+++ b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
@@ -1,6 +1,7 @@
#include "arch/context_switching/descriptor_table/global_descriptor_table.hpp"
#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
+#include "arch/exception_handling/assert.hpp"
#include "arch/kernel/cpu/lgdt.hpp"
#include "arch/stl/vector.hpp"
@@ -47,6 +48,12 @@ namespace teachos::arch::context_switching::descriptor_table
decltype(auto) gdt = create_global_descriptor_table();
global_descriptor_table_pointer gdt_pointer{static_cast<uint16_t>(gdt.size() - 1), &gdt};
kernel::cpu::load_global_descriptor_table(gdt_pointer);
+
+ auto stored_gdt_pointer = kernel::cpu::store_global_descriptor_table();
+ arch::exception_handling::assert(
+ gdt_pointer == stored_gdt_pointer,
+ "[Global Descriptor Table] Loaded GDTR value is not the same as the stored value.");
+
return gdt;
}
} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp
new file mode 100644
index 0000000..f552496
--- /dev/null
+++ b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp
@@ -0,0 +1,12 @@
+#include "arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp"
+
+namespace teachos::arch::context_switching::descriptor_table
+{
+ global_descriptor_table_pointer::global_descriptor_table_pointer(uint16_t table_length,
+ global_descriptor_table * address)
+ : table_length(table_length)
+ , address(address)
+ {
+ // Nothing to do.
+ }
+} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/src/kernel/cpu/lgdt.cpp b/arch/x86_64/src/kernel/cpu/lgdt.cpp
index cad3ffa..386914f 100644
--- a/arch/x86_64/src/kernel/cpu/lgdt.cpp
+++ b/arch/x86_64/src/kernel/cpu/lgdt.cpp
@@ -4,10 +4,17 @@
namespace teachos::arch::kernel::cpu
{
+ auto store_global_descriptor_table() -> context_switching::descriptor_table::global_descriptor_table_pointer
+ {
+ context_switching::descriptor_table::global_descriptor_table_pointer current_value{};
+ asm("sgdt %[output]" : [output] "=m"(current_value));
+ return current_value;
+ }
+
auto
load_global_descriptor_table(context_switching::descriptor_table::global_descriptor_table_pointer const & gdt_pointer)
-> void
{
- asm volatile("lgdt %[input]" : /* no output from call */ : [input] "r"(gdt_pointer));
+ asm volatile("lgdt %[input]" : /* no output from call */ : [input] "m"(gdt_pointer));
}
} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/src/kernel/cpu/ss.cpp b/arch/x86_64/src/kernel/cpu/ss.cpp
index 9c8dd61..1f28e7f 100644
--- a/arch/x86_64/src/kernel/cpu/ss.cpp
+++ b/arch/x86_64/src/kernel/cpu/ss.cpp
@@ -19,15 +19,15 @@ namespace teachos::arch::kernel::cpu
auto read_ss() -> uint16_t
{
- uint16_t ss;
- asm volatile("mov %%ss, %0" : "=r"(ss));
- return ss;
+ uint16_t segment_selector;
+ asm volatile("mov %%ss, %[output]" : [output] "=r"(segment_selector));
+ return segment_selector;
}
auto write_ss(segment_selector selector) -> void
{
uint16_t ss = selector.to_uint16();
- asm volatile("mov %0, %%ss" ::"r"(ss));
+ asm volatile("mov %[input], %%ss" : /* no output from call */ : [input] "r"(ss));
}
} // namespace teachos::arch::kernel::cpu \ No newline at end of file
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 055b516..2c0b6c8 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -1,6 +1,7 @@
#include "arch/kernel/main.hpp"
#include "arch/context_switching/descriptor_table/global_descriptor_table.hpp"
+#include "arch/kernel/cpu/lgdt.hpp"
#include "arch/memory/heap/bump_allocator.hpp"
#include "arch/memory/heap/global_heap_allocator.hpp"
#include "arch/memory/main.hpp"
@@ -61,14 +62,7 @@ namespace teachos::arch::kernel
heap_test();
auto global_descriptor_table = context_switching::descriptor_table::initialize_global_descriptor_table();
-
- decltype(auto) x = global_descriptor_table.at(1);
- if (global_descriptor_table.size() == 0)
- {
- }
- if (x.get_segment_type() == context_switching::descriptor_table::segment_descriptor_type::CODE_SEGMENT)
- {
- }
+ (void)global_descriptor_table.at(1);
video::vga::text::write("GDT FILLED", video::vga::text::common_attributes::green_on_black);
}
} // namespace teachos::arch::kernel