diff options
| author | Fabian Imhof <fabian.imhof@ost.ch> | 2025-03-13 14:05:45 +0000 |
|---|---|---|
| committer | Fabian Imhof <fabian.imhof@ost.ch> | 2025-03-13 14:05:45 +0000 |
| commit | 2e4cbd473ff3bb7ac7371af39becf830b4fb753b (patch) | |
| tree | 3eb8cc5fcf255db3c308930b800c9dd32c6b295b /arch/x86_64/src/kernel/cpu/ss.cpp | |
| parent | b8a0024ee71a64ec0e87a1e2d0c0c7280dc954e6 (diff) | |
| download | teachos-2e4cbd473ff3bb7ac7371af39becf830b4fb753b.tar.xz teachos-2e4cbd473ff3bb7ac7371af39becf830b4fb753b.zip | |
IN_PROGRESS implement gdt initialization
Diffstat (limited to 'arch/x86_64/src/kernel/cpu/ss.cpp')
| -rw-r--r-- | arch/x86_64/src/kernel/cpu/ss.cpp | 33 |
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 |
