jump_i386_ms_pe_gas.asm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Copyright Oliver Kowalke 2009.
  3. Copyright Thomas Sailer 2013.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. /*************************************************************************************
  9. * --------------------------------------------------------------------------------- *
  10. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
  11. * --------------------------------------------------------------------------------- *
  12. * | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch | *
  13. * --------------------------------------------------------------------------------- *
  14. * | fc_strg |fc_deallo| limit | base | fc_seh | EDI | ESI | EBX | *
  15. * --------------------------------------------------------------------------------- *
  16. * --------------------------------------------------------------------------------- *
  17. * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
  18. * --------------------------------------------------------------------------------- *
  19. * | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch | *
  20. * --------------------------------------------------------------------------------- *
  21. * | EBP | EIP | to | data | | EH NXT |SEH HNDLR| | *
  22. * --------------------------------------------------------------------------------- *
  23. *************************************************************************************/
  24. .file "jump_i386_ms_pe_gas.asm"
  25. .text
  26. .p2align 4,,15
  27. .globl _jump_fcontext
  28. .def _jump_fcontext; .scl 2; .type 32; .endef
  29. _jump_fcontext:
  30. pushl %ebp /* save EBP */
  31. pushl %ebx /* save EBX */
  32. pushl %esi /* save ESI */
  33. pushl %edi /* save EDI */
  34. /* load NT_TIB */
  35. movl %fs:(0x18), %edx
  36. /* load current SEH exception list */
  37. movl (%edx), %eax
  38. push %eax
  39. /* load current stack base */
  40. movl 0x04(%edx), %eax
  41. push %eax
  42. /* load current stack limit */
  43. movl 0x08(%edx), %eax
  44. push %eax
  45. /* load current dealloction stack */
  46. movl 0xe0c(%edx), %eax
  47. push %eax
  48. /* load fiber local storage */
  49. movl 0x10(%edx), %eax
  50. push %eax
  51. /* store ESP (pointing to context-data) in EAX */
  52. movl %esp, %eax
  53. /* first arg of jump_fcontext() == fcontext to jump to */
  54. movl 0x28(%esp), %ecx
  55. /* restore ESP (pointing to context-data) from EDX */
  56. movl %ecx, %esp
  57. /* load NT_TIB into ECX */
  58. movl %fs:(0x18), %edx
  59. /* restore fiber local storage */
  60. popl %ecx
  61. movl %ecx, 0x10(%edx)
  62. /* restore current deallocation stack */
  63. popl %ecx
  64. movl %ecx, 0xe0c(%edx)
  65. /* restore current stack limit */
  66. popl %ecx
  67. movl %ecx, 0x08(%edx)
  68. /* restore current stack base */
  69. popl %ecx
  70. movl %ecx, 0x04(%edx)
  71. /* restore current SEH exception list */
  72. popl %ecx
  73. movl %ecx, (%edx)
  74. popl %edi /* save EDI */
  75. popl %esi /* save ESI */
  76. popl %ebx /* save EBX */
  77. popl %ebp /* save EBP */
  78. /* return transfer_t */
  79. /* FCTX == EAX, DATA == EDX */
  80. movl 0x2c(%eax), %edx
  81. /* jump to context */
  82. ret
  83. .section .drectve
  84. .ascii " -export:\"jump_fcontext\""