Xen Test Framework
pagetables.S
Go to the documentation of this file.
1#include <xtf/asm_macros.h>
2
3#include <arch/page.h>
4
5#define PAGETABLE_START(sym) \
6 GLOBAL(sym)
7
8#define PAGETABLE_END(sym) \
9 .type sym, STT_OBJECT; \
10 SIZE(sym)
11
12#define _PAGE_LEAF (_PAGE_AD + _PAGE_RW + _PAGE_PRESENT)
13#define _PAGE_SUPER (_PAGE_PSE + _PAGE_LEAF)
14#define _PAGE_NONLEAF (_PAGE_USER + _PAGE_LEAF)
15
16#define PAE_IDX(sym) ((. - (sym)) / PAE_PTE_SIZE)
17#define PSE_IDX(sym) ((. - (sym)) / PSE_PTE_SIZE)
18
19 .section ".data.page_aligned", "aw"
20 .p2align PAGE_SHIFT
21
22/* PAE mappings of first 2M of memory in 4k pages. Uses 1x 4k page. */
23PAGETABLE_START(pae_l1_identmap)
24 .long 0, 0 /* Unmap page at 0 to catch errors with NULL pointers. */
25 .rept PAE_L1_PT_ENTRIES - 1
26 .long (PAE_IDX(pae_l1_identmap) << PAE_L1_PT_SHIFT) + _PAGE_LEAF
27 .long 0
28 .endr
29PAGETABLE_END(pae_l1_identmap)
30
31/* PAE mappings up to 4G, mostly in 2M superpages. Uses 4x 4k pages. */
32PAGETABLE_START(pae_l2_identmap)
33 .long pae_l1_identmap + _PAGE_NONLEAF
34 .long 0
35 .rept (4 * PAE_L2_PT_ENTRIES) - 1
36 .long (PAE_IDX(pae_l2_identmap) << PAE_L2_PT_SHIFT) + _PAGE_SUPER
37 .long 0
38 .endr
39PAGETABLE_END(pae_l2_identmap)
40.Lpae_l2_identmap_end:
41
42/* PAE l3 pagetable. Maps 4x l2 tables. */
43PAGETABLE_START(pae_l3_identmap)
44 .rept 4
45 .long pae_l2_identmap + (PAE_IDX(pae_l3_identmap) << PAGE_SHIFT) + _PAGE_NONLEAF
46 .long 0
47 .endr
48 .fill PAE_L3_PT_ENTRIES - 4, 8, 0
49PAGETABLE_END(pae_l3_identmap)
50
51/* PAE l4 pagetable. Maps 1x l3 table. */
52PAGETABLE_START(pae_l4_identmap)
53 .long pae_l3_identmap + _PAGE_NONLEAF
54 .long 0
55 .fill PAE_L4_PT_ENTRIES - 1, 8, 0
56PAGETABLE_END(pae_l4_identmap)
57
58/* PSE mappings of the first 4M of memory in 4k pages. Uses 1x 4k page. */
59PAGETABLE_START(pse_l1_identmap)
60 .long 0 /* Unmap page at 0 to catch errors with NULL pointers. */
61 .rept PSE_L1_PT_ENTRIES - 1
62 .long (PSE_IDX(pse_l1_identmap) << PSE_L1_PT_SHIFT) + _PAGE_LEAF
63 .endr
64PAGETABLE_END(pse_l1_identmap)
65
66/* PSE mappings up to 4G, mostly in 4M superpages. Uses 1x 4k page. */
67PAGETABLE_START(pse_l2_identmap)
68 .long pse_l1_identmap + _PAGE_NONLEAF
69 .rept PSE_L2_PT_ENTRIES - 1
70 .long (PSE_IDX(pse_l2_identmap) << PSE_L2_PT_SHIFT) + _PAGE_SUPER
71 .endr
72PAGETABLE_END(pse_l2_identmap)
73.Lpse_l2_identmap_end:
74
75 .data
76 .align 32
77/* PAE l3 32bit quad. Contains 4 64bit entries. */
78PAGETABLE_START(pae32_l3_identmap)
79 .rept PAE32_L3_ENTRIES
80 .long pae_l2_identmap + (PAE_IDX(pae32_l3_identmap) << PAGE_SHIFT) + _PAGE_PRESENT
81 .long 0
82 .endr
83PAGETABLE_END(pae32_l3_identmap)
84
85
86 /* Aliases of the live tables (PAE or PSE as appropriate). */
87#if CONFIG_PAGING_LEVELS >= 3
88 .set l1_identmap, pae_l1_identmap
89 .set l2_identmap, pae_l2_identmap
90 .set l2_identmap_end, .Lpae_l2_identmap_end
91#else
92 .set l1_identmap, pse_l1_identmap
93 .set l2_identmap, pse_l2_identmap
94 .set l2_identmap_end, .Lpse_l2_identmap_end
95#endif
96 .global l1_identmap
97 .global l2_identmap
98 .global l2_identmap_end
99
100 /* Alias of the pagetable %cr3 points at. */
101#if CONFIG_PAGING_LEVELS > 0
102
103#if CONFIG_PAGING_LEVELS == 2
104 .set cr3_target, pse_l2_identmap
105#elif CONFIG_PAGING_LEVELS == 3
106 .set cr3_target, pae32_l3_identmap
107#elif CONFIG_PAGING_LEVELS == 4
108 .set cr3_target, pae_l4_identmap
109#else
110# error Bad paging mode
111#endif
112
113#else
114 .set cr3_target, 0
115#endif
116 .global cr3_target
117
118/*
119 * Local variables:
120 * tab-width: 8
121 * indent-tabs-mode: nil
122 * End:
123 */