summaryrefslogtreecommitdiff
path: root/src/buildvm_x86.dasc
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildvm_x86.dasc')
-rw-r--r--src/buildvm_x86.dasc182
1 files changed, 153 insertions, 29 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc
index a667bcb6..dd409c5c 100644
--- a/src/buildvm_x86.dasc
+++ b/src/buildvm_x86.dasc
@@ -3687,10 +3687,21 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
3687 |.endif 3687 |.endif
3688 | 3688 |
3689 |//----------------------------------------------------------------------- 3689 |//-----------------------------------------------------------------------
3690 |//-- Assertions ---------------------------------------------------------
3691 |//-----------------------------------------------------------------------
3692 |
3693 |->assert_bad_for_arg_type:
3694#ifdef LUA_USE_ASSERT
3695 | int3
3696#endif
3697 | int3
3698 |
3699 |//-----------------------------------------------------------------------
3690 |//-- FFI helper functions ----------------------------------------------- 3700 |//-- FFI helper functions -----------------------------------------------
3691 |//----------------------------------------------------------------------- 3701 |//-----------------------------------------------------------------------
3692 | 3702 |
3693 |->vm_ffi_call@4: 3703 |->vm_ffi_call@4: // Call C function via FFI.
3704 | // Caveat: needs special frame unwinding, see below.
3694#if LJ_HASFFI 3705#if LJ_HASFFI
3695 |.if X64 3706 |.if X64
3696 | .type CCSTATE, CCallState, rbx 3707 | .type CCSTATE, CCallState, rbx
@@ -3786,16 +3797,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
3786 | mov ebx, [ebp-4]; leave; ret 3797 | mov ebx, [ebp-4]; leave; ret
3787 |.endif 3798 |.endif
3788#endif 3799#endif
3789 | 3800 |// Note: vm_ffi_call must be the last function in this object file!
3790 |//-----------------------------------------------------------------------
3791 |//-- Assertions ---------------------------------------------------------
3792 |//-----------------------------------------------------------------------
3793 |
3794 |->assert_bad_for_arg_type:
3795#ifdef LUA_USE_ASSERT
3796 | int3
3797#endif
3798 | int3
3799 | 3801 |
3800 |//----------------------------------------------------------------------- 3802 |//-----------------------------------------------------------------------
3801} 3803}
@@ -6001,6 +6003,7 @@ static int build_backend(BuildCtx *ctx)
6001/* Emit pseudo frame-info for all assembler functions. */ 6003/* Emit pseudo frame-info for all assembler functions. */
6002static void emit_asm_debug(BuildCtx *ctx) 6004static void emit_asm_debug(BuildCtx *ctx)
6003{ 6005{
6006 int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
6004#if LJ_64 6007#if LJ_64
6005#define SZPTR "8" 6008#define SZPTR "8"
6006#define BSZPTR "3" 6009#define BSZPTR "3"
@@ -6034,22 +6037,49 @@ static void emit_asm_debug(BuildCtx *ctx)
6034 "\t.long .LEFDE0-.LASFDE0\n" 6037 "\t.long .LEFDE0-.LASFDE0\n"
6035 ".LASFDE0:\n" 6038 ".LASFDE0:\n"
6036 "\t.long .Lframe0\n" 6039 "\t.long .Lframe0\n"
6037 "\t.long .Lbegin\n"
6038 "\t.long %d\n"
6039 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6040#if LJ_64 6040#if LJ_64
6041 "\t.quad .Lbegin\n"
6042 "\t.quad %d\n"
6043 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6041 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */ 6044 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6042 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */ 6045 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6043 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */ 6046 "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
6044 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */ 6047 "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
6045#else 6048#else
6049 "\t.long .Lbegin\n"
6050 "\t.long %d\n"
6051 "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
6046 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */ 6052 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6047 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */ 6053 "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
6048 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */ 6054 "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
6049 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ 6055 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6050#endif 6056#endif
6051 "\t.align " SZPTR "\n" 6057 "\t.align " SZPTR "\n"
6052 ".LEFDE0:\n\n", (int)ctx->codesz, CFRAME_SIZE); 6058 ".LEFDE0:\n\n", fcofs, CFRAME_SIZE);
6059#if LJ_HASFFI
6060 fprintf(ctx->fp,
6061 ".LSFDE1:\n"
6062 "\t.long .LEFDE1-.LASFDE1\n"
6063 ".LASFDE1:\n"
6064 "\t.long .Lframe0\n"
6065#if LJ_64
6066 "\t.quad lj_vm_ffi_call\n"
6067 "\t.quad %d\n"
6068 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6069 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6070 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6071 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6072#else
6073 "\t.long lj_vm_ffi_call\n"
6074 "\t.long %d\n"
6075 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6076 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6077 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6078 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6079#endif
6080 "\t.align " SZPTR "\n"
6081 ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
6082#endif
6053#if (defined(__sun__) && defined(__svr4__)) || defined(__solaris_) 6083#if (defined(__sun__) && defined(__svr4__)) || defined(__solaris_)
6054 fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n"); 6084 fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
6055#else 6085#else
@@ -6074,10 +6104,10 @@ static void emit_asm_debug(BuildCtx *ctx)
6074 "\t.align " SZPTR "\n" 6104 "\t.align " SZPTR "\n"
6075 ".LECIE1:\n\n"); 6105 ".LECIE1:\n\n");
6076 fprintf(ctx->fp, 6106 fprintf(ctx->fp,
6077 ".LSFDE1:\n" 6107 ".LSFDE2:\n"
6078 "\t.long .LEFDE1-.LASFDE1\n" 6108 "\t.long .LEFDE2-.LASFDE2\n"
6079 ".LASFDE1:\n" 6109 ".LASFDE2:\n"
6080 "\t.long .LASFDE1-.Lframe1\n" 6110 "\t.long .LASFDE2-.Lframe1\n"
6081 "\t.long .Lbegin-.\n" 6111 "\t.long .Lbegin-.\n"
6082 "\t.long %d\n" 6112 "\t.long %d\n"
6083 "\t.uleb128 0\n" /* augmentation length */ 6113 "\t.uleb128 0\n" /* augmentation length */
@@ -6094,7 +6124,46 @@ static void emit_asm_debug(BuildCtx *ctx)
6094 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */ 6124 "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
6095#endif 6125#endif
6096 "\t.align " SZPTR "\n" 6126 "\t.align " SZPTR "\n"
6097 ".LEFDE1:\n\n", (int)ctx->codesz, CFRAME_SIZE); 6127 ".LEFDE2:\n\n", fcofs, CFRAME_SIZE);
6128#if LJ_HASFFI
6129 fprintf(ctx->fp,
6130 ".Lframe2:\n"
6131 "\t.long .LECIE2-.LSCIE2\n"
6132 ".LSCIE2:\n"
6133 "\t.long 0\n"
6134 "\t.byte 0x1\n"
6135 "\t.string \"zR\"\n"
6136 "\t.uleb128 0x1\n"
6137 "\t.sleb128 -" SZPTR "\n"
6138 "\t.byte " REG_RA "\n"
6139 "\t.uleb128 1\n" /* augmentation length */
6140 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6141 "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
6142 "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
6143 "\t.align " SZPTR "\n"
6144 ".LECIE2:\n\n");
6145 fprintf(ctx->fp,
6146 ".LSFDE3:\n"
6147 "\t.long .LEFDE3-.LASFDE3\n"
6148 ".LASFDE3:\n"
6149 "\t.long .LASFDE3-.Lframe2\n"
6150 "\t.long lj_vm_ffi_call-.\n"
6151 "\t.long %d\n"
6152 "\t.uleb128 0\n" /* augmentation length */
6153#if LJ_64
6154 "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
6155 "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
6156 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6157 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
6158#else
6159 "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
6160 "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
6161 "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
6162 "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
6163#endif
6164 "\t.align " SZPTR "\n"
6165 ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
6166#endif
6098 break; 6167 break;
6099 case BUILD_coffasm: 6168 case BUILD_coffasm:
6100 fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n"); 6169 fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n");
@@ -6145,6 +6214,9 @@ static void emit_asm_debug(BuildCtx *ctx)
6145 ** Or a linker. Or a plastic case. But I digress. 6214 ** Or a linker. Or a plastic case. But I digress.
6146 */ 6215 */
6147 case BUILD_machasm: { 6216 case BUILD_machasm: {
6217#if LJ_HASFFI
6218 int fcsize = 0;
6219#endif
6148 int i; 6220 int i;
6149 fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n"); 6221 fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
6150 fprintf(ctx->fp, 6222 fprintf(ctx->fp,
@@ -6176,6 +6248,9 @@ static void emit_asm_debug(BuildCtx *ctx)
6176 const char *name = ctx->sym[i].name; 6248 const char *name = ctx->sym[i].name;
6177 int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; 6249 int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
6178 if (size == 0) continue; 6250 if (size == 0) continue;
6251#if LJ_HASFFI
6252 if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; }
6253#endif
6179 fprintf(ctx->fp, 6254 fprintf(ctx->fp,
6180 "%s.eh:\n" 6255 "%s.eh:\n"
6181 "LSFDE%d:\n" 6256 "LSFDE%d:\n"
@@ -6185,23 +6260,72 @@ static void emit_asm_debug(BuildCtx *ctx)
6185 "\t.long LASFDE%d-EH_frame1\n" 6260 "\t.long LASFDE%d-EH_frame1\n"
6186 "\t.long %s-.\n" 6261 "\t.long %s-.\n"
6187 "\t.long %d\n" 6262 "\t.long %d\n"
6188 "\t.byte 0\n" /* augmentation length */ 6263 "\t.byte 0\n" /* augmentation length */
6189 "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ 6264 "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */
6190#if LJ_64 6265#if LJ_64
6191 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ 6266 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6192 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ 6267 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6193 "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ 6268 "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
6194 "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ 6269 "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
6195#else 6270#else
6196 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ 6271 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6197 "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ 6272 "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
6198 "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ 6273 "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
6199 "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ 6274 "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
6200#endif 6275#endif
6201 "\t.align " BSZPTR "\n" 6276 "\t.align " BSZPTR "\n"
6202 "LEFDE%d:\n\n", 6277 "LEFDE%d:\n\n",
6203 name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); 6278 name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
6204 } 6279 }
6280#if LJ_HASFFI
6281 if (fcsize) {
6282 fprintf(ctx->fp,
6283 "EH_frame2:\n"
6284 "\t.set L$set$y,LECIEY-LSCIEY\n"
6285 "\t.long L$set$y\n"
6286 "LSCIEY:\n"
6287 "\t.long 0\n"
6288 "\t.byte 0x1\n"
6289 "\t.ascii \"zR\\0\"\n"
6290 "\t.byte 0x1\n"
6291 "\t.byte 128-" SZPTR "\n"
6292 "\t.byte " REG_RA "\n"
6293 "\t.byte 1\n" /* augmentation length */
6294#if LJ_64
6295 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6296 "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
6297#else
6298 "\t.byte 0x1b\n" /* pcrel|sdata4 */
6299 "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */
6300#endif
6301 "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
6302 "\t.align " BSZPTR "\n"
6303 "LECIEY:\n\n");
6304 fprintf(ctx->fp,
6305 "_lj_vm_ffi_call.eh:\n"
6306 "LSFDEY:\n"
6307 "\t.set L$set$yy,LEFDEY-LASFDEY\n"
6308 "\t.long L$set$yy\n"
6309 "LASFDEY:\n"
6310 "\t.long LASFDEY-EH_frame2\n"
6311 "\t.long _lj_vm_ffi_call-.\n"
6312 "\t.long %d\n"
6313 "\t.byte 0\n" /* augmentation length */
6314#if LJ_64
6315 "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */
6316 "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
6317 "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
6318 "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
6319#else
6320 "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */
6321 "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
6322 "\t.byte 0xd\n\t.uleb128 0x4\n" /* def_cfa_register ebp */
6323 "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */
6324#endif
6325 "\t.align " BSZPTR "\n"
6326 "LEFDEY:\n\n", fcsize);
6327 }
6328#endif
6205#if LJ_64 6329#if LJ_64
6206 fprintf(ctx->fp, "\t.subsections_via_symbols\n"); 6330 fprintf(ctx->fp, "\t.subsections_via_symbols\n");
6207#else 6331#else