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.1KB

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