📄 pmap_bootstrap.c
字号:
/* * 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. * * 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. * * @(#)pmap_bootstrap.c 8.1 (Berkeley) 6/10/93 */#include <sys/param.h>#include <sys/msgbuf.h>#include <hp300/hp300/pte.h>#include <hp300/hp300/clockreg.h>#include <machine/vmparam.h>#include <machine/cpu.h>#include <vm/vm.h>#define RELOC(v, t) *((t*)((u_int)&(v) + firstpa))extern char *etext;extern int Sysptsize;extern char *extiobase, *proc0paddr;extern struct ste *Sysseg;extern struct pte *Sysptmap, *Sysmap;extern vm_offset_t Umap, CLKbase, MMUbase;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[];#ifdef HAVEVACextern int pmap_aliasmask;#endif/* * 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 */caddr_t CADDR1, CADDR2, vmmap, ledbase;struct msgbuf *msgbufp;/* * Bootstrap the VM system. * * Called with MMU off so we must relocate all global references by `firstpa' * (don't call any functions here!) `nextpa' is the first available physical * memory address. Returns an updated first PA reflecting the memory we * have allocated. MMU is still off when we return. * * XXX assumes sizeof(u_int) == sizeof(struct pte) * XXX a PIC compiler would make this much easier. */voidpmap_bootstrap(nextpa, firstpa) vm_offset_t nextpa; register vm_offset_t firstpa;{ vm_offset_t kstpa, kptpa, iiopa, eiopa, kptmpa, lkptpa, p0upa; u_int nptpages, kstsize; register u_int protoste, protopte, *ste, *pte, *epte; /* * Calculate important physical addresses: * * kstpa kernel segment table 1 page (!040) * N pages (040) * * kptpa statically allocated * kernel PT pages Sysptsize+ pages * * iiopa internal IO space * PT pages IIOMAPSIZE pages * * eiopa external IO space * PT pages EIOMAPSIZE pages * * [ Sysptsize is the number of pages of PT, IIOMAPSIZE and * EIOMAPSIZE are the number of PTEs, hence we need to round * the total to a page boundary with IO maps at the end. ] * * 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). */ if (RELOC(mmutype, int) == MMU_68040) kstsize = MAXKL2SIZE / (NPTEPG/SG4_LEV2SIZE); else kstsize = 1; kstpa = nextpa; nextpa += kstsize * NBPG; kptpa = nextpa; nptpages = RELOC(Sysptsize, int) + (IIOMAPSIZE + EIOMAPSIZE + NPTEPG - 1) / NPTEPG; nextpa += nptpages * NBPG; eiopa = nextpa - EIOMAPSIZE * sizeof(struct pte); iiopa = eiopa - IIOMAPSIZE * sizeof(struct pte); kptmpa = nextpa; nextpa += NBPG; lkptpa = nextpa; nextpa += NBPG; p0upa = nextpa; nextpa += UPAGES * NBPG; /* * Initialize segment table and kernel page table map. * * On 68030s and earlier MMUs the two are identical except for * the valid bits so both are initialized with essentially the * 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 (0xFFF00000 - * 0xFFFFFFFF) are mapped for a couple of purposes. 0xFFF00000 * for UPAGES is used for mapping the current process u-area * (u + kernel stack). The very last page (0xFFFFF000) 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). */ if (RELOC(mmutype, int) == 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)[SG4_LEV1SIZE-1]; 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)[NPTEPG-1]; *pte = lkptpa | PG_RW | PG_CI | PG_V; } else { /* * 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -