pops.c 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /* pops.c - handle pseudo-ops for assembler */
  2. #include "syshead.h"
  3. #include "const.h"
  4. #include "type.h"
  5. #include "address.h"
  6. #include "flag.h"
  7. #include "globvar.h"
  8. #include "opcode.h"
  9. #include "scan.h"
  10. PRIVATE bool_t elseflag; /* set if ELSE/ELSEIF are enabled */
  11. /* depends on zero = FALSE init */
  12. PRIVATE bool_t lcommflag;
  13. FORWARD void bumpsem P((struct flags_s *flagptr, int defval));
  14. FORWARD void constdata P((unsigned size));
  15. FORWARD void docomm P((void));
  16. FORWARD void doelseif P((pfv func));
  17. FORWARD void doequset P((int labits));
  18. FORWARD void doentexp P((int entbits, int impbits));
  19. FORWARD void dofcc P((void));
  20. FORWARD void doif P((pfv func));
  21. FORWARD struct sym_s *needlabel P((void));
  22. FORWARD void showredefinedlabel P((void));
  23. FORWARD void setloc P((unsigned seg));
  24. PRIVATE void bumpsem(flagptr, defval)
  25. register struct flags_s *flagptr;
  26. int defval;
  27. {
  28. int newcount;
  29. if (flagptr->global && pass == last_pass)
  30. {
  31. /* bump semaphore count by an expression (default 1), */
  32. /* then set currentflag iff semaphore count is plus */
  33. if (sym == EOLSYM)
  34. lastexp.offset = defval;
  35. else
  36. {
  37. absexpres();
  38. if (lastexp.data & UNDBIT)
  39. return;
  40. }
  41. newcount = (int) lastexp.offset;
  42. #ifdef I80386 /* really sizeof (offset_t) != sizeof (int) */
  43. if (newcount != lastexp.offset)
  44. datatoobig();
  45. #endif
  46. newcount += flagptr->semaphore;
  47. if ((int) lastexp.offset >= 0)
  48. {
  49. if (newcount < flagptr->semaphore)
  50. {
  51. error(COUNTOV);
  52. newcount = 0x7fff;
  53. }
  54. }
  55. else if (newcount >= flagptr->semaphore)
  56. {
  57. error(COUNTUN);
  58. newcount = -0x8000;
  59. }
  60. flagptr->semaphore = newcount;
  61. flagptr->current = newcount >= 0;
  62. }
  63. }
  64. /* check symbol is either undefined */
  65. /* or has the same segment & relocatability as lc */
  66. PUBLIC bool_pt checksegrel(symptr)
  67. register struct sym_s *symptr;
  68. {
  69. if ((symptr->type & LABIT ||
  70. (symptr->data & IMPBIT && !(symptr->data & UNDBIT))) &&
  71. ((symptr->data ^ lcdata) & (RELBIT | SEGM)))
  72. {
  73. error(SEGREL);
  74. return FALSE;
  75. }
  76. return TRUE;
  77. }
  78. /* check address fits in 1 byte (possibly with sign truncated) */
  79. PUBLIC void checkdatabounds()
  80. {
  81. if (!(lastexp.data & UNDBIT) &&
  82. (offset_t) (lastexp.offset + 0x80) >= 0x180)
  83. datatoobig();
  84. }
  85. /* allocate constant data (zero except for size 1), default zero for size 1 */
  86. PRIVATE void constdata(size)
  87. unsigned size;
  88. {
  89. offset_t remaining;
  90. absexpres();
  91. if (!((lcdata |= lastexp.data) & UNDBIT))
  92. {
  93. lcjump = lastexp.offset * size;
  94. popflags = POPLONG | POPHI | POPLO | POPLC;
  95. if (size == 1 && sym == COMMA)
  96. {
  97. symabsexpres();
  98. checkdatabounds();
  99. for (remaining = lcjump; remaining != 0; --remaining)
  100. {
  101. putbin((opcode_pt) lastexp.offset); /* fill byte */
  102. putabs((opcode_pt) lastexp.offset);
  103. }
  104. lastexp.offset = lcjump;
  105. }
  106. else
  107. accumulate_rmb(lastexp.offset * size);
  108. }
  109. }
  110. PUBLIC void datatoobig()
  111. {
  112. error(DBOUNDS);
  113. }
  114. /* common routine for COMM/.COMM */
  115. PRIVATE void docomm()
  116. {
  117. register struct sym_s *labptr;
  118. absexpres(); /* if undefined, value 0 and size unchanged */
  119. labptr = label;
  120. if (checksegrel(labptr))
  121. {
  122. if (labptr->type & (EXPBIT | LABIT))
  123. labelerror(ALREADY);
  124. else
  125. {
  126. if (!(labptr->type & COMMBIT) ||
  127. lastexp.offset > labptr->value_reg_or_op.value)
  128. labptr->value_reg_or_op.value = lastexp.offset;
  129. labptr->type |= COMMBIT;
  130. if (lcommflag)
  131. labptr->type |= REDBIT; /* kludge - COMMBIT | REDBIT => SA */
  132. if( last_pass == 1 )
  133. labptr->data = (lcdata & SEGM) | (FORBIT | IMPBIT | RELBIT);
  134. else
  135. labptr->data = (lcdata & SEGM) | (IMPBIT | RELBIT);
  136. showlabel();
  137. }
  138. }
  139. lcommflag = FALSE;
  140. }
  141. /* common routine for ELSEIF/ELSEIFC */
  142. PRIVATE void doelseif(func)
  143. pfv func;
  144. {
  145. if (iflevel == 0)
  146. error(ELSEIFBAD);
  147. else
  148. {
  149. ifflag = FALSE;
  150. if (elseflag)
  151. {
  152. (*func) ();
  153. if (!(lastexp.data & UNDBIT) && lastexp.offset != 0)
  154. /* expression valid and TRUE, enable assembling */
  155. {
  156. ifflag = TRUE;
  157. elseflag = FALSE;
  158. }
  159. }
  160. else
  161. {
  162. /* Skip to EOL */
  163. while (sym != EOLSYM)
  164. getsym();
  165. }
  166. }
  167. }
  168. /* common routine for EQU/SET */
  169. PRIVATE void doequset(labits)
  170. unsigned char labits;
  171. {
  172. register struct sym_s *labptr;
  173. unsigned char olddata;
  174. unsigned char oldtype;
  175. labptr = label;
  176. /* set up new label flags in case labe isl used in expression */
  177. labptr->type = (oldtype = labptr->type) | labits;
  178. labptr->data = (olddata = labptr->data) & ~IMPBIT;
  179. /* non-imported now */
  180. nonimpexpres();
  181. lastexp.data |= olddata & FORBIT; /* take all but FORBIT from
  182. expression */
  183. if (oldtype & LABIT && !(olddata & UNDBIT) && !pass)
  184. /* this is a previously defined label */
  185. /*
  186. redefinition only allowed if same relocatability, segment and
  187. value
  188. */
  189. {
  190. if ((olddata ^ lastexp.data) & (RELBIT | UNDBIT) ||
  191. labptr->value_reg_or_op.value != lastexp.offset)
  192. {
  193. showredefinedlabel();
  194. return;
  195. }
  196. }
  197. labptr->data = lastexp.data;
  198. labptr->value_reg_or_op.value = lastexp.offset;
  199. showlabel();
  200. if(pass && !(labits & VARBIT) && labptr->value_reg_or_op.value != oldlabel)
  201. {
  202. dirty_pass = TRUE;
  203. if( pass == last_pass )
  204. error(UNSTABLE_LABEL);
  205. }
  206. }
  207. /* common routine for ENTRY/EXPORT */
  208. PRIVATE void doentexp(entbits, impbits)
  209. unsigned char entbits;
  210. unsigned char impbits;
  211. {
  212. struct sym_s *symptr;
  213. while (TRUE)
  214. {
  215. if ((symptr = needlabel()) != NUL_PTR)
  216. {
  217. if (symptr->type & COMMBIT)
  218. error(ALREADY);
  219. else if (impbits != 0)
  220. {
  221. if (pass == last_pass)
  222. ;
  223. else if (symptr->type & (EXPBIT | LABIT))
  224. symptr->type |= EXPBIT;
  225. else
  226. {
  227. symptr->type |= REDBIT;
  228. if (!(symptr->data & IMPBIT))
  229. symptr->data |= IMPBIT | SEGM;
  230. }
  231. }
  232. else
  233. {
  234. if (pass == last_pass)
  235. {
  236. if (!(symptr->type & LABIT))
  237. error(UNLAB);
  238. }
  239. else
  240. {
  241. symptr->type |= entbits | EXPBIT;
  242. symptr->data &= ~IMPBIT;
  243. }
  244. }
  245. }
  246. getsym();
  247. if (sym != COMMA)
  248. break;
  249. getsym();
  250. }
  251. }
  252. /* common routine for FCC (== .ASCII) and .ASCIZ */
  253. PRIVATE void dofcc()
  254. {
  255. register char *bufptr;
  256. char byte;
  257. char delimiter;
  258. register char *reglineptr;
  259. bufptr = databuf.fcbuf;
  260. reglineptr = symname;
  261. if ((delimiter = *reglineptr) != EOLCHAR)
  262. ++reglineptr;
  263. while (TRUE)
  264. {
  265. if ((byte = *reglineptr) == EOLCHAR)
  266. {
  267. symname = reglineptr;
  268. error(DELEXP);
  269. break;
  270. }
  271. if (byte == delimiter)
  272. {
  273. if ((byte = *++reglineptr) != delimiter)
  274. break;
  275. }
  276. else if (byte == '\\')
  277. {
  278. switch (byte = *++reglineptr)
  279. {
  280. case '"':
  281. case '\'':
  282. case '\\':
  283. case '?':
  284. break;
  285. case '0':
  286. case '1':
  287. case '2':
  288. case '3':
  289. case '4':
  290. case '5':
  291. case '6':
  292. case '7':
  293. byte -= '0';
  294. if (*(reglineptr + 1) >= '0' && *(reglineptr + 1) < '8')
  295. {
  296. byte = 8 * byte + *++reglineptr - '0';
  297. if (*(reglineptr + 1) >= '0' && *(reglineptr + 1) < '8')
  298. byte = 8 * byte + *++reglineptr - '0';
  299. }
  300. break;
  301. case 'a':
  302. byte = 7;
  303. break;
  304. case 'b':
  305. byte = 8;
  306. break;
  307. case 'f':
  308. byte = 12;
  309. break;
  310. case 'n':
  311. byte = 10;
  312. break;
  313. case 'r':
  314. byte = 13;
  315. break;
  316. case 't':
  317. byte = 9;
  318. break;
  319. case 'v':
  320. byte = 11;
  321. break;
  322. case 'x':
  323. byte = '0';
  324. while (TRUE)
  325. {
  326. ++reglineptr;
  327. if (*reglineptr >= '0' && *reglineptr <= '9')
  328. byte = 16 * byte + *reglineptr - '0';
  329. else if (*reglineptr >= 'F' && *reglineptr <= 'F')
  330. byte = 16 * byte + *reglineptr - 'A';
  331. else if (*reglineptr >= 'a' && *reglineptr <= 'f')
  332. byte = 16 * byte + *reglineptr - 'F';
  333. else
  334. break;
  335. }
  336. --reglineptr;
  337. break;
  338. default:
  339. symname = reglineptr;
  340. error(UNKNOWN_ESCAPE_SEQUENCE);
  341. break;
  342. }
  343. }
  344. else if (byte < ' ' && byte >= 0)
  345. {
  346. symname = reglineptr;
  347. error(CTLINS);
  348. byte = ' ';
  349. }
  350. ++reglineptr;
  351. *bufptr++ = byte;
  352. }
  353. lineptr = reglineptr;
  354. getsym();
  355. lastexp.offset = databuf.fcbuf[0]; /* show only 1st char (if any) */
  356. mcount = bufptr - databuf.fcbuf;
  357. /* won't overflow, line length limits it */
  358. /* XXX - but now line length is unlimited */
  359. }
  360. /* common routine for IF/IFC */
  361. PRIVATE void doif(func)
  362. pfv func;
  363. {
  364. if (iflevel >= MAXIF)
  365. error(IFOV);
  366. else
  367. {
  368. ++iflevel;
  369. --ifstak;
  370. ifstak->elseflag = elseflag;
  371. elseflag = FALSE; /* prepare */
  372. if ((ifstak->ifflag = ifflag) != FALSE)
  373. /* else not assembling before, so not now & no ELSE's */
  374. {
  375. (*func) ();
  376. if (!(lastexp.data & UNDBIT) && lastexp.offset == 0)
  377. /* else expression invalid or FALSE, don't change flags */
  378. {
  379. ifflag = FALSE; /* not assembling */
  380. elseflag = TRUE;/* but ELSE will change that */
  381. }
  382. }
  383. else
  384. {
  385. /* Skip to EOL */
  386. while (sym != EOLSYM)
  387. getsym();
  388. }
  389. }
  390. }
  391. PUBLIC void fatalerror(err_str)
  392. char * err_str;
  393. {
  394. error(err_str);
  395. skipline();
  396. listline();
  397. finishup();
  398. }
  399. /* swap position with label position, do error, put back posn */
  400. /* also clear label ptr */
  401. PUBLIC void labelerror(err_str)
  402. char * err_str;
  403. {
  404. struct sym_s *oldgsymptr;
  405. char *oldlineptr;
  406. unsigned char oldsym;
  407. char *oldsymname;
  408. oldgsymptr = gsymptr;
  409. oldlineptr = lineptr;
  410. oldsym = sym;
  411. oldsymname = symname;
  412. lineptr = linebuf;
  413. getsym(); /* 1st symbol is label or symbol after
  414. * missing one */
  415. error(err_str);
  416. gsymptr = oldgsymptr;
  417. lineptr = oldlineptr;
  418. sym = oldsym;
  419. symname = oldsymname;
  420. label = NUL_PTR;
  421. }
  422. PRIVATE struct sym_s *needlabel()
  423. {
  424. register struct sym_s *symptr;
  425. if (sym != IDENT ||
  426. (symptr = gsymptr)->type & (MACBIT | MNREGBIT | VARBIT))
  427. {
  428. error(LABEXP);
  429. return NUL_PTR;
  430. }
  431. return symptr;
  432. }
  433. /* .ALIGN pseudo-op */
  434. PUBLIC void palign()
  435. {
  436. absexpres();
  437. if (!((lcdata |= lastexp.data) & UNDBIT))
  438. {
  439. popflags = POPLONG | POPHI | POPLO | POPLC;
  440. if (lastexp.offset != 0 &&
  441. (lcjump = lc % lastexp.offset) != 0)
  442. accumulate_rmb(lcjump = lastexp.offset - lcjump);
  443. }
  444. }
  445. /* .ASCIZ pseudo-op */
  446. PUBLIC void pasciz()
  447. {
  448. dofcc();
  449. databuf.fcbuf[mcount++] = 0;
  450. fcflag = TRUE;
  451. popflags = POPLO | POPLC;
  452. }
  453. /* .BLKW pseudo-op */
  454. PUBLIC void pblkw()
  455. {
  456. constdata(2);
  457. }
  458. /* BLOCK pseudo-op */
  459. PUBLIC void pblock()
  460. {
  461. if (blocklevel >= MAXBLOCK)
  462. error(BLOCKOV);
  463. else
  464. {
  465. register struct block_s *blockp;
  466. ++blocklevel;
  467. blockp = blockstak;
  468. blockstak = --blockp;
  469. blockp->data = lcdata;
  470. blockp->dp = dirpag;
  471. blockp->lc = lc;
  472. porg(); /* same as ORG apart from stacking */
  473. }
  474. }
  475. /* .BSS pseudo-op */
  476. PUBLIC void pbss()
  477. {
  478. setloc(BSSLOC);
  479. }
  480. /* COMM pseudo-op */
  481. PUBLIC void pcomm()
  482. {
  483. if (label == NUL_PTR)
  484. labelerror(MISLAB);
  485. else if (label->type & VARBIT)
  486. labelerror(VARLAB); /* variable cannot be COMM'd */
  487. else
  488. docomm();
  489. }
  490. /* .COMM pseudo-op */
  491. PUBLIC void pcomm1()
  492. {
  493. unsigned oldseg;
  494. if (label != NUL_PTR)
  495. labelerror(ILLAB);
  496. oldseg = lcdata & SEGM;
  497. setloc(BSSLOC);
  498. if ((label = needlabel()) != NUL_PTR && checksegrel(label))
  499. {
  500. /* Like import. */
  501. if (label->type & (EXPBIT | LABIT))
  502. error(ALREADY);
  503. else if( last_pass == 1 )
  504. label->data = lcdata | (FORBIT | IMPBIT | RELBIT);
  505. else
  506. label->data = lcdata | (IMPBIT | RELBIT);
  507. getsym();
  508. getcomma();
  509. if (label->type & (EXPBIT | LABIT))
  510. absexpres(); /* just to check it */
  511. else
  512. docomm();
  513. }
  514. setloc(oldseg);
  515. }
  516. /* .DATA pseudo-op */
  517. PUBLIC void pdata()
  518. {
  519. setloc(DATALOC);
  520. }
  521. /* ELSE pseudo-op */
  522. PUBLIC void pelse()
  523. {
  524. if (iflevel == 0)
  525. error(ELSEBAD);
  526. else
  527. {
  528. ifflag = FALSE; /* assume ELSE disabled */
  529. if (elseflag)
  530. {
  531. ifflag = TRUE; /* ELSE enabled */
  532. elseflag = FALSE;
  533. }
  534. }
  535. }
  536. /* ELSEIF pseudo-op */
  537. PUBLIC void pelseif()
  538. {
  539. doelseif(absexpres);
  540. }
  541. /* ELSEIFC pseudo-op */
  542. PUBLIC void pelsifc()
  543. {
  544. doelseif(scompare);
  545. }
  546. /* ENDB pseudo-op */
  547. PUBLIC void pendb()
  548. {
  549. if (label != NUL_PTR)
  550. labelerror(ILLAB);
  551. if (blocklevel == 0)
  552. error(ENDBBAD);
  553. else
  554. {
  555. register struct block_s *blockp;
  556. blockp = blockstak;
  557. lcdata = blockp->data;
  558. dirpag = blockp->dp;
  559. accumulate_rmb(blockp->lc - lc);
  560. lc = blockp->lc;
  561. --blocklevel;
  562. blockstak = blockp + 1;
  563. }
  564. }
  565. /* ENDIF pseudo-op */
  566. PUBLIC void pendif()
  567. {
  568. if (iflevel == 0)
  569. error(ENDIFBAD);
  570. else
  571. {
  572. ifflag = ifstak->ifflag;
  573. elseflag = ifstak->elseflag;
  574. ++ifstak;
  575. --iflevel;
  576. }
  577. }
  578. /* ENTER pseudo-op */
  579. PUBLIC void penter()
  580. {
  581. if (!(pedata & UNDBIT))
  582. error(REENTER);
  583. else
  584. {
  585. if (!((pedata = (pedata & ~UNDBIT) | lcdata) & UNDBIT))
  586. {
  587. progent = lc;
  588. popflags = POPLC;
  589. }
  590. }
  591. }
  592. /* ENTRY pseudo-op */
  593. PUBLIC void pentry()
  594. {
  595. doentexp(ENTBIT, 0);
  596. }
  597. /* EQU pseudo-op */
  598. PUBLIC void pequ()
  599. {
  600. register struct sym_s *labptr;
  601. if ((labptr = label) == NUL_PTR)
  602. labelerror(MISLAB);
  603. else if (labptr->type & COMMBIT)
  604. showredefinedlabel(); /* common cannot be EQU'd */
  605. else if (labptr->type & VARBIT)
  606. labelerror(VARLAB); /* variable cannot be EQU'd */
  607. else
  608. doequset(LABIT);
  609. }
  610. /* .EVEN pseudo-op */
  611. PUBLIC void peven()
  612. {
  613. popflags = POPLONG | POPHI | POPLO | POPLC;
  614. accumulate_rmb(lcjump = lastexp.data = lc & 1);
  615. }
  616. /* EXPORT pseudo-op */
  617. PUBLIC void pexport()
  618. {
  619. doentexp(0, 0);
  620. }
  621. /* FAIL pseudo-op */
  622. PUBLIC void pfail()
  623. {
  624. if(pass==last_pass) error(FAILERR);
  625. }
  626. /* FCB pseudo-op */
  627. PUBLIC void pfcb()
  628. {
  629. char *bufptr;
  630. offset_t firstbyte;
  631. bufptr = databuf.fcbuf;
  632. absexpres();
  633. firstbyte = lastexp.offset;
  634. while (TRUE)
  635. {
  636. checkdatabounds();
  637. *bufptr++ = lastexp.offset;
  638. ++mcount; /* won't overflow, line length limits it */
  639. if (sym != COMMA)
  640. break;
  641. symabsexpres();
  642. }
  643. lastexp.offset = firstbyte;
  644. popflags = POPLO | POPLC;
  645. fcflag = TRUE;
  646. }
  647. /* FCC pseudo-op */
  648. PUBLIC void pfcc()
  649. {
  650. dofcc();
  651. if (mcount != 0)
  652. {
  653. fcflag = TRUE;
  654. popflags = POPLO | POPLC;
  655. }
  656. }
  657. /* FDB pseudo-op */
  658. PUBLIC void pfdb()
  659. {
  660. struct address_s *adrptr;
  661. unsigned firstdata;
  662. offset_t firstword;
  663. adrptr = databuf.fdbuf;
  664. expres();
  665. firstword = lastexp.offset;
  666. firstdata = lastexp.data;
  667. while (TRUE)
  668. {
  669. *adrptr++ = lastexp;
  670. mcount += 2; /* won't overflow, line length limits it */
  671. if (sym != COMMA)
  672. break;
  673. symexpres();
  674. }
  675. lastexp.offset = firstword;
  676. lastexp.data = firstdata;
  677. popflags = POPHI | POPLO | POPLC;
  678. fdflag = TRUE;
  679. }
  680. #if SIZEOF_OFFSET_T > 2
  681. /* FQB pseudo-op */
  682. PUBLIC void pfqb()
  683. {
  684. struct address_s *adrptr;
  685. offset_t firstdata;
  686. offset_t firstword;
  687. adrptr = databuf.fqbuf;
  688. expres();
  689. firstword = lastexp.offset;
  690. firstdata = lastexp.data;
  691. while (TRUE)
  692. {
  693. *adrptr++ = lastexp;
  694. mcount += 4; /* won't overflow, line length limits it */
  695. if (sym != COMMA)
  696. break;
  697. symexpres();
  698. }
  699. lastexp.offset = firstword;
  700. lastexp.data = firstdata;
  701. popflags = POPLONG | POPHI | POPLO | POPLC;
  702. fqflag = TRUE;
  703. }
  704. #endif /* SIZEOF_OFFSET_T > 2 */
  705. /* .GLOBL pseudo-op */
  706. PUBLIC void pglobl()
  707. {
  708. if (binaryg)
  709. error(NOIMPORT);
  710. doentexp(0, IMPBIT);
  711. }
  712. /* IDENT pseudo-op (not complete) */
  713. PUBLIC void pident()
  714. {
  715. if (sym != IDENT)
  716. error(LABEXP);
  717. else
  718. getsym_nolookup(); /* should save ident string */
  719. }
  720. /* IF pseudo-op */
  721. PUBLIC void pif()
  722. {
  723. doif(absexpres);
  724. }
  725. /* IFC pseudo-op */
  726. PUBLIC void pifc()
  727. {
  728. doif(scompare);
  729. }
  730. /* IMPORT pseudo-op */
  731. PUBLIC void pimport()
  732. {
  733. struct sym_s *symptr;
  734. if (binaryg)
  735. error(NOIMPORT);
  736. while (TRUE)
  737. {
  738. if ((symptr = needlabel()) != NUL_PTR && checksegrel(symptr))
  739. {
  740. if (symptr->type & (COMMBIT | EXPBIT | LABIT))
  741. /* IMPORT is null if label (to be) declared */
  742. error(ALREADY);
  743. else if( last_pass == 1 )
  744. /* get current segment from lcdata, no need to mask rest */
  745. symptr->data = lcdata | (FORBIT | IMPBIT | RELBIT);
  746. else
  747. symptr->data = lcdata | (IMPBIT | RELBIT);
  748. }
  749. getsym();
  750. if (sym != COMMA)
  751. break;
  752. getsym();
  753. }
  754. }
  755. /* LCOMM pseudo-op */
  756. PUBLIC void plcomm()
  757. {
  758. lcommflag = TRUE;
  759. pcomm();
  760. }
  761. /* .LCOMM pseudo-op */
  762. PUBLIC void plcomm1()
  763. {
  764. lcommflag = TRUE;
  765. pcomm1();
  766. }
  767. /* .LIST pseudo-op */
  768. PUBLIC void plist()
  769. {
  770. bumpsem(&list, 1);
  771. }
  772. /* .NOLIST pseudo-op */
  773. PUBLIC void pnolist()
  774. {
  775. bumpsem(&list, -1);
  776. }
  777. /* LOC pseudo-op */
  778. PUBLIC void ploc()
  779. {
  780. if (label != NUL_PTR)
  781. labelerror(ILLAB);
  782. absexpres();
  783. if (!(lastexp.data & UNDBIT))
  784. {
  785. if (lastexp.offset >= NLOC)
  786. datatoobig();
  787. else
  788. setloc((unsigned) lastexp.offset);
  789. }
  790. }
  791. /* .MACLIST pseudo-op */
  792. PUBLIC void pmaclist()
  793. {
  794. bumpsem(&maclist, 1);
  795. }
  796. /* .MAP pseudo-op */
  797. PUBLIC void pmap()
  798. {
  799. absexpres();
  800. if (!(lastexp.data & UNDBIT))
  801. {
  802. mapnum = lastexp.offset;
  803. popflags = POPLO;
  804. if (lastexp.offset >= 0x100)
  805. datatoobig();
  806. }
  807. }
  808. /* ORG pseudo-op */
  809. PUBLIC void porg()
  810. {
  811. if (label != NUL_PTR)
  812. labelerror(ILLAB);
  813. absexpres();
  814. if (!((lcdata = lastexp.data) & UNDBIT))
  815. {
  816. accumulate_rmb(lastexp.offset - lc);
  817. binmbuf = lc = lastexp.offset;
  818. binmbuf_set = 1;
  819. popflags = POPLC;
  820. }
  821. }
  822. /* RMB pseudo-op */
  823. PUBLIC void prmb()
  824. {
  825. constdata(1);
  826. }
  827. /* .SECT pseudo-op */
  828. PUBLIC void psect()
  829. {
  830. if (label != NUL_PTR)
  831. labelerror(ILLAB);
  832. while (sym == IDENT)
  833. {
  834. if (!(gsymptr->type & MNREGBIT))
  835. error(ILL_SECTION);
  836. else switch (gsymptr->value_reg_or_op.op.routine)
  837. {
  838. case BSSOP:
  839. pbss();
  840. break;
  841. case DATAOP:
  842. pdata();
  843. break;
  844. case TEXTOP:
  845. ptext();
  846. break;
  847. default:
  848. error(ILL_SECTION);
  849. break;
  850. }
  851. getsym();
  852. if (sym == COMMA)
  853. getsym();
  854. }
  855. }
  856. /* SET pseudo-op */
  857. PUBLIC void pset()
  858. {
  859. register struct sym_s *labptr;
  860. if ((labptr = label) == NUL_PTR)
  861. labelerror(MISLAB);
  862. else if (labptr->type & COMMBIT)
  863. labelerror(RELAB); /* common cannot be SET'd */
  864. else
  865. doequset(labptr->type & LABIT ? 0 : VARBIT);
  866. }
  867. /* SETDP pseudo-op */
  868. PUBLIC void psetdp()
  869. {
  870. absexpres();
  871. if (!(lastexp.data & UNDBIT))
  872. {
  873. dirpag = lastexp.offset;
  874. popflags = POPLO;
  875. if (lastexp.offset >= 0x100)
  876. datatoobig();
  877. }
  878. }
  879. /* .TEXT pseudo-op */
  880. PUBLIC void ptext()
  881. {
  882. if( textseg <= 0 )
  883. setloc(TEXTLOC);
  884. else
  885. setloc(textseg);
  886. }
  887. /* .WARN pseudo-op */
  888. PUBLIC void pwarn()
  889. {
  890. bumpsem(&as_warn, -1);
  891. }
  892. #ifdef I80386
  893. /* USE16 pseudo-op */
  894. PUBLIC void puse16()
  895. {
  896. defsize = 2;
  897. #ifdef iscpu
  898. if( sym != EOLSYM )
  899. {
  900. absexpres();
  901. if (lastexp.data & UNDBIT)
  902. return;
  903. if( lastexp.offset > 8000 )
  904. setcpu((int) lastexp.offset / 100 % 10);
  905. else if( lastexp.offset > 15 )
  906. setcpu((int) lastexp.offset / 100);
  907. else
  908. setcpu((int) lastexp.offset);
  909. }
  910. #endif
  911. }
  912. /* USE16 pseudo-op */
  913. PUBLIC void puse32()
  914. {
  915. defsize = 4;
  916. #ifdef iscpu
  917. if(!iscpu(3)) setcpu(3);
  918. if( sym != EOLSYM )
  919. {
  920. absexpres();
  921. if (lastexp.data & UNDBIT)
  922. return;
  923. if( lastexp.offset > 15 )
  924. setcpu((int) lastexp.offset / 100);
  925. else
  926. setcpu((int) lastexp.offset);
  927. }
  928. #endif
  929. }
  930. #endif
  931. /* show redefined label and error, and set REDBIT */
  932. PRIVATE void showredefinedlabel()
  933. {
  934. register struct sym_s *labptr;
  935. labptr = label; /* showlabel() will kill label prematurely */
  936. showlabel();
  937. if (!(labptr->type & REDBIT))
  938. {
  939. labptr->type |= REDBIT;
  940. labelerror(RELAB);
  941. }
  942. }
  943. PUBLIC void showlabel()
  944. {
  945. register struct sym_s *labptr;
  946. labptr = label;
  947. lastexp.data = labptr->data;
  948. lastexp.offset = labptr->value_reg_or_op.value;
  949. popflags = POPLONG | POPHI | POPLO;
  950. label = NUL_PTR; /* show handled by COMM, EQU or SET */
  951. }
  952. /* set location segment */
  953. PRIVATE void setloc(seg)
  954. unsigned seg;
  955. {
  956. if (pass == last_pass && seg != (lcdata & SEGM))
  957. putobj((opcode_pt) (seg | OBJ_SET_SEG));
  958. {
  959. register struct lc_s *lcp;
  960. lcp = lcptr;
  961. lcp->data = lcdata;
  962. lcp->lc = lc;
  963. lcptr = lcp = lctab + (unsigned char) seg;
  964. lcdata = (lcp->data & ~SEGM) | (unsigned char) seg;
  965. binmbuf = lc = lcp->lc;
  966. popflags = POPLC;
  967. }
  968. }