3 ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
12 /* -- Lua stack frame ----------------------------------------------------- */
14 /* Frame type markers in callee function slot (callee base-1). */
16 FRAME_LUA
, FRAME_C
, FRAME_CONT
, FRAME_VARG
,
17 FRAME_LUAP
, FRAME_CP
, FRAME_PCALL
, FRAME_PCALLH
21 #define FRAME_TYPEP (FRAME_TYPE|FRAME_P)
23 /* Macros to access and modify Lua frames. */
24 #define frame_gc(f) (gcref((f)->fr.func))
25 #define frame_func(f) (&frame_gc(f)->fn)
26 #define frame_ftsz(f) ((f)->fr.tp.ftsz)
28 #define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
29 #define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
30 #define frame_islua(f) (frame_type(f) == FRAME_LUA)
31 #define frame_isc(f) (frame_type(f) == FRAME_C)
32 #define frame_iscont(f) (frame_typep(f) == FRAME_CONT)
33 #define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
34 #define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
36 #define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
37 #define frame_contpc(f) (frame_pc((f)-1))
39 #define frame_contf(f) \
40 ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \
41 (intptr_t)(int32_t)((f)-1)->u32.lo))
43 #define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
45 #define frame_delta(f) (frame_ftsz(f) >> 3)
46 #define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
48 #define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1])))
49 #define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
50 #define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
51 /* Note: this macro does not skip over FRAME_VARG. */
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)))
57 /* -- C stack frame ------------------------------------------------------- */
59 /* Macros to access and modify the C stack frame chain. */
61 /* These definitions must match with the arch-specific *.dasc files. */
63 #define CFRAME_OFS_ERRF (15*4)
64 #define CFRAME_OFS_NRES (14*4)
65 #define CFRAME_OFS_PREV (13*4)
66 #define CFRAME_OFS_L (12*4)
67 #define CFRAME_OFS_PC (6*4)
68 #define CFRAME_OFS_MULTRES (5*4)
69 #define CFRAME_SIZE (12*4)
70 #define CFRAME_SHIFT_MULTRES 0
73 #define CFRAME_OFS_PREV (13*8)
74 #define CFRAME_OFS_PC (25*4)
75 #define CFRAME_OFS_L (24*4)
76 #define CFRAME_OFS_ERRF (23*4)
77 #define CFRAME_OFS_NRES (22*4)
78 #define CFRAME_OFS_MULTRES (21*4)
79 #define CFRAME_SIZE (10*8)
80 #define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8)
81 #define CFRAME_SHIFT_MULTRES 0
83 #define CFRAME_OFS_PREV (4*8)
84 #define CFRAME_OFS_PC (7*4)
85 #define CFRAME_OFS_L (6*4)
86 #define CFRAME_OFS_ERRF (5*4)
87 #define CFRAME_OFS_NRES (4*4)
88 #define CFRAME_OFS_MULTRES (1*4)
89 #define CFRAME_SIZE (10*8)
90 #define CFRAME_SIZE_JIT (CFRAME_SIZE + 16)
91 #define CFRAME_SHIFT_MULTRES 0
94 #define CFRAME_OFS_ERRF 24
95 #define CFRAME_OFS_NRES 20
96 #define CFRAME_OFS_PREV 16
97 #define CFRAME_OFS_L 12
98 #define CFRAME_OFS_PC 8
99 #define CFRAME_OFS_MULTRES 4
100 #define CFRAME_SIZE 64
101 #define CFRAME_SHIFT_MULTRES 3
103 #define CFRAME_OFS_ERRF 48
104 #define CFRAME_OFS_NRES 44
105 #define CFRAME_OFS_PREV 40
106 #define CFRAME_OFS_L 36
107 #define CFRAME_OFS_PC 32
108 #define CFRAME_OFS_MULTRES 28
109 #define CFRAME_SIZE 272
110 #define CFRAME_SHIFT_MULTRES 3
111 #elif LJ_TARGET_PPCSPE
112 #define CFRAME_OFS_ERRF 28
113 #define CFRAME_OFS_NRES 24
114 #define CFRAME_OFS_PREV 20
115 #define CFRAME_OFS_L 16
116 #define CFRAME_OFS_PC 12
117 #define CFRAME_OFS_MULTRES 8
118 #define CFRAME_SIZE 184
119 #define CFRAME_SHIFT_MULTRES 3
121 #define CFRAME_OFS_ERRF 124
122 #define CFRAME_OFS_NRES 120
123 #define CFRAME_OFS_PREV 116
124 #define CFRAME_OFS_L 112
125 #define CFRAME_OFS_PC 20
126 #define CFRAME_OFS_MULTRES 16
127 #define CFRAME_SIZE 112
128 #define CFRAME_SHIFT_MULTRES 3
130 #error "Missing CFRAME_* definitions for this architecture"
133 #ifndef CFRAME_SIZE_JIT
134 #define CFRAME_SIZE_JIT CFRAME_SIZE
137 #define CFRAME_RESUME 1
138 #define CFRAME_UNWIND_FF 2 /* Only used in unwinder. */
139 #define CFRAME_RAWMASK (~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF))
141 #define cframe_errfunc(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF))
142 #define cframe_nres(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES))
143 #define cframe_prev(cf) (*(void **)(((char *)(cf))+CFRAME_OFS_PREV))
144 #define cframe_multres(cf) (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES))
145 #define cframe_multres_n(cf) (cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES)
146 #define cframe_L(cf) \
147 (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th)
148 #define cframe_pc(cf) \
149 (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns))
150 #define setcframe_L(cf, L) \
151 (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L)))
152 #define setcframe_pc(cf, pc) \
153 (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc)))
154 #define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_RESUME)
155 #define cframe_unwind_ff(cf) ((intptr_t)(cf) & CFRAME_UNWIND_FF)
156 #define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK))
157 #define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe))