From 587edc0d9786aff3c7a4728ba941f6a993e59bdc Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 28 Apr 2022 00:48:04 +0200 Subject: [PATCH] fix up runtime for ppc64 BE ELFv2 + ensure it's used --- configure | 2 +- libraries/ghci/GHCi/InfoTable.hsc | 36 ++++++++++++------------------- m4/fptools.m4 | 2 +- rts/AdjustorAsm.S | 2 +- rts/StgCRun.c | 4 ++-- rts/StgCRunAsm.S | 2 +- rts/adjustor/NativeIA64.c | 2 +- rts/adjustor/NativePowerPC.c | 2 +- 8 files changed, 22 insertions(+), 30 deletions(-) diff --git a/configure b/configure index 8310e6f..eac1124 100755 --- a/configure +++ b/configure @@ -10508,7 +10508,7 @@ printf "%s\n" "no" >&6; } test -z "$2" || eval "$2=ArchPPC" ;; powerpc64) - test -z "$2" || eval "$2=\"ArchPPC_64 {ppc_64ABI = ELF_V1}\"" + test -z "$2" || eval "$2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" ;; powerpc64le) test -z "$2" || eval "$2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" diff --git a/libraries/ghci/GHCi/InfoTable.hsc b/libraries/ghci/GHCi/InfoTable.hsc index ad4eb4d..e4f1c0c 100644 --- a/libraries/ghci/GHCi/InfoTable.hsc +++ b/libraries/ghci/GHCi/InfoTable.hsc @@ -231,30 +231,22 @@ mkJumpToAddr' platform a = case platform of , fromIntegral w64 , fromIntegral (w64 `shiftR` 32) ] ArchPPC64 -> - -- We use the compiler's register r12 to read the function - -- descriptor and the linker's register r11 as a temporary - -- register to hold the function entry point. - -- In the medium code model the function descriptor - -- is located in the first two gigabytes, i.e. the address - -- of the function pointer is a non-negative 32 bit number. - -- 0x0EADBEEF stands for the address of the function pointer: - -- 0: 3d 80 0e ad lis r12,0x0EAD - -- 4: 61 8c be ef ori r12,r12,0xBEEF - -- 8: e9 6c 00 00 ld r11,0(r12) - -- c: e8 4c 00 08 ld r2,8(r12) - -- 10: 7d 69 03 a6 mtctr r11 - -- 14: e9 6c 00 10 ld r11,16(r12) - -- 18: 4e 80 04 20 bctr - let w32 = fromIntegral (funPtrToInt a) + -- The ABI requires r12 to point to the function's entry point. + -- We use the medium code model where code resides in the first + -- two gigabytes, so loading a non-negative32 bit address + -- with lis followed by ori is fine. + -- 0x0EADBEEF stands for the address: + -- 3D800EAD lis r12,0x0EAD + -- 618CBEEF ori r12,r12,0xBEEF + -- 7D8903A6 mtctr r12 + -- 4E800420 bctr + + let w32 = fromIntegral (funPtrToInt a) hi16 x = (x `shiftR` 16) .&. 0xFFFF lo16 x = x .&. 0xFFFF - in Right [ 0x3D800000 .|. hi16 w32, - 0x618C0000 .|. lo16 w32, - 0xE96C0000, - 0xE84C0008, - 0x7D6903A6, - 0xE96C0010, - 0x4E800420] + in Right [ 0x3D800000 .|. hi16 w32, + 0x618C0000 .|. lo16 w32, + 0x7D8903A6, 0x4E800420 ] ArchPPC64LE -> -- The ABI requires r12 to point to the function's entry point. diff --git a/m4/fptools.m4 b/m4/fptools.m4 index 8c6c9b7..eb25c37 100644 --- a/m4/fptools.m4 +++ b/m4/fptools.m4 @@ -201,7 +201,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS], test -z "[$]2" || eval "[$]2=ArchPPC" ;; powerpc64) - test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V1}\"" + test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" ;; powerpc64le) test -z "[$]2" || eval "[$]2=\"ArchPPC_64 {ppc_64ABI = ELF_V2}\"" diff --git a/rts/AdjustorAsm.S b/rts/AdjustorAsm.S index 2795b83..63cfe91 100644 --- a/rts/AdjustorAsm.S +++ b/rts/AdjustorAsm.S @@ -2,7 +2,7 @@ /* ******************************** PowerPC ******************************** */ -#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) +#if defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) #if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) /* The following code applies, with some differences, to all powerpc platforms except for powerpc32-linux, diff --git a/rts/StgCRun.c b/rts/StgCRun.c index f43227a..927d44a 100644 --- a/rts/StgCRun.c +++ b/rts/StgCRun.c @@ -724,7 +724,7 @@ StgRunIsImplementedInAssembler(void) Everything is in assembler, so we don't have to deal with GCC... -------------------------------------------------------------------------- */ -#if defined(powerpc64_HOST_ARCH) +#if defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2) /* 64-bit PowerPC ELF ABI 1.9 * * Stack frame organization (see Figure 3-17, ELF ABI 1.9, p 14) @@ -792,7 +792,7 @@ StgRunIsImplementedInAssembler(void) #endif -#if defined(powerpc64le_HOST_ARCH) +#if defined(powerpc64le_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF == 2)) /* ----------------------------------------------------------------------------- PowerPC 64 little endian architecture diff --git a/rts/StgCRunAsm.S b/rts/StgCRunAsm.S index 60f1bf9..c6794d7 100644 --- a/rts/StgCRunAsm.S +++ b/rts/StgCRunAsm.S @@ -5,7 +5,7 @@ * then functions StgRun/StgReturn are implemented in file StgCRun.c */ #if !defined(USE_MINIINTERPRETER) -#if defined(powerpc64le_HOST_ARCH) +#if defined(powerpc64le_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF == 2)) # if defined(linux_HOST_OS) /* 64-bit PowerPC ELF V2 ABI Revision 1.4 * diff --git a/rts/adjustor/NativeIA64.c b/rts/adjustor/NativeIA64.c index 9fd1991..816b3ef 100644 --- a/rts/adjustor/NativeIA64.c +++ b/rts/adjustor/NativeIA64.c @@ -39,7 +39,7 @@ void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr, char *typeString -#if !defined(powerpc_HOST_ARCH) && !defined(powerpc64_HOST_ARCH) && !defined(x86_64_HOST_ARCH) +#if !defined(powerpc_HOST_ARCH) && (!defined(powerpc64_HOST_ARCH) || (_CALL_ELF == 2)) && !defined(x86_64_HOST_ARCH) STG_UNUSED #endif ) diff --git a/rts/adjustor/NativePowerPC.c b/rts/adjustor/NativePowerPC.c index 2e5d605..caef5d3 100644 --- a/rts/adjustor/NativePowerPC.c +++ b/rts/adjustor/NativePowerPC.c @@ -29,7 +29,7 @@ __asm__("obscure_ccall_ret_code:\n\t" extern void obscure_ccall_ret_code(void); #endif /* defined(linux_HOST_OS) */ -#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) +#if defined(powerpc_HOST_ARCH) || (defined(powerpc64_HOST_ARCH) && (_CALL_ELF != 2)) #if !(defined(powerpc_HOST_ARCH) && defined(linux_HOST_OS)) /* !!! !!! WARNING: !!! !!! -- 2.35.1