/ u1 -- unix
unkni: / used for all system calls
sysent:
incb sysflg / indicate a system routine is
beq 1f / in progress
jmp panic / called if trap inside system
1:
mov $s.syst+2,clockp
mov r0,-(sp) / save user registers
mov sp,u.r0 / pointer to bottom of users stack in u.r0
mov r1,-(sp)
mov r2,-(sp)
mov r3,-(sp)
mov r4,-(sp)
mov r5,-(sp)
mov ac,-(sp) / "accumulator" register for extended
/ arithmetic unit
mov mq,-(sp) / "multiplier quotient" register for the
/ extended arithmetic unit
mov sc,-(sp) / "step count" register for the extended
/ arithmetic unit
mov sp,u.sp / u.sp points to top of users stack
mov 18.(sp),r0 / store pc in r0
mov -(r0),r0 / sys inst in r0 10400xxx
sub $sys,r0 / get xxx code
asl r0 / multiply by 2 to jump indirect in bytes
cmp r0,$2f-1f / limit of table (35) exceeded
bhis badsys / yes, bad system call
bic $341,20.(sp) / set users processor priority to 0 and clear
/ carry bit
jmp *1f(r0) / jump indirect thru table of addresses
/ to proper system routine.
1:
sysrele / 0
sysexit / 1
sysfork / 2
sysread / 3
syswrite / 4
sysopen / 5
sysclose / 6
syswait / 7
syscreat / 8
syslink / 9
sysunlink / 10
sysexec / 11
syschdir / 12
systime / 13
sysmkdir / 14
syschmod / 15
syschown / 16
sysbreak / 17
sysstat / 18
sysseek / 19
systell / 20
sysmount / 21
sysumount / 22
syssetuid / 23
sysgetuid / 24
sysstime / 25
sysquit / 26
sysintr / 27
sysfstat / 28
sysemt / 29
sysmdate / 30
sysstty / 31
sysgtty / 32
sysilgins / 33
2:
error:
mov u.sp,r1
bis $1,20.(r1) / set c bit in processor status word below
/ users stack
sysret:
tstb u.bsys / is a process about to be terminated because
bne sysexit / of an error? yes, go to sysexit
mov u.sp,sp / no point stack to users stack
clr r1 / zero r1 to check last mentioned i-node
jsr r0,iget / if last mentioned i-node has been modified
/ it is written out
tstb smod / has the super block been modified
beq 1f / no, 1f
clrb smod / yes, clear smod
bis $1000,sb0 / set write bit in I/O queue for super block
/ output
jsr r0,ppoke / write out modified super block to disk
1:
tstb mmod / has the super block for the dismountable file
/ system
beq 1f / been modified? no, 1f
clrb mmod / yes, clear mmod
movb mntd,sb1 / set the I/O queue
bis $1000,sb1 / set write bit in I/O queue for detached sb
jsr r0,ppoke / write it out to its device
1:
tstb uquant / is the time quantum 0?
bne 1f / no, don't swap it out
sysrele:
jsr r0,tswap / yes, swap it out
1:
mov (sp)+,sc / restore user registers
mov (sp)+,mq
mov (sp)+,ac
mov (sp)+,r5
mov (sp)+,r4
mov (sp)+,r3
mov (sp)+,r2
mov (sp)+,r1
mov (sp)+,r0
mov $s.chrgt+2,clockp
decb sysflg / turn system flag off
jsr r0,isintr / is there an interrupt from the user
br intract / yes, output gets flushed, take interrupt
/ action
rti / no return from interrupt
badsys:
incb u.bsys / turn on the user's bad-system flag
mov $3f,u.namep / point u.namep to "core\0\0"
jsr r0,namei / get the i-number for the core image file
br 1f / error
neg r1 / negate the i-number to open the core image file
/ for writing
jsr r0,iopen / open the core image file
jsr r0,itrunc / free all associated blocks
br 2f
1:
mov $17,r1 / put i-node mode (17) in r1
jsr r0,maknod / make an i-node
mov u.dirbuf,r1 / put i-nodes number in r1
2:
mov $core,u.base / move address core to u.base
mov $ecore-core,u.count / put the byte count in u.count
mov $u.off,u.fofp / more user offset to u.fofp
clr u.off / clear user offset
jsr r0,writei / write out the core image to the user
mov $user,u.base / pt. u.base to user
mov $64.,u.count / u.count = 64
jsr r0,writei / write out all the user parameters
neg r1 / make i-number positive
jsr r0,iclose / close the core image file
br sysexit /
3:
<core\0\0>
sysexit: / terminate process
clr u.intr / clear interrupt control word
clr r1 / clear r1
1: / r1 has file descriptor (index to u.fp list) Search the whole list
jsr r0,fclose / close all files the process opened
br .+2 / ignore error return
inc r1 / increment file descriptor
cmp r1,$10. / end of u.fp list?
blt 1b / no, go back
movb u.uno,r1 / yes, move dying process's number to r1
clrb p.stat-1(r1) / free the process
asl r1 / use r1 for index into the below tables
mov p.pid-2(r1),r3 / move dying process's name to r3
mov p.ppid-2(r1),r4 / move its parents name to r4
clr r2
clr r5 / initialize reg
1: / find children of this dying process, if they are zombies, free them
add $2,r2 / search parent process table for dying process's name
cmp p.ppid-2(r2),r3 / found it?
bne 3f / no
asr r2 / yes, it is a parent
cmpb p.stat-1(r2),$3 / is the child of this dying process a
/ zombie
bne 2f / no
clrb p.stat-1(r2) / yes, free the child process
2:
asl r2
3: / search the process name table for the dying process's parent
cmp p.pid-2(r2),r4 / found it?
bne 3f / no
mov r2,r5 / yes, put index to p.pid table (parents
/ process # x2) in r5
3:
cmp r2,$nproc+nproc / has whole table been searched?
blt 1b / no, go back
mov r5,r1 / yes, r1 now has parents process # x2
beq 2f / no parent has been found. The process just dies
asr r1 / set up index to p.stat
movb p.stat-1(r1),r2 / move status of parent to r2
beq 2f / if its been freed, 2f
cmp r2,$3 / is parent a zombie?
beq 2f / yes, 2f
movb u.uno,r3 / move dying process's number to r3
movb $3,p.stat-1(r3) / make the process a zombie
cmp r2,$2 / is the parent waiting for this child to die
bne 2f / yes, notify parent not to wait any more
decb p.stat-1(r1) / awaken it by putting it (parent)
mov $runq+4,r2 / on the runq
jsr r0, putlu
2: / the process dies
clrb u.uno / put zero as the process number, so "swap" will
jsr r0,swap / overwrite process with another process
0 / and thereby kill it; halt?
intract: / interrupt action
cmp *(sp),$rti / are you in a clock interrupt?
bne 1f / no, 1f
cmp (sp)+,(sp)+ / pop clock pointer
1: / now in user area
mov r1,-(sp) / save r1
mov u.ttyp,r1 / pointer to tty buffer in control-to r1
cmpb 6(r1),$177 / is the interrupt char equal to "del"
beq 1f / yes, 1f
clrb 6(r1) / no, clear the byte (must be a quit character)
mov (sp)+,r1 / restore r1
clr u.quit / clear quit flag
bis $20,2(sp) / set trace for quit (sets t bit of ps-trace trap)
rti / return from interrupt
1: / interrupt char = del
clrb 6(r1) / clear the interrupt byte in the buffer
mov (sp)+,r1 / restore r1
cmp u.intr,$core / should control be transferred to loc core?
blo 1f
jmp *u.intr / user to do rti yes, transfer to loc core
1:
sys 1 / exit
syswait: / wait for a process to die
movb u.uno,r1 / put parents process number in r1
asl r1 / x2 to get index into p.pid table
mov p.pid-2(r1),r1 / get the name of this process
clr r2
clr r3 / initialize reg 3
1:
add $2,r2 / use r2 for index into p.ppid table / search table
/ of parent processes for this process name
cmp p.ppid-2(r2),r1 / r2 will contain the childs process number
bne 3f / branch if no match of parent process name
inc r3 / yes, a match, r3 indicates number of children
asr r2 / r2/2 to get index to p.stat table
cmpb p.stat-1(r2),$3 / is the child process a zombie?
bne 2f / no, skip it
clrb p.stat-1(r2) / yes, free it
asl r2 / r2x2 to get index into p.pid table
mov p.pid-2(r2),*u.r0 / put childs process name in (u.r0)
br sysret1 / return cause child is dead
2:
asl r2 / r2x2 to get index into p.ppid table
3:
cmp r2,$nproc+nproc / have all processes been checked?
blt 1b / no, continue search
tst r3 / one gets here if there are no children or children
/ that are still active
be
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PDP计算机 Unix v1 源代码-贝尔实验室 (238个子文件)
ed.1 15KB
bas.1 9KB
tap.1 8KB
db.1 8KB
sh.1 8KB
as.1 7KB
ld.1 4KB
dc.1 3KB
form.1 3KB
ar.1 3KB
stat.1 2KB
write.1 2KB
ls.1 2KB
mail.1 2KB
check.1 1KB
for.1 1KB
mv.1 1KB
type.1 1KB
dtf.1 1KB
du.1 1KB
boot.1 1KB
roff.1 1KB
mkfs.1 1KB
rkf.1 1024B
ln.1 998B
lbppt.1 960B
b.1 958B
rm.1 954B
pr.1 912B
strip.1 894B
rmdir.1 834B
nm.1 793B
od.1 782B
cat.1 767B
mount.1 753B
su.1 743B
wc.1 729B
un.1 721B
chmod.1 720B
rkl.1 712B
sdate.1 700B
rkd.1 677B
cp.1 672B
dsw.1 669B
mesg.1 663B
dbppt.1 641B
cmp.1 636B
mkdir.1 590B
cedir.1 589B
umount.1 586B
rew.1 572B
chown.1 569B
sum.1 531B
df.1 482B
who.1 476B
tty.1 465B
find.1 439B
bcd.1 420B
hup.1 407B
date.1 293B
tm.1 220B
exec.2 3KB
stty.2 2KB
stat.2 2KB
creat.2 2KB
wait.2 2KB
unlink.2 1KB
read.2 1KB
mount.2 1KB
open.2 1KB
intr.2 1KB
seek.2 1KB
cemt.2 1KB
write.2 1KB
chmod.2 1KB
break.2 1KB
fork.2 963B
tell.2 930B
chown.2 902B
ilgins.2 877B
getuid.2 842B
umount.2 835B
quit.2 737B
mkdir.2 733B
close.2 731B
smdate.2 709B
fstat.2 709B
gtty.2 706B
rele.2 692B
link.2 689B
setuid.2 607B
time.2 595B
chdir.2 582B
exit.2 520B
stime.2 477B
getw.3 2KB
putc.3 2KB
atof.3 848B
ftoa.3 796B
ctime.3 788B
共 238 条
- 1
- 2
- 3
资源评论
矛盾行者
- 粉丝: 3
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功