This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: m68k setjmp()


>>>>> "Ulrich" == Ulrich Drepper <drepper@redhat.com> writes:

Ulrich> Jes Sorensen <jes@trained-monkey.org> writes:
>> Is that a reasonable requirement to say that setjmp() just doesn't
>> work when compiled with -fomit-frame-pointer?

Ulrich> The implementation should be as general as possible.  If you
Ulrich> patch helps to do it it should be used.  It's up to Andreas to
Ulrich> decide (and apply).

Ok, here is a patch that seems to pass my test case (cpp0 in
gcc-2.95.4 build by gcc-2.95.4's stage1 compiler). The tests in the
setjmp directory pass as well.

I have gone through it several times to verify the filling in of the
__jmp_buf structure is correct, but it's of course possible I screwed
up.

Andreas, what do you think?

Cheers,
Jes

2001-10-15  Jes Sorensen  <jes@trained-monkey.org>

	* sysdeps/m68k/bsd-setjmp.S: Implement setjmp() inline in order
	not having to enlarge the stack frame and clobber the stack
	pointer. This makes setjmp() work for code compiled without a
	frame pointer.
	* sysdeps/m68k/bsd-_setjmp.S: Likewise for _setjmp().

--- glibc-2.2.4/sysdeps/m68k/bsd-_setjmp.S~	Mon Jul  9 14:58:12 2001
+++ glibc-2.2.4/sysdeps/m68k/bsd-_setjmp.S	Mon Oct 15 22:13:50 2001
@@ -1,6 +1,7 @@
 /* BSD `_setjmp' entry point to `sigsetjmp (..., 0)'.  m68k version.
-   Copyright (C) 1994, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1997, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
+   Contributed by Jes Sorensen <jes@trained-monkey.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -17,33 +18,33 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-/* This just does a tail-call to `__sigsetjmp (ARG, 0)'.
-   We cannot do it in C because it must be a tail-call, so frame-unwinding
-   in setjmp doesn't clobber the state restored by longjmp.  */
+/* This cannot just call __sigsetjmp (ARG, 0) since it would require us
+   to enlarge the stack frame frame to add the extra argument which results
+   in clobbering the stack pointer. */
 
 #include <sysdep.h>
-
-#ifdef MOTOROLA_SYNTAX
-#define d0 %d0
-#define d1 %d1
-#define PUSH(reg)	move.l reg, -(%sp)
-#define POP(reg)	move.l (%sp)+, reg
-#define PUSH0		clr.l -(%sp)
-#else
-#define PUSH(reg)	movel reg, sp@-
-#define POP(reg)	movel sp@+, reg
-#define PUSH0		clrl sp@-
-#endif
+#include "asm-syntax.h"
 
 ENTRY (_setjmp)
-	POP (d0)		/* Pop return PC.  */
-	POP (d1)		/* Pop jmp_buf argument.  */
-	PUSH0			/* Push second argument of zero.  */
-	PUSH (d1)		/* Push back first argument.  */
-	PUSH (d0)		/* Push back return PC.  */
+	movel	MEM_DISP(sp, 4), R(a0)		/* Pointer to env  */
+	moveml	R(d1)-R(d7), MEM(a0)		/* Store regs d1-d7 */
+	moveq	#28, R(d0)
+	addl	R(d0), R(a0)
+	movel	MEM(sp), MEM_POSTINC(a0)	/* Save return address */
+	moveml	R(a1)-R(fp), MEM(a0)		/* Save regs a1-a6 (fp) */
+	moveq	#24, R(d0)
+	addl	R(d0), R(a0)
+	movel	R(sp), MEM_POSTINC(a0)		/* Save caller's SP */
+#if	defined(__HAVE_68881__) || defined(__HAVE_FPU__)
+	fmovemx	R(fp0)-R(fp7), MEM(a0)
+#endif
+	clrl	MEM_PREDEC(sp)
+	movel	MEM_DISP(sp, 8), MEM_PREDEC(sp)
 #ifdef PIC
-	bra.l C_SYMBOL_NAME (__sigsetjmp@PLTPC)
+	bsrl C_SYMBOL_NAME (__sigjmp_save@PLTPC)
 #else
-	jmp C_SYMBOL_NAME (__sigsetjmp)
+	jsr C_SYMBOL_NAME (__sigjmp_save)
 #endif
+	addl	#8, R(sp)
+	rts
 END (_setjmp)
--- glibc-2.2.4/sysdeps/m68k/bsd-setjmp.S~	Mon Jul  9 14:58:12 2001
+++ glibc-2.2.4/sysdeps/m68k/bsd-setjmp.S	Mon Oct 15 22:14:01 2001
@@ -1,6 +1,7 @@
 /* BSD `setjmp' entry point to `sigsetjmp (..., 1)'.  m68k version.
-   Copyright (C) 1994, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1997, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
+   Contributed by Jes Sorensen <jes@trained-monkey.org>.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -17,31 +18,33 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-/* This just does a tail-call to `__sigsetjmp (ARG, 1)'.
-   We cannot do it in C because it must be a tail-call, so frame-unwinding
-   in setjmp doesn't clobber the state restored by longjmp.  */
+/* This cannot just call __sigsetjmp (ARG, 1) since it would require us
+   to enlarge the stack frame frame to add the extra argument which results
+   in clobbering the stack pointer. */
 
 #include <sysdep.h>
-
-#ifdef MOTOROLA_SYNTAX
-#define d0 %d0
-#define d1 %d1
-#define PUSH(reg)	move.l reg, -(%sp)
-#define POP(reg)	move.l (%sp)+, reg
-#else
-#define PUSH(reg)	movel reg, sp@-
-#define POP(reg)	movel sp@+, reg
-#endif
+#include "asm-syntax.h"
 
 ENTRY (setjmp)
-	POP (d0)		/* Pop return PC.  */
-	POP (d1)		/* Pop jmp_buf argument.  */
-	pea 1			/* Push second argument of one.  */
-	PUSH (d1)		/* Push back first argument.  */
-	PUSH (d0)		/* Push back return PC.  */
+	movel	MEM_DISP(sp, 4), R(a0)		/* Pointer to env  */
+	moveml	R(d1)-R(d7), MEM(a0)		/* Store regs d1-d7 */
+	moveq	#28, R(d0)
+	addl	R(d0), R(a0)
+	movel	MEM(sp), MEM_POSTINC(a0)	/* Save return address */
+	moveml	R(a1)-R(fp), MEM(a0)		/* Save regs a1-a6 (fp) */
+	moveq	#24, R(d0)
+	addl	R(d0), R(a0)
+	movel	R(sp), MEM_POSTINC(a0)		/* Save caller's SP */
+#if	defined(__HAVE_68881__) || defined(__HAVE_FPU__)
+	fmovemx	R(fp0)-R(fp7), MEM(a0)
+#endif
+	pea	1
+	movel	MEM_DISP(sp, 8), MEM_PREDEC(sp)
 #ifdef PIC
-	bra.l C_SYMBOL_NAME (__sigsetjmp@PLTPC)
+	bsrl C_SYMBOL_NAME (__sigjmp_save@PLTPC)
 #else
-	jmp C_SYMBOL_NAME (__sigsetjmp)
+	jsr C_SYMBOL_NAME (__sigjmp_save)
 #endif
+	addl	#8, R(sp)
+	rts
 END (setjmp)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]