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.

343 lines
5.9 KiB

  1. ;++
  2. ;
  3. ;Copyright (c) 1991 Microsoft Corporation
  4. ;
  5. ;Module Name:
  6. ;
  7. ; asmmacro.inc
  8. ;
  9. ;Abstract:
  10. ;
  11. ; Contains macros to extend masm functionality:
  12. ;
  13. ; jmpc
  14. ; jmpnc
  15. ; jmpne
  16. ; jmps
  17. ; _mkjmp
  18. ;
  19. ;
  20. ;Author:
  21. ;
  22. ; Richard L Firth (rfirth) 24-Sep-1991
  23. ;
  24. ;Environment:
  25. ;
  26. ; DOS application mode only
  27. ;
  28. ;Revision History:
  29. ;
  30. ; 24-Sep-1991 rfirth
  31. ; Created
  32. ;
  33. ;--
  34. DEFINED_BIT=020h
  35. ;ISDEFINED equ %(.type <thing> and DEFINED_BIT)
  36. LABEL_DEFINED equ <(.type &label and DEFINED_BIT)>
  37. DEBUG_MACROS = 0
  38. ;DEBUG_MACROS = 1
  39. ;*** jmpa
  40. ;*
  41. ;* jump to label if above. Label can be short (+129, -126 from
  42. ;* the first byte of the current jump instruction, if it is a short - ie
  43. ;* byte - jump) or near
  44. ;*
  45. ;* ENTRY label - to jump to
  46. ;*
  47. ;* EXIT nothing
  48. ;*
  49. ;* USES nothing
  50. ;*
  51. ;* ASSUMES 286+
  52. ;*
  53. ;***
  54. jmpa macro label
  55. _mkjmp ja,jna,&label
  56. endm
  57. ;*** jmpc
  58. ;*
  59. ;* jump to label if below. Label can be short (+129, -126 from
  60. ;* the first byte of the current jump instruction, if it is a short - ie
  61. ;* byte - jump) or near
  62. ;*
  63. ;* ENTRY label - to jump to
  64. ;*
  65. ;* EXIT nothing
  66. ;*
  67. ;* USES nothing
  68. ;*
  69. ;* ASSUMES 286+
  70. ;*
  71. ;***
  72. jmpb macro label
  73. _mkjmp jb,jnb,&label
  74. endm
  75. ;*** jmpc
  76. ;*
  77. ;* jump to label if carry flag set. Label can be short (+129, -126 from
  78. ;* the first byte of the current jump instruction, if it is a short - ie
  79. ;* byte - jump) or near
  80. ;*
  81. ;* ENTRY label - to jump to
  82. ;*
  83. ;* EXIT nothing
  84. ;*
  85. ;* USES nothing
  86. ;*
  87. ;* ASSUMES 286+
  88. ;*
  89. ;***
  90. jmpc macro label
  91. _mkjmp jc,jnc,&label
  92. endm
  93. ;*** jmpnc
  94. ;*
  95. ;* jump to label if carry flag NOT set. Label can be short (+129, -126 from
  96. ;* the first byte of the current jump instruction, if it is a short - ie
  97. ;* byte - jump) or near
  98. ;*
  99. ;* ENTRY label - to jump to
  100. ;*
  101. ;* EXIT nothing
  102. ;*
  103. ;* USES nothing
  104. ;*
  105. ;* ASSUMES 286+
  106. ;*
  107. ;***
  108. jmpnc macro label
  109. _mkjmp jnc,jc,&label
  110. endm
  111. ;*** jmpne
  112. ;*
  113. ;* jump to label if zero flag NOT set. Label can be short (+129, -126 from
  114. ;* the first byte of the current jump instruction, if it is a short - ie
  115. ;* byte - jump) or near
  116. ;*
  117. ;* ENTRY label - to jump to
  118. ;*
  119. ;* EXIT nothing
  120. ;*
  121. ;* USES nothing
  122. ;*
  123. ;* ASSUMES 286+
  124. ;*
  125. ;***
  126. jmpne macro label
  127. _mkjmp jne,je,&label
  128. endm
  129. ;*** jmpe
  130. ;*
  131. ;* jump to label if zero flag set. Label can be short (+129, -126 from
  132. ;* the first byte of the current jump instruction, if it is a short - ie
  133. ;* byte - jump) or near
  134. ;*
  135. ;* ENTRY label - to jump to
  136. ;*
  137. ;* EXIT nothing
  138. ;*
  139. ;* USES nothing
  140. ;*
  141. ;* ASSUMES 286+
  142. ;*
  143. ;***
  144. jmpe macro label
  145. _mkjmp je,jne,&label
  146. endm
  147. ;*** jmps
  148. ;*
  149. ;* jump to label. Label can be short (+129, -126 from
  150. ;* the first byte of the current jump instruction, if it is a short - ie
  151. ;* byte - jump) or near
  152. ;*
  153. ;* ENTRY label - to jump to
  154. ;*
  155. ;* EXIT nothing
  156. ;*
  157. ;* USES nothing
  158. ;*
  159. ;* ASSUMES 286+
  160. ;*
  161. ;***
  162. jmps macro label
  163. local l,dist
  164. dist=&label-$
  165. if1
  166. if (.type label and DEFINED_BIT)
  167. if ((dist gt 129) or (dist lt -126))
  168. if DEBUG_MACROS
  169. %out pass1: &label defined and near
  170. endif
  171. jmp &label
  172. else
  173. if DEBUG_MACROS
  174. %out pass1: &label defined and short
  175. endif
  176. jmp short &label
  177. endif
  178. else
  179. if DEBUG_MACROS
  180. %out pass1: &label not defined
  181. endif
  182. org $+3
  183. endif
  184. else
  185. if ((dist gt 129) or (dist lt -126))
  186. if DEBUG_MACROS
  187. %out pass2: &label defined and near
  188. endif
  189. jmp &label
  190. else
  191. if DEBUG_MACROS
  192. %out pass2: &label defined and short
  193. endif
  194. jmp short &label
  195. org $+1
  196. endif
  197. endif
  198. l:
  199. endm
  200. ;*** _mkjmp
  201. ;*
  202. ;* Make a jmp<?> macro. Generate instruction sequence for jump with or
  203. ;* without conditional test. Jump may be short (+127/-128 bytes) or near
  204. ;* (+32767/-32768 bytes)
  205. ;*
  206. ;* ENTRY is - short jump instruction
  207. ;* in - near jump instruction
  208. ;* label - to jump to
  209. ;*
  210. ;* EXIT nothing
  211. ;*
  212. ;* USES nothing
  213. ;*
  214. ;* ASSUMES 286+
  215. ;*
  216. ;***
  217. _put macro s,v
  218. if2
  219. if DEBUG_MACROS
  220. %out s = v
  221. endif
  222. endif
  223. endm
  224. _mkjmp macro is, in, label
  225. local l
  226. ;;
  227. ;; if pass 1 and label is already known, generate correct instruction
  228. ;;
  229. if1
  230. if (.type &label and DEFINED_BIT)
  231. ;;
  232. ;; if label is too far away for short jump instruction, make jump <condition>
  233. ;; into jump <NOT condition> round jump to label followed by a near jump to
  234. ;; label
  235. ;;
  236. if (((&label - $) gt 129) or ((&label - $) lt -126))
  237. &in l ;; short jump, NOT condition
  238. jmp &label ;; jump to where we want to go
  239. else
  240. &is &label ;; short jump
  241. endif
  242. ;;
  243. ;; if pass 1 and we don't know about the label yet, adjust the program
  244. ;; counter by the max. number of bytes taken up by this macro (5 - 2 for
  245. ;; short jump, 3 for near jump)
  246. ;;
  247. else
  248. nop
  249. nop
  250. nop
  251. nop
  252. nop
  253. endif
  254. ;;
  255. ;; pass 2 - do same stuff as for pass 1
  256. ;;
  257. else
  258. if (((&label - $) gt 129) or ((&label - $) lt -126))
  259. if ((&label-$) gt 129)
  260. _put <label distance>, %(&label-$)
  261. else
  262. _put <label distance>, %($-&label)
  263. endif
  264. &in l
  265. jmp &label
  266. else
  267. ;;
  268. ;; label is within +127/-128 bytes of current instruction - generate short
  269. ;; jump instruction and put the program counter forward past the space
  270. ;; reserved during pass 1
  271. ;;
  272. _put <label distance>, %(&label-$)
  273. &is &label
  274. nop
  275. nop
  276. nop
  277. endif
  278. endif
  279. l:
  280. endm
  281. oldjmps macro label
  282. if2
  283. if (((&label - $) gt 127) or (($ - &label) lt -128))
  284. jmp short l
  285. jmp &label
  286. else
  287. jmp short &label
  288. org $+3
  289. endif
  290. else
  291. ;;
  292. ;; if this is pass 1 just take up max amount of space so phases don't get
  293. ;; screwed
  294. ;;
  295. org $+5
  296. endif
  297. l:
  298. endm