2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-32 / dl-trampoline.S
blobfbbbc189dbb188b4d86c2f401961ed4bb9f4e0bd
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 /* This code is used in dl-runtime.c to call the `fixup' function
21    and then redirect to the address it returns.  */
23 /* The PLT stubs will call _dl_runtime_resolve/_dl_runtime_profile
24  * with the following linkage:
25  *   r2 - r6 : parameter registers
26  *   f0, f2 : floating point parameter registers
27  *   24(r15), 28(r15) : PLT arguments PLT1, PLT2
28  *   96(r15) : additional stack parameters
29  * The normal clobber rules for function calls apply:
30  *   r0 - r5 : call clobbered
31  *   r6 - r13 :  call saved
32  *   r14 : return address (call clobbered)
33  *   r15 : stack pointer (call saved)
34  *   f4, f6 : call saved
35  *   f0 - f3, f5, f7 - f15 : call clobbered
36  */
38 #include <sysdep.h>
40         .text
41         .globl _dl_runtime_resolve
42         .type _dl_runtime_resolve, @function
43         cfi_startproc
44         .align 16
45 _dl_runtime_resolve:
46         stm    %r2,%r5,32(%r15)         # save registers
47         st     %r14,8(%r15)
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         lr     %r12,%r15                # create stack frame
80         cfi_def_cfa_register (12)
81         ahi    %r15,-96
82         st     %r12,0(%r15)
83         lm     %r2,%r3,24(%r12)         # load arguments saved by PLT
84         lr     %r4,%r14                 # return address as third parameter
85         basr   %r1,0
86 0:      l      %r14,6f-0b(%r1)
87         la     %r5,32(%r12)             # pointer to struct La_s390_32_regs
88         la     %r6,20(%r12)             # long int * framesize
89         bas    %r14,0(%r14,%r1)         # call resolver
90         lr     %r1,%r2                  # function addr returned in r2
91         icm    %r0,15,20(%r12)          # load & test framesize
92         jnm    2f
93         lm     %r2,%r6,32(%r12)
94         ld     %f0,56(%r12)
95         ld     %f2,64(%r12)
96         basr   %r14,%r1                 # call resolved function
97 1:      lr     %r15,%r12                # remove stack frame
98         cfi_def_cfa_register (15)
99         l      %r14,16(%r15)            # restore registers
100         l      %r12,12(%r15)
101         l      %r6,8(%r15)
102         br     %r14
103         cfi_def_cfa_register (12)
104 2:      jz     4f                       # framesize == 0 ?
105         ahi    %r0,7                    # align framesize to 8
106         lhi    %r2,-8
107         nr     %r0,%r2
108         slr    %r15,%r0                 # make room for framesize bytes
109         st     %r12,0(%r15)
110         la     %r2,96(%r15)
111         la     %r3,96(%r12)
112         srl    %r0,3
113 3:      mvc    0(8,%r2),0(%r3)          # copy additional parameters
114         la     %r2,8(%r2)
115         la     %r3,8(%r3)
116         brct   %r0,3b
117 4:      lm     %r2,%r6,32(%r12)         # load register parameters
118         ld     %f0,56(%r12)
119         ld     %f2,64(%r12)
120         basr   %r14,%r1                 # call resolved function
121         stm    %r2,%r3,72(%r12)
122         std    %f0,80(%r12)
123         lm     %r2,%r3,24(%r12)         # load arguments saved by PLT
124         basr   %r1,0
125 5:      l      %r14,7f-5b(%r1)
126         la     %r4,32(%r12)             # pointer to struct La_s390_32_regs
127         la     %r5,72(%r12)             # pointer to struct La_s390_32_retval
128         basr   %r14,%r1                 # call _dl_call_pltexit
129         j      1b
130 6:      .long  _dl_profile_fixup - 0b
131 7:      .long  _dl_call_pltexit - 5b
132         cfi_endproc
133         .size _dl_runtime_profile, .-_dl_runtime_profile
134 #endif