BSD 4_4 release
[unix-history] / usr / src / sys / luna68k / luna68k / pmap_bootstrap.c
index 7ec16b7..dcab649 100644 (file)
@@ -1,37 +1,55 @@
 /* 
  * Copyright (c) 1992 OMRON Corporation.
 /* 
  * Copyright (c) 1992 OMRON Corporation.
- * Copyright (c) 1991 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993
+ *     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.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  * Science Department.
  *
- * %sccs.include.redist.c%
+ * 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.
  *
  *
- *     OMRON: $Id: pmap_bootstrap.c,v 1.2 92/06/14 18:11:27 moti Exp $
+ * 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: hp300/hp300/pmap_bootstrap.c  7.1 (Berkeley) 6/5/92
+ * from: hp300/hp300/pmap_bootstrap.c  7.4 (Berkeley) 12/27/92
  *
  *
- *     @(#)pmap_bootstrap.c    7.2 (Berkeley) %G%
+ *     @(#)pmap_bootstrap.c    8.1 (Berkeley) 6/10/93
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
+#include <sys/msgbuf.h>
 #include <luna68k/luna68k/pte.h>
 #include <machine/vmparam.h>
 #include <machine/cpu.h>
 
 #include <vm/vm.h>
 
 #include <luna68k/luna68k/pte.h>
 #include <machine/vmparam.h>
 #include <machine/cpu.h>
 
 #include <vm/vm.h>
 
-/*
- * Allocate various and sundry SYSMAPs used in the days of old VM
- * and not yet converted.  XXX.
- */
-#define BSDVM_COMPAT   1
-
 extern char *etext;
 extern int Sysptsize;
 extern char *etext;
 extern int Sysptsize;
-
 extern char *proc0paddr;
 extern struct ste *Sysseg;
 extern struct pte *Sysptmap, *Sysmap;
 extern char *proc0paddr;
 extern struct ste *Sysseg;
 extern struct pte *Sysptmap, *Sysmap;
@@ -41,43 +59,18 @@ extern int maxmem, physmem;
 extern vm_offset_t avail_start, avail_end, virtual_avail, virtual_end;
 extern vm_size_t mem_size;
 extern int protection_codes[];
 extern vm_offset_t avail_start, avail_end, virtual_avail, virtual_end;
 extern vm_size_t mem_size;
 extern int protection_codes[];
-#if defined(DYNPGSIZE)
-extern int lunapagesperpage;
-#endif
-
-#if BSDVM_COMPAT
-#include <sys/msgbuf.h>
 
 /*
 
 /*
- * All those kernel PT submaps that BSD is so fond of
+ * Special purpose kernel virtual addresses, used for mapping
+ * physical pages for a variety of temporary or permanent purposes:
+ *
+ *     CADDR1, CADDR2: pmap zero/copy operations
+ *     vmmap:          /dev/mem, crash dumps, parity error checking
+ *     ledbase:        SPU LEDs
+ *     msgbufp:        kernel message buffer
  */
  */
-struct pte     *CMAP1, *CMAP2, *mmap;
-caddr_t                CADDR1, CADDR2, vmmap;
-struct pte     *msgbufmap;
+caddr_t                CADDR1, CADDR2, vmmap, ledbase;
 struct msgbuf  *msgbufp;
 struct msgbuf  *msgbufp;
-#endif
-
-/* 
- * LUNA H/W information.
- */
-struct physmap io_physmap[] =
-{
-       {0x40000000,0x00100000,1},      /* debugger */
-       {0x41000000,0x00020000,1},      /* PROM */
-       {0x45000000,0x00000800,0},      /* calendar clock */
-       {0x49000000,0x00000004,0},      /* pio-0 */
-       {0x4D000000,0x00000004,0},      /* pio-1 */
-       {0x51000000,0x00000008,0},      /* sio */
-       {0x61000000,0x00000001,0},      /* TAS register */
-       {0x63000000,0x00000001,0},      /* SYSINT flag */
-       {0x6B000000,0x00000001,0},      /* internal FPP enable/disable */
-       {0x6F000000,0x00000001,0},      /* external FPP enable/disable */
-       {0x71000000,0x00020000,0},      /* 3 port RAM */
-       {0,0,0}                         /* terminate */
-};
-#define        IO_DBG_OFF      0               /* debugger offset in io_physmap[] */
-#define        IOPTPAGE        ((sizeof(io_physmap)/sizeof(struct physmap))-1)
-int    ioptpage = IOPTPAGE;            /* for locore */
 
 /*
  * Bootstrap the VM system.
 
 /*
  * Bootstrap the VM system.
@@ -95,7 +88,7 @@ pmap_bootstrap(nextpa, firstpa)
        vm_offset_t nextpa;
        register vm_offset_t firstpa;
 {
        vm_offset_t nextpa;
        register vm_offset_t firstpa;
 {
-       vm_offset_t kstpa, kptpa, iopa, kptmpa, ukptpa, p0upa;
+       vm_offset_t kstpa, kptpa, kptmpa, lkptpa, p0upa;
        u_int nptpages, kstsize;
        register u_int protoste, protopte, *ste, *pte, *epte;
 
        u_int nptpages, kstsize;
        register u_int protoste, protopte, *ste, *pte, *epte;
 
@@ -108,20 +101,22 @@ pmap_bootstrap(nextpa, firstpa)
         *      kptpa           statically allocated
         *                      kernel PT pages         Sysptsize+ pages
         *
         *      kptpa           statically allocated
         *                      kernel PT pages         Sysptsize+ pages
         *
-        *      kptmpa          kernel PT map           1 page
-        *
-        *      ukptpa          Uarea kernel PT page    1 page
+        * [ Sysptsize is the number of pages of PT, hence we need to
+        *   round the total to a page boundary at the end. ]
         *
         *
-        *      iopa            IO and debbuger space
-        *                      PT pages                IOPTPAGE pages
+        *      kptmpa          kernel PT map           1 page
         *
         *
+        *      lkptpa          last kernel PT page     1 page
         *
         *      p0upa           proc 0 u-area           UPAGES pages
         *
         * The KVA corresponding to any of these PAs is:
         *      (PA - firstpa + KERNBASE).
         */
         *
         *      p0upa           proc 0 u-area           UPAGES pages
         *
         * The KVA corresponding to any of these PAs is:
         *      (PA - firstpa + KERNBASE).
         */
-       kstsize = 1;
+       if (mmutype == MMU_68040)
+               kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE);
+       else
+               kstsize = 1;
        kstpa = nextpa;
        nextpa += kstsize * NBPG;
        kptpa = nextpa;
        kstpa = nextpa;
        nextpa += kstsize * NBPG;
        kptpa = nextpa;
@@ -129,10 +124,8 @@ pmap_bootstrap(nextpa, firstpa)
        nextpa += nptpages * NBPG;
        kptmpa = nextpa;
        nextpa += NBPG;
        nextpa += nptpages * NBPG;
        kptmpa = nextpa;
        nextpa += NBPG;
-       ukptpa = nextpa;
+       lkptpa = nextpa;
        nextpa += NBPG;
        nextpa += NBPG;
-       iopa = nextpa;
-       nextpa += IOPTPAGE * NBPG;
        p0upa = nextpa;
        nextpa += UPAGES * NBPG;
 
        p0upa = nextpa;
        nextpa += UPAGES * NBPG;
 
@@ -141,47 +134,138 @@ pmap_bootstrap(nextpa, firstpa)
         *
         * On 68030s and earlier MMUs the two are identical except for
         * the valid bits so both are initialized with essentially the
         *
         * On 68030s and earlier MMUs the two are identical except for
         * the valid bits so both are initialized with essentially the
-        * same values.
-        * 0x3FF00000 for UPAGES is used for mapping the current process u-area
-        * (u + kernel stack). 
-        */
-
-       /*
-        * 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 +1.
-        */
-       ste = (u_int *)kstpa;
-       pte = (u_int *)kptmpa;
-       epte = &pte[nptpages+1];
-       protoste = kptpa | SG_RW | SG_V;
-       protopte = kptpa | PG_RW | PG_CI | PG_V;
-       while (pte < epte) {
-           *ste++ = protoste;
-           *pte++ = protopte;
-           protoste += NBPG;
-           protopte += NBPG;
-       }
-       /*
-        * Invalidate all but the last remaining entries in both.
+        * same values.  On the 68040, which has a mandatory 3-level
+        * structure, the segment table holds the level 1 table and part
+        * (or all) of the level 2 table and hence is considerably
+        * different.  Here the first level consists of 128 descriptors
+        * (512 bytes) each mapping 32mb of address space.  Each of these
+        * points to blocks of 128 second level descriptors (512 bytes)
+        * each mapping 256kb.  Note that there may be additional "segment
+        * table" pages depending on how large MAXKL2SIZE is.
+        *
+        * Portions of the last segment of KVA space (0x3FF00000 -
+        * 0x3FFFFFFF) are mapped for a couple of purposes.  0x3FF00000
+        * for UPAGES is used for mapping the current process u-area
+        * (u + kernel stack).  The very last page (0x3FFFF000) is mapped
+        * to the last physical page of RAM to give us a region in which
+        * PA == VA.  We use the first part of this page for enabling
+        * and disabling mapping.  The last part of this page also contains
+        * info left by the boot ROM.
+        *
+        * XXX cramming two levels of mapping into the single "segment"
+        * table on the 68040 is intended as a temporary hack to get things
+        * working.  The 224mb of address space that this allows will most
+        * likely be insufficient in the future (at least for the kernel).
         */
         */
-       epte = &((u_int *)kptmpa)[NPTEPG];
-       while (pte < epte) {
-           *ste++ = SG_NV;
-           *pte++ = PG_NV;
+#if defined(LUNA2)
+       if (mmutype == MMU_68040) {
+               register int num;
+
+               /*
+                * First invalidate the entire "segment table" pages
+                * (levels 1 and 2 have the same "invalid" value).
+                */
+               pte = (u_int *)kstpa;
+               epte = &pte[kstsize * NPTEPG];
+               while (pte < epte)
+                       *pte++ = SG_NV;
+               /*
+                * Initialize level 2 descriptors (which immediately
+                * 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.
+                */
+               num = (nptpages + 1) * (NPTEPG / SG4_LEV3SIZE);
+               pte = &((u_int *)kstpa)[SG4_LEV1SIZE];
+               epte = &pte[num];
+               protoste = kptpa | SG_U | SG_RW | SG_V;
+               while (pte < epte) {
+                       *pte++ = protoste;
+                       protoste += (SG4_LEV3SIZE * sizeof(struct ste));
+               }
+               /*
+                * Initialize level 1 descriptors.  We need:
+                *      roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE
+                * level 1 descriptors to map the `num' level 2's.
+                */
+               pte = (u_int *)kstpa;
+               epte = &pte[roundup(num, SG4_LEV2SIZE) / SG4_LEV2SIZE];
+               protoste = (u_int)&pte[SG4_LEV1SIZE] | SG_U | SG_RW | SG_V;
+               while (pte < epte) {
+                       *pte++ = protoste;
+                       protoste += (SG4_LEV2SIZE * sizeof(struct ste));
+               }
+               /*
+                * Initialize the final level 1 descriptor to map the last
+                * block of level 2 descriptors.
+                */
+               ste = &((u_int *)kstpa)[KERNELSTACK >> SG4_SHIFT1];
+               pte = &((u_int *)kstpa)[kstsize*NPTEPG - SG4_LEV2SIZE];
+               *ste = (u_int)pte | SG_U | SG_RW | SG_V;
+               /*
+                * Now initialize the final portion of that block of
+                * descriptors to map the "last PT page".
+                */
+               pte = &((u_int *)kstpa)[kstsize*NPTEPG - NPTEPG/SG4_LEV3SIZE];
+               epte = &pte[NPTEPG/SG4_LEV3SIZE];
+               protoste = lkptpa | SG_U | SG_RW | SG_V;
+               while (pte < epte) {
+                       *pte++ = protoste;
+                       protoste += (SG4_LEV3SIZE * sizeof(struct ste));
+               }
+               /*
+                * Initialize Sysptmap
+                */
+               pte = (u_int *)kptmpa;
+               epte = &pte[nptpages+1];
+               protopte = kptpa | PG_RW | PG_CI | PG_V;
+               while (pte < epte) {
+                       *pte++ = protopte;
+                       protopte += NBPG;
+               }
+               pte = &((u_int *)kptmpa)[KERNELSTACK>>SG_ISHIFT];
+               *pte = lkptpa | PG_RW | PG_CI | PG_V;
+       } else
+#endif
+       {
+               /*
+                * 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 +1.
+                */
+               ste = (u_int *)kstpa;
+               pte = (u_int *)kptmpa;
+               epte = &pte[nptpages+1];
+               protoste = kptpa | SG_RW | SG_V;
+               protopte = kptpa | PG_RW | PG_CI | PG_V;
+               while (pte < epte) {
+                       *ste++ = protoste;
+                       *pte++ = protopte;
+                       protoste += NBPG;
+                       protopte += NBPG;
+               }
+               /*
+                * Invalidate all entries.
+                */
+               epte = &((u_int *)kptmpa)[NPTEPG];
+               while (pte < epte) {
+                       *ste++ = SG_NV;
+                       *pte++ = PG_NV;
+               }
+               /* LUNA: Uarea pt map */
+               ste = (u_int *)kstpa;
+               pte = (u_int *)kptmpa;
+               ste[KERNELSTACK>>SG_ISHIFT] = lkptpa | SG_RW | SG_V;
+               pte[KERNELSTACK>>SG_ISHIFT] = lkptpa | PG_RW | PG_CI | PG_V;
        }
        }
-       /* LUNA: Uarea pt map */
-       ste = (u_int *)kstpa;
-       pte = (u_int *)kptmpa;
-       ste[KERNELSTACK>>SG_ISHIFT] = ukptpa | SG_RW | SG_V;
-       pte[KERNELSTACK>>SG_ISHIFT] = ukptpa | PG_RW | PG_CI | PG_V;
-
        /*
         * Invalidate all but the final entry in the last kernel PT page
         * (u-area PTEs will be validated later).  The final entry maps
         * the last page of physical memory.
         */
        /*
         * Invalidate all but the final entry in the last kernel PT page
         * (u-area PTEs will be validated later).  The final entry maps
         * the last page of physical memory.
         */
-       pte = (u_int *)ukptpa;
+       pte = (u_int *)lkptpa;
        epte = &pte[NPTEPG];
        while (pte < epte)
                *pte++ = PG_NV;
        epte = &pte[NPTEPG];
        while (pte < epte)
                *pte++ = PG_NV;
@@ -214,58 +298,17 @@ pmap_bootstrap(nextpa, firstpa)
         */
        epte = &((u_int *)kptpa)[luna_btop(nextpa - firstpa)];
        protopte = (protopte & ~PG_PROT) | PG_RW;
         */
        epte = &((u_int *)kptpa)[luna_btop(nextpa - firstpa)];
        protopte = (protopte & ~PG_PROT) | PG_RW;
+#if defined(LUNA2)
+       /*
+        * Enable copy-back caching of data pages
+        */
+       if (mmutype == MMU_68040)
+               protopte |= PG_CCB;
+#endif
        while (pte < epte) {
                *pte++ = protopte;
                protopte += NBPG;
        }
        while (pte < epte) {
                *pte++ = protopte;
                protopte += NBPG;
        }
-
-       /* initialize; all IO pte invalidate */
-       pte = (u_int *)iopa;
-       epte = &pte[IOPTPAGE * NPTEPG];
-       while (pte < epte)
-               *pte++ = PG_NV;
-       /*
-        * Here, we validate STEs and kernel page table PTEs
-        * for io space.
-        */
-       {
-           int index;
-
-           protoste = iopa | SG_RW | SG_V;
-           protopte = iopa | PG_RW | PG_CI | PG_V;
-           for (index = 0; io_physmap[index].pm_phys; index++)
-             {
-                 ste = &((u_int *)kstpa)[io_physmap[index].pm_phys/NBSEG];
-                 pte = &((u_int *)kptmpa)[io_physmap[index].pm_phys/NBSEG];
-                 *ste = protoste;
-                 *pte = protopte;
-                 protoste += NBPG;
-                 protopte += NBPG;
-             }
-           /*
-            * Finally, validate the IO space PTEs.
-            */
-           /* create io(and debbuger) PTEs */
-           for (index = 0; io_physmap[index].pm_phys; index++)
-             {
-                 pte = (u_int *)iopa + index*NPTEPG;
-                 epte = &pte[(luna_round_page(io_physmap[index].pm_size))>>PG_SHIFT];
-                 /* 
-                  * First entry(index == IO_DBG_OFF) is very special, 
-                  * we map debugger at fixed address(0x40000000).
-                  * Debugger is always loaded (maxmem+1) page.
-                  */
-                 protopte = (index == IO_DBG_OFF ? 
-                             ((maxmem+1)<<PG_SHIFT) : io_physmap[index].pm_phys) |
-                   PG_RW |(io_physmap[index].pm_cache == 0 ? PG_CI : 0) | PG_V;
-                 
-                 /* physical page setup loop */
-                 while (pte < epte) {
-                     *pte++ = protopte;
-                     protopte += NBPG;
-                 }
-             }
-       }
        /*
         * Calculate important exported kernel virtual addresses
         */
        /*
         * Calculate important exported kernel virtual addresses
         */
@@ -288,6 +331,7 @@ pmap_bootstrap(nextpa, firstpa)
         * LUNA: User stack address = 0x3ff00000.
         */
        Umap = (vm_offset_t)Sysmap + (LUNA_MAX_PTSIZE/4 - HIGHPAGES * sizeof(struct pte));
         * LUNA: User stack address = 0x3ff00000.
         */
        Umap = (vm_offset_t)Sysmap + (LUNA_MAX_PTSIZE/4 - HIGHPAGES * sizeof(struct pte));
+
        /*
         * Setup u-area for process 0.
         */
        /*
         * Setup u-area for process 0.
         */
@@ -296,7 +340,7 @@ pmap_bootstrap(nextpa, firstpa)
         * which are HIGHPAGES from the end of the last kernel PT page
         * allocated earlier.
         */
         * which are HIGHPAGES from the end of the last kernel PT page
         * allocated earlier.
         */
-       pte = &((u_int *)ukptpa)[NPTEPG - HIGHPAGES];
+       pte = &((u_int *)lkptpa)[NPTEPG - HIGHPAGES];
        epte = &pte[UPAGES];
        protopte = p0upa | PG_RW | PG_V;
        while (pte < epte) {
        epte = &pte[UPAGES];
        protopte = p0upa | PG_RW | PG_V;
        while (pte < epte) {
@@ -322,43 +366,30 @@ pmap_bootstrap(nextpa, firstpa)
         * the pmap module.
         */
        avail_start = nextpa;
         * the pmap module.
         */
        avail_start = nextpa;
-       avail_end = luna_ptob(maxmem);
-#if BSDVM_COMPAT
+       avail_end = luna_ptob(maxmem)
                        /* XXX allow for msgbuf */
                        /* XXX allow for msgbuf */
-                       - luna_round_page(sizeof(struct msgbuf))
-#endif
-                               ;
+                       - luna_round_page(sizeof(struct msgbuf));
        mem_size = luna_ptob(physmem);
        mem_size = luna_ptob(physmem);
-       virtual_avail = VM_MIN_KERNEL_ADDRESS + (nextpa - firstpa);
+       virtual_avail = VM_MIN_KERNEL_ADDRESS + (nextpa - firstpa);
        virtual_end = VM_MAX_KERNEL_ADDRESS;
        virtual_end = VM_MAX_KERNEL_ADDRESS;
-#if defined(DYNPGSIZE)
-       lunapagesperpage = 1;           /* XXX */
-#endif
+
        /*
         * Initialize protection array.
        /*
         * Initialize protection array.
+        * XXX don't use a switch statement, it might produce an
+        * absolute "jmp" table.
         */
        {
         */
        {
-               register int *kp, prot;
+               register int *kp;
 
                kp = protection_codes;
 
                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;
-                       }
-               }
+               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;
        }
 
        /*
        }
 
        /*
@@ -373,133 +404,47 @@ pmap_bootstrap(nextpa, firstpa)
                simple_lock_init(&kpm->pm_lock);
                kpm->pm_count = 1;
                kpm->pm_stpa = (struct ste *)kstpa;
                simple_lock_init(&kpm->pm_lock);
                kpm->pm_count = 1;
                kpm->pm_stpa = (struct ste *)kstpa;
+#if defined(LUNA2)
+               /*
+                * For the 040 we also initialize the free level 2
+                * descriptor mask noting that we have used:
+                *      0:              level 1 table
+                *      1 to `num':     map page tables
+                *      MAXKL2SIZE-1:   maps last-page page table
+                */
+               if (mmutype == MMU_68040) {
+                       register int num;
+                       
+                       kpm->pm_stfree = ~l2tobm(0);
+                       num = roundup((nptpages + 1) * (NPTEPG / SG4_LEV3SIZE),
+                                     SG4_LEV2SIZE) / SG4_LEV2SIZE;
+                       while (num)
+                               kpm->pm_stfree &= ~l2tobm(num--);
+                       kpm->pm_stfree &= ~l2tobm(MAXKL2SIZE-1);
+                       for (num = MAXKL2SIZE;
+                            num < sizeof(kpm->pm_stfree)*NBBY;
+                            num++)
+                               kpm->pm_stfree &= ~l2tobm(num);
+               }
+#endif
        }
 
        }
 
-#if BSDVM_COMPAT
-#define        SYSMAP(c, p, v, n) \
-       v = (c)va; va += ((n)*LUNA_PAGE_SIZE); \
-       p = (struct pte *)pte; pte += (n);
-
        /*
        /*
-        * Allocate all the submaps we need
+        * Allocate some fixed, special purpose kernel virtual addresses
         */
        {
                vm_offset_t va = virtual_avail;
 
         */
        {
                vm_offset_t va = virtual_avail;
 
-               pte = &Sysmap[luna_btop(va)];
-       
-               SYSMAP(caddr_t          ,CMAP1          ,CADDR1    ,1   )
-               SYSMAP(caddr_t          ,CMAP2          ,CADDR2    ,1   )
-               SYSMAP(caddr_t          ,mmap           ,vmmap     ,1   )
-               SYSMAP(struct msgbuf *  ,msgbufmap      ,msgbufp   ,1   )
-
+               CADDR1 = (caddr_t)va;
+               va += LUNA_PAGE_SIZE;
+               CADDR2 = (caddr_t)va;
+               va += LUNA_PAGE_SIZE;
+               vmmap = (caddr_t)va;
+               va += LUNA_PAGE_SIZE;
+               ledbase = (caddr_t)va;
+               va += LUNA_PAGE_SIZE;
+               msgbufp = (struct msgbuf *)va;
+               va += LUNA_PAGE_SIZE;
                virtual_avail = va;
        }
                virtual_avail = va;
        }
-#undef SYSMAP
-#endif
-}
-
-pmap_showstuff()
-{
-       int i;
-       printf("CADDR1=%x pte at CMAP1=%x\n", CADDR1, CMAP1);
-       printf("CADDR2=%x pte at CMAP2=%x\n", CADDR2, CMAP2);
-       printf("vmmap=%x pte at mmap=%x\n", vmmap, mmap);
-       printf("msgbufp=%x pte at msgbufmap=%x\n", msgbufp, msgbufmap);
-       printf("virtual_avail=%x, virtual_end=%x\n", virtual_avail, virtual_end);
-       for (i = 0; i < 8; i++)
-               printf("%x ", protection_codes[i]);
-       printf("\n");
 }
 }
-
-#ifdef BOOTDEBUG
-/*
- *     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
-Opmap_bootstrap(firstaddr, loadaddr)
-       vm_offset_t firstaddr;
-       vm_offset_t loadaddr;
-{
-#if BSDVM_COMPAT
-       vm_offset_t va;
-       struct pte *pte;
-#endif
-
-       avail_start = firstaddr;
-       avail_end = maxmem << PGSHIFT;
-
-#if BSDVM_COMPAT
-       /* XXX: allow for msgbuf */
-       avail_end -= luna_round_page(sizeof(struct msgbuf));
-#endif
-
-       mem_size = physmem << PGSHIFT;
-       virtual_avail = VM_MIN_KERNEL_ADDRESS + (firstaddr - loadaddr);
-       virtual_end = VM_MAX_KERNEL_ADDRESS;
-#if defined(DYNPGSIZE)
-       lunapagesperpage = PAGE_SIZE / LUNA_PAGE_SIZE;
-#endif
-       /*
-        * Initialize protection array.
-        */
-       {
-               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;
-                       }
-               }
-       }
-       /*
-        * Kernel page/segment table allocated in locore,
-        * just initialize pointers.
-        */
-       kernel_pmap->pm_stab = Sysseg;
-       kernel_pmap->pm_ptab = Sysmap;
-
-       simple_lock_init(&kernel_pmap->pm_lock);
-       kernel_pmap->pm_count = 1;
-
-#if BSDVM_COMPAT
-       /*
-        * Allocate all the submaps we need
-        */
-#define        SYSMAP(c, p, v, n)      \
-       v = (c)va; va += ((n)*LUNA_PAGE_SIZE); p = pte; pte += (n);
-
-       va = virtual_avail;
-       pte = &Sysmap[luna_btop(va)];
-
-       SYSMAP(caddr_t          ,CMAP1          ,CADDR1    ,1           )
-       SYSMAP(caddr_t          ,CMAP2          ,CADDR2    ,1           )
-       SYSMAP(caddr_t          ,mmap           ,vmmap     ,1           )
-       SYSMAP(struct msgbuf *  ,msgbufmap      ,msgbufp   ,1           )
-       virtual_avail = va;
-#undef SYSMAP
-#endif
-}
-#endif