- Symmetrically define ffi_call_DARWIN for AIX.
[gcc.git] / libffi / src / powerpc / aix.S
1 /* -----------------------------------------------------------------------
2 aix.S - Copyright (c) 2002 Free Software Foundation, Inc.
3 based on darwin.S by John Hornkvist
4
5 PowerPC Assembly glue.
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, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
26
27 .set r0,0
28 .set r1,1
29 .set r2,2
30 .set r3,3
31 .set r4,4
32 .set r5,5
33 .set r6,6
34 .set r7,7
35 .set r8,8
36 .set r9,9
37 .set r10,10
38 .set r11,11
39 .set r12,12
40 .set r13,13
41 .set r14,14
42 .set r15,15
43 .set r16,16
44 .set r17,17
45 .set r18,18
46 .set r19,19
47 .set r20,20
48 .set r21,21
49 .set r22,22
50 .set r23,23
51 .set r24,24
52 .set r25,25
53 .set r26,26
54 .set r27,27
55 .set r28,28
56 .set r29,29
57 .set r30,30
58 .set r31,31
59 .set f0,0
60 .set f1,1
61 .set f2,2
62 .set f3,3
63 .set f4,4
64 .set f5,5
65 .set f6,6
66 .set f7,7
67 .set f8,8
68 .set f9,9
69 .set f10,10
70 .set f11,11
71 .set f12,12
72 .set f13,13
73 .set f14,14
74 .set f15,15
75 .set f16,16
76 .set f17,17
77 .set f18,18
78 .set f19,19
79 .set f20,20
80 .set f21,21
81
82 #define LIBFFI_ASM
83 #include <ffi.h>
84 #define JUMPTARGET(name) name
85 #define L(x) x
86 .file "aix.S"
87 .toc
88 .csect .text[PR]
89 .align 2
90 .globl ffi_prep_args
91
92 .csect .text[PR]
93 .align 2
94 .globl ffi_call_AIX
95 .globl .ffi_call_AIX
96 .csect ffi_call_AIX[DS]
97 ffi_call_AIX:
98 .long .ffi_call_AIX, TOC[tc0], 0
99 .csect .text[PR]
100 .ffi_call_AIX:
101 mr r12,r8 // We only need r12 until the call, so it doesn't have to be saved...
102 /* Save the old stack pointer as AP. */
103 mr r8,r1
104
105 /* Allocate the stack space we need. */
106 stwux r1,r1,r4
107
108 /* Save registers we use. */
109 mflr r9
110
111 stw r28,-16(r8)
112 stw r29,-12(r8)
113 stw r30, -8(r8)
114 stw r31, -4(r8)
115
116 stw r9, 8(r8)
117 stw r2, 20(r1)
118
119 /* Save arguments over call... */
120 mr r31,r5 /* flags, */
121 mr r30,r6 /* rvalue, */
122 mr r29,r7 /* function address, */
123 mr r28,r8 /* our AP. */
124
125 /* Call ffi_prep_args. */
126 mr r4,r1
127 li r9,0
128
129 lwz r2,4(r12)
130 lwz r12,0(r12)
131 mtctr r12 // r12 holds address of _ffi_prep_args
132 bctrl
133 lwz r2,20(r1)
134
135 /* Now do the call. */
136 lwz r12,0(r29)
137 /* Set up cr1 with bits 4-7 of the flags. */
138 mtcrf 0x40,r31
139 stw r2,20(r1)
140 mtctr r12
141 lwz r2,4(r29)
142 /* Load all those argument registers. */
143 // We have set up a nice stack frame, just load it into registers.
144 lwz r3, 20+(1*4)(r1)
145 lwz r4, 20+(2*4)(r1)
146 lwz r5, 20+(3*4)(r1)
147 lwz r6, 20+(4*4)(r1)
148 nop
149 lwz r7, 20+(5*4)(r1)
150 lwz r8, 20+(6*4)(r1)
151 lwz r9, 20+(7*4)(r1)
152 lwz r10,20+(8*4)(r1)
153
154 L1:
155 /* Load all the FP registers. */
156 bf 6,L2 // 2f + 0x18
157 lfd f1,-16-(13*8)(r28)
158 lfd f2,-16-(12*8)(r28)
159 lfd f3,-16-(11*8)(r28)
160 lfd f4,-16-(10*8)(r28)
161 nop
162 lfd f5,-16-(9*8)(r28)
163 lfd f6,-16-(8*8)(r28)
164 lfd f7,-16-(7*8)(r28)
165 lfd f8,-16-(6*8)(r28)
166 nop
167 lfd f9,-16-(5*8)(r28)
168 lfd f10,-16-(4*8)(r28)
169 lfd f11,-16-(3*8)(r28)
170 lfd f12,-16-(2*8)(r28)
171 nop
172 lfd f13,-16-(1*8)(r28)
173
174 L2:
175 /* Make the call. */
176 bctrl
177 lwz r2,20(r1)
178
179 /* Now, deal with the return value. */
180 mtcrf 0x01,r31
181
182 bt 30,L(done_return_value)
183 bt 29,L(fp_return_value)
184 stw r3,0(r30)
185 bf 28,L(done_return_value)
186 stw r4,4(r30)
187
188 /* Fall through... */
189
190 L(done_return_value):
191 /* Restore the registers we used and return. */
192 lwz r9, 8(r28)
193 lwz r31, -4(r28)
194 mtlr r9
195 lwz r30, -8(r28)
196 lwz r29,-12(r28)
197 lwz r28,-16(r28)
198 lwz r1,0(r1)
199 blr
200
201 L(fp_return_value):
202 bf 28,L(float_return_value)
203 stfd f1,0(r30)
204 b L(done_return_value)
205 L(float_return_value):
206 stfs f1,0(r30)
207 b L(done_return_value)
208 .long 0
209 .byte 0,0,0,1,128,4,0,0
210 //END(ffi_call_AIX)
211
212 .csect .text[PR]
213 .align 2
214 .globl ffi_call_DARWIN
215 .globl .ffi_call_DARWIN
216 .csect ffi_call_DARWIN[DS]
217 ffi_call_DARWIN:
218 .long .ffi_call_DARWIN, TOC[tc0], 0
219 .csect .text[PR]
220 .ffi_call_DARWIN:
221 blr
222 .long 0
223 .byte 0,0,0,0,0,0,0,0
224 //END(ffi_call_DARWIN)