Rev 139 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 139 | Rev 160 | ||
---|---|---|---|
Line 164... | Line 164... | ||
164 | ret |
164 | ret |
165 | .IDE_Channel_2: |
165 | .IDE_Channel_2: |
166 | mov [IDE_Channel_2],0 |
166 | mov [IDE_Channel_2],0 |
167 | ret |
167 | ret |
168 | ;******************************************** |
168 | ;******************************************** |
169 | clear_hd_cache: |
- | |
170 | - | ||
171 | push eax ecx edi |
- | |
172 | mov edi,0x600000 |
- | |
173 | mov ecx,16384 |
- | |
174 | xor eax,eax |
- | |
175 | cld |
- | |
176 | rep stosd ; clear hd cache with 0 |
- | |
177 | mov [cache_search_start],eax |
- | |
178 | mov [fat_in_cache],-1 |
- | |
179 | mov [fat_change],0 |
- | |
180 | pop edi ecx eax |
- | |
181 | ret |
- | |
182 | - | ||
183 | problem_partition db 0 ; used for partitions search |
169 | problem_partition db 0 ; used for partitions search |
Line 184... | Line 170... | ||
184 | 170 | ||
Line 185... | Line 171... | ||
185 | include 'part_set.inc' |
171 | include 'part_set.inc' |
Line 1924... | Line 1910... | ||
1924 | 1910 | ||
1925 | call write_cache |
1911 | call write_cache |
1926 | update_disk_acces_denied: |
1912 | update_disk_acces_denied: |
Line 1927... | Line -... | ||
1927 | ret |
- | |
1928 | - | ||
1929 | - | ||
1930 | ;************************************************************************** |
- | |
1931 | ; |
- | |
1932 | ; 0x600008 - first entry in cache list |
- | |
1933 | ; |
- | |
1934 | ; +0 - lba sector |
- | |
1935 | ; +4 - state of cache sector |
- | |
1936 | ; 0 = empty |
- | |
1937 | ; 1 = used for read ( same as in hd ) |
- | |
1938 | ; 2 = used for write ( differs from hd ) |
- | |
1939 | ; |
- | |
1940 | ; +65536 - cache entries |
- | |
1941 | ; |
- | |
1942 | ;************************************************************************** |
- | |
1943 | - | ||
1944 | - | ||
1945 | hd_read: |
- | |
1946 | ;----------------------------------------------------------- |
- | |
1947 | ; input : eax = block to read |
- | |
1948 | ; ebx = destination |
- | |
1949 | ;----------------------------------------------------------- |
- | |
1950 | push ecx esi edi ; scan cache |
- | |
1951 | - | ||
1952 | mov ecx,cache_max ; entries in cache |
- | |
1953 | mov esi,0x600000+8 |
- | |
1954 | mov edi,1 |
- | |
1955 | - | ||
1956 | hdreadcache: |
- | |
1957 | - | ||
1958 | cmp dword [esi+4],0 ; empty |
- | |
1959 | je nohdcache |
- | |
1960 | - | ||
1961 | cmp [esi],eax ; correct sector |
- | |
1962 | je yeshdcache |
- | |
1963 | - | ||
1964 | nohdcache: |
- | |
1965 | - | ||
1966 | add esi,8 |
- | |
1967 | inc edi |
- | |
1968 | dec ecx |
- | |
1969 | jnz hdreadcache |
- | |
1970 | - | ||
1971 | call find_empty_slot ; ret in edi |
- | |
1972 | cmp [hd_error],0 |
- | |
1973 | jne return_01 |
- | |
1974 | - | ||
1975 | push eax edx |
- | |
1976 | - | ||
1977 | call disable_ide_int |
- | |
1978 | - | ||
1979 | call wait_for_hd_idle |
- | |
1980 | cmp [hd_error],0 |
- | |
1981 | jne hd_read_error |
- | |
1982 | - | ||
1983 | ; cli |
- | |
1984 | xor eax,eax |
- | |
1985 | mov edx,[hdbase] |
- | |
1986 | inc edx |
- | |
1987 | out dx,al ; ATAFeatures ॣ¨áâà "®á®¡¥®á⥩" |
- | |
1988 | inc edx |
- | |
1989 | inc eax |
- | |
1990 | out dx,al ; ATASectorCount áç¥â稪 ᥪâ®à®¢ |
- | |
1991 | inc edx |
- | |
1992 | mov eax,[esp+4] |
- | |
1993 | out dx,al ; ATASectorNumber ॣ¨áâà ®¬¥à ᥪâ®à |
- | |
1994 | shr eax,8 |
- | |
1995 | inc edx |
- | |
1996 | out dx,al ; ATACylinder ®¬¥à 樫¨¤à (¬« ¤è¨© ¡ ©â) |
- | |
1997 | shr eax,8 |
- | |
1998 | inc edx |
- | |
1999 | out dx,al ; ®¬¥à 樫¨¤à (áâ à訩 ¡ ©â) |
- | |
2000 | shr eax,8 |
- | |
2001 | inc edx |
- | |
2002 | and al,1+2+4+8 |
- | |
2003 | add al,byte [hdid] |
- | |
2004 | add al,128+64+32 |
- | |
2005 | out dx,al ; ®¬¥à £®«®¢ª¨/®¬¥à ¤¨áª |
- | |
2006 | inc edx |
- | |
2007 | mov al,20h |
- | |
2008 | out dx,al ; ATACommand ॣ¨áâà ª®¬ ¤ |
- | |
2009 | ; sti |
- | |
2010 | - | ||
2011 | call wait_for_sector_buffer |
- | |
2012 | - | ||
2013 | cmp [hd_error],0 |
- | |
2014 | jne hd_read_error |
- | |
2015 | - | ||
2016 | ; cli |
- | |
2017 | push edi |
- | |
2018 | shl edi,9 |
- | |
2019 | add edi,0x600000+65536 |
- | |
2020 | mov ecx,256 |
- | |
2021 | mov edx,[hdbase] |
- | |
2022 | cld |
- | |
2023 | rep insw |
- | |
2024 | pop edi |
- | |
2025 | ; sti |
- | |
2026 | - | ||
2027 | call enable_ide_int |
- | |
2028 | - | ||
2029 | pop edx eax |
- | |
2030 | blok_read_2: |
- | |
2031 | lea esi,[edi*8+0x600000] |
- | |
2032 | mov [esi],eax ; sector number |
- | |
2033 | mov dword [esi+4],1 ; hd read - mark as same as in hd |
- | |
2034 | - | ||
2035 | yeshdcache: |
- | |
2036 | - | ||
2037 | mov esi,edi |
- | |
2038 | shl esi,9 |
- | |
2039 | add esi,0x600000+65536 |
- | |
2040 | mov edi,ebx |
- | |
2041 | mov ecx,512/4 |
- | |
2042 | cld |
- | |
2043 | rep movsd ; move data |
- | |
2044 | return_01: |
- | |
2045 | pop edi esi ecx |
- | |
2046 | ret |
- | |
2047 | - | ||
2048 | disable_ide_int: |
- | |
2049 | mov edx,[hdbase] |
- | |
2050 | add edx,0x206 |
- | |
2051 | mov al,2 |
- | |
2052 | out dx,al |
- | |
2053 | ret |
- | |
2054 | - | ||
2055 | enable_ide_int: |
- | |
2056 | mov edx,[hdbase] |
- | |
2057 | add edx,0x206 |
- | |
2058 | mov al,0 |
- | |
2059 | out dx,al |
- | |
2060 | ret |
- | |
2061 | - | ||
2062 | hd_write: |
- | |
2063 | ;----------------------------------------------------------- |
- | |
2064 | ; input : eax = block |
- | |
2065 | ; ebx = pointer to memory |
- | |
2066 | ;----------------------------------------------------------- |
- | |
2067 | push ecx esi edi |
- | |
2068 | - | ||
2069 | ; check if the cache already has the sector and overwrite it |
- | |
2070 | - | ||
2071 | mov ecx,cache_max |
- | |
2072 | mov esi,0x600000+8 |
- | |
2073 | mov edi,1 |
- | |
2074 | - | ||
2075 | hdwritecache: |
- | |
2076 | - | ||
2077 | cmp dword [esi+4],0 ; if cache slot is empty |
- | |
2078 | je not_in_cache_write |
- | |
2079 | - | ||
2080 | cmp [esi],eax ; if the slot has the sector |
- | |
2081 | je yes_in_cache_write |
- | |
2082 | - | ||
2083 | not_in_cache_write: |
- | |
2084 | - | ||
2085 | add esi,8 |
- | |
2086 | inc edi |
- | |
2087 | dec ecx |
- | |
2088 | jnz hdwritecache |
- | |
2089 | - | ||
2090 | ; sector not found in cache |
- | |
2091 | ; write the block to a new location |
- | |
2092 | - | ||
2093 | call find_empty_slot ; ret in edi |
- | |
2094 | cmp [hd_error],0 |
- | |
2095 | jne hd_write_access_denied |
- | |
2096 | - | ||
2097 | lea esi,[edi*8+0x600000] |
- | |
2098 | mov [esi],eax ; sector number |
- | |
2099 | - | ||
2100 | yes_in_cache_write: |
- | |
2101 | - | ||
2102 | mov dword [esi+4],2 ; write - differs from hd |
- | |
2103 | - | ||
2104 | shl edi,9 |
- | |
2105 | add edi,0x600000+65536 |
- | |
2106 | mov esi,ebx |
- | |
2107 | mov ecx,512/4 |
- | |
2108 | cld |
- | |
2109 | rep movsd ; move data |
- | |
2110 | hd_write_access_denied: |
- | |
2111 | pop edi esi ecx |
- | |
2112 | ret |
- | |
2113 | - | ||
2114 | - | ||
2115 | write_cache: |
- | |
2116 | ;----------------------------------------------------------- |
- | |
2117 | ; write all changed sectors to disk |
- | |
2118 | ;----------------------------------------------------------- |
- | |
2119 | push eax ecx edx esi edi |
- | |
2120 | - | ||
2121 | ; write difference ( 2 ) from cache to hd |
- | |
2122 | - | ||
2123 | mov ecx,cache_max |
- | |
2124 | mov esi,0x600000+8 |
- | |
2125 | mov edi,1 |
- | |
2126 | - | ||
2127 | write_cache_more: |
- | |
2128 | - | ||
2129 | cmp dword [esi+4],2 ; if cache slot is not different |
- | |
2130 | jne does_not_need_writing |
- | |
2131 | - | ||
2132 | mov dword [esi+4],1 ; same as in hd |
- | |
2133 | mov eax,[esi] ; eax = sector to write |
- | |
2134 | - | ||
2135 | cmp eax,[PARTITION_START] |
- | |
2136 | jb danger |
- | |
2137 | cmp eax,[PARTITION_END] |
- | |
2138 | ja danger |
- | |
2139 | - | ||
2140 | call disable_ide_int |
- | |
2141 | - | ||
2142 | call wait_for_hd_idle |
- | |
2143 | cmp [hd_error],0 |
- | |
2144 | jne hd_write_error |
- | |
2145 | - | ||
2146 | ; cli |
- | |
2147 | xor eax,eax |
- | |
2148 | mov edx,[hdbase] |
- | |
2149 | inc edx |
- | |
2150 | out dx,al |
- | |
2151 | inc edx |
- | |
2152 | inc eax |
- | |
2153 | out dx,al |
- | |
2154 | inc edx |
- | |
2155 | mov eax,[esi] ; eax = sector to write |
- | |
2156 | out dx,al |
- | |
2157 | shr eax,8 |
- | |
2158 | inc edx |
- | |
2159 | out dx,al |
- | |
2160 | shr eax,8 |
- | |
2161 | inc edx |
- | |
2162 | out dx,al |
- | |
2163 | shr eax,8 |
- | |
2164 | inc edx |
- | |
2165 | and al,1+2+4+8 |
- | |
2166 | add al,byte [hdid] |
- | |
2167 | add al,128+64+32 |
- | |
2168 | out dx,al |
- | |
2169 | inc edx |
- | |
2170 | mov al,30h |
- | |
2171 | out dx,al |
- | |
2172 | ; sti |
- | |
2173 | - | ||
2174 | call wait_for_sector_buffer |
- | |
2175 | - | ||
2176 | cmp [hd_error],0 |
- | |
2177 | jne hd_write_error |
- | |
2178 | - | ||
2179 | push ecx esi |
- | |
2180 | - | ||
2181 | ; cli |
- | |
2182 | mov esi,edi |
- | |
2183 | shl esi,9 |
- | |
2184 | add esi,0x600000+65536 ; esi = from memory position |
- | |
2185 | mov ecx,256 |
- | |
2186 | mov edx,[hdbase] |
- | |
2187 | cld |
- | |
2188 | rep outsw |
- | |
2189 | ; sti |
- | |
2190 | - | ||
2191 | pop esi ecx |
- | |
2192 | - | ||
2193 | call enable_ide_int |
- | |
2194 | - | ||
2195 | danger: |
- | |
2196 | does_not_need_writing: |
- | |
2197 | - | ||
2198 | add esi,8 |
- | |
2199 | inc edi |
- | |
2200 | dec ecx |
- | |
2201 | jnz write_cache_more |
- | |
2202 | return_02: |
- | |
2203 | pop edi esi edx ecx eax |
- | |
2204 | ret |
- | |
2205 | - | ||
2206 | - | ||
2207 | find_empty_slot: |
- | |
2208 | ;----------------------------------------------------------- |
- | |
2209 | ; find empty or read slot, flush cache if next 10% is used by write |
- | |
2210 | ; output : edi = cache slot |
- | |
2211 | ;----------------------------------------------------------- |
- | |
2212 | push ecx esi |
- | |
2213 | - | ||
2214 | search_again: |
- | |
2215 | - | ||
2216 | mov ecx,cache_max*10/100 |
- | |
2217 | mov edi,[cache_search_start] |
- | |
2218 | - | ||
2219 | search_for_empty: |
- | |
2220 | - | ||
2221 | inc edi |
- | |
2222 | cmp edi,cache_max |
- | |
2223 | jbe inside_cache |
- | |
2224 | mov edi,1 |
- | |
2225 | - | ||
2226 | inside_cache: |
- | |
2227 | - | ||
2228 | cmp dword [edi*8+0x600000+4],2 ; get cache slot info |
- | |
2229 | jb found_slot ; it's empty or read |
- | |
2230 | dec ecx |
- | |
2231 | jnz search_for_empty |
- | |
2232 | - | ||
2233 | call write_cache ; no empty slots found, write all |
- | |
2234 | cmp [hd_error],0 |
- | |
2235 | jne found_slot_access_denied |
- | |
2236 | - | ||
2237 | jmp search_again ; and start again |
- | |
2238 | - | ||
2239 | found_slot: |
- | |
2240 | - | ||
2241 | mov [cache_search_start],edi |
- | |
2242 | found_slot_access_denied: |
- | |
2243 | pop esi ecx |
- | |
2244 | ret |
- | |
2245 | - | ||
2246 | - | ||
2247 | save_hd_wait_timeout: |
- | |
2248 | - | ||
2249 | push eax |
- | |
2250 | mov eax,[timer_ticks];[0xfdf0] |
- | |
2251 | add eax,300 ; 3 sec timeout |
- | |
2252 | mov [hd_wait_timeout],eax |
- | |
2253 | pop eax |
- | |
2254 | ret |
- | |
2255 | - | ||
2256 | - | ||
2257 | check_hd_wait_timeout: |
- | |
2258 | - | ||
2259 | push eax |
- | |
2260 | mov eax,[hd_wait_timeout] |
- | |
2261 | cmp [timer_ticks], eax ;[0xfdf0],eax |
- | |
2262 | jg hd_timeout_error |
- | |
2263 | pop eax |
- | |
2264 | mov [hd_error],0 |
- | |
2265 | ret |
- | |
2266 | - | ||
2267 | iglobal |
- | |
2268 | hd_timeout_str db 'K : FS - HD timeout',13,10,0 |
- | |
2269 | hd_read_str db 'K : FS - HD read error',13,10,0 |
- | |
2270 | hd_write_str db 'K : FS - HD write error',13,10,0 |
- | |
2271 | hd_lba_str db 'K : FS - HD LBA error',13,10,0 |
- | |
2272 | endg |
- | |
2273 | - | ||
2274 | hd_timeout_error: |
- | |
2275 | - | ||
2276 | call clear_hd_cache |
- | |
2277 | call clear_application_table_status |
- | |
2278 | mov esi,hd_timeout_str |
- | |
2279 | call sys_msg_board_str |
- | |
2280 | ; jmp $ |
- | |
2281 | mov [hd_error],1 |
- | |
2282 | pop eax |
- | |
2283 | ret |
- | |
2284 | - | ||
2285 | hd_read_error: |
- | |
2286 | - | ||
2287 | call clear_hd_cache |
- | |
2288 | call clear_application_table_status |
- | |
2289 | mov esi,hd_read_str |
- | |
2290 | call sys_msg_board_str |
- | |
2291 | pop edx eax |
- | |
2292 | jmp return_01 |
- | |
2293 | ; jmp $ |
- | |
2294 | - | ||
2295 | hd_write_error: |
- | |
2296 | - | ||
2297 | call clear_hd_cache |
- | |
2298 | call clear_application_table_status |
- | |
2299 | mov esi,hd_write_str |
- | |
2300 | call sys_msg_board_str |
- | |
2301 | jmp return_02 |
- | |
2302 | ; jmp $ |
- | |
2303 | - | ||
2304 | hd_lba_error: |
- | |
2305 | call clear_hd_cache |
- | |
2306 | call clear_application_table_status |
- | |
2307 | mov esi,hd_lba_str |
- | |
2308 | call sys_msg_board_str |
- | |
2309 | jmp LBA_read_ret |
- | |
2310 | - | ||
2311 | - | ||
2312 | wait_for_hd_idle: |
- | |
2313 | - | ||
2314 | push eax edx |
- | |
2315 | - | ||
2316 | call save_hd_wait_timeout |
- | |
2317 | - | ||
2318 | mov edx,[hdbase] |
- | |
2319 | add edx,0x7 |
- | |
2320 | - | ||
2321 | wfhil1: |
- | |
2322 | - | ||
2323 | call check_hd_wait_timeout |
- | |
2324 | cmp [hd_error],0 |
- | |
2325 | jne @f |
- | |
2326 | - | ||
2327 | in al,dx |
- | |
2328 | test al,128 |
- | |
2329 | jnz wfhil1 |
- | |
2330 | - | ||
2331 | @@: |
- | |
2332 | - | ||
2333 | pop edx eax |
- | |
2334 | ret |
- | |
2335 | - | ||
2336 | - | ||
2337 | - | ||
2338 | wait_for_sector_buffer: |
- | |
2339 | - | ||
2340 | push eax edx |
- | |
2341 | - | ||
2342 | mov edx,[hdbase] |
- | |
2343 | add edx,0x7 |
- | |
2344 | - | ||
2345 | call save_hd_wait_timeout |
- | |
2346 | - | ||
2347 | hdwait_sbuf: ; wait for sector buffer to be ready |
- | |
2348 | - | ||
2349 | call check_hd_wait_timeout |
- | |
2350 | cmp [hd_error],0 |
- | |
2351 | jne @f |
- | |
2352 | - | ||
2353 | in al,dx |
- | |
2354 | test al,8 |
- | |
2355 | jz hdwait_sbuf |
- | |
2356 | - | ||
2357 | mov [hd_error],0 |
- | |
2358 | - | ||
2359 | cmp [hd_setup],1 ; do not mark error for setup request |
- | |
2360 | je buf_wait_ok |
- | |
2361 | - | ||
2362 | test al,1 ; previous command ended up with an error |
- | |
2363 | jz buf_wait_ok |
- | |
2364 | @@: |
- | |
2365 | mov [hd_error],1 |
- | |
2366 | - | ||
2367 | buf_wait_ok: |
- | |
2368 | - | ||
2369 | pop edx eax |
- | |
2370 | ret |
- | |
2371 | - | ||
2372 | 1913 | ret |
|
2373 | 1914 | ||
2374 | read_hd_file: |
1915 | read_hd_file: |
2375 | ;----------------------------------------------------------------- |
1916 | ;----------------------------------------------------------------- |
2376 | ; |
1917 | ; |