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.

594 lines
35 KiB

  1. --- libs/context/build/Jamfile.v2.orig 2013-03-03 13:39:59.684868916 +0100
  2. +++ libs/context/build/Jamfile.v2 2013-03-03 15:09:09.893232829 +0100
  3. @@ -282,6 +284,17 @@
  4. ;
  5. alias asm_context_sources
  6. + : asm/make_i386_ms_pe_gas.S
  7. + asm/jump_i386_ms_pe_gas.S
  8. + dummy.cpp
  9. + : <address-model>32
  10. + <architecture>x86
  11. + <binary-format>pe
  12. + <target-os>windows
  13. + <toolset>gcc
  14. + ;
  15. +
  16. +alias asm_context_sources
  17. : asm/make_i386_ms_pe_masm.asm
  18. asm/jump_i386_ms_pe_masm.asm
  19. dummy.cpp
  20. @@ -379,6 +392,17 @@
  21. ;
  22. alias asm_context_sources
  23. + : asm/make_x86_64_ms_pe_gas.S
  24. + asm/jump_x86_64_ms_pe_gas.S
  25. + dummy.cpp
  26. + : <address-model>64
  27. + <architecture>x86
  28. + <binary-format>pe
  29. + <target-os>windows
  30. + <toolset>gcc
  31. + ;
  32. +
  33. +alias asm_context_sources
  34. : asm/make_x86_64_ms_pe_masm.asm
  35. asm/jump_x86_64_ms_pe_masm.asm
  36. dummy.cpp
  37. --- libs/context/src/asm/make_i386_ms_pe_gas.S.orig 2013-03-03 13:41:28.645502113 +0100
  38. +++ libs/context/src/asm/make_i386_ms_pe_gas.S 2013-03-03 14:39:27.590477410 +0100
  39. @@ -0,0 +1,115 @@
  40. +/*
  41. + Copyright Oliver Kowalke 2009.
  42. + Copyright Thomas Sailer 2013.
  43. + Distributed under the Boost Software License, Version 1.0.
  44. + (See accompanying file LICENSE_1_0.txt or copy at
  45. + http://www.boost.org/LICENSE_1_0.txt)
  46. +*/
  47. +
  48. +/********************************************************************
  49. + * *
  50. + * -------------------------------------------------------------- *
  51. + * | 0 | 1 | 2 | 3 | 4 | 5 | *
  52. + * -------------------------------------------------------------- *
  53. + * | 0h | 04h | 08h | 0ch | 010h | 014h | *
  54. + * -------------------------------------------------------------- *
  55. + * | EDI | ESI | EBX | EBP | ESP | EIP | *
  56. + * -------------------------------------------------------------- *
  57. + * -------------------------------------------------------------- *
  58. + * | 6 | 7 | 8 | | *
  59. + * -------------------------------------------------------------- *
  60. + * | 018h | 01ch | 020h | | *
  61. + * -------------------------------------------------------------- *
  62. + * | sp | size | limit | | *
  63. + * -------------------------------------------------------------- *
  64. + * -------------------------------------------------------------- *
  65. + * | 9 | | *
  66. + * -------------------------------------------------------------- *
  67. + * | 024h | | *
  68. + * -------------------------------------------------------------- *
  69. + * |fc_execpt| | *
  70. + * -------------------------------------------------------------- *
  71. + * -------------------------------------------------------------- *
  72. + * | 10 | | *
  73. + * -------------------------------------------------------------- *
  74. + * | 028h | | *
  75. + * -------------------------------------------------------------- *
  76. + * |fc_strage| | *
  77. + * -------------------------------------------------------------- *
  78. + * -------------------------------------------------------------- *
  79. + * | 11 | 12 | | *
  80. + * -------------------------------------------------------------- *
  81. + * | 02ch | 030h | | *
  82. + * -------------------------------------------------------------- *
  83. + * | fc_mxcsr|fc_x87_cw| | *
  84. + * -------------------------------------------------------------- *
  85. + * *
  86. + * *****************************************************************/
  87. +
  88. +.file "make_i386_ms_pe_gas.S"
  89. +.text
  90. +.p2align 4,,15
  91. +.globl _make_fcontext
  92. +.def _make_fcontext; .scl 2; .type 32; .endef
  93. +_make_fcontext:
  94. + movl 0x04(%esp), %eax /* load 1. arg of make_fcontext, pointer to context stack (base) */
  95. + leal -0x34(%eax),%eax /* reserve space for fcontext_t at top of context stack */
  96. +
  97. + /* shift address in EAX to lower 16 byte boundary */
  98. + /* == pointer to fcontext_t and address of context stack */
  99. + andl $-16, %eax
  100. +
  101. + movl 0x04(%esp), %ecx /* load 1. arg of make_fcontext, pointer to context stack (base) */
  102. + movl %ecx, 0x18(%eax) /* save address of context stack (base) in fcontext_t */
  103. + movl 0x08(%esp), %edx /* load 2. arg of make_fcontext, context stack size */
  104. + movl %edx, 0x1c(%eax) /* save context stack size in fcontext_t */
  105. + negl %edx /* negate stack size for LEA instruction (== substraction) */
  106. + leal (%ecx,%edx),%ecx /* compute bottom address of context stack (limit) */
  107. + movl %ecx, 0x20(%eax) /* save address of context stack (limit) in fcontext_t */
  108. + movl 0x0c(%esp), %ecx /* load 3. arg of make_fcontext, pointer to context function */
  109. + movl %ecx, 0x14(%eax) /* save address of context function in fcontext_t */
  110. +
  111. + stmxcsr 0x02c(%eax) /* save MMX control word */
  112. + fnstcw 0x030(%eax) /* save x87 control word */
  113. +
  114. + leal -0x1c(%eax),%edx /* reserve space for last frame and seh on context stack, (ESP - 0x4) % 16 == 0 */
  115. + movl %edx, 0x10(%eax) /* save address in EDX as stack pointer for context function */
  116. +
  117. + movl $finish, %ecx /* abs address of finish */
  118. + movl %ecx, (%edx) /* save address of finish as return address for context function */
  119. + /* entered after context function returns */
  120. +
  121. + /* traverse current seh chain to get the last exception handler installed by Windows */
  122. + /* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */
  123. + /* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */
  124. + /* at its end by RaiseException all seh andlers are disregarded if not present and the */
  125. + /* program is aborted */
  126. + movl %fs:(0x18), %ecx /* load NT_TIB into ECX */
  127. +
  128. +walk:
  129. + movl (%ecx), %edx /* load 'next' member of current SEH into EDX */
  130. + incl %edx /* test if 'next' of current SEH is last (== 0xffffffff) */
  131. + jz found
  132. + decl %edx
  133. + xchgl %ecx, %edx /* exchange content; ECX contains address of next SEH */
  134. + jmp walk /* inspect next SEH */
  135. +
  136. +found:
  137. + movl 0x04(%ecx), %ecx /* load 'handler' member of SEH == address of last SEH handler installed by Windows */
  138. + movl 0x10(%eax), %edx /* load address of stack pointer for context function */
  139. + movl %ecx, 0x18(%edx) /* save address in ECX as SEH handler for context */
  140. + movl $0xffffffff,%ecx /* set ECX to -1 */
  141. + movl %ecx, 0x14(%edx) /* save ECX as next SEH item */
  142. + leal 0x14(%edx), %ecx /* load address of next SEH item */
  143. + movl %ecx, 0x24(%eax) /* save next SEH */
  144. +
  145. + ret
  146. +
  147. +finish:
  148. + /* ESP points to same address as ESP on entry of context function + 0x4 */
  149. + xorl %eax, %eax
  150. + movl %eax, (%esp) /* exit code is zero */
  151. + call __exit /* exit application */
  152. + hlt
  153. +
  154. +.def __exit; .scl 2; .type 32; .endef /* standard C library function */
  155. --- libs/context/src/asm/jump_i386_ms_pe_gas.S.orig 2013-03-03 13:41:34.332670479 +0100
  156. +++ libs/context/src/asm/jump_i386_ms_pe_gas.S 2013-03-03 14:35:35.634611625 +0100
  157. @@ -0,0 +1,108 @@
  158. +/*
  159. + Copyright Oliver Kowalke 2009.
  160. + Copyright Thomas Sailer 2013.
  161. + Distributed under the Boost Software License, Version 1.0.
  162. + (See accompanying file LICENSE_1_0.txt or copy at
  163. + http://www.boost.org/LICENSE_1_0.txt)
  164. +*/
  165. +
  166. +/********************************************************************
  167. + * *
  168. + * -------------------------------------------------------------- *
  169. + * | 0 | 1 | 2 | 3 | 4 | 5 | *
  170. + * -------------------------------------------------------------- *
  171. + * | 0h | 04h | 08h | 0ch | 010h | 014h | *
  172. + * -------------------------------------------------------------- *
  173. + * | EDI | ESI | EBX | EBP | ESP | EIP | *
  174. + * -------------------------------------------------------------- *
  175. + * -------------------------------------------------------------- *
  176. + * | 6 | 7 | 8 | | *
  177. + * -------------------------------------------------------------- *
  178. + * | 018h | 01ch | 020h | | *
  179. + * -------------------------------------------------------------- *
  180. + * | sp | size | limit | | *
  181. + * -------------------------------------------------------------- *
  182. + * -------------------------------------------------------------- *
  183. + * | 9 | | *
  184. + * -------------------------------------------------------------- *
  185. + * | 024h | | *
  186. + * -------------------------------------------------------------- *
  187. + * |fc_execpt| | *
  188. + * -------------------------------------------------------------- *
  189. + * -------------------------------------------------------------- *
  190. + * | 10 | | *
  191. + * -------------------------------------------------------------- *
  192. + * | 028h | | *
  193. + * -------------------------------------------------------------- *
  194. + * |fc_strage| | *
  195. + * -------------------------------------------------------------- *
  196. + * -------------------------------------------------------------- *
  197. + * | 11 | 12 | | *
  198. + * -------------------------------------------------------------- *
  199. + * | 02ch | 030h | | *
  200. + * -------------------------------------------------------------- *
  201. + * | fc_mxcsr|fc_x87_cw| | *
  202. + * -------------------------------------------------------------- *
  203. + * *
  204. + * *****************************************************************/
  205. +
  206. +.file "jump_i386_ms_pe_gas.S"
  207. +.text
  208. +.p2align 4,,15
  209. +.globl _jump_fcontext
  210. +.def _jump_fcontext; .scl 2; .type 32; .endef
  211. +_jump_fcontext:
  212. + movl 0x04(%esp), %ecx /* load address of the first fcontext_t arg */
  213. + movl %edi, (%ecx) /* save EDI */
  214. + movl %esi, 0x04(%ecx) /* save ESI */
  215. + movl %ebx, 0x08(%ecx) /* save EBX */
  216. + movl %ebp, 0x0c(%ecx) /* save EBP */
  217. +
  218. + movl %fs:(0x18), %edx /* load NT_TIB */
  219. + movl (%edx), %eax /* load current SEH exception list */
  220. + movl %eax, 0x24(%ecx) /* save current exception list */
  221. + movl 0x04(%edx), %eax /* load current stack base */
  222. + movl %eax, 0x18(%ecx) /* save current stack base */
  223. + movl 0x08(%edx), %eax /* load current stack limit */
  224. + movl %eax, 0x20(%ecx) /* save current stack limit */
  225. + movl 0x10(%edx), %eax /* load fiber local storage */
  226. + movl %eax, 0x28(%ecx) /* save fiber local storage */
  227. +
  228. + leal 0x04(%esp), %eax /* exclude the return address */
  229. + movl %eax, 0x10(%ecx) /* save as stack pointer */
  230. + movl (%esp), %eax /* load return address */
  231. + movl %eax, 0x14(%ecx) /* save return address */
  232. +
  233. + movl 0x08(%esp), %edx /* load address of the second fcontext_t arg */
  234. + movl (%edx), %edi /* restore EDI */
  235. + movl 0x04(%edx), %esi /* restore ESI */
  236. + movl 0x08(%edx), %ebx /* restore EBX */
  237. + movl 0x0c(%edx), %ebp /* restore EBP */
  238. +
  239. + movl 0x10(%esp), %eax /* check if fpu enve preserving was requested */
  240. + testl %eax, %eax
  241. + je 1f
  242. +
  243. + stmxcsr 0x2c(%ecx) /* save MMX control word */
  244. + fnstcw 0x30(%ecx) /* save x87 control word */
  245. + ldmxcsr 0x2c(%edx) /* restore MMX control word */
  246. + fldcw 0x30(%edx) /* restore x87 control word */
  247. +1:
  248. + movl %edx, %ecx
  249. + movl %fs:(0x18), %edx /* load NT_TIB */
  250. + movl 0x24(%ecx), %eax /* load SEH exception list */
  251. + movl %eax, (%edx) /* restore next SEH item */
  252. + movl 0x18(%ecx), %eax /* load stack base */
  253. + movl %eax, 0x04(%edx) /* restore stack base */
  254. + movl 0x20(%ecx), %eax /* load stack limit */
  255. + movl %eax, 0x08(%edx) /* restore stack limit */
  256. + movl 0x28(%ecx), %eax /* load fiber local storage */
  257. + movl %eax, 0x10(%edx) /* restore fiber local storage */
  258. +
  259. + movl 0x0c(%esp), %eax /* use third arg as return value after jump */
  260. +
  261. + movl 0x10(%ecx), %esp /* restore ESP */
  262. + movl %eax, 0x04(%esp) /* use third arg as first arg in context function */
  263. + movl 0x14(%ecx), %ecx /* fetch the address to return to */
  264. +
  265. + jmp *%ecx /* indirect jump to context */
  266. --- libs/context/src/asm/make_x86_64_ms_pe_gas.S.orig 2013-03-03 13:43:03.137299031 +0100
  267. +++ libs/context/src/asm/make_x86_64_ms_pe_gas.S 2013-03-03 14:54:16.036775106 +0100
  268. @@ -0,0 +1,132 @@
  269. +/*
  270. + Copyright Oliver Kowalke 2009.
  271. + Copyright Thomas Sailer 2013.
  272. + Distributed under the Boost Software License, Version 1.0.
  273. + (See accompanying file LICENSE_1_0.txt or copy at
  274. + http://www.boost.org/LICENSE_1_0.txt)
  275. +*/
  276. +
  277. +/****************************************************************************************
  278. + * *
  279. + * ---------------------------------------------------------------------------------- *
  280. + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  281. + * ---------------------------------------------------------------------------------- *
  282. + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
  283. + * ---------------------------------------------------------------------------------- *
  284. + * | R12 | R13 | R14 | R15 | *
  285. + * ---------------------------------------------------------------------------------- *
  286. + * ---------------------------------------------------------------------------------- *
  287. + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  288. + * ---------------------------------------------------------------------------------- *
  289. + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
  290. + * ---------------------------------------------------------------------------------- *
  291. + * | RDI | RSI | RBX | RBP | *
  292. + * ---------------------------------------------------------------------------------- *
  293. + * ---------------------------------------------------------------------------------- *
  294. + * | 16 | 17 | 18 | 19 | | *
  295. + * ---------------------------------------------------------------------------------- *
  296. + * | 0x40 | 0x44 | 0x48 | 0x4c | | *
  297. + * ---------------------------------------------------------------------------------- *
  298. + * | RSP | RIP | | *
  299. + * ---------------------------------------------------------------------------------- *
  300. + * ---------------------------------------------------------------------------------- *
  301. + * | 20 | 21 | 22 | 23 | 24 | 25 | | *
  302. + * ---------------------------------------------------------------------------------- *
  303. + * | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | | *
  304. + * ---------------------------------------------------------------------------------- *
  305. + * | sp | size | limit | | *
  306. + * ---------------------------------------------------------------------------------- *
  307. + * ---------------------------------------------------------------------------------- *
  308. + * | 26 | 27 | | *
  309. + * ---------------------------------------------------------------------------------- *
  310. + * | 0x68 | 0x6c | | *
  311. + * ---------------------------------------------------------------------------------- *
  312. + * | fbr_strg | | *
  313. + * ---------------------------------------------------------------------------------- *
  314. + * ---------------------------------------------------------------------------------- *
  315. + * | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | *
  316. + * ---------------------------------------------------------------------------------- *
  317. + * | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 0x88 | 0x8c | *
  318. + * ---------------------------------------------------------------------------------- *
  319. + * | fc_mxcsr|fc_x87_cw| fc_xmm | SEE registers (XMM6-XMM15) | *
  320. + * ---------------------------------------------------------------------------------- *
  321. + * ---------------------------------------------------------------------------------- *
  322. + * | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | *
  323. + * ---------------------------------------------------------------------------------- *
  324. + * | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 0xa8 | 0xac | *
  325. + * ---------------------------------------------------------------------------------- *
  326. + * | SEE registers (XMM6-XMM15) | *
  327. + * ---------------------------------------------------------------------------------- *
  328. + * ---------------------------------------------------------------------------------- *
  329. + * | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | *
  330. + * ---------------------------------------------------------------------------------- *
  331. + * | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 0xc8 | 0xcc | *
  332. + * ---------------------------------------------------------------------------------- *
  333. + * | SEE registers (XMM6-XMM15) | *
  334. + * ---------------------------------------------------------------------------------- *
  335. + * ---------------------------------------------------------------------------------- *
  336. + * | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | *
  337. + * ---------------------------------------------------------------------------------- *
  338. + * | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 0xe8 | 0xec | *
  339. + * ---------------------------------------------------------------------------------- *
  340. + * | SEE registers (XMM6-XMM15) | *
  341. + * ---------------------------------------------------------------------------------- *
  342. + * ---------------------------------------------------------------------------------- *
  343. + * | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | *
  344. + * ---------------------------------------------------------------------------------- *
  345. + * | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 0x108 | 0x10c | *
  346. + * ---------------------------------------------------------------------------------- *
  347. + * | SEE registers (XMM6-XMM15) | *
  348. + * ---------------------------------------------------------------------------------- *
  349. + * ---------------------------------------------------------------------------------- *
  350. + * | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | *
  351. + * ---------------------------------------------------------------------------------- *
  352. + * | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 0x128 | 0x12c | *
  353. + * ---------------------------------------------------------------------------------- *
  354. + * | SEE registers (XMM6-XMM15) | *
  355. + * ---------------------------------------------------------------------------------- *
  356. + * *
  357. + * *************************************************************************************/
  358. +
  359. +.file "make_x86_64_ms_pe_gas.S"
  360. +.text
  361. +.p2align 4,,15
  362. +.globl make_fcontext
  363. +.def make_fcontext; .scl 2; .type 32; .endef
  364. +.seh_proc make_fcontext
  365. +make_fcontext:
  366. +.seh_endprologue
  367. + leaq -0x130(%rcx),%rax /* reserve space for fcontext_t at top of context stack */
  368. +
  369. + /* shift address in RAX to lower 16 byte boundary */
  370. + /* == pointer to fcontext_t and address of context stack */
  371. + andq $-16, %rax
  372. +
  373. + movq %r8, 0x48(%rax) /* save address of context function in fcontext_t */
  374. + movq %rdx, 0x58(%rax) /* save context stack size in fcontext_t */
  375. + movq %rcx, 0x50(%rax) /* save address of context stack pointer (base) in fcontext_t */
  376. +
  377. + negq %rdx /* negate stack size for LEA instruction (== substraction) */
  378. + leaq (%rcx,%rdx),%rcx /* compute bottom address of context stack (limit) */
  379. + movq %rcx, 0x60(%rax) /* save bottom address of context stack (limit) in fcontext_t */
  380. +
  381. + stmxcsr 0x70(%rax) /* save MMX control and status word */
  382. + fnstcw 0x74(%rax) /* save x87 control word */
  383. +
  384. + leaq -0x28(%rax),%rdx /* reserve 32byte shadow space + return address on stack, (RSP - 0x8) % 16 == 0 */
  385. + movq %rdx, 0x40(%rax) /* save address in RDX as stack pointer for context function */
  386. +
  387. + leaq finish(%rip),%rcx /* compute abs address of label finish */
  388. + movq %rcx,(%rdx) /* save address of finish as return address for context function */
  389. + /* entered after context function returns */
  390. +
  391. + ret
  392. +
  393. +finish:
  394. + /* RSP points to same address as RSP on entry of context function + 0x8 */
  395. + xorq %rcx, %rcx /* exit code is zero */
  396. + call _exit /* exit application */
  397. + hlt
  398. +.seh_endproc
  399. +
  400. +.def _exit; .scl 2; .type 32; .endef /* standard C library function */
  401. --- libs/context/src/asm/jump_x86_64_ms_pe_gas.S.orig 2013-03-03 13:42:57.753139784 +0100
  402. +++ libs/context/src/asm/jump_x86_64_ms_pe_gas.S 2013-03-03 15:06:08.269856857 +0100
  403. @@ -0,0 +1,189 @@
  404. +/*
  405. + Copyright Oliver Kowalke 2009.
  406. + Copyright Thomas Sailer 2013.
  407. + Distributed under the Boost Software License, Version 1.0.
  408. + (See accompanying file LICENSE_1_0.txt or copy at
  409. + http://www.boost.org/LICENSE_1_0.txt)
  410. +*/
  411. +
  412. +/****************************************************************************************
  413. + * *
  414. + * ---------------------------------------------------------------------------------- *
  415. + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  416. + * ---------------------------------------------------------------------------------- *
  417. + * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
  418. + * ---------------------------------------------------------------------------------- *
  419. + * | R12 | R13 | R14 | R15 | *
  420. + * ---------------------------------------------------------------------------------- *
  421. + * ---------------------------------------------------------------------------------- *
  422. + * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  423. + * ---------------------------------------------------------------------------------- *
  424. + * | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
  425. + * ---------------------------------------------------------------------------------- *
  426. + * | RDI | RSI | RBX | RBP | *
  427. + * ---------------------------------------------------------------------------------- *
  428. + * ---------------------------------------------------------------------------------- *
  429. + * | 16 | 17 | 18 | 19 | | *
  430. + * ---------------------------------------------------------------------------------- *
  431. + * | 0x40 | 0x44 | 0x48 | 0x4c | | *
  432. + * ---------------------------------------------------------------------------------- *
  433. + * | RSP | RIP | | *
  434. + * ---------------------------------------------------------------------------------- *
  435. + * ---------------------------------------------------------------------------------- *
  436. + * | 20 | 21 | 22 | 23 | 24 | 25 | | *
  437. + * ---------------------------------------------------------------------------------- *
  438. + * | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | | *
  439. + * ---------------------------------------------------------------------------------- *
  440. + * | sp | size | limit | | *
  441. + * ---------------------------------------------------------------------------------- *
  442. + * ---------------------------------------------------------------------------------- *
  443. + * | 26 | 27 | | *
  444. + * ---------------------------------------------------------------------------------- *
  445. + * | 0x68 | 0x6c | | *
  446. + * ---------------------------------------------------------------------------------- *
  447. + * | fbr_strg | | *
  448. + * ---------------------------------------------------------------------------------- *
  449. + * ---------------------------------------------------------------------------------- *
  450. + * | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | *
  451. + * ---------------------------------------------------------------------------------- *
  452. + * | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | 0x88 | 0x8c | *
  453. + * ---------------------------------------------------------------------------------- *
  454. + * | fc_mxcsr|fc_x87_cw| fc_xmm | SEE registers (XMM6-XMM15) | *
  455. + * ---------------------------------------------------------------------------------- *
  456. + * ---------------------------------------------------------------------------------- *
  457. + * | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | *
  458. + * ---------------------------------------------------------------------------------- *
  459. + * | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | 0xa8 | 0xac | *
  460. + * ---------------------------------------------------------------------------------- *
  461. + * | SEE registers (XMM6-XMM15) | *
  462. + * ---------------------------------------------------------------------------------- *
  463. + * ---------------------------------------------------------------------------------- *
  464. + * | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | *
  465. + * ---------------------------------------------------------------------------------- *
  466. + * | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | 0xc8 | 0xcc | *
  467. + * ---------------------------------------------------------------------------------- *
  468. + * | SEE registers (XMM6-XMM15) | *
  469. + * ---------------------------------------------------------------------------------- *
  470. + * ---------------------------------------------------------------------------------- *
  471. + * | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | *
  472. + * ---------------------------------------------------------------------------------- *
  473. + * | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | 0xe8 | 0xec | *
  474. + * ---------------------------------------------------------------------------------- *
  475. + * | SEE registers (XMM6-XMM15) | *
  476. + * ---------------------------------------------------------------------------------- *
  477. + * ---------------------------------------------------------------------------------- *
  478. + * | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | *
  479. + * ---------------------------------------------------------------------------------- *
  480. + * | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | 0x108 | 0x10c | *
  481. + * ---------------------------------------------------------------------------------- *
  482. + * | SEE registers (XMM6-XMM15) | *
  483. + * ---------------------------------------------------------------------------------- *
  484. + * ---------------------------------------------------------------------------------- *
  485. + * | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | *
  486. + * ---------------------------------------------------------------------------------- *
  487. + * | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | 0x128 | 0x12c | *
  488. + * ---------------------------------------------------------------------------------- *
  489. + * | SEE registers (XMM6-XMM15) | *
  490. + * ---------------------------------------------------------------------------------- *
  491. + * *
  492. + * *************************************************************************************/
  493. +
  494. +.file "jump_x86_64_ms_pe_gas.S"
  495. +.text
  496. +.p2align 4,,15
  497. +.globl jump_fcontext
  498. +.def jump_fcontext; .scl 2; .type 32; .endef
  499. +.seh_proc jump_fcontext
  500. +jump_fcontext:
  501. +.seh_endprologue
  502. + movq %r12, (%rcx) /* save R12 */
  503. + movq %r13, 0x08(%rcx) /* save R13 */
  504. + movq %r14, 0x10(%rcx) /* save R14 */
  505. + movq %r15, 0x18(%rcx) /* save R15 */
  506. + movq %rdi, 0x20(%rcx) /* save RDI */
  507. + movq %rsi, 0x28(%rcx) /* save RSI */
  508. + movq %rbx, 0x30(%rcx) /* save RBX */
  509. + movq %rbp, 0x38(%rcx) /* save RBP */
  510. +
  511. + movq %gs:(0x30), %r10 /* load NT_TIB */
  512. + movq 0x08(%r10), %rax /* load current stack base */
  513. + movq %rax, 0x50(%rcx) /* save current stack base */
  514. + movq 0x10(%r10), %rax /* load current stack limit */
  515. + movq %rax, 0x60(%rcx) /* save current stack limit */
  516. + movq 0x18(%r10), %rax /* load fiber local storage */
  517. + movq %rax, 0x68(%rcx) /* save fiber local storage */
  518. +
  519. + testq %r9, %r9
  520. + je 1f
  521. +
  522. + stmxcsr 0x70(%rcx) /* save MMX control and status word */
  523. + fnstcw 0x74(%rcx) /* save x87 control word */
  524. + /* save XMM storage */
  525. + /* save start address of SSE register block in R10 */
  526. + leaq 0x90(%rcx), %r10
  527. + /* shift address in R10 to lower 16 byte boundary */
  528. + /* == pointer to SEE register block */
  529. + andq $-16, %r10
  530. +
  531. + movaps %xmm6, (%r10)
  532. + movaps %xmm7, 0x10(%r10)
  533. + movaps %xmm8, 0x20(%r10)
  534. + movaps %xmm9, 0x30(%r10)
  535. + movaps %xmm10, 0x40(%r10)
  536. + movaps %xmm11, 0x50(%r10)
  537. + movaps %xmm12, 0x60(%r10)
  538. + movaps %xmm13, 0x70(%r10)
  539. + movaps %xmm14, 0x80(%r10)
  540. + movaps %xmm15, 0x90(%r10)
  541. +
  542. + ldmxcsr 0x70(%rdx) /* restore MMX control and status word */
  543. + fldcw 0x74(%rdx) /* restore x87 control word */
  544. + /* restore XMM storage */
  545. + /* save start address of SSE register block in R10 */
  546. + leaq 0x90(%rdx), %r10
  547. + /* shift address in R10 to lower 16 byte boundary */
  548. + /* == pointer to SEE register block */
  549. + andq $-16, %r10
  550. +
  551. + movaps (%r10), %xmm6
  552. + movaps 0x10(%r10), %xmm7
  553. + movaps 0x20(%r10), %xmm8
  554. + movaps 0x30(%r10), %xmm9
  555. + movaps 0x40(%r10), %xmm10
  556. + movaps 0x50(%r10), %xmm11
  557. + movaps 0x60(%r10), %xmm12
  558. + movaps 0x70(%r10), %xmm13
  559. + movaps 0x80(%r10), %xmm14
  560. + movaps 0x90(%r10), %xmm15
  561. +
  562. +1:
  563. + leaq 0x08(%rsp), %rax /* exclude the return address */
  564. + movq %rax, 0x40(%rcx) /* save as stack pointer */
  565. + movq (%rsp), %rax /* load return address */
  566. + movq %rax, 0x48(%rcx) /* save return address */
  567. +
  568. + movq (%rdx), %r12 /* restore R12 */
  569. + movq 0x08(%rdx), %r13 /* restore R13 */
  570. + movq 0x10(%rdx), %r14 /* restore R14 */
  571. + movq 0x18(%rdx), %r15 /* restore R15 */
  572. + movq 0x20(%rdx), %rdi /* restore RDI */
  573. + movq 0x28(%rdx), %rsi /* restore RSI */
  574. + movq 0x30(%rdx), %rbx /* restore RBX */
  575. + movq 0x38(%rdx), %rbp /* restore RBP */
  576. +
  577. + movq %gs:(0x30), %r10 /* load NT_TIB */
  578. + movq 0x50(%rdx), %rax /* load stack base */
  579. + movq %rax, 0x08(%r10) /* restore stack base */
  580. + movq 0x60(%rdx), %rax /* load stack limit */
  581. + movq %rax, 0x10(%r10) /* restore stack limit */
  582. + movq 0x68(%rdx), %rax /* load fiber local storage */
  583. + movq %rax, 0x18(%r10) /* restore fiber local storage */
  584. +
  585. + movq 0x40(%rdx), %rsp /* restore RSP */
  586. + movq 0x48(%rdx), %r10 /* fetch the address to returned to */
  587. +
  588. + movq %r8, %rax /* use third arg as return value after jump */
  589. + movq %r8, %rcx /* use third arg as first arg in context function */
  590. +
  591. + jmp *%r10 /* indirect jump to caller */
  592. +.seh_endproc