Xen Test Framework
segment.h
Go to the documentation of this file.
1 #ifndef XTF_X86_SEGMENT_H
2 #define XTF_X86_SEGMENT_H
3 
4 #include <xtf/types.h>
5 
6 #include <xen/arch-x86/xen.h>
7 
8 /*
9  * GDT layout:
10  *
11  * For simplicitly, the gdt is shared as much as possible between different
12  * environments.
13  *
14  * 0 - null
15  * 1 - 64bit supervisor code
16  * 2 - 32bit supervisor code
17  * 3 - 32bit supervisor data
18  * 4 - 64bit userspace code
19  * 5 - 32bit userspace code
20  * 6 - 32bit userspace data
21  * 7/8 - TSS (two slots in long mode)
22  * 8 - DF TSS (32bit only)
23  *
24  * 9-14 - Available for test use
25  */
26 
27 #define GDTE_CS64_DPL0 1
28 #define GDTE_CS32_DPL0 2
29 #define GDTE_DS32_DPL0 3
30 #define GDTE_CS64_DPL3 4
31 #define GDTE_CS32_DPL3 5
32 #define GDTE_DS32_DPL3 6
33 
34 #define GDTE_TSS 7
35 #define GDTE_TSS_DF 8
36 
37 #define GDTE_AVAIL0 9
38 #define GDTE_AVAIL1 10
39 #define GDTE_AVAIL2 11
40 #define GDTE_AVAIL3 12
41 #define GDTE_AVAIL4 13
42 #define GDTE_AVAIL5 14
43 
44 #define NR_GDT_ENTRIES 15
45 
46 /*
47  * HVM guests use the GDT directly.
48  */
49 #if defined(CONFIG_HVM)
50 
51 #ifdef __x86_64__
52 
53 #define __KERN_CS (GDTE_CS64_DPL0 * 8)
54 #define __KERN_DS (0)
55 #define __KERN_CS32 (GDTE_CS32_DPL0 * 8)
56 #define __KERN_DS32 __KERN_DS
57 
58 #define __USER_CS (GDTE_CS64_DPL3 * 8 + 3)
59 #define __USER_DS (GDTE_DS32_DPL3 * 8 + 3)
60 #define __USER_CS32 (GDTE_CS32_DPL3 * 8 + 3)
61 #define __USER_DS32 __USER_DS
62 
63 #else /* __x86_64__ */
64 
65 #define __KERN_CS (GDTE_CS32_DPL0 * 8)
66 #define __KERN_DS (GDTE_DS32_DPL0 * 8)
67 #define __KERN_CS32 __KERN_CS
68 #define __KERN_DS32 __KERN_DS
69 
70 #define __USER_CS (GDTE_CS32_DPL3 * 8 + 3)
71 #define __USER_DS (GDTE_DS32_DPL3 * 8 + 3)
72 #define __USER_CS32 __USER_CS
73 #define __USER_DS32 __USER_DS
74 
75 #endif /* __x86_64__ */
76 
77 #define TSS_SEL (GDTE_TSS * 8)
78 
79 #endif /* CONFIG_HVM */
80 
81 /*
82  * PV guests by default use the Xen ABI-provided selectors.
83  */
84 #if defined(CONFIG_PV)
85 
86 #ifdef __x86_64__
87 /*
88  * 64bit PV guest kernels run in cpl3, but exception frames generated by Xen
89  * report cpl0 when interrupting kernel mode. Trim the kernel selectors down
90  * to rpl0 so they match the exception frames; Xen will take care of bumping
91  * rpl back to 3 when required.
92  *
93  * In Long mode, it is permitted to have NULL selectors for the plain data
94  * segment selectors (this is expressed in the Xen ABI), but not for %ss. As
95  * __{KERN,USER}_DS are used for all data selectors including %ss, use the
96  * FLAT_RING3_SS64 rather than FLAT_RING3_DS64.
97  */
98 #define __KERN_CS (FLAT_RING3_CS64 & ~3)
99 #define __KERN_DS (FLAT_RING3_SS64 & ~3)
100 #define __KERN_CS32 (FLAT_RING3_CS32 & ~3)
101 #define __KERN_DS32 __KERN_DS
102 
103 #define __USER_CS FLAT_RING3_CS64
104 #define __USER_DS FLAT_RING3_SS64
105 #define __USER_CS32 FLAT_RING3_CS32
106 #define __USER_DS32 __USER_DS
107 
108 #else /* __x86_64__ */
109 
110 #define __KERN_CS FLAT_RING1_CS
111 #define __KERN_DS FLAT_RING1_DS
112 #define __KERN_CS32 __KERN_CS
113 #define __KERN_DS32 __KERN_DS
114 
115 #define __USER_CS FLAT_RING3_CS
116 #define __USER_DS FLAT_RING3_DS
117 #define __USER_CS32 __USER_CS
118 #define __USER_DS32 __USER_DS
119 
120 #endif /* __x86_64__ */
121 
122 #endif /* CONFIG_PV */
123 
124 #endif /* XTF_X86_SEGMENT_H */
125 
126 /*
127  * Local variables:
128  * mode: C
129  * c-file-style: "BSD"
130  * c-basic-offset: 4
131  * tab-width: 4
132  * indent-tabs-mode: nil
133  * End:
134  */
Common declarations for all tests.