x86-64 needs more logic to handle native_call() and vm_native_call(). Therefore we turn these two macros into functions to cater for other arches' needs.
Signed-off-by: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro> --- arch/x86/Makefile_32 | 1 + arch/x86/Makefile_64 | 1 + arch/x86/call.c | 129 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/include/arch/call.h | 68 ---------------------- include/vm/call.h | 7 ++ vm/call.c | 6 +- 6 files changed, 140 insertions(+), 72 deletions(-) create mode 100644 arch/x86/call.c delete mode 100644 arch/x86/include/arch/call.h diff --git a/arch/x86/Makefile_32 b/arch/x86/Makefile_32 index 58bd024..8a76208 100644 --- a/arch/x86/Makefile_32 +++ b/arch/x86/Makefile_32 @@ -1,6 +1,7 @@ ARCH_OBJS = \ arch/x86/args.o \ arch/x86/backtrace.o \ + arch/x86/call.o \ arch/x86/disassemble.o \ arch/x86/emit-code.o \ arch/x86/exception.o \ diff --git a/arch/x86/Makefile_64 b/arch/x86/Makefile_64 index 30b4e0c..34052d2 100644 --- a/arch/x86/Makefile_64 +++ b/arch/x86/Makefile_64 @@ -4,6 +4,7 @@ ARCH_LIBS = -L/usr/lib64/libffi -lffi ARCH_OBJS = \ arch/x86/args.o \ arch/x86/backtrace.o \ + arch/x86/call.o \ arch/x86/disassemble.o \ arch/x86/emit-code.o \ arch/x86/exception.o \ diff --git a/arch/x86/call.c b/arch/x86/call.c new file mode 100644 index 0000000..cef3bdf --- /dev/null +++ b/arch/x86/call.c @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2009 Tomek Grabiec <tgrab...@gmail.com> + * Copyright (C) 2009 Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro> + * + * This file is released under the GPL version 2 with the following + * clarification and special exception: + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. An + * independent module is a module which is not derived from or based on + * this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + * + * Please refer to the file LICENSE for details. + */ + +#include <stdlib.h> + +#include "vm/call.h" +#include "vm/method.h" + +#ifdef CONFIG_X86_32 + +/** + * This calls a function with call arguments copied from @args + * array. The array contains @args_count elements of machine word + * size. The @target must be a variable holding a function + * pointer. Call result will be stored in @result. + */ +unsigned long native_call(struct vm_method *method, + const void *target, + unsigned long *args) +{ + unsigned long result; + + __asm__ volatile ( + "movl %%ebx, %%ecx \n" + "shl $2, %%ebx \n" + "subl %%ebx, %%esp \n" + "movl %%esp, %%edi \n" + "cld \n" + "rep movsd \n" + "movl %%ebx, %%esi \n" + "call *%3 \n" + "addl %%esi, %%esp \n" + : "=a" (result) + : "b" (method->args_count), "S"(args), "m"(target) + : "%ecx", "%edi", "cc" + ); + + return result; +} + +/** + * This calls a VM native function with call arguments copied from + * @args array. The array contains @args_count elements of machine + * word size. The @target must be a pointer to a VM function. Call + * result will be stored in @result. + */ +unsigned long vm_native_call(struct vm_method *method, + const void *target, + unsigned long *args) + unsigned long result; + + __asm__ volatile ( + "movl %%ebx, %%ecx \n" + "shl $2, %%ebx \n" + "subl %%ebx, %%esp \n" + "movl %%esp, %%edi \n" + "cld \n" + "rep movsd \n" + "movl %%ebx, %%esi \n" + + "pushl %%esp \n" + "pushl %3 \n" + "call vm_enter_vm_native \n" + "addl $8, %%esp \n" + "test %%eax, %%eax \n" + "jnz 1f \n" + + "call * -8(%%esp)\n" + "movl %%eax, %0 \n" + + "call vm_leave_vm_native \n" + + "1: addl %%esi, %%esp \n" + : "=r" (result) + : "b" (method->args_count), "S"(args), "r"(target) + : "%ecx", "%edi", "cc" + ); + + return result; +} + +#else /* CONFIG_X86_32 */ + +unsigned long native_call(struct vm_method *method, + const void *target, + unsigned long *args) +{ + abort(); + + return 0; +} + +unsigned long vm_native_call(struct vm_method *method, + const void *target, + unsigned long *args) +{ + abort(); + + return 0; +} + +#warning NOT IMPLEMENTED + +#endif /* CONFIG_X86_32 */ + diff --git a/arch/x86/include/arch/call.h b/arch/x86/include/arch/call.h deleted file mode 100644 index dd77ddc..0000000 --- a/arch/x86/include/arch/call.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef __X86_CALL_H -#define __X86_CALL_H - -#ifdef CONFIG_X86_32 -/** - * This calls a function with call arguments copied from @args - * array. The array contains @args_count elements of machine word - * size. The @target must be a variable holding a function - * pointer. Call result will be stored in @result. - */ -#define native_call(target, args, args_count, result) { \ - __asm__ volatile ( \ - "movl %%ebx, %%ecx \n" \ - "shl $2, %%ebx \n" \ - "subl %%ebx, %%esp \n" \ - "movl %%esp, %%edi \n" \ - "cld \n" \ - "rep movsd \n" \ - "movl %%ebx, %%esi \n" \ - "call *%3 \n" \ - "addl %%esi, %%esp \n" \ - : "=a" (result) \ - : "b" (args_count), "S"(args), "m"(target) \ - : "%ecx", "%edi", "cc" \ - ); \ - } - -/** - * This calls a VM native function with call arguments copied from - * @args array. The array contains @args_count elements of machine - * word size. The @target must be a pointer to a VM function. Call - * result will be stored in @result. - */ -#define vm_native_call(target, args, args_count, result) { \ - __asm__ volatile ( \ - "movl %%ebx, %%ecx \n" \ - "shl $2, %%ebx \n" \ - "subl %%ebx, %%esp \n" \ - "movl %%esp, %%edi \n" \ - "cld \n" \ - "rep movsd \n" \ - "movl %%ebx, %%esi \n" \ - \ - "pushl %%esp \n" \ - "pushl %3 \n" \ - "call vm_enter_vm_native \n" \ - "addl $8, %%esp \n" \ - "test %%eax, %%eax \n" \ - "jnz 1f \n" \ - \ - "call * -8(%%esp)\n" \ - "movl %%eax, %0 \n" \ - \ - "call vm_leave_vm_native \n" \ - \ - "1: addl %%esi, %%esp \n" \ - : "=r" (result) \ - : "b" (args_count), "S"(args), "r"(target) \ - : "%ecx", "%edi", "cc" \ - ); \ - } -#else -#define native_call(target, args, args_count, result) abort(); -#define vm_native_call(target, args, args_count, result) abort(); -#warning NOT IMPLEMENTED -#endif - -#endif /* __X86_CALL_H */ diff --git a/include/vm/call.h b/include/vm/call.h index d0238ba..872579b 100644 --- a/include/vm/call.h +++ b/include/vm/call.h @@ -50,4 +50,11 @@ DECLARE_VM_CALL_METHOD(short); DECLARE_VM_CALL_METHOD(object); DECLARE_VM_CALL_METHOD(int); +extern unsigned long native_call(struct vm_method *method, + const void *target, + unsigned long *args); +extern unsigned long vm_native_call(struct vm_method *method, + const void *target, + unsigned long *args); + #endif diff --git a/vm/call.c b/vm/call.c index 419e13d..eaf2b4f 100644 --- a/vm/call.c +++ b/vm/call.c @@ -28,8 +28,6 @@ #include <stdarg.h> #include <stdio.h> -#include "arch/call.h" - #include "jit/exception.h" #include "vm/call.h" @@ -54,11 +52,11 @@ call_method_a(struct vm_method *method, void *target, unsigned long *args) clear_exception(); if (vm_method_is_vm_native(method)) { - vm_native_call(target, args, method->args_count, result); + result = vm_native_call(method, target, args); goto out; } - native_call(target, args, method->args_count, result); + result = native_call(method, target, args); out: if (!exception_occurred() && exception) -- 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