aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/pre/src/kernel/main.cpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-12-15 17:13:12 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-12-15 17:13:12 +0100
commit7b9482ae637126ac9337876e60f519b493437711 (patch)
tree6fc71a253c8b0325d303bd34c95b564ba536ed14 /arch/x86_64/pre/src/kernel/main.cpp
parent116f9332a206767c45095950f09f7c7447b561cf (diff)
parenta9eeec745e29d89afd48ee43d09432eb6fc35be7 (diff)
downloadteachos-7b9482ae637126ac9337876e60f519b493437711.tar.xz
teachos-7b9482ae637126ac9337876e60f519b493437711.zip
os: rework kernel architecture
Rework the code structure and architecture of the kernel by separating platform-dependent and platform-independent code more cleanly. As of this patchset, full feature parity has not been achieved. Nonetheless, a sufficient subset of functionality has been ported to the new architecture to demonstrate the feasibility of the new structure.
Diffstat (limited to 'arch/x86_64/pre/src/kernel/main.cpp')
-rw-r--r--arch/x86_64/pre/src/kernel/main.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/arch/x86_64/pre/src/kernel/main.cpp b/arch/x86_64/pre/src/kernel/main.cpp
new file mode 100644
index 0000000..43b5f90
--- /dev/null
+++ b/arch/x86_64/pre/src/kernel/main.cpp
@@ -0,0 +1,71 @@
+#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;
+ }
+
+ 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();
+
+ auto address = memory::heap::global_heap_allocator::kmalloc(8U);
+ (void)address;
+
+ context_switching::switch_to_user_mode();
+ }
+} // namespace teachos::arch::kernel