Commit | Line | Data |
---|---|---|
1965aae3 PA |
1 | #ifndef _ASM_X86_SEGMENT_H |
2 | #define _ASM_X86_SEGMENT_H | |
cef18950 | 3 | |
4fdf08b5 PA |
4 | /* Constructor for a conventional segment GDT (or LDT) entry */ |
5 | /* This is a macro so it can be used in initializers */ | |
6 | #define GDT_ENTRY(flags, base, limit) \ | |
7 | ((((base) & 0xff000000ULL) << (56-24)) | \ | |
8 | (((flags) & 0x0000f0ffULL) << 40) | \ | |
9 | (((limit) & 0x000f0000ULL) << (48-16)) | \ | |
10 | (((base) & 0x00ffffffULL) << 16) | \ | |
11 | (((limit) & 0x0000ffffULL))) | |
12 | ||
2a6648e6 PA |
13 | /* Simple and small GDT entries for booting only */ |
14 | ||
15 | #define GDT_ENTRY_BOOT_CS 2 | |
16 | #define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8) | |
17 | ||
18 | #define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1) | |
19 | #define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8) | |
20 | ||
88089519 PA |
21 | #define GDT_ENTRY_BOOT_TSS (GDT_ENTRY_BOOT_CS + 2) |
22 | #define __BOOT_TSS (GDT_ENTRY_BOOT_TSS * 8) | |
23 | ||
96a388de | 24 | #ifdef CONFIG_X86_32 |
b23be399 GOC |
25 | /* |
26 | * The layout of the per-CPU GDT under Linux: | |
27 | * | |
28 | * 0 - null | |
29 | * 1 - reserved | |
30 | * 2 - reserved | |
31 | * 3 - reserved | |
32 | * | |
33 | * 4 - unused <==== new cacheline | |
34 | * 5 - unused | |
35 | * | |
36 | * ------- start of TLS (Thread-Local Storage) segments: | |
37 | * | |
38 | * 6 - TLS segment #1 [ glibc's TLS segment ] | |
39 | * 7 - TLS segment #2 [ Wine's %fs Win32 segment ] | |
40 | * 8 - TLS segment #3 | |
41 | * 9 - reserved | |
42 | * 10 - reserved | |
43 | * 11 - reserved | |
44 | * | |
45 | * ------- start of kernel segments: | |
46 | * | |
47 | * 12 - kernel code segment <==== new cacheline | |
48 | * 13 - kernel data segment | |
49 | * 14 - default user CS | |
50 | * 15 - default user DS | |
51 | * 16 - TSS | |
52 | * 17 - LDT | |
53 | * 18 - PNPBIOS support (16->32 gate) | |
54 | * 19 - PNPBIOS support | |
55 | * 20 - PNPBIOS support | |
56 | * 21 - PNPBIOS support | |
57 | * 22 - PNPBIOS support | |
58 | * 23 - APM BIOS support | |
59 | * 24 - APM BIOS support | |
60 | * 25 - APM BIOS support | |
61 | * | |
62 | * 26 - ESPFIX small SS | |
63 | * 27 - per-cpu [ offset to per-cpu data area ] | |
60a5317f | 64 | * 28 - stack_canary-20 [ for stack protector ] |
b23be399 GOC |
65 | * 29 - unused |
66 | * 30 - unused | |
67 | * 31 - TSS for double fault handler | |
68 | */ | |
69 | #define GDT_ENTRY_TLS_MIN 6 | |
70 | #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1) | |
71 | ||
72 | #define GDT_ENTRY_DEFAULT_USER_CS 14 | |
b23be399 GOC |
73 | |
74 | #define GDT_ENTRY_DEFAULT_USER_DS 15 | |
b23be399 GOC |
75 | |
76 | #define GDT_ENTRY_KERNEL_BASE 12 | |
77 | ||
78 | #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0) | |
b23be399 GOC |
79 | |
80 | #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1) | |
b23be399 GOC |
81 | |
82 | #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4) | |
83 | #define GDT_ENTRY_LDT (GDT_ENTRY_KERNEL_BASE + 5) | |
84 | ||
85 | #define GDT_ENTRY_PNPBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 6) | |
86 | #define GDT_ENTRY_APMBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 11) | |
87 | ||
88 | #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14) | |
89 | #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8) | |
90 | ||
91 | #define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15) | |
92 | #ifdef CONFIG_SMP | |
93 | #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8) | |
94 | #else | |
95 | #define __KERNEL_PERCPU 0 | |
96 | #endif | |
97 | ||
60a5317f TH |
98 | #define GDT_ENTRY_STACK_CANARY (GDT_ENTRY_KERNEL_BASE + 16) |
99 | #ifdef CONFIG_CC_STACKPROTECTOR | |
100 | #define __KERNEL_STACK_CANARY (GDT_ENTRY_STACK_CANARY * 8) | |
101 | #else | |
102 | #define __KERNEL_STACK_CANARY 0 | |
103 | #endif | |
104 | ||
b23be399 GOC |
105 | #define GDT_ENTRY_DOUBLEFAULT_TSS 31 |
106 | ||
107 | /* | |
108 | * The GDT has 32 entries | |
109 | */ | |
110 | #define GDT_ENTRIES 32 | |
111 | ||
b23be399 GOC |
112 | /* The PnP BIOS entries in the GDT */ |
113 | #define GDT_ENTRY_PNPBIOS_CS32 (GDT_ENTRY_PNPBIOS_BASE + 0) | |
114 | #define GDT_ENTRY_PNPBIOS_CS16 (GDT_ENTRY_PNPBIOS_BASE + 1) | |
115 | #define GDT_ENTRY_PNPBIOS_DS (GDT_ENTRY_PNPBIOS_BASE + 2) | |
116 | #define GDT_ENTRY_PNPBIOS_TS1 (GDT_ENTRY_PNPBIOS_BASE + 3) | |
117 | #define GDT_ENTRY_PNPBIOS_TS2 (GDT_ENTRY_PNPBIOS_BASE + 4) | |
118 | ||
119 | /* The PnP BIOS selectors */ | |
120 | #define PNP_CS32 (GDT_ENTRY_PNPBIOS_CS32 * 8) /* segment for calling fn */ | |
121 | #define PNP_CS16 (GDT_ENTRY_PNPBIOS_CS16 * 8) /* code segment for BIOS */ | |
122 | #define PNP_DS (GDT_ENTRY_PNPBIOS_DS * 8) /* data segment for BIOS */ | |
123 | #define PNP_TS1 (GDT_ENTRY_PNPBIOS_TS1 * 8) /* transfer data segment */ | |
124 | #define PNP_TS2 (GDT_ENTRY_PNPBIOS_TS2 * 8) /* another data segment */ | |
125 | ||
126 | /* Bottom two bits of selector give the ring privilege level */ | |
127 | #define SEGMENT_RPL_MASK 0x3 | |
128 | /* Bit 2 is table indicator (LDT/GDT) */ | |
129 | #define SEGMENT_TI_MASK 0x4 | |
130 | ||
131 | /* User mode is privilege level 3 */ | |
132 | #define USER_RPL 0x3 | |
133 | /* LDT segment has TI set, GDT has it cleared */ | |
134 | #define SEGMENT_LDT 0x4 | |
135 | #define SEGMENT_GDT 0x0 | |
136 | ||
137 | /* | |
138 | * Matching rules for certain types of segments. | |
139 | */ | |
140 | ||
b23be399 GOC |
141 | /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */ |
142 | #define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8) | |
143 | ||
144 | ||
96a388de | 145 | #else |
b23be399 GOC |
146 | #include <asm/cache.h> |
147 | ||
a939098a GC |
148 | #define GDT_ENTRY_KERNEL32_CS 1 |
149 | #define GDT_ENTRY_KERNEL_CS 2 | |
150 | #define GDT_ENTRY_KERNEL_DS 3 | |
b23be399 | 151 | |
a939098a | 152 | #define __KERNEL32_CS (GDT_ENTRY_KERNEL32_CS * 8) |
b23be399 GOC |
153 | |
154 | /* | |
155 | * we cannot use the same code segment descriptor for user and kernel | |
156 | * -- not even in the long flat mode, because of different DPL /kkeil | |
157 | * The segment offset needs to contain a RPL. Grr. -AK | |
158 | * GDT layout to get 64bit syscall right (sysret hardcodes gdt offsets) | |
159 | */ | |
a939098a GC |
160 | #define GDT_ENTRY_DEFAULT_USER32_CS 4 |
161 | #define GDT_ENTRY_DEFAULT_USER_DS 5 | |
162 | #define GDT_ENTRY_DEFAULT_USER_CS 6 | |
163 | #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3) | |
b23be399 GOC |
164 | #define __USER32_DS __USER_DS |
165 | ||
166 | #define GDT_ENTRY_TSS 8 /* needs two entries */ | |
167 | #define GDT_ENTRY_LDT 10 /* needs two entries */ | |
168 | #define GDT_ENTRY_TLS_MIN 12 | |
169 | #define GDT_ENTRY_TLS_MAX 14 | |
170 | ||
171 | #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */ | |
172 | #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3) | |
173 | ||
174 | /* TLS indexes for 64bit - hardcoded in arch_prctl */ | |
175 | #define FS_TLS 0 | |
176 | #define GS_TLS 1 | |
177 | ||
178 | #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3) | |
179 | #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3) | |
180 | ||
181 | #define GDT_ENTRIES 16 | |
182 | ||
96a388de | 183 | #endif |
cef18950 | 184 | |
a939098a GC |
185 | #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8) |
186 | #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8) | |
187 | #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3) | |
188 | #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3) | |
cef18950 GOC |
189 | #ifndef CONFIG_PARAVIRT |
190 | #define get_kernel_rpl() 0 | |
191 | #endif | |
192 | ||
15ee09b4 GOC |
193 | /* User mode is privilege level 3 */ |
194 | #define USER_RPL 0x3 | |
195 | /* LDT segment has TI set, GDT has it cleared */ | |
196 | #define SEGMENT_LDT 0x4 | |
197 | #define SEGMENT_GDT 0x0 | |
198 | ||
199 | /* Bottom two bits of selector give the ring privilege level */ | |
200 | #define SEGMENT_RPL_MASK 0x3 | |
201 | /* Bit 2 is table indicator (LDT/GDT) */ | |
202 | #define SEGMENT_TI_MASK 0x4 | |
203 | ||
204 | #define IDT_ENTRIES 256 | |
5524ea32 | 205 | #define NUM_EXCEPTION_VECTORS 32 |
15ee09b4 GOC |
206 | #define GDT_SIZE (GDT_ENTRIES * 8) |
207 | #define GDT_ENTRY_TLS_ENTRIES 3 | |
208 | #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8) | |
209 | ||
8866cd9d RM |
210 | #ifdef __KERNEL__ |
211 | #ifndef __ASSEMBLY__ | |
5524ea32 | 212 | extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10]; |
8866cd9d RM |
213 | #endif |
214 | #endif | |
215 | ||
1965aae3 | 216 | #endif /* _ASM_X86_SEGMENT_H */ |