Debian Codegraph @

src/mips/n32.S

raw
1 /* -----------------------------------------------------------------------
2 n32.S - Copyright (c) 1996, 1998, 2005, 2007, 2009, 2010 Red Hat, Inc.
3
4 MIPS Foreign Function Interface
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
26
27 #define LIBFFI_ASM
28 #include <fficonfig.h>
29 #include <ffi.h>
30
31 /* Only build this code if we are compiling for n32 */
32
33 #if defined(FFI_MIPS_N32)
34
35 #define callback a0
36 #define bytes a2
37 #define flags a3
38 #define raddr a4
39 #define fn a5
40 #define closure a6
41
42 /* Note: to keep stack 16 byte aligned we need even number slots
43 used 9 slots here
44 */
45 #define SIZEOF_FRAME ( 10 * FFI_SIZEOF_ARG )
46
47 #ifdef __GNUC__
48 .abicalls
49 #endif
50 #if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
51 .set mips4
52 #endif
53 .text
54 .align 2
55 .globl ffi_call_N32
56 .ent ffi_call_N32
57 ffi_call_N32:
58 .LFB0:
59 .frame $fp, SIZEOF_FRAME, ra
60 .mask 0xc0000000,-FFI_SIZEOF_ARG
61 .fmask 0x00000000,0
62
63 # Prologue
64 SUBU $sp, SIZEOF_FRAME # Frame size
65 .LCFI00:
66 REG_S $fp, SIZEOF_FRAME - 2*FFI_SIZEOF_ARG($sp) # Save frame pointer
67 REG_S ra, SIZEOF_FRAME - 1*FFI_SIZEOF_ARG($sp) # Save return address
68 .LCFI01:
69 move $fp, $sp
70 .LCFI02:
71 move t9, callback # callback function pointer
72 REG_S bytes, 2*FFI_SIZEOF_ARG($fp) # bytes
73 REG_S flags, 3*FFI_SIZEOF_ARG($fp) # flags
74 REG_S raddr, 4*FFI_SIZEOF_ARG($fp) # raddr
75 REG_S fn, 5*FFI_SIZEOF_ARG($fp) # fn
76 REG_S closure, 6*FFI_SIZEOF_ARG($fp) # closure
77
78 # Allocate at least 4 words in the argstack
79 move v0, bytes
80 bge bytes, 4 * FFI_SIZEOF_ARG, bigger
81 LI v0, 4 * FFI_SIZEOF_ARG
82 b sixteen
83
84 bigger:
85 ADDU t4, v0, 2 * FFI_SIZEOF_ARG -1 # make sure it is aligned
86 and v0, t4, -2 * FFI_SIZEOF_ARG # to a proper boundry.
87
88 sixteen:
89 SUBU $sp, $sp, v0 # move the stack pointer to reflect the
90 # arg space
91
92 move a0, $sp # 4 * FFI_SIZEOF_ARG
93 ADDU a3, $fp, 3 * FFI_SIZEOF_ARG
94
95 # Call ffi_prep_args
96 jal t9
97
98 # Copy the stack pointer to t9
99 move t9, $sp
100
101 # Fix the stack if there are more than 8 64bit slots worth
102 # of arguments.
103
104 # Load the number of bytes
105 REG_L t6, 2*FFI_SIZEOF_ARG($fp)
106
107 # Is it bigger than 8 * FFI_SIZEOF_ARG?
108 daddiu t8, t6, -(8 * FFI_SIZEOF_ARG)
109 bltz t8, loadregs
110
111 ADDU t9, t9, t8
112
113 loadregs:
114
115 REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
116
117 # when retval is _Complex long double, $f12/$a0, $f13/$a1 will be skipped
118 # no idea why, but gcc does it.
119 SRL t4, t6, 8*FFI_FLAG_BITS
120 move t8, t6
121 bne t4, FFI_TYPE_COMPLEX_LDLD, loadregs1
122
123 SLL t8, t6, 2*FFI_FLAG_BITS
124
125
126 loadregs1:
127 #ifdef __mips_soft_float
128 REG_L a0, 0*FFI_SIZEOF_ARG(t9)
129 REG_L a1, 1*FFI_SIZEOF_ARG(t9)
130 REG_L a2, 2*FFI_SIZEOF_ARG(t9)
131 REG_L a3, 3*FFI_SIZEOF_ARG(t9)
132 REG_L a4, 4*FFI_SIZEOF_ARG(t9)
133 REG_L a5, 5*FFI_SIZEOF_ARG(t9)
134 REG_L a6, 6*FFI_SIZEOF_ARG(t9)
135 REG_L a7, 7*FFI_SIZEOF_ARG(t9)
136 #else
137 and t4, t8, ((1<<FFI_FLAG_BITS)-1)
138 REG_L a0, 0*FFI_SIZEOF_ARG(t9)
139 beqz t4, arg1_next
140 bne t4, FFI_TYPE_FLOAT, arg1_doublep
141 l.s $f12, 0*FFI_SIZEOF_ARG(t9)
142 b arg1_next
143 arg1_doublep:
144 l.d $f12, 0*FFI_SIZEOF_ARG(t9)
145 arg1_next:
146
147 SRL t4, t8, 1*FFI_FLAG_BITS
148 and t4, ((1<<FFI_FLAG_BITS)-1)
149 REG_L a1, 1*FFI_SIZEOF_ARG(t9)
150 beqz t4, arg2_next
151 bne t4, FFI_TYPE_FLOAT, arg2_doublep
152 l.s $f13, 1*FFI_SIZEOF_ARG(t9)
153 b arg2_next
154 arg2_doublep:
155 l.d $f13, 1*FFI_SIZEOF_ARG(t9)
156 arg2_next:
157
158 SRL t4, t8, 2*FFI_FLAG_BITS
159 and t4, ((1<<FFI_FLAG_BITS)-1)
160 REG_L a2, 2*FFI_SIZEOF_ARG(t9)
161 beqz t4, arg3_next
162 bne t4, FFI_TYPE_FLOAT, arg3_doublep
163 l.s $f14, 2*FFI_SIZEOF_ARG(t9)
164 b arg3_next
165 arg3_doublep:
166 l.d $f14, 2*FFI_SIZEOF_ARG(t9)
167 arg3_next:
168
169 SRL t4, t8, 3*FFI_FLAG_BITS
170 and t4, ((1<<FFI_FLAG_BITS)-1)
171 REG_L a3, 3*FFI_SIZEOF_ARG(t9)
172 beqz t4, arg4_next
173 bne t4, FFI_TYPE_FLOAT, arg4_doublep
174 l.s $f15, 3*FFI_SIZEOF_ARG(t9)
175 b arg4_next
176 arg4_doublep:
177 l.d $f15, 3*FFI_SIZEOF_ARG(t9)
178 arg4_next:
179
180 SRL t4, t8, 4*FFI_FLAG_BITS
181 and t4, ((1<<FFI_FLAG_BITS)-1)
182 REG_L a4, 4*FFI_SIZEOF_ARG(t9)
183 beqz t4, arg5_next
184 bne t4, FFI_TYPE_FLOAT, arg5_doublep
185 l.s $f16, 4*FFI_SIZEOF_ARG(t9)
186 b arg5_next
187 arg5_doublep:
188 l.d $f16, 4*FFI_SIZEOF_ARG(t9)
189 arg5_next:
190
191 SRL t4, t8, 5*FFI_FLAG_BITS
192 and t4, ((1<<FFI_FLAG_BITS)-1)
193 REG_L a5, 5*FFI_SIZEOF_ARG(t9)
194 beqz t4, arg6_next
195 bne t4, FFI_TYPE_FLOAT, arg6_doublep
196 l.s $f17, 5*FFI_SIZEOF_ARG(t9)
197 b arg6_next
198 arg6_doublep:
199 l.d $f17, 5*FFI_SIZEOF_ARG(t9)
200 arg6_next:
201
202 SRL t4, t8, 6*FFI_FLAG_BITS
203 and t4, ((1<<FFI_FLAG_BITS)-1)
204 REG_L a6, 6*FFI_SIZEOF_ARG(t9)
205 beqz t4, arg7_next
206 bne t4, FFI_TYPE_FLOAT, arg7_doublep
207 l.s $f18, 6*FFI_SIZEOF_ARG(t9)
208 b arg7_next
209 arg7_doublep:
210 l.d $f18, 6*FFI_SIZEOF_ARG(t9)
211 arg7_next:
212
213 SRL t4, t8, 7*FFI_FLAG_BITS
214 and t4, ((1<<FFI_FLAG_BITS)-1)
215 REG_L a7, 7*FFI_SIZEOF_ARG(t9)
216 beqz t4, arg8_next
217 bne t4, FFI_TYPE_FLOAT, arg8_doublep
218 l.s $f19, 7*FFI_SIZEOF_ARG(t9)
219 b arg8_next
220 arg8_doublep:
221 l.d $f19, 7*FFI_SIZEOF_ARG(t9)
222 arg8_next:
223 #endif
224
225 callit:
226 # Load the function pointer
227 REG_L t9, 5*FFI_SIZEOF_ARG($fp)
228
229 # install the static chain(t7=$15)
230 REG_L t7, 6*FFI_SIZEOF_ARG($fp)
231
232 # If the return value pointer is NULL, assume no return value.
233 REG_L t5, 4*FFI_SIZEOF_ARG($fp)
234 beqz t5, noretval
235
236 # Shift the return type flag over
237 SRL t6, 8*FFI_FLAG_BITS
238
239 bne t6, FFI_TYPE_UINT64, retsint32
240
241 retuint64:
242 jal t9
243 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
244 sd v0, 0(t4)
245 b epilogue
246
247 retsint32:
248 bne t6, FFI_TYPE_SINT32, retuint16
249 jal t9
250 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
251 sll v0, v0, 0
252 sd v0, 0(t4)
253 b epilogue
254
255 retuint16:
256 bne t6, FFI_TYPE_UINT16, retsint16
257 jal t9
258 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
259 andi v0, v0, 0xffff
260 sd v0, 0(t4)
261 b epilogue
262
263 retsint16:
264 bne t6, FFI_TYPE_SINT16, retuint8
265 jal t9
266 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
267 dsll v0, v0, 48
268 dsra v0, v0, 48
269 sd v0, 0(t4)
270 b epilogue
271
272 retuint8:
273 bne t6, FFI_TYPE_UINT8, retsint8
274 jal t9
275 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
276 andi v0, v0, 0xff
277 sd v0, 0(t4)
278 b epilogue
279
280 retsint8:
281 bne t6, FFI_TYPE_SINT8, retfloat
282 jal t9
283 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
284 sd v0, 0(t4)
285 dsll v0, v0, 56
286 dsra v0, v0, 56
287 b epilogue
288
289 retfloat:
290 #ifndef __mips_soft_float
291 bne t6, FFI_TYPE_FLOAT, retdouble
292 jal t9
293 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
294 s.s $f0, 0(t4)
295 b epilogue
296
297 retdouble:
298 bne t6, FFI_TYPE_DOUBLE, retstruct_d
299 jal t9
300 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
301 s.d $f0, 0(t4)
302 b epilogue
303
304 retstruct_d:
305 bne t6, FFI_TYPE_STRUCT_D, retstruct_f
306 jal t9
307 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
308 s.d $f0, 0(t4)
309 b epilogue
310
311 retstruct_f:
312 bne t6, FFI_TYPE_STRUCT_F, retstruct_d_d
313 jal t9
314 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
315 s.s $f0, 0(t4)
316 b epilogue
317
318 retstruct_d_d:
319 bne t6, FFI_TYPE_STRUCT_DD, retcomplex_d_d
320 jal t9
321 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
322 s.d $f0, 0(t4)
323 s.d $f2, 8(t4)
324 b epilogue
325
326 retcomplex_d_d:
327 bne t6, FFI_TYPE_COMPLEX_DD, retcomplex_ld_ld
328 jal t9
329 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
330 s.d $f0, 0(t4)
331 s.d $f2, 8(t4)
332 b epilogue
333
334 retcomplex_ld_ld:
335 bne t6, FFI_TYPE_COMPLEX_LDLD, retstruct_f_f
336 jal t9
337 b epilogue
338
339 retstruct_f_f:
340 bne t6, FFI_TYPE_STRUCT_FF, retcomplex_f_f
341 jal t9
342 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
343 s.s $f0, 0(t4)
344 s.s $f2, 4(t4)
345 b epilogue
346
347 retcomplex_f_f:
348 bne t6, FFI_TYPE_COMPLEX_FF, retstruct_d_f
349 jal t9
350 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
351 s.s $f0, 0(t4)
352 s.s $f2, 4(t4)
353 b epilogue
354
355 retstruct_d_f:
356 bne t6, FFI_TYPE_STRUCT_DF, retstruct_f_d
357 jal t9
358 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
359 s.d $f0, 0(t4)
360 s.s $f2, 8(t4)
361 b epilogue
362
363 retstruct_f_d:
364 bne t6, FFI_TYPE_STRUCT_FD, retstruct_d_soft
365 jal t9
366 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
367 s.s $f0, 0(t4)
368 s.d $f2, 8(t4)
369 b epilogue
370 #endif
371
372 retstruct_d_soft:
373 bne t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
374 jal t9
375 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
376 sd v0, 0(t4)
377 b epilogue
378
379 retstruct_f_soft:
380 bne t6, FFI_TYPE_STRUCT_F_SOFT, retstruct_d_d_soft
381 jal t9
382 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
383 sw v0, 0(t4)
384 b epilogue
385
386 retstruct_d_d_soft:
387 bne t6, FFI_TYPE_STRUCT_DD_SOFT, retstruct_f_f_soft
388 jal t9
389 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
390 sd v0, 0(t4)
391 sd a0, 8(t4) # not typo, it is a0, I have no idea, gcc does do it
392 b epilogue
393
394 retstruct_f_f_soft:
395 bne t6, FFI_TYPE_STRUCT_FF_SOFT, retstruct_d_f_soft
396 jal t9
397 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
398 sw v0, 0(t4)
399 sw v1, 4(t4)
400 b epilogue
401
402 retstruct_d_f_soft:
403 bne t6, FFI_TYPE_STRUCT_DF_SOFT, retstruct_f_d_soft
404 jal t9
405 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
406 sd v0, 0(t4)
407 sw v1, 8(t4)
408 b epilogue
409
410 retstruct_f_d_soft:
411 bne t6, FFI_TYPE_STRUCT_FD_SOFT, retstruct_small
412 jal t9
413 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
414 sw v0, 0(t4)
415 sd a0, 8(t4) # not typo, it is a0, I have no idea, gcc does do it
416 b epilogue
417
418 retstruct_small:
419 bne t6, FFI_TYPE_STRUCT_SMALL, retstruct_small2
420 jal t9
421 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
422 REG_S v0, 0(t4)
423 b epilogue
424
425 retstruct_small2:
426 bne t6, FFI_TYPE_STRUCT_SMALL2, retlongdouble_soft
427 jal t9
428 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
429 REG_S v0, 0(t4)
430 REG_S v1, 8(t4)
431 b epilogue
432
433 retlongdouble_soft:
434 bne t6, FFI_TYPE_LONGDOUBLE, retcomplex_small
435 jal t9
436 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
437 REG_S v0, 0(t4)
438 REG_S a0, 8(t4) # not typo, it is a0, I have no idea, gcc does do it
439 b epilogue
440
441 retcomplex_small:
442 bne t6, FFI_TYPE_COMPLEX_SMALL, retcomplex_small2
443 jal t9
444 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
445 REG_S v0, 0(t4)
446 b epilogue
447
448 retcomplex_small2:
449 bne t6, FFI_TYPE_COMPLEX_SMALL2, retstruct
450 jal t9
451 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
452 REG_S v0, 0(t4)
453 REG_S v1, 8(t4)
454 b epilogue
455
456 retstruct:
457 noretval:
458 jal t9
459
460 # Epilogue
461 epilogue:
462 move $sp, $fp
463 REG_L $fp, SIZEOF_FRAME - 2*FFI_SIZEOF_ARG($sp) # Restore frame pointer
464 REG_L ra, SIZEOF_FRAME - 1*FFI_SIZEOF_ARG($sp) # Restore return address
465 ADDU $sp, SIZEOF_FRAME # Fix stack pointer
466 j ra
467
468 .LFE0:
469 .end ffi_call_N32
470
471 /* ffi_closure_N32. Expects address of the passed-in ffi_closure in t0
472 ($12). Stores any arguments passed in registers onto the stack,
473 then calls ffi_closure_mips_inner_N32, which then decodes
474 them.
475
476 Stack layout:
477
478 20 - Start of parameters, original sp
479 19 - Called function a7 save
480 18 - Called function a6 save
481 17 - Called function a5 save
482 16 - Called function a4 save
483 15 - Called function a3 save
484 14 - Called function a2 save
485 13 - Called function a1 save
486 12 - Called function a0 save
487 11 - Called function f19
488 10 - Called function f18
489 9 - Called function f17
490 8 - Called function f16
491 7 - Called function f15
492 6 - Called function f14
493 5 - Called function f13
494 4 - Called function f12
495 3 - return value high (v1 or $f2)
496 2 - return value low (v0 or $f0)
497 1 - ra save
498 0 - gp save our sp points here
499 */
500
501 #define SIZEOF_FRAME2 (20 * FFI_SIZEOF_ARG)
502
503 #define A7_OFF2 (19 * FFI_SIZEOF_ARG)
504 #define A6_OFF2 (18 * FFI_SIZEOF_ARG)
505 #define A5_OFF2 (17 * FFI_SIZEOF_ARG)
506 #define A4_OFF2 (16 * FFI_SIZEOF_ARG)
507 #define A3_OFF2 (15 * FFI_SIZEOF_ARG)
508 #define A2_OFF2 (14 * FFI_SIZEOF_ARG)
509 #define A1_OFF2 (13 * FFI_SIZEOF_ARG)
510 #define A0_OFF2 (12 * FFI_SIZEOF_ARG)
511
512 #define F19_OFF2 (11 * FFI_SIZEOF_ARG)
513 #define F18_OFF2 (10 * FFI_SIZEOF_ARG)
514 #define F17_OFF2 (9 * FFI_SIZEOF_ARG)
515 #define F16_OFF2 (8 * FFI_SIZEOF_ARG)
516 #define F15_OFF2 (7 * FFI_SIZEOF_ARG)
517 #define F14_OFF2 (6 * FFI_SIZEOF_ARG)
518 #define F13_OFF2 (5 * FFI_SIZEOF_ARG)
519 #define F12_OFF2 (4 * FFI_SIZEOF_ARG)
520
521 #define V1_OFF2 (3 * FFI_SIZEOF_ARG)
522 #define V0_OFF2 (2 * FFI_SIZEOF_ARG)
523
524 #define RA_OFF2 (1 * FFI_SIZEOF_ARG)
525 #define GP_OFF2 (0 * FFI_SIZEOF_ARG)
526
527 .align 2
528 .globl ffi_go_closure_N32
529 .ent ffi_go_closure_N32
530 ffi_go_closure_N32:
531 .LFB1:
532 .frame $sp, SIZEOF_FRAME2, ra
533 .mask 0x90000000,-(SIZEOF_FRAME2 - RA_OFF2)
534 .fmask 0x00000000,0
535 SUBU $sp, SIZEOF_FRAME2
536 .LCFI10:
537 .cpsetup t9, GP_OFF2, ffi_go_closure_N32
538 REG_S ra, RA_OFF2($sp) # Save return address
539 .LCFI11:
540
541 REG_S a0, A0_OFF2($sp)
542 REG_S a1, A1_OFF2($sp)
543 REG_S a2, A2_OFF2($sp)
544 REG_S a3, A3_OFF2($sp)
545 REG_S a4, A4_OFF2($sp)
546 REG_S a5, A5_OFF2($sp)
547
548 # Call ffi_closure_mips_inner_N32 to do the real work.
549 LA t9, ffi_closure_mips_inner_N32
550 #if _MIPS_SIM==_ABIN32
551 lw a0, 4($15) # cif
552 lw a1, 8($15) # fun
553 #else
554 REG_L a0, 8($15) # cif
555 REG_L a1, 16($15) # fun
556 #endif
557 move a2, t7 # userdata=closure
558 ADDU a3, $sp, V0_OFF2 # rvalue
559 ADDU a4, $sp, A0_OFF2 # ar
560 ADDU a5, $sp, F12_OFF2 # fpr
561
562 b $do_closure
563
564 .LFE1:
565 .end ffi_go_closure_N32
566
567 .align 2
568 .globl ffi_closure_N32
569 .ent ffi_closure_N32
570 ffi_closure_N32:
571 .LFB2:
572 .frame $sp, SIZEOF_FRAME2, ra
573 .mask 0x90000000,-(SIZEOF_FRAME2 - RA_OFF2)
574 .fmask 0x00000000,0
575 SUBU $sp, SIZEOF_FRAME2
576 .LCFI20:
577 .cpsetup t9, GP_OFF2, ffi_closure_N32
578 REG_S ra, RA_OFF2($sp) # Save return address
579 .LCFI21:
580 REG_S a0, A0_OFF2($sp)
581 REG_S a1, A1_OFF2($sp)
582 REG_S a2, A2_OFF2($sp)
583 REG_S a3, A3_OFF2($sp)
584 REG_S a4, A4_OFF2($sp)
585 REG_S a5, A5_OFF2($sp)
586
587 # Call ffi_closure_mips_inner_N32 to do the real work.
588 LA t9, ffi_closure_mips_inner_N32
589 #if _MIPS_SIM==_ABIN32
590 lw a0, 20($12) # cif
591 lw a1, 24($12) # fun
592 lw a2, 28($12) # user_data
593 #else
594 REG_L a0, 56($12) # cif
595 REG_L a1, 64($12) # fun
596 REG_L a2, 72($12) # user_data
597 #endif
598 ADDU a3, $sp, V0_OFF2
599 # FIXME: a4 does work, while if ret is _Complex long double, it will overwrite Fn_OFF2
600 ADDU a4, $sp, A0_OFF2
601 ADDU a5, $sp, F12_OFF2
602
603 $do_closure:
604 # Store all possible argument registers. If there are more than
605 # fit in registers, then they were stored on the stack.
606 REG_S a6, A6_OFF2($sp)
607 REG_S a7, A7_OFF2($sp)
608
609 #ifndef __mips_soft_float
610 # Store all possible float/double registers.
611 s.d $f12, F12_OFF2($sp)
612 s.d $f13, F13_OFF2($sp)
613 s.d $f14, F14_OFF2($sp)
614 s.d $f15, F15_OFF2($sp)
615 s.d $f16, F16_OFF2($sp)
616 s.d $f17, F17_OFF2($sp)
617 s.d $f18, F18_OFF2($sp)
618 s.d $f19, F19_OFF2($sp)
619 #endif
620
621 jalr t9
622
623 cls_retuint64:
624 # Return flags are in v0
625 bne v0, FFI_TYPE_UINT64, cls_retsint32
626 ld v0, V0_OFF2($sp)
627 b cls_epilogue
628
629 cls_retsint32:
630 bne v0, FFI_TYPE_SINT32, cls_retsint16
631 lw v0, V0_OFF2($sp)
632 b cls_epilogue
633
634 cls_retsint16:
635 bne v0, FFI_TYPE_SINT16, cls_retuint16
636 lh v0, V0_OFF2($sp)
637 b cls_epilogue
638
639 cls_retuint16:
640 bne v0, FFI_TYPE_UINT16, cls_retsint8
641 lhu v0, V0_OFF2($sp)
642 b cls_epilogue
643
644 cls_retsint8:
645 bne v0, FFI_TYPE_SINT8, cls_retuint8
646 lb v0, V0_OFF2($sp)
647 b cls_epilogue
648
649 cls_retuint8:
650 bne v0, FFI_TYPE_UINT8, cls_retfloat
651 lbu v0, V0_OFF2($sp)
652 b cls_epilogue
653
654 cls_retfloat:
655 #ifndef __mips_soft_float
656 bne v0, FFI_TYPE_FLOAT, cls_retdouble
657 l.s $f0, V0_OFF2($sp)
658 b cls_epilogue
659
660 cls_retdouble:
661 bne v0, FFI_TYPE_DOUBLE, cls_retstruct_d
662 l.d $f0, V0_OFF2($sp)
663 b cls_epilogue
664
665 cls_retstruct_d:
666 bne v0, FFI_TYPE_STRUCT_D, cls_retstruct_f
667 l.d $f0, V0_OFF2($sp)
668 b cls_epilogue
669
670 cls_retstruct_f:
671 bne v0, FFI_TYPE_STRUCT_F, cls_retstruct_d_d
672 l.s $f0, V0_OFF2($sp)
673 b cls_epilogue
674
675 cls_retstruct_d_d:
676 bne v0, FFI_TYPE_STRUCT_DD, cls_retcomplex_d_d
677 l.d $f0, V0_OFF2($sp)
678 l.d $f2, V1_OFF2($sp)
679 b cls_epilogue
680
681 cls_retcomplex_d_d:
682 bne v0, FFI_TYPE_COMPLEX_DD, cls_retcomplex_f_f
683 l.d $f0, V0_OFF2($sp)
684 l.d $f2, V1_OFF2($sp)
685 b cls_epilogue
686
687 cls_retstruct_f_f:
688 bne v0, FFI_TYPE_STRUCT_FF, cls_retcomplex_f_f
689 l.s $f0, V0_OFF2($sp)
690 l.s $f2, V1_OFF2($sp)
691 b cls_epilogue
692
693 cls_retcomplex_f_f:
694 bne v0, FFI_TYPE_COMPLEX_FF, cls_retstruct_d_f
695 l.s $f0, V0_OFF2($sp)
696 l.s $f2, (V0_OFF2+4)($sp)
697 b cls_epilogue
698
699 cls_retstruct_d_f:
700 bne v0, FFI_TYPE_STRUCT_DF, cls_retstruct_f_d
701 l.d $f0, V0_OFF2($sp)
702 l.s $f2, V1_OFF2($sp)
703 b cls_epilogue
704
705 cls_retstruct_f_d:
706 bne v0, FFI_TYPE_STRUCT_FD, cls_retcomplex_ld_ld
707 l.s $f0, V0_OFF2($sp)
708 l.d $f2, V1_OFF2($sp)
709 b cls_epilogue
710 #else
711 cls_longdouble_soft:
712 bne v0, FFI_TYPE_LONGDOUBLE, cls_retcomplex_ld_ld
713 REG_L v0, V0_OFF2($sp)
714 REG_L a0, V1_OFF2($sp) # not typo, it is a0, I have no idea, gcc does do it
715 b cls_epilogue
716 #endif
717
718 cls_retcomplex_ld_ld:
719 bne v0, FFI_TYPE_COMPLEX_LDLD, cls_retstruct_small2
720 REG_L t8, A0_OFF2($sp)
721 REG_L t9, 16($sp)
722 REG_S t9, 0(t8)
723 REG_L t9, 24($sp)
724 REG_S t9, 8(t8)
725 REG_L t9, 32($sp)
726 REG_S t9, 16(t8)
727 REG_L t9, 40($sp)
728 REG_S t9, 24(t8)
729 b cls_epilogue
730
731 cls_retstruct_small2:
732 REG_L v0, V0_OFF2($sp)
733 REG_L v1, V1_OFF2($sp)
734
735 # Epilogue
736 cls_epilogue:
737 REG_L ra, RA_OFF2($sp) # Restore return address
738 .cpreturn
739 ADDU $sp, SIZEOF_FRAME2
740 j ra
741 .LFE2:
742 .end ffi_closure_N32
743
744 #ifdef __GNUC__
745 .section .eh_frame,EH_FRAME_FLAGS,@progbits
746 .Lframe1:
747 .4byte .LECIE1-.LSCIE1 # length
748 .LSCIE1:
749 .4byte 0x0 # CIE
750 .byte 0x1 # Version 1
751 .ascii "\000" # Augmentation
752 .uleb128 0x1 # Code alignment 1
753 .sleb128 -4 # Data alignment -4
754 .byte 0x1f # Return Address $31
755 .byte 0xc # DW_CFA_def_cfa
756 .uleb128 0x1d # in $sp
757 .uleb128 0x0 # offset 0
758 .align EH_FRAME_ALIGN
759 .LECIE1:
760
761 .LSFDE0:
762 .4byte .LEFDE0-.LASFDE0 # length.
763 .LASFDE0:
764 .4byte .LASFDE0-.Lframe1 # CIE_pointer.
765 FDE_ADDR_BYTES .LFB0 # initial_location.
766 FDE_ADDR_BYTES .LFE0-.LFB0 # address_range.
767 .byte 0x4 # DW_CFA_advance_loc4
768 .4byte .LCFI00-.LFB0 # to .LCFI00
769 .byte 0xe # DW_CFA_def_cfa_offset
770 .uleb128 SIZEOF_FRAME # adjust stack.by SIZEOF_FRAME
771 .byte 0x4 # DW_CFA_advance_loc4
772 .4byte .LCFI01-.LCFI00 # to .LCFI01
773 .byte 0x9e # DW_CFA_offset of $fp
774 .uleb128 2*FFI_SIZEOF_ARG/4 #
775 .byte 0x9f # DW_CFA_offset of ra
776 .uleb128 1*FFI_SIZEOF_ARG/4 #
777 .byte 0x4 # DW_CFA_advance_loc4
778 .4byte .LCFI02-.LCFI01 # to .LCFI02
779 .byte 0xd # DW_CFA_def_cfa_register
780 .uleb128 0x1e # in $fp
781 .align EH_FRAME_ALIGN
782 .LEFDE0:
783
784 .LSFDE1:
785 .4byte .LEFDE1-.LASFDE1 # length
786 .LASFDE1:
787 .4byte .LASFDE1-.Lframe1 # CIE_pointer.
788 FDE_ADDR_BYTES .LFB1 # initial_location.
789 FDE_ADDR_BYTES .LFE1-.LFB1 # address_range.
790 .byte 0x4 # DW_CFA_advance_loc4
791 .4byte .LCFI10-.LFB1 # to .LCFI10
792 .byte 0xe # DW_CFA_def_cfa_offset
793 .uleb128 SIZEOF_FRAME2 # adjust stack.by SIZEOF_FRAME
794 .byte 0x4 # DW_CFA_advance_loc4
795 .4byte .LCFI11-.LCFI10 # to .LCFI11
796 .byte 0x9c # DW_CFA_offset of $gp ($28)
797 .uleb128 (SIZEOF_FRAME2 - GP_OFF2)/4
798 .byte 0x9f # DW_CFA_offset of ra ($31)
799 .uleb128 (SIZEOF_FRAME2 - RA_OFF2)/4
800 .align EH_FRAME_ALIGN
801 .LEFDE1:
802
803 .LSFDE2:
804 .4byte .LEFDE2-.LASFDE2 # length
805 .LASFDE2:
806 .4byte .LASFDE2-.Lframe1 # CIE_pointer.
807 FDE_ADDR_BYTES .LFB2 # initial_location.
808 FDE_ADDR_BYTES .LFE2-.LFB2 # address_range.
809 .byte 0x4 # DW_CFA_advance_loc4
810 .4byte .LCFI20-.LFB2 # to .LCFI20
811 .byte 0xe # DW_CFA_def_cfa_offset
812 .uleb128 SIZEOF_FRAME2 # adjust stack.by SIZEOF_FRAME
813 .byte 0x4 # DW_CFA_advance_loc4
814 .4byte .LCFI21-.LCFI20 # to .LCFI21
815 .byte 0x9c # DW_CFA_offset of $gp ($28)
816 .uleb128 (SIZEOF_FRAME2 - GP_OFF2)/4
817 .byte 0x9f # DW_CFA_offset of ra ($31)
818 .uleb128 (SIZEOF_FRAME2 - RA_OFF2)/4
819 .align EH_FRAME_ALIGN
820 .LEFDE2:
821 #endif /* __GNUC__ */
822
823 #endif
824
825 #if defined __ELF__ && defined __linux__
826 .section .note.GNU-stack,"",%progbits
827 #endif