CacaoJVM on OS X/Intel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I posted this patch to the Cacao mailing list, too, but I can't tell if that's a black hole for me (I couldn't even subscribe...). So, attached is a patch that makes Cacao work on OS X/Intel. There are still some bugs (I can't run the full mauve test suite with cacao running the harness, but, with jamvm running the harness, and cacao the test VM, I get 888 fails, and a lot of these are because I have no AWT peers enabled) but it does seem to work.

Thanks.

Index: src/vm/jit/i386/darwin/md-os.c
===================================================================
--- src/vm/jit/i386/darwin/md-os.c	(revision 0)
+++ src/vm/jit/i386/darwin/md-os.c	(revision 0)
@@ -0,0 +1,140 @@
+/* src/vm/jit/i386/darwin/md-os.c - machine dependent i386 Darwin functions
+
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien, C. Marshall
+
+   This file is part of CACAO.
+
+   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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Contact: cacao@xxxxxxxxxxxx
+
+   Authors: Christian Thalinger
+
+   Changes:
+
+   $Id$
+
+   Based on ../freebsd/md-os.c and ../../powerpc/darwin/md-os.c;
+   modified for Darwin/x86 by Casey Marshall.
+*/
+
+
+#include "config.h"
+
+#include <ucontext.h>
+
+#include "vm/jit/i386/md-abi.h"
+
+#include "vm/exceptions.h"
+#include "vm/signallocal.h"
+#include "vm/jit/asmpart.h"
+#include "vm/jit/stacktrace.h"
+
+
+/* md_signal_handler_sigsegv ***************************************************
+
+   NullPointerException signal handler for hardware null pointer
+   check.
+
+*******************************************************************************/
+
+void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
+{
+	ucontext_t *_uc;
+	mcontext_t  _mc;
+	i386_thread_state_t *_ss;
+	u1         *sp;
+	u1         *ra;
+	u1         *xpc;
+
+	_uc = (ucontext_t *) _p;
+	_mc = _uc->uc_mcontext;
+	_ss = &_mc->ss;
+	
+	sp  = (u1 *) _ss->esp;
+	xpc = (u1 *) _ss->eip;
+	ra  = xpc;                          /* return address is equal to xpc     */
+
+	_ss->eax =
+		(ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
+	
+	_ss->ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
+	_ss->eip = (ptrint) asm_handle_exception;
+}
+
+
+/* md_signal_handler_sigfpe ****************************************************
+
+   ArithmeticException signal handler for hardware divide by zero
+   check.
+
+*******************************************************************************/
+
+void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
+{
+	ucontext_t *_uc;
+	mcontext_t  _mc;
+	i386_thread_state_t *_ss;
+	u1         *sp;
+	u1         *ra;
+	u1         *xpc;
+
+	_uc = (ucontext_t *) _p;
+	_mc = _uc->uc_mcontext;
+	_ss = &_mc->ss;
+
+	sp  = (u1 *) _ss->esp;
+	xpc = (u1 *) _ss->eip;
+	ra  = xpc;                          /* return address is equal to xpc     */
+
+	_ss->eax =
+		(ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
+	
+	_ss->ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
+	_ss->eip = (ptrint) asm_handle_exception;
+}
+
+
+#if defined(ENABLE_THREADS)
+void thread_restartcriticalsection(ucontext_t *uc)
+{
+	void *critical;
+	mcontext_t _mc = uc->uc_mcontext;
+	i386_thread_state_t *_ss = &_mc->ss;
+
+	critical = critical_find_restart_point((void *) _ss->eip);
+
+	if (critical)
+		_ss->eip = (ptrint) critical;
+}
+#endif
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
Index: src/vm/jit/i386/darwin/Makefile.am
===================================================================
--- src/vm/jit/i386/darwin/Makefile.am	(revision 0)
+++ src/vm/jit/i386/darwin/Makefile.am	(revision 0)
@@ -0,0 +1,53 @@
+## src/vm/jit/i386/darwin/Makefile.am
+##
+## Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+## C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+## E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+## J. Wenninger, Institut f. Computersprachen - TU Wien, C. Marshall
+##
+## This file is part of CACAO.
+##
+## 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+##
+## Contact: cacao@xxxxxxxxxxxx
+##
+## Authors: Christian Thalinger
+##
+## Changes:
+##
+## $Id$
+
+## Process this file with automake to produce Makefile.in
+
+AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/vm/jit/$(ARCH_DIR)
+
+LIBS =
+
+noinst_HEADERS =
+
+noinst_LTLIBRARIES = libmd.la
+
+libmd_la_SOURCES = \
+	md-os.c
+
+
+## Local variables:
+## mode: Makefile
+## indent-tabs-mode: t
+## c-basic-offset: 4
+## tab-width: 8
+## compile-command: "automake --add-missing"
+## End:
Index: src/vm/jit/i386/codegen.c
===================================================================
--- src/vm/jit/i386/codegen.c	(revision 5126)
+++ src/vm/jit/i386/codegen.c	(working copy)
@@ -4422,6 +4422,10 @@
 		1 +                             /* function pointer                   */
 		4 * 4 +                         /* 4 arguments (start_native_call)    */
 		nmd->memuse;
+	stackframesize |= 0x3;		        /* Keep aligned to 16-bytes. We can't
+										   tell if the function we are calling
+										   is a leaf function or not, so just
+										   align all of them. */
 
 	/* create method header */
 
Index: src/vm/jit/i386/asmpart.S
===================================================================
--- src/vm/jit/i386/asmpart.S	(revision 5126)
+++ src/vm/jit/i386/asmpart.S	(working copy)
@@ -52,6 +52,7 @@
 
 /* export functions ***********************************************************/
 
+#if !defined(__DARWIN__)
 	.globl asm_md_init
 
 	.globl asm_vm_call_method
@@ -81,8 +82,48 @@
 	.globl asm_getclassvalues_atomic
 
 	.globl asm_get_cycle_count
+#else
+	.globl _asm_md_init
 
+	.globl _asm_vm_call_method
+	.globl _asm_vm_call_method_int
+	.globl _asm_vm_call_method_long
+	.globl _asm_vm_call_method_float
+	.globl _asm_vm_call_method_double
+	.globl _asm_vm_call_method_exception_handler
 
+	.globl _asm_call_jit_compiler
+	.globl _asm_handle_nat_exception
+	.globl _asm_handle_exception
+
+	.globl _asm_abstractmethoderror
+
+	.globl _asm_wrapper_patcher
+
+	.globl _asm_replacement_out
+	.globl _asm_replacement_in
+
+	.globl _asm_builtin_f2i
+	.globl _asm_builtin_f2l
+	.globl _asm_builtin_d2i
+	.globl _asm_builtin_d2l
+
+	.globl _asm_criticalsections
+	.globl _asm_getclassvalues_atomic
+
+	.globl _asm_get_cycle_count
+#endif
+
+/*
+ * On Darwin, exported symbols need to have _ prepended to them.
+ */
+#if !defined(__DARWIN__)
+#define EXTERNAL_SYMBOL(s) s
+#else
+#define EXTERNAL_SYMBOL(s) _##s
+#endif
+
+
 /* asm_md_init *****************************************************************
 
    Initialize machine dependent stuff.
@@ -98,7 +139,7 @@
 
 *******************************************************************************/
 
-asm_md_init:
+EXTERNAL_SYMBOL(asm_md_init):
 	sub     $4,sp                       /* allocate space for the FPU state   */
 	fnstcw  (sp)                        /* get the FPU state                  */
 	mov     (sp),%eax
@@ -140,11 +181,11 @@
 	.long   0                           /* frame size                         */
 	.long   0                           /* codeinfo pointer                   */
 
-asm_vm_call_method:
-asm_vm_call_method_int:
-asm_vm_call_method_long:
-asm_vm_call_method_float:
-asm_vm_call_method_double:
+EXTERNAL_SYMBOL(asm_vm_call_method):
+EXTERNAL_SYMBOL(asm_vm_call_method_int):
+EXTERNAL_SYMBOL(asm_vm_call_method_long):
+EXTERNAL_SYMBOL(asm_vm_call_method_float):
+EXTERNAL_SYMBOL(asm_vm_call_method_double):
 	push    bp
 	mov     sp,bp                       /* save stackptr                      */
 	sub     $(4*4),sp                   /* create stackframe                  */
@@ -177,8 +218,11 @@
 	sub     $1,itmp3
 	test	itmp3,itmp3                 /* any args left?                     */
 	jz      calljava_setstack
-
+#if !defined(__DARWIN__)
 	add     $sizevmarg,itmp1            /* goto next argument block           */
+#else
+	add		$16,itmp1					/* XXX hack */ 
+#endif
 	jmp     calljava_calcstacksize
 		
 calljava_setstack:				
@@ -204,7 +248,11 @@
 	test    itmp2,itmp2
 	jle     L_asm_vm_call_method_copy_done
 
+#if !defined(__DARWIN__)
 	add     $sizevmarg,itmp1            /* goto next argument block           */
+#else
+	add		$16,itmp1					/* XXX hack */
+#endif
 	jmp     calljava_copyloop
 
 L_asm_vm_call_method_copy_done:
@@ -229,7 +277,7 @@
 	leave
 	ret
 
-asm_vm_call_method_exception_handler:
+EXTERNAL_SYMBOL(asm_vm_call_method_exception_handler):
 	push    xptr                        /* pass exception pointer             */
 	call    builtin_throw_exception
 	add     $4,sp
@@ -263,7 +311,7 @@
 
 *******************************************************************************/
 
-asm_call_jit_compiler:
+EXTERNAL_SYMBOL(asm_call_jit_compiler):
 L_asm_call_jit_compiler:                /* required for PIC code              */
 	sub     $(4*4),sp                   /* create stack frame                 */
 
@@ -301,10 +349,10 @@
 *                                                                              *
 *******************************************************************************/
 
-asm_handle_nat_exception:
+EXTERNAL_SYMBOL(asm_handle_nat_exception):
 	add     $4,sp                       /* clear return address of native stub*/
 		
-asm_handle_exception:
+EXTERNAL_SYMBOL(asm_handle_exception):
 L_asm_handle_exception:                 /* required for PIC code              */
 	sub     $((ARG_CNT+TMP_CNT)*4),sp   /* create maybe-leaf stackframe       */
 
@@ -436,7 +484,7 @@
 
 *******************************************************************************/
 
-asm_abstractmethoderror:
+EXTERNAL_SYMBOL(asm_abstractmethoderror):
 	sub     $(2*4),sp                   /* create stack frame                 */
 	mov     sp,itmp1                    /* pass java sp                       */
 	add     $((1+2)*4),itmp1
@@ -468,7 +516,7 @@
 
 *******************************************************************************/
 
-asm_wrapper_patcher:
+EXTERNAL_SYMBOL(asm_wrapper_patcher):
 	sub     $((2+4)*4),sp               /* create stack frame                 */
 
 	mov     itmp1,(0+4)*4(sp)           /* save itmp1 and itmp2               */
@@ -518,7 +566,7 @@
 	/* XXX we should find a cleaner solution here */
 #define REPLACEMENT_ROOM  512
 
-asm_replacement_out:
+EXTERNAL_SYMBOL(asm_replacement_out):
     /* create stack frame */
 	sub     $(sizeexecutionstate + REPLACEMENT_ROOM),sp
 
@@ -571,7 +619,7 @@
 
 *******************************************************************************/
 
-asm_replacement_in:
+EXTERNAL_SYMBOL(asm_replacement_in):
 	mov     4(sp),%ebp                  /* executionstate *es                 */
 
 	/* set new sp */
@@ -599,28 +647,28 @@
 *                                                                              *
 *******************************************************************************/
 
-asm_builtin_f2i:
+EXTERNAL_SYMBOL(asm_builtin_f2i):
 	sub     $4,%esp
 	fsts    (%esp)
 	call    builtin_f2i
 	add     $4,%esp
 	ret
 
-asm_builtin_d2i:
+EXTERNAL_SYMBOL(asm_builtin_d2i):
 	sub     $8,%esp
 	fstl    (%esp)
 	call    builtin_d2i
 	add     $8,%esp
 	ret
 
-asm_builtin_f2l:
+EXTERNAL_SYMBOL(asm_builtin_f2l):
 	sub     $4,%esp
 	fsts    (%esp)
 	call    builtin_f2l
 	add     $4,%esp
 	ret
 
-asm_builtin_d2l:
+EXTERNAL_SYMBOL(asm_builtin_d2l):
 	sub     $8,%esp
 	fstl    (%esp)
 	call    builtin_d2l
@@ -628,7 +676,7 @@
 	ret
 
 
-asm_getclassvalues_atomic:
+EXTERNAL_SYMBOL(asm_getclassvalues_atomic):
 _crit_restart2:
 	mov     4(%esp),%ecx        /* super */
 	mov     8(%esp),%edx        /* sub */
@@ -647,7 +695,7 @@
 
 	.data
 
-asm_criticalsections:
+EXTERNAL_SYMBOL(asm_criticalsections):
 #if defined(ENABLE_THREADS)
 #if 0
 	.long   _crit_begin1
@@ -674,11 +722,71 @@
 
 *******************************************************************************/
 
-asm_get_cycle_count:
+EXTERNAL_SYMBOL(asm_get_cycle_count):
 	rdtsc
 	ret
 
+/* Symbol stubs for darwin. */
+#if defined(__DARWIN__)
+	.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
 
+builtin_d2l:
+	.indirect_symbol _builtin_d2l
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+builtin_f2l:
+	.indirect_symbol _builtin_f2l
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+builtin_d2i:
+	.indirect_symbol _builtin_d2i
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+builtin_f2i:
+	.indirect_symbol _builtin_f2i
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+abort:
+	.indirect_symbol _abort
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+replace_me:
+	.indirect_symbol _replace_me
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+exceptions_handle_exception:
+	.indirect_symbol _exceptions_handle_exception
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+codegen_findmethod:
+	.indirect_symbol _codegen_findmethod
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+builtin_throw_exception:
+	.indirect_symbol _builtin_throw_exception
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+
+patcher_wrapper:
+	.indirect_symbol _patcher_wrapper
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+exceptions_asm_new_abstractmethoderror:
+	.indirect_symbol _exceptions_asm_new_abstractmethoderror
+	hlt ; hlt ; hlt ; hlt ; hlt
+		
+exceptions_get_and_clear_exception:
+	.indirect_symbol _exceptions_get_and_clear_exception
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+jit_asm_compile:
+	.indirect_symbol _jit_asm_compile
+	hlt ; hlt ; hlt ; hlt ; hlt
+
+	.subsections_via_symbols
+
+#endif
+
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
Index: src/vm/jit/i386/Makefile.am
===================================================================
--- src/vm/jit/i386/Makefile.am	(revision 5126)
+++ src/vm/jit/i386/Makefile.am	(working copy)
@@ -33,6 +33,7 @@
 ## Process this file with automake to produce Makefile.in
 
 DIST_SUBDIRS = \
+	darwin \
 	freebsd \
 	linux
 
Index: src/threads/native/threads.c
===================================================================
--- src/threads/native/threads.c	(revision 5126)
+++ src/threads/native/threads.c	(working copy)
@@ -494,9 +494,15 @@
 	do {
 		if (tobj != self)
 		{
+#if defined(__i386__)
+			thread_state_flavor_t flavor = i386_THREAD_STATE;
+			mach_msg_type_number_t thread_state_count = i386_THREAD_STATE_COUNT;
+			i386_thread_state_t thread_state;
+#else
 			thread_state_flavor_t flavor = PPC_THREAD_STATE;
 			mach_msg_type_number_t thread_state_count = PPC_THREAD_STATE_COUNT;
 			ppc_thread_state_t thread_state;
+#endif
 			mach_port_t thread = tobj->mach_thread;
 			kern_return_t r;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5126)
+++ ChangeLog	(working copy)
@@ -1,3 +1,18 @@
+2006-07-20  Casey Marshall  <csm@xxxxxxx>
+
+	* configure.ac (AC_CONFIG_FILES): add
+	`vm/jit/i386/darwin/Makefile'.
+	* src/threads/native/threads.c (threads_cast_darwinstop): add i386
+	declarations.
+	* src/vm/jit/i386/codegen.c (createnativestub): align the stack.
+	* src/vm/jit/i386/asmpart.S: export symbols with `_' on Darwin.
+	(EXTERNAL_SYMBOL): new macro; wrap all exported symbols with
+	`EXTERNAL_SYMBOL'.
+	Add indirect symbol stubs for externally-called functions.
+	* src/vm/jit/i386/Makefile.am (SUBDIRS): add `darwin'.
+	* src/vm/jit/i386/darwin/Makefile.am: new file
+	* src/vm/jit/i386/darwin/md-os.c: new file.
+
 2006-05-29 18:52  twisti
 
 	* configure.ac (AC_INIT): Changed to version 0.96.
Index: configure.ac
===================================================================
--- configure.ac	(revision 5126)
+++ configure.ac	(working copy)
@@ -822,6 +822,7 @@
 		[src/vm/jit/alpha/freebsd/Makefile]
 		[src/vm/jit/alpha/linux/Makefile]
 		[src/vm/jit/i386/Makefile]
+		[src/vm/jit/i386/darwin/Makefile]
 		[src/vm/jit/i386/freebsd/Makefile]
 		[src/vm/jit/i386/linux/Makefile]
 		[src/vm/jit/ifconv/Makefile]

Attachment: PGP.sig
Description: This is a digitally signed message part


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux