Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 708 → Rev 709

/kernel/trunk/blkdev/hd_drv.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10,6 → 10,7
 
; Low-level driver for HDD access
; DMA support by Mario79
; Access through BIOS by diamond
 
align 4
hd_read:
45,6 → 46,9
call find_empty_slot ; ret in edi
cmp [hd_error],0
jne return_01
; Read through BIOS?
cmp [hdpos], 0x80
jae .bios
; DMA read is permitted if [allow_dma_access]=1 or 2
cmp [allow_dma_access], 2
ja .nodma
54,6 → 58,9
jmp @f
.nodma:
call hd_read_pio
jmp @f
.bios:
call bd_read
@@:
; lea esi,[edi*8+HD_CACHE]
; push eax
675,6 → 682,8
mov [cache_chain_size],1
mov [cache_chain_pos],edi
write_cache_chain:
cmp [hdpos], 0x80
jae bd_write_cache_chain
push esi
mov eax, IDE_descriptor_table
mov edx,eax
773,3 → 782,144
IDEContrRegsBaseAddr dw ?
endg
; \end{Mario79}
 
; \begin{diamond}
uglobal
bios_hdpos dd 0 ; 0 is invalid value for [hdpos]
bios_cur_sector dd ?
bios_read_len dd ?
endg
bd_read:
push eax
push edx
mov edx, [bios_hdpos]
cmp edx, [hdpos]
jne .notread
mov edx, [bios_cur_sector]
cmp eax, edx
jb .notread
add edx, [bios_read_len]
dec edx
cmp eax, edx
ja .notread
sub eax, [bios_cur_sector]
shl eax, 9
add eax, (OS_BASE+0x9C000)
push ecx esi edi
mov esi, eax
shl edi, 9
; add edi, HD_CACHE+0x10000
push eax
call calculate_cache_2
add edi,eax
pop eax
 
mov ecx, 512/4
cld
rep movsd
pop edi esi ecx
pop edx
pop eax
ret
.notread:
push ecx
mov dl, 42h
mov ecx, 16
call int13_call
pop ecx
test eax, eax
jnz .v86err
test edx, edx
jz .readerr
mov [bios_read_len], edx
mov edx, [hdpos]
mov [bios_hdpos], edx
pop edx
pop eax
mov [bios_cur_sector], eax
jmp bd_read
.readerr:
.v86err:
mov [hd_error], 1
jmp hd_read_error
 
bd_write_cache_chain:
pusha
mov esi, [cache_chain_pos]
shl esi, 9
call calculate_cache_2
add esi, eax
mov edi, OS_BASE + 0x9C000
movzx ecx, [cache_chain_size]
push ecx
shl ecx, 9-2
rep movsd
pop ecx
mov dl, 43h
mov eax, [cache_chain_ptr]
mov eax, [eax]
call int13_call
test eax, eax
jnz .v86err
cmp edx, ecx
jnz .writeerr
popa
ret
.v86err:
.writeerr:
popa
mov [hd_error], 1
jmp hd_write_error
 
uglobal
int13_regs_in rb v86_regs.size
int13_regs_out rb v86_regs.size
endg
 
int13_call:
; Because this code uses fixed addresses,
; it can not be run simultaniously by many threads.
; In current implementation it is protected by common mutex 'hd1_status'
mov word [BOOT_VAR + 510h], 10h ; packet length
mov word [BOOT_VAR + 512h], cx ; number of sectors
mov dword [BOOT_VAR + 514h], 9C000000h ; buffer 9C00:0000
mov dword [BOOT_VAR + 518h], eax
and dword [BOOT_VAR + 51Ch], 0
push ebx ecx esi edi
mov ebx, int13_regs_in
mov edi, ebx
mov ecx, v86_regs.size/4
xor eax, eax
rep stosd
mov byte [ebx+v86_regs.eax+1], dl
mov eax, [hdpos]
lea eax, [BiosDisksData+(eax-80h)*4]
mov dl, [eax]
mov byte [ebx+v86_regs.edx], dl
movzx edx, byte [eax+1]
; mov dl, 5
test edx, edx
jnz .hasirq
dec edx
jmp @f
.hasirq:
pushad
stdcall enable_irq, edx
popad
@@:
mov word [ebx+v86_regs.esi], 510h
mov word [ebx+v86_regs.esp], 900h
mov word [ebx+v86_regs.eip], 500h
mov [ebx+v86_regs.eflags], 20200h
mov esi, [sys_v86_machine]
mov ecx, 0x502
call v86_start
and [bios_hdpos], 0
pop edi esi ecx ebx
movzx edx, byte [BOOT_VAR + 512h]
test byte [int13_regs_out+v86_regs.eflags], 1
jnz @f
mov edx, ecx
@@:
ret
; \end{diamond}
/kernel/trunk/blkdev/ide_cache.inc
37,11 → 37,14
jb danger
cmp eax,[PARTITION_END]
ja danger
cmp [hdpos], 0x80
jae @f
; DMA write is permitted only if [allow_dma_access]=1
cmp [allow_dma_access], 2
jae .nodma
cmp [dma_hdd], 1
jnz .nodma
@@:
; Ž¡ê¥¤¨­ï¥¬ § ¯¨áì 楯®çª¨ ¯®á«¥¤®¢ â¥«ì­ëå ᥪâ®à®¢ ¢ ®¤­® ®¡à é¥­¨¥ ª ¤¨áªã
cmp ecx, 1
jz .nonext
60,7 → 63,7
mov [cache_chain_ptr], esi
@@:
inc [cache_chain_size]
cmp [cache_chain_size], 64
cmp [cache_chain_size], 16
jnz .continue
jmp .write_chain
.nonext:
174,6 → 177,8
mov esi,[cache_ide2_data_pointer]
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
mov ecx,[cache_ide3_system_sad_size]
183,6 → 188,31
mov ecx,[cache_ide3_appl_sad_size]
mov esi,[cache_ide3_data_pointer]
ret
.noide:
push eax
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
mov ecx,[cache_ide0_system_sad_size-cache_ide0+eax]
mov esi,[cache_ide0_pointer-cache_ide0+eax]
pop eax
ret
.bd_appl_data:
mov ecx,[cache_ide0_appl_sad_size-cache_ide0+eax]
mov esi,[cache_ide0_data_pointer-cache_ide0+eax]
pop eax
ret
;--------------------------------------------------------------------
align 4
calculate_cache_1:
219,6 → 249,8
mov esi,[cache_ide2_data_pointer]
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
mov esi,[cache_ide3_pointer]
226,6 → 258,30
.ide3_appl_data:
mov esi,[cache_ide3_data_pointer]
ret
.noide:
push eax
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
mov esi,[cache_ide0_pointer-cache_ide0+eax]
pop eax
ret
.bd_appl_data:
mov esi,[cache_ide0_data_pointer-cache_ide0+eax]
pop eax
ret
 
;--------------------------------------------------------------------
align 4
calculate_cache_2:
262,6 → 318,8
mov eax,[cache_ide2_appl_data]
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
mov eax,[cache_ide3_system_data]
269,6 → 327,26
.ide3_appl_data:
mov eax,[cache_ide3_appl_data]
ret
.noide:
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
mov eax,[cache_ide0_system_data-cache_ide0+eax]
ret
.bd_appl_data:
mov eax,[cache_ide0_appl_data-cache_ide0+eax]
ret
;--------------------------------------------------------------------
align 4
calculate_cache_3:
313,6 → 391,8
mov edi,[cache_ide2_appl_search_start]
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
mov ecx,[cache_ide3_system_sad_size]
322,6 → 402,31
mov ecx,[cache_ide3_appl_sad_size]
mov edi,[cache_ide3_appl_search_start]
ret
.noide:
push eax
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
mov ecx,[cache_ide0_system_sad_size-cache_ide0+eax]
mov edi,[cache_ide0_search_start-cache_ide0+eax]
pop eax
ret
.bd_appl_data:
mov ecx,[cache_ide0_appl_sad_size-cache_ide0+eax]
mov edi,[cache_ide0_appl_search_start-cache_ide0+eax]
pop eax
ret
;--------------------------------------------------------------------
align 4
calculate_cache_4:
358,6 → 463,8
cmp edi,[cache_ide2_appl_sad_size]
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
cmp edi,[cache_ide3_system_sad_size]
365,6 → 472,30
.ide3_appl_data:
cmp edi,[cache_ide3_appl_sad_size]
ret
.noide:
push eax
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
cmp edi,[cache_ide0_system_sad_size-cache_ide0+eax]
pop eax
ret
.bd_appl_data:
cmp edi,[cache_ide0_appl_sad_size-cache_ide0+eax]
pop eax
ret
 
;--------------------------------------------------------------------
align 4
calculate_cache_5:
401,6 → 532,8
mov [cache_ide2_appl_search_start],edi
ret
.ide3:
cmp [hdpos],4
jne .noide
cmp [hdd_appl_data],0
jne .ide3_appl_data
mov [cache_ide3_search_start],edi
408,6 → 541,29
.ide3_appl_data:
mov [cache_ide3_appl_search_start],edi
ret
.noide:
push eax
mov eax,[hdpos]
sub eax,80h
cmp byte [BiosDisksData+eax*4+2], -1
jz @f
movzx eax,byte [BiosDisksData+eax*4+2]
imul eax,cache_ide1-cache_ide0
add eax,cache_ide0
jmp .get
@@:
imul eax,cache_ide1-cache_ide0
add eax,BiosDiskCaches
.get:
cmp [hdd_appl_data],0
jne .bd_appl_data
mov [cache_ide0_search_start-cache_ide0+eax],edi
pop eax
ret
.bd_appl_data:
mov [cache_ide0_appl_search_start-cache_ide0+eax],edi
pop eax
ret
 
;--------------------------------------------------------------------
align 4