summaryrefslogtreecommitdiff
path: root/gpxe/src/arch/i386/include/registers.h
blob: 2839e2bdd33ab54610f16b9aa96b0e70524dfd1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef REGISTERS_H
#define REGISTERS_H

/** @file
 *
 * i386 registers.
 *
 * This file defines data structures that allow easy access to i386
 * register dumps.
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

#include <stdint.h>

/**
 * A 16-bit general register.
 *
 * This type encapsulates a 16-bit register such as %ax, %bx, %cx,
 * %dx, %si, %di, %bp or %sp.
 *
 */
typedef union {
	struct {
		union {
			uint8_t l;
			uint8_t byte;
		};
		uint8_t h;
	} PACKED;
	uint16_t word;
} PACKED reg16_t;

/**
 * A 32-bit general register.
 *
 * This type encapsulates a 32-bit register such as %eax, %ebx, %ecx,
 * %edx, %esi, %edi, %ebp or %esp.
 *
 */
typedef union {
	struct {
		union {
			uint8_t l;
			uint8_t byte;
		};
		uint8_t h;
	} PACKED;
	uint16_t word;
	uint32_t dword;
} PACKED reg32_t;

/**
 * A 32-bit general register dump.
 *
 * This is the data structure that is created on the stack by the @c
 * pushal instruction, and can be read back using the @c popal
 * instruction.
 *
 */
struct i386_regs {
	union {
		uint16_t di;
		uint32_t edi;
	};
	union {
		uint16_t si;
		uint32_t esi;
	};
	union {
		uint16_t bp;
		uint32_t ebp;
	};
	union {
		uint16_t sp;
		uint32_t esp;
	};
	union {
		struct {
			uint8_t bl;
			uint8_t bh;
		} PACKED;
		uint16_t bx;
		uint32_t ebx;
	};
	union {
		struct {
			uint8_t dl;
			uint8_t dh;
		} PACKED;
		uint16_t dx;
		uint32_t edx;
	};
	union {
		struct {
			uint8_t cl;
			uint8_t ch;
		} PACKED;
		uint16_t cx;
		uint32_t ecx;
	};
	union {
		struct {
			uint8_t al;
			uint8_t ah;
		} PACKED;
		uint16_t ax;
		uint32_t eax;
	};
} PACKED;

/**
 * A segment register dump.
 *
 * The i386 has no equivalent of the @c pushal or @c popal
 * instructions for the segment registers.  We adopt the convention of
 * always using the sequences
 *
 * @code
 *
 *   pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
 *
 * @endcode
 *
 * and
 *
 * @code
 *
 *   addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
 *
 * @endcode
 *
 * This is the data structure that is created and read back by these
 * instruction sequences.
 *
 */
struct i386_seg_regs {
	uint16_t cs;
	uint16_t ss;
	uint16_t ds;
	uint16_t es;
	uint16_t fs;
	uint16_t gs;
} PACKED;

/**
 * A full register dump.
 *
 * This data structure is created by the instructions
 *
 * @code
 *
 *   pushfl
 *   pushal
 *   pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
 *
 * @endcode
 *
 * and can be read back using the instructions
 *
 * @code
 *
 *   addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
 *   popal
 *   popfl
 *
 * @endcode
 *
 * prot_call() and kir_call() create this data structure on the stack
 * and pass in a pointer to this structure.
 *
 */
struct i386_all_regs {
	struct i386_seg_regs segs;
	struct i386_regs regs;
	uint32_t flags;
} PACKED;

/* Flags */
#define CF ( 1 <<  0 )
#define PF ( 1 <<  2 )
#define AF ( 1 <<  4 )
#define ZF ( 1 <<  6 )
#define SF ( 1 <<  7 )
#define OF ( 1 << 11 )

/* Segment:offset structure.  Note that the order within the structure
 * is offset:segment.
 */
struct segoff {
	uint16_t offset;
	uint16_t segment;
} PACKED;

typedef struct segoff segoff_t;

#endif /* REGISTERS_H */