aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/context_switching
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/context_switching')
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/gate_descriptor.cpp5
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp18
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/initialization.cpp38
-rw-r--r--arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table.cpp10
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp5
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp10
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp (renamed from arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table_pointer.cpp)6
-rw-r--r--arch/x86_64/src/context_switching/main.cpp36
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/access_byte.cpp (renamed from arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp)6
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/gdt_flags.cpp18
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp (renamed from arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp)10
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp (renamed from arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp)6
-rw-r--r--arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor.cpp (renamed from arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp)6
13 files changed, 86 insertions, 88 deletions
diff --git a/arch/x86_64/src/context_switching/descriptor_table/gate_descriptor.cpp b/arch/x86_64/src/context_switching/descriptor_table/gate_descriptor.cpp
deleted file mode 100644
index ee91e53..0000000
--- a/arch/x86_64/src/context_switching/descriptor_table/gate_descriptor.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "arch/context_switching/descriptor_table/gate_descriptor.hpp"
-
-namespace teachos::arch::context_switching::descriptor_table
-{
-} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp b/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp
deleted file mode 100644
index 9e95182..0000000
--- a/arch/x86_64/src/context_switching/descriptor_table/gdt_flags.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "arch/context_switching/descriptor_table/gdt_flags.hpp"
-
-namespace teachos::arch::context_switching::descriptor_table
-{
- gdt_flags::gdt_flags(uint8_t flags, std::bitset<20U> limit)
- : _limit_2(limit.to_ulong() >> 16U)
- , _flags(flags)
- {
- // Nothing to do.
- }
-
- auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool
- {
- return (std::bitset<4U>{_flags} & other) == other;
- }
-
- auto descriptor_table::gdt_flags::get_limit() const -> std::bitset<4U> { return std::bitset<4U>{_limit_2}; }
-} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/initialization.cpp b/arch/x86_64/src/context_switching/descriptor_table/initialization.cpp
deleted file mode 100644
index 4d8b3e3..0000000
--- a/arch/x86_64/src/context_switching/descriptor_table/initialization.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "arch/context_switching/descriptor_table/initialization.hpp"
-
-#include "arch/boot/pointers.hpp"
-#include "arch/exception_handling/assert.hpp"
-#include "arch/kernel/cpu/if.hpp"
-#include "arch/kernel/cpu/jmp.hpp"
-#include "arch/kernel/cpu/tr.hpp"
-
-namespace teachos::arch::context_switching::descriptor_table
-{
- auto initialize_descriptor_tables() -> descriptor_tables
- {
- decltype(auto) global_descriptor_table = context_switching::descriptor_table::initialize_global_descriptor_table();
-
- // TODO: Replace random construction with return value of initialization.
- interrupt_descriptor_table idt{};
- context_switching::descriptor_table::initialize_interrupt_descriptor_table();
-
- kernel::cpu::jmp((uint64_t)&global_descriptor_table.at(1), boot::segment_register_reload_pointer);
-
- uint16_t const tss_selector = (global_descriptor_table.size() - 1) << 3;
- kernel::cpu::load_task_register(tss_selector);
-
- // Not sure if offset index or offset in bytes is needed!
- // uint16_t const tss_selector = (gdt.size() - 1) * sizeof(segment_descriptor);
- // kernel::cpu::load_task_register(tss_selector);
-
- auto const stored_task_register = kernel::cpu::store_task_register();
- arch::exception_handling::assert(tss_selector == stored_task_register,
- "[Global Descriptor Table] Loaded TR value is not the same as the stored value.");
-
- kernel::cpu::set_interrupt_flag();
-
- descriptor_tables descriptor_tables = {global_descriptor_table, idt};
- return descriptor_tables;
- }
-
-} // namespace teachos::arch::context_switching::descriptor_table \ No newline at end of file
diff --git a/arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table.cpp b/arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table.cpp
deleted file mode 100644
index 9878664..0000000
--- a/arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "arch/context_switching/descriptor_table/interrupt_descriptor_table.hpp"
-
-namespace teachos::arch::context_switching::descriptor_table
-{
- auto initialize_interrupt_descriptor_table() -> void
- {
- // DO NOT
- }
-
-} // namespace teachos::arch::context_switching::descriptor_table
diff --git a/arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp
new file mode 100644
index 0000000..4f18197
--- /dev/null
+++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/gate_descriptor.cpp
@@ -0,0 +1,5 @@
+#include "arch/context_switching/interrupt_descriptor_table/gate_descriptor.hpp"
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
diff --git a/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp
new file mode 100644
index 0000000..619a695
--- /dev/null
+++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp
@@ -0,0 +1,10 @@
+#include "arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp"
+
+namespace teachos::arch::context_switching::interrupt_descriptor_table
+{
+ auto initialize_interrupt_descriptor_table() -> void
+ {
+ // DO NOT
+ }
+
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table_pointer.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp
index b45324d..981944d 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/interrupt_descriptor_table_pointer.cpp
+++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.cpp
@@ -1,6 +1,6 @@
-#include "arch/context_switching/descriptor_table/interrupt_descriptor_table_pointer.hpp"
+#include "arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table_pointer.hpp"
-namespace teachos::arch::context_switching::descriptor_table
+namespace teachos::arch::context_switching::interrupt_descriptor_table
{
interrupt_descriptor_table_pointer::interrupt_descriptor_table_pointer(uint16_t table_length,
interrupt_descriptor_table * address)
@@ -10,4 +10,4 @@ namespace teachos::arch::context_switching::descriptor_table
// Nothing to do.
}
-} // namespace teachos::arch::context_switching::descriptor_table
+} // namespace teachos::arch::context_switching::interrupt_descriptor_table
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
new file mode 100644
index 0000000..b682e79
--- /dev/null
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -0,0 +1,36 @@
+#include "arch/context_switching/main.hpp"
+
+#include "arch/boot/pointers.hpp"
+#include "arch/exception_handling/assert.hpp"
+#include "arch/kernel/cpu/if.hpp"
+#include "arch/kernel/cpu/jmp.hpp"
+#include "arch/kernel/cpu/tr.hpp"
+
+namespace teachos::arch::context_switching
+{
+ auto initialize_descriptor_tables() -> descriptor_tables
+ {
+ decltype(auto) global_descriptor_table = segment_descriptor_table::initialize_global_descriptor_table();
+
+ // TODO: Replace random construction with return value of initialization.
+ interrupt_descriptor_table::interrupt_descriptor_table idt{};
+ interrupt_descriptor_table::initialize_interrupt_descriptor_table();
+
+ kernel::cpu::jmp((uint64_t)&global_descriptor_table.at(1), boot::segment_register_reload_pointer);
+
+ // Load task state segment descriptor from the last element in the global descriptor table, done by calculating
+ // offset in bytes to the start of the segment descriptor (5 * 16) = 80
+ uint16_t const tss_selector =
+ (global_descriptor_table.size() - 1) * sizeof(segment_descriptor_table::segment_descriptor);
+ kernel::cpu::load_task_register(tss_selector);
+
+ auto const stored_task_register = kernel::cpu::store_task_register();
+ arch::exception_handling::assert(tss_selector == stored_task_register,
+ "[Global Descriptor Table] Loaded TR value is not the same as the stored value.");
+
+ kernel::cpu::set_interrupt_flag();
+
+ descriptor_tables tables = {global_descriptor_table, idt};
+ return tables;
+ }
+} // namespace teachos::arch::context_switching
diff --git a/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/access_byte.cpp
index 6b54451..34a10f1 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/access_byte.cpp
+++ b/arch/x86_64/src/context_switching/segment_descriptor_table/access_byte.cpp
@@ -1,6 +1,6 @@
-#include "arch/context_switching/descriptor_table/access_byte.hpp"
+#include "arch/context_switching/segment_descriptor_table/access_byte.hpp"
-namespace teachos::arch::context_switching::descriptor_table
+namespace teachos::arch::context_switching::segment_descriptor_table
{
access_byte::access_byte(uint8_t flags)
: _flags(flags)
@@ -12,4 +12,4 @@ namespace teachos::arch::context_switching::descriptor_table
{
return (std::bitset<8U>{_flags} & other) == other;
}
-} // namespace teachos::arch::context_switching::descriptor_table
+} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/src/context_switching/segment_descriptor_table/gdt_flags.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/gdt_flags.cpp
new file mode 100644
index 0000000..9885bda
--- /dev/null
+++ b/arch/x86_64/src/context_switching/segment_descriptor_table/gdt_flags.cpp
@@ -0,0 +1,18 @@
+#include "arch/context_switching/segment_descriptor_table/gdt_flags.hpp"
+
+namespace teachos::arch::context_switching::segment_descriptor_table
+{
+ gdt_flags::gdt_flags(uint8_t flags, std::bitset<20U> limit)
+ : _limit_2(limit.to_ulong() >> 16U)
+ , _flags(flags)
+ {
+ // Nothing to do.
+ }
+
+ auto gdt_flags::contains_flags(std::bitset<4U> other) const -> bool
+ {
+ return (std::bitset<4U>{_flags} & other) == other;
+ }
+
+ auto gdt_flags::get_limit() const -> std::bitset<4U> { return std::bitset<4U>{_limit_2}; }
+} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp
index 639b079..1bbd24f 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table.cpp
+++ b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table.cpp
@@ -1,13 +1,13 @@
-#include "arch/context_switching/descriptor_table/global_descriptor_table.hpp"
+#include "arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp"
-#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
-#include "arch/context_switching/descriptor_table/task_state_segment.hpp"
+#include "arch/context_switching/segment_descriptor_table/segment_descriptor.hpp"
+#include "arch/context_switching/segment_descriptor_table/task_state_segment.hpp"
#include "arch/exception_handling/assert.hpp"
#include "arch/kernel/cpu/gdtr.hpp"
#include "arch/kernel/cpu/tr.hpp"
#include "arch/stl/vector.hpp"
-namespace teachos::arch::context_switching::descriptor_table
+namespace teachos::arch::context_switching::segment_descriptor_table
{
auto create_segment_descriptor(segment_descriptor_type segment_descriptor_type, access_level access_level)
-> segment_descriptor
@@ -89,4 +89,4 @@ namespace teachos::arch::context_switching::descriptor_table
return gdt;
}
-} // namespace teachos::arch::context_switching::descriptor_table
+} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp
index f552496..132565f 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/global_descriptor_table_pointer.cpp
+++ b/arch/x86_64/src/context_switching/segment_descriptor_table/global_descriptor_table_pointer.cpp
@@ -1,6 +1,6 @@
-#include "arch/context_switching/descriptor_table/global_descriptor_table_pointer.hpp"
+#include "arch/context_switching/segment_descriptor_table/global_descriptor_table_pointer.hpp"
-namespace teachos::arch::context_switching::descriptor_table
+namespace teachos::arch::context_switching::segment_descriptor_table
{
global_descriptor_table_pointer::global_descriptor_table_pointer(uint16_t table_length,
global_descriptor_table * address)
@@ -9,4 +9,4 @@ namespace teachos::arch::context_switching::descriptor_table
{
// Nothing to do.
}
-} // namespace teachos::arch::context_switching::descriptor_table
+} // namespace teachos::arch::context_switching::segment_descriptor_table
diff --git a/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp b/arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor.cpp
index 2385c58..6d831a1 100644
--- a/arch/x86_64/src/context_switching/descriptor_table/segment_descriptor.cpp
+++ b/arch/x86_64/src/context_switching/segment_descriptor_table/segment_descriptor.cpp
@@ -1,6 +1,6 @@
-#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
+#include "arch/context_switching/segment_descriptor_table/segment_descriptor.hpp"
-namespace teachos::arch::context_switching::descriptor_table
+namespace teachos::arch::context_switching::segment_descriptor_table
{
segment_descriptor::segment_descriptor(uint128_t flags)
: _limit_1(flags << 112U)
@@ -32,4 +32,4 @@ namespace teachos::arch::context_switching::descriptor_table
return _access.contains_flags(access_byte::CODE_SEGMENT) ? segment_descriptor_type::CODE_SEGMENT
: segment_descriptor_type::DATA_SEGMENT;
}
-} // namespace teachos::arch::context_switching::descriptor_table
+} // namespace teachos::arch::context_switching::segment_descriptor_table