1 #ifndef _ASM_X86_SEGMENT_H_
2 #define _ASM_X86_SEGMENT_H_
4 /* Simple and small GDT entries for booting only */
6 #define GDT_ENTRY_BOOT_CS 2
7 #define __BOOT_CS (GDT_ENTRY_BOOT_CS * 8)
9 #define GDT_ENTRY_BOOT_DS (GDT_ENTRY_BOOT_CS + 1)
10 #define __BOOT_DS (GDT_ENTRY_BOOT_DS * 8)
12 #define GDT_ENTRY_BOOT_TSS (GDT_ENTRY_BOOT_CS + 2)
13 #define __BOOT_TSS (GDT_ENTRY_BOOT_TSS * 8)
17 * The layout of the per-CPU GDT under Linux:
24 * 4 - unused <==== new cacheline
27 * ------- start of TLS (Thread-Local Storage) segments:
29 * 6 - TLS segment #1 [ glibc's TLS segment ]
30 * 7 - TLS segment #2 [ Wine's %fs Win32 segment ]
36 * ------- start of kernel segments:
38 * 12 - kernel code segment <==== new cacheline
39 * 13 - kernel data segment
40 * 14 - default user CS
41 * 15 - default user DS
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
53 * 26 - ESPFIX small SS
54 * 27 - per-cpu [ offset to per-cpu data area ]
58 * 31 - TSS for double fault handler
60 #define GDT_ENTRY_TLS_MIN 6
61 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
63 #define GDT_ENTRY_DEFAULT_USER_CS 14
65 #define GDT_ENTRY_DEFAULT_USER_DS 15
67 #define GDT_ENTRY_KERNEL_BASE 12
69 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
71 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
73 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
74 #define GDT_ENTRY_LDT (GDT_ENTRY_KERNEL_BASE + 5)
76 #define GDT_ENTRY_PNPBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 6)
77 #define GDT_ENTRY_APMBIOS_BASE (GDT_ENTRY_KERNEL_BASE + 11)
79 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
80 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
82 #define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
84 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
86 #define __KERNEL_PERCPU 0
89 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
92 * The GDT has 32 entries
94 #define GDT_ENTRIES 32
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)
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 */
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
115 /* User mode is privilege level 3 */
117 /* LDT segment has TI set, GDT has it cleared */
118 #define SEGMENT_LDT 0x4
119 #define SEGMENT_GDT 0x0
122 * Matching rules for certain types of segments.
125 /* Matches only __KERNEL_CS, ignoring PnP / USER / APM segments */
126 #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
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)
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)
136 #include <asm/cache.h>
138 #define GDT_ENTRY_KERNEL32_CS 1
139 #define GDT_ENTRY_KERNEL_CS 2
140 #define GDT_ENTRY_KERNEL_DS 3
142 #define __KERNEL32_CS (GDT_ENTRY_KERNEL32_CS * 8)
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)
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)
154 #define __USER32_DS __USER_DS
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
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)
164 /* TLS indexes for 64bit - hardcoded in arch_prctl */
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)
171 #define GDT_ENTRIES 16
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)
179 #ifndef CONFIG_PARAVIRT
180 #define get_kernel_rpl() 0
183 /* User mode is privilege level 3 */
185 /* LDT segment has TI set, GDT has it cleared */
186 #define SEGMENT_LDT 0x4
187 #define SEGMENT_GDT 0x0
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
194 #define IDT_ENTRIES 256
195 #define NUM_EXCEPTION_VECTORS 32
196 #define GDT_SIZE (GDT_ENTRIES * 8)
197 #define GDT_ENTRY_TLS_ENTRIES 3
198 #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8)
202 extern const char early_idt_handlers[NUM_EXCEPTION_VECTORS][10];