diff options
| -rw-r--r-- | arch/x86_64/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/boot/boot.hpp (renamed from arch/x86_64/include/x86_64/boot/boot.hpp) | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/boot/ld.hpp (renamed from arch/x86_64/include/x86_64/boot/ld.hpp) | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/cpu/control_register.hpp (renamed from arch/x86_64/include/x86_64/cpu/control_register.hpp) | 26 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/cpu/interrupts.hpp (renamed from arch/x86_64/include/x86_64/cpu/interrupts.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/cpu/model_specific_register.hpp (renamed from arch/x86_64/include/x86_64/cpu/model_specific_register.hpp) | 14 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/cpu/registers.hpp (renamed from arch/x86_64/include/x86_64/cpu/registers.hpp) | 10 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/cpu/segment_selector.hpp (renamed from arch/x86_64/include/x86_64/cpu/segment_selector.hpp) | 5 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/debug/qemu_output.hpp (renamed from arch/x86_64/include/x86_64/debug/qemu_output.hpp) | 14 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/device_io/port_io.hpp (renamed from arch/x86_64/include/x86_64/device_io/port_io.hpp) | 4 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/buffered_allocator.hpp (renamed from arch/x86_64/include/x86_64/memory/buffered_allocator.hpp) | 15 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/kernel_mapper.hpp (renamed from arch/x86_64/include/x86_64/memory/kernel_mapper.hpp) | 9 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/mmu.hpp (renamed from arch/x86_64/include/x86_64/memory/mmu.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/page_table.hpp (renamed from arch/x86_64/include/x86_64/memory/page_table.hpp) | 43 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/page_utilities.hpp (renamed from arch/x86_64/include/x86_64/memory/page_utilities.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/paging_root.hpp (renamed from arch/x86_64/include/x86_64/memory/paging_root.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/recursive_page_mapper.hpp | 25 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/region_allocator.hpp (renamed from arch/x86_64/include/x86_64/memory/region_allocator.hpp) | 35 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/memory/scoped_mapping.hpp (renamed from arch/x86_64/include/x86_64/memory/scoped_mapping.hpp) | 18 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/crtc.hpp (renamed from arch/x86_64/include/x86_64/vga/crtc.hpp) | 8 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text.hpp (renamed from arch/x86_64/include/x86_64/vga/text.hpp) | 0 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/attribute.hpp (renamed from arch/x86_64/include/x86_64/vga/text/attribute.hpp) | 10 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/buffer.hpp (renamed from arch/x86_64/include/x86_64/vga/text/buffer.hpp) | 8 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/color.hpp (renamed from arch/x86_64/include/x86_64/vga/text/color.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/common_attributes.hpp (renamed from arch/x86_64/include/x86_64/vga/text/common_attributes.hpp) | 12 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/device.hpp (renamed from arch/x86_64/include/x86_64/vga/text/device.hpp) | 14 | ||||
| -rw-r--r-- | arch/x86_64/include/arch/vga/text/flags.hpp (renamed from arch/x86_64/include/x86_64/vga/text/flags.hpp) | 6 | ||||
| -rw-r--r-- | arch/x86_64/include/x86_64/memory/recursive_page_mapper.hpp | 25 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cio.cpp | 20 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu.cpp (renamed from arch/x86_64/src/kapi/cpu.cpp) | 4 | ||||
| -rw-r--r-- | arch/x86_64/kapi/memory.cpp (renamed from arch/x86_64/src/kapi/memory.cpp) | 64 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/boot32.S | 2 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/initialize_runtime.cpp | 23 | ||||
| -rw-r--r-- | arch/x86_64/src/debug/qemu_output.cpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/src/kapi/cio.cpp | 20 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/kernel_mapper.cpp | 36 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/mmu.cpp | 12 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/page_table.cpp | 12 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/paging_root.cpp | 6 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/recursive_page_mapper.cpp | 30 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/region_allocator.cpp | 30 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/scoped_mapping.cpp | 22 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text/buffer.cpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text/device.cpp | 24 | ||||
| -rw-r--r-- | kapi/include/kapi/boot.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/cio.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/cio/output_device.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/cpu.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/address.hpp | 12 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/chunk.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/frame.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/frame_allocator.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/page.hpp | 4 | ||||
| -rw-r--r-- | kapi/include/kapi/memory/page_mapper.hpp | 6 | ||||
| -rw-r--r-- | kapi/include/kapi/system.hpp | 4 | ||||
| -rw-r--r-- | kernel/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | kernel/kapi/cio.cpp (renamed from kernel/src/kapi/cio.cpp) | 4 | ||||
| -rw-r--r-- | kernel/kapi/memory.cpp (renamed from kernel/src/kapi/memory.cpp) | 4 | ||||
| -rw-r--r-- | kernel/kapi/system.cpp (renamed from kernel/src/kapi/system.cpp) | 4 | ||||
| -rw-r--r-- | kernel/kstd/os.cpp (renamed from kernel/src/kstd/os.cpp) | 2 | ||||
| -rw-r--r-- | kernel/kstd/print.cpp (renamed from kernel/src/kstd/print.cpp) | 8 | ||||
| -rw-r--r-- | kernel/src/main.cpp | 6 |
63 files changed, 393 insertions, 378 deletions
diff --git a/arch/x86_64/CMakeLists.txt b/arch/x86_64/CMakeLists.txt index 519fb93..413b5aa 100644 --- a/arch/x86_64/CMakeLists.txt +++ b/arch/x86_64/CMakeLists.txt @@ -11,6 +11,11 @@ target_link_libraries("x86_64" PUBLIC ) target_sources("x86_64" PRIVATE + # Platform-dependent KAPI implementation + "kapi/cio.cpp" + "kapi/cpu.cpp" + "kapi/memory.cpp" + # Low-level bootstrap "src/boot/boot32.S" "src/boot/entry64.s" @@ -20,11 +25,6 @@ target_sources("x86_64" PRIVATE # Debug interfaces "src/debug/qemu_output.cpp" - # api::kapi implementation - "src/kapi/cio.cpp" - "src/kapi/cpu.cpp" - "src/kapi/memory.cpp" - # Memory management "src/memory/kernel_mapper.cpp" "src/memory/mmu.cpp" diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/arch/boot/boot.hpp index 2c44659..71e8a70 100644 --- a/arch/x86_64/include/x86_64/boot/boot.hpp +++ b/arch/x86_64/include/arch/boot/boot.hpp @@ -51,7 +51,7 @@ #include <cstddef> -namespace teachos::boot +namespace kapi::boot { struct information @@ -63,7 +63,7 @@ namespace teachos::boot std::size_t vga_buffer_index; }; -} // namespace teachos::boot +} // namespace kapi::boot #endif diff --git a/arch/x86_64/include/x86_64/boot/ld.hpp b/arch/x86_64/include/arch/boot/ld.hpp index b073863..988723d 100644 --- a/arch/x86_64/include/x86_64/boot/ld.hpp +++ b/arch/x86_64/include/arch/boot/ld.hpp @@ -17,7 +17,7 @@ #include <cstddef> -namespace teachos::boot::x86_64 +namespace arch::boot { extern "C" @@ -56,6 +56,6 @@ namespace teachos::boot::x86_64 extern std::byte TEACHOS_VMA; } -} // namespace teachos::boot::x86_64 +} // namespace arch::boot #endif diff --git a/arch/x86_64/include/x86_64/cpu/control_register.hpp b/arch/x86_64/include/arch/cpu/control_register.hpp index 67ae87e..681dc5f 100644 --- a/arch/x86_64/include/x86_64/cpu/control_register.hpp +++ b/arch/x86_64/include/arch/cpu/control_register.hpp @@ -1,7 +1,7 @@ -#ifndef TEACHOS_X86_64_CPU_IMPL_CONTROL_REGISTERS_HPP -#define TEACHOS_X86_64_CPU_IMPL_CONTROL_REGISTERS_HPP +#ifndef TEACHOS_X86_64_CPU_CONTROL_REGISTERS_HPP +#define TEACHOS_X86_64_CPU_CONTROL_REGISTERS_HPP -// IWYU pragma: private, include "x86_64/cpu/registers.hpp" +// IWYU pragma: private, include "arch/cpu/registers.hpp" #include "kapi/memory.hpp" @@ -12,7 +12,7 @@ #include <type_traits> #include <utility> -namespace teachos::cpu::x86_64 +namespace arch::cpu { namespace impl { @@ -58,22 +58,22 @@ namespace teachos::cpu::x86_64 page_level_write_through = 1uz << 0, page_level_cache_disable = 1uz << 1, }; -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu namespace kstd::ext { template<> - struct is_bitfield_enum<teachos::cpu::x86_64::cr0_flags> : std::true_type + struct is_bitfield_enum<arch::cpu::cr0_flags> : std::true_type { }; template<> - struct is_bitfield_enum<teachos::cpu::x86_64::cr3_flags> : std::true_type + struct is_bitfield_enum<arch::cpu::cr3_flags> : std::true_type { }; } // namespace kstd::ext -namespace teachos::cpu::x86_64 +namespace arch::cpu { //! A mixin for flag-oriented control registers. //! @@ -173,7 +173,7 @@ namespace teachos::cpu::x86_64 //! //! @param address The physical address of the root page map //! @param flags The root configuration flags of the paging system. - constexpr cr3_value(memory::physical_address address, cr3_flags flags = static_cast<cr3_flags>(0)) + constexpr cr3_value(kapi::memory::physical_address address, cr3_flags flags = static_cast<cr3_flags>(0)) : m_flags{static_cast<std::uint64_t>(flags)} , m_address{static_cast<std::uint64_t>(address.raw())} {} @@ -181,15 +181,15 @@ namespace teachos::cpu::x86_64 //! Extract the physical address of the root page map from this value. //! //! @return The physical address of the root page map. - [[nodiscard]] constexpr auto address() const -> memory::physical_address + [[nodiscard]] constexpr auto address() const -> kapi::memory::physical_address { - return memory::physical_address{m_address}; + return kapi::memory::physical_address{m_address}; } //! Encode the frame aligned physical address of the root page map into this value. //! //! @param frame The frame containing a PML4. - constexpr auto frame(memory::frame frame) -> void + constexpr auto frame(kapi::memory::frame frame) -> void { m_address = static_cast<std::uint64_t>(frame.number()); } @@ -243,6 +243,6 @@ namespace teachos::cpu::x86_64 static_assert(sizeof(cr3_value) == sizeof(std::uint64_t)); -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/cpu/interrupts.hpp b/arch/x86_64/include/arch/cpu/interrupts.hpp index 88d0b78..92c5824 100644 --- a/arch/x86_64/include/x86_64/cpu/interrupts.hpp +++ b/arch/x86_64/include/arch/cpu/interrupts.hpp @@ -1,13 +1,13 @@ #ifndef TEACHOS_X86_64_CPU_INTERRUPTS_HPP #define TEACHOS_X86_64_CPU_INTERRUPTS_HPP -#include "x86_64/cpu/segment_selector.hpp" +#include "arch/cpu/segment_selector.hpp" #include <array> #include <cstdint> #include <type_traits> -namespace teachos::cpu::x86_64 +namespace arch::cpu { //! The types of supported gates. @@ -56,6 +56,6 @@ namespace teachos::cpu::x86_64 std::array<gate_descriptor, 256> m_descriptors{}; }; -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/cpu/model_specific_register.hpp b/arch/x86_64/include/arch/cpu/model_specific_register.hpp index 39765fe..8539a24 100644 --- a/arch/x86_64/include/x86_64/cpu/model_specific_register.hpp +++ b/arch/x86_64/include/arch/cpu/model_specific_register.hpp @@ -1,5 +1,5 @@ -#ifndef TEACHOS_X86_64_CPU_IMPL_MODEL_SPECIFIC_REGISTER_HPP -#define TEACHOS_X86_64_CPU_IMPL_MODEL_SPECIFIC_REGISTER_HPP +#ifndef TEACHOS_X86_64_CPU_MODEL_SPECIFIC_REGISTER_HPP +#define TEACHOS_X86_64_CPU_MODEL_SPECIFIC_REGISTER_HPP // IWYU pragma: private, include "x86_64/cpu/registers.hpp" @@ -9,7 +9,7 @@ #include <cstdint> #include <type_traits> -namespace teachos::cpu::x86_64 +namespace arch::cpu { //! The flags of the IA32_EFER (Extended Features Enable Register) MSR. @@ -25,19 +25,19 @@ namespace teachos::cpu::x86_64 execute_disable_bit_enable = 1uz << 11, }; -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu namespace kstd::ext { template<> - struct is_bitfield_enum<teachos::cpu::x86_64::ia32_efer_flags> : std::true_type + struct is_bitfield_enum<arch::cpu::ia32_efer_flags> : std::true_type { }; } // namespace kstd::ext -namespace teachos::cpu::x86_64 +namespace arch::cpu { //! The MSR number for the IA32_EFER MSR constexpr auto ia32_efer_number = 0xC000'0080u; @@ -146,6 +146,6 @@ namespace teachos::cpu::x86_64 } }; -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/cpu/registers.hpp b/arch/x86_64/include/arch/cpu/registers.hpp index 3ddd539..d7def10 100644 --- a/arch/x86_64/include/x86_64/cpu/registers.hpp +++ b/arch/x86_64/include/arch/cpu/registers.hpp @@ -3,10 +3,10 @@ #include "kapi/memory.hpp" -#include "x86_64/cpu/control_register.hpp" // IWYU pragma: export -#include "x86_64/cpu/model_specific_register.hpp" // IWYU pragma: export +#include "arch/cpu/control_register.hpp" // IWYU pragma: export +#include "arch/cpu/model_specific_register.hpp" // IWYU pragma: export -namespace teachos::cpu::x86_64 +namespace arch::cpu { //! Configuration Register 0. @@ -17,7 +17,7 @@ namespace teachos::cpu::x86_64 //! Configuration Register 2. //! //! This configuration register holds the memory address the access to which has triggered the most recent page fault. - using cr2 = control_register<memory::linear_address, &impl::cr2_asm>; + using cr2 = control_register<kapi::memory::linear_address, &impl::cr2_asm>; //! Configuration Register 3. //! @@ -27,6 +27,6 @@ namespace teachos::cpu::x86_64 //! The I32_EFER (Extended Feature Enable Register) MSR using i32_efer = model_specific_register<ia32_efer_number, ia32_efer_flags>; -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/cpu/segment_selector.hpp b/arch/x86_64/include/arch/cpu/segment_selector.hpp index bb07e28..1a78c47 100644 --- a/arch/x86_64/include/x86_64/cpu/segment_selector.hpp +++ b/arch/x86_64/include/arch/cpu/segment_selector.hpp @@ -2,7 +2,8 @@ #define TEACHOS_X86_64_SEGMENT_SELECTOR_HPP #include <cstdint> -namespace teachos::cpu::x86_64 + +namespace arch::cpu { struct segment_selector @@ -15,6 +16,6 @@ namespace teachos::cpu::x86_64 static_assert(sizeof(segment_selector) == sizeof(std::uint16_t)); static_assert(alignof(segment_selector) == alignof(std::uint16_t)); -} // namespace teachos::cpu::x86_64 +} // namespace arch::cpu #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/debug/qemu_output.hpp b/arch/x86_64/include/arch/debug/qemu_output.hpp index 61b47d6..e72eb39 100644 --- a/arch/x86_64/include/x86_64/debug/qemu_output.hpp +++ b/arch/x86_64/include/arch/debug/qemu_output.hpp @@ -3,11 +3,11 @@ #include "kapi/cio.hpp" -#include "x86_64/device_io/port_io.hpp" +#include "arch/device_io/port_io.hpp" #include <string_view> -namespace teachos::debug::x86_64 +namespace arch::debug { //! A QEMU debug console output device. @@ -18,18 +18,18 @@ namespace teachos::debug::x86_64 //! @note Support for the device has to be enabled when the emulator is started. The device will try to detect if the //! port is available. If the port is detected, any output to the device will be written to port before being //! forwarded to the lower device. - struct qemu_output : cio::output_device + struct qemu_output : kapi::cio::output_device { //! The port to write to. - using port = io::x86_64::port<0xE9, unsigned char, io::x86_64::port_write, io::x86_64::port_read>; + using port = io::port<0xE9, unsigned char, io::port_write, io::port_read>; //! Construct a new debug device wrapper for the given output device. //! //! @param lower The device to forward the output to. explicit qemu_output(output_device & lower); - //! @copydoc cio::output_device - auto write(cio::output_stream stream, std::string_view text) -> void override; + //! @copydoc kapi::cio::output_device + auto write(kapi::cio::output_stream stream, std::string_view text) -> void override; private: //! The device to forward the output to. @@ -38,6 +38,6 @@ namespace teachos::debug::x86_64 bool m_present; }; -} // namespace teachos::debug::x86_64 +} // namespace arch::debug #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/device_io/port_io.hpp b/arch/x86_64/include/arch/device_io/port_io.hpp index fa2ec2d..65e58e3 100644 --- a/arch/x86_64/include/x86_64/device_io/port_io.hpp +++ b/arch/x86_64/include/arch/device_io/port_io.hpp @@ -8,7 +8,7 @@ #include <string_view> #include <type_traits> -namespace teachos::io::x86_64 +namespace arch::io { //! The requirements imposed on a type usable for port I/O. @@ -102,6 +102,6 @@ namespace teachos::io::x86_64 : std::string_view{"eax"}; }; -} // namespace teachos::io::x86_64 +} // namespace arch::io #endif
\ No newline at end of file diff --git a/arch/x86_64/include/x86_64/memory/buffered_allocator.hpp b/arch/x86_64/include/arch/memory/buffered_allocator.hpp index fa3b5cb..87ebbf6 100644 --- a/arch/x86_64/include/x86_64/memory/buffered_allocator.hpp +++ b/arch/x86_64/include/arch/memory/buffered_allocator.hpp @@ -10,11 +10,11 @@ #include <optional> #include <utility> -namespace teachos::memory::x86_64 +namespace arch::memory { template<std::size_t BufferSize> - struct buffered_allocator : frame_allocator + struct buffered_allocator : kapi::memory::frame_allocator { explicit buffered_allocator(frame_allocator * underlying) : m_underlying{underlying} @@ -23,7 +23,7 @@ namespace teachos::memory::x86_64 auto from_underlying = m_underlying->allocate_many(BufferSize); if (!from_underlying) { - system::panic("[x86_64:MEM] Not enough frames available from underlying allocator."); + kapi::system::panic("[x86_64:MEM] Not enough frames available from underlying allocator."); } auto [first_frame, count] = *from_underlying; std::ranges::generate_n(m_pool.begin(), count, [first_frame]() mutable { return first_frame++; }); @@ -45,7 +45,8 @@ namespace teachos::memory::x86_64 auto operator=(buffered_allocator const &) = delete; auto operator=(buffered_allocator &&) = delete; - auto allocate_many(std::size_t count = 1) noexcept -> std::optional<std::pair<frame, std::size_t>> override + auto allocate_many(std::size_t count = 1) noexcept + -> std::optional<std::pair<kapi::memory::frame, std::size_t>> override { if (count > m_free) { @@ -87,7 +88,7 @@ namespace teachos::memory::x86_64 return m_underlying->allocate_many(count); } - auto release_many(std::pair<frame, std::size_t> frame_set) -> void override + auto release_many(std::pair<kapi::memory::frame, std::size_t> frame_set) -> void override { if (m_free == BufferSize) { @@ -129,9 +130,9 @@ namespace teachos::memory::x86_64 frame_allocator * m_underlying; std::size_t m_free; - std::array<std::optional<frame>, BufferSize> m_pool{}; + std::array<std::optiona |
