From b931a53849b55b87dce592dbeebecee14f8463a1 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Tue, 1 Dec 2015 17:01:27 +0000 Subject: [PATCH] Allow loader to load 64-bit ELFv2 PowerPC kernels. --- sys/boot/ofw/libofw/ppc64_elf_freebsd.c | 7 +++++-- sys/boot/powerpc/kboot/ppc64_elf_freebsd.c | 9 +++++++-- sys/boot/powerpc/ps3/ppc64_elf_freebsd.c | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sys/boot/ofw/libofw/ppc64_elf_freebsd.c b/sys/boot/ofw/libofw/ppc64_elf_freebsd.c index f85a77acbf8b..b411da491222 100644 --- a/sys/boot/ofw/libofw/ppc64_elf_freebsd.c +++ b/sys/boot/ofw/libofw/ppc64_elf_freebsd.c @@ -77,8 +77,11 @@ ppc64_ofw_elf_exec(struct preloaded_file *fp) } e = (Elf_Ehdr *)&fmp->md_data; - /* Handle function descriptor */ - entry = *(uint64_t *)e->e_entry; + /* Handle function descriptor for ELFv1 kernels */ + if ((e->e_flags & 3) == 2) + entry = e->e_entry; + else + entry = *(uint64_t *)e->e_entry; if ((error = md_load64(fp->f_args, &mdp, &dtbp)) != 0) return (error); diff --git a/sys/boot/powerpc/kboot/ppc64_elf_freebsd.c b/sys/boot/powerpc/kboot/ppc64_elf_freebsd.c index 3ee5e78507eb..22fa7b576775 100644 --- a/sys/boot/powerpc/kboot/ppc64_elf_freebsd.c +++ b/sys/boot/powerpc/kboot/ppc64_elf_freebsd.c @@ -78,10 +78,15 @@ ppc64_elf_exec(struct preloaded_file *fp) /* Figure out where to put it */ trampolinebase = archsw.arch_loadaddr(LOAD_RAW, NULL, 0); - /* Set up interesting values in function descriptor */ + /* Set up loader trampoline */ trampoline = malloc(szkerneltramp); memcpy(trampoline, &kerneltramp, szkerneltramp); - archsw.arch_copyout(e->e_entry + elf64_relocation_offset, &entry, 8); + /* Parse function descriptor for ELFv1 kernels */ + if ((e->e_flags & 3) == 2) + entry = e->e_entry; + else + archsw.arch_copyout(e->e_entry + elf64_relocation_offset, + &entry, 8); trampoline[2] = entry + elf64_relocation_offset; trampoline[4] = 0; /* Phys. mem offset */ trampoline[5] = 0; /* OF entry point */ diff --git a/sys/boot/powerpc/ps3/ppc64_elf_freebsd.c b/sys/boot/powerpc/ps3/ppc64_elf_freebsd.c index 2892448f1204..3eb991e10ae9 100644 --- a/sys/boot/powerpc/ps3/ppc64_elf_freebsd.c +++ b/sys/boot/powerpc/ps3/ppc64_elf_freebsd.c @@ -75,8 +75,11 @@ ppc64_elf_exec(struct preloaded_file *fp) } e = (Elf_Ehdr *)&fmp->md_data; - /* Handle function descriptor */ - entry = (void *)(uintptr_t)(*(uint64_t *)e->e_entry); + /* Handle function descriptor for ELFv1 kernels */ + if ((e->e_flags & 3) == 2) + entry = e->e_entry; + else + entry = (void *)(uintptr_t)(*(uint64_t *)e->e_entry); if ((error = md_load64(fp->f_args, &mdp)) != 0) return (error);