xref: /csrg-svn/sys/sparc/include/pte.h (revision 55124)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)pte.h	7.1 (Berkeley) 07/13/92
12  *
13  * from: $Header: pte.h,v 1.4 92/06/17 06:10:25 torek Exp $
14  */
15 
16 /*
17  * Sun-4 (sort of) and 4c (SparcStation) Page Table Entries
18  * (Sun call them `Page Map Entries').
19  */
20 
21 #ifndef LOCORE
22 /*
23  * Segment maps contain `pmeg' (Page Map Entry Group) numbers.
24  * A PMEG is simply an index that names a group of 32 (sun4) or
25  * 64 (sun4c) PTEs.
26  */
27 #ifdef SUN4
28 typedef u_short pmeg_t;		/* 9 bits needed per Sun-4 segmap entry */
29 #else
30 typedef u_char pmeg_t;		/* 7 bits needed per Sun-4c segmap entry */
31 #endif
32 #endif
33 
34 /*
35  * Address translation works as follows:
36  *
37  *	1. test va<31:29> -- these must be 000 or 111 (or you get a fault)
38  *	2. concatenate context_reg<2:0> and va<29:18> to get a 15 bit number;
39  *	   use this to index the segment maps, yeilding a 7 or 9 bit value.
40  * (for sun4c)
41  *	3. take the value from (2) above and concatenate va<17:12> to
42  *	   get a `page map entry' index.  This gives a 32-bit PTE.
43  * (for sun4)
44  *	3. take the value from (2) above and concatenate va<17:13> to
45  *	   get a `page map entry' index.  This gives a 32-bit PTE.
46  *
47  * In other words:
48  *
49  *	struct sun4_virtual_addr {
50  *		u_int	:2,		(required to be the same as bit 29)
51  *			va_seg:12,	(virtual segment)
52  *			va_pg:5,	(virtual page within segment)
53  *			va_off:13;	(offset within page)
54  *	};
55  *	struct sun4c_virtual_addr {
56  *		u_int	:2,		(required to be the same as bit 29)
57  *			va_seg:12,	(virtual segment)
58  *			va_pg:6,	(virtual page within segment)
59  *			va_off:12;	(offset within page)
60  *	};
61  *
62  * Then, given any `va':
63  *
64  *	extern pmeg_t segmap[8][1<<12];		([16][1<<12] for sun4)
65  *	extern int ptetable[128][1<<6];		([512][1<<5] for sun4)
66  *
67  * (the above being in the hardware, accessed as Alternate Address Spaces)
68  *
69  *	physseg = segmap[curr_ctx][va.va_seg];
70  *	pte = ptetable[physseg][va.va_pg];
71  *	if (!(pte & PG_V)) TRAP();
72  *	if (writing && !pte.pg_w) TRAP();
73  *	if (usermode && pte.pg_s) TRAP();
74  *	if (pte & PG_NC) DO_NOT_USE_CACHE_FOR_THIS_ACCESS();
75  *	pte |= PG_U;					(mark used/accessed)
76  *	if (writing) pte |= PG_M;			(mark modified)
77  *	ptetable[physseg][va.va_pg] = pte;
78  *	physadr = ((pte & PG_PFNUM) << PGSHIFT) | va.va_off;
79  */
80 
81 #define	NBPSG	(1 << 18)	/* bytes per segment */
82 #define	SGSHIFT	18		/* log2(NBPSG) */
83 #define	SGOFSET	(NBPSG - 1)	/* mask for segment offset */
84 
85 /* number of PTEs that map one segment (not number that fit in one segment!) */
86 #if defined(SUN4) && defined(SUN4C)
87 #define	NPTESG	nptesg		/* (which someone will have to init) */
88 #else
89 #define	NPTESG	(NBPSG / NBPG)
90 #endif
91 
92 /* virtual address to virtual segment number */
93 #define	VA_VSEG(va)	(((int)(va) >> SGSHIFT) & 0xfff)
94 
95 /* virtual address to virtual page number, for Sun-4 and Sun-4c */
96 #define	VA_SUN4_VPG(va)		(((int)(va) >> 13) & 31)
97 #define	VA_SUN4C_VPG(va)	(((int)(va) >> 12) & 63)
98 
99 /* truncate virtual address to segment base */
100 #define	VA_ROUNDDOWNTOSEG(va)	((int)(va) & ~SGOFSET)
101 
102 /* virtual segment to virtual address (must sign extend!) */
103 #define	VSTOVA(vseg)	(((int)(vseg) << 20) >> 2)
104 
105 #ifdef SUN4
106 #ifdef SUN4C
107 int	issun4c;
108 #define VA_VPG(va)	(issun4c ? VA_SUN4C_VPG(va) : VA_SUN4_VPG(va))
109 #else /* sun4 and not sun4c */
110 #define VA_VPG(va)	VA_SUN4_VPG(va)
111 #endif
112 #else /* not sun4; must be 4c */
113 #define	VA_VPG(va)	VA_SUN4C_VPG(va)
114 #endif
115 
116 /* there is no `struct pte'; we just use `int' */
117 #define	PG_V		0x80000000
118 #define	PG_PROT		0x60000000	/* both protection bits */
119 #define	PG_W		0x40000000	/* allowed to write */
120 #define	PG_S		0x20000000	/* supervisor only */
121 #define	PG_NC		0x10000000	/* non-cacheable */
122 #define	PG_TYPE		0x0c000000	/* both type bits */
123 
124 #define	PG_OBMEM	0x00000000	/* on board memory */
125 #define	PG_OBIO		0x04000000	/* on board I/O (incl. Sbus on 4c) */
126 #ifdef SUN4
127 #define	PG_VME16	0x08000000	/* 16-bit-data VME space */
128 #define	PG_VME32	0x0c000000	/* 32-bit-data VME space */
129 #endif
130 
131 #define	PG_U		0x02000000
132 #define	PG_M		0x01000000
133 #define	PG_MBZ		0x00f80000	/* unused; must be zero (oh really?) */
134 #define	PG_PFNUM	0x0007ffff	/* n.b.: only 16 bits on sun4c */
135 
136 #define	PG_TNC_SHIFT	26		/* shift to get PG_TYPE + PG_NC */
137 #define	PG_M_SHIFT	24		/* shift to get PG_M, PG_U */
138 
139 /*efine	PG_NOACC	0		** XXX */
140 #define	PG_KR		0x20000000
141 #define	PG_KW		0x60000000
142 #define	PG_URKR		0
143 #define	PG_UW		0x40000000
144 
145 #ifdef KGDB
146 /* but we will define one for gdb anyway */
147 struct pte {
148 	u_int	pg_v:1,
149 		pg_w:1,
150 		pg_s:1,
151 		pg_nc:1;
152 	enum pgtype { pg_obmem, pg_obio, pg_vme16, pg_vme32 } pg_type:2;
153 	u_int	pg_u:1,
154 		pg_m:1,
155 		pg_mbz:5,
156 		pg_pfnum:19;
157 };
158 #endif
159 
160 /*
161  * These are needed in the register window code
162  * to check the validity of (ostensible) user stack PTEs.
163  */
164 #define	PG_VSHIFT	30		/* (va>>vshift)==0 or -1 => valid */
165 	/* XXX fix this name, it is a va shift not a pte bit shift! */
166 
167 #define	PG_PROTSHIFT	29
168 #define	PG_PROTUWRITE	6		/* PG_V,PG_W,!PG_S */
169 #define	PG_PROTUREAD	4		/* PG_V,!PG_W,!PG_S */
170 
171 /* static __inline int PG_VALID(void *va) {
172 	register int t = va; t >>= PG_VSHIFT; return (t == 0 || t == -1);
173 } */
174