Fix on sparc and sparc64.

ok phessler@ jasper@
This commit is contained in:
joshe 2010-09-23 13:38:33 +00:00
parent 9cb945ffc2
commit 4770ab0216
7 changed files with 203 additions and 16 deletions

View File

@ -1,15 +1,15 @@
# $OpenBSD: Makefile,v 1.16 2010/08/23 16:23:13 jasper Exp $
# $OpenBSD: Makefile,v 1.17 2010/09/23 13:38:33 joshe Exp $
# $FreeBSD: ports/devel/ffcall/Makefile,v 1.2 2001/08/31 14:20:18 sobomax Exp $
# Original From: jagapen@home.com
# m68k: mmap configure test causes system hang
# arm: doesn't build super-old and broken assember files
ONLY_FOR_ARCH= alpha amd64 hppa i386 mips64 mips64el powerpc sparc64
ONLY_FOR_ARCH= alpha amd64 hppa i386 mips64 mips64el powerpc sparc sparc64
COMMENT= foreign function call libraries
DISTNAME= ffcall-1.10
REVISION = 0
REVISION = 1
SHARED_LIBS= avcall 1.0 \
callback 1.0
CATEGORIES= devel
@ -29,6 +29,12 @@ CONFIGURE_STYLE=gnu
CONFIGURE_ARGS= ${CONFIGURE_SHARED}
MODGNU_CONFIG_GUESS_DIRS=${WRKSRC}/autoconf
.if ${MACHINE_ARCH} == "sparc"
CONFIGURE_ENV += cl_cv_c_struct_return_small=no
.elif ${MACHINE_ARCH} == "sparc64"
CONFIGURE_ENV += cl_cv_c_struct_return_small=yes
.endif
FAKE_FLAGS= htmldir="\$$(datadir)/doc/ffcall/html"
pre-install:

View File

@ -1,6 +1,11 @@
$OpenBSD: patch-avcall_avcall-sparc64_S,v 1.2 2004/01/15 07:43:01 pvalchev Exp $
--- avcall/avcall-sparc64.S.orig 1999-11-26 13:28:33.000000000 -0700
+++ avcall/avcall-sparc64.S 2004-01-15 00:25:33.000000000 -0700
$OpenBSD: patch-avcall_avcall-sparc64_S,v 1.3 2010/09/23 13:38:33 joshe Exp $
Add missing .register declaration for %g3.
Account for the stack bias when using %sp.
Use [foo,bar] syntax instead of bar(foo).
--- avcall/avcall-sparc64.S.orig Fri Nov 26 12:28:33 1999
+++ avcall/avcall-sparc64.S Tue Apr 7 14:20:26 2009
@@ -3,6 +3,7 @@
.version "01.01"
.section ".text"
@ -9,6 +14,15 @@ $OpenBSD: patch-avcall_avcall-sparc64_S,v 1.2 2004/01/15 07:43:01 pvalchev Exp $
.global __builtin_avcall
DECLARE_FUNCTION(__builtin_avcall)
.type __builtin_avcall,$function
@@ -14,7 +15,7 @@ __builtin_avcall:
ldx [%i0+40], %g3
ld [%i0+60], %o7
add %g3, -72, %g3
- add %sp, 136, %g1
+ add %sp, 2175, %g1
sub %g3, %i0, %g3
cmp %o7, 0
sdivx %g3, 8, %g3
@@ -24,98 +25,98 @@ __builtin_avcall:
cmp %g3, 0
be,pn %icc, .LL161
@ -227,7 +241,7 @@ $OpenBSD: patch-avcall_avcall-sparc64_S,v 1.2 2004/01/15 07:43:01 pvalchev Exp $
be,pn %icc, .LL191
sethi %hi(32768), %g3
- ldd 184(%i0),%f28
+ ldd [%i0+186],%f28
+ ldd [%i0+184],%f28
sethi %hi(32768), %g3
.LL191:
andcc %o7, %g3, %g0

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-avcall_avcall_h_in,v 1.1 2010/09/23 13:38:33 joshe Exp $
--- avcall/avcall.h.in.orig Mon Jan 26 06:58:41 2004
+++ avcall/avcall.h.in Sat Apr 25 16:17:43 2009
@@ -1307,8 +1307,9 @@ typedef struct
? -1 : (ASSIGN(TYPE,TYPE_SIZE,TYPE_ALIGN,(void*)((__avword)(LIST).aptr-(TYPE_SIZE)),VAL),\
(LIST).aptr = (__avword*)(((__avword)(LIST).aptr+sizeof(__avword)-1) & -(long)sizeof(__avword)),\
((LIST).anum < 16 \
- && ((LIST).farg_mask |= (-1 << (LIST).anum), \
- (LIST).darg_mask |= (-1 << (LIST).anum))), \
+ && ((TYPE_SIZE) > 4 \
+ ? ((LIST).darg_mask |= (-1 << (LIST).anum)) \
+ : ((LIST).farg_mask |= (-1 << (LIST).anum)))), \
(LIST).anum += (((((TYPE_SIZE)+(TYPE_ALIGN)-1) & -(long)(TYPE_ALIGN)) + sizeof(__avword)-1) & -(long)sizeof(__avword))/sizeof(__avword),\
(LIST).farg_mask &= (1 << ((LIST).anum < 16 ? (LIST).anum : 16)) - 1, \
(LIST).darg_mask &= (1 << ((LIST).anum < 16 ? (LIST).anum : 16)) - 1, \

View File

@ -1,6 +1,14 @@
$OpenBSD: patch-callback_trampoline_r_trampoline_c,v 1.2 2010/08/23 14:16:09 jasper Exp $
$OpenBSD: patch-callback_trampoline_r_trampoline_c,v 1.3 2010/09/23 13:38:33 joshe Exp $
Fix the horrible trampoline code to work on sparc and
sparc64. OpenBSD's runtime linker trashes registers which are supposed
to be preserved across function calls, so steal some space on the
stack instead.
Also fix powerpc and mips64.
--- callback/trampoline_r/trampoline.c.orig Mon Jan 26 07:00:05 2004
+++ callback/trampoline_r/trampoline.c Sat Jul 31 06:59:02 2010
+++ callback/trampoline_r/trampoline.c Fri Jul 30 14:34:10 2010
@@ -21,7 +21,7 @@
#endif
#endif
@ -23,3 +31,99 @@ $OpenBSD: patch-callback_trampoline_r_trampoline_c,v 1.2 2010/08/23 14:16:09 jas
#endif
#endif
#endif
@@ -259,11 +259,11 @@ extern void __TR_clear_cache();
#define TRAMP_ALIGN 8
#endif
#if defined(__sparc__) && !defined(__sparc64__)
-#define TRAMP_LENGTH 16
+#define TRAMP_LENGTH 24
#define TRAMP_ALIGN 16
#endif
#ifdef __sparc64__
-#define TRAMP_LENGTH 32
+#define TRAMP_LENGTH 40
#define TRAMP_ALIGN 16
#endif
#ifdef __alpha__
@@ -614,52 +614,64 @@ __TR_function alloc_trampoline_r (address, data0, data
/* function:
* sethi %hi(<data>),%g2 05000000 | (<data> >> 10)
* sethi %hi(<address>),%g1 03000000 | (<address> >> 10)
- * jmp %g1+%lo(<address>) 81C06000 | (<address> & 0x3ff)
+ * add %sp,-8,%sp 9C03BFF8
* or %g2,%lo(<data>),%g2 8410A000 | (<data> & 0x3ff)
+ * jmp %g1+%lo(<address>) 81C06000 | (<address> & 0x3ff)
+ * st %g2,[%sp+96] C423A060
*/
#define hi(word) ((unsigned long) (word) >> 10)
#define lo(word) ((unsigned long) (word) & 0x3ff)
*(long *) (function + 0) = 0x05000000 | hi(data);
*(long *) (function + 4) = 0x03000000 | hi(address);
- *(long *) (function + 8) = 0x81C06000 | lo(address);
+ *(long *) (function + 8) = 0x9C03BFF8;
*(long *) (function +12) = 0x8410A000 | lo(data);
+ *(long *) (function +16) = 0x81C06000 | lo(address);
+ *(long *) (function +20) = 0xC423A060;
#define is_tramp(function) \
(*(long *) (function + 0) & 0xffc00000) == 0x05000000 && \
(*(long *) (function + 4) & 0xffc00000) == 0x03000000 && \
- (*(long *) (function + 8) & 0xfffffc00) == 0x81C06000 && \
- (*(long *) (function +12) & 0xfffffc00) == 0x8410A000
+ (*(long *) (function + 8)) == 0x9C03BFF8 && \
+ (*(long *) (function +12) & 0xfffffc00) == 0x8410A000 && \
+ (*(long *) (function +16) & 0xfffffc00) == 0x81C06000 && \
+ (*(long *) (function +20)) == 0xC423A060
#define hilo(hiword,loword) (((hiword) << 10) | ((loword) & 0x3ff))
#define tramp_address(function) \
- hilo(*(long *) (function + 4), *(long *) (function + 8))
+ hilo(*(long *) (function + 4), *(long *) (function +16))
#define tramp_data(function) \
hilo(*(long *) (function + 0), *(long *) (function +12))
#endif
#ifdef __sparc64__
/* function:
* rd %pc,%g1 83414000
- * ldx [%g1+24],%g2 C4586018
+ * ldx [%g1+32],%g2 C4586020
+ * ldx [%g1+24],%g5 CA586018
+ * add %sp,-32,%sp 9C03BFE0
* jmp %g2 81C08000
- * ldx [%g1+16],%g5 CA586010
+ * stx %g5,[%sp+2239] CA73A8BF
* .long high32(<data>) <data> >> 32
* .long low32(<data>) <data> & 0xffffffff
* .long high32(<address>) <address> >> 32
* .long low32(<address>) <address> & 0xffffffff
*/
*(int *) (function + 0) = 0x83414000;
- *(int *) (function + 4) = 0xC4586018;
- *(int *) (function + 8) = 0x81C08000;
- *(int *) (function +12) = 0xCA586010;
- *(long *) (function +16) = (long) data;
- *(long *) (function +24) = (long) address;
+ *(int *) (function + 4) = 0xC4586020;
+ *(int *) (function + 8) = 0xCA586018;
+ *(int *) (function +12) = 0x9C03BFE0;
+ *(int *) (function +16) = 0x81C08000;
+ *(int *) (function +20) = 0xCA73A8BF;
+ *(long *) (function +24) = (long) data;
+ *(long *) (function +32) = (long) address;
#define is_tramp(function) \
*(int *) (function + 0) == 0x83414000 && \
- *(int *) (function + 4) == 0xC4586018 && \
- *(int *) (function + 8) == 0x81C08000 && \
- *(int *) (function +12) == 0xCA586010
+ *(int *) (function + 4) == 0xC4586020 && \
+ *(int *) (function + 8) == 0xCA586018 && \
+ *(int *) (function +12) == 0x9C03BFE0 && \
+ *(int *) (function +16) == 0x81C08000 && \
+ *(int *) (function +20) == 0xCA73A8BF
#define tramp_address(function) \
- *(long *) (function +24)
+ *(long *) (function +32)
#define tramp_data(function) \
- *(long *) (function +16)
+ *(long *) (function +24)
#endif
#ifdef __alpha__
/* function:

View File

@ -1,7 +1,13 @@
$OpenBSD: patch-callback_vacall_r_vacall-sparc64_S,v 1.1 2004/01/16 22:01:45 naddy Exp $
--- callback/vacall_r/vacall-sparc64.S.orig 2004-01-16 22:47:29.000000000 +0100
+++ callback/vacall_r/vacall-sparc64.S 2004-01-16 22:47:53.000000000 +0100
@@ -4,6 +4,8 @@
$OpenBSD: patch-callback_vacall_r_vacall-sparc64_S,v 1.2 2010/09/23 13:38:33 joshe Exp $
Add missing .register declarations.
Load the saved callback data from the stack into %g5, see the
trampoline.c patch for more info.
Initalize __va_alist->anum to 0.
--- callback/vacall_r/vacall-sparc64.S.orig Fri Nov 26 12:35:23 1999
+++ callback/vacall_r/vacall-sparc64.S Sat Apr 25 13:58:31 2009
@@ -4,10 +4,14 @@
.section ".text"
.align 4
.global __vacall_r
@ -10,3 +16,17 @@ $OpenBSD: patch-callback_vacall_r_vacall-sparc64_S,v 1.1 2004/01/16 22:01:45 nad
DECLARE_FUNCTION(__vacall_r)
.type __vacall_r,$function
.proc 020
__vacall_r:
+ ldx [%sp+2239], %g5
+ add %sp, 32, %sp
!$PROLOGUE$ 0
save %sp, -448, %sp
!$PROLOGUE$ 1
@@ -55,6 +59,7 @@ __vacall_r:
st %f31, [%fp+1895]
st %g0, [%fp+1775]
stx %g0, [%fp+1791]
+ st %g0, [%fp+1831]
st %g0, [%fp+1799]
ldx [%g5], %o2
call %o2, 0

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-callback_vacall_r_vacall-sparc_S,v 1.1 2010/09/23 13:38:33 joshe Exp $
Load the saved callback data from the stack into %g2, see the
trampoline.c patch for more info.
--- callback/vacall_r/vacall-sparc.S.orig Fri Nov 26 12:13:06 1999
+++ callback/vacall_r/vacall-sparc.S Sat May 2 20:13:30 2009
@@ -5,6 +5,8 @@
DECLARE_FUNCTION(__vacall_r)
.proc 020
C(__vacall_r:)
+ ld [%sp+96], %g2
+ add %sp, 8, %sp
!$PROLOGUE$ 0
save %sp, -144, %sp
!$PROLOGUE$ 1

View File

@ -1,6 +1,10 @@
$OpenBSD: patch-vacall_vacall-sparc64_S,v 1.2 2007/01/26 22:32:23 steven Exp $
--- vacall/vacall-sparc64.S.orig Wed Jun 2 21:00:42 2004
+++ vacall/vacall-sparc64.S Fri Jan 26 23:11:52 2007
$OpenBSD: patch-vacall_vacall-sparc64_S,v 1.3 2010/09/23 13:38:33 joshe Exp $
Add missing .register declarations.
Initalize __va_alist->anum to 0.
--- vacall/vacall-sparc64.S.orig Wed Jun 2 12:00:42 2004
+++ vacall/vacall-sparc64.S Thu Apr 9 19:15:56 2009
@@ -4,6 +4,8 @@
.section ".text"
.align 4
@ -10,3 +14,11 @@ $OpenBSD: patch-vacall_vacall-sparc64_S,v 1.2 2007/01/26 22:32:23 steven Exp $
DECLARE_FUNCTION(__vacall)
.type __vacall,$function
.proc 020
@@ -57,6 +59,7 @@ __vacall:
st %f31, [%fp+1895]
st %g0, [%fp+1775]
stx %g0, [%fp+1791]
+ st %g0, [%fp+1831]
call %o2, 0
st %g0, [%fp+1799]
ld [%fp+1799], %o0