debuggers.hg

view xen/include/asm-x86/x86_64/page.h @ 4629:6375127fdf23

bitkeeper revision 1.1311.1.1 (426641eeBv97w6sl983zxeR4Dc3Utg)

Cleanup page table handling. Add macros to access page table
entries, fixup plenty of places in the code to use the page
table types instead of "unsigned long".

Signed-off-by: Gerd Knorr <kraxel@bytesex.org>
Signed-off-by: michael.fetterman@cl.cam.ac.uk
author mafetter@fleming.research
date Wed Apr 20 11:50:06 2005 +0000 (2005-04-20)
parents 3f2415a328b7
children 1803018b3b05
line source
2 #ifndef __X86_64_PAGE_H__
3 #define __X86_64_PAGE_H__
5 #define L1_PAGETABLE_SHIFT 12
6 #define L2_PAGETABLE_SHIFT 21
7 #define L3_PAGETABLE_SHIFT 30
8 #define L4_PAGETABLE_SHIFT 39
9 #define PAGE_SHIFT L1_PAGETABLE_SHIFT
10 #define ROOT_PAGETABLE_SHIFT L4_PAGETABLE_SHIFT
12 #define PAGETABLE_ORDER 9
13 #define L1_PAGETABLE_ENTRIES (1<<PAGETABLE_ORDER)
14 #define L2_PAGETABLE_ENTRIES (1<<PAGETABLE_ORDER)
15 #define L3_PAGETABLE_ENTRIES (1<<PAGETABLE_ORDER)
16 #define L4_PAGETABLE_ENTRIES (1<<PAGETABLE_ORDER)
17 #define ROOT_PAGETABLE_ENTRIES L4_PAGETABLE_ENTRIES
19 #define __PAGE_OFFSET (0xFFFF830000000000)
21 /* These are page-table limitations. Current CPUs support only 40-bit phys. */
22 #define PADDR_BITS 52
23 #define VADDR_BITS 48
24 #define PADDR_MASK ((1UL << PADDR_BITS)-1)
25 #define VADDR_MASK ((1UL << VADDR_BITS)-1)
27 #define _PAGE_NX (cpu_has_nx ? (1UL<<63) : 0UL)
28 #define PAGE_FLAG_MASK 0xfff
30 #ifndef __ASSEMBLY__
31 #include <xen/config.h>
32 #include <asm/types.h>
33 typedef struct { u64 l1_lo; } l1_pgentry_t;
34 typedef struct { u64 l2_lo; } l2_pgentry_t;
35 typedef struct { u64 l3_lo; } l3_pgentry_t;
36 typedef struct { u64 l4_lo; } l4_pgentry_t;
37 typedef l4_pgentry_t root_pgentry_t;
39 /* read access (depricated) */
40 #define l1e_get_value(_x) ((_x).l1_lo)
41 #define l2e_get_value(_x) ((_x).l2_lo)
42 #define l3e_get_value(_x) ((_x).l3_lo)
43 #define l4e_get_value(_x) ((_x).l4_lo)
45 /* read access */
46 #define l1e_get_pfn(_x) (((_x).l1_lo & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
47 #define l1e_get_phys(_x) (((_x).l1_lo & (PADDR_MASK&PAGE_MASK)))
48 #define l1e_get_flags(_x) ((_x).l1_lo & PAGE_FLAG_MASK)
50 #define l2e_get_pfn(_x) (((_x).l2_lo & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
51 #define l2e_get_phys(_x) (((_x).l2_lo & (PADDR_MASK&PAGE_MASK)))
52 #define l2e_get_flags(_x) ((_x).l2_lo & PAGE_FLAG_MASK)
54 #define l3e_get_pfn(_x) (((_x).l3_lo & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
55 #define l3e_get_phys(_x) (((_x).l3_lo & (PADDR_MASK&PAGE_MASK)))
56 #define l3e_get_flags(_x) ((_x).l3_lo & PAGE_FLAG_MASK)
58 #define l4e_get_pfn(_x) (((_x).l4_lo & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
59 #define l4e_get_phys(_x) (((_x).l4_lo & (PADDR_MASK&PAGE_MASK)))
60 #define l4e_get_flags(_x) ((_x).l4_lo & PAGE_FLAG_MASK)
62 /* write access */
63 static inline l1_pgentry_t l1e_empty(void)
64 {
65 l1_pgentry_t e = { .l1_lo = 0 };
66 return e;
67 }
68 static inline l1_pgentry_t l1e_create_pfn(u64 pfn, u64 flags)
69 {
70 l1_pgentry_t e = { .l1_lo = (pfn << PAGE_SHIFT) | flags };
71 return e;
72 }
73 static inline l1_pgentry_t l1e_create_phys(u64 addr, u64 flags)
74 {
75 l1_pgentry_t e = { .l1_lo = (addr & (PADDR_MASK&PAGE_MASK)) | flags };
76 return e;
77 }
78 static inline void l1e_add_flags(l1_pgentry_t *e, u64 flags)
79 {
80 e->l1_lo |= flags;
81 }
82 static inline void l1e_remove_flags(l1_pgentry_t *e, u64 flags)
83 {
84 e->l1_lo &= ~flags;
85 }
87 static inline l2_pgentry_t l2e_empty(void)
88 {
89 l2_pgentry_t e = { .l2_lo = 0 };
90 return e;
91 }
92 static inline l2_pgentry_t l2e_create_pfn(u64 pfn, u64 flags)
93 {
94 l2_pgentry_t e = { .l2_lo = (pfn << PAGE_SHIFT) | flags };
95 return e;
96 }
97 static inline l2_pgentry_t l2e_create_phys(u64 addr, u64 flags)
98 {
99 l2_pgentry_t e = { .l2_lo = (addr & (PADDR_MASK&PAGE_MASK)) | flags };
100 return e;
101 }
102 static inline void l2e_add_flags(l2_pgentry_t *e, u64 flags)
103 {
104 e->l2_lo |= flags;
105 }
106 static inline void l2e_remove_flags(l2_pgentry_t *e, u64 flags)
107 {
108 e->l2_lo &= ~flags;
109 }
111 static inline l3_pgentry_t l3e_empty(void)
112 {
113 l3_pgentry_t e = { .l3_lo = 0 };
114 return e;
115 }
116 static inline l3_pgentry_t l3e_create_pfn(u64 pfn, u64 flags)
117 {
118 l3_pgentry_t e = { .l3_lo = (pfn << PAGE_SHIFT) | flags };
119 return e;
120 }
121 static inline l3_pgentry_t l3e_create_phys(u64 addr, u64 flags)
122 {
123 l3_pgentry_t e = { .l3_lo = (addr & (PADDR_MASK&PAGE_MASK)) | flags };
124 return e;
125 }
126 static inline void l3e_add_flags(l3_pgentry_t *e, u64 flags)
127 {
128 e->l3_lo |= flags;
129 }
130 static inline void l3e_remove_flags(l3_pgentry_t *e, u64 flags)
131 {
132 e->l3_lo &= ~flags;
133 }
135 static inline l4_pgentry_t l4e_empty(void)
136 {
137 l4_pgentry_t e = { .l4_lo = 0 };
138 return e;
139 }
140 static inline l4_pgentry_t l4e_create_pfn(u64 pfn, u64 flags)
141 {
142 l4_pgentry_t e = { .l4_lo = (pfn << PAGE_SHIFT) | flags };
143 return e;
144 }
145 static inline l4_pgentry_t l4e_create_phys(u64 addr, u64 flags)
146 {
147 l4_pgentry_t e = { .l4_lo = (addr & (PADDR_MASK&PAGE_MASK)) | flags };
148 return e;
149 }
150 static inline void l4e_add_flags(l4_pgentry_t *e, u64 flags)
151 {
152 e->l4_lo |= flags;
153 }
154 static inline void l4e_remove_flags(l4_pgentry_t *e, u64 flags)
155 {
156 e->l4_lo &= ~flags;
157 }
159 /* check entries */
160 static inline int l1e_has_changed(l1_pgentry_t *e1, l1_pgentry_t *e2, u32 flags)
161 {
162 return ((e1->l1_lo ^ e2->l1_lo) & ((PADDR_MASK&PAGE_MASK) | flags)) != 0;
163 }
164 static inline int l2e_has_changed(l2_pgentry_t *e1, l2_pgentry_t *e2, u32 flags)
165 {
166 return ((e1->l2_lo ^ e2->l2_lo) & ((PADDR_MASK&PAGE_MASK) | flags)) != 0;
167 }
168 static inline int l3e_has_changed(l3_pgentry_t *e1, l3_pgentry_t *e2, u32 flags)
169 {
170 return ((e1->l3_lo ^ e2->l3_lo) & ((PADDR_MASK&PAGE_MASK) | flags)) != 0;
171 }
172 static inline int l4e_has_changed(l4_pgentry_t *e1, l4_pgentry_t *e2, u32 flags)
173 {
174 return ((e1->l4_lo ^ e2->l4_lo) & ((PADDR_MASK&PAGE_MASK) | flags)) != 0;
175 }
177 #endif /* !__ASSEMBLY__ */
179 /* Pagetable walking. */
180 #define l2e_to_l1e(_x) \
181 ((l1_pgentry_t *)__va(l2e_get_phys(_x)))
182 #define l3e_to_l2e(_x) \
183 ((l2_pgentry_t *)__va(l3e_get_phys(_x)))
184 #define l4e_to_l3e(_x) \
185 ((l3_pgentry_t *)__va(l4e_get_phys(_x)))
187 /* Given a virtual address, get an entry offset into a page table. */
188 #define l1_table_offset(_a) \
189 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
190 #define l2_table_offset(_a) \
191 (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
192 #define l3_table_offset(_a) \
193 (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
194 #define l4_table_offset(_a) \
195 (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
197 /* Given a virtual address, get an entry offset into a linear page table. */
198 #define l1_linear_offset(_a) (((_a) & VADDR_MASK) >> PAGE_SHIFT)
200 #define is_guest_l1_slot(_s) (1)
201 #define is_guest_l2_slot(_s) (1)
202 #define is_guest_l3_slot(_s) (1)
203 #define is_guest_l4_slot(_s) \
204 (((_s) < ROOT_PAGETABLE_FIRST_XEN_SLOT) || \
205 ((_s) > ROOT_PAGETABLE_LAST_XEN_SLOT))
207 #define root_get_pfn l4e_get_pfn
208 #define root_get_flags l4e_get_flags
209 #define root_get_value l4e_get_value
210 #define root_empty l4e_empty
211 #define root_create_phys l4e_create_phys
212 #define PGT_root_page_table PGT_l4_page_table
214 #define L1_DISALLOW_MASK ((cpu_has_nx?0:(1UL<<63)) | (3UL << 7))
215 #define L2_DISALLOW_MASK ((cpu_has_nx?0:(1UL<<63)) | (7UL << 7))
216 #define L3_DISALLOW_MASK ((cpu_has_nx?0:(1UL<<63)) | (7UL << 7))
217 #define L4_DISALLOW_MASK ((cpu_has_nx?0:(1UL<<63)) | (7UL << 7))
219 #endif /* __X86_64_PAGE_H__ */
221 /*
222 * Local variables:
223 * mode: C
224 * c-set-style: "BSD"
225 * c-basic-offset: 4
226 * tab-width: 4
227 * indent-tabs-mode: nil
228 * End:
229 */