xref: /csrg-svn/sys/vax/mdec/mtboot.c (revision 29323)
123145Smckusick /*
2*29323Smckusick  * Copyright (c) 1980, 1986 Regents of the University of California.
323145Smckusick  * All rights reserved.  The Berkeley software License Agreement
423145Smckusick  * specifies the terms and conditions for redistribution.
523145Smckusick  */
611092Ssam 
7*29323Smckusick /* "@(#)mtboot.c	7.1 (Berkeley) 06/05/86" */
823145Smckusick 
911092Ssam /*
1011092Ssam  * VAX tape boot block for distribution tapes
1111092Ssam  * works on massbys tu78
1211092Ssam  *
1311092Ssam  * reads a program from a tp directory on a tape and executes it
1411092Ssam  * program must be stripped of the header and is loaded ``bits as is''
1511092Ssam  * you can return to this loader via ``ret'' as you are called ``calls $0,ent''
1611092Ssam  *
1711092Ssam  * Based on similar driver for tm03 formatter.
1811092Ssam  * Local modifications by Jeffrey R. Schwab	June, 1982
1911092Ssam  *				Purdue University Computing Center
2011092Ssam  */
2111092Ssam 	.set	RELOC,0x70000
2211092Ssam /* a.out defines */
2311092Ssam 	.set	HDRSIZ,040	/* size of file header for VAX */
2411092Ssam 	.set	MAGIC,0410	/* file type id in header */
2511092Ssam 	.set	TSIZ,4		/* text size */
2611092Ssam 	.set	DSIZ,8		/* data size */
2711092Ssam 	.set	BSIZ,12		/* bss size */
2811092Ssam 	.set	TENT,024	/* task header entry loc */
2911092Ssam /* tp directory definitions */
3011092Ssam 	.set	FILSIZ,38	/* tp direc offset for file size */
3111092Ssam 	.set	BNUM,44		/* tp dir offset for start block no. */
3211092Ssam 	.set	ENTSIZ,64	/* size of 1 TP dir entry, bytes */
3311092Ssam 	.set	PTHSIZ,32	/* size of TP path name, bytes */
3411092Ssam 	.set	BLKSIZ,512	/* tape block size, bytes */
3511092Ssam 	.set	NUMDIR,24	/* no. of dir blocks on tape */
3611092Ssam 	.set	ENTBLK,8	/* no. of dir entries per tape block */
3711092Ssam /* processor registers and bits */
3811092Ssam 	.set	RXCS,32
3911092Ssam 	.set	RXDB,33
4011092Ssam 	.set	TXCS,34
4111092Ssam 	.set	TXDB,35
4211092Ssam 	.set	RXCS_DONE,0x80
4311092Ssam 	.set	TXCS_RDY,0x80
4411092Ssam 	.set	TXCS_pr,7	/* bit position of TXCS ready bit */
4511092Ssam 	.set	RXCS_pd,7	/* bit position of RXCS done bit */
4611092Ssam /* MBA registers */
4711092Ssam 	.set	MBA_CSR,0	/* configuration and status register */
4811092Ssam 	.set	MBA_CR,4	/* MBA control reg */
4911092Ssam 	.set	MBA_SR,8	/* MBA status reg */
5011092Ssam 	.set	MBA_VAR,12	/* MBA virt addr reg */
5111092Ssam 	.set	MBA_BCR,16	/* MBA byte count reg */
5211092Ssam 	.set	MBA_MAP,0x800	/* start of MBA map reg's */
5311092Ssam 	.set	MRV,0x80000000
5411092Ssam 	.set	MBA_bsy,31	/* massbus busy */
5511092Ssam /* TU78 mba registers */
5611092Ssam 	.set	MTCS,0		/* MT data transfer control reg */
5711092Ssam 	.set	MTER,4		/* data transfer error status reg */
5811092Ssam 	.set	MTRC,8		/* record count */
5911092Ssam 	.set	MTAS,16		/* attention summary */
6011092Ssam 	.set	MTBC,20		/* byte count */
6111092Ssam 	.set	MTNER,44	/* non data transfer error status reg */
6211092Ssam 	.set	MTNCS,48	/* non data transfer control reg */
6311092Ssam 	.set	MTID,68		/* internal data reg */
6411092Ssam /* MT commands */
6511092Ssam 	.set	GO,1		/* GO bit */
6611092Ssam 	.set	MT_REW,6	/* rewind, on-line */
6711092Ssam 	.set	MT_RCOM,070	/* read forward */
6811092Ssam /* MT bits */
6911092Ssam 	.set	MT_rdy,15	/* controller ready */
7011092Ssam 	.set	MT_rec,2	/* bit for single record count */
7111092Ssam 	.set	MT_rcnt,4	/* record count for single record (shifted) */
7211092Ssam 	.set	MT_erc,0xffffffc0	/* error code mask */
7311092Ssam 	.set	MT_done,1	/* proper completion code */
7411092Ssam /* local stack variables */
7511092Ssam 	.set	tapa,-4		/* desired tape addr */
7611092Ssam 	.set	mtapa,-8	/* current tape addr */
7711092Ssam 	.set	name,-8-PTHSIZ	/* operator-typed file name */
7811092Ssam /* register usage */
7911092Ssam 	.set	rMBA,r10
8011092Ssam 	.set	rMT,r11
8111092Ssam 
8211092Ssam /* initialization */
8311092Ssam init:
8411092Ssam 	mull2	$0x80,%rMT
8511092Ssam 	addl2	$0x400,%rMT
8611092Ssam 	addl2	%rMBA,%rMT
8711092Ssam 	movl	$RELOC,fp	/* core loc to which to move this program */
8811092Ssam 	addl3	$name,fp,sp	/* set stack pointer, leaving room for locals */
8911092Ssam 	clrl	r0
9011092Ssam 1:
9111092Ssam 	movc3	$end,(r0),(fp)	/* move boot up to relocated position */
9211092Ssam 	jmp	start+RELOC
9311092Ssam start:
9411092Ssam 	movl	$1,MBA_CR(%rMBA)	/* MBA init */
9511092Ssam 1:
9611092Ssam 	movl	MTID(%rMT),r2		/* wait for tape controller to ready */
9711092Ssam 	bbc	$MT_rdy,r2,1b		/* after massbus init */
9811092Ssam 	bsbw	rew			/* rewind input tape */
9911092Ssam 	movab	name(fp),r4		/* start of filename storage */
10011092Ssam 	movzbl	$'=,r0			/* prompt character */
10111092Ssam 	bsbw	putc			/* output char to main console */
10211092Ssam /* read in a file name */
10311092Ssam 	movl	r4,r1			/* loc at which to store file name */
10411092Ssam nxtc:
10511092Ssam 	bsbw	getc			/* get input char's in file name */
10611092Ssam 	cmpb	r0,$012			/* terminator ? */
10711092Ssam 	beql	nullc
10811092Ssam 	movb	r0,(r1)+
10911092Ssam 	brb	nxtc
11011092Ssam nullc:
11111092Ssam 	subl3	r4,r1,r9		/* size of path name */
11211092Ssam 	beql	start			/* dumb operator */
11311092Ssam 	clrb	(r1)+
11411092Ssam 	incl	r9
11511092Ssam /* user-specified TP filename has been stored at name(fp) */
11611092Ssam /* read in entire tp directory contents into low core */
11711092Ssam dirred:
11811092Ssam 	movl	$8,tapa(fp)		/* tp directory starts at block 8 */
11911092Ssam 	movl	$(NUMDIR*BLKSIZ),r6	/* no. bytes in total dir */
12011092Ssam 	bsbw	taper			/* read no. bytes indicated */
12111092Ssam /* search entire directory for user-specified file name */
12211092Ssam 	clrl	r5			/* dir buff loc = 0 */
12311092Ssam nxtdir:
12411092Ssam 	cmpc3	r9,(r5),(r4)		/* see if dir entry matches filename */
12511092Ssam 	beql	fndfil			/* found match */
12611092Ssam 	acbl	$NUMDIR*BLKSIZ-1,$ENTSIZ,r5,nxtdir
12711092Ssam 					/* see if done with tp dir */
12811092Ssam 	brw	start			/* entry not in directory; start over */
12911092Ssam /* found desired tp dir entry */
13011092Ssam fndfil:
13111092Ssam 	movzwl	BNUM(r5),tapa(fp)	/* start block no., 2 bytes */
13211092Ssam 	addl2	$7,tapa(fp)		/* skip 7 boot blocks */
13311092Ssam 	movzwl	FILSIZ(r5),r6		/* low 2 bytes file size */
13411092Ssam 	insv	FILSIZ-1(r5),$16,$8,r6  /* file size, high byte */
13511092Ssam 	cmpl	r6,$RELOC-512		/* check if file fits below stack */
13611092Ssam 	blss	filok 			/* file o.k. */
13711092Ssam 	brw	start			/* file too large */
13811092Ssam /* time to read in desired file from tape */
13911092Ssam filok:
14011092Ssam 	movl	r6,r7			/* save r6 */
14111092Ssam 	bsbb	taper
14211092Ssam 	bsbw	rew
14311092Ssam /* clear core */
14411092Ssam 	subl3	r7,$RELOC-4,r0		/* no. bytes to clear */
14511092Ssam 1:
14611092Ssam 	clrb	(r7)+
14711092Ssam 	sobgtr	r0,1b
14811092Ssam /* time to jump to start of file & execute */
14911092Ssam 	addl3	$20,fp,ap
15011092Ssam 	clrl	r5
15111092Ssam 	calls	$0,(r5)
15211092Ssam 	brw	start
15311092Ssam /* taper: movcTAPE (r6),tapa(fp),0 */
15411092Ssam rew2:
15511092Ssam 	bsbb	rew			/* beginning of tape */
15611092Ssam taper0:
15711092Ssam 	bsbb	rrec			/* advance 1 block; never want blk0 */
15811092Ssam taper:
15911092Ssam 	clrl	r0			/* page no. */
16011092Ssam 	cmpl	mtapa(fp),tapa(fp)	/* current position .vs. desired */
16111092Ssam 	bgtr	rew2
16211092Ssam 	blss	taper0
16311092Ssam 1:
16411092Ssam 	bsbb	rrec
16511092Ssam 	acbl	$1,$-BLKSIZ,r6,1b
16611092Ssam 	rsb
16711092Ssam /* rew: rewind the tape */
16811092Ssam rew:
16911092Ssam 	clrl	mtapa(fp)		/* current position */
17011092Ssam 	movl	MTNER(%rMT),r2		/* read non-data status */
17111092Ssam  	movl	MTAS(%rMT),MTAS(%rMT)	/* and clear any attention bits */
17211092Ssam 	movl	$MT_REW+GO,MTNCS(%rMT)	/* rewind command and go bit */
17311092Ssam 1:
17411092Ssam 	movl	MTAS(%rMT),r2		/* check attention bits */
17513199Sroot 	beql	1b			/* loop if attention not yet set */
17611092Ssam 	movl	MTNER(%rMT),r2		/* read non-data status */
17711092Ssam 	movl	MTAS(%rMT),MTAS(%rMT)	/* and clear any attention bits */
17811092Ssam 	bicl2	$MT_erc,r2		/* isolate error condition */
17911092Ssam 	subl2	$MT_done,r2		/* check with completion condition */
18011092Ssam 	bneq	1b			/* wait for completion attention */
18111092Ssam 	rsb
18211092Ssam /* rrec: read 1 block from mag tape into page (r0) */
18311092Ssam rrec:
18411092Ssam 	/* pushl r0; movzbl $'r,r0; bsbw putc; movl (sp)+,r0; */
18511092Ssam 	movl	MTNER(%rMT),r2		/* read non-data status */
18611092Ssam 	movl	MTAS(%rMT),MTAS(%rMT)	/* and clear any attention bits */
18711092Ssam 	movl	$-BLKSIZ,MBA_BCR(%rMBA)
18811092Ssam 	bisl3	$MRV,r0,MBA_MAP(%rMBA)
18911092Ssam 	clrl	MBA_VAR(%rMBA)
19011092Ssam 	movl	$BLKSIZ,MTBC(%rMT)	/* set byte count */
19111092Ssam 	bisl2	$MT_rcnt,MTRC(%rMT)	/* set record count */
19211092Ssam 	movl	$MT_RCOM+GO,MTCS(%rMT)	/* load read command */
19311092Ssam 1:
19411092Ssam 	movl	MBA_SR(%rMBA),r2	/* load mba status reg */
19511092Ssam 	bbs	$MBA_bsy,r2,1b		/* wait for mba to go non-busy */
19611092Ssam 	movl	MTRC(%rMT),r2		/* fetch record count */
19711092Ssam 	bbs	$MT_rec,r2,rrec		/* retry read if we did not read a record */
19811092Ssam 	movl	MTER(%rMT),r2		/* load data transfer error status */
19911092Ssam 	bicl2	$MT_erc,r2		/* isolate status value */
20011092Ssam 	subl2	$MT_done,r2		/* compare with successful read */
20111092Ssam 	bneq	rrec			/* load to try read again */
20211092Ssam 
20311092Ssam 	incl	r0			/* next page no. */
20411092Ssam 	incl	mtapa(fp)		/* mag tape block position */
20511092Ssam 	rsb
20611092Ssam getc:
20711092Ssam 	mfpr	$RXCS,r0
20811092Ssam 	bbc	$RXCS_pd,r0,getc	/* receiver ready ? */
20911092Ssam 	mfpr	$RXDB,r0
21011092Ssam 	extzv	$0,$7,r0,r0
21111092Ssam 	cmpb	r0,$015
21211092Ssam 	bneq	putc
21311092Ssam 	bsbb	putc
21411092Ssam 	movb	$0,r0
21511092Ssam 	bsbb	putc
21611092Ssam 	movb	$012,r0
21711092Ssam putc:
21811092Ssam 	mfpr	$TXCS,r2
21911092Ssam 	bbc	$TXCS_pr,r2,putc	/* transmitter ready ? */
22011092Ssam 	extzv	$0,$7,r0,r0
22111092Ssam 	mtpr	r0,$TXDB
22211092Ssam 	rsb
22311092Ssam end:
224