aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel/cpu/tr.cpp
blob: e2811892aa8d1008d7f80c94e7440fabc3e1c6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "arch/kernel/cpu/tr.hpp"

namespace teachos::arch::kernel::cpu
{
  auto store_task_register() -> uint16_t
  {
    uint16_t current_value{};
    asm("str %[output]" : [output] "=r"(current_value));
    return current_value;
  }

  auto load_task_register(uint16_t gdt_offset) -> void
  {
    // asm volatile("ltr %[input]" : /* no output from call */ : [input] "R"(gdt_offset));
    //  https://www.scs.stanford.edu/05au-cs240c/lab/i386/s07_03.htm
    asm volatile("mov %[input], %%ax\n"
                 "ltr %%ax\n"
                 : /* no output from call */
                 : [input] "r"(gdt_offset)
                 : "ax");
  }
}  // namespace teachos::arch::kernel::cpu