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.

762 lines
15 KiB

  1. ;--------------- Standard MATHMAC.INC
  2. ;
  3. ; Standard Math Macro Definition File
  4. ;
  5. ; Gregory F. Whitten
  6. ; 07/28/83
  7. ;
  8. ; Copyright (c) 1983-2001, Microsoft Corporation. All rights reserved.
  9. ;
  10. ;
  11. ; Revision History
  12. ;
  13. ; 10/18/83 Greg Whitten
  14. ; changed LCL FLT option to have 2 values for IEEE
  15. ;
  16. ; 05/02/84 Greg Whitten
  17. ; added CSconst switch support
  18. ;
  19. ; 07/23/84 Greg Whitten
  20. ; changed public/extrn to lower case
  21. ;
  22. ; 09/03/84 Greg Whitten
  23. ; added movcnp macro for constant pointers (with CSconst)
  24. ; fixed CSconst bug in f_movcs (only used 1 place)
  25. ;
  26. ; 10/29/84 Greg Whitten
  27. ; added debugger switch for fout changes
  28. ;
  29. ; 06/17/87 Jamie Bariteau
  30. ; changed outif macro for MASM 5.0 compatibility
  31. ;
  32. ; 02/22/88 Bill johnston
  33. ; outif now checks to see if QUIET was defined.
  34. ;
  35. ;---------------
  36. if1 ; Pass 1 only
  37. ; Helper macros for undefined symbols
  38. ;*** OUTIF name,msg
  39. ;
  40. ; Function:
  41. ; Output msg if name is non-zero. If name is undefined, set name = 0.
  42. ;
  43. outif MACRO name,msg
  44. ifndef Name
  45. Name= 0
  46. else
  47. if Name
  48. if1
  49. ifndef QUIET
  50. %out ! msg
  51. endif
  52. endif
  53. endif
  54. Name=Name
  55. endif
  56. ENDM
  57. ;*** ERROR msg
  58. ;
  59. ; Function:
  60. ; Output msg and generate an assembly time error
  61. ;
  62. error MACRO msg
  63. bug
  64. %OUT E r r o r ----- msg
  65. ENDM
  66. endif ; Pass 1
  67. ; Define standard math package switches
  68. ifdef DEBUG
  69. %out <+++++++++++++++++++++++>
  70. %out <+++ DEBUG version +++>
  71. %out <+++++++++++++++++++++++>
  72. endif ;DEBUG
  73. outif XENIX3, <+++ XENIX 3.0 and later version +++>
  74. outif BASIC, <BASIC Interpreter>
  75. outif BASCOM, <BASIC Compiler>
  76. outif CC, <C Compiler>
  77. outif FORTRAN, <FORTRAN Compiler>
  78. outif PASCAL, <PASCAL Compiler>
  79. outif Frontends, < compiler front-end version>
  80. outif LOGO, <LOGO Interpreter>
  81. outif IBMASM, <IBM Assembler Library>
  82. outif ASSEMBLER, <Macro Assembler>
  83. outif debugger, <Symbolic Assembly Debugger>
  84. outif DecFmt, <- Decimal Microsoft Format>
  85. outif MBinFmt, <- Binary Microsoft Format>
  86. outif IEEEFmt, <- IEEE Format>
  87. if IEEEFmt and (Frontends or debugger)
  88. Denormal= 1 ; front-ends need denormals
  89. endif
  90. outif Denormal, <- denormal number support>
  91. outif Use8087, <- 8087 instructions>
  92. outif Single, <- Single precision>
  93. outif Double, <- Double precision>
  94. outif CSconst, <- Constants in CS>
  95. if DecFmt+IEEEFmt+MBinFmt ne 1
  96. error <Improper math format specified>
  97. endif
  98. if Single+Double ne 1
  99. error <Improper math size specified>
  100. endif
  101. poly1 = 8000h ; flag for leading 1 in poly
  102. if Single ; Defined on both passes
  103. DefTyp= 4
  104. DefWrd= 2
  105. else ;Double
  106. DefTyp= 8
  107. DefWrd= 4
  108. endif
  109. ; offsets to sign and exponent fields
  110. if IEEEFmt
  111. if single
  112. expmask= 07F80h
  113. expbias= 03F80h
  114. expshft= 7
  115. manbits= 24
  116. of_exp= 2
  117. of_sgn= 3
  118. else ;double
  119. expmask= 07FF0h
  120. expbias= 03FF0h
  121. expshft= 4
  122. manbits= 53
  123. of_exp= 6
  124. of_sgn= 7
  125. endif
  126. endif ;IEEEFmt
  127. if MBinFmt
  128. if single
  129. manbits= 24
  130. of_exp= 3
  131. of_sgn= 2
  132. else ;double
  133. manbits= 56
  134. of_exp= 7
  135. of_sgn= 6
  136. endif
  137. endif ;MBinFmt
  138. if DecFmt
  139. of_exp= 0
  140. of_sgn= 0
  141. endif ;DecFmt
  142. if1 ; Pass 1 only
  143. ; Helper macros for elementary functions
  144. ;*** LCL name,type,value
  145. ;
  146. ; Function:
  147. ; LCL declares data with the specified name, type, and value.
  148. ; If the type is FLT for IEEE numbers, then either DD or DQ is
  149. ; substituted depending on the size of the variable.
  150. ;
  151. lcl MACRO name,type,value,value2
  152. ifidn <type>,<FLT>
  153. if IEEEFmt
  154. if Single
  155. name DD value
  156. else ;;Double
  157. name DQ value2
  158. endif
  159. else
  160. error <FLT not implemented for this type>
  161. endif
  162. else
  163. name type value
  164. endif
  165. ENDM
  166. ;*** GENHELP typ,siz
  167. ;
  168. ; Function:
  169. ; GENHELP generates the following macros with the typ and siz
  170. ; information embedded in the macro.
  171. ;
  172. ; PUB name
  173. ; PUB4 name
  174. ; PUB8 name
  175. ; GBL name,type,value
  176. ; GBL4 name,type,value
  177. ; GBL8 name,type,value
  178. ; EXT name,type
  179. ; EXT4 name,type
  180. ; EXT8 name,type
  181. ; F_DW rout
  182. ; F4_DW rout
  183. ; F8_DW rout
  184. ; F_JMP rout
  185. ; F4_JMP rout
  186. ; F8_JMP rout
  187. ; F_CALL rout
  188. ; F4_CALL rout
  189. ; F8_CALL rout
  190. ;
  191. ; Global names are considered to be names with the type and size prefix.
  192. ; Local names have no prefix. I.e., $I8_ONE and ONE, respectively.
  193. ;
  194. ; Macros with a size in the name create local names with the size at the
  195. ; end. I.e., RESULT4
  196. ;
  197. genhelp MACRO typ,siz
  198. ;*** PUB name
  199. ;
  200. ; Function:
  201. ; PUB declares both the global and local names as labels.
  202. ;
  203. pub &MACRO name
  204. public $&typ&&siz&_&&name
  205. $&typ&&siz&_&&name:
  206. name:
  207. &ENDM
  208. pub4 &MACRO name
  209. public $&typ&4_&&name
  210. $&typ&4_&&name:
  211. name&&4:
  212. &ENDM
  213. pub8 &MACRO name
  214. public $&typ&8_&&name
  215. $&typ&8_&&name:
  216. name&&8:
  217. &ENDM
  218. ;*** PUBX name
  219. ;
  220. ; Function:
  221. ; PUBX declares both the global and local names as labels.
  222. ; Added for MASM 5.0 compatibility. Adds leading underscore
  223. ; to local names to avoid conflict with MASM 5.0 reserved words.
  224. ;
  225. pubx &MACRO name
  226. public $&typ&&siz&_&&name
  227. $&typ&&siz&_&&name:
  228. _&&name:
  229. &ENDM
  230. pub4x &MACRO name
  231. public $&typ&4_&&name
  232. $&typ&4_&&name:
  233. _name&&4:
  234. &ENDM
  235. pub8x &MACRO name
  236. public $&typ&8_&&name
  237. $&typ&8_&&name:
  238. _name&&8:
  239. &ENDM
  240. ;*** GLB name,type,value
  241. ;
  242. ; Function:
  243. ; GLB declares the global name for the data value and aliases the local
  244. ; name to it.
  245. ;
  246. glb &MACRO name,type,value
  247. public $&typ&&siz&_&&name
  248. lcl $&typ&&siz&_&&name,type,<value>
  249. name equ $&typ&&siz&_&&name
  250. &ENDM
  251. glb4 &MACRO name,type,value
  252. public $&typ&4_&&name
  253. lcl $&typ&4_&&name,type,<value>
  254. name&&4 equ $&typ&4_&&name
  255. &ENDM
  256. glb8 &MACRO name,type,value
  257. public $&typ&8_&&name
  258. lcl $&typ&8_&&name,type,<value>
  259. name&&8 equ $&typ&8_&&name
  260. &ENDM
  261. ;*** EXT name,type
  262. ;
  263. ; Function:
  264. ; EXT declares the global name to be external with the specified type.
  265. ; It also aliases the local name to the global name.
  266. ;
  267. ext &MACRO name,type
  268. extrn $&typ&&siz&_&&name:type
  269. name equ $&typ&&siz&_&&name
  270. &ENDM
  271. ext4 &MACRO name,type
  272. extrn $&typ&4_&&name:type
  273. name&&4 equ $&typ&8_&&name
  274. &ENDM
  275. ext8 &MACRO name,type
  276. extrn $&typ&8_&&name:type
  277. name&&8 equ $&typ&8_&&name
  278. &ENDM
  279. ;*** F_DW name
  280. ;
  281. ; Function:
  282. ; F_DW declares the code address of the global name
  283. ;
  284. f_dw &MACRO name
  285. dwcp $&typ&&siz&_&&name
  286. &ENDM
  287. f4_dw &MACRO name
  288. dwcp $&typ&4_&&name
  289. &ENDM
  290. f8_dw &MACRO name
  291. dwcp $&typ&8_&&name
  292. &ENDM
  293. ;*** F_CALL name
  294. ;
  295. ; Function:
  296. ; F_CALL declares the global name to be external and issues a call.
  297. ;
  298. f_call &MACRO name
  299. extrn $&typ&&siz&_&&name:near
  300. call $&typ&&siz&_&&name
  301. &ENDM
  302. f4_call &MACRO name
  303. extrn $&typ&4_&&name:near
  304. call $&typ&4_&&name
  305. &ENDM
  306. f8_call &MACRO name
  307. extrn $&typ&8_&&name:near
  308. call $&typ&8_&&name
  309. &ENDM
  310. ;*** F_JMP name
  311. ;
  312. ; Function:
  313. ; F_JMP declares the global name to be external and issues a jmp.
  314. ;
  315. f_jmp &MACRO name
  316. extrn $&typ&&siz&_&&name:near
  317. jmp $&typ&&siz&_&&name
  318. &ENDM
  319. f4_jmp &MACRO name
  320. extrn $&typ&4_&&name:near
  321. jmp $&typ&4_&&name
  322. &ENDM
  323. f8_jmp &MACRO name
  324. extrn $&typ&8_&&name:near
  325. jmp $&typ&8_&&name
  326. &ENDM
  327. ENDM ;; End of genhelp
  328. ; Invoke GENHELP with the appropriate type and size information.
  329. if DecFmt
  330. if Single
  331. genhelp d,4
  332. else ;;Double
  333. genhelp d,8
  334. endif
  335. endif
  336. if IEEEFmt
  337. if Single
  338. genhelp i,4
  339. else ;;Double
  340. genhelp i,8
  341. endif
  342. endif
  343. if MBinFmt
  344. if Single
  345. genhelp m,4
  346. else ;;Double
  347. genhelp m,8
  348. endif
  349. endif
  350. purge genhelp ; toss genhelp macro
  351. ; cs mover macros - generate code iff CSconst nonzero
  352. movcssi macro
  353. if CSconst
  354. f_call mvcssi
  355. endif
  356. endm
  357. movcsdi macro
  358. if CSconst
  359. f_call mvcsdi
  360. endif
  361. endm
  362. movcnp macro dest,name,off
  363. if CSconst
  364. movcp dest,name,off
  365. else
  366. movp dest,name,off
  367. endif
  368. endm
  369. ; f_movcs macro
  370. ; f_mov macro
  371. ; f4_mov macro
  372. ; f8_mov macro
  373. ;
  374. ; Special forms f_mov
  375. ;
  376. ; op1/DI op2/SI Routine Res SI Use
  377. ;
  378. ; ARG AC movarg_ac AC DI
  379. ; ARG <> movarg SI DI
  380. ; AC ARG movac_arg AC DI
  381. ; AC <> movac AC DI
  382. ; TEMP <> movtemp SI DI
  383. ; any any gen code used SI.DI
  384. ;
  385. ; Special forms f_movcs
  386. ;
  387. ; op1/DI op2/SI Routine Res SI Use
  388. ;
  389. ; AC any gencode AC DI
  390. ; any any gen code used SI.DI
  391. f_movcs macro op1,op2
  392. if CSconst
  393. movp di,op1
  394. movcp si,op2 ;; op2 is source
  395. &rept DefWrd
  396. movs word ptr es:[di],word ptr cs:[si]
  397. &endm
  398. ifidn <op1>,<AC>
  399. movp si,AC
  400. endif
  401. else
  402. f_mov op1,op2
  403. endif
  404. endm
  405. f_mov MACRO op1,op2
  406. ifidn <op1>,<ARG>
  407. ifidn <op2>,<AC>
  408. f_call movarg_ac
  409. else
  410. ifnb <op2>
  411. movp si,op2 ;; op2 is source
  412. endif
  413. f_call movarg
  414. endif
  415. else
  416. ifidn <op1>,<AC>
  417. ifidn <op2>,<ARG>
  418. f_call movac_arg
  419. else
  420. ifnb <op2>
  421. movp si,op2 ;; op2 is source
  422. endif
  423. f_call movac
  424. endif
  425. else
  426. ifidn <op1>,<TEMP>
  427. ifnb <op2>
  428. movp si,op2 ;; op2 is source
  429. endif
  430. f_call movtemp
  431. else
  432. ifnb <op1>
  433. movp di,op1 ;; op1 is dest
  434. endif
  435. ifnb <op2>
  436. movp si,op2 ;; op2 is source
  437. endif
  438. &rept DefWrd
  439. movsw
  440. &endm
  441. endif
  442. endif
  443. endif
  444. ENDM
  445. f4_mov MACRO op1,op2
  446. ifidn <op1>,<ARG>
  447. ifidn <op2>,<AC>
  448. f4_call movarg_ac
  449. else
  450. ifnb <op2>
  451. movp si,op2 ;; op2 is source
  452. endif
  453. f4_call movarg
  454. endif
  455. else
  456. ifidn <op1>,<AC>
  457. ifidn <op2>,<ARG>
  458. f4_call movac_arg
  459. else
  460. ifnb <op2>
  461. movp si,op2 ;; op2 is source
  462. endif
  463. f4_call movac
  464. endif
  465. else
  466. ifidn <op1>,<TEMP>
  467. ifnb <op2>
  468. movp si,op2 ;; op2 is source
  469. endif
  470. f4_call movtemp
  471. else
  472. ifnb <op1>
  473. movp di,op1 ;; op1 is dest
  474. endif
  475. ifnb <op2>
  476. movp si,op2 ;; op2 is source
  477. endif
  478. movsw
  479. movsw
  480. endif
  481. endif
  482. endif
  483. ENDM
  484. f8_mov MACRO op1,op2
  485. ifidn <op1>,<ARG>
  486. ifidn <op2>,<AC>
  487. f8_call movarg_ac
  488. else
  489. ifnb <op2>
  490. movp si,op2 ;; op2 is source
  491. endif
  492. f8_call movarg
  493. endif
  494. else
  495. ifidn <op1>,<AC>
  496. ifidn <op2>,<ARG>
  497. f8_call movac_arg
  498. else
  499. ifnb <op2>
  500. movp si,op2 ;; op2 is source
  501. endif
  502. f8_call movac
  503. endif
  504. else
  505. ifidn <op1>,<TEMP>
  506. ifnb <op2>
  507. movp si,op2 ;; op2 is source
  508. endif
  509. f8_call movtemp
  510. else
  511. ifnb <op1>
  512. movp di,op1 ;; op1 is dest
  513. endif
  514. ifnb <op2>
  515. movp si,op2 ;; op2 is source
  516. endif
  517. movsw
  518. movsw
  519. movsw
  520. movsw
  521. endif
  522. endif
  523. endif
  524. ENDM
  525. ; f_push macro
  526. ;
  527. ; Special forms
  528. ;
  529. ; op1 Routine Res SI Use
  530. ;
  531. ; AC pushac AC AX
  532. ; ARG pusharg ARG AX
  533. ; SI pushsi SI AX
  534. ; any gen code SI ---
  535. f_push MACRO op1
  536. ifidn <op1>,<AC>
  537. f_call pshac
  538. else
  539. ifidn <op1>,<ARG>
  540. f_call psharg
  541. else
  542. ifidn <op1>,<SI>
  543. f_call pshsi
  544. else
  545. if Double
  546. push [op1+6]
  547. push [op1+4]
  548. endif
  549. push [op1+2]
  550. push [op1]
  551. endif
  552. endif
  553. endif
  554. ENDM
  555. ; f_pop macro
  556. ;
  557. ; Special forms
  558. ;
  559. ; op1 Routine Res SI Use
  560. ;
  561. ; AC popac AC AX
  562. ; ARG poparg ARG AX
  563. ; SI popsi SI AX
  564. ; any gen code SI ---
  565. f_pop MACRO op1
  566. ifidn <op1>,<AC>
  567. f_call popac
  568. else
  569. ifidn <op1>,<ARG>
  570. f_call poparg
  571. else
  572. ifidn <op1>,<SI>
  573. f_call popsi
  574. else
  575. pop [op1]
  576. pop [op1+2]
  577. if Double
  578. pop [op1+4]
  579. pop [op1+6]
  580. endif
  581. endif
  582. endif
  583. endif
  584. ENDM
  585. ; f_opr macro
  586. ;
  587. ; Special forms
  588. ;
  589. ; op1/SI op2/DI routine operations
  590. ;
  591. ; AC ARG xxxf add,sub,mul,div,cmp
  592. ; <> ARG xxxfsi add,sub,mul,div,cmp
  593. ; ARG AC xxxr sub,div,cmp
  594. ; ARG <> xxxrdi sub,div,cmp
  595. ; any any gen moves and call
  596. genoper MACRO op
  597. f_&op &MACRO op1,op2
  598. ifidn <op2>,<ARG>
  599. ifidn <op1>,<AC>
  600. f_call op&f
  601. else
  602. ifb <op1>
  603. f_call op&fsi
  604. else
  605. movp si,op1
  606. movp di,ARG
  607. f_call op
  608. endif
  609. endif
  610. else
  611. ifidn <op1>,<ARG>
  612. ifidn <op2>,<AC>
  613. f_call op&r
  614. else
  615. ifb <op2>
  616. f_call op&rdi
  617. else
  618. movp si,ARG
  619. movp di,op2
  620. f_call op
  621. endif
  622. endif
  623. else
  624. ifnb <op1>
  625. movp si,op1
  626. endif
  627. ifnb <op2>
  628. movp di,op2
  629. endif
  630. f_call op
  631. endif
  632. endif
  633. &ENDM
  634. ENDM
  635. genoper add
  636. genoper sub
  637. genoper mul
  638. genoper div
  639. genoper cmp
  640. purge genoper
  641. endif ; Pass 1
  642. ;--------------- End of Standard MATHMAC.INC