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.

191 lines
5.0 KiB

  1. title "Stubless Support"
  2. ;++
  3. ;
  4. ; Copyright (C) 2000 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; stubless.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module contains interpreter support routines for the AMD64 platform.
  13. ;
  14. ; Author:
  15. ;
  16. ; David N. Cutler 30-Dec-2000
  17. ;
  18. ; Environment:
  19. ;
  20. ; User mode.
  21. ;
  22. ;--
  23. include ksamd64.inc
  24. extern ObjectStublessClient:proc
  25. extern __chkstk:proc
  26. ;
  27. ; Define object stubless client macro.
  28. ;
  29. STUBLESS_CLIENT macro Method
  30. LEAF_ENTRY ObjectStublessClient&Method, _TEXT$00
  31. mov r10d, Method ; set method number
  32. jmp ObjectStubless ; finish in common code
  33. LEAF_END ObjectStublessClient&Method, _TEXT$00
  34. endm
  35. ;
  36. ; Generate stubless client thunks.
  37. ;
  38. index = 3
  39. rept (1023 - 3 + 1)
  40. STUBLESS_CLIENT %index
  41. index = index + 1
  42. endm
  43. subttl "Common Object Stubless Client Code"
  44. ;++
  45. ;
  46. ; long
  47. ; ObjectStubless (
  48. ; ...
  49. ; )
  50. ;
  51. ; Routine description:
  52. ;
  53. ; This function is jumped to from the corresponding linkage stub and calls
  54. ; the object stubless client routine to invoke the ultimate function.
  55. ;
  56. ; N.B. Only three of the possible floating argument registers are saved.
  57. ; The first argument is the "this" pointer, and therefore, cannot be
  58. ; a floating value.
  59. ;
  60. ; Arguments:
  61. ;
  62. ; ...
  63. ;
  64. ; Implicit Arguments:
  65. ;
  66. ; Method (r10d) - Supplies the method number from the thunk code.
  67. ;
  68. ; Return Value:
  69. ;
  70. ; The value as returned by the target function.
  71. ;
  72. ;--
  73. OsFrame struct
  74. SavedXmm1 dq ? ; saved nonvolatile registers
  75. SavedXmm2 dq ? ;
  76. SavedXmm3 dq ? ;
  77. OsFrame ends
  78. NESTED_ENTRY ObjectStubless, _TEXT$00
  79. alloc_stack sizeof OsFrame ; allocate stack frame
  80. save_xmm xmm1, OsFrame.SavedXmm1 ; save nonvolatile registers
  81. save_xmm xmm2, OsFrame.SavedXmm2 ;
  82. save_xmm xmm3, OsFrame.SavedXmm3 ;
  83. END_PROLOGUE
  84. mov sizeof OsFrame + 8[rsp], rcx ; save register arguments in
  85. mov sizeof OsFrame + 16[rsp], rdx ; home addresses
  86. mov sizeof OsFrame + 24[rsp], r8 ;
  87. mov sizeof OsFrame + 32[rsp], r9 ;
  88. lea rcx, sizeof OsFrame + 8[rsp] ; set address of argument list
  89. mov rdx, rsp ; set address of floating registers
  90. mov r8d, r10d ; set method number
  91. call ObjectStublessClient ;
  92. add rsp, sizeof OsFrame ; deallocate stack frame
  93. ret ; return
  94. NESTED_END ObjectStubless, _TEXT$00
  95. subttl "Invoke Function with Parameter List"
  96. ;++
  97. ;
  98. ; REGISTER_TYPE
  99. ; Invoke (
  100. ; MANAGER_FUNCTION Function,
  101. ; REGISTER_TYPE *ArgumentList,
  102. ; ULONG Arguments
  103. ; )
  104. ;
  105. ; Routine description:
  106. ;
  107. ; This function builds an appropriate argument list and calls the specified
  108. ; function.
  109. ;
  110. ; Arguments:
  111. ;
  112. ; Function (rcx) - Supplies a pointer to the target function.
  113. ;
  114. ; ArgumentList (rdx) - Supplies a pointer to the argument list.
  115. ;
  116. ; Arguments (r8d) - Supplies the number of arguments.
  117. ;
  118. ; Return Value:
  119. ;
  120. ; The value as returned by the target function.
  121. ;
  122. ;--
  123. NESTED_ENTRY Invoke, _TEXT$00
  124. push_reg rdi ; save nonvolatile registers
  125. push_reg rsi ;
  126. push_reg rbp ;
  127. set_frame rbp, 0 ; set frame pointer
  128. END_PROLOGUE
  129. mov eax, r8d ; round to even argument count
  130. inc eax ;
  131. and al, 0feh ;
  132. shl eax, 3 ; compute number of bytes
  133. call __chkstk ; check stack allocation
  134. sub rsp, rax ; allocate argument list
  135. mov r10, rcx ; save address of function
  136. mov rsi, rdx ; set source argument list address
  137. mov rdi, rsp ; set destination argument list address
  138. mov ecx, r8d ; set number of arguments
  139. rep movsq ; copy arguments to the stack
  140. ;
  141. ; N.B. All four argument registers are loaded regardless of the actual number
  142. ; of arguments.
  143. ;
  144. ; N.B. The first argument cannot be in a floating point register and therefore
  145. ; xmm0 is not loaded.
  146. ;
  147. mov rcx, 0[rsp] ; load first four argument registers
  148. mov rdx, 8[rsp] ;
  149. movq xmm1, 8[rsp] ;
  150. mov r8, 16[rsp] ;
  151. movq xmm2, 16[rsp] ;
  152. mov r9, 24[rsp] ;
  153. movq xmm3, 24[rsp] ;
  154. call r10 ; call target function
  155. mov rsp, rbp ; deallocate argument list
  156. pop rbp ; restore nonvolatile register
  157. pop rsi ;
  158. pop rdi ;
  159. ret ;
  160. NESTED_END Invoke, _TEXT$00
  161. end