1 /* 2 * Copyright (c) 1987 Carnegie-Mellon University 3 * Copyright (c) 1992 Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Ralph Campbell. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the University of 20 * California, Berkeley and its contributors. 21 * 4. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * from: @(#)pmap.h 7.6 (Berkeley) 2/4/93 38 * $Id: pmap.h,v 1.2 1993/10/15 02:57:13 deraadt Exp $ 39 */ 40 41 #ifndef _PMAP_MACHINE_ 42 #define _PMAP_MACHINE_ 43 44 /* 45 * TLB hash table values. 46 * SHIFT2 should shift virtual address bit 22 to the high bit of the index. 47 * address: index: 48 * USRTEXT 0x00400000 10xxxxxxx 49 * USRDATA 0x10000000 00xxxxxxx 50 * USRSTACK 0x7FFFFFFF 11xxxxxxx 51 * This gives 1/2 the table to data, 1/4 for text and 1/4 for stack. 52 * Note: the current process has its hash table mapped at PMAP_HASH_UADDR. 53 * the kernel's hash table is mapped at PMAP_HASH_KADDR. 54 * The size of the hash table is known in locore.s. 55 * The wired entries in the TLB will contain the following: 56 * UPAGES (for curproc) 57 * PMAP_HASH_UPAGES (for curproc) 58 * PMAP_HASH_KPAGES (for kernel) 59 * The kernel doesn't actually use a pmap_hash_t, the pm_hash field is NULL and 60 * all the PTE entries are stored in a single array at PMAP_HASH_KADDR. 61 * If we need more KPAGES that the TLB has wired entries, then we can switch 62 * to a global pointer for the kernel TLB table. 63 * If we try to use a hash table for the kernel, wired TLB entries become a 64 * problem. 65 * Note: PMAP_HASH_UPAGES should be a multiple of MACH pages (see pmap_enter()). 66 */ 67 #define PMAP_HASH_UPAGES 1 68 #define PMAP_HASH_KPAGES 5 69 #define PMAP_HASH_UADDR (UADDR - PMAP_HASH_UPAGES * NBPG) 70 #define PMAP_HASH_KADDR (UADDR - (PMAP_HASH_UPAGES + PMAP_HASH_KPAGES) * NBPG) 71 #define PMAP_HASH_NUM_ENTRIES 256 72 #define PMAP_HASH_SIZE_SHIFT 4 73 #define PMAP_HASH_SHIFT1 12 74 #define PMAP_HASH_SHIFT2 21 75 #define PMAP_HASH_MASK1 0x07f 76 #define PMAP_HASH_MASK2 0x080 77 #define PMAP_HASH_SIZE (PMAP_HASH_NUM_ENTRIES*sizeof(struct pmap_hash)) 78 79 /* compute pointer to pmap hash table */ 80 #define PMAP_HASH(va) \ 81 ((((va) >> PMAP_HASH_SHIFT1) & PMAP_HASH_MASK1) | \ 82 (((va) >> PMAP_HASH_SHIFT2) & PMAP_HASH_MASK2)) 83 84 /* 85 * A TLB hash entry. 86 */ 87 typedef struct pmap_hash { 88 struct { 89 u_int low; /* The TLB low register value. */ 90 u_int high; /* The TLB high register value. */ 91 } pmh_pte[2]; 92 } *pmap_hash_t; 93 94 /* 95 * Machine dependent pmap structure. 96 */ 97 struct pmap { 98 int pm_count; /* pmap reference count */ 99 simple_lock_data_t pm_lock; /* lock on pmap */ 100 struct pmap_statistics pm_stats; /* pmap statistics */ 101 int pm_flags; /* see below */ 102 int pm_tlbpid; /* address space tag */ 103 pmap_hash_t pm_hash; /* TLB cache */ 104 unsigned pm_hash_ptes[PMAP_HASH_UPAGES]; 105 }; 106 107 typedef struct pmap *pmap_t; 108 109 #define PM_MODIFIED 1 /* flush tlbpid before resume() */ 110 111 /* 112 * Defines for pmap_attributes[phys_mach_page]; 113 */ 114 #define PMAP_ATTR_MOD 0x01 /* page has been modified */ 115 #define PMAP_ATTR_REF 0x02 /* page has been referenced */ 116 117 #ifdef KERNEL 118 extern struct pmap kernel_pmap_store; 119 extern pmap_t kernel_pmap; 120 extern char *pmap_attributes; /* reference and modify bits */ 121 #endif KERNEL 122 #endif _PMAP_MACHINE_ 123