Subject: Re: Latest currnet kernels don't boot
To: Manuel Bouyer <bouyer@antioche.eu.org>
From: Matt Thomas <matt@3am-software.com>
List: port-macppc
Date: 11/20/2003 15:21:45
--=====================_13080058==_
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 02:09 PM 11/20/2003, Manuel Bouyer wrote:
>On Thu, Nov 20, 2003 at 01:41:57PM -0800, Matt Thomas wrote:
> > >yes, the attached patch fixes the problem on my 4400.
> >
> > I haven't been able to figure out why it fixes things.  It may be due
> > to the small number of TLBs on 603 but that doesn't seem right.  The
> > only I can think of is that de-referencing the PCB is causing an endless
> > amount of DSI faults.  But really the only two mapped pages active at
> > that point are the kernel stack and PCB and that's should cause a TLB
> > shortage.
>
>Is there something I can do to help debug this ?
>Unfortunably serial console on the 4400 doesn't work (OF bug I guess),
>and when it hang, I can't even enter ddb from keyboard.

I have a possible fix which I'll test tonight on my IBM NWS1000.
Rather than restoring ci_curpm, I'm moving the initial trapframe down
by one callframe.  Then directly after the trapframe, I'm storing a pointer
to the current process'es pmap.  This is nicer than ci_curpm since I don't
have to swap it on context switch.  Since I know the page is mapped and
accessible since I've restored the userstate from it, getting the pmap can
not result in another DSI fault.

I've attached the diffs (they at least build) but haven't tested them yet.



-- 
Matt Thomas                     email: matt@3am-software.com
3am Software Foundry              www: http://3am-software.com/bio/matt/
Cupertino, CA              disclaimer: I avow all knowledge of this message.


--=====================_13080058==_
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="603-diffs.txt"

Index: include/frame.h
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/include/frame.h,v
retrieving revision 1.17
diff -u -r1.17 frame.h
--- include/frame.h	27 Aug 2003 20:20:08 -0000	1.17
+++ include/frame.h	20 Nov 2003 23:22:49 -0000
@@ -100,7 +100,7 @@
  * This is to ensure alignment of the stackpointer
  */
 #define	FRAMELEN	roundup(sizeof(struct trapframe) + 2*sizeof(register_t), CALLFRAMELEN)
-#define	trapframe(l)	((struct trapframe *)((char *)(l)->l_addr + USPACE - FRAMELEN + 2*sizeof(register_t)))
+#define	trapframe(l)	((struct trapframe *)((char *)(l)->l_addr + USPACE - CALLFRAMELEN - FRAMELEN + 2*sizeof(register_t)))
 
 #define	SFRAMELEN	roundup(sizeof(struct switchframe), CALLFRAMELEN)
 struct switchframe {
Index: ibm4xx/trap_subr.S
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/ibm4xx/trap_subr.S,v
retrieving revision 1.9
diff -u -r1.9 trap_subr.S
--- ibm4xx/trap_subr.S	11 Aug 2003 05:13:21 -0000	1.9
+++ ibm4xx/trap_subr.S	20 Nov 2003 23:22:49 -0000
@@ -96,7 +96,7 @@
 	mtcr	31;						\
 	bc	4,17,1f;	/* branch if PSL_PR is clear */	\
 	GET_PCB(1);						\
-	addi	1,1,USPACE;	/* stack is top of user struct */ \
+	addi	1,1,USPACE-CALLFRAMELEN;	/* stack is top of user struct */ \
 1:
 
 #define	CRITICAL_PROLOG(savearea)	\
@@ -111,7 +111,7 @@
 	mtcr	31;						\
 	bc	4,17,1f;	/* branch if PSL_PR is clear */	\
 	GET_PCB(1);						\
-	addi	1,1,USPACE;	/* stack is top of user struct */ \
+	addi	1,1,USPACE-CALLFRAMELEN;	/* stack is top of user struct */ \
 1:
 
 
@@ -306,7 +306,7 @@
 					   overwritten) */
 	bc	4,17,s_trap		/* branch if PSL_PR is false */
 	GET_PCB(1)
-	addi	1,1,USPACE		/* stack is top of user struct */
+	addi	1,1,USPACE-CALLFRAMELEN		/* stack is top of user struct */
 /*
  * Now the common trap catching code.
  */
Index: oea/genassym.cf
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/oea/genassym.cf,v
retrieving revision 1.6
diff -u -r1.6 genassym.cf
--- oea/genassym.cf	27 Aug 2003 20:20:07 -0000	1.6
+++ oea/genassym.cf	20 Nov 2003 23:22:49 -0000
@@ -88,6 +88,7 @@
 define	FRAME_EXC	offsetof(struct trapframe, exc)
 define	FRAME_VRSAVE	offsetof(struct trapframe, tf_xtra[TF_VRSAVE])
 define	FRAME_MQ	offsetof(struct trapframe, tf_xtra[TF_MQ])
+define	FRAME_PM	sizeof(struct trapframe)
 
 define	IFRAMELEN		IFRAMELEN
 define	IFRAME_R1		offsetof(struct intrframe, r1)
Index: oea/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/oea/pmap.c,v
retrieving revision 1.16
diff -u -r1.16 pmap.c
--- oea/pmap.c	27 Oct 2003 23:35:41 -0000	1.16
+++ oea/pmap.c	20 Nov 2003 23:22:49 -0000
@@ -2101,6 +2101,7 @@
 	 * XXX Normally performed in cpu_fork().
 	 */
 	pcb->pcb_pm = pmap;
+	*(struct pmap **)(trapframe(l)+1) = pmap;
 }
 
 /*
Index: powerpc/trap_subr.S
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/trap_subr.S,v
retrieving revision 1.51
diff -u -r1.51 trap_subr.S
--- powerpc/trap_subr.S	22 Oct 2003 17:27:58 -0000	1.51
+++ powerpc/trap_subr.S	20 Nov 2003 23:22:50 -0000
@@ -728,6 +728,9 @@
 	RESTORE_MQ(%r1,%r8);						\
 	RESTORE_VRSAVE(%r1,%r9);					\
 	GET_CPUINFO(%r7);						\
+/* While the MMU is on, get the PMAP address and save it */		\
+	ldreg	%r8,(FRAME_PM+(2*SZREG))(%r1);	/* fetch pmap */	\
+	stptr	%r8,(savearea+CPUSAVE_R28)(%r7);  /* save pmap */	\
 	streg	%r2,(savearea+CPUSAVE_SRR0)(%r7); /* save SRR0 */	\
 	streg	%r3,(savearea+CPUSAVE_SRR1)(%r7); /* save SRR1 */	\
 	ldint	%r7,(FRAME_CR+(2*SZREG))(%r1);				\
@@ -770,11 +773,6 @@
 /* Can't touch %r1 from here on */					\
 	mtsprg2	%r2;			/* save r2 & r3 */		\
 	mtsprg3	%r3;							\
-/* While the MMU is on, get the PMAP address and save it */		\
-	GET_CPUINFO(%r2);						\
-	ldptr	%r3,CI_CURPCB(%r2);					\
-	ldptr	%r3,PCB_PM(%r3);					\
-	stptr	%r3,(savearea+CPUSAVE_R28)(%r2);			\
 /* Disable translation, machine check and recoverability: */		\
 	mfmsr	%r2;							\
 	andi.	%r2,%r2,~(PSL_DR|PSL_IR|PSL_ME|PSL_RI)@l;		\
@@ -861,7 +859,7 @@
 	GET_CPUINFO(%r1)		/* get cpu_info for this cpu */
 u_trap:
 	ldptr	%r1,CI_CURPCB(%r1)
-	addi	%r1,%r1,USPACE		/* stack is top of user struct */
+	addi	%r1,%r1,USPACE-CALLFRAMELEN /* stack is top of user struct */
 
 /*
  * Now the common trap catching code.
@@ -923,7 +921,7 @@
 s_sctrap:
 	GET_CPUINFO(%r1)
 	ldptr	%r1,CI_CURPCB(%r1)
-	addi	%r1,%r1,USPACE		/* stack is top of user struct */
+	addi	%r1,%r1,USPACE-CALLFRAMELEN /* stack is top of user struct */
 	RESTORE_KERN_SRS(%r30,%r31)	/* First enable KERNEL mapping */
 	CPU601_KERN_ENTRY(%r30,%r31)
 	FRAME_SETUP(CI_TEMPSAVE)
Index: powerpc/vm_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/vm_machdep.c,v
retrieving revision 1.57
diff -u -r1.57 vm_machdep.c
--- powerpc/vm_machdep.c	27 Sep 2003 04:44:42 -0000	1.57
+++ powerpc/vm_machdep.c	20 Nov 2003 23:22:50 -0000
@@ -116,6 +116,11 @@
 	memcpy(stktop2, stktop1, sizeof(struct trapframe));
 
 	/*
+	 * Make the PMAP easily accessible right above the trapframe.
+	 */
+	*(struct pmap **) (trapframe(l2)+1) = pcb->pcb_pm;
+
+	/*
 	 * If specified, give the child a different stack.
 	 */
 	if (stack != NULL) {

--=====================_13080058==_--