1: / machine language assist 2: / for 11/40 3: 4: / non-UNIX instructions 5: mfpi = 6500^tst 6: mtpi = 6600^tst 7: wait = 1 8: rtt = 6 9: reset = 5 10: 11: .globl trap, call 12: .globl _trap 13: trap: 14: mov PS,-4(sp) 15: tst nofault 16: bne 1f 17: mov SSR0,ssr 18: mov SSR2,ssr+4 19: mov $1,SSR0 20: jsr r0,call1; _trap 21: / no return 22: 1: 23: mov $1,SSR0 24: mov nofault,(sp) 25: rtt 26: 27: .globl _runrun, _swtch 28: call1: 29: tst -(sp) 30: bic $340,PS 31: br 1f 32: 33: call: 34: mov PS,-(sp) 35: 1: 36: mov r1,-(sp) 37: mfpi sp 38: mov 4(sp),-(sp) 39: bic $!37,(sp) 40: bit $30000,PS 41: beq 1f 42: jsr pc,*(r0)+ 43: 2: 44: bis $340,PS 45: tstb _runrun 46: beq 2f 47: bic $340,PS 48: jsr pc,_swtch 49: br 2b 50: 2: 51: tst (sp)+ 52: mtpi sp 53: br 2f 54: 1: 55: bis $30000,PS 56: jsr pc,*(r0)+ 57: cmp (sp)+,(sp)+ 58: 2: 59: mov (sp)+,r1 60: tst (sp)+ 61: mov (sp)+,r0 62: rtt 63: 64: .globl _savfp, _display 65: _savfp: 66: _display: 67: rts pc 68: 69: .globl _incupc 70: _incupc: 71: mov r2,-(sp) 72: mov 6(sp),r2 / base of prof with base,leng,off,scale 73: mov 4(sp),r0 / pc 74: sub 4(r2),r0 / offset 75: clc 76: ror r0 77: mul 6(r2),r0 / scale 78: ashc $-14.,r0 79: inc r1 80: bic $1,r1 81: cmp r1,2(r2) / length 82: bhis 1f 83: add (r2),r1 / base 84: mov nofault,-(sp) 85: mov $2f,nofault 86: mfpi (r1) 87: inc (sp) 88: mtpi (r1) 89: br 3f 90: 2: 91: clr 6(r2) 92: 3: 93: mov (sp)+,nofault 94: 1: 95: mov (sp)+,r2 96: rts pc 97: 98: / Character list get/put 99: 100: .globl _getc, _putc 101: .globl _cfreelist 102: 103: _getc: 104: mov 2(sp),r1 105: mov PS,-(sp) 106: mov r2,-(sp) 107: bis $340,PS 108: bic $100,PS / spl 5 109: mov 2(r1),r2 / first ptr 110: beq 9f / empty 111: movb (r2)+,r0 / character 112: bic $!377,r0 113: mov r2,2(r1) 114: dec (r1)+ / count 115: bne 1f 116: clr (r1)+ 117: clr (r1)+ / last block 118: br 2f 119: 1: 120: bit $7,r2 121: bne 3f 122: mov -10(r2),(r1) / next block 123: add $2,(r1) 124: 2: 125: dec r2 126: bic $7,r2 127: mov _cfreelist,(r2) 128: mov r2,_cfreelist 129: 3: 130: mov (sp)+,r2 131: mov (sp)+,PS 132: rts pc 133: 9: 134: clr 4(r1) 135: mov $-1,r0 136: mov (sp)+,r2 137: mov (sp)+,PS 138: rts pc 139: 140: _putc: 141: mov 2(sp),r0 142: mov 4(sp),r1 143: mov PS,-(sp) 144: mov r2,-(sp) 145: mov r3,-(sp) 146: bis $340,PS 147: bic $100,PS / spl 5 148: mov 4(r1),r2 / last ptr 149: bne 1f 150: mov _cfreelist,r2 151: beq 9f 152: mov (r2),_cfreelist 153: clr (r2)+ 154: mov r2,2(r1) / first ptr 155: br 2f 156: 1: 157: bit $7,r2 158: bne 2f 159: mov _cfreelist,r3 160: beq 9f 161: mov (r3),_cfreelist 162: mov r3,-10(r2) 163: mov r3,r2 164: clr (r2)+ 165: 2: 166: movb r0,(r2)+ 167: mov r2,4(r1) 168: inc (r1) / count 169: clr r0 170: mov (sp)+,r3 171: mov (sp)+,r2 172: mov (sp)+,PS 173: rts pc 174: 9: 175: mov pc,r0 176: mov (sp)+,r3 177: mov (sp)+,r2 178: mov (sp)+,PS 179: rts pc 180: 181: .globl _backup 182: .globl _regloc 183: _backup: 184: mov 2(sp),ssr+2 185: mov r2,-(sp) 186: jsr pc,backup 187: mov r2,ssr+2 188: mov (sp)+,r2 189: movb jflg,r0 190: bne 2f 191: mov 2(sp),r0 192: movb ssr+2,r1 193: jsr pc,1f 194: movb ssr+3,r1 195: jsr pc,1f 196: movb _regloc+7,r1 197: asl r1 198: add r0,r1 199: mov ssr+4,(r1) 200: clr r0 201: 2: 202: rts pc 203: 1: 204: mov r1,-(sp) 205: asr (sp) 206: asr (sp) 207: asr (sp) 208: bic $!7,r1 209: movb _regloc(r1),r1 210: asl r1 211: add r0,r1 212: sub (sp)+,(r1) 213: rts pc 214: 215: / hard part 216: / simulate the ssr2 register missing on 11/40 217: 218: backup: 219: clr r2 / backup register ssr1 220: mov $1,bflg / clrs jflg 221: mov ssr+4,r0 222: jsr pc,fetch 223: mov r0,r1 224: ash $-11.,r0 225: bic $!36,r0 226: jmp *0f(r0) 227: 0: t00; t01; t02; t03; t04; t05; t06; t07 228: t10; t11; t12; t13; t14; t15; t16; t17 229: 230: t00: 231: clrb bflg 232: 233: t10: 234: mov r1,r0 235: swab r0 236: bic $!16,r0 237: jmp *0f(r0) 238: 0: u0; u1; u2; u3; u4; u5; u6; u7 239: 240: u6: / single op, m[tf]pi, sxt, illegal 241: bit $400,r1 242: beq u5 / all but m[tf], sxt 243: bit $200,r1 244: beq 1f / mfpi 245: bit $100,r1 246: bne u5 / sxt 247: 248: / simulate mtpi with double (sp)+,dd 249: bic $4000,r1 / turn instr into (sp)+ 250: br t01 251: 252: / simulate mfpi with double ss,-(sp) 253: 1: 254: ash $6,r1 255: bis $46,r1 / -(sp) 256: br t01 257: 258: u4: / jsr 259: mov r1,r0 260: jsr pc,setreg / assume no fault 261: bis $173000,r2 / -2 from sp 262: rts pc 263: 264: t07: / EIS 265: clrb bflg 266: 267: u0: / jmp, swab 268: u5: / single op 269: mov r1,r0 270: br setreg 271: 272: t01: / mov 273: t02: / cmp 274: t03: / bit 275: t04: / bic 276: t05: / bis 277: t06: / add 278: t16: / sub 279: clrb bflg 280: 281: t11: / movb 282: t12: / cmpb 283: t13: / bitb 284: t14: / bicb 285: t15: / bisb 286: mov r1,r0 287: ash $-6,r0 288: jsr pc,setreg 289: swab r2 290: mov r1,r0 291: jsr pc,setreg 292: 293: / if delta(dest) is zero, 294: / no need to fetch source 295: 296: bit $370,r2 297: beq 1f 298: 299: / if mode(source) is R, 300: / no fault is possible 301: 302: bit $7000,r1 303: beq 1f 304: 305: / if reg(source) is reg(dest), 306: / too bad. 307: 308: mov r2,-(sp) 309: bic $174370,(sp) 310: cmpb 1(sp),(sp)+ 311: beq t17 312: 313: / start source cycle 314: / pick up value of reg 315: 316: mov r1,r0 317: ash $-6,r0 318: bic $!7,r0 319: movb _regloc(r0),r0 320: asl r0 321: add ssr+2,r0 322: mov (r0),r0 323: 324: / if reg has been incremented, 325: / must decrement it before fetch 326: 327: bit $174000,r2 328: ble 2f 329: dec r0 330: bit $10000,r2 331: beq 2f 332: dec r0 333: 2: 334: 335: / if mode is 6,7 fetch and add X(R) to R 336: 337: bit $4000,r1 338: beq 2f 339: bit $2000,r1 340: beq 2f 341: mov r0,-(sp) 342: mov ssr+4,r0 343: add $2,r0 344: jsr pc,fetch 345: add (sp)+,r0 346: 2: 347: 348: / fetch operand 349: / if mode is 3,5,7 fetch * 350: 351: jsr pc,fetch 352: bit $1000,r1 353: beq 1f 354: bit $6000,r1 355: bne fetch 356: 1: 357: rts pc 358: 359: t17: / illegal 360: u1: / br 361: u2: / br 362: u3: / br 363: u7: / illegal 364: incb jflg 365: rts pc 366: 367: setreg: 368: mov r0,-(sp) 369: bic $!7,r0 370: bis r0,r2 371: mov (sp)+,r0 372: ash $-3,r0 373: bic $!7,r0 374: movb 0f(r0),r0 375: tstb bflg 376: beq 1f 377: bit $2,r2 378: beq 2f 379: bit $4,r2 380: beq 2f 381: 1: 382: cmp r0,$20 383: beq 2f 384: cmp r0,$-20 385: beq 2f 386: asl r0 387: 2: 388: bisb r0,r2 389: rts pc 390: 391: 0: .byte 0,0,10,20,-10,-20,0,0 392: 393: fetch: 394: bic $1,r0 395: mov nofault,-(sp) 396: mov $1f,nofault 397: mfpi (r0) 398: mov (sp)+,r0 399: mov (sp)+,nofault 400: rts pc 401: 402: 1: 403: mov (sp)+,nofault 404: clrb r2 / clear out dest on fault 405: mov $-1,r0 406: rts pc 407: 408: .bss 409: bflg: .=.+1 410: jflg: .=.+1 411: .text 412: 413: .globl _fubyte, _subyte 414: .globl _fuibyte, _suibyte 415: .globl _fuword, _suword 416: .globl _fuiword, _suiword 417: _fuibyte: 418: _fubyte: 419: mov 2(sp),r1 420: bic $1,r1 421: jsr pc,gword 422: cmp r1,2(sp) 423: beq 1f 424: swab r0 425: 1: 426: bic $!377,r0 427: rts pc 428: 429: _suibyte: 430: _subyte: 431: mov 2(sp),r1 432: bic $1,r1 433: jsr pc,gword 434: mov r0,-(sp) 435: cmp r1,4(sp) 436: beq 1f 437: movb 6(sp),1(sp) 438: br 2f 439: 1: 440: movb 6(sp),(sp) 441: 2: 442: mov (sp)+,r0 443: jsr pc,pword 444: clr r0 445: rts pc 446: 447: _fuiword: 448: _fuword: 449: mov 2(sp),r1 450: fuword: 451: jsr pc,gword 452: rts pc 453: 454: gword: 455: mov PS,-(sp) 456: bis $340,PS 457: mov nofault,-(sp) 458: mov $err,nofault 459: mfpi (r1) 460: mov (sp)+,r0 461: br 1f 462: 463: _suiword: 464: _suword: 465: mov 2(sp),r1 466: mov 4(sp),r0 467: suword: 468: jsr pc,pword 469: rts pc 470: 471: pword: 472: mov PS,-(sp) 473: bis $340,PS 474: mov nofault,-(sp) 475: mov $err,nofault 476: mov r0,-(sp) 477: mtpi (r1) 478: 1: 479: mov (sp)+,nofault 480: mov (sp)+,PS 481: rts pc 482: 483: err: 484: mov (sp)+,nofault 485: mov (sp)+,PS 486: tst (sp)+ 487: mov $-1,r0 488: rts pc 489: 490: .globl _copyin, _copyout 491: _copyin: 492: jsr pc,copsu 493: 1: 494: mfpi (r0)+ 495: mov (sp)+,(r1)+ 496: sob r2,1b 497: br 2f 498: 499: _copyout: 500: jsr pc,copsu 501: 1: 502: mov (r0)+,-(sp) 503: mtpi (r1)+ 504: sob r2,1b 505: 2: 506: mov (sp)+,nofault 507: mov (sp)+,r2 508: clr r0 509: rts pc 510: 511: copsu: 512: mov (sp)+,r0 513: mov r2,-(sp) 514: mov nofault,-(sp) 515: mov r0,-(sp) 516: mov 10(sp),r0 517: mov 12(sp),r1 518: mov 14(sp),r2 519: asr r2 520: mov $1f,nofault 521: rts pc 522: 523: 1: 524: mov (sp)+,nofault 525: mov (sp)+,r2 526: mov $-1,r0 527: rts pc 528: 529: .globl _idle 530: _idle: 531: mov PS,-(sp) 532: bic $340,PS 533: wait 534: mov (sp)+,PS 535: rts pc 536: 537: .globl _savu, _retu, _aretu 538: _savu: 539: bis $340,PS 540: mov (sp)+,r1 541: mov (sp),r0 542: mov sp,(r0)+ 543: mov r5,(r0)+ 544: bic $340,PS 545: jmp (r1) 546: 547: _aretu: 548: bis $340,PS 549: mov (sp)+,r1 550: mov (sp),r0 551: br 1f 552: 553: _retu: 554: bis $340,PS 555: mov (sp)+,r1 556: mov (sp),KISA6 557: mov $_u,r0 558: 1: 559: mov (r0)+,sp 560: mov (r0)+,r5 561: bic $340,PS 562: jmp (r1) 563: 564: .globl _spl0, _spl1, _spl4, _spl5, _spl6, _spl7 565: _spl0: 566: bic $340,PS 567: rts pc 568: 569: _spl1: 570: bis $40,PS 571: bic $300,PS 572: rts pc 573: 574: _spl4: 575: _spl5: 576: bis $340,PS 577: bic $100,PS 578: rts pc 579: 580: _spl6: 581: bis $340,PS 582: bic $40,PS 583: rts pc 584: 585: _spl7: 586: bis $340,PS 587: rts pc 588: 589: .globl _copyseg 590: _copyseg: 591: mov PS,-(sp) 592: mov UISA0,-(sp) 593: mov UISA1,-(sp) 594: mov $30340,PS 595: mov 10(sp),UISA0 596: mov 12(sp),UISA1 597: mov UISD0,-(sp) 598: mov UISD1,-(sp) 599: mov $6,UISD0 600: mov $6,UISD1 601: mov r2,-(sp) 602: clr r0 603: mov $8192.,r1 604: mov $32.,r2 605: 1: 606: mfpi (r0)+ 607: mtpi (r1)+ 608: sob r2,1b 609: mov (sp)+,r2 610: mov (sp)+,UISD1 611: mov (sp)+,UISD0 612: mov (sp)+,UISA1 613: mov (sp)+,UISA0 614: mov (sp)+,PS 615: rts pc 616: 617: .globl _clearseg 618: _clearseg: 619: mov PS,-(sp) 620: mov UISA0,-(sp) 621: mov $30340,PS 622: mov 6(sp),UISA0 623: mov UISD0,-(sp) 624: mov $6,UISD0 625: clr r0 626: mov $32.,r1 627: 1: 628: clr -(sp) 629: mtpi (r0)+ 630: sob r1,1b 631: mov (sp)+,UISD0 632: mov (sp)+,UISA0 633: mov (sp)+,PS 634: rts pc 635: 636: .globl _dpadd 637: _dpadd: 638: mov 2(sp),r0 639: add 4(sp),2(r0) 640: adc (r0) 641: rts pc 642: 643: .globl _dpcmp 644: _dpcmp: 645: mov 2(sp),r0 646: mov 4(sp),r1 647: sub 6(sp),r0 648: sub 8(sp),r1 649: sbc r0 650: bge 1f 651: cmp r0,$-1 652: bne 2f 653: cmp r1,$-512. 654: bhi 3f 655: 2: 656: mov $-512.,r0 657: rts pc 658: 1: 659: bne 2f 660: cmp r1,$512. 661: blo 3f 662: 2: 663: mov $512.,r1 664: 3: 665: mov r1,r0 666: rts pc 667: 668: .globl dump 669: dump: 670: bit $1,SSR0 671: bne dump 672: 673: / save regs r0,r1,r2,r3,r4,r5,r6,KIA6 674: / starting at abs location 4 675: 676: mov r0,4 677: mov $6,r0 678: mov r1,(r0)+ 679: mov r2,(r0)+ 680: mov r3,(r0)+ 681: mov r4,(r0)+ 682: mov r5,(r0)+ 683: mov sp,(r0)+ 684: mov KISA6,(r0)+ 685: 686: / dump all of core (ie to first mt error) 687: / onto mag tape. (9 track or 7 track 'binary') 688: 689: mov $MTC,r0 690: mov $60004,(r0)+ 691: clr 2(r0) 692: 1: 693: mov $-512.,(r0) 694: inc -(r0) 695: 2: 696: tstb (r0) 697: bge 2b 698: tst (r0)+ 699: bge 1b 700: reset 701: 702: / end of file and loop 703: 704: mov $60007,-(r0) 705: br . 706: 707: .globl start, _end, _edata, _main 708: start: 709: bit $1,SSR0 710: bne start / loop if restart 711: reset 712: 713: / initialize systems segments 714: 715: mov $KISA0,r0 716: mov $KISD0,r1 717: mov $200,r4 718: clr r2 719: mov $6,r3 720: 1: 721: mov r2,(r0)+ 722: mov $77406,(r1)+ / 4k rw 723: add r4,r2 724: sob r3,1b 725: 726: / initialize user segment 727: 728: mov $_end+63.,r2 729: ash $-6,r2 730: bic $!1777,r2 731: mov r2,(r0)+ / ksr6 = sysu 732: mov $usize-1\<8|6,(r1)+ 733: 734: / initialize io segment 735: / set up counts on supervisor segments 736: 737: mov $IO,(r0)+ 738: mov $77406,(r1)+ / rw 4k 739: 740: / get a sp and start segmentation 741: 742: mov $_u+[usize*64.],sp 743: inc SSR0 744: 745: / clear bss 746: 747: mov $_edata,r0 748: 1: 749: clr (r0)+ 750: cmp r0,$_end 751: blo 1b 752: 753: / clear user block 754: 755: mov $_u,r0 756: 1: 757: clr (r0)+ 758: cmp r0,$_u+[usize*64.] 759: blo 1b 760: 761: / set up previous mode and call main 762: / on return, enter user mode at 0R 763: 764: mov $30000,PS 765: jsr pc,_main 766: mov $170000,-(sp) 767: clr -(sp) 768: rtt 769: 770: .globl _ldiv 771: _ldiv: 772: clr r0 773: mov 2(sp),r1 774: div 4(sp),r0 775: rts pc 776: 777: .globl _lrem 778: _lrem: 779: clr r0 780: mov 2(sp),r1 781: div 4(sp),r0 782: mov r1,r0 783: rts pc 784: 785: .globl _lshift 786: _lshift: 787: mov 2(sp),r1 788: mov (r1)+,r0 789: mov (r1),r1 790: ashc 4(sp),r0 791: mov r1,r0 792: rts pc 793: 794: .globl csv 795: csv: 796: mov r5,r0 797: mov sp,r5 798: mov r4,-(sp) 799: mov r3,-(sp) 800: mov r2,-(sp) 801: jsr pc,(r0) 802: 803: .globl cret 804: cret: 805: mov r5,r1 806: mov -(r1),r4 807: mov -(r1),r3 808: mov -(r1),r2 809: mov r5,sp 810: mov (sp)+,r5 811: rts pc 812: 813: .globl _u 814: _u = 140000 815: usize = 16. 816: 817: PS = 177776 818: SSR0 = 177572 819: SSR2 = 177576 820: KISA0 = 172340 821: KISA6 = 172354 822: KISD0 = 172300 823: MTC = 172522 824: UISA0 = 177640 825: UISA1 = 177642 826: UISD0 = 177600 827: UISD1 = 177602 828: IO = 7600 829: 830: .data 831: .globl _ka6, _cputype 832: _ka6: KISA6 833: _cputype:40. 834: 835: .bss 836: .globl nofault, ssr, badtrap 837: nofault:.=.+2 838: ssr: .=.+6 839: badtrap:.=.+2