Author: zoltan
Date: 2005-06-09 16:23:06 -0400 (Thu, 09 Jun 2005)
New Revision: 45720
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/cpu-ia64.md
trunk/mono/mono/mini/exceptions-ia64.c
trunk/mono/mono/mini/inssel-ia64.brg
trunk/mono/mono/mini/mini-ia64.c
trunk/mono/mono/mini/mini-ia64.h
trunk/mono/mono/mini/mini.h
trunk/mono/mono/mini/tramp-ia64.c
Log:
2005-06-09 Zoltan Varga <[EMAIL PROTECTED]>
* *-ia64.*: Ongoing IA64 work.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/ChangeLog 2005-06-09 20:23:06 UTC (rev 45720)
@@ -1,5 +1,7 @@
2005-06-09 Zoltan Varga <[EMAIL PROTECTED]>
+ * *-ia64.*: Ongoing IA64 work.
+
* basic.cs: Add conv.ovf.i4.un test.
2005-06-09 Massimiliano Mantione <[EMAIL PROTECTED]>
Modified: trunk/mono/mono/mini/cpu-ia64.md
===================================================================
--- trunk/mono/mono/mini/cpu-ia64.md 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/cpu-ia64.md 2005-06-09 20:23:06 UTC (rev 45720)
@@ -66,7 +66,7 @@
stobj:
conv.ovf.i1.un:
conv.ovf.i2.un:
-conv.ovf.i4.un: dest:i src1:i len:48
+conv.ovf.i4.un: dest:i src1:i len:96
conv.ovf.i8.un:
conv.ovf.u1.un:
conv.ovf.u2.un:
@@ -121,7 +121,6 @@
mul.ovf.un: dest:i src1:i src2:i len:48
sub.ovf:
sub.ovf.un:
-endfinally:
leave:
leave.s:
stind.i:
@@ -149,7 +148,6 @@
ldloca:
stloc:
localloc: dest:i src1:i len:48
-endfilter:
unaligned.:
volatile.:
tail.:
@@ -365,7 +363,11 @@
float_clt_un_membase: dest:i src1:f src2:b len:48
float_conv_to_u: dest:i src1:f len:48
fmove: dest:f src1:f len:48
-call_handler: len:48
+call_handler: len:96
+start_handler: len:96
+op_endfilter: len:96
+endfinally: len:96
+endfilter: len:96
aot_const: dest:i len:48
tls_get: dest:i len:48
atomic_add_i4: src1:b src2:i dest:i len:48
Modified: trunk/mono/mono/mini/exceptions-ia64.c
===================================================================
--- trunk/mono/mono/mini/exceptions-ia64.c 2005-06-09 20:22:08 UTC (rev
45719)
+++ trunk/mono/mono/mini/exceptions-ia64.c 2005-06-09 20:23:06 UTC (rev
45720)
@@ -11,6 +11,10 @@
* We implement exception handling with the help of the libuwind library:
*
* http://www.hpl.hp.com/research/linux/libunwind/
+ *
+ * Under IA64 all functions are assumed to have unwind info, we do not need
to save
+ * the machine state in the LMF. But we have to generate unwind info for all
+ * dynamically generated code.
*/
#include <config.h>
@@ -38,38 +42,64 @@
#define GP_SCRATCH_REG 31
#define GP_SCRATCH_REG2 30
-/*
- * mono_arch_get_restore_context:
- *
- * Returns a pointer to a method which restores a previously saved sigcontext.
- */
-gpointer
-mono_arch_get_restore_context (void)
+static gpointer
+mono_create_ftnptr (gpointer ptr)
{
- static guint8 *start = NULL;
- static gboolean inited = FALSE;
- Ia64CodegenState code;
+ gpointer *desc = g_malloc (2 * sizeof (gpointer));
+ desc [0] = ptr;
+ desc [1] = NULL;
- if (inited)
- return start;
+ return desc;
+}
- /* restore_contect (MonoContext *ctx) */
+static void
+fill_monocontext_from_cursor (MonoContext *ctx)
+{
+ unw_word_t ip, sp, fp;
+ unw_cursor_t new_cursor;
+ int err;
- start = mono_global_codeman_reserve (256);
+ /* After changing the cursor, the variables in the MonoContext must be
updated */
+ err = unw_get_reg (&ctx->cursor, UNW_IA64_IP, &ip);
+ g_assert (err == 0);
- /* FIXME: */
- ia64_codegen_init (code, start);
- ia64_break_i (code, 0);
- ia64_codegen_close (code);
+ err = unw_get_reg (&ctx->cursor, UNW_IA64_SP, &sp);
+ g_assert (err == 0);
- g_assert ((code.buf - start) <= 256);
+ /* Fp is the SP of the parent frame */
+ new_cursor = ctx->cursor;
- mono_arch_flush_icache (start, code.buf - start);
+ err = unw_step (&new_cursor);
+ g_assert (err >= 0);
- return start;
+ err = unw_get_reg (&new_cursor, UNW_IA64_SP, &fp);
+ g_assert (err == 0);
+
+ MONO_CONTEXT_SET_IP (ctx, ip);
+ MONO_CONTEXT_SET_SP (ctx, sp);
+ MONO_CONTEXT_SET_BP (ctx, fp);
}
+static void
+restore_context (MonoContext *ctx)
+{
+ unw_set_reg (&ctx->cursor, UNW_IA64_IP, (guint64)ctx->ip);
+ unw_set_reg (&ctx->cursor, UNW_IA64_SP, (guint64)ctx->sp);
+ unw_resume (&ctx->cursor);
+}
+
/*
+ * mono_arch_get_restore_context:
+ *
+ * Returns a pointer to a method which restores a previously saved sigcontext.
+ */
+gpointer
+mono_arch_get_restore_context (void)
+{
+ return restore_context;
+}
+
+/*
* mono_arch_get_call_filter:
*
* Returns a pointer to a method which calls an exception filter. We
@@ -81,7 +111,6 @@
{
static guint8 *start;
static gboolean inited = FALSE;
- int i;
guint32 pos;
Ia64CodegenState code;
@@ -108,13 +137,12 @@
}
static void
-throw_exception (MonoObject *exc, guint64 rip, guint64 rethrow)
+throw_exception (MonoObject *exc, guint64 ip, guint64 rethrow)
{
static void (*restore_context) (MonoContext *);
unw_context_t unw_ctx;
MonoContext ctx;
int res;
- unw_word_t ip, sp;
if (!restore_context)
restore_context = mono_arch_get_restore_context ();
@@ -130,34 +158,23 @@
res = unw_init_local (&ctx.cursor, &unw_ctx);
g_assert (res == 0);
- res = unw_get_reg (&ctx.cursor, UNW_IA64_IP, &ip);
- g_assert (res == 0);
+ /* Get rid of this frame and the throw trampoline frame */
+ res = unw_step (&ctx.cursor);
+ g_assert (res >= 0);
+ res = unw_step (&ctx.cursor);
+ g_assert (res >= 0);
- res = unw_get_reg (&ctx.cursor, UNW_IA64_SP, &sp);
- g_assert (res == 0);
+ unw_set_reg (&ctx.cursor, UNW_IA64_IP, (guint64)ip);
- /* FIXME: bp */
+ fill_monocontext_from_cursor (&ctx);
- MONO_CONTEXT_SET_IP (&ctx, ip);
- MONO_CONTEXT_SET_SP (&ctx, sp);
-
- mono_handle_exception (&ctx, exc, (gpointer)(rip + 1), FALSE);
+ mono_handle_exception (&ctx, exc, (gpointer)(ip + 1), FALSE);
restore_context (&ctx);
g_assert_not_reached ();
}
static gpointer
-mono_create_ftnptr (gpointer ptr)
-{
- gpointer *desc = g_malloc (2 * sizeof (gpointer));
- desc [0] = ptr;
- desc [1] = NULL;
-
- return desc;
-}
-
-static gpointer
get_throw_trampoline (gboolean rethrow)
{
guint8* start;
@@ -265,7 +282,6 @@
gpointer
mono_arch_get_throw_exception_by_name (void)
{
- static gboolean inited = FALSE;
guint8* start;
Ia64CodegenState code;
@@ -298,24 +314,84 @@
{
static guint8* start;
static gboolean inited = FALSE;
- guint64 throw_ex;
+ gpointer ptr;
+ int i, in0, local0, out0, nout;
Ia64CodegenState code;
+ unw_dyn_info_t *di;
+ unw_dyn_region_info_t *r_pro;
if (inited)
return start;
- start = mono_global_codeman_reserve (64);
+ start = mono_global_codeman_reserve (1024);
- /* FIXME: */
+ in0 = 32;
+ local0 = in0 + 2;
+ out0 = local0 + 4;
+ nout = 3;
+
+ /* FIXME: Add unwind info */
+
ia64_codegen_init (code, start);
+ ia64_alloc (code, local0 + 0, local0 - in0, out0 - local0, nout, 0);
+ ia64_mov_from_br (code, local0 + 1, IA64_RP);
+
+ r_pro = g_malloc0 (_U_dyn_region_info_size (2));
+ r_pro->op_count = 2;
+ r_pro->insn_count = 6;
+ i = 0;
+ _U_dyn_op_save_reg (&r_pro->op[i++], _U_QP_TRUE, /* when=*/ 2,
+ /* reg=*/ UNW_IA64_AR_PFS, /*
dst=*/ UNW_IA64_GR + local0 + 0);
+ _U_dyn_op_save_reg (&r_pro->op[i++], _U_QP_TRUE, /* when=*/ 5,
+ /* reg=*/ UNW_IA64_RP, /*
dst=*/ UNW_IA64_GR + local0 + 1);
+ g_assert ((unsigned) i <= r_pro->op_count);
+
+ /* Call exception_from_token */
+ ia64_movl (code, out0 + 0, mono_defaults.exception_class->image);
+ ia64_mov (code, out0 + 1, in0 + 0);
+ ptr = mono_exception_from_token;
+ ia64_movl (code, GP_SCRATCH_REG, ptr);
+ ia64_ld8_inc_imm (code, GP_SCRATCH_REG2, GP_SCRATCH_REG, 8);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG2);
+ ia64_ld8 (code, IA64_GP, GP_SCRATCH_REG);
+ ia64_br_call_reg (code, IA64_B0, IA64_B6);
+ ia64_mov (code, local0 + 3, IA64_R8);
+
+ /* Compute throw ip */
+ ia64_mov (code, local0 + 2, local0 + 1);
+ ia64_sub (code, local0 + 2, local0 + 2, in0 + 1);
+
+ /* Set args */
+ ia64_mov (code, out0 + 0, local0 + 3);
+ ia64_mov (code, out0 + 1, local0 + 2);
+ ia64_mov (code, out0 + 2, IA64_R0);
+
+ /* Call throw_exception */
+ ptr = throw_exception;
+ ia64_movl (code, GP_SCRATCH_REG, ptr);
+ ia64_ld8_inc_imm (code, GP_SCRATCH_REG2, GP_SCRATCH_REG, 8);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG2);
+ ia64_ld8 (code, IA64_GP, GP_SCRATCH_REG);
+ ia64_br_call_reg (code, IA64_B0, IA64_B6);
+
ia64_break_i (code, 0);
ia64_codegen_close (code);
- g_assert ((code.buf - start) <= 256);
+ g_assert ((code.buf - start) <= 1024);
+ di = g_malloc0 (sizeof (unw_dyn_info_t));
+ di->start_ip = (unw_word_t) start;
+ di->end_ip = (unw_word_t) code.buf;
+ di->gp = 0;
+ di->format = UNW_INFO_FORMAT_DYNAMIC;
+ di->u.pi.name_ptr = (unw_word_t)"throw_corlib_exception_trampoline";
+ di->u.pi.regions = r_pro;
+
+ _U_dyn_register (di);
+
mono_arch_flush_icache (start, code.buf - start);
- return start;
+ return mono_create_ftnptr (start);
}
/* mono_arch_find_jit_info:
@@ -333,26 +409,35 @@
gboolean *managed)
{
MonoJitInfo *ji;
- int i, err;
- unw_word_t ip, sp;
+ int err;
+ unw_word_t ip;
*new_ctx = *ctx;
while (TRUE) {
- ip = MONO_CONTEXT_GET_IP (new_ctx);
+ err = unw_get_reg (&new_ctx->cursor, UNW_IA64_IP, &ip);
+ g_assert (err == 0);
/* Avoid costly table lookup during stack overflow */
- if (prev_ji && (ip > prev_ji->code_start && ((guint8*)ip <
((guint8*)prev_ji->code_start) + prev_ji->code_size)))
+ if (prev_ji && ((guint8*)ip > (guint8*)prev_ji->code_start &&
((guint8*)ip < ((guint8*)prev_ji->code_start) + prev_ji->code_size)))
ji = prev_ji;
else
- ji = mono_jit_info_table_find (domain, ip);
+ ji = mono_jit_info_table_find (domain, (gpointer)ip);
if (managed)
*managed = FALSE;
+ /*
+ {
+ char name[256];
+ unw_word_t off;
+
+ unw_get_proc_name (&new_ctx->cursor, name, 256, &off);
+ printf ("F: %s\n", name);
+ }
+ */
+
if (ji != NULL) {
- int offset;
-
if (managed)
if (!ji->method->wrapper_type)
*managed = TRUE;
@@ -363,7 +448,6 @@
* JIT, so we have to restore callee saved registers
from the lmf.
*/
if (ji->method->save_lmf) {
- NOT_IMPLEMENTED;
}
else {
}
@@ -373,51 +457,27 @@
*lmf = (*lmf)->previous_lmf;
}
- err = unw_step (&new_ctx->cursor);
- g_assert (err >= 0);
-
- err = unw_get_reg (&new_ctx->cursor, UNW_IA64_IP, &ip);
- g_assert (err == 0);
-
- err = unw_get_reg (&new_ctx->cursor, UNW_IA64_SP, &sp);
- g_assert (err == 0);
-
- /* FIXME: bp */
-
- MONO_CONTEXT_SET_IP (new_ctx, ip);
- MONO_CONTEXT_SET_SP (new_ctx, sp);
-
- return ji;
+ break;
}
/* This is an unmanaged frame, so just unwind through it */
err = unw_step (&new_ctx->cursor);
g_assert (err >= 0);
- {
- char name[256];
- unw_word_t off;
-
- unw_get_proc_name (&new_ctx->cursor, name, 256, &off);
- printf ("F: %s\n", name);
- }
-
if (err == 0)
- return NULL;
+ break;
+ }
- err = unw_get_reg (&new_ctx->cursor, UNW_IA64_IP, &ip);
- g_assert (err == 0);
+ if (ji) {
+ err = unw_step (&new_ctx->cursor);
+ g_assert (err >= 0);
- err = unw_get_reg (&new_ctx->cursor, UNW_IA64_SP, &sp);
- g_assert (err == 0);
+ fill_monocontext_from_cursor (new_ctx);
- /* FIXME: bp */
-
- MONO_CONTEXT_SET_IP (new_ctx, ip);
- MONO_CONTEXT_SET_SP (new_ctx, sp);
+ return ji;
}
-
- return NULL;
+ else
+ return NULL;
}
/**
Modified: trunk/mono/mono/mini/inssel-ia64.brg
===================================================================
--- trunk/mono/mono/mini/inssel-ia64.brg 2005-06-09 20:22:08 UTC (rev
45719)
+++ trunk/mono/mono/mini/inssel-ia64.brg 2005-06-09 20:23:06 UTC (rev
45720)
@@ -260,15 +260,16 @@
stmt: OP_START_HANDLER {
- /* FIXME: */
+ mono_bblock_add_inst (s->cbb, tree);
}
stmt: CEE_ENDFINALLY {
- /* FIXME: */
+ mono_bblock_add_inst (s->cbb, tree);
}
stmt: OP_ENDFILTER (reg) {
- /* FIXME: */
+ tree->sreg1 = state->left->reg1;
+ mono_bblock_add_inst (s->cbb, tree);
}
%%
Modified: trunk/mono/mono/mini/mini-ia64.c
===================================================================
--- trunk/mono/mono/mini/mini-ia64.c 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/mini-ia64.c 2005-06-09 20:23:06 UTC (rev 45720)
@@ -503,8 +503,11 @@
cfg->arch.reg_saved_b0 = cfg->arch.reg_local0 - 2;
cfg->arch.reg_saved_sp = cfg->arch.reg_local0 - 3;
- /* Need to allocate at least 1 out register for use by CEE_THROW */
- cfg->arch.n_out_regs = MAX (cfg->arch.n_out_regs, 1);
+ /*
+ * Need to allocate at least 2 out register for use by CEE_THROW / the
system
+ * exception throwing code.
+ */
+ cfg->arch.n_out_regs = MAX (cfg->arch.n_out_regs, 2);
g_free (cinfo);
}
@@ -1679,7 +1682,7 @@
while (ins) {
offset = code.buf - cfg->native_code;
- max_len = ((guint8 *)ins_spec [ins->opcode])[MONO_INST_LEN];
+ max_len = ((int)(((guint8 *)ins_spec
[ins->opcode])[MONO_INST_LEN]));
if (offset > (cfg->code_size - max_len - 16)) {
ia64_codegen_close (code);
@@ -2046,8 +2049,9 @@
ia64_break_i_pred (code, 7, 0);
break;
case OP_IA64_COND_EXC:
- /* FIXME: */
- ia64_break_i_pred (code, 6, 0);
+ mono_add_patch_info (cfg, code.buf - cfg->native_code,
+
MONO_PATCH_INFO_EXC, ins->inst_p1);
+ ia64_br_cond_pred (code, 6, 0);
break;
case OP_IA64_CSET:
/* FIXME: Do this with one instruction ? */
@@ -2087,7 +2091,19 @@
/* FIXME: */
ia64_mov (code, ins->dreg, ins->sreg1);
break;
+ case CEE_CONV_OVF_I4_UN:
+ /* FIXME: Do this in the lowering pass */
+ ia64_movl (code, GP_SCRATCH_REG, 0x7fffffff);
+ ia64_cmp4_gtu (code, 6, 7, ins->sreg1, GP_SCRATCH_REG);
+ mono_add_patch_info (cfg, code.buf - cfg->native_code,
+
MONO_PATCH_INFO_EXC, "OverflowException");
+ ia64_br_cond_pred (code, 6, 0);
+
+ /* FIXME: */
+ ia64_mov (code, ins->dreg, ins->sreg1);
+ break;
+
/*
* FLOAT OPCODES
*/
@@ -2233,9 +2249,46 @@
/* Exception handling */
case OP_CALL_HANDLER:
- /* FIXME: */
+ /*
+ * Using a call instruction would mess up the register
stack, so
+ * save the return address to a register and use a
+ * branch.
+ */
+ ia64_mov_from_ip (code, GP_SCRATCH_REG);
+ /* Add the length of OP_CALL_HANDLER */
+ ia64_adds_imm (code, GP_SCRATCH_REG, 5 * 16,
GP_SCRATCH_REG);
+ mono_add_patch_info (cfg, code.buf - cfg->native_code,
MONO_PATCH_INFO_BB, ins->inst_target_bb);
+ ia64_movl (code, GP_SCRATCH_REG2, 0);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG2);
+ ia64_br_cond_reg (code, IA64_B6);
break;
+ case OP_START_HANDLER: {
+ /*
+ * We receive the return address in GP_SCRATCH_REG.
+ */
+ MonoInst *spvar = mono_find_spvar_for_region (cfg,
bb->region);
+ ia64_adds_imm (code, GP_SCRATCH_REG2,
spvar->inst_offset, cfg->frame_reg);
+ ia64_st8_hint (code, GP_SCRATCH_REG2, GP_SCRATCH_REG,
0);
+ break;
+ }
+ case CEE_ENDFINALLY: {
+ MonoInst *spvar = mono_find_spvar_for_region (cfg,
bb->region);
+ ia64_adds_imm (code, GP_SCRATCH_REG,
spvar->inst_offset, cfg->frame_reg);
+ ia64_ld8_hint (code, GP_SCRATCH_REG, GP_SCRATCH_REG, 0);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG);
+ ia64_br_cond_reg (code, IA64_B6);
+ break;
+ }
+ case OP_ENDFILTER: {
+ /* FIXME: Return the value */
+ MonoInst *spvar = mono_find_spvar_for_region (cfg,
bb->region);
+ ia64_adds_imm (code, GP_SCRATCH_REG,
spvar->inst_offset, cfg->frame_reg);
+ ia64_ld8_hint (code, GP_SCRATCH_REG, GP_SCRATCH_REG, 0);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG);
+ ia64_br_cond_reg (code, IA64_B6);
+ break;
+ }
case CEE_THROW:
ia64_mov (code, cfg->arch.reg_out0, ins->sreg1);
code = emit_call (cfg, code,
MONO_PATCH_INFO_INTERNAL_METHOD,
@@ -2306,6 +2359,111 @@
{0, 0, 0}
};
+static gboolean stops_in_template [32][3] = {
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, TRUE, FALSE },
+ { FALSE, TRUE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE },
+
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { TRUE, FALSE, FALSE },
+ { TRUE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, TRUE },
+ { FALSE, FALSE, FALSE },
+ { FALSE, FALSE, FALSE }
+};
+
+void
+ia64_emit_bundle (Ia64CodegenState *code, gboolean flush)
+{
+ int i, j, ins_type, template;
+
+ if (!code->automatic) {
+ if (code->nins == 0)
+ return;
+
+ g_assert (code->nins == 3);
+
+ /* Verify template is correct */
+ template = code->template;
+ for (j = 0; j < 3; ++j) {
+ if (code->stops [j])
+ g_assert (stops_in_template [template]);
+
+ ins_type = ins_types_in_template [template][j];
+ switch (code->itypes [j]) {
+ case IA64_INS_TYPE_A:
+ g_assert ((ins_type == IA64_INS_TYPE_I) ||
(ins_type == IA64_INS_TYPE_M));
+ break;
+ case IA64_INS_TYPE_LX:
+ g_assert (j == 1);
+ g_assert (ins_type == IA64_INS_TYPE_LX);
+ j ++;
+ break;
+ default:
+ g_assert (ins_type == code->itypes [j]);
+ }
+ }
+
+ ia64_emit_bundle_template (code, template, code->instructions
[0], code->instructions [1], code->instructions [2]);
+ code->template = 0;
+ code->nins = 0;
+ return;
+ }
+
+ for (i = 0; i < code->nins; ++i) {
+ switch (code->itypes [i]) {
+ case IA64_INS_TYPE_A:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MIIS,
code->instructions [i], IA64_NOP_I, IA64_NOP_I);
+ break;
+ case IA64_INS_TYPE_I:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MIIS,
IA64_NOP_M, code->instructions [i], IA64_NOP_I);
+ break;
+ case IA64_INS_TYPE_M:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MIIS,
code->instructions [i], IA64_NOP_I, IA64_NOP_I);
+ break;
+ case IA64_INS_TYPE_B:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MIBS,
IA64_NOP_M, IA64_NOP_I, code->instructions [i]);
+ break;
+ case IA64_INS_TYPE_F:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MFIS,
IA64_NOP_M, code->instructions [i], IA64_NOP_I);
+ break;
+ case IA64_INS_TYPE_LX:
+ ia64_emit_bundle_template (code, IA64_TEMPLATE_MLXS,
IA64_NOP_M, code->instructions [i], code->instructions [i + 1]);
+ i ++;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ }
+
+ code->nins = 0;
+}
+
static void
ia64_patch (unsigned char* code, gpointer target)
{
@@ -2428,6 +2586,8 @@
int alloc_size, pos, max_offset, i;
Ia64CodegenState code;
CallInfo *cinfo;
+ unw_dyn_region_info_t *r_pro;
+ int unw_op_count;
sig = mono_method_signature (method);
pos = 0;
@@ -2438,10 +2598,8 @@
cfg->native_code = g_malloc (cfg->code_size);
ia64_codegen_init (code, cfg->native_code);
+ ia64_codegen_set_automatic (code, FALSE);
- ia64_alloc (code, cfg->arch.reg_saved_ar_pfs, cfg->arch.reg_local0 -
cfg->arch.reg_in0, cfg->arch.reg_out0 - cfg->arch.reg_local0,
cfg->arch.n_out_regs, 0);
- ia64_mov_from_br (code, cfg->arch.reg_saved_b0, IA64_B0);
-
alloc_size = ALIGN_TO (cfg->stack_offset, MONO_ARCH_FRAME_ALIGNMENT);
if (cfg->param_area)
alloc_size += cfg->param_area;
@@ -2460,48 +2618,62 @@
alloc_size -= pos;
- if (alloc_size || cinfo->stack_usage)
+ /* Initialize unwind info */
+ r_pro = g_malloc0 (_U_dyn_region_info_size (3));
+ unw_op_count = 0;
+
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_MIIS);
+ ia64_alloc (code, cfg->arch.reg_saved_ar_pfs, cfg->arch.reg_local0 -
cfg->arch.reg_in0, cfg->arch.reg_out0 - cfg->arch.reg_local0,
cfg->arch.n_out_regs, 0);
+ ia64_mov_from_br (code, cfg->arch.reg_saved_b0, IA64_B0);
+
+ _U_dyn_op_save_reg (&r_pro->op[unw_op_count++], _U_QP_TRUE, /* when=*/
0,
+ /* reg=*/ UNW_IA64_AR_PFS, /*
dst=*/ UNW_IA64_GR + cfg->arch.reg_saved_ar_pfs);
+ _U_dyn_op_save_reg (&r_pro->op[unw_op_count++], _U_QP_TRUE, /* when=*/
1,
+ /* reg=*/ UNW_IA64_RP, /*
dst=*/ UNW_IA64_GR + cfg->arch.reg_saved_b0);
+
+ if (alloc_size || cinfo->stack_usage) {
ia64_mov (code, cfg->frame_reg, IA64_SP);
+ _U_dyn_op_save_reg (&r_pro->op[unw_op_count++], _U_QP_TRUE, /*
when=*/ 2,
+ /* reg=*/ UNW_IA64_SP,
/* dst=*/ UNW_IA64_GR + cfg->frame_reg);
+ }
+ else
+ ia64_nop_i (code, 0);
+ ia64_stop (code);
+ ia64_end_bundle (code);
+ /* Finish unwind info */
+ r_pro->op_count = unw_op_count;
+ r_pro->insn_count = (code.buf - cfg->native_code) >> 4;
+
+ cfg->arch.r_pro = r_pro;
+
if (alloc_size) {
/* See mono_emit_stack_alloc */
#if defined(MONO_ARCH_SIGSEGV_ON_ALTSTACK)
NOT_IMPLEMENTED;
#else
- ia64_mov (code, cfg->arch.reg_saved_sp, IA64_SP);
- if (ia64_is_imm14 (-alloc_size))
+ if (ia64_is_imm14 (-alloc_size)) {
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_MISI);
+ ia64_nop_m (code, 0);
+ ia64_mov (code, cfg->arch.reg_saved_sp, IA64_SP);
ia64_stop (code);
ia64_adds_imm (code, IA64_SP, (-alloc_size), IA64_SP);
+ ia64_end_bundle (code);
+ }
else {
- ia64_movl (code, GP_SCRATCH_REG, -alloc_size);
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_MLXS);
+ ia64_mov (code, cfg->arch.reg_saved_sp, IA64_SP);
+ ia64_movl (code, GP_SCRATCH_REG, -alloc_size);
ia64_stop (code);
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_MIIS);
ia64_add (code, IA64_SP, GP_SCRATCH_REG, IA64_SP);
+ ia64_nop_i (code, 0);
+ ia64_nop_i (code, 0); ia64_stop (code);
+ ia64_end_bundle (code);
}
#endif
}
+ ia64_codegen_set_automatic (code, TRUE);
- /* compute max_offset in order to use short forward jumps */
- max_offset = 0;
- if (cfg->opt & MONO_OPT_BRANCH) {
- for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
- MonoInst *ins = bb->code;
- bb->max_offset = max_offset;
-
- if (cfg->prof_options & MONO_PROFILE_COVERAGE)
- max_offset += 6;
- /* max alignment for loops */
- if ((cfg->opt & MONO_OPT_LOOP) && bb_is_loop_start (bb))
- max_offset += LOOP_ALIGNMENT;
-
- while (ins) {
- if (ins->opcode == OP_LABEL)
- ins->inst_c1 = max_offset;
-
- max_offset += ((guint8 *)ins_spec
[ins->opcode])[MONO_INST_LEN];
- ins = ins->next;
- }
- }
- }
-
if (sig->ret->type != MONO_TYPE_VOID) {
if ((cinfo->ret.storage == ArgInIReg) && (cfg->ret->opcode !=
OP_REGVAR)) {
/* Save volatile arguments to the stack */
@@ -2603,6 +2775,8 @@
mono_jit_stats.code_reallocs++;
}
+ /* FIXME: Emit unwind info */
+
buf = cfg->native_code + cfg->code_len;
if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
@@ -2624,13 +2798,25 @@
}
g_free (cinfo);
+ ia64_end_bundle (code);
+ ia64_codegen_set_automatic (code, FALSE);
+
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_MIIS);
if (cfg->arch.stack_alloc_size)
ia64_mov (code, IA64_SP, cfg->arch.reg_saved_sp);
+ else
+ ia64_nop_m (code, 0);
+ ia64_mov_to_ar_i (code, IA64_PFS, cfg->arch.reg_saved_ar_pfs);
+ ia64_mov_ret_to_br (code, IA64_B0, cfg->arch.reg_saved_b0); ia64_stop
(code);
+ ia64_end_bundle (code);
- ia64_mov_to_ar_i (code, IA64_PFS, cfg->arch.reg_saved_ar_pfs);
- ia64_mov_ret_to_br (code, IA64_B0, cfg->arch.reg_saved_b0);
+ ia64_begin_bundle_template (code, IA64_TEMPLATE_BBBS);
ia64_br_ret_reg (code, IA64_B0);
+ ia64_nop_b (code, 0);
+ ia64_nop_b (code, 0); ia64_stop (code);
+ ia64_end_bundle (code);
+ ia64_codegen_set_automatic (code, TRUE);
ia64_codegen_close (code);
cfg->code_len = code.buf - cfg->native_code;
@@ -2653,25 +2839,61 @@
/* Compute needed space */
for (patch_info = cfg->patch_info; patch_info; patch_info =
patch_info->next) {
if (patch_info->type == MONO_PATCH_INFO_EXC)
- code_size += 40;
+ code_size += 256;
if (patch_info->type == MONO_PATCH_INFO_R8)
code_size += 8 + 7; /* sizeof (double) + alignment */
if (patch_info->type == MONO_PATCH_INFO_R4)
code_size += 4 + 7; /* sizeof (float) + alignment */
}
+ while (cfg->code_len + code_size > (cfg->code_size - 16)) {
+ cfg->code_size *= 2;
+ cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
+ mono_jit_stats.code_reallocs++;
+ }
+
ia64_codegen_init (code, cfg->native_code + cfg->code_len);
/* add code to raise exceptions */
+ /* FIXME: Optimize this */
nthrows = 0;
for (patch_info = cfg->patch_info; patch_info; patch_info =
patch_info->next) {
switch (patch_info->type) {
case MONO_PATCH_INFO_EXC: {
- NOT_IMPLEMENTED;
+ MonoClass *exc_class;
+ guint8* throw_ip;
+ guint8* buf;
+
+ exc_class = mono_class_from_name (mono_defaults.corlib,
"System", patch_info->data.name);
+ g_assert (exc_class);
+ throw_ip = cfg->native_code + patch_info->ip.i;
+
+ ia64_patch (cfg->native_code + patch_info->ip.i,
code.buf);
+
+ ia64_movl (code, cfg->arch.reg_out0 + 0,
exc_class->type_token);
+
+ ia64_begin_bundle (code);
+
+ patch_info->data.name =
"mono_arch_throw_corlib_exception";
+ patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
+ patch_info->ip.i = code.buf - cfg->native_code;
+
+ /* Indirect call */
+ ia64_movl (code, GP_SCRATCH_REG, 0);
+ ia64_ld8_inc_imm (code, GP_SCRATCH_REG2,
GP_SCRATCH_REG, 8);
+ ia64_mov_to_br (code, IA64_B6, GP_SCRATCH_REG2);
+ ia64_ld8 (code, IA64_GP, GP_SCRATCH_REG);
+
+ /* Compute the offset */
+ buf = code.buf + 32;
+ ia64_movl (code, cfg->arch.reg_out0 + 1, buf -
throw_ip);
+
+ ia64_br_call_reg (code, IA64_B0, IA64_B6);
+ break;
+ }
default:
break;
}
- }
}
ia64_codegen_close (code);
@@ -2698,6 +2920,24 @@
}
void
+mono_arch_save_unwind_info (MonoCompile *cfg)
+{
+ unw_dyn_info_t *di;
+
+ /* FIXME: Unregister this for dynamic methods */
+
+ di = g_malloc0 (sizeof (unw_dyn_info_t));
+ di->start_ip = (unw_word_t) cfg->native_code;
+ di->end_ip = (unw_word_t) cfg->native_code + cfg->code_len;
+ di->gp = 0;
+ di->format = UNW_INFO_FORMAT_DYNAMIC;
+ di->u.pi.name_ptr = (unw_word_t)mono_method_full_name (cfg->method,
TRUE);
+ di->u.pi.regions = cfg->arch.r_pro;
+
+ _U_dyn_register (di);
+}
+
+void
mono_arch_flush_icache (guint8 *code, gint size)
{
guint8* p = (guint8*)((guint64)code & ~(0x3f));
Modified: trunk/mono/mono/mini/mini-ia64.h
===================================================================
--- trunk/mono/mono/mini/mini-ia64.h 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/mini-ia64.h 2005-06-09 20:23:06 UTC (rev 45720)
@@ -72,6 +72,7 @@
gint32 reg_saved_ar_pfs;
gint32 reg_saved_b0;
gint32 reg_saved_sp;
+ unw_dyn_region_info_t *r_pro;
} MonoCompileArch;
#define MONO_CONTEXT_SET_IP(ctx,eip) do { (ctx)->ip = (gpointer)(eip); } while
(0);
@@ -111,5 +112,6 @@
#define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
#define MONO_ARCH_HAVE_PIC_AOT 1
#define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN 1
+#define MONO_ARCH_HAVE_SAVE_UNWIND_INFO 1
#endif /* __MONO_MINI_IA64_H__ */
Modified: trunk/mono/mono/mini/mini.h
===================================================================
--- trunk/mono/mono/mini/mini.h 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/mini.h 2005-06-09 20:23:06 UTC (rev 45720)
@@ -900,6 +900,7 @@
gpointer*mono_arch_get_vcall_slot_addr (guint8* code, gpointer *regs);
gpointer*mono_arch_get_delegate_method_ptr_addr (guint8* code, gpointer *regs);
void mono_arch_create_vars (MonoCompile *cfg);
+void mono_arch_save_unwind_info (MonoCompile *cfg);
/* Exception handling */
gboolean mono_handle_exception (MonoContext *ctx, gpointer
obj,
Modified: trunk/mono/mono/mini/tramp-ia64.c
===================================================================
--- trunk/mono/mono/mini/tramp-ia64.c 2005-06-09 20:22:08 UTC (rev 45719)
+++ trunk/mono/mono/mini/tramp-ia64.c 2005-06-09 20:23:06 UTC (rev 45720)
@@ -309,6 +309,8 @@
ia64_codegen_close (code);
+ g_assert (code.buf - buf <= TRAMPOLINE_SIZE);
+
mono_arch_flush_icache (buf, code.buf - buf);
ji = g_new0 (MonoJitInfo, 1);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches