Annotation of Net2/arch/i386/include/pmap.h, revision 1.1.1.2

1.1       root        1: /* 
                      2:  * Copyright (c) 1991 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * the Systems Programming Group of the University of Utah Computer
                      7:  * Science Department and William Jolitz of UUNET Technologies Inc.
                      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:  *     @(#)pmap.h      7.4 (Berkeley) 5/12/91
                     38:  */
                     39: 
                     40: /*
                     41:  * Derived from hp300 version by Mike Hibler, this version by William
                     42:  * Jolitz uses a recursive map [a pde points to the page directory] to
                     43:  * map the page tables using the pagetables themselves. This is done to
                     44:  * reduce the impact on kernel virtual memory for lots of sparse address
                     45:  * space, and to reduce the cost of memory to each process.
                     46:  *
                     47:  * from hp300: @(#)pmap.h      7.2 (Berkeley) 12/16/90
                     48:  */
                     49: 
                     50: #ifndef        _PMAP_MACHINE_
                     51: #define        _PMAP_MACHINE_  1
                     52: 
                     53: /*
                     54:  * 386 page table entry and page table directory
                     55:  * W.Jolitz, 8/89
                     56:  */
                     57: 
                     58: struct pde
                     59: {
                     60: unsigned int   
                     61:                pd_v:1,                 /* valid bit */
                     62:                pd_prot:2,              /* access control */
                     63:                pd_mbz1:2,              /* reserved, must be zero */
                     64:                pd_u:1,                 /* hardware maintained 'used' bit */
                     65:                :1,                     /* not used */
                     66:                pd_mbz2:2,              /* reserved, must be zero */
                     67:                :3,                     /* reserved for software */
                     68:                pd_pfnum:20;            /* physical page frame number of pte's*/
                     69: };
                     70: 
                     71: #define        PD_MASK         0xffc00000      /* page directory address bits */
                     72: #define        PT_MASK         0x003ff000      /* page table address bits */
                     73: #define        PD_SHIFT        22              /* page directory address shift */
                     74: #define        PG_SHIFT        12              /* page table address shift */
                     75: 
                     76: struct pte
                     77: {
                     78: unsigned int   
                     79:                pg_v:1,                 /* valid bit */
                     80:                pg_prot:2,              /* access control */
                     81:                pg_mbz1:2,              /* reserved, must be zero */
                     82:                pg_u:1,                 /* hardware maintained 'used' bit */
                     83:                pg_m:1,                 /* hardware maintained modified bit */
                     84:                pg_mbz2:2,              /* reserved, must be zero */
                     85:                pg_w:1,                 /* software, wired down page */
                     86:                :1,                     /* software (unused) */
                     87:                pg_nc:1,                /* 'uncacheable page' bit */
                     88:                pg_pfnum:20;            /* physical page frame number */
                     89: };
                     90: 
                     91: #define        PG_V            0x00000001
                     92: #define        PG_RO           0x00000000
                     93: #define        PG_RW           0x00000002
                     94: #define        PG_u            0x00000004
                     95: #define        PG_PROT         0x00000006 /* all protection bits . */
                     96: #define        PG_W            0x00000200
                     97: #define PG_N           0x00000800 /* Non-cacheable */
                     98: #define        PG_M            0x00000040
                     99: #define PG_U           0x00000020
                    100: #define        PG_FRAME        0xfffff000
                    101: 
                    102: #define        PG_NOACC        0
                    103: #define        PG_KR           0x00000000
                    104: #define        PG_KW           0x00000002
                    105: #define        PG_URKR         0x00000004
                    106: #define        PG_URKW         0x00000004
                    107: #define        PG_UW           0x00000006
                    108: 
                    109: /* Garbage for current bastardized pager that assumes a hp300 */
                    110: #define        PG_NV   0
                    111: #define        PG_CI   0
                    112: /*
                    113:  * Page Protection Exception bits
                    114:  */
                    115: 
                    116: #define PGEX_P         0x01    /* Protection violation vs. not present */
                    117: #define PGEX_W         0x02    /* during a Write cycle */
                    118: #define PGEX_U         0x04    /* access from User mode (UPL) */
                    119: 
                    120: typedef struct pde     pd_entry_t;     /* page directory entry */
                    121: typedef struct pte     pt_entry_t;     /* Mach page table entry */
                    122: 
                    123: /*
                    124:  * One page directory, shared between
                    125:  * kernel and user modes.
                    126:  */
                    127: #define I386_PAGE_SIZE NBPG
                    128: #define I386_PDR_SIZE  NBPDR
                    129: 
                    130: #define I386_KPDES     8 /* KPT page directory size */
                    131: #define I386_UPDES     NBPDR/sizeof(struct pde)-8 /* UPT page directory size */
                    132: 
                    133: #define        UPTDI           0x3f6           /* ptd entry for u./kernel&user stack */
                    134: #define        PTDPTDI         0x3f7           /* ptd entry that points to ptd! */
                    135: #define        KPTDI_FIRST     0x3f8           /* start of kernel virtual pde's */
                    136: #define        KPTDI_LAST      0x3fA           /* last of kernel virtual pde's */
                    137: 
                    138: /*
                    139:  * Address of current and alternate address space page table maps
                    140:  * and directories.
                    141:  */
                    142: #ifdef KERNEL
                    143: extern struct pte      PTmap[], APTmap[], Upte;
                    144: extern struct pde      PTD[], APTD[], PTDpde, APTDpde, Upde;
                    145: extern pt_entry_t      *Sysmap;
                    146: 
                    147: extern int     IdlePTD;        /* physical address of "Idle" state directory */
                    148: #endif
                    149: 
                    150: /*
                    151:  * virtual address to page table entry and
                    152:  * to physical address. Likewise for alternate address space.
                    153:  * Note: these work recursively, thus vtopte of a pte will give
                    154:  * the corresponding pde that in turn maps it.
                    155:  */
                    156: #define        vtopte(va)      (PTmap + i386_btop(va))
                    157: #define        kvtopte(va)     vtopte(va)
                    158: #define        ptetov(pt)      (i386_ptob(pt - PTmap)) 
                    159: #define        vtophys(va)  (i386_ptob(vtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
                    160: #define ispt(va)       ((va) >= UPT_MIN_ADDRESS && (va) <= KPT_MAX_ADDRESS)
                    161: 
                    162: #define        avtopte(va)     (APTmap + i386_btop(va))
                    163: #define        ptetoav(pt)     (i386_ptob(pt - APTmap)) 
                    164: #define        avtophys(va)  (i386_ptob(avtopte(va)->pg_pfnum) | ((int)(va) & PGOFSET))
                    165: 
                    166: /*
                    167:  * macros to generate page directory/table indicies
                    168:  */
                    169: 
                    170: #define        pdei(va)        (((va)&PD_MASK)>>PD_SHIFT)
1.1.1.2 ! root      171: #define        ptei(va)        (((va)&PT_MASK)>>PG_SHIFT)
1.1       root      172: 
                    173: /*
                    174:  * Pmap stuff
                    175:  */
                    176: 
                    177: struct pmap {
                    178:        pd_entry_t              *pm_pdir;       /* KVA of page directory */
                    179:        boolean_t               pm_pdchanged;   /* pdir changed */
                    180:        short                   pm_dref;        /* page directory ref count */
                    181:        short                   pm_count;       /* pmap reference count */
                    182:        simple_lock_data_t      pm_lock;        /* lock on pmap */
                    183:        struct pmap_statistics  pm_stats;       /* pmap statistics */
                    184:        long                    pm_ptpages;     /* more stats: PT pages */
                    185: };
                    186: 
                    187: typedef struct pmap    *pmap_t;
                    188: 
                    189: #ifdef KERNEL
                    190: extern pmap_t          kernel_pmap;
                    191: #endif
                    192: 
                    193: /*
                    194:  * Macros for speed
                    195:  */
                    196: #define PMAP_ACTIVATE(pmapp, pcbp) \
                    197:        if ((pmapp) != NULL /*&& (pmapp)->pm_pdchanged */) {  \
                    198:                (pcbp)->pcb_cr3 = \
                    199:                    pmap_extract(kernel_pmap, (pmapp)->pm_pdir); \
                    200:                if ((pmapp) == &curproc->p_vmspace->vm_pmap) \
                    201:                        load_cr3((pcbp)->pcb_cr3); \
                    202:                (pmapp)->pm_pdchanged = FALSE; \
                    203:        }
                    204: 
                    205: #define PMAP_DEACTIVATE(pmapp, pcbp)
                    206: 
                    207: /*
                    208:  * For each vm_page_t, there is a list of all currently valid virtual
                    209:  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
                    210:  */
                    211: typedef struct pv_entry {
                    212:        struct pv_entry *pv_next;       /* next pv_entry */
                    213:        pmap_t          pv_pmap;        /* pmap where mapping lies */
                    214:        vm_offset_t     pv_va;          /* virtual address for mapping */
                    215:        int             pv_flags;       /* flags */
                    216: } *pv_entry_t;
                    217: 
                    218: #define        PV_ENTRY_NULL   ((pv_entry_t) 0)
                    219: 
                    220: #define        PV_CI           0x01    /* all entries must be cache inhibited */
                    221: #define PV_PTPAGE      0x02    /* entry maps a page table page */
                    222: 
                    223: #ifdef KERNEL
                    224: 
                    225: pv_entry_t     pv_table;               /* array of entries, one per page */
                    226: 
                    227: #define pa_index(pa)           atop(pa - vm_first_phys)
                    228: #define pa_to_pvh(pa)          (&pv_table[pa_index(pa)])
                    229: 
                    230: #define        pmap_resident_count(pmap)       ((pmap)->pm_stats.resident_count)
                    231: 
                    232: #endif KERNEL
                    233: 
                    234: #endif _PMAP_MACHINE_

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.