Bell 32V development
[unix-history] / usr / src / mdec / mboot.s
CommitLineData
2a08801b
TL
1#
2# Tape boot program to load and transfer
3# to a program on a 9-tr mag tape in
4# UNIX 'tp' format on the VAX machine.
5# This program is the boot block on the mag tape.
6#
7# Entry is made to the desired file via 'calls $0,entrypt'
8# so return can be 'ret'.
9#
10 .set core,50 # assume 50 K words avail.
11 .set BOOBLK,1 # no. tape blocks for boot
12 .set RELOC,0x50000
13 .set HDRSIZ,040 # size of file header for VAX
14 .set MAGIC,0410 # file type id in header
15 .set ENTSIZ,64 # size of 1 TP dir entry, bytes
16 .set PTHSIZ,32 # size of TP path name, bytes
17 .set BLKSIZ,512 # tape block size, bytes
18 .set NUMDIR,24 # no. of dir blocks on tape
19 .set ENTBLK,8 # no. of dir entries per tape block
20 .set NL,012 # new-line char
21 .set CR,015 # carriage-return char
22 .set MAXC,65535 # max. count for 'movc' op
23 .set TSIZ,4 # text size
24 .set DSIZ,8 # data size
25 .set BSIZ,12 # bss size
26 .set TENT,024 # task header entry loc
27#
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#
37 .set FILSIZ,38 # dir offset for file size
38 .set BNUM,44 # dir offset for start block no.
39#
40# MBA registers
41 .set MBA1,0x20012000 # MBA 1 device reg's
42 .set M_cfg,0 # MBA config reg
43 .set M_cr,4 # MBA control reg
44 .set M_stat,8 # MBA status reg
45 .set M_var,12 # MBA virt addr reg
46 .set M_bc,16 # MBA byte count reg
47 .set M_map,0x800 # start of MBA map reg's
48 .set MBAinit,1 # MBA init bit in MBA control reg
49#
50# TM02 registers
51 .set TM02,MBA1+0x400 # start of TM02 reg's
52 .set TM_cs1,0 # TM02 control 1 reg
53 .set TM_ds,4 # status reg
54 .set TM_er,8 # error reg
55 .set TM_as,16 # attention summary
56 .set TM_fc,20 # frame count
57 .set TM_tc,36 # TM02 tape control
58# Function codes for TM02 control reg 1
59 .set GO,1 # GO bit
60 .set RWND,6 # rewind, on-line
61 .set DCLR,010 # drive clear
62 .set SFWD,030 # space forward
63 .set SREV,032 # space reverse
64 .set WRIF,060 # write forward
65 .set REDF,070 # read forward
66# misc bits
67 .set ERR,040000 # composite error bit in status reg
68 .set TCHAR,011700 # drive 0, odd parity, PDP11,
69# 800 BPI NRZ, abort on error - for
70# tape control reg
71 .set DRDY,0200 # TM02/drive ready in status reg
72 .set TM_pd,7 # bit position of TM DRDY bit
73 .set TM_pe,14 # bit position of TM ERROR bit
74#
75 .set tapa,-4 # desired tape addr
76 .set mtapa,-8 # current tape addr
77 .set name,-8-PTHSIZ # operator-typed file name
78#
79 .set rMBA,r10
80 .set rTM,r11
81# system initialization
82init:
83 movl $RELOC,fp # core loc to which to move this program
84 addl3 $name,fp,sp # set stack pointer, leaving room for locals
85 clrl r0
86 cmpl (r0),$MAGIC
87 bneq rel
88 movl $HDRSIZ,r0 # skip header
89rel :
90 movc3 $end,(r0),(fp) # move boot up to relocated position
91 jmp start+RELOC # jump to relocated code
92#
93start :
94 movab *$MBA1,%rMBA
95 movl $MBAinit,M_cr(%rMBA) # MBA initialize
96 movab *$TM02,%rTM
97 movl $TCHAR,TM_tc(%rTM) # drive no., etc.
98 movl $DCLR+GO,TM_cs1(%rTM) # drive clear
99 bsbw rew # rewind input tape
100 movab name(fp),r4 # start of filename storage
101 movzbl $'=,r0 # prompt character
102 bsbw putc # output char to main console
103#
104gfil :
105 movl r4,r1 # loc at which to store user-specified file name
106nxtc :
107 bsbw getc # get input char's in file name
108 cmpb r0,$NL # terminator ?
109 beql nullc
110 cmpb r0,$'@ # r0 = return character
111 beql gfil
112 movb r0,(r1)+
113 cmpb r0,$'#
114 bneq nxtc
115 tstw -(r1) # subl2 $2,r1
116 cmpl r1,r4
117 blss gfil
118 brb nxtc
119nullc:
120 subl3 r4,r1,r9 # size of path name
121 beql start # dumb operator
122#
123# user-specified TP filename has been stored at name(fp)
124#
125# read in entire tp directory contents into low core
126# 'cmpc[35]' instruction uses reg's 0-3
127#
128dirred :
129 movl $BOOBLK,tapa(fp) # desired tape block no.
130 movl $(NUMDIR*BLKSIZ),r6 # no. bytes in total dir
131 bsbw taper # read no. bytes indicated
132#
133# search entire directory for user-specified file name
134 clrl r5 # dir buff loc = 0
135nxtdir :
136 cmpc3 r9,(r5),(r4) # see if dir entry matches filename
137 beql fndfil # found match
138 acbl $NUMDIR*BLKSIZ-1,$ENTSIZ,r5,nxtdir # see if done with tp dir
139#
140 brb start # entry not in directory - start all over
141#
142# found desired tp dir entry
143fndfil :
144 movzwl BNUM(r5),tapa(fp) # start block no., 2 bytes
145 movzwl FILSIZ(r5),r6 # low 2 bytes file size
146 insv FILSIZ-1(r5),$16,$8,r6 # file size, high byte
147 cmpl r6,$RELOC-512 # check if file fits below stack
148 blss filok # file o.k.
149 brw start # file too large
150#
151# time to read in desired file from tape
152filok :
153 movl r6,r7 # save r6
154 bsbb taper
155 bsbw rew
156#
157# if load module header exists, move down rest of load
158# module to 0
159 clrl r5 # entry loc
160 cmpl (r5),$MAGIC # unix a.out?
161 bneq clrcor
162# move start of exec image down to 0
163 clrl r0
164 movq TSIZ(r0),r1 # text size and data size
165 movq BSIZ(r0),r3 # bss size, symbol table size
166 movl TENT(r0),r5 # entry loc
167 movl r7,r6 # restore file size
168movtxt:
169 movb HDRSIZ(r0),(r0)+
170 sobgtr r6,movtxt
171# move data up to page boundary
172 extzv $0,$9,r1,r0 # byte-in-page of last text byte
173 beql clrcor
174 subl3 r0,$512,r0 # room needed
175 addl2 r2,r1 # current end+1 of data
176 addl2 r1,r0 # new end+1 of data
177 movl r0,r7 # start here on bssz clearing
178movdat:
179 movb -(r1),-(r0)
180 sobgtr r2,movdat
181#
182# clear core up to stack
183clrcor :
184 subl3 r7,$RELOC-4,r0 # no. bytes to clear
185clrit :
186 clrb (r7)+
187 sobgtr r0,clrit
188#
189# time to jump to start of file & execute
190 calls $0,(r5)
191 brw start # returned from execution - start all over
192#
193#
194# taper: movcTAPE (r6),tapa(fp),0
195#
196rew2 :
197 bsbb rew # beginning of tape
198taper0:
199 bsbb rrec # advance 1 block; (we never want block 0)
200taper :
201 clrl r0 # SBI page no.
202 cmpl mtapa(fp),tapa(fp) # current position .vs. desired
203 bgtr rew2
204 blss taper0
205rloop :
206 bsbb rrec
207 acbl $1,$-BLKSIZ,r6,rloop
208 rsb
209#
210# subr to read 1 block from mag tape into page (r0)
211#
212rrec :
213 movl TM_ds(%rTM),r2
214 bbc $TM_pd,r2,rrec # TM02 & drive ready ?
215 movl $-BLKSIZ,M_bc(%rMBA) # byte count
216 bisl3 $0x80000000,r0,M_map(%rMBA) # MBA map entry = valid bit + phys page no.
217 clrl M_var(%rMBA) # MBA virt addr reg = map reg no. + byte offset
218 movl $REDF+GO,TM_cs1(%rTM) # read forward
219tmrdy :
220 movl TM_ds(%rTM),r2
221 bbc $TM_pd,r2,tmrdy # TM02 & device ready ?
222 movl TM_er(%rTM),r2
223 bbc $TM_pe,r2,donred # any read errors ?
224 clrl TM_ds(%rTM) # clear status - try to recover
225 mnegl $1,TM_fc(%rTM) # frame count for backspace
226 movl $SREV+GO,TM_cs1(%rTM) # space reverse
227 brb rrec
228donred :
229 incl r0 # next SBI page no.
230 incl mtapa(fp) # mag tape block position
231 rsb
232#
233# subr to rewind mag tape
234#
235rew :
236 movl $RWND+GO,TM_cs1(%rTM) # rewind
237 clrl mtapa(fp) # current position
238 rsb
239#
240# subroutines to do char i-o with main tty console
241#
242getc :
243 mfpr $RXCS,r0
244 bbc $RXCS_pd,r0,getc # receiver ready ?
245 mfpr $RXDB,r0
246 cmpb r0,$CR
247 bneq putc
248 movb $NL,r0
249#
250putc:
251 mfpr $TXCS,r2
252 bbc $TXCS_pr,r2,putc # transmitter ready ?
253 cmpb r0,$NL
254 bneq wbyt
255 movb $CR,r0
256 bsbb putc
257 clrb r0
258 bsbb putc
259 movb $NL,r0
260wbyt :
261 extzv $0,$7,r0,r0
262 mtpr r0,$TXDB
263 rsb
264end :