Xen Test Framework
arch
x86
include
arch
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
#endif
/* CONFIG_HVM */
78
79
/*
80
* PV guests by default use the Xen ABI-provided selectors.
81
*/
82
#if defined(CONFIG_PV)
83
84
#ifdef __x86_64__
85
/*
86
* 64bit PV guest kernels run in cpl3, but exception frames generated by Xen
87
* report cpl0 when interrupting kernel mode. Trim the kernel selectors down
88
* to rpl0 so they match the exception frames; Xen will take care of bumping
89
* rpl back to 3 when required.
90
*
91
* In Long mode, it is permitted to have NULL selectors for the plain data
92
* segment selectors (this is expressed in the Xen ABI), but not for %ss. As
93
* __{KERN,USER}_DS are used for all data selectors including %ss, use the
94
* FLAT_RING3_SS64 rather than FLAT_RING3_DS64.
95
*/
96
#define __KERN_CS (FLAT_RING3_CS64 & ~3)
97
#define __KERN_DS (FLAT_RING3_SS64 & ~3)
98
#define __KERN_CS32 (FLAT_RING3_CS32 & ~3)
99
#define __KERN_DS32 __KERN_DS
100
101
#define __USER_CS FLAT_RING3_CS64
102
#define __USER_DS FLAT_RING3_SS64
103
#define __USER_CS32 FLAT_RING3_CS32
104
#define __USER_DS32 __USER_DS
105
106
#else
/* __x86_64__ */
107
108
#define __KERN_CS FLAT_RING1_CS
109
#define __KERN_DS FLAT_RING1_DS
110
#define __KERN_CS32 __KERN_CS
111
#define __KERN_DS32 __KERN_DS
112
113
#define __USER_CS FLAT_RING3_CS
114
#define __USER_DS FLAT_RING3_DS
115
#define __USER_CS32 __USER_CS
116
#define __USER_DS32 __USER_DS
117
118
#endif
/* __x86_64__ */
119
120
#endif
/* CONFIG_PV */
121
122
#endif
/* XTF_X86_SEGMENT_H */
123
124
/*
125
* Local variables:
126
* mode: C
127
* c-file-style: "BSD"
128
* c-basic-offset: 4
129
* tab-width: 4
130
* indent-tabs-mode: nil
131
* End:
132
*/
types.h
Common declarations for all tests.
xen.h
Generated by
1.8.13