[PATCH] oops on entry to kdb with gcc 3.1

Jim Houston jim.houston at attbi.com
Fri Aug 2 04:02:30 PDT 2002


Hi Keith,

I was getting pretty desperate yesterday and even considered writing
the whole setjmp over in assembler;-)  Finally I realized that the
stack is pretty consistent.  If setjmp is compiled to save a frame
pointer it will always be the first thing pushed on the stack after
the return address.  So I don't need the __builtin_frame_address().

Here is a new version of the patch.  I like this better than
defeating the leaf optimization.

Jim Houston - Concurrent Computer Corp.

--

diff -urN -X dontdiff 2.4.18-ccur1.orig/arch/i386/kdb/kdbasupport.c 2.4.18-ccur1/arch/i386/kdb/kdbasupport.c
--- 2.4.18-ccur1.orig/arch/i386/kdb/kdbasupport.c	Wed Jun 12 09:44:32 2002
+++ 2.4.18-ccur1/arch/i386/kdb/kdbasupport.c	Thu Aug  1 19:48:29 2002
@@ -1041,56 +1041,37 @@
 int
 kdba_setjmp(kdb_jmp_buf *jb)
 {
-#if defined(CONFIG_FRAME_POINTER)
-	__asm__ ("movl 8(%esp), %eax\n\t"
-		 "movl %ebx, 0(%eax)\n\t"
-		 "movl %esi, 4(%eax)\n\t"
-		 "movl %edi, 8(%eax)\n\t"
-		 "movl (%esp), %ecx\n\t"
-		 "movl %ecx, 12(%eax)\n\t"
-		 "leal 8(%esp), %ecx\n\t"
-		 "movl %ecx, 16(%eax)\n\t"
-		 "movl 4(%esp), %ecx\n\t"
-		 "movl %ecx, 20(%eax)\n\t");
-#else	 /* CONFIG_FRAME_POINTER */
-	__asm__ ("movl 4(%esp), %eax\n\t"
-		 "movl %ebx, 0(%eax)\n\t"
-		 "movl %esi, 4(%eax)\n\t"
-		 "movl %edi, 8(%eax)\n\t"
-		 "movl %ebp, 12(%eax)\n\t"
-		 "leal 4(%esp), %ecx\n\t"
-		 "movl %ecx, 16(%eax)\n\t"
-		 "movl 0(%esp), %ecx\n\t"
-		 "movl %ecx, 20(%eax)\n\t");
-#endif   /* CONFIG_FRAME_POINTER */
+	register kdb_jmp_buf *eax asm("eax") = jb;
+	register long *ebp;
+
+	/* save the callee save registers. */
+	__asm__("movl %%ebx,0(%0)\n\t"
+		"movl %%esi,4(%0)\n\t"
+		"movl %%edi,8(%0)\n\t" : : "a" (eax));
+	/* check if we saved bp on our stack */
+	__asm__("movl	%%ebp,%0" : "=r" (ebp) : );
+	if (ebp == ((long *)&jb)-2)
+		ebp = (long *)(*ebp);
+	eax->regs[3] = (unsigned long)ebp;
+	eax->regs[4] = (unsigned long)&jb;
+	eax->regs[5] = (unsigned long)__builtin_return_address(0);
 	KDB_STATE_SET(LONGJMP);
 	return 0;
 }
 
 void
 kdba_longjmp(kdb_jmp_buf *jb, int reason)
-{
-#if defined(CONFIG_FRAME_POINTER)
-	__asm__("movl 8(%esp), %ecx\n\t"
-		"movl 12(%esp), %eax\n\t"
-		"movl 20(%ecx), %edx\n\t"
-		"movl 0(%ecx), %ebx\n\t"
-		"movl 4(%ecx), %esi\n\t"
-		"movl 8(%ecx), %edi\n\t"
-		"movl 12(%ecx), %ebp\n\t"
-		"movl 16(%ecx), %esp\n\t"
-		"jmp *%edx\n");
-#else    /* CONFIG_FRAME_POINTER */
-	__asm__("movl 4(%esp), %ecx\n\t"
-		"movl 8(%esp), %eax\n\t"
-		"movl 20(%ecx), %edx\n\t"
-		"movl 0(%ecx), %ebx\n\t"
-		"movl 4(%ecx), %esi\n\t"
-		"movl 8(%ecx), %edi\n\t"
-		"movl 12(%ecx), %ebp\n\t"
-		"movl 16(%ecx), %esp\n\t"
-		"jmp *%edx\n");
-#endif	 /* CONFIG_FRAME_POINTER */
+{                                                                               
+	__asm__(
+		"movl 20(%0), %%edx\n\t"
+		"movl 0(%0), %%ebx\n\t"
+		"movl 4(%0), %%esi\n\t"
+		"movl 8(%0), %%edi\n\t"
+		"movl 12(%0), %%ebp\n\t"
+		"movl 16(%0), %%esp\n\t"
+		"jmp *%%edx\n" : : 
+			"c" (jb),
+			"a" (reason));
 }
 #endif	/* KDB_HAVE_LONGJMP */
 



More information about the kdb mailing list