mirror of
https://github.com/DoctorWkt/unix-jun72.git
synced 2026-03-10 04:44:54 +00:00
- next three pages from Hellwig
This commit is contained in:
56
pages/e01-04
Normal file
56
pages/e01-04
Normal file
@@ -0,0 +1,56 @@
|
||||
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:
|
||||
56
pages/e01-05
Normal file
56
pages/e01-05
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
beq error1 / there are no children, error
|
||||
movb u.uno,r1 / there are children so put parent process number
|
||||
/ in r1
|
||||
incb p.stat-1(r1) / it is waiting for other children to die
|
||||
jsr r0,swap / swap it out, because it's waiting
|
||||
br syswait / wait on next process
|
||||
|
||||
error1:
|
||||
jmp error / see 'error' routine
|
||||
sysret1:
|
||||
jmp sysret / see 'sysret' routine
|
||||
|
||||
sysfork: / create a new process
|
||||
clr r1
|
||||
1: / search p.stat table for unused process number
|
||||
inc r1
|
||||
tstb p.stat-1(r1) / is process active, unused, dead
|
||||
beq 1f / it's unused so branch
|
||||
cmp r1,$nproc / all processes checked
|
||||
blt 1b / no, branch back
|
||||
add $2,18.(sp) / add 2 to pc when trap occured, points
|
||||
/ to old process return
|
||||
br error1 / no room for a new process
|
||||
1:
|
||||
movb u.uno,-(sp) / save parent process number
|
||||
movb r1,u.uno / set child process number to r1
|
||||
incb p.stat-1(r1) / set p.stat entry for child process to
|
||||
/ active status
|
||||
56
pages/e01-06
Normal file
56
pages/e01-06
Normal file
@@ -0,0 +1,56 @@
|
||||
mov u.ttyp,r2 / put pointer to parent process' control tty
|
||||
/ buffer in r2
|
||||
beq 2f / branch, if no such tty assigned
|
||||
clrb 6(r2) / clear interrupt character in tty buffer
|
||||
2:
|
||||
mov $runq+4,r2
|
||||
jsr r0,putlu / put child process on lowest priority run queue
|
||||
asl r1 / multiply r1 by 2 to get index into p.pid table
|
||||
inc mpid / increment m.pid; get a new process name
|
||||
mov mpid,p.pid-2(r1) / put new process name in child process'
|
||||
/ name slot
|
||||
movb (sp),r2 / put parent process number in r2
|
||||
asl r2 / multiply by 2 to get index into below tables
|
||||
mov p.pid-2(r2),r2 / get process name of parent process
|
||||
mov r2,p.ppid-2(r1) / put parent process name in parent
|
||||
/ process slot for child
|
||||
mov r2,*u.r0 / put parent process name on stack at location
|
||||
/ where r0 was saved
|
||||
mov $sysret1,-(sp) /
|
||||
mov sp,u.usp / contents of sp at the time when user is
|
||||
/ swapped out
|
||||
mov $sstack,sp / point sp to swapping stack space
|
||||
jsr r0,wswap / put child process out on drum
|
||||
jsr r0,unpack / unpack user stack
|
||||
mov u.usp,sp / restore user stack pointer
|
||||
tst (sp)+ / bump stack pointer
|
||||
movb (sp)+,u.uno / put parent process number in u.uno
|
||||
mov mpid,*u.r0 / put child process name on stack where r0
|
||||
/ was saved
|
||||
add $2,18.(sp) / add 2 to pc on stack; gives parent
|
||||
/ process return
|
||||
clr r1
|
||||
1: / search u.fp list to find the files opened by the parent process
|
||||
movb u.fp(r1),r2 / get an open file for this process
|
||||
beq 2f / file has not been opened by parent, so branch
|
||||
asl r2 / multiply by 8
|
||||
asl r2 / to get index into fsp table
|
||||
asl r2
|
||||
incb fsp-2(r2) / increment number of processes using file,
|
||||
/ because child will now be using this file
|
||||
2:
|
||||
inc r1 / get next open file
|
||||
cmp r1,$10. / 10. files is the maximum number which can be
|
||||
/ opened
|
||||
blt 1b / check next entry
|
||||
br sysret1
|
||||
|
||||
sysread:
|
||||
jsr r0,rw1 / get i-number of file to be read into r1
|
||||
tst r1 / negative i—number?
|
||||
ble error1 / yes, error 1 to read it should be positive
|
||||
jsr r0,readi / read data into core
|
||||
br 1f
|
||||
|
||||
syswrite:
|
||||
jsr r0,rw1 / get i-number in r1 of file to write
|
||||
Reference in New Issue
Block a user