Rev 514 | Rev 581 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 514 | Rev 580 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | $Revision: 514 $ |
1 | $Revision: 580 $ |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; ;; |
3 | ;; ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;; ;; |
6 | ;; ;; |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 8... | Line 8... | ||
8 | 8 | ||
9 | ; Low-level driver for HDD access |
9 | ; Low-level driver for HDD access |
Line 10... | Line -... | ||
10 | ; DMA support by Mario79 |
- | |
11 | - | ||
12 | ;************************************************************************** |
- | |
13 | ; |
- | |
14 | ; 0x600008 - first entry in cache list |
- | |
15 | ; |
- | |
16 | ; +0 - lba sector |
- | |
17 | ; +4 - state of cache sector |
- | |
18 | ; 0 = empty |
- | |
19 | ; 1 = used for read ( same as in hd ) |
- | |
20 | ; 2 = used for write ( differs from hd ) |
- | |
21 | ; |
- | |
22 | ; +65536 - cache entries |
- | |
23 | ; |
- | |
24 | ;************************************************************************** |
10 | ; DMA support by Mario79 |
25 | 11 | ||
26 | align 4 |
12 | align 4 |
27 | hd_read: |
13 | hd_read: |
28 | ;----------------------------------------------------------- |
14 | ;----------------------------------------------------------- |
29 | ; input : eax = block to read |
15 | ; input : eax = block to read |
30 | ; ebx = destination |
16 | ; ebx = destination |
31 | ;----------------------------------------------------------- |
17 | ;----------------------------------------------------------- |
Line 32... | Line 18... | ||
32 | and [hd_error], 0 |
18 | and [hd_error], 0 |
33 | push ecx esi edi ; scan cache |
19 | push ecx esi edi ; scan cache |
- | 20 | ||
- | 21 | ; mov ecx,cache_max ; entries in cache |
|
- | 22 | ; mov esi,HD_CACHE+8 |
|
34 | 23 | call calculate_cache |
|
Line 35... | Line 24... | ||
35 | mov ecx,cache_max ; entries in cache |
24 | add esi,8 |
Line 36... | Line 25... | ||
36 | mov esi,HD_CACHE+8 |
25 | |
Line 62... | Line 51... | ||
62 | call hd_read_dma |
51 | call hd_read_dma |
63 | jmp @f |
52 | jmp @f |
64 | .nodma: |
53 | .nodma: |
65 | call hd_read_pio |
54 | call hd_read_pio |
66 | @@: |
55 | @@: |
- | 56 | ; lea esi,[edi*8+HD_CACHE] |
|
- | 57 | ; push eax |
|
- | 58 | call calculate_cache_1 |
|
- | 59 | lea esi,[edi*8+esi] |
|
- | 60 | ; pop eax |
|
Line 67... | Line -... | ||
67 | - | ||
68 | lea esi,[edi*8+HD_CACHE] |
61 | |
69 | mov [esi],eax ; sector number |
62 | mov [esi],eax ; sector number |
Line 70... | Line 63... | ||
70 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
63 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
Line 71... | Line 64... | ||
71 | 64 | ||
72 | yeshdcache: |
65 | yeshdcache: |
73 | 66 | ||
- | 67 | mov esi,edi |
|
- | 68 | shl esi,9 |
|
- | 69 | ; add esi,HD_CACHE+65536 |
|
- | 70 | push eax |
|
- | 71 | call calculate_cache_2 |
|
74 | mov esi,edi |
72 | add esi,eax |
75 | shl esi,9 |
73 | pop eax |
76 | add esi,HD_CACHE+65536 |
74 | |
77 | mov edi,ebx |
75 | mov edi,ebx |
78 | mov ecx,512/4 |
76 | mov ecx,512/4 |
Line 124... | Line 122... | ||
124 | jne hd_read_error |
122 | jne hd_read_error |
Line 125... | Line 123... | ||
125 | 123 | ||
126 | cli |
124 | cli |
127 | push edi |
125 | push edi |
128 | shl edi,9 |
126 | shl edi,9 |
- | 127 | ; add edi,HD_CACHE+65536 |
|
- | 128 | push eax |
|
- | 129 | call calculate_cache_2 |
|
- | 130 | add edi,eax |
|
- | 131 | pop eax |
|
129 | add edi,HD_CACHE+65536 |
132 | |
130 | mov ecx,256 |
133 | mov ecx,256 |
131 | mov edx,[hdbase] |
134 | mov edx,[hdbase] |
132 | cld |
135 | cld |
133 | rep insw |
136 | rep insw |
Line 161... | Line 164... | ||
161 | ;----------------------------------------------------------- |
164 | ;----------------------------------------------------------- |
162 | push ecx esi edi |
165 | push ecx esi edi |
Line 163... | Line 166... | ||
163 | 166 | ||
Line 164... | Line 167... | ||
164 | ; check if the cache already has the sector and overwrite it |
167 | ; check if the cache already has the sector and overwrite it |
165 | 168 | ||
- | 169 | ; mov ecx,cache_max |
|
- | 170 | ; mov esi,HD_CACHE+8 |
|
- | 171 | call calculate_cache |
|
166 | mov ecx,cache_max |
172 | add esi,8 |
Line 167... | Line 173... | ||
167 | mov esi,HD_CACHE+8 |
173 | |
Line 168... | Line 174... | ||
168 | mov edi,1 |
174 | mov edi,1 |
Line 187... | Line 193... | ||
187 | 193 | ||
188 | call find_empty_slot ; ret in edi |
194 | call find_empty_slot ; ret in edi |
189 | cmp [hd_error],0 |
195 | cmp [hd_error],0 |
Line 190... | Line 196... | ||
190 | jne hd_write_access_denied |
196 | jne hd_write_access_denied |
- | 197 | ||
- | 198 | ; lea esi,[edi*8+HD_CACHE] |
|
- | 199 | ; push eax |
|
- | 200 | call calculate_cache_1 |
|
- | 201 | lea esi,[edi*8+esi] |
|
191 | 202 | ; pop eax |
|
Line 192... | Line 203... | ||
192 | lea esi,[edi*8+HD_CACHE] |
203 | |
Line 193... | Line 204... | ||
193 | mov [esi],eax ; sector number |
204 | mov [esi],eax ; sector number |
Line 194... | Line 205... | ||
194 | 205 | ||
195 | yes_in_cache_write: |
206 | yes_in_cache_write: |
- | 207 | ||
- | 208 | mov dword [esi+4],2 ; write - differs from hd |
|
- | 209 | ||
- | 210 | shl edi,9 |
|
- | 211 | ; add edi,HD_CACHE+65536 |
|
196 | 212 | push eax |
|
197 | mov dword [esi+4],2 ; write - differs from hd |
213 | call calculate_cache_2 |
198 | 214 | add edi,eax |
|
199 | shl edi,9 |
215 | pop eax |
200 | add edi,HD_CACHE+65536 |
216 | |
201 | mov esi,ebx |
217 | mov esi,ebx |
202 | mov ecx,512/4 |
218 | mov ecx,512/4 |
Line 203... | Line -... | ||
203 | cld |
- | |
204 | rep movsd ; move data |
- | |
205 | hd_write_access_denied: |
- | |
206 | pop edi esi ecx |
- | |
207 | ret |
- | |
208 | - | ||
209 | - | ||
210 | write_cache: |
- | |
211 | ;----------------------------------------------------------- |
- | |
212 | ; write all changed sectors to disk |
- | |
213 | ;----------------------------------------------------------- |
- | |
214 | push eax ecx edx esi edi |
- | |
215 | - | ||
216 | ; write difference ( 2 ) from cache to hd |
- | |
217 | - | ||
218 | mov ecx,cache_max |
- | |
219 | mov esi,HD_CACHE+8 |
- | |
220 | mov edi,1 |
- | |
221 | - | ||
222 | write_cache_more: |
- | |
223 | - | ||
224 | cmp dword [esi+4],2 ; if cache slot is not different |
- | |
225 | jne .write_chain |
- | |
226 | - | ||
227 | mov dword [esi+4],1 ; same as in hd |
- | |
228 | mov eax,[esi] ; eax = sector to write |
- | |
229 | - | ||
230 | cmp eax,[PARTITION_START] |
- | |
231 | jb danger |
- | |
232 | cmp eax,[PARTITION_END] |
- | |
233 | ja danger |
- | |
234 | - | ||
235 | ; DMA write is permitted only if [allow_dma_access]=1 |
- | |
236 | cmp [allow_dma_access], 2 |
- | |
237 | jae .nodma |
- | |
238 | cmp [dma_hdd], 1 |
- | |
239 | jnz .nodma |
- | |
240 | ; ¡ê¥¤¨ï¥¬ § ¯¨áì 楯®çª¨ ¯®á«¥¤®¢ ⥫ìëå ᥪâ®à®¢ ¢ ®¤® ®¡à 饨¥ ª ¤¨áªã |
- | |
241 | cmp ecx, 1 |
- | |
242 | jz .nonext |
- | |
243 | cmp dword [esi+8+4], 2 |
- | |
244 | jnz .nonext |
- | |
245 | push eax |
- | |
246 | inc eax |
- | |
247 | cmp eax, [esi+8] |
- | |
248 | pop eax |
- | |
249 | jnz .nonext |
- | |
250 | cmp [cache_chain_started], 1 |
- | |
251 | jz @f |
- | |
252 | mov [cache_chain_started], 1 |
- | |
253 | mov [cache_chain_size], 0 |
- | |
254 | mov [cache_chain_pos], edi |
- | |
255 | mov [cache_chain_ptr], esi |
- | |
256 | @@: |
- | |
257 | inc [cache_chain_size] |
- | |
258 | cmp [cache_chain_size], 64 |
- | |
259 | jnz .continue |
- | |
260 | jmp .write_chain |
- | |
261 | .nonext: |
- | |
262 | call flush_cache_chain |
- | |
263 | mov [cache_chain_size], 1 |
- | |
264 | mov [cache_chain_ptr], esi |
- | |
265 | call write_cache_sector |
- | |
266 | jmp .continue |
- | |
267 | .nodma: |
- | |
268 | call cache_write_pio |
- | |
269 | .write_chain: |
- | |
270 | call flush_cache_chain |
- | |
271 | - | ||
272 | .continue: |
- | |
273 | danger: |
- | |
274 | - | ||
275 | add esi,8 |
- | |
276 | inc edi |
- | |
277 | dec ecx |
- | |
278 | jnz write_cache_more |
- | |
279 | call flush_cache_chain |
- | |
280 | return_02: |
- | |
281 | pop edi esi edx ecx eax |
- | |
282 | ret |
- | |
283 | - | ||
284 | flush_cache_chain: |
- | |
285 | cmp [cache_chain_started], 0 |
- | |
286 | jz @f |
219 | cld |
287 | call write_cache_chain |
220 | rep movsd ; move data |
288 | mov [cache_chain_started], 0 |
221 | hd_write_access_denied: |
Line 289... | Line 222... | ||
289 | @@: |
222 | pop edi esi ecx |
290 | ret |
223 | ret |
291 | 224 | ||
Line 292... | Line 225... | ||
292 | align 4 |
225 | align 4 |
293 | cache_write_pio: |
226 | cache_write_pio: |
294 | call disable_ide_int |
227 | ; call disable_ide_int |
295 | 228 | ||
296 | call wait_for_hd_idle |
229 | call wait_for_hd_idle |
297 | cmp [hd_error],0 |
230 | cmp [hd_error],0 |
Line 321... | Line 254... | ||
321 | add al,128+64+32 |
254 | add al,128+64+32 |
322 | out dx,al |
255 | out dx,al |
323 | inc edx |
256 | inc edx |
324 | mov al,30h |
257 | mov al,30h |
325 | out dx,al |
258 | out dx,al |
326 | ; sti |
259 | sti |
Line 327... | Line 260... | ||
327 | 260 | ||
Line 328... | Line 261... | ||
328 | call wait_for_sector_buffer |
261 | call wait_for_sector_buffer |
329 | 262 | ||
Line 330... | Line 263... | ||
330 | cmp [hd_error],0 |
263 | cmp [hd_error],0 |
Line 331... | Line 264... | ||
331 | jne hd_write_error |
264 | jne hd_write_error |
332 | 265 | ||
333 | push ecx esi |
266 | push ecx esi |
334 | 267 | ||
- | 268 | cli |
|
- | 269 | mov esi,edi |
|
- | 270 | shl esi,9 |
|
- | 271 | ; add esi,HD_CACHE+65536 ; esi = from memory position |
|
- | 272 | push eax |
|
335 | ; cli |
273 | call calculate_cache_2 |
336 | mov esi,edi |
274 | add esi,eax |
337 | shl esi,9 |
275 | pop eax |
338 | add esi,HD_CACHE+65536 ; esi = from memory position |
276 | |
339 | mov ecx,256 |
277 | mov ecx,256 |
Line 340... | Line 278... | ||
340 | mov edx,[hdbase] |
278 | mov edx,[hdbase] |
341 | cld |
279 | cld |
Line 342... | Line 280... | ||
342 | rep outsw |
280 | rep outsw |
Line 343... | Line -... | ||
343 | ; sti |
- | |
344 | - | ||
345 | call enable_ide_int |
- | |
346 | pop esi ecx |
- | |
347 | - | ||
348 | ret |
- | |
349 | - | ||
350 | align 4 |
- | |
351 | find_empty_slot: |
- | |
352 | ;----------------------------------------------------------- |
- | |
353 | ; find empty or read slot, flush cache if next 10% is used by write |
- | |
354 | ; output : edi = cache slot |
- | |
355 | ;----------------------------------------------------------- |
- | |
356 | ; push ecx esi |
- | |
357 | - | ||
358 | search_again: |
- | |
359 | - | ||
360 | mov ecx,cache_max*10/100 |
- | |
361 | mov edi,[cache_search_start] |
- | |
362 | - | ||
363 | search_for_empty: |
- | |
364 | - | ||
365 | inc edi |
- | |
366 | cmp edi,cache_max |
- | |
367 | jbe inside_cache |
- | |
368 | mov edi,1 |
- | |
369 | - | ||
370 | inside_cache: |
- | |
371 | - | ||
372 | cmp dword [edi*8+HD_CACHE+4],2 ; get cache slot info |
- | |
373 | jb found_slot ; it's empty or read |
- | |
374 | dec ecx |
- | |
375 | jnz search_for_empty |
- | |
376 | - | ||
377 | call write_cache ; no empty slots found, write all |
- | |
378 | cmp [hd_error],0 |
- | |
379 | jne found_slot_access_denied |
- | |
380 | - | ||
381 | jmp search_again ; and start again |
- | |
382 | - | ||
383 | found_slot: |
- | |
384 | - | ||
385 | mov [cache_search_start],edi |
- | |
386 | found_slot_access_denied: |
- | |
387 | ret |
- | |
388 | - | ||
389 | align 4 |
- | |
390 | clear_hd_cache: |
- | |
391 | - | ||
392 | push eax ecx edi |
- | |
393 | mov edi, HD_CACHE |
- | |
394 | mov ecx,16384 |
- | |
395 | xor eax,eax |
- | |
396 | cld |
- | |
397 | rep stosd ; clear hd cache with 0 |
281 | sti |
Line 398... | Line 282... | ||
398 | mov [cache_search_start],eax |
282 | |
399 | mov [fat_in_cache],-1 |
283 | ; call enable_ide_int |
400 | mov [fat_change],0 |
284 | pop esi ecx |
Line 682... | Line 566... | ||
682 | shl eax, 9 |
566 | shl eax, 9 |
683 | add eax, OS_BASE+0x284000 |
567 | add eax, OS_BASE+0x284000 |
684 | push ecx esi edi |
568 | push ecx esi edi |
685 | mov esi, eax |
569 | mov esi, eax |
686 | shl edi, 9 |
570 | shl edi, 9 |
687 | add edi, HD_CACHE+0x10000 |
571 | ; add edi, HD_CACHE+0x10000 |
- | 572 | push eax |
|
- | 573 | call calculate_cache_2 |
|
- | 574 | add edi,eax |
|
- | 575 | pop eax |
|
- | 576 | ||
688 | mov ecx, 512/4 |
577 | mov ecx, 512/4 |
689 | cld |
578 | cld |
690 | rep movsd |
579 | rep movsd |
691 | pop edi esi ecx |
580 | pop edi esi ecx |
692 | pop edx |
581 | pop edx |
Line 772... | Line 661... | ||
772 | pop eax |
661 | pop eax |
773 | mov [dma_cur_sector], eax |
662 | mov [dma_cur_sector], eax |
774 | jmp hd_read_dma |
663 | jmp hd_read_dma |
Line 775... | Line 664... | ||
775 | 664 | ||
776 | align 4 |
- | |
777 | write_cache_chain: |
- | |
778 | push esi |
- | |
779 | mov eax, IDE_descriptor_table |
- | |
780 | mov edx, [cache_chain_pos] |
- | |
781 | shl edx, 9 |
- | |
782 | add edx, DMA_HD_MEM+0x10000 |
- | |
783 | mov [eax], edx |
- | |
784 | movzx edx, [cache_chain_size] |
- | |
785 | shl edx, 9 |
- | |
786 | mov [eax+4], dx |
- | |
787 | jmp do_write_dma |
665 | align 4 |
- | 666 | write_cache_sector: |
|
- | 667 | mov [cache_chain_size],1 |
|
- | 668 | mov [cache_chain_pos],edi |
|
788 | write_cache_sector: |
669 | write_cache_chain: |
789 | push esi |
670 | push esi |
790 | mov eax, IDE_descriptor_table |
671 | mov eax, IDE_descriptor_table |
- | 672 | mov edx,eax |
|
- | 673 | pusha |
|
791 | mov edx, edi |
674 | mov esi,[cache_chain_pos] |
- | 675 | shl esi, 9 |
|
- | 676 | call calculate_cache_2 |
|
- | 677 | add esi,eax |
|
- | 678 | mov edi,OS_BASE+0x284000 ;HD_CACHE |
|
792 | shl edx, 9 |
679 | mov dword [edx], 0x284000 ;DMA_HD_MEM |
793 | add edx, DMA_HD_MEM+0x10000 |
680 | movzx ecx, [cache_chain_size] |
794 | mov [eax], edx |
681 | shl ecx, 9 |
- | 682 | mov word [edx+4], cx |
|
- | 683 | shr ecx,2 |
|
- | 684 | cld |
|
795 | mov word [eax+4], 0x200 |
685 | rep movsd |
796 | do_write_dma: |
686 | popa |
797 | sub eax, OS_BASE |
687 | sub eax, OS_BASE |
798 | mov dx, [IDEContrRegsBaseAddr] |
688 | mov dx, [IDEContrRegsBaseAddr] |
799 | cmp [hdbase], 0x1F0 |
689 | cmp [hdbase], 0x1F0 |
800 | jz @f |
690 | jz @f |