aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/include/arch/kernel/cpu/segment_register.hpp6
-rw-r--r--arch/x86_64/src/context_switching/main.cpp9
-rw-r--r--arch/x86_64/src/kernel/cpu/segment_register.cpp23
3 files changed, 34 insertions, 4 deletions
diff --git a/arch/x86_64/include/arch/kernel/cpu/segment_register.hpp b/arch/x86_64/include/arch/kernel/cpu/segment_register.hpp
index fd5a972..d495ce6 100644
--- a/arch/x86_64/include/arch/kernel/cpu/segment_register.hpp
+++ b/arch/x86_64/include/arch/kernel/cpu/segment_register.hpp
@@ -25,6 +25,12 @@ namespace teachos::arch::kernel::cpu
*/
auto read_code_segment_register() -> context_switching::interrupt_descriptor_table::segment_selector;
+ /**
+ * @brief TODO
+ *
+ */
+ auto validate_data_segment_registers() -> context_switching::interrupt_descriptor_table::segment_selector;
+
} // namespace teachos::arch::kernel::cpu
#endif // TEACHOS_ARCH_X86_64_KERNEL_CPU_SEGMENT_REGISTER_HPP
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
index 3efba45..0f2ec93 100644
--- a/arch/x86_64/src/context_switching/main.cpp
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -2,6 +2,7 @@
#include "arch/exception_handling/assert.hpp"
#include "arch/kernel/cpu/call.hpp"
+#include "arch/kernel/cpu/control_register.hpp"
#include "arch/kernel/cpu/if.hpp"
#include "arch/kernel/cpu/segment_register.hpp"
#include "arch/kernel/cpu/tr.hpp"
@@ -82,10 +83,12 @@ namespace teachos::arch::context_switching
auto user_mode_main() -> void
{
auto current_segment = kernel::cpu::read_code_segment_register();
- arch::exception_handling::assert(USER_CODE_SEGMENT_SELECTOR == current_segment,
- "[Context Switching] Context switch into user mode not successful");
+ exception_handling::assert(USER_CODE_SEGMENT_SELECTOR == current_segment,
+ "[Context Switching] Context switch into user mode not successful");
+ exception_handling::assert(USER_DATA_SEGMENT_SELECTOR == kernel::cpu::validate_data_segment_registers(),
+ "[Context Switching] Context switch into user mode not successful");
- video::vga::text::write("User Mode!!!", video::vga::text::common_attributes::green_on_black);
+ video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black);
}
auto switch_to_user_mode() -> void
diff --git a/arch/x86_64/src/kernel/cpu/segment_register.cpp b/arch/x86_64/src/kernel/cpu/segment_register.cpp
index 9fb7433..cb367b6 100644
--- a/arch/x86_64/src/kernel/cpu/segment_register.cpp
+++ b/arch/x86_64/src/kernel/cpu/segment_register.cpp
@@ -1,6 +1,7 @@
#include "arch/kernel/cpu/segment_register.hpp"
#include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp"
+#include "arch/exception_handling/assert.hpp"
namespace teachos::arch::kernel::cpu
{
@@ -37,6 +38,26 @@ namespace teachos::arch::kernel::cpu
return current_value;
}
- auto validate_segment_registers() -> context_switching::interrupt_descriptor_table::segment_selector {}
+ auto validate_data_segment_registers() -> context_switching::interrupt_descriptor_table::segment_selector
+ {
+ context_switching::interrupt_descriptor_table::segment_selector ss;
+ context_switching::interrupt_descriptor_table::segment_selector ds;
+ context_switching::interrupt_descriptor_table::segment_selector es;
+ context_switching::interrupt_descriptor_table::segment_selector fs;
+ context_switching::interrupt_descriptor_table::segment_selector gs;
+
+ asm volatile(
+ "mov %%ss, %[ss_output]\n"
+ "mov %%ds, %[ds_output]\n"
+ "mov %%es, %[es_output]\n"
+ "mov %%fs, %[fs_output]\n"
+ "mov %%gs, %[gs_output]\n"
+ : [ss_output] "=r"(ss), [ds_output] "=r"(ds), [es_output] "=r"(es), [fs_output] "=r"(fs), [gs_output] "=r"(gs));
+
+ auto result = ss == ds && ss == es && ss == fs && ss == gs;
+ exception_handling::assert(result, "[Segment Register] Values in data register are not the same.");
+
+ return ss;
+ }
} // namespace teachos::arch::kernel::cpu