|
| 1 | +#if defined(__aarch64__) /* HOST_ARCH_ARM64 */ |
| 2 | + |
| 3 | +.text |
| 4 | + |
| 5 | +#if defined(__ANDROID__) || defined(__linux__) || defined(__FreeBSD__) |
| 6 | +/* HOST_OS_ANDROID || HOST_OS_LINUX */ |
| 7 | +.global FfiTrampolineCall |
| 8 | +.align 2 |
| 9 | +FfiTrampolineCall: |
| 10 | +#else /* HOST_OS_MACOS */ |
| 11 | +.global _FfiTrampolineCall |
| 12 | +.align 2 |
| 13 | +_FfiTrampolineCall: |
| 14 | +#endif |
| 15 | + |
| 16 | +/* Save argument in scratch register. */ |
| 17 | +stp x19, x20, [sp, #-16]! /* Push x19 and x20, we use x19 as scratch. */ |
| 18 | +mov x19, x0 /* Save argument in scratch register. */ |
| 19 | + |
| 20 | +/* Enter frame. */ |
| 21 | +stp fp, lr, [sp, #-16]! |
| 22 | +mov fp, sp |
| 23 | + |
| 24 | +/* Reserve framespace for arguments. */ |
| 25 | +ldr x9, [x19, #(8*18)] /* Load number of stack arguments. */ |
| 26 | +lsl x9, x9, #3 /* Multiply by size (8 bytes). */ |
| 27 | +sub sp, sp, x9 /* Reserve num_stack_args stack slots. */ |
| 28 | + |
| 29 | +/* Stack alignment. */ |
| 30 | +ldr x10, [x19, #(8*17)] /* Load stack alignment mask. */ |
| 31 | +mov x11, sp |
| 32 | +and x11, x11, x10 /* Align stack. */ |
| 33 | +mov sp, x11 |
| 34 | + |
| 35 | +/* Copy stack arguments. */ |
| 36 | +cmp x9, #0 /* Check if number of stack arguments is 0. */ |
| 37 | +beq .done /* Skip loop if no stack arguments. */ |
| 38 | +add x19, x19, #(8*19) /* Offset r19 to point to stack arguments. */ |
| 39 | +.align 2 |
| 40 | +.loop: /* Copy stack arguments loop. */ |
| 41 | +sub x9, x9, #8 /* Decrement stack argument iterator. */ |
| 42 | +ldr x10, [x19, x9] /* Load value from ffi_marshalled_args. */ |
| 43 | +str x10, [sp, x9] /* Store value on stack. */ |
| 44 | +cmp x9, #0 /* Compare iterator with 0 */ |
| 45 | +bne .loop /* Loop while iterator is not 0 */ |
| 46 | +sub x19, x19, #(8*19) /* Restore r19 to original value. */ |
| 47 | +.align 2 |
| 48 | +.done: /* End stack arguments loop. */ |
| 49 | + |
| 50 | +/* Copy registers and fpu registers. */ |
| 51 | +ldp x0, x1, [x19, #(8*1)] /* and #(8*2) */ |
| 52 | +ldp x2, x3, [x19, #(8*3)] /* and #(8*4) */ |
| 53 | +ldp x4, x5, [x19, #(8*5)] /* ... */ |
| 54 | +ldp x6, x7, [x19, #(8*7)] |
| 55 | +ldp d0, d1, [x19, #(8*9)] |
| 56 | +ldp d2, d3, [x19, #(8*11)] |
| 57 | +ldp d4, d5, [x19, #(8*13)] |
| 58 | +ldp d6, d7, [x19, #(8*15)] |
| 59 | + |
| 60 | +/* Do call. */ |
| 61 | +ldr x9, [x19] /* Load function address. */ |
| 62 | +blr x9 /* Call the function. */ |
| 63 | + |
| 64 | +/* Copy results back. */ |
| 65 | +str x0, [x19, #(8*0)] /* Move integer result in kOffsetIntResult. */ |
| 66 | +str d0, [x19, #(8*1)] /* Move double result in kOffsetDoubleResult. */ |
| 67 | + |
| 68 | +/* Leave frame. */ |
| 69 | +mov sp, fp |
| 70 | +ldp fp, lr, [sp], #16 |
| 71 | + |
| 72 | +/* Restore caller saved register. */ |
| 73 | +ldp x19, x20, [sp], #16 /* Pop x19 and x20. */ |
| 74 | +ret |
| 75 | + |
| 76 | +#endif /* HOST_ARCH_ARM64 */ |
0 commit comments