1 | n/a | /* ----------------------------------------------------------------------- |
---|
2 | n/a | ffi_sysv.c - Copyright (C) 2013 IBM |
---|
3 | n/a | Copyright (C) 2011 Anthony Green |
---|
4 | n/a | Copyright (C) 2011 Kyle Moffett |
---|
5 | n/a | Copyright (C) 2008 Red Hat, Inc |
---|
6 | n/a | Copyright (C) 2007, 2008 Free Software Foundation, Inc |
---|
7 | n/a | Copyright (c) 1998 Geoffrey Keating |
---|
8 | n/a | |
---|
9 | n/a | PowerPC Foreign Function Interface |
---|
10 | n/a | |
---|
11 | n/a | Permission is hereby granted, free of charge, to any person obtaining |
---|
12 | n/a | a copy of this software and associated documentation files (the |
---|
13 | n/a | ``Software''), to deal in the Software without restriction, including |
---|
14 | n/a | without limitation the rights to use, copy, modify, merge, publish, |
---|
15 | n/a | distribute, sublicense, and/or sell copies of the Software, and to |
---|
16 | n/a | permit persons to whom the Software is furnished to do so, subject to |
---|
17 | n/a | the following conditions: |
---|
18 | n/a | |
---|
19 | n/a | The above copyright notice and this permission notice shall be included |
---|
20 | n/a | in all copies or substantial portions of the Software. |
---|
21 | n/a | |
---|
22 | n/a | THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS |
---|
23 | n/a | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
---|
24 | n/a | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
---|
25 | n/a | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR |
---|
26 | n/a | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
---|
27 | n/a | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
---|
28 | n/a | OTHER DEALINGS IN THE SOFTWARE. |
---|
29 | n/a | ----------------------------------------------------------------------- */ |
---|
30 | n/a | |
---|
31 | n/a | #include "ffi.h" |
---|
32 | n/a | |
---|
33 | n/a | #ifndef POWERPC64 |
---|
34 | n/a | #include "ffi_common.h" |
---|
35 | n/a | #include "ffi_powerpc.h" |
---|
36 | n/a | |
---|
37 | n/a | |
---|
38 | n/a | /* About the SYSV ABI. */ |
---|
39 | n/a | #define ASM_NEEDS_REGISTERS 4 |
---|
40 | n/a | #define NUM_GPR_ARG_REGISTERS 8 |
---|
41 | n/a | #define NUM_FPR_ARG_REGISTERS 8 |
---|
42 | n/a | |
---|
43 | n/a | |
---|
44 | n/a | #if HAVE_LONG_DOUBLE_VARIANT && FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
45 | n/a | /* Adjust size of ffi_type_longdouble. */ |
---|
46 | n/a | void FFI_HIDDEN |
---|
47 | n/a | ffi_prep_types_sysv (ffi_abi abi) |
---|
48 | n/a | { |
---|
49 | n/a | if ((abi & (FFI_SYSV | FFI_SYSV_LONG_DOUBLE_128)) == FFI_SYSV) |
---|
50 | n/a | { |
---|
51 | n/a | ffi_type_longdouble.size = 8; |
---|
52 | n/a | ffi_type_longdouble.alignment = 8; |
---|
53 | n/a | } |
---|
54 | n/a | else |
---|
55 | n/a | { |
---|
56 | n/a | ffi_type_longdouble.size = 16; |
---|
57 | n/a | ffi_type_longdouble.alignment = 16; |
---|
58 | n/a | } |
---|
59 | n/a | } |
---|
60 | n/a | #endif |
---|
61 | n/a | |
---|
62 | n/a | /* Transform long double, double and float to other types as per abi. */ |
---|
63 | n/a | static int |
---|
64 | n/a | translate_float (int abi, int type) |
---|
65 | n/a | { |
---|
66 | n/a | #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
67 | n/a | if (type == FFI_TYPE_LONGDOUBLE |
---|
68 | n/a | && (abi & FFI_SYSV_LONG_DOUBLE_128) == 0) |
---|
69 | n/a | type = FFI_TYPE_DOUBLE; |
---|
70 | n/a | #endif |
---|
71 | n/a | if ((abi & FFI_SYSV_SOFT_FLOAT) != 0) |
---|
72 | n/a | { |
---|
73 | n/a | if (type == FFI_TYPE_FLOAT) |
---|
74 | n/a | type = FFI_TYPE_UINT32; |
---|
75 | n/a | else if (type == FFI_TYPE_DOUBLE) |
---|
76 | n/a | type = FFI_TYPE_UINT64; |
---|
77 | n/a | #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
78 | n/a | else if (type == FFI_TYPE_LONGDOUBLE) |
---|
79 | n/a | type = FFI_TYPE_UINT128; |
---|
80 | n/a | } |
---|
81 | n/a | else if ((abi & FFI_SYSV_IBM_LONG_DOUBLE) == 0) |
---|
82 | n/a | { |
---|
83 | n/a | if (type == FFI_TYPE_LONGDOUBLE) |
---|
84 | n/a | type = FFI_TYPE_STRUCT; |
---|
85 | n/a | #endif |
---|
86 | n/a | } |
---|
87 | n/a | return type; |
---|
88 | n/a | } |
---|
89 | n/a | |
---|
90 | n/a | /* Perform machine dependent cif processing */ |
---|
91 | n/a | static ffi_status |
---|
92 | n/a | ffi_prep_cif_sysv_core (ffi_cif *cif) |
---|
93 | n/a | { |
---|
94 | n/a | ffi_type **ptr; |
---|
95 | n/a | unsigned bytes; |
---|
96 | n/a | unsigned i, fparg_count = 0, intarg_count = 0; |
---|
97 | n/a | unsigned flags = cif->flags; |
---|
98 | n/a | unsigned struct_copy_size = 0; |
---|
99 | n/a | unsigned type = cif->rtype->type; |
---|
100 | n/a | unsigned size = cif->rtype->size; |
---|
101 | n/a | |
---|
102 | n/a | /* The machine-independent calculation of cif->bytes doesn't work |
---|
103 | n/a | for us. Redo the calculation. */ |
---|
104 | n/a | |
---|
105 | n/a | /* Space for the frame pointer, callee's LR, and the asm's temp regs. */ |
---|
106 | n/a | bytes = (2 + ASM_NEEDS_REGISTERS) * sizeof (int); |
---|
107 | n/a | |
---|
108 | n/a | /* Space for the GPR registers. */ |
---|
109 | n/a | bytes += NUM_GPR_ARG_REGISTERS * sizeof (int); |
---|
110 | n/a | |
---|
111 | n/a | /* Return value handling. The rules for SYSV are as follows: |
---|
112 | n/a | - 32-bit (or less) integer values are returned in gpr3; |
---|
113 | n/a | - Structures of size <= 4 bytes also returned in gpr3; |
---|
114 | n/a | - 64-bit integer values and structures between 5 and 8 bytes are returned |
---|
115 | n/a | in gpr3 and gpr4; |
---|
116 | n/a | - Larger structures are allocated space and a pointer is passed as |
---|
117 | n/a | the first argument. |
---|
118 | n/a | - Single/double FP values are returned in fpr1; |
---|
119 | n/a | - long doubles (if not equivalent to double) are returned in |
---|
120 | n/a | fpr1,fpr2 for Linux and as for large structs for SysV. */ |
---|
121 | n/a | |
---|
122 | n/a | type = translate_float (cif->abi, type); |
---|
123 | n/a | |
---|
124 | n/a | switch (type) |
---|
125 | n/a | { |
---|
126 | n/a | #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
127 | n/a | case FFI_TYPE_LONGDOUBLE: |
---|
128 | n/a | flags |= FLAG_RETURNS_128BITS; |
---|
129 | n/a | /* Fall through. */ |
---|
130 | n/a | #endif |
---|
131 | n/a | case FFI_TYPE_DOUBLE: |
---|
132 | n/a | flags |= FLAG_RETURNS_64BITS; |
---|
133 | n/a | /* Fall through. */ |
---|
134 | n/a | case FFI_TYPE_FLOAT: |
---|
135 | n/a | flags |= FLAG_RETURNS_FP; |
---|
136 | n/a | #ifdef __NO_FPRS__ |
---|
137 | n/a | return FFI_BAD_ABI; |
---|
138 | n/a | #endif |
---|
139 | n/a | break; |
---|
140 | n/a | |
---|
141 | n/a | case FFI_TYPE_UINT128: |
---|
142 | n/a | flags |= FLAG_RETURNS_128BITS; |
---|
143 | n/a | /* Fall through. */ |
---|
144 | n/a | case FFI_TYPE_UINT64: |
---|
145 | n/a | case FFI_TYPE_SINT64: |
---|
146 | n/a | flags |= FLAG_RETURNS_64BITS; |
---|
147 | n/a | break; |
---|
148 | n/a | |
---|
149 | n/a | case FFI_TYPE_STRUCT: |
---|
150 | n/a | /* The final SYSV ABI says that structures smaller or equal 8 bytes |
---|
151 | n/a | are returned in r3/r4. A draft ABI used by linux instead |
---|
152 | n/a | returns them in memory. */ |
---|
153 | n/a | if ((cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8) |
---|
154 | n/a | { |
---|
155 | n/a | flags |= FLAG_RETURNS_SMST; |
---|
156 | n/a | break; |
---|
157 | n/a | } |
---|
158 | n/a | intarg_count++; |
---|
159 | n/a | flags |= FLAG_RETVAL_REFERENCE; |
---|
160 | n/a | /* Fall through. */ |
---|
161 | n/a | case FFI_TYPE_VOID: |
---|
162 | n/a | flags |= FLAG_RETURNS_NOTHING; |
---|
163 | n/a | break; |
---|
164 | n/a | |
---|
165 | n/a | default: |
---|
166 | n/a | /* Returns 32-bit integer, or similar. Nothing to do here. */ |
---|
167 | n/a | break; |
---|
168 | n/a | } |
---|
169 | n/a | |
---|
170 | n/a | /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the |
---|
171 | n/a | first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest |
---|
172 | n/a | goes on the stack. Structures and long doubles (if not equivalent |
---|
173 | n/a | to double) are passed as a pointer to a copy of the structure. |
---|
174 | n/a | Stuff on the stack needs to keep proper alignment. */ |
---|
175 | n/a | for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++) |
---|
176 | n/a | { |
---|
177 | n/a | unsigned short typenum = (*ptr)->type; |
---|
178 | n/a | |
---|
179 | n/a | typenum = translate_float (cif->abi, typenum); |
---|
180 | n/a | |
---|
181 | n/a | switch (typenum) |
---|
182 | n/a | { |
---|
183 | n/a | #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
184 | n/a | case FFI_TYPE_LONGDOUBLE: |
---|
185 | n/a | fparg_count++; |
---|
186 | n/a | /* Fall thru */ |
---|
187 | n/a | #endif |
---|
188 | n/a | case FFI_TYPE_DOUBLE: |
---|
189 | n/a | fparg_count++; |
---|
190 | n/a | /* If this FP arg is going on the stack, it must be |
---|
191 | n/a | 8-byte-aligned. */ |
---|
192 | n/a | if (fparg_count > NUM_FPR_ARG_REGISTERS |
---|
193 | n/a | && intarg_count >= NUM_GPR_ARG_REGISTERS |
---|
194 | n/a | && intarg_count % 2 != 0) |
---|
195 | n/a | intarg_count++; |
---|
196 | n/a | #ifdef __NO_FPRS__ |
---|
197 | n/a | return FFI_BAD_ABI; |
---|
198 | n/a | #endif |
---|
199 | n/a | break; |
---|
200 | n/a | |
---|
201 | n/a | case FFI_TYPE_FLOAT: |
---|
202 | n/a | fparg_count++; |
---|
203 | n/a | #ifdef __NO_FPRS__ |
---|
204 | n/a | return FFI_BAD_ABI; |
---|
205 | n/a | #endif |
---|
206 | n/a | break; |
---|
207 | n/a | |
---|
208 | n/a | case FFI_TYPE_UINT128: |
---|
209 | n/a | /* A long double in FFI_LINUX_SOFT_FLOAT can use only a set |
---|
210 | n/a | of four consecutive gprs. If we do not have enough, we |
---|
211 | n/a | have to adjust the intarg_count value. */ |
---|
212 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3 |
---|
213 | n/a | && intarg_count < NUM_GPR_ARG_REGISTERS) |
---|
214 | n/a | intarg_count = NUM_GPR_ARG_REGISTERS; |
---|
215 | n/a | intarg_count += 4; |
---|
216 | n/a | break; |
---|
217 | n/a | |
---|
218 | n/a | case FFI_TYPE_UINT64: |
---|
219 | n/a | case FFI_TYPE_SINT64: |
---|
220 | n/a | /* 'long long' arguments are passed as two words, but |
---|
221 | n/a | either both words must fit in registers or both go |
---|
222 | n/a | on the stack. If they go on the stack, they must |
---|
223 | n/a | be 8-byte-aligned. |
---|
224 | n/a | |
---|
225 | n/a | Also, only certain register pairs can be used for |
---|
226 | n/a | passing long long int -- specifically (r3,r4), (r5,r6), |
---|
227 | n/a | (r7,r8), (r9,r10). */ |
---|
228 | n/a | if (intarg_count == NUM_GPR_ARG_REGISTERS-1 |
---|
229 | n/a | || intarg_count % 2 != 0) |
---|
230 | n/a | intarg_count++; |
---|
231 | n/a | intarg_count += 2; |
---|
232 | n/a | break; |
---|
233 | n/a | |
---|
234 | n/a | case FFI_TYPE_STRUCT: |
---|
235 | n/a | /* We must allocate space for a copy of these to enforce |
---|
236 | n/a | pass-by-value. Pad the space up to a multiple of 16 |
---|
237 | n/a | bytes (the maximum alignment required for anything under |
---|
238 | n/a | the SYSV ABI). */ |
---|
239 | n/a | struct_copy_size += ((*ptr)->size + 15) & ~0xF; |
---|
240 | n/a | /* Fall through (allocate space for the pointer). */ |
---|
241 | n/a | |
---|
242 | n/a | case FFI_TYPE_POINTER: |
---|
243 | n/a | case FFI_TYPE_INT: |
---|
244 | n/a | case FFI_TYPE_UINT32: |
---|
245 | n/a | case FFI_TYPE_SINT32: |
---|
246 | n/a | case FFI_TYPE_UINT16: |
---|
247 | n/a | case FFI_TYPE_SINT16: |
---|
248 | n/a | case FFI_TYPE_UINT8: |
---|
249 | n/a | case FFI_TYPE_SINT8: |
---|
250 | n/a | /* Everything else is passed as a 4-byte word in a GPR, either |
---|
251 | n/a | the object itself or a pointer to it. */ |
---|
252 | n/a | intarg_count++; |
---|
253 | n/a | break; |
---|
254 | n/a | |
---|
255 | n/a | default: |
---|
256 | n/a | FFI_ASSERT (0); |
---|
257 | n/a | } |
---|
258 | n/a | } |
---|
259 | n/a | |
---|
260 | n/a | if (fparg_count != 0) |
---|
261 | n/a | flags |= FLAG_FP_ARGUMENTS; |
---|
262 | n/a | if (intarg_count > 4) |
---|
263 | n/a | flags |= FLAG_4_GPR_ARGUMENTS; |
---|
264 | n/a | if (struct_copy_size != 0) |
---|
265 | n/a | flags |= FLAG_ARG_NEEDS_COPY; |
---|
266 | n/a | |
---|
267 | n/a | /* Space for the FPR registers, if needed. */ |
---|
268 | n/a | if (fparg_count != 0) |
---|
269 | n/a | bytes += NUM_FPR_ARG_REGISTERS * sizeof (double); |
---|
270 | n/a | |
---|
271 | n/a | /* Stack space. */ |
---|
272 | n/a | if (intarg_count > NUM_GPR_ARG_REGISTERS) |
---|
273 | n/a | bytes += (intarg_count - NUM_GPR_ARG_REGISTERS) * sizeof (int); |
---|
274 | n/a | if (fparg_count > NUM_FPR_ARG_REGISTERS) |
---|
275 | n/a | bytes += (fparg_count - NUM_FPR_ARG_REGISTERS) * sizeof (double); |
---|
276 | n/a | |
---|
277 | n/a | /* The stack space allocated needs to be a multiple of 16 bytes. */ |
---|
278 | n/a | bytes = (bytes + 15) & ~0xF; |
---|
279 | n/a | |
---|
280 | n/a | /* Add in the space for the copied structures. */ |
---|
281 | n/a | bytes += struct_copy_size; |
---|
282 | n/a | |
---|
283 | n/a | cif->flags = flags; |
---|
284 | n/a | cif->bytes = bytes; |
---|
285 | n/a | |
---|
286 | n/a | return FFI_OK; |
---|
287 | n/a | } |
---|
288 | n/a | |
---|
289 | n/a | ffi_status FFI_HIDDEN |
---|
290 | n/a | ffi_prep_cif_sysv (ffi_cif *cif) |
---|
291 | n/a | { |
---|
292 | n/a | if ((cif->abi & FFI_SYSV) == 0) |
---|
293 | n/a | { |
---|
294 | n/a | /* This call is from old code. Translate to new ABI values. */ |
---|
295 | n/a | cif->flags |= FLAG_COMPAT; |
---|
296 | n/a | switch (cif->abi) |
---|
297 | n/a | { |
---|
298 | n/a | default: |
---|
299 | n/a | return FFI_BAD_ABI; |
---|
300 | n/a | |
---|
301 | n/a | case FFI_COMPAT_SYSV: |
---|
302 | n/a | cif->abi = FFI_SYSV | FFI_SYSV_STRUCT_RET | FFI_SYSV_LONG_DOUBLE_128; |
---|
303 | n/a | break; |
---|
304 | n/a | |
---|
305 | n/a | case FFI_COMPAT_GCC_SYSV: |
---|
306 | n/a | cif->abi = FFI_SYSV | FFI_SYSV_LONG_DOUBLE_128; |
---|
307 | n/a | break; |
---|
308 | n/a | |
---|
309 | n/a | case FFI_COMPAT_LINUX: |
---|
310 | n/a | cif->abi = (FFI_SYSV | FFI_SYSV_IBM_LONG_DOUBLE |
---|
311 | n/a | | FFI_SYSV_LONG_DOUBLE_128); |
---|
312 | n/a | break; |
---|
313 | n/a | |
---|
314 | n/a | case FFI_COMPAT_LINUX_SOFT_FLOAT: |
---|
315 | n/a | cif->abi = (FFI_SYSV | FFI_SYSV_SOFT_FLOAT | FFI_SYSV_IBM_LONG_DOUBLE |
---|
316 | n/a | | FFI_SYSV_LONG_DOUBLE_128); |
---|
317 | n/a | break; |
---|
318 | n/a | } |
---|
319 | n/a | } |
---|
320 | n/a | return ffi_prep_cif_sysv_core (cif); |
---|
321 | n/a | } |
---|
322 | n/a | |
---|
323 | n/a | /* ffi_prep_args_SYSV is called by the assembly routine once stack space |
---|
324 | n/a | has been allocated for the function's arguments. |
---|
325 | n/a | |
---|
326 | n/a | The stack layout we want looks like this: |
---|
327 | n/a | |
---|
328 | n/a | | Return address from ffi_call_SYSV 4bytes | higher addresses |
---|
329 | n/a | |--------------------------------------------| |
---|
330 | n/a | | Previous backchain pointer 4 | stack pointer here |
---|
331 | n/a | |--------------------------------------------|<+ <<< on entry to |
---|
332 | n/a | | Saved r28-r31 4*4 | | ffi_call_SYSV |
---|
333 | n/a | |--------------------------------------------| | |
---|
334 | n/a | | GPR registers r3-r10 8*4 | | ffi_call_SYSV |
---|
335 | n/a | |--------------------------------------------| | |
---|
336 | n/a | | FPR registers f1-f8 (optional) 8*8 | | |
---|
337 | n/a | |--------------------------------------------| | stack | |
---|
338 | n/a | | Space for copied structures | | grows | |
---|
339 | n/a | |--------------------------------------------| | down V |
---|
340 | n/a | | Parameters that didn't fit in registers | | |
---|
341 | n/a | |--------------------------------------------| | lower addresses |
---|
342 | n/a | | Space for callee's LR 4 | | |
---|
343 | n/a | |--------------------------------------------| | stack pointer here |
---|
344 | n/a | | Current backchain pointer 4 |-/ during |
---|
345 | n/a | |--------------------------------------------| <<< ffi_call_SYSV |
---|
346 | n/a | |
---|
347 | n/a | */ |
---|
348 | n/a | |
---|
349 | n/a | void FFI_HIDDEN |
---|
350 | n/a | ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack) |
---|
351 | n/a | { |
---|
352 | n/a | const unsigned bytes = ecif->cif->bytes; |
---|
353 | n/a | const unsigned flags = ecif->cif->flags; |
---|
354 | n/a | |
---|
355 | n/a | typedef union |
---|
356 | n/a | { |
---|
357 | n/a | char *c; |
---|
358 | n/a | unsigned *u; |
---|
359 | n/a | long long *ll; |
---|
360 | n/a | float *f; |
---|
361 | n/a | double *d; |
---|
362 | n/a | } valp; |
---|
363 | n/a | |
---|
364 | n/a | /* 'stacktop' points at the previous backchain pointer. */ |
---|
365 | n/a | valp stacktop; |
---|
366 | n/a | |
---|
367 | n/a | /* 'gpr_base' points at the space for gpr3, and grows upwards as |
---|
368 | n/a | we use GPR registers. */ |
---|
369 | n/a | valp gpr_base; |
---|
370 | n/a | int intarg_count; |
---|
371 | n/a | |
---|
372 | n/a | #ifndef __NO_FPRS__ |
---|
373 | n/a | /* 'fpr_base' points at the space for fpr1, and grows upwards as |
---|
374 | n/a | we use FPR registers. */ |
---|
375 | n/a | valp fpr_base; |
---|
376 | n/a | int fparg_count; |
---|
377 | n/a | #endif |
---|
378 | n/a | |
---|
379 | n/a | /* 'copy_space' grows down as we put structures in it. It should |
---|
380 | n/a | stay 16-byte aligned. */ |
---|
381 | n/a | valp copy_space; |
---|
382 | n/a | |
---|
383 | n/a | /* 'next_arg' grows up as we put parameters in it. */ |
---|
384 | n/a | valp next_arg; |
---|
385 | n/a | |
---|
386 | n/a | int i; |
---|
387 | n/a | ffi_type **ptr; |
---|
388 | n/a | #ifndef __NO_FPRS__ |
---|
389 | n/a | double double_tmp; |
---|
390 | n/a | #endif |
---|
391 | n/a | union |
---|
392 | n/a | { |
---|
393 | n/a | void **v; |
---|
394 | n/a | char **c; |
---|
395 | n/a | signed char **sc; |
---|
396 | n/a | unsigned char **uc; |
---|
397 | n/a | signed short **ss; |
---|
398 | n/a | unsigned short **us; |
---|
399 | n/a | unsigned int **ui; |
---|
400 | n/a | long long **ll; |
---|
401 | n/a | float **f; |
---|
402 | n/a | double **d; |
---|
403 | n/a | } p_argv; |
---|
404 | n/a | size_t struct_copy_size; |
---|
405 | n/a | unsigned gprvalue; |
---|
406 | n/a | |
---|
407 | n/a | stacktop.c = (char *) stack + bytes; |
---|
408 | n/a | gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS; |
---|
409 | n/a | intarg_count = 0; |
---|
410 | n/a | #ifndef __NO_FPRS__ |
---|
411 | n/a | fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS; |
---|
412 | n/a | fparg_count = 0; |
---|
413 | n/a | copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c); |
---|
414 | n/a | #else |
---|
415 | n/a | copy_space.c = gpr_base.c; |
---|
416 | n/a | #endif |
---|
417 | n/a | next_arg.u = stack + 2; |
---|
418 | n/a | |
---|
419 | n/a | /* Check that everything starts aligned properly. */ |
---|
420 | n/a | FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0); |
---|
421 | n/a | FFI_ASSERT (((unsigned long) copy_space.c & 0xF) == 0); |
---|
422 | n/a | FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0); |
---|
423 | n/a | FFI_ASSERT ((bytes & 0xF) == 0); |
---|
424 | n/a | FFI_ASSERT (copy_space.c >= next_arg.c); |
---|
425 | n/a | |
---|
426 | n/a | /* Deal with return values that are actually pass-by-reference. */ |
---|
427 | n/a | if (flags & FLAG_RETVAL_REFERENCE) |
---|
428 | n/a | { |
---|
429 | n/a | *gpr_base.u++ = (unsigned long) (char *) ecif->rvalue; |
---|
430 | n/a | intarg_count++; |
---|
431 | n/a | } |
---|
432 | n/a | |
---|
433 | n/a | /* Now for the arguments. */ |
---|
434 | n/a | p_argv.v = ecif->avalue; |
---|
435 | n/a | for (ptr = ecif->cif->arg_types, i = ecif->cif->nargs; |
---|
436 | n/a | i > 0; |
---|
437 | n/a | i--, ptr++, p_argv.v++) |
---|
438 | n/a | { |
---|
439 | n/a | unsigned int typenum = (*ptr)->type; |
---|
440 | n/a | |
---|
441 | n/a | typenum = translate_float (ecif->cif->abi, typenum); |
---|
442 | n/a | |
---|
443 | n/a | /* Now test the translated value */ |
---|
444 | n/a | switch (typenum) |
---|
445 | n/a | { |
---|
446 | n/a | #ifndef __NO_FPRS__ |
---|
447 | n/a | # if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
448 | n/a | case FFI_TYPE_LONGDOUBLE: |
---|
449 | n/a | double_tmp = (*p_argv.d)[0]; |
---|
450 | n/a | |
---|
451 | n/a | if (fparg_count >= NUM_FPR_ARG_REGISTERS - 1) |
---|
452 | n/a | { |
---|
453 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS |
---|
454 | n/a | && intarg_count % 2 != 0) |
---|
455 | n/a | { |
---|
456 | n/a | intarg_count++; |
---|
457 | n/a | next_arg.u++; |
---|
458 | n/a | } |
---|
459 | n/a | *next_arg.d = double_tmp; |
---|
460 | n/a | next_arg.u += 2; |
---|
461 | n/a | double_tmp = (*p_argv.d)[1]; |
---|
462 | n/a | *next_arg.d = double_tmp; |
---|
463 | n/a | next_arg.u += 2; |
---|
464 | n/a | } |
---|
465 | n/a | else |
---|
466 | n/a | { |
---|
467 | n/a | *fpr_base.d++ = double_tmp; |
---|
468 | n/a | double_tmp = (*p_argv.d)[1]; |
---|
469 | n/a | *fpr_base.d++ = double_tmp; |
---|
470 | n/a | } |
---|
471 | n/a | |
---|
472 | n/a | fparg_count += 2; |
---|
473 | n/a | FFI_ASSERT (flags & FLAG_FP_ARGUMENTS); |
---|
474 | n/a | break; |
---|
475 | n/a | # endif |
---|
476 | n/a | case FFI_TYPE_DOUBLE: |
---|
477 | n/a | double_tmp = **p_argv.d; |
---|
478 | n/a | |
---|
479 | n/a | if (fparg_count >= NUM_FPR_ARG_REGISTERS) |
---|
480 | n/a | { |
---|
481 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS |
---|
482 | n/a | && intarg_count % 2 != 0) |
---|
483 | n/a | { |
---|
484 | n/a | intarg_count++; |
---|
485 | n/a | next_arg.u++; |
---|
486 | n/a | } |
---|
487 | n/a | *next_arg.d = double_tmp; |
---|
488 | n/a | next_arg.u += 2; |
---|
489 | n/a | } |
---|
490 | n/a | else |
---|
491 | n/a | *fpr_base.d++ = double_tmp; |
---|
492 | n/a | fparg_count++; |
---|
493 | n/a | FFI_ASSERT (flags & FLAG_FP_ARGUMENTS); |
---|
494 | n/a | break; |
---|
495 | n/a | |
---|
496 | n/a | case FFI_TYPE_FLOAT: |
---|
497 | n/a | double_tmp = **p_argv.f; |
---|
498 | n/a | if (fparg_count >= NUM_FPR_ARG_REGISTERS) |
---|
499 | n/a | { |
---|
500 | n/a | *next_arg.f = (float) double_tmp; |
---|
501 | n/a | next_arg.u += 1; |
---|
502 | n/a | intarg_count++; |
---|
503 | n/a | } |
---|
504 | n/a | else |
---|
505 | n/a | *fpr_base.d++ = double_tmp; |
---|
506 | n/a | fparg_count++; |
---|
507 | n/a | FFI_ASSERT (flags & FLAG_FP_ARGUMENTS); |
---|
508 | n/a | break; |
---|
509 | n/a | #endif /* have FPRs */ |
---|
510 | n/a | |
---|
511 | n/a | case FFI_TYPE_UINT128: |
---|
512 | n/a | /* The soft float ABI for long doubles works like this, a long double |
---|
513 | n/a | is passed in four consecutive GPRs if available. A maximum of 2 |
---|
514 | n/a | long doubles can be passed in gprs. If we do not have 4 GPRs |
---|
515 | n/a | left, the long double is passed on the stack, 4-byte aligned. */ |
---|
516 | n/a | { |
---|
517 | n/a | unsigned int int_tmp; |
---|
518 | n/a | unsigned int ii; |
---|
519 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3) |
---|
520 | n/a | { |
---|
521 | n/a | if (intarg_count < NUM_GPR_ARG_REGISTERS) |
---|
522 | n/a | intarg_count = NUM_GPR_ARG_REGISTERS; |
---|
523 | n/a | for (ii = 0; ii < 4; ii++) |
---|
524 | n/a | { |
---|
525 | n/a | int_tmp = (*p_argv.ui)[ii]; |
---|
526 | n/a | *next_arg.u++ = int_tmp; |
---|
527 | n/a | } |
---|
528 | n/a | } |
---|
529 | n/a | else |
---|
530 | n/a | { |
---|
531 | n/a | for (ii = 0; ii < 4; ii++) |
---|
532 | n/a | { |
---|
533 | n/a | int_tmp = (*p_argv.ui)[ii]; |
---|
534 | n/a | *gpr_base.u++ = int_tmp; |
---|
535 | n/a | } |
---|
536 | n/a | } |
---|
537 | n/a | intarg_count += 4; |
---|
538 | n/a | break; |
---|
539 | n/a | } |
---|
540 | n/a | |
---|
541 | n/a | case FFI_TYPE_UINT64: |
---|
542 | n/a | case FFI_TYPE_SINT64: |
---|
543 | n/a | if (intarg_count == NUM_GPR_ARG_REGISTERS-1) |
---|
544 | n/a | intarg_count++; |
---|
545 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS) |
---|
546 | n/a | { |
---|
547 | n/a | if (intarg_count % 2 != 0) |
---|
548 | n/a | { |
---|
549 | n/a | intarg_count++; |
---|
550 | n/a | next_arg.u++; |
---|
551 | n/a | } |
---|
552 | n/a | *next_arg.ll = **p_argv.ll; |
---|
553 | n/a | next_arg.u += 2; |
---|
554 | n/a | } |
---|
555 | n/a | else |
---|
556 | n/a | { |
---|
557 | n/a | /* The abi states only certain register pairs can be |
---|
558 | n/a | used for passing long long int specifically (r3,r4), |
---|
559 | n/a | (r5,r6), (r7,r8), (r9,r10). If next arg is long long |
---|
560 | n/a | but not correct starting register of pair then skip |
---|
561 | n/a | until the proper starting register. */ |
---|
562 | n/a | if (intarg_count % 2 != 0) |
---|
563 | n/a | { |
---|
564 | n/a | intarg_count ++; |
---|
565 | n/a | gpr_base.u++; |
---|
566 | n/a | } |
---|
567 | n/a | *gpr_base.ll++ = **p_argv.ll; |
---|
568 | n/a | } |
---|
569 | n/a | intarg_count += 2; |
---|
570 | n/a | break; |
---|
571 | n/a | |
---|
572 | n/a | case FFI_TYPE_STRUCT: |
---|
573 | n/a | struct_copy_size = ((*ptr)->size + 15) & ~0xF; |
---|
574 | n/a | copy_space.c -= struct_copy_size; |
---|
575 | n/a | memcpy (copy_space.c, *p_argv.c, (*ptr)->size); |
---|
576 | n/a | |
---|
577 | n/a | gprvalue = (unsigned long) copy_space.c; |
---|
578 | n/a | |
---|
579 | n/a | FFI_ASSERT (copy_space.c > next_arg.c); |
---|
580 | n/a | FFI_ASSERT (flags & FLAG_ARG_NEEDS_COPY); |
---|
581 | n/a | goto putgpr; |
---|
582 | n/a | |
---|
583 | n/a | case FFI_TYPE_UINT8: |
---|
584 | n/a | gprvalue = **p_argv.uc; |
---|
585 | n/a | goto putgpr; |
---|
586 | n/a | case FFI_TYPE_SINT8: |
---|
587 | n/a | gprvalue = **p_argv.sc; |
---|
588 | n/a | goto putgpr; |
---|
589 | n/a | case FFI_TYPE_UINT16: |
---|
590 | n/a | gprvalue = **p_argv.us; |
---|
591 | n/a | goto putgpr; |
---|
592 | n/a | case FFI_TYPE_SINT16: |
---|
593 | n/a | gprvalue = **p_argv.ss; |
---|
594 | n/a | goto putgpr; |
---|
595 | n/a | |
---|
596 | n/a | case FFI_TYPE_INT: |
---|
597 | n/a | case FFI_TYPE_UINT32: |
---|
598 | n/a | case FFI_TYPE_SINT32: |
---|
599 | n/a | case FFI_TYPE_POINTER: |
---|
600 | n/a | |
---|
601 | n/a | gprvalue = **p_argv.ui; |
---|
602 | n/a | |
---|
603 | n/a | putgpr: |
---|
604 | n/a | if (intarg_count >= NUM_GPR_ARG_REGISTERS) |
---|
605 | n/a | *next_arg.u++ = gprvalue; |
---|
606 | n/a | else |
---|
607 | n/a | *gpr_base.u++ = gprvalue; |
---|
608 | n/a | intarg_count++; |
---|
609 | n/a | break; |
---|
610 | n/a | } |
---|
611 | n/a | } |
---|
612 | n/a | |
---|
613 | n/a | /* Check that we didn't overrun the stack... */ |
---|
614 | n/a | FFI_ASSERT (copy_space.c >= next_arg.c); |
---|
615 | n/a | FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS); |
---|
616 | n/a | /* The assert below is testing that the number of integer arguments agrees |
---|
617 | n/a | with the number found in ffi_prep_cif_machdep(). However, intarg_count |
---|
618 | n/a | is incremented whenever we place an FP arg on the stack, so account for |
---|
619 | n/a | that before our assert test. */ |
---|
620 | n/a | #ifndef __NO_FPRS__ |
---|
621 | n/a | if (fparg_count > NUM_FPR_ARG_REGISTERS) |
---|
622 | n/a | intarg_count -= fparg_count - NUM_FPR_ARG_REGISTERS; |
---|
623 | n/a | FFI_ASSERT (fpr_base.u |
---|
624 | n/a | <= stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS); |
---|
625 | n/a | #endif |
---|
626 | n/a | FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4); |
---|
627 | n/a | } |
---|
628 | n/a | |
---|
629 | n/a | #define MIN_CACHE_LINE_SIZE 8 |
---|
630 | n/a | |
---|
631 | n/a | static void |
---|
632 | n/a | flush_icache (char *wraddr, char *xaddr, int size) |
---|
633 | n/a | { |
---|
634 | n/a | int i; |
---|
635 | n/a | for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE) |
---|
636 | n/a | __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" |
---|
637 | n/a | : : "r" (xaddr + i), "r" (wraddr + i) : "memory"); |
---|
638 | n/a | __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;" |
---|
639 | n/a | : : "r"(xaddr + size - 1), "r"(wraddr + size - 1) |
---|
640 | n/a | : "memory"); |
---|
641 | n/a | } |
---|
642 | n/a | |
---|
643 | n/a | ffi_status FFI_HIDDEN |
---|
644 | n/a | ffi_prep_closure_loc_sysv (ffi_closure *closure, |
---|
645 | n/a | ffi_cif *cif, |
---|
646 | n/a | void (*fun) (ffi_cif *, void *, void **, void *), |
---|
647 | n/a | void *user_data, |
---|
648 | n/a | void *codeloc) |
---|
649 | n/a | { |
---|
650 | n/a | unsigned int *tramp; |
---|
651 | n/a | |
---|
652 | n/a | if (cif->abi < FFI_SYSV || cif->abi >= FFI_LAST_ABI) |
---|
653 | n/a | return FFI_BAD_ABI; |
---|
654 | n/a | |
---|
655 | n/a | tramp = (unsigned int *) &closure->tramp[0]; |
---|
656 | n/a | tramp[0] = 0x7c0802a6; /* mflr r0 */ |
---|
657 | n/a | tramp[1] = 0x4800000d; /* bl 10 <trampoline_initial+0x10> */ |
---|
658 | n/a | tramp[4] = 0x7d6802a6; /* mflr r11 */ |
---|
659 | n/a | tramp[5] = 0x7c0803a6; /* mtlr r0 */ |
---|
660 | n/a | tramp[6] = 0x800b0000; /* lwz r0,0(r11) */ |
---|
661 | n/a | tramp[7] = 0x816b0004; /* lwz r11,4(r11) */ |
---|
662 | n/a | tramp[8] = 0x7c0903a6; /* mtctr r0 */ |
---|
663 | n/a | tramp[9] = 0x4e800420; /* bctr */ |
---|
664 | n/a | *(void **) &tramp[2] = (void *) ffi_closure_SYSV; /* function */ |
---|
665 | n/a | *(void **) &tramp[3] = codeloc; /* context */ |
---|
666 | n/a | |
---|
667 | n/a | /* Flush the icache. */ |
---|
668 | n/a | flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE); |
---|
669 | n/a | |
---|
670 | n/a | closure->cif = cif; |
---|
671 | n/a | closure->fun = fun; |
---|
672 | n/a | closure->user_data = user_data; |
---|
673 | n/a | |
---|
674 | n/a | return FFI_OK; |
---|
675 | n/a | } |
---|
676 | n/a | |
---|
677 | n/a | /* Basically the trampoline invokes ffi_closure_SYSV, and on |
---|
678 | n/a | entry, r11 holds the address of the closure. |
---|
679 | n/a | After storing the registers that could possibly contain |
---|
680 | n/a | parameters to be passed into the stack frame and setting |
---|
681 | n/a | up space for a return value, ffi_closure_SYSV invokes the |
---|
682 | n/a | following helper function to do most of the work. */ |
---|
683 | n/a | |
---|
684 | n/a | int |
---|
685 | n/a | ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue, |
---|
686 | n/a | unsigned long *pgr, ffi_dblfl *pfr, |
---|
687 | n/a | unsigned long *pst) |
---|
688 | n/a | { |
---|
689 | n/a | /* rvalue is the pointer to space for return value in closure assembly */ |
---|
690 | n/a | /* pgr is the pointer to where r3-r10 are stored in ffi_closure_SYSV */ |
---|
691 | n/a | /* pfr is the pointer to where f1-f8 are stored in ffi_closure_SYSV */ |
---|
692 | n/a | /* pst is the pointer to outgoing parameter stack in original caller */ |
---|
693 | n/a | |
---|
694 | n/a | void ** avalue; |
---|
695 | n/a | ffi_type ** arg_types; |
---|
696 | n/a | long i, avn; |
---|
697 | n/a | #ifndef __NO_FPRS__ |
---|
698 | n/a | long nf = 0; /* number of floating registers already used */ |
---|
699 | n/a | #endif |
---|
700 | n/a | long ng = 0; /* number of general registers already used */ |
---|
701 | n/a | |
---|
702 | n/a | ffi_cif *cif = closure->cif; |
---|
703 | n/a | unsigned size = cif->rtype->size; |
---|
704 | n/a | unsigned short rtypenum = cif->rtype->type; |
---|
705 | n/a | |
---|
706 | n/a | avalue = alloca (cif->nargs * sizeof (void *)); |
---|
707 | n/a | |
---|
708 | n/a | /* First translate for softfloat/nonlinux */ |
---|
709 | n/a | rtypenum = translate_float (cif->abi, rtypenum); |
---|
710 | n/a | |
---|
711 | n/a | /* Copy the caller's structure return value address so that the closure |
---|
712 | n/a | returns the data directly to the caller. |
---|
713 | n/a | For FFI_SYSV the result is passed in r3/r4 if the struct size is less |
---|
714 | n/a | or equal 8 bytes. */ |
---|
715 | n/a | if (rtypenum == FFI_TYPE_STRUCT |
---|
716 | n/a | && !((cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8)) |
---|
717 | n/a | { |
---|
718 | n/a | rvalue = (void *) *pgr; |
---|
719 | n/a | ng++; |
---|
720 | n/a | pgr++; |
---|
721 | n/a | } |
---|
722 | n/a | |
---|
723 | n/a | i = 0; |
---|
724 | n/a | avn = cif->nargs; |
---|
725 | n/a | arg_types = cif->arg_types; |
---|
726 | n/a | |
---|
727 | n/a | /* Grab the addresses of the arguments from the stack frame. */ |
---|
728 | n/a | while (i < avn) { |
---|
729 | n/a | unsigned short typenum = arg_types[i]->type; |
---|
730 | n/a | |
---|
731 | n/a | /* We may need to handle some values depending on ABI. */ |
---|
732 | n/a | typenum = translate_float (cif->abi, typenum); |
---|
733 | n/a | |
---|
734 | n/a | switch (typenum) |
---|
735 | n/a | { |
---|
736 | n/a | #ifndef __NO_FPRS__ |
---|
737 | n/a | case FFI_TYPE_FLOAT: |
---|
738 | n/a | /* Unfortunately float values are stored as doubles |
---|
739 | n/a | in the ffi_closure_SYSV code (since we don't check |
---|
740 | n/a | the type in that routine). */ |
---|
741 | n/a | if (nf < NUM_FPR_ARG_REGISTERS) |
---|
742 | n/a | { |
---|
743 | n/a | /* FIXME? here we are really changing the values |
---|
744 | n/a | stored in the original calling routines outgoing |
---|
745 | n/a | parameter stack. This is probably a really |
---|
746 | n/a | naughty thing to do but... */ |
---|
747 | n/a | double temp = pfr->d; |
---|
748 | n/a | pfr->f = (float) temp; |
---|
749 | n/a | avalue[i] = pfr; |
---|
750 | n/a | nf++; |
---|
751 | n/a | pfr++; |
---|
752 | n/a | } |
---|
753 | n/a | else |
---|
754 | n/a | { |
---|
755 | n/a | avalue[i] = pst; |
---|
756 | n/a | pst += 1; |
---|
757 | n/a | } |
---|
758 | n/a | break; |
---|
759 | n/a | |
---|
760 | n/a | case FFI_TYPE_DOUBLE: |
---|
761 | n/a | if (nf < NUM_FPR_ARG_REGISTERS) |
---|
762 | n/a | { |
---|
763 | n/a | avalue[i] = pfr; |
---|
764 | n/a | nf++; |
---|
765 | n/a | pfr++; |
---|
766 | n/a | } |
---|
767 | n/a | else |
---|
768 | n/a | { |
---|
769 | n/a | if (((long) pst) & 4) |
---|
770 | n/a | pst++; |
---|
771 | n/a | avalue[i] = pst; |
---|
772 | n/a | pst += 2; |
---|
773 | n/a | } |
---|
774 | n/a | break; |
---|
775 | n/a | |
---|
776 | n/a | # if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE |
---|
777 | n/a | case FFI_TYPE_LONGDOUBLE: |
---|
778 | n/a | if (nf < NUM_FPR_ARG_REGISTERS - 1) |
---|
779 | n/a | { |
---|
780 | n/a | avalue[i] = pfr; |
---|
781 | n/a | pfr += 2; |
---|
782 | n/a | nf += 2; |
---|
783 | n/a | } |
---|
784 | n/a | else |
---|
785 | n/a | { |
---|
786 | n/a | if (((long) pst) & 4) |
---|
787 | n/a | pst++; |
---|
788 | n/a | avalue[i] = pst; |
---|
789 | n/a | pst += 4; |
---|
790 | n/a | nf = 8; |
---|
791 | n/a | } |
---|
792 | n/a | break; |
---|
793 | n/a | # endif |
---|
794 | n/a | #endif |
---|
795 | n/a | |
---|
796 | n/a | case FFI_TYPE_UINT128: |
---|
797 | n/a | /* Test if for the whole long double, 4 gprs are available. |
---|
798 | n/a | otherwise the stuff ends up on the stack. */ |
---|
799 | n/a | if (ng < NUM_GPR_ARG_REGISTERS - 3) |
---|
800 | n/a | { |
---|
801 | n/a | avalue[i] = pgr; |
---|
802 | n/a | pgr += 4; |
---|
803 | n/a | ng += 4; |
---|
804 | n/a | } |
---|
805 | n/a | else |
---|
806 | n/a | { |
---|
807 | n/a | avalue[i] = pst; |
---|
808 | n/a | pst += 4; |
---|
809 | n/a | ng = 8+4; |
---|
810 | n/a | } |
---|
811 | n/a | break; |
---|
812 | n/a | |
---|
813 | n/a | case FFI_TYPE_SINT8: |
---|
814 | n/a | case FFI_TYPE_UINT8: |
---|
815 | n/a | #ifndef __LITTLE_ENDIAN__ |
---|
816 | n/a | if (ng < NUM_GPR_ARG_REGISTERS) |
---|
817 | n/a | { |
---|
818 | n/a | avalue[i] = (char *) pgr + 3; |
---|
819 | n/a | ng++; |
---|
820 | n/a | pgr++; |
---|
821 | n/a | } |
---|
822 | n/a | else |
---|
823 | n/a | { |
---|
824 | n/a | avalue[i] = (char *) pst + 3; |
---|
825 | n/a | pst++; |
---|
826 | n/a | } |
---|
827 | n/a | break; |
---|
828 | n/a | #endif |
---|
829 | n/a | |
---|
830 | n/a | case FFI_TYPE_SINT16: |
---|
831 | n/a | case FFI_TYPE_UINT16: |
---|
832 | n/a | #ifndef __LITTLE_ENDIAN__ |
---|
833 | n/a | if (ng < NUM_GPR_ARG_REGISTERS) |
---|
834 | n/a | { |
---|
835 | n/a | avalue[i] = (char *) pgr + 2; |
---|
836 | n/a | ng++; |
---|
837 | n/a | pgr++; |
---|
838 | n/a | } |
---|
839 | n/a | else |
---|
840 | n/a | { |
---|
841 | n/a | avalue[i] = (char *) pst + 2; |
---|
842 | n/a | pst++; |
---|
843 | n/a | } |
---|
844 | n/a | break; |
---|
845 | n/a | #endif |
---|
846 | n/a | |
---|
847 | n/a | case FFI_TYPE_SINT32: |
---|
848 | n/a | case FFI_TYPE_UINT32: |
---|
849 | n/a | case FFI_TYPE_POINTER: |
---|
850 | n/a | if (ng < NUM_GPR_ARG_REGISTERS) |
---|
851 | n/a | { |
---|
852 | n/a | avalue[i] = pgr; |
---|
853 | n/a | ng++; |
---|
854 | n/a | pgr++; |
---|
855 | n/a | } |
---|
856 | n/a | else |
---|
857 | n/a | { |
---|
858 | n/a | avalue[i] = pst; |
---|
859 | n/a | pst++; |
---|
860 | n/a | } |
---|
861 | n/a | break; |
---|
862 | n/a | |
---|
863 | n/a | case FFI_TYPE_STRUCT: |
---|
864 | n/a | /* Structs are passed by reference. The address will appear in a |
---|
865 | n/a | gpr if it is one of the first 8 arguments. */ |
---|
866 | n/a | if (ng < NUM_GPR_ARG_REGISTERS) |
---|
867 | n/a | { |
---|
868 | n/a | avalue[i] = (void *) *pgr; |
---|
869 | n/a | ng++; |
---|
870 | n/a | pgr++; |
---|
871 | n/a | } |
---|
872 | n/a | else |
---|
873 | n/a | { |
---|
874 | n/a | avalue[i] = (void *) *pst; |
---|
875 | n/a | pst++; |
---|
876 | n/a | } |
---|
877 | n/a | break; |
---|
878 | n/a | |
---|
879 | n/a | case FFI_TYPE_SINT64: |
---|
880 | n/a | case FFI_TYPE_UINT64: |
---|
881 | n/a | /* Passing long long ints are complex, they must |
---|
882 | n/a | be passed in suitable register pairs such as |
---|
883 | n/a | (r3,r4) or (r5,r6) or (r6,r7), or (r7,r8) or (r9,r10) |
---|
884 | n/a | and if the entire pair aren't available then the outgoing |
---|
885 | n/a | parameter stack is used for both but an alignment of 8 |
---|
886 | n/a | must will be kept. So we must either look in pgr |
---|
887 | n/a | or pst to find the correct address for this type |
---|
888 | n/a | of parameter. */ |
---|
889 | n/a | if (ng < NUM_GPR_ARG_REGISTERS - 1) |
---|
890 | n/a | { |
---|
891 | n/a | if (ng & 1) |
---|
892 | n/a | { |
---|
893 | n/a | /* skip r4, r6, r8 as starting points */ |
---|
894 | n/a | ng++; |
---|
895 | n/a | pgr++; |
---|
896 | n/a | } |
---|
897 | n/a | avalue[i] = pgr; |
---|
898 | n/a | ng += 2; |
---|
899 | n/a | pgr += 2; |
---|
900 | n/a | } |
---|
901 | n/a | else |
---|
902 | n/a | { |
---|
903 | n/a | if (((long) pst) & 4) |
---|
904 | n/a | pst++; |
---|
905 | n/a | avalue[i] = pst; |
---|
906 | n/a | pst += 2; |
---|
907 | n/a | ng = NUM_GPR_ARG_REGISTERS; |
---|
908 | n/a | } |
---|
909 | n/a | break; |
---|
910 | n/a | |
---|
911 | n/a | default: |
---|
912 | n/a | FFI_ASSERT (0); |
---|
913 | n/a | } |
---|
914 | n/a | |
---|
915 | n/a | i++; |
---|
916 | n/a | } |
---|
917 | n/a | |
---|
918 | n/a | (closure->fun) (cif, rvalue, avalue, closure->user_data); |
---|
919 | n/a | |
---|
920 | n/a | /* Tell ffi_closure_SYSV how to perform return type promotions. |
---|
921 | n/a | Because the FFI_SYSV ABI returns the structures <= 8 bytes in |
---|
922 | n/a | r3/r4 we have to tell ffi_closure_SYSV how to treat them. We |
---|
923 | n/a | combine the base type FFI_SYSV_TYPE_SMALL_STRUCT with the size of |
---|
924 | n/a | the struct less one. We never have a struct with size zero. |
---|
925 | n/a | See the comment in ffitarget.h about ordering. */ |
---|
926 | n/a | if (rtypenum == FFI_TYPE_STRUCT |
---|
927 | n/a | && (cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8) |
---|
928 | n/a | return FFI_SYSV_TYPE_SMALL_STRUCT - 1 + size; |
---|
929 | n/a | return rtypenum; |
---|
930 | n/a | } |
---|
931 | n/a | #endif |
---|