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 .globl ffi_prep_args_SYSV
37 /* Save the old stack pointer as AP. */
41 /* Allocate the stack space we need. */
43 /* Save registers we use. */
56 /* Save arguments over call... */
57 mr %r31,%r5 /* flags, */
58 mr %r30,%r6 /* rvalue, */
59 mr %r29,%r7 /* function address, */
60 mr %r28,%r8 /* our AP. */
63 /* Call ffi_prep_args_SYSV. */
65 bl ffi_prep_args_SYSV@local
67 /* Now do the call. */
68 /* Set up cr1 with bits 4-7 of the flags. */
70 /* Get the address to call into CTR. */
72 /* Load all those argument registers. */
73 lwz %r3,-16-(8*4)(%r28)
74 lwz %r4,-16-(7*4)(%r28)
75 lwz %r5,-16-(6*4)(%r28)
76 lwz %r6,-16-(5*4)(%r28)
79 lwz %r7,-16-(4*4)(%r28)
80 lwz %r8,-16-(3*4)(%r28)
81 lwz %r9,-16-(2*4)(%r28)
82 lwz %r10,-16-(1*4)(%r28)
87 /* Load all the FP registers. */
89 lfd %f1,-16-(8*4)-(8*8)(%r28)
90 lfd %f2,-16-(8*4)-(7*8)(%r28)
91 lfd %f3,-16-(8*4)-(6*8)(%r28)
92 lfd %f4,-16-(8*4)-(5*8)(%r28)
94 lfd %f5,-16-(8*4)-(4*8)(%r28)
95 lfd %f6,-16-(8*4)-(3*8)(%r28)
96 lfd %f7,-16-(8*4)-(2*8)(%r28)
97 lfd %f8,-16-(8*4)-(1*8)(%r28)
104 /* Now, deal with the return value. */
105 mtcrf 0x01,%r31 /* cr7 */
106 bt- 31,L(small_struct_return_value)
107 bt- 30,L(done_return_value)
109 bt- 29,L(fp_return_value)
112 bf+ 28,L(done_return_value)
114 mtcrf 0x02,%r31 /* cr6 */
115 bf 27,L(done_return_value)
118 /* Fall through... */
120 L(done_return_value):
121 /* Restore the registers we used and return. */
133 bf 28,L(float_return_value)
135 mtcrf 0x02,%r31 /* cr6 */
136 bf 27,L(done_return_value)
138 b L(done_return_value)
139 L(float_return_value):
141 b L(done_return_value)
144 L(small_struct_return_value):
146 * The C code always allocates a properly-aligned 8-byte bounce
147 * buffer to make this assembly code very simple. Just write out
148 * r3 and r4 to the buffer to allow the C code to handle the rest.
152 b L(done_return_value)
157 .section ".eh_frame",EH_FRAME_FLAGS,@progbits
159 .4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */
161 .4byte 0x0 /* CIE Identifier Tag */
162 .byte 0x1 /* CIE Version */
163 #if defined _RELOCATABLE || defined __PIC__
164 .ascii "zR\0" /* CIE Augmentation */
166 .ascii "\0" /* CIE Augmentation */
168 .uleb128 0x1 /* CIE Code Alignment Factor */
169 .sleb128 -4 /* CIE Data Alignment Factor */
170 .byte 0x41 /* CIE RA Column */
171 #if defined _RELOCATABLE || defined __PIC__
172 .uleb128 0x1 /* Augmentation size */
173 .byte 0x1b /* FDE Encoding (pcrel sdata4) */
175 .byte 0xc /* DW_CFA_def_cfa */
181 .4byte .LEFDE1-.LASFDE1 /* FDE Length */
183 .4byte .LASFDE1-.Lframe1 /* FDE CIE offset */
184 #if defined _RELOCATABLE || defined __PIC__
185 .4byte .LFB1-. /* FDE initial location */
187 .4byte .LFB1 /* FDE initial location */
189 .4byte .LFE1-.LFB1 /* FDE address range */
190 #if defined _RELOCATABLE || defined __PIC__
191 .uleb128 0x0 /* Augmentation size */
193 .byte 0x4 /* DW_CFA_advance_loc4 */
195 .byte 0xd /* DW_CFA_def_cfa_register */
197 .byte 0x4 /* DW_CFA_advance_loc4 */
199 .byte 0x11 /* DW_CFA_offset_extended_sf */
202 .byte 0x9f /* DW_CFA_offset, column 0x1f */
204 .byte 0x9e /* DW_CFA_offset, column 0x1e */
206 .byte 0x9d /* DW_CFA_offset, column 0x1d */
208 .byte 0x9c /* DW_CFA_offset, column 0x1c */
210 .byte 0x4 /* DW_CFA_advance_loc4 */
212 .byte 0xd /* DW_CFA_def_cfa_register */
218 #if defined __ELF__ && defined __linux__
219 .section .note.GNU-stack,"",@progbits