You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
8.0 KiB

  1. ; Copyright Oliver Kowalke 2009.
  2. ; Distributed under the Boost Software License, Version 1.0.
  3. ; (See accompanying file LICENSE_1_0.txt or copy at
  4. ; http://www.boost.org/LICENSE_1_0.txt)
  5. ; ----------------------------------------------------------------------------------
  6. ; | 0 | 1 | |
  7. ; ----------------------------------------------------------------------------------
  8. ; | 0x0 | 0x4 | |
  9. ; ----------------------------------------------------------------------------------
  10. ; | <indicator> | |
  11. ; ----------------------------------------------------------------------------------
  12. ; ----------------------------------------------------------------------------------
  13. ; | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
  14. ; ----------------------------------------------------------------------------------
  15. ; | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 |
  16. ; ----------------------------------------------------------------------------------
  17. ; | SEE registers (XMM6-XMM15) |
  18. ; ----------------------------------------------------------------------------------
  19. ; ----------------------------------------------------------------------------------
  20. ; | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
  21. ; ----------------------------------------------------------------------------------
  22. ; | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 |
  23. ; ----------------------------------------------------------------------------------
  24. ; | SEE registers (XMM6-XMM15) |
  25. ; ----------------------------------------------------------------------------------
  26. ; ----------------------------------------------------------------------------------
  27. ; | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
  28. ; ----------------------------------------------------------------------------------
  29. ; | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 |
  30. ; ----------------------------------------------------------------------------------
  31. ; | SEE registers (XMM6-XMM15) |
  32. ; ----------------------------------------------------------------------------------
  33. ; ----------------------------------------------------------------------------------
  34. ; | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
  35. ; ----------------------------------------------------------------------------------
  36. ; | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 |
  37. ; ----------------------------------------------------------------------------------
  38. ; | SEE registers (XMM6-XMM15) |
  39. ; ----------------------------------------------------------------------------------
  40. ; ----------------------------------------------------------------------------------
  41. ; | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
  42. ; ----------------------------------------------------------------------------------
  43. ; | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 |
  44. ; ----------------------------------------------------------------------------------
  45. ; | SEE registers (XMM6-XMM15) |
  46. ; ----------------------------------------------------------------------------------
  47. ; ----------------------------------------------------------------------------------
  48. ; | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
  49. ; ----------------------------------------------------------------------------------
  50. ; | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 |
  51. ; ----------------------------------------------------------------------------------
  52. ; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
  53. ; ----------------------------------------------------------------------------------
  54. ; ----------------------------------------------------------------------------------
  55. ; | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
  56. ; ----------------------------------------------------------------------------------
  57. ; | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 |
  58. ; ----------------------------------------------------------------------------------
  59. ; | limit | base | R12 | R13 |
  60. ; ----------------------------------------------------------------------------------
  61. ; ----------------------------------------------------------------------------------
  62. ; | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
  63. ; ----------------------------------------------------------------------------------
  64. ; | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 |
  65. ; ----------------------------------------------------------------------------------
  66. ; | R14 | R15 | RDI | RSI |
  67. ; ----------------------------------------------------------------------------------
  68. ; ----------------------------------------------------------------------------------
  69. ; | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
  70. ; ----------------------------------------------------------------------------------
  71. ; | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 |
  72. ; ----------------------------------------------------------------------------------
  73. ; | RBX | RBP | RIP | EXIT |
  74. ; ----------------------------------------------------------------------------------
  75. ; standard C library function
  76. EXTERN _exit:PROC
  77. .code
  78. ; generate function table entry in .pdata and unwind information in
  79. make_fcontext PROC EXPORT FRAME
  80. ; .xdata for a function's structured exception handling unwind behavior
  81. .endprolog
  82. ; first arg of make_fcontext() == top of context-stack
  83. mov rax, rcx
  84. ; reserve 32byte shadow-space for context-function
  85. sub rax, 028h
  86. ; shift address in RAX to lower 16 byte boundary
  87. ; == pointer to fcontext_t and address of context stack
  88. and rax, -16
  89. ; reserve space for context-data on context-stack
  90. ; size for fc_mxcsr .. RIP + return-address for context-function
  91. ; on context-function entry: (RSP -0x8) % 16 == 0
  92. sub rax, 0128h
  93. ; third arg of make_fcontext() == address of context-function
  94. mov [rax+0118h], r8
  95. ; first arg of make_fcontext() == top of context-stack
  96. ; save top address of context stack as 'base'
  97. mov [rax+0d0h], rcx
  98. ; second arg of make_fcontext() == size of context-stack
  99. ; negate stack size for LEA instruction (== substraction)
  100. neg rdx
  101. ; compute bottom address of context stack (limit)
  102. lea rcx, [rcx+rdx]
  103. ; save bottom address of context stack as 'limit'
  104. mov [rax+0c8h], rcx
  105. ; save address of context stack limit as 'dealloction stack'
  106. mov [rax+0c0h], rcx
  107. ; save MMX control- and status-word
  108. stmxcsr [rax+0a8h]
  109. ; save x87 control-word
  110. fnstcw [rax+0ach]
  111. ; compute abs address of label finish
  112. lea rcx, finish
  113. ; save address of finish as return-address for context-function
  114. ; will be entered after context-function returns
  115. mov [rax+0120h], rcx
  116. ; set indicator
  117. mov rcx, 1
  118. mov [rax], rcx
  119. ret ; return pointer to context-data
  120. finish:
  121. ; 32byte shadow-space for _exit() are
  122. ; already reserved by make_fcontext()
  123. ; exit code is zero
  124. xor rcx, rcx
  125. ; exit application
  126. call _exit
  127. hlt
  128. make_fcontext ENDP
  129. END