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.

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