1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 1998 Geoffrey Keating
3 Copyright (C) 2007 Free Software Foundation, Inc
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:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
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 ----------------------------------------------------------------------- */
29 #include <fficonfig.h>
31 #include <powerpc/asm.h>
34 FFI_HIDDEN(ffi_call_SYSV)
37 /* Save the old stack pointer as AP. */
39 .cfi_def_cfa_register 10
41 /* Allocate the stack space we need. */
43 /* Save registers we use. */
56 /* Save arguments over call... */
57 stw %r7, -20(%r10) /* closure, */
58 mr %r31,%r6 /* flags, */
59 mr %r30,%r5 /* rvalue, */
60 mr %r29,%r4 /* function address, */
61 mr %r28,%r10 /* our AP. */
62 .cfi_def_cfa_register 28
64 /* Call ffi_prep_args_SYSV. */
66 bl ffi_prep_args_SYSV@local
68 /* Now do the call. */
69 /* Set up cr1 with bits 4-7 of the flags. */
71 /* Get the address to call into CTR. */
73 /* Load all those argument registers. */
74 lwz %r3,-24-(8*4)(%r28)
75 lwz %r4,-24-(7*4)(%r28)
76 lwz %r5,-24-(6*4)(%r28)
77 lwz %r6,-24-(5*4)(%r28)
80 lwz %r7,-24-(4*4)(%r28)
81 lwz %r8,-24-(3*4)(%r28)
82 lwz %r9,-24-(2*4)(%r28)
83 lwz %r10,-24-(1*4)(%r28)
88 /* Load all the FP registers. */
90 lfd %f1,-24-(8*4)-(8*8)(%r28)
91 lfd %f2,-24-(8*4)-(7*8)(%r28)
92 lfd %f3,-24-(8*4)-(6*8)(%r28)
93 lfd %f4,-24-(8*4)-(5*8)(%r28)
95 lfd %f5,-24-(8*4)-(4*8)(%r28)
96 lfd %f6,-24-(8*4)-(3*8)(%r28)
97 lfd %f7,-24-(8*4)-(2*8)(%r28)
98 lfd %f8,-24-(8*4)-(1*8)(%r28)
106 /* Now, deal with the return value. */
107 mtcrf 0x01,%r31 /* cr7 */
108 bt- 31,L(small_struct_return_value)
109 bt- 30,L(done_return_value)
111 bt- 29,L(fp_return_value)
114 bf+ 28,L(done_return_value)
116 mtcrf 0x02,%r31 /* cr6 */
117 bf 27,L(done_return_value)
120 /* Fall through... */
122 L(done_return_value):
123 /* Restore the registers we used and return. */
131 /* At this point we don't have a cfa register. Say all our
132 saved regs have been restored. */
138 /* Hopefully this works.. */
139 .cfi_def_cfa_register 1
148 bf 28,L(float_return_value)
150 mtcrf 0x02,%r31 /* cr6 */
151 bf 27,L(done_return_value)
153 b L(done_return_value)
154 L(float_return_value):
156 b L(done_return_value)
159 L(small_struct_return_value):
161 * The C code always allocates a properly-aligned 8-byte bounce
162 * buffer to make this assembly code very simple. Just write out
163 * r3 and r4 to the buffer to allow the C code to handle the rest.
167 b L(done_return_value)
172 #if defined __ELF__ && defined __linux__
173 .section .note.GNU-stack,"",@progbits