Rev 3555 | Rev 3908 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3555 | Rev 3725 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 3555 $ |
8 | $Revision: 3725 $ |
9 | 9 | ||
10 | 10 | ||
11 | ; Low-level driver for HDD access |
- | |
- | 11 | ; Low-level driver for HDD access |
|
- | 12 | ; DMA support by Mario79 |
|
12 | ; DMA support by Mario79 |
13 | ; Access through BIOS by diamond |
13 | ; Access through BIOS by diamond |
14 | ; LBA48 support by Mario79 |
14 | 15 | ;----------------------------------------------------------------------------- |
|
15 | align 4 |
16 | align 4 |
16 | hd_read: |
17 | hd_read: |
17 | ;----------------------------------------------------------- |
18 | ;----------------------------------------------------------- |
18 | ; input : eax = block to read |
19 | ; input : eax = block to read |
19 | ; ebx = destination |
20 | ; ebx = destination |
Line 20... | Line -... | ||
20 | ;----------------------------------------------------------- |
- | |
21 | and [hd_error], 0 |
- | |
22 | push ecx esi edi ; scan cache |
21 | ;----------------------------------------------------------- |
23 | 22 | and [hd_error], 0 |
|
Line 24... | Line 23... | ||
24 | ; mov ecx,cache_max ; entries in cache |
23 | push ecx esi edi ; scan cache |
Line 25... | Line 24... | ||
25 | ; mov esi,HD_CACHE+8 |
24 | |
26 | call calculate_cache |
- | |
27 | add esi, 8 |
25 | call calculate_cache |
28 | 26 | add esi, 8 |
|
Line 29... | Line 27... | ||
29 | mov edi, 1 |
27 | |
30 | 28 | mov edi, 1 |
|
Line 31... | Line 29... | ||
31 | hdreadcache: |
29 | |
32 | - | ||
33 | cmp dword [esi+4], 0; empty |
30 | hdreadcache: |
34 | je nohdcache |
31 | cmp dword [esi+4], 0 ; empty |
35 | 32 | je nohdcache |
|
36 | cmp [esi], eax ; correct sector |
33 | |
Line 47... | Line 44... | ||
47 | cmp [hd_error], 0 |
44 | cmp [hd_error], 0 |
48 | jne return_01 |
45 | jne return_01 |
49 | ; Read through BIOS? |
46 | ; Read through BIOS? |
50 | cmp [hdpos], 0x80 |
47 | cmp [hdpos], 0x80 |
51 | jae .bios |
48 | jae .bios |
52 | ; hd_read_{dma,pio} use old ATA with 28 bit for sector number |
- | |
53 | cmp eax, 0x10000000 |
- | |
54 | jb @f |
- | |
55 | inc [hd_error] |
- | |
56 | jmp return_01 |
- | |
57 | @@: |
- | |
58 | ; DMA read is permitted if [allow_dma_access]=1 or 2 |
49 | ; DMA read is permitted if [allow_dma_access]=1 or 2 |
59 | cmp [allow_dma_access], 2 |
50 | cmp [allow_dma_access], 2 |
60 | ja .nodma |
51 | ja .nodma |
61 | cmp [dma_hdd], 1 |
52 | cmp [dma_hdd], 1 |
62 | jnz .nodma |
53 | jnz .nodma |
Line 68... | Line 59... | ||
68 | .bios: |
59 | .bios: |
69 | call bd_read |
60 | call bd_read |
70 | @@: |
61 | @@: |
71 | cmp [hd_error], 0 |
62 | cmp [hd_error], 0 |
72 | jne return_01 |
63 | jne return_01 |
73 | ; lea esi,[edi*8+HD_CACHE] |
- | |
74 | ; push eax |
64 | |
75 | call calculate_cache_1 |
65 | call calculate_cache_1 |
76 | lea esi, [edi*8+esi] |
66 | lea esi, [edi*8+esi] |
77 | ; pop eax |
- | |
Line 78... | Line 67... | ||
78 | 67 | ||
79 | mov [esi], eax ; sector number |
68 | mov [esi], eax ; sector number |
Line 80... | Line 69... | ||
80 | mov dword [esi+4], 1; hd read - mark as same as in hd |
69 | mov dword [esi+4], 1 ; hd read - mark as same as in hd |
81 | - | ||
82 | yeshdcache: |
70 | |
83 | 71 | yeshdcache: |
|
84 | mov esi, edi |
- | |
- | 72 | mov esi, edi |
|
85 | shl esi, 9 |
73 | shl esi, 9 |
86 | ; add esi,HD_CACHE+65536 |
74 | |
87 | push eax |
75 | push eax |
88 | call calculate_cache_2 |
76 | call calculate_cache_2 |
Line 89... | Line 77... | ||
89 | add esi, eax |
77 | add esi, eax |
90 | pop eax |
78 | pop eax |
91 | 79 | ||
92 | mov edi, ebx |
80 | mov edi, ebx |
- | 81 | mov ecx, 512/4 |
|
93 | mov ecx, 512/4 |
82 | cld |
94 | cld |
83 | rep movsd ; move data |
95 | rep movsd ; move data |
84 | |
96 | return_01: |
- | |
- | 85 | return_01: |
|
97 | pop edi esi ecx |
86 | pop edi esi ecx |
98 | ret |
87 | ret |
99 | 88 | ;----------------------------------------------------------------------------- |
|
Line -... | Line 89... | ||
- | 89 | align 4 |
|
- | 90 | hd_read_pio: |
|
- | 91 | push eax edx |
|
- | 92 | ||
- | 93 | ; Select the desired drive |
|
- | 94 | mov edx, [hdbase] |
|
- | 95 | add edx, 6 ;адрес регистра головок |
|
100 | align 4 |
96 | mov al, byte [hdid] |
101 | hd_read_pio: |
97 | add al, 128+64+32 |
102 | push eax edx |
98 | out dx, al; номер головки/номер диска |
Line -... | Line 99... | ||
- | 99 | ||
- | 100 | call wait_for_hd_idle |
|
- | 101 | cmp [hd_error], 0 |
|
- | 102 | jne hd_read_error |
|
- | 103 | ||
- | 104 | ; ATA with 28 or 48 bit for sector number? |
|
- | 105 | mov eax, [esp+4] |
|
103 | 106 | cmp eax, 0x10000000 |
|
104 | call wait_for_hd_idle |
107 | jae .lba48 |
105 | cmp [hd_error], 0 |
108 | ;-------------------------------------- |
106 | jne hd_read_error |
109 | .lba28: |
107 | 110 | pushfd |
|
108 | cli |
111 | cli |
109 | xor eax, eax |
112 | xor eax, eax |
110 | mov edx, [hdbase] |
113 | mov edx, [hdbase] |
111 | inc edx |
114 | inc edx |
112 | out dx, al; ATAFeatures регистр "особенностей" |
115 | out dx, al ; ATA Features регистр "особенностей" |
113 | inc edx |
116 | inc edx |
114 | inc eax |
117 | inc eax |
115 | out dx, al; ATASectorCount счётчик секторов |
118 | out dx, al ; ATA Sector Counter счётчик секторов |
116 | inc edx |
119 | inc edx |
117 | mov eax, [esp+4] |
120 | mov eax, [esp+4+4] |
118 | out dx, al; ATASectorNumber регистр номера сектора |
121 | out dx, al ; LBA Low LBA (7:0) |
119 | shr eax, 8 |
122 | shr eax, 8 |
120 | inc edx |
123 | inc edx |
121 | out dx, al; ATACylinder номер цилиндра (младший байт) |
124 | out dx, al ; LBA Mid LBA (15:8) |
122 | shr eax, 8 |
125 | shr eax, 8 |
123 | inc edx |
126 | inc edx |
124 | out dx, al; номер цилиндра (старший байт) |
127 | out dx, al ; LBA High LBA (23:16) |
125 | shr eax, 8 |
128 | shr eax, 8 |
126 | inc edx |
129 | inc edx |
127 | and al, 1+2+4+8 |
130 | and al, 1+2+4+8 ; LBA (27:24) |
128 | add al, byte [hdid] |
131 | add al, byte [hdid] |
- | 132 | add al, 128+64+32 |
|
- | 133 | out dx, al ; номер головки/номер диска |
|
- | 134 | inc edx |
|
- | 135 | mov al, 20h ; READ SECTOR(S) |
|
- | 136 | out dx, al ; ATACommand регистр команд |
|
129 | add al, 128+64+32 |
137 | popfd |
- | 138 | jmp .continue |
|
- | 139 | ;-------------------------------------- |
|
- | 140 | .lba48: |
|
- | 141 | pushfd |
|
- | 142 | cli |
|
- | 143 | xor eax, eax |
|
- | 144 | mov edx, [hdbase] |
|
- | 145 | inc edx |
|
- | 146 | out dx, al ; Features Previous Reserved |
|
- | 147 | out dx, al ; Features Current Reserved |
|
- | 148 | inc edx |
|
- | 149 | out dx, al ; Sector Count Previous Sector count (15:8) |
|
- | 150 | inc eax |
|
- | 151 | out dx, al ; Sector Count Current Sector count (7:0) |
|
- | 152 | inc edx |
|
- | 153 | mov eax, [esp+4+4] |
|
- | 154 | rol eax, 8 |
|
- | 155 | out dx, al ; LBA Low Previous LBA (31:24) |
|
- | 156 | xor eax, eax ; because only 32 bit cache |
|
- | 157 | inc edx |
|
- | 158 | out dx, al ; LBA Mid Previous LBA (39:32) |
|
- | 159 | inc edx |
|
- | 160 | out dx, al ; LBA High Previous LBA (47:40) |
|
- | 161 | sub edx, 2 |
|
- | 162 | mov eax, [esp+4+4] |
|
- | 163 | out dx, al ; LBA Low Current LBA (7:0) |
|
- | 164 | shr eax, 8 |
|
- | 165 | inc edx |
|
- | 166 | out dx, al ; LBA Mid Current LBA (15:8) |
|
- | 167 | shr eax, 8 |
|
- | 168 | inc edx |
|
- | 169 | out dx, al ; LBA High Current LBA (23:16) |
|
- | 170 | inc edx |
|
- | 171 | mov al, byte [hdid] |
|
- | 172 | add al, 128+64+32 |
|
- | 173 | out dx, al ; номер головки/номер диска |
|
130 | out dx, al; номер головки/номер диска |
174 | inc edx |
131 | inc edx |
175 | mov al, 24h ; READ SECTOR(S) EXT |
Line 132... | Line 176... | ||
132 | mov al, 20h |
176 | out dx, al ; ATACommand регистр команд |
133 | out dx, al; ATACommand регистр команд |
177 | popfd |
Line -... | Line 178... | ||
- | 178 | ;-------------------------------------- |
|
134 | sti |
179 | .continue: |
135 | 180 | call wait_for_sector_buffer |
|
136 | call wait_for_sector_buffer |
181 | |
137 | - | ||
- | 182 | cmp [hd_error], 0 |
|
138 | cmp [hd_error], 0 |
183 | jne hd_read_error |
139 | jne hd_read_error |
184 | |
140 | 185 | pushfd |
|
141 | cli |
186 | cli |
Line 142... | Line 187... | ||
142 | push edi |
187 | push edi |
143 | shl edi, 9 |
188 | shl edi, 9 |
144 | ; add edi,HD_CACHE+65536 |
189 | |
145 | push eax |
190 | push eax |
146 | call calculate_cache_2 |
191 | call calculate_cache_2 |
147 | add edi, eax |
192 | add edi, eax |
Line 148... | Line 193... | ||
148 | pop eax |
193 | pop eax |
149 | 194 | ||
150 | mov ecx, 256 |
- | |
151 | mov edx, [hdbase] |
- | |
152 | cld |
195 | mov ecx, 256 |
153 | rep insw |
- | |
154 | pop edi |
- | |
155 | sti |
- | |
156 | - | ||
157 | pop edx eax |
- | |
158 | ret |
- | |
159 | - | ||
160 | disable_ide_int: |
- | |
161 | ; mov edx,[hdbase] |
- | |
162 | ; add edx,0x206 |
- | |
163 | ; mov al,2 |
- | |
164 | ; out dx,al |
- | |
165 | cli |
- | |
166 | ret |
- | |
167 | 196 | mov edx, [hdbase] |
|
168 | enable_ide_int: |
197 | cld |
169 | ; mov edx,[hdbase] |
198 | rep insw |
170 | ; add edx,0x206 |
199 | pop edi |
171 | ; mov al,0 |
200 | popfd |
172 | ; out dx,al |
201 | |
173 | sti |
202 | pop edx eax |
Line 174... | Line 203... | ||
174 | ret |
203 | ret |
175 | - | ||
176 | align 4 |
- | |
177 | hd_write: |
- | |
178 | ;----------------------------------------------------------- |
204 | ;----------------------------------------------------------------------------- |
179 | ; input : eax = block |
205 | align 4 |
180 | ; ebx = pointer to memory |
- | |
181 | ;----------------------------------------------------------- |
206 | hd_write: |
Line 182... | Line 207... | ||
182 | push ecx esi edi |
207 | ;----------------------------------------------------------- |
183 | - | ||
184 | ; check if the cache already has the sector and overwrite it |
208 | ; input : eax = block |
185 | 209 | ; ebx = pointer to memory |
|
Line 186... | Line 210... | ||
186 | ; mov ecx,cache_max |
210 | ;----------------------------------------------------------- |
187 | ; mov esi,HD_CACHE+8 |
211 | push ecx esi edi |
Line 188... | Line 212... | ||
188 | call calculate_cache |
212 | |
189 | add esi, 8 |
- | |
190 | 213 | ; check if the cache already has the sector and overwrite it |
|
191 | mov edi, 1 |
214 | call calculate_cache |
192 | 215 | add esi, 8 |
|
193 | hdwritecache: |
216 | mov edi, 1 |
Line 194... | Line 217... | ||
194 | 217 | ||
195 | cmp dword [esi+4], 0; if cache slot is empty |
218 | hdwritecache: |
196 | je not_in_cache_write |
- | |
197 | 219 | cmp dword [esi+4], 0 ; if cache slot is empty |
|
198 | cmp [esi], eax ; if the slot has the sector |
220 | je not_in_cache_write |
199 | je yes_in_cache_write |
221 | |
Line 200... | Line -... | ||
200 | - | ||
201 | not_in_cache_write: |
- | |
202 | 222 | cmp [esi], eax ; if the slot has the sector |
|
203 | add esi, 8 |
223 | je yes_in_cache_write |
204 | inc edi |
- | |
205 | dec ecx |
- | |
206 | jnz hdwritecache |
224 | |
Line 207... | Line 225... | ||
207 | 225 | not_in_cache_write: |
|
208 | ; sector not found in cache |
- | |
209 | ; write the block to a new location |
226 | add esi, 8 |
Line 210... | Line 227... | ||
210 | 227 | inc edi |
|
211 | call find_empty_slot ; ret in edi |
- | |
- | 228 | dec ecx |
|
212 | cmp [hd_error], 0 |
229 | jnz hdwritecache |
213 | jne hd_write_access_denied |
230 | |
214 | 231 | ; sector not found in cache |
|
215 | ; lea esi,[edi*8+HD_CACHE] |
232 | ; write the block to a new location |
Line 216... | Line 233... | ||
216 | ; push eax |
233 | call find_empty_slot ; ret in edi |
217 | call calculate_cache_1 |
234 | cmp [hd_error], 0 |
218 | lea esi, [edi*8+esi] |
235 | jne hd_write_access_denied |
219 | ; pop eax |
236 | |
- | 237 | call calculate_cache_1 |
|
220 | 238 | lea esi, [edi*8+esi] |
|
221 | mov [esi], eax ; sector number |
239 | mov [esi], eax ; sector number |
222 | 240 | ||
223 | yes_in_cache_write: |
- | |
- | 241 | yes_in_cache_write: |
|
224 | 242 | mov dword [esi+4], 2 ; write - differs from hd |
|
225 | mov dword [esi+4], 2; write - differs from hd |
243 | |
- | 244 | shl edi, 9 |
|
226 | 245 | ||
- | 246 | push eax |
|
227 | shl edi, 9 |
247 | call calculate_cache_2 |
228 | ; add edi,HD_CACHE+65536 |
248 | add edi, eax |
- | 249 | pop eax |
|
Line 229... | Line 250... | ||
229 | push eax |
250 | |
230 | call calculate_cache_2 |
251 | mov esi, ebx |
231 | add edi, eax |
252 | mov ecx, 512/4 |
Line -... | Line 253... | ||
- | 253 | cld |
|
- | 254 | rep movsd ; move data |
|
- | 255 | ||
- | 256 | hd_write_access_denied: |
|
- | 257 | pop edi esi ecx |
|
- | 258 | ret |
|
- | 259 | ;----------------------------------------------------------------------------- |
|
232 | pop eax |
260 | align 4 |
233 | 261 | cache_write_pio: |
|
234 | mov esi, ebx |
262 | ; Select the desired drive |
235 | mov ecx, 512/4 |
263 | mov edx, [hdbase] |
236 | cld |
264 | add edx, 6 ;адрес регистра головок |
237 | rep movsd ; move data |
265 | mov al, byte [hdid] |
238 | hd_write_access_denied: |
266 | add al, 128+64+32 |
239 | pop edi esi ecx |
267 | out dx, al ; номер головки/номер диска |
240 | ret |
268 | |
241 | 269 | call wait_for_hd_idle |
|
242 | align 4 |
270 | cmp [hd_error], 0 |
243 | cache_write_pio: |
271 | jne hd_write_error |
244 | cmp dword[esi], 0x10000000 |
272 | |
245 | jae .bad |
273 | ; ATA with 28 or 48 bit for sector number? |
246 | ; call disable_ide_int |
274 | mov eax, [esi] |
247 | 275 | cmp eax, 0x10000000 |
|
248 | call wait_for_hd_idle |
276 | jae .lba48 |
249 | cmp [hd_error], 0 |
277 | ;-------------------------------------- |
250 | jne hd_write_error |
278 | .lba28: |
251 | 279 | pushfd |
|
252 | cli |
280 | cli |
253 | xor eax, eax |
281 | xor eax, eax |
254 | mov edx, [hdbase] |
282 | mov edx, [hdbase] |
255 | inc edx |
283 | inc edx |
- | 284 | out dx, al ; ATA Features регистр "особенностей" |
|
- | 285 | inc edx |
|
- | 286 | inc eax |
|
- | 287 | out dx, al ; ATA Sector Counter счётчик секторов |
|
- | 288 | inc edx |
|
- | 289 | mov eax, [esi] ; eax = sector to write |
|
- | 290 | out dx, al ; LBA Low LBA (7:0) |
|
- | 291 | shr eax, 8 |
|
- | 292 | inc edx |
|
- | 293 | out dx, al ; LBA Mid LBA (15:8) |
|
- | 294 | shr eax, 8 |
|
- | 295 | inc edx |
|
- | 296 | out dx, al ; LBA High LBA (23:16) |
|
- | 297 | shr eax, 8 |
|
- | 298 | inc edx |
|
- | 299 | and al, 1+2+4+8 ; LBA (27:24) |
|
- | 300 | add al, byte [hdid] |
|
- | 301 | add al, 128+64+32 |
|
256 | out dx, al |
302 | out dx, al ; номер головки/номер диска |
- | 303 | inc edx |
|
- | 304 | mov al, 30h ; WRITE SECTOR(S) |
|
- | 305 | out dx, al ; ATACommand регистр команд |
|
- | 306 | popfd |
|
- | 307 | jmp .continue |
|
- | 308 | ;-------------------------------------- |
|
- | 309 | .lba48: |
|
257 | inc edx |
310 | pushfd |
- | 311 | cli |
|
- | 312 | xor eax, eax |
|
- | 313 | mov edx, [hdbase] |
|
- | 314 | inc edx |
|
- | 315 | out dx, al ; Features Previous Reserved |
|
- | 316 | out dx, al ; Features Current Reserved |
|
- | 317 | inc edx |
|
- | 318 | out dx, al ; Sector Count Previous Sector count (15:8) |
|
- | 319 | inc eax |
|
- | 320 | out dx, al ; Sector Count Current Sector count (7:0) |
|
- | 321 | inc edx |
|
- | 322 | mov eax, [esi] |
|
- | 323 | rol eax, 8 |
|
- | 324 | out dx, al ; LBA Low Previous LBA (31:24) |
|
- | 325 | xor eax, eax ; because only 32 bit cache |
|
258 | inc eax |
326 | inc edx |
- | 327 | out dx, al ; LBA Mid Previous LBA (39:32) |
|
259 | out dx, al |
328 | inc edx |
260 | inc edx |
329 | out dx, al ; LBA High Previous LBA (47:40) |
Line 261... | Line 330... | ||
261 | mov eax, [esi] ; eax = sector to write |
330 | sub edx, 2 |
262 | out dx, al |
331 | mov eax, [esi] |
Line 263... | Line 332... | ||
263 | shr eax, 8 |
332 | out dx, al ; LBA Low Current LBA (7:0) |
Line -... | Line 333... | ||
- | 333 | shr eax, 8 |
|
264 | inc edx |
334 | inc edx |
265 | out dx, al |
335 | out dx, al ; LBA Mid Current LBA (15:8) |
266 | shr eax, 8 |
336 | shr eax, 8 |
267 | inc edx |
- | |
- | 337 | inc edx |
|
268 | out dx, al |
338 | out dx, al ; LBA High Current LBA (23:16) |
269 | shr eax, 8 |
339 | inc edx |
270 | inc edx |
340 | mov al, byte [hdid] |
271 | and al, 1+2+4+8 |
341 | add al, 128+64+32 |
Line 272... | Line 342... | ||
272 | add al, byte [hdid] |
342 | out dx, al ; номер головки/номер диска |
273 | add al, 128+64+32 |
343 | inc edx |
274 | out dx, al |
344 | mov al, 34h ; WRITE SECTOR(S) EXT |
275 | inc edx |
345 | out dx, al ; ATACommand регистр команд |
276 | mov al, 30h |
346 | popfd |
Line 277... | Line -... | ||
277 | out dx, al |
- | |
278 | sti |
347 | ;-------------------------------------- |
279 | - | ||
280 | call wait_for_sector_buffer |
- | |
281 | - | ||
282 | cmp [hd_error], 0 |
- | |
283 | jne hd_write_error |
348 | .continue: |
- | 349 | call wait_for_sector_buffer |
|
284 | 350 | ||
285 | push ecx esi |
351 | cmp [hd_error], 0 |
286 | - | ||
287 | cli |
352 | jne hd_write_error |
288 | mov esi, edi |
353 | |
289 | shl esi, 9 |
354 | push ecx esi |
290 | ; add esi,HD_CACHE+65536 ; esi = from memory position |
355 | |
291 | push eax |
356 | pushfd |
292 | call calculate_cache_2 |
357 | cli |
293 | add esi, eax |
- | |
- | 358 | mov esi, edi |
|
294 | pop eax |
359 | shl esi, 9 |
295 | 360 | ||
296 | mov ecx, 256 |
- | |
297 | mov edx, [hdbase] |
361 | push eax |
298 | cld |
362 | call calculate_cache_2 |
299 | rep outsw |
363 | add esi, eax |
300 | sti |
364 | pop eax |
- | 365 | ||
301 | 366 | mov ecx, 256 |
|
302 | ; call enable_ide_int |
367 | mov edx, [hdbase] |
303 | pop esi ecx |
368 | cld |
304 | - | ||
305 | ret |
- | |
306 | .bad: |
- | |
307 | inc [hd_error] |
- | |
308 | ret |
369 | rep outsw |
309 | - | ||
310 | save_hd_wait_timeout: |
- | |
311 | - | ||
312 | push eax |
370 | popfd |
313 | mov eax, [timer_ticks] |
- | |
314 | add eax, 300 ; 3 sec timeout |
- | |
315 | mov [hd_wait_timeout], eax |
- | |
316 | pop eax |
- | |
317 | ret |
- | |
318 | 371 | ||
319 | align 4 |
372 | pop esi ecx |
320 | check_hd_wait_timeout: |
373 | ret |
321 | 374 | ;----------------------------------------------------------------------------- |
|
322 | push eax |
375 | align 4 |
323 | mov eax, [hd_wait_timeout] |
- | |
324 | cmp [timer_ticks], eax |
376 | save_hd_wait_timeout: |
325 | jg hd_timeout_error |
377 | push eax |
326 | pop eax |
378 | mov eax, [timer_ticks] |
327 | mov [hd_error], 0 |
- | |
- | 379 | add eax, 300 ; 3 sec timeout |
|
328 | ret |
380 | mov [hd_wait_timeout], eax |
329 | - | ||
330 | ;iglobal |
- | |
331 | ; hd_timeout_str db 'K : FS - HD timeout',0 |
- | |
332 | ; hd_read_str db 'K : FS - HD read error',0 |
- | |
333 | ; hd_write_str db 'K : FS - HD write error',0 |
- | |
334 | ; hd_lba_str db 'K : FS - HD LBA error',0 |
381 | pop eax |
335 | ;endg |
382 | ret |
336 | 383 | ;----------------------------------------------------------------------------- |
|
337 | hd_timeout_error: |
384 | align 4 |
338 | 385 | check_hd_wait_timeout: |
|
339 | ; call clear_hd_cache |
386 | push eax |
340 | ; call clear_application_table_status |
387 | mov eax, [hd_wait_timeout] |
341 | ; mov esi,hd_timeout_str |
- | |
- | 388 | cmp [timer_ticks], eax |
|
- | 389 | jg hd_timeout_error |
|
- | 390 | ||
342 | ; call sys_msg_board_str |
391 | pop eax |
343 | if lang eq sp |
- | |
344 | DEBUGF 1,"K : FS - HD tiempo de espera agotado\n" |
- | |
345 | else |
- | |
346 | DEBUGF 1,"K : FS - HD timeout\n" |
- | |
347 | end if |
- | |
348 | 392 | mov [hd_error], 0 |
|
349 | mov [hd_error], 1 |
393 | ret |
350 | pop eax |
394 | ;----------------------------------------------------------------------------- |
351 | ret |
395 | hd_timeout_error: |
352 | 396 | if lang eq sp |
|
353 | hd_read_error: |
397 | DEBUGF 1,"K : FS - HD tiempo de espera agotado\n" |
354 | - | ||
355 | ; call clear_hd_cache |
- | |
356 | ; call clear_application_table_status |
- | |
357 | ; mov esi,hd_read_str |
- | |
358 | ; call sys_msg_board_str |
- | |
359 | if lang eq sp |
- | |
360 | DEBUGF 1,"K : FS - HD error de lectura\n" |
- | |
361 | else |
398 | else |
362 | DEBUGF 1,"K : FS - HD read error\n" |
- | |
363 | end if |
- | |
364 | pop edx eax |
- | |
365 | ret |
- | |
366 | - | ||
367 | hd_write_error: |
- | |
368 | 399 | DEBUGF 1,"K : FS - HD timeout\n" |
|
369 | ; call clear_hd_cache |
- | |
370 | ; call clear_application_table_status |
- | |
371 | ; mov esi,hd_write_str |
- | |
372 | ; call sys_msg_board_str |
- | |
373 | if lang eq sp |
400 | end if |
374 | DEBUGF 1,"K : FS - HD error de escritura\n" |
401 | mov [hd_error], 1 |
375 | else |
402 | pop eax |
376 | DEBUGF 1,"K : FS - HD write error\n" |
403 | ret |
377 | end if |
404 | ;----------------------------------------------------------------------------- |
378 | ret |
405 | hd_read_error: |
379 | - | ||
380 | hd_write_error_dma: |
- | |
- | 406 | if lang eq sp |
|
381 | ; call clear_hd_cache |
407 | DEBUGF 1,"K : FS - HD error de lectura\n" |
382 | ; call clear_application_table_status |
408 | else |
383 | ; mov esi, hd_write_str |
- | |
384 | ; call sys_msg_board_str |
409 | DEBUGF 1,"K : FS - HD read error\n" |
Line 385... | Line 410... | ||
385 | if lang eq sp |
410 | end if |
Line 386... | Line 411... | ||
386 | DEBUGF 1,"K : FS - HD error de escritura\n" |
411 | pop edx eax |
387 | else |
412 | ret |
- | 413 | ;----------------------------------------------------------------------------- |
|
388 | DEBUGF 1,"K : FS - HD write error\n" |
414 | hd_write_error_dma: |
389 | end if |
415 | pop esi |
390 | pop esi |
- | |
391 | ret |
416 | hd_write_error: |
392 | 417 | if lang eq sp |
|
393 | hd_lba_error: |
418 | DEBUGF 1,"K : FS - HD error de escritura\n" |
Line 394... | Line 419... | ||
394 | ; call clear_hd_cache |
419 | else |
395 | ; call clear_application_table_status |
420 | DEBUGF 1,"K : FS - HD write error\n" |
396 | ; mov esi,hd_lba_str |
421 | end if |
Line 397... | Line 422... | ||
397 | ; call sys_msg_board_str |
422 | ret |
398 | if lang eq sp |
- | |
399 | DEBUGF 1,"K : FS - HD error en LBA\n" |
423 | ;----------------------------------------------------------------------------- |
400 | else |
424 | hd_lba_error: |
401 | DEBUGF 1,"K : FS - HD LBA error\n" |
- | |
402 | end if |
- | |
- | 425 | if lang eq sp |
|
403 | jmp LBA_read_ret |
426 | DEBUGF 1,"K : FS - HD error en LBA\n" |
404 | 427 | else |
|
405 | - | ||
406 | align 4 |
428 | DEBUGF 1,"K : FS - HD LBA error\n" |
Line 407... | Line 429... | ||
407 | wait_for_hd_idle: |
429 | end if |
408 | 430 | jmp LBA_read_ret |
|
Line 409... | Line 431... | ||
409 | push eax edx |
431 | ;----------------------------------------------------------------------------- |
- | 432 | align 4 |
|
410 | 433 | wait_for_hd_idle: |
|
411 | call save_hd_wait_timeout |
434 | push eax edx |
412 | - | ||
413 | mov edx, [hdbase] |
435 | |
414 | add edx, 0x7 |
436 | call save_hd_wait_timeout |
415 | 437 | ||
Line 416... | Line 438... | ||
416 | wfhil1: |
438 | mov edx, [hdbase] |
Line 458... | Line 480... | ||
458 | jz buf_wait_ok |
480 | jz buf_wait_ok |
459 | @@: |
481 | @@: |
460 | mov [hd_error], 1 |
482 | mov [hd_error], 1 |
Line 461... | Line 483... | ||
461 | 483 | ||
462 | buf_wait_ok: |
- | |
463 | 484 | buf_wait_ok: |
|
464 | pop edx eax |
485 | pop edx eax |
465 | ret |
- | |
466 | 486 | ret |
|
467 | ; \begin{Mario79} |
487 | ;----------------------------------------------------------------------------- |
468 | align 4 |
488 | align 4 |
469 | wait_for_sector_dma_ide0: |
489 | wait_for_sector_dma_ide0: |
470 | push eax |
490 | push eax |
471 | push edx |
491 | push edx |
- | 492 | call save_hd_wait_timeout |
|
- | 493 | ;-------------------------------------- |
|
472 | call save_hd_wait_timeout |
494 | align 4 |
473 | .wait: |
495 | .wait: |
474 | call change_task |
496 | call change_task |
475 | cmp [irq14_func], hdd_irq14 |
497 | cmp [irq14_func], hdd_irq14 |
476 | jnz .done |
498 | jnz .done |
Line 483... | Line 505... | ||
483 | out dx, al |
505 | out dx, al |
484 | .done: |
506 | .done: |
485 | pop edx |
507 | pop edx |
486 | pop eax |
508 | pop eax |
487 | ret |
509 | ret |
488 | - | ||
- | 510 | ;----------------------------------------------------------------------------- |
|
489 | align 4 |
511 | align 4 |
490 | wait_for_sector_dma_ide1: |
512 | wait_for_sector_dma_ide1: |
491 | push eax |
513 | push eax |
492 | push edx |
514 | push edx |
493 | call save_hd_wait_timeout |
515 | call save_hd_wait_timeout |
- | 516 | ;-------------------------------------- |
|
- | 517 | align 4 |
|
494 | .wait: |
518 | .wait: |
495 | call change_task |
519 | call change_task |
496 | cmp [irq15_func], hdd_irq15 |
520 | cmp [irq15_func], hdd_irq15 |
497 | jnz .done |
521 | jnz .done |
498 | call check_hd_wait_timeout |
522 | call check_hd_wait_timeout |
Line 505... | Line 529... | ||
505 | out dx, al |
529 | out dx, al |
506 | .done: |
530 | .done: |
507 | pop edx |
531 | pop edx |
508 | pop eax |
532 | pop eax |
509 | ret |
533 | ret |
510 | - | ||
- | 534 | ;----------------------------------------------------------------------------- |
|
511 | iglobal |
535 | iglobal |
512 | align 4 |
536 | align 4 |
513 | ; note that IDE descriptor table must be 4-byte aligned and do not cross 4K boundary |
537 | ; note that IDE descriptor table must be 4-byte aligned and do not cross 4K boundary |
514 | IDE_descriptor_table: |
538 | IDE_descriptor_table: |
515 | dd IDE_DMA |
539 | dd IDE_DMA |
Line 519... | Line 543... | ||
519 | dma_cur_sector dd not 40h |
543 | dma_cur_sector dd not 40h |
520 | dma_hdpos dd 0 |
544 | dma_hdpos dd 0 |
521 | irq14_func dd hdd_irq_null |
545 | irq14_func dd hdd_irq_null |
522 | irq15_func dd hdd_irq_null |
546 | irq15_func dd hdd_irq_null |
523 | endg |
547 | endg |
524 | - | ||
- | 548 | ;----------------------------------------------------------------------------- |
|
525 | uglobal |
549 | uglobal |
526 | ; all uglobals are zeroed at boot |
550 | ; all uglobals are zeroed at boot |
527 | dma_process dd 0 |
551 | dma_process dd 0 |
528 | dma_slot_ptr dd 0 |
552 | dma_slot_ptr dd 0 |
529 | cache_chain_pos dd 0 |
553 | cache_chain_pos dd 0 |
Line 532... | Line 556... | ||
532 | cache_chain_started db 0 |
556 | cache_chain_started db 0 |
533 | dma_task_switched db 0 |
557 | dma_task_switched db 0 |
534 | dma_hdd db 0 |
558 | dma_hdd db 0 |
535 | allow_dma_access db 0 |
559 | allow_dma_access db 0 |
536 | endg |
560 | endg |
537 | - | ||
- | 561 | ;----------------------------------------------------------------------------- |
|
538 | align 4 |
562 | align 4 |
539 | hdd_irq14: |
563 | hdd_irq14: |
540 | pushfd |
564 | pushfd |
541 | cli |
565 | cli |
542 | pushad |
566 | pushad |
543 | mov [irq14_func], hdd_irq_null |
567 | mov [irq14_func], hdd_irq_null |
544 | mov dx, [IDEContrRegsBaseAddr] |
568 | mov dx, [IDEContrRegsBaseAddr] |
545 | mov al, 0 |
569 | mov al, 0 |
546 | out dx, al |
570 | out dx, al |
547 | ; call update_counters |
- | |
548 | ; mov ebx, [dma_process] |
- | |
549 | ; cmp [CURRENT_TASK], ebx |
- | |
550 | ; jz .noswitch |
- | |
551 | ; mov [dma_task_switched], 1 |
- | |
552 | ; mov edi, [dma_slot_ptr] |
- | |
553 | ; mov eax, [CURRENT_TASK] |
- | |
554 | ; mov [dma_process], eax |
- | |
555 | ; mov eax, [TASK_BASE] |
- | |
556 | ; mov [dma_slot_ptr], eax |
- | |
557 | ; mov [CURRENT_TASK], ebx |
- | |
558 | ; mov [TASK_BASE], edi |
- | |
559 | ; mov byte [DONT_SWITCH], 1 |
- | |
560 | ; call do_change_task |
- | |
561 | .noswitch: |
- | |
562 | popad |
571 | popad |
563 | popfd |
572 | popfd |
564 | align 4 |
573 | align 4 |
565 | hdd_irq_null: |
574 | hdd_irq_null: |
566 | ret |
575 | ret |
567 | - | ||
- | 576 | ;----------------------------------------------------------------------------- |
|
568 | align 4 |
577 | align 4 |
569 | hdd_irq15: |
578 | hdd_irq15: |
570 | pushfd |
579 | pushfd |
571 | cli |
580 | cli |
572 | pushad |
581 | pushad |
573 | mov [irq15_func], hdd_irq_null |
582 | mov [irq15_func], hdd_irq_null |
574 | mov dx, [IDEContrRegsBaseAddr] |
583 | mov dx, [IDEContrRegsBaseAddr] |
575 | add dx, 8 |
584 | add dx, 8 |
576 | mov al, 0 |
585 | mov al, 0 |
577 | out dx, al |
586 | out dx, al |
578 | ; call update_counters |
- | |
579 | ; mov ebx, [dma_process] |
- | |
580 | ; cmp [CURRENT_TASK], ebx |
- | |
581 | ; jz .noswitch |
- | |
582 | ; mov [dma_task_switched], 1 |
- | |
583 | ; mov edi, [dma_slot_ptr] |
- | |
584 | ; mov eax, [CURRENT_TASK] |
- | |
585 | ; mov [dma_process], eax |
- | |
586 | ; mov eax, [TASK_BASE] |
- | |
587 | ; mov [dma_slot_ptr], eax |
- | |
588 | ; mov [CURRENT_TASK], ebx |
- | |
589 | ; mov [TASK_BASE], edi |
- | |
590 | ; mov byte [DONT_SWITCH], 1 |
- | |
591 | ; call do_change_task |
- | |
592 | .noswitch: |
- | |
593 | popad |
587 | popad |
594 | popfd |
588 | popfd |
595 | ret |
589 | ret |
596 | - | ||
- | 590 | ;----------------------------------------------------------------------------- |
|
597 | align 4 |
591 | align 4 |
598 | hd_read_dma: |
592 | hd_read_dma: |
599 | push eax |
593 | push eax |
600 | push edx |
594 | push edx |
601 | mov edx, [dma_hdpos] |
595 | mov edx, [dma_hdpos] |
Line 612... | Line 606... | ||
612 | shl eax, 9 |
606 | shl eax, 9 |
613 | add eax, (OS_BASE+IDE_DMA) |
607 | add eax, (OS_BASE+IDE_DMA) |
614 | push ecx esi edi |
608 | push ecx esi edi |
615 | mov esi, eax |
609 | mov esi, eax |
616 | shl edi, 9 |
610 | shl edi, 9 |
617 | ; add edi, HD_CACHE+0x10000 |
- | |
- | 611 | ||
618 | push eax |
612 | push eax |
619 | call calculate_cache_2 |
613 | call calculate_cache_2 |
620 | add edi, eax |
614 | add edi, eax |
621 | pop eax |
615 | pop eax |
Line 644... | Line 638... | ||
644 | mov al, 0 |
638 | mov al, 0 |
645 | out dx, al |
639 | out dx, al |
646 | add edx, 2 |
640 | add edx, 2 |
647 | mov al, 6 |
641 | mov al, 6 |
648 | out dx, al |
642 | out dx, al |
- | 643 | ||
- | 644 | ; Select the desired drive |
|
- | 645 | mov edx, [hdbase] |
|
- | 646 | add edx, 6 ; адрес регистра головок |
|
- | 647 | mov al, byte [hdid] |
|
- | 648 | add al, 128+64+32 |
|
- | 649 | out dx, al ; номер головки/номер диска |
|
- | 650 | ||
649 | call wait_for_hd_idle |
651 | call wait_for_hd_idle |
650 | cmp [hd_error], 0 |
652 | cmp [hd_error], 0 |
651 | jnz hd_read_error |
653 | jnz hd_read_error |
- | 654 | ||
- | 655 | ; ATA with 28 or 48 bit for sector number? |
|
652 | call disable_ide_int |
656 | mov eax, [esp+4] |
- | 657 | ; -10h because the PreCache hits the boundary between lba28 and lba48 |
|
- | 658 | ; 10h = 16 - size of PreCache |
|
- | 659 | cmp eax, 0x10000000-10h |
|
- | 660 | jae .lba48 |
|
- | 661 | ;-------------------------------------- |
|
- | 662 | .lba28: |
|
- | 663 | pushfd |
|
- | 664 | cli |
|
653 | xor eax, eax |
665 | xor eax, eax |
654 | mov edx, [hdbase] |
666 | mov edx, [hdbase] |
655 | inc edx |
667 | inc edx |
656 | out dx, al |
668 | out dx, al ; ATA Features регистр "особенностей" |
657 | inc edx |
669 | inc edx |
658 | mov eax, 10h |
670 | mov eax, 10h ; Sector Counter = 16 ; PreCache |
659 | out dx, al |
671 | out dx, al ; ATA Sector Counter счётчик секторов |
660 | inc edx |
672 | inc edx |
661 | mov eax, [esp+4] |
673 | mov eax, [esp+4+4] |
662 | out dx, al |
674 | out dx, al ; LBA Low LBA (7:0) |
663 | shr eax, 8 |
675 | shr eax, 8 |
664 | inc edx |
676 | inc edx |
665 | out dx, al |
677 | out dx, al ; LBA Mid LBA (15:8) |
666 | shr eax, 8 |
678 | shr eax, 8 |
667 | inc edx |
679 | inc edx |
668 | out dx, al |
680 | out dx, al ; LBA High LBA (23:16) |
669 | shr eax, 8 |
681 | shr eax, 8 |
670 | inc edx |
682 | inc edx |
671 | and al, 0xF |
683 | and al, 0xF ; LBA (27:24) |
672 | add al, byte [hdid] |
684 | add al, byte [hdid] |
673 | add al, 11100000b |
685 | add al, 11100000b |
674 | out dx, al |
686 | out dx, al ; номер головки/номер диска |
675 | inc edx |
687 | inc edx |
- | 688 | mov al, 0xC8 ; READ DMA |
|
- | 689 | out dx, al ; ATACommand регистр команд |
|
- | 690 | jmp .continue |
|
- | 691 | ;-------------------------------------- |
|
- | 692 | .lba48: |
|
- | 693 | pushfd |
|
- | 694 | cli |
|
- | 695 | xor eax, eax |
|
- | 696 | mov edx, [hdbase] |
|
- | 697 | inc edx |
|
- | 698 | out dx, al ; Features Previous Reserved |
|
- | 699 | out dx, al ; Features Current Reserved |
|
- | 700 | inc edx |
|
- | 701 | out dx, al ; Sector Count Previous Sector count (15:8) |
|
- | 702 | mov eax, 10h ; Sector Counter = 16 PreCache |
|
- | 703 | out dx, al ; Sector Count Current Sector count (7:0) |
|
- | 704 | inc edx |
|
- | 705 | mov eax, [esp+4+4] |
|
676 | mov al, 0xC8 |
706 | rol eax, 8 |
- | 707 | out dx, al ; LBA Low Previous LBA (31:24) |
|
- | 708 | xor eax, eax ; because only 32 bit cache |
|
- | 709 | inc edx |
|
- | 710 | out dx, al ; LBA Mid Previous LBA (39:32) |
|
- | 711 | inc edx |
|
- | 712 | out dx, al ; LBA High Previous LBA (47:40) |
|
677 | out dx, al |
713 | sub edx, 2 |
- | 714 | mov eax, [esp+4+4] |
|
- | 715 | out dx, al ; LBA Low Current LBA (7:0) |
|
- | 716 | shr eax, 8 |
|
- | 717 | inc edx |
|
- | 718 | out dx, al ; LBA Mid Current LBA (15:8) |
|
- | 719 | shr eax, 8 |
|
- | 720 | inc edx |
|
- | 721 | out dx, al ; LBA High Current LBA (23:16) |
|
- | 722 | inc edx |
|
- | 723 | mov al, byte [hdid] |
|
- | 724 | add al, 128+64+32 |
|
- | 725 | out dx, al ; номер головки/номер диска |
|
- | 726 | inc edx |
|
- | 727 | mov al, 25h ; READ DMA EXT |
|
- | 728 | out dx, al ; ATACommand регистр команд |
|
- | 729 | ;-------------------------------------- |
|
- | 730 | .continue: |
|
678 | mov dx, [IDEContrRegsBaseAddr] |
731 | mov dx, [IDEContrRegsBaseAddr] |
- | 732 | mov eax, [hd_address_table] |
|
679 | cmp [hdbase], 0x1F0 |
733 | cmp [hdbase], eax ; 0x1F0 |
680 | jz @f |
734 | jz @f |
681 | add dx, 8 |
735 | add dx, 8 |
682 | @@: |
736 | @@: |
683 | mov al, 9 |
737 | mov al, 9 |
684 | out dx, al |
738 | out dx, al |
685 | mov eax, [CURRENT_TASK] |
739 | mov eax, [CURRENT_TASK] |
686 | mov [dma_process], eax |
740 | mov [dma_process], eax |
687 | mov eax, [TASK_BASE] |
741 | mov eax, [TASK_BASE] |
688 | mov [dma_slot_ptr], eax |
742 | mov [dma_slot_ptr], eax |
- | 743 | mov eax, [hd_address_table] |
|
689 | cmp [hdbase], 0x1F0 |
744 | cmp [hdbase], eax ; 0x1F0 |
690 | jnz .ide1 |
745 | jnz .ide1 |
691 | mov [irq14_func], hdd_irq14 |
746 | mov [irq14_func], hdd_irq14 |
692 | jmp @f |
747 | jmp @f |
693 | .ide1: |
748 | .ide1: |
694 | mov [irq15_func], hdd_irq15 |
749 | mov [irq15_func], hdd_irq15 |
695 | @@: |
750 | @@: |
- | 751 | popfd |
|
696 | call enable_ide_int |
752 | mov eax, [hd_address_table] |
697 | cmp [hdbase], 0x1F0 |
753 | cmp [hdbase], eax ; 0x1F0 |
698 | jnz .wait_ide1 |
754 | jnz .wait_ide1 |
699 | call wait_for_sector_dma_ide0 |
755 | call wait_for_sector_dma_ide0 |
700 | jmp @f |
756 | jmp @f |
701 | .wait_ide1: |
757 | .wait_ide1: |
702 | call wait_for_sector_dma_ide1 |
758 | call wait_for_sector_dma_ide1 |
Line 707... | Line 763... | ||
707 | mov [dma_hdpos], eax |
763 | mov [dma_hdpos], eax |
708 | pop edx |
764 | pop edx |
709 | pop eax |
765 | pop eax |
710 | mov [dma_cur_sector], eax |
766 | mov [dma_cur_sector], eax |
711 | jmp hd_read_dma |
767 | jmp hd_read_dma |
712 | - | ||
- | 768 | ;----------------------------------------------------------------------------- |
|
713 | align 4 |
769 | align 4 |
714 | write_cache_sector: |
770 | write_cache_sector: |
715 | mov [cache_chain_size], 1 |
771 | mov [cache_chain_size], 1 |
716 | mov [cache_chain_pos], edi |
772 | mov [cache_chain_pos], edi |
- | 773 | ;-------------------------------------- |
|
- | 774 | align 4 |
|
717 | write_cache_chain: |
775 | write_cache_chain: |
718 | cmp [hdpos], 0x80 |
776 | cmp [hdpos], 0x80 |
719 | jae bd_write_cache_chain |
777 | jae bd_write_cache_chain |
720 | mov eax, [cache_chain_ptr] |
778 | mov eax, [cache_chain_ptr] |
721 | cmp dword[eax], 0x10000000 |
- | |
722 | jae .bad |
- | |
723 | push esi |
779 | push esi |
724 | mov eax, IDE_descriptor_table |
780 | mov eax, IDE_descriptor_table |
725 | mov edx, eax |
781 | mov edx, eax |
726 | pusha |
782 | pusha |
727 | mov esi, [cache_chain_pos] |
783 | mov esi, [cache_chain_pos] |
Line 750... | Line 806... | ||
750 | mov al, 0 |
806 | mov al, 0 |
751 | out dx, al |
807 | out dx, al |
752 | add edx, 2 |
808 | add edx, 2 |
753 | mov al, 6 |
809 | mov al, 6 |
754 | out dx, al |
810 | out dx, al |
- | 811 | ||
- | 812 | ; Select the desired drive |
|
- | 813 | mov edx, [hdbase] |
|
- | 814 | add edx, 6 ; адрес регистра головок |
|
- | 815 | mov al, byte [hdid] |
|
- | 816 | add al, 128+64+32 |
|
- | 817 | out dx, al ; номер головки/номер диска |
|
- | 818 | ||
755 | call wait_for_hd_idle |
819 | call wait_for_hd_idle |
756 | cmp [hd_error], 0 |
820 | cmp [hd_error], 0 |
757 | jnz hd_write_error_dma |
821 | jnz hd_write_error_dma |
- | 822 | ||
- | 823 | ; ATA with 28 or 48 bit for sector number? |
|
- | 824 | mov esi, [cache_chain_ptr] |
|
758 | call disable_ide_int |
825 | mov eax, [esi] |
- | 826 | ; -40h because the PreCache hits the boundary between lba28 and lba48 |
|
- | 827 | ; 40h = 64 - the maximum number of sectors to be written for one command |
|
- | 828 | cmp eax, 0x10000000-40h |
|
- | 829 | jae .lba48 |
|
- | 830 | ;-------------------------------------- |
|
- | 831 | .lba28: |
|
- | 832 | pushfd |
|
- | 833 | cli |
|
759 | xor eax, eax |
834 | xor eax, eax |
760 | mov edx, [hdbase] |
835 | mov edx, [hdbase] |
761 | inc edx |
836 | inc edx |
762 | out dx, al |
837 | out dx, al ; ATA Features регистр "особенностей" |
763 | inc edx |
838 | inc edx |
764 | mov al, [cache_chain_size] |
839 | mov al, [cache_chain_size] ; Sector Counter |
765 | out dx, al |
840 | out dx, al ; ATA Sector Counter счётчик секторов |
766 | inc edx |
841 | inc edx |
767 | mov esi, [cache_chain_ptr] |
- | |
768 | mov eax, [esi] |
842 | mov eax, [esi] |
769 | out dx, al |
843 | out dx, al ; LBA Low LBA (7:0) |
770 | shr eax, 8 |
844 | shr eax, 8 |
771 | inc edx |
845 | inc edx |
772 | out dx, al |
846 | out dx, al ; LBA Mid LBA (15:8) |
773 | shr eax, 8 |
847 | shr eax, 8 |
774 | inc edx |
848 | inc edx |
775 | out dx, al |
849 | out dx, al ; LBA High LBA (23:16) |
776 | shr eax, 8 |
850 | shr eax, 8 |
777 | inc edx |
851 | inc edx |
778 | and al, 0xF |
852 | and al, 0xF ; LBA (27:24) |
779 | add al, byte [hdid] |
853 | add al, byte [hdid] |
780 | add al, 11100000b |
854 | add al, 11100000b |
781 | out dx, al |
855 | out dx, al ; номер головки/номер диска |
782 | inc edx |
856 | inc edx |
- | 857 | mov al, 0xCA ; WRITE DMA |
|
- | 858 | out dx, al ; ATACommand регистр команд |
|
- | 859 | jmp .continue |
|
- | 860 | ;-------------------------------------- |
|
- | 861 | .lba48: |
|
- | 862 | pushfd |
|
- | 863 | cli |
|
- | 864 | xor eax, eax |
|
- | 865 | mov edx, [hdbase] |
|
- | 866 | inc edx |
|
- | 867 | out dx, al ; Features Previous Reserved |
|
- | 868 | out dx, al ; Features Current Reserved |
|
- | 869 | inc edx |
|
- | 870 | out dx, al ; Sector Count Previous Sector count (15:8) |
|
- | 871 | mov al, [cache_chain_size] ; Sector Counter |
|
- | 872 | out dx, al ; Sector Count Current Sector count (7:0) |
|
- | 873 | inc edx |
|
783 | mov al, 0xCA |
874 | mov eax, [esi] |
- | 875 | rol eax, 8 |
|
- | 876 | out dx, al ; LBA Low Previous LBA (31:24) |
|
- | 877 | xor eax, eax ; because only 32 bit cache |
|
- | 878 | inc edx |
|
- | 879 | out dx, al ; LBA Mid Previous LBA (39:32) |
|
- | 880 | inc edx |
|
- | 881 | out dx, al ; LBA High Previous LBA (47:40) |
|
784 | out dx, al |
882 | sub edx, 2 |
- | 883 | mov eax, [esi] |
|
- | 884 | out dx, al ; LBA Low Current LBA (7:0) |
|
- | 885 | shr eax, 8 |
|
- | 886 | inc edx |
|
- | 887 | out dx, al ; LBA Mid Current LBA (15:8) |
|
- | 888 | shr eax, 8 |
|
- | 889 | inc edx |
|
- | 890 | out dx, al ; LBA High Current LBA (23:16) |
|
- | 891 | inc edx |
|
- | 892 | mov al, byte [hdid] |
|
- | 893 | add al, 128+64+32 |
|
- | 894 | out dx, al ; номер головки/номер диска |
|
- | 895 | inc edx |
|
- | 896 | mov al, 35h ; WRITE DMA EXT |
|
- | 897 | out dx, al ; ATACommand регистр команд |
|
- | 898 | ;-------------------------------------- |
|
- | 899 | .continue: |
|
785 | mov dx, [IDEContrRegsBaseAddr] |
900 | mov dx, [IDEContrRegsBaseAddr] |
- | 901 | mov eax, [hd_address_table] |
|
786 | cmp [hdbase], 0x1F0 |
902 | cmp [hdbase], eax ; 0x1F0 |
787 | jz @f |
903 | jz @f |
788 | add dx, 8 |
904 | add dx, 8 |
789 | @@: |
905 | @@: |
790 | mov al, 1 |
906 | mov al, 1 |
791 | out dx, al |
907 | out dx, al |
792 | mov eax, [CURRENT_TASK] |
908 | mov eax, [CURRENT_TASK] |
793 | mov [dma_process], eax |
909 | mov [dma_process], eax |
794 | mov eax, [TASK_BASE] |
910 | mov eax, [TASK_BASE] |
795 | mov [dma_slot_ptr], eax |
911 | mov [dma_slot_ptr], eax |
- | 912 | mov eax, [hd_address_table] |
|
796 | cmp [hdbase], 0x1F0 |
913 | cmp [hdbase], eax ; 0x1F0 |
797 | jnz .ide1 |
914 | jnz .ide1 |
798 | mov [irq14_func], hdd_irq14 |
915 | mov [irq14_func], hdd_irq14 |
799 | jmp @f |
916 | jmp @f |
800 | .ide1: |
917 | .ide1: |
801 | mov [irq15_func], hdd_irq15 |
918 | mov [irq15_func], hdd_irq15 |
802 | @@: |
919 | @@: |
803 | call enable_ide_int |
920 | popfd |
804 | mov [dma_cur_sector], not 0x40 |
921 | mov [dma_cur_sector], not 0x40 |
- | 922 | mov eax, [hd_address_table] |
|
805 | cmp [hdbase], 0x1F0 |
923 | cmp [hdbase], eax ; 0x1F0 |
806 | jnz .wait_ide1 |
924 | jnz .wait_ide1 |
807 | call wait_for_sector_dma_ide0 |
925 | call wait_for_sector_dma_ide0 |
808 | jmp @f |
926 | jmp @f |
809 | .wait_ide1: |
927 | .wait_ide1: |
810 | call wait_for_sector_dma_ide1 |
928 | call wait_for_sector_dma_ide1 |
811 | @@: |
929 | @@: |
812 | cmp [hd_error], 0 |
930 | cmp [hd_error], 0 |
813 | jnz hd_write_error_dma |
931 | jnz hd_write_error_dma |
814 | pop esi |
932 | pop esi |
815 | ret |
933 | ret |
816 | .bad: |
- | |
817 | inc [hd_error] |
934 | ;----------------------------------------------------------------------------- |
818 | ret |
- | |
819 | - | ||
820 | uglobal |
935 | uglobal |
821 | IDEContrRegsBaseAddr dw ? |
936 | IDEContrRegsBaseAddr dw ? |
- | 937 | IDEContrProgrammingInterface dw ? |
|
- | 938 | IDE_BAR0_val dw ? |
|
- | 939 | IDE_BAR1_val dw ? |
|
- | 940 | IDE_BAR2_val dw ? |
|
- | 941 | IDE_BAR3_val dw ? |
|
822 | endg |
942 | endg |
823 | ; \end{Mario79} |
943 | ;----------------------------------------------------------------------------- |
824 | - | ||
825 | ; \begin{diamond} |
944 | ; \begin{diamond} |
826 | uglobal |
945 | uglobal |
827 | bios_hdpos dd 0 ; 0 is invalid value for [hdpos] |
946 | bios_hdpos dd 0 ; 0 is invalid value for [hdpos] |
828 | bios_cur_sector dd ? |
947 | bios_cur_sector dd ? |
829 | bios_read_len dd ? |
948 | bios_read_len dd ? |
830 | endg |
949 | endg |
- | 950 | ;----------------------------------------------------------------------------- |
|
- | 951 | align 4 |
|
831 | bd_read: |
952 | bd_read: |
832 | push eax |
953 | push eax |
833 | push edx |
954 | push edx |
834 | mov edx, [bios_hdpos] |
955 | mov edx, [bios_hdpos] |
835 | cmp edx, [hdpos] |
956 | cmp edx, [hdpos] |
Line 845... | Line 966... | ||
845 | shl eax, 9 |
966 | shl eax, 9 |
846 | add eax, (OS_BASE+0x9A000) |
967 | add eax, (OS_BASE+0x9A000) |
847 | push ecx esi edi |
968 | push ecx esi edi |
848 | mov esi, eax |
969 | mov esi, eax |
849 | shl edi, 9 |
970 | shl edi, 9 |
850 | ; add edi, HD_CACHE+0x10000 |
- | |
- | 971 | ||
851 | push eax |
972 | push eax |
852 | call calculate_cache_2 |
973 | call calculate_cache_2 |
853 | add edi, eax |
974 | add edi, eax |
854 | pop eax |
975 | pop eax |
Line 879... | Line 1000... | ||
879 | jmp bd_read |
1000 | jmp bd_read |
880 | .readerr: |
1001 | .readerr: |
881 | .v86err: |
1002 | .v86err: |
882 | mov [hd_error], 1 |
1003 | mov [hd_error], 1 |
883 | jmp hd_read_error |
1004 | jmp hd_read_error |
- | 1005 | ;----------------------------------------------------------------------------- |
|
884 | 1006 | align 4 |
|
885 | bd_write_cache_chain: |
1007 | bd_write_cache_chain: |
886 | pusha |
1008 | pusha |
887 | mov esi, [cache_chain_pos] |
1009 | mov esi, [cache_chain_pos] |
888 | shl esi, 9 |
1010 | shl esi, 9 |
889 | call calculate_cache_2 |
1011 | call calculate_cache_2 |
Line 907... | Line 1029... | ||
907 | .v86err: |
1029 | .v86err: |
908 | .writeerr: |
1030 | .writeerr: |
909 | popa |
1031 | popa |
910 | mov [hd_error], 1 |
1032 | mov [hd_error], 1 |
911 | jmp hd_write_error |
1033 | jmp hd_write_error |
912 | - | ||
- | 1034 | ;----------------------------------------------------------------------------- |
|
913 | uglobal |
1035 | uglobal |
914 | int13_regs_in rb sizeof.v86_regs |
1036 | int13_regs_in rb sizeof.v86_regs |
915 | int13_regs_out rb sizeof.v86_regs |
1037 | int13_regs_out rb sizeof.v86_regs |
916 | endg |
1038 | endg |
- | 1039 | ;----------------------------------------------------------------------------- |
|
917 | 1040 | align 4 |
|
918 | int13_call: |
1041 | int13_call: |
919 | ; Because this code uses fixed addresses, |
1042 | ; Because this code uses fixed addresses, |
920 | ; it can not be run simultaniously by many threads. |
1043 | ; it can not be run simultaniously by many threads. |
921 | ; In current implementation it is protected by common mutex 'hd1_status' |
1044 | ; In current implementation it is protected by common mutex 'hd1_status' |
922 | mov word [OS_BASE + 510h], 10h ; packet length |
1045 | mov word [OS_BASE + 510h], 10h ; packet length |
Line 963... | Line 1086... | ||
963 | jnz @f |
1086 | jnz @f |
964 | mov edx, ecx |
1087 | mov edx, ecx |
965 | @@: |
1088 | @@: |
966 | ret |
1089 | ret |
967 | ; \end{diamond} |
1090 | ; \end{diamond} |
- | 1091 | ;----------------------------------------------------------------------------- |
|
968 | 1092 | align 4 |
|
969 | reserve_hd1: |
1093 | reserve_hd1: |
970 | - | ||
971 | cli |
1094 | cli |
972 | cmp [hd1_status], 0 |
1095 | cmp [hd1_status], 0 |
973 | je reserve_ok1 |
1096 | je reserve_ok1 |
Line 974... | Line 1097... | ||
974 | 1097 | ||
975 | sti |
1098 | sti |
976 | call change_task |
1099 | call change_task |
Line 977... | Line 1100... | ||
977 | jmp reserve_hd1 |
1100 | jmp reserve_hd1 |
978 | - | ||
979 | reserve_ok1: |
1101 | |
980 | 1102 | reserve_ok1: |
|
981 | push eax |
1103 | push eax |
982 | mov eax, [CURRENT_TASK] |
1104 | mov eax, [CURRENT_TASK] |
983 | shl eax, 5 |
1105 | shl eax, 5 |
984 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
1106 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
985 | mov [hd1_status], eax |
1107 | mov [hd1_status], eax |
986 | pop eax |
1108 | pop eax |
987 | sti |
1109 | sti |
988 | ret |
- | |
989 | ;******************************************** |
1110 | ret |
990 | 1111 | ;----------------------------------------------------------------------------- |
|
991 | uglobal |
1112 | uglobal |
- | 1113 | hd_in_cache db ? |
|
992 | hd_in_cache db ? |
1114 | endg |
993 | endg |
1115 | ;----------------------------------------------------------------------------- |
994 | 1116 | align 4 |
|
995 | reserve_hd_channel: |
1117 | reserve_hd_channel: |
996 | ; BIOS disk accesses are protected with common mutex hd1_status |
1118 | ; BIOS disk accesses are protected with common mutex hd1_status |
997 | ; This must be modified when hd1_status will not be valid! |
1119 | ; This must be modified when hd1_status will not be valid! |
Line 1028... | Line 1150... | ||
1028 | mov [hd_in_cache], al |
1150 | mov [hd_in_cache], al |
1029 | pop eax |
1151 | pop eax |
1030 | sti |
1152 | sti |
1031 | .ret: |
1153 | .ret: |
1032 | ret |
1154 | ret |
1033 | - | ||
- | 1155 | ;----------------------------------------------------------------------------- |
|
1034 | free_hd_channel: |
1156 | free_hd_channel: |
1035 | ; see comment at reserve_hd_channel |
1157 | ; see comment at reserve_hd_channel |
1036 | cmp [hdpos], 0x80 |
1158 | cmp [hdpos], 0x80 |
1037 | jae .ret |
1159 | jae .ret |
1038 | cmp [hdbase], 0x1F0 |
1160 | cmp [hdbase], 0x1F0 |
Line 1042... | Line 1164... | ||
1042 | .ret: |
1164 | .ret: |
1043 | ret |
1165 | ret |
1044 | .IDE_Channel_2: |
1166 | .IDE_Channel_2: |
1045 | mov [IDE_Channel_2], 0 |
1167 | mov [IDE_Channel_2], 0 |
1046 | ret |
1168 | ret |
1047 | ;******************************************** |
1169 | ;----------------------------------------------------------------------------- |