diff options
Diffstat (limited to 'src/buildvm_x86.dasc')
-rw-r--r-- | src/buildvm_x86.dasc | 111 |
1 files changed, 110 insertions, 1 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index add00c9d..f6add4d0 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
@@ -287,6 +287,35 @@ static void build_subroutines(BuildCtx *ctx, int cmov) | |||
287 | | lea RA, [BASE+RA*8] | 287 | | lea RA, [BASE+RA*8] |
288 | | jmp <9 | 288 | | jmp <9 |
289 | | | 289 | | |
290 | |->gate_cwrap: // Call gate for wrapped C functions. | ||
291 | | // RA = new base, RB = CFUNC, RC = nargs+1, (BASE = old base), PC = return | ||
292 | | mov [RA-4], PC | ||
293 | | mov KBASE, CFUNC:RB->f | ||
294 | | mov L:RB, SAVE_L | ||
295 | | lea RC, [RA+NARGS:RC*8-8] | ||
296 | | mov L:RB->base, RA | ||
297 | | lea RA, [RC+8*LUA_MINSTACK] | ||
298 | | mov ARG2, KBASE | ||
299 | | mov ARG1, L:RB | ||
300 | | mov L:RB->top, RC | ||
301 | | cmp RA, L:RB->maxstack | ||
302 | | ja ->gate_c_growstack // Need to grow stack. | ||
303 | | set_vmstate C | ||
304 | | // (lua_State *L, lua_CFunction f) | ||
305 | | call aword [DISPATCH+DISPATCH_GL(wrapf)] | ||
306 | | set_vmstate INTERP | ||
307 | | // nresults returned in eax (RD). | ||
308 | | mov BASE, L:RB->base | ||
309 | | lea RA, [BASE+RD*8] | ||
310 | | neg RA | ||
311 | | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8 | ||
312 | |->vm_returnc: | ||
313 | | add RD, 1 // RD = nresults+1 | ||
314 | | mov NRESULTS, RD | ||
315 | | test PC, FRAME_TYPE | ||
316 | | jz ->BC_RET_Z // Handle regular return to Lua. | ||
317 | | jmp ->vm_return | ||
318 | | | ||
290 | |->gate_c: // Call gate for C functions. | 319 | |->gate_c: // Call gate for C functions. |
291 | | // RA = new base, RB = CFUNC, RC = nargs+1, (BASE = old base), PC = return | 320 | | // RA = new base, RB = CFUNC, RC = nargs+1, (BASE = old base), PC = return |
292 | | mov [RA-4], PC | 321 | | mov [RA-4], PC |
@@ -312,6 +341,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov) | |||
312 | | mov NRESULTS, RD | 341 | | mov NRESULTS, RD |
313 | | test PC, FRAME_TYPE | 342 | | test PC, FRAME_TYPE |
314 | | jz ->BC_RET_Z // Handle regular return to Lua. | 343 | | jz ->BC_RET_Z // Handle regular return to Lua. |
344 | | // Fallthrough. | ||
315 | | | 345 | | |
316 | |//-- Return handling (non-inline) --------------------------------------- | 346 | |//-- Return handling (non-inline) --------------------------------------- |
317 | | | 347 | | |
@@ -1455,7 +1485,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov) | |||
1455 | | mov ARG5, RA | 1485 | | mov ARG5, RA |
1456 | | fstp FPARG1 | 1486 | | fstp FPARG1 |
1457 | | mov RB, BASE | 1487 | | mov RB, BASE |
1458 | | call extern func | 1488 | | call extern lj_wrapper_ .. func |
1459 | | mov RA, ARG5 | 1489 | | mov RA, ARG5 |
1460 | | mov BASE, RB | 1490 | | mov BASE, RB |
1461 | | jmp ->fff_resn | 1491 | | jmp ->fff_resn |
@@ -3584,6 +3614,85 @@ static void emit_asm_debug(BuildCtx *ctx) | |||
3584 | "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ | 3614 | "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ |
3585 | "\t.align 4\n" | 3615 | "\t.align 4\n" |
3586 | ".LEFDE0:\n\n", (int)ctx->codesz); | 3616 | ".LEFDE0:\n\n", (int)ctx->codesz); |
3617 | fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n"); | ||
3618 | fprintf(ctx->fp, | ||
3619 | ".Lframe1:\n" | ||
3620 | "\t.long .LECIE1-.LSCIE1\n" | ||
3621 | ".LSCIE1:\n" | ||
3622 | "\t.long 0\n" | ||
3623 | "\t.byte 0x1\n" | ||
3624 | "\t.string \"zPR\"\n" | ||
3625 | "\t.uleb128 0x1\n" | ||
3626 | "\t.sleb128 -4\n" | ||
3627 | "\t.byte 0x8\n" | ||
3628 | "\t.uleb128 6\n" /* augmentation length */ | ||
3629 | "\t.byte 0x1b\n" /* pcrel|sdata4 */ | ||
3630 | "\t.long lj_err_unwind_dwarf-.\n" | ||
3631 | "\t.byte 0x1b\n" /* pcrel|sdata4 */ | ||
3632 | "\t.byte 0xc\n\t.uleb128 0x4\n\t.uleb128 0x4\n" | ||
3633 | "\t.byte 0x88\n\t.uleb128 0x1\n" | ||
3634 | "\t.align 4\n" | ||
3635 | ".LECIE1:\n\n"); | ||
3636 | fprintf(ctx->fp, | ||
3637 | ".LSFDE1:\n" | ||
3638 | "\t.long .LEFDE1-.LASFDE1\n" | ||
3639 | ".LASFDE1:\n" | ||
3640 | "\t.long .LASFDE1-.Lframe1\n" | ||
3641 | "\t.long .Lbegin-.\n" | ||
3642 | "\t.long %d\n" | ||
3643 | "\t.uleb128 0\n" /* augmentation length */ | ||
3644 | "\t.byte 0xe\n\t.uleb128 0x30\n" /* def_cfa_offset */ | ||
3645 | "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ | ||
3646 | "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ | ||
3647 | "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ | ||
3648 | "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ | ||
3649 | "\t.align 4\n" | ||
3650 | ".LEFDE1:\n\n", (int)ctx->codesz); | ||
3651 | break; | ||
3652 | case BUILD_machasm: | ||
3653 | /* NYI: OSX ignores it. Something must be missing. */ | ||
3654 | fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n"); | ||
3655 | fprintf(ctx->fp, | ||
3656 | "EH_frame1:\n" | ||
3657 | "\t.set L$set$0,LECIE1-LSCIE1\n" | ||
3658 | "\t.long L$set$0\n" | ||
3659 | "LSCIE1:\n" | ||
3660 | "\t.long 0\n" | ||
3661 | "\t.byte 0x1\n" | ||
3662 | "\t.ascii \"zPR\"\n" | ||
3663 | "\t.byte 0x1\n" | ||
3664 | "\t.byte 128-4\n" | ||
3665 | "\t.byte 0x8\n" | ||
3666 | "\t.byte 6\n" /* augmentation length */ | ||
3667 | "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */ | ||
3668 | "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n" | ||
3669 | "\t.byte 0x1b\n" /* pcrel|sdata4 */ | ||
3670 | "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */ | ||
3671 | "\t.byte 0x88\n\t.byte 0x1\n" | ||
3672 | "\t.align 2\n" | ||
3673 | "LECIE1:\n\n"); | ||
3674 | fprintf(ctx->fp, | ||
3675 | "_lj_vm_asm_begin.eh:\n" | ||
3676 | "LSFDE1:\n" | ||
3677 | "\t.set L$set$1,LEFDE1-LASFDE1\n" | ||
3678 | "\t.long L$set$1\n" | ||
3679 | "LASFDE1:\n" | ||
3680 | "\t.long LASFDE1-EH_frame1\n" | ||
3681 | "\t.long _lj_vm_asm_begin-.\n" | ||
3682 | "\t.long %d\n" | ||
3683 | "\t.byte 0\n" /* augmentation length */ | ||
3684 | "\t.byte 0xe\n\t.byte 0x30\n" /* def_cfa_offset */ | ||
3685 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ | ||
3686 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ | ||
3687 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ | ||
3688 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ | ||
3689 | "\t.align 2\n" | ||
3690 | "LEFDE1:\n\n", (int)ctx->codesz); | ||
3691 | fprintf(ctx->fp, | ||
3692 | "\t.non_lazy_symbol_pointer\n" | ||
3693 | "L_lj_err_unwind_dwarf$non_lazy_ptr:\n" | ||
3694 | ".indirect_symbol _lj_err_unwind_dwarf\n" | ||
3695 | ".long 0\n"); | ||
3587 | break; | 3696 | break; |
3588 | default: /* Difficult for other modes. */ | 3697 | default: /* Difficult for other modes. */ |
3589 | break; | 3698 | break; |