[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:
@@ -101,19 +101,21 @@ load_program(
|
|||||||
|
|
||||||
bootproto::program_section §ion = sections[next_section++];
|
bootproto::program_section §ion = 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
|
||||||
|
size_t prelude = virt_addr & 0xfff;
|
||||||
|
mem_size += prelude;
|
||||||
|
virt_addr &= ~0xfffull;
|
||||||
|
|
||||||
|
size_t page_count = memory::bytes_to_pages(mem_size);
|
||||||
void *pages = g_alloc.allocate_pages(page_count, alloc_type::program, true);
|
void *pages = g_alloc.allocate_pages(page_count, alloc_type::program, true);
|
||||||
void *source = util::offset_pointer(data.pointer, seg.offset);
|
void *source = util::offset_pointer(data.pointer, seg.offset);
|
||||||
g_alloc.copy(pages, source, seg.file_size);
|
g_alloc.copy(util::offset_pointer(pages, prelude), source, seg.file_size);
|
||||||
section.phys_addr = reinterpret_cast<uintptr_t>(pages);
|
section.phys_addr = reinterpret_cast<uintptr_t>(pages);
|
||||||
} else {
|
section.virt_addr = virt_addr;
|
||||||
section.phys_addr = program.base() + seg.offset;
|
section.size = mem_size;
|
||||||
}
|
|
||||||
|
|
||||||
section.virt_addr = seg.vaddr;
|
|
||||||
section.size = seg.mem_size;
|
|
||||||
section.type = static_cast<bootproto::section_flags>(seg.flags);
|
section.type = static_cast<bootproto::section_flags>(seg.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user