A68kmisc.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*------------------------------------------------------------------*/
  2. /* */
  3. /* MC68000 Cross Assembler */
  4. /* */
  5. /* Copyright 1985 by Brian R. Anderson */
  6. /* */
  7. /* Miscellaneous routines - May 23, 1992 */
  8. /* */
  9. /* This program may be copied for personal, non-commercial use */
  10. /* only, provided that the above copyright notice is included */
  11. /* on all copies of the source code. Copying for any other use */
  12. /* without the consent of the author is prohibited. */
  13. /* */
  14. /*------------------------------------------------------------------*/
  15. /* */
  16. /* Originally published (in Modula-2) in */
  17. /* Dr. Dobb's Journal, April, May, and June 1986. */
  18. /* */
  19. /* AmigaDOS conversion copyright 1991 by Charlie Gibbs. */
  20. /* */
  21. /*------------------------------------------------------------------*/
  22. #include "A68kdef.h"
  23. #include "A68kglb.h"
  24. char Sdata[MAXSREC]; /* S-record data */
  25. int Sindex; /* Index for Sdata */
  26. int NumRExt, NumR32, NumR16, NumR8;
  27. int NumA32, NumA16, NumA8; /* added by Kevin Kofler in v.2.71.F3l */
  28. static char *errmsg[] = {
  29. "--- Unknown error code ---",
  30. "Alignment error.",
  31. "No such op-code.",
  32. "Duplicate Symbol.",
  33. "Undefined Symbol.",
  34. "Addressing mode not allowed here.",
  35. "Error in operand format.",
  36. "Error in relative branch.",
  37. "Address mode error.",
  38. "Operand size error.",
  39. "END statement not allowed here.", /* replaces obsolete "END statement is
  40. missing." - Kevin Kofler, v.2.71.F3c */
  41. "Value must be absolute.",
  42. "Relocatability error.",
  43. "INCLUDE file cannot be opened.",
  44. "Illegal forward reference.",
  45. "Not supported in S-format.",
  46. "This instruction needs a label.",
  47. "Pass 1 / Pass 2 phase error.",
  48. "ENDM statement is missing.",
  49. "ENDC statement is missing.",
  50. "Unmatched ENDC statement.",
  51. "Too much DC data.",
  52. "Too many SECTIONs.",
  53. "Duplicate macro definition.",
  54. "More than one label on this line.",
  55. "End of string is missing.",
  56. "Short displacement can't be zero.",
  57. ""};
  58. long AddrBndW (v) register long v;
  59. /* Advances "v" to the next word boundary. */
  60. {
  61. if (v & 1L) {
  62. AppendSdata (0L, 1);
  63. v++;
  64. }
  65. return (v);
  66. }
  67. long AddrBndL (v) register long v;
  68. /* Advances "v" to the next long-word boundary. */
  69. {
  70. long templong;
  71. v = AddrBndW (v); /* Bump to a word boundary first. */
  72. if (v & 2L) { /* If still not aligned, */
  73. templong = NOP; /* generate a NOP. */
  74. AppendSdata (templong, 2);
  75. v += 2;
  76. }
  77. return (v);
  78. }
  79. void WriteListLine (f) struct fs *f;
  80. /* Writes one line to the Listing file, including Object Code. */
  81. {
  82. register int i, j, printed;
  83. long templong;
  84. char macflag;
  85. char tempstr[12];
  86. /* int dummy = 0; */ /* using now void in v.2.71.F3d - Kevin Kofler */
  87. if (!Pass2)
  88. return; /* Pass 2 only */
  89. if (FwdShort && (ErrLim == 0)) {
  90. DisplayLine (/*dummy*/ /*(using now void in v.2.71.F3d - Kevin Kofler)*/);
  91. printf ("A short branch can be used here.\n");
  92. }
  93. if (SuppList)
  94. return; /* Listing is suppresed. */
  95. if (ErrLim == 0)
  96. if ((Dir == Page) || (Dir == Space) || (Dir == Title)
  97. || (Dir == DoList) || (Dir == NoList) || (ListOff))
  98. return; /* Don't print unless they have errors. */
  99. CheckPage (f, FALSE); /* Print headings if necessary. */
  100. if (PrntAddr) {
  101. if ((Dir == Equ) || (Dir == Set))
  102. LongPut (f, ObjSrc, 3); /* Equated value */
  103. else
  104. LongPut (f, AddrCnt, 3); /* Current location */
  105. if (!KeepTabs)
  106. xputs (f, " ");
  107. } else
  108. if (!KeepTabs)
  109. xputs (f, " "); /* Don't print location. */
  110. if (KeepTabs)
  111. xputs (f, "\t"); /* Use tabs for spacing. */
  112. printed = 8; /* We've printed 8 positions. */
  113. LongPut (f, ObjOp, nO); /* Generated code */
  114. printed += nO * 2;
  115. if (nS != 0) {
  116. xputs (f, " ");
  117. LongPut (f, ObjSrc, nS);
  118. printed+= nS * 2 + 1;
  119. }
  120. if (nD != 0) {
  121. xputs (f, " ");
  122. LongPut (f, ObjDest, nD);
  123. printed += nD * 2 + 1;
  124. }
  125. if ((j = nX) > 0) { /* String data */
  126. if ((j * 2 + printed) > ObjMAX)
  127. j = (ObjMAX - printed) / 2;
  128. for (i = 0; i < j; i++) {
  129. templong = ObjString[i];
  130. LongPut (f, templong, 1);
  131. }
  132. printed += j * 2;
  133. }
  134. while (printed < ObjMAX) {
  135. if (KeepTabs) {
  136. xputs (f, "\t");
  137. printed += 8;
  138. printed &= ~7;
  139. } else {
  140. xputs (f, " ");
  141. printed++;
  142. }
  143. }
  144. if ((InFNum == 0) || (OuterMac == 0))
  145. macflag = ' '; /* Open code */
  146. else if (InFNum > OuterMac)
  147. macflag = '+'; /* Inner macro */
  148. else if ((InFNum == OuterMac) && (Dir != MacCall))
  149. macflag = '+'; /* Outermost macro */
  150. else
  151. macflag = ' '; /* We're outside macros. */
  152. sprintf (tempstr, " %5d%c", LineCount, macflag);
  153. xputs (f, tempstr);
  154. xputs (f, Line);
  155. xputs (f, "\n");
  156. if (FwdShort && (ErrLim == 0))
  157. xputs (f, "A short branch can be used here.\n");
  158. for (i = 0; i < ErrLim; i++) { /* Write error messages. */
  159. CheckPage (f, FALSE);
  160. xputs (f, errmsg[ErrCode[i]]);
  161. printed = strlen(errmsg[ErrCode[i]]);
  162. while (printed < ObjMAX + 8) {
  163. if (KeepTabs) {
  164. xputs (f, "\t");
  165. printed += 8;
  166. printed &= ~7;
  167. } else {
  168. xputs (f, " ");
  169. printed++;
  170. }
  171. }
  172. for (j = 0; j < ErrPos[i]; j++) {
  173. if (Line[j] == '\t') {
  174. xputs (f, "\t");
  175. printed += 8;
  176. printed &= ~7;
  177. } else {
  178. xputs (f, " ");
  179. printed++;
  180. }
  181. }
  182. xputs (f, "^ "); /* Error flag */
  183. if (i == 0) {
  184. if (InF->UPtr == 0)
  185. xputs (f, InF->NPtr); /* Module name */
  186. else
  187. xputs (f, "(user macro)"); /* We're in a user macro. */
  188. sprintf (tempstr, " line %d", InF->Line);
  189. xputs (f, tempstr); /* Line number */
  190. }
  191. xputs (f, "\n");
  192. }
  193. }
  194. void WriteSymTab (f) struct fs *f;
  195. /* Lists the symbol table in alphabetical order. */
  196. {
  197. int printhunk, i;
  198. char *p;
  199. char tempstr[MAXLINE];
  200. long templong;
  201. register int j, k;
  202. register struct SymTab **ss1, **ss2, *sym, **sortlim;
  203. struct Ref *ref;
  204. if (NumSyms == 0)
  205. return; /* The symbol table is empty - exit. */
  206. /* Build a sorted table of pointers to symbol table entries. */
  207. templong = NumSyms * sizeof (struct SymTab *);
  208. SymSort = (struct SymTab **) malloc ((unsigned) templong);
  209. if (SymSort == NULL) {
  210. fprintf (stderr, "Not enough memory for symbol table sort!\n");
  211. return;
  212. }
  213. sortlim = SymSort + NumSyms;
  214. sym = SymChunk = SymStart;
  215. sym++;
  216. SymChLim = (struct SymTab *) ((char *) SymChunk + CHUNKSIZE);
  217. ss1 = SymSort;
  218. while (sym) {
  219. *ss1++ = sym;
  220. sym = NextSym (sym); /* Try for another symbol table entry. */
  221. }
  222. for (i = NumSyms / 2; i > 0; i /= 2) { /* Shell sort */
  223. for (ss1 = SymSort + i; ss1 < sortlim; ss1++) { /* (copied */
  224. for (ss2=ss1-i; ss2 >= SymSort; ss2 -= i) { /* from K&R) */
  225. if (strcmp ((*ss2)->Nam, (*(ss2+i))->Nam) <= 0)
  226. break;
  227. sym = *ss2;
  228. *ss2 = *(ss2+i);
  229. *(ss2+i) = sym;
  230. }
  231. }
  232. }
  233. /* The table is now sorted - print the listing. */
  234. LnCnt = LnMax; /* Skip to a new page. */
  235. for (i = 0, ss1 = SymSort; i < NumSyms; i++) {
  236. sym = *ss1++;
  237. CheckPage (f, TRUE);
  238. p = sym->Nam; /* Pointer to symbol */
  239. if (sym->Flags & 8)
  240. p++; /* Skip blank preceding macro name. */
  241. else if (sym->Flags & 0x10)
  242. p += 6; /* Skip hunk sequence number. */
  243. sprintf (tempstr, "%-11s ", p); /* Symbol or macro name */
  244. xputs (f, tempstr);
  245. if (strlen (p) > 11) /* Long symbol - go to new line. */
  246. if (KeepTabs)
  247. xputs (f, "\n\t ");
  248. else
  249. xputs (f, "\n ");
  250. printhunk = FALSE; /* Assume no hunk no. to print. */
  251. if (sym->Defn == NODEF)
  252. xputs (f, " *** UNDEFINED *** ");
  253. else if (sym->Flags & 4)
  254. xputs (f, " -- SET Symbol -- ");
  255. else if (sym->Flags & 8) {
  256. sprintf (tempstr, " +++ MACRO +++ %5d", sym->Defn);
  257. xputs (f, tempstr);
  258. } else if (sym->Flags & 0x10) {
  259. j = (sym->Hunk & 0x3FFF0000L) >> 16;
  260. if (j == HunkCode)
  261. xputs (f, " CODE ");
  262. else if (j == HunkData)
  263. xputs (f, " DATA ");
  264. else
  265. xputs (f, " BSS ");
  266. printhunk = TRUE;
  267. } else if (sym->Flags & 0x20) {
  268. sprintf (tempstr, " %c%ld ",
  269. (sym->Val & 8L) ? 'A' : 'D', sym->Val & 7L);
  270. xputs (f, tempstr);
  271. printhunk = TRUE;
  272. } else {
  273. LongPut (f, sym->Val, 4); /* Value */
  274. xputs (f, " ");
  275. printhunk = TRUE;
  276. }
  277. if (printhunk) {
  278. j = sym->Hunk & 0x00007FFFL; /* Hunk number */
  279. if (sym->Flags & 0x60)
  280. xputs (f, " Reg"); /* Register or list */
  281. else if (sym->Flags & 1) {
  282. xputs (f, " Ext"); /* External */
  283. }
  284. else if (j == ABSHUNK)
  285. xputs (f, " Abs"); /* Absolute */
  286. else {
  287. sprintf (tempstr, "%4d", j); /* Hunk number */
  288. xputs (f, tempstr);
  289. }
  290. sprintf (tempstr," %5d",sym->Defn); /* Statement number */
  291. xputs (f, tempstr);
  292. }
  293. if (XrefList) {
  294. xputs (f, " ");
  295. if (sym->Ref1 == NULL)
  296. xputs (f, " *** UNREFERENCED ***");
  297. else {
  298. ref = sym->Ref1;
  299. j = k = 0;
  300. while (1) {
  301. if (ref->RefNum[j] == 0)
  302. break;
  303. if (k >= 9) {
  304. xputs (f, "\n"); /* New line */
  305. if (KeepTabs)
  306. xputs (f, "\t\t\t\t "); /* 34 spaces */
  307. else
  308. for (k = 0; k < 34; k++)
  309. xputs (f, " ");
  310. k = 0;
  311. }
  312. sprintf (tempstr, "%5d", ref->RefNum[j]);
  313. xputs (f, tempstr);
  314. j++;
  315. k++;
  316. if (j < MAXREF)
  317. continue; /* Get the next slot. */
  318. if ((ref = ref->NextRef) == 0)
  319. break; /* End of last entry */
  320. j = 0; /* Start the next entry. */
  321. }
  322. }
  323. }
  324. xputs (f, "\n");
  325. }
  326. free (SymSort); /* Free the sort work area. */
  327. SymSort = NULL;
  328. }
  329. void CheckPage (f, xhdr) struct fs *f; int xhdr;
  330. /* Checks if end of page reached yet -- if so, advances to next page. */
  331. {
  332. register int printed;
  333. char tempstr[12];
  334. LnCnt++;
  335. if (LnCnt >= LnMax) {
  336. PgCnt++;
  337. if (PgCnt > 1)
  338. xputs (f, "\f"); /* Skip to new page. */
  339. xputs (f, TTLstring); /* Title */
  340. printed = strlen (TTLstring);
  341. while (printed < 56)
  342. if (KeepTabs) {
  343. xputs (f, "\t");
  344. printed += 8;
  345. printed &= ~7;
  346. } else {
  347. xputs (f, " ");
  348. printed++;
  349. }
  350. xputs (f, SourceFN); /* File name */
  351. if (KeepTabs)
  352. xputs (f, "\t");
  353. else
  354. xputs (f, " ");
  355. sprintf(tempstr, "Page %d\n\n", PgCnt); /* Page number */
  356. xputs (f, tempstr);
  357. LnCnt = 2;
  358. if (xhdr) {
  359. xputs (f, "Symbol Value Hunk Line");
  360. if (XrefList)
  361. xputs (f, " References"); /* Cross-reference */
  362. xputs (f, "\n\n");
  363. LnCnt += 2;
  364. }
  365. }
  366. }
  367. void StartSrec (f, idntname) struct fs *f; char *idntname;
  368. /* Writes object header record. */
  369. {
  370. register long CheckSum, templong;
  371. register char *s;
  372. if (SFormat) {
  373. xputs (f, "S0");
  374. templong = strlen (idntname) + 3; /* extra for addr. & checksum */
  375. LongPut (f, templong, 1);
  376. CheckSum = templong;
  377. xputs (f, "0000"); /* Address is 4 digits, all zero, for S0. */
  378. s = idntname;
  379. while (*s) {
  380. templong = toupper (*s);
  381. LongPut (f, templong, 1);
  382. CheckSum += templong;
  383. s++;
  384. }
  385. CheckSum = ~CheckSum; /* Complement the checksum. */
  386. LongPut (f, CheckSum, 1);
  387. xputs (f, "\n");
  388. } else {
  389. templong = HunkUnit;
  390. xputl (f, templong);
  391. DumpName (f, idntname, 0L);
  392. }
  393. StartAddr = TempAddr = Sindex = 0;
  394. NumRExt = NumR32 = NumR16 = NumR8 = 0;
  395. NumA32 = NumA16 = NumA8 = 0; /* added by Kevin Kofler in v.2.71.F3l */
  396. }
  397. /* void WriteSrecLine (f) struct fs *f; */
  398. void WriteSrecLine (__NO_PARAMS__) /* removed useless parameter - Kevin Kofler,
  399. v.2.71.F3d */
  400. /* Transfers object code components to output buffer. */
  401. /* Moves long words or portions thereof. */
  402. {
  403. register int i, j;
  404. register long templong;
  405. if (HunkType == HunkBSS)
  406. return; /* No code in BSS hunk! */
  407. if (nO + nS + nD + nX) { /* If we have object code... */
  408. AppendSdata (ObjOp, nO); /* Opcode */
  409. AppendSdata (ObjSrc, nS); /* Source */
  410. AppendSdata (ObjDest, nD); /* Destination */
  411. for (i = 0; i < DupFact; i++) {
  412. for (j = 0; j < nX; j++) { /* String data */
  413. templong = ObjString[j];
  414. AppendSdata (templong, 1);
  415. }
  416. }
  417. }
  418. }
  419. void AppendSdata (Data, n) register long Data; int n;
  420. /* If we are producing S-format records:
  421. Transfers "n" low-order bytes from "Data" to the output buffer.
  422. If the buffer becomes full, DumpSdata will be called to flush it.
  423. S-records will also be broken on 16-byte boundaries.
  424. If we are producing AmigaDOS format, data will be written
  425. directly to Srec - we'll go back and fill in the hunk length
  426. at the end of the hunk. DumpSdata will never be called from here. */
  427. {
  428. register int i;
  429. register char byte;
  430. /* int dummy = 0; */ /* using now void in v.2.71.F3d - Kevin Kofler */
  431. if (!Pass2)
  432. return; /* Pass 2 only */
  433. if (HunkType == HunkBSS)
  434. return; /* No data in BSS hunks! */
  435. if (HunkType == HunkNone) { /* We're not in a hunk yet - */
  436. DoSection ("", 0, "", 0, "", 0); /* start a code hunk. */
  437. MakeHunk = TRUE;
  438. }
  439. if (OrgFlag) { /* If we've had an ORG directive */
  440. FixOrg (/*dummy*/ /*(using now void in v.2.71.F3d - Kevin Kofler)*/); /* do necessary adjustments */
  441. OrgFlag = FALSE; /* to the object code file. */
  442. }
  443. Data <<= (4 - n) * 8; /* Left-justify data. */
  444. for (i = 0; i < n; i++) {
  445. byte = (char) (Data >> ((3 - i) * 8));
  446. TempAddr++;
  447. if (!SFormat) {
  448. xputc (byte, &Srec);
  449. } else {
  450. Sdata[Sindex++] = byte;
  451. if (((TempAddr & 0x0F) == 0) || (Sindex >= MAXSREC))
  452. DumpSdata (&Srec); /* Break S-record. */
  453. }
  454. }
  455. }
  456. void FixOrg (__NO_PARAMS__) /* using now void in v.2.71.F3d - Kevin Kofler */
  457. /* Makes necessary adjustments to the object code file if an
  458. ORG directive has been processed. This routine is called
  459. exclusively by AppendSdata and must only be called once for
  460. each ORG encountered, when writing the next object code (if any). */
  461. {
  462. register long templong;
  463. register int i;
  464. if (SFormat && (AddrCnt != TempAddr)) { /* ORG in S-format - */
  465. DumpSdata (&Srec); /* dump current record */
  466. StartAddr = TempAddr = AddrCnt; /* and start afresh. */
  467. }
  468. if (AddrCnt < TempAddr) { /* AmigaDOS backward ORG */
  469. if (TempAddr > OrgHigh) {
  470. LenPtr = NULL;
  471. OrgHigh = TempAddr; /* Save high address for return. */
  472. xwrite (&Srec); /* Flush the buffer. */
  473. OrgSeek = lseek (Srec.fd, 0L, 1); /* Remember position. */
  474. lseek (Srec.fd,(AddrCnt & ~3L)-TempAddr,1); /* New position */
  475. if (AddrCnt & 3L) { /* If ORG isn't to long-word */
  476. read (Srec.fd, Srec.Buf, AddrCnt & 3L); /* move ahead */
  477. lseek (Srec.fd, -(AddrCnt & 3L), 1); /* to keep */
  478. } /* the buffer */
  479. Srec.Ptr = Srec.Buf + (AddrCnt & 3L); /* aligned. */
  480. }
  481. StartAddr = TempAddr = AddrCnt;
  482. } else if (AddrCnt > TempAddr) { /* AmigaDOS forward ORG */
  483. if (OrgHigh > TempAddr) { /* Previous backward ORG */
  484. if (AddrCnt < OrgHigh)
  485. templong = AddrCnt; /* Within previous range */
  486. else
  487. templong = OrgHigh; /* Beyond previous range */
  488. i = (int) (templong & 3L); /* Alignment factor */
  489. templong -= TempAddr; /* Number of bytes to skip */
  490. LenPtr = NULL;
  491. xwrite (&Srec); /* Flush the buffer. */
  492. lseek (Srec.fd,templong-(long)i,1); /* Skip written data. */
  493. if (i) { /* If skip isn't to long-word, */
  494. read(Srec.fd,Srec.Buf,(long)i); /* move ahead */
  495. lseek(Srec.fd, -((long) i), 1); /* to keep */
  496. } /* the buffer */
  497. Srec.Ptr = Srec.Buf + (long) i; /* aligned. */
  498. TempAddr += templong;
  499. StartAddr = TempAddr;
  500. }
  501. while (TempAddr < AddrCnt) { /* Extend with binary zeros. */
  502. xputc (0, &Srec);
  503. TempAddr++;
  504. }
  505. }
  506. }
  507. void DumpSdata (f) register struct fs *f;
  508. /* Writes an object code record. */
  509. {
  510. register long CheckSum, templong;
  511. register char *s;
  512. register int i;
  513. if (!SFormat) {
  514. if (AddrCnt < OrgHigh) { /* If we did a backwards ORG, */
  515. LenPtr = NULL; /* we have to fix things up. */
  516. xwrite (&Srec); /* Flush the buffer. */
  517. lseek(f->fd,OrgSeek&~3L,0); /* Back to high position */
  518. if (OrgSeek & 3L) { /* If ORG isn't to long-word, */
  519. read (f->fd, f->Buf, OrgSeek & 3L); /* move ahead */
  520. lseek (f->fd, -(OrgSeek & 3L), 1); /* to keep */
  521. } /* the buffer */
  522. f->Ptr = f->Buf + (OrgSeek & 3L); /* aligned. */
  523. AddrCnt = StartAddr = TempAddr = OrgHigh;
  524. }
  525. AddrCnt = AddrBndL (AddrCnt); /* Finish the last long word. */
  526. templong = (AddrCnt - SectStart) >> 2;
  527. if ((s = LenPtr) == NULL) {
  528. xwrite (&Srec); /* Flush the buffer. */
  529. CheckSum = lseek (f->fd, 0L, 1); /* Remember position. */
  530. lseek (f->fd, LenPos, 0); /* Put hunk length here. */
  531. s = f->Buf;
  532. }
  533. *s++ = (char) (templong >> 24);
  534. *s++ = (char) (templong >> 16);
  535. *s++ = (char) (templong >> 8);
  536. *s++ = (char) templong;
  537. if (LenPtr == NULL) {
  538. f->Ptr = f->Buf + 4;
  539. xwrite (f);
  540. lseek (f->fd, CheckSum, 0); /* Go back to where we were. */
  541. f->Ptr = f->Buf;
  542. }
  543. DumpRel (f); /* Write relocation information. */
  544. templong = HunkEnd;
  545. xputl (f, templong); /* End of the hunk */
  546. TempAddr = AddrCnt;
  547. return;
  548. }
  549. if (Sindex == 0)
  550. return; /* There's nothing to dump. */
  551. xputs (f, "S2");
  552. templong = Sindex + 4; /* Record length */
  553. LongPut (f, templong, 1);
  554. CheckSum = templong; /* Initialize CheckSum. */
  555. LongPut (f, StartAddr, 3); /* Address */
  556. CheckSum += (StartAddr >> 16) & 0x00FFL;
  557. CheckSum += (StartAddr >> 8) & 0x00FFL;
  558. CheckSum += StartAddr & 0x00FFL;
  559. for (i = 0; i < Sindex; i++) {
  560. templong = Sdata[i];
  561. LongPut (f, templong, 1); /* Object code */
  562. CheckSum += templong;
  563. }
  564. CheckSum = ~CheckSum; /* Complement the checksum. */
  565. LongPut (f, CheckSum, 1);
  566. xputs (f, "\n");
  567. StartAddr += Sindex;
  568. TempAddr = StartAddr;
  569. Sindex = 0;
  570. }
  571. void PutRel (addr, hunk, size, IsPC) long addr, hunk; int size; int IsPC;
  572. /* Build a relocation entry if necessary. */
  573. {
  574. register struct RelTab *rel;
  575. if (!Pass2)
  576. return; /* Pass 2 only */
  577. if (SFormat)
  578. return; /* Not for S-format! */
  579. if (hunk == ABSHUNK)
  580. return; /* Absolute */
  581. if (HunkType == HunkBSS)
  582. return; /* Not for BSS hunks! */
  583. rel = RelLim; /* Pointer to new entry. */
  584. RelLim++; /* Bump limit pointer. */
  585. if (((char *) RelLim - (char *) RelCurr) > CHUNKSIZE) {
  586. rel = (struct RelTab *) malloc ((unsigned) CHUNKSIZE);
  587. if (rel == NULL)
  588. quit_cleanup ("Out of memory!\n");
  589. RelCurr->Link = rel; /* Link from previous chunk */
  590. RelCurr = rel; /* Make the new chunk current. */
  591. RelCurr->Link = NULL; /* Clear forward pointer. */
  592. rel++; /* Skip over pointer entry. */
  593. RelLim = rel; /* New table limit */
  594. RelLim++; /* Bump it. */
  595. }
  596. if (RelLast != NULL)
  597. RelLast->Link = rel; /* Link from previous entry */
  598. rel->Link = NULL; /* End of the chain (so far) */
  599. rel->Offset = addr; /* Offset */
  600. rel->Hunk = hunk; /* Hunk number */
  601. rel->Size = size; /* Size */
  602. rel->IsPC = IsPC;
  603. rel->Target = -1; /* added by Kevin Kofler in v.2.71.F3l */
  604. rel->Negative = 0; /* added by Kevin Kofler in v.2.71.F3l */
  605. RelLast = rel; /* Pointer to last entry in chain */
  606. if (hunk < 0) /* Count entries by type. */
  607. NumRExt++;
  608. else if (size == Long)
  609. NumR32++;
  610. else if (size == Word)
  611. NumR16++;
  612. else
  613. NumR8++;
  614. }
  615. /* Function added by Kevin Kofler -- v.2.71.F3l */
  616. void EmitAddrDiffs (addr, size) long addr; int size;
  617. /* Emit address differences if necessary. */
  618. {
  619. register struct RelTab *rel;
  620. if (!Pass2)
  621. return; /* Pass 2 only */
  622. if (SFormat)
  623. return; /* Not for S-format! */
  624. while (AddrDiffs) {
  625. struct AddrDiff *next=AddrDiffs->Link;
  626. rel = RelLim; /* Pointer to new entry. */
  627. RelLim++; /* Bump limit pointer. */
  628. if (((char *) RelLim - (char *) RelCurr) > CHUNKSIZE) {
  629. rel = (struct RelTab *) malloc ((unsigned) CHUNKSIZE);
  630. if (rel == NULL)
  631. quit_cleanup ("Out of memory!\n");
  632. RelCurr->Link = rel; /* Link from previous chunk */
  633. RelCurr = rel; /* Make the new chunk current. */
  634. RelCurr->Link = NULL; /* Clear forward pointer. */
  635. rel++; /* Skip over pointer entry. */
  636. RelLim = rel; /* New table limit */
  637. RelLim++; /* Bump it. */
  638. }
  639. if (RelLast != NULL)
  640. RelLast->Link = rel; /* Link from previous entry */
  641. rel->Link = NULL; /* End of the chain (so far) */
  642. rel->Offset = addr; /* Offset */
  643. rel->Hunk = AddrDiffs->phunk; /* Hunk number */
  644. rel->Size = size; /* Size */
  645. rel->IsPC = 0;
  646. rel->Target = AddrDiffs->paddr;
  647. rel->Negative = 0;
  648. RelLast = rel; /* Pointer to last entry in chain */
  649. rel = RelLim; /* Pointer to new entry. */
  650. RelLim++; /* Bump limit pointer. */
  651. if (((char *) RelLim - (char *) RelCurr) > CHUNKSIZE) {
  652. rel = (struct RelTab *) malloc ((unsigned) CHUNKSIZE);
  653. if (rel == NULL)
  654. quit_cleanup ("Out of memory!\n");
  655. RelCurr->Link = rel; /* Link from previous chunk */
  656. RelCurr = rel; /* Make the new chunk current. */
  657. RelCurr->Link = NULL; /* Clear forward pointer. */
  658. rel++; /* Skip over pointer entry. */
  659. RelLim = rel; /* New table limit */
  660. RelLim++; /* Bump it. */
  661. }
  662. if (RelLast != NULL)
  663. RelLast->Link = rel; /* Link from previous entry */
  664. rel->Link = NULL; /* End of the chain (so far) */
  665. rel->Offset = addr; /* Offset */
  666. rel->Hunk = AddrDiffs->nhunk; /* Hunk number */
  667. rel->Size = size; /* Size */
  668. rel->IsPC = 0;
  669. rel->Target = AddrDiffs->naddr;
  670. rel->Negative = 1;
  671. RelLast = rel; /* Pointer to last entry in chain */
  672. if (size == Long) /* Count entries by type. */
  673. NumA32+=2;
  674. else if (size == Word)
  675. NumA16+=2;
  676. else
  677. NumA8+=2;
  678. free(AddrDiffs);
  679. AddrDiffs=next;
  680. }
  681. }
  682. void DumpRel (f) struct fs *f;
  683. /* Dump relocation information to the object file. */
  684. {
  685. register struct SymTab *sym;
  686. register struct RelTab *rel, *rel2;
  687. int j, size, num, donexhdr, secthlin;
  688. long currhunk, nexthunk, templong;
  689. char *s, *t;
  690. secthlin = LineCount; /* Current section ends here */
  691. if ((Dir == Section) /* unless we're starting */
  692. || (Dir == CSeg) /* a new section. */
  693. || (Dir == DSeg)
  694. || (Dir == BSS))
  695. secthlin--; /* Then it ends at previous line. */
  696. if (SFormat)
  697. return; /* S-format is absolute! */
  698. while (1) {
  699. if ((num = NumR32) != 0) {
  700. size = Long; /* Do 32-bit fields */
  701. templong = HunkR32;
  702. NumR32 = 0; /* ...but only once. */
  703. } else if ((num = NumR16) != 0) {
  704. size = Word; /* Then do 16-bit fields. */
  705. templong = HunkR16;
  706. NumR16 = 0;
  707. } else if ((num = NumR8) != 0) {
  708. size = Byte; /* Finally do 8-bit fields. */
  709. templong = HunkR8;
  710. NumR8 = 0;
  711. } else
  712. break; /* We're all done. */
  713. xputl (f, templong); /* Record type */
  714. currhunk = 32767;
  715. num = 0;
  716. if (rel = RelStart) /* If we have anything, */
  717. rel++; /* skip over the first chunk's link. */
  718. while (rel) {
  719. if ((rel->Size == size) && (rel->Hunk >= 0)
  720. && (rel->Target == -1) /* added by Kevin Kofler in v.2.71.F3l */
  721. ) {
  722. if (rel->Hunk < currhunk) {
  723. currhunk = rel->Hunk; /* Lowest hunk number */
  724. num = 1; /* Reset counter. */
  725. } else if (rel->Hunk == currhunk) {
  726. num++; /* Count entries. */
  727. }
  728. }
  729. rel = rel->Link;
  730. }
  731. while (num > 0) { /* Repeat for all hunk references. */
  732. templong = num;
  733. xputl (f, templong); /* Number of entries */
  734. xputl (f, currhunk); /* Hunk number */
  735. nexthunk = 32767;
  736. num = 0; /* Count for next hunk */
  737. if (rel = RelStart)
  738. rel++;
  739. while (rel) {
  740. if ((rel->Size == size) && (rel->Hunk >= 0)
  741. && (rel->Target == -1) /* added by Kevin Kofler in v.2.71.F3l */
  742. ) {
  743. if (rel->Hunk < currhunk) {
  744. rel = rel->Link; /* We already wrote it. */
  745. continue;
  746. } else if (rel->Hunk == currhunk) {
  747. xputl (f, rel->Offset - SectStart);
  748. } else if (rel->Hunk < nexthunk) {
  749. nexthunk = rel->Hunk; /* Next hunk number */
  750. num = 1; /* Reset counter. */
  751. } else if (rel->Hunk == nexthunk) {
  752. num++; /* Count entries. */
  753. }
  754. }
  755. rel = rel->Link;
  756. }
  757. currhunk = nexthunk; /* Get ready for next hunk. */
  758. }
  759. xputl (f, 0L); /* End of relocation information */
  760. }
  761. /* loop added by Kevin Kofler in v.2.71.F3l: */
  762. while (1) {
  763. if ((num = NumA32) != 0) {
  764. size = Long; /* Do 32-bit fields */
  765. templong = HunkA32;
  766. NumA32 = 0; /* ...but only once. */
  767. } else if ((num = NumA16) != 0) {
  768. size = Word; /* Then do 16-bit fields. */
  769. templong = HunkA16;
  770. NumA16 = 0;
  771. } else if ((num = NumA8) != 0) {
  772. size = Byte; /* Finally do 8-bit fields. */
  773. templong = HunkA8;
  774. NumA8 = 0;
  775. } else
  776. break; /* We're all done. */
  777. xputl (f, templong); /* Record type */
  778. xputl (f, num); /* Record number of relocs */
  779. if (rel = RelStart) /* If we have anything, */
  780. rel++; /* skip over the first chunk's link. */
  781. while (rel) {
  782. if ((rel->Size == size) && (rel->Hunk >= 0)
  783. && (rel->Target != -1)
  784. ) {
  785. /* target hunk */
  786. xputl(f,rel->Hunk);
  787. /* source offset */
  788. xputl(f,rel->Offset-SectStart);
  789. /* target offset */
  790. xputl(f,rel->Target-SectStart);
  791. /* FIXME: We shouldn't have to subtract SectStart here. This should
  792. have been done during the evaluation. But for now, only
  793. in-hunk address differences are allowed, so it is fine for
  794. now. */
  795. /* reloc sign */
  796. xputl(f,(rel->Negative?-1:0));
  797. }
  798. rel = rel->Link;
  799. }
  800. }
  801. /* end of loop added by Kevin Kofler in v.2.71.F3l */
  802. donexhdr = FALSE; /* We haven't written hunk_ext yet. */
  803. sym = SymChunk = SymStart;
  804. sym++;
  805. SymChLim = (struct SymTab *) ((char *) SymChunk + CHUNKSIZE);
  806. while (sym) {
  807. if (sym->Flags & 2) { /* Scan for XDEF symbols. */
  808. j = sym->Defn; /* Defined in current section? */
  809. if ((j >= SectLine) && (j <= secthlin)) {
  810. if (!donexhdr) {
  811. templong = HunkExt; /* We haven't done header yet. */
  812. xputl (f, templong);
  813. donexhdr = TRUE;
  814. }
  815. if ((sym->Hunk & 0x0000FFFFL) == ABSHUNK)
  816. templong = 0x02000000;
  817. else
  818. templong = 0x01000000; /* Flags */
  819. DumpName (f, sym->Nam, templong); /* Symbol */
  820. xputl (f, sym->Val - SectStart); /* Offset */
  821. }
  822. }
  823. sym = NextSym (sym);
  824. }
  825. if (NumRExt != 0) { /* External references (XREF) */
  826. if (!donexhdr) {
  827. templong = HunkExt; /* We haven't done header yet. */
  828. xputl (f, templong);
  829. donexhdr = TRUE;
  830. }
  831. if (rel = RelStart)
  832. rel++;
  833. while (rel) {
  834. if (rel->Hunk < 0) {
  835. size = rel->Size;
  836. if (size == Long)
  837. templong = 0x81000000L; /* ext_ref32 */
  838. else if (size == Word) {
  839. if (rel->IsPC)
  840. templong = 0x83000000L; /* ext_ref16 */
  841. else
  842. templong = 0x8A000000L; /* ext_absref16 */
  843. }
  844. else {
  845. if (rel->IsPC)
  846. templong = 0x84000000L; /* ext_ref8 */
  847. else
  848. templong = 0x8B000000L; /* ext_absref8 */
  849. }
  850. s = (char *) ~(rel->Hunk);
  851. DumpName (f, s, templong); /* Flags and symbol */
  852. templong = 1;
  853. rel2 = rel->Link;
  854. while (rel2) {
  855. if ((rel2->Hunk == rel->Hunk) && (rel2->Size == size) && (rel2->IsPC == rel->IsPC))
  856. templong++; /* Number of times */
  857. rel2 = rel2->Link; /* symbol occurs */
  858. }
  859. xputl (f, templong);
  860. rel2 = rel; /* Now go back and */
  861. while (rel2) { /* write them out. */
  862. if ((rel2->Hunk==rel->Hunk) && (rel2->Size==size) && (rel2->IsPC == rel->IsPC)) {
  863. xputl(f, rel2->Offset - SectStart); /* Offset */
  864. if (rel2 != rel) /* Kill hunk so we */
  865. rel2->Hunk = 0; /* don't do it again */
  866. } /* (we're done with */
  867. rel2 = rel2->Link; /* the table anyway). */
  868. }
  869. }
  870. rel = rel->Link;
  871. }
  872. NumRExt = 0;
  873. }
  874. if (donexhdr)
  875. xputl (f, 0L); /* End of external information */
  876. if (DumpSym) { /* Dump the symbol table. */
  877. donexhdr = FALSE;
  878. sym = SymChunk = SymStart;
  879. sym++;
  880. SymChLim = (struct SymTab *) ((char *) SymChunk + CHUNKSIZE);
  881. for (; sym; sym = NextSym (sym)) {
  882. s = DumpSymList;
  883. if (*s) { /* Select by prefix. */
  884. if (*s == '!')
  885. s++; /* Symbols must NOT match prefix. */
  886. t = sym->Nam;
  887. j = TRUE; /* Assume we have a match. */
  888. while (*s) {
  889. if (*s++ != *t++) {
  890. j = FALSE; /* Symbol does not match prefix. */
  891. break;
  892. }
  893. }
  894. if (DumpSymList[0] == '!') {
  895. if (j)
  896. continue;
  897. } else {
  898. if (!j)
  899. continue;
  900. }
  901. }
  902. if ((sym->Hunk & 0x0000FFFFL) == CurrHunk) {
  903. j = sym->Flags & 0x7F; /* Ignore PUBLIC flag. */
  904. if ((j == 0) || (j == 2)) { /* Defined, may be XDEF. */
  905. if ((sym->Defn >= SectLine) && (sym->Defn <= secthlin)) {
  906. if (!donexhdr) { /* It's in current SECTION. */
  907. templong = HunkSym;
  908. xputl (f, templong); /* Write header */
  909. donexhdr = TRUE; /* if necessary. */
  910. }
  911. DumpName (f, sym->Nam, 0L); /* Symbol */
  912. xputl(f, sym->Val - SectStart); /* Offset */
  913. }
  914. }
  915. }
  916. }
  917. if (donexhdr)
  918. xputl (f, 0L); /* End of symbol table dump */
  919. }
  920. rel = RelStart->Link;
  921. while (rel != NULL) {
  922. rel2 = rel;
  923. rel = rel2->Link;
  924. free (rel2); /* Free all but the first chunk. */
  925. }
  926. RelCurr = RelStart; /* The first chunk is current. */
  927. RelCurr->Link = NULL; /* Unlink additional chunks. */
  928. RelLast = NULL; /* There are no entries left. */
  929. RelLim = RelStart;
  930. RelLim++; /* First unused space */
  931. }
  932. void EndSdata (f, addr) struct fs *f; long addr;
  933. /* Write end record to object file. */
  934. {
  935. register long checksum;
  936. if (SFormat) {
  937. DumpSdata (f); /* Write any remaining data. */
  938. xputs (f, "S804"); /* Record header */
  939. checksum = 4;
  940. LongPut (f, addr, 3); /* Transfer address */
  941. checksum += (addr >> 16) & 0x00FFL;
  942. checksum += (addr >> 8) & 0x00FFL;
  943. checksum += addr & 0x00FFL;
  944. checksum = ~checksum;
  945. LongPut (f, checksum, 1); /* Checksum */
  946. xputs (f, "\n");
  947. } else {
  948. if (HunkType != HunkNone) {
  949. DumpSdata (f); /* Last hunk's data */
  950. }
  951. }
  952. }
  953. void DumpName (f, name, flags) struct fs *f; char *name; long flags;
  954. /* Writes a name preceded by a long word containing the
  955. length of the name in long words. The length word has
  956. the contents of "flags" ORed into it. The name is padded
  957. with binary zeros to the next long word boundary. */
  958. {
  959. register int i;
  960. register long templong;
  961. i = strlen (name);
  962. templong = (i + 3) >> 2; /* Length of name (long words) */
  963. templong |= flags; /* Add flag bits. */
  964. xputl (f, templong); /* Write length and flags. */
  965. xputs (f, name); /* Write the name itself. */
  966. while (i & 3) {
  967. xputc ('\0', f); /* Pad the last word. */
  968. i++;
  969. }
  970. }
  971. void LongPut (f, data, length) struct fs *f; long data; int length;
  972. /* Writes to file "f" the hexadecimal interpretation of
  973. the bytes in "data". The number of bytes written
  974. (two hex digits per byte) is given in "length" -
  975. if less than 4, only low-order bytes are written. */
  976. {
  977. register int i, j;
  978. register char *t;
  979. char xstr[9];
  980. t = xstr;
  981. for (i = length * 8 - 4; i >= 0; i -= 4) {
  982. j = (int) ((data >> i) & 0x0FL);
  983. *t++ = (char) ((j > 9) ? (j - 10 + 'A') : (j + '0'));
  984. }
  985. *t = '\0';
  986. xputs (f, xstr);
  987. }
  988. int xopen (name, f, desc) char *name; struct fs *f; char *desc;
  989. /* Opens the output file whose name is in "name",
  990. setting up the file structure pointed to by "f".
  991. This routine first allocates a file buffer -
  992. if unsuccessful, it calls quit_cleanup.
  993. Otherwise, it opens the file - if unsuccessful,
  994. displays an error message using "desc" and returns TRUE.
  995. If the file is successfully opened, this routine returns FALSE. */
  996. {
  997. if ((f->Buf = (char *) malloc (BUFFSIZE)) == NULL)
  998. quit_cleanup ("Out of memory!\n");
  999. if ((f->fd = creat (name, 0644)) < 0) {
  1000. /* S_IREAD | S_IWRITE */
  1001. fprintf (stderr, "Unable to open %s file.\n", desc);
  1002. f->fd = NOFD;
  1003. return (TRUE);
  1004. }
  1005. f->Ptr = f->Buf;
  1006. f->Lim = f->Buf + BUFFSIZE;
  1007. return (FALSE);
  1008. }
  1009. void xputs (f, s) struct fs *f; register char *s;
  1010. /* Writes the string pointed to by "s"
  1011. to the output file whose structure is pointed to by "f". */
  1012. {
  1013. register char *t, *l;
  1014. t = f->Ptr; /* Current position (use registers for speed) */
  1015. l = f->Lim; /* End of buffer */
  1016. while (*s) {
  1017. *t++ = *s++;
  1018. if (t >= l) {
  1019. f->Ptr = t;
  1020. xwrite (f); /* Flush the buffer. */
  1021. if (f == &Srec)
  1022. LenPtr = NULL; /* Hunk length is no longer in buffer. */
  1023. t = f->Buf; /* Reset pointer. */
  1024. }
  1025. }
  1026. f->Ptr = t; /* Update pointer. */
  1027. }
  1028. void xputl (f, data) register struct fs *f; register long data;
  1029. /* Writes to file "f" the contents of the long word in "data". */
  1030. {
  1031. xputc ((char) (data >> 24), f);
  1032. xputc ((char) (data >> 16), f);
  1033. xputc ((char) (data >> 8), f);
  1034. xputc ((char) data, f);
  1035. }
  1036. void xputc (byte, f) char byte; register struct fs *f;
  1037. /* Writes the byte contained in "byte" to file "f". */
  1038. {
  1039. register char *t;
  1040. t = f->Ptr; /* Current position (use a register for speed) */
  1041. *t++ = byte;
  1042. if (t >= f->Lim) {
  1043. f->Ptr = t;
  1044. xwrite (f); /* Flush the buffer. */
  1045. if (f == &Srec)
  1046. LenPtr = NULL; /* Hunk length is no longer in buffer. */
  1047. t = f->Buf; /* Reset pointer. */
  1048. }
  1049. f->Ptr = t; /* Update pointer. */
  1050. }
  1051. void xclose (f) struct fs *f;
  1052. /* Closes the output file whose structure is pointed to by "f".
  1053. The buffer is flushed if necessary, then freed. */
  1054. {
  1055. xwrite (f); /* Flush the buffer. */
  1056. close (f->fd); /* Close the file. */
  1057. f->fd = NOFD;
  1058. free (f->Buf); /* Free the buffer. */
  1059. f->Buf = NULL;
  1060. }
  1061. void xwrite (f) struct fs *f;
  1062. /* General write routine */
  1063. {
  1064. int i;
  1065. i = (int) (f->Ptr - f->Buf); /* Number of bytes to write */
  1066. if (i > 0) {
  1067. if (write (f->fd, f->Buf, i) != i) { /* Write the buffer. */
  1068. f->Ptr = f->Buf; /* Avoid loop in xclose()! */
  1069. if (f == &List)
  1070. quit_cleanup ("\nListing file write error!\n");
  1071. else if (f == &Eq)
  1072. quit_cleanup ("\nEquate file write error!\n");
  1073. else
  1074. quit_cleanup ("\nObject file write error!\n");
  1075. }
  1076. }
  1077. }
  1078. void Error (pos, errornum) int pos, errornum;
  1079. /* Displays error message #errornum. If this is the first error for
  1080. the current line, the line itself is displayed, preceded by a
  1081. message giving the current position in the current module.
  1082. If the line is in a macro or include file, the position in
  1083. each nested module is given, working out to the source file.
  1084. A flag is placed under the column indicated by "pos". */
  1085. {
  1086. register int i;
  1087. /* int dummy = 0; */ /* using now void in v.2.71.F3d - Kevin Kofler */
  1088. isError = TRUE; /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3a */
  1089. if (!Pass2 && (errornum != NoIncl)) {
  1090. if (IncStart != 0) { /* Don't skip this */
  1091. IncStart = 0; /* INCLUDE file in */
  1092. if (SkipLim->Set1 != NULL) { /* pass 2 - we must */
  1093. SetFixLim = SkipLim->Set1; /* re-read it to */
  1094. SetFixLim++; /* report its errors. */
  1095. }
  1096. }
  1097. return; /* Report during pass 2 only. */
  1098. }
  1099. if (ErrLim < ERRMAX) { /* Save error data. */
  1100. ErrCode[ErrLim] = errornum;
  1101. ErrPos[ErrLim] = pos;
  1102. ErrLim++;
  1103. }
  1104. if (ErrLim == 1) /* If this is the first error for this line, */
  1105. DisplayLine (/*dummy*/ /*(using now void in v.2.71.F3d - Kevin Kofler)*/); /* display the line and its number(s). */
  1106. printf ("\t");
  1107. for (i = 0; i < pos; i++)
  1108. if (Line[i] == '\t')
  1109. printf ("\t");
  1110. else
  1111. printf(" "); /* Space over to error column. */
  1112. printf ("^ %s\n",errmsg[errornum]); /* Error flag and message */
  1113. ErrorCount++; /* Count errors. */
  1114. }
  1115. void DisplayLine (__NO_PARAMS__) /* using now void in v.2.71.F3d - Kevin Kofler */
  1116. /* Displays the current line and its position
  1117. in all current files - used by Error, etc. */
  1118. {
  1119. register struct InFCtl *inf;
  1120. register int i;
  1121. printf ("\n");
  1122. for (i = InFNum, inf = InF; i >= 0; i--, inf++) { /* Nested? */
  1123. if (inf->UPtr == 0)
  1124. printf ("%s", inf->NPtr); /* Module name */
  1125. else
  1126. printf ("(user macro)"); /* We're in a user macro. */
  1127. printf (" line %d\n", inf->Line); /* Line number in module */
  1128. }
  1129. printf ("%5d %s\n", LineCount, Line); /* The line itself */
  1130. }