#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.
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.
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));
}
}
};
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
}
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;
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]);