More cygwin fixes
[platform/upstream/libffi.git] / patches / mint
1 Index: libffi/ChangeLog
2 ===================================================================
3 --- libffi.orig/ChangeLog
4 +++ libffi/ChangeLog
5 @@ -1,3 +1,8 @@
6 +2012-03-19  Alan Hourihane  <alanh@fairlite.co.uk>
7 +
8 +       * src/m68k/ffi.c: Add MINT support.
9 +       * src/m68k/sysv.S: Ditto.
10 +
11  2012-03-19  chennam  <csit@axway.com>
12  
13         * src/powerpc/ffi_darwin.c (ffi_prep_closure_loc): Fix AIX closure
14 Index: libffi/src/m68k/ffi.c
15 ===================================================================
16 --- libffi.orig/src/m68k/ffi.c
17 +++ libffi/src/m68k/ffi.c
18 @@ -1,7 +1,7 @@
19  /* -----------------------------------------------------------------------
20     ffi.c
21 -   
22 -   m68k Foreign Function Interface 
23 +
24 +   m68k Foreign Function Interface
25     ----------------------------------------------------------------------- */
26  
27  #include <ffi.h>
28 @@ -13,8 +13,13 @@
29  void rtems_cache_flush_multiple_data_lines( const void *, size_t );
30  #else
31  #include <sys/syscall.h>
32 +#ifdef __MINT__
33 +#include <mint/mintbind.h>
34 +#include <mint/ssystem.h>
35 +#else
36  #include <asm/cachectl.h>
37  #endif
38 +#endif
39  
40  void ffi_call_SYSV (extended_cif *,
41                     unsigned, unsigned,
42 @@ -39,8 +44,12 @@ ffi_prep_args (void *stack, extended_cif
43  
44    argp = stack;
45  
46 -  if (ecif->cif->rtype->type == FFI_TYPE_STRUCT
47 -      && !ecif->cif->flags)
48 +  if (
49 +#ifdef __MINT__
50 +      (ecif->cif->rtype->type == FFI_TYPE_LONGDOUBLE) ||
51 +#endif
52 +      (((ecif->cif->rtype->type == FFI_TYPE_STRUCT)
53 +        && !ecif->cif->flags)))
54      struct_value_ptr = ecif->rvalue;
55    else
56      struct_value_ptr = NULL;
57 @@ -51,12 +60,12 @@ ffi_prep_args (void *stack, extended_cif
58         i != 0;
59         i--, p_arg++)
60      {
61 -      size_t z;
62 +      size_t z = (*p_arg)->size;
63 +      int type = (*p_arg)->type;
64  
65 -      z = (*p_arg)->size;
66        if (z < sizeof (int))
67         {
68 -         switch ((*p_arg)->type)
69 +         switch (type)
70             {
71             case FFI_TYPE_SINT8:
72               *(signed int *) argp = (signed int) *(SINT8 *) *p_argv;
73 @@ -75,7 +84,14 @@ ffi_prep_args (void *stack, extended_cif
74               break;
75  
76             case FFI_TYPE_STRUCT:
77 +#ifdef __MINT__
78 +             if (z == 1 || z == 2)
79 +               memcpy (argp + 2, *p_argv, z);
80 +              else
81 +               memcpy (argp, *p_argv, z);
82 +#else
83               memcpy (argp + sizeof (int) - z, *p_argv, z);
84 +#endif
85               break;
86  
87             default:
88 @@ -120,17 +136,34 @@ ffi_prep_cif_machdep (ffi_cif *cif)
89        break;
90  
91      case FFI_TYPE_STRUCT:
92 +      if (cif->rtype->elements[0]->type == FFI_TYPE_STRUCT &&
93 +          cif->rtype->elements[1])
94 +        {
95 +          cif->flags = 0;
96 +          break;
97 +        }
98 +
99        switch (cif->rtype->size)
100         {
101         case 1:
102 +#ifdef __MINT__
103 +         cif->flags = CIF_FLAGS_STRUCT2;
104 +#else
105           cif->flags = CIF_FLAGS_STRUCT1;
106 +#endif
107           break;
108         case 2:
109           cif->flags = CIF_FLAGS_STRUCT2;
110           break;
111 +#ifdef __MINT__
112 +       case 3:
113 +#endif
114         case 4:
115           cif->flags = CIF_FLAGS_INT;
116           break;
117 +#ifdef __MINT__
118 +       case 7:
119 +#endif
120         case 8:
121           cif->flags = CIF_FLAGS_DINT;
122           break;
123 @@ -150,7 +183,11 @@ ffi_prep_cif_machdep (ffi_cif *cif)
124  
125  #if (FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE)
126      case FFI_TYPE_LONGDOUBLE:
127 +#ifdef __MINT__
128 +      cif->flags = 0;
129 +#else
130        cif->flags = CIF_FLAGS_LDOUBLE;
131 +#endif
132        break;
133  #endif
134  
135 @@ -218,6 +255,26 @@ ffi_prep_incoming_args_SYSV (char *stack
136        size_t z;
137  
138        z = (*p_arg)->size;
139 +#ifdef __MINT__
140 +      if (cif->flags &&
141 +          cif->rtype->type == FFI_TYPE_STRUCT &&
142 +          (z == 1 || z == 2))
143 +       {
144 +         *p_argv = (void *) (argp + 2);
145 +
146 +         z = 4;
147 +       }
148 +      else
149 +      if (cif->flags &&
150 +          cif->rtype->type == FFI_TYPE_STRUCT &&
151 +          (z == 3 || z == 4))
152 +       {
153 +         *p_argv = (void *) (argp);
154 +
155 +         z = 4;
156 +       }
157 +      else
158 +#endif
159        if (z <= 4)
160         {
161           *p_argv = (void *) (argp + 4 - z);
162 @@ -267,14 +324,21 @@ ffi_prep_closure_loc (ffi_closure* closu
163    *(unsigned short *)closure->tramp = 0x207c;
164    *(void **)(closure->tramp + 2) = codeloc;
165    *(unsigned short *)(closure->tramp + 6) = 0x4ef9;
166 -  if (cif->rtype->type == FFI_TYPE_STRUCT
167 -      && !cif->flags)
168 +
169 +  if (
170 +#ifdef __MINT__
171 +      (cif->rtype->type == FFI_TYPE_LONGDOUBLE) ||
172 +#endif
173 +      (((cif->rtype->type == FFI_TYPE_STRUCT)
174 +         && !cif->flags)))
175      *(void **)(closure->tramp + 8) = ffi_closure_struct_SYSV;
176    else
177      *(void **)(closure->tramp + 8) = ffi_closure_SYSV;
178  
179  #ifdef __rtems__
180    rtems_cache_flush_multiple_data_lines( codeloc, FFI_TRAMPOLINE_SIZE );
181 +#elif defined(__MINT__)
182 +  Ssystem(S_FLUSHCACHE, codeloc, FFI_TRAMPOLINE_SIZE);
183  #else
184    syscall(SYS_cacheflush, codeloc, FLUSH_SCOPE_LINE,
185           FLUSH_CACHE_BOTH, FFI_TRAMPOLINE_SIZE);
186 @@ -286,4 +350,3 @@ ffi_prep_closure_loc (ffi_closure* closu
187  
188    return FFI_OK;
189  }
190 -
191 Index: libffi/src/m68k/sysv.S
192 ===================================================================
193 --- libffi.orig/src/m68k/sysv.S
194 +++ libffi/src/m68k/sysv.S
195 @@ -1,6 +1,7 @@
196  /* -----------------------------------------------------------------------
197         
198 -   sysv.S - Copyright (c) 1998, 2012 Andreas Schwab
199 +   sysv.S - Copyright (c) 2012 Alan Hourihane
200 +           Copyright (c) 1998, 2012 Andreas Schwab
201             Copyright (c) 2008 Red Hat, Inc. 
202     
203     m68k Foreign Function Interface 
204 @@ -42,13 +43,19 @@
205  #define CFI_ENDPROC()
206  #endif
207  
208 +#ifdef __MINT__
209 +#define CALLFUNC(funcname) _ ## funcname
210 +#else
211 +#define CALLFUNC(funcname) funcname
212 +#endif
213 +
214         .text
215  
216 -       .globl  ffi_call_SYSV
217 -       .type   ffi_call_SYSV,@function
218 +       .globl  CALLFUNC(ffi_call_SYSV)
219 +       .type   CALLFUNC(ffi_call_SYSV),@function
220         .align  4
221  
222 -ffi_call_SYSV:
223 +CALLFUNC(ffi_call_SYSV):
224         CFI_STARTPROC()
225         link    %fp,#0
226         CFI_OFFSET(14,-8)
227 @@ -63,14 +70,18 @@ ffi_call_SYSV:
228         move.l  8(%fp),-(%sp)
229         pea     4(%sp)
230  #if !defined __PIC__
231 -       jsr     ffi_prep_args
232 +       jsr     CALLFUNC(ffi_prep_args)
233  #else
234 -       bsr.l   ffi_prep_args@PLTPC
235 +       bsr.l   CALLFUNC(ffi_prep_args@PLTPC)
236  #endif
237         addq.l  #8,%sp  
238  
239         | Pass pointer to struct value, if any
240 +#ifdef __MINT__
241 +       move.l  %d0,%a1
242 +#else
243         move.l  %a0,%a1
244 +#endif
245  
246         | Call the function
247         move.l  24(%fp),%a0
248 @@ -142,7 +153,11 @@ retlongdouble:
249  retpointer:
250         btst    #5,%d2
251         jbeq    retstruct1
252 +#ifdef __MINT__
253 +       move.l  %d0,(%a1)
254 +#else
255         move.l  %a0,(%a1)
256 +#endif
257         jbra    epilogue
258  
259  retstruct1:
260 @@ -162,13 +177,13 @@ epilogue:
261         unlk    %fp
262         rts
263         CFI_ENDPROC()
264 -       .size   ffi_call_SYSV,.-ffi_call_SYSV
265 +       .size   CALLFUNC(ffi_call_SYSV),.-CALLFUNC(ffi_call_SYSV)
266  
267 -       .globl  ffi_closure_SYSV
268 -       .type   ffi_closure_SYSV, @function
269 +       .globl  CALLFUNC(ffi_closure_SYSV)
270 +       .type   CALLFUNC(ffi_closure_SYSV), @function
271         .align  4
272  
273 -ffi_closure_SYSV:
274 +CALLFUNC(ffi_closure_SYSV):
275         CFI_STARTPROC()
276         link    %fp,#-12
277         CFI_OFFSET(14,-8)
278 @@ -178,9 +193,9 @@ ffi_closure_SYSV:
279         pea     -12(%fp)
280         move.l  %a0,-(%sp)
281  #if !defined __PIC__
282 -       jsr     ffi_closure_SYSV_inner
283 +       jsr     CALLFUNC(ffi_closure_SYSV_inner)
284  #else
285 -       bsr.l   ffi_closure_SYSV_inner@PLTPC
286 +       bsr.l   CALLFUNC(ffi_closure_SYSV_inner@PLTPC)
287  #endif
288  
289         lsr.l   #1,%d0
290 @@ -240,13 +255,13 @@ ffi_closure_SYSV:
291         jra     .Lcls_epilogue
292         CFI_ENDPROC()
293  
294 -       .size   ffi_closure_SYSV,.-ffi_closure_SYSV
295 +       .size   CALLFUNC(ffi_closure_SYSV),.-CALLFUNC(ffi_closure_SYSV)
296  
297 -       .globl  ffi_closure_struct_SYSV
298 -       .type   ffi_closure_struct_SYSV, @function
299 +       .globl  CALLFUNC(ffi_closure_struct_SYSV)
300 +       .type   CALLFUNC(ffi_closure_struct_SYSV), @function
301         .align  4
302  
303 -ffi_closure_struct_SYSV:
304 +CALLFUNC(ffi_closure_struct_SYSV):
305         CFI_STARTPROC()
306         link    %fp,#0
307         CFI_OFFSET(14,-8)
308 @@ -256,14 +271,14 @@ ffi_closure_struct_SYSV:
309         move.l  %a1,-(%sp)
310         move.l  %a0,-(%sp)
311  #if !defined __PIC__
312 -       jsr     ffi_closure_SYSV_inner
313 +       jsr     CALLFUNC(ffi_closure_SYSV_inner)
314  #else
315 -       bsr.l   ffi_closure_SYSV_inner@PLTPC
316 +       bsr.l   CALLFUNC(ffi_closure_SYSV_inner@PLTPC)
317  #endif
318         unlk    %fp
319         rts
320         CFI_ENDPROC()
321 -       .size   ffi_closure_struct_SYSV,.-ffi_closure_struct_SYSV
322 +       .size   CALLFUNC(ffi_closure_struct_SYSV),.-CALLFUNC(ffi_closure_struct_SYSV)
323  
324  #if defined __ELF__ && defined __linux__
325         .section        .note.GNU-stack,"",@progbits
326 Index: libffi/README
327 ===================================================================
328 --- libffi.orig/README
329 +++ libffi/README
330 @@ -58,6 +58,7 @@ tested:
331  | AVR32        | Linux            |
332  | HPPA         | HPUX             |
333  | IA-64        | Linux            |
334 +| M68K         | FreeMiNT         |
335  | M68K         | RTEMS            |
336  | MIPS         | IRIX             |
337  | MIPS         | Linux            |
338 @@ -150,6 +151,7 @@ See the ChangeLog files for details.
339          Lots of build fixes.
340          Add Amiga newer MacOS support.
341         Add Linux/x32 support.
342 +       Add m68k FreeMiNT support.
343         Add thiscall and fastcall support on Windows.
344         Fix Octeon and MC68881 support.
345         Fix code pessimizations.