return EWOULDBLOCK on read w/ no carrier or NBIO in raw mode
[unix-history] / usr / src / sys / vax / mdec / tsboot.c
CommitLineData
92e67171 1/* tsboot.c 6.1 83/07/29 */
cbaeb7fe
SL
2
3/*
4 * VAX tape boot block for distribution tapes
5 * works on unibus ts11
6 *
7 * reads a program from a tp directory on a tape and executes it
8 * program must be stripped of the header and is loaded ``bits as is''
9 * you can return to this loader via ``ret'' as you are called ``calls $0,ent''
10 */
11 .set RELOC,0x70000
12/* a.out defines */
13 .set HDRSIZ,040 /* size of file header for VAX */
14 .set MAGIC,0410 /* file type id in header */
15 .set TSIZ,4 /* text size */
16 .set DSIZ,8 /* data size */
17 .set BSIZ,12 /* bss size */
18 .set TENT,024 /* task header entry loc */
19/* tp directory definitions */
20 .set FILSIZ,38 /* tp direc offset for file size */
21 .set BNUM,44 /* tp dir offset for start block no. */
22 .set ENTSIZ,64 /* size of 1 TP dir entry, bytes */
23 .set PTHSIZ,32 /* size of TP path name, bytes */
24 .set BLKSIZ,512 /* tape block size, bytes */
25 .set NUMDIR,24 /* no. of dir blocks on tape */
26 .set ENTBLK,8 /* no. of dir entries per tape block */
27/* processor registers and bits */
28 .set RXCS,32
29 .set RXDB,33
30 .set TXCS,34
31 .set TXDB,35
32 .set RXCS_DONE,0x80
33 .set TXCS_RDY,0x80
34 .set TXCS_pr,7 /* bit position of TXCS ready bit */
35 .set RXCS_pd,7 /* bit position of RXCS done bit */
36/* UBA registers */
37 .set UBA_DPR1,68
38 .set UBA_MAP,2048
39 .set BNE,0x80000000
40 .set MRV,0x80000000
41 .set MR_BDP1,0x200000
42/* TS UBA registers */
43 .set TSDB,0
44 .set TSSR,2
45/* TS commands and bits */
46 .set TSA,0x200 /* page 1, ts command buffer relocation */
47 .set TS_ACK,0100000 /* ack packet */
48 .set TS_CVC,040000 /* clear volume check */
49 .set TS_SETCHR,4 /* set characteristics */
50 .set TS_READ,1 /* read */
51 .set TS_RETRY,01000 /* retry, or with read */
52 .set TS_REWIND,02010
53/* local stack variables */
54 .set tapa,-4 /* desired tape addr */
55 .set mtapa,-8 /* current tape addr */
56 .set name,-8-PTHSIZ /* operator-typed file name */
57/* register usage */
58 .set rUBA,r10
59 .set rTS,r11
60/* ===== */
61
62/* initialization */
63init:
64 movl $RELOC,fp /* core loc to which to move this program */
65 addl3 $name,fp,sp /* set stack pointer; leave room for locals */
66 clrl r0
671:
68 movc3 $end,(r0),(fp) /* move boot up to relocated position */
69 jmp start+RELOC
70start:
71 ashl $-9,$RELOC,r0
72 bisl3 $MRV,r0,UBA_MAP+4(%rUBA)
73 clrw TSSR(%rTS)
74 bsbw tsquiet
75 movw $TSA+setchr,TSDB(%rTS)
76 bsbw tsquiet
77 bsbw rew /* rewind input tape */
78 movab name(fp),r4 /* start of filename storage */
79 movzbl $'=,r0 /* prompt character */
80 bsbw putc /* output char to main console */
81/* read in a file name */
82 movl r4,r1 /* loc at which to store file name */
83nxtc:
84 bsbw getc /* get input char's in file name */
85 cmpb r0,$012 /* terminator ? */
86 beql nullc
87 movb r0,(r1)+
88 brb nxtc
89nullc:
90 subl3 r4,r1,r9 /* size of path name */
91 beql start /* dumb operator */
92 clrb (r1)+
93 incl r9
94/* user-specified TP filename has been stored at name(fp) */
95/* read in entire tp directory contents into low core */
96dirred:
97 movl $8,tapa(fp) /* tp directory starts at block 8 */
98 movl $(NUMDIR*BLKSIZ),r6 /* no. bytes in total dir */
99 bsbw taper /* read no. bytes indicated */
100/* search entire directory for user-specified file name */
101 clrl r5 /* dir buff loc = 0 */
102nxtdir:
103 cmpc3 r9,(r5),(r4) /* see if dir entry matches filename */
104 beql fndfil /* found match */
105 acbl $NUMDIR*BLKSIZ-1,$ENTSIZ,r5,nxtdir
106 /* see if done with tp dir */
107 brw start /* entry not in directory; start over */
108/* found desired tp dir entry */
109fndfil:
110 movzwl BNUM(r5),tapa(fp) /* start block no., 2 bytes */
111 addl2 $7,tapa(fp) /* skip 7 boot blocks */
112 movzwl FILSIZ(r5),r6 /* low 2 bytes file size */
113 insv FILSIZ-1(r5),$16,$8,r6 /* file size, high byte */
114 cmpl r6,$RELOC-512 /* check if file fits below stack */
115 blss filok /* file o.k. */
116 brw start /* file too large */
117/* time to read in desired file from tape */
118filok:
119 movl r6,r7 /* save r6 */
120 bsbb taper
121 bsbw rew
122/* clear core */
123 subl3 r7,$RELOC-4,r0 /* no. bytes to clear */
1241:
125 clrb (r7)+
126 sobgtr r0,1b
127/* time to jump to start of file & execute */
128 addl3 $20,fp,ap
129 clrl r5
130 calls $0,(r5)
131 brw start
132/* taper: movcTAPE (r6),tapa(fp),0 */
133rew2:
134 bsbb rew /* beginning of tape */
135taper0:
136 bsbb rrec /* advance 1 block; never want blk 0 */
137taper:
138 clrl r0 /* page no. */
139 cmpl mtapa(fp),tapa(fp) /* current position .vs. desired */
140 bgtr rew2
141 blss taper0
1421:
143 bsbb rrec
144 acbl $1,$-BLKSIZ,r6,1b
145 rsb
146/* rew: rewind the tape */
147rew:
148 clrl mtapa(fp) /* current position */
149 movw $TSA+rewind,TSDB(%rTS)
150 bsbb tsquiet
151 rsb
152/* rrec: read 1 block from mag tape into page (r0) */
153rrec:
154 /* pushl r0; movzbl $'r,r0; bsbw putc; movl (sp)+,r0; */
155 bisl3 $MRV,r0,UBA_MAP(%rUBA)
156 movw $TS_ACK|TS_CVC|TS_READ,tsread
1571:
158 movw $TSA+tsread,TSDB(%rTS)
159 bsbb tsquiet
160/* bisl2 $BNE,UBA_DPR1(%rUBA) */
161 tstw TSSR(%rTS)
162 bgeq 2f
163 bisw2 $TS_RETRY,tsread
164 brb 1b
1652:
166 incl r0 /* next page no. */
167 incl mtapa(fp) /* mag tape block position */
168 rsb
169tsquiet:
170 tstb TSSR(%rTS)
171 bgeq tsquiet
172 rsb
173getc:
174 mfpr $RXCS,r0
175 bbc $RXCS_pd,r0,getc /* receiver ready ? */
176 mfpr $RXDB,r0
177 extzv $0,$7,r0,r0
178 cmpb r0,$015
179 bneq putc
180 bsbb putc
181 movb $0,r0
182 bsbb putc
183 movb $012,r0
184putc:
185 mfpr $TXCS,r2
186 bbc $TXCS_pr,r2,putc /* transmitter ready ? */
187 extzv $0,$7,r0,r0
188 mtpr r0,$TXDB
189 rsb
190 .align 2
191setchr:
192 .word TS_ACK|TS_CVC|TS_SETCHR
193 .long TSA+char
194 .word 0xe
195char:
196 .long TSA+tsstat
197 .word 0xe
198 .word 0
199tsread:
200 .word TS_ACK|TS_CVC|TS_READ
201 .long 0
202 .word BLKSIZ
203rewind:
204 .word TS_ACK|TS_CVC|TS_REWIND
205 .long 0
206 .word 0
207tsstat:
208 .space 7*2
209end: