diff options
Diffstat (limited to 'sys/boot/common/load_elf.c')
-rw-r--r-- | sys/boot/common/load_elf.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/sys/boot/common/load_elf.c b/sys/boot/common/load_elf.c index f0880b1..ee6389f 100644 --- a/sys/boot/common/load_elf.c +++ b/sys/boot/common/load_elf.c @@ -97,7 +97,6 @@ __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result) struct elf_file ef; Elf_Ehdr *ehdr; int err; - u_int pad; ssize_t bytes_read; fp = NULL; @@ -157,12 +156,6 @@ __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result) /* Looks OK, got ahead */ ef.kernel = 0; - /* Page-align the load address */ - pad = (u_int)dest & PAGE_MASK; - if (pad != 0) { - pad = PAGE_SIZE - pad; - dest += pad; - } } else if (ehdr->e_type == ET_EXEC) { /* Looks like a kernel */ if (kfp != NULL) { @@ -173,7 +166,7 @@ __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result) /* * Calculate destination address based on kernel entrypoint */ - dest = ehdr->e_entry; + dest = (ehdr->e_entry & ~PAGE_MASK); if (dest == 0) { printf("elf" __XSTRING(__ELF_WORD_SIZE) "_loadfile: not a kernel (maybe static binary?)\n"); err = EPERM; @@ -186,6 +179,11 @@ __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result) goto oerr; } + if (archsw.arch_loadaddr != NULL) + dest = archsw.arch_loadaddr(LOAD_ELF, ehdr, dest); + else + dest = roundup(dest, PAGE_SIZE); + /* * Ok, we think we should handle this. */ @@ -202,7 +200,7 @@ __elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result) #ifdef ELF_VERBOSE if (ef.kernel) - printf("%s entry at 0x%jx\n", filename, (uintmax_t)dest); + printf("%s entry at 0x%jx\n", filename, (uintmax_t)ehdr->e_entry); #else printf("%s ", filename); #endif @@ -362,6 +360,9 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) printf("\n"); #endif + if (archsw.arch_loadseg != NULL) + archsw.arch_loadseg(ehdr, phdr + i, off); + if (firstaddr == 0 || firstaddr > (phdr[i].p_vaddr + off)) firstaddr = phdr[i].p_vaddr + off; if (lastaddr == 0 || lastaddr < (phdr[i].p_vaddr + off + phdr[i].p_memsz)) |