[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / arch / i386 / include / registers.h
blob06d2365241fa2eeaa14ab6d9c32ac6378cc1846d
1 #ifndef REGISTERS_H
2 #define REGISTERS_H
4 /** @file
6 * i386 registers.
8 * This file defines data structures that allow easy access to i386
9 * register dumps.
13 FILE_LICENCE ( GPL2_OR_LATER );
15 #include <stdint.h>
17 /**
18 * A 16-bit general register.
20 * This type encapsulates a 16-bit register such as %ax, %bx, %cx,
21 * %dx, %si, %di, %bp or %sp.
24 typedef union {
25 struct {
26 union {
27 uint8_t l;
28 uint8_t byte;
30 uint8_t h;
31 } __attribute__ (( packed ));
32 uint16_t word;
33 } __attribute__ (( packed )) reg16_t;
35 /**
36 * A 32-bit general register.
38 * This type encapsulates a 32-bit register such as %eax, %ebx, %ecx,
39 * %edx, %esi, %edi, %ebp or %esp.
42 typedef union {
43 struct {
44 union {
45 uint8_t l;
46 uint8_t byte;
48 uint8_t h;
49 } __attribute__ (( packed ));
50 uint16_t word;
51 uint32_t dword;
52 } __attribute__ (( packed )) reg32_t;
54 /**
55 * A 32-bit general register dump.
57 * This is the data structure that is created on the stack by the @c
58 * pushal instruction, and can be read back using the @c popal
59 * instruction.
62 struct i386_regs {
63 union {
64 uint16_t di;
65 uint32_t edi;
67 union {
68 uint16_t si;
69 uint32_t esi;
71 union {
72 uint16_t bp;
73 uint32_t ebp;
75 union {
76 uint16_t sp;
77 uint32_t esp;
79 union {
80 struct {
81 uint8_t bl;
82 uint8_t bh;
83 } __attribute__ (( packed ));
84 uint16_t bx;
85 uint32_t ebx;
87 union {
88 struct {
89 uint8_t dl;
90 uint8_t dh;
91 } __attribute__ (( packed ));
92 uint16_t dx;
93 uint32_t edx;
95 union {
96 struct {
97 uint8_t cl;
98 uint8_t ch;
99 } __attribute__ (( packed ));
100 uint16_t cx;
101 uint32_t ecx;
103 union {
104 struct {
105 uint8_t al;
106 uint8_t ah;
107 } __attribute__ (( packed ));
108 uint16_t ax;
109 uint32_t eax;
111 } __attribute__ (( packed ));
114 * A segment register dump.
116 * The i386 has no equivalent of the @c pushal or @c popal
117 * instructions for the segment registers. We adopt the convention of
118 * always using the sequences
120 * @code
122 * pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
124 * @endcode
126 * and
128 * @code
130 * addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
132 * @endcode
134 * This is the data structure that is created and read back by these
135 * instruction sequences.
138 struct i386_seg_regs {
139 uint16_t cs;
140 uint16_t ss;
141 uint16_t ds;
142 uint16_t es;
143 uint16_t fs;
144 uint16_t gs;
145 } __attribute__ (( packed ));
148 * A full register dump.
150 * This data structure is created by the instructions
152 * @code
154 * pushfl
155 * pushal
156 * pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
158 * @endcode
160 * and can be read back using the instructions
162 * @code
164 * addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
165 * popal
166 * popfl
168 * @endcode
170 * prot_call() and kir_call() create this data structure on the stack
171 * and pass in a pointer to this structure.
174 struct i386_all_regs {
175 struct i386_seg_regs segs;
176 struct i386_regs regs;
177 uint32_t flags;
178 } __attribute__ (( packed ));
180 /* Flags */
181 #define CF ( 1 << 0 )
182 #define PF ( 1 << 2 )
183 #define AF ( 1 << 4 )
184 #define ZF ( 1 << 6 )
185 #define SF ( 1 << 7 )
186 #define OF ( 1 << 11 )
188 /* Segment:offset structure. Note that the order within the structure
189 * is offset:segment.
191 struct segoff {
192 uint16_t offset;
193 uint16_t segment;
194 } __attribute__ (( packed ));
196 typedef struct segoff segoff_t;
198 #endif /* REGISTERS_H */