aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-07-24 16:33:10 +0000
committerFelix Morgner <felix.morgner@ost.ch>2025-07-24 16:33:10 +0000
commit1b65136a11453fe7e89320dfe6170a0cd75e60dd (patch)
treeb031192e5af29866e75a2c842d01e22f16877bcc /arch/x86_64/src
parent3b9bbbb4be529f2365b8bc2e43c1c8e9a65b1a07 (diff)
downloadteachos-1b65136a11453fe7e89320dfe6170a0cd75e60dd.tar.xz
teachos-1b65136a11453fe7e89320dfe6170a0cd75e60dd.zip
x86_64: clean up hw details
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/cpu/registers.cpp (renamed from arch/x86_64/src/kernel/cpu/control_register.cpp)28
-rw-r--r--arch/x86_64/src/kernel/cpu/tlb.cpp16
-rw-r--r--arch/x86_64/src/memory/mmu.cpp17
3 files changed, 30 insertions, 31 deletions
diff --git a/arch/x86_64/src/kernel/cpu/control_register.cpp b/arch/x86_64/src/cpu/registers.cpp
index 41b8cd7..7ade98d 100644
--- a/arch/x86_64/src/kernel/cpu/control_register.cpp
+++ b/arch/x86_64/src/cpu/registers.cpp
@@ -1,26 +1,24 @@
-#include "arch/kernel/cpu/control_register.hpp"
-
-#include "arch/exception_handling/panic.hpp"
+#include "x86_64/cpu/registers.hpp"
#include <type_traits>
-namespace teachos::arch::kernel::cpu
+namespace teachos::x86_64::cpu
{
auto read_control_register(control_register cr) -> uint64_t
{
uint64_t current_value;
switch (cr)
{
- case control_register::CR0:
+ case control_register::cr0:
asm volatile("mov %%cr0, %[output]" : [output] "=r"(current_value));
break;
- case control_register::CR2:
+ case control_register::cr2:
asm volatile("mov %%cr2, %[output]" : [output] "=r"(current_value));
break;
- case control_register::CR3:
+ case control_register::cr3:
asm volatile("mov %%cr3, %[output]" : [output] "=r"(current_value));
break;
- case control_register::CR4:
+ case control_register::cr4:
asm volatile("mov %%cr4, %[output]" : [output] "=r"(current_value));
break;
}
@@ -31,25 +29,25 @@ namespace teachos::arch::kernel::cpu
{
switch (cr)
{
- case control_register::CR0:
+ case control_register::cr0:
asm volatile("mov %[input], %%cr0"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
- case control_register::CR2:
+ case control_register::cr2:
asm volatile("mov %[input], %%cr2"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
- case control_register::CR3:
+ case control_register::cr3:
asm volatile("mov %[input], %%cr3"
: /* no output from call */
: [input] "r"(new_value)
: "memory");
break;
- case control_register::CR4:
+ case control_register::cr4:
asm volatile("mov %[input], %%cr4"
: /* no output from call */
: [input] "r"(new_value)
@@ -60,7 +58,7 @@ namespace teachos::arch::kernel::cpu
auto set_cr0_bit(cr0_flags flag) -> void
{
- auto const cr0 = read_control_register(control_register::CR0);
- write_control_register(control_register::CR0, static_cast<std::underlying_type<cr0_flags>::type>(flag) | cr0);
+ auto const cr0 = read_control_register(control_register::cr0);
+ write_control_register(control_register::cr0, static_cast<std::underlying_type<cr0_flags>::type>(flag) | cr0);
}
-} // namespace teachos::arch::kernel::cpu
+} // namespace teachos::x86_64::cpu
diff --git a/arch/x86_64/src/kernel/cpu/tlb.cpp b/arch/x86_64/src/kernel/cpu/tlb.cpp
deleted file mode 100644
index a09001c..0000000
--- a/arch/x86_64/src/kernel/cpu/tlb.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "arch/kernel/cpu/tlb.hpp"
-
-#include "arch/kernel/cpu/control_register.hpp"
-
-namespace teachos::arch::kernel::cpu
-{
- auto tlb_flush(memory::paging::virtual_address address) -> void
- {
- asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory");
- }
-
- auto tlb_flush_all() -> void
- {
- write_control_register(cpu::control_register::CR3, read_control_register(cpu::control_register::CR3));
- }
-} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/src/memory/mmu.cpp b/arch/x86_64/src/memory/mmu.cpp
new file mode 100644
index 0000000..31783fe
--- /dev/null
+++ b/arch/x86_64/src/memory/mmu.cpp
@@ -0,0 +1,17 @@
+#include "x86_64/memory/mmu.hpp"
+
+#include "x86_64/cpu/registers.hpp"
+
+namespace teachos::x86_64::memory
+{
+ auto tlb_flush(linear_address address) -> void
+ {
+ asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory");
+ }
+
+ auto tlb_flush_all() -> void
+ {
+ auto current_value = cpu::read_control_register(cpu::control_register::cr3);
+ cpu::write_control_register(cpu::control_register::cr3, current_value);
+ }
+} // namespace teachos::x86_64::memory