Fix rename registers problem; Rewrite 64-bit conditionals in terms of COND_EXEC inste...
[official-gcc.git] / libffi / include / ffi.h.in
blob6be7e23c727ec0c1c5bef26c1caf4ad749779d25
1 /* -----------------------------------------------------------------*-C-*-
2 libffi @VERSION@ - Copyright (c) 1996-1999 Cygnus Solutions
4 $Id: ffi.h.in,v 1.4 2000/02/25 19:13:44 tromey Exp $
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
27 /* -------------------------------------------------------------------
28 The basic API is described in the README file.
30 The raw API is designed to bypass some of the argument packing
31 and unpacking on architectures for which it can be avoided.
33 The closure API allows interpreted functions to be packaged up
34 inside a C function pointer, so that they can be called as C functions,
35 with no understanding on the client side that they are interpreted.
36 It can also be used in other cases in which it is necessary to package
37 up a user specified parameter and a function pointer as a single
38 function pointer.
40 The closure API must be implemented in order to get its functionality,
41 e.g. for use by gij. Routines are provided to emulate the raw API
42 if the underlying platform doesn't allow faster implementation.
44 More details on the raw and cloure API can be found in:
46 http://sourceware.cygnus.com/ml/java-discuss/1999-q3/msg00138.html
48 and
50 http://sourceware.cygnus.com/ml/java-discuss/1999-q3/msg00174.html
51 -------------------------------------------------------------------- */
53 #ifndef LIBFFI_H
54 #define LIBFFI_H
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
60 /* Specify which architecture libffi is configured for. */
61 #define @TARGET@
63 /* ---- System configuration information --------------------------------- */
65 #include <fficonfig.h>
67 #if !defined(LIBFFI_ASM)
68 #include <stddef.h>
69 #if defined(FFI_DEBUG)
70 #include <stdio.h>
71 #endif
72 #endif
74 /* ---- Generic type definitions ----------------------------------------- */
76 #define FLOAT32 float
77 #define FLOAT64 double
78 #define FLOAT80 long double
80 #define UINT8 unsigned char
81 #define SINT8 signed char
83 #if SIZEOF_INT == 2
85 #define UINT16 unsigned int
86 #define SINT16 int
87 #define ffi_type_uint ffi_type_uint16
88 #define ffi_type_sint ffi_type_sint16
90 #else
91 #if SIZEOF_SHORT == 2
93 #define UINT16 unsigned short
94 #define SINT16 short
95 #define ffi_type_ushort ffi_type_uint16
96 #define ffi_type_sshort ffi_type_sint16
98 #endif
99 #endif
101 #if SIZEOF_INT == 4
103 #define UINT32 unsigned int
104 #define SINT32 int
105 #define ffi_type_uint ffi_type_uint32
106 #define ffi_type_sint ffi_type_sint32
108 #else
109 #if SIZEOF_SHORT == 4
111 #define UINT32 unsigned short
112 #define SINT32 short
113 #define ffi_type_ushort ffi_type_uint32
114 #define ffi_type_sshort ffi_type_sint32
116 #else
117 #if SIZEOF_LONG == 4
119 #define UINT32 unsigned long
120 #define SINT32 long
121 #define ffi_type_ulong ffi_type_uint32
122 #define ffi_type_slong ffi_type_sint32
124 #endif
125 #endif
126 #endif
128 #if SIZEOF_INT == 8
130 #define UINT64 unsigned int
131 #define SINT64 int
132 #define ffi_type_uint ffi_type_uint64
133 #define ffi_type_sint ffi_type_sint64
135 #else
136 #if SIZEOF_LONG == 8
138 #define UINT64 unsigned long
139 #define SINT64 long
140 #define ffi_type_ulong ffi_type_uint64
141 #define ffi_type_slong ffi_type_sint64
143 #else
144 #if SIZEOF_LONG_LONG == 8
146 #define UINT64 unsigned long long
147 #define SINT64 long long
148 #define ffi_type_ulong ffi_type_uint64
149 #define ffi_type_slong ffi_type_sint64
151 #endif
152 #endif
153 #endif
155 /* ---- System specific configurations ----------------------------------- */
157 #ifdef MIPS
158 #include <ffi_mips.h>
159 #else
160 #define SIZEOF_ARG SIZEOF_VOID_P
161 #endif
163 #ifdef SPARC
164 #if defined(__arch64__) || defined(__sparcv9)
165 #define SPARC64
166 #endif
167 #endif
169 #ifndef LIBFFI_ASM
171 /* ---- Generic type definitions ----------------------------------------- */
173 #define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
174 /* The closure code assumes that this works on pointers, i.e. a size_t */
175 /* can hold a pointer. */
177 typedef enum ffi_abi {
179 /* Leave this for debugging purposes */
180 FFI_FIRST_ABI = 0,
182 /* ---- Sparc -------------------- */
183 #ifdef SPARC
184 FFI_V8,
185 FFI_V8PLUS,
186 FFI_V9,
187 #ifdef SPARC64
188 FFI_DEFAULT_ABI = FFI_V9,
189 #else
190 FFI_DEFAULT_ABI = FFI_V8,
191 #endif
192 #endif
194 /* ---- Intel x86 ---------------- */
195 #ifdef X86
196 FFI_SYSV,
197 FFI_DEFAULT_ABI = FFI_SYSV,
198 #endif
200 /* ---- Intel ia64 ---------------- */
201 #ifdef IA64
202 FFI_UNIX, /* Linux and all Unix variants use the same conventions */
203 FFI_DEFAULT_ABI = FFI_UNIX,
204 #endif
206 /* ---- Mips --------------------- */
207 #ifdef MIPS
208 FFI_O32,
209 FFI_N32,
210 FFI_N64,
211 #endif
213 /* ---- Alpha -------------------- */
214 #ifdef ALPHA
215 FFI_OSF,
216 FFI_DEFAULT_ABI = FFI_OSF,
217 #endif
219 /* ---- Motorola m68k ------------ */
220 #ifdef M68K
221 FFI_SYSV,
222 FFI_DEFAULT_ABI = FFI_SYSV,
223 #endif
225 /* ---- PowerPC ------------------ */
226 #ifdef POWERPC
227 FFI_SYSV,
228 FFI_GCC_SYSV,
229 FFI_DEFAULT_ABI = FFI_GCC_SYSV,
230 #endif
232 /* ---- ARM --------------------- */
233 #ifdef ARM
234 FFI_SYSV,
235 FFI_DEFAULT_ABI = FFI_SYSV,
236 #endif
238 /* Leave this for debugging purposes */
239 FFI_LAST_ABI
241 } ffi_abi;
243 typedef struct _ffi_type
245 size_t size;
246 unsigned short alignment;
247 unsigned short type;
248 /*@null@*/ struct _ffi_type **elements;
249 } ffi_type;
251 /* These are defined in ffi.c */
252 extern ffi_type ffi_type_void;
253 extern ffi_type ffi_type_uint8;
254 extern ffi_type ffi_type_sint8;
255 extern ffi_type ffi_type_uint16;
256 extern ffi_type ffi_type_sint16;
257 extern ffi_type ffi_type_uint32;
258 extern ffi_type ffi_type_sint32;
259 extern ffi_type ffi_type_uint64;
260 extern ffi_type ffi_type_sint64;
261 extern ffi_type ffi_type_float;
262 extern ffi_type ffi_type_double;
263 extern ffi_type ffi_type_longdouble;
264 extern ffi_type ffi_type_pointer;
266 /* Characters are 8 bit integral types */
267 #define ffi_type_schar ffi_type_sint8
268 #define ffi_type_uchar ffi_type_uint8
270 typedef enum {
271 FFI_OK = 0,
272 FFI_BAD_TYPEDEF,
273 FFI_BAD_ABI
274 } ffi_status;
276 typedef unsigned FFI_TYPE;
278 typedef struct {
279 ffi_abi abi;
280 unsigned nargs;
281 /*@dependent@*/ ffi_type **arg_types;
282 /*@dependent@*/ ffi_type *rtype;
283 unsigned bytes;
284 unsigned flags;
286 #ifdef MIPS
287 #if _MIPS_SIM == _ABIN32
288 unsigned rstruct_flag;
289 #endif
290 #endif
292 } ffi_cif;
294 /* ---- Definitions for the raw API -------------------------------------- */
296 #if !FFI_NO_RAW_API
298 #if SIZEOF_ARG == 4
300 #define UINT_ARG UINT32
301 #define SINT_ARG SINT32
303 #endif
305 #if SIZEOF_ARG == 8
307 #define UINT_ARG UINT64
308 #define SINT_ARG SINT64
310 #endif
312 typedef union {
313 SINT_ARG sint;
314 UINT_ARG uint;
315 float flt;
316 char data[SIZEOF_ARG];
317 void* ptr;
318 } ffi_raw;
320 void ffi_raw_call (/*@dependent@*/ ffi_cif *cif,
321 void (*fn)(),
322 /*@out@*/ void *rvalue,
323 /*@dependent@*/ ffi_raw *avalue);
325 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
326 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
327 size_t ffi_raw_size (ffi_cif *cif);
329 #if !NO_JAVA_RAW_API
331 /* This is analogous to the raw API, except it uses Java parameter */
332 /* packing, even on 64-bit machines. I.e. on 64-bit machines */
333 /* longs and doubles are followed by an empty 64-bit word. */
335 void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif,
336 void (*fn)(),
337 /*@out@*/ void *rvalue,
338 /*@dependent@*/ ffi_raw *avalue);
340 void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
341 void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
342 size_t ffi_java_raw_size (ffi_cif *cif);
344 #endif /* !NO_JAVA_RAW_API */
346 #endif /* !FFI_NO_RAW_API */
348 /* ---- Definitions for closures ----------------------------------------- */
350 #ifdef X86
352 #define FFI_CLOSURES 1 /* x86 supports closures */
353 #define FFI_TRAMPOLINE_SIZE 10
354 #define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
356 #elif defined(IA64)
358 #define FFI_CLOSURES 1
359 #define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */
360 /* can be interpreted as a C function */
361 /* decriptor: */
363 struct ffi_ia64_trampoline_struct {
364 void * code_pointer; /* Pointer to ffi_closure_UNIX */
365 void * fake_gp; /* Pointer to closure, installed as gp */
366 void * real_gp; /* Real gp value, reinstalled by */
367 /* ffi_closure_UNIX. */
369 #define FFI_NATIVE_RAW_API 0
371 #else
373 #define FFI_CLOSURES 0
374 #define FFI_NATIVE_RAW_API 0
376 #endif
380 #if FFI_CLOSURES
382 typedef struct {
383 char tramp[FFI_TRAMPOLINE_SIZE];
384 ffi_cif *cif;
385 void (*fun)(ffi_cif*,void*,void**,void*);
386 void *user_data;
387 } ffi_closure;
389 ffi_status
390 ffi_prep_closure (ffi_closure*,
391 ffi_cif *,
392 void (*fun)(ffi_cif*,void*,void**,void*),
393 void *user_data);
395 #if !FFI_NO_RAW_API
397 typedef struct {
398 char tramp[FFI_TRAMPOLINE_SIZE];
400 ffi_cif *cif;
402 #if !FFI_NATIVE_RAW_API
404 /* if this is enabled, then a raw closure has the same layout
405 as a regular closure. We use this to install an intermediate
406 handler to do the transaltion, void** -> ffi_raw*. */
408 void (*translate_args)(ffi_cif*,void*,void**,void*);
409 void *this_closure;
411 #endif
413 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
414 void *user_data;
416 } ffi_raw_closure;
418 ffi_status
419 ffi_prep_raw_closure (ffi_raw_closure*,
420 ffi_cif *cif,
421 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
422 void *user_data);
424 #ifndef NO_JAVA_RAW_API
425 ffi_status
426 ffi_prep_java_raw_closure (ffi_raw_closure*,
427 ffi_cif *cif,
428 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
429 void *user_data);
430 #endif
432 #endif /* !FFI_NO_RAW_API */
433 #endif /* FFI_CLOSURES */
435 /* ---- Public interface definition -------------------------------------- */
437 ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif,
438 ffi_abi abi,
439 unsigned int nargs,
440 /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype,
441 /*@dependent@*/ ffi_type **atypes);
443 void ffi_call(/*@dependent@*/ ffi_cif *cif,
444 void (*fn)(),
445 /*@out@*/ void *rvalue,
446 /*@dependent@*/ void **avalue);
448 /* Useful for eliminating compiler warnings */
449 #define FFI_FN(f) ((void (*)())f)
451 /* ---- Definitions shared with assembly code ---------------------------- */
453 #endif
455 #define FFI_TYPE_VOID 0
456 #define FFI_TYPE_INT 1
457 #define FFI_TYPE_FLOAT 2
458 #define FFI_TYPE_DOUBLE 3
459 #if SIZEOF_LONG_DOUBLE == SIZEOF_DOUBLE
460 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
461 #else
462 #define FFI_TYPE_LONGDOUBLE 4
463 #endif
465 #define FFI_TYPE_UINT8 5 /* If this changes, update ffi_mips.h. */
466 #define FFI_TYPE_SINT8 6 /* If this changes, update ffi_mips.h. */
467 #define FFI_TYPE_UINT16 7
468 #define FFI_TYPE_SINT16 8
469 #define FFI_TYPE_UINT32 9
470 #define FFI_TYPE_SINT32 10
471 #define FFI_TYPE_UINT64 11
472 #define FFI_TYPE_SINT64 12
473 #define FFI_TYPE_STRUCT 13 /* If this changes, update ffi_mips.h. */
474 #define FFI_TYPE_POINTER 14
476 /* This should always refer to the last type code (for sanity checks) */
477 #define FFI_TYPE_LAST FFI_TYPE_POINTER
479 #ifdef __cplusplus
481 #endif
483 #endif