[Jamvm-general] [PATCH] added darwin/x86_64 support
Brought to you by:
rlougher
From: Christopher F. <chr...@gm...> - 2013-10-11 11:19:02
|
--- configure.ac | 2 + src/os/darwin/Makefile.am | 2 +- src/os/darwin/x86_64/Makefile.am | 25 ++++ src/os/darwin/x86_64/callNative.S | 269 ++++++++++++++++++++++++++++++++++++++ src/os/darwin/x86_64/dll_md.c | 57 ++++++++ src/os/darwin/x86_64/init.c | 28 ++++ 6 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 src/os/darwin/x86_64/Makefile.am create mode 100644 src/os/darwin/x86_64/callNative.S create mode 100644 src/os/darwin/x86_64/dll_md.c create mode 100644 src/os/darwin/x86_64/init.c diff --git a/configure.ac b/configure.ac index d065142..5542bd3 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ i386-*-openbsd*) host_os=bsd libdl_needed=no ;; i386-*-freebsd*) host_os=bsd libdl_needed=no ;; i386-*-solaris*) host_cpu=x86 host_os=solaris ;; x86_64-*-linux*) host_os=linux ;; +x86_64-*-darwin*) host_os=darwin ;; hppa*-*-linux*) host_cpu=parisc host_os=linux ;; mips*-*-linux*) host_cpu=mips host_os=linux ;; x86_64-*-openbsd*) host_os=bsd libdl_needed=no ;; @@ -405,6 +406,7 @@ AC_CONFIG_FILES( src/os/linux/parisc/Makefile \ src/os/linux/mips/Makefile \ src/os/darwin/i386/Makefile \ + src/os/darwin/x86_64/Makefile \ src/os/darwin/arm/Makefile \ src/os/darwin/powerpc/Makefile \ src/os/bsd/powerpc/Makefile \ diff --git a/src/os/darwin/Makefile.am b/src/os/darwin/Makefile.am index 760c699..8cadf1d 100644 --- a/src/os/darwin/Makefile.am +++ b/src/os/darwin/Makefile.am @@ -20,7 +20,7 @@ ## SUBDIRS = @arch@ -DIST_SUBDIRS = powerpc i386 arm +DIST_SUBDIRS = powerpc i386 arm x86_64 noinst_LTLIBRARIES = libos.la libos_la_SOURCES = os.c diff --git a/src/os/darwin/x86_64/Makefile.am b/src/os/darwin/x86_64/Makefile.am new file mode 100644 index 0000000..0ddea9f --- /dev/null +++ b/src/os/darwin/x86_64/Makefile.am @@ -0,0 +1,25 @@ +## +## Copyright (C) 2003, 2004, 2005, 2006, 2007 +## Robert Lougher <ro...@ja...>. +## +## This file is part of JamVM. +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2, +## or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +## + +noinst_LTLIBRARIES = libnative.la +libnative_la_SOURCES = init.c dll_md.c callNative.S + +AM_CPPFLAGS = -I$(top_builddir)/src diff --git a/src/os/darwin/x86_64/callNative.S b/src/os/darwin/x86_64/callNative.S new file mode 100644 index 0000000..b2bde79 --- /dev/null +++ b/src/os/darwin/x86_64/callNative.S @@ -0,0 +1,269 @@ +/* + * Copyright (C) 2008, 2009 Robert Lougher <ro...@ja...>. + * + * This file is part of JamVM. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#ifndef USE_FFI +.text +.align 2 +.globl _callJNIMethod +//.type callJNIMethod,function + +/* + * Arguments passed in: + * + * %rdi JNIEnv + * %rsi class or NULL + * %rdx sig + * %rcx extra arg + * %r8 ostack + * %r9 function pntr + */ + +_callJNIMethod: + pushq %rbp + movq %rsp, %rbp + + pushq %r8 + pushq %r9 + pushq %rbx + pushq %r12 + pushq %r14 + pushq %r15 + + testq %rsi, %rsi + jne alloc_space + + movq (%r8), %rsi + addq $8, %r8 + +alloc_space: + subq %rcx, %rsp + +/* Setup argument registers: + * rdx, rcx, r8, r9 + * xmm0 - xmm7 + * + * local register usage: + * r10 = int reg count + * r11 = double handler + * r12 = float handler + * r14 = sig pntr + * r15 = stack pntr + * rbx = ostack pntr + */ + + leaq double_regs-10(%rip), %r11 + leaq float_regs-10(%rip), %r12 + leaq 1(%rdx), %r14 + movq %rsp, %r15 + xorq %r10, %r10 + movq %r8, %rbx + +next: + movzbq (%r14), %rax + incq %r14 + + cmpq $41, %rax /* ')' */ + je done + cmpq $68, %rax /* 'D' */ + je double + cmpq $70, %rax /* 'F' */ + je float + cmpq $74, %rax /* 'J' */ + je long + +skip_brackets: + cmpq $91, %rax /* '[' */ + jne check_ref + movzbq (%r14), %rax + incq %r14 + jmp skip_brackets + +check_ref: + cmpq $76, %rax /* 'L' */ + jne int + +skip_ref: + movzbq (%r14), %rax + incq %r14 + cmpq $59, %rax /* ';' */ + jne skip_ref + +int: + movq (%rbx), %rax + addq $8, %rbx + +check_regs: + incq %r10 + cmpq $2, %r10 + jg check_4 + + cmovneq %rax, %rdx + cmoveq %rax, %rcx + jmp next + +check_4: + cmpq $4, %r10 + jg stack_push + + cmovneq %rax, %r8 + cmoveq %rax, %r9 + jmp next + +stack_push: + movq %rax, (%r15) + addq $8, %r15 + jmp next + +long: + movq (%rbx), %rax + addq $16, %rbx + jmp check_regs + +double: + addq $10, %r11 + addq $10, %r12 + addq $16, %rbx + jmp *%r11 + +double_regs: + movsd -16(%rbx), %xmm0 + jmp next + movsd -16(%rbx), %xmm1 + jmp next + movsd -16(%rbx), %xmm2 + jmp next + movsd -16(%rbx), %xmm3 + jmp next + movsd -16(%rbx), %xmm4 + jmp next + movsd -16(%rbx), %xmm5 + jmp next + movsd -16(%rbx), %xmm6 + jmp next + movsd -16(%rbx), %xmm7 + jmp next + movq -16(%rbx), %rax + subq $10, %r11 + subq $10, %r12 + jmp stack_push + +float: + addq $10, %r11 + addq $10, %r12 + addq $8, %rbx + jmp *%r12 + +float_regs: + movss -8(%rbx), %xmm0 + jmp next + movss -8(%rbx), %xmm1 + jmp next + movss -8(%rbx), %xmm2 + jmp next + movss -8(%rbx), %xmm3 + jmp next + movss -8(%rbx), %xmm4 + jmp next + movss -8(%rbx), %xmm5 + jmp next + movss -8(%rbx), %xmm6 + jmp next + movss -8(%rbx), %xmm7 + jmp next + movl -8(%rbx), %eax + subq $10, %r11 + subq $10, %r12 + jmp stack_push + +done: + /* Arguments all setup -- + call the native method */ + + callq *-16(%rbp) + + /* Get back ostack for return value */ + movq -8(%rbp), %rcx + + /* Handle return type */ + + movzbq (%r14), %rbx + cmpq $86, %rbx /* 'V' */ + je return + cmpq $76, %rbx /* 'L' */ + je int_ret + cmpq $91, %rbx /* '[' */ + je int_ret + cmpq $73, %rbx /* 'I' */ + je int_ret + cmpq $68, %rbx /* 'D' */ + je double_ret + cmpq $70, %rbx /* 'F' */ + je float_ret + cmpq $74, %rbx /* 'J' */ + je long_ret + cmpq $67, %rbx /* 'C' */ + je char_ret + cmpq $83, %rbx /* 'S' */ + je short_ret + + /* remaining types Z and B */ + movsbq %al, %rax + +int_ret: + movq %rax, (%rcx) + addq $8, %rcx + +return: + movq -24(%rbp), %rbx + movq -32(%rbp), %r12 + movq -40(%rbp), %r14 + movq -48(%rbp), %r15 + + movq %rbp, %rsp + popq %rbp + + movq %rcx, %rax + retq + +char_ret: + movzwq %ax, %rax + jmp int_ret + +short_ret: + movswq %ax, %rax + jmp int_ret + +long_ret: + movq %rax, (%rcx) + addq $16, %rcx + jmp return + +double_ret: + movsd %xmm0, (%rcx) + addq $16, %rcx + jmp return + +float_ret: + movss %xmm0, (%rcx) + addq $8, %rcx + jmp return +#endif diff --git a/src/os/darwin/x86_64/dll_md.c b/src/os/darwin/x86_64/dll_md.c new file mode 100644 index 0000000..f5be3b3 --- /dev/null +++ b/src/os/darwin/x86_64/dll_md.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008, 2010 Robert Lougher <ro...@ja...>. + * + * This file is part of JamVM. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "jam.h" + +#ifndef USE_FFI +#include <stdio.h> + +int nativeExtraArg(MethodBlock *mb) { + char *sig = mb->type; + int stack_space; + int iargs = 0; + int fargs = 0; + + while(*++sig != ')') + switch(*sig) { + case 'D': + case 'F': + fargs++; + break; + + default: + iargs++; + + if(*sig == '[') + while(*++sig == '['); + if(*sig == 'L') + while(*++sig != ';'); + break; + } + + stack_space = ((iargs > 4 ? iargs - 4 : 0) + + (fargs > 8 ? fargs - 8 : 0)) << 3; + + /* Ensure the stack remains 16 byte aligned. As + callJNIMethod pushes an even number of registers + the extra space must also be even. */ + return (stack_space + 15) & ~15; +} +#endif diff --git a/src/os/darwin/x86_64/init.c b/src/os/darwin/x86_64/init.c new file mode 100644 index 0000000..4fed8fc --- /dev/null +++ b/src/os/darwin/x86_64/init.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2003, 2004, 2006, 2007 + * Robert Lougher <ro...@ja...>. + * + * This file is part of JamVM. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/* This is needed on Linux/i386. Find out if it's + needed on Darwin/i386, and how to set it. */ +void setDoublePrecision() { +} + +void initialisePlatform() { +} -- 1.8.3.2 |