Xen Test Framework
page.h
Go to the documentation of this file.
1#ifndef XTF_X86_PAGE_H
2#define XTF_X86_PAGE_H
3
4#include <xtf/numbers.h>
5
6/*
7 * Nomenclature inherited from Xen.
8 */
9
10#define PAGE_SHIFT 12
11#define PAGE_SIZE (_AC(1, L) << PAGE_SHIFT)
12#define PAGE_MASK (~(PAGE_SIZE - 1))
13
14#define PADDR_BITS 52
15#define PADDR_MASK ((_AC(1, ULL) << PADDR_BITS) - 1)
16
17#include "page-pae.h"
18#include "page-pse.h"
19
20#define PAGE_ORDER_4K 0
21#define PAGE_ORDER_2M 9
22#define PAGE_ORDER_4M 10
23#define PAGE_ORDER_1G 18
24
25#define _PAGE_PRESENT 0x0001
26#define _PAGE_RW 0x0002
27#define _PAGE_USER 0x0004
28#define _PAGE_PWT 0x0008
29#define _PAGE_PCD 0x0010
30#define _PAGE_ACCESSED 0x0020
31#define _PAGE_DIRTY 0x0040
32#define _PAGE_AD (_PAGE_ACCESSED | _PAGE_DIRTY)
33#define _PAGE_PSE 0x0080
34#define _PAGE_PAT 0x0080
35#define _PAGE_GLOBAL 0x0100
36#define _PAGE_AVAIL 0x0e00
37#define _PAGE_PSE_PAT 0x1000
38#define _PAGE_NX (_AC(1, ULL) << 63)
39
40/* Shortened flags for use with PF_SYM(). */
41#define _PAGE_P _PAGE_PRESENT
42#define _PAGE_U _PAGE_USER
43#define _PAGE_A _PAGE_ACCESSED
44#define _PAGE_D _PAGE_DIRTY
45
46#if CONFIG_PAGING_LEVELS == 2 /* PSE Paging */
47
48#define PTE_SIZE PSE_PTE_SIZE
49#define PTE_ORDER PSE_PTE_ORDER
50
51#define PT_ORDER PSE_PT_ORDER
52
53#define L1_PT_SHIFT PSE_L1_PT_SHIFT
54#define L2_PT_SHIFT PSE_L2_PT_SHIFT
55
56#define L1_PT_ENTRIES PSE_L1_PT_ENTRIES
57#define L2_PT_ENTRIES PSE_L2_PT_ENTRIES
58
59#else /* CONFIG_PAGING_LEVELS == 2 */ /* PAE Paging */
60
61#define PTE_SIZE PAE_PTE_SIZE
62#define PTE_ORDER PAE_PTE_ORDER
63
64#define PT_ORDER PAE_PT_ORDER
65
66#define L1_PT_SHIFT PAE_L1_PT_SHIFT
67#define L2_PT_SHIFT PAE_L2_PT_SHIFT
68
69#define L1_PT_ENTRIES PAE_L1_PT_ENTRIES
70#define L2_PT_ENTRIES PAE_L2_PT_ENTRIES
71
72#endif /* !CONFIG_PAGING_LEVELS == 2 */
73
74#if CONFIG_PAGING_LEVELS >= 3 /* PAE Paging */
75
76#define L3_PT_SHIFT PAE_L3_PT_SHIFT
77
78#define L3_PT_ENTRIES PAE_L3_PT_ENTRIES
79
80#endif /* CONFIG_PAGING_LEVELS >= 3 */
81
82#if CONFIG_PAGING_LEVELS >= 4 /* PAE Paging */
83
84#define L4_PT_SHIFT PAE_L4_PT_SHIFT
85
86#define L4_PT_ENTRIES PAE_L4_PT_ENTRIES
87
88#endif /* CONFIG_PAGING_LEVELS >= 4 */
89
90
91#ifndef __ASSEMBLY__
92
93/*
94 * Always consider "physical" addresses to be 64bits wide, even in 32bit mode.
95 */
97#define PRIpaddr "016"PRIx64
98
99#if CONFIG_PAGING_LEVELS > 0 /* Some form of pagetables. */
100
101#if CONFIG_PAGING_LEVELS == 2 /* PSE Paging */
102
103typedef pse_intpte_t intpte_t;
104#define PRIpte PSE_PRIpte
105
106static inline unsigned int l1_table_offset(unsigned long linear)
107{
108 return pse_l1_table_offset(linear);
109}
110static inline unsigned int l2_table_offset(unsigned long linear)
111{
112 return pse_l2_table_offset(linear);
113}
114
115#else /* CONFIG_PAGING_LEVELS == 2 */ /* PAE Paging */
116
117typedef pae_intpte_t intpte_t;
118#define PRIpte PAE_PRIpte
119
120static inline unsigned int l1_table_offset(unsigned long linear)
121{
122 return pae_l1_table_offset(linear);
123}
124static inline unsigned int l2_table_offset(unsigned long linear)
125{
126 return pae_l2_table_offset(linear);
127}
128
129#endif /* !CONFIG_PAGING_LEVELS == 2 */
130
131#if CONFIG_PAGING_LEVELS >= 3 /* PAE Paging */
132
133static inline unsigned int l3_table_offset(unsigned long linear)
134{
135 return pae_l3_table_offset(linear);
136}
137
138#endif /* CONFIG_PAGING_LEVELS >= 3 */
139
140#if CONFIG_PAGING_LEVELS >= 4 /* PAE Paging */
141
142static inline unsigned int l4_table_offset(unsigned long linear)
143{
144 return pae_l4_table_offset(linear);
145}
146
147#endif /* CONFIG_PAGING_LEVELS >= 4 */
148
149#else /* CONFIG_PAGING_LEVELS > 0 */
150
151/* Enough compatibility to compile in unpaged environments. */
152typedef unsigned long intpte_t;
153#define PRIpte "08lx"
154
155unsigned int l1_table_offset(unsigned long linear);
156unsigned int l2_table_offset(unsigned long linear);
157unsigned int l3_table_offset(unsigned long linear);
158unsigned int l4_table_offset(unsigned long linear);
159
160#endif
161
162#ifdef CONFIG_HVM
163
164extern pae_intpte_t pae_l1_identmap[PAE_L1_PT_ENTRIES];
165extern pae_intpte_t pae_l2_identmap[4 * PAE_L2_PT_ENTRIES];
166extern pae_intpte_t pae_l3_identmap[PAE_L3_PT_ENTRIES];
167extern pae_intpte_t pae_l4_identmap[PAE_L4_PT_ENTRIES];
168extern pae_intpte_t pae32_l3_identmap[PAE32_L3_ENTRIES];
169
170extern pse_intpte_t pse_l1_identmap[PSE_L1_PT_ENTRIES];
171extern pse_intpte_t pse_l2_identmap[PSE_L2_PT_ENTRIES];
172
173/* Aliases of the live tables (PAE or PSE as appropriate). */
174extern intpte_t l1_identmap[L1_PT_ENTRIES];
175#if CONFIG_PAGING_LEVELS >= 3
176extern intpte_t l2_identmap[4 *L2_PT_ENTRIES];
177#else
178extern intpte_t l2_identmap[L2_PT_ENTRIES];
179#endif
180
181/* Alias of the pagetable %cr3 points at. */
182extern intpte_t cr3_target[];
183
184#endif /* CONFIG_HVM */
185
186#endif /* !__ASSEMBLY__ */
187
188#endif /* XTF_X86_PAGE_H */
189
190/*
191 * Local variables:
192 * mode: C
193 * c-file-style: "BSD"
194 * c-basic-offset: 4
195 * tab-width: 4
196 * indent-tabs-mode: nil
197 * End:
198 */
Primatives for number manipulation.
Definitions and helpers for PAE pagetable handling.
static unsigned int pae_l1_table_offset(unsigned long linear)
Definition: page-pae.h:43
#define PAE32_L3_ENTRIES
Definition: page-pae.h:29
#define PAE_L4_PT_ENTRIES
Definition: page-pae.h:26
#define PAE_L1_PT_ENTRIES
All PAE pagetables contain 512 entries.
Definition: page-pae.h:23
static unsigned int pae_l3_table_offset(unsigned long linear)
Definition: page-pae.h:51
#define PAE_L2_PT_ENTRIES
Definition: page-pae.h:24
#define PAE_L3_PT_ENTRIES
Definition: page-pae.h:25
static unsigned int pae_l2_table_offset(unsigned long linear)
Definition: page-pae.h:47
uint64_t pae_intpte_t
Integer representation of a PTE.
Definition: page-pae.h:40
Definitions and helpers for PSE pagetable handling.
static unsigned int pse_l2_table_offset(unsigned long linear)
Definition: page-pse.h:40
#define PSE_L1_PT_ENTRIES
All PSE pagetables contain 1024 entries.
Definition: page-pse.h:23
uint32_t pse_intpte_t
Integer representation of a PTE.
Definition: page-pse.h:33
static unsigned int pse_l1_table_offset(unsigned long linear)
Definition: page-pse.h:36
#define PSE_L2_PT_ENTRIES
Definition: page-pse.h:24
#define L2_PT_ENTRIES
Definition: page.h:70
uint64_t paddr_t
Definition: page.h:96
unsigned int l3_table_offset(unsigned long linear)
#define L1_PT_ENTRIES
Definition: page.h:69
unsigned int l4_table_offset(unsigned long linear)
unsigned int l2_table_offset(unsigned long linear)
unsigned long intpte_t
Definition: page.h:152
unsigned int l1_table_offset(unsigned long linear)
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17