1187
|
1 ********************************************************************
|
|
2 * Boot - Eliminator WD1002-05 Boot Module
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * WD 1002-05 OS-9 Boot Subroutine (called by OS9p1)
|
|
7 * Copyright 1988, 1989 Bruce Isted
|
|
8 * All Rights Reserved
|
|
9 *
|
|
10 * Ed. Comments Who YY/MM/DD
|
|
11 * ------------------------------------------------------------------
|
|
12 * 2 Created by Bruce Isted BRI ??/??/??
|
|
13
|
|
14 nam Boot
|
|
15 ttl Eliminator WD1002-05 Boot Module
|
|
16
|
|
17 * These equates should be set before assembly:
|
|
18 FDStep equ $09 see Step Rate Table
|
|
19 HDStep equ $0F see step rate table
|
|
20
|
|
21 *Step Rate Table:
|
|
22 *+------------------+------------------+------------------+------------------+
|
|
23 *! Value=FD/HD Rate ! Value=FD/HD Rate ! Value=FD/HD Rate ! Value=FD/HD Rate !
|
|
24 *+------------------+------------------+------------------+------------------+
|
|
25 *! $00=40mS/7.5mS ! $04=16mS/5.5mS ! $08=08mS/3.5mS ! $0C=03mS/1.5mS !
|
|
26 *! $01=25mS/7.0mS ! $05=14mS/5.0mS ! $09=06mS/3.0mS ! $0D=02mS/1.0mS !
|
|
27 *! $02=20mS/6.5mS ! $06=12mS/4.5mS ! $0A=05mS/2.5mS ! $0E=01mS/0.5mS !
|
|
28 *! $03=18mS/6.0mS ! $07=10mS/4.0mS ! $0B=04mS/2.0mS ! $0F=15uS/ 35uS !
|
|
29 *+------------------+------------------+------------------+------------------+
|
|
30
|
|
31 ifp1
|
|
32 use defsfile
|
|
33 use rbfdefs
|
|
34 endc
|
|
35
|
|
36 * These equates should not have to be changed:
|
|
37 BEdtn equ 2
|
|
38 BVrsn equ 1
|
|
39 MaxCyls equ 1024 maximum cylinders supported
|
|
40 MaxHeads equ 16 maximum heads supported
|
|
41 MaxSctrs equ 64 maximum sectors per track supported
|
|
42 PhysDrv0 equ %10000000 SDH register mask for HD0
|
|
43 PhysDrv1 equ %10001000 SDH register mask for HD1
|
|
44 PhysDrv2 equ %10010000 SDH register mask for HD2
|
|
45 PhysDrv3 equ %00011000 SDH register mask for FD0
|
|
46 PhysDrv4 equ %00011010 SDH register mask for FD1
|
|
47 PhysDrv5 equ %00011100 SDH register mask for FD2
|
|
48 PhysDrv6 equ %00011110 SDH register mask for FD3
|
|
49 ReadSctr equ %00100000 read sector command
|
|
50 Restore equ %00010000 base restore command
|
|
51 SelfTest equ %10010000 WD 1002-05 diagnostic test command
|
|
52
|
|
53 * HCA memory map:
|
|
54 org 0
|
|
55 WDData rmb 2 WD 1002-05 sector buffer/task files
|
|
56 rmb 2 reserved - do not use
|
|
57 PA equ . PIA PA offset
|
|
58 DDRA rmb 1 PIA DDRA offset
|
|
59 CRA rmb 1 PIA CRA offset
|
|
60 PB equ . PIA PB offset
|
|
61 DDRB rmb 1 PIA DDRB offset
|
|
62 CRB rmb 1 PIA CRB offset
|
|
63
|
|
64 * WD 1002-05 register definitions:
|
|
65 org 0
|
|
66 WDBuff rmb 1 WD 1002-05 sector buffer address
|
|
67 ErrReg equ . error register address (read)
|
|
68 WPCReg rmb 1 write precomp register address (write)
|
|
69 SctrCnt rmb 1 sector count register address
|
|
70 SctrReg rmb 1 sector number register address
|
|
71 CylLow rmb 1 cylinder LSB register address
|
|
72 CylHigh rmb 1 cylinder MSB register address
|
|
73 SDHReg rmb 1 Size/Drive/Head register address
|
|
74 StatReg equ . status register address (read)
|
|
75 CmdReg rmb 1 command register address (write)
|
|
76
|
|
77 org 0
|
|
78 U.BSZ rmb 2 boot file size
|
|
79 U.BSct rmb 1 number of sectors in boot file
|
|
80 U.BT rmb 3 boot file start LSN
|
|
81 U.BtStrt rmb 2 boot file start address
|
|
82 U.CrtCyl rmb 2 current cylinder number
|
|
83 U.CrtSct rmb 1 current sector number
|
|
84 U.CrtSid rmb 1 current side (head) number
|
|
85 U.Restor rmb 1 restore command incl. step rate code
|
|
86 U.SDH rmb 1 base WD Size/Drive/Head register copy
|
|
87 U.Sides rmb 1 number of disk sides (heads)
|
|
88 U.SPC rmb 2 sectors per cylinder
|
|
89 U.SPT rmb 2 sectors per track
|
|
90 U.StSctr rmb 1 start sector number (HD=0, FD=1)
|
|
91 BootMem equ .
|
|
92
|
|
93 mod BEnd,BNam,Systm+Objct,ReEnt+BVrsn,BExec,$00
|
|
94 BNam fcs "Boot"
|
|
95 fcb BEdtn edition number
|
|
96
|
|
97 * base SDH register table
|
|
98 SDHTable equ *
|
|
99 fcb PhysDrv0,PhysDrv1,PhysDrv2 base SDH for hard drives
|
|
100 fcb PhysDrv3,PhysDrv4,PhysDrv5,PhysDrv6 base SDH for floppys
|
|
101 ***
|
|
102 * Boot subroutine module
|
|
103 *
|
|
104 * INPUT: none
|
|
105 *
|
|
106 * OUTPUT: [D]=size of bootstrap file
|
|
107 * [X]=start address of bootstrap file in memory
|
|
108 * y,u registers altered
|
|
109 *
|
|
110 * ERROR OUTPUT: [CC]=carry set
|
|
111 * [B]=error code
|
|
112 BExec ldy <D.WDAddr get HCA base address (set by auto-boot EPROM)
|
|
113 cmpy #$FF40 base address too low?
|
|
114 blo UnitErr yes, go report error...
|
|
115 cmpy #$FF7F base address too high?
|
|
116 bhi UnitErr yes, go report error...
|
|
117 lda <D.WDBtDr get boot drive number (set by auto-boot EPROM
|
|
118 cmpa #$07 legal drive number?
|
|
119 blo InitPIA yes, go initialize PIA...
|
|
120 UnitErr ldb #E$Unit
|
|
121 coma
|
|
122 rts
|
|
123
|
|
124 DumpRead clr PB,y set WD address to sector buffer
|
|
125 DumpR0 lda WDData,y get a byte from WD sector buffer
|
|
126 decb done yet?
|
|
127 bne DumpR0 no, go dump another byte
|
|
128 rts
|
|
129 LSN0Info ldb #DD.FMT load number of bytes to dump
|
|
130 bsr DumpRead go dump LSN0 up to DD.FMT
|
|
131 lda WDData,y get DD.FMT (disk density, sides)
|
|
132 anda #$01 mask out all but disk sides bit
|
|
133 inca correction to bit coding
|
|
134 sta U.Sides,u save disk sides (not valid if HD > 2 heads)
|
|
135 ldd WDData,y get DD.SPT (sectors per track)
|
|
136 std U.SPT,u
|
|
137 ldb #DD.BT-DD.RES load number of bytes to dump
|
|
138 bsr DumpRead go dump LSN0 from DD.RES to DD.BT
|
|
139 lda WDData,y get DD.BT (boot file start LSN) MSB
|
|
140 sta U.BT,u
|
|
141 ldd WDData,y get DD.BT (boot file start LSN) LSBs
|
|
142 std U.BT+1,u
|
|
143 ldd WDData,y get DD.BSZ (boot file size)
|
|
144 std U.BSZ,u
|
|
145 ldb U.StSctr,u floppy drive? (start sector = 1)
|
|
146 bne GotInfo yes, sides info OK, go return
|
|
147 ldb #DD.OPT+(PD.SID-PD.OPT)-DD.DAT load number of bytes to dump
|
|
148 bsr DumpRead go dump LSN0 from DD.DAT to number of sides in option table
|
|
149 lda WDData,y get number of sides from DD.OPT section
|
|
150 sta U.Sides,u
|
|
151 GotInfo rts
|
|
152
|
|
153 InitPIA clr CRA,y enable PIA DDRA
|
|
154 ldd #$033E [A]=DDRA: PA bits 7-2 = inputs, bits 1-0 = outputs
|
|
155 std DDRA,y [B]=CRA: PIA CA2 out high, PA slct, CA1 low to high, no IRQs
|
|
156 clr CRB,y enable PIA DDRB
|
|
157 lda #$FF [A]=DDRB: PB bits 7-0 all outputs
|
|
158 std DDRB,y [B]=CRB: PIA CB2 out high, PB slct, CB1 low to high, no IRQs
|
|
159 leas -BootMem,s open up some space for variables
|
|
160 leau ,s point [U] to start of variables
|
|
161 ldb #BootMem number of bytes to clear
|
|
162 leax ,u point [X] to start of variables
|
|
163 ClrLoop clr ,x+ initialize a byte to 0
|
|
164 decb done yet?
|
|
165 bne ClrLoop no, go clear another byte
|
|
166 lda #SelfTest WD 1002-05 internal diagnostic command
|
|
167 lbsr CmdUpdat go issue WD command, ensure everything is ready...
|
|
168 bcs ReadErr error, go report it...
|
|
169 lda #Restore!($0F&^HDStep) default to Restore with HD step rate
|
|
170 ldb <D.WDBtDr get boot drive number
|
|
171 cmpb #$03 hard drive?
|
|
172 blo SaveRstr yes, go save HD Restore command...
|
|
173 inc U.StSctr,u set start sector to 1 for floppy disks
|
|
174 lda #Restore!($0F&^FDStep) get Restore with FD step rate
|
|
175 SaveRstr sta U.Restor,u
|
|
176 leax SDHTable,pc
|
|
177 lda b,x get base SDH register
|
|
178 sta U.SDH,u save it...
|
|
179 * restore head to track 0
|
|
180 lbsr SetupTF go update WD task files (except command)
|
|
181 lda U.Restor,u load WD restore command code
|
|
182 lbsr CmdUpdat go issue WD command
|
|
183 bcs ReadErr error, go report it...
|
|
184 * read cylinder 0, head 0, first sector
|
|
185 lbsr GetSctr go set up, issue read command
|
|
186 bcs ReadErr error, go report it...
|
|
187 bsr LSN0Info go get disk info from LSN0
|
|
188 ldd U.BSZ,u get boot file size/cylinder offset number
|
|
189 bne ChkInfo must be boot file size, go check other LSN0 info...
|
|
190 ldd U.BT+1,u get offset cylinder number
|
|
191 beq ReadErr must not be boot disk, go report error...
|
|
192 cmpd #MaxCyls offset cylinder number OK?
|
|
193 bhs ReadErr no, go return error...
|
|
194 std U.CrtCyl,u save offset cylinder
|
|
195 * read offset cylinder, head 0, first sector
|
|
196 lbsr GetSctr go set up, issue read command
|
|
197 bcs ReadErr error, go exit...
|
|
198 lbsr LSN0Info go get disk info from offset LSN0
|
|
199 ldd U.BSZ,u get boot file size
|
|
200 beq ReadErr must not be boot disk, go report error...
|
|
201 * check LSN0 info
|
|
202 ChkInfo ldd U.SPT,u get sectors per track
|
|
203 beq ReadErr 0 sectors per track, go return error
|
|
204 cmpd #MaxSctrs sectors per track OK?
|
|
205 bhi ReadErr no, go return error
|
|
206 lda U.Sides,u get disk sides (heads)
|
|
207 beq ReadErr 0 sides, go return error
|
|
208 cmpa #MaxHeads number of heads OK?
|
|
209 bhi ReadErr no, go return error
|
|
210 mul calculate sectors per cylinder
|
|
211 std U.SPC,u save sectors per cylinder
|
|
212 ldd U.BSZ,u get boot file size
|
|
213 addd #$00FF round up to even sector...
|
|
214 sta U.BSct,u save number of sectors in boot file
|
|
215 * calculate boot file start cylinder, head, & sector
|
|
216 ldd U.BT+1,u get boot file LSN LSBs
|
|
217 ldx U.CrtCyl,u get current (offset) cylinder number
|
|
218 CylLoop subd U.SPC,u subtract sectors/cylinder
|
|
219 blo ChkBtMSB [D] underflow, go check boot file LSN MSB
|
|
220 CylLoop0 leax 1,x increment current cylinder number
|
|
221 bne CylLoop no overflow, go do another subtraction
|
|
222 ReadErr ldb #E$Read
|
|
223 coma set Carry for error
|
|
224 leas BootMem,s restore stack pointer
|
|
225 rts
|
|
226 ChkBtMSB tst U.BT,u boot file LSN MSB = 0?
|
|
227 beq GotCyl yes, go determine head number
|
|
228 dec U.BT,u decrement boot file LSN MSB
|
|
229 bra CylLoop0 go on...
|
|
230 GotCyl addd U.SPC,u restore sector number
|
|
231 stx U.CrtCyl,u save current cylinder number
|
|
232 TrkLoop subd U.SPT,u subtract sectors/track
|
|
233 blo GotSide [D] underflow, go save current sector number
|
|
234 inc U.CrtSid,u increment current side number
|
|
235 bra TrkLoop go do another subtraction
|
|
236 GotSide addd U.SPT,u restore sector number
|
|
237 stb U.CrtSct,u save it
|
|
238 * request boot file memory
|
|
239 pshs u save data pointer
|
|
240 ldd U.BSZ,u get boot file size
|
|
241 os9 F$SRqMem
|
|
242 tfr u,x move start address into [X]
|
|
243 puls u recover data pointer
|
|
244 bcs BtExit0 go return F$SRqMem error
|
|
245 stx U.BtStrt,u save boot file start address
|
|
246 ldd U.CrtCyl,u get cylinder number
|
|
247 bra ChkCyl go check cylinder & get first sector
|
|
248
|
|
249 * load boot file into memory
|
|
250 BootLoad inc U.CrtSct,u move on to next sector
|
|
251 lda U.SPT+1,u get sectors per track LSB (MSB is always 0)
|
|
252 cmpa U.CrtSct,u done track?
|
|
253 bhi LoadSctr no, go get sector
|
|
254 clr U.CrtSct,u reset current sector number to 0
|
|
255 inc U.CrtSid,u move on to next side
|
|
256 lda U.CrtSid,u get side number
|
|
257 cmpa U.Sides,u done cylinder?
|
|
258 blo LoadSctr no, go get sector
|
|
259 clr U.CrtSid,u reset side number to 0
|
|
260 ldd U.CrtCyl,u get cylinder number
|
|
261 addd #1 move on to next cylinder
|
|
262 std U.CrtCyl,u save cylinder number
|
|
263 ChkCyl cmpd #MaxCyls cylinder number OK?
|
|
264 bhs ReadErr no, go return error
|
|
265 LoadSctr bsr GetSctr go get current sector from WD 1002-05
|
|
266 bcs ReadErr error, go exit
|
|
267 clrb transfer 256 bytes
|
|
268 stb PB,y set WD sector buffer address
|
|
269 ReadLoop lda WDData,y get byte from WD 1002-05
|
|
270 sta ,x+ save byte to buffer
|
|
271 decb done yet?
|
|
272 bne ReadLoop no, go get another byte
|
|
273 dec U.BSct,u count down boot file sectors remaining
|
|
274 bne BootLoad
|
|
275 clrb clear carry
|
|
276 ldd U.BSZ,u get boot file size
|
|
277 ldx U.BtStrt,u get boot file start address
|
|
278 BtExit0 leas BootMem,s restore stack pointer
|
|
279 rts
|
|
280
|
|
281 GetSctr bsr SetupTF go set up WD task files (except command)
|
|
282 lda #ReadSctr load WD read sector command code
|
|
283 CmdUpdat ldb #CmdReg load WD command register address
|
|
284 bsr TFUpdat go issue command...
|
|
285 BusyWait ldb #StatReg
|
|
286 stb PB,y set WD status register address
|
|
287 BusyW0 ldb WDData,y get WD 1002-05 status
|
|
288 bitb #%00000010 valid data? (WD 1002-05 powered & connected?)
|
|
289 bne BWErr no, go report error...
|
|
290 tstb ensure [CC] sign flag is current
|
|
291 bmi BusyW0 yes, go check again
|
|
292 ldb WDData,y get valid controller status
|
|
293 rorb rotate error bit into carry
|
|
294 bcc NoError
|
|
295 ldb #ErrReg
|
|
296 stb PB,y set WD error register address
|
|
297 ldb WDData,y get error register contents
|
|
298 bne BWErr
|
|
299 NoError clrb
|
|
300 rts
|
|
301 BWErr comb error, set [CC] Carry...
|
|
302 rts
|
|
303
|
|
304 SetupTF ldd #$01*256+SctrCnt single sector commands only
|
|
305 bsr TFUpdat
|
|
306 lda U.CrtCyl,u get current cylinder number MSB
|
|
307 ldb #CylHigh
|
|
308 bsr TFUpdat
|
|
309 lda U.CrtCyl+1,u get current cylinder number LSB
|
|
310 ldb #CylLow
|
|
311 bsr TFUpdat
|
|
312 lda U.CrtSct,u get current sector number
|
|
313 adda U.StSctr,u add offset...
|
|
314 ldb #SctrReg
|
|
315 bsr TFUpdat
|
|
316 clrb default extended head disabled
|
|
317 lda U.CrtSid,u get current side (head) number
|
|
318 cmpa #$08 extended head?
|
|
319 blo StdHead no, go on...
|
|
320 incb set enable code
|
|
321 anda #$07 mask out all but standard head number
|
|
322 StdHead stb PA,y set extended head enable/disable
|
|
323 ora U.SDH,u mask in base SDH copy
|
|
324 ldb #SDHReg
|
|
325 TfUpdat stb PB,y set WD register address
|
|
326 sta WDData,y write data to WD 1002-05
|
|
327 rts
|
|
328
|
|
329 * pad Boot module out to $01D0 exactly
|
|
330 Pad fill $39,$1D0-3-*
|
|
331
|
|
332 emod
|
|
333 BEnd equ *
|
|
334 end
|
|
335
|