• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_LINUX_LONG_DOUBLE_IEEE128 = 4,
95   FFI_DEFAULT_ABI = (FFI_LINUX
96 #  ifdef __STRUCT_PARM_ALIGN__
97 		     | FFI_LINUX_STRUCT_ALIGN
98 #  endif
99 #  ifdef __LONG_DOUBLE_128__
100 		     | FFI_LINUX_LONG_DOUBLE_128
101 #   ifdef __LONG_DOUBLE_IEEE128__
102 		     | FFI_LINUX_LONG_DOUBLE_IEEE128
103 #   endif
104 #  endif
105 		     ),
106   FFI_LAST_ABI = 16
107 
108 # else
109   /* This bit, always set in new code, must not be set in any of the
110      old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd.  */
111   FFI_SYSV = 8,
112   /* This and following bits can reuse FFI_COMPAT values.  */
113   FFI_SYSV_SOFT_FLOAT = 1,
114   FFI_SYSV_STRUCT_RET = 2,
115   FFI_SYSV_IBM_LONG_DOUBLE = 4,
116   FFI_SYSV_LONG_DOUBLE_128 = 16,
117 
118   FFI_DEFAULT_ABI = (FFI_SYSV
119 #  ifdef __NO_FPRS__
120 		     | FFI_SYSV_SOFT_FLOAT
121 #  endif
122 #  if (defined (__SVR4_STRUCT_RETURN)					\
123        || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
124 		     | FFI_SYSV_STRUCT_RET
125 #  endif
126 #  if __LDBL_MANT_DIG__ == 106
127 		     | FFI_SYSV_IBM_LONG_DOUBLE
128 #  endif
129 #  ifdef __LONG_DOUBLE_128__
130 		     | FFI_SYSV_LONG_DOUBLE_128
131 #  endif
132 		     ),
133   FFI_LAST_ABI = 32
134 # endif
135 #endif
136 
137 } ffi_abi;
138 #endif
139 
140 /* ---- Definitions for closures ----------------------------------------- */
141 
142 #define FFI_CLOSURES 1
143 #define FFI_NATIVE_RAW_API 0
144 #if defined (POWERPC) || defined (POWERPC_FREEBSD)
145 # define FFI_GO_CLOSURES 1
146 # define FFI_TARGET_SPECIFIC_VARIADIC 1
147 # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
148 #endif
149 #if defined (POWERPC_AIX)
150 # define FFI_GO_CLOSURES 1
151 #endif
152 
153 /* ppc_closure.S and linux64_closure.S expect this.  */
154 #define FFI_PPC_TYPE_LAST FFI_TYPE_POINTER
155 
156 /* We define additional types below.  If generic types are added that
157    must be supported by powerpc libffi then it is likely that
158    FFI_PPC_TYPE_LAST needs increasing *and* the jump tables in
159    ppc_closure.S and linux64_closure.S be extended.  */
160 
161 #if !(FFI_TYPE_LAST == FFI_PPC_TYPE_LAST		\
162       || (FFI_TYPE_LAST == FFI_TYPE_COMPLEX		\
163 	  && !defined FFI_TARGET_HAS_COMPLEX_TYPE))
164 # error "You likely have a broken powerpc libffi"
165 #endif
166 
167 /* Needed for soft-float long-double-128 support.  */
168 #define FFI_TYPE_UINT128 (FFI_PPC_TYPE_LAST + 1)
169 
170 /* Needed for FFI_SYSV small structure returns.  */
171 #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2)
172 
173 /* Used by ELFv2 for homogenous structure returns.  */
174 #define FFI_V2_TYPE_VECTOR		(FFI_PPC_TYPE_LAST + 1)
175 #define FFI_V2_TYPE_VECTOR_HOMOG	(FFI_PPC_TYPE_LAST + 2)
176 #define FFI_V2_TYPE_FLOAT_HOMOG		(FFI_PPC_TYPE_LAST + 3)
177 #define FFI_V2_TYPE_DOUBLE_HOMOG	(FFI_PPC_TYPE_LAST + 4)
178 #define FFI_V2_TYPE_SMALL_STRUCT	(FFI_PPC_TYPE_LAST + 5)
179 
180 #if _CALL_ELF == 2
181 # define FFI_TRAMPOLINE_SIZE 32
182 #else
183 # if defined(POWERPC64) || defined(POWERPC_AIX)
184 #  if defined(POWERPC_DARWIN64)
185 #    define FFI_TRAMPOLINE_SIZE 48
186 #  else
187 #    define FFI_TRAMPOLINE_SIZE 24
188 #  endif
189 # else /* POWERPC || POWERPC_AIX */
190 #  define FFI_TRAMPOLINE_SIZE 40
191 # endif
192 #endif
193 
194 #ifndef LIBFFI_ASM
195 #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
196 struct ffi_aix_trampoline_struct {
197     void * code_pointer;	/* Pointer to ffi_closure_ASM */
198     void * toc;			/* TOC */
199     void * static_chain;	/* Pointer to closure */
200 };
201 #endif
202 #endif
203 
204 #endif
205