pte.h revision 1.30 1 1.30 maxv /* $NetBSD: pte.h,v 1.30 2019/03/07 14:40:35 maxv Exp $ */
2 1.16 yamt
3 1.16 yamt /*
4 1.16 yamt * Copyright (c) 2001 Wasabi Systems, Inc.
5 1.16 yamt * All rights reserved.
6 1.16 yamt *
7 1.16 yamt * Written by Frank van der Linden for Wasabi Systems, Inc.
8 1.16 yamt *
9 1.16 yamt * Redistribution and use in source and binary forms, with or without
10 1.16 yamt * modification, are permitted provided that the following conditions
11 1.16 yamt * are met:
12 1.16 yamt * 1. Redistributions of source code must retain the above copyright
13 1.16 yamt * notice, this list of conditions and the following disclaimer.
14 1.16 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.16 yamt * notice, this list of conditions and the following disclaimer in the
16 1.16 yamt * documentation and/or other materials provided with the distribution.
17 1.16 yamt * 3. All advertising materials mentioning features or use of this software
18 1.16 yamt * must display the following acknowledgement:
19 1.16 yamt * This product includes software developed for the NetBSD Project by
20 1.16 yamt * Wasabi Systems, Inc.
21 1.16 yamt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.16 yamt * or promote products derived from this software without specific prior
23 1.16 yamt * written permission.
24 1.16 yamt *
25 1.16 yamt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.16 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.16 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.16 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.16 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.16 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.16 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.16 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.16 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.16 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.16 yamt * POSSIBILITY OF SUCH DAMAGE.
36 1.16 yamt */
37 1.11 thorpej
38 1.10 mrg /*
39 1.10 mrg * Copyright (c) 1997 Charles D. Cranor and Washington University.
40 1.1 cgd * All rights reserved.
41 1.1 cgd *
42 1.1 cgd * Redistribution and use in source and binary forms, with or without
43 1.1 cgd * modification, are permitted provided that the following conditions
44 1.1 cgd * are met:
45 1.1 cgd * 1. Redistributions of source code must retain the above copyright
46 1.1 cgd * notice, this list of conditions and the following disclaimer.
47 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 cgd * notice, this list of conditions and the following disclaimer in the
49 1.1 cgd * documentation and/or other materials provided with the distribution.
50 1.10 mrg *
51 1.10 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 1.10 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 1.10 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 1.10 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 1.10 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 1.10 mrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 1.10 mrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 1.10 mrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 1.10 mrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 1.10 mrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 1.1 cgd */
62 1.1 cgd
63 1.3 andrew #ifndef _I386_PTE_H_
64 1.3 andrew #define _I386_PTE_H_
65 1.17 bouyer #ifdef _KERNEL_OPT
66 1.17 bouyer #include "opt_xen.h"
67 1.17 bouyer #endif
68 1.3 andrew
69 1.10 mrg /*
70 1.20 dyoung * The PAE extension extends the size of the PTE to 64 bits (52bits physical
71 1.17 bouyer * address) and is compatible with the amd64 PTE format. The first level
72 1.22 jld * maps 2M, the second 1G, so a third level page table is introduced to
73 1.17 bouyer * map the 4GB virtual address space. This PD has only 4 entries.
74 1.22 jld * We can't use recursive mapping at level 3 to map the PD pages, as this
75 1.22 jld * would eat one GB of address space. In addition, Xen imposes restrictions
76 1.17 bouyer * on the entries we put in the L3 page (for example, the page pointed to by
77 1.28 maxv * the last slot can't be shared among different L3 pages), which makes
78 1.17 bouyer * handling this L3 page in the same way we do for L2 on i386 (or L4 on amd64)
79 1.17 bouyer * difficult. For most things we'll just pretend to have only 2 levels,
80 1.17 bouyer * with the 2 high bits of the L2 index being in fact the index in the
81 1.17 bouyer * L3.
82 1.10 mrg */
83 1.10 mrg
84 1.11 thorpej #if !defined(_LOCORE)
85 1.10 mrg
86 1.10 mrg /*
87 1.10 mrg * here we define the data types for PDEs and PTEs
88 1.10 mrg */
89 1.17 bouyer #ifdef PAE
90 1.17 bouyer typedef uint64_t pd_entry_t; /* PDE */
91 1.17 bouyer typedef uint64_t pt_entry_t; /* PTE */
92 1.17 bouyer #else
93 1.15 perry typedef uint32_t pd_entry_t; /* PDE */
94 1.15 perry typedef uint32_t pt_entry_t; /* PTE */
95 1.17 bouyer #endif
96 1.10 mrg
97 1.1 cgd #endif
98 1.1 cgd
99 1.17 bouyer #ifdef PAE
100 1.28 maxv #define L1_SHIFT 12
101 1.28 maxv #define L2_SHIFT 21
102 1.28 maxv #define L3_SHIFT 30
103 1.28 maxv #define NBPD_L1 (1ULL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
104 1.28 maxv #define NBPD_L2 (1ULL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
105 1.28 maxv #define NBPD_L3 (1ULL << L3_SHIFT) /* # bytes mapped by L3 ent (1GB) */
106 1.28 maxv
107 1.28 maxv #define L3_MASK 0xc0000000
108 1.28 maxv #define L2_REALMASK 0x3fe00000
109 1.28 maxv #define L2_MASK (L2_REALMASK | L3_MASK)
110 1.28 maxv #define L1_MASK 0x001ff000
111 1.28 maxv
112 1.28 maxv #define L3_FRAME (L3_MASK)
113 1.28 maxv #define L2_FRAME (L3_FRAME | L2_MASK)
114 1.28 maxv #define L1_FRAME (L2_FRAME|L1_MASK)
115 1.17 bouyer
116 1.30 maxv /* XXX To be deleted. */
117 1.28 maxv #define PG_FRAME 0x000ffffffffff000ULL /* page frame mask */
118 1.28 maxv #define PG_LGFRAME 0x000fffffffe00000ULL /* large (2MB) page frame mask */
119 1.17 bouyer
120 1.30 maxv #define PTE_4KFRAME 0x000ffffffffff000ULL
121 1.30 maxv #define PTE_2MFRAME 0x000fffffffe00000ULL
122 1.30 maxv
123 1.30 maxv #define PTE_FRAME PTE_4KFRAME
124 1.30 maxv #define PTE_LGFRAME PTE_2MFRAME
125 1.30 maxv
126 1.17 bouyer /* macros to get real L2 and L3 index, from our "extended" L2 index */
127 1.17 bouyer #define l2tol3(idx) ((idx) >> (L3_SHIFT - L2_SHIFT))
128 1.17 bouyer #define l2tol2(idx) ((idx) & (L2_REALMASK >> L2_SHIFT))
129 1.24 cegger
130 1.17 bouyer #else /* PAE */
131 1.24 cegger
132 1.28 maxv #define L1_SHIFT 12
133 1.28 maxv #define L2_SHIFT 22
134 1.28 maxv #define NBPD_L1 (1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
135 1.28 maxv #define NBPD_L2 (1UL << L2_SHIFT) /* # bytes mapped by L2 ent (4MB) */
136 1.16 yamt
137 1.16 yamt #define L2_MASK 0xffc00000
138 1.16 yamt #define L1_MASK 0x003ff000
139 1.16 yamt
140 1.16 yamt #define L2_FRAME (L2_MASK)
141 1.16 yamt #define L1_FRAME (L2_FRAME|L1_MASK)
142 1.1 cgd
143 1.30 maxv /* XXX To be deleted. */
144 1.28 maxv #define PG_FRAME 0xfffff000 /* page frame mask */
145 1.28 maxv #define PG_LGFRAME 0xffc00000 /* large (4MB) page frame mask */
146 1.17 bouyer
147 1.30 maxv #define PTE_4KFRAME 0xfffff000
148 1.30 maxv #define PTE_4MFRAME 0xffc00000
149 1.30 maxv
150 1.30 maxv #define PTE_FRAME PTE_4KFRAME
151 1.30 maxv #define PTE_LGFRAME PTE_4MFRAME
152 1.30 maxv
153 1.17 bouyer #endif /* PAE */
154 1.28 maxv
155 1.10 mrg /*
156 1.30 maxv * x86 PTE/PDE bits.
157 1.30 maxv */
158 1.30 maxv #define PTE_P 0x00000001 /* Present */
159 1.30 maxv #define PTE_W 0x00000002 /* Write */
160 1.30 maxv #define PTE_U 0x00000004 /* User */
161 1.30 maxv #define PTE_PWT 0x00000008 /* Write-Through */
162 1.30 maxv #define PTE_PCD 0x00000010 /* Cache-Disable */
163 1.30 maxv #define PTE_A 0x00000020 /* Accessed */
164 1.30 maxv #define PTE_D 0x00000040 /* Dirty */
165 1.30 maxv #define PTE_PAT 0x00000080 /* PAT on 4KB Pages */
166 1.30 maxv #define PTE_PS 0x00000080 /* Large Page Size */
167 1.30 maxv #define PTE_G 0x00000100 /* Global Translation */
168 1.30 maxv #define PTE_AVL1 0x00000200 /* Ignored by Hardware */
169 1.30 maxv #define PTE_AVL2 0x00000400 /* Ignored by Hardware */
170 1.30 maxv #define PTE_AVL3 0x00000800 /* Ignored by Hardware */
171 1.30 maxv #define PTE_LGPAT 0x00001000 /* PAT on Large Pages */
172 1.30 maxv #ifdef PAE
173 1.30 maxv #define PTE_NX 0x8000000000000000ULL /* No Execute */
174 1.30 maxv #else
175 1.30 maxv #define PTE_NX 0 /* Dummy */
176 1.30 maxv #endif
177 1.30 maxv
178 1.30 maxv /*
179 1.10 mrg * here we define the bits of the PDE/PTE, as described above:
180 1.10 mrg * XXXCDC: need to rename these (PG_u == ugly).
181 1.30 maxv * XXX To be deleted.
182 1.10 mrg */
183 1.28 maxv #define PG_V 0x00000001 /* valid entry */
184 1.28 maxv #define PG_RW 0x00000002 /* read-write page */
185 1.28 maxv #define PG_u 0x00000004 /* user accessible page */
186 1.24 cegger #define PG_WT 0x00000008 /* write through */
187 1.28 maxv #define PG_N 0x00000010 /* non-cacheable */
188 1.28 maxv #define PG_U 0x00000020 /* has been used */
189 1.28 maxv #define PG_M 0x00000040 /* has been modified */
190 1.24 cegger #define PG_PAT 0x00000080 /* PAT (on pte) */
191 1.26 jym #define PG_PS 0x00000080 /* 4MB page size (2MB for PAE) */
192 1.10 mrg #define PG_G 0x00000100 /* global, don't TLB flush */
193 1.10 mrg #define PG_AVAIL1 0x00000200 /* ignored by hardware */
194 1.10 mrg #define PG_AVAIL2 0x00000400 /* ignored by hardware */
195 1.10 mrg #define PG_AVAIL3 0x00000800 /* ignored by hardware */
196 1.24 cegger #define PG_LGPAT 0x00001000 /* PAT on large pages */
197 1.28 maxv #define PG_KW 0x00000002 /* kernel read-write */
198 1.19 cegger #ifdef PAE
199 1.28 maxv #define PG_NX 0x8000000000000000ULL /* No-execute */
200 1.19 cegger #else
201 1.28 maxv #define PG_NX 0 /* dummy */
202 1.19 cegger #endif
203 1.10 mrg
204 1.24 cegger #include <x86/pte.h>
205 1.3 andrew
206 1.3 andrew #endif /* _I386_PTE_H_ */
207