f85527f4c4fb1327f75130e0834fbb9457d3f2c3
[platform/upstream/glibc.git] / sysdeps / sparc / sparc64 / dl-trampoline.S
1 /* PLT trampolines.  Sparc 64-bit version.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
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.  */
19
20 #include <sysdep.h>
21
22         .text
23         .align  32
24
25         /* %g1: PLT offset loaded by PLT entry
26          * %g4: callers PC, which is PLT0 + 24, therefore we
27          *      add (32 + 8) to get the address of PLT2 which
28          *      is where the magic cookie is stored
29          */
30         .globl  _dl_runtime_resolve_0
31         .type   _dl_runtime_resolve_0, @function
32 _dl_runtime_resolve_0:
33         save    %sp, -192, %sp
34         sethi   %hi(1047552), %l2
35         ldx     [%g4 + 32 + 8], %o0
36         sub     %g1, %g4, %l0
37         xor     %l2, -1016, %l2
38         sethi   %hi(5120), %l3  /* 160 * 32 */
39         add     %l0, %l2, %l0
40         sethi   %hi(32768), %l4
41         udivx   %l0, %l3, %l3
42         sllx    %l3, 2, %l1
43         add     %l1, %l3, %l1
44         sllx    %l1, 10, %l2
45         sub     %l4, 4, %l4
46         sllx    %l1, 5, %l1
47         sub     %l0, %l2, %l0
48         udivx   %l0, 24, %l0
49         add     %l0, %l4, %l0
50         add     %l1, %l0, %l1
51         add     %l1, %l1, %l0
52         add     %l0, %l1, %l0
53         call    _dl_fixup
54          sllx    %l0, 3, %o1
55         jmp     %o0
56          restore
57         .size   _dl_runtime_resolve_0, .-_dl_runtime_resolve_0
58
59         /* %g1: PLT offset loaded by PLT entry
60          * %g4: callers PC, which is PLT1 + 24, therefore we
61          *      add 8 to get the address of PLT2 which
62          *      is where the magic cookie is stored
63          */
64         .globl  _dl_runtime_resolve_1
65         .type   _dl_runtime_resolve_1, @function
66 _dl_runtime_resolve_1:
67         save    %sp, -192, %sp
68         srlx    %g1, 12, %o1
69         ldx     [%g4 + 8], %o0
70         add     %o1, %o1, %o3
71         sub     %o1, 96, %o1
72         call    _dl_fixup
73          add    %o1, %o3, %o1
74         jmp     %o0
75          restore
76         .size   _dl_runtime_resolve_1, .-_dl_runtime_resolve_1
77
78         /* For the profiling cases we pass in our stack frame
79          * as the base of the La_sparc64_regs, so it looks
80          * like:
81          *      %l0                     %sp
82          *      ...
83          *      %l7                     %sp + (7 * 8)
84          *      %i0                     %sp + (8 * 8)
85          *      ...
86          *      %i7                     %sp + (15 * 8)
87          *      %f0                     %sp + (16 * 8)
88          *      %f16                    %sp + (31 * 8)
89          *      framesize               %sp + (32 * 8)
90          */
91
92         .globl  _dl_profile_save_regs
93         .type   _dl_profile_save_regs, @function
94 _dl_profile_save_regs:
95         stx     %l0, [%sp + STACK_BIAS + ( 0 * 8)]
96         stx     %l1, [%sp + STACK_BIAS + ( 1 * 8)]
97         stx     %l2, [%sp + STACK_BIAS + ( 2 * 8)]
98         stx     %l3, [%sp + STACK_BIAS + ( 3 * 8)]
99         stx     %l4, [%sp + STACK_BIAS + ( 4 * 8)]
100         stx     %l5, [%sp + STACK_BIAS + ( 5 * 8)]
101         stx     %l6, [%sp + STACK_BIAS + ( 6 * 8)]
102         stx     %l7, [%sp + STACK_BIAS + ( 7 * 8)]
103         stx     %i0, [%sp + STACK_BIAS + ( 8 * 8)]
104         stx     %i1, [%sp + STACK_BIAS + ( 9 * 8)]
105         stx     %i2, [%sp + STACK_BIAS + (10 * 8)]
106         stx     %i3, [%sp + STACK_BIAS + (11 * 8)]
107         stx     %i4, [%sp + STACK_BIAS + (12 * 8)]
108         stx     %i5, [%sp + STACK_BIAS + (13 * 8)]
109         stx     %i6, [%sp + STACK_BIAS + (14 * 8)]
110         stx     %i7, [%sp + STACK_BIAS + (15 * 8)]
111         std     %f0, [%sp + STACK_BIAS + (16 * 8)]
112         std     %f2, [%sp + STACK_BIAS + (17 * 8)]
113         std     %f4, [%sp + STACK_BIAS + (18 * 8)]
114         std     %f6, [%sp + STACK_BIAS + (19 * 8)]
115         std     %f8, [%sp + STACK_BIAS + (20 * 8)]
116         std     %f10, [%sp + STACK_BIAS + (21 * 8)]
117         std     %f12, [%sp + STACK_BIAS + (22 * 8)]
118         std     %f14, [%sp + STACK_BIAS + (23 * 8)]
119         std     %f16, [%sp + STACK_BIAS + (24 * 8)]
120         std     %f18, [%sp + STACK_BIAS + (25 * 8)]
121         std     %f20, [%sp + STACK_BIAS + (26 * 8)]
122         std     %f22, [%sp + STACK_BIAS + (27 * 8)]
123         std     %f24, [%sp + STACK_BIAS + (28 * 8)]
124         std     %f26, [%sp + STACK_BIAS + (29 * 8)]
125         std     %f28, [%sp + STACK_BIAS + (30 * 8)]
126         retl
127          std    %f30, [%sp + STACK_BIAS + (31 * 8)]
128         .size   _dl_profile_save_regs, .-_dl_profile_save_regs
129
130         /* If we are going to call pltexit, then we must replicate
131          * the caller's stack frame.
132          * %o0: PLT resolved function address
133          */
134         .globl  _dl_profile_invoke
135         .type   _dl_profile_invoke, @function
136 _dl_profile_invoke:
137         sub     %sp, %l0, %sp
138 1:
139         srlx    %l0, 3, %l7
140         mov     %o0, %l1
141         mov     %i0, %o0
142         mov     %i1, %o1
143         mov     %i2, %o2
144         mov     %i3, %o3
145         mov     %i4, %o4
146         mov     %i5, %o5
147         add     %fp, STACK_BIAS, %l2
148         add     %sp, STACK_BIAS, %l3
149 1:      ldx     [%l2], %l4
150         add     %l2, 0x8, %l2
151         subcc   %l7, 1, %l7
152         stx     %l4, [%l3]
153         bne,pt  %xcc, 1b
154          add    %l3, 0x8, %l3
155
156         jmpl    %l1, %o7
157          nop
158
159         stx     %o0, [%sp + STACK_BIAS + (16 * 8)]
160         stx     %o1, [%sp + STACK_BIAS + (17 * 8)]
161         stx     %o2, [%sp + STACK_BIAS + (18 * 8)]
162         stx     %o3, [%sp + STACK_BIAS + (19 * 8)]
163         std     %f0, [%sp + STACK_BIAS + (20 * 8)]
164         std     %f2, [%sp + STACK_BIAS + (21 * 8)]
165         std     %f4, [%sp + STACK_BIAS + (22 * 8)]
166         std     %f8, [%sp + STACK_BIAS + (23 * 8)]
167
168         mov     %l5, %o0
169         mov     %l6, %o1
170         add     %sp, %l0, %o2
171         add     %sp, STACK_BIAS + (16 * 8), %o3
172         call    _dl_call_pltexit
173          add    %o2, STACK_BIAS, %o2
174
175         ldx     [%sp + STACK_BIAS + (16 * 8)], %i0
176         ldx     [%sp + STACK_BIAS + (17 * 8)], %i1
177         ldx     [%sp + STACK_BIAS + (18 * 8)], %i2
178         ldx     [%sp + STACK_BIAS + (19 * 8)], %i3
179
180         jmpl    %i7 + 8, %g0
181          restore
182
183         /* %g1: PLT offset loaded by PLT entry
184          * %g4: callers PC, which is PLT0 + 24, therefore we
185          *      add (32 + 8) to get the address of PLT2 which
186          *      is where the magic cookie is stored
187          */
188         .align  32
189         .globl  _dl_runtime_profile_0
190         .type   _dl_runtime_profile_0, @function
191 _dl_runtime_profile_0:
192         brz,a,pn %fp, 1f
193          mov    192, %g5
194         sub     %fp, %sp, %g5
195 1:      save    %sp, -336, %sp
196         sethi   %hi(1047552), %l2
197         ldx     [%g4 + 32 + 8], %o0
198         sub     %g1, %g4, %l0
199         xor     %l2, -1016, %l2
200         sethi   %hi(5120), %l3  /* 160 * 32 */
201         add     %l0, %l2, %l0
202         sethi   %hi(32768), %l4
203         udivx   %l0, %l3, %l3
204         sllx    %l3, 2, %l1
205         add     %l1, %l3, %l1
206         sllx    %l1, 10, %l2
207         sub     %l4, 4, %l4
208         sllx    %l1, 5, %l1
209         sub     %l0, %l2, %l0
210         udivx   %l0, 24, %l0
211         add     %l0, %l4, %l0
212         add     %l1, %l0, %l1
213         add     %l1, %l1, %l0
214         add     %l0, %l1, %l0
215
216         mov     %i7, %o2
217         sllx    %l0, 3, %o1
218
219         mov     %g5, %l0
220         mov     %o0, %l5
221         mov     %o1, %l6
222
223         call    _dl_profile_save_regs
224          nop
225
226         add     %sp, STACK_BIAS, %o3
227         call    _dl_profile_fixup
228          add    %sp, (STACK_BIAS + (32 * 8)), %o4
229
230         ldx     [%sp + STACK_BIAS + (32 * 8)], %o1
231         brgez,pt %o1, 1f
232          nop
233
234         call    _dl_profile_invoke
235          nop
236
237 1:      jmp     %o0
238          restore
239         .size   _dl_runtime_profile_0, .-_dl_runtime_profile_0
240
241         /* %g1: PLT offset loaded by PLT entry
242          * %g4: callers PC, which is PLT1 + 24, therefore we
243          *      add 8 to get the address of PLT2 which
244          *      is where the magic cookie is stored
245          */
246         .globl  _dl_runtime_profile_1
247         .type   _dl_runtime_profile_1, @function
248 _dl_runtime_profile_1:
249         brz,a,pn %fp, 1f
250          mov    192, %g5
251         sub     %fp, %sp, %g5
252 1:      save    %sp, -336, %sp
253         srlx    %g1, 12, %o1
254         ldx     [%g4 + 8], %o0
255         add     %o1, %o1, %o3
256         sub     %o1, 96, %o1
257         mov     %i7, %o2
258         add     %o1, %o3, %o1
259
260         mov     %g5, %l0
261         mov     %o0, %l5
262         mov     %o1, %l6
263
264         call    _dl_profile_save_regs
265          nop
266
267         add     %sp, STACK_BIAS, %o3
268         call    _dl_profile_fixup
269          add    %sp, (STACK_BIAS + (32 * 8)), %o4
270
271         ldx     [%sp + STACK_BIAS + (32 * 8)], %o1
272         brgez,pt %o1, 1f
273          nop
274
275         call    _dl_profile_invoke
276          nop
277
278 1:      jmp     %o0
279          restore
280         .size   _dl_runtime_resolve_1, .-_dl_runtime_resolve_1