Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(129486)

Side by Side Diff: Modules/_ctypes/libffi_ios/aarch64/sysv_arm64.S

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #ifdef __arm64__
2
3 /* Copyright (c) 2009, 2010, 2011, 2012 ARM Ltd.
4
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 ``Software''), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #define LIBFFI_ASM
25 #include <fficonfig.h>
26 #include <ffi.h>
27 #include <ffi_cfi.h>
28 #include "internal.h"
29
30 #ifdef HAVE_MACHINE_ASM_H
31 #include <machine/asm.h>
32 #else
33 #ifdef __USER_LABEL_PREFIX__
34 #define CONCAT1(a, b) CONCAT2(a, b)
35 #define CONCAT2(a, b) a ## b
36
37 /* Use the right prefix for global labels. */
38 #define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
39 #else
40 #define CNAME(x) x
41 #endif
42 #endif
43
44 #ifdef __AARCH64EB__
45 # define BE(X) X
46 #else
47 # define BE(X) 0
48 #endif
49
50 #ifdef __ILP32__
51 #define PTR_REG(n) w##n
52 #else
53 #define PTR_REG(n) x##n
54 #endif
55
56 #ifdef __ILP32__
57 #define PTR_SIZE 4
58 #else
59 #define PTR_SIZE 8
60 #endif
61
62 .text
63 .align 4
64
65 /* ffi_call_SYSV
66 extern void ffi_call_SYSV (void *stack, void *frame,
67 void (*fn)(void), void *rvalue,
68 int flags, void *closure);
69
70 Therefore on entry we have:
71
72 x0 stack
73 x1 frame
74 x2 fn
75 x3 rvalue
76 x4 flags
77 x5 closure
78 */
79
80 cfi_startproc
81 CNAME(ffi_call_SYSV):
82 /* Use a stack frame allocated by our caller. */
83 cfi_def_cfa(x1, 32);
84 stp x29, x30, [x1]
85 mov x29, x1
86 mov sp, x0
87 cfi_def_cfa_register(x29)
88 cfi_rel_offset (x29, 0)
89 cfi_rel_offset (x30, 8)
90
91 mov x9, x2 /* save fn */
92 mov x8, x3 /* install structure return */
93 #ifdef FFI_GO_CLOSURES
94 mov x18, x5 /* install static chain */
95 #endif
96 stp x3, x4, [x29, #16] /* save rvalue and flags */
97
98 /* Load the vector argument passing registers, if necessary. */
99 tbz w4, #AARCH64_FLAG_ARG_V_BIT, 1f
100 ldp q0, q1, [sp, #0]
101 ldp q2, q3, [sp, #32]
102 ldp q4, q5, [sp, #64]
103 ldp q6, q7, [sp, #96]
104 1:
105 /* Load the core argument passing registers, including
106 the structure return pointer. */
107 ldp x0, x1, [sp, #16*N_V_ARG_REG + 0]
108 ldp x2, x3, [sp, #16*N_V_ARG_REG + 16]
109 ldp x4, x5, [sp, #16*N_V_ARG_REG + 32]
110 ldp x6, x7, [sp, #16*N_V_ARG_REG + 48]
111
112 /* Deallocate the context, leaving the stacked arguments. */
113 add sp, sp, #CALL_CONTEXT_SIZE
114
115 blr x9 /* call fn */
116
117 ldp x3, x4, [x29, #16] /* reload rvalue and flags */
118
119 /* Partially deconstruct the stack frame. */
120 mov sp, x29
121 cfi_def_cfa_register (sp)
122 ldp x29, x30, [x29]
123
124 /* Save the return value as directed. */
125 adr x5, 0f
126 and w4, w4, #AARCH64_RET_MASK
127 add x5, x5, x4, lsl #3
128 br x5
129
130 /* Note that each table entry is 2 insns, and thus 8 bytes.
131 For integer data, note that we're storing into ffi_arg
132 and therefore we want to extend to 64 bits; these types
133 have two consecutive entries allocated for them. */
134 .align 4
135 0: ret /* VOID */
136 nop
137 1: str x0, [x3] /* INT64 */
138 ret
139 2: stp x0, x1, [x3] /* INT128 */
140 ret
141 3: brk #1000 /* UNUSED */
142 ret
143 4: brk #1000 /* UNUSED */
144 ret
145 5: brk #1000 /* UNUSED */
146 ret
147 6: brk #1000 /* UNUSED */
148 ret
149 7: brk #1000 /* UNUSED */
150 ret
151 8: st4 { v0.s, v1.s, v2.s, v3.s }[0], [x3] /* S4 */
152 ret
153 9: st3 { v0.s, v1.s, v2.s }[0], [x3] /* S3 */
154 ret
155 10: stp s0, s1, [x3] /* S2 */
156 ret
157 11: str s0, [x3] /* S1 */
158 ret
159 12: st4 { v0.d, v1.d, v2.d, v3.d }[0], [x3] /* D4 */
160 ret
161 13: st3 { v0.d, v1.d, v2.d }[0], [x3] /* D3 */
162 ret
163 14: stp d0, d1, [x3] /* D2 */
164 ret
165 15: str d0, [x3] /* D1 */
166 ret
167 16: str q3, [x3, #48] /* Q4 */
168 nop
169 17: str q2, [x3, #32] /* Q3 */
170 nop
171 18: stp q0, q1, [x3] /* Q2 */
172 ret
173 19: str q0, [x3] /* Q1 */
174 ret
175 20: uxtb w0, w0 /* UINT8 */
176 str x0, [x3]
177 21: ret /* reserved */
178 nop
179 22: uxth w0, w0 /* UINT16 */
180 str x0, [x3]
181 23: ret /* reserved */
182 nop
183 24: mov w0, w0 /* UINT32 */
184 str x0, [x3]
185 25: ret /* reserved */
186 nop
187 26: sxtb x0, w0 /* SINT8 */
188 str x0, [x3]
189 27: ret /* reserved */
190 nop
191 28: sxth x0, w0 /* SINT16 */
192 str x0, [x3]
193 29: ret /* reserved */
194 nop
195 30: sxtw x0, w0 /* SINT32 */
196 str x0, [x3]
197 31: ret /* reserved */
198 nop
199
200 cfi_endproc
201
202 .globl CNAME(ffi_call_SYSV)
203 #ifdef __ELF__
204 .type CNAME(ffi_call_SYSV), #function
205 .hidden CNAME(ffi_call_SYSV)
206 .size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV)
207 #endif
208
209 /* ffi_closure_SYSV
210
211 Closure invocation glue. This is the low level code invoked directly by
212 the closure trampoline to setup and call a closure.
213
214 On entry x17 points to a struct ffi_closure, x16 has been clobbered
215 all other registers are preserved.
216
217 We allocate a call context and save the argument passing registers,
218 then invoked the generic C ffi_closure_SYSV_inner() function to do all
219 the real work, on return we load the result passing registers back from
220 the call context.
221 */
222
223 #define ffi_closure_SYSV_FS (8*2 + CALL_CONTEXT_SIZE + 64)
224
225 .align 4
226 CNAME(ffi_closure_SYSV_V):
227 cfi_startproc
228 stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
229 cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
230 cfi_rel_offset (x29, 0)
231 cfi_rel_offset (x30, 8)
232
233 /* Save the argument passing vector registers. */
234 stp q0, q1, [sp, #16 + 0]
235 stp q2, q3, [sp, #16 + 32]
236 stp q4, q5, [sp, #16 + 64]
237 stp q6, q7, [sp, #16 + 96]
238 b 0f
239 cfi_endproc
240
241 .globl CNAME(ffi_closure_SYSV_V)
242 #ifdef __ELF__
243 .type CNAME(ffi_closure_SYSV_V), #function
244 .hidden CNAME(ffi_closure_SYSV_V)
245 .size CNAME(ffi_closure_SYSV_V), . - CNAME(ffi_closure_SYSV_V)
246 #endif
247
248 .align 4
249 cfi_startproc
250 CNAME(ffi_closure_SYSV):
251 stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
252 cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
253 cfi_rel_offset (x29, 0)
254 cfi_rel_offset (x30, 8)
255 0:
256 mov x29, sp
257
258 /* Save the argument passing core registers. */
259 stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0]
260 stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16]
261 stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32]
262 stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
263
264 /* Load ffi_closure_inner arguments. */
265 ldp PTR_REG(0), PTR_REG(1), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET] /* load cif, fn */
266 ldr PTR_REG(2), [x17, #FFI_TRAMPOLINE_CLOSURE_OFFSET+PTR_SIZE*2] /* load user_data */
267 .Ldo_closure:
268 add x3, sp, #16 /* load context */
269 add x4, sp, #ffi_closure_SYSV_FS /* load stack */
270 add x5, sp, #16+CALL_CONTEXT_SIZE /* load rvalue */
271 mov x6, x8 /* load struct_rval */
272 bl CNAME(ffi_closure_SYSV_inner)
273
274 /* Load the return value as directed. */
275 adr x1, 0f
276 and w0, w0, #AARCH64_RET_MASK
277 add x1, x1, x0, lsl #3
278 add x3, sp, #16+CALL_CONTEXT_SIZE
279 br x1
280
281 /* Note that each table entry is 2 insns, and thus 8 bytes. */
282 .align 4
283 0: b 99f /* VOID */
284 nop
285 1: ldr x0, [x3] /* INT64 */
286 b 99f
287 2: ldp x0, x1, [x3] /* INT128 */
288 b 99f
289 3: brk #1000 /* UNUSED */
290 nop
291 4: brk #1000 /* UNUSED */
292 nop
293 5: brk #1000 /* UNUSED */
294 nop
295 6: brk #1000 /* UNUSED */
296 nop
297 7: brk #1000 /* UNUSED */
298 nop
299 8: ldr s3, [x3, #12] /* S4 */
300 nop
301 9: ldr s2, [x2, #8] /* S3 */
302 nop
303 10: ldp s0, s1, [x3] /* S2 */
304 b 99f
305 11: ldr s0, [x3] /* S1 */
306 b 99f
307 12: ldr d3, [x3, #24] /* D4 */
308 nop
309 13: ldr d2, [x3, #16] /* D3 */
310 nop
311 14: ldp d0, d1, [x3] /* D2 */
312 b 99f
313 15: ldr d0, [x3] /* D1 */
314 b 99f
315 16: ldr q3, [x3, #48] /* Q4 */
316 nop
317 17: ldr q2, [x3, #32] /* Q3 */
318 nop
319 18: ldp q0, q1, [x3] /* Q2 */
320 b 99f
321 19: ldr q0, [x3] /* Q1 */
322 b 99f
323 20: ldrb w0, [x3, #BE(7)] /* UINT8 */
324 b 99f
325 21: brk #1000 /* reserved */
326 nop
327 22: ldrh w0, [x3, #BE(6)] /* UINT16 */
328 b 99f
329 23: brk #1000 /* reserved */
330 nop
331 24: ldr w0, [x3, #BE(4)] /* UINT32 */
332 b 99f
333 25: brk #1000 /* reserved */
334 nop
335 26: ldrsb x0, [x3, #BE(7)] /* SINT8 */
336 b 99f
337 27: brk #1000 /* reserved */
338 nop
339 28: ldrsh x0, [x3, #BE(6)] /* SINT16 */
340 b 99f
341 29: brk #1000 /* reserved */
342 nop
343 30: ldrsw x0, [x3, #BE(4)] /* SINT32 */
344 nop
345 31: /* reserved */
346 99: ldp x29, x30, [sp], #ffi_closure_SYSV_FS
347 cfi_adjust_cfa_offset (-ffi_closure_SYSV_FS)
348 cfi_restore (x29)
349 cfi_restore (x30)
350 ret
351 cfi_endproc
352
353 .globl CNAME(ffi_closure_SYSV)
354 #ifdef __ELF__
355 .type CNAME(ffi_closure_SYSV), #function
356 .hidden CNAME(ffi_closure_SYSV)
357 .size CNAME(ffi_closure_SYSV), . - CNAME(ffi_closure_SYSV)
358 #endif
359
360 #if FFI_EXEC_TRAMPOLINE_TABLE
361
362 #ifdef __MACH__
363 #include <mach/vm_param.h>
364 .align PAGE_MAX_SHIFT
365 CNAME(ffi_closure_trampoline_table_page):
366 .rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
367 adr x16, -PAGE_MAX_SIZE
368 ldp x17, x16, [x16]
369 br x16
370 nop /* each entry in the trampoline config page is 2*sizeof( void*) so the trampoline itself cannot be smaller that 16 bytes */
371 .endr
372
373 .globl CNAME(ffi_closure_trampoline_table_page)
374 #ifdef __ELF__
375 .type CNAME(ffi_closure_trampoline_table_page), #function
376 .hidden CNAME(ffi_closure_trampoline_table_page)
377 .size CNAME(ffi_closure_trampoline_table_page), . - CNAME(ffi_closure_ trampoline_table_page)
378 #endif
379 #endif
380
381 #endif /* FFI_EXEC_TRAMPOLINE_TABLE */
382
383 #ifdef FFI_GO_CLOSURES
384 .align 4
385 CNAME(ffi_go_closure_SYSV_V):
386 cfi_startproc
387 stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
388 cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
389 cfi_rel_offset (x29, 0)
390 cfi_rel_offset (x30, 8)
391
392 /* Save the argument passing vector registers. */
393 stp q0, q1, [sp, #16 + 0]
394 stp q2, q3, [sp, #16 + 32]
395 stp q4, q5, [sp, #16 + 64]
396 stp q6, q7, [sp, #16 + 96]
397 b 0f
398 cfi_endproc
399
400 .globl CNAME(ffi_go_closure_SYSV_V)
401 #ifdef __ELF__
402 .type CNAME(ffi_go_closure_SYSV_V), #function
403 .hidden CNAME(ffi_go_closure_SYSV_V)
404 .size CNAME(ffi_go_closure_SYSV_V), . - CNAME(ffi_go_closure_SYSV_V)
405 #endif
406
407 .align 4
408 cfi_startproc
409 CNAME(ffi_go_closure_SYSV):
410 stp x29, x30, [sp, #-ffi_closure_SYSV_FS]!
411 cfi_adjust_cfa_offset (ffi_closure_SYSV_FS)
412 cfi_rel_offset (x29, 0)
413 cfi_rel_offset (x30, 8)
414 0:
415 mov x29, sp
416
417 /* Save the argument passing core registers. */
418 stp x0, x1, [sp, #16 + 16*N_V_ARG_REG + 0]
419 stp x2, x3, [sp, #16 + 16*N_V_ARG_REG + 16]
420 stp x4, x5, [sp, #16 + 16*N_V_ARG_REG + 32]
421 stp x6, x7, [sp, #16 + 16*N_V_ARG_REG + 48]
422
423 /* Load ffi_closure_inner arguments. */
424 ldp PTR_REG(0), PTR_REG(1), [x18, #PTR_SIZE]/* load cif, fn */
425 mov x2, x18 /* load user_data */
426 b .Ldo_closure
427 cfi_endproc
428
429 .globl CNAME(ffi_go_closure_SYSV)
430 #ifdef __ELF__
431 .type CNAME(ffi_go_closure_SYSV), #function
432 .hidden CNAME(ffi_go_closure_SYSV)
433 .size CNAME(ffi_go_closure_SYSV), . - CNAME(ffi_go_closure_SYSV)
434 #endif
435 #endif /* FFI_GO_CLOSURES */
436
437 #if defined __ELF__ && defined __linux__
438 .section .note.GNU-stack,"",%progbits
439 #endif
440
441
442
443 #endif
OLDNEW
« no previous file with comments | « Modules/_ctypes/libffi_ios/aarch64/internal.h ('k') | Modules/_ctypes/libffi_ios/arm/ffi_armv7.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+