m68k jit support
Kiyo Inaba
inaba at src.ricoh.co.jp
Mon Aug 17 12:36:27 PDT 1998
Hi,
Finally, I understand why old jit code does not work with kaffe 1.0b.
There is a macro SLOT2ARGOFFSET in 'jit.h' file, which defines the
offset to be 4 more in the case of static method...
Fixing this line makes kaffe to print "Hello World!" :-)
But still, I am considering how we can merge machine dependent
code between m68k/linux and m68k/netbsd or m68k/sunos. The big
difference between these two are as follows.
1. Assembler syntax
2. Function return sequence in float
I am not so sure how many persons are working on the port for
m68k (including a-ux, amigaos, or nextstep3), and I am very glad
if I can hear someone else is active for the port.
Anyway, I attached a patch for m68k/netbsd which includes
config/m68k/common.h
Merged version between linux and netbsd/sunos.
config/m68k/netbsd1/jit-md.h
Change a field name to reflect structual change in 1.0b.
config/m68k/netbsd1/jit.h
Add trampoline support, and reorder definitions.
config/m68k/netbsd1/md.h
Move sysdepCallMethod definition from here to 'common.h'.
config/m68k/sunos4/config.frag
Remove cross development command names.
config/m68k/sunos4/md.h
Move sysdepCallMethod definition from here to 'common.h'.
config/m68k/trampolines.c
New file to support trampoline, only for staticlib.
Kiyo
diff -cr config/m68k/common.h /tmp/config/m68k/common.h
*** config/m68k/common.h Thu May 28 04:47:14 1998
--- /tmp/config/m68k/common.h Tue Aug 18 04:08:18 1998
***************
*** 2,17 ****
* m68k/common.h
* Common M68K configuration information.
*
! * Copyright (c) 1996, 1997
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
* of this file.
*/
#ifndef __m68k_common_h
#define __m68k_common_h
#define sysdepCallMethod(CALL) \
asm volatile (" \n\
1: \n\
--- 2,29 ----
* m68k/common.h
* Common M68K configuration information.
*
! * Copyright (c) 1996, 1997, 1998
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
* of this file.
+ *
+ * Written by Kiyo Inaba <inaba at src.ricoh.co.jp>, 1998;
+ * Based on the ports
+ * by Remi Perrot <r_perrot at mail.club-internet.fr> to m68k/linux
+ * and
+ * by Alexandre Oliva <oliva at dcc.unicamp.br> to sparc
*/
#ifndef __m68k_common_h
#define __m68k_common_h
+ /*
+ * Alignment in structure is 2 bytes packed.
+ */
+ #define ALIGNMENT_OF_SIZE(S) (((S>1)?2:1))
+
+ #if defined(__linux__)
#define sysdepCallMethod(CALL) \
asm volatile (" \n\
1: \n\
***************
*** 54,58 ****
--- 66,98 ----
asm volatile (" \n\
add.w %0,%%sp \n\
" : : "r" ((CALL)->argsize * sizeof(jint)) : "cc")
+ #else /* defined(__linux__) */
+
+ #define sysdepCallMethod(CALL) do { \
+ int extraargs[(CALL)->nrargs]; \
+ register int d0 asm ("d0"); \
+ register int d1 asm ("d1"); \
+ int *res; \
+ int *args = extraargs; \
+ int argidx; \
+ for(argidx = 0; argidx < (CALL)->nrargs; ++argidx) { \
+ if ((CALL)->callsize[argidx]) \
+ *args++ = (CALL)->args[argidx].i; \
+ else \
+ *args++ = (CALL)->args[argidx-1].j; \
+ } \
+ asm volatile ("jsr %2@\n" \
+ : "=r" (d0), "=r" (d1) \
+ : "a" ((CALL)->function), \
+ "r" ((CALL)->nrargs * sizeof(int)) \
+ : "cc", "memory"); \
+ if ((CALL)->retsize != 0) { \
+ res = (int *)(CALL)->ret; \
+ res[1] = d1; \
+ res[0] = d0; \
+ } \
+ } while (0)
+
+ #endif /* defined(__linux__) */
#endif
diff -cr config/m68k/netbsd1/jit-md.h /tmp/config/m68k/netbsd1/jit-md.h
*** config/m68k/netbsd1/jit-md.h Wed Apr 1 04:10:53 1998
--- /tmp/config/m68k/netbsd1/jit-md.h Thu Jul 30 23:38:06 1998
***************
*** 38,44 ****
/* Get the first exception frame from a signal handler */
#define EXCEPTIONFRAME(f, c) \
do { \
! (f).retfp = (uintp)__builtin_frame_address(1); \
(f).retpc = (uintp)(c)->sc_pc; \
} while (0)
--- 38,44 ----
/* Get the first exception frame from a signal handler */
#define EXCEPTIONFRAME(f, c) \
do { \
! (f).retbp = (uintp)__builtin_frame_address(1); \
(f).retpc = (uintp)(c)->sc_pc; \
} while (0)
diff -cr config/m68k/netbsd1/jit.h /tmp/config/m68k/netbsd1/jit.h
*** config/m68k/netbsd1/jit.h Wed Apr 1 04:10:53 1998
--- /tmp/config/m68k/netbsd1/jit.h Tue Aug 18 04:10:36 1998
***************
*** 2,8 ****
* m68k/netbsd1/jit.h
* NetBSD M68000 JIT configuration information.
*
! * Copyright (c) 1996, 1997
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
--- 2,8 ----
* m68k/netbsd1/jit.h
* NetBSD M68000 JIT configuration information.
*
! * Copyright (c) 1996, 1997, 1998
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
***************
*** 11,16 ****
--- 11,19 ----
* Written by Marcello Balduccini <marcy at morgana.usr.dsi.unimi.it>, 1997
* NOTE: this file is heavily based on m68k/jit.h,
* written by Richard Henderson <rth at tamu.edu>, 1997.
+ *
+ * Modified by Kiyo Inaba <inaba at src.ricoh.co.jp>,
+ * to use trampoline code.
*/
#ifndef __m68k_jit_h
***************
*** 17,90 ****
#define __m68k_jit_h
/**/
- /* Native function invocation. */
- /**/
- #define CALL_KAFFE_FUNCTION_VARARGS(meth, obj, nargs, argptr, retval) \
- __asm__ __volatile__( \
- "movem%.l %/d0-%/d7/%/a0-%/a5,%-\n\t" \
- "fmovem %/fp0-%/fp7,%-\n\t" \
- "move%.l %3,%/d0\n\t" \
- "beq 2f\n\t" \
- "lea %4@(%/d0:l:4),%/a0\n\t" \
- "subq%.l %#1,%/d0\n\t" \
- "1: move%.l %/a0 at -,%-\n\t" \
- "dbra %/d0, 1b\n" \
- "2: move%.l %2,%-\n\t" \
- "jsr %1@\n\t" \
- "move%.l %5,%/d1\n\t" \
- "addl %/d1,%/sp\n\t" \
- "move%.l %/d0,%0\n\t" \
- "fmovem %+,%/fp0-%/fp7\n\t" \
- "movem%.l %+,%/d0-%/d7/%/a0-%/a5" \
- : "=m"(retval) \
- : "a"(meth->ncode), "g"(obj), "g"(nargs), "a"(argptr), \
- "m"(4*(nargs+1)) \
- : "cc", "memory")
-
- #define CALL_KAFFE_FUNCTION(meth, obj) \
- __asm__ __volatile__( \
- "movem%.l %/d0-%/d7/%/a0-%/a5,%-\n\t" \
- "fmovem %/fp0-%/fp7,%-\n\t" \
- "move%.l %1,%-\n\t" \
- "jsr %0@\n\t" \
- "addl %#4,%/sp\n\t" \
- "fmovem %+,%/fp0-%/fp7\n\t" \
- "movem%.l %+,%/d0-%/d7/%/a0-%/a5" \
- : : "a"(meth->ncode), "g"(obj) \
- : "cc", "memory")
-
- /**/
/* Exception handling information. */
/**/
- /*extern struct _thread* currentThread;*/
- extern struct Hjava_lang_Thread *currentThread;
-
/* Structure of exception frame on stack */
typedef struct _exceptionFrame {
! uintp retfp;
uintp retpc;
} exceptionFrame;
/* Is this frame valid (ie. is it on the current stack) ? */
#define FRAMEOKAY(f) \
! ((f) && (f)->retfp >= (uintp)TCTX(currentThread)->stackBase && \
! (f)->retfp < (uintp)TCTX(currentThread)->stackEnd)
/* Get the next frame in the chain */
#define NEXTFRAME(f) \
! ((f) = (exceptionFrame*)(f)->retfp)
/* Extract the PC from the given frame */
#define PCFRAME(f) ((f)->retpc)
/* Get the first exception frame from a subroutine call */
#define FIRSTFRAME(f, o) \
((f) = *(exceptionFrame*)__builtin_frame_address(0))
- /* Extract the object argument from given frame */
- #define FRAMEOBJECT(f) (*(Hjava_lang_Object**)((f)->retfp + 8))
-
/* Call the relevant exception handler (rewinding the stack as
necessary). */
#define CALL_KAFFE_EXCEPTION(frame, info, obj) \
--- 20,53 ----
#define __m68k_jit_h
/**/
/* Exception handling information. */
/**/
/* Structure of exception frame on stack */
typedef struct _exceptionFrame {
! uintp retbp;
uintp retpc;
} exceptionFrame;
/* Is this frame valid (ie. is it on the current stack) ? */
#define FRAMEOKAY(f) \
! ((f) && (f)->retbp >= (uintp)TCTX(currentThread)->stackBase && \
! (f)->retbp < (uintp)TCTX(currentThread)->stackEnd)
/* Get the next frame in the chain */
#define NEXTFRAME(f) \
! ((f) = (exceptionFrame*)(f)->retbp)
/* Extract the PC from the given frame */
#define PCFRAME(f) ((f)->retpc)
+ /* Extract the object argument from given frame */
+ #define FRAMEOBJECT(f) (*(Hjava_lang_Object**)((f)->retbp + 8))
+
/* Get the first exception frame from a subroutine call */
#define FIRSTFRAME(f, o) \
((f) = *(exceptionFrame*)__builtin_frame_address(0))
/* Call the relevant exception handler (rewinding the stack as
necessary). */
#define CALL_KAFFE_EXCEPTION(frame, info, obj) \
***************
*** 92,101 ****
"move%.l %0,%/a6\n\t" \
"move%.l %1,%/d0\n\t" \
"jmp %2@" \
! : : "g"(frame->retfp), "g"(obj), "a"(info.handler) \
: "d0", "cc", "memory")
/**/
/* Register management information. */
/**/
--- 55,87 ----
"move%.l %0,%/a6\n\t" \
"move%.l %1,%/d0\n\t" \
"jmp %2@" \
! : : "g"(frame->retbp), "g"(obj), "a"(info.handler) \
: "d0", "cc", "memory")
+ /**/
+ /* Method dispatch. */
+ /**/
+
+ #define HAVE_TRAMPOLINE
+
+ typedef struct _methodTrampoline {
+ unsigned short call;
+ int fixup;
+ struct _methods* meth;
+ } methodTrampoline;
+
+ extern void m68k_do_fixup_trampoline(void);
+
+ #define FILL_IN_TRAMPOLINE(t,m) \
+ do { \
+ (t)->call = 0x4eb9; /* jsr abs.l */ \
+ (t)->fixup = (int)m68k_do_fixup_trampoline; \
+ (t)->meth = (m); \
+ } while (0)
+ #define FIXUP_TRAMPOLINE_DECL Method** _pmeth
+ #define FIXUP_TRAMPOLINE_INIT (meth = *_pmeth)
+
/**/
/* Register management information. */
/**/
***************
*** 135,140 ****
--- 121,127 ----
/* Number of registers in the register set */
#define NR_REGISTERS 24
+ #if 0
/* Define which registers are used for which return values as seen
* by the the callee */
#define RETURN_INT 0 /* d0 */
***************
*** 144,154 ****
--- 131,151 ----
#define RETURN_FLOAT 32 /* f0 */
#define RETURN_DOUBLE_LOW 32 /* f0 */
#define RETURN_DOUBLE_HIGH 32 /* Not used in this configuration */
+ #endif
/**/
/* Opcode generation. */
/**/
+ #define LABEL_FRAMESIZE(L,P) \
+ { \
+ int framesize = SLOTSIZE * (maxLocal + maxStack + \
+ maxTemp - maxArgs); \
+ *(P) = framesize; \
+ }
+
+ #define EXTRA_LABELS(P,D,L)
+
/* Define if generated code uses two operands rather than one */
#define TWO_OPERAND
***************
*** 174,180 ****
*/
/* Generate slot offset for an argument (relative to fp) */
! #define SLOT2ARGOFFSET(_n) (8 + SLOTSIZE*((_n) + isStatic))
/* Generate slot offset for a local (non-argument) (relative to fp) */
#define SLOT2LOCALOFFSET(_n) (-SLOTSIZE * (maxTemp+maxLocal+maxStack - (_n)))
--- 171,177 ----
*/
/* Generate slot offset for an argument (relative to fp) */
! #define SLOT2ARGOFFSET(_n) (8 + SLOTSIZE * (_n))
/* Generate slot offset for a local (non-argument) (relative to fp) */
#define SLOT2LOCALOFFSET(_n) (-SLOTSIZE * (maxTemp+maxLocal+maxStack - (_n)))
***************
*** 187,192 ****
--- 184,191 ----
privledged instruction, so we have to get operating system help
for this. Naturally, there is no standard there. */
+ #define FLUSH_DCACHE(beg, end) __clear_cache((beg), (end))
+ #if 0
#define FLUSH_DCACHE(beg, end) \
__asm__ __volatile__( \
"movem%.l %/d0-%/d7/%/a0-%/a5,%-\n\t" \
***************
*** 198,209 ****
"movem%.l %+,%/d0-%/d7/%/a0-%/a5" \
: \
: "g" (beg), "g" (end) )
!
! #define LABEL_FRAMESIZE(L,P) \
! { \
! int framesize = SLOTSIZE * (maxLocal + maxStack + \
! maxTemp - maxArgs); \
! *(P) = framesize; \
! }
#endif
--- 197,202 ----
"movem%.l %+,%/d0-%/d7/%/a0-%/a5" \
: \
: "g" (beg), "g" (end) )
! #endif
#endif
diff -cr config/m68k/netbsd1/md.c /tmp/config/m68k/netbsd1/md.c
*** config/m68k/netbsd1/md.c Wed Apr 1 04:10:53 1998
--- /tmp/config/m68k/netbsd1/md.c Mon Jul 27 14:35:00 1998
***************
*** 1,5 ****
/*
! * m68k/netbsd/md.c
* netbsd specific functions.
*
* Copyright (c) 1996 Matthias Hopf <mshopf at informatik.uni-erlangen.de>
--- 1,5 ----
/*
! * m68k/netbsd1/md.c
* netbsd specific functions.
*
* Copyright (c) 1996 Matthias Hopf <mshopf at informatik.uni-erlangen.de>
diff -cr config/m68k/netbsd1/md.h /tmp/config/m68k/netbsd1/md.h
*** config/m68k/netbsd1/md.h Mon Jul 27 05:42:50 1998
--- /tmp/config/m68k/netbsd1/md.h Mon Jul 27 14:42:44 1998
***************
*** 1,13 ****
/*
! * m68k/netbsd/md.h
* netbsd/m68k specific functions.
*
- * Copyright (c) 1996 Matthias Hopf <mshopf at informatik.uni-erlangen.de>
- * netbsd/m68k version Erik Johannessen <erjohann at sn.no>
- *
- * Permission granted for Tim Wilkinson to include this source in his
- * Kaffe system.
- *
* Copyright (c) 1996, 1997
* Transvirtual Technologies, Inc. All rights reserved.
*
--- 1,7 ----
/*
! * m68k/netbsd1/md.h
* netbsd/m68k specific functions.
*
* Copyright (c) 1996, 1997
* Transvirtual Technologies, Inc. All rights reserved.
*
***************
*** 14,26 ****
* See the file "license.terms" for information on usage and redistribution
* of this file.
*
! * SP_OFFSET, ALIGNMENT_OF_SIZE, and sysdepCallMethod macro were
! * written by Kiyo Inaba <inaba at src.ricoh.co.jp>, 1998;
*/
! #ifndef __m68k_netbsd_md_h
! #define __m68k_netbsd_md_h
#include "m68k/threads.h"
/*
--- 8,20 ----
* See the file "license.terms" for information on usage and redistribution
* of this file.
*
! * Written by Kiyo Inaba <inaba at src.ricoh.co.jp>, 1998;
*/
! #ifndef __m68k_netbsd1_md_h
! #define __m68k_netbsd1_md_h
+ #include "m68k/common.h"
#include "m68k/threads.h"
/*
***************
*** 28,63 ****
*/
#undef SP_OFFSET
#define SP_OFFSET 2
-
- /*
- * Alignment in structure is 2 bytes packed.
- */
- #define ALIGNMENT_OF_SIZE(S) (((S>1)?2:1))
-
- #define sysdepCallMethod(CALL) do { \
- int extraargs[(CALL)->nrargs]; \
- register int d0 asm ("d0"); \
- register int d1 asm ("d1"); \
- int *res; \
- int *args = extraargs; \
- int argidx; \
- for(argidx = 0; argidx < (CALL)->nrargs; ++argidx) { \
- if ((CALL)->callsize[argidx]) \
- *args++ = (CALL)->args[argidx].i; \
- else \
- *args++ = (CALL)->args[argidx-1].j; \
- } \
- asm volatile ("jsr %2@\naddw %3,sp\n" \
- : "=r" (d0), "=r" (d1) \
- : "a" ((CALL)->function), \
- "r" ((CALL)->nrargs * sizeof(int)) \
- : "cc", "memory"); \
- if ((CALL)->retsize != 0) { \
- res = (int *)(CALL)->ret; \
- res[1] = d1; \
- res[0] = d0; \
- } \
- } while (0)
#if defined(TRANSLATOR)
#include "jit-md.h"
--- 22,27 ----
diff -cr config/m68k/sunos4/config.frag /tmp/config/m68k/sunos4/config.frag
*** config/m68k/sunos4/config.frag Wed Jul 15 06:08:14 1998
--- /tmp/config/m68k/sunos4/config.frag Mon Jul 27 14:30:40 1998
***************
*** 7,18 ****
LIBSHARE=-Bdynamic
LIBEXT=.so
if [ "$cross_compiling" = yes ]; then
- # if we use cross environment, set tools properly
- ac_cv_prog_AR=${ac_cv_prog_AR='m68k-sun-sunos4.1.1-ar -r'}
- # CC should be set before invoking configure, rather than here.
- # ac_cv_prog_CC=${ac_cv_prog_CC='m68k-sun-sunos4.1.1-gcc'}
- ac_cv_prog_CPP=${ac_cv_prog_CPP='m68k-sun-sunos4.1.1-gcc -E'}
- ac_cv_prog_RANLIB=${ac_cv_prog_RANLIB='m68k-sun-sunos4.1.1-ranlib'}
# if we use cross environment, following values may not be detected.
ac_cv_alignmentof_voidp=${ac_cv_alignmentof_voidp='2'}
ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}
--- 7,12 ----
diff -cr config/m68k/sunos4/md.h /tmp/config/m68k/sunos4/md.h
*** config/m68k/sunos4/md.h Wed Jul 15 06:08:14 1998
--- /tmp/config/m68k/sunos4/md.h Mon Jul 27 14:41:46 1998
***************
*** 9,24 ****
* of this file.
*
* Written by Kiyo Inaba <inaba at src.ricoh.co.jp>, 1998;
- * Based on the ports
- * by Remi Perrot <r_perrot at mail.club-internet.fr> to m68k/linux
- * and
- * by Alexandre Oliva <oliva at dcc.unicamp.br> to sparc
- *
*/
#ifndef __m68k_sunos4_md_h
#define __m68k_sunos4_md_h
#include "m68k/threads.h"
/*
--- 9,20 ----
* of this file.
*
* Written by Kiyo Inaba <inaba at src.ricoh.co.jp>, 1998;
*/
#ifndef __m68k_sunos4_md_h
#define __m68k_sunos4_md_h
+ #include "m68k/common.h"
#include "m68k/threads.h"
/*
***************
*** 26,61 ****
*/
#undef SP_OFFSET
#define SP_OFFSET 2
-
- /*
- * Alignment in structure is 2 bytes packed.
- */
- #define ALIGNMENT_OF_SIZE(S) (((S>1)?2:1))
-
- #define sysdepCallMethod(CALL) do { \
- int extraargs[(CALL)->nrargs]; \
- register int d0 asm ("d0"); \
- register int d1 asm ("d1"); \
- int *res; \
- int *args = extraargs; \
- int argidx; \
- for(argidx = 0; argidx < (CALL)->nrargs; ++argidx) { \
- if ((CALL)->callsize[argidx]) \
- *args++ = (CALL)->args[argidx].i; \
- else \
- *args++ = (CALL)->args[argidx-1].j; \
- } \
- asm volatile ("jsr %2@\naddw %3,sp\n" \
- : "=r" (d0), "=r" (d1) \
- : "a" ((CALL)->function), \
- "r" ((CALL)->nrargs * sizeof(int)) \
- : "cc", "memory"); \
- if ((CALL)->retsize != 0) { \
- res = (int *)(CALL)->ret; \
- res[1] = d1; \
- res[0] = d0; \
- } \
- } while (0)
#if defined(TRANSLATOR)
#include "jit-md.h"
--- 22,27 ----
diff -cr config/m68k/trampolines.c /tmp/config/m68k/trampolines.c
*** config/m68k/trampolines.c Tue Aug 18 03:38:38 1998
--- /tmp/config/m68k/trampolines.c Fri Jul 31 13:09:45 1998
***************
*** 0 ****
--- 1,51 ----
+ /*
+ * m68k/trampolines.c
+ * m68k trampolines codes for for various occasions.
+ *
+ * Copyright (c) 1996, 1997, 1998
+ * Transvirtual Technologies, Inc. All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ *
+ * Written by Kiyo Inaba (inaba at src.ricoh.co.jp) based on i386/trampolines.c
+ */
+
+ #if defined(TRAMPOLINE_FUNCTION)
+ /*
+ * If we have an explit function defined then use that.
+ */
+ TRAMPOLINE_FUNCTION()
+
+ #else
+ /*
+ * Otherwise we'll try to construct one.
+ */
+ #if !defined(START_ASM_FUNC)
+ #define START_ASM_FUNC() ".text\n\t.even\n\t.globl "
+ #endif
+ #if !defined(END_ASM_FUNC)
+ #define END_ASM_FUNC() ""
+ #endif
+ #if defined(HAVE_UNDERSCORED_C_NAMES)
+ #define C_FUNC_NAME(FUNC) "_" #FUNC
+ #else
+ #define C_FUNC_NAME(FUNC) #FUNC
+ #endif
+
+ #if defined(NO_SHARED_VMLIBRARY)
+
+ asm(
+ START_ASM_FUNC() C_FUNC_NAME(m68k_do_fixup_trampoline) "\n"
+ C_FUNC_NAME(m68k_do_fixup_trampoline) ": \n
+ jbsr " C_FUNC_NAME(soft_fixup_trampoline) " \n
+ addqw #4,sp \n
+ movel d0,a0 \n
+ jmp a0@"
+ END_ASM_FUNC()
+ );
+
+ #else
+ #endif
+
+ #endif
More information about the kaffe
mailing list