about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-01-17 01:02:24 +0000
committerUlrich Drepper <drepper@redhat.com>2003-01-17 01:02:24 +0000
commit609b4783564008cafdeb947bfd613a1bcb5946f6 (patch)
treeec4d830d2bf9d55decdf5bc941ececfe91e71d7d /sysdeps
parent7b7b9e70ea0d820c863c78fbf84fe52626a408d6 (diff)
downloadglibc-609b4783564008cafdeb947bfd613a1bcb5946f6.tar.gz
glibc-609b4783564008cafdeb947bfd613a1bcb5946f6.tar.xz
glibc-609b4783564008cafdeb947bfd613a1bcb5946f6.zip
Update.
2003-01-16  Steven Munroe  <sjmunroe@us.ibm.com>

	* sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.h: New file.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: New file.
	* sysdeps/unix/sysv/linux/configure.in: Minimum kernel for PPC64
	is 2.4.21.

2003-01-16  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/generic/glob.c (glob): Assume sysconf() always returns
	values != -1 for _LIBC.  Use extend_alloca to reallocate alloca'ed
	buffers.

	* sysdeps/generic/sysconf.c: Unconditionally implement
	_SC_GETPW_R_SIZE_MAX and _SC_GETGR_R_SIZE_MAX.
	* sysdeps/posix/sysconf.c: Likewise.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/glob.c20
-rw-r--r--sysdeps/generic/sysconf.c11
-rw-r--r--sysdeps/posix/sysconf.c10
-rw-r--r--sysdeps/unix/sysv/linux/configure.in4
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S138
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S161
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S162
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S257
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h47
9 files changed, 793 insertions, 17 deletions
diff --git a/sysdeps/generic/glob.c b/sysdeps/generic/glob.c
index 5e56629082..fa23f8cac1 100644
--- a/sysdeps/generic/glob.c
+++ b/sysdeps/generic/glob.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2002, 2003 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
@@ -284,6 +284,7 @@ extern char *alloca ();
 #endif
 
 #ifdef _LIBC
+# include <alloca.h>
 # undef strdup
 # define strdup(str) __strdup (str)
 # define sysconf(id) __sysconf (id)
@@ -697,10 +698,12 @@ glob (pattern, flags, errfunc, pglob)
 		  struct passwd pwbuf;
 		  int save = errno;
 
+#    ifndef _LIBC
 		  if (pwbuflen == -1)
 		    /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.
 		       Try a moderate value.  */
 		    pwbuflen = 1024;
+#    endif
 		  pwtmpbuf = (char *) __alloca (pwbuflen);
 
 		  while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p)
@@ -711,8 +714,13 @@ glob (pattern, flags, errfunc, pglob)
 			  p = NULL;
 			  break;
 			}
+#    ifdef _LIBC
+		      pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen,
+						2 * pwbuflen);
+#    else
 		      pwbuflen *= 2;
 		      pwtmpbuf = (char *) __alloca (pwbuflen);
+#    endif
 		      __set_errno (save);
 		    }
 #   else
@@ -781,10 +789,12 @@ glob (pattern, flags, errfunc, pglob)
 	    struct passwd pwbuf;
 	    int save = errno;
 
+#   ifndef _LIBC
 	    if (buflen == -1)
 	      /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.  Try a
 		 moderate value.  */
 	      buflen = 1024;
+#   endif
 	    pwtmpbuf = (char *) __alloca (buflen);
 
 	    while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0)
@@ -794,8 +804,12 @@ glob (pattern, flags, errfunc, pglob)
 		    p = NULL;
 		    break;
 		  }
+#   ifdef _LIBC
+		pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen);
+#   else
 		buflen *= 2;
 		pwtmpbuf = __alloca (buflen);
+#   endif
 		__set_errno (save);
 	      }
 #  else
@@ -1326,9 +1340,9 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
 	      int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
 			       | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
 #if defined _AMIGA || defined VMS
-				   | FNM_CASEFOLD
+			       | FNM_CASEFOLD
 #endif
-				   );
+			       );
 	      nfound = 0;
 	      flags |= GLOB_MAGCHAR;
 
diff --git a/sysdeps/generic/sysconf.c b/sysdeps/generic/sysconf.c
index f1b64d58eb..d67e3568a3 100644
--- a/sysdeps/generic/sysconf.c
+++ b/sysdeps/generic/sysconf.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991,1993,1995-1997,2001,2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1995-1997,2001,2002,2003
+   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
@@ -142,6 +143,12 @@ __sysconf (name)
     case _SC_USHRT_MAX:
       return USHRT_MAX;
 
+    case _SC_GETGR_R_SIZE_MAX:
+      return NSS_BUFLEN_GROUP;
+
+    case _SC_GETPW_R_SIZE_MAX:
+      return NSS_BUFLEN_PASSWD;
+
     case _SC_ARG_MAX:
     case _SC_CHILD_MAX:
     case _SC_CLK_TCK:
@@ -211,8 +218,6 @@ __sysconf (name)
 
     case _SC_THREADS:
     case _SC_THREAD_SAFE_FUNCTIONS:
-    case _SC_GETGR_R_SIZE_MAX:
-    case _SC_GETPW_R_SIZE_MAX:
     case _SC_LOGIN_NAME_MAX:
     case _SC_TTY_NAME_MAX:
     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index 3804aa1061..1700ed0b87 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,93,1995-1997,1999-2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,93,1995-1997,1999-2003 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
@@ -509,18 +509,10 @@ __sysconf (name)
 #endif
 
     case _SC_GETGR_R_SIZE_MAX:
-#ifdef	NSS_BUFLEN_GROUP
       return NSS_BUFLEN_GROUP;
-#else
-      return -1;
-#endif
 
     case _SC_GETPW_R_SIZE_MAX:
-#ifdef	NSS_BUFLEN_PASSWD
       return NSS_BUFLEN_PASSWD;
-#else
-      return -1;
-#endif
 
     case _SC_LOGIN_NAME_MAX:
 #ifdef	_POSIX_LOGIN_NAME_MAX
diff --git a/sysdeps/unix/sysv/linux/configure.in b/sysdeps/unix/sysv/linux/configure.in
index 30309c2948..7947743f1a 100644
--- a/sysdeps/unix/sysv/linux/configure.in
+++ b/sysdeps/unix/sysv/linux/configure.in
@@ -64,7 +64,7 @@ case "$machine" in
     arch_minimum_kernel=2.4.0
     ;;
   hppa*)
-    libc_cv_gcc_unwind_find_fde=yes  
+    libc_cv_gcc_unwind_find_fde=yes
     arch_minimum_kernel=2.4.19
     ;;
   m68k*)
@@ -80,7 +80,7 @@ case "$machine" in
     arch_minimum_kernel=2.0.10
     ;;
   powerpc/powerpc64)
-    arch_minimum_kernel=2.4.19
+    arch_minimum_kernel=2.4.21
     ;;
   s390/s390-32)
     libc_cv_gcc_unwind_find_fde=yes
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
new file mode 100644
index 0000000000..59dfb82ef5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/getcontext.S
@@ -0,0 +1,138 @@
+/* Save current context.
+   Copyright (C) 2002 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
+   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.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+ENTRY(__getcontext)
+  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)
+
+  addi  r5,r3,UCONTEXT_SIGMASK
+  li  r4,0
+  li  r3,SIG_BLOCK
+  bl  .sigprocmask
+  nop
+  
+  ld    r0,128+FRAME_LR_SAVE(r1)  
+  addi  r1,r1,128
+  mtlr  r0
+  blr
+PSEUDO_END(__getcontext)
+
+weak_alias(__getcontext, getcontext)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S
new file mode 100644
index 0000000000..29dd17ffe4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/makecontext.S
@@ -0,0 +1,161 @@
+/* Create new context.
+   Copyright (C) 2002 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
+   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.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+ENTRY(__makecontext)
+  /* Save parameters into the parameter save area of callers frame.  */
+  std  r3,FRAME_PARM1_SAVE(r1) /* ucontext_t *ucp  */
+  std  r4,FRAME_PARM2_SAVE(r1) /* void (*func)(void)  */
+  std  r5,FRAME_PARM3_SAVE(r1) /* int argc  */
+  std  r6,FRAME_PARM4_SAVE(r1) /* ... */
+  std  r7,FRAME_PARM5_SAVE(r1)
+  std  r8,FRAME_PARM6_SAVE(r1)
+  std  r9,FRAME_PARM7_SAVE(r1)
+  std  r10,FRAME_PARM8_SAVE(r1)
+  mflr  r0
+  /* Get the address of the target functions first parameter.  */
+  addi  r6,r1,FRAME_PARM4_SAVE
+  std   r0,FRAME_LR_SAVE(r1)
+  stdu  r1,-128(r1)
+  
+  /* Get the ucontexts stack pointer and size.  Compute the top of stack
+     and round down to a quadword boundary.  Then stack a dummy frame 
+     with a null back chain.  We store the context pointer in the frames
+     "compiler double word" field so we can recover if is the function 
+     returns.  Finally save the callers link register and TOC pointer 
+     into this frame so the debugger can display a backtrace.
+  */
+  ld    r7,UCONTEXT_STACK_SP(r3)
+  ld    r0,UCONTEXT_STACK_SIZE(r3)
+  add   r7,r7,r0
+  clrrdi  r7,r7,4
+  li    r0,0
+  stdu  r0,-48(r7)
+  std   r3,24(r7)
+  mflr  r0
+  std   r2,FRAME_TOC_SAVE(r7)  /* Store the TOC pointer for later.  */
+  std   r0,FRAME_LR_SAVE(r7)
+  
+  /* Now we need to stack another frame to hold the parameter save area
+     for the function.  We need to allocate a frame with the minimum 48 
+     byte header and 8 parameter register.  However if there are more 
+     than 8 parameters addition space is need to hold all the parameters.
+     The total size it rounded up to a quadword multiple then a frame is 
+     stacked.  This address is stored in the ucontext as GPR 1.  */
+     
+  cmpdi cr1,r5,8  
+  sldi  r8,r5,3
+  bgt   cr1,L(gt8)
+  li    r8,64
+L(gt8):
+  addi  r8,r8,FRAME_PARM_SAVE+8 /* Add header plus rounding factor.  */
+  clrrdi  r8,r8,4  /* Round down to quadword.  */
+  
+  subf  r8,r8,r7
+  std   r7,0(r8)   /* Stack the frame.  */
+  std   r8,(SIGCONTEXT_GP_REGS+(PT_R1*8))(r3)
+  
+  /* Now we need to copy the target functions parameters.  The functions 
+     parameters are saved in the parameter save area.  We skip over the
+     first three parameters and copy up to 8 double word into the 
+     SIGCONTEXT_GP_REGS starting with R3.  If there are more than 8 
+     parameters then doublewords 8-N are copied into the parameter
+     save area of the context frame.  */ 
+  cmpdi r5,0
+  beq   L(noparms)
+  mr    r0,r5
+  ble   cr1,L(le8)
+  li    r0,8
+L(le8):    
+  mtctr r0
+  addi  r7,r6,-8
+  addi  r9,r3,(SIGCONTEXT_GP_REGS+(PT_R3*8)-8)
+L(parmloop2):
+  ldu   r0,8(r7)
+  stdu  r0,8(r9)
+  bdnz  L(parmloop2)
+  
+  addi  r0,r5,-8 
+  ble   cr1,L(noparms) 
+  mtctr r0
+  addi  r9,r8,FRAME_PARM9_SAVE-8
+L(parmloop):
+  ldu   r0,8(r7)
+  stdu  r0,8(r9)
+  bdnz  L(parmloop)
+  
+L(noparms):
+  
+  /* Load the function address and TOC from the function descriptor
+     and store them in the ucontext as NIP and r2.  Store the 3rd 
+     field of the function descriptor into the ucontext as r11 in case
+     the calling language needs the "environment pointer".  */
+  ld    r0,0(r4)
+  ld    r10,8(r4);
+  ld    r9,16(r4); 
+  std   r0,(SIGCONTEXT_GP_REGS+(PT_NIP*8))(r3)  
+  std   r10,(SIGCONTEXT_GP_REGS+(PT_R2*8))(r3) 
+  std   r9,(SIGCONTEXT_GP_REGS+(PT_R11*8))(r3)
+  
+  /* If the target function returns we need to do some cleanup.  We use a
+     code trick to get the address of our cleanup function into the link
+     register.  Do not add any code between here and L(exitcode).  */
+  bl  L(gotexitcodeaddr);
+
+	/* This is the helper code which gets called if a function which
+	   is registered with 'makecontext' returns.  In this case we
+	   have to install the context listed in the uc_link element of
+	   the context 'makecontext' manipulated at the time of the
+	   'makecontext' call.  If the pointer is NULL the process must
+	   terminate.  */
+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    r2,FRAME_TOC_SAVE(r1)
+  ld    r3,UCONTEXT_LINK(r3)  /* Load the resume context.  */
+  cmpdi r3,0
+  beq   L(BADSTATUS)
+	bl    JUMPTARGET(__setcontext)
+	nop
+
+L(BADSTATUS):
+/* If setcontext returns (which can happen if the syscall fails) we will
+   exit the program with error status (-1).  */
+  li    r3,-1
+  b     JUMPTARGET(exit);
+  
+  /* The address of the exit code is in the link register.  Store the lr
+     in the ucontext as LNK so the target function will return to our 
+     exit code.  */
+L(gotexitcodeaddr):
+  mflr  r0
+  std   r0,(SIGCONTEXT_GP_REGS+(PT_LNK*8))(r3)
+  ld    r0,128+FRAME_LR_SAVE(r1)  
+  addi  r1,r1,128
+  mtlr  r0
+  blr
+END(__makecontext)
+
+weak_alias(__makecontext, makecontext)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
new file mode 100644
index 0000000000..d503cbbf3e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/setcontext.S
@@ -0,0 +1,162 @@
+/* Switch to context.
+   Copyright (C) 2002 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
+   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.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+ENTRY(__setcontext)
+  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(do_sigret)
+
+  li    r5,0
+  addi  r4,r3,UCONTEXT_SIGMASK
+  li    r3,SIG_SETMASK
+  bl    .sigprocmask
+  nop
+  cmpdi r3,0
+  bne   L(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(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(do_sigret):
+  mr   r1,r3,
+  li   r0,SYS_ify(rt_sigreturn)
+  sc
+  /* No return.  */
+
+PSEUDO_END(__setcontext)
+
+weak_alias(__setcontext, setcontext)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
new file mode 100644
index 0000000000..23422fb948
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/swapcontext.S
@@ -0,0 +1,257 @@
+/* Save current context and install the given one.
+   Copyright (C) 2002 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
+   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.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+#define __ASSEMBLY__
+#include <asm/ptrace.h>
+#include "ucontext_i.h"
+
+ENTRY(__swapcontext)
+  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    .sigprocmask
+  nop
+  cmpdi  r3,0
+  bne   L(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(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(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(do_sigret):
+  mr   r1,r3,
+  li   r0,SYS_ify(rt_sigreturn)
+  sc
+  /* No return.  */
+
+PSEUDO_END(__swapcontext)
+
+weak_alias(__swapcontext, swapcontext)
diff --git a/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
new file mode 100644
index 0000000000..0f7b19c70c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
@@ -0,0 +1,47 @@
+/* Copyright (C) 1998, 1999, 2002 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
+   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.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H	1
+
+#include <features.h>
+#include <signal.h>
+
+/* We need the signal context definitions even if they are not used
+   included in <signal.h>.  */
+#include <bits/sigcontext.h>
+
+/* A machine context is exactly a sigcontext.  */
+typedef struct sigcontext mcontext_t;
+
+/* Userlevel context.  */
+typedef struct ucontext
+  {
+    unsigned long int uc_flags;
+    struct ucontext *uc_link;
+    stack_t uc_stack;
+#if __WORDSIZE == 32
+    mcontext_t uc_mcontext;
+    __sigset_t uc_sigmask;
+#else
+    sigset_t    uc_sigmask;
+    mcontext_t  uc_mcontext;  /* last for extensibility */
+#endif
+  } ucontext_t;
+
+#endif /* sys/ucontext.h */