1187
|
1 ********************************************************************
|
|
2 * Boot - Burke & Burke Boot Module
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Burke & Burke boot module... needs to be patched for OS9Boots that are
|
|
7 * far into the device.
|
|
8 * Track is the literal cylinder #, Cylinder would be including all heads
|
|
9 * of that track
|
|
10 *
|
1287
|
11 * Edt/Rev YYYY/MM/DD Modified by
|
|
12 * Comment
|
1187
|
13 * ------------------------------------------------------------------
|
1287
|
14 * 2 ????/??/??
|
|
15 * Initial version.
|
1187
|
16
|
|
17 nam Boot
|
|
18 ttl Burke & Burke Boot Module
|
|
19
|
|
20 org 0
|
|
21 buffptr rmb 2 Pointer to sector buffer in memory
|
|
22 numcyl rmb 2 Number of tracks for drive geometry init
|
|
23 sechead rmb 2 # of logical sectors/physical sector
|
|
24 numhead rmb 1 # of heads (sides)
|
|
25 seccyl rmb 2 # of sectors/cylinder (# of heads*sectors per head)
|
|
26 track rmb 2 Cylinder number last calculated ($9 - $A)
|
|
27 head rmb 1 Drive/head number (drive always 0)
|
|
28 sector rmb 1 Sector number (0-63)
|
|
29 vars equ 13-buffptr Size of stack variables buffer
|
|
30
|
|
31
|
1287
|
32 IFP1
|
1187
|
33 use defsfile
|
|
34 use rbfdefs
|
1287
|
35 ENDC
|
1187
|
36
|
|
37 tylg set Systm+Objct
|
|
38 atrv set ReEnt+rev
|
1287
|
39 rev set $00
|
1187
|
40 edition set 2
|
|
41
|
|
42 mod eom,name,tylg,atrv,start,size
|
|
43
|
|
44 u0000 rmb 0
|
|
45 size equ .
|
|
46
|
|
47 name fcs /Boot/
|
|
48 fcb edition
|
|
49
|
|
50 start ldb >MPI.Slct Set up Multipak properly for us
|
|
51 lda #$10
|
|
52 mul
|
|
53 ldb #$11
|
|
54 mul
|
|
55 stb >MPI.Slct
|
|
56 leas -vars,s Reserve work area on stack of 13 bytes
|
|
57 tfr s,u U points to beginning of 13 byte buffer
|
|
58 pshs u,y,x,b,a Preserve registers
|
|
59 ldd #$0200 512 bytes for each read from XT-GEN
|
|
60 std numcyl,u # of cyls on drive
|
|
61 sta sechead+1,u # of sectors/head
|
|
62 sta numhead,u # of heads on drive
|
|
63 os9 F$SRqMem Request 512 byte buffer from OS9P1
|
|
64 lbcs L00B6 Error
|
|
65 tfr u,d d=Starting address of 512 byte block
|
|
66 ldu $06,s Get back pointer to 13 byte buffer
|
|
67 std buffptr,u Preserve buffer pointer
|
|
68
|
|
69 clr >$FF51 Reset controller
|
|
70
|
|
71 clr >$FF53 Set controller mode to 0 (part of init)
|
|
72 lbsr drvtype Set drive geometry (type of drive)
|
|
73 clrb Set initial LSN to 0
|
|
74 ldx #$0000
|
|
75 lbsr GetSect Figure out track/head/sector for LSN0
|
|
76 bcs L00B6 Error occured in read
|
|
77 ldy buffptr,u Get buffer pointer
|
|
78 ldd DD.NAM+PD.CYL,y Get real # cylinders on drive
|
|
79 std numcyl,u Preserve
|
|
80 ldd DD.NAM+PD.SCT,y Get real # sectors/track
|
|
81 std sechead,u Preserve
|
|
82 lda DD.NAM+PD.SID,y Get real # heads
|
|
83 sta numhead,u Preserve
|
|
84 leay DD.BT,y Point to OS9Boot information
|
|
85 ldd DD.BSZ-DD.BT,y Get size of OS9Boot
|
|
86 std ,s Preserve on stack
|
|
87 ldb DD.BT-DD.BT,y Get MSB of starting LSN of OS9Boot
|
|
88 ldx DD.BT-DD.BT+1,y Get LSW of starting LSN of OS9Boot
|
|
89 pshs x,b Push on stack
|
|
90 lbsr drvtype Set up drive for real drive specs
|
|
91 ldd #$0200 Get size of our buffer
|
|
92 ldu buffptr,u Get pointer to our 512 byte buffer
|
|
93 os9 F$SRtMem Deallocate our old sector buffer
|
|
94 ldd $03,s Get back size of OS9Boot
|
|
95 inca Increase size by 1 block (256 bytes)
|
|
96 IFEQ Level-1
|
|
97 os9 F$SRqMem
|
|
98 ELSE
|
|
99 os9 F$BtMem Allocate memory for boot file
|
|
100 ENDC
|
|
101 bcs L00B0 Error
|
|
102 stu $05,s Preserve pointer to start of OS9boot memory
|
|
103 ldu $09,s Get back pointer to local variables
|
|
104 ldd $05,s Get pointer to start of OS9Boot memory
|
|
105 std buffptr,u Move disk buffer pointer to there
|
|
106 ldd $03,s Get size of bootfile
|
|
107 beq L00A9 If zero, do someting
|
|
108 pshs b,a Otherwise push on stack
|
|
109 ReadBt std ,s Store # bytes left in boot on stack
|
|
110 ldb $02,s Get MSB of start sector of boot
|
|
111 ldx $03,s Get LSW of start sector of boot
|
|
112 bsr GetSect Convert to track/head/sector
|
|
113 bcs L00B4 If an error in getting, do something
|
|
114 inc buffptr,u Bump up buffer pointer by a page
|
|
115 ldx $03,s Bump up LSW of sector number
|
|
116 leax $01,x
|
|
117 stx $03,s And put it back
|
|
118 bne L00A0 If no carry over needed, proceed
|
|
119 inc $02,s Bump up MSB of sector number
|
|
120 L00A0 ldd ,s Get current boot size left to do
|
|
121 subd #$0100 Subtract 256 from it
|
|
122 bhi ReadBt If not zero yet, keep reading
|
|
123 leas $02,s Eat our temporary size left
|
|
124 L00A9 leas $03,s Eat our current LSN to get
|
|
125 clrb Clear carry (No error)
|
|
126 puls b,a pull off multipak settings (?)
|
|
127 bra BtExit
|
|
128 L00B0 leas $03,s Purge stack
|
|
129 bra L00B6
|
|
130 L00B4 leas $05,s Purge stack
|
|
131
|
|
132 L00B6 leas $02,s Purge stack
|
|
133
|
|
134 BtExit pshs a
|
|
135 lda #$FF
|
|
136 sta >$FF51 Reset controller
|
|
137 sta >MPI.Slct Reset multipak
|
|
138 sta >$FFD9 Double speed on
|
|
139 puls u,y,x,a Get exit parameters for Boot
|
|
140 leas vars,s Reset stack
|
|
141 rts Exit from Boot
|
|
142
|
|
143 * Get 512 byte sector from controller
|
|
144 * Entry X:B = 24 bit Logical sector number to get
|
|
145
|
|
146 GetSect pshs x,b Preserve registers
|
|
147 ldx #$FFFF (Init X so it will be 0 in loop)
|
|
148
|
|
149 * 24 bit divide routine. Stack=LSN (3 bytes)
|
|
150 * Entry: u=pointer to our local variable list
|
|
151
|
|
152 cyldiv leax $01,x # of loops through subtract
|
|
153 ldd $01,s Get original x (0)
|
|
154 subd seccyl,u Subtract # sector/cylinder
|
|
155 std $01,s Preserve it back
|
|
156 ldb ,s Continue subtract with borrow for 24 bit
|
|
157 sbcb #$00
|
|
158 stb ,s
|
|
159 bcc cyldiv If not trying to borrow again, continue
|
|
160 stx track,u Got track #
|
|
161 ldd $01,s Reset value to last in loop
|
|
162 addd seccyl,u
|
|
163 clr head,u Set head # to 0?
|
|
164 hddiv inc head,u Increase head #?
|
|
165 subd sechead,u Subtract # sectors/head?
|
|
166 bcc hddiv Continue subtracting until it wraps
|
|
167 dec head,u Adjust head to not include wrap
|
|
168 addd sechead,u Adjust leftover to not include wrap
|
|
169 lsrb Divide b by 2 (256 byte sector to 512)
|
|
170 stb sector,u Preserve sector #
|
|
171 leas $03,s Clear stack of 24 bit number
|
|
172
|
|
173 pshs cc Preserve odd sector flag (carry bit)
|
|
174
|
|
175 bsr cmdstrt Set up controller for new command
|
|
176 lda #$08 Read sector command
|
|
177 ldb head,u Drive/head byte (Drive always 0)
|
|
178 bsr dblsend Send to controller
|
|
179 ldd track,u Get msb of track
|
|
180 lsra Move right 2 bits into left two for the
|
|
181 rora controller
|
|
182 rora
|
|
183 ora sector,u mask in the sector number into remaining 6 bits
|
|
184 * ldb track+1,u Get LSB of track
|
|
185 bsr dblsend Send to controller
|
|
186 ldd #$0100 1 sector to read/no error correction/3 ms step
|
|
187 bsr dblsend Send that to controller
|
|
188 ldx buffptr,u Get pointer to sector buffer
|
|
189 * new code is here
|
|
190 puls cc Get back odd sector 1/2 indicator
|
|
191 bcc normal Even sector, use 1st half
|
|
192 bsr Eat256 Odd sector, use 2nd half
|
|
193 bsr Read256 Read 256 bytes off of controller
|
|
194 lbra chkcmplt See if command is complete
|
|
195 normal bsr Read256 Read 1/2 of sector
|
|
196 bsr Eat256 Eat half of sector
|
|
197 lbra chkcmplt See if command is complete
|
|
198
|
|
199 Eat256 clrb Eat 256 bytes off of controller
|
|
200 Eatlp lbsr nxtready Get byte from controller
|
|
201 decb counter
|
|
202 bne Eatlp Keep eating until 256 bytes done
|
|
203 clrb
|
|
204 rts
|
|
205
|
|
206 * Read 256 bytes from controller
|
|
207 * Entry: X=Pointer to current position in 512 physical sector buffer
|
|
208
|
|
209 Read256 clrb Set counter for 256 byte read
|
|
210 ReadLp lbsr nxtready Go get a byte from controller
|
|
211 sta ,x+ Put in buffer
|
|
212 decb keep doing until all 256 are read
|
|
213 bne ReadLp
|
|
214
|
|
215 middle clrb Clear carry for no error & return
|
|
216 rts
|
|
217
|
|
218 * Send 2 bytes to the controller
|
|
219 * Entry: a=1st byte to send
|
|
220 * b=2nd byte to send
|
|
221
|
|
222 dblsend pshs b,a Preserve d for a moment
|
|
223 bsr sendbyte Go send what is in a to controller
|
|
224 tfr b,a Send what was in b to the controller
|
|
225 bsr sendbyte
|
|
226 puls pc,b,a Return with a and b intact
|
|
227
|
|
228 * Sends a byte to the controller when it is ready for it
|
|
229 * Entry: a=byte to send
|
|
230
|
|
231 sendbyte pshs a Preserve a for a moment
|
|
232 waitsend bsr stable Make sure status register is stable and get it
|
|
233 anda #%00001011 Mask out bits
|
|
234 cmpa #$09 Is it expecting next byte of data packet?
|
|
235 bne waitsend
|
|
236 puls a Yes, get the byte we are sending next
|
|
237 sta >$FF50 Store in data register
|
|
238 rts
|
|
239
|
|
240 * Sends out command packet (6 bytes). Hard coded for drive 0, head 0,
|
|
241 * track 0, sector 0, interleave 0, no error correction, 3 ms step rate
|
|
242
|
|
243 cmdpckt pshs a Preserve command for a moment
|
|
244 bsr cmdstrt Go initialize controller for command start
|
|
245 puls a Get back command byte
|
|
246 clrb 1st option byte to 0
|
|
247 bsr dblsend Send both to controller
|
|
248 clra
|
|
249 bsr dblsend Send 4 more 0's to controller
|
|
250 bsr dblsend (sent command byte and 5 zero bytes for command
|
|
251 rts packet)
|
|
252
|
|
253 cmdstrt bsr stable
|
|
254 anda #%00001001 Mask out all but bits 0 and 3
|
|
255 bne cmdstrt If controller command is not complete or expecting
|
|
256 clr >$FF52 data, keep reading status register until it is ready
|
|
257 rts Otherwise initialize command start
|
|
258
|
|
259 * Make sure controller's status register is stable
|
|
260
|
|
261 stable lda >$FF51 Get status from controller
|
|
262 cmpa >$FF51 Keep getting until it stabilizes
|
|
263 bne stable
|
|
264 rts
|
|
265
|
|
266 * Set the drive type (set to 512 track - may be the error)
|
|
267 * Using the initialize drive geometry command
|
|
268 * Exit: Carry set if non-recoverable error
|
|
269
|
|
270 drvtype lda #$0C Initialize drive geometry command
|
|
271 bsr cmdpckt Go init
|
|
272 ldd numcyl,u Get # of cylinders on media
|
|
273 bsr dblsend Send it out (indicates drive has 512 tracks)
|
|
274 ldb sechead+1,u Get # of sectors/head
|
|
275 lda numhead,u Get # of heads on media
|
|
276 lsrb Divide OS9 sectors by 2
|
|
277 bsr sendbyte Send out # of heads for drive geometry
|
|
278 lslb Multiply WD sectors by 2 to get OS9 sectors again.
|
|
279 mul
|
|
280 std seccyl,u # sectors per cylinder (all heads on a track)
|
|
281 ldd numcyl,u Get # of tracks back
|
|
282 subd #$0001 Reduce write track=last track-1
|
|
283 bsr dblsend Send out reduced write track #
|
|
284 bsr dblsend Also use as write precomp track #
|
|
285 lda #$04 Maximum ECC burst length correctable=4
|
|
286 bsr sendbyte Send it out
|
|
287
|
|
288 * Make sure command has completed
|
|
289 * Exit: Carry set if controller reported a non-recoverable error
|
|
290 * Carry clear if everything went fine
|
|
291
|
|
292 chkcmplt bsr stable When status register is stable get it
|
|
293 anda #%00000111 Keep checking until controller indicates that
|
|
294 cmpa #%00000111 command completion code is ready to be read
|
|
295 bne chkcmplt
|
|
296 lda >$FF50 Get command completion code
|
|
297 bita #%00000010 Was there in error in completing the command?
|
|
298 beq noerror Nope, everything fine setting drive geometry
|
|
299 lda #$03 Error, Request Sense Status from the drive
|
|
300 bsr cmdpckt send Request Sense Status code
|
|
301 bsr nxtready Go get response from controller
|
|
302 anda #%00111111 Mask out all but error type and error code
|
|
303 pshs a Preserve it for a second
|
|
304 bsr eat2 Go eat next 4 bytes from controller (remaining 3
|
|
305 bsr eat2 from Sense Status & command completion code)
|
|
306 puls a Get back original error byte
|
|
307 tsta No error occured?
|
|
308 beq noerror No error; exit without error
|
|
309 cmpa #%00011000 Type 1, error 8 (correctable data error)?
|
|
310 beq noerror Yes, return without error
|
|
311 comb Set carry to indicate error
|
|
312 rts return
|
|
313 noerror clrb
|
|
314 rts
|
|
315
|
|
316 * Reads two byte from controller without caring what they are
|
|
317
|
|
318 eat2 bsr nxtready
|
|
319
|
|
320 * Waits until next byte coming from controller is ready, then gets it
|
|
321 * Exit: a=byte from controller
|
|
322
|
|
323 nxtready bsr stable Make sure status register is stable and get it
|
|
324 anda #%00001011 Controller ready to send me next byte?
|
|
325 cmpa #%00001011
|
|
326 bne nxtready Nope, keep waiting
|
|
327 lda >$FF50 Yes, get byte and return
|
|
328 rts Padding to get $1D0 Size
|
1287
|
329
|
|
330 IFGT Level-1
|
|
331 * Pad to $1D0 bytes exactly
|
1187
|
332 Pad fill $39,$1D0-3-*
|
1287
|
333 ENDC
|
1187
|
334
|
|
335 emod
|
|
336 eom equ *
|
|
337 end
|