Author: zoltan
Date: 2007-10-06 16:16:13 -0400 (Sat, 06 Oct 2007)
New Revision: 87034
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini-sparc.c
trunk/mono/mono/mini/mini-sparc.h
Log:
2007-10-06 Zoltan Varga <[EMAIL PROTECTED]>
* mini-sparc.c (mono_arch_get_vcall_slot_addr): Allow signed
displacements.
* mini-sparc.h mini-sparc.c: Implement IMT support.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2007-10-06 20:04:25 UTC (rev 87033)
+++ trunk/mono/mono/mini/ChangeLog 2007-10-06 20:16:13 UTC (rev 87034)
@@ -1,5 +1,9 @@
2007-10-06 Zoltan Varga <[EMAIL PROTECTED]>
+ * mini-sparc.c (mono_arch_get_vcall_slot_addr): Allow signed
displacements.
+
+ * mini-sparc.h mini-sparc.c: Implement IMT support.
+
* tramp-sparc.c (mono_arch_create_trampoline_code): Rework the
trampoline code so
its smaller and doesn't clobber sparc_g1.
Modified: trunk/mono/mono/mini/mini-sparc.c
===================================================================
--- trunk/mono/mono/mini/mini-sparc.c 2007-10-06 20:04:25 UTC (rev 87033)
+++ trunk/mono/mono/mini/mini-sparc.c 2007-10-06 20:16:13 UTC (rev 87034)
@@ -2181,7 +2181,7 @@
if ((sparc_inst_op (prev_ins) == 0x3) && (sparc_inst_i
(prev_ins) == 1) && (sparc_inst_op3 (prev_ins) == 0 || sparc_inst_op3
(prev_ins) == 0xb)) {
/* ld [r1 + CONST ], r2; call r2 */
guint32 base = sparc_inst_rs1 (prev_ins);
- guint32 disp = sparc_inst_imm13 (prev_ins);
+ gint32 disp = (((gint32)(sparc_inst_imm13 (prev_ins)))
<< 19) >> 19;
gpointer base_val;
g_assert (sparc_inst_rd (prev_ins) == sparc_inst_rs1
(ins));
@@ -2232,7 +2232,117 @@
return NULL;
}
+#define CMP_SIZE 3
+#define BR_SMALL_SIZE 2
+#define BR_LARGE_SIZE 2
+#define JUMP_IMM_SIZE 5
+#define ENABLE_WRONG_METHOD_CHECK 0
+
/*
+ * LOCKING: called with the domain lock held
+ */
+gpointer
+mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
MonoIMTCheckItem **imt_entries, int count)
+{
+ int i;
+ int size = 0;
+ guint32 *code, *start;
+
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ if (item->is_equals) {
+ if (item->check_target_idx) {
+ if (!item->compare_done)
+ item->chunk_size += CMP_SIZE;
+ item->chunk_size += BR_SMALL_SIZE +
JUMP_IMM_SIZE;
+ } else {
+ item->chunk_size += JUMP_IMM_SIZE;
+#if ENABLE_WRONG_METHOD_CHECK
+ item->chunk_size += CMP_SIZE + BR_SMALL_SIZE +
1;
+#endif
+ }
+ } else {
+ item->chunk_size += CMP_SIZE + BR_LARGE_SIZE;
+ imt_entries [item->check_target_idx]->compare_done =
TRUE;
+ }
+ size += item->chunk_size;
+ }
+ code = mono_code_manager_reserve (domain->code_mp, size * 4);
+ start = code;
+
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ item->code_target = (guint8*)code;
+ if (item->is_equals) {
+ if (item->check_target_idx) {
+ if (!item->compare_done) {
+ sparc_set (code, (guint32)item->method,
sparc_g5);
+ sparc_cmp (code, MONO_ARCH_IMT_REG,
sparc_g5);
+ }
+ item->jmp_code = (guint8*)code;
+ sparc_branch (code, 0, sparc_bne, 0);
+ sparc_nop (code);
+ sparc_set (code, ((guint32)(&(vtable->vtable
[item->vtable_slot]))), sparc_g5);
+ sparc_ld (code, sparc_g5, 0, sparc_g5);
+ sparc_jmpl (code, sparc_g5, sparc_g0, sparc_g0);
+ sparc_nop (code);
+ } else {
+ /* enable the commented code to assert on wrong
method */
+#if ENABLE_WRONG_METHOD_CHECK
+ g_assert_not_reached ();
+#endif
+ sparc_set (code, ((guint32)(&(vtable->vtable
[item->vtable_slot]))), sparc_g5);
+ sparc_ld (code, sparc_g5, 0, sparc_g5);
+ sparc_jmpl (code, sparc_g5, sparc_g0, sparc_g0);
+ sparc_nop (code);
+#if ENABLE_WRONG_METHOD_CHECK
+ g_assert_not_reached ();
+#endif
+ }
+ } else {
+ sparc_set (code, (guint32)item->method, sparc_g5);
+ sparc_cmp (code, MONO_ARCH_IMT_REG, sparc_g5);
+ item->jmp_code = (guint8*)code;
+ sparc_branch (code, 0, sparc_beu, 0);
+ sparc_nop (code);
+ }
+ }
+ /* patch the branches to get to the target items */
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ if (item->jmp_code) {
+ if (item->check_target_idx) {
+ sparc_patch ((guint32*)item->jmp_code,
imt_entries [item->check_target_idx]->code_target);
+ }
+ }
+ }
+
+ mono_arch_flush_icache ((guint8*)start, (code - start) * 4);
+
+ mono_stats.imt_thunks_size += (code - start) * 4;
+ g_assert (code - start <= size);
+ return start;
+}
+
+MonoMethod*
+mono_arch_find_imt_method (gpointer *regs, guint8 *code)
+{
+#ifdef SPARCV9
+ g_assert_not_reached ();
+#endif
+
+ return (MonoMethod*)regs [sparc_g1];
+}
+
+MonoObject*
+mono_arch_find_this_argument (gpointer *regs, MonoMethod *method)
+{
+ mono_sparc_flushw ();
+
+ return (gpointer)regs [sparc_o0];
+}
+
+/*
* Some conventions used in the following code.
* 2) The only scratch registers we have are o7 and g1. We try to
* stick to o7 when we can, and use g1 when necessary.
Modified: trunk/mono/mono/mini/mini-sparc.h
===================================================================
--- trunk/mono/mono/mini/mini-sparc.h 2007-10-06 20:04:25 UTC (rev 87033)
+++ trunk/mono/mono/mini/mini-sparc.h 2007-10-06 20:16:13 UTC (rev 87034)
@@ -18,7 +18,7 @@
*/
#define MONO_ARCH_CALLEE_REGS ((1 << sparc_o0) | (1 << sparc_o1) | (1 <<
sparc_o2) | (1 << sparc_o3) | (1 << sparc_o4) | (1 << sparc_o5) | (1 <<
sparc_l7))
-#define MONO_ARCH_CALLEE_SAVED_REGS (~MONO_ARCH_CALLEE_REGS)
+#define MONO_ARCH_CALLEE_SAVED_REGS ((~MONO_ARCH_CALLEE_REGS) & ~(1 <<
sparc_g1))
#ifdef SPARCV9
/* Use %d34..%d62 as the double precision floating point local registers */
@@ -124,6 +124,8 @@
#define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
#define MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN 1
#define MONO_ARCH_HAVE_CREATE_SPECIFIC_TRAMPOLINE 1
+#define MONO_ARCH_HAVE_IMT 1
+#define MONO_ARCH_IMT_REG sparc_g1
#ifdef SPARCV9
#define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches