Print this page
11859 need swapgs mitigation
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/sys/segments.h
+++ new/usr/src/uts/intel/sys/segments.h
1 1 /*
2 2 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
3 3 */
4 4 /*
5 - * Copyright 2018 Joyent, Inc.
5 + * Copyright 2019 Joyent, Inc.
6 6 */
7 7
8 8 #ifndef _SYS_SEGMENTS_H
9 9 #define _SYS_SEGMENTS_H
10 10
11 11 #ifdef __cplusplus
12 12 extern "C" {
13 13 #endif
14 14
15 15 /*
16 16 * Copyright (c) 1989, 1990 William F. Jolitz
17 17 * Copyright (c) 1990 The Regents of the University of California.
18 18 * All rights reserved.
19 19 *
20 20 * This code is derived from software contributed to Berkeley by
21 21 * William Jolitz.
22 22 *
23 23 * Redistribution and use in source and binary forms, with or without
24 24 * modification, are permitted provided that the following conditions
25 25 * are met:
26 26 * 1. Redistributions of source code must retain the above copyright
27 27 * notice, this list of conditions and the following disclaimer.
28 28 * 2. Redistributions in binary form must reproduce the above copyright
29 29 * notice, this list of conditions and the following disclaimer in the
30 30 * documentation and/or other materials provided with the distribution.
31 31 * 3. All advertising materials mentioning features or use of this software
32 32 * must display the following acknowledgement:
33 33 * This product includes software developed by the University of
34 34 * California, Berkeley and its contributors.
35 35 * 4. Neither the name of the University nor the names of its contributors
36 36 * may be used to endorse or promote products derived from this software
37 37 * without specific prior written permission.
38 38 *
39 39 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
40 40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 42 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
43 43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 49 * SUCH DAMAGE.
50 50 *
51 51 * from: @(#)segments.h 7.1 (Berkeley) 5/9/91
52 52 * $FreeBSD: src/sys/i386/include/segments.h,v 1.34 2003/09/10 01:07:04
53 53 * jhb Exp $
54 54 *
55 55 * 386 Segmentation Data Structures and definitions
56 56 * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989
57 57 */
58 58
59 59 #include <sys/tss.h>
60 60
61 61 /*
62 62 * Selector register format
63 63 * CS, DS, ES, FS, GS, SS
64 64 *
65 65 * 15 3 2 1 0
66 66 * +---------------------+---+----+
67 67 * | SI |TI |RPL |
68 68 * +---------------------+---+----+
69 69 *
70 70 * SI = selector index
71 71 * TI = table indicator (0 = GDT, 1 = LDT)
72 72 * RPL = requestor privilege level
73 73 */
74 74 #if !defined(_ASM) || defined(__GNUC_AS__)
75 75 #define IDXTOSEL(s) ((s) << 3) /* index to selector */
76 76 #define SEL_GDT(s, r) (IDXTOSEL(s) | r) /* global sel */
77 77 #else
78 78 #define IDXTOSEL(s) [s << 3]
79 79 #define SEL_GDT(s, r) [IDXTOSEL(s) | r]
80 80 #endif
81 81
82 82 #define SELTOIDX(s) ((s) >> 3) /* selector to index */
83 83
84 84 /*
85 85 * SEL_(KPL,UPL,XPL) is the RPL or DPL value for code and data selectors
86 86 * and their descriptors respectively.
87 87 *
88 88 * TRP_(KPL,UPL,XPL) is used to indicate the DPL for system gates only.
89 89 *
90 90 * This distinction is important to support para-virt guests on the
91 91 * 64-bit hypervisor. Both guest kernel and user run in ring 3 and the
92 92 * hypervisor runs in ring 0. When the kernel creates its trap and
93 93 * interrupt gates it needs a way to prevent any arbitrary int $n
94 94 * instruction from entering a gate that is not expected. The hypervisor
95 95 * allows these gates to have a DPL from 1 to 3. By creating gates
96 96 * with a DPL below user (ring 3) the int $n will generate a #gp fault
97 97 * which the hypervisor catches and forwards to the guest.
98 98 */
99 99 #if defined(__xpv)
100 100
101 101 #define SEL_XPL 0 /* hypervisor privilege level */
102 102 #define SEL_KPL 3 /* both kernel and user in ring 3 */
103 103 #define TRP_KPL 1 /* system gate priv (user blocked) */
104 104 #define TRP_XPL 0 /* system gate priv (hypervisor) */
105 105
106 106 #define IST_DBG 0
107 107
108 108 #else /* __xpv */
109 109
110 110 #define SEL_KPL 0 /* kernel privilege level on metal */
111 111 #define TRP_KPL SEL_KPL /* system gate priv (user blocked) */
112 112
113 113
114 114 #define IST_DF 1
115 115 #define IST_NMI 2
116 116 #define IST_MCE 3
117 117 #define IST_DBG 4
118 118 #define IST_NESTABLE 5
119 119 #define IST_DEFAULT 6
120 120
121 121 #endif /* __xpv */
122 122
123 123 #define IST_NONE 0
124 124
125 125 #define SEL_UPL 3 /* user priority level */
126 126 #define TRP_UPL 3 /* system gate priv (user allowed) */
127 127 #define SEL_TI_LDT 4 /* local descriptor table */
128 128 #define SEL_LDT(s) (IDXTOSEL(s) | SEL_TI_LDT | SEL_UPL) /* local sel */
129 129 #define CPL_MASK 3 /* RPL mask for selector */
130 130 #define SELISLDT(s) (((s) & SEL_TI_LDT) == SEL_TI_LDT)
131 131 #define SELISUPL(s) (((s) & CPL_MASK) == SEL_UPL)
132 132
133 133 #ifndef _ASM
134 134
135 135 typedef uint16_t selector_t; /* selector reigster */
136 136
137 137 /*
138 138 * Hardware descriptor table register format for GDT and IDT.
139 139 */
140 140 #if defined(__amd64)
141 141
142 142 #pragma pack(2)
143 143 typedef struct {
144 144 uint16_t dtr_limit; /* table limit */
145 145 uint64_t dtr_base; /* table base address */
146 146 } desctbr_t;
147 147 #pragma pack()
148 148
149 149 #elif defined(__i386)
150 150
151 151 #pragma pack(2)
152 152 typedef struct {
153 153 uint16_t dtr_limit; /* table limit */
154 154 uint32_t dtr_base; /* table base address */
155 155 } desctbr_t;
156 156 #pragma pack()
157 157
158 158 #endif /* __i386 */
159 159
160 160 /*
161 161 * Functions for loading and storing descriptor table
162 162 * registers.
163 163 */
164 164 extern void rd_idtr(desctbr_t *);
165 165 extern void wr_idtr(desctbr_t *);
166 166 extern void rd_gdtr(desctbr_t *);
167 167 extern void wr_gdtr(desctbr_t *);
168 168 extern void wr_ldtr(selector_t);
169 169 extern selector_t rd_ldtr(void);
170 170 extern void wr_tsr(selector_t);
171 171 extern void kmdb_enter(void);
↓ open down ↓ |
156 lines elided |
↑ open up ↑ |
172 172
173 173 #if defined(__amd64)
174 174
175 175 /*
176 176 * inlines for update_segregs
177 177 */
178 178 extern void __set_ds(selector_t);
179 179 extern void __set_es(selector_t);
180 180 extern void __set_fs(selector_t);
181 181 extern void __set_gs(selector_t);
182 -extern void __swapgs(void);
183 182 #endif /* __amd64 */
184 183
185 184 #if defined(__amd64)
186 185 extern void load_segment_registers(selector_t, selector_t, selector_t,
187 186 selector_t); /* (alphabetical) */
188 187 #elif defined(__i386)
189 188 extern void load_segment_registers(selector_t, selector_t, selector_t,
190 189 selector_t, selector_t, selector_t); /* (alphabetical) */
191 190 #endif /* __i386 */
192 191
193 192 selector_t get_cs_register();
194 193
195 194 #if !defined(__amd64)
196 195
197 196 /*
198 197 * User segment descriptors (code and data).
199 198 * Legacy mode 64-bits wide.
200 199 */
201 200 typedef struct user_desc {
202 201 uint32_t usd_lolimit:16; /* segment limit 15:0 */
203 202 uint32_t usd_lobase:16; /* segment base 15:0 */
204 203 uint32_t usd_midbase:8; /* segment base 23:16 */
205 204 uint32_t usd_type:5; /* segment type, includes S bit */
206 205 uint32_t usd_dpl:2; /* segment descriptor priority level */
207 206 uint32_t usd_p:1; /* segment descriptor present */
208 207 uint32_t usd_hilimit:4; /* segment limit 19:16 */
209 208 uint32_t usd_avl:1; /* available to sw, but not used */
210 209 uint32_t usd_reserved:1; /* unused, ignored */
211 210 uint32_t usd_def32:1; /* default 32 vs 16 bit operand */
212 211 uint32_t usd_gran:1; /* limit units (bytes vs pages) */
213 212 uint32_t usd_hibase:8; /* segment base 31:24 */
214 213 } user_desc_t;
215 214
216 215 #define USEGD_GETBASE(usd) ((usd)->usd_lobase | \
217 216 (usd)->usd_midbase << 16 | \
218 217 (usd)->usd_hibase << (16 + 8))
219 218
220 219 #define USEGD_SETBASE(usd, b) ((usd)->usd_lobase = (b), \
221 220 (usd)->usd_midbase = (b) >> 16, \
222 221 (usd)->usd_hibase = (b) >> (16 + 8))
223 222
224 223 #define USEGD_GETLIMIT(usd) ((usd)->usd_lolimit | \
225 224 (usd)->usd_hilimit << 16)
226 225
227 226 #define USEGD_SETLIMIT(usd, lim) ((usd)->usd_lolimit = lim, \
228 227 (usd)->usd_hilimit = lim >> 16)
229 228
230 229 #define USD_TYPESHIFT 5 /* size of usd_type field */
231 230
232 231 #else /* __amd64 */
233 232
234 233 /*
235 234 * User segment descriptors.
236 235 * Long mode 64-bits wide.
237 236 *
238 237 * In 32-bit compatibility mode (%cs:usd_long=0) all fields are interpreted
239 238 * as in legacy mode for both code and data.
240 239 *
241 240 * In 64-bit mode (%cs:usd_long=1) code segments only have the conforming
242 241 * bit in usd_type, usd_dpl, usd_p, usd_long and usd_def32=0. usd_def32
243 242 * must be zero in 64-bit mode. Setting it to 1 is reserved for future use.
244 243 * All other fields are loaded but ignored by hardware.
245 244 *
246 245 * 64-bit data segments only have usd_p. All other fields are loaded but
247 246 * ignored by hardware when in 64-bit mode.
248 247 */
249 248 typedef struct user_desc {
250 249 uint64_t usd_lolimit:16; /* segment limit 15:0 */
251 250 uint64_t usd_lobase:16; /* segment base 15:0 */
252 251 uint64_t usd_midbase:8; /* segment base 23:16 */
253 252 uint64_t usd_type:5; /* segment type, includes S bit */
254 253 uint64_t usd_dpl:2; /* segment descriptor priority level */
255 254 uint64_t usd_p:1; /* segment descriptor present */
256 255 uint64_t usd_hilimit:4; /* segment limit 19:16 */
257 256 uint64_t usd_avl:1; /* available to sw, but not used */
258 257 uint64_t usd_long:1; /* long mode (%cs only) */
259 258 uint64_t usd_def32:1; /* default 32 vs 16 bit operand */
260 259 uint64_t usd_gran:1; /* limit units (bytes vs page) */
261 260 uint64_t usd_hibase:8; /* segment base 31:24 */
262 261 } user_desc_t;
263 262
264 263 #define USEGD_GETBASE(usd) ((usd)->usd_lobase | \
265 264 (usd)->usd_midbase << 16 | \
266 265 (usd)->usd_hibase << (16 + 8))
267 266
268 267 #define USEGD_SETBASE(usd, b) ((usd)->usd_lobase = (b), \
269 268 (usd)->usd_midbase = (b) >> 16, \
270 269 (usd)->usd_hibase = (b) >> (16 + 8))
271 270
272 271 #define USEGD_GETLIMIT(usd) ((usd)->usd_lolimit | \
273 272 (usd)->usd_hilimit << 16)
274 273
275 274 #define USEGD_SETLIMIT(usd, lim) ((usd)->usd_lolimit = lim, \
276 275 (usd)->usd_hilimit = lim >> 16)
277 276
278 277 #define USD_TYPESHIFT 5 /* size of usd_type field */
279 278
280 279 #endif /* __amd64 */
281 280
282 281 #if !defined(__amd64)
283 282
284 283 /*
285 284 * System segment descriptors for LDT and TSS segments.
286 285 * Legacy mode 64-bits wide.
287 286 */
288 287 typedef struct system_desc {
289 288 uint32_t ssd_lolimit:16; /* segment limit 15:0 */
290 289 uint32_t ssd_lobase:16; /* segment base 15:0 */
291 290 uint32_t ssd_midbase:8; /* segment base 23:16 */
292 291 uint32_t ssd_type:4; /* segment type */
293 292 uint32_t ssd_zero:1; /* must be zero */
294 293 uint32_t ssd_dpl:2; /* segment descriptor priority level */
295 294 uint32_t ssd_p:1; /* segment descriptor present */
296 295 uint32_t ssd_hilimit:4; /* segment limit 19:16 */
297 296 uint32_t ssd_avl:1; /* available to sw, but not used */
298 297 uint32_t ssd_reserved:2; /* unused, ignored */
299 298 uint32_t ssd_gran:1; /* limit unit (bytes vs pages) */
300 299 uint32_t ssd_hibase:8; /* segment base 31:24 */
301 300 } system_desc_t;
302 301
303 302 #else /* __amd64 */
304 303
305 304 /*
306 305 * System segment descriptors for LDT and TSS segments.
307 306 * Long mode 128-bits wide.
308 307 *
309 308 * 32-bit LDT and TSS descriptor types are redefined to 64-bit equivalents.
310 309 * All other legacy types are reserved and illegal.
311 310 */
312 311 typedef struct system_desc {
313 312 uint64_t ssd_lolimit:16; /* segment limit 15:0 */
314 313 uint64_t ssd_lobase:16; /* segment base 15:0 */
315 314 uint64_t ssd_midbase:8; /* segment base 23:16 */
316 315 uint64_t ssd_type:4; /* segment type */
317 316 uint64_t ssd_zero1:1; /* must be zero */
318 317 uint64_t ssd_dpl:2; /* segment descriptor priority level */
319 318 uint64_t ssd_p:1; /* segment descriptor present */
320 319 uint64_t ssd_hilimit:4; /* segment limit 19:16 */
321 320 uint64_t ssd_avl:1; /* available to sw, but not used */
322 321 uint64_t ssd_resv1:2; /* unused, ignored */
323 322 uint64_t ssd_gran:1; /* limit unit (bytes vs pages) */
324 323 uint64_t ssd_hibase:8; /* segment base 31:24 */
325 324 uint64_t ssd_hi64base:32; /* segment base 63:32 */
326 325 uint64_t ssd_resv2:8; /* unused, ignored */
327 326 uint64_t ssd_zero2:5; /* must be zero */
328 327 uint64_t ssd_resv3:19; /* unused, ignored */
329 328 } system_desc_t;
330 329
331 330 #endif /* __amd64 */
332 331
333 332 #define SYSSEGD_SETLIMIT(ssd, lim) ((ssd)->ssd_lolimit = lim, \
334 333 (ssd)->ssd_hilimit = lim >> 16)
335 334
336 335 #define SYSSEGD_GETLIMIT(ssd) (((ssd)->ssd_hilimit << 16) | \
337 336 (ssd)->ssd_lolimit)
338 337
339 338 #if !defined(__amd64)
340 339
341 340 /*
342 341 * System gate segment descriptors for interrupt, trap, call and task gates.
343 342 * Legacy mode 64-bits wide.
344 343 */
345 344 typedef struct gate_desc {
346 345 uint32_t sgd_looffset:16; /* segment code offset 15:0 */
347 346 uint32_t sgd_selector:16; /* target code or task selector */
348 347 uint32_t sgd_stkcpy:5; /* number of stack wds to cpy */
349 348 uint32_t sgd_resv:3; /* unused, ignored */
350 349 uint32_t sgd_type:5; /* segment type, includes S bit */
351 350 uint32_t sgd_dpl:2; /* segment descriptor priority level */
352 351 uint32_t sgd_p:1; /* segment descriptor present */
353 352 uint32_t sgd_hioffset:16; /* code seg off 31:16 */
354 353 } gate_desc_t;
355 354
356 355 #define GATESEG_GETOFFSET(sgd) ((uintptr_t)((sgd)->sgd_looffset | \
357 356 (sgd)->sgd_hioffset << 16))
358 357
359 358 #else /* __amd64 */
360 359
361 360 /*
362 361 * System segment descriptors for interrupt, trap and call gates.
363 362 * Long mode 128-bits wide.
364 363 *
365 364 * 32-bit interrupt, trap and call gate types are redefined to 64-bit
366 365 * equivalents. Task gates along with all other legacy types are reserved
367 366 * and illegal.
368 367 */
369 368 typedef struct gate_desc {
370 369 uint64_t sgd_looffset:16; /* segment code offset 15:0 */
371 370 uint64_t sgd_selector:16; /* target code or task selector */
372 371 uint64_t sgd_ist:3; /* IST table index */
373 372 uint64_t sgd_resv1:5; /* unused, ignored */
374 373 uint64_t sgd_type:5; /* segment type, includes S bit */
375 374 uint64_t sgd_dpl:2; /* segment descriptor priority level */
376 375 uint64_t sgd_p:1; /* segment descriptor present */
377 376 uint64_t sgd_hioffset:16; /* segment code offset 31:16 */
378 377 uint64_t sgd_hi64offset:32; /* segment code offset 63:32 */
379 378 uint64_t sgd_resv2:8; /* unused, ignored */
380 379 uint64_t sgd_zero:5; /* call gate only: must be zero */
381 380 uint64_t sgd_resv3:19; /* unused, ignored */
382 381 } gate_desc_t;
383 382
384 383 #define GATESEG_GETOFFSET(sgd) ((uintptr_t)((sgd)->sgd_looffset | \
385 384 (sgd)->sgd_hioffset << 16 | \
386 385 (uint64_t)((sgd)->sgd_hi64offset) << 32))
387 386
388 387 #endif /* __amd64 */
389 388
390 389 /*
391 390 * functions for initializing and updating segment descriptors.
392 391 */
393 392 #if defined(__amd64)
394 393
395 394 extern void set_usegd(user_desc_t *, uint_t, void *, size_t, uint_t, uint_t,
396 395 uint_t, uint_t);
397 396
398 397 #elif defined(__i386)
399 398
400 399 extern void set_usegd(user_desc_t *, void *, size_t, uint_t, uint_t,
401 400 uint_t, uint_t);
402 401
403 402 #endif /* __i386 */
404 403
405 404 extern uint_t idt_vector_to_ist(uint_t);
406 405
407 406 extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t,
408 407 uint_t, uint_t, uint_t);
409 408
410 409 extern void set_syssegd(system_desc_t *, void *, size_t, uint_t, uint_t);
411 410
412 411 extern void *get_ssd_base(system_desc_t *);
413 412
414 413 extern void gdt_update_usegd(uint_t, user_desc_t *);
415 414
416 415 extern int ldt_update_segd(user_desc_t *, user_desc_t *);
417 416
418 417 #if defined(__xpv)
419 418
420 419 extern int xen_idt_to_trap_info(uint_t, gate_desc_t *, void *);
421 420 extern void xen_idt_write(gate_desc_t *, uint_t);
422 421
423 422 #endif /* __xen */
424 423
425 424 void init_boot_gdt(user_desc_t *);
426 425
427 426 #endif /* _ASM */
428 427
429 428 /*
430 429 * Common segment parameter defintions for granularity, default
431 430 * operand size and operaton mode.
432 431 */
433 432 #define SDP_BYTES 0 /* segment limit scaled to bytes */
434 433 #define SDP_PAGES 1 /* segment limit scaled to pages */
435 434 #define SDP_OP32 1 /* code and data default operand = 32 bits */
436 435 #define SDP_LONG 1 /* long mode code segment (64 bits) */
437 436 #define SDP_SHORT 0 /* compat/legacy code segment (32 bits) */
438 437 /*
439 438 * System segments and gate types.
440 439 *
441 440 * In long mode i386 32-bit ldt, tss, call, interrupt and trap gate
442 441 * types are redefined into 64-bit equivalents.
443 442 */
444 443 #define SDT_SYSNULL 0 /* system null */
445 444 #define SDT_SYS286TSS 1 /* system 286 TSS available */
446 445 #define SDT_SYSLDT 2 /* system local descriptor table */
447 446 #define SDT_SYS286BSY 3 /* system 286 TSS busy */
448 447 #define SDT_SYS286CGT 4 /* system 286 call gate */
449 448 #define SDT_SYSTASKGT 5 /* system task gate */
450 449 #define SDT_SYS286IGT 6 /* system 286 interrupt gate */
451 450 #define SDT_SYS286TGT 7 /* system 286 trap gate */
452 451 #define SDT_SYSNULL2 8 /* system null again */
453 452 #define SDT_SYSTSS 9 /* system TSS available */
454 453 #define SDT_SYSNULL3 10 /* system null again */
455 454 #define SDT_SYSTSSBSY 11 /* system TSS busy */
456 455 #define SDT_SYSCGT 12 /* system call gate */
457 456 #define SDT_SYSNULL4 13 /* system null again */
458 457 #define SDT_SYSIGT 14 /* system interrupt gate */
459 458 #define SDT_SYSTGT 15 /* system trap gate */
460 459
461 460 /*
462 461 * Memory segment types.
463 462 *
464 463 * While in long mode expand-down, writable and accessed type field
465 464 * attributes are ignored. Only the conforming bit is loaded by hardware
466 465 * for long mode code segment descriptors.
467 466 */
468 467 #define SDT_MEMRO 16 /* read only */
469 468 #define SDT_MEMROA 17 /* read only accessed */
470 469 #define SDT_MEMRW 18 /* read write */
471 470 #define SDT_MEMRWA 19 /* read write accessed */
472 471 #define SDT_MEMROD 20 /* read only expand dwn limit */
473 472 #define SDT_MEMRODA 21 /* read only expand dwn limit accessed */
474 473 #define SDT_MEMRWD 22 /* read write expand dwn limit */
475 474 #define SDT_MEMRWDA 23 /* read write expand dwn limit accessed */
476 475 #define SDT_MEME 24 /* execute only */
477 476 #define SDT_MEMEA 25 /* execute only accessed */
478 477 #define SDT_MEMER 26 /* execute read */
479 478 #define SDT_MEMERA 27 /* execute read accessed */
480 479 #define SDT_MEMEC 28 /* execute only conforming */
481 480 #define SDT_MEMEAC 29 /* execute only accessed conforming */
482 481 #define SDT_MEMERC 30 /* execute read conforming */
483 482 #define SDT_MEMERAC 31 /* execute read accessed conforming */
484 483
485 484 /* These bits are within the "type" field, like the values above. */
486 485 #define SDT_A 0x01 /* accessed bit */
487 486 #define SDT_S 0x10 /* S-bit at the top of "type" for usegs */
488 487
489 488 /*
490 489 * Entries in the Interrupt Descriptor Table (IDT)
491 490 */
492 491 #define IDT_DE 0 /* #DE: Divide Error */
493 492 #define IDT_DB 1 /* #DB: Debug */
494 493 #define IDT_NMI 2 /* Nonmaskable External Interrupt */
495 494 #define IDT_BP 3 /* #BP: Breakpoint */
496 495 #define IDT_OF 4 /* #OF: Overflow */
497 496 #define IDT_BR 5 /* #BR: Bound Range Exceeded */
498 497 #define IDT_UD 6 /* #UD: Undefined/Invalid Opcode */
499 498 #define IDT_NM 7 /* #NM: No Math Coprocessor */
500 499 #define IDT_DF 8 /* #DF: Double Fault */
501 500 #define IDT_FPUGP 9 /* Coprocessor Segment Overrun */
502 501 #define IDT_TS 10 /* #TS: Invalid TSS */
503 502 #define IDT_NP 11 /* #NP: Segment Not Present */
504 503 #define IDT_SS 12 /* #SS: Stack Segment Fault */
505 504 #define IDT_GP 13 /* #GP: General Protection Fault */
506 505 #define IDT_PF 14 /* #PF: Page Fault */
507 506 #define IDT_MF 16 /* #MF: FPU Floating-Point Error */
508 507 #define IDT_AC 17 /* #AC: Alignment Check */
509 508 #define IDT_MC 18 /* #MC: Machine Check */
510 509 #define IDT_XF 19 /* #XF: SIMD Floating-Point Exception */
511 510 #define NIDT 256 /* size in entries of IDT */
512 511
513 512 /*
514 513 * Entries in the Global Descriptor Table (GDT)
515 514 *
516 515 * We make sure to space the system descriptors (LDT's, TSS')
517 516 * such that they are double gdt slot aligned. This is because
518 517 * in long mode system segment decriptors expand to 128 bits.
519 518 *
520 519 * GDT_LWPFS and GDT_LWPGS must be the same for both 32 and 64-bit
521 520 * kernels. See setup_context in libc. 64-bit processes must set
522 521 * %fs or %gs to null selector to use 64-bit fsbase or gsbase
523 522 * respectively.
524 523 */
525 524 #define GDT_NULL 0 /* null */
526 525 #define GDT_B32DATA 1 /* dboot 32 bit data descriptor */
527 526 #define GDT_B32CODE 2 /* dboot 32 bit code descriptor */
528 527 #define GDT_B16CODE 3 /* bios call 16 bit code descriptor */
529 528 #define GDT_B16DATA 4 /* bios call 16 bit data descriptor */
530 529 #define GDT_B64CODE 5 /* dboot 64 bit code descriptor */
531 530 #define GDT_BGSTMP 7 /* kmdb descriptor only used early in boot */
532 531 #define GDT_CPUID 16 /* store numeric id of current CPU */
533 532
534 533 #if defined(__amd64)
535 534
536 535 #define GDT_KCODE 6 /* kernel code seg %cs */
537 536 #define GDT_KDATA 7 /* kernel data seg %ds */
538 537 #define GDT_U32CODE 8 /* 32-bit process on 64-bit kernel %cs */
539 538 #define GDT_UDATA 9 /* user data seg %ds (32 and 64 bit) */
540 539 #define GDT_UCODE 10 /* native user code seg %cs */
541 540 #define GDT_LDT 12 /* (12-13) LDT for current process */
542 541 #define GDT_KTSS 14 /* (14-15) kernel tss */
543 542 #define GDT_FS GDT_NULL /* kernel %fs segment selector */
544 543 #define GDT_GS GDT_NULL /* kernel %gs segment selector */
545 544 #define GDT_LWPFS 55 /* lwp private %fs segment selector (32-bit) */
546 545 #define GDT_LWPGS 56 /* lwp private %gs segment selector (32-bit) */
547 546 #define GDT_BRANDMIN 57 /* first entry in GDT for brand usage */
548 547 #define GDT_BRANDMAX 61 /* last entry in GDT for brand usage */
549 548 #define NGDT 62 /* number of entries in GDT */
550 549
551 550 /*
552 551 * This selector is only used in the temporary GDT used to bring additional
553 552 * CPUs from 16-bit real mode into long mode in real_mode_start().
554 553 */
555 554 #define TEMPGDT_KCODE64 1 /* 64-bit code selector */
556 555
557 556 #elif defined(__i386)
558 557
559 558 #define GDT_LDT 40 /* LDT for current process */
560 559 #define GDT_KTSS 42 /* kernel tss */
561 560 #define GDT_KCODE 43 /* kernel code seg %cs */
562 561 #define GDT_KDATA 44 /* kernel data seg %ds */
563 562 #define GDT_UCODE 45 /* native user code seg %cs */
564 563 #define GDT_UDATA 46 /* user data seg %ds (32 and 64 bit) */
565 564 #define GDT_DBFLT 47 /* double fault #DF selector */
566 565 #define GDT_FS 53 /* kernel %fs segment selector */
567 566 #define GDT_GS 54 /* kernel %gs segment selector */
568 567 #define GDT_LWPFS 55 /* lwp private %fs segment selector */
569 568 #define GDT_LWPGS 56 /* lwp private %gs segment selector */
570 569 #define GDT_BRANDMIN 57 /* first entry in GDT for brand usage */
571 570 #define GDT_BRANDMAX 61 /* last entry in GDT for brand usage */
572 571 #if !defined(__xpv)
573 572 #define NGDT 90 /* number of entries in GDT */
574 573 #else
575 574 #define NGDT 512 /* single 4K page for the hypervisor */
576 575 #endif
577 576
578 577 #endif /* __i386 */
579 578
580 579 /*
581 580 * Convenient selector definitions.
582 581 */
583 582
584 583 /*
585 584 * XXPV 64 bit Xen only allows the guest %cs/%ss be the private ones it
586 585 * provides, not the ones we create for ourselves. See FLAT_RING3_CS64 in
587 586 * public/arch-x86_64.h
588 587 *
589 588 * 64-bit Xen runs paravirtual guests in ring 3 but emulates them running in
590 589 * ring 0 by clearing CPL in %cs value pushed on guest exception stacks.
591 590 * Therefore we will have KCS_SEL value indicate ring 0 and use that everywhere
592 591 * in the kernel. But in the few files where we initialize segment registers or
593 592 * create and update descriptors we will explicity OR in SEL_KPL (ring 3) for
594 593 * kernel %cs. See desctbls.c for an example.
595 594 */
596 595
597 596 #if defined(__xpv) && defined(__amd64)
598 597 #define KCS_SEL 0xe030 /* FLAT_RING3_CS64 & 0xFFF0 */
599 598 #define KDS_SEL 0xe02b /* FLAT_RING3_SS64 */
600 599 #else
601 600 #define KCS_SEL SEL_GDT(GDT_KCODE, SEL_KPL)
602 601 #define KDS_SEL SEL_GDT(GDT_KDATA, SEL_KPL)
603 602 #endif
604 603
605 604 #define UCS_SEL SEL_GDT(GDT_UCODE, SEL_UPL)
606 605 #if defined(__amd64)
607 606 #define TEMP_CS64_SEL SEL_GDT(TEMPGDT_KCODE64, SEL_KPL)
608 607 #define U32CS_SEL SEL_GDT(GDT_U32CODE, SEL_UPL)
609 608 #endif
610 609
611 610 #define UDS_SEL SEL_GDT(GDT_UDATA, SEL_UPL)
612 611 #define ULDT_SEL SEL_GDT(GDT_LDT, SEL_KPL)
613 612 #define KTSS_SEL SEL_GDT(GDT_KTSS, SEL_KPL)
614 613 #define DFTSS_SEL SEL_GDT(GDT_DBFLT, SEL_KPL)
615 614 #define KFS_SEL 0
616 615 #define KGS_SEL SEL_GDT(GDT_GS, SEL_KPL)
617 616 #define LWPFS_SEL SEL_GDT(GDT_LWPFS, SEL_UPL)
618 617 #define LWPGS_SEL SEL_GDT(GDT_LWPGS, SEL_UPL)
619 618 #define BRANDMIN_SEL SEL_GDT(GDT_BRANDMIN, SEL_UPL)
620 619 #define BRANDMAX_SEL SEL_GDT(GDT_BRANDMAX, SEL_UPL)
621 620
622 621 #define B64CODE_SEL SEL_GDT(GDT_B64CODE, SEL_KPL)
623 622 #define B32CODE_SEL SEL_GDT(GDT_B32CODE, SEL_KPL)
624 623 #define B32DATA_SEL SEL_GDT(GDT_B32DATA, SEL_KPL)
625 624 #define B16CODE_SEL SEL_GDT(GDT_B16CODE, SEL_KPL)
626 625 #define B16DATA_SEL SEL_GDT(GDT_B16DATA, SEL_KPL)
627 626
628 627 /*
629 628 * Temporary %gs descriptor used by kmdb with -d option. Only lives
630 629 * in boot's GDT and is not copied into kernel's GDT from boot.
631 630 */
632 631 #define KMDBGS_SEL SEL_GDT(GDT_BGSTMP, SEL_KPL)
633 632
634 633 /*
635 634 * Selector used for kdi_idt when kmdb has taken over the IDT.
636 635 */
637 636 #if defined(__amd64)
638 637 #define KMDBCODE_SEL B64CODE_SEL
639 638 #else
640 639 #define KMDBCODE_SEL B32CODE_SEL
641 640 #endif
642 641
643 642 /*
644 643 * Entries in default Local Descriptor Table (LDT) for every process.
645 644 */
646 645 #define LDT_SYSCALL 0 /* call gate for libc.a (obsolete) */
647 646 #define LDT_SIGCALL 1 /* EOL me, call gate for static sigreturn */
648 647 #define LDT_RESVD1 2 /* old user %cs */
649 648 #define LDT_RESVD2 3 /* old user %ds */
650 649 #define LDT_ALTSYSCALL 4 /* alternate call gate for system calls */
651 650 #define LDT_ALTSIGCALL 5 /* EOL me, alternate call gate for sigreturn */
652 651 #define LDT_UDBASE 6 /* user descriptor base index */
653 652 #define MINNLDT 512 /* Current min solaris ldt size (1 4K page) */
654 653 #define MAXNLDT 8192 /* max solaris ldt size (16 4K pages) */
655 654
656 655 #ifdef _KERNEL
657 656 #define LDT_CPU_SIZE (16 * 4096) /* Size of kernel per-CPU allocation */
658 657 #endif
659 658
660 659 #ifndef _ASM
661 660
662 661 extern gate_desc_t *idt0;
663 662 extern desctbr_t idt0_default_reg;
664 663 extern user_desc_t *gdt0;
665 664
666 665 extern user_desc_t zero_udesc;
667 666 extern user_desc_t null_udesc;
668 667 extern system_desc_t null_sdesc;
669 668
670 669 #if defined(__amd64)
671 670 extern user_desc_t zero_u32desc;
672 671 #endif
673 672 #if defined(__amd64)
674 673 extern user_desc_t ucs_on;
675 674 extern user_desc_t ucs_off;
676 675 extern user_desc_t ucs32_on;
677 676 extern user_desc_t ucs32_off;
678 677 #endif /* __amd64 */
679 678
680 679 extern tss_t *ktss0;
681 680
682 681 #if defined(__i386)
683 682 extern tss_t *dftss0;
684 683 #endif /* __i386 */
685 684
686 685 extern void div0trap(), dbgtrap(), nmiint(), brktrap(), ovflotrap();
687 686 extern void boundstrap(), invoptrap(), ndptrap();
688 687 #if !defined(__xpv)
689 688 extern void syserrtrap();
690 689 #endif
691 690 extern void invaltrap(), invtsstrap(), segnptrap(), stktrap();
692 691 extern void gptrap(), pftrap(), ndperr();
693 692 extern void overrun(), resvtrap();
694 693 extern void _start(), cmnint();
695 694 extern void achktrap(), mcetrap();
696 695 extern void xmtrap();
697 696 extern void fasttrap();
698 697 extern void dtrace_ret();
699 698
700 699 /* KPTI trampolines */
701 700 extern void tr_invaltrap();
702 701 extern void tr_div0trap(), tr_dbgtrap(), tr_nmiint(), tr_brktrap();
703 702 extern void tr_ovflotrap(), tr_boundstrap(), tr_invoptrap(), tr_ndptrap();
704 703 #if !defined(__xpv)
705 704 extern void tr_syserrtrap();
706 705 #endif
707 706 extern void tr_invaltrap(), tr_invtsstrap(), tr_segnptrap(), tr_stktrap();
708 707 extern void tr_gptrap(), tr_pftrap(), tr_ndperr();
709 708 extern void tr_overrun(), tr_resvtrap();
710 709 extern void tr_achktrap(), tr_mcetrap();
711 710 extern void tr_xmtrap();
712 711 extern void tr_fasttrap();
713 712 extern void tr_dtrace_ret();
714 713
715 714 #if !defined(__amd64)
716 715 extern void pentium_pftrap();
717 716 #endif
718 717
719 718 extern uint64_t kpti_enable;
720 719
721 720 #endif /* _ASM */
722 721
723 722 #ifdef __cplusplus
724 723 }
725 724 #endif
726 725
727 726 #endif /* _SYS_SEGMENTS_H */
↓ open down ↓ |
535 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX