From e02257d5ef91d99a0cbad38c0d72529b041c8ed6 Mon Sep 17 00:00:00 2001 From: Ken Thompson Date: Tue, 26 Nov 1974 18:13:21 -0500 Subject: [PATCH] Research V5 development Work on file usr/source/s2/update.s Work on file usr/source/s4/read.s Work on file usr/source/s1/exit.c Work on file usr/source/s3/put.s Work on file usr/source/s3/get.s Work on file usr/sys/inode.h Co-Authored-By: Dennis Ritchie Synthesized-from: v5 --- usr/source/s1/exit.c | 5 ++ usr/source/s2/update.s | 10 ++++ usr/source/s3/get.s | 92 +++++++++++++++++++++++++++++++++++++ usr/source/s3/put.s | 102 +++++++++++++++++++++++++++++++++++++++++ usr/source/s4/read.s | 22 +++++++++ usr/sys/inode.h | 36 +++++++++++++++ 6 files changed, 267 insertions(+) create mode 100644 usr/source/s1/exit.c create mode 100644 usr/source/s2/update.s create mode 100644 usr/source/s3/get.s create mode 100644 usr/source/s3/put.s create mode 100644 usr/source/s4/read.s create mode 100644 usr/sys/inode.h diff --git a/usr/source/s1/exit.c b/usr/source/s1/exit.c new file mode 100644 index 0000000000..79ca44437f --- /dev/null +++ b/usr/source/s1/exit.c @@ -0,0 +1,5 @@ +/* exit -- end runcom */ + +main() { + seek(0, 0, 2); +} diff --git a/usr/source/s2/update.s b/usr/source/s2/update.s new file mode 100644 index 0000000000..c98baaf36a --- /dev/null +++ b/usr/source/s2/update.s @@ -0,0 +1,10 @@ + sys fork + br 1f + sys exit +1: + sys sync + mov $30.,r0 + sys sleep + br 1b +sleep = 35. +sync = 36. diff --git a/usr/source/s3/get.s b/usr/source/s3/get.s new file mode 100644 index 0000000000..24d87e4bc2 --- /dev/null +++ b/usr/source/s3/get.s @@ -0,0 +1,92 @@ +/ getw/getc -- get words/characters from input file +/ fopen -- open a file for use by get(c|w) +/ +/ calling sequences -- +/ +/ mov $filename,r0 +/ jsr r5,fopen; ioptr +/ +/ on return ioptr buffer is set up or error bit is set if +/ file could not be opened. +/ +/ jsr r5,get(c|w)1; ioptr +/ +/ on return char/word is in r0; error bit is +/ set on error or end of file. +/ +/ ioptr is the address of a 518-byte buffer +/ whose layout is as follows: +/ +/ ioptr: .=.+2 / file descriptor +/ .=.+2 / charact+2 / pointer to next character (reset if no. chars=0) +/ .=.+512. / the buffer + + .globl getc,getw,fopen + +fopen: + mov r1,-(sp) + mov (r5)+,r1 + mov r0,0f + sys 0; 9f +.data +9: + sys open; 0:..; 0 +.text + bes 1f + mov r0,(r1)+ + clr (r1)+ + mov (sp)+,r1 + rts r5 +1: + mov $-1,(r1) + mov (sp)+,r1 + sec + rts r5 + +.data +getw: + mov (r5),9f + mov (r5)+,8f + jsr r5,getc; 8:.. + bec 1f + rts r5 +1: + mov r0,-(sp) + jsr r5,getc; 9:.. + swab r0 + bis (sp)+,r0 + rts r5 +.text + +getc: + mov r1,-(sp) + mov (r5)+,r1 + dec 2(r1) + bge 1f + mov r1,r0 + add $6,r0 + mov r0,0f + mov r0,4(r1) + mov (r1),r0 + sys 0; 9f +.data +9: + sys read; 0:..; 512. +.text + bes 2f + tst r0 + bne 3f +2: + mov (sp)+,r1 + sec + rts r5 +3: + dec r0 + mov r0,2(r1) +1: + clr r0 + bisb *4(r1),r0 + inc 4(r1) + mov (sp)+,r1 + rts r5 + diff --git a/usr/source/s3/put.s b/usr/source/s3/put.s new file mode 100644 index 0000000000..82aa5cad8b --- /dev/null +++ b/usr/source/s3/put.s @@ -0,0 +1,102 @@ +/ putw/putc -- write words/characters on output file +/ +/ fcreat -- create an output file for use by put(w|c) +/ +/ calling sequences -- +/ +/ mov $filename,r0 +/ jsr r5,fcreat; ioptr +/ +/ on return ioptr is set up for use by put or error +/ bit is set if file could not be created. +/ +/ mov(b) thing,r0 +/ jsr r5,put(w|c)1; ioptr +/ +/ the character or word is written out. +/ +/ jsr r5,flush; ioptr +/ +/ the buffer is fled. +/ + + .globl putc, putw, flush, fcreat + +fcreat: + mov r1,-(sp) + mov (r5)+,r1 + mov r0,0f + sys 0; 9f +.data +9: + sys creat; 0:..; 666 +.text + bes 1f + mov r0,(r1)+ +2: + clr (r1)+ + clr (r1)+ + mov (sp)+,r1 + rts r5 +1: + mov $-1,(r1)+ + mov (sp)+,r1 + sec + rts r5 + +.data +putw: + mov (r5),8f + mov (r5)+,9f + mov r0,-(sp) + jsr r5,putc; 8:.. + mov (sp)+,r0 + swab r0 + jsr r5,putc; 9:.. + rts r5 +.text + +putc: + mov r1,-(sp) + mov (r5)+,r1 +1: + dec 2(r1) + bge 1f + mov r0,-(sp) + jsr pc,fl + mov (sp)+,r0 + br 1b +1: + movb r0,*4(r1) + inc 4(r1) + mov (sp)+,r1 + rts r5 + +flush: + mov r0,-(sp) + mov r1,-(sp) + mov (r5)+,r1 + jsr pc,fl + mov (sp)+,r1 + mov (sp)+,r0 + rts r5 + +fl: + mov r1,r0 + add $6,r0 + mov r0,-(sp) + mov r0,0f + mov 4(r1),0f+2 + beq 1f + sub (sp),0f+2 + mov (r1),r0 + sys 0; 9f +.data +9: + sys write; 0:..; .. +.text +1: + mov (sp)+,4(r1) + mov $512.,2(r1) + rts pc + diff --git a/usr/source/s4/read.s b/usr/source/s4/read.s new file mode 100644 index 0000000000..c99df0fef7 --- /dev/null +++ b/usr/source/s4/read.s @@ -0,0 +1,22 @@ +/ C library -- read + +/ nread = read(file, buffer, count); +/ +/ nread ==0 means eof; nread == -1 means error + +.globl _read, retrn, cerror + +_read: + 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: + jmp retrn +.data +9: + sys read; 0:..; .. diff --git a/usr/sys/inode.h b/usr/sys/inode.h new file mode 100644 index 0000000000..c8c69de7eb --- /dev/null +++ b/usr/sys/inode.h @@ -0,0 +1,36 @@ +struct inode { + char i_flag; + char i_count; + int i_dev; + int i_number; + int i_mode; + char i_nlink; + char i_uid; + char i_gid; + char i_size0; + char *i_size1; + int i_addr[8]; + int i_lastr; +} inode[NINODE]; + +/* flags */ +#define ILOCK 01 +#define IUPD 02 +#define IACC 04 +#define IMOUNT 010 +#define IWANT 020 +#define ITEXT 040 + +/* modes */ +#define IALLOC 0100000 +#define IFMT 060000 +#define IFDIR 040000 +#define IFCHR 020000 +#define IFBLK 060000 +#define ILARG 010000 +#define ISUID 04000 +#define ISGID 02000 +#define ISVTX 01000 +#define IREAD 0400 +#define IWRITE 0200 +#define IEXEC 0100 -- 2.20.1