]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Made types a bit better
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 26 Mar 2023 02:24:29 +0000 (04:24 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 26 Mar 2023 02:24:29 +0000 (04:24 +0200)
kernel/src/elf64.cpp
kernel/src/elf64.hpp
kernel/src/kernel.cpp
kernel/src/lib/multiboot2.hpp

index 70d9e1a39e61e3cdf437f38718a9e9aeb8ef75b2..9f961061aa23287b2c6dd33962e5ef15d62d077d 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "elf64.hpp"
 
-os::process os::elf::load_elf(void* start, std::size_t length, const paging::PML4T& original_PML4T) {
+os::process os::elf::load_elf(std::byte* start, std::size_t length, const paging::PML4T& original_PML4T) {
        os::assert(length >= sizeof(os::elf::header), "Elf file isn't big enough to contain a header: there is an error.");
        // TODO: Check that the elf file sections are all fully inside the file.
 
@@ -44,7 +44,7 @@ os::process os::elf::load_elf(void* start, std::size_t length, const paging::PML
 
        for (std::size_t i = 0; i < elf_header.entry_count_program_header_table; i++) {
                const os::elf::program_header program_header = *(os::elf::program_header*)(
-                       reinterpret_cast<std::byte*>(start) + elf_header.program_header_table
+                       start + elf_header.program_header_table
                                + i * elf_header.entry_size_program_header_table
                );
                if (program_header.type != 1) { // Segment shouldn't be loaded.
@@ -61,7 +61,7 @@ os::process os::elf::load_elf(void* start, std::size_t length, const paging::PML
                for (std::size_t i = 0; i < nb_pages; i++) {
                        std::byte* const page =
                                os::paging::setup_page(*result.PML4T, program_header.p_vaddr + i * 0x1000, (program_header.flags & 2) >> 1, 1);
-                       memcpy(page, (std::byte*)start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul));
+                       memcpy(page, start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul));
                }
        }
 
index b3eaa123a3cd7a225a0943921301272a2aa3b761..7f348b832c3f2518b5e040cdf987374edbccedbf 100644 (file)
@@ -56,5 +56,5 @@ namespace os { namespace elf {
        };
        static_assert(sizeof(program_header) == 56);
 
-       process load_elf(void* start, std::size_t length, const paging::PML4T& original_PML4T);
+       process load_elf(std::byte* start, std::size_t length, const paging::PML4T& original_PML4T);
 } } // namespace os::elf
index a83504c975ee0bb06a8f4a482bf9b58560dcd338..e31457af3976ae81515b634a003e0fe376166a74 100644 (file)
@@ -77,10 +77,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_s
                                }
                                break;
                        case multiboot2::info::type_t::modules:
-                               os::print("{}->{}: {}\n", multiboot2::modules_mod_start(it) / 0x1000 * 0x1000, multiboot2::modules_mod_end(it) / 0x1000 * 0x1000, multiboot2::modules_string(it));
+                               os::print("{}->{}: {}\n", multiboot2::modules_mod_start(it), multiboot2::modules_mod_end(it), multiboot2::modules_string(it));
                                os::assert(test_module_process.PML4T == nullptr, "Multiple modules specified in the multiboot. This is unsupported.");
                                test_module_process =
-                                       os::elf::load_elf(&*os::phys_ptr<std::byte>(multiboot2::modules_mod_start(it)),
+                                       os::elf::load_elf((std::byte*)multiboot2::modules_mod_start(it),
                                                          multiboot2::modules_mod_end(it) - multiboot2::modules_mod_start(it),
                                                          PML4T);
                                break;
index 6a42639d9b703a6fd9823d407356611bf6d67825..bb196f45dc7eb20fa9ac08ea16f6facdf2dab3f6 100644 (file)
                return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 16]);
        }
 
-       inline std::uint32_t modules_mod_start(os::phys_ptr<const info> ptr) {
-               return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[0]);
+       inline os::phys_ptr<std::byte> modules_mod_start(os::phys_ptr<const info> ptr) {
+               return os::phys_ptr<std::byte>{*reinterpret_cast<const std::uint32_t*>(&ptr->rest[0])};
        }
-       inline std::uint32_t modules_mod_end(os::phys_ptr<const info> ptr) {
-               return *reinterpret_cast<const std::uint32_t*>(&ptr->rest[4]);
+       inline os::phys_ptr<std::byte> modules_mod_end(os::phys_ptr<const info> ptr) {
+               return os::phys_ptr<std::byte>{*reinterpret_cast<const std::uint32_t*>(&ptr->rest[4])};
        }
        inline const char* modules_string(os::phys_ptr<const info> ptr) {
                return reinterpret_cast<const char*>(&ptr->rest[8]);