Debian Codegraph @

src/s390/sysv.S

raw
1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 2000 Software AG
3 Copyright (c) 2008 Red Hat, Inc.
4
5 S390 Foreign Function Interface
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 ``Software''), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 ----------------------------------------------------------------------- */
27
28 #define LIBFFI_ASM
29 #include <fficonfig.h>
30 #include <ffi.h>
31 #include "internal.h"
32
33 .text
34
35 #ifndef __s390x__
36
37 # r2: frame
38 # r3: ret_type
39 # r4: ret_addr
40 # r5: fun
41 # r6: closure
42
43 # This assumes we are using gas.
44 .balign 8
45 .globl ffi_call_SYSV
46 FFI_HIDDEN(ffi_call_SYSV)
47 .type ffi_call_SYSV,%function
48 ffi_call_SYSV:
49 .cfi_startproc
50 st %r6,44(%r2) # Save registers
51 stm %r12,%r14,48(%r2)
52 lr %r13,%r2 # Install frame pointer
53 .cfi_rel_offset r6, 44
54 .cfi_rel_offset r12, 48
55 .cfi_rel_offset r13, 52
56 .cfi_rel_offset r14, 56
57 .cfi_def_cfa_register r13
58 st %r2,0(%r15) # Set up back chain
59 sla %r3,3 # ret_type *= 8
60 lr %r12,%r4 # Save ret_addr
61 lr %r1,%r5 # Save fun
62 lr %r0,%r6 # Install static chain
63
64 # Set return address, so that there is only one indirect jump.
65 #ifdef HAVE_AS_S390_ZARCH
66 larl %r14,.Ltable
67 ar %r14,%r3
68 #else
69 basr %r14,0
70 0: la %r14,.Ltable-0b(%r14,%r3)
71 #endif
72
73 lm %r2,%r6,8(%r13) # Load arguments
74 ld %f0,64(%r13)
75 ld %f2,72(%r13)
76 br %r1 # ... and call function
77
78 .balign 8
79 .Ltable:
80 # FFI390_RET_DOUBLE
81 std %f0,0(%r12)
82 j .Ldone
83
84 .balign 8
85 # FFI390_RET_FLOAT
86 ste %f0,0(%r12)
87 j .Ldone
88
89 .balign 8
90 # FFI390_RET_INT64
91 st %r3,4(%r12)
92 nop
93 # fallthru
94
95 .balign 8
96 # FFI390_RET_INT32
97 st %r2,0(%r12)
98 nop
99 # fallthru
100
101 .balign 8
102 # FFI390_RET_VOID
103 .Ldone:
104 l %r14,56(%r13)
105 l %r12,48(%r13)
106 l %r6,44(%r13)
107 l %r13,52(%r13)
108 .cfi_restore 14
109 .cfi_restore 13
110 .cfi_restore 12
111 .cfi_restore 6
112 .cfi_def_cfa r15, 96
113 br %r14
114 .cfi_endproc
115 .size ffi_call_SYSV,.-ffi_call_SYSV
116
117
118 .balign 8
119 .globl ffi_go_closure_SYSV
120 FFI_HIDDEN(ffi_go_closure_SYSV)
121 .type ffi_go_closure_SYSV,%function
122 ffi_go_closure_SYSV:
123 .cfi_startproc
124 stm %r2,%r6,8(%r15) # Save arguments
125 lr %r4,%r0 # Load closure -> user_data
126 l %r2,4(%r4) # ->cif
127 l %r3,8(%r4) # ->fun
128 j .Ldoclosure
129 .cfi_endproc
130
131 .balign 8
132 .globl ffi_closure_SYSV
133 FFI_HIDDEN(ffi_closure_SYSV)
134 .type ffi_closure_SYSV,%function
135 ffi_closure_SYSV:
136 .cfi_startproc
137 stm %r2,%r6,8(%r15) # Save arguments
138 lr %r4,%r0 # Closure
139 l %r2,16(%r4) # ->cif
140 l %r3,20(%r4) # ->fun
141 l %r4,24(%r4) # ->user_data
142 .Ldoclosure:
143 stm %r12,%r15,48(%r15) # Save registers
144 lr %r12,%r15
145 .cfi_def_cfa_register r12
146 .cfi_rel_offset r6, 24
147 .cfi_rel_offset r12, 48
148 .cfi_rel_offset r13, 52
149 .cfi_rel_offset r14, 56
150 .cfi_rel_offset r15, 60
151 #ifndef HAVE_AS_S390_ZARCH
152 basr %r13,0 # Set up base register
153 .Lcbase:
154 l %r1,.Lchelper-.Lcbase(%r13) # Get helper function
155 #endif
156 ahi %r15,-96-8 # Set up stack frame
157 st %r12,0(%r15) # Set up back chain
158
159 std %f0,64(%r12) # Save fp arguments
160 std %f2,72(%r12)
161
162 la %r5,96(%r12) # Overflow
163 st %r5,96(%r15)
164 la %r6,64(%r12) # FPRs
165 la %r5,8(%r12) # GPRs
166 #ifdef HAVE_AS_S390_ZARCH
167 brasl %r14,ffi_closure_helper_SYSV
168 #else
169 bas %r14,0(%r1,%r13) # Call helper
170 #endif
171
172 lr %r15,%r12
173 .cfi_def_cfa_register r15
174 lm %r12,%r14,48(%r12) # Restore saved registers
175 l %r6,24(%r15)
176 ld %f0,64(%r15) # Load return registers
177 lm %r2,%r3,8(%r15)
178 br %r14
179 .cfi_endproc
180
181 #ifndef HAVE_AS_S390_ZARCH
182 .align 4
183 .Lchelper:
184 .long ffi_closure_helper_SYSV-.Lcbase
185 #endif
186
187 .size ffi_closure_SYSV,.-ffi_closure_SYSV
188
189 #else
190
191 # r2: frame
192 # r3: ret_type
193 # r4: ret_addr
194 # r5: fun
195 # r6: closure
196
197 # This assumes we are using gas.
198 .balign 8
199 .globl ffi_call_SYSV
200 FFI_HIDDEN(ffi_call_SYSV)
201 .type ffi_call_SYSV,%function
202 ffi_call_SYSV:
203 .cfi_startproc
204 stg %r6,88(%r2) # Save registers
205 stmg %r12,%r14,96(%r2)
206 lgr %r13,%r2 # Install frame pointer
207 .cfi_rel_offset r6, 88
208 .cfi_rel_offset r12, 96
209 .cfi_rel_offset r13, 104
210 .cfi_rel_offset r14, 112
211 .cfi_def_cfa_register r13
212 stg %r2,0(%r15) # Set up back chain
213 larl %r14,.Ltable # Set up return address
214 slag %r3,%r3,3 # ret_type *= 8
215 lgr %r12,%r4 # Save ret_addr
216 lgr %r1,%r5 # Save fun
217 lgr %r0,%r6 # Install static chain
218 agr %r14,%r3
219 lmg %r2,%r6,16(%r13) # Load arguments
220 ld %f0,128(%r13)
221 ld %f2,136(%r13)
222 ld %f4,144(%r13)
223 ld %f6,152(%r13)
224 br %r1 # ... and call function
225
226 .balign 8
227 .Ltable:
228 # FFI390_RET_DOUBLE
229 std %f0,0(%r12)
230 j .Ldone
231
232 .balign 8
233 # FFI390_RET_DOUBLE
234 ste %f0,0(%r12)
235 j .Ldone
236
237 .balign 8
238 # FFI390_RET_INT64
239 stg %r2,0(%r12)
240
241 .balign 8
242 # FFI390_RET_INT32
243 # Never used, as we always store type ffi_arg.
244 # But the stg above is 6 bytes and we cannot
245 # jump around this case, so fall through.
246 nop
247 nop
248
249 .balign 8
250 # FFI390_RET_VOID
251 .Ldone:
252 lg %r14,112(%r13)
253 lg %r12,96(%r13)
254 lg %r6,88(%r13)
255 lg %r13,104(%r13)
256 .cfi_restore r14
257 .cfi_restore r13
258 .cfi_restore r12
259 .cfi_restore r6
260 .cfi_def_cfa r15, 160
261 br %r14
262 .cfi_endproc
263 .size ffi_call_SYSV,.-ffi_call_SYSV
264
265
266 .balign 8
267 .globl ffi_go_closure_SYSV
268 FFI_HIDDEN(ffi_go_closure_SYSV)
269 .type ffi_go_closure_SYSV,%function
270 ffi_go_closure_SYSV:
271 .cfi_startproc
272 stmg %r2,%r6,16(%r15) # Save arguments
273 lgr %r4,%r0 # Load closure -> user_data
274 lg %r2,8(%r4) # ->cif
275 lg %r3,16(%r4) # ->fun
276 j .Ldoclosure
277 .cfi_endproc
278 .size ffi_go_closure_SYSV,.-ffi_go_closure_SYSV
279
280
281 .balign 8
282 .globl ffi_closure_SYSV
283 FFI_HIDDEN(ffi_closure_SYSV)
284 .type ffi_closure_SYSV,%function
285 ffi_closure_SYSV:
286 .cfi_startproc
287 stmg %r2,%r6,16(%r15) # Save arguments
288 lgr %r4,%r0 # Load closure
289 lg %r2,32(%r4) # ->cif
290 lg %r3,40(%r4) # ->fun
291 lg %r4,48(%r4) # ->user_data
292 .Ldoclosure:
293 stmg %r13,%r15,104(%r15) # Save registers
294 lgr %r13,%r15
295 .cfi_def_cfa_register r13
296 .cfi_rel_offset r6, 48
297 .cfi_rel_offset r13, 104
298 .cfi_rel_offset r14, 112
299 .cfi_rel_offset r15, 120
300 aghi %r15,-160-16 # Set up stack frame
301 stg %r13,0(%r15) # Set up back chain
302
303 std %f0,128(%r13) # Save fp arguments
304 std %f2,136(%r13)
305 std %f4,144(%r13)
306 std %f6,152(%r13)
307 la %r5,160(%r13) # Overflow
308 stg %r5,160(%r15)
309 la %r6,128(%r13) # FPRs
310 la %r5,16(%r13) # GPRs
311 brasl %r14,ffi_closure_helper_SYSV # Call helper
312
313 lgr %r15,%r13
314 .cfi_def_cfa_register r15
315 lmg %r13,%r14,104(%r13) # Restore saved registers
316 lg %r6,48(%r15)
317 ld %f0,128(%r15) # Load return registers
318 lg %r2,16(%r15)
319 br %r14
320 .cfi_endproc
321 .size ffi_closure_SYSV,.-ffi_closure_SYSV
322
323
324 #if defined(FFI_EXEC_STATIC_TRAMP)
325 /*
326 * Below is the definition of the trampoline code table. Each element in
327 * the code table is a trampoline.
328 */
329 /*
330 * The trampoline uses the volatile register r0 and r1. As the registers are
331 * marked volatile in the ABI, the original values are not saved.
332 *
333 * The trampoline has two parameters - target code to jump to and data for
334 * the target code. The trampoline extracts the parameters from its parameter
335 * block (see tramp_table_map()). The trampoline saves the data address in r0.
336 * Finally, it jumps to the target code.
337 */
338
339 .align FFI390_TRAMP_MAP_SIZE
340 trampoline_code_table:
341 .rept FFI390_TRAMP_MAP_SIZE / FFI390_TRAMP_SIZE
342 basr %r1,0 # load next instruction address to r1
343 lmg %r0,%r1,4094(%r1) # load parameter block
344 # r0 -> data
345 # r1 -> code
346 br %r1 # jump to r1/code
347 .balign 8
348 .endr
349
350 .globl trampoline_code_table
351 FFI_HIDDEN(trampoline_code_table)
352 #ifdef __ELF__
353 .type trampoline_code_table, @function
354 .size trampoline_code_table,.- trampoline_code_table
355 #endif
356 .align FFI390_TRAMP_MAP_SIZE
357 #endif /* FFI_EXEC_STATIC_TRAMP */
358
359 #endif /* !s390x */
360
361 #if defined __ELF__ && defined __linux__
362 .section .note.GNU-stack,"",@progbits
363 #endif