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