2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-64 / dl-trampoline.S
blob72043c9779b4a1b817eb8102c3e7f8705890a76d
1 /* PLT trampolines.  s390 version.
2    Copyright (C) 2005 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 /* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
21  * with the following linkage:
22  *   r2 - r6 : parameter registers
23  *   f0, f2, f4, f6 : floating point parameter registers
24  *   24(r15), 28(r15) : PLT arguments PLT1, PLT2
25  *   96(r15) : additional stack parameters
26  * The normal clobber rules for function calls apply:
27  *   r0 - r5 : call clobbered
28  *   r6 - r13 :  call saved
29  *   r14 : return address (call clobbered)
30  *   r15 : stack pointer (call saved)
31  *   f1, f3, f5, f7 : call saved
32  *   f0 - f3, f5, f7 - f15 : call clobbered
33  */
35 #include <sysdep.h>
37         .text
38         .globl _dl_runtime_resolve
39         .type _dl_runtime_resolve, @function
40         cfi_startproc
41         .align 16
42 _dl_runtime_resolve:
43         stmg   2,5,64(15)       # save registers
44         stg    14,96(15)
45         lgr    0,15             # create stack frame
46         aghi   15,-160
47         cfi_adjust_cfa_offset (160)
48         stg    0,0(15)
49         lmg    2,3,208(15)      # load args saved by PLT
50         brasl  14,_dl_fixup     # call fixup
51         lgr    1,2              # function addr returned in r2
52         aghi   15,160           # remove stack frame
53         cfi_adjust_cfa_offset (-160)
54         lg     14,96(15)        # restore registers
55         lmg    2,5,64(15)
56         br     1
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 registers
68         std    %f0,104(%r15)
69         std    %f2,112(%r15)
70         std    %f4,120(%r15)
71         std    %f6,128(%r15)
72         stg    %r6,16(%r15)
73         stg    %r12,24(%r15)
74         stg    %r14,32(%r15)
75         lgr    %r12,%r15                # create stack frame
76         cfi_def_cfa_register (12)
77         aghi   %r15,-160
78         stg    %r12,0(%r15)
79         lmg    %r2,%r3,48(%r12)         # load arguments saved by PLT
80         lgr    %r4,%r14                 # return address as third parameter
81         la     %r5,64(%r12)             # pointer to struct La_s390_32_regs
82         la     %r6,40(%r12)             # long int * framesize
83         brasl  %r14,_dl_profile_fixup   # call resolver
84         lgr    %r1,%r2                  # function addr returned in r2
85         lg     %r0,40(%r12)             # load framesize
86         ltgr   %r0,%r0
87         jnm    1f
88         lmg    %r2,%r6,64(%r12)
89         ld     %f0,104(%r12)
90         ld     %f2,112(%r12)
91         ld     %f4,120(%r12)
92         ld     %f6,128(%r12)
93         basr   %r14,%r1                 # call resolved function
94 0:      lgr    %r15,%r12                # remove stack frame
95         cfi_def_cfa_register (15)
96         lg     %r14,32(%r15)            # restore registers
97         lg     %r12,24(%r15)
98         lg     %r6,16(%r15)
99         br     %r14
100         cfi_def_cfa_register (12)
101 1:      jz     4f                       # framesize == 0 ?
102         aghi   %r0,7                    # align framesize to 8
103         nill   %r0,0xfff8
104         slgr   %r15,%r0                 # make room for framesize bytes
105         stg    %r12,0(%r15)
106         la     %r2,160(%r15)
107         la     %r3,160(%r12)
108         srlg   %r0,%r0,3
109 3:      mvc    0(8,%r2),0(%r3)          # copy additional parameters
110         la     %r2,8(%r2)
111         la     %r3,8(%r3)
112         brctg  %r0,3b
113 4:      lmg    %r2,%r6,64(%r12)         # load register parameters
114         ld     %f0,104(%r12)
115         ld     %f2,112(%r12)
116         ld     %f4,120(%r12)
117         ld     %f6,128(%r12)
118         basr   %r14,%r1                 # call resolved function
119         stg    %r2,136(%r12)
120         std    %f0,144(%r12)
121         lmg    %r2,%r3,48(%r12)         # load arguments saved by PLT
122         la     %r4,32(%r12)             # pointer to struct La_s390_32_regs
123         la     %r5,72(%r12)             # pointer to struct La_s390_32_retval
124         brasl  %r14,_dl_call_pltexit
125         j      0b
126         cfi_endproc
127         .size _dl_runtime_profile, .-_dl_runtime_profile
128 #endif