Rev 425 | Rev 465 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 425 | Rev 431 | ||
---|---|---|---|
1 | $Revision: 425 $ |
1 | $Revision: 431 $ |
- | 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 3 | ;; ;; |
|
- | 4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
|
- | 5 | ;; Distributed under terms of the GNU General Public License ;; |
|
- | 6 | ;; ;; |
|
- | 7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 8 | ||
2 | ; Low-level driver for HDD access |
9 | ; Low-level driver for HDD access |
3 | ; DMA support by Mario79 |
10 | ; DMA support by Mario79 |
4 | 11 | ||
5 | ;************************************************************************** |
12 | ;************************************************************************** |
6 | ; |
13 | ; |
7 | ; 0x600008 - first entry in cache list |
14 | ; 0x600008 - first entry in cache list |
8 | ; |
15 | ; |
9 | ; +0 - lba sector |
16 | ; +0 - lba sector |
10 | ; +4 - state of cache sector |
17 | ; +4 - state of cache sector |
11 | ; 0 = empty |
18 | ; 0 = empty |
12 | ; 1 = used for read ( same as in hd ) |
19 | ; 1 = used for read ( same as in hd ) |
13 | ; 2 = used for write ( differs from hd ) |
20 | ; 2 = used for write ( differs from hd ) |
14 | ; |
21 | ; |
15 | ; +65536 - cache entries |
22 | ; +65536 - cache entries |
16 | ; |
23 | ; |
17 | ;************************************************************************** |
24 | ;************************************************************************** |
18 | 25 | ||
19 | align 4 |
26 | align 4 |
20 | hd_read: |
27 | hd_read: |
21 | ;----------------------------------------------------------- |
28 | ;----------------------------------------------------------- |
22 | ; input : eax = block to read |
29 | ; input : eax = block to read |
23 | ; ebx = destination |
30 | ; ebx = destination |
24 | ;----------------------------------------------------------- |
31 | ;----------------------------------------------------------- |
25 | and [hd_error], 0 |
32 | and [hd_error], 0 |
26 | push ecx esi edi ; scan cache |
33 | push ecx esi edi ; scan cache |
27 | 34 | ||
28 | mov ecx,cache_max ; entries in cache |
35 | mov ecx,cache_max ; entries in cache |
29 | mov esi,OS_BASE+0x600000+8 |
36 | mov esi,OS_BASE+0x600000+8 |
30 | mov edi,1 |
37 | mov edi,1 |
31 | 38 | ||
32 | hdreadcache: |
39 | hdreadcache: |
33 | 40 | ||
34 | cmp dword [esi+4],0 ; empty |
41 | cmp dword [esi+4],0 ; empty |
35 | je nohdcache |
42 | je nohdcache |
36 | 43 | ||
37 | cmp [esi],eax ; correct sector |
44 | cmp [esi],eax ; correct sector |
38 | je yeshdcache |
45 | je yeshdcache |
39 | 46 | ||
40 | nohdcache: |
47 | nohdcache: |
41 | 48 | ||
42 | add esi,8 |
49 | add esi,8 |
43 | inc edi |
50 | inc edi |
44 | dec ecx |
51 | dec ecx |
45 | jnz hdreadcache |
52 | jnz hdreadcache |
46 | 53 | ||
47 | call find_empty_slot ; ret in edi |
54 | call find_empty_slot ; ret in edi |
48 | cmp [hd_error],0 |
55 | cmp [hd_error],0 |
49 | jne return_01 |
56 | jne return_01 |
50 | cmp [dma_hdd], 1 |
57 | cmp [dma_hdd], 1 |
51 | jnz .nodma |
58 | jnz .nodma |
52 | call hd_read_dma |
59 | call hd_read_dma |
53 | jmp @f |
60 | jmp @f |
54 | .nodma: |
61 | .nodma: |
55 | call hd_read_pio |
62 | call hd_read_pio |
56 | @@: |
63 | @@: |
57 | 64 | ||
58 | lea esi,[edi*8+OS_BASE+0x600000] |
65 | lea esi,[edi*8+OS_BASE+0x600000] |
59 | mov [esi],eax ; sector number |
66 | mov [esi],eax ; sector number |
60 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
67 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
61 | 68 | ||
62 | yeshdcache: |
69 | yeshdcache: |
63 | 70 | ||
64 | mov esi,edi |
71 | mov esi,edi |
65 | shl esi,9 |
72 | shl esi,9 |
66 | add esi,OS_BASE+0x600000+65536 |
73 | add esi,OS_BASE+0x600000+65536 |
67 | mov edi,ebx |
74 | mov edi,ebx |
68 | mov ecx,512/4 |
75 | mov ecx,512/4 |
69 | cld |
76 | cld |
70 | rep movsd ; move data |
77 | rep movsd ; move data |
71 | return_01: |
78 | return_01: |
72 | pop edi esi ecx |
79 | pop edi esi ecx |
73 | ret |
80 | ret |
74 | 81 | ||
75 | align 4 |
82 | align 4 |
76 | hd_read_pio: |
83 | hd_read_pio: |
77 | push eax edx |
84 | push eax edx |
78 | 85 | ||
79 | call wait_for_hd_idle |
86 | call wait_for_hd_idle |
80 | cmp [hd_error],0 |
87 | cmp [hd_error],0 |
81 | jne hd_read_error |
88 | jne hd_read_error |
82 | 89 | ||
83 | cli |
90 | cli |
84 | xor eax,eax |
91 | xor eax,eax |
85 | mov edx,[hdbase] |
92 | mov edx,[hdbase] |
86 | inc edx |
93 | inc edx |
87 | out dx,al ; ATAFeatures ॣ¨áâà "®á®¡¥®á⥩" |
94 | out dx,al ; ATAFeatures ॣ¨áâà "®á®¡¥®á⥩" |
88 | inc edx |
95 | inc edx |
89 | inc eax |
96 | inc eax |
90 | out dx,al ; ATASectorCount áçñâ稪 ᥪâ®à®¢ |
97 | out dx,al ; ATASectorCount áçñâ稪 ᥪâ®à®¢ |
91 | inc edx |
98 | inc edx |
92 | mov eax,[esp+4] |
99 | mov eax,[esp+4] |
93 | out dx,al ; ATASectorNumber ॣ¨áâà ®¬¥à ᥪâ®à |
100 | out dx,al ; ATASectorNumber ॣ¨áâà ®¬¥à ᥪâ®à |
94 | shr eax,8 |
101 | shr eax,8 |
95 | inc edx |
102 | inc edx |
96 | out dx,al ; ATACylinder ®¬¥à 樫¨¤à (¬« ¤è¨© ¡ ©â) |
103 | out dx,al ; ATACylinder ®¬¥à 樫¨¤à (¬« ¤è¨© ¡ ©â) |
97 | shr eax,8 |
104 | shr eax,8 |
98 | inc edx |
105 | inc edx |
99 | out dx,al ; ®¬¥à 樫¨¤à (áâ à訩 ¡ ©â) |
106 | out dx,al ; ®¬¥à 樫¨¤à (áâ à訩 ¡ ©â) |
100 | shr eax,8 |
107 | shr eax,8 |
101 | inc edx |
108 | inc edx |
102 | and al,1+2+4+8 |
109 | and al,1+2+4+8 |
103 | add al,byte [hdid] |
110 | add al,byte [hdid] |
104 | add al,128+64+32 |
111 | add al,128+64+32 |
105 | out dx,al ; ®¬¥à £®«®¢ª¨/®¬¥à ¤¨áª |
112 | out dx,al ; ®¬¥à £®«®¢ª¨/®¬¥à ¤¨áª |
106 | inc edx |
113 | inc edx |
107 | mov al,20h |
114 | mov al,20h |
108 | out dx,al ; ATACommand ॣ¨áâà ª®¬ ¤ |
115 | out dx,al ; ATACommand ॣ¨áâà ª®¬ ¤ |
109 | sti |
116 | sti |
110 | 117 | ||
111 | call wait_for_sector_buffer |
118 | call wait_for_sector_buffer |
112 | 119 | ||
113 | cmp [hd_error],0 |
120 | cmp [hd_error],0 |
114 | jne hd_read_error |
121 | jne hd_read_error |
115 | 122 | ||
116 | cli |
123 | cli |
117 | push edi |
124 | push edi |
118 | shl edi,9 |
125 | shl edi,9 |
119 | add edi,OS_BASE+0x600000+65536 |
126 | add edi,OS_BASE+0x600000+65536 |
120 | mov ecx,256 |
127 | mov ecx,256 |
121 | mov edx,[hdbase] |
128 | mov edx,[hdbase] |
122 | cld |
129 | cld |
123 | rep insw |
130 | rep insw |
124 | pop edi |
131 | pop edi |
125 | sti |
132 | sti |
126 | 133 | ||
127 | pop edx eax |
134 | pop edx eax |
128 | ret |
135 | ret |
129 | 136 | ||
130 | disable_ide_int: |
137 | disable_ide_int: |
131 | ; mov edx,[hdbase] |
138 | ; mov edx,[hdbase] |
132 | ; add edx,0x206 |
139 | ; add edx,0x206 |
133 | ; mov al,2 |
140 | ; mov al,2 |
134 | ; out dx,al |
141 | ; out dx,al |
135 | cli |
142 | cli |
136 | ret |
143 | ret |
137 | 144 | ||
138 | enable_ide_int: |
145 | enable_ide_int: |
139 | ; mov edx,[hdbase] |
146 | ; mov edx,[hdbase] |
140 | ; add edx,0x206 |
147 | ; add edx,0x206 |
141 | ; mov al,0 |
148 | ; mov al,0 |
142 | ; out dx,al |
149 | ; out dx,al |
143 | sti |
150 | sti |
144 | ret |
151 | ret |
145 | 152 | ||
146 | align 4 |
153 | align 4 |
147 | hd_write: |
154 | hd_write: |
148 | ;----------------------------------------------------------- |
155 | ;----------------------------------------------------------- |
149 | ; input : eax = block |
156 | ; input : eax = block |
150 | ; ebx = pointer to memory |
157 | ; ebx = pointer to memory |
151 | ;----------------------------------------------------------- |
158 | ;----------------------------------------------------------- |
152 | push ecx esi edi |
159 | push ecx esi edi |
153 | 160 | ||
154 | ; check if the cache already has the sector and overwrite it |
161 | ; check if the cache already has the sector and overwrite it |
155 | 162 | ||
156 | mov ecx,cache_max |
163 | mov ecx,cache_max |
157 | mov esi,OS_BASE+0x600000+8 |
164 | mov esi,OS_BASE+0x600000+8 |
158 | mov edi,1 |
165 | mov edi,1 |
159 | 166 | ||
160 | hdwritecache: |
167 | hdwritecache: |
161 | 168 | ||
162 | cmp dword [esi+4],0 ; if cache slot is empty |
169 | cmp dword [esi+4],0 ; if cache slot is empty |
163 | je not_in_cache_write |
170 | je not_in_cache_write |
164 | 171 | ||
165 | cmp [esi],eax ; if the slot has the sector |
172 | cmp [esi],eax ; if the slot has the sector |
166 | je yes_in_cache_write |
173 | je yes_in_cache_write |
167 | 174 | ||
168 | not_in_cache_write: |
175 | not_in_cache_write: |
169 | 176 | ||
170 | add esi,8 |
177 | add esi,8 |
171 | inc edi |
178 | inc edi |
172 | dec ecx |
179 | dec ecx |
173 | jnz hdwritecache |
180 | jnz hdwritecache |
174 | 181 | ||
175 | ; sector not found in cache |
182 | ; sector not found in cache |
176 | ; write the block to a new location |
183 | ; write the block to a new location |
177 | 184 | ||
178 | call find_empty_slot ; ret in edi |
185 | call find_empty_slot ; ret in edi |
179 | cmp [hd_error],0 |
186 | cmp [hd_error],0 |
180 | jne hd_write_access_denied |
187 | jne hd_write_access_denied |
181 | 188 | ||
182 | lea esi,[edi*8+OS_BASE+0x600000] |
189 | lea esi,[edi*8+OS_BASE+0x600000] |
183 | mov [esi],eax ; sector number |
190 | mov [esi],eax ; sector number |
184 | 191 | ||
185 | yes_in_cache_write: |
192 | yes_in_cache_write: |
186 | 193 | ||
187 | mov dword [esi+4],2 ; write - differs from hd |
194 | mov dword [esi+4],2 ; write - differs from hd |
188 | 195 | ||
189 | shl edi,9 |
196 | shl edi,9 |
190 | add edi,OS_BASE+0x600000+65536 |
197 | add edi,OS_BASE+0x600000+65536 |
191 | mov esi,ebx |
198 | mov esi,ebx |
192 | mov ecx,512/4 |
199 | mov ecx,512/4 |
193 | cld |
200 | cld |
194 | rep movsd ; move data |
201 | rep movsd ; move data |
195 | hd_write_access_denied: |
202 | hd_write_access_denied: |
196 | pop edi esi ecx |
203 | pop edi esi ecx |
197 | ret |
204 | ret |
198 | 205 | ||
199 | 206 | ||
200 | write_cache: |
207 | write_cache: |
201 | ;----------------------------------------------------------- |
208 | ;----------------------------------------------------------- |
202 | ; write all changed sectors to disk |
209 | ; write all changed sectors to disk |
203 | ;----------------------------------------------------------- |
210 | ;----------------------------------------------------------- |
204 | push eax ecx edx esi edi |
211 | push eax ecx edx esi edi |
205 | 212 | ||
206 | ; write difference ( 2 ) from cache to hd |
213 | ; write difference ( 2 ) from cache to hd |
207 | 214 | ||
208 | mov ecx,cache_max |
215 | mov ecx,cache_max |
209 | mov esi,OS_BASE+0x600000+8 |
216 | mov esi,OS_BASE+0x600000+8 |
210 | mov edi,1 |
217 | mov edi,1 |
211 | 218 | ||
212 | write_cache_more: |
219 | write_cache_more: |
213 | 220 | ||
214 | cmp dword [esi+4],2 ; if cache slot is not different |
221 | cmp dword [esi+4],2 ; if cache slot is not different |
215 | jne .write_chain |
222 | jne .write_chain |
216 | 223 | ||
217 | mov dword [esi+4],1 ; same as in hd |
224 | mov dword [esi+4],1 ; same as in hd |
218 | mov eax,[esi] ; eax = sector to write |
225 | mov eax,[esi] ; eax = sector to write |
219 | 226 | ||
220 | cmp eax,[PARTITION_START] |
227 | cmp eax,[PARTITION_START] |
221 | jb danger |
228 | jb danger |
222 | cmp eax,[PARTITION_END] |
229 | cmp eax,[PARTITION_END] |
223 | ja danger |
230 | ja danger |
224 | 231 | ||
225 | cmp [allow_dma_write], 1 |
232 | cmp [allow_dma_write], 1 |
226 | jnz .nodma |
233 | jnz .nodma |
227 | cmp [dma_hdd], 1 |
234 | cmp [dma_hdd], 1 |
228 | jnz .nodma |
235 | jnz .nodma |
229 | ; ¡ê¥¤¨ï¥¬ § ¯¨áì 楯®çª¨ ¯®á«¥¤®¢ ⥫ìëå ᥪâ®à®¢ ¢ ®¤® ®¡à 饨¥ ª ¤¨áªã |
236 | ; ¡ê¥¤¨ï¥¬ § ¯¨áì 楯®çª¨ ¯®á«¥¤®¢ ⥫ìëå ᥪâ®à®¢ ¢ ®¤® ®¡à 饨¥ ª ¤¨áªã |
230 | cmp ecx, 1 |
237 | cmp ecx, 1 |
231 | jz .nonext |
238 | jz .nonext |
232 | cmp dword [esi+8+4], 2 |
239 | cmp dword [esi+8+4], 2 |
233 | jnz .nonext |
240 | jnz .nonext |
234 | push eax |
241 | push eax |
235 | inc eax |
242 | inc eax |
236 | cmp eax, [esi+8] |
243 | cmp eax, [esi+8] |
237 | pop eax |
244 | pop eax |
238 | jnz .nonext |
245 | jnz .nonext |
239 | cmp [cache_chain_started], 1 |
246 | cmp [cache_chain_started], 1 |
240 | jz @f |
247 | jz @f |
241 | mov [cache_chain_started], 1 |
248 | mov [cache_chain_started], 1 |
242 | mov [cache_chain_size], 0 |
249 | mov [cache_chain_size], 0 |
243 | mov [cache_chain_pos], edi |
250 | mov [cache_chain_pos], edi |
244 | mov [cache_chain_ptr], esi |
251 | mov [cache_chain_ptr], esi |
245 | @@: |
252 | @@: |
246 | inc [cache_chain_size] |
253 | inc [cache_chain_size] |
247 | cmp [cache_chain_size], 64 |
254 | cmp [cache_chain_size], 64 |
248 | jnz .continue |
255 | jnz .continue |
249 | jmp .write_chain |
256 | jmp .write_chain |
250 | .nonext: |
257 | .nonext: |
251 | call flush_cache_chain |
258 | call flush_cache_chain |
252 | mov [cache_chain_size], 1 |
259 | mov [cache_chain_size], 1 |
253 | mov [cache_chain_ptr], esi |
260 | mov [cache_chain_ptr], esi |
254 | call write_cache_sector |
261 | call write_cache_sector |
255 | jmp .continue |
262 | jmp .continue |
256 | .nodma: |
263 | .nodma: |
257 | call cache_write_pio |
264 | call cache_write_pio |
258 | .write_chain: |
265 | .write_chain: |
259 | call flush_cache_chain |
266 | call flush_cache_chain |
260 | 267 | ||
261 | .continue: |
268 | .continue: |
262 | danger: |
269 | danger: |
263 | 270 | ||
264 | add esi,8 |
271 | add esi,8 |
265 | inc edi |
272 | inc edi |
266 | dec ecx |
273 | dec ecx |
267 | jnz write_cache_more |
274 | jnz write_cache_more |
268 | call flush_cache_chain |
275 | call flush_cache_chain |
269 | return_02: |
276 | return_02: |
270 | pop edi esi edx ecx eax |
277 | pop edi esi edx ecx eax |
271 | ret |
278 | ret |
272 | 279 | ||
273 | flush_cache_chain: |
280 | flush_cache_chain: |
274 | cmp [cache_chain_started], 0 |
281 | cmp [cache_chain_started], 0 |
275 | jz @f |
282 | jz @f |
276 | call write_cache_chain |
283 | call write_cache_chain |
277 | mov [cache_chain_started], 0 |
284 | mov [cache_chain_started], 0 |
278 | @@: |
285 | @@: |
279 | ret |
286 | ret |
280 | 287 | ||
281 | align 4 |
288 | align 4 |
282 | cache_write_pio: |
289 | cache_write_pio: |
283 | call disable_ide_int |
290 | call disable_ide_int |
284 | 291 | ||
285 | call wait_for_hd_idle |
292 | call wait_for_hd_idle |
286 | cmp [hd_error],0 |
293 | cmp [hd_error],0 |
287 | jne hd_write_error |
294 | jne hd_write_error |
288 | 295 | ||
289 | ; cli |
296 | ; cli |
290 | xor eax,eax |
297 | xor eax,eax |
291 | mov edx,[hdbase] |
298 | mov edx,[hdbase] |
292 | inc edx |
299 | inc edx |
293 | out dx,al |
300 | out dx,al |
294 | inc edx |
301 | inc edx |
295 | inc eax |
302 | inc eax |
296 | out dx,al |
303 | out dx,al |
297 | inc edx |
304 | inc edx |
298 | mov eax,[esi] ; eax = sector to write |
305 | mov eax,[esi] ; eax = sector to write |
299 | out dx,al |
306 | out dx,al |
300 | shr eax,8 |
307 | shr eax,8 |
301 | inc edx |
308 | inc edx |
302 | out dx,al |
309 | out dx,al |
303 | shr eax,8 |
310 | shr eax,8 |
304 | inc edx |
311 | inc edx |
305 | out dx,al |
312 | out dx,al |
306 | shr eax,8 |
313 | shr eax,8 |
307 | inc edx |
314 | inc edx |
308 | and al,1+2+4+8 |
315 | and al,1+2+4+8 |
309 | add al,byte [hdid] |
316 | add al,byte [hdid] |
310 | add al,128+64+32 |
317 | add al,128+64+32 |
311 | out dx,al |
318 | out dx,al |
312 | inc edx |
319 | inc edx |
313 | mov al,30h |
320 | mov al,30h |
314 | out dx,al |
321 | out dx,al |
315 | ; sti |
322 | ; sti |
316 | 323 | ||
317 | call wait_for_sector_buffer |
324 | call wait_for_sector_buffer |
318 | 325 | ||
319 | cmp [hd_error],0 |
326 | cmp [hd_error],0 |
320 | jne hd_write_error |
327 | jne hd_write_error |
321 | 328 | ||
322 | push ecx esi |
329 | push ecx esi |
323 | 330 | ||
324 | ; cli |
331 | ; cli |
325 | mov esi,edi |
332 | mov esi,edi |
326 | shl esi,9 |
333 | shl esi,9 |
327 | add esi,OS_BASE+0x600000+65536 ; esi = from memory position |
334 | add esi,OS_BASE+0x600000+65536 ; esi = from memory position |
328 | mov ecx,256 |
335 | mov ecx,256 |
329 | mov edx,[hdbase] |
336 | mov edx,[hdbase] |
330 | cld |
337 | cld |
331 | rep outsw |
338 | rep outsw |
332 | ; sti |
339 | ; sti |
333 | 340 | ||
334 | call enable_ide_int |
341 | call enable_ide_int |
335 | pop esi ecx |
342 | pop esi ecx |
336 | 343 | ||
337 | ret |
344 | ret |
338 | 345 | ||
339 | align 4 |
346 | align 4 |
340 | find_empty_slot: |
347 | find_empty_slot: |
341 | ;----------------------------------------------------------- |
348 | ;----------------------------------------------------------- |
342 | ; find empty or read slot, flush cache if next 10% is used by write |
349 | ; find empty or read slot, flush cache if next 10% is used by write |
343 | ; output : edi = cache slot |
350 | ; output : edi = cache slot |
344 | ;----------------------------------------------------------- |
351 | ;----------------------------------------------------------- |
345 | ; push ecx esi |
352 | ; push ecx esi |
346 | 353 | ||
347 | search_again: |
354 | search_again: |
348 | 355 | ||
349 | mov ecx,cache_max*10/100 |
356 | mov ecx,cache_max*10/100 |
350 | mov edi,[cache_search_start] |
357 | mov edi,[cache_search_start] |
351 | 358 | ||
352 | search_for_empty: |
359 | search_for_empty: |
353 | 360 | ||
354 | inc edi |
361 | inc edi |
355 | cmp edi,cache_max |
362 | cmp edi,cache_max |
356 | jbe inside_cache |
363 | jbe inside_cache |
357 | mov edi,1 |
364 | mov edi,1 |
358 | 365 | ||
359 | inside_cache: |
366 | inside_cache: |
360 | 367 | ||
361 | cmp dword [edi*8+OS_BASE+0x600000+4],2 ; get cache slot info |
368 | cmp dword [edi*8+OS_BASE+0x600000+4],2 ; get cache slot info |
362 | jb found_slot ; it's empty or read |
369 | jb found_slot ; it's empty or read |
363 | dec ecx |
370 | dec ecx |
364 | jnz search_for_empty |
371 | jnz search_for_empty |
365 | 372 | ||
366 | call write_cache ; no empty slots found, write all |
373 | call write_cache ; no empty slots found, write all |
367 | cmp [hd_error],0 |
374 | cmp [hd_error],0 |
368 | jne found_slot_access_denied |
375 | jne found_slot_access_denied |
369 | 376 | ||
370 | jmp search_again ; and start again |
377 | jmp search_again ; and start again |
371 | 378 | ||
372 | found_slot: |
379 | found_slot: |
373 | 380 | ||
374 | mov [cache_search_start],edi |
381 | mov [cache_search_start],edi |
375 | found_slot_access_denied: |
382 | found_slot_access_denied: |
376 | ret |
383 | ret |
377 | 384 | ||
378 | align 4 |
385 | align 4 |
379 | clear_hd_cache: |
386 | clear_hd_cache: |
380 | 387 | ||
381 | push eax ecx edi |
388 | push eax ecx edi |
382 | mov edi,OS_BASE+0x600000 |
389 | mov edi,OS_BASE+0x600000 |
383 | mov ecx,16384 |
390 | mov ecx,16384 |
384 | xor eax,eax |
391 | xor eax,eax |
385 | cld |
392 | cld |
386 | rep stosd ; clear hd cache with 0 |
393 | rep stosd ; clear hd cache with 0 |
387 | mov [cache_search_start],eax |
394 | mov [cache_search_start],eax |
388 | mov [fat_in_cache],-1 |
395 | mov [fat_in_cache],-1 |
389 | mov [fat_change],0 |
396 | mov [fat_change],0 |
390 | pop edi ecx eax |
397 | pop edi ecx eax |
391 | ret |
398 | ret |
392 | 399 | ||
393 | save_hd_wait_timeout: |
400 | save_hd_wait_timeout: |
394 | 401 | ||
395 | push eax |
402 | push eax |
396 | mov eax,[timer_ticks];[0xfdf0] |
403 | mov eax,[timer_ticks];[0xfdf0] |
397 | add eax,300 ; 3 sec timeout |
404 | add eax,300 ; 3 sec timeout |
398 | mov [hd_wait_timeout],eax |
405 | mov [hd_wait_timeout],eax |
399 | pop eax |
406 | pop eax |
400 | ret |
407 | ret |
401 | 408 | ||
402 | align 4 |
409 | align 4 |
403 | check_hd_wait_timeout: |
410 | check_hd_wait_timeout: |
404 | 411 | ||
405 | push eax |
412 | push eax |
406 | mov eax,[hd_wait_timeout] |
413 | mov eax,[hd_wait_timeout] |
407 | cmp [timer_ticks], eax ;[0xfdf0],eax |
414 | cmp [timer_ticks], eax ;[0xfdf0],eax |
408 | jg hd_timeout_error |
415 | jg hd_timeout_error |
409 | pop eax |
416 | pop eax |
410 | mov [hd_error],0 |
417 | mov [hd_error],0 |
411 | ret |
418 | ret |
412 | 419 | ||
413 | ;iglobal |
420 | ;iglobal |
414 | ; hd_timeout_str db 'K : FS - HD timeout',0 |
421 | ; hd_timeout_str db 'K : FS - HD timeout',0 |
415 | ; hd_read_str db 'K : FS - HD read error',0 |
422 | ; hd_read_str db 'K : FS - HD read error',0 |
416 | ; hd_write_str db 'K : FS - HD write error',0 |
423 | ; hd_write_str db 'K : FS - HD write error',0 |
417 | ; hd_lba_str db 'K : FS - HD LBA error',0 |
424 | ; hd_lba_str db 'K : FS - HD LBA error',0 |
418 | ;endg |
425 | ;endg |
419 | 426 | ||
420 | hd_timeout_error: |
427 | hd_timeout_error: |
421 | 428 | ||
422 | ; call clear_hd_cache |
429 | ; call clear_hd_cache |
423 | ; call clear_application_table_status |
430 | ; call clear_application_table_status |
424 | ; mov esi,hd_timeout_str |
431 | ; mov esi,hd_timeout_str |
425 | ; call sys_msg_board_str |
432 | ; call sys_msg_board_str |
426 | DEBUGF 1,"K : FS - HD timeout\n" |
433 | DEBUGF 1,"K : FS - HD timeout\n" |
427 | ; jmp $ |
434 | ; jmp $ |
428 | mov [hd_error],1 |
435 | mov [hd_error],1 |
429 | pop eax |
436 | pop eax |
430 | ret |
437 | ret |
431 | 438 | ||
432 | hd_read_error: |
439 | hd_read_error: |
433 | 440 | ||
434 | ; call clear_hd_cache |
441 | ; call clear_hd_cache |
435 | ; call clear_application_table_status |
442 | ; call clear_application_table_status |
436 | ; mov esi,hd_read_str |
443 | ; mov esi,hd_read_str |
437 | ; call sys_msg_board_str |
444 | ; call sys_msg_board_str |
438 | DEBUGF 1,"K : FS - HD read error\n" |
445 | DEBUGF 1,"K : FS - HD read error\n" |
439 | pop edx eax |
446 | pop edx eax |
440 | ret |
447 | ret |
441 | 448 | ||
442 | hd_write_error: |
449 | hd_write_error: |
443 | 450 | ||
444 | ; call clear_hd_cache |
451 | ; call clear_hd_cache |
445 | ; call clear_application_table_status |
452 | ; call clear_application_table_status |
446 | ; mov esi,hd_write_str |
453 | ; mov esi,hd_write_str |
447 | ; call sys_msg_board_str |
454 | ; call sys_msg_board_str |
448 | DEBUGF 1,"K : FS - HD write error\n" |
455 | DEBUGF 1,"K : FS - HD write error\n" |
449 | ret |
456 | ret |
450 | 457 | ||
451 | hd_write_error_dma: |
458 | hd_write_error_dma: |
452 | ; call clear_hd_cache |
459 | ; call clear_hd_cache |
453 | ; call clear_application_table_status |
460 | ; call clear_application_table_status |
454 | ; mov esi, hd_write_str |
461 | ; mov esi, hd_write_str |
455 | ; call sys_msg_board_str |
462 | ; call sys_msg_board_str |
456 | DEBUGF 1,"K : FS - HD read error\n" |
463 | DEBUGF 1,"K : FS - HD read error\n" |
457 | pop esi |
464 | pop esi |
458 | ret |
465 | ret |
459 | 466 | ||
460 | hd_lba_error: |
467 | hd_lba_error: |
461 | ; call clear_hd_cache |
468 | ; call clear_hd_cache |
462 | ; call clear_application_table_status |
469 | ; call clear_application_table_status |
463 | ; mov esi,hd_lba_str |
470 | ; mov esi,hd_lba_str |
464 | ; call sys_msg_board_str |
471 | ; call sys_msg_board_str |
465 | DEBUGF 1,"K : FS - HD LBA error\n" |
472 | DEBUGF 1,"K : FS - HD LBA error\n" |
466 | jmp LBA_read_ret |
473 | jmp LBA_read_ret |
467 | 474 | ||
468 | 475 | ||
469 | align 4 |
476 | align 4 |
470 | wait_for_hd_idle: |
477 | wait_for_hd_idle: |
471 | 478 | ||
472 | push eax edx |
479 | push eax edx |
473 | 480 | ||
474 | call save_hd_wait_timeout |
481 | call save_hd_wait_timeout |
475 | 482 | ||
476 | mov edx,[hdbase] |
483 | mov edx,[hdbase] |
477 | add edx,0x7 |
484 | add edx,0x7 |
478 | 485 | ||
479 | wfhil1: |
486 | wfhil1: |
480 | 487 | ||
481 | call check_hd_wait_timeout |
488 | call check_hd_wait_timeout |
482 | cmp [hd_error],0 |
489 | cmp [hd_error],0 |
483 | jne @f |
490 | jne @f |
484 | 491 | ||
485 | in al,dx |
492 | in al,dx |
486 | test al,128 |
493 | test al,128 |
487 | jnz wfhil1 |
494 | jnz wfhil1 |
488 | 495 | ||
489 | @@: |
496 | @@: |
490 | 497 | ||
491 | pop edx eax |
498 | pop edx eax |
492 | ret |
499 | ret |
493 | 500 | ||
494 | 501 | ||
495 | align 4 |
502 | align 4 |
496 | wait_for_sector_buffer: |
503 | wait_for_sector_buffer: |
497 | 504 | ||
498 | push eax edx |
505 | push eax edx |
499 | 506 | ||
500 | mov edx,[hdbase] |
507 | mov edx,[hdbase] |
501 | add edx,0x7 |
508 | add edx,0x7 |
502 | 509 | ||
503 | call save_hd_wait_timeout |
510 | call save_hd_wait_timeout |
504 | 511 | ||
505 | hdwait_sbuf: ; wait for sector buffer to be ready |
512 | hdwait_sbuf: ; wait for sector buffer to be ready |
506 | 513 | ||
507 | call check_hd_wait_timeout |
514 | call check_hd_wait_timeout |
508 | cmp [hd_error],0 |
515 | cmp [hd_error],0 |
509 | jne @f |
516 | jne @f |
510 | 517 | ||
511 | in al,dx |
518 | in al,dx |
512 | test al,8 |
519 | test al,8 |
513 | jz hdwait_sbuf |
520 | jz hdwait_sbuf |
514 | 521 | ||
515 | mov [hd_error],0 |
522 | mov [hd_error],0 |
516 | 523 | ||
517 | cmp [hd_setup],1 ; do not mark error for setup request |
524 | cmp [hd_setup],1 ; do not mark error for setup request |
518 | je buf_wait_ok |
525 | je buf_wait_ok |
519 | 526 | ||
520 | test al,1 ; previous command ended up with an error |
527 | test al,1 ; previous command ended up with an error |
521 | jz buf_wait_ok |
528 | jz buf_wait_ok |
522 | @@: |
529 | @@: |
523 | mov [hd_error],1 |
530 | mov [hd_error],1 |
524 | 531 | ||
525 | buf_wait_ok: |
532 | buf_wait_ok: |
526 | 533 | ||
527 | pop edx eax |
534 | pop edx eax |
528 | ret |
535 | ret |
529 | 536 | ||
530 | ; \begin{Mario79} |
537 | ; \begin{Mario79} |
531 | align 4 |
538 | align 4 |
532 | wait_for_sector_dma_ide0: |
539 | wait_for_sector_dma_ide0: |
533 | push eax |
540 | push eax |
534 | push edx |
541 | push edx |
535 | call save_hd_wait_timeout |
542 | call save_hd_wait_timeout |
536 | .wait: |
543 | .wait: |
537 | call change_task |
544 | call change_task |
538 | cmp [irq14_func], hdd_irq14 |
545 | cmp [irq14_func], hdd_irq14 |
539 | jnz .done |
546 | jnz .done |
540 | call check_hd_wait_timeout |
547 | call check_hd_wait_timeout |
541 | cmp [hd_error], 0 |
548 | cmp [hd_error], 0 |
542 | jz .wait |
549 | jz .wait |
543 | mov [irq14_func], hdd_irq_null |
550 | mov [irq14_func], hdd_irq_null |
544 | mov dx, [IDEContrRegsBaseAddr] |
551 | mov dx, [IDEContrRegsBaseAddr] |
545 | mov al, 0 |
552 | mov al, 0 |
546 | out dx, al |
553 | out dx, al |
547 | .done: |
554 | .done: |
548 | pop edx |
555 | pop edx |
549 | pop eax |
556 | pop eax |
550 | ret |
557 | ret |
551 | 558 | ||
552 | align 4 |
559 | align 4 |
553 | wait_for_sector_dma_ide1: |
560 | wait_for_sector_dma_ide1: |
554 | push eax |
561 | push eax |
555 | push edx |
562 | push edx |
556 | call save_hd_wait_timeout |
563 | call save_hd_wait_timeout |
557 | .wait: |
564 | .wait: |
558 | call change_task |
565 | call change_task |
559 | cmp [irq15_func], hdd_irq15 |
566 | cmp [irq15_func], hdd_irq15 |
560 | jnz .done |
567 | jnz .done |
561 | call check_hd_wait_timeout |
568 | call check_hd_wait_timeout |
562 | cmp [hd_error], 0 |
569 | cmp [hd_error], 0 |
563 | jz .wait |
570 | jz .wait |
564 | mov [irq15_func], hdd_irq_null |
571 | mov [irq15_func], hdd_irq_null |
565 | mov dx, [IDEContrRegsBaseAddr] |
572 | mov dx, [IDEContrRegsBaseAddr] |
566 | add dx, 8 |
573 | add dx, 8 |
567 | mov al, 0 |
574 | mov al, 0 |
568 | out dx, al |
575 | out dx, al |
569 | .done: |
576 | .done: |
570 | pop edx |
577 | pop edx |
571 | pop eax |
578 | pop eax |
572 | ret |
579 | ret |
573 | 580 | ||
574 | iglobal |
581 | iglobal |
575 | align 4 |
582 | align 4 |
576 | ; note that IDE descriptor table must be 4-byte aligned and do not cross 4K boundary |
583 | ; note that IDE descriptor table must be 4-byte aligned and do not cross 4K boundary |
577 | IDE_descriptor_table: |
584 | IDE_descriptor_table: |
578 | dd OS_BASE+284000h |
585 | dd OS_BASE+284000h |
579 | dw 2000h |
586 | dw 2000h |
580 | dw 8000h |
587 | dw 8000h |
581 | 588 | ||
582 | dma_cur_sector dd not 40h |
589 | dma_cur_sector dd not 40h |
583 | irq14_func dd hdd_irq_null |
590 | irq14_func dd hdd_irq_null |
584 | irq15_func dd hdd_irq_null |
591 | irq15_func dd hdd_irq_null |
585 | endg |
592 | endg |
586 | 593 | ||
587 | uglobal |
594 | uglobal |
588 | ; all uglobals are zeroed at boot |
595 | ; all uglobals are zeroed at boot |
589 | dma_process dd 0 |
596 | dma_process dd 0 |
590 | dma_slot_ptr dd 0 |
597 | dma_slot_ptr dd 0 |
591 | cache_chain_pos dd 0 |
598 | cache_chain_pos dd 0 |
592 | cache_chain_ptr dd 0 |
599 | cache_chain_ptr dd 0 |
593 | cache_chain_size db 0 |
600 | cache_chain_size db 0 |
594 | cache_chain_started db 0 |
601 | cache_chain_started db 0 |
595 | dma_task_switched db 0 |
602 | dma_task_switched db 0 |
596 | dma_hdd db 0 |
603 | dma_hdd db 0 |
597 | allow_dma_write db 0 |
604 | allow_dma_write db 0 |
598 | endg |
605 | endg |
599 | 606 | ||
600 | align 4 |
607 | align 4 |
601 | hdd_irq14: |
608 | hdd_irq14: |
602 | pushfd |
609 | pushfd |
603 | cli |
610 | cli |
604 | pushad |
611 | pushad |
605 | mov [irq14_func], hdd_irq_null |
612 | mov [irq14_func], hdd_irq_null |
606 | mov dx, [IDEContrRegsBaseAddr] |
613 | mov dx, [IDEContrRegsBaseAddr] |
607 | mov al, 0 |
614 | mov al, 0 |
608 | out dx, al |
615 | out dx, al |
609 | call update_counters |
616 | call update_counters |
610 | mov ebx, [dma_process] |
617 | mov ebx, [dma_process] |
611 | cmp [CURRENT_TASK], ebx |
618 | cmp [CURRENT_TASK], ebx |
612 | jz .noswitch |
619 | jz .noswitch |
613 | mov [dma_task_switched], 1 |
620 | mov [dma_task_switched], 1 |
614 | mov edi, [dma_slot_ptr] |
621 | mov edi, [dma_slot_ptr] |
615 | mov eax, [CURRENT_TASK] |
622 | mov eax, [CURRENT_TASK] |
616 | mov [dma_process], eax |
623 | mov [dma_process], eax |
617 | mov eax, [TASK_BASE] |
624 | mov eax, [TASK_BASE] |
618 | mov [dma_slot_ptr], eax |
625 | mov [dma_slot_ptr], eax |
619 | mov [CURRENT_TASK], ebx |
626 | mov [CURRENT_TASK], ebx |
620 | mov [TASK_BASE], edi |
627 | mov [TASK_BASE], edi |
621 | mov byte [0xFFFF], 1 |
628 | mov byte [0xFFFF], 1 |
622 | call do_change_task |
629 | call do_change_task |
623 | .noswitch: |
630 | .noswitch: |
624 | popad |
631 | popad |
625 | popfd |
632 | popfd |
626 | align 4 |
633 | align 4 |
627 | hdd_irq_null: |
634 | hdd_irq_null: |
628 | ret |
635 | ret |
629 | 636 | ||
630 | align 4 |
637 | align 4 |
631 | hdd_irq15: |
638 | hdd_irq15: |
632 | pushfd |
639 | pushfd |
633 | cli |
640 | cli |
634 | pushad |
641 | pushad |
635 | mov [irq15_func], hdd_irq_null |
642 | mov [irq15_func], hdd_irq_null |
636 | mov dx, [IDEContrRegsBaseAddr] |
643 | mov dx, [IDEContrRegsBaseAddr] |
637 | add dx, 8 |
644 | add dx, 8 |
638 | mov al, 0 |
645 | mov al, 0 |
639 | out dx, al |
646 | out dx, al |
640 | call update_counters |
647 | call update_counters |
641 | mov ebx, [dma_process] |
648 | mov ebx, [dma_process] |
642 | cmp [CURRENT_TASK], ebx |
649 | cmp [CURRENT_TASK], ebx |
643 | jz .noswitch |
650 | jz .noswitch |
644 | mov [dma_task_switched], 1 |
651 | mov [dma_task_switched], 1 |
645 | mov edi, [dma_slot_ptr] |
652 | mov edi, [dma_slot_ptr] |
646 | mov eax, [CURRENT_TASK] |
653 | mov eax, [CURRENT_TASK] |
647 | mov [dma_process], eax |
654 | mov [dma_process], eax |
648 | mov eax, [TASK_BASE] |
655 | mov eax, [TASK_BASE] |
649 | mov [dma_slot_ptr], eax |
656 | mov [dma_slot_ptr], eax |
650 | mov [CURRENT_TASK], ebx |
657 | mov [CURRENT_TASK], ebx |
651 | mov [TASK_BASE], edi |
658 | mov [TASK_BASE], edi |
652 | mov byte [0xFFFF], 1 |
659 | mov byte [0xFFFF], 1 |
653 | call do_change_task |
660 | call do_change_task |
654 | .noswitch: |
661 | .noswitch: |
655 | popad |
662 | popad |
656 | popfd |
663 | popfd |
657 | ret |
664 | ret |
658 | 665 | ||
659 | align 4 |
666 | align 4 |
660 | hd_read_dma: |
667 | hd_read_dma: |
661 | push eax |
668 | push eax |
662 | push edx |
669 | push edx |
663 | mov edx, [dma_cur_sector] |
670 | mov edx, [dma_cur_sector] |
664 | cmp eax, edx |
671 | cmp eax, edx |
665 | jb .notread |
672 | jb .notread |
666 | add edx, 15 |
673 | add edx, 15 |
667 | cmp [esp+4], edx |
674 | cmp [esp+4], edx |
668 | ja .notread |
675 | ja .notread |
669 | mov eax, [esp+4] |
676 | mov eax, [esp+4] |
670 | sub eax, [dma_cur_sector] |
677 | sub eax, [dma_cur_sector] |
671 | shl eax, 9 |
678 | shl eax, 9 |
672 | add eax, OS_BASE+0x284000 |
679 | add eax, OS_BASE+0x284000 |
673 | push ecx esi edi |
680 | push ecx esi edi |
674 | mov esi, eax |
681 | mov esi, eax |
675 | shl edi, 9 |
682 | shl edi, 9 |
676 | add edi, OS_BASE+0x610000 |
683 | add edi, OS_BASE+0x610000 |
677 | mov ecx, 512/4 |
684 | mov ecx, 512/4 |
678 | cld |
685 | cld |
679 | rep movsd |
686 | rep movsd |
680 | pop edi esi ecx |
687 | pop edi esi ecx |
681 | pop edx |
688 | pop edx |
682 | pop eax |
689 | pop eax |
683 | ret |
690 | ret |
684 | .notread: |
691 | .notread: |
685 | mov eax, IDE_descriptor_table-OS_BASE |
692 | mov eax, IDE_descriptor_table-OS_BASE |
686 | mov dword [eax+OS_BASE], 0x284000 |
693 | mov dword [eax+OS_BASE], 0x284000 |
687 | mov word [eax+4+OS_BASE], 0x2000 |
694 | mov word [eax+4+OS_BASE], 0x2000 |
688 | mov dx, [IDEContrRegsBaseAddr] |
695 | mov dx, [IDEContrRegsBaseAddr] |
689 | cmp [hdbase], 0x1F0 |
696 | cmp [hdbase], 0x1F0 |
690 | jz @f |
697 | jz @f |
691 | add edx, 8 |
698 | add edx, 8 |
692 | @@: |
699 | @@: |
693 | push edx |
700 | push edx |
694 | add edx, 4 |
701 | add edx, 4 |
695 | out dx, eax |
702 | out dx, eax |
696 | pop edx |
703 | pop edx |
697 | mov al, 0 |
704 | mov al, 0 |
698 | out dx, al |
705 | out dx, al |
699 | add edx, 2 |
706 | add edx, 2 |
700 | mov al, 6 |
707 | mov al, 6 |
701 | out dx, al |
708 | out dx, al |
702 | call wait_for_hd_idle |
709 | call wait_for_hd_idle |
703 | cmp [hd_error], 0 |
710 | cmp [hd_error], 0 |
704 | jnz hd_read_error |
711 | jnz hd_read_error |
705 | call disable_ide_int |
712 | call disable_ide_int |
706 | xor eax, eax |
713 | xor eax, eax |
707 | mov edx, [hdbase] |
714 | mov edx, [hdbase] |
708 | inc edx |
715 | inc edx |
709 | out dx, al |
716 | out dx, al |
710 | inc edx |
717 | inc edx |
711 | mov eax, 10h |
718 | mov eax, 10h |
712 | out dx, al |
719 | out dx, al |
713 | inc edx |
720 | inc edx |
714 | mov eax, [esp+4] |
721 | mov eax, [esp+4] |
715 | out dx, al |
722 | out dx, al |
716 | shr eax, 8 |
723 | shr eax, 8 |
717 | inc edx |
724 | inc edx |
718 | out dx, al |
725 | out dx, al |
719 | shr eax, 8 |
726 | shr eax, 8 |
720 | inc edx |
727 | inc edx |
721 | out dx, al |
728 | out dx, al |
722 | shr eax, 8 |
729 | shr eax, 8 |
723 | inc edx |
730 | inc edx |
724 | and al, 0xF |
731 | and al, 0xF |
725 | add al, byte [hdid] |
732 | add al, byte [hdid] |
726 | add al, 11100000b |
733 | add al, 11100000b |
727 | out dx, al |
734 | out dx, al |
728 | inc edx |
735 | inc edx |
729 | mov al, 0xC8 |
736 | mov al, 0xC8 |
730 | out dx, al |
737 | out dx, al |
731 | mov dx, [IDEContrRegsBaseAddr] |
738 | mov dx, [IDEContrRegsBaseAddr] |
732 | cmp [hdbase], 0x1F0 |
739 | cmp [hdbase], 0x1F0 |
733 | jz @f |
740 | jz @f |
734 | add dx, 8 |
741 | add dx, 8 |
735 | @@: |
742 | @@: |
736 | mov al, 9 |
743 | mov al, 9 |
737 | out dx, al |
744 | out dx, al |
738 | mov eax, [CURRENT_TASK] |
745 | mov eax, [CURRENT_TASK] |
739 | mov [dma_process], eax |
746 | mov [dma_process], eax |
740 | mov eax, [TASK_BASE] |
747 | mov eax, [TASK_BASE] |
741 | mov [dma_slot_ptr], eax |
748 | mov [dma_slot_ptr], eax |
742 | cmp [hdbase], 0x1F0 |
749 | cmp [hdbase], 0x1F0 |
743 | jnz .ide1 |
750 | jnz .ide1 |
744 | mov [irq14_func], hdd_irq14 |
751 | mov [irq14_func], hdd_irq14 |
745 | jmp @f |
752 | jmp @f |
746 | .ide1: |
753 | .ide1: |
747 | mov [irq15_func], hdd_irq15 |
754 | mov [irq15_func], hdd_irq15 |
748 | @@: |
755 | @@: |
749 | call enable_ide_int |
756 | call enable_ide_int |
750 | cmp [hdbase], 0x1F0 |
757 | cmp [hdbase], 0x1F0 |
751 | jnz .wait_ide1 |
758 | jnz .wait_ide1 |
752 | call wait_for_sector_dma_ide0 |
759 | call wait_for_sector_dma_ide0 |
753 | jmp @f |
760 | jmp @f |
754 | .wait_ide1: |
761 | .wait_ide1: |
755 | call wait_for_sector_dma_ide1 |
762 | call wait_for_sector_dma_ide1 |
756 | @@: |
763 | @@: |
757 | cmp [hd_error], 0 |
764 | cmp [hd_error], 0 |
758 | jnz hd_read_error |
765 | jnz hd_read_error |
759 | pop edx |
766 | pop edx |
760 | pop eax |
767 | pop eax |
761 | mov [dma_cur_sector], eax |
768 | mov [dma_cur_sector], eax |
762 | jmp hd_read_dma |
769 | jmp hd_read_dma |
763 | 770 | ||
764 | align 4 |
771 | align 4 |
765 | write_cache_chain: |
772 | write_cache_chain: |
766 | push esi |
773 | push esi |
767 | mov eax, IDE_descriptor_table |
774 | mov eax, IDE_descriptor_table |
768 | mov edx, [cache_chain_pos] |
775 | mov edx, [cache_chain_pos] |
769 | shl edx, 9 |
776 | shl edx, 9 |
770 | add edx, OS_BASE+0x610000 |
777 | add edx, OS_BASE+0x610000 |
771 | mov [eax], edx |
778 | mov [eax], edx |
772 | movzx edx, [cache_chain_size] |
779 | movzx edx, [cache_chain_size] |
773 | shl edx, 9 |
780 | shl edx, 9 |
774 | mov [eax+4], dx |
781 | mov [eax+4], dx |
775 | jmp do_write_dma |
782 | jmp do_write_dma |
776 | write_cache_sector: |
783 | write_cache_sector: |
777 | push esi |
784 | push esi |
778 | mov eax, IDE_descriptor_table |
785 | mov eax, IDE_descriptor_table |
779 | mov edx, edi |
786 | mov edx, edi |
780 | shl edx, 9 |
787 | shl edx, 9 |
781 | add edx, OS_BASE+0x610000 |
788 | add edx, OS_BASE+0x610000 |
782 | mov [eax], edx |
789 | mov [eax], edx |
783 | mov word [eax+4], 0x200 |
790 | mov word [eax+4], 0x200 |
784 | do_write_dma: |
791 | do_write_dma: |
785 | mov dx, [IDEContrRegsBaseAddr] |
792 | mov dx, [IDEContrRegsBaseAddr] |
786 | cmp [hdbase], 0x1F0 |
793 | cmp [hdbase], 0x1F0 |
787 | jz @f |
794 | jz @f |
788 | add edx, 8 |
795 | add edx, 8 |
789 | @@: |
796 | @@: |
790 | push edx |
797 | push edx |
791 | add edx, 4 |
798 | add edx, 4 |
792 | out dx, eax |
799 | out dx, eax |
793 | pop edx |
800 | pop edx |
794 | mov al, 0 |
801 | mov al, 0 |
795 | out dx, al |
802 | out dx, al |
796 | add edx, 2 |
803 | add edx, 2 |
797 | mov al, 6 |
804 | mov al, 6 |
798 | out dx, al |
805 | out dx, al |
799 | call wait_for_hd_idle |
806 | call wait_for_hd_idle |
800 | cmp [hd_error], 0 |
807 | cmp [hd_error], 0 |
801 | jnz hd_write_error_dma |
808 | jnz hd_write_error_dma |
802 | call disable_ide_int |
809 | call disable_ide_int |
803 | xor eax, eax |
810 | xor eax, eax |
804 | mov edx, [hdbase] |
811 | mov edx, [hdbase] |
805 | inc edx |
812 | inc edx |
806 | out dx, al |
813 | out dx, al |
807 | inc edx |
814 | inc edx |
808 | mov al, [cache_chain_size] |
815 | mov al, [cache_chain_size] |
809 | out dx, al |
816 | out dx, al |
810 | inc edx |
817 | inc edx |
811 | mov esi, [cache_chain_ptr] |
818 | mov esi, [cache_chain_ptr] |
812 | mov eax, [esi] |
819 | mov eax, [esi] |
813 | out dx, al |
820 | out dx, al |
814 | shr eax, 8 |
821 | shr eax, 8 |
815 | inc edx |
822 | inc edx |
816 | out dx, al |
823 | out dx, al |
817 | shr eax, 8 |
824 | shr eax, 8 |
818 | inc edx |
825 | inc edx |
819 | out dx, al |
826 | out dx, al |
820 | shr eax, 8 |
827 | shr eax, 8 |
821 | inc edx |
828 | inc edx |
822 | and al, 0xF |
829 | and al, 0xF |
823 | add al, byte [hdid] |
830 | add al, byte [hdid] |
824 | add al, 11100000b |
831 | add al, 11100000b |
825 | out dx, al |
832 | out dx, al |
826 | inc edx |
833 | inc edx |
827 | mov al, 0xCA |
834 | mov al, 0xCA |
828 | out dx, al |
835 | out dx, al |
829 | mov dx, [IDEContrRegsBaseAddr] |
836 | mov dx, [IDEContrRegsBaseAddr] |
830 | cmp [hdbase], 0x1F0 |
837 | cmp [hdbase], 0x1F0 |
831 | jz @f |
838 | jz @f |
832 | add dx, 8 |
839 | add dx, 8 |
833 | @@: |
840 | @@: |
834 | mov al, 1 |
841 | mov al, 1 |
835 | out dx, al |
842 | out dx, al |
836 | mov eax, [CURRENT_TASK] |
843 | mov eax, [CURRENT_TASK] |
837 | mov [dma_process], eax |
844 | mov [dma_process], eax |
838 | mov eax, [TASK_BASE] |
845 | mov eax, [TASK_BASE] |
839 | mov [dma_slot_ptr], eax |
846 | mov [dma_slot_ptr], eax |
840 | cmp [hdbase], 0x1F0 |
847 | cmp [hdbase], 0x1F0 |
841 | jnz .ide1 |
848 | jnz .ide1 |
842 | mov [irq14_func], hdd_irq14 |
849 | mov [irq14_func], hdd_irq14 |
843 | jmp @f |
850 | jmp @f |
844 | .ide1: |
851 | .ide1: |
845 | mov [irq15_func], hdd_irq15 |
852 | mov [irq15_func], hdd_irq15 |
846 | @@: |
853 | @@: |
847 | call enable_ide_int |
854 | call enable_ide_int |
848 | mov [dma_cur_sector], not 0x40 |
855 | mov [dma_cur_sector], not 0x40 |
849 | cmp [hdbase], 0x1F0 |
856 | cmp [hdbase], 0x1F0 |
850 | jnz .wait_ide1 |
857 | jnz .wait_ide1 |
851 | call wait_for_sector_dma_ide0 |
858 | call wait_for_sector_dma_ide0 |
852 | jmp @f |
859 | jmp @f |
853 | .wait_ide1: |
860 | .wait_ide1: |
854 | call wait_for_sector_dma_ide1 |
861 | call wait_for_sector_dma_ide1 |
855 | @@: |
862 | @@: |
856 | cmp [hd_error], 0 |
863 | cmp [hd_error], 0 |
857 | jnz hd_write_error_dma |
864 | jnz hd_write_error_dma |
858 | pop esi |
865 | pop esi |
859 | ret |
866 | ret |
860 | 867 | ||
861 | uglobal |
868 | uglobal |
862 | IDEContrRegsBaseAddr dw ? |
869 | IDEContrRegsBaseAddr dw ? |
863 | endg |
870 | endg |
864 | ; \end{Mario79} |
871 | ; \end{Mario79} |