Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
desc_defs.h
Go to the documentation of this file.
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 an 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 {
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 {
45  GATE_TRAP = 0xF,
46  GATE_CALL = 0xC,
47  GATE_TASK = 0x5,
48 };
49 
50 /* 16byte gate */
51 struct gate_struct64 {
54  unsigned ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1;
58 } __attribute__((packed));
59 
60 #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)
63 
64 enum {
65  DESC_TSS = 0x9,
66  DESC_LDT = 0x2,
67  DESCTYPE_S = 0x10, /* !system */
68 };
69 
70 /* LDT or TSS descriptor in the GDT. 16 bytes. */
71 struct ldttss_desc64 {
74  unsigned base1 : 8, type : 5, dpl : 2, p : 1;
75  unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
78 } __attribute__((packed));
79 
80 #ifdef CONFIG_X86_64
81 typedef struct gate_struct64 gate_desc;
82 typedef struct ldttss_desc64 ldt_desc;
83 typedef struct ldttss_desc64 tss_desc;
84 #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)
86 #else
87 typedef struct desc_struct gate_desc;
88 typedef struct desc_struct ldt_desc;
89 typedef struct desc_struct tss_desc;
90 #define gate_offset(g) (((g).b & 0xffff0000) | ((g).a & 0x0000ffff))
91 #define gate_segment(g) ((g).a >> 16)
92 #endif
93 
94 struct desc_ptr {
95  unsigned short size;
96  unsigned long address;
97 } __attribute__((packed)) ;
98 
99 #endif /* !__ASSEMBLY__ */
100 
101 #endif /* _ASM_X86_DESC_DEFS_H */