mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-22 06:43:27 +00:00
LoongArch64: Add DWARF and ELF header definitions
Co-developed-by: Qiqi Huang <huangqiqi@loongson.cn>
This commit is contained in:
parent
b76aba86c8
commit
fbb0994c6f
@ -306,6 +306,9 @@ enum {
|
|||||||
#elif LJ_TARGET_MIPS
|
#elif LJ_TARGET_MIPS
|
||||||
DW_REG_SP = 29,
|
DW_REG_SP = 29,
|
||||||
DW_REG_RA = 31,
|
DW_REG_RA = 31,
|
||||||
|
#elif LJ_TARGET_LOONGARCH64
|
||||||
|
DW_REG_SP = 3,
|
||||||
|
DW_REG_RA = 1,
|
||||||
#else
|
#else
|
||||||
#error "Unsupported target architecture"
|
#error "Unsupported target architecture"
|
||||||
#endif
|
#endif
|
||||||
@ -383,6 +386,8 @@ static const ELFheader elfhdr_template = {
|
|||||||
.machine = 20,
|
.machine = 20,
|
||||||
#elif LJ_TARGET_MIPS
|
#elif LJ_TARGET_MIPS
|
||||||
.machine = 8,
|
.machine = 8,
|
||||||
|
#elif LJ_TARGET_LOONGARCH64
|
||||||
|
.machine = 258,
|
||||||
#else
|
#else
|
||||||
#error "Unsupported target architecture"
|
#error "Unsupported target architecture"
|
||||||
#endif
|
#endif
|
||||||
@ -591,6 +596,13 @@ static void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx)
|
|||||||
for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }
|
for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }
|
||||||
for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }
|
for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }
|
||||||
}
|
}
|
||||||
|
#elif LJ_TARGET_LOONGARCH64
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
DB(DW_CFA_offset|30); DUV(2);
|
||||||
|
for (i = 31; i >= 23; i--) { DB(DW_CFA_offset|i); DUV(3+(31-i)); }
|
||||||
|
for (i = 31; i >= 24; i--) { DB(DW_CFA_offset|32|i); DUV(43-i); }
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#error "Unsupported target architecture"
|
#error "Unsupported target architecture"
|
||||||
#endif
|
#endif
|
||||||
|
@ -4477,3 +4477,132 @@ static int build_backend(BuildCtx *ctx)
|
|||||||
|
|
||||||
return BC__MAX;
|
return BC__MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Emit pseudo frame-info for all assembler functions. */
|
||||||
|
static void emit_asm_debug(BuildCtx *ctx)
|
||||||
|
{
|
||||||
|
int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
|
||||||
|
int i;
|
||||||
|
switch (ctx->mode) {
|
||||||
|
case BUILD_elfasm:
|
||||||
|
fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".Lframe0:\n"
|
||||||
|
"\t.4byte .LECIE0-.LSCIE0\n"
|
||||||
|
".LSCIE0:\n"
|
||||||
|
"\t.4byte 0xffffffff\n"
|
||||||
|
"\t.byte 0x1\n"
|
||||||
|
"\t.string \"\"\n"
|
||||||
|
"\t.uleb128 0x1\n"
|
||||||
|
"\t.sleb128 -4\n"
|
||||||
|
"\t.byte 1\n" /* Return address is in ra. */
|
||||||
|
"\t.byte 0xc\n\t.uleb128 3\n\t.uleb128 0\n" /* def_cfa sp 0 */
|
||||||
|
"\t.align 3\n"
|
||||||
|
".LECIE0:\n\n");
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".LSFDE0:\n"
|
||||||
|
"\t.4byte .LEFDE0-.LASFDE0\n"
|
||||||
|
".LASFDE0:\n"
|
||||||
|
"\t.4byte .Lframe0\n"
|
||||||
|
"\t.8byte .Lbegin\n"
|
||||||
|
"\t.8byte %d\n"
|
||||||
|
"\t.byte 0xe\n\t.uleb128 %d\n"
|
||||||
|
"\t.byte 0x81\n\t.uleb128 2*5\n" /* offset ra*/
|
||||||
|
"\t.byte 0x96\n\t.uleb128 2*6\n", /* offset fp */
|
||||||
|
fcofs, CFRAME_SIZE);
|
||||||
|
for (i = 31; i >= 23; i--) /* offset r31-r23 */
|
||||||
|
fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2*(31-i+7));
|
||||||
|
for (i = 31; i >= 24; i--) /* offset f31-f24 */
|
||||||
|
fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 2*(31-i+16));
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
"\t.align 3\n"
|
||||||
|
".LEFDE0:\n\n");
|
||||||
|
#if LJ_HASFFI
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".LSFDE1:\n"
|
||||||
|
"\t.4byte .LEFDE1-.LASFDE1\n"
|
||||||
|
".LASFDE1:\n"
|
||||||
|
"\t.4byte .Lframe0\n"
|
||||||
|
"\t.4byte lj_vm_ffi_call\n"
|
||||||
|
"\t.4byte %d\n"
|
||||||
|
"\t.byte 0x81\n\t.uleb128 2*5\n" /* offset ra*/
|
||||||
|
"\t.byte 0x96\n\t.uleb128 2*6\n" /* offset fp */
|
||||||
|
"\t.align 3\n"
|
||||||
|
".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
|
||||||
|
#endif
|
||||||
|
#if !LJ_NO_UNWIND
|
||||||
|
fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".Lframe1:\n"
|
||||||
|
"\t.4byte .LECIE1-.LSCIE1\n"
|
||||||
|
".LSCIE1:\n"
|
||||||
|
"\t.4byte 0\n"
|
||||||
|
"\t.byte 0x1\n"
|
||||||
|
"\t.string \"zPR\"\n"
|
||||||
|
"\t.uleb128 0x1\n"
|
||||||
|
"\t.sleb128 -4\n"
|
||||||
|
"\t.byte 1\n" /* Return address is in ra. */
|
||||||
|
"\t.uleb128 6\n" /* augmentation length */
|
||||||
|
"\t.byte 0x1b\n"
|
||||||
|
"\t.4byte lj_err_unwind_dwarf-.\n"
|
||||||
|
"\t.byte 0x1b\n"
|
||||||
|
"\t.byte 0xc\n\t.uleb128 3\n\t.uleb128 0\n" /* def_cfa sp 0 */
|
||||||
|
"\t.align 2\n"
|
||||||
|
".LECIE1:\n\n");
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".LSFDE2:\n"
|
||||||
|
"\t.4byte .LEFDE2-.LASFDE2\n"
|
||||||
|
".LASFDE2:\n"
|
||||||
|
"\t.4byte .LASFDE2-.Lframe1\n"
|
||||||
|
"\t.4byte .Lbegin-.\n"
|
||||||
|
"\t.4byte %d\n"
|
||||||
|
"\t.uleb128 0\n" /* augmentation length */
|
||||||
|
"\t.byte 0x81\n\t.uleb128 2*5\n" /* offset ra*/
|
||||||
|
"\t.byte 0x96\n\t.uleb128 2*6\n", /* offset fp */
|
||||||
|
fcofs);
|
||||||
|
for (i = 31; i >= 23; i--) /* offset r23-r31 */
|
||||||
|
fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2*(31-i+7));
|
||||||
|
for (i = 31; i >= 24; i--) /* offset f24-f31 */
|
||||||
|
fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 2*(31-i+16));
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
"\t.align 2\n"
|
||||||
|
".LEFDE2:\n\n");
|
||||||
|
#if LJ_HASFFI
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".Lframe2:\n"
|
||||||
|
"\t.4byte .LECIE2-.LSCIE2\n"
|
||||||
|
".LSCIE2:\n"
|
||||||
|
"\t.4byte 0\n"
|
||||||
|
"\t.byte 0x1\n"
|
||||||
|
"\t.string \"zR\"\n"
|
||||||
|
"\t.uleb128 0x1\n"
|
||||||
|
"\t.sleb128 -4\n"
|
||||||
|
"\t.byte 1\n" /* Return address is in ra. */
|
||||||
|
"\t.uleb128 1\n" /* augmentation length */
|
||||||
|
"\t.byte 0x1b\n"
|
||||||
|
"\t.byte 0xc\n\t.uleb128 3\n\t.uleb128 0\n" /* def_cfa sp 0 */
|
||||||
|
"\t.align 2\n"
|
||||||
|
".LECIE2:\n\n");
|
||||||
|
fprintf(ctx->fp,
|
||||||
|
".LSFDE3:\n"
|
||||||
|
"\t.4byte .LEFDE3-.LASFDE3\n"
|
||||||
|
".LASFDE3:\n"
|
||||||
|
"\t.4byte .LASFDE3- .Lframe2\n"
|
||||||
|
"\t.4byte lj_vm_ffi_call-.\n"
|
||||||
|
"\t.4byte %d\n"
|
||||||
|
"\t.uleb128 0\n" /* augmentation length */
|
||||||
|
"\t.byte 0x81\n\t.uleb128 2*5\n" /* offset ra*/
|
||||||
|
"\t.byte 0x96\n\t.uleb128 2*6\n" /* offset fp */
|
||||||
|
"\t.align 2\n"
|
||||||
|
".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if !LJ_NO_UNWIND
|
||||||
|
/* NYI */
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user