Print this page
Bring back LX zones.
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 5 * Copyright 2011 Joyent, Inc. All rights reserved.
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 #if defined(__amd64)
102 102
103 103 #define SEL_XPL 0 /* hypervisor privilege level */
104 104 #define SEL_KPL 3 /* both kernel and user in ring 3 */
105 105 #define TRP_KPL 1 /* system gate priv (user blocked) */
106 106
107 107 #elif defined(__i386)
108 108
109 109 #define SEL_XPL 0 /* hypervisor privilege level */
110 110 #define SEL_KPL 1 /* kernel privilege level */
111 111 #define TRP_KPL SEL_KPL /* system gate priv (user blocked) */
112 112
113 113 #endif /* __i386 */
114 114
115 115 #define TRP_XPL 0 /* system gate priv (hypervisor) */
116 116
117 117 #else /* __xpv */
118 118
119 119 #define SEL_KPL 0 /* kernel privilege level on metal */
120 120 #define TRP_KPL SEL_KPL /* system gate priv (user blocked) */
121 121
122 122 #endif /* __xpv */
123 123
124 124 #define SEL_UPL 3 /* user priority level */
125 125 #define TRP_UPL 3 /* system gate priv (user allowed) */
126 126 #define SEL_TI_LDT 4 /* local descriptor table */
127 127 #define SEL_LDT(s) (IDXTOSEL(s) | SEL_TI_LDT | SEL_UPL) /* local sel */
128 128 #define CPL_MASK 3 /* RPL mask for selector */
129 129 #define SELISLDT(s) (((s) & SEL_TI_LDT) == SEL_TI_LDT)
130 130 #define SELISUPL(s) (((s) & CPL_MASK) == SEL_UPL)
131 131
132 132 #ifndef _ASM
133 133
134 134 typedef uint16_t selector_t; /* selector reigster */
135 135
136 136 /*
137 137 * Hardware descriptor table register format for GDT and IDT.
138 138 */
139 139 #if defined(__amd64)
140 140
141 141 #pragma pack(2)
142 142 typedef struct {
143 143 uint16_t dtr_limit; /* table limit */
144 144 uint64_t dtr_base; /* table base address */
145 145 } desctbr_t;
146 146 #pragma pack()
147 147
148 148 #elif defined(__i386)
149 149
150 150 #pragma pack(2)
151 151 typedef struct {
152 152 uint16_t dtr_limit; /* table limit */
153 153 uint32_t dtr_base; /* table base address */
154 154 } desctbr_t;
155 155 #pragma pack()
156 156
157 157 #endif /* __i386 */
158 158
159 159 /*
160 160 * Functions for loading and storing descriptor table
161 161 * registers.
162 162 */
163 163 extern void rd_idtr(desctbr_t *);
164 164 extern void wr_idtr(desctbr_t *);
165 165 extern void rd_gdtr(desctbr_t *);
166 166 extern void wr_gdtr(desctbr_t *);
167 167 extern void wr_ldtr(selector_t);
168 168 extern selector_t rd_ldtr(void);
169 169 extern void wr_tsr(selector_t);
170 170 extern void kmdb_enter(void);
171 171
172 172 #if defined(__amd64)
173 173
174 174 /*
175 175 * inlines for update_segregs
176 176 */
177 177 extern void __set_ds(selector_t);
178 178 extern void __set_es(selector_t);
179 179 extern void __set_fs(selector_t);
180 180 extern void __set_gs(selector_t);
181 181 extern void __swapgs(void);
182 182 #endif /* __amd64 */
183 183
184 184 #if defined(__amd64)
185 185 extern void load_segment_registers(selector_t, selector_t, selector_t,
186 186 selector_t); /* (alphabetical) */
187 187 #elif defined(__i386)
188 188 extern void load_segment_registers(selector_t, selector_t, selector_t,
189 189 selector_t, selector_t, selector_t); /* (alphabetical) */
190 190 #endif /* __i386 */
191 191
192 192 selector_t get_cs_register();
193 193
194 194 #if !defined(__amd64)
195 195
196 196 /*
197 197 * User segment descriptors (code and data).
198 198 * Legacy mode 64-bits wide.
199 199 */
200 200 typedef struct user_desc {
201 201 uint32_t usd_lolimit:16; /* segment limit 15:0 */
202 202 uint32_t usd_lobase:16; /* segment base 15:0 */
203 203 uint32_t usd_midbase:8; /* segment base 23:16 */
204 204 uint32_t usd_type:5; /* segment type, includes S bit */
205 205 uint32_t usd_dpl:2; /* segment descriptor priority level */
206 206 uint32_t usd_p:1; /* segment descriptor present */
207 207 uint32_t usd_hilimit:4; /* segment limit 19:16 */
208 208 uint32_t usd_avl:1; /* available to sw, but not used */
209 209 uint32_t usd_reserved:1; /* unused, ignored */
210 210 uint32_t usd_def32:1; /* default 32 vs 16 bit operand */
211 211 uint32_t usd_gran:1; /* limit units (bytes vs pages) */
212 212 uint32_t usd_hibase:8; /* segment base 31:24 */
213 213 } user_desc_t;
214 214
215 215 #define USEGD_GETBASE(usd) ((usd)->usd_lobase | \
216 216 (usd)->usd_midbase << 16 | \
217 217 (usd)->usd_hibase << (16 + 8))
218 218
219 219 #define USEGD_SETBASE(usd, b) ((usd)->usd_lobase = (b), \
220 220 (usd)->usd_midbase = (b) >> 16, \
221 221 (usd)->usd_hibase = (b) >> (16 + 8))
222 222
223 223 #define USEGD_GETLIMIT(usd) ((usd)->usd_lolimit | \
224 224 (usd)->usd_hilimit << 16)
225 225
226 226 #define USEGD_SETLIMIT(usd, lim) ((usd)->usd_lolimit = lim, \
227 227 (usd)->usd_hilimit = lim >> 16)
228 228
229 229 #define USD_TYPESHIFT 5 /* size of usd_type field */
230 230
231 231 #else /* __amd64 */
232 232
233 233 /*
234 234 * User segment descriptors.
235 235 * Long mode 64-bits wide.
236 236 *
237 237 * In 32-bit compatibility mode (%cs:usd_long=0) all fields are interpreted
238 238 * as in legacy mode for both code and data.
239 239 *
240 240 * In 64-bit mode (%cs:usd_long=1) code segments only have the conforming
241 241 * bit in usd_type, usd_dpl, usd_p, usd_long and usd_def32=0. usd_def32
242 242 * must be zero in 64-bit mode. Setting it to 1 is reserved for future use.
243 243 * All other fields are loaded but ignored by hardware.
244 244 *
245 245 * 64-bit data segments only have usd_p. All other fields are loaded but
246 246 * ignored by hardware when in 64-bit mode.
247 247 */
248 248 typedef struct user_desc {
249 249 uint64_t usd_lolimit:16; /* segment limit 15:0 */
250 250 uint64_t usd_lobase:16; /* segment base 15:0 */
251 251 uint64_t usd_midbase:8; /* segment base 23:16 */
252 252 uint64_t usd_type:5; /* segment type, includes S bit */
253 253 uint64_t usd_dpl:2; /* segment descriptor priority level */
254 254 uint64_t usd_p:1; /* segment descriptor present */
255 255 uint64_t usd_hilimit:4; /* segment limit 19:16 */
256 256 uint64_t usd_avl:1; /* available to sw, but not used */
257 257 uint64_t usd_long:1; /* long mode (%cs only) */
258 258 uint64_t usd_def32:1; /* default 32 vs 16 bit operand */
259 259 uint64_t usd_gran:1; /* limit units (bytes vs page) */
260 260 uint64_t usd_hibase:8; /* segment base 31:24 */
261 261 } user_desc_t;
262 262
263 263 #define USEGD_GETBASE(usd) ((usd)->usd_lobase | \
264 264 (usd)->usd_midbase << 16 | \
265 265 (usd)->usd_hibase << (16 + 8))
266 266
267 267 #define USEGD_SETBASE(usd, b) ((usd)->usd_lobase = (b), \
268 268 (usd)->usd_midbase = (b) >> 16, \
269 269 (usd)->usd_hibase = (b) >> (16 + 8))
270 270
271 271 #define USEGD_GETLIMIT(usd) ((usd)->usd_lolimit | \
272 272 (usd)->usd_hilimit << 16)
273 273
274 274 #define USEGD_SETLIMIT(usd, lim) ((usd)->usd_lolimit = lim, \
275 275 (usd)->usd_hilimit = lim >> 16)
276 276
277 277 #define USD_TYPESHIFT 5 /* size of usd_type field */
278 278
279 279 #endif /* __amd64 */
280 280
281 281 #if !defined(__amd64)
282 282
283 283 /*
284 284 * System segment descriptors for LDT and TSS segments.
285 285 * Legacy mode 64-bits wide.
286 286 */
287 287 typedef struct system_desc {
288 288 uint32_t ssd_lolimit:16; /* segment limit 15:0 */
289 289 uint32_t ssd_lobase:16; /* segment base 15:0 */
290 290 uint32_t ssd_midbase:8; /* segment base 23:16 */
291 291 uint32_t ssd_type:4; /* segment type */
292 292 uint32_t ssd_zero:1; /* must be zero */
293 293 uint32_t ssd_dpl:2; /* segment descriptor priority level */
294 294 uint32_t ssd_p:1; /* segment descriptor present */
295 295 uint32_t ssd_hilimit:4; /* segment limit 19:16 */
296 296 uint32_t ssd_avl:1; /* available to sw, but not used */
297 297 uint32_t ssd_reserved:2; /* unused, ignored */
298 298 uint32_t ssd_gran:1; /* limit unit (bytes vs pages) */
299 299 uint32_t ssd_hibase:8; /* segment base 31:24 */
300 300 } system_desc_t;
301 301
302 302 #else /* __amd64 */
303 303
304 304 /*
305 305 * System segment descriptors for LDT and TSS segments.
306 306 * Long mode 128-bits wide.
307 307 *
308 308 * 32-bit LDT and TSS descriptor types are redefined to 64-bit equivalents.
309 309 * All other legacy types are reserved and illegal.
310 310 */
311 311 typedef struct system_desc {
312 312 uint64_t ssd_lolimit:16; /* segment limit 15:0 */
313 313 uint64_t ssd_lobase:16; /* segment base 15:0 */
314 314 uint64_t ssd_midbase:8; /* segment base 23:16 */
315 315 uint64_t ssd_type:4; /* segment type */
316 316 uint64_t ssd_zero1:1; /* must be zero */
317 317 uint64_t ssd_dpl:2; /* segment descriptor priority level */
318 318 uint64_t ssd_p:1; /* segment descriptor present */
319 319 uint64_t ssd_hilimit:4; /* segment limit 19:16 */
320 320 uint64_t ssd_avl:1; /* available to sw, but not used */
321 321 uint64_t ssd_resv1:2; /* unused, ignored */
322 322 uint64_t ssd_gran:1; /* limit unit (bytes vs pages) */
323 323 uint64_t ssd_hibase:8; /* segment base 31:24 */
324 324 uint64_t ssd_hi64base:32; /* segment base 63:32 */
325 325 uint64_t ssd_resv2:8; /* unused, ignored */
326 326 uint64_t ssd_zero2:5; /* must be zero */
327 327 uint64_t ssd_resv3:19; /* unused, ignored */
328 328 } system_desc_t;
329 329
330 330 #endif /* __amd64 */
331 331
332 332 #define SYSSEGD_SETLIMIT(ssd, lim) ((ssd)->ssd_lolimit = lim, \
333 333 (ssd)->ssd_hilimit = lim >> 16)
334 334
335 335 #define SYSSEGD_GETLIMIT(ssd) (((ssd)->ssd_hilimit << 16) | \
336 336 (ssd)->ssd_lolimit)
337 337
338 338 #if !defined(__amd64)
339 339
340 340 /*
341 341 * System gate segment descriptors for interrupt, trap, call and task gates.
342 342 * Legacy mode 64-bits wide.
343 343 */
344 344 typedef struct gate_desc {
345 345 uint32_t sgd_looffset:16; /* segment code offset 15:0 */
346 346 uint32_t sgd_selector:16; /* target code or task selector */
347 347 uint32_t sgd_stkcpy:5; /* number of stack wds to cpy */
348 348 uint32_t sgd_resv:3; /* unused, ignored */
349 349 uint32_t sgd_type:5; /* segment type, includes S bit */
350 350 uint32_t sgd_dpl:2; /* segment descriptor priority level */
351 351 uint32_t sgd_p:1; /* segment descriptor present */
352 352 uint32_t sgd_hioffset:16; /* code seg off 31:16 */
353 353 } gate_desc_t;
354 354
355 355 #define GATESEG_GETOFFSET(sgd) ((uintptr_t)((sgd)->sgd_looffset | \
356 356 (sgd)->sgd_hioffset << 16))
357 357
358 358 #else /* __amd64 */
359 359
360 360 /*
361 361 * System segment descriptors for interrupt, trap and call gates.
362 362 * Long mode 128-bits wide.
363 363 *
364 364 * 32-bit interrupt, trap and call gate types are redefined to 64-bit
365 365 * equivalents. Task gates along with all other legacy types are reserved
366 366 * and illegal.
367 367 */
368 368 typedef struct gate_desc {
369 369 uint64_t sgd_looffset:16; /* segment code offset 15:0 */
370 370 uint64_t sgd_selector:16; /* target code or task selector */
371 371 uint64_t sgd_ist:3; /* IST table index */
372 372 uint64_t sgd_resv1:5; /* unused, ignored */
373 373 uint64_t sgd_type:5; /* segment type, includes S bit */
374 374 uint64_t sgd_dpl:2; /* segment descriptor priority level */
375 375 uint64_t sgd_p:1; /* segment descriptor present */
376 376 uint64_t sgd_hioffset:16; /* segment code offset 31:16 */
377 377 uint64_t sgd_hi64offset:32; /* segment code offset 63:32 */
378 378 uint64_t sgd_resv2:8; /* unused, ignored */
379 379 uint64_t sgd_zero:5; /* call gate only: must be zero */
380 380 uint64_t sgd_resv3:19; /* unused, ignored */
381 381 } gate_desc_t;
382 382
383 383 #define GATESEG_GETOFFSET(sgd) ((uintptr_t)((sgd)->sgd_looffset | \
384 384 (sgd)->sgd_hioffset << 16 | \
385 385 (uint64_t)((sgd)->sgd_hi64offset) << 32))
386 386
387 387 #endif /* __amd64 */
388 388
389 389 /*
390 390 * functions for initializing and updating segment descriptors.
391 391 */
392 392 #if defined(__amd64)
393 393
394 394 extern void set_usegd(user_desc_t *, uint_t, void *, size_t, uint_t, uint_t,
395 395 uint_t, uint_t);
396 396
397 397 #elif defined(__i386)
398 398
399 399 extern void set_usegd(user_desc_t *, void *, size_t, uint_t, uint_t,
400 400 uint_t, uint_t);
401 401
402 402 #endif /* __i386 */
403 403
404 404 extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t,
405 405 uint_t, uint_t, uint_t);
406 406
407 407 extern void set_syssegd(system_desc_t *, void *, size_t, uint_t, uint_t);
408 408
409 409 extern void *get_ssd_base(system_desc_t *);
410 410
411 411 extern void gdt_update_usegd(uint_t, user_desc_t *);
412 412
413 413 extern int ldt_update_segd(user_desc_t *, user_desc_t *);
414 414
415 415 #if defined(__xpv)
416 416
417 417 extern int xen_idt_to_trap_info(uint_t, gate_desc_t *, void *);
418 418 extern void xen_idt_write(gate_desc_t *, uint_t);
419 419
420 420 #endif /* __xen */
421 421
422 422 void init_boot_gdt(user_desc_t *);
423 423
424 424 #endif /* _ASM */
425 425
426 426 /*
427 427 * Common segment parameter defintions for granularity, default
428 428 * operand size and operaton mode.
429 429 */
430 430 #define SDP_BYTES 0 /* segment limit scaled to bytes */
431 431 #define SDP_PAGES 1 /* segment limit scaled to pages */
432 432 #define SDP_OP32 1 /* code and data default operand = 32 bits */
433 433 #define SDP_LONG 1 /* long mode code segment (64 bits) */
434 434 #define SDP_SHORT 0 /* compat/legacy code segment (32 bits) */
435 435 /*
436 436 * System segments and gate types.
437 437 *
438 438 * In long mode i386 32-bit ldt, tss, call, interrupt and trap gate
439 439 * types are redefined into 64-bit equivalents.
440 440 */
441 441 #define SDT_SYSNULL 0 /* system null */
442 442 #define SDT_SYS286TSS 1 /* system 286 TSS available */
443 443 #define SDT_SYSLDT 2 /* system local descriptor table */
444 444 #define SDT_SYS286BSY 3 /* system 286 TSS busy */
445 445 #define SDT_SYS286CGT 4 /* system 286 call gate */
446 446 #define SDT_SYSTASKGT 5 /* system task gate */
447 447 #define SDT_SYS286IGT 6 /* system 286 interrupt gate */
448 448 #define SDT_SYS286TGT 7 /* system 286 trap gate */
449 449 #define SDT_SYSNULL2 8 /* system null again */
450 450 #define SDT_SYSTSS 9 /* system TSS available */
451 451 #define SDT_SYSNULL3 10 /* system null again */
452 452 #define SDT_SYSTSSBSY 11 /* system TSS busy */
453 453 #define SDT_SYSCGT 12 /* system call gate */
454 454 #define SDT_SYSNULL4 13 /* system null again */
455 455 #define SDT_SYSIGT 14 /* system interrupt gate */
456 456 #define SDT_SYSTGT 15 /* system trap gate */
457 457
458 458 /*
459 459 * Memory segment types.
460 460 *
461 461 * While in long mode expand-down, writable and accessed type field
462 462 * attributes are ignored. Only the conforming bit is loaded by hardware
463 463 * for long mode code segment descriptors.
464 464 */
465 465 #define SDT_MEMRO 16 /* read only */
466 466 #define SDT_MEMROA 17 /* read only accessed */
467 467 #define SDT_MEMRW 18 /* read write */
468 468 #define SDT_MEMRWA 19 /* read write accessed */
469 469 #define SDT_MEMROD 20 /* read only expand dwn limit */
470 470 #define SDT_MEMRODA 21 /* read only expand dwn limit accessed */
471 471 #define SDT_MEMRWD 22 /* read write expand dwn limit */
472 472 #define SDT_MEMRWDA 23 /* read write expand dwn limit accessed */
473 473 #define SDT_MEME 24 /* execute only */
474 474 #define SDT_MEMEA 25 /* execute only accessed */
475 475 #define SDT_MEMER 26 /* execute read */
476 476 #define SDT_MEMERA 27 /* execute read accessed */
477 477 #define SDT_MEMEC 28 /* execute only conforming */
478 478 #define SDT_MEMEAC 29 /* execute only accessed conforming */
479 479 #define SDT_MEMERC 30 /* execute read conforming */
480 480 #define SDT_MEMERAC 31 /* execute read accessed conforming */
481 481
482 482 /*
483 483 * Entries in the Interrupt Descriptor Table (IDT)
484 484 */
485 485 #define IDT_DE 0 /* #DE: Divide Error */
486 486 #define IDT_DB 1 /* #DB: Debug */
487 487 #define IDT_NMI 2 /* Nonmaskable External Interrupt */
488 488 #define IDT_BP 3 /* #BP: Breakpoint */
489 489 #define IDT_OF 4 /* #OF: Overflow */
490 490 #define IDT_BR 5 /* #BR: Bound Range Exceeded */
491 491 #define IDT_UD 6 /* #UD: Undefined/Invalid Opcode */
492 492 #define IDT_NM 7 /* #NM: No Math Coprocessor */
493 493 #define IDT_DF 8 /* #DF: Double Fault */
494 494 #define IDT_FPUGP 9 /* Coprocessor Segment Overrun */
495 495 #define IDT_TS 10 /* #TS: Invalid TSS */
496 496 #define IDT_NP 11 /* #NP: Segment Not Present */
497 497 #define IDT_SS 12 /* #SS: Stack Segment Fault */
498 498 #define IDT_GP 13 /* #GP: General Protection Fault */
499 499 #define IDT_PF 14 /* #PF: Page Fault */
500 500 #define IDT_MF 16 /* #MF: FPU Floating-Point Error */
501 501 #define IDT_AC 17 /* #AC: Alignment Check */
502 502 #define IDT_MC 18 /* #MC: Machine Check */
503 503 #define IDT_XF 19 /* #XF: SIMD Floating-Point Exception */
504 504 #define NIDT 256 /* size in entries of IDT */
505 505
506 506 /*
507 507 * Entries in the Global Descriptor Table (GDT)
508 508 *
509 509 * We make sure to space the system descriptors (LDT's, TSS')
510 510 * such that they are double gdt slot aligned. This is because
511 511 * in long mode system segment decriptors expand to 128 bits.
512 512 *
513 513 * GDT_LWPFS and GDT_LWPGS must be the same for both 32 and 64-bit
514 514 * kernels. See setup_context in libc. 64-bit processes must set
515 515 * %fs or %gs to null selector to use 64-bit fsbase or gsbase
516 516 * respectively.
517 517 */
518 518 #define GDT_NULL 0 /* null */
519 519 #define GDT_B32DATA 1 /* dboot 32 bit data descriptor */
520 520 #define GDT_B32CODE 2 /* dboot 32 bit code descriptor */
521 521 #define GDT_B16CODE 3 /* bios call 16 bit code descriptor */
522 522 #define GDT_B16DATA 4 /* bios call 16 bit data descriptor */
523 523 #define GDT_B64CODE 5 /* dboot 64 bit code descriptor */
524 524 #define GDT_BGSTMP 7 /* kmdb descriptor only used early in boot */
525 525
526 526 #if defined(__amd64)
527 527
528 528 #define GDT_KCODE 6 /* kernel code seg %cs */
529 529 #define GDT_KDATA 7 /* kernel data seg %ds */
530 530 #define GDT_U32CODE 8 /* 32-bit process on 64-bit kernel %cs */
531 531 #define GDT_UDATA 9 /* user data seg %ds (32 and 64 bit) */
532 532 #define GDT_UCODE 10 /* native user code seg %cs */
533 533 #define GDT_LDT 12 /* LDT for current process */
534 534 #define GDT_KTSS 14 /* kernel tss */
535 535 #define GDT_FS GDT_NULL /* kernel %fs segment selector */
536 536 #define GDT_GS GDT_NULL /* kernel %gs segment selector */
537 537 #define GDT_LWPFS 55 /* lwp private %fs segment selector (32-bit) */
538 538 #define GDT_LWPGS 56 /* lwp private %gs segment selector (32-bit) */
539 539 #define GDT_BRANDMIN 57 /* first entry in GDT for brand usage */
540 540 #define GDT_BRANDMAX 61 /* last entry in GDT for brand usage */
541 541 #define NGDT 62 /* number of entries in GDT */
542 542
543 543 /*
544 544 * This selector is only used in the temporary GDT used to bring additional
545 545 * CPUs from 16-bit real mode into long mode in real_mode_start().
546 546 */
547 547 #define TEMPGDT_KCODE64 1 /* 64-bit code selector */
548 548
549 549 #elif defined(__i386)
550 550
551 551 #define GDT_LDT 40 /* LDT for current process */
552 552 #define GDT_KTSS 42 /* kernel tss */
553 553 #define GDT_KCODE 43 /* kernel code seg %cs */
554 554 #define GDT_KDATA 44 /* kernel data seg %ds */
555 555 #define GDT_UCODE 45 /* native user code seg %cs */
556 556 #define GDT_UDATA 46 /* user data seg %ds (32 and 64 bit) */
557 557 #define GDT_DBFLT 47 /* double fault #DF selector */
558 558 #define GDT_FS 53 /* kernel %fs segment selector */
559 559 #define GDT_GS 54 /* kernel %gs segment selector */
560 560 #define GDT_LWPFS 55 /* lwp private %fs segment selector */
561 561 #define GDT_LWPGS 56 /* lwp private %gs segment selector */
562 562 #define GDT_BRANDMIN 57 /* first entry in GDT for brand usage */
563 563 #define GDT_BRANDMAX 61 /* last entry in GDT for brand usage */
564 564 #if !defined(__xpv)
565 565 #define NGDT 90 /* number of entries in GDT */
566 566 #else
567 567 #define NGDT 512 /* single 4K page for the hypervisor */
568 568 #endif
569 569
570 570 #endif /* __i386 */
571 571
572 572 /*
573 573 * Convenient selector definitions.
574 574 */
575 575
576 576 /*
577 577 * XXPV 64 bit Xen only allows the guest %cs/%ss be the private ones it
578 578 * provides, not the ones we create for ourselves. See FLAT_RING3_CS64 in
579 579 * public/arch-x86_64.h
580 580 *
581 581 * 64-bit Xen runs paravirtual guests in ring 3 but emulates them running in
582 582 * ring 0 by clearing CPL in %cs value pushed on guest exception stacks.
583 583 * Therefore we will have KCS_SEL value indicate ring 0 and use that everywhere
584 584 * in the kernel. But in the few files where we initialize segment registers or
585 585 * create and update descriptors we will explicity OR in SEL_KPL (ring 3) for
586 586 * kernel %cs. See desctbls.c for an example.
587 587 */
588 588
589 589 #if defined(__xpv) && defined(__amd64)
590 590 #define KCS_SEL 0xe030 /* FLAT_RING3_CS64 & 0xFFF0 */
591 591 #define KDS_SEL 0xe02b /* FLAT_RING3_SS64 */
592 592 #else
593 593 #define KCS_SEL SEL_GDT(GDT_KCODE, SEL_KPL)
594 594 #define KDS_SEL SEL_GDT(GDT_KDATA, SEL_KPL)
595 595 #endif
596 596
597 597 #define UCS_SEL SEL_GDT(GDT_UCODE, SEL_UPL)
598 598 #if defined(__amd64)
599 599 #define TEMP_CS64_SEL SEL_GDT(TEMPGDT_KCODE64, SEL_KPL)
600 600 #define U32CS_SEL SEL_GDT(GDT_U32CODE, SEL_UPL)
601 601 #endif
602 602
603 603 #define UDS_SEL SEL_GDT(GDT_UDATA, SEL_UPL)
604 604 #define ULDT_SEL SEL_GDT(GDT_LDT, SEL_KPL)
605 605 #define KTSS_SEL SEL_GDT(GDT_KTSS, SEL_KPL)
606 606 #define DFTSS_SEL SEL_GDT(GDT_DBFLT, SEL_KPL)
607 607 #define KFS_SEL 0
608 608 #define KGS_SEL SEL_GDT(GDT_GS, SEL_KPL)
609 609 #define LWPFS_SEL SEL_GDT(GDT_LWPFS, SEL_UPL)
610 610 #define LWPGS_SEL SEL_GDT(GDT_LWPGS, SEL_UPL)
611 611 #define BRANDMIN_SEL SEL_GDT(GDT_BRANDMIN, SEL_UPL)
612 612 #define BRANDMAX_SEL SEL_GDT(GDT_BRANDMAX, SEL_UPL)
613 613
614 614 #define B64CODE_SEL SEL_GDT(GDT_B64CODE, SEL_KPL)
615 615 #define B32CODE_SEL SEL_GDT(GDT_B32CODE, SEL_KPL)
616 616 #define B32DATA_SEL SEL_GDT(GDT_B32DATA, SEL_KPL)
617 617 #define B16CODE_SEL SEL_GDT(GDT_B16CODE, SEL_KPL)
618 618 #define B16DATA_SEL SEL_GDT(GDT_B16DATA, SEL_KPL)
619 619
620 620 /*
621 621 * Temporary %gs descriptor used by kmdb with -d option. Only lives
622 622 * in boot's GDT and is not copied into kernel's GDT from boot.
623 623 */
624 624 #define KMDBGS_SEL SEL_GDT(GDT_BGSTMP, SEL_KPL)
625 625
626 626 /*
627 627 * Selector used for kdi_idt when kmdb has taken over the IDT.
628 628 */
629 629 #if defined(__amd64)
630 630 #define KMDBCODE_SEL B64CODE_SEL
631 631 #else
632 632 #define KMDBCODE_SEL B32CODE_SEL
633 633 #endif
634 634
635 635 /*
636 636 * Entries in default Local Descriptor Table (LDT) for every process.
637 637 */
638 638 #define LDT_SYSCALL 0 /* call gate for libc.a (obsolete) */
639 639 #define LDT_SIGCALL 1 /* EOL me, call gate for static sigreturn */
640 640 #define LDT_RESVD1 2 /* old user %cs */
641 641 #define LDT_RESVD2 3 /* old user %ds */
642 642 #define LDT_ALTSYSCALL 4 /* alternate call gate for system calls */
643 643 #define LDT_ALTSIGCALL 5 /* EOL me, alternate call gate for sigreturn */
644 644 #define LDT_UDBASE 6 /* user descriptor base index */
645 645 #define MINNLDT 512 /* Current min solaris ldt size (1 4K page) */
646 646 #define MAXNLDT 8192 /* max solaris ldt size (16 4K pages) */
647 647
648 648 #ifndef _ASM
649 649
650 650 extern gate_desc_t *idt0;
651 651 extern desctbr_t idt0_default_reg;
652 652 extern user_desc_t *gdt0;
653 653
654 654 extern user_desc_t zero_udesc;
655 655 extern user_desc_t null_udesc;
656 656 extern system_desc_t null_sdesc;
657 657
658 658 #if defined(__amd64)
659 659 extern user_desc_t zero_u32desc;
660 660 #endif
661 661 #if defined(__amd64)
662 662 extern user_desc_t ucs_on;
663 663 extern user_desc_t ucs_off;
664 664 extern user_desc_t ucs32_on;
665 665 extern user_desc_t ucs32_off;
666 666 #endif /* __amd64 */
667 667
668 668 extern tss_t *ktss0;
669 669
670 670 #if defined(__i386)
671 671 extern tss_t *dftss0;
672 672 #endif /* __i386 */
673 673
674 674 extern void div0trap(), dbgtrap(), nmiint(), brktrap(), ovflotrap();
675 675 extern void boundstrap(), invoptrap(), ndptrap();
↓ open down ↓ |
675 lines elided |
↑ open up ↑ |
676 676 #if !defined(__xpv)
677 677 extern void syserrtrap();
678 678 #endif
679 679 extern void invaltrap(), invtsstrap(), segnptrap(), stktrap();
680 680 extern void gptrap(), pftrap(), ndperr();
681 681 extern void overrun(), resvtrap();
682 682 extern void _start(), cmnint();
683 683 extern void achktrap(), mcetrap();
684 684 extern void xmtrap();
685 685 extern void fasttrap();
686 +extern void sys_int80();
687 +extern void brand_sys_int80();
686 688 extern void dtrace_ret();
687 689
688 690 #if !defined(__amd64)
689 691 extern void pentium_pftrap();
690 692 #endif
691 693
692 694 #endif /* _ASM */
693 695
694 696 #ifdef __cplusplus
695 697 }
696 698 #endif
697 699
698 700 #endif /* _SYS_SEGMENTS_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX