Index: head/sys/boot/common/self_reloc.c =================================================================== --- head/sys/boot/common/self_reloc.c (nonexistent) +++ head/sys/boot/common/self_reloc.c (revision 282727) @@ -0,0 +1,123 @@ +/*- + * Copyright (c) 2008-2010 Rui Paulo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#if defined(__aarch64__) +#define ElfW_Rel Elf64_Rela +#define ElfW_Dyn Elf64_Dyn +#define ELFW_R_TYPE ELF64_R_TYPE +#define ELF_RELA +#elif defined(__arm__) || defined(__i386__) +#define ElfW_Rel Elf32_Rel +#define ElfW_Dyn Elf32_Dyn +#define ELFW_R_TYPE ELF32_R_TYPE +#elif defined(__amd64__) +#define ElfW_Rel Elf64_Rel +#define ElfW_Dyn Elf64_Dyn +#define ELFW_R_TYPE ELF64_R_TYPE +#else +#error architecture not supported +#endif +#if defined(__aarch64__) +#define RELOC_TYPE_NONE R_AARCH64_NONE +#define RELOC_TYPE_RELATIVE R_AARCH64_RELATIVE +#elif defined(__amd64__) +#define RELOC_TYPE_NONE R_X86_64_NONE +#define RELOC_TYPE_RELATIVE R_X86_64_RELATIVE +#elif defined(__arm__) +#define RELOC_TYPE_NONE R_ARM_NONE +#define RELOC_TYPE_RELATIVE R_ARM_RELATIVE +#elif defined(__i386__) +#define RELOC_TYPE_NONE R_386_NONE +#define RELOC_TYPE_RELATIVE R_386_RELATIVE +#endif + +/* + * A simple elf relocator. + */ +void +self_reloc(Elf_Addr baseaddr, ElfW_Dyn *dynamic) +{ + Elf_Word relsz, relent; + Elf_Addr *newaddr; + ElfW_Rel *rel; + ElfW_Dyn *dynp; + + /* + * Find the relocation address, its size and the relocation entry. + */ + relsz = 0; + relent = 0; + for (dynp = dynamic; dynp->d_tag != DT_NULL; dynp++) { + switch (dynp->d_tag) { + case DT_REL: + case DT_RELA: + rel = (ElfW_Rel *)(dynp->d_un.d_ptr + baseaddr); + break; + case DT_RELSZ: + case DT_RELASZ: + relsz = dynp->d_un.d_val; + break; + case DT_RELENT: + case DT_RELAENT: + relent = dynp->d_un.d_val; + break; + default: + break; + } + } + + /* + * Perform the actual relocation. + */ + for (; relsz > 0; relsz -= relent) { + switch (ELFW_R_TYPE(rel->r_info)) { + case RELOC_TYPE_NONE: + /* No relocation needs be performed. */ + break; + + case RELOC_TYPE_RELATIVE: + /* Address relative to the base address. */ + newaddr = (Elf_Addr *)(rel->r_offset + baseaddr); + *newaddr += baseaddr; + /* Add the addend when the ABI uses them */ +#ifdef ELF_RELA + *newaddr += rel->r_addend; +#endif + break; + default: + /* XXX: do we need other relocations ? */ + break; + } + rel = (ElfW_Rel *) ((caddr_t) rel + relent); + } +} Property changes on: head/sys/boot/common/self_reloc.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/sys/boot/efi/boot1/Makefile =================================================================== --- head/sys/boot/efi/boot1/Makefile (revision 282726) +++ head/sys/boot/efi/boot1/Makefile (revision 282727) @@ -1,109 +1,109 @@ # $FreeBSD$ MAN= .include # In-tree GCC does not support __attribute__((ms_abi)). .if ${COMPILER_TYPE} != "gcc" MK_SSP= no PROG= loader.sym INTERNALPROG= # architecture-specific loader code -SRCS= boot1.c reloc.c start.S +SRCS= boot1.c self_reloc.c start.S CFLAGS+= -I. CFLAGS+= -I${.CURDIR}/../include CFLAGS+= -I${.CURDIR}/../include/${MACHINE} CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include CFLAGS+= -I${.CURDIR}/../../.. # Always add MI sources and REGULAR efi loader bits .PATH: ${.CURDIR}/../loader/arch/${MACHINE} .PATH: ${.CURDIR}/../loader .PATH: ${.CURDIR}/../../common CFLAGS+= -I${.CURDIR}/../../common FILES= boot1.efi boot1.efifat FILESMODE_boot1.efi= ${BINMODE} LDSCRIPT= ${.CURDIR}/../loader/arch/${MACHINE}/ldscript.${MACHINE} LDFLAGS= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared .if ${MACHINE_CPUARCH} == "aarch64" CFLAGS+= -msoft-float -mgeneral-regs-only .endif .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" CFLAGS+= -fPIC LDFLAGS+= -Wl,-znocombreloc .endif .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "i386" # # Add libstand for the runtime functions used by the compiler - for example # __aeabi_* (arm) or __divdi3 (i386). # DPADD+= ${LIBSTAND} LDADD+= -lstand .endif ${PROG}: ${LDSCRIPT} OBJCOPY?= objcopy OBJDUMP?= objdump .if ${MACHINE_CPUARCH} == "amd64" EFI_TARGET= efi-app-x86_64 .elif ${MACHINE_CPUARCH} == "i386" EFI_TARGET= efi-app-ia32 .else EFI_TARGET= binary .endif boot1.efi: loader.sym if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \ ${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \ exit 1; \ fi ${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel.dyn \ -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ --output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET} boot1.o: ${.CURDIR}/../../common/ufsread.c # The following inserts out objects into a template FAT file system # created by generate-fat.sh .include "${.CURDIR}/Makefile.fat" boot1.efifat: boot1.efi echo ${.OBJDIR} uudecode ${.CURDIR}/fat-${MACHINE}.tmpl.bz2.uu mv fat-${MACHINE}.tmpl.bz2 ${.TARGET}.bz2 bzip2 -f -d ${.TARGET}.bz2 dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc CLEANFILES= boot1.efi boot1.efifat .endif # ${COMPILER_TYPE} != "gcc" .include beforedepend ${OBJS}: machine CLEANFILES+= machine machine: ln -sf ${.CURDIR}/../../../${MACHINE}/include machine .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" beforedepend ${OBJS}: x86 CLEANFILES+= x86 x86: ln -sf ${.CURDIR}/../../../x86/include x86 .endif Index: head/sys/boot/efi/loader/reloc.c =================================================================== --- head/sys/boot/efi/loader/reloc.c (revision 282726) +++ head/sys/boot/efi/loader/reloc.c (nonexistent) @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2008-2010 Rui Paulo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#if defined(__aarch64__) -#define ElfW_Rel Elf64_Rela -#define ElfW_Dyn Elf64_Dyn -#define ELFW_R_TYPE ELF64_R_TYPE -#define ELF_RELA -#elif defined(__arm__) || defined(__i386__) -#define ElfW_Rel Elf32_Rel -#define ElfW_Dyn Elf32_Dyn -#define ELFW_R_TYPE ELF32_R_TYPE -#elif defined(__amd64__) -#define ElfW_Rel Elf64_Rel -#define ElfW_Dyn Elf64_Dyn -#define ELFW_R_TYPE ELF64_R_TYPE -#else -#error architecture not supported -#endif -#if defined(__aarch64__) -#define RELOC_TYPE_NONE R_AARCH64_NONE -#define RELOC_TYPE_RELATIVE R_AARCH64_RELATIVE -#elif defined(__amd64__) -#define RELOC_TYPE_NONE R_X86_64_NONE -#define RELOC_TYPE_RELATIVE R_X86_64_RELATIVE -#elif defined(__arm__) -#define RELOC_TYPE_NONE R_ARM_NONE -#define RELOC_TYPE_RELATIVE R_ARM_RELATIVE -#elif defined(__i386__) -#define RELOC_TYPE_NONE R_386_NONE -#define RELOC_TYPE_RELATIVE R_386_RELATIVE -#endif - -/* - * A simple relocator for EFI binaries. - */ -EFI_STATUS -_reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle, - EFI_SYSTEM_TABLE *system_table) -{ - unsigned long relsz, relent; - unsigned long *newaddr; - ElfW_Rel *rel; - ElfW_Dyn *dynp; - - /* - * Find the relocation address, its size and the relocation entry. - */ - relsz = 0; - relent = 0; - for (dynp = dynamic; dynp->d_tag != DT_NULL; dynp++) { - switch (dynp->d_tag) { - case DT_REL: - case DT_RELA: - rel = (ElfW_Rel *) ((unsigned long) dynp->d_un.d_ptr + - ImageBase); - break; - case DT_RELSZ: - case DT_RELASZ: - relsz = dynp->d_un.d_val; - break; - case DT_RELENT: - case DT_RELAENT: - relent = dynp->d_un.d_val; - break; - default: - break; - } - } - - /* - * Perform the actual relocation. - */ - for (; relsz > 0; relsz -= relent) { - switch (ELFW_R_TYPE(rel->r_info)) { - case RELOC_TYPE_NONE: - /* No relocation needs be performed. */ - break; - - case RELOC_TYPE_RELATIVE: - /* Address relative to the base address. */ - newaddr = (unsigned long *)(ImageBase + rel->r_offset); - *newaddr += ImageBase; - /* Add the addend when the ABI uses them */ -#ifdef ELF_RELA - *newaddr += rel->r_addend; -#endif - break; - default: - /* XXX: do we need other relocations ? */ - break; - } - rel = (ElfW_Rel *) ((caddr_t) rel + relent); - } - - return (EFI_SUCCESS); -} Property changes on: head/sys/boot/efi/loader/reloc.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: head/sys/boot/efi/loader/Makefile =================================================================== --- head/sys/boot/efi/loader/Makefile (revision 282726) +++ head/sys/boot/efi/loader/Makefile (revision 282727) @@ -1,133 +1,133 @@ # $FreeBSD$ MAN= .include # In-tree GCC does not support __attribute__((ms_abi)). .if ${COMPILER_TYPE} != "gcc" MK_SSP= no PROG= loader.sym INTERNALPROG= .PATH: ${.CURDIR}/../../efi/loader # architecture-specific loader code SRCS= autoload.c \ bootinfo.c \ conf.c \ copy.c \ devicename.c \ main.c \ - reloc.c \ + self_reloc.c \ smbios.c \ vers.c .PATH: ${.CURDIR}/arch/${MACHINE} # For smbios.c .PATH: ${.CURDIR}/../../i386/libi386 .include "${.CURDIR}/arch/${MACHINE}/Makefile.inc" CFLAGS+= -I${.CURDIR} CFLAGS+= -I${.CURDIR}/arch/${MACHINE} CFLAGS+= -I${.CURDIR}/../include CFLAGS+= -I${.CURDIR}/../include/${MACHINE} CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include CFLAGS+= -I${.CURDIR}/../../.. CFLAGS+= -I${.CURDIR}/../../i386/libi386 CFLAGS+= -DNO_PCI -DEFI # make buildenv doesn't set DESTDIR, this means LIBSTAND # will be wrong when crossbuilding. .if exists(${.OBJDIR}/../../../../lib/libstand/libstand.a) LIBSTAND= ${.OBJDIR}/../../../../lib/libstand/libstand.a .endif .if ${MK_FORTH} != "no" BOOT_FORTH= yes CFLAGS+= -DBOOT_FORTH CFLAGS+= -I${.CURDIR}/../../ficl CFLAGS+= -I${.CURDIR}/../../ficl/${MACHINE_CPUARCH} LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .endif LOADER_FDT_SUPPORT?= no .if ${MK_FDT} != "no" && ${LOADER_FDT_SUPPORT} != "no" CFLAGS+= -I${.CURDIR}/../../fdt CFLAGS+= -I${.OBJDIR}/../../fdt CFLAGS+= -DLOADER_FDT_SUPPORT LIBEFI_FDT= ${.OBJDIR}/../../efi/fdt/libefi_fdt.a LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a .endif # Include bcache code. HAVE_BCACHE= yes .if defined(EFI_STAGING_SIZE) CFLAGS+= -DEFI_STAGING_SIZE=${EFI_STAGING_SIZE} .endif # Always add MI sources .PATH: ${.CURDIR}/../../common .include "${.CURDIR}/../../common/Makefile.inc" CFLAGS+= -I${.CURDIR}/../../common FILES= loader.efi FILESMODE_loader.efi= ${BINMODE} LDSCRIPT= ${.CURDIR}/arch/${MACHINE}/ldscript.${MACHINE} LDFLAGS+= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared CLEANFILES= vers.c loader.efi NEWVERSWHAT= "EFI loader" ${MACHINE} vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../../efi/loader/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} OBJCOPY?= objcopy OBJDUMP?= objdump .if ${MACHINE_CPUARCH} == "amd64" EFI_TARGET= efi-app-x86_64 .elif ${MACHINE_CPUARCH} == "i386" EFI_TARGET= efi-app-ia32 .else EFI_TARGET= binary .endif loader.efi: loader.sym if [ `${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*' | wc -l` != 0 ]; then \ ${OBJDUMP} -t ${.ALLSRC} | fgrep '*UND*'; \ exit 1; \ fi ${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel.dyn \ -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ --output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET} LIBEFI= ${.OBJDIR}/../libefi/libefi.a DPADD= ${LIBFICL} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} ${LIBSTAND} \ ${LDSCRIPT} LDADD= ${LIBFICL} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} ${LIBSTAND} .endif # ${COMPILER_TYPE} != "gcc" .include beforedepend ${OBJS}: machine CLEANFILES+= machine machine: ln -sf ${.CURDIR}/../../../${MACHINE}/include machine .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" beforedepend ${OBJS}: x86 CLEANFILES+= x86 x86: ln -sf ${.CURDIR}/../../../x86/include x86 .endif Index: head/sys/boot/efi/loader/arch/amd64/start.S =================================================================== --- head/sys/boot/efi/loader/arch/amd64/start.S (revision 282726) +++ head/sys/boot/efi/loader/arch/amd64/start.S (revision 282727) @@ -1,76 +1,76 @@ /*- * Copyright (C) 1999 Hewlett-Packard Co. * Contributed by David Mosberger . * Copyright (C) 2005 Intel Co. * Contributed by Fenghua Yu . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Hewlett-Packard Co. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * crt0-efi-x86_64.S - x86_64 EFI startup code. * $FreeBSD$ */ .text .align 4 .globl _start _start: subq $8, %rsp pushq %rcx pushq %rdx 0: lea ImageBase(%rip), %rdi lea _DYNAMIC(%rip), %rsi popq %rcx popq %rdx pushq %rcx pushq %rdx - call _reloc + call self_reloc popq %rdi popq %rsi call efi_main addq $8, %rsp .exit: ret /* * hand-craft a dummy .reloc section so EFI knows it's a relocatable * executable: */ .data .section .reloc, "a" .long 0 .long 10 .word 0 Index: head/sys/boot/efi/loader/arch/arm/start.S =================================================================== --- head/sys/boot/efi/loader/arch/arm/start.S (revision 282726) +++ head/sys/boot/efi/loader/arch/arm/start.S (revision 282727) @@ -1,189 +1,189 @@ /*- * Copyright (c) 2014, 2015 Andrew Turner * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include /* * We need to be a PE32 file for EFI. On some architectures we can use * objcopy to create the correct file, however on arm we need to do * it ourselves. */ #define IMAGE_FILE_MACHINE_ARM 0x01c2 #define IMAGE_SCN_CNT_CODE 0x00000020 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 #define IMAGE_SCN_MEM_READ 0x40000000 .section .peheader efi_start: /* The MS-DOS Stub, only used to get the offset of the COFF header */ .ascii "MZ" .short 0 .space 0x38 .long pe_sig - efi_start /* The PE32 Signature. Needs to be 8-byte aligned */ .align 3 pe_sig: .ascii "PE" .short 0 coff_head: .short IMAGE_FILE_MACHINE_ARM /* ARM file */ .short 2 /* 2 Sections */ .long 0 /* Timestamp */ .long 0 /* No symbol table */ .long 0 /* No symbols */ .short section_table - optional_header /* Optional header size */ .short 0 /* Characteristics TODO: Fill in */ optional_header: .short 0x010b /* PE32 (32-bit addressing) */ .byte 0 /* Major linker version */ .byte 0 /* Minor linker version */ .long _edata - _end_header /* Code size */ .long 0 /* No initialized data */ .long 0 /* No uninitialized data */ .long _start - efi_start /* Entry point */ .long _end_header - efi_start /* Start of code */ .long 0 /* Start of data */ optional_windows_header: .long 0 /* Image base */ .long 32 /* Section Alignment */ .long 8 /* File alignment */ .short 0 /* Major OS version */ .short 0 /* Minor OS version */ .short 0 /* Major image version */ .short 0 /* Minor image version */ .short 0 /* Major subsystem version */ .short 0 /* Minor subsystem version */ .long 0 /* Win32 version */ .long _edata - efi_start /* Image size */ .long _end_header - efi_start /* Header size */ .long 0 /* Checksum */ .short 0xa /* Subsystem (EFI app) */ .short 0 /* DLL Characteristics */ .long 0 /* Stack reserve */ .long 0 /* Stack commit */ .long 0 /* Heap reserve */ .long 0 /* Heap commit */ .long 0 /* Loader flags */ .long 6 /* Number of RVAs */ /* RVAs: */ .quad 0 .quad 0 .quad 0 .quad 0 .quad 0 .quad 0 section_table: /* We need a .reloc section for EFI */ .ascii ".reloc" .byte 0 .byte 0 /* Pad to 8 bytes */ .long 0 /* Virtual size */ .long 0 /* Virtual address */ .long 0 /* Size of raw data */ .long 0 /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ IMAGE_SCN_MEM_DISCARDABLE) /* Characteristics */ /* The contents of the loader */ .ascii ".text" .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ .long _edata - _end_header /* Virtual size */ .long _end_header - efi_start /* Virtual address */ .long _edata - _end_header /* Size of raw data */ .long _end_header - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ IMAGE_SCN_MEM_READ) /* Characteristics */ _end_header: .text _start: /* Save the boot params to the stack */ push {r0, r1} adr r0, .Lbase ldr r1, [r0] sub r5, r0, r1 ldr r0, .Limagebase add r0, r0, r5 ldr r1, .Ldynamic add r1, r1, r5 - bl _C_LABEL(_reloc) + bl _C_LABEL(self_reloc) /* Zero the BSS, _reloc fixed the values for us */ ldr r0, .Lbss ldr r1, .Lbssend mov r2, #0 1: cmp r0, r1 bgt 2f str r2, [r0], #4 b 1b 2: pop {r0, r1} bl _C_LABEL(efi_main) 1: b 1b .Lbase: .word . .Limagebase: .word ImageBase .Ldynamic: .word _DYNAMIC .Lbss: .word __bss_start .Lbssend: .word __bss_end .align 3 stack: .space 512 stack_end: Index: head/sys/boot/efi/loader/arch/arm64/start.S =================================================================== --- head/sys/boot/efi/loader/arch/arm64/start.S (revision 282726) +++ head/sys/boot/efi/loader/arch/arm64/start.S (revision 282727) @@ -1,165 +1,165 @@ /*- * Copyright (c) 2014 Andrew Turner * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ /* * We need to be a PE32+ file for EFI. On some architectures we can use * objcopy to create the correct file, however on arm64 we need to do * it ourselves. */ #define IMAGE_FILE_MACHINE_ARM64 0xaa64 #define IMAGE_SCN_CNT_CODE 0x00000020 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 #define IMAGE_SCN_MEM_READ 0x40000000 .section .peheader efi_start: /* The MS-DOS Stub, only used to get the offset of the COFF header */ .ascii "MZ" .short 0 .space 0x38 .long pe_sig - efi_start /* The PE32 Signature. Needs to be 8-byte aligned */ .align 3 pe_sig: .ascii "PE" .short 0 coff_head: .short IMAGE_FILE_MACHINE_ARM64 /* AArch64 file */ .short 2 /* 2 Sections */ .long 0 /* Timestamp */ .long 0 /* No symbol table */ .long 0 /* No symbols */ .short section_table - optional_header /* Optional header size */ .short 0 /* Characteristics TODO: Fill in */ optional_header: .short 0x020b /* PE32+ (64-bit addressing) */ .byte 0 /* Major linker version */ .byte 0 /* Minor linker version */ .long _edata - _end_header /* Code size */ .long 0 /* No initialized data */ .long 0 /* No uninitialized data */ .long _start - efi_start /* Entry point */ .long _end_header - efi_start /* Start of code */ optional_windows_header: .quad 0 /* Image base */ .long 32 /* Section Alignment */ .long 8 /* File alignment */ .short 0 /* Major OS version */ .short 0 /* Minor OS version */ .short 0 /* Major image version */ .short 0 /* Minor image version */ .short 0 /* Major subsystem version */ .short 0 /* Minor subsystem version */ .long 0 /* Win32 version */ .long _edata - efi_start /* Image size */ .long _end_header - efi_start /* Header size */ .long 0 /* Checksum */ .short 0xa /* Subsystem (EFI app) */ .short 0 /* DLL Characteristics */ .quad 0 /* Stack reserve */ .quad 0 /* Stack commit */ .quad 0 /* Heap reserve */ .quad 0 /* Heap commit */ .long 0 /* Loader flags */ .long 6 /* Number of RVAs */ /* RVAs: */ .quad 0 .quad 0 .quad 0 .quad 0 .quad 0 .quad 0 section_table: /* We need a .reloc section for EFI */ .ascii ".reloc" .byte 0 .byte 0 /* Pad to 8 bytes */ .long 0 /* Virtual size */ .long 0 /* Virtual address */ .long 0 /* Size of raw data */ .long 0 /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ IMAGE_SCN_MEM_DISCARDABLE) /* Characteristics */ /* The contents of the loader */ .ascii ".text" .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ .long _edata - _end_header /* Virtual size */ .long _end_header - efi_start /* Virtual address */ .long _edata - _end_header /* Size of raw data */ .long _end_header - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ IMAGE_SCN_MEM_READ) /* Characteristics */ _end_header: .text .globl _start _start: /* Save the boot params to the stack */ stp x0, x1, [sp, #-16]! adr x0, __bss_start adr x1, __bss_end b 2f 1: stp xzr, xzr, [x0], #16 2: cmp x0, x1 b.lo 1b adr x0, ImageBase adr x1, _DYNAMIC - bl _reloc + bl self_reloc ldp x0, x1, [sp], #16 bl efi_main 1: b 1b Index: head/sys/boot/efi/loader/arch/i386/start.S =================================================================== --- head/sys/boot/efi/loader/arch/i386/start.S (revision 282726) +++ head/sys/boot/efi/loader/arch/i386/start.S (revision 282727) @@ -1,70 +1,70 @@ /*- * Copyright (c) 2008-2010 Rui Paulo * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ .text #include #define EFI_SUCCESS 0 /* * EFI entry point. * _start(EFI_IMAGE image_handle, EFI_SYSTEM_TABLE *system_table); * * We calculate the base address along with _DYNAMIC, relocate us and finally * pass control to efi_main. */ ENTRY(_start) pushl %ebp movl %esp, %ebp pushl 12(%ebp) /* image_handle */ pushl 8(%ebp) /* system_table */ call 0f 0: popl %eax movl %eax, %ebx addl $ImageBase-0b, %eax addl $_DYNAMIC-0b, %ebx pushl %ebx /* dynamic */ pushl %eax /* ImageBase */ - call _reloc + call self_reloc cmpl $EFI_SUCCESS, %eax jne 1f popl %ebx /* remove ImageBase from the stack */ popl %ebx /* remove dynamic from the stack */ call efi_main 1: leave ret END(_start) .data .section .reloc, "a" .long 0 .long 10 .word 0