blob: 278441f39856edf31edca4f5391479c356b19a61 [file] [log] [blame]
Avi Kivity249e83f2006-12-07 02:14:04 +01001/* Written 2000 by Andi Kleen */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_DESC_DEFS_H
3#define _ASM_X86_DESC_DEFS_H
Avi Kivity249e83f2006-12-07 02:14:04 +01004
5/*
6 * Segment descriptor structure definitions, usable from both x86_64 and i386
7 * archs.
8 */
9
10#ifndef __ASSEMBLY__
11
12#include <linux/types.h>
13
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010014/*
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020015 * FIXME: Accessing the desc_struct through its fields is more elegant,
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010016 * and should be the one valid thing to do. However, a lot of open code
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020017 * still touches the a and b accessors, and doing this allow us to do it
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010018 * incrementally. We keep the signature as a struct, rather than an union,
19 * so we can get rid of it transparently in the future -- glommer
20 */
Joe Perchesb7761902008-03-23 01:01:57 -070021/* 8 byte segment descriptor */
Avi Kivity249e83f2006-12-07 02:14:04 +010022struct desc_struct {
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010023 union {
Joe Perchesb7761902008-03-23 01:01:57 -070024 struct {
25 unsigned int a;
26 unsigned int b;
27 };
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010028 struct {
29 u16 limit0;
30 u16 base0;
31 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
32 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
33 };
Glauber de Oliveira Costa6842ef02008-01-30 13:31:11 +010034 };
35} __attribute__((packed));
Avi Kivity249e83f2006-12-07 02:14:04 +010036
Akinobu Mita1e5de182009-07-19 00:12:20 +090037#define GDT_ENTRY_INIT(flags, base, limit) { { { \
38 .a = ((limit) & 0xffff) | (((base) & 0xffff) << 16), \
39 .b = (((base) & 0xff0000) >> 16) | (((flags) & 0xf0ff) << 8) | \
40 ((limit) & 0xf0000) | ((base) & 0xff000000), \
41 } } }
42
Avi Kivity249e83f2006-12-07 02:14:04 +010043enum {
44 GATE_INTERRUPT = 0xE,
45 GATE_TRAP = 0xF,
46 GATE_CALL = 0xC,
Glauber de Oliveira Costa507f90c2008-01-30 13:31:14 +010047 GATE_TASK = 0x5,
Avi Kivity249e83f2006-12-07 02:14:04 +010048};
49
Joe Perchesb7761902008-03-23 01:01:57 -070050/* 16byte gate */
Glauber de Oliveira Costa010d4f82008-01-30 13:31:12 +010051struct gate_struct64 {
Avi Kivity249e83f2006-12-07 02:14:04 +010052 u16 offset_low;
53 u16 segment;
54 unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
55 u16 offset_middle;
56 u32 offset_high;
57 u32 zero1;
58} __attribute__((packed));
59
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +010060#define PTR_LOW(x) ((unsigned long long)(x) & 0xFFFF)
61#define PTR_MIDDLE(x) (((unsigned long long)(x) >> 16) & 0xFFFF)
62#define PTR_HIGH(x) ((unsigned long long)(x) >> 32)
Avi Kivity249e83f2006-12-07 02:14:04 +010063
64enum {
65 DESC_TSS = 0x9,
66 DESC_LDT = 0x2,
Joe Perchesb7761902008-03-23 01:01:57 -070067 DESCTYPE_S = 0x10, /* !system */
Avi Kivity249e83f2006-12-07 02:14:04 +010068};
69
Joe Perchesb7761902008-03-23 01:01:57 -070070/* LDT or TSS descriptor in the GDT. 16 bytes. */
Glauber de Oliveira Costa25deca52008-01-30 13:31:13 +010071struct ldttss_desc64 {
Avi Kivity249e83f2006-12-07 02:14:04 +010072 u16 limit0;
73 u16 base0;
74 unsigned base1 : 8, type : 5, dpl : 2, p : 1;
75 unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
76 u32 base3;
77 u32 zero1;
78} __attribute__((packed));
79
Glauber de Oliveira Costa010d4f82008-01-30 13:31:12 +010080#ifdef CONFIG_X86_64
81typedef struct gate_struct64 gate_desc;
Glauber de Oliveira Costa25deca52008-01-30 13:31:13 +010082typedef struct ldttss_desc64 ldt_desc;
Glauber de Oliveira Costa18245d52008-01-30 13:31:13 +010083typedef struct ldttss_desc64 tss_desc;
Jeremy Fitzhardinge43adfc22008-06-25 00:19:04 -040084#define gate_offset(g) ((g).offset_low | ((unsigned long)(g).offset_middle << 16) | ((unsigned long)(g).offset_high << 32))
85#define gate_segment(g) ((g).segment)
Glauber de Oliveira Costa010d4f82008-01-30 13:31:12 +010086#else
87typedef struct desc_struct gate_desc;
Glauber de Oliveira Costa25deca52008-01-30 13:31:13 +010088typedef struct desc_struct ldt_desc;
Glauber de Oliveira Costa18245d52008-01-30 13:31:13 +010089typedef struct desc_struct tss_desc;
Jeremy Fitzhardinge43adfc22008-06-25 00:19:04 -040090#define gate_offset(g) (((g).b & 0xffff0000) | ((g).a & 0x0000ffff))
91#define gate_segment(g) ((g).a >> 16)
Glauber de Oliveira Costa010d4f82008-01-30 13:31:12 +010092#endif
93
Avi Kivity249e83f2006-12-07 02:14:04 +010094struct desc_ptr {
95 unsigned short size;
96 unsigned long address;
97} __attribute__((packed)) ;
98
Avi Kivity249e83f2006-12-07 02:14:04 +010099#endif /* !__ASSEMBLY__ */
100
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700101#endif /* _ASM_X86_DESC_DEFS_H */