aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86_64/src/kernel')
-rw-r--r--arch/x86_64/src/kernel/main.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/arch/x86_64/src/kernel/main.cpp b/arch/x86_64/src/kernel/main.cpp
index 472aed5..d3938ed 100644
--- a/arch/x86_64/src/kernel/main.cpp
+++ b/arch/x86_64/src/kernel/main.cpp
@@ -1,9 +1,11 @@
#include "arch/kernel/main.hpp"
+#include "arch/context_switching/descriptor_table/segment_descriptor.hpp"
#include "arch/memory/heap/bump_allocator.hpp"
#include "arch/memory/heap/global_heap_allocator.hpp"
#include "arch/memory/main.hpp"
#include "arch/memory/multiboot/reader.hpp"
+#include "arch/stl/vector.hpp"
#include "arch/video/vga/text.hpp"
namespace teachos::arch::kernel
@@ -57,5 +59,53 @@ namespace teachos::arch::kernel
memory::heap::global_heap_allocator::register_heap_allocator(memory::heap::heap_allocator_type::LINKED_LIST);
heap_test();
+
+ using context_switching::descriptor_table::access_byte;
+ using context_switching::descriptor_table::gdt_flags;
+ using context_switching::descriptor_table::segment_descriptor;
+ using context_switching::descriptor_table::segment_descriptor_type;
+ using context_switching::descriptor_table::type_field;
+
+ segment_descriptor null_segment{0};
+
+ // Kernel space code segment
+ access_byte kernel_code_access_byte{access_byte::PRESENT | access_byte::ACCESS_LEVEL_KERNEL |
+ access_byte::CODE_OR_DATA_SEGMENT,
+ type_field::CODE_SEGMENT | type_field::READABLE};
+ gdt_flags kernel_code_gdt_flags{gdt_flags::GRANULARITY | gdt_flags::LENGTH};
+ segment_descriptor kernel_code_segment{kernel_code_access_byte, kernel_code_gdt_flags, 0, 0xFFFFF};
+
+ // Kernel space data segment
+ access_byte kernel_data_access_byte{access_byte::PRESENT | access_byte::ACCESS_LEVEL_KERNEL |
+ access_byte::CODE_OR_DATA_SEGMENT,
+ type_field::WRITABLE};
+ gdt_flags kernel_data_gdt_flags{gdt_flags::GRANULARITY | gdt_flags::UPPER_BOUND};
+ segment_descriptor kernel_data_segment{kernel_data_access_byte, kernel_data_gdt_flags, 0, 0xFFFFF};
+
+ // User space code segment
+ access_byte user_code_access_byte{access_byte::PRESENT | access_byte::ACCESS_LEVEL_USER |
+ access_byte::CODE_OR_DATA_SEGMENT,
+ type_field::CODE_SEGMENT | type_field::READABLE};
+ gdt_flags user_code_gdt_flags{gdt_flags::GRANULARITY | gdt_flags::LENGTH};
+ segment_descriptor user_code_segment{user_code_access_byte, user_code_gdt_flags, 0, 0xFFFFF};
+
+ // User space data segment
+ access_byte user_data_access_byte{access_byte::PRESENT | access_byte::ACCESS_LEVEL_USER |
+ access_byte::CODE_OR_DATA_SEGMENT,
+ type_field::WRITABLE};
+ gdt_flags user_data_gdt_flags{gdt_flags::GRANULARITY | gdt_flags::UPPER_BOUND};
+ segment_descriptor user_data_segment{user_data_access_byte, user_data_gdt_flags, 0, 0xFFFFF};
+
+ stl::vector<segment_descriptor> global_descriptor_table{null_segment, kernel_code_segment, kernel_data_segment,
+ user_code_segment, user_data_segment};
+
+ decltype(auto) x = global_descriptor_table.at(1);
+ if (global_descriptor_table.size() == 0)
+ {
+ }
+ if (x.get_segment_type() == segment_descriptor_type::CODE_SEGMENT)
+ {
+ }
+ video::vga::text::write("GDT FILLED", video::vga::text::common_attributes::green_on_black);
}
} // namespace teachos::arch::kernel