make_i386_sysv_macho_gas.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /****************************************************************************************
  8. * *
  9. * ---------------------------------------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * ---------------------------------------------------------------------------------- *
  12. * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
  13. * ---------------------------------------------------------------------------------- *
  14. * | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | to | *
  15. * ---------------------------------------------------------------------------------- *
  16. * ---------------------------------------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ---------------------------------------------------------------------------------- *
  19. * | 0x20 | | *
  20. * ---------------------------------------------------------------------------------- *
  21. * | data | | *
  22. * ---------------------------------------------------------------------------------- *
  23. * *
  24. ****************************************************************************************/
  25. .text
  26. .globl _make_fcontext
  27. .align 2
  28. _make_fcontext:
  29. /* first arg of make_fcontext() == top of context-stack */
  30. movl 0x4(%esp), %eax
  31. /* reserve space for first argument of context-function
  32. eax might already point to a 16byte border */
  33. leal -0x8(%eax), %eax
  34. /* shift address in EAX to lower 16 byte boundary */
  35. andl $-16, %eax
  36. /* reserve space for context-data on context-stack */
  37. leal -0x2c(%eax), %eax
  38. /* third arg of make_fcontext() == address of context-function */
  39. /* stored in EBX */
  40. movl 0xc(%esp), %ecx
  41. movl %ecx, 0x10(%eax)
  42. /* save MMX control- and status-word */
  43. stmxcsr (%eax)
  44. /* save x87 control-word */
  45. fnstcw 0x4(%eax)
  46. /* compute abs address of label trampoline */
  47. call 1f
  48. /* address of trampoline 1 */
  49. 1: popl %ecx
  50. /* compute abs address of label trampoline */
  51. addl $trampoline-1b, %ecx
  52. /* save address of trampoline as return address */
  53. /* will be entered after calling jump_fcontext() first time */
  54. movl %ecx, 0x18(%eax)
  55. /* compute abs address of label finish */
  56. call 2f
  57. /* address of label 2 */
  58. 2: popl %ecx
  59. /* compute abs address of label finish */
  60. addl $finish-2b, %ecx
  61. /* save address of finish as return-address for context-function */
  62. /* will be entered after context-function returns */
  63. movl %ecx, 0x14(%eax)
  64. ret /* return pointer to context-data */
  65. trampoline:
  66. /* move transport_t for entering context-function */
  67. movl %eax, (%esp)
  68. movl %edx, 0x4(%esp)
  69. pushl %ebp
  70. /* jump to context-function */
  71. jmp *%ebx
  72. finish:
  73. /* exit code is zero */
  74. xorl %eax, %eax
  75. movl %eax, (%esp)
  76. /* exit application */
  77. call __exit
  78. hlt