Xen Test Framework
x86-gate.h
Go to the documentation of this file.
1 
7 #ifndef XTF_X86_GATE_H
8 #define XTF_X86_GATE_H
9 
10 #include <xtf/lib.h>
11 
14  union {
15  struct {
16  uint32_t lo, hi;
17  };
18  struct {
21  unsigned int param_count:5, _r0:3;
22  unsigned int type:4, s:1, dpl:2, p:1;
24  };
25  };
26 };
27 
28 static inline void pack_x86_gate32(
29  struct x86_gate32 *g,
30  unsigned int type, unsigned int sel, uint32_t offset,
31  unsigned int dpl, unsigned int count)
32 {
33  g->offset0 = offset & 0xffff;
34  g->selector = sel;
35  g->param_count = count;
36  g->_r0 = 0;
37  g->type = type;
38  g->s = 0;
39  g->dpl = dpl;
40  g->p = 1;
41  g->offset1 = (offset >> 16) & 0xffff;
42 }
43 
46  union {
47  struct {
48  uint64_t lo, hi;
49  };
50  struct {
53  unsigned int ist:3, _r0:5;
54  unsigned int type:4, s:1, dpl:2, p:1;
58  };
59  };
60 };
61 
62 static inline void pack_x86_gate64(
63  struct x86_gate64 *g,
64  unsigned int type, unsigned int sel, uint64_t offset,
65  unsigned int dpl, unsigned int ist)
66 {
67  g->offset0 = offset & 0xffff;
68  g->selector = sel;
69  g->ist = ist;
70  g->_r0 = 0;
71  g->type = type;
72  g->s = 0;
73  g->dpl = dpl;
74  g->p = 1;
75  g->offset1 = (offset >> 16) & 0xffff;
76  g->offset2 = (offset >> 32) & 0xffffffffu;
77  g->_r1 = 0;
78 }
79 
80 #if defined(__x86_64__)
81 
82 typedef struct x86_gate64 env_gate;
83 
84 #elif defined(__i386__)
85 
86 typedef struct x86_gate32 env_gate;
87 
88 #else
89 # error Bad architecture for Gate infrastructure
90 #endif
91 
92 static inline void pack_gate(
93  env_gate *g,
94  unsigned int type, unsigned int sel, unsigned long offset,
95  unsigned int dpl, unsigned int other)
96 {
97 #if defined(__x86_64__)
99 #else
101 #endif
102  (g, type, sel, offset, dpl, other);
103 }
104 
105 static inline void pack_task_gate(env_gate *g, unsigned int selector)
106 {
107  pack_gate(g, 5, selector, 0, 0, 0);
108 }
109 
110 static inline void pack_call_gate(
111  env_gate *g, unsigned int sel, unsigned long offset,
112  unsigned int dpl, unsigned int other)
113 {
114  pack_gate(g, 12, sel, offset, dpl, other);
115 }
116 
117 static inline void pack_intr_gate(
118  env_gate *g, unsigned int sel, unsigned long offset,
119  unsigned int dpl, unsigned int other)
120 {
121  pack_gate(g, 14, sel, offset, dpl, other);
122 }
123 
124 static inline void pack_trap_gate(
125  env_gate *g, unsigned int sel, unsigned long offset,
126  unsigned int dpl, unsigned int other)
127 {
128  pack_gate(g, 15, sel, offset, dpl, other);
129 }
130 
131 #endif /* XTF_X86_GATE_H */
132 
133 /*
134  * Local variables:
135  * mode: C
136  * c-file-style: "BSD"
137  * c-basic-offset: 4
138  * tab-width: 4
139  * indent-tabs-mode: nil
140  * End:
141  */
static void pack_intr_gate(env_gate *g, unsigned int sel, unsigned long offset, unsigned int dpl, unsigned int other)
Definition: x86-gate.h:117
8-byte gate - Protected mode IDT entry, GDT task/call gate.
Definition: x86-gate.h:13
unsigned int dpl
Definition: x86-gate.h:22
16-byte gate - Long mode IDT entry, GDT call gate.
Definition: x86-gate.h:45
uint32_t offset2
Definition: x86-gate.h:56
static void pack_x86_gate32(struct x86_gate32 *g, unsigned int type, unsigned int sel, uint32_t offset, unsigned int dpl, unsigned int count)
Definition: x86-gate.h:28
uint32_t _r1
Definition: x86-gate.h:57
unsigned int _r0
Definition: x86-gate.h:21
unsigned int type
Definition: x86-gate.h:22
uint16_t selector
Definition: x86-gate.h:52
unsigned int s
Definition: x86-gate.h:54
unsigned int s
Definition: x86-gate.h:22
unsigned int p
Definition: x86-gate.h:22
uint16_t offset1
Definition: x86-gate.h:23
static void pack_gate(env_gate *g, unsigned int type, unsigned int sel, unsigned long offset, unsigned int dpl, unsigned int other)
Definition: x86-gate.h:92
uint16_t offset0
Definition: x86-gate.h:19
unsigned int ist
Definition: x86-gate.h:53
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
static void pack_x86_gate64(struct x86_gate64 *g, unsigned int type, unsigned int sel, uint64_t offset, unsigned int dpl, unsigned int ist)
Definition: x86-gate.h:62
static void pack_call_gate(env_gate *g, unsigned int sel, unsigned long offset, unsigned int dpl, unsigned int other)
Definition: x86-gate.h:110
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
uint64_t lo
Definition: x86-gate.h:48
uint16_t selector
Definition: x86-gate.h:20
#define __packed
Definition: compiler.h:11
uint32_t lo
Definition: x86-gate.h:16
unsigned int p
Definition: x86-gate.h:54
unsigned int dpl
Definition: x86-gate.h:54
uint16_t offset1
Definition: x86-gate.h:55
unsigned int _r0
Definition: x86-gate.h:53
__UINT16_TYPE__ uint16_t
Definition: stdint.h:15
uint16_t offset0
Definition: x86-gate.h:51
static void pack_trap_gate(env_gate *g, unsigned int sel, unsigned long offset, unsigned int dpl, unsigned int other)
Definition: x86-gate.h:124
static void pack_task_gate(env_gate *g, unsigned int selector)
Definition: x86-gate.h:105
unsigned int param_count
Definition: x86-gate.h:21
unsigned int type
Definition: x86-gate.h:54