1dfb0193eSmckusick /* 2*6ef710fcSmckusick * Copyright (c) 1980, 1986 Regents of the University of California. 3dfb0193eSmckusick * All rights reserved. The Berkeley software License Agreement 4dfb0193eSmckusick * specifies the terms and conditions for redistribution. 5dfb0193eSmckusick */ 6dfb0193eSmckusick 7*6ef710fcSmckusick /* "@(#)mtboot.c 7.1 (Berkeley) 06/05/86" */ 8a68aee57Ssam 9a68aee57Ssam /* 10a68aee57Ssam * VAX tape boot block for distribution tapes 11a68aee57Ssam * works on massbys tu78 12a68aee57Ssam * 13a68aee57Ssam * reads a program from a tp directory on a tape and executes it 14a68aee57Ssam * program must be stripped of the header and is loaded ``bits as is'' 15a68aee57Ssam * you can return to this loader via ``ret'' as you are called ``calls $0,ent'' 16a68aee57Ssam * 17a68aee57Ssam * Based on similar driver for tm03 formatter. 18a68aee57Ssam * Local modifications by Jeffrey R. Schwab June, 1982 19a68aee57Ssam * Purdue University Computing Center 20a68aee57Ssam */ 21a68aee57Ssam .set RELOC,0x70000 22a68aee57Ssam /* a.out defines */ 23a68aee57Ssam .set HDRSIZ,040 /* size of file header for VAX */ 24a68aee57Ssam .set MAGIC,0410 /* file type id in header */ 25a68aee57Ssam .set TSIZ,4 /* text size */ 26a68aee57Ssam .set DSIZ,8 /* data size */ 27a68aee57Ssam .set BSIZ,12 /* bss size */ 28a68aee57Ssam .set TENT,024 /* task header entry loc */ 29a68aee57Ssam /* tp directory definitions */ 30a68aee57Ssam .set FILSIZ,38 /* tp direc offset for file size */ 31a68aee57Ssam .set BNUM,44 /* tp dir offset for start block no. */ 32a68aee57Ssam .set ENTSIZ,64 /* size of 1 TP dir entry, bytes */ 33a68aee57Ssam .set PTHSIZ,32 /* size of TP path name, bytes */ 34a68aee57Ssam .set BLKSIZ,512 /* tape block size, bytes */ 35a68aee57Ssam .set NUMDIR,24 /* no. of dir blocks on tape */ 36a68aee57Ssam .set ENTBLK,8 /* no. of dir entries per tape block */ 37a68aee57Ssam /* processor registers and bits */ 38a68aee57Ssam .set RXCS,32 39a68aee57Ssam .set RXDB,33 40a68aee57Ssam .set TXCS,34 41a68aee57Ssam .set TXDB,35 42a68aee57Ssam .set RXCS_DONE,0x80 43a68aee57Ssam .set TXCS_RDY,0x80 44a68aee57Ssam .set TXCS_pr,7 /* bit position of TXCS ready bit */ 45a68aee57Ssam .set RXCS_pd,7 /* bit position of RXCS done bit */ 46a68aee57Ssam /* MBA registers */ 47a68aee57Ssam .set MBA_CSR,0 /* configuration and status register */ 48a68aee57Ssam .set MBA_CR,4 /* MBA control reg */ 49a68aee57Ssam .set MBA_SR,8 /* MBA status reg */ 50a68aee57Ssam .set MBA_VAR,12 /* MBA virt addr reg */ 51a68aee57Ssam .set MBA_BCR,16 /* MBA byte count reg */ 52a68aee57Ssam .set MBA_MAP,0x800 /* start of MBA map reg's */ 53a68aee57Ssam .set MRV,0x80000000 54a68aee57Ssam .set MBA_bsy,31 /* massbus busy */ 55a68aee57Ssam /* TU78 mba registers */ 56a68aee57Ssam .set MTCS,0 /* MT data transfer control reg */ 57a68aee57Ssam .set MTER,4 /* data transfer error status reg */ 58a68aee57Ssam .set MTRC,8 /* record count */ 59a68aee57Ssam .set MTAS,16 /* attention summary */ 60a68aee57Ssam .set MTBC,20 /* byte count */ 61a68aee57Ssam .set MTNER,44 /* non data transfer error status reg */ 62a68aee57Ssam .set MTNCS,48 /* non data transfer control reg */ 63a68aee57Ssam .set MTID,68 /* internal data reg */ 64a68aee57Ssam /* MT commands */ 65a68aee57Ssam .set GO,1 /* GO bit */ 66a68aee57Ssam .set MT_REW,6 /* rewind, on-line */ 67a68aee57Ssam .set MT_RCOM,070 /* read forward */ 68a68aee57Ssam /* MT bits */ 69a68aee57Ssam .set MT_rdy,15 /* controller ready */ 70a68aee57Ssam .set MT_rec,2 /* bit for single record count */ 71a68aee57Ssam .set MT_rcnt,4 /* record count for single record (shifted) */ 72a68aee57Ssam .set MT_erc,0xffffffc0 /* error code mask */ 73a68aee57Ssam .set MT_done,1 /* proper completion code */ 74a68aee57Ssam /* local stack variables */ 75a68aee57Ssam .set tapa,-4 /* desired tape addr */ 76a68aee57Ssam .set mtapa,-8 /* current tape addr */ 77a68aee57Ssam .set name,-8-PTHSIZ /* operator-typed file name */ 78a68aee57Ssam /* register usage */ 79a68aee57Ssam .set rMBA,r10 80a68aee57Ssam .set rMT,r11 81a68aee57Ssam 82a68aee57Ssam /* initialization */ 83a68aee57Ssam init: 84a68aee57Ssam mull2 $0x80,%rMT 85a68aee57Ssam addl2 $0x400,%rMT 86a68aee57Ssam addl2 %rMBA,%rMT 87a68aee57Ssam movl $RELOC,fp /* core loc to which to move this program */ 88a68aee57Ssam addl3 $name,fp,sp /* set stack pointer, leaving room for locals */ 89a68aee57Ssam clrl r0 90a68aee57Ssam 1: 91a68aee57Ssam movc3 $end,(r0),(fp) /* move boot up to relocated position */ 92a68aee57Ssam jmp start+RELOC 93a68aee57Ssam start: 94a68aee57Ssam movl $1,MBA_CR(%rMBA) /* MBA init */ 95a68aee57Ssam 1: 96a68aee57Ssam movl MTID(%rMT),r2 /* wait for tape controller to ready */ 97a68aee57Ssam bbc $MT_rdy,r2,1b /* after massbus init */ 98a68aee57Ssam bsbw rew /* rewind input tape */ 99a68aee57Ssam movab name(fp),r4 /* start of filename storage */ 100a68aee57Ssam movzbl $'=,r0 /* prompt character */ 101a68aee57Ssam bsbw putc /* output char to main console */ 102a68aee57Ssam /* read in a file name */ 103a68aee57Ssam movl r4,r1 /* loc at which to store file name */ 104a68aee57Ssam nxtc: 105a68aee57Ssam bsbw getc /* get input char's in file name */ 106a68aee57Ssam cmpb r0,$012 /* terminator ? */ 107a68aee57Ssam beql nullc 108a68aee57Ssam movb r0,(r1)+ 109a68aee57Ssam brb nxtc 110a68aee57Ssam nullc: 111a68aee57Ssam subl3 r4,r1,r9 /* size of path name */ 112a68aee57Ssam beql start /* dumb operator */ 113a68aee57Ssam clrb (r1)+ 114a68aee57Ssam incl r9 115a68aee57Ssam /* user-specified TP filename has been stored at name(fp) */ 116a68aee57Ssam /* read in entire tp directory contents into low core */ 117a68aee57Ssam dirred: 118a68aee57Ssam movl $8,tapa(fp) /* tp directory starts at block 8 */ 119a68aee57Ssam movl $(NUMDIR*BLKSIZ),r6 /* no. bytes in total dir */ 120a68aee57Ssam bsbw taper /* read no. bytes indicated */ 121a68aee57Ssam /* search entire directory for user-specified file name */ 122a68aee57Ssam clrl r5 /* dir buff loc = 0 */ 123a68aee57Ssam nxtdir: 124a68aee57Ssam cmpc3 r9,(r5),(r4) /* see if dir entry matches filename */ 125a68aee57Ssam beql fndfil /* found match */ 126a68aee57Ssam acbl $NUMDIR*BLKSIZ-1,$ENTSIZ,r5,nxtdir 127a68aee57Ssam /* see if done with tp dir */ 128a68aee57Ssam brw start /* entry not in directory; start over */ 129a68aee57Ssam /* found desired tp dir entry */ 130a68aee57Ssam fndfil: 131a68aee57Ssam movzwl BNUM(r5),tapa(fp) /* start block no., 2 bytes */ 132a68aee57Ssam addl2 $7,tapa(fp) /* skip 7 boot blocks */ 133a68aee57Ssam movzwl FILSIZ(r5),r6 /* low 2 bytes file size */ 134a68aee57Ssam insv FILSIZ-1(r5),$16,$8,r6 /* file size, high byte */ 135a68aee57Ssam cmpl r6,$RELOC-512 /* check if file fits below stack */ 136a68aee57Ssam blss filok /* file o.k. */ 137a68aee57Ssam brw start /* file too large */ 138a68aee57Ssam /* time to read in desired file from tape */ 139a68aee57Ssam filok: 140a68aee57Ssam movl r6,r7 /* save r6 */ 141a68aee57Ssam bsbb taper 142a68aee57Ssam bsbw rew 143a68aee57Ssam /* clear core */ 144a68aee57Ssam subl3 r7,$RELOC-4,r0 /* no. bytes to clear */ 145a68aee57Ssam 1: 146a68aee57Ssam clrb (r7)+ 147a68aee57Ssam sobgtr r0,1b 148a68aee57Ssam /* time to jump to start of file & execute */ 149a68aee57Ssam addl3 $20,fp,ap 150a68aee57Ssam clrl r5 151a68aee57Ssam calls $0,(r5) 152a68aee57Ssam brw start 153a68aee57Ssam /* taper: movcTAPE (r6),tapa(fp),0 */ 154a68aee57Ssam rew2: 155a68aee57Ssam bsbb rew /* beginning of tape */ 156a68aee57Ssam taper0: 157a68aee57Ssam bsbb rrec /* advance 1 block; never want blk0 */ 158a68aee57Ssam taper: 159a68aee57Ssam clrl r0 /* page no. */ 160a68aee57Ssam cmpl mtapa(fp),tapa(fp) /* current position .vs. desired */ 161a68aee57Ssam bgtr rew2 162a68aee57Ssam blss taper0 163a68aee57Ssam 1: 164a68aee57Ssam bsbb rrec 165a68aee57Ssam acbl $1,$-BLKSIZ,r6,1b 166a68aee57Ssam rsb 167a68aee57Ssam /* rew: rewind the tape */ 168a68aee57Ssam rew: 169a68aee57Ssam clrl mtapa(fp) /* current position */ 170a68aee57Ssam movl MTNER(%rMT),r2 /* read non-data status */ 171a68aee57Ssam movl MTAS(%rMT),MTAS(%rMT) /* and clear any attention bits */ 172a68aee57Ssam movl $MT_REW+GO,MTNCS(%rMT) /* rewind command and go bit */ 173a68aee57Ssam 1: 174a68aee57Ssam movl MTAS(%rMT),r2 /* check attention bits */ 175b6392066Sroot beql 1b /* loop if attention not yet set */ 176a68aee57Ssam movl MTNER(%rMT),r2 /* read non-data status */ 177a68aee57Ssam movl MTAS(%rMT),MTAS(%rMT) /* and clear any attention bits */ 178a68aee57Ssam bicl2 $MT_erc,r2 /* isolate error condition */ 179a68aee57Ssam subl2 $MT_done,r2 /* check with completion condition */ 180a68aee57Ssam bneq 1b /* wait for completion attention */ 181a68aee57Ssam rsb 182a68aee57Ssam /* rrec: read 1 block from mag tape into page (r0) */ 183a68aee57Ssam rrec: 184a68aee57Ssam /* pushl r0; movzbl $'r,r0; bsbw putc; movl (sp)+,r0; */ 185a68aee57Ssam movl MTNER(%rMT),r2 /* read non-data status */ 186a68aee57Ssam movl MTAS(%rMT),MTAS(%rMT) /* and clear any attention bits */ 187a68aee57Ssam movl $-BLKSIZ,MBA_BCR(%rMBA) 188a68aee57Ssam bisl3 $MRV,r0,MBA_MAP(%rMBA) 189a68aee57Ssam clrl MBA_VAR(%rMBA) 190a68aee57Ssam movl $BLKSIZ,MTBC(%rMT) /* set byte count */ 191a68aee57Ssam bisl2 $MT_rcnt,MTRC(%rMT) /* set record count */ 192a68aee57Ssam movl $MT_RCOM+GO,MTCS(%rMT) /* load read command */ 193a68aee57Ssam 1: 194a68aee57Ssam movl MBA_SR(%rMBA),r2 /* load mba status reg */ 195a68aee57Ssam bbs $MBA_bsy,r2,1b /* wait for mba to go non-busy */ 196a68aee57Ssam movl MTRC(%rMT),r2 /* fetch record count */ 197a68aee57Ssam bbs $MT_rec,r2,rrec /* retry read if we did not read a record */ 198a68aee57Ssam movl MTER(%rMT),r2 /* load data transfer error status */ 199a68aee57Ssam bicl2 $MT_erc,r2 /* isolate status value */ 200a68aee57Ssam subl2 $MT_done,r2 /* compare with successful read */ 201a68aee57Ssam bneq rrec /* load to try read again */ 202a68aee57Ssam 203a68aee57Ssam incl r0 /* next page no. */ 204a68aee57Ssam incl mtapa(fp) /* mag tape block position */ 205a68aee57Ssam rsb 206a68aee57Ssam getc: 207a68aee57Ssam mfpr $RXCS,r0 208a68aee57Ssam bbc $RXCS_pd,r0,getc /* receiver ready ? */ 209a68aee57Ssam mfpr $RXDB,r0 210a68aee57Ssam extzv $0,$7,r0,r0 211a68aee57Ssam cmpb r0,$015 212a68aee57Ssam bneq putc 213a68aee57Ssam bsbb putc 214a68aee57Ssam movb $0,r0 215a68aee57Ssam bsbb putc 216a68aee57Ssam movb $012,r0 217a68aee57Ssam putc: 218a68aee57Ssam mfpr $TXCS,r2 219a68aee57Ssam bbc $TXCS_pr,r2,putc /* transmitter ready ? */ 220a68aee57Ssam extzv $0,$7,r0,r0 221a68aee57Ssam mtpr r0,$TXDB 222a68aee57Ssam rsb 223a68aee57Ssam end: 224