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