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