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.

3050 lines
74 KiB

  1. comment $
  2. SCCSID = "@(#)cmacros.mas:1.12"
  3. cmacros - assembly macros for interfacing to hhls
  4. Copyright (C) 1984-2001, Microsoft Corporation. All rights reserved.
  5. $
  6. ;; Revision History
  7. ;;
  8. ;; 1.00 05/03/84 Initial Release
  9. ;;
  10. ;; 1.01 05/06/84 Greg Whitten
  11. ;; Added defgrp and changed cMerge to Microsoft C
  12. ;; Added copyright message and changed to 1.01
  13. ;; Changes should have no affect on working programs
  14. ;;
  15. ;; 1.02 07/10/84 Steve Wood
  16. ;; Added labelx macros
  17. ;;
  18. ;; 1.03 07/14/84 Greg Whitten
  19. ;; Added defines for ?pu, ?adj, ?lblpu
  20. ;; (removes undefined errors)
  21. ;; Changes should have no affect on working programs
  22. ;;
  23. ;; 1.04 07/18/84 Greg Whitten
  24. ;; Added local control from PL/M or C conventions
  25. ;; except for cCall macro
  26. ;;
  27. ;; 1.05 08/06/84 Steve Wood
  28. ;; Made ?PLM and ?WIN be the defaults
  29. ;;
  30. ;; 1.06 01/02/85 Steve Wood
  31. ;; Changed createSeg and defgrp to automatically
  32. ;; define the ln_assumes macro and the lnoffset
  33. ;; and lnbase equates for each logical segment
  34. ;; name.
  35. ;;
  36. ;; 1.07 02/19/85 Walt Moore
  37. ;; Added farptr macro for defining a far pointer
  38. ;; to be used in a cCall. Folded regptr into
  39. ;; farptr. Space compaction in macros. Changed
  40. ;; ?pp to be smaller. Moved ?ia out of ?al1 into
  41. ;; ?aloc. Merged cProc and ?pd into one macro.
  42. ;; Changed some %outs to use the error macro so
  43. ;; an error would be generated. Added makeframe
  44. ;; and parmR to cProc. Changed error to also put
  45. ;; the error message in the listing.
  46. ;; Deleted the smashes macro.
  47. ;;
  48. ;; 1.08 03/18/85 Steve Wood
  49. ;; Added NODATA support.
  50. ;;
  51. ;; 1.09 03/27/85 Steve Wood
  52. ;; Added ?definitions
  53. ;;
  54. ;; 2.00 04/01/85 Steve Wood
  55. ;; April fools
  56. ;;
  57. ;; 2.01 06/17/85 Steve Wood
  58. ;; Changed NODATA to always generate POP DS
  59. ;; for return address patching
  60. ;;
  61. ;; 2.02 02/11/86 Steve Wood
  62. ;; Added ATOMIC keyword to cProc macro
  63. ;; Changed far epilog to use LEA SP,BP-2
  64. ;; Changed error macro to ??error to avoid
  65. ;; conflict
  66. ;;
  67. ;; 2.03 03/06/86 Steve Wood
  68. ;; Fixed bug with ATOMIC and locals in far proc
  69. ;; Added DOS5 switch to disable INC/DEC BP
  70. ;; instructions in special far prologs/epilogs
  71. ;;
  72. ;; 2.04 08/07/86 Scott Randell
  73. ;; Fixed bug with ATOMIC and ?TF
  74. ;; (was doing unnecessary MOV SP,BP)
  75. ;; Added pcode profile ?PROFILE
  76. ;;
  77. ;; 2.05 08/12/86 Walt Moore
  78. ;; Changed _TEXT alignment to word.
  79. ;; Added/corrected some comments.
  80. ;; Removed redundant init of ?pc in cProc
  81. ;; Made ATOMIC require NODATA
  82. ;; Moved definition of non-underscored 'C' label
  83. ;; from the cProc to the cBegin macro
  84. ;; Minor clean-up of code
  85. ;;
  86. ;; 2.06 09/11/86 Walt Moore
  87. ;; Added private stack checking
  88. ;; Put local control for PL/M or C into cCall
  89. ;;
  90. ;;
  91. ;; 2.07 09/19/86 Steve Wood
  92. ;; Added ?SMALL, ?MEDIUM, etc. symbols
  93. ;; Added forceframe keyword to cProc macro.
  94. ;; Interpret ?TF for all epilogs.
  95. ;;
  96. ;; 3.xx.a 02/26/87 Walt Moore
  97. ;; Massive rework. Documentation coming.
  98. ;;
  99. ;; 3.xx.b 04/08/87 NeilK
  100. ;; Added parmH, which is like parmW except
  101. ;; that it reserves 4 bytes on frame.
  102. ;;
  103. ;; 3.xx.c 05/11/87 Walt Moore
  104. ;; Added <> to ?ap so that arg <DataOFFSET foo>
  105. ;; can be used.
  106. ;;
  107. ;; 3.01 07/03/87 Walt Moore
  108. ;; parm_bytes_&procname is now generated for
  109. ;; all cProcs, and is the number of bytes of
  110. ;; parameters to the cProc.
  111. ;;
  112. ;; NO_BP added as a keyword to cProc which
  113. ;; causes all equates to be generated without
  114. ;; reference to BP for the procedure. All type
  115. ;; info is still generated, but the user must
  116. ;; supply any segment and base register.
  117. ;; ?NO_BP, if defined, makes this the default.
  118. ;;
  119. ;; USE_BP can be specified on the cProc line
  120. ;; to force the generation of BP in equates.
  121. ;;
  122. ;; Moved definition of xxxxBASE. The equ was to
  123. ;; a forward reference.
  124. ;;
  125. ;; Don't generate a warning for a nogen if only
  126. ;; parameters are present.
  127. ;;
  128. ;; Keywords for cProc, cBegin, cEnd, and registers
  129. ;; are now allowed to be either all upper case or
  130. ;; all lower case.
  131. ;;
  132. ;; Only generate warnings on pass 2.
  133. ;;
  134. ;; 3.02 07/06/87 Walt Moore
  135. ;; Boy did I mess up <nogen> If the text is
  136. ;; recognized as nogen, then process it as such,
  137. ;; else ignore it and generate frame as needed.
  138. ;;
  139. ;; 3.03 07/14/87 Walt Moore
  140. ;; Added <partial> keyword to the cBegin macro
  141. ;; to only allocate locals and save registers.
  142. ;; Used in conjunction with dispatching in the
  143. ;; Winthorn engine and drivers.
  144. ;;
  145. ;; Added cleanframe macro which will take the
  146. ;; frame down, but not generate the RET statement.
  147. ;; Used in conjunction with dispatching in the
  148. ;; Winthorn engine and drivers.
  149. ;;
  150. ;; 3.04 07/16/87 Walt Moore
  151. ;; globalD was generating off and seg name
  152. ;; without word ptr override, giving them a
  153. ;; dword attribute
  154. ;;
  155. ;; 3.05 07/17/87 Walt Moore
  156. ;; .xcref cleanframe
  157. ;;
  158. ;; 3.06 07/24/87 Hans Spiller
  159. ;; 32 bit small model (?SMALL32):
  160. ;; new entry exit sequences using pseudoregs
  161. ;; mach independant register names (IAX, etc)
  162. ;; parmI/localI (int size variables)
  163. ;; mpush/mpop uses mach independant names
  164. ;; IPUSHF, IPOPF, IPUSHA,IPOPA,IIRET
  165. ;;
  166. ;; case sensitivity bugfix. the compiler
  167. ;; generates "CODE", not "Code"
  168. ;;
  169. ;; 32 bit issues as yet undone: allocation
  170. ;; macros for dealing with 32 bit mode far
  171. ;; pointers, globalI, staticI, parmR, saving
  172. ;; si,di vs. esi,edi,ebx
  173. ;;
  174. ;; 3.06a 09/29/87 Mark Roberts
  175. ;; 32 bit small model (?SMALL32):
  176. ;; fix a few bugs and add staticI
  177. ;;
  178. ;; 3.06b 07/20/87 Scott Randell
  179. ;; Fix up for ?COW compatibility, added ?NOATOMIC
  180. ;; to 3.xx version.
  181. ;;
  182. ;; 3.06c 04/29/88 Jim Schaad
  183. ;; Put in ?DFDATA to force data segments even if
  184. ;; ?NODATA is set.
  185. ;;
  186. ;; 3.06d 05/02/88 Andy Padawer
  187. ;; Bug fixes for 3.06b (cEnd), 3.06c (general).
  188. ;;
  189. ;; 3.06e 08/31/88 Andy Padawer
  190. ;; use "if memS32" not "ifdef ?SMALL32".
  191. ;;
  192. ;; 3.06f 05/12/89 Mark Roberts
  193. ;; fix staticI, globalDP and add globalI
  194. ;;
  195. ;; 3.06g 12/07/89 Mark Roberts
  196. ;; add externI
  197. ;;
  198. ;; 3.06h 01/25/90 Jan de Rie
  199. ;; add ?DFCODE to allow suppressing code segments
  200. ;;
  201. ;; Assembly macros for interfacing to C
  202. ;;
  203. ;; User settable conditional assembly flags used within the cmacros
  204. ;;
  205. ;; Memory model flags. Set only one of the following. memS is the
  206. ;; default. The symbols with ? are for defining from the command line
  207. ;; and the memx symbols are numeric symbols that can be set in your source
  208. ;; file prior to including this file.
  209. ;;
  210. ;; ?SMALL memS - small model
  211. ;; ?MEDIUM memM - medium model
  212. ;; ?LARGE memL - large model
  213. ;; ?COMPACT memC - compact model
  214. ;; ?HUGE memH - huge model
  215. ;; ?SMALL32 memS32 - 32 bit small model
  216. ;;
  217. ;; ?DF Define flag. If this flag is 0, then defines default segment
  218. ;; and group definitions based on the compiler flag. If this
  219. ;; flag is 1, then does not define any segments or groups.
  220. ;;
  221. ;; ?DFDATA Define Data Flag. If this flag is 0, then defines default
  222. ;; data segment and group definitions based on compiler flag.
  223. ;; If this flag is 1, then does not define any data segments
  224. ;; or groups.
  225. ;;
  226. ;; ?DFCODE Define Code Flag. If this flag is 0, then defines default
  227. ;; code segments based on the compiler flag. If this flag is 1,
  228. ;; then does not define the code segments. Inactive if
  229. ;; ?DF is 1.
  230. ;;
  231. ;; ?TF Tight flag. If this flag is 0, then use longer epilog
  232. ;; sequence that safely cleans up a stack frame. If this flag is
  233. ;; 1, then use more efficient epilog that assumes the stack is
  234. ;; valid (SP)
  235. ;;
  236. ;; ?WIN Windows flag. Enables generation of special prolog/epilog
  237. ;; for far procedures. Default value is 1 (Windows).
  238. ;;
  239. ;; ?COW Character Windows flag. To be used in conjunction with ?WIN,
  240. ;; If defined will not save DS for ?NODATA far prolog/epilog
  241. ;; (CW does not modify the DS on the stack).
  242. ;;
  243. ;; DOS5 If defined, then special far prolog/epilog seqeuences will not
  244. ;; include the INC/DEC BP instructions.
  245. ;;
  246. ;; ?PLM Calling convention flag. If this flag is 0, then the
  247. ;; calling convention used is that of C. If this flag
  248. ;; is 1, then the PL/M calling convention is used.
  249. ;; The default value is 1. The PL/M calling convention
  250. ;; is used by pascal, fortran, basic, and cobol.
  251. ;;
  252. ;; In the C calling convention, arguments are passed
  253. ;; in reverse order; arg0 is the last pushed, argn is the
  254. ;; first pushed. also, it is the callers responsibility
  255. ;; to remove the arguments from the stack upon a return
  256. ;; from a call.
  257. ;;
  258. ;; In the PL/M calling comvention, arguments are passed
  259. ;; as encountered; arg0 is the first pushed, argn is the
  260. ;; last pushed. also, it is the called procedure's
  261. ;; responsibility to remove parameters from the stack
  262. ;; before returning (using the RET n instruction)
  263. ;;
  264. ;; ?NODATA If defined, then no data segment or DGROUP is defined and
  265. ;; the special prolog/epilog sequences will not contain the
  266. ;; code needed to setup DS.
  267. ;;
  268. ;; ?CHKSTK If defined, then prolog sequences for cProcs with local
  269. ;; parameters will call the CHKSTK procedure to allocate
  270. ;; the stack space.
  271. ;;
  272. ;; ?CHKSTKPROC If defined, then this macro will be invoked to
  273. ;; perform the stack checking, otherwise the
  274. ;; standard stack checking procedure will be
  275. ;; performed. ?CHKSTKPROC must be declared
  276. ;; before the cmacros are included in the source
  277. ;; else the standard chkstk routine will be declared
  278. ;; as an external symbol.
  279. ;;
  280. ;; On entry to the user's stack checking procedure,
  281. ;; the frame has been setup except for allocating
  282. ;; local variable space and saving autosave registers.
  283. ;;
  284. ;; The user supplied macro is passed as an argument
  285. ;; the number of byte of stack space requested.
  286. ;;
  287. ;; ?PROFILE If defined then all far cBegin entries will have StartNMeas,
  288. ;; and all cEnd will have StopNMeas calls, StartNMeas and
  289. ;; StopNMeas will be defined as externfp
  290. ;;
  291. ;; ?NOPARMR If defined, then the "parmR" macro will not be defined.
  292. ;;
  293. ;; ?NOGLOBAL If defined, then the "globalx" macros will not be defined.
  294. ;;
  295. ;; ?NOSTATIC If defined, then the "staticx" macros will not be defined.
  296. ;;
  297. ;; ?NOEXTERN If defined, then the "externx" macros will not be defined.
  298. ;;
  299. ;; ?NOLABEL If defined, then the "labelx" macros will not be defined.
  300. ;;
  301. ;; ?NODEF If defined, then the "defx" macros will not be defined.
  302. ;;
  303. ;; ?NOPTR If defined, then "farptr & regptr" will not be defined.
  304. ;;
  305. ;; ?QUIET If defined, then only error messages will be issued to
  306. ;; the console. If undefined, then certain cmacro text will
  307. ;; be generated to the console.
  308. ;;
  309. ;; ?NOATOMIC If defined, then ATOMIC will be ignored (for giving real
  310. ;; frames to all procedures (and profiling).
  311. ;;
  312. ;; ?NO_BP If defined, then equates generated for parms and locals
  313. ;; will not explicitly reference BP.
  314. ;; IAX, ICX, IDX, IBX, ISP, IBP, ISI, IDI
  315. ;; these pseudo registers expand to either ax..., or eax...
  316. ;; depending upon 32bit mode being enabled. they should be
  317. ;; used whenever a pointer or integer is being used in order
  318. ;; to make source code machine independant
  319. .xcref ;;Get rid of a lot of symbols
  320. ; ??_out - output given message to the console unless ?QUIET has
  321. ; been specified.
  322. ;
  323. ; usage:
  324. ; ??_out <t>
  325. ;
  326. ; where:
  327. ; <t> is the message to output
  328. .xcref ??_out
  329. ??_out macro t
  330. ifndef ?QUIET
  331. %out t
  332. endif
  333. endm
  334. ; outif - output msg if name is non-zero. if name is undefined,
  335. ; set name = 0, else set name to the default value.
  336. ;
  337. ; usage:
  338. ; outif name,defval,onmsg,offmsg
  339. ; where:
  340. ; name name of symbol
  341. ; defval default value to give symbol if not defined
  342. ; if blank, then 0 will be used
  343. ; onmsg text to display if symbol is non-zero
  344. ; offmsg test to be displayed if symbol is zero
  345. outif macro name,defval,onmsg,offmsg
  346. ifndef name
  347. ifb <defval>
  348. name=0
  349. else
  350. name=defval
  351. endif
  352. endif
  353. if name
  354. name=1
  355. ifnb <onmsg>
  356. ??_out <! onmsg>
  357. endif
  358. else
  359. ifnb <offmsg>
  360. ??_out <! offmsg>
  361. endif
  362. endif
  363. endm
  364. ; ??error - output msg and generate an assembly time error
  365. ; on regardess of assembler pass
  366. ; usage:
  367. ; ??error <t>
  368. ; where:
  369. ; t is the text to be output
  370. .xcref ??error
  371. ??error macro msg
  372. %out e r r o r ----- msg ;;to console
  373. .err e r r o r ----- msg ;;forced error by assembler
  374. endm
  375. ; ??error2 - output msg and generate an assembly time error
  376. ; on pass 2 only
  377. ; usage:
  378. ; ??error2 <t>
  379. ; where:
  380. ; t is the text to be output
  381. .xcref ??error2
  382. ??error2 macro msg
  383. if2
  384. %out e r r o r ----- msg ;;to console
  385. .err e r r o r ----- msg ;;forced error by assembler
  386. endif
  387. endm
  388. .xcref ASMpass
  389. .xcref memS,memM,memL,memC,memH,memMOD,sizec,sized,memS32,sizeI,wordI
  390. ;if1 ;;Only on pass 1
  391. ASMpass=1
  392. ifdef ?SMALL ;;inform user what is going on
  393. memS=1
  394. endif
  395. ifdef ?MEDIUM
  396. memM=1
  397. endif
  398. ifdef ?COMPACT
  399. memC=1
  400. endif
  401. ifdef ?LARGE
  402. memL=1
  403. endif
  404. ifdef ?HUGE
  405. memH=1
  406. endif
  407. ifdef ?SMALL32
  408. memS32=1
  409. endif
  410. ifdef ?FLAT32
  411. memF32=1
  412. endif
  413. ??_out <cMacros Version 3.06h - 01/25/90>
  414. ??_out <Copyright (C) 1984-2001 Microsoft Corporation. All rights reserved.>
  415. outif memS,0,<Small Model>
  416. outif memM,0,<Medium model>
  417. outif memL,0,<Large Model>
  418. outif memC,0,<Compact Model>
  419. outif memH,0,<Huge Model>
  420. outif memS32,0,<32 Bit Small Model>
  421. outif memF32,0,<32 Bit Flat Model>
  422. memMOD= memS + memM + memL + memC + memH + memS32
  423. if memMOD ne 1
  424. if memMOD eq 0
  425. memS = 1 ; assume small model
  426. outif memS,0,<Small model>
  427. else
  428. ??error <must have only 1 memory model selected>
  429. endif
  430. endif
  431. sizec= memM + memL + memH ; large code
  432. sized= memL + memC + (memH*2) ; large data (2 if huge)
  433. ;; note that memS32 is used generaly to indicate 32 bitness. I
  434. ;; doubt very much whether anyone will ever do other models in
  435. ;; 32 bit code...
  436. if memS32
  437. sizeI = 4 ; size of a push
  438. wordI equ <dword>
  439. asmdI equ <dd>
  440. else
  441. sizeI = 2
  442. wordI equ <word>
  443. asmdI equ <dw>
  444. endif
  445. outif ?DF,0,<No segments or groups will be defined>
  446. outif ?DFDATA,0,<No data segments will be defined>
  447. outif ?DFCODE,0,<No code segments will be defined>
  448. outif ?TF,0,<Epilog sequences assume valid SP>
  449. outif ?WIN,1,<Windows support>
  450. outif ?COW,0,<Characters Windows support>
  451. outif ?PLM,1,<PL/M calling convention>
  452. outif ?NOATOMIC,0,<ATOMIC disabled>
  453. outif ?NODATA,0,<NODATA module>
  454. ife ?NODATA
  455. ?nodata1=0
  456. else
  457. ?nodata1=1
  458. endif
  459. ifndef ?CHKSTK
  460. ?chkstk1=0
  461. else
  462. ?chkstk1=1
  463. ifdef ?CHKSTKPROC
  464. ??_out <! Private stack checking enabled>
  465. else
  466. ??_out <! Stack checking enabled>
  467. endif
  468. endif
  469. ifndef DOS5
  470. ?DOS5=0
  471. else
  472. ?DOS5=1
  473. ??_out <! DOS5 module>
  474. endif
  475. ifdef ?PROFILE
  476. ??_out <! Native profiling enabled>
  477. endif
  478. ifndef ?NO_BP
  479. ?no_bp1=0
  480. else
  481. ?no_bp1=1
  482. ??_out <! NO_BP is default>
  483. endif
  484. ;else
  485. ASMpass=2
  486. ;endif
  487. ;; define pseudo registers and instructions for 386/8086 independance
  488. if memS32
  489. .386
  490. IAX equ <eax>
  491. ICX equ <ecx>
  492. IDX equ <edx>
  493. IBX equ <ebx>
  494. ISP equ <esp>
  495. IBP equ <ebp>
  496. ISI equ <esi>
  497. IDI equ <edi>
  498. IPUSHF equ pushfd
  499. IPOPF equ popfd
  500. IPUSHA equ pushad
  501. IPOPA equ popad
  502. IIRET equ iretd
  503. else
  504. IAX equ <ax>
  505. ICX equ <cx>
  506. IDX equ <dx>
  507. IBX equ <bx>
  508. ISP equ <sp>
  509. IBP equ <bp>
  510. ISI equ <si>
  511. IDI equ <di>
  512. IPUSHF equ pushf
  513. IPOPF equ popf
  514. ; IPUSHA equ pusha
  515. ; IPOPA equ popa
  516. IIRET equ iret
  517. endif
  518. ;; Initialize all symbols used in the macros. Theses symbols will not be
  519. ;; included in any cross reference listing.
  520. .xcref ?n,?ax,?ah,?al,?bx,?bh
  521. .xcref ?bl,?cx,?ch,?cl,?dx,?dh
  522. .xcref ?dl,?si,?di,?es,?ds,?bp
  523. .xcref ?sp,?ss,?cs
  524. .xcref ?n,?AX,?AH,?AL,?BX,?BH
  525. .xcref ?BL,?CX,?CH,?CL,?DX,?DH
  526. .xcref ?DL,?SI,?DI,?ES,?DS,?BP
  527. .xcref ?SP,?SS,?CS
  528. .xcref ?EAX,?EBX,?ECX,?EDX,?ESI,?EDI,?ESP,?EBP
  529. .xcref ?eax,?ebx,?ecx,?edx,?esi,?edi,?esp,?ebp
  530. .xcref ?IAX,?IBX,?ICX,?IDX,?ISI,?IDI,?ISP,?IBP
  531. .xcref ?rsl,?cpd,?argl,?argc,?ba
  532. .xcref ?acb,???,?po
  533. .xcref ?pas,?pc
  534. .xcref uconcat,mpush,mpop
  535. .xcref ?ri,?pp,?pp1,?al1
  536. .xcref ?ad,?ap,?atal,?dd,?dd1,?dd2
  537. .xcref ?pg,?pg1,?aloc,?cs1,?cs2
  538. .xcref ?DF,?TF,?ff,?PLM,?WIN,?ia,?pu,?adj
  539. .xcref ?uf,?rp,?nx,?nd,?nodata1,?chkstk1,?DOS5
  540. .xcref ?wfp,arg,cCall,cProc,assumes,?cs3,?cs2,?cs1
  541. .xcref defgrp,addseg,createSeg
  542. .xcref save,outif,errnz,errn$,errnz1
  543. .xcref ?PLMPrevParm,?gcc
  544. .xcref ?cCall1,?pcc,?no_bp1,?no_bp2
  545. .xcref ?cbe,?pcbe
  546. ;; conditionals set by the macros
  547. ;;
  548. ;; ?pc Procedure class. If this is set to 1, then the procedure
  549. ;; is a far procedure, else it is a near procedure.
  550. ;;
  551. ;; ?ia Interface adjustment count for far procedures. The
  552. ;; interface adjustment defines the number of bytes of
  553. ;; storage allocated between BP and the first frame variable
  554. ;; allocated on the stack.
  555. ;;
  556. ;; Normally zero, it will be adjusted for both far windows
  557. ;; procedures and by register parameters.
  558. ;;
  559. ;; ?cpd Current procedure defined. This is set to a non-zero
  560. ;; value if a procedure is being defined (i.e a cProc has
  561. ;; been encountered, and cBegin has not).
  562. ;;
  563. ;; ?ba Begin active. This is set to a non-zero value if a
  564. ;; cBegin is active (i.e. a cBegin has been encountered,
  565. ;; and cEnd has not).
  566. ;;
  567. ;; ?wfp Windows far procedure. Set if a windows far procedure
  568. ;;
  569. ;; ?pcc procedure calling conventing. Calling convention for
  570. ;; this procedure. May be different than the default set
  571. ;; via ?PLM
  572. ;;
  573. ;;
  574. ;; Other variables that are defined once so that the .xcref command
  575. ;; doesn't get too upset if they show up missing!
  576. ?rsl = 0 ;;0 = no register to save
  577. ?cpd = 0 ;;<> 0 if in a procedure definition
  578. ?argl = 0 ;;length of arguments pushed on stack
  579. ?argc = 0 ;;# of arguments so far
  580. ?ba = 0 ;;<>0 if in a procedure (xbegin)
  581. ?acb = 0 ;;number of arguments to a call
  582. ??? = 0 ;;byte count of local storage
  583. ?po = 0 ;;byte count of parameters
  584. ?pas = 0 ;;autosave value for procedure
  585. ?pc = 0 ;;class of a procedure (near/far)
  586. ?ia = 0 ;;no adjustment
  587. ?pu = 0 ;;public flag for some macros
  588. ?adj = 0 ;;initial define for .xcref
  589. ?rp = 0 ;;count of register parameters
  590. ?uf = 0 ;;user's frame code specified
  591. ?nd = 0 ;;NODATA keyword specified
  592. ?nx = 0 ;;ATOMIC keyword specified
  593. ?wfp = 0 ;;window far procedure
  594. ?ff = 0 ;;forceframe keyword specified
  595. ?dd2 = 0 ;;used for globalx and staticx
  596. ?cCall1 = 0 ;;used for cCalls
  597. ?pcc = ?PLM ;;procedure calling convention
  598. ?PLMPrevParm = 0 ;;Used in parameter processing
  599. ?no_bp2 = ?no_bp1 ;;BP / No BP flag
  600. ?cbe = 0 ;;cbegin/cEnd keyword flag
  601. .xcref ?casen
  602. if1 ;;only define ?casen on pass 1
  603. ?casen = 0 ;;case sensitive assembly if <> 0
  604. endif
  605. ?n = 0000000000000000b ;;register none
  606. ?ax = 0000000000000011b ;;register ax
  607. ?ah = 0000000000000001b ;;register ah
  608. ?al = 0000000000000010b ;;register al
  609. ?bx = 0000000000001100b ;;register bx
  610. ?bh = 0000000000000100b ;;register bh
  611. ?bl = 0000000000001000b ;;register bl
  612. ?cx = 0000000000110000b ;;register cx
  613. ?ch = 0000000000010000b ;;register ch
  614. ?cl = 0000000000100000b ;;register cl
  615. ?dx = 0000000011000000b ;;register dx
  616. ?dh = 0000000001000000b ;;register dh
  617. ?dl = 0000000010000000b ;;register dl
  618. ?si = 0000000100000000b ;;register si
  619. ?di = 0000001000000000b ;;register di
  620. ?es = 0000010000000000b ;;register es
  621. ?ds = 0000100000000000b ;;register ds
  622. ?bp = 0001000000000000b ;;register bp
  623. ?sp = 0010000000000000b ;;register sp
  624. ?ss = 0100000000000000b ;;register ss
  625. ?cs = 1000000000000000b ;;register cs
  626. ;;Incase we're case sensitive
  627. ?AX = 0000000000000011b ;;register ax
  628. ?AH = 0000000000000001b ;;register ah
  629. ?AL = 0000000000000010b ;;register al
  630. ?BX = 0000000000001100b ;;register bx
  631. ?BH = 0000000000000100b ;;register bh
  632. ?BL = 0000000000001000b ;;register bl
  633. ?CX = 0000000000110000b ;;register cx
  634. ?CH = 0000000000010000b ;;register ch
  635. ?CL = 0000000000100000b ;;register cl
  636. ?DX = 0000000011000000b ;;register dx
  637. ?DH = 0000000001000000b ;;register dh
  638. ?DL = 0000000010000000b ;;register dl
  639. ?SI = 0000000100000000b ;;register si
  640. ?DI = 0000001000000000b ;;register di
  641. ?ES = 0000010000000000b ;;register es
  642. ?DS = 0000100000000000b ;;register ds
  643. ?BP = 0001000000000000b ;;register bp
  644. ?SP = 0010000000000000b ;;register sp
  645. ?SS = 0100000000000000b ;;register ss
  646. ?CS = 1000000000000000b ;;register cs
  647. ?EAX = 0000000000000011b ;;register ax
  648. ?EBX = 0000000000001100b ;;register bx
  649. ?ECX = 0000000000110000b ;;register cx
  650. ?EDX = 0000000011000000b ;;register dx
  651. ?ESI = 0000000100000000b ;;register si
  652. ?EDI = 0000001000000000b ;;register di
  653. ?EBP = 0001000000000000b ;;register bp
  654. ?ESP = 0010000000000000b ;;register sp
  655. ?eax = 0000000000000011b ;;register ax
  656. ?ebx = 0000000000001100b ;;register bx
  657. ?ecx = 0000000000110000b ;;register cx
  658. ?edx = 0000000011000000b ;;register dx
  659. ?esi = 0000000100000000b ;;register si
  660. ?edi = 0000001000000000b ;;register di
  661. ?ebp = 0001000000000000b ;;register bp
  662. ?esp = 0010000000000000b ;;register sp
  663. ?IAX = 0000000000000011b ;;register ax
  664. ?IBX = 0000000000001100b ;;register bx
  665. ?ICX = 0000000000110000b ;;register cx
  666. ?IDX = 0000000011000000b ;;register dx
  667. ?ISI = 0000000100000000b ;;register si
  668. ?IDI = 0000001000000000b ;;register di
  669. ?IBP = 0001000000000000b ;;register bp
  670. ?ISP = 0010000000000000b ;;register sp
  671. .cref
  672. ;; uconcat - unconditionally generate a statement from a field
  673. ;; of given parameters
  674. ;;
  675. ;; usage:
  676. ;; uconcat a,b,c,d,e,f,g
  677. ;;
  678. ;; where:
  679. ;; a,b are concatenated for field 1
  680. ;; c,d are concatenated for field 2
  681. ;; e,f,g are concatenated for field 3
  682. uconcat macro a,b,c,d,e,f,g
  683. a&b c&d e&f&g
  684. endm
  685. ;; mpush pushes multiple registers onto the stack according to
  686. ;; a register specification.
  687. ;;
  688. ;; format:
  689. ;; mpush r
  690. ;;
  691. ;; where:
  692. ;; r is a numeric expression returned from ?ri
  693. ;; or any other valid register expression
  694. mpush macro r
  695. irp x,<IAX,IBX,ICX,IDX,ISI,IDI,es,ds,IBP,ISP,ss,cs>
  696. if (r and ?&&x)
  697. push x ;@
  698. endif
  699. endm
  700. endm
  701. ;; mpop pops multiple registers from the stack according to
  702. ;; a register specification.
  703. ;;
  704. ;; format:
  705. ;; mpop r
  706. ;;
  707. ;; where:
  708. ;; r is a numeric expression returned from ?ri
  709. ;; or any other valid register expression
  710. mpop macro r
  711. irp x,<cs,ss,ISP,IBP,ds,es,IDI,ISI,IDX,ICX,IBX,IAX>
  712. if (r and ?&&x)
  713. pop x ;@
  714. endif
  715. endm
  716. endm
  717. ;; save - flag that the indicated registers are to be saved/restored
  718. ;;
  719. ;; A flag is created which indicates which registers are to be saved
  720. ;; when the cCall macro is invoked, and then restored after the call.
  721. ;;
  722. ;; usage:
  723. ;; save <r>
  724. ;;
  725. ;; where r is the list of registers to save, which may be:
  726. ;;
  727. ;; register saves
  728. ;; AX AX
  729. ;; AH AX
  730. ;; AL AX
  731. ;; BX BX
  732. ;; BH BX
  733. ;; BL BX
  734. ;; CX CX
  735. ;; CH CX
  736. ;; CL CX
  737. ;; DX DX
  738. ;; DH DX
  739. ;; DL DX
  740. ;; SI SI
  741. ;; DI DI
  742. ;; ES ES
  743. ;; DS DS
  744. ;; BP BP
  745. ;;
  746. ;; none nothing
  747. ;;
  748. ;; the macro generates a value for the variable ?rsl
  749. save macro r
  750. ?rsl=0 ;;initialize save list
  751. ?ri ?rsl,<r> ;;generate magic number
  752. endm
  753. ;; ?ri - or register indexes to variable
  754. ;;
  755. ;; ?ri is a macro that examines the passed argument list and computes
  756. ;; a register index variable.
  757. ;;
  758. ;; The values ORed with the variable are:
  759. ;;
  760. ;; ?n equ 0000000000000000b;
  761. ;; ?AX equ 0000000000000011b;
  762. ;; ?AH equ 0000000000000001b;
  763. ;; ?AL equ 0000000000000010b;
  764. ;; ?BX equ 0000000000001100b;
  765. ;; ?BH equ 0000000000000100b;
  766. ;; ?BL equ 0000000000001000b;
  767. ;; ?CX equ 0000000000110000b;
  768. ;; ?CH equ 0000000000010000b;
  769. ;; ?CL equ 0000000000100000b;
  770. ;; ?DX equ 0000000011000000b;
  771. ;; ?DH equ 0000000001000000b;
  772. ;; ?DL equ 0000000010000000b;
  773. ;; ?SI equ 0000000100000000b;
  774. ;; ?DI equ 0000001000000000b;
  775. ;; ?ES equ 0000010000000000b;
  776. ;; ?DS equ 0000100000000000b;
  777. ;; ?BP equ 0001000000000000b;
  778. ;; ?SP equ 0010000000000000b;
  779. ;; ?SS equ 0100000000000000b;
  780. ;; ?CS equ 1000000000000000b;
  781. ;; usage:
  782. ;; ?ri n,<rl>
  783. ;s mach independant names; where:
  784. ;; n is the variable to contain the new index value
  785. ;; r is the register list
  786. ?ri macro n,r
  787. irp x,<r>
  788. ifdef ?&&x ;;if defined, then add to list
  789. n=n or ?&&x
  790. else
  791. ??error2 <unknown register x>
  792. .err
  793. endif
  794. endm
  795. endm
  796. ;; parmx - generate reference to parameter(s) on the stack
  797. ;;
  798. ;; An equate is generated for addressing a paramter(s)
  799. ;; on the stack for the current procedural frame.
  800. ;;
  801. ;; An error message is generated if there isn't a current frame.
  802. ;;
  803. ;; usage:
  804. ;; parmX n
  805. ;; where:
  806. ;; X is the type of the argument(s) B=byte, W=word, D=dword
  807. ;; I = machine independant int size
  808. ;; n is the name(s) to be given the parameter(s).
  809. ;;
  810. ;; Bytes are considered to be two bytes long for alignment.
  811. ;;
  812. ;; The parmd form of the macro generates three equates:
  813. ;;
  814. ;; name - for accessing the parameter as a double word
  815. ;; off_name - for accessing the offset (lsw) of the parameter
  816. ;; seg_name - for accessing the segment (msw) of the parameter
  817. .xcref
  818. .xcref parmB,parmW,parmD,parmQ,parmT,parmCP,parmDP,parmH,parmI
  819. .cref
  820. parmB macro n
  821. ?pp <n>,<byte>,sizeI,1
  822. endm
  823. parmW macro n
  824. ?pp <n>,<word>,sizeI,2
  825. endm
  826. parmI macro n
  827. ?pp <n>,wordI,sizeI,sizeI
  828. endm
  829. parmD macro n
  830. ife ?pcc ;;if to assemble for C
  831. irp x,<n>
  832. ?pp <&&x>,<dword>,0,4
  833. ?pp <off_&&x>,<word>,2,2
  834. ?pp <seg_&&x>,<word>,2,2
  835. endm
  836. else ;;if to assemble for PL/M
  837. irp x,<n>
  838. ?pp <seg_&&x>,<word>,2,2
  839. ?pp <off_&&x>,<word>,2,2
  840. ?pp <&&x>,<dword>,0,4
  841. endm
  842. endif
  843. endm
  844. parmH macro n
  845. ?pp <n>,<word>,4,2
  846. endm
  847. parmQ macro n
  848. ?pp <n>,<qword>,8,8
  849. endm
  850. parmT macro n
  851. ?pp <n>,<tbyte>,10,10
  852. endm
  853. if sizec
  854. parmCP macro n
  855. parmD <n>
  856. endm
  857. else
  858. parmCP macro n
  859. parmW <n>
  860. endm
  861. endif
  862. if sized
  863. parmDP macro n
  864. parmD <n>
  865. endm
  866. else
  867. parmDP macro n
  868. parmI <n>
  869. endm
  870. endif
  871. ;; ?pp is the generalized parameter definition macro
  872. ;;
  873. ;; usage:
  874. ;; ?pp m,t,l,s
  875. ;;
  876. ;; where:
  877. ;; n is the name(s) of the parameters
  878. ;; t is the type (word, dword)
  879. ;; l is the length to update parameter byte count by
  880. ;; s is the internal typing size
  881. ?pp macro n,t,l,s ;;process parameter
  882. if ?cpd ;;must be in a procedure definition
  883. .xcref
  884. irp x,<n>
  885. .xcref ?t&&x ;;don't want this in xref
  886. ?t&&x=s ;;save size info
  887. ife ?pcc ;;if C calling convention
  888. ?pp1 x,<t>,,,%(?po+?adj)
  889. ?po=?po+l ;;update parameter offset
  890. else ;;else assemble for PL/M
  891. ?PLMPrevParm=?PLMPrevParm+1 ;;Show next parameter
  892. ?po=?po+l ;;update parameter offset
  893. ?pp1 x,<t>,%?po,%?adj,,%?PLMPrevParm,%(?PLMPrevParm-1)
  894. endif
  895. endm
  896. .cref
  897. else
  898. ??error2 <parm(s) "&n" declared outside proc def>
  899. endif
  900. endm
  901. ;; ?pp1 is the macro that generates the text equate for the
  902. ;; parameter. Two options exist, one for the C calling
  903. ;; convention where the last parameter was the first pushed onto
  904. ;; the stack ('C' convention), and one for the PL/M calling
  905. ;; convention where the first parameter was the first
  906. ;; pushed (also the same as ms-pascal).
  907. ;;
  908. ;; The text generated will be of one of two forms:
  909. ;;
  910. ;; name equ (type ptr [bp+(adj+offset)]) for C
  911. ;; or
  912. ;; name equ (type ptr [bp+adj+?po-offset]) for PL/M
  913. ;;
  914. ;;
  915. ;; For C, since parameters are pushed first last, the offset
  916. ;; plus the adjust will point to the correct parameter.
  917. ;;
  918. ;; For PL/M, since parameters are pushed first first, the offset
  919. ;; of a parameter is much more complicated. A known portion of
  920. ;; the offset can be computed when the text equate is generated.
  921. ;;
  922. ;; What is known is the number of garbage bytes between BP and
  923. ;; the nearest parameter (in this case the last parameter), and
  924. ;; also how many bytes of parameters have preceeded this parameter.
  925. ;;
  926. ;; What is unknown is how many total bytes of parameters there will
  927. ;; be, which affects all the generated text equates since the offset
  928. ;; from bp must be determined at some point.
  929. ;;
  930. ;; Well, the offset from BP can be computed with one variable if
  931. ;; the following is remembered:
  932. ;;
  933. ;; the offset of any parameter from the first parameter is always
  934. ;; the current parameter offset (?po).
  935. ;;
  936. ;; With this in mind, you just have to figure out where the first
  937. ;; parameter is, which is:
  938. ;;
  939. ;; bp + garbage adjustment + distance to first parameter
  940. ;; or
  941. ;; bp + ?adj + ?po
  942. ;;
  943. ;; This implies that any parameter can be defined as:
  944. ;;
  945. ;; bp + ?adj + ?po -%?po
  946. ;;
  947. ;; Make any sense?
  948. ;;
  949. ;; For PL/M, a chain of self-purging macros will be generated
  950. ;; which will pass the evaluated ?po to any previous incarnation
  951. ;; of the macro. This will allow the text equate to be generated
  952. ;; with the actual offset instead of the symbolic ?po.
  953. ;;
  954. ;;
  955. ;; usage:
  956. ;; ?pp1 n,t,o,a,b,cpc,ppc
  957. ;;
  958. ;; where:
  959. ;; n is the name to be given the equate
  960. ;; t is the type (byte, word, dword)
  961. ;; o is the offset from the first parameter
  962. ;; a is the adjustment
  963. ;; b is the adjustment plus the offset from the first parameter
  964. ;; cpc is the number of parameters so far
  965. ;; ppc is cpc - 1
  966. ?pp1 macro n,t,o,a,b,cpc,ppc
  967. ife ?pcc ;;if to generate for C
  968. if ?no_bp2
  969. n equ (t ptr [+b])
  970. else
  971. n equ (t ptr [IBP][+b])
  972. endif
  973. else ;;else generate for PL/M
  974. .xcref
  975. .xcref ?PLMParm&cpc
  976. .cref
  977. if ?no_bp2
  978. ?PLMParm&cpc &macro po
  979. uconcat <n>,,<equ>,,<(t ptr [+>,%(a+po-o),<])>
  980. ?PLMParm&ppc po
  981. purge ?PLMParm&cpc
  982. &endm
  983. else
  984. ?PLMParm&cpc &macro po
  985. uconcat <n>,,<equ>,,<(t ptr [IBP][+>,%(a+po-o),<])>
  986. ?PLMParm&ppc po
  987. purge ?PLMParm&cpc
  988. &endm
  989. endif
  990. endif
  991. endm
  992. ;; parmR - register parameter
  993. ;;
  994. ;; parmR is the macro used for generating register parameters.
  995. ;; The space allocated for the register parameters will be
  996. ;; the ?ia (interface adjust) area which is between the old
  997. ;; BP and the first parameter. Normally this is empty (?ia=0),
  998. ;; or has the saved ds for a windows far procedure.
  999. ;;
  1000. ;; Byte and dword register parameters will be allowed.
  1001. ;;
  1002. ;; usage:
  1003. ;; parmR n,r,r2
  1004. ;; where:
  1005. ;; n is the name of the parameter
  1006. ;; r is the register it is in
  1007. ;; r2 is the offset register if a dword
  1008. ifndef ?NOPARMR
  1009. .xcref
  1010. .xcref ?pr,parmR
  1011. .cref
  1012. parmR macro n,r,r2
  1013. ?pr n,r,r2,%?rp,%(?ia+2)
  1014. endm
  1015. ;; ?pr - register parameter
  1016. ;;
  1017. ;; ?pr is the actual macro for generating the equates for
  1018. ;; register parameters.
  1019. ;;
  1020. ;; usage:
  1021. ;; parmR n,r,r2,i,o
  1022. ;; where:
  1023. ;; n is the name of the parameter
  1024. ;; r is the register it is in
  1025. ;; r2 is the offset register if a dword
  1026. ;; i is the index of the ?rp to generate
  1027. ;; o is the offset from bp where the parm will be
  1028. ?pr macro n,r,r2,i,o
  1029. .xcref
  1030. ifnb <r2> ;;if a dword parameter
  1031. parmR seg_&n,r ;;define segment equate
  1032. parmR off_&n,r2 ;;define offset equate
  1033. if ?no_bp2
  1034. n equ (dword ptr [-o-2]) ;;define dword equate
  1035. else
  1036. n equ (dword ptr [bp][-o-2]) ;;define dword equate
  1037. endif
  1038. .xcref ?t&n
  1039. ?t&n=4 ;;show a dword to cmacros
  1040. else
  1041. .xcref ?rp&i
  1042. ?rp&i=0 ;;show no register(s)
  1043. ifdef ?&r ;;define register if valid
  1044. ?rp&i=?&r
  1045. endif
  1046. if ??? or (?cpd eq 0) or (?rp&i eq 0)
  1047. ??error2 <invalid parmR encountered: &n,&r>
  1048. exitm
  1049. endif
  1050. if ?no_bp2
  1051. n equ (word ptr [-o]) ;;assume a word register
  1052. else
  1053. n equ (word ptr [bp][-o]) ;;assume a word register
  1054. endif
  1055. .xcref ?t&n
  1056. ?t&n=2 ;;show a word to cmacros
  1057. irp x,<bh,ch,dh,bl,cl,dl,ah,al>
  1058. if ?&&x eq ?&r ;;if really a byte register
  1059. if ?no_bp2
  1060. n equ (byte ptr [-o]) ;; then make it a byte
  1061. else
  1062. n equ (byte ptr [bp][-o]) ;; then make it a byte
  1063. endif
  1064. ?t&n=1 ;;show a byte to cmacros
  1065. exitm
  1066. endif
  1067. endm
  1068. ?ia=?ia+2 ;;show this guy is out there
  1069. ?rp=?rp+1 ;;show one more register parameter
  1070. endif
  1071. .cref
  1072. endm
  1073. endif
  1074. ;; localx - generate reference to a local variable on the stack
  1075. ;;
  1076. ;; An equate is generated for addressing a local variable
  1077. ;; on the stack for the current procedural frame.
  1078. ;;
  1079. ;; usage:
  1080. ;; localx n
  1081. ;; where:
  1082. ;; x is the type b=byte, w=word, d=dword, v=variable size
  1083. ;; n is the name(s) to be given the variable(s).
  1084. ;;
  1085. ;; Bytes are considered to be two bytes long for alignment reasons
  1086. ;;
  1087. ;; The locald form of the macro generates three equates:
  1088. ;;
  1089. ;; name - for accessing the variable as a double word
  1090. ;; off_name - for accessing the offset (lsw) of the variable
  1091. ;; seg_name - for accessing the segment (msw) of the variable
  1092. .xcref
  1093. .xcref localB,localW,localD,localQ,localT,localCP,localDP,localV,localI
  1094. .cref
  1095. localB macro n
  1096. ?aloc <n>,<byte ptr>,1,1,0 ;; no alignment
  1097. endm
  1098. localW macro n
  1099. ?aloc <n>,<word ptr>,2,2,1 ;; word aligned
  1100. endm
  1101. localI macro n
  1102. ?aloc <n>,&wordI&< ptr>,sizeI,sizeI,1 ;; dword aligned
  1103. endm
  1104. localD macro n
  1105. irp x,<n>
  1106. ?aloc <seg_&&x>,<word ptr>,2,2,1 ;; word aligned
  1107. ?aloc <off_&&x>,<word ptr>,2,2,1 ;; word aligned
  1108. ?aloc <&&x>,<dword ptr>,0,4,1 ;; word aligned
  1109. endm
  1110. endm
  1111. localQ macro n
  1112. ?aloc <n>,<qword ptr>,8,8,1 ;; word aligned
  1113. endm
  1114. localT macro n
  1115. ?aloc <n>,<tbyte ptr>,10,10,1 ;; word aligned
  1116. endm
  1117. if sizec
  1118. localCP macro n
  1119. localD <n>
  1120. endm
  1121. else
  1122. localCP macro n
  1123. localW <n>
  1124. endm
  1125. endif
  1126. if sized
  1127. localDP macro n
  1128. localD <n>
  1129. endm
  1130. else
  1131. localDP macro n
  1132. localI <n>
  1133. endm
  1134. endif
  1135. localV macro n,a
  1136. ?aloc <n>,,%(a),0,1 ;; word aligned
  1137. endm
  1138. ;; ?aloc is the macro that actually allocates local storage.
  1139. ;; it is only invoked by the localx macros.
  1140. ;;
  1141. ;; usage:
  1142. ;; ?aloc n,t,l,s,a
  1143. ;; where:
  1144. ;; n is a list of names of local variable of the
  1145. ;; given type.
  1146. ;; t is the text string for the given variable
  1147. ;; and is one of:
  1148. ;; word ptr
  1149. ;; dword ptr
  1150. ;; byte ptr
  1151. ;; or alternatively left blank for variable size
  1152. ;; allocations (no implicit type).
  1153. ;; l is the size of the variable in bytes
  1154. ;; s is the internal type flag (size), and is one of:
  1155. ;; word - 2
  1156. ;; dword - 4
  1157. ;; byte - 1
  1158. ;; variable - 0
  1159. ;; a is a flag indicating that word alignment is to be
  1160. ;; forced for this type of item.
  1161. ;;
  1162. ;; NOTE: It is assumed that the stack is already aligned on a word
  1163. ;; boundary when the cProc is invoked. The macros will guarantee
  1164. ;; to allocate an even number of bytes on the stack to maintain
  1165. ;; word alignment.
  1166. ?aloc macro n,t,l,s,a
  1167. if ?cpd ;;must be in a proc def
  1168. .xcref
  1169. irp x,<n> ;;generate symbol equates
  1170. ???=???+l ;;update length of locals
  1171. if a ;;if align, then force word alignment
  1172. if memS32 and l GT 2
  1173. ???=((??? + 3) and 0fffffffch) ;; dword alignment
  1174. else
  1175. ???=((??? + 1) and 0fffeh)
  1176. endif
  1177. endif
  1178. ?al1 x,<t>,%(???+?ia) ;;?ia will always be valid (0 or 2)
  1179. .xcref ?t&&x
  1180. ?t&&x=s ;;save size info
  1181. endm
  1182. .cref
  1183. else
  1184. ??error2 <locals "&n" declared outside procedure def>
  1185. endif
  1186. endm
  1187. ;; ?al1 - allocate local, continued.
  1188. ;;
  1189. ;; ?al1 actually generates the text equate for the local variable.
  1190. ;; The form of the text equate generated is more or less:
  1191. ;;
  1192. ;; name equ (type ptr [bp-?ia-nn])
  1193. ;; or
  1194. ;; name equ ([bp-?ia-nn])
  1195. ;;
  1196. ;; where:
  1197. ;; ?ia is defined to be either zero, or is defined to be
  1198. ;; the number of bytes between the saved BP and the first
  1199. ;; local. ?ia is only applicable if the current cProc is
  1200. ;; a windows far procedure or if parmRs have been
  1201. ;; encountered. If not, the ?ia will be zero. since ?ia
  1202. ;; is determinable prior to invoking this macro, it will be
  1203. ;; added into the offset ("nn") passed to this macro
  1204. ;;
  1205. ;; usage:
  1206. ;; ?al1 n,t,o
  1207. ;; where:
  1208. ;; n is the name for the text equate
  1209. ;; t is the type of the equate
  1210. ;; o is the offset of the equate
  1211. ?al1 macro n,t,o
  1212. if ?no_bp2
  1213. n equ (t [-o])
  1214. else
  1215. n equ (t [IBP][-o])
  1216. endif
  1217. endm
  1218. ;; ?gcc - get calling convention
  1219. ;;
  1220. ;; ?gcv sets the given symbol to the calling convention
  1221. ;; to be used.
  1222. ;;
  1223. ;; usage:
  1224. ;; ?gcc s,i,cc
  1225. ;;
  1226. ;; where:
  1227. ;; s is the symbol to return the convention in
  1228. ;; s = 0 if 'C' calling convention
  1229. ;; s = 1 if PL/M (PASCAL) calling convention
  1230. ;; i is the initial value for s
  1231. ;; cc is the calling convention override, and may be one of
  1232. ;; C use 'C' convention
  1233. ;; PLM use PL/M calling convention
  1234. ;; PASCAL use PL/M calling convention
  1235. ?gcc macro s,i,cc
  1236. s = i ;;Set default calling convention
  1237. ifnb <cc>
  1238. ifidn <cc>,<C> ;;If overriding default
  1239. s=0 ;; 'C' calling convention
  1240. endif
  1241. ifidn <cc>,<PLM>
  1242. s=1 ;; PL/M calling convention
  1243. endif
  1244. ifidn <cc>,<PASCAL>
  1245. s=1 ;; PL/M calling convention
  1246. endif
  1247. endif
  1248. endm
  1249. ifndef ?NOGLOBAL
  1250. .xcref
  1251. .xcref globalB,globalW,globalD,globalQ,globalT,globalCP,globalDP,globalI
  1252. .cref
  1253. ;; globalx - define global data of type x
  1254. ;;
  1255. ;; usage:
  1256. ;; globalx n,i,s,c
  1257. ;; where:
  1258. ;; x is the type of the variable b=byte, w=word, d=dword
  1259. ;; q=quad word, t=tenbytes, cp=code pointer, dp=data pointer
  1260. ;; n is the name to be given the variable.
  1261. ;; i is the initial value of the variable.
  1262. ;; s is the duplication factor
  1263. ;; c is the convention, C for C, PLM or PASCAL for PL/M.
  1264. ;; The default (?PLM flag) will be used if not specified.
  1265. ;;
  1266. ;; The D form will generate two extra equates of the form off_n and seg_n.
  1267. globalB macro n,i,s,c
  1268. ?ad <n>,1
  1269. ?dd n,1,<byte>,<db>,<i>,<s>,<c>
  1270. endm
  1271. globalW macro n,i,s,c
  1272. ?ad <n>,2
  1273. ?dd n,1,<word>,<dw>,<i>,<s>,<c>
  1274. endm
  1275. globalI macro n,i,s,c
  1276. ?ad <n>,2
  1277. ?dd n,1,wordI,%asmdI,<i>,<s>,<c>
  1278. endm
  1279. globalD macro n,i,s,c
  1280. ?ad <n>,4
  1281. ?dd n,1,<dword>,<dd>,<i>,<s>,<c>
  1282. off_&n equ word ptr n[0]
  1283. seg_&n equ word ptr n[2]
  1284. endm
  1285. globalQ macro n,i,s,c
  1286. ?ad <n>,8
  1287. ?dd n,1,<qword>,<dq>,<i>,<s>,<c>
  1288. endm
  1289. globalT macro n,i,s,c
  1290. ?ad <n>,10
  1291. ?dd n,1,<tbyte>,<dt>,<i>,<s>,<c>
  1292. endm
  1293. if sizec
  1294. globalCP macro n,i,s,c
  1295. globalD n,<i>,<s>,<c>
  1296. endm
  1297. else
  1298. globalCP macro n,i,s,c
  1299. globalW n,<i>,<s>,<c>
  1300. endm
  1301. endif
  1302. if sized
  1303. globalDP macro n,i,s,c
  1304. globalD n,<i>,<s>,<c>
  1305. endm
  1306. else
  1307. globalDP macro n,i,s,c
  1308. globalI n,<i>,<s>,<c>
  1309. endm
  1310. endif
  1311. endif
  1312. ifndef ?NOSTATIC
  1313. .xcref
  1314. .xcref staticB,staticW,staticD,staticQ,staticT,staticCP,staticDP,staticI
  1315. .cref
  1316. ;; staticx - define static data of type x
  1317. ;;
  1318. ;; usage:
  1319. ;; staticx n,i,s
  1320. ;; where:
  1321. ;; x is the type of the variable b=byte, w=word, d=dword
  1322. ;; q=quad word, t=tenbytes, cp=code pointer, dp=data pointer
  1323. ;; n is the name to be given the variable.
  1324. ;; i is the initial value of the variable.
  1325. ;; s is the duplication factor
  1326. ;;
  1327. ;; statics do not generate an underscored version of the symbol
  1328. ;; since they are intended to be internal symbols. If they are
  1329. ;; required to be public, use globlax.
  1330. staticB macro n,i,s
  1331. ?ad <n>,1
  1332. ?dd n,0,<byte>,<db>,<i>,<s>,<PLM> ;;PLM to keep from generating _
  1333. endm
  1334. staticW macro n,i,s
  1335. ?ad <n>,2
  1336. ?dd n,0,<word>,<dw>,<i>,<s>,<PLM>
  1337. endm
  1338. staticD macro n,i,s
  1339. ?ad <n>,4
  1340. ?dd n,0,<dword>,<dd>,<i>,<s>,<PLM>
  1341. endm
  1342. staticI macro n,i,s
  1343. ?ad <n>,sizeI
  1344. ?dd n,0,wordI,%asmdI,<i>,<s>,<PLM>
  1345. endm
  1346. staticQ macro n,i,s
  1347. ?ad <n>,8
  1348. ?dd n,0,<qword>,<dq>,<i>,<s>,<PLM>
  1349. endm
  1350. staticT macro n,i,s
  1351. ?ad <n>,10
  1352. ?dd n,0,<tbyte>,<dt>,<i>,<s>,<PLM>
  1353. endm
  1354. if sizec
  1355. staticCP macro n,i,s
  1356. staticD n,<i>,<s>
  1357. endm
  1358. else
  1359. staticCP macro n,i,s
  1360. staticW n,<i>,<s>
  1361. endm
  1362. endif
  1363. if sized
  1364. staticDP macro n,i,s
  1365. staticD n,<i>,<s>
  1366. endm
  1367. else
  1368. staticDP macro n,i,s
  1369. staticI n,<i>,<s>
  1370. endm
  1371. endif
  1372. endif
  1373. ;; ?dd is the generalized data definition macro.
  1374. ;;
  1375. ;; format:
  1376. ;; ?dd n,p,t,d,i,s,c
  1377. ;; where:
  1378. ;; n is the name of the procedure
  1379. ;; p is the public flag
  1380. ;; t is the assembler type (byte, word, dword)
  1381. ;; d is the assembler directive (db,dw or dd)
  1382. ;; i is the initial value
  1383. ;; s is a duplication factor
  1384. ;; c is the convention, C for C, PLM or PSACAL for PL/M.
  1385. ;; The default (?PLM flag) will be used if not specified.
  1386. ?dd macro n,p,t,d,i,s,c
  1387. ?gcc ?dd2,%?PLM,<c> ;;Set calling convention
  1388. ife ?dd2 ;;If 'C'
  1389. n label t
  1390. ?dd1 _&n,p,<d>,<i>,<s> ;;Microsoft C uses leading underscores
  1391. else
  1392. ?dd1 n,p,<d>,<i>,<s> ;;If PL/M
  1393. endif
  1394. endm
  1395. ;; ?dd1 is the generalized data definition macro.
  1396. ;;
  1397. ;; format:
  1398. ;; ?dd1 n,p,d,i,s
  1399. ;; where:
  1400. ;; n is the name of the procedure
  1401. ;; p is the public flag
  1402. ;; d is the assembler directive (db,dw or dd)
  1403. ;; i is the initial value
  1404. ;; s is a duplication factor
  1405. ?dd1 macro n,p,d,i,s
  1406. if p
  1407. public n
  1408. endif
  1409. ifb <s>
  1410. n d i
  1411. else
  1412. ifb <i>
  1413. n d s dup (?)
  1414. else
  1415. n d s dup (i)
  1416. endif
  1417. endif
  1418. endm
  1419. ifndef ?NOEXTERN
  1420. .xcref
  1421. .xcref ?ex1,?ex2,externB,externW,externD,externQ,externT,externI
  1422. .xcref externNP,externFP,externP,externCP,externDP,externA
  1423. .cref
  1424. ?ex2 = 0
  1425. ;; externx - define external data of type x
  1426. ;;
  1427. ;; usage:
  1428. ;; externx n,c
  1429. ;; where:
  1430. ;; x is the type of the variable b=byte, w=word, d=dword
  1431. ;; q=quad word, t=tenbytes, cp=code pointer
  1432. ;; dp=data pointer, a=absolute
  1433. ;; n is a list of names to define
  1434. ;; c is the convention, C for C, PLM or PSACAL forPL/M.
  1435. ;; The default (?PLM flag) will be used if not specified.
  1436. externA macro n,c ;;40h is reserved for whatever will
  1437. ?ex1 <n>,40h,<abs>,<c>,<> ;; be done in the future for ASB
  1438. endm ;; externals
  1439. externB macro n,c
  1440. ?ex1 <n>,1,<byte>,<c>,<>
  1441. endm
  1442. externW macro n,c
  1443. ?ex1 <n>,2,<word>,<c>,<>
  1444. endm
  1445. externD macro n,c
  1446. ?ex1 <n>,4,<dword>,<c>,<>
  1447. endm
  1448. externI macro n,c
  1449. ?ex1 <n>,sizeI,%wordI,<c>,<>
  1450. endm
  1451. externQ macro n,c
  1452. ?ex1 <n>,8,<qword>,<c>,<>
  1453. endm
  1454. externT macro n,c
  1455. ?ex1 <n>,10,<tbyte>,<c>,<>
  1456. endm
  1457. externNP macro n,c
  1458. ?ex1 <n>,2,<near>,<c>,<cc>
  1459. endm
  1460. externFP macro n,c
  1461. ?ex1 <n>,4,<far>,<c>,<cc>
  1462. endm
  1463. if sizec
  1464. externP macro n,c
  1465. ?ex1 <n>,4,<far>,<c>,<cc>
  1466. endm
  1467. else
  1468. externP macro n,c
  1469. ?ex1 <n>,2,<near>,<c>,<cc>
  1470. endm
  1471. endif
  1472. if sizec
  1473. externCP macro n,c
  1474. ?ex1 <n>,4,<dword>,<c>,<>
  1475. endm
  1476. else
  1477. externCP macro n,c
  1478. ?ex1 <n>,2,<word>,<c>,<>
  1479. endm
  1480. endif
  1481. if sized
  1482. externDP macro n,c
  1483. ?ex1 <n>,4,<dword>,<c>,<>
  1484. endm
  1485. else
  1486. externDP macro n,c
  1487. ?ex1 <n>,2,<word>,<c>,<>
  1488. endm
  1489. endif
  1490. ;; ?ex1 is the generalized external definition macro
  1491. ;;
  1492. ;; format:
  1493. ;; ?ex1 n,s,d,c,scv
  1494. ;; where:
  1495. ;; n is are the names of the externals
  1496. ;; s is the size in bytes (used for typing)
  1497. ;; d is the type
  1498. ;; c is the convention, C for C, PLM or PSACAL for PL/M.
  1499. ;; The default (?PLM flag) will be used if not specified.
  1500. ;; scv save calling convention. If this field is "cc", then
  1501. ;; the calling convention will be saved in a ?CCn equ.
  1502. ?ex1 macro n,s,d,c,scv
  1503. ?gcc ?ex2,%?PLM,<c>
  1504. irp x,<n>
  1505. .xcref
  1506. .xcref ?t&&x
  1507. .cref
  1508. ?t&&x=s ;;save size info
  1509. ife ?ex2
  1510. extrn _&&x:&d
  1511. x equ _&&x
  1512. else
  1513. extrn x:&d
  1514. endif
  1515. ifidn <scv>,<cc> ;;save calling convention (C or PL/M)
  1516. .xcref ;; if NP, FP, or P
  1517. .xcref ?CC&&x
  1518. .cref
  1519. ?CC&&x=?ex2
  1520. endif
  1521. endm
  1522. endm
  1523. endif
  1524. ifndef ?NOLABEL
  1525. .xcref
  1526. .xcref ?lb1,?lblpu,?lb2
  1527. .xcref labelB,labelW,labelD,labelQ,labelT
  1528. .xcref labelNP,labelFP,labelP,labelCP,labelDP
  1529. .cref
  1530. ?lblpu = 0
  1531. ?lb2 = 0
  1532. ;; labelx - define label of data type x
  1533. ;;
  1534. ;; usage:
  1535. ;; labelx n,c
  1536. ;; where:
  1537. ;; x is the type of the variable b=byte, w=word, d=dword
  1538. ;; q=quad word, t=tenbytes, cp=code pointer, dp=data pointer
  1539. ;; n is a list of names to define, the first of which can
  1540. ;; be the keyword public
  1541. ;; c is the convention, C for C, PLM or PSACAL for PL/M.
  1542. ;; The default (?PLM flag) will be used if not specified.
  1543. labelB macro n,c
  1544. ?lb1 <n>,1,<byte>,<c>
  1545. endm
  1546. labelW macro n,c
  1547. ?lb1 <n>,2,<word>,<c>
  1548. endm
  1549. labelD macro n,c
  1550. ?lb1 <n>,4,<dword>,<c>
  1551. endm
  1552. labelQ macro n,c
  1553. ?lb1 <n>,8,<qword>,<c>
  1554. endm
  1555. labelT macro n,c
  1556. ?lb1 <n>,10,<tbyte>,<c>
  1557. endm
  1558. labelNP macro n,c
  1559. ?lb1 <n>,2,<near>,<c>
  1560. endm
  1561. labelFP macro n,c
  1562. ?lb1 <n>,4,<far>,<c>
  1563. endm
  1564. if sizec
  1565. labelP macro n,c
  1566. ?lb1 <n>,4,<far>,<c>
  1567. endm
  1568. else
  1569. labelP macro n,c
  1570. ?lb1 <n>,2,<near>,<c>
  1571. endm
  1572. endif
  1573. if sizec
  1574. labelCP macro n,c
  1575. ?lb1 <n>,4,<dword>,<c>
  1576. endm
  1577. else
  1578. labelCP macro n,c
  1579. ?lb1 <n>,2,<word>,<c>
  1580. endm
  1581. endif
  1582. if sized
  1583. labelDP macro n,c
  1584. ?lb1 <n>,4,<dword>,<c>
  1585. endm
  1586. else
  1587. labelDP macro n,c
  1588. ?lb1 <n>,2,<word>,<c>
  1589. endm
  1590. endif
  1591. ;; ?lb1 is the generalized label definition macro
  1592. ;;
  1593. ;; format:
  1594. ;; ?lb1 n,s,d
  1595. ;; where:
  1596. ;; n are the names of the labels
  1597. ;; s is the size in bytes (used for typing)
  1598. ;; d is the type
  1599. ;; c is the convention, C for C, PLM or PSACAL for PL/M.
  1600. ;; The default (?PLM flag) will be used if not specified.
  1601. ?lb1 macro n,s,d,c
  1602. ?gcc ?lb2,%?PLM,<c>
  1603. ?lblpu=0
  1604. irp x,<n>
  1605. ifidn <x>,<PUBLIC>
  1606. ?lblpu=1
  1607. else
  1608. .xcref
  1609. .xcref ?t&&x
  1610. .cref
  1611. ?t&&x=s ;;save size info
  1612. ife ?lb2 ;;If C
  1613. if ?lblpu
  1614. public _&&x
  1615. endif
  1616. _&&x label &d
  1617. x equ _&&x
  1618. else ;;If PL/M
  1619. if ?lblpu
  1620. public x
  1621. endif
  1622. x label &d
  1623. endif
  1624. endif
  1625. endm
  1626. endm
  1627. endif
  1628. ifndef ?NODEF
  1629. ;; defx - inform macros that name is of type x
  1630. ;;
  1631. ;; The given name(s) is flaged to be of the given type. This macro
  1632. ;; is intended for giving types to variables that were not generated
  1633. ;; by the macros (i.e., static storage). There must be a type definition
  1634. ;; for all parameters in a call list.
  1635. ;;
  1636. ;; usage:
  1637. ;; defx n
  1638. ;; where:
  1639. ;; x is the type of the variable b=byte, w=word, d=dword
  1640. ;; n is the name(s) to be given the variable(s).
  1641. ;;
  1642. ;; Bytes are considered to be two bytes long for alignment reasons
  1643. .xcref
  1644. .xcref defB,defW,defD,defQ,defT,defCP,defDP
  1645. .cref
  1646. defB macro n
  1647. ?ad <n>,1
  1648. endm
  1649. defW macro n
  1650. ?ad <n>,2
  1651. endm
  1652. defD macro n
  1653. ?ad <n>,4
  1654. endm
  1655. defQ macro n
  1656. ?ad <n>,8
  1657. endm
  1658. defT macro n
  1659. ?ad <n>,10
  1660. endm
  1661. if sizec
  1662. defCP macro n
  1663. defD <n>
  1664. endm
  1665. else
  1666. defCP macro n
  1667. defW <n>
  1668. endm
  1669. endif
  1670. if sized
  1671. defDP macro n
  1672. defD <n>
  1673. endm
  1674. else
  1675. defDP macro n
  1676. defW <n>
  1677. endm
  1678. endif
  1679. endif
  1680. ; ?ad is the macro which creates a definition for the given
  1681. ; symbol
  1682. ;
  1683. ; usage:
  1684. ; ?ad <n>,s
  1685. ; where:
  1686. ; n is a list of names to define
  1687. ; s is the size info (1,2,4,8,10)
  1688. ?ad macro n,s
  1689. irp x,<n>
  1690. .xcref
  1691. .xcref ?t&&x
  1692. .cref
  1693. ?t&&x=s ;;save size info
  1694. endm
  1695. endm
  1696. ifndef ?NOPTR
  1697. .xcref
  1698. .xcref regPtr,farPtr
  1699. .cref
  1700. ;; regPtr generates information allowing a 32-bit pointer currently
  1701. ;; in a register to be pushed as a parameter to a subroutine using
  1702. ;; the cCall macro.
  1703. ;;
  1704. ;; usage:
  1705. ;; regptr n,s,o
  1706. ;; where:
  1707. ;; n is the name the argument will be known as
  1708. ;; s is the register containing the segment portion
  1709. ;; of the pointer
  1710. ;; o is the register containing the offset portion
  1711. ;; of the pointer
  1712. ;;
  1713. ;; 2/14/85 - made obsolete with farptr
  1714. regPtr macro n,s,o
  1715. farPtr n,s,o
  1716. endm
  1717. ;; farPtr generates information allowing a 32-bit pointer to be
  1718. ;; pushed as a parameter to a subroutine using the cCall macro.
  1719. ;;
  1720. ;; usage:
  1721. ;; farptr n,s,o
  1722. ;; where:
  1723. ;; n is the name the argument will be known as
  1724. ;; s is the segment portion of the pointer
  1725. ;; o is the offset portion of the pointer
  1726. ;;
  1727. ;; Note that any cast must have been made in the argument itself
  1728. ;; (i.e. regptr ptr1,ds,<word ptr 3[si]>)
  1729. farPtr macro n,s,o
  1730. .xcref
  1731. .xcref ?t&n
  1732. .cref
  1733. n &macro
  1734. push s ;@
  1735. push o ;@
  1736. &endm
  1737. ?t&n=80h
  1738. endm
  1739. endif
  1740. ;; arg - declare argument
  1741. ;;
  1742. ;; The given argument(s) is added to the argument list structure
  1743. ;;
  1744. ;; format:
  1745. ;; arg a
  1746. ;;
  1747. ;; where:
  1748. ;; a is any valid argument to push.
  1749. ;;
  1750. ;; If any element in arglist has not been defined or isn't a 16-bit
  1751. ;; register, then a complete specification must have been given in a
  1752. ;; text equate and a defx also given (if not, you'll pay the penalty!)
  1753. arg macro a
  1754. irp x,<a>
  1755. ?argc=?argc+1 ;;increment the arg count
  1756. ?atal <x>,%?argc ;;generate argument
  1757. endm
  1758. endm
  1759. ;; ?atal (add to argument list) generates a macro that will cause
  1760. ;; the given argument to be processed when invoked. It is used by
  1761. ;; the arg macro only.
  1762. ?atal macro n,i
  1763. .xcref
  1764. .xcref ?ali&i
  1765. .cref
  1766. ?ali&i &macro
  1767. ?ap <n>
  1768. &endm
  1769. endm
  1770. ;; ?ap - process arguments and place onto stack
  1771. ;;
  1772. ;; The given argument is processed (type checking) and place on
  1773. ;; the stack for a pending call. There must be a type definition
  1774. ;; for all arguments (except words). This can be done by using
  1775. ;; text equates and the defx macro.
  1776. ;;
  1777. ;; format:
  1778. ;; ?ap n
  1779. ;; where:
  1780. ;; n is the name of the argument to be pushed
  1781. ;;
  1782. ;; The variable ?argl is updated by the length of the arguments
  1783. ;; pushed so that the stack can be cleaned up after the call.
  1784. ?ap macro n
  1785. ?argl=?argl+2 ;;assume one word is pushed
  1786. ifdef ?t&n
  1787. ife ?t&n-1 ;;byte type
  1788. push word ptr (n) ;@
  1789. exitm
  1790. endif
  1791. ife ?t&n-2 ;;word type
  1792. push n ;@
  1793. exitm
  1794. endif
  1795. ife ?t&n-4 ;;dword type
  1796. push word ptr (n)[2] ;@
  1797. push word ptr (n) ;@
  1798. ?argl=?argl+2
  1799. exitm
  1800. endif
  1801. ife ?t&n-8 ;;qword type
  1802. push word ptr (n)[6] ;@
  1803. push word ptr (n)[4] ;@
  1804. push word ptr (n)[2] ;@
  1805. push word ptr (n) ;@
  1806. ?argl=?argl+6
  1807. exitm
  1808. endif
  1809. if ?t&n and 80h ;;far pointer type
  1810. n
  1811. ?argl=?argl+2
  1812. exitm
  1813. endif
  1814. ife ?t&n ;;variable storage
  1815. push word ptr (n) ;@
  1816. exitm
  1817. endif
  1818. endif
  1819. push n ;;unknown or register or immediate ;@
  1820. endm
  1821. ;; cCall - call a 'c' language procedure
  1822. ;;
  1823. ;; The given procedure is called with the given parameters.
  1824. ;; If the calling convention is C, the arguments are pushed
  1825. ;; in reverse order, and removed after the called procedure
  1826. ;; returns. If the calling conventing is PL/M, the arguments
  1827. ;; are pushed as they were encountered, and the called procedure
  1828. ;; is assumed to have removed them from the stack.
  1829. ;;
  1830. ;; The calling convention priority will be:
  1831. ;; 1) that specified on the cCall if present
  1832. ;; 2) that defined by the target
  1833. ;; 3) the default (?PLM flag)
  1834. ;;
  1835. ;; format:
  1836. ;; ccall n,<a>,c
  1837. ;;
  1838. ;; where:
  1839. ;; n is the name of the procedure to call
  1840. ;; a are arguments to be pushed (optional, may be
  1841. ;; specified with the "arg" macro.
  1842. ;; c is the convention, C for C, PLM or PSACAL for PL/M.
  1843. ;; The default (?PLM flag) will be used if not specified.
  1844. cCall macro n,a,c
  1845. ifnb <a> ;;add any arguments to list
  1846. arg <a>
  1847. endif
  1848. mpush %?rsl ;;save registers (if any)
  1849. ifdef ?CC&n ;;if calling convention has been
  1850. ?cCall1=?CC&n ;; defined for target, use it
  1851. else ;;else use the default
  1852. ?cCall1=?PLM
  1853. endif
  1854. ifnb <c> ;;If possible override, check it out
  1855. ?gcc ?cCall1,%?cCall1,<c>
  1856. endif
  1857. ?argl=0 ;;init argument length
  1858. ife ?cCall1 ;;if C calling convention
  1859. ?acb=?argc ;;initialize for looping
  1860. else
  1861. ?acb=1 ;;initialize for looping
  1862. endif
  1863. rept ?argc ;;push arguments and purge macros
  1864. uconcat <?ali>,%?acb
  1865. uconcat <purge>,,<?ali>,%?acb
  1866. ife ?cCall1 ;;if C calling convention
  1867. ?acb=?acb-1
  1868. else
  1869. ?acb=?acb+1
  1870. endif
  1871. endm
  1872. call n ;;call the procedure ;@
  1873. if ((?cCall1 eq 0) and (?argl ne 0)) ;;If C calling convention and arguments
  1874. add sp,?argl ;; then remove them ;@
  1875. endif
  1876. mpop %?rsl ;;pop all specified regs
  1877. ?rsl=0 ;;invalidate save list
  1878. ?argc= 0 ;; " arguments
  1879. ?argl= 0
  1880. endm
  1881. ;; cProc - define a 'c' procedure
  1882. ;;
  1883. ;; cProc is the procedure definition for procedures.
  1884. ;;
  1885. ;; format:
  1886. ;; cProc n,cf,a
  1887. ;; where:
  1888. ;; n is the name of the procedure
  1889. ;;
  1890. ;; cf controls certain definitions, and may be:
  1891. ;; NEAR proc is to be a near label
  1892. ;; FAR proc is to be a far label
  1893. ;; PUBLIC proc is to be defined as public
  1894. ;; SMALL call makeframe procedure
  1895. ;; NODATA dont create prolog code to setup DS
  1896. ;; ATOMIC don't link stack if not needed
  1897. ;; NODATA must be specified for ATOMIC
  1898. ;; FORCEFRAME Force generation of a frame
  1899. ;; C proc is to be a C procedure
  1900. ;; PLM proc is to be a PL/M procedure
  1901. ;; PASCAL proc is to be a PL/M procedure
  1902. ;; WIN proc is to be a windows procedure
  1903. ;; NONWIN proc isn't to be a windows procedure
  1904. ;; NO_BP don't generate BP in text equates
  1905. ;; BP generate BP in text equates
  1906. ;;
  1907. ;; a is a list of registers that are to be saved whenever
  1908. ;; the procedure is invoked.
  1909. ;;
  1910. ;; makeframe procedure: If small is specified, then
  1911. ;; the "makeframe procedure" is invoked instead of
  1912. ;; generating normal prologues/epilogues
  1913. ;;
  1914. ;; A call is performed to the makeframe procedure. The
  1915. ;; call is followed by two bytes. the first byte is the
  1916. ;; number of locals to allocate for the frame, the second
  1917. ;; is the number of bytes of parameters. The makeframe
  1918. ;; procedure will in turn call the cProc routine at the
  1919. ;; address following the data bytes. When the cProc is
  1920. ;; finished, it will do a near return to the makeframe
  1921. ;; procedure to clean up the frame and exit.
  1922. ;;
  1923. ;; Note that register parameters and makeframe are
  1924. ;; incompatible and cannot be used together.
  1925. ;;
  1926. ;; The makeframe procedure will save SI, DI, and also
  1927. ;; DS if a far procedure. These registers will be
  1928. ;; removed from the autosave list if specified.
  1929. cProc macro n,cf,a
  1930. if ?cpd
  1931. ?utpe ;;generate unterminated proc error
  1932. endif
  1933. ?cpd=1 ;;a procdef is active now
  1934. ???=0 ;;no locals are defined yet
  1935. ?argc=0 ;;no arguments are defined
  1936. ?ba=0 ;;not in a procedure
  1937. ?po=0 ;;initial parameter offset
  1938. ?pu=0 ;;initial public setting
  1939. ?ia=0 ;;no special prolog/epilog
  1940. ?adj=2*sizeI ;;parameter adjustment (near ret+bp)
  1941. ?rp=0 ;;no register parameters
  1942. ?uf=0 ;;don't use makeframe
  1943. ?wfp=?WIN ;;default far procedure (win or not)
  1944. ?ff=0 ;;don't force frame setup
  1945. ?pas=0 ;;process register save list
  1946. ?pcc=?PLM ;;calling convention (C or PL/M)
  1947. ?no_bp2=?no_bp1 ;;Default base register generation
  1948. ifnb <a> ;;register save list
  1949. ?ri ?pas,<a>
  1950. endif
  1951. ?pc=sizec ;;default size
  1952. ?nd=?nodata1 ;;default NODATA flag
  1953. ?nx=0 ;;default is not ATOMIC
  1954. irp x,<cf>
  1955. ifdef ??_cproc_&&x
  1956. ??_cproc_&&x
  1957. else
  1958. ??error2 <e r r o r - unknown keyword x>
  1959. .err
  1960. endif
  1961. endm
  1962. if ?pcc ;;If PLM
  1963. ?PLMPrevParm=0 ;; show no previous parameter
  1964. .xcref
  1965. .xcref ?PLMParm0
  1966. .cref
  1967. ?PLMParm0 &macro ;;Null macro to terminate
  1968. purge ?PLMParm0
  1969. &endm
  1970. endif
  1971. .xcref
  1972. .xcref ?CC&n
  1973. .cref
  1974. ?CC&n=?pcc ;;Save procedure type
  1975. if (?nx eq 1) and (?nd eq 0) ;;ATOMIC requires NODATA
  1976. ?nx = 0 ;;clear the ATOMIC keyword
  1977. ??error2 <ATOMIC specified without NODATA - ATOMIC ignored>
  1978. endif
  1979. if ?pc ;;if a far procedure
  1980. if ?wfp ;;if windows
  1981. ife ?nx ;;if not ATOMIC
  1982. ife ?COW ;; COW dos not save DS
  1983. ?ia=2 ;; adjust locals for saved ds
  1984. ?pas = ?pas and (not ?ds) ;;no need for extra save
  1985. endif
  1986. endif
  1987. endif
  1988. ?adj=?adj+sizeI ;;far, make parameter adjustment
  1989. else
  1990. ?wfp=0 ;;not a far windows procedure
  1991. endif
  1992. ?pas = ?pas and (not (?sp+?cs+?ss)) ;;make no sense to save these
  1993. if ?uf ;;don't save these if user frame
  1994. ?pas = ?pas and (not (?bp+?si+?di))
  1995. endif
  1996. ife ?pcc
  1997. ?pg <_&n>,%?pu,%?pc,%?pas,%?wfp,<n>,%?pcc
  1998. else
  1999. ?pg <n>,%?pu,%?pc,%?pas,%?wfp,<n>,%?pcc
  2000. endif
  2001. endm
  2002. ;; ?pg - generate begin and nested macros for current procedure
  2003. ;;
  2004. ;; format:
  2005. ;; ?pg n,p,c,a,w,nnu,cc
  2006. ;; where:
  2007. ;; n is the name of the procedure
  2008. ;; p is the public flag
  2009. ;; c is the class definition for the procedure
  2010. ;; a is an enumerated list of registers to save
  2011. ;; at entry and restore at exit
  2012. ;; w true if a far windows procedure
  2013. ;; nnu procedure name without any underscore
  2014. ;; cc calling convention (C or PL/M)
  2015. ;;
  2016. ;;
  2017. ;; local stack allocation will be forced to an even byte count to
  2018. ;; maintain stack word alignment.
  2019. ?pg macro n,p,c,a,w,nnu,cc
  2020. .xcref
  2021. if ?uf ;;if user frame
  2022. if ?nd
  2023. ??error2 <NODATA encountered in &n - user frame ignored>
  2024. ?uf=0
  2025. endif
  2026. endif
  2027. .xcref cBegin
  2028. cBegin &macro g ;;generate cBegin macro
  2029. .xcref
  2030. if cc ;;Finish definition of parameters
  2031. uconcat <?PLMParm>,%?PLMPrevParm,%?po
  2032. endif
  2033. if ?uf ;;if user frame
  2034. if ?rp ;;If register parameters
  2035. ??error2 <parmR encountered in &n - user frame ignored>
  2036. ?uf=0
  2037. endif
  2038. endif
  2039. ?pg1 <n>,c,a,%?po,w,%?uf,%?nd,%?rp,cc,<nnu>,%??? ;;generate cEnd macro
  2040. ?cpd=0 ;;terminate current proc def
  2041. ?argc=0 ;;no arguments are defined yet
  2042. ?ba=1 ;;have reached a begin
  2043. ???=(???+1) and 0fffeh ;;word align local storage
  2044. if p ;;If to be public
  2045. public n
  2046. endif
  2047. ife c ;;declare procedure type
  2048. n proc near
  2049. else
  2050. n proc far
  2051. endif
  2052. ife cc ;;if 'C' calling convention
  2053. nnu equ n ;; generate label without underscore
  2054. endif
  2055. ?cbe = 0 ;;Assume no command on cBegin line
  2056. ifnb <g>
  2057. ?pcbe <g>,<nnu>,<cBegin>
  2058. endif
  2059. if ?cbe eq 1 ;;if nogen, then cannot have locals
  2060. if ???+a+?rp ;; saved regs, or parmRs
  2061. if2
  2062. ??_out <cBegin - possibly invalid use of nogen>
  2063. endif
  2064. endif
  2065. else ;;else must generate a frame
  2066. if ?uf ;;if user frame code specified
  2067. ?mf c,%???,%?po ;; call user's makeframe
  2068. mpush a ;; save specified registers
  2069. else
  2070. ife ?cbe ;;If full frame to be set up
  2071. if w ;;if a far windows procedure
  2072. ife ?nd ;;if not NODATA,
  2073. mov IAX,ds ;; then set AX = current ds, and ;@
  2074. nop ;; leave room for MOV AX,1234h ;@
  2075. endif
  2076. ife ?nx ;;if not ATOMIC, far frame must be set
  2077. ife ?DOS5 ;;if not DOS5, then set far frame flag
  2078. inc IBP ;; by incrementing the old bp ;@
  2079. endif
  2080. push IBP ;@
  2081. mov IBP,ISP ;@
  2082. ife ?COW ;; save DS not needed for CW
  2083. push ds ;@
  2084. endif
  2085. else ;;ATOMIC procedure
  2086. if ?ff+???+?po+?rp ;;if any locals or parameters
  2087. push IBP ;; then must set frame pointer ;@
  2088. mov IBP,ISP ;; to be able to access them ;@
  2089. endif
  2090. endif
  2091. ife ?nd ;;if not NODATA, then AX should
  2092. mov ds,IAX ;; have the ds to use ;@
  2093. endif
  2094. else ;;not windows. use standard prolog
  2095. if ?ff+???+?po+?rp ;;if any locals or parameters
  2096. push IBP ;; then must set frame pointer ;@
  2097. mov IBP,ISP ;; to be able to access them ;@
  2098. endif
  2099. endif
  2100. if ?rp ;;if parmR's, push them before
  2101. ?uf=0 ;; allocating locals and saving
  2102. rept ?rp ;; the autosave registers
  2103. uconcat mpush,,?rp,%?uf
  2104. ?uf=?uf+1
  2105. endm
  2106. endif
  2107. if ??? ;;if locals to allocate
  2108. if ?chkstk1 ;;if stack checking enabled
  2109. ifdef ?CHKSTKPROC ;;if user supplied stack checking
  2110. ?CHKSTKPROC %??? ;; invoke it with bytes requested
  2111. else
  2112. mov IAX,??? ;;invoke default stack checking ;@
  2113. ife cc
  2114. call _chkstk ;@
  2115. else
  2116. call chkstk ;@
  2117. endif
  2118. endif
  2119. else ;;no stack checking
  2120. sub ISP,??? ;; allocate any local storage ;@
  2121. endif
  2122. endif
  2123. else ;;partial frame, only set locals
  2124. if ?rp ;;If parmRs, error
  2125. ??error2 <cBegin - parmRs encountered with partial frame>
  2126. else
  2127. if ??? ;;Only realloc frame if locals
  2128. lea ISP,[IBP][-???-?ia] ;;?ia will adjust for saved BP ;@
  2129. endif
  2130. endif
  2131. endif
  2132. mpush a ;;save autosave registers
  2133. endif
  2134. ifdef ?PROFILE ;;if profiling enabled
  2135. if c ;; and a far procedure
  2136. call StartNMeas ;; invoke profile start procedure ;@
  2137. endif
  2138. endif
  2139. endif
  2140. .cref
  2141. purge cBegin ;;remove the macro
  2142. &endm ;;end of cBegin macro
  2143. .xcref ?utpe
  2144. ?utpe &macro
  2145. ??error2 <unterminated procedure definition: "&n">
  2146. &endm
  2147. .cref
  2148. endm ;;end of ?pg macro
  2149. ;; ?pg1 - generate end macro for current procedure
  2150. ;;
  2151. ;; format:
  2152. ;; ?pg1 n,c,a,o,w,f,d,r,cc,nnu,lc
  2153. ;; where:
  2154. ;; n is the name of the procedure
  2155. ;; c is the class definition for the procedure
  2156. ;; a is an enumerated list of registers to save
  2157. ;; at entry and restore at exit
  2158. ;; o is the number of bytes of paramteres to remove at exit
  2159. ;; w true if a far windows procedure
  2160. ;; f is 1 if to use the user's makeframe procedure
  2161. ;; d is 1 if NODATA procedure
  2162. ;; r number of register parameters
  2163. ;; cc calling convention (C or PL/M)
  2164. ;; nnu procedure name without any underscore
  2165. ;; lc locals byte count
  2166. ?pg1 macro n,c,a,o,w,f,d,r,cc,nnu,lc
  2167. .xcref
  2168. .xcref cEnd
  2169. parm_bytes_&nnu = o ;;Define number of parameter bytes
  2170. cEnd &macro g ;;start of cEnd macro
  2171. .xcref
  2172. ?ba=0 ;;no longer in a procedure
  2173. ?cbe = 0 ;;Assume no command on cBegin line
  2174. ifnb <g>
  2175. ?pcbe <g>,<nnu>,<cEnd>
  2176. endif
  2177. if ?cbe eq 1 ;;if nogen, then cannot have parmRs
  2178. if a+r+lc ;; locals, or saved registers
  2179. if2
  2180. ??_out <cEnd - possibly invalid use of nogen>
  2181. endif
  2182. endif
  2183. else ;;else must remove the frame
  2184. ifdef ?PROFILE ;;if profiling enabled
  2185. if c ;; and a far procedure
  2186. call StopNMeas ;; invoke profile stop procedure
  2187. endif ;; (doesn't trash DX:AX)
  2188. endif
  2189. mpop a ;;restore autosaved registers
  2190. if f ;;if to use the "makeframe" procedure
  2191. db 0c3h ;; near return to user's makeframe @
  2192. else
  2193. if w ;;if far win proc, use special epilog
  2194. ife ?nx ;;if not ATOMIC, bp was pushed
  2195. ife ?COW ;; restore DS not needed for CW
  2196. if (?TF eq 0) or (???+r) ;;if cannot assume valid sp
  2197. lea sp,-2[bp] ;; or locals or parmR's, get valid SP @
  2198. endif
  2199. pop ds ;;restore saved ds and bp @
  2200. else
  2201. if (?TF eq 0) or (???+r) ;;if cannot assume valid sp
  2202. mov sp,bp
  2203. endif
  2204. endif
  2205. pop IBP ;; @
  2206. ife ?DOS5 ;;if not DOS5, bp was
  2207. dec IBP ;; incremented to mark far frame @
  2208. endif
  2209. else ;;ATOMIC frame was set up
  2210. if memS32
  2211. leave
  2212. else
  2213. if (?TF eq 0) or (???+r) ;;if cannot assume valid sp
  2214. mov ISP,IBP ;; or locals or parmR's, get valid SP @
  2215. endif
  2216. if ???+?po+r
  2217. pop IBP ;@
  2218. endif
  2219. endif
  2220. endif
  2221. else ;;non-windows standard epilog
  2222. if ?ff+???+?po+r ;;if any parameters
  2223. if (?TF eq 0) or (???+r) ;;if cannot assume valid SP
  2224. mov ISP,IBP ;; or locals or parmR's, get valid SP;@
  2225. endif
  2226. pop IBP ;@
  2227. endif
  2228. endif
  2229. if ?cbe ne 4 ;;Don't generate ret if ??cleanframe?? e
  2230. ife cc ;;if C calling convention
  2231. ret ;; return ;@
  2232. else ;;else
  2233. ret o ;; return and remove paramteres ;@
  2234. endif
  2235. endif
  2236. endif
  2237. endif
  2238. if ?cbe ne 4 ;;Don't delete macro if ??cleanframe?? e
  2239. n endp ;;end of process
  2240. .cref
  2241. purge cEnd ;;remove the macro
  2242. else
  2243. .cref
  2244. endif
  2245. &endm
  2246. .cref
  2247. endm
  2248. ;; cleanframe
  2249. ;;
  2250. ;; cleanframe removes a cMacros generated frame, invoking cEnd
  2251. ;; with a special keyword which will keep the cEnd macro from
  2252. ;; generating a return statement and purging itself.
  2253. .xcref
  2254. .xcref cleanframe
  2255. cleanframe macro
  2256. cEnd <??cleanframe??>
  2257. endm
  2258. .cref
  2259. ;; The following macros are used to speed up the processing of the
  2260. ;; command allowed on a cProc command line. They simply set or clear
  2261. ;; the correct flag as needed.
  2262. .xcref
  2263. .xcref ??_cproc_FAR,??_cproc_NEAR,??_cproc_PUBLIC,??_cproc_SMALL
  2264. .xcref ??_cproc_DATA,??_cproc_NODATA,??_cproc_ATOMIC,??_cproc_C
  2265. .xcref ??_cproc_PLM,??_cproc_PASCAL,??_cproc_WIN,??_cproc_NONWIN
  2266. .xcref ??_cproc_NO_BP,??_cproc_BP
  2267. .xcref ??_cproc_far,??_cproc_near,??_cproc_public,??_cproc_small
  2268. .xcref ??_cproc_data,??_cproc_nodata,??_cproc_atomic,??_cproc_c
  2269. .xcref ??_cproc_plm,??_cproc_pascal,??_cproc_win,??_cproc_nonwin
  2270. .xcref ??_cproc_no_bp,??_cproc_bp
  2271. .cref
  2272. ??_cproc_FAR macro
  2273. ?pc=1
  2274. endm
  2275. ??_cproc_NEAR macro
  2276. ?pc=0
  2277. endm
  2278. ??_cproc_PUBLIC macro
  2279. ?pu=1
  2280. endm
  2281. ??_cproc_SMALL macro
  2282. ?uf=1
  2283. endm
  2284. ??_cproc_DATA macro
  2285. ?nd=0
  2286. endm
  2287. ??_cproc_NODATA macro
  2288. ?nd=1
  2289. endm
  2290. ??_cproc_ATOMIC macro
  2291. ?nx=1
  2292. endm
  2293. ??_cproc_C macro
  2294. ?pcc=0
  2295. endm
  2296. ??_cproc_PLM macro
  2297. ?pcc=1
  2298. endm
  2299. ??_cproc_PASCAL macro
  2300. ?pcc=1
  2301. endm
  2302. ??_cproc_WIN macro
  2303. ?wfp=1
  2304. endm
  2305. ??_cproc_NONWIN macro
  2306. ?wfp=0
  2307. endm
  2308. ??_cproc_NO_BP macro
  2309. ?no_bp2=1
  2310. endm
  2311. ??_cproc_BP macro
  2312. ?no_bp2=0
  2313. endm
  2314. ??_cproc_far macro
  2315. ?pc=1
  2316. endm
  2317. ??_cproc_near macro
  2318. ?pc=0
  2319. endm
  2320. ??_cproc_public macro
  2321. ?pu=1
  2322. endm
  2323. ??_cproc_small macro
  2324. ?uf=1
  2325. endm
  2326. ??_cproc_data macro
  2327. ?nd=0
  2328. endm
  2329. ??_cproc_nodata macro
  2330. ?nd=1
  2331. endm
  2332. ??_cproc_atomic macro
  2333. ?nx=1
  2334. endm
  2335. ??_cproc_c macro
  2336. ?pcc=0
  2337. endm
  2338. ??_cproc_plm macro
  2339. ?pcc=1
  2340. endm
  2341. ??_cproc_pascal macro
  2342. ?pcc=1
  2343. endm
  2344. ??_cproc_win macro
  2345. ?wfp=1
  2346. endm
  2347. ??_cproc_nonwin macro
  2348. ?wfp=0
  2349. endm
  2350. ??_cproc_no_bp macro
  2351. ?no_bp2=1
  2352. endm
  2353. ??_cproc_bp macro
  2354. ?no_bp2=0
  2355. endm
  2356. ; ?pcbe is the macro which processes the text on cBegin/cEnd
  2357. ; The text is allowed to be:
  2358. ;
  2359. ; NOGEN nogen
  2360. ; PARTIAL partial
  2361. ; the procedure name as given on the cProc line
  2362. ;
  2363. ; usage:
  2364. ; ?pcbe <g>,<nnu>,<mt>
  2365. ; where:
  2366. ; g is the text on the cBegin/cEnd line
  2367. ; nnu is the procedure name without any underscores
  2368. ; mt macro type (cBegin/cEnd)
  2369. ;
  2370. ; The variable ?cbe is set to the following value
  2371. ;
  2372. ; 0 = invalid (defualt action>
  2373. ; 1 = nogen
  2374. ; 2 = partial frame
  2375. ; 4 = clean frame
  2376. ?pcbe macro g,nnu,mt
  2377. ifidn <g>,<NOGEN>
  2378. ?cbe = 1
  2379. else
  2380. ifidn <g>,<nogen>
  2381. ?cbe = 1
  2382. else
  2383. ifidn <mt>,<cBegin>
  2384. ifidn <g>,<PARTIAL>
  2385. ?cbe = 2
  2386. else
  2387. ifidn <g>,<partial>
  2388. ?cbe = 2
  2389. else
  2390. ifdif <g>,<nnu>
  2391. ??error2 <mt - unknown keyword g>
  2392. endif
  2393. endif
  2394. endif
  2395. else
  2396. ifidn <g>,<??cleanframe??>
  2397. ?cbe = 4
  2398. else
  2399. ifdif <g>,<nnu>
  2400. ??error2 <mt - unknown keyword g>
  2401. endif
  2402. endif
  2403. endif
  2404. endif
  2405. endif
  2406. endm
  2407. ; assumes is a macro that will set up the assumes for a segment
  2408. ; or group created with the createSeg macro. If the assumed
  2409. ; value passed in isn't known, then a normal assume is made.
  2410. ;
  2411. ; usage:
  2412. ; assumes s,g
  2413. ;
  2414. ; where:
  2415. ; s is the register to make the assumption about
  2416. ; g is the value to assume is in it
  2417. ;
  2418. ; as a hack, substitute FLAT for g if memF32 is set
  2419. assumes macro s,ln
  2420. if memF32
  2421. assume s:FLAT
  2422. endif
  2423. ife memF32
  2424. ifndef ln&_assumes
  2425. assume s:ln
  2426. else
  2427. ln&_assumes s
  2428. endif
  2429. endif
  2430. endm
  2431. ; createSeg is a macro that sets up a segment definition and
  2432. ; a logical name for that segment. The logical name can be
  2433. ; used to enter the segment, but it cannot be used for anything
  2434. ; else.
  2435. ;
  2436. ; usage:
  2437. ; createSeg n,ln,a,co,cl,grp
  2438. ; where:
  2439. ; n is the physical name of the segment
  2440. ; ln is the name it is to be invoked by
  2441. ; a is the alignment, and is optional
  2442. ; co is the combine type, and is optional
  2443. ; cl is the class, and is optional
  2444. ; grp is the name of the group that contains this segment
  2445. createSeg macro n,ln,a,co,cl,grp
  2446. ifnb <cl>
  2447. n segment a co '&cl'
  2448. else
  2449. n segment a co
  2450. endif
  2451. n ends
  2452. ifnb <grp>
  2453. addseg grp,n
  2454. else
  2455. ln&OFFSET equ offset n:
  2456. ln&BASE equ n
  2457. ?cs3 <ln>,<n>
  2458. endif
  2459. ?cs1 <ln>,<n>
  2460. endm
  2461. addseg macro grp,seg
  2462. .xcref
  2463. .xcref grp&_def
  2464. .cref
  2465. ifndef grp&_def
  2466. grp&_def=0
  2467. endif
  2468. if grp&_def ne ASMpass
  2469. .xcref
  2470. .xcref grp&_add
  2471. .cref
  2472. grp&_add &macro s
  2473. grp&_in <seg>,s
  2474. &endm
  2475. .xcref
  2476. .xcref grp&_in
  2477. .cref
  2478. grp&_in &macro sl,s
  2479. ifb <s>
  2480. grp group sl
  2481. else
  2482. grp&_add &macro ns
  2483. grp&_in <sl,s>,ns
  2484. &endm
  2485. endif
  2486. &endm
  2487. grp&_def=ASMpass
  2488. else
  2489. grp&_add seg
  2490. endif
  2491. endm
  2492. defgrp macro grp,ln
  2493. addseg grp
  2494. ifnb <ln>
  2495. irp x,<ln>
  2496. ?cs3 <&x>,<grp>
  2497. x&&OFFSET equ offset grp:
  2498. x&&BASE equ grp
  2499. endm
  2500. endif
  2501. endm
  2502. ?cs1 macro ln,n
  2503. .xcref
  2504. .xcref ln&_sbegin
  2505. .cref
  2506. ln&_sbegin &macro
  2507. .xcref
  2508. .xcref ?mf
  2509. .cref
  2510. ?mf &&macro c,l,p ;;when sBegin is invoked, generate
  2511. if c ;; the makeframe macro
  2512. extrn n&_FARFRAME:near ;; make frame for far procedures ;@
  2513. call n&_FARFRAME ;@
  2514. else
  2515. extrn n&_NEARFRAME:near ;; make frame for near procedures ;@
  2516. call n&_NEARFRAME ;@
  2517. endif
  2518. db l shr 1 ;;define number of locals ;@
  2519. db p shr 1 ;;define number of parameters ;@
  2520. &&endm
  2521. ?cs2 <ln>,<n>
  2522. n segment
  2523. &endm
  2524. endm
  2525. ?cs2 macro ln,n
  2526. .xcref
  2527. .xcref sEnd
  2528. .cref
  2529. sEnd &macro
  2530. n ends
  2531. purge ?mf ;;delete the makeframe macro
  2532. purge sEnd
  2533. &endm
  2534. endm
  2535. ?cs3 macro ln,n
  2536. .xcref
  2537. .xcref ln&_assumes
  2538. .cref
  2539. ln&_assumes &macro s
  2540. assume s:&n
  2541. &endm
  2542. endm
  2543. ; sBegin is the macro that opens up the definition of a segment.
  2544. ; The segment must have already been defined with the createSeg
  2545. ; macro.
  2546. ;
  2547. ; usage:
  2548. ; sBegin ln
  2549. ;
  2550. ; where:
  2551. ; ln is the logical name given to the segment when
  2552. ; it was declared.
  2553. .xcref
  2554. .xcref sBegin
  2555. .cref
  2556. sBegin macro ln
  2557. ln&_sbegin
  2558. endm
  2559. BeginDATA macro
  2560. ife memF32
  2561. sBegin DATA
  2562. else
  2563. .data
  2564. endif
  2565. endm
  2566. BeginCODE macro
  2567. ife memF32
  2568. sBegin CODE
  2569. else
  2570. .code
  2571. endif
  2572. endm
  2573. EndDATA macro
  2574. ife memF32
  2575. sEnd DATA
  2576. endif
  2577. endm
  2578. EndCODE macro
  2579. ife memF32
  2580. sEnd CODE
  2581. endif
  2582. endm
  2583. ife ?DF
  2584. ; Define all segments that will be used. This will allow the
  2585. ; assume and groups to be set up at one given place, and also
  2586. ; allow quick changes to be made
  2587. ;
  2588. ; createSeg name,logname,align,combine,class,group
  2589. ife ?DFCODE
  2590. createSeg _TEXT,CODE,%wordI,public,CODE
  2591. endif
  2592. ife ?nodata1
  2593. createSeg _DATA,DATA,%wordI,public,DATA,DGROUP
  2594. defgrp DGROUP,DATA
  2595. else
  2596. ife ?DFDATA
  2597. createSeg _DATA,DATA,%wordI,public,DATA,DGROUP
  2598. defgrp DGROUP,DATA
  2599. endif
  2600. endif
  2601. if ?chkstk1
  2602. ifndef ?CHKSTKPROC
  2603. externp <chkstk>
  2604. endif
  2605. endif
  2606. endif
  2607. ; errnz exp - generate error message if expression isn't zero
  2608. ;
  2609. ; The errnz will generate an error message if the expression "exp"
  2610. ; does not evaluate to zero. This macro is very useful for testing
  2611. ; relationships between items, labels, and data that was coded into
  2612. ; an application.
  2613. ;
  2614. ; errnz <offset $ - offset label> ;error if not at "label"
  2615. ; errnz <eofflag and 00000001b> ;eofflag must be bit 0
  2616. ;
  2617. ; For expressions involving more than one token, the angle brackets
  2618. ; must be used.
  2619. ;
  2620. ; The macro is only evaluated on pass 2, so forward references may be
  2621. ; used in the expression.
  2622. errnz macro x ;;display error if expression is <>0
  2623. if2
  2624. if x ;;if expression is non-zero,
  2625. errnz1 <x>,%(x)
  2626. endif
  2627. endif
  2628. endm
  2629. errnz1 macro x1,x2
  2630. = *errnz* x1 = x2
  2631. .err
  2632. endm
  2633. ; errn$ label,exp - generate error message if label (exp) <> $
  2634. ;
  2635. ; The errnz will generate an error message if the label and "exp"
  2636. ; does not evaluate to the current value of the location counter.
  2637. ; This macro is very useful for testing relationships between
  2638. ; labels and the location counter that was coded into an application.
  2639. ;
  2640. ; examples: errn$ label ;error if not at "label"
  2641. ; errn$ label,+3 ;error if not three bytes from "label"
  2642. ; errn$ label,-3 ;error if not three bytes past "label"
  2643. ;
  2644. ; If no "exp" is given, it is the same as specifying 0
  2645. ;
  2646. ; The macro is only evaluated on pass 2, so forward references may be
  2647. ; used in the expression.
  2648. errn$ macro l,x ;;error if <$-label1 (exp2)> <>0
  2649. errnz <offset $ - offset l x>
  2650. endm
  2651. ;; If profile has been specified, declare the profile routines
  2652. ;; to be external and far. It would be best if this could be done
  2653. ;; when the call is actually made, but then the fix-up would be
  2654. ;; generated as segment-relative.
  2655. ifdef ?PROFILE
  2656. externFP <StartNMeas,StopNMeas>
  2657. endif
  2658. if memF32
  2659. .model small
  2660. endif