Research V5 development
authorKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
committerKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
Work on file usr/source/s1/db4.s
Work on file usr/source/s4/seek.s
Work on file usr/source/s4/stat.s
Work on file usr/source/s1/comm.c
Work on file usr/source/s3/rand.s
Work on file usr/mdec/mcopy.s
Work on file usr/source/s2/ps.c
Work on file usr/source/s1/clri.s
Work on file usr/source/s4/locv.s

Co-Authored-By: Dennis Ritchie <dmr@research.uucp>
Synthesized-from: v5

usr/mdec/mcopy.s [new file with mode: 0644]
usr/source/s1/clri.s [new file with mode: 0644]
usr/source/s1/comm.c [new file with mode: 0644]
usr/source/s1/db4.s [new file with mode: 0644]
usr/source/s2/ps.c [new file with mode: 0644]
usr/source/s3/rand.s [new file with mode: 0644]
usr/source/s4/locv.s [new file with mode: 0644]
usr/source/s4/seek.s [new file with mode: 0644]
usr/source/s4/stat.s [new file with mode: 0644]

diff --git a/usr/mdec/mcopy.s b/usr/mdec/mcopy.s
new file mode 100644 (file)
index 0000000..f302025
--- /dev/null
@@ -0,0 +1,155 @@
+/ copy mag tape to disk
+
+       jsr     pc,rew
+2:
+       jsr     pc,4(r5)
+               <'p' for rp; 'k' for rk\n\0>
+               .even
+       jsr     pc,2(r5)
+       cmp     r0,$'k
+       bne     3f
+       mov     $rkblk,r0
+       br      1f
+3:
+       cmp     r0,$'p
+       bne     2b
+       mov     $rpblk,r0
+1:
+       mov     r0,rxblk
+       mov     $'\n,r0
+       jsr     pc,(r5)
+       jsr     pc,4(r5)
+               <disk offset\n\0>
+               .even
+       jsr     pc,numb
+       mov     r0,bno
+       jsr     pc,4(r5)
+               <tape offset\n\0>
+               .even
+       jsr     pc,numb
+       mov     r0,r1
+       beq     2f
+1:
+       jsr     pc,rblk
+       dec     r1
+       bne     1b
+2:
+
+       jsr     pc,4(r5)
+               <count\n\0>
+               .even
+       jsr     pc,numb
+       mov     r0,r1
+1:
+       jsr     pc,rblk
+       jsr     pc,wblk
+       dec     r1
+       bne     1b
+       jsr     pc,rew
+       rts     pc
+
+numb:
+       clr     r1
+1:
+       jsr     pc,2(r5)
+       cmp     r0,$'\n
+       beq     1f
+       sub     $'0,r0
+       cmp     r0,$9
+       bhi     2f
+       mul     $10.,r1
+       add     r0,r1
+       br      1b
+1:
+       mov     r1,r0
+       rts     pc
+2:
+       jsr     pc,4(r5)
+               <illegal digit\n\0>
+               .even
+       tst     (sp)+
+       rts     pc
+
+mts = 172520
+mtc = 172522
+mtbrc = 172524
+mtcma = 172526
+
+rblk:
+       bit     $2,*$mts
+       bne     rblk
+       tstb    *$mtc
+       bge     rblk
+       mov     $-512.,*$mtbrc
+       mov     $buf,*$mtcma
+       mov     $60003,*$mtc
+1:
+       tstb    *$mtc
+       bge     1b
+       tst     *$mtc
+       bge     1f
+       jsr     pc,4(r5)
+               <tape error\n\0>
+               .even
+       mov     $-1,*$mtbrc
+       mov     $60013,*$mtc
+       br      rblk
+1:
+       rts     pc
+
+rew:
+       mov     $60017,*$mtc
+       rts     pc
+
+wblk:
+       mov     bno,r0
+       inc     bno
+       mov     r1,-(sp)
+       mov     r0,r1
+       clr     r0
+       jmp     *rxblk
+
+rpda = 176724
+rpblk:
+       div     $10.,r0
+       mov     r1,-(sp)
+       mov     r0,r1
+       clr     r0
+       div     $20.,r0
+       bisb    r1,1(sp)
+       mov     $rpda,r1
+       mov     (sp)+,(r1)
+       mov     r0,-(r1)
+       br      1f
+
+rkda = 177412
+rkblk:
+       div     $12.,r0
+       ash     $4.,r0
+       bis     r1,r0
+       mov     $rkda,r1
+       mov     r0,(r1)
+
+1:
+       mov     $buf,-(r1)
+       mov     $-256.,-(r1)
+       mov     $3,-(r1)
+1:
+       tstb    (r1)
+       bge     1b
+       tst     (r1)
+       blt     1f
+       mov     (sp)+,r1
+       rts     pc
+1:
+       jsr     pc,4(r5)
+               <disk error\n\0>
+               .even
+       mov     (sp)+,r1
+       dec     bno
+       br      wblk
+
+.bss
+buf:   .=.+512.
+rxblk: .=.+2
+bno:   .=.+2
diff --git a/usr/source/s1/clri.s b/usr/source/s1/clri.s
new file mode 100644 (file)
index 0000000..04686a5
--- /dev/null
@@ -0,0 +1,63 @@
+/ clri -- clear inode
+
+       cmp     (sp)+,$2
+       blt     error
+       beq     1f
+       mov     4(sp),fs1
+       mov     4(sp),fs2
+1:
+       tst     (sp)+
+       mov     (sp)+,r0
+       clr     r5
+1:
+       movb    (r0)+,r1
+       beq     1f
+       mpy     $10.,r5
+       sub     $'0,r1
+       cmp     r1,$10.
+       bhis    error
+       add     r1,r5
+       br      1b
+1:
+       add     $31.,r5
+       mov     r5,r0
+       als     $-4,r0
+       mov     r0,0f
+       sys     open; fs1: filsys; 0
+       bes     error
+       mov     r0,-(sp)
+       sys     seek; 0:..; 3
+       mov     (sp),r0
+       sys     read; buf; 512.
+       mov     (sp)+,r0
+       sys     close
+       mov     r5,r0
+       als     $5,r0
+       bic     $!777,r0
+       add     $buf,r0
+       mov     $16.,r5
+1:
+       clr     (r0)+
+       sob     r5,1b
+       sys     open; fs2: filsys; 1
+       bes     error
+       mov     r0,-(sp)
+       mov     0b,0f
+       sys     seek; 0:..; 3
+       mov     (sp)+,r0
+       sys     write; buf; 512.
+       bes     error
+       sys     exit
+
+error:
+       mov     $1,r0
+       sys     write; 1f; 2f-1f
+       sys     exit
+1:
+       <error\n>
+2:
+
+filsys:        </dev/junk\0>
+.even
+       .bss
+buf:   .=.+512.
diff --git a/usr/source/s1/comm.c b/usr/source/s1/comm.c
new file mode 100644 (file)
index 0000000..4b356e0
--- /dev/null
@@ -0,0 +1,168 @@
+#define LB 250
+int    one;
+int    two;
+int    three;
+
+char   *ldr[3];
+
+char   ib1[518];
+char   ib2[518];
+main(argc,argv)
+       char    *argv[];
+{
+       extern  fout;
+       int     l;
+       char    lb1[LB],lb2[80];
+
+       ldr[0] = "";
+       ldr[1] = "\t";
+       ldr[2] = "\t\t";
+       if(argc > 1)  {
+               if(*argv[1] == '-' && argv[1][1] != 0) {
+                       l = 1;
+                       while(*++argv[1]) {
+                               switch(*argv[1]) {
+                               case'1':
+                                       if(!one) {
+                                               one = 1;
+                                               ldr[1][0] =
+                                               ldr[2][l--] = '\0';
+                                       }
+                                       break;
+                               case '2':
+                                       if(!two) {
+                                               two = 1;
+                                               ldr[2][l--] = '\0';
+                                       }
+                                       break;
+                               case '3':
+                                       three = 1;
+                                       break;
+                               default:
+                               printf("Illegal flag: %c\n",*argv[1]);
+                               exit();
+                               }
+                       }
+                       argv++;
+                       argc--;
+               }
+       }
+
+       if(argc < 3) {
+               printf("Argc = %d\n",argc);
+               exit();
+       }
+
+       openfil(argv[1],ib1);
+       openfil(argv[2],ib2);
+       fout = dup(1);
+
+
+       if(rd(ib1,lb1) < 0) {
+               if(rd(ib2,lb2) < 0)     exit();
+               copy(ib2,lb2,2);
+       }
+       if(rd(ib2,lb2) < 0)     copy(ib1,lb1,1);
+
+       while(1) {
+
+               switch(compare(lb1,lb2)) {
+
+                       case 0:
+                               wr(lb1,3);
+                               if(rd(ib1,lb1) < 0) {
+                                       if(rd(ib2,lb2) < 0)     fexit();
+                                       copy(ib2,lb2,2);
+                               }
+                               if(rd(ib2,lb2) < 0)     copy(ib1,lb1,1);
+                               continue;
+
+                       case 1:
+                               wr(lb1,1);
+                               if(rd(ib1,lb1) < 0)     copy(ib2,lb2,2);
+                               continue;
+
+                       case 2:
+                               wr(lb2,2);
+                               if(rd(ib2,lb2) < 0)     copy(ib1,lb1,1);
+                               continue;
+               }
+       }
+}
+
+rd(file,buf)
+       char    *buf;
+{
+
+       register int i;
+       i = 0;
+       while((*buf = getc(file)) >=0) {
+               if(*buf == '\n' || i > LB-2) {
+                       *buf = '\0';
+                       return(0);
+               }
+               i++;
+               buf++;
+       }
+       return(-1);
+}
+
+wr(str,n)
+       char    *str;
+{
+
+       switch(n) {
+
+               case 1:
+                       if(one) return;
+                       break;
+
+               case 2:
+                       if(two) return;
+                       break;
+
+               case 3:
+                       if(three)       return;
+       }
+       printf("%s%s\n",ldr[n-1],str);
+}
+
+copy(ibuf,lbuf,n)
+{
+       do {
+               wr(lbuf,n);
+       } while(rd(ibuf,lbuf) >= 0);
+
+       flush();
+       exit();
+}
+
+compare(a,b)
+       char    *a,*b;
+{
+       register char *ra,*rb;
+
+       ra = --a;
+       rb = --b;
+       while(*++ra == *++rb)
+               if(*ra == '\0') return(0);
+       if(*ra < *rb)   return(1);
+       return(2);
+}
+fexit()
+{
+       flush();
+       exit();
+}
+
+openfil(s,b)
+char *s;
+int *b;
+{
+       if(s[0]=='-' && s[1]==0)
+               b[0] = 0;
+       else if(fopen(s, b) == -1) {
+               printf("Can't open %s\n", s);
+               exit(1);
+       }
+}
diff --git a/usr/source/s1/db4.s b/usr/source/s1/db4.s
new file mode 100644 (file)
index 0000000..cfc467d
--- /dev/null
@@ -0,0 +1,54 @@
+/ db4 -- debugger
+
+maxsym = 24000.
+core:
+   <core\0>
+a.out:
+   <a.out\0>
+.even
+zero:  0
+.bss
+regbuf:
+       .=.+1024.
+sigp   = regbuf+250
+txtsiz = regbuf+262
+datsiz = regbuf+264
+stksiz = regbuf+266
+rtxtsiz: .=.+2
+.data
+objmagic: 407
+nobjmagic: 410
+namsiz:        nambuf
+incdot: 2
+nlcom: '/
+
+       .bss
+
+starmod:.=.+2
+symbol:        .=.+10.
+getoff:        .=.+2
+namstrt: .=.+2
+bytemod: .=.+2
+savsp: .=.+2
+error: .=.+2
+ttyfin: .=.+2
+dbfin: .=.+2
+symfin:        .=.+2
+curfin:        .=.+2
+dbfout: .=.+2
+ch: .=.+2
+lastop: .=.+2
+addres: .=.+2
+taddr: .=.+2
+adrflg: .=.+2
+fpsr:  .=.+2
+och:   .=.+2
+dot: .=.+2
+count: .=.+2
+syscnt: .=.+2
+temp: .=.+2
+temp1: .=.+2
+obuf: .=.+8.
+inbuf: .=.+128.
+nambuf:        .=.+20
+
diff --git a/usr/source/s2/ps.c b/usr/source/s2/ps.c
new file mode 100644 (file)
index 0000000..8d044c0
--- /dev/null
@@ -0,0 +1,193 @@
+#
+
+#include "/usr/sys/param.h"
+#include "/usr/sys/proc.h"
+#include "/usr/sys/tty.h"
+#include "/usr/sys/user.h"
+#define NDC11 10
+#define NKL11 4
+#define NDH11 16
+
+struct {
+       char name[8];
+       int  type;
+       char  *value;
+} nl[5];
+
+struct proc proc[1];
+struct user u;
+int    lflg;
+int    kflg;
+int    xflg;
+int    tflg;
+int    aflg;
+int    mem;
+int    swap;
+
+int    stbuf[257];
+char   *coref;
+
+main(argc, argv)
+char **argv;
+{
+       struct proc *p;
+       int n, b;
+       int i, c, mtty;
+       char *ap;
+       int hmem;
+       int uid, puid;
+
+       if (argc>1) {
+               ap = argv[1];
+               while (*ap) switch (*ap++) {
+               case 'a':
+                       aflg++;
+                       break;
+
+               case 't':
+                       tflg++;
+                       break;
+
+               case 'x':
+                       xflg++;
+                       break;
+
+               case 'l':
+                       lflg++;
+                       break;
+
+               case 'k':
+                       kflg++;
+                       break;
+
+               }
+       }
+       setup(&nl[0], "_proc");
+       setup(&nl[1], "_dc11");
+       setup(&nl[2], "_kl11");
+       setup(&nl[3], "_dh11");
+       nlist("/unix", nl);
+       if (nl[0].type==0) {
+               printf("No namelist\n");
+               return;
+       }
+       coref = "/dev/mem";
+       if(kflg)
+               coref = "/usr/sys/core";
+       if ((hmem = open(coref, 0)) < 0) {
+               printf("No mem\n");
+               return;
+       }
+       mem = open(coref, 0);
+       swap = open("/dev/swap", 0);
+       if (swap < 0)
+               printf("No swap\n");
+       n = &proc[1];
+       b = &proc;
+       n =- b;
+       seek(hmem, nl[0].value, 0);
+       mtty = ttyn(0);
+       uid = getuid() & 0377;
+       for (i=0; i<NPROC; i++) {
+               read(hmem, proc, n);
+               if (proc[0].p_stat==0)
+                       continue;
+               if ((c=ttyc(proc[0].p_ttyp))=='?' && xflg==0)
+                       continue;
+               puid = proc[0].p_uid & 0377;
+               if (uid != puid && aflg==0)
+                       continue;
+               if (lflg || c!=mtty)
+                       printf("%c:", c);
+               else
+                       printf("  ");
+               if (lflg) {
+                       printf("%3o%4d%5d%5d",
+                               proc[0].p_flag<<3|proc[0].p_stat, puid,
+                               proc[0].p_pri,
+                               proc[0].p_time);
+               }
+               printf("%6d", proc[0].p_pid);
+               if (lflg) {
+                       printf("%4d", (proc[0].p_size+7)>>3);
+                       if (proc[0].p_wchan)
+                               printf("%8o", proc[0].p_wchan);
+                       else
+                               printf("        ");
+               }
+               if (proc[0].p_stat==5)
+                       printf(" <defunct>");
+               else
+                       prcom();
+               printf("\n");
+       }
+}
+
+ttyc(p)
+struct tty *p;
+{
+       int n;
+       struct { struct tty xdc11[]; };
+
+       n = p - nl[1].value->xdc11;
+       if (n>=0 && n<NDC11) {
+               if (n<8)
+                       return(n+'0');
+               return(n+'a'-8);
+       }
+       n = p - nl[2].value->xdc11;
+       if(n>=0 && n<NKL11)
+               return('8'+n);
+       n = p - nl[3].value->xdc11;
+       if(n>=0 && n<NDH11)
+               return('f'+n);
+       return('?');
+}
+
+setup(p, s)
+char *p, *s;
+{
+       while (*p++ = *s++);
+}
+
+prcom()
+{
+       int baddr, laddr, mf;
+       int *ip;
+       char *cp, *cp1;
+       int c;
+
+       baddr = 0;
+       laddr = 0;
+       if (proc[0].p_flag&SLOAD) {
+               laddr = proc[0].p_addr;
+               mf = mem;
+       } else {
+               baddr = proc[0].p_addr;
+               mf = swap;
+       }
+       laddr =+ proc[0].p_size - 8;
+       baddr =+ laddr>>3;
+       laddr = (laddr&07)<<6;
+       seek(mf, baddr, 3);
+       seek(mf, laddr, 1);
+       if (read(mf, stbuf, 512) != 512)
+               return(0);
+       for (ip = &stbuf[256]; ip > &stbuf[0];) {
+               if (*--ip == -1) {
+                       cp = ip+1;
+                       if (*cp==0)
+                               cp++;
+                       for (cp1 = cp; cp1 < &stbuf[256]; cp1++) {
+                               c = *cp1;
+                               if (c==0)
+                                       *cp1 = ' ';
+                               else if (c < ' ' || c > 0176)
+                                       *cp1 = '?';
+                       }
+                       printf(" %.32s ", cp);
+                       return(1);
+               }
+       }
+       return(0);
+}
diff --git a/usr/source/s3/rand.s b/usr/source/s3/rand.s
new file mode 100644 (file)
index 0000000..4b08e4e
--- /dev/null
@@ -0,0 +1,21 @@
+/ random fixed point number generator
+
+.globl rand, srand
+
+srand:
+       mov     r0,ranx
+       rts     pc
+
+rand:
+       mov     r1,-(sp)
+       mov     ranx,r1
+       mpy     $13077.,r1
+       add     $6925.,r1
+       mov     r1,r0
+       mov     r0,ranx
+       bic     $100000,r0
+       mov     (sp)+,r1
+       rts     pc
+
+.data
+ranx:  1
diff --git a/usr/source/s4/locv.s b/usr/source/s4/locv.s
new file mode 100644 (file)
index 0000000..9650747
--- /dev/null
@@ -0,0 +1,56 @@
+/ C library -- long output conversion
+
+.globl _locv
+
+_locv:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     r4,-(sp)
+       mov     r3,-(sp)
+       mov     r2,-(sp)
+       mov     $buf,r4
+       mov     6(r5),r3
+       mov     4(r5),r2
+       bpl     1f
+       neg     r2
+       neg     r3
+       sbc     r2
+       movb    $'-,(r4)+
+1:
+       jsr     pc,1f
+       clrb    (r4)+
+       mov     $buf,r0
+       mov     (sp)+,r2
+       mov     (sp)+,r3
+       mov     (sp)+,r4
+       mov     (sp)+,r5
+       rts     pc
+
+1:
+       jsr     pc,divid
+       add     $'0,r1
+       mov     r1,-(sp)
+       ashc    $0,r2
+       beq     1f
+       jsr     pc,1b
+1:
+       movb    (sp)+,(r4)+
+       rts     pc
+
+divid:
+       clr     r1
+       mov     $32.,r0
+1:
+       ashc    $1,r2
+       rol     r1
+       cmp     r1,$10.
+       blo     2f
+       sub     $10.,r1
+       inc     r3
+2:
+       sob     r0,1b
+       rts     pc
+
+
+.bss
+buf:   .=.+12.
diff --git a/usr/source/s4/seek.s b/usr/source/s4/seek.s
new file mode 100644 (file)
index 0000000..6d446eb
--- /dev/null
@@ -0,0 +1,21 @@
+/ C library -- seek
+
+/ error = seek(file, offset, ptr);
+
+.globl _seek, retrn, cerror
+
+_seek:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),r0
+       mov     6(r5),0f
+       mov     8(r5),0f+2
+       sys     0; 9f
+       bec     1f
+       jmp     cerror
+1:
+       clr     r0
+       jmp     retrn
+.data
+9:
+       sys     seek; 0:..; ..
diff --git a/usr/source/s4/stat.s b/usr/source/s4/stat.s
new file mode 100644 (file)
index 0000000..57ebe84
--- /dev/null
@@ -0,0 +1,24 @@
+/ C library -- stat
+
+/ error = stat(string, statbuf);
+
+/ int statbuf[18] or
+/ char statbuf[36]
+/ as appropriate
+
+.globl _stat, retrn, cerror
+
+_stat:
+       mov     r5,-(sp)
+       mov     sp,r5
+       mov     4(r5),0f
+       mov     6(r5),0f+2
+       sys     0; 9f
+       bec     1f
+       jmp     cerror
+1:
+       clr     r0
+       jmp     retrn
+.data
+9:
+       sys     stat; 0:..; ..