]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/include/asm/desc_defs.h
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / arch / x86 / include / asm / desc_defs.h
1 /* Written 2000 by Andi Kleen */
2 #ifndef _ASM_X86_DESC_DEFS_H
3 #define _ASM_X86_DESC_DEFS_H
4
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
14 /*
15 * FIXME: Accessing the desc_struct through its fields is more elegant,
16 * and should be the one valid thing to do. However, a lot of open code
17 * still touches the a and b accessors, and doing this allow us to do it
18 * incrementally. We keep the signature as a struct, rather than a union,
19 * so we can get rid of it transparently in the future -- glommer
20 */
21 /* 8 byte segment descriptor */
22 struct desc_struct {
23 union {
24 struct {
25 unsigned int a;
26 unsigned int b;
27 };
28 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 };
34 };
35 } __attribute__((packed));
36
37 #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
43 enum {
44 GATE_INTERRUPT = 0xE,
45 GATE_TRAP = 0xF,
46 GATE_CALL = 0xC,
47 GATE_TASK = 0x5,
48 };
49
50 enum {
51 DESC_TSS = 0x9,
52 DESC_LDT = 0x2,
53 DESCTYPE_S = 0x10, /* !system */
54 };
55
56 /* LDT or TSS descriptor in the GDT. 16 bytes. */
57 struct ldttss_desc64 {
58 u16 limit0;
59 u16 base0;
60 unsigned base1 : 8, type : 5, dpl : 2, p : 1;
61 unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
62 u32 base3;
63 u32 zero1;
64 } __attribute__((packed));
65
66
67 #ifdef CONFIG_X86_64
68 typedef struct ldttss_desc64 ldt_desc;
69 typedef struct ldttss_desc64 tss_desc;
70 #else
71 typedef struct desc_struct ldt_desc;
72 typedef struct desc_struct tss_desc;
73 #endif
74
75 struct idt_bits {
76 u16 ist : 3,
77 zero : 5,
78 type : 5,
79 dpl : 2,
80 p : 1;
81 } __attribute__((packed));
82
83 struct gate_struct {
84 u16 offset_low;
85 u16 segment;
86 struct idt_bits bits;
87 u16 offset_middle;
88 #ifdef CONFIG_X86_64
89 u32 offset_high;
90 u32 reserved;
91 #endif
92 } __attribute__((packed));
93
94 typedef struct gate_struct gate_desc;
95
96 static inline unsigned long gate_offset(const gate_desc *g)
97 {
98 #ifdef CONFIG_X86_64
99 return g->offset_low | ((unsigned long)g->offset_middle << 16) |
100 ((unsigned long) g->offset_high << 32);
101 #else
102 return g->offset_low | ((unsigned long)g->offset_middle << 16);
103 #endif
104 }
105
106 static inline unsigned long gate_segment(const gate_desc *g)
107 {
108 return g->segment;
109 }
110
111 struct desc_ptr {
112 unsigned short size;
113 unsigned long address;
114 } __attribute__((packed)) ;
115
116 #endif /* !__ASSEMBLY__ */
117
118 /* Access rights as returned by LAR */
119 #define AR_TYPE_RODATA (0 * (1 << 9))
120 #define AR_TYPE_RWDATA (1 * (1 << 9))
121 #define AR_TYPE_RODATA_EXPDOWN (2 * (1 << 9))
122 #define AR_TYPE_RWDATA_EXPDOWN (3 * (1 << 9))
123 #define AR_TYPE_XOCODE (4 * (1 << 9))
124 #define AR_TYPE_XRCODE (5 * (1 << 9))
125 #define AR_TYPE_XOCODE_CONF (6 * (1 << 9))
126 #define AR_TYPE_XRCODE_CONF (7 * (1 << 9))
127 #define AR_TYPE_MASK (7 * (1 << 9))
128
129 #define AR_DPL0 (0 * (1 << 13))
130 #define AR_DPL3 (3 * (1 << 13))
131 #define AR_DPL_MASK (3 * (1 << 13))
132
133 #define AR_A (1 << 8) /* "Accessed" */
134 #define AR_S (1 << 12) /* If clear, "System" segment */
135 #define AR_P (1 << 15) /* "Present" */
136 #define AR_AVL (1 << 20) /* "AVaiLable" (no HW effect) */
137 #define AR_L (1 << 21) /* "Long mode" for code segments */
138 #define AR_DB (1 << 22) /* D/B, effect depends on type */
139 #define AR_G (1 << 23) /* "Granularity" (limit in pages) */
140
141 #endif /* _ASM_X86_DESC_DEFS_H */