Author: zoltan
Date: 2007-12-08 08:56:01 -0500 (Sat, 08 Dec 2007)
New Revision: 90990

Modified:
   trunk/mono/mono/mini/ChangeLog
   trunk/mono/mono/mini/tramp-amd64.c
Log:
2007-12-08  Zoltan Varga  <[EMAIL PROTECTED]>

        * tramp-amd64.c (mono_arch_create_trampoline_code): Clean up the code a 
bit.


Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog      2007-12-08 09:18:36 UTC (rev 90989)
+++ trunk/mono/mono/mini/ChangeLog      2007-12-08 13:56:01 UTC (rev 90990)
@@ -1,3 +1,7 @@
+2007-12-08  Zoltan Varga  <[EMAIL PROTECTED]>
+
+       * tramp-amd64.c (mono_arch_create_trampoline_code): Clean up the code a 
bit.
+
 2007-12-07  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * mini-amd64.c (peephole_pass): Add a missing instruction check.

Modified: trunk/mono/mono/mini/tramp-amd64.c
===================================================================
--- trunk/mono/mono/mini/tramp-amd64.c  2007-12-08 09:18:36 UTC (rev 90989)
+++ trunk/mono/mono/mini/tramp-amd64.c  2007-12-08 13:56:01 UTC (rev 90990)
@@ -175,7 +175,7 @@
 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
 {
        guint8 *buf, *code, *tramp, *br [2];
-       int i, lmf_offset, offset, method_offset, tramp_offset, 
saved_regs_offset, saved_fpregs_offset, framesize;
+       int i, lmf_offset, offset, arg_offset, tramp_offset, saved_regs_offset, 
saved_fpregs_offset, framesize;
        gboolean has_caller;
 
        if (tramp_type == MONO_TRAMPOLINE_JUMP)
@@ -190,6 +190,10 @@
 
        offset = 0;
 
+       /*
+        * The generic class init trampoline is called directly by JITted code, 
there is no
+        * specific trampoline.
+        */
        if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
                /* Pop the return address off the stack */
                amd64_pop_reg (code, AMD64_R11);
@@ -206,12 +210,16 @@
        tramp_offset = - offset;
 
        offset += 8;
-       method_offset = - offset;
+       arg_offset = - offset;
 
-       /* Compute the trampoline address from the return address */
-       /* 5 = length of amd64_call_membase () */
-       amd64_alu_reg_imm (code, X86_SUB, AMD64_R11, 5);
-       amd64_mov_membase_reg (code, AMD64_RBP, tramp_offset, AMD64_R11, 8);
+       if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
+               /* Compute the trampoline address from the return address */
+               /* 5 = length of amd64_call_membase () */
+               amd64_alu_reg_imm (code, X86_SUB, AMD64_R11, 5);
+               amd64_mov_membase_reg (code, AMD64_RBP, tramp_offset, 
AMD64_R11, 8);
+       } else {
+               amd64_mov_membase_imm (code, AMD64_RBP, tramp_offset, 0, 8);
+       }
 
        /* Save all registers */
 
@@ -240,9 +248,9 @@
                mono_amd64_patch (br [0], code);
                amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 8);
                mono_amd64_patch (br [1], code);
-               amd64_mov_membase_reg (code, AMD64_RBP, method_offset, 
AMD64_R11, 8);
+               amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, AMD64_R11, 
8);
        } else {
-               amd64_mov_membase_reg (code, AMD64_RBP, method_offset, 
MONO_ARCH_VTABLE_REG, 8);
+               amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, 
MONO_ARCH_VTABLE_REG, 8);
        }
 
        /* Save LMF begin */
@@ -264,8 +272,12 @@
        amd64_alu_reg_imm (code, X86_ADD, AMD64_R11, framesize + 16);
        amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET 
(MonoLMF, rsp), AMD64_R11, 8);
        /* Save method */
-       amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, method_offset, 8);
-       amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET 
(MonoLMF, method), AMD64_R11, 8);
+       if (tramp_type == MONO_TRAMPOLINE_GENERIC || tramp_type == 
MONO_TRAMPOLINE_JUMP) {
+               amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, arg_offset, 
8);
+               amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + 
G_STRUCT_OFFSET (MonoLMF, method), AMD64_R11, 8);
+       } else {
+               amd64_mov_membase_imm (code, AMD64_RBP, lmf_offset + 
G_STRUCT_OFFSET (MonoLMF, method), 0, 8);
+       }
        /* Save callee saved regs */
 #ifdef PLATFORM_WIN32
        amd64_mov_membase_reg (code, AMD64_RBP, lmf_offset + G_STRUCT_OFFSET 
(MonoLMF, rdi), AMD64_RDI, 8);
@@ -301,15 +313,12 @@
                amd64_mov_reg_imm (code, AMD64_ARG_REG2, 0);
 
        /* Arg3 is the method/vtable ptr */
-       amd64_mov_reg_membase (code, AMD64_ARG_REG3, AMD64_RBP, method_offset, 
8);
+       amd64_mov_reg_membase (code, AMD64_ARG_REG3, AMD64_RBP, arg_offset, 8);
 
        /* Arg4 is the trampoline address */
-       if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
-               amd64_mov_reg_imm (code, AMD64_ARG_REG4, 0);
-       else
-               amd64_mov_reg_membase (code, AMD64_ARG_REG4, AMD64_RBP, 
tramp_offset, 8);
+       amd64_mov_reg_membase (code, AMD64_ARG_REG4, AMD64_RBP, tramp_offset, 
8);
 
-       tramp = mono_get_trampoline_func (tramp_type);
+       tramp = (guint8*)mono_get_trampoline_func (tramp_type);
        amd64_mov_reg_imm (code, AMD64_RAX, tramp);
        amd64_call_reg (code, AMD64_RAX);
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to