#include "serial.hpp"
+#include "utils.hpp"
#include "fb.hpp"
os::color os::operator*(color c1, color c2) {
#pragma once
#include <cstdint>
-#include "utils.hpp"
+#include "phys_ptr.hpp"
namespace os {
#ifdef __cplusplus
# include <cstdint>
-# include "utils.hpp"
+# include "phys_ptr.hpp"
namespace multiboot2 {
#endif // __cplusplus
#include <cstdint>
#include "serial.hpp"
#include "utils.hpp"
+#include "phys_ptr.hpp"
namespace os { namespace paging {
--- /dev/null
+#pragma once
+
+#include <cstdint>
+#include <cstddef>
+#include <compare>
+
+namespace os {
+
+template <typename T>
+class phys_ptr {
+public:
+ constexpr explicit phys_ptr(std::uintptr_t phys_addr): phys_addr(phys_addr) {}
+ constexpr phys_ptr(std::nullptr_t): phys_addr(0) {}
+
+ constexpr T& operator[](std::size_t i) const {
+ return get_virt_addr()[i];
+ }
+ constexpr T& operator*() const {
+ return *get_virt_addr();
+ }
+ constexpr T* operator->() const {
+ return get_virt_addr();
+ }
+
+ constexpr phys_ptr<T>& operator++() {
+ phys_addr += sizeof(T);
+ }
+ constexpr phys_ptr<T>& operator++(int) {
+ const auto old = *this;
+ operator++();
+ return old;
+ }
+ constexpr phys_ptr<T>& operator--() {
+ phys_addr -= sizeof(T);
+ }
+ constexpr phys_ptr<T>& operator--(int) {
+ const auto old = *this;
+ operator--();
+ return old;
+ }
+ constexpr phys_ptr<T>& operator+=(std::ptrdiff_t offset) {
+ phys_addr += offset * sizeof(T);
+ return *this;
+ }
+ constexpr phys_ptr<T>& operator-=(std::ptrdiff_t offset) {
+ phys_addr -= offset * sizeof(T);
+ return *this;
+ }
+
+ friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) { return a.phys_addr <=> b.phys_addr; }
+ friend constexpr auto operator== (phys_ptr<T> a, phys_ptr<T> b) { return a.phys_addr == b.phys_addr; }
+
+ friend constexpr phys_ptr<T> operator+(phys_ptr<T> ptr, std::ptrdiff_t offset) {
+ return phys_ptr<T>{ptr.phys_addr + offset * sizeof(T)};
+ }
+ friend constexpr phys_ptr<T> operator+(std::ptrdiff_t offset, phys_ptr<T> ptr) {
+ return ptr + offset;
+ }
+ friend constexpr phys_ptr<T> operator-(phys_ptr<T> ptr, std::ptrdiff_t offset) {
+ return phys_ptr<T>{ptr.phys_addr - offset * sizeof(T)};
+ }
+ friend constexpr std::ptrdiff_t operator-(phys_ptr<T> a, phys_ptr<T> b) {
+ return (a.phys_addr - b.phys_addr) / sizeof(T);
+ }
+
+ constexpr std::uintptr_t get_phys_addr() const {
+ return phys_addr;
+ }
+
+private:
+ constexpr T* get_virt_addr() const {
+ return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000);
+ }
+
+ std::uintptr_t phys_addr;
+};
+
+} // namespace os
#pragma once
-#include <cstddef>
-#include <cstdint>
-#include <compare>
-
namespace os {
- template <typename T>
- class phys_ptr {
- public:
- constexpr explicit phys_ptr(std::uintptr_t phys_addr): phys_addr(phys_addr) {}
- constexpr phys_ptr(std::nullptr_t): phys_addr(0) {}
-
- constexpr T& operator[](std::size_t i) const {
- return get_virt_addr()[i];
- }
- constexpr T& operator*() const {
- return *get_virt_addr();
- }
- constexpr T* operator->() const {
- return get_virt_addr();
- }
-
- constexpr phys_ptr<T>& operator++() {
- phys_addr += sizeof(T);
- }
- constexpr phys_ptr<T>& operator++(int) {
- const auto old = *this;
- operator++();
- return old;
- }
- constexpr phys_ptr<T>& operator--() {
- phys_addr -= sizeof(T);
- }
- constexpr phys_ptr<T>& operator--(int) {
- const auto old = *this;
- operator--();
- return old;
- }
- constexpr phys_ptr<T>& operator+=(std::ptrdiff_t offset) {
- phys_addr += offset * sizeof(T);
- return *this;
- }
- constexpr phys_ptr<T>& operator-=(std::ptrdiff_t offset) {
- phys_addr -= offset * sizeof(T);
- return *this;
- }
-
- friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) { return a.phys_addr <=> b.phys_addr; }
- friend constexpr auto operator== (phys_ptr<T> a, phys_ptr<T> b) { return a.phys_addr == b.phys_addr; }
-
- friend constexpr phys_ptr<T> operator+(phys_ptr<T> ptr, std::ptrdiff_t offset) {
- return phys_ptr<T>{ptr.phys_addr + offset * sizeof(T)};
- }
- friend constexpr phys_ptr<T> operator+(std::ptrdiff_t offset, phys_ptr<T> ptr) {
- return ptr + offset;
- }
- friend constexpr phys_ptr<T> operator-(phys_ptr<T> ptr, std::ptrdiff_t offset) {
- return phys_ptr<T>{ptr.phys_addr - offset * sizeof(T)};
- }
- friend constexpr std::ptrdiff_t operator-(phys_ptr<T> a, phys_ptr<T> b) {
- return (a.phys_addr - b.phys_addr) / sizeof(T);
- }
-
- constexpr std::uintptr_t get_phys_addr() const {
- return phys_addr;
- }
-
- private:
- constexpr T* get_virt_addr() const {
- return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000);
- }
-
- std::uintptr_t phys_addr;
- };
+void halt();
- void halt();
} // namespace os