Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / s390 / s390-32 / dl-trampoline.S
blobd3a8548259c5423af202df4dbea16ddc5e05654d
1 /* PLT trampolines.  s390 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 /* This code is used in dl-runtime.c to call the `fixup' function
20    and then redirect to the address it returns.  */
22 /* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
23  * with the following linkage:
24  *   r2 - r6 : parameter registers
25  *   f0, f2 : floating point parameter registers
26  *   24(r15), 28(r15) : PLT arguments PLT1, PLT2
27  *   96(r15) : additional stack parameters
28  * The normal clobber rules for function calls apply:
29  *   r0 - r5 : call clobbered
30  *   r6 - r13 :  call saved
31  *   r14 : return address (call clobbered)
32  *   r15 : stack pointer (call saved)
33  *   f4, f6 : call saved
34  *   f0 - f3, f5, f7 - f15 : call clobbered
35  */
37 #include <sysdep.h>
39         .text
40         .globl _dl_runtime_resolve
41         .type _dl_runtime_resolve, @function
42         cfi_startproc
43         .align 16
44 _dl_runtime_resolve:
45         stm    %r2,%r5,32(%r15)         # save registers
46         st     %r14,8(%r15)
47         cfi_offset (r14, -88)
48         lr     %r0,%r15                 # create stack frame
49         ahi    %r15,-96
50         cfi_adjust_cfa_offset (96)
51         st     0,0(%r15)
52         lm     %r2,%r3,120(%r15)        # load args saved by PLT
53         basr   %r1,0
54 0:      l      %r14,1f-0b(%r1)
55         bas    %r14,0(%r14,%r1)         # call resolver
56         lr     %r1,%r2                  # function addr returned in r2
57         ahi    %r15,96                  # remove stack frame
58         cfi_adjust_cfa_offset (-96)
59         l      %r14,8(15)               # restore registers
60         lm     %r2,%r5,32(%r15)
61         br     %r1
62 1:      .long  _dl_fixup - 0b
63         cfi_endproc
64         .size _dl_runtime_resolve, .-_dl_runtime_resolve
67 #ifndef PROF
68         .globl _dl_runtime_profile
69         .type _dl_runtime_profile, @function
70         cfi_startproc
71         .align 16
72 _dl_runtime_profile:
73         stm    %r2,%r6,32(%r15)         # save registers
74         std    %f0,56(%r15)
75         std    %f2,64(%r15)
76         st     %r6,8(%r15)
77         st     %r12,12(%r15)
78         st     %r14,16(%r15)
79         cfi_offset (r6, -64)
80         cfi_offset (f0, -40)
81         cfi_offset (f2, -32)
82         cfi_offset (r12, -84)
83         cfi_offset (r14, -80)
84         lr     %r12,%r15                # create stack frame
85         cfi_def_cfa_register (12)
86         ahi    %r15,-96
87         st     %r12,0(%r15)
88         lm     %r2,%r3,24(%r12)         # load arguments saved by PLT
89         lr     %r4,%r14                 # return address as third parameter
90         basr   %r1,0
91 0:      l      %r14,6f-0b(%r1)
92         la     %r5,32(%r12)             # pointer to struct La_s390_32_regs
93         la     %r6,20(%r12)             # long int * framesize
94         bas    %r14,0(%r14,%r1)         # call resolver
95         lr     %r1,%r2                  # function addr returned in r2
96         icm    %r0,15,20(%r12)          # load & test framesize
97         jnm    2f
99         lm     %r2,%r6,32(%r12)
100         ld     %f0,56(%r12)
101         ld     %f2,64(%r12)
102         lr     %r15,%r12                # remove stack frame
103         cfi_def_cfa_register (15)
104         l      %r14,16(%r15)            # restore registers
105         l      %r12,12(%r15)
106         br     %r1                      # tail-call to the resolved function
108         cfi_def_cfa_register (12)
109 2:      jz     4f                       # framesize == 0 ?
110         ahi    %r0,7                    # align framesize to 8
111         lhi    %r2,-8
112         nr     %r0,%r2
113         slr    %r15,%r0                 # make room for framesize bytes
114         st     %r12,0(%r15)
115         la     %r2,96(%r15)
116         la     %r3,96(%r12)
117         srl    %r0,3
118 3:      mvc    0(8,%r2),0(%r3)          # copy additional parameters
119         la     %r2,8(%r2)
120         la     %r3,8(%r3)
121         brct   %r0,3b
122 4:      lm     %r2,%r6,32(%r12)         # load register parameters
123         ld     %f0,56(%r12)
124         ld     %f2,64(%r12)
125         basr   %r14,%r1                 # call resolved function
126         stm    %r2,%r3,72(%r12)
127         std    %f0,80(%r12)
128         lm     %r2,%r3,24(%r12)         # load arguments saved by PLT
129         basr   %r1,0
130 5:      l      %r14,7f-5b(%r1)
131         la     %r4,32(%r12)             # pointer to struct La_s390_32_regs
132         la     %r5,72(%r12)             # pointer to struct La_s390_32_retval
133         basr   %r14,%r1                 # call _dl_call_pltexit
135         lr     %r15,%r12                # remove stack frame
136         cfi_def_cfa_register (15)
137         l      %r14,16(%r15)            # restore registers
138         l      %r12,12(%r15)
139         br     %r14
141 6:      .long  _dl_profile_fixup - 0b
142 7:      .long  _dl_call_pltexit - 5b
143         cfi_endproc
144         .size _dl_runtime_profile, .-_dl_runtime_profile
145 #endif