aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/memory
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/memory')
-rw-r--r--arch/x86_64/src/memory/cpu/control_register.cpp30
-rw-r--r--arch/x86_64/src/memory/cpu/msr.cpp8
2 files changed, 22 insertions, 16 deletions
diff --git a/arch/x86_64/src/memory/cpu/control_register.cpp b/arch/x86_64/src/memory/cpu/control_register.cpp
index 38a887c..7624244 100644
--- a/arch/x86_64/src/memory/cpu/control_register.cpp
+++ b/arch/x86_64/src/memory/cpu/control_register.cpp
@@ -2,24 +2,26 @@
#include "arch/exception_handling/assert.hpp"
+#include <type_traits>
+
namespace teachos::arch::memory::cpu
{
- auto read_control_register(control_register cr) -> std::size_t
+ auto read_control_register(control_register cr) -> uint64_t
{
- std::size_t current_value;
+ uint64_t current_value;
switch (cr)
{
case control_register::CR0:
- asm volatile("movq %%cr0, %[output]" : [output] "=r"(current_value));
+ asm volatile("mov %%cr0, %[output]" : [output] "=r"(current_value));
break;
case control_register::CR2:
- asm volatile("movq %%cr2, %[output]" : [output] "=r"(current_value));
+ asm volatile("mov %%cr2, %[output]" : [output] "=r"(current_value));
break;
case control_register::CR3:
- asm volatile("movq %%cr3, %[output]" : [output] "=r"(current_value));
+ asm volatile("mov %%cr3, %[output]" : [output] "=r"(current_value));
break;
case control_register::CR4:
- asm volatile("movq %%cr4, %[output]" : [output] "=r"(current_value));
+ asm volatile("mov %%cr4, %[output]" : [output] "=r"(current_value));
break;
default:
exception_handling::assert(false,
@@ -29,30 +31,30 @@ namespace teachos::arch::memory::cpu
return current_value;
}
- auto write_control_register(control_register cr, std::size_t new_value) -> void
+ auto write_control_register(control_register cr, uint64_t new_value) -> void
{
switch (cr)
{
case control_register::CR0:
- asm volatile("movq %[input], %%cr0"
+ asm volatile("mov %[input], %%cr0"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
case control_register::CR2:
- asm volatile("movq %[input], %%cr2"
+ asm volatile("mov %[input], %%cr2"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
case control_register::CR3:
- asm volatile("movq %[input], %%cr3"
+ asm volatile("mov %[input], %%cr3"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
case control_register::CR4:
- asm volatile("movq %[input], %%cr4"
+ asm volatile("mov %[input], %%cr4"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
@@ -63,4 +65,10 @@ namespace teachos::arch::memory::cpu
break;
}
}
+
+ auto set_cr2_bit(cr2_flags flag) -> void
+ {
+ auto const cr2 = read_control_register(control_register::CR2);
+ write_control_register(control_register::CR2, static_cast<std::underlying_type<cr2_flags>::type>(flag) | cr2);
+ }
} // namespace teachos::arch::memory::cpu
diff --git a/arch/x86_64/src/memory/cpu/msr.cpp b/arch/x86_64/src/memory/cpu/msr.cpp
index 6e3d1d3..b83f902 100644
--- a/arch/x86_64/src/memory/cpu/msr.cpp
+++ b/arch/x86_64/src/memory/cpu/msr.cpp
@@ -4,7 +4,7 @@ namespace teachos::arch::memory::cpu
{
namespace
{
- constexpr uint32_t IA32_EFER_ADDRESS = 0xC0000080;
+ auto constexpr IA32_EFER_ADDRESS = 0xC0000080;
}
auto read_msr(uint32_t msr) -> uint64_t
@@ -25,9 +25,7 @@ namespace teachos::arch::memory::cpu
auto set_efer_bit(efer_flags flag) -> void
{
- uint64_t const efer = read_msr(IA32_EFER_ADDRESS);
- write_msr(IA32_EFER_ADDRESS, static_cast<uint64_t>(flag) | efer);
+ auto const efer = read_msr(IA32_EFER_ADDRESS);
+ write_msr(IA32_EFER_ADDRESS, static_cast<std::underlying_type<efer_flags>::type>(flag) | efer);
}
-
- auto enable_nxe_bit() -> void { set_efer_bit(efer_flags::NXE); }
} // namespace teachos::arch::memory::cpu