Rev 3711 | Rev 3742 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3711 | Rev 3712 | ||
---|---|---|---|
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: 3711 $ |
8 | $Revision: 3712 $ |
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 100... | Line 89... | ||
100 | align 4 |
89 | align 4 |
101 | hd_read_pio: |
90 | hd_read_pio: |
102 | push eax edx |
91 | push eax edx |
103 | 92 | ||
104 | ; Выбрать нужный диск |
93 | ; Select the desired drive |
105 | mov edx, [hdbase] |
94 | mov edx, [hdbase] |
Line 114... | Line 103... | ||
114 | 103 | ||
115 | ; ATA with 28 or 48 bit for sector number? |
104 | ; ATA with 28 or 48 bit for sector number? |
116 | mov eax, [esp+4] |
105 | mov eax, [esp+4] |
117 | cmp eax, 0x10000000 |
106 | cmp eax, 0x10000000 |
- | 107 | jae .lba48 |
|
118 | jae .lba48 |
108 | ;-------------------------------------- |
119 | .lba28: |
109 | .lba28: |
120 | pushfd |
110 | pushfd |
121 | cli |
111 | cli |
122 | xor eax, eax |
112 | xor eax, eax |
Line 144... | Line 134... | ||
144 | inc edx |
134 | inc edx |
145 | mov al, 20h ; READ SECTOR(S) |
135 | mov al, 20h ; READ SECTOR(S) |
146 | out dx, al ; ATACommand регистр команд |
136 | out dx, al ; ATACommand регистр команд |
147 | popfd |
137 | popfd |
148 | jmp .continue |
138 | jmp .continue |
- | 139 | ;-------------------------------------- |
|
149 | .lba48: |
140 | .lba48: |
150 | pushfd |
141 | pushfd |
151 | cli |
142 | cli |
152 | xor eax, eax |
143 | xor eax, eax |
153 | mov edx, [hdbase] |
144 | mov edx, [hdbase] |
Line 182... | Line 173... | ||
182 | out dx, al; номер головки/номер диска |
173 | out dx, al ; номер головки/номер диска |
183 | inc edx |
174 | inc edx |
184 | mov al, 24h ; READ SECTOR(S) EXT |
175 | mov al, 24h ; READ SECTOR(S) EXT |
185 | out dx, al; ATACommand регистр команд |
176 | out dx, al ; ATACommand регистр команд |
186 | popfd |
177 | popfd |
- | 178 | ;-------------------------------------- |
|
187 | .continue: |
179 | .continue: |
188 | call wait_for_sector_buffer |
180 | call wait_for_sector_buffer |
Line 189... | Line 181... | ||
189 | 181 | ||
190 | cmp [hd_error], 0 |
182 | cmp [hd_error], 0 |
Line -... | Line 183... | ||
- | 183 | jne hd_read_error |
|
191 | jne hd_read_error |
184 | |
192 | 185 | pushfd |
|
193 | cli |
186 | cli |
194 | push edi |
- | |
- | 187 | push edi |
|
195 | shl edi, 9 |
188 | shl edi, 9 |
196 | ; add edi,HD_CACHE+65536 |
189 | |
197 | push eax |
190 | push eax |
198 | call calculate_cache_2 |
191 | call calculate_cache_2 |
Line 199... | Line 192... | ||
199 | add edi, eax |
192 | add edi, eax |
200 | pop eax |
193 | pop eax |
201 | 194 | ||
202 | mov ecx, 256 |
195 | mov ecx, 256 |
203 | mov edx, [hdbase] |
196 | mov edx, [hdbase] |
204 | cld |
197 | cld |
Line 205... | Line 198... | ||
205 | rep insw |
198 | rep insw |
206 | pop edi |
199 | pop edi |
207 | sti |
- | |
208 | - | ||
209 | pop edx eax |
200 | popfd |
210 | ret |
- | |
211 | - | ||
212 | disable_ide_int: |
- | |
213 | ; mov edx,[hdbase] |
- | |
214 | ; add edx,0x206 |
- | |
215 | ; mov al,2 |
- | |
216 | ; out dx,al |
- | |
217 | cli |
- | |
218 | ret |
- | |
219 | - | ||
220 | enable_ide_int: |
- | |
221 | ; mov edx,[hdbase] |
- | |
222 | ; add edx,0x206 |
- | |
223 | ; mov al,0 |
- | |
224 | ; out dx,al |
201 | |
225 | sti |
202 | pop edx eax |
226 | ret |
203 | ret |
227 | 204 | ;----------------------------------------------------------------------------- |
|
228 | align 4 |
205 | align 4 |
229 | hd_write: |
206 | hd_write: |
230 | ;----------------------------------------------------------- |
207 | ;----------------------------------------------------------- |
Line 231... | Line 208... | ||
231 | ; input : eax = block |
208 | ; input : eax = block |
232 | ; ebx = pointer to memory |
- | |
233 | ;----------------------------------------------------------- |
- | |
234 | push ecx esi edi |
- | |
235 | 209 | ; ebx = pointer to memory |
|
236 | ; check if the cache already has the sector and overwrite it |
210 | ;----------------------------------------------------------- |
237 | - | ||
238 | ; mov ecx,cache_max |
211 | push ecx esi edi |
Line 239... | Line 212... | ||
239 | ; mov esi,HD_CACHE+8 |
212 | |
240 | call calculate_cache |
- | |
241 | add esi, 8 |
213 | ; check if the cache already has the sector and overwrite it |
242 | 214 | call calculate_cache |
|
Line 243... | Line 215... | ||
243 | mov edi, 1 |
215 | add esi, 8 |
244 | 216 | mov edi, 1 |
|
Line 245... | Line 217... | ||
245 | hdwritecache: |
217 | |
246 | - | ||
247 | cmp dword [esi+4], 0; if cache slot is empty |
218 | hdwritecache: |
248 | je not_in_cache_write |
219 | cmp dword [esi+4], 0 ; if cache slot is empty |
249 | 220 | je not_in_cache_write |
|
250 | cmp [esi], eax ; if the slot has the sector |
221 | |
Line 251... | Line 222... | ||
251 | je yes_in_cache_write |
222 | cmp [esi], eax ; if the slot has the sector |
252 | 223 | je yes_in_cache_write |
|
253 | not_in_cache_write: |
- | |
254 | 224 | ||
255 | add esi, 8 |
225 | not_in_cache_write: |
256 | inc edi |
226 | add esi, 8 |
Line 257... | Line -... | ||
257 | dec ecx |
- | |
258 | jnz hdwritecache |
- | |
259 | 227 | inc edi |
|
260 | ; sector not found in cache |
228 | dec ecx |
261 | ; write the block to a new location |
- | |
262 | - | ||
263 | call find_empty_slot ; ret in edi |
229 | jnz hdwritecache |
Line 264... | Line 230... | ||
264 | cmp [hd_error], 0 |
230 | |
265 | jne hd_write_access_denied |
- | |
266 | 231 | ; sector not found in cache |
|
Line 267... | Line 232... | ||
267 | ; lea esi,[edi*8+HD_CACHE] |
232 | ; write the block to a new location |
268 | ; push eax |
- | |
- | 233 | call find_empty_slot ; ret in edi |
|
269 | call calculate_cache_1 |
234 | cmp [hd_error], 0 |
270 | lea esi, [edi*8+esi] |
235 | jne hd_write_access_denied |
271 | ; pop eax |
236 | |
272 | 237 | call calculate_cache_1 |
|
Line 273... | Line 238... | ||
273 | mov [esi], eax ; sector number |
238 | lea esi, [edi*8+esi] |
274 | 239 | mov [esi], eax ; sector number |
|
275 | yes_in_cache_write: |
240 | |
276 | 241 | yes_in_cache_write: |
|
- | 242 | mov dword [esi+4], 2 ; write - differs from hd |
|
277 | mov dword [esi+4], 2; write - differs from hd |
243 | |
278 | 244 | shl edi, 9 |
|
279 | shl edi, 9 |
245 | |
280 | ; add edi,HD_CACHE+65536 |
- | |
- | 246 | push eax |
|
281 | push eax |
247 | call calculate_cache_2 |
282 | call calculate_cache_2 |
248 | add edi, eax |
283 | add edi, eax |
249 | pop eax |
284 | pop eax |
- | |
285 | - | ||
286 | mov esi, ebx |
250 | |
287 | mov ecx, 512/4 |
251 | mov esi, ebx |
288 | cld |
252 | mov ecx, 512/4 |
289 | rep movsd ; move data |
253 | cld |
290 | hd_write_access_denied: |
254 | rep movsd ; move data |
Line 308... | Line 272... | ||
308 | 272 | ||
309 | ; ATA with 28 or 48 bit for sector number? |
273 | ; ATA with 28 or 48 bit for sector number? |
310 | mov eax, [esi] |
274 | mov eax, [esi] |
311 | cmp eax, 0x10000000 |
275 | cmp eax, 0x10000000 |
- | 276 | jae .lba48 |
|
312 | jae .lba48 |
277 | ;-------------------------------------- |
313 | .lba28: |
278 | .lba28: |
314 | pushfd |
279 | pushfd |
315 | cli |
280 | cli |
316 | xor eax, eax |
281 | xor eax, eax |
Line 338... | Line 303... | ||
338 | inc edx |
303 | inc edx |
339 | mov al, 30h ; WRITE SECTOR(S) |
304 | mov al, 30h ; WRITE SECTOR(S) |
340 | out dx, al ; ATACommand регистр команд |
305 | out dx, al ; ATACommand регистр команд |
341 | popfd |
306 | popfd |
342 | jmp .continue |
307 | jmp .continue |
- | 308 | ;-------------------------------------- |
|
343 | .lba48: |
309 | .lba48: |
344 | pushfd |
310 | pushfd |
345 | cli |
311 | cli |
346 | xor eax, eax |
312 | xor eax, eax |
347 | mov edx, [hdbase] |
313 | mov edx, [hdbase] |
Line 376... | Line 342... | ||
376 | out dx, al; номер головки/номер диска |
342 | out dx, al ; номер головки/номер диска |
377 | inc edx |
343 | inc edx |
378 | mov al, 34h ; WRITE SECTOR(S) EXT |
344 | mov al, 34h ; WRITE SECTOR(S) EXT |
379 | out dx, al; ATACommand регистр команд |
345 | out dx, al ; ATACommand регистр команд |
380 | popfd |
346 | popfd |
- | 347 | ;-------------------------------------- |
|
381 | .continue: |
348 | .continue: |
382 | call wait_for_sector_buffer |
349 | call wait_for_sector_buffer |
Line 383... | Line 350... | ||
383 | 350 | ||
384 | cmp [hd_error], 0 |
351 | cmp [hd_error], 0 |
Line 385... | Line 352... | ||
385 | jne hd_write_error |
352 | jne hd_write_error |
Line -... | Line 353... | ||
- | 353 | ||
386 | 354 | push ecx esi |
|
387 | push ecx esi |
355 | |
388 | 356 | pushfd |
|
389 | cli |
- | |
- | 357 | cli |
|
390 | mov esi, edi |
358 | mov esi, edi |
391 | shl esi, 9 |
359 | shl esi, 9 |
392 | ; add esi,HD_CACHE+65536 ; esi = from memory position |
360 | |
393 | push eax |
361 | push eax |
Line 394... | Line 362... | ||
394 | call calculate_cache_2 |
362 | call calculate_cache_2 |
395 | add esi, eax |
363 | add esi, eax |
396 | pop eax |
364 | pop eax |
397 | 365 | ||
398 | mov ecx, 256 |
366 | mov ecx, 256 |
Line 399... | Line -... | ||
399 | mov edx, [hdbase] |
- | |
400 | cld |
367 | mov edx, [hdbase] |
401 | rep outsw |
- | |
402 | sti |
368 | cld |
- | 369 | rep outsw |
|
403 | 370 | popfd |
|
404 | ; call enable_ide_int |
371 | |
405 | pop esi ecx |
- | |
406 | 372 | pop esi ecx |
|
407 | ret |
373 | ret |
408 | 374 | ;----------------------------------------------------------------------------- |
|
409 | save_hd_wait_timeout: |
375 | align 4 |
410 | 376 | save_hd_wait_timeout: |
|
411 | push eax |
377 | push eax |
412 | mov eax, [timer_ticks] |
- | |
- | 378 | mov eax, [timer_ticks] |
|
413 | add eax, 300 ; 3 sec timeout |
379 | add eax, 300 ; 3 sec timeout |
414 | mov [hd_wait_timeout], eax |
380 | mov [hd_wait_timeout], eax |
415 | pop eax |
- | |
416 | ret |
381 | pop eax |
417 | 382 | ret |
|
418 | align 4 |
383 | ;----------------------------------------------------------------------------- |
419 | check_hd_wait_timeout: |
384 | align 4 |
- | 385 | check_hd_wait_timeout: |
|
420 | 386 | push eax |
|
421 | push eax |
387 | mov eax, [hd_wait_timeout] |
422 | mov eax, [hd_wait_timeout] |
388 | cmp [timer_ticks], eax |
423 | cmp [timer_ticks], eax |
- | |
424 | jg hd_timeout_error |
- | |
425 | pop eax |
- | |
426 | mov [hd_error], 0 |
- | |
427 | ret |
389 | jg hd_timeout_error |
428 | - | ||
429 | ;iglobal |
- | |
430 | ; hd_timeout_str db 'K : FS - HD timeout',0 |
- | |
431 | ; hd_read_str db 'K : FS - HD read error',0 |
390 | |
432 | ; hd_write_str db 'K : FS - HD write error',0 |
- | |
433 | ; hd_lba_str db 'K : FS - HD LBA error',0 |
- | |
434 | ;endg |
- | |
435 | - | ||
436 | hd_timeout_error: |
- | |
437 | 391 | pop eax |
|
438 | ; call clear_hd_cache |
392 | mov [hd_error], 0 |
439 | ; call clear_application_table_status |
393 | ret |
440 | ; mov esi,hd_timeout_str |
394 | ;----------------------------------------------------------------------------- |
441 | ; call sys_msg_board_str |
395 | hd_timeout_error: |
442 | if lang eq sp |
- | |
443 | DEBUGF 1,"K : FS - HD tiempo de espera agotado\n" |
396 | if lang eq sp |
444 | else |
397 | DEBUGF 1,"K : FS - HD tiempo de espera agotado\n" |
445 | DEBUGF 1,"K : FS - HD timeout\n" |
398 | else |
446 | end if |
- | |
- | 399 | DEBUGF 1,"K : FS - HD timeout\n" |
|
447 | 400 | end if |
|
448 | mov [hd_error], 1 |
- | |
449 | pop eax |
- | |
450 | ret |
- | |
451 | - | ||
452 | hd_read_error: |
- | |
453 | 401 | mov [hd_error], 1 |
|
454 | ; call clear_hd_cache |
402 | pop eax |
455 | ; call clear_application_table_status |
403 | ret |
456 | ; mov esi,hd_read_str |
404 | ;----------------------------------------------------------------------------- |
457 | ; call sys_msg_board_str |
405 | hd_read_error: |
458 | if lang eq sp |
406 | if lang eq sp |
459 | DEBUGF 1,"K : FS - HD error de lectura\n" |
407 | DEBUGF 1,"K : FS - HD error de lectura\n" |
460 | else |
- | |
461 | DEBUGF 1,"K : FS - HD read error\n" |
- | |
462 | end if |
- | |
463 | pop edx eax |
- | |
464 | ret |
- | |
465 | - | ||
466 | hd_write_error: |
- | |
467 | - | ||
468 | ; call clear_hd_cache |
408 | else |
469 | ; call clear_application_table_status |
- | |
470 | ; mov esi,hd_write_str |
- | |
471 | ; call sys_msg_board_str |
- | |
472 | if lang eq sp |
- | |
473 | DEBUGF 1,"K : FS - HD error de escritura\n" |
- | |
474 | else |
409 | DEBUGF 1,"K : FS - HD read error\n" |
475 | DEBUGF 1,"K : FS - HD write error\n" |
410 | end if |
476 | end if |
- | |
477 | ret |
411 | pop edx eax |
478 | - | ||
479 | hd_write_error_dma: |
412 | ret |
480 | ; call clear_hd_cache |
413 | ;----------------------------------------------------------------------------- |
481 | ; call clear_application_table_status |
414 | hd_write_error_dma: |
482 | ; mov esi, hd_write_str |
415 | pop esi |
483 | ; call sys_msg_board_str |
416 | hd_write_error: |
484 | if lang eq sp |
- | |
485 | DEBUGF 1,"K : FS - HD error de escritura\n" |
417 | if lang eq sp |
486 | else |
- | |
- | 418 | DEBUGF 1,"K : FS - HD error de escritura\n" |
|
487 | DEBUGF 1,"K : FS - HD write error\n" |
419 | else |
488 | end if |
- | |
489 | pop esi |
- | |
490 | ret |
- | |
491 | - | ||
492 | hd_lba_error: |
420 | DEBUGF 1,"K : FS - HD write error\n" |
493 | ; call clear_hd_cache |
421 | end if |
494 | ; call clear_application_table_status |
422 | ret |
495 | ; mov esi,hd_lba_str |
423 | ;----------------------------------------------------------------------------- |
496 | ; call sys_msg_board_str |
424 | hd_lba_error: |
497 | if lang eq sp |
425 | if lang eq sp |
498 | DEBUGF 1,"K : FS - HD error en LBA\n" |
- | |
499 | else |
- | |
- | 426 | DEBUGF 1,"K : FS - HD error en LBA\n" |
|
500 | DEBUGF 1,"K : FS - HD LBA error\n" |
427 | else |
501 | end if |
428 | DEBUGF 1,"K : FS - HD LBA error\n" |
502 | jmp LBA_read_ret |
- | |
503 | 429 | end if |
|
Line 504... | Line 430... | ||
504 | 430 | jmp LBA_read_ret |
|
Line 505... | Line 431... | ||
505 | align 4 |
431 | ;----------------------------------------------------------------------------- |
506 | wait_for_hd_idle: |
432 | align 4 |
- | 433 | wait_for_hd_idle: |
|
507 | 434 | push eax edx |
|
508 | push eax edx |
435 | |
509 | - | ||
510 | call save_hd_wait_timeout |
436 | call save_hd_wait_timeout |
511 | 437 | ||
512 | mov edx, [hdbase] |
438 | mov edx, [hdbase] |
Line 513... | Line 439... | ||
513 | add edx, 0x7 |
439 | add edx, 0x7 |
514 | 440 | ;-------------------------------------- |
|
515 | wfhil1: |
441 | align 4 |
Line 516... | Line 442... | ||
516 | 442 | wfhil1: |
|
517 | call check_hd_wait_timeout |
- | |
518 | cmp [hd_error], 0 |
443 | call check_hd_wait_timeout |
519 | jne @f |
444 | cmp [hd_error], 0 |
520 | - | ||
521 | in al, dx |
- | |
- | 445 | jne @f |
|
522 | test al, 128 |
446 | |
523 | jnz wfhil1 |
447 | in al, dx |
524 | - | ||
525 | @@: |
448 | test al, 128 |
Line 526... | Line 449... | ||
526 | 449 | jnz wfhil1 |
|
527 | pop edx eax |
450 | |
Line 528... | Line 451... | ||
528 | ret |
451 | @@: |
- | 452 | pop edx eax |
|
529 | 453 | ret |
|
530 | 454 | ;----------------------------------------------------------------------------- |
|
531 | align 4 |
- | |
532 | wait_for_sector_buffer: |
455 | align 4 |
533 | 456 | wait_for_sector_buffer: |
|
534 | push eax edx |
457 | push eax edx |
Line 535... | Line 458... | ||
535 | 458 | ||
Line 557... | Line 480... | ||
557 | jz buf_wait_ok |
480 | jz buf_wait_ok |
558 | @@: |
481 | @@: |
559 | mov [hd_error], 1 |
482 | mov [hd_error], 1 |
Line 560... | Line 483... | ||
560 | 483 | ||
561 | buf_wait_ok: |
- | |
562 | 484 | buf_wait_ok: |
|
563 | pop edx eax |
485 | pop edx eax |
564 | ret |
- | |
565 | 486 | ret |
|
566 | ; \begin{Mario79} |
487 | ;----------------------------------------------------------------------------- |
567 | align 4 |
488 | align 4 |
568 | wait_for_sector_dma_ide0: |
489 | wait_for_sector_dma_ide0: |
569 | push eax |
490 | push eax |
570 | push edx |
491 | push edx |
- | 492 | call save_hd_wait_timeout |
|
- | 493 | ;-------------------------------------- |
|
571 | call save_hd_wait_timeout |
494 | align 4 |
572 | .wait: |
495 | .wait: |
573 | call change_task |
496 | call change_task |
574 | cmp [irq14_func], hdd_irq14 |
497 | cmp [irq14_func], hdd_irq14 |
575 | jnz .done |
498 | jnz .done |
Line 582... | Line 505... | ||
582 | out dx, al |
505 | out dx, al |
583 | .done: |
506 | .done: |
584 | pop edx |
507 | pop edx |
585 | pop eax |
508 | pop eax |
586 | ret |
509 | ret |
587 | - | ||
- | 510 | ;----------------------------------------------------------------------------- |
|
588 | align 4 |
511 | align 4 |
589 | wait_for_sector_dma_ide1: |
512 | wait_for_sector_dma_ide1: |
590 | push eax |
513 | push eax |
591 | push edx |
514 | push edx |
592 | call save_hd_wait_timeout |
515 | call save_hd_wait_timeout |
- | 516 | ;-------------------------------------- |
|
- | 517 | align 4 |
|
593 | .wait: |
518 | .wait: |
594 | call change_task |
519 | call change_task |
595 | cmp [irq15_func], hdd_irq15 |
520 | cmp [irq15_func], hdd_irq15 |
596 | jnz .done |
521 | jnz .done |
597 | call check_hd_wait_timeout |
522 | call check_hd_wait_timeout |
Line 604... | Line 529... | ||
604 | out dx, al |
529 | out dx, al |
605 | .done: |
530 | .done: |
606 | pop edx |
531 | pop edx |
607 | pop eax |
532 | pop eax |
608 | ret |
533 | ret |
609 | - | ||
- | 534 | ;----------------------------------------------------------------------------- |
|
610 | iglobal |
535 | iglobal |
611 | align 4 |
536 | align 4 |
612 | ; 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 |
613 | IDE_descriptor_table: |
538 | IDE_descriptor_table: |
614 | dd IDE_DMA |
539 | dd IDE_DMA |
Line 618... | Line 543... | ||
618 | dma_cur_sector dd not 40h |
543 | dma_cur_sector dd not 40h |
619 | dma_hdpos dd 0 |
544 | dma_hdpos dd 0 |
620 | irq14_func dd hdd_irq_null |
545 | irq14_func dd hdd_irq_null |
621 | irq15_func dd hdd_irq_null |
546 | irq15_func dd hdd_irq_null |
622 | endg |
547 | endg |
623 | - | ||
- | 548 | ;----------------------------------------------------------------------------- |
|
624 | uglobal |
549 | uglobal |
625 | ; all uglobals are zeroed at boot |
550 | ; all uglobals are zeroed at boot |
626 | dma_process dd 0 |
551 | dma_process dd 0 |
627 | dma_slot_ptr dd 0 |
552 | dma_slot_ptr dd 0 |
628 | cache_chain_pos dd 0 |
553 | cache_chain_pos dd 0 |
Line 631... | Line 556... | ||
631 | cache_chain_started db 0 |
556 | cache_chain_started db 0 |
632 | dma_task_switched db 0 |
557 | dma_task_switched db 0 |
633 | dma_hdd db 0 |
558 | dma_hdd db 0 |
634 | allow_dma_access db 0 |
559 | allow_dma_access db 0 |
635 | endg |
560 | endg |
636 | - | ||
- | 561 | ;----------------------------------------------------------------------------- |
|
637 | align 4 |
562 | align 4 |
638 | hdd_irq14: |
563 | hdd_irq14: |
639 | pushfd |
564 | pushfd |
640 | cli |
565 | cli |
641 | pushad |
566 | pushad |
642 | mov [irq14_func], hdd_irq_null |
567 | mov [irq14_func], hdd_irq_null |
643 | mov dx, [IDEContrRegsBaseAddr] |
568 | mov dx, [IDEContrRegsBaseAddr] |
644 | mov al, 0 |
569 | mov al, 0 |
645 | out dx, al |
570 | out dx, al |
646 | ; call update_counters |
- | |
647 | ; mov ebx, [dma_process] |
- | |
648 | ; cmp [CURRENT_TASK], ebx |
- | |
649 | ; jz .noswitch |
- | |
650 | ; mov [dma_task_switched], 1 |
- | |
651 | ; mov edi, [dma_slot_ptr] |
- | |
652 | ; mov eax, [CURRENT_TASK] |
- | |
653 | ; mov [dma_process], eax |
- | |
654 | ; mov eax, [TASK_BASE] |
- | |
655 | ; mov [dma_slot_ptr], eax |
- | |
656 | ; mov [CURRENT_TASK], ebx |
- | |
657 | ; mov [TASK_BASE], edi |
- | |
658 | ; mov byte [DONT_SWITCH], 1 |
- | |
659 | ; call do_change_task |
- | |
660 | .noswitch: |
- | |
661 | popad |
571 | popad |
662 | popfd |
572 | popfd |
663 | align 4 |
573 | align 4 |
664 | hdd_irq_null: |
574 | hdd_irq_null: |
665 | ret |
575 | ret |
666 | - | ||
- | 576 | ;----------------------------------------------------------------------------- |
|
667 | align 4 |
577 | align 4 |
668 | hdd_irq15: |
578 | hdd_irq15: |
669 | pushfd |
579 | pushfd |
670 | cli |
580 | cli |
671 | pushad |
581 | pushad |
672 | mov [irq15_func], hdd_irq_null |
582 | mov [irq15_func], hdd_irq_null |
673 | mov dx, [IDEContrRegsBaseAddr] |
583 | mov dx, [IDEContrRegsBaseAddr] |
674 | add dx, 8 |
584 | add dx, 8 |
675 | mov al, 0 |
585 | mov al, 0 |
676 | out dx, al |
586 | out dx, al |
677 | ; call update_counters |
- | |
678 | ; mov ebx, [dma_process] |
- | |
679 | ; cmp [CURRENT_TASK], ebx |
- | |
680 | ; jz .noswitch |
- | |
681 | ; mov [dma_task_switched], 1 |
- | |
682 | ; mov edi, [dma_slot_ptr] |
- | |
683 | ; mov eax, [CURRENT_TASK] |
- | |
684 | ; mov [dma_process], eax |
- | |
685 | ; mov eax, [TASK_BASE] |
- | |
686 | ; mov [dma_slot_ptr], eax |
- | |
687 | ; mov [CURRENT_TASK], ebx |
- | |
688 | ; mov [TASK_BASE], edi |
- | |
689 | ; mov byte [DONT_SWITCH], 1 |
- | |
690 | ; call do_change_task |
- | |
691 | .noswitch: |
- | |
692 | popad |
587 | popad |
693 | popfd |
588 | popfd |
694 | ret |
589 | ret |
695 | - | ||
- | 590 | ;----------------------------------------------------------------------------- |
|
696 | align 4 |
591 | align 4 |
697 | hd_read_dma: |
592 | hd_read_dma: |
698 | ; hd_read_dma use old ATA with 28 bit for sector number |
- | |
699 | cmp eax, 0x10000000 |
- | |
700 | jb @f |
- | |
701 | inc [hd_error] |
- | |
702 | ret |
- | |
703 | @@: |
- | |
704 | push eax |
593 | push eax |
705 | push edx |
594 | push edx |
706 | mov edx, [dma_hdpos] |
595 | mov edx, [dma_hdpos] |
707 | cmp edx, [hdpos] |
596 | cmp edx, [hdpos] |
708 | jne .notread |
597 | jne .notread |
Line 717... | Line 606... | ||
717 | shl eax, 9 |
606 | shl eax, 9 |
718 | add eax, (OS_BASE+IDE_DMA) |
607 | add eax, (OS_BASE+IDE_DMA) |
719 | push ecx esi edi |
608 | push ecx esi edi |
720 | mov esi, eax |
609 | mov esi, eax |
721 | shl edi, 9 |
610 | shl edi, 9 |
722 | ; add edi, HD_CACHE+0x10000 |
- | |
- | 611 | ||
723 | push eax |
612 | push eax |
724 | call calculate_cache_2 |
613 | call calculate_cache_2 |
725 | add edi, eax |
614 | add edi, eax |
726 | pop eax |
615 | pop eax |
Line 749... | Line 638... | ||
749 | mov al, 0 |
638 | mov al, 0 |
750 | out dx, al |
639 | out dx, al |
751 | add edx, 2 |
640 | add edx, 2 |
752 | mov al, 6 |
641 | mov al, 6 |
753 | 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 | ||
754 | call wait_for_hd_idle |
651 | call wait_for_hd_idle |
755 | cmp [hd_error], 0 |
652 | cmp [hd_error], 0 |
756 | jnz hd_read_error |
653 | jnz hd_read_error |
- | 654 | ||
- | 655 | ; ATA with 28 or 48 bit for sector number? |
|
757 | 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 |
|
758 | xor eax, eax |
665 | xor eax, eax |
759 | mov edx, [hdbase] |
666 | mov edx, [hdbase] |
760 | inc edx |
667 | inc edx |
761 | out dx, al |
668 | out dx, al ; ATA Features регистр "особенностей" |
762 | inc edx |
669 | inc edx |
763 | mov eax, 10h |
670 | mov eax, 10h ; Sector Counter = 16 ; PreCache |
764 | out dx, al |
671 | out dx, al ; ATA Sector Counter счётчик секторов |
765 | inc edx |
672 | inc edx |
766 | mov eax, [esp+4] |
673 | mov eax, [esp+4+4] |
767 | out dx, al |
674 | out dx, al ; LBA Low LBA (7:0) |
768 | shr eax, 8 |
675 | shr eax, 8 |
769 | inc edx |
676 | inc edx |
770 | out dx, al |
677 | out dx, al ; LBA Mid LBA (15:8) |
771 | shr eax, 8 |
678 | shr eax, 8 |
772 | inc edx |
679 | inc edx |
773 | out dx, al |
680 | out dx, al ; LBA High LBA (23:16) |
774 | shr eax, 8 |
681 | shr eax, 8 |
775 | inc edx |
682 | inc edx |
776 | and al, 0xF |
683 | and al, 0xF ; LBA (27:24) |
777 | add al, byte [hdid] |
684 | add al, byte [hdid] |
778 | add al, 11100000b |
685 | add al, 11100000b |
779 | out dx, al |
686 | out dx, al ; номер головки/номер диска |
780 | 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] |
|
781 | 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) |
|
782 | 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: |
|
783 | mov dx, [IDEContrRegsBaseAddr] |
731 | mov dx, [IDEContrRegsBaseAddr] |
- | 732 | mov eax, [hd_address_table] |
|
784 | cmp [hdbase], 0x1F0 |
733 | cmp [hdbase], eax ; 0x1F0 |
785 | jz @f |
734 | jz @f |
786 | add dx, 8 |
735 | add dx, 8 |
787 | @@: |
736 | @@: |
788 | mov al, 9 |
737 | mov al, 9 |
789 | out dx, al |
738 | out dx, al |
790 | mov eax, [CURRENT_TASK] |
739 | mov eax, [CURRENT_TASK] |
791 | mov [dma_process], eax |
740 | mov [dma_process], eax |
792 | mov eax, [TASK_BASE] |
741 | mov eax, [TASK_BASE] |
793 | mov [dma_slot_ptr], eax |
742 | mov [dma_slot_ptr], eax |
- | 743 | mov eax, [hd_address_table] |
|
794 | cmp [hdbase], 0x1F0 |
744 | cmp [hdbase], eax ; 0x1F0 |
795 | jnz .ide1 |
745 | jnz .ide1 |
796 | mov [irq14_func], hdd_irq14 |
746 | mov [irq14_func], hdd_irq14 |
797 | jmp @f |
747 | jmp @f |
798 | .ide1: |
748 | .ide1: |
799 | mov [irq15_func], hdd_irq15 |
749 | mov [irq15_func], hdd_irq15 |
800 | @@: |
750 | @@: |
- | 751 | popfd |
|
801 | call enable_ide_int |
752 | mov eax, [hd_address_table] |
802 | cmp [hdbase], 0x1F0 |
753 | cmp [hdbase], eax ; 0x1F0 |
803 | jnz .wait_ide1 |
754 | jnz .wait_ide1 |
804 | call wait_for_sector_dma_ide0 |
755 | call wait_for_sector_dma_ide0 |
805 | jmp @f |
756 | jmp @f |
806 | .wait_ide1: |
757 | .wait_ide1: |
807 | call wait_for_sector_dma_ide1 |
758 | call wait_for_sector_dma_ide1 |
Line 812... | Line 763... | ||
812 | mov [dma_hdpos], eax |
763 | mov [dma_hdpos], eax |
813 | pop edx |
764 | pop edx |
814 | pop eax |
765 | pop eax |
815 | mov [dma_cur_sector], eax |
766 | mov [dma_cur_sector], eax |
816 | jmp hd_read_dma |
767 | jmp hd_read_dma |
817 | - | ||
- | 768 | ;----------------------------------------------------------------------------- |
|
818 | align 4 |
769 | align 4 |
819 | write_cache_sector: |
770 | write_cache_sector: |
820 | mov [cache_chain_size], 1 |
771 | mov [cache_chain_size], 1 |
821 | mov [cache_chain_pos], edi |
772 | mov [cache_chain_pos], edi |
- | 773 | ;-------------------------------------- |
|
- | 774 | align 4 |
|
822 | write_cache_chain: |
775 | write_cache_chain: |
823 | cmp [hdpos], 0x80 |
776 | cmp [hdpos], 0x80 |
824 | jae bd_write_cache_chain |
777 | jae bd_write_cache_chain |
825 | mov eax, [cache_chain_ptr] |
778 | mov eax, [cache_chain_ptr] |
826 | cmp dword[eax], 0x10000000 |
- | |
827 | jae .bad |
- | |
828 | push esi |
779 | push esi |
829 | mov eax, IDE_descriptor_table |
780 | mov eax, IDE_descriptor_table |
830 | mov edx, eax |
781 | mov edx, eax |
831 | pusha |
782 | pusha |
832 | mov esi, [cache_chain_pos] |
783 | mov esi, [cache_chain_pos] |
Line 855... | Line 806... | ||
855 | mov al, 0 |
806 | mov al, 0 |
856 | out dx, al |
807 | out dx, al |
857 | add edx, 2 |
808 | add edx, 2 |
858 | mov al, 6 |
809 | mov al, 6 |
859 | 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 | ||
860 | call wait_for_hd_idle |
819 | call wait_for_hd_idle |
861 | cmp [hd_error], 0 |
820 | cmp [hd_error], 0 |
862 | 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] |
|
863 | 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 |
|
864 | xor eax, eax |
834 | xor eax, eax |
865 | mov edx, [hdbase] |
835 | mov edx, [hdbase] |
866 | inc edx |
836 | inc edx |
867 | out dx, al |
837 | out dx, al ; ATA Features регистр "особенностей" |
868 | inc edx |
838 | inc edx |
869 | mov al, [cache_chain_size] |
839 | mov al, [cache_chain_size] ; Sector Counter |
870 | out dx, al |
840 | out dx, al ; ATA Sector Counter счётчик секторов |
871 | inc edx |
841 | inc edx |
872 | mov esi, [cache_chain_ptr] |
- | |
873 | mov eax, [esi] |
842 | mov eax, [esi] |
874 | out dx, al |
843 | out dx, al ; LBA Low LBA (7:0) |
875 | shr eax, 8 |
844 | shr eax, 8 |
876 | inc edx |
845 | inc edx |
877 | out dx, al |
846 | out dx, al ; LBA Mid LBA (15:8) |
878 | shr eax, 8 |
847 | shr eax, 8 |
879 | inc edx |
848 | inc edx |
880 | out dx, al |
849 | out dx, al ; LBA High LBA (23:16) |
881 | shr eax, 8 |
850 | shr eax, 8 |
882 | inc edx |
851 | inc edx |
883 | and al, 0xF |
852 | and al, 0xF ; LBA (27:24) |
884 | add al, byte [hdid] |
853 | add al, byte [hdid] |
885 | add al, 11100000b |
854 | add al, 11100000b |
886 | out dx, al |
855 | out dx, al ; номер головки/номер диска |
887 | 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 |
|
888 | 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) |
|
889 | 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: |
|
890 | mov dx, [IDEContrRegsBaseAddr] |
900 | mov dx, [IDEContrRegsBaseAddr] |
- | 901 | mov eax, [hd_address_table] |
|
891 | cmp [hdbase], 0x1F0 |
902 | cmp [hdbase], eax ; 0x1F0 |
892 | jz @f |
903 | jz @f |
893 | add dx, 8 |
904 | add dx, 8 |
894 | @@: |
905 | @@: |
895 | mov al, 1 |
906 | mov al, 1 |
896 | out dx, al |
907 | out dx, al |
897 | mov eax, [CURRENT_TASK] |
908 | mov eax, [CURRENT_TASK] |
898 | mov [dma_process], eax |
909 | mov [dma_process], eax |
899 | mov eax, [TASK_BASE] |
910 | mov eax, [TASK_BASE] |
900 | mov [dma_slot_ptr], eax |
911 | mov [dma_slot_ptr], eax |
- | 912 | mov eax, [hd_address_table] |
|
901 | cmp [hdbase], 0x1F0 |
913 | cmp [hdbase], eax ; 0x1F0 |
902 | jnz .ide1 |
914 | jnz .ide1 |
903 | mov [irq14_func], hdd_irq14 |
915 | mov [irq14_func], hdd_irq14 |
904 | jmp @f |
916 | jmp @f |
905 | .ide1: |
917 | .ide1: |
906 | mov [irq15_func], hdd_irq15 |
918 | mov [irq15_func], hdd_irq15 |
907 | @@: |
919 | @@: |
908 | call enable_ide_int |
920 | popfd |
909 | mov [dma_cur_sector], not 0x40 |
921 | mov [dma_cur_sector], not 0x40 |
- | 922 | mov eax, [hd_address_table] |
|
910 | cmp [hdbase], 0x1F0 |
923 | cmp [hdbase], eax ; 0x1F0 |
911 | jnz .wait_ide1 |
924 | jnz .wait_ide1 |
912 | call wait_for_sector_dma_ide0 |
925 | call wait_for_sector_dma_ide0 |
913 | jmp @f |
926 | jmp @f |
914 | .wait_ide1: |
927 | .wait_ide1: |
915 | call wait_for_sector_dma_ide1 |
928 | call wait_for_sector_dma_ide1 |
916 | @@: |
929 | @@: |
917 | cmp [hd_error], 0 |
930 | cmp [hd_error], 0 |
918 | jnz hd_write_error_dma |
931 | jnz hd_write_error_dma |
919 | pop esi |
932 | pop esi |
920 | ret |
933 | ret |
921 | .bad: |
- | |
922 | inc [hd_error] |
934 | ;----------------------------------------------------------------------------- |
923 | ret |
- | |
924 | - | ||
925 | uglobal |
935 | uglobal |
926 | IDEContrRegsBaseAddr dw ? |
936 | IDEContrRegsBaseAddr dw ? |
927 | IDEContrProgrammingInterface dw ? |
937 | IDEContrProgrammingInterface dw ? |
928 | IDE_BAR0_val dw ? |
938 | IDE_BAR0_val dw ? |
929 | IDE_BAR1_val dw ? |
939 | IDE_BAR1_val dw ? |
930 | IDE_BAR2_val dw ? |
940 | IDE_BAR2_val dw ? |
931 | IDE_BAR3_val dw ? |
941 | IDE_BAR3_val dw ? |
932 | endg |
942 | endg |
933 | ; \end{Mario79} |
943 | ;----------------------------------------------------------------------------- |
934 | - | ||
935 | ; \begin{diamond} |
944 | ; \begin{diamond} |
936 | uglobal |
945 | uglobal |
937 | bios_hdpos dd 0 ; 0 is invalid value for [hdpos] |
946 | bios_hdpos dd 0 ; 0 is invalid value for [hdpos] |
938 | bios_cur_sector dd ? |
947 | bios_cur_sector dd ? |
939 | bios_read_len dd ? |
948 | bios_read_len dd ? |
940 | endg |
949 | endg |
- | 950 | ;----------------------------------------------------------------------------- |
|
- | 951 | align 4 |
|
941 | bd_read: |
952 | bd_read: |
942 | push eax |
953 | push eax |
943 | push edx |
954 | push edx |
944 | mov edx, [bios_hdpos] |
955 | mov edx, [bios_hdpos] |
945 | cmp edx, [hdpos] |
956 | cmp edx, [hdpos] |
Line 955... | Line 966... | ||
955 | shl eax, 9 |
966 | shl eax, 9 |
956 | add eax, (OS_BASE+0x9A000) |
967 | add eax, (OS_BASE+0x9A000) |
957 | push ecx esi edi |
968 | push ecx esi edi |
958 | mov esi, eax |
969 | mov esi, eax |
959 | shl edi, 9 |
970 | shl edi, 9 |
960 | ; add edi, HD_CACHE+0x10000 |
- | |
- | 971 | ||
961 | push eax |
972 | push eax |
962 | call calculate_cache_2 |
973 | call calculate_cache_2 |
963 | add edi, eax |
974 | add edi, eax |
964 | pop eax |
975 | pop eax |
Line 989... | Line 1000... | ||
989 | jmp bd_read |
1000 | jmp bd_read |
990 | .readerr: |
1001 | .readerr: |
991 | .v86err: |
1002 | .v86err: |
992 | mov [hd_error], 1 |
1003 | mov [hd_error], 1 |
993 | jmp hd_read_error |
1004 | jmp hd_read_error |
- | 1005 | ;----------------------------------------------------------------------------- |
|
994 | 1006 | align 4 |
|
995 | bd_write_cache_chain: |
1007 | bd_write_cache_chain: |
996 | pusha |
1008 | pusha |
997 | mov esi, [cache_chain_pos] |
1009 | mov esi, [cache_chain_pos] |
998 | shl esi, 9 |
1010 | shl esi, 9 |
999 | call calculate_cache_2 |
1011 | call calculate_cache_2 |
Line 1017... | Line 1029... | ||
1017 | .v86err: |
1029 | .v86err: |
1018 | .writeerr: |
1030 | .writeerr: |
1019 | popa |
1031 | popa |
1020 | mov [hd_error], 1 |
1032 | mov [hd_error], 1 |
1021 | jmp hd_write_error |
1033 | jmp hd_write_error |
1022 | - | ||
- | 1034 | ;----------------------------------------------------------------------------- |
|
1023 | uglobal |
1035 | uglobal |
1024 | int13_regs_in rb sizeof.v86_regs |
1036 | int13_regs_in rb sizeof.v86_regs |
1025 | int13_regs_out rb sizeof.v86_regs |
1037 | int13_regs_out rb sizeof.v86_regs |
1026 | endg |
1038 | endg |
- | 1039 | ;----------------------------------------------------------------------------- |
|
1027 | 1040 | align 4 |
|
1028 | int13_call: |
1041 | int13_call: |
1029 | ; Because this code uses fixed addresses, |
1042 | ; Because this code uses fixed addresses, |
1030 | ; it can not be run simultaniously by many threads. |
1043 | ; it can not be run simultaniously by many threads. |
1031 | ; In current implementation it is protected by common mutex 'hd1_status' |
1044 | ; In current implementation it is protected by common mutex 'hd1_status' |
1032 | mov word [OS_BASE + 510h], 10h ; packet length |
1045 | mov word [OS_BASE + 510h], 10h ; packet length |
Line 1073... | Line 1086... | ||
1073 | jnz @f |
1086 | jnz @f |
1074 | mov edx, ecx |
1087 | mov edx, ecx |
1075 | @@: |
1088 | @@: |
1076 | ret |
1089 | ret |
1077 | ; \end{diamond} |
1090 | ; \end{diamond} |
- | 1091 | ;----------------------------------------------------------------------------- |
|
1078 | 1092 | align 4 |
|
1079 | reserve_hd1: |
1093 | reserve_hd1: |
1080 | - | ||
1081 | cli |
1094 | cli |
1082 | cmp [hd1_status], 0 |
1095 | cmp [hd1_status], 0 |
1083 | je reserve_ok1 |
1096 | je reserve_ok1 |
Line 1084... | Line 1097... | ||
1084 | 1097 | ||
1085 | sti |
1098 | sti |
1086 | call change_task |
1099 | call change_task |
Line 1087... | Line 1100... | ||
1087 | jmp reserve_hd1 |
1100 | jmp reserve_hd1 |
1088 | - | ||
1089 | reserve_ok1: |
1101 | |
1090 | 1102 | reserve_ok1: |
|
1091 | push eax |
1103 | push eax |
1092 | mov eax, [CURRENT_TASK] |
1104 | mov eax, [CURRENT_TASK] |
1093 | shl eax, 5 |
1105 | shl eax, 5 |
1094 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
1106 | mov eax, [eax+CURRENT_TASK+TASKDATA.pid] |
1095 | mov [hd1_status], eax |
1107 | mov [hd1_status], eax |
1096 | pop eax |
1108 | pop eax |
1097 | sti |
1109 | sti |
1098 | ret |
- | |
1099 | ;******************************************** |
1110 | ret |
1100 | 1111 | ;----------------------------------------------------------------------------- |
|
1101 | uglobal |
1112 | uglobal |
- | 1113 | hd_in_cache db ? |
|
1102 | hd_in_cache db ? |
1114 | endg |
1103 | endg |
1115 | ;----------------------------------------------------------------------------- |
1104 | 1116 | align 4 |
|
1105 | reserve_hd_channel: |
1117 | reserve_hd_channel: |
1106 | ; BIOS disk accesses are protected with common mutex hd1_status |
1118 | ; BIOS disk accesses are protected with common mutex hd1_status |
1107 | ; This must be modified when hd1_status will not be valid! |
1119 | ; This must be modified when hd1_status will not be valid! |
Line 1138... | Line 1150... | ||
1138 | mov [hd_in_cache], al |
1150 | mov [hd_in_cache], al |
1139 | pop eax |
1151 | pop eax |
1140 | sti |
1152 | sti |
1141 | .ret: |
1153 | .ret: |
1142 | ret |
1154 | ret |
1143 | - | ||
- | 1155 | ;----------------------------------------------------------------------------- |
|
1144 | free_hd_channel: |
1156 | free_hd_channel: |
1145 | ; see comment at reserve_hd_channel |
1157 | ; see comment at reserve_hd_channel |
1146 | cmp [hdpos], 0x80 |
1158 | cmp [hdpos], 0x80 |
1147 | jae .ret |
1159 | jae .ret |
1148 | cmp [hdbase], 0x1F0 |
1160 | cmp [hdbase], 0x1F0 |
Line 1152... | Line 1164... | ||
1152 | .ret: |
1164 | .ret: |
1153 | ret |
1165 | ret |
1154 | .IDE_Channel_2: |
1166 | .IDE_Channel_2: |
1155 | mov [IDE_Channel_2], 0 |
1167 | mov [IDE_Channel_2], 0 |
1156 | ret |
1168 | ret |
1157 | ;******************************************** |
1169 | ;----------------------------------------------------------------------------- |