ffi 1.0.11 → 1.0.12.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (159) hide show
  1. data/Rakefile +1 -1
  2. data/ext/ffi_c/AbstractMemory.c +9 -0
  3. data/ext/ffi_c/AbstractMemory.h +4 -0
  4. data/ext/ffi_c/Buffer.c +8 -0
  5. data/ext/ffi_c/Call.c +8 -0
  6. data/ext/ffi_c/ClosurePool.c +12 -0
  7. data/ext/ffi_c/DynamicLibrary.c +7 -1
  8. data/ext/ffi_c/Function.c +11 -1
  9. data/ext/ffi_c/Function.h +6 -0
  10. data/ext/ffi_c/FunctionInfo.c +8 -0
  11. data/ext/ffi_c/LastError.c +8 -0
  12. data/ext/ffi_c/MemoryPointer.c +8 -0
  13. data/ext/ffi_c/MemoryPointer.h +6 -0
  14. data/ext/ffi_c/MethodHandle.c +8 -0
  15. data/ext/ffi_c/Platform.c +8 -0
  16. data/ext/ffi_c/Pointer.c +8 -0
  17. data/ext/ffi_c/Pointer.h +6 -0
  18. data/ext/ffi_c/Struct.c +6 -0
  19. data/ext/ffi_c/StructByReference.c +8 -0
  20. data/ext/ffi_c/StructByValue.c +8 -0
  21. data/ext/ffi_c/StructLayout.c +6 -0
  22. data/ext/ffi_c/Thread.c +7 -0
  23. data/ext/ffi_c/Thread.h +6 -0
  24. data/ext/ffi_c/Type.c +3 -0
  25. data/ext/ffi_c/Types.h +4 -0
  26. data/ext/ffi_c/Variadic.c +8 -0
  27. data/ext/ffi_c/endian.h +3 -0
  28. data/ext/ffi_c/extconf.rb +6 -1
  29. data/ext/ffi_c/libffi.vc.mk +26 -0
  30. data/ext/ffi_c/libffi.vc64.mk +26 -0
  31. data/ext/ffi_c/libffi/ChangeLog +541 -0
  32. data/ext/ffi_c/libffi/ChangeLog.libffi +13 -87
  33. data/ext/ffi_c/libffi/LICENSE +3 -3
  34. data/ext/ffi_c/libffi/Makefile.am +41 -32
  35. data/ext/ffi_c/libffi/Makefile.in +95 -66
  36. data/ext/ffi_c/libffi/Makefile.vc +141 -0
  37. data/ext/ffi_c/libffi/Makefile.vc64 +141 -0
  38. data/ext/ffi_c/libffi/README +40 -4
  39. data/ext/ffi_c/libffi/aclocal.m4 +729 -7854
  40. data/ext/ffi_c/libffi/build-ios.sh +67 -0
  41. data/ext/ffi_c/libffi/compile +11 -10
  42. data/ext/ffi_c/libffi/config.guess +4 -1
  43. data/ext/ffi_c/libffi/config.sub +6 -3
  44. data/ext/ffi_c/libffi/configure +6264 -6354
  45. data/ext/ffi_c/libffi/configure.ac +155 -63
  46. data/ext/ffi_c/libffi/depcomp +81 -35
  47. data/ext/ffi_c/libffi/doc/libffi.info +78 -18
  48. data/ext/ffi_c/libffi/doc/libffi.texi +64 -5
  49. data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
  50. data/ext/ffi_c/libffi/doc/version.texi +4 -4
  51. data/ext/ffi_c/libffi/fficonfig.h.in +18 -0
  52. data/ext/ffi_c/libffi/fficonfig.hw +57 -0
  53. data/ext/ffi_c/libffi/include/Makefile.in +21 -3
  54. data/ext/ffi_c/libffi/include/ffi.h.in +42 -14
  55. data/ext/ffi_c/libffi/include/ffi.h.vc +427 -0
  56. data/ext/ffi_c/libffi/include/ffi.h.vc64 +427 -0
  57. data/ext/ffi_c/libffi/include/ffi_common.h +9 -5
  58. data/ext/ffi_c/libffi/install-sh +364 -167
  59. data/ext/ffi_c/libffi/ltmain.sh +2599 -1369
  60. data/ext/ffi_c/libffi/m4/ax_cc_maxopt.m4 +176 -0
  61. data/ext/ffi_c/libffi/m4/ax_cflags_warn_all.m4 +195 -0
  62. data/ext/ffi_c/libffi/m4/ax_check_compiler_flags.m4 +76 -0
  63. data/ext/ffi_c/libffi/m4/ax_compiler_vendor.m4 +63 -0
  64. data/ext/ffi_c/libffi/m4/ax_configure_args.m4 +70 -0
  65. data/ext/ffi_c/libffi/m4/ax_enable_builddir.m4 +300 -0
  66. data/ext/ffi_c/libffi/m4/ax_gcc_archflag.m4 +215 -0
  67. data/ext/ffi_c/libffi/m4/ax_gcc_x86_cpuid.m4 +79 -0
  68. data/ext/ffi_c/libffi/m4/libtool.m4 +1239 -768
  69. data/ext/ffi_c/libffi/m4/ltoptions.m4 +7 -6
  70. data/ext/ffi_c/libffi/m4/ltversion.m4 +6 -6
  71. data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +9 -3
  72. data/ext/ffi_c/libffi/man/Makefile.in +21 -3
  73. data/ext/ffi_c/libffi/mdate-sh +0 -0
  74. data/ext/ffi_c/libffi/missing +60 -44
  75. data/ext/ffi_c/libffi/msvcc.sh +197 -0
  76. data/ext/ffi_c/libffi/src/alpha/osf.S +39 -18
  77. data/ext/ffi_c/libffi/src/arm/ffi.c +443 -24
  78. data/ext/ffi_c/libffi/src/arm/ffitarget.h +17 -1
  79. data/ext/ffi_c/libffi/src/arm/gentramp.sh +118 -0
  80. data/ext/ffi_c/libffi/src/arm/sysv.S +206 -15
  81. data/ext/ffi_c/libffi/src/arm/trampoline.S +4450 -0
  82. data/ext/ffi_c/libffi/src/avr32/ffi.c +4 -2
  83. data/ext/ffi_c/libffi/src/avr32/ffitarget.h +2 -2
  84. data/ext/ffi_c/libffi/src/closures.c +17 -35
  85. data/ext/ffi_c/libffi/src/cris/ffi.c +1 -1
  86. data/ext/ffi_c/libffi/src/cris/ffitarget.h +2 -2
  87. data/ext/ffi_c/libffi/src/dlmalloc.c +66 -4
  88. data/ext/ffi_c/libffi/src/frv/ffitarget.h +2 -6
  89. data/ext/ffi_c/libffi/src/ia64/ffi.c +7 -5
  90. data/ext/ffi_c/libffi/src/ia64/ffitarget.h +2 -2
  91. data/ext/ffi_c/libffi/src/java_raw_api.c +1 -1
  92. data/ext/ffi_c/libffi/src/m32r/ffitarget.h +2 -2
  93. data/ext/ffi_c/libffi/src/m68k/ffi.c +10 -0
  94. data/ext/ffi_c/libffi/src/m68k/ffitarget.h +2 -2
  95. data/ext/ffi_c/libffi/src/m68k/sysv.S +36 -0
  96. data/ext/ffi_c/libffi/src/mips/ffi.c +12 -5
  97. data/ext/ffi_c/libffi/src/mips/ffitarget.h +18 -11
  98. data/ext/ffi_c/libffi/src/mips/n32.S +4 -4
  99. data/ext/ffi_c/libffi/src/moxie/eabi.S +128 -0
  100. data/ext/ffi_c/libffi/src/moxie/ffi.c +276 -0
  101. data/ext/ffi_c/libffi/src/pa/ffi.c +7 -4
  102. data/ext/ffi_c/libffi/src/pa/ffitarget.h +6 -5
  103. data/ext/ffi_c/libffi/src/powerpc/aix.S +5 -1
  104. data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +2 -0
  105. data/ext/ffi_c/libffi/src/powerpc/asm.h +1 -1
  106. data/ext/ffi_c/libffi/src/powerpc/darwin.S +215 -77
  107. data/ext/ffi_c/libffi/src/powerpc/darwin_closure.S +358 -100
  108. data/ext/ffi_c/libffi/src/powerpc/ffi.c +11 -5
  109. data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +603 -172
  110. data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +17 -4
  111. data/ext/ffi_c/libffi/src/prep_cif.c +16 -13
  112. data/ext/ffi_c/libffi/src/s390/ffitarget.h +4 -2
  113. data/ext/ffi_c/libffi/src/sh/ffitarget.h +2 -2
  114. data/ext/ffi_c/libffi/src/sh64/ffitarget.h +2 -2
  115. data/ext/ffi_c/libffi/src/sparc/ffi.c +55 -11
  116. data/ext/ffi_c/libffi/src/sparc/ffitarget.h +5 -3
  117. data/ext/ffi_c/libffi/src/x86/ffi.c +54 -92
  118. data/ext/ffi_c/libffi/src/x86/ffi64.c +17 -8
  119. data/ext/ffi_c/libffi/src/x86/ffitarget.h +15 -14
  120. data/ext/ffi_c/libffi/src/x86/sysv.S +40 -26
  121. data/ext/ffi_c/libffi/src/x86/unix64.S +4 -0
  122. data/ext/ffi_c/libffi/src/x86/win32.S +379 -191
  123. data/ext/ffi_c/libffi/src/x86/win64.S +15 -7
  124. data/ext/ffi_c/libffi/testsuite/Makefile.am +1 -1
  125. data/ext/ffi_c/libffi/testsuite/Makefile.in +22 -4
  126. data/ext/ffi_c/libffi/testsuite/lib/libffi.exp +350 -0
  127. data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +1 -5
  128. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +1 -1
  129. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +1 -1
  130. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +1 -0
  131. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +1 -0
  132. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +3 -0
  133. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +2 -2
  134. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +3 -0
  135. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +1 -1
  136. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +1 -1
  137. data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +1 -0
  138. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +2 -3
  139. data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +2 -1
  140. data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +36 -0
  141. data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +17 -17
  142. data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -0
  143. data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +1 -0
  144. data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +1 -1
  145. data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +1 -3
  146. data/ext/ffi_c/win32/stdint.h +199 -0
  147. data/gen/Rakefile +18 -2
  148. data/lib/ffi/platform/arm-linux/types.conf +102 -0
  149. data/lib/ffi/platform/i486-gnu/types.conf +107 -0
  150. data/lib/ffi/platform/ia64-linux/types.conf +102 -0
  151. data/lib/ffi/platform/mips-linux/types.conf +102 -0
  152. data/lib/ffi/platform/mipsel-linux/types.conf +102 -0
  153. data/lib/ffi/platform/powerpc-linux/types.conf +100 -0
  154. data/lib/ffi/platform/s390-linux/types.conf +102 -0
  155. data/lib/ffi/platform/s390x-linux/types.conf +102 -0
  156. data/lib/ffi/platform/sparc-linux/types.conf +102 -0
  157. data/lib/ffi/tools/types_generator.rb +8 -1
  158. data/lib/ffi_c.bundle +0 -0
  159. metadata +72 -42
@@ -1,6 +1,7 @@
1
1
  /* -----------------------------------------------------------------------
2
- ffi.c - Copyright (c) 1996, 2007, 2008 Red Hat, Inc.
3
- Copyright (c) 2008 David Daney
2
+ ffi.c - Copyright (c) 2011 Anthony Green
3
+ Copyright (c) 2008 David Daney
4
+ Copyright (c) 1996, 2007, 2008, 2011 Red Hat, Inc.
4
5
 
5
6
  MIPS Foreign Function Interface
6
7
 
@@ -37,7 +38,11 @@
37
38
  #endif
38
39
 
39
40
  #ifndef USE__BUILTIN___CLEAR_CACHE
40
- #include <sys/cachectl.h>
41
+ # if defined(__OpenBSD__)
42
+ # include <mips64/sysarch.h>
43
+ # else
44
+ # include <sys/cachectl.h>
45
+ # endif
41
46
  #endif
42
47
 
43
48
  #ifdef FFI_DEBUG
@@ -662,10 +667,12 @@ ffi_prep_closure_loc (ffi_closure *closure,
662
667
  char *clear_location = (char *) codeloc;
663
668
 
664
669
  #if defined(FFI_MIPS_O32)
665
- FFI_ASSERT(cif->abi == FFI_O32 || cif->abi == FFI_O32_SOFT_FLOAT);
670
+ if (cif->abi != FFI_O32 && cif->abi != FFI_O32_SOFT_FLOAT)
671
+ return FFI_BAD_ABI;
666
672
  fn = ffi_closure_O32;
667
673
  #else /* FFI_MIPS_N32 */
668
- FFI_ASSERT(cif->abi == FFI_N32 || cif->abi == FFI_N64);
674
+ if (cif->abi != FFI_N32 && cif->abi != FFI_N64)
675
+ return FFI_BAD_ABI;
669
676
  fn = ffi_closure_N32;
670
677
  #endif /* FFI_MIPS_O32 */
671
678
 
@@ -29,9 +29,17 @@
29
29
 
30
30
  #ifdef linux
31
31
  # include <asm/sgidefs.h>
32
- #else
32
+ #elif defined(__rtems__)
33
+ /*
34
+ * Subprogram calling convention - copied from sgidefs.h
35
+ */
36
+ #define _MIPS_SIM_ABI32 1
37
+ #define _MIPS_SIM_NABI32 2
38
+ #define _MIPS_SIM_ABI64 3
39
+ #elif !defined(__OpenBSD__)
33
40
  # include <sgidefs.h>
34
41
  #endif
42
+
35
43
  # ifndef _ABIN32
36
44
  # define _ABIN32 _MIPS_SIM_NABI32
37
45
  # endif
@@ -43,7 +51,7 @@
43
51
  # endif
44
52
 
45
53
  #if !defined(_MIPS_SIM)
46
- -- something is very wrong --
54
+ # error -- something is very wrong --
47
55
  #else
48
56
  # if (_MIPS_SIM==_ABIN32 && defined(_ABIN32)) || (_MIPS_SIM==_ABI64 && defined(_ABI64))
49
57
  # define FFI_MIPS_N32
@@ -51,7 +59,7 @@
51
59
  # if (_MIPS_SIM==_ABIO32 && defined(_ABIO32))
52
60
  # define FFI_MIPS_O32
53
61
  # else
54
- -- this is an unsupported platform --
62
+ # error -- this is an unsupported platform --
55
63
  # endif
56
64
  # endif
57
65
  #endif
@@ -186,30 +194,29 @@ typedef enum ffi_abi {
186
194
  FFI_O32_SOFT_FLOAT,
187
195
  FFI_N32_SOFT_FLOAT,
188
196
  FFI_N64_SOFT_FLOAT,
197
+ FFI_LAST_ABI,
189
198
 
190
199
  #ifdef FFI_MIPS_O32
191
200
  #ifdef __mips_soft_float
192
- FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT,
201
+ FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT
193
202
  #else
194
- FFI_DEFAULT_ABI = FFI_O32,
203
+ FFI_DEFAULT_ABI = FFI_O32
195
204
  #endif
196
205
  #else
197
206
  # if _MIPS_SIM==_ABI64
198
207
  # ifdef __mips_soft_float
199
- FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT,
208
+ FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT
200
209
  # else
201
- FFI_DEFAULT_ABI = FFI_N64,
210
+ FFI_DEFAULT_ABI = FFI_N64
202
211
  # endif
203
212
  # else
204
213
  # ifdef __mips_soft_float
205
- FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT,
214
+ FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT
206
215
  # else
207
- FFI_DEFAULT_ABI = FFI_N32,
216
+ FFI_DEFAULT_ABI = FFI_N32
208
217
  # endif
209
218
  # endif
210
219
  #endif
211
-
212
- FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
213
220
  } ffi_abi;
214
221
 
215
222
  #define FFI_EXTRA_CIF_FIELDS unsigned rstruct_flag
@@ -1,5 +1,5 @@
1
1
  /* -----------------------------------------------------------------------
2
- n32.S - Copyright (c) 1996, 1998, 2005 Red Hat, Inc.
2
+ n32.S - Copyright (c) 1996, 1998, 2005, 2007, 2009, 2010 Red Hat, Inc.
3
3
 
4
4
  MIPS Foreign Function Interface
5
5
 
@@ -40,7 +40,7 @@
40
40
 
41
41
  #define SIZEOF_FRAME ( 8 * FFI_SIZEOF_ARG )
42
42
 
43
- #ifdef linux
43
+ #ifdef __GNUC__
44
44
  .abicalls
45
45
  #endif
46
46
  .text
@@ -529,7 +529,7 @@ cls_epilogue:
529
529
  .LFE2:
530
530
  .end ffi_closure_N32
531
531
 
532
- #ifdef linux
532
+ #ifdef __GNUC__
533
533
  .section .eh_frame,"aw",@progbits
534
534
  .Lframe1:
535
535
  .4byte .LECIE1-.LSCIE1 # length
@@ -586,6 +586,6 @@ cls_epilogue:
586
586
  .uleb128 (SIZEOF_FRAME2 - RA_OFF2)/4
587
587
  .align EH_FRAME_ALIGN
588
588
  .LEFDE3:
589
- #endif /* linux */
589
+ #endif /* __GNUC__ */
590
590
 
591
591
  #endif
@@ -0,0 +1,128 @@
1
+ /* -----------------------------------------------------------------------
2
+ eabi.S - Copyright (c) 2004 Anthony Green
3
+
4
+ FR-V Assembly glue.
5
+
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
+
14
+ The above copyright notice and this permission notice shall be included
15
+ in all copies or substantial portions of the Software.
16
+
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 THE AUTHOR 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.
24
+ ----------------------------------------------------------------------- */
25
+
26
+ #define LIBFFI_ASM
27
+ #include <fficonfig.h>
28
+ #include <ffi.h>
29
+
30
+ .globl ffi_prep_args_EABI
31
+
32
+ .text
33
+ .p2align 4
34
+ .globl ffi_call_EABI
35
+ .type ffi_call_EABI, @function
36
+
37
+ # gr8 : ffi_prep_args
38
+ # gr9 : &ecif
39
+ # gr10: cif->bytes
40
+ # gr11: fig->flags
41
+ # gr12: ecif.rvalue
42
+ # gr13: fn
43
+
44
+ ffi_call_EABI:
45
+ addi sp, #-80, sp
46
+ sti fp, @(sp, #24)
47
+ addi sp, #24, fp
48
+ movsg lr, gr5
49
+
50
+ /* Make room for the new arguments. */
51
+ /* subi sp, fp, gr10 */
52
+
53
+ /* Store return address and incoming args on stack. */
54
+ sti gr5, @(fp, #8)
55
+ sti gr8, @(fp, #-4)
56
+ sti gr9, @(fp, #-8)
57
+ sti gr10, @(fp, #-12)
58
+ sti gr11, @(fp, #-16)
59
+ sti gr12, @(fp, #-20)
60
+ sti gr13, @(fp, #-24)
61
+
62
+ sub sp, gr10, sp
63
+
64
+ /* Call ffi_prep_args. */
65
+ ldi @(fp, #-4), gr4
66
+ addi sp, #0, gr8
67
+ ldi @(fp, #-8), gr9
68
+ #ifdef __FRV_FDPIC__
69
+ ldd @(gr4, gr0), gr14
70
+ calll @(gr14, gr0)
71
+ #else
72
+ calll @(gr4, gr0)
73
+ #endif
74
+
75
+ /* ffi_prep_args returns the new stack pointer. */
76
+ mov gr8, gr4
77
+
78
+ ldi @(sp, #0), gr8
79
+ ldi @(sp, #4), gr9
80
+ ldi @(sp, #8), gr10
81
+ ldi @(sp, #12), gr11
82
+ ldi @(sp, #16), gr12
83
+ ldi @(sp, #20), gr13
84
+
85
+ /* Always copy the return value pointer into the hidden
86
+ parameter register. This is only strictly necessary
87
+ when we're returning an aggregate type, but it doesn't
88
+ hurt to do this all the time, and it saves a branch. */
89
+ ldi @(fp, #-20), gr3
90
+
91
+ /* Use the ffi_prep_args return value for the new sp. */
92
+ mov gr4, sp
93
+
94
+ /* Call the target function. */
95
+ ldi @(fp, -24), gr4
96
+ #ifdef __FRV_FDPIC__
97
+ ldd @(gr4, gr0), gr14
98
+ calll @(gr14, gr0)
99
+ #else
100
+ calll @(gr4, gr0)
101
+ #endif
102
+
103
+ /* Store the result. */
104
+ ldi @(fp, #-16), gr10 /* fig->flags */
105
+ ldi @(fp, #-20), gr4 /* ecif.rvalue */
106
+
107
+ /* Is the return value stored in two registers? */
108
+ cmpi gr10, #8, icc0
109
+ bne icc0, 0, .L2
110
+ /* Yes, save them. */
111
+ sti gr8, @(gr4, #0)
112
+ sti gr9, @(gr4, #4)
113
+ bra .L3
114
+ .L2:
115
+ /* Is the return value a structure? */
116
+ cmpi gr10, #-1, icc0
117
+ beq icc0, 0, .L3
118
+ /* No, save a 4 byte return value. */
119
+ sti gr8, @(gr4, #0)
120
+ .L3:
121
+
122
+ /* Restore the stack, and return. */
123
+ ldi @(fp, 8), gr5
124
+ ld @(fp, gr0), fp
125
+ addi sp,#80,sp
126
+ jmpl @(gr5,gr0)
127
+ .size ffi_call_EABI, .-ffi_call_EABI
128
+
@@ -0,0 +1,276 @@
1
+ /* -----------------------------------------------------------------------
2
+ ffi.c - Copyright (C) 2009 Anthony Green
3
+
4
+ Moxie Foreign Function Interface
5
+
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
+
14
+ The above copyright notice and this permission notice shall be included
15
+ in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
+ DEALINGS IN THE SOFTWARE.
25
+ ----------------------------------------------------------------------- */
26
+
27
+ #include <ffi.h>
28
+ #include <ffi_common.h>
29
+
30
+ #include <stdlib.h>
31
+
32
+ /* ffi_prep_args is called by the assembly routine once stack space
33
+ has been allocated for the function's arguments */
34
+
35
+ void *ffi_prep_args(char *stack, extended_cif *ecif)
36
+ {
37
+ register unsigned int i;
38
+ register void **p_argv;
39
+ register char *argp;
40
+ register ffi_type **p_arg;
41
+ register int count = 0;
42
+
43
+ p_argv = ecif->avalue;
44
+ argp = stack;
45
+
46
+ for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
47
+ (i != 0);
48
+ i--, p_arg++)
49
+ {
50
+ size_t z;
51
+
52
+ z = (*p_arg)->size;
53
+
54
+ if ((*p_arg)->type == FFI_TYPE_STRUCT)
55
+ {
56
+ z = sizeof(void*);
57
+ *(void **) argp = *p_argv;
58
+ }
59
+ /* if ((*p_arg)->type == FFI_TYPE_FLOAT)
60
+ {
61
+ if (count > 24)
62
+ {
63
+ // This is going on the stack. Turn it into a double.
64
+ *(double *) argp = (double) *(float*)(* p_argv);
65
+ z = sizeof(double);
66
+ }
67
+ else
68
+ *(void **) argp = *(void **)(* p_argv);
69
+ } */
70
+ else if (z < sizeof(int))
71
+ {
72
+ z = sizeof(int);
73
+ switch ((*p_arg)->type)
74
+ {
75
+ case FFI_TYPE_SINT8:
76
+ *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
77
+ break;
78
+
79
+ case FFI_TYPE_UINT8:
80
+ *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
81
+ break;
82
+
83
+ case FFI_TYPE_SINT16:
84
+ *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
85
+ break;
86
+
87
+ case FFI_TYPE_UINT16:
88
+ *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
89
+ break;
90
+
91
+ default:
92
+ FFI_ASSERT(0);
93
+ }
94
+ }
95
+ else if (z == sizeof(int))
96
+ {
97
+ *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
98
+ }
99
+ else
100
+ {
101
+ memcpy(argp, *p_argv, z);
102
+ }
103
+ p_argv++;
104
+ argp += z;
105
+ count += z;
106
+ }
107
+
108
+ return (stack + ((count > 24) ? 24 : ALIGN_DOWN(count, 8)));
109
+ }
110
+
111
+ /* Perform machine dependent cif processing */
112
+ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
113
+ {
114
+ if (cif->rtype->type == FFI_TYPE_STRUCT)
115
+ cif->flags = -1;
116
+ else
117
+ cif->flags = cif->rtype->size;
118
+
119
+ cif->bytes = ALIGN (cif->bytes, 8);
120
+
121
+ return FFI_OK;
122
+ }
123
+
124
+ extern void ffi_call_EABI(void *(*)(char *, extended_cif *),
125
+ extended_cif *,
126
+ unsigned, unsigned,
127
+ unsigned *,
128
+ void (*fn)(void));
129
+
130
+ void ffi_call(ffi_cif *cif,
131
+ void (*fn)(void),
132
+ void *rvalue,
133
+ void **avalue)
134
+ {
135
+ extended_cif ecif;
136
+
137
+ ecif.cif = cif;
138
+ ecif.avalue = avalue;
139
+
140
+ /* If the return value is a struct and we don't have a return */
141
+ /* value address then we need to make one */
142
+
143
+ if ((rvalue == NULL) &&
144
+ (cif->rtype->type == FFI_TYPE_STRUCT))
145
+ {
146
+ ecif.rvalue = alloca(cif->rtype->size);
147
+ }
148
+ else
149
+ ecif.rvalue = rvalue;
150
+
151
+
152
+ switch (cif->abi)
153
+ {
154
+ case FFI_EABI:
155
+ ffi_call_EABI(ffi_prep_args, &ecif, cif->bytes,
156
+ cif->flags, ecif.rvalue, fn);
157
+ break;
158
+ default:
159
+ FFI_ASSERT(0);
160
+ break;
161
+ }
162
+ }
163
+
164
+ void ffi_closure_eabi (unsigned arg1, unsigned arg2, unsigned arg3,
165
+ unsigned arg4, unsigned arg5, unsigned arg6)
166
+ {
167
+ /* This function is called by a trampoline. The trampoline stows a
168
+ pointer to the ffi_closure object in gr7. We must save this
169
+ pointer in a place that will persist while we do our work. */
170
+ register ffi_closure *creg __asm__ ("gr7");
171
+ ffi_closure *closure = creg;
172
+
173
+ /* Arguments that don't fit in registers are found on the stack
174
+ at a fixed offset above the current frame pointer. */
175
+ register char *frame_pointer __asm__ ("fp");
176
+ char *stack_args = frame_pointer + 16;
177
+
178
+ /* Lay the register arguments down in a continuous chunk of memory. */
179
+ unsigned register_args[6] =
180
+ { arg1, arg2, arg3, arg4, arg5, arg6 };
181
+
182
+ ffi_cif *cif = closure->cif;
183
+ ffi_type **arg_types = cif->arg_types;
184
+ void **avalue = alloca (cif->nargs * sizeof(void *));
185
+ char *ptr = (char *) register_args;
186
+ int i;
187
+
188
+ /* Find the address of each argument. */
189
+ for (i = 0; i < cif->nargs; i++)
190
+ {
191
+ switch (arg_types[i]->type)
192
+ {
193
+ case FFI_TYPE_SINT8:
194
+ case FFI_TYPE_UINT8:
195
+ avalue[i] = ptr + 3;
196
+ break;
197
+ case FFI_TYPE_SINT16:
198
+ case FFI_TYPE_UINT16:
199
+ avalue[i] = ptr + 2;
200
+ break;
201
+ case FFI_TYPE_SINT32:
202
+ case FFI_TYPE_UINT32:
203
+ case FFI_TYPE_FLOAT:
204
+ avalue[i] = ptr;
205
+ break;
206
+ case FFI_TYPE_STRUCT:
207
+ avalue[i] = *(void**)ptr;
208
+ break;
209
+ default:
210
+ /* This is an 8-byte value. */
211
+ avalue[i] = ptr;
212
+ ptr += 4;
213
+ break;
214
+ }
215
+ ptr += 4;
216
+
217
+ /* If we've handled more arguments than fit in registers,
218
+ start looking at the those passed on the stack. */
219
+ if (ptr == ((char *)register_args + (6*4)))
220
+ ptr = stack_args;
221
+ }
222
+
223
+ /* Invoke the closure. */
224
+ if (cif->rtype->type == FFI_TYPE_STRUCT)
225
+ {
226
+ /* The caller allocates space for the return structure, and
227
+ passes a pointer to this space in gr3. Use this value directly
228
+ as the return value. */
229
+ register void *return_struct_ptr __asm__("gr3");
230
+ (closure->fun) (cif, return_struct_ptr, avalue, closure->user_data);
231
+ }
232
+ else
233
+ {
234
+ /* Allocate space for the return value and call the function. */
235
+ long long rvalue;
236
+ (closure->fun) (cif, &rvalue, avalue, closure->user_data);
237
+
238
+ /* Functions return 4-byte or smaller results in gr8. 8-byte
239
+ values also use gr9. We fill the both, even for small return
240
+ values, just to avoid a branch. */
241
+ asm ("ldi @(%0, #0), gr8" : : "r" (&rvalue));
242
+ asm ("ldi @(%0, #0), gr9" : : "r" (&((int *) &rvalue)[1]));
243
+ }
244
+ }
245
+
246
+ ffi_status
247
+ ffi_prep_closure_loc (ffi_closure* closure,
248
+ ffi_cif* cif,
249
+ void (*fun)(ffi_cif*, void*, void**, void*),
250
+ void *user_data,
251
+ void *codeloc)
252
+ {
253
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
254
+ unsigned long fn = (long) ffi_closure_eabi;
255
+ unsigned long cls = (long) codeloc;
256
+ int i;
257
+
258
+ fn = (unsigned long) ffi_closure_eabi;
259
+
260
+ tramp[0] = 0x8cfc0000 + (fn & 0xffff); /* setlos lo(fn), gr6 */
261
+ tramp[1] = 0x8efc0000 + (cls & 0xffff); /* setlos lo(cls), gr7 */
262
+ tramp[2] = 0x8cf80000 + (fn >> 16); /* sethi hi(fn), gr6 */
263
+ tramp[3] = 0x8ef80000 + (cls >> 16); /* sethi hi(cls), gr7 */
264
+ tramp[4] = 0x80300006; /* jmpl @(gr0, gr6) */
265
+
266
+ closure->cif = cif;
267
+ closure->fun = fun;
268
+ closure->user_data = user_data;
269
+
270
+ /* Cache flushing. */
271
+ for (i = 0; i < FFI_TRAMPOLINE_SIZE; i++)
272
+ __asm__ volatile ("dcf @(%0,%1)\n\tici @(%2,%1)" :: "r" (tramp), "r" (i),
273
+ "r" (codeloc));
274
+
275
+ return FFI_OK;
276
+ }