From 5c2425a61e38d8fda5011d1e34519fb51fe2952a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 22 Apr 2015 02:40:05 +0200 Subject: [PATCH] PPC: fix COFF bootloader entry point The concept of entry point in COFF is actually different than in ELF. In COFF, the entry point is actually a "descriptor" (pointer) to the actual start code. So we patch the entry point address when calling objcopy. Now my old Performa 5400/180 actually starts the loader correctly \o/ --- src/system/boot/Jamfile | 8 +++++++- src/system/boot/platform/openfirmware/start.cpp | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 4070d0ef75..e751743336 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -93,8 +93,14 @@ rule BuildCoffLoader { actions BuildCoffLoader bind HACK_COFF { rm -f $(1) - $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) $(2) $(1) + # get the address of the COFF entry + $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O symbolsrec $(2) $(2).syms + EP=`grep _coff_start $(2).syms | tr -d '\r' | cut -d'$' -f2` + rm -f $(2).syms + # copy to XCOFF format and patch the entry point + $(TARGET_OBJCOPY_$(TARGET_PACKAGING_ARCH)) -O $(COFF_FORMAT) --set-start="0x${EP}" $(2) $(1) #$(CP) $(2) $(1) + # fill-in some fields objcopy missed $(HACK_COFF) $(1) } diff --git a/src/system/boot/platform/openfirmware/start.cpp b/src/system/boot/platform/openfirmware/start.cpp index de6dce172f..2938db2373 100644 --- a/src/system/boot/platform/openfirmware/start.cpp +++ b/src/system/boot/platform/openfirmware/start.cpp @@ -27,6 +27,10 @@ extern "C" void _start(uint32 _unused1, uint32 _unused2, void *openFirmwareEntry); extern "C" void start(void *openFirmwareEntry); +// XCOFF "entry-point" is actually a pointer to the real code +extern "C" void *_coff_start; +void *_coff_start = (void *)&_start; + // GCC defined globals extern void (*__ctor_list)(void); extern void (*__ctor_end)(void);