make_i386_sysv_elf_gas.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 | hidden | *
  15. * ---------------------------------------------------------------------------------- *
  16. * ---------------------------------------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * ---------------------------------------------------------------------------------- *
  19. * | 0x20 | 0x24 | | *
  20. * ---------------------------------------------------------------------------------- *
  21. * | to | data | | *
  22. * ---------------------------------------------------------------------------------- *
  23. * *
  24. ****************************************************************************************/
  25. .text
  26. .globl make_fcontext
  27. .align 2
  28. .type make_fcontext,@function
  29. make_fcontext:
  30. /* first arg of make_fcontext() == top of context-stack */
  31. movl 0x4(%esp), %eax
  32. /* reserve space for first argument of context-function
  33. eax might already point to a 16byte border */
  34. leal -0x8(%eax), %eax
  35. /* shift address in EAX to lower 16 byte boundary */
  36. andl $-16, %eax
  37. /* reserve space for context-data on context-stack */
  38. leal -0x28(%eax), %eax
  39. /* third arg of make_fcontext() == address of context-function */
  40. /* stored in EBX */
  41. movl 0xc(%esp), %ecx
  42. movl %ecx, 0x10(%eax)
  43. /* save MMX control- and status-word */
  44. stmxcsr (%eax)
  45. /* save x87 control-word */
  46. fnstcw 0x4(%eax)
  47. /* return transport_t */
  48. /* FCTX == EDI, DATA == ESI */
  49. leal 0x8(%eax), %ecx
  50. movl %ecx, 0x1c(%eax)
  51. /* compute abs address of label trampoline */
  52. call 1f
  53. /* address of trampoline 1 */
  54. 1: popl %ecx
  55. /* compute abs address of label trampoline */
  56. addl $trampoline-1b, %ecx
  57. /* save address of trampoline as return address */
  58. /* will be entered after calling jump_fcontext() first time */
  59. movl %ecx, 0x18(%eax)
  60. /* compute abs address of label finish */
  61. call 2f
  62. /* address of label 2 */
  63. 2: popl %ecx
  64. /* compute abs address of label finish */
  65. addl $finish-2b, %ecx
  66. /* save address of finish as return-address for context-function */
  67. /* will be entered after context-function returns */
  68. movl %ecx, 0x14(%eax)
  69. ret /* return pointer to context-data */
  70. trampoline:
  71. /* move transport_t for entering context-function */
  72. movl %edi, (%esp)
  73. movl %esi, 0x4(%esp)
  74. pushl %ebp
  75. /* jump to context-function */
  76. jmp *%ebx
  77. finish:
  78. call 3f
  79. /* address of label 3 */
  80. 3: popl %ebx
  81. /* compute address of GOT and store it in EBX */
  82. addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx
  83. /* exit code is zero */
  84. xorl %eax, %eax
  85. movl %eax, (%esp)
  86. /* exit application */
  87. call _exit@PLT
  88. hlt
  89. .size make_fcontext,.-make_fcontext
  90. /* Mark that we don't need executable stack. */
  91. .section .note.GNU-stack,"",%progbits