xref: /netbsd-src/sys/arch/vax/include/pte.h (revision 6a6027692662ba623e7bf5274322989a7b5d1440)
1 /*	$NetBSD: pte.h,v 1.24 2017/05/22 17:12:11 ragge Exp $	  */
2 
3 /*
4  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _VAX_PTE_H_
29 #define _VAX_PTE_H_
30 
31 #ifndef _LOCORE
32 /*
33  * VAX page table entries
34  */
35 struct pte {
36 	unsigned int	pg_pfn:21;	/* Page Frame Number or 0 */
37 	unsigned int	pg_illegal:2;	/* Don't use this bits */
38 	unsigned int	pg_sref:1;	/* Help for ref simulation */
39 	unsigned int	pg_w:1;		/* Wired bit */
40 	unsigned int	pg_z:1;		/* Zero DIGITAL = 0 */
41 	unsigned int	pg_m:1;		/* Modify DIGITAL */
42 	unsigned int	pg_prot:4;	/* reserved at zero */
43 	unsigned int	pg_v:1;		/* valid bit */
44 };
45 
46 
47 typedef struct pte	pt_entry_t;	/* Mach page table entry */
48 
49 #endif /* _LOCORE */
50 
51 #define PG_V		0x80000000
52 #define PG_NV		0x00000000
53 #define PG_PROT		0x78000000
54 #define PG_RW		0x20000000
55 #define PG_KW		0x10000000
56 #define PG_KR		0x18000000
57 #define PG_URKW		0x70000000
58 #define PG_RO		0x78000000
59 #define PG_NONE		0x00000000
60 #define PG_M		0x04000000
61 #define PG_W		0x01000000
62 #define PG_SREF		0x00800000
63 #define PG_ILLEGAL	0x00600000
64 #define PG_FRAME	0x001fffff
65 #define PG_PFNUM(x)	(((unsigned long)(x) & 0x3ffffe00) >> VAX_PGSHIFT)
66 
67 #ifndef _LOCORE
68 extern pt_entry_t *Sysmap;
69 /*
70  * Kernel virtual address to page table entry and to physical address.
71  */
72 #endif
73 
74 #ifdef __GNUC__
75 #define	kvtopte(va)	kvtopte0((vaddr_t) (va))
76 static inline struct pte *
kvtopte0(vaddr_t va)77 kvtopte0(vaddr_t va)
78 {
79 	struct pte *pt;
80 #ifdef _RUMPKERNEL
81 	__asm(
82 		"extzv $9,$21,%1,%0\n\t"
83 		"moval %2[%0],%0\n\t"
84 	     : "=r"(pt)
85 	     : "g"(va), "o"(*Sysmap));
86 #else
87 	__asm(
88 		"extzv $9,$21,%1,%0\n\t"
89 		"moval *Sysmap[%0],%0\n\t"
90 	     : "=r"(pt)
91 	     : "g"(va));
92 #endif
93 	return pt;
94 }
95 
96 #define	kvtophys(va)	kvtophys0((vaddr_t) (va))
97 static inline paddr_t
kvtophys0(vaddr_t va)98 kvtophys0(vaddr_t va)
99 {
100 	paddr_t pa;
101 #ifdef _RUMPKERNEL
102 	__asm(
103 		"extzv $9,$21,%1,%0\n\t"
104 		"ashl $9,%2[%0],%0\n\t"
105 		"insv %1,$0,$9,%0\n\t"
106 	    : "=&r"(pa)
107 	    : "g"(va), "o"(*Sysmap) : "cc");
108 #else
109 	__asm(
110 		"extzv $9,$21,%1,%0\n\t"
111 		"ashl $9,*Sysmap[%0],%0\n\t"
112 		"insv %1,$0,$9,%0\n\t"
113 	    : "=&r"(pa)
114 	    : "g"(va) : "cc");
115 #endif
116 	return pa;
117 }
118 #else /* __GNUC__ */
119 #define kvtophys(va) \
120 	(((kvtopte(va))->pg_pfn << VAX_PGSHIFT) | ((paddr_t)(va) & VAX_PGOFSET))
121 #define kvtopte(va) (&Sysmap[PG_PFNUM(va)])
122 #endif /* __GNUC__ */
123 #define uvtopte(va, pcb) \
124 	(((vaddr_t)va < 0x40000000) ? \
125 	&(((pcb)->P0BR)[PG_PFNUM(va)]) : \
126 	&(((pcb)->P1BR)[PG_PFNUM(va)]))
127 
128 #endif
129