svn commit: r281237 - in head/sys/boot/efi: boot1 loader loader/arch/amd64 loader/arch/arm
Ed Maste
emaste at FreeBSD.org
Tue Apr 7 21:34:50 UTC 2015
Author: emaste
Date: Tue Apr 7 21:34:49 2015
New Revision: 281237
URL: https://svnweb.freebsd.org/changeset/base/281237
Log:
EFI: use common reloc.c for all architectures
Much of this file is common to the architectures we support, so share
an implementation by adding a little #ifdef-ery.
Differential Revision: https://reviews.freebsd.org/D2241
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
Added:
head/sys/boot/efi/loader/reloc.c
- copied, changed from r281235, head/sys/boot/efi/loader/arch/amd64/reloc.c
Deleted:
head/sys/boot/efi/loader/arch/amd64/reloc.c
head/sys/boot/efi/loader/arch/arm/reloc.c
Modified:
head/sys/boot/efi/boot1/Makefile
Modified: head/sys/boot/efi/boot1/Makefile
==============================================================================
--- head/sys/boot/efi/boot1/Makefile Tue Apr 7 21:31:17 2015 (r281236)
+++ head/sys/boot/efi/boot1/Makefile Tue Apr 7 21:34:49 2015 (r281237)
@@ -23,7 +23,9 @@ CFLAGS+= -I${.CURDIR}/../../../contrib/d
CFLAGS+= -I${.CURDIR}/../../..
# Always add MI sources and REGULAR efi loader bits
-.PATH: ${.CURDIR}/../loader/arch/${MACHINE_CPUARCH} ${.CURDIR}/../../common
+.PATH: ${.CURDIR}/../loader/arch/${MACHINE_CPUARCH}
+.PATH: ${.CURDIR}/../loader
+.PATH: ${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../common
FILES= boot1.efi boot1.efifat
Copied and modified: head/sys/boot/efi/loader/reloc.c (from r281235, head/sys/boot/efi/loader/arch/amd64/reloc.c)
==============================================================================
--- head/sys/boot/efi/loader/arch/amd64/reloc.c Tue Apr 7 21:05:52 2015 (r281235, copy source)
+++ head/sys/boot/efi/loader/reloc.c Tue Apr 7 21:34:49 2015 (r281237)
@@ -32,18 +32,30 @@ __FBSDID("$FreeBSD$");
#include <efi.h>
#include <bootstrap.h>
-#ifdef __i386__
+#if defined(__arm__) || defined(__i386__)
#define ElfW_Rel Elf32_Rel
#define ElfW_Dyn Elf32_Dyn
#define ELFW_R_TYPE ELF32_R_TYPE
-#elif __amd64__
+#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(__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 IA32/AMD64 EFI binaries.
+ * A simple relocator for EFI binaries.
*/
EFI_STATUS
_reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle,
@@ -81,17 +93,14 @@ _reloc(unsigned long ImageBase, ElfW_Dyn
/*
* Perform the actual relocation.
- * XXX: We are reusing code for the amd64 version of this, but
- * we must make sure the relocation types are the same.
*/
- CTASSERT(R_386_NONE == R_X86_64_NONE);
- CTASSERT(R_386_RELATIVE == R_X86_64_RELATIVE);
for (; relsz > 0; relsz -= relent) {
switch (ELFW_R_TYPE(rel->r_info)) {
- case R_386_NONE:
+ case RELOC_TYPE_NONE:
/* No relocation needs be performed. */
break;
- case R_386_RELATIVE:
+
+ case RELOC_TYPE_RELATIVE:
/* Address relative to the base address. */
newaddr = (unsigned long *)(ImageBase + rel->r_offset);
*newaddr += ImageBase;
More information about the svn-src-head
mailing list