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