[jit] Using a literal field with stdsfld/ldsfld should trigger a MissingFieldExceptio...
[mono.git] / mono / mini / tramp-arm.c
index 156a5ee54fb561dc72c3573cd46e9de525c14eaa..2430e2295ceda8979dab5340ee18e038b737c70b 100644 (file)
@@ -23,6 +23,7 @@
 #include "mini.h"
 #include "mini-arm.h"
 #include "debugger-agent.h"
+#include "jit-icalls.h"
 
 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
 
@@ -167,7 +168,7 @@ emit_bx (guint8* code, int reg)
 
 /* Stack size for trampoline function
  */
-#define STACK ALIGN_TO (sizeof (MonoLMF), 8)
+#define STACK ALIGN_TO (sizeof (MonoLMF), MONO_ARCH_FRAME_ALIGNMENT)
 
 /* Method-specific trampoline code fragment size */
 #define METHOD_TRAMPOLINE_SIZE 64
@@ -183,11 +184,10 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
 #ifdef USE_JUMP_TABLES
        gpointer *load_get_lmf_addr = NULL, *load_trampoline = NULL;
 #else
-        guint8 *load_get_lmf_addr  = NULL, *load_trampoline  = NULL;
+       guint8 *load_get_lmf_addr  = NULL, *load_trampoline  = NULL;
        gpointer *constants;
 #endif
-
-       int cfa_offset, regsave_size, lr_offset;
+       int i, cfa_offset, regsave_size, lr_offset;
        GSList *unwind_ops = NULL;
        MonoJumpInfo *ji = NULL;
        int buf_len;
@@ -223,6 +223,9 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
        mono_add_unwind_op_def_cfa (unwind_ops, code, buf, ARMREG_SP, cfa_offset);
        // PC saved at sp+LR_OFFSET
        mono_add_unwind_op_offset (unwind_ops, code, buf, ARMREG_LR, -4);
+       /* Callee saved regs */
+       for (i = 0; i < 8; ++i)
+               mono_add_unwind_op_offset (unwind_ops, code, buf, ARMREG_R4 + i, -regsave_size + ((4 + i) * 4));
 
        if (aot) {
                /* 
@@ -231,6 +234,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
                 * preceeding the got slot where the value is stored. The offset can be
                 * found at [lr + 0].
                 */
+               /* See if emit_trampolines () in aot-compiler.c for the '2' */
                if (aot == 2) {
                        ARM_MOV_REG_REG (code, ARMREG_V2, ARMREG_R1);
                } else {
@@ -243,6 +247,18 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
        }
        ARM_LDR_IMM (code, ARMREG_V3, ARMREG_SP, lr_offset);
 
+       /* we build the MonoLMF structure on the stack - see mini-arm.h
+        * The pointer to the struct is put in r1.
+        * the iregs array is already allocated on the stack by push.
+        */
+       code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - regsave_size);
+       ARM_SUB_REG_REG (code, ARMREG_SP, ARMREG_SP, ARMREG_R2);
+       cfa_offset += STACK - regsave_size;
+       mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
+       /* V1 == lmf */
+       code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - sizeof (MonoLMF));
+       ARM_ADD_REG_REG (code, ARMREG_V1, ARMREG_SP, ARMREG_R2);
+
        /* ok, now we can continue with the MonoLMF setup, mostly untouched 
         * from emit_prolog in mini-arm.c
         * This is a synthetized call to mono_get_lmf_addr ()
@@ -266,18 +282,6 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
        ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
        code = emit_bx (code, ARMREG_R0);
 
-       /* we build the MonoLMF structure on the stack - see mini-arm.h
-        * The pointer to the struct is put in r1.
-        * the iregs array is already allocated on the stack by push.
-        */
-       code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - regsave_size);
-       ARM_SUB_REG_REG (code, ARMREG_SP, ARMREG_SP, ARMREG_R2);
-       cfa_offset += STACK - regsave_size;
-       mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
-       /* V1 == lmf */
-       code = mono_arm_emit_load_imm (code, ARMREG_R2, STACK - sizeof (MonoLMF));
-       ARM_ADD_REG_REG (code, ARMREG_V1, ARMREG_SP, ARMREG_R2);
-
        /*
         * The stack now looks like:
         *       <saved regs>
@@ -376,7 +380,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
         * Have to call the _force_ variant, since there could be a protected wrapper on the top of the stack.
         */
        if (aot) {
-               ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_thread_force_interruption_checkpoint");
+               ji = mono_patch_info_list_prepend (ji, code - buf, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_interruption_checkpoint_from_trampoline");
                ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
                ARM_B (code, 0);
                *(gpointer*)code = NULL;
@@ -386,11 +390,11 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
 #ifdef USE_JUMP_TABLES
                gpointer *jte = mono_jumptable_add_entry ();
                code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
-               jte [0] = mono_thread_force_interruption_checkpoint;
+               jte [0] = mono_interruption_checkpoint_from_trampoline;
 #else
                ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
                ARM_B (code, 0);
-               *(gpointer*)code = mono_thread_force_interruption_checkpoint;
+               *(gpointer*)code = mono_interruption_checkpoint_from_trampoline;
                code += 4;
 #endif
        }