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

#include "arch/exception_handling/assert.hpp"

namespace teachos::arch::memory::cpu
{
  auto read_cr3_register() -> allocator::physical_address
  {
    allocator::physical_address cr3;
    asm volatile("movq %%cr3, %[output]" : [output] "=r"(cr3) : /* no input into call */ : "memory");
    return cr3;
  }

  auto write_cr3_register(allocator::physical_address new_p4_table_address) -> void
  {
    exception_handling::assert(new_p4_table_address % allocator::PAGE_FRAME_SIZE == 0U,
                               "[CR3] Physical address to be written into register must be page aligned");
    asm volatile("movq %[input], %%cr3"
                 : /* no output from call */
                 : [input] "r"(new_p4_table_address)
                 : "memory");
  }
}  // namespace teachos::arch::memory::cpu