1: / Sept 10, 1997 - fix coredump caused by using wrong error reporting 2: / calling convention in three places. 3: 4: .globl _signal, _close, _lseek, _unlink, _umask, _chmod, __exit 5: .globl _write, _read, _brk, _end, _open, _realloc, _fchmod 6: .globl pass1, hshsiz, outmod, dot, dotdot, error 7: .globl checkeos, curfb, savdot, ch, line, savop, inbuf, errflg 8: .globl fbptr, fbtbl, symnum, hshtab, symblk, symleft, dotrel 9: .globl symtab, aexit, overlaid, defund, a.outp, passno, filerr 10: .globl wrterr, argb, curfb, nxtfb, usymtab 11: .globl fin, fout, a.tmp1, ibufc, ibufp, obufp, outbuf, symbol 12: .globl PSTENTSZ, SYMENTSZ, SYMBLKSZ, Newsym 13: 14: pass1: 15: mov fout,fin / tmp file is now input file 16: mov $666,-(sp) / mode 17: mov $3001 ,-(sp) / O_WRONLY|O_CREAT|O_TRUNC 18: mov a.outp,-(sp) / filename 19: jsr pc,_open 20: add $6,sp 21: mov r0,fout / file descriptor any good? 22: bpl 1f / yes - br 23: mov a.outp,-(sp) 24: jsr pc,filerr 25: 1: 26: 27: / 'symnum' has number of symbols. The hashtable from pass 0 is no 28: / longer needed - we can reuse it directly for 'usymtab' if there are less 29: / than 'hshsiz' symbols. If there are more than 'hshsiz' (currently 30: / 1500) symbols we have to realloc. 31: / 32: / The 'fb' table (usually 0 long) is appended to the 'usymtab' (4 byte 33: / entries per symbol). 34: 35: mov fbptr,r0 36: sub fbtbl,r0 / # bytes in 'fb' table 37: asr r0 / convert to number of words 38: add symnum,r0 / add in number of symbols twice 39: add symnum,r0 / because we need 2 words per symbol 40: inc r0 / one more for terminator word 41: cmp r0,$hshsiz / is hashtable big enough already? 42: blo 1f / yes -br 43: asl r0 / convert to bytes 44: mov r0,-(sp) 45: mov hshtab,-(sp) 46: jsr pc,_realloc / hshtab = realloc(hshtab, r0) 47: mov r0,hshtab 48: bne 1f 49: iot / should never happen 50: 1: 51: mov hshtab,r1 52: mov usymtab,r2 53: 9: 54: mov r2,symblk / save ptr to start of block 55: tst (r2)+ / skip link word 56: mov $SYMBLKSZ,symleft / init amount left in block 57: 1: 58: tst (r2) / end of symbol table block 59: beq 4f / yes - br 60: add $8.,symsiz / size of symbol table 61: tst Newsym / are we doing new style? 62: bne 8f / yes - br 63: add $4,symsiz / no, symbol table entries are bigger 64: 8: 65: mov 2(r2),r0 / flags word 66: bic $!37,r0 67: cmp r0,$2 /text 68: blo 2f 69: cmp r0,$3 /data 70: bhi 2f 71: add $31,r0 /mark "estimated" 72: mov r0,(r1)+ / store flags word 73: mov 4(r2),(r1)+ / copy value word 74: br 3f 75: 2: 76: clr (r1)+ 77: clr (r1)+ 78: 3: 79: add $SYMENTSZ,r2 / skip to next symbol entry 80: sub $SYMENTSZ,symleft / one symbol less in block 81: cmp symleft,$SYMENTSZ / room for another symbol? 82: bge 1b / yes - br 83: 4: 84: mov *symblk,r2 / follow link to next block 85: bne 9b / if not at end 86: 1: 87: 88: / The 'fb' table needs to be appended to the 'usymtab' table now 89: 90: mov fbtbl,r0 91: mov r1,fbbufp / save start of 'fb' table 92: 1: 93: cmp r0,fbptr / at end of table? 94: bhis 2f / yes - br 95: mov (r0)+,r4 96: add $31,r4 / "estimated" 97: mov r4,(r1)+ 98: mov (r0)+,(r1)+ 99: br 1b 100: 2: 101: mov r1,endtable 102: mov $100000,(r1)+ 103: 104: mov $savdot,r0 / reset the 'psect' (text,data,bss) 105: clr (r0)+ / counters for the next pass 106: clr (r0)+ 107: clr (r0)+ 108: jsr pc,setup / init fb stuff 109: 110: jsr pc,pass1_2 / do pass 1 111: 112: / prepare for pass 2 113: inc passno 114: cmp outmod,$777 115: beq 1f 116: jsr pc,aexit 117: / not reached 118: 1: 119: jsr pc,setup 120: inc bsssiz 121: bic $1,bsssiz 122: mov txtsiz,r1 123: inc r1 124: bic $1,r1 125: mov r1,txtsiz 126: mov datsiz,r2 127: inc r2 128: bic $1,r2 129: mov r2,datsiz 130: mov r1,r3 131: mov r3,datbase / txtsiz 132: mov r3,savdot+2 133: add r2,r3 134: mov r3,bssbase / txtsiz+datsiz 135: mov r3,savdot+4 136: clr r0 137: asl r3 138: adc r0 139: add $20,r3 140: adc r0 141: mov r3,symseek+2 / 2*txtsiz+2*datsiz+20 142: mov r0,symseek 143: sub r2,r3 144: sbc r0 145: mov r3,drelseek+2 / 2*txtsiz+datsiz 146: mov r0,drelseek 147: sub r1,r3 148: sbc r0 149: mov r3,trelseek+2 / txtsiz+datsiz+20 150: mov r0,trelseek 151: sub r2,r3 152: sbc r0 153: mov r0,datseek 154: mov r3,datseek+2 / txtsiz+20 155: mov hshtab,r1 156: 1: 157: jsr pc,doreloc 158: add $4,r1 159: cmp r1,endtable 160: blo 1b 161: clr r0 162: clr r1 163: mov $txtp,-(sp) 164: jsr pc,oset 165: mov trelseek,r0 166: mov trelseek+2,r1 167: mov $relp,-(sp) 168: jsr pc,oset 169: mov $8.,r2 170: mov $txtmagic,r1 171: 1: 172: mov (r1)+,r0 173: mov $txtp,-(sp) 174: jsr pc,putw 175: sob r2,1b 176: 177: jsr pc,pass1_2 / do pass 2 178: 179: /polish off text and relocation 180: 181: mov $txtp,-(sp) 182: jsr pc,flush 183: mov $relp,-(sp) 184: jsr pc,flush 185: 186: / append full symbol table 187: mov symseek,r0 188: mov symseek+2,r1 189: mov $txtp,-(sp) 190: jsr pc,oset 191: 192: mov usymtab,r2 / pointer to first symbol block 193: mov hshtab,r1 / 'type' and 'value' array 194: 195: tst Newsym 196: beq 8f 197: jsr pc,nsymout 198: br 9f 199: 8: 200: jsr pc,osymout 201: 9: 202: mov $txtp,-(sp) 203: jsr pc,flush 204: jsr pc,aexit 205: / not reached 206: 207: saexit: 208: mov pc,errflg 209: 210: aexit: 211: mov $a.tmp1,-(sp) / unlink(a.tmp1) 212: jsr pc,_unlink 213: tst errflg 214: bne 2f 215: 216: clr (sp) 217: jsr pc,_umask 218: 219: bic r0,outmod / fchmod(fout, outmod&umask(0)) 220: mov outmod,(sp) 221: mov fout,-(sp) 222: jsr pc,_fchmod 223: tst (sp)+ 224: clr (sp) 225: br 1f 226: 2: 227: mov $2,(sp) 228: 1: 229: jsr pc,__exit / _exit(errflg ? 2 : 0) 230: 231: filerr: 232: mov 2(sp),r0 / filename string. no need to clean 233: tst -(sp) / stack, this routine goes to saexit. 234: mov r0,-(sp) 235: mov $1,-(sp) 236: 1: 237: tstb (r0)+ 238: bne 1b 239: sub 2(sp),r0 240: dec r0 241: mov r0,4(sp) 242: jsr pc,_write 243: add $6,sp 244: 245: mov $2,-(sp) / write(1, "?\n", 2) 246: mov $qnl,-(sp) 247: mov $1,-(sp) 248: jsr pc,_write 249: add $6,sp 250: tst passno 251: bpl saexit 252: rts pc 253: 254: osymout: 255: 9: 256: mov r2,symblk / save ptr to current sym block 257: tst (r2)+ / skip link word 258: mov $SYMBLKSZ,symleft / space left in symbol block 259: 1: 260: mov (r2),r4 / pointer to symbol name 261: beq 4f / end of block - br 262: 263: mov $8.,r5 / max number to copy 264: mov $symbol,r0 / destination buffer 265: 2: 266: movb (r4),(r0)+ / copy a byte 267: beq 6f 268: inc r4 / non null - bump source ptr 269: 6: 270: sob r5,2b 271: 272: / Now put four words of symbol name to the object file 273: mov $4,r5 / number of words to do 274: mov $symbol,r4 275: 6: 276: mov (r4)+,r0 / word (2 chars) of symbol name 277: mov $txtp,-(sp) 278: jsr pc,putw 279: sob r5,6b 280: 281: / values from 'hshtab' (parallel array to symbol table) are retrieved now, 282: / they take the place of the flags and value entries of the symbol table. 283: mov (r1)+,r0 284: mov $txtp,-(sp) 285: jsr pc,putw 286: mov (r1)+,r0 287: mov $txtp,-(sp) 288: jsr pc,putw 289: add $SYMENTSZ,r2 / skip to next symbol 290: sub $SYMENTSZ,symleft / one less symbol in block 291: cmp symleft,$SYMENTSZ / room for another? 292: bge 1b / yes - br 293: 4: 294: mov *symblk,r2 / no, follow link to next block 295: bne 9b / unless it's end of list 296: rts pc 297: 298: nsymout: 299: clr totalsz 300: mov $4,totalsz+2 / string table min size is 4 301: 9: 302: mov r2,symblk / save ptr to current symbol block 303: tst (r2)+ / skip link word 304: mov $SYMBLKSZ,symleft / amount of space left in block 305: 1: 306: mov (r2),r4 / pointer to symbol's string 307: beq 4f / end of block - br 308: mov totalsz,r0 / now output the... 309: mov $txtp,-(sp) / high order of the string index... 310: jsr pc,putw / to the object file 311: mov totalsz+2,r0 312: mov $txtp,-(sp) 313: jsr pc,putw / and the low order word 314: 2: 315: tstb (r4)+ / find the end of the string 316: bne 2b 317: sub (r2),r4 / compute length including the null 318: add r4,totalsz+2 / offset of next string 319: adc totalsz 320: mov (r1)+,r0 / 'type' word of symbol 321: mov $txtp,-(sp) 322: jsr pc,putw 323: mov (r1)+,r0 / 'value' word of symbol 324: mov $txtp,-(sp) 325: jsr pc,putw 326: add $SYMENTSZ,r2 / advance to next symbol 327: sub $SYMENTSZ,symleft / adjust amount left in symbol block 328: cmp symleft,$SYMENTSZ / is there enough for another symbol? 329: bge 1b / yes - br 330: 4: 331: mov *symblk,r2 / follow link to next symbol block 332: bne 9b / more - br 333: mov totalsz,r0 / now output the string table length 334: mov $txtp,-(sp) / high order word first 335: jsr pc,putw 336: mov totalsz+2,r0 / followed by the low order 337: mov $txtp,-(sp) 338: jsr pc,putw 339: 340: / Now write the strings out 341: 342: mov usymtab,r2 / start at beginning of symbols 343: 9: 344: mov r2,symblk / save pointer to current block 345: tst (r2)+ / skip link word 346: mov $SYMBLKSZ,symleft / amount left in block 347: 1: 348: mov (r2),r4 / pointer to symbol's string 349: beq 4f / at end of block - br 350: jsr pc,putstring / write out the string 351: add $SYMENTSZ,r2 / advance to next symbol 352: sub $SYMENTSZ,symleft / adjust amount left in block 353: cmp symleft,$SYMENTSZ / enough for another symbol? 354: bge 1b / yes - br 355: 4: 356: mov *symblk,r2 / move to next block of symbols 357: bne 9b / any left - br 358: 359: / probably not necessary but let us leave the file size on an even 360: / byte boundary. 361: 362: bit $1,totalsz+2 / odd number of bytes in string table? 363: beq 5f / no - br 364: mov symblk,r4 / we know 'symblk' points to a null 365: jsr pc,putstring / output a single null 366: 5: 367: rts pc 368: 369: / R4 has the address of a null terminated string to write to the output 370: / file. The terminating null is included in the output. This routine 371: / "inlines" the 'txtp seek structure' manipulation because the 'putw' 372: / routine was 1) not suitable to byte output and 2) symbol strings are 373: / only written using the 'txtp' (as opposed to 'relp' - relocation info) 374: / structure. 375: 376: putstring: 377: cmp txtp,txtp+2 / room for another byte? 378: bhis 1f / no - br 379: 3: 380: movb (r4),*txtp / put byte in buffer 381: inc txtp / advance output position 382: tstb (r4)+ / did we just do the null? 383: bne putstring / no - go again 384: rts pc / yes - we're done, return 385: 1: 386: mov r2,-(sp) / save r2 from being destroyed 387: mov $txtp,-(sp) / flush buffered output and... 388: jsr pc,flush / reset the pointers 389: mov (sp)+,r2 / restore symbol pointer 390: br 3b / go output a byte 391: 392: doreloc: 393: movb (r1),r0 394: bne 1f 395: bisb defund,(r1) 396: 1: 397: bic $!37,r0 398: cmp r0,$5 399: bhis 1f 400: cmp r0,$3 401: blo 1f 402: beq 2f 403: add bssbase,2(r1) 404: rts pc 405: 2: 406: add datbase,2(r1) 407: 1: 408: rts pc 409: 410: setup: 411: clr dot 412: mov $2,dotrel 413: mov $..,dotdot 414: clr brtabp 415: 416: mov $curfb,r4 417: 1: 418: clr (r4)+ 419: cmp r4,$curfb+40. 420: blo 1b 421: clr r4 422: 1: 423: jsr pc,fbadv 424: inc r4 425: cmp r4,$10. 426: blt 1b 427: / just rewind /tmp/atm1xx rather than close and re-open 428: clr -(sp) 429: clr -(sp) 430: clr -(sp) 431: mov fin,-(sp) 432: jsr pc,_lseek / lseek(fin, 0L, 0) 433: add $8.,sp 434: clr ibufc 435: rts pc 436: 437: outw: 438: cmp dot-2,$4 439: beq 9f 440: bit $1,dot 441: bne 1f 442: add $2,dot 443: tst passno 444: beq 8f 445: clr -(sp) 446: rol r3 447: adc (sp) 448: asr r3 / get relative pc bit 449: cmp r3,$40 450: bne 2f 451: / external references 452: mov $666,outmod / make nonexecutable 453: mov xsymbol,r3 454: sub hshtab,r3 455: asl r3 456: bis $4,r3 / external relocation 457: br 3f 458: 2: 459: bic $40,r3 / clear any ext bits 460: cmp r3,$5 461: blo 4f 462: cmp r3,$33 / est. text, data 463: beq 6f 464: cmp r3,$34 465: bne 7f 466: 6: 467: mov $'r,-(sp) 468: jsr pc,error 469: 7: 470: mov $1,r3 / make absolute 471: 4: 472: cmp r3,$2 473: blo 5f 474: cmp r3,$4 475: bhi 5f 476: tst (sp) 477: bne 4f 478: add dotdot,r2 479: br 4f 480: 5: 481: tst (sp) 482: beq 4f 483: sub dotdot,r2 484: 4: 485: dec r3 486: bpl 3f 487: clr r3 488: 3: 489: asl r3 490: bis (sp)+,r3 491: mov r2,r0 492: mov $txtp,-(sp) 493: jsr pc,putw 494: mov tseekp,r0 495: add $2,2(r0) 496: adc (r0) 497: mov r3,r0 498: mov $relp,-(sp) 499: jsr pc,putw 500: mov rseekp,r0 501: add $2,2(r0) 502: adc (r0) 503: 8: 504: rts pc 505: 1: 506: mov $'o,-(sp) 507: jsr pc,error 508: clr r3 509: jsr pc,outb 510: rts pc 511: 9: 512: mov $'x,-(sp) 513: jsr pc,error 514: rts pc 515: 516: outb: 517: cmp dot-2,$4 / test bss mode 518: beq 9b 519: cmp r3,$1 520: blos 1f 521: mov $'r,-(sp) 522: jsr pc,error 523: 1: 524: tst passno 525: beq 2f 526: mov r2,r0 527: bit $1,dot 528: bne 1f 529: mov $txtp,-(sp) 530: jsr pc,putw 531: clr r0 532: mov $relp,-(sp) 533: jsr pc,putw 534: mov tseekp,r0 535: add $2,2(r0) 536: adc (r0) 537: mov rseekp,r0 538: add $2,2(r0) 539: adc (r0) 540: br 2f 541: 1: 542: mov txtp,r0 543: movb r2,-1(r0) 544: 2: 545: inc dot 546: rts pc 547: 548: / pass 1 and 2 common code 549: 550: pass1_2: 551: jsr pc,readop 552: cmp r4,$5 553: beq 2f 554: cmp r4,$'< 555: beq 2f 556: jsr pc,checkeos 557: br eal1 558: mov r4,-(sp) 559: cmp (sp),$1 560: bne 1f 561: mov $2,(sp) 562: jsr pc,getw 563: mov r4,numval 564: 1: 565: jsr pc,readop 566: cmp r4,$'= 567: beq 4f 568: cmp r4,$': 569: beq 1f 570: mov r4,savop 571: mov (sp)+,r4 572: 2: 573: jsr pc,opline 574: dotmax: 575: tst passno 576: bne eal1 577: movb dotrel,r0 578: asl r0 579: cmp dot,txtsiz-4(r0) 580: bhi 8f 581: jmp ealoop 582: 8: 583: mov dot,txtsiz-4(r0) 584: eal1: 585: jmp ealoop 586: 1: 587: mov (sp)+,r4 588: cmp r4,$200 589: bhis 1f 590: cmp r4,$2 591: beq 3f 592: mov $'x,-(sp) 593: jsr pc,error 594: br pass1_2 595: 1: 596: tst passno 597: bne 2f 598: movb (r4),r0 599: bic $!37,r0 600: beq 5f 601: cmp r0,$33 602: blt 6f 603: cmp r0,$34 604: ble 5f 605: 6: 606: mov $'m,-(sp) 607: jsr pc,error 608: 5: 609: bic $37,(r4) 610: bis dotrel,(r4) 611: mov 2(r4),brdelt 612: sub dot,brdelt 613: mov dot,2(r4) 614: br pass1_2 615: 2: 616: cmp dot,2(r4) 617: beq pass1_2 618: mov $'p,-(sp) 619: jsr pc,error 620: br pass1_2 621: 3: 622: mov numval,r4 623: jsr pc,fbadv 624: asl r4 625: mov curfb(r4),r0 626: movb dotrel,(r0) 627: mov 2(r0),brdelt 628: sub dot,brdelt 629: mov dot,2(r0) 630: br pass1_2 631: 4: 632: jsr pc,readop 633: jsr pc,expres 634: mov (sp)+,r1 635: cmp r1,$dotrel /test for dot 636: bne 1f 637: bic $40,r3 638: cmp r3,dotrel / can't change relocation 639: bne 2f 640: cmp r3,$4 / bss 641: bne 3f 642: mov r2,dot 643: br dotmax 644: 3: 645: sub dot,r2 646: bmi 2f 647: mov r2,-(sp) 648: 3: 649: dec (sp) 650: bmi 3f 651: clr r2 652: mov $1,r3 653: jsr pc,outb 654: br 3b 655: 3: 656: tst (sp)+ 657: br dotmax 658: 2: 659: mov $'.,-(sp) 660: jsr pc,error 661: br ealoop 662: 1: 663: cmp r3,$40 664: bne 1f 665: mov $'r,-(sp) 666: jsr pc,error 667: 1: 668: bic $37,(r1) 669: bic $!37,r3 670: bne 1f 671: clr r2 672: 1: 673: bisb r3,(r1) 674: mov r2,2(r1) 675: 676: ealoop: 677: cmp r4,$'\n 678: beq 1f 679: cmp r4,$'\e 680: bne 9f 681: rts pc 682: 1: 683: inc line 684: 9: 685: jmp pass1_2 686: 687: checkeos: 688: cmp r4,$'\n 689: beq 1f 690: cmp r4,$'; 691: beq 1f 692: cmp r4,$'\e 693: beq 1f 694: add $2,(sp) 695: 1: 696: rts pc 697: 698: fbadv: 699: asl r4 700: mov nxtfb(r4),r1 701: mov r1,curfb(r4) 702: bne 1f 703: mov fbbufp,r1 704: br 2f 705: 1: 706: add $4,r1 707: 2: 708: cmpb 1(r1),r4 709: beq 1f 710: tst (r1) 711: bpl 1b 712: 1: 713: mov r1,nxtfb(r4) 714: asr r4 715: rts pc 716: 717: oset: 718: mov r2,-(sp) 719: mov r3,-(sp) 720: mov 6(sp),r3 721: mov r1,r2 722: bic $!1777,r1 723: add r3,r1 724: add $8,r1 725: mov r1,(r3)+ / next slot 726: mov r3,r1 727: add $2006,r1 728: mov r1,(r3)+ / buf max 729: mov r0,(r3)+ 730: mov r2,(r3)+ / seek addr 731: mov (sp)+,r3 732: mov (sp)+,r2 733: mov (sp)+,(sp) 734: rts pc 735: 736: putw: 737: mov r1,-(sp) 738: mov r2,-(sp) 739: mov 6(sp),r2 740: mov (r2)+,r1 / slot 741: cmp r1,(r2) / buf max 742: bhis 1f 743: mov r0,(r1)+ 744: mov r1,-(r2) 745: br 2f 746: 1: 747: tst (r2)+ 748: mov r0,-(sp) 749: jsr pc,flush1 750: mov (sp)+,r0 751: mov r0,*(r2)+ 752: add $2,-(r2) 753: 2: 754: mov (sp)+,r2 755: mov (sp)+,r1 756: mov (sp)+,(sp) 757: ret: 758: rts pc 759: 760: flush: 761: mov 2(sp),r2 762: mov (sp)+,(sp) 763: cmp (r2)+,(r2)+ 764: flush1: 765: 766: clr -(sp) / lseek(fout, (r2)L+, L_SET) 767: mov 2(r2),-(sp) 768: mov (r2)+,-(sp) 769: tst (r2)+ 770: mov fout,-(sp) 771: jsr pc,_lseek 772: add $8.,sp 773: 774: cmp -(sp),-(sp) / write(fout, <buf>, <len>) 775: bic $!1777,r1 776: add r2,r1 / write address 777: mov r1,-(sp) / { <buf> } 778: mov r2,r0 779: bis $1777,-(r2) 780: add $1,(r2) / new seek addr 781: adc -(r2) 782: cmp -(r2),-(r2) 783: sub (r2),r1 784: neg r1 785: mov r1,2(sp) / count 786: mov r0,(r2) / new next slot 787: 788: mov fout,-(sp) 789: mov r1,6(sp) / protect r1 from library 790: jsr pc,_write 791: add $6,sp 792: mov (sp)+,r1 793: tst r0 794: bpl ret 795: / fall thru to wrterr 796: 797: wrterr: 798: mov $8f-9f,-(sp) / write(1, 9f, 8f-9f) 799: mov $9f,-(sp) 800: mov $1,-(sp) 801: jsr pc,_write 802: add $6,sp 803: jsr pc,saexit 804: / not reached 805: 806: .data 807: 9: 808: <as: write error\n> 809: 8: 810: .even 811: .text 812: 813: readop: 814: mov savop,r4 815: beq 1f 816: clr savop 817: rts pc 818: 1: 819: jsr pc,getw1 820: cmp r4,$200 821: blo 1f 822: cmp r4,$4000 823: blo 2f 824: sub $4000,r4 825: asl r4 826: asl r4 827: add hshtab,r4 828: rts pc 829: 2: 830: / remove PST flag (1000) then multiply by PSTENTSZ. In pass 0 the PST 831: / symbol number was divided by PSTENTSZ(to make it fit) - we now reverse 832: / that process. 833: mov r5,-(sp) 834: mov r4,r5 835: sub $1000,r5 836: mul $PSTENTSZ,r5 837: mov r5,r4 838: mov (sp)+,r5 839: add $dotrel,r4 / point at dot's flag field 840: 1: 841: rts pc 842: 843: getw: 844: mov savop,r4 845: beq getw1 846: clr savop 847: rts pc 848: getw1: 849: dec ibufc 850: bgt 1f 851: 852: mov r1,-(sp) / protect r1 from library 853: mov $1024.,-(sp) / read(fin, inbuf, 1024) 854: mov $inbuf,-(sp) 855: mov fin,-(sp) 856: jsr pc,_read 857: add $6,sp 858: mov (sp)+,r1 859: asr r0 860: mov r0,ibufc 861: bgt 2f 862: mov $4,r4 863: sev 864: rts pc 865: 2: 866: mov $inbuf,ibufp 867: 1: 868: mov *ibufp,r4 869: add $2,ibufp 870: rts pc 871: 872: opline: 873: mov r4,r0 874: bmi 2f 875: cmp r0,$177 876: bgt 2f 877: cmp r4,$5 878: beq opeof 879: cmp r4,$'< 880: bne xpr 881: jmp opl17 882: xxpr: 883: tst (sp)+ 884: xpr: 885: jsr pc,expres 886: jsr pc,outw 887: rts pc 888: 2: 889: movb (r4),r0 890: cmp r0,$24 /reg 891: beq xpr 892: cmp r0,$33 /est text 893: beq xpr 894: cmp r0,$34 / est data 895: beq xpr 896: cmp r0,$5 897: blt xpr 898: cmp r0,$36 899: bgt xpr 900: mov 2(r4),-(sp) 901: mov r0,-(sp) 902: jsr pc,readop 903: mov (sp)+,r0 904: asl r0 905: mov $adrbuf,r5 906: clr swapf 907: mov $-1,rlimit 908: jmp *1f-10.(r0) 909: .data 910: 1: 911: opl5 912: opl6 913: opl7 914: opl10 915: opl11 916: opl12 917: opl13 918: opl14 919: opl15 920: opl16 921: opl17 922: opl20 923: opl21 924: opl22 925: opl23 926: xxpr 927: opl25 928: opl26 929: opl27 930: opl30 931: opl31 932: opl32 933: xxpr 934: xxpr 935: opl35 936: opl36 937: .text 938: 939: opeof: 940: mov $1,line 941: mov $20,-(sp) 942: mov $argb,r1 943: 1: 944: jsr pc,getw 945: tst r4 946: bmi 1f 947: movb r4,(r1)+ 948: dec (sp) 949: bgt 1b 950: tstb -(r1) 951: br 1b 952: 1: 953: movb $'\n,(r1)+ 954: clrb (r1)+ 955: tst (sp)+ 956: rts pc 957: 958: opl30: / mul, div etc 959: inc swapf 960: mov $1000,rlimit 961: br opl13 962: 963: opl14: / flop freg,fsrc 964: inc swapf 965: 966: opl5: / flop src,freg 967: mov $400,rlimit 968: 969: opl13: /double 970: jsr pc,addres 971: op2a: 972: mov r2,-(sp) 973: jsr pc,readop 974: op2b: 975: jsr pc,addres 976: tst swapf 977: beq 1f 978: mov (sp),r0 979: mov r2,(sp) 980: mov r0,r2 981: 1: 982: swab (sp) 983: asr (sp) 984: asr (sp) 985: cmp (sp),rlimit 986: blo 1f 987: mov $'x,-(sp) 988: jsr pc,error 989: 1: 990: bis (sp)+,r2 991: bis (sp)+,r2 992: clr r3 993: jsr pc,outw 994: mov $adrbuf,r1 995: 1: 996: cmp r1,r5 997: bhis 1f 998: mov (r1)+,r2 999: mov (r1)+,r3 1000: mov (r1)+,xsymbol 1001: jsr pc,outw 1002: br 1b 1003: 1: 1004: rts pc 1005: 1006: opl15: / single operand 1007: clr -(sp) 1008: br op2b 1009: 1010: opl12: / movf 1011: mov $400,rlimit 1012: jsr pc,addres 1013: cmp r2,$4 / see if source is fregister 1014: blo 1f 1015: inc swapf 1016: br op2a 1017: 1: 1018: mov $174000,(sp) 1019: br op2a 1020: 1021: opl35: / jbr 1022: opl36: / jeq, jne, etc 1023: jsr pc,expres 1024: tst passno 1025: bne 1f 1026: mov r2,r0 1027: jsr pc,setbr 1028: tst r2 1029: beq 2f 1030: cmp (sp),$br 1031: beq 2f 1032: add $2,r2 1033: 2: 1034: add r2,dot / if doesn't fit 1035: add $2,dot 1036: tst (sp)+ 1037: rts pc 1038: 1: 1039: jsr pc,getbr 1040: bcc dobranch 1041: mov (sp)+,r0 1042: mov r2,-(sp) 1043: mov r3,-(sp) 1044: cmp r0,$br 1045: beq 2f 1046: mov $402,r2 1047: xor r0,r2 / flip cond, add ".+6" 1048: mov $1,r3 1049: jsr pc,outw 1050: 2: 1051: mov $1,r3 1052: mov $jmp+37,r2 1053: jsr pc,outw 1054: mov (sp)+,r3 1055: mov (sp)+,r2 1056: jsr pc,outw 1057: rts pc 1058: 1059: opl31: / sob 1060: jsr pc,expres 1061: jsr pc,checkreg 1062: swab r2 1063: asr r2 1064: asr r2 1065: bis r2,(sp) 1066: jsr pc,readop 1067: jsr pc,expres 1068: tst passno 1069: beq 3f 1070: sub dot,r2 1071: neg r2 1072: mov r2,r0 1073: cmp r0,$-2 1074: blt 2f 1075: cmp r0,$175 1076: bgt 2f 1077: add $4,r2 1078: br 1f 1079: 1080: opl6: /branch 1081: jsr pc,expres 1082: tst passno 1083: beq 3f 1084: dobranch: 1085: sub dot,r2 1086: mov r2,r0 1087: cmp r0,$-254. 1088: blt 2f 1089: cmp r0,$256. 1090: bgt 2f 1091: 1: 1092: bit $1,r2 1093: bne 2f 1094: cmp r3,dot-2 / same relocation as . 1095: bne 2f 1096: asr r2 1097: dec r2 1098: bic $177400,r2 1099: 3: 1100: bis (sp)+,r2 1101: clr r3 1102: jsr pc,outw 1103: rts pc 1104: 2: 1105: mov $'b,-(sp) 1106: jsr pc,error 1107: clr r2 1108: br 3b 1109: 1110: opl7: /jsr 1111: jsr pc,expres 1112: jsr pc,checkreg 1113: jmp op2a 1114: 1115: opl10: / rts 1116: jsr pc,expres 1117: jsr pc,checkreg 1118: br 1f 1119: 1120: opl11: / sys 1121: jsr pc,expres 1122: cmp r2,$256. 1123: bhis 0f 1124: cmp r3,$1 1125: ble 1f 1126: 0: 1127: mov $'a,-(sp) 1128: jsr pc,error 1129: 1: 1130: bis (sp)+,r2 1131: jsr pc,outw 1132: rts pc 1133: 1134: opl16: / .byte 1135: jsr pc,expres 1136: jsr pc,outb 1137: cmp r4,$', 1138: bne 1f 1139: jsr pc,readop 1140: br opl16 1141: 1: 1142: tst (sp)+ 1143: rts pc 1144: 1145: opl17: / < (.ascii) 1146: jsr pc,getw 1147: mov $1,r3 1148: mov r4,r2 1149: bmi 2f 1150: bic $!377,r2 1151: jsr pc,outb 1152: br opl17 1153: 2: 1154: jsr pc,getw 1155: rts pc 1156: 1157: opl20: /.even 1158: bit $1,dot 1159: beq 1f 1160: cmp dot-2,$4 1161: beq 2f / bss mode 1162: clr r2 1163: clr r3 1164: jsr pc,outb 1165: br 1f 1166: 2: 1167: inc dot 1168: 1: 1169: tst (sp)+ 1170: rts pc 1171: 1172: opl21: /if 1173: jsr pc,expres 1174: opl22: 1175: oplret: 1176: tst (sp)+ 1177: rts pc 1178: 1179: opl23: /.globl 1180: cmp r4,$200 1181: blo 1f 1182: bisb $40,(r4) 1183: jsr pc,readop 1184: cmp r4,$', 1185: bne 1f 1186: jsr pc,readop 1187: br opl23 1188: 1: 1189: tst (sp)+ 1190: rts pc 1191: 1192: opl25: / .text, .data, .bss 1193: opl26: 1194: opl27: 1195: inc dot 1196: bic $1,dot 1197: mov r0,-(sp) 1198: mov dot-2,r1 1199: asl r1 1200: mov dot,savdot-4(r1) 1201: tst passno 1202: beq 1f 1203: mov $txtp,-(sp) 1204: jsr pc,flush 1205: mov $relp,-(sp) 1206: jsr pc,flush 1207: mov (sp),r2 1208: asl r2 1209: add $txtseek-[4*25],r2 1210: mov r2,tseekp 1211: mov (r2),r0 1212: mov 2(r2),r1 1213: mov $txtp,-(sp) 1214: jsr pc,oset 1215: add $trelseek-txtseek,r2 1216: mov (r2),r0 1217: mov 2(r2),r1 1218: mov r2,rseekp 1219: mov $relp,-(sp) 1220: jsr pc,oset 1221: 1: 1222: mov (sp)+,r0 1223: mov savdot-[2*25](r0),dot 1224: asr r0 1225: sub $25-2,r0 1226: mov r0,dot-2 / new . relocation 1227: tst (sp)+ 1228: rts pc 1229: 1230: opl32: 1231: cmp r4,$200 1232: blo 1f 1233: mov r4,-(sp) 1234: jsr pc,readop 1235: jsr pc,readop 1236: jsr pc,expres 1237: mov (sp)+,r0 1238: bit $37,(r0) 1239: bne 1f 1240: bis $40,(r0) 1241: mov r2,2(r0) 1242: 1: 1243: tst (sp)+ 1244: rts pc 1245: 1246: addres: 1247: clr -(sp) 1248: 4: 1249: cmp r4,$'( 1250: beq alp 1251: cmp r4,$'- 1252: beq amin 1253: cmp r4,$'$ 1254: beq adoll 1255: cmp r4,$'* 1256: bne getx 1257: jmp astar 1258: getx: 1259: jsr pc,expres 1260: cmp r4,$'( 1261: bne 2f 1262: jsr pc,readop 1263: mov r2,(r5)+ 1264: mov r3,(r5)+ 1265: mov xsymbol,(r5)+ 1266: jsr pc,expres 1267: jsr pc,checkreg 1268: jsr pc,checkrp 1269: bis $60,r2 1270: bis (sp)+,r2 1271: rts pc 1272: 1273: 2: 1274: cmp r3,$24 1275: bne 1f 1276: jsr pc,checkreg 1277: bis (sp)+,r2 1278: rts pc 1279: 1: 1280: mov r3,-(sp) 1281: bic $40,r3 1282: mov (sp)+,r3 1283: bis $100000,r3 1284: sub dot,r2 1285: sub $4,r2 1286: cmp r5,$adrbuf 1287: beq 1f 1288: sub $2,r2 1289: 1: 1290: mov r2,(r5)+ / index 1291: mov r3,(r5)+ / index reloc. 1292: mov xsymbol,(r5)+ / index global 1293: mov $67,r2 / address mode 1294: bis (sp)+,r2 1295: rts pc 1296: 1297: alp: 1298: jsr pc,readop 1299: jsr pc,expres 1300: jsr pc,checkrp 1301: jsr pc,checkreg 1302: cmp r4,$'+ 1303: beq 1f 1304: tst (sp)+ 1305: beq 2f 1306: bis $70,r2 1307: clr (r5)+ 1308: clr (r5)+ 1309: mov xsymbol,(r5)+ 1310: rts pc 1311: 2: 1312: bis $10,r2 1313: rts pc 1314: 1: 1315: jsr pc,readop 1316: bis $20,r2 1317: bis (sp)+,r2 1318: rts pc 1319: 1320: amin: 1321: jsr pc,readop 1322: cmp r4,$'( 1323: beq 1f 1324: mov r4,savop 1325: mov $'-,r4 1326: br getx 1327: 1: 1328: jsr pc,readop 1329: jsr pc,expres 1330: jsr pc,checkrp 1331: jsr pc,checkreg 1332: bis (sp)+,r2 1333: bis $40,r2 1334: rts pc 1335: 1336: adoll: 1337: jsr pc,readop 1338: jsr pc,expres 1339: mov r2,(r5)+ 1340: mov r3,(r5)+ 1341: mov xsymbol,(r5)+ 1342: mov (sp)+,r2 1343: bis $27,r2 1344: rts pc 1345: 1346: astar: 1347: tst (sp) 1348: beq 1f 1349: mov $'*,-(sp) 1350: jsr pc,error 1351: 1: 1352: mov $10,(sp) 1353: jsr pc,readop 1354: jmp 4b 1355: 1356: checkreg: 1357: cmp r2,$7 1358: bhi 1f 1359: cmp r1,$1 1360: blos 2f 1361: cmp r3,$5 1362: blo 1f 1363: 2: 1364: rts pc 1365: 1: 1366: mov $'a,-(sp) 1367: jsr pc,error 1368: clr r2 1369: clr r3 1370: rts pc 1371: 1372: checkrp: 1373: cmp r4,$') 1374: beq 1f 1375: mov $'),-(sp) 1376: jsr pc,error 1377: rts pc 1378: 1: 1379: jsr pc,readop 1380: rts pc 1381: 1382: setbr: 1383: mov brtabp,r1 1384: cmp r1,$brlen 1385: blt 1f 1386: mov $2,r2 1387: rts pc 1388: 1: 1389: inc brtabp 1390: clr -(sp) 1391: sub dot,r0 1392: ble 1f 1393: sub brdelt,r0 1394: 1: 1395: cmp r0,$-254. 1396: blt 1f 1397: cmp r0,$256. 1398: ble 2f 1399: 1: 1400: mov r1,-(sp) 1401: bic $!7,(sp) 1402: mov $1,r0 1403: ash (sp)+,r0 1404: ash $-3,r1 1405: bisb r0,brtab(r1) 1406: mov $2,(sp) 1407: 2: 1408: mov (sp)+,r2 1409: rts pc 1410: 1411: getbr: 1412: mov brtabp,r1 1413: cmp r1,$brlen 1414: blt 1f 1415: sec 1416: rts pc 1417: 1: 1418: mov r1,-(sp) 1419: bic $!7,(sp) 1420: neg (sp) 1421: inc brtabp 1422: ash $-3,r1 1423: movb brtab(r1),r1 1424: ash (sp)+,r1 1425: ror r1 / 0-bit into c-bit 1426: rts pc 1427: 1428: expres: 1429: clr xsymbol 1430: expres1: 1431: mov r5,-(sp) 1432: mov $'+,-(sp) 1433: clr r2 1434: mov $1,r3 1435: br 1f 1436: advanc: 1437: jsr pc,readop 1438: 1: 1439: mov r4,r0 1440: blt 6f 1441: cmp r0,$177 1442: ble 7f 1443: 6: 1444: movb (r4),r0 1445: bne 1f 1446: tst passno 1447: beq 1f 1448: mov $'u,-(sp) 1449: jsr pc,error 1450: 1: 1451: tst overlaid 1452: beq 0f 1453: / 1454: / Bill Shannon's hack to the assembler to force globl text 1455: / references to remain undefined so that the link editor may 1456: / resolve them. This is necessary if a function is used as an 1457: / arg in an overlay located piece of code, and the function is 1458: / actually in another overlay. Elsewise, the assembler fix's up 1459: / the reference before the link editor changes the globl refrence 1460: / to the thunk. -wfj 5/80 1461: cmp r0,$42 / is it globl text ? 1462: bne 0f / nope 1463: mov $40,r0 / yes, treat it as undefined external 1464: 0: 1465: cmp r0,$40 1466: bne 1f 1467: mov r4,xsymbol 1468: clr r1 1469: br oprand 1470: 1: 1471: mov 2(r4),r1 1472: br oprand 1473: 7: 1474: cmp r4,$141 1475: blo 1f 1476: asl r4 1477: mov curfb-[2*141](r4),r0 1478: mov 2(r0),r1 1479: movb (r0),r0 1480: br oprand 1481: 1: 1482: mov $esw1,r1 1483: 1: 1484: cmp (r1)+,r4 1485: beq 1f 1486: tst (r1)+ 1487: bne 1b 1488: tst (sp)+ 1489: mov (sp)+,r5 1490: rts pc 1491: 1: 1492: jmp *(r1) 1493: .data 1494: esw1: 1495: '+; binop 1496: '-; binop 1497: '*; binop 1498: '/; binop 1499: '&; binop 1500: 037; binop 1501: 035; binop 1502: 036; binop 1503: '%; binop 1504: '[; brack 1505: '^; binop 1506: 1; exnum 1507: 2; exnum1 1508: '!; binop 1509: 200; 0 1510: .text 1511: binop: 1512: cmpb (sp),$'+ 1513: beq 1f 1514: mov $'e,-(sp) 1515: jsr pc,error 1516: 1: 1517: movb r4,(sp) 1518: br advanc 1519: 1520: exnum1: 1521: mov numval,r1 1522: br 1f 1523: 1524: exnum: 1525: jsr pc,getw 1526: mov r4,r1 1527: 1: 1528: mov $1,r0 1529: br oprand 1530: 1531: brack: 1532: mov r2,-(sp) 1533: mov r3,-(sp) 1534: jsr pc,readop 1535: jsr pc,expres1 1536: cmp r4,$'] 1537: beq 1f 1538: mov $'],-(sp) 1539: jsr pc,error 1540: 1: 1541: mov r3,r0 1542: mov r2,r1 1543: mov (sp)+,r3 1544: mov (sp)+,r2 1545: 1546: oprand: 1547: mov $exsw2,r5 1548: 1: 1549: cmp (sp),(r5)+ 1550: beq 1f 1551: tst (r5)+ 1552: bne 1b 1553: br eoprnd 1554: 1: 1555: jmp *(r5) 1556: .data 1557: exsw2: 1558: '+; exadd 1559: '-; exsub 1560: '*; exmul 1561: '/; exdiv 1562: 037; exor 1563: '&; exand 1564: 035;exlsh 1565: 036;exrsh 1566: '%; exmod 1567: '^; excmbin 1568: '!; exnot 1569: 200; 0 1570: .text 1571: excmbin: 1572: mov r0,r3 1573: br eoprnd 1574: 1575: exrsh: 1576: neg r1 1577: beq exlsh 1578: inc r1 1579: clc 1580: ror r2 1581: exlsh: 1582: mov $relte2,r5 1583: jsr pc,combin 1584: ash r1,r2 1585: br eoprnd 1586: 1587: exmod: 1588: mov $relte2,r5 1589: jsr pc,combin 1590: mov r3,r0 1591: mov r2,r3 1592: clr r2 1593: div r1,r2 1594: mov r3,r2 1595: mov r0,r3 1596: br eoprnd 1597: 1598: exadd: 1599: mov $reltp2,r5 1600: jsr pc,combin 1601: add r1,r2 1602: br eoprnd 1603: 1604: exsub: 1605: mov $reltm2,r5 1606: jsr pc,combin 1607: sub r1,r2 1608: br eoprnd 1609: 1610: exand: 1611: mov $relte2,r5 1612: jsr pc,combin 1613: com r1 1614: bic r1,r2 1615: br eoprnd 1616: 1617: exor: 1618: mov $relte2,r5 1619: jsr pc,combin 1620: bis r1,r2 1621: br eoprnd 1622: 1623: exmul: 1624: mov $relte2,r5 1625: jsr pc,combin 1626: mul r2,r1 1627: mov r1,r2 1628: br eoprnd 1629: 1630: exdiv: 1631: mov $relte2,r5 1632: jsr pc,combin 1633: mov r3,r0 1634: mov r2,r3 1635: clr r2 1636: div r1,r2 1637: mov r0,r3 1638: br eoprnd 1639: 1640: exnot: 1641: mov $relte2,r5 1642: jsr pc,combin 1643: com r1 1644: add r1,r2 1645: br eoprnd 1646: 1647: eoprnd: 1648: mov $'+,(sp) 1649: jmp advanc 1650: 1651: combin: 1652: tst passno 1653: bne combin1 1654: mov r0,-(sp) 1655: bis r3,(sp) 1656: bic $!40,(sp) 1657: bic $!37,r0 1658: bic $!37,r3 1659: cmp r0,r3 1660: ble 1f 1661: mov r0,-(sp) 1662: mov r3,r0 1663: mov (sp)+,r3 1664: 1: 1665: tst r0 1666: beq 1f 1667: cmp r5,$reltm2 1668: bne 2f 1669: cmp r0,r3 1670: bne 2f 1671: mov $1,r3 1672: br 2f 1673: 1: 1674: clr r3 1675: 2: 1676: bis (sp)+,r3 1677: rts pc 1678: combin1: 1679: mov r1,-(sp) 1680: clr maxtyp 1681: jsr pc,maprel 1682: mov r0,r1 1683: mul $6,r1 1684: mov r3,r0 1685: jsr pc,maprel 1686: add r5,r0 1687: add r1,r0 1688: movb (r0),r3 1689: bpl 1f 1690: cmp r3,$-1 1691: beq 2f 1692: mov $'r,-(sp) 1693: jsr pc,error 1694: 2: 1695: mov maxtyp,r3 1696: 1: 1697: mov (sp)+,r1 1698: rts pc 1699: 1700: maprel: 1701: cmp r0,$40 1702: bne 1f 1703: mov $5,r0 1704: rts pc 1705: 1: 1706: bic $!37,r0 1707: cmp r0,maxtyp 1708: blos 1f 1709: mov r0,maxtyp 1710: 1: 1711: cmp r0,$5 1712: blo 1f 1713: mov $1,r0 1714: 1: 1715: rts pc 1716: .data 1717: X = -2 1718: M = -1 1719: reltp2: 1720: .byte 0, 0, 0, 0, 0, 0 1721: .byte 0, M, 2, 3, 4,40 1722: .byte 0, 2, X, X, X, X 1723: .byte 0, 3, X, X, X, X 1724: .byte 0, 4, X, X, X, X 1725: .byte 0,40, X, X, X, X 1726: 1727: reltm2: 1728: .byte 0, 0, 0, 0, 0, 0 1729: .byte 0, M, 2, 3, 4,40 1730: .byte 0, X, 1, X, X, X 1731: .byte 0, X, X, 1, X, X 1732: .byte 0, X, X, X, 1, X 1733: .byte 0, X, X, X, X, X 1734: 1735: relte2: 1736: .byte 0, 0, 0, 0, 0, 0 1737: .byte 0, M, X, X, X, X 1738: .byte 0, X, X, X, X, X 1739: .byte 0, X, X, X, X, X 1740: .byte 0, X, X, X, X, X 1741: .byte 0, X, X, X, X, X 1742: 1743: qnl: <?\n> 1744: a.out: <a.out\0> 1745: .even 1746: a.outp: a.out 1747: 1748: obufp: outbuf 1749: passno: -1 1750: outmod: 0777 1751: 1752: tseekp: txtseek 1753: rseekp: trelseek 1754: 1755: txtmagic: 1756: br .+20 1757: txtsiz: .=.+2 1758: datsiz: .=.+2 1759: bsssiz: .=.+2 1760: symsiz: .=.+2 1761: .=.+6 1762: 1763: txtseek:0; 20 1764: datseek:.=.+4 1765: .=.+4 1766: trelseek:.=.+4 1767: drelseek:.=.+4 1768: .=.+4 1769: symseek:.=.+4 1770: 1771: .bss 1772: brlen = 1024. 1773: brtab: .=.+[brlen\/8.] 1774: brtabp: .=.+2 1775: brdelt: .=.+2 1776: fbbufp: .=.+2 1777: defund: .=.+2 1778: datbase:.=.+2 1779: bssbase:.=.+2 1780: ibufc: .=.+2 1781: overlaid: .=.+2 1782: adrbuf: .=.+12. 1783: xsymbol:.=.+2 1784: errflg: .=.+2 1785: argb: .=.+22. 1786: numval: .=.+2 1787: maxtyp: .=.+2 1788: ibufp: .=.+2 1789: txtp: .=.+8. 1790: .=.+1024. 1791: relp: .=.+8. 1792: outbuf: 1793: .=.+1024. 1794: swapf: .=.+2 1795: rlimit: .=.+2 1796: endtable:.=.+2 1797: totalsz: / string table length 1798: .=.+4 1799: .text