Dixi quod…

>Hello Debian libffi maintainer, you will receive patches in a separate
>message against unstable (3.0.10) and experimental (3.0.11) as well as
>gcc-4.7 (uses something close to 3.0.10 but not quite).

OK, attached are:

• Patch against libffi from unstable
  ‣ symbols file change:
--- debian/libffi5.symbols.m68k (libffi5_3.0.10-3+m68k.4_m68k)
+++ dpkg-gensymbolsKl0ncP       2012-12-02 22:08:22.000000000 +0000
@@ -14,6 +14,7 @@
  ffi_prep_args@Base 3.0.4
  ffi_prep_cif@Base 3.0.4
  ffi_prep_cif_machdep@Base 3.0.4
+ ffi_prep_cif_var@Base 3.0.10-3+m68k.4
  ffi_prep_closure@Base 3.0.4
  ffi_prep_closure_loc@Base 3.0.4
  ffi_prep_java_raw_closure@Base 3.0.4

• Patch against libffi from experimental
  (with the caveat that I believe some testcases to be broken;
  the patch adds no new failures)

• Drop-in replacement for debian/patches/libffi-m68k.diff
  in gcc-4.7_4.7.2-12

I’m keeping the gcc-4.6 patch separate, as I’m currently
juggling a larger m68k related patchset, which I’ll post
occasionally to #694112 to be applied after the unfreeze.

>Andreas, I think you can commit the GCC side of the patch as well, so
>I’ll keep debian-68k on Cc for the followup message with them.

See above ;)

bye,
//mirabilos
-- 
FWIW, I'm quite impressed with mksh interactively. I thought it was much
*much* more bare bones. But it turns out it beats the living hell out of
ksh93 in that respect. I'd even consider it for my daily use if I hadn't
wasted half my life on my zsh setup. :-) -- Frank Terbeck in #!/bin/mksh
--- a/src/libffi/src/m68k/ffi.c
+++ b/src/libffi/src/m68k/ffi.c
@@ -107,6 +107,8 @@ ffi_prep_args (void *stack, extended_cif
 #define CIF_FLAGS_POINTER      32
 #define CIF_FLAGS_STRUCT1      64
 #define CIF_FLAGS_STRUCT2      128
+#define CIF_FLAGS_SINT8                256
+#define CIF_FLAGS_SINT16       512
 
 /* Perform machine dependent cif processing */
 ffi_status
@@ -120,6 +122,13 @@ ffi_prep_cif_machdep (ffi_cif *cif)
       break;
 
     case FFI_TYPE_STRUCT:
+      if (cif->rtype->elements[0]->type == FFI_TYPE_STRUCT &&
+          cif->rtype->elements[1])
+        {
+          cif->flags = 0;
+          break;
+        }
+
       switch (cif->rtype->size)
        {
        case 1:
@@ -163,6 +172,14 @@ ffi_prep_cif_machdep (ffi_cif *cif)
       cif->flags = CIF_FLAGS_DINT;
       break;
 
+    case FFI_TYPE_SINT16:
+      cif->flags = CIF_FLAGS_SINT16;
+      break;
+
+    case FFI_TYPE_SINT8:
+      cif->flags = CIF_FLAGS_SINT8;
+      break;
+
     default:
       cif->flags = CIF_FLAGS_INT;
       break;
@@ -261,7 +278,8 @@ ffi_prep_closure_loc (ffi_closure* closu
                      void *user_data,
                      void *codeloc)
 {
-  FFI_ASSERT (cif->abi == FFI_SYSV);
+  if (cif->abi != FFI_SYSV)
+    return FFI_BAD_ABI;
 
   *(unsigned short *)closure->tramp = 0x207c;
   *(void **)(closure->tramp + 2) = codeloc;
--- a/src/libffi/src/m68k/ffitarget.h
+++ b/src/libffi/src/m68k/ffitarget.h
@@ -34,8 +34,8 @@ typedef signed long            ffi_sarg;
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
--- a/src/libffi/src/m68k/sysv.S
+++ b/src/libffi/src/m68k/sysv.S
@@ -2,6 +2,7 @@
        
    sysv.S - Copyright (c) 1998, 2012 Andreas Schwab
            Copyright (c) 2008 Red Hat, Inc. 
+           Copyright (c) 2012 Thorsten Glaser
    
    m68k Foreign Function Interface 
 
@@ -153,8 +154,22 @@ retstruct1:
 
 retstruct2:
        btst    #7,%d2
-       jbeq    noretval
+       jbeq    retsint8
        move.w  %d0,(%a1)
+       jbra    epilogue
+
+retsint8:
+       btst    #8,%d2
+       jbeq    retsint16
+       extb.l  %d0
+       move.l  %d0,(%a1)
+       jbra    epilogue
+
+retsint16:
+       btst    #9,%d2
+       jbeq    noretval
+       ext.l   %d0
+       move.l  %d0,(%a1)
 
 noretval:
 epilogue:
@@ -186,8 +201,10 @@ ffi_closure_SYSV:
        lsr.l   #1,%d0
        jne     1f
        jcc     .Lcls_epilogue
+       | CIF_FLAGS_INT
        move.l  -12(%fp),%d0
 .Lcls_epilogue:
+       | no CIF_FLAGS_*
        unlk    %fp
        rts
 1:
@@ -195,6 +212,7 @@ ffi_closure_SYSV:
        lsr.l   #2,%d0
        jne     1f
        jcs     .Lcls_ret_float
+       | CIF_FLAGS_DINT
        move.l  (%a0)+,%d0
        move.l  (%a0),%d1
        jra     .Lcls_epilogue
@@ -209,6 +227,7 @@ ffi_closure_SYSV:
        lsr.l   #2,%d0
        jne     1f
        jcs     .Lcls_ret_ldouble
+       | CIF_FLAGS_DOUBLE
 #if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.d (%a0),%fp0
 #else
@@ -227,17 +246,31 @@ ffi_closure_SYSV:
        jra     .Lcls_epilogue
 1:
        lsr.l   #2,%d0
-       jne     .Lcls_ret_struct2
+       jne     1f
        jcs     .Lcls_ret_struct1
+       | CIF_FLAGS_POINTER
        move.l  (%a0),%a0
        move.l  %a0,%d0
        jra     .Lcls_epilogue
 .Lcls_ret_struct1:
        move.b  (%a0),%d0
        jra     .Lcls_epilogue
-.Lcls_ret_struct2:
+1:
+       lsr.l   #2,%d0
+       jne     1f
+       jcs     .Lcls_ret_sint8
+       | CIF_FLAGS_STRUCT2
        move.w  (%a0),%d0
        jra     .Lcls_epilogue
+.Lcls_ret_sint8:
+       move.l  (%a0),%d0
+       extb.l  %d0
+       jra     .Lcls_epilogue
+1:
+       | CIF_FLAGS_SINT16
+       move.l  (%a0),%d0
+       ext.l   %d0
+       jra     .Lcls_epilogue
        CFI_ENDPROC()
 
        .size   ffi_closure_SYSV,.-ffi_closure_SYSV
diff -Nru libffi-3.0.10/debian/changelog libffi-3.0.10/debian/changelog
--- libffi-3.0.10/debian/changelog      2012-12-02 21:49:27.000000000 +0000
+++ libffi-3.0.10/debian/changelog      2012-12-02 21:49:54.000000000 +0000
@@ -1,3 +1,10 @@
+libffi (3.0.10-3+m68k.4) unreleased; urgency=low
+
+  * Update m68k code from master with fixes by Andreas Schwab and
+    Alan Hourihane; fix signed 8/16-bit calls myself (Closes: #660525)
+
+ -- Thorsten Glaser <t...@mirbsd.de>  Sun, 02 Dec 2012 21:18:16 +0000
+
 libffi (3.0.10-3) unstable; urgency=low
 
   * Fix powerpc and ppc64 builds (Kyle Moffett).
diff -Nru libffi-3.0.10/src/m68k/ffi.c libffi-3.0.10/src/m68k/ffi.c
--- libffi-3.0.10/src/m68k/ffi.c        2011-07-28 19:45:45.000000000 +0000
+++ libffi-3.0.10/src/m68k/ffi.c        2012-12-02 21:49:54.000000000 +0000
@@ -107,6 +107,8 @@
 #define CIF_FLAGS_POINTER      32
 #define CIF_FLAGS_STRUCT1      64
 #define CIF_FLAGS_STRUCT2      128
+#define CIF_FLAGS_SINT8                256
+#define CIF_FLAGS_SINT16       512
 
 /* Perform machine dependent cif processing */
 ffi_status
@@ -120,6 +122,13 @@
       break;
 
     case FFI_TYPE_STRUCT:
+      if (cif->rtype->elements[0]->type == FFI_TYPE_STRUCT &&
+          cif->rtype->elements[1])
+        {
+          cif->flags = 0;
+          break;
+        }
+
       switch (cif->rtype->size)
        {
        case 1:
@@ -163,6 +172,14 @@
       cif->flags = CIF_FLAGS_DINT;
       break;
 
+    case FFI_TYPE_SINT16:
+      cif->flags = CIF_FLAGS_SINT16;
+      break;
+
+    case FFI_TYPE_SINT8:
+      cif->flags = CIF_FLAGS_SINT8;
+      break;
+
     default:
       cif->flags = CIF_FLAGS_INT;
       break;
@@ -261,7 +278,8 @@
                      void *user_data,
                      void *codeloc)
 {
-  FFI_ASSERT (cif->abi == FFI_SYSV);
+  if (cif->abi != FFI_SYSV)
+    return FFI_BAD_ABI;
 
   *(unsigned short *)closure->tramp = 0x207c;
   *(void **)(closure->tramp + 2) = codeloc;
diff -Nru libffi-3.0.10/src/m68k/sysv.S libffi-3.0.10/src/m68k/sysv.S
--- libffi-3.0.10/src/m68k/sysv.S       2011-07-28 19:45:45.000000000 +0000
+++ libffi-3.0.10/src/m68k/sysv.S       2012-12-02 21:49:54.000000000 +0000
@@ -2,6 +2,7 @@
        
    sysv.S - Copyright (c) 1998 Andreas Schwab
            Copyright (c) 2008 Red Hat, Inc. 
+           Copyright (c) 2012 Thorsten Glaser
    
    m68k Foreign Function Interface 
 
@@ -87,7 +88,7 @@
 
        | If the return value pointer is NULL, assume no return value.
        | NOTE: On the mc68000, tst on an address register is not supported.
-#if defined(__mc68000__) && !defined(__mcoldfire__)
+#if !defined(__mc68020__) && !defined(__mc68030__) && !defined(__mc68040__) && 
!defined(__mc68060__) && !defined(__mcoldfire__)
        cmp.w   #0, %a1
 #else
        tst.l   %a1
@@ -109,7 +110,7 @@
 retfloat:
        btst    #2,%d2
        jbeq    retdouble
-#if defined(__MC68881__)
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.s %fp0,(%a1)
 #else
        move.l  %d0,(%a1)
@@ -119,7 +120,7 @@
 retdouble:
        btst    #3,%d2
        jbeq    retlongdouble
-#if defined(__MC68881__)
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.d %fp0,(%a1)
 #else
        move.l  %d0,(%a1)+
@@ -130,7 +131,7 @@
 retlongdouble:
        btst    #4,%d2
        jbeq    retpointer
-#if defined(__MC68881__)
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.x %fp0,(%a1)
 #else
        move.l  %d0,(%a1)+
@@ -153,8 +154,22 @@
 
 retstruct2:
        btst    #7,%d2
-       jbeq    noretval
+       jbeq    retsint8
        move.w  %d0,(%a1)
+       jbra    epilogue
+
+retsint8:
+       btst    #8,%d2
+       jbeq    retsint16
+       extb.l  %d0
+       move.l  %d0,(%a1)
+       jbra    epilogue
+
+retsint16:
+       btst    #9,%d2
+       jbeq    noretval
+       ext.l   %d0
+       move.l  %d0,(%a1)
 
 noretval:
 epilogue:
@@ -186,8 +201,10 @@
        lsr.l   #1,%d0
        jne     1f
        jcc     .Lcls_epilogue
+       | CIF_FLAGS_INT
        move.l  -12(%fp),%d0
 .Lcls_epilogue:
+       | no CIF_FLAGS_*
        unlk    %fp
        rts
 1:
@@ -195,11 +212,12 @@
        lsr.l   #2,%d0
        jne     1f
        jcs     .Lcls_ret_float
+       | CIF_FLAGS_DINT
        move.l  (%a0)+,%d0
        move.l  (%a0),%d1
        jra     .Lcls_epilogue
 .Lcls_ret_float:
-#if defined(__MC68881__)
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.s (%a0),%fp0
 #else
        move.l  (%a0),%d0
@@ -209,7 +227,8 @@
        lsr.l   #2,%d0
        jne     1f
        jcs     .Lcls_ret_ldouble
-#if defined(__MC68881__)
+       | CIF_FLAGS_DOUBLE
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.d (%a0),%fp0
 #else
        move.l  (%a0)+,%d0
@@ -217,7 +236,7 @@
 #endif
        jra     .Lcls_epilogue
 .Lcls_ret_ldouble:
-#if defined(__MC68881__)
+#if defined(__MC68881__) || defined(__HAVE_68881__)
        fmove.x (%a0),%fp0
 #else
        move.l  (%a0)+,%d0
@@ -227,17 +246,31 @@
        jra     .Lcls_epilogue
 1:
        lsr.l   #2,%d0
-       jne     .Lcls_ret_struct2
+       jne     1f
        jcs     .Lcls_ret_struct1
+       | CIF_FLAGS_POINTER
        move.l  (%a0),%a0
        move.l  %a0,%d0
        jra     .Lcls_epilogue
 .Lcls_ret_struct1:
        move.b  (%a0),%d0
        jra     .Lcls_epilogue
-.Lcls_ret_struct2:
+1:
+       lsr.l   #2,%d0
+       jne     1f
+       jcs     .Lcls_ret_sint8
+       | CIF_FLAGS_STRUCT2
        move.w  (%a0),%d0
        jra     .Lcls_epilogue
+.Lcls_ret_sint8:
+       move.l  (%a0),%d0
+       extb.l  %d0
+       jra     .Lcls_epilogue
+1:
+       | CIF_FLAGS_SINT16
+       move.l  (%a0),%d0
+       ext.l   %d0
+       jra     .Lcls_epilogue
        CFI_ENDPROC()
 
        .size   ffi_closure_SYSV,.-ffi_closure_SYSV
diff -Nru libffi-3.0.11/debian/changelog libffi-3.0.11/debian/changelog
--- libffi-3.0.11/debian/changelog      2012-11-06 17:49:28.000000000 +0000
+++ libffi-3.0.11/debian/changelog      2012-12-02 21:18:13.000000000 +0000
@@ -1,3 +1,9 @@
+libffi (3.0.11-3+m68k.2) unreleased-experimental; urgency=low
+
+  * Fix signed 8/16-bit calls on m68k (Closes: #660525)
+
+ -- Thorsten Glaser <t...@mirbsd.de>  Sun, 02 Dec 2012 21:18:07 +0000
+
 libffi (3.0.11-3) experimental; urgency=low
 
   * Add missing AArch64 patches.
diff -Nru libffi-3.0.11/debian/patches/m68k-fix.diff 
libffi-3.0.11/debian/patches/m68k-fix.diff
--- libffi-3.0.11/debian/patches/m68k-fix.diff  1970-01-01 00:00:00.000000000 
+0000
+++ libffi-3.0.11/debian/patches/m68k-fix.diff  2012-12-02 21:10:19.000000000 
+0000
@@ -0,0 +1,121 @@
+--- a/src/m68k/ffi.c
++++ b/src/m68k/ffi.c
+@@ -123,6 +123,8 @@ ffi_prep_args (void *stack, extended_cif
+ #define CIF_FLAGS_POINTER     32
+ #define CIF_FLAGS_STRUCT1     64
+ #define CIF_FLAGS_STRUCT2     128
++#define CIF_FLAGS_SINT8               256
++#define CIF_FLAGS_SINT16      512
+ 
+ /* Perform machine dependent cif processing */
+ ffi_status
+@@ -200,6 +202,14 @@ ffi_prep_cif_machdep (ffi_cif *cif)
+       cif->flags = CIF_FLAGS_DINT;
+       break;
+ 
++    case FFI_TYPE_SINT16:
++      cif->flags = CIF_FLAGS_SINT16;
++      break;
++
++    case FFI_TYPE_SINT8:
++      cif->flags = CIF_FLAGS_SINT8;
++      break;
++
+     default:
+       cif->flags = CIF_FLAGS_INT;
+       break;
+--- a/src/m68k/sysv.S
++++ b/src/m68k/sysv.S
+@@ -3,6 +3,7 @@
+    sysv.S - Copyright (c) 2012 Alan Hourihane
+           Copyright (c) 1998, 2012 Andreas Schwab
+           Copyright (c) 2008 Red Hat, Inc. 
++          Copyright (c) 2012 Thorsten Glaser
+    
+    m68k Foreign Function Interface 
+ 
+@@ -168,8 +169,22 @@ retstruct1:
+ 
+ retstruct2:
+       btst    #7,%d2
+-      jbeq    noretval
++      jbeq    retsint8
+       move.w  %d0,(%a1)
++      jbra    epilogue
++
++retsint8:
++      btst    #8,%d2
++      jbeq    retsint16
++      extb.l  %d0
++      move.l  %d0,(%a1)
++      jbra    epilogue
++
++retsint16:
++      btst    #9,%d2
++      jbeq    noretval
++      ext.l   %d0
++      move.l  %d0,(%a1)
+ 
+ noretval:
+ epilogue:
+@@ -201,8 +216,10 @@ CALLFUNC(ffi_closure_SYSV):
+       lsr.l   #1,%d0
+       jne     1f
+       jcc     .Lcls_epilogue
++      | CIF_FLAGS_INT
+       move.l  -12(%fp),%d0
+ .Lcls_epilogue:
++      | no CIF_FLAGS_*
+       unlk    %fp
+       rts
+ 1:
+@@ -210,6 +227,7 @@ CALLFUNC(ffi_closure_SYSV):
+       lsr.l   #2,%d0
+       jne     1f
+       jcs     .Lcls_ret_float
++      | CIF_FLAGS_DINT
+       move.l  (%a0)+,%d0
+       move.l  (%a0),%d1
+       jra     .Lcls_epilogue
+@@ -224,6 +242,7 @@ CALLFUNC(ffi_closure_SYSV):
+       lsr.l   #2,%d0
+       jne     1f
+       jcs     .Lcls_ret_ldouble
++      | CIF_FLAGS_DOUBLE
+ #if defined(__MC68881__) || defined(__HAVE_68881__)
+       fmove.d (%a0),%fp0
+ #else
+@@ -242,17 +261,31 @@ CALLFUNC(ffi_closure_SYSV):
+       jra     .Lcls_epilogue
+ 1:
+       lsr.l   #2,%d0
+-      jne     .Lcls_ret_struct2
++      jne     1f
+       jcs     .Lcls_ret_struct1
++      | CIF_FLAGS_POINTER
+       move.l  (%a0),%a0
+       move.l  %a0,%d0
+       jra     .Lcls_epilogue
+ .Lcls_ret_struct1:
+       move.b  (%a0),%d0
+       jra     .Lcls_epilogue
+-.Lcls_ret_struct2:
++1:
++      lsr.l   #2,%d0
++      jne     1f
++      jcs     .Lcls_ret_sint8
++      | CIF_FLAGS_STRUCT2
+       move.w  (%a0),%d0
+       jra     .Lcls_epilogue
++.Lcls_ret_sint8:
++      move.l  (%a0),%d0
++      extb.l  %d0
++      jra     .Lcls_epilogue
++1:
++      | CIF_FLAGS_SINT16
++      move.l  (%a0),%d0
++      ext.l   %d0
++      jra     .Lcls_epilogue
+       CFI_ENDPROC()
+ 
+       .size   CALLFUNC(ffi_closure_SYSV),.-CALLFUNC(ffi_closure_SYSV)
diff -Nru libffi-3.0.11/debian/patches/series 
libffi-3.0.11/debian/patches/series
--- libffi-3.0.11/debian/patches/series 2012-10-10 12:12:46.000000000 +0000
+++ libffi-3.0.11/debian/patches/series 2012-12-02 20:05:45.000000000 +0000
@@ -3,3 +3,4 @@
 aarch64-libffi.diff
 aarch64-libffi-testsuite.diff
 aarch64-config.diff
+m68k-fix.diff

Reply via email to