diff options
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 50 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/boot.hpp (renamed from arch/x86_64/include/arch/boot/boot.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/boot32.S (renamed from arch/x86_64/src/boot/boot32.S) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/entry64.s (renamed from arch/x86_64/src/boot/entry64.s) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/initialize_runtime.cpp (renamed from arch/x86_64/src/boot/initialize_runtime.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/ld.hpp (renamed from arch/x86_64/include/arch/boot/ld.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/boot/multiboot.s (renamed from arch/x86_64/src/boot/multiboot.s) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/bus/isa.cpp (renamed from arch/x86_64/src/bus/isa.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/bus/isa.hpp (renamed from arch/x86_64/include/arch/bus/isa.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/control_register.hpp (renamed from arch/x86_64/include/arch/cpu/control_register.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/global_descriptor_table.hpp (renamed from arch/x86_64/include/arch/cpu/global_descriptor_table.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/initialization.cpp (renamed from arch/x86_64/src/cpu/initialization.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/initialization.hpp (renamed from arch/x86_64/include/arch/cpu/initialization.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/interrupts.S (renamed from arch/x86_64/src/cpu/interrupt_stubs.S) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/interrupts.cpp (renamed from arch/x86_64/src/cpu/interrupts.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/interrupts.hpp (renamed from arch/x86_64/include/arch/cpu/interrupts.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/legacy_pic.hpp (renamed from arch/x86_64/include/arch/cpu/legacy_pic.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/model_specific_register.hpp (renamed from arch/x86_64/include/arch/cpu/model_specific_register.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/registers.hpp (renamed from arch/x86_64/include/arch/cpu/registers.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/segment_descriptor.hpp (renamed from arch/x86_64/include/arch/cpu/segment_descriptor.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/segment_selector.hpp (renamed from arch/x86_64/include/arch/cpu/segment_selector.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/cpu/task_state_segment.hpp (renamed from arch/x86_64/include/arch/cpu/task_state_segment.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/debug/qemu_output.cpp (renamed from arch/x86_64/src/debug/qemu_output.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/debug/qemu_output.hpp (renamed from arch/x86_64/include/arch/debug/qemu_output.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/device_io/port_io.hpp (renamed from arch/x86_64/include/arch/device_io/port_io.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/init.cpp (renamed from arch/x86_64/src/devices/init.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/init.hpp (renamed from arch/x86_64/include/arch/devices/init.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/legacy_pit.cpp (renamed from arch/x86_64/src/devices/legacy_pit.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/legacy_pit.hpp (renamed from arch/x86_64/include/arch/devices/legacy_pit.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/local_apic.cpp (renamed from arch/x86_64/src/devices/local_apic.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/local_apic.hpp (renamed from arch/x86_64/include/arch/devices/local_apic.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/higher_half_mapper.cpp (renamed from arch/x86_64/src/memory/higher_half_mapper.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/higher_half_mapper.hpp (renamed from arch/x86_64/include/arch/memory/higher_half_mapper.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/kernel_mapper.cpp (renamed from arch/x86_64/src/memory/kernel_mapper.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/kernel_mapper.hpp (renamed from arch/x86_64/include/arch/memory/kernel_mapper.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/mmu.cpp (renamed from arch/x86_64/src/memory/mmu.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/mmu.hpp (renamed from arch/x86_64/include/arch/memory/mmu.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/page_table.cpp (renamed from arch/x86_64/src/memory/page_table.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/page_table.hpp (renamed from arch/x86_64/include/arch/memory/page_table.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/page_utilities.hpp (renamed from arch/x86_64/include/arch/memory/page_utilities.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/region_allocator.cpp (renamed from arch/x86_64/src/memory/region_allocator.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/memory/region_allocator.hpp (renamed from arch/x86_64/include/arch/memory/region_allocator.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/crtc.hpp (renamed from arch/x86_64/include/arch/vga/crtc.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text.hpp (renamed from arch/x86_64/include/arch/vga/text.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/attribute.hpp (renamed from arch/x86_64/include/arch/vga/text/attribute.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/buffer.cpp (renamed from arch/x86_64/src/vga/text/buffer.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/buffer.hpp (renamed from arch/x86_64/include/arch/vga/text/buffer.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/color.hpp (renamed from arch/x86_64/include/arch/vga/text/color.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/common_attributes.hpp (renamed from arch/x86_64/include/arch/vga/text/common_attributes.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/device.cpp (renamed from arch/x86_64/src/vga/text/device.cpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/device.hpp (renamed from arch/x86_64/include/arch/vga/text/device.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/arch/vga/text/flags.hpp (renamed from arch/x86_64/include/arch/vga/text/flags.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/context_switching/main.hpp | 51 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp | 91 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/context_switching/syscall/syscall_enable.hpp | 18 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/context_switching/syscall/syscall_handler.hpp | 18 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/kernel/halt.hpp | 13 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/kernel/main.hpp | 13 | ||||
| -rw-r--r-- | arch/x86_64/pre/include/arch/user/main.hpp | 16 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/context_switching/main.cpp | 66 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/context_switching/syscall/main.cpp | 35 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/context_switching/syscall/syscall_enable.cpp | 32 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/context_switching/syscall/syscall_handler.cpp | 121 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/kernel/main.cpp | 71 | ||||
| -rw-r--r-- | arch/x86_64/pre/src/user/main.cpp | 35 |
65 files changed, 30 insertions, 600 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 9e346ef..20a48f9 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -5,8 +5,16 @@ add_library("x86_64" OBJECT) add_library("arch::lib" ALIAS "x86_64") +target_include_directories("x86_64" PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}" +) + +target_link_libraries("x86_64" PUBLIC + "kapi::lib" + "multiboot2::lib" +) + target_sources("x86_64" PRIVATE - # Platform-dependent KAPI implementation "kapi/boot_modules.cpp" "kapi/cio.cpp" "kapi/cpu.cpp" @@ -14,39 +22,41 @@ target_sources("x86_64" PRIVATE "kapi/interrupts.cpp" "kapi/memory.cpp" "kapi/system.cpp" +) +target_sources("x86_64" PRIVATE # CPU Initialization - "src/cpu/initialization.cpp" - "src/cpu/interrupts.cpp" - "src/cpu/interrupt_stubs.S" + "arch/cpu/initialization.cpp" + "arch/cpu/interrupts.cpp" + "arch/cpu/interrupts.S" # Bus Initialization - "src/bus/isa.cpp" + "arch/bus/isa.cpp" # Low-level bootstrap - "src/boot/boot32.S" - "src/boot/entry64.s" - "src/boot/initialize_runtime.cpp" - "src/boot/multiboot.s" + "arch/boot/boot32.S" + "arch/boot/entry64.s" + "arch/boot/initialize_runtime.cpp" + "arch/boot/multiboot.s" # Debug interfaces - "src/debug/qemu_output.cpp" + "arch/debug/qemu_output.cpp" # Devices - "src/devices/init.cpp" - "src/devices/legacy_pit.cpp" - "src/devices/local_apic.cpp" + "arch/devices/init.cpp" + "arch/devices/legacy_pit.cpp" + "arch/devices/local_apic.cpp" # Memory management - "src/memory/kernel_mapper.cpp" - "src/memory/higher_half_mapper.cpp" - "src/memory/mmu.cpp" - "src/memory/page_table.cpp" - "src/memory/region_allocator.cpp" + "arch/memory/kernel_mapper.cpp" + "arch/memory/higher_half_mapper.cpp" + "arch/memory/mmu.cpp" + "arch/memory/page_table.cpp" + "arch/memory/region_allocator.cpp" # VGA text mode - "src/vga/text/buffer.cpp" - "src/vga/text/device.cpp" + "arch/vga/text/buffer.cpp" + "arch/vga/text/device.cpp" ) file(GLOB_RECURSE ARCH_HEADERS diff --git a/arch/x86_64/include/arch/boot/boot.hpp b/arch/x86_64/arch/boot/boot.hpp index 7df61c4..7df61c4 100644 --- a/arch/x86_64/include/arch/boot/boot.hpp +++ b/arch/x86_64/arch/boot/boot.hpp diff --git a/arch/x86_64/src/boot/boot32.S b/arch/x86_64/arch/boot/boot32.S index e6fcd85..e6fcd85 100644 --- a/arch/x86_64/src/boot/boot32.S +++ b/arch/x86_64/arch/boot/boot32.S diff --git a/arch/x86_64/src/boot/entry64.s b/arch/x86_64/arch/boot/entry64.s index 29fb778..29fb778 100644 --- a/arch/x86_64/src/boot/entry64.s +++ b/arch/x86_64/arch/boot/entry64.s diff --git a/arch/x86_64/src/boot/initialize_runtime.cpp b/arch/x86_64/arch/boot/initialize_runtime.cpp index b08c13c..b08c13c 100644 --- a/arch/x86_64/src/boot/initialize_runtime.cpp +++ b/arch/x86_64/arch/boot/initialize_runtime.cpp diff --git a/arch/x86_64/include/arch/boot/ld.hpp b/arch/x86_64/arch/boot/ld.hpp index 988723d..988723d 100644 --- a/arch/x86_64/include/arch/boot/ld.hpp +++ b/arch/x86_64/arch/boot/ld.hpp diff --git a/arch/x86_64/src/boot/multiboot.s b/arch/x86_64/arch/boot/multiboot.s index 37d8afe..37d8afe 100644 --- a/arch/x86_64/src/boot/multiboot.s +++ b/arch/x86_64/arch/boot/multiboot.s diff --git a/arch/x86_64/src/bus/isa.cpp b/arch/x86_64/arch/bus/isa.cpp index f6cc72d..f6cc72d 100644 --- a/arch/x86_64/src/bus/isa.cpp +++ b/arch/x86_64/arch/bus/isa.cpp diff --git a/arch/x86_64/include/arch/bus/isa.hpp b/arch/x86_64/arch/bus/isa.hpp index e56f56a..e56f56a 100644 --- a/arch/x86_64/include/arch/bus/isa.hpp +++ b/arch/x86_64/arch/bus/isa.hpp diff --git a/arch/x86_64/include/arch/cpu/control_register.hpp b/arch/x86_64/arch/cpu/control_register.hpp index 9cedc35..9cedc35 100644 --- a/arch/x86_64/include/arch/cpu/control_register.hpp +++ b/arch/x86_64/arch/cpu/control_register.hpp diff --git a/arch/x86_64/include/arch/cpu/global_descriptor_table.hpp b/arch/x86_64/arch/cpu/global_descriptor_table.hpp index b17c509..b17c509 100644 --- a/arch/x86_64/include/arch/cpu/global_descriptor_table.hpp +++ b/arch/x86_64/arch/cpu/global_descriptor_table.hpp diff --git a/arch/x86_64/src/cpu/initialization.cpp b/arch/x86_64/arch/cpu/initialization.cpp index 1be9c82..1be9c82 100644 --- a/arch/x86_64/src/cpu/initialization.cpp +++ b/arch/x86_64/arch/cpu/initialization.cpp diff --git a/arch/x86_64/include/arch/cpu/initialization.hpp b/arch/x86_64/arch/cpu/initialization.hpp index 564c544..564c544 100644 --- a/arch/x86_64/include/arch/cpu/initialization.hpp +++ b/arch/x86_64/arch/cpu/initialization.hpp diff --git a/arch/x86_64/src/cpu/interrupt_stubs.S b/arch/x86_64/arch/cpu/interrupts.S index e59bdd2..e59bdd2 100644 --- a/arch/x86_64/src/cpu/interrupt_stubs.S +++ b/arch/x86_64/arch/cpu/interrupts.S diff --git a/arch/x86_64/src/cpu/interrupts.cpp b/arch/x86_64/arch/cpu/interrupts.cpp index f40422f..f40422f 100644 --- a/arch/x86_64/src/cpu/interrupts.cpp +++ b/arch/x86_64/arch/cpu/interrupts.cpp diff --git a/arch/x86_64/include/arch/cpu/interrupts.hpp b/arch/x86_64/arch/cpu/interrupts.hpp index 6162f56..6162f56 100644 --- a/arch/x86_64/include/arch/cpu/interrupts.hpp +++ b/arch/x86_64/arch/cpu/interrupts.hpp diff --git a/arch/x86_64/include/arch/cpu/legacy_pic.hpp b/arch/x86_64/arch/cpu/legacy_pic.hpp index 56ca9c4..56ca9c4 100644 --- a/arch/x86_64/include/arch/cpu/legacy_pic.hpp +++ b/arch/x86_64/arch/cpu/legacy_pic.hpp diff --git a/arch/x86_64/include/arch/cpu/model_specific_register.hpp b/arch/x86_64/arch/cpu/model_specific_register.hpp index bd4aff9..bd4aff9 100644 --- a/arch/x86_64/include/arch/cpu/model_specific_register.hpp +++ b/arch/x86_64/arch/cpu/model_specific_register.hpp diff --git a/arch/x86_64/include/arch/cpu/registers.hpp b/arch/x86_64/arch/cpu/registers.hpp index 58633f6..58633f6 100644 --- a/arch/x86_64/include/arch/cpu/registers.hpp +++ b/arch/x86_64/arch/cpu/registers.hpp diff --git a/arch/x86_64/include/arch/cpu/segment_descriptor.hpp b/arch/x86_64/arch/cpu/segment_descriptor.hpp index 9570670..9570670 100644 --- a/arch/x86_64/include/arch/cpu/segment_descriptor.hpp +++ b/arch/x86_64/arch/cpu/segment_descriptor.hpp diff --git a/arch/x86_64/include/arch/cpu/segment_selector.hpp b/arch/x86_64/arch/cpu/segment_selector.hpp index 1a78c47..1a78c47 100644 --- a/arch/x86_64/include/arch/cpu/segment_selector.hpp +++ b/arch/x86_64/arch/cpu/segment_selector.hpp diff --git a/arch/x86_64/include/arch/cpu/task_state_segment.hpp b/arch/x86_64/arch/cpu/task_state_segment.hpp index 57729dd..57729dd 100644 --- a/arch/x86_64/include/arch/cpu/task_state_segment.hpp +++ b/arch/x86_64/arch/cpu/task_state_segment.hpp diff --git a/arch/x86_64/src/debug/qemu_output.cpp b/arch/x86_64/arch/debug/qemu_output.cpp index 71acede..71acede 100644 --- a/arch/x86_64/src/debug/qemu_output.cpp +++ b/arch/x86_64/arch/debug/qemu_output.cpp diff --git a/arch/x86_64/include/arch/debug/qemu_output.hpp b/arch/x86_64/arch/debug/qemu_output.hpp index 5ddd4be..5ddd4be 100644 --- a/arch/x86_64/include/arch/debug/qemu_output.hpp +++ b/arch/x86_64/arch/debug/qemu_output.hpp diff --git a/arch/x86_64/include/arch/device_io/port_io.hpp b/arch/x86_64/arch/device_io/port_io.hpp index 4c8d66a..4c8d66a 100644 --- a/arch/x86_64/include/arch/device_io/port_io.hpp +++ b/arch/x86_64/arch/device_io/port_io.hpp diff --git a/arch/x86_64/src/devices/init.cpp b/arch/x86_64/arch/devices/init.cpp index c30e8cf..c30e8cf 100644 --- a/arch/x86_64/src/devices/init.cpp +++ b/arch/x86_64/arch/devices/init.cpp diff --git a/arch/x86_64/include/arch/devices/init.hpp b/arch/x86_64/arch/devices/init.hpp index c5fbf37..c5fbf37 100644 --- a/arch/x86_64/include/arch/devices/init.hpp +++ b/arch/x86_64/arch/devices/init.hpp diff --git a/arch/x86_64/src/devices/legacy_pit.cpp b/arch/x86_64/arch/devices/legacy_pit.cpp index d542d47..d542d47 100644 --- a/arch/x86_64/src/devices/legacy_pit.cpp +++ b/arch/x86_64/arch/devices/legacy_pit.cpp diff --git a/arch/x86_64/include/arch/devices/legacy_pit.hpp b/arch/x86_64/arch/devices/legacy_pit.hpp index 356895c..356895c 100644 --- a/arch/x86_64/include/arch/devices/legacy_pit.hpp +++ b/arch/x86_64/arch/devices/legacy_pit.hpp diff --git a/arch/x86_64/src/devices/local_apic.cpp b/arch/x86_64/arch/devices/local_apic.cpp index 660921b..660921b 100644 --- a/arch/x86_64/src/devices/local_apic.cpp +++ b/arch/x86_64/arch/devices/local_apic.cpp diff --git a/arch/x86_64/include/arch/devices/local_apic.hpp b/arch/x86_64/arch/devices/local_apic.hpp index f8f080d..f8f080d 100644 --- a/arch/x86_64/include/arch/devices/local_apic.hpp +++ b/arch/x86_64/arch/devices/local_apic.hpp diff --git a/arch/x86_64/src/memory/higher_half_mapper.cpp b/arch/x86_64/arch/memory/higher_half_mapper.cpp index 75adb3c..75adb3c 100644 --- a/arch/x86_64/src/memory/higher_half_mapper.cpp +++ b/arch/x86_64/arch/memory/higher_half_mapper.cpp diff --git a/arch/x86_64/include/arch/memory/higher_half_mapper.hpp b/arch/x86_64/arch/memory/higher_half_mapper.hpp index 9b02ee6..9b02ee6 100644 --- a/arch/x86_64/include/arch/memory/higher_half_mapper.hpp +++ b/arch/x86_64/arch/memory/higher_half_mapper.hpp diff --git a/arch/x86_64/src/memory/kernel_mapper.cpp b/arch/x86_64/arch/memory/kernel_mapper.cpp index 74272a0..74272a0 100644 --- a/arch/x86_64/src/memory/kernel_mapper.cpp +++ b/arch/x86_64/arch/memory/kernel_mapper.cpp diff --git a/arch/x86_64/include/arch/memory/kernel_mapper.hpp b/arch/x86_64/arch/memory/kernel_mapper.hpp index adbf688..adbf688 100644 --- a/arch/x86_64/include/arch/memory/kernel_mapper.hpp +++ b/arch/x86_64/arch/memory/kernel_mapper.hpp diff --git a/arch/x86_64/src/memory/mmu.cpp b/arch/x86_64/arch/memory/mmu.cpp index 2b53fa4..2b53fa4 100644 --- a/arch/x86_64/src/memory/mmu.cpp +++ b/arch/x86_64/arch/memory/mmu.cpp diff --git a/arch/x86_64/include/arch/memory/mmu.hpp b/arch/x86_64/arch/memory/mmu.hpp index 64373f4..64373f4 100644 --- a/arch/x86_64/include/arch/memory/mmu.hpp +++ b/arch/x86_64/arch/memory/mmu.hpp diff --git a/arch/x86_64/src/memory/page_table.cpp b/arch/x86_64/arch/memory/page_table.cpp index 2180420..2180420 100644 --- a/arch/x86_64/src/memory/page_table.cpp +++ b/arch/x86_64/arch/memory/page_table.cpp diff --git a/arch/x86_64/include/arch/memory/page_table.hpp b/arch/x86_64/arch/memory/page_table.hpp index ce3d3a1..ce3d3a1 100644 --- a/arch/x86_64/include/arch/memory/page_table.hpp +++ b/arch/x86_64/arch/memory/page_table.hpp diff --git a/arch/x86_64/include/arch/memory/page_utilities.hpp b/arch/x86_64/arch/memory/page_utilities.hpp index 068e824..068e824 100644 --- a/arch/x86_64/include/arch/memory/page_utilities.hpp +++ b/arch/x86_64/arch/memory/page_utilities.hpp diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/arch/memory/region_allocator.cpp index 4086a10..4086a10 100644 --- a/arch/x86_64/src/memory/region_allocator.cpp +++ b/arch/x86_64/arch/memory/region_allocator.cpp diff --git a/arch/x86_64/include/arch/memory/region_allocator.hpp b/arch/x86_64/arch/memory/region_allocator.hpp index 5d9da2e..5d9da2e 100644 --- a/arch/x86_64/include/arch/memory/region_allocator.hpp +++ b/arch/x86_64/arch/memory/region_allocator.hpp diff --git a/arch/x86_64/include/arch/vga/crtc.hpp b/arch/x86_64/arch/vga/crtc.hpp index a8bec93..a8bec93 100644 --- a/arch/x86_64/include/arch/vga/crtc.hpp +++ b/arch/x86_64/arch/vga/crtc.hpp diff --git a/arch/x86_64/include/arch/vga/text.hpp b/arch/x86_64/arch/vga/text.hpp index 2e73dd2..2e73dd2 100644 --- a/arch/x86_64/include/arch/vga/text.hpp +++ b/arch/x86_64/arch/vga/text.hpp diff --git a/arch/x86_64/include/arch/vga/text/attribute.hpp b/arch/x86_64/arch/vga/text/attribute.hpp index 6395aed..6395aed 100644 --- a/arch/x86_64/include/arch/vga/text/attribute.hpp +++ b/arch/x86_64/arch/vga/text/attribute.hpp diff --git a/arch/x86_64/src/vga/text/buffer.cpp b/arch/x86_64/arch/vga/text/buffer.cpp index 498b9a3..498b9a3 100644 --- a/arch/x86_64/src/vga/text/buffer.cpp +++ b/arch/x86_64/arch/vga/text/buffer.cpp diff --git a/arch/x86_64/include/arch/vga/text/buffer.hpp b/arch/x86_64/arch/vga/text/buffer.hpp index 8eb6645..8eb6645 100644 --- a/arch/x86_64/include/arch/vga/text/buffer.hpp +++ b/arch/x86_64/arch/vga/text/buffer.hpp diff --git a/arch/x86_64/include/arch/vga/text/color.hpp b/arch/x86_64/arch/vga/text/color.hpp index e0ad6df..e0ad6df 100644 --- a/arch/x86_64/include/arch/vga/text/color.hpp +++ b/arch/x86_64/arch/vga/text/color.hpp diff --git a/arch/x86_64/include/arch/vga/text/common_attributes.hpp b/arch/x86_64/arch/vga/text/common_attributes.hpp index 3d8929f..3d8929f 100644 --- a/arch/x86_64/include/arch/vga/text/common_attributes.hpp +++ b/arch/x86_64/arch/vga/text/common_attributes.hpp diff --git a/arch/x86_64/src/vga/text/device.cpp b/arch/x86_64/arch/vga/text/device.cpp index 8468358..8468358 100644 --- a/arch/x86_64/src/vga/text/device.cpp +++ b/arch/x86_64/arch/vga/text/device.cpp diff --git a/arch/x86_64/include/arch/vga/text/device.hpp b/arch/x86_64/arch/vga/text/device.hpp index 0a0e017..0a0e017 100644 --- a/arch/x86_64/include/arch/vga/text/device.hpp +++ b/arch/x86_64/arch/vga/text/device.hpp diff --git a/arch/x86_64/include/arch/vga/text/flags.hpp b/arch/x86_64/arch/vga/text/flags.hpp index 7a29e33..7a29e33 100644 --- a/arch/x86_64/include/arch/vga/text/flags.hpp +++ b/arch/x86_64/arch/vga/text/flags.hpp diff --git a/arch/x86_64/pre/include/arch/context_switching/main.hpp b/arch/x86_64/pre/include/arch/context_switching/main.hpp deleted file mode 100644 index 07e00e8..0000000 --- a/arch/x86_64/pre/include/arch/context_switching/main.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_MAIN_HPP -#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_MAIN_HPP - -#include <arch/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.hpp> -#include <arch/context_switching/segment_descriptor_table/global_descriptor_table.hpp> - -namespace teachos::arch::context_switching -{ - /** - * @brief Contains the references to the tables required for context switching - */ - struct descriptor_tables - { - segment_descriptor_table::global_descriptor_table & gdt; ///< Reference to the global descriptor table. - interrupt_descriptor_table::interrupt_descriptor_table & idt; ///< Reference to the interrupt descriptor table. - }; - - /** - * @brief Creates the Interrupt Descriptor Table and Global Descriptor Table as a static variable the first time this - * method is called and update IDTR and GDTR registers values. - * - * @note Subsequent calls after the first one, will simply return the previously created tables, but not update the - * registers again. - * - * @return References to the statically created Interrupt Descriptor and Global Descriptor Table. - */ - auto initialize_descriptor_tables() -> descriptor_tables; - - /** - * @brief Switches from the current Kernel Mode (Level 0) to User Mode (Level 3). Will simply use predefined Segment - * Selectors for the User Data and User Code Segment, which are Index 3 and 4 in the GDT respectively. - */ - auto switch_to_user_mode() -> void; - - /** - * @brief Switches from the current Code and Data Segment to the given Code and Data Segment. - * - * @note This method will additionally call initialize_descriptor_tables, to ensure the GDTR and IDTR have been setup - * correctly before attempting to switch the context. This switch is achieved using a far return, which will once - * executed call the given void function. - * - * @param data_segment Data Segment that the SS, DS; ES, FS and GS register will be set too. - * @param code_segment Code Segment that the CS register will be set too. - * @param return_function Function that will be called once the switch has been achieved. - */ - auto switch_context(interrupt_descriptor_table::segment_selector data_segment, - interrupt_descriptor_table::segment_selector code_segment, void (*return_function)()) -> void; - -} // namespace teachos::arch::context_switching - -#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_MAIN_HPP diff --git a/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp b/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp deleted file mode 100644 index f507c61..0000000 --- a/arch/x86_64/pre/include/arch/context_switching/syscall/main.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_MAIN_HPP -#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_MAIN_HPP - -#include <cstdint> - -namespace teachos::arch::context_switching::syscall -{ - /** - * @brief Possible syscall implementation that should actually be called. - * - * @note Attempts to reflect the Linux interface partially. See https://filippo.io/linux-syscall-table/ for more - * information. - */ - enum class type : uint64_t - { - WRITE = 1U, ///< Loads the arg_0 parameter as an address pointing to a const char array, which will then be printed - ///< onto the VGA buffer screen. - EXPAND_HEAP = 2U, /// Expands the User Heap by additonally mapping 100 KiB of virtual page memory. Ignores the - /// parameters and uses them as out parameters instead, where arg_0 is the start of the newly - /// mapped heap area and arg_1 is the size of the entire area. Can be less than 100 KiB if less - /// space remains. - ASSERT = 3U, /// Loads the arg_0 parameter as a boolean which needs to be true or it will print the message in - /// arg_1 parameter onto the VGA buffer screen, keep it as a nullptr if it shouldn't print anything - /// and then it halts the further execution of the application. - }; - - /** - * @brief Possible error codes that can be returned by the different syscall methods called depending on the type - * enum. - */ - enum class error : uint8_t - { - OK = 0U, ///< No error occured in syscall. - OUT_OF_MEMORY = 1U, ///< Expanding heap failed because we have run out of mappable virtual address space. - }; - - /** - * @brief Allows to convert the error enum type into a boolean directly. Where any code besides 0 being no error, will - * return true. The remaining errors return true. - * - * @param e Error code that was returned by the syscall. - * @return Return true if there was no error and false otherwise. - */ - constexpr bool operator!(error e) - { - return e == error::OK; - } - - /** - * @brief Maximum amount of arguments that can be passed to a syscall. Default value is 0 and arguments are only ever - * used depending on the actual enum type and if the method requires thoose parameters. - */ - struct arguments - { - uint64_t arg_0{}; ///< First optional paramter to the syscall representing the RDI register. - uint64_t arg_1{}; ///< Second optional paramter to the syscall representing the RSI register. - uint64_t arg_2{}; ///< Third optional paramter to the syscall representing the RDX register. - uint64_t arg_3{}; ///< Fourth optional paramter to the syscall representing the R10 register. - uint64_t arg_4{}; ///< Fifth optional paramter to the syscall representing the R8 register. - uint64_t arg_5{}; ///< Sixth optional paramter to the syscall representing the R9 register. - }; - - /** - * @brief Response of a systemcall always containin an error code, signaling if the syscall even succeeded or not. - * Additionally it may contain up to 6 return values in the values struct. - */ - struct response - { - error error_code; ///< Error code returned by the syscall. If it failed all the values will be 0. - arguments values = {}; ///< Optional return values of the syscall implementation. - }; - - /** - * @brief Calls the method associated with the given syscall number and passes the given optional arguments to it, - * over the RDI, RSI, RDX, R10, R8 and R9 register. - * - * @param syscall_number Syscall method that should be called. See enum values in type for possible implemented - * methods. - * @param args Optional arguments passable to the different syscall methods, called depending on the syscall_number. - * Not passing the required parameters to the method, will result in passing 0 instead, which might make the fail or - * not function correctly. - * @return The syscall implementation always returns a bool-convertable error code converting to true if the syscall - * failed or false if it didn't. Additionally it might pase additional values besides the error code, they will be set - * in the arguments struct. So the value can be read and used for further processing. - */ - [[gnu::section(".user_text")]] - auto syscall(type syscall_number, arguments args = {}) -> response; - -} // namespace teachos::arch::context_switching::syscall - -#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_MAIN_HPP diff --git a/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_enable.hpp b/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_enable.hpp deleted file mode 100644 index 8cb468a..0000000 --- a/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_enable.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_ENABLE_HPP -#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_ENABLE_HPP - -namespace teachos::arch::context_switching::syscall -{ - /** - * @brief Enables and sets up internal CPU registers to allow for syscall to function correctly and switch context - * temporarily back to the kernel level. - * - * @note Configures the Model Specific Register required by syscall (LSTAR, FMASK, STAR) with the correct values so - * that the syscall_handler is called and sets the System Call Extension bit on the EFER flags to allow for syscall - * to be used. - */ - auto enable_syscall() -> void; - -} // namespace teachos::arch::context_switching::syscall - -#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_ENABLE_HPP diff --git a/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_handler.hpp b/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_handler.hpp deleted file mode 100644 index 2e7bcd1..0000000 --- a/arch/x86_64/pre/include/arch/context_switching/syscall/syscall_handler.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_HANDLER_HPP -#define TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_HANDLER_HPP - -#include <cstdint> - -namespace teachos::arch::context_switching::syscall -{ - /** - * @brief Handler for SYSCALL instruction. Calls a specific implementation based - * on the register RAX. - * - * @return Returns with LEAVE, SYSRETQ - */ - auto syscall_handler() -> void; - -} // namespace teachos::arch::context_switching::syscall - -#endif // TEACHOS_ARCH_X86_64_CONTEXT_SWITCHING_SYSCALL_SYSCALL_HANDLER_HPP diff --git a/arch/x86_64/pre/include/arch/kernel/halt.hpp b/arch/x86_64/pre/include/arch/kernel/halt.hpp deleted file mode 100644 index 377acc0..0000000 --- a/arch/x86_64/pre/include/arch/kernel/halt.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_KERNEL_HALT_HPP -#define TEACHOS_ARCH_X86_64_KERNEL_HALT_HPP - -namespace teachos::arch::kernel -{ - /** - * @brief Halts the kernel execution, meaning any code after a call to this will not run anymore. - */ - extern "C" [[noreturn]] auto halt() -> void; - -} // namespace teachos::arch::kernel - -#endif // TEACHOS_ARCH_X86_64_KERNEL_HALT_HPP diff --git a/arch/x86_64/pre/include/arch/kernel/main.hpp b/arch/x86_64/pre/include/arch/kernel/main.hpp deleted file mode 100644 index a13e5f4..0000000 --- a/arch/x86_64/pre/include/arch/kernel/main.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP -#define TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP - -namespace teachos::arch::kernel -{ - /** - * @brief Initalizes the kernel system. - */ - auto main() -> void; - -} // namespace teachos::arch::kernel - -#endif // TEACHOS_ARCH_X86_64_KERNEL_MAIN_HPP diff --git a/arch/x86_64/pre/include/arch/user/main.hpp b/arch/x86_64/pre/include/arch/user/main.hpp deleted file mode 100644 index c168a1f..0000000 --- a/arch/x86_64/pre/include/arch/user/main.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_USER_MAIN_HPP -#define TEACHOS_ARCH_X86_64_USER_MAIN_HPP - -namespace teachos::arch::user -{ - /** - * @brief User Main method. If this method finishes there is no code left to run and the whole OS will shut down. - * Additionally this main method is executed at Ring 3 and accessing CPU Registers or Kernel level functionality can - * only be done over syscalls and not directly anymore. - */ - [[gnu::section(".user_text")]] - auto main() -> void; - -} // namespace teachos::arch::user - -#endif // TEACHOS_ARCH_X86_64_USER_MAIN_HPP diff --git a/arch/x86_64/pre/src/context_switching/main.cpp b/arch/x86_64/pre/src/context_switching/main.cpp deleted file mode 100644 index 0961499..0000000 --- a/arch/x86_64/pre/src/context_switching/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include <arch/context_switching/main.hpp> - -#include <arch/boot/pointers.hpp> -#include <arch/context_switching/syscall/syscall_enable.hpp> -#include <arch/kernel/cpu/call.hpp> -#include <arch/kernel/cpu/if.hpp> -#include <arch/kernel/cpu/segment_register.hpp> -#include <arch/kernel/cpu/tr.hpp> -#include <arch/user/main.hpp> - -namespace teachos::arch::context_switching -{ - namespace - { - constexpr interrupt_descriptor_table::segment_selector KERNEL_CODE_SEGMENT_SELECTOR{ - 1U, interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_KERNEL}; - constexpr kernel::cpu::far_pointer KERNEL_CODE_POINTER{&kernel::cpu::reload_data_segment_registers, - KERNEL_CODE_SEGMENT_SELECTOR}; - constexpr context_switching::interrupt_descriptor_table::segment_selector USER_CODE_SEGMENT_SELECTOR{ - 3U, context_switching::interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_USER}; - constexpr context_switching::interrupt_descriptor_table::segment_selector USER_DATA_SEGMENT_SELECTOR{ - 4U, context_switching::interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_USER}; - - auto reload_gdtr() -> void - { - kernel::cpu::call(KERNEL_CODE_POINTER); - } - } // namespace - - auto initialize_descriptor_tables() -> descriptor_tables - { - bool static initalized = false; - - if (!initalized) - { - kernel::cpu::clear_interrupt_flag(); - - segment_descriptor_table::update_gdtr(); - interrupt_descriptor_table::update_interrupt_descriptor_table_register(); - - reload_gdtr(); - segment_descriptor_table::update_tss_register(); - - kernel::cpu::set_interrupt_flag(); - initalized = true; - } - - descriptor_tables tables = {segment_descriptor_table::get_or_create_gdt(), - interrupt_descriptor_table::get_or_create_interrupt_descriptor_table()}; - return tables; - } - - auto switch_to_user_mode() -> void - { - syscall::enable_syscall(); - switch_context(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR, user::main); - } - - auto switch_context(interrupt_descriptor_table::segment_selector data_segment, - interrupt_descriptor_table::segment_selector code_segment, void (*return_function)()) -> void - { - (void)initialize_descriptor_tables(); - kernel::cpu::set_data_segment_registers(data_segment); - kernel::cpu::set_code_segment_register(data_segment, code_segment, reinterpret_cast<uint64_t>(return_function)); - } -} // namespace teachos::arch::context_switching diff --git a/arch/x86_64/pre/src/context_switching/syscall/main.cpp b/arch/x86_64/pre/src/context_switching/syscall/main.cpp deleted file mode 100644 index 10bd087..0000000 --- a/arch/x86_64/pre/src/context_switching/syscall/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include <arch/context_switching/syscall/main.hpp> - -namespace teachos::arch::context_switching::syscall -{ - auto syscall(type syscall_number, arguments args) -> response - { - asm volatile("mov %[input], %%rax" - : /* no output from call */ - : [input] "m"(syscall_number) - : "memory"); - - asm volatile("mov %[input], %%rdi " : /* no output from call */ : [input] "m"(args.arg_0) : "memory"); - asm volatile("mov %[input], %%rsi" : /* no output from call */ : [input] "m"(args.arg_1) : "memory"); - asm volatile("mov %[input], %%rdx" : /* no output from call */ : [input] "m"(args.arg_2) : "memory"); - asm volatile("mov %[input], %%r10" : /* no output from call */ : [input] "m"(args.arg_3) : "memory"); - asm volatile("mov %[input], %%r8" : /* no output from call */ : [input] "m"(args.arg_4) : "memory"); - asm volatile("mov %[input], %%r9" : /* no output from call */ : [input] "m"(args.arg_5) : "memory"); - - asm volatile("syscall"); - - arguments values{}; - asm volatile("mov %%rdi, %[output]" : [output] "=m"(values.arg_0)); - asm volatile("mov %%rsi, %[output]" : [output] "=m"(values.arg_1)); - asm volatile("mov %%rdx, %[output]" : [output] "=m"(values.arg_2)); - asm volatile("mov %%r10, %[output]" : [output] "=m"(values.arg_3)); - asm volatile("mov %%r8, %[output]" : [output] "=m"(values.arg_4)); - asm volatile("mov %%r9, %[output]" : [output] "=m"(values.arg_5)); - - error error_code{}; - asm volatile("mov %%al, %[output]" : [output] "=m"(error_code)); - - return {error_code, values}; - } - -} // namespace teachos::arch::context_switching::syscall diff --git a/arch/x86_64/pre/src/context_switching/syscall/syscall_enable.cpp b/arch/x86_64/pre/src/context_switching/syscall/syscall_enable.cpp deleted file mode 100644 index f9f070a..0000000 --- a/arch/x86_64/pre/src/context_switching/syscall/syscall_enable.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include <arch/context_switching/syscall/syscall_enable.hpp> - -#include <arch/context_switching/interrupt_descriptor_table/segment_selector.hpp> -#include <arch/context_switching/syscall/syscall_handler.hpp> -#include <arch/kernel/cpu/msr.hpp> - -namespace teachos::arch::context_switching::syscall -{ - namespace - { - constexpr interrupt_descriptor_table::segment_selector KERNEL_CODE_SEGMENT_SELECTOR{ - 1U, interrupt_descriptor_table::segment_selector::REQUEST_LEVEL_KERNEL}; - - constexpr auto IA32_STAR_ADDRESS = 0xC000'0081; - constexpr auto IA32_LSTAR_ADDRESS = 0xC000'0082; - constexpr auto IA32_FMASK_ADDRESS = 0xC000'0084; - - } // namespace - - auto enable_syscall() -> void - { - uint64_t const syscall_function = reinterpret_cast<uint64_t>(syscall_handler); - kernel::cpu::write_msr(IA32_LSTAR_ADDRESS, syscall_function); - kernel::cpu::write_msr(IA32_FMASK_ADDRESS, 0U); - - uint64_t const kernel_cs = KERNEL_CODE_SEGMENT_SELECTOR; - uint64_t const star_value = (kernel_cs << 32) | (kernel_cs << 48); - kernel::cpu::write_msr(IA32_STAR_ADDRESS, star_value); - - kernel::cpu::set_efer_bit(kernel::cpu::efer_flags::SCE); - } -} // namespace teachos::arch::context_switching::syscall diff --git a/arch/x86_64/pre/src/context_switching/syscall/syscall_handler.cpp b/arch/x86_64/pre/src/context_switching/syscall/syscall_handler.cpp deleted file mode 100644 index 430d65c..0000000 --- a/arch/x86_64/pre/src/context_switching/syscall/syscall_handler.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include <arch/context_switching/syscall/syscall_handler.hpp> - -#include <arch/context_switching/syscall/main.hpp> -#include <arch/exception_handling/assert.hpp> -#include <arch/exception_handling/panic.hpp> -#include <arch/memory/heap/global_heap_allocator.hpp> -#include <arch/memory/main.hpp> -#include <arch/video/vga/text.hpp> - -namespace teachos::arch::context_switching::syscall -{ - - namespace - { - auto write_to_vga_buffer(uint64_t buffer) -> response - { - video::vga::text::write(reinterpret_cast<char const *>(buffer), - video::vga::text::common_attributes::green_on_black); - video::vga::text::newline(); - return {error::OK}; - } - - auto expand_user_heap() -> response - { - auto static current_heap_end = memory::heap::USER_HEAP_START; - uint64_t const heap_start = current_heap_end; - memory::remap_heap(heap_start, memory::heap::USER_HEAP_SIZE, memory::paging::entry::USER_ACCESSIBLE); - current_heap_end += memory::heap::USER_HEAP_SIZE; - return { - error::OK, - {heap_start, memory::heap::USER_HEAP_SIZE} - }; - } - } // namespace - - auto syscall_handler() -> void - { - // Saving state of rcx and r11 because it is required by sysretq to function. - // Calls to other functions potentially overwrite these registers, because of - // callee saved calling convention. - uint64_t return_instruction_pointer, rflags = {}; - asm volatile("mov %%rcx, %[output]" : [output] "=m"(return_instruction_pointer)); - asm volatile("mov %%r11, %[output]" : [output] "=m"(rflags)); - - uint64_t syscall_number, arg_0, arg_1, arg_2, arg_3, arg_4, arg_5 = {}; - asm volatile("mov %%rdi, %[output]" : [output] "=m"(arg_0)); - asm volatile("mov %%rsi, %[output]" : [output] "=m"(arg_1)); - asm volatile("mov %%rdx, %[output]" : [output] "=m"(arg_2)); - asm volatile("mov %%r10, %[output]" : [output] "=m"(arg_3)); - asm volatile("mov %%r8, %[output]" : [output] "=m"(arg_4)); - asm volatile("mov %%r9, %[output]" : [output] "=m"(arg_5)); - - // RAX is read last, because paired with our type enum, we can use it to check - // if the register has been written by the compiled code between executing the syscall - // and now. - asm volatile("mov %%rax, %[output]" : [output] "=m"(syscall_number)); - - response result; - switch (static_cast<type>(syscall_number)) - { - case type::WRITE: - result = write_to_vga_buffer(arg_0); - break; - case type::EXPAND_HEAP: - result = expand_user_heap(); - break; - case type::ASSERT: - teachos::arch::exception_handling::assert(arg_0, reinterpret_cast<char const *>(arg_1)); - break; - default: - teachos::arch::exception_handling::panic("[Syscall Handler] Invalid syscall number"); - break; - } - - asm volatile("mov %[input], %%rax" - : /* no output from call */ - : [input] "m"(result.error_code) - : "memory"); - - asm volatile("mov %[input], %%rdi" - : /* no output from call */ - : [input] "m"(result.values.arg_0) - : "memory"); - asm volatile("mov %[input], %%rsi" - : /* no output from call */ - : [input] "m"(result.values.arg_1) - : "memory"); - asm volatile("mov %[input], %%rdx" - : /* no output from call */ - : [input] "m"(result.values.arg_2) - : "memory"); - asm volatile("mov %[input], %%r10" - : /* no output from call */ - : [input] "m"(result.values.arg_3) - : "memory"); - asm volatile("mov %[input], %%r8" - : /* no output from call */ - : [input] "m"(result.values.arg_4) - : "memory"); - asm volatile("mov %[input], %%r9" - : /* no output from call */ - : [input] "m"(result.values.arg_5) - : "memory"); - - asm volatile("mov %[input], %%rcx" - : /* no output from call */ - : [input] "m"(return_instruction_pointer) - : "memory"); - asm volatile("mov %[input], %%r11" - : /* no output from call */ - : [input] "m"(rflags) - : "memory"); - - // Additionally call leave, because x86 allocates stack space for the internal variables. If we do not clean up this - // newly created stack frame the syscall instruction that landed in this syscall_handler, will never return to the - // method that originally called it, because the RIP has not been restored from the previous stack frame. - asm volatile("leave\n" - "sysretq"); - } - -} // namespace teachos::arch::context_switching::syscall diff --git a/arch/x86_64/pre/src/kernel/main.cpp b/arch/x86_64/pre/src/kernel/main.cpp deleted file mode 100644 index 2658678..0000000 --- a/arch/x86_64/pre/src/kernel/main.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#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 diff --git a/arch/x86_64/pre/src/user/main.cpp b/arch/x86_64/pre/src/user/main.cpp deleted file mode 100644 index 10a17db..0000000 --- a/arch/x86_64/pre/src/user/main.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include <arch/user/main.hpp> - -#include <arch/context_switching/syscall/main.hpp> -#include <arch/memory/heap/global_heap_allocator.hpp> - -#include <algorithm> -#include <array> -#include <atomic> -#include <ranges> - -namespace teachos::arch::user -{ - auto main() -> void - { - constexpr char syscall_message[] = "Successfully entered user mode and wrote to VGA buffer via syscall!"; - context_switching::syscall::syscall(context_switching::syscall::type::WRITE, - {reinterpret_cast<uint64_t>(&syscall_message)}); - - // Test C++ standard library - std::array<std::atomic<uint8_t>, 4> array_test = {std::atomic<uint8_t>{5}, std::atomic<uint8_t>{10}, - std::atomic<uint8_t>{15}, std::atomic<uint8_t>{20}}; - std::ranges::for_each(array_test, [](auto & item) { - auto value = item.load(); - uint8_t max_value = std::max(value, uint8_t{10}); - item.exchange(max_value + 2); - }); - - auto address = new uint64_t{10U}; - (void)address; - - for (;;) - { - } - } -} // namespace teachos::arch::user |
