aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel/cpu
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-04-10 12:29:19 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-04-10 12:29:19 +0000
commit87091e2246d2c4c794d9d6a0c5398ca80d92335a (patch)
tree4f9ff755da53182d864b604f28e10c0dd8ba82bd /arch/x86_64/src/kernel/cpu
parentdff78de795a89c181e9c94b26db2f16988e8f4d6 (diff)
downloadteachos-87091e2246d2c4c794d9d6a0c5398ca80d92335a.tar.xz
teachos-87091e2246d2c4c794d9d6a0c5398ca80d92335a.zip
add register validation and asserts
Diffstat (limited to 'arch/x86_64/src/kernel/cpu')
-rw-r--r--arch/x86_64/src/kernel/cpu/segment_register.cpp23
1 files changed, 22 insertions, 1 deletions
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