Re: Current kernel with http://gnats.netbsd.org/39965 and pmap patches

Izumi Tsutsui <[email protected]>
Newsgroups gmane.os.netbsd.ports.atari
Message-ID <[email protected]>
> As a side note: it seems that some of the latest patches (probably pmap sync)
> cause FALCON kernel to freeze before kernel prints any messages with 68060
> cpu. I used BOOTX to test things and it does not have this problem.

Does it mean FALCON with pmap-sync3.diff doens't work on 68060
while FALCON with pmap-sync2.diff and BOOTX with pmap-sync3.diff work?

Anyway, here is the latest diff based on pmap-sync3.diff
againt HEAD (for MI pmap_kernel() changes):

Index: atari/atari_init.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/atari_init.c,v
retrieving revision 1.68
diff -u -r1.68 atari_init.c
--- atari/atari_init.c	15 Nov 2008 21:30:50 -0000	1.68
+++ atari/atari_init.c	28 Dec 2008 05:31:08 -0000
@@ -82,14 +82,14 @@
 static void atari_hwinit __P((void));
 static void cpu_init_kcorehdr __P((u_long));
 static void initcpu __P((void));
-static void mmu030_setup __P((st_entry_t *, u_int, pt_entry_t *, u_int,
-			      pt_entry_t *, u_int, u_int));
+static void mmu030_setup __P((u_int, pt_entry_t *, u_int,
+			      u_int, u_int));
 static void map_io_areas __P((pt_entry_t *, u_int, u_int));
 static void set_machtype __P((void));
 
 #if defined(M68040) || defined(M68060)
-static void mmu040_setup __P((st_entry_t *, u_int, pt_entry_t *, u_int,
-			      pt_entry_t *, u_int, u_int));
+static void mmu040_setup __P((u_int, pt_entry_t *, u_int,
+			      u_int, u_int));
 #endif
 
 /*
@@ -121,10 +121,8 @@
 extern u_int	Sysptsize, Sysseg_pa, proc0paddr;
 extern pt_entry_t *Sysptmap;
 extern st_entry_t *Sysseg;
-u_int		*Sysmap;
 int		machineid, mmutype, cputype, astpending;
 char		*vmmap;
-pv_entry_t	pv_table;
 #if defined(M68040) || defined(M68060)
 extern int	protostfree;
 #endif
@@ -201,6 +199,7 @@
 	u_int		end_loaded;
 	u_long		kbase;
 	u_int		kstsize;
+	u_int		Sysptmap_pa;
 
 #if defined(_MILANHW_)
 	/* XXX
@@ -237,8 +236,9 @@
 	 * the kernel ends at end() or esym.
 	 */
 	if(esym == NULL)
-		end_loaded = (u_int)end;
-	else end_loaded = (u_int)esym;
+		end_loaded = (u_int) &end;
+	else 
+		end_loaded = (u_int) esym;
 
 	/*
 	 * If we have enough fast-memory to put the kernel in and the
@@ -268,7 +268,14 @@
 	pstart = (u_int)end_loaded;
 	pstart = m68k_round_page(pstart);
 	avail  = stphysize - pstart;
-  
+
+	/*
+	 * Save KVA of proc0 user-area and allocate it
+	 */
+	proc0paddr = pstart;
+	pstart    += USPACE;
+	avail     -= USPACE;
+
 	/*
 	 * Calculate the number of pages needed for Sysseg.
 	 * For the 68030, we need 256 descriptors (segment-table-entries).
@@ -290,7 +297,15 @@
 	Sysseg_pa  = (u_int)Sysseg + kbase;
 	pstart    += kstsize * PAGE_SIZE;
 	avail     -= kstsize * PAGE_SIZE;
-  
+
+	/*
+	 * allocate kernel page table map
+	 */
+	Sysptmap = (pt_entry_t *)pstart;
+	Sysptmap_pa = pstart;
+	pstart  += PAGE_SIZE;
+	avail   -= PAGE_SIZE;
+
 	/*
 	 * Determine the number of pte's we need for extra's like
 	 * ST I/O map's.
@@ -315,44 +330,22 @@
 	ptsize  = (Sysptsize + howmany(ptextra, NPTEPG)) << PGSHIFT;
 	pstart += ptsize;
 	avail  -= ptsize;
-  
-	/*
-	 * allocate kernel page table map
-	 */
-	Sysptmap = (pt_entry_t *)pstart;
-	pstart  += PAGE_SIZE;
-	avail   -= PAGE_SIZE;
 
-	/*
-	 * Set Sysmap; mapped after page table pages. Because I too (LWP)
-	 * didn't understand the reason for this, I borrowed the following
-	 * (sligthly modified) comment from mac68k/locore.s:
-	 * LAK:  There seems to be some confusion here about the next line,
-	 * so I'll explain.  The kernel needs some way of dynamically modifying
-	 * the page tables for its own virtual memory.  What it does is that it
-	 * has a page table map.  This page table map is mapped right after the
-	 * kernel itself (in our implementation; in HP's it was after the I/O
-	 * space). Therefore, the first three (or so) entries in the segment
-	 * table point to the first three pages of the page tables (which
-	 * point to the kernel) and the next entry in the segment table points
-	 * to the page table map (this is done later).  Therefore, the value
-	 * of the pointer "Sysmap" will be something like 16M*3 = 48M.  When
-	 * the kernel addresses this pointer (e.g., Sysmap[0]), it will get
-	 * the first longword of the first page map (== pt[0]).  Since the
-	 * page map mirrors the segment table, addressing any index of Sysmap
-	 * will give you a PTE of the page maps which map the kernel.
+        /*
+	 * We want Sysmap to be the first address mapped by Sysptmap.
+	 * Sysmap is now placed at the end of Supervisor virtual address space.
 	 */
-	Sysmap = (u_int *)(ptsize << (SEGSHIFT - PGSHIFT));
+	Sysmap = (u_int *) ((u_int *)-(NPTEPG * PAGE_SIZE));
 
 	/*
 	 * Initialize segment tables
 	 */
 #if defined(M68040) || defined(M68060)
 	if (mmutype == MMU_68040)
-		mmu040_setup(Sysseg, kstsize, pt, ptsize, Sysptmap, 1, kbase);
+		mmu040_setup(kstsize, pt, ptsize, Sysptmap_pa, kbase);
 	else
 #endif /* defined(M68040) || defined(M68060) */
-		mmu030_setup(Sysseg, kstsize, pt, ptsize, Sysptmap, 1, kbase);
+		mmu030_setup(kstsize, pt, ptsize, Sysptmap_pa, kbase);
 
 	/*
 	 * initialize kernel page table page(s).
@@ -362,7 +355,8 @@
 	 */
 	pg_proto = (0 + kbase) | PG_RO | PG_V;
 	pg       = pt;
-	*pg++ = PG_NV; pg_proto += PAGE_SIZE;
+	*pg++ = PG_NV;
+	pg_proto += PAGE_SIZE;
 	for(i = PAGE_SIZE; i < (u_int)etext;
 	    i += PAGE_SIZE, pg_proto += PAGE_SIZE)
 		*pg++ = pg_proto;
@@ -389,6 +383,7 @@
 	    pg_proto = (pg_proto & ~PG_CCB) | PG_CI;
 	    for (; i < pstart; i += PAGE_SIZE, pg_proto += PAGE_SIZE)
 		*pg++ = pg_proto;
+
 	    pg_proto = (pg_proto & ~PG_CI);
 	    if (kernel_copyback)
 		pg_proto |= PG_CCB;
@@ -399,13 +394,13 @@
 	 * go till end of data allocated so far
 	 * plus proc0 u-area (to be allocated)
 	 */
-	for(; i < pstart + USPACE; i += PAGE_SIZE, pg_proto += PAGE_SIZE)
+	for (; i < pstart; i += PAGE_SIZE, pg_proto += PAGE_SIZE)
 		*pg++ = pg_proto;
 
 	/*
 	 * invalidate remainder of kernel PT
 	 */
-	while(pg < &pt[ptsize/sizeof(pt_entry_t)])
+	while((pt_entry_t *)pg < &pt[ptsize/sizeof(pt_entry_t)])
 		*pg++ = PG_NV;
 
 	/*
@@ -414,13 +409,6 @@
 	map_io_areas(pt, ptsize, ptextra);
 
 	/*
-	 * Save KVA of proc0 user-area and allocate it
-	 */
-	proc0paddr = pstart;
-	pstart    += USPACE;
-	avail     -= USPACE;
-
-	/*
 	 * At this point, virtual and physical allocation starts to divert.
 	 */
 	vstart     = pstart;
@@ -490,7 +478,7 @@
 	for (i = 0, physmem = 0; usable_segs[i].start; i++)
 		physmem += usable_segs[i].end - usable_segs[i].start;
 	physmem >>= PGSHIFT;
-  
+
 	/*
 	 * get the pmap module in sync with reality.
 	 */
@@ -552,7 +540,7 @@
 		tc = 0x82d08b00;
 		__asm volatile ("pmove %0@,%%tc" : : "a" (&tc));
 	}
- 
+
 	/* Is this to fool the optimizer?? */
 	i = *(int *)proc0paddr;
 	*(volatile int *)proc0paddr = i;
@@ -905,29 +893,25 @@
 }
 
 void
-mmu030_setup(sysseg, kstsize, pt, ptsize, sysptmap, sysptsize, kbase)
-	st_entry_t	*sysseg;	/* System segment table		*/
+mmu030_setup(kstsize, pt, ptsize, sysptmap_pa, kbase)
 	u_int		kstsize;	/* size of 'sysseg' in pages	*/
 	pt_entry_t	*pt;		/* Kernel page table		*/
 	u_int		ptsize;		/* size	of 'pt' in bytes	*/
-	pt_entry_t	*sysptmap;	/* System page table		*/
-	u_int		sysptsize;	/* size of 'sysptmap' in pages	*/
+	u_int		sysptmap_pa;	/* System page table		*/
 	u_int		kbase;
 {
 	st_entry_t	sg_proto, *sg;
 	pt_entry_t	pg_proto, *pg, *epg;
 
-	sg_proto = ((u_int)pt + kbase) | SG_RW | SG_V;
-	pg_proto = ((u_int)pt + kbase) | PG_RW | PG_CI | PG_V;
-
 	/*
 	 * Map the page table pages in both the HW segment table
-	 * and the software Sysptmap.  Note that Sysptmap is also
-	 * considered a PT page, hence the +sysptsize.
+	 * and the software Sysptmap.
 	 */
-	sg  = sysseg;
-	pg  = sysptmap; 
-	epg = &pg[(ptsize >> PGSHIFT) + sysptsize];
+	sg  = (u_int *)Sysseg_pa;
+	pg  = (u_int *)sysptmap_pa;
+	epg = &pg[ptsize >> PGSHIFT];
+	sg_proto = ((u_int)pt + kbase) | SG_RW | SG_V;
+	pg_proto = ((u_int)pt + kbase) | PG_RW | PG_CI | PG_V;
 	while(pg < epg) {
 		*sg++ = sg_proto;
 		*pg++ = pg_proto;
@@ -938,22 +922,23 @@
 	/* 
 	 * invalidate the remainder of the tables
 	 */
-	epg = &sysptmap[sysptsize * NPTEPG];
+	/* XXX PAGE_SIZE dependent constant: 256 or 1024 */
+	epg = (u_int *)(sysptmap_pa + (256 - 1) * sizeof(st_entry_t));
 	while(pg < epg) {
 		*sg++ = SG_NV;
 		*pg++ = PG_NV;
 	}
+	*sg = sysptmap_pa | SG_RW | SG_V;
+	*pg = sysptmap_pa | PG_RW | PG_CI | PG_V;
 }
 
 #if defined(M68040) || defined(M68060)
 void
-mmu040_setup(sysseg, kstsize, pt, ptsize, sysptmap, sysptsize, kbase)
-	st_entry_t	*sysseg;	/* System segment table		*/
+mmu040_setup(kstsize, pt, ptsize, sysptmap_pa, kbase)
 	u_int		kstsize;	/* size of 'sysseg' in pages	*/
 	pt_entry_t	*pt;		/* Kernel page table		*/
 	u_int		ptsize;		/* size	of 'pt' in bytes	*/
-	pt_entry_t	*sysptmap;	/* System page table		*/
-	u_int		sysptsize;	/* size of 'sysptmap' in pages	*/
+	u_int		sysptmap_pa;	/* System page table		*/
 	u_int		kbase;
 {
 	int		i;
@@ -964,22 +949,22 @@
 	 * First invalidate the entire "segment table" pages
 	 * (levels 1 and 2 have the same "invalid" values).
 	 */
-	sg  = sysseg;
+	sg  = (u_int *)Sysseg_pa;
 	esg = &sg[kstsize * NPTEPG];
 	while (sg < esg)
 		*sg++ = SG_NV;
 
 	/*
 	 * Initialize level 2 descriptors (which immediately
-	 * follow the level 1 table). These should map 'pt' + 'sysptmap'.
+	 * follow the level 1 table).
 	 * We need:
 	 *	NPTEPG / SG4_LEV3SIZE
 	 * level 2 descriptors to map each of the nptpages + 1
 	 * pages of PTEs.  Note that we set the "used" bit
 	 * now to save the HW the expense of doing it.
 	 */
-	i   = ((ptsize >> PGSHIFT) + sysptsize) * (NPTEPG / SG4_LEV3SIZE);
-	sg  = &sysseg[SG4_LEV1SIZE];
+	i   = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE);
+	sg  = &((u_int *)Sysseg_pa)[SG4_LEV1SIZE];
 	esg = &sg[i];
 	sg_proto = ((u_int)pt + kbase) | SG_U | SG_RW | SG_V;
 	while (sg < esg) {
@@ -993,8 +978,8 @@
 	 * level 1 descriptors to map the 'num' level 2's.
 	 */
 	i = roundup(i, SG4_LEV2SIZE) / SG4_LEV2SIZE;
-	protostfree = (-1 << (i + 1)) /* & ~(-1 << MAXKL2SIZE) */;
-	sg  = sysseg;
+	protostfree = (-1 << (i + 2)) /* & ~(-1 << MAXKL2SIZE) */;
+	sg  = (u_int *)Sysseg_pa;
 	esg = &sg[i];
 	sg_proto = ((u_int)&sg[SG4_LEV1SIZE] + kbase) | SG_U | SG_RW |SG_V;
 	while (sg < esg) {
@@ -1002,22 +987,44 @@
 		sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t));
 	}
 
+	/* Sysmap is last entry in level 1 */
+	sg = (u_int *)Sysseg_pa;
+	sg = &sg[SG4_LEV1SIZE - 1];
+	*sg = sg_proto;
+
 	/*
-	 * Initialize sysptmap
+	 * Kernel segment table at end of next level 2 table
+	 */
+	/* XXX fix calculations XXX */
+	i = ((((ptsize >> PGSHIFT) + 3) & -2) - 1) * (NPTEPG / SG4_LEV3SIZE);
+	sg = &((u_int *)Sysseg_pa)[SG4_LEV1SIZE + i];
+	esg = &sg[NPTEPG / SG4_LEV3SIZE];
+	sg_proto = sysptmap_pa | SG_U | SG_RW | SG_V;
+	while (sg < esg) {
+		*sg++ = sg_proto;
+		sg_proto += (SG4_LEV3SIZE * sizeof (st_entry_t));
+	}
+
+	/*
+	 * Initialize Sysptmap
 	 */
-	sg  = sysptmap;
-	esg = &sg[(ptsize >> PGSHIFT) + sysptsize];
+	sg = (u_int *) sysptmap_pa;
+	esg = &sg[ptsize >> PGSHIFT];
 	pg_proto = ((u_int)pt + kbase) | PG_RW | PG_CI | PG_V;
 	while (sg < esg) {
-		*sg++     = pg_proto;
+		*sg++ = pg_proto;
 		pg_proto += PAGE_SIZE;
 	}
+
 	/*
 	 * Invalidate rest of Sysptmap page
 	 */
-	esg = &sysptmap[sysptsize * NPTEPG];
+	esg = (u_int *)(sysptmap_pa + PAGE_SIZE - sizeof(st_entry_t));
 	while (sg < esg)
 		*sg++ = SG_NV;
+	sg = (u_int *) Sysptmap;
+	sg = &sg[256 - 1];              /* XXX */
+	*sg = sysptmap_pa | PG_RW | PG_CI | PG_V;
 }
 #endif /* M68040 */
 
@@ -1121,7 +1128,7 @@
 
 	s = stp;
 	{
-		es = s + (ATARI_STSIZE >> 2);
+		es = s + (M68K_STSIZE >> 2);
 		shift = SG_ISHIFT;
 	}
 
Index: atari/genassym.cf
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/genassym.cf,v
retrieving revision 1.27
diff -u -r1.27 genassym.cf
--- atari/genassym.cf	30 Apr 2008 13:10:59 -0000	1.27
+++ atari/genassym.cf	28 Dec 2008 05:31:08 -0000
@@ -166,7 +166,6 @@
 define	PCB_PS			offsetof(struct pcb, pcb_ps)
 define	PCB_USP			offsetof(struct pcb, pcb_usp)
 define	PCB_REGS		offsetof(struct pcb, pcb_regs)
-define	PCB_CMAP2		offsetof(struct pcb, pcb_cmap2)
 define	PCB_ONFAULT		offsetof(struct pcb, pcb_onfault)
 define	PCB_FPCTX		offsetof(struct pcb, pcb_fpregs)
 define	SIZEOF_PCB		sizeof(struct pcb)
Index: atari/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/pmap.c,v
retrieving revision 1.109
diff -u -r1.109 pmap.c
--- atari/pmap.c	19 Dec 2008 18:49:38 -0000	1.109
+++ atari/pmap.c	28 Dec 2008 05:31:08 -0000
@@ -110,13 +110,12 @@
 
 #include <uvm/uvm.h>
 
-#include <m68k/cpu.h>
-#include <m68k/cacheops.h>
-
 #include <machine/pte.h>
 #include <machine/cpu.h>
 #include <machine/vmparam.h>
 
+#include <m68k/cacheops.h>
+
 /*
  * Allocate various and sundry SYSMAPs used in the days of old VM
  * and not yet converted.  XXX.
@@ -177,8 +176,8 @@
 
 #define	PMAP_DPRINTF(l, x)	if (pmapdebug & (l)) printf x
 
-static void	pmap_check_wiring __P((const char *, vaddr_t));
-static void	pmap_pvdump __P((paddr_t));
+static void	pmap_check_wiring(const char *, vaddr_t);
+static void	pmap_pvdump(paddr_t);
 #else
 #define	PMAP_DPRINTF(l, x)
 #endif
@@ -187,22 +186,26 @@
  * Get STEs and PTEs for user/kernel address space
  */
 #if defined(M68040) || defined(M68060)
-
-#define	pmap_ste(m, v)	(&((m)->pm_stab[(vaddr_t)(v) >> pmap_ishift]))
+#if defined(M68020) || defined(M68030)
+#define	pmap_ste(m, v)	(&((m)->pm_stab[(vaddr_t)(v) \
+	>> (mmutype == MMU_68040 ? SG4_SHIFT1 : SG_ISHIFT)]))
+#else
+#define	pmap_ste(m, v)	(&((m)->pm_stab[(vaddr_t)(v) >> SG4_SHIFT1]))
+#endif
 #define	pmap_ste1(m, v) (&((m)->pm_stab[(vaddr_t)(v) >> SG4_SHIFT1]))
 /* XXX assumes physically contiguous ST pages (if more than one) */
 #define	pmap_ste2(m, v) \
-	(&((m)->pm_stab[(u_int *)(*(u_int *)pmap_ste1(m,v) & SG4_ADDR1) \
+	(&((m)->pm_stab[(st_entry_t *)(*(u_int *)pmap_ste1(m,v) & SG4_ADDR1) \
 			- (m)->pm_stpa + (((v) & SG4_MASK2) >> SG4_SHIFT2)]))
 #define	pmap_ste_v(m, v) \
-	(mmutype == MMU_68040 		\
-	? ((*pmap_ste1(m, v) & SG_V) && \
+	(mmutype == MMU_68040		\
+	? ((*pmap_ste1(m, v) & SG_V) &&	\
 	   (*pmap_ste2(m, v) & SG_V))	\
 	: (*pmap_ste(m, v) & SG_V))
-#else  /* defined(M68040) || defined(M68060) */
-#define	pmap_ste(m, v)		(&((m)->pm_stab[(vaddr_t)(v) >> SG_ISHIFT]))
+#else	/* defined(M68040) || defined(M68060) */
+#define	pmap_ste(m, v)	(&((m)->pm_stab[(vaddr_t)(v) >> SG_ISHIFT]))
 #define pmap_ste_v(m, v)	(*pmap_ste(m, v) & SG_V)
-#endif /* defined(M68040) || defined(M68060) */
+#endif	/* defined(M68040) || defined(M68060) */
 
 #define pmap_pte(m, v)	(&((m)->pm_ptab[(vaddr_t)(v) >> PG_SHIFT]))
 
@@ -265,17 +268,18 @@
  * reference something.
  */
 u_int		*Sysseg, *Sysseg_pa;
-u_int		*Sysmap, *Sysptmap;
-u_int		*Segtabzero, *Segtabzeropa;
+pt_entry_t	*Sysmap, *Sysptmap;
+st_entry_t	*Segtabzero, *Segtabzeropa;
 vsize_t		Sysptsize = VM_KERNEL_PT_PAGES;
 
-static struct pmap	kernel_pmap_store;
-struct pmap		*const kernel_pmap_ptr = &kernel_pmap_store;
+struct pv_entry	*pv_table;	/* memory size in bytes */
+
+static struct pmap kernel_pmap_store;
+struct pmap	*const kernel_pmap_ptr = &kernel_pmap_store;
 struct vm_map	*pt_map;
 struct vm_map_kernel pt_map_store;
 
 vsize_t		mem_size;	/* memory size in bytes */
-paddr_t		avail_end;	/* PA of last available physical page */
 vaddr_t		virtual_avail;  /* VA of first avail page (after kernel bss)*/
 vaddr_t		virtual_end;	/* VA of last avail page (end of kernel AS) */
 int		page_cnt;	/* number of pages managed by the VM system */
@@ -284,38 +288,42 @@
 TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
 int		pv_nfree;
 #if defined(M68040) || defined(M68060)
-static int	pmap_ishift;	/* segment table index shift */
 int		protostfree;	/* prototype (default) free ST map */
 #endif
 
-extern	void *	msgbufaddr;
-extern	vaddr_t	msgbufpa;
+pt_entry_t	*caddr1_pte;	/* PTE for CADDR1 */
+pt_entry_t	*caddr2_pte;	/* PTE for CADDR2 */
+
+extern void *	msgbufaddr;
+extern paddr_t	msgbufpa;
+
+extern vaddr_t reserve_dumppages(vaddr_t);
 
-static bool		pmap_testbit __P((paddr_t, int));
-static int		pmap_enter_ptpage __P((pmap_t, vaddr_t, bool));
-static struct pv_entry* pmap_alloc_pv __P((void));
-static void		pmap_free_pv __P((struct pv_entry *));
-static void		pmap_pinit __P((pmap_t));
-static void		pmap_ptpage_addref __P((vaddr_t));
-static int		pmap_ptpage_delref __P((vaddr_t));
-static void		pmap_release __P((pmap_t));
-static void		pmap_remove_mapping __P((pmap_t, vaddr_t, pt_entry_t *,
-							int));
-static void		atari_protection_init __P((void));
-static void		pmap_collect1 __P((pmap_t, paddr_t, paddr_t));  
+bool		pmap_testbit(paddr_t, int);
+int		pmap_enter_ptpage(pmap_t, vaddr_t, bool);
+static void	pmap_ptpage_addref(vaddr_t);
+static int	pmap_ptpage_delref(vaddr_t);
+static void	pmap_changebit(vaddr_t, int, bool);
+struct pv_entry * pmap_alloc_pv(void);
+void		pmap_free_pv(struct pv_entry *);
+void		pmap_pinit(pmap_t);
+void		pmap_release(pmap_t);
+static void	pmap_remove_mapping(pmap_t, vaddr_t, pt_entry_t *, int);
+
+void		pmap_collect1(pmap_t, paddr_t, paddr_t);
 
 /* pmap_remove_mapping flags */
-#define	PRM_TFLUSH	0x01
-#define	PRM_CFLUSH	0x02
-#define	PRM_KEEPPTPAGE	0x04
+#define		PRM_TFLUSH	0x01
+#define		PRM_CFLUSH	0x02
+#define		PRM_KEEPPTPAGE	0x04
 
 /*
  * All those kernel PT submaps that BSD is so fond of
  */
-void *CADDR1, *CADDR2;
-u_int	*CMAP1, *CMAP2, *vmpte, *msgbufmap;
+void 	*CADDR1, *CADDR2;
+char	*vmmap;
 
-#define	PAGE_IS_MANAGED(pa)	(pmap_initialized 			\
+#define	PAGE_IS_MANAGED(pa)	(pmap_initialized			\
 				 && vm_physseg_find(atop((pa)), NULL) != -1)
 
 static inline struct pv_entry *pa_to_pvh(paddr_t pa);
@@ -324,7 +332,7 @@
 static inline struct pv_entry *
 pa_to_pvh(paddr_t pa)
 {
-	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
+	int bank, pg = 0;	/* gcc4 -Wunitialized */
 
 	bank = vm_physseg_find(atop((pa)), &pg);
 	return &vm_physmem[bank].pmseg.pvent[pg];
@@ -333,124 +341,18 @@
 static inline char *
 pa_to_attribute(paddr_t pa)
 {
-	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
+	int bank, pg = 0;	/* gcc4 -Wuninitialized */
 
 	bank = vm_physseg_find(atop((pa)), &pg);
 	return &vm_physmem[bank].pmseg.attrs[pg];
 }
 
 /*
- * The preallocated virtual memory range used by the I/O area. Their
- * values are passed to pmap_bootstrap().
- */
-static u_int	atarihwaddr;
-
-/*
- *	Bootstrap the system enough to run with virtual memory.
- *	Map the kernel's code and data, and allocate the system page table.
- *
- *	On the HP this is called after mapping has already been enabled
- *	and just syncs the pmap module with what has already been done.
- *	[We can't call it easily with mapping off since the kernel is not
- *	mapped with PA == VA, hence we would have to relocate every address
- *	from the linked base (virtual) address 0 to the actual (physical)
- *	address of 0xFFxxxxxx.]
+ *	Initialize the pmap module.
+ *	Called by vm_init, to initialize any structures that the pmap
+ *	system needs to map virtual memory.
  */
 void
-pmap_bootstrap(kernel_size, hw_addr)
-psize_t	kernel_size;
-u_int	hw_addr;
-{
-	vaddr_t	va;
-	u_int	*pte;
-	int	i;
-
-	/*
-	 * Record start & size of I/O area for use by pmap_init()
-	 */
-
-	atarihwaddr = hw_addr;
-
-	/*
-	 * Announce page-size to the VM-system
-	 */
-	uvmexp.pagesize = NBPG;
-	uvm_setpagesize();
-
-	/*
-	 * Setup physical address ranges
-	 */
-	for (i = 0; usable_segs[i+1].start; i++)
-		;
-	/* XXX: allow for msgbuf */
-	usable_segs[i].end -= m68k_round_page(MSGBUFSIZE);
-	avail_end = msgbufpa = usable_segs[i].end;
-
-	/*
-	 * Count physical memory
-	 */
-	for (i = mem_size = 0; i < NMEM_SEGS; i++) {
-		if (boot_segs[i].start == boot_segs[i].end)
-			break;
-		mem_size += boot_segs[i].end - boot_segs[i].start;
-	}
-
-	/*
-	 * Announce available memory to the VM-system
-	 */
-	for (i = 0; usable_segs[i].start; i++)
-		uvm_page_physload(atop(usable_segs[i].start),
-				 atop(usable_segs[i].end),
-				 atop(usable_segs[i].start),
-				 atop(usable_segs[i].end),
-				 VM_FREELIST_DEFAULT);
-
-	virtual_avail = VM_MIN_KERNEL_ADDRESS + kernel_size;
-	virtual_end   = VM_MAX_KERNEL_ADDRESS;
-
-	/*
-	 * Initialize protection array.
-	 */
-	atari_protection_init();
-
-	/*
-	 * Kernel page/segment table allocated in locore,
-	 * just initialize pointers.
-	 */
-	pmap_kernel()->pm_stpa = Sysseg_pa;
-	pmap_kernel()->pm_stab = Sysseg;
-	pmap_kernel()->pm_ptab = Sysmap;
-#if defined(M68040) || defined(M68060)
-	if (mmutype == MMU_68040) {
-		pmap_ishift = SG4_SHIFT1;
-		pmap_kernel()->pm_stfree = protostfree;
-	}
-	else pmap_ishift = SG_ISHIFT;
-#endif
-
-	simple_lock_init(&pmap_kernel()->pm_lock);
-	pmap_kernel()->pm_count = 1;
-
-	/*
-	 * Allocate all the submaps we need
-	 */
-#define	SYSMAP(c, p, v, n)	\
-	v = (c)va; va += ((n)*PAGE_SIZE); p = pte; pte += (n);
-
-	va = virtual_avail;
-	pte = pmap_pte(pmap_kernel(), va);
-
-	SYSMAP(void *	,CMAP1	   ,CADDR1	,1		    )
-	SYSMAP(void *	,CMAP2	   ,CADDR2	,1		    )
-	SYSMAP(void *	,vmpte	   ,vmmap	,1		    )
-	SYSMAP(void *	,msgbufmap ,msgbufaddr	,btoc(MSGBUFSIZE)   )
-
-	DCIS();
-
-	virtual_avail = reserve_dumppages(va);
-}
-
-void
 pmap_init()
 {
 	vaddr_t		addr, addr2;
@@ -458,16 +360,28 @@
 	u_int		npg;
 	struct pv_entry *pv;
 	char            *attr;
-	int		rv, bank;
-#ifdef M68060
-	struct kpt_page	*kptp;
+	int             rv, bank;
+#if defined(M68060)
+	struct kpt_page *kptp;
+	paddr_t		paddr;
 #endif
 
 #ifdef DEBUG
-	if (pmapdebug & PDB_FOLLOW) {
+	if (pmapdebug & PDB_FOLLOW)
 		printf("pmap_init()\n");
+#endif
+
+	/*
+	 * Before we do anything else, initialize the PTE pointers
+	 * used by pmap_zero_page() and pmap_copy_page().
+	 */
+	caddr1_pte = pmap_pte(pmap_kernel(), CADDR1);
+	caddr2_pte = pmap_pte(pmap_kernel(), CADDR2);
+
+#ifdef DEBUG
+	if (pmapdebug & PDB_INIT) {
 		printf("pmap_init: Sysseg %p, Sysmap %p, Sysptmap %p\n",
-		       Sysseg, Sysmap, Sysptmap);
+		    Sysseg, Sysmap, Sysptmap);
 		printf(" vstart %lx, vend %lx\n", virtual_avail, virtual_end);
 	}
 #endif
@@ -484,18 +398,19 @@
 		    vm_physmem[bank].end << PGSHIFT, page_cnt << PGSHIFT);
 #endif
 	}
-	s = ATARI_STSIZE;				/* Segtabzero	   */
-	s += page_cnt * sizeof(struct pv_entry);	/* pv table	   */
+	s = M68K_STSIZE;				/* Segtabzero */
+	s += page_cnt * sizeof(struct pv_entry);	/* pv table */
 	s += page_cnt * sizeof(char);			/* attribute table */
 	s = round_page(s);
 
 	addr = uvm_km_alloc(kernel_map, s, 0, UVM_KMF_WIRED | UVM_KMF_ZERO);
 	if (addr == 0)
 		panic("pmap_init: can't allocate data structures");
-	Segtabzero   = (u_int *) addr;
+	Segtabzero = (u_int *) addr;
 	(void) pmap_extract(pmap_kernel(), addr, (paddr_t *)(void *)&Segtabzeropa);
-	addr += ATARI_STSIZE;
-	pv_table = (pv_entry_t) addr;
+	addr += M68K_STSIZE;
+
+	pv_table = (struct pv_entry *) addr;
 	addr += page_cnt * sizeof(struct pv_entry);
 
 	pmap_attributes = (char *) addr;
@@ -523,16 +438,16 @@
 
 	/*
 	 * Allocate physical memory for kernel PT pages and their management.
-	 * we need enough pages to map the page tables for each process 
+	 * we need enough pages to map the page tables for each process
 	 * plus some slop.
 	 */
-	npg = howmany(((maxproc + 16) * ATARI_UPTSIZE / NPTEPG), PAGE_SIZE);
+	npg = howmany(((maxproc + 16) * M68K_MAX_PTSIZE / NPTEPG), PAGE_SIZE);
 #ifdef NKPTADD
 	npg += NKPTADD;
 #else
 	npg += mem_size >> NKPTADDSHIFT;
 #endif
-#ifdef DEBUG
+#if 1/*def DEBUG*/
 	printf("Maxproc %d, mem_size %ld MB: allocating %d KPT pages\n",
 	    maxproc, mem_size>>20, npg);
 #endif
@@ -568,40 +483,35 @@
 		kpt_pages->kpt_va = addr2;
 		(void) pmap_extract(pmap_kernel(), addr2,
 		    (paddr_t *)&kpt_pages->kpt_pa);
-
 	} while (addr != addr2);
+
 #ifdef DEBUG
 	kpt_stats.kpttotal = atop(s);
 	if (pmapdebug & PDB_INIT)
 		printf("pmap_init: KPT: %ld pages from %lx to %lx\n",
-		       atop(s), addr, addr + s);
+		    atop(s), addr, addr + s);
 #endif
 
 	/*
-	 * Slightly modified version of kmem_suballoc() to get page table
-	 * map where we want it.
+	 * Allocate the segment table map and the page table map.
 	 */
-	addr = ATARI_UPTBASE;
-	if (ATARI_UPTMAXSIZE / ATARI_UPTSIZE < maxproc) {
-		s = ATARI_UPTMAXSIZE;
+	addr = M68K_PTBASE;
+	if (M68K_PTMAXSIZE / M68K_MAX_PTSIZE < maxproc) {
+		s = M68K_PTMAXSIZE;
 
 		/*
 		 * XXX We don't want to hang when we run out of page
 		 * tables, so we lower maxproc so that fork will fail
-		 * instead. Note that root could still raise this
+		 * instead.  Note that root could still raise this
 		 * value through sysctl(3).
 		 */
-		maxproc = ATARI_UPTMAXSIZE / ATARI_UPTSIZE;
-	}
-	else s = maxproc * ATARI_UPTSIZE;
+		maxproc = M68K_PTMAXSIZE / M68K_MAX_PTSIZE;
+	} else
+		s = maxproc * M68K_MAX_PTSIZE;
 
 	pt_map = uvm_km_suballoc(kernel_map, &addr, &addr2, s, 0,
 	    true, &pt_map_store);
 
-#ifdef DEBUG
-	if (pmapdebug & PDB_INIT)
-		printf("pmap_init: pt_map [%lx - %lx)\n", addr, addr2);
-#endif
 #if defined(M68040) || defined(M68060)
 	if (mmutype == MMU_68040)
 		protostfree = ~1 & ~(-1 << MAXUL2SIZE);
@@ -628,11 +538,11 @@
 			kptp = kptp->kpt_next;
 		}
 
-		addr2 = (vaddr_t)Segtabzeropa;
-		while (addr2 < (vaddr_t)Segtabzeropa + ATARI_STSIZE) {
-			pmap_changebit(addr2, PG_CCB, 0);
-			pmap_changebit(addr2, PG_CI, 1);
-			addr2 += PAGE_SIZE;
+		paddr = (paddr_t)Segtabzeropa;
+		while (paddr < (paddr_t)Segtabzeropa + M68K_STSIZE) {
+			pmap_changebit(paddr, PG_CCB, 0);
+			pmap_changebit(paddr, PG_CI, 1);
+			paddr += PAGE_SIZE;
 		}
 
 		DCIS();
@@ -679,7 +589,7 @@
 pmap_free_pv(pv)
 	struct pv_entry *pv;
 {
-	register struct pv_page *pvp;
+	struct pv_page *pvp;
 
 	pvp = (struct pv_page *) trunc_page((vaddr_t)pv);
 	switch (++pvp->pvp_pgi.pgi_nfree) {
@@ -698,6 +608,7 @@
 	}
 }
 
+
 /*
  *	Used to map a range of physical addresses into kernel
  *	virtual address space.
@@ -710,7 +621,7 @@
 	vaddr_t	virt;
 	paddr_t	start;
 	paddr_t	end;
-	int	prot;
+	int		prot;
 {
 #ifdef DEBUG
 	if (pmapdebug & PDB_FOLLOW)
@@ -740,7 +651,7 @@
 pmap_t
 pmap_create()
 {
-	register pmap_t pmap;
+	pmap_t pmap;
 
 #ifdef DEBUG
 	if (pmapdebug & (PDB_FOLLOW|PDB_CREATE))
@@ -756,9 +667,9 @@
  * Initialize a preallocated and zeroed pmap structure,
  * such as one in a vmspace structure.
  */
-static void
+void
 pmap_pinit(pmap)
-	register pmap_t	pmap;
+	pmap_t pmap;
 {
 
 #ifdef DEBUG
@@ -778,7 +689,6 @@
 		pmap->pm_stfree = protostfree;
 #endif
 	pmap->pm_count = 1;
-	simple_lock_init(&pmap->pm_lock);
 }
 
 /*
@@ -788,7 +698,7 @@
  */
 void
 pmap_destroy(pmap)
-	register pmap_t pmap;
+	pmap_t pmap;
 {
 	int count;
 
@@ -796,9 +706,7 @@
 	if (pmapdebug & PDB_FOLLOW)
 		printf("pmap_destroy(%p)\n", pmap);
 #endif
-	simple_lock(&pmap->pm_lock);
 	count = --pmap->pm_count;
-	simple_unlock(&pmap->pm_lock);
 	if (count == 0) {
 		pmap_release(pmap);
 		free((void *)pmap, M_VMPMAP);
@@ -810,9 +718,9 @@
  * Called when a pmap initialized by pmap_pinit is being released.
  * Should only be called if the map contains no valid mappings.
  */
-static void
+void
 pmap_release(pmap)
-	register pmap_t pmap;
+	pmap_t pmap;
 {
 
 #ifdef DEBUG
@@ -821,17 +729,16 @@
 #endif
 #ifdef notdef /* DIAGNOSTIC */
 	/* count would be 0 from pmap_destroy... */
-	simple_lock(&pmap->pm_lock);
 	if (pmap->pm_count != 1)
 		panic("pmap_release count");
 #endif
 	if (pmap->pm_ptab) {
 		pmap_remove(pmap_kernel(), (vaddr_t)pmap->pm_ptab,
-		    (vaddr_t)pmap->pm_ptab + ATARI_UPTSIZE);
+		    (vaddr_t)pmap->pm_ptab + M68K_MAX_PTSIZE);
 		uvm_km_pgremove((vaddr_t)pmap->pm_ptab,
-		    (vaddr_t)pmap->pm_ptab + ATARI_UPTSIZE);
+		    (vaddr_t)pmap->pm_ptab + M68K_MAX_PTSIZE);
 		uvm_km_free(pt_map, (vaddr_t)pmap->pm_ptab,
-				   ATARI_UPTSIZE, UVM_KMF_VAONLY);
+		    M68K_MAX_PTSIZE, UVM_KMF_VAONLY);
 	}
 	KASSERT(pmap->pm_stab == Segtabzero);
 }
@@ -848,9 +755,7 @@
 		printf("pmap_reference(%p)\n", pmap);
 #endif
 	if (pmap != NULL) {
-		simple_lock(&pmap->pm_lock);
 		pmap->pm_count++;
-		simple_unlock(&pmap->pm_lock);
 	}
 }
 
@@ -862,12 +767,12 @@
  */
 void
 pmap_remove(pmap, sva, eva)
-	register pmap_t pmap;
+	pmap_t pmap;
 	vaddr_t sva, eva;
 {
-	register paddr_t pa;
-	register vaddr_t va;
-	register u_int *pte;
+	paddr_t pa;
+	vaddr_t va;
+	u_int *pte;
 	int flags;
 
 #ifdef DEBUG
@@ -877,22 +782,22 @@
 #endif
 	flags = active_pmap(pmap) ? PRM_TFLUSH : 0;
 	for (va = sva; va < eva; va += PAGE_SIZE) {
-	    /*
-	     * Weed out invalid mappings.
-	     * Note: we assume that the segment table is always allocated.
-	     */
-	    if (!pmap_ste_v(pmap, va)) {
-		/* XXX: avoid address wrap around */
-		if (va >= m68k_trunc_seg((vaddr_t)-1))
-			break;
-		va = m68k_round_seg(va + PAGE_SIZE) - PAGE_SIZE;
-		continue;
-	    }
-	    pte = pmap_pte(pmap, va);
-	    pa = pmap_pte_pa(pte);
-	    if (pa == 0)
-		continue;
-	    pmap_remove_mapping(pmap, va, pte, flags);
+		/*
+		 * Weed out invalid mappings.
+		 * Note: we assume that the segment table is always allocated.
+		 */
+		if (!pmap_ste_v(pmap, va)) {
+			/* XXX: avoid address wrap around */
+			if (va >= m68k_trunc_seg((vaddr_t)-1))
+				break;
+			va = m68k_round_seg(va + PAGE_SIZE) - PAGE_SIZE;
+			continue;
+		}
+		pte = pmap_pte(pmap, va);
+		pa = pmap_pte_pa(pte);
+		if (pa == 0)
+			continue;
+		pmap_remove_mapping(pmap, va, pte, flags);
 	}
 }
 
@@ -906,9 +811,9 @@
 	struct vm_page *pg;
 	vm_prot_t	prot;
 {
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
-	register pv_entry_t pv;
+	struct pv_entry *pv;
 	int s;
+	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
 
 #ifdef DEBUG
 	if ((pmapdebug & (PDB_FOLLOW|PDB_PROTECT)) ||
@@ -928,22 +833,22 @@
 		pv = pa_to_pvh(pa);
 		s = splvm();
 		while (pv->pv_pmap != NULL) {
-		    pt_entry_t	*pte;
+			pt_entry_t  *pte;
 
-		    pte = pmap_pte(pv->pv_pmap, pv->pv_va);
+			pte = pmap_pte(pv->pv_pmap, pv->pv_va);
 #ifdef DEBUG
-		    if (!pmap_ste_v(pv->pv_pmap,pv->pv_va) ||
+			if (!pmap_ste_v(pv->pv_pmap,pv->pv_va) ||
 			    pmap_pte_pa(pte) != pa)
 {
-  printf ("pmap_page_protect: va %08lx, pmap_ste_v %d pmap_pte_pa %08x/%08lx\n",
-    pv->pv_va, pmap_ste_v(pv->pv_pmap,pv->pv_va),
-    pmap_pte_pa(pmap_pte(pv->pv_pmap,pv->pv_va)),pa);
-  printf (" pvh %p pv %p pv_next %p\n", pa_to_pvh(pa), pv, pv->pv_next);
+    printf ("pmap_page_protect: va %lx, pmap_ste_v %d pmap_pte_pa %08x/%lx\n",
+	pv->pv_va, pmap_ste_v(pv->pv_pmap,pv->pv_va),
+	pmap_pte_pa(pmap_pte(pv->pv_pmap,pv->pv_va)),pa);
+    printf (" pvh %p pv %p pv_next %p\n", pa_to_pvh(pa), pv, pv->pv_next);
 			panic("pmap_page_protect: bad mapping");
 }
 #endif
-		    pmap_remove_mapping(pv->pv_pmap, pv->pv_va,
-			pte, PRM_TFLUSH|PRM_CFLUSH);
+			pmap_remove_mapping(pv->pv_pmap, pv->pv_va,
+			    pte, PRM_TFLUSH|PRM_CFLUSH);
 		}
 		splx(s);
 		break;
@@ -956,12 +861,12 @@
  */
 void
 pmap_protect(pmap, sva, eva, prot)
-	register pmap_t	pmap;
-	vaddr_t		sva, eva;
-	vm_prot_t	prot;
+	pmap_t pmap;
+	vaddr_t	sva, eva;
+	vm_prot_t prot;
 {
-	register u_int *pte;
-	register vaddr_t va;
+	u_int *pte;
+	vaddr_t va;
 	bool needtflush;
 	int isro;
 
@@ -1033,14 +938,14 @@
 
 int
 pmap_enter(pmap, va, pa, prot, flags)
-	register pmap_t pmap;
+	pmap_t pmap;
 	vaddr_t va;
-	register paddr_t pa;
+	paddr_t pa;
 	vm_prot_t prot;
 	int flags;
 {
-	register u_int *pte;
-	register int npte;
+	u_int *pte;
+	int npte;
 	paddr_t opa;
 	bool cacheable = true;
 	bool checkpv = true;
@@ -1050,7 +955,7 @@
 #ifdef DEBUG
 	if (pmapdebug & (PDB_FOLLOW|PDB_ENTER))
 		printf("pmap_enter(%p, %lx, %lx, %x, %x)\n",
-		       pmap, va, pa, prot, wired);
+		    pmap, va, pa, prot, wired);
 	if (pmap == pmap_kernel())
 		enter_stats.kernel++;
 	else
@@ -1060,8 +965,8 @@
 	 * For user mapping, allocate kernel VM resources if necessary.
 	 */
 	if (pmap->pm_ptab == NULL)
-		pmap->pm_ptab = (u_int *)
-		    uvm_km_alloc(pt_map, ATARI_UPTSIZE, 0,
+		pmap->pm_ptab = (pt_entry_t *)
+		    uvm_km_alloc(pt_map, M68K_MAX_PTSIZE, 0,
 		    UVM_KMF_VAONLY | 
 		    (can_fail ? UVM_KMF_NOWAIT : UVM_KMF_WAITVA));
 		if (pmap->pm_ptab == NULL)
@@ -1148,7 +1053,7 @@
 	 * since pmap_enter can be called at interrupt time.
 	 */
 	if (PAGE_IS_MANAGED(pa)) {
-		register pv_entry_t pv, npv;
+		struct pv_entry *pv, *npv;
 		int s;
 
 #ifdef DEBUG
@@ -1225,23 +1130,23 @@
 	 */
 #if defined(M68040) || defined(M68060)
 #if DEBUG
-	if (pmapdebug & 0x10000 && mmutype == MMU_68040 && 
+	if (pmapdebug & 0x10000 && mmutype == MMU_68040 &&
 	    pmap == pmap_kernel()) {
-		struct proc *cp = curproc;
 		const char *s;
-		if (va >= ATARI_UPTBASE && 
-		    va < (ATARI_UPTBASE + ATARI_UPTMAXSIZE))
+		struct proc *cp = curproc;
+		if (va >= M68K_PTBASE &&
+		    va < (M68K_PTBASE + (u_int)M68K_PTMAXSIZE))
 			s = "UPT";
-		else if (va >= (u_int)Sysmap && 
-		    va < ((u_int)Sysmap + ATARI_KPTSIZE))
+		else if (va >= (u_int)Sysmap &&
+		    va < ((u_int)Sysmap + M68K_MAX_KPTSIZE))
 			s = "KPT";
-		else if (va >= (u_int)pmap->pm_stab && 
-		    va < ((u_int)pmap->pm_stab + ATARI_STSIZE))
+		else if (va >= (u_int)pmap->pm_stab &&
+		    va < ((u_int)pmap->pm_stab + M68K_STSIZE))
 			s = "KST";
-		else if (cp && 
+		else if (cp &&
 		    va >= (u_int)cp->p_vmspace->vm_map.pmap->pm_stab &&
 		    va < ((u_int)cp->p_vmspace->vm_map.pmap->pm_stab +
-		    ATARI_STSIZE))
+		    M68K_STSIZE))
 			s = "UST";
 		else
 			s = "other";
@@ -1251,8 +1156,8 @@
 	}
 #endif
 	if (mmutype == MMU_68040 && pmap == pmap_kernel() && (
-	    (va >= ATARI_UPTBASE && va < (ATARI_UPTBASE + ATARI_UPTMAXSIZE)) ||
-	    (va >= (u_int)Sysmap && va < ((u_int)Sysmap + ATARI_KPTSIZE))))
+	    (va >= M68K_PTBASE && va < (M68K_PTBASE + (u_int)M68K_PTMAXSIZE)) ||
+	    (va >= (u_int)Sysmap && va < ((u_int)Sysmap + M68K_MAX_KPTSIZE))))
 		cacheable = false;	/* don't cache user page tables */
 #endif
 	npte = (pa & PG_FRAME) | pte_prot(pmap, prot) | PG_V;
@@ -1260,10 +1165,18 @@
 	if (wired)
 		npte |= PG_W;
 	if (!checkpv && !cacheable)
+#if defined(M68060) && defined(NO_SLOW_CIRRUS)
+#if defined(M68040) || defined(M68030) || defined(M68020)
 		npte |= (cputype == CPU_68060 ? PG_CIN : PG_CI);
+#else
+		npte |= PG_CIN;
+#endif
+#else
+		npte |= PG_CI;
+#endif
 #if defined(M68040) || defined(M68060)
 	else if (mmutype == MMU_68040 && (npte & PG_PROT) == PG_RW &&
-	         (kernel_copyback || pmap != pmap_kernel()))
+	    (kernel_copyback || pmap != pmap_kernel()))
 		npte |= PG_CCB;		/* cache copyback */
 #endif
 	if (flags & VM_PROT_ALL) {
@@ -1293,11 +1206,9 @@
 #ifdef DEBUG
 	if ((pmapdebug & PDB_WIRING) && pmap != pmap_kernel()) {
 		va -= PAGE_SIZE;
-		pmap_check_wiring("enter",
-		    trunc_page((vaddr_t)pmap_pte(pmap, va)));
+		pmap_check_wiring("enter", trunc_page((vaddr_t) pmap_pte(pmap, va)));
 	}
 #endif
-
 	return 0;
 }
 
@@ -1318,7 +1229,7 @@
 	 * Segment table entry not valid, we need a new PT page
 	 */
 
-	if (!pmap_ste_v(pmap, va)) { 
+	if (!pmap_ste_v(pmap, va)) {
 		s = splvm();
 		pmap_enter_ptpage(pmap, va, false);
 		splx(s);
@@ -1438,10 +1349,10 @@
  */
 void
 pmap_unwire(pmap, va)
-	register pmap_t	pmap;
+	pmap_t	pmap;
 	vaddr_t	va;
 {
-	register u_int *pte;
+	u_int *pte;
 
 	pte = pmap_pte(pmap, va);
 #ifdef DEBUG
@@ -1492,16 +1403,15 @@
 
 bool
 pmap_extract(pmap, va, pap)
-	register pmap_t	pmap;
+	pmap_t	pmap;
 	vaddr_t va;
 	paddr_t *pap;
 {
 	bool rv = false;
-	paddr_t pa;
+	paddr_t pa = 0;
 	u_int pte;
 
 #ifdef DEBUG
-	pa = 0;	/* XXX gcc -Wuninitialized */
 	if (pmapdebug & PDB_FOLLOW)
 		printf("pmap_extract(%p, %lx) -> ", pmap, va);
 #endif
@@ -1591,22 +1501,22 @@
  *		Helper function for pmap_collect().  Do the actual
  *		garbage-collection of range of physical addresses.
  */
-static void
+void
 pmap_collect1(pmap, startpa, endpa)
-    pmap_t		pmap;
-    paddr_t		startpa, endpa;
+    pmap_t	pmap;
+    paddr_t	startpa, endpa;
 {
 	paddr_t pa;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	paddr_t kpa;
 #ifdef DEBUG
-	int *ste;
+	st_entry_t *ste;
 	int opmapdebug = 0;
 #endif
 
 	for (pa = startpa; pa < endpa; pa += PAGE_SIZE) {
-		register struct kpt_page *kpt, **pkpt;
+		struct kpt_page *kpt, **pkpt;
 
 		/*
 		 * Locate physical pages which are being used as kernel
@@ -1623,7 +1533,7 @@
 			continue;
 #ifdef DEBUG
 		if (pv->pv_va < (vaddr_t)Sysmap ||
-		    pv->pv_va >= (vaddr_t)Sysmap + ATARI_KPTSIZE)
+		    pv->pv_va >= (vaddr_t)Sysmap + M68K_MAX_KPTSIZE)
 			printf("collect: kernel PT VA out of range\n");
 		else
 			goto ok;
@@ -1684,7 +1594,7 @@
 		if (*ste)
 			printf("collect: kernel STE at %p still valid (%x)\n",
 			       ste, *ste);
-		ste = (int *)&Sysptmap[(u_int *)ste-pmap_ste(pmap_kernel(), 0)];
+		ste = &Sysptmap[ste - pmap_ste(pmap_kernel(), 0)];
 		if (*ste)
 			printf("collect: kernel PTmap at %p still valid (%x)\n",
 			       ste, *ste);
@@ -1706,7 +1616,8 @@
 		printf("pmap_activate(%p)\n", l);
 #endif
 
-	PMAP_ACTIVATE(pmap, curlwp == NULL || l->l_proc == curproc);
+	PMAP_ACTIVATE(pmap, (curlwp->l_flag & LW_IDLE) != 0 ||
+	    l->l_proc == curproc);
 }
 
 /*
@@ -1731,7 +1642,7 @@
  */
 void
 pmap_zero_page(phys)
-	register paddr_t	phys;
+	paddr_t	phys;
 {
 	int	s;
 	int	dst_pte = PG_RW | PG_V;
@@ -1753,7 +1664,7 @@
 
 	s = splvm();
 
-	*CMAP1 = phys | dst_pte;
+	*caddr1_pte = phys | dst_pte;
 	TBIS((vaddr_t)CADDR1);
 	zeropage(CADDR1);
 
@@ -1762,7 +1673,7 @@
 	 * XXX: Invalidating is not strictly necessary.... Not doing it
          * is saving us a few cycles
 	 */
-	*CMAP1 = PG_NV;
+	*caddr1_pte = PG_NV;
 	TBIS((vaddr_t)CADDR1);
 #endif
 
@@ -1782,7 +1693,7 @@
  */
 void
 pmap_copy_page(src, dst)
-	register paddr_t	src, dst;
+	paddr_t	src, dst;
 {
 	int	s;
 	int	src_pte = PG_RO | PG_V;
@@ -1804,9 +1715,9 @@
 #endif
 
 	s = splvm();
-	*CMAP1 = src | src_pte;
+	*caddr1_pte = src | src_pte;
 	TBIS((vaddr_t)CADDR1);
-	*CMAP2 = dst | dst_pte;
+	*caddr2_pte = dst | dst_pte;
 	TBIS((vaddr_t)CADDR2);
 
 	copypage(CADDR1, CADDR2);
@@ -1816,9 +1727,9 @@
 	 * XXX: Invalidating is not strictly necessary.... Not doing it
          * is saving us a few cycles
 	 */
-	*CMAP1 = PG_NV;
+	*caddr1_pte = PG_NV;
 	TBIS((vaddr_t)CADDR1);
-	*CMAP2 = PG_NV;
+	*caddr2_pte = PG_NV;
 	TBIS((vaddr_t)CADDR2);
 #endif
 
@@ -1833,13 +1744,14 @@
 pmap_clear_modify(pg)
 	struct vm_page *pg;
 {
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
 	bool rv;
+	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_FOLLOW)
 		printf("pmap_clear_modify(%lx)\n", pa);
 #endif
+
 	rv = pmap_testbit(pa, PG_M);
 	pmap_changebit(pa, PG_M, false);
 	return rv;
@@ -1855,13 +1767,14 @@
 pmap_clear_reference(pg)
 	struct vm_page *pg;
 {
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
 	bool rv;
+	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_FOLLOW)
 		printf("pmap_clear_reference(%lx)\n", pa);
 #endif
+
 	rv = pmap_testbit(pa, PG_U);
 	pmap_changebit(pa, PG_U, false);
 	return rv;
@@ -1878,7 +1791,7 @@
 pmap_is_referenced(pg)
 	struct vm_page *pg;
 {
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
+	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_FOLLOW) {
@@ -1901,7 +1814,7 @@
 pmap_is_modified(pg)
 	struct vm_page *pg;
 {
-	paddr_t pa = VM_PAGE_TO_PHYS(pg);
+	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_FOLLOW) {
@@ -2013,33 +1926,33 @@
 		 */
 		if (refs == 0 && (flags & PRM_KEEPPTPAGE) == 0) {
 #ifdef DIAGNOSTIC
-			struct pv_entry *pve;
+			struct pv_entry *_pv;
 #endif
-			paddr_t paddr;
+			paddr_t _pa;
 
-			paddr = pmap_pte_pa(pmap_pte(pmap_kernel(), ptpva));
+			_pa = pmap_pte_pa(pmap_pte(pmap_kernel(), ptpva));
 #ifdef DIAGNOSTIC
-			if (PAGE_IS_MANAGED(paddr) == 0)
+			if (PAGE_IS_MANAGED(_pa) == 0)
 				panic("pmap_remove_mapping: unmanaged PT page");
-			pve = pa_to_pvh(paddr);
-			if (pve->pv_ptste == NULL)
+			_pv = pa_to_pvh(_pa);
+			if (_pv->pv_ptste == NULL)
 				panic("pmap_remove_mapping: ptste == NULL");
-			if (pve->pv_pmap != pmap_kernel() ||
-			    pve->pv_va != ptpva ||
-			    pve->pv_next != NULL)
+			if (_pv->pv_pmap != pmap_kernel() ||
+			    _pv->pv_va != ptpva ||
+			    _pv->pv_next != NULL)
 				panic("pmap_remove_mapping: "
 				    "bad PT page pmap %p, va 0x%lx, next %p",
-				    pve->pv_pmap, pve->pv_va, pve->pv_next);
+				    _pv->pv_pmap, _pv->pv_va, _pv->pv_next);
 #endif
 			pmap_remove_mapping(pmap_kernel(), ptpva,
 			    NULL, PRM_TFLUSH|PRM_CFLUSH);
 			mutex_enter(&uvm_kernel_object->vmobjlock);
-			uvm_pagefree(PHYS_TO_VM_PAGE(paddr));
+			uvm_pagefree(PHYS_TO_VM_PAGE(_pa));
 			mutex_exit(&uvm_kernel_object->vmobjlock);
 #ifdef DEBUG
 			if (pmapdebug & (PDB_REMOVE|PDB_PTPAGE))
 			    printf("remove: PT page 0x%lx (0x%lx) freed\n",
-				    ptpva, paddr);
+				    ptpva, _pa);
 #endif
 		}
 	}
@@ -2138,8 +2051,7 @@
 					ptpmap->pm_stab,
 					ptpmap->pm_sref - 1);
 			if ((pmapdebug & PDB_PARANOIA) &&
-			    ptpmap->pm_stab !=
-			     (st_entry_t *)trunc_page((vaddr_t)ste))
+			    ptpmap->pm_stab != (st_entry_t *)trunc_page((vaddr_t) ste))
 				panic("remove: bogus ste");
 #endif
 			if (--(ptpmap->pm_sref) == 0) {
@@ -2149,7 +2061,7 @@
 					    ptpmap->pm_stab);
 #endif
 				uvm_km_free(kernel_map,
-				    (vaddr_t)ptpmap->pm_stab, ATARI_STSIZE,
+				    (vaddr_t)ptpmap->pm_stab, M68K_STSIZE,
 				    UVM_KMF_WIRED);
 				ptpmap->pm_stab = Segtabzero;
 				ptpmap->pm_stpa = Segtabzeropa;
@@ -2165,10 +2077,6 @@
 				if (active_user_pmap(ptpmap))
 					PMAP_ACTIVATE(ptpmap, 1);
 			}
-#ifdef DEBUG
-			else if (ptpmap->pm_sref < 0)
-				panic("remove: sref < 0");
-#endif
 		}
 #if 0
 		/*
@@ -2226,39 +2134,14 @@
 	return (rv);
 }
 
-static void
-atari_protection_init()
-{
-	register int *kp, prot;
-
-	kp = protection_codes;
-	for (prot = 0; prot < 8; prot++) {
-		switch (prot) {
-		case VM_PROT_NONE | VM_PROT_NONE | VM_PROT_NONE:
-			*kp++ = 0;
-			break;
-		case VM_PROT_READ | VM_PROT_NONE | VM_PROT_NONE:
-		case VM_PROT_READ | VM_PROT_NONE | VM_PROT_EXECUTE:
-		case VM_PROT_NONE | VM_PROT_NONE | VM_PROT_EXECUTE:
-			*kp++ = PG_RO;
-			break;
-		case VM_PROT_NONE | VM_PROT_WRITE | VM_PROT_NONE:
-		case VM_PROT_NONE | VM_PROT_WRITE | VM_PROT_EXECUTE:
-		case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_NONE:
-		case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE:
-			*kp++ = PG_RW;
-			break;
-		}
-	}
-}
-
-static bool
+/* static */
+bool
 pmap_testbit(pa, bit)
-	register paddr_t pa;
+	paddr_t pa;
 	int bit;
 {
-	register pv_entry_t pv;
-	register int *pte;
+	struct pv_entry *pv;
+	int *pte;
 	int s;
 
 	pv = pa_to_pvh(pa);
@@ -2291,24 +2174,24 @@
 	return(false);
 }
 
-void
+static void
 pmap_changebit(pa, bit, setem)
-	register paddr_t pa;
+	paddr_t pa;
 	int bit;
 	bool setem;
 {
-	register pv_entry_t pv;
-	register int *pte, npte;
+	struct pv_entry *pv;
+	int *pte, npte;
 	vaddr_t va;
-	int s;
 	bool firstpage;
+	int s;
 
 	firstpage = true;
 
 #ifdef DEBUG
 	if (pmapdebug & PDB_BITS)
 		printf("pmap_changebit(%lx, %x, %s)\n",
-		       pa, bit, setem ? "set" : "clear");
+		    pa, bit, setem ? "set" : "clear");
 #endif
 
 	pv = pa_to_pvh(pa);
@@ -2320,10 +2203,12 @@
 
 	if (!setem)
 		*pa_to_attribute(pa) &= ~bit;
+
 	/*
 	 * Loop over all current mappings setting/clearing as appropos
 	 * If setting RO do we need to clear the VAC?
 	 */
+
 	if (pv->pv_pmap == NULL) {
 		splx(s);
 		return;
@@ -2336,11 +2221,13 @@
 		else
 			npte = *pte & ~bit;
 		if (*pte != npte) {
+
 			/*
 			 * If we are changing caching status or
 			 * protection make sure the caches are
 			 * flushed (but only once).
 			 */
+
 #if defined(M68040) || defined(M68060)
 			if (firstpage && mmutype == MMU_68040 &&
 			    ((bit == PG_RO && setem) || (bit & PG_CMASK))) {
@@ -2357,7 +2244,8 @@
 	splx(s);
 }
 
-static int
+/* static */
+int
 pmap_enter_ptpage(pmap, va, can_fail)
 	pmap_t pmap;
 	vaddr_t va;
@@ -2365,11 +2253,11 @@
 {
 	paddr_t ptpa;
 	struct vm_page *pg;
-	pv_entry_t pv;
+	struct pv_entry *pv;
 #ifdef M68060
 	u_int stpa;
-#endif /* M68060 */
-	u_int *ste;
+#endif
+	st_entry_t *ste;
 	int s;
 
 #ifdef DEBUG
@@ -2385,16 +2273,17 @@
 	 * reference count drops to zero.
 	 */
 	if (pmap->pm_stab == Segtabzero) {
-		pmap->pm_stab = (u_int *)
-		    uvm_km_alloc(kernel_map, ATARI_STSIZE, 0,
-		    UVM_KMF_WIRED | UVM_KMF_ZERO |
-		    (can_fail ? UVM_KMF_NOWAIT : 0));
+		/* XXX Atari uses kernel_map here: */
+		pmap->pm_stab = (st_entry_t *)
+		    uvm_km_alloc(kernel_map, M68K_STSIZE, 0,
+			UVM_KMF_WIRED | UVM_KMF_ZERO |
+		 	(can_fail ? UVM_KMF_NOWAIT : 0));
 		if (pmap->pm_stab == NULL) {
 			pmap->pm_stab = Segtabzero;
 			return ENOMEM;
 		}
-		(void) pmap_extract(pmap_kernel(),
-		    (vaddr_t)pmap->pm_stab, (paddr_t *)&pmap->pm_stpa);
+		(void) pmap_extract(pmap_kernel(), (vaddr_t)pmap->pm_stab,
+		    (paddr_t *)&pmap->pm_stpa);
 #if defined(M68040) || defined(M68060)
 		if (mmutype == MMU_68040) {
 #if defined(M68060)
@@ -2403,8 +2292,8 @@
 				pt_entry_t	*pte;
 
 				pte = pmap_pte(pmap_kernel(), pmap->pm_stab);
-				while (stpa < (u_int)pmap->pm_stpa + 
-				    ATARI_STSIZE) {
+				while (stpa < (u_int)pmap->pm_stpa +
+				    M68K_STSIZE) {
 					*pte = (*pte & ~PG_CMASK) | PG_CI;
 					++pte;
 					stpa += PAGE_SIZE;
@@ -2467,8 +2356,7 @@
 			    pmap_ste2(pmap, va), ste);
 #endif
 	}
-#endif /* defined(M68040) || defined(M68060) */
-
+#endif
 	va = trunc_page((vaddr_t)pmap_pte(pmap, va));
 
 	/*
@@ -2477,7 +2365,7 @@
 	 * pmap_enter).
 	 */
 	if (pmap == pmap_kernel()) {
-		register struct kpt_page *kpt;
+		struct kpt_page *kpt;
 
 		s = splvm();
 		if ((kpt = kpt_free_list) == NULL) {
@@ -2599,7 +2487,7 @@
 	 */
 #if defined(M68040) || defined(M68060)
 	if (mmutype == MMU_68040) {
-		u_int *este;
+		st_entry_t *este;
 
 		for (este = &ste[NPTEPG / SG4_LEV3SIZE]; ste < este; ++ste) {
 			*ste = ptpa | SG_U | SG_RW | SG_V;
@@ -2629,46 +2517,12 @@
 	return 0;
 }
 
-/*
- *	Routine:	pmap_virtual_space
- *
- *	Function:
- *		Report the range of available kernel virtual address
- *		space to the VM system during bootstrap.  Called by
- *		vm_bootstrap_steal_memory().
- */
-void
-pmap_virtual_space(vstartp, vendp)
-	vaddr_t     *vstartp, *vendp;
-{
-
-	*vstartp = virtual_avail;
-	*vendp = virtual_end;
-}
-
-/*
- *	Routine:	pmap_procwr
- *
- *	Function:
- *		Synchronize caches corresponding to [addr, addr+len) in
- *		p.
- *
- */
-void
-pmap_procwr(p, va, len)
-	struct proc	*p;
-	vaddr_t		va;
-	u_long		len;
-{
-	(void)cachectl1(0x80000004, va, len, p);
-}
-
 #ifdef DEBUG
-static void
+void
 pmap_pvdump(pa)
 	paddr_t pa;
 {
-	register pv_entry_t pv;
+	struct pv_entry *pv;
 
 	printf("pa %lx", pa);
 	for (pv = pa_to_pvh(pa); pv; pv = pv->pv_next)
@@ -2685,7 +2539,7 @@
  *	and ensure that it is consistent with the number of wirings
  *	to that page that the VM system has.
  */
-static void
+void
 pmap_check_wiring(str, va)
 	const char *str;
 	vaddr_t va;
@@ -2707,7 +2561,8 @@
 	}
 
 	count = 0;
-	for (pte = (pt_entry_t *)va; pte < (pt_entry_t *)(va + PAGE_SIZE); pte++)
+	for (pte = (pt_entry_t *)va; pte < (pt_entry_t *)(va + PAGE_SIZE);
+	     pte++)
 		if (*pte)
 			count++;
 	if (pg->wire_count != count)
@@ -2715,3 +2570,37 @@
 		       str, va, pg->wire_count, count);
 }
 #endif
+
+/*
+ *	Routine:	pmap_virtual_space
+ *
+ *	Function:
+ *		Report the range of available kernel virtual address
+ *		space to the VM system during bootstrap.  Called by
+ *		vm_bootstrap_steal_memory().
+ */
+void
+pmap_virtual_space(vstartp, vendp)
+	vaddr_t     *vstartp, *vendp;
+{
+
+	*vstartp = virtual_avail;
+	*vendp = virtual_end;
+}
+
+/*
+ *	Routine:	pmap_procwr
+ *
+ *	Function:
+ *		Synchronize caches corresponding to [addr, addr+len) in
+ *		p.
+ *
+ */
+void
+pmap_procwr(p, va, len)
+	struct proc	*p;
+	vaddr_t		va;
+	size_t		len;
+{
+	(void)cachectl1(0x80000004, va, len, p);
+}
Index: conf/files.atari
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/conf/files.atari,v
retrieving revision 1.112
diff -u -r1.112 files.atari
--- conf/files.atari	20 Feb 2008 21:43:33 -0000	1.112
+++ conf/files.atari	28 Dec 2008 05:31:08 -0000
@@ -203,6 +203,7 @@
 file	arch/atari/atari/mainbus.c
 file	arch/atari/atari/mem.c
 file	arch/atari/atari/pmap.c
+file	arch/atari/atari/pmap_bootstrap.c
 file	arch/atari/atari/trap.c
 file	arch/atari/atari/stalloc.c
 file	arch/atari/atari/fpu.c
@@ -210,6 +211,7 @@
 file	arch/atari/atari/intr.c
 file	arch/m68k/m68k/cacheops.c
 file	arch/m68k/m68k/db_memrw.c		ddb
+#file	arch/m68k/m68k/pmap_motorola.c
 file	arch/m68k/m68k/procfs_machdep.c		procfs
 file	arch/m68k/m68k/sys_machdep.c
 file	arch/m68k/m68k/vm_machdep.c
Index: include/pcb.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/pcb.h,v
retrieving revision 1.7
diff -u -r1.7 pcb.h
--- include/pcb.h	4 Mar 2007 05:59:41 -0000	1.7
+++ include/pcb.h	28 Dec 2008 05:31:08 -0000
@@ -1,115 +1,3 @@
 /*	$NetBSD: pcb.h,v 1.7 2007/03/04 05:59:41 christos Exp $	*/
 
-/*
- * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: pcb.h 1.13 89/04/23$
- *
- *	@(#)pcb.h	7.4 (Berkeley) 5/4/91
- */
-/*
- * Copyright (c) 1988 University of Utah.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: pcb.h 1.13 89/04/23$
- *
- *	@(#)pcb.h	7.4 (Berkeley) 5/4/91
- */
-
-#ifndef _MACHINE_PCB_H_
-#define _MACHINE_PCB_H_
-
-#include <machine/frame.h>
-
-/*
- * ATARI process control block
- */
-struct pcb
-{
-	short	pcb_flags;	/* misc. process flags (+0) */
-	short	pcb_ps; 	/* processor status word (+2) */
-	int	__pcb_spare0;
-	int	pcb_usp;	/* user stack pointer (+8) */
-	int	pcb_regs[12];	/* D2-D7, A2-A7 (+C) */
-	int	pcb_cmap2;	/* temporary copy PTE */
-	void *	pcb_onfault;	/* for copyin/out faults */
-	struct	fpframe pcb_fpregs; /* 68881/2 context save area */
-	int	pcb_exec[16];	/* exec structure for core dumps */
-};
-
-/* Positions within pcb_regs[] of A6 and A7 (FP and SP). For m68k DDB. */
-#define PCB_REGS_FP	10
-#define PCB_REGS_SP	11
-
-/* flags (none currently used) */
-
-/*
- * The pcb is augmented with machine-dependent additional data for
- * core dumps. For the hp300, this includes an HP-UX exec header
- * which is dumped for HP-UX processes.
- */
-struct md_coredump {
-        int     md_exec[16];    /* exec structure for HP-UX core dumps */
-};
-
-#endif /* !_MACHINE_PCB_H_ */
+#include <m68k/pcb.h>
Index: include/pmap.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/pmap.h,v
retrieving revision 1.38
diff -u -r1.38 pmap.h
--- include/pmap.h	9 Dec 2008 20:45:44 -0000	1.38
+++ include/pmap.h	28 Dec 2008 05:31:09 -0000
@@ -76,93 +76,18 @@
 #ifndef	_MACHINE_PMAP_H_
 #define	_MACHINE_PMAP_H_
 
-#include <sys/simplelock.h>
-
-/*
- * Pmap stuff
- */
-struct pmap {
-	pt_entry_t 		*pm_ptab;	/* KVA of page table */
-	st_entry_t		*pm_stab;	/* KVA of segment table */
-	int			pm_stfree;	/* 040: free lev2 blocks */
-	u_int			*pm_stpa;	/* 040: ST phys. address */
-	short			pm_sref;	/* segment table ref count */
-	short			pm_count;	/* pmap reference count */
-	long			pm_ptpages;	/* more stats: PT pages */
-	struct simplelock	pm_lock;	/* lock on pmap */
-	struct pmap_statistics	pm_stats;	/* pmap statistics */
-};
-
-/*
- * On the 040 we keep track of which level 2 blocks are already in use
- * with the pm_stfree mask.  Bits are arranged from LSB (block 0) to MSB
- * (block 31).  For convenience, the level 1 table is considered to be
- * block 0.
- *
- * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed.
- * for the kernel and users.  16 implies only the initial "segment table"
- * page is used.  WARNING: don't change MAXUL2SIZE unless you can allocate
- * physically contiguous pages for the ST in pmap.c!
- */
-#define	MAXKL2SIZE	32
-#define MAXUL2SIZE	16
-#define l2tobm(n)	(1 << (n))
-#define	bmtol2(n)	(ffs(n) - 1)
-
-/*
- * Macros for speed
- */
-#define	PMAP_ACTIVATE(pmap, loadhw)					\
-{									\
-	if ((loadhw))							\
-		loadustp(m68k_btop((pmap)->pm_stpa));	\
-}
+#include <m68k/pmap_motorola.h>
 
 /*
  * Description of the memory segments. Build in atari_init/start_c().
  * This gives a better separation between machine dependent stuff and
  * the pmap-module.
  */
-#define	NMEM_SEGS	8
+#define NMEM_SEGS	8
 struct memseg {
-	paddr_t	start;		/* PA of first page in segment	*/
-	paddr_t	end;		/* PA of last  page in segment	*/
-	int	first_page;	/* relative page# of 'start'	*/
-};
-
-/*
- * For each struct vm_page, there is a list of all currently valid virtual
- * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
- */
-typedef struct pv_entry {
-	struct pv_entry	*pv_next;	/* next pv_entry */
-	struct pmap	*pv_pmap;	/* pmap where mapping lies */
-	vaddr_t		pv_va;		/* virtual address for mapping */
-	u_int		*pv_ptste;	/* non-zero if VA maps a PT page */
-	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
-	int		pv_flags;	/* flags */
-} *pv_entry_t;
-
-#define	PV_CI		0x01	/* all entries must be cache inhibited */
-#define PV_PTPAGE	0x02	/* entry maps a page table page */
-
-struct pv_page;
-
-struct pv_page_info {
-	TAILQ_ENTRY(pv_page) pgi_list;
-	struct pv_entry *pgi_freelist;
-	int pgi_nfree;
-};
-
-/*
- * This is basically:
- * ((PAGE_SIZE - sizeof(struct pv_page_info)) / sizeof(struct pv_entry))
- */
-#define	NPVPPG	340
-
-struct pv_page {
-	struct pv_page_info pvp_pgi;
-	struct pv_entry pvp_pv[NPVPPG];
+	paddr_t start;		/* PA of first page in segment	*/
+	paddr_t end;		/* PA of last  page in segment	*/
+	int     first_page;	/* relative page# of 'start'	*/
 };
 
 #ifdef	_KERNEL
@@ -177,31 +102,7 @@
 struct memseg	boot_segs[NMEM_SEGS];
 struct memseg	usable_segs[NMEM_SEGS];
 
-pv_entry_t	pv_table;	/* array of entries, one per page */
-u_int		*Sysmap;
-char		*vmmap;		/* map for mem, dumps, etc. */
-
-#define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
-#define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
-
-#define	pmap_update(pmap)		/* nothing (yet) */
-
-static __inline void
-pmap_remove_all(struct pmap *pmap)
-{
-	/* Nothing. */
-}
-
-#define	active_user_pmap(pm) \
-	(curproc && \
-	 (pm) != pmap_kernel() && (pm) == curproc->p_vmspace->vm_map.pmap)
-
 void	pmap_bootstrap __P((psize_t, u_int));
-void	pmap_changebit __P((paddr_t, int, bool));
-
-vaddr_t	pmap_map __P((vaddr_t, paddr_t, paddr_t, int));
-void	pmap_procwr __P((struct proc *, vaddr_t, u_long));
-#define PMAP_NEED_PROCWR
 
 #endif	/* _KERNEL */
 
Index: include/pte.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/pte.h,v
retrieving revision 1.7
diff -u -r1.7 pte.h
--- include/pte.h	11 Dec 2005 12:16:59 -0000	1.7
+++ include/pte.h	28 Dec 2008 05:31:09 -0000
@@ -1,188 +1,3 @@
 /*	$NetBSD: pte.h,v 1.7 2005/12/11 12:16:59 christos Exp $	*/
 
-/*
- * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: pte.h 1.11 89/09/03$
- *
- *	@(#)pte.h	7.3 (Berkeley) 5/8/91
- */
-/*
- * Copyright (c) 1988 University of Utah.
- *
- * This code is derived from software contributed to Berkeley by
- * the Systems Programming Group of the University of Utah Computer
- * Science Department.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Utah $Hdr: pte.h 1.11 89/09/03$
- *
- *	@(#)pte.h	7.3 (Berkeley) 5/8/91
- */
-
-#ifndef _MACHINE_PTE_H_
-#define _MACHINE_PTE_H_
-
-/*
- * ATARI hardware segment/page table entries
- */
-
-struct pte {
-	u_int pte;
-};
-
-typedef u_int	pt_entry_t;
-
-struct ste {
-	u_int ste;
-};
-
-typedef u_int	st_entry_t;
-
-#define	PT_ENTRY_NULL	((pt_entry_t *) 0)
-#define	ST_ENTRY_NULL	((st_entry_t *) 0)
-
-#define	SG_V		0x00000002	/* segment is valid */
-#define	SG_NV		0x00000000
-#define	SG_PROT		0x00000004	/* access protection mask */
-#define	SG_RO		0x00000004
-#define	SG_RW		0x00000000
-#define SG_U		0x00000008	/* modified bit (68040) */
-#define	SG_FRAME	0xffffe000
-#define SG_IMASK	0xff000000
-#define SG_ISHIFT	24
-#define SG_PMASK	0x00ffe000
-#define SG_PSHIFT	13
-
-/* 68040 additions */
-#define SG4_MASK1	0xfe000000	/* pointer table 1 index mask */
-#define SG4_SHIFT1	25
-#define SG4_MASK2	0x01fc0000	/* pointer table 2 index mask */
-#define	SG4_SHIFT2	18
-#define SG4_MASK3	0x0003e000	/* page table index mask */
-#define	SG4_SHIFT3	13
-#define	SG4_ADDR1	0xfffffe00	/* pointer table address mask */
-#define	SG4_ADDR2	0xffffff80	/* page table address mask */
-#define SG4_LEV1SIZE	128		/* entries in pointer table 1 */
-#define SG4_LEV2SIZE	128		/* entries in pointer table 2 */
-#define SG4_LEV3SIZE	32		/* entries in page table */
-
-#define	PG_V		0x00000001
-#define	PG_NV		0x00000000
-#define	PG_PROT		0x00000004
-#define	PG_U		0x00000008
-#define	PG_M		0x00000010
-/*
- * XXX The Milan uses the U0 pin to switch the pci-bridge between little & big
- * endian mode. That's why I moved the 'wired' flag to U1 leo 10Apr/2001.
- */
-#if 0
-#define	PG_W		0x00000100
-#else
-#define	PG_W		0x00000200
-#endif
-#define	PG_RO		0x00000004
-#define	PG_RW		0x00000000
-#define PG_FRAME	0xffffe000
-#define	PG_CI		0x00000040
-#define PG_SHIFT	13
-#define	PG_PFNUM(x)	(((x) & PG_FRAME) >> PG_SHIFT)
-
-/* 68040 additions */
-#define PG_CMASK	0x00000060	/* cache mode mask */
-#define PG_CWT		0x00000000	/* writethrough caching */
-#define PG_CCB		0x00000020	/* copyback caching */
-#define PG_CIS		0x00000040	/* cache inhibited serialized */
-#define PG_CIN		0x00000060	/* cache inhibited nonserialized */
-#define PG_SO		0x00000080	/* supervisor only */
-
-#define	ATARI_STSIZE		(MAXUL2SIZE*SG4_LEV2SIZE*sizeof(st_entry_t))
-
-/*
- * ATARI_MAX_COREUPT	maximum number of incore user page tables
- * ATARI_USER_PTSIZE	the number of bytes for user pagetables
- * ATARI_PTBASE		the VA start of the map from which upt's are allocated
- * ATARI_PTSIZE		the size of the map from which upt's are allocated
- * ATARI_KPTSIZE	size of kernel page table
- * ATARI_MAX_KPTSIZE	the most number of bytes for kpt pages
- * ATARI_MAX_PTSIZE	the number of bytes to map everything
- */
-#define ATARI_MAX_COREUPT	1024
-#define ATARI_UPTSIZE		roundup(VM_MAXUSER_ADDRESS / NPTEPG, PAGE_SIZE)
-#define ATARI_UPTBASE		0x10000000
-#define ATARI_UPTMAXSIZE \
-    roundup((ATARI_MAX_COREUPT * ATARI_UPTSIZE), PAGE_SIZE)
-#define ATARI_MAX_KPTSIZE \
-    (ATARI_MAX_COREUPT * ATARI_UPTSIZE / NPTEPG)
-#define ATARI_KPTSIZE \
-    roundup((VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / NPTEPG, PAGE_SIZE)
-#define ATARI_MAX_PTSIZE	roundup(0xffffffff / NPTEPG, PAGE_SIZE)
-
-/*
- * Kernel virtual address to page table entry and to physical address.
- */
-#define	kvtopte(va) \
-	(&Sysmap[((unsigned)(va) - VM_MIN_KERNEL_ADDRESS) >> PGSHIFT])
-#define	ptetokv(pt) \
-	((((u_int *)(pt) - Sysmap) << PGSHIFT) + VM_MIN_KERNEL_ADDRESS)
-#define	kvtophys(va) \
-	((kvtopte(va)->pg_pfnum << PGSHIFT) | ((int)(va) & PGOFSET))
-
-
-#endif /* !_MACHINE_PTE_H_ */
+#include <m68k/pte_motorola.h>
Index: include/vmparam.h
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/include/vmparam.h,v
retrieving revision 1.21
diff -u -r1.21 vmparam.h
--- include/vmparam.h	11 Dec 2005 12:16:59 -0000	1.21
+++ include/vmparam.h	28 Dec 2008 05:31:09 -0000
@@ -152,7 +152,7 @@
 #define VM_MAX_ADDRESS		((vaddr_t)(USRSTACK))
 #define VM_MAXUSER_ADDRESS	((vaddr_t)(VM_MAX_ADDRESS))
 #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)0)
-#define VM_MAX_KERNEL_ADDRESS	((vaddr_t)(0-PAGE_SIZE))
+#define VM_MAX_KERNEL_ADDRESS	((vaddr_t)-(NPTEPG * PAGE_SIZE))
 
 /*
  * virtual sizes (bytes) for various kernel submaps
--- /dev/null	2008-12-28 14:05:29.000000000 +0900
+++ atari/pmap_bootstrap.c	2008-12-28 14:32:45.000000000 +0900
@@ -0,0 +1,220 @@
+/*	$NetBSD$	*/
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* 
+ * Copyright (c) 1991 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)pmap.c	7.5 (Berkeley) 5/10/91
+ */
+
+#include <sys/cdefs.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/user.h>
+
+#include <uvm/uvm.h>
+
+#include <machine/pte.h>
+#include <machine/cpu.h>
+#include <machine/vmparam.h>
+
+#include <m68k/cacheops.h>
+
+/*
+ * Kernel segment/page table and page table map.
+ * The page table map gives us a level of indirection we need to dynamically
+ * expand the page table.  It is essentially a copy of the segment table
+ * with PTEs instead of STEs.  All are initialized in locore at boot time.
+ * Sysmap will initially contain VM_KERNEL_PT_PAGES pages of PTEs.
+ * Segtabzero is an empty segment table which all processes share til they
+ * reference something.
+ */
+u_int		*Sysseg, *Sysseg_pa;
+pt_entry_t	*Sysmap, *Sysptmap;
+
+vsize_t		mem_size;	/* memory size in bytes */
+paddr_t		avail_end;	/* PA of last available physical page */
+vaddr_t		virtual_avail;  /* VA of first avail page (after kernel bss)*/
+vaddr_t		virtual_end;	/* VA of last avail page (end of kernel AS) */
+#if defined(M68040) || defined(M68060)
+int		protostfree;    /* prototype (default) free ST map */
+#endif
+
+extern void *	msgbufaddr;
+extern paddr_t	msgbufpa;
+
+/*
+ * All those kernel PT submaps that BSD is so fond of
+ */
+void 		*CADDR1, *CADDR2;
+char		*vmmap;
+
+extern int	protection_codes[];
+
+/*
+ *	Bootstrap the system enough to run with virtual memory.
+ *	Map the kernel's code and data, and allocate the system page table.
+ *
+ *	On the HP this is called after mapping has already been enabled
+ *	and just syncs the pmap module with what has already been done.
+ *	[We can't call it easily with mapping off since the kernel is not
+ *	mapped with PA == VA, hence we would have to relocate every address
+ *	from the linked base (virtual) address 0 to the actual (physical)
+ *	address of 0xFFxxxxxx.]
+ */
+void
+pmap_bootstrap(kernel_size, hw_addr)
+psize_t	kernel_size;
+u_int	hw_addr;
+{
+	vaddr_t	va;
+	int	i;
+
+	/*
+	 * Announce page-size to the VM-system
+	 */
+	uvmexp.pagesize = NBPG;
+	uvm_setpagesize();
+
+	/*
+	 * Setup physical address ranges
+	 */
+	for (i = 0; usable_segs[i+1].start; i++)
+		;
+	/* XXX: allow for msgbuf */
+	usable_segs[i].end -= m68k_round_page(MSGBUFSIZE);
+	avail_end = msgbufpa = usable_segs[i].end;
+
+	/*
+	 * Count physical memory
+	 */
+	for (i = mem_size = 0; i < NMEM_SEGS; i++) {
+		if (boot_segs[i].start == boot_segs[i].end)
+			break;
+		mem_size += boot_segs[i].end - boot_segs[i].start;
+	}
+
+	/*
+	 * Announce available memory to the VM-system
+	 */
+	for (i = 0; usable_segs[i].start; i++)
+		uvm_page_physload(atop(usable_segs[i].start),
+				 atop(usable_segs[i].end),
+				 atop(usable_segs[i].start),
+				 atop(usable_segs[i].end),
+				 VM_FREELIST_DEFAULT);
+
+	virtual_avail = VM_MIN_KERNEL_ADDRESS + kernel_size;
+	virtual_end   = VM_MAX_KERNEL_ADDRESS;
+
+	/*
+	 * Initialize protection array.
+	 * XXX don't use a switch statement, it might produce an
+	 * absolute "jmp" table.
+	 */
+	{
+		int *kp;
+
+		kp = (int *)&protection_codes;
+		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_NONE] = 0;
+		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_NONE] = PG_RO;
+		kp[VM_PROT_READ|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
+		kp[VM_PROT_NONE|VM_PROT_NONE|VM_PROT_EXECUTE] = PG_RO;
+		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
+		kp[VM_PROT_NONE|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
+		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_NONE] = PG_RW;
+		kp[VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE] = PG_RW;
+	}
+
+	/*
+	 * Kernel page/segment table allocated in locore,
+	 * just initialize pointers.
+	 */
+	pmap_kernel()->pm_stpa = Sysseg_pa;
+	pmap_kernel()->pm_stab = Sysseg;
+	pmap_kernel()->pm_ptab = Sysmap;
+#if defined(M68040) || defined(M68060)
+	if (mmutype == MMU_68040) {
+		pmap_kernel()->pm_stfree = protostfree;
+	}
+#endif
+
+	simple_lock_init(&pmap_kernel()->pm_lock);
+	pmap_kernel()->pm_count = 1;
+
+	/*
+	 * Allocate all the submaps we need
+	 */
+#define	SYSMAP(c, v, n)	\
+	v = (c)va; va += ((n)*PAGE_SIZE);
+
+	va = virtual_avail;
+
+	SYSMAP(void *   ,CADDR1	,1			)
+	SYSMAP(void *   ,CADDR2	,1			)
+	SYSMAP(void *   ,vmmap	,1			)
+	SYSMAP(void *	,msgbufaddr ,btoc(MSGBUFSIZE)	)
+
+	DCIS();
+
+	virtual_avail = reserve_dumppages(va);
+}

---
Izumi Tsutsui
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.