]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added operator- to phys_ptr<T>s, which allowed for simplifying a bit of the code
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Mon, 9 May 2022 09:29:54 +0000 (11:29 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Mon, 9 May 2022 09:29:54 +0000 (11:29 +0200)
src/kernel.cpp
src/utils.hpp

index 32ec362d27b4b8e524df9a588f772af2d1373dc3..9512d14a690bec730524011362899ce538e20795 100644 (file)
@@ -91,7 +91,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
                                                        remove_some_mem(
                                                        s, e, info_start, info_end,
                                                        [] (auto s, auto e) {
-                                                               page_allocator.deallocate({.ptr = s, .size = (e.get_phys_addr() - s.get_phys_addr()) / 0x1000});
+                                                               page_allocator.deallocate({.ptr = s, .size = std::uint64_t(e - s)});
                                                        }
                                                        );
                                                }
@@ -114,10 +114,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
 
        // Deallocate multiboot info structure: not usable anymore.
        if (info_pages_wholly_usable) {
-               page_allocator.deallocate({.ptr = info_start, .size = (info_end.get_phys_addr() - info_start.get_phys_addr()) / 0x1000});
+               page_allocator.deallocate({.ptr = info_start, .size = std::uint64_t(info_end - info_start)});
        } else if (info_start + 1 < info_end - 1) {
                // Ignore the first and last blocks: ensures all the RAM is truly usable.
-               page_allocator.deallocate({.ptr = info_start + 1, .size = (info_end.get_phys_addr() - info_start.get_phys_addr()) / 0x1000 - 2});
+               page_allocator.deallocate({.ptr = info_start + 1, .size = std::uint64_t(info_end - info_start - 2)});
        }
 
        os::print("RAM:\n");
index 2f1ae158b09e75ac9bc505f98a5107efc922f775..5210817199889d5cfa49740d81d4cb631cdc9322 100644 (file)
@@ -59,6 +59,9 @@ namespace os {
                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;