/ machine language assist for PDP-11/03, PDP-11/05, etc / assemble with appropriate header file for model selection / non-UNIX instructions halt = 0 wait = 1 rti = 2 reset = 5 .if M03 mtps = 106400^tst mfps = 106700^tst .endif .globl trap, call, emtrap .globl _trap trap: .if M03 mfps -4(sp) .endif .if M03-1 mov PS,-4(sp) .endif tst nofault bne 1f emtrap: jsr r0,call1; _trap / no return 1: mov nofault,(sp) rti .globl _runrun, _swtch call1: tst -(sp) .if M03 mfps -(sp) / r0/r1 in use as args bic $340,*sp / so use stack directly mtps (sp)+ .endif .if M03-1 bic $340,PS .endif br 1f call: .if M03 mfps -(sp) .endif .if M03-1 mov PS,-(sp) .endif 1: mov r1,-(sp) mov sp,r1 /get stack pointer at trap mov r1,-(sp) add $10.,(sp) mov 4(sp),-(sp) bic $!37,(sp) / trap type cmp 10.(sp),$_u+[usize*64.] blo 1f / trap from system mov 2(sp),r1 / trap from user, get user stack mov $_u+[usize*64.],sp mov -(r1),-(sp) / copy user stack to system stack mov -(r1),-(sp) mov -(r1),-(sp) mov -(r1),-(sp) mov -(r1),-(sp) mov -(r1),-(sp) mov -(r1),-(sp) jsr pc,*(r0)+ 2: .if M03 mfps r0 / OK to use R0 here; can only get here bis $340,r0 / via return from above call or call mtps r0 / to _swtch below .endif .if M03-1 bis $340,PS .endif tstb _runrun beq 2f .if M03 mfps r0 bic $340,r0 mtps r0 .endif .if M03-1 bic $340,PS .endif jsr pc,_swtch br 2b 1: jsr pc,*(r0)+ 2: tst (sp)+ mov (sp)+,r1 / new user stack pointer cmp 6(sp),$_u+[usize*64.] blo 1f / return from system trap sub $10.,r1 / begin. of system stack to be copied to user stack mov (sp)+,(r1)+ / copy system stack to user stack mov (sp)+,(r1)+ mov (sp)+,(r1)+ mov (sp)+,(r1)+ mov (sp)+,(r1)+ sub $10.,r1 mov r1,sp / switch to user stack 1: mov (sp)+,r1 tst (sp)+ mov (sp)+,r0 rti / Character list get/put .globl _getc, _putc .globl _cfreelist _getc: mov 2(sp),r1 .if M03 mfps -(sp) .endif .if M03-1 mov PS,-(sp) .endif mov r2,-(sp) .if M03 mfps r0 bis $340,r0 bic $100,r0 / spl 5 mtps r0 .endif .if M03-1 bis $340,PS bic $100,PS / spl 5 .endif mov 2(r1),r2 / first ptr beq 9f / empty movb (r2)+,r0 / character bic $!377,r0 mov r2,2(r1) dec (r1)+ / count bne 1f clr (r1)+ clr (r1)+ / last block br 2f 1: bit $7,r2 bne 3f mov -10(r2),(r1) / next block add $2,(r1) 2: dec r2 bic $7,r2 mov _cfreelist,(r2) mov r2,_cfreelist 3: mov (sp)+,r2 .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc 9: clr 4(r1) mov $-1,r0 mov (sp)+,r2 .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc _putc: mov 2(sp),r0 mov 4(sp),r1 .if M03 mfps -(sp) .endif .if M03-1 mov PS,-(sp) .endif mov r2,-(sp) mov r3,-(sp) .if M03 mfps r2 / already saved bis $340,r2 bic $100,r2 / spl 5 mtps r2 .endif .if M03-1 bis $340,PS bic $100,PS / spl 5 .endif mov 4(r1),r2 / last ptr bne 1f mov _cfreelist,r2 beq 9f mov (r2),_cfreelist clr (r2)+ mov r2,2(r1) / first ptr br 2f 1: bit $7,r2 bne 2f mov _cfreelist,r3 beq 9f mov (r3),_cfreelist mov r3,-10(r2) mov r3,r2 clr (r2)+ 2: movb r0,(r2)+ mov r2,4(r1) inc (r1) / count clr r0 mov (sp)+,r3 mov (sp)+,r2 .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc 9: mov pc,r0 mov (sp)+,r3 mov (sp)+,r2 .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc .globl _fubyte, _subyte .globl _fuibyte, _suibyte .globl _fuword, _suword .globl _fuiword, _suiword _fuibyte: _fubyte: mov 2(sp),r1 bic $1,r1 jsr pc,gword cmp r1,2(sp) beq 1f swab r0 1: bic $!377,r0 rts pc _suibyte: _subyte: mov 2(sp),r1 bic $1,r1 jsr pc,gword mov r0,-(sp) cmp r1,4(sp) beq 1f movb 6(sp),1(sp) br 2f 1: movb 6(sp),(sp) 2: mov (sp)+,r0 jsr pc,pword clr r0 rts pc _fuiword: _fuword: mov 2(sp),r1 fuword: jsr pc,gword rts pc gword: .if M03 mfps r0 mov r0,-(sp) bis $340,r0 mtps r0 .endif .if M03-1 mov PS,-(sp) bis $340,PS .endif mov nofault,-(sp) mov $err,nofault mov (r1),r0 br 1f _suiword: _suword: mov 2(sp),r1 mov 4(sp),r0 suword: jsr pc,pword rts pc pword: .if M03 mfps -(sp) / saved PS for restore on exit mfps -(sp) / whis one will be modified bis $340,*sp mtps (sp)+ .endif .if M03-1 mov PS,-(sp) bis $340,PS .endif mov nofault,-(sp) mov $err,nofault mov r0,(r1) 1: mov (sp)+,nofault .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc err: mov (sp)+,nofault .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif tst (sp)+ mov $-1,r0 rts pc .globl _copyin, _copyout _copyin: jsr pc,copsu 1: mov (r0)+,(r1)+ dec r2 bne 1b br 2f _copyout: jsr pc,copsu 1: mov (r0)+,(r1)+ dec r2 bne 1b 2: mov (sp)+,nofault mov (sp)+,r2 clr r0 rts pc copsu: mov (sp)+,r0 mov r2,-(sp) mov nofault,-(sp) mov r0,-(sp) mov 10(sp),r0 mov 12(sp),r1 mov 14(sp),r2 asr r2 mov $1f,nofault rts pc 1: mov (sp)+,nofault mov (sp)+,r2 mov $-1,r0 rts pc .globl _idle _idle: .if M03 mfps r0 mov r0,-(sp) bic $340,r0 mtps r0 .endif .if M03-1 mov PS,-(sp) bic $340,PS .endif wait .if M03 mtps (sp)+ .endif .if M03-1 mov (sp)+,PS .endif rts pc .globl _savu, _retu _savu: .if M03 mfps r0 bis $340,r0 mtps r0 .endif .if M03-1 bis $340,PS .endif mov (sp)+,r1 mov (sp),r0 mov sp,(r0)+ mov r5,(r0)+ .if M03 mfps r0 bic $340,r0 mtps r0 .endif .if M03-1 bic $340,PS .endif jmp (r1) _retu: .if M03 mfps r0 bis $340,r0 mtps r0 .endif .if M03-1 bis $340,PS .endif mov (sp)+,r1 mov (sp),r0 mov (r0)+,sp mov (r0)+,r5 .if M03 mfps r0 / OK to use, done with it bic $340,r0 mtps r0 .endif .if M03-1 bic $340,PS .endif jmp (r1) .globl _getps, _putps _getps: .if M03 mfps r0 .endif .if M03-1 mov PS,r0 .endif rts pc _putps: .if M03 mtps 2(sp) .endif .if M03-1 mov 2(sp),PS .endif rts pc .globl _spl0, _spl1, _spl4, _spl5, _spl6, _spl7 _spl0: .if M03 mfps r0 bic $340,r0 mtps r0 .endif .if M03-1 bic $340,PS .endif rts pc _spl1: .if M03 mfps r0 bis $40,r0 bic $300,r0 mtps r0 .endif .if M03-1 bis $40,PS bic $300,PS .endif rts pc _spl4: _spl5: .if M03 mfps r0 bis $340,r0 bic $100,r0 mtps r0 .endif .if M03-1 bis $340,PS bic $100,PS .endif rts pc _spl6: .if M03 mfps r0 bis $340,r0 bic $40,r0 mtps r0 .endif .if M03-1 bis $340,PS bic $40,PS .endif rts pc _spl7: .if M03 mfps r0 bis $340,r0 mtps r0 .endif .if M03-1 bis $340,PS .endif rts pc .globl _halt _halt: halt br _halt / poor man's printf .globl _prs _prs: mov $conout,r0 mov 2(sp),r1 1: tstb *r0 bpl 1b mov *r0,-(sp) clr *r0 2: tstb *r0 bpl 2b movb (r1)+,2(r0) tstb *r1 bne 2b mov (sp)+,*r0 rts pc .globl _prn _prn: mov r2,-(sp) mov 4(sp),r2 mov $nbe,r0 clrb -(r0) 1: mov r2,r1 bic $177770, r1 add $'0, r1 movb r1,-(r0) asr r2 asr r2 asr r2 bic $160000, r2 bne 1b mov (sp)+,r2 movb $'0,-(r0) mov r0,2(sp) br _prs / Startup .globl start, _edata, _main start: / clear bss and user block mov $_edata,r0 1: clr (r0)+ cmp r0,$_u+[usize*64.] blo 1b / set up stack pointer mov r0,sp / and pointer to system stack mov $_u-2,_u / set up previous mode and call main / on return, enter user mode at 060000 jsr pc,_main mov $_u+[usize*64.]+8192.,sp / set stack at first 4K of user space clr -(sp) mov $_u+[usize*64.],-(sp) rti /general utilities .globl _dpcmp _dpcmp: mov 2(sp),r0 mov 4(sp),r1 sub 6(sp),r0 sub 8(sp),r1 sbc r0 bge 1f cmp r0,$-1 bne 2f cmp r1,$-512. bhi 3f 2: mov $-512.,r0 rts pc 1: bne 2f cmp r1,$512. blo 3f 2: mov $512.,r1 3: mov r1,r0 rts pc .globl _dpadd _dpadd: mov 2(sp),r0 add 4(sp),2(r0) adc (r0) rts pc .globl _ldiv _ldiv: clr r0 mov 2(sp),r1 div 4(sp),r0 rts pc .globl _lrem _lrem: clr r0 mov 2(sp),r1 div 4(sp),r0 mov r1,r0 rts pc .globl _lshift _lshift: mov 2(sp),r1 mov (r1)+,r0 mov (r1),r1 ashc 4(sp),r0 mov r1,r0 rts pc .globl csv csv: mov r5,r0 mov sp,r5 mov r4,-(sp) mov r3,-(sp) mov r2,-(sp) jsr pc,(r0) .globl cret cret: mov r5,r1 mov -(r1),r4 mov -(r1),r3 mov -(r1),r2 mov r5,sp mov (sp)+,r5 rts pc .globl _u _u = 56000 usize = 16. .if M03-1 PS = 177776 .endif conin = 177560 conout = 177564 .bss numbuf: .=.+10 nbe: .=.+2 .globl nofault nofault:.=.+2