Since quite some time I keep splitting/cleaning up/rebasing and fixing the 2 year old PowerPC64le patchset from 2019 (done by Timothy Pearson): [1]
The goal is to have a winelib base for Hangover [2] on PowerPC64 and there's also interest in having winelib for crosscompiling [3].
This rebase meanwhile matured, especially end of last year, and I hope it can get upstreamed now that wine-6.0 is out and the patch flood after it calmed down a bit.
[1] https://github.com/madscientist159/wine/commits/master [2] https://github.com/AndreRH/hangover [3] https://wiki.raptorcs.com/wiki/Porting/Wine
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: Timothy Pearson tpearson@raptorengineering.com Signed-off-by: André Hentschel nerv@dawncrow.de --- include/basetsd.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/include/basetsd.h b/include/basetsd.h index 7087b592d1a..761af4d5214 100644 --- a/include/basetsd.h +++ b/include/basetsd.h @@ -275,6 +275,10 @@ typedef ULONG_PTR KAFFINITY, *PKAFFINITY; # undef WORDS_BIGENDIAN #elif defined(__x86_64__) # undef WORDS_BIGENDIAN +#elif defined(__powerpc64__) && defined(__BIG_ENDIAN__) +# define WORDS_BIGENDIAN +#elif defined(__powerpc64__) +# undef WORDS_BIGENDIAN #elif defined(__powerpc__) # define WORDS_BIGENDIAN #elif defined(__ALPHA__)
Signed-off-by: André Hentschel nerv@dawncrow.de --- include/wine/port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/wine/port.h b/include/wine/port.h index 9c2eb7277bf..15d1ed6315c 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -85,7 +85,7 @@ typedef int ssize_t; #else /* _WIN32 */
#ifndef __int64 -# if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64) +# if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || defined(_WIN64) # define __int64 long # else # define __int64 long long
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/winecrt0/setjmp.c | 95 ++++++++++++++++++++++++++++++++++++++++ include/wine/exception.h | 2 + 2 files changed, 97 insertions(+)
diff --git a/dlls/winecrt0/setjmp.c b/dlls/winecrt0/setjmp.c index 642e78e355e..6c493020b59 100644 --- a/dlls/winecrt0/setjmp.c +++ b/dlls/winecrt0/setjmp.c @@ -201,6 +201,101 @@ __ASM_GLOBAL_FUNC( __wine_longjmp, "mov x0, x1\n\t" /* retval */ "ret" )
+#elif defined(__powerpc64__) + +__ASM_GLOBAL_FUNC( __wine_setjmpex, + "std 4, 0(3)\n\t" /* Frame */ + "std 14, 8(3)\n\t" /* GPR14 */ + "std 15, 16(3)\n\t" /* GPR15 */ + "std 16, 24(3)\n\t" /* GPR16 */ + "std 17, 32(3)\n\t" /* GPR17 */ + "std 18, 40(3)\n\t" /* GPR18 */ + "std 19, 48(3)\n\t" /* GPR19 */ + "std 20, 56(3)\n\t" /* GPR20 */ + "std 21, 64(3)\n\t" /* GPR21 */ + "std 22, 72(3)\n\t" /* GPR22 */ + "std 23, 80(3)\n\t" /* GPR23 */ + "std 24, 88(3)\n\t" /* GPR24 */ + "std 25, 96(3)\n\t" /* GPR25 */ + "std 26, 104(3)\n\t" /* GPR26 */ + "std 27, 112(3)\n\t" /* GPR27 */ + "std 28, 120(3)\n\t" /* GPR28 */ + "std 29, 128(3)\n\t" /* GPR29 */ + "std 30, 136(3)\n\t" /* GPR30 */ + "std 31, 144(3)\n\t" /* GPR31 */ + "std 1, 152(3)\n\t" /* SP */ + "std 2, 160(3)\n\t" /* TOC */ + "mfcr 0\n\t" + "stw 0, 168(3)\n\t" /* CR (32-Bit) */ + "mflr 0\n\t" + "std 0, 176(3)\n\t" /* LR */ + "stfd 14, 184(3)\n\t" /* FP14 */ + "stfd 15, 192(3)\n\t" /* FP15 */ + "stfd 16, 200(3)\n\t" /* FP16 */ + "stfd 17, 208(3)\n\t" /* FP17 */ + "stfd 18, 216(3)\n\t" /* FP18 */ + "stfd 19, 224(3)\n\t" /* FP19 */ + "stfd 20, 232(3)\n\t" /* FP20 */ + "stfd 21, 240(3)\n\t" /* FP21 */ + "stfd 22, 248(3)\n\t" /* FP22 */ + "stfd 23, 256(3)\n\t" /* FP23 */ + "stfd 24, 264(3)\n\t" /* FP24 */ + "stfd 25, 272(3)\n\t" /* FP25 */ + "stfd 26, 280(3)\n\t" /* FP26 */ + "stfd 27, 288(3)\n\t" /* FP27 */ + "stfd 28, 296(3)\n\t" /* FP28 */ + "stfd 29, 304(3)\n\t" /* FP29 */ + "stfd 30, 312(3)\n\t" /* FP30 */ + "stfd 31, 320(3)\n\t" /* FP31 */ + "li 3, 0\n\t" /* return 0 */ + "blr" ) + +__ASM_GLOBAL_FUNC( __wine_longjmp, + "ld 14, 8(3)\n\t" /* GPR14 */ + "ld 15, 16(3)\n\t" /* GPR15 */ + "ld 16, 24(3)\n\t" /* GPR16 */ + "ld 17, 32(3)\n\t" /* GPR17 */ + "ld 18, 40(3)\n\t" /* GPR18 */ + "ld 19, 48(3)\n\t" /* GPR19 */ + "ld 20, 56(3)\n\t" /* GPR20 */ + "ld 21, 64(3)\n\t" /* GPR21 */ + "ld 22, 72(3)\n\t" /* GPR22 */ + "ld 23, 80(3)\n\t" /* GPR23 */ + "ld 24, 88(3)\n\t" /* GPR24 */ + "ld 25, 96(3)\n\t" /* GPR25 */ + "ld 26, 104(3)\n\t" /* GPR26 */ + "ld 27, 112(3)\n\t" /* GPR27 */ + "ld 28, 120(3)\n\t" /* GPR28 */ + "ld 29, 128(3)\n\t" /* GPR29 */ + "ld 30, 136(3)\n\t" /* GPR30 */ + "ld 31, 144(3)\n\t" /* GPR31 */ + "ld 1, 152(3)\n\t" /* SP */ + "ld 2, 160(3)\n\t" /* TOC */ + "lwz 0, 168(3)\n\t" /* CR (32-Bit) */ + "mtcr 0\n\t" + "ld 0, 176(3)\n\t" /* LR */ + "mtlr 0\n\t" + "lfd 14, 184(3)\n\t" /* FP14 */ + "lfd 15, 192(3)\n\t" /* FP15 */ + "lfd 16, 200(3)\n\t" /* FP16 */ + "lfd 17, 208(3)\n\t" /* FP17 */ + "lfd 18, 216(3)\n\t" /* FP18 */ + "lfd 19, 224(3)\n\t" /* FP19 */ + "lfd 20, 232(3)\n\t" /* FP20 */ + "lfd 21, 240(3)\n\t" /* FP21 */ + "lfd 22, 248(3)\n\t" /* FP22 */ + "lfd 23, 256(3)\n\t" /* FP23 */ + "lfd 24, 264(3)\n\t" /* FP24 */ + "lfd 25, 272(3)\n\t" /* FP25 */ + "lfd 26, 280(3)\n\t" /* FP26 */ + "lfd 27, 288(3)\n\t" /* FP27 */ + "lfd 28, 296(3)\n\t" /* FP28 */ + "lfd 29, 304(3)\n\t" /* FP29 */ + "lfd 30, 312(3)\n\t" /* FP30 */ + "lfd 31, 320(3)\n\t" /* FP31 */ + "mr 3, 4\n\t" /* return retval */ + "blr" ) + #else
int __cdecl __wine_setjmpex( __wine_jmp_buf *buf, EXCEPTION_REGISTRATION_RECORD *frame ) diff --git a/include/wine/exception.h b/include/wine/exception.h index a2b0bb08dc3..fe5252ea70f 100644 --- a/include/wine/exception.h +++ b/include/wine/exception.h @@ -99,6 +99,8 @@ typedef struct { DECLSPEC_ALIGN(16) struct { unsigned __int64 Part[2]; } reg[16] typedef struct { int reg[28]; } __wine_jmp_buf; #elif defined(__aarch64__) typedef struct { __int64 reg[24]; } __wine_jmp_buf; +#elif defined(__powerpc64__) +typedef struct { __int64 reg[48]; } __wine_jmp_buf; #else typedef struct { int reg; } __wine_jmp_buf; #endif
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- include/msvcrt/corecrt.h | 3 +++ include/windef.h | 3 +++ 2 files changed, 6 insertions(+)
diff --git a/include/msvcrt/corecrt.h b/include/msvcrt/corecrt.h index 4adbe0920f6..7559d68ab79 100644 --- a/include/msvcrt/corecrt.h +++ b/include/msvcrt/corecrt.h @@ -83,6 +83,9 @@ # define __stdcall __attribute__((pcs("aapcs-vfp"))) # elif defined(__aarch64__) && defined (__GNUC__) && __has_attribute(ms_abi) # define __stdcall __attribute__((ms_abi)) +# elif defined(__powerpc64__) && defined (__GNUC__) && !defined (__clang__) + /* ppc64 relies on long calls being generated for thunks (r2 save / restore) */ +# define __stdcall __attribute__((__longcall__)) # else /* __i386__ */ # define __stdcall # endif /* __i386__ */ diff --git a/include/windef.h b/include/windef.h index ac2ec619fbd..b69cbe51f6d 100644 --- a/include/windef.h +++ b/include/windef.h @@ -76,6 +76,9 @@ extern "C" { # define __stdcall __attribute__((pcs("aapcs-vfp"))) # elif defined(__aarch64__) && defined (__GNUC__) && __has_attribute(ms_abi) # define __stdcall __attribute__((ms_abi)) +# elif defined(__powerpc64__) && defined (__GNUC__) && !defined (__clang__) + /* ppc64 relies on long calls being generated for thunks (r2 save / restore) */ +# define __stdcall __attribute__((__longcall__)) # else /* __i386__ */ # define __stdcall # endif /* __i386__ */
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- tools/widl/widl.c | 38 +++++++++++++++++++++++--------------- tools/widl/widl.h | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 333351bc11b..99b24e86fdc 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -97,6 +97,8 @@ static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSIO enum target_cpu target_cpu = CPU_x86; #elif defined(__x86_64__) enum target_cpu target_cpu = CPU_x86_64; +#elif defined(__powerpc64__) +enum target_cpu target_cpu = CPU_POWERPC64; #elif defined(__powerpc__) enum target_cpu target_cpu = CPU_POWERPC; #elif defined(__arm__) @@ -281,21 +283,23 @@ static void set_target( const char *target ) enum target_cpu cpu; } cpu_names[] = { - { "i386", CPU_x86 }, - { "i486", CPU_x86 }, - { "i586", CPU_x86 }, - { "i686", CPU_x86 }, - { "i786", CPU_x86 }, - { "amd64", CPU_x86_64 }, - { "x86_64", CPU_x86_64 }, - { "powerpc", CPU_POWERPC }, - { "arm", CPU_ARM }, - { "armv5", CPU_ARM }, - { "armv6", CPU_ARM }, - { "armv7", CPU_ARM }, - { "armv7a", CPU_ARM }, - { "arm64", CPU_ARM64 }, - { "aarch64", CPU_ARM64 }, + { "i386", CPU_x86 }, + { "i486", CPU_x86 }, + { "i586", CPU_x86 }, + { "i686", CPU_x86 }, + { "i786", CPU_x86 }, + { "amd64", CPU_x86_64 }, + { "x86_64", CPU_x86_64 }, + { "powerpc", CPU_POWERPC }, + { "powerpc64", CPU_POWERPC64 }, + { "powerpc64le", CPU_POWERPC64 }, + { "arm", CPU_ARM }, + { "armv5", CPU_ARM }, + { "armv6", CPU_ARM }, + { "armv7", CPU_ARM }, + { "armv7a", CPU_ARM }, + { "arm64", CPU_ARM64 }, + { "aarch64", CPU_ARM64 }, };
unsigned int i; @@ -796,6 +800,10 @@ int main(int argc,char *argv[]) if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" ); pointer_size = 8; break; + case CPU_POWERPC64: + if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" ); + pointer_size = 8; + break; default: if (pointer_size == 8) error( "Cannot build 64-bit code for this CPU\n" ); pointer_size = 4; diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 4f4252e3ea3..bc6226c54fe 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -76,7 +76,7 @@ extern int char_number;
enum target_cpu { - CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64 + CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_POWERPC64, CPU_LAST = CPU_POWERPC64 };
extern enum target_cpu target_cpu;
Signed-off-by: André Hentschel nerv@dawncrow.de --- tools/wrc/wrc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c index b260e20af07..1f2486f9ff7 100644 --- a/tools/wrc/wrc.c +++ b/tools/wrc/wrc.c @@ -328,7 +328,8 @@ static void set_target( const char *target ) if (!(p = strchr( cpu, '-' ))) error( "Invalid target specification '%s'\n", target ); *p = 0; if (!strcmp( cpu, "amd64" ) || !strcmp( cpu, "x86_64" ) || - !strcmp( cpu, "ia64" ) || !strcmp( cpu, "aarch64" )) + !strcmp( cpu, "ia64" ) || !strcmp( cpu, "aarch64" ) || + !strcmp( cpu, "ppc64" ) || !strcmp( cpu, "powerpc64le" )) pointer_size = 8; else pointer_size = 4;
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/setupapi/devinst.c | 2 ++ dlls/setupapi/fakedll.c | 4 ++++ include/winnt.h | 2 ++ 3 files changed, 8 insertions(+)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index de0413e74f5..3c72c82a26b 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -61,6 +61,8 @@ static const WCHAR NtPlatformExtension[] = {'.','N','T','a','m','d','6','4',0}; static const WCHAR NtPlatformExtension[] = {'.','N','T','a','r','m',0}; #elif defined(__aarch64__) static const WCHAR NtPlatformExtension[] = {'.','N','T','a','r','m','6','4',0}; +#elif defined(__powerpc64__) +static const WCHAR NtPlatformExtension[] = {'.','N','T','p','p','c','6','4',0}; #endif static const WCHAR Signature[] = {'S','i','g','n','a','t','u','r','e',0}; static const WCHAR Version[] = {'V','e','r','s','i','o','n',0}; diff --git a/dlls/setupapi/fakedll.c b/dlls/setupapi/fakedll.c index cf219916400..f020e275248 100644 --- a/dlls/setupapi/fakedll.c +++ b/dlls/setupapi/fakedll.c @@ -281,6 +281,8 @@ static BOOL build_fake_dll( HANDLE file, const WCHAR *name ) nt->FileHeader.Machine = IMAGE_FILE_MACHINE_ARM64; #elif defined __arm__ nt->FileHeader.Machine = IMAGE_FILE_MACHINE_ARMNT; +#elif defined __powerpc64__ + nt->FileHeader.Machine = IMAGE_FILE_MACHINE_POWERPC64; #else nt->FileHeader.Machine = IMAGE_FILE_MACHINE_I386; #endif @@ -711,6 +713,8 @@ static BOOL CALLBACK register_manifest( HMODULE module, const WCHAR *type, WCHAR static const char current_arch[] = "arm"; #elif defined __aarch64__ static const char current_arch[] = "arm64"; +#elif defined __powerpc64__ + static const char current_arch[] = "ppc64"; #else static const char current_arch[] = "none"; #endif diff --git a/include/winnt.h b/include/winnt.h index 5b3efe61385..0c9487bcffc 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -689,6 +689,7 @@ typedef DWORD FLONG; #define PROCESSOR_ARCHITECTURE_ARM64 12 #define PROCESSOR_ARCHITECTURE_ARM32_ON_WIN64 13 #define PROCESSOR_ARCHITECTURE_IA32_ON_ARM64 14 +#define PROCESSOR_ARCHITECTURE_PPC64 200 /* Wine extension */ #define PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
/* dwProcessorType */ @@ -3046,6 +3047,7 @@ typedef struct _IMAGE_VXD_HEADER { #define IMAGE_FILE_MACHINE_AM33 0x01d3 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1 +#define IMAGE_FILE_MACHINE_POWERPC64 0x01f2 #define IMAGE_FILE_MACHINE_IA64 0x0200 #define IMAGE_FILE_MACHINE_MIPS16 0x0266 #define IMAGE_FILE_MACHINE_ALPHA64 0x0284
Signed-off-by: André Hentschel nerv@dawncrow.de --- include/winnt.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-)
diff --git a/include/winnt.h b/include/winnt.h index 0c9487bcffc..359a6a3a5fd 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -2262,8 +2262,121 @@ typedef struct _CONTEXT
#endif /* _MIPS_ */
+/* PowerPC 64-bit context definitions */ +#ifdef __powerpc64__ + +#define CONTEXT_POWERPC64 0x00800000 +#define CONTEXT_CONTROL 0x0001 +#define CONTEXT_FLOATING_POINT 0x0002 +#define CONTEXT_INTEGER 0x0004 +#define CONTEXT_DEBUG_REGISTERS 0x0008 +#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER) +#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | \ + CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS) + +#define EXCEPTION_READ_FAULT 0 +#define EXCEPTION_WRITE_FAULT 1 +#define EXCEPTION_EXECUTE_FAULT 8 + +typedef struct +{ + /* These are selected by CONTEXT_FLOATING_POINT */ + double Fpr0; + double Fpr1; + double Fpr2; + double Fpr3; + double Fpr4; + double Fpr5; + double Fpr6; + double Fpr7; + double Fpr8; + double Fpr9; + double Fpr10; + double Fpr11; + double Fpr12; + double Fpr13; + double Fpr14; + double Fpr15; + double Fpr16; + double Fpr17; + double Fpr18; + double Fpr19; + double Fpr20; + double Fpr21; + double Fpr22; + double Fpr23; + double Fpr24; + double Fpr25; + double Fpr26; + double Fpr27; + double Fpr28; + double Fpr29; + double Fpr30; + double Fpr31; + double Fpscr; + + /* These are selected by CONTEXT_INTEGER */ + DWORD64 Gpr0; + DWORD64 Gpr1; + DWORD64 Gpr2; + DWORD64 Gpr3; + DWORD64 Gpr4; + DWORD64 Gpr5; + DWORD64 Gpr6; + DWORD64 Gpr7; + DWORD64 Gpr8; + DWORD64 Gpr9; + DWORD64 Gpr10; + DWORD64 Gpr11; + DWORD64 Gpr12; + DWORD64 Gpr13; + DWORD64 Gpr14; + DWORD64 Gpr15; + DWORD64 Gpr16; + DWORD64 Gpr17; + DWORD64 Gpr18; + DWORD64 Gpr19; + DWORD64 Gpr20; + DWORD64 Gpr21; + DWORD64 Gpr22; + DWORD64 Gpr23; + DWORD64 Gpr24; + DWORD64 Gpr25; + DWORD64 Gpr26; + DWORD64 Gpr27; + DWORD64 Gpr28; + DWORD64 Gpr29; + DWORD64 Gpr30; + DWORD64 Gpr31; + + DWORD64 Cr; + DWORD64 Xer; + + /* These are selected by CONTEXT_CONTROL */ + DWORD64 Msr; + DWORD64 Iar; /* Instruction Address Register , aka PC ... */ + DWORD64 Lr; + DWORD64 Ctr; + + DWORD64 ContextFlags; + + DWORD64 Dar; /* Fault registers for coredump */ + DWORD64 Dsisr; + DWORD64 Trap; /* number of powerpc exception taken */ + + /* These are selected by CONTEXT_DEBUG_REGISTERS */ + DWORD64 Dr0; + DWORD64 Dr1; + DWORD64 Dr2; + DWORD64 Dr3; + DWORD64 Dr4; + DWORD64 Dr5; + DWORD64 Dr6; + DWORD64 Dr7; +} CONTEXT, *PCONTEXT; + /* PowerPC context definitions */ -#ifdef __powerpc__ +#elif defined(__powerpc__)
#define CONTEXT_CONTROL 0x0001 #define CONTEXT_FLOATING_POINT 0x0002
Signed-off-by: André Hentschel nerv@dawncrow.de --- tools/winebuild/build.h | 4 +- tools/winebuild/import.c | 271 +++++++++++++++++++++++++++++++++++++++ tools/winebuild/main.c | 2 + tools/winebuild/parser.c | 4 +- tools/winebuild/spec32.c | 37 +++--- tools/winebuild/utils.c | 39 +++--- 6 files changed, 321 insertions(+), 36 deletions(-)
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h index 4fb6e23700e..dce415deca1 100644 --- a/tools/winebuild/build.h +++ b/tools/winebuild/build.h @@ -145,7 +145,7 @@ typedef struct
enum target_cpu { - CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64 + CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_POWERPC64, CPU_LAST = CPU_POWERPC64 };
enum target_platform @@ -193,7 +193,7 @@ struct strarray
#define FLAG_CPU(cpu) (0x10000 << (cpu)) #define FLAG_CPU_MASK (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0)) -#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64)) +#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64) | FLAG_CPU(CPU_POWERPC64)) #define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
#define MAX_ORDINALS 65535 diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index 827a875e5df..7ee75ad3575 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -3,6 +3,8 @@ * * Copyright 2000, 2004 Alexandre Julliard * Copyright 2000 Eric Pouech + * Copyright 2009-2013, 2015, 2017, 2020 André Hentschel + * Copyright 2019 Timothy Pearson tpearson@raptorengineering.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -793,6 +795,20 @@ static void output_import_thunk( const char *name, const char *table, int pos ) output( "\tmr %s, %s\n", ppc_reg(31), ppc_reg(0) ); output( "\tbctr\n" ); break; + case CPU_POWERPC64: + /* + * The ppc64 ABIv2 expects r12 to be set to ctr before bctr for PLT-like calls. + * ABIv2-compatible functions attempt to rebuild the TOC pointer (r2) from r12 under this assumption. + */ + output( "\tlis %s, (%s+%d)@highest\n", ppc_reg(12), table, pos ); + output( "\tori %s, %s, (%s+%d)@higher\n", ppc_reg(12), ppc_reg(12), table, pos ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, (%s+%d)@high\n", ppc_reg(12), ppc_reg(12), table, pos ); + output( "\tori %s, %s, (%s+%d)@l\n", ppc_reg(12), ppc_reg(12), table, pos ); + output( "\tld %s, 0(%s)\n", ppc_reg(12), ppc_reg(12) ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctr\n" ); + break; } output_cfi( ".cfi_endproc" ); output_function_size( name ); @@ -1144,6 +1160,54 @@ static void output_delayed_import_thunks( const DLLSPEC *spec ) output( "\tmtlr %s\n", ppc_reg(0)); output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 48+extra_stack_storage);
+ /* branch to ctr register. */ + output( "\tbctr\n"); + break; + case CPU_POWERPC64: + /* Save all callee saved registers into a stackframe. */ + output( "\tstdu %s, -%d(%s)\n",ppc_reg(1), 176, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(3), 48, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(4), 56, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(5), 64, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(6), 72, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(7), 80, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(8), 88, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(9), 96, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(10),104, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(11),112, ppc_reg(1)); + output( "\tstd %s, %d(%s)\n", ppc_reg(12),120, ppc_reg(1)); + /* r0 -> r3 (arg1) */ + output( "\tmr %s, %s\n", ppc_reg(3), ppc_reg(0)); + /* Call the __wine_delay_load function, arg1 is arg1. */ + output( "\tlis %s, %s@highest\n", ppc_reg(12), asm_name("__wine_spec_delay_load") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_spec_delay_load") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_spec_delay_load") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_spec_delay_load") ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctrl\n" ); + output( "\tld %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1)); + /* r3 (return value) -> r12 (branch / ctr) */ + output( "\tmr %s, %s\n", ppc_reg(12), ppc_reg(3)); + /* Load return value from call into ctr register */ + output( "\tmtctr %s\n", ppc_reg(12)); + /* restore all saved registers and drop stackframe. */ + output( "\tld %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(3), 48, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(4), 56, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(5), 64, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(6), 72, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(7), 80, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(8), 88, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(9), 96, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(10),104, ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(11),112, ppc_reg(1)); + /* don't restore r12! restoring r12 here would corrupt the computed TOC post-bctr. */ + /* Load return value from call into return register */ + output( "\tld %s, 0(%s)\n", ppc_reg(1), ppc_reg(1)); + output( "\tld %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1)); + output( "\tmtlr %s\n", ppc_reg(0)); /* branch to ctr register. */ output( "\tbctr\n"); break; @@ -1219,6 +1283,23 @@ static void output_delayed_import_thunks( const DLLSPEC *spec ) break; } break; + case CPU_POWERPC64: + output( "\tmflr %s\n", ppc_reg(0)); + output( "\tstd %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1)); /* save return address */ + output( "\tlis %s, %d@highest\n", ppc_reg(12), (idx << 16) | j ); + output( "\tori %s, %s, %d@higher\n", ppc_reg(12), ppc_reg(12), (idx << 16) | j ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %d@high\n", ppc_reg(12), ppc_reg(12), (idx << 16) | j ); + output( "\tori %s, %s, %d@l\n", ppc_reg(12), ppc_reg(12), (idx << 16) | j ); + output( "\tmr %s, %s\n", ppc_reg(0), ppc_reg(12) ); + output( "\tlis %s, %s@highest\n", ppc_reg(12), asm_name("__wine_delay_load_asm") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_delay_load_asm") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_delay_load_asm") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_delay_load_asm") ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctr\n" ); + break; } output_cfi( ".cfi_endproc" ); } @@ -1392,6 +1473,37 @@ void output_stubs( DLLSPEC *spec ) output( "\tmov x1, %u\n", odp->ordinal ); output( "\tbl %s\n", asm_name("__wine_spec_unimplemented_stub") ); break; + case CPU_POWERPC64: + /* Clobbers r3, r4, and r12 */ + output( "\tlis %s, .L__wine_spec_file_name@highest\n", ppc_reg(3) ); + output( "\tori %s, %s, .L__wine_spec_file_name@higher\n", ppc_reg(3), ppc_reg(3) ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(3), ppc_reg(3) ); + output( "\toris %s, %s, .L__wine_spec_file_name@high\n", ppc_reg(3), ppc_reg(3) ); + output( "\tori %s, %s, .L__wine_spec_file_name@l\n", ppc_reg(3), ppc_reg(3) ); + if (exp_name) + { + output( "\tlis %s, .L%s_string@highest\n", ppc_reg(4), name ); + output( "\tori %s, %s, .L%s_string@higher\n", ppc_reg(4), ppc_reg(4), name ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(4), ppc_reg(4) ); + output( "\toris %s, %s, .L%s_string@high\n", ppc_reg(4), ppc_reg(4), name ); + output( "\tori %s, %s, .L%s_string@l\n", ppc_reg(4), ppc_reg(4), name ); + } + else + { + output( "\tlis %s, %u@highest\n", ppc_reg(4), odp->ordinal ); + output( "\tori %s, %s, %u@higher\n", ppc_reg(4), ppc_reg(4), odp->ordinal ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(4), ppc_reg(4) ); + output( "\toris %s, %s, %u@high\n", ppc_reg(4), ppc_reg(4), odp->ordinal ); + output( "\tori %s, %s, %u@l\n", ppc_reg(4), ppc_reg(4), odp->ordinal ); + } + output( "\tlis %s, __wine_spec_unimplemented_stub@highest\n", ppc_reg(12) ); + output( "\tori %s, %s, __wine_spec_unimplemented_stub@higher\n", ppc_reg(12), ppc_reg(12) ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, __wine_spec_unimplemented_stub@high\n", ppc_reg(12), ppc_reg(12) ); + output( "\tori %s, %s, __wine_spec_unimplemented_stub@l\n", ppc_reg(12), ppc_reg(12) ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctr\n" ); + break; default: assert(0); } @@ -1684,6 +1796,136 @@ void output_syscalls( DLLSPEC *spec ) output( "\tmovk x0, #0x%x\n", invalid_param & 0x0000ffff ); output( "\tret\n" ); break; + case CPU_POWERPC64: + output( "\tlis %s, %u@highest\n", ppc_reg(12), count ); + output( "\tori %s, %s, %u@higher\n", ppc_reg(12), ppc_reg(12), count ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %u@high\n", ppc_reg(12), ppc_reg(12), count ); + output( "\tori %s, %s, %u@l\n", ppc_reg(12), ppc_reg(12), count ); + output( "\tcmpw cr7, %s, %s\n", ppc_reg(11), ppc_reg(12) ); + output( "\tbgt cr7, 3f\n" ); + /* save return address (thunk_addr) */ + output( "\tmflr %s\n", ppc_reg(0) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1) ); + /* Save all callee saved registers into the syscall_frame. */ + output( "\tstdu %s, -%d(%s)\n",ppc_reg(1), 240, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(3), 32, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(4), 40, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(5), 48, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(6), 56, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(7), 64, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(8), 72, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(9), 80, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(10), 88, ppc_reg(1) ); + /* Save all nonvolatile registers into the syscall_frame. */ + output( "\tstd %s, %d(%s)\n", ppc_reg(14), 96, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(15), 104, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(16), 112, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(17), 120, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(18), 128, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(19), 136, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(20), 144, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(21), 152, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(22), 160, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(23), 168, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(24), 176, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(25), 184, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(26), 192, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(27), 200, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(28), 208, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(29), 216, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(30), 224, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(31), 232, ppc_reg(1) ); + output( "\tmr %s, %s\n", ppc_reg(15), ppc_reg(11) ); + output( "\tmr %s, %s\n", ppc_reg(18), ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(11), 240 + 40, ppc_reg(1) ); + output( "\tlis %s, %s@highest\n", ppc_reg(12), asm_name("NtCurrentTeb") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name("NtCurrentTeb") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name("NtCurrentTeb") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name("NtCurrentTeb") ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctrl\n" ); + /* ppc64_thread_data()->syscall_frame */ + output( "\taddi %s, %s, 0x200\n", ppc_reg(3), ppc_reg(3) ); + output( "\taddi %s, %s, 0x0f0\n", ppc_reg(3), ppc_reg(3) ); + output( "\taddi %s, %s, 0x008\n", ppc_reg(19), ppc_reg(3) ); + output( "\tstd %s, 0(%s)\n", ppc_reg(1), ppc_reg(19) ); /* syscall frame */ + output( "\tld %s, %d(%s)\n", ppc_reg(3), 32, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(4), 40, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(5), 48, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(6), 56, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(7), 64, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(8), 72, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(9), 80, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(10), 88, ppc_reg(1) ); + output( "\tlis %s, %s@highest\n", ppc_reg(12), asm_name(".Lsyscall_args") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_args") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_args") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_args") ); + output( "\tadd %s, %s, %s\n", ppc_reg(12), ppc_reg(12), ppc_reg(15) ); + output( "\tlbz %s, 0(%s)\n", ppc_reg(16), ppc_reg(12) ); + output( "\taddi %s, %s, -64\n", ppc_reg(16), ppc_reg(16) ); + output( "\tcmpwi cr7, %s, 0\n", ppc_reg(16) ); + output( "\textsw %s, %s\n", ppc_reg(16), ppc_reg(16) ); + output( "\tble cr7, 2f\n" ); + output( "\taddi %s, %s, %d\n", ppc_reg(17), ppc_reg(1), 240 + 64 + 96); /* this function + prev function (thunk) + parameter save area */ + output( "\tsub %s, %s, %s\n", ppc_reg(1), ppc_reg(1), ppc_reg(16) ); + output( "\taddi %s, %s, -%d\n", ppc_reg(1), ppc_reg(1), 96 ); + output( "\trldicr %s, %s, 0, 59\n", ppc_reg(1), ppc_reg(1) ); /* align sp */ + output( "\tstd %s, %d(%s)\n", ppc_reg(18), 0, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1) ); + output( "\taddi %s, %s, %d\n", ppc_reg(20), ppc_reg(1), 96 ); /* new parameter save area */ + output( "1:\taddi %s, %s, -%d\n", ppc_reg(16), ppc_reg(16), 8 ); + output( "\tldx %s, %s, %s\n", ppc_reg(0), ppc_reg(17), ppc_reg(16) ); + output( "\tstdx %s, %s, %s\n", ppc_reg(0), ppc_reg(20), ppc_reg(16) ); + output( "\tcmpwi cr7, %s, 0\n", ppc_reg(16) ); + output( "\tbne cr7, 1b\n" ); + output( "2:\tlis %s, %s@highest\n", ppc_reg(12), asm_name(".Lsyscall_table") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_table") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_table") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name(".Lsyscall_table") ); + output( "\trldicr %s, %s, 3, 60\n", ppc_reg(17), ppc_reg(15) ); + output( "\tadd %s, %s, %s\n", ppc_reg(17), ppc_reg(17), ppc_reg(12) ); + output( "\tld %s, 0(%s)\n", ppc_reg(12), ppc_reg(17) ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctrl\n" ); + output( "\tmr %s, %s\n", ppc_reg(1), ppc_reg(18) ); + output( "\tli %s, 0\n", ppc_reg(0) ); + output( "\tstd %s, 0(%s)\n", ppc_reg(0), ppc_reg(19) ); + output( "\tld %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(14), 96, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(15), 104, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(16), 112, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(17), 120, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(18), 128, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(19), 136, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(20), 144, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(21), 152, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(22), 160, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(23), 168, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(24), 176, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(25), 184, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(26), 192, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(27), 200, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(28), 208, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(29), 216, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(30), 224, ppc_reg(1) ); + output( "\tld %s, %d(%s)\n", ppc_reg(31), 232, ppc_reg(1) ); + output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 240 ); /* restore sp */ + output( "\tld %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1) ); + output( "\tmtlr %s\n", ppc_reg(0) ); + output( "\tblr\n" ); + output( "3:\tlis %s, %u@highest\n", ppc_reg(3), invalid_param ); + output( "\tori %s, %s, %u@higher\n", ppc_reg(3), ppc_reg(3), invalid_param ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(3), ppc_reg(3) ); + output( "\toris %s, %s, %u@high\n", ppc_reg(3), ppc_reg(3), invalid_param ); + output( "\tori %s, %s, %u@l\n", ppc_reg(3), ppc_reg(3), invalid_param ); + output( "\tblr\n" ); + break; default: assert(0); } @@ -1778,6 +2020,35 @@ void output_syscalls( DLLSPEC *spec ) output( "\tldp x29, x30, [sp], #16\n" ); output( "\tret\n" ); break; + case CPU_POWERPC64: + output( "\tmflr %s\n", ppc_reg(0) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1) ); /* save lr */ + output( "\tstdu %s, -%d(%s)\n",ppc_reg(1), 64, ppc_reg(1) ); + output( "\tstd %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1) ); /* save r2 */ + output( "\tstd %s, %d(%s)\n", ppc_reg(0), 32, ppc_reg(1) ); /* save lr again */ + output( "\tstd %s, %d(%s)\n", ppc_reg(11), 40, ppc_reg(1) ); /* save r11 */ + output( "\tstd %s, %d(%s)\n", ppc_reg(12), 48, ppc_reg(1) ); /* save r12 */ + output( "\tlis %s, %s@highest\n", ppc_reg(12), asm_name("__wine_syscall_dispatcher") ); + output( "\tori %s, %s, %s@higher\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_syscall_dispatcher") ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(12), ppc_reg(12) ); + output( "\toris %s, %s, %s@high\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_syscall_dispatcher") ); + output( "\tori %s, %s, %s@l\n", ppc_reg(12), ppc_reg(12), asm_name("__wine_syscall_dispatcher") ); + output( "\tld %s, 0(%s)\n", ppc_reg(12), ppc_reg(12) ); + output( "\tlis %s, %u@highest\n", ppc_reg(11), i ); + output( "\tori %s, %s, %u@higher\n", ppc_reg(11), ppc_reg(11), i ); + output( "\trldicr %s, %s, 32, 31\n", ppc_reg(11), ppc_reg(11) ); + output( "\toris %s, %s, %u@high\n", ppc_reg(11), ppc_reg(11), i ); + output( "\tori %s, %s, %u@l\n", ppc_reg(11), ppc_reg(11), i ); + output( "\tmtctr %s\n", ppc_reg(12) ); + output( "\tbctrl\n" ); + output( "\tld %s, %d(%s)\n", ppc_reg(12), 48, ppc_reg(1) ); /* restore r12 */ + output( "\tld %s, %d(%s)\n", ppc_reg(11), 40, ppc_reg(1) ); /* restore r11 */ + output( "\tld %s, %d(%s)\n", ppc_reg(2), 24, ppc_reg(1) ); /* restore r2 */ + output( "\taddi %s, %s, %d\n", ppc_reg(1), ppc_reg(1), 64 ); /* restore sp */ + output( "\tld %s, %d(%s)\n", ppc_reg(0), 16, ppc_reg(1) ); /* restore lr */ + output( "\tmtlr %s\n", ppc_reg(0) ); + output( "\tblr\n" ); + break; default: assert(0); } diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c index 1477df7f259..2420225ffaf 100644 --- a/tools/winebuild/main.c +++ b/tools/winebuild/main.c @@ -54,6 +54,8 @@ int safe_seh = 0; enum target_cpu target_cpu = CPU_x86; #elif defined(__x86_64__) enum target_cpu target_cpu = CPU_x86_64; +#elif defined(__powerpc64__) +enum target_cpu target_cpu = CPU_POWERPC64; #elif defined(__powerpc__) enum target_cpu target_cpu = CPU_POWERPC; #elif defined(__arm__) diff --git a/tools/winebuild/parser.c b/tools/winebuild/parser.c index 2e6424fe76a..edcacadf801 100644 --- a/tools/winebuild/parser.c +++ b/tools/winebuild/parser.c @@ -432,9 +432,9 @@ static int parse_spec_stub( ORDDEF *odp, DLLSPEC *spec ) odp->link_name = xstrdup(""); /* don't bother generating stubs for Winelib */ if (odp->flags & FLAG_CPU_MASK) - odp->flags &= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64); + odp->flags &= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64) | FLAG_CPU(CPU_POWERPC64); else - odp->flags |= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64); + odp->flags |= FLAG_CPU(CPU_x86) | FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM) | FLAG_CPU(CPU_ARM64) | FLAG_CPU(CPU_POWERPC64);
return parse_spec_arguments( odp, spec, 1 ); } diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c index 678f104c555..21df41329cd 100644 --- a/tools/winebuild/spec32.c +++ b/tools/winebuild/spec32.c @@ -32,12 +32,13 @@
#include "build.h"
-#define IMAGE_FILE_MACHINE_UNKNOWN 0 -#define IMAGE_FILE_MACHINE_I386 0x014c -#define IMAGE_FILE_MACHINE_POWERPC 0x01f0 -#define IMAGE_FILE_MACHINE_AMD64 0x8664 -#define IMAGE_FILE_MACHINE_ARMNT 0x01C4 -#define IMAGE_FILE_MACHINE_ARM64 0xaa64 +#define IMAGE_FILE_MACHINE_UNKNOWN 0 +#define IMAGE_FILE_MACHINE_I386 0x014c +#define IMAGE_FILE_MACHINE_POWERPC 0x01f0 +#define IMAGE_FILE_MACHINE_POWERPC64 0x01f2 +#define IMAGE_FILE_MACHINE_AMD64 0x8664 +#define IMAGE_FILE_MACHINE_ARMNT 0x01C4 +#define IMAGE_FILE_MACHINE_ARM64 0xaa64
#define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240 @@ -610,7 +611,6 @@ void output_exports( DLLSPEC *spec ) } }
- /******************************************************************* * output_module * @@ -655,6 +655,7 @@ void output_module( DLLSPEC *spec ) break; case CPU_ARM64: case CPU_POWERPC: + case CPU_POWERPC64: output( "\n\t.section ".init","ax"\n" ); output( "\tb 1f\n" ); break; @@ -676,11 +677,12 @@ void output_module( DLLSPEC *spec ) output( "\t.long 0x4550\n" ); /* Signature */ switch(target_cpu) { - case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break; - case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break; - case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break; - case CPU_ARM: machine = IMAGE_FILE_MACHINE_ARMNT; break; - case CPU_ARM64: machine = IMAGE_FILE_MACHINE_ARM64; break; + case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break; + case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break; + case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break; + case CPU_POWERPC64: machine = IMAGE_FILE_MACHINE_POWERPC64; break; + case CPU_ARM: machine = IMAGE_FILE_MACHINE_ARMNT; break; + case CPU_ARM64: machine = IMAGE_FILE_MACHINE_ARM64; break; } output( "\t.short 0x%04x\n", /* Machine */ machine ); @@ -833,11 +835,12 @@ void output_fake_module( DLLSPEC *spec ) put_dword( 0x4550 ); /* Signature */ switch(target_cpu) { - case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break; - case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break; - case CPU_POWERPC: put_word( IMAGE_FILE_MACHINE_POWERPC ); break; - case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break; - case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break; + case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break; + case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break; + case CPU_POWERPC: put_word( IMAGE_FILE_MACHINE_POWERPC ); break; + case CPU_POWERPC64: put_word( IMAGE_FILE_MACHINE_POWERPC64 ); break; + case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break; + case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break; } put_word( nb_sections ); /* NumberOfSections */ put_dword( hash_filename(spec->file_name) ); /* TimeDateStamp */ diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c index 928a2460aa1..5389c1ba32c 100644 --- a/tools/winebuild/utils.c +++ b/tools/winebuild/utils.c @@ -52,21 +52,23 @@ static const struct enum target_cpu cpu; } cpu_names[] = { - { "i386", CPU_x86 }, - { "i486", CPU_x86 }, - { "i586", CPU_x86 }, - { "i686", CPU_x86 }, - { "i786", CPU_x86 }, - { "amd64", CPU_x86_64 }, - { "x86_64", CPU_x86_64 }, - { "powerpc", CPU_POWERPC }, - { "arm", CPU_ARM }, - { "armv5", CPU_ARM }, - { "armv6", CPU_ARM }, - { "armv7", CPU_ARM }, - { "armv7a", CPU_ARM }, - { "arm64", CPU_ARM64 }, - { "aarch64", CPU_ARM64 }, + { "i386", CPU_x86 }, + { "i486", CPU_x86 }, + { "i586", CPU_x86 }, + { "i686", CPU_x86 }, + { "i786", CPU_x86 }, + { "amd64", CPU_x86_64 }, + { "x86_64", CPU_x86_64 }, + { "powerpc", CPU_POWERPC }, + { "powerpc64", CPU_POWERPC64 }, + { "powerpc64le", CPU_POWERPC64 }, + { "arm", CPU_ARM }, + { "armv5", CPU_ARM }, + { "armv6", CPU_ARM }, + { "armv7", CPU_ARM }, + { "armv7a", CPU_ARM }, + { "arm64", CPU_ARM64 }, + { "aarch64", CPU_ARM64 }, };
/* atexit handler to clean tmp files */ @@ -425,6 +427,7 @@ struct strarray get_as_command(void) switch(target_cpu) { case CPU_POWERPC: + case CPU_POWERPC64: strarray_add_one( &args, (force_pointer_size == 8) ? "-a64" : "-a32" ); break; default: @@ -472,6 +475,10 @@ struct strarray get_ld_command(void) case CPU_POWERPC: strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf64ppc" : "elf32ppc", NULL ); break; + case CPU_POWERPC64: + /* We only respect the little endian version for now */ + strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf64lppc" : "elf32lppc", NULL ); + break; default: strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf_x86_64" : "elf_i386", NULL ); break; @@ -1029,6 +1036,7 @@ unsigned int get_alignment(unsigned int align) if (target_platform != PLATFORM_APPLE) return align; /* fall through */ case CPU_POWERPC: + case CPU_POWERPC64: case CPU_ARM: case CPU_ARM64: n = 0; @@ -1056,6 +1064,7 @@ unsigned int get_ptr_size(void) case CPU_ARM: return 4; case CPU_x86_64: + case CPU_POWERPC64: case CPU_ARM64: return 8; }
Signed-off-by: André Hentschel nerv@dawncrow.de --- tools/winegcc/utils.h | 2 +- tools/winegcc/winegcc.c | 62 ++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/tools/winegcc/utils.h b/tools/winegcc/utils.h index 9c70011a90f..ebc71d85e8e 100644 --- a/tools/winegcc/utils.h +++ b/tools/winegcc/utils.h @@ -39,7 +39,7 @@
enum target_cpu { - CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64 + CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_POWERPC64 };
enum target_platform diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index e72f234d94b..79a9eebe891 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -160,21 +160,23 @@ static const struct enum target_cpu cpu; } cpu_names[] = { - { "i386", CPU_x86 }, - { "i486", CPU_x86 }, - { "i586", CPU_x86 }, - { "i686", CPU_x86 }, - { "i786", CPU_x86 }, - { "amd64", CPU_x86_64 }, - { "x86_64", CPU_x86_64 }, - { "powerpc", CPU_POWERPC }, - { "arm", CPU_ARM }, - { "armv5", CPU_ARM }, - { "armv6", CPU_ARM }, - { "armv7", CPU_ARM }, - { "armv7a", CPU_ARM }, - { "arm64", CPU_ARM64 }, - { "aarch64", CPU_ARM64 }, + { "i386", CPU_x86 }, + { "i486", CPU_x86 }, + { "i586", CPU_x86 }, + { "i686", CPU_x86 }, + { "i786", CPU_x86 }, + { "amd64", CPU_x86_64 }, + { "x86_64", CPU_x86_64 }, + { "powerpc", CPU_POWERPC }, + { "powerpc64", CPU_POWERPC64 }, + { "powerpc64le", CPU_POWERPC64 }, + { "arm", CPU_ARM }, + { "armv5", CPU_ARM }, + { "armv6", CPU_ARM }, + { "armv7", CPU_ARM }, + { "armv7a", CPU_ARM }, + { "arm64", CPU_ARM64 }, + { "aarch64", CPU_ARM64 }, };
static const struct @@ -247,6 +249,8 @@ struct options static const enum target_cpu build_cpu = CPU_x86; #elif defined(__x86_64__) static const enum target_cpu build_cpu = CPU_x86_64; +#elif defined(__powerpc64__) +static const enum target_cpu build_cpu = CPU_POWERPC64; #elif defined(__powerpc__) static const enum target_cpu build_cpu = CPU_POWERPC; #elif defined(__arm__) @@ -610,9 +614,9 @@ static int check_platform( struct options *opts, const char *file ) if (!memcmp( header, "\177ELF", 4 )) { if (header[4] == 2) /* 64-bit */ - ret = (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64); + ret = (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 || opts->target_cpu == CPU_POWERPC64); else - ret = (opts->target_cpu != CPU_x86_64 && opts->target_cpu != CPU_ARM64); + ret = (opts->target_cpu != CPU_x86_64 && opts->target_cpu != CPU_ARM64 && opts->target_cpu != CPU_POWERPC64); } } close( fd ); @@ -624,11 +628,12 @@ static const char *get_multiarch_dir( enum target_cpu cpu ) { switch(cpu) { - case CPU_x86: return "/i386-linux-gnu"; - case CPU_x86_64: return "/x86_64-linux-gnu"; - case CPU_ARM: return "/arm-linux-gnueabi"; - case CPU_ARM64: return "/aarch64-linux-gnu"; - case CPU_POWERPC: return "/powerpc-linux-gnu"; + case CPU_x86: return "/i386-linux-gnu"; + case CPU_x86_64: return "/x86_64-linux-gnu"; + case CPU_ARM: return "/arm-linux-gnueabi"; + case CPU_ARM64: return "/aarch64-linux-gnu"; + case CPU_POWERPC: return "/powerpc-linux-gnu"; + case CPU_POWERPC64: return "/powerpc64le-linux-gnu"; default: assert(0); return NULL; @@ -644,8 +649,8 @@ static char *get_lib_dir( struct options *opts ) unsigned int i; size_t build_len, target_len;
- bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 ? "64" : "32"; - other_bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 ? "32" : "64"; + bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 || opts->target_cpu == CPU_POWERPC64 ? "64" : "32"; + other_bit_suffix = opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 || opts->target_cpu == CPU_POWERPC64 ? "32" : "64"; build_multiarch = get_multiarch_dir( build_cpu ); target_multiarch = get_multiarch_dir( opts->target_cpu ); build_len = strlen( build_multiarch ); @@ -804,7 +809,7 @@ static void compile(struct options* opts, const char* lang) strarray_add(comp_args, "-fno-PIC"); }
- if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64) + if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 || opts->target_cpu == CPU_POWERPC64) { strarray_add(comp_args, "-DWIN64"); strarray_add(comp_args, "-D_WIN64"); @@ -839,6 +844,11 @@ static void compile(struct options* opts, const char* lang) strarray_add(comp_args, "-D__cdecl=__stdcall"); strarray_add(comp_args, "-D__fastcall=__stdcall"); break; + case CPU_POWERPC64: + strarray_add(comp_args, "-D__stdcall=__attribute__((__longcall__))"); + strarray_add(comp_args, "-D__cdecl=__stdcall"); + strarray_add(comp_args, "-D__fastcall=__stdcall"); + break; case CPU_POWERPC: strarray_add(comp_args, "-D__stdcall="); strarray_add(comp_args, "-D__cdecl="); @@ -866,7 +876,7 @@ static void compile(struct options* opts, const char* lang) strarray_add(comp_args, "-D__int8=char"); strarray_add(comp_args, "-D__int16=short"); strarray_add(comp_args, "-D__int32=int"); - if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64) + if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64 || opts->target_cpu == CPU_POWERPC64) strarray_add(comp_args, "-D__int64=long"); else strarray_add(comp_args, "-D__int64=long long");
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- server/mapping.c | 5 +++++ server/process.h | 2 +- server/protocol.def | 6 +++++- server/thread.c | 13 ++++++++----- server/trace.c | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/server/mapping.c b/server/mapping.c index 9c51aa3bec7..a0d72b29a01 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -688,6 +688,10 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s mapping->image.cpu = CPU_ARM64; if (cpu_mask & (CPU_FLAG(CPU_ARM) | CPU_FLAG(CPU_ARM64))) break; return STATUS_INVALID_IMAGE_FORMAT; + case IMAGE_FILE_MACHINE_POWERPC64: + mapping->image.cpu = CPU_POWERPC64; + if (cpu_mask & CPU_FLAG(CPU_POWERPC64)) break; + return STATUS_INVALID_IMAGE_FORMAT; default: return STATUS_INVALID_IMAGE_FORMAT; } @@ -758,6 +762,7 @@ static unsigned int get_image_params( struct mapping *mapping, file_pos_t file_s mapping->image.image_flags |= IMAGE_FLAGS_ComPlusNativeReady; if (cpu_mask & CPU_FLAG(CPU_x86_64)) mapping->image.cpu = CPU_x86_64; else if (cpu_mask & CPU_FLAG(CPU_ARM64)) mapping->image.cpu = CPU_ARM64; + else if (cpu_mask & CPU_FLAG(CPU_POWERPC64)) mapping->image.cpu = CPU_POWERPC64; } if (clr.Flags & COMIMAGE_FLAGS_32BITPREFERRED) mapping->image.image_flags |= IMAGE_FLAGS_ComPlusPrefer32bit; diff --git a/server/process.h b/server/process.h index 5901e8fa3de..f4ba7d94666 100644 --- a/server/process.h +++ b/server/process.h @@ -100,7 +100,7 @@ struct process };
#define CPU_FLAG(cpu) (1 << (cpu)) -#define CPU_64BIT_MASK (CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_ARM64)) +#define CPU_64BIT_MASK (CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_ARM64) | CPU_FLAG(CPU_POWERPC64))
/* process functions */
diff --git a/server/protocol.def b/server/protocol.def index 853f9dbae01..2d2b37ee6bb 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -133,7 +133,7 @@ typedef union /* supported CPU types */ enum cpu_type { - CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64 + CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_POWERPC64 }; typedef int client_cpu_t;
@@ -148,6 +148,7 @@ typedef struct struct { unsigned __int64 rip, rbp, rsp; unsigned int cs, ss, flags, __pad; } x86_64_regs; struct { unsigned int iar, msr, ctr, lr, dar, dsisr, trap, __pad; } powerpc_regs; + struct { unsigned __int64 iar, msr, ctr, lr, dar, dsisr, trap, __pad; } powerpc64_regs; struct { unsigned int sp, lr, pc, cpsr; } arm_regs; struct { unsigned __int64 sp, pc, pstate; } arm64_regs; } ctl; /* selected by SERVER_CTX_CONTROL */ @@ -157,6 +158,7 @@ typedef struct struct { unsigned __int64 rax,rbx, rcx, rdx, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15; } x86_64_regs; struct { unsigned int gpr[32], cr, xer; } powerpc_regs; + struct { unsigned __int64 gpr[32], cr, xer; } powerpc64_regs; struct { unsigned int r[13]; } arm_regs; struct { unsigned __int64 x[31]; } arm64_regs; } integer; /* selected by SERVER_CTX_INTEGER */ @@ -171,6 +173,7 @@ typedef struct unsigned char regs[80]; } i386_regs; struct { struct { unsigned __int64 low, high; } fpregs[32]; } x86_64_regs; struct { double fpr[32], fpscr; } powerpc_regs; + struct { double fpr[32]; unsigned __int64 fpscr; } powerpc64_regs; struct { unsigned __int64 d[32]; unsigned int fpscr; } arm_regs; struct { struct { unsigned __int64 low, high; } q[32]; unsigned int fpcr, fpsr; } arm64_regs; } fp; /* selected by SERVER_CTX_FLOATING_POINT */ @@ -179,6 +182,7 @@ typedef struct struct { unsigned int dr0, dr1, dr2, dr3, dr6, dr7; } i386_regs; struct { unsigned __int64 dr0, dr1, dr2, dr3, dr6, dr7; } x86_64_regs; struct { unsigned int dr[8]; } powerpc_regs; + struct { unsigned __int64 dr[8]; } powerpc64_regs; struct { unsigned int bvr[8], bcr[8], wvr[1], wcr[1]; } arm_regs; struct { unsigned __int64 bvr[8], wvr[2]; unsigned int bcr[8], wcr[2]; } arm64_regs; } debug; /* selected by SERVER_CTX_DEBUG_REGISTERS */ diff --git a/server/thread.c b/server/thread.c index 296f0848027..8bef09136f1 100644 --- a/server/thread.c +++ b/server/thread.c @@ -57,6 +57,8 @@ static const unsigned int supported_cpus = CPU_FLAG(CPU_x86); #elif defined(__x86_64__) static const unsigned int supported_cpus = CPU_FLAG(CPU_x86_64) | CPU_FLAG(CPU_x86); +#elif defined(__powerpc64__) +static const unsigned int supported_cpus = CPU_FLAG(CPU_POWERPC64); #elif defined(__powerpc__) static const unsigned int supported_cpus = CPU_FLAG(CPU_POWERPC); #elif defined(__arm__) @@ -1294,11 +1296,12 @@ static unsigned int get_context_system_regs( enum cpu_type cpu ) { switch (cpu) { - case CPU_x86: return SERVER_CTX_DEBUG_REGISTERS; - case CPU_x86_64: return SERVER_CTX_DEBUG_REGISTERS; - case CPU_POWERPC: return 0; - case CPU_ARM: return SERVER_CTX_DEBUG_REGISTERS; - case CPU_ARM64: return SERVER_CTX_DEBUG_REGISTERS; + case CPU_x86: return SERVER_CTX_DEBUG_REGISTERS; + case CPU_x86_64: return SERVER_CTX_DEBUG_REGISTERS; + case CPU_POWERPC: return 0; + case CPU_POWERPC64: return SERVER_CTX_DEBUG_REGISTERS; + case CPU_ARM: return SERVER_CTX_DEBUG_REGISTERS; + case CPU_ARM64: return SERVER_CTX_DEBUG_REGISTERS; } return 0; } diff --git a/server/trace.c b/server/trace.c index 4d59b06d040..305f1a16138 100644 --- a/server/trace.c +++ b/server/trace.c @@ -155,6 +155,7 @@ static void dump_client_cpu( const char *prefix, const client_cpu_t *code ) CASE(x86); CASE(x86_64); CASE(POWERPC); + CASE(POWERPC64); CASE(ARM); CASE(ARM64); default: fprintf( stderr, "%s%u", prefix, *code ); break; @@ -695,6 +696,41 @@ static void dump_varargs_context( const char *prefix, data_size_t size ) fprintf( stderr, ",fpscr=%g", ctx.fp.powerpc_regs.fpscr ); } break; + case CPU_POWERPC64: + if (ctx.flags & SERVER_CTX_CONTROL) + { + dump_uint64( ",iar=", &ctx.ctl.powerpc64_regs.iar ); + dump_uint64( ",msr=", &ctx.ctl.powerpc64_regs.msr ); + dump_uint64( ",ctr=", &ctx.ctl.powerpc64_regs.ctr ); + dump_uint64( ",lr=", &ctx.ctl.powerpc64_regs.lr ); + dump_uint64( ",dar=", &ctx.ctl.powerpc64_regs.dar ); + dump_uint64( ",dsisr=", &ctx.ctl.powerpc64_regs.dsisr ); + dump_uint64( ",trap=", &ctx.ctl.powerpc64_regs.trap ); + } + if (ctx.flags & SERVER_CTX_INTEGER) + { + for (i = 0; i < 32; i++) + { + fprintf( stderr, ",gpr%u=", i ); + dump_uint64( "", &ctx.integer.powerpc64_regs.gpr[i] ); + } + dump_uint64( ",cr=", &ctx.integer.powerpc64_regs.cr ); + dump_uint64( ",xer=", &ctx.integer.powerpc64_regs.xer ); + } + if (ctx.flags & SERVER_CTX_DEBUG_REGISTERS) + { + for (i = 0; i < 8; i++) + { + fprintf( stderr, ",dr%u=", i ); + dump_uint64( "", &ctx.debug.powerpc64_regs.dr[i] ); + } + } + if (ctx.flags & SERVER_CTX_FLOATING_POINT) + { + for (i = 0; i < 32; i++) fprintf( stderr, ",fpr%u=%g", i, ctx.fp.powerpc64_regs.fpr[i] ); + dump_uint64( ",fpscr=", &ctx.fp.powerpc64_regs.fpscr ); + } + break; case CPU_ARM: if (ctx.flags & SERVER_CTX_CONTROL) fprintf( stderr, ",sp=%08x,lr=%08x,pc=%08x,cpsr=%08x",
Signed-off-by: André Hentschel nerv@dawncrow.de --- configure.ac | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac index a9003523700..5ecb2af0ec8 100644 --- a/configure.ac +++ b/configure.ac @@ -217,6 +217,14 @@ case $host in enable_win16=${enable_win16:-yes} with_unwind=${with_unwind:-no} ;; + powerpc64*) + host_cpu="powerpc64le" + notice_platform="64-bit " + WINE_TRY_CFLAGS([-mlongcall], [CC="$CC -mlongcall" + CXX="$CXX -mlongcall"]) + WINE_TRY_CFLAGS([-mno-pltseq], [CC="$CC -mno-pltseq" + CXX="$CXX -mno-pltseq"]) + ;; esac
dnl enable_win16 defaults to yes on x86, to no on other CPUs @@ -937,7 +945,7 @@ case $host_os in WINEPRELOADER_LDFLAGS="-static -nostartfiles -nodefaultlibs -Wl,-Ttext=0x7d400000"
case $host_cpu in - *i[[3456789]]86* | x86_64 | *aarch64*) + *i[[3456789]]86* | x86_64 | *aarch64* | powerpc64*) WINE_TRY_CFLAGS([-Wl,-Ttext-segment=0x7bc00000], [case $host_os in freebsd* | kfreebsd*-gnu) WINELOADER_LDFLAGS="$WINELOADER_LDFLAGS -Wl,-Ttext-segment=0x60000000" ;;
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- .../api-ms-win-crt-private-l1-1-0.spec | 2 +- dlls/ucrtbase/ucrtbase.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec b/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec index 136358a174c..73a33b4157d 100644 --- a/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec +++ b/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec @@ -660,7 +660,7 @@ @ cdecl -arch=x86_64 _o__scalbf(float long) ucrtbase._o__scalbf @ cdecl _o__searchenv(str str ptr) ucrtbase._o__searchenv @ cdecl _o__searchenv_s(str str ptr long) ucrtbase._o__searchenv_s -@ cdecl _o__seh_filter_dll(long ptr) ucrtbase._o__seh_filter_dll +@ cdecl -arch=i386,x86_64,arm,arm64 _o__seh_filter_dll(long ptr) ucrtbase._o__seh_filter_dll @ cdecl _o__seh_filter_exe(long ptr) ucrtbase._o__seh_filter_exe @ cdecl _o__set_abort_behavior(long long) ucrtbase._o__set_abort_behavior @ cdecl _o__set_app_type(long) ucrtbase._o__set_app_type diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index 0a8d74521f5..c14cd3d66cb 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -1324,7 +1324,7 @@ @ cdecl -arch=x86_64 _o__scalbf(float long) _scalbf @ cdecl _o__searchenv(str str ptr) _searchenv @ cdecl _o__searchenv_s(str str ptr long) _searchenv_s -@ cdecl _o__seh_filter_dll(long ptr) __CppXcptFilter +@ cdecl -arch=i386,x86_64,arm,arm64 _o__seh_filter_dll(long ptr) __CppXcptFilter @ cdecl _o__seh_filter_exe(long ptr) _XcptFilter @ cdecl _o__set_abort_behavior(long long) _set_abort_behavior @ cdecl _o__set_app_type(long) __set_app_type
Signed-off-by: André Hentschel nerv@dawncrow.de --- .../api-ms-win-core-crt-l2-1-0.spec | 2 +- .../api-ms-win-crt-private-l1-1-0.spec | 2 +- dlls/msvcrt20/msvcrt20.spec | 22 +++++++++---------- dlls/msvcrt40/msvcrt40.spec | 22 +++++++++---------- dlls/ucrtbase/ucrtbase.spec | 2 +- dlls/vcruntime140/vcruntime140.spec | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/dlls/api-ms-win-core-crt-l2-1-0/api-ms-win-core-crt-l2-1-0.spec b/dlls/api-ms-win-core-crt-l2-1-0/api-ms-win-core-crt-l2-1-0.spec index 69f2629c8d5..86651e0a8bc 100644 --- a/dlls/api-ms-win-core-crt-l2-1-0/api-ms-win-core-crt-l2-1-0.spec +++ b/dlls/api-ms-win-core-crt-l2-1-0/api-ms-win-core-crt-l2-1-0.spec @@ -14,5 +14,5 @@ @ cdecl exit(long) msvcrt.exit @ stub hgets @ stub hwprintf -@ cdecl time(ptr) msvcrt.time +@ cdecl -arch=win32 time(ptr) msvcrt.time @ varargs wprintf(wstr) msvcrt.wprintf diff --git a/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec b/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec index 73a33b4157d..3f260a402a6 100644 --- a/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec +++ b/dlls/api-ms-win-crt-private-l1-1-0/api-ms-win-crt-private-l1-1-0.spec @@ -40,7 +40,7 @@ @ stub __dcrt_initial_narrow_environment @ cdecl __intrinsic_abnormal_termination() ucrtbase.__intrinsic_abnormal_termination @ cdecl -arch=i386,x86_64,arm,arm64 -norelay __intrinsic_setjmp(ptr) ucrtbase.__intrinsic_setjmp -@ cdecl -arch=x86_64,arm64 -norelay __intrinsic_setjmpex(ptr ptr) ucrtbase.__intrinsic_setjmpex +@ cdecl -arch=x86_64,arm64,powerpc64 -norelay __intrinsic_setjmpex(ptr ptr) ucrtbase.__intrinsic_setjmpex @ cdecl __processing_throw() ucrtbase.__processing_throw @ stub __report_gsfailure @ cdecl __std_exception_copy(ptr ptr) ucrtbase.__std_exception_copy diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec index 7e2ec304979..e386ed8511d 100644 --- a/dlls/msvcrt20/msvcrt20.spec +++ b/dlls/msvcrt20/msvcrt20.spec @@ -932,10 +932,10 @@ @ cdecl _fputwchar(long) msvcrt._fputwchar @ cdecl _fsopen(str str long) msvcrt._fsopen @ cdecl _fstat(long ptr) msvcrt._fstat -@ cdecl _ftime(ptr) msvcrt._ftime +@ cdecl -arch=win32 _ftime(ptr) msvcrt._ftime @ cdecl -arch=i386 -ret64 _ftol() msvcrt._ftol @ cdecl _fullpath(ptr str long) msvcrt._fullpath -@ cdecl _futime(long ptr) msvcrt._futime +@ cdecl -arch=win32 _futime(long ptr) msvcrt._futime @ cdecl _gcvt(double long str) msvcrt._gcvt @ cdecl _get_osfhandle(long) msvcrt._get_osfhandle @ cdecl _getch() msvcrt._getch @@ -1187,7 +1187,7 @@ @ cdecl _ungetch(long) msvcrt._ungetch @ cdecl _unlink(str) msvcrt._unlink @ cdecl _unloaddll(long) msvcrt._unloaddll -@ cdecl _utime(str ptr) msvcrt._utime +@ cdecl -arch=win32 _utime(str ptr) msvcrt._utime @ cdecl -norelay _vsnprintf(ptr long str ptr) msvcrt._vsnprintf @ cdecl _vsnwprintf(ptr long wstr ptr) msvcrt._vsnwprintf @ cdecl _waccess(wstr long) msvcrt._waccess @@ -1207,7 +1207,7 @@ @ cdecl _wcsrev(wstr) msvcrt._wcsrev @ cdecl _wcsset(wstr long) msvcrt._wcsset @ cdecl _wcsupr(wstr) msvcrt._wcsupr -@ cdecl _wctime(ptr) msvcrt._wctime +@ cdecl -arch=win32 _wctime(ptr) msvcrt._wctime @ extern _wenviron msvcrt._wenviron @ varargs _wexecl(wstr wstr) msvcrt._wexecl @ varargs _wexecle(wstr wstr) msvcrt._wexecle @@ -1263,7 +1263,7 @@ @ cdecl _wtoi(wstr) msvcrt._wtoi @ cdecl _wtol(wstr) msvcrt._wtol @ cdecl _wunlink(wstr) msvcrt._wunlink -@ cdecl _wutime(wstr ptr) msvcrt._wutime +@ cdecl -arch=win32 _wutime(wstr ptr) msvcrt._wutime @ cdecl _y0(double) msvcrt._y0 @ cdecl _y1(double) msvcrt._y1 @ cdecl _yn(long double) msvcrt._yn @@ -1285,8 +1285,8 @@ @ cdecl clock() msvcrt.clock @ cdecl cos(double) msvcrt.cos @ cdecl cosh(double) msvcrt.cosh -@ cdecl ctime(ptr) msvcrt.ctime -@ cdecl difftime(long long) msvcrt.difftime +@ cdecl -arch=win32 ctime(ptr) msvcrt.ctime +@ cdecl -arch=win32 difftime(long long) msvcrt.difftime @ cdecl -ret64 div(long long) msvcrt.div @ cdecl exit(long) msvcrt.exit @ cdecl exp(double) msvcrt.exp @@ -1325,7 +1325,7 @@ @ cdecl gets(str) msvcrt.gets @ cdecl getwc(ptr) msvcrt.getwc @ cdecl getwchar() msvcrt.getwchar -@ cdecl gmtime(ptr) msvcrt.gmtime +@ cdecl -arch=win32 gmtime(ptr) msvcrt.gmtime @ cdecl is_wctype(long long) msvcrt.is_wctype @ cdecl isalnum(long) msvcrt.isalnum @ cdecl isalpha(long) msvcrt.isalpha @@ -1356,7 +1356,7 @@ @ cdecl ldexp(double long) msvcrt.ldexp @ cdecl -ret64 ldiv(long long) msvcrt.ldiv @ cdecl localeconv() msvcrt.localeconv -@ cdecl localtime(ptr) msvcrt.localtime +@ cdecl -arch=win32 localtime(ptr) msvcrt.localtime @ cdecl log(double) msvcrt.log @ cdecl log10(double) msvcrt.log10 @ cdecl -arch=i386,x86_64,arm,arm64 longjmp(ptr long) msvcrt.longjmp @@ -1369,7 +1369,7 @@ @ cdecl memcpy(ptr ptr long) msvcrt.memcpy @ cdecl memmove(ptr ptr long) msvcrt.memmove @ cdecl memset(ptr long long) msvcrt.memset -@ cdecl mktime(ptr) msvcrt.mktime +@ cdecl -arch=win32 mktime(ptr) msvcrt.mktime @ cdecl modf(double ptr) msvcrt.modf @ cdecl perror(str) msvcrt.perror @ cdecl pow(double double) msvcrt.pow @@ -1423,7 +1423,7 @@ @ cdecl system(str) msvcrt.system @ cdecl tan(double) msvcrt.tan @ cdecl tanh(double) msvcrt.tanh -@ cdecl time(ptr) msvcrt.time +@ cdecl -arch=win32 time(ptr) msvcrt.time @ cdecl tmpfile() msvcrt.tmpfile @ cdecl tmpnam(ptr) msvcrt.tmpnam @ cdecl tolower(long) msvcrt.tolower diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec index ebcf5df4fc3..1024644b29c 100644 --- a/dlls/msvcrt40/msvcrt40.spec +++ b/dlls/msvcrt40/msvcrt40.spec @@ -1019,10 +1019,10 @@ @ cdecl _fsopen(str str long) msvcrt._fsopen @ cdecl _fstat(long ptr) msvcrt._fstat @ cdecl _fstati64(long ptr) msvcrt._fstati64 -@ cdecl _ftime(ptr) msvcrt._ftime +@ cdecl -arch=win32 _ftime(ptr) msvcrt._ftime @ cdecl -arch=i386 -ret64 _ftol() msvcrt._ftol @ cdecl _fullpath(ptr str long) msvcrt._fullpath -@ cdecl _futime(long ptr) msvcrt._futime +@ cdecl -arch=win32 _futime(long ptr) msvcrt._futime @ cdecl _gcvt(double long str) msvcrt._gcvt @ cdecl _get_osfhandle(long) msvcrt._get_osfhandle @ cdecl _getch() msvcrt._getch @@ -1252,7 +1252,7 @@ @ cdecl _ungetch(long) msvcrt._ungetch @ cdecl _unlink(str) msvcrt._unlink @ cdecl _unloaddll(long) msvcrt._unloaddll -@ cdecl _utime(str ptr) msvcrt._utime +@ cdecl -arch=win32 _utime(str ptr) msvcrt._utime @ cdecl -norelay _vsnprintf(ptr long str ptr) msvcrt._vsnprintf @ cdecl _vsnwprintf(ptr long wstr ptr) msvcrt._vsnwprintf @ cdecl _waccess(wstr long) msvcrt._waccess @@ -1272,7 +1272,7 @@ @ cdecl _wcsrev(wstr) msvcrt._wcsrev @ cdecl _wcsset(wstr long) msvcrt._wcsset @ cdecl _wcsupr(wstr) msvcrt._wcsupr -@ cdecl _wctime(ptr) msvcrt._wctime +@ cdecl -arch=win32 _wctime(ptr) msvcrt._wctime @ extern _wenviron msvcrt._wenviron @ varargs _wexecl(wstr wstr) msvcrt._wexecl @ varargs _wexecle(wstr wstr) msvcrt._wexecle @@ -1331,7 +1331,7 @@ @ cdecl _wtoi(wstr) msvcrt._wtoi @ cdecl _wtol(wstr) msvcrt._wtol @ cdecl _wunlink(wstr) msvcrt._wunlink -@ cdecl _wutime(wstr ptr) msvcrt._wutime +@ cdecl -arch=win32 _wutime(wstr ptr) msvcrt._wutime @ cdecl _y0(double) msvcrt._y0 @ cdecl _y1(double) msvcrt._y1 @ cdecl _yn(long double) msvcrt._yn @@ -1353,8 +1353,8 @@ @ cdecl clock() msvcrt.clock @ cdecl cos(double) msvcrt.cos @ cdecl cosh(double) msvcrt.cosh -@ cdecl ctime(ptr) msvcrt.ctime -@ cdecl difftime(long long) msvcrt.difftime +@ cdecl -arch=win32 ctime(ptr) msvcrt.ctime +@ cdecl -arch=win32 difftime(long long) msvcrt.difftime @ cdecl -ret64 div(long long) msvcrt.div @ cdecl exit(long) msvcrt.exit @ cdecl exp(double) msvcrt.exp @@ -1393,7 +1393,7 @@ @ cdecl gets(str) msvcrt.gets @ cdecl getwc(ptr) msvcrt.getwc @ cdecl getwchar() msvcrt.getwchar -@ cdecl gmtime(ptr) msvcrt.gmtime +@ cdecl -arch=win32 gmtime(ptr) msvcrt.gmtime @ cdecl is_wctype(long long) msvcrt.is_wctype @ cdecl isalnum(long) msvcrt.isalnum @ cdecl isalpha(long) msvcrt.isalpha @@ -1424,7 +1424,7 @@ @ cdecl ldexp(double long) msvcrt.ldexp @ cdecl -ret64 ldiv(long long) msvcrt.ldiv @ cdecl localeconv() msvcrt.localeconv -@ cdecl localtime(ptr) msvcrt.localtime +@ cdecl -arch=win32 localtime(ptr) msvcrt.localtime @ cdecl log(double) msvcrt.log @ cdecl log10(double) msvcrt.log10 @ cdecl -arch=i386,x86_64,arm,arm64 longjmp(ptr long) msvcrt.longjmp @@ -1437,7 +1437,7 @@ @ cdecl memcpy(ptr ptr long) msvcrt.memcpy @ cdecl memmove(ptr ptr long) msvcrt.memmove @ cdecl memset(ptr long long) msvcrt.memset -@ cdecl mktime(ptr) msvcrt.mktime +@ cdecl -arch=win32 mktime(ptr) msvcrt.mktime @ cdecl modf(double ptr) msvcrt.modf @ cdecl perror(str) msvcrt.perror @ cdecl pow(double double) msvcrt.pow @@ -1491,7 +1491,7 @@ @ cdecl system(str) msvcrt.system @ cdecl tan(double) msvcrt.tan @ cdecl tanh(double) msvcrt.tanh -@ cdecl time(ptr) msvcrt.time +@ cdecl -arch=win32 time(ptr) msvcrt.time @ cdecl tmpfile() msvcrt.tmpfile @ cdecl tmpnam(ptr) msvcrt.tmpnam @ cdecl tolower(long) msvcrt.tolower diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index c14cd3d66cb..465df3838d6 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -94,7 +94,7 @@ @ cdecl __initialize_lconv_for_unsigned_char() __lconv_init @ cdecl __intrinsic_abnormal_termination() @ cdecl -arch=i386,x86_64,arm,arm64 -norelay __intrinsic_setjmp(ptr) MSVCRT__setjmp -@ cdecl -arch=x86_64,arm64 -norelay __intrinsic_setjmpex(ptr ptr) __wine_setjmpex +@ cdecl -arch=x86_64,arm64,powerpc64 -norelay __intrinsic_setjmpex(ptr ptr) __wine_setjmpex @ cdecl __isascii(long) @ cdecl __iscsym(long) @ cdecl __iscsymf(long) diff --git a/dlls/vcruntime140/vcruntime140.spec b/dlls/vcruntime140/vcruntime140.spec index f799bcd4db5..d7cf8007bef 100644 --- a/dlls/vcruntime140/vcruntime140.spec +++ b/dlls/vcruntime140/vcruntime140.spec @@ -33,7 +33,7 @@ @ cdecl __current_exception() ucrtbase.__current_exception @ cdecl __current_exception_context() ucrtbase.__current_exception_context @ cdecl -arch=i386,x86_64,arm,arm64 -norelay __intrinsic_setjmp(ptr) ucrtbase.__intrinsic_setjmp -@ cdecl -arch=x86_64,arm64 -norelay __intrinsic_setjmpex(ptr ptr) ucrtbase.__intrinsic_setjmpex +@ cdecl -arch=x86_64,arm64,powerpc64 -norelay __intrinsic_setjmpex(ptr ptr) ucrtbase.__intrinsic_setjmpex @ cdecl __processing_throw() ucrtbase.__processing_throw @ stub __report_gsfailure @ cdecl __std_exception_copy(ptr ptr) ucrtbase.__std_exception_copy
Hi André,
On 31 Jan 2021, at 18:34, André Hentschel nerv@dawncrow.de wrote: -@ cdecl time(ptr) msvcrt.time +@ cdecl -arch=win32 time(ptr) msvcrt.time
Some of the spec file changes are incorrect (and unrelated to the patch).
Thanks, Piotr
Am 31.01.21 um 19:06 schrieb Piotr Caban:
Hi André,
On 31 Jan 2021, at 18:34, André Hentschel nerv@dawncrow.de wrote: -@ cdecl time(ptr) msvcrt.time +@ cdecl -arch=win32 time(ptr) msvcrt.time
Some of the spec file changes are incorrect (and unrelated to the patch).
Thanks, Piotr
Hi Piotr,
Thanks for having a look. You are obviosly correct, they were not intented... I wait for more feedback before resending
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/kernelbase/memory.c | 3 +++ include/winnt.h | 1 + 2 files changed, 4 insertions(+)
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c index 2bfd3893e8e..f1becdaded5 100644 --- a/dlls/kernelbase/memory.c +++ b/dlls/kernelbase/memory.c @@ -150,6 +150,9 @@ void WINAPI DECLSPEC_HOTPATCH GetSystemInfo( SYSTEM_INFO *si ) case PROCESSOR_ARCHITECTURE_ARM64: si->dwProcessorType = 0; break; + case PROCESSOR_ARCHITECTURE_PPC64: + si->dwProcessorType = PROCESSOR_PPC64_OP; + break; default: FIXME( "Unknown processor architecture %x\n", cpu_info.Architecture ); si->dwProcessorType = 0; diff --git a/include/winnt.h b/include/winnt.h index 359a6a3a5fd..a697331e157 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -707,6 +707,7 @@ typedef DWORD FLONG; #define PROCESSOR_PPC_603 603 #define PROCESSOR_PPC_604 604 #define PROCESSOR_PPC_620 620 +#define PROCESSOR_PPC64_OP 690 #define PROCESSOR_HITACHI_SH3 10003 #define PROCESSOR_HITACHI_SH3E 10004 #define PROCESSOR_HITACHI_SH4 10005
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/kernel32/module.c | 1 + dlls/kernel32/tests/file.c | 2 ++ dlls/kernel32/tests/loader.c | 2 ++ dlls/kernel32/tests/module.c | 2 ++ 4 files changed, 7 insertions(+)
diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c index 0449bedf83f..b40bb0c3133 100644 --- a/dlls/kernel32/module.c +++ b/dlls/kernel32/module.c @@ -201,6 +201,7 @@ BOOL WINAPI GetBinaryTypeW( LPCWSTR name, LPDWORD type ) return TRUE; case IMAGE_FILE_MACHINE_AMD64: case IMAGE_FILE_MACHINE_ARM64: + case IMAGE_FILE_MACHINE_POWERPC64: *type = SCS_64BIT_BINARY; return TRUE; } diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 2814ab194b2..e3df58ded9c 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -2337,6 +2337,8 @@ static BOOL create_fake_dll( LPCSTR filename ) nt->FileHeader.Machine = IMAGE_FILE_MACHINE_I386; #elif defined __x86_64__ nt->FileHeader.Machine = IMAGE_FILE_MACHINE_AMD64; +#elif defined __powerpc64__ + nt->FileHeader.Machine = IMAGE_FILE_MACHINE_POWERPC64; #elif defined __arm__ nt->FileHeader.Machine = IMAGE_FILE_MACHINE_ARMNT; #elif defined __aarch64__ diff --git a/dlls/kernel32/tests/loader.c b/dlls/kernel32/tests/loader.c index 47fb3cf4649..dbce1c3864e 100644 --- a/dlls/kernel32/tests/loader.c +++ b/dlls/kernel32/tests/loader.c @@ -105,6 +105,8 @@ static const IMAGE_NT_HEADERS nt_header_template = IMAGE_FILE_MACHINE_I386, /* Machine */ #elif defined __x86_64__ IMAGE_FILE_MACHINE_AMD64, /* Machine */ +#elif defined __powerpc64__ + IMAGE_FILE_MACHINE_POWERPC64, /* Machine */ #elif defined __arm__ IMAGE_FILE_MACHINE_ARMNT, /* Machine */ #elif defined __aarch64__ diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c index 6eb2fc804d1..e8638114aba 100644 --- a/dlls/kernel32/tests/module.c +++ b/dlls/kernel32/tests/module.c @@ -68,6 +68,8 @@ static const struct IMAGE_FILE_MACHINE_I386, /* Machine */ #elif defined __x86_64__ IMAGE_FILE_MACHINE_AMD64, /* Machine */ +#elif defined __powerpc64__ + IMAGE_FILE_MACHINE_POWERPC64, /* Machine */ #elif defined __arm__ IMAGE_FILE_MACHINE_ARMNT, /* Machine */ #elif defined __aarch64__
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=84802
Your paranoid android.
=== w10pro64 (32 bit report) ===
kernel32: loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c0000130 loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1193: wrong status c0000131/c000011b loader.c:722: Test failed: 1210: wrong status c0000131/c0000130 loader.c:722: Test failed: 1215: wrong status c0000131/c0000130 loader.c:722: Test failed: 1220: wrong status c0000131/c000007b loader.c:722: Test failed: 1225: wrong status c0000131/c000007b loader.c:722: Test failed: 1230: wrong status c0000131/c000007b loader.c:722: Test failed: 1235: wrong status c0000131/c000007b loader.c:722: Test failed: 1240: wrong status c0000131/c000007b loader.c:722: Test failed: 1256: wrong status c0000131/0 loader.c:722: Test failed: 1260: wrong status c0000131/0 loader.c:722: Test failed: 1265: wrong status c0000131/0 loader.c:722: Test failed: 1269: wrong status c0000131/0 loader.c:722: Test failed: 1273: wrong status c0000131/0 loader.c:722: Test failed: 1312: wrong status c0000131/c000007b loader.c:722: Test failed: 1321: wrong status c0000131/c000007b
=== w10pro64 (64 bit report) ===
kernel32: loader.c:722: Test failed: 1193: wrong status c000011b/c0000130 loader.c:722: Test failed: 1210: wrong status c000011b/c0000130 loader.c:722: Test failed: 1215: wrong status c000011b/c0000130 loader.c:722: Test failed: 1220: wrong status c000011b/c000007b loader.c:722: Test failed: 1225: wrong status c000011b/c000007b loader.c:722: Test failed: 1230: wrong status c000011b/c000007b loader.c:722: Test failed: 1235: wrong status c000011b/c000007b loader.c:722: Test failed: 1240: wrong status c000011b/c000007b loader.c:722: Test failed: 1256: wrong status c000011b/0 loader.c:722: Test failed: 1260: wrong status c000011b/0 loader.c:722: Test failed: 1265: wrong status c000011b/0 loader.c:722: Test failed: 1269: wrong status c000011b/0 loader.c:722: Test failed: 1273: wrong status c000011b/0
Signed-off-by: André Hentschel nerv@dawncrow.de --- programs/winetest/main.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/programs/winetest/main.c b/programs/winetest/main.c index 1731850bfdb..1f9ed7dd116 100644 --- a/programs/winetest/main.c +++ b/programs/winetest/main.c @@ -348,6 +348,8 @@ static void print_version (void) static const char platform[] = "arm"; #elif defined(__aarch64__) static const char platform[] = "arm64"; +#elif defined(__powerpc64__) + static const char platform[] = "ppc64"; #else # error CPU unknown #endif
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- programs/winedbg/Makefile.in | 1 + programs/winedbg/be_ppc64.c | 303 ++++++++++++++++++++++++++++++++ programs/winedbg/tgt_active.c | 2 + programs/winedbg/tgt_minidump.c | 3 + programs/winedbg/winedbg.c | 4 + 5 files changed, 313 insertions(+) create mode 100644 programs/winedbg/be_ppc64.c
diff --git a/programs/winedbg/Makefile.in b/programs/winedbg/Makefile.in index ca60d566288..a809e9d955a 100644 --- a/programs/winedbg/Makefile.in +++ b/programs/winedbg/Makefile.in @@ -8,6 +8,7 @@ C_SRCS = \ be_arm.c \ be_arm64.c \ be_i386.c \ + be_ppc64.c \ be_x86_64.c \ break.c \ crashdlg.c \ diff --git a/programs/winedbg/be_ppc64.c b/programs/winedbg/be_ppc64.c new file mode 100644 index 00000000000..46d86b15bb7 --- /dev/null +++ b/programs/winedbg/be_ppc64.c @@ -0,0 +1,303 @@ +/* + * Debugger Power PC specific functions + * + * Copyright 2000-2003 Marcus Meissner + * 2004 Eric Pouech + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "debugger.h" + +#if defined(__powerpc64__) + +static BOOL be_ppc_get_addr(HANDLE hThread, const dbg_ctx_t *ctx, + enum be_cpu_addr bca, ADDRESS64* addr) +{ + switch (bca) + { + case be_cpu_addr_pc: + return be_cpu_build_addr(hThread, ctx, addr, 0, ctx->ctx.Iar); + default: + case be_cpu_addr_stack: + case be_cpu_addr_frame: + dbg_printf("not done\n"); + } + return FALSE; +} + +static BOOL be_ppc_get_register_info(int regno, enum be_cpu_addr* kind) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static void be_ppc_single_step(dbg_ctx_t *ctx, BOOL enable) +{ +#ifndef MSR_SE +# define MSR_SE (1<<10) +#endif + if (enable) ctx->ctx.Msr |= MSR_SE; + else ctx->ctx.Msr &= ~MSR_SE; +} + +static void be_ppc_print_context(HANDLE hThread, const dbg_ctx_t *ctx, int all_regs) +{ + dbg_printf("Context printing for PPC not done yet\n"); +} + +static void be_ppc_print_segment_info(HANDLE hThread, const dbg_ctx_t *ctx) +{ +} + +static struct dbg_internal_var be_ppc_ctx[] = +{ + {0, NULL, 0, dbg_itype_none} +}; + +static BOOL be_ppc_is_step_over_insn(const void* insn) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static BOOL be_ppc_is_function_return(const void* insn) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static BOOL be_ppc_is_break_insn(const void* insn) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static BOOL be_ppc_is_func_call(const void* insn, ADDRESS64* callee) +{ + return FALSE; +} + +static BOOL be_ppc_is_jump(const void* insn, ADDRESS64* jumpee) +{ + return FALSE; +} + +static void be_ppc_disasm_one_insn(ADDRESS64* addr, int display) + +{ + dbg_printf("Disasm NIY\n"); +} + +static BOOL be_ppc_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio, + dbg_ctx_t *ctx, enum be_xpoint_type type, + void* addr, unsigned long* val, unsigned size) +{ + unsigned long xbp; + SIZE_T sz; + + switch (type) + { + case be_xpoint_break: + if (!size) return FALSE; + if (!pio->read(hProcess, addr, val, 4, &sz) || sz != 4) return FALSE; + xbp = 0x7d821008; /* 7d 82 10 08 ... in big endian */ + if (!pio->write(hProcess, addr, &xbp, 4, &sz) || sz != 4) return FALSE; + break; + default: + dbg_printf("Unknown/unsupported bp type %c\n", type); + return FALSE; + } + return TRUE; +} + +static BOOL be_ppc_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio, + dbg_ctx_t *ctx, enum be_xpoint_type type, + void* addr, unsigned long val, unsigned size) +{ + SIZE_T sz; + + switch (type) + { + case be_xpoint_break: + if (!size) return FALSE; + if (!pio->write(hProcess, addr, &val, 4, &sz) || sz == 4) return FALSE; + break; + default: + dbg_printf("Unknown/unsupported bp type %c\n", type); + return FALSE; + } + return TRUE; +} + +static BOOL be_ppc_is_watchpoint_set(const dbg_ctx_t *ctx, unsigned idx) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static void be_ppc_clear_watchpoint(dbg_ctx_t *ctx, unsigned idx) +{ + dbg_printf("not done\n"); +} + +static int be_ppc_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way) +{ + dbg_printf("not done\n"); + return 0; +} + +static BOOL be_ppc_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size, + BOOL is_signed, LONGLONG* ret) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static BOOL be_ppc_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, + long double* ret) +{ + dbg_printf("not done\n"); + return FALSE; +} + +static BOOL be_ppc_store_integer(const struct dbg_lvalue* lvalue, unsigned size, + BOOL is_signed, LONGLONG val) +{ + dbg_printf("be_ppc_store_integer: not done\n"); + return FALSE; +} + +static BOOL be_ppc_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ + ctx->ctx.ContextFlags = CONTEXT_ALL; + return GetThreadContext(thread, &ctx->ctx); +} + +static BOOL be_ppc_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return SetThreadContext(thread, &ctx->ctx); +} + +#define REG(r,gs) {FIELD_OFFSET(CONTEXT, r), sizeof(((CONTEXT*)NULL)->r), gs} + +static struct gdb_register be_ppc_gdb_register_map[] = { + REG(Gpr0, 4), + REG(Gpr1, 4), + REG(Gpr2, 4), + REG(Gpr3, 4), + REG(Gpr4, 4), + REG(Gpr5, 4), + REG(Gpr6, 4), + REG(Gpr7, 4), + REG(Gpr8, 4), + REG(Gpr9, 4), + REG(Gpr10, 4), + REG(Gpr11, 4), + REG(Gpr12, 4), + REG(Gpr13, 4), + REG(Gpr14, 4), + REG(Gpr15, 4), + REG(Gpr16, 4), + REG(Gpr17, 4), + REG(Gpr18, 4), + REG(Gpr19, 4), + REG(Gpr20, 4), + REG(Gpr21, 4), + REG(Gpr22, 4), + REG(Gpr23, 4), + REG(Gpr24, 4), + REG(Gpr25, 4), + REG(Gpr26, 4), + REG(Gpr27, 4), + REG(Gpr28, 4), + REG(Gpr29, 4), + REG(Gpr30, 4), + REG(Gpr31, 4), + REG(Fpr0, 4), + REG(Fpr1, 4), + REG(Fpr2, 4), + REG(Fpr3, 4), + REG(Fpr4, 4), + REG(Fpr5, 4), + REG(Fpr6, 4), + REG(Fpr7, 4), + REG(Fpr8, 4), + REG(Fpr9, 4), + REG(Fpr10, 4), + REG(Fpr11, 4), + REG(Fpr12, 4), + REG(Fpr13, 4), + REG(Fpr14, 4), + REG(Fpr15, 4), + REG(Fpr16, 4), + REG(Fpr17, 4), + REG(Fpr18, 4), + REG(Fpr19, 4), + REG(Fpr20, 4), + REG(Fpr21, 4), + REG(Fpr22, 4), + REG(Fpr23, 4), + REG(Fpr24, 4), + REG(Fpr25, 4), + REG(Fpr26, 4), + REG(Fpr27, 4), + REG(Fpr28, 4), + REG(Fpr29, 4), + REG(Fpr30, 4), + REG(Fpr31, 4), + + REG(Iar, 4), + REG(Msr, 4), + REG(Cr, 4), + REG(Lr, 4), + REG(Ctr, 4), + REG(Xer, 4), + /* FIXME: MQ is missing? FIELD_OFFSET(CONTEXT, Mq), */ + /* see gdb/nlm/ppc.c */ +}; + +struct backend_cpu be_ppc64 = +{ + IMAGE_FILE_MACHINE_POWERPC64, + 8, + be_cpu_linearize, + be_cpu_build_addr, + be_ppc_get_addr, + be_ppc_get_register_info, + be_ppc_single_step, + be_ppc_print_context, + be_ppc_print_segment_info, + be_ppc_ctx, + be_ppc_is_step_over_insn, + be_ppc_is_function_return, + be_ppc_is_break_insn, + be_ppc_is_func_call, + be_ppc_is_jump, + be_ppc_disasm_one_insn, + be_ppc_insert_Xpoint, + be_ppc_remove_Xpoint, + be_ppc_is_watchpoint_set, + be_ppc_clear_watchpoint, + be_ppc_adjust_pc_for_break, + be_ppc_fetch_integer, + be_ppc_fetch_float, + be_ppc_store_integer, + be_ppc_get_context, + be_ppc_set_context, + be_ppc_gdb_register_map, + ARRAY_SIZE(be_ppc_gdb_register_map), +}; +#endif diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index d4e2d7d6347..0e74aae2c2c 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -756,6 +756,8 @@ static void output_system_info(void) static const char platform[] = "i386"; #elif defined(__x86_64__) static const char platform[] = "x86_64"; +#elif defined(__powerpc64__) + static const char platform[] = "powerpc64"; #elif defined(__arm__) static const char platform[] = "arm"; #elif defined(__aarch64__) diff --git a/programs/winedbg/tgt_minidump.c b/programs/winedbg/tgt_minidump.c index 95af7a601e5..295e3e2b4d4 100644 --- a/programs/winedbg/tgt_minidump.c +++ b/programs/winedbg/tgt_minidump.c @@ -291,6 +291,9 @@ static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data) case PROCESSOR_ARCHITECTURE_PPC: str = "PowerPC"; break; + case PROCESSOR_ARCHITECTURE_PPC64: + str = "PowerPC 64"; + break; case PROCESSOR_ARCHITECTURE_AMD64: str = "X86_64"; break; diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index 838089e8628..ff2dcef20a8 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -280,6 +280,8 @@ struct dbg_process* dbg_get_process_h(HANDLE h)
#ifdef __i386__ extern struct backend_cpu be_i386; +#elif defined(__powerpc64__) +extern struct backend_cpu be_ppc64; #elif defined(__x86_64__) extern struct backend_cpu be_i386; extern struct backend_cpu be_x86_64; @@ -327,6 +329,8 @@ struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid,
#ifdef __i386__ p->be_cpu = &be_i386; +#elif defined(__powerpc64__) + p->be_cpu = &be_ppc64; #elif defined(__x86_64__) p->be_cpu = wow64 ? &be_i386 : &be_x86_64; #elif defined(__arm__) && !defined(__ARMEB__)
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/dbghelp/Makefile.in | 1 + dlls/dbghelp/cpu_ppc64.c | 119 +++++++++++++++++++++++++++++++++++++++ dlls/dbghelp/dbghelp.c | 6 +- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 dlls/dbghelp/cpu_ppc64.c
diff --git a/dlls/dbghelp/Makefile.in b/dlls/dbghelp/Makefile.in index a370b94e7ce..531d36487bc 100644 --- a/dlls/dbghelp/Makefile.in +++ b/dlls/dbghelp/Makefile.in @@ -10,6 +10,7 @@ C_SRCS = \ cpu_arm.c \ cpu_arm64.c \ cpu_i386.c \ + cpu_ppc64.c \ cpu_x86_64.c \ dbghelp.c \ dwarf.c \ diff --git a/dlls/dbghelp/cpu_ppc64.c b/dlls/dbghelp/cpu_ppc64.c new file mode 100644 index 00000000000..52a5f10e3d5 --- /dev/null +++ b/dlls/dbghelp/cpu_ppc64.c @@ -0,0 +1,119 @@ +/* + * File cpu_ppc64.c + * + * Copyright (C) 2009 Eric Pouech + * Copyright (C) 2010-2013 André Hentschel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <assert.h> + +#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "dbghelp_private.h" +#include "winternl.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(dbghelp); + +static BOOL ppc64_get_addr(HANDLE hThread, const CONTEXT* ctx, + enum cpu_addr ca, ADDRESS64* addr) +{ + return FALSE; +} + +#ifdef __powerpc64__ + +/* indexes in Reserved array */ +#define __CurrentModeCount 0 + +#define curr_mode (frame->Reserved[__CurrentModeCount] & 0x0F) +#define curr_count (frame->Reserved[__CurrentModeCount] >> 4) + +#define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);} +#define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10) + +/* fetch_next_frame() + * + * modify (at least) context.Pc using unwind information + * either out of debug info (dwarf), or simple Lr trace + */ +static BOOL fetch_next_frame(struct cpu_stack_walk* csw, union ctx *pcontext, + DWORD_PTR curr_pc) +{ + FIXME("stub\n"); + return TRUE; +} + +static BOOL ppc64_stack_walk(struct cpu_stack_walk *csw, STACKFRAME64 *frame, + union ctx *context) +{ + FIXME("stub\n"); + return FALSE; +} +#else +static BOOL ppc64_stack_walk(struct cpu_stack_walk* csw, STACKFRAME64 *frame, + union ctx *ctx) +{ + return FALSE; +} +#endif + +static unsigned ppc64_map_dwarf_register(unsigned regno, const struct module* module, BOOL eh_frame) +{ + FIXME("stub\n"); + return 0; +} + +static void *ppc64_fetch_context_reg(union ctx *pctx, unsigned regno, unsigned *size) +{ + FIXME("Unknown register %x\n", regno); + return NULL; +} + +static const char* ppc64_fetch_regname(unsigned regno) +{ + FIXME("Unknown register %x\n", regno); + return NULL; +} + +static BOOL ppc64_fetch_minidump_thread(struct dump_context* dc, unsigned index, unsigned flags, const CONTEXT* ctx) +{ + FIXME("stub\n"); + return TRUE; +} + +static BOOL ppc64_fetch_minidump_module(struct dump_context* dc, unsigned index, unsigned flags) +{ + FIXME("stub\n"); + return FALSE; +} + +DECLSPEC_HIDDEN struct cpu cpu_ppc64 = { + IMAGE_FILE_MACHINE_POWERPC64, + 8, + 0, + ppc64_get_addr, + ppc64_stack_walk, + NULL, + ppc64_map_dwarf_register, + ppc64_fetch_context_reg, + ppc64_fetch_regname, + ppc64_fetch_minidump_thread, + ppc64_fetch_minidump_module, +}; diff --git a/dlls/dbghelp/dbghelp.c b/dlls/dbghelp/dbghelp.c index 00d7b61fbd8..d55aae943a4 100644 --- a/dlls/dbghelp/dbghelp.c +++ b/dlls/dbghelp/dbghelp.c @@ -147,9 +147,9 @@ const char* wine_dbgstr_addr(const ADDRESS64* addr) } }
-extern struct cpu cpu_i386, cpu_x86_64, cpu_arm, cpu_arm64; +extern struct cpu cpu_i386, cpu_x86_64, cpu_arm, cpu_arm64, cpu_ppc64;
-static struct cpu* dbghelp_cpus[] = {&cpu_i386, &cpu_x86_64, &cpu_arm, &cpu_arm64, NULL}; +static struct cpu* dbghelp_cpus[] = {&cpu_i386, &cpu_x86_64, &cpu_arm, &cpu_arm64, &cpu_ppc64, NULL}; struct cpu* dbghelp_current_cpu = #if defined(__i386__) &cpu_i386 @@ -159,6 +159,8 @@ struct cpu* dbghelp_current_cpu = &cpu_arm #elif defined(__aarch64__) &cpu_arm64 +#elif defined(__powerpc64__) + &cpu_ppc64 #else #error define support for your CPU #endif
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/ntdll/Makefile.in | 2 + dlls/ntdll/loader.c | 6 +- dlls/ntdll/ntdll.spec | 2 +- dlls/ntdll/ntdll_misc.h | 2 +- dlls/ntdll/signal_powerpc64.c | 420 ++++++++++ dlls/ntdll/unix/loader.c | 4 +- dlls/ntdll/unix/signal_powerpc64.c | 1247 ++++++++++++++++++++++++++++ dlls/ntdll/unix/system.c | 7 + dlls/ntdll/unix/unix_private.h | 2 + dlls/ntdll/unixlib.h | 2 +- 10 files changed, 1688 insertions(+), 6 deletions(-) create mode 100644 dlls/ntdll/signal_powerpc64.c create mode 100644 dlls/ntdll/unix/signal_powerpc64.c
diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index b2f63d9f63a..fdd6c1aa213 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -37,6 +37,7 @@ C_SRCS = \ signal_arm.c \ signal_arm64.c \ signal_i386.c \ + signal_powerpc64.c \ signal_x86_64.c \ string.c \ sync.c \ @@ -56,6 +57,7 @@ C_SRCS = \ unix/signal_arm.c \ unix/signal_arm64.c \ unix/signal_i386.c \ + unix/signal_powerpc64.c \ unix/signal_x86_64.c \ unix/sync.c \ unix/system.c \ diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 6a90770b3b4..abad2ce4ddf 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -2071,8 +2071,10 @@ static BOOL is_valid_binary( HANDLE file, const SECTION_IMAGE_INFORMATION *info #elif defined(_WIN64) /* support 32-bit IL-only images on 64-bit */ #ifdef __x86_64__ if (info->Machine == IMAGE_FILE_MACHINE_AMD64) return TRUE; -#else +#elif defined(__aarch64__) if (info->Machine == IMAGE_FILE_MACHINE_ARM64) return TRUE; +#elif defined(__powerpc64__) + if (info->Machine == IMAGE_FILE_MACHINE_POWERPC64) return TRUE; #endif if (!info->ImageContainsCode) return TRUE; if (!(info->u.ImageFlags & IMAGE_FLAGS_ComPlusNativeReady)) @@ -3500,6 +3502,8 @@ void WINAPI LdrInitializeThunk( CONTEXT *context, ULONG_PTR unknown2, ULONG_PTR entry = (void **)&context->R0; #elif defined(__aarch64__) entry = (void **)&context->u.s.X0; +#elif defined(__powerpc64__) + entry = (void **)&context->Gpr3; #endif
if (process_detaching) NtTerminateThread( GetCurrentThread(), 0 ); diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 740030f2066..4a3e30b6f2a 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -189,7 +189,7 @@ @ stub NtCreateToken @ stdcall -syscall NtCreateUserProcess(ptr ptr long long ptr ptr long long ptr ptr ptr) # @ stub NtCreateWaitablePort -@ stdcall -arch=i386,arm64 NtCurrentTeb() +@ stdcall -arch=i386,arm64,powerpc64 NtCurrentTeb() @ stdcall -syscall NtDebugActiveProcess(long long) # @ stub NtDebugContinue @ stdcall -syscall NtDelayExecution(long ptr) diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 41e8666a25c..dcd47799385 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -38,7 +38,7 @@
#define MAX_NT_PATH_LENGTH 277
-#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) +#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__powerpc64__) static const UINT_PTR page_size = 0x1000; #else extern UINT_PTR page_size DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/signal_powerpc64.c b/dlls/ntdll/signal_powerpc64.c new file mode 100644 index 00000000000..05f99c6c12e --- /dev/null +++ b/dlls/ntdll/signal_powerpc64.c @@ -0,0 +1,420 @@ +/* + * PowerPC64 signal handling routines + * + * Copyright 2019 Timothy Pearson tpearson@raptorengineering.com + * Copyright 2020 André Hentschel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifdef __powerpc64__ + +#include <assert.h> +#include <signal.h> +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> + +#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winternl.h" +#include "wine/exception.h" +#include "ntdll_misc.h" +#include "wine/debug.h" +#include "winnt.h" + +WINE_DEFAULT_DEBUG_CHANNEL(seh); + +/* layering violation: the setjmp buffer is defined in msvcrt, but used by RtlUnwindEx */ +struct MSVCRT_JUMP_BUFFER +{ + unsigned __int64 Frame; + unsigned __int64 Reserved; + unsigned __int64 X19; + unsigned __int64 X20; + unsigned __int64 X21; + unsigned __int64 X22; + unsigned __int64 X23; + unsigned __int64 X24; + unsigned __int64 X25; + unsigned __int64 X26; + unsigned __int64 X27; + unsigned __int64 X28; + unsigned __int64 Fp; + unsigned __int64 Lr; + unsigned __int64 Sp; + unsigned long Fpcr; + unsigned long Fpsr; + double D[8]; +}; + + +/******************************************************************* + * is_valid_frame + */ +static inline BOOL is_valid_frame( void *frame ) +{ + if ((ULONG_PTR)frame & 7) return FALSE; + return (frame >= NtCurrentTeb()->Tib.StackLimit && + (void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1); +} + + +/*********************************************************************** + * RtlCaptureContext (NTDLL.@) + */ +__ASM_STDCALL_FUNC( RtlCaptureContext, 8, + /* TODO: fp regs */ + "std 0, 264(3)\n\t" /* context->Gpr0 */ + "std 1, 272(3)\n\t" /* context->Gpr1 */ + "std 2, 280(3)\n\t" /* context->Gpr2 */ + "std 3, 288(3)\n\t" /* context->Gpr3 */ + "std 4, 296(3)\n\t" /* context->Gpr4 */ + "std 5, 304(3)\n\t" /* context->Gpr5 */ + "std 6, 312(3)\n\t" /* context->Gpr6 */ + "std 7, 320(3)\n\t" /* context->Gpr7 */ + "std 8, 328(3)\n\t" /* context->Gpr8 */ + "std 9, 336(3)\n\t" /* context->Gpr9 */ + "std 10, 344(3)\n\t" /* context->Gpr10 */ + "std 11, 352(3)\n\t" /* context->Gpr11 */ + "std 12, 360(3)\n\t" /* context->Gpr12 */ + "std 13, 368(3)\n\t" /* context->Gpr13 */ + "std 14, 376(3)\n\t" /* context->Gpr14 */ + "std 15, 384(3)\n\t" /* context->Gpr15 */ + "std 16, 392(3)\n\t" /* context->Gpr16 */ + "std 17, 400(3)\n\t" /* context->Gpr17 */ + "std 18, 408(3)\n\t" /* context->Gpr18 */ + "std 19, 416(3)\n\t" /* context->Gpr19 */ + "std 20, 424(3)\n\t" /* context->Gpr20 */ + "std 21, 432(3)\n\t" /* context->Gpr21 */ + "std 22, 440(3)\n\t" /* context->Gpr22 */ + "std 23, 448(3)\n\t" /* context->Gpr23 */ + "std 24, 456(3)\n\t" /* context->Gpr24 */ + "std 25, 464(3)\n\t" /* context->Gpr25 */ + "std 26, 472(3)\n\t" /* context->Gpr26 */ + "std 27, 480(3)\n\t" /* context->Gpr27 */ + "std 28, 488(3)\n\t" /* context->Gpr28 */ + "std 29, 496(3)\n\t" /* context->Gpr29 */ + "std 30, 504(3)\n\t" /* context->Gpr30 */ + "std 31, 512(3)\n\t" /* context->Gpr31 */ + /* TODO: cr */ + /* TODO: xer */ + /* TODO: msr (536) */ + "mflr 0\n\t" + "std 0, 544(3)\n\t" /* context->Iar */ + "std 0, 552(3)\n\t" /* context->Lr */ + "mfctr 0\n\t" + "std 0, 560(3)\n\t" /* context->Ctr */ + "lis 0, 0x80\n\t" + "ori 0, 0, 7\n\t" + "std 0, 568(1)\n\t" /* context->ContextFlags = CONTEXT_FULL */ + "blr" ) + + +/********************************************************************** + * call_stack_handlers + * + * Call the stack handlers chain. + */ +static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) +{ + EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame; + DWORD res; + + frame = NtCurrentTeb()->Tib.ExceptionList; + nested_frame = NULL; + while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) + { + /* Check frame address */ + if (!is_valid_frame( frame )) + { + rec->ExceptionFlags |= EH_STACK_INVALID; + break; + } + + /* Call handler */ + TRACE( "calling handler at %p code=%x flags=%x\n", + frame->Handler, rec->ExceptionCode, rec->ExceptionFlags ); + res = frame->Handler( rec, frame, context, &dispatch ); + TRACE( "handler at %p returned %x\n", frame->Handler, res ); + + if (frame == nested_frame) + { + /* no longer nested */ + nested_frame = NULL; + rec->ExceptionFlags &= ~EH_NESTED_CALL; + } + + switch(res) + { + case ExceptionContinueExecution: + if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS; + return STATUS_NONCONTINUABLE_EXCEPTION; + case ExceptionContinueSearch: + break; + case ExceptionNestedException: + if (nested_frame < dispatch) nested_frame = dispatch; + rec->ExceptionFlags |= EH_NESTED_CALL; + break; + default: + return STATUS_INVALID_DISPOSITION; + } + frame = frame->Prev; + } + return STATUS_UNHANDLED_EXCEPTION; +} + + +/******************************************************************* + * KiUserExceptionDispatcher (NTDLL.@) + */ +NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *context ) +{ + NTSTATUS status; + DWORD c; + + TRACE( "code=%x flags=%x addr=%p pc=%lx tid=%04x\n", + rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, + context->Iar, GetCurrentThreadId() ); + for (c = 0; c < rec->NumberParameters; c++) + TRACE( " info[%d]=%016lx\n", c, rec->ExceptionInformation[c] ); + + if (rec->ExceptionCode == EXCEPTION_WINE_STUB) + { + if (rec->ExceptionInformation[1] >> 16) + MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n", + rec->ExceptionAddress, + (char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] ); + else + MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n", + rec->ExceptionAddress, + (char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] ); + } + else + { + TRACE(" r0=%016lx r1=%016lx r2=%016lx r3=%016lx\n", + context->Gpr0, context->Gpr1, context->Gpr2, context->Gpr3 ); + TRACE(" r4=%016lx r5=%016lx r6=%016lx r7=%016lx\n", + context->Gpr4, context->Gpr5, context->Gpr6, context->Gpr7 ); + TRACE(" r8=%016lx r9=%016lx r10=%016lx r11=%016lx\n", + context->Gpr8, context->Gpr9, context->Gpr10, context->Gpr11 ); + TRACE(" r12=%016lx r13=%016lx r14=%016lx r15=%016lx\n", + context->Gpr12, context->Gpr13, context->Gpr14, context->Gpr15 ); + TRACE(" r16=%016lx r17=%016lx r18=%016lx r19=%016lx\n", + context->Gpr16, context->Gpr17, context->Gpr18, context->Gpr19 ); + TRACE(" r20=%016lx r21=%016lx r22=%016lx r23=%016lx\n", + context->Gpr20, context->Gpr21, context->Gpr22, context->Gpr23 ); + TRACE(" r24=%016lx r25=%016lx r26=%016lx r27=%016lx\n", + context->Gpr24, context->Gpr25, context->Gpr26, context->Gpr27 ); + TRACE(" r28=%016lx r29=%016lx r30=%016lx r31=%016lx\n", + context->Gpr28, context->Gpr29, context->Gpr30, context->Gpr31 ); + TRACE(" ctr=%016lx fpscr=%016lx lr=%016lx\n", + context->Ctr, context->Fpscr, context->Lr ); + } + + if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) + NtContinue( context, FALSE ); + + if ((status = call_stack_handlers( rec, context )) == STATUS_SUCCESS) + NtContinue( context, FALSE ); + + if (status != STATUS_UNHANDLED_EXCEPTION) RtlRaiseStatus( status ); + return NtRaiseException( rec, context, FALSE ); +} + +/******************************************************************* + * KiUserApcDispatcher (NTDLL.@) + */ +void WINAPI KiUserApcDispatcher( CONTEXT *context, ULONG_PTR ctx, ULONG_PTR arg1, ULONG_PTR arg2, + PNTAPCFUNC func ) +{ + func( ctx, arg1, arg2 ); + NtContinue( context, TRUE ); +} + +/********************************************************************** + * RtlVirtualUnwind (NTDLL.@) + */ +PVOID WINAPI RtlVirtualUnwind( ULONG type, ULONG_PTR base, ULONG_PTR pc, + void *func, CONTEXT *context, + PVOID *handler_data, ULONG_PTR *frame_ret, + void *ctx_ptr ) +{ + FIXME( "stub!\n" ); + return NULL; +} + +/******************************************************************* + * RtlRestoreContext (NTDLL.@) + */ +void CDECL RtlRestoreContext( CONTEXT *context, EXCEPTION_RECORD *rec ) +{ + FIXME( "stub!\n" ); +} + +/*********************************************************************** + * RtlUnwind (NTDLL.@) + */ +void WINAPI RtlUnwind( void *end_frame, void *target_ip, EXCEPTION_RECORD *rec, void *retval ) +{ + CONTEXT context; + EXCEPTION_RECORD record; + EXCEPTION_REGISTRATION_RECORD *frame, *dispatch; + DWORD res; + + RtlCaptureContext( &context ); + context.Gpr3 = (DWORD64)retval; + + /* build an exception record, if we do not have one */ + if (!rec) + { + record.ExceptionCode = STATUS_UNWIND; + record.ExceptionFlags = 0; + record.ExceptionRecord = NULL; + record.ExceptionAddress = (void *)context.Iar; + record.NumberParameters = 0; + rec = &record; + } + + rec->ExceptionFlags |= EH_UNWINDING | (end_frame ? 0 : EH_EXIT_UNWIND); + + TRACE( "code=%x flags=%x\n", rec->ExceptionCode, rec->ExceptionFlags ); + + /* get chain of exception frames */ + frame = NtCurrentTeb()->Tib.ExceptionList; + while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != end_frame)) + { + /* Check frame address */ + if (end_frame && ((void*)frame > end_frame)) + raise_status( STATUS_INVALID_UNWIND_TARGET, rec ); + + if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, rec ); + + /* Call handler */ + TRACE( "calling handler at %p code=%x flags=%x\n", + frame->Handler, rec->ExceptionCode, rec->ExceptionFlags ); + res = frame->Handler(rec, frame, &context, &dispatch); + TRACE( "handler at %p returned %x\n", frame->Handler, res ); + + switch(res) + { + case ExceptionContinueSearch: + break; + case ExceptionCollidedUnwind: + frame = dispatch; + break; + default: + raise_status( STATUS_INVALID_DISPOSITION, rec ); + break; + } + frame = __wine_pop_frame( frame ); + } +} + + +/*********************************************************************** + * RtlRaiseException (NTDLL.@) + */ +__ASM_STDCALL_FUNC( RtlRaiseException, 4, + "mflr 0\n\t" + "std 0, 16(1)\n\t" + "stdu 1, -0x2d8(1)\n\t" /* 0x298 (context) + 0x40 */ + "std 3, 32(1)\n\t" + "addi 3, 1, 0x40\n\t" + "lis 12, " __ASM_NAME("RtlCaptureContext") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("RtlCaptureContext") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("RtlCaptureContext") "@high\n\t" + "ori 12, 12, " __ASM_NAME("RtlCaptureContext") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "addi 4, 1, 0x40\n\t" /* context pointer */ + "addi 5, 1, 0x2d8\n\t" /* orig stack pointer */ + "std 5, 272(4)\n\t" /* context->Gpr1 aka SP */ + "ld 3, 32(1)\n\t" /* original first parameter */ + "std 3, 288(4)\n\t" /* context->Gpr3 */ + "ld 6, 0x2e8(1)\n\t" + "std 6, 544(4)\n\t" /* context->Iar */ + "std 6, 552(4)\n\t" /* context->Lr */ + "std 6, 16(3)\n\t" /* rec->ExceptionAddress */ + "li 5, 1\n\t" + "lis 12, " __ASM_NAME("NtRaiseException") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("NtRaiseException") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("NtRaiseException") "@high\n\t" + "ori 12, 12, " __ASM_NAME("NtRaiseException") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "lis 12, " __ASM_NAME("RtlRaiseStatus") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("RtlRaiseStatus") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("RtlRaiseStatus") "@high\n\t" + "ori 12, 12, " __ASM_NAME("RtlRaiseStatus") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" /* does not return */ + "ori 0, 0, 0" ); + +/************************************************************************* + * RtlCaptureStackBackTrace (NTDLL.@) + */ +USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash ) +{ + FIXME( "(%d, %d, %p, %p) stub!\n", skip, count, buffer, hash ); + return 0; +} + +/*********************************************************************** + * signal_start_thread + */ +__ASM_GLOBAL_FUNC( signal_start_thread, + "mr 1, 3\n\t" /* context */ + "li 4, 1\n\t" + "lis 12, " __ASM_NAME("NtContinue") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("NtContinue") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("NtContinue") "@high\n\t" + "ori 12, 12, " __ASM_NAME("NtContinue") "@l\n\t" + "mtctr 12\n\t" + "bctr" ) + +/********************************************************************** + * DbgBreakPoint (NTDLL.@) + */ +void WINAPI DbgBreakPoint(void) +{ + FIXME( "stub!\n" ); +} + +/********************************************************************** + * DbgUserBreakPoint (NTDLL.@) + */ +void WINAPI DbgUserBreakPoint(void) +{ + FIXME( "stub!\n" ); +} +/********************************************************************** + * NtCurrentTeb (NTDLL.@) + */ +TEB * WINAPI NtCurrentTeb(void) +{ + return unix_funcs->NtCurrentTeb(); +} + +#endif /* __aarch64__ */ diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 8caddb19abf..9f771c5d230 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -483,7 +483,7 @@ static NTSTATUS loader_exec( const char *loader, char **argv, client_cpu_t cpu ) */ NTSTATUS exec_wineloader( char **argv, int socketfd, const pe_image_info_t *pe_info ) { - int is_child_64bit = (pe_info->cpu == CPU_x86_64 || pe_info->cpu == CPU_ARM64); + int is_child_64bit = (pe_info->cpu == CPU_x86_64 || pe_info->cpu == CPU_ARM64 || pe_info->cpu == CPU_POWERPC64); ULONGLONG res_start = pe_info->base; ULONGLONG res_end = pe_info->base + pe_info->map_size; const char *loader = argv0; @@ -1563,7 +1563,7 @@ static double CDECL ntdll_tan( double d ) { return tan( d ); } */ static struct unix_funcs unix_funcs = { -#ifdef __aarch64__ +#if defined(__aarch64__) || defined(__powerpc64__) NtCurrentTeb, #endif DbgUiIssueRemoteBreakin, diff --git a/dlls/ntdll/unix/signal_powerpc64.c b/dlls/ntdll/unix/signal_powerpc64.c new file mode 100644 index 00000000000..44762ce28cd --- /dev/null +++ b/dlls/ntdll/unix/signal_powerpc64.c @@ -0,0 +1,1247 @@ +/* + * PowerPC64 signal handling routines + * + * Copyright 2019 Timothy Pearson tpearson@raptorengineering.com + * Copyright 2020 André Hentschel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#ifdef __powerpc64__ + +#include "config.h" +#include "wine/port.h" + +#include <assert.h> +#include <pthread.h> +#include <signal.h> +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif +#ifdef HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif +#ifdef HAVE_SYSCALL_H +# include <syscall.h> +#else +# ifdef HAVE_SYS_SYSCALL_H +# include <sys/syscall.h> +# endif +#endif +#ifdef HAVE_SYS_SIGNAL_H +# include <sys/signal.h> +#endif +#ifdef HAVE_SYS_UCONTEXT_H +# include <sys/ucontext.h> +#endif +#ifdef HAVE_LIBUNWIND +# define UNW_LOCAL_ONLY +# include <libunwind.h> +#endif + +#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winnt.h" +#include "winternl.h" +#include "wine/exception.h" +#include "wine/asm.h" +#include "unix_private.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(seh); + +/*********************************************************************** + * signal context platform-specific definitions + */ +#ifdef linux + +/* All Registers access - only for local access */ +# define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name) + + +/* Gpr Registers access */ +# define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) + +# define IAR_sig(context) REG_sig(nip, context) /* Program counter */ +# define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */ +# define CTR_sig(context) REG_sig(ctr, context) /* Count register */ + +# define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */ +# define LR_sig(context) REG_sig(link, context) /* Link register */ +# define CR_sig(context) REG_sig(ccr, context) /* Condition register */ + +/* Float Registers access */ +# define FLOAT_sig(reg_num, context) ((context)->uc_mcontext.fp_regs[reg_num]) + +# define FPSCR_sig(context) FLOAT_sig(32, context) + +/* Exception Registers access */ +# define DAR_sig(context) REG_sig(dar, context) +# define DSISR_sig(context) REG_sig(dsisr, context) +# define TRAP_sig(context) REG_sig(trap, context) + +#endif /* linux */ + +static pthread_key_t teb_key; + +struct syscall_frame +{ + ULONG64 r1; + ULONG64 cr; /* unused */ + ULONG64 pad0; + ULONG64 r2; + ULONG64 r3, r4, r5, r6, r7, r8, r9, r10; + ULONG64 r14, r15, r16, r17, r18, r19, r20, r21, r22; + ULONG64 r23, r24, r25, r26, r27, r28, r29, r30, r31; + ULONG64 thunk_r1; + ULONG64 pad2; + ULONG64 thunk_addr; + ULONG64 thunk_r2; + ULONG64 ret_addr; + ULONG64 r11; + ULONG64 r12; + ULONG64 pad3; +}; + +struct ppc64_thread_data +{ + void *exit_frame; /* 02f0 exit frame pointer */ + struct syscall_frame *syscall_frame; /* 02f8 frame pointer on syscall entry */ +}; + +C_ASSERT( sizeof(struct ppc64_thread_data) <= sizeof(((struct ntdll_thread_data *)0)->cpu_data) ); +C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct ppc64_thread_data, exit_frame ) == 0x2f0 ); +C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct ppc64_thread_data, syscall_frame ) == 0x2f8 ); + +static inline struct ppc64_thread_data *ppc64_thread_data(void) +{ + return (struct ppc64_thread_data *)ntdll_get_thread_data()->cpu_data; +} + +void *get_syscall_frame(void) +{ + return ppc64_thread_data()->syscall_frame; +} + +void set_syscall_frame(void *frame) +{ + ppc64_thread_data()->syscall_frame = frame; +} + +/*********************************************************************** + * unwind_builtin_dll + * + * Equivalent of RtlVirtualUnwind for builtin modules. + */ +NTSTATUS CDECL unwind_builtin_dll( ULONG type, struct _DISPATCHER_CONTEXT *dispatch, CONTEXT *context ) +{ + FIXME("not implemented\n"); + return STATUS_UNSUCCESSFUL; +} + + +/*********************************************************************** + * save_context + * + * Set the register values from a sigcontext. + */ +static void save_context( CONTEXT *context, const ucontext_t *sigcontext ) +{ +#define C(x) context->Gpr##x = GPR_sig(x,sigcontext) + /* Save Gpr registers */ + C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); + C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); + C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); + C(31); +#undef C + + context->Iar = IAR_sig(sigcontext); /* Program Counter */ + context->Msr = MSR_sig(sigcontext); /* Machine State Register (Supervisor) */ + context->Ctr = CTR_sig(sigcontext); + + context->Xer = XER_sig(sigcontext); + context->Lr = LR_sig(sigcontext); + context->Cr = CR_sig(sigcontext); + + /* Saving Exception regs */ + context->Dar = DAR_sig(sigcontext); + context->Dsisr = DSISR_sig(sigcontext); + context->Trap = TRAP_sig(sigcontext); +} + + +/*********************************************************************** + * restore_context + * + * Build a sigcontext from the register values. + */ +static void restore_context( const CONTEXT *context, ucontext_t *sigcontext ) +{ +#define C(x) GPR_sig(x,sigcontext) = context->Gpr##x + C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); + C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); + C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); + C(31); +#undef C + + IAR_sig(sigcontext) = context->Iar; /* Program Counter */ + MSR_sig(sigcontext) = context->Msr; /* Machine State Register (Supervisor) */ + CTR_sig(sigcontext) = context->Ctr; + + XER_sig(sigcontext) = context->Xer; + LR_sig(sigcontext) = context->Lr; + CR_sig(sigcontext) = context->Cr; + + /* Setting Exception regs */ + DAR_sig(sigcontext) = context->Dar; + DSISR_sig(sigcontext) = context->Dsisr; + TRAP_sig(sigcontext) = context->Trap; +} + + +/*********************************************************************** + * save_fpu + * + * Set the FPU context from a sigcontext. + */ +static void save_fpu( CONTEXT *context, ucontext_t *sigcontext ) +{ +#define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext) + C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); + C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); + C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); + C(31); +#undef C + context->Fpscr = FPSCR_sig(sigcontext); +} + + +/*********************************************************************** + * restore_fpu + * + * Restore the FPU context to a sigcontext. + */ +static void restore_fpu( CONTEXT *context, ucontext_t *sigcontext ) +{ +#define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x + C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10); + C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20); + C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30); + C(31); +#undef C + FPSCR_sig(sigcontext) = context->Fpscr; +} + + +/*********************************************************************** + * set_cpu_context + * + * Set the new CPU context. + */ +void DECLSPEC_HIDDEN set_cpu_context( const CONTEXT *context ); +__ASM_GLOBAL_FUNC( set_cpu_context, + "ld 1, 272(3)\n\t" + "ld 2, 280(3)\n\t" + "ld 4, 296(3)\n\t" + "ld 5, 304(3)\n\t" + "ld 6, 312(3)\n\t" + "ld 7, 320(3)\n\t" + "ld 8, 328(3)\n\t" + "ld 9, 336(3)\n\t" + "ld 10, 344(3)\n\t" + "ld 11, 352(3)\n\t" + "ld 14, 376(3)\n\t" + "ld 15, 384(3)\n\t" + "ld 16, 392(3)\n\t" + "ld 17, 400(3)\n\t" + "ld 18, 408(3)\n\t" + "ld 19, 416(3)\n\t" + "ld 20, 424(3)\n\t" + "ld 21, 432(3)\n\t" + "ld 22, 440(3)\n\t" + "ld 23, 448(3)\n\t" + "ld 24, 456(3)\n\t" + "ld 25, 464(3)\n\t" + "ld 26, 472(3)\n\t" + "ld 27, 480(3)\n\t" + "ld 28, 488(3)\n\t" + "ld 29, 496(3)\n\t" + "ld 30, 504(3)\n\t" + "ld 31, 512(3)\n\t" + "ld 12, 544(3)\n\t" /* iar */ + "ld 0, 552(3)\n\t" /* lr */ + "mtlr 0\n\t" + "ld 3, 288(3)\n\t" /* r3 */ + "mtctr 12\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + + +/*********************************************************************** + * get_server_context_flags + * + * Convert CPU-specific flags to generic server flags + */ +static unsigned int get_server_context_flags( DWORD flags ) +{ + unsigned int ret = 0; + + flags &= ~CONTEXT_POWERPC64; /* get rid of CPU id */ + if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL; + if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER; + if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT; + if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS; + return ret; +} + + +/*********************************************************************** + * context_to_server + * + * Convert a register context to the server format. + */ +NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) +{ + DWORD flags = from->ContextFlags & ~CONTEXT_POWERPC64; /* get rid of CPU id */ + + memset( to, 0, sizeof(*to) ); + to->cpu = CPU_POWERPC64; + + if (flags & CONTEXT_CONTROL) + { + to->flags |= SERVER_CTX_CONTROL; + to->ctl.powerpc64_regs.iar = from->Iar; + to->ctl.powerpc64_regs.msr = from->Msr; + to->ctl.powerpc64_regs.ctr = from->Ctr; + to->ctl.powerpc64_regs.lr = from->Lr; + to->ctl.powerpc64_regs.dar = from->Dar; + to->ctl.powerpc64_regs.dsisr = from->Dsisr; + to->ctl.powerpc64_regs.trap = from->Trap; + } + if (flags & CONTEXT_INTEGER) + { + to->flags |= SERVER_CTX_INTEGER; + to->integer.powerpc64_regs.gpr[0] = from->Gpr0; + to->integer.powerpc64_regs.gpr[1] = from->Gpr1; + to->integer.powerpc64_regs.gpr[2] = from->Gpr2; + to->integer.powerpc64_regs.gpr[3] = from->Gpr3; + to->integer.powerpc64_regs.gpr[4] = from->Gpr4; + to->integer.powerpc64_regs.gpr[5] = from->Gpr5; + to->integer.powerpc64_regs.gpr[6] = from->Gpr6; + to->integer.powerpc64_regs.gpr[7] = from->Gpr7; + to->integer.powerpc64_regs.gpr[8] = from->Gpr8; + to->integer.powerpc64_regs.gpr[9] = from->Gpr9; + to->integer.powerpc64_regs.gpr[10] = from->Gpr10; + to->integer.powerpc64_regs.gpr[11] = from->Gpr11; + to->integer.powerpc64_regs.gpr[12] = from->Gpr12; + to->integer.powerpc64_regs.gpr[13] = from->Gpr13; + to->integer.powerpc64_regs.gpr[14] = from->Gpr14; + to->integer.powerpc64_regs.gpr[15] = from->Gpr15; + to->integer.powerpc64_regs.gpr[16] = from->Gpr16; + to->integer.powerpc64_regs.gpr[17] = from->Gpr17; + to->integer.powerpc64_regs.gpr[18] = from->Gpr18; + to->integer.powerpc64_regs.gpr[19] = from->Gpr19; + to->integer.powerpc64_regs.gpr[20] = from->Gpr20; + to->integer.powerpc64_regs.gpr[21] = from->Gpr21; + to->integer.powerpc64_regs.gpr[22] = from->Gpr22; + to->integer.powerpc64_regs.gpr[23] = from->Gpr23; + to->integer.powerpc64_regs.gpr[24] = from->Gpr24; + to->integer.powerpc64_regs.gpr[25] = from->Gpr25; + to->integer.powerpc64_regs.gpr[26] = from->Gpr26; + to->integer.powerpc64_regs.gpr[27] = from->Gpr27; + to->integer.powerpc64_regs.gpr[28] = from->Gpr28; + to->integer.powerpc64_regs.gpr[29] = from->Gpr29; + to->integer.powerpc64_regs.gpr[30] = from->Gpr30; + to->integer.powerpc64_regs.gpr[31] = from->Gpr31; + to->integer.powerpc64_regs.xer = from->Xer; + to->integer.powerpc64_regs.cr = from->Cr; + } + if (flags & CONTEXT_FLOATING_POINT) + { + to->flags |= SERVER_CTX_FLOATING_POINT; + to->fp.powerpc64_regs.fpr[0] = from->Fpr0; + to->fp.powerpc64_regs.fpr[1] = from->Fpr1; + to->fp.powerpc64_regs.fpr[2] = from->Fpr2; + to->fp.powerpc64_regs.fpr[3] = from->Fpr3; + to->fp.powerpc64_regs.fpr[4] = from->Fpr4; + to->fp.powerpc64_regs.fpr[5] = from->Fpr5; + to->fp.powerpc64_regs.fpr[6] = from->Fpr6; + to->fp.powerpc64_regs.fpr[7] = from->Fpr7; + to->fp.powerpc64_regs.fpr[8] = from->Fpr8; + to->fp.powerpc64_regs.fpr[9] = from->Fpr9; + to->fp.powerpc64_regs.fpr[10] = from->Fpr10; + to->fp.powerpc64_regs.fpr[11] = from->Fpr11; + to->fp.powerpc64_regs.fpr[12] = from->Fpr12; + to->fp.powerpc64_regs.fpr[13] = from->Fpr13; + to->fp.powerpc64_regs.fpr[14] = from->Fpr14; + to->fp.powerpc64_regs.fpr[15] = from->Fpr15; + to->fp.powerpc64_regs.fpr[16] = from->Fpr16; + to->fp.powerpc64_regs.fpr[17] = from->Fpr17; + to->fp.powerpc64_regs.fpr[18] = from->Fpr18; + to->fp.powerpc64_regs.fpr[19] = from->Fpr19; + to->fp.powerpc64_regs.fpr[20] = from->Fpr20; + to->fp.powerpc64_regs.fpr[21] = from->Fpr21; + to->fp.powerpc64_regs.fpr[22] = from->Fpr22; + to->fp.powerpc64_regs.fpr[23] = from->Fpr23; + to->fp.powerpc64_regs.fpr[24] = from->Fpr24; + to->fp.powerpc64_regs.fpr[25] = from->Fpr25; + to->fp.powerpc64_regs.fpr[26] = from->Fpr26; + to->fp.powerpc64_regs.fpr[27] = from->Fpr27; + to->fp.powerpc64_regs.fpr[28] = from->Fpr28; + to->fp.powerpc64_regs.fpr[29] = from->Fpr29; + to->fp.powerpc64_regs.fpr[30] = from->Fpr30; + to->fp.powerpc64_regs.fpr[31] = from->Fpr31; + to->fp.powerpc64_regs.fpscr = from->Fpscr; + } + return STATUS_SUCCESS; +} + + +/*********************************************************************** + * context_from_server + * + * Convert a register context from the server format. + */ +NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) +{ + if (from->cpu != CPU_POWERPC64) return STATUS_INVALID_PARAMETER; + + to->ContextFlags = CONTEXT_POWERPC64; + if (from->flags & SERVER_CTX_CONTROL) + { + to->ContextFlags |= CONTEXT_CONTROL; + to->Msr = from->ctl.powerpc64_regs.msr; + to->Ctr = from->ctl.powerpc64_regs.ctr; + to->Iar = from->ctl.powerpc64_regs.iar; + to->Lr = from->ctl.powerpc64_regs.lr; + to->Dar = from->ctl.powerpc64_regs.dar; + to->Dsisr = from->ctl.powerpc64_regs.dsisr; + to->Trap = from->ctl.powerpc64_regs.trap; + } + if (from->flags & SERVER_CTX_INTEGER) + { + to->ContextFlags |= CONTEXT_INTEGER; + to->Gpr0 = from->integer.powerpc64_regs.gpr[0]; + to->Gpr1 = from->integer.powerpc64_regs.gpr[1]; + to->Gpr2 = from->integer.powerpc64_regs.gpr[2]; + to->Gpr3 = from->integer.powerpc64_regs.gpr[3]; + to->Gpr4 = from->integer.powerpc64_regs.gpr[4]; + to->Gpr5 = from->integer.powerpc64_regs.gpr[5]; + to->Gpr6 = from->integer.powerpc64_regs.gpr[6]; + to->Gpr7 = from->integer.powerpc64_regs.gpr[7]; + to->Gpr8 = from->integer.powerpc64_regs.gpr[8]; + to->Gpr9 = from->integer.powerpc64_regs.gpr[9]; + to->Gpr10 = from->integer.powerpc64_regs.gpr[10]; + to->Gpr11 = from->integer.powerpc64_regs.gpr[11]; + to->Gpr12 = from->integer.powerpc64_regs.gpr[12]; + to->Gpr13 = from->integer.powerpc64_regs.gpr[13]; + to->Gpr14 = from->integer.powerpc64_regs.gpr[14]; + to->Gpr15 = from->integer.powerpc64_regs.gpr[15]; + to->Gpr16 = from->integer.powerpc64_regs.gpr[16]; + to->Gpr17 = from->integer.powerpc64_regs.gpr[17]; + to->Gpr18 = from->integer.powerpc64_regs.gpr[18]; + to->Gpr19 = from->integer.powerpc64_regs.gpr[19]; + to->Gpr20 = from->integer.powerpc64_regs.gpr[20]; + to->Gpr21 = from->integer.powerpc64_regs.gpr[21]; + to->Gpr22 = from->integer.powerpc64_regs.gpr[22]; + to->Gpr23 = from->integer.powerpc64_regs.gpr[23]; + to->Gpr24 = from->integer.powerpc64_regs.gpr[24]; + to->Gpr25 = from->integer.powerpc64_regs.gpr[25]; + to->Gpr26 = from->integer.powerpc64_regs.gpr[26]; + to->Gpr27 = from->integer.powerpc64_regs.gpr[27]; + to->Gpr28 = from->integer.powerpc64_regs.gpr[28]; + to->Gpr29 = from->integer.powerpc64_regs.gpr[29]; + to->Gpr30 = from->integer.powerpc64_regs.gpr[30]; + to->Gpr31 = from->integer.powerpc64_regs.gpr[31]; + to->Xer = from->integer.powerpc64_regs.xer; + to->Cr = from->integer.powerpc64_regs.cr; + } + if (from->flags & SERVER_CTX_FLOATING_POINT) + { + to->ContextFlags |= CONTEXT_FLOATING_POINT; + to->Fpr0 = from->fp.powerpc64_regs.fpr[0]; + to->Fpr1 = from->fp.powerpc64_regs.fpr[1]; + to->Fpr2 = from->fp.powerpc64_regs.fpr[2]; + to->Fpr3 = from->fp.powerpc64_regs.fpr[3]; + to->Fpr4 = from->fp.powerpc64_regs.fpr[4]; + to->Fpr5 = from->fp.powerpc64_regs.fpr[5]; + to->Fpr6 = from->fp.powerpc64_regs.fpr[6]; + to->Fpr7 = from->fp.powerpc64_regs.fpr[7]; + to->Fpr8 = from->fp.powerpc64_regs.fpr[8]; + to->Fpr9 = from->fp.powerpc64_regs.fpr[9]; + to->Fpr10 = from->fp.powerpc64_regs.fpr[10]; + to->Fpr11 = from->fp.powerpc64_regs.fpr[11]; + to->Fpr12 = from->fp.powerpc64_regs.fpr[12]; + to->Fpr13 = from->fp.powerpc64_regs.fpr[13]; + to->Fpr14 = from->fp.powerpc64_regs.fpr[14]; + to->Fpr15 = from->fp.powerpc64_regs.fpr[15]; + to->Fpr16 = from->fp.powerpc64_regs.fpr[16]; + to->Fpr17 = from->fp.powerpc64_regs.fpr[17]; + to->Fpr18 = from->fp.powerpc64_regs.fpr[18]; + to->Fpr19 = from->fp.powerpc64_regs.fpr[19]; + to->Fpr20 = from->fp.powerpc64_regs.fpr[20]; + to->Fpr21 = from->fp.powerpc64_regs.fpr[21]; + to->Fpr22 = from->fp.powerpc64_regs.fpr[22]; + to->Fpr23 = from->fp.powerpc64_regs.fpr[23]; + to->Fpr24 = from->fp.powerpc64_regs.fpr[24]; + to->Fpr25 = from->fp.powerpc64_regs.fpr[25]; + to->Fpr26 = from->fp.powerpc64_regs.fpr[26]; + to->Fpr27 = from->fp.powerpc64_regs.fpr[27]; + to->Fpr28 = from->fp.powerpc64_regs.fpr[28]; + to->Fpr29 = from->fp.powerpc64_regs.fpr[29]; + to->Fpr30 = from->fp.powerpc64_regs.fpr[30]; + to->Fpr31 = from->fp.powerpc64_regs.fpr[31]; + to->Fpscr = from->fp.powerpc64_regs.fpscr; + } + return STATUS_SUCCESS; +} + + +/*********************************************************************** + * NtSetContextThread (NTDLL.@) + * ZwSetContextThread (NTDLL.@) + */ +NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context ) +{ + NTSTATUS ret; + BOOL self; + context_t server_context; + + context_to_server( &server_context, context ); + ret = set_thread_context( handle, &server_context, &self ); + if (self && ret == STATUS_SUCCESS) + { + ppc64_thread_data()->syscall_frame = NULL; + set_cpu_context( context ); + } + return ret; +} + + +/*********************************************************************** + * NtGetContextThread (NTDLL.@) + * ZwGetContextThread (NTDLL.@) + */ +NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context ) +{ + NTSTATUS ret; + struct syscall_frame *frame = ppc64_thread_data()->syscall_frame; + DWORD needed_flags = context->ContextFlags & ~CONTEXT_POWERPC64; + BOOL self = (handle == GetCurrentThread()); + + FIXME("semi stub\n"); + + if (!self) + { + context_t server_context; + unsigned int server_flags = get_server_context_flags( context->ContextFlags ); + + if ((ret = get_thread_context( handle, &server_context, server_flags, &self ))) return ret; + if ((ret = context_from_server( context, &server_context ))) return ret; + needed_flags &= ~context->ContextFlags; + } + + if (self) + { + if (needed_flags & CONTEXT_INTEGER) + { + context->Gpr0 = 0; + context->Gpr3 = 0; + context->Gpr4 = 0; + context->Gpr5 = 0; + context->Gpr6 = 0; + context->Gpr7 = 0; + context->Gpr8 = 0; + context->Gpr9 = 0; + context->Gpr10 = 0; + context->Gpr11 = 0; + context->Gpr12 = 0; + context->Gpr13 = 0; + context->Gpr14 = frame->r14; + context->Gpr15 = frame->r15; + context->Gpr16 = frame->r16; + context->Gpr17 = frame->r17; + context->Gpr18 = frame->r18; + context->Gpr19 = frame->r19; + context->Gpr20 = frame->r20; + context->Gpr21 = frame->r21; + context->Gpr22 = frame->r22; + context->Gpr23 = frame->r23; + context->Gpr24 = frame->r24; + context->Gpr25 = frame->r25; + context->Gpr26 = frame->r26; + context->Gpr27 = frame->r27; + context->Gpr28 = frame->r28; + context->Gpr29 = frame->r29; + context->Gpr30 = frame->r30; + context->Gpr31 = frame->r31; + context->ContextFlags |= CONTEXT_INTEGER; + } + if (needed_flags & CONTEXT_CONTROL) + { + context->Gpr1 = (DWORD64)&frame->thunk_r1; + context->Gpr2 = (DWORD64)&frame->thunk_r2; + context->Lr = frame->ret_addr; + context->Iar = frame->thunk_addr; + context->ContextFlags |= CONTEXT_CONTROL; + } + if (needed_flags & CONTEXT_FLOATING_POINT) FIXME( "floating point not supported\n" ); + if (needed_flags & CONTEXT_DEBUG_REGISTERS) FIXME( "debug registers not supported\n" ); + } + return STATUS_SUCCESS; +} + + +/*********************************************************************** + * setup_exception + * + * Modify the signal context to call the exception raise function. + */ +static void setup_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec ) +{ + struct + { + void *r1; + ULONG64 cr; + ULONG64 lr; + ULONG64 r2; + CONTEXT context; + EXCEPTION_RECORD rec; + } *stack; + + void *stack_ptr = (void *)(GPR_sig(1, sigcontext) & ~15); + CONTEXT context; + NTSTATUS status; + + rec->ExceptionAddress = (void *)IAR_sig(sigcontext); + save_context( &context, sigcontext ); + save_fpu( &context, sigcontext ); + if (rec->ExceptionCode == EXCEPTION_BREAKPOINT) context.Iar += 4; + + status = send_debug_event( rec, &context, TRUE ); + if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED) + { + restore_context( &context, sigcontext ); + restore_fpu( &context, sigcontext ); + return; + } + + stack = virtual_setup_exception( stack_ptr, sizeof(*stack), rec ); + stack->r1 = stack_ptr; + stack->cr = CR_sig(sigcontext); + stack->lr = LR_sig(sigcontext); + stack->r2 = GPR_sig(2, sigcontext); + stack->context = context; + stack->rec = *rec; + + /* now modify the sigcontext to return to the raise function */ + GPR_sig(1, sigcontext) = (ULONG_PTR)stack; + GPR_sig(3, sigcontext) = (ULONG_PTR)&stack->rec; /* first arg for KiUserExceptionDispatcher */ + GPR_sig(4, sigcontext) = (ULONG_PTR)&stack->context; /* second arg for KiUserExceptionDispatcher */ + GPR_sig(12, sigcontext) = (ULONG_PTR)pKiUserExceptionDispatcher; /* for ABIv2 */ + LR_sig(sigcontext) = IAR_sig(sigcontext); + IAR_sig(sigcontext) = (ULONG_PTR)pKiUserExceptionDispatcher; +} + +/*********************************************************************** + * call_user_apc_dispatcher + */ +__ASM_GLOBAL_FUNC( call_user_apc_dispatcher, + "mr 14, 3\n\t" /* context */ + "mr 15, 4\n\t" /* ctx */ + "mr 16, 5\n\t" /* arg1 */ + "mr 17, 6\n\t" /* arg2 */ + "mr 18, 7\n\t" /* func */ + "mr 19, 8\n\t" /* dispatcher */ + "lis 12, " __ASM_NAME("NtCurrentTeb") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("NtCurrentTeb") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("NtCurrentTeb") "@high\n\t" + "ori 12, 12, " __ASM_NAME("NtCurrentTeb") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "ld 20, 0x2f8(3)\n\t" /* ppc64_thread_data()->syscall_frame */ + "cmpdi cr7, 20, 0\n\t" + "beq cr7, 1f\n\t" + "ld 3, 272(14)\n\t" /* context.Gpr1 */ + "subi 3, 3, 920\n\t" /* sizeof(CONTEXT)=664 + offsetof(frame,thunk_r1)=256 */ + "li 9, 0\n\t" + "std 9, 0(20)\n\t" + "mr 1, 3\n\t" + "b 2f\n" + "1:\tld 3, 0(20)\n\t" + "subi 1, 3, 0x298\n\t" /* sizeof(CONTEXT)=664 */ + "lis 0, 0x80\n\t" /* context.ContextFlags = CONTEXT_FULL */ + "ori 0, 0, 7\n\t" + "std 0, 568(1)\n\t" + "li 3, -2\n\t" /* -2 == ~1 == GetCurrentThread() */ + "mr 4, 1\n\t" + "lis 12, " __ASM_NAME("NtGetContextThread") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("NtGetContextThread") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("NtGetContextThread") "@high\n\t" + "ori 12, 12, " __ASM_NAME("NtGetContextThread") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "li 0, 0xc0\n\t" + "std 0, 288(1)\n\t" /* context.Gpr3 = STATUS_USER_APC */ + "li 0, 0\n\t" + "std 0, 0(20)\n\t" + "mr 3, 1\n" + "2:\tld 0, 552(3)\n\t" /* context.Lr */ + "mtlr 0\n\t" + "mr 4, 15\n\t" /* ctx */ + "mr 5, 16\n\t" /* arg1 */ + "mr 6, 17\n\t" /* arg2 */ + "mr 7, 18\n\t" /* func */ + "mr 12, 19\n\t" + "mtctr 12\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + +/*********************************************************************** + * call_raise_user_exception_dispatcher + */ +__ASM_GLOBAL_FUNC( call_raise_user_exception_dispatcher, + "mr 5, 3\n\t" /* dispatcher */ + "lis 12, " __ASM_NAME("call_user_exception_dispatcher") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("call_user_exception_dispatcher") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("call_user_exception_dispatcher") "@high\n\t" + "ori 12, 12, " __ASM_NAME("call_user_exception_dispatcher") "@l\n\t" + "mtctr 12\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + + +/*********************************************************************** + * call_user_exception_dispatcher + */ +__ASM_GLOBAL_FUNC( call_user_exception_dispatcher, + "mr 14, 3\n\t" + "mr 15, 4\n\t" + "mr 16, 5\n\t" + "lis 12, " __ASM_NAME("NtCurrentTeb") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("NtCurrentTeb") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("NtCurrentTeb") "@high\n\t" + "ori 12, 12, " __ASM_NAME("NtCurrentTeb") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "ld 8, 0x2f8(3)\n\t" /* ppc64_thread_data()->syscall_frame */ + "li 5, 0\n\t" + "std 5, 0x2f8(3)\n\t" + "mr 3, 14\n\t" + "mr 4, 15\n\t" + "mr 5, 16\n\t" + "ld 14, 96(8)\n\t" + "ld 15, 104(8)\n\t" + "ld 16, 112(8)\n\t" + "ld 17, 120(8)\n\t" + "ld 18, 128(8)\n\t" + "ld 19, 136(8)\n\t" + "ld 20, 144(8)\n\t" + "ld 21, 152(8)\n\t" + "ld 22, 160(8)\n\t" + "ld 23, 168(8)\n\t" + "ld 24, 176(8)\n\t" + "ld 25, 184(8)\n\t" + "ld 26, 192(8)\n\t" + "ld 27, 200(8)\n\t" + "ld 28, 208(8)\n\t" + "ld 29, 216(8)\n\t" + "ld 20, 224(8)\n\t" + "ld 31, 232(8)\n\t" + "addi 1, 8, 240\n\t" + "mr 12, 5\n\t" + "mtctr 12\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + +/*********************************************************************** + * handle_syscall_fault + * + * Handle a page fault happening during a system call. + */ +static BOOL handle_syscall_fault( ucontext_t *context, EXCEPTION_RECORD *rec ) +{ + struct syscall_frame *frame = ppc64_thread_data()->syscall_frame; + __WINE_FRAME *wine_frame = (__WINE_FRAME *)NtCurrentTeb()->Tib.ExceptionList; + DWORD i; + + if (!frame) return FALSE; + + TRACE( "code=%x flags=%x addr=%p pc=%p tid=%04x\n", + rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, + (void *)IAR_sig(context), GetCurrentThreadId() ); + for (i = 0; i < rec->NumberParameters; i++) + TRACE( " info[%d]=%016lx\n", i, rec->ExceptionInformation[i] ); + + TRACE(" r0=%016lx r1=%016lx r2=%016lx r3=%016lx\n", + (DWORD64)GPR_sig(0, context), (DWORD64)GPR_sig(1, context), + (DWORD64)GPR_sig(2, context), (DWORD64)GPR_sig(3, context) ); + TRACE(" r4=%016lx r5=%016lx r6=%016lx r7=%016lx\n", + (DWORD64)GPR_sig(4, context), (DWORD64)GPR_sig(5, context), + (DWORD64)GPR_sig(6, context), (DWORD64)GPR_sig(7, context) ); + TRACE(" r8=%016lx r9=%016lx r10=%016lx r11=%016lx\n", + (DWORD64)GPR_sig(8, context), (DWORD64)GPR_sig(9, context), + (DWORD64)GPR_sig(10, context), (DWORD64)GPR_sig(11, context) ); + TRACE(" r12=%016lx r13=%016lx r14=%016lx r15=%016lx\n", + (DWORD64)GPR_sig(12, context), (DWORD64)GPR_sig(13, context), + (DWORD64)GPR_sig(14, context), (DWORD64)GPR_sig(15, context) ); + TRACE(" r16=%016lx r17=%016lx r18=%016lx r19=%016lx\n", + (DWORD64)GPR_sig(16, context), (DWORD64)GPR_sig(17, context), + (DWORD64)GPR_sig(18, context), (DWORD64)GPR_sig(19, context) ); + TRACE(" r20=%016lx r21=%016lx r22=%016lx r23=%016lx\n", + (DWORD64)GPR_sig(20, context), (DWORD64)GPR_sig(21, context), + (DWORD64)GPR_sig(22, context), (DWORD64)GPR_sig(23, context) ); + TRACE(" r24=%016lx r25=%016lx r26=%016lx r27=%016lx\n", + (DWORD64)GPR_sig(24, context), (DWORD64)GPR_sig(25, context), + (DWORD64)GPR_sig(26, context), (DWORD64)GPR_sig(27, context) ); + TRACE(" r28=%016lx r29=%016lx r30=%016lx r31=%016lx\n", + (DWORD64)GPR_sig(28, context), (DWORD64)GPR_sig(29, context), + (DWORD64)GPR_sig(30, context), (DWORD64)GPR_sig(31, context) ); + TRACE(" ctr=%016lx fpscr=%016lx lr=%016lx\n", + (DWORD64)CTR_sig(context), (DWORD64)FPSCR_sig(context), (DWORD64)LR_sig(context) ); + + if ((char *)wine_frame < (char *)frame) + { + TRACE( "returning to handler\n" ); + GPR_sig(3, context) = (ULONG_PTR)&wine_frame->jmp; + GPR_sig(4, context) = 1; + GPR_sig(12, context) = (ULONG_PTR)__wine_longjmp; /* for ABIv2 */ + IAR_sig(context) = (ULONG_PTR)__wine_longjmp; + } + else + { + TRACE( "returning to user mode ip=%p ret=%08x\n", (void *)frame->ret_addr, rec->ExceptionCode ); + GPR_sig(1, context) = (ULONG_PTR)&frame->thunk_r1; + GPR_sig(2, context) = frame->thunk_r2; + GPR_sig(3, context) = rec->ExceptionCode; + GPR_sig(14, context) = frame->r14; + GPR_sig(15, context) = frame->r15; + GPR_sig(16, context) = frame->r16; + GPR_sig(17, context) = frame->r17; + GPR_sig(18, context) = frame->r18; + GPR_sig(19, context) = frame->r19; + GPR_sig(20, context) = frame->r20; + GPR_sig(21, context) = frame->r21; + GPR_sig(22, context) = frame->r22; + GPR_sig(23, context) = frame->r23; + GPR_sig(24, context) = frame->r24; + GPR_sig(25, context) = frame->r25; + GPR_sig(26, context) = frame->r26; + GPR_sig(27, context) = frame->r27; + GPR_sig(28, context) = frame->r28; + GPR_sig(29, context) = frame->r29; + GPR_sig(30, context) = frame->r30; + GPR_sig(31, context) = frame->r31; + LR_sig(context) = frame->ret_addr; + IAR_sig(context) = frame->thunk_addr; + ppc64_thread_data()->syscall_frame = NULL; + } + return TRUE; +} + +/********************************************************************** + * segv_handler + * + * Handler for SIGSEGV. + */ +static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { 0 }; + ucontext_t *context = sigcontext; + + rec.NumberParameters = 2; + rec.ExceptionInformation[0] = (REG_sig(dsisr, context) & 0x02000000) != 0; + rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr; + rec.ExceptionCode = virtual_handle_fault( siginfo->si_addr, rec.ExceptionInformation[0], + (void *)GPR_sig(1, context) ); + if (!rec.ExceptionCode) return; + if (handle_syscall_fault( context, &rec )) return; + setup_exception( context, &rec ); +} + + +/********************************************************************** + * ill_handler + * + * Handler for SIGILL. + */ +static void ill_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { EXCEPTION_ILLEGAL_INSTRUCTION }; + + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * bus_handler + * + * Handler for SIGBUS. + */ +static void bus_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { EXCEPTION_DATATYPE_MISALIGNMENT }; + + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * trap_handler + * + * Handler for SIGTRAP. + */ +static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { 0 }; + + switch (siginfo->si_code) + { + case TRAP_TRACE: + rec.ExceptionCode = EXCEPTION_SINGLE_STEP; + break; + case TRAP_BRKPT: + default: + rec.ExceptionCode = EXCEPTION_BREAKPOINT; + rec.NumberParameters = 1; + break; + } + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * fpe_handler + * + * Handler for SIGFPE. + */ +static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { 0 }; + + switch (siginfo->si_code & 0xffff ) + { +#ifdef FPE_FLTSUB + case FPE_FLTSUB: + rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED; + break; +#endif +#ifdef FPE_INTDIV + case FPE_INTDIV: + rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO; + break; +#endif +#ifdef FPE_INTOVF + case FPE_INTOVF: + rec.ExceptionCode = EXCEPTION_INT_OVERFLOW; + break; +#endif +#ifdef FPE_FLTDIV + case FPE_FLTDIV: + rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO; + break; +#endif +#ifdef FPE_FLTOVF + case FPE_FLTOVF: + rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW; + break; +#endif +#ifdef FPE_FLTUND + case FPE_FLTUND: + rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW; + break; +#endif +#ifdef FPE_FLTRES + case FPE_FLTRES: + rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT; + break; +#endif +#ifdef FPE_FLTINV + case FPE_FLTINV: +#endif + default: + rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION; + break; + } + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * int_handler + * + * Handler for SIGINT. + */ +static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { CONTROL_C_EXIT }; + + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * abrt_handler + * + * Handler for SIGABRT. + */ +static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + EXCEPTION_RECORD rec = { EXCEPTION_WINE_ASSERTION, EH_NONCONTINUABLE }; + + setup_exception( sigcontext, &rec ); +} + + +/********************************************************************** + * quit_handler + * + * Handler for SIGQUIT. + */ +static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + abort_thread(0); +} + + +/********************************************************************** + * usr1_handler + * + * Handler for SIGUSR1, used to signal a thread that it got suspended. + */ +static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext ) +{ + CONTEXT context; + + save_context( &context, sigcontext ); + wait_suspend( &context ); + restore_context( &context, sigcontext ); + restore_fpu( &context, sigcontext ); +} + + +/********************************************************************** + * get_thread_ldt_entry + */ +NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len ) +{ + return STATUS_NOT_IMPLEMENTED; +} + + +/****************************************************************************** + * NtSetLdtEntries (NTDLL.@) + * ZwSetLdtEntries (NTDLL.@) + */ +NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 ) +{ + return STATUS_NOT_IMPLEMENTED; +} + + +/********************************************************************** + * signal_init_threading + */ +void signal_init_threading(void) +{ + pthread_key_create( &teb_key, NULL ); +} + + +/********************************************************************** + * signal_alloc_thread + */ +NTSTATUS signal_alloc_thread( TEB *teb ) +{ + return STATUS_SUCCESS; +} + + +/********************************************************************** + * signal_free_thread + */ +void signal_free_thread( TEB *teb ) +{ +} + + +/********************************************************************** + * signal_init_thread + */ +void signal_init_thread( TEB *teb ) +{ + pthread_setspecific( teb_key, teb ); +} + + +/********************************************************************** + * signal_init_process + */ +void signal_init_process(void) +{ + struct sigaction sig_act; + + sig_act.sa_mask = server_block_set; + sig_act.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; + + sig_act.sa_sigaction = int_handler; + if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = fpe_handler; + if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = abrt_handler; + if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = quit_handler; + if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = usr1_handler; + if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = trap_handler; + if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = segv_handler; + if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = ill_handler; + if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error; + sig_act.sa_sigaction = bus_handler; + if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error; + return; + + error: + perror("sigaction"); + exit(1); +} + +/*********************************************************************** + * init_thread_context + */ +static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, TEB *teb ) +{ + context->Gpr1 = (DWORD64)teb->Tib.StackBase - 32; /* add initial frame size */ + context->Gpr3 = (DWORD64)entry; + context->Gpr4 = (DWORD64)arg; + context->Gpr12 = (DWORD64)pRtlUserThreadStart; + context->Iar = (DWORD64)pRtlUserThreadStart; +} + +/*********************************************************************** + * get_initial_context + */ +PCONTEXT DECLSPEC_HIDDEN get_initial_context( LPTHREAD_START_ROUTINE entry, void *arg, + BOOL suspend, TEB *teb ) +{ + CONTEXT *ctx; + + if (suspend) + { + CONTEXT context = { CONTEXT_ALL }; + + init_thread_context( &context, entry, arg, teb ); + wait_suspend( &context ); + ctx = (CONTEXT *)((ULONG_PTR)context.Gpr1 & ~15) - 1; + *ctx = context; + } + else + { + ctx = (CONTEXT *)teb->Tib.StackBase - 1; + init_thread_context( ctx, entry, arg, teb ); + } + pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL ); + ctx->ContextFlags = CONTEXT_FULL; + return ctx; +} + + +/*********************************************************************** + * signal_start_thread + */ +/* extern void DECLSPEC_NORETURN signal_start_thread( PRTL_THREAD_START_ROUTINE entry, void *arg, +- BOOL suspend, void *relay, void *thunk, TEB *teb ) DECLSPEC_HIDDEN; ++ BOOL suspend, void *thunk, TEB *teb ) DECLSPEC_HIDDEN;*/ +__ASM_GLOBAL_FUNC( signal_start_thread, + "mflr 0\n\t" + "std 0, 16(1)\n\t" + /* store exit frame */ + "addi 9, 7, 0x200\n\t" + "addi 9, 9, 0x0f0\n\t" + "std 1, 0(9)\n\t" /* ppc64_thread_data()->exit_frame */ + /* switch to thread stack */ + "ld 9, 8(7)\n\t" /* teb->Tib.StackBase */ + "subi 1, 9, 0x1000\n\t" + /* attach dlls */ + "std 6, 32(1)\n\t" + "mr 6, 7\n\t" + "lis 12, " __ASM_NAME("get_initial_context") "@highest\n\t" + "ori 12, 12, " __ASM_NAME("get_initial_context") "@higher\n\t" + "rldicr 12, 12, 32, 31\n\t" + "oris 12, 12, " __ASM_NAME("get_initial_context") "@high\n\t" + "ori 12, 12, " __ASM_NAME("get_initial_context") "@l\n\t" + "mtctr 12\n\t" + "bctrl\n\t" + "ori 0, 0, 0\n\t" + "ld 12, 32(1)\n\t" + "mtctr 12\n\t" + "li 4, 0\n\t" + "mtlr 4\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + +extern void DECLSPEC_NORETURN call_thread_exit_func( int status, void (*func)(int), TEB *teb ); +__ASM_GLOBAL_FUNC( call_thread_exit_func, + "li 7, 0\n\t" + "addi 8, 5, 0x200\n\t" + "addi 8, 8, 0x0f0\n\t" + "ld 6, 0(8)\n\t" + "std 7, 0(8)\n\t" + "cmpdi cr7, 6, 0\n\t" + "beq cr7, 1f\n\t" + "mr 1, 6\n" + "1:\tmr 12, 4\n\t" + "mtctr 12\n\t" + "bctr\n\t" + "ori 0, 0, 0" ) + +/*********************************************************************** + * signal_exit_thread + */ +void signal_exit_thread( int status, void (*func)(int) ) +{ + call_thread_exit_func( status, func, NtCurrentTeb() ); +} + + +/********************************************************************** + * NtCurrentTeb (NTDLL.@) + */ +TEB * WINAPI NtCurrentTeb(void) +{ + return pthread_getspecific( teb_key ); +} + +#endif /* __aarch64__ */ diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index a889b2e020c..f208dd915cc 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -465,6 +465,13 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) info->Architecture = PROCESSOR_ARCHITECTURE_ARM64; }
+#elif defined(__powerpc64__) + +static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) +{ + FIXME("CPU Feature detection not implemented.\n"); +} + #endif /* End architecture specific feature detection for CPUs */
/****************************************************************** diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 1d6ba95d2a1..493f98670bd 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -34,6 +34,8 @@ static const enum cpu_type client_cpu = CPU_x86_64; static const enum cpu_type client_cpu = CPU_ARM; #elif defined(__aarch64__) static const enum cpu_type client_cpu = CPU_ARM64; +#elif defined(__powerpc64__) +static const enum cpu_type client_cpu = CPU_POWERPC64; #endif
struct debug_info diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index 0847c7e07ca..33d4621dc6b 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -32,7 +32,7 @@ struct _DISPATCHER_CONTEXT; struct unix_funcs { /* Nt* functions */ -#ifdef __aarch64__ +#if defined(__aarch64__) || defined(__powerpc64__) TEB * (WINAPI *NtCurrentTeb)(void); #endif
From: Timothy Pearson tpearson@raptorengineering.com
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/ntdll/unix/system.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index f208dd915cc..3e5398c0cd4 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -469,7 +469,47 @@ static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info )
static void get_cpuinfo( SYSTEM_CPU_INFORMATION *info ) { +#ifdef linux + char line[512]; + char *s, *value; + FILE *f = fopen("/proc/cpuinfo", "r"); + if (f) + { + while (fgets(line, sizeof(line), f) != NULL) + { + /* NOTE: the ':' is the only character we can rely on */ + if (!(value = strchr(line,':'))) + continue; + /* terminate the valuename */ + s = value - 1; + while ((s >= line) && isspace(*s)) s--; + *(s + 1) = '\0'; + /* and strip leading spaces from value */ + value += 1; + while (isspace(*value)) value++; + if ((s = strchr(value,'\n'))) + *s='\0'; + if (!strcasecmp(line, "cpu")) + { + if (isdigit(value[5])) + info->Level = atoi(value+5); + continue; + } + if (!strcasecmp(line, "revision")) + { + if (isdigit(value[0])) + info->Revision = (atof(value) * 100); + continue; + } + } + fclose(f); + } +#else FIXME("CPU Feature detection not implemented.\n"); +#endif + info->Level = max(info->Level, 8); /* Default to POWER8 if unable to detect CPU series */ + info->Architecture = PROCESSOR_ARCHITECTURE_PPC64; + }
#endif /* End architecture specific feature detection for CPUs */
Signed-off-by: André Hentschel nerv@dawncrow.de --- libs/wine/port.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/libs/wine/port.c b/libs/wine/port.c index 8e56ada52aa..407596e0e81 100644 --- a/libs/wine/port.c +++ b/libs/wine/port.c @@ -127,6 +127,11 @@ __ASM_GLOBAL_FUNC( wine_call_on_stack_obsolete, "ldr x19, [sp,#16]\n\t" /* restore register from stack */ "ldp x29, x30, [sp],#32\n\t" /* restore return address */ "ret") /* return */ +#else +int wine_call_on_stack_obsolete( int (*func)(void *), void *arg, void *stack ) +{ + return 0; +} #endif
/***********************************************************************
Signed-off-by: André Hentschel nerv@dawncrow.de --- dlls/ntdll/tests/exception.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c index 06d8246a566..fe64c34f1ba 100644 --- a/dlls/ntdll/tests/exception.c +++ b/dlls/ntdll/tests/exception.c @@ -5719,6 +5719,20 @@ static void test_debug_service(DWORD numexc) /* not supported */ }
+#else + +static void test_debug_service(DWORD numexc) +{ + /* not supported */ +} +static void test_debugger(DWORD cont_status) +{ + /* not supported */ +} +static void test_thread_context(void) +{ + /* not supported */ +} #endif /* __aarch64__ */
#if defined(__i386__) || defined(__x86_64__) @@ -6137,6 +6151,7 @@ static const DWORD breakpoint_code[] = { 0xd4200000, 0xd65f03c0 }; /* brk #0; r
static void test_breakpoint(DWORD numexc) { +#ifndef __powerpc64__ DWORD (CDECL *func)(void) = code_mem; void *vectored_handler;
@@ -6151,6 +6166,7 @@ static void test_breakpoint(DWORD numexc) breakpoint_exceptions, numexc);
pRtlRemoveVectoredExceptionHandler(vectored_handler); +#endif }
#if defined(__i386__) || defined(__x86_64__)
André Hentschel nerv@dawncrow.de writes:
Since quite some time I keep splitting/cleaning up/rebasing and fixing the 2 year old PowerPC64le patchset from 2019 (done by Timothy Pearson): [1]
The goal is to have a winelib base for Hangover [2] on PowerPC64 and there's also interest in having winelib for crosscompiling [3].
This rebase meanwhile matured, especially end of last year, and I hope it can get upstreamed now that wine-6.0 is out and the patch flood after it calmed down a bit.
I don't think we want to commit to maintaining and supporting this at this point, especially as we are moving more towards PE builds, which I don't expect to be supported on PowerPC anytime soon.