aboutsummaryrefslogtreecommitdiff
path: root/src/vm_arm64.dasc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/vm_arm64.dasc130
1 files changed, 121 insertions, 9 deletions
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index 895262e0..a31cbb3a 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -853,7 +853,8 @@ static void build_subroutines(BuildCtx *ctx)
853 | str PC, SAVE_PC 853 | str PC, SAVE_PC
854 | add CARG3, RA, NARGS8:RC 854 | add CARG3, RA, NARGS8:RC
855 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top) 855 | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
856 | ldp LFUNC:CARG3, PC, [RA, FRAME_FUNC] // Guaranteed to be a function here. 856 | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
857 | ldr PC, [BASE, FRAME_PC]
857 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now. 858 | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
858 | and LFUNC:CARG3, CARG3, #LJ_GCVMASK 859 | and LFUNC:CARG3, CARG3, #LJ_GCVMASK
859 | b ->BC_CALLT2_Z 860 | b ->BC_CALLT2_Z
@@ -1859,18 +1860,89 @@ static void build_subroutines(BuildCtx *ctx)
1859 |// Saveregs already performed. Callback slot number in [sp], g in r12. 1860 |// Saveregs already performed. Callback slot number in [sp], g in r12.
1860 |->vm_ffi_callback: 1861 |->vm_ffi_callback:
1861 |.if FFI 1862 |.if FFI
1862 | NYI 1863 |.type CTSTATE, CTState, PC
1864 | saveregs
1865 | ldr CTSTATE, GL:x10->ctype_state
1866 | mov GL, x10
1867 | add x10, sp, # CFRAME_SPACE
1868 | str w9, CTSTATE->cb.slot
1869 | stp x0, x1, CTSTATE->cb.gpr[0]
1870 | stp d0, d1, CTSTATE->cb.fpr[0]
1871 | stp x2, x3, CTSTATE->cb.gpr[2]
1872 | stp d2, d3, CTSTATE->cb.fpr[2]
1873 | stp x4, x5, CTSTATE->cb.gpr[4]
1874 | stp d4, d5, CTSTATE->cb.fpr[4]
1875 | stp x6, x7, CTSTATE->cb.gpr[6]
1876 | stp d6, d7, CTSTATE->cb.fpr[6]
1877 | str x10, CTSTATE->cb.stack
1878 | mov CARG1, CTSTATE
1879 | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
1880 | mov CARG2, sp
1881 | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
1882 | // Returns lua_State *.
1883 | ldp BASE, RC, L:CRET1->base
1884 | movz TISNUM, #(LJ_TISNUM>>1)&0xffff, lsl #48
1885 | movz TISNUMhi, #(LJ_TISNUM>>1)&0xffff, lsl #16
1886 | movn TISNIL, #0
1887 | mov L, CRET1
1888 | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
1889 | sub RC, RC, BASE
1890 | st_vmstate ST_INTERP
1891 | and LFUNC:CARG3, CARG3, #LJ_GCVMASK
1892 | ins_callt
1863 |.endif 1893 |.endif
1864 | 1894 |
1865 |->cont_ffi_callback: // Return from FFI callback. 1895 |->cont_ffi_callback: // Return from FFI callback.
1866 |.if FFI 1896 |.if FFI
1867 | NYI 1897 | ldr CTSTATE, GL->ctype_state
1898 | stp BASE, CARG4, L->base
1899 | str L, CTSTATE->L
1900 | mov CARG1, CTSTATE
1901 | mov CARG2, RA
1902 | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
1903 | ldp x0, x1, CTSTATE->cb.gpr[0]
1904 | ldp d0, d1, CTSTATE->cb.fpr[0]
1905 | b ->vm_leave_unw
1868 |.endif 1906 |.endif
1869 | 1907 |
1870 |->vm_ffi_call: // Call C function via FFI. 1908 |->vm_ffi_call: // Call C function via FFI.
1871 | // Caveat: needs special frame unwinding, see below. 1909 | // Caveat: needs special frame unwinding, see below.
1872 |.if FFI 1910 |.if FFI
1873 | NYI 1911 | .type CCSTATE, CCallState, x19
1912 | stp fp, lr, [sp, #-32]!
1913 | add fp, sp, #0
1914 | str CCSTATE, [sp, #16]
1915 | mov CCSTATE, x0
1916 | ldr TMP0w, CCSTATE:x0->spadj
1917 | ldrb TMP1w, CCSTATE->nsp
1918 | add TMP2, CCSTATE, #offsetof(CCallState, stack)
1919 | subs TMP1, TMP1, #1
1920 | ldr TMP3, CCSTATE->func
1921 | sub sp, fp, TMP0
1922 | bmi >2
1923 |1: // Copy stack slots
1924 | ldr TMP0, [TMP2, TMP1, lsl #3]
1925 | str TMP0, [sp, TMP1, lsl #3]
1926 | subs TMP1, TMP1, #1
1927 | bpl <1
1928 |2:
1929 | ldp x0, x1, CCSTATE->gpr[0]
1930 | ldp d0, d1, CCSTATE->fpr[0]
1931 | ldp x2, x3, CCSTATE->gpr[2]
1932 | ldp d2, d3, CCSTATE->fpr[2]
1933 | ldp x4, x5, CCSTATE->gpr[4]
1934 | ldp d4, d5, CCSTATE->fpr[4]
1935 | ldp x6, x7, CCSTATE->gpr[6]
1936 | ldp d6, d7, CCSTATE->fpr[6]
1937 | ldr x8, CCSTATE->retp
1938 | blr TMP3
1939 | mov sp, fp
1940 | stp x0, x1, CCSTATE->gpr[0]
1941 | stp d0, d1, CCSTATE->fpr[0]
1942 | stp d2, d3, CCSTATE->fpr[2]
1943 | ldr CCSTATE, [sp, #16]
1944 | ldp fp, lr, [sp], #32
1945 | ret
1874 |.endif 1946 |.endif
1875 |// Note: vm_ffi_call must be the last function in this object file! 1947 |// Note: vm_ffi_call must be the last function in this object file!
1876 | 1948 |
@@ -2087,7 +2159,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
2087 | 2159 |
2088 |.if FFI 2160 |.if FFI
2089 |7: 2161 |7:
2090 | asr ITYPE, TMP0, #47 2162 | asr ITYPE, CARG1, #47
2091 | cmn ITYPE, #-LJ_TCDATA 2163 | cmn ITYPE, #-LJ_TCDATA
2092 | bne <2 2164 | bne <2
2093 | b ->vmeta_equal_cd 2165 | b ->vmeta_equal_cd
@@ -3600,7 +3672,19 @@ static void emit_asm_debug(BuildCtx *ctx)
3600 "\t.align 3\n" 3672 "\t.align 3\n"
3601 ".LEFDE0:\n\n"); 3673 ".LEFDE0:\n\n");
3602#if LJ_HASFFI 3674#if LJ_HASFFI
3603#error "NYI" 3675 fprintf(ctx->fp,
3676 ".LSFDE1:\n"
3677 "\t.long .LEFDE1-.LASFDE1\n"
3678 ".LASFDE1:\n"
3679 "\t.long .Lframe0\n"
3680 "\t.quad lj_vm_ffi_call\n"
3681 "\t.quad %d\n"
3682 "\t.byte 0xe\n\t.uleb128 32\n" /* def_cfa_offset */
3683 "\t.byte 0x9d\n\t.uleb128 4\n" /* offset fp */
3684 "\t.byte 0x9e\n\t.uleb128 3\n" /* offset lr */
3685 "\t.byte 0x93\n\t.uleb128 2\n" /* offset x19 */
3686 "\t.align 3\n"
3687 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
3604#endif 3688#endif
3605 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",%%progbits\n"); 3689 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",%%progbits\n");
3606 fprintf(ctx->fp, 3690 fprintf(ctx->fp,
@@ -3615,7 +3699,7 @@ static void emit_asm_debug(BuildCtx *ctx)
3615 "\t.byte 30\n" /* Return address is in lr. */ 3699 "\t.byte 30\n" /* Return address is in lr. */
3616 "\t.uleb128 6\n" /* augmentation length */ 3700 "\t.uleb128 6\n" /* augmentation length */
3617 "\t.byte 0x1b\n" /* pcrel|sdata4 */ 3701 "\t.byte 0x1b\n" /* pcrel|sdata4 */
3618 "\t.long lj_err_unwind_dwarf-.\n" 3702 "\t.long lj_err_unwind_dwarf-.\n"
3619 "\t.byte 0x1b\n" /* pcrel|sdata4 */ 3703 "\t.byte 0x1b\n" /* pcrel|sdata4 */
3620 "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */ 3704 "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */
3621 "\t.align 3\n" 3705 "\t.align 3\n"
@@ -3627,7 +3711,7 @@ static void emit_asm_debug(BuildCtx *ctx)
3627 "\t.long .LASFDE2-.Lframe1\n" 3711 "\t.long .LASFDE2-.Lframe1\n"
3628 "\t.long .Lbegin-.\n" 3712 "\t.long .Lbegin-.\n"
3629 "\t.long %d\n" 3713 "\t.long %d\n"
3630 "\t.uleb128 0\n" /* augmentation length */ 3714 "\t.uleb128 0\n" /* augmentation length */
3631 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ 3715 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
3632 "\t.byte 0x9d\n\t.uleb128 %d\n" /* offset fp */ 3716 "\t.byte 0x9d\n\t.uleb128 %d\n" /* offset fp */
3633 "\t.byte 0x9e\n\t.uleb128 %d\n", /* offset lr */ 3717 "\t.byte 0x9e\n\t.uleb128 %d\n", /* offset lr */
@@ -3641,7 +3725,35 @@ static void emit_asm_debug(BuildCtx *ctx)
3641 "\t.align 3\n" 3725 "\t.align 3\n"
3642 ".LEFDE2:\n\n"); 3726 ".LEFDE2:\n\n");
3643#if LJ_HASFFI 3727#if LJ_HASFFI
3644#error "NYI" 3728 fprintf(ctx->fp,
3729 ".Lframe2:\n"
3730 "\t.long .LECIE2-.LSCIE2\n"
3731 ".LSCIE2:\n"
3732 "\t.long 0\n"
3733 "\t.byte 0x1\n"
3734 "\t.string \"zR\"\n"
3735 "\t.uleb128 0x1\n"
3736 "\t.sleb128 -8\n"
3737 "\t.byte 30\n" /* Return address is in lr. */
3738 "\t.uleb128 1\n" /* augmentation length */
3739 "\t.byte 0x1b\n" /* pcrel|sdata4 */
3740 "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */
3741 "\t.align 3\n"
3742 ".LECIE2:\n\n");
3743 fprintf(ctx->fp,
3744 ".LSFDE3:\n"
3745 "\t.long .LEFDE3-.LASFDE3\n"
3746 ".LASFDE3:\n"
3747 "\t.long .LASFDE3-.Lframe2\n"
3748 "\t.long lj_vm_ffi_call-.\n"
3749 "\t.long %d\n"
3750 "\t.uleb128 0\n" /* augmentation length */
3751 "\t.byte 0xe\n\t.uleb128 32\n" /* def_cfa_offset */
3752 "\t.byte 0x9d\n\t.uleb128 4\n" /* offset fp */
3753 "\t.byte 0x9e\n\t.uleb128 3\n" /* offset lr */
3754 "\t.byte 0x93\n\t.uleb128 2\n" /* offset x19 */
3755 "\t.align 3\n"
3756 ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
3645#endif 3757#endif
3646 break; 3758 break;
3647 default: 3759 default: