Commit | Line | Data |
---|---|---|
45cc16b2 KT |
1 | / u6 -- unix |
2 | ||
3 | readi: | |
4 | clr u.nread / accumulates number of bytes transmitted | |
5 | tst u.count / is number of bytes to be read greater than 0 | |
6 | bgt 1f / yes, branch | |
7 | rts r0 / no, nothing to read; return to caller | |
8 | 1: | |
9 | mov r1,-(sp) / save i-number on stack | |
10 | cmp r1,$40. / want to read a special file (i-nodes 1,...,40 are | |
11 | / for special files) | |
12 | ble 1f / yes, branch | |
13 | jmp dskr / no, jmp to dskr; read file with i-node number (r1) | |
14 | / starting at byte ((u.fofp)), read in u.count bytes | |
15 | 1: | |
16 | asl r1 / multiply inode number by 2 | |
17 | jmp *1f-2(r1) | |
18 | 1: | |
19 | rtty / tty; r1=2 | |
20 | rppt / ppt; r1=4 | |
21 | rmem / mem; r1=6 | |
22 | rrf0 / rf0 | |
23 | rrk0 / rk0 | |
24 | rtap / tap0 | |
25 | rtap / tap1 | |
26 | rtap / tap2 | |
27 | rtap / tap3 | |
28 | rtap / tap4 | |
29 | rtap / tap5 | |
30 | rtap / tap6 | |
31 | rtap / tap7 | |
32 | rcvt / tty0 | |
33 | rcvt / tty1 | |
34 | rcvt / tty2 | |
35 | rcvt / tty3 | |
36 | rcvt / tty4 | |
37 | rcvt / tty5 | |
38 | rcvt / tty6 | |
39 | rcvt / tty7 | |
40 | rcrd/ crd | |
41 | ||
42 | rtty: / read from console tty | |
43 | mov tty+[8*ntty]-8+6,r5 / r5 is the address of the 4th word of | |
44 | / of the control and status block | |
45 | tst 2(r5) / for the console tty; this word points to the console | |
46 | / tty buffer | |
47 | bne 1f / 2nd word of console tty buffer contains number | |
48 | / of chars. Is this number non-zero? | |
49 | jsr r0,canon; ttych / if 0, call 'canon' to get a line | |
50 | / (120 chars.) | |
51 | 1: | |
52 | tst 2(r5) / is the number of characters zero | |
53 | beq ret1 / yes, return to caller via 'ret1' | |
54 | movb *4(r5),r1 / no, put character in r1 | |
55 | inc 4(r5) / 3rd word of console tty buffer points to byte which | |
56 | / contains the next char. | |
57 | dec 2(r5) / decrement the character count | |
58 | jsr r0,passc / move the character to core (user) | |
59 | br 1b / get next character | |
60 | ||
61 | ret1: | |
62 | jmp ret / return to caller via 'ret' | |
63 | ||
64 | rppt: / read paper tape | |
65 | jsr r0,pptic / gets next character in clist for ppt input and | |
66 | / places | |
67 | br ret / it in r1; if there 1s no problem with reader, it | |
68 | / also enables read bit in prs | |
69 | jsr r0,passc / place character in users buffer area | |
70 | br rppt | |
71 | ||
72 | rmem: / transfer characters from memory to a user area of core | |
73 | mov *u.fofp,r1 / save file offset which points to the char to | |
74 | / be transferred to user | |
75 | inc *u.fofp / increment file offset to point to 'next' char in | |
76 | / memory file | |
77 | movb (r1),r1 / get character from memory file, put it in r1 | |
78 | jsr r0,passc / move this character to the next byte of the | |
79 | / users core area | |
80 | br rmem / continue | |
81 | 1: | |
82 | rcrd: | |
83 | jmp error / see 'error' routine | |
84 | ||
85 | dskr: | |
86 | mov (sp),r1 / i-number in r1 | |
87 | jsr r0,iget / get i-node (r1) into i-node section of core | |
88 | mov i.size,r2 / file size in bytes in r2 | |
89 | sub *u.fofp,r2 / subtract file offset | |
90 | blos ret | |
91 | cmp r2,u.count / are enough bytes left in file to carry out read | |
92 | bhis 1f | |
93 | mov r2,u.count / no, just read to end of file | |
94 | 1 : | |
95 | jsr r0,mget / returns physical block number of block in file | |
96 | / where offset points | |
97 | jsr r0,dskrd / read in block, r5 points to 1st word of data in | |
98 | / buffer | |
99 | jsr r0,sioreg | |
100 | 2: | |
101 | movb (r2)+,(r1)+ / move data from buffer into working core | |
102 | / starting at u.base | |
103 | dec r3 | |
104 | bne 2b / branch until proper number of bytes are transferred | |
105 | tst u.count / all bytes read off disk | |
106 | bne dskr | |
107 | br ret | |
108 | ||
109 | passc: | |
110 | movb r1,*u.base / move a character to the next byte of the | |
111 | / users buffer | |
112 | inc u.base / increment the pointer to point to the next byte | |
113 | / in users buffer | |
114 | inc u.nread / increment the number of bytes read | |
115 | dec u.count / decrement the number of bytes to be read | |
116 | bne 1f / any more bytes to read?; yes, branch | |
117 | mov (sp)+,r0 / no, do a non-local return to the caller of | |
118 | / 'readi' by: | |
119 | ret: / (1) pop the return address off the stack into r0 | |
120 | mov (sp)+,r1 / (2) pop the i-number off the stack into r1 | |
121 | 1: | |
122 | clr *$ps / clear processor status | |
123 | rts r0 / return to address currently on top of stack | |
124 | ||
125 | writei: | |
126 | clr u.nread / clear the number of bytes transmitted during | |
127 | / read or write calls | |
128 | tst u.count / test the byte count specified by the user | |
129 | bgt 1f / any bytes to output; yes, branch | |
130 | rts r0 / no, return - no writing to do | |
131 | 1: | |
132 | mov r1 ,-(sp) / save the i-node number on the stack | |
133 | cmp r1,$40. / does the i-node number indicate a special file? | |
134 | bgt dskw / no, branch to standard file output | |
135 | asl r1 / yes, calculate the index into the special file | |
136 | jmp *1f-2(r1) / jump table and jump to the appropriate routine | |
137 | 1: | |
138 | wtty / tty | |
139 | wppt / ppt | |
140 | wmem / mem | |
141 | wrf0 / rf0 | |
142 | wrk0 / rk0 | |
143 | wtap / tap0 | |
144 | wtap / tap1 | |
145 | wtap / tap2 | |
146 | wtap / tap3 | |
147 | wtap / tap4 | |
148 | wtap / tap5 | |
149 | wtap / tap6 | |
150 | wtap / tap7 | |
151 | xmtt / tty0 | |
152 | xmtt / tty1 | |
153 | xmtt / tty2 | |
154 | xmtt / tty3 | |
155 | xmtt / tty4 | |
156 | xmtt / tty5 | |
157 | xmtt / tty6 | |
158 | xmtt / tty7 | |
159 | / w1pr / lpr | |
160 | ||
161 | wtty: | |
162 | jsr r0,cpass / get next character from user buffer area; if | |
163 | / none go to return address in syswrite | |
164 | tst r1 / is character = null | |
165 | beq wtty / yes, get next character | |
166 | 1 : | |
167 | mov $240,*$ps / no, set processor priority to five | |
168 | cmpb cc+1,$20. / is character count for console tty greater | |
169 | / than 20 | |
170 | bhis 2f / yes; branch to put process to sleep | |
171 | jsr r0,putc; 1 / find place in freelist to assign to console | |
172 | / tty and | |
173 | br 2f / place character in list; if none available | |
174 | / branch to put process to sleep | |
175 | jsr r0,startty / attempt to output character on tty | |
176 | br wtty | |
177 | 2: | |
178 | mov r1,-(sp) / place character on stack | |
179 | jsr r0,sleep; 1 / put process to sleep | |
180 | mov (sp)+,r1 / remove character from stack | |
181 | br 1b / try again to place character in clist and output | |
182 | ||
183 | wppt: | |
184 | jsr r0,cpass / get next character from user buffer area, | |
185 | / if none return to writei's calling routine | |
186 | jsr r0,pptoc / output character on ppt | |
187 | br wppt | |
188 | /wlpr: | |
189 | / jsr r0,cpass | |
190 | / cmp r0,$'a | |
191 | / blo 1f | |
192 | / cmp r1,$'z | |
193 | / bhi 1f | |
194 | / sub $40,r1 | |
195 | /1: | |
196 | / jsr r0,lptoc | |
197 | / br wlpr | |
198 | ||
199 | wmem: / transfer characters from a user area of core to memory file | |
200 | jsr r0,cpass / get next character from users area of core and | |
201 | / put it in r1 | |
202 | mov r1,-(sp) / put character on the stack | |
203 | mov *u.fofp,r1 / save file offset in r1 | |
204 | inc *u.fofp / increment file offset to point to next available | |
205 | / location in file | |
206 | movb (sp)+,(r1) / pop char off stack, put in memory loc assigned | |
207 | / to it | |
208 | br wmem / continue | |
209 | 1: | |
210 | jmp error / ? | |
211 | ||
212 | dskw: / write routine for non-special files | |
213 | mov (sp),r1 / get an i-node number from the stack into r1 | |
214 | jsr r0,iget / write i-node out (if modified), read i-node 'r1' | |
215 | / into i-node area of core | |
216 | mov *u.fofp,r2 / put the file offset [(u.off) or the offset in | |
217 | / the fsp entry for this file] in r2 | |
218 | add u.count,r2 / no. of bytes to be written + file offset is | |
219 | / put in r2 | |
220 | cmp r2,i.size / is this greater than the present size of | |
221 | / the file? | |
222 | blos 1f / no, branch | |
223 | mov r2,i.size / yes, increase the f11e size to file offset + | |
224 | / no. of data bytes | |
225 | jsr r0,setimod / set imod=1 (i.e., core inode has been | |
226 | / modified), stuff tlme of modification into | |
227 | / core image of i-node | |
228 | 1: | |
229 | jsr r0,mget / get the block no. in which to write the next data | |
230 | / byte | |
231 | bit *u.fofp,$777 / test the lower 9 bits of the file offset | |
232 | bne 2f / if its non-zero, branch; if zero, file offset = 0, | |
233 | / 512, 1024,...(i.e., start of new block) | |
234 | cmp u.count,$512. / if zero, is there enough data to fill an | |
235 | / entire block? (i.e., no. of | |
236 | bhis 3f / bytes to be written greater than 512.? Yes, branch. | |
237 | / Don't have to read block | |
238 | 2: / in as no past info. is to be saved (the entire block will be | |
239 | / overwritten). | |
240 | jsr r0,dskrd / no, must retain old info.. Hence, read block 'r1' | |
241 | / into an I/O buffer | |
242 | 3: | |
243 | jsr r0,wslot / set write and inhibit bits in I/O queue, proc. | |
244 | / status=0, r5 points to 1st word of data | |
245 | jsr r0,sioreg / r3 = no. of bytes of data, r1 = address of data, | |
246 | / r2 points to location in buffer in which to | |
247 | / start writing data | |
248 | 2: | |
249 | movb (r1 )+,(r2)+ / transfer a byte of data to the I/O buffer | |
250 | dec r3 / decrement no. of bytes to be written | |
251 | bne 2b / have all bytes been transferred? No, branch | |
252 | jsr r0,dskwr / yes, write the block and the i-node | |
253 | tst u.count / any more data to write? | |
254 | bne 1b / yes, branch | |
255 | jmp ret / no, return to the caller via 'ret' | |
256 | ||
257 | cpass: / get next character from user area of core and put it in r1 | |
258 | tst u.count / have all the characters been transferred (i.e., | |
259 | / u.count, # of chars. left | |
260 | beq 1f / to be transferred = 0?) yes, branch | |
261 | dec u.count / no, decrement u.count | |
262 | movb *u.base,r1 / take the character pointed to by u.base and | |
263 | / put it in r1 | |
264 | inc u.nread / increment no. of bytes transferred | |
265 | inc u.base / increment the buffer address to point to the | |
266 | rts r0 / next byte | |
267 | 1: | |
268 | mov (sp)+,r0 / put return address of calling routine into r0 | |
269 | mov (sp)+,r1 / i-number in r1 | |
270 | rts r0 / non-local return | |
271 | ||
272 | sioreg: | |
273 | mov *u.fofp,r2 / file offset (in bytes) is moved to r2 | |
274 | mov r2,r3 / and also to r3 | |
275 | bis $177000,r3 / set bits 9,...,15. of file offset in r3 | |
276 | bic $!777,r2 / calculate file offset mod 512. | |
277 | add r5,r2 / r2 now points to 1st byte in system buffer where | |
278 | / data is to be placed | |
279 | mov u.base,r1 / address of data is in r1 | |
280 | neg r3 / 512 - file offset (mod512.) in r3 (i.e., the number | |
281 | / of free bytes in the file block | |
282 | cmp r3,u.count / compare this with the number of data bytes to | |
283 | / be written to the file | |
284 | blos 2f / if less than branch. Use the number of free bytes | |
285 | / in the file block as the number to be written | |
286 | mov u.count,r3 / if greater than, use the number of data bytes | |
287 | / as the number to be written | |
288 | 2: | |
289 | add r3,u.nread / r3 + number of bytes xmitted during write is | |
290 | / put into u.nread | |
291 | sub r3,u.count / u.count = no. of bytes that still must be | |
292 | / written or read | |
293 | add r3,u.base / u.base points to the 1st of the remaining data | |
294 | / bytes | |
295 | add r3,*u.fofp / new file offset = number of bytes done + old | |
296 | / file offset | |
297 | rts r0 | |
298 |