]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/asm-x86/segment.h
1ff05a9f55130af956bf800e65c30df8fa0b08a5
[linux-2.6-omap-h63xx.git] / include / asm-x86 / segment.h
1 #ifndef _ASM_X86_SEGMENT_H_
2 #define _ASM_X86_SEGMENT_H_
3
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
12 #ifdef CONFIG_X86_32
13 /*
14  * The layout of the per-CPU GDT under Linux:
15  *
16  *   0 - null
17  *   1 - reserved
18  *   2 - reserved
19  *   3 - reserved
20  *
21  *   4 - unused                 <==== new cacheline
22  *   5 - unused
23  *
24  *  ------- start of TLS (Thread-Local Storage) segments:
25  *
26  *   6 - TLS segment #1                 [ glibc's TLS segment ]
27  *   7 - TLS segment #2                 [ Wine's %fs Win32 segment ]
28  *   8 - TLS segment #3
29  *   9 - reserved
30  *  10 - reserved
31  *  11 - reserved
32  *
33  *  ------- start of kernel segments:
34  *
35  *  12 - kernel code segment            <==== new cacheline
36  *  13 - kernel data segment
37  *  14 - default user CS
38  *  15 - default user DS
39  *  16 - TSS
40  *  17 - LDT
41  *  18 - PNPBIOS support (16->32 gate)
42  *  19 - PNPBIOS support
43  *  20 - PNPBIOS support
44  *  21 - PNPBIOS support
45  *  22 - PNPBIOS support
46  *  23 - APM BIOS support
47  *  24 - APM BIOS support
48  *  25 - APM BIOS support
49  *
50  *  26 - ESPFIX small SS
51  *  27 - per-cpu                        [ offset to per-cpu data area ]
52  *  28 - unused
53  *  29 - unused
54  *  30 - unused
55  *  31 - TSS for double fault handler
56  */
57 #define GDT_ENTRY_TLS_MIN       6
58 #define GDT_ENTRY_TLS_MAX       (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
59
60 #define GDT_ENTRY_DEFAULT_USER_CS       14
61 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS * 8 + 3)
62
63 #define GDT_ENTRY_DEFAULT_USER_DS       15
64 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS * 8 + 3)
65
66 #define GDT_ENTRY_KERNEL_BASE   12
67
68 #define GDT_ENTRY_KERNEL_CS             (GDT_ENTRY_KERNEL_BASE + 0)
69 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
70
71 #define GDT_ENTRY_KERNEL_DS             (GDT_ENTRY_KERNEL_BASE + 1)
72 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
73
74 #define GDT_ENTRY_TSS                   (GDT_ENTRY_KERNEL_BASE + 4)
75 #define GDT_ENTRY_LDT                   (GDT_ENTRY_KERNEL_BASE + 5)
76
77 #define GDT_ENTRY_PNPBIOS_BASE          (GDT_ENTRY_KERNEL_BASE + 6)
78 #define GDT_ENTRY_APMBIOS_BASE          (GDT_ENTRY_KERNEL_BASE + 11)
79
80 #define GDT_ENTRY_ESPFIX_SS             (GDT_ENTRY_KERNEL_BASE + 14)
81 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
82
83 #define GDT_ENTRY_PERCPU                        (GDT_ENTRY_KERNEL_BASE + 15)
84 #ifdef CONFIG_SMP
85 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
86 #else
87 #define __KERNEL_PERCPU 0
88 #endif
89
90 #define GDT_ENTRY_DOUBLEFAULT_TSS       31
91
92 /*
93  * The GDT has 32 entries
94  */
95 #define GDT_ENTRIES 32
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
136 #else
137 #include <asm/cache.h>
138
139 #define __KERNEL_CS     0x10
140 #define __KERNEL_DS     0x18
141
142 #define __KERNEL32_CS   0x08
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  */
150
151 #define __USER32_CS   0x23   /* 4*8+3 */
152 #define __USER_DS     0x2b   /* 5*8+3 */
153 #define __USER_CS     0x33   /* 6*8+3 */
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
173 #endif
174
175 #ifndef CONFIG_PARAVIRT
176 #define get_kernel_rpl()  0
177 #endif
178
179 /* User mode is privilege level 3 */
180 #define USER_RPL                0x3
181 /* LDT segment has TI set, GDT has it cleared */
182 #define SEGMENT_LDT             0x4
183 #define SEGMENT_GDT             0x0
184
185 /* Bottom two bits of selector give the ring privilege level */
186 #define SEGMENT_RPL_MASK        0x3
187 /* Bit 2 is table indicator (LDT/GDT) */
188 #define SEGMENT_TI_MASK         0x4
189
190 #define IDT_ENTRIES 256
191 #define GDT_SIZE (GDT_ENTRIES * 8)
192 #define GDT_ENTRY_TLS_ENTRIES 3
193 #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES * 8)
194
195 #endif