summaryrefslogtreecommitdiff
path: root/src/buildvm_arm.dasc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/buildvm_arm.dasc60
1 files changed, 56 insertions, 4 deletions
diff --git a/src/buildvm_arm.dasc b/src/buildvm_arm.dasc
index 29c616e0..60857c08 100644
--- a/src/buildvm_arm.dasc
+++ b/src/buildvm_arm.dasc
@@ -502,22 +502,30 @@ static void build_subroutines(BuildCtx *ctx)
502 | ldr CARG1, [BASE, #-16] // Get continuation. 502 | ldr CARG1, [BASE, #-16] // Get continuation.
503 | mov CARG4, BASE 503 | mov CARG4, BASE
504 | mov BASE, RB // Restore caller BASE. 504 | mov BASE, RB // Restore caller BASE.
505 | cmp CARG1, #0 505#if LJ_HASFFI
506 | cmp CARG1, #1
507#endif
506 | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC]. 508 | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC].
507 | beq >1
508 | ldr CARG3, LFUNC:CARG3->field_pc 509 | ldr CARG3, LFUNC:CARG3->field_pc
509 | mvn INS, #~LJ_TNIL 510 | mvn INS, #~LJ_TNIL
510 | add CARG2, RA, RC 511 | add CARG2, RA, RC
511 | str INS, [CARG2, #-4] // Ensure one valid arg. 512 | str INS, [CARG2, #-4] // Ensure one valid arg.
513#if LJ_HASFFI
514 | bls >1
515#endif
512 | ldr KBASE, [CARG3, #PC2PROTO(k)] 516 | ldr KBASE, [CARG3, #PC2PROTO(k)]
513 | // BASE = base, RA = resultptr, CARG4 = meta base 517 | // BASE = base, RA = resultptr, CARG4 = meta base
514 | bx CARG1 518 | bx CARG1
515 | 519 |
516 |1: // Tail call from C function. 520#if LJ_HASFFI
521 |1:
522 | beq ->cont_ffi_callback // cont = 1: return from FFI callback.
523 | // cont = 0: tailcall from C function.
517 | ldr CARG3, [BASE, FRAME_FUNC] 524 | ldr CARG3, [BASE, FRAME_FUNC]
518 | sub CARG4, CARG4, #16 525 | sub CARG4, CARG4, #16
519 | sub RC, CARG4, BASE 526 | sub RC, CARG4, BASE
520 | b ->vm_call_tail 527 | b ->vm_call_tail
528#endif
521 | 529 |
522 |->cont_cat: // RA = resultptr, CARG4 = meta base 530 |->cont_cat: // RA = resultptr, CARG4 = meta base
523 | ldr INS, [PC, #-4] 531 | ldr INS, [PC, #-4]
@@ -2178,6 +2186,50 @@ static void build_subroutines(BuildCtx *ctx)
2178 |//-- FFI helper functions ----------------------------------------------- 2186 |//-- FFI helper functions -----------------------------------------------
2179 |//----------------------------------------------------------------------- 2187 |//-----------------------------------------------------------------------
2180 | 2188 |
2189 |// Handler for callback functions.
2190 |// Saveregs already performed. Callback slot number in [sp], g in r12.
2191 |->vm_ffi_callback:
2192#if LJ_HASFFI
2193 |.type CTSTATE, CTState, PC
2194 | ldr CTSTATE, GL:r12->ctype_state
2195 | add DISPATCH, r12, #GG_G2DISP
2196 | strd CARG12, CTSTATE->cb.gpr[0]
2197 | strd CARG34, CTSTATE->cb.gpr[2]
2198 | ldr CARG4, [sp]
2199 | add CARG3, sp, #CFRAME_SIZE
2200 | mov CARG1, CTSTATE
2201 | lsr CARG4, CARG4, #3
2202 | str CARG3, CTSTATE->cb.stack
2203 | mov CARG2, sp
2204 | str CARG4, CTSTATE->cb.slot
2205 | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
2206 | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
2207 | // Returns lua_State *.
2208 | ldr BASE, L:CRET1->base
2209 | mv_vmstate CARG2, INTERP
2210 | ldr RC, L:CRET1->top
2211 | mov MASKR8, #255
2212 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
2213 | mov L, CRET1
2214 | sub RC, RC, BASE
2215 | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
2216 | st_vmstate CARG2
2217 | ins_callt
2218#endif
2219 |
2220 |->cont_ffi_callback: // Return from FFI callback.
2221#if LJ_HASFFI
2222 | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]
2223 | str BASE, L->base
2224 | str CARG4, L->top
2225 | str L, CTSTATE->L
2226 | mov CARG1, CTSTATE
2227 | mov CARG2, RA
2228 | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
2229 | ldrd CARG12, CTSTATE->cb.gpr[0]
2230 | b ->vm_leave_unw
2231#endif
2232 |
2181 |->vm_ffi_call: // Call C function via FFI. 2233 |->vm_ffi_call: // Call C function via FFI.
2182 | // Caveat: needs special frame unwinding, see below. 2234 | // Caveat: needs special frame unwinding, see below.
2183#if LJ_HASFFI 2235#if LJ_HASFFI