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.

811 lines
16 KiB

  1. page ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name: MACROS.MAC
  4. ;
  5. ; This file contains macros definitions for all display drivers to use.
  6. ;
  7. ; Created: 06-Jan-1987
  8. ; Author: Walt Moore [waltm]
  9. ;
  10. ; Copyright (c) 1987 Microsoft Corporation
  11. ;
  12. ; Exported Functions: none
  13. ;
  14. ; Public Functions: none
  15. ;
  16. ; Public Data: none
  17. ;
  18. ; General Description:
  19. ;
  20. ; Two text equates are given as short hand for WORD PTR
  21. ; and BYTE PTR.
  22. ;
  23. ; A Macro is defined for performing 16-bit output on machines
  24. ; which cannot correctly do so.
  25. ;
  26. ; The macro which is invoked by CMACROS for private stack
  27. ; checking is defined.
  28. ;
  29. ; Restrictions:
  30. ; The use of the ?CHKSTKPROC macro requires it to be defined
  31. ; before CMACROS is included. If CMACROS is included before
  32. ; the include file, a ?CHKSTKPROC macro should be defined
  33. ; with a null macro body. This macro will then redefine the
  34. ; earlier macro.
  35. ;
  36. ; The out16 macro is intended as documentation for anyone
  37. ; converting a driver to a machine which cannot do 16-bit
  38. ; outputs correctly. There is no guarantee that any code
  39. ; will have been tested (only one machine is known to have
  40. ; the problem).
  41. ;
  42. ;-----------------------------------------------------------------------;
  43. ; The following two equates are just used as shorthand
  44. ; for the "word ptr" and "byte ptr" overrides.
  45. wptr equ word ptr
  46. bptr equ byte ptr
  47. .286
  48. ;---------------------------------Macro---------------------------------;
  49. ; out16
  50. ;
  51. ; out16 is a macro used wherever any 16-bit output is performed.
  52. ; The macro is intended to serve as documentation for those machines
  53. ; which do not perform 16-bit outputs correctly (where correctly is
  54. ; defined as the way the IBM AT does it).
  55. ;
  56. ; usage
  57. ;
  58. ; out16 d,a
  59. ;
  60. ; where
  61. ;
  62. ; d - I/O address register. Included as documentation
  63. ; only. Must always be DX (lower case).
  64. ;
  65. ; a - Register to output. Included as documentation
  66. ; only. Must always be AX (lower case).
  67. ;
  68. ; Entry:
  69. ; AX = data to output
  70. ; DX = I/O port address
  71. ; Returns:
  72. ; none
  73. ; Error Returns:
  74. ; none
  75. ; Registers Destroyed:
  76. ; FLAGS
  77. ; Registers Preserved:
  78. ; AX,BX,CX,DX,SI,DI,BP,DS,ES
  79. ; Calls:
  80. ; none
  81. ; History:
  82. ; Fri 16-Jan-1987 16:49:03 -by- Walt Moore [waltm]
  83. ; Initial version
  84. ;-----------------------------------------------------------------------;
  85. ifndef IO8 ;;If normal 16 bit outputs
  86. out16 equ out
  87. else ;;If 8-bit outputs
  88. out16 macro d,a
  89. ifdif <a>,<ax>
  90. %out out16 - invalid register, must be ax
  91. .err
  92. endif
  93. ifdif <d>,<dx>
  94. %out out16 - invalid register, must be dx
  95. .err
  96. endif
  97. ifdif <is>,<cli> ;; If interrupts not off
  98. cli ;; then turn them off
  99. endif ;;
  100. out dx,al ;; Output LSB portion
  101. inc dx ;; --> next address
  102. xchg al,ah ;; Get MSB of output value
  103. out dx,al ;; Output MSB portion
  104. ifdif <ie>,<cli> ;; If not explicitly told to leave
  105. sti ;; interrupts off, turn them on
  106. endif ;;
  107. ifdif <rd>,<dont_save_DL> ;; If not explicitly told to trash DX,
  108. dec dx ;; restore it.
  109. xchg al,ah
  110. endif
  111. endm
  112. endif
  113. ;---------------------------------Macro---------------------------------;
  114. ; ?CHKSTKPROC
  115. ;
  116. ; Private Stack Checking Macro
  117. ;
  118. ; ?CHKSTKPROC will be invoked by the CMACROS for any procedure
  119. ; with local variables if both ?CHKSTK and ?CHKSTKPROC were
  120. ; defined prior to including the CMACROS.
  121. ;
  122. ; The macro has one parameter, which is the number of bytes
  123. ; to allocate, which is supplied by the CMACROS.
  124. ;
  125. ; The usage of this macro is defined by the CMACROS. There is no
  126. ; user control over the macro. Register usage will be as defined
  127. ; by the routine my_check_stack.
  128. ;
  129. ; Calls:
  130. ; my_check_stack
  131. ; History:
  132. ; Fri 16-Jan-1987 16:49:03 -by- Walt Moore [waltm]
  133. ; Initial version
  134. ;-----------------------------------------------------------------------;
  135. ifdef ?CHKSTK ;;Only define macro if
  136. ifdef ?CHKSTKPROC ;; private stack checking
  137. ifndef ?CHKSTKNAME ;;If user name differs from default
  138. extrn my_check_stack:near ;;Procedure to do the checking
  139. endif
  140. ?CHKSTKPROC macro s ;;Actual macro text
  141. mov ax,s ;;my_check_stack takes requested space
  142. ifdef ?CHKSTKNAME
  143. ?CHKSTKNAME
  144. else
  145. call my_check_stack ;; in AX
  146. endif
  147. endm
  148. endif
  149. endif
  150. ;-----------------------------------------------------------------------;
  151. ; odd --- macro for odd alignment, counterpart for masm's "even".
  152. ;
  153. ; Arguments:
  154. ; none
  155. ; Returns:
  156. ; nothing
  157. ; Alters:
  158. ; nothing
  159. ; Calls:
  160. ; nothing
  161. ; History:
  162. ;
  163. ; Sun Mar 01, 1987 07:48:01p -by- Wesley O. Rupel [wesleyr]
  164. ; Wrote it!
  165. ;-----------------------------------------------------------------------;
  166. odd macro
  167. ife (offset $) AND 1
  168. nop
  169. endif
  170. endm
  171. ;-----------------------------------------------------------------------;
  172. ; pushem
  173. ; popem
  174. ;
  175. ; Allows giving a list of registers to push/pop on a single line.
  176. ; Also allows easy verificaton that pushes and pops are balanced
  177. ; because arguements are given in the same order:
  178. ;
  179. ; pushem ax,bx,cx goes with
  180. ; popem ax,bx,cx
  181. ;
  182. ; Arguments:
  183. ; registers to push/pop
  184. ; Returns:
  185. ; nothing
  186. ; Alters:
  187. ; nothing
  188. ; Calls:
  189. ; nothing
  190. ; History:
  191. ;
  192. ; Mon Mar 09, 1987 06:12:32p -by- Wesley O. Rupel [wesleyr]
  193. ; Wrote it!
  194. ;-----------------------------------------------------------------------;
  195. pushem macro r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12
  196. irp x,<r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12>
  197. ifnb <x>
  198. push x
  199. endif
  200. endm
  201. endm
  202. popem macro r1,r2,r3,r4,r5,r6,r7,r8,r9,rA,rB,rC,rD,rE,rF,r10,r11,r12
  203. irp x,<r12,r11,r10,rF,rE,rD,rC,rB,rA,r9,r8,r7,r6,r5,r4,r3,r2,r1>
  204. ifnb <x>
  205. pop x
  206. endif
  207. endm
  208. endm
  209. ;-----------------------------------------------------------------------;
  210. ; smov
  211. ;
  212. ; smove moves the contents of one segment register into another
  213. ; segment register.
  214. ;
  215. ; usage
  216. ;
  217. ; smov x,y
  218. ;
  219. ; where
  220. ;
  221. ; x is the destination register
  222. ; y is the source register
  223. ;
  224. ; Arguments:
  225. ; y is source segment register
  226. ; Returns:
  227. ; x segment register = y segment register
  228. ; Alters:
  229. ; x segment register
  230. ; Calls:
  231. ; nothing
  232. ; History:
  233. ;
  234. ; Mon Mar 09, 1987 06:12:32p -by- Wesley O. Rupel [wesleyr]
  235. ; Wrote it!
  236. ;-----------------------------------------------------------------------;
  237. smov macro x,y
  238. push y
  239. pop x
  240. endm
  241. ;--------------------------------------------------------------------------;
  242. ; abs_ax
  243. ; takes absolute value of AX
  244. ; Entry:
  245. ; AX = integer
  246. ; Returns:
  247. ; AX = abs(AX)
  248. ; Error Returns:
  249. ; none
  250. ; Registers Destroyed:
  251. ; DX,FLAGS
  252. ; Registers Preserved:
  253. ; BX,CX,SI,DI,DS,ES,BP
  254. ; Calls:
  255. ; none
  256. ; History:
  257. ; Thu Mar 05, 1987 06:15:46p -by- Tony Pisculli [tonyp]
  258. ; wrote it
  259. ;--------------------------------------------------------------------------;
  260. abs_ax macro
  261. cwd
  262. xor ax,dx
  263. sub ax,dx
  264. endm
  265. ;--------------------------------------------------------------------------;
  266. ; min_ax
  267. ; returns min of AX and REG
  268. ; Entry:
  269. ; AX = integer
  270. ; REG = general purpose register containing an integer
  271. ; Returns:
  272. ; AX = min(AX,REG)
  273. ; Error Returns:
  274. ; none
  275. ; Registers Destroyed:
  276. ; DX,FLAGS
  277. ; Registers Preserved:
  278. ; BX,CX,SI,DI,DS,ES,BP
  279. ; Calls:
  280. ; none
  281. ; History:
  282. ; Sat Mar 07, 1987 08:39:04p -by- Tony Pisculli [tonyp]
  283. ; wrote it
  284. ;--------------------------------------------------------------------------;
  285. min_ax macro REG
  286. sub ax,REG
  287. cwd
  288. and ax,dx
  289. add ax,REG
  290. endm
  291. ;--------------------------------------------------------------------------;
  292. ; max_ax
  293. ; returns max of AX and REG
  294. ; Entry:
  295. ; AX = integer
  296. ; REG = general purpose register containing an integer
  297. ; Returns:
  298. ; AX = max(AX, REG)
  299. ; Error Returns:
  300. ; none
  301. ; Registers Destroyed:
  302. ; DX,FLAGS
  303. ; Registers Preserved:
  304. ; BX,CX,SI,DI,DS,ES,BP
  305. ; Calls:
  306. ; none
  307. ; History:
  308. ; Sat Mar 07, 1987 08:41:38p -by- Tony Pisculli [tonyp]
  309. ; wrote it
  310. ;--------------------------------------------------------------------------;
  311. max_ax macro REG
  312. sub ax,REG
  313. cwd
  314. not dx
  315. and ax,dx
  316. add ax,REG
  317. endm
  318. ; The following equates are used for defining the target
  319. ; processor to the shift macros.
  320. GENERIC equ 0
  321. CPU equ GENERIC
  322. ;CPU equ 88
  323. ;CPU equ 86
  324. ;CPU equ 186
  325. ;CPU equ 286
  326. ;CPU equ 386
  327. ;--------------------------------------------------------------------------;
  328. ; shiftl
  329. ;
  330. ; shiftl is used to implement the advanced shift left immediate
  331. ; (SHL dest,count) functionality of the 286 and 386.
  332. ;
  333. ; Entry:
  334. ; DEST = var to shift
  335. ; COUNT = number to shift by
  336. ; Returns:
  337. ; DEST = DEST shl COUNT
  338. ; Error Returns:
  339. ; none
  340. ; Registers Destroyed:
  341. ; none
  342. ; Registers Preserved:
  343. ; all
  344. ; Calls:
  345. ; none
  346. ; History:
  347. ; Sat Mar 07, 1987 08:44:30p -by- Tony Pisculli [tonyp]
  348. ; wrote it
  349. ;--------------------------------------------------------------------------;
  350. shiftl macro DEST,COUNT
  351. if (CPU eq 286) or (CPU eq 386)
  352. shl DEST,COUNT
  353. else
  354. REPT COUNT
  355. shl DEST,1
  356. ENDM
  357. endif
  358. endm
  359. ;--------------------------------------------------------------------------;
  360. ; shiftr
  361. ;
  362. ; shiftr is used to implement the advanced shift right immediate
  363. ; (SHR dest,count) functionality of the 286 and 386.
  364. ;
  365. ; Entry:
  366. ; DEST = var to shift
  367. ; COUNT = number to shift by
  368. ; Returns:
  369. ; DEST = DEST shr COUNT
  370. ; Error Returns:
  371. ; none
  372. ; Registers Destroyed:
  373. ; none
  374. ; Registers Preserved:
  375. ; all
  376. ; Calls:
  377. ; none
  378. ; History:
  379. ; Sat Mar 07, 1987 08:44:52p -by- Tony Pisculli [tonyp]
  380. ; wrote it
  381. ;--------------------------------------------------------------------------;
  382. shiftr macro DEST,COUNT
  383. if (CPU eq 286) or (CPU eq 386)
  384. shr DEST,COUNT
  385. else
  386. REPT COUNT
  387. shr DEST,1
  388. ENDM
  389. endif
  390. endm
  391. ;--------------------------------------------------------------------------;
  392. ; rotcr, rotcl
  393. ; rotr, rotl
  394. ;
  395. ; Use just like you would rcr (or rcl, rol, ror) immediate in 286 specific
  396. ; code. If the processor does not support the immediate count (>1 on 808[68])
  397. ; then the macro generates multiple rcr (...) by one statements.
  398. ;
  399. ; Entry:
  400. ; DEST = var to rotate
  401. ; COUNT = number to rotate by
  402. ; Returns:
  403. ; DEST = DEST shr COUNT
  404. ; Error Returns:
  405. ; none
  406. ; Registers Destroyed:
  407. ; none
  408. ; Registers Preserved:
  409. ; all
  410. ; Calls:
  411. ; none
  412. ; History:
  413. ;
  414. ; Fri Apr 17, 1987 08:39:39p -by- Wesley O. Rupel [wesleyr]
  415. ; added rotl and rotr
  416. ;
  417. ; Sun Apr 12, 1987 07:34:37p -by- Wesley O. Rupel [wesleyr]
  418. ; wrote it
  419. ;--------------------------------------------------------------------------;
  420. rotcr macro DEST,COUNT
  421. if (CPU eq 286) or (CPU eq 386)
  422. rcr DEST,COUNT
  423. else
  424. REPT COUNT
  425. rcr DEST,1
  426. ENDM
  427. endif
  428. endm
  429. rotcl macro DEST,COUNT
  430. if (CPU eq 286) or (CPU eq 386)
  431. rcl DEST,COUNT
  432. else
  433. REPT COUNT
  434. rcl DEST,1
  435. ENDM
  436. endif
  437. endm
  438. rotl macro DEST,COUNT
  439. if (CPU eq 286) or (CPU eq 386)
  440. rol DEST,COUNT
  441. else
  442. REPT COUNT
  443. rol DEST,1
  444. ENDM
  445. endif
  446. endm
  447. rotr macro DEST,COUNT
  448. if (CPU eq 286) or (CPU eq 386)
  449. ror DEST,COUNT
  450. else
  451. REPT COUNT
  452. ror DEST,1
  453. ENDM
  454. endif
  455. endm
  456. ;--------------------------------------------------------------------------;
  457. ; ashiftr
  458. ;
  459. ; ashiftr is used to implement the advanced shift arithmetic right immediate
  460. ; (SAR dest,count) functionality of the 286 and 386.
  461. ;
  462. ; Entry:
  463. ; DEST = var to shift
  464. ; COUNT = number to shift by
  465. ; Returns:
  466. ; DEST = DEST sar COUNT
  467. ; Error Returns:
  468. ; none
  469. ; Registers Destroyed:
  470. ; none
  471. ; Registers Preserved:
  472. ; all
  473. ; Calls:
  474. ; none
  475. ; History:
  476. ; Sat Mar 07, 1987 08:45:06p -by- Tony Pisculli [tonyp]
  477. ; wrote it
  478. ;--------------------------------------------------------------------------;
  479. ashiftr macro DEST,COUNT
  480. if (CPU eq 286) or (CPU eq 386)
  481. sar DEST,COUNT
  482. else
  483. REPT COUNT
  484. sar DEST,1
  485. ENDM
  486. endif
  487. endm
  488. ;---------------------------------Macro---------------------------------;
  489. ; jmpnext
  490. ; jmpnext stop
  491. ;
  492. ; jmpnext is used in the generation of fall through chains. It
  493. ; generates the opcode used to swallow the next two bytes of object
  494. ; code (cmp ax,immediate word), and performs error checking to
  495. ; ensure that only two bytes of object code exist between any
  496. ; use of jmpnext.
  497. ;
  498. ; The chain is terminated by use of an optional parameter to jmpnext.
  499. ; If this optional field is non-blank, the chain is terminated.
  500. ;
  501. ; usage
  502. ;
  503. ; dog:
  504. ; mov al,34
  505. ; jmpnext
  506. ;
  507. ; foo:
  508. ; mov al,0
  509. ; jmpnext
  510. ;
  511. ; bar:
  512. ; mov al,1
  513. ; jmpnext stop ;End of the chain
  514. ;
  515. ; Entry:
  516. ; none
  517. ; Returns:
  518. ; none
  519. ; Error Returns:
  520. ; none
  521. ; Registers Destroyed:
  522. ; FLAGS
  523. ; Registers Preserved:
  524. ; AX,BX,CX,DX,SI,DI,BP,DS,ES
  525. ; Calls:
  526. ; none
  527. ; History:
  528. ; Fri 13-Mar-1987 12:03:16 -by- Walt Moore [waltm]
  529. ; Initial version
  530. ;-----------------------------------------------------------------------;
  531. ??ji = 0 ;;Initial index value
  532. jmpnext macro e
  533. jn %??ji,%(??ji+1),e ;;Set next label
  534. endm
  535. jn macro i,j,e
  536. .sall
  537. ??ji&i:
  538. .xall
  539. ifb <e> ;;If not the end of the chain
  540. db 03Dh ;;cmp ax, next two bytes
  541. errn$ ??ji&j,+2 ;;next lable must be two bytes away
  542. endif
  543. ??ji=j ;;increment counter
  544. endm
  545. ;---------------------------------Macro---------------------------------;
  546. ; missing_code
  547. ;
  548. ; missing_code is a macro which will display a message on the screen
  549. ; at assembly time. It is used to flag code sequences which have not
  550. ; been completed.
  551. ;
  552. ; usage
  553. ;
  554. ; missing_code <text>
  555. ;
  556. ; Entry:
  557. ; none
  558. ; Returns:
  559. ; none
  560. ; Error Returns:
  561. ; none
  562. ; Registers Destroyed:
  563. ; none
  564. ; Registers Preserved:
  565. ; ALL
  566. ; Calls:
  567. ; none
  568. ; History:
  569. ; Sun 22-Mar-1987 18:21:34 -by- Walt Moore [waltm]
  570. ; Initial version
  571. ;-----------------------------------------------------------------------;
  572. missing_code macro x
  573. if1
  574. ??_out <&! Missing Code &! x>
  575. endif
  576. endm
  577. ;---------------------------Macro---------------------------------------;
  578. ; LMHtoP
  579. ;
  580. ; Converts a Local Memory Handle to a local pointer.
  581. ;
  582. ; Entry:
  583. ; reg1[,reg2]
  584. ; Returns:
  585. ; reg1 = pointer
  586. ; Error Returns:
  587. ;
  588. ; Registers Destroyed:
  589. ; none
  590. ; History:
  591. ; Mon Mar 23, 1987 06:54:26a -by- Charles Whitmer [chuckwh]
  592. ; Imported from GDI.
  593. ;-----------------------------------------------------------------------;
  594. LMHtoP macro r1,r2 ;; Local Movable Handle to pointer
  595. ifnb <r2>
  596. mov r1,[r2]
  597. else
  598. mov r1,[r1]
  599. endif
  600. endm
  601. ;-------------------------Macro-----------------------------------------;
  602. ; REPSTOSB Dst
  603. ;
  604. ; store <cx> copies of al at Dst, aliging destination on WORD writes
  605. ;
  606. ; Dst destination, must be of the form SEL:[di] (default is es:[di])
  607. ;
  608. ; Entry:
  609. ; Dst -> points to dest buffer
  610. ; al byte to write
  611. ; cx count bytes
  612. ;
  613. ; NOTE a dest segment other than ES is handled by generating a loop
  614. ; all other cases generate a rep mov
  615. ;
  616. ; NOTE this code assumes the direction flag is set to FORWARD
  617. ;
  618. ; NOTE cx must be non-zero
  619. ;
  620. ; Returns:
  621. ;
  622. ; History:
  623. ; Sun 31-Jul-1989 -by- ToddLa
  624. ; Wrote it.
  625. ;
  626. ;-----------------------------------------------------------------------;
  627. ?REPSTOSB macro Dst
  628. local l1
  629. local l2
  630. local l3
  631. local localdest
  632. IFIDNI <Dst>, <NOAHLOAD>
  633. localdest EQU es:[di]
  634. ELSE
  635. localdest EQU Dst
  636. mov ah,al ; make sure ah == al
  637. ENDIF
  638. test di,1
  639. jz l1
  640. stos byte ptr localdest
  641. dec cx
  642. l1:
  643. shr cx,1
  644. rep stos word ptr localdest
  645. adc cl,cl
  646. rep stos byte ptr localdest
  647. endm
  648. REPSTOSB macro Dst
  649. ifb <Dst>
  650. ?REPSTOSB es:[di]
  651. else
  652. ?REPSTOSB Dst
  653. endif
  654. endm
  655. ;-------------------------Macro-----------------------------------------;
  656. ; REPMOVSB Dst, Src, alignR
  657. ;
  658. ; copy <cx> bytes from Src to Dst, aliging destination or source
  659. ; on WORD writes
  660. ;
  661. ; Dst destination, must be of the form SEL:[di] (default is es:[di])
  662. ; Src source, must be of the form SEL:[si] (default is ds:[si])
  663. ; alignR register to align si or di (default is di)
  664. ;
  665. ; Entry:
  666. ; Src -> points to source buffer
  667. ; Dst -> points to dest buffer
  668. ; cx count bytes
  669. ;
  670. ; NOTE this code assumes the direction flag is set to FORWARD
  671. ;
  672. ; NOTE cx must be non-zero
  673. ;
  674. ; Returns:
  675. ;
  676. ; History:
  677. ; Sun 31-Jul-1989 -by- ToddLa
  678. ; Wrote it.
  679. ;-----------------------------------------------------------------------;
  680. ?REPMOVSB macro Dst, Src, alignR
  681. local l1
  682. local l2
  683. local l3
  684. test alignR,1
  685. jz l1
  686. movs byte ptr Dst, byte ptr Src
  687. dec cx
  688. l1: shr cx,1
  689. rep movs word ptr Dst, word ptr Src
  690. adc cl,cl
  691. rep movs byte ptr Dst, byte ptr Src
  692. endm
  693. REPMOVSB macro Dst, Src, alignR
  694. ifb <Dst>
  695. ?REPMOVSB es:[di],ds:[si],di
  696. exitm
  697. endif
  698. ifb <Src>
  699. ?REPMOVSB Dst,ds:[si],di
  700. exitm
  701. endif
  702. ifb <alignR>
  703. ?REPMOVSB Dst,Src,di
  704. exitm
  705. endif
  706. ?REPMOVSB Dst,Src,alignR
  707. endm