1: / machine language assist 2: / for 11/40 3: 4: 5: / non-UNIX instructions 6: mfpi = 6500^tst 7: mtpi = 6600^tst 8: halt = 0 9: wait = 1 10: reset = 5 11: rtt = 6 12: 13: .globl start, _end, _edata, _main, dump 14: dump: 15: start: 16: mov $trap,34 17: 18: / Set location 0 and 2 to catch traps and jumps to 0 19: 20: mov $42,0 / illegal instruction if jump 21: mov $777,2 / trace trap at high priority if trap 22: 23: / initialize systems segments 24: 25: mov $KISA0,r0 26: mov $KISD0,r1 27: mov $200,r4 28: clr r2 29: mov $6,r3 30: 1: 31: mov r2,(r0)+ 32: mov $77406,(r1)+ / 4k rw 33: add r4,r2 34: sob r3,1b 35: 36: / initialize user segment 37: 38: mov $_end+63.,r2 39: ash $-6,r2 40: bic $!1777,r2 41: mov r2,(r0)+ / ksr6 = sysu 42: mov $usize-1\<8|6,(r1)+ 43: 44: / initialize io segment 45: / set up counts on supervisor segments 46: 47: mov $IO,(r0)+ 48: mov $77406,(r1)+ / rw 4k 49: 50: / get a sp and start segmentation 51: 52: mov $_u+[usize*64.],sp 53: 54: inc SSR0 55: / test for floating point 56: mov $1f,nofault 57: setd / jumps to 1f if no fpu 58: inc fpp 59: 1: 60: clr nofault 61: 62: / clear bss 63: 64: mov $_edata,r0 65: 1: 66: clr (r0)+ 67: cmp r0,$_end 68: blo 1b 69: 70: / clear user block 71: 72: mov $_u,r0 73: 1: 74: clr (r0)+ 75: cmp r0,$_u+[usize*64.] 76: blo 1b 77: 78: / set up previous mode and call main 79: / on return, enter user mode at 0R 80: 81: mov $30000,PS 82: jsr pc,_main 83: mov $170000,-(sp) 84: clr -(sp) 85: rtt 86: 87: .globl trap, call 88: .globl _trap 89: 90: / all traps and interrupts are 91: / vectored thru this routine. 92: 93: trap: 94: mov PS,saveps 95: tst nofault 96: bne 1f 97: mov SSR0,ssr 98: mov SSR2,ssr+4 99: mov $1,SSR0 100: jsr r0,call1; jmp _trap 101: / no return 102: 1: 103: mov $1,SSR0 104: mov nofault,(sp) 105: rtt 106: .text 107: 108: .globl _runrun 109: call1: 110: mov saveps,-(sp) 111: bic $HIPRI,PS 112: br 1f 113: 114: call: 115: mov PS,-(sp) 116: 1: 117: mov r1,-(sp) 118: mfpi sp 119: mov 4(sp),-(sp) 120: bic $!37,(sp) 121: bit $30000,PS 122: beq 1f 123: jsr pc,(r0)+ 124: tstb _runrun 125: beq 2f 126: mov $12.,(sp) / trap 12 is give up cpu 127: jsr pc,_trap 128: 2: 129: tst (sp)+ 130: mtpi sp 131: br 2f 132: 1: 133: bis $30000,PS 134: jsr pc,(r0)+ 135: cmp (sp)+,(sp)+ 136: 2: 137: mov (sp)+,r1 138: tst (sp)+ 139: mov (sp)+,r0 140: rtt 141: .globl _savfp 142: _savfp: 143: tst fpp 144: beq 8f 145: mov 2(sp),r1 146: stfps (r1)+ 147: setd 148: movf fr0,(r1)+ 149: movf fr1,(r1)+ 150: movf fr2,(r1)+ 151: movf fr3,(r1)+ 152: movf fr4,fr0 153: movf fr0,(r1)+ 154: movf fr5,fr0 155: movf fr0,(r1)+ 156: 8: 157: rts pc 158: 159: .globl _restfp 160: _restfp: 161: tst fpp 162: beq 8f 163: mov 2(sp),r1 164: mov r1,r0 165: setd 166: add $8.+2.,r1 167: movf (r1)+,fr1 168: movf (r1)+,fr2 169: movf (r1)+,fr3 170: movf (r1)+,fr0 171: movf fr0,fr4 172: movf (r1)+,fr0 173: movf fr0,fr5 174: movf 2(r0),fr0 175: ldfps (r0) 176: 8: 177: rts pc 178: 179: .globl _addupc 180: _addupc: 181: mov r2,-(sp) 182: mov 6(sp),r2 / base of prof with base,leng,off,scale 183: mov 4(sp),r0 / pc 184: sub 4(r2),r0 / offset 185: clc 186: ror r0 187: mov 6(r2),r1 188: clc 189: ror r1 190: mul r1,r0 / scale 191: ashc $-14.,r0 192: inc r1 193: bic $1,r1 194: cmp r1,2(r2) / length 195: bhis 1f 196: add (r2),r1 / base 197: mov nofault,-(sp) 198: mov $2f,nofault 199: mfpi (r1) 200: add 12.(sp),(sp) 201: mtpi (r1) 202: br 3f 203: 2: 204: clr 6(r2) 205: 3: 206: mov (sp)+,nofault 207: 1: 208: mov (sp)+,r2 209: rts pc 210: 211: .globl _display 212: _display: 213: rts pc 214: 215: / Character list get/put 216: 217: /.globl _getc, _putc 218: /.globl _cfreelist 219: / 220: /_getc: 221: / mov 2(sp),r1 222: / mov PS,-(sp) 223: / mov r2,-(sp) 224: / bis $HIPRI,PS 225: / bic $40,PS 226: / mov 2(r1),r2 / first ptr 227: / beq 9f / empty 228: / movb (r2)+,r0 / character 229: / bic $!377,r0 230: / mov r2,2(r1) 231: / dec (r1)+ / count 232: / bne 1f 233: / clr (r1)+ 234: / clr (r1)+ / last block 235: / br 2f 236: /1: 237: / bit $7,r2 238: / bne 3f 239: / mov -10(r2),(r1) / next block 240: / add $2,(r1) 241: /2: 242: / dec r2 243: / bic $7,r2 244: / mov _cfreelist,(r2) 245: / mov r2,_cfreelist 246: /3: 247: / mov (sp)+,r2 248: / mov (sp)+,PS 249: / rts pc 250: /9: 251: / clr 4(r1) 252: / mov $-1,r0 253: / mov (sp)+,r2 254: / mov (sp)+,PS 255: / rts pc 256: / 257: /_putc: 258: / mov 2(sp),r0 259: / mov 4(sp),r1 260: / mov PS,-(sp) 261: / mov r2,-(sp) 262: / mov r3,-(sp) 263: / bis $HIPRI,PS 264: / bic $40,PS 265: / mov 4(r1),r2 / last ptr 266: / bne 1f 267: / mov _cfreelist,r2 268: / beq 9f 269: / mov (r2),_cfreelist 270: / clr (r2)+ 271: / mov r2,2(r1) / first ptr 272: / br 2f 273: /1: 274: / bit $7,r2 275: / bne 2f 276: / mov _cfreelist,r3 277: / beq 9f 278: / mov (r3),_cfreelist 279: / mov r3,-10(r2) 280: / mov r3,r2 281: / clr (r2)+ 282: /2: 283: / movb r0,(r2)+ 284: / mov r2,4(r1) 285: / inc (r1) / count 286: / clr r0 287: / mov (sp)+,r3 288: / mov (sp)+,r2 289: / mov (sp)+,PS 290: / rts pc 291: /9: 292: / mov pc,r0 293: / mov (sp)+,r3 294: / mov (sp)+,r2 295: / mov (sp)+,PS 296: / rts pc 297: 298: .globl _backup 299: .globl _regloc 300: _backup: 301: mov 2(sp),ssr+2 302: mov r2,-(sp) 303: jsr pc,backup 304: mov r2,ssr+2 305: mov (sp)+,r2 306: movb jflg,r0 307: bne 2f 308: mov 2(sp),r0 309: movb ssr+2,r1 310: jsr pc,1f 311: movb ssr+3,r1 312: jsr pc,1f 313: movb _regloc+7,r1 314: asl r1 315: add r0,r1 316: mov ssr+4,(r1) 317: clr r0 318: 2: 319: rts pc 320: 1: 321: mov r1,-(sp) 322: asr (sp) 323: asr (sp) 324: asr (sp) 325: bic $!7,r1 326: movb _regloc(r1),r1 327: asl r1 328: add r0,r1 329: sub (sp)+,(r1) 330: rts pc 331: 332: / hard part 333: / simulate the ssr2 register missing on 11/40 334: 335: backup: 336: clr r2 / backup register ssr1 337: mov $1,bflg / clrs jflg 338: mov ssr+4,r0 339: jsr pc,fetch 340: mov r0,r1 341: ash $-11.,r0 342: bic $!36,r0 343: jmp *0f(r0) 344: 0: t00; t01; t02; t03; t04; t05; t06; t07 345: t10; t11; t12; t13; t14; t15; t16; t17 346: 347: t00: 348: clrb bflg 349: 350: t10: 351: mov r1,r0 352: swab r0 353: bic $!16,r0 354: jmp *0f(r0) 355: 0: u0; u1; u2; u3; u4; u5; u6; u7 356: 357: u6: / single op, m[tf]pi, sxt, illegal 358: bit $400,r1 359: beq u5 / all but m[tf], sxt 360: bit $200,r1 361: beq 1f / mfpi 362: bit $100,r1 363: bne u5 / sxt 364: 365: / simulate mtpi with double (sp)+,dd 366: bic $4000,r1 / turn instr into (sp)+ 367: br t01 368: 369: / simulate mfpi with double ss,-(sp) 370: 1: 371: ash $6,r1 372: bis $46,r1 / -(sp) 373: br t01 374: 375: u4: / jsr 376: mov r1,r0 377: jsr pc,setreg / assume no fault 378: bis $173000,r2 / -2 from sp 379: rts pc 380: 381: t07: / EIS 382: clrb bflg 383: 384: u0: / jmp, swab 385: u5: / single op 386: f5: / movei, movfi 387: ff1: / ldfps 388: ff2: / stfps 389: ff3: / stst 390: mov r1,r0 391: br setreg 392: 393: t01: / mov 394: t02: / cmp 395: t03: / bit 396: t04: / bic 397: t05: / bis 398: t06: / add 399: t16: / sub 400: clrb bflg 401: 402: t11: / movb 403: t12: / cmpb 404: t13: / bitb 405: t14: / bicb 406: t15: / bisb 407: mov r1,r0 408: ash $-6,r0 409: jsr pc,setreg 410: swab r2 411: mov r1,r0 412: jsr pc,setreg 413: 414: / if delta(dest) is zero, 415: / no need to fetch source 416: 417: bit $370,r2 418: beq 1f 419: 420: / if mode(source) is R, 421: / no fault is possible 422: 423: bit $7000,r1 424: beq 1f 425: 426: / if reg(source) is reg(dest), 427: / too bad. 428: 429: mov r2,-(sp) 430: bic $174370,(sp) 431: cmpb 1(sp),(sp)+ 432: beq u7 433: 434: / start source cycle 435: / pick up value of reg 436: 437: mov r1,r0 438: ash $-6,r0 439: bic $!7,r0 440: movb _regloc(r0),r0 441: asl r0 442: add ssr+2,r0 443: mov (r0),r0 444: 445: / if reg has been incremented, 446: / must decrement it before fetch 447: 448: bit $174000,r2 449: ble 2f 450: dec r0 451: bit $10000,r2 452: beq 2f 453: dec r0 454: 2: 455: 456: / if mode is 6,7 fetch and add X(R) to R 457: 458: bit $4000,r1 459: beq 2f 460: bit $2000,r1 461: beq 2f 462: mov r0,-(sp) 463: mov ssr+4,r0 464: add $2,r0 465: jsr pc,fetch 466: add (sp)+,r0 467: 2: 468: 469: / fetch operand 470: / if mode is 3,5,7 fetch * 471: 472: jsr pc,fetch 473: bit $1000,r1 474: beq 1f 475: bit $6000,r1 476: bne fetch 477: 1: 478: rts pc 479: 480: t17: / floating point instructions 481: clrb bflg 482: mov r1,r0 483: swab r0 484: bic $!16,r0 485: jmp *0f(r0) 486: 0: f0; f1; f2; f3; f4; f5; f6; f7 487: 488: f0: 489: mov r1,r0 490: ash $-5,r0 491: bic $!16,r0 492: jmp *0f(r0) 493: 0: ff0; ff1; ff2; ff3; ff4; ff5; ff6; ff7 494: 495: f1: / mulf, modf 496: f2: / addf, movf 497: f3: / subf, cmpf 498: f4: / movf, divf 499: ff4: / clrf 500: ff5: / tstf 501: ff6: / absf 502: ff7: / negf 503: inc fflg 504: mov r1,r0 505: br setreg 506: 507: f6: 508: bit $400,r1 509: beq f1 / movfo 510: br f5 / movie 511: 512: f7: 513: bit $400,r1 514: beq f5 / movif 515: br f1 / movof 516: 517: ff0: / cfcc, setf, setd, seti, setl 518: u1: / br 519: u2: / br 520: u3: / br 521: u7: / illegal 522: incb jflg 523: rts pc 524: 525: setreg: 526: mov r0,-(sp) 527: bic $!7,r0 528: bis r0,r2 529: mov (sp)+,r0 530: ash $-3,r0 531: bic $!7,r0 532: movb 0f(r0),r0 533: tstb bflg 534: beq 1f 535: bit $2,r2 536: beq 2f 537: bit $4,r2 538: beq 2f 539: 1: 540: cmp r0,$20 541: beq 2f 542: cmp r0,$-20 543: beq 2f 544: asl r0 545: 2: 546: tstb fflg 547: beq 3f 548: asl r0 549: stfps r1 550: bit $200,r1 551: beq 3f 552: asl r0 553: 3: 554: bisb r0,r2 555: rts pc 556: 557: 0: .byte 0,0,10,20,-10,-20,0,0 558: 559: fetch: 560: bic $1,r0 561: mov nofault,-(sp) 562: mov $1f,nofault 563: mfpi (r0) 564: mov (sp)+,r0 565: mov (sp)+,nofault 566: rts pc 567: 568: 1: 569: mov (sp)+,nofault 570: clrb r2 / clear out dest on fault 571: mov $-1,r0 572: rts pc 573: 574: .bss 575: bflg: .=.+1 576: jflg: .=.+1 577: fflg: .=.+1 578: .text 579: 580: .text 581: 582: .globl _fubyte, _subyte 583: .globl _fuibyte, _suibyte 584: .globl _fuword, _suword 585: .globl _fuiword, _suiword 586: _fuibyte: 587: _fubyte: 588: mov 2(sp),r1 589: bic $1,r1 590: jsr pc,gword 591: cmp r1,2(sp) 592: beq 1f 593: swab r0 594: 1: 595: bic $!377,r0 596: rts pc 597: 598: _suibyte: 599: _subyte: 600: mov 2(sp),r1 601: bic $1,r1 602: jsr pc,gword 603: mov r0,-(sp) 604: cmp r1,4(sp) 605: beq 1f 606: movb 6(sp),1(sp) 607: br 2f 608: 1: 609: movb 6(sp),(sp) 610: 2: 611: mov (sp)+,r0 612: jsr pc,pword 613: clr r0 614: rts pc 615: _fuiword: 616: _fuword: 617: mov 2(sp),r1 618: fuword: 619: jsr pc,gword 620: rts pc 621: 622: gword: 623: mov PS,-(sp) 624: bis $HIPRI,PS 625: mov nofault,-(sp) 626: mov $err,nofault 627: mfpi (r1) 628: mov (sp)+,r0 629: br 1f 630: 631: _suiword: 632: _suword: 633: mov 2(sp),r1 634: mov 4(sp),r0 635: suword: 636: jsr pc,pword 637: rts pc 638: 639: pword: 640: mov PS,-(sp) 641: bis $HIPRI,PS 642: mov nofault,-(sp) 643: mov $err,nofault 644: mov r0,-(sp) 645: mtpi (r1) 646: 1: 647: mov (sp)+,nofault 648: mov (sp)+,PS 649: rts pc 650: 651: err: 652: mov (sp)+,nofault 653: mov (sp)+,PS 654: tst (sp)+ 655: mov $-1,r0 656: rts pc 657: rts pc 658: .globl _copyin, _copyout 659: .globl _copyiin, _copyiout 660: _copyiin: 661: _copyin: 662: jsr pc,copsu 663: 1: 664: mfpi (r0)+ 665: mov (sp)+,(r1)+ 666: sob r2,1b 667: br 2f 668: 669: _copyiout: 670: _copyout: 671: jsr pc,copsu 672: 1: 673: mov (r0)+,-(sp) 674: mtpi (r1)+ 675: sob r2,1b 676: 2: 677: mov (sp)+,nofault 678: mov (sp)+,r2 679: clr r0 680: rts pc 681: 682: copsu: 683: mov (sp)+,r0 684: mov r2,-(sp) 685: mov nofault,-(sp) 686: mov r0,-(sp) 687: mov 10(sp),r0 688: mov 12(sp),r1 689: mov 14(sp),r2 690: asr r2 691: mov $1f,nofault 692: rts pc 693: 694: 1: 695: mov (sp)+,nofault 696: mov (sp)+,r2 697: mov $-1,r0 698: rts pc 699: 700: .globl _idle, _waitloc 701: _idle: 702: mov PS,-(sp) 703: bic $HIPRI,PS 704: wait 705: waitloc: 706: mov (sp)+,PS 707: rts pc 708: .data 709: _waitloc: 710: waitloc 711: .text 712: 713: .globl _save 714: _save: 715: mov (sp)+,r1 716: mov (sp),r0 717: mov r2,(r0)+ 718: mov r3,(r0)+ 719: mov r4,(r0)+ 720: mov r5,(r0)+ 721: mov sp,(r0)+ 722: mov r1,(r0)+ 723: clr r0 724: jmp (r1) 725: 726: .globl _resume 727: _resume: 728: mov 2(sp),r0 / new process 729: mov 4(sp),r1 / new stack 730: bis $HIPRI,PS 731: mov r0,KISA6 / In new process 732: mov (r1)+,r2 733: mov (r1)+,r3 734: mov (r1)+,r4 735: mov (r1)+,r5 736: mov (r1)+,sp 737: mov $1,r0 738: bic $HIPRI,PS 739: jmp *(r1)+ 740: 741: .globl _spl0, _spl1, _spl4, _spl5, _spl6, _spl7, _splx 742: _spl0: 743: mov PS,r0 744: bic $HIPRI,PS 745: rts pc 746: 747: _spl1: 748: mov PS,r0 749: bis $HIPRI,PS 750: bic $300,PS 751: rts pc 752: 753: _spl4: 754: mov PS,r0 755: bis $HIPRI,PS 756: bic $140,PS 757: rts pc 758: 759: _spl5: 760: mov PS,r0 761: bis $HIPRI,PS 762: bic $100,PS 763: rts pc 764: 765: _spl6: 766: mov PS,r0 767: bis $HIPRI,PS 768: bic $40,PS 769: rts pc 770: 771: _spl7: 772: mov PS,r0 773: bis $HIPRI,PS 774: rts pc 775: 776: _splx: 777: mov 2(sp),PS 778: rts pc 779: 780: .globl _copyseg 781: _copyseg: 782: mov PS,-(sp) 783: mov UISA0,-(sp) 784: mov UISA1,-(sp) 785: mov $30340,PS 786: mov 10(sp),UISA0 787: mov 12(sp),UISA1 788: mov UISD0,-(sp) 789: mov UISD1,-(sp) 790: mov $6,UISD0 791: mov $6,UISD1 792: mov r2,-(sp) 793: clr r0 794: mov $8192.,r1 795: mov $32.,r2 796: 1: 797: mfpi (r0)+ 798: mtpi (r1)+ 799: sob r2,1b 800: mov (sp)+,r2 801: mov (sp)+,UISD1 802: mov (sp)+,UISD0 803: mov (sp)+,UISA1 804: mov (sp)+,UISA0 805: mov (sp)+,PS 806: rts pc 807: 808: .globl _clearseg 809: _clearseg: 810: mov PS,-(sp) 811: mov UISA0,-(sp) 812: mov $30340,PS 813: mov 6(sp),UISA0 814: mov UISD0,-(sp) 815: mov $6,UISD0 816: clr r0 817: mov $32.,r1 818: 1: 819: clr -(sp) 820: mtpi (r0)+ 821: sob r1,1b 822: mov (sp)+,UISD0 823: mov (sp)+,UISA0 824: mov (sp)+,PS 825: rts pc 826: 827: .globl _piget, _piput 828: _piget: 829: mov PS,-(sp) 830: jsr pc,2f 831: mfpi (r0) 832: mov (sp)+,r0 833: 1: 834: mov (sp)+,PS 835: rts pc 836: 837: _piput: 838: mov PS,-(sp) 839: jsr pc,2f 840: mov 10(sp),r1 841: mov r1,-(sp) 842: mtpi (r0) 843: br 1b 844: 2: 845: mov 6(sp),r0 846: mov 10(sp),r1 847: ashc $-6,r0 848: mov HIPRI,PS 849: mov r1,KISA7 850: mov 10(sp),r0 851: bic $!77,r0 852: bis $160000,r0 853: rts pc 854: 855: / Long quotient 856: 857: .globl ldiv 858: ldiv: 859: jsr r5,csv 860: mov 10.(r5),r3 861: sxt r4 862: bpl 1f 863: neg r3 864: 1: 865: cmp r4,8.(r5) 866: bne hardldiv 867: mov 6.(r5),r2 868: mov 4.(r5),r1 869: bge 1f 870: neg r1 871: neg r2 872: sbc r1 873: com r4 874: 1: 875: mov r4,-(sp) 876: clr r0 877: div r3,r0 878: mov r0,r4 /high quotient 879: mov r1,r0 880: mov r2,r1 881: div r3,r0 882: bvc 1f 883: sub r3,r0 / this is the clever part 884: div r3,r0 885: tst r1 886: sxt r1 887: add r1,r0 / cannot overflow! 888: 1: 889: mov r0,r1 890: mov r4,r0 891: tst (sp)+ 892: bpl 9f 893: neg r0 894: neg r1 895: sbc r0 896: 9: 897: jmp cret 898: 899: hardldiv: 900: 4 901: 902: / Long remainder 903: 904: .globl lrem 905: lrem: 906: jsr r5,csv 907: mov 10.(r5),r3 908: sxt r4 909: bpl 1f 910: neg r3 911: 1: 912: cmp r4,8.(r5) 913: bne hardlrem 914: mov 6.(r5),r2 915: mov 4.(r5),r1 916: mov r1,r4 917: bge 1f 918: neg r1 919: neg r2 920: sbc r1 921: 1: 922: clr r0 923: div r3,r0 924: mov r1,r0 925: mov r2,r1 926: div r3,r0 927: bvc 1f 928: sub r3,r0 929: div r3,r0 930: tst r1 931: beq 9f 932: add r3,r1 933: 1: 934: tst r4 935: bpl 9f 936: neg r1 937: 9: 938: sxt r0 939: jmp cret 940: 941: / The divisor is known to be >= 2^15. Only 16 cycles are 942: / needed to get a remainder. 943: hardlrem: 944: 4 945: 946: .globl csv 947: csv: 948: mov r5,r0 949: mov sp,r5 950: mov r4,-(sp) 951: mov r3,-(sp) 952: mov r2,-(sp) 953: jsr pc,(r0) 954: 955: .globl cret 956: cret: 957: mov r5,r2 958: mov -(r2),r4 959: mov -(r2),r3 960: mov -(r2),r2 961: mov r5,sp 962: mov (sp)+,r5 963: rts pc 964: 965: .globl _u 966: _u = 140000 967: usize = 16. 968: 969: HIPRI = 340 970: 971: PS = 177776 972: SSR0 = 177572 973: SSR2 = 177576 974: KISA0 = 172340 975: KISA6 = 172354 976: KISA7 = 172356 977: KISD0 = 172300 978: MTC = 172522 979: TUC = 172440 980: UISA0 = 177640 981: UISA1 = 177642 982: UISD0 = 177600 983: UISD1 = 177602 984: IO = 7600 985: 986: .data 987: .globl _ka6 988: .globl _cputype 989: 990: _ka6: KISA6 991: _cputype:40. 992: stk: 0 993: 994: .bss 995: nofault:.=.+2 996: ssr: .=.+6 997: saveps: .=.+2 998: power: .=.+2 999: fpp: .=.+2 1000: 1001: .globl _stst 1002: .text 1003: .globl _stst 1004: stst = 170300^tst 1005: _stst: 1006: tst fpp 1007: beq 9f 1008: stst r0 1009: mov r0,*2(sp) 1010: 9: 1011: rts pc