Subject: Re: UVM on sun3x
To: None <gwr@mc.com>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-sun3
Date: 11/29/1998 12:18:19
Hi,

In <199806092046.QAA11537@bach.mc.com>
gwr@mc.com wrote:

> I've just committed some changes to the sun3x code to
> allow building a UVM kernel, except for one thing:
> It needs to be switched to MACHINE_NEW_NONCONTIG
> before UVM will compile.  The patch below will enable
> that, but I want to give it some more testing before
> commiting the change.  Feel free to try it out...

I have managed to track problems with MACHINE_NEW_NONCONTIG on sun3x.
The comments in sun3x/pmap.c say that a few pages in the last
memory bank are reserved for PROM, but pmap_page_upload() which
is used on MACHINE_NEW_NONCONTIG does not take care about it.

I'm not sure my fixes are appropriate, but my kernel with UVM and
MACHINE_NEW_NONCONTIG seems to work on my 3/80 with bwtwo.
Xserver also works fine on it.
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp

--- arch/sun3/sun3x/machdep.c.orig	Sun Oct 18 17:05:25 1998
+++ arch/sun3/sun3x/machdep.c	Sun Nov 29 04:06:18 1998
@@ -125,6 +125,8 @@
 #endif
 
 int	physmem;
+int	totalphysmem;
+int	resvmem;
 int	fputype;
 caddr_t	msgbufaddr;
 
@@ -306,8 +308,9 @@
 	identifycpu();
 	initfpu();	/* also prints FPU type */
 
-	size = ptoa(physmem);
-	printf("real  mem = %dK (0x%lx)\n", (size >> 10), size);
+	size = ptoa(totalphysmem);
+	printf("real  mem = %ldK (0x%lx), %ldK reserved for PROM\n",
+	       (size >> 10), size, (ptoa(resvmem) >> 10));
 
 	/*
 	 * Find out how much space we need, allocate it,
@@ -435,7 +438,7 @@
 #else
 	size = ptoa(cnt.v_free_count);
 #endif
-	printf("avail mem = %dK (0x%lx)\n", (size >> 10), size);
+	printf("avail mem = %ldK (0x%lx)\n", (size >> 10), size);
 	printf("using %d buffers containing %d bytes of memory\n",
 		   nbuf, bufpages * CLBYTES);
 
--- arch/sun3/sun3x/pmap.c.orig	Wed Jul  8 20:10:32 1998
+++ arch/sun3/sun3x/pmap.c	Sun Nov 29 04:37:18 1998
@@ -146,6 +146,8 @@
 /* XXX - What headers declare these? */
 extern struct pcb *curpcb;
 extern int physmem;
+extern int totalphysmem;
+extern int resvmem;
 
 extern void copypage __P((const void*, void*));
 extern void zeropage __P((void*));
@@ -581,8 +583,6 @@
  ** - functions required by the Mach VM Pmap interface, with MACHINE_CONTIG
  **   defined.
  **/
-#ifdef INCLUDED_IN_PMAP_H
-void   pmap_bootstrap __P((void));
 void  *pmap_bootstrap_alloc __P((int));
 void   pmap_enter __P((pmap_t, vm_offset_t, vm_offset_t, vm_prot_t, boolean_t));
 pmap_t pmap_create __P((vm_size_t));
@@ -593,8 +593,10 @@
 void   pmap_clear_modify __P((vm_offset_t));
 vm_offset_t pmap_extract __P((pmap_t, vm_offset_t));
 int    pmap_page_index __P((vm_offset_t));
+#if !defined(MACHINE_NEW_NONCONTIG)
 u_int  pmap_free_pages __P((void));
-#endif /* INCLUDED_IN_PMAP_H */
+boolean_t   pmap_next_page __P((vm_offset_t *));
+#endif /* MACHINE_NEW_NONCONTIG */
 void pmap_pinit __P((pmap_t));
 void pmap_release __P((pmap_t));
 
@@ -677,15 +679,6 @@
 		membank = membank->next;
 	}
 
-	/*
-	 * XXX The last bank of memory should be reduced to exclude the
-	 * physical pages needed by the PROM monitor from being used
-	 * in the VM system.  XXX - See below - Fix!
-	 */
-	pmap_membank->pmem_start = membank->address;
-	pmap_membank->pmem_end = membank->address + membank->size;
-	pmap_membank->pmem_next = NULL;
-
 #if 0	/* XXX - Need to integrate this! */
 	/*
 	 * The last few pages of physical memory are "owned" by
@@ -701,7 +694,20 @@
 #endif	/* XXX */
 
 	total_phys_mem += membank->size;	/* XXX see above */
-	physmem = btoc(total_phys_mem);
+	totalphysmem = btoc(total_phys_mem);
+	physmem = btoc(*romVectorPtr->memoryAvail);
+	resvmem = btoc(total_phys_mem - *romVectorPtr->memoryAvail);
+
+	/*
+	 * XXX The last bank of memory should be reduced to exclude the
+	 * physical pages needed by the PROM monitor from being used
+	 * in the VM system.  XXX - See below - Fix!
+	 */
+	pmap_membank->pmem_start = membank->address;
+	pmap_membank->pmem_end = membank->address + membank->size -
+		(total_phys_mem - *romVectorPtr->memoryAvail);
+	pmap_membank->pmem_end = m68k_trunc_page(pmap_membank->pmem_end);
+	pmap_membank->pmem_next = NULL;
 
 	/*
 	 * Avail_end is set to the first byte of physical memory
@@ -710,9 +716,7 @@
 	 *
 	 * XXX - The setting of avail_end is a temporary ROM saving hack.
 	 */
-	avail_end = pmap_membank->pmem_end -
-		(total_phys_mem - *romVectorPtr->memoryAvail);
-	avail_end = m68k_trunc_page(avail_end);
+	avail_end = pmap_membank->pmem_end;
 
 	/*
 	 * First allocate enough kernel MMU tables to map all
@@ -3755,10 +3759,6 @@
 	vm_offset_t *pa;
 {
 	static struct pmap_physmem_struct *curbank = avail_mem;
-
-	/* XXX - temporary ROM saving hack. */
-	if (avail_next >= avail_end)
-		return FALSE;
 
 	if (avail_next >= curbank->pmem_end)
 		if (curbank->pmem_next == NULL)