2011-10-15 01:38:50 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 23:10:22 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2011-10-15 01:38:50 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
2015-06-17 21:25:55 +03:00
|
|
|
; HDD driver
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2013-07-01 20:29:16 +04:00
|
|
|
struct HD_DATA
|
2015-10-21 01:51:18 +03:00
|
|
|
hdbase dw ?
|
|
|
|
hdid dw ?
|
|
|
|
hdpos dw ?
|
|
|
|
hd48 dw ?
|
2013-07-01 20:29:16 +04:00
|
|
|
ends
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2013-07-01 20:29:16 +04:00
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
ide_callbacks:
|
2015-10-21 01:51:18 +03:00
|
|
|
dd ide_callbacks.end - ide_callbacks
|
|
|
|
dd 0 ; no close function
|
|
|
|
dd 0 ; no closemedia function
|
|
|
|
dd ide_querymedia
|
|
|
|
dd ide_read
|
|
|
|
dd ide_write
|
|
|
|
dd 0 ; no flush function
|
|
|
|
dd 0 ; use default cache size
|
2013-07-01 20:29:16 +04:00
|
|
|
.end:
|
|
|
|
|
2015-10-21 01:51:18 +03:00
|
|
|
hd0_data HD_DATA ?, 0, 1, 0
|
|
|
|
hd1_data HD_DATA ?, 16, 2, 0
|
|
|
|
hd2_data HD_DATA ?, 0, 3, 0
|
|
|
|
hd3_data HD_DATA ?, 16, 4, 0
|
|
|
|
hd4_data HD_DATA ?, 0, 5, 0
|
|
|
|
hd5_data HD_DATA ?, 16, 6, 0
|
|
|
|
hd6_data HD_DATA ?, 0, 7, 0
|
|
|
|
hd7_data HD_DATA ?, 16, 8, 0
|
|
|
|
hd8_data HD_DATA ?, 0, 9, 0
|
|
|
|
hd9_data HD_DATA ?, 16, 10, 0
|
|
|
|
hd10_data HD_DATA ?, 0, 11, 0
|
|
|
|
hd11_data HD_DATA ?, 16, 12, 0
|
2013-11-21 20:07:16 +04:00
|
|
|
|
2014-03-28 00:44:32 +04:00
|
|
|
ide_mutex_table:
|
2015-10-21 01:51:18 +03:00
|
|
|
dd ide_channel1_mutex
|
|
|
|
dd ide_channel2_mutex
|
|
|
|
dd ide_channel3_mutex
|
|
|
|
dd ide_channel4_mutex
|
|
|
|
dd ide_channel5_mutex
|
|
|
|
dd ide_channel6_mutex
|
2013-07-01 20:29:16 +04:00
|
|
|
endg
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2013-07-01 20:29:16 +04:00
|
|
|
uglobal
|
|
|
|
ide_mutex MUTEX
|
|
|
|
ide_channel1_mutex MUTEX
|
|
|
|
ide_channel2_mutex MUTEX
|
2014-03-28 00:44:32 +04:00
|
|
|
ide_channel3_mutex MUTEX
|
|
|
|
ide_channel4_mutex MUTEX
|
|
|
|
ide_channel5_mutex MUTEX
|
|
|
|
ide_channel6_mutex MUTEX
|
2015-06-17 21:25:55 +03:00
|
|
|
blockSize:
|
|
|
|
rb 4
|
|
|
|
sector:
|
|
|
|
rb 6
|
|
|
|
allow_dma_access db ?
|
|
|
|
IDE_common_irq_param db ?
|
|
|
|
eventPointer dd ?
|
|
|
|
eventID dd ?
|
2013-07-01 20:29:16 +04:00
|
|
|
endg
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2015-06-17 21:37:58 +03:00
|
|
|
ide_read:
|
|
|
|
mov al, 25h ; READ DMA EXT
|
|
|
|
jmp ide_read_write
|
|
|
|
|
|
|
|
ide_write:
|
|
|
|
mov al, 35h ; WRITE DMA EXT
|
|
|
|
|
|
|
|
proc ide_read_write stdcall uses esi edi ebx, \
|
2013-07-01 20:29:16 +04:00
|
|
|
hd_data, buffer, startsector:qword, numsectors
|
|
|
|
; hd_data = pointer to hd*_data
|
2015-06-17 21:37:58 +03:00
|
|
|
; buffer = pointer to buffer with/for data
|
2013-07-01 20:29:16 +04:00
|
|
|
; startsector = 64-bit start sector
|
|
|
|
; numsectors = pointer to number of sectors on input,
|
2015-06-17 21:37:58 +03:00
|
|
|
; must be filled with number of sectors really read/written
|
2013-07-01 20:29:16 +04:00
|
|
|
locals
|
|
|
|
sectors_todo dd ?
|
|
|
|
channel_lock dd ?
|
|
|
|
endl
|
2015-10-21 01:51:18 +03:00
|
|
|
mov bl, al
|
2015-06-17 21:25:55 +03:00
|
|
|
; get number of requested sectors and say that no sectors were read yet
|
2013-07-01 20:29:16 +04:00
|
|
|
mov ecx, [numsectors]
|
|
|
|
mov eax, [ecx]
|
|
|
|
mov dword [ecx], 0
|
|
|
|
mov [sectors_todo], eax
|
2015-06-17 21:25:55 +03:00
|
|
|
; acquire the global lock
|
2013-07-01 20:29:16 +04:00
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_lock
|
2014-03-28 00:44:32 +04:00
|
|
|
mov ecx, [hd_data]
|
2015-10-21 01:51:18 +03:00
|
|
|
movzx ecx, [ecx+HD_DATA.hdpos]
|
2014-03-28 00:44:32 +04:00
|
|
|
dec ecx
|
|
|
|
shr ecx, 1
|
|
|
|
shl ecx, 2
|
|
|
|
mov ecx, [ecx + ide_mutex_table]
|
2013-07-01 20:29:16 +04:00
|
|
|
mov [channel_lock], ecx
|
|
|
|
call mutex_lock
|
2015-06-17 21:25:55 +03:00
|
|
|
; prepare worker procedures variables
|
2015-10-21 01:51:18 +03:00
|
|
|
mov esi, [buffer]
|
|
|
|
mov edi, esi
|
2013-07-01 20:29:16 +04:00
|
|
|
mov ecx, [hd_data]
|
2015-10-21 01:51:18 +03:00
|
|
|
movzx eax, [ecx+HD_DATA.hdbase]
|
2013-07-01 20:29:16 +04:00
|
|
|
mov [hdbase], eax
|
2015-10-21 01:51:18 +03:00
|
|
|
mov ax, [ecx+HD_DATA.hdid]
|
2013-07-01 20:29:16 +04:00
|
|
|
mov [hdid], eax
|
|
|
|
mov eax, dword [startsector]
|
2015-06-17 21:25:55 +03:00
|
|
|
mov [sector], eax
|
2015-10-21 01:51:18 +03:00
|
|
|
cmp [ecx+HD_DATA.hd48], 0
|
|
|
|
jz .LBA28
|
2015-06-17 21:25:55 +03:00
|
|
|
mov ax, word [startsector+4]
|
|
|
|
mov [sector+4], ax
|
2015-10-21 01:51:18 +03:00
|
|
|
movzx ecx, [ecx+HD_DATA.hdpos]
|
|
|
|
mov [hdpos], ecx
|
2014-03-31 01:09:44 +04:00
|
|
|
dec ecx
|
|
|
|
shr ecx, 2
|
|
|
|
imul ecx, sizeof.IDE_DATA
|
|
|
|
add ecx, IDE_controller_1
|
|
|
|
mov [IDE_controller_pointer], ecx
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
and eax, 11b
|
|
|
|
shr eax, 1
|
|
|
|
add eax, ecx
|
|
|
|
cmp [eax+IDE_DATA.dma_hdd_channel_1], 1
|
2015-06-17 21:25:55 +03:00
|
|
|
jz .next
|
2015-06-17 21:37:58 +03:00
|
|
|
dec ebx ; READ/WRITE SECTOR(S) EXT
|
2015-10-21 01:51:18 +03:00
|
|
|
; LBA48 supports max 10000h sectors per time
|
2015-06-17 21:25:55 +03:00
|
|
|
; loop until all sectors will be processed
|
|
|
|
.next:
|
|
|
|
mov ecx, 8000h
|
|
|
|
cmp ecx, [sectors_todo]
|
|
|
|
jbe @f
|
|
|
|
mov ecx, [sectors_todo]
|
|
|
|
@@:
|
|
|
|
mov [blockSize], ecx
|
|
|
|
push ecx
|
|
|
|
call IDE_transfer
|
|
|
|
pop ecx
|
|
|
|
jc .out
|
2013-07-01 20:29:16 +04:00
|
|
|
mov eax, [numsectors]
|
|
|
|
add [eax], ecx
|
|
|
|
sub [sectors_todo], ecx
|
2015-06-17 21:25:55 +03:00
|
|
|
jz .out
|
|
|
|
add [sector], ecx
|
|
|
|
adc word [sector+4], 0
|
|
|
|
jmp .next
|
2015-10-21 01:51:18 +03:00
|
|
|
.LBA28:
|
|
|
|
add eax, [sectors_todo]
|
|
|
|
add eax, 0xF0000000
|
|
|
|
jc .out
|
|
|
|
sub bl, 5 ; READ/WRITE SECTOR(S)
|
|
|
|
; LBA28 supports max 256 sectors per time
|
|
|
|
; loop until all sectors will be processed
|
|
|
|
.next28:
|
|
|
|
mov ecx, 256
|
|
|
|
cmp ecx, [sectors_todo]
|
|
|
|
jbe @f
|
|
|
|
mov ecx, [sectors_todo]
|
|
|
|
@@:
|
|
|
|
mov [blockSize], ecx
|
|
|
|
push ecx
|
|
|
|
call IDE_transfer.LBA28
|
|
|
|
pop ecx
|
|
|
|
jc .out
|
|
|
|
mov eax, [numsectors]
|
|
|
|
add [eax], ecx
|
|
|
|
sub [sectors_todo], ecx
|
|
|
|
jz .out
|
|
|
|
add [sector], ecx
|
|
|
|
jmp .next28
|
2015-06-17 21:25:55 +03:00
|
|
|
; loop is done, either due to error or because everything is done
|
|
|
|
; release the global lock and return the corresponding status
|
|
|
|
.out:
|
|
|
|
sbb eax, eax
|
|
|
|
push eax
|
2013-07-01 20:29:16 +04:00
|
|
|
mov ecx, [channel_lock]
|
|
|
|
call mutex_unlock
|
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_unlock
|
2015-06-17 21:25:55 +03:00
|
|
|
pop eax
|
2013-07-01 20:29:16 +04:00
|
|
|
ret
|
|
|
|
endp
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
; this is a stub
|
2013-07-01 20:29:16 +04:00
|
|
|
proc ide_querymedia stdcall, hd_data, mediainfo
|
|
|
|
mov eax, [mediainfo]
|
|
|
|
mov [eax+DISKMEDIAINFO.Flags], 0
|
|
|
|
mov [eax+DISKMEDIAINFO.SectorSize], 512
|
|
|
|
or dword [eax+DISKMEDIAINFO.Capacity], 0xFFFFFFFF
|
|
|
|
or dword [eax+DISKMEDIAINFO.Capacity+4], 0xFFFFFFFF
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
; input: esi -> buffer, bl = command, [sector], [blockSize]
|
|
|
|
; output: esi -> next block in buffer
|
|
|
|
; for pio read esi equal edi
|
|
|
|
IDE_transfer:
|
2013-06-25 07:15:38 +04:00
|
|
|
mov edx, [hdbase]
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 6
|
2013-06-25 07:15:38 +04:00
|
|
|
mov al, byte [hdid]
|
2015-06-17 21:25:55 +03:00
|
|
|
add al, 224
|
|
|
|
out dx, al ; select the desired drive
|
|
|
|
call save_hd_wait_timeout
|
|
|
|
inc edx
|
|
|
|
@@:
|
|
|
|
call check_hd_wait_timeout
|
|
|
|
jc .hd_error
|
|
|
|
in al, dx
|
|
|
|
test al, 128 ; ready for command?
|
|
|
|
jnz @b
|
|
|
|
pushfd ; fill the ports
|
2011-10-15 01:38:50 +04:00
|
|
|
cli
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
inc edx
|
2015-06-17 21:25:55 +03:00
|
|
|
mov al, [blockSize+1]
|
|
|
|
out dx, al ; Sector count (15:8)
|
2011-10-15 01:38:50 +04:00
|
|
|
inc edx
|
2015-06-17 21:25:55 +03:00
|
|
|
mov eax, [sector+3]
|
|
|
|
out dx, al ; LBA (31:24)
|
2011-10-15 01:38:50 +04:00
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
2015-06-17 21:25:55 +03:00
|
|
|
out dx, al ; LBA (39:32)
|
2011-10-15 01:38:50 +04:00
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
2015-06-17 21:25:55 +03:00
|
|
|
out dx, al ; LBA (47:40)
|
|
|
|
sub edx, 3
|
|
|
|
mov al, [blockSize]
|
|
|
|
out dx, al ; Sector count (7:0)
|
2011-10-15 01:38:50 +04:00
|
|
|
inc edx
|
2015-06-17 21:25:55 +03:00
|
|
|
mov eax, [sector]
|
|
|
|
out dx, al ; LBA (7:0)
|
2013-06-25 07:15:38 +04:00
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
2015-06-17 21:25:55 +03:00
|
|
|
out dx, al ; LBA (15:8)
|
2013-06-25 07:15:38 +04:00
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
2015-06-17 21:25:55 +03:00
|
|
|
out dx, al ; LBA (23:16)
|
2013-06-25 07:15:38 +04:00
|
|
|
inc edx
|
|
|
|
mov al, byte [hdid]
|
2015-06-17 21:25:55 +03:00
|
|
|
add al, 224
|
|
|
|
out dx, al
|
|
|
|
test bl, 1
|
|
|
|
jz .PIO
|
|
|
|
; DMA
|
|
|
|
mov dword [esp], 0x1000
|
|
|
|
call kernel_alloc
|
|
|
|
mov edi, eax
|
|
|
|
push eax
|
|
|
|
shl dword [blockSize], 9
|
|
|
|
mov eax, esi
|
|
|
|
add eax, [blockSize]
|
|
|
|
push eax
|
|
|
|
; check buffer pages physical addresses and fill the scatter-gather list
|
|
|
|
; buffer may be not aligned and may have size not divisible by page size
|
|
|
|
; [edi] = block physical address, [edi+4] = block size in bytes
|
|
|
|
; block addresses can not cross 10000h borders
|
|
|
|
mov ecx, esi
|
|
|
|
and ecx, 0xFFF
|
|
|
|
jz .aligned
|
|
|
|
mov eax, esi
|
|
|
|
call get_pg_addr
|
|
|
|
add eax, ecx
|
|
|
|
neg ecx
|
|
|
|
add ecx, 0x1000
|
|
|
|
mov [edi], eax
|
|
|
|
cmp ecx, [blockSize]
|
|
|
|
jnc .end
|
|
|
|
mov [edi+4], ecx
|
|
|
|
add esi, 0x1000
|
|
|
|
add edi, 8
|
|
|
|
sub [blockSize], ecx
|
|
|
|
.aligned:
|
|
|
|
mov eax, esi
|
|
|
|
call get_pg_addr
|
|
|
|
mov ecx, eax
|
|
|
|
mov [edi], eax
|
|
|
|
and ecx, 0xFFFF
|
|
|
|
neg ecx
|
|
|
|
add ecx, 0x10000
|
|
|
|
cmp [blockSize], ecx
|
|
|
|
jnc @f
|
|
|
|
mov ecx, [blockSize]
|
|
|
|
and ecx, 0xF000
|
|
|
|
jz .end
|
|
|
|
@@:
|
|
|
|
push ecx
|
|
|
|
@@:
|
|
|
|
add esi, 0x1000
|
|
|
|
add eax, 0x1000
|
|
|
|
sub ecx, 0x1000
|
|
|
|
jz @f
|
|
|
|
mov edx, eax
|
|
|
|
mov eax, esi
|
|
|
|
call get_pg_addr
|
|
|
|
cmp eax, edx
|
|
|
|
jz @b
|
|
|
|
@@:
|
|
|
|
pop edx
|
|
|
|
sub edx, ecx
|
|
|
|
mov [edi+4], edx
|
|
|
|
add edi, 8
|
|
|
|
sub [blockSize], edx
|
|
|
|
jnz .aligned
|
|
|
|
sub edi, 8
|
|
|
|
jmp @f
|
|
|
|
.end:
|
|
|
|
mov ecx, [blockSize]
|
|
|
|
mov [edi+4], ecx
|
|
|
|
@@:
|
|
|
|
mov byte [edi+7], 80h ; list end
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
; select controller Primary or Secondary
|
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
|
|
|
jz @f
|
|
|
|
add edx, 8
|
|
|
|
@@:
|
|
|
|
add edx, 2 ; Bus Master IDE Status register
|
|
|
|
mov al, 6
|
|
|
|
out dx, al ; clear Error bit and Interrupt bit
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 2 ; Bus Master IDE PRD Table Address
|
|
|
|
mov eax, edi
|
|
|
|
call get_pg_addr
|
|
|
|
out dx, eax ; send scatter-gather list physical address
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2015-06-17 21:25:55 +03:00
|
|
|
push edx
|
2011-10-15 01:38:50 +04:00
|
|
|
mov edx, [hdbase]
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 7 ; ATACommand
|
|
|
|
mov al, bl
|
|
|
|
out dx, al ; Start hard drive
|
|
|
|
pop edx
|
2011-10-15 01:38:50 +04:00
|
|
|
|
2015-06-17 21:25:55 +03:00
|
|
|
sub edx, 4 ; Bus Master IDE Command register
|
|
|
|
mov al, 1 ; set direction
|
|
|
|
cmp bl, 35h ; write
|
|
|
|
jz @f
|
|
|
|
add al, 8 ; read
|
|
|
|
@@:
|
|
|
|
out dx, al ; Start Bus Master
|
|
|
|
mov [IDE_common_irq_param], 14
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
|
|
|
jz @f
|
|
|
|
inc [IDE_common_irq_param]
|
|
|
|
@@:
|
|
|
|
push edi esi ebx
|
|
|
|
xor ecx, ecx
|
|
|
|
xor esi, esi
|
|
|
|
call create_event
|
|
|
|
mov [eventPointer], eax
|
|
|
|
mov [eventID], edx
|
|
|
|
sti
|
|
|
|
mov ebx, edx
|
|
|
|
mov ecx, 300
|
|
|
|
call wait_event_timeout
|
|
|
|
test eax, eax
|
|
|
|
jnz @f
|
|
|
|
mov [IDE_common_irq_param], 0
|
|
|
|
mov eax, [eventPointer]
|
|
|
|
mov ebx, [eventID]
|
|
|
|
call destroy_event
|
|
|
|
mov [eventPointer], 0
|
|
|
|
@@:
|
|
|
|
pop ebx esi
|
|
|
|
call kernel_free
|
|
|
|
cmp [eventPointer], 0
|
|
|
|
jz .hd_error
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-10-21 01:51:18 +03:00
|
|
|
|
|
|
|
.LBA28:
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 224
|
|
|
|
out dx, al ; select the desired drive
|
|
|
|
call save_hd_wait_timeout
|
|
|
|
inc edx
|
|
|
|
@@:
|
|
|
|
call check_hd_wait_timeout
|
|
|
|
jc .hd_error
|
|
|
|
in al, dx
|
|
|
|
test al, 128 ; ready for command?
|
|
|
|
jnz @b
|
|
|
|
pushfd ; fill the ports
|
|
|
|
cli
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
inc edx
|
|
|
|
mov al, [blockSize]
|
|
|
|
out dx, al ; Sector count (7:0)
|
|
|
|
inc edx
|
|
|
|
mov eax, [sector]
|
|
|
|
out dx, al ; LBA (7:0)
|
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
|
|
|
out dx, al ; LBA (15:8)
|
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
|
|
|
out dx, al ; LBA (23:16)
|
|
|
|
inc edx
|
|
|
|
shr eax, 8
|
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 224
|
|
|
|
out dx, al ; LBA (27:24)
|
2015-06-17 21:25:55 +03:00
|
|
|
.PIO:
|
|
|
|
inc edx ; ATACommand
|
|
|
|
mov al, bl
|
|
|
|
out dx, al ; Start hard drive
|
2013-09-02 01:29:56 +04:00
|
|
|
popfd
|
2015-06-17 21:25:55 +03:00
|
|
|
.sectorTransfer:
|
|
|
|
call save_hd_wait_timeout
|
|
|
|
in al, dx
|
|
|
|
in al, dx
|
|
|
|
in al, dx
|
|
|
|
in al, dx
|
|
|
|
@@:
|
|
|
|
call check_hd_wait_timeout
|
|
|
|
jc .hd_error
|
|
|
|
in al, dx
|
|
|
|
test al, 8 ; ready for transfer?
|
|
|
|
jz @b
|
|
|
|
cmp [hd_setup], 1 ; do not mark error for setup request
|
|
|
|
jz @f
|
|
|
|
test al, 1 ; previous command ended up with an error
|
|
|
|
jnz .hd_error
|
|
|
|
@@:
|
2013-06-27 10:11:10 +04:00
|
|
|
pushfd
|
2011-10-15 01:38:50 +04:00
|
|
|
cli
|
2015-06-17 21:25:55 +03:00
|
|
|
cld
|
2011-10-15 01:38:50 +04:00
|
|
|
mov ecx, 256
|
|
|
|
mov edx, [hdbase]
|
2015-10-21 01:51:18 +03:00
|
|
|
cmp bl, 30h
|
|
|
|
jnc .write
|
2015-06-17 21:25:55 +03:00
|
|
|
rep insw
|
|
|
|
jmp @f
|
|
|
|
.write:
|
2011-10-15 01:38:50 +04:00
|
|
|
rep outsw
|
2015-06-17 21:25:55 +03:00
|
|
|
@@:
|
2013-06-27 10:11:10 +04:00
|
|
|
popfd
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 7
|
|
|
|
dec dword [blockSize]
|
|
|
|
jnz .sectorTransfer
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-06-17 21:25:55 +03:00
|
|
|
.hd_error:
|
|
|
|
cmp bl, 30h
|
|
|
|
jnc hd_write_error
|
|
|
|
;-----------------------------------------------------------------
|
2011-10-15 01:38:50 +04:00
|
|
|
hd_read_error:
|
2013-06-27 10:11:10 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD error de lectura\n"
|
|
|
|
else
|
|
|
|
DEBUGF 1,"K : FS - HD read error\n"
|
|
|
|
end if
|
2015-06-17 21:25:55 +03:00
|
|
|
stc
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2013-06-27 10:11:10 +04:00
|
|
|
hd_write_error:
|
2013-03-03 00:57:38 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD error de escritura\n"
|
|
|
|
else
|
|
|
|
DEBUGF 1,"K : FS - HD write error\n"
|
|
|
|
end if
|
2015-06-17 21:25:55 +03:00
|
|
|
stc
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
save_hd_wait_timeout:
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
add eax, 300 ; 3 sec timeout
|
|
|
|
mov [hd_wait_timeout], eax
|
|
|
|
ret
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
check_hd_wait_timeout:
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
cmp [hd_wait_timeout], eax
|
|
|
|
jc @f
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2013-06-27 10:11:10 +04:00
|
|
|
@@:
|
2015-06-17 21:25:55 +03:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD tiempo de espera agotado\n"
|
|
|
|
else
|
|
|
|
DEBUGF 1,"K : FS - HD timeout\n"
|
|
|
|
end if
|
|
|
|
stc
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2013-06-27 10:11:10 +04:00
|
|
|
align 4
|
2015-06-17 21:25:55 +03:00
|
|
|
IDE_irq_14_handler:
|
|
|
|
IDE_irq_15_handler:
|
|
|
|
IDE_common_irq_handler:
|
|
|
|
; DEBUGF 1, 'K : IDE_irq_handler %x\n', [IDE_common_irq_param]:2
|
2013-08-24 03:22:21 +04:00
|
|
|
cmp [IDE_common_irq_param], 0
|
2015-06-17 21:25:55 +03:00
|
|
|
jz .exit
|
2011-10-15 01:38:50 +04:00
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
2014-03-28 00:44:32 +04:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
2015-06-17 21:25:55 +03:00
|
|
|
cmp [IDE_common_irq_param], 14
|
2013-11-26 00:00:10 +04:00
|
|
|
jz @f
|
2011-10-15 01:38:50 +04:00
|
|
|
add dx, 8
|
2013-11-26 00:00:10 +04:00
|
|
|
@@:
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 2 ; Bus Master IDE Status register
|
2013-11-26 00:00:10 +04:00
|
|
|
in al, dx
|
2015-06-17 21:25:55 +03:00
|
|
|
test al, 4
|
2013-11-26 00:00:10 +04:00
|
|
|
jz @f
|
2015-06-17 21:25:55 +03:00
|
|
|
mov [IDE_common_irq_param], 0
|
|
|
|
out dx, al ; clear Interrupt bit
|
2013-11-26 00:00:10 +04:00
|
|
|
sub edx, 2
|
|
|
|
xor eax, eax
|
2015-06-17 21:25:55 +03:00
|
|
|
out dx, al ; clear Bus Master IDE Command register
|
2013-11-26 00:00:10 +04:00
|
|
|
mov edx, [hdbase]
|
2015-06-17 21:25:55 +03:00
|
|
|
add edx, 7
|
|
|
|
in al, dx ; read status register
|
|
|
|
mov eax, [eventPointer]
|
|
|
|
mov ebx, [eventID]
|
|
|
|
xor edx, edx
|
|
|
|
xor esi, esi
|
|
|
|
call raise_event
|
2013-11-26 00:00:10 +04:00
|
|
|
popad
|
|
|
|
popfd
|
2015-06-17 21:25:55 +03:00
|
|
|
mov al, 1 ; remove the interrupt request
|
2013-11-26 00:00:10 +04:00
|
|
|
ret
|
|
|
|
@@:
|
2011-10-15 01:38:50 +04:00
|
|
|
popad
|
2013-06-27 10:11:10 +04:00
|
|
|
popfd
|
2015-06-17 21:25:55 +03:00
|
|
|
.exit:
|
|
|
|
xor eax, eax ; not our interrupt
|
2011-10-15 01:38:50 +04:00
|
|
|
ret
|
2015-06-17 21:25:55 +03:00
|
|
|
;-----------------------------------------------------------------
|
2014-02-20 17:01:13 +04:00
|
|
|
proc clear_pci_ide_interrupts
|
|
|
|
mov esi, pcidev_list
|
2014-03-28 00:44:32 +04:00
|
|
|
align 4
|
2014-02-20 17:01:13 +04:00
|
|
|
.loop:
|
|
|
|
mov esi, [esi+PCIDEV.fd]
|
|
|
|
cmp esi, pcidev_list
|
|
|
|
jz .done
|
2014-03-28 00:44:32 +04:00
|
|
|
|
2014-03-31 01:09:44 +04:00
|
|
|
; cmp [esi+PCIDEV.class], 0x01018F
|
|
|
|
mov eax, [esi+PCIDEV.class]
|
|
|
|
shr eax, 4
|
|
|
|
cmp eax, 0x01018
|
2014-02-20 17:01:13 +04:00
|
|
|
jnz .loop
|
2014-03-28 00:44:32 +04:00
|
|
|
|
2014-02-20 17:01:13 +04:00
|
|
|
mov ah, [esi+PCIDEV.bus]
|
|
|
|
mov al, 2
|
|
|
|
mov bh, [esi+PCIDEV.devfn]
|
|
|
|
mov bl, 0x20
|
|
|
|
call pci_read_reg
|
2014-03-28 00:44:32 +04:00
|
|
|
|
2014-02-20 17:01:13 +04:00
|
|
|
and eax, 0FFFCh
|
|
|
|
mov edx, eax
|
|
|
|
add edx, 2
|
|
|
|
in al, dx
|
|
|
|
DEBUGF 1,'K : clear_pci_ide_interrupts: port[%x] = %x ',dx,al
|
|
|
|
out dx, al
|
|
|
|
in al, dx
|
|
|
|
DEBUGF 1,'-> %x; ',al
|
|
|
|
add edx, 8
|
|
|
|
in al, dx
|
|
|
|
DEBUGF 1,'port[%x] = %x ',dx,al
|
|
|
|
out dx, al
|
|
|
|
in al, dx
|
|
|
|
DEBUGF 1,'-> %x\n',al
|
|
|
|
jmp .loop
|
|
|
|
.done:
|
|
|
|
ret
|
|
|
|
endp
|