xref: /csrg-svn/sys/vax/mdec/htboot.c (revision 29321)
123143Smckusick /*
2*29321Smckusick  * Copyright (c) 1980, 1986 Regents of the University of California.
323143Smckusick  * All rights reserved.  The Berkeley software License Agreement
423143Smckusick  * specifies the terms and conditions for redistribution.
523143Smckusick  */
611090Ssam 
7*29321Smckusick /* "@(#)htboot.c	7.1 (Berkeley) 06/05/86" */
823143Smckusick 
923143Smckusick 
1011090Ssam /*
1111090Ssam  * VAX tape boot block for distribution tapes
1211090Ssam  * works on massbus tu10/te16/tu45/tu77
1311090Ssam  *
1411090Ssam  * reads a program from a tp directory on a tape and executes it
1511090Ssam  * program must be stripped of the header and is loaded ``bits as is''
1611090Ssam  * you can return to this loader via ``ret'' as you are called ``calls $0,ent''
1711090Ssam  */
1811090Ssam 	.set	RELOC,0x70000
1911090Ssam /* a.out defines */
2011090Ssam 	.set	HDRSIZ,040	/* size of file header for VAX */
2111090Ssam 	.set	MAGIC,0410	/* file type id in header */
2211090Ssam 	.set	TSIZ,4		/* text size */
2311090Ssam 	.set	DSIZ,8		/* data size */
2411090Ssam 	.set	BSIZ,12		/* bss size */
2511090Ssam 	.set	TENT,024	/* task header entry loc */
2611090Ssam /* tp directory definitions */
2711090Ssam 	.set	FILSIZ,38	/* tp direc offset for file size */
2811090Ssam 	.set	BNUM,44		/* tp dir offset for start block no. */
2911090Ssam 	.set	ENTSIZ,64	/* size of 1 TP dir entry, bytes */
3011090Ssam 	.set	PTHSIZ,32	/* size of TP path name, bytes */
3111090Ssam 	.set	BLKSIZ,512	/* tape block size, bytes */
3211090Ssam 	.set	NUMDIR,24	/* no. of dir blocks on tape */
3311090Ssam 	.set	ENTBLK,8	/* no. of dir entries per tape block */
3411090Ssam /* processor registers and bits */
3511090Ssam 	.set	RXCS,32
3611090Ssam 	.set	RXDB,33
3711090Ssam 	.set	TXCS,34
3811090Ssam 	.set	TXDB,35
3911090Ssam 	.set	RXCS_DONE,0x80
4011090Ssam 	.set	TXCS_RDY,0x80
4111090Ssam 	.set	TXCS_pr,7	/* bit position of TXCS ready bit */
4211090Ssam 	.set	RXCS_pd,7	/* bit position of RXCS done bit */
4311090Ssam /* MBA registers */
4411090Ssam 	.set	MBA_CSR,0	/* configuration and status register */
4511090Ssam 	.set	MBA_CR,4	/* MBA control reg */
4611090Ssam 	.set	MBA_SR,8	/* MBA status reg */
4711090Ssam 	.set	MBA_VAR,12	/* MBA virt addr reg */
4811090Ssam 	.set	MBA_BCR,16	/* MBA byte count reg */
4911090Ssam 	.set	MBA_MAP,0x800	/* start of MBA map reg's */
5011090Ssam 	.set	MRV,0x80000000
5111090Ssam /* TE16/TU45/TU77 mba registers */
5211090Ssam 	.set	HTCS1,0		/* HT control 1 reg */
5311090Ssam 	.set	HTDS,4		/* status reg */
5411090Ssam 	.set	HTER,8		/* error reg */
5511090Ssam 	.set	HTAS,16		/* attention summary */
5611090Ssam 	.set	HTFC,20		/* frame count */
5711090Ssam 	.set	HTTC,36		/* HT tape control */
5811090Ssam /* HT commands */
5911090Ssam 	.set	GO,1		/* GO bit */
6011090Ssam 	.set	HT_REW,6	/* rewind, on-line */
6111090Ssam 	.set	HT_DCLR,010	/* drive clear */
6211090Ssam 	.set	HT_SREV,032	/* space reverse */
6311090Ssam 	.set	HT_RCOM,070	/* read forward */
6411090Ssam /* HT bits */
6511090Ssam 	.set	ERR,040000 	/* composite error bit in status reg */
6611090Ssam 	.set	TCHAR,012300 	/* unit 0, odd parity, PDP11, 1600 BPI NRZ, */
6711090Ssam 				/* abort on error - for tape controller */
6811090Ssam 	.set	DRDY,0200	/* HT/drive ready in status reg */
6911090Ssam 	.set	HT_pd,7 	/* bit position of HT DRDY bit */
7011090Ssam 	.set	HT_pe,14	/* bit position of HT ERROR bit */
7111090Ssam /* local stack variables */
7211090Ssam 	.set	tapa,-4		/* desired tape addr */
7311090Ssam 	.set	mtapa,-8	/* current tape addr */
7411090Ssam 	.set	name,-8-PTHSIZ	/* operator-typed file name */
7511090Ssam /* register usage */
7611090Ssam 	.set	rMBA,r10
7711090Ssam 	.set	rHT,r11
7811090Ssam 
7911090Ssam /* initialization */
8011090Ssam init:
8111090Ssam 	mull2	$0x80,%rHT
8211090Ssam 	addl2	$0x400,%rHT
8311090Ssam 	addl2	%rMBA,%rHT
8411090Ssam 	movl	$RELOC,fp	/* core loc to which to move this program */
8511090Ssam 	addl3	$name,fp,sp	/* set stack pointer, leaving room for locals */
8611090Ssam 	clrl	r0
8711090Ssam 1:
8811090Ssam 	movc3	$end,(r0),(fp)	/* move boot up to relocated position */
8911090Ssam 	jmp	start+RELOC
9011090Ssam start:
9111090Ssam 	movl	$1,MBA_CR(%rMBA)	/* MBA init */
9211090Ssam 	movl	$TCHAR,HTTC(%rHT)	/* drive no., etc. */
9311090Ssam 	movl	$HT_DCLR+GO,HTCS1(%rHT)	/* drive clear */
9411090Ssam 	bsbw	rew			/* rewind input tape */
9511090Ssam 	movab	name(fp),r4		/* start of filename storage */
9611090Ssam 	movzbl	$'=,r0			/* prompt character */
9711090Ssam 	bsbw	putc			/* output char to main console */
9811090Ssam /* read in a file name */
9911090Ssam 	movl	r4,r1			/* loc at which to store file name */
10011090Ssam nxtc:
10111090Ssam 	bsbw	getc			/* get input char's in file name */
10211090Ssam 	cmpb	r0,$012			/* terminator ? */
10311090Ssam 	beql	nullc
10411090Ssam 	movb	r0,(r1)+
10511090Ssam 	brb	nxtc
10611090Ssam nullc:
10711090Ssam 	subl3	r4,r1,r9		/* size of path name */
10811090Ssam 	beql	start			/* dumb operator */
10911090Ssam 	clrb	(r1)+
11011090Ssam 	incl	r9
11111090Ssam /* user-specified TP filename has been stored at name(fp) */
11211090Ssam /* read in entire tp directory contents into low core */
11311090Ssam dirred:
11411090Ssam 	movl	$8,tapa(fp)		/* tp directory starts at block 8 */
11511090Ssam 	movl	$(NUMDIR*BLKSIZ),r6	/* no. bytes in total dir */
11611090Ssam 	bsbw	taper			/* read no. bytes indicated */
11711090Ssam /* search entire directory for user-specified file name */
11811090Ssam 	clrl	r5			/* dir buff loc = 0 */
11911090Ssam nxtdir:
12011090Ssam 	cmpc3	r9,(r5),(r4)		/* see if dir entry matches filename */
12111090Ssam 	beql	fndfil			/* found match */
12211090Ssam 	acbl	$NUMDIR*BLKSIZ-1,$ENTSIZ,r5,nxtdir
12311090Ssam 					/* see if done with tp dir */
12411090Ssam 	brw	start			/* entry not in directory; start over */
12511090Ssam /* found desired tp dir entry */
12611090Ssam fndfil:
12711090Ssam 	movzwl	BNUM(r5),tapa(fp)	/* start block no., 2 bytes */
12811090Ssam 	addl2	$7,tapa(fp)		/* skip 7 boot blocks */
12911090Ssam 	movzwl	FILSIZ(r5),r6		/* low 2 bytes file size */
13011090Ssam 	insv	FILSIZ-1(r5),$16,$8,r6  /* file size, high byte */
13111090Ssam 	cmpl	r6,$RELOC-512		/* check if file fits below stack */
13211090Ssam 	blss	filok 			/* file o.k. */
13311090Ssam 	brw	start			/* file too large */
13411090Ssam /* time to read in desired file from tape */
13511090Ssam filok:
13611090Ssam 	movl	r6,r7			/* save r6 */
13711090Ssam 	bsbb	taper
13811090Ssam 	bsbw	rew
13911090Ssam /* clear core */
14011090Ssam 	subl3	r7,$RELOC-4,r0		/* no. bytes to clear */
14111090Ssam 1:
14211090Ssam 	clrb	(r7)+
14311090Ssam 	sobgtr	r0,1b
14411090Ssam /* time to jump to start of file & execute */
14511090Ssam 	addl3	$20,fp,ap
14611090Ssam 	clrl	r5
14711090Ssam 	calls	$0,(r5)
14811090Ssam 	brw	start
14911090Ssam /* taper: movcTAPE (r6),tapa(fp),0 */
15011090Ssam rew2:
15111090Ssam 	bsbb	rew			/* beginning of tape */
15211090Ssam taper0:
15311090Ssam 	bsbb	rrec			/* advance 1 block; never want blk0 */
15411090Ssam taper:
15511090Ssam 	clrl	r0			/* page no. */
15611090Ssam 	cmpl	mtapa(fp),tapa(fp)	/* current position .vs. desired */
15711090Ssam 	bgtr	rew2
15811090Ssam 	blss	taper0
15911090Ssam 1:
16011090Ssam 	bsbb	rrec
16111090Ssam 	acbl	$1,$-BLKSIZ,r6,1b
16211090Ssam 	rsb
16311090Ssam /* rew: rewind the tape */
16411090Ssam rew:
16511090Ssam 	clrl	mtapa(fp)		/* current position */
16611090Ssam 	movl	$HT_REW+GO,HTCS1(%rHT)  /* rewind */
16711090Ssam 	rsb
16811090Ssam /* rrec: read 1 block from mag tape into page (r0) */
16911090Ssam rrec:
17011090Ssam 	/* pushl r0; movzbl $'r,r0; bsbw putc; movl (sp)+,r0; */
17111090Ssam 	movl	HTDS(%rHT),r2
17211090Ssam 	bbc	$HT_pd,r2,rrec		/* HT & drive ready ? */
17311090Ssam 	movl	$-BLKSIZ,MBA_BCR(%rMBA)
17411090Ssam 	bisl3	$MRV,r0,MBA_MAP(%rMBA)
17511090Ssam 	clrl	MBA_VAR(%rMBA)
17611090Ssam 	movl	$HT_RCOM+GO,HTCS1(%rHT)	/* read forward */
17711090Ssam 1:
17811090Ssam 	movl	HTDS(%rHT),r2
17911090Ssam 	bbc	$HT_pd,r2,1b
18011090Ssam 	movl	HTER(%rHT),r2
18111090Ssam 	bbc	$HT_pe,r2,2f		/* any read errors ? */
18211090Ssam 	clrl	HTDS(%rHT)		/* clear status - try to recover */
18311090Ssam 	mnegl	$1,HTFC(%rHT)		/* frame count for backspace */
18411090Ssam 	movl	$HT_SREV+GO,HTCS1(%rHT)	/* space reverse */
18511090Ssam 	brb	rrec
18611090Ssam 2:
18711090Ssam 	incl	r0			/* next page no. */
18811090Ssam 	incl	mtapa(fp)		/* mag tape block position */
18911090Ssam 	rsb
19011090Ssam getc:
19111090Ssam 	mfpr	$RXCS,r0
19211090Ssam 	bbc	$RXCS_pd,r0,getc	/* receiver ready ? */
19311090Ssam 	mfpr	$RXDB,r0
19411090Ssam 	extzv	$0,$7,r0,r0
19511090Ssam 	cmpb	r0,$015
19611090Ssam 	bneq	putc
19711090Ssam 	bsbb	putc
19811090Ssam 	movb	$0,r0
19911090Ssam 	bsbb	putc
20011090Ssam 	movb	$012,r0
20111090Ssam putc:
20211090Ssam 	mfpr	$TXCS,r2
20311090Ssam 	bbc	$TXCS_pr,r2,putc	/* transmitter ready ? */
20411090Ssam 	extzv	$0,$7,r0,r0
20511090Ssam 	mtpr	r0,$TXDB
20611090Ssam 	rsb
20711090Ssam end:
208