From edd359716c2096274e656d26ed8945d99afc2da5 Mon Sep 17 00:00:00 2001 From: Vikas Gupta <93921236+vikasgupta8@users.noreply.github.com> Date: Mon, 20 Jun 2022 17:58:47 +0530 Subject: [PATCH] Upstream coreclr and pal changes to support powerpc (ppc64le) architecture (#69105) * coreclr pal layer chanegs. * Updated the system arch for power architecture. * Fixed the failing PAL SXS exception_handling test case * replaced gint with gint64 to avoid overflow and this has fixed the segmentation fault issue. * coreclr pal layer chanegs. * Fixed the failing PAL SXS exception_handling test case * coreclr pal layer chanegs. * Updated the system arch for power architecture. * Fixed the failing PAL SXS exception_handling test case * replaced gint with gint64 to avoid overflow and this has fixed the segmentation fault issue. * coreclr pal layer chanegs. * Fixed the failing PAL SXS exception_handling test case * Removing intsafe.h file as main does not have this file now.(Already removed in commit 27195f670937c7e21ab68a806396f9d17c57231a) Co-authored-by: Alhad Deshpande --- src/coreclr/debug/daccess/ppc64le/primitives.cpp | 8 + src/coreclr/debug/ee/ppc64le/dbghelpers.S | 8 + src/coreclr/debug/ee/ppc64le/primitives.cpp | 9 + src/coreclr/debug/shared/ppc64le/primitives.cpp | 15 ++ src/coreclr/inc/crosscomp.h | 2 + src/coreclr/inc/pedecoder.h | 2 + src/coreclr/inc/switches.h | 2 +- src/coreclr/inc/volatile.h | 4 +- src/coreclr/pal/inc/pal.h | 153 +++++++++++++++++ src/coreclr/pal/inc/rt/palrt.h | 8 + src/coreclr/pal/inc/unixasmmacros.inc | 4 +- src/coreclr/pal/inc/unixasmmacrosppc64le.inc | 37 ++++ src/coreclr/pal/src/arch/ppc64le/asmconstants.h | 89 ++++++++++ .../src/arch/ppc64le/callsignalhandlerwrapper.S | 31 ++++ src/coreclr/pal/src/arch/ppc64le/context2.S | 188 +++++++++++++++++++++ src/coreclr/pal/src/arch/ppc64le/debugbreak.S | 10 ++ src/coreclr/pal/src/arch/ppc64le/exceptionhelper.S | 63 +++++++ src/coreclr/pal/src/arch/ppc64le/processor.cpp | 21 +++ .../pal/src/arch/ppc64le/signalhandlerhelper.cpp | 68 ++++++++ src/coreclr/pal/src/exception/remote-unwind.cpp | 63 ++++++- src/coreclr/pal/src/exception/seh-unwind.cpp | 60 +++++++ src/coreclr/pal/src/include/pal/context.h | 89 ++++++++++ src/coreclr/pal/src/thread/context.cpp | 58 ++++++- src/coreclr/unwinder/ppc64le/unwinder_ppc64le.cpp | 11 ++ src/coreclr/vm/ppc64le/unixstubs.cpp | 12 ++ src/mono/mono/mini/tramp-ppc.c | 2 +- src/native/external/libunwind.cmake | 36 ++++ src/native/external/libunwind/CMakeLists.txt | 5 + src/native/external/libunwind/src/CMakeLists.txt | 33 ++++ .../external/libunwind_extras/CMakeLists.txt | 2 + .../libs/System.Native/pal_runtimeinformation.c | 6 + 31 files changed, 1089 insertions(+), 10 deletions(-) create mode 100644 src/coreclr/debug/daccess/ppc64le/primitives.cpp create mode 100644 src/coreclr/debug/ee/ppc64le/dbghelpers.S create mode 100644 src/coreclr/debug/ee/ppc64le/primitives.cpp create mode 100644 src/coreclr/debug/shared/ppc64le/primitives.cpp create mode 100644 src/coreclr/pal/inc/unixasmmacrosppc64le.inc create mode 100644 src/coreclr/pal/src/arch/ppc64le/asmconstants.h create mode 100644 src/coreclr/pal/src/arch/ppc64le/callsignalhandlerwrapper.S create mode 100644 src/coreclr/pal/src/arch/ppc64le/context2.S create mode 100644 src/coreclr/pal/src/arch/ppc64le/debugbreak.S create mode 100644 src/coreclr/pal/src/arch/ppc64le/exceptionhelper.S create mode 100644 src/coreclr/pal/src/arch/ppc64le/processor.cpp create mode 100644 src/coreclr/pal/src/arch/ppc64le/signalhandlerhelper.cpp create mode 100644 src/coreclr/unwinder/ppc64le/unwinder_ppc64le.cpp create mode 100644 src/coreclr/vm/ppc64le/unixstubs.cpp diff --git a/src/coreclr/debug/daccess/ppc64le/primitives.cpp b/src/coreclr/debug/daccess/ppc64le/primitives.cpp new file mode 100644 index 0000000..6bbe300 --- /dev/null +++ b/src/coreclr/debug/daccess/ppc64le/primitives.cpp @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// + +#include "stdafx.h" + +#include "../../shared/ppc64le/primitives.cpp" diff --git a/src/coreclr/debug/ee/ppc64le/dbghelpers.S b/src/coreclr/debug/ee/ppc64le/dbghelpers.S new file mode 100644 index 0000000..a1ec663 --- /dev/null +++ b/src/coreclr/debug/ee/ppc64le/dbghelpers.S @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "asmconstants.h" +#include "unixasmmacros.inc" + +#error Unsupported platform + diff --git a/src/coreclr/debug/ee/ppc64le/primitives.cpp b/src/coreclr/debug/ee/ppc64le/primitives.cpp new file mode 100644 index 0000000..9b2e216 --- /dev/null +++ b/src/coreclr/debug/ee/ppc64le/primitives.cpp @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// + +#include "stdafx.h" +#include "threads.h" +#include "../../shared/ppc64le/primitives.cpp" + diff --git a/src/coreclr/debug/shared/ppc64le/primitives.cpp b/src/coreclr/debug/shared/ppc64le/primitives.cpp new file mode 100644 index 0000000..cb4be30 --- /dev/null +++ b/src/coreclr/debug/shared/ppc64le/primitives.cpp @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +//***************************************************************************** +// File: primitives.cpp +// + +// +// Platform-specific debugger primitives +// +//***************************************************************************** + +#include "primitives.h" + +#error Unsupported platform + diff --git a/src/coreclr/inc/crosscomp.h b/src/coreclr/inc/crosscomp.h index d7d8378..9a78c69 100644 --- a/src/coreclr/inc/crosscomp.h +++ b/src/coreclr/inc/crosscomp.h @@ -565,6 +565,8 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS { #define DAC_CS_NATIVE_DATA_SIZE 96 #elif defined(TARGET_LINUX) && defined(TARGET_LOONGARCH64) #define DAC_CS_NATIVE_DATA_SIZE 96 +#elif defined(TARGET_LINUX) && defined(TARGET_POWERPC64) +#define DAC_CS_NATIVE_DATA_SIZE 96 #elif defined(TARGET_NETBSD) && defined(TARGET_AMD64) #define DAC_CS_NATIVE_DATA_SIZE 96 #elif defined(TARGET_NETBSD) && defined(TARGET_ARM) diff --git a/src/coreclr/inc/pedecoder.h b/src/coreclr/inc/pedecoder.h index 7cd145f..2bb79e3 100644 --- a/src/coreclr/inc/pedecoder.h +++ b/src/coreclr/inc/pedecoder.h @@ -83,6 +83,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2) #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_ARM64 #elif defined(TARGET_LOONGARCH64) #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_LOONGARCH64 +#elif defined(TARGET_POWERPC64) +#define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_POWERPC #elif defined(TARGET_S390X) #define IMAGE_FILE_MACHINE_NATIVE IMAGE_FILE_MACHINE_UNKNOWN #else diff --git a/src/coreclr/inc/switches.h b/src/coreclr/inc/switches.h index d3fe1d6..9ec7e3c 100644 --- a/src/coreclr/inc/switches.h +++ b/src/coreclr/inc/switches.h @@ -53,7 +53,7 @@ #if defined(TARGET_X86) || defined(TARGET_ARM) #define USE_LAZY_PREFERRED_RANGE 0 -#elif defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_S390X) || defined(TARGET_LOONGARCH64) +#elif defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_S390X) || defined(TARGET_LOONGARCH64) || defined(TARGET_POWERPC64) #if defined(HOST_UNIX) // In PAL we have a smechanism that reserves memory on start up that is diff --git a/src/coreclr/inc/volatile.h b/src/coreclr/inc/volatile.h index dcfc8af..5f3f749 100644 --- a/src/coreclr/inc/volatile.h +++ b/src/coreclr/inc/volatile.h @@ -68,8 +68,8 @@ #error The Volatile type is currently only defined for Visual C++ and GNU C++ #endif -#if defined(__GNUC__) && !defined(HOST_X86) && !defined(HOST_AMD64) && !defined(HOST_ARM) && !defined(HOST_ARM64) && !defined(HOST_LOONGARCH64) && !defined(HOST_S390X) -#error The Volatile type is currently only defined for GCC when targeting x86, AMD64, ARM, ARM64, LOONGARCH64, or S390X CPUs +#if defined(__GNUC__) && !defined(HOST_X86) && !defined(HOST_AMD64) && !defined(HOST_ARM) && !defined(HOST_ARM64) && !defined(HOST_LOONGARCH64) && !defined(HOST_S390X) && !defined(HOST_POWERPC64) +#error The Volatile type is currently only defined for GCC when targeting x86, AMD64, ARM, ARM64, LOONGARCH64, PPC64LE, or S390X CPUs #endif #if defined(__GNUC__) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index db7d114..dd7e99c 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -96,6 +96,8 @@ typedef PVOID NATIVE_LIBRARY_HANDLE; #define _M_LOONGARCH64 1 #elif defined(__s390x__) && !defined(_M_S390X) #define _M_S390X 1 +#elif defined(__powerpc__) && !defined(_M_PPC64) +#define _M_PPC64 1 #endif #if defined(_M_IX86) && !defined(HOST_X86) @@ -110,6 +112,8 @@ typedef PVOID NATIVE_LIBRARY_HANDLE; #define HOST_LOONGARCH64 #elif defined(_M_S390X) && !defined(HOST_S390X) #define HOST_S390X +#elif defined(_M_PPC64) && !defined(HOST_POWERPC64) +#define HOST_POWERPC64 #endif #endif // !_MSC_VER @@ -2399,6 +2403,153 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS; +#elif defined(HOST_POWERPC64) + +// There is no context for ppc64le defined in winnt.h, +// so we re-use the amd64 values. +#define CONTEXT_PPC64 0x100000 + +#define CONTEXT_CONTROL (CONTEXT_PPC64 | 0x1L) +#define CONTEXT_INTEGER (CONTEXT_PPC64 | 0x2L) +#define CONTEXT_FLOATING_POINT (CONTEXT_PPC64 | 0x4L) + +#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) + +#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) + +#define CONTEXT_EXCEPTION_ACTIVE 0x8000000 +#define CONTEXT_SERVICE_ACTIVE 0x10000000 +#define CONTEXT_EXCEPTION_REQUEST 0x40000000 +#define CONTEXT_EXCEPTION_REPORTING 0x80000000 + +typedef struct DECLSPEC_ALIGN(16) _CONTEXT { + + // + // Control flags. + // + + DWORD ContextFlags; + + // + // Integer Registers + // + + DWORD64 R0; + DWORD64 R1; + DWORD64 R2; + DWORD64 R3; + DWORD64 R4; + DWORD64 R5; + DWORD64 R6; + DWORD64 R7; + DWORD64 R8; + DWORD64 R9; + DWORD64 R10; + DWORD64 R11; + DWORD64 R12; + DWORD64 R13; + DWORD64 R14; + DWORD64 R15; + DWORD64 R16; + DWORD64 R17; + DWORD64 R18; + DWORD64 R19; + DWORD64 R20; + DWORD64 R21; + DWORD64 R22; + DWORD64 R23; + DWORD64 R24; + DWORD64 R25; + DWORD64 R26; + DWORD64 R27; + DWORD64 R28; + DWORD64 R29; + DWORD64 R30; + DWORD64 R31; + + // + // Floaring Point Registers + // + + DWORD64 F0; + DWORD64 F1; + DWORD64 F2; + DWORD64 F3; + DWORD64 F4; + DWORD64 F5; + DWORD64 F6; + DWORD64 F7; + DWORD64 F8; + DWORD64 F9; + DWORD64 F10; + DWORD64 F11; + DWORD64 F12; + DWORD64 F13; + DWORD64 F14; + DWORD64 F15; + DWORD64 F16; + DWORD64 F17; + DWORD64 F18; + DWORD64 F19; + DWORD64 F20; + DWORD64 F21; + DWORD64 F22; + DWORD64 F23; + DWORD64 F24; + DWORD64 F25; + DWORD64 F26; + DWORD64 F27; + DWORD64 F28; + DWORD64 F29; + DWORD64 F30; + DWORD64 F31; + DWORD64 Fpscr; + + // + // Control Registers + // + + DWORD64 Nip; + DWORD64 Msr; + DWORD64 Ctr; + DWORD64 Link; + + DWORD Xer; + DWORD Ccr; + + +} CONTEXT, *PCONTEXT, *LPCONTEXT; + +// +// Nonvolatile context pointer record. +// + +typedef struct _KNONVOLATILE_CONTEXT_POINTERS { + PDWORD64 R14; + PDWORD64 R15; + PDWORD64 R16; + PDWORD64 R17; + PDWORD64 R18; + PDWORD64 R19; + PDWORD64 R20; + PDWORD64 R21; + PDWORD64 R22; + PDWORD64 R23; + PDWORD64 R24; + PDWORD64 R25; + PDWORD64 R26; + PDWORD64 R27; + PDWORD64 R28; + PDWORD64 R29; + PDWORD64 R30; + PDWORD64 R31; + + // + // Need to add Floating point non-volatile registers. + // + +} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS; + #else #error Unknown architecture for defining CONTEXT. #endif @@ -2536,6 +2687,8 @@ PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context, KNONVOLATILE_ #define PAL_CS_NATIVE_DATA_SIZE 96 #elif defined(__linux__) && defined(HOST_S390X) #define PAL_CS_NATIVE_DATA_SIZE 96 +#elif defined(__linux__) && defined(HOST_POWERPC64) +#define PAL_CS_NATIVE_DATA_SIZE 96 #elif defined(__NetBSD__) && defined(__amd64__) #define PAL_CS_NATIVE_DATA_SIZE 96 #elif defined(__NetBSD__) && defined(__earm__) diff --git a/src/coreclr/pal/inc/rt/palrt.h b/src/coreclr/pal/inc/rt/palrt.h index 6264223..1080824 100644 --- a/src/coreclr/pal/inc/rt/palrt.h +++ b/src/coreclr/pal/inc/rt/palrt.h @@ -1148,6 +1148,14 @@ typedef struct _DISPATCHER_CONTEXT { DWORD Reserved; } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT; +#elif defined(HOST_POWERPC64) + +typedef struct _DISPATCHER_CONTEXT { + // PPC64LE does not build the VM or JIT at this point, + // so we only provide a dummy definition. + DWORD Reserved; +} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT; + #else #error Unknown architecture for defining DISPATCHER_CONTEXT. diff --git a/src/coreclr/pal/inc/unixasmmacros.inc b/src/coreclr/pal/inc/unixasmmacros.inc index a814c5a..cf05fbe 100644 --- a/src/coreclr/pal/inc/unixasmmacros.inc +++ b/src/coreclr/pal/inc/unixasmmacros.inc @@ -19,7 +19,7 @@ #if defined(__APPLE__) #define C_PLTFUNC(name) _##name -#elif defined(HOST_ARM64) +#elif defined(HOST_ARM64) || defined(HOST_POWERPC64) #define C_PLTFUNC(name) name #else #define C_PLTFUNC(name) name@PLT @@ -47,4 +47,6 @@ #include "unixasmmacross390x.inc" #elif defined(HOST_LOONGARCH64) #include "unixasmmacrosloongarch64.inc" +#elif defined(HOST_POWERPC64) +#include "unixasmmacrosppc64le.inc" #endif diff --git a/src/coreclr/pal/inc/unixasmmacrosppc64le.inc b/src/coreclr/pal/inc/unixasmmacrosppc64le.inc new file mode 100644 index 0000000..2c1c4d6 --- /dev/null +++ b/src/coreclr/pal/inc/unixasmmacrosppc64le.inc @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +.macro NESTED_ENTRY Name, Section, Handler + LEAF_ENTRY \Name, \Section + .ifnc \Handler, NoHandler + .personality C_FUNC(\Handler) + .endif +.endm + +.macro NESTED_END Name, Section + LEAF_END \Name, \Section +.endm + +.macro PATCH_LABEL Name + .global C_FUNC(\Name) +C_FUNC(\Name): +.endm + +.macro LEAF_ENTRY Name, Section + .global C_FUNC(\Name) + .type \Name, %function +C_FUNC(\Name): + .cfi_startproc +.endm + +.macro LEAF_END Name, Section + .size \Name, .-\Name + .cfi_endproc +.endm + +.macro LEAF_END_MARKED Name, Section +C_FUNC(\Name\()_End): + .global C_FUNC(\Name\()_End) + LEAF_END \Name, \Section +.endm + diff --git a/src/coreclr/pal/src/arch/ppc64le/asmconstants.h b/src/coreclr/pal/src/arch/ppc64le/asmconstants.h new file mode 100644 index 0000000..15ee945 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/asmconstants.h @@ -0,0 +1,89 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef __PAL_POWERPC_ASMCONSTANTS_H__ +#define __PAL_POWERPC_ASMCONSTANTS_H__ + +#define CONTEXT_PPC64 0x100000 + +#define CONTEXT_CONTROL 1 +#define CONTEXT_INTEGER 2 +#define CONTEXT_FLOATING_POINT 4 + +#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT) + +#define CONTEXT_ContextFlags 0 +#define CONTEXT_R0 CONTEXT_ContextFlags+8 +#define CONTEXT_R1 CONTEXT_R0+8 +#define CONTEXT_R2 CONTEXT_R1+8 +#define CONTEXT_R3 CONTEXT_R2+8 +#define CONTEXT_R4 CONTEXT_R3+8 +#define CONTEXT_R5 CONTEXT_R4+8 +#define CONTEXT_R6 CONTEXT_R5+8 +#define CONTEXT_R7 CONTEXT_R6+8 +#define CONTEXT_R8 CONTEXT_R7+8 +#define CONTEXT_R9 CONTEXT_R8+8 +#define CONTEXT_R10 CONTEXT_R9+8 +#define CONTEXT_R11 CONTEXT_R10+8 +#define CONTEXT_R12 CONTEXT_R11+8 +#define CONTEXT_R13 CONTEXT_R12+8 +#define CONTEXT_R14 CONTEXT_R13+8 +#define CONTEXT_R15 CONTEXT_R14+8 +#define CONTEXT_R16 CONTEXT_R15+8 +#define CONTEXT_R17 CONTEXT_R16+8 +#define CONTEXT_R18 CONTEXT_R17+8 +#define CONTEXT_R19 CONTEXT_R18+8 +#define CONTEXT_R20 CONTEXT_R19+8 +#define CONTEXT_R21 CONTEXT_R20+8 +#define CONTEXT_R22 CONTEXT_R21+8 +#define CONTEXT_R23 CONTEXT_R22+8 +#define CONTEXT_R24 CONTEXT_R23+8 +#define CONTEXT_R25 CONTEXT_R24+8 +#define CONTEXT_R26 CONTEXT_R25+8 +#define CONTEXT_R27 CONTEXT_R26+8 +#define CONTEXT_R28 CONTEXT_R27+8 +#define CONTEXT_R29 CONTEXT_R28+8 +#define CONTEXT_R30 CONTEXT_R29+8 +#define CONTEXT_R31 CONTEXT_R30+8 +#define CONTEXT_F0 CONTEXT_R31+8 +#define CONTEXT_F1 CONTEXT_F0+8 +#define CONTEXT_F2 CONTEXT_F1+8 +#define CONTEXT_F3 CONTEXT_F2+8 +#define CONTEXT_F4 CONTEXT_F3+8 +#define CONTEXT_F5 CONTEXT_F4+8 +#define CONTEXT_F6 CONTEXT_F5+8 +#define CONTEXT_F7 CONTEXT_F6+8 +#define CONTEXT_F8 CONTEXT_F7+8 +#define CONTEXT_F9 CONTEXT_F8+8 +#define CONTEXT_F10 CONTEXT_F9+8 +#define CONTEXT_F11 CONTEXT_F10+8 +#define CONTEXT_F12 CONTEXT_F11+8 +#define CONTEXT_F13 CONTEXT_F12+8 +#define CONTEXT_F14 CONTEXT_F13+8 +#define CONTEXT_F15 CONTEXT_F14+8 +#define CONTEXT_F16 CONTEXT_F15+8 +#define CONTEXT_F17 CONTEXT_F16+8 +#define CONTEXT_F18 CONTEXT_F17+8 +#define CONTEXT_F19 CONTEXT_F18+8 +#define CONTEXT_F20 CONTEXT_F19+8 +#define CONTEXT_F21 CONTEXT_F20+8 +#define CONTEXT_F22 CONTEXT_F21+8 +#define CONTEXT_F23 CONTEXT_F22+8 +#define CONTEXT_F24 CONTEXT_F23+8 +#define CONTEXT_F25 CONTEXT_F24+8 +#define CONTEXT_F26 CONTEXT_F25+8 +#define CONTEXT_F27 CONTEXT_F26+8 +#define CONTEXT_F28 CONTEXT_F27+8 +#define CONTEXT_F29 CONTEXT_F28+8 +#define CONTEXT_F30 CONTEXT_F29+8 +#define CONTEXT_F31 CONTEXT_F30+8 +#define CONTEXT_FPSCR CONTEXT_F31+8 +#define CONTEXT_NIP CONTEXT_FPSCR+8 +#define CONTEXT_MSR CONTEXT_NIP+8 +#define CONTEXT_CTR CONTEXT_MSR+8 +#define CONTEXT_LINK CONTEXT_CTR+8 +#define CONTEXT_XER CONTEXT_LINK+8 +#define CONTEXT_CCR CONTEXT_XER+8 +#define CONTEXT_Size CONTEXT_CCR+8 + +#endif diff --git a/src/coreclr/pal/src/arch/ppc64le/callsignalhandlerwrapper.S b/src/coreclr/pal/src/arch/ppc64le/callsignalhandlerwrapper.S new file mode 100644 index 0000000..1ace139 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/callsignalhandlerwrapper.S @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +.macro CALL_SIGNAL_HANDLER_WRAPPER Alignment + +.globl C_FUNC(SignalHandlerWorkerReturnOffset\Alignment) +C_FUNC(SignalHandlerWorkerReturnOffset\Alignment): + .int LOCAL_LABEL(SignalHandlerWorkerReturn\Alignment)-C_FUNC(CallSignalHandlerWrapper\Alignment) + +// This function is never called, only a fake stack frame will be setup to have a return +// address set to SignalHandlerWorkerReturn during SIGSEGV handling. +// It enables the unwinder to unwind stack from the handling code to the actual failure site. +NESTED_ENTRY CallSignalHandlerWrapper\Alignment, _TEXT, NoHandler + mflr %r0 + std %r0, 16(%r1) + stdu %r1,-32(%r1) + bl EXTERNAL_C_FUNC(signal_handler_worker) +LOCAL_LABEL(SignalHandlerWorkerReturn\Alignment): + addi %r1, %r1, 32 + ld %r0, 16(%r1) + mtlr %r0 + blr +NESTED_END CallSignalHandlerWrapper\Alignment, _TEXT + +.endm + +CALL_SIGNAL_HANDLER_WRAPPER 0 +CALL_SIGNAL_HANDLER_WRAPPER 8 diff --git a/src/coreclr/pal/src/arch/ppc64le/context2.S b/src/coreclr/pal/src/arch/ppc64le/context2.S new file mode 100644 index 0000000..f48c741 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/context2.S @@ -0,0 +1,188 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +// Implementation of _CONTEXT_CaptureContext for the IBM power ppc64le platform. +// This function is processor dependent. It is used by exception handling, +// and is always apply to the current thread. +// + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +// Incoming: +// R3: Context* +// +LEAF_ENTRY CONTEXT_CaptureContext, _TEXT + + // Store all general purpose registers + std %r0, CONTEXT_R0(%r3) + std %r1, CONTEXT_R1(%r3) + std %r2, CONTEXT_R2(%r3) + std %r3, CONTEXT_R3(%r3) + std %r4, CONTEXT_R4(%r3) + std %r5, CONTEXT_R5(%r3) + std %r6, CONTEXT_R6(%r3) + std %r7, CONTEXT_R7(%r3) + std %r8, CONTEXT_R8(%r3) + std %r9, CONTEXT_R9(%r3) + std %r10, CONTEXT_R10(%r3) + std %r11, CONTEXT_R11(%r3) + std %r12, CONTEXT_R12(%r3) + std %r13, CONTEXT_R13(%r3) + std %r14, CONTEXT_R14(%r3) + std %r15, CONTEXT_R15(%r3) + std %r16, CONTEXT_R16(%r3) + std %r17, CONTEXT_R17(%r3) + std %r18, CONTEXT_R18(%r3) + std %r19, CONTEXT_R19(%r3) + std %r20, CONTEXT_R20(%r3) + std %r21, CONTEXT_R21(%r3) + std %r22, CONTEXT_R22(%r3) + std %r23, CONTEXT_R23(%r3) + std %r24, CONTEXT_R24(%r3) + std %r25, CONTEXT_R25(%r3) + std %r26, CONTEXT_R26(%r3) + std %r27, CONTEXT_R27(%r3) + std %r28, CONTEXT_R28(%r3) + std %r29, CONTEXT_R29(%r3) + std %r30, CONTEXT_R30(%r3) + std %r31, CONTEXT_R31(%r3) + + // Store all floating point registers + stfd %f0, CONTEXT_F0(%r3) + stfd %f1, CONTEXT_F1(%r3) + stfd %f2, CONTEXT_F2(%r3) + stfd %f3, CONTEXT_F3(%r3) + stfd %f4, CONTEXT_F4(%r3) + stfd %f5, CONTEXT_F5(%r3) + stfd %f6, CONTEXT_F6(%r3) + stfd %f7, CONTEXT_F7(%r3) + stfd %f8, CONTEXT_F8(%r3) + stfd %f9, CONTEXT_F9(%r3) + stfd %f10, CONTEXT_F10(%r3) + stfd %f11, CONTEXT_F11(%r3) + stfd %f12, CONTEXT_F12(%r3) + stfd %f13, CONTEXT_F13(%r3) + stfd %f14, CONTEXT_F14(%r3) + stfd %f15, CONTEXT_F15(%r3) + stfd %f16, CONTEXT_F16(%r3) + stfd %f17, CONTEXT_F17(%r3) + stfd %f18, CONTEXT_F18(%r3) + stfd %f19, CONTEXT_F19(%r3) + stfd %f20, CONTEXT_F20(%r3) + stfd %f21, CONTEXT_F21(%r3) + stfd %f22, CONTEXT_F22(%r3) + stfd %f23, CONTEXT_F23(%r3) + stfd %f24, CONTEXT_F24(%r3) + stfd %f25, CONTEXT_F25(%r3) + stfd %f26, CONTEXT_F26(%r3) + stfd %f27, CONTEXT_F27(%r3) + stfd %f28, CONTEXT_F28(%r3) + stfd %f29, CONTEXT_F29(%r3) + stfd %f30, CONTEXT_F30(%r3) + stfd %f31, CONTEXT_F31(%r3) + + // Save Control Registers - XER, LR and CTR + mfspr 5, 1 + std %r5, CONTEXT_XER(%r3) + mflr %r5 + std %r5, CONTEXT_LINK(%r3) + mfspr 5, 9 + std %r5, CONTEXT_CTR(%r3) + + // Restore r5 general purpose register + ld %r5, CONTEXT_R5(%r3) + + blr +LEAF_END CONTEXT_CaptureContext, _TEXT + +LEAF_ENTRY RtlCaptureContext, _TEXT + b C_FUNC(CONTEXT_CaptureContext) +LEAF_END RtlCaptureContext, _TEXT + +LEAF_ENTRY RtlRestoreContext, _TEXT + + // Restore all floating point registers + lfd %f0, CONTEXT_F0(%r3) + lfd %f1, CONTEXT_F1(%r3) + lfd %f2, CONTEXT_F2(%r3) + lfd %f3, CONTEXT_F3(%r3) + lfd %f4, CONTEXT_F4(%r3) + lfd %f5, CONTEXT_F5(%r3) + lfd %f6, CONTEXT_F6(%r3) + lfd %f7, CONTEXT_F7(%r3) + lfd %f8, CONTEXT_F8(%r3) + lfd %f9, CONTEXT_F9(%r3) + lfd %f10, CONTEXT_F10(%r3) + lfd %f11, CONTEXT_F11(%r3) + lfd %f12, CONTEXT_F12(%r3) + lfd %f13, CONTEXT_F13(%r3) + lfd %f14, CONTEXT_F14(%r3) + lfd %f15, CONTEXT_F15(%r3) + lfd %f16, CONTEXT_F16(%r3) + lfd %f17, CONTEXT_F17(%r3) + lfd %f18, CONTEXT_F18(%r3) + lfd %f19, CONTEXT_F19(%r3) + lfd %f20, CONTEXT_F20(%r3) + lfd %f21, CONTEXT_F21(%r3) + lfd %f22, CONTEXT_F22(%r3) + lfd %f23, CONTEXT_F23(%r3) + lfd %f24, CONTEXT_F24(%r3) + lfd %f25, CONTEXT_F25(%r3) + lfd %f26, CONTEXT_F26(%r3) + lfd %f27, CONTEXT_F27(%r3) + lfd %f28, CONTEXT_F28(%r3) + lfd %f29, CONTEXT_F29(%r3) + lfd %f30, CONTEXT_F30(%r3) + lfd %f31, CONTEXT_F31(%r3) + + // Restore all general purpose registers + ld %r0, CONTEXT_R0(%R3) + ld %r1, CONTEXT_R1(%r3) + ld %r2, CONTEXT_R2(%r3) + ld %r4, CONTEXT_R4(%r3) + ld %r5, CONTEXT_R5(%r3) + ld %r6, CONTEXT_R6(%r3) + ld %r7, CONTEXT_R7(%r3) + ld %r8, CONTEXT_R8(%r3) + ld %r9, CONTEXT_R9(%r3) + ld %r10, CONTEXT_R10(%r3) + ld %r11, CONTEXT_R11(%r3) + ld %r12, CONTEXT_R12(%r3) + ld %r13, CONTEXT_R13(%r3) + ld %r14, CONTEXT_R14(%r3) + ld %r15, CONTEXT_R15(%r3) + ld %r16, CONTEXT_R16(%r3) + ld %r17, CONTEXT_R17(%r3) + ld %r18, CONTEXT_R18(%r3) + ld %r19, CONTEXT_R19(%r3) + ld %r20, CONTEXT_R20(%r3) + ld %r21, CONTEXT_R21(%r3) + ld %r22, CONTEXT_R22(%r3) + ld %r23, CONTEXT_R23(%r3) + ld %r24, CONTEXT_R24(%r3) + ld %r25, CONTEXT_R25(%r3) + ld %r26, CONTEXT_R26(%r3) + ld %r27, CONTEXT_R27(%r3) + ld %r28, CONTEXT_R28(%r3) + ld %r29, CONTEXT_R29(%r3) + ld %r30, CONTEXT_R30(%r3) + ld %r31, CONTEXT_R31(%r3) + + // Restore Control Register - XER + ld %r12, CONTEXT_XER(%r3) + mtspr 1, 12 + + // Restore Control Register - LR + mtlr %r0 + + // Restore Control Register - CTR + ld %r12, CONTEXT_LINK(%r3) + mtctr %r12 + + // Restore R3 register + ld %r3, CONTEXT_R3(%r3) + + // Branch to CTR register location + bctr +LEAF_END RtlRestoreContext, _TEXT diff --git a/src/coreclr/pal/src/arch/ppc64le/debugbreak.S b/src/coreclr/pal/src/arch/ppc64le/debugbreak.S new file mode 100644 index 0000000..8ff9c9c4 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/debugbreak.S @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" + +LEAF_ENTRY DBG_DebugBreak, _TEXT + bl abort + nop +LEAF_END_MARKED DBG_DebugBreak, _TEXT + diff --git a/src/coreclr/pal/src/arch/ppc64le/exceptionhelper.S b/src/coreclr/pal/src/arch/ppc64le/exceptionhelper.S new file mode 100644 index 0000000..9c3d9f4 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/exceptionhelper.S @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "unixasmmacros.inc" +#include "asmconstants.h" + +////////////////////////////////////////////////////////////////////////// +// +// This function creates a stack frame right below the target frame, restores all callee +// saved registers from the passed in context, sets R15 to that frame and sets the +// return address to the target frame's PSW address. +// Then it uses the ThrowExceptionHelper to throw the passed in exception from that context. +// EXTERN_C void ThrowExceptionFromContextInternal(CONTEXT* context, PAL_SEHException* ex); +LEAF_ENTRY ThrowExceptionFromContextInternal, _TEXT + + // Restore all non volatile floating point registers + lfd %f15, CONTEXT_F15(%r3) + lfd %f16, CONTEXT_F16(%r3) + lfd %f17, CONTEXT_F17(%r3) + lfd %f18, CONTEXT_F18(%r3) + lfd %f19, CONTEXT_F19(%r3) + lfd %f20, CONTEXT_F20(%r3) + lfd %f21, CONTEXT_F21(%r3) + lfd %f22, CONTEXT_F22(%r3) + lfd %f23, CONTEXT_F23(%r3) + lfd %f24, CONTEXT_F24(%r3) + lfd %f25, CONTEXT_F25(%r3) + lfd %f26, CONTEXT_F26(%r3) + lfd %f27, CONTEXT_F27(%r3) + lfd %f28, CONTEXT_F28(%r3) + lfd %f29, CONTEXT_F29(%r3) + lfd %f30, CONTEXT_F30(%r3) + lfd %f31, CONTEXT_F31(%r3) + + // Restore all non volatile general purpose registers + ld %r14, CONTEXT_R14(%r3) + ld %r15, CONTEXT_R15(%r3) + ld %r16, CONTEXT_R16(%r3) + ld %r17, CONTEXT_R17(%r3) + ld %r18, CONTEXT_R18(%r3) + ld %r19, CONTEXT_R19(%r3) + ld %r20, CONTEXT_R20(%r3) + ld %r21, CONTEXT_R21(%r3) + ld %r22, CONTEXT_R22(%r3) + ld %r23, CONTEXT_R23(%r3) + ld %r24, CONTEXT_R24(%r3) + ld %r25, CONTEXT_R25(%r3) + ld %r26, CONTEXT_R26(%r3) + ld %r27, CONTEXT_R27(%r3) + ld %r28, CONTEXT_R28(%r3) + ld %r29, CONTEXT_R29(%r3) + ld %r30, CONTEXT_R30(%r3) + ld %r31, CONTEXT_R31(%r3) + + ld %r0, CONTEXT_NIP(%r3) + mtlr %r0 + + ld %r1, CONTEXT_R1(%r3) + + // The PAL_SEHException pointer + mr %r3, %r4 + b EXTERNAL_C_FUNC(ThrowExceptionHelper) +LEAF_END ThrowExceptionFromContextInternal, _TEXT diff --git a/src/coreclr/pal/src/arch/ppc64le/processor.cpp b/src/coreclr/pal/src/arch/ppc64le/processor.cpp new file mode 100644 index 0000000..6680dbc --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/processor.cpp @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +/*++ + + + +Module Name: + + processor.cpp + +Abstract: + + Implementation of processor related functions for the IBM PowerPC (ppc64le) + platforms. These functions are processor dependent. + + + +--*/ + +#include "pal/palinternal.h" diff --git a/src/coreclr/pal/src/arch/ppc64le/signalhandlerhelper.cpp b/src/coreclr/pal/src/arch/ppc64le/signalhandlerhelper.cpp new file mode 100644 index 0000000..6661517 --- /dev/null +++ b/src/coreclr/pal/src/arch/ppc64le/signalhandlerhelper.cpp @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "pal/dbgmsg.h" +SET_DEFAULT_DEBUG_CHANNEL(EXCEPT); // some headers have code with asserts, so do this first + +#include "pal/palinternal.h" +#include "pal/context.h" +#include "pal/signal.hpp" +#include "pal/utils.h" +#include + +/*++ +Function : + ExecuteHandlerOnCustomStack + + Execute signal handler on a custom stack, the current stack pointer is specified by the customSp + If the customSp is 0, then the handler is executed on the original stack where the signal was fired. + It installs a fake stack frame to enable stack unwinding to the signal source location. + +Parameters : + POSIX signal handler parameter list ("man sigaction" for details) + returnPoint - context to which the function returns if the common_signal_handler returns + + (no return value) +--*/ +void ExecuteHandlerOnCustomStack(int code, siginfo_t *siginfo, void *context, size_t customSp, SignalHandlerWorkerReturnPoint* returnPoint) +{ + ucontext_t *ucontext = (ucontext_t *)context; + size_t faultSp = (size_t)MCREG_R1(ucontext->uc_mcontext); + _ASSERTE(IS_ALIGNED(faultSp, 8)); + + if (customSp == 0) + { + customSp = faultSp; + } + + size_t fakeFrameReturnAddress; + if (IS_ALIGNED(faultSp, 16)) + { + fakeFrameReturnAddress = (size_t)SignalHandlerWorkerReturnOffset0 + (size_t)CallSignalHandlerWrapper0; + } + else + { + fakeFrameReturnAddress = (size_t)SignalHandlerWorkerReturnOffset8 + (size_t)CallSignalHandlerWrapper8; + } + + // Build fake stack frame to enable the stack unwinder to unwind from signal_handler_worker to the faulting instruction + size_t* saveArea = (size_t*)(customSp - 32); + saveArea[0] = faultSp; + saveArea[2] = (size_t)MCREG_Nip(ucontext->uc_mcontext); + size_t sp = customSp - 32; + + // Switch the current context to the signal_handler_worker and the custom stack + CONTEXT context2; + RtlCaptureContext(&context2); + + context2.Link = (size_t)signal_handler_worker; + context2.R0 = fakeFrameReturnAddress; + context2.R1 = sp; + context2.R3 = code; + context2.R4 = (size_t)siginfo; + context2.R5 = (size_t)context; + context2.R6 = (size_t)returnPoint; + + + RtlRestoreContext(&context2, NULL); +} diff --git a/src/coreclr/pal/src/exception/remote-unwind.cpp b/src/coreclr/pal/src/exception/remote-unwind.cpp index 514851f..ebeb466 100644 --- a/src/coreclr/pal/src/exception/remote-unwind.cpp +++ b/src/coreclr/pal/src/exception/remote-unwind.cpp @@ -124,7 +124,7 @@ typedef BOOL(*UnwindReadMemoryCallback)(PVOID address, PVOID buffer, SIZE_T size #define PRId PRId32 #define PRIA "08" #define PRIxA PRIA PRIx -#elif defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_S390X) || defined(TARGET_LOONGARCH64) +#elif defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_S390X) || defined(TARGET_LOONGARCH64) || defined(TARGET_POWERPC64) #define PRIx PRIx64 #define PRIu PRIu64 #define PRId PRId64 @@ -1872,6 +1872,25 @@ static void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, GetContextPointer(cursor, unwContext, UNW_S390X_R13, &contextPointers->R13); GetContextPointer(cursor, unwContext, UNW_S390X_R14, &contextPointers->R14); GetContextPointer(cursor, unwContext, UNW_S390X_R15, &contextPointers->R15); +#elif defined(TARGET_POWERPC64) + GetContextPointer(cursor, unwContext, UNW_PPC64_R14, &contextPointers->R14); + GetContextPointer(cursor, unwContext, UNW_PPC64_R15, &contextPointers->R15); + GetContextPointer(cursor, unwContext, UNW_PPC64_R16, &contextPointers->R16); + GetContextPointer(cursor, unwContext, UNW_PPC64_R17, &contextPointers->R17); + GetContextPointer(cursor, unwContext, UNW_PPC64_R18, &contextPointers->R18); + GetContextPointer(cursor, unwContext, UNW_PPC64_R19, &contextPointers->R19); + GetContextPointer(cursor, unwContext, UNW_PPC64_R20, &contextPointers->R20); + GetContextPointer(cursor, unwContext, UNW_PPC64_R21, &contextPointers->R21); + GetContextPointer(cursor, unwContext, UNW_PPC64_R22, &contextPointers->R22); + GetContextPointer(cursor, unwContext, UNW_PPC64_R23, &contextPointers->R23); + GetContextPointer(cursor, unwContext, UNW_PPC64_R24, &contextPointers->R24); + GetContextPointer(cursor, unwContext, UNW_PPC64_R25, &contextPointers->R25); + GetContextPointer(cursor, unwContext, UNW_PPC64_R26, &contextPointers->R26); + GetContextPointer(cursor, unwContext, UNW_PPC64_R27, &contextPointers->R27); + GetContextPointer(cursor, unwContext, UNW_PPC64_R28, &contextPointers->R28); + GetContextPointer(cursor, unwContext, UNW_PPC64_R29, &contextPointers->R29); + GetContextPointer(cursor, unwContext, UNW_PPC64_R30, &contextPointers->R30); + GetContextPointer(cursor, unwContext, UNW_PPC64_R31, &contextPointers->R31); #else #error unsupported architecture #endif @@ -1959,6 +1978,27 @@ static void UnwindContextToContext(unw_cursor_t *cursor, CONTEXT *winContext) unw_get_reg(cursor, UNW_S390X_R13, (unw_word_t *) &winContext->R13); unw_get_reg(cursor, UNW_S390X_R14, (unw_word_t *) &winContext->R14); TRACE("sp %p pc %p lr %p\n", winContext->R15, winContext->PSWAddr, winContext->R14); +#elif defined(TARGET_POWERPC64) + //TODO + unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Nip); + unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->R31); + unw_get_reg(cursor, UNW_PPC64_R14, (unw_word_t *) &winContext->R14); + unw_get_reg(cursor, UNW_PPC64_R15, (unw_word_t *) &winContext->R15); + unw_get_reg(cursor, UNW_PPC64_R16, (unw_word_t *) &winContext->R16); + unw_get_reg(cursor, UNW_PPC64_R17, (unw_word_t *) &winContext->R17); + unw_get_reg(cursor, UNW_PPC64_R18, (unw_word_t *) &winContext->R18); + unw_get_reg(cursor, UNW_PPC64_R19, (unw_word_t *) &winContext->R19); + unw_get_reg(cursor, UNW_PPC64_R20, (unw_word_t *) &winContext->R20); + unw_get_reg(cursor, UNW_PPC64_R21, (unw_word_t *) &winContext->R21); + unw_get_reg(cursor, UNW_PPC64_R22, (unw_word_t *) &winContext->R22); + unw_get_reg(cursor, UNW_PPC64_R23, (unw_word_t *) &winContext->R23); + unw_get_reg(cursor, UNW_PPC64_R24, (unw_word_t *) &winContext->R24); + unw_get_reg(cursor, UNW_PPC64_R25, (unw_word_t *) &winContext->R25); + unw_get_reg(cursor, UNW_PPC64_R26, (unw_word_t *) &winContext->R26); + unw_get_reg(cursor, UNW_PPC64_R27, (unw_word_t *) &winContext->R27); + unw_get_reg(cursor, UNW_PPC64_R28, (unw_word_t *) &winContext->R28); + unw_get_reg(cursor, UNW_PPC64_R29, (unw_word_t *) &winContext->R29); + unw_get_reg(cursor, UNW_PPC64_R30, (unw_word_t *) &winContext->R30); #else #error unsupported architecture #endif @@ -2073,6 +2113,27 @@ access_reg(unw_addr_space_t as, unw_regnum_t regnum, unw_word_t *valp, int write case UNW_S390X_R14: *valp = (unw_word_t)winContext->R14; break; case UNW_S390X_R15: *valp = (unw_word_t)winContext->R15; break; case UNW_S390X_IP: *valp = (unw_word_t)winContext->PSWAddr; break; +#elif defined(TARGET_POWERPC64) + //TODO + case UNW_PPC64_R14: *valp = (unw_word_t)winContext->R14; break; + case UNW_PPC64_R15: *valp = (unw_word_t)winContext->R15; break; + case UNW_PPC64_R16: *valp = (unw_word_t)winContext->R16; break; + case UNW_PPC64_R17: *valp = (unw_word_t)winContext->R17; break; + case UNW_PPC64_R18: *valp = (unw_word_t)winContext->R18; break; + case UNW_PPC64_R19: *valp = (unw_word_t)winContext->R19; break; + case UNW_PPC64_R20: *valp = (unw_word_t)winContext->R20; break; + case UNW_PPC64_R21: *valp = (unw_word_t)winContext->R21; break; + case UNW_PPC64_R22: *valp = (unw_word_t)winContext->R22; break; + case UNW_PPC64_R23: *valp = (unw_word_t)winContext->R23; break; + case UNW_PPC64_R24: *valp = (unw_word_t)winContext->R24; break; + case UNW_PPC64_R25: *valp = (unw_word_t)winContext->R25; break; + case UNW_PPC64_R26: *valp = (unw_word_t)winContext->R26; break; + case UNW_PPC64_R27: *valp = (unw_word_t)winContext->R27; break; + case UNW_PPC64_R28: *valp = (unw_word_t)winContext->R28; break; + case UNW_PPC64_R29: *valp = (unw_word_t)winContext->R29; break; + case UNW_PPC64_R30: *valp = (unw_word_t)winContext->R30; break; + case UNW_PPC64_R31: *valp = (unw_word_t)winContext->R31; break; + case UNW_PPC64_NIP: *valp = (unw_word_t)winContext->Nip; break; #else #error unsupported architecture #endif diff --git a/src/coreclr/pal/src/exception/seh-unwind.cpp b/src/coreclr/pal/src/exception/seh-unwind.cpp index fd9756d..9fe6c61 100644 --- a/src/coreclr/pal/src/exception/seh-unwind.cpp +++ b/src/coreclr/pal/src/exception/seh-unwind.cpp @@ -152,6 +152,27 @@ enum ASSIGN_REG(S6) \ ASSIGN_REG(S7) \ ASSIGN_REG(S8) +#elif (defined(HOST_UNIX) && defined(HOST_POWERPC64)) +#define ASSIGN_UNWIND_REGS \ + ASSIGN_REG(Nip) \ + ASSIGN_REG(R14) \ + ASSIGN_REG(R15) \ + ASSIGN_REG(R16) \ + ASSIGN_REG(R17) \ + ASSIGN_REG(R18) \ + ASSIGN_REG(R19) \ + ASSIGN_REG(R20) \ + ASSIGN_REG(R21) \ + ASSIGN_REG(R22) \ + ASSIGN_REG(R23) \ + ASSIGN_REG(R24) \ + ASSIGN_REG(R25) \ + ASSIGN_REG(R26) \ + ASSIGN_REG(R27) \ + ASSIGN_REG(R28) \ + ASSIGN_REG(R29) \ + ASSIGN_REG(R30) \ + ASSIGN_REG(R31) #else #error unsupported architecture #endif @@ -390,6 +411,26 @@ void UnwindContextToWinContext(unw_cursor_t *cursor, CONTEXT *winContext) unw_get_reg(cursor, UNW_LOONGARCH64_R29, (unw_word_t *) &winContext->S6); unw_get_reg(cursor, UNW_LOONGARCH64_R30, (unw_word_t *) &winContext->S7); unw_get_reg(cursor, UNW_LOONGARCH64_R31, (unw_word_t *) &winContext->S8); +#elif (defined(HOST_UNIX) && defined(HOST_POWERPC64)) + unw_get_reg(cursor, UNW_REG_SP, (unw_word_t *) &winContext->R31); + unw_get_reg(cursor, UNW_REG_IP, (unw_word_t *) &winContext->Nip); + unw_get_reg(cursor, UNW_PPC64_R14, (unw_word_t *) &winContext->R14); + unw_get_reg(cursor, UNW_PPC64_R15, (unw_word_t *) &winContext->R15); + unw_get_reg(cursor, UNW_PPC64_R16, (unw_word_t *) &winContext->R16); + unw_get_reg(cursor, UNW_PPC64_R17, (unw_word_t *) &winContext->R17); + unw_get_reg(cursor, UNW_PPC64_R18, (unw_word_t *) &winContext->R18); + unw_get_reg(cursor, UNW_PPC64_R19, (unw_word_t *) &winContext->R19); + unw_get_reg(cursor, UNW_PPC64_R20, (unw_word_t *) &winContext->R20); + unw_get_reg(cursor, UNW_PPC64_R21, (unw_word_t *) &winContext->R21); + unw_get_reg(cursor, UNW_PPC64_R22, (unw_word_t *) &winContext->R22); + unw_get_reg(cursor, UNW_PPC64_R23, (unw_word_t *) &winContext->R23); + unw_get_reg(cursor, UNW_PPC64_R24, (unw_word_t *) &winContext->R24); + unw_get_reg(cursor, UNW_PPC64_R25, (unw_word_t *) &winContext->R25); + unw_get_reg(cursor, UNW_PPC64_R26, (unw_word_t *) &winContext->R26); + unw_get_reg(cursor, UNW_PPC64_R27, (unw_word_t *) &winContext->R27); + unw_get_reg(cursor, UNW_PPC64_R28, (unw_word_t *) &winContext->R28); + unw_get_reg(cursor, UNW_PPC64_R29, (unw_word_t *) &winContext->R29); + unw_get_reg(cursor, UNW_PPC64_R30, (unw_word_t *) &winContext->R30); #else #error unsupported architecture #endif @@ -488,6 +529,25 @@ void GetContextPointers(unw_cursor_t *cursor, unw_context_t *unwContext, KNONVOL GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R29, &contextPointers->S6); GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R30, &contextPointers->S7); GetContextPointer(cursor, unwContext, UNW_LOONGARCH64_R31, &contextPointers->S8); +#elif (defined(HOST_UNIX) && defined(HOST_POWERPC64)) + GetContextPointer(cursor, unwContext, UNW_PPC64_R14, &contextPointers->R14); + GetContextPointer(cursor, unwContext, UNW_PPC64_R15, &contextPointers->R15); + GetContextPointer(cursor, unwContext, UNW_PPC64_R16, &contextPointers->R16); + GetContextPointer(cursor, unwContext, UNW_PPC64_R17, &contextPointers->R17); + GetContextPointer(cursor, unwContext, UNW_PPC64_R18, &contextPointers->R18); + GetContextPointer(cursor, unwContext, UNW_PPC64_R19, &contextPointers->R19); + GetContextPointer(cursor, unwContext, UNW_PPC64_R20, &contextPointers->R20); + GetContextPointer(cursor, unwContext, UNW_PPC64_R21, &contextPointers->R21); + GetContextPointer(cursor, unwContext, UNW_PPC64_R22, &contextPointers->R22); + GetContextPointer(cursor, unwContext, UNW_PPC64_R23, &contextPointers->R23); + GetContextPointer(cursor, unwContext, UNW_PPC64_R24, &contextPointers->R24); + GetContextPointer(cursor, unwContext, UNW_PPC64_R25, &contextPointers->R25); + GetContextPointer(cursor, unwContext, UNW_PPC64_R26, &contextPointers->R26); + GetContextPointer(cursor, unwContext, UNW_PPC64_R27, &contextPointers->R27); + GetContextPointer(cursor, unwContext, UNW_PPC64_R28, &contextPointers->R28); + GetContextPointer(cursor, unwContext, UNW_PPC64_R29, &contextPointers->R29); + GetContextPointer(cursor, unwContext, UNW_PPC64_R30, &contextPointers->R30); + GetContextPointer(cursor, unwContext, UNW_PPC64_R31, &contextPointers->R31); #else #error unsupported architecture #endif diff --git a/src/coreclr/pal/src/include/pal/context.h b/src/coreclr/pal/src/include/pal/context.h index fd37f92..fec5139 100644 --- a/src/coreclr/pal/src/include/pal/context.h +++ b/src/coreclr/pal/src/include/pal/context.h @@ -75,6 +75,47 @@ using asm_sigcontext::_xstate; #define MCREG_R14(mc) ((mc).gregs[14]) #define MCREG_R15(mc) ((mc).gregs[15]) +#elif HOST_POWERPC64 + +#define MCREG_R0(mc) ((mc).gp_regs[0]) +#define MCREG_R1(mc) ((mc).gp_regs[1]) +#define MCREG_R2(mc) ((mc).gp_regs[2]) +#define MCREG_R3(mc) ((mc).gp_regs[3]) +#define MCREG_R4(mc) ((mc).gp_regs[4]) +#define MCREG_R5(mc) ((mc).gp_regs[5]) +#define MCREG_R6(mc) ((mc).gp_regs[6]) +#define MCREG_R7(mc) ((mc).gp_regs[7]) +#define MCREG_R8(mc) ((mc).gp_regs[8]) +#define MCREG_R9(mc) ((mc).gp_regs[9]) +#define MCREG_R10(mc) ((mc).gp_regs[10]) +#define MCREG_R11(mc) ((mc).gp_regs[11]) +#define MCREG_R12(mc) ((mc).gp_regs[12]) +#define MCREG_R13(mc) ((mc).gp_regs[13]) +#define MCREG_R14(mc) ((mc).gp_regs[14]) +#define MCREG_R15(mc) ((mc).gp_regs[15]) +#define MCREG_R16(mc) ((mc).gp_regs[16]) +#define MCREG_R17(mc) ((mc).gp_regs[17]) +#define MCREG_R18(mc) ((mc).gp_regs[18]) +#define MCREG_R19(mc) ((mc).gp_regs[19]) +#define MCREG_R20(mc) ((mc).gp_regs[20]) +#define MCREG_R21(mc) ((mc).gp_regs[21]) +#define MCREG_R22(mc) ((mc).gp_regs[22]) +#define MCREG_R23(mc) ((mc).gp_regs[23]) +#define MCREG_R24(mc) ((mc).gp_regs[24]) +#define MCREG_R25(mc) ((mc).gp_regs[25]) +#define MCREG_R26(mc) ((mc).gp_regs[26]) +#define MCREG_R27(mc) ((mc).gp_regs[27]) +#define MCREG_R28(mc) ((mc).gp_regs[28]) +#define MCREG_R29(mc) ((mc).gp_regs[29]) +#define MCREG_R30(mc) ((mc).gp_regs[30]) +#define MCREG_R31(mc) ((mc).gp_regs[31]) +#define MCREG_Nip(mc) ((mc).gp_regs[32]) +#define MCREG_Msr(mc) ((mc).gp_regs[33]) +#define MCREG_Ctr(mc) ((mc).gp_regs[35]) +#define MCREG_Link(mc) ((mc).gp_regs[36]) +#define MCREG_Xer(mc) ((mc).gp_regs[37]) +#define MCREG_Ccr(mc) ((mc).gp_regs[38]) + #elif HAVE___GREGSET_T #ifdef HOST_64BIT @@ -756,6 +797,47 @@ const VfpSigFrame* GetConstNativeSigSimdContext(const native_context_t *mc) #define PTREG_Pc(ptreg) ((ptreg).csr_epc) #endif // HOST_LOONGARCH64 +#if defined(HOST_POWERPC64) +#define PTREG_R0(ptreg) ((ptreg).gpr[0]) +#define PTREG_R1(ptreg) ((ptreg).gpr[1]) +#define PTREG_R2(ptreg) ((ptreg).gpr[2]) +#define PTREG_R3(ptreg) ((ptreg).gpr[3]) +#define PTREG_R4(ptreg) ((ptreg).gpr[4]) +#define PTREG_R5(ptreg) ((ptreg).gpr[5]) +#define PTREG_R6(ptreg) ((ptreg).gpr[6]) +#define PTREG_R7(ptreg) ((ptreg).gpr[7]) +#define PTREG_R8(ptreg) ((ptreg).gpr[8]) +#define PTREG_R9(ptreg) ((ptreg).gpr[9]) +#define PTREG_R10(ptreg) ((ptreg).gpr[10]) +#define PTREG_R11(ptreg) ((ptreg).gpr[11]) +#define PTREG_R12(ptreg) ((ptreg).gpr[12]) +#define PTREG_R13(ptreg) ((ptreg).gpr[13]) +#define PTREG_R14(ptreg) ((ptreg).gpr[14]) +#define PTREG_R15(ptreg) ((ptreg).gpr[15]) +#define PTREG_R16(ptreg) ((ptreg).gpr[16]) +#define PTREG_R17(ptreg) ((ptreg).gpr[17]) +#define PTREG_R18(ptreg) ((ptreg).gpr[18]) +#define PTREG_R19(ptreg) ((ptreg).gpr[19]) +#define PTREG_R20(ptreg) ((ptreg).gpr[20]) +#define PTREG_R21(ptreg) ((ptreg).gpr[21]) +#define PTREG_R22(ptreg) ((ptreg).gpr[22]) +#define PTREG_R23(ptreg) ((ptreg).gpr[23]) +#define PTREG_R24(ptreg) ((ptreg).gpr[24]) +#define PTREG_R25(ptreg) ((ptreg).gpr[25]) +#define PTREG_R26(ptreg) ((ptreg).gpr[26]) +#define PTREG_R27(ptreg) ((ptreg).gpr[27]) +#define PTREG_R28(ptreg) ((ptreg).gpr[28]) +#define PTREG_R29(ptreg) ((ptreg).gpr[29]) +#define PTREG_R30(ptreg) ((ptreg).gpr[30]) +#define PTREG_R31(ptreg) ((ptreg).gpr[31]) +#define PTREG_Nip(ptreg) ((ptreg).nip) +#define PTREG_Msr(ptreg) ((ptreg).msr) +#define PTREG_Ctr(ptreg) ((ptreg).ctr) +#define PTREG_Link(ptreg) ((ptreg).link) +#define PTREG_Xer(ptreg) ((ptreg).xer) +#define PTREG_Ccr(ptreg) ((ptreg).ccr) +#else //HOST_POWERPC64 + #define PTREG_Rbx(ptreg) ((ptreg).rbx) #define PTREG_Rcx(ptreg) ((ptreg).rcx) #define PTREG_Rdx(ptreg) ((ptreg).rdx) @@ -776,6 +858,7 @@ const VfpSigFrame* GetConstNativeSigSimdContext(const native_context_t *mc) #define PTREG_R14(ptreg) ((ptreg).r14) #define PTREG_R15(ptreg) ((ptreg).r15) +#endif //HOST_POWERPC64 #else // HOST_64BIT #if defined(HOST_ARM) @@ -881,6 +964,8 @@ inline static DWORD64 CONTEXTGetPC(LPCONTEXT pContext) return pContext->Pc; #elif defined(HOST_S390X) return pContext->PSWAddr; +#elif defined(HOST_POWERPC64) + return pContext->Nip; #else #error "don't know how to get the program counter for this architecture" #endif @@ -898,6 +983,8 @@ inline static void CONTEXTSetPC(LPCONTEXT pContext, DWORD64 pc) pContext->Pc = pc; #elif defined(HOST_S390X) pContext->PSWAddr = pc; +#elif defined(HOST_POWERPC64) + pContext->Nip = pc; #else #error "don't know how to set the program counter for this architecture" #endif @@ -917,6 +1004,8 @@ inline static DWORD64 CONTEXTGetFP(LPCONTEXT pContext) return pContext->Fp; #elif defined(HOST_S390X) return pContext->R11; +#elif defined(HOST_POWERPC64) + return pContext->R31; #else #error "don't know how to get the frame pointer for this architecture" #endif diff --git a/src/coreclr/pal/src/thread/context.cpp b/src/coreclr/pal/src/thread/context.cpp index 5c9f89d..92d2ef0 100644 --- a/src/coreclr/pal/src/thread/context.cpp +++ b/src/coreclr/pal/src/thread/context.cpp @@ -45,6 +45,8 @@ extern PGET_GCMARKER_EXCEPTION_CODE g_getGcMarkerExceptionCode; #define CONTEXT_ALL_FLOATING CONTEXT_FLOATING_POINT #elif defined(HOST_S390X) #define CONTEXT_ALL_FLOATING CONTEXT_FLOATING_POINT +#elif defined(HOST_POWERPC64) +#define CONTEXT_ALL_FLOATING CONTEXT_FLOATING_POINT #else #error Unexpected architecture. #endif @@ -232,6 +234,50 @@ typedef int __ptrace_request; ASSIGN_REG(R13) \ ASSIGN_REG(R14) +#elif defined(HOST_POWERPC64) +#define ASSIGN_CONTROL_REGS \ + ASSIGN_REG(Nip) \ + ASSIGN_REG(Msr) \ + ASSIGN_REG(Ctr) \ + ASSIGN_REG(Link) \ + ASSIGN_REG(Xer) \ + ASSIGN_REG(Ccr) \ + ASSIGN_REG(R31) \ + +#define ASSIGN_INTEGER_REGS \ + ASSIGN_REG(R0) \ + ASSIGN_REG(R1) \ + ASSIGN_REG(R2) \ + ASSIGN_REG(R3) \ + ASSIGN_REG(R4) \ + ASSIGN_REG(R5) \ + ASSIGN_REG(R5) \ + ASSIGN_REG(R6) \ + ASSIGN_REG(R7) \ + ASSIGN_REG(R8) \ + ASSIGN_REG(R9) \ + ASSIGN_REG(R10) \ + ASSIGN_REG(R11) \ + ASSIGN_REG(R12) \ + ASSIGN_REG(R13) \ + ASSIGN_REG(R14) \ + ASSIGN_REG(R15) \ + ASSIGN_REG(R16) \ + ASSIGN_REG(R17) \ + ASSIGN_REG(R18) \ + ASSIGN_REG(R19) \ + ASSIGN_REG(R20) \ + ASSIGN_REG(R21) \ + ASSIGN_REG(R22) \ + ASSIGN_REG(R23) \ + ASSIGN_REG(R24) \ + ASSIGN_REG(R25) \ + ASSIGN_REG(R26) \ + ASSIGN_REG(R27) \ + ASSIGN_REG(R28) \ + ASSIGN_REG(R29) \ + ASSIGN_REG(R30) + #else #error "Don't know how to assign registers on this architecture" #endif @@ -499,7 +545,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) #undef ASSIGN_REG #if !HAVE_FPREGS_WITH_CW -#if (HAVE_GREGSET_T || HAVE___GREGSET_T) && !defined(HOST_S390X) && !defined(HOST_LOONGARCH64) +#if (HAVE_GREGSET_T || HAVE___GREGSET_T) && !defined(HOST_S390X) && !defined(HOST_LOONGARCH64) && !defined(HOST_POWERPC64) #if HAVE_GREGSET_T if (native->uc_mcontext.fpregs == nullptr) #elif HAVE___GREGSET_T @@ -511,7 +557,7 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native) // whether CONTEXT_FLOATING_POINT is set in the CONTEXT's flags. return; } -#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X && !HOST_LOONGARCH64 +#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X && !HOST_LOONGARCH64 && !HOST_POWERPC64 #endif // !HAVE_FPREGS_WITH_CW if ((lpContext->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) @@ -634,7 +680,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex #undef ASSIGN_REG #if !HAVE_FPREGS_WITH_CW -#if (HAVE_GREGSET_T || HAVE___GREGSET_T) && !defined(HOST_S390X) && !defined(HOST_LOONGARCH64) +#if (HAVE_GREGSET_T || HAVE___GREGSET_T) && !defined(HOST_S390X) && !defined(HOST_LOONGARCH64) && !defined(HOST_POWERPC64) #if HAVE_GREGSET_T if (native->uc_mcontext.fpregs == nullptr) #elif HAVE___GREGSET_T @@ -656,7 +702,7 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex // Bail out regardless of whether the caller wanted CONTEXT_FLOATING_POINT or CONTEXT_XSTATE return; } -#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X +#endif // (HAVE_GREGSET_T || HAVE___GREGSET_T) && !HOST_S390X && !HOST_POWERPC64 #endif // !HAVE_FPREGS_WITH_CW if ((contextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) @@ -785,6 +831,8 @@ LPVOID GetNativeContextPC(const native_context_t *context) return (LPVOID) MCREG_Pc(context->uc_mcontext); #elif defined(HOST_S390X) return (LPVOID) MCREG_PSWAddr(context->uc_mcontext); +#elif defined(HOST_POWERPC64) + return (LPVOID) MCREG_Nip(context->uc_mcontext); #else # error implement me for this architecture #endif @@ -817,6 +865,8 @@ LPVOID GetNativeContextSP(const native_context_t *context) return (LPVOID) MCREG_Sp(context->uc_mcontext); #elif defined(HOST_S390X) return (LPVOID) MCREG_R15(context->uc_mcontext); +#elif defined(HOST_POWERPC64) + return (LPVOID) MCREG_R31(context->uc_mcontext); #else # error implement me for this architecture #endif diff --git a/src/coreclr/unwinder/ppc64le/unwinder_ppc64le.cpp b/src/coreclr/unwinder/ppc64le/unwinder_ppc64le.cpp new file mode 100644 index 0000000..66cb24b --- /dev/null +++ b/src/coreclr/unwinder/ppc64le/unwinder_ppc64le.cpp @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// + +#include "stdafx.h" +#include "utilcode.h" +#include "crosscomp.h" + +#error Unsupported platform + diff --git a/src/coreclr/vm/ppc64le/unixstubs.cpp b/src/coreclr/vm/ppc64le/unixstubs.cpp new file mode 100644 index 0000000..d51902a --- /dev/null +++ b/src/coreclr/vm/ppc64le/unixstubs.cpp @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "common.h" + +extern "C" +{ + void RedirectForThrowControl() + { + PORTABILITY_ASSERT("Implement for PAL"); + } +}; diff --git a/src/mono/mono/mini/tramp-ppc.c b/src/mono/mono/mini/tramp-ppc.c index 956cce2..3a78709 100644 --- a/src/mono/mono/mini/tramp-ppc.c +++ b/src/mono/mono/mini/tramp-ppc.c @@ -53,7 +53,7 @@ mono_ppc_create_ftnptr (guint8 *code) static guint32 branch_for_target_reachable (guint8 *branch, guint8 *target) { - gint diff = target - branch; + gint64 diff = target - branch; g_assert ((diff & 3) == 0); if (diff >= 0) { if (diff <= 33554431) diff --git a/src/native/external/libunwind.cmake b/src/native/external/libunwind.cmake index c304fd1..21bd0d7 100644 --- a/src/native/external/libunwind.cmake +++ b/src/native/external/libunwind.cmake @@ -333,6 +333,34 @@ set(libunwind_s390x_la_SOURCES_s390x s390x/Gget_proc_info.c s390x/Gregs.c s390x/Gresume.c s390x/Gis_signal_frame.c s390x/Gstep.c ) +# The list of files that go both into libunwind and libunwind-ppc64le: +set(libunwind_la_SOURCES_ppc64le_common + ${libunwind_la_SOURCES_common} + ppc64/is_fpreg.c ppc64/regname.c ppc64/get_func_addr.c +) + +# The list of files that go into libunwind: +set(libunwind_la_SOURCES_ppc64le + ${libunwind_la_SOURCES_ppc64le_common} + ${libunwind_la_SOURCES_local} + ppc64/setcontext.S + ppc64/Lapply_reg_state.c ppc64/Lreg_states_iterate.c + ppc64/Lcreate_addr_space.c ppc/Lget_save_loc.c ppc64/Lglobal.c + ppc64/Linit.c ppc/Linit_local.c + ppc64/Lregs.c ppc64/Lresume.c + ppc/Lis_signal_frame.c ppc64/Lstep.c +) + +# The list of files that go into libunwind-ppc64le: +set(libunwind_ppc64le_la_SOURCES_ppc64le + ${libunwind_la_SOURCES_ppc64le_common} + ${libunwind_la_SOURCES_generic} + ppc64/Gapply_reg_state.c ppc64/Greg_states_iterate.c + ppc64/Gcreate_addr_space.c ppc/Gget_save_loc.c ppc64/Gglobal.c + ppc64/Ginit.c ppc/Ginit_local.c + ppc64/Gregs.c ppc64/Gresume.c + ppc/Gis_signal_frame.c ppc64/Gstep.c +) if(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_ARCH_ARM64) @@ -364,6 +392,10 @@ if(CLR_CMAKE_HOST_UNIX) set(libunwind_la_SOURCES ${libunwind_la_SOURCES_s390x}) set(libunwind_remote_la_SOURCES ${libunwind_s390x_la_SOURCES_s390x}) set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) + elseif(CLR_CMAKE_HOST_ARCH_POWERPC64) + set(libunwind_la_SOURCES ${libunwind_la_SOURCES_ppc64le}) + set(libunwind_remote_la_SOURCES ${libunwind_ppc64le_la_SOURCES_ppc64le}) + set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(libunwind_la_SOURCES ${libunwind_la_SOURCES_loongarch}) set(libunwind_remote_la_SOURCES ${libunwind_loongarch_la_SOURCES_loongarch}) @@ -418,6 +450,10 @@ else(CLR_CMAKE_HOST_UNIX) set(libunwind_la_SOURCES ${libunwind_la_SOURCES_s390x}) set(libunwind_remote_la_SOURCES ${libunwind_s390x_la_SOURCES_s390x}) set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) + elseif(CLR_CMAKE_TARGET_ARCH_POWERPC64) + set(libunwind_la_SOURCES ${libunwind_la_SOURCES_ppc64le}) + set(libunwind_remote_la_SOURCES ${libunwind_ppc64le_la_SOURCES_ppc64le}) + set(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) endif() set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc) diff --git a/src/native/external/libunwind/CMakeLists.txt b/src/native/external/libunwind/CMakeLists.txt index dc12eb7..9fca17d 100644 --- a/src/native/external/libunwind/CMakeLists.txt +++ b/src/native/external/libunwind/CMakeLists.txt @@ -35,6 +35,11 @@ elseif ('$ENV{TARGET}' STREQUAL 'loongarch64-linux-gnu') set(arch loongarch64) add_definitions(-D__loongarch64) add_definitions(-D__linux__) +elseif ('$ENV{TARGET}' STREQUAL 'powerpc64-linux-gnu') + set(TARGET_POWERPC64 1) + set(arch ppc64le) + add_definitions(-D__ppc64le__) + add_definitions(-D__linux__) else () message(FATAL_ERROR "Unrecognize value in environment variable TARGET") endif () diff --git a/src/native/external/libunwind/src/CMakeLists.txt b/src/native/external/libunwind/src/CMakeLists.txt index 82ef68a..3971116 100644 --- a/src/native/external/libunwind/src/CMakeLists.txt +++ b/src/native/external/libunwind/src/CMakeLists.txt @@ -297,6 +297,35 @@ SET(libunwind_s390x_la_SOURCES_s390x s390x/Gis_signal_frame.c s390x/Gstep.c ) +## The list of files that go both into libunwind and libunwind-ppc64le: +SET(libunwind_la_SOURCES_ppc64le_common + ${libunwind_la_SOURCES_common} + ppc64/is_fpreg.c ppc64/regname.c ppc64/get_func_addr.c +) + +# The list of files that go into libunwind: +SET(libunwind_la_SOURCES_ppc64le + ${libunwind_la_SOURCES_ppc64le_common} + ${libunwind_la_SOURCES_local} + ppc64/setcontext.S + ppc64/Lapply_reg_state.c ppc64/Lreg_states_iterate.c + ppc64/Lcreate_addr_space.c ppc/Lget_save_loc.c ppc64/Lglobal.c + ppc64/Linit.c ppc/Linit_local.c + ppc64/Lregs.c ppc64/Lresume.c + ppc/Lis_signal_frame.c ppc64/Lstep.c +) + +# The list of files that go into libunwind-ppc64le: +SET(libunwind_ppc64le_la_SOURCES_ppc64le + ${libunwind_la_SOURCES_ppc64le_common} + ${libunwind_la_SOURCES_generic} + ppc64/Gapply_reg_state.c ppc64/Greg_states_iterate.c + ppc64/Gcreate_addr_space.c ppc/Gget_save_loc.c ppc64/Gglobal.c + ppc64/Ginit.c ppc/Ginit_local.c + ppc64/Gregs.c ppc64/Gresume.c + ppc/Gis_signal_frame.c ppc64/Gstep.c +) + # The list of files that go into libunwind and libunwind-loongarch64: SET(libunwind_la_SOURCES_loongarch_common ${libunwind_la_SOURCES_common} @@ -343,6 +372,10 @@ elseif(TARGET_S390X) SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_s390x}) SET(libunwind_remote_la_SOURCES ${libunwind_s390x_la_SOURCES_s390x}) SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) +elseif(CLR_CMAKE_HOST_ARCH_POWERPC64) + SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_ppc64le}) + SET(libunwind_remote_la_SOURCES ${libunwind_ppc64le_la_SOURCES_ppc64le}) + SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) elseif(TARGET_LOONGARCH64) SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_loongarch64}) SET(libunwind_remote_la_SOURCES ${libunwind_loongarch64_la_SOURCES_loongarch}) diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 3da5f2c..9f999f0 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -29,6 +29,8 @@ if(CLR_CMAKE_HOST_UNIX) set(arch s390x) elseif(CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(arch loongarch64) + elseif(CLR_CMAKE_HOST_ARCH_POWERPC64) + set(arch ppc64le) endif () # Disable warning due to incorrect format specifier in debugging printf via the Debug macro diff --git a/src/native/libs/System.Native/pal_runtimeinformation.c b/src/native/libs/System.Native/pal_runtimeinformation.c index a2a8fb2..028ae5f 100644 --- a/src/native/libs/System.Native/pal_runtimeinformation.c +++ b/src/native/libs/System.Native/pal_runtimeinformation.c @@ -64,6 +64,7 @@ enum ARCH_S390X, ARCH_LOONGARCH64, ARCH_ARMV6, + ARCH_POWERPC64, }; int32_t SystemNative_GetOSArchitecture() @@ -127,6 +128,11 @@ int32_t SystemNative_GetOSArchitecture() result = ARCH_S390X; } + else if (strcmp("ppc64le", isa) == 0) + { + result = ARCH_POWERPC64; + } + else if (strcmp("loongarch64", isa) == 0) { result = ARCH_LOONGARCH64; -- 2.7.4