From 25483b7af8df6b08d460f807fda04c6d409bd44e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 14 Jul 2025 16:02:43 +0000 Subject: ide: start large-scale restructuring --- src/kernel/main.cpp | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/kernel/main.cpp (limited to 'src') diff --git a/src/kernel/main.cpp b/src/kernel/main.cpp deleted file mode 100644 index 36c6d92..0000000 --- a/src/kernel/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "arch/kernel/main.hpp" - -#include "arch/exception_handling/panic.hpp" - -extern "C" auto kernel_main() -> void -{ - teachos::arch::kernel::main(); - teachos::arch::exception_handling::panic("Architecture specific main returned!"); -} -- cgit v1.2.3 From 4edbe94ce1266c9acc6a695fedf1d2edd4ce11cd Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 24 Jul 2025 15:31:31 +0000 Subject: build: factor out kernel API --- src/abort.cpp | 3 +++ src/kstd.cpp | 13 +++++++++++++ src/main.cpp | 13 +++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/abort.cpp create mode 100644 src/kstd.cpp create mode 100644 src/main.cpp (limited to 'src') diff --git a/src/abort.cpp b/src/abort.cpp new file mode 100644 index 0000000..6b0070e --- /dev/null +++ b/src/abort.cpp @@ -0,0 +1,3 @@ +#include "kapi/system.hpp" + +extern "C" [[noreturn]] auto abort() -> void { teachos::system::panic("Abort called"); } diff --git a/src/kstd.cpp b/src/kstd.cpp new file mode 100644 index 0000000..2149c12 --- /dev/null +++ b/src/kstd.cpp @@ -0,0 +1,13 @@ +#include "kapi/system.hpp" + +#include + +namespace kstd::os +{ + + auto panic(std::string_view message, std::source_location location) -> void + { + teachos::system::panic(message, location); + } + +} // namespace kstd::os \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d6199d0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,13 @@ +#include "kapi/io.hpp" +#include "kapi/memory.hpp" +#include "kapi/system.hpp" + +auto main() -> int +{ + teachos::io::init(); + teachos::io::println("[OS] IO subsystem initialized."); + + teachos::memory::init(); + + teachos::system::panic("Architecture specific main returned!"); +} -- cgit v1.2.3 From dd04850c27e8bc273506f4a64bb28b7ddf111dc5 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 24 Jul 2025 20:51:55 +0000 Subject: kapi: rework text device interface --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index d6199d0..120e7e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,11 @@ -#include "kapi/io.hpp" +#include "kapi/cio.hpp" #include "kapi/memory.hpp" #include "kapi/system.hpp" auto main() -> int { - teachos::io::init(); - teachos::io::println("[OS] IO subsystem initialized."); + teachos::cio::init(); + teachos::cio::println("[OS] IO subsystem initialized."); teachos::memory::init(); -- cgit v1.2.3 From 12dedc7e2e51390fdf2caec3700e75db19be1cd4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 28 Oct 2025 18:31:39 +0100 Subject: kstd: don't rely on newlib --- src/abort.cpp | 3 --- src/kstd.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) delete mode 100644 src/abort.cpp (limited to 'src') diff --git a/src/abort.cpp b/src/abort.cpp deleted file mode 100644 index 6b0070e..0000000 --- a/src/abort.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "kapi/system.hpp" - -extern "C" [[noreturn]] auto abort() -> void { teachos::system::panic("Abort called"); } diff --git a/src/kstd.cpp b/src/kstd.cpp index 2149c12..77155af 100644 --- a/src/kstd.cpp +++ b/src/kstd.cpp @@ -5,6 +5,12 @@ namespace kstd::os { + auto abort() -> bool + { + panic("Abort called."); + return true; + } + auto panic(std::string_view message, std::source_location location) -> void { teachos::system::panic(message, location); -- cgit v1.2.3 From acabbacdee68ad80e829bda56ae5363d04646d2d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 29 Oct 2025 10:39:30 +0100 Subject: kstd: clean up libc implementation --- src/kstd.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/kstd.cpp b/src/kstd.cpp index 77155af..2149c12 100644 --- a/src/kstd.cpp +++ b/src/kstd.cpp @@ -5,12 +5,6 @@ namespace kstd::os { - auto abort() -> bool - { - panic("Abort called."); - return true; - } - auto panic(std::string_view message, std::source_location location) -> void { teachos::system::panic(message, location); -- cgit v1.2.3 From 6434de8ff75a9143847ef529bc209790ac4909b3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 29 Oct 2025 11:09:42 +0100 Subject: kapi: move frame and address to KAPI --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 120e7e0..fc7d2f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,5 +9,5 @@ auto main() -> int teachos::memory::init(); - teachos::system::panic("Architecture specific main returned!"); + teachos::system::panic("Returning from kernel main!"); } -- cgit v1.2.3 From 8fc5f9e3cc28b07b1f120eb1ffedc042fa6662b8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 12 Dec 2025 13:00:26 +0100 Subject: x86_64/kapi: implement remaining mapping steps --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index fc7d2f4..3394275 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ auto main() -> int teachos::cio::println("[OS] IO subsystem initialized."); teachos::memory::init(); + teachos::cio::println("[OS] Memory subsystem initialized."); teachos::system::panic("Returning from kernel main!"); } -- cgit v1.2.3 From 4bf9eded3a5d6b007ba79a5716143fa8b3a5aaf6 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 12 Dec 2025 14:26:16 +0100 Subject: kapi: move platform independent implementation --- src/kapi/cio.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/kapi/system.cpp | 20 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/kapi/cio.cpp create mode 100644 src/kapi/system.cpp (limited to 'src') diff --git a/src/kapi/cio.cpp b/src/kapi/cio.cpp new file mode 100644 index 0000000..66493b6 --- /dev/null +++ b/src/kapi/cio.cpp @@ -0,0 +1,57 @@ +#include "kapi/cio.hpp" + +#include +#include +#include + +namespace teachos::cio +{ + namespace + { + struct null_device final : public output_device + { + null_device static instance; + + auto write(std::string_view) -> void override {} + auto writeln(std::string_view) -> void override {} + + auto write_error(std::string_view) -> void override {} + auto writeln_error(std::string_view) -> void override {} + }; + + constinit null_device null_device::instance; + } // namespace + + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + constinit auto 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 print(std::string_view text) -> void + { + active_device->write(text); + } + + auto println(std::string_view text) -> void + { + active_device->writeln(text); + } + + auto print_error(std::string_view text) -> void + { + active_device->write_error(text); + } + + auto println_error(std::string_view text) -> void + { + active_device->writeln_error(text); + } + +} // namespace teachos::cio \ No newline at end of file diff --git a/src/kapi/system.cpp b/src/kapi/system.cpp new file mode 100644 index 0000000..3ae3f29 --- /dev/null +++ b/src/kapi/system.cpp @@ -0,0 +1,20 @@ +#include "kapi/system.hpp" + +#include "kapi/cio.hpp" +#include "kapi/cpu.hpp" + +namespace teachos::system +{ + + [[gnu::weak]] + auto panic(std::string_view message, std::source_location location) -> void + { + cio::println_error("!!!Kernel Panic!!! "); + cio::println_error(message); + cio::println_error(location.file_name()); + cio::println_error(location.function_name()); + + cpu::halt(); + } + +} // namespace teachos::system -- cgit v1.2.3 From 43ddde5e30a0d71aa11025a5ae232cea83e7fbde Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Dec 2025 16:28:16 +0100 Subject: kapi: remodel memory API to follow cio API --- src/kapi/memory.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/kapi/memory.cpp (limited to 'src') diff --git a/src/kapi/memory.cpp b/src/kapi/memory.cpp new file mode 100644 index 0000000..d6c84e1 --- /dev/null +++ b/src/kapi/memory.cpp @@ -0,0 +1,91 @@ +#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() noexcept -> std::optional override + { + system::panic("Tried to allocate a frame without an active allocator."); + } + + auto release(frame) -> void override + { + system::panic("Tried to release a frame 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 + + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + constinit auto active_frame_allocator = static_cast(&bad_frame_allocator::instance); + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) + constinit auto 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 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 -- cgit v1.2.3 From 0f09b8ff164a69195ec6c25f6aea1cb607d826f8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 15 Dec 2025 16:32:34 +0100 Subject: kernel: move implementation to kernel directory --- src/kapi/cio.cpp | 57 --------------------------------- src/kapi/memory.cpp | 91 ----------------------------------------------------- src/kapi/system.cpp | 20 ------------ src/kstd.cpp | 13 -------- src/main.cpp | 14 --------- 5 files changed, 195 deletions(-) delete mode 100644 src/kapi/cio.cpp delete mode 100644 src/kapi/memory.cpp delete mode 100644 src/kapi/system.cpp delete mode 100644 src/kstd.cpp delete mode 100644 src/main.cpp (limited to 'src') diff --git a/src/kapi/cio.cpp b/src/kapi/cio.cpp deleted file mode 100644 index 66493b6..0000000 --- a/src/kapi/cio.cpp +++ /dev/null @@ -1,57 +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(std::string_view) -> void override {} - auto writeln(std::string_view) -> void override {} - - auto write_error(std::string_view) -> void override {} - auto writeln_error(std::string_view) -> void override {} - }; - - constinit null_device null_device::instance; - } // namespace - - // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - constinit auto 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 print(std::string_view text) -> void - { - active_device->write(text); - } - - auto println(std::string_view text) -> void - { - active_device->writeln(text); - } - - auto print_error(std::string_view text) -> void - { - active_device->write_error(text); - } - - auto println_error(std::string_view text) -> void - { - active_device->writeln_error(text); - } - -} // namespace teachos::cio \ No newline at end of file diff --git a/src/kapi/memory.cpp b/src/kapi/memory.cpp deleted file mode 100644 index d6c84e1..0000000 --- a/src/kapi/memory.cpp +++ /dev/null @@ -1,91 +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() noexcept -> std::optional override - { - system::panic("Tried to allocate a frame without an active allocator."); - } - - auto release(frame) -> void override - { - system::panic("Tried to release a frame 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 - - // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - constinit auto active_frame_allocator = static_cast(&bad_frame_allocator::instance); - // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - constinit auto 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 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/src/kapi/system.cpp b/src/kapi/system.cpp deleted file mode 100644 index 3ae3f29..0000000 --- a/src/kapi/system.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "kapi/system.hpp" - -#include "kapi/cio.hpp" -#include "kapi/cpu.hpp" - -namespace teachos::system -{ - - [[gnu::weak]] - auto panic(std::string_view message, std::source_location location) -> void - { - cio::println_error("!!!Kernel Panic!!! "); - cio::println_error(message); - cio::println_error(location.file_name()); - cio::println_error(location.function_name()); - - cpu::halt(); - } - -} // namespace teachos::system diff --git a/src/kstd.cpp b/src/kstd.cpp deleted file mode 100644 index 2149c12..0000000 --- a/src/kstd.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "kapi/system.hpp" - -#include - -namespace kstd::os -{ - - auto panic(std::string_view message, std::source_location location) -> void - { - teachos::system::panic(message, location); - } - -} // namespace kstd::os \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 3394275..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "kapi/cio.hpp" -#include "kapi/memory.hpp" -#include "kapi/system.hpp" - -auto main() -> int -{ - teachos::cio::init(); - teachos::cio::println("[OS] IO subsystem initialized."); - - teachos::memory::init(); - teachos::cio::println("[OS] Memory subsystem initialized."); - - teachos::system::panic("Returning from kernel main!"); -} -- cgit v1.2.3