Home | History | Annotate | Line # | Download | only in include
pte.h revision 1.23.2.1
      1  1.23.2.1  thorpej /*	$NetBSD: pte.h,v 1.23.2.1 2002/01/10 19:48:54 thorpej Exp $ */
      2       1.7  deraadt 
      3       1.1  deraadt /*
      4      1.15       pk  * Copyright (c) 1996
      5      1.17   abrown  * 	The President and Fellows of Harvard College. All rights reserved.
      6       1.1  deraadt  * Copyright (c) 1992, 1993
      7       1.1  deraadt  *	The Regents of the University of California.  All rights reserved.
      8       1.1  deraadt  *
      9       1.1  deraadt  * This software was developed by the Computer Systems Engineering group
     10       1.1  deraadt  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     11       1.1  deraadt  * contributed to Berkeley.
     12       1.1  deraadt  *
     13       1.1  deraadt  * All advertising materials mentioning features or use of this software
     14      1.15       pk  * must display the following acknowledgements:
     15      1.15       pk  * 	This product includes software developed by Harvard University.
     16       1.1  deraadt  *	This product includes software developed by the University of
     17       1.1  deraadt  *	California, Lawrence Berkeley Laboratory.
     18       1.1  deraadt  *
     19       1.1  deraadt  * Redistribution and use in source and binary forms, with or without
     20       1.1  deraadt  * modification, are permitted provided that the following conditions
     21       1.1  deraadt  * are met:
     22       1.1  deraadt  * 1. Redistributions of source code must retain the above copyright
     23       1.1  deraadt  *    notice, this list of conditions and the following disclaimer.
     24       1.1  deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     25       1.1  deraadt  *    notice, this list of conditions and the following disclaimer in the
     26       1.1  deraadt  *    documentation and/or other materials provided with the distribution.
     27       1.1  deraadt  * 3. All advertising materials mentioning features or use of this software
     28      1.15       pk  *    must display the following acknowledgements:
     29      1.15       pk  *	This product includes software developed by Harvard University.
     30       1.1  deraadt  *	This product includes software developed by the University of
     31       1.1  deraadt  *	California, Berkeley and its contributors.
     32       1.1  deraadt  * 4. Neither the name of the University nor the names of its contributors
     33       1.1  deraadt  *    may be used to endorse or promote products derived from this software
     34       1.1  deraadt  *    without specific prior written permission.
     35       1.1  deraadt  *
     36       1.1  deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     37       1.1  deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     38       1.1  deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     39       1.1  deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     40       1.1  deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     41       1.1  deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     42       1.1  deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     43       1.1  deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     44       1.1  deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     45       1.1  deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     46       1.1  deraadt  * SUCH DAMAGE.
     47       1.1  deraadt  *
     48       1.1  deraadt  *	@(#)pte.h	8.1 (Berkeley) 6/11/93
     49       1.1  deraadt  */
     50  1.23.2.1  thorpej 
     51  1.23.2.1  thorpej #if defined(_KERNEL_OPT)
     52  1.23.2.1  thorpej #include "opt_sparc_arch.h"
     53  1.23.2.1  thorpej #endif
     54       1.1  deraadt 
     55       1.1  deraadt /*
     56      1.15       pk  * Sun-4 (sort of), 4c (SparcStation), and 4m Page Table Entries
     57      1.15       pk  * (Sun calls them `Page Map Entries').
     58       1.1  deraadt  */
     59       1.1  deraadt 
     60      1.13  mycroft #ifndef _LOCORE
     61       1.1  deraadt /*
     62       1.1  deraadt  * Segment maps contain `pmeg' (Page Map Entry Group) numbers.
     63       1.1  deraadt  * A PMEG is simply an index that names a group of 32 (sun4) or
     64       1.1  deraadt  * 64 (sun4c) PTEs.
     65       1.9       pk  * Depending on the CPU model, we need 7 (sun4c) to 10 (sun4/400) bits
     66       1.9       pk  * to hold the hardware MMU resource number.
     67       1.1  deraadt  */
     68       1.9       pk typedef u_short pmeg_t;		/* 10 bits needed per Sun-4 segmap entry */
     69       1.8       pk /*
     70       1.8       pk  * Region maps contain `smeg' (Segment Entry Group) numbers.
     71       1.9       pk  * An SMEG is simply an index that names a group of 64 PMEGs.
     72       1.8       pk  */
     73       1.9       pk typedef u_char smeg_t;		/* 8 bits needed per Sun-4 regmap entry */
     74       1.1  deraadt #endif
     75       1.1  deraadt 
     76       1.1  deraadt /*
     77       1.1  deraadt  * Address translation works as follows:
     78       1.1  deraadt  *
     79       1.8       pk  * (for sun4c and 2-level sun4)
     80       1.1  deraadt  *	1. test va<31:29> -- these must be 000 or 111 (or you get a fault)
     81       1.1  deraadt  *	2. concatenate context_reg<2:0> and va<29:18> to get a 15 bit number;
     82       1.8       pk  *	   use this to index the segment maps, yielding a 7 or 9 bit value.
     83       1.8       pk  * (for 3-level sun4)
     84       1.8       pk  *	1. concatenate context_reg<3:0> and va<31:24> to get a 8 bit number;
     85       1.8       pk  *	   use this to index the region maps, yielding a 10 bit value.
     86       1.8       pk  *	2. take the value from (1) above and concatenate va<17:12> to
     87       1.8       pk  *	   get a `segment map entry' index.  This gives a 9 bit value.
     88       1.1  deraadt  * (for sun4c)
     89       1.1  deraadt  *	3. take the value from (2) above and concatenate va<17:12> to
     90       1.1  deraadt  *	   get a `page map entry' index.  This gives a 32-bit PTE.
     91       1.1  deraadt  * (for sun4)
     92       1.8       pk  *	3. take the value from (2 or 3) above and concatenate va<17:13> to
     93       1.1  deraadt  *	   get a `page map entry' index.  This gives a 32-bit PTE.
     94      1.15       pk  **
     95      1.15       pk  * For sun4m:
     96      1.15       pk  *	1. Use context_reg<3:0> to index the context table (located at
     97      1.15       pk  *	   (context_reg << 2) | ((ctx_tbl_ptr_reg >> 2) << 6) ). This
     98      1.15       pk  *	   gives a 32-bit page-table-descriptor (PTP).
     99      1.15       pk  *	2. Use va<31:24> to index the region table located by the PTP from (1):
    100      1.15       pk  *	   PTP<31:6> << 10. This gives another PTP for the segment tables
    101      1.15       pk  *	3. Use va<23:18> to index the segment table located by the PTP from (2)
    102      1.15       pk  *	   as follows: PTP<31:4> << 8. This gives another PTP for the page tbl.
    103      1.15       pk  * 	4. Use va<17:12> to index the page table given by (3)'s PTP:
    104      1.15       pk  * 	   PTP<31:4> << 8. This gives a 32-bit PTE.
    105       1.1  deraadt  *
    106       1.1  deraadt  * In other words:
    107       1.1  deraadt  *
    108       1.8       pk  *	struct sun4_3_levelmmu_virtual_addr {
    109       1.8       pk  *		u_int	va_reg:8,	(virtual region)
    110       1.8       pk  *			va_seg:6,	(virtual segment)
    111       1.8       pk  *			va_pg:5,	(virtual page within segment)
    112       1.8       pk  *			va_off:13;	(offset within page)
    113       1.8       pk  *	};
    114       1.1  deraadt  *	struct sun4_virtual_addr {
    115       1.1  deraadt  *		u_int	:2,		(required to be the same as bit 29)
    116       1.1  deraadt  *			va_seg:12,	(virtual segment)
    117       1.1  deraadt  *			va_pg:5,	(virtual page within segment)
    118       1.1  deraadt  *			va_off:13;	(offset within page)
    119       1.1  deraadt  *	};
    120       1.1  deraadt  *	struct sun4c_virtual_addr {
    121       1.1  deraadt  *		u_int	:2,		(required to be the same as bit 29)
    122       1.1  deraadt  *			va_seg:12,	(virtual segment)
    123       1.1  deraadt  *			va_pg:6,	(virtual page within segment)
    124       1.1  deraadt  *			va_off:12;	(offset within page)
    125       1.1  deraadt  *	};
    126       1.1  deraadt  *
    127      1.15       pk  *	struct sun4m_virtual_addr {
    128      1.15       pk  *		u_int	va_reg:8,	(virtual region)
    129      1.15       pk  *			va_seg:6,	(virtual segment within region)
    130      1.15       pk  *			va_pg:6,	(virtual page within segment)
    131      1.15       pk  *			va_off:12;	(offset within page)
    132      1.15       pk  *	};
    133      1.15       pk  *
    134       1.1  deraadt  * Then, given any `va':
    135       1.1  deraadt  *
    136       1.8       pk  *	extern smeg_t regmap[16][1<<8];		(3-level MMU only)
    137       1.1  deraadt  *	extern pmeg_t segmap[8][1<<12];		([16][1<<12] for sun4)
    138       1.1  deraadt  *	extern int ptetable[128][1<<6];		([512][1<<5] for sun4)
    139       1.1  deraadt  *
    140      1.15       pk  *	extern u_int  s4m_ctxmap[16];		(sun4m SRMMU only)
    141      1.15       pk  *	extern u_int  s4m_regmap[16][1<<8];	(sun4m SRMMU only)
    142      1.15       pk  * 	extern u_int  s4m_segmap[1<<8][1<<6];	(sun4m SRMMU only)
    143      1.15       pk  * 	extern u_int  s4m_pagmap[1<<14][1<<6];	(sun4m SRMMU only)
    144      1.15       pk  *
    145      1.15       pk  * (the above being in the hardware, accessed as Alternate Address Spaces on
    146      1.15       pk  *  all machines but the Sun4m SRMMU, in which case the tables are in physical
    147      1.15       pk  *  kernel memory. In the 4m architecture, the tables are not layed out as
    148      1.15       pk  *  2-dim arrays, but are sparsely allocated as needed, and point to each
    149      1.15       pk  *  other.)
    150      1.15       pk  *
    151      1.15       pk  *	if (cputyp==CPU_SUN4M) 		// SPARC Reference MMU
    152      1.15       pk  *		regptp = s4m_ctxmap[curr_ctx];
    153      1.15       pk  *		if (!(regptp & SRMMU_TEPTD)) TRAP();
    154      1.15       pk  *		segptp = *(u_int *)(((regptp & ~0x3) << 4) | va.va_reg);
    155      1.15       pk  *		if (!(segptp & SRMMU_TEPTD)) TRAP();
    156      1.15       pk  *		pagptp = *(u_int *)(((segptp & ~0x3) << 4) | va.va_seg);
    157      1.15       pk  *		if (!(pagptp & SRMMU_TEPTD)) TRAP();
    158      1.15       pk  *		pte = *(u_int *)(((pagptp & ~0x3) << 4) | va.va_pg);
    159      1.15       pk  *		if (!(pte & SRMMU_TEPTE)) TRAP();       // like PG_V
    160      1.15       pk  * 		if (usermode && PTE_PROT_LEVEL(pte) > 0x5) TRAP();
    161      1.15       pk  *		if (writing && !PTE_PROT_LEVEL_ALLOWS_WRITING(pte)) TRAP();
    162      1.15       pk  *		if (!(pte & SRMMU_PG_C)) DO_NOT_USE_CACHE_FOR_THIS_ACCESS();
    163      1.15       pk  *		pte |= SRMMU_PG_U;
    164      1.15       pk  * 		if (writing) pte |= PG_M;
    165      1.15       pk  * 		physaddr = ((pte & SRMMU_PG_PFNUM) << SRMMU_PGSHIFT)|va.va_off;
    166      1.15       pk  *		return;
    167       1.8       pk  *	if (mmu_3l)
    168       1.8       pk  *		physreg = regmap[curr_ctx][va.va_reg];
    169       1.8       pk  *		physseg = segmap[physreg][va.va_seg];
    170       1.8       pk  *	else
    171       1.8       pk  *		physseg = segmap[curr_ctx][va.va_seg];
    172       1.1  deraadt  *	pte = ptetable[physseg][va.va_pg];
    173       1.1  deraadt  *	if (!(pte & PG_V)) TRAP();
    174       1.1  deraadt  *	if (writing && !pte.pg_w) TRAP();
    175       1.1  deraadt  *	if (usermode && pte.pg_s) TRAP();
    176       1.1  deraadt  *	if (pte & PG_NC) DO_NOT_USE_CACHE_FOR_THIS_ACCESS();
    177       1.1  deraadt  *	pte |= PG_U;					(mark used/accessed)
    178       1.1  deraadt  *	if (writing) pte |= PG_M;			(mark modified)
    179       1.1  deraadt  *	ptetable[physseg][va.va_pg] = pte;
    180       1.1  deraadt  *	physadr = ((pte & PG_PFNUM) << PGSHIFT) | va.va_off;
    181       1.1  deraadt  */
    182       1.1  deraadt 
    183      1.18       pk #if defined(SUN4_MMU3L) && !defined(SUN4)
    184       1.8       pk #error "configuration error"
    185       1.8       pk #endif
    186       1.8       pk 
    187      1.12       pk #define	NBPRG	(1 << 24)	/* bytes per region */
    188      1.12       pk #define	RGSHIFT	24		/* log2(NBPRG) */
    189      1.12       pk #define	RGOFSET	(NBPRG - 1)	/* mask for region offset */
    190       1.8       pk #define NSEGRG	(NBPRG / NBPSG)	/* segments per region */
    191       1.8       pk 
    192       1.1  deraadt #define	NBPSG	(1 << 18)	/* bytes per segment */
    193       1.1  deraadt #define	SGSHIFT	18		/* log2(NBPSG) */
    194       1.1  deraadt #define	SGOFSET	(NBPSG - 1)	/* mask for segment offset */
    195       1.1  deraadt 
    196       1.1  deraadt /* number of PTEs that map one segment (not number that fit in one segment!) */
    197      1.15       pk #if defined(SUN4) && (defined(SUN4C) || defined(SUN4M))
    198       1.2  deraadt extern int nptesg;
    199       1.4  deraadt #define	NPTESG	nptesg		/* (which someone will have to initialize) */
    200       1.1  deraadt #else
    201       1.1  deraadt #define	NPTESG	(NBPSG / NBPG)
    202       1.1  deraadt #endif
    203       1.1  deraadt 
    204       1.8       pk /* virtual address to virtual region number */
    205       1.8       pk #define	VA_VREG(va)	(((unsigned int)(va) >> RGSHIFT) & 255)
    206       1.8       pk 
    207       1.1  deraadt /* virtual address to virtual segment number */
    208       1.8       pk #define	VA_VSEG(va)	(((unsigned int)(va) >> SGSHIFT) & 63)
    209       1.1  deraadt 
    210       1.1  deraadt /* virtual address to virtual page number, for Sun-4 and Sun-4c */
    211       1.1  deraadt #define	VA_SUN4_VPG(va)		(((int)(va) >> 13) & 31)
    212       1.1  deraadt #define	VA_SUN4C_VPG(va)	(((int)(va) >> 12) & 63)
    213      1.15       pk #define VA_SUN4M_VPG(va)	(((int)(va) >> 12) & 63)
    214      1.15       pk 
    215      1.15       pk /* virtual address to offset within page */
    216      1.15       pk #define VA_SUN4_OFF(va)       	(((int)(va)) & 0x1FFF)
    217      1.15       pk #define VA_SUN4C_OFF(va)     	(((int)(va)) & 0xFFF)
    218      1.15       pk #define VA_SUN4M_OFF(va)	(((int)(va)) & 0xFFF)
    219       1.1  deraadt 
    220       1.8       pk /* truncate virtual address to region base */
    221       1.8       pk #define	VA_ROUNDDOWNTOREG(va)	((int)(va) & ~RGOFSET)
    222       1.8       pk 
    223       1.1  deraadt /* truncate virtual address to segment base */
    224       1.1  deraadt #define	VA_ROUNDDOWNTOSEG(va)	((int)(va) & ~SGOFSET)
    225       1.1  deraadt 
    226       1.8       pk /* virtual segment to virtual address (must sign extend on holy MMUs!) */
    227      1.18       pk #define	VRTOVA(vr)	((CPU_ISSUN4M || HASSUN4_MMU3L)	\
    228      1.18       pk 	? ((int)(vr) << RGSHIFT)			\
    229       1.8       pk 	: (((int)(vr) << (RGSHIFT+2)) >> 2))
    230      1.18       pk #define	VSTOVA(vr,vs)	((CPU_ISSUN4M || HASSUN4_MMU3L)	\
    231      1.15       pk 	? (((int)(vr) << RGSHIFT) + ((int)(vs) << SGSHIFT))	\
    232      1.15       pk 	: ((((int)(vr) << (RGSHIFT+2)) >> 2) + ((int)(vs) << SGSHIFT)))
    233       1.1  deraadt 
    234       1.9       pk extern int mmu_has_hole;
    235       1.9       pk #define VA_INHOLE(va)	(mmu_has_hole \
    236       1.9       pk 	? ( (unsigned int)(((int)(va) >> PG_VSHIFT) + 1) > 1) \
    237       1.9       pk 	: 0)
    238       1.9       pk 
    239       1.9       pk /* Define the virtual address space hole */
    240       1.9       pk #define MMU_HOLE_START	0x20000000
    241       1.9       pk #define MMU_HOLE_END	0xe0000000
    242       1.9       pk 
    243      1.15       pk #if defined(SUN4M)		/* Optimization: sun4m, sun4c have same page */
    244      1.15       pk #if defined(SUN4)		/* size, so they're used interchangeably */
    245      1.15       pk #define VA_VPG(va)	(cputyp==CPU_SUN4 ? VA_SUN4_VPG(va) : VA_SUN4C_VPG(va))
    246      1.19       pk #define VA_OFF(va)	(cputyp==CPU_SUN4 ? VA_SUN4_OFF(va) : VA_SUN4C_OFF(va))
    247      1.15       pk #else
    248      1.15       pk #define VA_VPG(va)	VA_SUN4M_VPG(va)
    249      1.15       pk #define VA_OFF(va)	VA_SUN4M_OFF(va)
    250      1.15       pk #endif /* defined SUN4 */
    251      1.15       pk #else /* 4m not defined */
    252       1.4  deraadt #if defined(SUN4) && defined(SUN4C)
    253       1.4  deraadt #define VA_VPG(va)	(cputyp==CPU_SUN4C ? VA_SUN4C_VPG(va) : VA_SUN4_VPG(va))
    254      1.15       pk #define VA_OFF(va)	(cputyp==CPU_SUN4C ? VA_SUN4C_OFF(va) : VA_SUN4_OFF(va))
    255       1.4  deraadt #endif
    256       1.4  deraadt #if defined(SUN4C) && !defined(SUN4)
    257       1.4  deraadt #define VA_VPG(va)	VA_SUN4C_VPG(va)
    258      1.15       pk #define VA_OFF(va)	VA_SUN4C_OFF(va)
    259       1.1  deraadt #endif
    260       1.4  deraadt #if !defined(SUN4C) && defined(SUN4)
    261       1.4  deraadt #define	VA_VPG(va)	VA_SUN4_VPG(va)
    262      1.15       pk #define VA_OFF(va)	VA_SUN4_OFF(va)
    263       1.1  deraadt #endif
    264      1.15       pk #endif /* defined 4m */
    265       1.1  deraadt 
    266      1.15       pk /* there is no `struct pte'; we just use `int'; this is for non-4M only */
    267       1.1  deraadt #define	PG_V		0x80000000
    268       1.1  deraadt #define	PG_PROT		0x60000000	/* both protection bits */
    269       1.1  deraadt #define	PG_W		0x40000000	/* allowed to write */
    270       1.1  deraadt #define	PG_S		0x20000000	/* supervisor only */
    271       1.1  deraadt #define	PG_NC		0x10000000	/* non-cacheable */
    272       1.1  deraadt #define	PG_TYPE		0x0c000000	/* both type bits */
    273       1.1  deraadt 
    274       1.1  deraadt #define	PG_OBMEM	0x00000000	/* on board memory */
    275       1.1  deraadt #define	PG_OBIO		0x04000000	/* on board I/O (incl. Sbus on 4c) */
    276       1.1  deraadt #define	PG_VME16	0x08000000	/* 16-bit-data VME space */
    277       1.1  deraadt #define	PG_VME32	0x0c000000	/* 32-bit-data VME space */
    278      1.15       pk #if defined(SUN4M)
    279      1.15       pk #define PG_SUN4M_OBMEM	0x0	       	/* No type bits=>obmem on 4m */
    280      1.15       pk #define PG_SUN4M_OBIO	0xf		/* obio maps to 0xf on 4M */
    281      1.15       pk #define SRMMU_PGTYPE	0xf0000000	/* Top 4 bits of pte PPN give type */
    282       1.1  deraadt #endif
    283       1.1  deraadt 
    284       1.1  deraadt #define	PG_U		0x02000000
    285       1.1  deraadt #define	PG_M		0x01000000
    286      1.15       pk #define PG_IOC		0x00800000
    287      1.11       pk #define	PG_MBZ		0x00780000	/* unused; must be zero (oh really?) */
    288       1.1  deraadt #define	PG_PFNUM	0x0007ffff	/* n.b.: only 16 bits on sun4c */
    289       1.1  deraadt 
    290       1.1  deraadt #define	PG_TNC_SHIFT	26		/* shift to get PG_TYPE + PG_NC */
    291       1.1  deraadt #define	PG_M_SHIFT	24		/* shift to get PG_M, PG_U */
    292      1.15       pk #define PG_M_SHIFT4M	5		/* shift to get SRMMU_PG_M,R on 4m */
    293       1.1  deraadt /*efine	PG_NOACC	0		** XXX */
    294       1.1  deraadt #define	PG_KR		0x20000000
    295       1.1  deraadt #define	PG_KW		0x60000000
    296       1.1  deraadt #define	PG_URKR		0
    297       1.1  deraadt #define	PG_UW		0x40000000
    298       1.1  deraadt 
    299       1.1  deraadt #ifdef KGDB
    300       1.1  deraadt /* but we will define one for gdb anyway */
    301       1.1  deraadt struct pte {
    302       1.1  deraadt 	u_int	pg_v:1,
    303       1.1  deraadt 		pg_w:1,
    304       1.1  deraadt 		pg_s:1,
    305       1.1  deraadt 		pg_nc:1;
    306       1.1  deraadt 	enum pgtype { pg_obmem, pg_obio, pg_vme16, pg_vme32 } pg_type:2;
    307       1.1  deraadt 	u_int	pg_u:1,
    308       1.1  deraadt 		pg_m:1,
    309       1.1  deraadt 		pg_mbz:5,
    310       1.1  deraadt 		pg_pfnum:19;
    311       1.1  deraadt };
    312      1.15       pk #if defined(SUN4M)
    313      1.15       pk struct srmmu_pte {
    314      1.15       pk 	u_int	pg_pfnum:20,
    315      1.15       pk 		pg_c:1,
    316      1.15       pk 		pg_m:1,
    317      1.15       pk 		pg_u:1;
    318      1.15       pk 	enum pgprot { pprot_r_r, pprot_rw_rw, pprot_rx_rx, pprot_rwx_rwx,
    319      1.15       pk 		      pprot_x_x, pprot_r_rw, pprot_n_rx, pprot_n_rwx }
    320      1.15       pk 		pg_prot:3;	/* prot. bits: pprot_<user>_<supervisor> */
    321      1.15       pk 	u_int	pg_must_be_2:2;
    322      1.15       pk };
    323      1.15       pk #endif
    324       1.1  deraadt #endif
    325       1.1  deraadt 
    326       1.1  deraadt /*
    327       1.1  deraadt  * These are needed in the register window code
    328       1.1  deraadt  * to check the validity of (ostensible) user stack PTEs.
    329       1.1  deraadt  */
    330       1.9       pk #define	PG_VSHIFT	29		/* (va>>vshift)==0 or -1 => valid */
    331       1.1  deraadt 	/* XXX fix this name, it is a va shift not a pte bit shift! */
    332       1.1  deraadt 
    333       1.1  deraadt #define	PG_PROTSHIFT	29
    334       1.1  deraadt #define	PG_PROTUWRITE	6		/* PG_V,PG_W,!PG_S */
    335       1.1  deraadt #define	PG_PROTUREAD	4		/* PG_V,!PG_W,!PG_S */
    336       1.1  deraadt 
    337      1.15       pk /* %%%: Fix above and below for 4m? */
    338      1.15       pk 
    339       1.1  deraadt /* static __inline int PG_VALID(void *va) {
    340       1.1  deraadt 	register int t = va; t >>= PG_VSHIFT; return (t == 0 || t == -1);
    341       1.1  deraadt } */
    342      1.10       pk 
    343      1.10       pk 
    344      1.10       pk /*
    345      1.15       pk  * Here are the bit definitions for 4M/SRMMU pte's
    346      1.10       pk  */
    347      1.15       pk 		/* MMU TABLE ENTRIES */
    348      1.15       pk #define SRMMU_TEINVALID	0x0		/* invalid (serves as !valid bit) */
    349      1.15       pk #define	SRMMU_TEPTD	0x1		/* Page Table Descriptor */
    350      1.15       pk #define SRMMU_TEPTE	0x2		/* Page Table Entry */
    351      1.15       pk #define SRMMU_TERES	0x3		/* reserved */
    352      1.15       pk #define SRMMU_TETYPE	0x3		/* mask for table entry type */
    353      1.15       pk 		/* PTE FIELDS */
    354      1.15       pk #define SRMMU_PPNMASK	0xFFFFFF00
    355      1.15       pk #define SRMMU_PPNSHIFT	0x8
    356      1.15       pk #define SRMMU_PPNPASHIFT 0x4 		/* shift to put ppn into PAddr */
    357      1.15       pk #define SRMMU_L1PPNSHFT	0x14
    358      1.15       pk #define SRMMU_L1PPNMASK	0xFFF00000
    359      1.15       pk #define SRMMU_L2PPNSHFT 0xE
    360      1.15       pk #define SRMMU_L2PPNMASK	0xFC000
    361      1.15       pk #define SRMMU_L3PPNSHFT	0x8
    362      1.15       pk #define SRMMU_L3PPNMASK 0x3F00
    363      1.15       pk 		/* PTE BITS */
    364      1.15       pk #define SRMMU_PG_C	0x80		/* cacheable */
    365      1.15       pk #define SRMMU_PG_M	0x40		/* modified (dirty) */
    366      1.15       pk #define SRMMU_PG_R	0x20		/* referenced */
    367      1.15       pk #define SRMMU_PGBITSMSK	0xE0
    368      1.15       pk 		/* PTE PROTECTION */
    369      1.15       pk #define SRMMU_PROT_MASK	0x1C		/* Mask protection bits out of pte */
    370      1.15       pk #define SRMMU_PROT_SHFT	0x2
    371      1.15       pk #define PPROT_R_R	0x0		/* These are in the form:	*/
    372      1.15       pk #define PPROT_RW_RW	0x4		/* 	PPROT_<u>_<s>		*/
    373      1.15       pk #define PPROT_RX_RX	0x8		/* where <u> is the user-mode	*/
    374      1.15       pk #define PPROT_RWX_RWX	0xC		/* permission, and <s> is the 	*/
    375      1.15       pk #define PPROT_X_X	0x10		/* supervisor mode permission.	*/
    376      1.15       pk #define PPROT_R_RW	0x14		/* R=read, W=write, X=execute	*/
    377      1.15       pk #define PPROT_N_RX	0x18		/* N=none.			*/
    378      1.15       pk #define PPROT_N_RWX	0x1C
    379      1.15       pk #define PPROT_WRITE	0x4		/* set iff write priv. allowed  */
    380      1.15       pk #define PPROT_S		0x18		/* effective S bit */
    381      1.15       pk #define PPROT_U2S_OMASK 0x18		/* OR with prot. to revoke user priv */
    382      1.15       pk 		/* TABLE SIZES */
    383      1.15       pk #define SRMMU_L1SIZE	0x100
    384      1.15       pk #define SRMMU_L2SIZE 	0x40
    385      1.15       pk #define SRMMU_L3SIZE	0x40
    386      1.10       pk 
    387      1.20       pk #define SRMMU_PTE_BITS	"\177\020"					\
    388      1.20       pk 	"f\0\2TYPE\0=\1PTD\0=\2PTE\0f\2\3PROT\0"			\
    389      1.20       pk 	"=\0R_R\0=\4RW_RW\0=\10RX_RX\0=\14RWX_RWX\0=\20X_X\0=\24R_RW\0"	\
    390      1.20       pk 	"=\30N_RX\0=\34N_RWX\0"						\
    391      1.20       pk 	"b\5R\0b\6M\0b\7C\0f\10\30PFN\0"
    392      1.20       pk 
    393      1.10       pk /*
    394      1.10       pk  * IOMMU PTE bits.
    395      1.10       pk  */
    396      1.15       pk #define IOPTE_PPN_MASK  0x07ffff00
    397      1.15       pk #define IOPTE_PPN_SHIFT 8
    398      1.15       pk #define IOPTE_RSVD      0x000000f1
    399      1.15       pk #define IOPTE_WRITE     0x00000004
    400      1.15       pk #define IOPTE_VALID     0x00000002
    401      1.20       pk 
    402      1.20       pk #define IOMMU_PTE_BITS	"\177\020"					\
    403      1.20       pk 	"f\10\23PPN\0b\2W\0b\1V\0"
    404      1.20       pk 
    405      1.21       pk 
    406      1.22   kleink #if defined(_KERNEL) || defined(_STANDALONE)
    407      1.21       pk /*
    408      1.21       pk  * Macros to get and set the processor context.
    409      1.21       pk  */
    410      1.21       pk #define getcontext4()		lduba(AC_CONTEXT, ASI_CONTROL)
    411      1.21       pk #define getcontext4m()		lda(SRMMU_CXR, ASI_SRMMU)
    412      1.21       pk #define getcontext()		(CPU_ISSUN4M ? getcontext4m() : getcontext4())
    413      1.21       pk 
    414      1.21       pk #define setcontext4(c)		stba(AC_CONTEXT, ASI_CONTROL, c)
    415      1.21       pk #define setcontext4m(c)		sta(SRMMU_CXR, ASI_SRMMU, c)
    416      1.21       pk #define setcontext(c)		(CPU_ISSUN4M ? setcontext4m(c) : setcontext4(c))
    417      1.21       pk 
    418      1.21       pk /* sun4/sun4c access to MMU-resident PTEs */
    419      1.21       pk #define	getpte4(va)		lda(va, ASI_PTE)
    420      1.21       pk #define	setpte4(va, pte)	sta(va, ASI_PTE, pte)
    421      1.21       pk 
    422      1.21       pk /* sun4m TLB probe */
    423      1.21       pk #define getpte4m(va)		lda((va & 0xFFFFF000) | ASI_SRMMUFP_L3, \
    424      1.23   kleink 				    ASI_SRMMUFP)
    425      1.22   kleink 
    426      1.22   kleink #endif /* _KERNEL || _STANDALONE */
    427