aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/include/x86_64/boot/boot.hpp26
-rw-r--r--arch/x86_64/include/x86_64/boot/ld.hpp4
-rw-r--r--arch/x86_64/include/x86_64/cpu/registers.hpp4
-rw-r--r--arch/x86_64/include/x86_64/device_io/port_io.hpp4
-rw-r--r--arch/x86_64/include/x86_64/memory/mmu.hpp6
-rw-r--r--arch/x86_64/include/x86_64/memory/region_allocator.hpp8
-rw-r--r--arch/x86_64/include/x86_64/vga/crtc.hpp8
-rw-r--r--arch/x86_64/include/x86_64/vga/text.hpp4
-rw-r--r--arch/x86_64/src/cpu/registers.cpp4
-rw-r--r--arch/x86_64/src/kapi/cio.cpp2
-rw-r--r--arch/x86_64/src/kapi/memory.cpp8
-rw-r--r--arch/x86_64/src/memory/mmu.cpp6
-rw-r--r--arch/x86_64/src/memory/region_allocator.cpp16
-rw-r--r--arch/x86_64/src/vga/text.cpp6
-rw-r--r--kapi/include/kapi/memory.hpp5
-rw-r--r--kapi/include/kapi/memory/address.hpp (renamed from arch/x86_64/include/x86_64/memory/address.hpp)8
-rw-r--r--kapi/include/kapi/memory/frame.hpp (renamed from arch/x86_64/include/x86_64/memory/frame.hpp)55
-rw-r--r--src/main.cpp2
18 files changed, 89 insertions, 87 deletions
diff --git a/arch/x86_64/include/x86_64/boot/boot.hpp b/arch/x86_64/include/x86_64/boot/boot.hpp
index 1887e73..86f8ce3 100644
--- a/arch/x86_64/include/x86_64/boot/boot.hpp
+++ b/arch/x86_64/include/x86_64/boot/boot.hpp
@@ -48,18 +48,22 @@
#include <kstd/asm_ptr>
-extern "C"
+namespace teachos::boot::x86_64
{
- /**
- * @brief A pointer to the multiboot 2 information structure provided by the boot loader.
- */
- extern kstd::asm_ptr<multiboot2::information_view> multiboot_information_pointer;
-
- /**
- * @brief A pointer to the VGA text mode buffer.
- */
- extern kstd::asm_ptr<std::pair<char, std::byte>> vga_buffer_pointer;
-}
+
+ extern "C"
+ {
+ /**
+ * @brief A pointer to the multiboot 2 information structure provided by the boot loader.
+ */
+ extern kstd::asm_ptr<multiboot2::information_view> multiboot_information_pointer;
+
+ /**
+ * @brief A pointer to the VGA text mode buffer.
+ */
+ extern kstd::asm_ptr<std::pair<char, std::byte>> vga_buffer_pointer;
+ }
+} // namespace teachos::boot::x86_64
#endif
diff --git a/arch/x86_64/include/x86_64/boot/ld.hpp b/arch/x86_64/include/x86_64/boot/ld.hpp
index 51eb23b..cf59c66 100644
--- a/arch/x86_64/include/x86_64/boot/ld.hpp
+++ b/arch/x86_64/include/x86_64/boot/ld.hpp
@@ -17,7 +17,7 @@
#include <cstddef>
-namespace teachos::x86_64::boot
+namespace teachos::boot::x86_64
{
/**
* @var _start_physical
@@ -42,6 +42,6 @@ namespace teachos::x86_64::boot
* @see _start_physical
*/
extern "C" std::byte _end_physical;
-} // namespace teachos::x86_64::boot
+} // namespace teachos::boot::x86_64
#endif
diff --git a/arch/x86_64/include/x86_64/cpu/registers.hpp b/arch/x86_64/include/x86_64/cpu/registers.hpp
index 607d559..d19acfc 100644
--- a/arch/x86_64/include/x86_64/cpu/registers.hpp
+++ b/arch/x86_64/include/x86_64/cpu/registers.hpp
@@ -3,7 +3,7 @@
#include <cstdint>
-namespace teachos::x86_64::cpu
+namespace teachos::cpu::x86_64
{
/**
@@ -67,6 +67,6 @@ namespace teachos::x86_64::cpu
*/
auto set_cr0_bit(cr0_flags flag) -> void;
-} // namespace teachos::x86_64::cpu
+} // namespace teachos::cpu::x86_64
#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/x86_64/device_io/port_io.hpp
index 4cf0b65..352a4d0 100644
--- a/arch/x86_64/include/x86_64/device_io/port_io.hpp
+++ b/arch/x86_64/include/x86_64/device_io/port_io.hpp
@@ -5,7 +5,7 @@
#include <cstdint>
#include <type_traits>
-namespace teachos::x86_64::io
+namespace teachos::io::x86_64
{
/**
* @brief An I/O port of a given size at a given address.
@@ -127,6 +127,6 @@ namespace teachos::x86_64::io
}
};
-} // namespace teachos::x86_64::io
+} // namespace teachos::io::x86_64
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/mmu.hpp b/arch/x86_64/include/x86_64/memory/mmu.hpp
index b03ffa2..323d18a 100644
--- a/arch/x86_64/include/x86_64/memory/mmu.hpp
+++ b/arch/x86_64/include/x86_64/memory/mmu.hpp
@@ -1,9 +1,9 @@
#ifndef TEACHOS_X86_64_MEMORY_MMU_HPP
#define TEACHOS_X86_64_MEMORY_MMU_HPP
-#include "x86_64/memory/address.hpp"
+#include "kapi/memory/address.hpp"
-namespace teachos::x86_64::memory
+namespace teachos::memory::x86_64
{
/**
* @brief Invalidates any translation lookaside buffer (TLB) entry for the page table the given address is cotained
@@ -22,6 +22,6 @@ namespace teachos::x86_64::memory
*/
auto tlb_flush_all() -> void;
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory::x86_64
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/region_allocator.hpp b/arch/x86_64/include/x86_64/memory/region_allocator.hpp
index 23bea10..a918195 100644
--- a/arch/x86_64/include/x86_64/memory/region_allocator.hpp
+++ b/arch/x86_64/include/x86_64/memory/region_allocator.hpp
@@ -1,15 +1,15 @@
#ifndef TEACHOS_X86_64_MEMORY_REGION_ALLOCATOR_HPP
#define TEACHOS_X86_64_MEMORY_REGION_ALLOCATOR_HPP
-#include "x86_64/memory/address.hpp"
-#include "x86_64/memory/frame.hpp"
+#include "kapi/memory/address.hpp"
+#include "kapi/memory/frame.hpp"
#include <multiboot2/information.hpp>
#include <optional>
#include <utility>
-namespace teachos::x86_64::memory
+namespace teachos::memory::x86_64
{
/**
* @brief Allocates memory linearly using memory areas read from the multiboot2 information pointer and leaks any
@@ -71,6 +71,6 @@ namespace teachos::x86_64::memory
frame const m_multiboot_end; ///< The end address of the multiboot code in memory.
};
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory::x86_64
#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_AREA_FRAME_ALLOCATOR_HPP
diff --git a/arch/x86_64/include/x86_64/vga/crtc.hpp b/arch/x86_64/include/x86_64/vga/crtc.hpp
index 4b4eac5..e5ab9f1 100644
--- a/arch/x86_64/include/x86_64/vga/crtc.hpp
+++ b/arch/x86_64/include/x86_64/vga/crtc.hpp
@@ -5,17 +5,17 @@
#include <cstddef>
-namespace teachos::x86_64::vga::crtc
+namespace teachos::vga::x86_64::crtc
{
/**
* @brief The address port of the CRT Controller.
*/
- using address = x86_64::io::port<0x3d4, 1>;
+ using address = io::x86_64::port<0x3d4, 1>;
/**
* @brief The data port of the CRT Controller.
*/
- using data = x86_64::io::port<0x3d5, 1>;
+ using data = io::x86_64::port<0x3d5, 1>;
namespace registers
{
@@ -30,6 +30,6 @@ namespace teachos::x86_64::vga::crtc
[[maybe_unused]] auto constexpr cursor_end = std::byte{0x0b};
} // namespace registers
-} // namespace teachos::x86_64::vga::crtc
+} // namespace teachos::vga::x86_64::crtc
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp
index f8e6f1b..c193576 100644
--- a/arch/x86_64/include/x86_64/vga/text.hpp
+++ b/arch/x86_64/include/x86_64/vga/text.hpp
@@ -6,7 +6,7 @@
#include <cstdint>
#include <string_view>
-namespace teachos::x86_64::vga::text
+namespace teachos::vga::x86_64::text
{
/**
* @brief The colors available in the standard VGA text mode.
@@ -142,6 +142,6 @@ namespace teachos::x86_64::vga::text
auto writeln(std::string_view code_points, attribute attribute) -> void;
};
-} // namespace teachos::x86_64::vga::text
+} // namespace teachos::vga::x86_64::text
#endif // TEACHOS_ARCH_X86_64_VIDEO_VGA_TEXT_HPP \ No newline at end of file
diff --git a/arch/x86_64/src/cpu/registers.cpp b/arch/x86_64/src/cpu/registers.cpp
index 7ade98d..8646829 100644
--- a/arch/x86_64/src/cpu/registers.cpp
+++ b/arch/x86_64/src/cpu/registers.cpp
@@ -2,7 +2,7 @@
#include <type_traits>
-namespace teachos::x86_64::cpu
+namespace teachos::cpu::x86_64
{
auto read_control_register(control_register cr) -> uint64_t
{
@@ -61,4 +61,4 @@ namespace teachos::x86_64::cpu
auto const cr0 = read_control_register(control_register::cr0);
write_control_register(control_register::cr0, static_cast<std::underlying_type<cr0_flags>::type>(flag) | cr0);
}
-} // namespace teachos::x86_64::cpu
+} // namespace teachos::cpu::x86_64
diff --git a/arch/x86_64/src/kapi/cio.cpp b/arch/x86_64/src/kapi/cio.cpp
index ac3ae39..eb0142a 100644
--- a/arch/x86_64/src/kapi/cio.cpp
+++ b/arch/x86_64/src/kapi/cio.cpp
@@ -5,7 +5,7 @@
namespace teachos::cio
{
- auto static constinit vga_device = std::optional<x86_64::vga::text::device>{};
+ auto static constinit vga_device = std::optional<vga::x86_64::text::device>{};
auto init() -> void
{
diff --git a/arch/x86_64/src/kapi/memory.cpp b/arch/x86_64/src/kapi/memory.cpp
index d1c1f03..55e6ba9 100644
--- a/arch/x86_64/src/kapi/memory.cpp
+++ b/arch/x86_64/src/kapi/memory.cpp
@@ -1,10 +1,10 @@
#include "kapi/memory.hpp"
+#include "kapi/memory/frame.hpp"
#include "kapi/system.hpp"
#include "x86_64/boot/boot.hpp"
#include "x86_64/boot/ld.hpp"
-#include "x86_64/memory/address.hpp"
#include "x86_64/memory/region_allocator.hpp"
#include <multiboot2/information.hpp>
@@ -13,8 +13,10 @@
namespace teachos::memory
{
- using namespace x86_64::memory;
- using namespace x86_64::boot;
+ using namespace boot::x86_64;
+ using namespace memory::x86_64;
+
+ std::size_t const PLATFORM_FRAME_SIZE{4096};
namespace
{
diff --git a/arch/x86_64/src/memory/mmu.cpp b/arch/x86_64/src/memory/mmu.cpp
index 31783fe..e573b4e 100644
--- a/arch/x86_64/src/memory/mmu.cpp
+++ b/arch/x86_64/src/memory/mmu.cpp
@@ -2,8 +2,10 @@
#include "x86_64/cpu/registers.hpp"
-namespace teachos::x86_64::memory
+namespace teachos::memory::x86_64
{
+ namespace cpu = cpu::x86_64;
+
auto tlb_flush(linear_address address) -> void
{
asm volatile("invlpg (%[input])" : /* no output from call */ : [input] "r"(address) : "memory");
@@ -14,4 +16,4 @@ namespace teachos::x86_64::memory
auto current_value = cpu::read_control_register(cpu::control_register::cr3);
cpu::write_control_register(cpu::control_register::cr3, current_value);
}
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory::x86_64
diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/src/memory/region_allocator.cpp
index c9a98b4..91a5d49 100644
--- a/arch/x86_64/src/memory/region_allocator.cpp
+++ b/arch/x86_64/src/memory/region_allocator.cpp
@@ -1,22 +1,14 @@
-// #include "arch/memory/allocator/region_allocator.hpp"
-
-// #include "arch/exception_handling/assert.hpp"
-
-// #include <algorithm>
-// #include <array>
-// #include <ranges>
-
#include "x86_64/memory/region_allocator.hpp"
-#include "x86_64/memory/address.hpp"
-#include "x86_64/memory/frame.hpp"
+#include "kapi/memory/address.hpp"
+#include "kapi/memory/frame.hpp"
#include <multiboot2/information.hpp>
#include <algorithm>
#include <ranges>
-namespace teachos::x86_64::memory
+namespace teachos::memory::x86_64
{
namespace
{
@@ -92,4 +84,4 @@ namespace teachos::x86_64::memory
}
auto region_allocator::deallocate_frame(frame const &) -> void {}
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory::x86_64
diff --git a/arch/x86_64/src/vga/text.cpp b/arch/x86_64/src/vga/text.cpp
index af089fd..8f78ea9 100644
--- a/arch/x86_64/src/vga/text.cpp
+++ b/arch/x86_64/src/vga/text.cpp
@@ -9,8 +9,10 @@
#include <string_view>
#include <utility>
-namespace teachos::x86_64::vga::text
+namespace teachos::vga::x86_64::text
{
+ using boot::x86_64::vga_buffer_pointer;
+
namespace
{
auto constinit buffer_offset = std::ptrdiff_t{};
@@ -67,4 +69,4 @@ namespace teachos::x86_64::vga::text
newline();
}
-} // namespace teachos::x86_64::vga::text
+} // namespace teachos::vga::x86_64::text
diff --git a/kapi/include/kapi/memory.hpp b/kapi/include/kapi/memory.hpp
index 842a2fa..3ad5ac5 100644
--- a/kapi/include/kapi/memory.hpp
+++ b/kapi/include/kapi/memory.hpp
@@ -1,9 +1,12 @@
#ifndef TEACHOS_KAPI_MEMORY_HPP
#define TEACHOS_KAPI_MEMORY_HPP
+#include "kapi/memory/address.hpp" // IWYU pragma: export
+#include "kapi/memory/frame.hpp" // IWYU pragma: export
+
namespace teachos::memory
{
auto init() -> void;
-}
+} // namespace teachos::memory
#endif
diff --git a/arch/x86_64/include/x86_64/memory/address.hpp b/kapi/include/kapi/memory/address.hpp
index 20e9655..585807a 100644
--- a/arch/x86_64/include/x86_64/memory/address.hpp
+++ b/kapi/include/kapi/memory/address.hpp
@@ -1,12 +1,12 @@
-#ifndef TEACHOS_X86_64_MEMORY_ADDRESS_HPP
-#define TEACHOS_X86_64_MEMORY_ADDRESS_HPP
+#ifndef TEACHOS_KAPI_MEMORY_ADDRESS_HPP
+#define TEACHOS_KAPI_MEMORY_ADDRESS_HPP
#include <bit>
#include <compare>
#include <cstddef>
#include <cstdint>
-namespace teachos::x86_64::memory
+namespace teachos::memory
{
enum struct address_type : bool
@@ -42,6 +42,6 @@ namespace teachos::x86_64::memory
using linear_address = address<address_type::linear>;
using physical_address = address<address_type::physical>;
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory
#endif \ No newline at end of file
diff --git a/arch/x86_64/include/x86_64/memory/frame.hpp b/kapi/include/kapi/memory/frame.hpp
index 21565fd..1251e51 100644
--- a/arch/x86_64/include/x86_64/memory/frame.hpp
+++ b/kapi/include/kapi/memory/frame.hpp
@@ -1,33 +1,24 @@
-#ifndef TEACHOS_X86_64_MEMORY_FRAME_HPP
-#define TEACHOS_X86_64_MEMORY_FRAME_HPP
+#ifndef TEACHOS_KAPI_MEMORY_FRAME_HPP
+#define TEACHOS_KAPI_MEMORY_FRAME_HPP
-#include "x86_64/memory/address.hpp"
+#include "kapi/memory/address.hpp"
+#include <bit>
#include <compare>
#include <cstddef>
+#include <cstdint>
-namespace teachos::x86_64::memory
+namespace teachos::memory
{
- /**
- * @brief Specific physical frame containing helper functions to determine if a specific address is in that
- * physical frame or not.
- */
+
+ extern std::size_t const PLATFORM_FRAME_SIZE;
+
struct frame
{
- auto static inline constexpr DEFAULT_SIZE = std::size_t{4096}; ///< Default page size of x86_84 is always 4KiB.
-
- /**
- * @brief Defaulted constructor.
- */
constexpr frame() = default;
- /**
- * @brief Constructor.
- *
- * @param frame_number Index number that should be assigned to this physical frame.
- */
explicit constexpr frame(std::size_t number)
- : m_number(number)
+ : m_number{number}
{
}
@@ -39,7 +30,7 @@ namespace teachos::x86_64::memory
*/
auto constexpr static containing(physical_address address) noexcept -> frame
{
- return frame{address.raw() / DEFAULT_SIZE};
+ return frame{address.raw() / PLATFORM_FRAME_SIZE};
}
/**
@@ -49,13 +40,19 @@ namespace teachos::x86_64::memory
*/
auto constexpr start_address() const noexcept -> physical_address
{
- return physical_address{m_number * DEFAULT_SIZE};
+ return physical_address{m_number * PLATFORM_FRAME_SIZE};
}
- auto constexpr operator+(std::size_t offset) const noexcept -> frame { return frame{m_number + offset}; }
+ /**
+ * @brief Get the nth next frame.
+ *
+ * @param offset
+ * @return A new frame n frames after this one.
+ */
+ auto constexpr operator+(std::size_t n) const noexcept -> frame { return frame{m_number + n}; }
/**
- * @brief Post increment operator. Returns a copy of the value.
+ * @brief Increment this frame to refer to the next one, returning a copy.
*
* @return Copy of the incremented underlying frame number.
*/
@@ -66,7 +63,7 @@ namespace teachos::x86_64::memory
}
/**
- * @brief Pre increment operator. Returns a reference to the changed value.
+ * @brief Increment this frame to refer to the next one, returning a this frame.
*
* @return Reference to the incremented underlying frame number.
*/
@@ -77,19 +74,19 @@ namespace teachos::x86_64::memory
}
/**
- * @brief Defaulted equals operator.
+ * @brief Check if this frame refers to the same frame as @p other.
*/
auto constexpr operator==(frame const & other) const noexcept -> bool = default;
/**
- * @brief Defaulted three-way comparison operator.
+ * @brief Lexicographically compare this frame to @p other.
*/
auto constexpr operator<=>(frame const & other) const noexcept -> std::strong_ordering = default;
private:
- std::size_t m_number{}; ///< Index number of the current physical frame, used to distinguish it from other frames.
+ std::size_t m_number{};
};
-} // namespace teachos::x86_64::memory
+} // namespace teachos::memory
-#endif // TEACHOS_ARCH_X86_64_MEMORY_ALLOCATOR_frame_HPP
+#endif \ No newline at end of file
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!");
}