sighndh.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2009 by Pierre Muller,
  4. member of the Free Pascal development team.
  5. Sigcontext and Sigaction for amd64/i386 CPUs
  6. Adapted from
  7. http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/intel/sys/regset.h
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. {$packrecords C}
  15. {$packrecords C}
  16. const
  17. { i386/amd64 definition }
  18. {
  19. #if defined(__amd64)
  20. #define _NGREG 28
  21. #else
  22. #define _NGREG 19
  23. #endif
  24. }
  25. {$ifdef x86_64 }
  26. _NGREG = 28;
  27. {$else i386 }
  28. _NGREG = 19;
  29. {$endif i386 }
  30. _NGREG32 = 19;
  31. _NGREG64 = 28;
  32. {$ifdef x86_64}
  33. (* AMD64 layout
  34. #define REG_GSBASE 27
  35. #define REG_FSBASE 26
  36. #define REG_DS 25
  37. #define REG_ES 24
  38. #define REG_GS 23
  39. #define REG_FS 22
  40. #define REG_SS 21
  41. #define REG_RSP 20
  42. #define REG_RFL 19
  43. #define REG_CS 18
  44. #define REG_RIP 17
  45. #define REG_ERR 16
  46. #define REG_TRAPNO 15
  47. #define REG_RAX 14
  48. #define REG_RCX 13
  49. #define REG_RDX 12
  50. #define REG_RBX 11
  51. #define REG_RBP 10
  52. #define REG_RSI 9
  53. #define REG_RDI 8
  54. #define REG_R8 7
  55. #define REG_R9 6
  56. #define REG_R10 5
  57. #define REG_R11 4
  58. #define REG_R12 3
  59. #define REG_R13 2
  60. #define REG_R14 1
  61. #define REG_R15 0
  62. *)
  63. REG_R15 = 0;
  64. REG_R14 = 1;
  65. REG_R13 = 2;
  66. REG_R12 = 3;
  67. REG_R11 = 4;
  68. REG_R10 = 5;
  69. REG_R9 = 6;
  70. REG_R8 = 7;
  71. REG_RDI = 8;
  72. REG_RSI = 9;
  73. REG_RBP = 10;
  74. REG_RBX = 11;
  75. REG_RDX = 12;
  76. REG_RCX = 13;
  77. REG_RAX = 14;
  78. REG_TRAPNO = 15;
  79. REG_ERR = 16;
  80. REG_RIP = 17;
  81. REG_CS = 18;
  82. REG_RFL = 19;
  83. REG_RSP = 20;
  84. REG_SS = 21;
  85. REG_FS = 22;
  86. REG_GS = 23;
  87. REG_ES = 24;
  88. REG_DS = 25;
  89. REG_FSBASE = 26;
  90. REG_GSBASE = 27;
  91. {$else i386}
  92. (* I386 layout
  93. #define SS 18 /* only stored on a privilege transition */
  94. #define UESP 17 /* only stored on a privilege transition */
  95. #define EFL 16
  96. #define CS 15
  97. #define EIP 14
  98. #define ERR 13
  99. #define TRAPNO 12
  100. #define EAX 11
  101. #define ECX 10
  102. #define EDX 9
  103. #define EBX 8
  104. #define ESP 7
  105. #define EBP 6
  106. #define ESI 5
  107. #define EDI 4
  108. #define DS 3
  109. #define ES 2
  110. #define FS 1
  111. #define GS 0
  112. *)
  113. REG_GS = 0;
  114. REG_FS = 1;
  115. REG_ES = 2;
  116. REG_DS = 3;
  117. REG_EDI = 4;
  118. REG_ESI = 5;
  119. REG_EBP = 6;
  120. REG_ESP = 7;
  121. REG_EBX = 8;
  122. REG_EDX = 9;
  123. REG_ECX = 10;
  124. REG_EAX = 11;
  125. REG_TRAPNO = 12;
  126. REG_ERR = 13;
  127. REG_EIP = 14;
  128. REG_CS = 15;
  129. REG_EFL = 16;
  130. REG_UESP = 17; (* only stored on a privilege transition *)
  131. REG_SS = 18; (* only stored on a privilege transition *)
  132. {$endif i386}
  133. {$ifdef x86_64 }
  134. REG_PC = REG_RIP;
  135. REG_FP = REG_RBP;
  136. REG_SP = REG_RSP;
  137. REG_PS = REG_RFL;
  138. REG_R0 = REG_RAX;
  139. REG_R1 = REG_RDX;
  140. {$else /* __i386 */ }
  141. REG_PC = REG_EIP;
  142. REG_FP = REG_EBP;
  143. REG_SP = REG_UESP;
  144. REG_PS = REG_EFL;
  145. REG_R0 = REG_EAX;
  146. REG_R1 = REG_EDX;
  147. {$endif }
  148. type
  149. {$ifdef x86_64}
  150. TGReg = cint64;
  151. {$else}
  152. TGReg = cint32;
  153. {$endif}
  154. TGReg32 = cint32;
  155. TGReg64 = cint64;
  156. TGRegSet = array[0.._NGREG-1] of TGReg;
  157. TGRegSet32 = array[0.._NGREG32-1] of TGReg32;
  158. TGRegSet64 = array[0.._NGREG64-1] of TGReg64;
  159. type
  160. FPU_SAVE_TYPE = (fnsave_type, fxsave_type);
  161. TFPURegs = record
  162. case longint of
  163. 0: ( fpuregs: array[0..31] of cardinal);
  164. 1: ( fpudregs: array[0..15] of double);
  165. end;
  166. PFQ = ^TFQ;
  167. TFQ = record
  168. fpq_addr : ^cuint;
  169. fpq_instr : cuint;
  170. end;
  171. (* struct fpchip_state {
  172. uint32_t state[27]; /* 287/387 saved state */
  173. uint32_t status; /* saved at exception */
  174. uint32_t mxcsr; /* SSE control and status */
  175. uint32_t xstatus; /* SSE mxcsr at exception */
  176. uint32_t __pad[2]; /* align to 128-bits */
  177. upad128_t xmm[8]; /* %xmm0-%xmm7 */
  178. } fpchip_state;
  179. *)
  180. TUpad128 = record
  181. case longint of
  182. 0: (_q : extended;);
  183. 1: (_l : array [0..4-1] of cuint32;);
  184. end;
  185. TFPChip_State = record
  186. state : array [0..27-1] of cuint32;
  187. status : cuint32;
  188. mxcsr : cuint32;
  189. xstatus : cuint32;
  190. __pad : array [0..1] of cuint32;
  191. xmm : array [0..8-1] of TUpad128;
  192. end;
  193. TFP_emul_space = record
  194. fp_emul : array [0..248-1] of cuint8;
  195. fp_epad : array [0..1] of cuint8;
  196. end;
  197. TFPU = record
  198. case longint of
  199. 0: (fpchip_state : TFPChip_state;);
  200. 1: (fp_emul_space : TFP_emul_space;);
  201. 2: (f_fpregs : Array[0..130-1] of cuint32;);
  202. end;
  203. TFPRegSet = TFPU;
  204. TMContext = record
  205. gregs : TGRegSet;
  206. fpregs : TFPRegSet;
  207. end;
  208. TStack = record
  209. ss_sp : pointer;
  210. ss_size : size_t;
  211. ss_flags : cint;
  212. end;
  213. PSigContext = ^TSigContext;
  214. TSigContext = record
  215. uc_flags : cuint;
  216. uc_link : PSigContext;
  217. uc_sigmask : sigset_t;
  218. uc_stack : TStack;
  219. uc_mcontext : TMContext;
  220. __uc_filler : array[0..5-1] of clong;
  221. end;