From: Amelia Coutard Date: Thu, 26 May 2022 18:21:29 +0000 (+0200) Subject: Changed nullptr to be ~0 instead of 0 for phys_ptr and fixed a missing line in... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=694848ebcd51f2a60acbe5f4deab1292f3cac092;p=voyage-au-centre-des-fichiers.git Changed nullptr to be ~0 instead of 0 for phys_ptr and fixed a missing line in page_allocator The goal is to allow usage of physical address 0. Removed the changing of address <0x1000 to 0x1000 in the initial memory detection phase. --- diff --git a/src/kernel.cpp b/src/kernel.cpp index 3ca6bd4..cb01bc1 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -58,11 +58,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr 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 s{(multiboot2::memory_map_base_addr(it, i) + 0x1000 - 1) / 0x1000 * 0x1000}; const os::phys_ptr e{multiboot2::memory_map_base_addr(it, i) + multiboot2::memory_map_length(it, i) / 0x1000 * 0x1000}; if (s < e) { remove_some_mem( diff --git a/src/paging.cpp b/src/paging.cpp index 7b96ef4..e73cfb2 100644 --- a/src/paging.cpp +++ b/src/paging.cpp @@ -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 b_it{b.ptr.get_phys_addr()}; auto it = begin(); diff --git a/src/phys_ptr.hpp b/src/phys_ptr.hpp index 72ffc79..256cd5d 100644 --- a/src/phys_ptr.hpp +++ b/src/phys_ptr.hpp @@ -9,7 +9,7 @@ template 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 a, phys_ptr b) = default; private: - T* get_virt_addr() const { + constexpr T* get_virt_addr() const { return reinterpret_cast(phys_addr + 0xFFFF800000000000); }