aboutsummaryrefslogtreecommitdiff
path: root/src/lj_frame.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_frame.h127
1 files changed, 105 insertions, 22 deletions
diff --git a/src/lj_frame.h b/src/lj_frame.h
index 697a61d9..fc0e281c 100644
--- a/src/lj_frame.h
+++ b/src/lj_frame.h
@@ -11,7 +11,16 @@
11 11
12/* -- Lua stack frame ----------------------------------------------------- */ 12/* -- Lua stack frame ----------------------------------------------------- */
13 13
14/* Frame type markers in callee function slot (callee base-1). */ 14/* Frame type markers in LSB of PC (4-byte aligned) or delta (8-byte aligned:
15**
16** PC 00 Lua frame
17** delta 001 C frame
18** delta 010 Continuation frame
19** delta 011 Lua vararg frame
20** delta 101 cpcall() frame
21** delta 110 ff pcall() frame
22** delta 111 ff pcall() frame with active hook
23*/
15enum { 24enum {
16 FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG, 25 FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,
17 FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH 26 FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH
@@ -21,9 +30,47 @@ enum {
21#define FRAME_TYPEP (FRAME_TYPE|FRAME_P) 30#define FRAME_TYPEP (FRAME_TYPE|FRAME_P)
22 31
23/* Macros to access and modify Lua frames. */ 32/* Macros to access and modify Lua frames. */
33#if LJ_FR2
34/* Two-slot frame info, required for 64 bit PC/GCRef:
35**
36** base-2 base-1 | base base+1 ...
37** [func PC/delta/ft] | [slots ...]
38** ^-- frame | ^-- base ^-- top
39**
40** Continuation frames:
41**
42** base-4 base-3 base-2 base-1 | base base+1 ...
43** [cont PC ] [func PC/delta/ft] | [slots ...]
44** ^-- frame | ^-- base ^-- top
45*/
46#define frame_gc(f) (gcval((f)-1))
47#define frame_ftsz(f) ((ptrdiff_t)(f)->ftsz)
48#define frame_pc(f) ((const BCIns *)frame_ftsz(f))
49#define setframe_gc(f, p, tp) (setgcVraw((f)-1, (p), (tp)))
50#define setframe_ftsz(f, sz) ((f)->ftsz = (sz))
51#define setframe_pc(f, pc) ((f)->ftsz = (int64_t)(intptr_t)(pc))
52#else
53/* One-slot frame info, sufficient for 32 bit PC/GCRef:
54**
55** base-1 | base base+1 ...
56** lo hi |
57** [func | PC/delta/ft] | [slots ...]
58** ^-- frame | ^-- base ^-- top
59**
60** Continuation frames:
61**
62** base-2 base-1 | base base+1 ...
63** lo hi lo hi |
64** [cont | PC] [func | PC/delta/ft] | [slots ...]
65** ^-- frame | ^-- base ^-- top
66*/
24#define frame_gc(f) (gcref((f)->fr.func)) 67#define frame_gc(f) (gcref((f)->fr.func))
25#define frame_func(f) (&frame_gc(f)->fn) 68#define frame_ftsz(f) ((ptrdiff_t)(f)->fr.tp.ftsz)
26#define frame_ftsz(f) ((f)->fr.tp.ftsz) 69#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
70#define setframe_gc(f, p, tp) (setgcref((f)->fr.func, (p)), UNUSED(tp))
71#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (int32_t)(sz))
72#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
73#endif
27 74
28#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE) 75#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
29#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP) 76#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
@@ -33,27 +80,36 @@ enum {
33#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG) 80#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
34#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL) 81#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
35 82
36#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns)) 83#define frame_func(f) (&frame_gc(f)->fn)
84#define frame_delta(f) (frame_ftsz(f) >> 3)
85#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
86
87enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
88
89#if LJ_FR2
90#define frame_contpc(f) (frame_pc((f)-2))
91#define frame_contv(f) (((f)-3)->u64)
92#else
37#define frame_contpc(f) (frame_pc((f)-1)) 93#define frame_contpc(f) (frame_pc((f)-1))
38#if LJ_64 94#define frame_contv(f) (((f)-1)->u32.lo)
95#endif
96#if LJ_FR2
97#define frame_contf(f) ((ASMFunction)(uintptr_t)((f)-3)->u64)
98#elif LJ_64
39#define frame_contf(f) \ 99#define frame_contf(f) \
40 ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \ 100 ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \
41 (intptr_t)(int32_t)((f)-1)->u32.lo)) 101 (intptr_t)(int32_t)((f)-1)->u32.lo))
42#else 102#else
43#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void)) 103#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
44#endif 104#endif
45#define frame_delta(f) (frame_ftsz(f) >> 3) 105#define frame_iscont_fficb(f) \
46#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP) 106 (LJ_HASFFI && frame_contv(f) == LJ_CONT_FFI_CALLBACK)
47 107
48#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1]))) 108#define frame_prevl(f) ((f) - (1+LJ_FR2+bc_a(frame_pc(f)[-1])))
49#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f))) 109#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
50#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f)) 110#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
51/* Note: this macro does not skip over FRAME_VARG. */ 111/* Note: this macro does not skip over FRAME_VARG. */
52 112
53#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
54#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz))
55#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
56
57/* -- C stack frame ------------------------------------------------------- */ 113/* -- C stack frame ------------------------------------------------------- */
58 114
59/* Macros to access and modify the C stack frame chain. */ 115/* Macros to access and modify the C stack frame chain. */
@@ -71,21 +127,37 @@ enum {
71#elif LJ_TARGET_X64 127#elif LJ_TARGET_X64
72#if LJ_ABI_WIN 128#if LJ_ABI_WIN
73#define CFRAME_OFS_PREV (13*8) 129#define CFRAME_OFS_PREV (13*8)
130#if LJ_GC64
131#define CFRAME_OFS_PC (12*8)
132#define CFRAME_OFS_L (11*8)
133#define CFRAME_OFS_ERRF (21*4)
134#define CFRAME_OFS_NRES (20*4)
135#define CFRAME_OFS_MULTRES (8*4)
136#else
74#define CFRAME_OFS_PC (25*4) 137#define CFRAME_OFS_PC (25*4)
75#define CFRAME_OFS_L (24*4) 138#define CFRAME_OFS_L (24*4)
76#define CFRAME_OFS_ERRF (23*4) 139#define CFRAME_OFS_ERRF (23*4)
77#define CFRAME_OFS_NRES (22*4) 140#define CFRAME_OFS_NRES (22*4)
78#define CFRAME_OFS_MULTRES (21*4) 141#define CFRAME_OFS_MULTRES (21*4)
142#endif
79#define CFRAME_SIZE (10*8) 143#define CFRAME_SIZE (10*8)
80#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8) 144#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8)
81#define CFRAME_SHIFT_MULTRES 0 145#define CFRAME_SHIFT_MULTRES 0
82#else 146#else
83#define CFRAME_OFS_PREV (4*8) 147#define CFRAME_OFS_PREV (4*8)
148#if LJ_GC64
149#define CFRAME_OFS_PC (3*8)
150#define CFRAME_OFS_L (2*8)
151#define CFRAME_OFS_ERRF (3*4)
152#define CFRAME_OFS_NRES (2*4)
153#define CFRAME_OFS_MULTRES (0*4)
154#else
84#define CFRAME_OFS_PC (7*4) 155#define CFRAME_OFS_PC (7*4)
85#define CFRAME_OFS_L (6*4) 156#define CFRAME_OFS_L (6*4)
86#define CFRAME_OFS_ERRF (5*4) 157#define CFRAME_OFS_ERRF (5*4)
87#define CFRAME_OFS_NRES (4*4) 158#define CFRAME_OFS_NRES (4*4)
88#define CFRAME_OFS_MULTRES (1*4) 159#define CFRAME_OFS_MULTRES (1*4)
160#endif
89#if LJ_NO_UNWIND 161#if LJ_NO_UNWIND
90#define CFRAME_SIZE (12*8) 162#define CFRAME_SIZE (12*8)
91#else 163#else
@@ -107,6 +179,15 @@ enum {
107#define CFRAME_SIZE 64 179#define CFRAME_SIZE 64
108#endif 180#endif
109#define CFRAME_SHIFT_MULTRES 3 181#define CFRAME_SHIFT_MULTRES 3
182#elif LJ_TARGET_ARM64
183#define CFRAME_OFS_ERRF 196
184#define CFRAME_OFS_NRES 200
185#define CFRAME_OFS_PREV 160
186#define CFRAME_OFS_L 176
187#define CFRAME_OFS_PC 168
188#define CFRAME_OFS_MULTRES 192
189#define CFRAME_SIZE 208
190#define CFRAME_SHIFT_MULTRES 3
110#elif LJ_TARGET_PPC 191#elif LJ_TARGET_PPC
111#if LJ_TARGET_XBOX360 192#if LJ_TARGET_XBOX360
112#define CFRAME_OFS_ERRF 424 193#define CFRAME_OFS_ERRF 424
@@ -117,7 +198,7 @@ enum {
117#define CFRAME_OFS_MULTRES 408 198#define CFRAME_OFS_MULTRES 408
118#define CFRAME_SIZE 384 199#define CFRAME_SIZE 384
119#define CFRAME_SHIFT_MULTRES 3 200#define CFRAME_SHIFT_MULTRES 3
120#elif LJ_ARCH_PPC64 201#elif LJ_ARCH_PPC32ON64
121#define CFRAME_OFS_ERRF 472 202#define CFRAME_OFS_ERRF 472
122#define CFRAME_OFS_NRES 468 203#define CFRAME_OFS_NRES 468
123#define CFRAME_OFS_PREV 448 204#define CFRAME_OFS_PREV 448
@@ -136,16 +217,8 @@ enum {
136#define CFRAME_SIZE 272 217#define CFRAME_SIZE 272
137#define CFRAME_SHIFT_MULTRES 3 218#define CFRAME_SHIFT_MULTRES 3
138#endif 219#endif
139#elif LJ_TARGET_PPCSPE
140#define CFRAME_OFS_ERRF 28
141#define CFRAME_OFS_NRES 24
142#define CFRAME_OFS_PREV 20
143#define CFRAME_OFS_L 16
144#define CFRAME_OFS_PC 12
145#define CFRAME_OFS_MULTRES 8
146#define CFRAME_SIZE 184
147#define CFRAME_SHIFT_MULTRES 3
148#elif LJ_TARGET_MIPS 220#elif LJ_TARGET_MIPS
221#if LJ_ARCH_HASFPU
149#define CFRAME_OFS_ERRF 124 222#define CFRAME_OFS_ERRF 124
150#define CFRAME_OFS_NRES 120 223#define CFRAME_OFS_NRES 120
151#define CFRAME_OFS_PREV 116 224#define CFRAME_OFS_PREV 116
@@ -155,6 +228,16 @@ enum {
155#define CFRAME_SIZE 112 228#define CFRAME_SIZE 112
156#define CFRAME_SHIFT_MULTRES 3 229#define CFRAME_SHIFT_MULTRES 3
157#else 230#else
231#define CFRAME_OFS_ERRF 76
232#define CFRAME_OFS_NRES 72
233#define CFRAME_OFS_PREV 68
234#define CFRAME_OFS_L 64
235#define CFRAME_OFS_PC 20
236#define CFRAME_OFS_MULTRES 16
237#define CFRAME_SIZE 64
238#define CFRAME_SHIFT_MULTRES 3
239#endif
240#else
158#error "Missing CFRAME_* definitions for this architecture" 241#error "Missing CFRAME_* definitions for this architecture"
159#endif 242#endif
160 243