From 7d6f0ed063790042a808f4bf07c50d308b3f2de4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 16 Jan 2026 13:36:38 +0100 Subject: chore: restructure namespaces --- kernel/src/kapi/cio.cpp | 36 ------------------ kernel/src/kapi/memory.cpp | 94 ---------------------------------------------- kernel/src/kapi/system.cpp | 21 ----------- 3 files changed, 151 deletions(-) delete mode 100644 kernel/src/kapi/cio.cpp delete mode 100644 kernel/src/kapi/memory.cpp delete mode 100644 kernel/src/kapi/system.cpp (limited to 'kernel/src/kapi') diff --git a/kernel/src/kapi/cio.cpp b/kernel/src/kapi/cio.cpp deleted file mode 100644 index 01c6420..0000000 --- a/kernel/src/kapi/cio.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "kapi/cio.hpp" - -#include -#include -#include - -namespace teachos::cio -{ - namespace - { - struct null_device final : public output_device - { - null_device static instance; - auto write(output_stream, std::string_view) -> void override {} - }; - - constinit null_device null_device::instance; - } // namespace - - constinit auto static active_device = static_cast(&null_device::instance); - - auto set_output_device(output_device & device) -> std::optional - { - if (&device == active_device) - { - return {}; - } - return std::exchange(active_device, &device); - } - - auto write(output_stream stream, std::string_view text) -> void - { - active_device->write(stream, text); - } - -} // namespace teachos::cio diff --git a/kernel/src/kapi/memory.cpp b/kernel/src/kapi/memory.cpp deleted file mode 100644 index ebd4c15..0000000 --- a/kernel/src/kapi/memory.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "kapi/memory.hpp" - -#include "kapi/system.hpp" - -#include -#include -#include - -namespace teachos::memory -{ - - namespace - { - struct bad_frame_allocator final : public frame_allocator - { - bad_frame_allocator static instance; - - auto allocate_many(std::size_t) noexcept -> std::optional> override - { - system::panic("Tried to allocate frames without an active allocator."); - } - - auto release_many(std::pair) -> void override - { - system::panic("Tried to release frames without an active allocator."); - } - }; - - struct bad_page_mapper final : public page_mapper - { - bad_page_mapper static instance; - - auto map(page, frame, flags) -> std::byte * override - { - system::panic("Tried to map a page without an active mapper."); - } - - auto unmap(page) -> void override - { - system::panic("Tried to unmap a page without an active mapper."); - } - - auto try_unmap(page) noexcept -> bool override - { - return false; - } - }; - - constinit bad_frame_allocator bad_frame_allocator::instance{}; - constinit bad_page_mapper bad_page_mapper::instance{}; - } // namespace - - constinit auto static active_frame_allocator = static_cast(&bad_frame_allocator::instance); - constinit auto static active_page_mapper = static_cast(&bad_page_mapper::instance); - - auto set_frame_allocator(frame_allocator & allocator) -> std::optional - { - if (&allocator == active_frame_allocator) - { - return {}; - } - return std::exchange(active_frame_allocator, &allocator); - } - - auto set_page_mapper(page_mapper & mapper) -> std::optional - { - if (&mapper == active_page_mapper) - { - return {}; - } - return std::exchange(active_page_mapper, &mapper); - } - - auto allocate_frame() -> std::optional - { - return active_frame_allocator->allocate(); - } - - auto allocate_many_frames(std::size_t count) -> std::optional> - { - return active_frame_allocator->allocate_many(count); - } - - auto map(page page, frame frame) -> std::byte * - { - return active_page_mapper->map(page, frame, page_mapper::flags::empty); - } - - auto unmap(page page) -> void - { - return active_page_mapper->unmap(page); - } - -} // namespace teachos::memory \ No newline at end of file diff --git a/kernel/src/kapi/system.cpp b/kernel/src/kapi/system.cpp deleted file mode 100644 index cdde049..0000000 --- a/kernel/src/kapi/system.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "kapi/system.hpp" - -#include "kapi/cpu.hpp" - -#include - -#include -#include - -namespace teachos::system -{ - - [[gnu::weak]] - auto panic(std::string_view message, std::source_location location) -> void - { - kstd::println(kstd::print_sink::stderr, "[PANIC] in {} : {} @ {}:{}", location.function_name(), message, - location.file_name(), location.line()); - cpu::halt(); - } - -} // namespace teachos::system -- cgit v1.2.3