Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / sparc / sparc64 / dl-trampoline.S
blobc57b0faace514430c7a9bc7f0796bd6ea7f25225
1 /* PLT trampolines.  Sparc 64-bit version.
2    Copyright (C) 2005-2014 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, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21         .text
22         .align  32
24         /* %g1: PLT offset loaded by PLT entry
25          * %g4: callers PC, which is PLT0 + 24, therefore we
26          *      add (32 + 8) to get the address of PLT2 which
27          *      is where the magic cookie is stored
28          */
29         .globl  _dl_runtime_resolve_0
30         .type   _dl_runtime_resolve_0, @function
31 _dl_runtime_resolve_0:
32         cfi_startproc
34         save    %sp, -192, %sp
35         cfi_def_cfa_register(%fp)
36         cfi_window_save
37         cfi_register(%o7, %i7)
39         sethi   %hi(1047552), %l2
40         ldx     [%g4 + 32 + 8], %o0
41         sub     %g1, %g4, %l0
42         xor     %l2, -1016, %l2
43         sethi   %hi(5120), %l3  /* 160 * 32 */
44         add     %l0, %l2, %l0
45         sethi   %hi(32768), %l4
46         udivx   %l0, %l3, %l3
47         sllx    %l3, 2, %l1
48         add     %l1, %l3, %l1
49         sllx    %l1, 10, %l2
50         sub     %l4, 4, %l4
51         sllx    %l1, 5, %l1
52         sub     %l0, %l2, %l0
53         udivx   %l0, 24, %l0
54         add     %l0, %l4, %l0
55         add     %l1, %l0, %l1
56         add     %l1, %l1, %l0
57         add     %l0, %l1, %l0
58         call    _dl_fixup
59          sllx    %l0, 3, %o1
60         jmp     %o0
61          restore
63         cfi_endproc
65         .size   _dl_runtime_resolve_0, .-_dl_runtime_resolve_0
67         /* %g1: PLT offset loaded by PLT entry
68          * %g4: callers PC, which is PLT1 + 24, therefore we
69          *      add 8 to get the address of PLT2 which
70          *      is where the magic cookie is stored
71          */
72         .globl  _dl_runtime_resolve_1
73         .type   _dl_runtime_resolve_1, @function
74 _dl_runtime_resolve_1:
75         cfi_startproc
77         save    %sp, -192, %sp
78         cfi_def_cfa_register(%fp)
79         cfi_window_save
80         cfi_register(%o7, %i7)
82         srlx    %g1, 12, %o1
83         ldx     [%g4 + 8], %o0
84         add     %o1, %o1, %o3
85         sub     %o1, 96, %o1
86         call    _dl_fixup
87          add    %o1, %o3, %o1
88         jmp     %o0
89          restore
91         cfi_endproc
93         .size   _dl_runtime_resolve_1, .-_dl_runtime_resolve_1
95         /* For the profiling cases we pass in our stack frame
96          * as the base of the La_sparc64_regs, so it looks
97          * like:
98          *      %l0                     %sp
99          *      ...
100          *      %l7                     %sp + (7 * 8)
101          *      %i0                     %sp + (8 * 8)
102          *      ...
103          *      %i7                     %sp + (15 * 8)
104          *      %f0                     %sp + (16 * 8)
105          *      %f16                    %sp + (31 * 8)
106          *      framesize               %sp + (32 * 8)
107          */
109         .globl  _dl_profile_save_regs
110         .type   _dl_profile_save_regs, @function
111 _dl_profile_save_regs:
112         cfi_startproc
114         stx     %l0, [%sp + STACK_BIAS + ( 0 * 8)]
115         stx     %l1, [%sp + STACK_BIAS + ( 1 * 8)]
116         stx     %l2, [%sp + STACK_BIAS + ( 2 * 8)]
117         stx     %l3, [%sp + STACK_BIAS + ( 3 * 8)]
118         stx     %l4, [%sp + STACK_BIAS + ( 4 * 8)]
119         stx     %l5, [%sp + STACK_BIAS + ( 5 * 8)]
120         stx     %l6, [%sp + STACK_BIAS + ( 6 * 8)]
121         stx     %l7, [%sp + STACK_BIAS + ( 7 * 8)]
122         stx     %i0, [%sp + STACK_BIAS + ( 8 * 8)]
123         stx     %i1, [%sp + STACK_BIAS + ( 9 * 8)]
124         stx     %i2, [%sp + STACK_BIAS + (10 * 8)]
125         stx     %i3, [%sp + STACK_BIAS + (11 * 8)]
126         stx     %i4, [%sp + STACK_BIAS + (12 * 8)]
127         stx     %i5, [%sp + STACK_BIAS + (13 * 8)]
128         stx     %i6, [%sp + STACK_BIAS + (14 * 8)]
129         stx     %i7, [%sp + STACK_BIAS + (15 * 8)]
130         std     %f0, [%sp + STACK_BIAS + (16 * 8)]
131         std     %f2, [%sp + STACK_BIAS + (17 * 8)]
132         std     %f4, [%sp + STACK_BIAS + (18 * 8)]
133         std     %f6, [%sp + STACK_BIAS + (19 * 8)]
134         std     %f8, [%sp + STACK_BIAS + (20 * 8)]
135         std     %f10, [%sp + STACK_BIAS + (21 * 8)]
136         std     %f12, [%sp + STACK_BIAS + (22 * 8)]
137         std     %f14, [%sp + STACK_BIAS + (23 * 8)]
138         std     %f16, [%sp + STACK_BIAS + (24 * 8)]
139         std     %f18, [%sp + STACK_BIAS + (25 * 8)]
140         std     %f20, [%sp + STACK_BIAS + (26 * 8)]
141         std     %f22, [%sp + STACK_BIAS + (27 * 8)]
142         std     %f24, [%sp + STACK_BIAS + (28 * 8)]
143         std     %f26, [%sp + STACK_BIAS + (29 * 8)]
144         std     %f28, [%sp + STACK_BIAS + (30 * 8)]
145         retl
146          std    %f30, [%sp + STACK_BIAS + (31 * 8)]
148         cfi_endproc
150         .size   _dl_profile_save_regs, .-_dl_profile_save_regs
152         /* If we are going to call pltexit, then we must replicate
153          * the caller's stack frame.
154          * %o0: PLT resolved function address
155          */
156         .globl  _dl_profile_invoke
157         .type   _dl_profile_invoke, @function
158 _dl_profile_invoke:
159         cfi_startproc
161         add     %l0, 7, %l0
162         andn    %l0, 7, %l0
163         add     %l0, (8 * 8), %g1
165         sub     %sp, %g1, %sp
166         srlx    %l0, 3, %l7
167         mov     %o0, %l1
168         mov     %i0, %o0
169         mov     %i1, %o1
170         mov     %i2, %o2
171         mov     %i3, %o3
172         mov     %i4, %o4
173         mov     %i5, %o5
174         add     %fp, STACK_BIAS, %l2
175         brz     %l0, 2f
176          add    %sp, STACK_BIAS, %l3
177 1:      ldx     [%l2], %l4
178         add     %l2, 0x8, %l2
179         subcc   %l7, 1, %l7
180         stx     %l4, [%l3]
181         bne,pt  %xcc, 1b
182          add    %l3, 0x8, %l3
184 2:      jmpl    %l1, %o7
185          nop
187         stx     %o0, [%sp + STACK_BIAS + (16 * 8)]
188         stx     %o1, [%sp + STACK_BIAS + (17 * 8)]
189         stx     %o2, [%sp + STACK_BIAS + (18 * 8)]
190         stx     %o3, [%sp + STACK_BIAS + (19 * 8)]
191         std     %f0, [%sp + STACK_BIAS + (20 * 8)]
192         std     %f2, [%sp + STACK_BIAS + (21 * 8)]
193         std     %f4, [%sp + STACK_BIAS + (22 * 8)]
194         std     %f8, [%sp + STACK_BIAS + (23 * 8)]
196         mov     %l5, %o0
197         mov     %l6, %o1
198         add     %sp, STACK_BIAS + (24 * 8), %o2
199         call    _dl_call_pltexit
200          add    %sp, STACK_BIAS + (16 * 8), %o3
202         ldx     [%sp + STACK_BIAS + (16 * 8)], %i0
203         ldx     [%sp + STACK_BIAS + (17 * 8)], %i1
204         ldx     [%sp + STACK_BIAS + (18 * 8)], %i2
205         ldx     [%sp + STACK_BIAS + (19 * 8)], %i3
206         ldd     [%sp + STACK_BIAS + (20 * 8)], %f0
207         ldd     [%sp + STACK_BIAS + (21 * 8)], %f2
208         ldd     [%sp + STACK_BIAS + (22 * 8)], %f4
209         ldd     [%sp + STACK_BIAS + (23 * 8)], %f8
211         jmpl    %i7 + 8, %g0
212          restore
214         cfi_endproc
216         .size   _dl_profile_invoke, .-_dl_profile_invoke
218         /* %g1: PLT offset loaded by PLT entry
219          * %g4: callers PC, which is PLT0 + 24, therefore we
220          *      add (32 + 8) to get the address of PLT2 which
221          *      is where the magic cookie is stored
222          */
223         .align  32
224         .globl  _dl_runtime_profile_0
225         .type   _dl_runtime_profile_0, @function
226 _dl_runtime_profile_0:
227         cfi_startproc
229         save    %sp, -336, %sp
230         cfi_def_cfa_register(%fp)
231         cfi_window_save
232         cfi_register(%o7, %i7)
234         sethi   %hi(1047552), %l2
235         ldx     [%g4 + 32 + 8], %o0
236         sub     %g1, %g4, %l0
237         xor     %l2, -1016, %l2
238         sethi   %hi(5120), %l3  /* 160 * 32 */
239         add     %l0, %l2, %l0
240         sethi   %hi(32768), %l4
241         udivx   %l0, %l3, %l3
242         sllx    %l3, 2, %l1
243         add     %l1, %l3, %l1
244         sllx    %l1, 10, %l2
245         sub     %l4, 4, %l4
246         sllx    %l1, 5, %l1
247         sub     %l0, %l2, %l0
248         udivx   %l0, 24, %l0
249         add     %l0, %l4, %l0
250         add     %l1, %l0, %l1
251         add     %l1, %l1, %l0
252         add     %l0, %l1, %l0
254         mov     %i7, %o2
255         sllx    %l0, 3, %o1
257         mov     %o0, %l5
258         mov     %o1, %l6
260         call    _dl_profile_save_regs
261          nop
263         add     %sp, STACK_BIAS, %o3
264         call    _dl_profile_fixup
265          add    %sp, (STACK_BIAS + (32 * 8)), %o4
267         ldx     [%sp + STACK_BIAS + (32 * 8)], %l0
268         brlz,pt %l0, 1f
269          nop
271         call    _dl_profile_invoke
272          nop
274 1:      jmp     %o0
275          restore
277         cfi_endproc
279         .size   _dl_runtime_profile_0, .-_dl_runtime_profile_0
281         /* %g1: PLT offset loaded by PLT entry
282          * %g4: callers PC, which is PLT1 + 24, therefore we
283          *      add 8 to get the address of PLT2 which
284          *      is where the magic cookie is stored
285          */
286         .globl  _dl_runtime_profile_1
287         .type   _dl_runtime_profile_1, @function
288 _dl_runtime_profile_1:
289         cfi_startproc
291         save    %sp, -336, %sp
292         cfi_def_cfa_register(%fp)
293         cfi_window_save
294         cfi_register(%o7, %i7)
296         srlx    %g1, 12, %o1
297         ldx     [%g4 + 8], %o0
298         add     %o1, %o1, %o3
299         sub     %o1, 96, %o1
300         mov     %i7, %o2
301         add     %o1, %o3, %o1
303         mov     %o0, %l5
304         mov     %o1, %l6
306         call    _dl_profile_save_regs
307          nop
309         add     %sp, STACK_BIAS, %o3
310         call    _dl_profile_fixup
311          add    %sp, (STACK_BIAS + (32 * 8)), %o4
313         ldx     [%sp + STACK_BIAS + (32 * 8)], %l0
314         brlz,pt %l0, 1f
315          nop
317         call    _dl_profile_invoke
318          nop
320 1:      jmp     %o0
321          restore
323         cfi_endproc
325         .size   _dl_runtime_resolve_1, .-_dl_runtime_resolve_1