3 #include <stdio.h> /* temp */
10 #include <sys/types.h>
14 #define SEEK_SET L_SET
19 /* Sept 10, 1997 - fix coredump caused by using wrong error reporting */
20 /* calling convention in three places. */
22 /* .globl _signal, _close, _lseek, _unlink, _umask, _chmod, __exit */
23 /* .globl _write, _read, _brk, _end, _open, _realloc, _fchmod */
24 /* .globl pass1, hshsiz, outmod, dot, dotdot, error */
25 /* .globl checkeos, curfb, savdot, ch, line, savop, inbuf, errflg */
26 /* .globl fbptr, fbtbl, symnum, hshtab, symblk, symleft, dotrel */
27 /* .globl symtab, aexit, overlaid, defund, a.outp, passno, filerr */
28 /* .globl wrterr, argb, curfb, nxtfb, usymtab */
29 /* .globl fin, fout, a.tmp1, ibufc, ibufp, obufp, outbuf, symbol */
30 /* .globl PSTENTSZ, SYMENTSZ, SYMBLKSZ, Newsym */
32 intptr_t *adrptr; /* r5 */
33 int opcode; /* (sp) or 2(sp) if rvalue is present */
34 int rvalue; /* (sp) */
40 /* mov fout,fin / tmp file is now input file */
41 /* mov $666,-(sp) / mode */
42 /* mov $3001 ,-(sp) / O_WRONLY|O_CREAT|O_TRUNC */
43 /* mov a.outp,-(sp) / filename */
46 /* mov r0,fout / file descriptor any good? */
47 /* bpl 1f / yes - br */
48 /* mov a.outp,-(sp) */
54 struct symbol *psymbol;
55 struct symbol **ppsymbol;
59 fout = open(a_outp, O_WRONLY|O_CREAT|O_TRUNC, 0666);
63 /* 'symnum' has number of symbols. The hashtable from pass 0 is no */
64 /* longer needed - we can reuse it directly for 'usymtab' if there are less */
65 /* than 'hshsiz' symbols. If there are more than 'hshsiz' (currently */
66 /* 1500) symbols we have to realloc. */
68 /* The 'fb' table (usually 0 long) is appended to the 'usymtab' (4 byte */
69 /* entries per symbol). */
72 /* sub fbtbl,r0 / # bytes in 'fb' table */
73 /* asr r0 / convert to number of words */
74 /* add symnum,r0 / add in number of symbols twice */
75 /* add symnum,r0 / because we need 2 words per symbol */
76 /* inc r0 / one more for terminator word */
78 symtot = (fbptr - fbtbl) + symnum + 1;
80 /* cmp r0,$hshsiz / is hashtable big enough already? */
81 /* blo 1f / yes -br */
82 /* asl r0 / convert to bytes */
84 /* mov hshtab,-(sp) */
85 /* jsr pc,_realloc / hshtab = realloc(hshtab, r0) */
88 /* iot / should never happen */
91 if (symtot > hshsiz) {
92 hshtab = (struct symbol **)realloc(hshtab, symtot * sizeof(struct symbol *));
100 /* mov r2,symblk / save ptr to start of block */
101 /* tst (r2)+ / skip link word */
102 /* mov $SYMBLKSZ,symleft / init amount left in block */
107 psymbol = symblk->data;
111 /* tst (r2) / end of symbol table block */
112 /* beq 4f / yes - br */
113 /* add $8.,symsiz / size of symbol table */
114 /* tst Newsym / are we doing new style? */
115 /* bne 8f / yes - br */
116 /* add $4,symsiz / no, symbol table entries are bigger */
120 if (psymbol->name == NULL)
122 /* printf("%s\n", psymbol->name); */
123 siz[3] += Newsym ? 8 : 12;
125 /* mov 2(r2),r0 / flags word */
127 /* cmp r0,$2 /text */
129 /* cmp r0,$3 /data */
131 /* add $31,r0 /mark "estimated" */
132 /* mov r0,(r1)+ / store flags word */
133 /* mov 4(r2),(r1)+ / copy value word */
140 flags = psymbol->flags & 037;
141 if (flags == FTEXT || flags == FDATA)
142 psymbol->flags = flags + FESTTEXT - FTEXT;
148 /* add $SYMENTSZ,r2 / skip to next symbol entry */
149 /* sub $SYMENTSZ,symleft / one symbol less in block */
150 /* cmp symleft,$SYMENTSZ / room for another symbol? */
151 /* bge 1b / yes - br */
153 /* printf("0x%08x 0x%08x\n", (ppsymbol - hshtab), psymbol->number); */
154 *ppsymbol++ = psymbol++;
159 /* mov *symblk,r2 / follow link to next block */
160 /* bne 9b / if not at end */
163 symblk = symblk->next;
166 /* The 'fb' table needs to be appended to the 'usymtab' table now */
169 /* mov r1,fbbufp / save start of 'fb' table */
171 /* cmp r0,fbptr / at end of table? */
172 /* bhis 2f / yes - br */
174 /* add $31,r4 / "estimated" */
176 /* mov (r0)+,(r1)+ */
182 while (psymbol < fbptr) {
183 psymbol->flags += FESTTEXT - FTEXT; /* FESTBSS ??? */
184 *ppsymbol++ = psymbol++;
187 /* mov r1,endtable */
188 /* mov $100000,(r1)+ */
193 /* mov $savdot,r0 / reset the 'psect' (text,data,bss) */
194 /* clr (r0)+ / counters for the next pass */
197 /* jsr pc,setup / init fb stuff */
204 /* jsr pc,pass1_2 / do pass 1 */
208 /* prepare for pass 2 */
210 /* cmp outmod,$777 */
236 siz[0] = (siz[0] + 1) & ~1;
237 siz[1] = (siz[1] + 1) & ~1;
238 siz[2] = (siz[2] + 1) & ~1;
241 /* mov r3,datbase / txtsiz */
242 /* mov r3,savdot+2 */
244 /* mov r3,bssbase / txtsiz+datsiz */
245 /* mov r3,savdot+4 */
249 base[2] = base[1] + siz[1];
257 /* mov r3,symseek+2 / 2*txtsiz+2*datsiz+20 */
260 seek[6] = (off_t)base[2] * 2 + 020;
264 /* mov r3,drelseek+2 / 2*txtsiz+datsiz */
265 /* mov r0,drelseek */
267 seek[4] = seek[6] - siz[1];
271 /* mov r3,trelseek+2 / txtsiz+datsiz+20 */
272 /* mov r0,trelseek */
274 seek[3] = seek[4] - siz[0];
279 /* mov r3,datseek+2 / txtsiz+20 */
281 seek[1] = seek[3] - siz[1];
288 /* cmp r1,endtable */
291 for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++)
296 /* mov $txtp,-(sp) */
298 /* mov trelseek,r0 */
299 /* mov trelseek+2,r1 */
300 /* mov $relp,-(sp) */
304 oset(&relp, seek[3]);
307 /* mov $txtmagic,r1 */
310 /* mov $txtp,-(sp) */
315 p1putw(&txtp, siz[0]);
316 p1putw(&txtp, siz[1]);
317 p1putw(&txtp, siz[2]);
318 p1putw(&txtp, siz[3]);
323 /* jsr pc,pass1_2 / do pass 2 */
331 /*polish off text and relocation */
333 /* mov $txtp,-(sp) */
335 /* mov $relp,-(sp) */
341 /* append full symbol table */
343 /* mov symseek+2,r1 */
344 /* mov $txtp,-(sp) */
347 oset(&txtp, seek[6]);
349 /* mov usymtab,r2 / pointer to first symbol block */
350 /* mov hshtab,r1 / 'type' and 'value' array */
364 /* mov $txtp,-(sp) */
382 /* mov $a.tmp1,-(sp) / unlink(a.tmp1) */
398 /* bic r0,outmod / fchmod(fout, outmod&umask(0)) */
399 /* mov outmod,(sp) */
406 fchmod(fout, outmod & ~umask(0));
413 /* jsr pc,__exit / _exit(errflg ? 2 : 0) */
419 /* mov 2(sp),r0 / filename string. no need to clean */
420 /* tst -(sp) / stack, this routine goes to saexit. */
432 void filerr(p) char *p; {
433 write(1, p, strlen(p));
435 /* mov $2,-(sp) / write(1, "?\n", 2) */
451 /* mov r2,symblk / save ptr to current sym block */
452 /* tst (r2)+ / skip link word */
453 /* mov $SYMBLKSZ,symleft / space left in symbol block */
455 /* mov (r2),r4 / pointer to symbol name */
456 /* beq 4f / end of block - br */
459 struct symbol **ppsymbol;
460 struct symbol *psymbol;
463 for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
467 break; /* reached the start of the fbtab */
469 /* mov $8.,r5 / max number to copy */
470 /* mov $symbol,r0 / destination buffer */
472 /* movb (r4),(r0)+ / copy a byte */
474 /* inc r4 / non null - bump source ptr */
478 strncpy(symbol, p, 8);
480 /* Now put four words of symbol name to the object file */
481 /* mov $4,r5 / number of words to do */
484 /* mov (r4)+,r0 / word (2 chars) of symbol name */
485 /* mov $txtp,-(sp) */
489 p1putw(&txtp, (symbol[0] & 0377) | ((symbol[1] & 0377) << 8));
490 p1putw(&txtp, (symbol[2] & 0377) | ((symbol[3] & 0377) << 8));
491 p1putw(&txtp, (symbol[4] & 0377) | ((symbol[5] & 0377) << 8));
492 p1putw(&txtp, (symbol[6] & 0377) | ((symbol[7] & 0377) << 8));
494 /* values from 'hshtab' (parallel array to symbol table) are retrieved now, */
495 /* they take the place of the flags and value entries of the symbol table. */
497 /* mov $txtp,-(sp) */
500 /* mov $txtp,-(sp) */
503 p1putw(&txtp, psymbol->flags);
504 p1putw(&txtp, psymbol->value);
506 /* add $SYMENTSZ,r2 / skip to next symbol */
507 /* sub $SYMENTSZ,symleft / one less symbol in block */
508 /* cmp symleft,$SYMENTSZ / room for another? */
509 /* bge 1b / yes - br */
511 /* mov *symblk,r2 / no, follow link to next block */
512 /* bne 9b / unless it's end of list */
520 /* mov $4,totalsz+2 / string table min size is 4 */
523 struct symbol **ppsymbol;
524 struct symbol *psymbol;
530 /* mov r2,symblk / save ptr to current symbol block */
531 /* tst (r2)+ / skip link word */
532 /* mov $SYMBLKSZ,symleft / amount of space left in block */
534 /* mov (r2),r4 / pointer to symbol's string */
535 /* beq 4f / end of block - br */
537 for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
541 break; /* reached the start of the fbtab */
543 /* mov totalsz,r0 / now output the... */
544 /* mov $txtp,-(sp) / high order of the string index... */
545 /* jsr pc,putw / to the object file */
546 /* mov totalsz+2,r0 */
547 /* mov $txtp,-(sp) */
548 /* jsr pc,putw / and the low order word */
550 /* tstb (r4)+ / find the end of the string */
552 /* sub (r2),r4 / compute length including the null */
553 /* add r4,totalsz+2 / offset of next string */
556 p1putw(&txtp, (int)(totalsz >> 16) & 0177777);
557 p1putw(&txtp, (int)totalsz & 0177777);
558 totalsz += strlen(p) + 1;
560 /* mov (r1)+,r0 / 'type' word of symbol */
561 /* mov $txtp,-(sp) */
563 /* mov (r1)+,r0 / 'value' word of symbol */
564 /* mov $txtp,-(sp) */
567 p1putw(&txtp, psymbol->flags);
568 p1putw(&txtp, psymbol->value);
570 /* add $SYMENTSZ,r2 / advance to next symbol */
571 /* sub $SYMENTSZ,symleft / adjust amount left in symbol block */
572 /* cmp symleft,$SYMENTSZ / is there enough for another symbol? */
573 /* bge 1b / yes - br */
575 /* mov *symblk,r2 / follow link to next symbol block */
576 /* bne 9b / more - br */
580 /* mov totalsz,r0 / now output the string table length */
581 /* mov $txtp,-(sp) / high order word first */
583 /* mov totalsz+2,r0 / followed by the low order */
584 /* mov $txtp,-(sp) */
587 p1putw(&txtp, (int)(totalsz >> 16) & 0177777);
588 p1putw(&txtp, (int)totalsz & 0177777);
590 /* Now write the strings out */
592 /* mov usymtab,r2 / start at beginning of symbols */
594 /* mov r2,symblk / save pointer to current block */
595 /* tst (r2)+ / skip link word */
596 /* mov $SYMBLKSZ,symleft / amount left in block */
598 /* mov (r2),r4 / pointer to symbol's string */
599 /* beq 4f / at end of block - br */
601 for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
605 break; /* reached the start of the fbtab */
607 /* jsr pc,putstring / write out the string */
611 /* add $SYMENTSZ,r2 / advance to next symbol */
612 /* sub $SYMENTSZ,symleft / adjust amount left in block */
613 /* cmp symleft,$SYMENTSZ / enough for another symbol? */
614 /* bge 1b / yes - br */
616 /* mov *symblk,r2 / move to next block of symbols */
617 /* bne 9b / any left - br */
621 /* probably not necessary but let us leave the file size on an even */
624 /* bit $1,totalsz+2 / odd number of bytes in string table? */
625 /* beq 5f / no - br */
626 /* mov symblk,r4 / we know 'symblk' points to a null */
627 /* jsr pc,putstring / output a single null */
636 /* R4 has the address of a null terminated string to write to the output */
637 /* file. The terminating null is included in the output. This routine */
638 /* "inlines" the 'txtp seek structure' manipulation because the 'putw' */
639 /* routine was 1) not suitable to byte output and 2) symbol strings are */
640 /* only written using the 'txtp' (as opposed to 'relp' - relocation info) */
645 void putstring(p) char *p; {
648 /* cmp txtp,txtp+2 / room for another byte? */
649 /* bhis 1f / no - br */
651 /* movb (r4),*txtp / put byte in buffer */
652 /* inc txtp / advance output position */
653 /* tstb (r4)+ / did we just do the null? */
654 /* bne putstring / no - go again */
655 /* rts pc / yes - we're done, return */
657 while (txtp.append < txtp.limit) {
664 /* mov r2,-(sp) / save r2 from being destroyed */
665 /* mov $txtp,-(sp) / flush buffered output and... */
666 /* jsr pc,flush / reset the pointers */
667 /* mov (sp)+,r2 / restore symbol pointer */
668 /* br 3b / go output a byte */
677 /* bisb defund,(r1) */
680 void doreloc(psymbol) struct symbol *psymbol; {
683 flags = psymbol->flags;
685 psymbol->flags = defund;
697 /* add bssbase,2(r1) */
701 psymbol->value += base[2];
705 /* add datbase,2(r1) */
710 psymbol->value += base[1];
732 /* cmp r4,$curfb+40. */
735 memset(curfb, 0, 10 * sizeof(intptr_t));
736 memset(nxtfb, 0, 10 * sizeof(intptr_t));
745 for (label = 0; label < 10; label++)
748 /* just rewind /tmp/atm1xx rather than close and re-open */
753 /* jsr pc,_lseek / lseek(fin, 0L, 0) */
756 lseek(fin, 0L, SEEK_SET);
768 void outw(value, flags) int value; int flags; {
773 printf("%04x: %04x (%04x)\n", pdot->value, value & 0177777,
776 if (pdot->flags != FBSS) {
781 if ((pdot->value & 1) == 0) {
794 /* asr r3 / get relative pc bit */
798 relocate = (flags >> 15) & 1;
800 if (flags == FGLOBAL) {
802 /* external references */
803 /* mov $666,outmod / make nonexecutable */
807 /* bis $4,r3 / external relocation */
812 flags = (xsymbol->number << 3) | 4;
815 /* bic $40,r3 / clear any ext bits */
818 /* cmp r3,$33 / est. text, data */
826 /* mov $1,r3 / make absolute */
832 if (flags == FESTTEXT ||
848 if (flags >= FTEXT && flags <= FBSS) {
850 value += pdotdot->value;
860 value -= pdotdot->value;
875 flags = (flags << 1) | relocate;
878 /* mov $txtp,-(sp) */
884 p1putw(&txtp, value);
888 /* mov $relp,-(sp) */
894 p1putw(&relp, flags);
925 /* cmp dot-2,$4 / test bss mode */
928 void outb(value, flags) int value; int flags; {
931 printf("%04x: %02x (%04x)\n", pdot->value, value & 0377,
934 if (pdot->flags == FBSS) {
937 /* bug!! didn't increment dot's value */
958 if ((pdot->value & 1) == 0) {
960 /* mov $txtp,-(sp) */
963 /* mov $relp,-(sp) */
966 p1putw(&txtp, value);
986 *(txtp.append - 1) = (char)value;
996 /* pass 1 and 2 common code */
1004 /* jsr pc,checkeos */
1010 struct symbol *psymbol;
1018 if (token != TNEWFILE && token != TSTRING) {
1031 if (token == TABS) {
1048 if (token == TEQUAL)
1050 if (token == TCOLON)
1060 /* movb dotrel,r0 */
1062 /* cmp dot,txtsiz-4(r0) */
1066 /* mov dot,txtsiz-4(r0) */
1072 flags = pdot->flags - FTEXT;
1073 if (siz[flags] < pdot->value)
1074 siz[flags] = pdot->value;
1091 if (tokensave >= 0 && tokensave < TASCII) {
1092 if (tokensave != TABS2) {
1113 psymbol = (struct symbol *)tokensave;
1115 flags = psymbol->flags & 037;
1116 if (flags && (flags < FESTTEXT || flags > FESTDATA))
1120 /* bis dotrel,(r4) */
1121 /* mov 2(r4),brdelt */
1122 /* sub dot,brdelt */
1126 psymbol->flags = (psymbol->flags & ~037) | pdot->flags;
1127 brdelt = psymbol->value - pdot->value;
1128 psymbol->value = pdot->value;
1139 if (psymbol->value != pdot->value)
1142 printf("%04x: %s\n", psymbol->value & 0177777, psymbol->name);
1150 /* mov curfb(r4),r0 */
1151 /* movb dotrel,(r0) */
1152 /* mov 2(r0),brdelt */
1153 /* sub dot,brdelt */
1160 psymbol = *(struct symbol **)curfb[label];
1161 psymbol->flags = pdot->flags;
1162 brdelt = psymbol->value - pdot->value;
1163 psymbol->value = pdot->value;
1166 printf("%04x: %d\n", psymbol->value & 0177777, label);
1174 /* cmp r1,$dotrel /test for dot */
1177 /* cmp r3,dotrel / can't change relocation */
1183 psymbol = (struct symbol *)tokensave;
1184 if (psymbol == pdot) {
1185 leftflags &= ~FGLOBAL;
1186 /* printf("leftflags 0%o pdot->flags 0%o\n", leftflags, pdot->flags); */
1187 if (leftflags != pdot->flags)
1190 /* cmp r3,$4 / bss */
1196 if (leftflags == FBSS) {
1197 pdot->value = leftvalue;
1200 printf("%04x: .\n", pdot->value & 0177777);
1219 leftvalue -= pdot->value;
1245 if (leftflags == FGLOBAL)
1254 psymbol->flags &= ~037;
1262 psymbol->flags |= leftflags;
1263 psymbol->value = leftvalue;
1266 printf("%04x: %s\n", psymbol->value & 0177777,
1282 /* printf("ealoop token = 0x%08x\n", token); */
1283 if (token == TNEWLINE) {
1287 while ((argch = getc(argfp)) != EOF) {
1294 else if (token == TENDFILE)
1311 return token == TNEWLINE || token == TSEMICOLON || token == TENDFILE;
1316 /* mov nxtfb(r4),r1 */
1317 /* mov r1,curfb(r4) */
1324 void fbadv(label) int label; {
1325 struct symbol **ppsymbol;
1326 struct symbol *psymbol;
1328 ppsymbol = (struct symbol **)nxtfb[label];
1329 curfb[label] = (intptr_t)ppsymbol;
1330 if (ppsymbol == NULL) {
1345 psymbol = *ppsymbol;
1346 } while (psymbol && psymbol->number != label);
1348 /* mov r1,nxtfb(r4) */
1352 nxtfb[label] = (intptr_t)ppsymbol;
1363 /* mov r1,(r3)+ / next slot */
1365 void oset(pstream, offset) struct stream *pstream; off_t offset; {
1366 pstream->append = pstream->data + ((int)offset & 01777);
1370 /* mov r1,(r3)+ / buf max */
1372 pstream->limit = pstream->data + 02000;
1375 /* mov r2,(r3)+ / seek addr */
1377 pstream->offset = offset;
1381 /* mov (sp)+,(sp) */
1390 /* mov (r2)+,r1 / slot */
1391 /* cmp r1,(r2) / buf max */
1406 /* mov (sp)+,(sp) */
1410 void p1putw(pstream, word) struct stream *pstream; int word; {
1411 /* printf("p1putw 0x%08x %04x\n", pstream, word); */
1412 if (pstream->append >= pstream->limit)
1413 /* note!! should be pstream->limit - 1, but it never makes any difference */
1415 *pstream->append++ = (char)word;
1416 *pstream->append++ = (char)(word >> 8);
1421 /* mov (sp)+,(sp) */
1422 /* cmp (r2)+,(r2)+ */
1424 /* clr -(sp) / lseek(fout, (r2)L+, L_SET) */
1425 /* mov 2(r2),-(sp) */
1426 /* mov (r2)+,-(sp) */
1428 /* mov fout,-(sp) */
1432 void flush(pstream) struct stream *pstream; {
1436 lseek(fout, pstream->offset, SEEK_SET);
1438 /* cmp -(sp),-(sp) / write(fout, <buf>, <len>) */
1440 /* add r2,r1 / write address */
1442 start = pstream->data + ((int)pstream->offset & 01777);
1444 /* mov r1,-(sp) / { <buf> } */
1446 /* bis $1777,-(r2) */
1447 /* add $1,(r2) / new seek addr */
1449 /* cmp -(r2),-(r2) */
1451 pstream->offset = (pstream->offset | 01777) + 1;
1455 /* mov r1,2(sp) / count */
1456 /* mov r0,(r2) / new next slot */
1458 count = pstream->append - start;
1459 pstream->append = pstream->data;
1461 /* mov fout,-(sp) */
1462 /* mov r1,6(sp) / protect r1 from library */
1468 /* fall thru to wrterr */
1470 if (write(fout, start, count) < 0)
1475 /* mov $8f-9f,-(sp) / write(1, 9f, 8f-9f) */
1484 write(1, "as: write error\n", 16);
1490 /* <as: write error\n> */
1505 /* printf("readop() savop = 0x%08x\n", savop); */
1525 if (word >= 0 && word < TASCII)
1529 token = (intptr_t)hshtab[word - 04000];
1531 /* remove PST flag (1000) then multiply by PSTENTSZ. In pass 0 the PST */
1532 /* symbol number was divided by PSTENTSZ(to make it fit) - we now reverse */
1537 /* mul $PSTENTSZ,r5 */
1540 /* add $dotrel,r4 / point at dot's flag field */
1545 token = (intptr_t)(symtab + (word - 01000));
1572 /* mov r1,-(sp) / protect r1 from library */
1573 /* mov $1024.,-(sp) / read(fin, inbuf, 1024) */
1574 /* mov $inbuf,-(sp) */
1580 ibufc = read(fin, inbuf, 1024);
1591 /* mov $inbuf,ibufp */
1594 ibufc /= sizeof(short);
1595 ibufp = (short *)inbuf;
1596 /* note!! rather silly, ibufc doesn't get decremented through this path */
1626 outw(leftvalue, leftflags);
1630 struct symbol *psymbol;
1633 /* printf("opline() token 0x%08x\n", token); */
1634 if (token >= 0 && token < TASCII) {
1635 if (token == TNEWFILE)
1637 else if (token == TSTRING)
1645 /* cmp r0,$24 /reg */
1647 /* cmp r0,$33 /est text */
1649 /* cmp r0,$34 / est data */
1656 psymbol = (struct symbol *)token;
1657 flags = psymbol->flags;
1658 if (flags <= FBSS || flags == FREGISTER || flags == FESTTEXT ||
1659 flags == FESTDATA || flags > FJCOND) {
1664 /* mov 2(r4),-(sp) */
1669 /* mov $adrbuf,r5 */
1671 /* mov $-1,rlimit */
1672 /* jmp *1f-10.(r0) */
1674 opcode = psymbol->value;
1743 #if 1 /* modifications for dec syntax */
1781 case FREGISTER: /* can never get here */
1860 /* movb $'\n,(r1)+ */
1889 argfp = fopen(argb, "r");
1891 while ((argch = getc(argfp)) != EOF) {
1902 /* opl30: / mul, div etc */
1904 /* mov $1000,rlimit */
1913 /* opl14: / flop freg,fsrc */
1921 /* opl5: / flop src,freg */
1922 /* mov $400,rlimit */
1929 /* opl13: /double */
1961 /* printf("op2b %d 0x%08x 0x%08x\n", swapf, rvalue, leftvalue); */
1965 leftvalue = tempvalue;
1971 /* cmp (sp),rlimit */
1980 rvalue = (rvalue & 0377) << 6; /* seems a bit stupid */
1982 if ((unsigned int)rvalue >= (unsigned int)rlimit)
1984 printf("a 0x%08x 0x%08x\n", rvalue, rlimit);
1993 outw(leftvalue | rvalue | opcode, 0);
1995 /* mov $adrbuf,r1 */
2001 /* mov (r1)+,xsymbol */
2008 while (adrtmp < adrptr) {
2009 leftvalue = *adrtmp++;
2010 leftflags = *adrtmp++;
2011 xsymbol = (struct symbol *)*adrtmp++;
2012 outw(leftvalue, leftflags);
2016 /* opl15: / single operand */
2026 /* mov $400,rlimit */
2028 /* cmp r2,$4 / see if source is fregister */
2033 /* mov $174000,(sp) */
2047 /* opl36: / jeq, jne, etc */
2059 /* add r2,dot / if doesn't fit */
2072 /* xor r0,r2 / flip cond, add ".+6" */
2077 /* mov $jmp+37,r2 */
2087 pdot->value += setbr(leftvalue) ? 4 : 2;
2092 outw(0000137, FABS); /* jmp */
2093 outw(leftvalue, leftflags);
2101 pdot->value += setbr(leftvalue) ? 6 : 2;
2106 outw(opcode ^ 0402, FABS); /* jne, jeq, etc .+6 */
2107 outw(0000137, FABS); /* jmp */
2108 outw(leftvalue, leftflags);
2115 /* jsr pc,checkreg */
2137 opcode |= leftvalue << 6;
2143 leftvalue = pdot->value - leftvalue;
2144 if (leftvalue < -2 || leftvalue > 0175)
2175 leftvalue -= pdot->value;
2176 if (leftvalue < -254 || leftvalue > 256)
2185 /* cmp r3,dot-2 / same relocation as . */
2189 /* bic $177400,r2 */
2195 leftvalue = ((leftvalue >> 1) - 1) & 0377;
2207 outw(leftvalue | opcode, 0);
2224 /* jsr pc,checkreg */
2235 /* jsr pc,checkreg */
2256 if (leftvalue < 0 || leftvalue >= 256)
2267 outw(leftvalue | opcode, leftflags);
2270 /* opl16: / .byte */
2284 outb(leftvalue, leftflags);
2285 if (token != TCOMMA)
2291 #if 1 /* modifications for dec syntax */
2295 outw(leftvalue, leftflags);
2296 if (token != TCOMMA)
2303 /* opl17: / < (.ascii) */
2320 outb(token & 0377, FABS);
2329 /* beq 2f / bss mode */
2341 if (pdot->value & 1) {
2342 if (pdot->flags != FBSS)
2367 /* opl23: /.globl */
2381 struct symbol *psymbol;
2384 if (token >= 0 && token < TASCII)
2386 psymbol = (struct symbol *)token;
2387 psymbol->flags |= FGLOBAL;
2389 if (token != TCOMMA)
2395 /* opl25: / .text, .data, .bss */
2403 /* mov dot,savdot-4(r1) */
2406 /* mov $txtp,-(sp) */
2408 /* mov $relp,-(sp) */
2412 /* add $txtseek-[4*25],r2 */
2416 /* mov $txtp,-(sp) */
2418 /* add $trelseek-txtseek,r2 */
2422 /* mov $relp,-(sp) */
2426 /* mov savdot-[2*25](r0),dot */
2429 /* mov r0,dot-2 / new . relocation */
2434 pdot->value = (pdot->value + 1) & ~1;
2435 savdot[pdot->flags - FTEXT] = pdot->value;
2440 oset(&txtp, seek[0]);
2442 oset(&relp, seek[3]);
2444 pdot->value = savdot[0];
2445 pdot->flags = FTEXT;
2449 pdot->value = (pdot->value + 1) & ~1;
2450 savdot[pdot->flags - FTEXT] = pdot->value;
2455 oset(&txtp, seek[1]);
2457 oset(&relp, seek[4]);
2459 pdot->value = savdot[1];
2460 pdot->flags = FDATA;
2464 pdot->value = (pdot->value + 1) & ~1;
2465 savdot[pdot->flags - FTEXT] = pdot->value;
2466 if (passno) { /* this is not really needed: */
2470 oset(&txtp, seek[2]);
2472 oset(&relp, seek[5]);
2474 pdot->value = savdot[2];
2495 struct symbol *psymbol;
2497 if (token >= 0 && token < TASCII)
2499 psymbol = (struct symbol *)token;
2503 if ((psymbol->flags & 037) == 0) {
2504 psymbol->flags |= FGLOBAL;
2505 psymbol->value = leftvalue;
2513 /* printf("addres() token = 0x%08x\n", token); */
2514 indirect = 0; /* it has a different meaning on pass 1/2 */
2554 /* mov xsymbol,(r5)+ */
2556 /* jsr pc,checkreg */
2557 /* jsr pc,checkrp */
2565 if (token == TLPAREN) {
2567 *adrptr++ = leftvalue;
2568 *adrptr++ = leftflags;
2569 *adrptr++ = (intptr_t)xsymbol;
2573 leftvalue |= 060 | indirect;
2578 /* jsr pc,checkreg */
2583 else if (leftflags == FREGISTER) {
2585 leftvalue |= indirect;
2591 /* bis $100000,r3 */
2594 /* cmp r5,$adrbuf */
2600 leftflags |= 0100000; /* relocate flag */
2601 leftvalue -= (pdot->value + 4);
2602 if (adrptr != adrbuf)
2605 /* mov r2,(r5)+ / index */
2606 /* mov r3,(r5)+ / index reloc. */
2607 /* mov xsymbol,(r5)+ / index global */
2608 /* mov $67,r2 / address mode */
2612 *adrptr++ = leftvalue;
2613 *adrptr++ = leftflags;
2614 *adrptr++ = (intptr_t)xsymbol;
2615 leftvalue = 067 | indirect;
2622 /* jsr pc,checkrp */
2623 /* jsr pc,checkreg */
2632 if (token != TPLUS) {
2639 /* mov xsymbol,(r5)+ */
2647 *adrptr++ = (intptr_t)xsymbol;
2665 leftvalue |= 020 | indirect;
2679 /* jsr pc,checkrp */
2680 /* jsr pc,checkreg */
2688 if (token != TLPAREN) {
2698 leftvalue |= indirect | 040;
2707 /* mov xsymbol,(r5)+ */
2715 *adrptr++ = leftvalue;
2716 *adrptr++ = leftflags;
2717 *adrptr++ = (intptr_t)xsymbol;
2718 leftvalue = indirect | 027; /* means (pc)+ */
2756 if (leftvalue > 7 || (leftflags >= FTEXT && leftflags <= FBSS)) {
2774 if (token != TRPAREN)
2788 int setbr(value) int value; {
2791 if (brtabp >= brlen)
2802 value -= pdot->value;
2812 if (value < -254 || value > 256) {
2819 /* bisb r0,brtab(r1) */
2822 brtab[index >> 3] |= 1 << (index & 7);
2844 if (brtabp >= brlen)
2852 /* movb brtab(r1),r1 */
2854 /* ror r1 / 0-bit into c-bit */
2858 return brtab[index >> 3] & (1 << (index & 7));
2877 struct symbol *psymbol;
2879 /* printf("expres()\n"); */
2906 if (token < 0 || token >= TASCII) {
2907 psymbol = (struct symbol *)token;
2908 rightflags = psymbol->flags;
2909 if (rightflags == 0 && passno)
2915 /* Bill Shannon's hack to the assembler to force globl text */
2916 /* references to remain undefined so that the link editor may */
2917 /* resolve them. This is necessary if a function is used as an */
2918 /* arg in an overlay located piece of code, and the function is */
2919 /* actually in another overlay. Elsewise, the assembler fix's up */
2920 /* the reference before the link editor changes the globl refrence */
2921 /* to the thunk. -wfj 5/80 */
2922 /* cmp r0,$42 / is it globl text ? */
2924 /* mov $40,r0 / yes, treat it as undefined external */
2927 if (overlaid && rightflags == (FTEXT | FGLOBAL))
2928 rightflags = FGLOBAL;
2932 /* mov r4,xsymbol */
2937 if (rightflags == FGLOBAL) {
2938 xsymbol = (struct symbol *)token;
2946 rightvalue = psymbol->value;
2955 /* mov curfb-[2*141](r4),r0 */
2961 if (token >= TLABEL) {
2962 if (token < TLABEL + 10)
2963 psymbol = *(struct symbol **)
2964 curfb[token - TLABEL];
2966 psymbol = *(struct symbol **)
2967 nxtfb[token - (TLABEL + 10)];
2968 rightvalue = psymbol->value;
2969 rightflags = psymbol->flags;
3062 if (optoken != TPLUS)
3079 /* printf("exnum1() numval = 0%o\n", numval); */
3080 rightvalue = numval;
3087 /* printf("exnum() token = 0%o\n", rightvalue); */
3097 /* jsr pc,expres1 */
3113 tempvalue = leftvalue;
3114 tempflags = leftflags;
3115 temptoken = optoken;
3118 if (token != TRBRACK)
3120 rightflags = leftflags;
3121 rightvalue = leftvalue;
3122 leftflags = tempflags;
3123 leftvalue = tempvalue;
3124 optoken = temptoken;
3131 /* cmp (sp),(r5)+ */
3226 leftflags = rightflags;
3237 /* mov $relte2,r5 */
3245 leftvalue = ((unsigned int)leftvalue & 0177777) >> rightvalue;
3251 leftvalue <<= rightvalue;
3256 /* mov $relte2,r5 */
3270 temp = rightvalue & 0177777;
3272 leftvalue = (leftvalue & 0177777) % temp;
3274 error('0'); /* a nick innovation */
3281 /* mov $reltp2,r5 */
3289 leftvalue += rightvalue;
3294 /* mov $reltm2,r5 */
3301 leftvalue -= rightvalue;
3306 /* mov $relte2,r5 */
3314 leftvalue &= rightvalue;
3319 /* mov $relte2,r5 */
3326 leftvalue |= rightvalue;
3331 /* mov $relte2,r5 */
3339 leftvalue *= rightvalue;
3344 /* mov $relte2,r5 */
3357 temp = rightvalue & 0177777;
3359 leftvalue = (leftvalue & 0177777) / temp;
3361 error('0'); /* a nick innovation */
3368 /* mov $relte2,r5 */
3376 leftvalue += ~rightvalue;
3392 void combin(table) char *table; {
3410 global = (rightflags | leftflags) & FGLOBAL;
3413 if (rightflags > leftflags) {
3415 rightflags = leftflags;
3421 /* cmp r5,$reltm2 */
3434 if (table == reltm2 && rightflags == leftflags)
3440 leftflags |= global;
3459 leftflags = table[maprel(rightflags) * 6 + maprel(leftflags)];
3470 if (leftflags < 0) {
3499 int maprel(flags) int flags; {
3500 if (flags == FGLOBAL)
3514 /* .byte 0, 0, 0, 0, 0, 0 */
3515 /* .byte 0, M, 2, 3, 4,40 */
3516 /* .byte 0, 2, X, X, X, X */
3517 /* .byte 0, 3, X, X, X, X */
3518 /* .byte 0, 4, X, X, X, X */
3519 /* .byte 0,40, X, X, X, X */
3531 /* .byte 0, 0, 0, 0, 0, 0 */
3532 /* .byte 0, M, 2, 3, 4,40 */
3533 /* .byte 0, X, 1, X, X, X */
3534 /* .byte 0, X, X, 1, X, X */
3535 /* .byte 0, X, X, X, 1, X */
3536 /* .byte 0, X, X, X, X, X */
3548 /* .byte 0, 0, 0, 0, 0, 0 */
3549 /* .byte 0, M, X, X, X, X */
3550 /* .byte 0, X, X, X, X, X */
3551 /* .byte 0, X, X, X, X, X */
3552 /* .byte 0, X, X, X, X, X */
3553 /* .byte 0, X, X, X, X, X */
3565 /* a.out: <a.out\0> */
3569 char *a_outp = "a.out";
3573 short *obufp = outbuf;
3583 /* tseekp: txtseek */
3585 off_t *tseekp = seek;
3587 /* rseekp: trelseek */
3589 off_t *rseekp = seek + 3;
3604 /* trelseek:.=.+4 */
3605 /* drelseek:.=.+4 */
3613 /* brtab: .=.+[brlen\/8.] */
3615 char brtab[brlen / 8];
3627 struct symbol **fbbufp;
3642 /* overlaid: .=.+2 */
3646 /* adrbuf: .=.+12. */
3652 struct symbol *xsymbol;
3696 /* endtable:.=.+2 */
3698 struct symbol **endtable;
3700 /* totalsz: / string table length */