Commit | Line | Data |
---|---|---|
45cc16b2 KT |
1 | / init -- process control initialization |
2 | ||
3 | mount = 21. | |
4 | ||
5 | sys intr; 0 / turn off interrupts | |
6 | sys quit; 0 | |
7 | cmp csw,$73700 / single user? | |
8 | bne 1f / no | |
9 | help: | |
10 | clr r0 / yes | |
11 | sys close / close current read | |
12 | mov $1,r0 / and write | |
13 | sys close / files | |
14 | sys open; ctty; 0 / open control tty | |
15 | sys open; ctty; 1 / for read and write | |
16 | sys exec; shell; shellp / execute shell | |
17 | br help / keep trying | |
18 | 1: | |
19 | mov $'0,r1 / prepare to change | |
20 | 1 : | |
21 | movb r1,tapx+8 / mode of dec tape drive x, where | |
22 | sys chmod; tapx; 17 / x=0 to 7, to read/write by owner or | |
23 | inc r1 / non-owner mode | |
24 | cmp r1,$'8 / finished? | |
25 | blo 1b / no | |
26 | sys mount; rk0; usr / yes, root file on mounted rko5 | |
27 | / disk ls /usr | |
28 | sys creat; utmp; 16 / truncate /tmp/utmp | |
29 | sys close / close it | |
30 | movb $'x,zero+8. / put identifier in output buffer | |
31 | jsr pc,wtmprec / go to write accting info | |
32 | mov $itab,r1 / address of table to r1 | |
33 | ||
34 | / create shell processes | |
35 | ||
36 | 1: | |
37 | mov (r1)+,r0 / 'x, x=0, 1... to r0 | |
38 | beq 1f / branch if table end | |
39 | movb r0,ttyx+8 / put symbol in ttyx | |
40 | jsr pc,dfork / go to make new init for this ttyx | |
41 | mov r0,(r1)+ / save child id in word offer '0, '1,...etc. | |
42 | br 1b / set up next child | |
43 | ||
44 | / wait for process to die | |
45 | ||
46 | 1: | |
47 | sys wait / wait for user to terminate process | |
48 | mov $itab,r1 / initialize for search | |
49 | ||
50 | / search for process id | |
51 | ||
52 | 2: | |
53 | tst (r1)+ / bump r1 to child id location | |
54 | beq 1b / ? something silly | |
55 | cmp r0,(r1)+ / which process has terminated | |
56 | bne 2b / not this one | |
57 | ||
58 | / take name out of utmp | |
59 | ||
60 | sub $4, r1 / process is found, point x' to 'x | |
61 | / for it | |
62 | mov r1,-(sp) / save address on stack | |
63 | mov (r1),r1 / move 'x to r1 | |
64 | sub $'0,r1 / remove zone bits from character | |
65 | asl r1 / generate proper | |
66 | asl r1 / offset | |
67 | asl r1 / for | |
68 | asl r1 / seek | |
69 | mov r1,0f / move it to offset loc for seek | |
70 | mov $zero,r1 | |
71 | 2: | |
72 | clr (r1)+ / ccear- | |
73 | cmp r1,$zero+16. / output buffer | |
74 | blo 2b / area | |
75 | sys open; utmp; 1 / open file for writing | |
76 | bes 2f / if can't open, create user anyway | |
77 | mov r0,r1 / save file desc | |
78 | sys seek; 0:..; 0 / move to proper pointer position | |
79 | mov r1,r0 / not required | |
80 | sys write; zero; 16. / zero this position in | |
81 | mov r1,r0 / restore file descriptor | |
82 | sys close / close file | |
83 | ||
84 | / re-create user process | |
85 | ||
86 | 2: | |
87 | mov (sp)+,r1 / restore 'x to r1 | |
88 | mov (r1)+,r0 / move it to r0 | |
89 | movb r0,ttyx+8 / get correct ttyx | |
90 | movb r0,zero+8 / move identifier to output buffer | |
91 | jsr pc,wtmprec / go to write accting into | |
92 | jsr pc,dfork / fork | |
93 | mov r0,(r1)+ / save id of child | |
94 | br 1b / go to wait for next process end | |
95 | ||
96 | dfork: | |
97 | mov r1,r2 | |
98 | sub $itab+2,r2 / left over | |
99 | asl r2 / from previous | |
100 | asl r2 / version of code | |
101 | mov r2,offset | |
102 | sys fork | |
103 | br 1f / to new copy of init | |
104 | bes dfork / try again | |
105 | rts pc / return | |
106 | 1 : | |
107 | sys quit; 0 / new init turns off | |
108 | sys intr; 0 / interrupts | |
109 | sys chown; ttyx; 0 / change owner to super user | |
110 | sys chmod; ttyx; 15 / changemode to read/write owner, | |
111 | / write non-owner | |
112 | sys open; ttyx; 0 / open this ttyx for reading | |
113 | / and wait until someone calls | |
114 | bes help1 / branch if trouble | |
115 | sys open; ttyx; 1 / open this ttyx for writing after | |
116 | / user call | |
117 | bes help1 / branch if trouble | |
118 | sys exec; getty; gettyp / getty types <login> and | |
119 | / executes login which logs user | |
120 | / in and executes sh- | |
121 | sys exit / HELP! | |
122 | ||
123 | help1: | |
124 | jmp help / trouble | |
125 | ||
126 | wtmprec: | |
127 | sys time / get time | |
128 | mov ac,zero+10. / more to output | |
129 | mov mq,zero+12. / buffer | |
130 | sys open; wtmp; 1 / open accounting file | |
131 | bes 2f | |
132 | mov r0,r2 / save file descriptor | |
133 | sys seek; 0; 2 / move pointer to end of file | |
134 | mov r2,r0 / not required | |
135 | sys write; zero; 16. / write accting info | |
136 | mov r2,r0 / restore file descriptor | |
137 | sys close / close file | |
138 | 2: | |
139 | rts pc | |
140 | ||
141 | ctty: </dev/tty\0> | |
142 | shell: </bin/sh\0> | |
143 | shellm: <-\0> | |
144 | tapx: </dev/tapx\0> | |
145 | rk0: </dev/rk0\0> | |
146 | utmp: </tmp/utmp\0> | |
147 | wtmp: </tmp/wtmp\0> | |
148 | ttyx: </dev/ttyx\0> | |
149 | getty: </etc/getty\0> | |
150 | usr: </usr\0> | |
151 | .even | |
152 | ||
153 | shellp: shellm | |
154 | 0 | |
155 | gettyp: getty | |
156 | 0 | |
157 | itab: | |
158 | '0; .. | |
159 | '1; .. | |
160 | '2; .. | |
161 | '3; .. | |
162 | '4; .. | |
163 | '5; .. | |
164 | '6; .. | |
165 | '7; .. | |
166 | 0 | |
167 | ||
168 | offset: .=.+2 | |
169 | zero: .=.+8; .=.+6; .=.+2 |