2590
|
1 ********************************************************************
|
|
2 * Boot - IDE Boot Module
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
|
8 * ------------------------------------------------------------------
|
|
9 * ? 1994/06/25 Alan DeKok
|
|
10 * Diassembled.
|
|
11 *
|
|
12 * 6 1999/08/17 Paul T. Barton
|
|
13 * Redone for IDE.
|
|
14 *
|
|
15 * 7 2002/06/27 Boisy G. Pitre
|
|
16 * Added use of LSN bits 23-16.
|
|
17 *
|
|
18 * 7r1 2004/05/12 Boisy G. Pitre
|
|
19 * Optimized, made toG wait on !BUSY and DRDY, added slowdown POKE
|
|
20 * for Fujitsu 128MB CF (may be temporary)
|
|
21 *
|
|
22 * 8 2004/07/29 Boisy G. Pitre
|
|
23 * Now detects CHS/LBA mode to work with ALL IDE drives.
|
|
24 *
|
|
25 * 9 2005/10/13 Boisy G. Pitre
|
|
26 * Support for fragmented bootfiles added.
|
|
27
|
|
28 NAM Boot
|
|
29 TTL IDE Boot Module
|
|
30
|
|
31 IFP1
|
|
32 USE defsfile
|
|
33 USE ide.d
|
|
34 ENDC
|
|
35
|
|
36 tylg SET Systm+Objct
|
|
37 atrv SET ReEnt+rev
|
|
38 rev SET $00
|
|
39 edition SET 9
|
|
40
|
|
41 * Disassembled 94/06/25 11:37:47 by Alan DeKok
|
|
42 * ReDone by Paul T. Barton 99/08/17, for IDE
|
|
43
|
|
44 MOD eom,name,tylg,atrv,start,size
|
|
45
|
|
46 * on-stack static storage
|
|
47 ORG 0
|
|
48 cyls RMB 2
|
|
49 sides RMB 1
|
|
50 sects RMB 2
|
|
51 mode RMB 1
|
|
52 seglist RMB 2 pointer to segment list
|
|
53 blockloc RMB 2 pointer to memory requested
|
|
54 blockimg RMB 2 duplicate of the above
|
|
55 bootloc RMB 3 sector pointer; not byte pointer
|
|
56 bootsize RMB 2 size in bytes
|
|
57 LSN0Ptr RMB 2 LSN0 pointer (used by boot_common.asm)
|
|
58 size EQU .
|
|
59
|
|
60 name FCS /Boot/
|
|
61 FCB edition
|
|
62
|
|
63 * Common booter-required defines
|
|
64 LSN24BIT EQU 1
|
|
65 FLOPPY EQU 0
|
|
66
|
|
67 USE boot_common.asm
|
|
68
|
|
69 * HWInit - Initialize the device
|
|
70 * Entry: Y = hardware address
|
|
71 * Exit: Carry Clear = OK, Set = Error
|
|
72 * B = error (Carry Set)
|
|
73 HWInit ldb Address+2,pcr
|
|
74 bne slave@
|
|
75 lda #%10100000
|
|
76 FCB $8C
|
|
77 slave@ lda #%10110000
|
|
78 sta mode,u
|
|
79 stb DevHead,y select device
|
|
80 a@ tst Status,y wait for BSY to clear
|
|
81 bmi a@
|
|
82 lda #$EC
|
|
83 sta Command,y
|
|
84 b@ tst Status,y
|
|
85 bmi b@
|
|
86 * Harvest C/H/S values.
|
|
87 ldb DataReg,y ignore bytes 0-1
|
|
88 ldb DataReg,y bytes 2-3 = no. of cylinders
|
|
89 lda Latch,y
|
|
90 std cyls,u save cylinders in our private static area
|
|
91 ldb DataReg,y ignore bytes 4-5
|
|
92 ldb DataReg,y bytes 6-7 = no. of heads
|
|
93 stb sides,u save sides on stack (B)
|
|
94 ldb DataReg,y ignore bytes 8-9
|
|
95 ldb DataReg,y ignore bytes 10-11
|
|
96 ldb DataReg,y bytes 12-13 = no. of sectors/track
|
|
97 lda Latch,y
|
|
98 std sects,u save sectors/track on stack (Y)
|
|
99 * Throw away the next 42 (48-7) words
|
|
100 ldb #43
|
|
101 l@ tst DataReg,y
|
|
102 lda Latch,y
|
|
103 decb
|
|
104 bne l@
|
|
105 * A holds byte with LBA bit
|
|
106 anda #%00000010 LBA drive?
|
|
107 beq nope@
|
|
108 ldb mode,u
|
|
109 orb #%01000000
|
|
110 stb mode,u
|
|
111 nope@ ldb #256-50
|
|
112 o@ tst DataReg,y
|
|
113 decb
|
|
114 bne o@
|
|
115 HWTerm clrb
|
|
116 rts
|
|
117
|
|
118 * HWRead - Read a 256 byte sector from the device
|
|
119 * Entry: Y = hardware address
|
|
120 * B = bits 23-16 of LSN
|
|
121 * X = bits 15-0 of LSN
|
|
122 * blockloc,u = ptr to 256 byte sector
|
|
123 * Exit: X = ptr to data (i.e. ptr in blockloc,u)
|
|
124 HWRead
|
|
125 pshs x,b
|
|
126 b@ tst Status,y
|
|
127 bmi b@ if =1 then loop
|
|
128 lda mode,u
|
|
129 sta DevHead,y 0L0d/0hhh device=CHS
|
|
130 r@ ldb Status,y is IDE ready for commands?
|
|
131 andb #BusyBit+DrdyBit ready ?
|
|
132 cmpb #DrdyBit
|
|
133 bne r@ loop until Drdy=1 and Busy=0
|
|
134 ldb #$01 only one at a time
|
|
135 stb SectCnt,y only one at a time
|
|
136 anda #%01000000
|
|
137 beq chs@ branch if mode
|
|
138 lda ,s get bits 23-16
|
|
139 sta CylHigh,y
|
|
140 ldd 1,s get bits 15-0
|
|
141 stb SectNum,y
|
|
142 sta CylLow,y
|
|
143 bra DoCmd
|
|
144 chs@
|
|
145 * Compute proper C:H:S value
|
|
146 lda sides,u get device's head
|
|
147 ldb sects+1,u and sector
|
|
148 mul multiply H*S
|
|
149 * Note, there is a chance here that if the product is zero, we could loop forever
|
|
150 * beq ZeroProd
|
|
151 pshs d save product of H*S
|
|
152 ldd 1+2,s get bits 15-0 of LSN
|
|
153 ldx #-1 start Y at -1
|
|
154 inc 0+2,s increment physical sector
|
|
155 * Here we are doing physLSN/(H*S) to get cylinder for physLSN
|
|
156 a@ leax 1,x increment count to compensate
|
|
157 subd ,s subtract (H*S) from physLSN
|
|
158 bhs a@ if D>=0 then continue
|
|
159 dec 0+2,s decrement phys sector bits 23-16
|
|
160 bne a@ if not zero, continue divide
|
|
161 addd ,s++ add in (H*S) to make non-negative
|
|
162 pshs d X now holds cylinder, save D on stack
|
|
163 tfr x,d
|
|
164 exg a,b swap
|
|
165 std CylLow,y store computed cylinder in HW
|
|
166 puls d restore saved cylinder
|
|
167 * Now we will compute the sector/head value
|
|
168 ldx #-1
|
|
169 c@ leax 1,x
|
|
170 subb sects+1,u
|
|
171 sbca #0
|
|
172 bcc c@
|
|
173 addb sects+1,u
|
|
174 incb add 1 to B, which is sector
|
|
175 stb SectNum,y store computed sector in HW
|
|
176 tfr x,d
|
|
177 orb DevHead,y OR in with value written earlier
|
|
178 stb DevHead,y
|
|
179 DoCmd lda #S$READ read one sector
|
|
180 sta Command,y finish process
|
|
181
|
|
182 Blk2 lda Status,y is IDE ready to send?
|
|
183 anda #DrqBit DRQ, data request
|
|
184 beq Blk2 loop while DRQ =0
|
|
185
|
|
186 ldx blockloc,u
|
|
187 clr ,s
|
|
188 BlkLp
|
|
189 lda DataReg,y A <- IDE
|
|
190 ldb Latch,y
|
|
191 std ,x++ into RAM
|
|
192 inc ,s
|
|
193 bpl BlkLp go get the rest
|
|
194 b@ lda DataReg,y read remaining 256 bytes
|
|
195 dec ,s
|
|
196 bne b@
|
|
197
|
|
198 leax -256,x
|
|
199 stx 1,s
|
|
200 lda Status,y check for error-bit
|
|
201 clrb
|
|
202 puls b,x,pc
|
|
203
|
|
204
|
|
205
|
|
206 * ------------------------------------------
|
|
207
|
|
208 *Init
|
|
209 * pshs d,y
|
|
210 * ldy <Address,pcr
|
|
211 * bsr ChkBusy could be spinning up...
|
|
212 * lda #Diagnos hits all drives
|
|
213 * sta Command,y ./
|
|
214 * bsr ChkBusy wait 'til both done
|
|
215 * clrb no errors
|
|
216 * puls d,y,pc
|
|
217
|
|
218 * Entry: A = number to show
|
|
219 * Destroys D
|
|
220 *Num
|
|
221 * tfr a,b
|
|
222 * lsra
|
|
223 * lsra
|
|
224 * lsra
|
|
225 * lsra
|
|
226 * bsr x@
|
|
227 * andb #$0F
|
|
228 * tfr b,a
|
|
229 *x@
|
|
230 * adda #'0
|
|
231 * cmpa #'9
|
|
232 * ble s@
|
|
233 * adda #$7
|
|
234 *s@ jsr <D.BtBug
|
|
235 * rts
|
|
236
|
|
237 IFGT Level-1
|
|
238 Pad FILL $39,$1D0-3-2-1-*
|
|
239 ENDC
|
|
240
|
|
241 Address FDB SDAddr
|
|
242 WhchDriv FCB 0 Drive to use (0 = master, 1 = slave)
|
|
243
|
|
244
|
|
245 EMOD
|
|
246 eom EQU *
|
|
247 END
|
|
248
|