aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp17
-rw-r--r--arch/x86_64/src/kernel/cpu/control_register.cpp4
-rw-r--r--arch/x86_64/src/kernel/cpu/lgdt.cpp14
-rw-r--r--arch/x86_64/src/kernel/cpu/msr.cpp4
-rw-r--r--arch/x86_64/src/kernel/cpu/ss.cpp8
-rw-r--r--arch/x86_64/src/kernel/cpu/tlb.cpp6
-rw-r--r--arch/x86_64/src/memory/main.cpp4
7 files changed, 35 insertions, 22 deletions
diff --git a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
index 1cba13c..ca3d7ff 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
+++ b/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
@@ -1,9 +1,9 @@
-#include "global_descriptor_table.hpp"
+#include "arch/context_switching/descriptor_table/global_descriptor_table.hpp"
+#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
+#include "arch/kernel/cpu/lgdt.hpp"
#include "arch/stl/vector.hpp"
-#include "segment_descriptor.hpp"
-
namespace teachos::arch::context_switching::descriptor_table
{
auto create_global_descriptor_table() -> global_descriptor_table
@@ -43,15 +43,14 @@ namespace teachos::arch::context_switching::descriptor_table
return global_descriptor_table;
}
- auto load_global_descriptor_table(global_descriptor_table_pointer gdt_pointer) -> void
- {
- //
- }
-
auto initialize_global_descriptor_table() -> global_descriptor_table
{
global_descriptor_table gdt{create_global_descriptor_table()};
+
+ // TODO: Second argument does not work yet (because pointer hpp)
global_descriptor_table_pointer gdt_pointer{gdt.size() - 1, &gdt};
- load_global_descriptor_table(gdt_pointer);
+ kernel::cpu::load_global_descriptor_table(gdt_pointer);
+
+ return gdt;
}
} // namespace teachos::arch::context_switching::descriptor_table \ No newline at end of file
diff --git a/arch/x86_64/src/kernel/cpu/control_register.cpp b/arch/x86_64/src/kernel/cpu/control_register.cpp
index 3051bae..a39a360 100644
--- a/arch/x86_64/src/kernel/cpu/control_register.cpp
+++ b/arch/x86_64/src/kernel/cpu/control_register.cpp
@@ -4,7 +4,7 @@
#include <type_traits>
-namespace teachos::arch::memory::cpu
+namespace teachos::arch::kernel::cpu
{
auto read_control_register(control_register cr) -> uint64_t
{
@@ -69,4 +69,4 @@ namespace teachos::arch::memory::cpu
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::memory::cpu
+} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/src/kernel/cpu/lgdt.cpp b/arch/x86_64/src/kernel/cpu/lgdt.cpp
new file mode 100644
index 0000000..cb13aa8
--- /dev/null
+++ b/arch/x86_64/src/kernel/cpu/lgdt.cpp
@@ -0,0 +1,14 @@
+#include "arch/kernel/cpu/lgdt.hpp"
+
+#include "arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp"
+
+namespace teachos::arch::kernel::cpu
+{
+ auto load_global_descriptor_table(context_switching::descriptor_table::global_descriptor_table_pointer gdt_pointer)
+ -> void
+ {
+ // TODO: build lgdt argument from global_descriptor_table_pointer (don't know how yet)
+ asm volatile("lgdt (%0)" : : "r"(gdt_pointer));
+ }
+
+} // namespace teachos::arch::kernel::cpu \ No newline at end of file
diff --git a/arch/x86_64/src/kernel/cpu/msr.cpp b/arch/x86_64/src/kernel/cpu/msr.cpp
index 082bca9..6249f8f 100644
--- a/arch/x86_64/src/kernel/cpu/msr.cpp
+++ b/arch/x86_64/src/kernel/cpu/msr.cpp
@@ -1,6 +1,6 @@
#include "arch/kernel/cpu/msr.hpp"
-namespace teachos::arch::memory::cpu
+namespace teachos::arch::kernel::cpu
{
namespace
{
@@ -28,4 +28,4 @@ namespace teachos::arch::memory::cpu
auto const efer = read_msr(IA32_EFER_ADDRESS);
write_msr(IA32_EFER_ADDRESS, static_cast<std::underlying_type<efer_flags>::type>(flag) | efer);
}
-} // namespace teachos::arch::memory::cpu
+} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/src/kernel/cpu/ss.cpp b/arch/x86_64/src/kernel/cpu/ss.cpp
index b7e52e1..9c8dd61 100644
--- a/arch/x86_64/src/kernel/cpu/ss.cpp
+++ b/arch/x86_64/src/kernel/cpu/ss.cpp
@@ -1,6 +1,6 @@
#include "arch/kernel/cpu/ss.hpp"
-namespace teachos::arch::memory::cpu
+namespace teachos::arch::kernel::cpu
{
segment_selector::segment_selector(uint16_t index, std::bitset<1U> table_indicator,
std::bitset<2U> requested_privilege_level)
@@ -20,14 +20,14 @@ namespace teachos::arch::memory::cpu
auto read_ss() -> uint16_t
{
uint16_t ss;
- __asm__("mov %%ss, %0" : "=r"(ss));
+ asm volatile("mov %%ss, %0" : "=r"(ss));
return ss;
}
auto write_ss(segment_selector selector) -> void
{
uint16_t ss = selector.to_uint16();
- __asm__("mov %0, %%ss" ::"r"(ss));
+ asm volatile("mov %0, %%ss" ::"r"(ss));
}
-} // namespace teachos::arch::memory::cpu \ No newline at end of file
+} // namespace teachos::arch::kernel::cpu \ No newline at end of file
diff --git a/arch/x86_64/src/kernel/cpu/tlb.cpp b/arch/x86_64/src/kernel/cpu/tlb.cpp
index e753c2c..a09001c 100644
--- a/arch/x86_64/src/kernel/cpu/tlb.cpp
+++ b/arch/x86_64/src/kernel/cpu/tlb.cpp
@@ -2,9 +2,9 @@
#include "arch/kernel/cpu/control_register.hpp"
-namespace teachos::arch::memory::cpu
+namespace teachos::arch::kernel::cpu
{
- auto tlb_flush(paging::virtual_address address) -> void
+ auto tlb_flush(memory::paging::virtual_address address) -> void
{
asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory");
}
@@ -13,4 +13,4 @@ namespace teachos::arch::memory::cpu
{
write_control_register(cpu::control_register::CR3, read_control_register(cpu::control_register::CR3));
}
-} // namespace teachos::arch::memory::cpu
+} // namespace teachos::arch::kernel::cpu
diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp
index abc7431..a920a20 100644
--- a/arch/x86_64/src/memory/main.cpp
+++ b/arch/x86_64/src/memory/main.cpp
@@ -38,8 +38,8 @@ namespace teachos::arch::memory
auto const memory_information = multiboot::read_multiboot2();
allocator::area_frame_allocator allocator(memory_information);
- cpu::set_cr0_bit(memory::cpu::cr0_flags::WRITE_PROTECT);
- cpu::set_efer_bit(memory::cpu::efer_flags::NXE);
+ kernel::cpu::set_cr0_bit(kernel::cpu::cr0_flags::WRITE_PROTECT);
+ kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::NXE);
paging::kernel_mapper kernel(allocator, memory_information);
auto & active_table = kernel.remap_kernel();