Skip to content

Commit

Permalink
EFI: use common reloc.c for all architectures
Browse files Browse the repository at this point in the history
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
  • Loading branch information
emaste committed Apr 7, 2015
1 parent 363cef7 commit 0b81f9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 93 deletions.
4 changes: 3 additions & 1 deletion sys/boot/efi/boot1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include
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
Expand Down
83 changes: 0 additions & 83 deletions sys/boot/efi/loader/arch/arm/reloc.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -81,17 +93,14 @@ _reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle,

/*
* 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;
Expand Down

0 comments on commit 0b81f9c

Please sign in to comment.