Add original unix v6

This commit is contained in:
memnoth
2018-01-27 22:35:41 +09:00
commit 2c7099ee50
664 changed files with 106254 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
/ C library -- abort
.globl _abort
iot = 4
_abort:
mov r5,-(sp)
mov sp,r5
iot
mov (sp)+,r5
rts pc
+16
View File
@@ -0,0 +1,16 @@
/ abs - int absolute value.
/ fabs - floating abs
.globl _abs
_abs:
mov 2(sp),r0
bge 1f
neg r0
1:
rts pc
.globl _fabs
_fabs:
movf 2(sp),fr0
absf fr0
rts pc
+165
View File
@@ -0,0 +1,165 @@
/ storage allocator for use with C
/
/
/
/ hand-tooled from C compilation to modify save-return
/ so that it can be called from within the C save
/ when running with coroutines
/
/#
//*
/ * C storage allocator
/ * (circular first fit strategy)
/ */
/#define BLOK 512
/#define BUSY 01
/
/char *allocs[2] { /*initial empty arena*/
/ &allocs[1],
/ &allocs[0]
/};
/struct { int word; };
/char **allocp &allocs[1]; /*current search pointer*/
/char **alloct &allocs[1]; /*top of arena (last cell)*/
/
/alloc(nbytes)
/{
/ register int nwords;
/ register char **p, **q;
/ static char **t;
/
/ allocs[0].word =| BUSY; /*static initialization*/
/ allocs[1].word =| BUSY;
/
/ nwords = (nbytes+(2*sizeof(p)-1))/sizeof(p);
/ for(p=allocp;;) {
/ do {
/ if((p->word&BUSY)==0) {
/ while(((q = *p)->word&BUSY)==0)
/ *p = *q;
/ if(q >= &p[nwords])
/ goto found;
/ }
/ q = p;
/ p = p->word & ~BUSY;
/ } while(q>=allocp || p<allocp);
/ if((*alloct=t=sbrk(BLOK*sizeof(p))) == -1)
/ return(-1);
/ if(t!=alloct+1)
/ alloct->word =| BUSY;
/ alloct = (*t = &t[BLOK]-1);
/ *alloct = allocs;
/ alloct->word =| BUSY;
/ }
/found:
/ allocp = &p[nwords];
/ if(q>allocp)
/ *allocp = *p;
/ *p = allocp.word|BUSY;
/ return(p+1);
/}
/
/free(p)
/char **p;
/{
/ allocp = p-1;
/ allocp->word =& ~BUSY;
/}
.globl _allocs
.data
_allocs=.
2+_allocs
_allocs
.globl _allocp
.data
_allocp=.
2+_allocs
.globl _alloct
.data
_alloct=.
2+_allocs
.globl _alloc
.globl _sbrk
.text
_alloc:
mov r5,-(sp)
mov sp,r5
mov r4,-(sp)
mov r3,-(sp)
mov r2,-(sp)
bis $1,_allocs
bis $1,2+_allocs
mov 4(r5),r4
add $3,r4
asr r4
mov _allocp,r3
jbr L6
L7:mov r3,r2
mov (r3),r3
bic $!177776,r3
cmp r2,_allocp
jhis L6
cmp r3,_allocp
jlo L6
mov $2000,-(sp)
jsr pc,*$_sbrk
tst (sp)+
mov r0,t
mov r0,*_alloct
cmp $177777,r0
jeq L11
mov _alloct,r0
add $2,r0
cmp t,r0
jeq L12
bis $1,*_alloct
L12:mov t,r0
add $1776,r0
mov r0,*t
mov r0,_alloct
mov $_allocs,*_alloct
bis $1,*_alloct
L6:bit $1,(r3)
jeq L8
jbr L7
L20001:mov (r2),(r3)
L8:mov (r3),r2
bit $1,(r2)
jeq L20001
mov r4,r0
asl r0
add r3,r0
cmp r2,r0
jlo L7
mov r4,r0
asl r0
add r3,r0
mov r0,_allocp
cmp r2,r0
jlos L13
mov (r3),*_allocp
L13:mov _allocp,r0
bis $1,r0
mov r0,(r3)
mov r3,r0
add $2,r0
L11:
mov (sp)+,r2
mov (sp)+,r3
mov (sp)+,r4
mov (sp)+,r5
rts pc
.globl _free
.text
_free:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
add $177776,r0
mov r0,_allocp
bic $!177776,*_allocp
mov (sp)+,r5
rts pc
.bss
t: .=.+2
+130
View File
@@ -0,0 +1,130 @@
/ C library -- ascii to floating
/ f = atof(p)
/ char *p;
ldfps = 170100^tst
stfps = 170200^tst
.globl _atof
.globl csv, cret
_atof:
jsr r5,csv
stfps -(sp)
ldfps $200
movf fr1,-(sp)
clr -(sp)
clrf fr0
clr r2
mov 4(r5),r3
1:
movb (r3)+,r0
cmp $' ,r0
beq 1b
cmpb r0,$'-
bne 2f
inc (sp)
1:
movb (r3)+,r0
2:
sub $'0,r0
cmp r0,$9.
bhi 2f
jsr pc,digit
br 1b
inc r2
br 1b
2:
cmpb r0,$'.-'0
bne 2f
1:
movb (r3)+,r0
sub $'0,r0
cmp r0,$9.
bhi 2f
jsr pc,digit
dec r2
br 1b
2:
cmpb r0,$'E-'0
beq 3f
cmpb r0,$'e-'0
bne 1f
3:
clr r4
clr r1
cmpb (r3),$'-
bne 3f
inc r4
inc r3
3:
movb (r3)+,r0
sub $'0,r0
cmp r0,$9.
bhi 3f
mul $10.,r1
add r0,r1
br 3b
3:
tst r4
bne 3f
neg r1
3:
sub r1,r2
1:
movf $one,fr1
mov r2,-(sp)
beq 2f
bgt 1f
neg r2
1:
cmp r2,$38.
blos 1f
clrf fr0
tst (sp)+
bmi out
movf $huge,fr0
br out
1:
mulf $ten,fr1
sob r2,1b
2:
tst (sp)+
bge 1f
divf fr1,fr0
br 2f
1:
mulf fr1,fr0
cfcc
bvc 2f
movf $huge,fr0
2:
out:
tst (sp)+
beq 1f
negf fr0
1:
movf (sp)+,fr1
ldfps (sp)+
jmp cret
/
/
digit:
cmpf $big,fr0
cfcc
blt 1f
mulf $ten,fr0
movif r0,fr1
addf fr1,fr0
rts pc
1:
add $2,(sp)
rts pc
/
/
one = 40200
ten = 41040
big = 56200
huge = 77777
+24
View File
@@ -0,0 +1,24 @@
atoi(ap)
char *ap;
{
register n, c;
register char *p;
int f;
p = ap;
n = 0;
f = 0;
loop:
while(*p == ' ' || *p == ' ')
p++;
if(*p == '-') {
f++;
p++;
goto loop;
}
while(*p >= '0' && *p <= '9')
n = n*10 + *p++ - '0';
if(f)
n = -n;
return(n);
}
+12
View File
@@ -0,0 +1,12 @@
/ C return sequence which
/ sets errno, returns -1.
.globl cerror
.comm _errno,2
cerror:
mov r0,_errno
mov $-1,r0
mov r5,sp
mov (sp)+,r5
rts pc
+20
View File
@@ -0,0 +1,20 @@
/ C library -- chdir
/ error = chdir(string);
.globl _chdir, cerror
_chdir:
mov r5,-(sp)
mov sp,r5
mov 4(r5),0f
sys 0; 9f
bec 1f
jmp cerror
1:
clr r0
mov (sp)+,r5
rts pc
.data
9:
sys chdir; 0:..
+21
View File
@@ -0,0 +1,21 @@
/ C library -- chmod
/ error = chmod(string, mode);
.globl _chmod, cerror
_chmod:
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
mov (sp)+,r5
rts pc
.data
9:
sys chmod; 0:..; ..
+21
View File
@@ -0,0 +1,21 @@
/ C library -- chown
/ error = chown(string, owner);
.globl _chown, cerror
_chown:
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
mov (sp)+,r5
rts pc
.data
9:
sys chown; 0:..; ..
+17
View File
@@ -0,0 +1,17 @@
/ C library -- close
/ error = close(file);
.globl _close, cerror
_close:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
sys close
bec 1f
jmp cerror
1:
clr r0
mov (sp)+,r5
rts pc
+22
View File
@@ -0,0 +1,22 @@
/ C library -- creat
/ file = creat(string, mode);
/
/ file == -1 if error
.globl _creat, cerror
_creat:
mov r5,-(sp)
mov sp,r5
mov 4(r5),0f
mov 6(r5),0f+2
sys 0; 9f
bec 1f
jmp cerror
1:
mov (sp)+,r5
rts pc
.data
9:
sys creat; 0:..; ..
+20
View File
@@ -0,0 +1,20 @@
/ C runtime startoff
.globl savr5
.globl _exit
.globl _main
start:
setd
mov sp,r0
mov (r0),-(sp)
tst (r0)+
mov r0,2(sp)
jsr pc,_main
mov r0,(sp)
jsr pc,*$_exit
sys exit
.bss
savr5: .=.+2
+22
View File
@@ -0,0 +1,22 @@
/ C register save and restore -- version 12/74
.globl csv
.globl cret
csv:
mov r5,r0
mov sp,r5
mov r4,-(sp)
mov r3,-(sp)
mov r2,-(sp)
tst -(sp)
jmp (r0)
cret:
mov r5,r1
mov -(r1),r4
mov -(r1),r3
mov -(r1),r2
mov r5,sp
mov (sp)+,r5
rts pc
+249
View File
@@ -0,0 +1,249 @@
#
/*
* This routine converts time as follows.
* The epoch is 0000 Jan 1 1970 GMT.
* The argument time is in seconds since then.
* The localtime(t) entry returns a pointer to an array
* containing
* seconds (0-59)
* minutes (0-59)
* hours (0-23)
* day of month (1-31)
* month (0-11)
* year-1970
* weekday (0-6, Sun is 0)
* day of the year
* daylight savings flag
*
* The routine corrects for daylight saving
* time and will work in any time zone provided
* "timezone" is adjusted to the difference between
* Greenwich and local standard time (measured in seconds).
* In places like Michigan "daylight" must
* be initialized to 0 to prevent the conversion
* to daylight time.
* There is a table which accounts for the peculiarities
* undergone by daylight time in 1974-1975.
*
* The routine does not work
* in Saudi Arabia which runs on Solar time.
*
* asctime(tvec))
* where tvec is produced by localtime
* returns a ptr to a character string
* that has the ascii time in the form
* Thu Jan 01 00:00:00 1970n0\\
* 01234567890123456789012345
* 0 1 2
*
* ctime(t) just calls localtime, then asctime.
*/
char cbuf[26];
int dmsize[12]
{
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
};
int timezone 5*60*60;
int tzname[]
{
"EST",
"EDT",
};
int daylight 1; /* Allow daylight conversion */
/*
* The following table is used for 1974 and 1975 and
* gives the day number of the first day after the Sunday of the
* change.
*/
struct {
int daylb;
int dayle;
} daytab[] {
5, 333, /* 1974: Jan 6 - last Sun. in Nov */
58, 303, /* 1975: Last Sun. in Feb - last Sun in Oct */
};
#define SEC 0
#define MIN 1
#define HOUR 2
#define MDAY 3
#define MON 4
#define YEAR 5
#define WDAY 6
#define YDAY 7
#define ISDAY 8
ctime(at)
int *at;
{
return(asctime(localtime(at)));
}
localtime(tim)
int tim[];
{
register int *t, *ct, dayno;
int daylbegin, daylend;
int copyt[2];
t = copyt;
t[0] = tim[0];
t[1] = tim[1];
dpadd(t, -timezone);
ct = gmtime(t);
dayno = ct[YDAY];
daylbegin = 119; /* last Sun in Apr */
daylend = 303; /* Last Sun in Oct */
if (ct[YEAR]==74 || ct[YEAR]==75) {
daylbegin = daytab[ct[YEAR]-74].daylb;
daylend = daytab[ct[YEAR]-74].dayle;
}
daylbegin = sunday(ct, daylbegin);
daylend = sunday(ct, daylend);
if (daylight &&
(dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) &&
(dayno<daylend || (dayno==daylend && ct[HOUR]<1))) {
dpadd(t, 1*60*60);
ct = gmtime(t);
ct[ISDAY]++;
}
return(ct);
}
/*
* The argument is a 0-origin day number.
* The value is the day number of the first
* Sunday on or after the day.
*/
sunday(at, ad)
int *at;
{
register int *t, d;
t = at;
d = ad;
if (d >= 58)
d =+ dysize(t[YEAR]) - 365;
return(d - (d - t[YDAY] + t[WDAY] + 700) % 7);
}
gmtime(tim)
int tim[];
{
register int d0, d1;
register *tp;
static xtime[9];
extern int ldivr;
/*
* break initial number into
* multiples of 8 hours.
* (28800 = 60*60*8)
*/
d0 = ldiv(tim[0], tim[1], 28800);
d1 = ldivr;
tp = &xtime[0];
/*
* generate hours:minutes:seconds
*/
*tp++ = d1%60;
d1 =/ 60;
*tp++ = d1%60;
d1 =/ 60;
d1 =+ (d0%3)*8;
d0 =/ 3;
*tp++ = d1;
/*
* d0 is the day number.
* generate day of the week.
*/
xtime[WDAY] = (d0+4)%7;
/*
* year number
*/
for(d1=70; d0 >= dysize(d1); d1++)
d0 =- dysize(d1);
xtime[YEAR] = d1;
xtime[YDAY] = d0;
/*
* generate month
*/
if (dysize(d1)==366)
dmsize[1] = 29;
for(d1=0; d0 >= dmsize[d1]; d1++)
d0 =- dmsize[d1];
dmsize[1] = 28;
*tp++ = d0+1;
*tp++ = d1;
xtime[ISDAY] = 0;
return(xtime);
}
asctime(t)
int *t;
{
register char *cp, *ncp;
register int *tp;
cp = cbuf;
for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;);
ncp = &"SunMonTueWedThuFriSat"[3*t[6]];
cp = cbuf;
*cp++ = *ncp++;
*cp++ = *ncp++;
*cp++ = *ncp++;
cp++;
tp = &t[4];
ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3];
*cp++ = *ncp++;
*cp++ = *ncp++;
*cp++ = *ncp++;
cp = ct_numb(cp, *--tp);
cp = ct_numb(cp, *--tp+100);
cp = ct_numb(cp, *--tp+100);
cp = ct_numb(cp, *--tp+100);
cp =+ 2;
cp = ct_numb(cp, t[YEAR]);
return(cbuf);
}
dysize(y)
{
if((y%4) == 0)
return(366);
return(365);
}
ct_numb(acp, n)
{
register char *cp;
cp = acp;
cp++;
if (n>=10)
*cp++ = (n/10)%10 + '0';
else
*cp++ = ' ';
*cp++ = n%10 + '0';
return(cp);
}
+19
View File
@@ -0,0 +1,19 @@
/ C library -- dup
/ f = dup(of)
/ f == -1 for error
dup = 41.
.globl _dup, cerror
_dup:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
sys dup
bec 1f
jmp cerror
1:
mov (sp)+,r5
rts pc
+36
View File
@@ -0,0 +1,36 @@
char *sys_errlist[] {
"Error 0",
"Not super-user",
"No such file or directory",
"No such process",
"Interrupted system call",
"I/O error",
"No such device or address",
"Arg list too long",
"Exec format error",
"Bad file number",
"No children",
"No more processes",
"Not enough core",
"Permission denied",
"Error 14",
"Block device required",
"Mount device busy",
"File exists",
"Cross-device link",
"No such device",
"Not a directory",
"Is a directory",
"Invalid argument",
"File table overflow",
"Too many open files",
"Not a typewriter",
"Text file busy",
"File too large",
"No space left on device",
"Illegal seek",
"Read-only file system",
"Too many links",
"Broken Pipe",
};
int sys_nerr { sizeof sys_errlist/sizeof sys_errlist[0] };
+19
View File
@@ -0,0 +1,19 @@
/ C library -- execl
/ execl(file, arg1, arg2, ... , 0);
/
.globl _execl, cerror
_execl:
mov r5,-(sp)
mov sp,r5
mov 4(r5),0f
mov r5,r0
add $6,r0
mov r0,0f+2
sys 0; 9f
jmp cerror
.data
9:
sys exec; 0:..; ..
+31
View File
@@ -0,0 +1,31 @@
/ C library -- execv
/ execv(file, argv);
/
/ where argv is a vector argv[0] ... argv[x], 0
/ last vector element must be 0
/
/ The _exectrap flags is used by the debugger and causes
/ a trace trap on the first instruction of the executed instruction
/ to give a chance to set breakpoints.
.globl _execv, cerror
.comm __exectrap,2
rtt = 6
_execv:
mov r5,-(sp)
mov sp,r5
mov 4(r5),0f
mov 6(r5),0f+2
tst __exectrap
beq 1f
mov $170020,-(sp) / t-bit
mov $1f,-(sp)
rtt
1:
sys 0; 9f
jmp cerror
.data
9:
sys exec; 0:..; ..
+13
View File
@@ -0,0 +1,13 @@
/ C library -- exit
/ exit(code)
/ code is return in r0 to system
.globl _exit
_exit:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
sys exit
+23
View File
@@ -0,0 +1,23 @@
/ C runtime startoff
/ with floating point interpreter
.globl savr5
.globl fptrap
.globl _exit
.globl _main
start:
sys signal; 4; fptrap
setd
mov sp,r0
mov (r0),-(sp)
tst (r0)+
mov r0,2(sp)
jsr pc,_main
mov r0,(sp)
jsr pc,*$_exit
sys exit
.bss
savr5: .=.+2
+10
View File
@@ -0,0 +1,10 @@
/ C library-- fake floating output
.globl pfloat
.globl pscien
pfloat:
pscien:
add $8,r4
movb $'?,(r3)+
rts pc
+91
View File
@@ -0,0 +1,91 @@
/ C library-- floating output
.globl pfloat
.globl pscien
.globl fltused
.globl _ndigit
.globl ecvt
.globl fcvt
fltused: / force loading
pfloat:
mov r0,_ndigit
tst r2
bne 1f
mov $6,_ndigit
1:
movf (r4)+,fr0
jsr pc,fcvt
tst r1
beq 1f
movb $'-,(r3)+
1:
tst r2
bgt 1f
movb $'0,(r3)+
1:
mov r2,r1
ble 1f
2:
movb (r0)+,(r3)+
sob r1,2b
1:
mov _ndigit,r1
beq 1f
movb $'.,(r3)+
1:
neg r2
ble 1f
2:
dec r1
blt 1f
movb $'0,(r3)+
sob r2,2b
1:
tst r1
ble 2f
1:
movb (r0)+,(r3)+
sob r1,1b
2:
rts pc
pscien:
mov r0,_ndigit
tst r2
bne 1f
mov $6,_ndigit
1:
movf (r4)+,fr0
jsr pc,ecvt
tst r1
beq 1f
movb $'-,(r3)+
1:
movb (r0)+,(r3)+
movb $'.,(r3)+
mov _ndigit,r1
dec r1
ble 1f
2:
movb (r0)+,(r3)+
sob r1,2b
1:
movb $'e,(r3)+
dec r2
mov r2,r1
bge 1f
movb $'-,(r3)+
neg r1
br 2f
1:
movb $'+,(r3)+
2:
clr r0
div $10.,r0
add $'0,r0
movb r0,(r3)+
add $'0,r1
movb r1,(r3)+
rts pc
+24
View File
@@ -0,0 +1,24 @@
/ C library -- fork
/ pid = fork();
/
/ pid == 0 in child process; pid == -1 means error return
/ in child, parents id is in par_uid if needed
.globl _fork, cerror, _par_uid
_fork:
mov r5,-(sp)
mov sp,r5
sys fork
br 1f
bec 2f
jmp cerror
1:
mov r0,_par_uid
clr r0
2:
mov (sp)+,r5
rts pc
.bss
_par_uid: .=.+2
+25
View File
@@ -0,0 +1,25 @@
/ C library -- fstat
/ error = fstat(file, statbuf);
/ int statbuf[17] or
/ char statbuf[34]
/ as appropriate
.globl _fstat, cerror
_fstat:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
mov 6(r5),0f
sys 0; 9f
bec 1f
jmp cerror
1:
clr r0
mov (sp)+,r5
rts pc
.data
9:
sys fstat; 0:..
+83
View File
@@ -0,0 +1,83 @@
/ getw/getc -- get words/characters from input file
/ fopen -- open a file for use by get(c|w)
indir = 0
.globl _getc, _getw, _fopen
.globl cerror
.comm _errno,2
_fopen:
mov r5,-(sp)
mov sp,r5
mov 4(r5),0f
sys 0; 9f
.data
9: sys open; 0:..; 0
.text
bes badret
mov 6(r5),r1
mov r0,(r1)+
clr (r1)+
clr r0
mov (sp)+,r5
rts pc
_getw:
clr _errno
mov r5,-(sp)
mov sp,r5
mov 4(r5),r1
sub $2,2(r1)
bge 1f
cmp 2(r1),$-1
blt 2f
movb *4(r1),-(sp)
jsr pc,fill
mov 4(r1),r0
br 3f
2:
jsr pc,fill
dec 2(r1)
1:
mov 4(r1),r0
movb (r0)+,-(sp)
3:
movb (r0)+,1(sp)
mov r0,4(r1)
mov (sp)+,r0
mov (sp)+,r5
rts pc
_getc:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r1
dec 2(r1)
bge 1f
jsr pc,fill
1:
clr r0
bisb *4(r1),r0
inc 4(r1)
mov (sp)+,r5
rts pc
fill:
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 badret
dec r0
bmi badret
mov r0,2(r1)
rts pc
badret:
jmp cerror
+32
View File
@@ -0,0 +1,32 @@
/ getchar() -- get a character from input file fin
.globl _getchar
.comm _errno,2
.comm _fin,518.
_getchar:
mov r5,-(sp)
mov sp,r5
dec _fin+2
bge 1f
mov $_fin+6,_fin+4
mov _fin,r0
sys read; _fin+6; 512.
bes badret
tst r0
beq badret
dec r0
mov r0,_fin+2
1:
clr r0
bisb *_fin+4,r0
inc _fin+4
mov (sp)+,r5
rts pc
badret:
mov r0,_errno
clr r0
clr _fin+2
mov (sp)+,r5
rts pc
+12
View File
@@ -0,0 +1,12 @@
/ C library - getcsw
/ csw = getcsw();
.globl _getcsw
_getcsw:
mov r5,-(sp)
mov sp,r5
sys 38.
mov (sp)+,r5
rts pc
+14
View File
@@ -0,0 +1,14 @@
/ C library -- getgid
/ gid = getgid();
/
getgid = 47.
.globl _getgid
_getgid:
mov r5,-(sp)
mov sp,r5
sys getgid
mov (sp)+,r5
rts pc
+13
View File
@@ -0,0 +1,13 @@
/ getpid -- get process ID
getpid = 20.
.globl _getpid
_getpid:
mov r5,-(sp)
mov sp,r5
sys getpid
mov (sp)+,r5
rts pc
+43
View File
@@ -0,0 +1,43 @@
getpw(uid, buf)
int uid;
char buf[];
{
auto pbuf[259];
static pwf;
register n, c;
register char *bp;
if(pwf == 0)
pwf = open("/etc/passwd", 0);
if(pwf < 0)
return(1);
seek(pwf, 0, 0);
pbuf[0] = pwf;
pbuf[1] = 0;
pbuf[2] = 0;
uid =& 0377;
for (;;) {
bp = buf;
while((c=getc(pbuf)) != '\n') {
if(c <= 0)
return(1);
*bp++ = c;
}
*bp++ = '\0';
bp = buf;
n = 3;
while(--n)
while((c = *bp++) != ':')
if(c == '\n')
return(1);
while((c = *bp++) != ':') {
if(c<'0' || c>'9')
continue;
n = n*10+c-'0';
}
if(n == uid)
return(0);
}
return(1);
}
+13
View File
@@ -0,0 +1,13 @@
/ C library -- getuid
/ uid = getuid();
/
.globl _getuid
_getuid:
mov r5,-(sp)
mov sp,r5
sys getuid
mov (sp)+,r5
rts pc
+24
View File
@@ -0,0 +1,24 @@
/ C library -- gtty
/ error = gtty(filep, ttyvec);
/ filep is descriptor of open tty
/ ttyvec[0, 1, 2] correspond to args of gtty
.globl _gtty, cerror
_gtty:
mov r5,-(sp)
mov sp,r5
mov 4(r5),r0
mov 6(r5),0f
sys 0; 9f
bec 1f
jmp cerror
1:
clr r0
mov (sp)+,r5
rts pc
.data
9:
sys gtty; 0:..
+6
View File
@@ -0,0 +1,6 @@
.globl _hmul
_hmul:
mov 2(sp),r0
mul 4(sp),r0
rts pc
+22
View File
@@ -0,0 +1,22 @@
/ C library -- kill
.globl _kill, cerror
kill = 37.
indir = 0
_kill:
mov r5,-(sp)
mov sp,r5
mov 4(sp),r0
mov 6(sp),8f
sys indir; 9f
bec 1f
jmp cerror
1:
clr r0
mov (sp)+,r5
rts pc
.data
9:
sys kill; 8:..
+38
View File
@@ -0,0 +1,38 @@
/ C routine-- long integer subtract and add
/ ladd/lsub (a, b, c);
/ int a[2], b[2], c[2];
/ a = b +- c;
.globl _lsub
.globl _ladd
.globl csv
.globl cret
_lsub:
jsr r5,csv
mov 6(r5),r2
mov (r2)+,r0
mov (r2),r1
mov 10(r5),r2
sub (r2)+,r0
sub (r2),r1
sbc r0
mov 4(r5),r2
mov r0,(r2)+
mov r1,(r2)
jmp cret
_ladd:
jsr r5,csv
mov 6(r5),r2
mov (r2)+,r0
mov (r2),r1
mov 10(r5),r2
add (r2)+,r0
add (r2),r1
adc r0
mov 4(r5),r2
mov r0,(r2)+
mov r1,(r2)
jmp cret
+11
View File
@@ -0,0 +1,11 @@
ldfps = 170100^tst
/
/ ldfps(number);
.globl _ldfps
_ldfps:
mov r5,-(sp)
mov sp,r5
ldfps 4(r5)
mov (sp)+,r5
rts pc
+22
View File
@@ -0,0 +1,22 @@
/ C library -- link
/ error = link(old-file, new-file);
/
.globl _link, cerror
_link:
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
mov (sp)+,r5
rts pc
.data
9:
sys link; 0:..; ..
+56
View File
@@ -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.
+27
View File
@@ -0,0 +1,27 @@
/ C library
/ return floating-point from long integer
/ d = ltod(l)
.globl _ltod
_ltod:
mov r5,-(sp)
mov sp,r5
setl
movif *4(r5),fr0
seti
mov (sp)+,r5
rts pc
/ return long integer from floating
/ dtol(d, l)
.globl _dtol
_dtol:
mov r5,-(sp)
mov sp,r5
setl
movf 4(r5),fr0
movfi fr0,*12.(r5)
seti
mov (sp)+,r5
rts pc
+42
View File
@@ -0,0 +1,42 @@
as crt0.s
cmp a.out /lib/crt0.o
cp a.out /lib/crt0.o
as fcrt0.s
cmp a.out /lib/fcrt0.o
cp a.out /lib/fcrt0.o
as abort.s; mv a.out abort.o
as abs.s; mv a.out abs.o
as alloc.s; mv a.out alloc.o
as atof.s; mv a.out atof.o
as cerror.s; mv a.out cerror.o
as chdir.s; mv a.out chdir.o
as chmod.s; mv a.out chmod.o
as chown.s; mv a.out chown.o
as close.s; mv a.out close.o
as creat.s; mv a.out creat.o
as csv.s; mv a.out csv.o
as dup.s; mv a.out dup.o
as execl.s; mv a.out execl.o
as execv.s; mv a.out execv.o
as exit.s; mv a.out exit.o
as ffltpr.s; mv a.out ffltpr.o
as fltpr.s; mv a.out fltpr.o
as fork.s; mv a.out fork.o
as fstat.s; mv a.out fstat.o
as getc.s; mv a.out getc.o
as getchr.s; mv a.out getchr.o
as getcsw.s; mv a.out getcsw.o
as getgid.s; mv a.out getgid.o
as getpid.s; mv a.out getpid.o
as getuid.s; mv a.out getuid.o
as gtty.s; mv a.out gtty.o
as hmul.s; mv a.out hmul.o
as kill.s; mv a.out kill.o
as ladd.s; mv a.out ladd.o
as ldfps.s; mv a.out ldfps.o
as link.s; mv a.out link.o
as locv.s; mv a.out locv.o
as ltod.s; mv a.out ltod.o
cc -c -O *.c
ar r /lib/libc.a
rm *.o