i386.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Rokas Kupstys
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # Partially based on code from musl libc Copyright © 2005-2014 Rich Felker, et al.
  10. .globl narch_coroExecWithStack
  11. .globl narch_setjmp
  12. .globl narch_longjmp
  13. #if defined(__MINGW32__) || defined(__MINGW64__)
  14. .globl @narch_coroExecWithStack@8
  15. .globl @narch_setjmp@4
  16. .globl @narch_longjmp@8
  17. #endif
  18. .text
  19. #if defined(__MINGW32__) || defined(__MINGW64__)
  20. @narch_coroExecWithStack@8:
  21. #endif
  22. narch_coroExecWithStack:
  23. mov %edx, %esp # swap stack with one passed to func
  24. sub $0x10, %esp # 16-byte alignment
  25. and $-0x10, %esp #
  26. sub $4, %esp # Simulate misalignment caused by return addr
  27. jmp *%ecx
  28. #if defined(__MINGW32__) || defined(__MINGW64__)
  29. @narch_setjmp@4:
  30. #endif
  31. narch_setjmp:
  32. mov %ebx, (%ecx)
  33. mov %esi, 0x04(%ecx)
  34. mov %edi, 0x08(%ecx)
  35. mov %ebp, 0x0C(%ecx)
  36. lea 0x04(%esp), %eax
  37. mov %eax, 0x10(%ecx)
  38. mov (%esp), %eax
  39. mov %eax, 0x14(%ecx)
  40. xor %eax, %eax
  41. ret
  42. #if defined(__MINGW32__) || defined(__MINGW64__)
  43. @narch_longjmp@8:
  44. #endif
  45. narch_longjmp:
  46. mov %edx, %eax
  47. test %eax, %eax
  48. jnz narch_longjmp_1
  49. inc %eax
  50. narch_longjmp_1:
  51. mov (%ecx), %ebx
  52. mov 0x04(%ecx), %esi
  53. mov 0x08(%ecx), %edi
  54. mov 0x0C(%ecx), %ebp
  55. mov 0x10(%ecx), %esp
  56. mov 0x14(%ecx), %edx
  57. jmp *%edx