1 | /* |
2 | ** Assembler VM interface definitions. |
3 | ** Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h |
4 | */ |
5 | |
6 | #ifndef _LJ_VM_H |
7 | #define _LJ_VM_H |
8 | |
9 | #include "lj_obj.h" |
10 | |
11 | /* Entry points for ASM parts of VM. */ |
12 | LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1); |
13 | LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); |
14 | typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud); |
15 | LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud, |
16 | lua_CPFunction cp); |
17 | LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef); |
18 | LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode); |
19 | LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe); |
20 | #if LJ_ABI_WIN && LJ_TARGET_X86 |
21 | LJ_ASMF_NORET void LJ_FASTCALL lj_vm_rtlunwind(void *cframe, void *excptrec, |
22 | void *unwinder, int errcode); |
23 | #endif |
24 | LJ_ASMF void lj_vm_unwind_c_eh(void); |
25 | LJ_ASMF void lj_vm_unwind_ff_eh(void); |
26 | #if LJ_TARGET_X86ORX64 |
27 | LJ_ASMF void lj_vm_unwind_rethrow(void); |
28 | #endif |
29 | #if LJ_TARGET_MIPS |
30 | LJ_ASMF void lj_vm_unwind_stub(void); |
31 | #endif |
32 | |
33 | /* Miscellaneous functions. */ |
34 | #if LJ_TARGET_X86ORX64 |
35 | LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]); |
36 | #endif |
37 | #if LJ_TARGET_PPC |
38 | void lj_vm_cachesync(void *start, void *end); |
39 | #endif |
40 | LJ_ASMF double lj_vm_foldarith(double x, double y, int op); |
41 | #if LJ_HASJIT |
42 | LJ_ASMF double lj_vm_foldfpm(double x, int op); |
43 | #endif |
44 | #if !LJ_ARCH_HASFPU |
45 | /* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */ |
46 | #endif |
47 | |
48 | /* Dispatch targets for recording and hooks. */ |
49 | LJ_ASMF void lj_vm_record(void); |
50 | LJ_ASMF void lj_vm_inshook(void); |
51 | LJ_ASMF void lj_vm_rethook(void); |
52 | LJ_ASMF void lj_vm_callhook(void); |
53 | LJ_ASMF void lj_vm_profhook(void); |
54 | |
55 | /* Trace exit handling. */ |
56 | LJ_ASMF void lj_vm_exit_handler(void); |
57 | LJ_ASMF void lj_vm_exit_interp(void); |
58 | |
59 | /* Internal math helper functions. */ |
60 | #if LJ_TARGET_PPC || LJ_TARGET_ARM64 || (LJ_TARGET_MIPS && LJ_ABI_SOFTFP) |
61 | #define lj_vm_floor floor |
62 | #define lj_vm_ceil ceil |
63 | #else |
64 | LJ_ASMF double lj_vm_floor(double); |
65 | LJ_ASMF double lj_vm_ceil(double); |
66 | #if LJ_TARGET_ARM |
67 | LJ_ASMF double lj_vm_floor_sf(double); |
68 | LJ_ASMF double lj_vm_ceil_sf(double); |
69 | #endif |
70 | #endif |
71 | #ifdef LUAJIT_NO_LOG2 |
72 | LJ_ASMF double lj_vm_log2(double); |
73 | #else |
74 | #define lj_vm_log2 log2 |
75 | #endif |
76 | #if !(defined(_LJ_DISPATCH_H) && LJ_TARGET_MIPS) |
77 | LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t); |
78 | #endif |
79 | |
80 | #if LJ_HASJIT |
81 | #if LJ_TARGET_X86ORX64 |
82 | LJ_ASMF void lj_vm_floor_sse(void); |
83 | LJ_ASMF void lj_vm_ceil_sse(void); |
84 | LJ_ASMF void lj_vm_trunc_sse(void); |
85 | LJ_ASMF void lj_vm_powi_sse(void); |
86 | #define lj_vm_powi NULL |
87 | #else |
88 | LJ_ASMF double lj_vm_powi(double, int32_t); |
89 | #endif |
90 | #if LJ_TARGET_PPC || LJ_TARGET_ARM64 |
91 | #define lj_vm_trunc trunc |
92 | #else |
93 | LJ_ASMF double lj_vm_trunc(double); |
94 | #if LJ_TARGET_ARM |
95 | LJ_ASMF double lj_vm_trunc_sf(double); |
96 | #endif |
97 | #endif |
98 | #if LJ_HASFFI |
99 | LJ_ASMF int lj_vm_errno(void); |
100 | #endif |
101 | #endif |
102 | |
103 | /* Continuations for metamethods. */ |
104 | LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */ |
105 | LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */ |
106 | LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */ |
107 | LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */ |
108 | LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */ |
109 | LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */ |
110 | LJ_ASMF void lj_cont_stitch(void); /* Trace stitching. */ |
111 | |
112 | /* Start of the ASM code. */ |
113 | LJ_ASMF char lj_vm_asm_begin[]; |
114 | |
115 | /* Bytecode offsets are relative to lj_vm_asm_begin. */ |
116 | #define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs))) |
117 | |
118 | #endif |
119 | |