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