diff --git a/README.md b/README.md index d123007..89ad703 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ as the files 0*.pdf. We now need to convert these to machine-readable assembly code, write tools such as an assembler, a filesystem creation tool, and write from scratch missing things like a shell, ls etc. +The code in the original scans are (c) Novell who own the rights to the Unix +source code. Everything that didn't come from the scanned pages are GPLv3. + scans holds the unmodified OCR versions of the scanned files src/cmd holds the modified source code of the user-mode programs diff --git a/scans/Readme b/scans/Readme index 2447909..98da674 100644 --- a/scans/Readme +++ b/scans/Readme @@ -2,6 +2,9 @@ This area contains the OCR'd versions of the PDP-7 scans that are at http://www.tuhs.org/Archive/PDP-11/Distributions/research/McIlroy_v0/0*.pdf The files should be unaltered versions of the scanned pages. +Novell owns the rights to the Unix source code, so these files are probably +(c) 1970 Novell. They are certainly not under the GPLv3 license. + For modified versions of these files, look in src/cmds and src/sys. Details of the files: @@ -24,8 +27,18 @@ trysys.s: page 65 of 01-s1.pdf bc.s: pages 7-11 of 06-5-12.pdf bi.s: pages 12-19 of 06-5-12.pdf bl.s: pages 3-6 of 06-5-12.pdf +cat.s: pages 21-23 of 06-5-12.pdf + +db.s: pages 2-21 of 07-13-19.pdf +dmabs.s: pages 23-27 of 07-13-19.pdf +ds.s: pages 30-38 of 07-13-19.pdf +dsksav.s: page 40 of 07-13-19.pdf +dskres.s: page 41 of 07-13-19.pdf +dskio.s: pages 42-43 of 07-13-19.pdf +dsw.s: page 45 of 07-13-19.pdf +init.s pages 47-51 of 07-13-19.pdf + cas.s: pages 1-17 of 04-cas.pdf -cat.c: pages 21-23 of 06-5-12.pdf ind.b: page 2 of 08-rest.pdf lease.b: page 4 of 08-rest.pdf diff --git a/scans/db.s b/scans/db.s new file mode 100644 index 0000000..4ee59c4 --- /dev/null +++ b/scans/db.s @@ -0,0 +1,1217 @@ +" db + + narg = ..+07777 + lac i narg + sad d4 + jmp start + lac narg + tad d5 + dac rcorep + dac wcorep + lac i narg + sad d8 + jmp start + sad d12 + skp + jmp error + lac narg + tad d9 + dac nlnamep + " +start: + lac nlbufp + cma + tad o17777 + cll + idiv + 6 + cll + lacq + mul + 6 + lacq + dac namesize + sys open; nlnamep: nlname; 0 + dac symindex + sma + jmp 1f +2: + dzm nlcnt + lac nlbufp + dac nlsize + jmp 3f +1: + sys read; nlbuff; namesize;0 + spa + jmp 2b + dac nlcnt + tad nlbufp + dac nlsize +3: + lac symindex + sys close + sys open +wcorep: corename; 1 + dac wcore + sys open; rcorep: corename; 0 + dac rcore + spa + jmp error + " + lac o52012 + jms wchar + law dotdot + dac nsearch + jms nlsearch + jmp mloop + lac value + dac relocval + cma + tad d1 + dac mrelocv + dzm sysflag +mloop: + -1 + dac nwords +ml1: + jms rch + dac nchar1 + sad o52 + skp + jmp 1f + dzm nchar1 + dac indflg +1: + jms getexp + lac errf + sna + jmp cmd +error: + dzm indflg + lac o40 + dac rator + dzm errf + lac d1 + sys write; errmes; 1 + jmp mloop +cmd: + lacq + sad o41 + jmp patch + lac opfound + sna + jmp 1f + lac comflg + dzm comflg + sza + jmp 1f + lac curval + dac curdot + lac curreloc + dac dotrel +1: + lacq + sad o42 + jmp ascii + sad o12 + jmp newln + sad o77 + jmp symbol + sad o47 + jmp saddress + sad o75 + jmp address + sad o57 + jmp octal + sad o72 + jmp decimal + sad o136 + skp + jmp 1f + dac sysflag + jmp mloop +1: + sad o45 + skp + jmp 1f + dzm sysflag + jmp mloop +1: + sad d1 + sys exit + sad o54 + skp + jmp error + " comma + jms getexp + lac errf + sza + jmp error + law + dac comflg + lac curreloc + sza + jmp 1f + lac value + cma + dac nwords + jmp cmd +1: + lac reldot + sna + jmp error + lac curval + cma + tad curdot + sma + jmp error + dac nwords + jmp cmd + " +saddress: + lac curdot + dac 9f + dzm curdot + lac reldot + sza + lac relocval + tad 9f + jms prsym + lac o12 + jms wchar + lac 9f + dac curdot + jmp mloop +9:0 + " +symbol: + law prsym + dac type + jmp print + " +octal: + law proct + dac type + jmp print + " +ascii: + law prasc + dac type + jmp print + " +decimal: + law prdec + dac type + jmp print + " +address: + lac curdot + jms octw + 5 + lac curreloc + sza + jmp 1f + lac o12 + jms wchar + jmp mloop +1: + lac o162012 + jms wchar + jmp mloop + " +print: + lac sysflag + sza + jmp 2f + lac reldot + sza + jmp 1f + lac curdot + dac addr + jmp sprint +2: + lac curdot + dac addr + jmp sprint +1: + law inbuf + dac addr + lac curdot + dac 1f + lac rcore + sys seek; 1:0; 0 + spa + jmp error + lac rcore + sys read; inbuf; 64 + spa + jmp error + sna + jmp error + " +sprint: + lac indflg + sna + jmp 2f + dzm indflg + lac i addr + and o17777 + dac curdot + dzm reldot + tad mrelocv + spa + jmp print + dac curdot + lac d1 + dac reldot + jmp print + " +2: + lac o40 + jms wchar + lac addr + dac 3f + lac i addr + jms i type + lac 3f + dac addr + isz addr + law prasc + sad type + jmp 2f + lac nl + jms wchar +1: + isz nwords + jmp 1f + law prasc + sad type + skp + jmp mloop + lac nl + jms wchar + jmp mloop +1: + isz curdot + nop + lac nwords + spa + jmp print + jmp 2b +3:0 + " +prdec: "temp +proct:0 + jms octw + 6 + jmp i proct + " +patch: + lac opfound + sna + jmp error + lac curreloc + sna + jmp 1f + lac curval + tad relocval + skp +1: + lac curval + dac inbuf + lac sysflag + sna + jmp 1f + lac inbuf + dac i curdot + jmp bump +1: + lac reldot + sna + jmp error + lac curdot + dac 2f + lac wcore + spa + jmp error + sys seek; 2:0; 0 + spa + jmp error + lac wcore + sys write; inbuf; 1 + spa + jmp error +bump: + -1 + dac nwords + isz curdot + jmp print + " +newln: + lac opfound + sna + jmp bump + jmp print + " +getexp:0 + dzm errf + lac o40 + dac rator + dzm curval + dzm curreloc + dzm reloc + dzm value + dzm opfound +xloop: + jms rch + lmq + sad o044 + skp + jmp 1f + jms getspec + jms oprand + jmp xloop +1: + tad om60 + spa + jmp 1f + tad om10 + sma + jmp 1f + lacq + jms getnum + jms oprand + jmp xloop +1: + lacq + sad o56 + jmp 1f + tad om141 + spa + jmp 2f + tad om32 + sma + jmp 2f +1: + lacq + jms getsym + jms oprand + jmp xloop +2: + lacq + tad om101 + spa + jmp 1f + tad om32 + spa + jmp 1b +1: + lacq + sad o74 + skp + jmp 1f + jms rch + alss 9 + dac value + dzm reloc + jms oprand + jmp xloop +1: + sad o40 + jmp xloop + sad o55 "- + skp + jmp 1f +2: + lac o40 + sad rator + skp + jmp error + lacq + dac rator + jmp xloop +1: + sad o53 "+ + jmp 2b + lac curreloc + sna + jmp 1f + sad d1 + skp + dac errf +1: + lac o40 + sad rator + jmp i getexp + dac errf + jmp i getexp + " +getspec: 0 + jms rch + sad o141 + jmp spcac + sad o161 "q + jmp spcmq + sad o151 "i + jmp spcic + lmq + tad om60 + spa + jmp 2f + tad om10 + sma + jmp 2f + lacq + jms getnum + jmp spcai +2: + law + dac errf + jmp getspec i +spcac: + cla + jmp 1f +spcmq: + lac d1 + jmp 1f +spcic: + lac d10 + jmp 1f +spcai: + lac value + tad dm6 + +1: + tad o10000 + dac value + lac d1 + dac reloc + jmp i getspec + " +getsym:0 + lmq + law symbuf + dac symbufp + dzm symbuf + -8 + dac symcnt + dzm nchar1 + lac nopcom + dac skipt + skp +storech: + imq + lac i symbufp + and o177000 + sna + jmp 1f + omq + dac i symbufp + isz symbufp + dzm i symbufp + jmp 2f +1: + llss 27 + dac i symbufp + " +2: + isz symcnt + skp + jmp endsym +skipt: + nop " or jmp fill + jms rch + sad o76 + skp + jmp 1f + lac symbuf + lrss 9 + and o177 + dac value + dzm reloc + jmp i getsym +1: + sad o56 + jmp storech + dac nchar1 + tad om60 + spa + jmp fill + tad m10 + spa + jmp 2f + lac nchar1 + tad om141 + spa + jmp 1f + tad om32 + spa + jmp 2f +1: + lac nchar1 + tad om101 + spa + jmp fill + tad om32 + sma + jmp fill +2: + lac nchar1 + dzm nchar1 + jmp storech + " +fill: + lac trafill + dac skipt + lac o40 + jmp storech + " +endsym: + lac symbuf + sad o56040 + jmp dotsym + law symbuf + dac nsearch + jms nlsearch + jmp undef + dzm nsearch + jmp i getsym + " +dotsym: + lac curdot + dac value + lac dotrel + dac reloc + jmp i getsym + " +undef: + dzm nsearch + law + dac errf + jmp i getsym + " +getnum:0 + dzm reloc + dzm value +num1: + tad om60 + imq + lac value + alss 3 + omq + dac value + jms rch + dac nchar1 + sad o162 + jmp nrel + tad om60 + spa + jmp i getnum + tad om10 + sma + jmp i getnum + lac nchar1 + dzm nchar1 + jmp num1 +nrel: + dzm nchar1 + lac d1 + dac reloc + jmp i getnum + " +oprand:0 + lac rator + sad o53 + jmp opplus + sad o40 + jmp opor + sad o55 + jmp opminus +opplus: + lac value + tad curval + dac curval +1: + lac curreloc + tad reloc + dac curreloc + jmp retop + " +opor: + lac value + lmq + lac curval + omq + dac curval + jmp 1b + " +opminus: + lac curval + cma + tad value + cma + dac curval + lac reloc + cma + tad d1 + tad curreloc + dac curreloc +retop: + lac o40 + dac rator + dac opfound + jmp i oprand + " +prasc:0 + jms wchar + jmp i prasc + " +prsym:0 + dac word + dzm relflg + dzm relocflg + dzm nsearch + and o760000 + sad o760000 + jmp plaw + sad o20000 + jmp pcal + and o740000 + sad o640000 + jmp peae + sad o740000 + jmp popr + sad o700000 + jmp piot + sna + jmp poct + jms nlsearch + jmp poct + jms wrname + lac o40 + jms wchar + lac word + and o20000 + sna + jmp 1f + lac o151040 + jms wchar + lac word + xor o20000 + dac word +1: +symadr: + lac d1 + dac relflg + dac relocflg + lac word + and o17777 + tad mrelocv + sma + jmp 1f + tad relocval + dzm relocflg +1: +pradr: + dac addr + jms nlsearch + jmp octals +pr1: + dzm relflg + jms wrname + lac value + sad addr + jmp i prsym + cma + tad d1 + tad addr + sma + jmp 1f + cma + tad d1 + dac addr + lac o55 + jms wchar + jmp 2f +1: + dac addr + lac o53 + jms wchar +2: + lac addr + jms octw + 1 + jmp i prsym + " +plaw: + lac d1 + dac relocflg + lac word + and o17777 + tad mrelocv + sma + jmp 1f + tad relocval + dzm relocflg +1: + dac addr + law + dac relflg + lac addr + lms nlsearch + jmp poct + dac symindex + law laws + jms wrname + lac o40 + jms wchar +3: + lac symindex + jmp pr1 +2:0 +9:0 + " +peae: + lac word + jms nlsearch + jmp 1f + jms wrname + jmp i prsym +1: + lac word + and o777700 + jms nlsearch + jmp 1f + jms wrname + lac o40 + jms wchar + lac word + and o77 + jms octw + 1 + jmp i prsym +1: + law eaes + dac addr + jmp nfnd + " +popr: + law oprs + jmp 1f +piot: + law iots +1: + dac addr + lac word + jms nlsearch + jmp 1f + jms wrname + jmp i prsym +1: +nfnd: + lac addr + jms wrname +octala: + dzm relflg + lac o40 + jms wchar + lac word + and o37777 + lmq + lac relocflg + sna + jmp 1f + lacq + tad mrelocv + imq +1: + lacq + jms octw + 1 + lac relocflg + sna + jmp i prsym + lac o162 + jms wchar + dzm relocflg + jmp i prsym + " +poct: + lac word + jms octw + 6 + jmp i prsym + " +pcal: + lac word + sna + jmp poct + and o17777 + jms nlsearch + jmp 1f + dac addr + law syss + jms wrname + lac o40 + jms wchar + lac addr + jms wrname + jmp i prsym + " +1: + lac word + and o20000 + sza + jmp poct + jmp symadr + " +wrname:0 + tad dm1 + dac 10 + -4 + dac 3f +1: + lac i 10 + dac 2f + imq + cla + llss 9 + sad o40 + jmp i wrname + jms wchar + lac 2f + and o177 + sad o40 + jmp i wrname + jms wchar + isz 3f + jmp 1b + jmp i wrname +2:0 +3:0 + " +nlsearch:0 + dac match + lac brack + dac best + dzm minp +1: + lac nlbufp + tad dm6 + dac cnlp +nloop: + lac cnlp + tad d6 + dac cnlp + lmq + cma + tad nlsize + spa + jmp nlend + lac nsearch + sza + jmp testn + lacq + tad d3 + dac np + lac i np + sna + jmp nloop + isz np + lac i np + dac treloc + sad relocflg + skp + jmp nloop + isz np + iac i np + dac tvalue + sad match + jmp nlok + lac relocflg + sna + jmp nloop + lac relflg + sna + jmp nloop + -1 + tad tvalue + cma + tad match + spa + jmp nloop + dac 2f + tad mbrack + sma + jmp nloop + lac best + cma + tad d1 + tad 2f + sma + jmp nloop + lac 2f + dac best + lac tvalue + dac value + lac treloc + dac reloc + lac cnlp + dac minp + jmp nloop + " +2:0 + " +testn: + lacq + dac minp + -4 + dac value + lac match + dac inbuf +1: + lac i minp + sad i inbuf + skp + jmp nloop + isz minp + isz inbuf + isz value + jmp 1b + lac i minp + dac treloc + isz minp + lac i minp + dac tvalue + jmp nlok + " +nlend: + lac relflg + sna + jmp i nlsearch + lac dotrel + sad relocflg + skp + jmp 1f + -1 + tad curdot + cma + tad match + spa + jmp 2f + cma + tad d1 +2: + tad brack + spa + jmp 1f + tad mbrack + tad best + spa + jmp 1f + lac curdot + dac value + lac dotrel + dac reloc + law o56040 + dac minp +1: + lac minp + sza + isz nlsearch + jmp i nlsearch +nlok: + lac tvalue + dac value + lac treloc + dac reloc + lac cnip + isz nlsearch + jmp i nlsearch + " +nlerr: + law + dac errf + jmp i nlsearch + " +rch:0 + lac nchar1 + dzm nchar1 + sza + jmp i rch +1: + lac nchar + dzm nchar + sza + jmp i rch + cla + sys read; char; 1 + lac char + and o177 + dac nchar + lac char + lrss 9 + sna + jmp 1b + jmp i rch + " +wchar:0 + dac char + lac d1 + sys write; char; 1 + jmp i wchar + " +octw: 0 + isz octw + imq + cla cll + llss 3 + alss 6 + llss3 + tad o60060 + dac obuf + cla + llss 3 + alss 6 + llss 3 + tad o60060 + dac obuf+1 + cla + llss 3 + alss 6 + llss 3 + tad o60060 + dac obuf+2 + lac d1 + sys write; obuf; 3 + jmp i octw +m10: -10 + " + " +o54:054 +d6:6 +o52012:052012 +d5:5 +d9:9 +d12:12 +d8:8 +d3:3 +o177:0177 +o136: 0136 +o45: 045 +sysflag: 0 +char:0 +d2:2 +o162012:0162012 +mrelocv:-010000 +relocval:010000 +nwords:0 +errf:0 +rator:0 +d1:1 +errmes:077012 +o12:012 +curval:0 +curreloc:0 +curdot:0 +reldot: +dotrel:0 +value:0 +reloc:0 +o77:077 +o57:057 +o72:072 +o50:050 +type:proct +o162:0162 +nl:012 +om100:-0100 +d2:2 +symbuf: .=.+5 +inbuf:.=.+64 +o100:0100 +opfound:0 +wcore:0 +symindex:0 +rcore:0 +o56:056 +om60:-060 +om10:-010 +o56:056 +om141:-0141 +o141: 0141 +oO44: 044 +o151: 0151 +o161: 0161 +om101: -0101 +om32:-032 +o40:040 +o55:055 +o53:053 +symbufp:0 +symcnt:0 +nopcom:nop +dm6: -6 +d10: 10 +trafill: jmp fill +nchar1:0 +nchar:0 +o177000:0177000 +o56040:056040 +nsearch:0 +word:0 +relflg:0 +relocflg:0 +o740000:0740000 +o640000:0640000 +o700000:0700000 +o17777:017777 +o20000:020000 +o10000: 010000 +o151040:0151040 +eaes:0145141;0145040 +laws: 0154141;0167040 +oprs:0157160;0162040 +iots:0151157;0164040 +syss:0163171;0163040 +corename:0143157;0162145;040040;040040 +nlname:0156056;0157165;0164040;040040 +dotdot: <..>; 040040; 040040; 040040 +addr:0 +o37777:037777 +dm1:-1 +match:0 +rwdflg:0 +nlbufp:nlbuff +nlsize:0 +dm6:-6 +cnlp:0 +o377777:0377777 +minp:0 +d4:4 +np:0 +nlcnt:0 +obuf:.=.+3 +o60060:060060 +o75:075 +best: 0 +o60000:060000 +comflg:0 +nlbufp:nlbuff +brack: 30 +mbrack: -30 +o777700:0777700 +o41:041 +o42:042 +o760000:0760000 +o40000:040000 +tvalue: 0 +treloc: 0 +o151:0151 +o47: 047 +o52:052 +indflg: 0 +o74:074 +o76:076 +nlbufp: nlbuff + nlbuff = . \ No newline at end of file diff --git a/scans/dmabs.s b/scans/dmabs.s new file mode 100644 index 0000000..fce7825 --- /dev/null +++ b/scans/dmabs.s @@ -0,0 +1,256 @@ + " dmabs + + lac o17 + sys creat; punout + spa + sys save + dac fo + lac 017777 + tad d1 + dac name + jms space + 100 + +loop: + dzm oldsum + lac initcmd + dac comand + lac i 017777 + sad d4 + jmp stop + tad dm4 + dac i 017777 + lac name + tad d4 + dac name + +dump1: + lac comand + xor dactra + dac tracmd + +dump2: + sys open; name: 0; 0 + spa + jmp opnerr + dac fi + -bootsiz + dac c1 + law boot-1 + dac 8 +1: + lac i 8 + jms put + isz c1 + jmp 1b + lac bootcmd + lrs 12 + jms put1 + lac bootcmd + lrs 6 + jms put1 + lac bootcmd + and o77 + xor o300 + jms put2 + + jms space + 3 + +dump3: + -1 + tad bufp + dac 8 + -64 + dac c1 +1: + dzm i 8 + isz c1 + jmp 1b + lac fi + sys read; bufp: buf; 64 + sna + jmp done + dac count + -1 + tad bufp + dac 8 + -64 + dac c1 + cla +1: + add i 8 + isz c1 + jmp 1b + sna + jmp dump4 + dac newsum + lac comand + jms put + lac count + jms put + lac oldsum + add comand + add count + jms put + lac newsum + dac oldsum + jms space + 3 + -1 + tad bufp + dac 8 + -1 + tad count + cma + dac c1 +1: + lac i 8 + jms put + isz c1 + jmp 1b + jms space + 10 + +dump4: + lac comand + tad count + dac comand + jmp dump3 + +done: + lac tracmd + jms put + cla + jms put + lac oldsum + add tracmd + jms put + jms space + 20 + lac fi + sys close + jmp loop + +stop: + cla + jms put + jms space + 100 + sys exit + +space: 0 + -1 + tad i space + cma + dac c1 + isz space +1: + lac o400 + jms put2 + isz c1 + jmp 1b + jmp i space + +put: 0 + dac 1f + lrs 12 + jms put1 + lac 1f + lrs 6 + jms put1 + lac 1f + jms put1 + jmp i put +1:0 + +put1:0 + and o77 + xor o200 + jms put2 + jmp i put1 + +put2: 0 + dac 1f + lac fo + sys write; 1f; 1 + jmp i put2 +1: 0 + +boot: + org = 017740 +2: + jms get1-boot+org + dac cmd-boot+org + jms get1-boot+org + cma + dac cnt-boot+org + jms get2-boot+org + xor sum-boot+org + dzm sum-boot+org + cla cll sza + hlt + isz cnt-boot+org +1: + jms get1-boot+org +cmd: 0 + isz cmd-boot+org + isz cnt-boot+org + jmp 1b-boot+org + jmp 2b-boot+org +get1: 0 + jms get2-boot+org + dac get2-boot+org + add sum-boot+org + dac sum-boot+org + lac get2-boot+org + jmp i get1-boot+org +get2: 0 + iot 0144 +1: + iot 0101 + jmp 1b-boot+org + iot 0112 + jmp i get2-boot+org +sum: 0 + cnt = sum+1 + bootsiz = .-boot +bootcmd: jmp org + +opnerr: + lac name + dac 1f + lac d1 + sys write; 1: 0; 4 + lac d1 + sys write; mes; 2 + jmp loop +mes: + 040;077012 + +comand: 0 +tracmd: 0 + d1: 1 +.17777: 017777 +o77: 077 +o200: 0200 +o300: 0300 +d4: 4 +d64: 64 +dm4: -4 +o400: 0400 +punout: ;;;040040 +o17: 017 + +fi: 0 +fo: 0 +count: 0 +oldsum: 0 +newsum: 0 +daccmd: dac +dactra: dac jmp +initcmd: dac 0 +c1: 0 +buf: + +iot = 0700000 \ No newline at end of file diff --git a/scans/ds.s b/scans/ds.s new file mode 100644 index 0000000..2aa0f93 --- /dev/null +++ b/scans/ds.s @@ -0,0 +1,501 @@ +" ds + + lac 017777 i + sad d8 + skp + sys exit + lac 017777 + tad d5 + dac .+3 + law 017 + sys creat; .. + dac fo + law 017 + sys creat; scrname + spa; jms error + dac fso + sys open; scrname; 0 + spa; jms error + dac fsi + sys chdir; dd + spa; jms error + lac d1 + sys write; pass1; 1 + law fsobuf + dac fsopt + dzm nfiles + law fbuf + dac filp + dzm ndirs + law dbuf + dac dirp + dzm fsloc + sys open; dotdot; 0 + spa; jms error + dac fd + jms readdir; dotdot + law statbuf + sys status; dotdot; dotdot + spa; jms error + lac statbuf+12 " i index + dac dirp i + isz dirp + -1 + tad nfiles + cma + dac ddfiles + law fbuf + dac ddfilp + +loop: + -1 + tad ndirs + cma + dac c1 + law dbuf + dac i1 + +1: + isz i1 + lac i1 i + sad ddfilp i + jmp 2f + isz i1 + isz c1 + jmp 1b + + lac ddfilp + tad i1 + dac i1 + lac i1 i + dac .+3 + lac fsi + sys seek; ..; 0 + lac fsi + sys read; scrname; 4 + law statbuf + sys status; dotdot; scrname + spa; jms error + lac statbuf+0 " flags + and o20 + sna + jmp 2f + sys open; scrname; 0 + spa; jms error + dac fd + jms readdir; scrname + lac ddfilp i + dac dirp i + isz dirp + +2: + isz ddfilp + isz ddfilp + isz ddfiles + jmp loop + +" output phase + + lac fso + sys write; fsobuf; 64 + lac d1 + sys write; pass2; 2 + -500 + dac c1 + +1: + law dbuf+2 + dac i1 + dzm fflg + law fbuf + dac i2 + r1 + tad nfiles + cma + dac c2 + +2: + lac c1 + tad d501 + sad i2 i + skp + jmp 3f + -1 + tad i1 + dac i3 + iac i3 i + dac c3 + law fbuf + dac i3 +0: + lac i3 i + sad c3 + jmp 0f + isz i3 + isz i3 + jmp 0b +0: + lac i3 + tad d1 + dac c3 + lac c3 i + dac .+3 + lac fsi + sys seek; ..; 0 + lac fsi + sys read; scrname; 4 + lac i2 + tad d1 + dac c3 + lac c3 i + dac .+3 + lac fsi + sys seek; ..; 0 + lac fsi + sys read; dd; 4 + lac fflg + sza + jmp 0f + + lac nlinkt + sad nlinka + skp + jms fishy + dzm nlinka + law 012 + jms putc + law statbuf + sys status; scrname; dd + spa; jms error + -1 + tad statbuf+9 + cma + dac nlinkt + -1 + dac fflg + jms longout + law 012 + jms putc +0: + isz nlinka + jms putname; scrname + jms putname; dd + law 012 + jms putc + +3: + isz i2 + isz i2 + lac i2 + sad i1 i + skp + jmp .+3 + isz i1 + isz i1 + isz c2 + jmp 2b + + isz c1 + jmp 1b + lac nlinkt + sad nlinka + skp + jms fishy + + sys chdir; system + jmp done + +fishy: 0 + jms asters + jms asters + law 012 + jms putc + lac d1 + sys write; 1f; 1 + jmp fishy i +1: 052012 + +nlinka: 0 +nlinkt: 0 + +asters: 0 + -10 + dac c +1: + law 052 + jms putc + isz c + jmp 1b + jmp asters i + +longout: 0 + lac statbuf+12 " i + jms octal; -3 + lac statbuf+0 " flags + jms octal; -2 + lac statbuf+8 " uid + jms octal; -2 + -1 + tad statbuf+9 " nlinks + cma + jms octal; -2 + lac statbuf+10 + jms octal; -5 + jmp longout i + +readdir: 0 + law 012 + jms putc + law 012 + jms putc + jms asters + lac readdir i + dac 5f + dac .+2 + jms putname; .. + jms asters + law 012 + jms putc + law 012 + jms putc + isz readdir + isz ndirs + lac filp + dac dirp i + isz dirp +0: + jms copyz; buf; 64 + lac fd + sys read; buf; 64 + spa; jms error + sna + jmp 4f + -8 + dac c1 + law buf + dac i1 +1: + lac i1 i + sna + jmp 3f + + isz nfiles + dac filp i + isz filp + lac fsloc + dac filp i + tad d4 + dac fsloc + isz filp + lac i1 + tad d1 + dac .+4 + law statbuf + sys status; 5:..; .. + spa; jms error + jms longout + lac i1 + tad d1 + dac .+2 + jms putname; .. + law 012 + jms putc + lac i1 + dac 8 + lac 8 i + dac fsopt i + isz fsopt + lac 8 i + dac fsopt i + isz fsopt + lac 8 i + dac fsopt i + isz fsopt + lac 8 i + dac fsopt i + isz fsopt + law fsobuf+64 + sad fsopt + skp + jmp 3f + lac fso + sys write; fsobuf; 64 + law fsobuf + dac fsopt + +3: + law 8 + tad i1 + dac i1 + isz c1 + jmp 1b + jmp 0b +4: + lac fd + sys close + jmp readdir i + +putname: 0 + -1 + tad putname i + dac 8 + -4 + dac c +1: + lac 8 i + lrss 9 + jms putc + llss 9 + jms putc + isz c + jmp 1b + isz putname + jmp putname i + +octal: 0 + lmq + lac d5 + tad octal i + cma + dac c +1: + llss 3 + isz c + jmp 1b + lac octal i + dac c +1: + ecla llss 3 + tad o60 + jms putc + isz c + jmp 1b + law 040 + jms putc + isz octal + jmp octal i + +error: 0 + -1 + tad error + hlt + sys save + +copyz: 0 + -1 + tad copyz i + dac 8 + isz copyz + -1 + tad copyz i + cma + dac 2f + isz copyz +1: + dzm 8 i + isz 2f + jmp 1b + jmp copyz i +2: 0 + +done: + lac noc + sna + sys exit + and d1 + sna cla + jmp 1f + jms putc + jmp done +1: + lac noc + rcr + dac 1f + lac fo + sys write; obuf; 1;.. + sys exit + +putc: 0 + and o177 + dac 2f+1 + lac opt + dac 2f + add o400000 + dac opt + spa + jmp 1f + lac 2f i + xor 2f+1 + jmp 3f +1: + lac 2f+1 + alss 9 +3: + dac 2f i + isz noc + lac noc + sad d128 + skp + jmp putc i + lac fo + sys write; obuf; 64 + lac iopt + dac opt + dzm noc + jmp putc i +2: 0;0 +opt: obuf +iopt: obuf +noc: 0 +fo: 1 + +d1: 1 +o177: 0177 +o400000: 0400000 +d128: 128 +d4: 4 +d5: 5 +d8: 8 +o60: 060 +o20: 020 +d501: 501 + +dd: +
; 040040; 040040; 040040 +dotdot: + 056056; 040040; 040040; 040040 +system: + ;;; 040040 +scrname: + <*s>;;040040;040040 +pass2: + ;;;;;;<: 040 +m3s = .-m3 +dd: +
;040040;040040;040040 +dir: + 040040;040040;040040;040040 + +ttyin: + ;;;;; 040040 +keybd: + ;;; +displ: + ;;;; 040040;040040;040040 +system: + ;;; 040040 +password: + ;;; + +d1: 1 +o43: 043 +o100: 0100 +o400000; 0400000 +d2: 2 +o12: 012 +om60: -060 +d3: 3 +ebufp: buf+64 +bufp: buf +o777: 0777 +o777000: 0777000 +o40: 040 +o72: 072 + +ibuf: .=.+100 +obuf: .=.+100 +tal: .=.+1 +buf: .=.+64 +char: .=.+1 +nchar: .=.+1 +pid1: .=.+1 +pid2: .=.+1 diff --git a/src/cmd/cat.s b/src/cmd/cat.s index 39b6a87..9a5e65e 100644 --- a/src/cmd/cat.s +++ b/src/cmd/cat.s @@ -58,7 +58,7 @@ nofiles: done: lac noc - sns + sna sys exit and d1 sna cla diff --git a/tools/a7out b/tools/a7out index 2733355..591b242 100755 --- a/tools/a7out +++ b/tools/a7out @@ -51,12 +51,12 @@ sub load_code { $Mem[$i] = 0; } - # Set up two file open filehandles + # Set up some open filehandles $FD[0] = \*STDIN; $FD[1] = \*STDOUT; $FD[8] = \*STDERR; # According to cat.s (uses d8 == 8) - # Open up the file + # Open up the PDP-7 executable file open( my $IN, "<", $filename ) || die("Unable to open $filename: $!\n"); while (<$IN>) { chomp; @@ -122,7 +122,7 @@ sub set_arguments { for (my $i=0; $i < length($str); $i += 2) { my $c1= substr($str, $i, 1) || ""; my $c2= substr($str, $i+1, 1) || ""; - #printf("Saving %06o to %05o\n", (ord($c1) << 9 ) | ord($c2), $addr); + #printf("Saving %06o to %06o\n", (ord($c1) << 9 ) | ord($c2), $addr); $Mem[$addr++]= (ord($c1) << 9 ) | ord($c2); } } @@ -135,8 +135,12 @@ sub simulate { my %Oplist = ( oct("004") => \&dac, oct("010") => \&jms, + oct("010") => \&dzm, oct("020") => \&lac, + oct("024") => \&xor, oct("034") => \&tad, + oct("044") => \&isz, + oct("050") => \&and, oct("054") => \&sad, oct("060") => \&jmp, oct("070") => \&iot, @@ -178,7 +182,7 @@ sub dump_memory { # Load AC sub lac { my ( $instruction, $addr, $indaddr ) = @_; - dprintf( "PC %06o: lac %05o (value %06o) into AC\n", + dprintf( "PC %06o: lac %06o (value %06o) into AC\n", $PC, $indaddr, $Mem[$indaddr] ); $AC = $Mem[$indaddr]; $PC++; @@ -187,7 +191,7 @@ sub lac { # Deposit AC sub dac { my ( $instruction, $addr, $indaddr ) = @_; - dprintf( "PC %06o: dac AC (value %06o) into %05o\n", + dprintf( "PC %06o: dac AC (value %06o) into %06o\n", $PC, $AC, $indaddr ); $Mem[$indaddr] = $AC; $PC++; @@ -196,12 +200,30 @@ sub dac { # Add to AC sub tad { my ( $instruction, $addr, $indaddr ) = @_; - dprintf( "PC %06o: tad AC (value %06o) from addr %05o\n", - $PC, $AC, $indaddr ); + dprintf( "PC %06o: tad AC (value %06o) with addr %06o (%06o)\n", + $PC, $AC, $indaddr, $Mem[$indaddr] ); $AC= ($AC + $Mem[$indaddr]) & MAXINT; $PC++; } +# And AC and Y +sub and { + my ( $instruction, $addr, $indaddr ) = @_; + dprintf( "PC %06o: and AC (value %06o) with addr %06o (%06o)\n", + $PC, $AC, $indaddr, $Mem[$indaddr] ); + $AC &= $Mem[$indaddr]; + $PC++; +} + +# Xor AC and Y +sub xor { + my ( $instruction, $addr, $indaddr ) = @_; + dprintf( "PC %06o: xor AC (value %06o) with addr %06o (%06o)\n", + $PC, $AC, $indaddr, $Mem[$indaddr] ); + $AC ^= $Mem[$indaddr]; + $PC++; +} + # Skip if AC different to Y sub sad { my ( $instruction, $addr, $indaddr ) = @_; @@ -209,6 +231,21 @@ sub sad { $PC += ($AC != $Mem[$indaddr]) ? 2 : 1; } +# Deposit zero in memory +sub dzm { + my ( $instruction, $addr, $indaddr ) = @_; + dprintf( "PC %06o: dzm into %06o\n", $PC, $indaddr); + $Mem[$indaddr]= 0; +} + +# Index and skip if zero +sub isz { + my ( $instruction, $addr, $indaddr ) = @_; + dprintf( "PC %06o: isz %06o\n", $PC, $Mem[$indaddr]); + $Mem[$indaddr]++; $Mem[$indaddr] &= MAXINT; + $PC += ($Mem[$indaddr] == 0) ? 2 : 1; +} + # Jump sub jmp { my ( $instruction, $addr, $indaddr ) = @_; @@ -253,6 +290,21 @@ sub special { $PC += ( $AC == 0 ) ? 2 : 1; return; } + if ( $instruction == 0741400 ) { # szl: Skip when $LINK is zero + dprintf( "PC %06o: szl LINK %0o\n", $PC, $LINK ); + $PC += ( $LINK == 0 ) ? 2 : 1; + return; + } + if ( $instruction == 0740400 ) { # snl: Skip when $LINK not zero + dprintf( "PC %06o: snl LINK %0o\n", $PC, $LINK ); + $PC += ( $LINK != 0 ) ? 2 : 1; + return; + } + if ( $instruction == 0741000 ) { # ska: skip always + dprintf( "PC %06o: skp\n", $PC ); + $PC += 2; + return; + } if ( ($instruction >= 0760000) && ($instruction <= MAXINT) ) { # law: load word into AC dprintf( "PC %06o: law %06o into AC\n", $PC, $instruction); $AC = $instruction;