blob: 1f28e7f54e024e3e0333aaa52e8043ee18a5b1e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "arch/kernel/cpu/ss.hpp"
namespace teachos::arch::kernel::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 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 %[input], %%ss" : /* no output from call */ : [input] "r"(ss));
}
} // namespace teachos::arch::kernel::cpu
|