diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_ccallback.c | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c index 799dcd0e..66a09440 100644 --- a/src/lj_ccallback.c +++ b/src/lj_ccallback.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | #if LJ_OS_NOJIT | 28 | #if LJ_OS_NOJIT |
29 | 29 | ||
30 | /* Disabled callback support. */ | 30 | /* Callbacks disabled. */ |
31 | #define CALLBACK_SLOT2OFS(slot) (0*(slot)) | 31 | #define CALLBACK_SLOT2OFS(slot) (0*(slot)) |
32 | #define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) | 32 | #define CALLBACK_OFS2SLOT(ofs) (0*(ofs)) |
33 | #define CALLBACK_MAX_SLOT 0 | 33 | #define CALLBACK_MAX_SLOT 0 |
@@ -54,23 +54,18 @@ static MSize CALLBACK_OFS2SLOT(MSize ofs) | |||
54 | #elif LJ_TARGET_ARM | 54 | #elif LJ_TARGET_ARM |
55 | 55 | ||
56 | #define CALLBACK_MCODE_HEAD 32 | 56 | #define CALLBACK_MCODE_HEAD 32 |
57 | #define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) | 57 | |
58 | #define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) | 58 | #elif LJ_TARGET_ARM64 |
59 | #define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) | 59 | |
60 | #define CALLBACK_MCODE_HEAD 32 | ||
60 | 61 | ||
61 | #elif LJ_TARGET_PPC | 62 | #elif LJ_TARGET_PPC |
62 | 63 | ||
63 | #define CALLBACK_MCODE_HEAD 24 | 64 | #define CALLBACK_MCODE_HEAD 24 |
64 | #define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) | ||
65 | #define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) | ||
66 | #define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) | ||
67 | 65 | ||
68 | #elif LJ_TARGET_MIPS | 66 | #elif LJ_TARGET_MIPS |
69 | 67 | ||
70 | #define CALLBACK_MCODE_HEAD 24 | 68 | #define CALLBACK_MCODE_HEAD 24 |
71 | #define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) | ||
72 | #define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) | ||
73 | #define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) | ||
74 | 69 | ||
75 | #else | 70 | #else |
76 | 71 | ||
@@ -81,6 +76,12 @@ static MSize CALLBACK_OFS2SLOT(MSize ofs) | |||
81 | 76 | ||
82 | #endif | 77 | #endif |
83 | 78 | ||
79 | #ifndef CALLBACK_SLOT2OFS | ||
80 | #define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot)) | ||
81 | #define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8) | ||
82 | #define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE)) | ||
83 | #endif | ||
84 | |||
84 | /* Convert callback slot number to callback function pointer. */ | 85 | /* Convert callback slot number to callback function pointer. */ |
85 | static void *callback_slot2ptr(CTState *cts, MSize slot) | 86 | static void *callback_slot2ptr(CTState *cts, MSize slot) |
86 | { | 87 | { |
@@ -157,6 +158,26 @@ static void callback_mcode_init(global_State *g, uint32_t *page) | |||
157 | } | 158 | } |
158 | lua_assert(p - page <= CALLBACK_MCODE_SIZE); | 159 | lua_assert(p - page <= CALLBACK_MCODE_SIZE); |
159 | } | 160 | } |
161 | #elif LJ_TARGET_ARM64 | ||
162 | static void callback_mcode_init(global_State *g, uint32_t *page) | ||
163 | { | ||
164 | uint32_t *p = page; | ||
165 | void *target = (void *)lj_vm_ffi_callback; | ||
166 | MSize slot; | ||
167 | *p++ = A64I_LDRLx | A64F_D(RID_X11) | A64F_S19(4); | ||
168 | *p++ = A64I_LDRLx | A64F_D(RID_X10) | A64F_S19(5); | ||
169 | *p++ = A64I_BR | A64F_N(RID_X11); | ||
170 | *p++ = A64I_NOP; | ||
171 | ((void **)p)[0] = target; | ||
172 | ((void **)p)[1] = g; | ||
173 | p += 4; | ||
174 | for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) { | ||
175 | *p++ = A64I_MOVZw | A64F_D(RID_X9) | A64F_U16(slot); | ||
176 | *p = A64I_B | A64F_S26((page-p) & 0x03ffffffu); | ||
177 | p++; | ||
178 | } | ||
179 | lua_assert(p - page <= CALLBACK_MCODE_SIZE); | ||
180 | } | ||
160 | #elif LJ_TARGET_PPC | 181 | #elif LJ_TARGET_PPC |
161 | static void callback_mcode_init(global_State *g, uint32_t *page) | 182 | static void callback_mcode_init(global_State *g, uint32_t *page) |
162 | { | 183 | { |
@@ -351,6 +372,29 @@ void lj_ccallback_mcode_free(CTState *cts) | |||
351 | goto done; \ | 372 | goto done; \ |
352 | } CALLBACK_HANDLE_REGARG_FP2 | 373 | } CALLBACK_HANDLE_REGARG_FP2 |
353 | 374 | ||
375 | #elif LJ_TARGET_ARM64 | ||
376 | |||
377 | #define CALLBACK_HANDLE_REGARG \ | ||
378 | if (isfp) { \ | ||
379 | if (nfpr + n <= CCALL_NARG_FPR) { \ | ||
380 | sp = &cts->cb.fpr[nfpr]; \ | ||
381 | nfpr += n; \ | ||
382 | goto done; \ | ||
383 | } else { \ | ||
384 | nfpr = CCALL_NARG_FPR; /* Prevent reordering. */ \ | ||
385 | } \ | ||
386 | } else { \ | ||
387 | if (!LJ_TARGET_IOS && n > 1) \ | ||
388 | ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ | ||
389 | if (ngpr + n <= maxgpr) { \ | ||
390 | sp = &cts->cb.gpr[ngpr]; \ | ||
391 | ngpr += n; \ | ||
392 | goto done; \ | ||
393 | } else { \ | ||
394 | ngpr = CCALL_NARG_GPR; /* Prevent reordering. */ \ | ||
395 | } \ | ||
396 | } | ||
397 | |||
354 | #elif LJ_TARGET_PPC | 398 | #elif LJ_TARGET_PPC |
355 | 399 | ||
356 | #define CALLBACK_HANDLE_REGARG \ | 400 | #define CALLBACK_HANDLE_REGARG \ |