]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Changed nullptr to be ~0 instead of 0 for phys_ptr<T> and fixed a missing line in...
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 26 May 2022 18:21:29 +0000 (20:21 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 26 May 2022 18:21:29 +0000 (20:21 +0200)
The goal is to allow usage of physical address 0. Removed the changing
of address <0x1000 to 0x1000 in the initial memory detection phase.

src/kernel.cpp
src/paging.cpp
src/phys_ptr.hpp

index 3ca6bd482f5aeaea216aaffb32e7771ff2ab8c06..cb01bc15aa4673e9cd12048288006f634470efce 100644 (file)
@@ -58,11 +58,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
                case multiboot2::info::type_t::memory_map:
                        for (std::size_t i = 0; i < multiboot2::memory_map_number_of_entries(it); i++) {
                                if (multiboot2::memory_map_type(it, i) == 1) {
-                                       const os::phys_ptr<os::paging::page> s{
-                                               multiboot2::memory_map_base_addr(it, i) < 0x1000
-                                                       ? 0x1000
-                                                       : (multiboot2::memory_map_base_addr(it, i) + 0x1000 - 1) / 0x1000 * 0x1000
-                                       };
+                                       const os::phys_ptr<os::paging::page> s{(multiboot2::memory_map_base_addr(it, i) + 0x1000 - 1) / 0x1000 * 0x1000};
                                        const os::phys_ptr<os::paging::page> e{multiboot2::memory_map_base_addr(it, i) + multiboot2::memory_map_length(it, i) / 0x1000 * 0x1000};
                                        if (s < e) {
                                                remove_some_mem(
index 7b96ef4d3a802a0ee9f794835f18a5968bbf669d..e73cfb2369b88375f229dffb6ae7476d79c9b9a8 100644 (file)
@@ -36,6 +36,7 @@ os::paging::page_allocator::block os::paging::page_allocator::allocate(std::uint
        return { .ptr = nullptr, .size = count };
 }
 void os::paging::page_allocator::deallocate(block b) {
+       if (b.ptr == nullptr) { return; }
        if (b.size == 0) { return; }
        const phys_ptr<page> b_it{b.ptr.get_phys_addr()};
        auto it = begin();
index 72ffc794e85335ea5d91433ed266b40fc0f6293c..256cd5d276d0aae4e62bb923be56973aa33ea49b 100644 (file)
@@ -9,7 +9,7 @@ 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 phys_ptr(std::nullptr_t): phys_addr(~0ull) {}
 
        T& operator[](std::size_t i) const {
                return get_virt_addr()[i];
@@ -64,7 +64,7 @@ public:
        friend constexpr auto operator<=>(phys_ptr<T> a, phys_ptr<T> b) = default;
 
 private:
-       T* get_virt_addr() const {
+       constexpr T* get_virt_addr() const {
                return reinterpret_cast<T*>(phys_addr + 0xFFFF800000000000);
        }