Home | History | Annotate | Download | only in powerpc
      1 /* -----------------------------------------------------------------*-C-*-
      2    ffitarget.h - Copyright (c) 2012  Anthony Green
      3                  Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc
      4                  Copyright (c) 1996-2003  Red Hat, Inc.
      5 
      6    Target configuration macros for PowerPC.
      7 
      8    Permission is hereby granted, free of charge, to any person obtaining
      9    a copy of this software and associated documentation files (the
     10    ``Software''), to deal in the Software without restriction, including
     11    without limitation the rights to use, copy, modify, merge, publish,
     12    distribute, sublicense, and/or sell copies of the Software, and to
     13    permit persons to whom the Software is furnished to do so, subject to
     14    the following conditions:
     15 
     16    The above copyright notice and this permission notice shall be included
     17    in all copies or substantial portions of the Software.
     18 
     19    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
     20    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     22    NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
     23    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     24    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     25    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     26    DEALINGS IN THE SOFTWARE.
     27 
     28    ----------------------------------------------------------------------- */
     29 
     30 #ifndef LIBFFI_TARGET_H
     31 #define LIBFFI_TARGET_H
     32 
     33 #ifndef LIBFFI_H
     34 #error "Please do not include ffitarget.h directly into your source.  Use ffi.h instead."
     35 #endif
     36 
     37 /* ---- System specific configurations ----------------------------------- */
     38 
     39 #if defined (POWERPC) && defined (__powerpc64__)	/* linux64 */
     40 #ifndef POWERPC64
     41 #define POWERPC64
     42 #endif
     43 #elif defined (POWERPC_DARWIN) && defined (__ppc64__)	/* Darwin64 */
     44 #ifndef POWERPC64
     45 #define POWERPC64
     46 #endif
     47 #ifndef POWERPC_DARWIN64
     48 #define POWERPC_DARWIN64
     49 #endif
     50 #elif defined (POWERPC_AIX) && defined (__64BIT__)	/* AIX64 */
     51 #ifndef POWERPC64
     52 #define POWERPC64
     53 #endif
     54 #endif
     55 
     56 #ifndef LIBFFI_ASM
     57 typedef unsigned long          ffi_arg;
     58 typedef signed long            ffi_sarg;
     59 
     60 typedef enum ffi_abi {
     61   FFI_FIRST_ABI = 0,
     62 
     63 #if defined (POWERPC_AIX)
     64   FFI_AIX,
     65   FFI_DARWIN,
     66   FFI_DEFAULT_ABI = FFI_AIX,
     67   FFI_LAST_ABI
     68 
     69 #elif defined (POWERPC_DARWIN)
     70   FFI_AIX,
     71   FFI_DARWIN,
     72   FFI_DEFAULT_ABI = FFI_DARWIN,
     73   FFI_LAST_ABI
     74 
     75 #else
     76   /* The FFI_COMPAT values are used by old code.  Since libffi may be
     77      a shared library we have to support old values for backwards
     78      compatibility.  */
     79   FFI_COMPAT_SYSV,
     80   FFI_COMPAT_GCC_SYSV,
     81   FFI_COMPAT_LINUX64,
     82   FFI_COMPAT_LINUX,
     83   FFI_COMPAT_LINUX_SOFT_FLOAT,
     84 
     85 # if defined (POWERPC64)
     86   /* This bit, always set in new code, must not be set in any of the
     87      old FFI_COMPAT values that might be used for 64-bit linux.  We
     88      only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
     89      all old values.  */
     90   FFI_LINUX = 8,
     91   /* This and following bits can reuse FFI_COMPAT values.  */
     92   FFI_LINUX_STRUCT_ALIGN = 1,
     93   FFI_LINUX_LONG_DOUBLE_128 = 2,
     94   FFI_DEFAULT_ABI = (FFI_LINUX
     95 #  ifdef __STRUCT_PARM_ALIGN__
     96 		     | FFI_LINUX_STRUCT_ALIGN
     97 #  endif
     98 #  ifdef __LONG_DOUBLE_128__
     99 		     | FFI_LINUX_LONG_DOUBLE_128
    100 #  endif
    101 		     ),
    102   FFI_LAST_ABI = 12
    103 
    104 # else
    105   /* This bit, always set in new code, must not be set in any of the
    106      old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd.  */
    107   FFI_SYSV = 8,
    108   /* This and following bits can reuse FFI_COMPAT values.  */
    109   FFI_SYSV_SOFT_FLOAT = 1,
    110   FFI_SYSV_STRUCT_RET = 2,
    111   FFI_SYSV_IBM_LONG_DOUBLE = 4,
    112   FFI_SYSV_LONG_DOUBLE_128 = 16,
    113 
    114   FFI_DEFAULT_ABI = (FFI_SYSV
    115 #  ifdef __NO_FPRS__
    116 		     | FFI_SYSV_SOFT_FLOAT
    117 #  endif
    118 #  if (defined (__SVR4_STRUCT_RETURN)					\
    119        || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
    120 		     | FFI_SYSV_STRUCT_RET
    121 #  endif
    122 #  if __LDBL_MANT_DIG__ == 106
    123 		     | FFI_SYSV_IBM_LONG_DOUBLE
    124 #  endif
    125 #  ifdef __LONG_DOUBLE_128__
    126 		     | FFI_SYSV_LONG_DOUBLE_128
    127 #  endif
    128 		     ),
    129   FFI_LAST_ABI = 32
    130 # endif
    131 #endif
    132 
    133 } ffi_abi;
    134 #endif
    135 
    136 /* ---- Definitions for closures ----------------------------------------- */
    137 
    138 #define FFI_CLOSURES 1
    139 #define FFI_NATIVE_RAW_API 0
    140 #if defined (POWERPC) || defined (POWERPC_FREEBSD)
    141 # define FFI_TARGET_SPECIFIC_VARIADIC 1
    142 # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
    143 #endif
    144 
    145 /* For additional types like the below, take care about the order in
    146    ppc_closures.S. They must follow after the FFI_TYPE_LAST.  */
    147 
    148 /* Needed for soft-float long-double-128 support.  */
    149 #define FFI_TYPE_UINT128 (FFI_TYPE_LAST + 1)
    150 
    151 /* Needed for FFI_SYSV small structure returns.  */
    152 #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 2)
    153 
    154 /* Used by ELFv2 for homogenous structure returns.  */
    155 #define FFI_V2_TYPE_FLOAT_HOMOG		(FFI_TYPE_LAST + 1)
    156 #define FFI_V2_TYPE_DOUBLE_HOMOG	(FFI_TYPE_LAST + 2)
    157 #define FFI_V2_TYPE_SMALL_STRUCT	(FFI_TYPE_LAST + 3)
    158 
    159 #if _CALL_ELF == 2
    160 # define FFI_TRAMPOLINE_SIZE 32
    161 #else
    162 # if defined(POWERPC64) || defined(POWERPC_AIX)
    163 #  if defined(POWERPC_DARWIN64)
    164 #    define FFI_TRAMPOLINE_SIZE 48
    165 #  else
    166 #    define FFI_TRAMPOLINE_SIZE 24
    167 #  endif
    168 # else /* POWERPC || POWERPC_AIX */
    169 #  define FFI_TRAMPOLINE_SIZE 40
    170 # endif
    171 #endif
    172 
    173 #ifndef LIBFFI_ASM
    174 #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
    175 struct ffi_aix_trampoline_struct {
    176     void * code_pointer;	/* Pointer to ffi_closure_ASM */
    177     void * toc;			/* TOC */
    178     void * static_chain;	/* Pointer to closure */
    179 };
    180 #endif
    181 #endif
    182 
    183 #endif
    184