From a30e3c6bebd08254c7ef869561f9d6d20cdea2c0 Mon Sep 17 00:00:00 2001 From: Amelia Coutard <eliottulio.coutard@gmail.com> Date: Thu, 12 May 2022 13:20:38 +0200 Subject: [PATCH] Refactored phys_ptr and fixed little errors --- src/phys_ptr.hpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/phys_ptr.hpp b/src/phys_ptr.hpp index 1e5cb35..5fe43be 100644 --- a/src/phys_ptr.hpp +++ b/src/phys_ptr.hpp @@ -23,33 +23,28 @@ public: } constexpr phys_ptr<T>& operator++() { - phys_addr += sizeof(T); + return *this += 1; } - constexpr phys_ptr<T>& operator++(int) { + constexpr phys_ptr<T> operator++(int) { const auto old = *this; operator++(); return old; } constexpr phys_ptr<T>& operator--() { - phys_addr -= sizeof(T); + return *this -= 1; } - constexpr phys_ptr<T>& operator--(int) { + 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; + return *this = *this + offset; } constexpr phys_ptr<T>& operator-=(std::ptrdiff_t offset) { - phys_addr -= offset * sizeof(T); - return *this; + return *this = *this - offset; } - 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)}; } @@ -67,6 +62,8 @@ public: return phys_addr; } + friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) = default; + private: T* get_virt_addr() const { return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000); -- 2.46.0