make.S 3.2 KB

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