ffitarget.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. Target configuration macros for PowerPC.
  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:
  13. The above copyright notice and this permission notice shall be included
  14. in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. DEALINGS IN THE SOFTWARE.
  23. ----------------------------------------------------------------------- */
  24. #ifndef LIBFFI_TARGET_H
  25. #define LIBFFI_TARGET_H
  26. #ifndef LIBFFI_H
  27. #error "Please do not include ffitarget.h directly into your source. Use ffi.h instead."
  28. #endif
  29. /* ---- System specific configurations ----------------------------------- */
  30. #if defined (POWERPC) && defined (__powerpc64__) /* linux64 */
  31. #ifndef POWERPC64
  32. #define POWERPC64
  33. #endif
  34. #elif defined (POWERPC_DARWIN) && defined (__ppc64__) /* Darwin64 */
  35. #ifndef POWERPC64
  36. #define POWERPC64
  37. #endif
  38. #ifndef POWERPC_DARWIN64
  39. #define POWERPC_DARWIN64
  40. #endif
  41. #elif defined (POWERPC_AIX) && defined (__64BIT__) /* AIX64 */
  42. #ifndef POWERPC64
  43. #define POWERPC64
  44. #endif
  45. #endif
  46. #ifndef LIBFFI_ASM
  47. typedef unsigned long ffi_arg;
  48. typedef signed long ffi_sarg;
  49. typedef enum ffi_abi {
  50. FFI_FIRST_ABI = 0,
  51. #if defined (POWERPC_AIX)
  52. FFI_AIX,
  53. FFI_DARWIN,
  54. FFI_DEFAULT_ABI = FFI_AIX,
  55. FFI_LAST_ABI
  56. #elif defined (POWERPC_DARWIN)
  57. FFI_AIX,
  58. FFI_DARWIN,
  59. FFI_DEFAULT_ABI = FFI_DARWIN,
  60. FFI_LAST_ABI
  61. #else
  62. /* The FFI_COMPAT values are used by old code. Since libffi may be
  63. a shared library we have to support old values for backwards
  64. compatibility. */
  65. FFI_COMPAT_SYSV,
  66. FFI_COMPAT_GCC_SYSV,
  67. FFI_COMPAT_LINUX64,
  68. FFI_COMPAT_LINUX,
  69. FFI_COMPAT_LINUX_SOFT_FLOAT,
  70. # if defined (POWERPC64)
  71. /* This bit, always set in new code, must not be set in any of the
  72. old FFI_COMPAT values that might be used for 64-bit linux. We
  73. only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
  74. all old values. */
  75. FFI_LINUX = 8,
  76. /* This and following bits can reuse FFI_COMPAT values. */
  77. FFI_LINUX_STRUCT_ALIGN = 1,
  78. FFI_LINUX_LONG_DOUBLE_128 = 2,
  79. FFI_LINUX_LONG_DOUBLE_IEEE128 = 4,
  80. FFI_DEFAULT_ABI = (FFI_LINUX
  81. # ifdef __STRUCT_PARM_ALIGN__
  82. | FFI_LINUX_STRUCT_ALIGN
  83. # endif
  84. # ifdef __LONG_DOUBLE_128__
  85. | FFI_LINUX_LONG_DOUBLE_128
  86. # ifdef __LONG_DOUBLE_IEEE128__
  87. | FFI_LINUX_LONG_DOUBLE_IEEE128
  88. # endif
  89. # endif
  90. ),
  91. FFI_LAST_ABI = 16
  92. # else
  93. /* This bit, always set in new code, must not be set in any of the
  94. old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd. */
  95. FFI_SYSV = 8,
  96. /* This and following bits can reuse FFI_COMPAT values. */
  97. FFI_SYSV_SOFT_FLOAT = 1,
  98. FFI_SYSV_STRUCT_RET = 2,
  99. FFI_SYSV_IBM_LONG_DOUBLE = 4,
  100. FFI_SYSV_LONG_DOUBLE_128 = 16,
  101. FFI_DEFAULT_ABI = (FFI_SYSV
  102. # ifdef __NO_FPRS__
  103. | FFI_SYSV_SOFT_FLOAT
  104. # endif
  105. # if (defined (__SVR4_STRUCT_RETURN) \
  106. || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
  107. | FFI_SYSV_STRUCT_RET
  108. # endif
  109. # if __LDBL_MANT_DIG__ == 106
  110. | FFI_SYSV_IBM_LONG_DOUBLE
  111. # endif
  112. # ifdef __LONG_DOUBLE_128__
  113. | FFI_SYSV_LONG_DOUBLE_128
  114. # endif
  115. ),
  116. FFI_LAST_ABI = 32
  117. # endif
  118. #endif
  119. } ffi_abi;
  120. #endif
  121. /* ---- Definitions for closures ----------------------------------------- */
  122. #define FFI_CLOSURES 1
  123. #define FFI_NATIVE_RAW_API 0
  124. #if defined (POWERPC) || defined (POWERPC_FREEBSD)
  125. # define FFI_GO_CLOSURES 1
  126. # define FFI_TARGET_SPECIFIC_VARIADIC 1
  127. # define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
  128. #endif
  129. #if defined (POWERPC_AIX)
  130. # define FFI_GO_CLOSURES 1
  131. #endif
  132. /* ppc_closure.S and linux64_closure.S expect this. */
  133. #define FFI_PPC_TYPE_LAST FFI_TYPE_POINTER
  134. /* We define additional types below. If generic types are added that
  135. must be supported by powerpc libffi then it is likely that
  136. FFI_PPC_TYPE_LAST needs increasing *and* the jump tables in
  137. ppc_closure.S and linux64_closure.S be extended. */
  138. #if !(FFI_TYPE_LAST == FFI_PPC_TYPE_LAST \
  139. || (FFI_TYPE_LAST == FFI_TYPE_COMPLEX \
  140. && !defined FFI_TARGET_HAS_COMPLEX_TYPE))
  141. # error "You likely have a broken powerpc libffi"
  142. #endif
  143. /* Needed for soft-float long-double-128 support. */
  144. #define FFI_TYPE_UINT128 (FFI_PPC_TYPE_LAST + 1)
  145. /* Needed for FFI_SYSV small structure returns. */
  146. #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 2)
  147. /* Used by ELFv2 for homogenous structure returns. */
  148. #define FFI_V2_TYPE_VECTOR (FFI_PPC_TYPE_LAST + 1)
  149. #define FFI_V2_TYPE_VECTOR_HOMOG (FFI_PPC_TYPE_LAST + 2)
  150. #define FFI_V2_TYPE_FLOAT_HOMOG (FFI_PPC_TYPE_LAST + 3)
  151. #define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_PPC_TYPE_LAST + 4)
  152. #define FFI_V2_TYPE_SMALL_STRUCT (FFI_PPC_TYPE_LAST + 5)
  153. #if _CALL_ELF == 2
  154. # define FFI_TRAMPOLINE_SIZE 32
  155. #else
  156. # if defined(POWERPC64) || defined(POWERPC_AIX)
  157. # if defined(POWERPC_DARWIN64)
  158. # define FFI_TRAMPOLINE_SIZE 48
  159. # else
  160. # define FFI_TRAMPOLINE_SIZE 24
  161. # endif
  162. # else /* POWERPC || POWERPC_AIX */
  163. # define FFI_TRAMPOLINE_SIZE 40
  164. # endif
  165. #endif
  166. #ifndef LIBFFI_ASM
  167. #if defined(POWERPC_DARWIN) || defined(POWERPC_AIX)
  168. struct ffi_aix_trampoline_struct {
  169. void * code_pointer; /* Pointer to ffi_closure_ASM */
  170. void * toc; /* TOC */
  171. void * static_chain; /* Pointer to closure */
  172. };
  173. #endif
  174. #endif
  175. #endif