From: Amelia Coutard Date: Sun, 8 May 2022 22:48:36 +0000 (+0200) Subject: Changed the rounding of usable RAM addresses and the freeing of the multiboot2 info... X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=617e23517d703ea2151f9846006c5e126fc4eed3;p=voyage-au-centre-des-fichiers.git Changed the rounding of usable RAM addresses and the freeing of the multiboot2 info struct to avoid accidentally marking unusable RAM as usable --- diff --git a/src/kernel.cpp b/src/kernel.cpp index 5799f46..32ec362 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -49,8 +49,9 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr info_start{info.get_phys_addr()}; - const os::phys_ptr info_end = info_start + (info->total_size - 1 + 0x1000) / 0x1000; // Number of pages taken, rounded up + const os::phys_ptr info_start{info.get_phys_addr() / 0x1000 * 0x1000}; // Round start down. + const os::phys_ptr info_end{(info.get_phys_addr() + info->total_size + 0x1000 - 1) / 0x1000 * 0x1000}; // Round end up. + bool info_pages_wholly_usable = false; os::framebuffer framebuffer; @@ -59,6 +60,11 @@ extern "C" void kmain(unsigned long magic, os::phys_ptrtype != multiboot2::info::type_t::end; it = multiboot2::next(it)) { switch (it->type) { case multiboot2::info::type_t::framebuffer_info: + os::print("Framebuffer:\n"); + os::print(multiboot2::framebuffer_addr(it)); + os::print("->"); + os::print(multiboot2::framebuffer_addr(it) + multiboot2::framebuffer_pitch(it) * multiboot2::framebuffer_height(it)); + os::printc('\n'); framebuffer = os::framebuffer( multiboot2::framebuffer_addr(it), multiboot2::framebuffer_pitch(it), @@ -70,19 +76,14 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr"); - os::print(multiboot2::memory_map_base_addr(it, i) + multiboot2::memory_map_length(it, i)); - os::printc(':'); - os::printc('0' + multiboot2::memory_map_type(it, i)); - os::printc('\n'); if (multiboot2::memory_map_type(it, i) == 1) { - const os::phys_ptr s{multiboot2::memory_map_base_addr(it, i) == 0 ? 0x1000 : multiboot2::memory_map_base_addr(it, i)}; + const 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 e{multiboot2::memory_map_base_addr(it, i) + multiboot2::memory_map_length(it, i) / 0x1000 * 0x1000}; - if (s == nullptr) { - } if (s < e) { remove_some_mem( s, e, kernel_start, kernel_end, @@ -96,6 +97,14 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr