diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-01-16 04:50:59 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-01-16 04:50:59 +0000 |
commit | 5ef6ae4bdb04ed21b8efc70566d22fab821ec6b2 (patch) | |
tree | 15f431839d8211e34b54bd4294f48a25770a0170 /sysdeps | |
parent | 39b04aa39823faf1cc414e7f3eca4f43e01426e4 (diff) | |
download | glibc-5ef6ae4bdb04ed21b8efc70566d22fab821ec6b2.tar.gz glibc-5ef6ae4bdb04ed21b8efc70566d22fab821ec6b2.tar.xz glibc-5ef6ae4bdb04ed21b8efc70566d22fab821ec6b2.zip |
Update.
2004-01-14 Steven Munroe <sjmunroe@us.ibm.com> * include/libc-symbols.h [HAVE_ASM_GLOBAL_DOT_NAME] (_symbol_version): Use C_SYMBOL_DOT_NAME to create '.'ed symbols. (_default_symbol_version): Use C_SYMBOL_DOT_NAME to create '.'ed symbols. * sysdeps/powerpc/Makefile: Add rtld-global-offsets.sym to gen-as-const-headers. * sysdeps/powerpc/elf/rtld-global-offsets.sym: New file. * sysdeps/powerpc/sysdep.h: Define v# symbols for vector registers. Define PPC_FEATURE_* masks for Aux Vector AT_HWCAP. * sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_SWAPCONTEXT_SYSCALL): Define for PPC and 2.6.0 kernels. * sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h [!__WORDSIZE == 32]: Declare mcontext_t inline and include altivec state for 64-bit. * sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions: Add GLIBC_2.3.4 versions for setcontext, getcontext, and swapcontext. * sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions: Add GLIBC_2.3.4 versions for setcontext, getcontext, swapcontext, and makecontext. * sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S (__getcontext): Upgrade to save Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)](__novec_getcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S (__makecontext): Use parm save area instead of compiler_dw to hold context pointer. * sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S (__setcontext): Upgrade to restore Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)](__novec_setcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S (__swapcontext): Upgrade to swap Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4)](__novec_swapcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h (SIGCONTEXT_V_REGS_PTR, SIGCONTEXT_V_RESERVE): Defined. 2004-01-12 Steven Munroe <sjmunroe@us.ibm.com> * sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions: Add GLIBC_2.3.4 versions for setcontext, getcontext, swapcontext, and makecontext. * sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S (__getcontext): Upgrade to save Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)](__novec_getcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S (__makecontext): Upgrade to align for Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)](__novec_makecontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S (__setcontext): Upgrade to restore Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)](__novec_setcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S (__swapcontext): Upgrade to swap Altivec regs and version GLIBC_2_3_4. [SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4)] (__novec_swapcontext): Compatible with GLIBC_2.3.3 release. * sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h: (_UC_VSCR, _UC_VRSAVE): Define. (_FRAME_BACKCHAIN, _FRAME_LR_SAVE,_FRAME_PARM_SAVE1,_FRAME_PARM_SAVE2, _FRAME_PARM_SAVE3, _FRAME_PARM_SAVE4): Defined.
Diffstat (limited to 'sysdeps')
17 files changed, 2214 insertions, 32 deletions
diff --git a/sysdeps/powerpc/Makefile b/sysdeps/powerpc/Makefile index befa9c3bb7..f0b37bbdf9 100644 --- a/sysdeps/powerpc/Makefile +++ b/sysdeps/powerpc/Makefile @@ -17,3 +17,8 @@ sysdep_routines += dl-machine # extra shared linker files to link only into dl-allobjs.so sysdep-rtld-routines += dl-machine endif + +ifeq ($(subdir),csu) +# get offset to rtld_global._dl_hwcap +gen-as-const-headers += rtld-global-offsets.sym +endif diff --git a/sysdeps/powerpc/elf/rtld-global-offsets.sym b/sysdeps/powerpc/elf/rtld-global-offsets.sym new file mode 100644 index 0000000000..6bc8aaac55 --- /dev/null +++ b/sysdeps/powerpc/elf/rtld-global-offsets.sym @@ -0,0 +1,7 @@ +#define SHARED 1 + +#include <ldsodefs.h> + +#define rtdl_global_offsetof(mem) offsetof (struct rtld_global, mem) + +RTLD_GLOBAL_DL_HWCAP_OFFSET rtdl_global_offsetof (_dl_hwcap) diff --git a/sysdeps/powerpc/sysdep.h b/sysdeps/powerpc/sysdep.h index cd0485e070..214ac6a2ed 100644 --- a/sysdeps/powerpc/sysdep.h +++ b/sysdeps/powerpc/sysdep.h @@ -100,6 +100,42 @@ #define cr6 6 #define cr7 7 +/* Vector registers. */ +#define v0 0 +#define v1 1 +#define v2 2 +#define v3 3 +#define v4 4 +#define v5 5 +#define v6 6 +#define v7 7 +#define v8 8 +#define v9 9 +#define v10 10 +#define v11 11 +#define v12 12 +#define v13 13 +#define v14 14 +#define v15 15 +#define v16 16 +#define v17 17 +#define v18 18 +#define v19 19 +#define v20 20 +#define v21 21 +#define v22 22 +#define v23 23 +#define v24 24 +#define v25 25 +#define v26 26 +#define v27 27 +#define v28 28 +#define v29 29 +#define v30 30 +#define v31 31 + +#define VRSAVE 256 + #ifdef __ELF__ @@ -111,5 +147,18 @@ #endif /* __ELF__ */ +/* + * Powerpc Feature masks for the Aux Vector Hardware Capabilities (AT_HWCAP). + * This entry is copied to _dl_hwcap or rtld_global._dl_hwcap during startup. + * The following must match the kernels linux/asm/cputable.h. + */ +#define PPC_FEATURE_32 0x80000000 /* 32-bit mode. */ +#define PPC_FEATURE_64 0x40000000 /* 64-bit mode. */ +#define PPC_FEATURE_601_INSTR 0x20000000 /* 601 chip, Old POWER ISA. */ +#define PPC_FEATURE_HAS_ALTIVEC 0x10000000 /* SIMD/Vector Unit. */ +#define PPC_FEATURE_HAS_FPU 0x08000000 /* Floating Point Unit. */ +#define PPC_FEATURE_HAS_MMU 0x04000000 /* Memory Management Unit. */ +#define PPC_FEATURE_HAS_4xxMAC 0x02000000 /* 4xx Multiply Accumulator. */ +#define PPC_FEATURE_UNIFIED_CACHE 0x01000000 /* Unified I/D cache. */ #endif /* __ASSEMBLER__ */ diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index c2618ff8ed..43e95dfee4 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -379,3 +379,10 @@ #if __LINUX_KERNEL_VERSION >= 132609 # define __ASSUME_PROT_GROWSUPDOWN 1 #endif + +/* Starting with 2.6.0 PowerPC adds signal/swapcontext support for Vector + SIMD (AKA Altivec, VMX) instructions and register state. This changes + the overall size of the sigcontext and adds the swapcontext syscall. */ +#if __LINUX_KERNEL_VERSION >= (132608) && defined __powerpc__ +# define __ASSUME_SWAPCONTEXT_SYSCALL 1 +#endif diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions index d667eadbce..181d70150c 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions @@ -24,4 +24,7 @@ libc { posix_fadvise64; posix_fallocate64; setcontext; getcontext; swapcontext; makecontext; } + GLIBC_2.3.4 { + setcontext; getcontext; swapcontext; makecontext; + } } diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S index 3b1b3b9449..760e9b5534 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S @@ -1,5 +1,5 @@ /* Save current context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,7 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> #include <shlib-compat.h> #define __ASSEMBLY__ @@ -25,6 +26,231 @@ #include "ucontext_i.h" ENTRY(__getcontext) + stw r3,_FRAME_PARM_SAVE1(r1) + addi r3,r3,_UC_REG_SPACE+12 + clrrwi r3,r3,4 + stw r0,_UC_GREGS+(PT_R0*4)(r3) + mflr r0 + stw r1,_UC_GREGS+(PT_R1*4)(r3) + stwu r1,-16(r1) + stw r0,_UC_GREGS+(PT_LNK*4)(r3) + stw r0,_UC_GREGS+(PT_NIP*4)(r3) + stw r0,_FRAME_LR_SAVE+16(r1) + stw r2,_UC_GREGS+(PT_R2*4)(r3) + stw r4,_UC_GREGS+(PT_R4*4)(r3) + stw r5,_UC_GREGS+(PT_R5*4)(r3) + stw r6,_UC_GREGS+(PT_R6*4)(r3) + stw r7,_UC_GREGS+(PT_R7*4)(r3) + stw r8,_UC_GREGS+(PT_R8*4)(r3) + stw r9,_UC_GREGS+(PT_R9*4)(r3) + stw r10,_UC_GREGS+(PT_R10*4)(r3) + stw r11,_UC_GREGS+(PT_R11*4)(r3) + stw r12,_UC_GREGS+(PT_R12*4)(r3) + stw r13,_UC_GREGS+(PT_R13*4)(r3) + stw r14,_UC_GREGS+(PT_R14*4)(r3) + stw r15,_UC_GREGS+(PT_R15*4)(r3) + stw r16,_UC_GREGS+(PT_R16*4)(r3) + stw r17,_UC_GREGS+(PT_R17*4)(r3) + stw r18,_UC_GREGS+(PT_R18*4)(r3) + stw r19,_UC_GREGS+(PT_R19*4)(r3) + stw r20,_UC_GREGS+(PT_R20*4)(r3) + stw r21,_UC_GREGS+(PT_R21*4)(r3) + stw r22,_UC_GREGS+(PT_R22*4)(r3) + stw r23,_UC_GREGS+(PT_R23*4)(r3) + stw r24,_UC_GREGS+(PT_R24*4)(r3) + stw r25,_UC_GREGS+(PT_R25*4)(r3) + stw r26,_UC_GREGS+(PT_R26*4)(r3) + stw r27,_UC_GREGS+(PT_R27*4)(r3) + stw r28,_UC_GREGS+(PT_R28*4)(r3) + stw r29,_UC_GREGS+(PT_R29*4)(r3) + stw r30,_UC_GREGS+(PT_R30*4)(r3) + stw r31,_UC_GREGS+(PT_R31*4)(r3) + mfctr r0 + stw r0,_UC_GREGS+(PT_CTR*4)(r3) + mfxer r0 + stw r0,_UC_GREGS+(PT_XER*4)(r3) + mfcr r0 + stw r0,_UC_GREGS+(PT_CCR*4)(r3) + + /* Set the return value of getcontext to "success". R3 is the only + register whose value is not preserved in the saved context. */ + li r0,0 + stw r0,_UC_GREGS+(PT_R3*4)(r3) + + /* Zero fill fields that can't be set in user state. */ + stw r0,_UC_GREGS+(PT_MSR*4)(r3) + stw r0,_UC_GREGS+(PT_MQ*4)(r3) + + /* Save the floating-point registers */ + stfd fp0,_UC_FREGS+(0*8)(r3) + stfd fp1,_UC_FREGS+(1*8)(r3) + stfd fp2,_UC_FREGS+(2*8)(r3) + stfd fp3,_UC_FREGS+(3*8)(r3) + stfd fp4,_UC_FREGS+(4*8)(r3) + stfd fp5,_UC_FREGS+(5*8)(r3) + stfd fp6,_UC_FREGS+(6*8)(r3) + stfd fp7,_UC_FREGS+(7*8)(r3) + stfd fp8,_UC_FREGS+(8*8)(r3) + stfd fp9,_UC_FREGS+(9*8)(r3) + stfd fp10,_UC_FREGS+(10*8)(r3) + stfd fp11,_UC_FREGS+(11*8)(r3) + stfd fp12,_UC_FREGS+(12*8)(r3) + stfd fp13,_UC_FREGS+(13*8)(r3) + stfd fp14,_UC_FREGS+(14*8)(r3) + stfd fp15,_UC_FREGS+(15*8)(r3) + stfd fp16,_UC_FREGS+(16*8)(r3) + stfd fp17,_UC_FREGS+(17*8)(r3) + stfd fp18,_UC_FREGS+(18*8)(r3) + stfd fp19,_UC_FREGS+(19*8)(r3) + stfd fp20,_UC_FREGS+(20*8)(r3) + stfd fp21,_UC_FREGS+(21*8)(r3) + stfd fp22,_UC_FREGS+(22*8)(r3) + stfd fp23,_UC_FREGS+(23*8)(r3) + stfd fp24,_UC_FREGS+(24*8)(r3) + stfd fp25,_UC_FREGS+(25*8)(r3) + stfd fp26,_UC_FREGS+(26*8)(r3) + stfd fp27,_UC_FREGS+(27*8)(r3) + stfd fp28,_UC_FREGS+(28*8)(r3) + stfd fp29,_UC_FREGS+(29*8)(r3) + mffs fp0 + stfd fp30,_UC_FREGS+(30*8)(r3) + stfd fp31,_UC_FREGS+(31*8)(r3) + stfd fp0,_UC_FREGS+(32*8)(r3) + +#ifdef PIC + mflr r8 + bl _GLOBAL_OFFSET_TABLE_@local-4 + mflr r7 +#ifdef SHARED + lwz r7,_rtld_global@got(r7) + mtlr r8 + lwz r7,RTLD_GLOBAL_DL_HWCAP_OFFSET(r7) +#else + lwz r7,_dl_hwcap@got(r7) + mtlr r8 + lwz r7,0(r7) +#endif +#else + lis r7,_dl_hwcap@ha + lwz r7,_dl_hwcap@l(r7) +#endif + andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(no_vec) + + la r10,(_UC_VREGS)(r3) + la r9,(_UC_VREGS+16)(r3) + + stvx v0,0,r10 + stvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v2,0,r10 + stvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v4,0,r10 + stvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v6,0,r10 + stvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v8,0,r10 + stvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v12,0,r10 + stvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v14,0,r10 + stvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v16,0,r10 + stvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v18,0,r10 + stvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + stvx v20,0,r10 + stvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v22,0,r10 + stvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v24,0,r10 + stvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v26,0,r10 + stvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v28,0,r10 + stvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v30,0,r10 + stvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mfvscr v0 + mfspr r0,VRSAVE + stvx v0,0,r10 + sync + stw r0,0(r10) + +L(no_vec): +/* Restore ucontext (parm1) from stack. */ + lwz r12,_FRAME_PARM_SAVE1+16(r1) + li r4,0 + stw r3,_UC_REGS_PTR(r12) + addi r5,r12,_UC_SIGMASK + li r3,SIG_BLOCK + bl JUMPTARGET(sigprocmask) + + lwz r0,_FRAME_LR_SAVE+16(r1) + addi r1,r1,16 + mtlr r0 + blr +PSEUDO_END(__getcontext) + +versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_3_4) + +#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) + +ENTRY(__novec_getcontext) /* * Since we are not attempting to save the altivec registers, * there is no need to get the register storage space @@ -119,7 +345,7 @@ ENTRY(__getcontext) stfd fp30,_UC_FREGS+(30*8)(r3) stfd fp31,_UC_FREGS+(31*8)(r3) stfd fp0,_UC_FREGS+(32*8)(r3) - + addi r5,r3,_UC_SIGMASK - _UC_REG_SPACE li r4,0 li r3,SIG_BLOCK @@ -129,9 +355,11 @@ ENTRY(__getcontext) addi r1,r1,16 mtlr r0 blr -PSEUDO_END(__getcontext) +PSEUDO_END(__novec_getcontext) + +compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3_3) -versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_3_3) +#endif #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S index 9cb0b874f5..9f34357deb 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S @@ -1,5 +1,5 @@ /* Set up a context to call a function. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -26,7 +26,8 @@ ENTRY(__makecontext) /* Set up the first 7 args to the function in its registers */ - addi r11,r3,_UC_REG_SPACE + addi r11,r3,_UC_REG_SPACE+12 + clrrwi r11,r11,4 stw r11,_UC_REGS_PTR(r3) stw r6,_UC_GREGS+(PT_R3*4)(r11) stw r7,_UC_GREGS+(PT_R4*4)(r11) @@ -106,7 +107,94 @@ L(exitcode): END(__makecontext) -versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_3) +versioned_symbol (libc, __makecontext, makecontext, GLIBC_2_3_4) + +#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) + +ENTRY(__novec_makecontext) + /* Set up the first 7 args to the function in its registers */ + addi r11,r3,_UC_REG_SPACE + stw r11,_UC_REGS_PTR(r3) + stw r6,_UC_GREGS+(PT_R3*4)(r11) + stw r7,_UC_GREGS+(PT_R4*4)(r11) + stw r8,_UC_GREGS+(PT_R5*4)(r11) + stw r9,_UC_GREGS+(PT_R6*4)(r11) + stw r10,_UC_GREGS+(PT_R7*4)(r11) + lwz r8,8(r1) + lwz r9,12(r1) + stw r8,_UC_GREGS+(PT_R8*4)(r11) + stw r9,_UC_GREGS+(PT_R9*4)(r11) + + /* Set the NIP to the start of the function */ + stw r4,_UC_GREGS+(PT_NIP*4)(r11) + + /* Set the function's r31 to ucp->uc_link for the exitcode below. */ + lwz r7,_UC_LINK(r3) + stw r7,_UC_GREGS+(PT_R31*4)(r11) + + /* Set the function's LR to point to the exitcode below. */ +#ifdef PIC + mflr r0 + bl 1f +1: mflr r6 + addi r6,r6,L(novec_exitcode)-1b + mtlr r0 +#else + lis r6,L(novec_exitcode)@ha + addi r6,r6,L(novec_exitcode)@l +#endif + stw r6,_UC_GREGS+(PT_LNK*4)(r11) + + /* + * Set up the stack frame for the function. + * If we have more than 5 args to the function (8 args to makecontext), + * there will be some arguments on the stack which have to end up + * in registers. If there are more than 8 args to the function, + * we have to copy (argc - 8) args from our stack to the functions' + * stack (and allow space for them in the frame). + */ + lwz r4,_UC_STACK_SP(r3) + lwz r8,_UC_STACK_SIZE(r3) + add r4,r4,r8 + rlwinm r4,r4,0,0,27 /* round down to 16-byte boundary */ + addi r7,r4,-16 /* stack frame for fn's caller */ + cmpwi r5,8 + blt 2f /* less than 8 args is easy */ + lwz r10,16(r1) + stw r10,_UC_GREGS+(PT_R10*4)(r11) + beq 2f /* if exactly 8 args */ + subi r9,r5,3 + subi r5,r5,8 + rlwinm r9,r9,2,0,27 + subf r7,r9,r4 + mtctr r5 /* copy the 9th and following args */ + addi r6,r1,16 + addi r8,r7,4 +3: lwzu r10,4(r6) + stwu r10,4(r8) + bdnz 3b +2: stw r7,_UC_GREGS+(PT_R1*4)(r11) + li r6,0 + stw r6,0(r7) + + blr + +/* + * If the function returns, it comes here. We put ucp->uc_link in + * r31, which is a callee-saved register. We have to continue with + * the context that r31 points to, or exit if it is 0. + */ +L(novec_exitcode): + mr. r3,r31 + beq 4f + bl JUMPTARGET(__novec_setcontext) +4: bl HIDDEN_JUMPTARGET(exit) + b 4b + +END(__makecontext) + +compat_symbol (libc, __novec_makecontext, makecontext, GLIBC_2_3_3) +#endif #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S index deb946137d..cb2779731e 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S @@ -1,5 +1,5 @@ /* Jump to a new context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,7 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> #include <shlib-compat.h> #define __ASSEMBLY__ @@ -53,7 +54,122 @@ ENTRY(__setcontext) bl JUMPTARGET(sigprocmask) cmpwi r3,0 bne L(error_exit) + +#ifdef PIC + mflr r8 + bl _GLOBAL_OFFSET_TABLE_@local-4 + mflr r7 +#ifdef SHARED + lwz r7,_rtld_global@got(r7) + mtlr r8 + lwz r7,RTLD_GLOBAL_DL_HWCAP_OFFSET(r7) +#else + lwz r7,_dl_hwcap@got(r7) + mtlr r8 + lwz r7,0(r7) +#endif +#else + lis r7,_dl_hwcap@ha + lwz r7,_dl_hwcap@l(r7) +#endif + andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16) + la r10,(_UC_VREGS)(r31) + beq L(has_no_vec) + + lwz r0,(32*16)(r10) + li r9,(32*16) + cmpwi r0,0 + mtspr VRSAVE,r0 + beq L(has_no_vec) + + lvx v19,r9,r10 + la r9,(16)(r10) + + lvx v0,0,r10 + lvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mtvscr v19 + lvx v2,0,r10 + lvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v4,0,r10 + lvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v6,0,r10 + lvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v8,0,r10 + lvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v12,0,r10 + lvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v14,0,r10 + lvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v16,0,r10 + lvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v18,0,r10 + lvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + lvx v20,0,r10 + lvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v22,0,r10 + lvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v24,0,r10 + lvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + lvx v26,0,r10 + lvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v28,0,r10 + lvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v30,0,r10 + lvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + +L(has_no_vec): /* Restore the floating-point registers */ lfd fp31,_UC_FREGS+(32*8)(r31) lfd fp0,_UC_FREGS+(0*8)(r31) @@ -147,9 +263,138 @@ L(do_sigret): PSEUDO_END (__setcontext) -versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_3_3) +versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_3_4) + +#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) + +ENTRY(__novec_setcontext) + mflr r0 + stwu r1,-16(r1) + stw r0,20(r1) + stw r31,12(r1) + lwz r31,_UC_REGS_PTR(r3) + + /* + * If this ucontext refers to the point where we were interrupted + * by a signal, we have to use the rt_sigreturn system call to + * return to the context so we get both LR and CTR restored. + * + * Otherwise, the context we are restoring is either just after + * a procedure call (getcontext/swapcontext) or at the beginning + * of a procedure call (makecontext), so we don't need to restore + * r0, xer, ctr. We don't restore r2 since it will be used as + * the TLS pointer. + */ + lwz r0,_UC_GREGS+(PT_MSR*4)(r31) + cmpwi r0,0 + bne L(novec_do_sigret) + + /* Restore the signal mask */ + li r5,0 + addi r4,r3,_UC_SIGMASK + li r3,SIG_SETMASK + bl JUMPTARGET(sigprocmask) + cmpwi r3,0 + bne L(novec_error_exit) + + /* Restore the floating-point registers */ + lfd fp31,_UC_FREGS+(32*8)(r31) + lfd fp0,_UC_FREGS+(0*8)(r31) + mtfsf 0xff,fp31 + lfd fp1,_UC_FREGS+(1*8)(r31) + lfd fp2,_UC_FREGS+(2*8)(r31) + lfd fp3,_UC_FREGS+(3*8)(r31) + lfd fp4,_UC_FREGS+(4*8)(r31) + lfd fp5,_UC_FREGS+(5*8)(r31) + lfd fp6,_UC_FREGS+(6*8)(r31) + lfd fp7,_UC_FREGS+(7*8)(r31) + lfd fp8,_UC_FREGS+(8*8)(r31) + lfd fp9,_UC_FREGS+(9*8)(r31) + lfd fp10,_UC_FREGS+(10*8)(r31) + lfd fp11,_UC_FREGS+(11*8)(r31) + lfd fp12,_UC_FREGS+(12*8)(r31) + lfd fp13,_UC_FREGS+(13*8)(r31) + lfd fp14,_UC_FREGS+(14*8)(r31) + lfd fp15,_UC_FREGS+(15*8)(r31) + lfd fp16,_UC_FREGS+(16*8)(r31) + lfd fp17,_UC_FREGS+(17*8)(r31) + lfd fp18,_UC_FREGS+(18*8)(r31) + lfd fp19,_UC_FREGS+(19*8)(r31) + lfd fp20,_UC_FREGS+(20*8)(r31) + lfd fp21,_UC_FREGS+(21*8)(r31) + lfd fp22,_UC_FREGS+(22*8)(r31) + lfd fp23,_UC_FREGS+(23*8)(r31) + lfd fp24,_UC_FREGS+(24*8)(r31) + lfd fp25,_UC_FREGS+(25*8)(r31) + lfd fp26,_UC_FREGS+(26*8)(r31) + lfd fp27,_UC_FREGS+(27*8)(r31) + lfd fp28,_UC_FREGS+(28*8)(r31) + lfd fp29,_UC_FREGS+(29*8)(r31) + lfd fp30,_UC_FREGS+(30*8)(r31) + lfd fp31,_UC_FREGS+(31*8)(r31) + + /* Restore LR and CCR, and set CTR to the NIP value */ + lwz r3,_UC_GREGS+(PT_LNK*4)(r31) + lwz r4,_UC_GREGS+(PT_NIP*4)(r31) + lwz r5,_UC_GREGS+(PT_CCR*4)(r31) + mtlr r3 + mtctr r4 + mtcr r5 + + /* Restore the general registers */ + lwz r1,_UC_GREGS+(PT_R1*4)(r31) + lwz r3,_UC_GREGS+(PT_R3*4)(r31) + lwz r4,_UC_GREGS+(PT_R4*4)(r31) + lwz r5,_UC_GREGS+(PT_R5*4)(r31) + lwz r6,_UC_GREGS+(PT_R6*4)(r31) + lwz r7,_UC_GREGS+(PT_R7*4)(r31) + lwz r8,_UC_GREGS+(PT_R8*4)(r31) + lwz r9,_UC_GREGS+(PT_R9*4)(r31) + lwz r10,_UC_GREGS+(PT_R10*4)(r31) + lwz r11,_UC_GREGS+(PT_R11*4)(r31) + lwz r12,_UC_GREGS+(PT_R12*4)(r31) + lwz r13,_UC_GREGS+(PT_R13*4)(r31) + lwz r14,_UC_GREGS+(PT_R14*4)(r31) + lwz r15,_UC_GREGS+(PT_R15*4)(r31) + lwz r16,_UC_GREGS+(PT_R16*4)(r31) + lwz r17,_UC_GREGS+(PT_R17*4)(r31) + lwz r18,_UC_GREGS+(PT_R18*4)(r31) + lwz r19,_UC_GREGS+(PT_R19*4)(r31) + lwz r20,_UC_GREGS+(PT_R20*4)(r31) + lwz r21,_UC_GREGS+(PT_R21*4)(r31) + lwz r22,_UC_GREGS+(PT_R22*4)(r31) + lwz r23,_UC_GREGS+(PT_R23*4)(r31) + lwz r24,_UC_GREGS+(PT_R24*4)(r31) + lwz r25,_UC_GREGS+(PT_R25*4)(r31) + lwz r26,_UC_GREGS+(PT_R26*4)(r31) + lwz r27,_UC_GREGS+(PT_R27*4)(r31) + lwz r28,_UC_GREGS+(PT_R28*4)(r31) + lwz r29,_UC_GREGS+(PT_R29*4)(r31) + lwz r30,_UC_GREGS+(PT_R30*4)(r31) + lwz r31,_UC_GREGS+(PT_R31*4)(r31) + + bctr + +L(novec_error_exit): + lwz r31,12(r1) + lwz r0,20(r1) + addi r1,r1,16 + mtlr r0 + blr + +L(novec_do_sigret): + addi r1,r3,-0xd0 + li r0,SYS_ify(rt_sigreturn) + sc + /* NOTREACHED */ + +PSEUDO_END (__setcontext) + +compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3_3) + +#endif -#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_3) +#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3) #define _ERRNO_H 1 #include <bits/errno.h> @@ -159,6 +404,6 @@ ENTRY (__setcontext_stub) b JUMPTARGET(__syscall_error) END (__setcontext_stub) -compat_symbol (libc, __setcontext_stub, setcontext, GLIBC_2_0) +compat_symbol (libc, __setcontext_stub, setcontext, GLIBC_2_1) #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S index fac6802959..11f488a63b 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S @@ -1,5 +1,5 @@ /* Save current context and jump to a new context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,7 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> #include <shlib-compat.h> #define __ASSEMBLY__ @@ -26,6 +27,454 @@ ENTRY(__swapcontext) /* Save the current context */ + stw r3,_FRAME_PARM_SAVE1(r1) + addi r3,r3,_UC_REG_SPACE+12 + clrrwi r3,r3,4 + stw r0,_UC_GREGS+(PT_R0*4)(r3) + stw r1,_UC_GREGS+(PT_R1*4)(r3) + mflr r0 + stwu r1,-16(r1) + stw r0,20(r1) + stw r31,12(r1) + stw r31,_UC_GREGS+(PT_R31*4)(r3) + mr r31,r4 /* new context pointer */ + stw r0,_UC_GREGS+(PT_LNK*4)(r3) + stw r0,_UC_GREGS+(PT_NIP*4)(r3) + stw r2,_UC_GREGS+(PT_R2*4)(r3) + stw r4,_UC_GREGS+(PT_R4*4)(r3) + stw r5,_UC_GREGS+(PT_R5*4)(r3) + stw r6,_UC_GREGS+(PT_R6*4)(r3) + stw r7,_UC_GREGS+(PT_R7*4)(r3) + stw r8,_UC_GREGS+(PT_R8*4)(r3) + stw r9,_UC_GREGS+(PT_R9*4)(r3) + stw r10,_UC_GREGS+(PT_R10*4)(r3) + stw r11,_UC_GREGS+(PT_R11*4)(r3) + stw r12,_UC_GREGS+(PT_R12*4)(r3) + stw r13,_UC_GREGS+(PT_R13*4)(r3) + stw r14,_UC_GREGS+(PT_R14*4)(r3) + stw r15,_UC_GREGS+(PT_R15*4)(r3) + stw r16,_UC_GREGS+(PT_R16*4)(r3) + stw r17,_UC_GREGS+(PT_R17*4)(r3) + stw r18,_UC_GREGS+(PT_R18*4)(r3) + stw r19,_UC_GREGS+(PT_R19*4)(r3) + stw r20,_UC_GREGS+(PT_R20*4)(r3) + stw r21,_UC_GREGS+(PT_R21*4)(r3) + stw r22,_UC_GREGS+(PT_R22*4)(r3) + stw r23,_UC_GREGS+(PT_R23*4)(r3) + stw r24,_UC_GREGS+(PT_R24*4)(r3) + stw r25,_UC_GREGS+(PT_R25*4)(r3) + stw r26,_UC_GREGS+(PT_R26*4)(r3) + stw r27,_UC_GREGS+(PT_R27*4)(r3) + stw r28,_UC_GREGS+(PT_R28*4)(r3) + stw r29,_UC_GREGS+(PT_R29*4)(r3) + stw r30,_UC_GREGS+(PT_R30*4)(r3) + mfctr r0 + stw r0,_UC_GREGS+(PT_CTR*4)(r3) + mfxer r0 + stw r0,_UC_GREGS+(PT_XER*4)(r3) + mfcr r0 + stw r0,_UC_GREGS+(PT_CCR*4)(r3) + + /* Set the return value of swapcontext to "success". R3 is the only + register whose value is not preserved in the saved context. */ + li r0,0 + stw r0,_UC_GREGS+(PT_R3*4)(r3) + + /* Zero fill fields that can't be set in user state. */ + stw r0,_UC_GREGS+(PT_MSR*4)(r3) + stw r0,_UC_GREGS+(PT_MQ*4)(r3) + + /* Save the floating-point registers */ + stfd fp0,_UC_FREGS+(0*8)(r3) + stfd fp1,_UC_FREGS+(1*8)(r3) + stfd fp2,_UC_FREGS+(2*8)(r3) + stfd fp3,_UC_FREGS+(3*8)(r3) + stfd fp4,_UC_FREGS+(4*8)(r3) + stfd fp5,_UC_FREGS+(5*8)(r3) + stfd fp6,_UC_FREGS+(6*8)(r3) + stfd fp7,_UC_FREGS+(7*8)(r3) + stfd fp8,_UC_FREGS+(8*8)(r3) + stfd fp9,_UC_FREGS+(9*8)(r3) + stfd fp10,_UC_FREGS+(10*8)(r3) + stfd fp11,_UC_FREGS+(11*8)(r3) + stfd fp12,_UC_FREGS+(12*8)(r3) + stfd fp13,_UC_FREGS+(13*8)(r3) + stfd fp14,_UC_FREGS+(14*8)(r3) + stfd fp15,_UC_FREGS+(15*8)(r3) + stfd fp16,_UC_FREGS+(16*8)(r3) + stfd fp17,_UC_FREGS+(17*8)(r3) + stfd fp18,_UC_FREGS+(18*8)(r3) + stfd fp19,_UC_FREGS+(19*8)(r3) + stfd fp20,_UC_FREGS+(20*8)(r3) + stfd fp21,_UC_FREGS+(21*8)(r3) + stfd fp22,_UC_FREGS+(22*8)(r3) + stfd fp23,_UC_FREGS+(23*8)(r3) + stfd fp24,_UC_FREGS+(24*8)(r3) + stfd fp25,_UC_FREGS+(25*8)(r3) + stfd fp26,_UC_FREGS+(26*8)(r3) + stfd fp27,_UC_FREGS+(27*8)(r3) + stfd fp28,_UC_FREGS+(28*8)(r3) + stfd fp29,_UC_FREGS+(29*8)(r3) + mffs fp0 + stfd fp30,_UC_FREGS+(30*8)(r3) + stfd fp31,_UC_FREGS+(31*8)(r3) + stfd fp0,_UC_FREGS+(32*8)(r3) +#ifdef PIC + mflr r8 + bl _GLOBAL_OFFSET_TABLE_@local-4 + mflr r7 +#ifdef SHARED + lwz r7,_rtld_global@got(r7) + mtlr r8 + lwz r7,RTLD_GLOBAL_DL_HWCAP_OFFSET(r7) +#else + lwz r7,_dl_hwcap@got(r7) + mtlr r8 + lwz r7,0(r7) +#endif +#else + lis r7,_dl_hwcap@ha + lwz r7,_dl_hwcap@l(r7) +#endif + andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(no_vec) + + la r10,(_UC_VREGS)(r3) + la r9,(_UC_VREGS+16)(r3) + + stvx v0,0,r10 + stvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v2,0,r10 + stvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v4,0,r10 + stvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v6,0,r10 + stvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v8,0,r10 + stvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v12,0,r10 + stvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v14,0,r10 + stvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v16,0,r10 + stvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v18,0,r10 + stvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + stvx v20,0,r10 + stvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v22,0,r10 + stvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v24,0,r10 + stvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v26,0,r10 + stvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v28,0,r10 + stvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v30,0,r10 + stvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mfvscr v0 + mfspr r0,VRSAVE + stvx v0,0,r10 + sync + stw r0,0(r10) + +L(no_vec): +/* Restore ucontext (parm1) from stack. */ + lwz r12,_FRAME_PARM_SAVE1+16(r1) + li r4,0 + stw r3,_UC_REGS_PTR(r12) + addi r5,r12,_UC_SIGMASK + li r3,SIG_SETMASK + bl JUMPTARGET(sigprocmask) + cmpwi r3,0 + bne L(error_exit) + + /* + * If the new ucontext refers to the point where we were interrupted + * by a signal, we have to use the rt_sigreturn system call to + * return to the context so we get both LR and CTR restored. + * + * Otherwise, the context we are restoring is either just after + * a procedure call (getcontext/swapcontext) or at the beginning + * of a procedure call (makecontext), so we don't need to restore + * r0, xer, ctr. We don't restore r2 since it will be used as + * the TLS pointer. + */ + mr r4,r31 + lwz r31,_UC_REGS_PTR(r31) + lwz r0,_UC_GREGS+(PT_MSR*4)(r31) + cmpwi r0,0 + bne L(do_sigret) + +#ifdef PIC + mflr r8 + bl _GLOBAL_OFFSET_TABLE_@local-4 + mflr r7 +#ifdef SHARED + lwz r7,_rtld_global@got(r7) + mtlr r8 + lwz r7,RTLD_GLOBAL_DL_HWCAP_OFFSET(r7) +#else + lwz r7,_dl_hwcap@got(r7) + mtlr r8 + lwz r7,0(r7) +#endif +#else + lis r7,_dl_hwcap@ha + lwz r7,_dl_hwcap@l(r7) +#endif + andis. r7,r7,(PPC_FEATURE_HAS_ALTIVEC >> 16) + la r10,(_UC_VREGS)(r31) + beq L(has_no_vec) + + lwz r0,(32*16)(r10) + li r9,(32*16) + cmpwi r0,0 + mtspr VRSAVE,r0 + beq L(has_no_vec) + + lvx v19,r9,r10 + la r9,(16)(r10) + + lvx v0,0,r10 + lvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mtvscr v19 + lvx v2,0,r10 + lvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v4,0,r10 + lvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v6,0,r10 + lvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v8,0,r10 + lvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v12,0,r10 + lvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v14,0,r10 + lvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v16,0,r10 + lvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v18,0,r10 + lvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + lvx v20,0,r10 + lvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v22,0,r10 + lvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v24,0,r10 + lvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v26,0,r10 + lvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v28,0,r10 + lvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v30,0,r10 + lvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + +L(has_no_vec): + /* Restore the floating-point registers */ + lfd fp31,_UC_FREGS+(32*8)(r31) + lfd fp0,_UC_FREGS+(0*8)(r31) + mtfsf 0xff,fp31 + lfd fp1,_UC_FREGS+(1*8)(r31) + lfd fp2,_UC_FREGS+(2*8)(r31) + lfd fp3,_UC_FREGS+(3*8)(r31) + lfd fp4,_UC_FREGS+(4*8)(r31) + lfd fp5,_UC_FREGS+(5*8)(r31) + lfd fp6,_UC_FREGS+(6*8)(r31) + lfd fp7,_UC_FREGS+(7*8)(r31) + lfd fp8,_UC_FREGS+(8*8)(r31) + lfd fp9,_UC_FREGS+(9*8)(r31) + lfd fp10,_UC_FREGS+(10*8)(r31) + lfd fp11,_UC_FREGS+(11*8)(r31) + lfd fp12,_UC_FREGS+(12*8)(r31) + lfd fp13,_UC_FREGS+(13*8)(r31) + lfd fp14,_UC_FREGS+(14*8)(r31) + lfd fp15,_UC_FREGS+(15*8)(r31) + lfd fp16,_UC_FREGS+(16*8)(r31) + lfd fp17,_UC_FREGS+(17*8)(r31) + lfd fp18,_UC_FREGS+(18*8)(r31) + lfd fp19,_UC_FREGS+(19*8)(r31) + lfd fp20,_UC_FREGS+(20*8)(r31) + lfd fp21,_UC_FREGS+(21*8)(r31) + lfd fp22,_UC_FREGS+(22*8)(r31) + lfd fp23,_UC_FREGS+(23*8)(r31) + lfd fp24,_UC_FREGS+(24*8)(r31) + lfd fp25,_UC_FREGS+(25*8)(r31) + lfd fp26,_UC_FREGS+(26*8)(r31) + lfd fp27,_UC_FREGS+(27*8)(r31) + lfd fp28,_UC_FREGS+(28*8)(r31) + lfd fp29,_UC_FREGS+(29*8)(r31) + lfd fp30,_UC_FREGS+(30*8)(r31) + lfd fp31,_UC_FREGS+(31*8)(r31) + + /* Restore LR and CCR, and set CTR to the NIP value */ + lwz r3,_UC_GREGS+(PT_LNK*4)(r31) + lwz r4,_UC_GREGS+(PT_NIP*4)(r31) + lwz r5,_UC_GREGS+(PT_CCR*4)(r31) + mtlr r3 + mtctr r4 + mtcr r5 + + /* Restore the general registers */ + lwz r1,_UC_GREGS+(PT_R1*4)(r31) + lwz r3,_UC_GREGS+(PT_R3*4)(r31) + lwz r4,_UC_GREGS+(PT_R4*4)(r31) + lwz r5,_UC_GREGS+(PT_R5*4)(r31) + lwz r6,_UC_GREGS+(PT_R6*4)(r31) + lwz r7,_UC_GREGS+(PT_R7*4)(r31) + lwz r8,_UC_GREGS+(PT_R8*4)(r31) + lwz r9,_UC_GREGS+(PT_R9*4)(r31) + lwz r10,_UC_GREGS+(PT_R10*4)(r31) + lwz r11,_UC_GREGS+(PT_R11*4)(r31) + lwz r12,_UC_GREGS+(PT_R12*4)(r31) + lwz r13,_UC_GREGS+(PT_R13*4)(r31) + lwz r14,_UC_GREGS+(PT_R14*4)(r31) + lwz r15,_UC_GREGS+(PT_R15*4)(r31) + lwz r16,_UC_GREGS+(PT_R16*4)(r31) + lwz r17,_UC_GREGS+(PT_R17*4)(r31) + lwz r18,_UC_GREGS+(PT_R18*4)(r31) + lwz r19,_UC_GREGS+(PT_R19*4)(r31) + lwz r20,_UC_GREGS+(PT_R20*4)(r31) + lwz r21,_UC_GREGS+(PT_R21*4)(r31) + lwz r22,_UC_GREGS+(PT_R22*4)(r31) + lwz r23,_UC_GREGS+(PT_R23*4)(r31) + lwz r24,_UC_GREGS+(PT_R24*4)(r31) + lwz r25,_UC_GREGS+(PT_R25*4)(r31) + lwz r26,_UC_GREGS+(PT_R26*4)(r31) + lwz r27,_UC_GREGS+(PT_R27*4)(r31) + lwz r28,_UC_GREGS+(PT_R28*4)(r31) + lwz r29,_UC_GREGS+(PT_R29*4)(r31) + lwz r30,_UC_GREGS+(PT_R30*4)(r31) + lwz r31,_UC_GREGS+(PT_R31*4)(r31) + + bctr + +L(error_exit): + lwz r31,12(r1) + lwz r0,20(r1) + addi r1,r1,16 + mtlr r0 + blr + +L(do_sigret): + addi r1,r4,-0xd0 + li r0,SYS_ify(rt_sigreturn) + sc + /* NOTREACHED */ + +PSEUDO_END(__swapcontext) + +versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_3_4) + +#if SHLIB_COMPAT (libc, GLIBC_2_3_3, GLIBC_2_3_4) + +ENTRY(__novec_swapcontext) + /* Save the current context */ addi r3,r3,_UC_REG_SPACE stw r3,_UC_REGS_PTR - _UC_REG_SPACE(r3) stw r0,_UC_GREGS+(PT_R0*4)(r3) @@ -220,22 +669,24 @@ ENTRY(__swapcontext) bctr -L(error_exit): +L(novec_error_exit): lwz r31,12(r1) lwz r0,20(r1) addi r1,r1,16 mtlr r0 blr -L(do_sigret): +L(novec_do_sigret): addi r1,r4,-0xd0 li r0,SYS_ify(rt_sigreturn) sc /* NOTREACHED */ -PSEUDO_END(__swapcontext) +PSEUDO_END(__novec_swapcontext) + +compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3_3) -versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_3_3) +#endif #if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_3_3) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h index 1ae082a3ef..e47b24a09e 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h @@ -21,6 +21,13 @@ #define SIG_BLOCK 0 #define SIG_SETMASK 2 +#define _FRAME_BACKCHAIN 0 +#define _FRAME_LR_SAVE 4 +#define _FRAME_PARM_SAVE1 8 +#define _FRAME_PARM_SAVE2 12 +#define _FRAME_PARM_SAVE3 16 +#define _FRAME_PARM_SAVE4 20 + #define _UC_LINK 4 #define _UC_STACK_SP 8 #define _UC_STACK_SIZE 16 @@ -32,3 +39,5 @@ #define _UC_GREGS 0 #define _UC_FREGS 192 #define _UC_VREGS 464 +#define _UC_VSCR 976 +#define _UC_VRSAVE 980 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions b/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions index c3f9daad4c..8334741aec 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions @@ -14,4 +14,9 @@ libc { # s* scandir64; } + GLIBC_2.3.4 { + getcontext; + setcontext; + swapcontext; + } } diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S index 0ebf2d8727..279a36d68d 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S @@ -1,5 +1,5 @@ /* Save current context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,8 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> +#include <shlib-compat.h> #include "kernel-features.h" #define __ASSEMBLY__ @@ -25,7 +27,9 @@ #include <asm/errno.h> #include "ucontext_i.h" -ENTRY(__getcontext) + +#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4) +ENTRY(__novec_getcontext) #ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3) std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3) @@ -146,6 +150,256 @@ ENTRY(__getcontext) addi r1,r1,128 mtlr r0 blr +PSEUDO_END(__novec_getcontext) + +compat_symbol (libc, __novec_getcontext, getcontext, GLIBC_2_3) + +#endif + + .section ".toc","aw" +.LC__dl_hwcap: +#ifdef SHARED + .tc _rtld_global[TC],_rtld_global +#else + .tc _dl_hwcap[TC],_dl_hwcap +#endif + .section ".text" + +ENTRY(__getcontext) +#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL + std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3) + std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3) + mflr r0 + std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3) + std r0,FRAME_LR_SAVE(r1) + std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3) + stdu r1,-128(r1) + std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3) + std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3) + std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3) + std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3) + std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3) + std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3) + std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3) + std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3) + std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3) + std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3) + std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3) + std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3) + std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3) + std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3) + std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3) + std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3) + std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3) + std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3) + std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3) + std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3) + std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3) + std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3) + std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3) + std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3) + std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3) + std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3) + std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3) + std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3) + mfctr r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3) + mfxer r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3) + mfcr r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3) + + /* Set the return value of swapcontext to "success". R3 is the only + register whose value is not preserved in the saved context. */ + li r0,0 + std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3) + + /* Zero fill fields that can't be set in user state or are unused. */ + std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3) + + /* Set the PT_REGS pointer to the address of sigcontext's gp_regs + field. Struct pt_regs and elf_gregset_t are the same thing. + We kept the regs field for backwards compatibility with + libraries built before we extended sigcontext. */ + addi r0,r3,SIGCONTEXT_GP_REGS + std r0,SIGCONTEXT_PT_REGS(r3) + + stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3) + stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3) + stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3) + stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3) + stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3) + stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3) + stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3) + stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3) + stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3) + stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3) + stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3) + stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3) + stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3) + stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3) + stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3) + stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3) + stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3) + stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3) + stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3) + stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3) + stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3) + stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3) + stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3) + stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3) + stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3) + stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3) + stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3) + stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3) + stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3) + stfd fp29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3) + mffs fp0 + stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3) + stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3) + stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3) + + ld r5,.LC__dl_hwcap@toc(r2) + li r10,0 +#ifdef SHARED +/* Load _rtld-global._dl_hwcap. */ + ld r5,RTLD_GLOBAL_DL_HWCAP_OFFSET(r5) +#else + ld r5,0(r5) /* Load extern _dl_hwcap. */ +#endif + andis. r5,r5,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(has_no_vec) + + la r10,(SIGCONTEXT_V_RESERVE+8)(r3) + la r9,(SIGCONTEXT_V_RESERVE+24)(r3) + clrrdi r10,r10,4 + clrrdi r9,r9,4 + + stvx v0,0,r10 + stvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v2,0,r10 + stvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v4,0,r10 + stvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v6,0,r10 + stvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v8,0,r10 + stvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v12,0,r10 + stvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v14,0,r10 + stvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v16,0,r10 + stvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v18,0,r10 + stvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + stvx v20,0,r10 + stvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v22,0,r10 + stvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v24,0,r10 + stvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v26,0,r10 + stvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v28,0,r10 + stvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v30,0,r10 + stvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mfvscr v0 + mfspr r0,VRSAVE + stvx v0,0,r10 + stw r0,0(9) + +L(has_no_vec): +/* + Store either a NULL or a quadword aligned pointer to the Vector register + array into *v_regs. +*/ + std r10,(SIGCONTEXT_V_REGS_PTR)(r3) + + addi r5,r3,UCONTEXT_SIGMASK + li r4,0 + li r3,SIG_BLOCK + bl JUMPTARGET(sigprocmask) + nop +#else + /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */ + mflr r0 + std r0,FRAME_LR_SAVE(r1) + stdu r1,-128(r1) + li r3,ENOSYS + bl JUMPTARGET(__syscall_error) + nop + li r3,-1 +#endif + + ld r0,128+FRAME_LR_SAVE(r1) + addi r1,r1,128 + mtlr r0 + blr PSEUDO_END(__getcontext) -weak_alias(__getcontext, getcontext) +versioned_symbol (libc, __getcontext, getcontext, GLIBC_2_3_4) + diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S index 8487a3f522..bad67193d8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S @@ -1,5 +1,5 @@ /* Create new context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -54,8 +54,8 @@ ENTRY(__makecontext) add r7,r7,r0 clrrdi r7,r7,4 li r0,0 - stdu r0,-48(r7) - std r3,24(r7) + stdu r0,-64(r7) + std r3,FRAME_PARM1_SAVE(r7) /* Store context in dummy parm1. */ mflr r0 std r2,FRAME_TOC_SAVE(r7) /* Store the TOC pointer for later. */ std r0,FRAME_LR_SAVE(r7) @@ -135,7 +135,7 @@ L(noparms): L(exitcode): /* Recover the ucontext and TOC from the dummy frame. */ ld r1,FRAME_BACKCHAIN(r1) /* Unstack the parameter save area frame. */ - ld r3,FRAME_COMPILER_DW(r1) + ld r3,FRAME_PARM1_SAVE(r1) ld r2,FRAME_TOC_SAVE(r1) ld r3,UCONTEXT_LINK(r3) /* Load the resume context. */ cmpdi r3,0 diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S index 3e25a8e184..490eb27578 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S @@ -1,5 +1,5 @@ /* Switch to context. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,8 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> +#include <shlib-compat.h> #include "kernel-features.h" #define __ASSEMBLY__ @@ -25,6 +27,171 @@ #include "ucontext_i.h" #include <asm/errno.h> +#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4) +ENTRY(__novec_setcontext) +#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL + mflr r0 + std r31,-8(1) + std r0,FRAME_LR_SAVE(r1) + stdu r1,-128(r1) + mr r31,r3 + +/* + * If this ucontext refers to the point where we were interrupted + * by a signal, we have to use the rt_sigreturn system call to + * return to the context so we get both LR and CTR restored. + * + * Otherwise, the context we are restoring is either just after + * a procedure call (getcontext/swapcontext) or at the beginning + * of a procedure call (makecontext), so we don't need to restore + * msr and ctr. We don't restore r13 since it will be used as + * the TLS pointer. */ + lwz r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31) + cmpdi r0,0 + bne L(nv_do_sigret) + + li r5,0 + addi r4,r3,UCONTEXT_SIGMASK + li r3,SIG_SETMASK + bl JUMPTARGET(sigprocmask) + nop + cmpdi r3,0 + bne L(nv_error_exit) + + lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31) + lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31) + lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31) + mtfsf 0xff,fp0 + lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31) + lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31) + lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31) + lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31) + lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31) + lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31) + lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31) + lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31) + lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31) + lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31) + lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31) + lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31) + lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31) + lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31) + lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31) + lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31) + lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31) + lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31) + lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31) + lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31) + lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31) + lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31) + lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31) + lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31) + lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31) + lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31) + lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31) + lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31) + lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31) + lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31) + + ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31) + ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31) + mtlr r0 + ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31) + ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31) + ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31) + mtxer r0 + ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31) + ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31) + ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31) + mfcr r0 + ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31) + ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31) + ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31) + ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31) + ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31) + ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31) + ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31) + /* Don't reload the thread ID or TLS pointer (r13). */ + ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31) + ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31) + ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31) + ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31) + ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31) + ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31) + ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31) + ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31) + ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31) + ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31) + ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31) + ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31) + ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31) + ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31) + ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31) + ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31) + ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31) + + /* Now we branch to the "Next Instruction Pointer" from the saved + context. With the powerpc64 instruction set there is no good way to + do this (from user state) without clobbering either the LR or CTR. + The makecontext and swapcontext functions depend on the callers + LR being preserved so we use the CTR. */ + ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31) + mtctr r0 + ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31) + ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31) + bctr + +L(nv_error_exit): + ld r0,128+FRAME_LR_SAVE(r1) + addi r1,r1,128 + mtlr r0 + ld r31,-8(r1) + blr + + /* At this point we assume that the ucontext was created by a + rt_signal and we should use rt_sigreturn to restore the original + state. As of the 2.4.21 kernel the ucontext is the first thing + (offset 0) in the rt_signal frame and rt_sigreturn expects the + ucontext address in R1. Normally the rt-signal trampoline handles + this by popping dummy frame before the rt_signal syscall. In our + case the stack may not be in its original (signal handler return with + R1 pointing at the dummy frame) state. We do have the ucontext + address in R3, so simply copy R3 to R1 before the syscall. */ +L(nv_do_sigret): + mr r1,r3, + li r0,SYS_ify(rt_sigreturn) + sc + /* No return. */ +#else + /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */ + mflr r0 + std r0,FRAME_LR_SAVE(r1) + stdu r1,-128(r1) + li r3,ENOSYS + bl JUMPTARGET(__syscall_error) + nop + li r3,-1 + ld r0,128+FRAME_LR_SAVE(r1) + addi r1,r1,128 + mtlr r0 + blr +#endif + +PSEUDO_END(__novec_setcontext) + +compat_symbol (libc, __novec_setcontext, setcontext, GLIBC_2_3) + +#endif + + .section ".toc","aw" +.LC__dl_hwcap: +#ifdef SHARED + .tc _rtld_global[TC],_rtld_global +#else + .tc _dl_hwcap[TC],_dl_hwcap +#endif + .section ".text" + ENTRY(__setcontext) #ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL mflr r0 @@ -54,7 +221,117 @@ ENTRY(__setcontext) nop cmpdi r3,0 bne L(error_exit) - + + ld r5,.LC__dl_hwcap@toc(r2) + ld r10,(SIGCONTEXT_V_REGS_PTR)(r31) +#ifdef SHARED +/* Load _rtld-global._dl_hwcap. */ + ld r5,RTLD_GLOBAL_DL_HWCAP_OFFSET(r5) +#else + ld r5,0(r5) /* Load extern _dl_hwcap. */ +#endif + andis. r5,r5,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(has_no_vec) + + cmpdi r10,0 + beq L(has_no_vec) + lwz r0,(33*16)(r10) + + li r9,(16*32) + mtspr VRSAVE,r0 + cmpwi r0,0 + beq L(has_no_vec) + + lvx v19,r9,r10 + la r9,(16)(r10) + + lvx v0,0,r10 + lvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mtvscr v19 + lvx v2,0,r10 + lvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v4,0,r10 + lvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v6,0,r10 + lvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v8,0,r10 + lvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v12,0,r10 + lvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v14,0,r10 + lvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v16,0,r10 + lvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v18,0,r10 + lvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + lvx v20,0,r10 + lvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v22,0,r10 + lvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v24,0,r10 + lvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v26,0,r10 + lvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v28,0,r10 + lvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v30,0,r10 + lvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + +L(has_no_vec): lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31) lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31) lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31) @@ -176,4 +453,4 @@ L(do_sigret): PSEUDO_END(__setcontext) -weak_alias(__setcontext, setcontext) +versioned_symbol (libc, __setcontext, setcontext, GLIBC_2_3_4) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S index 653811bda2..ab6a6254f9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S @@ -1,5 +1,5 @@ /* Save current context and install the given one. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -18,6 +18,8 @@ 02111-1307 USA. */ #include <sysdep.h> +#include <rtld-global-offsets.h> +#include <shlib-compat.h> #include "kernel-features.h" #define __ASSEMBLY__ @@ -25,6 +27,266 @@ #include "ucontext_i.h" #include <asm/errno.h> +#if SHLIB_COMPAT (libc, GLIBC_2_3, GLIBC_2_3_4) +ENTRY(__novec_swapcontext) +#ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL + std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3) + std r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3) + mflr r0 + std r31,-8(1) + std r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3) + std r0,FRAME_LR_SAVE(r1) + std r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3) + stdu r1,-128(r1) + std r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r3) + std r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r3) + std r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r3) + std r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r3) + std r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r3) + std r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r3) + std r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r3) + std r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3) + std r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r3) + std r13,(SIGCONTEXT_GP_REGS+(PT_R13*8))(r3) + std r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r3) + std r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r3) + std r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r3) + std r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r3) + std r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r3) + std r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r3) + std r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r3) + std r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r3) + std r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r3) + std r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r3) + std r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r3) + std r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r3) + std r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r3) + std r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r3) + std r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r3) + std r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3) + std r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r3) + std r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r3) + mfctr r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_CTR*8))(r3) + mfxer r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r3) + mfcr r0 + std r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r3) + + /* Set the return value of swapcontext to "success". R3 is the only + register whose value is not preserved in the saved context. */ + li r0,0 + std r0,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r3) + + /* Zero fill fields that can't be set in user state or are unused. */ + std r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(34*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_SOFTE*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(40*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(41*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(42*8))(r3) + std r0,(SIGCONTEXT_GP_REGS+(PT_RESULT*8))(r3) + + /* Set the PT_REGS pointer to the address of sigcontext gp_regs + field. Struct pt_regs and elf_gregset_t are the same thing. + We kept the regs field for backwards compatibility with + libraries built before we extended sigcontext. */ + addi r0,r3,SIGCONTEXT_GP_REGS + std r0,SIGCONTEXT_PT_REGS(r3) + + stfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r3) + stfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r3) + stfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r3) + stfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r3) + stfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r3) + stfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r3) + stfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r3) + stfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r3) + stfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r3) + stfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r3) + stfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r3) + stfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r3) + stfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r3) + stfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r3) + stfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r3) + stfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r3) + stfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r3) + stfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r3) + stfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r3) + stfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r3) + stfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r3) + stfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r3) + stfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r3) + stfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r3) + stfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r3) + stfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r3) + stfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r3) + stfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r3) + stfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r3) + stfd fp29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r3) + mffs fp0 + stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3) + stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3) + stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3) + + mr r31,r4 + addi r5,r3,UCONTEXT_SIGMASK + addi r4,r4,UCONTEXT_SIGMASK + li r3,SIG_SETMASK + bl JUMPTARGET(sigprocmask) + nop + cmpdi r3,0 + bne L(nv_error_exit) + +/* + * If this new ucontext refers to the point where we were interrupted + * by a signal, we have to use the rt_sigreturn system call to + * return to the context so we get both LR and CTR restored. + * + * Otherwise, the context we are restoring is either just after + * a procedure call (getcontext/swapcontext) or at the beginning + * of a procedure call (makecontext), so we don't need to restore + * msr and ctr. We don't restore r13 since it will be used as + * the TLS pointer. */ + lwz r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31) + cmpdi r0,0 + bne L(nv_do_sigret) + + lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31) + lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31) + lfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r31) + mtfsf 0xff,fp0 + lfd fp29,(SIGCONTEXT_FP_REGS+(PT_R29*8))(r31) + lfd fp28,(SIGCONTEXT_FP_REGS+(PT_R28*8))(r31) + lfd fp27,(SIGCONTEXT_FP_REGS+(PT_R27*8))(r31) + lfd fp26,(SIGCONTEXT_FP_REGS+(PT_R26*8))(r31) + lfd fp25,(SIGCONTEXT_FP_REGS+(PT_R25*8))(r31) + lfd fp24,(SIGCONTEXT_FP_REGS+(PT_R24*8))(r31) + lfd fp23,(SIGCONTEXT_FP_REGS+(PT_R23*8))(r31) + lfd fp22,(SIGCONTEXT_FP_REGS+(PT_R22*8))(r31) + lfd fp21,(SIGCONTEXT_FP_REGS+(PT_R21*8))(r31) + lfd fp20,(SIGCONTEXT_FP_REGS+(PT_R20*8))(r31) + lfd fp19,(SIGCONTEXT_FP_REGS+(PT_R19*8))(r31) + lfd fp18,(SIGCONTEXT_FP_REGS+(PT_R18*8))(r31) + lfd fp17,(SIGCONTEXT_FP_REGS+(PT_R17*8))(r31) + lfd fp16,(SIGCONTEXT_FP_REGS+(PT_R16*8))(r31) + lfd fp15,(SIGCONTEXT_FP_REGS+(PT_R15*8))(r31) + lfd fp14,(SIGCONTEXT_FP_REGS+(PT_R14*8))(r31) + lfd fp13,(SIGCONTEXT_FP_REGS+(PT_R13*8))(r31) + lfd fp12,(SIGCONTEXT_FP_REGS+(PT_R12*8))(r31) + lfd fp11,(SIGCONTEXT_FP_REGS+(PT_R11*8))(r31) + lfd fp10,(SIGCONTEXT_FP_REGS+(PT_R10*8))(r31) + lfd fp9,(SIGCONTEXT_FP_REGS+(PT_R9*8))(r31) + lfd fp8,(SIGCONTEXT_FP_REGS+(PT_R8*8))(r31) + lfd fp7,(SIGCONTEXT_FP_REGS+(PT_R7*8))(r31) + lfd fp6,(SIGCONTEXT_FP_REGS+(PT_R6*8))(r31) + lfd fp5,(SIGCONTEXT_FP_REGS+(PT_R5*8))(r31) + lfd fp4,(SIGCONTEXT_FP_REGS+(PT_R4*8))(r31) + lfd fp3,(SIGCONTEXT_FP_REGS+(PT_R3*8))(r31) + lfd fp2,(SIGCONTEXT_FP_REGS+(PT_R2*8))(r31) + lfd fp1,(SIGCONTEXT_FP_REGS+(PT_R1*8))(r31) + lfd fp0,(SIGCONTEXT_FP_REGS+(PT_R0*8))(r31) + + ld r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r31) + ld r1,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r31) + mtlr r0 + ld r2,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r31) + ld r0,(SIGCONTEXT_GP_REGS+(PT_XER*8))(r31) + ld r3,(SIGCONTEXT_GP_REGS+(PT_R3*8))(r31) + mtxer r0 + ld r4,(SIGCONTEXT_GP_REGS+(PT_R4*8))(r31) + ld r0,(SIGCONTEXT_GP_REGS+(PT_CCR*8))(r31) + ld r5,(SIGCONTEXT_GP_REGS+(PT_R5*8))(r31) + mfcr r0 + ld r6,(SIGCONTEXT_GP_REGS+(PT_R6*8))(r31) + ld r7,(SIGCONTEXT_GP_REGS+(PT_R7*8))(r31) + ld r8,(SIGCONTEXT_GP_REGS+(PT_R8*8))(r31) + ld r9,(SIGCONTEXT_GP_REGS+(PT_R9*8))(r31) + ld r10,(SIGCONTEXT_GP_REGS+(PT_R10*8))(r31) + ld r11,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r31) + ld r12,(SIGCONTEXT_GP_REGS+(PT_R12*8))(r31) + /* Don't reload the thread ID or TLS pointer (r13). */ + ld r14,(SIGCONTEXT_GP_REGS+(PT_R14*8))(r31) + ld r15,(SIGCONTEXT_GP_REGS+(PT_R15*8))(r31) + ld r16,(SIGCONTEXT_GP_REGS+(PT_R16*8))(r31) + ld r17,(SIGCONTEXT_GP_REGS+(PT_R17*8))(r31) + ld r18,(SIGCONTEXT_GP_REGS+(PT_R18*8))(r31) + ld r19,(SIGCONTEXT_GP_REGS+(PT_R19*8))(r31) + ld r20,(SIGCONTEXT_GP_REGS+(PT_R20*8))(r31) + ld r21,(SIGCONTEXT_GP_REGS+(PT_R21*8))(r31) + ld r22,(SIGCONTEXT_GP_REGS+(PT_R22*8))(r31) + ld r23,(SIGCONTEXT_GP_REGS+(PT_R23*8))(r31) + ld r24,(SIGCONTEXT_GP_REGS+(PT_R24*8))(r31) + ld r25,(SIGCONTEXT_GP_REGS+(PT_R25*8))(r31) + ld r26,(SIGCONTEXT_GP_REGS+(PT_R26*8))(r31) + ld r27,(SIGCONTEXT_GP_REGS+(PT_R27*8))(r31) + ld r28,(SIGCONTEXT_GP_REGS+(PT_R28*8))(r31) + ld r29,(SIGCONTEXT_GP_REGS+(PT_R29*8))(r31) + ld r30,(SIGCONTEXT_GP_REGS+(PT_R30*8))(r31) + + /* Now we branch to the "Next Instruction Pointer" from the saved + context. With the powerpc64 instruction set there is no good way to + do this (from user state) without clobbering either the LR or CTR. + The makecontext and swapcontext functions depend on the callers + LR being preserved so we use the CTR. */ + ld r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r31) + mtctr r0 + ld r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r31) + ld r31,(SIGCONTEXT_GP_REGS+(PT_R31*8))(r31) + bctr + +L(nv_error_exit): + ld r0,128+FRAME_LR_SAVE(r1) + addi r1,r1,128 + mtlr r0 + ld r31,-8(r1) + blr + + /* At this point we assume that the ucontext was created by a + rt_signal and we should use rt_sigreturn to restore the original + state. As of the 2.4.21 kernel the ucontext is the first thing + (offset 0) in the rt_signal frame and rt_sigreturn expects the + ucontext address in R1. Normally the rt-signal trampoline handles + this by popping dummy frame before the rt_signal syscall. In our + case the stack may not be in its original (signal handler return with + R1 pointing at the dummy frame) state. We do have the ucontext + address in R3, so simply copy R3 to R1 before the syscall. */ +L(nv_do_sigret): + mr r1,r3, + li r0,SYS_ify(rt_sigreturn) + sc + /* No return. */ +#else + /* If the kernel is not at least 2.4.21 then generate a ENOSYS stub. */ + mflr r0 + std r0,FRAME_LR_SAVE(r1) + stdu r1,-128(r1) + li r3,ENOSYS + bl JUMPTARGET(__syscall_error) + nop + li r3,-1 + ld r0,128+FRAME_LR_SAVE(r1) + addi r1,r1,128 + mtlr r0 + blr +#endif + +PSEUDO_END(__novec_swapcontext) + +compat_symbol (libc, __novec_swapcontext, swapcontext, GLIBC_2_3) + +#endif + + .section ".toc","aw" +.LC__dl_hwcap: +#ifdef SHARED + .tc _rtld_global[TC],_rtld_global +#else + .tc _dl_hwcap[TC],_dl_hwcap +#endif + .section ".text" + ENTRY(__swapcontext) #ifdef __ASSUME_NEW_RT_SIGRETURN_SYSCALL std r0,(SIGCONTEXT_GP_REGS+(PT_R0*8))(r3) @@ -126,6 +388,119 @@ ENTRY(__swapcontext) stfd fp30,(SIGCONTEXT_FP_REGS+(PT_R30*8))(r3) stfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r3) stfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r3) + + ld r8,.LC__dl_hwcap@toc(r2) + li r10,0 +#ifdef SHARED +/* Load _rtld-global._dl_hwcap. */ + ld r8,RTLD_GLOBAL_DL_HWCAP_OFFSET(r8) +#else + ld r8,0(r8) /* Load extern _dl_hwcap. */ +#endif + andis. r8,r8,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(has_no_vec) + + la r10,(SIGCONTEXT_V_RESERVE+8)(r3) + la r9,(SIGCONTEXT_V_RESERVE+24)(r3) + clrrdi r10,r10,4 + clrrdi r9,r9,4 + + stvx v0,0,r10 + stvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v2,0,r10 + stvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v4,0,r10 + stvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v6,0,r10 + stvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v8,0,r10 + stvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v12,0,r10 + stvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v14,0,r10 + stvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v16,0,r10 + stvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v18,0,r10 + stvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + stvx v20,0,r10 + stvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v22,0,r10 + stvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v24,0,r10 + stvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v26,0,r10 + stvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v28,0,r10 + stvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v30,0,r10 + stvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + stvx v10,0,r10 + stvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mfvscr v0 + mfspr r0,VRSAVE + stvx v0,0,r10 + stw r0,0(9) + +L(has_no_vec): +/* + Store either a NULL or a quadword aligned pointer to the Vector register + array into *v_regs. +*/ + std r10,(SIGCONTEXT_V_REGS_PTR)(r3) mr r31,r4 addi r5,r3,UCONTEXT_SIGMASK @@ -149,6 +524,117 @@ ENTRY(__swapcontext) lwz r0,(SIGCONTEXT_GP_REGS+(PT_MSR*8))(r31) cmpdi r0,0 bne L(do_sigret) + + ld r8,.LC__dl_hwcap@toc(r2) + ld r10,(SIGCONTEXT_V_REGS_PTR)(r31) +#ifdef SHARED +/* Load _rtld-global._dl_hwcap. */ + ld r8,RTLD_GLOBAL_DL_HWCAP_OFFSET(r8) +#else + ld r8,0(r8) /* Load extern _dl_hwcap. */ +#endif + andis. r8,r8,(PPC_FEATURE_HAS_ALTIVEC >> 16) + beq L(has_no_vec2) + + cmpdi r10,0 + beq L(has_no_vec2) + lwz r0,(33*16)(r10) + + li r9,(16*32) + mtspr VRSAVE,r0 + cmpwi r0,0 + beq L(has_no_vec2) + + lvx v19,r9,r10 + la r9,(16)(r10) + + lvx v0,0,r10 + lvx v1,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + mtvscr v19 + lvx v2,0,r10 + lvx v3,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v4,0,r10 + lvx v5,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v6,0,r10 + lvx v7,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v8,0,r10 + lvx v9,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v12,0,r10 + lvx v13,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v14,0,r10 + lvx v15,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v16,0,r10 + lvx v17,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v18,0,r10 + lvx v11,0,r9 + addi r19,r10,32 + addi r9,r9,32 + + lvx v20,0,r10 + lvx v21,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v22,0,r10 + lvx v23,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v24,0,r10 + lvx v25,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v26,0,r10 + lvx v27,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v28,0,r10 + lvx v29,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v30,0,r10 + lvx v31,0,r9 + addi r10,r10,32 + addi r9,r9,32 + + lvx v10,0,r10 + lvx v11,0,r9 + addi r10,r10,32 + addi r9,r9,32 + +L(has_no_vec2): lfd fp0,(SIGCONTEXT_FP_REGS+(32*8))(r31) lfd fp31,(SIGCONTEXT_FP_REGS+(PT_R31*8))(r31) @@ -271,4 +757,4 @@ L(do_sigret): PSEUDO_END(__swapcontext) -weak_alias(__swapcontext, swapcontext) +versioned_symbol (libc, __swapcontext, swapcontext, GLIBC_2_3_4) diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h index c24a8d5963..45f1bfdae9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h @@ -56,3 +56,5 @@ #define SIGCONTEXT_PT_REGS 224 #define SIGCONTEXT_GP_REGS 232 #define SIGCONTEXT_FP_REGS 616 +#define SIGCONTEXT_V_REGS_PTR 880 +#define SIGCONTEXT_V_RESERVE 888 diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h index b75e25a3c8..a499a80ef9 100644 --- a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h +++ b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -29,7 +29,7 @@ #if __WORDSIZE == 32 /* Number of general registers. */ -#define NGREG 48 +# define NGREG 48 /* Container for all general registers. */ typedef unsigned long gregset_t[NGREG]; @@ -62,8 +62,74 @@ typedef struct #else -/* For 64-bit, a machine context is exactly a sigcontext. */ -typedef struct sigcontext mcontext_t; +/* For 64-bit kernels with Altivec support, a machine context is exactly + * a sigcontext. For older kernel (without Altivec) the sigcontext matches + * the mcontext upto but not including the v_regs field. For kernels that + * don't AT_HWCAP or return AT_HWCAP without PPC_FEATURE_HAS_ALTIVEC the + * v_regs field may not exit and should not be referenced. The v_regd field + * can be refernced safely only after verifying that PPC_FEATURE_HAS_ALTIVEC + * is set in AT_HWCAP. */ + +# include <asm/types.h> + +/* Number of general registers. */ +# define NGREG 48 /* includes r0-r31, nip, msr, lr, etc. */ +# define NFPREG 33 /* includes fp0-fp31 &fpscr. */ +# define NVRREG 34 /* includes v0-v31, vscr, & vrsave in split vectors */ + +typedef unsigned long gregset_t[NGREG]; +typedef double fpregset_t[NFPREG]; + +/* Container for Altivec/VMX Vector Status and Control Register. Only 32-bits + but can only be copied to/from a 128-bit vector register. So we allocated + a whole quadword speedup save/restore. */ +typedef struct _libc_vscr +{ + unsigned int __pad[3]; + unsigned int vscr_word; +} vscr_t; + +/* Container for Altivec/VMX registers and status. + Must to be aligned on a 16-byte boundary. */ +typedef struct _libc_vrstate +{ + unsigned int vrregs[32][4]; + vscr_t vscr; + unsigned int vrsave; + unsigned int __pad[3]; +} vrregset_t __attribute__((__aligned__(16))); + +typedef struct { + unsigned long __unused[4]; + int signal; + int __pad0; + unsigned long handler; + unsigned long oldmask; + struct pt_regs *regs; + gregset_t gp_regs; + fpregset_t fp_regs; +/* + * To maintain compatibility with current implementations the sigcontext is + * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t) + * followed by an unstructured (vmx_reserve) field of 69 doublewords. This + * allows the array of vector registers to be quadword aligned independent of + * the alignment of the containing sigcontext or ucontext. It is the + * responsibility of the code setting the sigcontext to set this pointer to + * either NULL (if this processor does not support the VMX feature) or the + * address of the first quadword within the allocated (vmx_reserve) area. + * + * The pointer (v_regs) of vector type (elf_vrreg_t) is essentually + * an array of 34 quadword entries. The entries with + * indexes 0-31 contain the corresponding vector registers. The entry with + * index 32 contains the vscr as the last word (offset 12) within the + * quadword. This allows the vscr to be stored as either a quadword (since + * it must be copied via a vector register to/from storage) or as a word. + * The entry with index 33 contains the vrsave as the first word (offset 0) + * within the quadword. + */ + vrregset_t *v_regs; + long vmx_reserve[NVRREG+NVRREG+1]; +} mcontext_t; #endif |