aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel/cpu/ss.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/kernel/cpu/ss.cpp')
-rw-r--r--arch/x86_64/src/kernel/cpu/ss.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/arch/x86_64/src/kernel/cpu/ss.cpp b/arch/x86_64/src/kernel/cpu/ss.cpp
new file mode 100644
index 0000000..b7e52e1
--- /dev/null
+++ b/arch/x86_64/src/kernel/cpu/ss.cpp
@@ -0,0 +1,33 @@
+#include "arch/kernel/cpu/ss.hpp"
+
+namespace teachos::arch::memory::cpu
+{
+ segment_selector::segment_selector(uint16_t index, std::bitset<1U> table_indicator,
+ std::bitset<2U> requested_privilege_level)
+ : index(index)
+ , table_indicator(table_indicator)
+ , requested_privilege_level(requested_privilege_level)
+ {
+ // Nothing to do
+ }
+
+ auto segment_selector::to_uint16() const -> uint16_t
+ {
+ return static_cast<uint16_t>((index << 3) | (table_indicator.to_ulong() << 2) |
+ requested_privilege_level.to_ulong());
+ }
+
+ auto read_ss() -> uint16_t
+ {
+ uint16_t ss;
+ __asm__("mov %%ss, %0" : "=r"(ss));
+ return ss;
+ }
+
+ auto write_ss(segment_selector selector) -> void
+ {
+ uint16_t ss = selector.to_uint16();
+ __asm__("mov %0, %%ss" ::"r"(ss));
+ }
+
+} // namespace teachos::arch::memory::cpu \ No newline at end of file