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.

306 lines
5.3 KiB

  1. /* asmmac.c -- microsoft 80x86 assembler
  2. **
  3. ** microsoft (r) macro assembler
  4. ** copyright (c) microsoft corp 1986. all rights reserved
  5. **
  6. ** randy nevin
  7. **
  8. ** 10/90 - Quick conversion to 32 bit by Jeff Spencer
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "asm86.h"
  13. #include "asmfcn.h"
  14. #include "asmctype.h"
  15. /*** macrodefine - define a macro
  16. *
  17. * macrodefine ();
  18. *
  19. * Entry
  20. * Exit
  21. * Returns
  22. * Calls
  23. */
  24. VOID PASCAL CODESIZE
  25. macrodefine ()
  26. {
  27. checkRes();
  28. if (!symFet ()) {
  29. /* Need to make it */
  30. symcreate (M_DEFINED | M_BACKREF, MACRO);
  31. }
  32. if (symptr->symkind != MACRO)
  33. errorn (E_SDK);
  34. else {
  35. crefdef ();
  36. /* Save ptr to macro entry */
  37. macroptr = symptr;
  38. /* Make param record */
  39. createMC (0);
  40. BACKC ();
  41. do {
  42. SKIPC ();
  43. scandummy ();
  44. } while (PEEKC () == ',');
  45. macroptr->symu.rsmsym.rsmtype.rsmmac.parmcnt = (unsigned char)pMCur->count;
  46. pMCur->count = 0;
  47. localflag = TRUE; /* LOCAL is legal */
  48. swaphandler = TRUE;
  49. handler = HMACRO;
  50. blocklevel = 1;
  51. }
  52. }
  53. /*** macrobuild - build body of macro
  54. *
  55. * macrobuild ();
  56. *
  57. * Entry
  58. * Exit
  59. * Returns
  60. * Calls
  61. */
  62. VOID PASCAL CODESIZE
  63. macrobuild ()
  64. {
  65. #ifdef BCBOPT
  66. if (fNotStored)
  67. storelinepb ();
  68. #endif
  69. if (localflag) { /* Still legal, check */
  70. getatom ();
  71. if (fndir () && optyp == TLOCAL) {
  72. /* Have LOCAL symlist */
  73. BACKC ();
  74. do {
  75. SKIPC ();
  76. scandummy ();
  77. } while (PEEKC () == ',');
  78. listline ();
  79. return;
  80. }
  81. lbufp = lbuf;
  82. macroptr->symu.rsmsym.rsmtype.rsmmac.lclcnt = (unsigned char)pMCur->count;
  83. swaphandler = TRUE;
  84. handler = HIRPX;
  85. }
  86. irpxbuild ();
  87. }
  88. /*** macrocall - process macro call
  89. *
  90. * macrocall ();
  91. *
  92. * Entry
  93. * Exit
  94. * Returns
  95. * Calls
  96. */
  97. #if !defined XENIX286 && !defined FLATMODEL
  98. # pragma check_stack+
  99. #endif
  100. VOID PASCAL CODESIZE
  101. macrocall ()
  102. {
  103. register USHORT cc;
  104. SHORT cbParms;
  105. SYMBOL FARSYM *macro;
  106. static char nullParm[1] = {0};
  107. #ifdef BCBOPT
  108. if (fNotStored)
  109. storelinepb ();
  110. #endif
  111. macro = symptr; /* Ptr to macro entry */
  112. crefnew (REF);
  113. /* Create param area */
  114. optyp = TMACRO;
  115. cbParms = macro->symu.rsmsym.rsmtype.rsmmac.parmcnt;
  116. createMC ((USHORT)(cbParms + macro->symu.rsmsym.rsmtype.rsmmac.lclcnt));
  117. while (--cbParms >= 0) {
  118. /* extract ' ' or ',' terminated parameter */
  119. scanparam (FALSE);
  120. /* check for proper termination parameter termination */
  121. if (((cc = PEEKC ()) != ',') && !ISBLANK (cc) && !ISTERM (cc)) {
  122. errorcSYN ();
  123. SKIPC ();
  124. }
  125. if (ISTERM (cc = skipblanks ()))
  126. break;
  127. if (cc == ',')
  128. SKIPC ();
  129. }
  130. pMCur->pTSCur = pMCur->pTSHead = macro->symu.rsmsym.rsmtype.rsmmac.macrotext; ;
  131. for (cc = pMCur->count;
  132. cc < macro->symu.rsmsym.rsmtype.rsmmac.parmcnt; cc++)
  133. pMCur->rgPV[cc].pActual = nullParm;
  134. pMCur->count = 1;
  135. pMCur->localBase = localbase;
  136. pMCur->iLocal = macro->symu.rsmsym.rsmtype.rsmmac.parmcnt;
  137. localbase += macro->symu.rsmsym.rsmtype.rsmmac.lclcnt;
  138. listline ();
  139. /* Start of macro text */
  140. macrolevel++;
  141. macro->symu.rsmsym.rsmtype.rsmmac.active++;
  142. pMCur->svcondlevel = (char)condlevel;
  143. pMCur->svlastcondon = (char)lastcondon;
  144. pMCur->svelseflag = elseflag;
  145. lineprocess (RMACRO, pMCur);
  146. if (!(--macro->symu.rsmsym.rsmtype.rsmmac.active))
  147. if (macro->symu.rsmsym.rsmtype.rsmmac.delete)
  148. deletemacro (macro);
  149. }
  150. #if !defined XENIX286 && !defined FLATMODEL
  151. # pragma check_stack-
  152. #endif
  153. /*** checkendm - check for ENDM on current line
  154. *
  155. * checkendm ();
  156. *
  157. * Entry
  158. * Exit
  159. * Returns
  160. * Calls
  161. */
  162. UCHAR PASCAL CODESIZE
  163. checkendm ()
  164. {
  165. char flag;
  166. getatomend ();
  167. if (PEEKC () == '&') { /* skip constructed name */
  168. while (PEEKC () == '&') {
  169. SKIPC ();
  170. getatomend ();
  171. }
  172. *naim.pszName = '\0';
  173. }
  174. if (PEEKC () == ':' || (naim.pszName[0] == '%' && naim.pszName[1] == 0)) {
  175. SKIPC ();
  176. /* Skip over label */
  177. getatomend ();
  178. }
  179. if (flag = (char)fndir ()) {
  180. }
  181. else if (ISBLANK (PEEKC ())) {
  182. /* Check for naim MACRO */
  183. getatomend ();
  184. flag = (char)fndir2 ();
  185. }
  186. if (flag) {
  187. if (opkind & BLKBEG)
  188. blocklevel++;
  189. else if (optyp == TENDM)
  190. blocklevel--;
  191. if (!blocklevel) {
  192. listline ();
  193. return (TRUE);
  194. }
  195. }
  196. return (FALSE);
  197. }
  198. /*** createMC - create parameter descriptor
  199. */
  200. VOID PASCAL CODESIZE
  201. createMC (
  202. USHORT cParms
  203. ){
  204. register MC *pMC;
  205. SHORT cb;
  206. /* Create it */
  207. cb = sizeof(MC) - sizeof(PV) + sizeof(PV) * cParms;
  208. pMCur = pMC = (MC *) nalloc (cb, "creatMC");
  209. memset(pMC, 0, cb);
  210. pMC->flags = optyp;
  211. pMC->cbParms = (USHORT)(linebp - lbufp + 10);
  212. pMC->pParmNames = nalloc(pMC->cbParms, "macrodefine");
  213. pMC->pParmAct = pMC->pParmNames;
  214. *pMC->pParmAct = NULL;
  215. }
  216. /*** deleteMC - delete dummy and parameter lists
  217. *
  218. *
  219. * Entry pMC = parameter descriptor
  220. * Exit descriptor, dummy parameters and local parameters released
  221. * Returns
  222. * Calls
  223. */
  224. VOID PASCAL CODESIZE
  225. deleteMC (
  226. register MC *pMC
  227. ){
  228. if (pMC->flags <= TIRPC)
  229. free(pMC->pParmNames);
  230. free(pMC->pParmAct);
  231. free((char *) pMC);
  232. }
  233. VOID PASCAL CODESIZE
  234. listfree (
  235. TEXTSTR FAR *ptr
  236. ){
  237. TEXTSTR FAR *ptrnxt;
  238. while (ptr) {
  239. ptrnxt = ptr->strnext;
  240. tfree ((char FAR *)ptr, (USHORT)ptr->size);
  241. ptr = ptrnxt;
  242. }
  243. }