[boot] Support non-page-aligned program sections in init

When the bootloader loads srv.init's program sections into memory, it
needed to page-align them if they weren't. srv.init's loader itself
handles this case, but the bootloader's did not.
This commit is contained in:
Justin C. Miller
2022-10-14 21:53:30 -07:00
parent b8323f7e0e
commit 516f4f1920

View File

@@ -101,19 +101,21 @@ load_program(
bootproto::program_section &section = sections[next_section++]; bootproto::program_section &section = sections[next_section++];
size_t page_count = memory::bytes_to_pages(seg.mem_size); uintptr_t virt_addr = seg.vaddr;
size_t mem_size = seg.mem_size;
if (seg.mem_size > seg.file_size) { // Page-align the section, which may require increasing the size
void *pages = g_alloc.allocate_pages(page_count, alloc_type::program, true); size_t prelude = virt_addr & 0xfff;
void *source = util::offset_pointer(data.pointer, seg.offset); mem_size += prelude;
g_alloc.copy(pages, source, seg.file_size); virt_addr &= ~0xfffull;
section.phys_addr = reinterpret_cast<uintptr_t>(pages);
} else {
section.phys_addr = program.base() + seg.offset;
}
section.virt_addr = seg.vaddr; size_t page_count = memory::bytes_to_pages(mem_size);
section.size = seg.mem_size; void *pages = g_alloc.allocate_pages(page_count, alloc_type::program, true);
void *source = util::offset_pointer(data.pointer, seg.offset);
g_alloc.copy(util::offset_pointer(pages, prelude), source, seg.file_size);
section.phys_addr = reinterpret_cast<uintptr_t>(pages);
section.virt_addr = virt_addr;
section.size = mem_size;
section.type = static_cast<bootproto::section_flags>(seg.flags); section.type = static_cast<bootproto::section_flags>(seg.flags);
} }