diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | kernel/include/kernel/cpu.hpp | 14 | ||||
| -rw-r--r-- | kernel/kapi/cpu.cpp | 30 | ||||
| -rw-r--r-- | kernel/src/cpu.cpp | 46 | ||||
| -rw-r--r-- | kernel/src/main.cpp | 5 |
5 files changed, 97 insertions, 0 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 398022c..d9a5c75 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -2,6 +2,7 @@ add_executable("kernel" # Platform-independent KAPI implementation "kapi/boot_modules.cpp" "kapi/cio.cpp" + "kapi/cpu.cpp" "kapi/memory.cpp" "kapi/system.cpp" @@ -10,6 +11,7 @@ add_executable("kernel" "kstd/print.cpp" # Kernel Implementation + "src/cpu.cpp" "src/main.cpp" "src/memory/bitmap_allocator.cpp" "src/memory/block_list_allocator.cpp" diff --git a/kernel/include/kernel/cpu.hpp b/kernel/include/kernel/cpu.hpp new file mode 100644 index 0000000..d4e1ced --- /dev/null +++ b/kernel/include/kernel/cpu.hpp @@ -0,0 +1,14 @@ +#ifndef TEACHOS_KERNEL_CPU_HPP +#define TEACHOS_KERNEL_CPU_HPP + +namespace kernel::cpu +{ + + //! Initialize the kernel heap. + auto init() -> void; + + //! + +} // namespace kernel::cpu + +#endif
\ No newline at end of file diff --git a/kernel/kapi/cpu.cpp b/kernel/kapi/cpu.cpp new file mode 100644 index 0000000..2089098 --- /dev/null +++ b/kernel/kapi/cpu.cpp @@ -0,0 +1,30 @@ +#include "kapi/cpu.hpp" + +namespace kapi::cpu +{ + + namespace + { + struct null_exception_handler : exception_handler + { + auto handle(exception const &) -> bool override + { + return false; + } + } static constinit default_exception_handler; + + exception_handler * current_handler = &default_exception_handler; + + } // namespace + + auto get_exception_handler() -> exception_handler & + { + return *current_handler; + } + + auto set_exception_handler(exception_handler & handler) -> void + { + current_handler = &handler; + } + +} // namespace kapi::cpu
\ No newline at end of file diff --git a/kernel/src/cpu.cpp b/kernel/src/cpu.cpp new file mode 100644 index 0000000..fc460c9 --- /dev/null +++ b/kernel/src/cpu.cpp @@ -0,0 +1,46 @@ +#include "kernel/cpu.hpp" + +#include "kapi/cpu.hpp" +#include "kapi/system.hpp" + +#include <kstd/print> + +namespace kernel::cpu +{ + + namespace + { + struct exception_handler : kapi::cpu::exception_handler + { + auto handle(kapi::cpu::exception const & context) -> bool override + { + switch (context.type) + { + case kapi::cpu::exception::type::page_fault: + return handle_page_fault(context); + default: + return false; + } + } + + private: + auto handle_page_fault(kapi::cpu::exception const & context) -> bool + { + kstd::println(kstd::print_sink::stderr, "[OS:CPU] PAGE FAULT!"); + kstd::println(kstd::print_sink::stderr, "\tFault address: {:#018x}", context.access_address); + kstd::println(kstd::print_sink::stderr, "\tPresent: {}", context.is_present); + kstd::println(kstd::print_sink::stderr, "\tWrite: {}", context.is_write_access); + kstd::println(kstd::print_sink::stderr, "\tUser: {}", context.is_user_mode); + kstd::println(kstd::print_sink::stderr, "\tRIP: {:#018x}", context.instruction_pointer); + + kapi::system::panic("Halting the system due to an unrecoverable page fault."); + } + } static constinit handler; + } // namespace + + auto init() -> void + { + kapi::cpu::set_exception_handler(handler); + } + +} // namespace kernel::cpu
\ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index eb59402..0416ee9 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -1,8 +1,10 @@ #include "kapi/boot_modules.hpp" #include "kapi/cio.hpp" +#include "kapi/cpu.hpp" #include "kapi/memory.hpp" #include "kapi/system.hpp" +#include "kernel/cpu.hpp" #include "kernel/devices/storage/storage_management.hpp" #include "kernel/filesystem/device_file.hpp" #include "kernel/filesystem/file_descriptor_table.hpp" @@ -90,6 +92,9 @@ auto main() -> int kapi::cio::init(); kstd::println("[OS] IO subsystem initialized."); + kapi::cpu::init(); + kernel::cpu::init(); + kapi::memory::init(); kernel::memory::init_heap(kapi::memory::heap_base); kstd::println("[OS] Memory subsystem initialized."); |
