From cfc91acd418d2ea62a4520b42406a16ef07257c3 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 17 Sep 2002 23:50:03 +0000 Subject: 2002-09-17 Steven Munroe Ported to PowerPC64 running Linux. * sysdeps/powerpc/powerpc64/Dist: New file. * sysdeps/powerpc/powerpc64/Implies: New file. * sysdeps/powerpc/powerpc64/Makefile: New file. * sysdeps/powerpc/powerpc64/__longjmp.S: New file. * sysdeps/powerpc/powerpc64/atomicity.h: New file. * sysdeps/powerpc/powerpc64/backtrace.c: New file. * sysdeps/powerpc/powerpc64/bp-asm.h: New file. * sysdeps/powerpc/powerpc64/bsd-_setjmp.S: New file. * sysdeps/powerpc/powerpc64/bsd-setjmp.S: New file. * sysdeps/powerpc/powerpc64/dl-dtprocnum.h: New file. * sysdeps/powerpc/powerpc64/dl-lookupcfg.h: New file. * sysdeps/powerpc/powerpc64/dl-machine.c: New file. * sysdeps/powerpc/powerpc64/dl-machine.h: New file. * sysdeps/powerpc/powerpc64/memset.S: New file. * sysdeps/powerpc/powerpc64/ppc-mcount.S: New file. * sysdeps/powerpc/powerpc64/register-dump.h: New file. * sysdeps/powerpc/powerpc64/setjmp.S: New file. * sysdeps/powerpc/powerpc64/stpcpy.S: New file. * sysdeps/powerpc/powerpc64/strchr.S: New file. * sysdeps/powerpc/powerpc64/strcmp.S: New file. * sysdeps/powerpc/powerpc64/strcpy.S: New file. * sysdeps/powerpc/powerpc64/strlen.S: New file. * sysdeps/powerpc/powerpc64/elf/bzero.S: New file. * sysdeps/powerpc/powerpc64/elf/start.S: New file. * sysdeps/powerpc/powerpc64/fpu/s_copysign.S: New file. * sysdeps/powerpc/powerpc64/fpu/s_copysignf.S: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions: New File. * sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/glob64.c: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list: New file. * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h: New file. --- sysdeps/powerpc/powerpc64/Dist | 4 + sysdeps/powerpc/powerpc64/Implies | 1 + sysdeps/powerpc/powerpc64/Makefile | 23 + sysdeps/powerpc/powerpc64/__longjmp.S | 74 ++ sysdeps/powerpc/powerpc64/atomicity.h | 132 ++++ sysdeps/powerpc/powerpc64/backtrace.c | 69 ++ sysdeps/powerpc/powerpc64/bp-asm.h | 115 ++++ sysdeps/powerpc/powerpc64/bsd-_setjmp.S | 21 + sysdeps/powerpc/powerpc64/bsd-setjmp.S | 21 + sysdeps/powerpc/powerpc64/dl-dtprocnum.h | 22 + sysdeps/powerpc/powerpc64/dl-lookupcfg.h | 22 + sysdeps/powerpc/powerpc64/dl-machine.c | 50 ++ sysdeps/powerpc/powerpc64/dl-machine.h | 750 +++++++++++++++++++++ sysdeps/powerpc/powerpc64/elf/bzero.S | 21 + sysdeps/powerpc/powerpc64/elf/start.S | 66 ++ sysdeps/powerpc/powerpc64/fpu/s_copysign.S | 50 ++ sysdeps/powerpc/powerpc64/fpu/s_copysignf.S | 1 + sysdeps/powerpc/powerpc64/memset.S | 296 ++++++++ sysdeps/powerpc/powerpc64/ppc-mcount.S | 43 ++ sysdeps/powerpc/powerpc64/register-dump.h | 125 ++++ sysdeps/powerpc/powerpc64/setjmp.S | 87 +++ sysdeps/powerpc/powerpc64/stpcpy.S | 121 ++++ sysdeps/powerpc/powerpc64/strchr.S | 130 ++++ sysdeps/powerpc/powerpc64/strcmp.S | 133 ++++ sysdeps/powerpc/powerpc64/strcpy.S | 120 ++++ sysdeps/powerpc/powerpc64/strlen.S | 163 +++++ sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions | 18 + sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S | 45 ++ sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S | 101 +++ sysdeps/unix/sysv/linux/powerpc/powerpc64/glob64.c | 2 + sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S | 89 +++ .../sysv/linux/powerpc/powerpc64/syscalls.list | 52 ++ sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h | 178 +++++ 33 files changed, 3145 insertions(+) create mode 100644 sysdeps/powerpc/powerpc64/Dist create mode 100644 sysdeps/powerpc/powerpc64/Implies create mode 100644 sysdeps/powerpc/powerpc64/Makefile create mode 100644 sysdeps/powerpc/powerpc64/__longjmp.S create mode 100644 sysdeps/powerpc/powerpc64/atomicity.h create mode 100644 sysdeps/powerpc/powerpc64/backtrace.c create mode 100644 sysdeps/powerpc/powerpc64/bp-asm.h create mode 100644 sysdeps/powerpc/powerpc64/bsd-_setjmp.S create mode 100644 sysdeps/powerpc/powerpc64/bsd-setjmp.S create mode 100644 sysdeps/powerpc/powerpc64/dl-dtprocnum.h create mode 100644 sysdeps/powerpc/powerpc64/dl-lookupcfg.h create mode 100644 sysdeps/powerpc/powerpc64/dl-machine.c create mode 100644 sysdeps/powerpc/powerpc64/dl-machine.h create mode 100644 sysdeps/powerpc/powerpc64/elf/bzero.S create mode 100644 sysdeps/powerpc/powerpc64/elf/start.S create mode 100644 sysdeps/powerpc/powerpc64/fpu/s_copysign.S create mode 100644 sysdeps/powerpc/powerpc64/fpu/s_copysignf.S create mode 100644 sysdeps/powerpc/powerpc64/memset.S create mode 100644 sysdeps/powerpc/powerpc64/ppc-mcount.S create mode 100644 sysdeps/powerpc/powerpc64/register-dump.h create mode 100644 sysdeps/powerpc/powerpc64/setjmp.S create mode 100644 sysdeps/powerpc/powerpc64/stpcpy.S create mode 100644 sysdeps/powerpc/powerpc64/strchr.S create mode 100644 sysdeps/powerpc/powerpc64/strcmp.S create mode 100644 sysdeps/powerpc/powerpc64/strcpy.S create mode 100644 sysdeps/powerpc/powerpc64/strlen.S create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/brk.S create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/glob64.c create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h diff --git a/sysdeps/powerpc/powerpc64/Dist b/sysdeps/powerpc/powerpc64/Dist new file mode 100644 index 0000000000..bbadfef3b8 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/Dist @@ -0,0 +1,4 @@ +dl-machine.c +ppc-mcount.S +elf/entry.h +bp-asm.h diff --git a/sysdeps/powerpc/powerpc64/Implies b/sysdeps/powerpc/powerpc64/Implies new file mode 100644 index 0000000000..a8cae95f9d --- /dev/null +++ b/sysdeps/powerpc/powerpc64/Implies @@ -0,0 +1 @@ +wordsize-64 diff --git a/sysdeps/powerpc/powerpc64/Makefile b/sysdeps/powerpc/powerpc64/Makefile new file mode 100644 index 0000000000..ff6819a63f --- /dev/null +++ b/sysdeps/powerpc/powerpc64/Makefile @@ -0,0 +1,23 @@ +# Powerpc64 specific build options. +# this is ./sysdeps/powerpc/powerpc64/Makefile + ++cflags += -Wa,-mppc64 -mpowerpc64 +asm-CPPFLAGS += -Wa,-mppc64 + +# On PPC64, -fpic is the default so we don't need to specify it. +# Also early compilers would issue a warning if -fpic was specified. +# Each TOC entry takes 8 bytes and the TOC holds up to 2^16 bytes, +# or 8192 entries. If the TOC fills up try -minimal-toc. + +ifeq ($(subdir),csu) +ifneq ($(elf),no) +# The initfini generation code doesn't work in the presence of -g1 or +# higher, so we use -g0. +CFLAGS-initfini.s = -g0 -O1 +endif +endif + +ifeq ($(subdir),elf) +# help gcc inline asm code from dl-machine.h ++cflags += --param max-inline-insns=2000 +endif diff --git a/sysdeps/powerpc/powerpc64/__longjmp.S b/sysdeps/powerpc/powerpc64/__longjmp.S new file mode 100644 index 0000000000..e4152126b1 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/__longjmp.S @@ -0,0 +1,74 @@ +/* longjmp for PowerPC64. + Copyright (C) 1995, 1996, 1997, 1999, 2000, 2001, 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 +#define _ASM +#define _SETJMP_H +#include +#include +#include + +ENTRY (BP_SYM (__longjmp)) + CHECK_BOUNDS_BOTH_WIDE_LIT (r3, r8, r9, JB_SIZE) + ld r1,(JB_GPR1*8)(r3) + ld r2,(JB_GPR2*8)(r3) + ld r0,(JB_LR*8)(r3) + ld r14,((JB_GPRS+0)*8)(r3) + lfd fp14,((JB_FPRS+0)*8)(r3) + ld r15,((JB_GPRS+1)*8)(r3) + lfd fp15,((JB_FPRS+1)*8)(r3) + ld r16,((JB_GPRS+2)*8)(r3) + lfd fp16,((JB_FPRS+2)*8)(r3) + ld r17,((JB_GPRS+3)*8)(r3) + lfd fp17,((JB_FPRS+3)*8)(r3) + ld r18,((JB_GPRS+4)*8)(r3) + lfd fp18,((JB_FPRS+4)*8)(r3) + ld r19,((JB_GPRS+5)*8)(r3) + lfd fp19,((JB_FPRS+5)*8)(r3) + ld r20,((JB_GPRS+6)*8)(r3) + lfd fp20,((JB_FPRS+6)*8)(r3) + mtlr r0 + ld r21,((JB_GPRS+7)*8)(r3) + lfd fp21,((JB_FPRS+7)*8)(r3) + ld r22,((JB_GPRS+8)*8)(r3) + lfd fp22,((JB_FPRS+8)*8)(r3) + ld r0,(JB_CR*8)(r3) + ld r23,((JB_GPRS+9)*8)(r3) + lfd fp23,((JB_FPRS+9)*8)(r3) + ld r24,((JB_GPRS+10)*8)(r3) + lfd fp24,((JB_FPRS+10)*8)(r3) + ld r25,((JB_GPRS+11)*8)(r3) + lfd fp25,((JB_FPRS+11)*8)(r3) + mtcrf 0xFF,r0 + ld r26,((JB_GPRS+12)*8)(r3) + lfd fp26,((JB_FPRS+12)*8)(r3) + ld r27,((JB_GPRS+13)*8)(r3) + lfd fp27,((JB_FPRS+13)*8)(r3) + ld r28,((JB_GPRS+14)*8)(r3) + lfd fp28,((JB_FPRS+14)*8)(r3) + ld r29,((JB_GPRS+15)*8)(r3) + lfd fp29,((JB_FPRS+15)*8)(r3) + ld r30,((JB_GPRS+16)*8)(r3) + lfd fp30,((JB_FPRS+16)*8)(r3) + ld r31,((JB_GPRS+17)*8)(r3) + lfd fp31,((JB_FPRS+17)*8)(r3) + mr r3,r4 + blr +END (BP_SYM (__longjmp)) diff --git a/sysdeps/powerpc/powerpc64/atomicity.h b/sysdeps/powerpc/powerpc64/atomicity.h new file mode 100644 index 0000000000..b9d0de0ac5 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/atomicity.h @@ -0,0 +1,132 @@ +/* Low-level functions for atomic operations. PowerPC64 version. + Copyright (C) 1997, 1998, 1999, 2000, 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _ATOMICITY_H +#define _ATOMICITY_H 1 + +#include + +#if BROKEN_PPC_ASM_CR0 +# define __ATOMICITY_INLINE /* nothing */ +#else +# define __ATOMICITY_INLINE inline +#endif + +static __ATOMICITY_INLINE int +__attribute__ ((unused)) +exchange_and_add (volatile uint32_t *mem, int val) +{ + int tmp, result; + __asm__ ("\n\ +0: lwarx %0,0,%2 \n\ + add%I3 %1,%0,%3 \n\ + stwcx. %1,0,%2 \n\ + bne- 0b \n\ +" : "=&b"(result), "=&r"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory"); + return result; +} + +static __ATOMICITY_INLINE void +__attribute__ ((unused)) +atomic_add_long (volatile long *mem, int val) +{ + int tmp; + __asm__ ("\n\ +0: ldarx %0,0,%1 \n\ + add%I2 %0,%0,%2 \n\ + stdcx. %0,0,%1 \n\ + bne- 0b \n\ +" : "=&b"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory"); +} + + +static __ATOMICITY_INLINE int +__attribute__ ((unused)) +exchange_and_add_long (volatile long *mem, int val) +{ + int tmp, result; + __asm__ ("\n\ +0: ldarx %0,0,%2 \n\ + add%I3 %1,%0,%3 \n\ + stdcx. %1,0,%2 \n\ + bne- 0b \n\ +" : "=&b"(result), "=&r"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory"); + return result; +} + +static __ATOMICITY_INLINE void +__attribute__ ((unused)) +atomic_add (volatile uint32_t *mem, int val) +{ + int tmp; + __asm__ ("\n\ +0: lwarx %0,0,%1 \n\ + add%I2 %0,%0,%2 \n\ + stwcx. %0,0,%1 \n\ + bne- 0b \n\ +" : "=&b"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory"); +} + +static __ATOMICITY_INLINE int +__attribute__ ((unused)) +compare_and_swap (volatile long int *p, long int oldval, long int newval) +{ + int result; + __asm__ ("\n\ +0: ldarx %0,0,%1 \n\ + sub%I2c. %0,%0,%2 \n\ + cntlzw %0,%0 \n\ + bne- 1f \n\ + stdcx. %3,0,%1 \n\ + bne- 0b \n\ +1: \n\ +" : "=&b"(result) : "r"(p), "Ir"(oldval), "r"(newval) : "cr0", "memory"); + return result >> 5; +} + +static __ATOMICITY_INLINE long int +__attribute__ ((unused)) +always_swap (volatile long int *p, long int newval) +{ + long int result; + __asm__ ("\n\ +0: ldarx %0,0,%1 \n\ + stdcx. %2,0,%1 \n\ + bne- 0b \n\ +" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory"); + return result; +} + +static __ATOMICITY_INLINE int +__attribute__ ((unused)) +test_and_set (volatile long int *p, long int newval) +{ + int result; + __asm__ ("\n\ +0: ldarx %0,0,%1 \n\ + cmpdi %0,0 \n\ + bne- 1f \n\ + stdcx. %2,0,%1 \n\ + bne- 0b \n\ +1: \n\ +" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory"); + return result; +} + +#endif /* atomicity.h */ diff --git a/sysdeps/powerpc/powerpc64/backtrace.c b/sysdeps/powerpc/powerpc64/backtrace.c new file mode 100644 index 0000000000..8669b6a689 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/backtrace.c @@ -0,0 +1,69 @@ +/* Return backtrace of current program state. + Copyright (C) 1998, 2000, 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include + +/* This is the stack layout we see with every stack frame. + Note that every routine is required by the ABI to lay out the stack + like this. + + +----------------+ +-----------------+ + %r1 -> | %r1 last frame--------> | %r1 last frame--->... --> NULL + | | | | + | cr save | | cr save | + | | | | + | (unused) | | return address | + +----------------+ +-----------------+ +*/ +struct layout +{ + struct layout *__unbounded next; + long condition_register; + void *__unbounded return_address; +}; + +int +__backtrace (void **array, int size) +{ + struct layout *current; + int count; + + /* Force gcc to spill LR. */ + asm volatile ("" : "=l"(current)); + + /* Get the address on top-of-stack. */ + asm volatile ("ld %0,0(1)" : "=r"(current)); + current = BOUNDED_1 (current); + + for ( count = 0; + current != NULL && count < size; + current = BOUNDED_1 (current->next), count++) + array[count] = current->return_address; + + /* It's possible the second-last stack frame can't return + (that is, it's __libc_start_main), in which case + the CRT startup code will have set its LR to 'NULL'. */ + if (count > 0 && array[count-1] == NULL) + count--; + + return count; +} +weak_alias (__backtrace, backtrace) diff --git a/sysdeps/powerpc/powerpc64/bp-asm.h b/sysdeps/powerpc/powerpc64/bp-asm.h new file mode 100644 index 0000000000..ee99e3044b --- /dev/null +++ b/sysdeps/powerpc/powerpc64/bp-asm.h @@ -0,0 +1,115 @@ +/* Bounded-pointer definitions for PowerPC64 assembler. + Copyright (C) 2000, 2002 Free Software Foundation, Inc. + Contributed by Greg McGary + + This file is part of the GNU C Library. Its master source is NOT part of + the C library, however. The master source lives in the GNU MP Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#if __BOUNDED_POINTERS__ + +/* Byte offsets of BP components. */ +# define oVALUE 0 +# define oLOW 4 +# define oHIGH 8 + +/* Don't check bounds, just convert the BP register to its simple + pointer value. */ + +# define DISCARD_BOUNDS(rBP) \ + ld rBP, oVALUE(rBP) + +/* Check low bound, with the side effect that the BP register is converted + its simple pointer value. Move the high bound into a register for + later use. */ + +# define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH) \ + ld rHIGH, oHIGH(rBP); \ + ld rLOW, oLOW(rBP); \ + ld rBP, oVALUE(rBP); \ + tdllt rBP, rLOW + +/* Check the high bound, which is in a register, using the given + conditional trap instruction. */ + +# define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc) \ + TWLcc rVALUE, rHIGH + +/* Check the high bound, which is stored at the return-value's high + bound slot, using the given conditional trap instruction. */ + +# define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc) \ + ld rHIGH, oHIGH(rRTN); \ + TWLcc rVALUE, rHIGH + +/* Check both bounds, with the side effect that the BP register is + converted to its simple pointer value. */ + +# define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH) \ + CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH); \ + tdlge rBP, rHIGH + +/* Check bounds on a memory region of given length, with the side + effect that the BP register is converted to its simple pointer + value. */ + +# define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH) \ + CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH); \ + sub rHIGH, rHIGH, rLENGTH; \ + tdlgt rBP, rHIGH + +# define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH) \ + CHECK_BOUNDS_LOW (rBP, rLOW, rHIGH); \ + subi rHIGH, rHIGH, LENGTH; \ + tdlgt rBP, rHIGH + +/* Store a pointer value register into the return-value's pointer + value slot. */ + +# define STORE_RETURN_VALUE(rVALUE) \ + std rVALUE, oVALUE(rRTN) + +/* Store a low and high bounds into the return-value's pointer bounds + slots. */ + +# define STORE_RETURN_BOUNDS(rLOW, rHIGH) \ + std rLOW, oLOW(rRTN); \ + std rHIGH, oHIGH(rRTN) + +/* Stuff zero value/low/high into the BP addressed by rRTN. */ + +# define RETURN_NULL_BOUNDED_POINTER \ + li r4, 0; \ + STORE_RETURN_VALUE (r4); \ + STORE_RETURN_BOUNDS (r4, r4) + +#else + +# define DISCARD_BOUNDS(rBP) +# define CHECK_BOUNDS_LOW(rBP, rLOW, rHIGH) +# define CHECK_BOUNDS_HIGH(rVALUE, rHIGH, TWLcc) +# define CHECK_BOUNDS_HIGH_RTN(rVALUE, rHIGH, TWLcc) +# define CHECK_BOUNDS_BOTH(rBP, rLOW, rHIGH) +# define CHECK_BOUNDS_BOTH_WIDE(rBP, rLOW, rHIGH, rLENGTH) +# define CHECK_BOUNDS_BOTH_WIDE_LIT(rBP, rLOW, rHIGH, LENGTH) +# define STORE_RETURN_VALUE(rVALUE) +# define STORE_RETURN_BOUNDS(rLOW, rHIGH) + +# define RETURN_NULL_BOUNDED_POINTER li rRTN, 0 + +#endif + diff --git a/sysdeps/powerpc/powerpc64/bsd-_setjmp.S b/sysdeps/powerpc/powerpc64/bsd-_setjmp.S new file mode 100644 index 0000000000..994f82f851 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/bsd-_setjmp.S @@ -0,0 +1,21 @@ +/* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'. PowerPC64 version. + 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. */ + +/* This code was moved into setjmp.S to solve a double stub call problem. + @local would have worked but it is not supported in PowerPC64 asm. */ diff --git a/sysdeps/powerpc/powerpc64/bsd-setjmp.S b/sysdeps/powerpc/powerpc64/bsd-setjmp.S new file mode 100644 index 0000000000..b6bb8f6e08 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/bsd-setjmp.S @@ -0,0 +1,21 @@ +/* BSD `setjmp' entry point to `sigsetjmp (..., 1)'. PowerPC version. + 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. */ + +/* This code was moved into setjmp.S to solve a double stub call problem. + @local would have worked but it is not supported in PowerPC64 asm. */ diff --git a/sysdeps/powerpc/powerpc64/dl-dtprocnum.h b/sysdeps/powerpc/powerpc64/dl-dtprocnum.h new file mode 100644 index 0000000000..477cb44339 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/dl-dtprocnum.h @@ -0,0 +1,22 @@ +/* Configuration of lookup functions. PowerPC64 version. + 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. */ + +/* Number of extra dynamic section entries for this architecture. By + default there are none. */ +#define DT_THISPROCNUM DT_PPC64_NUM diff --git a/sysdeps/powerpc/powerpc64/dl-lookupcfg.h b/sysdeps/powerpc/powerpc64/dl-lookupcfg.h new file mode 100644 index 0000000000..e502941015 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/dl-lookupcfg.h @@ -0,0 +1,22 @@ +/* Configuration of lookup functions. PowerPC64 version. + 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. */ + +/* Return the symbol map from the symbol lookup function. */ + +#define DL_LOOKUP_RETURNS_MAP 1 diff --git a/sysdeps/powerpc/powerpc64/dl-machine.c b/sysdeps/powerpc/powerpc64/dl-machine.c new file mode 100644 index 0000000000..ef7b3400f3 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/dl-machine.c @@ -0,0 +1,50 @@ +/* Machine-dependent ELF dynamic relocation functions. PowerPC64 version. + Copyright (C) 1995,96,97,98,99,2000,01, 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include +#include + +void +_dl_reloc_overflow (struct link_map *map, + const char *name, + Elf64_Addr *const reloc_addr, + const Elf64_Sym *sym, + const Elf64_Sym *refsym) +{ + char buffer[128]; + char *t; + const Elf64_Sym *errsym = sym ?: refsym; + t = stpcpy (buffer, name); + t = stpcpy (t, " reloc at 0x"); + _itoa_word ((unsigned long) reloc_addr, t, 16, 0); + if (errsym) + { + const char *strtab; + + strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]); + t = stpcpy (t, " for symbol `"); + t = stpcpy (t, strtab + errsym->st_name); + t = stpcpy (t, "'"); + } + t = stpcpy (t, " out of range"); + _dl_signal_error (0, map->l_name, NULL, buffer); +} diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h new file mode 100644 index 0000000000..408161649b --- /dev/null +++ b/sysdeps/powerpc/powerpc64/dl-machine.h @@ -0,0 +1,750 @@ +/* Machine-dependent ELF dynamic relocation inline functions. + PowerPC64 version. + Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "powerpc64" + +#include +#include + +/* Translate a processor specific dynamic tag to the index + in l_info array. */ +#define DT_PPC64(x) (DT_PPC64_##x - DT_LOPROC + DT_NUM) + +/* A PowerPC64 function descriptor. The .plt (procedure linkage + table) and .opd (official procedure descriptor) sections are + arrays of these. */ +typedef struct +{ + Elf64_Addr fd_func; + Elf64_Addr fd_toc; + Elf64_Addr fd_aux; +} Elf64_FuncDesc; + +#define ELF_MULT_MACHINES_SUPPORTED + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int +elf_machine_matches_host (const Elf64_Ehdr *ehdr) +{ + return ehdr->e_machine == EM_PPC64; +} + +/* Return nonzero iff ELF header is compatible with the running host, + but not this loader. */ +static inline int +elf_host_tolerates_machine (const Elf64_Ehdr *ehdr) +{ + return ehdr->e_machine == EM_PPC; +} + +/* Return nonzero iff ELF header is compatible with the running host, + but not this loader. */ +static inline int +elf_host_tolerates_class (const Elf64_Ehdr *ehdr) +{ + return ehdr->e_ident[EI_CLASS] == ELFCLASS32; +} + + +/* Return the run-time load address of the shared object, assuming it + was originally linked at zero. */ +static inline Elf64_Addr +elf_machine_load_address (void) __attribute__ ((const)); + +static inline Elf64_Addr +elf_machine_load_address (void) +{ + Elf64_Addr ret; + + /* The first entry in .got (and thus the first entry in .toc) is the + link-time TOC_base, ie. r2. So the difference between that and + the current r2 set by the kernel is how far the shared lib has + moved. */ + asm ( " ld %0,-32768(2)\n" + " subf %0,%0,2\n" + : "=r" (ret)); + return ret; +} + +/* Return the link-time address of _DYNAMIC. */ +static inline Elf64_Addr +elf_machine_dynamic (void) +{ + Elf64_Addr runtime_dynamic; + /* It's easier to get the run-time address. */ + asm ( " addis %0,2,_DYNAMIC@toc@ha\n" + " addi %0,%0,_DYNAMIC@toc@l\n" + : "=b" (runtime_dynamic)); + /* Then subtract off the load address offset. */ + return runtime_dynamic - elf_machine_load_address() ; +} + +#define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) /* nothing */ + +/* The PLT uses Elf64_Rela relocs. */ +#define elf_machine_relplt elf_machine_rela + +/* This code gets called via a .glink stub which loads PLT0. It is + used in dl-runtime.c to call the `fixup' function and then redirect + to the address `fixup' returns. + + Enter with r0 = plt reloc index, + r2 = ld.so tocbase, + r11 = ld.so link map. */ + +#define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \ + asm (".section \".text\"\n" \ +" .align 2\n" \ +" .globl ." #tramp_name "\n" \ +" .type ." #tramp_name ",@function\n" \ +" .section \".opd\",\"aw\"\n" \ +" .align 3\n" \ +" .globl " #tramp_name "\n" \ +" .size " #tramp_name ",24\n" \ +#tramp_name ":\n" \ +" .quad ." #tramp_name ",.TOC.@tocbase,0\n" \ +" .previous\n" \ +"." #tramp_name ":\n" \ +/* We need to save the registers used to pass parameters, ie. r3 thru \ + r10; the registers are saved in a stack frame. */ \ +" stdu 1,-128(1)\n" \ +" std 3,48(1)\n" \ +" mr 3,11\n" \ +" std 4,56(1)\n" \ +" sldi 4,0,1\n" \ +" std 5,64(1)\n" \ +" add 4,4,0\n" \ +" std 6,72(1)\n" \ +" sldi 4,4,3\n" \ +" std 7,80(1)\n" \ +" mflr 0\n" \ +" std 8,88(1)\n" \ +/* Store the LR in the LR Save area of the previous frame. */ \ +" std 0,128+16(1)\n" \ +" mfcr 0\n" \ +" std 9,96(1)\n" \ +" std 10,104(1)\n" \ +/* I'm almost certain we don't have to save cr... be safe. */ \ +" std 0,8(1)\n" \ +" bl ." #fixup_name "\n" \ +/* Put the registers back. */ \ +" ld 0,128+16(1)\n" \ +" ld 10,104(1)\n" \ +" ld 9,96(1)\n" \ +" ld 8,88(1)\n" \ +" ld 7,80(1)\n" \ +" mtlr 0\n" \ +" ld 0,8(1)\n" \ +" ld 6,72(1)\n" \ +" ld 5,64(1)\n" \ +" ld 4,56(1)\n" \ +" mtcrf 0xFF,0\n" \ +/* Load the target address, toc and static chain reg from the function \ + descriptor returned by fixup. */ \ +" ld 0,0(3)\n" \ +" ld 2,8(3)\n" \ +" mtctr 0\n" \ +" ld 11,16(3)\n" \ +" ld 3,48(1)\n" \ +/* Unwind the stack frame, and jump. */ \ +" addi 1,1,128\n" \ +" bctr\n" \ +".LT_" #tramp_name ":\n" \ +" .long 0\n" \ +" .byte 0x00,0x0c,0x24,0x40,0x00,0x00,0x00,0x00\n" \ +" .long .LT_" #tramp_name "-."#tramp_name "\n" \ +" .short .LT_" #tramp_name "_name_end-.LT_" #tramp_name "_name_start\n" \ +".LT_" #tramp_name "_name_start:\n" \ +" .ascii \"" #tramp_name "\"\n" \ +".LT_" #tramp_name "_name_end:\n" \ +" .align 2\n" \ +" .size ." #tramp_name ",. - ." #tramp_name "\n" \ +" .previous"); + +#ifndef PROF +#define ELF_MACHINE_RUNTIME_TRAMPOLINE \ + TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \ + TRAMPOLINE_TEMPLATE (_dl_profile_resolve, profile_fixup); +#else +#define ELF_MACHINE_RUNTIME_TRAMPOLINE \ + TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \ + void _dl_runtime_resolve (void); \ + strong_alias (_dl_runtime_resolve, _dl_profile_resolve); +#endif + + +/* Initial entry point code for the dynamic linker. The C function + `_dl_start' is the real entry point; its return value is the user + program's entry point. */ +#define RTLD_START \ + asm (".section \".text\"\n" \ +" .align 2\n" \ +" .globl ._start\n" \ +" .type ._start,@function\n" \ +" .section \".opd\",\"aw\"\n" \ +" .align 3\n" \ +" .globl _start\n" \ +" .size _start,24\n" \ +"_start:\n" \ +" .quad ._start,.TOC.@tocbase,0\n" \ +" .previous\n" \ +"._start:\n" \ +/* We start with the following on the stack, from top: \ + argc (4 bytes); \ + arguments for program (terminated by NULL); \ + environment variables (terminated by NULL); \ + arguments for the program loader. */ \ +" mr 3,1\n" \ +" li 4,0\n" \ +" stdu 4,-128(1)\n" \ +/* Call _dl_start with one parameter pointing at argc. */ \ +" bl ._dl_start\n" \ +" nop\n" \ +/* Transfer control to _dl_start_user! */ \ +" b ._dl_start_user\n" \ +".LT__start:\n" \ +" .long 0\n" \ +" .byte 0x00,0x0c,0x24,0x40,0x00,0x00,0x00,0x00\n" \ +" .long .LT__start-._start\n" \ +" .short .LT__start_name_end-.LT__start_name_start\n" \ +".LT__start_name_start:\n" \ +" .ascii \"_start\"\n" \ +".LT__start_name_end:\n" \ +" .align 2\n" \ +" .size ._start,.-._start\n" \ +" .globl _dl_start_user\n" \ +" .section \".opd\",\"aw\"\n" \ +"_dl_start_user:\n" \ +" .quad ._dl_start_user, .TOC.@tocbase, 0\n" \ +" .previous\n" \ +" .globl ._dl_start_user\n" \ +" .type ._dl_start_user,@function\n" \ +/* Now, we do our main work of calling initialisation procedures. \ + The ELF ABI doesn't say anything about parameters for these, \ + so we just pass argc, argv, and the environment. \ + Changing these is strongly discouraged (not least because argc is \ + passed by value!). */ \ +"._dl_start_user:\n" \ +/* the address of _start in r30. */ \ +" mr 30,3\n" \ +/* &_dl_argc in 29, &_dl_argv in 27, and _dl_loaded in 28. */ \ +" ld 28,_rtld_global@got(2)\n" \ +" ld 29,_dl_argc@got(2)\n" \ +" ld 27,_dl_argv@got(2)\n" \ +/* _dl_init (_dl_loaded, _dl_argc, _dl_argv, _dl_argv+_dl_argc+1). */ \ +" ld 3,0(28)\n" \ +" lwa 4,0(29)\n" \ +" ld 5,0(27)\n" \ +" sldi 6,4,3\n" \ +" add 6,5,6\n" \ +" addi 6,6,8\n" \ +" bl ._dl_init\n" \ +" nop\n" \ +/* Now, to conform to the ELF ABI, we have to: \ + Pass argc (actually _dl_argc) in r3; */ \ +" lwa 3,0(29)\n" \ +/* Pass argv (actually _dl_argv) in r4; */ \ +" ld 4,0(27)\n" \ +/* Pass argv+argc+1 in r5; */ \ +" sldi 5,3,3\n" \ +" add 6,4,5\n" \ +" addi 5,6,8\n" \ +/* Pass the auxilary vector in r6. This is passed to us just after \ + _envp. */ \ +"2: ldu 0,8(6)\n" \ +" cmpdi 0,0\n" \ +" bne 2b\n" \ +" addi 6,6,8\n" \ +/* Pass a termination function pointer (in this case _dl_fini) in \ + r7. */ \ +" ld 7,_dl_fini@got(2)\n" \ +" ld 26,_dl_starting_up@got(2)\n" \ +/* Pass the stack pointer in r1 (so far so good), pointing to a NULL \ + value. This lets our startup code distinguish between a program \ + linked statically, which linux will call with argc on top of the \ + stack which will hopefully never be zero, and a dynamically linked \ + program which will always have a NULL on the top of the stack. \ + Take the opportunity to clear LR, so anyone who accidentally \ + returns from _start gets SEGV. Also clear the next few words of \ + the stack. */ \ +" li 31,0\n" \ +" std 31,0(1)\n" \ +" mtlr 31\n" \ +" std 31,8(1)\n" \ +" std 31,16(1)\n" \ +" std 31,24(1)\n" \ +/* Clear _dl_starting_up. */ \ +" stw 31,0(26)\n" \ +/* Now, call the start function descriptor at r30... */ \ +" .globl ._dl_main_dispatch\n" \ +"._dl_main_dispatch:\n" \ +" ld 0,0(30)\n" \ +" ld 2,8(30)\n" \ +" mtctr 0\n" \ +" ld 11,16(30)\n" \ +" bctr\n" \ +".LT__dl_start_user:\n" \ +" .long 0\n" \ +" .byte 0x00,0x0c,0x24,0x40,0x00,0x00,0x00,0x00\n" \ +" .long .LT__dl_start_user-._dl_start_user\n" \ +" .short .LT__dl_start_user_name_end-.LT__dl_start_user_name_start\n" \ +".LT__dl_start_user_name_start:\n" \ +" .ascii \"_dl_start_user\"\n" \ +".LT__dl_start_user_name_end:\n" \ +" .align 2\n" \ +" .size ._dl_start_user,.-._dl_start_user\n" \ +" .previous"); + +/* Nonzero iff TYPE should not be allowed to resolve to one of + the main executable's symbols, as for a COPY reloc. */ +#define elf_machine_lookup_noexec_p(type) ((type) == R_PPC64_COPY) + +/* Nonzero iff TYPE describes relocation of a PLT entry, so + PLT entries should not be allowed to define the value. */ +#define elf_machine_lookup_noplt_p(type) ((type) == R_PPC64_JMP_SLOT) + +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so + PLT entries should not be allowed to define the value. + ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one + of the main executable's symbols, as for a COPY reloc. */ +#define elf_machine_type_class(type) \ + ((((type) == R_PPC64_ADDR24) * ELF_RTYPE_CLASS_PLT) \ + | (((type) == R_PPC64_COPY) * ELF_RTYPE_CLASS_COPY)) + +/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */ +#define ELF_MACHINE_JMP_SLOT R_PPC64_JMP_SLOT + +/* The PowerPC never uses REL relocations. */ +#define ELF_MACHINE_NO_REL 1 + +/* Stuff for the PLT. */ +#define PLT_INITIAL_ENTRY_WORDS 3 +#define GLINK_INITIAL_ENTRY_WORDS 8 + +#define PPC_DCBST(where) asm volatile ("dcbst 0,%0" : : "r"(where) : "memory") +#define PPC_SYNC asm volatile ("sync" : : : "memory") +#define PPC_ISYNC asm volatile ("sync; isync" : : : "memory") +#define PPC_ICBI(where) asm volatile ("icbi 0,%0" : : "r"(where) : "memory") +#define PPC_DIE asm volatile ("tweq 0,0") +/* Use this when you've modified some code, but it won't be in the + instruction fetch queue (or when it doesn't matter if it is). */ +#define MODIFIED_CODE_NOQUEUE(where) \ + do { PPC_DCBST(where); PPC_SYNC; PPC_ICBI(where); } while (0) +/* Use this when it might be in the instruction queue. */ +#define MODIFIED_CODE(where) \ + do { PPC_DCBST(where); PPC_SYNC; PPC_ICBI(where); PPC_ISYNC; } while (0) + +/* Set up the loaded object described by MAP so its unrelocated PLT + entries will jump to the on-demand fixup code in dl-runtime.c. */ +static inline int +elf_machine_runtime_setup (struct link_map *map, int lazy, int profile) +{ + if (map->l_info[DT_JMPREL]) + { + Elf64_Word i; + Elf64_Word *glink = NULL; + Elf64_Xword *plt = (Elf64_Xword *) D_PTR (map, l_info[DT_PLTGOT]); + Elf64_Word num_plt_entries = (map->l_info[DT_PLTRELSZ]->d_un.d_val + / sizeof (Elf64_Rela)); + Elf64_Addr l_addr = map->l_addr; + Elf64_Dyn **info = map->l_info; + char *p; + + extern void _dl_runtime_resolve (void); + extern void _dl_profile_resolve (void); + + /* Relocate the DT_PPC64_GLINK entry in the _DYNAMIC section. + elf_get_dynamic_info takes care of the standard entries but + doesn't know exactly what to do with processor specific + entires. */ + if (info[DT_PPC64(GLINK)] != NULL) + info[DT_PPC64(GLINK)]->d_un.d_ptr += l_addr; + + if (lazy) + { + /* The function descriptor of the appropriate trampline + routine is used to set the 1st and 2nd doubleword of the + plt_reserve. */ + Elf64_FuncDesc *resolve_fd; + Elf64_Word glink_offset; + /* the plt_reserve area is the 1st 3 doublewords of the PLT */ + Elf64_FuncDesc *plt_reserve = (Elf64_FuncDesc *) plt; + Elf64_Word offset; + + resolve_fd = (Elf64_FuncDesc *) (profile ? _dl_profile_resolve + : _dl_runtime_resolve); + if (profile && _dl_name_match_p (GL(dl_profile), map)) + /* This is the object we are looking for. Say that we really + want profiling and the timers are started. */ + GL(dl_profile_map) = map; + + + /* We need to stuff the address/TOC of _dl_runtime_resolve + into doublewords 0 and 1 of plt_reserve. Then we need to + stuff the map address into doubleword 2 of plt_reserve. + This allows the GLINK0 code to transfer control to the + correct trampoline which will transfer control to fixup + in dl-machine.c. */ + plt_reserve->fd_func = resolve_fd->fd_func; + plt_reserve->fd_toc = resolve_fd->fd_toc; + plt_reserve->fd_aux = (Elf64_Addr) map; +#ifdef RTLD_BOOTSTRAP + /* When we're bootstrapping, the opd entry will not have + been relocated yet. */ + plt_reserve->fd_func += l_addr; + plt_reserve->fd_toc += l_addr; +#endif + + /* Set up the lazy PLT entries. */ + glink = (Elf64_Word *) D_PTR (map, l_info[DT_PPC64(GLINK)]); + offset = PLT_INITIAL_ENTRY_WORDS; + glink_offset = GLINK_INITIAL_ENTRY_WORDS; + for (i = 0; i < num_plt_entries; i++) + { + + plt[offset] = (Elf64_Xword) &glink[glink_offset]; + offset += 3; + /* The first 32k entries of glink can set an index and + branch using two instructions; Past that point, + glink uses three instructions. */ + if (i < 0x8000) + glink_offset += 2; + else + glink_offset += 3; + } + + /* Now, we've modified data. We need to write the changes from + the data cache to a second-level unified cache, then make + sure that stale data in the instruction cache is removed. + (In a multiprocessor system, the effect is more complex.) + Most of the PLT shouldn't be in the instruction cache, but + there may be a little overlap at the start and the end. + + Assumes that dcbst and icbi apply to lines of 16 bytes or + more. Current known line sizes are 16, 32, and 128 bytes. */ + + for (p = (char *) plt; p < (char *) &plt[offset]; p += 16) + PPC_DCBST (p); + PPC_SYNC; + } + } + return lazy; +} + +static inline void +elf_machine_lazy_rel (struct link_map *map, + Elf64_Addr l_addr, const Elf64_Rela *reloc) +{ + /* elf_machine_runtime_setup handles this. */ +} + +/* Change the PLT entry whose reloc is 'reloc' to call the actual + routine. */ +static inline Elf64_Addr +elf_machine_fixup_plt (struct link_map *map, lookup_t sym_map, + const Elf64_Rela *reloc, + Elf64_Addr *reloc_addr, Elf64_Addr finaladdr) +{ + Elf64_FuncDesc *plt = (Elf64_FuncDesc *) reloc_addr; + Elf64_FuncDesc *rel = (Elf64_FuncDesc *) finaladdr; + Elf64_Addr offset = 0; +#ifndef RTLD_BOOTSTRAP + weak_extern (GL(dl_rtld_map)); +#endif + + /* If sym_map is NULL, it's a weak undefined sym; Leave the plt zero. */ + if (sym_map == NULL) + return 0; + + /* If the opd entry is not yet relocated (because it's from a shared + object that hasn't been processed yet), then manually reloc it. */ + if (map != sym_map && !sym_map->l_relocated +#ifndef RTLD_BOOTSTRAP + /* Bootstrap map doesn't have l_relocated set for it. */ + && sym_map != &GL(dl_rtld_map) +#endif + ) + offset = sym_map->l_addr; + + /* For PPC64, fixup_plt copies the function descriptor from opd + over the corresponding PLT entry. + Initially, PLT Entry[i] is set up for lazy linking, or is zero. + For lazy linking, the fd_toc and fd_aux entries are irrelevant, + so for thread safety we write them before changing fd_func. */ + + plt->fd_aux = rel->fd_aux + offset; + plt->fd_toc = rel->fd_toc + offset; + PPC_DCBST (&plt->fd_aux); + PPC_DCBST (&plt->fd_toc); + PPC_SYNC; + + plt->fd_func = rel->fd_func + offset; + PPC_DCBST (&plt->fd_func); + PPC_SYNC; + + return finaladdr; +} + +/* Return the final value of a plt relocation. */ +static inline Elf64_Addr +elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc, + Elf64_Addr value) +{ + return value + reloc->r_addend; +} + +#endif /* dl_machine_h */ + +#ifdef RESOLVE_MAP + +#define PPC_LO(v) ((v) & 0xffff) +#define PPC_HI(v) (((v) >> 16) & 0xffff) +#define PPC_HA(v) PPC_HI ((v) + 0x8000) +#define PPC_HIGHER(v) (((v) >> 32) & 0xffff) +#define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000) +#define PPC_HIGHEST(v) (((v) >> 48) & 0xffff) +#define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000) +#define BIT_INSERT(old, val, mask) ((old & ~(Elf64_Addr) mask) | (val & mask)) + +#define dont_expect(X) __builtin_expect ((X), 0) + +extern void _dl_reloc_overflow (struct link_map *map, + const char *name, + Elf64_Addr *const reloc_addr, + const Elf64_Sym *sym, + const Elf64_Sym *refsym) + attribute_hidden; + +static inline void +elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc, + Elf64_Addr *const reloc_addr) +{ + *reloc_addr = l_addr + reloc->r_addend; +} + +/* Perform the relocation specified by RELOC and SYM (which is fully + resolved). MAP is the object containing the reloc. */ +static inline void +elf_machine_rela (struct link_map *map, + const Elf64_Rela *reloc, + const Elf64_Sym *sym, + const struct r_found_version *version, + Elf64_Addr *const reloc_addr) +{ + int r_type = ELF64_R_TYPE (reloc->r_info); + struct link_map *sym_map; + Elf64_Addr value; +#ifndef RTLD_BOOTSTRAP + const Elf64_Sym *const refsym = sym; + /* This is defined in rtld.c, but nowhere in the static libc.a; make the + reference weak so static programs can still link. This declaration + cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) + because rtld.c contains the common defn for _dl_rtld_map, which is + incompatible with a weak decl in the same file. */ + weak_extern (GL(dl_rtld_map)); +#endif + + if (r_type == R_PPC64_RELATIVE) + { +#ifndef RTLD_BOOTSTRAP + /* Already done in dynamic linker. */ + if (map != &GL(dl_rtld_map)) +#endif + *reloc_addr = map->l_addr + reloc->r_addend; + return; + } + + if (r_type == R_PPC64_NONE) + return; + + sym_map = RESOLVE_MAP (&sym, version, r_type); + value = 0; + if (sym_map) + { + if (sym) + value = sym_map->l_addr + sym->st_value; + value += reloc->r_addend; + } + + switch (r_type) + { + case R_PPC64_ADDR64: + case R_PPC64_GLOB_DAT: + *reloc_addr = value; + return; + + case R_PPC64_JMP_SLOT: + + elf_machine_fixup_plt (map, sym_map, reloc, reloc_addr, value); + return; + +#ifndef RTLD_BOOTSTRAP /* None of the following appear in ld.so */ + case R_PPC64_ADDR16_LO_DS: + if (dont_expect ((value & 3) != 0)) + _dl_reloc_overflow (map, "R_PPC64_ADDR16_LO_DS", + reloc_addr, sym, refsym); + *(Elf64_Half *) reloc_addr = BIT_INSERT (*(Elf64_Half *) reloc_addr, + value, 0xfffc); + break; + + case R_PPC64_ADDR16_LO: + *(Elf64_Half *) reloc_addr = PPC_LO (value); + break; + + case R_PPC64_ADDR16_HI: + *(Elf64_Half *) reloc_addr = PPC_HI (value); + break; + + case R_PPC64_ADDR16_HA: + *(Elf64_Half *) reloc_addr = PPC_HA (value); + break; + + case R_PPC64_REL24: + { + Elf64_Addr delta = value - (Elf64_Xword) reloc_addr; + if (dont_expect ((delta + 0x2000000) >= 0x4000000 || (delta & 3) != 0)) + _dl_reloc_overflow (map, "R_PPC64_REL24", reloc_addr, sym, refsym); + *(Elf64_Word *) reloc_addr = BIT_INSERT (*(Elf64_Word *) reloc_addr, + delta, 0x3fffffc); + } + break; + + case R_PPC64_COPY: + if (dont_expect (sym == NULL)) + /* This can happen in trace mode when an object could not be found. */ + return; + if (dont_expect (sym->st_size > refsym->st_size + || (GL(dl_verbose) && sym->st_size < refsym->st_size))) + { + const char *strtab; + + strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]); + _dl_error_printf ("%s: Symbol `%s' has different size" \ + " in shared object," \ + " consider re-linking\n", + _dl_argv[0] ?: "", + strtab + refsym->st_name); + } + memcpy (reloc_addr, (char *) value, MIN (sym->st_size, refsym->st_size)); + return; + + case R_PPC64_UADDR64: + /* We are big-endian. */ + ((char *) reloc_addr)[0] = (value >> 56) & 0xff; + ((char *) reloc_addr)[1] = (value >> 48) & 0xff; + ((char *) reloc_addr)[2] = (value >> 40) & 0xff; + ((char *) reloc_addr)[3] = (value >> 32) & 0xff; + ((char *) reloc_addr)[4] = (value >> 24) & 0xff; + ((char *) reloc_addr)[5] = (value >> 16) & 0xff; + ((char *) reloc_addr)[6] = (value >> 8) & 0xff; + ((char *) reloc_addr)[7] = (value >> 0) & 0xff; + return; + + case R_PPC64_UADDR32: + /* We are big-endian. */ + ((char *) reloc_addr)[0] = (value >> 24) & 0xff; + ((char *) reloc_addr)[1] = (value >> 16) & 0xff; + ((char *) reloc_addr)[2] = (value >> 8) & 0xff; + ((char *) reloc_addr)[3] = (value >> 0) & 0xff; + return; + + case R_PPC64_ADDR24: + if (dont_expect ((value + 0x2000000) >= 0x4000000 || (value & 3) != 0)) + _dl_reloc_overflow (map, "R_PPC64_ADDR24", reloc_addr, sym, refsym); + *(Elf64_Word *) reloc_addr = BIT_INSERT (*(Elf64_Word *) reloc_addr, + value, 0x3fffffc); + break; + + case R_PPC64_ADDR16: + if (dont_expect ((value + 0x8000) >= 0x10000)) + _dl_reloc_overflow (map, "R_PPC64_ADDR16", reloc_addr, sym, refsym); + *(Elf64_Half *) reloc_addr = value; + break; + + case R_PPC64_UADDR16: + if (dont_expect ((value + 0x8000) >= 0x10000)) + _dl_reloc_overflow (map, "R_PPC64_UADDR16", reloc_addr, sym, refsym); + /* We are big-endian. */ + ((char *) reloc_addr)[0] = (value >> 8) & 0xff; + ((char *) reloc_addr)[1] = (value >> 0) & 0xff; + break; + + case R_PPC64_ADDR16_DS: + if (dont_expect ((value + 0x8000) >= 0x10000 || (value & 3) != 0)) + _dl_reloc_overflow (map, "R_PPC64_ADDR16_DS", reloc_addr, sym, refsym); + *(Elf64_Half *) reloc_addr = BIT_INSERT (*(Elf64_Half *) reloc_addr, + value, 0xfffc); + break; + + case R_PPC64_ADDR16_HIGHER: + *(Elf64_Half *) reloc_addr = PPC_HIGHER (value); + break; + + case R_PPC64_ADDR16_HIGHEST: + *(Elf64_Half *) reloc_addr = PPC_HIGHEST (value); + break; + + case R_PPC64_ADDR16_HIGHERA: + *(Elf64_Half *) reloc_addr = PPC_HIGHERA (value); + break; + + case R_PPC64_ADDR16_HIGHESTA: + *(Elf64_Half *) reloc_addr = PPC_HIGHESTA (value); + break; + + case R_PPC64_ADDR14: + case R_PPC64_ADDR14_BRTAKEN: + case R_PPC64_ADDR14_BRNTAKEN: + { + Elf64_Word insn; + if (dont_expect ((value + 0x8000) >= 0x10000 || (value & 3) != 0)) + _dl_reloc_overflow (map, "R_PPC64_ADDR14", reloc_addr, sym, refsym); + insn = BIT_INSERT (*(Elf64_Word *) reloc_addr, value, 0xfffc); + if (r_type != R_PPC64_ADDR14) + { + insn &= ~(1 << 21); + if (r_type == R_PPC64_ADDR14_BRTAKEN) + insn |= 1 << 21; + if ((insn & (0x14 << 21)) == (0x04 << 21)) + insn |= 0x02 << 21; + else if ((insn & (0x14 << 21)) == (0x10 << 21)) + insn |= 0x08 << 21; + } + *(Elf64_Word *) reloc_addr = insn; + } + break; + + case R_PPC64_REL32: + *(Elf64_Word *) reloc_addr = value - (Elf64_Xword) reloc_addr; + return; +#endif /* !RTLD_BOOTSTRAP */ + + default: + _dl_reloc_bad_type (map, r_type, 0); + return; + } + MODIFIED_CODE_NOQUEUE (reloc_addr); +} + +#endif /* RESOLVE */ diff --git a/sysdeps/powerpc/powerpc64/elf/bzero.S b/sysdeps/powerpc/powerpc64/elf/bzero.S new file mode 100644 index 0000000000..f899bd234e --- /dev/null +++ b/sysdeps/powerpc/powerpc64/elf/bzero.S @@ -0,0 +1,21 @@ +/* Optimized bzero `implementation' for PowerPC64. + Copyright (C) 1997, 1999, 2000, 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. */ + +/* This code was moved into memset.S to solve a double stub call problem. + @local would have worked but it is not supported in PowerPC64 asm. */ diff --git a/sysdeps/powerpc/powerpc64/elf/start.S b/sysdeps/powerpc/powerpc64/elf/start.S new file mode 100644 index 0000000000..129f126e9d --- /dev/null +++ b/sysdeps/powerpc/powerpc64/elf/start.S @@ -0,0 +1,66 @@ +/* Startup code for programs linked with GNU libc. PowerPC64 version. + Copyright (C) 1998, 1999, 2000, 2001, 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 +#include "bp-sym.h" + + /* These are the various addresses we require. */ + .section ".rodata" + .align 3 + weak_extern(_init) + weak_extern(_fini) + weak_extern(._init) + weak_extern(._fini) +L(start_addresses): + .quad 0 /* was _SDA_BASE_ but not in 64-bit ABI*/ +/* function descriptors so don't need JUMPTARGET */ + .quad BP_SYM(main) + .quad _init + .quad _fini + + ASM_SIZE_DIRECTIVE(L(start_addresses)) + + .section ".toc","aw" +.L01: + .tc L(start_addresses)[TC],L(start_addresses) + .section ".text" +ENTRY(_start) + /* Save the stack pointer, in case we're statically linked under Linux. */ + mr r9,r1 + /* Set up an initial stack frame, and clear the LR. */ + clrrdi r1,r1,4 + li r0,0 + stdu r1,-128(r1) + mtlr r0 + std r0,0(r1) + + /* put the address of start_addresses in r8... ** +** PPC64 ABI uses R13 for thread local, so we leave it alone */ + ld r8,.L01(r2) + + /* and continue in libc-start, in glibc. */ + b JUMPTARGET(BP_SYM(__libc_start_main)) + +END(_start) + +/* Define a symbol for the first piece of initialized data. */ + .section ".data" + .globl __data_start +__data_start: +weak_alias (__data_start, data_start) diff --git a/sysdeps/powerpc/powerpc64/fpu/s_copysign.S b/sysdeps/powerpc/powerpc64/fpu/s_copysign.S new file mode 100644 index 0000000000..40fd83d3d1 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/fpu/s_copysign.S @@ -0,0 +1,50 @@ +/* Copy a sign bit between floating-point values. PowerPC64 version. + Copyright (C) 1997, 1999, 2000, 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. */ + +/* This has been coded in assembler because GCC makes such a mess of it + when it's coded in C. */ + +#include + +ENTRY(__copysign) +/* double [f1] copysign (double [f1] x, double [f2] y); + copysign(x,y) returns a value with the magnitude of x and + with the sign bit of y. */ + stdu r1,-48(r1) + stfd fp2,24(r1) + ld r3,24(r1) + cmpdi r3,0 + addi r1,r1,48 + blt L(0) + fabs fp1,fp1 + blr +L(0): fnabs fp1,fp1 + blr + END (__copysign) + +weak_alias(__copysign,copysign) + +/* It turns out that it's safe to use this code even for single-precision. */ +weak_alias(__copysign,copysignf) +strong_alias(__copysign,__copysignf) + +#ifdef NO_LONG_DOUBLE +weak_alias(__copysign,copysignl) +strong_alias(__copysign,__copysignl) +#endif diff --git a/sysdeps/powerpc/powerpc64/fpu/s_copysignf.S b/sysdeps/powerpc/powerpc64/fpu/s_copysignf.S new file mode 100644 index 0000000000..e05438ae7d --- /dev/null +++ b/sysdeps/powerpc/powerpc64/fpu/s_copysignf.S @@ -0,0 +1 @@ +/* __copysignf is in s_copysign.S */ diff --git a/sysdeps/powerpc/powerpc64/memset.S b/sysdeps/powerpc/powerpc64/memset.S new file mode 100644 index 0000000000..4bfe20d7b1 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/memset.S @@ -0,0 +1,296 @@ +/* Optimized memset implementation for PowerPC64. + Copyright (C) 1997, 1999, 2000, 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 +#include +#include + +/* Define a global static that can hold the cache line size. The + assumption is that startup code will access the "aux vector" to + to obtain the value set by the kernel and store it into this + variable. */ + .globl __cache_line_size + .section ".data" + .align 2 + .type __cache_line_size,@object + .size __cache_line_size,4 +__cache_line_size: + .long 0 + .section ".toc","aw" +.LC0: + .tc __cache_line_size[TC],__cache_line_size + .section ".text" + .align 2 + +/* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5])); + Returns 's'. + + The memset is done in three sizes: byte (8 bits), word (32 bits), + cache line (256 bits). There is a special case for setting cache lines + to 0, to take advantage of the dcbz instruction. */ + +EALIGN (BP_SYM (memset), 5, 0) + +#define rTMP r0 +#define rRTN r3 /* Initial value of 1st argument. */ +#if __BOUNDED_POINTERS__ +# define rMEMP0 r4 /* Original value of 1st arg. */ +# define rCHR r5 /* Char to set in each byte. */ +# define rLEN r6 /* Length of region to set. */ +# define rMEMP r10 /* Address at which we are storing. */ +#else +# define rMEMP0 r3 /* Original value of 1st arg. */ +# define rCHR r4 /* Char to set in each byte. */ +# define rLEN r5 /* Length of region to set. */ +# define rMEMP r6 /* Address at which we are storing. */ +#endif +#define rALIGN r7 /* Number of bytes we are setting now (when aligning). */ +#define rMEMP2 r8 + +#define rNEG64 r8 /* Constant -64 for clearing with dcbz. */ +#define rCLS r8 /* Cache line size obtained from static. */ +#define rCLM r9 /* Cache line size mask to check for cache alignment. */ + +___memset: +#if __BOUNDED_POINTERS__ + cmpldi cr1, rRTN, 0 + CHECK_BOUNDS_BOTH_WIDE (rMEMP0, rTMP, rTMP2, rLEN) + beq cr1, L(b0) + STORE_RETURN_VALUE (rMEMP0) + STORE_RETURN_BOUNDS (rTMP, rTMP2) +L(b0): +#endif +/* Take care of case for size <= 4. */ + cmpldi cr1, rLEN, 8 + andi. rALIGN, rMEMP0, 7 + mr rMEMP, rMEMP0 + ble- cr1, L(small) + +/* Align to doubleword boundary. */ + cmpldi cr5, rLEN, 31 + rlwimi rCHR, rCHR, 8, 16, 23 /* Replicate byte to halfword. */ + beq+ L(aligned2) + mtcrf 0x01, rMEMP0 + subfic rALIGN, rALIGN, 8 + cror 28,30,31 /* Detect odd word aligned. */ + add rMEMP, rMEMP, rALIGN + sub rLEN, rLEN, rALIGN + rlwimi rCHR, rCHR, 16, 0, 15 /* Replicate halfword to word. */ + bt 29, L(g4) +/* Process the even word of doubleword. */ + bf+ 31, L(g2) + stb rCHR, 0(rMEMP0) + bt 30, L(g4x) +L(g2): + sth rCHR, -6(rMEMP) +L(g4x): + stw rCHR, -4(rMEMP) + b L(aligned) +/* Process the odd word of doubleword. */ +L(g4): + bf 28, L(g4x) /* If false, word aligned on odd word. */ + bf+ 31, L(g0) + stb rCHR, 0(rMEMP0) + bt 30, L(aligned) +L(g0): + sth rCHR, -2(rMEMP) + +/* Handle the case of size < 31. */ +L(aligned2): + rlwimi rCHR, rCHR, 16, 0, 15 /* Replicate halfword to word. */ +L(aligned): + mtcrf 0x01, rLEN + ble cr5, L(medium) +/* Align to 32-byte boundary. */ + andi. rALIGN, rMEMP, 0x18 + subfic rALIGN, rALIGN, 0x20 + insrdi rCHR,rCHR,32,0 /* Replicate word to double word. */ + beq L(caligned) + mtcrf 0x01, rALIGN + add rMEMP, rMEMP, rALIGN + sub rLEN, rLEN, rALIGN + cmplwi cr1, rALIGN, 0x10 + mr rMEMP2, rMEMP + bf 28, L(a1) + stdu rCHR, -8(rMEMP2) +L(a1): blt cr1, L(a2) + std rCHR, -8(rMEMP2) + stdu rCHR, -16(rMEMP2) +L(a2): + +/* Now aligned to a 32 byte boundary. */ +L(caligned): + cmpldi cr1, rCHR, 0 + clrrdi. rALIGN, rLEN, 5 + mtcrf 0x01, rLEN + beq cr1, L(zloopstart) /* Special case for clearing memory using dcbz. */ +L(nondcbz): + srdi rTMP, rALIGN, 5 + mtctr rTMP + beq L(medium) /* We may not actually get to do a full line. */ + clrldi. rLEN, rLEN, 59 + add rMEMP, rMEMP, rALIGN + li rNEG64, -0x40 + bdz L(cloopdone) + +L(c3): dcbtst rNEG64, rMEMP + std rCHR, -8(rMEMP) + std rCHR, -16(rMEMP) + std rCHR, -24(rMEMP) + stdu r