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.

303 lines
6.5 KiB

  1. ;****************************CallConv.Inc************************************
  2. ;
  3. ; Copyright (c) 1990-1995, Microsoft Corp. All rights reserved.
  4. ;
  5. ;****************************************************************************
  6. ;****************************Public Macro************************************
  7. ;
  8. ; ComposeInst Inst,p1,p2,p3,p4,p5,p6,p7,p8,p9
  9. ;
  10. ; This macro simply concatenates all arguments into one string.
  11. ;
  12. ;
  13. ;****************************************************************************
  14. ComposeInst macro Inst,p1,p2,p3,p4,p5,p6,p7,p8,p9
  15. &Inst p1&p2&p3&p4&p5&p6&p7&p8&p9
  16. endm
  17. ;****************************Public Macro************************************
  18. ;
  19. ; CountArg cCount,ArgList
  20. ;
  21. ; This macro count the number of arguments in the ArgList and returns
  22. ; the value in cCount.
  23. ;
  24. ;
  25. ;****************************************************************************
  26. CountArg macro cCount,ArgList
  27. cCount = 0
  28. irp arg,<ArgList>
  29. cCount = cCount+1
  30. endm
  31. endm
  32. ;****************************Public Macro************************************
  33. ;
  34. ; RevPush ArgList,cCount
  35. ;
  36. ; This macro pushes the arguments in ArgList in the reverse order
  37. ; and returns the number of arguments in cCount.
  38. ;
  39. ;
  40. ;****************************************************************************
  41. RevPush macro ArgList,cCount
  42. Local index,x
  43. CountArg cCount,<ArgList>
  44. index = cCount
  45. rept cCount
  46. x = 0
  47. irp arg,<ArgList>
  48. x = x+1
  49. ife index-x
  50. push arg
  51. exitm
  52. endif
  53. endm
  54. index = index-1
  55. endm
  56. endm
  57. ;****************************Public Macro************************************
  58. ;
  59. ; The following sections contain calling-convention related macros for:
  60. ;
  61. ; PUBLICP Func,N
  62. ; to define a public label
  63. ;
  64. ; EXTRNP Func,N,Thunk
  65. ; to define a external near label
  66. ;
  67. ; LABELP Func,N
  68. ; to label an address as a routine entry point
  69. ;
  70. ; stdPROC Func,N,ArgList
  71. ; to declare a routine header
  72. ;
  73. ; ProcName Name,Func,N
  74. ; to rename a function Func to Name. Using it in conjunction with
  75. ; normal function declaration (with the new name) will solve an error
  76. ; caused by a long parameter list routine that exhausts page width.
  77. ;
  78. ; stdRET Func
  79. ; to return from Func routines (declared with stdPROC or ProcName.)
  80. ;
  81. ; stdENDP Func
  82. ; to declare the end of routine (declared with stdPROC or ProcName.)
  83. ;
  84. ; endMod Func
  85. ; to declare the end of module with an entry point at Func (declared
  86. ; with stdPROC or ProcName.)
  87. ;
  88. ; stdCall Func,ArgList
  89. ; to call to a routine--Func--with the arguments pushed on the stack
  90. ;
  91. ; MovAddr dest,Func,n
  92. ; to move the address of the routine--Func--into dest.
  93. ;
  94. ; Note that for the standard calling convention all the function names,
  95. ; Func, are automatically converted to Func@N where N is the number of
  96. ; bytes (decimal) in the argument list.
  97. ;
  98. ;
  99. ;****************************************************************************
  100. if @Version GE 600
  101. option nokeyword:<stdcall>
  102. endif
  103. PUBLICP macro Func,N
  104. ifb <N>
  105. public Func&@0
  106. else
  107. PUBLICP2 Func,%(N*4)
  108. endif
  109. endm
  110. PUBLICP2 macro Func,N
  111. public Func&@&N
  112. endm
  113. EXTRNP macro Func,N,Thunk,FastCall
  114. ifb <N>
  115. IFNDEF Func&@0
  116. extrn Func&@0:NEAR
  117. ENDIF
  118. else
  119. ifb <FastCall>
  120. ifb <Thunk>
  121. EXTRNP2 Func,%(N*4)
  122. else
  123. EXTRNTHUNK Func,%(N*4)
  124. endif
  125. else
  126. cFCall&@&Func equ (N*4)
  127. ifb <Thunk>
  128. EXTRNP2 &@&Func,%(N*4)
  129. else
  130. EXTRNTHUNK &@&Func,%(N*4)
  131. endif
  132. endif
  133. endif
  134. endm
  135. EXTRNP2 macro Func,N
  136. IFNDEF Func&@&N
  137. extrn Func&@&N:NEAR
  138. ENDIF
  139. endm
  140. EXTRNTHUNK macro Func,N
  141. IFNDEF __imp_&Func&@&N
  142. extrn __imp_&Func&@&N:DWORD
  143. ENDIF
  144. endm
  145. LABELP macro Func,N
  146. ifb <N>
  147. Func&@0 label near
  148. else
  149. LABELP2 Func,%(N*4)
  150. endif
  151. endm
  152. LABELP2 macro Func,N
  153. Func&@&N label near
  154. endm
  155. ProcName macro Name,Func,N
  156. ifb <N>
  157. cByte&Func equ 0
  158. Name equ <Func&@0>
  159. else
  160. cByte&Func equ N
  161. Name equ <Func&@&N>
  162. endif
  163. endm
  164. stdPROC macro Func,N,ArgList
  165. ProcName Func,Func,%(N*4)
  166. Func proc ArgList
  167. endm
  168. cPublicProc macro Func,N,ArgList
  169. align dword
  170. PUBLICP Func,N
  171. ifb <N>
  172. stdPROC Func,0,<ArgList>
  173. else
  174. stdPROC Func,N,<ArgList>
  175. endif
  176. endm
  177. ProcNameF macro Name,Func,N,M
  178. cByte&Func equ M
  179. cFCall&Func equ N
  180. Name equ <Func&@&N>
  181. endm
  182. stdPROCF macro Func,N,ArgList
  183. if N gt 2
  184. ProcNameF Func,Func,%(N*4),%((N-2)*4)
  185. else
  186. ProcNameF Func,Func,%(N*4),0
  187. endif
  188. Func proc ArgList
  189. endm
  190. cPublicFastCall macro Func,N,ArgList
  191. align dword
  192. PUBLICP &@&Func,N
  193. ifb <N>
  194. stdPROCF &@&Func,0,<ArgList>
  195. else
  196. stdPROCF &@&Func,N,<ArgList>
  197. endif
  198. endm
  199. fstRET macro Func
  200. ret cByte&@&Func
  201. endm
  202. stdRET macro Func
  203. ret cByte&Func
  204. endm
  205. cPublicFpo macro FpoLocals, FpoParams
  206. .FPO ( FpoParams, FpoLocals, 0, 0, 0, 0 )
  207. endm
  208. fstENDP macro Func
  209. &@&Func endp
  210. endm
  211. stdENDP macro Func
  212. Func endp
  213. endm
  214. endMod macro Func
  215. end Func
  216. endm
  217. stdCallCall macro Func,N
  218. IFDEF __imp_&Func&@&N
  219. call dword ptr [__imp_&Func&@&N]
  220. ELSE
  221. call Func&@&N
  222. ENDIF
  223. endm
  224. stdCall macro Func,ArgList
  225. Local Bytes
  226. RevPush <ArgList>,Bytes
  227. Bytes = Bytes*4
  228. stdCallCall Func,%(Bytes)
  229. endm
  230. fstCall macro Func,ArgList
  231. Local Bytes
  232. RevPush <ArgList>,Bytes
  233. Bytes = Bytes*4
  234. if Bytes eq 0
  235. stdCallCall &@&Func,%cFCall&@&Func
  236. else
  237. ; must have 2 register params
  238. stdCallCall &@&Func,%(Bytes+8)
  239. endif
  240. endm
  241. MovAddr macro dest,addr,n
  242. ComposeInst <mov >,dest,<,offset FLAT:>,addr,<@>,n
  243. endm