Source code of Windows XP (NT5)
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.

128 lines
3.5 KiB

  1. title "Fiber Switch"
  2. ;++
  3. ;
  4. ; Copyright (c) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; fiber.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the platform specific fiber swtich code.
  13. ;
  14. ; Author:
  15. ;
  16. ; David N. Cutler (davec) 7-Jul-2000
  17. ;
  18. ;--
  19. include ksamd64.inc
  20. ;++
  21. ;
  22. ; VOID
  23. ; SwitchToFiber(
  24. ; PFIBER NewFiber
  25. ; )
  26. ;
  27. ; Routine Description:
  28. ;
  29. ; This function saves the state of the current fiber and switches to the
  30. ; specified fiber.
  31. ;
  32. ; Arguments:
  33. ;
  34. ; NewFiber (rcx) - Supplies the address of the new fiber.
  35. ;
  36. ; Return Value:
  37. ;
  38. ; None
  39. ;
  40. ;--
  41. LEAF_ENTRY SwitchToFiber, _TEXT$00
  42. mov rdx, gs:[TeSelf] ; get TEB address
  43. mov rax, TeFiberData[rdx] ; get current fiber address
  44. ;
  45. ; Set new deallocation stack and fiber data in TEB.
  46. ;
  47. mov r8, FbDeallocationStack[rcx] ; set deallocation stack address
  48. mov TeDeallocationStack[rdx], r8 ;
  49. mov TeFiberData[rdx], rcx ; set new fiber address
  50. ;
  51. ; Save stack limit.
  52. ;
  53. mov r8, TeStackLimit[rdx] ; save current stack limit
  54. mov FbStackLimit[rax], r8 ;
  55. ;
  56. ; Save the nonvolitile state of the current fiber.
  57. ;
  58. lea r8, FbFiberContext[rax] ; get fiber context record address
  59. mov CxRbx[r8], rbx ; save nonvolatile integer registers
  60. mov CxRbp[r8], rbp ;
  61. mov CxRsi[r8], rsi ;
  62. mov CxRdi[r8], rdi ;
  63. mov CxR12[r8], r12 ;
  64. mov CxR13[r8], r13 ;
  65. mov CxR14[r8], r14 ;
  66. mov CxR15[r8], r15 ;
  67. movq CxXmm6[r8], xmm6 ; save nonvolatile floating registers
  68. movq CxXmm7[r8], xmm7 ;
  69. movq CxXmm8[r8], xmm8 ;
  70. movq CxXmm9[r8], xmm9 ;
  71. movq CxXmm10[r8], xmm10 ;
  72. movq CxXmm11[r8], xmm11 ;
  73. movq CxXmm12[r8], xmm12 ;
  74. movq CxXmm13[r8], xmm13 ;
  75. movq CxXmm14[r8], xmm14 ;
  76. movq CxXmm15[r8], xmm15 ;
  77. mov r9, [rsp] ; save return address
  78. mov CxRip[r8], r9 ;
  79. mov CxRsp[r8], rsp ; save stack pointer
  80. ;
  81. ; Restore the new fiber stack base and stack limit.
  82. ;
  83. mov r8, FbStackBase[rcx] ; restore stack base
  84. mov TeStackBase[rdx], r8 ;
  85. mov r8, FbStackLimit[rcx] ; restore stack limit
  86. mov TeStackLimit[rdx], r8 ;
  87. ;
  88. ; Restore nonvolitile state of the new fiber.
  89. ;
  90. lea r8, FbFiberContext[rcx] ; get fiber context address
  91. mov rbx, CxRbx[r8] ; restore nonvolatile integer registers
  92. mov rbp, CxRbp[r8] ;
  93. mov rsi, CxRsi[r8] ;
  94. mov rdi, CxRdi[r8] ;
  95. mov r12, CxR12[r8] ;
  96. mov r13, CxR13[r8] ;
  97. mov r14, CxR14[r8] ;
  98. mov r15, CxR15[r8] ;
  99. movq xmm6, CxXmm6[r8] ; restore nonvolatile floating registers
  100. movq xmm7, CxXmm7[r8] ;
  101. movq xmm8, CxXmm8[r8] ;
  102. movq xmm9, CxXmm9[r8] ;
  103. movq xmm10, CxXmm10[r8] ;
  104. movq xmm11, CxXmm11[r8] ;
  105. movq xmm12, CxXmm12[r8] ;
  106. movq xmm13, CxXmm13[r8] ;
  107. movq xmm14, CxXmm14[r8] ;
  108. movq xmm15, CxXmm15[r8] ;
  109. mov rsp, CxRsp[r8] ; restore stack pointer
  110. ret ;
  111. LEAF_END SwitchToFiber, _TEXT$00
  112. end