Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / s390 / s390-64 / dl-trampoline.S
blob87c6d50ced84a0ebc572faaf67a780ec3a461746
1 /* PLT trampolines.  s390x 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 /* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
20  * with the following linkage:
21  *   r2 - r6 : parameter registers
22  *   f0, f2, f4, f6 : floating point parameter registers
23  *   48(r15), 56(r15) : PLT arguments PLT1, PLT2
24  *   160(r15) : additional stack parameters
25  * The normal clobber rules for function calls apply:
26  *   r0 - r5 : call clobbered
27  *   r6 - r13 :  call saved
28  *   r14 : return address (call clobbered)
29  *   r15 : stack pointer (call saved)
30  *   f1, f3, f5, f7 : call saved
31  *   f0 - f3, f5, f7 - f15 : call clobbered
32  */
34 #include <sysdep.h>
36         .text
37         .globl _dl_runtime_resolve
38         .type _dl_runtime_resolve, @function
39         cfi_startproc
40         .align 16
41 _dl_runtime_resolve:
42         stmg   %r2,%r5,64(15)   # save call-clobbered argument registers
43         stg    %r14,96(15)
44         cfi_offset (r14, -64)
45         lgr    %r0,%r15
46         aghi   %r15,-160        # create stack frame
47         cfi_adjust_cfa_offset (160)
48         stg    %r0,0(%r15)      # write backchain
49         lmg    %r2,%r3,208(%r15)# load args saved by PLT
50         brasl  %r14,_dl_fixup   # call fixup
51         lgr    %r1,%r2          # function addr returned in r2
52         aghi   %r15,160         # remove stack frame
53         cfi_adjust_cfa_offset (-160)
54         lg     %r14,96(15)      # restore registers
55         lmg    %r2,%r5,64(15)
56         br     %r1
57         cfi_endproc
58         .size _dl_runtime_resolve, .-_dl_runtime_resolve
61 #ifndef PROF
62         .globl _dl_runtime_profile
63         .type _dl_runtime_profile, @function
64         cfi_startproc
65         .align 16
66 _dl_runtime_profile:
67         stmg   %r2,%r6,64(%r15)         # save call-clobbered arg regs
68         std    %f0,104(%r15)            # + r6 needed as arg for
69         std    %f2,112(%r15)            #  _dl_profile_fixup
70         std    %f4,120(%r15)
71         std    %f6,128(%r15)
72         stg    %r12,24(%r15)            # r12 is used as backup of r15
73         stg    %r14,32(%r15)
74         cfi_offset (r6, -96)
75         cfi_offset (f0, -56)
76         cfi_offset (f2, -48)
77         cfi_offset (f4, -40)
78         cfi_offset (f6, -32)
79         cfi_offset (r12, -136)
80         cfi_offset (r14, -128)
81         lgr    %r12,%r15                # backup stack pointer
82         cfi_def_cfa_register (12)
83         aghi   %r15,-160                # create stack frame
84         stg    %r12,0(%r15)             # save backchain
85         lmg    %r2,%r3,48(%r12)         # load arguments saved by PLT
86         lgr    %r4,%r14                 # return address as third parameter
87         la     %r5,64(%r12)             # pointer to struct La_s390_32_regs
88         la     %r6,40(%r12)             # long int * framesize
89         brasl  %r14,_dl_profile_fixup   # call resolver
90         lgr    %r1,%r2                  # function addr returned in r2
91         lg     %r0,40(%r12)             # load framesize
92         ltgr   %r0,%r0
93         jnm    1f
95         lmg    %r2,%r6,64(%r12)         # framesize < 0 means no pltexit call
96         ld     %f0,104(%r12)            # so we can do a tail call without
97         ld     %f2,112(%r12)            # copying the arg overflow area
98         ld     %f4,120(%r12)
99         ld     %f6,128(%r12)
101         lgr    %r15,%r12                # remove stack frame
102         cfi_def_cfa_register (15)
103         lg     %r14,32(%r15)            # restore registers
104         lg     %r12,24(%r15)
105         br     %r1                      # tail-call to resolved function
107         cfi_def_cfa_register (12)
108 1:      jz     4f                       # framesize == 0 ?
109         aghi   %r0,7                    # align framesize to 8
110         nill   %r0,0xfff8
111         slgr   %r15,%r0                 # make room for framesize bytes
112         stg    %r12,0(%r15)
113         la     %r2,160(%r15)
114         la     %r3,160(%r12)
115         srlg   %r0,%r0,3
116 3:      mvc    0(8,%r2),0(%r3)          # copy additional parameters
117         la     %r2,8(%r2)
118         la     %r3,8(%r3)
119         brctg  %r0,3b
120 4:      lmg    %r2,%r6,64(%r12)         # load register parameters
121         ld     %f0,104(%r12)            # restore call-clobbered arg regs
122         ld     %f2,112(%r12)
123         ld     %f4,120(%r12)
124         ld     %f6,128(%r12)
125         basr   %r14,%r1                 # call resolved function
126         stg    %r2,136(%r12)
127         std    %f0,144(%r12)
128         lmg    %r2,%r3,48(%r12)         # load arguments saved by PLT
129         la     %r4,32(%r12)             # pointer to struct La_s390_32_regs
130         la     %r5,72(%r12)             # pointer to struct La_s390_32_retval
131         brasl  %r14,_dl_call_pltexit
133         lgr    %r15,%r12                # remove stack frame
134         cfi_def_cfa_register (15)
135         lg     %r14,32(%r15)            # restore registers
136         lg     %r12,24(%r15)
137         br     %r14
139         cfi_endproc
140         .size _dl_runtime_profile, .-_dl_runtime_profile
141 #endif