blob: 9c8dd611cb712812712ad44dfe14665007eeb28e (
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 ss;
asm volatile("mov %%ss, %0" : "=r"(ss));
return ss;
}
auto write_ss(segment_selector selector) -> void
{
uint16_t ss = selector.to_uint16();
asm volatile("mov %0, %%ss" ::"r"(ss));
}
} // namespace teachos::arch::kernel::cpu
|