Leaked source code of windows server 2003
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.

407 lines
8.5 KiB

  1. pushcontext listing
  2. .nolist
  3. ;
  4. ; (C) Copyright Microsoft Corporation 1992, 1995
  5. ; This file is used to create the same sets of prologue and epilogue
  6. ; sequences which the Microsoft C 6.00 compiler will produce. This
  7. ; file would be used for writing windows programs and to provide
  8. ; such features as stack checking in the assembler portions of
  9. ; a C based project.
  10. ; The following global variables will affect the prolog/epilog
  11. ; sequences produced
  12. ;
  13. ; PROFILE - If 1 then __penter calls will be inserted in all prologs
  14. ; ?WP_DEBUG - If 1 then prolog/epilog sequences will be forced
  15. ; ?WP_CHECKSTACK - If 1 then a check stack will be forced on all
  16. ; procedures
  17. ; ?WP_INCBP - If 1 then the inc bp sequence will be generated on
  18. ; all far procedures
  19. ; ?WP_LOADDS - If 1 then the load ds sequence will be generated on
  20. ; all far procedures
  21. ;
  22. ifndef ?WP_DEBUG
  23. ?WP_DEBUG = 0
  24. endif
  25. ifndef ?WP_CHECKSTACK
  26. ?WP_CHECKSTACK = 0
  27. endif
  28. ifndef ?WP_INCBP
  29. ?WP_INCBP = 0
  30. endif
  31. ifndef ?WP_LOADDS
  32. ?WP_LOADDS = 0
  33. endif
  34. ifndef PROFILE
  35. PROFILE = 0
  36. endif
  37. ;
  38. ; Complain if we are in a segment as this will affect how the
  39. ; externdefs are done and therefore the fixups and code
  40. ; created on the checkstack calls
  41. ;
  42. % ifnb <@CurSeg>
  43. echo Include should not be contained in a segment
  44. endif
  45. externdef C _aNchkstk:near ; Extern the symbols
  46. externdef C _aFchkstk:far ; for later reference
  47. externdef C _penter:near
  48. ;
  49. ; This macro will produce the same output as will the
  50. ; C6 compiler for the given switches.
  51. ;
  52. ; The following may be placed in the MacroArgs field of the
  53. ; proc defintion:
  54. ;
  55. ; CHECKSTACK
  56. ; NOCHECKSTACK
  57. ; LOADDS
  58. ; NOLOADDS
  59. ; FORCEFRAME
  60. ; INCBP
  61. ; NOINCBP
  62. ; PROFILE
  63. option prologue:cPrologue
  64. cPrologue macro szProcName, flags, cbParams, cbLocals, rgRegs, rgUserParams
  65. LOCAL ?doPrologue
  66. LOCAL ?loadds
  67. LOCAL ?checkstack
  68. LOCAL ?incbp
  69. LOCAL ?cbLocals
  70. LOCAL ?doProfile
  71. ; pushcontext listing
  72. ; .nolistmacro
  73. ; .listmacroall
  74. ?doPrologue = 0
  75. ?loadds = 0
  76. ?checkstack = 0
  77. ?incbp = 0
  78. ?cbLocals = cbLocals
  79. ?doProfile = 0
  80. ;; Set the defaults based on the global values specified
  81. ;;
  82. if ?WP_DEBUG NE 0 ;; Force frames by default
  83. ?doPrologue = 1
  84. endif
  85. if ?WP_CHECKSTACK NE 0 ;; Force checkstack by default
  86. ?checkstack = 1
  87. endif
  88. if ?WP_INCBP NE 0 ;; Force incbp by default if far
  89. if flags AND 020h
  90. ?incbp = 1
  91. endif
  92. endif
  93. if ?WP_LOADDS NE 0 ;; Force loadds by default if far
  94. if flags AND 020h
  95. ?loadds = 1
  96. endif
  97. endif
  98. if PROFILE NE 0 ;; profiling wanted
  99. ?doProfile = 1 ;; turn on profiling
  100. endif
  101. ;;
  102. ;; Get all of the user parameters parsed
  103. ;;
  104. ifnb <rgUserParams> ;; Parse user params if exsisting
  105. for p,<rgUserParams> ;; For every user param
  106. ifidni <p>, <CHECKSTACK> ;; Is it checkstack?
  107. ?checkstack = 1 ;; Yes -- do checkstack
  108. endif
  109. ifidni <p>, <NOCHECKSTACK> ;; Don't do checkstack?
  110. ?checkstack = 0 ;; Yes -- clear checkstack
  111. endif
  112. ifidni <p>, <LOADDS> ;; Is it LoadDS
  113. ?loadds = 1 ;; Yes -- do loadds sequence
  114. endif
  115. ifidni <p>, <NOLOADDS> ;; Don't do LoadDS?
  116. ?loadds = 0 ;; Yes -- clear loadds flag
  117. endif
  118. ifidni <p>, <INCBP> ;; Is it IncBP
  119. if flags AND 020h ;; and far?
  120. ?incbp = 1 ;; Yes -- do IncBP sequence
  121. endif
  122. endif
  123. ifidni <p>, <NOINCBP> ;; Is it NoIncBP
  124. ?incbp = 0 ;; Yes -- Clear the incbp flag
  125. endif
  126. ifidni <p>, <FORCEFRAME> ;; Is it ForceFrame?
  127. ?doPrologue = 1 ;; Yes -- force out a frame
  128. endif
  129. ifidni <p>, <PROFILE>
  130. ?doProfile = 1
  131. endif
  132. ifidni <p>, <NOPROFILE>
  133. ?doProfile = 0
  134. endif
  135. endm ;; End of user parameter parsing loop
  136. endif
  137. ;; Turn off options that don't make sense in USE32 segment
  138. if @WordSize eq 4
  139. ?checkstack = 0
  140. ?loadds = 0
  141. ?incbp = 0
  142. endif
  143. ;; Frames are generated iff
  144. ;; 1. cbLocals + cbParams != 0
  145. ;; 2. FORCEFRAME is set
  146. ;; 3. INCBP is set and proc is far
  147. ;; 4. LOADDS is set
  148. ;;
  149. ;; Force a prolog?
  150. ?doPrologue = ?doPrologue OR ?incbp OR ?loadds OR ?checkstack OR (?cbLocals NE 0) OR (cbParams NE 0)
  151. if ?doProfile EQ 1 ;; generate profiling call
  152. call _penter
  153. endif
  154. if ?doPrologue EQ 0 ;; No prolog needed -- so get out of here
  155. ; popcontext listing
  156. exitm<0>
  157. endif
  158. if ?loadds EQ 1 ;; Create the loadds code -- force in
  159. push ds ;; Put DS into AX -- we will place
  160. pop ax ;; back in DS later. This sequence
  161. nop ;; is altered by the OS if needed
  162. endif
  163. if ?incbp EQ 1 ;; Mark as a far procedure for stack
  164. inc bp ;; walking
  165. endif
  166. if @WordSize eq 4
  167. push ebp
  168. mov ebp, esp
  169. else
  170. push bp ;; Create the frame
  171. mov bp,sp
  172. endif
  173. if ?loadds EQ 1 ;; Load up DS with the value in AX
  174. push ds ;;
  175. mov ds,ax ;;
  176. ?cbLocals = ?cbLocals + 2
  177. endif
  178. if ?checkstack EQ 1 ;; Now allocate space for locals
  179. mov ax,cbLocals ;; # of bytes of locals (unadjusted)
  180. % ifidni <@CurSeg>, <_TEXT>
  181. call _aNchkstk ;; Call run time routine to allocate
  182. else
  183. call _aFchkstk
  184. endif
  185. else ; ?checkstack NE 1
  186. if cbLocals NE 0
  187. if @WordSize eq 4
  188. sub esp, cbLocals
  189. else
  190. sub sp,cbLocals ;; make space on the stack for locals
  191. endif
  192. endif
  193. endif
  194. ifnb rgRegs ;; There are registers to be saved. do so
  195. for r,rgRegs
  196. push r
  197. endm
  198. endif
  199. ; popcontext listing
  200. exitm <?cbLocals>
  201. endm
  202. ;
  203. ; This macro will produce the same output as will the
  204. ; C6 compiler for the given switches.
  205. ;
  206. ; The following may be placed in the MacroArgs field of the
  207. ; proc defintion:
  208. ;
  209. ; CHECKSTACK
  210. ; NOCHECKSTACK
  211. ; LOADDS
  212. ; NOLOADDS
  213. ; FORCEFRAME
  214. ; INCBP
  215. ; NOINCBP
  216. option epilogue:cEpilogue
  217. cEpilogue macro szProcName, flags, cbParams, cbLocals, rgRegs, rgUserParams
  218. LOCAL ?doPrologue
  219. LOCAL ?loadds
  220. LOCAL ?checkstack
  221. LOCAL ?incbp
  222. ; pushcontext listing
  223. ; .nolistmacro
  224. ; .listmacroall
  225. ?doPrologue = 0
  226. ?loadds = 0
  227. ?checkstack = 0
  228. ?incbp = 0
  229. ;; Turn off options that don't make sense in USE32 segment
  230. if @WordSize eq 4
  231. ?checkstack = 0
  232. ?loadds = 0
  233. ?incbp = 0
  234. endif
  235. ;; Set the defaults based on the global values specified
  236. ;;
  237. if ?WP_DEBUG NE 0 ;; Force frames by default
  238. ?doPrologue = 1
  239. endif
  240. if ?WP_CHECKSTACK NE 0 ;; Force checkstack by default
  241. ?checkstack = 1
  242. endif
  243. if ?WP_INCBP NE 0 ;; Force incbp by default
  244. if flags AND 020h
  245. ?incbp = 1
  246. endif
  247. endif
  248. if ?WP_LOADDS NE 0 ;; Force loadds by default
  249. if flags AND 020h
  250. ?loadds = 1
  251. endif
  252. endif
  253. ;;
  254. ;; Get all of the user parameters parsed
  255. ;;
  256. ifnb <rgUserParams> ;; Parse user params if exsisting
  257. for p,<rgUserParams> ;; For every user param
  258. ifidni <p>, <CHECKSTACK> ;; Is it checkstack?
  259. ?checkstack = 1 ;; Yes -- do checkstack
  260. endif
  261. ifidni <p>, <NOCHECKSTACK> ;; Don't do checkstack?
  262. ?checkstack = 0 ;; Yes -- clear checkstack
  263. endif
  264. ifidni <p>, <LOADDS> ;; Is it LoadDS
  265. ?loadds = 1 ;; Yes -- do loadds sequence
  266. endif
  267. ifidni <p>, <NOLOADDS> ;; Don't do LoadDS?
  268. ?loadds = 0 ;; Yes -- clear loadds flag
  269. endif
  270. ifidni <p>, <INCBP> ;; Is it IncBP
  271. if flags AND 020h
  272. ?incbp = 1 ;; Yes -- do IncBP sequence
  273. endif
  274. endif
  275. ifidni <p>, <NOINCBP> ;; Is it NoIncBP
  276. ?incbp = 0 ;; Yes -- Clear the incbp flag
  277. endif
  278. ifidni <p>, <FORCEFRAME> ;; Is it ForceFrame?
  279. ?doPrologue = 1 ;; Yes -- force out a frame
  280. endif
  281. endm ;; End of user parameter parsing loop
  282. endif
  283. ;; Turn off options that don't make sense in USE32 segment
  284. if @WordSize eq 4
  285. ?checkstack = 0
  286. ?loadds = 0
  287. ?incbp = 0
  288. endif
  289. ;; Frames are generated iff
  290. ;; 1. cbLocals + cbParams != 0
  291. ;; 2. FORCEFRAME is set
  292. ;; 3. INCBP is set and proc is far
  293. ;; 4. LOADDS is set
  294. ;;
  295. ;; Force a prolog?
  296. ?doPrologue = ?doPrologue OR ?incbp OR ?loadds OR ?checkstack OR (cbLocals NE 0) OR (cbParams NE 0)
  297. if ?doPrologue EQ 0 ;; No epilog needed -- so get out of here
  298. ret
  299. exitm
  300. endif
  301. ifnb rgRegs ;; Pop off the registers -- they are in
  302. for r,rgRegs ;; inverse order from the prologue call
  303. pop r
  304. endm
  305. endif
  306. if ?loadds ;;
  307. dec bp
  308. dec bp
  309. mov sp,bp
  310. pop ds
  311. pop bp
  312. else
  313. if @WordSize eq 4
  314. mov esp, ebp
  315. pop ebp
  316. else
  317. mov sp,bp
  318. pop bp
  319. endif
  320. endif
  321. if ?incbp ;; Remove the increment of BP if necessary
  322. dec bp
  323. endif
  324. if flags AND 010h ;; Caller pops stack arguments
  325. ret
  326. else ;; Callee pops args
  327. if cbParams NE 0 ;; Put out the correct form of return
  328. ret cbParams
  329. else
  330. ret
  331. endif
  332. endif
  333. endm
  334. popcontext listing
  335. .listmacro