#include "arch/kernel/main.hpp" #include "arch/boot/pointers.hpp" #include "arch/context_switching/interrupt_descriptor_table/segment_selector.hpp" #include "arch/context_switching/main.hpp" #include "arch/kernel/cpu/if.hpp" #include "arch/kernel/cpu/segment_register.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 { auto stack_overflow_test(int count) -> int { int test[5000] = {}; if (test[0] == 0xFFFF) { return count; } count = stack_overflow_test(count); return count++; } auto heap_test() -> void { auto test2 = new memory::multiboot::memory_information{}; auto test3 = new memory::multiboot::memory_information{}; auto test4 = *test2; auto test5 = *test3; test4.kernel_end = 5000; test5.kernel_end = 3000; auto test6 = test4.kernel_end; auto test7 = test5.kernel_end; auto test8 = memory::multiboot::read_multiboot2(); if (test6 && test7 && test8.kernel_end) { video::vga::text::write("Heap test successful", video::vga::text::common_attributes::green_on_black); } test2->kernel_end = 2000; test2->kernel_start = 1000; test2->multiboot_start = 2000; delete test2; delete test3; auto test9 = new int(50); delete test9; } [[gnu::naked]] auto push_code_segment(context_switching::interrupt_descriptor_table::segment_selector segment_selector_a, context_switching::interrupt_descriptor_table::segment_selector segment_selector_b) -> void { asm volatile("push %%rbp\n" "push %[input]" : /* No output from call */ : [input] "m"(segment_selector_a)); asm volatile("mov %[input], %%ax\n" "mov %%ax, %%ss\n" "mov %%ax, %%ds\n" "mov %%ax, %%es\n" "mov %%ax, %%fs\n" "mov %%ax, %%gs" : /* No output from call */ : [input] "m"(segment_selector_b)); asm volatile("iretq" : /* No output from call */ : /* No input to call */); } [[gnu::naked]] auto iret() -> void { asm volatile("iretq" : /* No output from call */ : /* No input to call */); } auto main() -> void { video::vga::text::clear(); video::vga::text::cursor(false); video::vga::text::write("TeachOS is starting up...", video::vga::text::common_attributes::green_on_black); video::vga::text::newline(); memory::initialize_memory_management(); // stack_overflow_test(0); memory::heap::global_heap_allocator::register_heap_allocator(memory::heap::heap_allocator_type::LINKED_LIST); heap_test(); decltype(auto) descriptor_tables = context_switching::initialize_descriptor_tables(); // - Clear NT flag in EFLAGS register (for far return) // - Push return instruction pointer // - Push return code segment selector // context_switching::interrupt_descriptor_table::segment_selector user_code_segment_selector{ // 3U, context_switching::interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_USER}; // context_switching::interrupt_descriptor_table::segment_selector user_data_segment_selector{ // 4U, context_switching::interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_USER}; // push_code_segment(user_code_segment_selector, user_data_segment_selector); boot::context_switch(); (void)descriptor_tables; } } // namespace teachos::arch::kernel