aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2010-08-31 00:17:22 +0200
committerMike Pall <mike>2010-08-31 00:17:22 +0200
commit690b1f3e4b103af73fb19dd32f84c6e68b34245c (patch)
tree52095c62272bdcf550a24b711d623396a8c54169 /src
parent4ef6564f2e07c10336bcc59cc33d36ddef42176d (diff)
downloadluajit-690b1f3e4b103af73fb19dd32f84c6e68b34245c.tar.gz
luajit-690b1f3e4b103af73fb19dd32f84c6e68b34245c.tar.bz2
luajit-690b1f3e4b103af73fb19dd32f84c6e68b34245c.zip
PPC: Add entry and exit points into VM. Add type check macros.
Diffstat (limited to 'src')
-rw-r--r--src/buildvm_ppc.dasc92
1 files changed, 85 insertions, 7 deletions
diff --git a/src/buildvm_ppc.dasc b/src/buildvm_ppc.dasc
index 8d3d3a70..ce049573 100644
--- a/src/buildvm_ppc.dasc
+++ b/src/buildvm_ppc.dasc
@@ -206,6 +206,18 @@
206| 206|
207|//----------------------------------------------------------------------- 207|//-----------------------------------------------------------------------
208| 208|
209|// Macros to test operand types.
210|.if SPE
211|.macro checknum, reg; evcmpltu reg, TISNUM; .endmacro
212|.macro checkstr, reg; evcmpeq reg, TISSTR; .endmacro
213|.macro checktab, reg; evcmpeq reg, TISTAB; .endmacro
214|.macro checkfunc, reg; evcmpeq reg, TISFUNC; .endmacro
215|.macro checknil, reg; evcmpeq reg, TISNIL; .endmacro
216|.macro checkok, label; blt label; .endmacro
217|.macro checkfail, label; bge label; .endmacro
218|.macro checkanyfail, label; bns label; .endmacro
219|.endif
220|
209|// Assumes DISPATCH is relative to GL. 221|// Assumes DISPATCH is relative to GL.
210#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field)) 222#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
211#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field)) 223#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
@@ -220,6 +232,10 @@
220| NYI 232| NYI
221|.endmacro 233|.endmacro
222| 234|
235|// Set current VM state. Uses TMP0.
236|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
237|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
238|
223|//----------------------------------------------------------------------- 239|//-----------------------------------------------------------------------
224 240
225/* Generate subroutines used by opcodes and other parts of the VM. */ 241/* Generate subroutines used by opcodes and other parts of the VM. */
@@ -242,10 +258,13 @@ static void build_subroutines(BuildCtx *ctx)
242 | NYI 258 | NYI
243 | 259 |
244 |->vm_leave_cp: 260 |->vm_leave_cp:
245 | NYI 261 | lwz TMP0, SAVE_CFRAME // Restore previous C frame.
262 | li CRET1, 0 // Ok return status for vm_pcall.
263 | stw TMP0, L->cframe
246 | 264 |
247 |->vm_leave_unw: 265 |->vm_leave_unw:
248 | NYI 266 | restoreregs
267 | blr
249 | 268 |
250 |->vm_unwind_c: // Unwind C stack, return from vm_pcall. 269 |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
251 | NYI 270 | NYI
@@ -275,19 +294,78 @@ static void build_subroutines(BuildCtx *ctx)
275 | NYI 294 | NYI
276 | 295 |
277 |->vm_pcall: // Setup protected C frame and enter VM. 296 |->vm_pcall: // Setup protected C frame and enter VM.
278 | NYI 297 | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
298 | saveregs
299 | li PC, FRAME_CP
300 | stw CARG4, SAVE_ERRF
301 | b >1
279 | 302 |
280 |->vm_call: // Setup C frame and enter VM. 303 |->vm_call: // Setup C frame and enter VM.
281 | NYI 304 | // (lua_State *L, TValue *base, int nres1)
305 | saveregs
306 | li PC, FRAME_C
307 |
308 |1: // Entry point for vm_pcall above (PC = ftype).
309 | lwz TMP1, L:CARG1->cframe
310 | stw CARG3, SAVE_NRES
311 | mr L, CARG1
312 | stw CARG1, SAVE_L
313 | mr BASE, CARG2
314 | stw sp, L->cframe // Add our C frame to cframe chain.
315 | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
316 | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
317 | stw TMP1, SAVE_CFRAME
318 | addi DISPATCH, DISPATCH, GG_G2DISP
319 |
320 |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
321 | lwz TMP2, L->base // TMP2 = old base (used in vmeta_call).
322 | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants.
323 | lwz TMP1, L->top
324 | evsplati TISFUNC, LJ_TFUNC
325 | add PC, PC, BASE
326 | li_vmstate INTERP
327 | evsplati TISTAB, LJ_TTAB
328 | sub PC, PC, TMP2 // PC = frame delta + frame type
329 | st_vmstate
330 | evsplati TISSTR, LJ_TSTR
331 | sub NARGS8:RC, TMP1, BASE
332 | evsplati TISNIL, LJ_TNIL
282 | 333 |
283 |->vm_call_dispatch: 334 |->vm_call_dispatch:
284 | NYI 335 | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
336 | // NYI: reschedule.
337 | li TMP0, -8
338 | evlddx LFUNC:RB, BASE, TMP0
339 | checkfunc LFUNC:RB
340 | checkfail ->vmeta_call // Ensure KBASE defined and != BASE.
285 | 341 |
286 |->vm_call_dispatch_f: 342 |->vm_call_dispatch_f:
287 | NYI 343 | ins_call
344 | // BASE = new base, RC = nargs*8
288 | 345 |
289 |->vm_cpcall: // Setup protected C frame, call C. 346 |->vm_cpcall: // Setup protected C frame, call C.
290 | NYI 347 | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
348 | saveregs
349 | mr L, CARG1
350 | mtctr CARG4
351 | lwz TMP0, L:CARG1->stack
352 | stw CARG1, SAVE_L
353 | lwz TMP1, L->top
354 | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
355 | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
356 | lwz TMP1, L->cframe
357 | stw sp, L->cframe // Add our C frame to cframe chain.
358 | li TMP2, 0
359 | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
360 | stw TMP2, SAVE_ERRF // No error function.
361 | stw TMP1, SAVE_CFRAME
362 | bctrl // (lua_State *L, lua_CFunction func, void *ud)
363 | mr. BASE, CRET1
364 | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
365 | li PC, FRAME_CP
366 | addi DISPATCH, DISPATCH, GG_G2DISP
367 | bne <3 // Else continue with the call.
368 | b ->vm_leave_cp // No base? Just remove C frame.
291 | 369 |
292 |//----------------------------------------------------------------------- 370 |//-----------------------------------------------------------------------
293 |//-- Metamethod handling ------------------------------------------------ 371 |//-- Metamethod handling ------------------------------------------------