alpha: Add hidden alias for fegetenv.
[glibc-ports.git] / sysdeps / hppa / dl-trampoline.S
blobc7c18ed18d34ed3aa3341048a38b626a8d34a5c5
1 /* PLT trampolines. hppa version.
2    Copyright (C) 2005, 2006 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
22 /* This code gets called via the .plt stub, and is used in
23    dl-runtime.c to call the `_dl_fixup' function and then redirect 
24    to the address it returns. `_dl_fixup' takes two arguments, however 
25    `_dl_profile_fixup' takes a number of parameters for use with 
26    library auditing (LA).
27    
28    WARNING: This template is also used by gcc's __cffc, and expects
29    that the "bl" for _dl_runtime_resolve exist at a particular offset.
30    Do not change this template without changing gcc, while the prefix
31    "bl" should fix everything so gcc finds the right spot, it will
32    slow down __cffc when it attempts to call fixup to resolve function
33    descriptor references. Please refer to gcc/gcc/config/pa/fptr.c
34    
35    Enter with r19 = reloc offset, r20 = got-8, r21 = fixup ltp.  */
37         /* RELOCATION MARKER: bl to provide gcc's __cffc with fixup loc. */
38         .text
39         /* THIS CODE DOES NOT EXECUTE */
40         bl      _dl_fixup, %r2
41         .text
42         .global _dl_runtime_resolve
43         .type _dl_runtime_resolve,@function
44         cfi_startproc
45         .align 4
46 _dl_runtime_resolve:
47         .PROC
48         .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=3
49         .ENTRY
50         /* SAVE_RP says we do */
51         stw     %rp, -20(%sp)
53         /* Save static link register */
54         stw     %r29,-16(%sp)
55         /* Save argument registers */
56         stw     %r26,-36(%sp)
57         stw     %r25,-40(%sp)
58         stw     %r24,-44(%sp)
59         stw     %r23,-48(%sp)
61         /* Build a call frame, and save structure pointer. */
62         copy    %sp, %r1        /* Copy previous sp */
63         /* Save function result address (on entry) */
64         stwm    %r28,128(%sp)
65         /* Fillin some frame info to follow ABI */
66         stw     %r1,-4(%sp)     /* Previous sp */
67         stw     %r21,-32(%sp)   /* PIC register value */
69         /* Save input floating point registers. This must be done
70            in the new frame since the previous frame doesn't have
71            enough space */
72         ldo     -56(%sp),%r1
73         fstd,ma %fr4,-8(%r1)
74         fstd,ma %fr5,-8(%r1)
75         fstd,ma %fr6,-8(%r1)
76         fstd,ma %fr7,-8(%r1)
78         /* Set up args to fixup func, needs only two arguments  */
79         ldw     8+4(%r20),%r26          /* (1) got[1] == struct link_map */
80         copy    %r19,%r25               /* (2) reloc offset  */
82         /* Call the real address resolver. */
83         bl      _dl_fixup,%rp
84         copy    %r21,%r19               /* set fixup func ltp */
86         /* Load up the returned func descriptor */
87         copy    %r28, %r22
88         copy    %r29, %r19
90         /* Reload arguments fp args */
91         ldo     -56(%sp),%r1
92         fldd,ma -8(%r1),%fr4
93         fldd,ma -8(%r1),%fr5
94         fldd,ma -8(%r1),%fr6
95         fldd,ma -8(%r1),%fr7
97         /* Adjust sp, and restore function result address*/
98         ldwm    -128(%sp),%r28
100         /* Reload static link register */
101         ldw     -16(%sp),%r29
102         /* Reload general args */
103         ldw     -36(%sp),%r26
104         ldw     -40(%sp),%r25
105         ldw     -44(%sp),%r24
106         ldw     -48(%sp),%r23
108         /* Jump to new function, but return to previous function */
109         bv      %r0(%r22)
110         ldw     -20(%sp),%rp
111         .EXIT
112         .PROCEND
113         cfi_endproc
114         .size   _dl_runtime_resolve, . - _dl_runtime_resolve
116         .text
117         .global _dl_runtime_profile
118         .type _dl_runtime_profile,@function
119         cfi_startproc
120         .align 4
121 _dl_runtime_profile:
122         .PROC
123         .CALLINFO FRAME=192,CALLS,SAVE_RP,ENTRY_GR=3
124         .ENTRY
126         /* SAVE_RP says we do */
127         stw     %rp, -20(%sp)
128         /* Save static link register */
129         stw     %r29,-16(%sp)
131         /* Build a call frame, and save structure pointer. */
132         copy    %sp, %r1        /* Copy previous sp */
133         /* Save function result address (on entry) */
134         stwm    %r28,192(%sp)
135         /* Fillin some frame info to follow ABI */
136         stw     %r1,-4(%sp)     /* Previous sp */
137         stw     %r21,-32(%sp)   /* PIC register value */
139         /* Create La_hppa_retval */
140         /* -140, lrv_r28 
141            -136, lrv_r29
142            -132, 4 byte pad 
143            -128, lr_fr4 (8 bytes) */
145         /* Create save space for _dl_profile_fixup arguments
146            -120, Saved reloc offset 
147            -116, Saved struct link_map 
148            -112, *framesizep */
150         /* Create La_hppa_regs */
151         /* 32-bit registers */
152         stw     %r26,-108(%sp)
153         stw     %r25,-104(%sp)
154         stw     %r24,-100(%sp)
155         stw     %r23,-96(%sp)
156         /* -92, 4 byte pad */
157         /* 64-bit floating point registers */
158         ldo     -88(%sp),%r1
159         fstd,ma %fr4,8(%r1)
160         fstd,ma %fr5,8(%r1)
161         fstd,ma %fr6,8(%r1)
162         fstd,ma %fr7,8(%r1)
163         /* 32-bit stack pointer and return register */
164         stw     %sp,-56(%sp)
165         stw     %r2,-52(%sp)
168         /* Set up args to fixup func, needs five arguments  */
169         ldw     8+4(%r20),%r26          /* (1) got[1] == struct link_map */
170         stw     %r26,-116(%sp)          /* Save struct link_map */
171         copy    %r19,%r25               /* (2) reloc offset  */
172         stw     %r25,-120(%sp)          /* Save reloc offset */
173         copy    %rp,%r24                /* (3) profile_fixup needs rp */
174         ldo     -56(%sp),%r23           /* (4) La_hppa_regs */
175         ldo     -112(%sp), %r1
176         stw     %r1, -52(%sp)           /* (5) long int *framesizep */
178         /* Call the real address resolver. */
179         bl      _dl_profile_fixup,%rp
180         copy    %r21,%r19               /* set fixup func ltp */
182         /* Load up the returned function descriptor */
183         copy    %r28, %r22
184         copy    %r29, %r19
186         /* Restore gr/fr/sp/rp */
187         ldw     -108(%sp),%r26
188         ldw     -104(%sp),%r25
189         ldw     -100(%sp),%r24
190         ldw     -96(%sp),%r23
191         /* -92, 4 byte pad, skip */
192         ldo     -88(%sp),%r1
193         fldd,ma 8(%r1),%fr4
194         fldd,ma 8(%r1),%fr5
195         fldd,ma 8(%r1),%fr6
196         fldd,ma 8(%r1),%fr7
197         ldw     -52(%sp),%rp
199         /* Reload static link register -(192+16) without adjusting stack */
200         ldw     -208(%sp),%r29
202         /* *framesizep is >= 0 if we have to run pltexit */
203         ldw     -112(%sp),%r28
204         cmpb,>>=,N %r0,%r28,L(cpe)
206         /* Adjust sp, and restore function result address*/
207         ldwm    -192(%sp),%r28
208         /* Jump to new function, but return to previous function */
209         bv      %r0(%r22)
210         ldw     -20(%sp),%rp
211         /* NO RETURN */
213 L(nf):
214         /* Call the returned function descriptor */
215         bv      %r0(%r22)
216         nop
217         b,n     L(cont)
219 L(cpe):
220         /* We are going to call the resolved function, but we have a 
221            stack frame in the middle. We use the value of framesize to
222            guess how much extra frame we need, and how much frame to
223            copy forward. */
225         /* Round to nearest multiple of 64 */
226         addi    63, %r28, %r28
227         depi    0, 27, 6, %r28
229         /* Calcualte start of stack copy */
230         ldo     -192(%sp),%r2
232         /* Increate the stack by *framesizep */
233         copy    %sp, %r1
234         add     %sp, %r28, %sp
235         /* Save stack pointer */
236         stw     %r1, -4(%sp)
238         /* Single byte copy of prevous stack onto newly allocated stack */
239 1:      ldb     %r28(%r2), %r1
240         add     %r28, %sp, %r26
241         stb     %r1, 0(%r26)
242         addi,<  -1,%r28,%r28
243         b,n     1b
245         /* Retore r28 and r27 and r2 already points at -192(%sp) */
246         ldw     0(%r2),%r28
247         ldw     84(%r2),%r26
249         /* Calculate address of L(cont) */
250         b,l     L(nf),%r2
251         depwi 0,31,2,%r2
252 L(cont):
253         /* Undo fake stack */
254         ldw     -4(%sp),%r1
255         copy    %r1, %sp
257         /* Arguments to _dl_call_pltexit */
258         ldw     -116(%sp), %r26         /* (1) got[1] == struct link_map */ 
259         ldw     -120(%sp), %r25         /* (2) reloc offsets */
260         ldo     -56(%sp), %r24          /* (3) *La_hppa_regs */
261         ldo     -124(%sp), %r23         /* (4) *La_hppa_retval */
263         /* Fill *La_hppa_retval */
264         stw     %r28,-140(%sp)
265         stw     %r29,-136(%sp)
266         ldo     -128(%sp), %r1
267         fstd    %fr4,0(%r1)
269         /* Call _dl_call_pltexit */
270         bl      _dl_call_pltexit,%rp
271         nop
273         /* Restore *La_hppa_retval */
274         ldw     -140(%sp), %r28
275         ldw     -136(%sp), %r29
276         ldo     -128(%sp), %r1
277         fldd    0(%r1), %fr4
279         /* Unwind the stack */
280         ldo     192(%sp),%sp
281         /* Retore callers rp */
282         ldw -20(%sp),%rp
283         /* Return */
284         bv,n    0(%r2)
285         .EXIT
286         .PROCEND
287         cfi_endproc
288         .size   _dl_runtime_profile, . - _dl_runtime_profile