* [PATCH/RFA] libffi: SH support
@ 2002-07-12 19:13 kaz Kojima
2002-07-13 15:22 ` kaz Kojima
2002-07-13 16:27 ` Tom Tromey
0 siblings, 2 replies; 10+ messages in thread
From: kaz Kojima @ 2002-07-12 19:13 UTC (permalink / raw)
To: gcc-patches; +Cc: aoliva, joern.rennecke
Hi,
This patch for mainline adds SH linux support to libffi.
Bootstrapped on i686-pc-linux-gnu and sh4-unknown-linux-gnu
without regressions. It passes ffitest on sh[34]-*-linux-gnu
platforms too.
kaz
--
2002-07-13 Kaz Kojima <kkojima@gcc.gnu.org>
* Makefile.am: Add SH support.
* Makefile.in: Regenerate.
* configure.in (sh*-*-linux-*): Add target.
* configure: Regenerate.
* include/ffi.h.in: Add SH support.
* src/sh/ffi.c: New flie.
* src/sh/sysv.S: New file.
diff -urN ORIG/gcc/libffi/Makefile.am LOCAL/gcc/libffi/Makefile.am
--- ORIG/gcc/libffi/Makefile.am Mon Apr 29 13:14:43 2002
+++ LOCAL/gcc/libffi/Makefile.am Fri Jul 12 17:42:34 2002
@@ -16,7 +16,8 @@
src/powerpc/darwin.S src/powerpc/aix.S \
src/powerpc/darwin_closure.S src/powerpc/aix_closures.S \
src/arm/ffi.c src/arm/sysv.S \
- src/s390/ffi.c src/s390/sysv.S
+ src/s390/ffi.c src/s390/sysv.S \
+ src/sh/ffi.c src/sh/sysv.S
VPATH = @srcdir@:@srcdir@/src:@srcdir@/src/@TARGETDIR@
@@ -105,6 +106,7 @@
TARGET_SRC_POWERPC_DARWIN = src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S
TARGET_SRC_ARM = src/arm/sysv.S src/arm/ffi.c
TARGET_SRC_S390 = src/s390/sysv.S src/s390/ffi.c
+TARGET_SRC_SH = src/sh/sysv.S src/sh/ffi.c
##libffi_la_SOURCES = src/debug.c src/prep_cif.c src/types.c $(TARGET_SRC_@TARGET@)
## Work around automake deficiency
@@ -161,6 +163,10 @@
if S390
libffi_la_SOURCES = $(libffi_la_common_SOURCES) $(TARGET_SRC_S390)
libffi_convenience_la_SOURCES = $(libffi_la_common_SOURCES) $(TARGET_SRC_S390)
+endif
+if SH
+libffi_la_SOURCES = $(libffi_la_common_SOURCES) $(TARGET_SRC_SH)
+libfficonvenience_la_SOURCES = $(libffi_la_common_SOURCES) $(TARGET_SRC_SH)
endif
AM_CFLAGS = -fexceptions
diff -urN ORIG/gcc/libffi/configure.in LOCAL/gcc/libffi/configure.in
--- ORIG/gcc/libffi/configure.in Wed May 8 13:36:40 2002
+++ LOCAL/gcc/libffi/configure.in Fri Jul 12 17:42:34 2002
@@ -68,6 +68,7 @@
rs6000-*-aix*) TARGET=POWERPC_AIX; TARGETDIR=powerpc;;
arm*-*-linux-*) TARGET=ARM; TARGETDIR=arm;;
s390-*-linux-*) TARGET=S390; TARGETDIR=s390;;
+sh*-*-linux-*) TARGET=SH; TARGETDIR=sh;;
esac
if test $TARGETDIR = unknown; then
@@ -87,6 +88,7 @@
AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
AM_CONDITIONAL(ARM, test x$TARGET = xARM)
AM_CONDITIONAL(S390, test x$TARGET = xS390)
+AM_CONDITIONAL(SH, test x$TARGET = xSH)
AC_HEADER_STDC
AC_CHECK_FUNCS(memcpy)
diff -urN ORIG/gcc/libffi/include/ffi.h.in LOCAL/gcc/libffi/include/ffi.h.in
--- ORIG/gcc/libffi/include/ffi.h.in Mon Apr 29 13:14:44 2002
+++ LOCAL/gcc/libffi/include/ffi.h.in Sat Jul 13 08:54:26 2002
@@ -257,6 +257,12 @@
FFI_DEFAULT_ABI = FFI_SYSV,
#endif
+ /* ---- SuperH ------------------- */
+#ifdef SH
+ FFI_SYSV,
+ FFI_DEFAULT_ABI = FFI_SYSV,
+#endif
+
/* Leave this for debugging purposes */
FFI_LAST_ABI
diff -urN ORIG/gcc/libffi/src/sh/ffi.c LOCAL/gcc/libffi/src/sh/ffi.c
--- ORIG/gcc/libffi/src/sh/ffi.c Thu Jan 1 09:00:00 1970
+++ LOCAL/gcc/libffi/src/sh/ffi.c Sun Feb 10 21:23:09 2002
@@ -0,0 +1,460 @@
+/* -----------------------------------------------------------------------
+ ffi.c - Copyright (c) 2002 Kaz Kojima
+
+ SuperH Foreign Function Interface
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ ``Software''), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+ ----------------------------------------------------------------------- */
+
+#include <ffi.h>
+#include <ffi_common.h>
+
+#include <stdlib.h>
+
+#define NGREGARG 4
+#if defined(__SH4__)
+#define NFREGARG 8
+#endif
+
+#if defined(__HITACHI__)
+#define STRUCT_VALUE_ADDRESS_WITH_ARG 1
+#else
+#define STRUCT_VALUE_ADDRESS_WITH_ARG 0
+#endif
+
+/* If the structure has essentialy an unique element, return its type. */
+static int
+simple_type (ffi_type *arg)
+{
+ if (arg->type != FFI_TYPE_STRUCT)
+ return arg->type;
+ else if (arg->elements[1])
+ return FFI_TYPE_STRUCT;
+
+ return simple_type (arg->elements[0]);
+}
+
+static int
+return_type (ffi_type *arg)
+{
+ unsigned short type;
+
+ if (arg->type != FFI_TYPE_STRUCT)
+ return arg->type;
+
+ type = simple_type (arg->elements[0]);
+ if (! arg->elements[1])
+ {
+ switch (type)
+ {
+ case FFI_TYPE_SINT8:
+ case FFI_TYPE_UINT8:
+ case FFI_TYPE_SINT16:
+ case FFI_TYPE_UINT16:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+ return FFI_TYPE_INT;
+
+ default:
+ return type;
+ }
+ }
+
+ /* gcc uses r0/r1 pair for some kind of structures. */
+ if (arg->size <= 2 * sizeof (int))
+ {
+ int i = 0;
+ ffi_type *e;
+
+ while ((e = arg->elements[i++]))
+ {
+ type = simple_type (e);
+ switch (type)
+ {
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+ case FFI_TYPE_INT:
+ case FFI_TYPE_FLOAT:
+ return FFI_TYPE_UINT64;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ return FFI_TYPE_STRUCT;
+}
+
+/* ffi_prep_args is called by the assembly routine once stack space
+ has been allocated for the function's arguments */
+
+/*@-exportheader@*/
+void ffi_prep_args(char *stack, extended_cif *ecif)
+/*@=exportheader@*/
+{
+ register unsigned int i;
+ register int tmp;
+ register unsigned int avn;
+ register void **p_argv;
+ register char *argp;
+ register ffi_type **p_arg;
+ int greg, ireg;
+#if defined(__SH4__)
+ int freg = 0;
+#endif
+
+ tmp = 0;
+ argp = stack;
+
+ if (return_type (ecif->cif->rtype) == FFI_TYPE_STRUCT)
+ {
+ *(void **) argp = ecif->rvalue;
+ argp += 4;
+ ireg = STRUCT_VALUE_ADDRESS_WITH_ARG ? 1 : 0;
+ }
+ else
+ ireg = 0;
+
+ /* Set arguments for registers. */
+ greg = ireg;
+ avn = ecif->cif->nargs;
+ p_argv = ecif->avalue;
+
+ for (i = 0, p_arg = ecif->cif->arg_types; i < avn; i++, p_arg++, p_argv++)
+ {
+ size_t z;
+
+ z = (*p_arg)->size;
+ if (z < sizeof(int))
+ {
+ if (greg++ >= NGREGARG)
+ continue;
+
+ z = sizeof(int);
+ switch ((*p_arg)->type)
+ {
+ case FFI_TYPE_SINT8:
+ *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_UINT8:
+ *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_SINT16:
+ *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_UINT16:
+ *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_STRUCT:
+ *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
+ break;
+
+ default:
+ FFI_ASSERT(0);
+ }
+ argp += z;
+ }
+ else if (z == sizeof(int))
+ {
+#if defined(__SH4__)
+ if ((*p_arg)->type == FFI_TYPE_FLOAT)
+ {
+ if (freg++ >= NFREGARG)
+ continue;
+ }
+ else
+#endif
+ {
+ if (greg++ >= NGREGARG)
+ continue;
+ }
+ *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
+ argp += z;
+ }
+#if defined(__SH4__)
+ else if ((*p_arg)->type == FFI_TYPE_DOUBLE)
+ {
+ if (freg + 1 >= NFREGARG)
+ continue;
+ freg = (freg + 1) & ~1;
+ freg += 2;
+ memcpy (argp, *p_argv, z);
+ argp += z;
+ }
+#endif
+ else
+ {
+ int n = (z + sizeof (int) - 1) / sizeof (int);
+#if defined(__SH4__)
+ if (greg + n - 1 >= NGREGARG)
+ continue;
+ greg += n;
+#else
+ if (greg >= NGREGARG)
+ continue;
+ else if (greg + n - 1 >= NGREGARG)
+ greg = NGREGARG;
+ else
+ greg += n;
+#endif
+ memcpy (argp, *p_argv, z);
+ argp += z;
+ }
+ }
+
+ /* Set arguments on stack. */
+ greg = ireg;
+#if defined(__SH4__)
+ freg = 0;
+#endif
+ p_argv = ecif->avalue;
+
+ for (i = 0, p_arg = ecif->cif->arg_types; i < avn; i++, p_arg++, p_argv++)
+ {
+ size_t z;
+
+ z = (*p_arg)->size;
+ if (z < sizeof(int))
+ {
+ if (greg++ < NGREGARG)
+ continue;
+
+ z = sizeof(int);
+ switch ((*p_arg)->type)
+ {
+ case FFI_TYPE_SINT8:
+ *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_UINT8:
+ *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_SINT16:
+ *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_UINT16:
+ *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
+ break;
+
+ case FFI_TYPE_STRUCT:
+ *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
+ break;
+
+ default:
+ FFI_ASSERT(0);
+ }
+ argp += z;
+ }
+ else if (z == sizeof(int))
+ {
+#if defined(__SH4__)
+ if ((*p_arg)->type == FFI_TYPE_FLOAT)
+ {
+ if (freg++ < NFREGARG)
+ continue;
+ }
+ else
+#endif
+ {
+ if (greg++ < NGREGARG)
+ continue;
+ }
+ *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
+ argp += z;
+ }
+#if defined(__SH4__)
+ else if ((*p_arg)->type == FFI_TYPE_DOUBLE)
+ {
+ if (freg + 1 < NFREGARG)
+ {
+ freg = (freg + 1) & ~1;
+ freg += 2;
+ continue;
+ }
+ memcpy (argp, *p_argv, z);
+ argp += z;
+ }
+#endif
+ else
+ {
+ int n = (z + sizeof (int) - 1) / sizeof (int);
+ if (greg + n - 1 < NGREGARG)
+ {
+ greg += n;
+ continue;
+ }
+#if (! defined(__SH4__))
+ else if (greg < NGREGARG)
+ {
+ greg = NGREGARG;
+ continue;
+ }
+#endif
+ memcpy (argp, *p_argv, z);
+ argp += z;
+ }
+ }
+
+ return;
+}
+
+/* Perform machine dependent cif processing */
+ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
+{
+ int i, j;
+ int size, type;
+ int n, m;
+ int greg;
+#if defined(__SH4__)
+ int freg = 0;
+#endif
+
+ cif->flags = 0;
+
+ greg = ((return_type (cif->rtype) == FFI_TYPE_STRUCT) &&
+ STRUCT_VALUE_ADDRESS_WITH_ARG) ? 1 : 0;
+
+#if defined(__SH4__)
+ for (i = j = 0; i < cif->nargs && j < 12; i++)
+ {
+ type = (cif->arg_types)[i]->type;
+ switch (type)
+ {
+ case FFI_TYPE_FLOAT:
+ if (freg >= NFREGARG)
+ continue;
+ freg++;
+ cif->flags += ((cif->arg_types)[i]->type) << (2 * j);
+ j++;
+ break;
+
+ case FFI_TYPE_DOUBLE:
+ if ((freg + 1) >= NFREGARG)
+ continue;
+ freg = (freg + 1) & ~1;
+ freg += 2;
+ cif->flags += ((cif->arg_types)[i]->type) << (2 * j);
+ j++;
+ break;
+
+ default:
+ size = (cif->arg_types)[i]->size;
+ n = (size + sizeof (int) - 1) / sizeof (int);
+ if (greg + n - 1 >= NGREGARG)
+ continue;
+ greg += n;
+ for (m = 0; m < n; m++)
+ cif->flags += FFI_TYPE_INT << (2 * j++);
+ break;
+ }
+ }
+#else
+ for (i = j = 0; i < cif->nargs && j < 4; i++)
+ {
+ size = (cif->arg_types)[i]->size;
+ n = (size + sizeof (int) - 1) / sizeof (int);
+ if (greg >= NGREGARG)
+ continue;
+ else if (greg + n - 1 >= NGREGARG)
+ greg = NGREGARG;
+ else
+ greg += n;
+ for (m = 0; m < n; m++)
+ cif->flags += FFI_TYPE_INT << (2 * j++);
+ }
+#endif
+
+ /* Set the return type flag */
+ switch (cif->rtype->type)
+ {
+ case FFI_TYPE_STRUCT:
+ cif->flags += (unsigned) (return_type (cif->rtype)) << 24;
+ break;
+
+ case FFI_TYPE_VOID:
+ case FFI_TYPE_FLOAT:
+ case FFI_TYPE_DOUBLE:
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+ cif->flags += (unsigned) cif->rtype->type << 24;
+ break;
+
+ default:
+ cif->flags += FFI_TYPE_INT << 24;
+ break;
+ }
+
+ return FFI_OK;
+}
+
+/*@-declundef@*/
+/*@-exportheader@*/
+extern void ffi_call_SYSV(void (*)(char *, extended_cif *),
+ /*@out@*/ extended_cif *,
+ unsigned, unsigned,
+ /*@out@*/ unsigned *,
+ void (*fn)());
+/*@=declundef@*/
+/*@=exportheader@*/
+
+void ffi_call(/*@dependent@*/ ffi_cif *cif,
+ void (*fn)(),
+ /*@out@*/ void *rvalue,
+ /*@dependent@*/ void **avalue)
+{
+ extended_cif ecif;
+
+ ecif.cif = cif;
+ ecif.avalue = avalue;
+
+ /* If the return value is a struct and we don't have a return */
+ /* value address then we need to make one */
+
+ if ((rvalue == NULL) &&
+ (cif->rtype->type == FFI_TYPE_STRUCT))
+ {
+ /*@-sysunrecog@*/
+ ecif.rvalue = alloca(cif->rtype->size);
+ /*@=sysunrecog@*/
+ }
+ else
+ ecif.rvalue = rvalue;
+
+
+ switch (cif->abi)
+ {
+ case FFI_SYSV:
+ /*@-usedef@*/
+ ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes,
+ cif->flags, ecif.rvalue, fn);
+ /*@=usedef@*/
+ break;
+ default:
+ FFI_ASSERT(0);
+ break;
+ }
+}
diff -urN ORIG/gcc/libffi/src/sh/sysv.S LOCAL/gcc/libffi/src/sh/sysv.S
--- ORIG/gcc/libffi/src/sh/sysv.S Thu Jan 1 09:00:00 1970
+++ LOCAL/gcc/libffi/src/sh/sysv.S Tue Oct 23 13:33:36 2001
@@ -0,0 +1,496 @@
+/* -----------------------------------------------------------------------
+ sysv.S - Copyright (c) 2002 Kaz Kojima
+
+ SuperH Foreign Function Interface
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ ``Software''), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+ ----------------------------------------------------------------------- */
+
+#define LIBFFI_ASM
+#include <ffi.h>
+#ifdef HAVE_MACHINE_ASM_H
+#include <machine/asm.h>
+#else
+/* XXX these lose for some platforms, I'm sure. */
+#define CNAME(x) x
+#define ENTRY(x) .globl CNAME(x); .type CNAME(x),%function; CNAME(x):
+#endif
+
+#if defined(__HITACHI__)
+#define STRUCT_VALUE_ADDRESS_WITH_ARG 1
+#else
+#define STRUCT_VALUE_ADDRESS_WITH_ARG 0
+#endif
+
+.text
+
+ # r4: ffi_prep_args
+ # r5: &ecif
+ # r6: bytes
+ # r7: flags
+ # sp+0: rvalue
+ # sp+4: fn
+
+ # This assumes we are using gas.
+ENTRY(ffi_call_SYSV)
+#if defined(__SH4__)
+ # Save registers
+ mov.l r8,@-r15
+ mov.l r9,@-r15
+ mov.l r10,@-r15
+ mov.l r12,@-r15
+ mov.l r14,@-r15
+ sts.l pr,@-r15
+ mov r15,r14
+
+ mov r6,r8
+ mov r7,r9
+
+ sub r6,r15
+ add #-16,r15
+ mov #~7,r0
+ and r0,r15
+
+ mov r4,r0
+ jsr @r0
+ mov r15,r4
+
+ mov r9,r1
+ shlr8 r9
+ shlr8 r9
+ shlr8 r9
+
+ mov #FFI_TYPE_STRUCT,r2
+ cmp/eq r2,r9
+ bf 1f
+#if STRUCT_VALUE_ADDRESS_WITH_ARG
+ mov.l @r15+,r4
+ bra 2f
+ mov #5,r2
+#else
+ mov.l @r15+,r10
+#endif
+1:
+ mov #4,r2
+2:
+ mov #4,r3
+
+L_pass:
+ cmp/pl r8
+ bf L_call_it
+
+ mov r1,r0
+ and #3,r0
+
+L_pass_d:
+ cmp/eq #FFI_TYPE_DOUBLE,r0
+ bf L_pass_f
+
+ mov r3,r0
+ and #1,r0
+ tst r0,r0
+ bt 1f
+ add #1,r3
+1:
+ mov r15,r0
+ and #7,r0
+ tst r0,r0
+ bt 2f
+ add #4,r15
+2:
+ mov #12,r0
+ cmp/hs r0,r3
+ bt/s 3f
+ shlr2 r1
+ bsr L_pop_d
+ nop
+3:
+ add #2,r3
+ bra L_pass
+ add #-8,r8
+
+L_pop_d:
+ mov r3,r0
+ add r0,r0
+ add r3,r0
+ add #-12,r0
+ braf r0
+ nop
+#ifdef __LITTLE_ENDIAN__
+ fmov.s @r15+,fr5
+ rts
+ fmov.s @r15+,fr4
+ fmov.s @r15+,fr7
+ rts
+ fmov.s @r15+,fr6
+ fmov.s @r15+,fr9
+ rts
+ fmov.s @r15+,fr8
+ fmov.s @r15+,fr11
+ rts
+ fmov.s @r15+,fr10
+#else
+ fmov.s @r15+,fr4
+ rts
+ fmov.s @r15+,fr5
+ fmov.s @r15+,fr6
+ rts
+ fmov.s @r15+,fr7
+ fmov.s @r15+,fr8
+ rts
+ fmov.s @r15+,fr9
+ fmov.s @r15+,fr10
+ rts
+ fmov.s @r15+,fr11
+#endif
+
+L_pass_f:
+ cmp/eq #FFI_TYPE_FLOAT,r0
+ bf L_pass_i
+
+ mov #12,r0
+ cmp/hs r0,r3
+ bt/s 2f
+ shlr2 r1
+ bsr L_pop_f
+ nop
+2:
+ add #1,r3
+ bra L_pass
+ add #-4,r8
+
+L_pop_f:
+ mov r3,r0
+ shll2 r0
+ add #-16,r0
+ braf r0
+ nop
+#ifdef __LITTLE_ENDIAN__
+ rts
+ fmov.s @r15+,fr5
+ rts
+ fmov.s @r15+,fr4
+ rts
+ fmov.s @r15+,fr7
+ rts
+ fmov.s @r15+,fr6
+ rts
+ fmov.s @r15+,fr9
+ rts
+ fmov.s @r15+,fr8
+ rts
+ fmov.s @r15+,fr11
+ rts
+ fmov.s @r15+,fr10
+#else
+ rts
+ fmov.s @r15+,fr4
+ rts
+ fmov.s @r15+,fr5
+ rts
+ fmov.s @r15+,fr6
+ rts
+ fmov.s @r15+,fr7
+ rts
+ fmov.s @r15+,fr8
+ rts
+ fmov.s @r15+,fr9
+ rts
+ fmov.s @r15+,fr10
+ rts
+ fmov.s @r15+,fr11
+#endif
+
+L_pass_i:
+ cmp/eq #FFI_TYPE_INT,r0
+ bf L_call_it
+
+ mov #8,r0
+ cmp/hs r0,r2
+ bt/s 2f
+ shlr2 r1
+ bsr L_pop_i
+ nop
+2:
+ add #1,r2
+ bra L_pass
+ add #-4,r8
+
+L_pop_i:
+ mov r2,r0
+ shll2 r0
+ add #-16,r0
+ braf r0
+ nop
+ rts
+ mov.l @r15+,r4
+ rts
+ mov.l @r15+,r5
+ rts
+ mov.l @r15+,r6
+ rts
+ mov.l @r15+,r7
+
+L_call_it:
+ # call function
+#if (! STRUCT_VALUE_ADDRESS_WITH_ARG)
+ mov r10, r2
+#endif
+ mov.l @(28,r14),r1
+ jsr @r1
+ nop
+
+L_ret_d:
+ mov #FFI_TYPE_DOUBLE,r2
+ cmp/eq r2,r9
+ bf L_ret_ll
+
+ mov.l @(24,r14),r1
+#ifdef __LITTLE_ENDIAN__
+ fmov.s fr1,@r1
+ add #4,r1
+ bra L_epilogue
+ fmov.s fr0,@r1
+#else
+ fmov.s fr0,@r1
+ add #4,r1
+ bra L_epilogue
+ fmov.s fr1,@r1
+#endif
+
+L_ret_ll:
+ mov #FFI_TYPE_SINT64,r2
+ cmp/eq r2,r9
+ bt/s 1f
+ mov #FFI_TYPE_UINT64,r2
+ cmp/eq r2,r9
+ bf L_ret_f
+
+1:
+ mov.l @(24,r14),r2
+ mov.l r0,@r2
+ bra L_epilogue
+ mov.l r1,@(4,r2)
+
+L_ret_f:
+ mov #FFI_TYPE_FLOAT,r2
+ cmp/eq r2,r9
+ bf L_ret_i
+
+ mov.l @(24,r14),r1
+ bra L_epilogue
+ fmov.s fr0,@r1
+
+L_ret_i:
+ mov #FFI_TYPE_INT,r2
+ cmp/eq r2,r9
+ bf L_epilogue
+
+ mov.l @(24,r14),r1
+ bra L_epilogue
+ mov.l r0,@r1
+
+L_epilogue:
+ # Remove the space we pushed for the args
+ mov r14,r15
+
+ lds.l @r15+,pr
+ mov.l @r15+,r14
+ mov.l @r15+,r12
+ mov.l @r15+,r10
+ mov.l @r15+,r9
+ rts
+ mov.l @r15+,r8
+#else
+ # Save registers
+ mov.l r8,@-r15
+ mov.l r9,@-r15
+ mov.l r10,@-r15
+ mov.l r12,@-r15
+ mov.l r14,@-r15
+ sts.l pr,@-r15
+ mov r15,r14
+
+ mov r6,r8
+ mov r7,r9
+
+ sub r6,r15
+ add #-16,r15
+ mov #~7,r0
+ and r0,r15
+
+ mov r4,r0
+ jsr @r0
+ mov r15,r4
+
+ mov r9,r3
+ shlr8 r9
+ shlr8 r9
+ shlr8 r9
+
+ mov #FFI_TYPE_STRUCT,r2
+ cmp/eq r2,r9
+ bf 1f
+#if STRUCT_VALUE_ADDRESS_WITH_ARG
+ mov.l @r15+,r4
+ bra 2f
+ mov #5,r2
+#else
+ mov.l @r15+,r10
+#endif
+1:
+ mov #4,r2
+2:
+
+L_pass:
+ cmp/pl r8
+ bf L_call_it
+
+ mov r3,r0
+ and #3,r0
+
+L_pass_d:
+ cmp/eq #FFI_TYPE_DOUBLE,r0
+ bf L_pass_i
+
+ mov r15,r0
+ and #7,r0
+ tst r0,r0
+ bt 1f
+ add #4,r15
+1:
+ mov #8,r0
+ cmp/hs r0,r2
+ bt/s 2f
+ shlr2 r3
+ bsr L_pop_d
+ nop
+2:
+ add #2,r2
+ bra L_pass
+ add #-8,r8
+
+L_pop_d:
+ mov r2,r0
+ add r0,r0
+ add r2,r0
+ add #-12,r0
+ add r0,r0
+ braf r0
+ nop
+ mov.l @r15+,r4
+ rts
+ mov.l @r15+,r5
+ mov.l @r15+,r5
+ rts
+ mov.l @r15+,r6
+ mov.l @r15+,r6
+ rts
+ mov.l @r15+,r7
+ rts
+ mov.l @r15+,r7
+
+L_pass_i:
+ mov #8,r0
+ cmp/hs r0,r2
+ bt/s 2f
+ shlr2 r3
+ bsr L_pop_i
+ nop
+2:
+ add #1,r2
+ bra L_pass
+ add #-4,r8
+
+L_pop_i:
+ mov r2,r0
+ shll2 r0
+ add #-16,r0
+ braf r0
+ nop
+ rts
+ mov.l @r15+,r4
+ rts
+ mov.l @r15+,r5
+ rts
+ mov.l @r15+,r6
+ rts
+ mov.l @r15+,r7
+
+L_call_it:
+ # call function
+#if (! STRUCT_VALUE_ADDRESS_WITH_ARG)
+ mov r10, r2
+#endif
+ mov.l @(28,r14),r1
+ jsr @r1
+ nop
+
+L_ret_d:
+ mov #FFI_TYPE_DOUBLE,r2
+ cmp/eq r2,r9
+ bf L_ret_ll
+
+ mov.l @(24,r14),r2
+ mov.l r0,@r2
+ bra L_epilogue
+ mov.l r1,@(4,r2)
+
+L_ret_ll:
+ mov #FFI_TYPE_SINT64,r2
+ cmp/eq r2,r9
+ bt/s 1f
+ mov #FFI_TYPE_UINT64,r2
+ cmp/eq r2,r9
+ bf L_ret_i
+
+1:
+ mov.l @(24,r14),r2
+ mov.l r0,@r2
+ bra L_epilogue
+ mov.l r1,@(4,r2)
+
+L_ret_i:
+ mov #FFI_TYPE_FLOAT,r2
+ cmp/eq r2,r9
+ bt 1f
+ mov #FFI_TYPE_INT,r2
+ cmp/eq r2,r9
+ bf L_epilogue
+1:
+ mov.l @(24,r14),r1
+ bra L_epilogue
+ mov.l r0,@r1
+
+L_epilogue:
+ # Remove the space we pushed for the args
+ mov r14,r15
+
+ lds.l @r15+,pr
+ mov.l @r15+,r14
+ mov.l @r15+,r12
+ mov.l @r15+,r10
+ mov.l @r15+,r9
+ rts
+ mov.l @r15+,r8
+#endif
+
+.ffi_call_SYSV_end:
+ .size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-12 19:13 [PATCH/RFA] libffi: SH support kaz Kojima
@ 2002-07-13 15:22 ` kaz Kojima
2002-07-15 11:02 ` Joern Rennecke
2002-07-13 16:27 ` Tom Tromey
1 sibling, 1 reply; 10+ messages in thread
From: kaz Kojima @ 2002-07-13 15:22 UTC (permalink / raw)
To: gcc-patches; +Cc: aoliva, joern.rennecke
kaz Kojima <kkojima@rr.iij4u.or.jp> wrote:
> This patch for mainline adds SH linux support to libffi.
> Bootstrapped on i686-pc-linux-gnu and sh4-unknown-linux-gnu
> without regressions. It passes ffitest on sh[34]-*-linux-gnu
> platforms too.
>
> kaz
> --
> 2002-07-13 Kaz Kojima <kkojima@gcc.gnu.org>
>
> * Makefile.am: Add SH support.
> * Makefile.in: Regenerate.
> * configure.in (sh*-*-linux-*): Add target.
> * configure: Regenerate.
> * include/ffi.h.in: Add SH support.
> * src/sh/ffi.c: New flie.
> * src/sh/sysv.S: New file.
Duh. I've forgot a patch for src/types.c.
kaz
--
* src/types.c: Add SH support.
--- ORIG/gcc/libffi/src/types.c Tue Mar 27 11:39:16 2001
+++ LOCAL/gcc/libffi/src/types.c Fri Jul 12 17:42:34 2002
@@ -67,6 +67,11 @@
FFI_INTEGRAL_TYPEDEF(uint64, 8, 4, FFI_TYPE_UINT64);
FFI_INTEGRAL_TYPEDEF(sint64, 8, 4, FFI_TYPE_SINT64);
+#elif defined SH
+
+FFI_INTEGRAL_TYPEDEF(uint64, 8, 4, FFI_TYPE_UINT64);
+FFI_INTEGRAL_TYPEDEF(sint64, 8, 4, FFI_TYPE_SINT64);
+
#elif defined M68K
FFI_INTEGRAL_TYPEDEF(uint64, 8, 4, FFI_TYPE_UINT64);
@@ -91,6 +96,11 @@
FFI_INTEGRAL_TYPEDEF(longdouble, 12, 4, FFI_TYPE_LONGDOUBLE);
#elif defined ARM
+
+FFI_INTEGRAL_TYPEDEF(double, 8, 4, FFI_TYPE_DOUBLE);
+FFI_INTEGRAL_TYPEDEF(longdouble, 8, 4, FFI_TYPE_LONGDOUBLE);
+
+#elif defined SH
FFI_INTEGRAL_TYPEDEF(double, 8, 4, FFI_TYPE_DOUBLE);
FFI_INTEGRAL_TYPEDEF(longdouble, 8, 4, FFI_TYPE_LONGDOUBLE);
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-12 19:13 [PATCH/RFA] libffi: SH support kaz Kojima
2002-07-13 15:22 ` kaz Kojima
@ 2002-07-13 16:27 ` Tom Tromey
2002-07-13 16:28 ` kaz Kojima
1 sibling, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2002-07-13 16:27 UTC (permalink / raw)
To: kaz Kojima; +Cc: gcc-patches, aoliva, joern.rennecke
>>>>> "kaz" == kaz Kojima <kkojima@rr.iij4u.or.jp> writes:
kaz> This patch for mainline adds SH linux support to libffi.
kaz> Bootstrapped on i686-pc-linux-gnu and sh4-unknown-linux-gnu
kaz> without regressions. It passes ffitest on sh[34]-*-linux-gnu
kaz> platforms too.
If the SH hackers think this looks good, then it is fine.
kaz> * src/sh/ffi.c: New flie.
Typo.
Any interest in implementing the closure API as well? This API is
needed by the libgcj bytecode interpreter.
Tom
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-13 16:27 ` Tom Tromey
@ 2002-07-13 16:28 ` kaz Kojima
0 siblings, 0 replies; 10+ messages in thread
From: kaz Kojima @ 2002-07-13 16:28 UTC (permalink / raw)
To: gcc-patches; +Cc: tromey, aoliva, joern.rennecke
Tom Tromey <tromey@redhat.com> writes:
> >>>>> "kaz" == kaz Kojima <kkojima@rr.iij4u.or.jp> writes:
>
> kaz> This patch for mainline adds SH linux support to libffi.
> kaz> Bootstrapped on i686-pc-linux-gnu and sh4-unknown-linux-gnu
> kaz> without regressions. It passes ffitest on sh[34]-*-linux-gnu
> kaz> platforms too.
>
> If the SH hackers think this looks good, then it is fine.
>
> kaz> * src/sh/ffi.c: New flie.
>
> Typo.
Thanks for the review. I'll wait the approval from SH maintainers.
> Any interest in implementing the closure API as well? This API is
> needed by the libgcj bytecode interpreter.
I've missed it. I think the libgcj bytecode interpreter is deadly
needed by some SH linux guys. I'd like to look the implementation
of the closure API for the other target.
Thanks again,
kaz
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-13 15:22 ` kaz Kojima
@ 2002-07-15 11:02 ` Joern Rennecke
2002-07-15 17:57 ` kaz Kojima
0 siblings, 1 reply; 10+ messages in thread
From: Joern Rennecke @ 2002-07-15 11:02 UTC (permalink / raw)
To: kaz Kojima; +Cc: gcc-patches, aoliva
kaz Kojima wrote:
>
> kaz Kojima <kkojima@rr.iij4u.or.jp> wrote:
> > This patch for mainline adds SH linux support to libffi.
> > Bootstrapped on i686-pc-linux-gnu and sh4-unknown-linux-gnu
> > without regressions. It passes ffitest on sh[34]-*-linux-gnu
> > platforms too.
> >
> > kaz
> > --
> > 2002-07-13 Kaz Kojima <kkojima@gcc.gnu.org>
> >
> > * Makefile.am: Add SH support.
> > * Makefile.in: Regenerate.
> > * configure.in (sh*-*-linux-*): Add target.
> > * configure: Regenerate.
> > * include/ffi.h.in: Add SH support.
> > * src/sh/ffi.c: New flie.
> > * src/sh/sysv.S: New file.
>
> Duh. I've forgot a patch for src/types.c.
>
> kaz
> --
> * src/types.c: Add SH support.
Your configuration will match sh64-linux, yet the implementation
doesn't support it.
--
--------------------------
SuperH
2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
T:+44 1454 462330
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-15 11:02 ` Joern Rennecke
@ 2002-07-15 17:57 ` kaz Kojima
2002-07-15 18:16 ` Jason R Thorpe
0 siblings, 1 reply; 10+ messages in thread
From: kaz Kojima @ 2002-07-15 17:57 UTC (permalink / raw)
To: gcc-patches; +Cc: joern.rennecke, aoliva
Joern Rennecke <joern.rennecke@superh.com> wrote:
> Your configuration will match sh64-linux, yet the implementation
> doesn't support it.
Sure. Is
sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
ok?
kaz
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-15 17:57 ` kaz Kojima
@ 2002-07-15 18:16 ` Jason R Thorpe
2002-07-15 18:38 ` kaz Kojima
0 siblings, 1 reply; 10+ messages in thread
From: Jason R Thorpe @ 2002-07-15 18:16 UTC (permalink / raw)
To: kaz Kojima; +Cc: gcc-patches, joern.rennecke, aoliva
On Tue, Jul 16, 2002 at 09:40:32AM +0900, kaz Kojima wrote:
> Joern Rennecke <joern.rennecke@superh.com> wrote:
> > Your configuration will match sh64-linux, yet the implementation
> > doesn't support it.
>
> Sure. Is
> sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
I think you'd also want sh-*-linux*, right? (I'm just thinking ahead
to what NetBSD will use...)
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-15 18:16 ` Jason R Thorpe
@ 2002-07-15 18:38 ` kaz Kojima
2002-07-16 3:54 ` Joern Rennecke
0 siblings, 1 reply; 10+ messages in thread
From: kaz Kojima @ 2002-07-15 18:38 UTC (permalink / raw)
To: gcc-patches; +Cc: thorpej, joern.rennecke, aoliva
Jason R Thorpe <thorpej@wasabisystems.com> writes:
> On Tue, Jul 16, 2002 at 09:40:32AM +0900, kaz Kojima wrote:
>
>> Joern Rennecke <joern.rennecke@superh.com> wrote:
>>> Your configuration will match sh64-linux, yet the implementation
>>> doesn't support it.
>>
>> Sure. Is
>> sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
>
> I think you'd also want sh-*-linux*, right? (I'm just thinking ahead
> to what NetBSD will use...)
Oops, I've forgot it. Is
sh-*-linux* | sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
ok?
Thanks,
kaz
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-15 18:38 ` kaz Kojima
@ 2002-07-16 3:54 ` Joern Rennecke
2002-07-16 5:46 ` kaz Kojima
0 siblings, 1 reply; 10+ messages in thread
From: Joern Rennecke @ 2002-07-16 3:54 UTC (permalink / raw)
To: kaz Kojima; +Cc: gcc-patches, thorpej, aoliva
kaz Kojima wrote:
> Oops, I've forgot it. Is
> sh-*-linux* | sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
> ok?
Yes. We might revisit later what sh-*-linux* is supposed to mean,
but at the moment is means sh3 / sh3e / sh4 with sh3 default.
--
--------------------------
SuperH
2430 Aztec West / Almondsbury / BRISTOL / BS32 4AQ
T:+44 1454 462330
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH/RFA] libffi: SH support
2002-07-16 3:54 ` Joern Rennecke
@ 2002-07-16 5:46 ` kaz Kojima
0 siblings, 0 replies; 10+ messages in thread
From: kaz Kojima @ 2002-07-16 5:46 UTC (permalink / raw)
To: gcc-patches; +Cc: joern.rennecke, aoliva, thorpej
Joern Rennecke <joern.rennecke@superh.com> wrote:
> kaz Kojima wrote:
>> Oops, I've forgot it. Is
>> sh-*-linux* | sh[34]*-*-linux*) TARGET=SH; TARGETDIR=sh;;
>> ok?
>
> Yes. We might revisit later what sh-*-linux* is supposed to mean,
> but at the moment is means sh3 / sh3e / sh4 with sh3 default.
OK. It seems reasonable to do so.
Thanks,
kaz
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2002-07-16 12:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-12 19:13 [PATCH/RFA] libffi: SH support kaz Kojima
2002-07-13 15:22 ` kaz Kojima
2002-07-15 11:02 ` Joern Rennecke
2002-07-15 17:57 ` kaz Kojima
2002-07-15 18:16 ` Jason R Thorpe
2002-07-15 18:38 ` kaz Kojima
2002-07-16 3:54 ` Joern Rennecke
2002-07-16 5:46 ` kaz Kojima
2002-07-13 16:27 ` Tom Tromey
2002-07-13 16:28 ` kaz Kojima
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).