Land jsctypes. b=513783, r=jorendorff, sr=bsmedberg.

This commit is contained in:
Dan Witte
2009-09-23 10:57:22 -07:00
parent 14104ccbc1
commit 2f9b51d42e
269 changed files with 112048 additions and 12 deletions

View File

@@ -182,6 +182,7 @@
@BINPATH@/components/inspector.xpt
@BINPATH@/components/intl.xpt
@BINPATH@/components/jar.xpt
@BINPATH@/components/jsctypes.xpt
@BINPATH@/components/jsdservice.xpt
@BINPATH@/components/layout_base.xpt
#ifdef NS_PRINTING

38
client.py Normal file → Executable file
View File

@@ -1,10 +1,14 @@
#!/usr/bin/python
NSPR_DIRS = ('nsprpub',)
NSS_DIRS = ('dbm',
'security/nss',
'security/coreconf',
'security/dbm')
NSPR_DIRS = (('nsprpub', 'mozilla/nsprpub'),)
NSS_DIRS = (('dbm', 'mozilla/dbm'),
('security/nss', 'mozilla/security/nss'),
('security/coreconf', 'mozilla/security/coreconf'),
('security/dbm', 'mozilla/security/dbm'))
LIBFFI_DIRS = (('js/ctypes/libffi', 'libffi'),)
CVSROOT_MOZILLA = ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'
CVSROOT_LIBFFI = ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
import os
import sys
@@ -37,9 +41,12 @@ def do_hg_pull(dir, repository, hg):
def do_cvs_export(modules, tag, cvsroot, cvs):
"""Check out a CVS directory without CVS metadata, using "export"
modules is a list of directories to check out, e.g. ['nsprpub']
modules is a list of directories to check out and the corresponding
cvs module, e.g. (('nsprpub', 'mozilla/nsprpub'))
"""
for module in modules:
for module_tuple in modules:
module = module_tuple[0]
cvs_module = module_tuple[1]
fullpath = os.path.join(topsrcdir, module)
if os.path.exists(fullpath):
print "Removing '%s'" % fullpath
@@ -48,12 +55,11 @@ def do_cvs_export(modules, tag, cvsroot, cvs):
(parent, leaf) = os.path.split(module)
print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
check_call_noisy([cvs, '-d', cvsroot,
'export', '-r', tag, '-d', leaf,
'mozilla/%s' % module],
'export', '-r', tag, '-d', leaf, cvs_module],
cwd=os.path.join(topsrcdir, parent))
print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname")
o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname")
o.add_option("--skip-mozilla", dest="skip_mozilla",
action="store_true", default=False,
help="Obsolete")
@@ -61,8 +67,7 @@ o.add_option("--skip-mozilla", dest="skip_mozilla",
o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
help="The location of the cvs binary")
o.add_option("--cvsroot", dest="cvsroot",
default=os.environ.get('CVSROOT', ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'),
help="The CVSROOT (default: :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot")
help="The CVSROOT (default for mozilla checkouts: %s)" % CVSROOT_MOZILLA)
try:
options, args = o.parse_args()
@@ -76,10 +81,19 @@ if action in ('checkout', 'co'):
pass
elif action in ('update_nspr'):
tag, = args[1:]
if not options.cvsroot:
options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
do_cvs_export(NSPR_DIRS, tag, options.cvsroot, options.cvs)
elif action in ('update_nss'):
tag, = args[1:]
if not options.cvsroot:
options.cvsroot = os.environ.get('CVSROOT', CVSROOT_MOZILLA)
do_cvs_export(NSS_DIRS, tag, options.cvsroot, options.cvs)
elif action in ('update_libffi'):
tag, = args[1:]
if not options.cvsroot:
options.cvsroot = CVSROOT_LIBFFI
do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
else:
o.print_help()
sys.exit(2)

View File

@@ -8228,6 +8228,14 @@ fi
AC_OUTPUT_SUBDIRS(js/src)
ac_configure_args="$_SUBDIR_CONFIG_ARGS"
# Run the libffi 'configure' script.
ac_configure_args="--disable-shared --enable-static --with-pic --disable-raw-api"
if test "$MOZ_DEBUG"; then
ac_configure_args="$ac_configure_args --enable-debug"
fi
AC_OUTPUT_SUBDIRS(js/ctypes/libffi)
ac_configure_args="$_SUBDIR_CONFIG_ARGS"
fi # COMPILE_ENVIRONMENT && !LIBXUL_SDK_DIR
dnl Prevent the regeneration of autoconf.mk forcing rebuilds of the world

86
js/ctypes/Makefile.in Normal file
View File

@@ -0,0 +1,86 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is js-ctypes.
#
# The Initial Developer of the Original Code is
# The Mozilla Foundation <http://www.mozilla.org/>.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Finkle <mark.finkle@gmail.com>, <mfinkle@mozilla.com>
# Dan Witte <dwitte@mozilla.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = jsctypes
XPIDL_MODULE = jsctypes
MODULE_NAME = jsctypes
LIBRARY_NAME = jsctypes
GRE_MODULE = 1
LIBXUL_LIBRARY = 1
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
XPIDLSRCS = \
nsINativeTypes.idl \
$(NULL)
LOCAL_INCLUDES = \
-Ilibffi/include \
$(NULL)
CPPSRCS = \
nsNativeMethod.cpp \
nsNativeTypes.cpp \
nsNativeModule.cpp \
$(NULL)
EXTRA_JS_MODULES = \
ctypes.jsm \
$(NULL)
SHARED_LIBRARY_LIBS = \
libffi/.libs/$(LIB_PREFIX)ffi.$(LIB_SUFFIX) \
$(NULL)
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_JS_LIBS) \
$(NULL)
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

63
js/ctypes/ctypes.jsm Normal file
View File

@@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is js-ctypes.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation <http://www.mozilla.org/>.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dan Witte <dwitte@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
let EXPORTED_SYMBOLS = [ "ctypes" ];
const Cc = Components.classes;
const Ci = Components.interfaces;
let ctypes = {
types: Ci.nsINativeTypes,
open: function(name) {
let library = Cc["@mozilla.org/jsctypes;1"]
.createInstance(Ci.nsINativeTypes);
let file;
if (name instanceof Ci.nsILocalFile) {
file = name;
} else {
file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(name);
}
library.open(file);
return library;
}
};

3257
js/ctypes/libffi/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,385 @@
2008-12-19 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.8.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-11-11 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.7.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-08-25 Andreas Tobler <a.tobler@schweiz.org>
* src/powerpc/ffitarget.h (ffi_abi): Add FFI_LINUX and
FFI_LINUX_SOFT_FLOAT to the POWERPC_FREEBSD enum.
Add note about flag bits used for FFI_SYSV_TYPE_SMALL_STRUCT.
Adjust copyright notice.
* src/powerpc/ffi.c: Add two new flags to indicate if we have one
register or two register to use for FFI_SYSV structs.
(ffi_prep_cif_machdep): Pass the right register flag introduced above.
(ffi_closure_helper_SYSV): Fix the return type for
FFI_SYSV_TYPE_SMALL_STRUCT. Comment.
Adjust copyright notice.
2008-07-24 Anthony Green <green@redhat.com>
* testsuite/libffi.call/cls_dbls_struct.c,
testsuite/libffi.call/cls_double_va.c,
testsuite/libffi.call/cls_longdouble.c,
testsuite/libffi.call/cls_longdouble_va.c,
testsuite/libffi.call/cls_pointer.c,
testsuite/libffi.call/cls_pointer_stack.c,
testsuite/libffi.call/err_bad_abi.c: Clean up failures from
compiler warnings.
2008-07-17 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.6.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision. Add documentation.
* README: Update for new release.
2008-07-16 Kaz Kojima <kkojima@gcc.gnu.org>
* src/sh/ffi.c (ffi_prep_closure_loc): Turn INSN into an unsigned
int.
2008-07-16 Kaz Kojima <kkojima@gcc.gnu.org>
* src/sh/sysv.S: Add .note.GNU-stack on Linux.
* src/sh64/sysv.S: Likewise.
2008-04-03 Anthony Green <green@redhat.com>
* libffi.pc.in (Libs): Add -L${libdir}.
* configure.ac: Bump version to 3.0.5.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-04-03 Anthony Green <green@redhat.com>
Xerces Ranby <xerxes@zafena.se>
* include/ffi.h.in: Wrap definition of target architecture to
protect from double definitions.
2008-03-22 Moriyoshi Koizumi <moriyoshi@gmail.com>
* src/x86/ffi.c (ffi_prep_closure_loc): Fix for bug revealed in
closure_loc_fn0.c.
* testsuite/libffi.call/closure_loc_fn0.c (closure_loc_test_fn0):
New test.
2008-03-04 Anthony Green <green@redhat.com>
Blake Chaffin
hos@tamanegi.org
* testsuite/libffi.call/cls_align_longdouble_split2.c
testsuite/libffi.call/cls_align_longdouble_split.c
testsuite/libffi.call/cls_dbls_struct.c
testsuite/libffi.call/cls_double_va.c
testsuite/libffi.call/cls_longdouble.c
testsuite/libffi.call/cls_longdouble_va.c
testsuite/libffi.call/cls_pointer.c
testsuite/libffi.call/cls_pointer_stack.c
testsuite/libffi.call/err_bad_abi.c
testsuite/libffi.call/err_bad_typedef.c
testsuite/libffi.call/huge_struct.c
testsuite/libffi.call/stret_large2.c
testsuite/libffi.call/stret_large.c
testsuite/libffi.call/stret_medium2.c
testsuite/libffi.call/stret_medium.c: New tests from Apple.
2008-02-26 Jakub Jelinek <jakub@redhat.com>
Anthony Green <green@redhat.com>
* src/alpha/osf.S: Add .note.GNU-stack on Linux.
* src/s390/sysv.S: Likewise.
* src/powerpc/linux64.S: Likewise.
* src/powerpc/linux64_closure.S: Likewise.
* src/powerpc/ppc_closure.S: Likewise.
* src/powerpc/sysv.S: Likewise.
* src/x86/unix64.S: Likewise.
* src/x86/sysv.S: Likewise.
* src/sparc/v8.S: Likewise.
* src/sparc/v9.S: Likewise.
* src/m68k/sysv.S: Likewise.
* src/ia64/unix.S: Likewise.
* src/arm/sysv.S: Likewise.
2008-02-26 Anthony Green <green@redhat.com>
Thomas Heller <theller@ctypes.org>
* src/x86/ffi.c (ffi_closure_SYSV_inner): Change C++ comment to C
comment.
2008-02-26 Anthony Green <green@redhat.org>
Thomas Heller <theller@ctypes.org>
* include/ffi.h.in: Change void (*)() to void (*)(void).
2008-02-26 Anthony Green <green@redhat.org>
Thomas Heller <theller@ctypes.org>
* src/alpha/ffi.c: Change void (*)() to void (*)(void).
src/alpha/osf.S, src/arm/ffi.c, src/frv/ffi.c, src/ia64/ffi.c,
src/ia64/unix.S, src/java_raw_api.c, src/m32r/ffi.c,
src/mips/ffi.c, src/pa/ffi.c, src/pa/hpux32.S, src/pa/linux.S,
src/powerpc/ffi.c, src/powerpc/ffi_darwin.c, src/raw_api.c,
src/s390/ffi.c, src/sh/ffi.c, src/sh64/ffi.c, src/sparc/ffi.c,
src/x86/ffi.c, src/x86/unix64.S, src/x86/darwin64.S,
src/x86/ffi64.c: Ditto.
2008-02-24 Anthony Green <green@redhat.org>
* configure.ac: Accept openbsd*, not just openbsd.
Bump version to 3.0.4.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-02-22 Anthony Green <green@redhat.com>
* README: Clean up list of tested platforms.
2008-02-22 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.3.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release. Clean up test docs.
2008-02-22 Bjoern Koenig <bkoenig@alpha-tierchen.de>
Andreas Tobler <a.tobler@schweiz.org>
* configure.ac: Add amd64-*-freebsd* target.
* configure: Regenerate.
2008-02-22 Thomas Heller <theller@ctypes.org>
* configure.ac: Add x86 OpenBSD support.
* configure: Rebuilt.
2008-02-21 Thomas Heller <theller@ctypes.org>
* README: Change "make test" to "make check".
2008-02-21 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.2.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-02-21 Björn König <bkoenig@alpha-tierchen.de>
* src/x86/freebsd.S: New file.
* configure.ac: Add x86 FreeBSD support.
* Makefile.am: Ditto.
2008-02-15 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.1.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* libtool-version: Increment revision.
* README: Update for new release.
2008-02-15 David Daney <ddaney@avtrex.com>
* src/mips/ffi.c: Remove extra '>' from include directive.
(ffi_prep_closure_loc): Use clear_location instead of tramp.
2008-02-15 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 3.0.0.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
2008-02-15 David Daney <ddaney@avtrex.com>
* src/mips/ffi.c (USE__BUILTIN___CLEAR_CACHE):
Define (conditionally), and use it to include cachectl.h.
(ffi_prep_closure_loc): Fix cache flushing.
* src/mips/ffitarget.h (_ABIN32, _ABI64, _ABIO32): Define.
2008-02-15 Anthony Green <green@redhat.com>
* man/ffi_call.3, man/ffi_prep_cif.3, man/ffi.3:
Update dates and remove all references to ffi_prep_closure.
* configure.ac: Bump version to 2.99.9.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
2008-02-15 Anthony Green <green@redhat.com>
* man/ffi_prep_closure.3: Delete.
* man/Makefile.am (EXTRA_DIST): Remove ffi_prep_closure.3.
(man_MANS): Ditto.
* man/Makefile.in: Rebuilt.
* configure.ac: Bump version to 2.99.8.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 2.99.7.
* configure, doc/stamp-vti, doc/version.texi: Rebuilt.
* include/ffi.h.in LICENSE src/debug.c src/closures.c
src/ffitest.c src/s390/sysv.S src/s390/ffitarget.h
src/types.c src/m68k/ffitarget.h src/raw_api.c src/frv/ffi.c
src/frv/ffitarget.h src/sh/ffi.c src/sh/sysv.S
src/sh/ffitarget.h src/powerpc/ffitarget.h src/pa/ffi.c
src/pa/ffitarget.h src/pa/linux.S src/java_raw_api.c
src/cris/ffitarget.h src/x86/ffi.c src/x86/sysv.S
src/x86/unix64.S src/x86/win32.S src/x86/ffitarget.h
src/x86/ffi64.c src/x86/darwin.S src/ia64/ffi.c
src/ia64/ffitarget.h src/ia64/ia64_flags.h src/ia64/unix.S
src/sparc/ffi.c src/sparc/v9.S src/sparc/ffitarget.h
src/sparc/v8.S src/alpha/ffi.c src/alpha/ffitarget.h
src/alpha/osf.S src/sh64/ffi.c src/sh64/sysv.S
src/sh64/ffitarget.h src/mips/ffi.c src/mips/ffitarget.h
src/mips/n32.S src/mips/o32.S src/arm/ffi.c src/arm/sysv.S
src/arm/ffitarget.h src/prep_cif.c: Update license text.
2008-02-14 Anthony Green <green@redhat.com>
* README: Update tested platforms.
* configure.ac: Bump version to 2.99.6.
* configure: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* configure.ac: Bump version to 2.99.5.
* configure: Rebuilt.
* Makefile.am (EXTRA_DIST): Add darwin64.S
* Makefile.in: Rebuilt.
* testsuite/lib/libffi-dg.exp: Remove libstdc++ bits from GCC tree.
* LICENSE: Update WARRANTY.
2008-02-14 Anthony Green <green@redhat.com>
* libffi.pc.in (libdir): Fix libdir definition.
* configure.ac: Bump version to 2.99.4.
* configure: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* README: Update.
* libffi.info: New file.
* doc/stamp-vti: New file.
* configure.ac: Bump version to 2.99.3.
* configure: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* Makefile.am (SUBDIRS): Add man dir.
* Makefile.in: Rebuilt.
* configure.ac: Create Makefile.
* configure: Rebuilt.
* man/ffi_call.3 man/ffi_prep_cif.3 man/ffi_prep_closure.3
man/Makefile.am man/Makefile.in: New files.
2008-02-14 Tom Tromey <tromey@redhat.com>
* aclocal.m4, Makefile.in, configure, fficonfig.h.in: Rebuilt.
* mdate-sh, texinfo.tex: New files.
* Makefile.am (info_TEXINFOS): New variable.
* doc/libffi.texi: New file.
* doc/version.texi: Likewise.
2008-02-14 Anthony Green <green@redhat.com>
* Makefile.am (AM_CFLAGS): Don't compile with -D$(TARGET).
(lib_LTLIBRARIES): Define.
(toolexeclib_LIBRARIES): Undefine.
* Makefile.in: Rebuilt.
* configure.ac: Reset version to 2.99.1.
* configure.in: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* libffi.pc.in: Use @PACKAGE_NAME@ and @PACKAGE_VERSION@.
* configure.ac: Reset version to 2.99.1.
* configure.in: Rebuilt.
* Makefile.am (EXTRA_DIST): Add ChangeLog.libffi.
* Makefile.in: Rebuilt.
* LICENSE: Update copyright notice.
2008-02-14 Anthony Green <green@redhat.com>
* include/Makefile.am (nodist_includes_HEADERS): Define. Don't
distribute ffitarget.h or ffi.h from the build include dir.
* Makefile.in: Rebuilt.
2008-02-14 Anthony Green <green@redhat.com>
* include/Makefile.am (includesdir): Install headers under libdir.
(pkgconfigdir): Define. Install libffi.pc.
* include/Makefile.in: Rebuilt.
* libffi.pc.in: Create.
* libtool-version: Increment CURRENT
* configure.ac: Add libffi.pc.in
* configure: Rebuilt.
2008-02-03 Anthony Green <green@redhat.com>
* include/Makefile.am (includesdir): Fix header install with
DESTDIR.
* include/Makefile.in: Rebuilt.
2008-02-03 Timothy Wall <twall@users.sf.net>
* src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL): Calculate jump return
offset based on code pointer, not data pointer.
2008-02-01 Anthony Green <green@redhat.com>
* include/Makefile.am: Fix header installs.
* Makefile.am: Ditto.
* include/Makefile.in: Rebuilt.
* Makefile.in: Ditto.
2008-02-01 Anthony Green <green@redhat.com>
* src/x86/ffi.c (FFI_INIT_TRAMPOLINE_STDCALL,
FFI_INIT_TRAMPOLINE): Revert my broken changes to twall's last
patch.
2008-01-31 Anthony Green <green@redhat.com>
* Makefile.am (EXTRA_DIST): Add missing files.
* testsuite/Makefile.am: Ditto.
* Makefile.in, testsuite/Makefile.in: Rebuilt.
2008-01-31 Timothy Wall <twall@users.sf.net>
* testsuite/libffi.call/closure_stdcall.c: Add test for stdcall
closures.
* src/x86/ffitarget.h: Increase size of trampoline for stdcall
closures.
* src/x86/win32.S: Add assembly for stdcall closure.
* src/x86/ffi.c: Initialize stdcall closure trampoline.
2008-01-30 H.J. Lu <hongjiu.lu@intel.com>
PR libffi/34612
* src/x86/sysv.S (ffi_closure_SYSV): Pop 4 byte from stack when
returning struct.
* testsuite/libffi.call/call.exp: Add "-O2 -fomit-frame-pointer"
tests.
2008-01-30 Anthony Green <green@redhat.com>
* Makefile.am, include/Makefile.am: Move headers to
libffi_la_SOURCES for new automake.
* Makefile.in, include/Makefile.in: Rebuilt.
* testsuite/lib/wrapper.exp: Copied from gcc tree to allow for
execution outside of gcc tree.
* testsuite/lib/target-libpath.exp: Ditto.
* testsuite/lib/libffi-dg.exp: Many changes to allow for execution
outside of gcc tree.

View File

@@ -0,0 +1,40 @@
2004-01-14 Kelley Cook <kcook@gcc.gnu.org>
* configure.in: Add in AC_PREREQ(2.13)
2003-02-20 Alexandre Oliva <aoliva@redhat.com>
* configure.in: Propagate ORIGINAL_LD_FOR_MULTILIBS to
config.status.
* configure: Rebuilt.
2002-01-27 Alexandre Oliva <aoliva@redhat.com>
* configure.in (toolexecdir, toolexeclibdir): Set and AC_SUBST.
Remove USE_LIBDIR conditional.
* Makefile.am (toolexecdir, toolexeclibdir): Don't override.
* Makefile.in, configure: Rebuilt.
Mon Aug 9 18:33:38 1999 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
* include/Makefile.in: Rebuilt.
* Makefile.in: Rebuilt
* Makefile.am (toolexeclibdir): Add $(MULTISUBDIR) even for native
builds.
Use USE_LIBDIR.
* configure: Rebuilt.
* configure.in (USE_LIBDIR): Define for native builds.
Use lowercase in configure --help explanations.
1999-08-08 Anthony Green <green@cygnus.com>
* include/ffi.h.in (FFI_FN): Remove `...'.
1999-08-08 Anthony Green <green@cygnus.com>
* Makefile.in: Rebuilt.
* Makefile.am (AM_CFLAGS): Compile with -fexceptions.
* src/x86/sysv.S: Add exception handling metadata.

View File

@@ -0,0 +1,764 @@
The libffi version 1 ChangeLog archive.
Version 1 of libffi had per-directory ChangeLogs. Current and future
versions have a single ChangeLog file in the root directory. The
version 1 ChangeLogs have all been concatonated into this file for
future reference only.
--- libffi ----------------------------------------------------------------
Mon Oct 5 02:17:50 1998 Anthony Green <green@cygnus.com>
* configure.in: Boosted rev.
* configure, Makefile.in, aclocal.m4: Rebuilt.
* README: Boosted rev and updated release notes.
Mon Oct 5 01:03:03 1998 Anthony Green <green@cygnus.com>
* configure.in: Boosted rev.
* configure, Makefile.in, aclocal.m4: Rebuilt.
* README: Boosted rev and updated release notes.
1998-07-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* m68k/ffi.c (ffi_prep_cif_machdep): Use bitmask for cif->flags.
Correctly handle small structures.
(ffi_prep_args): Also handle small structures.
(ffi_call): Pass size of return type to ffi_call_SYSV.
* m68k/sysv.S: Adjust for above changes. Correctly align small
structures in the return value.
* types.c (uint64, sint64) [M68K]: Change alignment to 4.
Fri Apr 17 17:26:58 1998 Anthony Green <green@hoser.cygnus.com>
* configure.in: Boosted rev.
* configure,Makefile.in,aclocal.m4: Rebuilt.
* README: Boosted rev and added release notes.
Sun Feb 22 00:50:41 1998 Geoff Keating <geoffk@ozemail.com.au>
* configure.in: Add PowerPC config bits.
1998-02-14 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* configure.in: Add m68k config bits. Change AC_CANONICAL_SYSTEM
to AC_CANONICAL_HOST, this is not a compiler. Use $host instead
of $target. Remove AC_CHECK_SIZEOF(char), we already know the
result. Fix argument of AC_ARG_ENABLE.
* configure, fficonfig.h.in: Rebuilt.
Tue Feb 10 20:53:40 1998 Richard Henderson <rth@cygnus.com>
* configure.in: Add Alpha config bits.
Tue May 13 13:39:20 1997 Anthony Green <green@hoser.cygnus.com>
* README: Updated dates and reworded Irix comments.
* configure.in: Removed AC_PROG_RANLIB.
* Makefile.in, aclocal.m4, config.guess, config.sub, configure,
ltmain.sh, */Makefile.in: libtoolized again and rebuilt with
automake and autoconf.
Sat May 10 18:44:50 1997 Tom Tromey <tromey@cygnus.com>
* configure, aclocal.m4: Rebuilt.
* configure.in: Don't compute EXTRADIST; now handled in
src/Makefile.in. Removed macros implied by AM_INIT_AUTOMAKE.
Don't run AM_MAINTAINER_MODE.
Thu May 8 14:34:05 1997 Anthony Green <green@hoser.cygnus.com>
* missing, ltmain.sh, ltconfig.sh: Created. These are new files
required by automake and libtool.
* README: Boosted rev to 1.14. Added notes.
* acconfig.h: Moved PACKAGE and VERSION for new automake.
* configure.in: Changes for libtool.
* Makefile.am (check): make test now make check. Uses libtool now.
* Makefile.in, configure.in, aclocal.h, fficonfig.h.in: Rebuilt.
Thu May 1 16:27:07 1997 Anthony Green <green@hoser.cygnus.com>
* missing: Added file required by new automake.
Tue Nov 26 14:10:42 1996 Anthony Green <green@csk3.cygnus.com>
* acconfig.h: Added USING_PURIFY flag. This is defined when
--enable-purify-safety was used at configure time.
* configure.in (allsources): Added --enable-purify-safety switch.
(VERSION): Boosted rev to 1.13.
* configure: Rebuilt.
Fri Nov 22 06:46:12 1996 Anthony Green <green@rtl.cygnus.com>
* configure.in (VERSION): Boosted rev to 1.12.
Removed special CFLAGS hack for gcc.
* configure: Rebuilt.
* README: Boosted rev to 1.12. Added notes.
* Many files: Cygnus Support changed to Cygnus Solutions.
Wed Oct 30 11:15:25 1996 Anthony Green <green@rtl.cygnus.com>
* configure.in (VERSION): Boosted rev to 1.11.
* configure: Rebuilt.
* README: Boosted rev to 1.11. Added notes about GNU make.
Tue Oct 29 12:25:12 1996 Anthony Green <green@rtl.cygnus.com>
* configure.in: Fixed -Wall trick.
(VERSION): Boosted rev.
* configure: Rebuilt
* acconfig.h: Needed for --enable-debug configure switch.
* README: Boosted rev to 1.09. Added more notes on building
libffi, and LCLint.
* configure.in: Added --enable-debug switch. Boosted rev to
1.09.
* configure: Rebuilt
Tue Oct 15 13:11:28 1996 Anthony Green <green@hoser.cygnus.com>
* configure.in (VERSION): Boosted rev to 1.08
* configure: Rebuilt.
* README: Added n32 bug fix notes.
* Makefile.am: Added "make lint" production.
* Makefile.in: Rebuilt.
Mon Oct 14 10:54:46 1996 Anthony Green <green@rtl.cygnus.com>
* README: Added web page reference.
* configure.in, README: Boosted rev to 1.05
* configure: Rebuilt.
* README: Fixed n32 sample code.
Fri Oct 11 17:09:28 1996 Anthony Green <green@rtl.cygnus.com>
* README: Added sparc notes.
* configure.in, README: Boosted rev to 1.04.
* configure: Rebuilt.
Thu Oct 10 10:31:03 1996 Anthony Green <green@rtl.cygnus.com>
* configure.in, README: Boosted rev to 1.03.
* configure: Rebuilt.
* README: Added struct notes.
* Makefile.am (EXTRA_DIST): Added LICENSE to distribution.
* Makefile.in: Rebuilt.
* README: Removed Linux section. No special notes now
because aggregates arg/return types work.
Wed Oct 9 16:16:42 1996 Anthony Green <green@rtl.cygnus.com>
* README, configure.in (VERSION): Boosted rev to 1.02
* configure: Rebuilt.
Tue Oct 8 11:56:33 1996 Anthony Green <green@rtl.cygnus.com>
* README (NOTE): Added n32 notes.
* Makefile.am: Added test production.
* Makefile: Rebuilt
* README: spell checked!
* configure.in (VERSION): Boosted rev to 1.01
* configure: Rebuilt.
Mon Oct 7 15:50:22 1996 Anthony Green <green@rtl.cygnus.com>
* configure.in: Added nasty bit to support SGI tools.
* configure: Rebuilt.
* README: Added SGI notes. Added note about automake bug.
Mon Oct 7 11:00:28 1996 Anthony Green <green@hoser.cygnus.com>
* README: Rewrote intro, and fixed examples.
Fri Oct 4 10:19:55 1996 Anthony Green <green@hoser.cygnus.com>
* configure.in: -D$TARGET is no longer used as a compiler switch.
It is now inserted into ffi.h at configure time.
* configure: Rebuilt.
* FFI_ABI and FFI_STATUS are now ffi_abi and ffi_status.
Thu Oct 3 13:47:34 1996 Anthony Green <green@hoser.cygnus.com>
* README, LICENSE: Created. Wrote some docs.
* configure.in: Don't barf on i586-unknown-linuxaout.
Added EXTRADIST code for "make dist".
* configure: Rebuilt.
* */Makefile.in: Rebuilt with patched automake.
Tue Oct 1 17:12:25 1996 Anthony Green <green@rtl.cygnus.com>
* Makefile.am, aclocal.m4, config.guess, config.sub,
configure.in, fficonfig.h.in, install-sh, mkinstalldirs,
stamp-h.in: Created
* Makefile.in, configure: Generated
--- libffi/include --------------------------------------------------------
Tue Feb 24 13:09:36 1998 Anthony Green <green@gerbil.cygnus.com>
* ffi_mips.h: Updated FFI_TYPE_STRUCT_* values based on
ffi.h.in changes. This is a work-around for SGI's "simple"
assembler.
Sun Feb 22 00:51:55 1998 Geoff Keating <geoffk@ozemail.com.au>
* ffi.h.in: PowerPC support.
1998-02-14 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* ffi.h.in: Add m68k support.
(FFI_TYPE_LONGDOUBLE): Make it a separate value.
Tue Feb 10 20:55:16 1998 Richard Henderson <rth@cygnus.com>
* ffi.h.in (SIZEOF_ARG): Use a pointer type by default.
* ffi.h.in: Alpha support.
Fri Nov 22 06:48:45 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in, ffi_common.h: Cygnus Support -> Cygnus Solutions.
Wed Nov 20 22:31:01 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.h.in: Added ffi_type_void definition.
Tue Oct 29 12:22:40 1996 Anthony Green <green@rtl.cygnus.com>
* Makefile.am (hack_DATA): Always install ffi_mips.h.
* ffi.h.in: Removed FFI_DEBUG. It's now in the correct
place (acconfig.h).
Added #include <stddef.h> for size_t definition.
Tue Oct 15 17:23:35 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.h.in, ffi_common.h, ffi_mips.h: More clean up.
Commented out #define of FFI_DEBUG.
Tue Oct 15 13:01:06 1996 Anthony Green <green@rtl.cygnus.com>
* ffi_common.h: Added bool definition.
* ffi.h.in, ffi_common.h: Clean up based on LCLint output.
Added funny /*@...@*/ comments to annotate source.
Mon Oct 14 12:29:23 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in: Interface changes based on feedback from Jim
Blandy.
Fri Oct 11 16:49:35 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in: Small change for sparc support.
Thu Oct 10 14:53:37 1996 Anthony Green <green@rtl.cygnus.com>
* ffi_mips.h: Added FFI_TYPE_STRUCT_* definitions for
special structure return types.
Wed Oct 9 13:55:57 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in: Added SIZEOF_ARG definition for X86
Tue Oct 8 11:40:36 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in (FFI_FN): Added macro for eliminating compiler warnings.
Use it to case your function pointers to the proper type.
* ffi_mips.h (SIZEOF_ARG): Added magic to fix type promotion bug.
* Makefile.am (EXTRA_DIST): Added ffi_mips.h to EXTRA_DIST.
* Makefile: Rebuilt.
* ffi_mips.h: Created. Moved all common mips definitions here.
Mon Oct 7 10:58:12 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.h.in: The SGI assember is very picky about parens. Redefined
some macros to avoid problems.
* ffi.h.in: Added FFI_DEFAULT_ABI definitions. Also added
externs for pointer, and 64bit integral ffi_types.
Fri Oct 4 09:51:37 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.h.in: Added FFI_ABI member to ffi_cif and changed
function prototypes accordingly.
Added #define @TARGET@. Now programs including ffi.h don't
have to specify this themselves.
Thu Oct 3 15:36:44 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.h.in: Changed ffi_prep_cif's values from void* to void**
* Makefile.am (EXTRA_DIST): Added EXTRA_DIST for "make dist"
to work.
* Makefile.in: Regenerated.
Wed Oct 2 10:16:59 1996 Anthony Green <green@hoser.cygnus.com>
* Makefile.am: Created
* Makefile.in: Generated
* ffi_common.h: Added rcsid comment
Tue Oct 1 17:13:51 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.h.in, ffi_common.h: Created
--- libffi/src ------------------------------------------------------------
Mon Oct 5 02:17:50 1998 Anthony Green <green@cygnus.com>
* arm/ffi.c, arm/sysv.S: Created.
* Makefile.am: Added arm files.
* Makefile.in: Rebuilt.
Mon Oct 5 01:41:38 1998 Anthony Green <green@rtl.cygnus.com>
* Makefile.am (libffi_la_LDFLAGS): Incremented revision.
Sun Oct 4 16:27:17 1998 Anthony Green <green@cygnus.com>
* alpha/osf.S (ffi_call_osf): Patch for DU assembler.
* ffitest.c (main): long long and long double return values work
for x86.
Fri Apr 17 11:50:58 1998 Anthony Green <green@hoser.cygnus.com>
* Makefile.in: Rebuilt.
* ffitest.c (main): Floating point tests not executed for systems
with broken lond double (SunOS 4 w/ GCC).
* types.c: Fixed x86 alignment info for long long types.
Thu Apr 16 07:15:28 1998 Anthony Green <green@ada.cygnus.com>
* ffitest.c: Added more notes about GCC bugs under Irix 6.
Wed Apr 15 08:42:22 1998 Anthony Green <green@hoser.cygnus.com>
* ffitest.c (struct5): New test function.
(main): New test with struct5.
Thu Mar 5 10:48:11 1998 Anthony Green <green@tootie.to.cygnus.com>
* prep_cif.c (initialize_aggregate): Fix assertion for
nested structures.
Tue Feb 24 16:33:41 1998 Anthony Green <green@hoser.cygnus.com>
* prep_cif.c (ffi_prep_cif): Added long double support for sparc.
Sun Feb 22 00:52:18 1998 Geoff Keating <geoffk@ozemail.com.au>
* powerpc/asm.h: New file.
* powerpc/ffi.c: New file.
* powerpc/sysv.S: New file.
* Makefile.am: PowerPC port.
* ffitest.c (main): Allow all tests to run even in presence of gcc
bug on PowerPC.
1998-02-17 Anthony Green <green@hoser.cygnus.com>
* mips/ffi.c: Fixed comment typo.
* x86/ffi.c (ffi_prep_cif_machdep), x86/sysv.S (retfloat):
Fixed x86 long double return handling.
* types.c: Fixed x86 long double alignment info.
1998-02-14 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* types.c: Add m68k support.
* ffitest.c (floating): Add long double parameter.
(return_ll, ldblit): New functions to test long long and long
double return value.
(main): Fix type error in assignment of ts[1-4]_type.elements.
Add tests for long long and long double arguments and return
values.
* prep_cif.c (ffi_prep_cif) [M68K]: Don't allocate argument for
struct value pointer.
* m68k/ffi.c, m68k/sysv.S: New files.
* Makefile.am: Add bits for m68k port. Add kludge to work around
automake deficiency.
(test): Don't require "." in $PATH.
* Makefile.in: Rebuilt.
Wed Feb 11 07:36:50 1998 Anthony Green <green@hoser.cygnus.com>
* Makefile.in: Rebuilt.
Tue Feb 10 20:56:00 1998 Richard Henderson <rth@cygnus.com>
* alpha/ffi.c, alpha/osf.S: New files.
* Makefile.am: Alpha port.
Tue Nov 18 14:12:07 1997 Anthony Green <green@hoser.cygnus.com>
* mips/ffi.c (ffi_prep_cif_machdep): Initialize rstruct_flag
for n32.
Tue Jun 3 17:18:20 1997 Anthony Green <green@hoser.cygnus.com>
* ffitest.c (main): Added hack to get structure tests working
correctly.
Sat May 10 19:06:42 1997 Tom Tromey <tromey@cygnus.com>
* Makefile.in: Rebuilt.
* Makefile.am (EXTRA_DIST): Explicitly list all distributable
files in subdirs.
(VERSION, CC): Removed.
Thu May 8 17:19:01 1997 Anthony Green <green@hoser.cygnus.com>
* Makefile.am: Many changes for new automake and libtool.
* Makefile.in: Rebuilt.
Fri Nov 22 06:57:56 1996 Anthony Green <green@rtl.cygnus.com>
* ffitest.c (main): Fixed test case for non mips machines.
Wed Nov 20 22:31:59 1996 Anthony Green <green@hoser.cygnus.com>
* types.c: Added ffi_type_void declaration.
Tue Oct 29 13:07:19 1996 Anthony Green <green@rtl.cygnus.com>
* ffitest.c (main): Fixed character constants.
(main): Emit warning for structure test 3 failure on Sun.
* Makefile.am (VPATH): Fixed VPATH def'n so automake won't
strip it out.
Moved distdir hack from libffi to automake.
(ffitest): Added missing -c for $(COMPILE) (change in automake).
* Makefile.in: Rebuilt.
Tue Oct 15 13:08:20 1996 Anthony Green <green@hoser.cygnus.com>
* Makefile.am: Added "make lint" production.
* Makefile.in: Rebuilt.
* prep_cif.c (STACK_ARG_SIZE): Improved STACK_ARG_SIZE macro.
Clean up based on LCLint output. Added funny /*@...@*/ comments to
annotate source.
* ffitest.c, debug.c: Cleaned up code.
Mon Oct 14 12:26:56 1996 Anthony Green <green@rtl.cygnus.com>
* ffitest.c: Changes based on interface changes.
* prep_cif.c (ffi_prep_cif): Cleaned up interface based on
feedback from Jim Blandy.
Fri Oct 11 15:53:18 1996 Anthony Green <green@rtl.cygnus.com>
* ffitest.c: Reordered tests while porting to sparc.
Made changes to handle lame structure passing for sparc.
Removed calls to fflush().
* prep_cif.c (ffi_prep_cif): Added special case for sparc
aggregate type arguments.
Thu Oct 10 09:56:51 1996 Anthony Green <green@rtl.cygnus.com>
* ffitest.c (main): Added structure passing/returning tests.
* prep_cif.c (ffi_prep_cif): Perform proper initialization
of structure return types if needed.
(initialize_aggregate): Bug fix
Wed Oct 9 16:04:20 1996 Anthony Green <green@rtl.cygnus.com>
* types.c: Added special definitions for x86 (double doesn't
need double word alignment).
* ffitest.c: Added many tests
Tue Oct 8 09:19:22 1996 Anthony Green <green@rtl.cygnus.com>
* prep_cif.c (ffi_prep_cif): Fixed assertion.
* debug.c (ffi_assert): Must return a non void now.
* Makefile.am: Added test production.
* Makefile: Rebuilt.
* ffitest.c (main): Created.
* types.c: Created. Stripped common code out of */ffi.c.
* prep_cif.c: Added missing stdlib.h include.
* debug.c (ffi_type_test): Used "a" to eliminate compiler
warnings in non-debug builds. Included ffi_common.h.
Mon Oct 7 15:36:42 1996 Anthony Green <green@rtl.cygnus.com>
* Makefile.am: Added a rule for .s -> .o
This is required by the SGI compiler.
* Makefile: Rebuilt.
Fri Oct 4 09:51:08 1996 Anthony Green <green@hoser.cygnus.com>
* prep_cif.c (initialize_aggregate): Moved abi specification
to ffi_prep_cif().
Thu Oct 3 15:37:37 1996 Anthony Green <green@hoser.cygnus.com>
* prep_cif.c (ffi_prep_cif): Changed values from void* to void**.
(initialize_aggregate): Fixed aggregate type initialization.
* Makefile.am (EXTRA_DIST): Added support code for "make dist".
* Makefile.in: Regenerated.
Wed Oct 2 11:41:57 1996 Anthony Green <green@hoser.cygnus.com>
* debug.c, prep_cif: Created.
* Makefile.am: Added debug.o and prep_cif.o to OBJ.
* Makefile.in: Regenerated.
* Makefile.am (INCLUDES): Added missing -I../include
* Makefile.in: Regenerated.
Tue Oct 1 17:11:51 1996 Anthony Green <green@rtl.cygnus.com>
* error.c, Makefile.am: Created.
* Makefile.in: Generated.
--- libffi/src/x86 --------------------------------------------------------
Sun Oct 4 16:27:17 1998 Anthony Green <green@cygnus.com>
* sysv.S (retlongdouble): Fixed long long return value support.
* ffi.c (ffi_prep_cif_machdep): Ditto.
Wed May 13 04:30:33 1998 Anthony Green <green@raft.ppp.tsoft.net>
* ffi.c (ffi_prep_cif_machdep): Fixed long double return value
support.
Wed Apr 15 08:43:20 1998 Anthony Green <green@hoser.cygnus.com>
* ffi.c (ffi_prep_args): small struct support was missing.
Thu May 8 16:53:58 1997 Anthony Green <green@hoser.cygnus.com>
* objects.mak: Removed.
Mon Dec 2 15:12:58 1996 Tom Tromey <tromey@cygnus.com>
* sysv.S: Use .balign, for a.out Linux boxes.
Tue Oct 15 13:06:50 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.c: Clean up based on LCLint output.
Added funny /*@...@*/ comments to annotate source.
Fri Oct 11 16:43:38 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c (ffi_call): Added assertion for bad ABIs.
Wed Oct 9 13:57:27 1996 Anthony Green <green@rtl.cygnus.com>
* sysv.S (retdouble): Fixed double return problems.
* ffi.c (ffi_call): Corrected fn arg definition.
(ffi_prep_cif_machdep): Fixed double return problems
Tue Oct 8 12:12:49 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c: Moved ffi_type definitions to types.c.
(ffi_prep_args): Fixed type promotion bug.
Mon Oct 7 15:53:06 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c (FFI_*_TYPEDEF): Removed redundant ';'
Fri Oct 4 09:54:53 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.c (ffi_call): Removed FFI_ABI arg, and swapped
remaining args.
Wed Oct 2 10:07:05 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.c, sysv.S, objects.mak: Created.
(ffi_prep_cif): cif->rvalue no longer initialized to NULL.
(ffi_prep_cif_machdep): Moved machine independent cif processing
to src/prep_cif.c. Introduced ffi_prep_cif_machdep().
--- libffi/src/mips -------------------------------------------------------
Tue Feb 17 17:18:07 1998 Anthony Green <green@hoser.cygnus.com>
* o32.S: Fixed typo in comment.
* ffi.c (ffi_prep_cif_machdep): Fixed argument processing.
Thu May 8 16:53:58 1997 Anthony Green <green@hoser.cygnus.com>
* o32.s, n32.s: Wrappers for SGI tool support.
* objects.mak: Removed.
Tue Oct 29 14:37:45 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c (ffi_prep_args): Changed int z to size_t z.
Tue Oct 15 13:17:25 1996 Anthony Green <green@hoser.cygnus.com>
* n32.S: Fixed bad stack munging.
* ffi.c: Moved prototypes for ffi_call_?32() to here from
ffi_mips.h because extended_cif is not defined in ffi_mips.h.
Mon Oct 14 12:42:02 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c: Interface changes based on feedback from Jim Blandy.
Thu Oct 10 11:22:16 1996 Anthony Green <green@rtl.cygnus.com>
* n32.S, ffi.c: Lots of changes to support passing and
returning structures with the n32 calling convention.
* n32.S: Fixed fn pointer bug.
* ffi.c (ffi_prep_cif_machdep): Fix for o32 structure
return values.
(ffi_prep_args): Fixed n32 structure passing when structures
partially fit in registers.
Wed Oct 9 13:49:25 1996 Anthony Green <green@rtl.cygnus.com>
* objects.mak: Added n32.o.
* n32.S: Created.
* ffi.c (ffi_prep_args): Added magic to support proper
n32 processing.
Tue Oct 8 10:37:35 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c: Moved ffi_type definitions to types.c.
(ffi_prep_args): Fixed type promotion bug.
* o32.S: This code is only built for o32 compiles.
A lot of the #define cruft has moved to ffi_mips.h.
* ffi.c (ffi_prep_cif_machdep): Fixed arg flags. Second arg
is only processed if the first is either a float or double.
Mon Oct 7 15:33:59 1996 Anthony Green <green@rtl.cygnus.com>
* o32.S: Modified to compile under each of o32, n32 and n64.
* ffi.c (FFI_*_TYPEDEF): Removed redundant ';'
Fri Oct 4 09:53:25 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.c (ffi_call): Removed FFI_ABI arg, and swapped
remaining args.
Wed Oct 2 17:41:22 1996 Anthony Green <green@rtl.cygnus.com>
* o32.S: Removed crufty definitions.
Wed Oct 2 12:53:42 1996 Anthony Green <green@hoser.cygnus.com>
* ffi.c (ffi_prep_cif): cif->rvalue no longer initialized to NULL.
(ffi_prep_cif_machdep): Moved all machine independent cif processing
to src/prep_cif.c. Introduced ffi_prep_cif_machdep. Return types
of FFI_TYPE_STRUCT are no different than FFI_TYPE_INT.
Tue Oct 1 17:11:02 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c, o32.S, object.mak: Created
--- libffi/src/sparc ------------------------------------------------------
Tue Feb 24 16:33:18 1998 Anthony Green <green@hoser.cygnus.com>
* ffi.c (ffi_prep_args): Added long double support.
Thu May 8 16:53:58 1997 Anthony Green <green@hoser.cygnus.com>
* objects.mak: Removed.
Thu May 1 16:07:56 1997 Anthony Green <green@hoser.cygnus.com>
* v8.S: Fixed minor portability problem reported by
Russ McManus <mcmanr@eq.gs.com>.
Tue Nov 26 14:12:43 1996 Anthony Green <green@csk3.cygnus.com>
* v8.S: Used STACKFRAME define elsewhere.
* ffi.c (ffi_prep_args): Zero out space when USING_PURIFY
is set.
(ffi_prep_cif_machdep): Allocate the correct stack frame
space for functions with < 6 args.
Tue Oct 29 15:08:55 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c (ffi_prep_args): int z is now size_t z.
Mon Oct 14 13:31:24 1996 Anthony Green <green@rtl.cygnus.com>
* v8.S (ffi_call_V8): Gordon rewrites this again. It looks
great now.
* ffi.c (ffi_call): The comment about hijacked registers
is no longer valid after gordoni hacked v8.S.
* v8.S (ffi_call_V8): Rewrote with gordoni. Much simpler.
* v8.S, ffi.c: ffi_call() had changed to accept more than
two args, so v8.S had to change (because it hijacks incoming
arg registers).
* ffi.c: Interface changes based on feedback from Jim Blandy.
Thu Oct 10 17:48:16 1996 Anthony Green <green@rtl.cygnus.com>
* ffi.c, v8.S, objects.mak: Created.

21
js/ctypes/libffi/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
libffi - Copyright (c) 1996-2008 Red Hat, Inc and others.
See source files for details.
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 THE AUTHORS OR COPYRIGHT HOLDERS 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.

View File

@@ -0,0 +1,177 @@
## Process this with automake to create Makefile.in
AUTOMAKE_OPTIONS = foreign subdir-objects
SUBDIRS = include testsuite man
EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj configure.host \
src/alpha/ffi.c src/alpha/osf.S src/alpha/ffitarget.h \
src/arm/ffi.c src/arm/sysv.S src/arm/ffitarget.h \
src/cris/ffi.c src/cris/sysv.S src/cris/ffitarget.h \
src/ia64/ffi.c src/ia64/ffitarget.h src/ia64/ia64_flags.h \
src/ia64/unix.S \
src/mips/ffi.c src/mips/n32.S src/mips/o32.S \
src/mips/ffitarget.h \
src/m32r/ffi.c src/m32r/sysv.S src/m32r/ffitarget.h \
src/m68k/ffi.c src/m68k/sysv.S src/m68k/ffitarget.h \
src/powerpc/ffi.c src/powerpc/sysv.S \
src/powerpc/linux64.S src/powerpc/linux64_closure.S \
src/powerpc/ppc_closure.S src/powerpc/asm.h \
src/powerpc/aix.S src/powerpc/darwin.S \
src/powerpc/aix_closure.S src/powerpc/darwin_closure.S \
src/powerpc/ffi_darwin.c src/powerpc/ffitarget.h \
src/s390/ffi.c src/s390/sysv.S src/s390/ffitarget.h \
src/sh/ffi.c src/sh/sysv.S src/sh/ffitarget.h \
src/sh64/ffi.c src/sh64/sysv.S src/sh64/ffitarget.h \
src/sparc/v8.S src/sparc/v9.S src/sparc/ffitarget.h \
src/sparc/ffi.c src/x86/darwin64.S \
src/x86/ffi.c src/x86/sysv.S src/x86/win32.S src/x86/darwin.S \
src/x86/freebsd.S \
src/x86/ffi64.c src/x86/unix64.S src/x86/ffitarget.h \
src/pa/ffitarget.h src/pa/ffi.c src/pa/linux.S src/pa/hpux32.S \
src/frv/ffi.c src/frv/eabi.S src/frv/ffitarget.h src/dlmalloc.c \
libtool-version ChangeLog.libffi
info_TEXINFOS = doc/libffi.texi
## ################################################################
##
## This section is for make and multilib madness.
##
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# values defined in terms of make variables, as is the case for CC and
# friends when we are called from the top level Makefile.
AM_MAKEFLAGS = \
"AR_FLAGS=$(AR_FLAGS)" \
"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
"CFLAGS=$(CFLAGS)" \
"CXXFLAGS=$(CXXFLAGS)" \
"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
"INSTALL=$(INSTALL)" \
"INSTALL_DATA=$(INSTALL_DATA)" \
"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
"JC1FLAGS=$(JC1FLAGS)" \
"LDFLAGS=$(LDFLAGS)" \
"LIBCFLAGS=$(LIBCFLAGS)" \
"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
"MAKE=$(MAKE)" \
"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
"PICFLAG=$(PICFLAG)" \
"PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
"SHELL=$(SHELL)" \
"exec_prefix=$(exec_prefix)" \
"infodir=$(infodir)" \
"libdir=$(libdir)" \
"prefix=$(prefix)" \
"AR=$(AR)" \
"AS=$(AS)" \
"CC=$(CC)" \
"CXX=$(CXX)" \
"LD=$(LD)" \
"NM=$(NM)" \
"RANLIB=$(RANLIB)" \
"DESTDIR=$(DESTDIR)"
MAKEOVERRIDES=
lib_LTLIBRARIES = libffi.la
noinst_LTLIBRARIES = libffi_convenience.la
libffi_la_SOURCES = src/debug.c src/prep_cif.c src/types.c \
src/raw_api.c src/java_raw_api.c src/closures.c
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libffi.pc
nodist_libffi_la_SOURCES =
if MIPS
nodist_libffi_la_SOURCES += src/mips/ffi.c src/mips/o32.S src/mips/n32.S
endif
if X86
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/sysv.S
endif
if X86_FREEBSD
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/freebsd.S
endif
if X86_WIN32
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/win32.S
endif
if X86_DARWIN
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S
endif
if SPARC
nodist_libffi_la_SOURCES += src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S
endif
if ALPHA
nodist_libffi_la_SOURCES += src/alpha/ffi.c src/alpha/osf.S
endif
if IA64
nodist_libffi_la_SOURCES += src/ia64/ffi.c src/ia64/unix.S
endif
if M32R
nodist_libffi_la_SOURCES += src/m32r/sysv.S src/m32r/ffi.c
endif
if M68K
nodist_libffi_la_SOURCES += src/m68k/ffi.c src/m68k/sysv.S
endif
if POWERPC
nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S
endif
if POWERPC_AIX
nodist_libffi_la_SOURCES += src/powerpc/ffi_darwin.c src/powerpc/aix.S src/powerpc/aix_closure.S
endif
if POWERPC_DARWIN
nodist_libffi_la_SOURCES += src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S
endif
if POWERPC_FREEBSD
nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S
endif
if ARM
nodist_libffi_la_SOURCES += src/arm/sysv.S src/arm/ffi.c
endif
if LIBFFI_CRIS
nodist_libffi_la_SOURCES += src/cris/sysv.S src/cris/ffi.c
endif
if FRV
nodist_libffi_la_SOURCES += src/frv/eabi.S src/frv/ffi.c
endif
if S390
nodist_libffi_la_SOURCES += src/s390/sysv.S src/s390/ffi.c
endif
if X86_64
nodist_libffi_la_SOURCES += src/x86/ffi64.c src/x86/unix64.S src/x86/ffi.c src/x86/sysv.S
endif
if SH
nodist_libffi_la_SOURCES += src/sh/sysv.S src/sh/ffi.c
endif
if SH64
nodist_libffi_la_SOURCES += src/sh64/sysv.S src/sh64/ffi.c
endif
if PA_LINUX
nodist_libffi_la_SOURCES += src/pa/linux.S src/pa/ffi.c
endif
if PA_HPUX
nodist_libffi_la_SOURCES += src/pa/hpux32.S src/pa/ffi.c
endif
libffi_convenience_la_SOURCES = $(libffi_la_SOURCES)
nodist_libffi_convenience_la_SOURCES = $(nodist_libffi_la_SOURCES)
AM_CFLAGS = -Wall -g -fexceptions
libffi_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
AM_CCASFLAGS = $(AM_CPPFLAGS)
# No install-html or install-pdf support in automake yet
.PHONY: install-html install-pdf
install-html:
install-pdf:

1648
js/ctypes/libffi/Makefile.in Normal file

File diff suppressed because it is too large Load Diff

336
js/ctypes/libffi/README Normal file
View File

@@ -0,0 +1,336 @@
Status
======
libffi-3.0.8 was released on December 19, 2008. Check the libffi web
page for updates: <URL:http://sourceware.org/libffi/>.
What is libffi?
===============
Compilers for high level languages generate code that follow certain
conventions. These conventions are necessary, in part, for separate
compilation to work. One such convention is the "calling convention".
The "calling convention" is a set of assumptions made by the compiler
about where function arguments will be found on entry to a function.
A "calling convention" also specifies where the return value for a
function is found.
Some programs may not know at the time of compilation what arguments
are to be passed to a function. For instance, an interpreter may be
told at run-time about the number and types of arguments used to call
a given function. Libffi can be used in such programs to provide a
bridge from the interpreter program to compiled code.
The libffi library provides a portable, high level programming
interface to various calling conventions. This allows a programmer to
call any function specified by a call interface description at run
time.
FFI stands for Foreign Function Interface. A foreign function
interface is the popular name for the interface that allows code
written in one language to call code written in another language. The
libffi library really only provides the lowest, machine dependent
layer of a fully featured foreign function interface. A layer must
exist above libffi that handles type conversions for values passed
between the two languages.
Supported Platforms
===================
Libffi has been ported to many different platforms, although this
release was only tested on:
arm oabi linux
arm eabi linux
hppa linux
mips o32 linux (little endian)
powerpc darwin
powerpc freebsd
powerpc64 linux
sparc solaris
sparc64 freebsd
sparc64 solaris
x86 cygwin
x86 darwin
x86 freebsd
x86 linux
x86 openbsd
x86 solaris
x86-64 darwin
x86-64 linux
x86-64 OS X
x86-64 freebsd
x86-64 solaris
Please send additional platform test results to
libffi-discuss@sourceware.org.
Installing libffi
=================
[Note: before actually performing any of these installation steps,
you may wish to read the "Platform Specific Notes" below.]
First you must configure the distribution for your particular
system. Go to the directory you wish to build libffi in and run the
"configure" program found in the root directory of the libffi source
distribution.
You may want to tell configure where to install the libffi library and
header files. To do that, use the --prefix configure switch. Libffi
will install under /usr/local by default.
If you want to enable extra run-time debugging checks use the the
--enable-debug configure switch. This is useful when your program dies
mysteriously while using libffi.
Another useful configure switch is --enable-purify-safety. Using this
will add some extra code which will suppress certain warnings when you
are using Purify with libffi. Only use this switch when using
Purify, as it will slow down the library.
Configure has many other options. Use "configure --help" to see them all.
Once configure has finished, type "make". Note that you must be using
GNU make. You can ftp GNU make from prep.ai.mit.edu:/pub/gnu.
To ensure that libffi is working as advertised, type "make check".
This will require that you have DejaGNU installed.
To install the library and header files, type "make install".
Platform Specific Notes
=======================
MIPS - Irix 5.3 & 6.x
---------------------
Irix 6.2 and better supports three different calling conventions: o32,
n32 and n64. Currently, libffi only supports both o32 and n32 under
Irix 6.x, but only o32 under Irix 5.3. Libffi will automatically be
configured for whichever calling convention it was built for.
By default, the configure script will try to build libffi with the GNU
development tools. To build libffi with the SGI development tools, set
the environment variable CC to either "cc -32" or "cc -n32" before
running configure under Irix 6.x (depending on whether you want an o32
or n32 library), or just "cc" for Irix 5.3.
With the n32 calling convention, when returning structures smaller
than 16 bytes, be sure to provide an RVALUE that is 8 byte aligned.
Here's one way of forcing this:
double struct_storage[2];
my_small_struct *s = (my_small_struct *) struct_storage;
/* Use s for RVALUE */
If you don't do this you are liable to get spurious bus errors.
"long long" values are not supported yet.
You must use GNU Make to build libffi on SGI platforms.
PowerPC System V ABI
--------------------
There are two `System V ABI's which libffi implements for PowerPC.
They differ only in how small structures are returned from functions.
In the FFI_SYSV version, structures that are 8 bytes or smaller are
returned in registers. This is what GCC does when it is configured
for solaris, and is what the System V ABI I have (dated September
1995) says.
In the FFI_GCC_SYSV version, all structures are returned the same way:
by passing a pointer as the first argument to the function. This is
what GCC does when it is configured for linux or a generic sysv
target.
EGCS 1.0.1 (and probably other versions of EGCS/GCC) also has a
inconsistency with the SysV ABI: When a procedure is called with many
floating-point arguments, some of them get put on the stack. They are
all supposed to be stored in double-precision format, even if they are
only single-precision, but EGCS stores single-precision arguments as
single-precision anyway. This causes one test to fail (the `many
arguments' test).
History
=======
3.0.7 Nov-11-08
Fix for ppc FreeBSD.
(thanks to Andreas Tobler)
3.0.6 Jul-17-08
Fix for closures on sh.
Mark the sh/sh64 stack as non-executable.
(both thanks to Kaz Kojima)
3.0.5 Apr-3-08
Fix libffi.pc file.
Fix #define ARM for IcedTea users.
Fix x86 closure bug.
3.0.4 Feb-24-08
Fix x86 OpenBSD configury.
3.0.3 Feb-22-08
Enable x86 OpenBSD thanks to Thomas Heller, and
x86-64 FreeBSD thanks to Björn König and Andreas Tobler.
Clean up test instruction in README.
3.0.2 Feb-21-08
Improved x86 FreeBSD support.
Thanks to Björn König.
3.0.1 Feb-15-08
Fix instruction cache flushing bug on MIPS.
Thanks to David Daney.
3.0.0 Feb-15-08
Many changes, mostly thanks to the GCC project.
Cygnus Solutions is now Red Hat.
[10 years go by...]
1.20 Oct-5-98
Raffaele Sena produces ARM port.
1.19 Oct-5-98
Fixed x86 long double and long long return support.
m68k bug fixes from Andreas Schwab.
Patch for DU assembler compatibility for the Alpha from Richard
Henderson.
1.18 Apr-17-98
Bug fixes and MIPS configuration changes.
1.17 Feb-24-98
Bug fixes and m68k port from Andreas Schwab. PowerPC port from
Geoffrey Keating. Various bug x86, Sparc and MIPS bug fixes.
1.16 Feb-11-98
Richard Henderson produces Alpha port.
1.15 Dec-4-97
Fixed an n32 ABI bug. New libtool, auto* support.
1.14 May-13-97
libtool is now used to generate shared and static libraries.
Fixed a minor portability problem reported by Russ McManus
<mcmanr@eq.gs.com>.
1.13 Dec-2-96
Added --enable-purify-safety to keep Purify from complaining
about certain low level code.
Sparc fix for calling functions with < 6 args.
Linux x86 a.out fix.
1.12 Nov-22-96
Added missing ffi_type_void, needed for supporting void return
types. Fixed test case for non MIPS machines. Cygnus Support
is now Cygnus Solutions.
1.11 Oct-30-96
Added notes about GNU make.
1.10 Oct-29-96
Added configuration fix for non GNU compilers.
1.09 Oct-29-96
Added --enable-debug configure switch. Clean-ups based on LCLint
feedback. ffi_mips.h is always installed. Many configuration
fixes. Fixed ffitest.c for sparc builds.
1.08 Oct-15-96
Fixed n32 problem. Many clean-ups.
1.07 Oct-14-96
Gordon Irlam rewrites v8.S again. Bug fixes.
1.06 Oct-14-96
Gordon Irlam improved the sparc port.
1.05 Oct-14-96
Interface changes based on feedback.
1.04 Oct-11-96
Sparc port complete (modulo struct passing bug).
1.03 Oct-10-96
Passing struct args, and returning struct values works for
all architectures/calling conventions. Expanded tests.
1.02 Oct-9-96
Added SGI n32 support. Fixed bugs in both o32 and Linux support.
Added "make test".
1.01 Oct-8-96
Fixed float passing bug in mips version. Restructured some
of the code. Builds cleanly with SGI tools.
1.00 Oct-7-96
First release. No public announcement.
Authors & Credits
=================
libffi was originally written by Anthony Green <green@redhat.com>.
The developers of the GNU Compiler Collection project have made
innumerable valuable contributions. See the ChangeLog file for
details.
Some of the ideas behind libffi were inspired by Gianni Mariani's free
gencall library for Silicon Graphics machines.
The closure mechanism was designed and implemented by Kresten Krab
Thorup.
Major processor architecture ports were contributed by the following
developers:
alpha Richard Henderson
arm Raffaele Sena
cris Simon Posnjak, Hans-Peter Nilsson
frv Anthony Green
ia64 Hans Boehm
m32r Kazuhiro Inaoka
m68k Andreas Schwab
mips Anthony Green, Casey Marshall
mips64 David Daney
pa Randolph Chung, Dave Anglin, Andreas Tobler
powerpc Geoffrey Keating, Andreas Tobler,
David Edelsohn, John Hornkvist
powerpc64 Jakub Jelinek
s390 Gerhard Tonn, Ulrich Weigand
sh Kaz Kojima
sh64 Kaz Kojima
sparc Anthony Green, Gordon Irlam
x86 Anthony Green, Jon Beniston
x86-64 Bo Thorsen
Jesper Skov and Andrew Haley both did more than their fair share of
stepping through the code and tracking down bugs.
Thanks also to Tom Tromey for bug fixes, documentation and
configuration help.
Thanks to Jim Blandy, who provided some useful feedback on the libffi
interface.
Andreas Tobler has done a tremendous amount of work on the testsuite.
Alex Oliva solved the executable page problem for SElinux.
The list above is almost certainly incomplete and inaccurate. I'm
happy to make corrections or additions upon request.
If you have a problem, or have found a bug, please send a note to
green@redhat.com.

1
js/ctypes/libffi/TODO Normal file
View File

@@ -0,0 +1 @@
- Merge with GCC tree.

View File

@@ -0,0 +1,92 @@
# mmap(2) blacklisting. Some platforms provide the mmap library routine
# but don't support all of the features we need from it.
AC_DEFUN([AC_FUNC_MMAP_BLACKLIST],
[
AC_CHECK_HEADER([sys/mman.h],
[libffi_header_sys_mman_h=yes], [libffi_header_sys_mman_h=no])
AC_CHECK_FUNC([mmap], [libffi_func_mmap=yes], [libffi_func_mmap=no])
if test "$libffi_header_sys_mman_h" != yes \
|| test "$libffi_func_mmap" != yes; then
ac_cv_func_mmap_file=no
ac_cv_func_mmap_dev_zero=no
ac_cv_func_mmap_anon=no
else
AC_CACHE_CHECK([whether read-only mmap of a plain file works],
ac_cv_func_mmap_file,
[# Add a system to this blacklist if
# mmap(0, stat_size, PROT_READ, MAP_PRIVATE, fd, 0) doesn't return a
# memory area containing the same data that you'd get if you applied
# read() to the same fd. The only system known to have a problem here
# is VMS, where text files have record structure.
case "$host_os" in
vms* | ultrix*)
ac_cv_func_mmap_file=no ;;
*)
ac_cv_func_mmap_file=yes;;
esac])
AC_CACHE_CHECK([whether mmap from /dev/zero works],
ac_cv_func_mmap_dev_zero,
[# Add a system to this blacklist if it has mmap() but /dev/zero
# does not exist, or if mmapping /dev/zero does not give anonymous
# zeroed pages with both the following properties:
# 1. If you map N consecutive pages in with one call, and then
# unmap any subset of those pages, the pages that were not
# explicitly unmapped remain accessible.
# 2. If you map two adjacent blocks of memory and then unmap them
# both at once, they must both go away.
# Systems known to be in this category are Windows (all variants),
# VMS, and Darwin.
case "$host_os" in
vms* | cygwin* | pe | mingw* | darwin* | ultrix* | hpux10* | hpux11.00)
ac_cv_func_mmap_dev_zero=no ;;
*)
ac_cv_func_mmap_dev_zero=yes;;
esac])
# Unlike /dev/zero, the MAP_ANON(YMOUS) defines can be probed for.
AC_CACHE_CHECK([for MAP_ANON(YMOUS)], ac_cv_decl_map_anon,
[AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
],
[int n = MAP_ANONYMOUS;],
ac_cv_decl_map_anon=yes,
ac_cv_decl_map_anon=no)])
if test $ac_cv_decl_map_anon = no; then
ac_cv_func_mmap_anon=no
else
AC_CACHE_CHECK([whether mmap with MAP_ANON(YMOUS) works],
ac_cv_func_mmap_anon,
[# Add a system to this blacklist if it has mmap() and MAP_ANON or
# MAP_ANONYMOUS, but using mmap(..., MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
# doesn't give anonymous zeroed pages with the same properties listed
# above for use of /dev/zero.
# Systems known to be in this category are Windows, VMS, and SCO Unix.
case "$host_os" in
vms* | cygwin* | pe | mingw* | sco* | udk* )
ac_cv_func_mmap_anon=no ;;
*)
ac_cv_func_mmap_anon=yes;;
esac])
fi
fi
if test $ac_cv_func_mmap_file = yes; then
AC_DEFINE(HAVE_MMAP_FILE, 1,
[Define if read-only mmap of a plain file works.])
fi
if test $ac_cv_func_mmap_dev_zero = yes; then
AC_DEFINE(HAVE_MMAP_DEV_ZERO, 1,
[Define if mmap of /dev/zero works.])
fi
if test $ac_cv_func_mmap_anon = yes; then
AC_DEFINE(HAVE_MMAP_ANON, 1,
[Define if mmap with MAP_ANON(YMOUS) works.])
fi
])

7593
js/ctypes/libffi/aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load Diff

142
js/ctypes/libffi/compile Executable file
View File

@@ -0,0 +1,142 @@
#! /bin/sh
# Wrapper for compilers which do not understand `-c -o'.
scriptversion=2005-05-14.22
# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# 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.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
case $1 in
'')
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand `-c -o'.
Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file `INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
esac
ofile=
cfile=
eat=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as `compile cc -o foo foo.c'.
# So we strip `-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no `-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# `.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
# Create the lock directory.
# Note: use `[/.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@@ -0,0 +1,911 @@
# Configure fragment invoked in the post-target section for subdirs
# wanting multilib support.
#
# Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
# Free Software Foundation, Inc.
#
# This file 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 of the License, 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., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
#
# Please report bugs to <gcc-bugs@gnu.org>
# and send patches to <gcc-patches@gnu.org>.
# It is advisable to support a few --enable/--disable options to let the
# user select which libraries s/he really wants.
#
# Subdirectories wishing to use multilib should put the following lines
# in the "post-target" section of configure.in.
#
# if [ "${srcdir}" = "." ] ; then
# if [ "${with_target_subdir}" != "." ] ; then
# . ${with_multisrctop}../../config-ml.in
# else
# . ${with_multisrctop}../config-ml.in
# fi
# else
# . ${srcdir}/../config-ml.in
# fi
#
#
# Things are complicated because 6 separate cases must be handled:
# 2 (native, cross) x 3 (absolute-path, relative-not-dot, dot) = 6.
#
# srcdir=. is special. It must handle make programs that don't handle VPATH.
# To implement this, a symlink tree is built for each library and for each
# multilib subdir.
#
# The build tree is layed out as
#
# ./
# newlib
# m68020/
# newlib
# m68881/
# newlib
#
# The nice feature about this arrangement is that inter-library references
# in the build tree work without having to care where you are. Note that
# inter-library references also work in the source tree because symlink trees
# are built when srcdir=.
#
# Unfortunately, trying to access the libraries in the build tree requires
# the user to manually choose which library to use as GCC won't be able to
# find the right one. This is viewed as the lesser of two evils.
#
# Configure variables:
# ${with_target_subdir} = "." for native, or ${target_alias} for cross.
# Set by top level Makefile.
# ${with_multisrctop} = how many levels of multilibs there are in the source
# tree. It exists to handle the case of configuring in the source tree:
# ${srcdir} is not constant.
# ${with_multisubdir} = name of multilib subdirectory (eg: m68020/m68881).
#
# Makefile variables:
# MULTISRCTOP = number of multilib levels in source tree (+1 if cross)
# (FIXME: note that this is different than ${with_multisrctop}. Check out.).
# MULTIBUILDTOP = number of multilib levels in build tree
# MULTIDIRS = list of multilib subdirs (eg: m68000 m68020 ...)
# (only defined in each library's main Makefile).
# MULTISUBDIR = installed subdirectory name with leading '/' (eg: /m68000)
# (only defined in each multilib subdir).
# FIXME: Multilib is currently disabled by default for everything other than
# newlib. It is up to each target to turn on multilib support for the other
# libraries as desired.
# Autoconf incoming variables:
# srcdir, host, ac_configure_args
#
# We *could* figure srcdir and host out, but we'd have to do work that
# our caller has already done to figure them out and requiring these two
# seems reasonable.
# Note that `host' in this case is GCC's `target'. Target libraries are
# configured for a particular host.
Makefile=${ac_file-Makefile}
ml_config_shell=${CONFIG_SHELL-/bin/sh}
ml_realsrcdir=${srcdir}
# Scan all the arguments and set all the ones we need.
ml_verbose=--verbose
for option in ${ac_configure_args}
do
# strip single quotes surrounding individual options
case $option in
\'*\') eval option=$option ;;
esac
case $option in
--*) ;;
-*) option=-$option ;;
esac
case $option in
--*=*)
optarg=`echo $option | sed -e 's/^[^=]*=//'`
;;
esac
case $option in
--disable-*)
enableopt=`echo ${option} | sed 's:^--disable-:enable_:;s:-:_:g'`
eval $enableopt=no
;;
--enable-*)
case "$option" in
*=*) ;;
*) optarg=yes ;;
esac
enableopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
eval $enableopt="$optarg"
;;
--norecursion | --no-recursion)
ml_norecursion=yes
;;
--silent | --sil* | --quiet | --q*)
ml_verbose=--silent
;;
--verbose | --v | --verb*)
ml_verbose=--verbose
;;
--with-*)
case "$option" in
*=*) ;;
*) optarg=yes ;;
esac
withopt=`echo ${option} | sed 's:^--::;s:=.*$::;s:-:_:g'`
eval $withopt="$optarg"
;;
--without-*)
withopt=`echo ${option} | sed 's:^--::;s:out::;s:-:_:g'`
eval $withopt=no
;;
esac
done
# Only do this if --enable-multilib.
if [ "${enable_multilib}" = yes ]; then
# Compute whether this is the library's top level directory
# (ie: not a multilib subdirectory, and not a subdirectory like newlib/src).
# ${with_multisubdir} tells us we're in the right branch, but we could be
# in a subdir of that.
# ??? The previous version could void this test by separating the process into
# two files: one that only the library's toplevel configure.in ran (to
# configure the multilib subdirs), and another that all configure.in's ran to
# update the Makefile. It seemed reasonable to collapse all multilib support
# into one file, but it does leave us with having to perform this test.
ml_toplevel_p=no
if [ -z "${with_multisubdir}" ]; then
if [ "${srcdir}" = "." ]; then
# Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
# ${with_target_subdir} = "." for native, otherwise target alias.
if [ "${with_target_subdir}" = "." ]; then
if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
ml_toplevel_p=yes
fi
else
if [ -f ${ml_realsrcdir}/../../config-ml.in ]; then
ml_toplevel_p=yes
fi
fi
else
# Use ${ml_realsrcdir} instead of ${srcdir} here to account for ${subdir}.
if [ -f ${ml_realsrcdir}/../config-ml.in ]; then
ml_toplevel_p=yes
fi
fi
fi
# If this is the library's top level directory, set multidirs to the
# multilib subdirs to support. This lives at the top because we need
# `multidirs' set right away.
if [ "${ml_toplevel_p}" = yes ]; then
multidirs=
for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
dir=`echo $i | sed -e 's/;.*$//'`
if [ "${dir}" = "." ]; then
true
else
if [ -z "${multidirs}" ]; then
multidirs="${dir}"
else
multidirs="${multidirs} ${dir}"
fi
fi
done
# Target libraries are configured for the host they run on, so we check
# $host here, not $target.
case "${host}" in
arc-*-elf*)
if [ x$enable_biendian != xyes ]
then
old_multidirs=${multidirs}
multidirs=""
for x in ${old_multidirs}; do
case "${x}" in
*be*) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
;;
arm-*-*)
if [ x"$enable_fpu" = xno ]
then
old_multidirs=${multidirs}
multidirs=""
for x in ${old_multidirs}; do
case "${x}" in
*fpu*) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x"$enable_26bit" = xno ]
then
old_multidirs=${multidirs}
multidirs=""
for x in ${old_multidirs}; do
case "${x}" in
*26bit*) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x"$enable_underscore" = xno ]
then
old_multidirs=${multidirs}
multidirs=""
for x in ${old_multidirs}; do
case "${x}" in
*under*) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x"$enable_interwork" = xno ]
then
old_multidirs=${multidirs}
multidirs=""
for x in ${old_multidirs}; do
case "${x}" in
*interwork*) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_biendian = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*le* ) : ;;
*be* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x"$enable_nofmult" = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*nofmult* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
;;
m68*-*-*)
if [ x$enable_softfloat = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*soft-float* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_m68881 = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*m68881* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_m68000 = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*m68000* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_m68020 = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*m68020* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
;;
mips*-*-*)
if [ x$enable_single_float = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*single* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_biendian = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*el* ) : ;;
*eb* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_softfloat = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*soft-float* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
case " $multidirs " in
*" mabi=64 "*)
# We will not be able to create libraries with -mabi=64 if
# we cannot even link a trivial program. It usually
# indicates the 64bit libraries are missing.
if echo 'main() {}' > conftest.c &&
${CC-gcc} -mabi=64 conftest.c -o conftest; then
:
else
echo Could not link program with -mabi=64, disabling it.
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*mabi=64* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
rm -f conftest.c conftest
;;
esac
;;
powerpc*-*-* | rs6000*-*-*)
if [ x$enable_aix64 = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*ppc64* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_pthread = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*pthread* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_softfloat = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*soft-float* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_powercpu = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
power | */power | */power/* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_powerpccpu = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*powerpc* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_powerpcos = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*mcall-linux* | *mcall-solaris* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_biendian = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*mlittle* | *mbig* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
if [ x$enable_sysv = xno ]
then
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*mcall-sysv* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
;;
sparc*-*-*)
case " $multidirs " in
*" m64 "*)
# We will not be able to create libraries with -m64 if
# we cannot even link a trivial program. It usually
# indicates the 64bit libraries are missing.
if echo 'main() {}' > conftest.c &&
${CC-gcc} -m64 conftest.c -o conftest; then
:
else
echo Could not link program with -m64, disabling it.
old_multidirs="${multidirs}"
multidirs=""
for x in ${old_multidirs}; do
case "$x" in
*m64* ) : ;;
*) multidirs="${multidirs} ${x}" ;;
esac
done
fi
rm -f conftest.c conftest
;;
esac
;;
esac
# Remove extraneous blanks from multidirs.
# Tests like `if [ -n "$multidirs" ]' require it.
multidirs=`echo "$multidirs" | sed -e 's/^[ ][ ]*//' -e 's/[ ][ ]*$//' -e 's/[ ][ ]*/ /g'`
# Add code to library's top level makefile to handle building the multilib
# subdirs.
cat > Multi.tem <<\EOF
PWD_COMMAND=$${PWDCMD-pwd}
# FIXME: There should be an @-sign in front of the `if'.
# Leave out until this is tested a bit more.
multi-do:
if [ -z "$(MULTIDIRS)" ]; then \
true; \
else \
rootpre=`${PWD_COMMAND}`/; export rootpre; \
srcrootpre=`cd $(srcdir); ${PWD_COMMAND}`/; export srcrootpre; \
lib=`echo $${rootpre} | sed -e 's,^.*/\([^/][^/]*\)/$$,\1,'`; \
compiler="$(CC)"; \
for i in `$${compiler} --print-multi-lib 2>/dev/null`; do \
dir=`echo $$i | sed -e 's/;.*$$//'`; \
if [ "$${dir}" = "." ]; then \
true; \
else \
if [ -d ../$${dir}/$${lib} ]; then \
flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \
if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) \
CFLAGS="$(CFLAGS) $${flags}" \
FCFLAGS="$(FCFLAGS) $${flags}" \
FFLAGS="$(FFLAGS) $${flags}" \
ADAFLAGS="$(ADAFLAGS) $${flags}" \
prefix="$(prefix)" \
exec_prefix="$(exec_prefix)" \
GCJFLAGS="$(GCJFLAGS) $${flags}" \
CXXFLAGS="$(CXXFLAGS) $${flags}" \
LIBCFLAGS="$(LIBCFLAGS) $${flags}" \
LIBCXXFLAGS="$(LIBCXXFLAGS) $${flags}" \
LDFLAGS="$(LDFLAGS) $${flags}" \
MULTIFLAGS="$${flags}" \
DESTDIR="$(DESTDIR)" \
INSTALL="$(INSTALL)" \
INSTALL_DATA="$(INSTALL_DATA)" \
INSTALL_PROGRAM="$(INSTALL_PROGRAM)" \
INSTALL_SCRIPT="$(INSTALL_SCRIPT)" \
$(DO)); then \
true; \
else \
exit 1; \
fi; \
else true; \
fi; \
fi; \
done; \
fi
# FIXME: There should be an @-sign in front of the `if'.
# Leave out until this is tested a bit more.
multi-clean:
if [ -z "$(MULTIDIRS)" ]; then \
true; \
else \
lib=`${PWD_COMMAND} | sed -e 's,^.*/\([^/][^/]*\)$$,\1,'`; \
for dir in Makefile $(MULTIDIRS); do \
if [ -f ../$${dir}/$${lib}/Makefile ]; then \
if (cd ../$${dir}/$${lib}; $(MAKE) $(FLAGS_TO_PASS) $(DO)); \
then true; \
else exit 1; \
fi; \
else true; \
fi; \
done; \
fi
EOF
cat ${Makefile} Multi.tem > Makefile.tem
rm -f ${Makefile} Multi.tem
mv Makefile.tem ${Makefile}
fi # ${ml_toplevel_p} = yes
if [ "${ml_verbose}" = --verbose ]; then
echo "Adding multilib support to Makefile in ${ml_realsrcdir}"
if [ "${ml_toplevel_p}" = yes ]; then
echo "multidirs=${multidirs}"
fi
echo "with_multisubdir=${with_multisubdir}"
fi
if [ "${srcdir}" = "." ]; then
if [ "${with_target_subdir}" != "." ]; then
ml_srcdotdot="../"
else
ml_srcdotdot=""
fi
else
ml_srcdotdot=""
fi
if [ -z "${with_multisubdir}" ]; then
ml_subdir=
ml_builddotdot=
: # ml_srcdotdot= # already set
else
ml_subdir="/${with_multisubdir}"
# The '[^/][^/]*' appears that way to work around a SunOS sed bug.
ml_builddotdot=`echo ${with_multisubdir} | sed -e 's:[^/][^/]*:..:g'`/
if [ "$srcdir" = "." ]; then
ml_srcdotdot=${ml_srcdotdot}${ml_builddotdot}
else
: # ml_srcdotdot= # already set
fi
fi
if [ "${ml_toplevel_p}" = yes ]; then
ml_do='$(MAKE)'
ml_clean='$(MAKE)'
else
ml_do=true
ml_clean=true
fi
# TOP is used by newlib and should not be used elsewhere for this purpose.
# MULTI{SRC,BUILD}TOP are the proper ones to use. MULTISRCTOP is empty
# when srcdir != builddir. MULTIBUILDTOP is always some number of ../'s.
# FIXME: newlib needs to be updated to use MULTI{SRC,BUILD}TOP so we can
# delete TOP. Newlib may wish to continue to use TOP for its own purposes
# of course.
# MULTIDIRS is non-empty for the cpu top level Makefile (eg: newlib/Makefile)
# and lists the subdirectories to recurse into.
# MULTISUBDIR is non-empty in each cpu subdirectory's Makefile
# (eg: newlib/h8300h/Makefile) and is the installed subdirectory name with
# a leading '/'.
# MULTIDO is used for targets like all, install, and check where
# $(FLAGS_TO_PASS) augmented with the subdir's compiler option is needed.
# MULTICLEAN is used for the *clean targets.
#
# ??? It is possible to merge MULTIDO and MULTICLEAN into one. They are
# currently kept separate because we don't want the *clean targets to require
# the existence of the compiler (which MULTIDO currently requires) and
# therefore we'd have to record the directory options as well as names
# (currently we just record the names and use --print-multi-lib to get the
# options).
sed -e "s:^TOP[ ]*=[ ]*\([./]*\)[ ]*$:TOP = ${ml_builddotdot}\1:" \
-e "s:^MULTISRCTOP[ ]*=.*$:MULTISRCTOP = ${ml_srcdotdot}:" \
-e "s:^MULTIBUILDTOP[ ]*=.*$:MULTIBUILDTOP = ${ml_builddotdot}:" \
-e "s:^MULTIDIRS[ ]*=.*$:MULTIDIRS = ${multidirs}:" \
-e "s:^MULTISUBDIR[ ]*=.*$:MULTISUBDIR = ${ml_subdir}:" \
-e "s:^MULTIDO[ ]*=.*$:MULTIDO = $ml_do:" \
-e "s:^MULTICLEAN[ ]*=.*$:MULTICLEAN = $ml_clean:" \
${Makefile} > Makefile.tem
rm -f ${Makefile}
mv Makefile.tem ${Makefile}
# If this is the library's top level, configure each multilib subdir.
# This is done at the end because this is the loop that runs configure
# in each multilib subdir and it seemed reasonable to finish updating the
# Makefile before going on to configure the subdirs.
if [ "${ml_toplevel_p}" = yes ]; then
# We must freshly configure each subdirectory. This bit of code is
# actually partially stolen from the main configure script. FIXME.
if [ -n "${multidirs}" ] && [ -z "${ml_norecursion}" ]; then
if [ "${ml_verbose}" = --verbose ]; then
echo "Running configure in multilib subdirs ${multidirs}"
echo "pwd: `${PWDCMD-pwd}`"
fi
ml_origdir=`${PWDCMD-pwd}`
ml_libdir=`echo $ml_origdir | sed -e 's,^.*/,,'`
# cd to top-level-build-dir/${with_target_subdir}
cd ..
for ml_dir in ${multidirs}; do
if [ "${ml_verbose}" = --verbose ]; then
echo "Running configure in multilib subdir ${ml_dir}"
echo "pwd: `${PWDCMD-pwd}`"
fi
if [ -d ${ml_dir} ]; then true; else
# ``mkdir -p ${ml_dir}'' See also mkinstalldirs.
pathcomp=""
for d in `echo ":${ml_dir}" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" > /dev/null 2>&1 || lasterr=$?
fi
if test ! -d "$pathcomp"; then
exit $lasterr
fi
pathcomp="$pathcomp/"
done
fi
if [ -d ${ml_dir}/${ml_libdir} ]; then true; else mkdir ${ml_dir}/${ml_libdir}; fi
# Eg: if ${ml_dir} = m68000/m68881, dotdot = ../../
dotdot=../`echo ${ml_dir} | sed -e 's|[^/]||g' -e 's|/|../|g'`
case ${srcdir} in
".")
echo Building symlink tree in `${PWDCMD-pwd}`/${ml_dir}/${ml_libdir}
if [ "${with_target_subdir}" != "." ]; then
ml_unsubdir="../"
else
ml_unsubdir=""
fi
(cd ${ml_dir}/${ml_libdir};
../${dotdot}${ml_unsubdir}symlink-tree ../${dotdot}${ml_unsubdir}${ml_libdir} "")
if [ -f ${ml_dir}/${ml_libdir}/Makefile ]; then
if [ x"${MAKE}" = x ]; then
(cd ${ml_dir}/${ml_libdir}; make distclean)
else
(cd ${ml_dir}/${ml_libdir}; ${MAKE} distclean)
fi
fi
ml_newsrcdir="."
ml_srcdiroption=
multisrctop=${dotdot}
;;
*)
case "${srcdir}" in
/* | [A-Za-z]:[\\/]* ) # absolute path
ml_newsrcdir=${srcdir}
;;
*) # otherwise relative
ml_newsrcdir=${dotdot}${srcdir}
;;
esac
ml_srcdiroption="-srcdir=${ml_newsrcdir}"
multisrctop=
;;
esac
case "${progname}" in
/* | [A-Za-z]:[\\/]* ) ml_recprog=${progname} ;;
*) ml_recprog=${dotdot}${progname} ;;
esac
# FIXME: POPDIR=${PWD=`pwd`} doesn't work here.
ML_POPDIR=`${PWDCMD-pwd}`
cd ${ml_dir}/${ml_libdir}
if [ -f ${ml_newsrcdir}/configure ]; then
ml_recprog="${ml_newsrcdir}/configure"
fi
# find compiler flag corresponding to ${ml_dir}
for i in `${CC-gcc} --print-multi-lib 2>/dev/null`; do
dir=`echo $i | sed -e 's/;.*$//'`
if [ "${dir}" = "${ml_dir}" ]; then
flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`
break
fi
done
ml_config_env='CC="${CC_}$flags" CXX="${CXX_}$flags" F77="${F77_}$flags" GCJ="${GCJ_}$flags" GFORTRAN="${GFORTRAN_}$flags"'
if [ "${with_target_subdir}" = "." ]; then
CC_=$CC' '
CXX_=$CXX' '
F77_=$F77' '
GCJ_=$GCJ' '
GFORTRAN_=$GFORTRAN' '
else
# Create a regular expression that matches any string as long
# as ML_POPDIR.
popdir_rx=`echo ${ML_POPDIR} | sed 's,.,.,g'`
CC_=
for arg in ${CC}; do
case $arg in
-[BIL]"${ML_POPDIR}"/*)
CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\1/p"`' ' ;;
"${ML_POPDIR}"/*)
CC_="${CC_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
*)
CC_="${CC_}${arg} " ;;
esac
done
CXX_=
for arg in ${CXX}; do
case $arg in
-[BIL]"${ML_POPDIR}"/*)
CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
"${ML_POPDIR}"/*)
CXX_="${CXX_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
*)
CXX_="${CXX_}${arg} " ;;
esac
done
F77_=
for arg in ${F77}; do
case $arg in
-[BIL]"${ML_POPDIR}"/*)
F77_="${F77_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
"${ML_POPDIR}"/*)
F77_="${F77_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
*)
F77_="${F77_}${arg} " ;;
esac
done
GCJ_=
for arg in ${GCJ}; do
case $arg in
-[BIL]"${ML_POPDIR}"/*)
GCJ_="${GCJ_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
"${ML_POPDIR}"/*)
GCJ_="${GCJ_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
*)
GCJ_="${GCJ_}${arg} " ;;
esac
done
GFORTRAN_=
for arg in ${GFORTRAN}; do
case $arg in
-[BIL]"${ML_POPDIR}"/*)
GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n "s/X\\(-[BIL]${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X-[BIL]${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
"${ML_POPDIR}"/*)
GFORTRAN_="${GFORTRAN_}"`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`' ' ;;
*)
GFORTRAN_="${GFORTRAN_}${arg} " ;;
esac
done
if test "x${LD_LIBRARY_PATH+set}" = xset; then
LD_LIBRARY_PATH_=
for arg in `echo "$LD_LIBRARY_PATH" | tr ':' ' '`; do
case "$arg" in
"${ML_POPDIR}"/*)
arg=`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`
;;
esac
if test "x$LD_LIBRARY_PATH_" != x; then
LD_LIBRARY_PATH_=$LD_LIBRARY_PATH_:$arg
else
LD_LIBRARY_PATH_=$arg
fi
done
ml_config_env="$ml_config_env LD_LIBRARY_PATH=$LD_LIBRARY_PATH_"
fi
if test "x${SHLIB_PATH+set}" = xset; then
SHLIB_PATH_=
for arg in `echo "$SHLIB_PATH" | tr ':' ' '`; do
case "$arg" in
"${ML_POPDIR}"/*)
arg=`echo "X${arg}" | sed -n "s/X\\(${popdir_rx}\\).*/\\1/p"`/${ml_dir}`echo "X${arg}" | sed -n "s/X${popdir_rx}\\(.*\\)/\\1/p"`
;;
esac
if test "x$SHLIB_PATH_" != x; then
SHLIB_PATH_=$SHLIB_PATH_:$arg
else
SHLIB_PATH_=$arg
fi
done
ml_config_env="$ml_config_env SHLIB_PATH=$SHLIB_PATH_"
fi
fi
if eval ${ml_config_env} ${ml_config_shell} ${ml_recprog} \
--with-multisubdir=${ml_dir} --with-multisrctop=${multisrctop} \
${ac_configure_args} ${ml_srcdiroption} ; then
true
else
exit 1
fi
cd ${ML_POPDIR}
done
cd ${ml_origdir}
fi
fi # ${ml_toplevel_p} = yes
fi # ${enable_multilib} = yes

1516
js/ctypes/libffi/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

1626
js/ctypes/libffi/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

25139
js/ctypes/libffi/configure vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,380 @@
dnl Process this with autoconf to create configure
AC_PREREQ(2.59)
AC_INIT([libffi], [3.0.8], [http://gcc.gnu.org/bugs.html])
AC_CONFIG_HEADERS([fficonfig.h])
AC_CANONICAL_SYSTEM
target_alias=${target_alias-$host_alias}
. ${srcdir}/configure.host
AM_INIT_AUTOMAKE
# The same as in boehm-gc and libstdc++. Have to borrow it from there.
# We must force CC to /not/ be precious variables; otherwise
# the wrong, non-multilib-adjusted value will be used in multilibs.
# As a side effect, we have to subst CFLAGS ourselves.
m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
m4_define([_AC_ARG_VAR_PRECIOUS],[])
AC_PROG_CC
m4_rename([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
AC_SUBST(CFLAGS)
AM_PROG_AS
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
AM_MAINTAINER_MODE
AC_CHECK_HEADERS(sys/mman.h)
AC_CHECK_FUNCS(mmap)
AC_FUNC_MMAP_BLACKLIST
dnl The -no-testsuite modules omit the test subdir.
AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
TARGETDIR="unknown"
case "$host" in
alpha*-*-*)
TARGET=ALPHA; TARGETDIR=alpha;
# Support 128-bit long double, changable via command-line switch.
HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
;;
arm*-*-*)
TARGET=ARM; TARGETDIR=arm
;;
amd64-*-freebsd*)
TARGET=X86_64; TARGETDIR=x86
;;
cris-*-*)
TARGET=LIBFFI_CRIS; TARGETDIR=cris
;;
frv-*-*)
TARGET=FRV; TARGETDIR=frv
;;
hppa*-*-linux* | parisc*-*-linux*)
TARGET=PA_LINUX; TARGETDIR=pa
;;
hppa*64-*-hpux*)
TARGET=PA64_HPUX; TARGETDIR=pa
;;
hppa*-*-hpux*)
TARGET=PA_HPUX; TARGETDIR=pa
;;
i386-*-freebsd* | i386-*-openbsd*)
TARGET=X86_FREEBSD; TARGETDIR=x86
;;
i?86-win32* | i?86-*-cygwin* | i?86-*-mingw*)
TARGET=X86_WIN32; TARGETDIR=x86
;;
i?86-*-darwin*)
TARGET=X86_DARWIN; TARGETDIR=x86
;;
i?86-*-solaris2.1[[0-9]]*)
TARGET=X86_64; TARGETDIR=x86
;;
i?86-*-*)
TARGET=X86; TARGETDIR=x86
;;
ia64*-*-*)
TARGET=IA64; TARGETDIR=ia64
;;
m32r*-*-*)
TARGET=M32R; TARGETDIR=m32r
;;
m68k-*-*)
TARGET=M68K; TARGETDIR=m68k
;;
mips-sgi-irix5.* | mips-sgi-irix6.*)
TARGET=MIPS; TARGETDIR=mips
;;
mips*-*-linux*)
TARGET=MIPS; TARGETDIR=mips
;;
powerpc*-*-linux* | powerpc-*-sysv*)
TARGET=POWERPC; TARGETDIR=powerpc
;;
powerpc-*-beos*)
TARGET=POWERPC; TARGETDIR=powerpc
;;
powerpc-*-darwin*)
TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
;;
powerpc-*-aix* | rs6000-*-aix*)
TARGET=POWERPC_AIX; TARGETDIR=powerpc
;;
powerpc-*-freebsd*)
TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
;;
powerpc*-*-rtems*)
TARGET=POWERPC; TARGETDIR=powerpc
;;
s390-*-* | s390x-*-*)
TARGET=S390; TARGETDIR=s390
;;
sh-*-* | sh[[34]]*-*-*)
TARGET=SH; TARGETDIR=sh
;;
sh64-*-* | sh5*-*-*)
TARGET=SH64; TARGETDIR=sh64
;;
sparc*-*-*)
TARGET=SPARC; TARGETDIR=sparc
;;
x86_64-*-darwin*)
TARGET=X86_DARWIN; TARGETDIR=x86
;;
x86_64-*-cygwin* | x86_64-*-mingw*)
;;
x86_64-*-*)
TARGET=X86_64; TARGETDIR=x86
;;
esac
AC_SUBST(AM_RUNTESTFLAGS)
if test $TARGETDIR = unknown; then
AC_MSG_ERROR(["libffi has not been ported to $host."])
fi
AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
AM_CONDITIONAL(X86, test x$TARGET = xX86)
AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
AM_CONDITIONAL(ARM, test x$TARGET = xARM)
AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
AM_CONDITIONAL(S390, test x$TARGET = xS390)
AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
AM_CONDITIONAL(SH, test x$TARGET = xSH)
AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
AC_HEADER_STDC
AC_CHECK_FUNCS(memcpy)
AC_FUNC_ALLOCA
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(long double)
# Also AC_SUBST this variable for ffi.h.
if test -z "$HAVE_LONG_DOUBLE"; then
HAVE_LONG_DOUBLE=0
if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
if test $ac_cv_sizeof_long_double != 0; then
HAVE_LONG_DOUBLE=1
AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
fi
fi
fi
AC_SUBST(HAVE_LONG_DOUBLE)
AC_C_BIGENDIAN
AC_CACHE_CHECK([assembler .cfi pseudo-op support],
libffi_cv_as_cfi_pseudo_op, [
libffi_cv_as_cfi_pseudo_op=unknown
AC_TRY_COMPILE([asm (".cfi_startproc\n\t.cfi_endproc");],,
[libffi_cv_as_cfi_pseudo_op=yes],
[libffi_cv_as_cfi_pseudo_op=no])
])
if test "x$libffi_cv_as_cfi_pseudo_op" = xyes; then
AC_DEFINE(HAVE_AS_CFI_PSEUDO_OP, 1,
[Define if your assembler supports .cfi_* directives.])
fi
if test x$TARGET = xSPARC; then
AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
libffi_cv_as_sparc_ua_pcrel, [
save_CFLAGS="$CFLAGS"
save_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS -fpic"
LDFLAGS="$LDFLAGS -shared"
AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
[libffi_cv_as_sparc_ua_pcrel=yes],
[libffi_cv_as_sparc_ua_pcrel=no])
CFLAGS="$save_CFLAGS"
LDFLAGS="$save_LDFLAGS"])
if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
[Define if your assembler and linker support unaligned PC relative relocs.])
fi
AC_CACHE_CHECK([assembler .register pseudo-op support],
libffi_cv_as_register_pseudo_op, [
libffi_cv_as_register_pseudo_op=unknown
# Check if we have .register
AC_TRY_COMPILE([asm (".register %g2, #scratch");],,
[libffi_cv_as_register_pseudo_op=yes],
[libffi_cv_as_register_pseudo_op=no])
])
if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
[Define if your assembler supports .register.])
fi
fi
if test x$TARGET = xX86 || test x$TARGET = xX86_64; then
AC_CACHE_CHECK([assembler supports pc related relocs],
libffi_cv_as_x86_pcrel, [
libffi_cv_as_x86_pcrel=yes
echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
libffi_cv_as_x86_pcrel=no
fi
])
if test "x$libffi_cv_as_x86_pcrel" = xyes; then
AC_DEFINE(HAVE_AS_X86_PCREL, 1,
[Define if your assembler supports PC relative relocs.])
fi
fi
AC_CACHE_CHECK([whether .eh_frame section should be read-only],
libffi_cv_ro_eh_frame, [
libffi_cv_ro_eh_frame=no
echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
if $CC $CFLAGS -S -fpic -fexceptions -o conftest.s conftest.c > /dev/null 2>&1; then
if grep '.section.*eh_frame.*"a"' conftest.s > /dev/null; then
libffi_cv_ro_eh_frame=yes
elif grep '.section.*eh_frame.*#alloc' conftest.c \
| grep -v '#write' > /dev/null; then
libffi_cv_ro_eh_frame=yes
fi
fi
rm -f conftest.*
])
if test "x$libffi_cv_ro_eh_frame" = xyes; then
AC_DEFINE(HAVE_RO_EH_FRAME, 1,
[Define if .eh_frame sections should be read-only.])
AC_DEFINE(EH_FRAME_FLAGS, "a",
[Define to the flags needed for the .section .eh_frame directive.])
else
AC_DEFINE(EH_FRAME_FLAGS, "aw",
[Define to the flags needed for the .section .eh_frame directive.])
fi
AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
libffi_cv_hidden_visibility_attribute, [
echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1; }' > conftest.c
libffi_cv_hidden_visibility_attribute=no
if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
if grep '\.hidden.*foo' conftest.s >/dev/null; then
libffi_cv_hidden_visibility_attribute=yes
fi
fi
rm -f conftest.*
])
if test $libffi_cv_hidden_visibility_attribute = yes; then
AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
[Define if __attribute__((visibility("hidden"))) is supported.])
fi
AH_BOTTOM([
#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
#ifdef LIBFFI_ASM
#define FFI_HIDDEN(name) .hidden name
#else
#define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
#endif
#else
#ifdef LIBFFI_ASM
#define FFI_HIDDEN(name)
#else
#define FFI_HIDDEN
#endif
#endif
])
AC_SUBST(TARGET)
AC_SUBST(TARGETDIR)
AC_SUBST(SHELL)
AC_ARG_ENABLE(debug,
[ --enable-debug debugging mode],
if test "$enable_debug" = "yes"; then
AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
fi)
AC_ARG_ENABLE(structs,
[ --disable-structs omit code for struct support],
if test "$enable_structs" = "no"; then
AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
fi)
AC_ARG_ENABLE(raw-api,
[ --disable-raw-api make the raw api unavailable],
if test "$enable_raw_api" = "no"; then
AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
fi)
AC_ARG_ENABLE(purify-safety,
[ --enable-purify-safety purify-safe mode],
if test "$enable_purify_safety" = "yes"; then
AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
fi)
if test -n "$with_cross_host" &&
test x"$with_cross_host" != x"no"; then
toolexecdir='$(exec_prefix)/$(target_alias)'
toolexeclibdir='$(toolexecdir)/lib'
else
toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
toolexeclibdir='$(libdir)'
fi
multi_os_directory=`$CC -print-multi-os-directory`
case $multi_os_directory in
.) ;; # Avoid trailing /.
*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
esac
AC_SUBST(toolexecdir)
AC_SUBST(toolexeclibdir)
if test "${multilib}" = "yes"; then
multilib_arg="--enable-multilib"
else
multilib_arg=
fi
AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
AC_CONFIG_COMMANDS(src, [
test -d src || mkdir src
test -d src/$TARGETDIR || mkdir src/$TARGETDIR
], [TARGETDIR="$TARGETDIR"])
AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
AC_OUTPUT

View File

@@ -0,0 +1,11 @@
# configure.host
#
# This shell script handles all host based configuration for libffi.
#
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
case "${host}" in
frv*-elf)
LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
;;
esac

584
js/ctypes/libffi/depcomp Executable file
View File

@@ -0,0 +1,584 @@
#! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
scriptversion=2006-10-15.18
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
# Foundation, Inc.
# 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.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
case $1 in
'')
echo "$0: No command. Try \`$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
Run PROGRAMS ARGS to compile a file, generating dependencies
as side-effects.
Environment variables:
depmode Dependency tracking mode.
source Source file read by `PROGRAMS ARGS'.
object Object file output by `PROGRAMS ARGS'.
DEPDIR directory where to store dependencies.
depfile Dependency file to output.
tmpdepfile Temporary file to use when outputing dependencies.
libtool Whether libtool is used (yes/no).
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "depcomp $scriptversion"
exit $?
;;
esac
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
fi
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
depfile=${depfile-`echo "$object" |
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
# Some modes work just like other modes, but use different flags. We
# parameterize here, but still list the modes in the big case below,
# to make depend.m4 easier to write. Note that we *cannot* use a case
# here, because this file can only contain one case statement.
if test "$depmode" = hp; then
# HP compiler uses -M and no extra arg.
gccflag=-M
depmode=gcc
fi
if test "$depmode" = dashXmstdout; then
# This is just like dashmstdout with a different argument.
dashmflag=-xM
depmode=dashmstdout
fi
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
## it if -MD -MP comes after the -MF stuff. Hmm.
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
## the command line argument order; so add the flags where they
## appear in depend2.am. Note that the slowdown incurred here
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
for arg
do
case $arg in
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
*) set fnord "$@" "$arg" ;;
esac
shift # fnord
shift # $arg
done
"$@"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
mv "$tmpdepfile" "$depfile"
;;
gcc)
## There are various ways to get dependency output from gcc. Here's
## why we pick this rather obscure method:
## - Don't want to use -MD because we'd like the dependencies to end
## up in a subdir. Having to rename by hand is ugly.
## (We might end up doing this anyway to support other compilers.)
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
## -MM, not -M (despite what the docs say).
## - Using -M directly means running the compiler twice (even worse
## than renaming).
if test -z "$gccflag"; then
gccflag=-MD,
fi
"$@" -Wp,"$gccflag$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
## The second -e expression handles DOS-style file names with drive letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the `deleted header file' problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
tr ' ' '
' < "$tmpdepfile" |
## Some versions of gcc put a space before the `:'. On the theory
## that the space means something, we add a space to the output as
## well.
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
sgi)
if test "$libtool" = yes; then
"$@" "-Wp,-MDupdate,$tmpdepfile"
else
"$@" -MDupdate "$tmpdepfile"
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
echo "$object : \\" > "$depfile"
# Clip off the initial element (the dependent). Don't try to be
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
# the IRIX cc adds comments like `#:fec' to the end of the
# dependency line.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
tr '
' ' ' >> $depfile
echo >> $depfile
# The second pass generates a dummy entry for each header file.
tr ' ' '
' < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> $depfile
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. In older versions, this file always lives in the
# current directory. Also, the AIX compiler puts `$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
tmpdepfile="$stripped.u"
if test "$libtool" = yes; then
"$@" -Wc,-M
else
"$@" -M
fi
stat=$?
if test -f "$tmpdepfile"; then :
else
stripped=`echo "$stripped" | sed 's,^.*/,,'`
tmpdepfile="$stripped.u"
fi
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
if test -f "$tmpdepfile"; then
outname="$stripped.o"
# Each line is of the form `foo.o: dependent.h'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
else
# The sourcefile does not contain any dependencies, so just
# store a dummy comment line, to avoid errors with the Makefile
# "include basename.Plo" scheme.
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
icc)
# Intel's C compiler understands `-MD -MF file'. However on
# icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
# ICC 7.0 will fill foo.d with something like
# foo.o: sub/foo.c
# foo.o: sub/foo.h
# which is wrong. We want:
# sub/foo.o: sub/foo.c
# sub/foo.o: sub/foo.h
# sub/foo.c:
# sub/foo.h:
# ICC 7.1 will output
# foo.o: sub/foo.c sub/foo.h
# and will wrap long lines using \ :
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
"$@" -MD -MF "$tmpdepfile"
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
# Each line is of the form `foo.o: dependent.h',
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this invocation
# correctly. Breaking it into two sed invocations is a workaround.
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp2)
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
# compilers, which have integrated preprocessors. The correct option
# to use with these is +Maked; it writes dependencies to a file named
# 'foo.d', which lands next to the object file, wherever that
# happens to be.
# Much of this is similar to the tru64 case; see comments there.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir.libs/$base.d
"$@" -Wc,+Maked
else
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir$base.d
"$@" +Maked
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
# Add `dependent.h:' lines.
sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile" "$tmpdepfile2"
;;
tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side
# effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
# dependencies in `foo.d' instead, so we check for that too.
# Subdirectories are respected.
dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
test "x$dir" = "x$object" && dir=
base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
if test "$libtool" = yes; then
# With Tru64 cc, shared objects can also be used to make a
# static library. This mechanism is used in libtool 1.4 series to
# handle both shared and static libraries in a single compilation.
# With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
#
# With libtool 1.5 this exception was removed, and libtool now
# generates 2 separate objects for the 2 libraries. These two
# compilations output dependencies in $dir.libs/$base.o.d and
# in $dir$base.o.d. We have to check for both files, because
# one of the two compilations can be disabled. We should prefer
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
# automatically cleaned when .libs/ is deleted, while ignoring
# the former would cause a distcleancheck panic.
tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4
tmpdepfile2=$dir$base.o.d # libtool 1.5
tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5
tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504
"$@" -Wc,-MD
else
tmpdepfile1=$dir$base.o.d
tmpdepfile2=$dir$base.d
tmpdepfile3=$dir$base.d
tmpdepfile4=$dir$base.d
"$@" -MD
fi
stat=$?
if test $stat -eq 0; then :
else
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
# That's a tab and a space in the [].
sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
else
echo "#dummy" > "$depfile"
fi
rm -f "$tmpdepfile"
;;
#nosideeffect)
# This comment above is used by automake to tell side-effect
# dependency tracking mechanisms from slower ones.
dashmstdout)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# Remove `-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
test -z "$dashmflag" && dashmflag=-M
# Require at least two characters before searching for `:'
# in the target name. This is to cope with DOS-style filenames:
# a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
"$@" $dashmflag |
sed 's:^[ ]*[^: ][^:][^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
tr ' ' '
' < "$tmpdepfile" | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
dashXmstdout)
# This case only exists to satisfy depend.m4. It is never actually
# run, as this mode is specially recognized in the preamble.
exit 1
;;
makedepend)
"$@" || exit $?
# Remove any Libtool call
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# X makedepend
shift
cleared=no
for arg in "$@"; do
case $cleared in
no)
set ""; shift
cleared=yes ;;
esac
case "$arg" in
-D*|-I*)
set fnord "$@" "$arg"; shift ;;
# Strip any option that makedepend may not understand. Remove
# the object too, otherwise makedepend will parse it as a source file.
-*|$object)
;;
*)
set fnord "$@" "$arg"; shift ;;
esac
done
obj_suffix="`echo $object | sed 's/^.*\././'`"
touch "$tmpdepfile"
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
sed '1,2d' "$tmpdepfile" | tr ' ' '
' | \
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile" "$tmpdepfile".bak
;;
cpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test $1 != '--mode=compile'; do
shift
done
shift
fi
# Remove `-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
"$@" -E |
sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
sed '$ s: \\$::' > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
cat < "$tmpdepfile" >> "$depfile"
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
msvisualcpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o,
# because we must use -o when running libtool.
"$@" || exit $?
IFS=" "
for arg
do
case "$arg" in
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
set fnord "$@"
shift
shift
;;
*)
set fnord "$@" "$arg"
shift
shift
;;
esac
done
"$@" -E |
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile"
echo " " >> "$depfile"
. "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;
none)
exec "$@"
;;
*)
echo "Unknown depmode $depmode" 1>&2
exit 1
;;
esac
exit 0
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@@ -0,0 +1,533 @@
This is doc/libffi.info, produced by makeinfo version 4.12 from
./doc/libffi.texi.
This manual is for Libffi, a portable foreign-function interface
library.
Copyright (C) 2008 Red Hat, Inc.
Permission is granted to copy, distribute and/or modify this
document 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. A copy of the license is
included in the section entitled "GNU General Public License".
INFO-DIR-SECTION
START-INFO-DIR-ENTRY
* libffi: (libffi). Portable foreign-function interface library.
END-INFO-DIR-ENTRY

File: libffi.info, Node: Top, Next: Introduction, Up: (dir)
libffi
******
This manual is for Libffi, a portable foreign-function interface
library.
Copyright (C) 2008 Red Hat, Inc.
Permission is granted to copy, distribute and/or modify this
document 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. A copy of the license is
included in the section entitled "GNU General Public License".
* Menu:
* Introduction:: What is libffi?
* Using libffi:: How to use libffi.
* Missing Features:: Things libffi can't do.
* Index:: Index.

File: libffi.info, Node: Introduction, Next: Using libffi, Prev: Top, Up: Top
1 What is libffi?
*****************
Compilers for high level languages generate code that follow certain
conventions. These conventions are necessary, in part, for separate
compilation to work. One such convention is the "calling convention".
The calling convention is a set of assumptions made by the compiler
about where function arguments will be found on entry to a function. A
calling convention also specifies where the return value for a function
is found. The calling convention is also sometimes called the "ABI" or
"Application Binary Interface".
Some programs may not know at the time of compilation what arguments
are to be passed to a function. For instance, an interpreter may be
told at run-time about the number and types of arguments used to call a
given function. `Libffi' can be used in such programs to provide a
bridge from the interpreter program to compiled code.
The `libffi' library provides a portable, high level programming
interface to various calling conventions. This allows a programmer to
call any function specified by a call interface description at run time.
FFI stands for Foreign Function Interface. A foreign function
interface is the popular name for the interface that allows code
written in one language to call code written in another language. The
`libffi' library really only provides the lowest, machine dependent
layer of a fully featured foreign function interface. A layer must
exist above `libffi' that handles type conversions for values passed
between the two languages.

File: libffi.info, Node: Using libffi, Next: Missing Features, Prev: Introduction, Up: Top
2 Using libffi
**************
* Menu:
* The Basics:: The basic libffi API.
* Simple Example:: A simple example.
* Types:: libffi type descriptions.
* Multiple ABIs:: Different passing styles on one platform.
* The Closure API:: Writing a generic function.

File: libffi.info, Node: The Basics, Next: Simple Example, Up: Using libffi
2.1 The Basics
==============
`Libffi' assumes that you have a pointer to the function you wish to
call and that you know the number and types of arguments to pass it, as
well as the return type of the function.
The first thing you must do is create an `ffi_cif' object that
matches the signature of the function you wish to call. This is a
separate step because it is common to make multiple calls using a
single `ffi_cif'. The "cif" in `ffi_cif' stands for Call InterFace.
To prepare a call interface object, use the function `ffi_prep_cif'.
-- Function: ffi_status ffi_prep_cif (ffi_cif *CIF, ffi_abi ABI,
unsigned int NARGS, ffi_type *RTYPE, ffi_type **ARGTYPES)
This initializes CIF according to the given parameters.
ABI is the ABI to use; normally `FFI_DEFAULT_ABI' is what you
want. *note Multiple ABIs:: for more information.
NARGS is the number of arguments that this function accepts.
`libffi' does not yet handle varargs functions; see *note Missing
Features:: for more information.
RTYPE is a pointer to an `ffi_type' structure that describes the
return type of the function. *Note Types::.
ARGTYPES is a vector of `ffi_type' pointers. ARGTYPES must have
NARGS elements. If NARGS is 0, this argument is ignored.
`ffi_prep_cif' returns a `libffi' status code, of type
`ffi_status'. This will be either `FFI_OK' if everything worked
properly; `FFI_BAD_TYPEDEF' if one of the `ffi_type' objects is
incorrect; or `FFI_BAD_ABI' if the ABI parameter is invalid.
To call a function using an initialized `ffi_cif', use the
`ffi_call' function:
-- Function: void ffi_call (ffi_cif *CIF, void *FN, void *RVALUE, void
**AVALUES)
This calls the function FN according to the description given in
CIF. CIF must have already been prepared using `ffi_prep_cif'.
RVALUE is a pointer to a chunk of memory that will hold the result
of the function call. This must be large enough to hold the
result and must be suitably aligned; it is the caller's
responsibility to ensure this. If CIF declares that the function
returns `void' (using `ffi_type_void'), then RVALUE is ignored.
If RVALUE is `NULL', then the return value is discarded.
AVALUES is a vector of `void *' pointers that point to the memory
locations holding the argument values for a call. If CIF declares
that the function has no arguments (i.e., NARGS was 0), then
AVALUES is ignored.

File: libffi.info, Node: Simple Example, Next: Types, Prev: The Basics, Up: Using libffi
2.2 Simple Example
==================
Here is a trivial example that calls `puts' a few times.
#include <stdio.h>
#include <ffi.h>
int main()
{
ffi_cif cif;
ffi_type *args[1];
void *values[1];
char *s;
int rc;
/* Initialize the argument info vectors */
args[0] = &ffi_type_pointer;
values[0] = &s;
/* Initialize the cif */
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_uint, args) == FFI_OK)
{
s = "Hello World!";
ffi_call(&cif, puts, &rc, values);
/* rc now holds the result of the call to puts */
/* values holds a pointer to the function's arg, so to
call puts() again all we need to do is change the
value of s */
s = "This is cool!";
ffi_call(&cif, puts, &rc, values);
}
return 0;
}

File: libffi.info, Node: Types, Next: Multiple ABIs, Prev: Simple Example, Up: Using libffi
2.3 Types
=========
* Menu:
* Primitive Types:: Built-in types.
* Structures:: Structure types.
* Type Example:: Structure type example.

File: libffi.info, Node: Primitive Types, Next: Structures, Up: Types
2.3.1 Primitive Types
---------------------
`Libffi' provides a number of built-in type descriptors that can be
used to describe argument and return types:
`ffi_type_void'
The type `void'. This cannot be used for argument types, only for
return values.
`ffi_type_uint8'
An unsigned, 8-bit integer type.
`ffi_type_sint8'
A signed, 8-bit integer type.
`ffi_type_uint16'
An unsigned, 16-bit integer type.
`ffi_type_sint16'
A signed, 16-bit integer type.
`ffi_type_uint32'
An unsigned, 32-bit integer type.
`ffi_type_sint32'
A signed, 32-bit integer type.
`ffi_type_uint64'
An unsigned, 64-bit integer type.
`ffi_type_sint64'
A signed, 64-bit integer type.
`ffi_type_float'
The C `float' type.
`ffi_type_double'
The C `double' type.
`ffi_type_uchar'
The C `unsigned char' type.
`ffi_type_schar'
The C `signed char' type. (Note that there is not an exact
equivalent to the C `char' type in `libffi'; ordinarily you should
either use `ffi_type_schar' or `ffi_type_uchar' depending on
whether `char' is signed.)
`ffi_type_ushort'
The C `unsigned short' type.
`ffi_type_sshort'
The C `short' type.
`ffi_type_uint'
The C `unsigned int' type.
`ffi_type_sint'
The C `int' type.
`ffi_type_ulong'
The C `unsigned long' type.
`ffi_type_slong'
The C `long' type.
`ffi_type_longdouble'
On platforms that have a C `long double' type, this is defined.
On other platforms, it is not.
`ffi_type_pointer'
A generic `void *' pointer. You should use this for all pointers,
regardless of their real type.
Each of these is of type `ffi_type', so you must take the address
when passing to `ffi_prep_cif'.

File: libffi.info, Node: Structures, Next: Type Example, Prev: Primitive Types, Up: Types
2.3.2 Structures
----------------
Although `libffi' has no special support for unions or bit-fields, it
is perfectly happy passing structures back and forth. You must first
describe the structure to `libffi' by creating a new `ffi_type' object
for it.
-- ffi_type:
The `ffi_type' has the following members:
`size_t size'
This is set by `libffi'; you should initialize it to zero.
`unsigned short alignment'
This is set by `libffi'; you should initialize it to zero.
`unsigned short type'
For a structure, this should be set to `FFI_TYPE_STRUCT'.
`ffi_type **elements'
This is a `NULL'-terminated array of pointers to `ffi_type'
objects. There is one element per field of the struct.

File: libffi.info, Node: Type Example, Prev: Structures, Up: Types
2.3.3 Type Example
------------------
The following example initializes a `ffi_type' object representing the
`tm' struct from Linux's `time.h'.
Here is how the struct is defined:
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
/* Those are for future use. */
long int __tm_gmtoff__;
__const char *__tm_zone__;
};
Here is the corresponding code to describe this struct to `libffi':
{
ffi_type tm_type;
ffi_type *tm_type_elements[12];
int i;
tm_type.size = tm_type.alignment = 0;
tm_type.elements = &tm_type_elements;
for (i = 0; i < 9; i++)
tm_type_elements[i] = &ffi_type_sint;
tm_type_elements[9] = &ffi_type_slong;
tm_type_elements[10] = &ffi_type_pointer;
tm_type_elements[11] = NULL;
/* tm_type can now be used to represent tm argument types and
return types for ffi_prep_cif() */
}

File: libffi.info, Node: Multiple ABIs, Next: The Closure API, Prev: Types, Up: Using libffi
2.4 Multiple ABIs
=================
A given platform may provide multiple different ABIs at once. For
instance, the x86 platform has both `stdcall' and `fastcall' functions.
`libffi' provides some support for this. However, this is
necessarily platform-specific.

File: libffi.info, Node: The Closure API, Prev: Multiple ABIs, Up: Using libffi
2.5 The Closure API
===================
`libffi' also provides a way to write a generic function - a function
that can accept and decode any combination of arguments. This can be
useful when writing an interpreter, or to provide wrappers for
arbitrary functions.
This facility is called the "closure API". Closures are not
supported on all platforms; you can check the `FFI_CLOSURES' define to
determine whether they are supported on the current platform.
Because closures work by assembling a tiny function at runtime, they
require special allocation on platforms that have a non-executable
heap. Memory management for closures is handled by a pair of functions:
-- Function: void *ffi_closure_alloc (size_t SIZE, void **CODE)
Allocate a chunk of memory holding SIZE bytes. This returns a
pointer to the writable address, and sets *CODE to the
corresponding executable address.
SIZE should be sufficient to hold a `ffi_closure' object.
-- Function: void ffi_closure_free (void *WRITABLE)
Free memory allocated using `ffi_closure_alloc'. The argument is
the writable address that was returned.
Once you have allocated the memory for a closure, you must construct
a `ffi_cif' describing the function call. Finally you can prepare the
closure function:
-- Function: ffi_status ffi_prep_closure_loc (ffi_closure *CLOSURE,
ffi_cif *CIF, void (*FUN) (ffi_cif *CIF, void *RET, void
**ARGS, void *USER_DATA), void *USER_DATA, void *CODELOC)
Prepare a closure function.
CLOSURE is the address of a `ffi_closure' object; this is the
writable address returned by `ffi_closure_alloc'.
CIF is the `ffi_cif' describing the function parameters.
USER_DATA is an arbitrary datum that is passed, uninterpreted, to
your closure function.
CODELOC is the executable address returned by `ffi_closure_alloc'.
FUN is the function which will be called when the closure is
invoked. It is called with the arguments:
CIF
The `ffi_cif' passed to `ffi_prep_closure_loc'.
RET
A pointer to the memory used for the function's return value.
FUN must fill this, unless the function is declared as
returning `void'.
ARGS
A vector of pointers to memory holding the arguments to the
function.
USER_DATA
The same USER_DATA that was passed to `ffi_prep_closure_loc'.
`ffi_prep_closure_loc' will return `FFI_OK' if everything went ok,
and something else on error.
After calling `ffi_prep_closure_loc', you can cast CODELOC to the
appropriate pointer-to-function type.
You may see old code referring to `ffi_prep_closure'. This function
is deprecated, as it cannot handle the need for separate writable and
executable addresses.

File: libffi.info, Node: Missing Features, Next: Index, Prev: Using libffi, Up: Top
3 Missing Features
******************
`libffi' is missing a few features. We welcome patches to add support
for these.
* There is no support for calling varargs functions. This may work
on some platforms, depending on how the ABI is defined, but it is
not reliable.
* There is no support for bit fields in structures.
* The closure API is
* The "raw" API is undocumented.

File: libffi.info, Node: Index, Prev: Missing Features, Up: Top
Index
*****
[index]
* Menu:
* : Structures. (line 12)
* ABI: Introduction. (line 13)
* Application Binary Interface: Introduction. (line 13)
* calling convention: Introduction. (line 13)
* cif: The Basics. (line 14)
* closure API: The Closure API. (line 13)
* closures: The Closure API. (line 13)
* FFI: Introduction. (line 31)
* ffi_call: The Basics. (line 41)
* ffi_closure_alloca: The Closure API. (line 19)
* ffi_closure_free: The Closure API. (line 26)
* FFI_CLOSURES: The Closure API. (line 13)
* ffi_prep_cif: The Basics. (line 16)
* ffi_prep_closure_loc: The Closure API. (line 34)
* ffi_status <1>: The Closure API. (line 37)
* ffi_status: The Basics. (line 18)
* ffi_type: Structures. (line 11)
* ffi_type_double: Primitive Types. (line 41)
* ffi_type_float: Primitive Types. (line 38)
* ffi_type_longdouble: Primitive Types. (line 71)
* ffi_type_pointer: Primitive Types. (line 75)
* ffi_type_schar: Primitive Types. (line 47)
* ffi_type_sint: Primitive Types. (line 62)
* ffi_type_sint16: Primitive Types. (line 23)
* ffi_type_sint32: Primitive Types. (line 29)
* ffi_type_sint64: Primitive Types. (line 35)
* ffi_type_sint8: Primitive Types. (line 17)
* ffi_type_slong: Primitive Types. (line 68)
* ffi_type_sshort: Primitive Types. (line 56)
* ffi_type_uchar: Primitive Types. (line 44)
* ffi_type_uint: Primitive Types. (line 59)
* ffi_type_uint16: Primitive Types. (line 20)
* ffi_type_uint32: Primitive Types. (line 26)
* ffi_type_uint64: Primitive Types. (line 32)
* ffi_type_uint8: Primitive Types. (line 14)
* ffi_type_ulong: Primitive Types. (line 65)
* ffi_type_ushort: Primitive Types. (line 53)
* ffi_type_void: Primitive Types. (line 10)
* Foreign Function Interface: Introduction. (line 31)
* void <1>: The Closure API. (line 20)
* void: The Basics. (line 43)

Tag Table:
Node: Top670
Node: Introduction1406
Node: Using libffi3042
Node: The Basics3477
Node: Simple Example6084
Node: Types7111
Node: Primitive Types7394
Node: Structures9214
Node: Type Example10074
Node: Multiple ABIs11297
Node: The Closure API11668
Node: Missing Features14588
Node: Index15081

End Tag Table

View File

@@ -0,0 +1,541 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename libffi.info
@settitle libffi
@setchapternewpage off
@c %**end of header
@c Merge the standard indexes into a single one.
@syncodeindex fn cp
@syncodeindex vr cp
@syncodeindex ky cp
@syncodeindex pg cp
@syncodeindex tp cp
@include version.texi
@copying
This manual is for Libffi, a portable foreign-function interface
library.
Copyright @copyright{} 2008 Red Hat, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
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. A copy of the license is included in the
section entitled ``GNU General Public License''.
@end quotation
@end copying
@dircategory
@direntry
* libffi: (libffi). Portable foreign-function interface library.
@end direntry
@titlepage
@title Libffi
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@ifnottex
@node Top
@top libffi
@insertcopying
@menu
* Introduction:: What is libffi?
* Using libffi:: How to use libffi.
* Missing Features:: Things libffi can't do.
* Index:: Index.
@end menu
@end ifnottex
@node Introduction
@chapter What is libffi?
Compilers for high level languages generate code that follow certain
conventions. These conventions are necessary, in part, for separate
compilation to work. One such convention is the @dfn{calling
convention}. The calling convention is a set of assumptions made by
the compiler about where function arguments will be found on entry to
a function. A calling convention also specifies where the return
value for a function is found. The calling convention is also
sometimes called the @dfn{ABI} or @dfn{Application Binary Interface}.
@cindex calling convention
@cindex ABI
@cindex Application Binary Interface
Some programs may not know at the time of compilation what arguments
are to be passed to a function. For instance, an interpreter may be
told at run-time about the number and types of arguments used to call
a given function. @samp{Libffi} can be used in such programs to
provide a bridge from the interpreter program to compiled code.
The @samp{libffi} library provides a portable, high level programming
interface to various calling conventions. This allows a programmer to
call any function specified by a call interface description at run
time.
@acronym{FFI} stands for Foreign Function Interface. A foreign
function interface is the popular name for the interface that allows
code written in one language to call code written in another language.
The @samp{libffi} library really only provides the lowest, machine
dependent layer of a fully featured foreign function interface. A
layer must exist above @samp{libffi} that handles type conversions for
values passed between the two languages.
@cindex FFI
@cindex Foreign Function Interface
@node Using libffi
@chapter Using libffi
@menu
* The Basics:: The basic libffi API.
* Simple Example:: A simple example.
* Types:: libffi type descriptions.
* Multiple ABIs:: Different passing styles on one platform.
* The Closure API:: Writing a generic function.
@end menu
@node The Basics
@section The Basics
@samp{Libffi} assumes that you have a pointer to the function you wish
to call and that you know the number and types of arguments to pass
it, as well as the return type of the function.
The first thing you must do is create an @code{ffi_cif} object that
matches the signature of the function you wish to call. This is a
separate step because it is common to make multiple calls using a
single @code{ffi_cif}. The @dfn{cif} in @code{ffi_cif} stands for
Call InterFace. To prepare a call interface object, use the function
@code{ffi_prep_cif}.
@cindex cif
@findex ffi_prep_cif
@defun ffi_status ffi_prep_cif (ffi_cif *@var{cif}, ffi_abi @var{abi}, unsigned int @var{nargs}, ffi_type *@var{rtype}, ffi_type **@var{argtypes})
This initializes @var{cif} according to the given parameters.
@var{abi} is the ABI to use; normally @code{FFI_DEFAULT_ABI} is what
you want. @ref{Multiple ABIs} for more information.
@var{nargs} is the number of arguments that this function accepts.
@samp{libffi} does not yet handle varargs functions; see @ref{Missing
Features} for more information.
@var{rtype} is a pointer to an @code{ffi_type} structure that
describes the return type of the function. @xref{Types}.
@var{argtypes} is a vector of @code{ffi_type} pointers.
@var{argtypes} must have @var{nargs} elements. If @var{nargs} is 0,
this argument is ignored.
@code{ffi_prep_cif} returns a @code{libffi} status code, of type
@code{ffi_status}. This will be either @code{FFI_OK} if everything
worked properly; @code{FFI_BAD_TYPEDEF} if one of the @code{ffi_type}
objects is incorrect; or @code{FFI_BAD_ABI} if the @var{abi} parameter
is invalid.
@end defun
To call a function using an initialized @code{ffi_cif}, use the
@code{ffi_call} function:
@findex ffi_call
@defun void ffi_call (ffi_cif *@var{cif}, void *@var{fn}, void *@var{rvalue}, void **@var{avalues})
This calls the function @var{fn} according to the description given in
@var{cif}. @var{cif} must have already been prepared using
@code{ffi_prep_cif}.
@var{rvalue} is a pointer to a chunk of memory that will hold the
result of the function call. This must be large enough to hold the
result and must be suitably aligned; it is the caller's responsibility
to ensure this. If @var{cif} declares that the function returns
@code{void} (using @code{ffi_type_void}), then @var{rvalue} is
ignored. If @var{rvalue} is @samp{NULL}, then the return value is
discarded.
@var{avalues} is a vector of @code{void *} pointers that point to the
memory locations holding the argument values for a call. If @var{cif}
declares that the function has no arguments (i.e., @var{nargs} was 0),
then @var{avalues} is ignored.
@end defun
@node Simple Example
@section Simple Example
Here is a trivial example that calls @code{puts} a few times.
@example
#include <stdio.h>
#include <ffi.h>
int main()
@{
ffi_cif cif;
ffi_type *args[1];
void *values[1];
char *s;
int rc;
/* Initialize the argument info vectors */
args[0] = &ffi_type_pointer;
values[0] = &s;
/* Initialize the cif */
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_uint, args) == FFI_OK)
@{
s = "Hello World!";
ffi_call(&cif, puts, &rc, values);
/* rc now holds the result of the call to puts */
/* values holds a pointer to the function's arg, so to
call puts() again all we need to do is change the
value of s */
s = "This is cool!";
ffi_call(&cif, puts, &rc, values);
@}
return 0;
@}
@end example
@node Types
@section Types
@menu
* Primitive Types:: Built-in types.
* Structures:: Structure types.
* Type Example:: Structure type example.
@end menu
@node Primitive Types
@subsection Primitive Types
@code{Libffi} provides a number of built-in type descriptors that can
be used to describe argument and return types:
@table @code
@item ffi_type_void
@tindex ffi_type_void
The type @code{void}. This cannot be used for argument types, only
for return values.
@item ffi_type_uint8
@tindex ffi_type_uint8
An unsigned, 8-bit integer type.
@item ffi_type_sint8
@tindex ffi_type_sint8
A signed, 8-bit integer type.
@item ffi_type_uint16
@tindex ffi_type_uint16
An unsigned, 16-bit integer type.
@item ffi_type_sint16
@tindex ffi_type_sint16
A signed, 16-bit integer type.
@item ffi_type_uint32
@tindex ffi_type_uint32
An unsigned, 32-bit integer type.
@item ffi_type_sint32
@tindex ffi_type_sint32
A signed, 32-bit integer type.
@item ffi_type_uint64
@tindex ffi_type_uint64
An unsigned, 64-bit integer type.
@item ffi_type_sint64
@tindex ffi_type_sint64
A signed, 64-bit integer type.
@item ffi_type_float
@tindex ffi_type_float
The C @code{float} type.
@item ffi_type_double
@tindex ffi_type_double
The C @code{double} type.
@item ffi_type_uchar
@tindex ffi_type_uchar
The C @code{unsigned char} type.
@item ffi_type_schar
@tindex ffi_type_schar
The C @code{signed char} type. (Note that there is not an exact
equivalent to the C @code{char} type in @code{libffi}; ordinarily you
should either use @code{ffi_type_schar} or @code{ffi_type_uchar}
depending on whether @code{char} is signed.)
@item ffi_type_ushort
@tindex ffi_type_ushort
The C @code{unsigned short} type.
@item ffi_type_sshort
@tindex ffi_type_sshort
The C @code{short} type.
@item ffi_type_uint
@tindex ffi_type_uint
The C @code{unsigned int} type.
@item ffi_type_sint
@tindex ffi_type_sint
The C @code{int} type.
@item ffi_type_ulong
@tindex ffi_type_ulong
The C @code{unsigned long} type.
@item ffi_type_slong
@tindex ffi_type_slong
The C @code{long} type.
@item ffi_type_longdouble
@tindex ffi_type_longdouble
On platforms that have a C @code{long double} type, this is defined.
On other platforms, it is not.
@item ffi_type_pointer
@tindex ffi_type_pointer
A generic @code{void *} pointer. You should use this for all
pointers, regardless of their real type.
@end table
Each of these is of type @code{ffi_type}, so you must take the address
when passing to @code{ffi_prep_cif}.
@node Structures
@subsection Structures
Although @samp{libffi} has no special support for unions or
bit-fields, it is perfectly happy passing structures back and forth.
You must first describe the structure to @samp{libffi} by creating a
new @code{ffi_type} object for it.
@tindex ffi_type
@deftp ffi_type
The @code{ffi_type} has the following members:
@table @code
@item size_t size
This is set by @code{libffi}; you should initialize it to zero.
@item unsigned short alignment
This is set by @code{libffi}; you should initialize it to zero.
@item unsigned short type
For a structure, this should be set to @code{FFI_TYPE_STRUCT}.
@item ffi_type **elements
This is a @samp{NULL}-terminated array of pointers to @code{ffi_type}
objects. There is one element per field of the struct.
@end table
@end deftp
@node Type Example
@subsection Type Example
The following example initializes a @code{ffi_type} object
representing the @code{tm} struct from Linux's @file{time.h}.
Here is how the struct is defined:
@example
struct tm @{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
/* Those are for future use. */
long int __tm_gmtoff__;
__const char *__tm_zone__;
@};
@end example
Here is the corresponding code to describe this struct to
@code{libffi}:
@example
@{
ffi_type tm_type;
ffi_type *tm_type_elements[12];
int i;
tm_type.size = tm_type.alignment = 0;
tm_type.elements = &tm_type_elements;
for (i = 0; i < 9; i++)
tm_type_elements[i] = &ffi_type_sint;
tm_type_elements[9] = &ffi_type_slong;
tm_type_elements[10] = &ffi_type_pointer;
tm_type_elements[11] = NULL;
/* tm_type can now be used to represent tm argument types and
return types for ffi_prep_cif() */
@}
@end example
@node Multiple ABIs
@section Multiple ABIs
A given platform may provide multiple different ABIs at once. For
instance, the x86 platform has both @samp{stdcall} and @samp{fastcall}
functions.
@code{libffi} provides some support for this. However, this is
necessarily platform-specific.
@c FIXME: document the platforms
@node The Closure API
@section The Closure API
@code{libffi} also provides a way to write a generic function -- a
function that can accept and decode any combination of arguments.
This can be useful when writing an interpreter, or to provide wrappers
for arbitrary functions.
This facility is called the @dfn{closure API}. Closures are not
supported on all platforms; you can check the @code{FFI_CLOSURES}
define to determine whether they are supported on the current
platform.
@cindex closures
@cindex closure API
@findex FFI_CLOSURES
Because closures work by assembling a tiny function at runtime, they
require special allocation on platforms that have a non-executable
heap. Memory management for closures is handled by a pair of
functions:
@findex ffi_closure_alloca
@defun void *ffi_closure_alloc (size_t @var{size}, void **@var{code})
Allocate a chunk of memory holding @var{size} bytes. This returns a
pointer to the writable address, and sets *@var{code} to the
corresponding executable address.
@var{size} should be sufficient to hold a @code{ffi_closure} object.
@end defun
@findex ffi_closure_free
@defun void ffi_closure_free (void *@var{writable})
Free memory allocated using @code{ffi_closure_alloc}. The argument is
the writable address that was returned.
@end defun
Once you have allocated the memory for a closure, you must construct a
@code{ffi_cif} describing the function call. Finally you can prepare
the closure function:
@findex ffi_prep_closure_loc
@defun ffi_status ffi_prep_closure_loc (ffi_closure *@var{closure}, ffi_cif *@var{cif}, void (*@var{fun}) (ffi_cif *@var{cif}, void *@var{ret}, void **@var{args}, void *@var{user_data}), void *@var{user_data}, void *@var{codeloc})
Prepare a closure function.
@var{closure} is the address of a @code{ffi_closure} object; this is
the writable address returned by @code{ffi_closure_alloc}.
@var{cif} is the @code{ffi_cif} describing the function parameters.
@var{user_data} is an arbitrary datum that is passed, uninterpreted,
to your closure function.
@var{codeloc} is the executable address returned by
@code{ffi_closure_alloc}.
@var{fun} is the function which will be called when the closure is
invoked. It is called with the arguments:
@table @var
@item cif
The @code{ffi_cif} passed to @code{ffi_prep_closure_loc}.
@item ret
A pointer to the memory used for the function's return value.
@var{fun} must fill this, unless the function is declared as returning
@code{void}.
@c FIXME: is this NULL for void-returning functions?
@item args
A vector of pointers to memory holding the arguments to the function.
@item user_data
The same @var{user_data} that was passed to
@code{ffi_prep_closure_loc}.
@end table
@code{ffi_prep_closure_loc} will return @code{FFI_OK} if everything
went ok, and something else on error.
@c FIXME: what?
After calling @code{ffi_prep_closure_loc}, you can cast @var{codeloc}
to the appropriate pointer-to-function type.
@end defun
@c FIXME: example
You may see old code referring to @code{ffi_prep_closure}. This
function is deprecated, as it cannot handle the need for separate
writable and executable addresses.
@node Missing Features
@chapter Missing Features
@code{libffi} is missing a few features. We welcome patches to add
support for these.
@itemize @bullet
@item
There is no support for calling varargs functions. This may work on
some platforms, depending on how the ABI is defined, but it is not
reliable.
@item
There is no support for bit fields in structures.
@item
The closure API is
@item
The ``raw'' API is undocumented.
@c argument promotion?
@c unions?
@c anything else?
@end itemize
@node Index
@unnumbered Index
@printindex cp
@bye

View File

@@ -0,0 +1,4 @@
@set UPDATED 14 February 2008
@set UPDATED-MONTH February 2008
@set EDITION 3.0.8
@set VERSION 3.0.8

View File

@@ -0,0 +1,4 @@
@set UPDATED 14 February 2008
@set UPDATED-MONTH February 2008
@set EDITION 3.0.8
@set VERSION 3.0.8

View File

@@ -0,0 +1,163 @@
/* fficonfig.h.in. Generated from configure.ac by autoheader. */
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
*/
#undef CRAY_STACKSEG_END
/* Define to 1 if using `alloca.c'. */
#undef C_ALLOCA
/* Define to the flags needed for the .section .eh_frame directive. */
#undef EH_FRAME_FLAGS
/* Define this if you want extra debugging. */
#undef FFI_DEBUG
/* Define this is you do not want support for the raw API. */
#undef FFI_NO_RAW_API
/* Define this is you do not want support for aggregate types. */
#undef FFI_NO_STRUCTS
/* Define to 1 if you have `alloca', as a function or macro. */
#undef HAVE_ALLOCA
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#undef HAVE_ALLOCA_H
/* Define if your assembler supports .cfi_* directives. */
#undef HAVE_AS_CFI_PSEUDO_OP
/* Define if your assembler supports .register. */
#undef HAVE_AS_REGISTER_PSEUDO_OP
/* Define if your assembler and linker support unaligned PC relative relocs.
*/
#undef HAVE_AS_SPARC_UA_PCREL
/* Define if your assembler supports PC relative relocs. */
#undef HAVE_AS_X86_PCREL
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define if __attribute__((visibility("hidden"))) is supported. */
#undef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define if you have the long double type and it is bigger than a double */
#undef HAVE_LONG_DOUBLE
/* Define to 1 if you have the `memcpy' function. */
#undef HAVE_MEMCPY
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP
/* Define if mmap with MAP_ANON(YMOUS) works. */
#undef HAVE_MMAP_ANON
/* Define if mmap of /dev/zero works. */
#undef HAVE_MMAP_DEV_ZERO
/* Define if read-only mmap of a plain file works. */
#undef HAVE_MMAP_FILE
/* Define if .eh_frame sections should be read-only. */
#undef HAVE_RO_EH_FRAME
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#undef NO_MINUS_C_MINUS_O
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `double', as computed by sizeof. */
#undef SIZEOF_DOUBLE
/* The size of `long double', as computed by sizeof. */
#undef SIZEOF_LONG_DOUBLE
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#undef STACK_DIRECTION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define this if you are using Purify and want to suppress spurious messages.
*/
#undef USING_PURIFY
/* Version number of package */
#undef VERSION
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
#ifdef LIBFFI_ASM
#define FFI_HIDDEN(name) .hidden name
#else
#define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
#endif
#else
#ifdef LIBFFI_ASM
#define FFI_HIDDEN(name)
#else
#define FFI_HIDDEN
#endif
#endif

View File

@@ -0,0 +1,9 @@
## Process this with automake to create Makefile.in
AUTOMAKE_OPTIONS=foreign
DISTCLEANFILES=ffitarget.h
EXTRA_DIST=ffi.h.in ffi_common.h
includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
nodist_includes_HEADERS = ffi.h ffitarget.h

View File

@@ -0,0 +1,424 @@
# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = include
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/ffi.h.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/fficonfig.h
CONFIG_CLEAN_FILES = ffi.h ffitarget.h
SOURCES =
DIST_SOURCES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
am__installdirs = "$(DESTDIR)$(includesdir)"
nodist_includesHEADERS_INSTALL = $(INSTALL_HEADER)
HEADERS = $(nodist_includes_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AM_RUNTESTFLAGS = @AM_RUNTESTFLAGS@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCAS = @CCAS@
CCASDEPMODE = @CCASDEPMODE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NMEDIT = @NMEDIT@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TARGET = @TARGET@
TARGETDIR = @TARGETDIR@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
toolexecdir = @toolexecdir@
toolexeclibdir = @toolexeclibdir@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = foreign
DISTCLEANFILES = ffitarget.h
EXTRA_DIST = ffi.h.in ffi_common.h
includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
nodist_includes_HEADERS = ffi.h ffitarget.h
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign include/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
ffi.h: $(top_builddir)/config.status $(srcdir)/ffi.h.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-nodist_includesHEADERS: $(nodist_includes_HEADERS)
@$(NORMAL_INSTALL)
test -z "$(includesdir)" || $(MKDIR_P) "$(DESTDIR)$(includesdir)"
@list='$(nodist_includes_HEADERS)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f=$(am__strip_dir) \
echo " $(nodist_includesHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includesdir)/$$f'"; \
$(nodist_includesHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includesdir)/$$f"; \
done
uninstall-nodist_includesHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(nodist_includes_HEADERS)'; for p in $$list; do \
f=$(am__strip_dir) \
echo " rm -f '$(DESTDIR)$(includesdir)/$$f'"; \
rm -f "$(DESTDIR)$(includesdir)/$$f"; \
done
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(HEADERS)
installdirs:
for dir in "$(DESTDIR)$(includesdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-nodist_includesHEADERS
install-dvi: install-dvi-am
install-exec-am:
install-html: install-html-am
install-info: install-info-am
install-man:
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-nodist_includesHEADERS
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-libtool ctags distclean distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-man install-nodist_includesHEADERS \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-nodist_includesHEADERS
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,393 @@
/* -----------------------------------------------------------------*-C-*-
libffi @VERSION@ - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
/* -------------------------------------------------------------------
The basic API is described in the README file.
The raw API is designed to bypass some of the argument packing
and unpacking on architectures for which it can be avoided.
The closure API allows interpreted functions to be packaged up
inside a C function pointer, so that they can be called as C functions,
with no understanding on the client side that they are interpreted.
It can also be used in other cases in which it is necessary to package
up a user specified parameter and a function pointer as a single
function pointer.
The closure API must be implemented in order to get its functionality,
e.g. for use by gij. Routines are provided to emulate the raw API
if the underlying platform doesn't allow faster implementation.
More details on the raw and cloure API can be found in:
http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
and
http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
-------------------------------------------------------------------- */
#ifndef LIBFFI_H
#define LIBFFI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Specify which architecture libffi is configured for. */
#ifndef @TARGET@
#define @TARGET@
#endif
/* ---- System configuration information --------------------------------- */
#include <ffitarget.h>
#ifndef LIBFFI_ASM
#include <stddef.h>
#include <limits.h>
/* LONG_LONG_MAX is not always defined (not if STRICT_ANSI, for example).
But we can find it either under the correct ANSI name, or under GNU
C's internal name. */
#ifdef LONG_LONG_MAX
# define FFI_LONG_LONG_MAX LONG_LONG_MAX
#else
# ifdef LLONG_MAX
# define FFI_LONG_LONG_MAX LLONG_MAX
# else
# ifdef __GNUC__
# define FFI_LONG_LONG_MAX __LONG_LONG_MAX__
# endif
# endif
#endif
/* The closure code assumes that this works on pointers, i.e. a size_t */
/* can hold a pointer. */
typedef struct _ffi_type
{
size_t size;
unsigned short alignment;
unsigned short type;
struct _ffi_type **elements;
} ffi_type;
#ifndef LIBFFI_HIDE_BASIC_TYPES
#if SCHAR_MAX == 127
# define ffi_type_uchar ffi_type_uint8
# define ffi_type_schar ffi_type_sint8
#else
#error "char size not supported"
#endif
#if SHRT_MAX == 32767
# define ffi_type_ushort ffi_type_uint16
# define ffi_type_sshort ffi_type_sint16
#elif SHRT_MAX == 2147483647
# define ffi_type_ushort ffi_type_uint32
# define ffi_type_sshort ffi_type_sint32
#else
#error "short size not supported"
#endif
#if INT_MAX == 32767
# define ffi_type_uint ffi_type_uint16
# define ffi_type_sint ffi_type_sint16
#elif INT_MAX == 2147483647
# define ffi_type_uint ffi_type_uint32
# define ffi_type_sint ffi_type_sint32
#elif INT_MAX == 9223372036854775807
# define ffi_type_uint ffi_type_uint64
# define ffi_type_sint ffi_type_sint64
#else
#error "int size not supported"
#endif
#if LONG_MAX == 2147483647
# if FFI_LONG_LONG_MAX != 9223372036854775807
#error "no 64-bit data type supported"
# endif
#elif LONG_MAX != 9223372036854775807
#error "long size not supported"
#endif
#if LONG_MAX == 2147483647
# define ffi_type_ulong ffi_type_uint32
# define ffi_type_slong ffi_type_sint32
#elif LONG_MAX == 9223372036854775807
# define ffi_type_ulong ffi_type_uint64
# define ffi_type_slong ffi_type_sint64
#else
#error "long size not supported"
#endif
/* These are defined in types.c */
extern ffi_type ffi_type_void;
extern ffi_type ffi_type_uint8;
extern ffi_type ffi_type_sint8;
extern ffi_type ffi_type_uint16;
extern ffi_type ffi_type_sint16;
extern ffi_type ffi_type_uint32;
extern ffi_type ffi_type_sint32;
extern ffi_type ffi_type_uint64;
extern ffi_type ffi_type_sint64;
extern ffi_type ffi_type_float;
extern ffi_type ffi_type_double;
extern ffi_type ffi_type_pointer;
#if @HAVE_LONG_DOUBLE@
extern ffi_type ffi_type_longdouble;
#else
#define ffi_type_longdouble ffi_type_double
#endif
#endif /* LIBFFI_HIDE_BASIC_TYPES */
typedef enum {
FFI_OK = 0,
FFI_BAD_TYPEDEF,
FFI_BAD_ABI
} ffi_status;
typedef unsigned FFI_TYPE;
typedef struct {
ffi_abi abi;
unsigned nargs;
ffi_type **arg_types;
ffi_type *rtype;
unsigned bytes;
unsigned flags;
#ifdef FFI_EXTRA_CIF_FIELDS
FFI_EXTRA_CIF_FIELDS;
#endif
} ffi_cif;
/* ---- Definitions for the raw API -------------------------------------- */
#ifndef FFI_SIZEOF_ARG
# if LONG_MAX == 2147483647
# define FFI_SIZEOF_ARG 4
# elif LONG_MAX == 9223372036854775807
# define FFI_SIZEOF_ARG 8
# endif
#endif
#ifndef FFI_SIZEOF_JAVA_RAW
# define FFI_SIZEOF_JAVA_RAW FFI_SIZEOF_ARG
#endif
typedef union {
ffi_sarg sint;
ffi_arg uint;
float flt;
char data[FFI_SIZEOF_ARG];
void* ptr;
} ffi_raw;
#if FFI_SIZEOF_JAVA_RAW == 4 && FFI_SIZEOF_ARG == 8
/* This is a special case for mips64/n32 ABI (and perhaps others) where
sizeof(void *) is 4 and FFI_SIZEOF_ARG is 8. */
typedef union {
signed int sint;
unsigned int uint;
float flt;
char data[FFI_SIZEOF_JAVA_RAW];
void* ptr;
} ffi_java_raw;
#else
typedef ffi_raw ffi_java_raw;
#endif
void ffi_raw_call (ffi_cif *cif,
void (*fn)(void),
void *rvalue,
ffi_raw *avalue);
void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
size_t ffi_raw_size (ffi_cif *cif);
/* This is analogous to the raw API, except it uses Java parameter */
/* packing, even on 64-bit machines. I.e. on 64-bit machines */
/* longs and doubles are followed by an empty 64-bit word. */
void ffi_java_raw_call (ffi_cif *cif,
void (*fn)(void),
void *rvalue,
ffi_java_raw *avalue);
void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
size_t ffi_java_raw_size (ffi_cif *cif);
/* ---- Definitions for closures ----------------------------------------- */
#if FFI_CLOSURES
typedef struct {
char tramp[FFI_TRAMPOLINE_SIZE];
ffi_cif *cif;
void (*fun)(ffi_cif*,void*,void**,void*);
void *user_data;
} ffi_closure __attribute__((aligned (8)));
void *ffi_closure_alloc (size_t size, void **code);
void ffi_closure_free (void *);
ffi_status
ffi_prep_closure (ffi_closure*,
ffi_cif *,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data);
ffi_status
ffi_prep_closure_loc (ffi_closure*,
ffi_cif *,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void*codeloc);
typedef struct {
char tramp[FFI_TRAMPOLINE_SIZE];
ffi_cif *cif;
#if !FFI_NATIVE_RAW_API
/* if this is enabled, then a raw closure has the same layout
as a regular closure. We use this to install an intermediate
handler to do the transaltion, void** -> ffi_raw*. */
void (*translate_args)(ffi_cif*,void*,void**,void*);
void *this_closure;
#endif
void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
void *user_data;
} ffi_raw_closure;
typedef struct {
char tramp[FFI_TRAMPOLINE_SIZE];
ffi_cif *cif;
#if !FFI_NATIVE_RAW_API
/* if this is enabled, then a raw closure has the same layout
as a regular closure. We use this to install an intermediate
handler to do the transaltion, void** -> ffi_raw*. */
void (*translate_args)(ffi_cif*,void*,void**,void*);
void *this_closure;
#endif
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*);
void *user_data;
} ffi_java_raw_closure;
ffi_status
ffi_prep_raw_closure (ffi_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data);
ffi_status
ffi_prep_raw_closure_loc (ffi_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data,
void *codeloc);
ffi_status
ffi_prep_java_raw_closure (ffi_java_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data);
ffi_status
ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data,
void *codeloc);
#endif /* FFI_CLOSURES */
/* ---- Public interface definition -------------------------------------- */
ffi_status ffi_prep_cif(ffi_cif *cif,
ffi_abi abi,
unsigned int nargs,
ffi_type *rtype,
ffi_type **atypes);
void ffi_call(ffi_cif *cif,
void (*fn)(void),
void *rvalue,
void **avalue);
/* Useful for eliminating compiler warnings */
#define FFI_FN(f) ((void (*)(void))f)
/* ---- Definitions shared with assembly code ---------------------------- */
#endif
/* If these change, update src/mips/ffitarget.h. */
#define FFI_TYPE_VOID 0
#define FFI_TYPE_INT 1
#define FFI_TYPE_FLOAT 2
#define FFI_TYPE_DOUBLE 3
#if @HAVE_LONG_DOUBLE@
#define FFI_TYPE_LONGDOUBLE 4
#else
#define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
#endif
#define FFI_TYPE_UINT8 5
#define FFI_TYPE_SINT8 6
#define FFI_TYPE_UINT16 7
#define FFI_TYPE_SINT16 8
#define FFI_TYPE_UINT32 9
#define FFI_TYPE_SINT32 10
#define FFI_TYPE_UINT64 11
#define FFI_TYPE_SINT64 12
#define FFI_TYPE_STRUCT 13
#define FFI_TYPE_POINTER 14
/* This should always refer to the last type code (for sanity checks) */
#define FFI_TYPE_LAST FFI_TYPE_POINTER
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,98 @@
/* -----------------------------------------------------------------------
ffi_common.h - Copyright (c) 1996 Red Hat, Inc.
Copyright (C) 2007 Free Software Foundation, Inc
Common internal definitions and macros. Only necessary for building
libffi.
----------------------------------------------------------------------- */
#ifndef FFI_COMMON_H
#define FFI_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif
#include <fficonfig.h>
/* Do not move this. Some versions of AIX are very picky about where
this is positioned. */
#ifdef __GNUC__
# define alloca __builtin_alloca
# define MAYBE_UNUSED __attribute__((__unused__))
#else
# define MAYBE_UNUSED
# if HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
char *alloca ();
# endif
# endif
# endif
#endif
/* Check for the existence of memcpy. */
#if STDC_HEADERS
# include <string.h>
#else
# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# endif
#endif
#if defined(FFI_DEBUG)
#include <stdio.h>
#endif
#ifdef FFI_DEBUG
void ffi_assert(char *expr, char *file, int line);
void ffi_stop_here(void);
void ffi_type_test(ffi_type *a, char *file, int line);
#define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
#define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
#define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
#else
#define FFI_ASSERT(x)
#define FFI_ASSERT_AT(x, f, l)
#define FFI_ASSERT_VALID_TYPE(x)
#endif
#define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
#define ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
/* Perform machine dependent cif processing */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
/* Extended cif, used in callback from assembly routine */
typedef struct
{
ffi_cif *cif;
void *rvalue;
void **avalue;
} extended_cif;
/* Terse sized type definitions. */
typedef unsigned int UINT8 __attribute__((__mode__(__QI__)));
typedef signed int SINT8 __attribute__((__mode__(__QI__)));
typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));
typedef signed int SINT16 __attribute__((__mode__(__HI__)));
typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));
typedef signed int SINT32 __attribute__((__mode__(__SI__)));
typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));
typedef signed int SINT64 __attribute__((__mode__(__DI__)));
typedef float FLOAT32;
#ifdef __cplusplus
}
#endif
#endif

323
js/ctypes/libffi/install-sh Executable file
View File

@@ -0,0 +1,323 @@
#!/bin/sh
# install - install a program, script, or datafile
scriptversion=2004-12-17.09
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# 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 THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
chmodcmd="$chmodprog 0755"
chowncmd=
chgrpcmd=
stripcmd=
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=
dst=
dir_arg=
dstarg=
no_target_directory=
usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES...
In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.
Options:
-c (ignored)
-d create directories instead of installing files.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE.
-o USER $chownprog installed files to USER.
-s $stripprog installed files.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
--help display this help and exit.
--version display version info and exit.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
"
while test -n "$1"; do
case $1 in
-c) shift
continue;;
-d) dir_arg=true
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
--help) echo "$usage"; exit 0;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-s) stripcmd=$stripprog
shift
continue;;
-t) dstarg=$2
shift
shift
continue;;
-T) no_target_directory=true
shift
continue;;
--version) echo "$0 $scriptversion"; exit 0;;
*) # When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
test -n "$dir_arg$dstarg" && break
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dstarg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dstarg"
shift # fnord
fi
shift # arg
dstarg=$arg
done
break;;
esac
done
if test -z "$1"; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call `install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
for src
do
# Protect names starting with `-'.
case $src in
-*) src=./$src ;;
esac
if test -n "$dir_arg"; then
dst=$src
src=
if test -d "$dst"; then
mkdircmd=:
chmodcmd=
else
mkdircmd=$mkdirprog
fi
else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dstarg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dstarg
# Protect names starting with `-'.
case $dst in
-*) dst=./$dst ;;
esac
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
if test -n "$no_target_directory"; then
echo "$0: $dstarg: Is a directory" >&2
exit 1
fi
dst=$dst/`basename "$src"`
fi
fi
# This sed command emulates the dirname command.
dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# Skip lots of stat calls in the usual case.
if test ! -d "$dstdir"; then
defaultIFS='
'
IFS="${IFS-$defaultIFS}"
oIFS=$IFS
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
shift
IFS=$oIFS
pathcomp=
while test $# -ne 0 ; do
pathcomp=$pathcomp$1
shift
if test ! -d "$pathcomp"; then
$mkdirprog "$pathcomp"
# mkdir can fail with a `File exist' error in case several
# install-sh are creating the directory concurrently. This
# is OK.
test -d "$pathcomp" || exit
fi
pathcomp=$pathcomp/
done
fi
if test -n "$dir_arg"; then
$doit $mkdircmd "$dst" \
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
else
dstfile=`basename "$dst"`
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
trap '(exit $?); exit' 1 2 13 15
# Copy the file name to the temp name.
$doit $cpprog "$src" "$dsttmp" &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
# Now rename the file to the real destination.
{ $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
|| {
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
if test -f "$dstdir/$dstfile"; then
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
|| {
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
(exit 1); exit 1
}
else
:
fi
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
}
}
fi || { (exit 1); exit 1; }
done
# The final little trick to "correctly" pass the exit status to the exit trap.
{
(exit 0); exit 0
}
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=${libdir}/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
Name: @PACKAGE_NAME@
Description: Library supporting Foreign Function Interfaces
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lffi
Cflags: -I${includedir}

View File

@@ -0,0 +1,29 @@
# This file is used to maintain libtool version info for libffi. See
# the libtool manual to understand the meaning of the fields. This is
# a separate file so that version updates don't involve re-running
# automake.
#
# Here are a set of rules to help you update your library version
# information:
#
# 1. Start with version information of `0:0:0' for each libtool library.
#
# 2. Update the version information only immediately before a public
# release of your software. More frequent updates are unnecessary,
# and only guarantee that the current interface number gets larger
# faster.
#
# 3. If the library source code has changed at all since the last
# update, then increment revision (`c:r:a' becomes `c:r+1:a').
#
# 4. If any interfaces have been added, removed, or changed since the
# last update, increment current, and set revision to 0.
#
# 5. If any interfaces have been added since the last public release,
# then increment age.
#
# 6. If any interfaces have been removed since the last public
# release, then set age to 0.
#
# CURRENT:REVISION:AGE
5:9:0

861
js/ctypes/libffi/ltcf-c.sh Normal file
View File

@@ -0,0 +1,861 @@
#### This script is meant to be sourced by ltconfig.
# ltcf-c.sh - Create a C compiler specific configuration
#
# Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
# This file 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Source file extension for C test sources.
ac_ext=c
# Object file extension for compiled C test sources.
objext=o
# Code to be used in simple compile tests
lt_simple_compile_test_code="int some_variable = 0;"
# Code to be used in simple link tests
lt_simple_link_test_code='main(){return(0);}'
## Linker Characteristics
case $host_os in
cygwin* | mingw*)
# FIXME: the MSVC++ port hasn't been tested in a loooong time
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
if test "$with_gcc" != yes; then
with_gnu_ld=no
fi
;;
esac
ld_shlibs=yes
if test "$with_gnu_ld" = yes; then
# If archive_cmds runs LD, not CC, wlarc should be empty
wlarc='${wl}'
# See if GNU ld supports shared libraries.
case $host_os in
aix3* | aix4* | aix5*)
# On AIX/PPC, the GNU linker is very broken
if test "$host_cpu" != ia64; then
ld_shlibs=no
cat <<EOF 1>&2
*** Warning: the GNU linker, at least up to release 2.9.1, is reported
*** to be unable to reliably create shared libraries on AIX.
*** Therefore, libtool is disabling shared libraries support. If you
*** really care for shared libraries, you may want to modify your PATH
*** so that a non-GNU linker is found, and then restart.
EOF
fi
;;
amigaos*)
archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
# Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
# that the semantics of dynamic libraries on AmigaOS, at least up
# to version 4, is to share data among multiple programs linked
# with the same dynamic library. Since this doesn't match the
# behavior of shared libraries on other platforms, we can use
# them.
ld_shlibs=no
;;
beos*)
if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
allow_undefined_flag=unsupported
# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
# support --undefined. This deserves some investigation. FIXME
archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
else
ld_shlibs=no
fi
;;
cygwin* | mingw*)
# hardcode_libdir_flag_spec is actually meaningless, as there is
# no search path for DLLs.
hardcode_libdir_flag_spec='-L$libdir'
allow_undefined_flag=unsupported
always_export_symbols=yes
extract_expsyms_cmds='test -f $output_objdir/impgen.c || \
sed -e "/^# \/\* impgen\.c starts here \*\//,/^# \/\* impgen.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/impgen.c~
test -f $output_objdir/impgen.exe || (cd $output_objdir && \
if test "x$BUILD_CC" != "x" ; then $BUILD_CC -o impgen impgen.c ; \
else $CC -o impgen impgen.c ; fi)~
$output_objdir/impgen $dir/$soroot > $output_objdir/$soname-def'
old_archive_from_expsyms_cmds='$DLLTOOL --as=$AS --dllname $soname --def $output_objdir/$soname-def --output-lib $output_objdir/$newlib'
# cygwin and mingw dlls have different entry points and sets of symbols
# to exclude.
# FIXME: what about values for MSVC?
dll_entry=__cygwin_dll_entry@12
dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12~
case $host_os in
mingw*)
# mingw values
dll_entry=_DllMainCRTStartup@12
dll_exclude_symbols=DllMain@12,DllMainCRTStartup@12,DllEntryPoint@12~
;;
esac
# mingw and cygwin differ, and it's simplest to just exclude the union
# of the two symbol sets.
dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCRTStartup@12,DllEntryPoint@12
# recent cygwin and mingw systems supply a stub DllMain which the user
# can override, but on older systems we have to supply one (in ltdll.c)
if test "x$lt_cv_need_dllmain" = "xyes"; then
ltdll_obj='$output_objdir/$soname-ltdll.'"$objext "
ltdll_cmds='test -f $output_objdir/$soname-ltdll.c || sed -e "/^# \/\* ltdll\.c starts here \*\//,/^# \/\* ltdll.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/$soname-ltdll.c~
test -f $output_objdir/$soname-ltdll.$objext || (cd $output_objdir && $CC -c $soname-ltdll.c)~'
else
ltdll_obj=
ltdll_cmds=
fi
# Extract the symbol export list from an `--export-all' def file,
# then regenerate the def file from the symbol export list, so that
# the compiled dll only exports the symbol export list.
# Be careful not to strip the DATA tag left be newer dlltools.
export_symbols_cmds="$ltdll_cmds"'
$DLLTOOL --export-all --exclude-symbols '$dll_exclude_symbols' --output-def $output_objdir/$soname-def '$ltdll_obj'$libobjs $convenience~
sed -e "1,/EXPORTS/d" -e "s/ @ [0-9]*//" -e "s/ *;.*$//" < $output_objdir/$soname-def > $export_symbols'
# If the export-symbols file already is a .def file (1st line
# is EXPORTS), use it as is.
# If DATA tags from a recent dlltool are present, honour them!
archive_expsym_cmds='if test "x`head -1 $export_symbols`" = xEXPORTS; then
cp $export_symbols $output_objdir/$soname-def;
else
echo EXPORTS > $output_objdir/$soname-def;
_lt_hint=1;
cat $export_symbols | while read symbol; do
set dummy \$symbol;
case \[$]# in
2) echo " \[$]2 @ \$_lt_hint ; " >> $output_objdir/$soname-def;;
*) echo " \[$]2 @ \$_lt_hint \[$]3 ; " >> $output_objdir/$soname-def;;
esac;
_lt_hint=`expr 1 + \$_lt_hint`;
done;
fi~
'"$ltdll_cmds"'
$CC -Wl,--base-file,$output_objdir/$soname-base '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
$DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp~
$CC -Wl,--base-file,$output_objdir/$soname-base $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
$DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp --output-lib $output_objdir/$libname.dll.a~
$CC $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags'
;;
netbsd* | knetbsd*-gnu)
if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
wlarc=
else
archive_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
fi
;;
solaris* | sysv5*)
if $LD -v 2>&1 | egrep 'BFD 2\.8' > /dev/null; then
ld_shlibs=no
cat <<EOF 1>&2
*** Warning: The releases 2.8.* of the GNU linker cannot reliably
*** create shared libraries on Solaris systems. Therefore, libtool
*** is disabling shared libraries support. We urge you to upgrade GNU
*** binutils to release 2.9.1 or newer. Another option is to modify
*** your PATH or compiler configuration so that the native linker is
*** used, and then restart.
EOF
elif $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
else
ld_shlibs=no
fi
;;
sunos4*)
archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
wlarc=
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
tpf*)
ld_shlibs=yes
;;
*)
if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
else
ld_shlibs=no
fi
;;
esac
if test "$ld_shlibs" = yes; then
runpath_var=LD_RUN_PATH
hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'
export_dynamic_flag_spec='${wl}--export-dynamic'
case $host_os in
cygwin* | mingw*)
# dlltool doesn't understand --whole-archive et. al.
whole_archive_flag_spec=
;;
*)
# ancient GNU ld didn't support --whole-archive et. al.
if $LD --help 2>&1 | egrep 'no-whole-archive' > /dev/null; then
whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
else
whole_archive_flag_spec=
fi
;;
esac
fi
else
# PORTME fill in a description of your system's linker (not GNU ld)
case $host_os in
aix3*)
allow_undefined_flag=unsupported
always_export_symbols=yes
archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
# Note: this linker hardcodes the directories in LIBPATH if there
# are no directories specified by -L.
hardcode_minus_L=yes
if test "$with_gcc" = yes && test -z "$link_static_flag"; then
# Neither direct hardcoding nor static linking is supported with a
# broken collect2.
hardcode_direct=unsupported
fi
;;
aix4* | aix5*)
hardcode_direct=yes
hardcode_libdir_separator=':'
link_all_deplibs=yes
# When large executables or shared objects are built, AIX ld can
# have problems creating the table of contents. If linking a library
# or program results in "error TOC overflow" add -mminimal-toc to
# CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not
# enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
if test "$with_gcc" = yes; then
case $host_os in aix4.[012]|aix4.[012].*)
# We only want to do this on AIX 4.2 and lower, the check
# below for broken collect2 doesn't work under 4.3+
collect2name=`${CC} -print-prog-name=collect2`
if test -f "$collect2name" && \
strings "$collect2name" | grep resolve_lib_name >/dev/null
then
# We have reworked collect2
hardcode_direct=yes
else
# We have old collect2
hardcode_direct=unsupported
# It fails to find uninstalled libraries when the uninstalled
# path is not listed in the libpath. Setting hardcode_minus_L
# to unsupported forces relinking
hardcode_minus_L=yes
hardcode_libdir_flag_spec='-L$libdir'
hardcode_libdir_separator=
fi
esac
shared_flag='-shared'
else
# not using gcc
if test "$host_cpu" = ia64; then
shared_flag='${wl}-G'
else
shared_flag='${wl}-bM:SRE'
fi
fi
if test "$host_cpu" = ia64; then
# On IA64, the linker does run time linking by default, so we don't
# have to do anything special.
aix_use_runtimelinking=no
if test $with_gnu_ld = no; then
exp_sym_flag='-Bexport'
no_entry_flag=""
fi
else
# Test if we are trying to use run time linking, or normal AIX style linking.
# If -brtl is somewhere in LDFLAGS, we need to do run time linking.
aix_use_runtimelinking=no
for ld_flag in $LDFLAGS; do
if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl" ); then
aix_use_runtimelinking=yes
break
fi
done
exp_sym_flag='-bexport'
no_entry_flag='-bnoentry'
fi
# -bexpall does not export symbols beginning with underscore (_)
always_export_symbols=yes
if test "$aix_use_runtimelinking" = yes; then
# Warning - without using the other run time loading flags (-brtl), -berok will
# link without error, but may produce a broken library.
allow_undefined_flag=' ${wl}-berok'
hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
else
if test "$host_cpu" = ia64; then
if test $with_gnu_ld = no; then
hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
allow_undefined_flag="-z nodefs"
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
fi
else
allow_undefined_flag=' ${wl}-berok'
# -bexpall does not export symbols beginning with underscore (_)
always_export_symbols=yes
# Exported symbols can be pulled into shared objects from archives
whole_archive_flag_spec=' '
build_libtool_need_lc=yes
hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
# This is similar to how AIX traditionally builds it's shared libraries.
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
fi
fi
;;
amigaos*)
archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
# see comment about different semantics on the GNU ld section
ld_shlibs=no
;;
cygwin* | mingw*)
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
# hardcode_libdir_flag_spec is actually meaningless, as there is
# no search path for DLLs.
hardcode_libdir_flag_spec=' '
allow_undefined_flag=unsupported
# Tell ltmain to make .lib files, not .a files.
libext=lib
# FIXME: Setting linknames here is a bad hack.
archive_cmds='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | sed -e '\''s/ -lc$//'\''` -link -dll~linknames='
# The linker will automatically build a .lib file if we build a DLL.
old_archive_from_new_cmds='true'
# FIXME: Should let the user specify the lib program.
old_archive_cmds='lib /OUT:$oldlib$oldobjs$old_deplibs'
fix_srcfile_path='`cygpath -w "$srcfile"`'
;;
darwin* | rhapsody*)
case "$host_os" in
rhapsody* | darwin1.[[012]])
allow_undefined_flag='-undefined suppress'
;;
*) # Darwin 1.3 on
if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
allow_undefined_flag='-flat_namespace -undefined suppress'
else
case ${MACOSX_DEPLOYMENT_TARGET} in
10.[[012]])
allow_undefined_flag='-flat_namespace -undefined suppress'
;;
10.*)
allow_undefined_flag='-undefined dynamic_lookup'
;;
esac
fi
;;
esac
# Disable shared library build on OS-X older than 10.3.
case $host_os in
darwin[1-6]*)
can_build_shared=no
;;
darwin7*)
can_build_shared=yes
;;
esac
output_verbose_link_cmd='echo'
archive_cmds='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring'
module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
# Don't fix this by using the ld -exported_symbols_list flag,
# it doesn't exist in older darwin ld's
archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
module_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
hardcode_direct=no
hardcode_automatic=yes
hardcode_shlibpath_var=unsupported
whole_archive_flag_spec='-all_load $convenience'
link_all_deplibs=yes
;;
freebsd1*)
ld_shlibs=no
;;
# FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
# support. Future versions do this automatically, but an explicit c++rt0.o
# does not break anything, and helps significantly (at the cost of a little
# extra space).
freebsd2.2*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
# Unfortunately, older versions of FreeBSD 2 do not have this feature.
freebsd2*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
hardcode_direct=yes
hardcode_minus_L=yes
hardcode_shlibpath_var=no
;;
# FreeBSD 3 and greater uses gcc -shared to do shared libraries.
freebsd* | kfreebsd*-gnu)
archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
hpux9* | hpux10* | hpux11*)
case "$host_cpu" in
ia64*)
hardcode_direct=no
hardcode_shlibpath_var=no
archive_cmds='$LD -b +h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir' ;;
*)
if test $with_gcc = yes; then
case "$host_os" in
hpux9*) archive_cmds='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' ;;
*) archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;;
esac
else
case $host_os in
hpux9*) archive_cmds='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' ;;
*) archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' ;;
esac
fi
hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
hardcode_libdir_separator=:
hardcode_minus_L=yes # Not in the search PATH, but as the default
# location of the library.
;;
esac
export_dynamic_flag_spec='${wl}-E'
hardcode_direct=yes
;;
irix5* | irix6*)
if test "$with_gcc" = yes; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
else
archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
fi
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
link_all_deplibs=yes
;;
netbsd* | knetbsd*-gnu)
if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out
else
archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF
fi
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
newsos6)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linkopts'
hardcode_direct=yes
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
hardcode_shlibpath_var=no
;;
openbsd*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
os2*)
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
allow_undefined_flag=unsupported
archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
;;
osf3*)
if test "$with_gcc" = yes; then
allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
else
allow_undefined_flag=' -expect_unresolved \*'
archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
fi
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
;;
osf4* | osf5*) # as osf3* with the addition of -msym flag
if test "$with_gcc" = yes; then
allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
else
allow_undefined_flag=' -expect_unresolved \*'
archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
archive_expsym_cmds='for i in `cat $export_symbols`; do printf "-exported_symbol " >> $lib.exp; echo "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib~$rm $lib.exp'
# cc supports -rpath directly
hardcode_libdir_flag_spec='-rpath $libdir'
fi
hardcode_libdir_separator=:
;;
sco3.2v5*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
runpath_var=LD_RUN_PATH
hardcode_runpath_var=yes
;;
solaris*)
no_undefined_flag=' -z defs'
if test "$with_gcc" = yes; then
archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
$CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
else
archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
fi
hardcode_libdir_flag_spec='-R$libdir'
hardcode_shlibpath_var=no
case $host_os in
solaris2.[0-5] | solaris2.[0-5].*) ;;
*) # Supported since Solaris 2.6 (maybe 2.5.1?)
whole_archive_flag_spec='-z allextract$convenience -z defaultextract' ;;
esac
link_all_deplibs=yes
;;
sunos4*)
archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_direct=yes
hardcode_minus_L=yes
hardcode_shlibpath_var=no
;;
sysv4)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
runpath_var='LD_RUN_PATH'
hardcode_shlibpath_var=no
hardcode_direct=no #Motorola manual says yes, but my tests say they lie
;;
sysv4.3*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
export_dynamic_flag_spec='-Bexport'
;;
sysv5*)
no_undefined_flag=' -z text'
# $CC -shared without GNU ld will not create a library from C++
# object files and a static libstdc++, better avoid it by now
archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
hardcode_libdir_flag_spec=
hardcode_shlibpath_var=no
runpath_var='LD_RUN_PATH'
;;
uts4*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_shlibpath_var=no
;;
dgux*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_shlibpath_var=no
;;
sysv4*MP*)
if test -d /usr/nec; then
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
runpath_var=LD_RUN_PATH
hardcode_runpath_var=yes
ld_shlibs=yes
fi
;;
sysv4.2uw2*)
archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
hardcode_direct=yes
hardcode_minus_L=no
hardcode_shlibpath_var=no
hardcode_runpath_var=yes
runpath_var=LD_RUN_PATH
;;
sysv5uw7* | unixware7*)
no_undefined_flag='${wl}-z ${wl}text'
if test "$GCC" = yes; then
archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
else
archive_cmds='$CC -G ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
fi
runpath_var='LD_RUN_PATH'
hardcode_shlibpath_var=no
;;
*)
ld_shlibs=no
;;
esac
fi
## Compiler Characteristics: PIC flags, static flags, etc
if test "X${ac_cv_prog_cc_pic+set}" = Xset; then
:
else
ac_cv_prog_cc_pic=
ac_cv_prog_cc_shlib=
ac_cv_prog_cc_wl=
ac_cv_prog_cc_static=
ac_cv_prog_cc_no_builtin=
ac_cv_prog_cc_can_build_shared=$can_build_shared
if test "$with_gcc" = yes; then
ac_cv_prog_cc_wl='-Wl,'
ac_cv_prog_cc_static='-static'
case $host_os in
aix*)
# All AIX code is PIC.
if test "$host_cpu" = ia64; then
# AIX 5 now supports IA64 processor
lt_cv_prog_cc_static='-Bstatic'
else
lt_cv_prog_cc_static='-bnso -bI:/lib/syscalls.exp'
fi
;;
amigaos*)
# FIXME: we need at least 68020 code to build shared libraries, but
# adding the `-m68020' flag to GCC prevents building anything better,
# like `-m68040'.
ac_cv_prog_cc_pic='-m68020 -resident32 -malways-restore-a4'
;;
beos* | irix5* | irix6* | osf3* | osf4* | osf5*)
# PIC is the default for these OSes.
;;
cygwin* | mingw* | os2*)
# This hack is so that the source file can tell whether it is being
# built for inclusion in a dll (and should export symbols for example).
ac_cv_prog_cc_pic='-DDLL_EXPORT'
;;
darwin* | rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
ac_cv_prog_cc_pic='-fno-common'
;;
*djgpp*)
# DJGPP does not support shared libraries at all
ac_cv_prog_cc_pic=
;;
sysv4*MP*)
if test -d /usr/nec; then
ac_cv_prog_cc_pic=-Kconform_pic
fi
;;
*)
ac_cv_prog_cc_pic='-fPIC'
;;
esac
else
# PORTME Check for PIC flags for the system compiler.
case $host_os in
aix*)
# All AIX code is PIC.
ac_cv_prog_cc_static="$ac_cv_prog_cc_static ${ac_cv_prog_cc_wl}-lC"
;;
hpux9* | hpux10* | hpux11*)
# Is there a better ac_cv_prog_cc_static that works with the bundled CC?
ac_cv_prog_cc_wl='-Wl,'
ac_cv_prog_cc_static="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive"
ac_cv_prog_cc_pic='+Z'
;;
irix5* | irix6*)
ac_cv_prog_cc_wl='-Wl,'
ac_cv_prog_cc_static='-non_shared'
# PIC (with -KPIC) is the default.
;;
cygwin* | mingw* | os2*)
# This hack is so that the source file can tell whether it is being
# built for inclusion in a dll (and should export symbols for example).
ac_cv_prog_cc_pic='-DDLL_EXPORT'
;;
newsos6)
ac_cv_prog_cc_pic='-KPIC'
ac_cv_prog_cc_static='-Bstatic'
;;
osf3* | osf4* | osf5*)
# All OSF/1 code is PIC.
ac_cv_prog_cc_wl='-Wl,'
ac_cv_prog_cc_static='-non_shared'
;;
sco3.2v5*)
ac_cv_prog_cc_pic='-Kpic'
ac_cv_prog_cc_static='-dn'
ac_cv_prog_cc_shlib='-belf'
;;
solaris*)
ac_cv_prog_cc_pic='-KPIC'
ac_cv_prog_cc_static='-Bstatic'
ac_cv_prog_cc_wl='-Wl,'
;;
sunos4*)
ac_cv_prog_cc_pic='-PIC'
ac_cv_prog_cc_static='-Bstatic'
ac_cv_prog_cc_wl='-Qoption ld '
;;
sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
ac_cv_prog_cc_pic='-KPIC'
ac_cv_prog_cc_static='-Bstatic'
ac_cv_prog_cc_wl='-Wl,'
;;
uts4*)
ac_cv_prog_cc_pic='-pic'
ac_cv_prog_cc_static='-Bstatic'
;;
sysv4*MP*)
if test -d /usr/nec ;then
ac_cv_prog_cc_pic='-Kconform_pic'
ac_cv_prog_cc_static='-Bstatic'
fi
;;
*)
ac_cv_prog_cc_can_build_shared=no
;;
esac
fi
case "$host_os" in
# Platforms which do not suport PIC and -DPIC is meaningless
# on them:
*djgpp*)
ac_cv_prog_cc_pic=
;;
*)
ac_cv_prog_cc_pic="$ac_cv_prog_cc_pic -DPIC"
;;
esac
fi
need_lc=yes
if test "$enable_shared" = yes && test "$with_gcc" = yes; then
case $archive_cmds in
*'~'*)
# FIXME: we may have to deal with multi-command sequences.
;;
'$CC '*)
# Test whether the compiler implicitly links with -lc since on some
# systems, -lgcc has to come before -lc. If gcc already passes -lc
# to ld, don't add -lc before -lgcc.
echo $ac_n "checking whether -lc should be explicitly linked in... $ac_c" 1>&6
if eval "test \"`echo '$''{'ac_cv_archive_cmds_needs_lc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
need_lc=$ac_cv_archive_cmds_needs_lc
else
$rm conftest*
echo "static int dummy;" > conftest.$ac_ext
if { (eval echo ltcf-c.sh:need_lc: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; }; then
# Append any warnings to the config.log.
cat conftest.err 1>&5
soname=conftest
lib=conftest
libobjs=conftest.$objext
deplibs=
wl=$ac_cv_prog_cc_wl
compiler_flags=-v
linker_flags=-v
verstring=
output_objdir=.
libname=conftest
save_allow_undefined_flag=$allow_undefined_flag
allow_undefined_flag=
if { (eval echo ltcf-c.sh:need_lc: \"$archive_cmds\") 1>&5; (eval $archive_cmds) 2>&1 | grep " -lc " 1>&5 ; }; then
need_lc=no
fi
allow_undefined_flag=$save_allow_undefined_flag
else
cat conftest.err 1>&5
fi
fi
$rm conftest*
echo "$ac_t$need_lc" 1>&6
;;
esac
fi
ac_cv_archive_cmds_needs_lc=$need_lc

1069
js/ctypes/libffi/ltcf-cxx.sh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,700 @@
#### This script is meant to be sourced by ltconfig.
# ltcf-gcj.sh - Create a GCJ compiler specific configuration
#
# Copyright (C) 1996-1999, 2000, 2001, 2003 Free Software Foundation, Inc.
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
# Original GCJ support by:
# Alexandre Oliva <oliva@lsd.ic.unicamp.br>
#
# This file 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Source file extension for Java test sources.
ac_ext=java
# Object file extension for compiled Java test sources.
objext=o
# Code to be used in simple compile tests
lt_simple_compile_test_code="class foo {}"
# Code to be used in simple link tests
lt_simple_link_test_code='public class conftest { public static void main(String[] argv) {}; }'
## Linker Characteristics
case $host_os in
cygwin* | mingw*)
# FIXME: the MSVC++ port hasn't been tested in a loooong time
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
if test "$with_gcc" != yes; then
with_gnu_ld=no
fi
;;
esac
ld_shlibs=yes
if test "$with_gnu_ld" = yes; then
# If archive_cmds runs LD, not CC, wlarc should be empty
wlarc='${wl}'
# See if GNU ld supports shared libraries.
case $host_os in
aix3* | aix4* | aix5*)
# On AIX/PPC, the GNU linker is very broken
if test "$host_cpu" != ia64; then
ld_shlibs=no
cat <<EOF 1>&2
*** Warning: the GNU linker, at least up to release 2.9.1, is reported
*** to be unable to reliably create shared libraries on AIX.
*** Therefore, libtool is disabling shared libraries support. If you
*** really care for shared libraries, you may want to modify your PATH
*** so that a non-GNU linker is found, and then restart.
EOF
fi
;;
amigaos*)
archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
# Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
# that the semantics of dynamic libraries on AmigaOS, at least up
# to version 4, is to share data among multiple programs linked
# with the same dynamic library. Since this doesn't match the
# behavior of shared libraries on other platforms, we can use
# them.
ld_shlibs=no
;;
beos*)
if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
allow_undefined_flag=unsupported
# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
# support --undefined. This deserves some investigation. FIXME
archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
else
ld_shlibs=no
fi
;;
cygwin* | mingw*)
# hardcode_libdir_flag_spec is actually meaningless, as there is
# no search path for DLLs.
hardcode_libdir_flag_spec='-L$libdir'
allow_undefined_flag=unsupported
always_export_symbols=yes
extract_expsyms_cmds='test -f $output_objdir/impgen.c || \
sed -e "/^# \/\* impgen\.c starts here \*\//,/^# \/\* impgen.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/impgen.c~
test -f $output_objdir/impgen.exe || (cd $output_objdir && \
if test "x$BUILD_CC" != "x" ; then $BUILD_CC -o impgen impgen.c ; \
else $CC -o impgen impgen.c ; fi)~
$output_objdir/impgen $dir/$soroot > $output_objdir/$soname-def'
old_archive_from_expsyms_cmds='$DLLTOOL --as=$AS --dllname $soname --def $output_objdir/$soname-def --output-lib $output_objdir/$newlib'
# cygwin and mingw dlls have different entry points and sets of symbols
# to exclude.
# FIXME: what about values for MSVC?
dll_entry=__cygwin_dll_entry@12
dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12~
case $host_os in
mingw*)
# mingw values
dll_entry=_DllMainCRTStartup@12
dll_exclude_symbols=DllMain@12,DllMainCRTStartup@12,DllEntryPoint@12~
;;
esac
# mingw and cygwin differ, and it's simplest to just exclude the union
# of the two symbol sets.
dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCRTStartup@12,DllEntryPoint@12
# recent cygwin and mingw systems supply a stub DllMain which the user
# can override, but on older systems we have to supply one (in ltdll.c)
if test "x$lt_cv_need_dllmain" = "xyes"; then
ltdll_obj='$output_objdir/$soname-ltdll.'"$objext "
ltdll_cmds='test -f $output_objdir/$soname-ltdll.c || sed -e "/^# \/\* ltdll\.c starts here \*\//,/^# \/\* ltdll.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/$soname-ltdll.c~
test -f $output_objdir/$soname-ltdll.$objext || (cd $output_objdir && $CC -c $soname-ltdll.c)~'
else
ltdll_obj=
ltdll_cmds=
fi
# Extract the symbol export list from an `--export-all' def file,
# then regenerate the def file from the symbol export list, so that
# the compiled dll only exports the symbol export list.
# Be careful not to strip the DATA tag left be newer dlltools.
export_symbols_cmds="$ltdll_cmds"'
$DLLTOOL --export-all --exclude-symbols '$dll_exclude_symbols' --output-def $output_objdir/$soname-def '$ltdll_obj'$libobjs $convenience~
sed -e "1,/EXPORTS/d" -e "s/ @ [0-9]*//" -e "s/ *;.*$//" < $output_objdir/$soname-def > $export_symbols'
# If the export-symbols file already is a .def file (1st line
# is EXPORTS), use it as is.
# If DATA tags from a recent dlltool are present, honour them!
archive_expsym_cmds='if test "x`head -1 $export_symbols`" = xEXPORTS; then
cp $export_symbols $output_objdir/$soname-def;
else
echo EXPORTS > $output_objdir/$soname-def;
_lt_hint=1;
cat $export_symbols | while read symbol; do
set dummy \$symbol;
case \[$]# in
2) echo " \[$]2 @ \$_lt_hint ; " >> $output_objdir/$soname-def;;
*) echo " \[$]2 @ \$_lt_hint \[$]3 ; " >> $output_objdir/$soname-def;;
esac;
_lt_hint=`expr 1 + \$_lt_hint`;
done;
fi~
'"$ltdll_cmds"'
$CC -Wl,--base-file,$output_objdir/$soname-base '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
$DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp~
$CC -Wl,--base-file,$output_objdir/$soname-base $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
$DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp --output-lib $output_objdir/$libname.dll.a~
$CC $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags'
;;
netbsd* | knetbsd*-gnu)
if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
wlarc=
else
archive_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
fi
;;
solaris* | sysv5*)
if $LD -v 2>&1 | egrep 'BFD 2\.8' > /dev/null; then
ld_shlibs=no
cat <<EOF 1>&2
*** Warning: The releases 2.8.* of the GNU linker cannot reliably
*** create shared libraries on Solaris systems. Therefore, libtool
*** is disabling shared libraries support. We urge you to upgrade GNU
*** binutils to release 2.9.1 or newer. Another option is to modify
*** your PATH or compiler configuration so that the native linker is
*** used, and then restart.
EOF
elif $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
else
ld_shlibs=no
fi
;;
sunos4*)
archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
wlarc=
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
*)
if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
else
ld_shlibs=no
fi
;;
esac
if test "$ld_shlibs" = yes; then
runpath_var=LD_RUN_PATH
hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'
export_dynamic_flag_spec='${wl}--export-dynamic'
case $host_os in
cygwin* | mingw*)
# dlltool doesn't understand --whole-archive et. al.
whole_archive_flag_spec=
;;
*)
# ancient GNU ld didn't support --whole-archive et. al.
if $LD --help 2>&1 | egrep 'no-whole-archive' > /dev/null; then
whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
else
whole_archive_flag_spec=
fi
;;
esac
fi
else
# PORTME fill in a description of your system's linker (not GNU ld)
case $host_os in
aix3*)
allow_undefined_flag=unsupported
always_export_symbols=yes
archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
# Note: this linker hardcodes the directories in LIBPATH if there
# are no directories specified by -L.
hardcode_minus_L=yes
if test "$with_gcc" = yes && test -z "$link_static_flag"; then
# Neither direct hardcoding nor static linking is supported with a
# broken collect2.
hardcode_direct=unsupported
fi
;;
aix4* | aix5*)
hardcode_direct=yes
hardcode_libdir_separator=':'
link_all_deplibs=yes
# When large executables or shared objects are built, AIX ld can
# have problems creating the table of contents. If linking a library
# or program results in "error TOC overflow" add -mminimal-toc to
# CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not
# enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
if test "$with_gcc" = yes; then
case $host_os in aix4.[012]|aix4.[012].*)
# We only want to do this on AIX 4.2 and lower, the check
# below for broken collect2 doesn't work under 4.3+
collect2name=`${CC} -print-prog-name=collect2`
if test -f "$collect2name" && \
strings "$collect2name" | grep resolve_lib_name >/dev/null
then
# We have reworked collect2
hardcode_direct=yes
else
# We have old collect2
hardcode_direct=unsupported
# It fails to find uninstalled libraries when the uninstalled
# path is not listed in the libpath. Setting hardcode_minus_L
# to unsupported forces relinking
hardcode_minus_L=yes
hardcode_libdir_flag_spec='-L$libdir'
hardcode_libdir_separator=
fi
esac
shared_flag='-shared'
else
# not using gcc
if test "$host_cpu" = ia64; then
shared_flag='${wl}-G'
else
shared_flag='${wl}-bM:SRE'
fi
fi
if test "$host_cpu" = ia64; then
# On IA64, the linker does run time linking by default, so we don't
# have to do anything special.
aix_use_runtimelinking=no
if test $with_gnu_ld = no; then
exp_sym_flag='-Bexport'
no_entry_flag=""
fi
else
# Test if we are trying to use run time linking, or normal AIX style linking.
# If -brtl is somewhere in LDFLAGS, we need to do run time linking.
aix_use_runtimelinking=no
for ld_flag in $LDFLAGS; do
if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl" ); then
aix_use_runtimelinking=yes
break
fi
done
exp_sym_flag='-bexport'
no_entry_flag='-bnoentry'
fi
# -bexpall does not export symbols beginning with underscore (_)
always_export_symbols=yes
if test "$aix_use_runtimelinking" = yes; then
# Warning - without using the other run time loading flags (-brtl), -berok will
# link without error, but may produce a broken library.
allow_undefined_flag=' ${wl}-berok'
hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
else
if test "$host_cpu" = ia64; then
if test $with_gnu_ld = no; then
hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
allow_undefined_flag="-z nodefs"
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
fi
else
allow_undefined_flag=' ${wl}-berok'
# -bexpall does not export symbols beginning with underscore (_)
always_export_symbols=yes
# Exported symbols can be pulled into shared objects from archives
whole_archive_flag_spec=' '
build_libtool_need_lc=yes
hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
# This is similar to how AIX traditionally builds it's shared libraries.
archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
fi
fi
;;
amigaos*)
archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
# see comment about different semantics on the GNU ld section
ld_shlibs=no
;;
cygwin* | mingw*)
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
# hardcode_libdir_flag_spec is actually meaningless, as there is
# no search path for DLLs.
hardcode_libdir_flag_spec=' '
allow_undefined_flag=unsupported
# Tell ltmain to make .lib files, not .a files.
libext=lib
# FIXME: Setting linknames here is a bad hack.
archive_cmds='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | sed -e '\''s/ -lc$//'\''` -link -dll~linknames='
# The linker will automatically build a .lib file if we build a DLL.
old_archive_from_new_cmds='true'
# FIXME: Should let the user specify the lib program.
old_archive_cmds='lib /OUT:$oldlib$oldobjs$old_deplibs'
fix_srcfile_path='`cygpath -w "$srcfile"`'
;;
darwin* | rhapsody*)
case "$host_os" in
rhapsody* | darwin1.[[012]])
allow_undefined_flag='-undefined suppress'
;;
*) # Darwin 1.3 on
if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
allow_undefined_flag='-flat_namespace -undefined suppress'
else
case ${MACOSX_DEPLOYMENT_TARGET} in
10.[[012]])
allow_undefined_flag='-flat_namespace -undefined suppress'
;;
10.*)
allow_undefined_flag='-undefined dynamic_lookup'
;;
esac
fi
;;
esac
# Disable shared library build on OS-X older than 10.3.
case $host_os in
darwin[1-6]*)
can_build_shared=no
;;
darwin7*)
can_build_shared=yes
;;
esac
output_verbose_link_cmd='echo'
archive_cmds='$CC -r ${wl}-bind_at_load -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring'
module_cmds='$CC ${wl}-bind_at_load $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
# Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r ${wl}-bind_at_load -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
module_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
hardcode_direct=no
hardcode_automatic=yes
hardcode_shlibpath_var=unsupported
whole_archive_flag_spec='-all_load $convenience'
link_all_deplibs=yes
;;
freebsd1*)
ld_shlibs=no
;;
# FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
# support. Future versions do this automatically, but an explicit c++rt0.o
# does not break anything, and helps significantly (at the cost of a little
# extra space).
freebsd2.2*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
# Unfortunately, older versions of FreeBSD 2 do not have this feature.
freebsd2*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
hardcode_direct=yes
hardcode_minus_L=yes
hardcode_shlibpath_var=no
;;
# FreeBSD 3 and greater uses gcc -shared to do shared libraries.
freebsd* | kfreebsd*-gnu)
archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
hpux9* | hpux10* | hpux11*)
case $host_os in
hpux9*) archive_cmds='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' ;;
*) archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' ;;
esac
hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
hardcode_libdir_separator=:
hardcode_direct=yes
hardcode_minus_L=yes # Not in the search PATH, but as the default
# location of the library.
export_dynamic_flag_spec='${wl}-E'
;;
irix5* | irix6*)
if test "$with_gcc" = yes; then
archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
else
archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
fi
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
link_all_deplibs=yes
;;
netbsd* | knetbsd*-gnu)
if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out
else
archive_cmds='$LD -shared -nodefaultlibs -o $lib $libobjs $deplibs $linker_flags' # ELF
fi
hardcode_libdir_flag_spec='${wl}-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
openbsd*)
archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-R$libdir'
hardcode_direct=yes
hardcode_shlibpath_var=no
;;
os2*)
hardcode_libdir_flag_spec='-L$libdir'
hardcode_minus_L=yes
allow_undefined_flag=unsupported
archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
;;
osf3*)
if test "$with_gcc" = yes; then
allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
else
allow_undefined_flag=' -expect_unresolved \*'
archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
fi
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
;;
osf4* | osf5*) # as osf3* with the addition of -msym flag
if test "$with_gcc" = yes; then
allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
else
allow_undefined_flag=' -expect_unresolved \*'
archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
fi
hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
hardcode_libdir_separator=:
;;
sco3.2v5*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
runpath_var=LD_RUN_PATH
hardcode_runpath_var=yes
;;
solaris*)
no_undefined_flag=' ${wl}-z ${wl}defs'
archive_cmds='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
$CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
# Commands to make compiler produce verbose output that lists
# what "hidden" libraries, object files and flags are used when
# linking a shared library.
output_verbose_link_cmds="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | egrep \"\-L\""
hardcode_libdir_flag_spec='${wl}-R $wl$libdir'
hardcode_shlibpath_var=no
case $host_os in
solaris2.[0-5] | solaris2.[0-5].*) ;;
*) # Supported since Solaris 2.6 (maybe 2.5.1?)
whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' ;;
esac
link_all_deplibs=yes
;;
sunos4*)
archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_direct=yes
hardcode_minus_L=yes
hardcode_shlibpath_var=no
;;
sysv4)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
runpath_var='LD_RUN_PATH'
hardcode_shlibpath_var=no
hardcode_direct=no #Motorola manual says yes, but my tests say they lie
;;
sysv4.3*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
export_dynamic_flag_spec='-Bexport'
;;
sysv5*)
no_undefined_flag=' -z text'
# $CC -shared without GNU ld will not create a library from C++
# object files and a static libstdc++, better avoid it by now
archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
hardcode_libdir_flag_spec=
hardcode_shlibpath_var=no
runpath_var='LD_RUN_PATH'
;;
uts4*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_shlibpath_var=no
;;
dgux*)
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_libdir_flag_spec='-L$libdir'
hardcode_shlibpath_var=no
;;
sysv4*MP*)
if test -d /usr/nec; then
archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
hardcode_shlibpath_var=no
runpath_var=LD_RUN_PATH
hardcode_runpath_var=yes
ld_shlibs=yes
fi
;;
sysv4.2uw2*)
archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
hardcode_direct=yes
hardcode_minus_L=no
hardcode_shlibpath_var=no
hardcode_runpath_var=yes
runpath_var=LD_RUN_PATH
;;
sysv5uw7* | unixware7*)
no_undefined_flag='${wl}-z ${wl}text'
if test "$GCC" = yes; then
archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
else
archive_cmds='$CC -G ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
fi
runpath_var='LD_RUN_PATH'
hardcode_shlibpath_var=no
;;
*)
ld_shlibs=no
;;
esac
fi
## Compiler Characteristics: PIC flags, static flags, etc
# We don't use cached values here since only the C compiler
# characteristics should be cached.
ac_cv_prog_cc_pic=
ac_cv_prog_cc_shlib=
ac_cv_prog_cc_wl=
ac_cv_prog_cc_static=
ac_cv_prog_cc_no_builtin=
ac_cv_prog_cc_can_build_shared=$can_build_shared
ac_cv_prog_cc_wl='-Wl,'
ac_cv_prog_cc_static='-static'
case $host_os in
beos* | irix5* | irix6* | osf3* | osf4* | osf5*)
# PIC is the default for these OSes.
;;
aix*)
# Below there is a dirty hack to force normal static linking with -ldl
# The problem is because libdl dynamically linked with both libc and
# libC (AIX C++ library), which obviously doesn't included in libraries
# list by gcc. This cause undefined symbols with -static flags.
# This hack allows C programs to be linked with "-static -ldl", but
# we not sure about C++ programs.
ac_cv_prog_cc_static="$ac_cv_prog_cc_static ${ac_cv_prog_cc_wl}-lC"
;;
*djgpp*)
# DJGPP does not suppot shared libraries at all
ac_cv_prog_cc_pic=
;;
cygwin* | mingw* | os2*)
# This hack is so that the source file can tell whether it is being
# built for inclusion in a dll (and should export symbols for example).
ac_cv_prog_cc_pic='-DDLL_EXPORT'
;;
darwin* | rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
ac_cv_prog_cc_pic='-fno-common'
;;
amigaos*)
# FIXME: we need at least 68020 code to build shared libraries, but
# adding the `-m68020' flag to GCC prevents building anything better,
# like `-m68040'.
ac_cv_prog_cc_pic='-m68020 -resident32 -malways-restore-a4'
;;
sysv4*MP*)
if test -d /usr/nec; then
ac_cv_prog_cc_pic=-Kconform_pic
fi
;;
*)
ac_cv_prog_cc_pic='-fPIC'
;;
esac
# GCJ did not exist at the time GCC didn't implicitly link libc in.
need_lc=no
# All existing releases of GCJ support `-c -o'.
lt_cv_compiler_c_o=yes

2862
js/ctypes/libffi/ltconfig Executable file

File diff suppressed because it is too large Load Diff

6930
js/ctypes/libffi/ltmain.sh Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
## Process this with automake to create Makefile.in
AUTOMAKE_OPTIONS=foreign
EXTRA_DIST = ffi.3 ffi_call.3 ffi_prep_cif.3
man_MANS = ffi.3 ffi_call.3 ffi_prep_cif.3

View File

@@ -0,0 +1,398 @@
# Makefile.in generated by automake 1.10.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = man
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/fficonfig.h
CONFIG_CLEAN_FILES =
SOURCES =
DIST_SOURCES =
man3dir = $(mandir)/man3
am__installdirs = "$(DESTDIR)$(man3dir)"
NROFF = nroff
MANS = $(man_MANS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
AM_RUNTESTFLAGS = @AM_RUNTESTFLAGS@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCAS = @CCAS@
CCASDEPMODE = @CCASDEPMODE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DSYMUTIL = @DSYMUTIL@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GREP = @GREP@
HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NMEDIT = @NMEDIT@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
TARGET = @TARGET@
TARGETDIR = @TARGETDIR@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
toolexecdir = @toolexecdir@
toolexeclibdir = @toolexeclibdir@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = foreign
EXTRA_DIST = ffi.3 ffi_call.3 ffi_prep_cif.3
man_MANS = ffi.3 ffi_call.3 ffi_prep_cif.3
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
&& exit 0; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign man/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign man/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-man3: $(man3_MANS) $(man_MANS)
@$(NORMAL_INSTALL)
test -z "$(man3dir)" || $(MKDIR_P) "$(DESTDIR)$(man3dir)"
@list='$(man3_MANS) $(dist_man3_MANS) $(nodist_man3_MANS)'; \
l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
for i in $$l2; do \
case "$$i" in \
*.3*) list="$$list $$i" ;; \
esac; \
done; \
for i in $$list; do \
if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \
else file=$$i; fi; \
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
case "$$ext" in \
3*) ;; \
*) ext='3' ;; \
esac; \
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
inst=`echo $$inst | sed -e 's/^.*\///'`; \
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man3dir)/$$inst'"; \
$(INSTALL_DATA) "$$file" "$(DESTDIR)$(man3dir)/$$inst"; \
done
uninstall-man3:
@$(NORMAL_UNINSTALL)
@list='$(man3_MANS) $(dist_man3_MANS) $(nodist_man3_MANS)'; \
l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
for i in $$l2; do \
case "$$i" in \
*.3*) list="$$list $$i" ;; \
esac; \
done; \
for i in $$list; do \
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
case "$$ext" in \
3*) ;; \
*) ext='3' ;; \
esac; \
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
inst=`echo $$inst | sed -e 's/^.*\///'`; \
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
echo " rm -f '$(DESTDIR)$(man3dir)/$$inst'"; \
rm -f "$(DESTDIR)$(man3dir)/$$inst"; \
done
tags: TAGS
TAGS:
ctags: CTAGS
CTAGS:
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(MANS)
installdirs:
for dir in "$(DESTDIR)$(man3dir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am:
html: html-am
info: info-am
info-am:
install-data-am: install-man
install-dvi: install-dvi-am
install-exec-am:
install-html: install-html-am
install-info: install-info-am
install-man: install-man3
install-pdf: install-pdf-am
install-ps: install-ps-am
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-man
uninstall-man: uninstall-man3
.MAKE: install-am install-strip
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
distclean distclean-generic distclean-libtool distdir dvi \
dvi-am html html-am info info-am install install-am \
install-data install-data-am install-dvi install-dvi-am \
install-exec install-exec-am install-html install-html-am \
install-info install-info-am install-man install-man3 \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
uninstall uninstall-am uninstall-man uninstall-man3
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@@ -0,0 +1,31 @@
.Dd February 15, 2008
.Dt FFI 3
.Sh NAME
.Nm FFI
.Nd Foreign Function Interface
.Sh LIBRARY
libffi, -lffi
.Sh SYNOPSIS
.In ffi.h
.Ft ffi_status
.Fo ffi_prep_cif
.Fa "ffi_cif *cif"
.Fa "ffi_abi abi"
.Fa "unsigned int nargs"
.Fa "ffi_type *rtype"
.Fa "ffi_type **atypes"
.Fc
.Ft void
.Fo ffi_call
.Fa "ffi_cif *cif"
.Fa "void (*fn)(void)"
.Fa "void *rvalue"
.Fa "void **avalue"
.Fc
.Sh DESCRIPTION
The foreign function interface provides a mechanism by which a function can
generate a call to another function at runtime without requiring knowledge of
the called function's interface at compile time.
.Sh SEE ALSO
.Xr ffi_prep_cif 3 ,
.Xr ffi_call 3

View File

@@ -0,0 +1,103 @@
.Dd February 15, 2008
.Dt ffi_call 3
.Sh NAME
.Nm ffi_call
.Nd Invoke a foreign function.
.Sh SYNOPSIS
.In ffi.h
.Ft void
.Fo ffi_call
.Fa "ffi_cif *cif"
.Fa "void (*fn)(void)"
.Fa "void *rvalue"
.Fa "void **avalue"
.Fc
.Sh DESCRIPTION
The
.Nm ffi_call
function provides a simple mechanism for invoking a function without
requiring knowledge of the function's interface at compile time.
.Fa fn
is called with the values retrieved from the pointers in the
.Fa avalue
array. The return value from
.Fa fn
is placed in storage pointed to by
.Fa rvalue .
.Fa cif
contains information describing the data types, sizes and alignments of the
arguments to and return value from
.Fa fn ,
and must be initialized with
.Nm ffi_prep_cif
before it is used with
.Nm ffi_call .
.Pp
.Fa rvalue
must point to storage that is sizeof(long) or larger. For smaller
return value sizes, the
.Nm ffi_arg
or
.Nm ffi_sarg
integral type must be used to hold
the return value.
.Sh EXAMPLES
.Bd -literal
#include <ffi/ffi.h>
#include <stdio.h>
unsigned char
foo(unsigned int, float);
int
main(int argc, const char **argv)
{
ffi_cif cif;
ffi_type *arg_types[2];
void *arg_values[2];
ffi_status status;
// Because the return value from foo() is smaller than sizeof(long), it
// must be passed as ffi_arg or ffi_sarg.
ffi_arg result;
// Specify the data type of each argument. Available types are defined
// in <ffi/ffi.h>.
arg_types[0] = &ffi_type_uint;
arg_types[1] = &ffi_type_float;
// Prepare the ffi_cif structure.
if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
2, &ffi_type_uint8, arg_types)) != FFI_OK)
{
// Handle the ffi_status error.
}
// Specify the values of each argument.
unsigned int arg1 = 42;
float arg2 = 5.1;
arg_values[0] = &arg1;
arg_values[1] = &arg2;
// Invoke the function.
ffi_call(&cif, FFI_FN(foo), &result, arg_values);
// The ffi_arg 'result' now contains the unsigned char returned from foo(),
// which can be accessed by a typecast.
printf("result is %hhu", (unsigned char)result);
return 0;
}
// The target function.
unsigned char
foo(unsigned int x, float y)
{
unsigned char result = x - y;
return result;
}
.Ed
.Sh SEE ALSO
.Xr ffi 3 ,
.Xr ffi_prep_cif 3

View File

@@ -0,0 +1,66 @@
.Dd February 15, 2008
.Dt ffi_prep_cif 3
.Sh NAME
.Nm ffi_prep_cif
.Nd Prepare a
.Nm ffi_cif
structure for use with
.Nm ffi_call
.
.Sh SYNOPSIS
.In ffi.h
.Ft ffi_status
.Fo ffi_prep_cif
.Fa "ffi_cif *cif"
.Fa "ffi_abi abi"
.Fa "unsigned int nargs"
.Fa "ffi_type *rtype"
.Fa "ffi_type **atypes"
.Fc
.Sh DESCRIPTION
The
.Nm ffi_prep_cif
function prepares a
.Nm ffi_cif
structure for use with
.Nm ffi_call
.
.Fa abi
specifies a set of calling conventions to use.
.Fa atypes
is an array of
.Fa nargs
pointers to
.Nm ffi_type
structs that describe the data type, size and alignment of each argument.
.Fa rtype
points to an
.Nm ffi_type
that describes the data type, size and alignment of the
return value.
.Sh RETURN VALUES
Upon successful completion,
.Nm ffi_prep_cif
returns
.Nm FFI_OK .
It will return
.Nm FFI_BAD_TYPEDEF
if
.Fa cif
is
.Nm NULL
or
.Fa atypes
or
.Fa rtype
is malformed. If
.Fa abi
does not refer to a valid ABI,
.Nm FFI_BAD_ABI
will be returned. Available ABIs are
defined in
.Nm <ffitarget.h>
.
.Sh SEE ALSO
.Xr ffi 3 ,
.Xr ffi_call 3

201
js/ctypes/libffi/mdate-sh Executable file
View File

@@ -0,0 +1,201 @@
#!/bin/sh
# Get modification time of a file or directory and pretty-print it.
scriptversion=2005-06-29.22
# Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software
# Foundation, Inc.
# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
#
# 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.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
case $1 in
'')
echo "$0: No file. Try \`$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: mdate-sh [--help] [--version] FILE
Pretty-print the modification time of FILE.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "mdate-sh $scriptversion"
exit $?
;;
esac
# Prevent date giving response in another language.
LANG=C
export LANG
LC_ALL=C
export LC_ALL
LC_TIME=C
export LC_TIME
# GNU ls changes its time format in response to the TIME_STYLE
# variable. Since we cannot assume `unset' works, revert this
# variable to its documented default.
if test "${TIME_STYLE+set}" = set; then
TIME_STYLE=posix-long-iso
export TIME_STYLE
fi
save_arg1=$1
# Find out how to get the extended ls output of a file or directory.
if ls -L /dev/null 1>/dev/null 2>&1; then
ls_command='ls -L -l -d'
else
ls_command='ls -l -d'
fi
# A `ls -l' line looks as follows on OS/2.
# drwxrwx--- 0 Aug 11 2001 foo
# This differs from Unix, which adds ownership information.
# drwxrwx--- 2 root root 4096 Aug 11 2001 foo
#
# To find the date, we split the line on spaces and iterate on words
# until we find a month. This cannot work with files whose owner is a
# user named `Jan', or `Feb', etc. However, it's unlikely that `/'
# will be owned by a user whose name is a month. So we first look at
# the extended ls output of the root directory to decide how many
# words should be skipped to get the date.
# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
set x`ls -l -d /`
# Find which argument is the month.
month=
command=
until test $month
do
shift
# Add another shift to the command.
command="$command shift;"
case $1 in
Jan) month=January; nummonth=1;;
Feb) month=February; nummonth=2;;
Mar) month=March; nummonth=3;;
Apr) month=April; nummonth=4;;
May) month=May; nummonth=5;;
Jun) month=June; nummonth=6;;
Jul) month=July; nummonth=7;;
Aug) month=August; nummonth=8;;
Sep) month=September; nummonth=9;;
Oct) month=October; nummonth=10;;
Nov) month=November; nummonth=11;;
Dec) month=December; nummonth=12;;
esac
done
# Get the extended ls output of the file or directory.
set dummy x`eval "$ls_command \"\$save_arg1\""`
# Remove all preceding arguments
eval $command
# Because of the dummy argument above, month is in $2.
#
# On a POSIX system, we should have
#
# $# = 5
# $1 = file size
# $2 = month
# $3 = day
# $4 = year or time
# $5 = filename
#
# On Darwin 7.7.0 and 7.6.0, we have
#
# $# = 4
# $1 = day
# $2 = month
# $3 = year or time
# $4 = filename
# Get the month.
case $2 in
Jan) month=January; nummonth=1;;
Feb) month=February; nummonth=2;;
Mar) month=March; nummonth=3;;
Apr) month=April; nummonth=4;;
May) month=May; nummonth=5;;
Jun) month=June; nummonth=6;;
Jul) month=July; nummonth=7;;
Aug) month=August; nummonth=8;;
Sep) month=September; nummonth=9;;
Oct) month=October; nummonth=10;;
Nov) month=November; nummonth=11;;
Dec) month=December; nummonth=12;;
esac
case $3 in
???*) day=$1;;
*) day=$3; shift;;
esac
# Here we have to deal with the problem that the ls output gives either
# the time of day or the year.
case $3 in
*:*) set `date`; eval year=\$$#
case $2 in
Jan) nummonthtod=1;;
Feb) nummonthtod=2;;
Mar) nummonthtod=3;;
Apr) nummonthtod=4;;
May) nummonthtod=5;;
Jun) nummonthtod=6;;
Jul) nummonthtod=7;;
Aug) nummonthtod=8;;
Sep) nummonthtod=9;;
Oct) nummonthtod=10;;
Nov) nummonthtod=11;;
Dec) nummonthtod=12;;
esac
# For the first six month of the year the time notation can also
# be used for files modified in the last year.
if (expr $nummonth \> $nummonthtod) > /dev/null;
then
year=`expr $year - 1`
fi;;
*) year=$3;;
esac
# The result.
echo $day $month $year
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

353
js/ctypes/libffi/missing Executable file
View File

@@ -0,0 +1,353 @@
#! /bin/sh
# Common stub for a few missing GNU programs while installing.
scriptversion=2004-09-07.08
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004
# Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
# 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., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
fi
run=:
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
configure_ac=configure.ac
else
configure_ac=configure.in
fi
msg="missing on your system"
case "$1" in
--run)
# Try to run requested program, and just exit if it succeeds.
run=
shift
"$@" && exit 0
# Exit code 63 means version mismatch. This often happens
# when the user try to use an ancient version of a tool on
# a file that requires a minimum version. In this case we
# we should proceed has if the program had been absent, or
# if --run hadn't been passed.
if test $? = 63; then
run=:
msg="probably too old"
fi
;;
-h|--h|--he|--hel|--help)
echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
Options:
-h, --help display this help and exit
-v, --version output version information and exit
--run try to run the given command, and emulate it if it fails
Supported PROGRAM values:
aclocal touch file \`aclocal.m4'
autoconf touch file \`configure'
autoheader touch file \`config.h.in'
automake touch all \`Makefile.in' files
bison create \`y.tab.[ch]', if possible, from existing .[ch]
flex create \`lex.yy.c', if possible, from existing .c
help2man touch the output file
lex create \`lex.yy.c', if possible, from existing .c
makeinfo touch the output file
tar try tar, gnutar, gtar, then tar without non-portable flags
yacc create \`y.tab.[ch]', if possible, from existing .[ch]
Send bug reports to <bug-automake@gnu.org>."
exit 0
;;
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
echo "missing $scriptversion (GNU Automake)"
exit 0
;;
-*)
echo 1>&2 "$0: Unknown \`$1' option"
echo 1>&2 "Try \`$0 --help' for more information"
exit 1
;;
esac
# Now exit if we have it, but it failed. Also exit now if we
# don't have it and --version was passed (most likely to detect
# the program).
case "$1" in
lex|yacc)
# Not GNU programs, they don't have --version.
;;
tar)
if test -n "$run"; then
echo 1>&2 "ERROR: \`tar' requires --run"
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
exit 1
fi
;;
*)
if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
# We have it, but it failed.
exit 1
elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
# Could not run --version or --help. This is probably someone
# running `$TOOL --version' or `$TOOL --help' to check whether
# $TOOL exists and not knowing $TOOL uses missing.
exit 1
fi
;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case "$1" in
aclocal*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acinclude.m4' or \`${configure_ac}'. You might want
to install the \`Automake' and \`Perl' packages. Grab them from
any GNU archive site."
touch aclocal.m4
;;
autoconf)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`${configure_ac}'. You might want to install the
\`Autoconf' and \`GNU m4' packages. Grab them from any GNU
archive site."
touch configure
;;
autoheader)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`acconfig.h' or \`${configure_ac}'. You might want
to install the \`Autoconf' and \`GNU m4' packages. Grab them
from any GNU archive site."
files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
test -z "$files" && files="config.h"
touch_files=
for f in $files; do
case "$f" in
*:*) touch_files="$touch_files "`echo "$f" |
sed -e 's/^[^:]*://' -e 's/:.*//'`;;
*) touch_files="$touch_files $f.in";;
esac
done
touch $touch_files
;;
automake*)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
You might want to install the \`Automake' and \`Perl' packages.
Grab them from any GNU archive site."
find . -type f -name Makefile.am -print |
sed 's/\.am$/.in/' |
while read f; do touch "$f"; done
;;
autom4te)
echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
You might have modified some files without having the
proper tools for further handling them.
You can get \`$1' as part of \`Autoconf' from any GNU
archive site."
file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
if test -f "$file"; then
touch $file
else
test -z "$file" || exec >$file
echo "#! /bin/sh"
echo "# Created by GNU Automake missing as a replacement of"
echo "# $ $@"
echo "exit 0"
chmod +x $file
exit 1
fi
;;
bison|yacc)
echo 1>&2 "\
WARNING: \`$1' $msg. You should only need it if
you modified a \`.y' file. You may need the \`Bison' package
in order for those modifications to take effect. You can get
\`Bison' from any GNU archive site."
rm -f y.tab.c y.tab.h
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.y)
SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.c
fi
SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" y.tab.h
fi
;;
esac
fi
if [ ! -f y.tab.h ]; then
echo >y.tab.h
fi
if [ ! -f y.tab.c ]; then
echo 'main() { return 0; }' >y.tab.c
fi
;;
lex|flex)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.l' file. You may need the \`Flex' package
in order for those modifications to take effect. You can get
\`Flex' from any GNU archive site."
rm -f lex.yy.c
if [ $# -ne 1 ]; then
eval LASTARG="\${$#}"
case "$LASTARG" in
*.l)
SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
if [ -f "$SRCFILE" ]; then
cp "$SRCFILE" lex.yy.c
fi
;;
esac
fi
if [ ! -f lex.yy.c ]; then
echo 'main() { return 0; }' >lex.yy.c
fi
;;
help2man)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a dependency of a manual page. You may need the
\`Help2man' package in order for those modifications to take
effect. You can get \`Help2man' from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
fi
if [ -f "$file" ]; then
touch $file
else
test -z "$file" || exec >$file
echo ".ab help2man is required to generate this page"
exit 1
fi
;;
makeinfo)
echo 1>&2 "\
WARNING: \`$1' is $msg. You should only need it if
you modified a \`.texi' or \`.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy \`make' (AIX,
DU, IRIX). You might want to install the \`Texinfo' package or
the \`GNU make' package. Grab either from any GNU archive site."
file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
if test -z "$file"; then
file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
fi
touch $file
;;
tar)
shift
# We have already tried tar in the generic part.
# Look for gnutar/gtar before invocation to avoid ugly error
# messages.
if (gnutar --version > /dev/null 2>&1); then
gnutar "$@" && exit 0
fi
if (gtar --version > /dev/null 2>&1); then
gtar "$@" && exit 0
fi
firstarg="$1"
if shift; then
case "$firstarg" in
*o*)
firstarg=`echo "$firstarg" | sed s/o//`
tar "$firstarg" "$@" && exit 0
;;
esac
case "$firstarg" in
*h*)
firstarg=`echo "$firstarg" | sed s/h//`
tar "$firstarg" "$@" && exit 0
;;
esac
fi
echo 1>&2 "\
WARNING: I can't seem to be able to run \`tar' with the given arguments.
You may want to install GNU tar or Free paxutils, or check the
command line arguments."
exit 1
;;
*)
echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
You might have modified some files without having the
proper tools for further handling them. Check the \`README' file,
it often tells you about the needed prerequisites for installing
this package. You may also peek at any GNU archive site, in case
some other package would contain this missing \`$1' program."
exit 1
;;
esac
exit 0
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

158
js/ctypes/libffi/mkinstalldirs Executable file
View File

@@ -0,0 +1,158 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
scriptversion=2005-06-29.22
# Original author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain.
#
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
errstatus=0
dirmode=
usage="\
Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
Create each directory DIR (with mode MODE, if specified), including all
leading file name components.
Report bugs to <bug-automake@gnu.org>."
# process command line arguments
while test $# -gt 0 ; do
case $1 in
-h | --help | --h*) # -h for help
echo "$usage"
exit $?
;;
-m) # -m PERM arg
shift
test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
dirmode=$1
shift
;;
--version)
echo "$0 $scriptversion"
exit $?
;;
--) # stop option processing
shift
break
;;
-*) # unknown option
echo "$usage" 1>&2
exit 1
;;
*) # first non-opt arg
break
;;
esac
done
for file
do
if test -d "$file"; then
shift
else
break
fi
done
case $# in
0) exit 0 ;;
esac
# Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and
# mkdir -p a/c at the same time, both will detect that a is missing,
# one will create a, then the other will try to create a and die with
# a "File exists" error. This is a problem when calling mkinstalldirs
# from a parallel make. We use --version in the probe to restrict
# ourselves to GNU mkdir, which is thread-safe.
case $dirmode in
'')
if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
echo "mkdir -p -- $*"
exec mkdir -p -- "$@"
else
# On NextStep and OpenStep, the `mkdir' command does not
# recognize any option. It will interpret all options as
# directories to create, and then abort because `.' already
# exists.
test -d ./-p && rmdir ./-p
test -d ./--version && rmdir ./--version
fi
;;
*)
if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
test ! -d ./--version; then
echo "mkdir -m $dirmode -p -- $*"
exec mkdir -m "$dirmode" -p -- "$@"
else
# Clean up after NextStep and OpenStep mkdir.
for d in ./-m ./-p ./--version "./$dirmode";
do
test -d $d && rmdir $d
done
fi
;;
esac
for file
do
case $file in
/*) pathcomp=/ ;;
*) pathcomp= ;;
esac
oIFS=$IFS
IFS=/
set fnord $file
shift
IFS=$oIFS
for d
do
test "x$d" = x && continue
pathcomp=$pathcomp$d
case $pathcomp in
-*) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp"
mkdir "$pathcomp" || lasterr=$?
if test ! -d "$pathcomp"; then
errstatus=$lasterr
else
if test ! -z "$dirmode"; then
echo "chmod $dirmode $pathcomp"
lasterr=
chmod "$dirmode" "$pathcomp" || lasterr=$?
if test ! -z "$lasterr"; then
errstatus=$lasterr
fi
fi
fi
fi
pathcomp=$pathcomp/
done
done
exit $errstatus
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@@ -0,0 +1,284 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1998, 2001, 2007, 2008 Red Hat, Inc.
Alpha 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
all further uses in this file will refer to the 128-bit type. */
#if defined(__LONG_DOUBLE_128__)
# if FFI_TYPE_LONGDOUBLE != 4
# error FFI_TYPE_LONGDOUBLE out of date
# endif
#else
# undef FFI_TYPE_LONGDOUBLE
# define FFI_TYPE_LONGDOUBLE 4
#endif
extern void ffi_call_osf(void *, unsigned long, unsigned, void *, void (*)(void))
FFI_HIDDEN;
extern void ffi_closure_osf(void) FFI_HIDDEN;
ffi_status
ffi_prep_cif_machdep(ffi_cif *cif)
{
/* Adjust cif->bytes to represent a minimum 6 words for the temporary
register argument loading area. */
if (cif->bytes < 6*FFI_SIZEOF_ARG)
cif->bytes = 6*FFI_SIZEOF_ARG;
/* Set the return type flag */
switch (cif->rtype->type)
{
case FFI_TYPE_STRUCT:
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags = cif->rtype->type;
break;
case FFI_TYPE_LONGDOUBLE:
/* 128-bit long double is returned in memory, like a struct. */
cif->flags = FFI_TYPE_STRUCT;
break;
default:
cif->flags = FFI_TYPE_INT;
break;
}
return FFI_OK;
}
void
ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
unsigned long *stack, *argp;
long i, avn;
ffi_type **arg_types;
/* 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->flags == FFI_TYPE_STRUCT)
rvalue = alloca(cif->rtype->size);
/* Allocate the space for the arguments, plus 4 words of temp
space for ffi_call_osf. */
argp = stack = alloca(cif->bytes + 4*FFI_SIZEOF_ARG);
if (cif->flags == FFI_TYPE_STRUCT)
*(void **) argp++ = rvalue;
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
while (i < avn)
{
size_t size = (*arg_types)->size;
switch ((*arg_types)->type)
{
case FFI_TYPE_SINT8:
*(SINT64 *) argp = *(SINT8 *)(* avalue);
break;
case FFI_TYPE_UINT8:
*(SINT64 *) argp = *(UINT8 *)(* avalue);
break;
case FFI_TYPE_SINT16:
*(SINT64 *) argp = *(SINT16 *)(* avalue);
break;
case FFI_TYPE_UINT16:
*(SINT64 *) argp = *(UINT16 *)(* avalue);
break;
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
/* Note that unsigned 32-bit quantities are sign extended. */
*(SINT64 *) argp = *(SINT32 *)(* avalue);
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
case FFI_TYPE_POINTER:
*(UINT64 *) argp = *(UINT64 *)(* avalue);
break;
case FFI_TYPE_FLOAT:
if (argp - stack < 6)
{
/* Note the conversion -- all the fp regs are loaded as
doubles. The in-register format is the same. */
*(double *) argp = *(float *)(* avalue);
}
else
*(float *) argp = *(float *)(* avalue);
break;
case FFI_TYPE_DOUBLE:
*(double *) argp = *(double *)(* avalue);
break;
case FFI_TYPE_LONGDOUBLE:
/* 128-bit long double is passed by reference. */
*(long double **) argp = (long double *)(* avalue);
size = sizeof (long double *);
break;
case FFI_TYPE_STRUCT:
memcpy(argp, *avalue, (*arg_types)->size);
break;
default:
FFI_ASSERT(0);
}
argp += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
i++, arg_types++, avalue++;
}
ffi_call_osf(stack, cif->bytes, cif->flags, rvalue, fn);
}
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*, void*, void**, void*),
void *user_data,
void *codeloc)
{
unsigned int *tramp;
tramp = (unsigned int *) &closure->tramp[0];
tramp[0] = 0x47fb0401; /* mov $27,$1 */
tramp[1] = 0xa77b0010; /* ldq $27,16($27) */
tramp[2] = 0x6bfb0000; /* jmp $31,($27),0 */
tramp[3] = 0x47ff041f; /* nop */
*(void **) &tramp[4] = ffi_closure_osf;
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
/* Flush the Icache.
Tru64 UNIX as doesn't understand the imb mnemonic, so use call_pal
instead, since both Compaq as and gas can handle it.
0x86 is PAL_imb in Tru64 UNIX <alpha/pal.h>. */
asm volatile ("call_pal 0x86" : : : "memory");
return FFI_OK;
}
long FFI_HIDDEN
ffi_closure_osf_inner(ffi_closure *closure, void *rvalue, unsigned long *argp)
{
ffi_cif *cif;
void **avalue;
ffi_type **arg_types;
long i, avn, argn;
cif = closure->cif;
avalue = alloca(cif->nargs * sizeof(void *));
argn = 0;
/* Copy the caller's structure return address to that the closure
returns the data directly to the caller. */
if (cif->flags == FFI_TYPE_STRUCT)
{
rvalue = (void *) argp[0];
argn = 1;
}
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
/* Grab the addresses of the arguments from the stack frame. */
while (i < avn)
{
size_t size = arg_types[i]->size;
switch (arg_types[i]->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:
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
case FFI_TYPE_POINTER:
case FFI_TYPE_STRUCT:
avalue[i] = &argp[argn];
break;
case FFI_TYPE_FLOAT:
if (argn < 6)
{
/* Floats coming from registers need conversion from double
back to float format. */
*(float *)&argp[argn - 6] = *(double *)&argp[argn - 6];
avalue[i] = &argp[argn - 6];
}
else
avalue[i] = &argp[argn];
break;
case FFI_TYPE_DOUBLE:
avalue[i] = &argp[argn - (argn < 6 ? 6 : 0)];
break;
case FFI_TYPE_LONGDOUBLE:
/* 128-bit long double is passed by reference. */
avalue[i] = (long double *) argp[argn];
size = sizeof (long double *);
break;
default:
abort ();
}
argn += ALIGN(size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
i++;
}
/* Invoke the closure. */
closure->fun (cif, rvalue, avalue, closure->user_data);
/* Tell ffi_closure_osf how to perform return type promotions. */
return cif->rtype->type;
}

View File

@@ -0,0 +1,48 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for Alpha.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_OSF,
FFI_LAST_ABI,
FFI_DEFAULT_ABI = FFI_OSF
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_TRAMPOLINE_SIZE 24
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,366 @@
/* -----------------------------------------------------------------------
osf.S - Copyright (c) 1998, 2001, 2007, 2008 Red Hat
Alpha/OSF 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
.arch ev6
.text
/* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
void *raddr, void (*fnaddr)(void));
Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
for this function. This has been allocated by ffi_call. We also
deallocate some of the stack that has been alloca'd. */
.align 3
.globl ffi_call_osf
.ent ffi_call_osf
FFI_HIDDEN(ffi_call_osf)
ffi_call_osf:
.frame $15, 32, $26, 0
.mask 0x4008000, -32
$LFB1:
addq $16,$17,$1
mov $16, $30
stq $26, 0($1)
stq $15, 8($1)
stq $18, 16($1)
mov $1, $15
$LCFI1:
.prologue 0
stq $19, 24($1)
mov $20, $27
# Load up all of the (potential) argument registers.
ldq $16, 0($30)
ldt $f16, 0($30)
ldt $f17, 8($30)
ldq $17, 8($30)
ldt $f18, 16($30)
ldq $18, 16($30)
ldt $f19, 24($30)
ldq $19, 24($30)
ldt $f20, 32($30)
ldq $20, 32($30)
ldt $f21, 40($30)
ldq $21, 40($30)
# Deallocate the register argument area.
lda $30, 48($30)
jsr $26, ($27), 0
ldgp $29, 0($26)
# If the return value pointer is NULL, assume no return value.
ldq $19, 24($15)
ldq $18, 16($15)
ldq $26, 0($15)
$LCFI2:
beq $19, $noretval
# Store the return value out in the proper type.
cmpeq $18, FFI_TYPE_INT, $1
bne $1, $retint
cmpeq $18, FFI_TYPE_FLOAT, $2
bne $2, $retfloat
cmpeq $18, FFI_TYPE_DOUBLE, $3
bne $3, $retdouble
.align 3
$noretval:
ldq $15, 8($15)
ret
.align 4
$retint:
stq $0, 0($19)
nop
ldq $15, 8($15)
ret
.align 4
$retfloat:
sts $f0, 0($19)
nop
ldq $15, 8($15)
ret
.align 4
$retdouble:
stt $f0, 0($19)
nop
ldq $15, 8($15)
ret
$LFE1:
.end ffi_call_osf
/* ffi_closure_osf(...)
Receives the closure argument in $1. */
.align 3
.globl ffi_closure_osf
.ent ffi_closure_osf
FFI_HIDDEN(ffi_closure_osf)
ffi_closure_osf:
.frame $30, 16*8, $26, 0
.mask 0x4000000, -16*8
$LFB2:
ldgp $29, 0($27)
subq $30, 16*8, $30
$LCFI5:
stq $26, 0($30)
$LCFI6:
.prologue 1
# Store all of the potential argument registers in va_list format.
stt $f16, 4*8($30)
stt $f17, 5*8($30)
stt $f18, 6*8($30)
stt $f19, 7*8($30)
stt $f20, 8*8($30)
stt $f21, 9*8($30)
stq $16, 10*8($30)
stq $17, 11*8($30)
stq $18, 12*8($30)
stq $19, 13*8($30)
stq $20, 14*8($30)
stq $21, 15*8($30)
# Call ffi_closure_osf_inner to do the bulk of the work.
mov $1, $16
lda $17, 2*8($30)
lda $18, 10*8($30)
jsr $26, ffi_closure_osf_inner
ldgp $29, 0($26)
ldq $26, 0($30)
# Load up the return value in the proper type.
lda $1, $load_table
s4addq $0, $1, $1
ldl $1, 0($1)
addq $1, $29, $1
jmp $31, ($1), $load_32
.align 4
$load_none:
addq $30, 16*8, $30
ret
.align 4
$load_float:
lds $f0, 16($30)
nop
addq $30, 16*8, $30
ret
.align 4
$load_double:
ldt $f0, 16($30)
nop
addq $30, 16*8, $30
ret
.align 4
$load_u8:
#ifdef __alpha_bwx__
ldbu $0, 16($30)
nop
#else
ldq $0, 16($30)
and $0, 255, $0
#endif
addq $30, 16*8, $30
ret
.align 4
$load_s8:
#ifdef __alpha_bwx__
ldbu $0, 16($30)
sextb $0, $0
#else
ldq $0, 16($30)
sll $0, 56, $0
sra $0, 56, $0
#endif
addq $30, 16*8, $30
ret
.align 4
$load_u16:
#ifdef __alpha_bwx__
ldwu $0, 16($30)
nop
#else
ldq $0, 16($30)
zapnot $0, 3, $0
#endif
addq $30, 16*8, $30
ret
.align 4
$load_s16:
#ifdef __alpha_bwx__
ldwu $0, 16($30)
sextw $0, $0
#else
ldq $0, 16($30)
sll $0, 48, $0
sra $0, 48, $0
#endif
addq $30, 16*8, $30
ret
.align 4
$load_32:
ldl $0, 16($30)
nop
addq $30, 16*8, $30
ret
.align 4
$load_64:
ldq $0, 16($30)
nop
addq $30, 16*8, $30
ret
$LFE2:
.end ffi_closure_osf
#ifdef __ELF__
.section .rodata
#else
.rdata
#endif
$load_table:
.gprel32 $load_none # FFI_TYPE_VOID
.gprel32 $load_32 # FFI_TYPE_INT
.gprel32 $load_float # FFI_TYPE_FLOAT
.gprel32 $load_double # FFI_TYPE_DOUBLE
.gprel32 $load_none # FFI_TYPE_LONGDOUBLE
.gprel32 $load_u8 # FFI_TYPE_UINT8
.gprel32 $load_s8 # FFI_TYPE_SINT8
.gprel32 $load_u16 # FFI_TYPE_UINT16
.gprel32 $load_s16 # FFI_TYPE_SINT16
.gprel32 $load_32 # FFI_TYPE_UINT32
.gprel32 $load_32 # FFI_TYPE_SINT32
.gprel32 $load_64 # FFI_TYPE_UINT64
.gprel32 $load_64 # FFI_TYPE_SINT64
.gprel32 $load_none # FFI_TYPE_STRUCT
.gprel32 $load_64 # FFI_TYPE_POINTER
/* Assert that the table above is in sync with ffi.h. */
#if FFI_TYPE_FLOAT != 2 \
|| FFI_TYPE_DOUBLE != 3 \
|| FFI_TYPE_UINT8 != 5 \
|| FFI_TYPE_SINT8 != 6 \
|| FFI_TYPE_UINT16 != 7 \
|| FFI_TYPE_SINT16 != 8 \
|| FFI_TYPE_UINT32 != 9 \
|| FFI_TYPE_SINT32 != 10 \
|| FFI_TYPE_UINT64 != 11 \
|| FFI_TYPE_SINT64 != 12 \
|| FFI_TYPE_STRUCT != 13 \
|| FFI_TYPE_POINTER != 14 \
|| FFI_TYPE_LAST != 14
#error "osf.S out of sync with ffi.h"
#endif
#ifdef __ELF__
.section .eh_frame,EH_FRAME_FLAGS,@progbits
__FRAME_BEGIN__:
.4byte $LECIE1-$LSCIE1 # Length of Common Information Entry
$LSCIE1:
.4byte 0x0 # CIE Identifier Tag
.byte 0x1 # CIE Version
.ascii "zR\0" # CIE Augmentation
.byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
.byte 0x78 # sleb128 -8; CIE Data Alignment Factor
.byte 26 # CIE RA Column
.byte 0x1 # uleb128 0x1; Augmentation size
.byte 0x1b # FDE Encoding (pcrel sdata4)
.byte 0xc # DW_CFA_def_cfa
.byte 30 # uleb128 column 30
.byte 0 # uleb128 offset 0
.align 3
$LECIE1:
$LSFDE1:
.4byte $LEFDE1-$LASFDE1 # FDE Length
$LASFDE1:
.4byte $LASFDE1-__FRAME_BEGIN__ # FDE CIE offset
.4byte $LFB1-. # FDE initial location
.4byte $LFE1-$LFB1 # FDE address range
.byte 0x0 # uleb128 0x0; Augmentation size
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI1-$LFB1
.byte 0x9a # DW_CFA_offset, column 26
.byte 4 # uleb128 4*-8
.byte 0x8f # DW_CFA_offset, column 15
.byte 0x3 # uleb128 3*-8
.byte 0xc # DW_CFA_def_cfa
.byte 15 # uleb128 column 15
.byte 32 # uleb128 offset 32
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI2-$LCFI1
.byte 0xda # DW_CFA_restore, column 26
.align 3
$LEFDE1:
$LSFDE3:
.4byte $LEFDE3-$LASFDE3 # FDE Length
$LASFDE3:
.4byte $LASFDE3-__FRAME_BEGIN__ # FDE CIE offset
.4byte $LFB2-. # FDE initial location
.4byte $LFE2-$LFB2 # FDE address range
.byte 0x0 # uleb128 0x0; Augmentation size
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI5-$LFB2
.byte 0xe # DW_CFA_def_cfa_offset
.byte 0x80,0x1 # uleb128 128
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI6-$LCFI5
.byte 0x9a # DW_CFA_offset, column 26
.byte 16 # uleb128 offset 16*-8
.align 3
$LEFDE3:
#ifdef __linux__
.section .note.GNU-stack,"",@progbits
#endif
#endif

View File

@@ -0,0 +1,309 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1998, 2008 Red Hat, Inc.
ARM 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments */
void ffi_prep_args(char *stack, extended_cif *ecif)
{
register unsigned int i;
register void **p_argv;
register char *argp;
register ffi_type **p_arg;
argp = stack;
if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
*(void **) argp = ecif->rvalue;
argp += 4;
}
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0);
i--, p_arg++)
{
size_t z;
/* Align if necessary */
if (((*p_arg)->alignment - 1) & (unsigned) argp) {
argp = (char *) ALIGN(argp, (*p_arg)->alignment);
}
if ((*p_arg)->type == FFI_TYPE_STRUCT)
argp = (char *) ALIGN(argp, 4);
z = (*p_arg)->size;
if (z < sizeof(int))
{
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:
memcpy(argp, *p_argv, (*p_arg)->size);
break;
default:
FFI_ASSERT(0);
}
}
else if (z == sizeof(int))
{
*(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
}
else
{
memcpy(argp, *p_argv, z);
}
p_argv++;
argp += z;
}
return;
}
/* Perform machine dependent cif processing */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
/* Round the stack up to a multiple of 8 bytes. This isn't needed
everywhere, but it is on some platforms, and it doesn't harm anything
when it isn't needed. */
cif->bytes = (cif->bytes + 7) & ~7;
/* Set the return type flag */
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags = (unsigned) cif->rtype->type;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
cif->flags = (unsigned) FFI_TYPE_SINT64;
break;
case FFI_TYPE_STRUCT:
if (cif->rtype->size <= 4)
/* A Composite Type not larger than 4 bytes is returned in r0. */
cif->flags = (unsigned)FFI_TYPE_INT;
else
/* A Composite Type larger than 4 bytes, or whose size cannot
be determined statically ... is stored in memory at an
address passed [in r0]. */
cif->flags = (unsigned)FFI_TYPE_STRUCT;
break;
default:
cif->flags = FFI_TYPE_INT;
break;
}
return FFI_OK;
}
extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
unsigned, unsigned, unsigned *, void (*fn)(void));
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
extended_cif ecif;
int small_struct = (cif->flags == FFI_TYPE_INT
&& cif->rtype->type == FFI_TYPE_STRUCT);
ecif.cif = cif;
ecif.avalue = avalue;
unsigned int temp;
/* 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->flags == FFI_TYPE_STRUCT))
{
ecif.rvalue = alloca(cif->rtype->size);
}
else if (small_struct)
ecif.rvalue = &temp;
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_SYSV:
ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes, cif->flags, ecif.rvalue,
fn);
break;
default:
FFI_ASSERT(0);
break;
}
if (small_struct)
memcpy (rvalue, &temp, cif->rtype->size);
}
/** private members **/
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
void** args, ffi_cif* cif);
void ffi_closure_SYSV (ffi_closure *);
/* This function is jumped to by the trampoline */
unsigned int
ffi_closure_SYSV_inner (closure, respp, args)
ffi_closure *closure;
void **respp;
void *args;
{
// our various things...
ffi_cif *cif;
void **arg_area;
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*));
/* this call will initialize ARG_AREA, such that each
* element in that array points to the corresponding
* value on the stack; and if the function returns
* a structure, it will re-set RESP to point to the
* structure return address. */
ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif);
(closure->fun) (cif, *respp, arg_area, closure->user_data);
return cif->flags;
}
/*@-exportheader@*/
static void
ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
void **avalue, ffi_cif *cif)
/*@=exportheader@*/
{
register unsigned int i;
register void **p_argv;
register char *argp;
register ffi_type **p_arg;
argp = stack;
if ( cif->flags == FFI_TYPE_STRUCT ) {
*rvalue = *(void **) argp;
argp += 4;
}
p_argv = avalue;
for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
{
size_t z;
size_t alignment = (*p_arg)->alignment;
if (alignment < 4)
alignment = 4;
/* Align if necessary */
if ((alignment - 1) & (unsigned) argp) {
argp = (char *) ALIGN(argp, alignment);
}
z = (*p_arg)->size;
/* because we're little endian, this is what it turns into. */
*p_argv = (void*) argp;
p_argv++;
argp += z;
}
return;
}
/* How to make a trampoline. */
#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \
unsigned int __ctx = (unsigned int)(CTX); \
*(unsigned int*) &__tramp[0] = 0xe92d000f; /* stmfd sp!, {r0-r3} */ \
*(unsigned int*) &__tramp[4] = 0xe59f0000; /* ldr r0, [pc] */ \
*(unsigned int*) &__tramp[8] = 0xe59ff000; /* ldr pc, [pc] */ \
*(unsigned int*) &__tramp[12] = __ctx; \
*(unsigned int*) &__tramp[16] = __fun; \
__clear_cache((&__tramp[0]), (&__tramp[19])); \
})
/* the cif must already be prep'ed */
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void *codeloc)
{
FFI_ASSERT (cif->abi == FFI_SYSV);
FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
&ffi_closure_SYSV, \
codeloc);
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
return FFI_OK;
}

View File

@@ -0,0 +1,49 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for ARM.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_SYSV,
FFI_DEFAULT_ABI = FFI_SYSV,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_TRAMPOLINE_SIZE 20
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,299 @@
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 1998, 2008 Red Hat, Inc.
ARM 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#ifdef HAVE_MACHINE_ASM_H
#include <machine/asm.h>
#else
#ifdef __USER_LABEL_PREFIX__
#define CONCAT1(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a ## b
/* Use the right prefix for global labels. */
#define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
#else
#define CNAME(x) x
#endif
#define ENTRY(x) .globl CNAME(x); .type CNAME(x),%function; CNAME(x):
#endif
#ifdef __ELF__
#define LSYM(x) .x
#else
#define LSYM(x) x
#endif
/* We need a better way of testing for this, but for now, this is all
we can do. */
@ This selects the minimum architecture level required.
#define __ARM_ARCH__ 3
#if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
# undef __ARM_ARCH__
# define __ARM_ARCH__ 4
#endif
#if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
|| defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
|| defined(__ARM_ARCH_5TEJ__)
# undef __ARM_ARCH__
# define __ARM_ARCH__ 5
#endif
#if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
|| defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
|| defined(__ARM_ARCH_6ZK__)
# undef __ARM_ARCH__
# define __ARM_ARCH__ 6
#endif
#if __ARM_ARCH__ >= 5
# define call_reg(x) blx x
#elif defined (__ARM_ARCH_4T__)
# define call_reg(x) mov lr, pc ; bx x
# if defined(__thumb__) || defined(__THUMB_INTERWORK__)
# define __INTERWORKING__
# endif
#else
# define call_reg(x) mov lr, pc ; mov pc, x
#endif
/* Conditionally compile unwinder directives. */
#ifdef __ARM_EABI__
#define UNWIND
#else
#define UNWIND @
#endif
#if defined(__thumb__) && !defined(__THUMB_INTERWORK__)
.macro ARM_FUNC_START name
.text
.align 0
.thumb
.thumb_func
ENTRY(\name)
bx pc
nop
.arm
UNWIND .fnstart
/* A hook to tell gdb that we've switched to ARM mode. Also used to call
directly from other local arm routines. */
_L__\name:
.endm
#else
.macro ARM_FUNC_START name
.text
.align 0
.arm
ENTRY(\name)
UNWIND .fnstart
.endm
#endif
.macro RETLDM regs=, cond=, dirn=ia
#if defined (__INTERWORKING__)
.ifc "\regs",""
ldr\cond lr, [sp], #4
.else
ldm\cond\dirn sp!, {\regs, lr}
.endif
bx\cond lr
#else
.ifc "\regs",""
ldr\cond pc, [sp], #4
.else
ldm\cond\dirn sp!, {\regs, pc}
.endif
#endif
.endm
@ r0: ffi_prep_args
@ r1: &ecif
@ r2: cif->bytes
@ r3: fig->flags
@ sp+0: ecif.rvalue
@ sp+4: fn
@ This assumes we are using gas.
ARM_FUNC_START ffi_call_SYSV
@ Save registers
stmfd sp!, {r0-r3, fp, lr}
UNWIND .save {r0-r3, fp, lr}
mov fp, sp
UNWIND .setfp fp, sp
@ Make room for all of the new args.
sub sp, fp, r2
@ Place all of the ffi_prep_args in position
mov ip, r0
mov r0, sp
@ r1 already set
@ Call ffi_prep_args(stack, &ecif)
call_reg(ip)
@ move first 4 parameters in registers
ldmia sp, {r0-r3}
@ and adjust stack
ldr ip, [fp, #8]
cmp ip, #16
movhs ip, #16
add sp, sp, ip
@ call (fn) (...)
ldr ip, [fp, #28]
call_reg(ip)
@ Remove the space we pushed for the args
mov sp, fp
@ Load r2 with the pointer to storage for the return value
ldr r2, [sp, #24]
@ Load r3 with the return type code
ldr r3, [sp, #12]
@ If the return value pointer is NULL, assume no return value.
cmp r2, #0
beq LSYM(Lepilogue)
@ return INT
cmp r3, #FFI_TYPE_INT
#ifdef __SOFTFP__
cmpne r3, #FFI_TYPE_FLOAT
#endif
streq r0, [r2]
beq LSYM(Lepilogue)
@ return INT64
cmp r3, #FFI_TYPE_SINT64
#ifdef __SOFTFP__
cmpne r3, #FFI_TYPE_DOUBLE
#endif
stmeqia r2, {r0, r1}
#ifndef __SOFTFP__
beq LSYM(Lepilogue)
@ return FLOAT
cmp r3, #FFI_TYPE_FLOAT
stfeqs f0, [r2]
beq LSYM(Lepilogue)
@ return DOUBLE or LONGDOUBLE
cmp r3, #FFI_TYPE_DOUBLE
stfeqd f0, [r2]
#endif
LSYM(Lepilogue):
RETLDM "r0-r3,fp"
.ffi_call_SYSV_end:
UNWIND .fnend
.size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)
/*
unsigned int FFI_HIDDEN
ffi_closure_SYSV_inner (closure, respp, args)
ffi_closure *closure;
void **respp;
void *args;
*/
ARM_FUNC_START ffi_closure_SYSV
UNWIND .pad #16
add ip, sp, #16
stmfd sp!, {ip, lr}
UNWIND .save {r0, lr}
add r2, sp, #8
.pad #16
sub sp, sp, #16
str sp, [sp, #8]
add r1, sp, #8
bl ffi_closure_SYSV_inner
cmp r0, #FFI_TYPE_INT
beq .Lretint
cmp r0, #FFI_TYPE_FLOAT
#ifdef __SOFTFP__
beq .Lretint
#else
beq .Lretfloat
#endif
cmp r0, #FFI_TYPE_DOUBLE
#ifdef __SOFTFP__
beq .Lretlonglong
#else
beq .Lretdouble
#endif
cmp r0, #FFI_TYPE_LONGDOUBLE
#ifdef __SOFTFP__
beq .Lretlonglong
#else
beq .Lretlongdouble
#endif
cmp r0, #FFI_TYPE_SINT64
beq .Lretlonglong
.Lclosure_epilogue:
add sp, sp, #16
ldmfd sp, {sp, pc}
.Lretint:
ldr r0, [sp]
b .Lclosure_epilogue
.Lretlonglong:
ldr r0, [sp]
ldr r1, [sp, #4]
b .Lclosure_epilogue
#ifndef __SOFTFP__
.Lretfloat:
ldfs f0, [sp]
b .Lclosure_epilogue
.Lretdouble:
ldfd f0, [sp]
b .Lclosure_epilogue
.Lretlongdouble:
ldfd f0, [sp]
b .Lclosure_epilogue
#endif
.ffi_closure_SYSV_end:
UNWIND .fnend
.size CNAME(ffi_closure_SYSV),.ffi_closure_SYSV_end-CNAME(ffi_closure_SYSV)
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",%progbits
#endif

View File

@@ -0,0 +1,575 @@
/* -----------------------------------------------------------------------
closures.c - Copyright (c) 2007 Red Hat, Inc.
Copyright (C) 2007 Free Software Foundation, Inc
Code to allocate and deallocate memory for closures.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#if defined __linux__ && !defined _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <ffi.h>
#include <ffi_common.h>
#ifndef FFI_MMAP_EXEC_WRIT
# if __gnu_linux__
/* This macro indicates it may be forbidden to map anonymous memory
with both write and execute permission. Code compiled when this
option is defined will attempt to map such pages once, but if it
fails, it falls back to creating a temporary file in a writable and
executable filesystem and mapping pages from it into separate
locations in the virtual memory space, one location writable and
another executable. */
# define FFI_MMAP_EXEC_WRIT 1
# endif
#endif
#if FFI_MMAP_EXEC_WRIT && !defined FFI_MMAP_EXEC_SELINUX
# ifdef __linux__
/* When defined to 1 check for SELinux and if SELinux is active,
don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
might cause audit messages. */
# define FFI_MMAP_EXEC_SELINUX 1
# endif
#endif
#if FFI_CLOSURES
# if FFI_MMAP_EXEC_WRIT
#define USE_LOCKS 1
#define USE_DL_PREFIX 1
#define USE_BUILTIN_FFS 1
/* We need to use mmap, not sbrk. */
#define HAVE_MORECORE 0
/* We could, in theory, support mremap, but it wouldn't buy us anything. */
#define HAVE_MREMAP 0
/* We have no use for this, so save some code and data. */
#define NO_MALLINFO 1
/* We need all allocations to be in regular segments, otherwise we
lose track of the corresponding code address. */
#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
/* Don't allocate more than a page unless needed. */
#define DEFAULT_GRANULARITY ((size_t)malloc_getpagesize)
#if FFI_CLOSURE_TEST
/* Don't release single pages, to avoid a worst-case scenario of
continuously allocating and releasing single pages, but release
pairs of pages, which should do just as well given that allocations
are likely to be small. */
#define DEFAULT_TRIM_THRESHOLD ((size_t)malloc_getpagesize)
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <mntent.h>
#include <sys/param.h>
#include <pthread.h>
/* We don't want sys/mman.h to be included after we redefine mmap and
dlmunmap. */
#include <sys/mman.h>
#define LACKS_SYS_MMAN_H 1
#if FFI_MMAP_EXEC_SELINUX
#include <sys/statfs.h>
#include <stdlib.h>
static int selinux_enabled = -1;
static int
selinux_enabled_check (void)
{
struct statfs sfs;
FILE *f;
char *buf = NULL;
size_t len = 0;
if (statfs ("/selinux", &sfs) >= 0
&& (unsigned int) sfs.f_type == 0xf97cff8cU)
return 1;
f = fopen ("/proc/mounts", "r");
if (f == NULL)
return 0;
while (getline (&buf, &len, f) >= 0)
{
char *p = strchr (buf, ' ');
if (p == NULL)
break;
p = strchr (p + 1, ' ');
if (p == NULL)
break;
if (strncmp (p + 1, "selinuxfs ", 10) != 0)
{
free (buf);
fclose (f);
return 1;
}
}
free (buf);
fclose (f);
return 0;
}
#define is_selinux_enabled() (selinux_enabled >= 0 ? selinux_enabled \
: (selinux_enabled = selinux_enabled_check ()))
#else
#define is_selinux_enabled() 0
#endif
/* Declare all functions defined in dlmalloc.c as static. */
static void *dlmalloc(size_t);
static void dlfree(void*);
static void *dlcalloc(size_t, size_t) MAYBE_UNUSED;
static void *dlrealloc(void *, size_t) MAYBE_UNUSED;
static void *dlmemalign(size_t, size_t) MAYBE_UNUSED;
static void *dlvalloc(size_t) MAYBE_UNUSED;
static int dlmallopt(int, int) MAYBE_UNUSED;
static size_t dlmalloc_footprint(void) MAYBE_UNUSED;
static size_t dlmalloc_max_footprint(void) MAYBE_UNUSED;
static void** dlindependent_calloc(size_t, size_t, void**) MAYBE_UNUSED;
static void** dlindependent_comalloc(size_t, size_t*, void**) MAYBE_UNUSED;
static void *dlpvalloc(size_t) MAYBE_UNUSED;
static int dlmalloc_trim(size_t) MAYBE_UNUSED;
static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
static void dlmalloc_stats(void) MAYBE_UNUSED;
/* Use these for mmap and munmap within dlmalloc.c. */
static void *dlmmap(void *, size_t, int, int, int, off_t);
static int dlmunmap(void *, size_t);
#define mmap dlmmap
#define munmap dlmunmap
#include "dlmalloc.c"
#undef mmap
#undef munmap
/* A mutex used to synchronize access to *exec* variables in this file. */
static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;
/* A file descriptor of a temporary file from which we'll map
executable pages. */
static int execfd = -1;
/* The amount of space already allocated from the temporary file. */
static size_t execsize = 0;
/* Open a temporary file name, and immediately unlink it. */
static int
open_temp_exec_file_name (char *name)
{
int fd = mkstemp (name);
if (fd != -1)
unlink (name);
return fd;
}
/* Open a temporary file in the named directory. */
static int
open_temp_exec_file_dir (const char *dir)
{
static const char suffix[] = "/ffiXXXXXX";
int lendir = strlen (dir);
char *tempname = __builtin_alloca (lendir + sizeof (suffix));
if (!tempname)
return -1;
memcpy (tempname, dir, lendir);
memcpy (tempname + lendir, suffix, sizeof (suffix));
return open_temp_exec_file_name (tempname);
}
/* Open a temporary file in the directory in the named environment
variable. */
static int
open_temp_exec_file_env (const char *envvar)
{
const char *value = getenv (envvar);
if (!value)
return -1;
return open_temp_exec_file_dir (value);
}
/* Open a temporary file in an executable and writable mount point
listed in the mounts file. Subsequent calls with the same mounts
keep searching for mount points in the same file. Providing NULL
as the mounts file closes the file. */
static int
open_temp_exec_file_mnt (const char *mounts)
{
static const char *last_mounts;
static FILE *last_mntent;
if (mounts != last_mounts)
{
if (last_mntent)
endmntent (last_mntent);
last_mounts = mounts;
if (mounts)
last_mntent = setmntent (mounts, "r");
else
last_mntent = NULL;
}
if (!last_mntent)
return -1;
for (;;)
{
int fd;
struct mntent mnt;
char buf[MAXPATHLEN * 3];
if (getmntent_r (last_mntent, &mnt, buf, sizeof (buf)))
return -1;
if (hasmntopt (&mnt, "ro")
|| hasmntopt (&mnt, "noexec")
|| access (mnt.mnt_dir, W_OK))
continue;
fd = open_temp_exec_file_dir (mnt.mnt_dir);
if (fd != -1)
return fd;
}
}
/* Instructions to look for a location to hold a temporary file that
can be mapped in for execution. */
static struct
{
int (*func)(const char *);
const char *arg;
int repeat;
} open_temp_exec_file_opts[] = {
{ open_temp_exec_file_env, "TMPDIR", 0 },
{ open_temp_exec_file_dir, "/tmp", 0 },
{ open_temp_exec_file_dir, "/var/tmp", 0 },
{ open_temp_exec_file_dir, "/dev/shm", 0 },
{ open_temp_exec_file_env, "HOME", 0 },
{ open_temp_exec_file_mnt, "/etc/mtab", 1 },
{ open_temp_exec_file_mnt, "/proc/mounts", 1 },
};
/* Current index into open_temp_exec_file_opts. */
static int open_temp_exec_file_opts_idx = 0;
/* Reset a current multi-call func, then advances to the next entry.
If we're at the last, go back to the first and return nonzero,
otherwise return zero. */
static int
open_temp_exec_file_opts_next (void)
{
if (open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func (NULL);
open_temp_exec_file_opts_idx++;
if (open_temp_exec_file_opts_idx
== (sizeof (open_temp_exec_file_opts)
/ sizeof (*open_temp_exec_file_opts)))
{
open_temp_exec_file_opts_idx = 0;
return 1;
}
return 0;
}
/* Return a file descriptor of a temporary zero-sized file in a
writable and exexutable filesystem. */
static int
open_temp_exec_file (void)
{
int fd;
do
{
fd = open_temp_exec_file_opts[open_temp_exec_file_opts_idx].func
(open_temp_exec_file_opts[open_temp_exec_file_opts_idx].arg);
if (!open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat
|| fd == -1)
{
if (open_temp_exec_file_opts_next ())
break;
}
}
while (fd == -1);
return fd;
}
/* Map in a chunk of memory from the temporary exec file into separate
locations in the virtual memory address space, one writable and one
executable. Returns the address of the writable portion, after
storing an offset to the corresponding executable portion at the
last word of the requested chunk. */
static void *
dlmmap_locked (void *start, size_t length, int prot, int flags, off_t offset)
{
void *ptr;
if (execfd == -1)
{
open_temp_exec_file_opts_idx = 0;
retry_open:
execfd = open_temp_exec_file ();
if (execfd == -1)
return MFAIL;
}
offset = execsize;
if (ftruncate (execfd, offset + length))
return MFAIL;
flags &= ~(MAP_PRIVATE | MAP_ANONYMOUS);
flags |= MAP_SHARED;
ptr = mmap (NULL, length, (prot & ~PROT_WRITE) | PROT_EXEC,
flags, execfd, offset);
if (ptr == MFAIL)
{
if (!offset)
{
close (execfd);
goto retry_open;
}
ftruncate (execfd, offset);
return MFAIL;
}
else if (!offset
&& open_temp_exec_file_opts[open_temp_exec_file_opts_idx].repeat)
open_temp_exec_file_opts_next ();
start = mmap (start, length, prot, flags, execfd, offset);
if (start == MFAIL)
{
munmap (ptr, length);
ftruncate (execfd, offset);
return start;
}
mmap_exec_offset ((char *)start, length) = (char*)ptr - (char*)start;
execsize += length;
return start;
}
/* Map in a writable and executable chunk of memory if possible.
Failing that, fall back to dlmmap_locked. */
static void *
dlmmap (void *start, size_t length, int prot,
int flags, int fd, off_t offset)
{
void *ptr;
assert (start == NULL && length % malloc_getpagesize == 0
&& prot == (PROT_READ | PROT_WRITE)
&& flags == (MAP_PRIVATE | MAP_ANONYMOUS)
&& fd == -1 && offset == 0);
#if FFI_CLOSURE_TEST
printf ("mapping in %zi\n", length);
#endif
if (execfd == -1 && !is_selinux_enabled ())
{
ptr = mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
if (ptr != MFAIL || (errno != EPERM && errno != EACCES))
/* Cool, no need to mess with separate segments. */
return ptr;
/* If MREMAP_DUP is ever introduced and implemented, try mmap
with ((prot & ~PROT_WRITE) | PROT_EXEC) and mremap with
MREMAP_DUP and prot at this point. */
}
if (execsize == 0 || execfd == -1)
{
pthread_mutex_lock (&open_temp_exec_file_mutex);
ptr = dlmmap_locked (start, length, prot, flags, offset);
pthread_mutex_unlock (&open_temp_exec_file_mutex);
return ptr;
}
return dlmmap_locked (start, length, prot, flags, offset);
}
/* Release memory at the given address, as well as the corresponding
executable page if it's separate. */
static int
dlmunmap (void *start, size_t length)
{
/* We don't bother decreasing execsize or truncating the file, since
we can't quite tell whether we're unmapping the end of the file.
We don't expect frequent deallocation anyway. If we did, we
could locate pages in the file by writing to the pages being
deallocated and checking that the file contents change.
Yuck. */
msegmentptr seg = segment_holding (gm, start);
void *code;
#if FFI_CLOSURE_TEST
printf ("unmapping %zi\n", length);
#endif
if (seg && (code = add_segment_exec_offset (start, seg)) != start)
{
int ret = munmap (code, length);
if (ret)
return ret;
}
return munmap (start, length);
}
#if FFI_CLOSURE_FREE_CODE
/* Return segment holding given code address. */
static msegmentptr
segment_holding_code (mstate m, char* addr)
{
msegmentptr sp = &m->seg;
for (;;) {
if (addr >= add_segment_exec_offset (sp->base, sp)
&& addr < add_segment_exec_offset (sp->base, sp) + sp->size)
return sp;
if ((sp = sp->next) == 0)
return 0;
}
}
#endif
/* Allocate a chunk of memory with the given size. Returns a pointer
to the writable address, and sets *CODE to the executable
corresponding virtual address. */
void *
ffi_closure_alloc (size_t size, void **code)
{
void *ptr;
if (!code)
return NULL;
ptr = dlmalloc (size);
if (ptr)
{
msegmentptr seg = segment_holding (gm, ptr);
*code = add_segment_exec_offset (ptr, seg);
}
return ptr;
}
/* Release a chunk of memory allocated with ffi_closure_alloc. If
FFI_CLOSURE_FREE_CODE is nonzero, the given address can be the
writable or the executable address given. Otherwise, only the
writable address can be provided here. */
void
ffi_closure_free (void *ptr)
{
#if FFI_CLOSURE_FREE_CODE
msegmentptr seg = segment_holding_code (gm, ptr);
if (seg)
ptr = sub_segment_exec_offset (ptr, seg);
#endif
dlfree (ptr);
}
#if FFI_CLOSURE_TEST
/* Do some internal sanity testing to make sure allocation and
deallocation of pages are working as intended. */
int main ()
{
void *p[3];
#define GET(idx, len) do { p[idx] = dlmalloc (len); printf ("allocated %zi for p[%i]\n", (len), (idx)); } while (0)
#define PUT(idx) do { printf ("freeing p[%i]\n", (idx)); dlfree (p[idx]); } while (0)
GET (0, malloc_getpagesize / 2);
GET (1, 2 * malloc_getpagesize - 64 * sizeof (void*));
PUT (1);
GET (1, 2 * malloc_getpagesize);
GET (2, malloc_getpagesize / 2);
PUT (1);
PUT (0);
PUT (2);
return 0;
}
#endif /* FFI_CLOSURE_TEST */
# else /* ! FFI_MMAP_EXEC_WRIT */
/* On many systems, memory returned by malloc is writable and
executable, so just use it. */
#include <stdlib.h>
void *
ffi_closure_alloc (size_t size, void **code)
{
if (!code)
return NULL;
return *code = malloc (size);
}
void
ffi_closure_free (void *ptr)
{
free (ptr);
}
# endif /* ! FFI_MMAP_EXEC_WRIT */
#endif /* FFI_CLOSURES */

View File

@@ -0,0 +1,383 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1998 Cygnus Solutions
Copyright (c) 2004 Simon Posnjak
Copyright (c) 2005 Axis Communications AB
Copyright (C) 2007 Free Software Foundation, Inc.
CRIS 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 SIMON POSNJAK 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>
#define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG)
static ffi_status
initialize_aggregate_packed_struct (ffi_type * arg)
{
ffi_type **ptr;
FFI_ASSERT (arg != NULL);
FFI_ASSERT (arg->elements != NULL);
FFI_ASSERT (arg->size == 0);
FFI_ASSERT (arg->alignment == 0);
ptr = &(arg->elements[0]);
while ((*ptr) != NULL)
{
if (((*ptr)->size == 0)
&& (initialize_aggregate_packed_struct ((*ptr)) != FFI_OK))
return FFI_BAD_TYPEDEF;
FFI_ASSERT (ffi_type_test ((*ptr)));
arg->size += (*ptr)->size;
arg->alignment = (arg->alignment > (*ptr)->alignment) ?
arg->alignment : (*ptr)->alignment;
ptr++;
}
if (arg->size == 0)
return FFI_BAD_TYPEDEF;
else
return FFI_OK;
}
int
ffi_prep_args (char *stack, extended_cif * ecif)
{
unsigned int i;
unsigned int struct_count = 0;
void **p_argv;
char *argp;
ffi_type **p_arg;
argp = stack;
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0); i--, p_arg++)
{
size_t z;
switch ((*p_arg)->type)
{
case FFI_TYPE_STRUCT:
{
z = (*p_arg)->size;
if (z <= 4)
{
memcpy (argp, *p_argv, z);
z = 4;
}
else if (z <= 8)
{
memcpy (argp, *p_argv, z);
z = 8;
}
else
{
unsigned int uiLocOnStack;
z = sizeof (void *);
uiLocOnStack = 4 * ecif->cif->nargs + struct_count;
struct_count = struct_count + (*p_arg)->size;
*(unsigned int *) argp =
(unsigned int) (UINT32 *) (stack + uiLocOnStack);
memcpy ((stack + uiLocOnStack), *p_argv, (*p_arg)->size);
}
break;
}
default:
z = (*p_arg)->size;
if (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;
default:
FFI_ASSERT (0);
}
z = sizeof (int);
}
else if (z == sizeof (int))
*(unsigned int *) argp = (unsigned int) *(UINT32 *) (*p_argv);
else
memcpy (argp, *p_argv, z);
break;
}
p_argv++;
argp += z;
}
return (struct_count);
}
ffi_status
ffi_prep_cif (ffi_cif * cif,
ffi_abi abi, unsigned int nargs,
ffi_type * rtype, ffi_type ** atypes)
{
unsigned bytes = 0;
unsigned int i;
ffi_type **ptr;
FFI_ASSERT (cif != NULL);
FFI_ASSERT ((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
cif->abi = abi;
cif->arg_types = atypes;
cif->nargs = nargs;
cif->rtype = rtype;
cif->flags = 0;
if ((cif->rtype->size == 0)
&& (initialize_aggregate_packed_struct (cif->rtype) != FFI_OK))
return FFI_BAD_TYPEDEF;
FFI_ASSERT_VALID_TYPE (cif->rtype);
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
if (((*ptr)->size == 0)
&& (initialize_aggregate_packed_struct ((*ptr)) != FFI_OK))
return FFI_BAD_TYPEDEF;
FFI_ASSERT_VALID_TYPE (*ptr);
if (((*ptr)->alignment - 1) & bytes)
bytes = ALIGN (bytes, (*ptr)->alignment);
if ((*ptr)->type == FFI_TYPE_STRUCT)
{
if ((*ptr)->size > 8)
{
bytes += (*ptr)->size;
bytes += sizeof (void *);
}
else
{
if ((*ptr)->size > 4)
bytes += 8;
else
bytes += 4;
}
}
else
bytes += STACK_ARG_SIZE ((*ptr)->size);
}
cif->bytes = bytes;
return ffi_prep_cif_machdep (cif);
}
ffi_status
ffi_prep_cif_machdep (ffi_cif * cif)
{
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
case FFI_TYPE_STRUCT:
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
cif->flags = (unsigned) cif->rtype->type;
break;
default:
cif->flags = FFI_TYPE_INT;
break;
}
return FFI_OK;
}
extern void ffi_call_SYSV (int (*)(char *, extended_cif *),
extended_cif *,
unsigned, unsigned, unsigned *, void (*fn) ())
__attribute__ ((__visibility__ ("hidden")));
void
ffi_call (ffi_cif * cif, void (*fn) (), void *rvalue, void **avalue)
{
extended_cif ecif;
ecif.cif = cif;
ecif.avalue = avalue;
if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT))
{
ecif.rvalue = alloca (cif->rtype->size);
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_SYSV:
ffi_call_SYSV (ffi_prep_args, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
break;
default:
FFI_ASSERT (0);
break;
}
}
/* Because the following variables are not exported outside libffi, we
mark them hidden. */
/* Assembly code for the jump stub. */
extern const char ffi_cris_trampoline_template[]
__attribute__ ((__visibility__ ("hidden")));
/* Offset into ffi_cris_trampoline_template of where to put the
ffi_prep_closure_inner function. */
extern const int ffi_cris_trampoline_fn_offset
__attribute__ ((__visibility__ ("hidden")));
/* Offset into ffi_cris_trampoline_template of where to put the
closure data. */
extern const int ffi_cris_trampoline_closure_offset
__attribute__ ((__visibility__ ("hidden")));
/* This function is sibling-called (jumped to) by the closure
trampoline. We get R10..R13 at PARAMS[0..3] and a copy of [SP] at
PARAMS[4] to simplify handling of a straddling parameter. A copy
of R9 is at PARAMS[5] and SP at PARAMS[6]. These parameters are
put at the appropriate place in CLOSURE which is then executed and
the return value is passed back to the caller. */
static unsigned long long
ffi_prep_closure_inner (void **params, ffi_closure* closure)
{
char *register_args = (char *) params;
void *struct_ret = params[5];
char *stack_args = params[6];
char *ptr = register_args;
ffi_cif *cif = closure->cif;
ffi_type **arg_types = cif->arg_types;
/* Max room needed is number of arguments as 64-bit values. */
void **avalue = alloca (closure->cif->nargs * sizeof(void *));
int i;
int doing_regs;
long long llret = 0;
/* Find the address of each argument. */
for (i = 0, doing_regs = 1; i < cif->nargs; i++)
{
/* Types up to and including 8 bytes go by-value. */
if (arg_types[i]->size <= 4)
{
avalue[i] = ptr;
ptr += 4;
}
else if (arg_types[i]->size <= 8)
{
avalue[i] = ptr;
ptr += 8;
}
else
{
FFI_ASSERT (arg_types[i]->type == FFI_TYPE_STRUCT);
/* Passed by-reference, so copy the pointer. */
avalue[i] = *(void **) ptr;
ptr += 4;
}
/* If we've handled more arguments than fit in registers, start
looking at the those passed on the stack. Step over the
first one if we had a straddling parameter. */
if (doing_regs && ptr >= register_args + 4*4)
{
ptr = stack_args + ((ptr > register_args + 4*4) ? 4 : 0);
doing_regs = 0;
}
}
/* Invoke the closure. */
(closure->fun) (cif,
cif->rtype->type == FFI_TYPE_STRUCT
/* The caller allocated space for the return
structure, and passed a pointer to this space in
R9. */
? struct_ret
/* We take advantage of being able to ignore that
the high part isn't set if the return value is
not in R10:R11, but in R10 only. */
: (void *) &llret,
avalue, closure->user_data);
return llret;
}
/* API function: Prepare the trampoline. */
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif *, void *, void **, void*),
void *user_data,
void *codeloc)
{
void *innerfn = ffi_prep_closure_inner;
FFI_ASSERT (cif->abi == FFI_SYSV);
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
memcpy (closure->tramp, ffi_cris_trampoline_template,
FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE);
memcpy (closure->tramp + ffi_cris_trampoline_fn_offset,
&innerfn, sizeof (void *));
memcpy (closure->tramp + ffi_cris_trampoline_closure_offset,
&codeloc, sizeof (void *));
return FFI_OK;
}

View File

@@ -0,0 +1,51 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for CRIS.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_SYSV,
FFI_DEFAULT_ABI = FFI_SYSV,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE 36
#define FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE (7*4)
#define FFI_TRAMPOLINE_SIZE \
(FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE + FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE)
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,215 @@
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 2004 Simon Posnjak
Copyright (c) 2005 Axis Communications AB
CRIS 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 SIMON POSNJAK 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>
#define CONCAT(x,y) x ## y
#define XCONCAT(x,y) CONCAT (x, y)
#define L(x) XCONCAT (__USER_LABEL_PREFIX__, x)
.text
;; OK, when we get called we should have this (according to
;; AXIS ETRAX 100LX Programmer's Manual chapter 6.3).
;;
;; R10: ffi_prep_args (func. pointer)
;; R11: &ecif
;; R12: cif->bytes
;; R13: fig->flags
;; sp+0: ecif.rvalue
;; sp+4: fn (function pointer to the function that we need to call)
.globl L(ffi_call_SYSV)
.type L(ffi_call_SYSV),@function
.hidden L(ffi_call_SYSV)
L(ffi_call_SYSV):
;; Save the regs to the stack.
push $srp
;; Used for stack pointer saving.
push $r6
;; Used for function address pointer.
push $r7
;; Used for stack pointer saving.
push $r8
;; We save fig->flags to stack we will need them after we
;; call The Function.
push $r13
;; Saving current stack pointer.
move.d $sp,$r8
move.d $sp,$r6
;; Move address of ffi_prep_args to r13.
move.d $r10,$r13
;; Make room on the stack for the args of fn.
sub.d $r12,$sp
;; Function void ffi_prep_args(char *stack, extended_cif *ecif) parameters are:
;; r10 <-- stack pointer
;; r11 <-- &ecif (already there)
move.d $sp,$r10
;; Call the function.
jsr $r13
;; Save the size of the structures which are passed on stack.
move.d $r10,$r7
;; Move first four args in to r10..r13.
move.d [$sp+0],$r10
move.d [$sp+4],$r11
move.d [$sp+8],$r12
move.d [$sp+12],$r13
;; Adjust the stack and check if any parameters are given on stack.
addq 16,$sp
sub.d $r7,$r6
cmp.d $sp,$r6
bpl go_on
nop
go_on_no_params_on_stack:
move.d $r6,$sp
go_on:
;; Discover if we need to put rval address in to r9.
move.d [$r8+0],$r7
cmpq FFI_TYPE_STRUCT,$r7
bne call_now
nop
;; Move rval address to $r9.
move.d [$r8+20],$r9
call_now:
;; Move address of The Function in to r7.
move.d [$r8+24],$r7
;; Call The Function.
jsr $r7
;; Reset stack.
move.d $r8,$sp
;; Load rval type (fig->flags) in to r13.
pop $r13
;; Detect rval type.
cmpq FFI_TYPE_VOID,$r13
beq epilogue
cmpq FFI_TYPE_STRUCT,$r13
beq epilogue
cmpq FFI_TYPE_DOUBLE,$r13
beq return_double_or_longlong
cmpq FFI_TYPE_UINT64,$r13
beq return_double_or_longlong
cmpq FFI_TYPE_SINT64,$r13
beq return_double_or_longlong
nop
;; Just return the 32 bit value.
ba return
nop
return_double_or_longlong:
;; Load half of the rval to r10 and the other half to r11.
move.d [$sp+16],$r13
move.d $r10,[$r13]
addq 4,$r13
move.d $r11,[$r13]
ba epilogue
nop
return:
;; Load the rval to r10.
move.d [$sp+16],$r13
move.d $r10,[$r13]
epilogue:
pop $r8
pop $r7
pop $r6
Jump [$sp+]
.size ffi_call_SYSV,.-ffi_call_SYSV
/* Save R10..R13 into an array, somewhat like varargs. Copy the next
argument too, to simplify handling of any straddling parameter.
Save R9 and SP after those. Jump to function handling the rest.
Since this is a template, copied and the main function filled in by
the user. */
.globl L(ffi_cris_trampoline_template)
.type L(ffi_cris_trampoline_template),@function
.hidden L(ffi_cris_trampoline_template)
L(ffi_cris_trampoline_template):
0:
/* The value we get for "PC" is right after the prefix instruction,
two bytes from the beginning, i.e. 0b+2. */
move.d $r10,[$pc+2f-(0b+2)]
move.d $pc,$r10
1:
addq 2f-1b+4,$r10
move.d $r11,[$r10+]
move.d $r12,[$r10+]
move.d $r13,[$r10+]
move.d [$sp],$r11
move.d $r11,[$r10+]
move.d $r9,[$r10+]
move.d $sp,[$r10+]
subq FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE,$r10
move.d 0,$r11
3:
jump 0
2:
.size ffi_cris_trampoline_template,.-0b
/* This macro create a constant usable as "extern const int \name" in
C from within libffi, when \name has no prefix decoration. */
.macro const name,value
.globl \name
.type \name,@object
.hidden \name
\name:
.dword \value
.size \name,4
.endm
/* Constants for offsets within the trampoline. We could do this with
just symbols, avoiding memory contents and memory accesses, but the
C usage code would look a bit stranger. */
const L(ffi_cris_trampoline_fn_offset),2b-4-0b
const L(ffi_cris_trampoline_closure_offset),3b-4-0b

View File

@@ -0,0 +1,59 @@
/* -----------------------------------------------------------------------
debug.c - Copyright (c) 1996 Red Hat, Inc.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
#include <stdio.h>
/* General debugging routines */
void ffi_stop_here(void)
{
/* This function is only useful for debugging purposes.
Place a breakpoint on ffi_stop_here to be notified of
significant events. */
}
/* This function should only be called via the FFI_ASSERT() macro */
void ffi_assert(char *expr, char *file, int line)
{
fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
ffi_stop_here();
abort();
}
/* Perform a sanity check on an ffi_type structure */
void ffi_type_test(ffi_type *a, char *file, int line)
{
FFI_ASSERT_AT(a != NULL, file, line);
FFI_ASSERT_AT(a->type <= FFI_TYPE_LAST, file, line);
FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->size > 0, file, line);
FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->alignment > 0, file, line);
FFI_ASSERT_AT(a->type != FFI_TYPE_STRUCT || a->elements != NULL, file, line);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,128 @@
/* -----------------------------------------------------------------------
eabi.S - Copyright (c) 2004 Anthony Green
FR-V Assembly glue.
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 THE AUTHOR 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 <fficonfig.h>
#include <ffi.h>
.globl ffi_prep_args_EABI
.text
.p2align 4
.globl ffi_call_EABI
.type ffi_call_EABI, @function
# gr8 : ffi_prep_args
# gr9 : &ecif
# gr10: cif->bytes
# gr11: fig->flags
# gr12: ecif.rvalue
# gr13: fn
ffi_call_EABI:
addi sp, #-80, sp
sti fp, @(sp, #24)
addi sp, #24, fp
movsg lr, gr5
/* Make room for the new arguments. */
/* subi sp, fp, gr10 */
/* Store return address and incoming args on stack. */
sti gr5, @(fp, #8)
sti gr8, @(fp, #-4)
sti gr9, @(fp, #-8)
sti gr10, @(fp, #-12)
sti gr11, @(fp, #-16)
sti gr12, @(fp, #-20)
sti gr13, @(fp, #-24)
sub sp, gr10, sp
/* Call ffi_prep_args. */
ldi @(fp, #-4), gr4
addi sp, #0, gr8
ldi @(fp, #-8), gr9
#ifdef __FRV_FDPIC__
ldd @(gr4, gr0), gr14
calll @(gr14, gr0)
#else
calll @(gr4, gr0)
#endif
/* ffi_prep_args returns the new stack pointer. */
mov gr8, gr4
ldi @(sp, #0), gr8
ldi @(sp, #4), gr9
ldi @(sp, #8), gr10
ldi @(sp, #12), gr11
ldi @(sp, #16), gr12
ldi @(sp, #20), gr13
/* Always copy the return value pointer into the hidden
parameter register. This is only strictly necessary
when we're returning an aggregate type, but it doesn't
hurt to do this all the time, and it saves a branch. */
ldi @(fp, #-20), gr3
/* Use the ffi_prep_args return value for the new sp. */
mov gr4, sp
/* Call the target function. */
ldi @(fp, -24), gr4
#ifdef __FRV_FDPIC__
ldd @(gr4, gr0), gr14
calll @(gr14, gr0)
#else
calll @(gr4, gr0)
#endif
/* Store the result. */
ldi @(fp, #-16), gr10 /* fig->flags */
ldi @(fp, #-20), gr4 /* ecif.rvalue */
/* Is the return value stored in two registers? */
cmpi gr10, #8, icc0
bne icc0, 0, .L2
/* Yes, save them. */
sti gr8, @(gr4, #0)
sti gr9, @(gr4, #4)
bra .L3
.L2:
/* Is the return value a structure? */
cmpi gr10, #-1, icc0
beq icc0, 0, .L3
/* No, save a 4 byte return value. */
sti gr8, @(gr4, #0)
.L3:
/* Restore the stack, and return. */
ldi @(fp, 8), gr5
ld @(fp, gr0), fp
addi sp,#80,sp
jmpl @(gr5,gr0)
.size ffi_call_EABI, .-ffi_call_EABI

View File

@@ -0,0 +1,292 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (C) 2004 Anthony Green
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright (C) 2008 Red Hat, Inc.
FR-V 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments */
void *ffi_prep_args(char *stack, extended_cif *ecif)
{
register unsigned int i;
register void **p_argv;
register char *argp;
register ffi_type **p_arg;
register int count = 0;
p_argv = ecif->avalue;
argp = stack;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0);
i--, p_arg++)
{
size_t z;
z = (*p_arg)->size;
if ((*p_arg)->type == FFI_TYPE_STRUCT)
{
z = sizeof(void*);
*(void **) argp = *p_argv;
}
/* if ((*p_arg)->type == FFI_TYPE_FLOAT)
{
if (count > 24)
{
// This is going on the stack. Turn it into a double.
*(double *) argp = (double) *(float*)(* p_argv);
z = sizeof(double);
}
else
*(void **) argp = *(void **)(* p_argv);
} */
else if (z < sizeof(int))
{
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;
default:
FFI_ASSERT(0);
}
}
else if (z == sizeof(int))
{
*(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
}
else
{
memcpy(argp, *p_argv, z);
}
p_argv++;
argp += z;
count += z;
}
return (stack + ((count > 24) ? 24 : ALIGN_DOWN(count, 8)));
}
/* Perform machine dependent cif processing */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
if (cif->rtype->type == FFI_TYPE_STRUCT)
cif->flags = -1;
else
cif->flags = cif->rtype->size;
cif->bytes = ALIGN (cif->bytes, 8);
return FFI_OK;
}
extern void ffi_call_EABI(void *(*)(char *, extended_cif *),
extended_cif *,
unsigned, unsigned,
unsigned *,
void (*fn)(void));
void ffi_call(ffi_cif *cif,
void (*fn)(void),
void *rvalue,
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))
{
ecif.rvalue = alloca(cif->rtype->size);
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_EABI:
ffi_call_EABI(ffi_prep_args, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
break;
default:
FFI_ASSERT(0);
break;
}
}
void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3,
unsigned arg4, unsigned arg5, unsigned arg6)
{
/* This function is called by a trampoline. The trampoline stows a
pointer to the ffi_closure object in gr7. We must save this
pointer in a place that will persist while we do our work. */
register ffi_closure *creg __asm__ ("gr7");
ffi_closure *closure = creg;
/* Arguments that don't fit in registers are found on the stack
at a fixed offset above the current frame pointer. */
register char *frame_pointer __asm__ ("fp");
char *stack_args = frame_pointer + 16;
/* Lay the register arguments down in a continuous chunk of memory. */
unsigned register_args[6] =
{ arg1, arg2, arg3, arg4, arg5, arg6 };
ffi_cif *cif = closure->cif;
ffi_type **arg_types = cif->arg_types;
void **avalue = alloca (cif->nargs * sizeof(void *));
char *ptr = (char *) register_args;
int i;
/* Find the address of each argument. */
for (i = 0; i < cif->nargs; i++)
{
switch (arg_types[i]->type)
{
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
avalue[i] = ptr + 3;
break;
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
avalue[i] = ptr + 2;
break;
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
case FFI_TYPE_FLOAT:
avalue[i] = ptr;
break;
case FFI_TYPE_STRUCT:
avalue[i] = *(void**)ptr;
break;
default:
/* This is an 8-byte value. */
avalue[i] = ptr;
ptr += 4;
break;
}
ptr += 4;
/* If we've handled more arguments than fit in registers,
start looking at the those passed on the stack. */
if (ptr == ((char *)register_args + (6*4)))
ptr = stack_args;
}
/* Invoke the closure. */
if (cif->rtype->type == FFI_TYPE_STRUCT)
{
/* The caller allocates space for the return structure, and
passes a pointer to this space in gr3. Use this value directly
as the return value. */
register void *return_struct_ptr __asm__("gr3");
(closure->fun) (cif, return_struct_ptr, avalue, closure->user_data);
}
else
{
/* Allocate space for the return value and call the function. */
long long rvalue;
(closure->fun) (cif, &rvalue, avalue, closure->user_data);
/* Functions return 4-byte or smaller results in gr8. 8-byte
values also use gr9. We fill the both, even for small return
values, just to avoid a branch. */
asm ("ldi @(%0, #0), gr8" : : "r" (&rvalue));
asm ("ldi @(%0, #0), gr9" : : "r" (&((int *) &rvalue)[1]));
}
}
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*, void*, void**, void*),
void *user_data,
void *codeloc)
{
unsigned int *tramp = (unsigned int *) &closure->tramp[0];
unsigned long fn = (long) ffi_closure_eabi;
unsigned long cls = (long) codeloc;
#ifdef __FRV_FDPIC__
register void *got __asm__("gr15");
#endif
int i;
fn = (unsigned long) ffi_closure_eabi;
#ifdef __FRV_FDPIC__
tramp[0] = &((unsigned int *)codeloc)[2];
tramp[1] = got;
tramp[2] = 0x8cfc0000 + (fn & 0xffff); /* setlos lo(fn), gr6 */
tramp[3] = 0x8efc0000 + (cls & 0xffff); /* setlos lo(cls), gr7 */
tramp[4] = 0x8cf80000 + (fn >> 16); /* sethi hi(fn), gr6 */
tramp[5] = 0x8ef80000 + (cls >> 16); /* sethi hi(cls), gr7 */
tramp[6] = 0x9cc86000; /* ldi @(gr6, #0), gr14 */
tramp[7] = 0x8030e000; /* jmpl @(gr14, gr0) */
#else
tramp[0] = 0x8cfc0000 + (fn & 0xffff); /* setlos lo(fn), gr6 */
tramp[1] = 0x8efc0000 + (cls & 0xffff); /* setlos lo(cls), gr7 */
tramp[2] = 0x8cf80000 + (fn >> 16); /* sethi hi(fn), gr6 */
tramp[3] = 0x8ef80000 + (cls >> 16); /* sethi hi(cls), gr7 */
tramp[4] = 0x80300006; /* jmpl @(gr0, gr6) */
#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
/* Cache flushing. */
for (i = 0; i < FFI_TRAMPOLINE_SIZE; i++)
__asm__ volatile ("dcf @(%0,%1)\n\tici @(%2,%1)" :: "r" (tramp), "r" (i),
"r" (codeloc));
return FFI_OK;
}

View File

@@ -0,0 +1,61 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2004 Red Hat, Inc.
Target configuration macros for FR-V
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
/* ---- System specific configurations ----------------------------------- */
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
#ifdef FRV
FFI_EABI,
FFI_DEFAULT_ABI = FFI_EABI,
#endif
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_NATIVE_RAW_API 0
#ifdef __FRV_FDPIC__
/* Trampolines are 8 4-byte instructions long. */
#define FFI_TRAMPOLINE_SIZE (8*4)
#else
/* Trampolines are 5 4-byte instructions long. */
#define FFI_TRAMPOLINE_SIZE (5*4)
#endif
#endif

View File

@@ -0,0 +1,580 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1998, 2007, 2008 Red Hat, Inc.
Copyright (c) 2000 Hewlett Packard Company
IA64 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
#include <stdbool.h>
#include <float.h>
#include "ia64_flags.h"
/* A 64-bit pointer value. In LP64 mode, this is effectively a plain
pointer. In ILP32 mode, it's a pointer that's been extended to
64 bits by "addp4". */
typedef void *PTR64 __attribute__((mode(DI)));
/* Memory image of fp register contents. This is the implementation
specific format used by ldf.fill/stf.spill. All we care about is
that it wants a 16 byte aligned slot. */
typedef struct
{
UINT64 x[2] __attribute__((aligned(16)));
} fpreg;
/* The stack layout given to ffi_call_unix and ffi_closure_unix_inner. */
struct ia64_args
{
fpreg fp_regs[8]; /* Contents of 8 fp arg registers. */
UINT64 gp_regs[8]; /* Contents of 8 gp arg registers. */
UINT64 other_args[]; /* Arguments passed on stack, variable size. */
};
/* Adjust ADDR, a pointer to an 8 byte slot, to point to the low LEN bytes. */
static inline void *
endian_adjust (void *addr, size_t len)
{
#ifdef __BIG_ENDIAN__
return addr + (8 - len);
#else
return addr;
#endif
}
/* Store VALUE to ADDR in the current cpu implementation's fp spill format.
This is a macro instead of a function, so that it works for all 3 floating
point types without type conversions. Type conversion to long double breaks
the denorm support. */
#define stf_spill(addr, value) \
asm ("stf.spill %0 = %1%P0" : "=m" (*addr) : "f"(value));
/* Load a value from ADDR, which is in the current cpu implementation's
fp spill format. As above, this must also be a macro. */
#define ldf_fill(result, addr) \
asm ("ldf.fill %0 = %1%P1" : "=f"(result) : "m"(*addr));
/* Return the size of the C type associated with with TYPE. Which will
be one of the FFI_IA64_TYPE_HFA_* values. */
static size_t
hfa_type_size (int type)
{
switch (type)
{
case FFI_IA64_TYPE_HFA_FLOAT:
return sizeof(float);
case FFI_IA64_TYPE_HFA_DOUBLE:
return sizeof(double);
case FFI_IA64_TYPE_HFA_LDOUBLE:
return sizeof(__float80);
default:
abort ();
}
}
/* Load from ADDR a value indicated by TYPE. Which will be one of
the FFI_IA64_TYPE_HFA_* values. */
static void
hfa_type_load (fpreg *fpaddr, int type, void *addr)
{
switch (type)
{
case FFI_IA64_TYPE_HFA_FLOAT:
stf_spill (fpaddr, *(float *) addr);
return;
case FFI_IA64_TYPE_HFA_DOUBLE:
stf_spill (fpaddr, *(double *) addr);
return;
case FFI_IA64_TYPE_HFA_LDOUBLE:
stf_spill (fpaddr, *(__float80 *) addr);
return;
default:
abort ();
}
}
/* Load VALUE into ADDR as indicated by TYPE. Which will be one of
the FFI_IA64_TYPE_HFA_* values. */
static void
hfa_type_store (int type, void *addr, fpreg *fpaddr)
{
switch (type)
{
case FFI_IA64_TYPE_HFA_FLOAT:
{
float result;
ldf_fill (result, fpaddr);
*(float *) addr = result;
break;
}
case FFI_IA64_TYPE_HFA_DOUBLE:
{
double result;
ldf_fill (result, fpaddr);
*(double *) addr = result;
break;
}
case FFI_IA64_TYPE_HFA_LDOUBLE:
{
__float80 result;
ldf_fill (result, fpaddr);
*(__float80 *) addr = result;
break;
}
default:
abort ();
}
}
/* Is TYPE a struct containing floats, doubles, or extended doubles,
all of the same fp type? If so, return the element type. Return
FFI_TYPE_VOID if not. */
static int
hfa_element_type (ffi_type *type, int nested)
{
int element = FFI_TYPE_VOID;
switch (type->type)
{
case FFI_TYPE_FLOAT:
/* We want to return VOID for raw floating-point types, but the
synthetic HFA type if we're nested within an aggregate. */
if (nested)
element = FFI_IA64_TYPE_HFA_FLOAT;
break;
case FFI_TYPE_DOUBLE:
/* Similarly. */
if (nested)
element = FFI_IA64_TYPE_HFA_DOUBLE;
break;
case FFI_TYPE_LONGDOUBLE:
/* Similarly, except that that HFA is true for double extended,
but not quad precision. Both have sizeof == 16, so tell the
difference based on the precision. */
if (LDBL_MANT_DIG == 64 && nested)
element = FFI_IA64_TYPE_HFA_LDOUBLE;
break;
case FFI_TYPE_STRUCT:
{
ffi_type **ptr = &type->elements[0];
for (ptr = &type->elements[0]; *ptr ; ptr++)
{
int sub_element = hfa_element_type (*ptr, 1);
if (sub_element == FFI_TYPE_VOID)
return FFI_TYPE_VOID;
if (element == FFI_TYPE_VOID)
element = sub_element;
else if (element != sub_element)
return FFI_TYPE_VOID;
}
}
break;
default:
return FFI_TYPE_VOID;
}
return element;
}
/* Perform machine dependent cif processing. */
ffi_status
ffi_prep_cif_machdep(ffi_cif *cif)
{
int flags;
/* Adjust cif->bytes to include space for the bits of the ia64_args frame
that preceeds the integer register portion. The estimate that the
generic bits did for the argument space required is good enough for the
integer component. */
cif->bytes += offsetof(struct ia64_args, gp_regs[0]);
if (cif->bytes < sizeof(struct ia64_args))
cif->bytes = sizeof(struct ia64_args);
/* Set the return type flag. */
flags = cif->rtype->type;
switch (cif->rtype->type)
{
case FFI_TYPE_LONGDOUBLE:
/* Leave FFI_TYPE_LONGDOUBLE as meaning double extended precision,
and encode quad precision as a two-word integer structure. */
if (LDBL_MANT_DIG != 64)
flags = FFI_IA64_TYPE_SMALL_STRUCT | (16 << 8);
break;
case FFI_TYPE_STRUCT:
{
size_t size = cif->rtype->size;
int hfa_type = hfa_element_type (cif->rtype, 0);
if (hfa_type != FFI_TYPE_VOID)
{
size_t nelts = size / hfa_type_size (hfa_type);
if (nelts <= 8)
flags = hfa_type | (size << 8);
}
else
{
if (size <= 32)
flags = FFI_IA64_TYPE_SMALL_STRUCT | (size << 8);
}
}
break;
default:
break;
}
cif->flags = flags;
return FFI_OK;
}
extern int ffi_call_unix (struct ia64_args *, PTR64, void (*)(void), UINT64);
void
ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
struct ia64_args *stack;
long i, avn, gpcount, fpcount;
ffi_type **p_arg;
FFI_ASSERT (cif->abi == FFI_UNIX);
/* If we have no spot for a return value, make one. */
if (rvalue == NULL && cif->rtype->type != FFI_TYPE_VOID)
rvalue = alloca (cif->rtype->size);
/* Allocate the stack frame. */
stack = alloca (cif->bytes);
gpcount = fpcount = 0;
avn = cif->nargs;
for (i = 0, p_arg = cif->arg_types; i < avn; i++, p_arg++)
{
switch ((*p_arg)->type)
{
case FFI_TYPE_SINT8:
stack->gp_regs[gpcount++] = *(SINT8 *)avalue[i];
break;
case FFI_TYPE_UINT8:
stack->gp_regs[gpcount++] = *(UINT8 *)avalue[i];
break;
case FFI_TYPE_SINT16:
stack->gp_regs[gpcount++] = *(SINT16 *)avalue[i];
break;
case FFI_TYPE_UINT16:
stack->gp_regs[gpcount++] = *(UINT16 *)avalue[i];
break;
case FFI_TYPE_SINT32:
stack->gp_regs[gpcount++] = *(SINT32 *)avalue[i];
break;
case FFI_TYPE_UINT32:
stack->gp_regs[gpcount++] = *(UINT32 *)avalue[i];
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
stack->gp_regs[gpcount++] = *(UINT64 *)avalue[i];
break;
case FFI_TYPE_POINTER:
stack->gp_regs[gpcount++] = (UINT64)(PTR64) *(void **)avalue[i];
break;
case FFI_TYPE_FLOAT:
if (gpcount < 8 && fpcount < 8)
stf_spill (&stack->fp_regs[fpcount++], *(float *)avalue[i]);
stack->gp_regs[gpcount++] = *(UINT32 *)avalue[i];
break;
case FFI_TYPE_DOUBLE:
if (gpcount < 8 && fpcount < 8)
stf_spill (&stack->fp_regs[fpcount++], *(double *)avalue[i]);
stack->gp_regs[gpcount++] = *(UINT64 *)avalue[i];
break;
case FFI_TYPE_LONGDOUBLE:
if (gpcount & 1)
gpcount++;
if (LDBL_MANT_DIG == 64 && gpcount < 8 && fpcount < 8)
stf_spill (&stack->fp_regs[fpcount++], *(__float80 *)avalue[i]);
memcpy (&stack->gp_regs[gpcount], avalue[i], 16);
gpcount += 2;
break;
case FFI_TYPE_STRUCT:
{
size_t size = (*p_arg)->size;
size_t align = (*p_arg)->alignment;
int hfa_type = hfa_element_type (*p_arg, 0);
FFI_ASSERT (align <= 16);
if (align == 16 && (gpcount & 1))
gpcount++;
if (hfa_type != FFI_TYPE_VOID)
{
size_t hfa_size = hfa_type_size (hfa_type);
size_t offset = 0;
size_t gp_offset = gpcount * 8;
while (fpcount < 8
&& offset < size
&& gp_offset < 8 * 8)
{
hfa_type_load (&stack->fp_regs[fpcount], hfa_type,
avalue[i] + offset);
offset += hfa_size;
gp_offset += hfa_size;
fpcount += 1;
}
}
memcpy (&stack->gp_regs[gpcount], avalue[i], size);
gpcount += (size + 7) / 8;
}
break;
default:
abort ();
}
}
ffi_call_unix (stack, rvalue, fn, cif->flags);
}
/* Closures represent a pair consisting of a function pointer, and
some user data. A closure is invoked by reinterpreting the closure
as a function pointer, and branching to it. Thus we can make an
interpreted function callable as a C function: We turn the
interpreter itself, together with a pointer specifying the
interpreted procedure, into a closure.
For IA64, function pointer are already pairs consisting of a code
pointer, and a gp pointer. The latter is needed to access global
variables. Here we set up such a pair as the first two words of
the closure (in the "trampoline" area), but we replace the gp
pointer with a pointer to the closure itself. We also add the real
gp pointer to the closure. This allows the function entry code to
both retrieve the user data, and to restire the correct gp pointer. */
extern void ffi_closure_unix ();
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void *codeloc)
{
/* The layout of a function descriptor. A C function pointer really
points to one of these. */
struct ia64_fd
{
UINT64 code_pointer;
UINT64 gp;
};
struct ffi_ia64_trampoline_struct
{
UINT64 code_pointer; /* Pointer to ffi_closure_unix. */
UINT64 fake_gp; /* Pointer to closure, installed as gp. */
UINT64 real_gp; /* Real gp value. */
};
struct ffi_ia64_trampoline_struct *tramp;
struct ia64_fd *fd;
FFI_ASSERT (cif->abi == FFI_UNIX);
tramp = (struct ffi_ia64_trampoline_struct *)closure->tramp;
fd = (struct ia64_fd *)(void *)ffi_closure_unix;
tramp->code_pointer = fd->code_pointer;
tramp->real_gp = fd->gp;
tramp->fake_gp = (UINT64)(PTR64)codeloc;
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
return FFI_OK;
}
UINT64
ffi_closure_unix_inner (ffi_closure *closure, struct ia64_args *stack,
void *rvalue, void *r8)
{
ffi_cif *cif;
void **avalue;
ffi_type **p_arg;
long i, avn, gpcount, fpcount;
cif = closure->cif;
avn = cif->nargs;
avalue = alloca (avn * sizeof (void *));
/* If the structure return value is passed in memory get that location
from r8 so as to pass the value directly back to the caller. */
if (cif->flags == FFI_TYPE_STRUCT)
rvalue = r8;
gpcount = fpcount = 0;
for (i = 0, p_arg = cif->arg_types; i < avn; i++, p_arg++)
{
switch ((*p_arg)->type)
{
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
avalue[i] = endian_adjust(&stack->gp_regs[gpcount++], 1);
break;
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
avalue[i] = endian_adjust(&stack->gp_regs[gpcount++], 2);
break;
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
avalue[i] = endian_adjust(&stack->gp_regs[gpcount++], 4);
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
avalue[i] = &stack->gp_regs[gpcount++];
break;
case FFI_TYPE_POINTER:
avalue[i] = endian_adjust(&stack->gp_regs[gpcount++], sizeof(void*));
break;
case FFI_TYPE_FLOAT:
if (gpcount < 8 && fpcount < 8)
{
fpreg *addr = &stack->fp_regs[fpcount++];
float result;
avalue[i] = addr;
ldf_fill (result, addr);
*(float *)addr = result;
}
else
avalue[i] = endian_adjust(&stack->gp_regs[gpcount], 4);
gpcount++;
break;
case FFI_TYPE_DOUBLE:
if (gpcount < 8 && fpcount < 8)
{
fpreg *addr = &stack->fp_regs[fpcount++];
double result;
avalue[i] = addr;
ldf_fill (result, addr);
*(double *)addr = result;
}
else
avalue[i] = &stack->gp_regs[gpcount];
gpcount++;
break;
case FFI_TYPE_LONGDOUBLE:
if (gpcount & 1)
gpcount++;
if (LDBL_MANT_DIG == 64 && gpcount < 8 && fpcount < 8)
{
fpreg *addr = &stack->fp_regs[fpcount++];
__float80 result;
avalue[i] = addr;
ldf_fill (result, addr);
*(__float80 *)addr = result;
}
else
avalue[i] = &stack->gp_regs[gpcount];
gpcount += 2;
break;
case FFI_TYPE_STRUCT:
{
size_t size = (*p_arg)->size;
size_t align = (*p_arg)->alignment;
int hfa_type = hfa_element_type (*p_arg, 0);
FFI_ASSERT (align <= 16);
if (align == 16 && (gpcount & 1))
gpcount++;
if (hfa_type != FFI_TYPE_VOID)
{
size_t hfa_size = hfa_type_size (hfa_type);
size_t offset = 0;
size_t gp_offset = gpcount * 8;
void *addr = alloca (size);
avalue[i] = addr;
while (fpcount < 8
&& offset < size
&& gp_offset < 8 * 8)
{
hfa_type_store (hfa_type, addr + offset,
&stack->fp_regs[fpcount]);
offset += hfa_size;
gp_offset += hfa_size;
fpcount += 1;
}
if (offset < size)
memcpy (addr + offset, (char *)stack->gp_regs + gp_offset,
size - offset);
}
else
avalue[i] = &stack->gp_regs[gpcount];
gpcount += (size + 7) / 8;
}
break;
default:
abort ();
}
}
closure->fun (cif, rvalue, avalue, closure->user_data);
return cif->flags;
}

View File

@@ -0,0 +1,50 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for IA-64.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifndef LIBFFI_ASM
typedef unsigned long long ffi_arg;
typedef signed long long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_UNIX, /* Linux and all Unix variants use the same conventions */
FFI_DEFAULT_ABI = FFI_UNIX,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */
/* can be interpreted as a C function */
/* descriptor: */
#endif

View File

@@ -0,0 +1,40 @@
/* -----------------------------------------------------------------------
ia64_flags.h - Copyright (c) 2000 Hewlett Packard Company
IA64/unix Foreign Function Interface
Original author: Hans Boehm, HP Labs
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
/* "Type" codes used between assembly and C. When used as a part of
a cfi->flags value, the low byte will be these extra type codes,
and bits 8-31 will be the actual size of the type. */
/* Small structures containing N words in integer registers. */
#define FFI_IA64_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 1)
/* Homogeneous Floating Point Aggregates (HFAs) which are returned
in FP registers. */
#define FFI_IA64_TYPE_HFA_FLOAT (FFI_TYPE_LAST + 2)
#define FFI_IA64_TYPE_HFA_DOUBLE (FFI_TYPE_LAST + 3)
#define FFI_IA64_TYPE_HFA_LDOUBLE (FFI_TYPE_LAST + 4)

View File

@@ -0,0 +1,560 @@
/* -----------------------------------------------------------------------
unix.S - Copyright (c) 1998, 2008 Red Hat, Inc.
Copyright (c) 2000 Hewlett Packard Company
IA64/unix Foreign Function Interface
Primary author: Hans Boehm, HP Labs
Loosely modeled on Cygnus code for other platforms.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#include "ia64_flags.h"
.pred.safe_across_calls p1-p5,p16-p63
.text
/* int ffi_call_unix (struct ia64_args *stack, PTR64 rvalue,
void (*fn)(void), int flags);
*/
.align 16
.global ffi_call_unix
.proc ffi_call_unix
ffi_call_unix:
.prologue
/* Bit o trickiness. We actually share a stack frame with ffi_call.
Rely on the fact that ffi_call uses a vframe and don't bother
tracking one here at all. */
.fframe 0
.save ar.pfs, r36 // loc0
alloc loc0 = ar.pfs, 4, 3, 8, 0
.save rp, loc1
mov loc1 = b0
.body
add r16 = 16, in0
mov loc2 = gp
mov r8 = in1
;;
/* Load up all of the argument registers. */
ldf.fill f8 = [in0], 32
ldf.fill f9 = [r16], 32
;;
ldf.fill f10 = [in0], 32
ldf.fill f11 = [r16], 32
;;
ldf.fill f12 = [in0], 32
ldf.fill f13 = [r16], 32
;;
ldf.fill f14 = [in0], 32
ldf.fill f15 = [r16], 24
;;
ld8 out0 = [in0], 16
ld8 out1 = [r16], 16
;;
ld8 out2 = [in0], 16
ld8 out3 = [r16], 16
;;
ld8 out4 = [in0], 16
ld8 out5 = [r16], 16
;;
ld8 out6 = [in0]
ld8 out7 = [r16]
;;
/* Deallocate the register save area from the stack frame. */
mov sp = in0
/* Call the target function. */
ld8 r16 = [in2], 8
;;
ld8 gp = [in2]
mov b6 = r16
br.call.sptk.many b0 = b6
;;
/* Dispatch to handle return value. */
mov gp = loc2
zxt1 r16 = in3
;;
mov ar.pfs = loc0
addl r18 = @ltoffx(.Lst_table), gp
;;
ld8.mov r18 = [r18], .Lst_table
mov b0 = loc1
;;
shladd r18 = r16, 3, r18
;;
ld8 r17 = [r18]
shr in3 = in3, 8
;;
add r17 = r17, r18
;;
mov b6 = r17
br b6
;;
.Lst_void:
br.ret.sptk.many b0
;;
.Lst_uint8:
zxt1 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_sint8:
sxt1 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_uint16:
zxt2 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_sint16:
sxt2 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_uint32:
zxt4 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_sint32:
sxt4 r8 = r8
;;
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_int64:
st8 [in1] = r8
br.ret.sptk.many b0
;;
.Lst_float:
stfs [in1] = f8
br.ret.sptk.many b0
;;
.Lst_double:
stfd [in1] = f8
br.ret.sptk.many b0
;;
.Lst_ldouble:
stfe [in1] = f8
br.ret.sptk.many b0
;;
.Lst_small_struct:
add sp = -16, sp
cmp.lt p6, p0 = 8, in3
cmp.lt p7, p0 = 16, in3
cmp.lt p8, p0 = 24, in3
;;
add r16 = 8, sp
add r17 = 16, sp
add r18 = 24, sp
;;
st8 [sp] = r8
(p6) st8 [r16] = r9
mov out0 = in1
(p7) st8 [r17] = r10
(p8) st8 [r18] = r11
mov out1 = sp
mov out2 = in3
br.call.sptk.many b0 = memcpy#
;;
mov ar.pfs = loc0
mov b0 = loc1
mov gp = loc2
br.ret.sptk.many b0
.Lst_hfa_float:
add r16 = 4, in1
cmp.lt p6, p0 = 4, in3
;;
stfs [in1] = f8, 8
(p6) stfs [r16] = f9, 8
cmp.lt p7, p0 = 8, in3
cmp.lt p8, p0 = 12, in3
;;
(p7) stfs [in1] = f10, 8
(p8) stfs [r16] = f11, 8
cmp.lt p9, p0 = 16, in3
cmp.lt p10, p0 = 20, in3
;;
(p9) stfs [in1] = f12, 8
(p10) stfs [r16] = f13, 8
cmp.lt p6, p0 = 24, in3
cmp.lt p7, p0 = 28, in3
;;
(p6) stfs [in1] = f14
(p7) stfs [r16] = f15
br.ret.sptk.many b0
;;
.Lst_hfa_double:
add r16 = 8, in1
cmp.lt p6, p0 = 8, in3
;;
stfd [in1] = f8, 16
(p6) stfd [r16] = f9, 16
cmp.lt p7, p0 = 16, in3
cmp.lt p8, p0 = 24, in3
;;
(p7) stfd [in1] = f10, 16
(p8) stfd [r16] = f11, 16
cmp.lt p9, p0 = 32, in3
cmp.lt p10, p0 = 40, in3
;;
(p9) stfd [in1] = f12, 16
(p10) stfd [r16] = f13, 16
cmp.lt p6, p0 = 48, in3
cmp.lt p7, p0 = 56, in3
;;
(p6) stfd [in1] = f14
(p7) stfd [r16] = f15
br.ret.sptk.many b0
;;
.Lst_hfa_ldouble:
add r16 = 16, in1
cmp.lt p6, p0 = 16, in3
;;
stfe [in1] = f8, 32
(p6) stfe [r16] = f9, 32
cmp.lt p7, p0 = 32, in3
cmp.lt p8, p0 = 48, in3
;;
(p7) stfe [in1] = f10, 32
(p8) stfe [r16] = f11, 32
cmp.lt p9, p0 = 64, in3
cmp.lt p10, p0 = 80, in3
;;
(p9) stfe [in1] = f12, 32
(p10) stfe [r16] = f13, 32
cmp.lt p6, p0 = 96, in3
cmp.lt p7, p0 = 112, in3
;;
(p6) stfe [in1] = f14
(p7) stfe [r16] = f15
br.ret.sptk.many b0
;;
.endp ffi_call_unix
.align 16
.global ffi_closure_unix
.proc ffi_closure_unix
#define FRAME_SIZE (8*16 + 8*8 + 8*16)
ffi_closure_unix:
.prologue
.save ar.pfs, r40 // loc0
alloc loc0 = ar.pfs, 8, 4, 4, 0
.fframe FRAME_SIZE
add r12 = -FRAME_SIZE, r12
.save rp, loc1
mov loc1 = b0
.save ar.unat, loc2
mov loc2 = ar.unat
.body
/* Retrieve closure pointer and real gp. */
#ifdef _ILP32
addp4 out0 = 0, gp
addp4 gp = 16, gp
#else
mov out0 = gp
add gp = 16, gp
#endif
;;
ld8 gp = [gp]
/* Spill all of the possible argument registers. */
add r16 = 16 + 8*16, sp
add r17 = 16 + 8*16 + 16, sp
;;
stf.spill [r16] = f8, 32
stf.spill [r17] = f9, 32
mov loc3 = gp
;;
stf.spill [r16] = f10, 32
stf.spill [r17] = f11, 32
;;
stf.spill [r16] = f12, 32
stf.spill [r17] = f13, 32
;;
stf.spill [r16] = f14, 32
stf.spill [r17] = f15, 24
;;
.mem.offset 0, 0
st8.spill [r16] = in0, 16
.mem.offset 8, 0
st8.spill [r17] = in1, 16
add out1 = 16 + 8*16, sp
;;
.mem.offset 0, 0
st8.spill [r16] = in2, 16
.mem.offset 8, 0
st8.spill [r17] = in3, 16
add out2 = 16, sp
;;
.mem.offset 0, 0
st8.spill [r16] = in4, 16
.mem.offset 8, 0
st8.spill [r17] = in5, 16
mov out3 = r8
;;
.mem.offset 0, 0
st8.spill [r16] = in6
.mem.offset 8, 0
st8.spill [r17] = in7
/* Invoke ffi_closure_unix_inner for the hard work. */
br.call.sptk.many b0 = ffi_closure_unix_inner
;;
/* Dispatch to handle return value. */
mov gp = loc3
zxt1 r16 = r8
;;
addl r18 = @ltoffx(.Lld_table), gp
mov ar.pfs = loc0
;;
ld8.mov r18 = [r18], .Lld_table
mov b0 = loc1
;;
shladd r18 = r16, 3, r18
mov ar.unat = loc2
;;
ld8 r17 = [r18]
shr r8 = r8, 8
;;
add r17 = r17, r18
add r16 = 16, sp
;;
mov b6 = r17
br b6
;;
.label_state 1
.Lld_void:
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_int:
.body
.copy_state 1
ld8 r8 = [r16]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_float:
.body
.copy_state 1
ldfs f8 = [r16]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_double:
.body
.copy_state 1
ldfd f8 = [r16]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_ldouble:
.body
.copy_state 1
ldfe f8 = [r16]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_small_struct:
.body
.copy_state 1
add r17 = 8, r16
cmp.lt p6, p0 = 8, r8
cmp.lt p7, p0 = 16, r8
cmp.lt p8, p0 = 24, r8
;;
ld8 r8 = [r16], 16
(p6) ld8 r9 = [r17], 16
;;
(p7) ld8 r10 = [r16]
(p8) ld8 r11 = [r17]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_hfa_float:
.body
.copy_state 1
add r17 = 4, r16
cmp.lt p6, p0 = 4, r8
;;
ldfs f8 = [r16], 8
(p6) ldfs f9 = [r17], 8
cmp.lt p7, p0 = 8, r8
cmp.lt p8, p0 = 12, r8
;;
(p7) ldfs f10 = [r16], 8
(p8) ldfs f11 = [r17], 8
cmp.lt p9, p0 = 16, r8
cmp.lt p10, p0 = 20, r8
;;
(p9) ldfs f12 = [r16], 8
(p10) ldfs f13 = [r17], 8
cmp.lt p6, p0 = 24, r8
cmp.lt p7, p0 = 28, r8
;;
(p6) ldfs f14 = [r16]
(p7) ldfs f15 = [r17]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_hfa_double:
.body
.copy_state 1
add r17 = 8, r16
cmp.lt p6, p0 = 8, r8
;;
ldfd f8 = [r16], 16
(p6) ldfd f9 = [r17], 16
cmp.lt p7, p0 = 16, r8
cmp.lt p8, p0 = 24, r8
;;
(p7) ldfd f10 = [r16], 16
(p8) ldfd f11 = [r17], 16
cmp.lt p9, p0 = 32, r8
cmp.lt p10, p0 = 40, r8
;;
(p9) ldfd f12 = [r16], 16
(p10) ldfd f13 = [r17], 16
cmp.lt p6, p0 = 48, r8
cmp.lt p7, p0 = 56, r8
;;
(p6) ldfd f14 = [r16]
(p7) ldfd f15 = [r17]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.Lld_hfa_ldouble:
.body
.copy_state 1
add r17 = 16, r16
cmp.lt p6, p0 = 16, r8
;;
ldfe f8 = [r16], 32
(p6) ldfe f9 = [r17], 32
cmp.lt p7, p0 = 32, r8
cmp.lt p8, p0 = 48, r8
;;
(p7) ldfe f10 = [r16], 32
(p8) ldfe f11 = [r17], 32
cmp.lt p9, p0 = 64, r8
cmp.lt p10, p0 = 80, r8
;;
(p9) ldfe f12 = [r16], 32
(p10) ldfe f13 = [r17], 32
cmp.lt p6, p0 = 96, r8
cmp.lt p7, p0 = 112, r8
;;
(p6) ldfe f14 = [r16]
(p7) ldfe f15 = [r17]
.restore sp
add sp = FRAME_SIZE, sp
br.ret.sptk.many b0
;;
.endp ffi_closure_unix
.section .rodata
.align 8
.Lst_table:
data8 @pcrel(.Lst_void) // FFI_TYPE_VOID
data8 @pcrel(.Lst_sint32) // FFI_TYPE_INT
data8 @pcrel(.Lst_float) // FFI_TYPE_FLOAT
data8 @pcrel(.Lst_double) // FFI_TYPE_DOUBLE
data8 @pcrel(.Lst_ldouble) // FFI_TYPE_LONGDOUBLE
data8 @pcrel(.Lst_uint8) // FFI_TYPE_UINT8
data8 @pcrel(.Lst_sint8) // FFI_TYPE_SINT8
data8 @pcrel(.Lst_uint16) // FFI_TYPE_UINT16
data8 @pcrel(.Lst_sint16) // FFI_TYPE_SINT16
data8 @pcrel(.Lst_uint32) // FFI_TYPE_UINT32
data8 @pcrel(.Lst_sint32) // FFI_TYPE_SINT32
data8 @pcrel(.Lst_int64) // FFI_TYPE_UINT64
data8 @pcrel(.Lst_int64) // FFI_TYPE_SINT64
data8 @pcrel(.Lst_void) // FFI_TYPE_STRUCT
data8 @pcrel(.Lst_int64) // FFI_TYPE_POINTER
data8 @pcrel(.Lst_small_struct) // FFI_IA64_TYPE_SMALL_STRUCT
data8 @pcrel(.Lst_hfa_float) // FFI_IA64_TYPE_HFA_FLOAT
data8 @pcrel(.Lst_hfa_double) // FFI_IA64_TYPE_HFA_DOUBLE
data8 @pcrel(.Lst_hfa_ldouble) // FFI_IA64_TYPE_HFA_LDOUBLE
.Lld_table:
data8 @pcrel(.Lld_void) // FFI_TYPE_VOID
data8 @pcrel(.Lld_int) // FFI_TYPE_INT
data8 @pcrel(.Lld_float) // FFI_TYPE_FLOAT
data8 @pcrel(.Lld_double) // FFI_TYPE_DOUBLE
data8 @pcrel(.Lld_ldouble) // FFI_TYPE_LONGDOUBLE
data8 @pcrel(.Lld_int) // FFI_TYPE_UINT8
data8 @pcrel(.Lld_int) // FFI_TYPE_SINT8
data8 @pcrel(.Lld_int) // FFI_TYPE_UINT16
data8 @pcrel(.Lld_int) // FFI_TYPE_SINT16
data8 @pcrel(.Lld_int) // FFI_TYPE_UINT32
data8 @pcrel(.Lld_int) // FFI_TYPE_SINT32
data8 @pcrel(.Lld_int) // FFI_TYPE_UINT64
data8 @pcrel(.Lld_int) // FFI_TYPE_SINT64
data8 @pcrel(.Lld_void) // FFI_TYPE_STRUCT
data8 @pcrel(.Lld_int) // FFI_TYPE_POINTER
data8 @pcrel(.Lld_small_struct) // FFI_IA64_TYPE_SMALL_STRUCT
data8 @pcrel(.Lld_hfa_float) // FFI_IA64_TYPE_HFA_FLOAT
data8 @pcrel(.Lld_hfa_double) // FFI_IA64_TYPE_HFA_DOUBLE
data8 @pcrel(.Lld_hfa_ldouble) // FFI_IA64_TYPE_HFA_LDOUBLE
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,359 @@
/* -----------------------------------------------------------------------
java_raw_api.c - Copyright (c) 1999, 2007, 2008 Red Hat, Inc.
Cloned from raw_api.c
Raw_api.c author: Kresten Krab Thorup <krab@gnu.org>
Java_raw_api.c author: Hans-J. Boehm <hboehm@hpl.hp.com>
$Id $
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
/* This defines a Java- and 64-bit specific variant of the raw API. */
/* It assumes that "raw" argument blocks look like Java stacks on a */
/* 64-bit machine. Arguments that can be stored in a single stack */
/* stack slots (longs, doubles) occupy 128 bits, but only the first */
/* 64 bits are actually used. */
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
#if !defined(NO_JAVA_RAW_API) && !defined(FFI_NO_RAW_API)
size_t
ffi_java_raw_size (ffi_cif *cif)
{
size_t result = 0;
int i;
ffi_type **at = cif->arg_types;
for (i = cif->nargs-1; i >= 0; i--, at++)
{
switch((*at) -> type) {
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
result += 2 * FFI_SIZEOF_JAVA_RAW;
break;
case FFI_TYPE_STRUCT:
/* No structure parameters in Java. */
abort();
default:
result += FFI_SIZEOF_JAVA_RAW;
}
}
return result;
}
void
ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args)
{
unsigned i;
ffi_type **tp = cif->arg_types;
#if WORDS_BIGENDIAN
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
switch ((*tp)->type)
{
case FFI_TYPE_UINT8:
case FFI_TYPE_SINT8:
*args = (void*) ((char*)(raw++) + 3);
break;
case FFI_TYPE_UINT16:
case FFI_TYPE_SINT16:
*args = (void*) ((char*)(raw++) + 2);
break;
#if FFI_SIZEOF_JAVA_RAW == 8
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
*args = (void *)raw;
raw += 2;
break;
#endif
case FFI_TYPE_POINTER:
*args = (void*) &(raw++)->ptr;
break;
default:
*args = raw;
raw +=
ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
}
}
#else /* WORDS_BIGENDIAN */
#if !PDP
/* then assume little endian */
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
#if FFI_SIZEOF_JAVA_RAW == 8
switch((*tp)->type) {
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
*args = (void*) raw;
raw += 2;
break;
default:
*args = (void*) raw++;
}
#else /* FFI_SIZEOF_JAVA_RAW != 8 */
*args = (void*) raw;
raw +=
ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
#endif /* FFI_SIZEOF_JAVA_RAW == 8 */
}
#else
#error "pdp endian not supported"
#endif /* ! PDP */
#endif /* WORDS_BIGENDIAN */
}
void
ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw)
{
unsigned i;
ffi_type **tp = cif->arg_types;
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
switch ((*tp)->type)
{
case FFI_TYPE_UINT8:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT8*) (*args);
#else
(raw++)->uint = *(UINT8*) (*args);
#endif
break;
case FFI_TYPE_SINT8:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT8*) (*args);
#else
(raw++)->sint = *(SINT8*) (*args);
#endif
break;
case FFI_TYPE_UINT16:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT16*) (*args);
#else
(raw++)->uint = *(UINT16*) (*args);
#endif
break;
case FFI_TYPE_SINT16:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT16*) (*args);
#else
(raw++)->sint = *(SINT16*) (*args);
#endif
break;
case FFI_TYPE_UINT32:
#if WORDS_BIGENDIAN
*(UINT32*)(raw++) = *(UINT32*) (*args);
#else
(raw++)->uint = *(UINT32*) (*args);
#endif
break;
case FFI_TYPE_SINT32:
#if WORDS_BIGENDIAN
*(SINT32*)(raw++) = *(SINT32*) (*args);
#else
(raw++)->sint = *(SINT32*) (*args);
#endif
break;
case FFI_TYPE_FLOAT:
(raw++)->flt = *(FLOAT32*) (*args);
break;
#if FFI_SIZEOF_JAVA_RAW == 8
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
case FFI_TYPE_DOUBLE:
raw->uint = *(UINT64*) (*args);
raw += 2;
break;
#endif
case FFI_TYPE_POINTER:
(raw++)->ptr = **(void***) args;
break;
default:
#if FFI_SIZEOF_JAVA_RAW == 8
FFI_ASSERT(0); /* Should have covered all cases */
#else
memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
raw +=
ALIGN ((*tp)->size, sizeof(ffi_java_raw)) / sizeof(ffi_java_raw);
#endif
}
}
}
#if !FFI_NATIVE_RAW_API
static void
ffi_java_rvalue_to_raw (ffi_cif *cif, void *rvalue)
{
#if WORDS_BIGENDIAN && FFI_SIZEOF_ARG == 8
switch (cif->rtype->type)
{
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT32:
*(UINT64 *)rvalue <<= 32;
break;
case FFI_TYPE_SINT8:
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32:
case FFI_TYPE_INT:
#if FFI_SIZEOF_JAVA_RAW == 4
case FFI_TYPE_POINTER:
#endif
*(SINT64 *)rvalue <<= 32;
break;
default:
break;
}
#endif
}
static void
ffi_java_raw_to_rvalue (ffi_cif *cif, void *rvalue)
{
#if WORDS_BIGENDIAN && FFI_SIZEOF_ARG == 8
switch (cif->rtype->type)
{
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT32:
*(UINT64 *)rvalue >>= 32;
break;
case FFI_TYPE_SINT8:
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT32:
case FFI_TYPE_INT:
#if FFI_SIZEOF_JAVA_RAW == 4
case FFI_TYPE_POINTER:
#endif
*(SINT64 *)rvalue >>= 32;
break;
default:
break;
}
#endif
}
/* This is a generic definition of ffi_raw_call, to be used if the
* native system does not provide a machine-specific implementation.
* Having this, allows code to be written for the raw API, without
* the need for system-specific code to handle input in that format;
* these following couple of functions will handle the translation forth
* and back automatically. */
void ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue,
ffi_java_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_java_raw_to_ptrarray (cif, raw, avalue);
ffi_call (cif, fn, rvalue, avalue);
ffi_java_rvalue_to_raw (cif, rvalue);
}
#if FFI_CLOSURES /* base system provides closures */
static void
ffi_java_translate_args (ffi_cif *cif, void *rvalue,
void **avalue, void *user_data)
{
ffi_java_raw *raw = (ffi_java_raw*)alloca (ffi_java_raw_size (cif));
ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
ffi_java_ptrarray_to_raw (cif, avalue, raw);
(*cl->fun) (cif, rvalue, raw, cl->user_data);
ffi_java_raw_to_rvalue (cif, rvalue);
}
ffi_status
ffi_prep_java_raw_closure_loc (ffi_java_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data,
void *codeloc)
{
ffi_status status;
status = ffi_prep_closure_loc ((ffi_closure*) cl,
cif,
&ffi_java_translate_args,
codeloc,
codeloc);
if (status == FFI_OK)
{
cl->fun = fun;
cl->user_data = user_data;
}
return status;
}
/* Again, here is the generic version of ffi_prep_raw_closure, which
* will install an intermediate "hub" for translation of arguments from
* the pointer-array format, to the raw format */
ffi_status
ffi_prep_java_raw_closure (ffi_java_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data)
{
return ffi_prep_java_raw_closure_loc (cl, cif, fun, user_data, cl);
}
#endif /* FFI_CLOSURES */
#endif /* !FFI_NATIVE_RAW_API */
#endif /* !FFI_NO_RAW_API */

View File

@@ -0,0 +1,232 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 2004 Renesas Technology
Copyright (c) 2008 Red Hat, Inc.
M32R 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 RENESAS TECHNOLOGY 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>
/* ffi_prep_args is called by the assembly routine once stack
space has been allocated for the function's arguments. */
void ffi_prep_args(char *stack, extended_cif *ecif)
{
unsigned int i;
int tmp;
unsigned int avn;
void **p_argv;
char *argp;
ffi_type **p_arg;
tmp = 0;
argp = stack;
if (ecif->cif->rtype->type == FFI_TYPE_STRUCT && ecif->cif->rtype->size > 8)
{
*(void **) argp = ecif->rvalue;
argp += 4;
}
avn = ecif->cif->nargs;
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
(i != 0) && (avn != 0);
i--, p_arg++)
{
size_t z;
/* Align if necessary. */
if (((*p_arg)->alignment - 1) & (unsigned) argp)
argp = (char *) ALIGN (argp, (*p_arg)->alignment);
if (avn != 0)
{
avn--;
z = (*p_arg)->size;
if (z < sizeof (int))
{
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:
z = (*p_arg)->size;
if ((*p_arg)->alignment != 1)
memcpy (argp, *p_argv, z);
else
memcpy (argp + 4 - z, *p_argv, z);
z = sizeof (int);
break;
default:
FFI_ASSERT(0);
}
}
else if (z == sizeof (int))
{
*(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
}
else
{
if ((*p_arg)->type == FFI_TYPE_STRUCT)
{
if (z > 8)
{
*(unsigned int *) argp = (unsigned int)(void *)(* p_argv);
z = sizeof(void *);
}
else
{
memcpy(argp, *p_argv, z);
z = 8;
}
}
else
{
/* Double or long long 64bit. */
memcpy (argp, *p_argv, z);
}
}
p_argv++;
argp += z;
}
}
return;
}
/* Perform machine dependent cif processing. */
ffi_status
ffi_prep_cif_machdep(ffi_cif *cif)
{
/* Set the return type flag. */
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
cif->flags = (unsigned) cif->rtype->type;
break;
case FFI_TYPE_STRUCT:
if (cif->rtype->size <= 4)
cif->flags = FFI_TYPE_INT;
else if (cif->rtype->size <= 8)
cif->flags = FFI_TYPE_DOUBLE;
else
cif->flags = (unsigned) cif->rtype->type;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
case FFI_TYPE_DOUBLE:
cif->flags = FFI_TYPE_DOUBLE;
break;
case FFI_TYPE_FLOAT:
default:
cif->flags = FFI_TYPE_INT;
break;
}
return FFI_OK;
}
extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
unsigned, unsigned, unsigned *, void (*fn)(void));
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, 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))
{
ecif.rvalue = alloca (cif->rtype->size);
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_SYSV:
ffi_call_SYSV(ffi_prep_args, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
if (cif->rtype->type == FFI_TYPE_STRUCT)
{
int size = cif->rtype->size;
int align = cif->rtype->alignment;
if (size < 4)
{
if (align == 1)
*(unsigned long *)(ecif.rvalue) <<= (4 - size) * 8;
}
else if (4 < size && size < 8)
{
if (align == 1)
{
memcpy (ecif.rvalue, ecif.rvalue + 8-size, size);
}
else if (align == 2)
{
if (size & 1)
size += 1;
if (size != 8)
memcpy (ecif.rvalue, ecif.rvalue + 8-size, size);
}
}
}
break;
default:
FFI_ASSERT(0);
break;
}
}

View File

@@ -0,0 +1,48 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 2004 Renesas Technology.
Target configuration macros for M32R.
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 RENESAS TECHNOLOGY 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
/* ---- Generic type definitions ----------------------------------------- */
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi
{
FFI_FIRST_ABI = 0,
FFI_SYSV,
FFI_DEFAULT_ABI = FFI_SYSV,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
#define FFI_CLOSURES 0
#define FFI_TRAMPOLINE_SIZE 24
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,121 @@
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 2004 Renesas Technology
M32R 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 RENESAS TECHNOLOGY 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 <fficonfig.h>
#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
.text
/* R0: ffi_prep_args */
/* R1: &ecif */
/* R2: cif->bytes */
/* R3: fig->flags */
/* sp+0: ecif.rvalue */
/* sp+4: fn */
/* This assumes we are using gas. */
ENTRY(ffi_call_SYSV)
/* Save registers. */
push fp
push lr
push r3
push r2
push r1
push r0
mv fp, sp
/* Make room for all of the new args. */
sub sp, r2
/* Place all of the ffi_prep_args in position. */
mv lr, r0
mv r0, sp
/* R1 already set. */
/* And call. */
jl lr
/* Move first 4 parameters in registers... */
ld r0, @(0,sp)
ld r1, @(4,sp)
ld r2, @(8,sp)
ld r3, @(12,sp)
/* ...and adjust the stack. */
ld lr, @(8,fp)
cmpi lr, #16
bc adjust_stack
ldi lr, #16
adjust_stack:
add sp, lr
/* Call the function. */
ld lr, @(28,fp)
jl lr
/* Remove the space we pushed for the args. */
mv sp, fp
/* Load R2 with the pointer to storage for the return value. */
ld r2, @(24,sp)
/* Load R3 with the return type code. */
ld r3, @(12,sp)
/* If the return value pointer is NULL, assume no return value. */
beqz r2, epilogue
/* Return INT. */
ldi r4, #FFI_TYPE_INT
bne r3, r4, return_double
st r0, @r2
bra epilogue
return_double:
/* Return DOUBLE or LONGDOUBLE. */
ldi r4, #FFI_TYPE_DOUBLE
bne r3, r4, epilogue
st r0, @r2
st r1, @(4,r2)
epilogue:
pop r0
pop r1
pop r2
pop r3
pop lr
pop fp
jmp lr
.ffi_call_SYSV_end:
.size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)

View File

@@ -0,0 +1,278 @@
/* -----------------------------------------------------------------------
ffi.c
m68k Foreign Function Interface
----------------------------------------------------------------------- */
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <asm/cachectl.h>
void ffi_call_SYSV (extended_cif *,
unsigned, unsigned,
void *, void (*fn) ());
void *ffi_prep_args (void *stack, extended_cif *ecif);
void ffi_closure_SYSV (ffi_closure *);
void ffi_closure_struct_SYSV (ffi_closure *);
unsigned int ffi_closure_SYSV_inner (ffi_closure *closure,
void *resp, void *args);
/* ffi_prep_args is called by the assembly routine once stack space has
been allocated for the function's arguments. */
void *
ffi_prep_args (void *stack, extended_cif *ecif)
{
unsigned int i;
void **p_argv;
char *argp;
ffi_type **p_arg;
void *struct_value_ptr;
argp = stack;
if (ecif->cif->rtype->type == FFI_TYPE_STRUCT
&& !ecif->cif->flags)
struct_value_ptr = ecif->rvalue;
else
struct_value_ptr = NULL;
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
i != 0;
i--, p_arg++)
{
size_t z;
z = (*p_arg)->size;
if (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:
memcpy (argp + sizeof (int) - z, *p_argv, z);
break;
default:
FFI_ASSERT (0);
}
z = sizeof (int);
}
else
{
memcpy (argp, *p_argv, z);
/* Align if necessary. */
if ((sizeof(int) - 1) & z)
z = ALIGN(z, sizeof(int));
}
p_argv++;
argp += z;
}
return struct_value_ptr;
}
#define CIF_FLAGS_INT 1
#define CIF_FLAGS_DINT 2
#define CIF_FLAGS_FLOAT 4
#define CIF_FLAGS_DOUBLE 8
#define CIF_FLAGS_LDOUBLE 16
#define CIF_FLAGS_POINTER 32
#define CIF_FLAGS_STRUCT1 64
#define CIF_FLAGS_STRUCT2 128
/* Perform machine dependent cif processing */
ffi_status
ffi_prep_cif_machdep (ffi_cif *cif)
{
/* Set the return type flag */
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
cif->flags = 0;
break;
case FFI_TYPE_STRUCT:
switch (cif->rtype->size)
{
case 1:
cif->flags = CIF_FLAGS_STRUCT1;
break;
case 2:
cif->flags = CIF_FLAGS_STRUCT2;
break;
case 4:
cif->flags = CIF_FLAGS_INT;
break;
case 8:
cif->flags = CIF_FLAGS_DINT;
break;
default:
cif->flags = 0;
break;
}
break;
case FFI_TYPE_FLOAT:
cif->flags = CIF_FLAGS_FLOAT;
break;
case FFI_TYPE_DOUBLE:
cif->flags = CIF_FLAGS_DOUBLE;
break;
case FFI_TYPE_LONGDOUBLE:
cif->flags = CIF_FLAGS_LDOUBLE;
break;
case FFI_TYPE_POINTER:
cif->flags = CIF_FLAGS_POINTER;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
cif->flags = CIF_FLAGS_DINT;
break;
default:
cif->flags = CIF_FLAGS_INT;
break;
}
return FFI_OK;
}
void
ffi_call (ffi_cif *cif, void (*fn) (), void *rvalue, 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
&& cif->rtype->size > 8)
ecif.rvalue = alloca (cif->rtype->size);
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_SYSV:
ffi_call_SYSV (&ecif, cif->bytes, cif->flags,
ecif.rvalue, fn);
break;
default:
FFI_ASSERT (0);
break;
}
}
static void
ffi_prep_incoming_args_SYSV (char *stack, void **avalue, ffi_cif *cif)
{
unsigned int i;
void **p_argv;
char *argp;
ffi_type **p_arg;
argp = stack;
p_argv = avalue;
for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
{
size_t z;
z = (*p_arg)->size;
if (z <= 4)
{
*p_argv = (void *) (argp + 4 - z);
z = 4;
}
else
{
*p_argv = (void *) argp;
/* Align if necessary */
if ((sizeof(int) - 1) & z)
z = ALIGN(z, sizeof(int));
}
p_argv++;
argp += z;
}
}
unsigned int
ffi_closure_SYSV_inner (ffi_closure *closure, void *resp, void *args)
{
ffi_cif *cif;
void **arg_area;
cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void *));
ffi_prep_incoming_args_SYSV(args, arg_area, cif);
(closure->fun) (cif, resp, arg_area, closure->user_data);
return cif->flags;
}
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void *codeloc)
{
FFI_ASSERT (cif->abi == FFI_SYSV);
*(unsigned short *)closure->tramp = 0x207c;
*(void **)(closure->tramp + 2) = codeloc;
*(unsigned short *)(closure->tramp + 6) = 0x4ef9;
if (cif->rtype->type == FFI_TYPE_STRUCT
&& !cif->flags)
*(void **)(closure->tramp + 8) = ffi_closure_struct_SYSV;
else
*(void **)(closure->tramp + 8) = ffi_closure_SYSV;
syscall(SYS_cacheflush, codeloc, FLUSH_SCOPE_LINE,
FLUSH_CACHE_BOTH, FFI_TRAMPOLINE_SIZE);
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
return FFI_OK;
}

View File

@@ -0,0 +1,49 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for Motorola 68K.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_SYSV,
FFI_DEFAULT_ABI = FFI_SYSV,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_TRAMPOLINE_SIZE 16
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,234 @@
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 1998 Andreas Schwab
Copyright (c) 2008 Red Hat, Inc.
m68k 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#ifdef HAVE_AS_CFI_PSEUDO_OP
#define CFI_STARTPROC() .cfi_startproc
#define CFI_OFFSET(reg,off) .cfi_offset reg,off
#define CFI_DEF_CFA(reg,off) .cfi_def_cfa reg,off
#define CFI_ENDPROC() .cfi_endproc
#else
#define CFI_STARTPROC()
#define CFI_OFFSET(reg,off)
#define CFI_DEF_CFA(reg,off)
#define CFI_ENDPROC()
#endif
.text
.globl ffi_call_SYSV
.type ffi_call_SYSV,@function
.align 4
ffi_call_SYSV:
CFI_STARTPROC()
link %fp,#0
CFI_OFFSET(14,-8)
CFI_DEF_CFA(14,8)
move.l %d2,-(%sp)
CFI_OFFSET(2,-12)
| Make room for all of the new args.
sub.l 12(%fp),%sp
| Call ffi_prep_args
move.l 8(%fp),-(%sp)
pea 4(%sp)
#if !defined __PIC__
jsr ffi_prep_args
#else
bsr.l ffi_prep_args@PLTPC
#endif
addq.l #8,%sp
| Pass pointer to struct value, if any
move.l %a0,%a1
| Call the function
move.l 24(%fp),%a0
jsr (%a0)
| Remove the space we pushed for the args
add.l 12(%fp),%sp
| Load the pointer to storage for the return value
move.l 20(%fp),%a1
| Load the return type code
move.l 16(%fp),%d2
| If the return value pointer is NULL, assume no return value.
tst.l %a1
jbeq noretval
btst #0,%d2
jbeq retlongint
move.l %d0,(%a1)
jbra epilogue
retlongint:
btst #1,%d2
jbeq retfloat
move.l %d0,(%a1)
move.l %d1,4(%a1)
jbra epilogue
retfloat:
btst #2,%d2
jbeq retdouble
fmove.s %fp0,(%a1)
jbra epilogue
retdouble:
btst #3,%d2
jbeq retlongdouble
fmove.d %fp0,(%a1)
jbra epilogue
retlongdouble:
btst #4,%d2
jbeq retpointer
fmove.x %fp0,(%a1)
jbra epilogue
retpointer:
btst #5,%d2
jbeq retstruct1
move.l %a0,(%a1)
jbra epilogue
retstruct1:
btst #6,%d2
jbeq retstruct2
move.b %d0,(%a1)
jbra epilogue
retstruct2:
btst #7,%d2
jbeq noretval
move.w %d0,(%a1)
noretval:
epilogue:
move.l (%sp)+,%d2
unlk %fp
rts
CFI_ENDPROC()
.size ffi_call_SYSV,.-ffi_call_SYSV
.globl ffi_closure_SYSV
.type ffi_closure_SYSV, @function
.align 4
ffi_closure_SYSV:
CFI_STARTPROC()
link %fp,#-12
CFI_OFFSET(14,-8)
CFI_DEF_CFA(14,8)
move.l %sp,-12(%fp)
pea 8(%fp)
pea -12(%fp)
move.l %a0,-(%sp)
#if !defined __PIC__
jsr ffi_closure_SYSV_inner
#else
bsr.l ffi_closure_SYSV_inner@PLTPC
#endif
lsr.l #1,%d0
jne 1f
jcc .Lcls_epilogue
move.l -12(%fp),%d0
.Lcls_epilogue:
unlk %fp
rts
1:
lea -12(%fp),%a0
lsr.l #2,%d0
jne 1f
jcs .Lcls_ret_float
move.l (%a0)+,%d0
move.l (%a0),%d1
jra .Lcls_epilogue
.Lcls_ret_float:
fmove.s (%a0),%fp0
jra .Lcls_epilogue
1:
lsr.l #2,%d0
jne 1f
jcs .Lcls_ret_ldouble
fmove.d (%a0),%fp0
jra .Lcls_epilogue
.Lcls_ret_ldouble:
fmove.x (%a0),%fp0
jra .Lcls_epilogue
1:
lsr.l #2,%d0
jne .Lcls_ret_struct2
jcs .Lcls_ret_struct1
move.l (%a0),%a0
move.l %a0,%d0
jra .Lcls_epilogue
.Lcls_ret_struct1:
move.b (%a0),%d0
jra .Lcls_epilogue
.Lcls_ret_struct2:
move.w (%a0),%d0
jra .Lcls_epilogue
CFI_ENDPROC()
.size ffi_closure_SYSV,.-ffi_closure_SYSV
.globl ffi_closure_struct_SYSV
.type ffi_closure_struct_SYSV, @function
.align 4
ffi_closure_struct_SYSV:
CFI_STARTPROC()
link %fp,#0
CFI_OFFSET(14,-8)
CFI_DEF_CFA(14,8)
move.l %sp,-12(%fp)
pea 8(%fp)
move.l %a1,-(%sp)
move.l %a0,-(%sp)
#if !defined __PIC__
jsr ffi_closure_SYSV_inner
#else
bsr.l ffi_closure_SYSV_inner@PLTPC
#endif
unlk %fp
rts
CFI_ENDPROC()
.size ffi_closure_struct_SYSV,.-ffi_closure_struct_SYSV
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,926 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1996, 2007, 2008 Red Hat, Inc.
Copyright (c) 2008 David Daney
MIPS 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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
#ifdef __GNUC__
# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
# define USE__BUILTIN___CLEAR_CACHE 1
# endif
#endif
#ifndef USE__BUILTIN___CLEAR_CACHE
#include <sys/cachectl.h>
#endif
#ifdef FFI_DEBUG
# define FFI_MIPS_STOP_HERE() ffi_stop_here()
#else
# define FFI_MIPS_STOP_HERE() do {} while(0)
#endif
#ifdef FFI_MIPS_N32
#define FIX_ARGP \
FFI_ASSERT(argp <= &stack[bytes]); \
if (argp == &stack[bytes]) \
{ \
argp = stack; \
FFI_MIPS_STOP_HERE(); \
}
#else
#define FIX_ARGP
#endif
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments */
static void ffi_prep_args(char *stack,
extended_cif *ecif,
int bytes,
int flags)
{
int i;
void **p_argv;
char *argp;
ffi_type **p_arg;
#ifdef FFI_MIPS_N32
/* If more than 8 double words are used, the remainder go
on the stack. We reorder stuff on the stack here to
support this easily. */
if (bytes > 8 * sizeof(ffi_arg))
argp = &stack[bytes - (8 * sizeof(ffi_arg))];
else
argp = stack;
#else
argp = stack;
#endif
memset(stack, 0, bytes);
#ifdef FFI_MIPS_N32
if ( ecif->cif->rstruct_flag != 0 )
#else
if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT )
#endif
{
*(ffi_arg *) argp = (ffi_arg) ecif->rvalue;
argp += sizeof(ffi_arg);
FIX_ARGP;
}
p_argv = ecif->avalue;
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; i; i--, p_arg++)
{
size_t z;
unsigned int a;
/* Align if necessary. */
a = (*p_arg)->alignment;
if (a < sizeof(ffi_arg))
a = sizeof(ffi_arg);
if ((a - 1) & (unsigned long) argp)
{
argp = (char *) ALIGN(argp, a);
FIX_ARGP;
}
z = (*p_arg)->size;
if (z <= sizeof(ffi_arg))
{
int type = (*p_arg)->type;
z = sizeof(ffi_arg);
/* The size of a pointer depends on the ABI */
if (type == FFI_TYPE_POINTER)
type =
(ecif->cif->abi == FFI_N64) ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
switch (type)
{
case FFI_TYPE_SINT8:
*(ffi_arg *)argp = *(SINT8 *)(* p_argv);
break;
case FFI_TYPE_UINT8:
*(ffi_arg *)argp = *(UINT8 *)(* p_argv);
break;
case FFI_TYPE_SINT16:
*(ffi_arg *)argp = *(SINT16 *)(* p_argv);
break;
case FFI_TYPE_UINT16:
*(ffi_arg *)argp = *(UINT16 *)(* p_argv);
break;
case FFI_TYPE_SINT32:
*(ffi_arg *)argp = *(SINT32 *)(* p_argv);
break;
case FFI_TYPE_UINT32:
*(ffi_arg *)argp = *(UINT32 *)(* p_argv);
break;
/* This can only happen with 64bit slots. */
case FFI_TYPE_FLOAT:
*(float *) argp = *(float *)(* p_argv);
break;
/* Handle structures. */
default:
memcpy(argp, *p_argv, (*p_arg)->size);
break;
}
}
else
{
#ifdef FFI_MIPS_O32
memcpy(argp, *p_argv, z);
#else
{
unsigned long end = (unsigned long) argp + z;
unsigned long cap = (unsigned long) stack + bytes;
/* Check if the data will fit within the register space.
Handle it if it doesn't. */
if (end <= cap)
memcpy(argp, *p_argv, z);
else
{
unsigned long portion = cap - (unsigned long)argp;
memcpy(argp, *p_argv, portion);
argp = stack;
z -= portion;
memcpy(argp, (void*)((unsigned long)(*p_argv) + portion),
z);
}
}
#endif
}
p_argv++;
argp += z;
FIX_ARGP;
}
}
#ifdef FFI_MIPS_N32
/* The n32 spec says that if "a chunk consists solely of a double
float field (but not a double, which is part of a union), it
is passed in a floating point register. Any other chunk is
passed in an integer register". This code traverses structure
definitions and generates the appropriate flags. */
static unsigned
calc_n32_struct_flags(ffi_type *arg, unsigned *loc, unsigned *arg_reg)
{
unsigned flags = 0;
unsigned index = 0;
ffi_type *e;
while ((e = arg->elements[index]))
{
/* Align this object. */
*loc = ALIGN(*loc, e->alignment);
if (e->type == FFI_TYPE_DOUBLE)
{
/* Already aligned to FFI_SIZEOF_ARG. */
*arg_reg = *loc / FFI_SIZEOF_ARG;
if (*arg_reg > 7)
break;
flags += (FFI_TYPE_DOUBLE << (*arg_reg * FFI_FLAG_BITS));
*loc += e->size;
}
else
*loc += e->size;
index++;
}
/* Next Argument register at alignment of FFI_SIZEOF_ARG. */
*arg_reg = ALIGN(*loc, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
return flags;
}
static unsigned
calc_n32_return_struct_flags(ffi_type *arg)
{
unsigned flags = 0;
unsigned small = FFI_TYPE_SMALLSTRUCT;
ffi_type *e;
/* Returning structures under n32 is a tricky thing.
A struct with only one or two floating point fields
is returned in $f0 (and $f2 if necessary). Any other
struct results at most 128 bits are returned in $2
(the first 64 bits) and $3 (remainder, if necessary).
Larger structs are handled normally. */
if (arg->size > 16)
return 0;
if (arg->size > 8)
small = FFI_TYPE_SMALLSTRUCT2;
e = arg->elements[0];
if (e->type == FFI_TYPE_DOUBLE)
flags = FFI_TYPE_DOUBLE;
else if (e->type == FFI_TYPE_FLOAT)
flags = FFI_TYPE_FLOAT;
if (flags && (e = arg->elements[1]))
{
if (e->type == FFI_TYPE_DOUBLE)
flags += FFI_TYPE_DOUBLE << FFI_FLAG_BITS;
else if (e->type == FFI_TYPE_FLOAT)
flags += FFI_TYPE_FLOAT << FFI_FLAG_BITS;
else
return small;
if (flags && (arg->elements[2]))
{
/* There are three arguments and the first two are
floats! This must be passed the old way. */
return small;
}
}
else
if (!flags)
return small;
return flags;
}
#endif
/* Perform machine dependent cif processing */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
cif->flags = 0;
#ifdef FFI_MIPS_O32
/* Set the flags necessary for O32 processing. FFI_O32_SOFT_FLOAT
* does not have special handling for floating point args.
*/
if (cif->rtype->type != FFI_TYPE_STRUCT && cif->abi == FFI_O32)
{
if (cif->nargs > 0)
{
switch ((cif->arg_types)[0]->type)
{
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags += (cif->arg_types)[0]->type;
break;
default:
break;
}
if (cif->nargs > 1)
{
/* Only handle the second argument if the first
is a float or double. */
if (cif->flags)
{
switch ((cif->arg_types)[1]->type)
{
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags += (cif->arg_types)[1]->type << FFI_FLAG_BITS;
break;
default:
break;
}
}
}
}
}
/* Set the return type flag */
if (cif->abi == FFI_O32_SOFT_FLOAT)
{
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
case FFI_TYPE_STRUCT:
cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
case FFI_TYPE_DOUBLE:
cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
break;
case FFI_TYPE_FLOAT:
default:
cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
break;
}
}
else
{
/* FFI_O32 */
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
case FFI_TYPE_STRUCT:
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 2);
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
cif->flags += FFI_TYPE_UINT64 << (FFI_FLAG_BITS * 2);
break;
default:
cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 2);
break;
}
}
#endif
#ifdef FFI_MIPS_N32
/* Set the flags necessary for N32 processing */
{
unsigned arg_reg = 0;
unsigned loc = 0;
unsigned count = (cif->nargs < 8) ? cif->nargs : 8;
unsigned index = 0;
unsigned struct_flags = 0;
if (cif->rtype->type == FFI_TYPE_STRUCT)
{
struct_flags = calc_n32_return_struct_flags(cif->rtype);
if (struct_flags == 0)
{
/* This means that the structure is being passed as
a hidden argument */
arg_reg = 1;
count = (cif->nargs < 7) ? cif->nargs : 7;
cif->rstruct_flag = !0;
}
else
cif->rstruct_flag = 0;
}
else
cif->rstruct_flag = 0;
while (count-- > 0 && arg_reg < 8)
{
switch ((cif->arg_types)[index]->type)
{
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags +=
((cif->arg_types)[index]->type << (arg_reg * FFI_FLAG_BITS));
arg_reg++;
break;
case FFI_TYPE_LONGDOUBLE:
/* Align it. */
arg_reg = ALIGN(arg_reg, 2);
/* Treat it as two adjacent doubles. */
cif->flags +=
(FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
arg_reg++;
cif->flags +=
(FFI_TYPE_DOUBLE << (arg_reg * FFI_FLAG_BITS));
arg_reg++;
break;
case FFI_TYPE_STRUCT:
loc = arg_reg * FFI_SIZEOF_ARG;
cif->flags += calc_n32_struct_flags((cif->arg_types)[index],
&loc, &arg_reg);
break;
default:
arg_reg++;
break;
}
index++;
}
/* Set the return type flag */
switch (cif->rtype->type)
{
case FFI_TYPE_STRUCT:
{
if (struct_flags == 0)
{
/* The structure is returned through a hidden
first argument. Do nothing, 'cause FFI_TYPE_VOID
is 0 */
}
else
{
/* The structure is returned via some tricky
mechanism */
cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
cif->flags += struct_flags << (4 + (FFI_FLAG_BITS * 8));
}
break;
}
case FFI_TYPE_VOID:
/* Do nothing, 'cause FFI_TYPE_VOID is 0 */
break;
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags += cif->rtype->type << (FFI_FLAG_BITS * 8);
break;
case FFI_TYPE_LONGDOUBLE:
/* Long double is returned as if it were a struct containing
two doubles. */
cif->flags += FFI_TYPE_STRUCT << (FFI_FLAG_BITS * 8);
cif->flags += (FFI_TYPE_DOUBLE + (FFI_TYPE_DOUBLE << FFI_FLAG_BITS))
<< (4 + (FFI_FLAG_BITS * 8));
break;
default:
cif->flags += FFI_TYPE_INT << (FFI_FLAG_BITS * 8);
break;
}
}
#endif
return FFI_OK;
}
/* Low level routine for calling O32 functions */
extern int ffi_call_O32(void (*)(char *, extended_cif *, int, int),
extended_cif *, unsigned,
unsigned, unsigned *, void (*)(void));
/* Low level routine for calling N32 functions */
extern int ffi_call_N32(void (*)(char *, extended_cif *, int, int),
extended_cif *, unsigned,
unsigned, unsigned *, void (*)(void));
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, 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))
ecif.rvalue = alloca(cif->rtype->size);
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
#ifdef FFI_MIPS_O32
case FFI_O32:
case FFI_O32_SOFT_FLOAT:
ffi_call_O32(ffi_prep_args, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
break;
#endif
#ifdef FFI_MIPS_N32
case FFI_N32:
case FFI_N64:
{
int copy_rvalue = 0;
void *rvalue_copy = ecif.rvalue;
if (cif->rtype->type == FFI_TYPE_STRUCT && cif->rtype->size < 16)
{
/* For structures smaller than 16 bytes we clobber memory
in 8 byte increments. Make a copy so we don't clobber
the callers memory outside of the struct bounds. */
rvalue_copy = alloca(16);
copy_rvalue = 1;
}
ffi_call_N32(ffi_prep_args, &ecif, cif->bytes,
cif->flags, rvalue_copy, fn);
if (copy_rvalue)
memcpy(ecif.rvalue, rvalue_copy, cif->rtype->size);
}
break;
#endif
default:
FFI_ASSERT(0);
break;
}
}
#if FFI_CLOSURES
#if defined(FFI_MIPS_O32)
extern void ffi_closure_O32(void);
#else
extern void ffi_closure_N32(void);
#endif /* FFI_MIPS_O32 */
ffi_status
ffi_prep_closure_loc (ffi_closure *closure,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void *codeloc)
{
unsigned int *tramp = (unsigned int *) &closure->tramp[0];
void * fn;
char *clear_location = (char *) codeloc;
#if defined(FFI_MIPS_O32)
FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
fn = ffi_closure_O32;
#else /* FFI_MIPS_N32 */
FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
fn = ffi_closure_N32;
#endif /* FFI_MIPS_O32 */
#if defined(FFI_MIPS_O32) || (_MIPS_SIM ==_ABIN32)
/* lui $25,high(fn) */
tramp[0] = 0x3c190000 | ((unsigned)fn >> 16);
/* ori $25,low(fn) */
tramp[1] = 0x37390000 | ((unsigned)fn & 0xffff);
/* lui $12,high(codeloc) */
tramp[2] = 0x3c0c0000 | ((unsigned)codeloc >> 16);
/* jr $25 */
tramp[3] = 0x03200008;
/* ori $12,low(codeloc) */
tramp[4] = 0x358c0000 | ((unsigned)codeloc & 0xffff);
#else
/* N64 has a somewhat larger trampoline. */
/* lui $25,high(fn) */
tramp[0] = 0x3c190000 | ((unsigned long)fn >> 48);
/* lui $12,high(codeloc) */
tramp[1] = 0x3c0c0000 | ((unsigned long)codeloc >> 48);
/* ori $25,mid-high(fn) */
tramp[2] = 0x37390000 | (((unsigned long)fn >> 32 ) & 0xffff);
/* ori $12,mid-high(codeloc) */
tramp[3] = 0x358c0000 | (((unsigned long)codeloc >> 32) & 0xffff);
/* dsll $25,$25,16 */
tramp[4] = 0x0019cc38;
/* dsll $12,$12,16 */
tramp[5] = 0x000c6438;
/* ori $25,mid-low(fn) */
tramp[6] = 0x37390000 | (((unsigned long)fn >> 16 ) & 0xffff);
/* ori $12,mid-low(codeloc) */
tramp[7] = 0x358c0000 | (((unsigned long)codeloc >> 16) & 0xffff);
/* dsll $25,$25,16 */
tramp[8] = 0x0019cc38;
/* dsll $12,$12,16 */
tramp[9] = 0x000c6438;
/* ori $25,low(fn) */
tramp[10] = 0x37390000 | ((unsigned long)fn & 0xffff);
/* jr $25 */
tramp[11] = 0x03200008;
/* ori $12,low(codeloc) */
tramp[12] = 0x358c0000 | ((unsigned long)codeloc & 0xffff);
#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
#ifdef USE__BUILTIN___CLEAR_CACHE
__builtin___clear_cache(clear_location, clear_location + FFI_TRAMPOLINE_SIZE);
#else
cacheflush (clear_location, FFI_TRAMPOLINE_SIZE, ICACHE);
#endif
return FFI_OK;
}
/*
* Decodes the arguments to a function, which will be stored on the
* stack. AR is the pointer to the beginning of the integer arguments
* (and, depending upon the arguments, some floating-point arguments
* as well). FPR is a pointer to the area where floating point
* registers have been saved, if any.
*
* RVALUE is the location where the function return value will be
* stored. CLOSURE is the prepared closure to invoke.
*
* This function should only be called from assembly, which is in
* turn called from a trampoline.
*
* Returns the function return type.
*
* Based on the similar routine for sparc.
*/
int
ffi_closure_mips_inner_O32 (ffi_closure *closure,
void *rvalue, ffi_arg *ar,
double *fpr)
{
ffi_cif *cif;
void **avaluep;
ffi_arg *avalue;
ffi_type **arg_types;
int i, avn, argn, seen_int;
cif = closure->cif;
avalue = alloca (cif->nargs * sizeof (ffi_arg));
avaluep = alloca (cif->nargs * sizeof (ffi_arg));
seen_int = (cif->abi == FFI_O32_SOFT_FLOAT);
argn = 0;
if ((cif->flags >> (FFI_FLAG_BITS * 2)) == FFI_TYPE_STRUCT)
{
rvalue = (void *)(UINT32)ar[0];
argn = 1;
}
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
while (i < avn)
{
if (i < 2 && !seen_int &&
(arg_types[i]->type == FFI_TYPE_FLOAT ||
arg_types[i]->type == FFI_TYPE_DOUBLE))
{
#ifdef __MIPSEB__
if (arg_types[i]->type == FFI_TYPE_FLOAT)
avaluep[i] = ((char *) &fpr[i]) + sizeof (float);
else
#endif
avaluep[i] = (char *) &fpr[i];
}
else
{
if (arg_types[i]->alignment == 8 && (argn & 0x1))
argn++;
switch (arg_types[i]->type)
{
case FFI_TYPE_SINT8:
avaluep[i] = &avalue[i];
*(SINT8 *) &avalue[i] = (SINT8) ar[argn];
break;
case FFI_TYPE_UINT8:
avaluep[i] = &avalue[i];
*(UINT8 *) &avalue[i] = (UINT8) ar[argn];
break;
case FFI_TYPE_SINT16:
avaluep[i] = &avalue[i];
*(SINT16 *) &avalue[i] = (SINT16) ar[argn];
break;
case FFI_TYPE_UINT16:
avaluep[i] = &avalue[i];
*(UINT16 *) &avalue[i] = (UINT16) ar[argn];
break;
default:
avaluep[i] = (char *) &ar[argn];
break;
}
seen_int = 1;
}
argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
i++;
}
/* Invoke the closure. */
(closure->fun) (cif, rvalue, avaluep, closure->user_data);
if (cif->abi == FFI_O32_SOFT_FLOAT)
{
switch (cif->rtype->type)
{
case FFI_TYPE_FLOAT:
return FFI_TYPE_INT;
case FFI_TYPE_DOUBLE:
return FFI_TYPE_UINT64;
default:
return cif->rtype->type;
}
}
else
{
return cif->rtype->type;
}
}
#if defined(FFI_MIPS_N32)
static void
copy_struct_N32(char *target, unsigned offset, ffi_abi abi, ffi_type *type,
int argn, unsigned arg_offset, ffi_arg *ar,
ffi_arg *fpr)
{
ffi_type **elt_typep = type->elements;
while(*elt_typep)
{
ffi_type *elt_type = *elt_typep;
unsigned o;
char *tp;
char *argp;
char *fpp;
o = ALIGN(offset, elt_type->alignment);
arg_offset += o - offset;
offset = o;
argn += arg_offset / sizeof(ffi_arg);
arg_offset = arg_offset % sizeof(ffi_arg);
argp = (char *)(ar + argn);
fpp = (char *)(argn >= 8 ? ar + argn : fpr + argn);
tp = target + offset;
if (elt_type->type == FFI_TYPE_DOUBLE)
*(double *)tp = *(double *)fpp;
else
memcpy(tp, argp + arg_offset, elt_type->size);
offset += elt_type->size;
arg_offset += elt_type->size;
elt_typep++;
argn += arg_offset / sizeof(ffi_arg);
arg_offset = arg_offset % sizeof(ffi_arg);
}
}
/*
* Decodes the arguments to a function, which will be stored on the
* stack. AR is the pointer to the beginning of the integer
* arguments. FPR is a pointer to the area where floating point
* registers have been saved.
*
* RVALUE is the location where the function return value will be
* stored. CLOSURE is the prepared closure to invoke.
*
* This function should only be called from assembly, which is in
* turn called from a trampoline.
*
* Returns the function return flags.
*
*/
int
ffi_closure_mips_inner_N32 (ffi_closure *closure,
void *rvalue, ffi_arg *ar,
ffi_arg *fpr)
{
ffi_cif *cif;
void **avaluep;
ffi_arg *avalue;
ffi_type **arg_types;
int i, avn, argn;
cif = closure->cif;
avalue = alloca (cif->nargs * sizeof (ffi_arg));
avaluep = alloca (cif->nargs * sizeof (ffi_arg));
argn = 0;
if (cif->rstruct_flag)
{
#if _MIPS_SIM==_ABIN32
rvalue = (void *)(UINT32)ar[0];
#else /* N64 */
rvalue = (void *)ar[0];
#endif
argn = 1;
}
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
while (i < avn)
{
if (arg_types[i]->type == FFI_TYPE_FLOAT
|| arg_types[i]->type == FFI_TYPE_DOUBLE)
{
ffi_arg *argp = argn >= 8 ? ar + argn : fpr + argn;
#ifdef __MIPSEB__
if (arg_types[i]->type == FFI_TYPE_FLOAT && argn < 8)
avaluep[i] = ((char *) argp) + sizeof (float);
else
#endif
avaluep[i] = (char *) argp;
}
else
{
unsigned type = arg_types[i]->type;
if (arg_types[i]->alignment > sizeof(ffi_arg))
argn = ALIGN(argn, arg_types[i]->alignment / sizeof(ffi_arg));
ffi_arg *argp = ar + argn;
/* The size of a pointer depends on the ABI */
if (type == FFI_TYPE_POINTER)
type = (cif->abi == FFI_N64) ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32;
switch (type)
{
case FFI_TYPE_SINT8:
avaluep[i] = &avalue[i];
*(SINT8 *) &avalue[i] = (SINT8) *argp;
break;
case FFI_TYPE_UINT8:
avaluep[i] = &avalue[i];
*(UINT8 *) &avalue[i] = (UINT8) *argp;
break;
case FFI_TYPE_SINT16:
avaluep[i] = &avalue[i];
*(SINT16 *) &avalue[i] = (SINT16) *argp;
break;
case FFI_TYPE_UINT16:
avaluep[i] = &avalue[i];
*(UINT16 *) &avalue[i] = (UINT16) *argp;
break;
case FFI_TYPE_SINT32:
avaluep[i] = &avalue[i];
*(SINT32 *) &avalue[i] = (SINT32) *argp;
break;
case FFI_TYPE_UINT32:
avaluep[i] = &avalue[i];
*(UINT32 *) &avalue[i] = (UINT32) *argp;
break;
case FFI_TYPE_STRUCT:
if (argn < 8)
{
/* Allocate space for the struct as at least part of
it was passed in registers. */
avaluep[i] = alloca(arg_types[i]->size);
copy_struct_N32(avaluep[i], 0, cif->abi, arg_types[i],
argn, 0, ar, fpr);
break;
}
/* Else fall through. */
default:
avaluep[i] = (char *) argp;
break;
}
}
argn += ALIGN(arg_types[i]->size, sizeof(ffi_arg)) / sizeof(ffi_arg);
i++;
}
/* Invoke the closure. */
(closure->fun) (cif, rvalue, avaluep, closure->user_data);
return cif->flags >> (FFI_FLAG_BITS * 8);
}
#endif /* FFI_MIPS_N32 */
#endif /* FFI_CLOSURES */

View File

@@ -0,0 +1,202 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for MIPS.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#ifdef linux
#include <asm/sgidefs.h>
# ifndef _ABIN32
# define _ABIN32 _MIPS_SIM_NABI32
# endif
# ifndef _ABI64
# define _ABI64 _MIPS_SIM_ABI64
# endif
# ifndef _ABIO32
# define _ABIO32 _MIPS_SIM_ABI32
# endif
#endif
#if !defined(_MIPS_SIM)
-- something is very wrong --
#else
# if (_MIPS_SIM==_ABIN32 && defined(_ABIN32)) || (_MIPS_SIM==_ABI64 && defined(_ABI64))
# define FFI_MIPS_N32
# else
# if (_MIPS_SIM==_ABIO32 && defined(_ABIO32))
# define FFI_MIPS_O32
# else
-- this is an unsupported platform --
# endif
# endif
#endif
#ifdef FFI_MIPS_O32
/* O32 stack frames have 32bit integer args */
# define FFI_SIZEOF_ARG 4
#else
/* N32 and N64 frames have 64bit integer args */
# define FFI_SIZEOF_ARG 8
# if _MIPS_SIM == _ABIN32
# define FFI_SIZEOF_JAVA_RAW 4
# endif
#endif
#define FFI_FLAG_BITS 2
/* SGI's strange assembler requires that we multiply by 4 rather
than shift left by FFI_FLAG_BITS */
#define FFI_ARGS_D FFI_TYPE_DOUBLE
#define FFI_ARGS_F FFI_TYPE_FLOAT
#define FFI_ARGS_DD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_DOUBLE
#define FFI_ARGS_FF FFI_TYPE_FLOAT * 4 + FFI_TYPE_FLOAT
#define FFI_ARGS_FD FFI_TYPE_DOUBLE * 4 + FFI_TYPE_FLOAT
#define FFI_ARGS_DF FFI_TYPE_FLOAT * 4 + FFI_TYPE_DOUBLE
/* Needed for N32 structure returns */
#define FFI_TYPE_SMALLSTRUCT FFI_TYPE_UINT8
#define FFI_TYPE_SMALLSTRUCT2 FFI_TYPE_SINT8
#if 0
/* The SGI assembler can't handle this.. */
#define FFI_TYPE_STRUCT_DD (( FFI_ARGS_DD ) << 4) + FFI_TYPE_STRUCT
/* (and so on) */
#else
/* ...so we calculate these by hand! */
#define FFI_TYPE_STRUCT_D 61
#define FFI_TYPE_STRUCT_F 45
#define FFI_TYPE_STRUCT_DD 253
#define FFI_TYPE_STRUCT_FF 173
#define FFI_TYPE_STRUCT_FD 237
#define FFI_TYPE_STRUCT_DF 189
#define FFI_TYPE_STRUCT_SMALL 93
#define FFI_TYPE_STRUCT_SMALL2 109
#endif
#ifdef LIBFFI_ASM
#define v0 $2
#define v1 $3
#define a0 $4
#define a1 $5
#define a2 $6
#define a3 $7
#define a4 $8
#define a5 $9
#define a6 $10
#define a7 $11
#define t0 $8
#define t1 $9
#define t2 $10
#define t3 $11
#define t4 $12
#define t5 $13
#define t6 $14
#define t7 $15
#define t8 $24
#define t9 $25
#define ra $31
#ifdef FFI_MIPS_O32
# define REG_L lw
# define REG_S sw
# define SUBU subu
# define ADDU addu
# define SRL srl
# define LI li
#else /* !FFI_MIPS_O32 */
# define REG_L ld
# define REG_S sd
# define SUBU dsubu
# define ADDU daddu
# define SRL dsrl
# define LI dli
# if (_MIPS_SIM==_ABI64)
# define LA dla
# define EH_FRAME_ALIGN 3
# define FDE_ADDR_BYTES .8byte
# else
# define LA la
# define EH_FRAME_ALIGN 2
# define FDE_ADDR_BYTES .4byte
# endif /* _MIPS_SIM==_ABI64 */
#endif /* !FFI_MIPS_O32 */
#else /* !LIBFFI_ASM */
#ifdef FFI_MIPS_O32
/* O32 stack frames have 32bit integer args */
typedef unsigned int ffi_arg __attribute__((__mode__(__SI__)));
typedef signed int ffi_sarg __attribute__((__mode__(__SI__)));
#else
/* N32 and N64 frames have 64bit integer args */
typedef unsigned int ffi_arg __attribute__((__mode__(__DI__)));
typedef signed int ffi_sarg __attribute__((__mode__(__DI__)));
#endif
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_O32,
FFI_N32,
FFI_N64,
FFI_O32_SOFT_FLOAT,
#ifdef FFI_MIPS_O32
#ifdef __mips_soft_float
FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT,
#else
FFI_DEFAULT_ABI = FFI_O32,
#endif
#else
# if _MIPS_SIM==_ABI64
FFI_DEFAULT_ABI = FFI_N64,
# else
FFI_DEFAULT_ABI = FFI_N32,
# endif
#endif
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#define FFI_EXTRA_CIF_FIELDS unsigned rstruct_flag
#endif /* !LIBFFI_ASM */
/* ---- Definitions for closures ----------------------------------------- */
#if defined(FFI_MIPS_O32)
#define FFI_CLOSURES 1
#define FFI_TRAMPOLINE_SIZE 20
#else
/* N32/N64. */
# define FFI_CLOSURES 1
#if _MIPS_SIM==_ABI64
#define FFI_TRAMPOLINE_SIZE 52
#else
#define FFI_TRAMPOLINE_SIZE 20
#endif
#endif /* FFI_MIPS_O32 */
#define FFI_NATIVE_RAW_API 0
#endif

View File

@@ -0,0 +1,534 @@
/* -----------------------------------------------------------------------
n32.S - Copyright (c) 1996, 1998, 2005 Red Hat, Inc.
MIPS 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 THE AUTHORS OR COPYRIGHT HOLDERS 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 <fficonfig.h>
#include <ffi.h>
/* Only build this code if we are compiling for n32 */
#if defined(FFI_MIPS_N32)
#define callback a0
#define bytes a2
#define flags a3
#define raddr a4
#define fn a5
#define SIZEOF_FRAME ( 8 * FFI_SIZEOF_ARG )
.abicalls
.text
.align 2
.globl ffi_call_N32
.ent ffi_call_N32
ffi_call_N32:
.LFB3:
.frame $fp, SIZEOF_FRAME, ra
.mask 0xc0000000,-FFI_SIZEOF_ARG
.fmask 0x00000000,0
# Prologue
SUBU $sp, SIZEOF_FRAME # Frame size
.LCFI0:
REG_S $fp, SIZEOF_FRAME - 2*FFI_SIZEOF_ARG($sp) # Save frame pointer
REG_S ra, SIZEOF_FRAME - 1*FFI_SIZEOF_ARG($sp) # Save return address
.LCFI1:
move $fp, $sp
.LCFI3:
move t9, callback # callback function pointer
REG_S bytes, 2*FFI_SIZEOF_ARG($fp) # bytes
REG_S flags, 3*FFI_SIZEOF_ARG($fp) # flags
REG_S raddr, 4*FFI_SIZEOF_ARG($fp) # raddr
REG_S fn, 5*FFI_SIZEOF_ARG($fp) # fn
# Allocate at least 4 words in the argstack
move v0, bytes
bge bytes, 4 * FFI_SIZEOF_ARG, bigger
LI v0, 4 * FFI_SIZEOF_ARG
b sixteen
bigger:
ADDU t4, v0, 2 * FFI_SIZEOF_ARG -1 # make sure it is aligned
and v0, t4, -2 * FFI_SIZEOF_ARG # to a proper boundry.
sixteen:
SUBU $sp, $sp, v0 # move the stack pointer to reflect the
# arg space
move a0, $sp # 4 * FFI_SIZEOF_ARG
ADDU a3, $fp, 3 * FFI_SIZEOF_ARG
# Call ffi_prep_args
jal t9
# Copy the stack pointer to t9
move t9, $sp
# Fix the stack if there are more than 8 64bit slots worth
# of arguments.
# Load the number of bytes
REG_L t6, 2*FFI_SIZEOF_ARG($fp)
# Is it bigger than 8 * FFI_SIZEOF_ARG?
daddiu t8, t6, -(8 * FFI_SIZEOF_ARG)
bltz t8, loadregs
ADDU t9, t9, t8
loadregs:
REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
and t4, t6, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg1_floatp
REG_L a0, 0*FFI_SIZEOF_ARG(t9)
b arg1_next
arg1_floatp:
bne t4, FFI_TYPE_FLOAT, arg1_doublep
l.s $f12, 0*FFI_SIZEOF_ARG(t9)
b arg1_next
arg1_doublep:
l.d $f12, 0*FFI_SIZEOF_ARG(t9)
arg1_next:
SRL t4, t6, 1*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg2_floatp
REG_L a1, 1*FFI_SIZEOF_ARG(t9)
b arg2_next
arg2_floatp:
bne t4, FFI_TYPE_FLOAT, arg2_doublep
l.s $f13, 1*FFI_SIZEOF_ARG(t9)
b arg2_next
arg2_doublep:
l.d $f13, 1*FFI_SIZEOF_ARG(t9)
arg2_next:
SRL t4, t6, 2*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg3_floatp
REG_L a2, 2*FFI_SIZEOF_ARG(t9)
b arg3_next
arg3_floatp:
bne t4, FFI_TYPE_FLOAT, arg3_doublep
l.s $f14, 2*FFI_SIZEOF_ARG(t9)
b arg3_next
arg3_doublep:
l.d $f14, 2*FFI_SIZEOF_ARG(t9)
arg3_next:
SRL t4, t6, 3*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg4_floatp
REG_L a3, 3*FFI_SIZEOF_ARG(t9)
b arg4_next
arg4_floatp:
bne t4, FFI_TYPE_FLOAT, arg4_doublep
l.s $f15, 3*FFI_SIZEOF_ARG(t9)
b arg4_next
arg4_doublep:
l.d $f15, 3*FFI_SIZEOF_ARG(t9)
arg4_next:
SRL t4, t6, 4*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg5_floatp
REG_L a4, 4*FFI_SIZEOF_ARG(t9)
b arg5_next
arg5_floatp:
bne t4, FFI_TYPE_FLOAT, arg5_doublep
l.s $f16, 4*FFI_SIZEOF_ARG(t9)
b arg5_next
arg5_doublep:
l.d $f16, 4*FFI_SIZEOF_ARG(t9)
arg5_next:
SRL t4, t6, 5*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg6_floatp
REG_L a5, 5*FFI_SIZEOF_ARG(t9)
b arg6_next
arg6_floatp:
bne t4, FFI_TYPE_FLOAT, arg6_doublep
l.s $f17, 5*FFI_SIZEOF_ARG(t9)
b arg6_next
arg6_doublep:
l.d $f17, 5*FFI_SIZEOF_ARG(t9)
arg6_next:
SRL t4, t6, 6*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg7_floatp
REG_L a6, 6*FFI_SIZEOF_ARG(t9)
b arg7_next
arg7_floatp:
bne t4, FFI_TYPE_FLOAT, arg7_doublep
l.s $f18, 6*FFI_SIZEOF_ARG(t9)
b arg7_next
arg7_doublep:
l.d $f18, 6*FFI_SIZEOF_ARG(t9)
arg7_next:
SRL t4, t6, 7*FFI_FLAG_BITS
and t4, ((1<<FFI_FLAG_BITS)-1)
bnez t4, arg8_floatp
REG_L a7, 7*FFI_SIZEOF_ARG(t9)
b arg8_next
arg8_floatp:
bne t4, FFI_TYPE_FLOAT, arg8_doublep
l.s $f19, 7*FFI_SIZEOF_ARG(t9)
b arg8_next
arg8_doublep:
l.d $f19, 7*FFI_SIZEOF_ARG(t9)
arg8_next:
callit:
# Load the function pointer
REG_L t9, 5*FFI_SIZEOF_ARG($fp)
# If the return value pointer is NULL, assume no return value.
REG_L t5, 4*FFI_SIZEOF_ARG($fp)
beqz t5, noretval
# Shift the return type flag over
SRL t6, 8*FFI_FLAG_BITS
bne t6, FFI_TYPE_INT, retfloat
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
REG_S v0, 0(t4)
b epilogue
retfloat:
bne t6, FFI_TYPE_FLOAT, retdouble
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.s $f0, 0(t4)
b epilogue
retdouble:
bne t6, FFI_TYPE_DOUBLE, retstruct_d
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.d $f0, 0(t4)
b epilogue
retstruct_d:
bne t6, FFI_TYPE_STRUCT_D, retstruct_f
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.d $f0, 0(t4)
b epilogue
retstruct_f:
bne t6, FFI_TYPE_STRUCT_F, retstruct_d_d
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.s $f0, 0(t4)
b epilogue
retstruct_d_d:
bne t6, FFI_TYPE_STRUCT_DD, retstruct_f_f
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.d $f0, 0(t4)
s.d $f2, 8(t4)
b epilogue
retstruct_f_f:
bne t6, FFI_TYPE_STRUCT_FF, retstruct_d_f
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.s $f0, 0(t4)
s.s $f2, 4(t4)
b epilogue
retstruct_d_f:
bne t6, FFI_TYPE_STRUCT_DF, retstruct_f_d
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.d $f0, 0(t4)
s.s $f2, 8(t4)
b epilogue
retstruct_f_d:
bne t6, FFI_TYPE_STRUCT_FD, retstruct_small
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
s.s $f0, 0(t4)
s.d $f2, 8(t4)
b epilogue
retstruct_small:
bne t6, FFI_TYPE_STRUCT_SMALL, retstruct_small2
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
REG_S v0, 0(t4)
b epilogue
retstruct_small2:
bne t6, FFI_TYPE_STRUCT_SMALL2, retstruct
jal t9
REG_L t4, 4*FFI_SIZEOF_ARG($fp)
REG_S v0, 0(t4)
REG_S v1, 8(t4)
b epilogue
retstruct:
noretval:
jal t9
# Epilogue
epilogue:
move $sp, $fp
REG_L $fp, SIZEOF_FRAME - 2*FFI_SIZEOF_ARG($sp) # Restore frame pointer
REG_L ra, SIZEOF_FRAME - 1*FFI_SIZEOF_ARG($sp) # Restore return address
ADDU $sp, SIZEOF_FRAME # Fix stack pointer
j ra
.LFE3:
.end ffi_call_N32
/* ffi_closure_N32. Expects address of the passed-in ffi_closure in t0
($12). Stores any arguments passed in registers onto the stack,
then calls ffi_closure_mips_inner_N32, which then decodes
them.
Stack layout:
20 - Start of parameters, original sp
19 - Called function a7 save
18 - Called function a6 save
17 - Called function a5 save
16 - Called function a4 save
15 - Called function a3 save
14 - Called function a2 save
13 - Called function a1 save
12 - Called function a0 save
11 - Called function f19
10 - Called function f18
9 - Called function f17
8 - Called function f16
7 - Called function f15
6 - Called function f14
5 - Called function f13
4 - Called function f12
3 - return value high (v1 or $f2)
2 - return value low (v0 or $f0)
1 - ra save
0 - gp save our sp points here
*/
#define SIZEOF_FRAME2 (20 * FFI_SIZEOF_ARG)
#define A7_OFF2 (19 * FFI_SIZEOF_ARG)
#define A6_OFF2 (18 * FFI_SIZEOF_ARG)
#define A5_OFF2 (17 * FFI_SIZEOF_ARG)
#define A4_OFF2 (16 * FFI_SIZEOF_ARG)
#define A3_OFF2 (15 * FFI_SIZEOF_ARG)
#define A2_OFF2 (14 * FFI_SIZEOF_ARG)
#define A1_OFF2 (13 * FFI_SIZEOF_ARG)
#define A0_OFF2 (12 * FFI_SIZEOF_ARG)
#define F19_OFF2 (11 * FFI_SIZEOF_ARG)
#define F18_OFF2 (10 * FFI_SIZEOF_ARG)
#define F17_OFF2 (9 * FFI_SIZEOF_ARG)
#define F16_OFF2 (8 * FFI_SIZEOF_ARG)
#define F15_OFF2 (7 * FFI_SIZEOF_ARG)
#define F14_OFF2 (6 * FFI_SIZEOF_ARG)
#define F13_OFF2 (5 * FFI_SIZEOF_ARG)
#define F12_OFF2 (4 * FFI_SIZEOF_ARG)
#define V1_OFF2 (3 * FFI_SIZEOF_ARG)
#define V0_OFF2 (2 * FFI_SIZEOF_ARG)
#define RA_OFF2 (1 * FFI_SIZEOF_ARG)
#define GP_OFF2 (0 * FFI_SIZEOF_ARG)
.align 2
.globl ffi_closure_N32
.ent ffi_closure_N32
ffi_closure_N32:
.LFB2:
.frame $sp, SIZEOF_FRAME2, ra
.mask 0x90000000,-(SIZEOF_FRAME2 - RA_OFF2)
.fmask 0x00000000,0
SUBU $sp, SIZEOF_FRAME2
.LCFI5:
.cpsetup t9, GP_OFF2, ffi_closure_N32
REG_S ra, RA_OFF2($sp) # Save return address
.LCFI6:
# Store all possible argument registers. If there are more than
# fit in registers, then they were stored on the stack.
REG_S a0, A0_OFF2($sp)
REG_S a1, A1_OFF2($sp)
REG_S a2, A2_OFF2($sp)
REG_S a3, A3_OFF2($sp)
REG_S a4, A4_OFF2($sp)
REG_S a5, A5_OFF2($sp)
REG_S a6, A6_OFF2($sp)
REG_S a7, A7_OFF2($sp)
# Store all possible float/double registers.
s.d $f12, F12_OFF2($sp)
s.d $f13, F13_OFF2($sp)
s.d $f14, F14_OFF2($sp)
s.d $f15, F15_OFF2($sp)
s.d $f16, F16_OFF2($sp)
s.d $f17, F17_OFF2($sp)
s.d $f18, F18_OFF2($sp)
s.d $f19, F19_OFF2($sp)
# Call ffi_closure_mips_inner_N32 to do the real work.
LA t9, ffi_closure_mips_inner_N32
move a0, $12 # Pointer to the ffi_closure
ADDU a1, $sp, V0_OFF2
ADDU a2, $sp, A0_OFF2
ADDU a3, $sp, F12_OFF2
jalr t9
# Return flags are in v0
bne v0, FFI_TYPE_INT, cls_retfloat
REG_L v0, V0_OFF2($sp)
b cls_epilogue
cls_retfloat:
bne v0, FFI_TYPE_FLOAT, cls_retdouble
l.s $f0, V0_OFF2($sp)
b cls_epilogue
cls_retdouble:
bne v0, FFI_TYPE_DOUBLE, cls_retstruct_d
l.d $f0, V0_OFF2($sp)
b cls_epilogue
cls_retstruct_d:
bne v0, FFI_TYPE_STRUCT_D, cls_retstruct_f
l.d $f0, V0_OFF2($sp)
b cls_epilogue
cls_retstruct_f:
bne v0, FFI_TYPE_STRUCT_F, cls_retstruct_d_d
l.s $f0, V0_OFF2($sp)
b cls_epilogue
cls_retstruct_d_d:
bne v0, FFI_TYPE_STRUCT_DD, cls_retstruct_f_f
l.d $f0, V0_OFF2($sp)
l.d $f2, V1_OFF2($sp)
b cls_epilogue
cls_retstruct_f_f:
bne v0, FFI_TYPE_STRUCT_FF, cls_retstruct_d_f
l.s $f0, V0_OFF2($sp)
l.s $f2, V1_OFF2($sp)
b cls_epilogue
cls_retstruct_d_f:
bne v0, FFI_TYPE_STRUCT_DF, cls_retstruct_f_d
l.d $f0, V0_OFF2($sp)
l.s $f2, V1_OFF2($sp)
b cls_epilogue
cls_retstruct_f_d:
bne v0, FFI_TYPE_STRUCT_FD, cls_retstruct_small2
l.s $f0, V0_OFF2($sp)
l.d $f2, V1_OFF2($sp)
b cls_epilogue
cls_retstruct_small2:
REG_L v0, V0_OFF2($sp)
REG_L v1, V1_OFF2($sp)
# Epilogue
cls_epilogue:
REG_L ra, RA_OFF2($sp) # Restore return address
.cpreturn
ADDU $sp, SIZEOF_FRAME2
j ra
.LFE2:
.end ffi_closure_N32
.section .eh_frame,"aw",@progbits
.Lframe1:
.4byte .LECIE1-.LSCIE1 # length
.LSCIE1:
.4byte 0x0 # CIE
.byte 0x1 # Version 1
.ascii "\000" # Augmentation
.uleb128 0x1 # Code alignment 1
.sleb128 -4 # Data alignment -4
.byte 0x1f # Return Address $31
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1d # in $sp
.uleb128 0x0 # offset 0
.align EH_FRAME_ALIGN
.LECIE1:
.LSFDE1:
.4byte .LEFDE1-.LASFDE1 # length.
.LASFDE1:
.4byte .LASFDE1-.Lframe1 # CIE_pointer.
FDE_ADDR_BYTES .LFB3 # initial_location.
FDE_ADDR_BYTES .LFE3-.LFB3 # address_range.
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI0-.LFB3 # to .LCFI0
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 SIZEOF_FRAME # adjust stack.by SIZEOF_FRAME
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI1-.LCFI0 # to .LCFI1
.byte 0x9e # DW_CFA_offset of $fp
.uleb128 2*FFI_SIZEOF_ARG/4 #
.byte 0x9f # DW_CFA_offset of ra
.uleb128 1*FFI_SIZEOF_ARG/4 #
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI3-.LCFI1 # to .LCFI3
.byte 0xd # DW_CFA_def_cfa_register
.uleb128 0x1e # in $fp
.align EH_FRAME_ALIGN
.LEFDE1:
.LSFDE3:
.4byte .LEFDE3-.LASFDE3 # length
.LASFDE3:
.4byte .LASFDE3-.Lframe1 # CIE_pointer.
FDE_ADDR_BYTES .LFB2 # initial_location.
FDE_ADDR_BYTES .LFE2-.LFB2 # address_range.
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI5-.LFB2 # to .LCFI5
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 SIZEOF_FRAME2 # adjust stack.by SIZEOF_FRAME
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI6-.LCFI5 # to .LCFI6
.byte 0x9c # DW_CFA_offset of $gp ($28)
.uleb128 (SIZEOF_FRAME2 - GP_OFF2)/4
.byte 0x9f # DW_CFA_offset of ra ($31)
.uleb128 (SIZEOF_FRAME2 - RA_OFF2)/4
.align EH_FRAME_ALIGN
.LEFDE3:
#endif

View File

@@ -0,0 +1,381 @@
/* -----------------------------------------------------------------------
o32.S - Copyright (c) 1996, 1998, 2005 Red Hat, Inc.
MIPS 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 THE AUTHORS OR COPYRIGHT HOLDERS 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 <fficonfig.h>
#include <ffi.h>
/* Only build this code if we are compiling for o32 */
#if defined(FFI_MIPS_O32)
#define callback a0
#define bytes a2
#define flags a3
#define SIZEOF_FRAME (4 * FFI_SIZEOF_ARG + 2 * FFI_SIZEOF_ARG)
#define A3_OFF (SIZEOF_FRAME + 3 * FFI_SIZEOF_ARG)
#define FP_OFF (SIZEOF_FRAME - 2 * FFI_SIZEOF_ARG)
#define RA_OFF (SIZEOF_FRAME - 1 * FFI_SIZEOF_ARG)
.abicalls
.text
.align 2
.globl ffi_call_O32
.ent ffi_call_O32
ffi_call_O32:
$LFB0:
# Prologue
SUBU $sp, SIZEOF_FRAME # Frame size
$LCFI0:
REG_S $fp, FP_OFF($sp) # Save frame pointer
$LCFI1:
REG_S ra, RA_OFF($sp) # Save return address
$LCFI2:
move $fp, $sp
$LCFI3:
move t9, callback # callback function pointer
REG_S flags, A3_OFF($fp) # flags
# Allocate at least 4 words in the argstack
LI v0, 4 * FFI_SIZEOF_ARG
blt bytes, v0, sixteen
ADDU v0, bytes, 7 # make sure it is aligned
and v0, -8 # to an 8 byte boundry
sixteen:
SUBU $sp, v0 # move the stack pointer to reflect the
# arg space
ADDU a0, $sp, 4 * FFI_SIZEOF_ARG
jalr t9
REG_L t0, A3_OFF($fp) # load the flags word
SRL t2, t0, 4 # shift our arg info
and t0, ((1<<4)-1) # mask out the return type
ADDU $sp, 4 * FFI_SIZEOF_ARG # adjust $sp to new args
bnez t0, pass_d # make it quick for int
REG_L a0, 0*FFI_SIZEOF_ARG($sp) # just go ahead and load the
REG_L a1, 1*FFI_SIZEOF_ARG($sp) # four regs.
REG_L a2, 2*FFI_SIZEOF_ARG($sp)
REG_L a3, 3*FFI_SIZEOF_ARG($sp)
b call_it
pass_d:
bne t0, FFI_ARGS_D, pass_f
l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
REG_L a2, 2*FFI_SIZEOF_ARG($sp) # passing a double
REG_L a3, 3*FFI_SIZEOF_ARG($sp)
b call_it
pass_f:
bne t0, FFI_ARGS_F, pass_d_d
l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
REG_L a1, 1*FFI_SIZEOF_ARG($sp) # passing a float
REG_L a2, 2*FFI_SIZEOF_ARG($sp)
REG_L a3, 3*FFI_SIZEOF_ARG($sp)
b call_it
pass_d_d:
bne t0, FFI_ARGS_DD, pass_f_f
l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing two doubles
b call_it
pass_f_f:
bne t0, FFI_ARGS_FF, pass_d_f
l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
l.s $f14, 1*FFI_SIZEOF_ARG($sp) # passing two floats
REG_L a2, 2*FFI_SIZEOF_ARG($sp)
REG_L a3, 3*FFI_SIZEOF_ARG($sp)
b call_it
pass_d_f:
bne t0, FFI_ARGS_DF, pass_f_d
l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
l.s $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
REG_L a3, 3*FFI_SIZEOF_ARG($sp)
b call_it
pass_f_d:
# assume that the only other combination must be float then double
# bne t0, FFI_ARGS_F_D, call_it
l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
call_it:
# Load the function pointer
REG_L t9, SIZEOF_FRAME + 5*FFI_SIZEOF_ARG($fp)
# If the return value pointer is NULL, assume no return value.
REG_L t1, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
beqz t1, noretval
bne t2, FFI_TYPE_INT, retlonglong
jalr t9
REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
REG_S v0, 0(t0)
b epilogue
retlonglong:
# Really any 64-bit int, signed or not.
bne t2, FFI_TYPE_UINT64, retfloat
jalr t9
REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
REG_S v1, 4(t0)
REG_S v0, 0(t0)
b epilogue
retfloat:
bne t2, FFI_TYPE_FLOAT, retdouble
jalr t9
REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
s.s $f0, 0(t0)
b epilogue
retdouble:
bne t2, FFI_TYPE_DOUBLE, noretval
jalr t9
REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
s.d $f0, 0(t0)
b epilogue
noretval:
jalr t9
# Epilogue
epilogue:
move $sp, $fp
REG_L $fp, FP_OFF($sp) # Restore frame pointer
REG_L ra, RA_OFF($sp) # Restore return address
ADDU $sp, SIZEOF_FRAME # Fix stack pointer
j ra
$LFE0:
.end ffi_call_O32
/* ffi_closure_O32. Expects address of the passed-in ffi_closure
in t4 ($12). Stores any arguments passed in registers onto the
stack, then calls ffi_closure_mips_inner_O32, which
then decodes them.
Stack layout:
3 - a3 save
2 - a2 save
1 - a1 save
0 - a0 save, original sp
-1 - ra save
-2 - fp save
-3 - $16 (s0) save
-4 - cprestore
-5 - return value high (v1)
-6 - return value low (v0)
-7 - f14 (le high, be low)
-8 - f14 (le low, be high)
-9 - f12 (le high, be low)
-10 - f12 (le low, be high)
-11 - Called function a3 save
-12 - Called function a2 save
-13 - Called function a1 save
-14 - Called function a0 save, our sp and fp point here
*/
#define SIZEOF_FRAME2 (14 * FFI_SIZEOF_ARG)
#define A3_OFF2 (SIZEOF_FRAME2 + 3 * FFI_SIZEOF_ARG)
#define A2_OFF2 (SIZEOF_FRAME2 + 2 * FFI_SIZEOF_ARG)
#define A1_OFF2 (SIZEOF_FRAME2 + 1 * FFI_SIZEOF_ARG)
#define A0_OFF2 (SIZEOF_FRAME2 + 0 * FFI_SIZEOF_ARG)
#define RA_OFF2 (SIZEOF_FRAME2 - 1 * FFI_SIZEOF_ARG)
#define FP_OFF2 (SIZEOF_FRAME2 - 2 * FFI_SIZEOF_ARG)
#define S0_OFF2 (SIZEOF_FRAME2 - 3 * FFI_SIZEOF_ARG)
#define GP_OFF2 (SIZEOF_FRAME2 - 4 * FFI_SIZEOF_ARG)
#define V1_OFF2 (SIZEOF_FRAME2 - 5 * FFI_SIZEOF_ARG)
#define V0_OFF2 (SIZEOF_FRAME2 - 6 * FFI_SIZEOF_ARG)
#define FA_1_1_OFF2 (SIZEOF_FRAME2 - 7 * FFI_SIZEOF_ARG)
#define FA_1_0_OFF2 (SIZEOF_FRAME2 - 8 * FFI_SIZEOF_ARG)
#define FA_0_1_OFF2 (SIZEOF_FRAME2 - 9 * FFI_SIZEOF_ARG)
#define FA_0_0_OFF2 (SIZEOF_FRAME2 - 10 * FFI_SIZEOF_ARG)
.text
.align 2
.globl ffi_closure_O32
.ent ffi_closure_O32
ffi_closure_O32:
$LFB1:
# Prologue
.frame $fp, SIZEOF_FRAME2, ra
.set noreorder
.cpload t9
.set reorder
SUBU $sp, SIZEOF_FRAME2
.cprestore GP_OFF2
$LCFI4:
REG_S $16, S0_OFF2($sp) # Save s0
REG_S $fp, FP_OFF2($sp) # Save frame pointer
REG_S ra, RA_OFF2($sp) # Save return address
$LCFI6:
move $fp, $sp
$LCFI7:
# Store all possible argument registers. If there are more than
# four arguments, then they are stored above where we put a3.
REG_S a0, A0_OFF2($fp)
REG_S a1, A1_OFF2($fp)
REG_S a2, A2_OFF2($fp)
REG_S a3, A3_OFF2($fp)
# Load ABI enum to s0
REG_L $16, 20($12) # cif pointer follows tramp.
REG_L $16, 0($16) # abi is first member.
li $13, 1 # FFI_O32
bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT
# Store all possible float/double registers.
s.d $f12, FA_0_0_OFF2($fp)
s.d $f14, FA_1_0_OFF2($fp)
1:
# Call ffi_closure_mips_inner_O32 to do the work.
la t9, ffi_closure_mips_inner_O32
move a0, $12 # Pointer to the ffi_closure
addu a1, $fp, V0_OFF2
addu a2, $fp, A0_OFF2
addu a3, $fp, FA_0_0_OFF2
jalr t9
# Load the return value into the appropriate register.
move $8, $2
li $9, FFI_TYPE_VOID
beq $8, $9, closure_done
li $13, 1 # FFI_O32
bne $16, $13, 1f # Skip fp restore if FFI_O32_SOFT_FLOAT
li $9, FFI_TYPE_FLOAT
l.s $f0, V0_OFF2($fp)
beq $8, $9, closure_done
li $9, FFI_TYPE_DOUBLE
l.d $f0, V0_OFF2($fp)
beq $8, $9, closure_done
1:
REG_L $3, V1_OFF2($fp)
REG_L $2, V0_OFF2($fp)
closure_done:
# Epilogue
move $sp, $fp
REG_L $16, S0_OFF2($sp) # Restore s0
REG_L $fp, FP_OFF2($sp) # Restore frame pointer
REG_L ra, RA_OFF2($sp) # Restore return address
ADDU $sp, SIZEOF_FRAME2
j ra
$LFE1:
.end ffi_closure_O32
/* DWARF-2 unwind info. */
.section .eh_frame,"a",@progbits
$Lframe0:
.4byte $LECIE0-$LSCIE0 # Length of Common Information Entry
$LSCIE0:
.4byte 0x0 # CIE Identifier Tag
.byte 0x1 # CIE Version
.ascii "zR\0" # CIE Augmentation
.uleb128 0x1 # CIE Code Alignment Factor
.sleb128 4 # CIE Data Alignment Factor
.byte 0x1f # CIE RA Column
.uleb128 0x1 # Augmentation size
.byte 0x00 # FDE Encoding (absptr)
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1d
.uleb128 0x0
.align 2
$LECIE0:
$LSFDE0:
.4byte $LEFDE0-$LASFDE0 # FDE Length
$LASFDE0:
.4byte $LASFDE0-$Lframe0 # FDE CIE offset
.4byte $LFB0 # FDE initial location
.4byte $LFE0-$LFB0 # FDE address range
.uleb128 0x0 # Augmentation size
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI0-$LFB0
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 0x18
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI2-$LCFI0
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x1e # $fp
.sleb128 -2 # SIZEOF_FRAME2 - 2*FFI_SIZEOF_ARG($sp)
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x1f # $ra
.sleb128 -1 # SIZEOF_FRAME2 - 1*FFI_SIZEOF_ARG($sp)
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI3-$LCFI2
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1e
.uleb128 0x18
.align 2
$LEFDE0:
$LSFDE1:
.4byte $LEFDE1-$LASFDE1 # FDE Length
$LASFDE1:
.4byte $LASFDE1-$Lframe0 # FDE CIE offset
.4byte $LFB1 # FDE initial location
.4byte $LFE1-$LFB1 # FDE address range
.uleb128 0x0 # Augmentation size
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI4-$LFB1
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 0x38
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI6-$LCFI4
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x10 # $16
.sleb128 -3 # SIZEOF_FRAME2 - 3*FFI_SIZEOF_ARG($sp)
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x1e # $fp
.sleb128 -2 # SIZEOF_FRAME2 - 2*FFI_SIZEOF_ARG($sp)
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x1f # $ra
.sleb128 -1 # SIZEOF_FRAME2 - 1*FFI_SIZEOF_ARG($sp)
.byte 0x4 # DW_CFA_advance_loc4
.4byte $LCFI7-$LCFI6
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1e
.uleb128 0x38
.align 2
$LEFDE1:
#endif

View File

@@ -0,0 +1,709 @@
/* -----------------------------------------------------------------------
ffi.c - (c) 2003-2004 Randolph Chung <tausq@debian.org>
(c) 2008 Red Hat, Inc.
HPPA Foreign Function Interface
HP-UX PA ABI support (c) 2006 Free Software Foundation, Inc.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
#include <stdio.h>
#define ROUND_UP(v, a) (((size_t)(v) + (a) - 1) & ~((a) - 1))
#define MIN_STACK_SIZE 64
#define FIRST_ARG_SLOT 9
#define DEBUG_LEVEL 0
#define fldw(addr, fpreg) \
__asm__ volatile ("fldw 0(%0), %%" #fpreg "L" : : "r"(addr) : #fpreg)
#define fstw(fpreg, addr) \
__asm__ volatile ("fstw %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define fldd(addr, fpreg) \
__asm__ volatile ("fldd 0(%0), %%" #fpreg : : "r"(addr) : #fpreg)
#define fstd(fpreg, addr) \
__asm__ volatile ("fstd %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define debug(lvl, x...) do { if (lvl <= DEBUG_LEVEL) { printf(x); } } while (0)
static inline int ffi_struct_type(ffi_type *t)
{
size_t sz = t->size;
/* Small structure results are passed in registers,
larger ones are passed by pointer. Note that
small structures of size 2, 4 and 8 differ from
the corresponding integer types in that they have
different alignment requirements. */
if (sz <= 1)
return FFI_TYPE_UINT8;
else if (sz == 2)
return FFI_TYPE_SMALL_STRUCT2;
else if (sz == 3)
return FFI_TYPE_SMALL_STRUCT3;
else if (sz == 4)
return FFI_TYPE_SMALL_STRUCT4;
else if (sz == 5)
return FFI_TYPE_SMALL_STRUCT5;
else if (sz == 6)
return FFI_TYPE_SMALL_STRUCT6;
else if (sz == 7)
return FFI_TYPE_SMALL_STRUCT7;
else if (sz <= 8)
return FFI_TYPE_SMALL_STRUCT8;
else
return FFI_TYPE_STRUCT; /* else, we pass it by pointer. */
}
/* PA has a downward growing stack, which looks like this:
Offset
[ Variable args ]
SP = (4*(n+9)) arg word N
...
SP-52 arg word 4
[ Fixed args ]
SP-48 arg word 3
SP-44 arg word 2
SP-40 arg word 1
SP-36 arg word 0
[ Frame marker ]
...
SP-20 RP
SP-4 previous SP
The first four argument words on the stack are reserved for use by
the callee. Instead, the general and floating registers replace
the first four argument slots. Non FP arguments are passed solely
in the general registers. FP arguments are passed in both general
and floating registers when using libffi.
Non-FP 32-bit args are passed in gr26, gr25, gr24 and gr23.
Non-FP 64-bit args are passed in register pairs, starting
on an odd numbered register (i.e. r25+r26 and r23+r24).
FP 32-bit arguments are passed in fr4L, fr5L, fr6L and fr7L.
FP 64-bit arguments are passed in fr5 and fr7.
The registers are allocated in the same manner as stack slots.
This allows the callee to save its arguments on the stack if
necessary:
arg word 3 -> gr23 or fr7L
arg word 2 -> gr24 or fr6L or fr7R
arg word 1 -> gr25 or fr5L
arg word 0 -> gr26 or fr4L or fr5R
Note that fr4R and fr6R are never used for arguments (i.e.,
doubles are not passed in fr4 or fr6).
The rest of the arguments are passed on the stack starting at SP-52,
but 64-bit arguments need to be aligned to an 8-byte boundary
This means we can have holes either in the register allocation,
or in the stack. */
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments
The following code will put everything into the stack frame
(which was allocated by the asm routine), and on return
the asm routine will load the arguments that should be
passed by register into the appropriate registers
NOTE: We load floating point args in this function... that means we
assume gcc will not mess with fp regs in here. */
void ffi_prep_args_pa32(UINT32 *stack, extended_cif *ecif, unsigned bytes)
{
register unsigned int i;
register ffi_type **p_arg;
register void **p_argv;
unsigned int slot = FIRST_ARG_SLOT;
char *dest_cpy;
size_t len;
debug(1, "%s: stack = %p, ecif = %p, bytes = %u\n", __FUNCTION__, stack,
ecif, bytes);
p_arg = ecif->cif->arg_types;
p_argv = ecif->avalue;
for (i = 0; i < ecif->cif->nargs; i++)
{
int type = (*p_arg)->type;
switch (type)
{
case FFI_TYPE_SINT8:
*(SINT32 *)(stack - slot) = *(SINT8 *)(*p_argv);
break;
case FFI_TYPE_UINT8:
*(UINT32 *)(stack - slot) = *(UINT8 *)(*p_argv);
break;
case FFI_TYPE_SINT16:
*(SINT32 *)(stack - slot) = *(SINT16 *)(*p_argv);
break;
case FFI_TYPE_UINT16:
*(UINT32 *)(stack - slot) = *(UINT16 *)(*p_argv);
break;
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
case FFI_TYPE_POINTER:
debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv),
slot);
*(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
/* Align slot for 64-bit type. */
slot += (slot & 1) ? 1 : 2;
*(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
break;
case FFI_TYPE_FLOAT:
/* First 4 args go in fr4L - fr7L. */
debug(3, "Storing UINT32(float) in slot %u\n", slot);
*(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
switch (slot - FIRST_ARG_SLOT)
{
/* First 4 args go in fr4L - fr7L. */
case 0: fldw(stack - slot, fr4); break;
case 1: fldw(stack - slot, fr5); break;
case 2: fldw(stack - slot, fr6); break;
case 3: fldw(stack - slot, fr7); break;
}
break;
case FFI_TYPE_DOUBLE:
/* Align slot for 64-bit type. */
slot += (slot & 1) ? 1 : 2;
debug(3, "Storing UINT64(double) at slot %u\n", slot);
*(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
switch (slot - FIRST_ARG_SLOT)
{
/* First 2 args go in fr5, fr7. */
case 1: fldd(stack - slot, fr5); break;
case 3: fldd(stack - slot, fr7); break;
}
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
/* Long doubles are passed in the same manner as structures
larger than 8 bytes. */
*(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
break;
#endif
case FFI_TYPE_STRUCT:
/* Structs smaller or equal than 4 bytes are passed in one
register. Structs smaller or equal 8 bytes are passed in two
registers. Larger structures are passed by pointer. */
len = (*p_arg)->size;
if (len <= 4)
{
dest_cpy = (char *)(stack - slot) + 4 - len;
memcpy(dest_cpy, (char *)*p_argv, len);
}
else if (len <= 8)
{
slot += (slot & 1) ? 1 : 2;
dest_cpy = (char *)(stack - slot) + 8 - len;
memcpy(dest_cpy, (char *)*p_argv, len);
}
else
*(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
break;
default:
FFI_ASSERT(0);
}
slot++;
p_arg++;
p_argv++;
}
/* Make sure we didn't mess up and scribble on the stack. */
{
unsigned int n;
debug(5, "Stack setup:\n");
for (n = 0; n < (bytes + 3) / 4; n++)
{
if ((n%4) == 0) { debug(5, "\n%08x: ", (unsigned int)(stack - n)); }
debug(5, "%08x ", *(stack - n));
}
debug(5, "\n");
}
FFI_ASSERT(slot * 4 <= bytes);
return;
}
static void ffi_size_stack_pa32(ffi_cif *cif)
{
ffi_type **ptr;
int i;
int z = 0; /* # stack slots */
for (ptr = cif->arg_types, i = 0; i < cif->nargs; ptr++, i++)
{
int type = (*ptr)->type;
switch (type)
{
case FFI_TYPE_DOUBLE:
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
z += 2 + (z & 1); /* must start on even regs, so we may waste one */
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
#endif
case FFI_TYPE_STRUCT:
z += 1; /* pass by ptr, callee will copy */
break;
default: /* <= 32-bit values */
z++;
}
}
/* We can fit up to 6 args in the default 64-byte stack frame,
if we need more, we need more stack. */
if (z <= 6)
cif->bytes = MIN_STACK_SIZE; /* min stack size */
else
cif->bytes = 64 + ROUND_UP((z - 6) * sizeof(UINT32), MIN_STACK_SIZE);
debug(3, "Calculated stack size is %u bytes\n", cif->bytes);
}
/* Perform machine dependent cif processing. */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
/* Set the return type flag */
switch (cif->rtype->type)
{
case FFI_TYPE_VOID:
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
cif->flags = (unsigned) cif->rtype->type;
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
/* Long doubles are treated like a structure. */
cif->flags = FFI_TYPE_STRUCT;
break;
#endif
case FFI_TYPE_STRUCT:
/* For the return type we have to check the size of the structures.
If the size is smaller or equal 4 bytes, the result is given back
in one register. If the size is smaller or equal 8 bytes than we
return the result in two registers. But if the size is bigger than
8 bytes, we work with pointers. */
cif->flags = ffi_struct_type(cif->rtype);
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
cif->flags = FFI_TYPE_UINT64;
break;
default:
cif->flags = FFI_TYPE_INT;
break;
}
/* Lucky us, because of the unique PA ABI we get to do our
own stack sizing. */
switch (cif->abi)
{
case FFI_PA32:
ffi_size_stack_pa32(cif);
break;
default:
FFI_ASSERT(0);
break;
}
return FFI_OK;
}
extern void ffi_call_pa32(void (*)(UINT32 *, extended_cif *, unsigned),
extended_cif *, unsigned, unsigned, unsigned *,
void (*fn)(void));
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, 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
#ifdef PA_HPUX
&& (cif->rtype->type == FFI_TYPE_STRUCT
|| cif->rtype->type == FFI_TYPE_LONGDOUBLE))
#else
&& cif->rtype->type == FFI_TYPE_STRUCT)
#endif
{
ecif.rvalue = alloca(cif->rtype->size);
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_PA32:
debug(3, "Calling ffi_call_pa32: ecif=%p, bytes=%u, flags=%u, rvalue=%p, fn=%p\n", &ecif, cif->bytes, cif->flags, ecif.rvalue, (void *)fn);
ffi_call_pa32(ffi_prep_args_pa32, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
break;
default:
FFI_ASSERT(0);
break;
}
}
#if FFI_CLOSURES
/* This is more-or-less an inverse of ffi_call -- we have arguments on
the stack, and we need to fill them into a cif structure and invoke
the user function. This really ought to be in asm to make sure
the compiler doesn't do things we don't expect. */
ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
{
ffi_cif *cif;
void **avalue;
void *rvalue;
UINT32 ret[2]; /* function can return up to 64-bits in registers */
ffi_type **p_arg;
char *tmp;
int i, avn;
unsigned int slot = FIRST_ARG_SLOT;
register UINT32 r28 asm("r28");
cif = closure->cif;
/* If returning via structure, callee will write to our pointer. */
if (cif->flags == FFI_TYPE_STRUCT)
rvalue = (void *)r28;
else
rvalue = &ret[0];
avalue = (void **)alloca(cif->nargs * FFI_SIZEOF_ARG);
avn = cif->nargs;
p_arg = cif->arg_types;
for (i = 0; i < avn; i++)
{
int type = (*p_arg)->type;
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:
case FFI_TYPE_POINTER:
avalue[i] = (char *)(stack - slot) + sizeof(UINT32) - (*p_arg)->size;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
slot += (slot & 1) ? 1 : 2;
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_FLOAT:
#ifdef PA_LINUX
/* The closure call is indirect. In Linux, floating point
arguments in indirect calls with a prototype are passed
in the floating point registers instead of the general
registers. So, we need to replace what was previously
stored in the current slot with the value in the
corresponding floating point register. */
switch (slot - FIRST_ARG_SLOT)
{
case 0: fstw(fr4, (void *)(stack - slot)); break;
case 1: fstw(fr5, (void *)(stack - slot)); break;
case 2: fstw(fr6, (void *)(stack - slot)); break;
case 3: fstw(fr7, (void *)(stack - slot)); break;
}
#endif
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_DOUBLE:
slot += (slot & 1) ? 1 : 2;
#ifdef PA_LINUX
/* See previous comment for FFI_TYPE_FLOAT. */
switch (slot - FIRST_ARG_SLOT)
{
case 1: fstd(fr5, (void *)(stack - slot)); break;
case 3: fstd(fr7, (void *)(stack - slot)); break;
}
#endif
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_STRUCT:
/* Structs smaller or equal than 4 bytes are passed in one
register. Structs smaller or equal 8 bytes are passed in two
registers. Larger structures are passed by pointer. */
if((*p_arg)->size <= 4)
{
avalue[i] = (void *)(stack - slot) + sizeof(UINT32) -
(*p_arg)->size;
}
else if ((*p_arg)->size <= 8)
{
slot += (slot & 1) ? 1 : 2;
avalue[i] = (void *)(stack - slot) + sizeof(UINT64) -
(*p_arg)->size;
}
else
avalue[i] = (void *) *(stack - slot);
break;
default:
FFI_ASSERT(0);
}
slot++;
p_arg++;
}
/* Invoke the closure. */
(closure->fun) (cif, rvalue, avalue, closure->user_data);
debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0],
ret[1]);
/* Store the result using the lower 2 bytes of the flags. */
switch (cif->flags)
{
case FFI_TYPE_UINT8:
*(stack - FIRST_ARG_SLOT) = (UINT8)(ret[0] >> 24);
break;
case FFI_TYPE_SINT8:
*(stack - FIRST_ARG_SLOT) = (SINT8)(ret[0] >> 24);
break;
case FFI_TYPE_UINT16:
*(stack - FIRST_ARG_SLOT) = (UINT16)(ret[0] >> 16);
break;
case FFI_TYPE_SINT16:
*(stack - FIRST_ARG_SLOT) = (SINT16)(ret[0] >> 16);
break;
case FFI_TYPE_INT:
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
*(stack - FIRST_ARG_SLOT) = ret[0];
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
*(stack - FIRST_ARG_SLOT) = ret[0];
*(stack - FIRST_ARG_SLOT - 1) = ret[1];
break;
case FFI_TYPE_DOUBLE:
fldd(rvalue, fr4);
break;
case FFI_TYPE_FLOAT:
fldw(rvalue, fr4);
break;
case FFI_TYPE_STRUCT:
/* Don't need a return value, done by caller. */
break;
case FFI_TYPE_SMALL_STRUCT2:
case FFI_TYPE_SMALL_STRUCT3:
case FFI_TYPE_SMALL_STRUCT4:
tmp = (void*)(stack - FIRST_ARG_SLOT);
tmp += 4 - cif->rtype->size;
memcpy((void*)tmp, &ret[0], cif->rtype->size);
break;
case FFI_TYPE_SMALL_STRUCT5:
case FFI_TYPE_SMALL_STRUCT6:
case FFI_TYPE_SMALL_STRUCT7:
case FFI_TYPE_SMALL_STRUCT8:
{
unsigned int ret2[2];
int off;
/* Right justify ret[0] and ret[1] */
switch (cif->flags)
{
case FFI_TYPE_SMALL_STRUCT5: off = 3; break;
case FFI_TYPE_SMALL_STRUCT6: off = 2; break;
case FFI_TYPE_SMALL_STRUCT7: off = 1; break;
default: off = 0; break;
}
memset (ret2, 0, sizeof (ret2));
memcpy ((char *)ret2 + off, ret, 8 - off);
*(stack - FIRST_ARG_SLOT) = ret2[0];
*(stack - FIRST_ARG_SLOT - 1) = ret2[1];
}
break;
case FFI_TYPE_POINTER:
case FFI_TYPE_VOID:
break;
default:
debug(0, "assert with cif->flags: %d\n",cif->flags);
FFI_ASSERT(0);
break;
}
return FFI_OK;
}
/* Fill in a closure to refer to the specified fun and user_data.
cif specifies the argument and result types for fun.
The cif must already be prep'ed. */
extern void ffi_closure_pa32(void);
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data,
void *codeloc)
{
UINT32 *tramp = (UINT32 *)(closure->tramp);
#ifdef PA_HPUX
UINT32 *tmp;
#endif
FFI_ASSERT (cif->abi == FFI_PA32);
/* Make a small trampoline that will branch to our
handler function. Use PC-relative addressing. */
#ifdef PA_LINUX
tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
tramp[2] = 0x4aa10028; /* ldw 20(%r21),%r1 ; load plabel */
tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
tramp[5] = 0xeac0c000; /* bv%r0(%r22) ; branch to handler */
tramp[6] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
tramp[7] = ((UINT32)(ffi_closure_pa32) & ~2);
/* Flush d/icache -- have to flush up 2 two lines because of
alignment. */
__asm__ volatile(
"fdc 0(%0)\n\t"
"fdc %1(%0)\n\t"
"fic 0(%%sr4, %0)\n\t"
"fic %1(%%sr4, %0)\n\t"
"sync\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n"
:
: "r"((unsigned long)tramp & ~31),
"r"(32 /* stride */)
: "memory");
#endif
#ifdef PA_HPUX
tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
tramp[2] = 0x4aa10038; /* ldw 28(%r21),%r1 ; load plabel */
tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
tramp[5] = 0x02c010b4; /* ldsid (%r22),%r20 ; load space id */
tramp[6] = 0x00141820; /* mtsp %r20,%sr0 ; into %sr0 */
tramp[7] = 0xe2c00000; /* be 0(%sr0,%r22) ; branch to handler */
tramp[8] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
tramp[9] = ((UINT32)(ffi_closure_pa32) & ~2);
/* Flush d/icache -- have to flush three lines because of alignment. */
__asm__ volatile(
"copy %1,%0\n\t"
"fdc,m %2(%0)\n\t"
"fdc,m %2(%0)\n\t"
"fdc,m %2(%0)\n\t"
"ldsid (%1),%0\n\t"
"mtsp %0,%%sr0\n\t"
"copy %1,%0\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"sync\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n"
: "=&r" ((unsigned long)tmp)
: "r" ((unsigned long)tramp & ~31),
"r" (32/* stride */)
: "memory");
#endif
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
return FFI_OK;
}
#endif

View File

@@ -0,0 +1,77 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for hppa.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
/* ---- System specific configurations ----------------------------------- */
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
#ifdef PA_LINUX
FFI_PA32,
FFI_DEFAULT_ABI = FFI_PA32,
#endif
#ifdef PA_HPUX
FFI_PA32,
FFI_DEFAULT_ABI = FFI_PA32,
#endif
#ifdef PA64_HPUX
#error "PA64_HPUX FFI is not yet implemented"
FFI_PA64,
FFI_DEFAULT_ABI = FFI_PA64,
#endif
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_NATIVE_RAW_API 0
#ifdef PA_LINUX
#define FFI_TRAMPOLINE_SIZE 32
#else
#define FFI_TRAMPOLINE_SIZE 40
#endif
#define FFI_TYPE_SMALL_STRUCT2 -1
#define FFI_TYPE_SMALL_STRUCT3 -2
#define FFI_TYPE_SMALL_STRUCT4 -3
#define FFI_TYPE_SMALL_STRUCT5 -4
#define FFI_TYPE_SMALL_STRUCT6 -5
#define FFI_TYPE_SMALL_STRUCT7 -6
#define FFI_TYPE_SMALL_STRUCT8 -7
#endif

View File

@@ -0,0 +1,368 @@
/* -----------------------------------------------------------------------
hpux32.S - Copyright (c) 2006 Free Software Foundation, Inc.
(c) 2008 Red Hat, Inc.
based on src/pa/linux.S
HP-UX PA 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 THE AUTHOR 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 <fficonfig.h>
#include <ffi.h>
.LEVEL 1.1
.SPACE $PRIVATE$
.IMPORT $global$,DATA
.IMPORT $$dyncall,MILLICODE
.SUBSPA $DATA$
.align 4
/* void ffi_call_pa32(void (*)(char *, extended_cif *),
extended_cif *ecif,
unsigned bytes,
unsigned flags,
unsigned *rvalue,
void (*fn)(void));
*/
.export ffi_call_pa32,ENTRY,PRIV_LEV=3
.import ffi_prep_args_pa32,CODE
.SPACE $TEXT$
.SUBSPA $CODE$
.align 4
L$FB1
ffi_call_pa32
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
.entry
stw %rp, -20(%sp)
copy %r3, %r1
L$CFI11
copy %sp, %r3
L$CFI12
/* Setup the stack for calling prep_args...
We want the stack to look like this:
[ Previous stack ] <- %r3
[ 64-bytes register save area ] <- %r4
[ Stack space for actual call, passed as ] <- %arg0
[ arg0 to ffi_prep_args_pa32 ]
[ Stack for calling prep_args ] <- %sp
*/
stwm %r1, 64(%sp)
stw %r4, 12(%r3)
L$CFI13
copy %sp, %r4
addl %arg2, %r4, %arg0 ; arg stack
stw %arg3, -48(%r3) ; save flags we need it later
/* Call prep_args:
%arg0(stack) -- set up above
%arg1(ecif) -- same as incoming param
%arg2(bytes) -- same as incoming param */
bl ffi_prep_args_pa32,%r2
ldo 64(%arg0), %sp
ldo -64(%sp), %sp
/* now %sp should point where %arg0 was pointing. */
/* Load the arguments that should be passed in registers
The fp args are loaded by the prep_args function. */
ldw -36(%sp), %arg0
ldw -40(%sp), %arg1
ldw -44(%sp), %arg2
ldw -48(%sp), %arg3
/* in case the function is going to return a structure
we need to give it a place to put the result. */
ldw -52(%r3), %ret0 ; %ret0 <- rvalue
ldw -56(%r3), %r22 ; %r22 <- function to call
bl $$dyncall, %r31 ; Call the user function
copy %r31, %rp
/* Prepare to store the result; we need to recover flags and rvalue. */
ldw -48(%r3), %r21 ; r21 <- flags
ldw -52(%r3), %r20 ; r20 <- rvalue
/* Store the result according to the return type. The most
likely types should come first. */
L$checkint
comib,<>,n FFI_TYPE_INT, %r21, L$checkint8
b L$done
stw %ret0, 0(%r20)
L$checkint8
comib,<>,n FFI_TYPE_UINT8, %r21, L$checkint16
b L$done
stb %ret0, 0(%r20)
L$checkint16
comib,<>,n FFI_TYPE_UINT16, %r21, L$checkdbl
b L$done
sth %ret0, 0(%r20)
L$checkdbl
comib,<>,n FFI_TYPE_DOUBLE, %r21, L$checkfloat
b L$done
fstd %fr4,0(%r20)
L$checkfloat
comib,<>,n FFI_TYPE_FLOAT, %r21, L$checkll
b L$done
fstw %fr4L,0(%r20)
L$checkll
comib,<>,n FFI_TYPE_UINT64, %r21, L$checksmst2
stw %ret0, 0(%r20)
b L$done
stw %ret1, 4(%r20)
L$checksmst2
comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, L$checksmst3
/* 2-byte structs are returned in ret0 as ????xxyy. */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret0, 0(%r20)
L$checksmst3
comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, L$checksmst4
/* 3-byte structs are returned in ret0 as ??xxyyzz. */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret0, 0(%r20)
L$checksmst4
comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, L$checksmst5
/* 4-byte structs are returned in ret0 as wwxxyyzz. */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret0, 0(%r20)
L$checksmst5
comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, L$checksmst6
/* 5 byte values are returned right justified:
ret0 ret1
5: ??????aa bbccddee */
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret1, 0(%r20)
L$checksmst6
comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, L$checksmst7
/* 6 byte values are returned right justified:
ret0 ret1
6: ????aabb ccddeeff */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret1, 0(%r20)
L$checksmst7
comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, L$checksmst8
/* 7 byte values are returned right justified:
ret0 ret1
7: ??aabbcc ddeeffgg */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b L$done
stb %ret1, 0(%r20)
L$checksmst8
comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, L$done
/* 8 byte values are returned right justified:
ret0 ret1
8: aabbccdd eeffgghh */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stb %ret1, 0(%r20)
L$done
/* all done, return */
copy %r4, %sp ; pop arg stack
ldw 12(%r3), %r4
ldwm -64(%sp), %r3 ; .. and pop stack
ldw -20(%sp), %rp
bv %r0(%rp)
nop
.exit
.procend
L$FE1
/* void ffi_closure_pa32(void);
Called with closure argument in %r21 */
.SPACE $TEXT$
.SUBSPA $CODE$
.export ffi_closure_pa32,ENTRY,PRIV_LEV=3,RTNVAL=GR
.import ffi_closure_inner_pa32,CODE
.align 4
L$FB2
ffi_closure_pa32
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
.entry
stw %rp, -20(%sp)
copy %r3, %r1
L$CFI21
copy %sp, %r3
L$CFI22
stwm %r1, 64(%sp)
/* Put arguments onto the stack and call ffi_closure_inner. */
stw %arg0, -36(%r3)
stw %arg1, -40(%r3)
stw %arg2, -44(%r3)
stw %arg3, -48(%r3)
copy %r21, %arg0
bl ffi_closure_inner_pa32, %r2
copy %r3, %arg1
ldwm -64(%sp), %r3
ldw -20(%sp), %rp
ldw -36(%sp), %ret0
bv %r0(%rp)
ldw -40(%sp), %ret1
.exit
.procend
L$FE2:
.SPACE $PRIVATE$
.SUBSPA $DATA$
.align 4
.EXPORT _GLOBAL__F_ffi_call_pa32,DATA
_GLOBAL__F_ffi_call_pa32
L$frame1:
.word L$ECIE1-L$SCIE1 ;# Length of Common Information Entry
L$SCIE1:
.word 0x0 ;# CIE Identifier Tag
.byte 0x1 ;# CIE Version
.ascii "\0" ;# CIE Augmentation
.uleb128 0x1 ;# CIE Code Alignment Factor
.sleb128 4 ;# CIE Data Alignment Factor
.byte 0x2 ;# CIE RA Column
.byte 0xc ;# DW_CFA_def_cfa
.uleb128 0x1e
.uleb128 0x0
.align 4
L$ECIE1:
L$SFDE1:
.word L$EFDE1-L$ASFDE1 ;# FDE Length
L$ASFDE1:
.word L$ASFDE1-L$frame1 ;# FDE CIE offset
.word L$FB1 ;# FDE initial location
.word L$FE1-L$FB1 ;# FDE address range
.byte 0x4 ;# DW_CFA_advance_loc4
.word L$CFI11-L$FB1
.byte 0x83 ;# DW_CFA_offset, column 0x3
.uleb128 0x0
.byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20]
.uleb128 0x2
.sleb128 -5
.byte 0x4 ;# DW_CFA_advance_loc4
.word L$CFI12-L$CFI11
.byte 0xd ;# DW_CFA_def_cfa_register = r3
.uleb128 0x3
.byte 0x4 ;# DW_CFA_advance_loc4
.word L$CFI13-L$CFI12
.byte 0x84 ;# DW_CFA_offset, column 0x4
.uleb128 0x3
.align 4
L$EFDE1:
L$SFDE2:
.word L$EFDE2-L$ASFDE2 ;# FDE Length
L$ASFDE2:
.word L$ASFDE2-L$frame1 ;# FDE CIE offset
.word L$FB2 ;# FDE initial location
.word L$FE2-L$FB2 ;# FDE address range
.byte 0x4 ;# DW_CFA_advance_loc4
.word L$CFI21-L$FB2
.byte 0x83 ;# DW_CFA_offset, column 0x3
.uleb128 0x0
.byte 0x11 ;# DW_CFA_offset_extended_sf
.uleb128 0x2
.sleb128 -5
.byte 0x4 ;# DW_CFA_advance_loc4
.word L$CFI22-L$CFI21
.byte 0xd ;# DW_CFA_def_cfa_register = r3
.uleb128 0x3
.align 4
L$EFDE2:

View File

@@ -0,0 +1,357 @@
/* -----------------------------------------------------------------------
linux.S - (c) 2003-2004 Randolph Chung <tausq@debian.org>
(c) 2008 Red Hat, Inc.
HPPA 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 RENESAS TECHNOLOGY 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 <fficonfig.h>
#include <ffi.h>
.text
.level 1.1
.align 4
/* void ffi_call_pa32(void (*)(char *, extended_cif *),
extended_cif *ecif,
unsigned bytes,
unsigned flags,
unsigned *rvalue,
void (*fn)(void));
*/
.export ffi_call_pa32,code
.import ffi_prep_args_pa32,code
.type ffi_call_pa32, @function
.LFB1:
ffi_call_pa32:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
.entry
stw %rp, -20(%sp)
copy %r3, %r1
.LCFI11:
copy %sp, %r3
.LCFI12:
/* Setup the stack for calling prep_args...
We want the stack to look like this:
[ Previous stack ] <- %r3
[ 64-bytes register save area ] <- %r4
[ Stack space for actual call, passed as ] <- %arg0
[ arg0 to ffi_prep_args_pa32 ]
[ Stack for calling prep_args ] <- %sp
*/
stwm %r1, 64(%sp)
stw %r4, 12(%r3)
.LCFI13:
copy %sp, %r4
addl %arg2, %r4, %arg0 /* arg stack */
stw %arg3, -48(%r3) /* save flags; we need it later */
/* Call prep_args:
%arg0(stack) -- set up above
%arg1(ecif) -- same as incoming param
%arg2(bytes) -- same as incoming param */
bl ffi_prep_args_pa32,%r2
ldo 64(%arg0), %sp
ldo -64(%sp), %sp
/* now %sp should point where %arg0 was pointing. */
/* Load the arguments that should be passed in registers
The fp args were loaded by the prep_args function. */
ldw -36(%sp), %arg0
ldw -40(%sp), %arg1
ldw -44(%sp), %arg2
ldw -48(%sp), %arg3
/* in case the function is going to return a structure
we need to give it a place to put the result. */
ldw -52(%r3), %ret0 /* %ret0 <- rvalue */
ldw -56(%r3), %r22 /* %r22 <- function to call */
bl $$dyncall, %r31 /* Call the user function */
copy %r31, %rp
/* Prepare to store the result; we need to recover flags and rvalue. */
ldw -48(%r3), %r21 /* r21 <- flags */
ldw -52(%r3), %r20 /* r20 <- rvalue */
/* Store the result according to the return type. */
.Lcheckint:
comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
b .Ldone
stw %ret0, 0(%r20)
.Lcheckint8:
comib,<>,n FFI_TYPE_UINT8, %r21, .Lcheckint16
b .Ldone
stb %ret0, 0(%r20)
.Lcheckint16:
comib,<>,n FFI_TYPE_UINT16, %r21, .Lcheckdbl
b .Ldone
sth %ret0, 0(%r20)
.Lcheckdbl:
comib,<>,n FFI_TYPE_DOUBLE, %r21, .Lcheckfloat
b .Ldone
fstd %fr4,0(%r20)
.Lcheckfloat:
comib,<>,n FFI_TYPE_FLOAT, %r21, .Lcheckll
b .Ldone
fstw %fr4L,0(%r20)
.Lcheckll:
comib,<>,n FFI_TYPE_UINT64, %r21, .Lchecksmst2
stw %ret0, 0(%r20)
b .Ldone
stw %ret1, 4(%r20)
.Lchecksmst2:
comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, .Lchecksmst3
/* 2-byte structs are returned in ret0 as ????xxyy. */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst3:
comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, .Lchecksmst4
/* 3-byte structs are returned in ret0 as ??xxyyzz. */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst4:
comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, .Lchecksmst5
/* 4-byte structs are returned in ret0 as wwxxyyzz. */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst5:
comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, .Lchecksmst6
/* 5 byte values are returned right justified:
ret0 ret1
5: ??????aa bbccddee */
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
.Lchecksmst6:
comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, .Lchecksmst7
/* 6 byte values are returned right justified:
ret0 ret1
6: ????aabb ccddeeff */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
.Lchecksmst7:
comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, .Lchecksmst8
/* 7 byte values are returned right justified:
ret0 ret1
7: ??aabbcc ddeeffgg */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
.Lchecksmst8:
comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
/* 8 byte values are returned right justified:
ret0 ret1
8: aabbccdd eeffgghh */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stb %ret1, 0(%r20)
.Ldone:
/* all done, return */
copy %r4, %sp /* pop arg stack */
ldw 12(%r3), %r4
ldwm -64(%sp), %r3 /* .. and pop stack */
ldw -20(%sp), %rp
bv %r0(%rp)
nop
.exit
.procend
.LFE1:
/* void ffi_closure_pa32(void);
Called with closure argument in %r21 */
.export ffi_closure_pa32,code
.import ffi_closure_inner_pa32,code
.type ffi_closure_pa32, @function
.LFB2:
ffi_closure_pa32:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
.entry
stw %rp, -20(%sp)
.LCFI20:
copy %r3, %r1
.LCFI21:
copy %sp, %r3
.LCFI22:
stwm %r1, 64(%sp)
/* Put arguments onto the stack and call ffi_closure_inner. */
stw %arg0, -36(%r3)
stw %arg1, -40(%r3)
stw %arg2, -44(%r3)
stw %arg3, -48(%r3)
copy %r21, %arg0
bl ffi_closure_inner_pa32, %r2
copy %r3, %arg1
ldwm -64(%sp), %r3
ldw -20(%sp), %rp
ldw -36(%sp), %ret0
bv %r0(%r2)
ldw -40(%sp), %ret1
.exit
.procend
.LFE2:
.section ".eh_frame",EH_FRAME_FLAGS,@progbits
.Lframe1:
.word .LECIE1-.LSCIE1 ;# Length of Common Information Entry
.LSCIE1:
.word 0x0 ;# CIE Identifier Tag
.byte 0x1 ;# CIE Version
.ascii "\0" ;# CIE Augmentation
.uleb128 0x1 ;# CIE Code Alignment Factor
.sleb128 4 ;# CIE Data Alignment Factor
.byte 0x2 ;# CIE RA Column
.byte 0xc ;# DW_CFA_def_cfa
.uleb128 0x1e
.uleb128 0x0
.align 4
.LECIE1:
.LSFDE1:
.word .LEFDE1-.LASFDE1 ;# FDE Length
.LASFDE1:
.word .LASFDE1-.Lframe1 ;# FDE CIE offset
.word .LFB1 ;# FDE initial location
.word .LFE1-.LFB1 ;# FDE address range
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI11-.LFB1
.byte 0x83 ;# DW_CFA_offset, column 0x3
.uleb128 0x0
.byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20]
.uleb128 0x2
.sleb128 -5
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI12-.LCFI11
.byte 0xd ;# DW_CFA_def_cfa_register = r3
.uleb128 0x3
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI13-.LCFI12
.byte 0x84 ;# DW_CFA_offset, column 0x4
.uleb128 0x3
.align 4
.LEFDE1:
.LSFDE2:
.word .LEFDE2-.LASFDE2 ;# FDE Length
.LASFDE2:
.word .LASFDE2-.Lframe1 ;# FDE CIE offset
.word .LFB2 ;# FDE initial location
.word .LFE2-.LFB2 ;# FDE address range
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI21-.LFB2
.byte 0x83 ;# DW_CFA_offset, column 0x3
.uleb128 0x0
.byte 0x11 ;# DW_CFA_offset_extended_sf
.uleb128 0x2
.sleb128 -5
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI22-.LCFI21
.byte 0xd ;# DW_CFA_def_cfa_register = r3
.uleb128 0x3
.align 4
.LEFDE2:

View File

@@ -0,0 +1,225 @@
/* -----------------------------------------------------------------------
aix.S - Copyright (c) 2002 Free Software Foundation, Inc.
based on darwin.S by John Hornkvist
PowerPC Assembly glue.
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 THE AUTHOR 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.
----------------------------------------------------------------------- */
.set r0,0
.set r1,1
.set r2,2
.set r3,3
.set r4,4
.set r5,5
.set r6,6
.set r7,7
.set r8,8
.set r9,9
.set r10,10
.set r11,11
.set r12,12
.set r13,13
.set r14,14
.set r15,15
.set r16,16
.set r17,17
.set r18,18
.set r19,19
.set r20,20
.set r21,21
.set r22,22
.set r23,23
.set r24,24
.set r25,25
.set r26,26
.set r27,27
.set r28,28
.set r29,29
.set r30,30
.set r31,31
.set f0,0
.set f1,1
.set f2,2
.set f3,3
.set f4,4
.set f5,5
.set f6,6
.set f7,7
.set f8,8
.set f9,9
.set f10,10
.set f11,11
.set f12,12
.set f13,13
.set f14,14
.set f15,15
.set f16,16
.set f17,17
.set f18,18
.set f19,19
.set f20,20
.set f21,21
#define LIBFFI_ASM
#include <fficonfig.h>
#include <ffi.h>
#define JUMPTARGET(name) name
#define L(x) x
.file "aix.S"
.toc
.csect .text[PR]
.align 2
.globl ffi_prep_args
.csect .text[PR]
.align 2
.globl ffi_call_AIX
.globl .ffi_call_AIX
.csect ffi_call_AIX[DS]
ffi_call_AIX:
.long .ffi_call_AIX, TOC[tc0], 0
.csect .text[PR]
.ffi_call_AIX:
mr r12,r8 // We only need r12 until the call, so it doesn't have to be saved...
/* Save the old stack pointer as AP. */
mr r8,r1
/* Allocate the stack space we need. */
stwux r1,r1,r4
/* Save registers we use. */
mflr r9
stw r28,-16(r8)
stw r29,-12(r8)
stw r30, -8(r8)
stw r31, -4(r8)
stw r9, 8(r8)
stw r2, 20(r1)
/* Save arguments over call... */
mr r31,r5 /* flags, */
mr r30,r6 /* rvalue, */
mr r29,r7 /* function address, */
mr r28,r8 /* our AP. */
/* Call ffi_prep_args. */
mr r4,r1
li r9,0
lwz r2,4(r12)
lwz r12,0(r12)
mtctr r12 // r12 holds address of _ffi_prep_args
bctrl
lwz r2,20(r1)
/* Now do the call. */
lwz r12,0(r29)
/* Set up cr1 with bits 4-7 of the flags. */
mtcrf 0x40,r31
stw r2,20(r1)
mtctr r12
lwz r2,4(r29)
/* Load all those argument registers. */
// We have set up a nice stack frame, just load it into registers.
lwz r3, 20+(1*4)(r1)
lwz r4, 20+(2*4)(r1)
lwz r5, 20+(3*4)(r1)
lwz r6, 20+(4*4)(r1)
nop
lwz r7, 20+(5*4)(r1)
lwz r8, 20+(6*4)(r1)
lwz r9, 20+(7*4)(r1)
lwz r10,20+(8*4)(r1)
L1:
/* Load all the FP registers. */
bf 6,L2 // 2f + 0x18
lfd f1,-16-(13*8)(r28)
lfd f2,-16-(12*8)(r28)
lfd f3,-16-(11*8)(r28)
lfd f4,-16-(10*8)(r28)
nop
lfd f5,-16-(9*8)(r28)
lfd f6,-16-(8*8)(r28)
lfd f7,-16-(7*8)(r28)
lfd f8,-16-(6*8)(r28)
nop
lfd f9,-16-(5*8)(r28)
lfd f10,-16-(4*8)(r28)
lfd f11,-16-(3*8)(r28)
lfd f12,-16-(2*8)(r28)
nop
lfd f13,-16-(1*8)(r28)
L2:
/* Make the call. */
bctrl
lwz r2,20(r1)
/* Now, deal with the return value. */
mtcrf 0x01,r31
bt 30,L(done_return_value)
bt 29,L(fp_return_value)
stw r3,0(r30)
bf 28,L(done_return_value)
stw r4,4(r30)
/* Fall through... */
L(done_return_value):
/* Restore the registers we used and return. */
lwz r9, 8(r28)
lwz r31, -4(r28)
mtlr r9
lwz r30, -8(r28)
lwz r29,-12(r28)
lwz r28,-16(r28)
lwz r1,0(r1)
blr
L(fp_return_value):
bf 28,L(float_return_value)
stfd f1,0(r30)
b L(done_return_value)
L(float_return_value):
stfs f1,0(r30)
b L(done_return_value)
.long 0
.byte 0,0,0,1,128,4,0,0
//END(ffi_call_AIX)
.csect .text[PR]
.align 2
.globl ffi_call_DARWIN
.globl .ffi_call_DARWIN
.csect ffi_call_DARWIN[DS]
ffi_call_DARWIN:
.long .ffi_call_DARWIN, TOC[tc0], 0
.csect .text[PR]
.ffi_call_DARWIN:
blr
.long 0
.byte 0,0,0,0,0,0,0,0
//END(ffi_call_DARWIN)

View File

@@ -0,0 +1,247 @@
/* -----------------------------------------------------------------------
aix_closure.S - Copyright (c) 2002 2003 Free Software Foundation, Inc.
based on darwin_closure.S
PowerPC Assembly glue.
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 THE AUTHOR 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.
----------------------------------------------------------------------- */
.set r0,0
.set r1,1
.set r2,2
.set r3,3
.set r4,4
.set r5,5
.set r6,6
.set r7,7
.set r8,8
.set r9,9
.set r10,10
.set r11,11
.set r12,12
.set r13,13
.set r14,14
.set r15,15
.set r16,16
.set r17,17
.set r18,18
.set r19,19
.set r20,20
.set r21,21
.set r22,22
.set r23,23
.set r24,24
.set r25,25
.set r26,26
.set r27,27
.set r28,28
.set r29,29
.set r30,30
.set r31,31
.set f0,0
.set f1,1
.set f2,2
.set f3,3
.set f4,4
.set f5,5
.set f6,6
.set f7,7
.set f8,8
.set f9,9
.set f10,10
.set f11,11
.set f12,12
.set f13,13
.set f14,14
.set f15,15
.set f16,16
.set f17,17
.set f18,18
.set f19,19
.set f20,20
.set f21,21
#define LIBFFI_ASM
#define JUMPTARGET(name) name
#define L(x) x
.file "aix_closure.S"
.toc
LC..60:
.tc L..60[TC],L..60
.csect .text[PR]
.align 2
.csect .text[PR]
.align 2
.globl ffi_closure_ASM
.globl .ffi_closure_ASM
.csect ffi_closure_ASM[DS]
ffi_closure_ASM:
.long .ffi_closure_ASM, TOC[tc0], 0
.csect .text[PR]
.ffi_closure_ASM:
mflr r0 /* extract return address */
stw r0, 8(r1) /* save the return address */
/* 24 Bytes (Linkage Area) */
/* 32 Bytes (params) */
/* 104 Bytes (13*8 from FPR) */
/* 8 Bytes (result) */
/* 168 Bytes */
stwu r1,-176(r1) /* skip over caller save area
keep stack aligned to 16 */
/* we want to build up an area for the parameters passed */
/* in registers (both floating point and integer) */
/* we store gpr 3 to gpr 10 (aligned to 4)
in the parents outgoing area */
stw r3, 200(r1)
stw r4, 204(r1)
stw r5, 208(r1)
stw r6, 212(r1)
stw r7, 216(r1)
stw r8, 220(r1)
stw r9, 224(r1)
stw r10, 228(r1)
/* next save fpr 1 to fpr 13 (aligned to 8) */
stfd f1, 56(r1)
stfd f2, 64(r1)
stfd f3, 72(r1)
stfd f4, 80(r1)
stfd f5, 88(r1)
stfd f6, 96(r1)
stfd f7, 104(r1)
stfd f8, 112(r1)
stfd f9, 120(r1)
stfd f10, 128(r1)
stfd f11, 136(r1)
stfd f12, 144(r1)
stfd f13, 152(r1)
/* set up registers for the routine that actually does the work */
/* get the context pointer from the trampoline */
mr r3,r11
/* now load up the pointer to the result storage */
addi r4,r1,160
/* now load up the pointer to the saved gpr registers */
addi r5,r1,200
/* now load up the pointer to the saved fpr registers */
addi r6,r1,56
/* make the call */
bl .ffi_closure_helper_DARWIN
nop
/* now r3 contains the return type */
/* so use it to look up in a table */
/* so we know how to deal with each type */
/* look up the proper starting point in table */
/* by using return type as offset */
addi r5,r1,160 /* get pointer to results area */
lwz r4,LC..60(2) /* get address of jump table */
slwi r3,r3,2 /* now multiply return type by 4 */
lwzx r3,r4,r3 /* get the contents of that table value */
add r3,r3,r4 /* add contents of table to table address */
mtctr r3
bctr /* jump to it */
L..60:
.long L..44-L..60 /* FFI_TYPE_VOID */
.long L..50-L..60 /* FFI_TYPE_INT */
.long L..47-L..60 /* FFI_TYPE_FLOAT */
.long L..46-L..60 /* FFI_TYPE_DOUBLE */
.long L..46-L..60 /* FFI_TYPE_LONGDOUBLE */
.long L..56-L..60 /* FFI_TYPE_UINT8 */
.long L..55-L..60 /* FFI_TYPE_SINT8 */
.long L..58-L..60 /* FFI_TYPE_UINT16 */
.long L..57-L..60 /* FFI_TYPE_SINT16 */
.long L..50-L..60 /* FFI_TYPE_UINT32 */
.long L..50-L..60 /* FFI_TYPE_SINT32 */
.long L..48-L..60 /* FFI_TYPE_UINT64 */
.long L..48-L..60 /* FFI_TYPE_SINT64 */
.long L..44-L..60 /* FFI_TYPE_STRUCT */
.long L..50-L..60 /* FFI_TYPE_POINTER */
/* case double */
L..46:
lfd f1,0(r5)
b L..44
/* case float */
L..47:
lfs f1,0(r5)
b L..44
/* case long long */
L..48:
lwz r3,0(r5)
lwz r4,4(r5)
b L..44
/* case default / int32 / pointer */
L..50:
lwz r3,0(r5)
b L..44
/* case signed int8 */
L..55:
addi r5,r5,3
lbz r3,0(r5)
slwi r3,r3,24
srawi r3,r3,24
b L..44
/* case unsigned int8 */
L..56:
addi r5,r5,3
lbz r3,0(r5)
b L..44
/* case signed int16 */
L..57:
addi r5,r5,2
lhz r3,0(r5)
extsh r3,r3
b L..44
/* case unsigned int16 */
L..58:
addi r5,r5,2
lhz r3,0(r5)
/* case void / done */
L..44:
addi r1,r1,176 /* restore stack pointer */
lwz r0,8(r1) /* get return address */
mtlr r0 /* reset link register */
blr
/* END(ffi_closure_ASM) */

View File

@@ -0,0 +1,125 @@
/* -----------------------------------------------------------------------
asm.h - Copyright (c) 1998 Geoffrey Keating
PowerPC Assembly glue.
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 THE AUTHOR 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 ASM_GLOBAL_DIRECTIVE .globl
#define C_SYMBOL_NAME(name) name
/* Macro for a label. */
#ifdef __STDC__
#define C_LABEL(name) name##:
#else
#define C_LABEL(name) name/**/:
#endif
/* This seems to always be the case on PPC. */
#define ALIGNARG(log2) log2
/* For ELF we need the `.type' directive to make shared libs work right. */
#define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
/* If compiled for profiling, call `_mcount' at the start of each function. */
#ifdef PROF
/* The mcount code relies on a the return address being on the stack
to locate our caller and so it can restore it; so store one just
for its benefit. */
#ifdef PIC
#define CALL_MCOUNT \
.pushsection; \
.section ".data"; \
.align ALIGNARG(2); \
0:.long 0; \
.previous; \
mflr %r0; \
stw %r0,4(%r1); \
bl _GLOBAL_OFFSET_TABLE_@local-4; \
mflr %r11; \
lwz %r0,0b@got(%r11); \
bl JUMPTARGET(_mcount);
#else /* PIC */
#define CALL_MCOUNT \
.section ".data"; \
.align ALIGNARG(2); \
0:.long 0; \
.previous; \
mflr %r0; \
lis %r11,0b@ha; \
stw %r0,4(%r1); \
addi %r0,%r11,0b@l; \
bl JUMPTARGET(_mcount);
#endif /* PIC */
#else /* PROF */
#define CALL_MCOUNT /* Do nothing. */
#endif /* PROF */
#define ENTRY(name) \
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
.align ALIGNARG(2); \
C_LABEL(name) \
CALL_MCOUNT
#define EALIGN_W_0 /* No words to insert. */
#define EALIGN_W_1 nop
#define EALIGN_W_2 nop;nop
#define EALIGN_W_3 nop;nop;nop
#define EALIGN_W_4 EALIGN_W_3;nop
#define EALIGN_W_5 EALIGN_W_4;nop
#define EALIGN_W_6 EALIGN_W_5;nop
#define EALIGN_W_7 EALIGN_W_6;nop
/* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
past a 2^align boundary. */
#ifdef PROF
#define EALIGN(name, alignt, words) \
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
.align ALIGNARG(2); \
C_LABEL(name) \
CALL_MCOUNT \
b 0f; \
.align ALIGNARG(alignt); \
EALIGN_W_##words; \
0:
#else /* PROF */
#define EALIGN(name, alignt, words) \
ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
.align ALIGNARG(alignt); \
EALIGN_W_##words; \
C_LABEL(name)
#endif
#define END(name) \
ASM_SIZE_DIRECTIVE(name)
#ifdef PIC
#define JUMPTARGET(name) name##@plt
#else
#define JUMPTARGET(name) name
#endif
/* Local labels stripped out by the linker. */
#define L(x) .L##x

View File

@@ -0,0 +1,245 @@
/* -----------------------------------------------------------------------
darwin.S - Copyright (c) 2000 John Hornkvist
Copyright (c) 2004 Free Software Foundation, Inc.
PowerPC Assembly glue.
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 THE AUTHOR 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.
----------------------------------------------------------------------- */
#if defined(__ppc64__)
#define MODE_CHOICE(x, y) y
#else
#define MODE_CHOICE(x, y) x
#endif
#define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */
#define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */
#define LIBFFI_ASM
#include <fficonfig.h>
#include <ffi.h>
#define JUMPTARGET(name) name
#define L(x) x
.text
.align 2
.globl _ffi_prep_args
.text
.align 2
.globl _ffi_call_DARWIN
.text
.align 2
_ffi_call_DARWIN:
LFB0:
mr r12,r8 /* We only need r12 until the call,
so it doesn't have to be saved. */
LFB1:
/* Save the old stack pointer as AP. */
mr r8,r1
LCFI0:
/* Allocate the stack space we need. */
stwux r1,r1,r4
/* Save registers we use. */
mflr r9
stw r28,-16(r8)
stw r29,-12(r8)
stw r30,-8(r8)
stw r31,-4(r8)
stw r9,8(r8)
stw r2,20(r1)
LCFI1:
/* Save arguments over call. */
mr r31,r5 /* flags, */
mr r30,r6 /* rvalue, */
mr r29,r7 /* function address, */
mr r28,r8 /* our AP. */
LCFI2:
/* Call ffi_prep_args. */
mr r4,r1
li r9,0
mtctr r12 /* r12 holds address of _ffi_prep_args. */
bctrl
lwz r2,20(r1)
/* Now do the call.
Set up cr1 with bits 4-7 of the flags. */
mtcrf 0x40,r31
/* Get the address to call into CTR. */
mtctr r29
/* Load all those argument registers.
We have set up a nice stack frame, just load it into registers. */
lwz r3,20+(1*4)(r1)
lwz r4,20+(2*4)(r1)
lwz r5,20+(3*4)(r1)
lwz r6,20+(4*4)(r1)
nop
lwz r7,20+(5*4)(r1)
lwz r8,20+(6*4)(r1)
lwz r9,20+(7*4)(r1)
lwz r10,20+(8*4)(r1)
L1:
/* Load all the FP registers. */
bf 6,L2 /* No floats to load. */
lfd f1,-16-(13*8)(r28)
lfd f2,-16-(12*8)(r28)
lfd f3,-16-(11*8)(r28)
lfd f4,-16-(10*8)(r28)
nop
lfd f5,-16-(9*8)(r28)
lfd f6,-16-(8*8)(r28)
lfd f7,-16-(7*8)(r28)
lfd f8,-16-(6*8)(r28)
nop
lfd f9,-16-(5*8)(r28)
lfd f10,-16-(4*8)(r28)
lfd f11,-16-(3*8)(r28)
lfd f12,-16-(2*8)(r28)
nop
lfd f13,-16-(1*8)(r28)
L2:
mr r12,r29 /* Put the target address in r12 as specified. */
mtctr r12
nop
nop
/* Make the call. */
bctrl
/* Now, deal with the return value. */
mtcrf 0x01,r31
bt 30,L(done_return_value)
bt 29,L(fp_return_value)
stw r3,0(r30)
bf 28,L(done_return_value)
stw r4,4(r30)
/* Fall through. */
L(done_return_value):
/* Restore the registers we used and return. */
lwz r9,8(r28)
lwz r31,-4(r28)
mtlr r9
lwz r30,-8(r28)
lwz r29,-12(r28)
lwz r28,-16(r28)
lwz r1,0(r1)
blr
L(fp_return_value):
/* Do we have long double to store? */
bf 31,L(fd_return_value)
stfd f1,0(r30)
stfd f2,8(r30)
b L(done_return_value)
L(fd_return_value):
/* Do we have double to store? */
bf 28,L(float_return_value)
stfd f1,0(r30)
b L(done_return_value)
L(float_return_value):
/* We only have a float to store. */
stfs f1,0(r30)
b L(done_return_value)
LFE1:
/* END(_ffi_call_DARWIN) */
/* Provide a null definition of _ffi_call_AIX. */
.text
.align 2
.globl _ffi_call_AIX
.text
.align 2
_ffi_call_AIX:
blr
/* END(_ffi_call_AIX) */
.data
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms
EH_frame1:
.set L$set$0,LECIE1-LSCIE1
.long L$set$0 ; Length of Common Information Entry
LSCIE1:
.long 0x0 ; CIE Identifier Tag
.byte 0x1 ; CIE Version
.ascii "zR\0" ; CIE Augmentation
.byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor
.byte 0x7c ; sleb128 -4; CIE Data Alignment Factor
.byte 0x41 ; CIE RA Column
.byte 0x1 ; uleb128 0x1; Augmentation size
.byte 0x90 ; FDE Encoding (indirect pcrel)
.byte 0xc ; DW_CFA_def_cfa
.byte 0x1 ; uleb128 0x1
.byte 0x0 ; uleb128 0x0
.align LOG2_GPR_BYTES
LECIE1:
.globl _ffi_call_DARWIN.eh
_ffi_call_DARWIN.eh:
LSFDE1:
.set L$set$1,LEFDE1-LASFDE1
.long L$set$1 ; FDE Length
LASFDE1:
.long LASFDE1-EH_frame1 ; FDE CIE offset
.g_long LLFB0$non_lazy_ptr-. ; FDE initial location
.set L$set$3,LFE1-LFB0
.g_long L$set$3 ; FDE address range
.byte 0x0 ; uleb128 0x0; Augmentation size
.byte 0x4 ; DW_CFA_advance_loc4
.set L$set$4,LCFI0-LFB1
.long L$set$4
.byte 0xd ; DW_CFA_def_cfa_register
.byte 0x08 ; uleb128 0x08
.byte 0x4 ; DW_CFA_advance_loc4
.set L$set$5,LCFI1-LCFI0
.long L$set$5
.byte 0x11 ; DW_CFA_offset_extended_sf
.byte 0x41 ; uleb128 0x41
.byte 0x7e ; sleb128 -2
.byte 0x9f ; DW_CFA_offset, column 0x1f
.byte 0x1 ; uleb128 0x1
.byte 0x9e ; DW_CFA_offset, column 0x1e
.byte 0x2 ; uleb128 0x2
.byte 0x9d ; DW_CFA_offset, column 0x1d
.byte 0x3 ; uleb128 0x3
.byte 0x9c ; DW_CFA_offset, column 0x1c
.byte 0x4 ; uleb128 0x4
.byte 0x4 ; DW_CFA_advance_loc4
.set L$set$6,LCFI2-LCFI1
.long L$set$6
.byte 0xd ; DW_CFA_def_cfa_register
.byte 0x1c ; uleb128 0x1c
.align LOG2_GPR_BYTES
LEFDE1:
.data
.align LOG2_GPR_BYTES
LLFB0$non_lazy_ptr:
.g_long LFB0

View File

@@ -0,0 +1,317 @@
/* -----------------------------------------------------------------------
darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation,
Inc. based on ppc_closure.S
PowerPC Assembly glue.
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 THE AUTHOR 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
#define L(x) x
#if defined(__ppc64__)
#define MODE_CHOICE(x, y) y
#else
#define MODE_CHOICE(x, y) x
#endif
#define lgu MODE_CHOICE(lwzu, ldu)
#define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */
#define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */
.file "darwin_closure.S"
.text
.align LOG2_GPR_BYTES
.globl _ffi_closure_ASM
.text
.align LOG2_GPR_BYTES
_ffi_closure_ASM:
LFB1:
mflr r0 /* extract return address */
stw r0,8(r1) /* save the return address */
LCFI0:
/* 24 Bytes (Linkage Area)
32 Bytes (outgoing parameter area, always reserved)
104 Bytes (13*8 from FPR)
16 Bytes (result)
176 Bytes */
stwu r1,-176(r1) /* skip over caller save area
keep stack aligned to 16. */
LCFI1:
/* We want to build up an area for the parameters passed
in registers. (both floating point and integer) */
/* We store gpr 3 to gpr 10 (aligned to 4)
in the parents outgoing area. */
stw r3,200(r1)
stw r4,204(r1)
stw r5,208(r1)
stw r6,212(r1)
stw r7,216(r1)
stw r8,220(r1)
stw r9,224(r1)
stw r10,228(r1)
/* We save fpr 1 to fpr 13. (aligned to 8) */
stfd f1,56(r1)
stfd f2,64(r1)
stfd f3,72(r1)
stfd f4,80(r1)
stfd f5,88(r1)
stfd f6,96(r1)
stfd f7,104(r1)
stfd f8,112(r1)
stfd f9,120(r1)
stfd f10,128(r1)
stfd f11,136(r1)
stfd f12,144(r1)
stfd f13,152(r1)
/* Set up registers for the routine that actually does the work
get the context pointer from the trampoline. */
mr r3,r11
/* Now load up the pointer to the result storage. */
addi r4,r1,160
/* Now load up the pointer to the saved gpr registers. */
addi r5,r1,200
/* Now load up the pointer to the saved fpr registers. */
addi r6,r1,56
/* Make the call. */
bl Lffi_closure_helper_DARWIN$stub
/* Now r3 contains the return type
so use it to look up in a table
so we know how to deal with each type. */
/* Look up the proper starting point in table
by using return type as offset. */
addi r5,r1,160 /* Get pointer to results area. */
bl Lget_ret_type0_addr /* Get pointer to Lret_type0 into LR. */
mflr r4 /* Move to r4. */
slwi r3,r3,4 /* Now multiply return type by 16. */
add r3,r3,r4 /* Add contents of table to table address. */
mtctr r3
bctr /* Jump to it. */
LFE1:
/* Each of the ret_typeX code fragments has to be exactly 16 bytes long
(4 instructions). For cache effectiveness we align to a 16 byte boundary
first. */
.align 4
nop
nop
nop
Lget_ret_type0_addr:
blrl
/* case FFI_TYPE_VOID */
Lret_type0:
b Lfinish
nop
nop
nop
/* case FFI_TYPE_INT */
Lret_type1:
lwz r3,0(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_FLOAT */
Lret_type2:
lfs f1,0(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_DOUBLE */
Lret_type3:
lfd f1,0(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_LONGDOUBLE */
Lret_type4:
lfd f1,0(r5)
lfd f2,8(r5)
b Lfinish
nop
/* case FFI_TYPE_UINT8 */
Lret_type5:
lbz r3,3(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_SINT8 */
Lret_type6:
lbz r3,3(r5)
extsb r3,r3
b Lfinish
nop
/* case FFI_TYPE_UINT16 */
Lret_type7:
lhz r3,2(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_SINT16 */
Lret_type8:
lha r3,2(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_UINT32 */
Lret_type9:
lwz r3,0(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_SINT32 */
Lret_type10:
lwz r3,0(r5)
b Lfinish
nop
nop
/* case FFI_TYPE_UINT64 */
Lret_type11:
lwz r3,0(r5)
lwz r4,4(r5)
b Lfinish
nop
/* case FFI_TYPE_SINT64 */
Lret_type12:
lwz r3,0(r5)
lwz r4,4(r5)
b Lfinish
nop
/* case FFI_TYPE_STRUCT */
Lret_type13:
b Lfinish
nop
nop
nop
/* case FFI_TYPE_POINTER */
Lret_type14:
lwz r3,0(r5)
b Lfinish
nop
nop
/* case done */
Lfinish:
addi r1,r1,176 /* Restore stack pointer. */
lwz r0,8(r1) /* Get return address. */
mtlr r0 /* Reset link register. */
blr
/* END(ffi_closure_ASM) */
.data
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
EH_frame1:
.set L$set$0,LECIE1-LSCIE1
.long L$set$0 ; Length of Common Information Entry
LSCIE1:
.long 0x0 ; CIE Identifier Tag
.byte 0x1 ; CIE Version
.ascii "zR\0" ; CIE Augmentation
.byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor
.byte 0x7c ; sleb128 -4; CIE Data Alignment Factor
.byte 0x41 ; CIE RA Column
.byte 0x1 ; uleb128 0x1; Augmentation size
.byte 0x90 ; FDE Encoding (indirect pcrel)
.byte 0xc ; DW_CFA_def_cfa
.byte 0x1 ; uleb128 0x1
.byte 0x0 ; uleb128 0x0
.align LOG2_GPR_BYTES
LECIE1:
.globl _ffi_closure_ASM.eh
_ffi_closure_ASM.eh:
LSFDE1:
.set L$set$1,LEFDE1-LASFDE1
.long L$set$1 ; FDE Length
LASFDE1:
.long LASFDE1-EH_frame1 ; FDE CIE offset
.g_long LLFB1$non_lazy_ptr-. ; FDE initial location
.set L$set$3,LFE1-LFB1
.g_long L$set$3 ; FDE address range
.byte 0x0 ; uleb128 0x0; Augmentation size
.byte 0x4 ; DW_CFA_advance_loc4
.set L$set$3,LCFI1-LCFI0
.long L$set$3
.byte 0xe ; DW_CFA_def_cfa_offset
.byte 176,1 ; uleb128 176
.byte 0x4 ; DW_CFA_advance_loc4
.set L$set$4,LCFI0-LFB1
.long L$set$4
.byte 0x11 ; DW_CFA_offset_extended_sf
.byte 0x41 ; uleb128 0x41
.byte 0x7e ; sleb128 -2
.align LOG2_GPR_BYTES
LEFDE1:
.data
.align LOG2_GPR_BYTES
LDFCM0:
.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
.align LOG2_GPR_BYTES
Lffi_closure_helper_DARWIN$stub:
#if 1
.indirect_symbol _ffi_closure_helper_DARWIN
mflr r0
bcl 20,31,LO$ffi_closure_helper_DARWIN
LO$ffi_closure_helper_DARWIN:
mflr r11
addis r11,r11,ha16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN)
mtlr r0
lgu r12,lo16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN)(r11)
mtctr r12
bctr
.lazy_symbol_pointer
L_ffi_closure_helper_DARWIN$lazy_ptr:
.indirect_symbol _ffi_closure_helper_DARWIN
.g_long dyld_stub_binding_helper
#endif
.data
.align LOG2_GPR_BYTES
LLFB1$non_lazy_ptr:
.g_long LFB1

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,800 @@
/* -----------------------------------------------------------------------
ffi_darwin.c
Copyright (C) 1998 Geoffrey Keating
Copyright (C) 2001 John Hornkvist
Copyright (C) 2002, 2006, 2007 Free Software Foundation, Inc.
FFI support for Darwin and AIX.
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 THE AUTHOR 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>
extern void ffi_closure_ASM(void);
enum {
/* The assembly depends on these exact flags. */
FLAG_RETURNS_NOTHING = 1 << (31-30), /* These go in cr7 */
FLAG_RETURNS_FP = 1 << (31-29),
FLAG_RETURNS_64BITS = 1 << (31-28),
FLAG_RETURNS_128BITS = 1 << (31-31),
FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
FLAG_4_GPR_ARGUMENTS = 1 << (31- 5),
FLAG_RETVAL_REFERENCE = 1 << (31- 4)
};
/* About the DARWIN ABI. */
enum {
NUM_GPR_ARG_REGISTERS = 8,
NUM_FPR_ARG_REGISTERS = 13
};
enum { ASM_NEEDS_REGISTERS = 4 };
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments.
The stack layout we want looks like this:
| Return address from ffi_call_DARWIN | higher addresses
|--------------------------------------------|
| Previous backchain pointer 4 | stack pointer here
|--------------------------------------------|<+ <<< on entry to
| Saved r28-r31 4*4 | | ffi_call_DARWIN
|--------------------------------------------| |
| Parameters (at least 8*4=32) | |
|--------------------------------------------| |
| Space for GPR2 4 | |
|--------------------------------------------| | stack |
| Reserved 2*4 | | grows |
|--------------------------------------------| | down V
| Space for callee's LR 4 | |
|--------------------------------------------| | lower addresses
| Saved CR 4 | |
|--------------------------------------------| | stack pointer here
| Current backchain pointer 4 |-/ during
|--------------------------------------------| <<< ffi_call_DARWIN
*/
void ffi_prep_args(extended_cif *ecif, unsigned *const stack)
{
const unsigned bytes = ecif->cif->bytes;
const unsigned flags = ecif->cif->flags;
/* 'stacktop' points at the previous backchain pointer. */
unsigned *const stacktop = stack + (bytes / sizeof(unsigned));
/* 'fpr_base' points at the space for fpr1, and grows upwards as
we use FPR registers. */
double *fpr_base = (double*) (stacktop - ASM_NEEDS_REGISTERS) - NUM_FPR_ARG_REGISTERS;
int fparg_count = 0;
/* 'next_arg' grows up as we put parameters in it. */
unsigned *next_arg = stack + 6; /* 6 reserved positions. */
int i = ecif->cif->nargs;
double double_tmp;
void **p_argv = ecif->avalue;
unsigned gprvalue;
ffi_type** ptr = ecif->cif->arg_types;
char *dest_cpy;
unsigned size_al = 0;
/* Check that everything starts aligned properly. */
FFI_ASSERT(((unsigned)(char *)stack & 0xF) == 0);
FFI_ASSERT(((unsigned)(char *)stacktop & 0xF) == 0);
FFI_ASSERT((bytes & 0xF) == 0);
/* Deal with return values that are actually pass-by-reference.
Rule:
Return values are referenced by r3, so r4 is the first parameter. */
if (flags & FLAG_RETVAL_REFERENCE)
*next_arg++ = (unsigned)(char *)ecif->rvalue;
/* Now for the arguments. */
for (;
i > 0;
i--, ptr++, p_argv++)
{
switch ((*ptr)->type)
{
/* If a floating-point parameter appears before all of the general-
purpose registers are filled, the corresponding GPRs that match
the size of the floating-point parameter are skipped. */
case FFI_TYPE_FLOAT:
double_tmp = *(float *)*p_argv;
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg++;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
case FFI_TYPE_DOUBLE:
double_tmp = *(double *)*p_argv;
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
double_tmp = ((double *)*p_argv)[0];
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
double_tmp = ((double *)*p_argv)[1];
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
#endif
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
*(long long *)next_arg = *(long long *)*p_argv;
next_arg+=2;
break;
case FFI_TYPE_UINT8:
gprvalue = *(unsigned char *)*p_argv;
goto putgpr;
case FFI_TYPE_SINT8:
gprvalue = *(signed char *)*p_argv;
goto putgpr;
case FFI_TYPE_UINT16:
gprvalue = *(unsigned short *)*p_argv;
goto putgpr;
case FFI_TYPE_SINT16:
gprvalue = *(signed short *)*p_argv;
goto putgpr;
case FFI_TYPE_STRUCT:
dest_cpy = (char *) next_arg;
/* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
SI 4 bytes) are aligned as if they were those modes.
Structures with 3 byte in size are padded upwards. */
size_al = (*ptr)->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if ((*ptr)->elements[0]->type == 3)
size_al = ALIGN((*ptr)->size, 8);
if (size_al < 3 && ecif->cif->abi == FFI_DARWIN)
dest_cpy += 4 - size_al;
memcpy((char *)dest_cpy, (char *)*p_argv, size_al);
next_arg += (size_al + 3) / 4;
break;
case FFI_TYPE_INT:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
case FFI_TYPE_POINTER:
gprvalue = *(unsigned *)*p_argv;
putgpr:
*next_arg++ = gprvalue;
break;
default:
break;
}
}
/* Check that we didn't overrun the stack... */
//FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
//FFI_ASSERT((unsigned *)fpr_base
// <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
//FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
}
/* Adjust the size of S to be correct for Darwin.
On Darwin, the first field of a structure has natural alignment. */
static void
darwin_adjust_aggregate_sizes (ffi_type *s)
{
int i;
if (s->type != FFI_TYPE_STRUCT)
return;
s->size = 0;
for (i = 0; s->elements[i] != NULL; i++)
{
ffi_type *p;
int align;
p = s->elements[i];
darwin_adjust_aggregate_sizes (p);
if (i == 0
&& (p->type == FFI_TYPE_UINT64
|| p->type == FFI_TYPE_SINT64
|| p->type == FFI_TYPE_DOUBLE
|| p->alignment == 8))
align = 8;
else if (p->alignment == 16 || p->alignment < 4)
align = p->alignment;
else
align = 4;
s->size = ALIGN(s->size, align) + p->size;
}
s->size = ALIGN(s->size, s->alignment);
if (s->elements[0]->type == FFI_TYPE_UINT64
|| s->elements[0]->type == FFI_TYPE_SINT64
|| s->elements[0]->type == FFI_TYPE_DOUBLE
|| s->elements[0]->alignment == 8)
s->alignment = s->alignment > 8 ? s->alignment : 8;
/* Do not add additional tail padding. */
}
/* Perform machine dependent cif processing. */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
/* All this is for the DARWIN ABI. */
int i;
ffi_type **ptr;
unsigned bytes;
int fparg_count = 0, intarg_count = 0;
unsigned flags = 0;
unsigned size_al = 0;
/* All the machine-independent calculation of cif->bytes will be wrong.
All the calculation of structure sizes will also be wrong.
Redo the calculation for DARWIN. */
if (cif->abi == FFI_DARWIN)
{
darwin_adjust_aggregate_sizes (cif->rtype);
for (i = 0; i < cif->nargs; i++)
darwin_adjust_aggregate_sizes (cif->arg_types[i]);
}
/* Space for the frame pointer, callee's LR, CR, etc, and for
the asm's temp regs. */
bytes = (6 + ASM_NEEDS_REGISTERS) * sizeof(long);
/* Return value handling. The rules are as follows:
- 32-bit (or less) integer values are returned in gpr3;
- Structures of size <= 4 bytes also returned in gpr3;
- 64-bit integer values and structures between 5 and 8 bytes are returned
in gpr3 and gpr4;
- Single/double FP values are returned in fpr1;
- Long double FP (if not equivalent to double) values are returned in
fpr1 and fpr2;
- Larger structures values are allocated space and a pointer is passed
as the first argument. */
switch (cif->rtype->type)
{
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
flags |= FLAG_RETURNS_128BITS;
flags |= FLAG_RETURNS_FP;
break;
#endif
case FFI_TYPE_DOUBLE:
flags |= FLAG_RETURNS_64BITS;
/* Fall through. */
case FFI_TYPE_FLOAT:
flags |= FLAG_RETURNS_FP;
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
flags |= FLAG_RETURNS_64BITS;
break;
case FFI_TYPE_STRUCT:
flags |= FLAG_RETVAL_REFERENCE;
flags |= FLAG_RETURNS_NOTHING;
intarg_count++;
break;
case FFI_TYPE_VOID:
flags |= FLAG_RETURNS_NOTHING;
break;
default:
/* Returns 32-bit integer, or similar. Nothing to do here. */
break;
}
/* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
goes on the stack. Structures are passed as a pointer to a copy of
the structure. Stuff on the stack needs to keep proper alignment. */
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
switch ((*ptr)->type)
{
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
fparg_count++;
/* If this FP arg is going on the stack, it must be
8-byte-aligned. */
if (fparg_count > NUM_FPR_ARG_REGISTERS
&& intarg_count%2 != 0)
intarg_count++;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
fparg_count += 2;
/* If this FP arg is going on the stack, it must be
8-byte-aligned. */
if (fparg_count > NUM_FPR_ARG_REGISTERS
&& intarg_count%2 != 0)
intarg_count++;
intarg_count +=2;
break;
#endif
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
/* 'long long' arguments are passed as two words, but
either both words must fit in registers or both go
on the stack. If they go on the stack, they must
be 8-byte-aligned. */
if (intarg_count == NUM_GPR_ARG_REGISTERS-1
|| (intarg_count >= NUM_GPR_ARG_REGISTERS && intarg_count%2 != 0))
intarg_count++;
intarg_count += 2;
break;
case FFI_TYPE_STRUCT:
size_al = (*ptr)->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if ((*ptr)->elements[0]->type == 3)
size_al = ALIGN((*ptr)->size, 8);
intarg_count += (size_al + 3) / 4;
break;
default:
/* Everything else is passed as a 4-byte word in a GPR, either
the object itself or a pointer to it. */
intarg_count++;
break;
}
}
if (fparg_count != 0)
flags |= FLAG_FP_ARGUMENTS;
/* Space for the FPR registers, if needed. */
if (fparg_count != 0)
bytes += NUM_FPR_ARG_REGISTERS * sizeof(double);
/* Stack space. */
if ((intarg_count + 2 * fparg_count) > NUM_GPR_ARG_REGISTERS)
bytes += (intarg_count + 2 * fparg_count) * sizeof(long);
else
bytes += NUM_GPR_ARG_REGISTERS * sizeof(long);
/* The stack space allocated needs to be a multiple of 16 bytes. */
bytes = (bytes + 15) & ~0xF;
cif->flags = flags;
cif->bytes = bytes;
return FFI_OK;
}
extern void ffi_call_AIX(extended_cif *, unsigned, unsigned, unsigned *,
void (*fn)(void), void (*fn2)(void));
extern void ffi_call_DARWIN(extended_cif *, unsigned, unsigned, unsigned *,
void (*fn)(void), void (*fn2)(void));
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, 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))
{
ecif.rvalue = alloca(cif->rtype->size);
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_AIX:
ffi_call_AIX(&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn,
ffi_prep_args);
break;
case FFI_DARWIN:
ffi_call_DARWIN(&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn,
ffi_prep_args);
break;
default:
FFI_ASSERT(0);
break;
}
}
static void flush_icache(char *);
static void flush_range(char *, int);
/* The layout of a function descriptor. A C function pointer really
points to one of these. */
typedef struct aix_fd_struct {
void *code_pointer;
void *toc;
} aix_fd;
/* here I'd like to add the stack frame layout we use in darwin_closure.S
and aix_clsoure.S
SP previous -> +---------------------------------------+ <--- child frame
| back chain to caller 4 |
+---------------------------------------+ 4
| saved CR 4 |
+---------------------------------------+ 8
| saved LR 4 |
+---------------------------------------+ 12
| reserved for compilers 4 |
+---------------------------------------+ 16
| reserved for binders 4 |
+---------------------------------------+ 20
| saved TOC pointer 4 |
+---------------------------------------+ 24
| always reserved 8*4=32 (previous GPRs)|
| according to the linkage convention |
| from AIX |
+---------------------------------------+ 56
| our FPR area 13*8=104 |
| f1 |
| . |
| f13 |
+---------------------------------------+ 160
| result area 8 |
+---------------------------------------+ 168
| alignement to the next multiple of 16 |
SP current --> +---------------------------------------+ 176 <- parent frame
| back chain to caller 4 |
+---------------------------------------+ 180
| saved CR 4 |
+---------------------------------------+ 184
| saved LR 4 |
+---------------------------------------+ 188
| reserved for compilers 4 |
+---------------------------------------+ 192
| reserved for binders 4 |
+---------------------------------------+ 196
| saved TOC pointer 4 |
+---------------------------------------+ 200
| always reserved 8*4=32 we store our |
| GPRs here |
| r3 |
| . |
| r10 |
+---------------------------------------+ 232
| overflow part |
+---------------------------------------+ xxx
| ???? |
+---------------------------------------+ xxx
*/
ffi_status
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*, void*, void**, void*),
void *user_data,
void *codeloc)
{
unsigned int *tramp;
struct ffi_aix_trampoline_struct *tramp_aix;
aix_fd *fd;
switch (cif->abi)
{
case FFI_DARWIN:
FFI_ASSERT (cif->abi == FFI_DARWIN);
tramp = (unsigned int *) &closure->tramp[0];
tramp[0] = 0x7c0802a6; /* mflr r0 */
tramp[1] = 0x429f000d; /* bcl- 20,4*cr7+so,0x10 */
tramp[4] = 0x7d6802a6; /* mflr r11 */
tramp[5] = 0x818b0000; /* lwz r12,0(r11) function address */
tramp[6] = 0x7c0803a6; /* mtlr r0 */
tramp[7] = 0x7d8903a6; /* mtctr r12 */
tramp[8] = 0x816b0004; /* lwz r11,4(r11) static chain */
tramp[9] = 0x4e800420; /* bctr */
tramp[2] = (unsigned long) ffi_closure_ASM; /* function */
tramp[3] = (unsigned long) codeloc; /* context */
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
/* Flush the icache. Only necessary on Darwin. */
flush_range(codeloc, FFI_TRAMPOLINE_SIZE);
break;
case FFI_AIX:
tramp_aix = (struct ffi_aix_trampoline_struct *) (closure->tramp);
fd = (aix_fd *)(void *)ffi_closure_ASM;
FFI_ASSERT (cif->abi == FFI_AIX);
tramp_aix->code_pointer = fd->code_pointer;
tramp_aix->toc = fd->toc;
tramp_aix->static_chain = codeloc;
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
default:
FFI_ASSERT(0);
break;
}
return FFI_OK;
}
static void
flush_icache(char *addr)
{
#ifndef _AIX
__asm__ volatile (
"dcbf 0,%0\n"
"\tsync\n"
"\ticbi 0,%0\n"
"\tsync\n"
"\tisync"
: : "r"(addr) : "memory");
#endif
}
static void
flush_range(char * addr1, int size)
{
#define MIN_LINE_SIZE 32
int i;
for (i = 0; i < size; i += MIN_LINE_SIZE)
flush_icache(addr1+i);
flush_icache(addr1+size-1);
}
typedef union
{
float f;
double d;
} ffi_dblfl;
int ffi_closure_helper_DARWIN (ffi_closure*, void*,
unsigned long*, ffi_dblfl*);
/* Basically the trampoline invokes ffi_closure_ASM, and on
entry, r11 holds the address of the closure.
After storing the registers that could possibly contain
parameters to be passed into the stack frame and setting
up space for a return value, ffi_closure_ASM invokes the
following helper function to do most of the work. */
int ffi_closure_helper_DARWIN (ffi_closure* closure, void * rvalue,
unsigned long * pgr, ffi_dblfl * pfr)
{
/* rvalue is the pointer to space for return value in closure assembly
pgr is the pointer to where r3-r10 are stored in ffi_closure_ASM
pfr is the pointer to where f1-f13 are stored in ffi_closure_ASM. */
typedef double ldbits[2];
union ldu
{
ldbits lb;
long double ld;
};
void ** avalue;
ffi_type ** arg_types;
long i, avn;
long nf; /* number of floating registers already used. */
long ng; /* number of general registers already used. */
ffi_cif * cif;
double temp;
unsigned size_al;
union ldu temp_ld;
cif = closure->cif;
avalue = alloca(cif->nargs * sizeof(void *));
nf = 0;
ng = 0;
/* Copy the caller's structure return value address so that the closure
returns the data directly to the caller. */
if (cif->rtype->type == FFI_TYPE_STRUCT)
{
rvalue = (void *) *pgr;
pgr++;
ng++;
}
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
/* Grab the addresses of the arguments from the stack frame. */
while (i < avn)
{
switch (arg_types[i]->type)
{
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
avalue[i] = (char *) pgr + 3;
ng++;
pgr++;
break;
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
avalue[i] = (char *) pgr + 2;
ng++;
pgr++;
break;
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
case FFI_TYPE_POINTER:
avalue[i] = pgr;
ng++;
pgr++;
break;
case FFI_TYPE_STRUCT:
/* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
SI 4 bytes) are aligned as if they were those modes. */
size_al = arg_types[i]->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if (arg_types[i]->elements[0]->type == 3)
size_al = ALIGN(arg_types[i]->size, 8);
if (size_al < 3 && cif->abi == FFI_DARWIN)
avalue[i] = (void*) pgr + 4 - size_al;
else
avalue[i] = (void*) pgr;
ng += (size_al + 3) / 4;
pgr += (size_al + 3) / 4;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
/* Long long ints are passed in two gpr's. */
avalue[i] = pgr;
ng += 2;
pgr += 2;
break;
case FFI_TYPE_FLOAT:
/* A float value consumes a GPR.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS)
{
temp = pfr->d;
pfr->f = (float)temp;
avalue[i] = pfr;
pfr++;
}
else
{
avalue[i] = pgr;
}
nf++;
ng++;
pgr++;
break;
case FFI_TYPE_DOUBLE:
/* A double value consumes two GPRs.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS)
{
avalue[i] = pfr;
pfr++;
}
else
{
avalue[i] = pgr;
}
nf++;
ng += 2;
pgr += 2;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
/* A long double value consumes four GPRs and two FPRs.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS - 1)
{
avalue[i] = pfr;
pfr += 2;
}
/* Here we have the situation where one part of the long double
is stored in fpr13 and the other part is already on the stack.
We use a union to pass the long double to avalue[i]. */
else if (nf == NUM_FPR_ARG_REGISTERS - 1)
{
memcpy (&temp_ld.lb[0], pfr, sizeof(ldbits));
memcpy (&temp_ld.lb[1], pgr + 2, sizeof(ldbits));
avalue[i] = &temp_ld.ld;
}
else
{
avalue[i] = pgr;
}
nf += 2;
ng += 4;
pgr += 4;
break;
#endif
default:
FFI_ASSERT(0);
}
i++;
}
(closure->fun) (cif, rvalue, avalue, closure->user_data);
/* Tell ffi_closure_ASM to perform return type promotions. */
return cif->rtype->type;
}

View File

@@ -0,0 +1,122 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Copyright (C) 2007, 2008 Free Software Foundation, Inc
Target configuration macros for PowerPC.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
/* ---- System specific configurations ----------------------------------- */
#if defined (POWERPC) && defined (__powerpc64__)
#define POWERPC64
#endif
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
#ifdef POWERPC
FFI_SYSV,
FFI_GCC_SYSV,
FFI_LINUX64,
FFI_LINUX,
FFI_LINUX_SOFT_FLOAT,
# ifdef POWERPC64
FFI_DEFAULT_ABI = FFI_LINUX64,
# else
# if (!defined(__NO_FPRS__) && (__LDBL_MANT_DIG__ == 106))
FFI_DEFAULT_ABI = FFI_LINUX,
# else
# ifdef __NO_FPRS__
FFI_DEFAULT_ABI = FFI_LINUX_SOFT_FLOAT,
# else
FFI_DEFAULT_ABI = FFI_GCC_SYSV,
# endif
# endif
# endif
#endif
#ifdef POWERPC_AIX
FFI_AIX,
FFI_DARWIN,
FFI_DEFAULT_ABI = FFI_AIX,
#endif
#ifdef POWERPC_DARWIN
FFI_AIX,
FFI_DARWIN,
FFI_DEFAULT_ABI = FFI_DARWIN,
#endif
#ifdef POWERPC_FREEBSD
FFI_SYSV,
FFI_GCC_SYSV,
FFI_LINUX64,
FFI_LINUX,
FFI_LINUX_SOFT_FLOAT,
FFI_DEFAULT_ABI = FFI_SYSV,
#endif
FFI_LAST_ABI
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#define FFI_NATIVE_RAW_API 0
/* For additional types like the below, take care about the order in
ppc_closures.S. They must follow after the FFI_TYPE_LAST. */
/* Needed for FFI_SYSV small structure returns.
We use two flag bits, (FLAG_SYSV_SMST_R3, FLAG_SYSV_SMST_R4) which are
defined in ffi.c, to determine the exact return type and its size. */
#define FFI_TYPE_UINT128 (FFI_TYPE_LAST + 1)
/* Needed for FFI_SYSV small structure returns. */
#define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 2)
#if defined(POWERPC64) || defined(POWERPC_AIX)
#define FFI_TRAMPOLINE_SIZE 24
#else /* POWERPC || POWERPC_AIX */
#define FFI_TRAMPOLINE_SIZE 40
#endif
#ifndef LIBFFI_ASM
#if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
struct ffi_aix_trampoline_struct {
void * code_pointer; /* Pointer to ffi_closure_ASM */
void * toc; /* TOC */
void * static_chain; /* Pointer to closure */
};
#endif
#endif
#endif

View File

@@ -0,0 +1,187 @@
/* -----------------------------------------------------------------------
sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
Copyright (c) 2008 Red Hat, Inc.
PowerPC64 Assembly glue.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#ifdef __powerpc64__
.hidden ffi_call_LINUX64, .ffi_call_LINUX64
.globl ffi_call_LINUX64, .ffi_call_LINUX64
.section ".opd","aw"
.align 3
ffi_call_LINUX64:
.quad .ffi_call_LINUX64,.TOC.@tocbase,0
.size ffi_call_LINUX64,24
.type .ffi_call_LINUX64,@function
.text
.ffi_call_LINUX64:
.LFB1:
mflr %r0
std %r28, -32(%r1)
std %r29, -24(%r1)
std %r30, -16(%r1)
std %r31, -8(%r1)
std %r0, 16(%r1)
mr %r28, %r1 /* our AP. */
.LCFI0:
stdux %r1, %r1, %r4
mr %r31, %r5 /* flags, */
mr %r30, %r6 /* rvalue, */
mr %r29, %r7 /* function address. */
std %r2, 40(%r1)
/* Call ffi_prep_args64. */
mr %r4, %r1
bl .ffi_prep_args64
ld %r0, 0(%r29)
ld %r2, 8(%r29)
ld %r11, 16(%r29)
/* Now do the call. */
/* Set up cr1 with bits 4-7 of the flags. */
mtcrf 0x40, %r31
/* Get the address to call into CTR. */
mtctr %r0
/* Load all those argument registers. */
ld %r3, -32-(8*8)(%r28)
ld %r4, -32-(7*8)(%r28)
ld %r5, -32-(6*8)(%r28)
ld %r6, -32-(5*8)(%r28)
bf- 5, 1f
ld %r7, -32-(4*8)(%r28)
ld %r8, -32-(3*8)(%r28)
ld %r9, -32-(2*8)(%r28)
ld %r10, -32-(1*8)(%r28)
1:
/* Load all the FP registers. */
bf- 6, 2f
lfd %f1, -32-(21*8)(%r28)
lfd %f2, -32-(20*8)(%r28)
lfd %f3, -32-(19*8)(%r28)
lfd %f4, -32-(18*8)(%r28)
lfd %f5, -32-(17*8)(%r28)
lfd %f6, -32-(16*8)(%r28)
lfd %f7, -32-(15*8)(%r28)
lfd %f8, -32-(14*8)(%r28)
lfd %f9, -32-(13*8)(%r28)
lfd %f10, -32-(12*8)(%r28)
lfd %f11, -32-(11*8)(%r28)
lfd %f12, -32-(10*8)(%r28)
lfd %f13, -32-(9*8)(%r28)
2:
/* Make the call. */
bctrl
/* This must follow the call immediately, the unwinder
uses this to find out if r2 has been saved or not. */
ld %r2, 40(%r1)
/* Now, deal with the return value. */
mtcrf 0x01, %r31
bt- 30, .Ldone_return_value
bt- 29, .Lfp_return_value
std %r3, 0(%r30)
/* Fall through... */
.Ldone_return_value:
/* Restore the registers we used and return. */
mr %r1, %r28
ld %r0, 16(%r28)
ld %r28, -32(%r1)
mtlr %r0
ld %r29, -24(%r1)
ld %r30, -16(%r1)
ld %r31, -8(%r1)
blr
.Lfp_return_value:
bf 28, .Lfloat_return_value
stfd %f1, 0(%r30)
mtcrf 0x02, %r31 /* cr6 */
bf 27, .Ldone_return_value
stfd %f2, 8(%r30)
b .Ldone_return_value
.Lfloat_return_value:
stfs %f1, 0(%r30)
b .Ldone_return_value
.LFE1:
.long 0
.byte 0,12,0,1,128,4,0,0
.size .ffi_call_LINUX64,.-.ffi_call_LINUX64
.section .eh_frame,EH_FRAME_FLAGS,@progbits
.Lframe1:
.4byte .LECIE1-.LSCIE1 # Length of Common Information Entry
.LSCIE1:
.4byte 0x0 # CIE Identifier Tag
.byte 0x1 # CIE Version
.ascii "zR\0" # CIE Augmentation
.uleb128 0x1 # CIE Code Alignment Factor
.sleb128 -8 # CIE Data Alignment Factor
.byte 0x41 # CIE RA Column
.uleb128 0x1 # Augmentation size
.byte 0x14 # FDE Encoding (pcrel udata8)
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1
.uleb128 0x0
.align 3
.LECIE1:
.LSFDE1:
.4byte .LEFDE1-.LASFDE1 # FDE Length
.LASFDE1:
.4byte .LASFDE1-.Lframe1 # FDE CIE offset
.8byte .LFB1-. # FDE initial location
.8byte .LFE1-.LFB1 # FDE address range
.uleb128 0x0 # Augmentation size
.byte 0x2 # DW_CFA_advance_loc1
.byte .LCFI0-.LFB1
.byte 0xd # DW_CFA_def_cfa_register
.uleb128 0x1c
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x41
.sleb128 -2
.byte 0x9f # DW_CFA_offset, column 0x1f
.uleb128 0x1
.byte 0x9e # DW_CFA_offset, column 0x1e
.uleb128 0x2
.byte 0x9d # DW_CFA_offset, column 0x1d
.uleb128 0x3
.byte 0x9c # DW_CFA_offset, column 0x1c
.uleb128 0x4
.align 3
.LEFDE1:
#endif
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,236 @@
/* -----------------------------------------------------------------------
sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
Copyright (c) 2008 Red Hat, Inc.
PowerPC64 Assembly glue.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
.file "linux64_closure.S"
#ifdef __powerpc64__
FFI_HIDDEN (ffi_closure_LINUX64)
FFI_HIDDEN (.ffi_closure_LINUX64)
.globl ffi_closure_LINUX64, .ffi_closure_LINUX64
.section ".opd","aw"
.align 3
ffi_closure_LINUX64:
.quad .ffi_closure_LINUX64,.TOC.@tocbase,0
.size ffi_closure_LINUX64,24
.type .ffi_closure_LINUX64,@function
.text
.ffi_closure_LINUX64:
.LFB1:
# save general regs into parm save area
std %r3, 48(%r1)
std %r4, 56(%r1)
std %r5, 64(%r1)
std %r6, 72(%r1)
mflr %r0
std %r7, 80(%r1)
std %r8, 88(%r1)
std %r9, 96(%r1)
std %r10, 104(%r1)
std %r0, 16(%r1)
# mandatory 48 bytes special reg save area + 64 bytes parm save area
# + 16 bytes retval area + 13*8 bytes fpr save area + round to 16
stdu %r1, -240(%r1)
.LCFI0:
# next save fpr 1 to fpr 13
stfd %f1, 128+(0*8)(%r1)
stfd %f2, 128+(1*8)(%r1)
stfd %f3, 128+(2*8)(%r1)
stfd %f4, 128+(3*8)(%r1)
stfd %f5, 128+(4*8)(%r1)
stfd %f6, 128+(5*8)(%r1)
stfd %f7, 128+(6*8)(%r1)
stfd %f8, 128+(7*8)(%r1)
stfd %f9, 128+(8*8)(%r1)
stfd %f10, 128+(9*8)(%r1)
stfd %f11, 128+(10*8)(%r1)
stfd %f12, 128+(11*8)(%r1)
stfd %f13, 128+(12*8)(%r1)
# set up registers for the routine that actually does the work
# get the context pointer from the trampoline
mr %r3, %r11
# now load up the pointer to the result storage
addi %r4, %r1, 112
# now load up the pointer to the parameter save area
# in the previous frame
addi %r5, %r1, 240 + 48
# now load up the pointer to the saved fpr registers */
addi %r6, %r1, 128
# make the call
bl .ffi_closure_helper_LINUX64
.Lret:
# now r3 contains the return type
# so use it to look up in a table
# so we know how to deal with each type
# look up the proper starting point in table
# by using return type as offset
mflr %r4 # move address of .Lret to r4
sldi %r3, %r3, 4 # now multiply return type by 16
addi %r4, %r4, .Lret_type0 - .Lret
ld %r0, 240+16(%r1)
add %r3, %r3, %r4 # add contents of table to table address
mtctr %r3
bctr # jump to it
# Each of the ret_typeX code fragments has to be exactly 16 bytes long
# (4 instructions). For cache effectiveness we align to a 16 byte boundary
# first.
.align 4
.Lret_type0:
# case FFI_TYPE_VOID
mtlr %r0
addi %r1, %r1, 240
blr
nop
# case FFI_TYPE_INT
lwa %r3, 112+4(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_FLOAT
lfs %f1, 112+0(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_DOUBLE
lfd %f1, 112+0(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_LONGDOUBLE
lfd %f1, 112+0(%r1)
mtlr %r0
lfd %f2, 112+8(%r1)
b .Lfinish
# case FFI_TYPE_UINT8
lbz %r3, 112+7(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT8
lbz %r3, 112+7(%r1)
extsb %r3,%r3
mtlr %r0
b .Lfinish
# case FFI_TYPE_UINT16
lhz %r3, 112+6(%r1)
mtlr %r0
.Lfinish:
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT16
lha %r3, 112+6(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_UINT32
lwz %r3, 112+4(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT32
lwa %r3, 112+4(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_UINT64
ld %r3, 112+0(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_SINT64
ld %r3, 112+0(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# case FFI_TYPE_STRUCT
mtlr %r0
addi %r1, %r1, 240
blr
nop
# case FFI_TYPE_POINTER
ld %r3, 112+0(%r1)
mtlr %r0
addi %r1, %r1, 240
blr
# esac
.LFE1:
.long 0
.byte 0,12,0,1,128,0,0,0
.size .ffi_closure_LINUX64,.-.ffi_closure_LINUX64
.section .eh_frame,EH_FRAME_FLAGS,@progbits
.Lframe1:
.4byte .LECIE1-.LSCIE1 # Length of Common Information Entry
.LSCIE1:
.4byte 0x0 # CIE Identifier Tag
.byte 0x1 # CIE Version
.ascii "zR\0" # CIE Augmentation
.uleb128 0x1 # CIE Code Alignment Factor
.sleb128 -8 # CIE Data Alignment Factor
.byte 0x41 # CIE RA Column
.uleb128 0x1 # Augmentation size
.byte 0x14 # FDE Encoding (pcrel udata8)
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1
.uleb128 0x0
.align 3
.LECIE1:
.LSFDE1:
.4byte .LEFDE1-.LASFDE1 # FDE Length
.LASFDE1:
.4byte .LASFDE1-.Lframe1 # FDE CIE offset
.8byte .LFB1-. # FDE initial location
.8byte .LFE1-.LFB1 # FDE address range
.uleb128 0x0 # Augmentation size
.byte 0x2 # DW_CFA_advance_loc1
.byte .LCFI0-.LFB1
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 240
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x41
.sleb128 -2
.align 3
.LEFDE1:
#endif
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,327 @@
/* -----------------------------------------------------------------------
sysv.h - Copyright (c) 2003 Jakub Jelinek <jakub@redhat.com>
Copyright (c) 2008 Red Hat, Inc.
PowerPC Assembly glue.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#include <powerpc/asm.h>
.file "ppc_closure.S"
#ifndef __powerpc64__
ENTRY(ffi_closure_SYSV)
.LFB1:
stwu %r1,-144(%r1)
.LCFI0:
mflr %r0
.LCFI1:
stw %r0,148(%r1)
# we want to build up an areas for the parameters passed
# in registers (both floating point and integer)
# so first save gpr 3 to gpr 10 (aligned to 4)
stw %r3, 16(%r1)
stw %r4, 20(%r1)
stw %r5, 24(%r1)
stw %r6, 28(%r1)
stw %r7, 32(%r1)
stw %r8, 36(%r1)
stw %r9, 40(%r1)
stw %r10,44(%r1)
#ifndef __NO_FPRS__
# next save fpr 1 to fpr 8 (aligned to 8)
stfd %f1, 48(%r1)
stfd %f2, 56(%r1)
stfd %f3, 64(%r1)
stfd %f4, 72(%r1)
stfd %f5, 80(%r1)
stfd %f6, 88(%r1)
stfd %f7, 96(%r1)
stfd %f8, 104(%r1)
#endif
# set up registers for the routine that actually does the work
# get the context pointer from the trampoline
mr %r3,%r11
# now load up the pointer to the result storage
addi %r4,%r1,112
# now load up the pointer to the saved gpr registers
addi %r5,%r1,16
# now load up the pointer to the saved fpr registers */
addi %r6,%r1,48
# now load up the pointer to the outgoing parameter
# stack in the previous frame
# i.e. the previous frame pointer + 8
addi %r7,%r1,152
# make the call
bl ffi_closure_helper_SYSV@local
.Lret:
# now r3 contains the return type
# so use it to look up in a table
# so we know how to deal with each type
# look up the proper starting point in table
# by using return type as offset
mflr %r4 # move address of .Lret to r4
slwi %r3,%r3,4 # now multiply return type by 16
addi %r4, %r4, .Lret_type0 - .Lret
lwz %r0,148(%r1)
add %r3,%r3,%r4 # add contents of table to table address
mtctr %r3
bctr # jump to it
.LFE1:
# Each of the ret_typeX code fragments has to be exactly 16 bytes long
# (4 instructions). For cache effectiveness we align to a 16 byte boundary
# first.
.align 4
# case FFI_TYPE_VOID
.Lret_type0:
mtlr %r0
addi %r1,%r1,144
blr
nop
# case FFI_TYPE_INT
lwz %r3,112+0(%r1)
mtlr %r0
.Lfinish:
addi %r1,%r1,144
blr
# case FFI_TYPE_FLOAT
lfs %f1,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_DOUBLE
lfd %f1,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_LONGDOUBLE
lfd %f1,112+0(%r1)
lfd %f2,112+8(%r1)
mtlr %r0
b .Lfinish
# case FFI_TYPE_UINT8
lbz %r3,112+3(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_SINT8
lbz %r3,112+3(%r1)
extsb %r3,%r3
mtlr %r0
b .Lfinish
# case FFI_TYPE_UINT16
lhz %r3,112+2(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_SINT16
lha %r3,112+2(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_UINT32
lwz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_SINT32
lwz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_UINT64
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
mtlr %r0
b .Lfinish
# case FFI_TYPE_SINT64
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
mtlr %r0
b .Lfinish
# case FFI_TYPE_STRUCT
mtlr %r0
addi %r1,%r1,144
blr
nop
# case FFI_TYPE_POINTER
lwz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_TYPE_UINT128
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
lwz %r5,112+8(%r1)
bl .Luint128
# The return types below are only used when the ABI type is FFI_SYSV.
# case FFI_SYSV_TYPE_SMALL_STRUCT + 1. One byte struct.
lbz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_SYSV_TYPE_SMALL_STRUCT + 2. Two byte struct.
lhz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_SYSV_TYPE_SMALL_STRUCT + 3. Three byte struct.
lwz %r3,112+0(%r1)
srwi %r3,%r3,8
mtlr %r0
b .Lfinish
# case FFI_SYSV_TYPE_SMALL_STRUCT + 4. Four byte struct.
lwz %r3,112+0(%r1)
mtlr %r0
addi %r1,%r1,144
blr
# case FFI_SYSV_TYPE_SMALL_STRUCT + 5. Five byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
li %r5,24
b .Lstruct567
# case FFI_SYSV_TYPE_SMALL_STRUCT + 6. Six byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
li %r5,16
b .Lstruct567
# case FFI_SYSV_TYPE_SMALL_STRUCT + 7. Seven byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
li %r5,8
b .Lstruct567
# case FFI_SYSV_TYPE_SMALL_STRUCT + 8. Eight byte struct.
lwz %r3,112+0(%r1)
lwz %r4,112+4(%r1)
mtlr %r0
b .Lfinish
.Lstruct567:
subfic %r6,%r5,32
srw %r4,%r4,%r5
slw %r6,%r3,%r6
srw %r3,%r3,%r5
or %r4,%r6,%r4
mtlr %r0
addi %r1,%r1,144
blr
.Luint128:
lwz %r6,112+12(%r1)
mtlr %r0
addi %r1,%r1,144
blr
END(ffi_closure_SYSV)
.section ".eh_frame",EH_FRAME_FLAGS,@progbits
.Lframe1:
.4byte .LECIE1-.LSCIE1 # Length of Common Information Entry
.LSCIE1:
.4byte 0x0 # CIE Identifier Tag
.byte 0x1 # CIE Version
#if defined _RELOCATABLE || defined __PIC__
.ascii "zR\0" # CIE Augmentation
#else
.ascii "\0" # CIE Augmentation
#endif
.uleb128 0x1 # CIE Code Alignment Factor
.sleb128 -4 # CIE Data Alignment Factor
.byte 0x41 # CIE RA Column
#if defined _RELOCATABLE || defined __PIC__
.uleb128 0x1 # Augmentation size
.byte 0x1b # FDE Encoding (pcrel sdata4)
#endif
.byte 0xc # DW_CFA_def_cfa
.uleb128 0x1
.uleb128 0x0
.align 2
.LECIE1:
.LSFDE1:
.4byte .LEFDE1-.LASFDE1 # FDE Length
.LASFDE1:
.4byte .LASFDE1-.Lframe1 # FDE CIE offset
#if defined _RELOCATABLE || defined __PIC__
.4byte .LFB1-. # FDE initial location
#else
.4byte .LFB1 # FDE initial location
#endif
.4byte .LFE1-.LFB1 # FDE address range
#if defined _RELOCATABLE || defined __PIC__
.uleb128 0x0 # Augmentation size
#endif
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI0-.LFB1
.byte 0xe # DW_CFA_def_cfa_offset
.uleb128 144
.byte 0x4 # DW_CFA_advance_loc4
.4byte .LCFI1-.LCFI0
.byte 0x11 # DW_CFA_offset_extended_sf
.uleb128 0x41
.sleb128 -1
.align 2
.LEFDE1:
#endif
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,230 @@
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 1998 Geoffrey Keating
Copyright (C) 2007 Free Software Foundation, Inc
PowerPC Assembly glue.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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 <fficonfig.h>
#include <ffi.h>
#include <powerpc/asm.h>
#ifndef __powerpc64__
.globl ffi_prep_args_SYSV
ENTRY(ffi_call_SYSV)
.LFB1:
/* Save the old stack pointer as AP. */
mr %r8,%r1
.LCFI0:
/* Allocate the stack space we need. */
stwux %r1,%r1,%r4
/* Save registers we use. */
mflr %r9
stw %r28,-16(%r8)
.LCFI1:
stw %r29,-12(%r8)
.LCFI2:
stw %r30, -8(%r8)
.LCFI3:
stw %r31, -4(%r8)
.LCFI4:
stw %r9, 4(%r8)
.LCFI5:
/* Save arguments over call... */
mr %r31,%r5 /* flags, */
mr %r30,%r6 /* rvalue, */
mr %r29,%r7 /* function address, */
mr %r28,%r8 /* our AP. */
.LCFI6:
/* Call ffi_prep_args_SYSV. */
mr %r4,%r1
bl ffi_prep_args_SYSV@local
/* Now do the call. */
/* Set up cr1 with bits 4-7 of the flags. */
mtcrf 0x40,%r31
/* Get the address to call into CTR. */
mtctr %r29
/* Load all those argument registers. */
lwz %r3,-16-(8*4)(%r28)
lwz %r4,-16-(7*4)(%r28)
lwz %r5,-16-(6*4)(%r28)
lwz %r6,-16-(5*4)(%r28)
bf- 5,1f
nop
lwz %r7,-16-(4*4)(%r28)
lwz %r8,-16-(3*4)(%r28)
lwz %r9,-16-(2*4)(%r28)
lwz %r10,-16-(1*4)(%r28)
nop
1:
/* Load all the FP registers. */
bf- 6,2f
lfd %f1,-16-(8*4)-(8*8)(%r28)
lfd %f2,-16-(8*4)-(7*8)(%r28)
lfd %f3,-16-(8*4)-(6*8)(%r28)
lfd %f4,-16-(8*4)-(5*8)(%r28)
nop
lfd %f5,-16-(8*4)-(4*8)(%r28)
lfd %f6,-16-(8*4)-(3*8)(%r28)
lfd %f7,-16-(8*4)-(2*8)(%r28)
lfd %f8,-16-(8*4)-(1*8)(%r28)
2:
/* Make the call. */
bctrl
/* Now, deal with the return value. */
mtcrf 0x01,%r31 /* cr7 */
bt- 31,L(small_struct_return_value)
bt- 30,L(done_return_value)
bt- 29,L(fp_return_value)
stw %r3,0(%r30)
bf+ 28,L(done_return_value)
stw %r4,4(%r30)
mtcrf 0x02,%r31 /* cr6 */
bf 27,L(done_return_value)
stw %r5,8(%r30)
stw %r6,12(%r30)
/* Fall through... */
L(done_return_value):
/* Restore the registers we used and return. */
lwz %r9, 4(%r28)
lwz %r31, -4(%r28)
mtlr %r9
lwz %r30, -8(%r28)
lwz %r29,-12(%r28)
lwz %r28,-16(%r28)
lwz %r1,0(%r1)
blr
L(fp_return_value):
bf 28,L(float_return_value)
stfd %f1,0(%r30)
mtcrf 0x02,%r31 /* cr6 */
bf 27,L(done_return_value)
stfd %f2,8(%r30)
b L(done_return_value)
L(float_return_value):
stfs %f1,0(%r30)
b L(done_return_value)
L(small_struct_return_value):
mtcrf 0x10,%r31 /* cr3 */
bt- 15,L(smst_one_register)
mtcrf 0x08,%r31 /* cr4 */
bt- 16,L(smst_two_register)
b L(done_return_value)
L(smst_one_register):
rlwinm %r5,%r31,5+23,32-5,31 /* Extract the value to shift. */
slw %r3,%r3,%r5
stw %r3,0(%r30)
b L(done_return_value)
L(smst_two_register):
rlwinm %r5,%r31,5+23,32-5,31 /* Extract the value to shift. */
cmpwi %r5,0
subfic %r9,%r5,32
slw %r29,%r3,%r5
srw %r9,%r4,%r9
beq- L(smst_8byte)
or %r3,%r9,%r29
slw %r4,%r4,%r5
L(smst_8byte):
stw %r3,0(%r30)
stw %r4,4(%r30)
b L(done_return_value)
.LFE1:
END(ffi_call_SYSV)
.section ".eh_frame",EH_FRAME_FLAGS,@progbits
.Lframe1:
.4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */
.LSCIE1:
.4byte 0x0 /* CIE Identifier Tag */
.byte 0x1 /* CIE Version */
#if defined _RELOCATABLE || defined __PIC__
.ascii "zR\0" /* CIE Augmentation */
#else
.ascii "\0" /* CIE Augmentation */
#endif
.uleb128 0x1 /* CIE Code Alignment Factor */
.sleb128 -4 /* CIE Data Alignment Factor */
.byte 0x41 /* CIE RA Column */
#if defined _RELOCATABLE || defined __PIC__
.uleb128 0x1 /* Augmentation size */
.byte 0x1b /* FDE Encoding (pcrel sdata4) */
#endif
.byte 0xc /* DW_CFA_def_cfa */
.uleb128 0x1
.uleb128 0x0
.align 2
.LECIE1:
.LSFDE1:
.4byte .LEFDE1-.LASFDE1 /* FDE Length */
.LASFDE1:
.4byte .LASFDE1-.Lframe1 /* FDE CIE offset */
#if defined _RELOCATABLE || defined __PIC__
.4byte .LFB1-. /* FDE initial location */
#else
.4byte .LFB1 /* FDE initial location */
#endif
.4byte .LFE1-.LFB1 /* FDE address range */
#if defined _RELOCATABLE || defined __PIC__
.uleb128 0x0 /* Augmentation size */
#endif
.byte 0x4 /* DW_CFA_advance_loc4 */
.4byte .LCFI0-.LFB1
.byte 0xd /* DW_CFA_def_cfa_register */
.uleb128 0x08
.byte 0x4 /* DW_CFA_advance_loc4 */
.4byte .LCFI5-.LCFI0
.byte 0x11 /* DW_CFA_offset_extended_sf */
.uleb128 0x41
.sleb128 -1
.byte 0x9f /* DW_CFA_offset, column 0x1f */
.uleb128 0x1
.byte 0x9e /* DW_CFA_offset, column 0x1e */
.uleb128 0x2
.byte 0x9d /* DW_CFA_offset, column 0x1d */
.uleb128 0x3
.byte 0x9c /* DW_CFA_offset, column 0x1c */
.uleb128 0x4
.byte 0x4 /* DW_CFA_advance_loc4 */
.4byte .LCFI6-.LCFI5
.byte 0xd /* DW_CFA_def_cfa_register */
.uleb128 0x1c
.align 2
.LEFDE1:
#endif
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",@progbits
#endif

View File

@@ -0,0 +1,174 @@
/* -----------------------------------------------------------------------
prep_cif.c - Copyright (c) 1996, 1998, 2007 Red Hat, Inc.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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>
/* Round up to FFI_SIZEOF_ARG. */
#define STACK_ARG_SIZE(x) ALIGN(x, FFI_SIZEOF_ARG)
/* Perform machine independent initialization of aggregate type
specifications. */
static ffi_status initialize_aggregate(ffi_type *arg)
{
ffi_type **ptr;
FFI_ASSERT(arg != NULL);
FFI_ASSERT(arg->elements != NULL);
FFI_ASSERT(arg->size == 0);
FFI_ASSERT(arg->alignment == 0);
ptr = &(arg->elements[0]);
while ((*ptr) != NULL)
{
if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK))
return FFI_BAD_TYPEDEF;
/* Perform a sanity check on the argument type */
FFI_ASSERT_VALID_TYPE(*ptr);
arg->size = ALIGN(arg->size, (*ptr)->alignment);
arg->size += (*ptr)->size;
arg->alignment = (arg->alignment > (*ptr)->alignment) ?
arg->alignment : (*ptr)->alignment;
ptr++;
}
/* Structure size includes tail padding. This is important for
structures that fit in one register on ABIs like the PowerPC64
Linux ABI that right justify small structs in a register.
It's also needed for nested structure layout, for example
struct A { long a; char b; }; struct B { struct A x; char y; };
should find y at an offset of 2*sizeof(long) and result in a
total size of 3*sizeof(long). */
arg->size = ALIGN (arg->size, arg->alignment);
if (arg->size == 0)
return FFI_BAD_TYPEDEF;
else
return FFI_OK;
}
#ifndef __CRIS__
/* The CRIS ABI specifies structure elements to have byte
alignment only, so it completely overrides this functions,
which assumes "natural" alignment and padding. */
/* Perform machine independent ffi_cif preparation, then call
machine dependent routine. */
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
ffi_type *rtype, ffi_type **atypes)
{
unsigned bytes = 0;
unsigned int i;
ffi_type **ptr;
FFI_ASSERT(cif != NULL);
FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
cif->abi = abi;
cif->arg_types = atypes;
cif->nargs = nargs;
cif->rtype = rtype;
cif->flags = 0;
/* Initialize the return type if necessary */
if ((cif->rtype->size == 0) && (initialize_aggregate(cif->rtype) != FFI_OK))
return FFI_BAD_TYPEDEF;
/* Perform a sanity check on the return type */
FFI_ASSERT_VALID_TYPE(cif->rtype);
/* x86-64 and s390 stack space allocation is handled in prep_machdep. */
#if !defined M68K && !defined __x86_64__ && !defined S390 && !defined PA
/* Make space for the return structure pointer */
if (cif->rtype->type == FFI_TYPE_STRUCT
#ifdef SPARC
&& (cif->abi != FFI_V9 || cif->rtype->size > 32)
#endif
#ifdef X86_DARWIN
&& (cif->rtype->size > 8)
#endif
)
bytes = STACK_ARG_SIZE(sizeof(void*));
#endif
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
/* Initialize any uninitialized aggregate type definitions */
if (((*ptr)->size == 0) && (initialize_aggregate((*ptr)) != FFI_OK))
return FFI_BAD_TYPEDEF;
/* Perform a sanity check on the argument type, do this
check after the initialization. */
FFI_ASSERT_VALID_TYPE(*ptr);
#if !defined __x86_64__ && !defined S390 && !defined PA
#ifdef SPARC
if (((*ptr)->type == FFI_TYPE_STRUCT
&& ((*ptr)->size > 16 || cif->abi != FFI_V9))
|| ((*ptr)->type == FFI_TYPE_LONGDOUBLE
&& cif->abi != FFI_V9))
bytes += sizeof(void*);
else
#endif
{
/* Add any padding if necessary */
if (((*ptr)->alignment - 1) & bytes)
bytes = ALIGN(bytes, (*ptr)->alignment);
bytes += STACK_ARG_SIZE((*ptr)->size);
}
#endif
}
cif->bytes = bytes;
/* Perform machine dependent cif processing */
return ffi_prep_cif_machdep(cif);
}
#endif /* not __CRIS__ */
#if FFI_CLOSURES
ffi_status
ffi_prep_closure (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data)
{
return ffi_prep_closure_loc (closure, cif, fun, user_data, closure);
}
#endif

View File

@@ -0,0 +1,254 @@
/* -----------------------------------------------------------------------
raw_api.c - Copyright (c) 1999, 2008 Red Hat, Inc.
Author: Kresten Krab Thorup <krab@gnu.org>
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
/* This file defines generic functions for use with the raw api. */
#include <ffi.h>
#include <ffi_common.h>
#if !FFI_NO_RAW_API
size_t
ffi_raw_size (ffi_cif *cif)
{
size_t result = 0;
int i;
ffi_type **at = cif->arg_types;
for (i = cif->nargs-1; i >= 0; i--, at++)
{
#if !FFI_NO_STRUCTS
if ((*at)->type == FFI_TYPE_STRUCT)
result += ALIGN (sizeof (void*), FFI_SIZEOF_ARG);
else
#endif
result += ALIGN ((*at)->size, FFI_SIZEOF_ARG);
}
return result;
}
void
ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
{
unsigned i;
ffi_type **tp = cif->arg_types;
#if WORDS_BIGENDIAN
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
switch ((*tp)->type)
{
case FFI_TYPE_UINT8:
case FFI_TYPE_SINT8:
*args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 1);
break;
case FFI_TYPE_UINT16:
case FFI_TYPE_SINT16:
*args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 2);
break;
#if FFI_SIZEOF_ARG >= 4
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
*args = (void*) ((char*)(raw++) + FFI_SIZEOF_ARG - 4);
break;
#endif
#if !FFI_NO_STRUCTS
case FFI_TYPE_STRUCT:
*args = (raw++)->ptr;
break;
#endif
case FFI_TYPE_POINTER:
*args = (void*) &(raw++)->ptr;
break;
default:
*args = raw;
raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
}
}
#else /* WORDS_BIGENDIAN */
#if !PDP
/* then assume little endian */
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
#if !FFI_NO_STRUCTS
if ((*tp)->type == FFI_TYPE_STRUCT)
{
*args = (raw++)->ptr;
}
else
#endif
{
*args = (void*) raw;
raw += ALIGN ((*tp)->size, sizeof (void*)) / sizeof (void*);
}
}
#else
#error "pdp endian not supported"
#endif /* ! PDP */
#endif /* WORDS_BIGENDIAN */
}
void
ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
{
unsigned i;
ffi_type **tp = cif->arg_types;
for (i = 0; i < cif->nargs; i++, tp++, args++)
{
switch ((*tp)->type)
{
case FFI_TYPE_UINT8:
(raw++)->uint = *(UINT8*) (*args);
break;
case FFI_TYPE_SINT8:
(raw++)->sint = *(SINT8*) (*args);
break;
case FFI_TYPE_UINT16:
(raw++)->uint = *(UINT16*) (*args);
break;
case FFI_TYPE_SINT16:
(raw++)->sint = *(SINT16*) (*args);
break;
#if FFI_SIZEOF_ARG >= 4
case FFI_TYPE_UINT32:
(raw++)->uint = *(UINT32*) (*args);
break;
case FFI_TYPE_SINT32:
(raw++)->sint = *(SINT32*) (*args);
break;
#endif
#if !FFI_NO_STRUCTS
case FFI_TYPE_STRUCT:
(raw++)->ptr = *args;
break;
#endif
case FFI_TYPE_POINTER:
(raw++)->ptr = **(void***) args;
break;
default:
memcpy ((void*) raw->data, (void*)*args, (*tp)->size);
raw += ALIGN ((*tp)->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
}
}
}
#if !FFI_NATIVE_RAW_API
/* This is a generic definition of ffi_raw_call, to be used if the
* native system does not provide a machine-specific implementation.
* Having this, allows code to be written for the raw API, without
* the need for system-specific code to handle input in that format;
* these following couple of functions will handle the translation forth
* and back automatically. */
void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_raw_to_ptrarray (cif, raw, avalue);
ffi_call (cif, fn, rvalue, avalue);
}
#if FFI_CLOSURES /* base system provides closures */
static void
ffi_translate_args (ffi_cif *cif, void *rvalue,
void **avalue, void *user_data)
{
ffi_raw *raw = (ffi_raw*)alloca (ffi_raw_size (cif));
ffi_raw_closure *cl = (ffi_raw_closure*)user_data;
ffi_ptrarray_to_raw (cif, avalue, raw);
(*cl->fun) (cif, rvalue, raw, cl->user_data);
}
ffi_status
ffi_prep_raw_closure_loc (ffi_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data,
void *codeloc)
{
ffi_status status;
status = ffi_prep_closure_loc ((ffi_closure*) cl,
cif,
&ffi_translate_args,
codeloc,
codeloc);
if (status == FFI_OK)
{
cl->fun = fun;
cl->user_data = user_data;
}
return status;
}
#endif /* FFI_CLOSURES */
#endif /* !FFI_NATIVE_RAW_API */
#if FFI_CLOSURES
/* Again, here is the generic version of ffi_prep_raw_closure, which
* will install an intermediate "hub" for translation of arguments from
* the pointer-array format, to the raw format */
ffi_status
ffi_prep_raw_closure (ffi_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data)
{
return ffi_prep_raw_closure_loc (cl, cif, fun, user_data, cl);
}
#endif /* FFI_CLOSURES */
#endif /* !FFI_NO_RAW_API */

View File

@@ -0,0 +1,780 @@
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 2000, 2007 Software AG
Copyright (c) 2008 Red Hat, Inc
S390 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 THE AUTHOR 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.
----------------------------------------------------------------------- */
/*====================================================================*/
/* Includes */
/* -------- */
/*====================================================================*/
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
#include <stdio.h>
/*====================== End of Includes =============================*/
/*====================================================================*/
/* Defines */
/* ------- */
/*====================================================================*/
/* Maximum number of GPRs available for argument passing. */
#define MAX_GPRARGS 5
/* Maximum number of FPRs available for argument passing. */
#ifdef __s390x__
#define MAX_FPRARGS 4
#else
#define MAX_FPRARGS 2
#endif
/* Round to multiple of 16. */
#define ROUND_SIZE(size) (((size) + 15) & ~15)
/* If these values change, sysv.S must be adapted! */
#define FFI390_RET_VOID 0
#define FFI390_RET_STRUCT 1
#define FFI390_RET_FLOAT 2
#define FFI390_RET_DOUBLE 3
#define FFI390_RET_INT32 4
#define FFI390_RET_INT64 5
/*===================== End of Defines ===============================*/
/*====================================================================*/
/* Prototypes */
/* ---------- */
/*====================================================================*/
static void ffi_prep_args (unsigned char *, extended_cif *);
void
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
__attribute__ ((visibility ("hidden")))
#endif
ffi_closure_helper_SYSV (ffi_closure *, unsigned long *,
unsigned long long *, unsigned long *);
/*====================== End of Prototypes ===========================*/
/*====================================================================*/
/* Externals */
/* --------- */
/*====================================================================*/
extern void ffi_call_SYSV(unsigned,
extended_cif *,
void (*)(unsigned char *, extended_cif *),
unsigned,
void *,
void (*fn)(void));
extern void ffi_closure_SYSV(void);
/*====================== End of Externals ============================*/
/*====================================================================*/
/* */
/* Name - ffi_check_struct_type. */
/* */
/* Function - Determine if a structure can be passed within a */
/* general purpose or floating point register. */
/* */
/*====================================================================*/
static int
ffi_check_struct_type (ffi_type *arg)
{
size_t size = arg->size;
/* If the struct has just one element, look at that element
to find out whether to consider the struct as floating point. */
while (arg->type == FFI_TYPE_STRUCT
&& arg->elements[0] && !arg->elements[1])
arg = arg->elements[0];
/* Structs of size 1, 2, 4, and 8 are passed in registers,
just like the corresponding int/float types. */
switch (size)
{
case 1:
return FFI_TYPE_UINT8;
case 2:
return FFI_TYPE_UINT16;
case 4:
if (arg->type == FFI_TYPE_FLOAT)
return FFI_TYPE_FLOAT;
else
return FFI_TYPE_UINT32;
case 8:
if (arg->type == FFI_TYPE_DOUBLE)
return FFI_TYPE_DOUBLE;
else
return FFI_TYPE_UINT64;
default:
break;
}
/* Other structs are passed via a pointer to the data. */
return FFI_TYPE_POINTER;
}
/*======================== End of Routine ============================*/
/*====================================================================*/
/* */
/* Name - ffi_prep_args. */
/* */
/* Function - Prepare parameters for call to function. */
/* */
/* ffi_prep_args is called by the assembly routine once stack space */
/* has been allocated for the function's arguments. */
/* */
/*====================================================================*/
static void
ffi_prep_args (unsigned char *stack, extended_cif *ecif)
{
/* The stack space will be filled with those areas:
FPR argument register save area (highest addresses)
GPR argument register save area
temporary struct copies
overflow argument area (lowest addresses)
We set up the following pointers:
p_fpr: bottom of the FPR area (growing upwards)
p_gpr: bottom of the GPR area (growing upwards)
p_ov: bottom of the overflow area (growing upwards)
p_struct: top of the struct copy area (growing downwards)
All areas are kept aligned to twice the word size. */
int gpr_off = ecif->cif->bytes;
int fpr_off = gpr_off + ROUND_SIZE (MAX_GPRARGS * sizeof (long));
unsigned long long *p_fpr = (unsigned long long *)(stack + fpr_off);
unsigned long *p_gpr = (unsigned long *)(stack + gpr_off);
unsigned char *p_struct = (unsigned char *)p_gpr;
unsigned long *p_ov = (unsigned long *)stack;
int n_fpr = 0;
int n_gpr = 0;
int n_ov = 0;
ffi_type **ptr;
void **p_argv = ecif->avalue;
int i;
/* If we returning a structure then we set the first parameter register
to the address of where we are returning this structure. */
if (ecif->cif->flags == FFI390_RET_STRUCT)
p_gpr[n_gpr++] = (unsigned long) ecif->rvalue;
/* Now for the arguments. */
for (ptr = ecif->cif->arg_types, i = ecif->cif->nargs;
i > 0;
i--, ptr++, p_argv++)
{
void *arg = *p_argv;
int type = (*ptr)->type;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
/* 16-byte long double is passed like a struct. */
if (type == FFI_TYPE_LONGDOUBLE)
type = FFI_TYPE_STRUCT;
#endif
/* Check how a structure type is passed. */
if (type == FFI_TYPE_STRUCT)
{
type = ffi_check_struct_type (*ptr);
/* If we pass the struct via pointer, copy the data. */
if (type == FFI_TYPE_POINTER)
{
p_struct -= ROUND_SIZE ((*ptr)->size);
memcpy (p_struct, (char *)arg, (*ptr)->size);
arg = &p_struct;
}
}
/* Now handle all primitive int/pointer/float data types. */
switch (type)
{
case FFI_TYPE_DOUBLE:
if (n_fpr < MAX_FPRARGS)
p_fpr[n_fpr++] = *(unsigned long long *) arg;
else
#ifdef __s390x__
p_ov[n_ov++] = *(unsigned long *) arg;
#else
p_ov[n_ov++] = ((unsigned long *) arg)[0],
p_ov[n_ov++] = ((unsigned long *) arg)[1];
#endif
break;
case FFI_TYPE_FLOAT:
if (n_fpr < MAX_FPRARGS)
p_fpr[n_fpr++] = (long long) *(unsigned int *) arg << 32;
else
p_ov[n_ov++] = *(unsigned int *) arg;
break;
case FFI_TYPE_POINTER:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = (unsigned long)*(unsigned char **) arg;
else
p_ov[n_ov++] = (unsigned long)*(unsigned char **) arg;
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
#ifdef __s390x__
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(unsigned long *) arg;
else
p_ov[n_ov++] = *(unsigned long *) arg;
#else
if (n_gpr == MAX_GPRARGS-1)
n_gpr = MAX_GPRARGS;
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = ((unsigned long *) arg)[0],
p_gpr[n_gpr++] = ((unsigned long *) arg)[1];
else
p_ov[n_ov++] = ((unsigned long *) arg)[0],
p_ov[n_ov++] = ((unsigned long *) arg)[1];
#endif
break;
case FFI_TYPE_UINT32:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(unsigned int *) arg;
else
p_ov[n_ov++] = *(unsigned int *) arg;
break;
case FFI_TYPE_INT:
case FFI_TYPE_SINT32:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(signed int *) arg;
else
p_ov[n_ov++] = *(signed int *) arg;
break;
case FFI_TYPE_UINT16:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(unsigned short *) arg;
else
p_ov[n_ov++] = *(unsigned short *) arg;
break;
case FFI_TYPE_SINT16:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(signed short *) arg;
else
p_ov[n_ov++] = *(signed short *) arg;
break;
case FFI_TYPE_UINT8:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(unsigned char *) arg;
else
p_ov[n_ov++] = *(unsigned char *) arg;
break;
case FFI_TYPE_SINT8:
if (n_gpr < MAX_GPRARGS)
p_gpr[n_gpr++] = *(signed char *) arg;
else
p_ov[n_ov++] = *(signed char *) arg;
break;
default:
FFI_ASSERT (0);
break;
}
}
}
/*======================== End of Routine ============================*/
/*====================================================================*/
/* */
/* Name - ffi_prep_cif_machdep. */
/* */
/* Function - Perform machine dependent CIF processing. */
/* */
/*====================================================================*/
ffi_status
ffi_prep_cif_machdep(ffi_cif *cif)
{
size_t struct_size = 0;
int n_gpr = 0;
int n_fpr = 0;
int n_ov = 0;
ffi_type **ptr;
int i;
/* Determine return value handling. */
switch (cif->rtype->type)
{
/* Void is easy. */
case FFI_TYPE_VOID:
cif->flags = FFI390_RET_VOID;
break;
/* Structures are returned via a hidden pointer. */
case FFI_TYPE_STRUCT:
cif->flags = FFI390_RET_STRUCT;
n_gpr++; /* We need one GPR to pass the pointer. */
break;
/* Floating point values are returned in fpr 0. */
case FFI_TYPE_FLOAT:
cif->flags = FFI390_RET_FLOAT;
break;
case FFI_TYPE_DOUBLE:
cif->flags = FFI390_RET_DOUBLE;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
cif->flags = FFI390_RET_STRUCT;
n_gpr++;
break;
#endif
/* Integer values are returned in gpr 2 (and gpr 3
for 64-bit values on 31-bit machines). */
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
cif->flags = FFI390_RET_INT64;
break;
case FFI_TYPE_POINTER:
case FFI_TYPE_INT:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT16:
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT8:
case FFI_TYPE_SINT8:
/* These are to be extended to word size. */
#ifdef __s390x__
cif->flags = FFI390_RET_INT64;
#else
cif->flags = FFI390_RET_INT32;
#endif
break;
default:
FFI_ASSERT (0);
break;
}
/* Now for the arguments. */
for (ptr = cif->arg_types, i = cif->nargs;
i > 0;
i--, ptr++)
{
int type = (*ptr)->type;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
/* 16-byte long double is passed like a struct. */
if (type == FFI_TYPE_LONGDOUBLE)
type = FFI_TYPE_STRUCT;
#endif
/* Check how a structure type is passed. */
if (type == FFI_TYPE_STRUCT)
{
type = ffi_check_struct_type (*ptr);
/* If we pass the struct via pointer, we must reserve space
to copy its data for proper call-by-value semantics. */
if (type == FFI_TYPE_POINTER)
struct_size += ROUND_SIZE ((*ptr)->size);
}
/* Now handle all primitive int/float data types. */
switch (type)
{
/* The first MAX_FPRARGS floating point arguments
go in FPRs, the rest overflow to the stack. */
case FFI_TYPE_DOUBLE:
if (n_fpr < MAX_FPRARGS)
n_fpr++;
else
n_ov += sizeof (double) / sizeof (long);
break;
case FFI_TYPE_FLOAT:
if (n_fpr < MAX_FPRARGS)
n_fpr++;
else
n_ov++;
break;
/* On 31-bit machines, 64-bit integers are passed in GPR pairs,
if one is still available, or else on the stack. If only one
register is free, skip the register (it won't be used for any
subsequent argument either). */
#ifndef __s390x__
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
if (n_gpr == MAX_GPRARGS-1)
n_gpr = MAX_GPRARGS;
if (n_gpr < MAX_GPRARGS)
n_gpr += 2;
else
n_ov += 2;
break;
#endif
/* Everything else is passed in GPRs (until MAX_GPRARGS
have been used) or overflows to the stack. */
default:
if (n_gpr < MAX_GPRARGS)
n_gpr++;
else
n_ov++;
break;
}
}
/* Total stack space as required for overflow arguments
and temporary structure copies. */
cif->bytes = ROUND_SIZE (n_ov * sizeof (long)) + struct_size;
return FFI_OK;
}
/*======================== End of Routine ============================*/
/*====================================================================*/
/* */
/* Name - ffi_call. */
/* */
/* Function - Call the FFI routine. */
/* */
/*====================================================================*/
void
ffi_call(ffi_cif *cif,
void (*fn)(void),
void *rvalue,
void **avalue)
{
int ret_type = cif->flags;
extended_cif ecif;
ecif.cif = cif;
ecif.avalue = avalue;
ecif.rvalue = rvalue;
/* If we don't have a return value, we need to fake one. */
if (rvalue == NULL)
{
if (ret_type == FFI390_RET_STRUCT)
ecif.rvalue = alloca (cif->rtype->size);
else
ret_type = FFI390_RET_VOID;
}
switch (cif->abi)
{
case FFI_SYSV:
ffi_call_SYSV (cif->bytes, &ecif, ffi_prep_args,
ret_type, ecif.rvalue, fn);
break;
default:
FFI_ASSERT (0);
break;
}
}
/*======================== End of Routine ============================*/
/*====================================================================*/
/* */
/* Name - ffi_closure_helper_SYSV. */
/* */
/* Function - Call a FFI closure target function. */
/* */
/*====================================================================*/
void
ffi_closure_helper_SYSV (ffi_closure *closure,
unsigned long *p_gpr,
unsigned long long *p_fpr,
unsigned long *p_ov)
{
unsigned long long ret_buffer;
void *rvalue = &ret_buffer;
void **avalue;
void **p_arg;
int n_gpr = 0;
int n_fpr = 0;
int n_ov = 0;
ffi_type **ptr;
int i;
/* Allocate buffer for argument list pointers. */
p_arg = avalue = alloca (closure->cif->nargs * sizeof (void *));
/* If we returning a structure, pass the structure address
directly to the target function. Otherwise, have the target
function store the return value to the GPR save area. */
if (closure->cif->flags == FFI390_RET_STRUCT)
rvalue = (void *) p_gpr[n_gpr++];
/* Now for the arguments. */
for (ptr = closure->cif->arg_types, i = closure->cif->nargs;
i > 0;
i--, p_arg++, ptr++)
{
int deref_struct_pointer = 0;
int type = (*ptr)->type;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
/* 16-byte long double is passed like a struct. */
if (type == FFI_TYPE_LONGDOUBLE)
type = FFI_TYPE_STRUCT;
#endif
/* Check how a structure type is passed. */
if (type == FFI_TYPE_STRUCT)
{
type = ffi_check_struct_type (*ptr);
/* If we pass the struct via pointer, remember to
retrieve the pointer later. */
if (type == FFI_TYPE_POINTER)
deref_struct_pointer = 1;
}
/* Pointers are passed like UINTs of the same size. */
if (type == FFI_TYPE_POINTER)
#ifdef __s390x__
type = FFI_TYPE_UINT64;
#else
type = FFI_TYPE_UINT32;
#endif
/* Now handle all primitive int/float data types. */
switch (type)
{
case FFI_TYPE_DOUBLE:
if (n_fpr < MAX_FPRARGS)
*p_arg = &p_fpr[n_fpr++];
else
*p_arg = &p_ov[n_ov],
n_ov += sizeof (double) / sizeof (long);
break;
case FFI_TYPE_FLOAT:
if (n_fpr < MAX_FPRARGS)
*p_arg = &p_fpr[n_fpr++];
else
*p_arg = (char *)&p_ov[n_ov++] + sizeof (long) - 4;
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
#ifdef __s390x__
if (n_gpr < MAX_GPRARGS)
*p_arg = &p_gpr[n_gpr++];
else
*p_arg = &p_ov[n_ov++];
#else
if (n_gpr == MAX_GPRARGS-1)
n_gpr = MAX_GPRARGS;
if (n_gpr < MAX_GPRARGS)
*p_arg = &p_gpr[n_gpr], n_gpr += 2;
else
*p_arg = &p_ov[n_ov], n_ov += 2;
#endif
break;
case FFI_TYPE_INT:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
if (n_gpr < MAX_GPRARGS)
*p_arg = (char *)&p_gpr[n_gpr++] + sizeof (long) - 4;
else
*p_arg = (char *)&p_ov[n_ov++] + sizeof (long) - 4;
break;
case FFI_TYPE_UINT16:
case FFI_TYPE_SINT16:
if (n_gpr < MAX_GPRARGS)
*p_arg = (char *)&p_gpr[n_gpr++] + sizeof (long) - 2;
else
*p_arg = (char *)&p_ov[n_ov++] + sizeof (long) - 2;
break;
case FFI_TYPE_UINT8:
case FFI_TYPE_SINT8:
if (n_gpr < MAX_GPRARGS)
*p_arg = (char *)&p_gpr[n_gpr++] + sizeof (long) - 1;
else
*p_arg = (char *)&p_ov[n_ov++] + sizeof (long) - 1;
break;
default:
FFI_ASSERT (0);
break;
}
/* If this is a struct passed via pointer, we need to
actually retrieve that pointer. */
if (deref_struct_pointer)
*p_arg = *(void **)*p_arg;
}
/* Call the target function. */
(closure->fun) (closure->cif, rvalue, avalue, closure->user_data);
/* Convert the return value. */
switch (closure->cif->rtype->type)
{
/* Void is easy, and so is struct. */
case FFI_TYPE_VOID:
case FFI_TYPE_STRUCT:
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
#endif
break;
/* Floating point values are returned in fpr 0. */
case FFI_TYPE_FLOAT:
p_fpr[0] = (long long) *(unsigned int *) rvalue << 32;
break;
case FFI_TYPE_DOUBLE:
p_fpr[0] = *(unsigned long long *) rvalue;
break;
/* Integer values are returned in gpr 2 (and gpr 3
for 64-bit values on 31-bit machines). */
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
#ifdef __s390x__
p_gpr[0] = *(unsigned long *) rvalue;
#else
p_gpr[0] = ((unsigned long *) rvalue)[0],
p_gpr[1] = ((unsigned long *) rvalue)[1];
#endif
break;
case FFI_TYPE_POINTER:
case FFI_TYPE_UINT32:
case FFI_TYPE_UINT16:
case FFI_TYPE_UINT8:
p_gpr[0] = *(unsigned long *) rvalue;
break;
case FFI_TYPE_INT:
case FFI_TYPE_SINT32:
case FFI_TYPE_SINT16:
case FFI_TYPE_SINT8:
p_gpr[0] = *(signed long *) rvalue;
break;
default:
FFI_ASSERT (0);
break;
}
}
/*======================== End of Routine ============================*/
/*====================================================================*/
/* */
/* Name - ffi_prep_closure_loc. */
/* */
/* Function - Prepare a FFI closure. */
/* */
/*====================================================================*/
ffi_status
ffi_prep_closure_loc (ffi_closure *closure,
ffi_cif *cif,
void (*fun) (ffi_cif *, void *, void **, void *),
void *user_data,
void *codeloc)
{
FFI_ASSERT (cif->abi == FFI_SYSV);
#ifndef __s390x__
*(short *)&closure->tramp [0] = 0x0d10; /* basr %r1,0 */
*(short *)&closure->tramp [2] = 0x9801; /* lm %r0,%r1,6(%r1) */
*(short *)&closure->tramp [4] = 0x1006;
*(short *)&closure->tramp [6] = 0x07f1; /* br %r1 */
*(long *)&closure->tramp [8] = (long)codeloc;
*(long *)&closure->tramp[12] = (long)&ffi_closure_SYSV;
#else
*(short *)&closure->tramp [0] = 0x0d10; /* basr %r1,0 */
*(short *)&closure->tramp [2] = 0xeb01; /* lmg %r0,%r1,14(%r1) */
*(short *)&closure->tramp [4] = 0x100e;
*(short *)&closure->tramp [6] = 0x0004;
*(short *)&closure->tramp [8] = 0x07f1; /* br %r1 */
*(long *)&closure->tramp[16] = (long)codeloc;
*(long *)&closure->tramp[24] = (long)&ffi_closure_SYSV;
#endif
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
return FFI_OK;
}
/*======================== End of Routine ============================*/

View File

@@ -0,0 +1,60 @@
/* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Target configuration macros for S390.
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 THE AUTHORS OR COPYRIGHT
HOLDERS 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.
----------------------------------------------------------------------- */
#ifndef LIBFFI_TARGET_H
#define LIBFFI_TARGET_H
#if defined (__s390x__)
#define S390X
#endif
/* ---- System specific configurations ----------------------------------- */
#ifndef LIBFFI_ASM
typedef unsigned long ffi_arg;
typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
FFI_SYSV,
FFI_DEFAULT_ABI = FFI_SYSV,
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
} ffi_abi;
#endif
/* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1
#ifdef S390X
#define FFI_TRAMPOLINE_SIZE 32
#else
#define FFI_TRAMPOLINE_SIZE 16
#endif
#define FFI_NATIVE_RAW_API 0
#endif

Some files were not shown because too many files have changed in this diff Show More