/ / (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. / / This product is part of the Amsterdam Compiler Kit. / / Permission to use, sell, duplicate or disclose this software must be / obtained in writing. Requests for such permissions may be sent to / / Dr. Andrew S. Tanenbaum / Wiskundig Seminarium / Vrije Universiteit / Postbox 7161 / 1007 MC Amsterdam / The Netherlands / / /------------------------------------------------------------------------------ / indir = 0 exit = 1 fork = 2 read = 3 write = 4 open = 5 close = 6 creat = 8. unlink = 10. break = 17. alarm = 27. pause = 29. sleep = 35. signal = 48. iot = 4 /------------------------------------------------------------------------------ / External references /------------------------------------------------------------------------------ .globl _end / /------------------------------------------------------------------------------ / Now the real program starts /------------------------------------------------------------------------------ startoff: mov sp,memlim mov $ldfail,r5 mov $emfile,forward+2 sys indir;forward jes badruninf; mov r0,saver0; mov $rhfail,r5; sys read;header;34. jes badruninf; cmp $34.,r0 jne badruninf mov $rtfail,r5 mov $_end,loadstart mov option,r1 bit $17774,r1 bne 1f mov tblmax,globmax 1: bit $1,r1 beq 1f mov saver0,r0 sys read;lasttab;98. jes badruninf; 1: bit $2,r1 beq 1f mov saver0,r0 sys read;opfrb;512. jes badruninf mov saver0,r0 sys read;opfra;512. jes badruninf mov saver0,r0 sys read;opfrc;640. jes badruninf 1: bit $4,r1 beq 1f mov saver0,r0 sys read;lcount;4 jes badruninf 1: bit $8.,r1 beq 1f mov saver0,r0 sys read;lflow;4 jes badruninf 1: bit $16.,r1 beq 1f mov saver0,r0 sys read;ltime;4 jes badruninf 1: mov tblmax,r3 sub pd,r3 sub ml,r3 mov $_end,sybreak+2 add r3,sybreak+2; sys indir;sybreak mov r3,lblread+4 mov $_end,lblread+2; mov saver0,r0 sys indir;lblread; jes badruninf mov saver0,r0 sys close sys unlink;emfile lbladj: add $header,linused sub header,linused mov pd,filext sub loadstart,filext mov filext,filarg add ml,filarg sub tblmax,filarg lbllast: bit $1,option /test for last beq 2f / no last table jump sys creat;emlast;666 bcs 2f cmp linused,$lasttab bhis 3f mov $yetmsg,lblwri+2 mov $40.,lblwri+4 sys indir;lblwri br 2f 3: mov r0,saver0 cmp linused-2,$-1 bne 6f mov $linused-2,linused clr linused-2 6: jsr pc,slilast inc r2 jsr pc,nexttab tst (r5) beq 3f sub $2,linused cmp eb,(r5) blo 3f 7: cmp r2,$lnend blt 1f jsr pc,slnlast 1: jsr pc,lnrnxt bne 7b 3: jsr pc,sfllast bne 6b mov saver0,r0 sys close 2: lblopfreq: bit $2,option beq 9f sys creat;emopf;666 bcs 9f mov r0,saver0 mov $opcode,r3 mov $104.,r4 mov $counttab,r5 0: mov $lnlast,r2 mov $8.,r0 2: movb (r3)+,(r2)+ sob r0,2b add $8,r2 mov r2,-(sp) jsr pc,ltoa mov (sp)+,r2 add $5,r2 mov $8.,r0 2: movb (r3)+,(r2)+ sob r0,2b add $8,r2 mov r2,-(sp) jsr pc,ltoa mov (sp)+,r2 add $5,r2 mov $8.,r0 2: movb (r3)+,(r2)+ sob r0,2b add $8,r2 mov r2,-(sp) jsr pc,ltoa mov (sp)+,r2 add $5,r2 mov $8.,r0 2: movb (r3)+,(r2)+ sob r0,2b add $8,r2 mov r2,-(sp) jsr pc,ltoa mov (sp)+,r2 mov r3,-(sp) jsr pc,slnlast mov (sp)+,r3 sob r4,0b mov saver0,r0 sys close 9: lblcount: clr filb bit $4,option beq 9f sys creat;emcount;666 bcs 9f mov r0,saver0 mov lcount,r5 add $4,r5 sub filext,r5 jsr pc,procrun mov saver0,r0 sys close 9: lblprof: bit $16.,option beq 9f sys creat;emprof;666 bcs 9f mov r0,saver0 mov ltime,r5 sub filext,r5 mov $profmsg,lblwri+2 mov $29,lblwri+4 mov $profmsg+27,r2 jsr pc,ltoa mov saver0,r0 sys indir;lblwri jsr pc,procrun mov saver0,r0 sys close 9: lblflow: mov $1,filb bit $8.,option beq 9f sys creat;emflow;666 bcs 9f mov lflow,r5 mov $-1,flowsiz sub filext,r5 jsr pc,procrun mov saver0,r0 sys close 9: clr r0 sys exit badruninf: mov $0f,lblwri+2 mov $21.,lblwri+4 mov $2,r0 sys indir;lblwri mov r5,lblwri+2 mov $23.,lblwri+4 mov $2,r0 sys indir;lblwri iot /force core dump .data lblwri: sys write;0;0 forward: sys open;0;0 sybreak: sys break;0; lblread: sys read;0;0 0: ldfail: < open runinf failed \n\0> rhfail: < read header failed \n\0> rtfail: < read tables failed \n\0> msgto: emlast: emcount: emfile: emopf: emprof: emflow: yetmsg: unknown: lilast: <\nlines \0> lnlast: < > < > lnend: < \0> fllast: < of file > < \0> profmsg:<\ninitialization \n\0> sep: <\n\0> /---------------------------------------------------------------------------- opcode: .even .text /------------------------------------------------------------------------------ / General subroutines /------------------------------------------------------------------------------ wrdoff: movb (r3)+,r0 /get first byte swab r0 /put it in high byte clrb r0 /clear low byte of r0 bisb (r3)+,r0 /"or" second byte in rts pc /done /------------------------------------------------------------------------------ nexttab: mov linused,r5; add $2,r5 / increment lasttab cmp r5,$linused / top of table reached? blo 1f sub $96.,r5 1: mov r5,linused rts pc slilast: mov $lnlast,r2 mov $6,r0 mov $lilast,r3 2: movb (r3)+,(r2)+ sob r0,2b rts pc slnlast: mov $lnlast,lblwri+2 mov r2,r3 sub $lnlast,r3 beq 3f inc r3 movb sep,(r2) 1: mov r3,lblwri+4 mov saver0,r0 sys indir; lblwri mov $lnlast,r2 2: movb $' ,(r2)+ sob r3,2b 3: mov $lnlast,r2 rts pc lnrnxt: jsr pc,nexttab tst (r5) ble 0f mov (r5),r1 clr (r5) add $6,r2 mov r2,r0 jsr pc,itoa 0: rts pc sfllast:jsr pc,nexttab tst (r5) bne 0f clr linused mov eb,-(sp) sub filext,(sp) add $4,(sp) mov *(sp),(sp) mov (sp)+,(r5) 0: jsr pc,slnlast jsr pc,filadj mov $14.,r3 mov $fllast+14.,r2 mov (r5),r0 3: inc r3 movb (r0)+,(r2)+ bne 3b movb sep,-(r2) mov $fllast,lblwri+2 mov r3,lblwri+4 mov saver0,r0 sys indir;lblwri mov $fllast+14.,r2 sub $10.,r3 2: movb $' ,(r2)+ sob r3,2b clr (r5) tst linused beq 2f jsr pc,slilast 2: rts pc filadj: cmp ml,(r5) bhi 8f sub filarg,(r5) br 7f 8: cmp eb,(r5) bhi 7f sub filext,(r5) 7: rts pc procrun: mov firstp,r4 sub filext,r4 0: tst 4(r4) beq 8f jsr pc,msgfile mov r4,-(sp) mov countsiz,r4 7: cmp r2,$lnend+10 blo 6f jsr pc,slnlast mov $lnlast,r2 6: tst filb bne 3f add $11.,r2 mov r2,-(sp) jsr pc,ltoa mov (sp)+,r2 br 4f 3: jsr pc,bittoa add $4,r2 4: sob r4,7b jsr pc,slnlast mov (sp)+,r4 8: mov 8.(r4),r4 beq 8f sub filext,r4 br 0b mov r0,saver0 sys write;sep;1 8: rts pc msgfile: jsr pc,slilast add $6,r2 mov 6(r4),r1 mov r2,r0 jsr pc,itoa add $4,r2 movb msgto,(r2)+ movb msgto+1,(r2)+ add $6,r2 mov 8.(r4),r1 3: bne 1f mov maxcount,r1 br 2f 1: sub filext,r1 tst 4(r1) beq 1f mov 4(r1),r1 br 2f 1: mov 8.(r1),r1 br 3b 2: sub 4(r4),r1 mov r1,countsiz dec r1 / is this a bug? add 6(r4),r1 mov r2,r0 jsr pc,itoa mov $fllast,r3 mov $14,r1 2: movb (r3)+,(r2)+ sob r1,2b mov 10.(r4),r3 bne 6f mov $unknown,r3 br 5f 6: cmp ml,r3 bhi 4f sub filarg,r3 br 5f 4: cmp eb,r3 bhi 5f sub filext,r3 5: lblmsgf: 2: movb (r3)+,(r2)+ bne 2b jsr pc,slnlast rts pc itoa: mov r5,-(sp) mov r0,r5 1: clr r0 div $10.,r0 add $'0,r1 movb r1,-(r5) mov r0,r1 bne 1b mov r5,r0 mov (sp)+,r5 rts pc rts pc ltoa: 0: mov (r5),r1 clr r0 div $10.,r0 mov r0,(r5) swab r1 clr r0 bisb 3(r5),r1 div $10.,r0 movb r0,3(r5) clr r0 swab r1 bisb 2(r5),r1 div $10.,r0 add $'0,r1 movb r1,-(r2) movb r0,2(r5) bne 0b tst (r5) bne 0b add $4,r5 rts pc bittoa: mov (r5),r1 mov flowsiz,r0 ash r0,r1 bit $1,r1 beq 0f movb $'1,(r2) br 1f 0: movb $'0,(r2) 1: dec r0 cmp $-16.,r0 beq 2f mov r0,flowsiz br 3f 2: clr flowsiz add $2,r5 3: rts pc /------------------------------------------------------------------------------ / Leftover data /------------------------------------------------------------------------------ .bss filb: .=.+2 loadstart: .=.+2 saver0: .=.+2 filarg: .=.+2 filext: .=.+2 memlim: .=.+2 header: bstrt: txtsiz: .=.+2 bend: ndatad: .=.+2 nprocs: .=.+2 option: entry.: .=.+2 nlines: .=.+2 szdata: .=.+2 firstp: .=.+2 maxcount: .=.+2 argc: .=.+2 argv: .=.+2 environ: .=.+2 pb: .=.+2 pd: .=.+2 eb: .=.+2 globmax: .=.+2 tblmax: .=.+2 ml: .=.+2 lasttab:.=.+96. / 16 descriptors of integers + index at the end linused:.=.+2 counttab: opfra: .=.+512. opfrb: .=.+512. opfrc: .=.+640. lcount: .=.+2 countsiz:.=.+2 lflow: .=.+2 flowsiz:.=.+2 ltime: .=.+2 profsiz:.=.+2