You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

registers.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef REGISTERS_H
  2. #define REGISTERS_H
  3. /** @file
  4. *
  5. * i386 registers.
  6. *
  7. * This file defines data structures that allow easy access to i386
  8. * register dumps.
  9. *
  10. */
  11. FILE_LICENCE ( GPL2_OR_LATER );
  12. #include <stdint.h>
  13. /**
  14. * A 16-bit general register.
  15. *
  16. * This type encapsulates a 16-bit register such as %ax, %bx, %cx,
  17. * %dx, %si, %di, %bp or %sp.
  18. *
  19. */
  20. typedef union {
  21. struct {
  22. union {
  23. uint8_t l;
  24. uint8_t byte;
  25. };
  26. uint8_t h;
  27. } __attribute__ (( packed ));
  28. uint16_t word;
  29. } __attribute__ (( packed )) reg16_t;
  30. /**
  31. * A 32-bit general register.
  32. *
  33. * This type encapsulates a 32-bit register such as %eax, %ebx, %ecx,
  34. * %edx, %esi, %edi, %ebp or %esp.
  35. *
  36. */
  37. typedef union {
  38. struct {
  39. union {
  40. uint8_t l;
  41. uint8_t byte;
  42. };
  43. uint8_t h;
  44. } __attribute__ (( packed ));
  45. uint16_t word;
  46. uint32_t dword;
  47. } __attribute__ (( packed )) reg32_t;
  48. /**
  49. * A 32-bit general register dump.
  50. *
  51. * This is the data structure that is created on the stack by the @c
  52. * pushal instruction, and can be read back using the @c popal
  53. * instruction.
  54. *
  55. */
  56. struct i386_regs {
  57. union {
  58. uint16_t di;
  59. uint32_t edi;
  60. };
  61. union {
  62. uint16_t si;
  63. uint32_t esi;
  64. };
  65. union {
  66. uint16_t bp;
  67. uint32_t ebp;
  68. };
  69. union {
  70. uint16_t sp;
  71. uint32_t esp;
  72. };
  73. union {
  74. struct {
  75. uint8_t bl;
  76. uint8_t bh;
  77. } __attribute__ (( packed ));
  78. uint16_t bx;
  79. uint32_t ebx;
  80. };
  81. union {
  82. struct {
  83. uint8_t dl;
  84. uint8_t dh;
  85. } __attribute__ (( packed ));
  86. uint16_t dx;
  87. uint32_t edx;
  88. };
  89. union {
  90. struct {
  91. uint8_t cl;
  92. uint8_t ch;
  93. } __attribute__ (( packed ));
  94. uint16_t cx;
  95. uint32_t ecx;
  96. };
  97. union {
  98. struct {
  99. uint8_t al;
  100. uint8_t ah;
  101. } __attribute__ (( packed ));
  102. uint16_t ax;
  103. uint32_t eax;
  104. };
  105. } __attribute__ (( packed ));
  106. /**
  107. * A segment register dump.
  108. *
  109. * The i386 has no equivalent of the @c pushal or @c popal
  110. * instructions for the segment registers. We adopt the convention of
  111. * always using the sequences
  112. *
  113. * @code
  114. *
  115. * pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
  116. *
  117. * @endcode
  118. *
  119. * and
  120. *
  121. * @code
  122. *
  123. * addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
  124. *
  125. * @endcode
  126. *
  127. * This is the data structure that is created and read back by these
  128. * instruction sequences.
  129. *
  130. */
  131. struct i386_seg_regs {
  132. uint16_t cs;
  133. uint16_t ss;
  134. uint16_t ds;
  135. uint16_t es;
  136. uint16_t fs;
  137. uint16_t gs;
  138. } __attribute__ (( packed ));
  139. /**
  140. * A full register dump.
  141. *
  142. * This data structure is created by the instructions
  143. *
  144. * @code
  145. *
  146. * pushfl
  147. * pushal
  148. * pushw %gs ; pushw %fs ; pushw %es ; pushw %ds ; pushw %ss ; pushw %cs
  149. *
  150. * @endcode
  151. *
  152. * and can be read back using the instructions
  153. *
  154. * @code
  155. *
  156. * addw $4, %sp ; popw %ds ; popw %es ; popw %fs ; popw %gs
  157. * popal
  158. * popfl
  159. *
  160. * @endcode
  161. *
  162. * prot_call() and kir_call() create this data structure on the stack
  163. * and pass in a pointer to this structure.
  164. *
  165. */
  166. struct i386_all_regs {
  167. struct i386_seg_regs segs;
  168. struct i386_regs regs;
  169. uint32_t flags;
  170. } __attribute__ (( packed ));
  171. /* Flags */
  172. #define CF ( 1 << 0 )
  173. #define PF ( 1 << 2 )
  174. #define AF ( 1 << 4 )
  175. #define ZF ( 1 << 6 )
  176. #define SF ( 1 << 7 )
  177. #define OF ( 1 << 11 )
  178. /* Segment:offset structure. Note that the order within the structure
  179. * is offset:segment.
  180. */
  181. struct segoff {
  182. uint16_t offset;
  183. uint16_t segment;
  184. } __attribute__ (( packed ));
  185. typedef struct segoff segoff_t;
  186. #endif /* REGISTERS_H */