This implements native_call() on x86-64. Unlike on x86-32, it also needs
to handle register arguments.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro>
---
 arch/x86/call.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/arch/x86/call.c b/arch/x86/call.c
index cef3bdf..f70c8a2 100644
--- a/arch/x86/call.c
+++ b/arch/x86/call.c
@@ -27,6 +27,10 @@
 
 #include <stdlib.h>
 
+#include "arch/registers.h"
+
+#include "jit/args.h"
+
 #include "vm/call.h"
 #include "vm/method.h"
 
@@ -109,7 +113,46 @@ unsigned long native_call(struct vm_method *method,
                          const void *target,
                          unsigned long *args)
 {
-       abort();
+       int i, sp = 0, r = 0;
+       unsigned long *stack, regs[6];
+       unsigned long result;
+
+       stack = malloc(sizeof(unsigned long) * method->args_count);
+       if (!stack)
+               abort();
+
+       for (i = 0; i < method->args_count; i++)
+               if (method->args_map[i].reg == MACH_REG_UNASSIGNED)
+                       stack[sp++] = args[i];
+               else
+                       regs[r++] = args[i];
+
+       __asm__ volatile (
+               /* Copy stack arguments onto the stack. */
+               "movq %%rbx, %%rcx \n"
+               "shl $3, %%rbx \n"
+               "subq %%rbx, %%rsp \n"
+               "movq %%rsp, %%rdi \n"
+               "cld \n"
+               "rep movsq \n"
+
+               /* Assign registers to register arguments. */
+               "movq 0x00(%%rax), %%rdi \n"
+               "movq 0x08(%%rax), %%rsi \n"
+               "movq 0x10(%%rax), %%rdx \n"
+               "movq 0x18(%%rax), %%rcx \n"
+               "movq 0x20(%%rax), %%r8 \n"
+               "movq 0x28(%%rax), %%r9 \n"
+
+               "call *%3 \n"   
+               "addq %%rbx, %%rsp \n"
+               : "=a" (result)
+               : "b" (get_stack_args_count(method)), "S" (stack),
+                 "m" (target), "a" (regs)
+               : "%rcx", "%rdi", "%r8", "%r9", "cc"
+       );
+
+       free(stack);
 
        return 0;
 }
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to