2011-10-14 23:38:50 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
; Low-level driver for HDD access
|
|
|
|
; DMA support by Mario79
|
2013-06-27 08:11:10 +02:00
|
|
|
; LBA48 support by Mario79
|
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
struct HD_DATA
|
|
|
|
hdbase dd ?
|
|
|
|
hdid dd ?
|
|
|
|
hdpos dd ?
|
|
|
|
ends
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
ide_callbacks:
|
|
|
|
dd ide_callbacks.end - ide_callbacks ; strucsize
|
|
|
|
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
|
|
|
|
.end:
|
|
|
|
|
|
|
|
hd0_data HD_DATA ?, 0, 1
|
|
|
|
hd1_data HD_DATA ?, 0x10, 2
|
|
|
|
hd2_data HD_DATA ?, 0, 3
|
|
|
|
hd3_data HD_DATA ?, 0x10, 4
|
2014-03-27 21:44:32 +01:00
|
|
|
hd4_data HD_DATA ?, 0, 5
|
|
|
|
hd5_data HD_DATA ?, 0x10, 6
|
|
|
|
hd6_data HD_DATA ?, 0, 7
|
|
|
|
hd7_data HD_DATA ?, 0x10, 8
|
|
|
|
hd8_data HD_DATA ?, 0, 9
|
|
|
|
hd9_data HD_DATA ?, 0x10, 10
|
|
|
|
hd10_data HD_DATA ?, 0, 11
|
|
|
|
hd11_data HD_DATA ?, 0x10, 12
|
2013-11-21 17:07:16 +01:00
|
|
|
|
2014-03-27 21:44:32 +01:00
|
|
|
ide_mutex_table:
|
|
|
|
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 18:29:16 +02:00
|
|
|
endg
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
uglobal
|
|
|
|
ide_mutex MUTEX
|
|
|
|
ide_channel1_mutex MUTEX
|
|
|
|
ide_channel2_mutex MUTEX
|
2014-03-27 21:44:32 +01:00
|
|
|
ide_channel3_mutex MUTEX
|
|
|
|
ide_channel4_mutex MUTEX
|
|
|
|
ide_channel5_mutex MUTEX
|
|
|
|
ide_channel6_mutex MUTEX
|
2013-07-01 18:29:16 +02:00
|
|
|
endg
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
proc ide_read stdcall uses edi, \
|
|
|
|
hd_data, buffer, startsector:qword, numsectors
|
|
|
|
; hd_data = pointer to hd*_data
|
|
|
|
; buffer = pointer to buffer for data
|
|
|
|
; startsector = 64-bit start sector
|
|
|
|
; numsectors = pointer to number of sectors on input,
|
|
|
|
; must be filled with number of sectors really read
|
|
|
|
locals
|
|
|
|
sectors_todo dd ?
|
|
|
|
channel_lock dd ?
|
|
|
|
endl
|
|
|
|
; 1. Initialize number of sectors: get number of requested sectors
|
|
|
|
; and say that no sectors were read yet.
|
|
|
|
mov ecx, [numsectors]
|
|
|
|
mov eax, [ecx]
|
|
|
|
mov dword [ecx], 0
|
|
|
|
mov [sectors_todo], eax
|
|
|
|
; 2. Acquire the global lock.
|
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_lock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
mov ecx, [hd_data]
|
|
|
|
mov ecx, [ecx+HD_DATA.hdpos]
|
|
|
|
dec ecx
|
|
|
|
shr ecx, 1
|
|
|
|
shl ecx, 2
|
|
|
|
mov ecx, [ecx + ide_mutex_table]
|
2013-07-01 18:29:16 +02:00
|
|
|
mov [channel_lock], ecx
|
|
|
|
call mutex_lock
|
|
|
|
; 3. Convert parameters to the form suitable for worker procedures.
|
|
|
|
; Underlying procedures do not know about 64-bit sectors.
|
|
|
|
; Worker procedures use global variables and edi for [buffer].
|
|
|
|
cmp dword [startsector+4], 0
|
|
|
|
jnz .fail
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
and [hd_error], 0
|
|
|
|
mov ecx, [hd_data]
|
|
|
|
mov eax, [ecx+HD_DATA.hdbase]
|
|
|
|
mov [hdbase], eax
|
|
|
|
mov eax, [ecx+HD_DATA.hdid]
|
|
|
|
mov [hdid], eax
|
|
|
|
mov eax, [ecx+HD_DATA.hdpos]
|
|
|
|
mov [hdpos], eax
|
|
|
|
mov eax, dword [startsector]
|
|
|
|
mov edi, [buffer]
|
|
|
|
; 4. Worker procedures take one sectors per time, so loop over all sectors to read.
|
|
|
|
.sectors_loop:
|
2011-10-14 23:38:50 +02:00
|
|
|
; DMA read is permitted if [allow_dma_access]=1 or 2
|
|
|
|
cmp [allow_dma_access], 2
|
|
|
|
ja .nodma
|
2013-11-25 21:00:10 +01:00
|
|
|
|
2014-03-30 23:09:44 +02:00
|
|
|
push eax ecx
|
|
|
|
mov ecx, [hdpos]
|
|
|
|
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
|
|
|
|
pop ecx eax
|
2013-11-25 21:00:10 +01:00
|
|
|
jnz .nodma
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call hd_read_dma
|
|
|
|
jmp @f
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.nodma:
|
|
|
|
call hd_read_pio
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz .fail
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, [numsectors]
|
|
|
|
inc dword [ecx] ; one more sector is read
|
|
|
|
dec [sectors_todo]
|
|
|
|
jz .done
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
inc eax
|
|
|
|
jnz .sectors_loop
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
; 5. Loop is done, either due to error or because everything is done.
|
|
|
|
; Release the global lock and return the corresponding status.
|
|
|
|
.fail:
|
|
|
|
mov ecx, [channel_lock]
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
.done:
|
|
|
|
mov ecx, [channel_lock]
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
proc ide_write stdcall uses esi edi, \
|
|
|
|
hd_data, buffer, startsector:qword, numsectors
|
|
|
|
; hd_data = pointer to hd*_data
|
|
|
|
; buffer = pointer to buffer with data
|
|
|
|
; startsector = 64-bit start sector
|
|
|
|
; numsectors = pointer to number of sectors on input,
|
|
|
|
; must be filled with number of sectors really written
|
|
|
|
locals
|
|
|
|
sectors_todo dd ?
|
|
|
|
channel_lock dd ?
|
|
|
|
endl
|
|
|
|
; 1. Initialize number of sectors: get number of requested sectors
|
|
|
|
; and say that no sectors were read yet.
|
|
|
|
mov ecx, [numsectors]
|
|
|
|
mov eax, [ecx]
|
|
|
|
mov dword [ecx], 0
|
|
|
|
mov [sectors_todo], eax
|
|
|
|
; 2. Acquire the global lock.
|
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_lock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
mov ecx, [hd_data]
|
|
|
|
mov ecx, [ecx+HD_DATA.hdpos]
|
|
|
|
dec ecx
|
|
|
|
shr ecx, 1
|
|
|
|
shl ecx, 2
|
|
|
|
mov ecx, [ecx + ide_mutex_table]
|
2013-07-01 18:29:16 +02:00
|
|
|
mov [channel_lock], ecx
|
|
|
|
call mutex_lock
|
|
|
|
; 3. Convert parameters to the form suitable for worker procedures.
|
|
|
|
; Underlying procedures do not know about 64-bit sectors.
|
|
|
|
; Worker procedures use global variables and esi for [buffer].
|
|
|
|
cmp dword [startsector+4], 0
|
|
|
|
jnz .fail
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
and [hd_error], 0
|
|
|
|
mov ecx, [hd_data]
|
|
|
|
mov eax, [ecx+HD_DATA.hdbase]
|
|
|
|
mov [hdbase], eax
|
|
|
|
mov eax, [ecx+HD_DATA.hdid]
|
|
|
|
mov [hdid], eax
|
|
|
|
mov eax, [ecx+HD_DATA.hdpos]
|
|
|
|
mov [hdpos], eax
|
|
|
|
mov esi, [buffer]
|
|
|
|
lea edi, [startsector]
|
|
|
|
mov [cache_chain_ptr], edi
|
|
|
|
; 4. Worker procedures take max 16 sectors per time,
|
|
|
|
; loop until all sectors will be processed.
|
|
|
|
.sectors_loop:
|
|
|
|
mov ecx, 16
|
|
|
|
cmp ecx, [sectors_todo]
|
|
|
|
jbe @f
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, [sectors_todo]
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
@@:
|
|
|
|
mov [cache_chain_size], cl
|
|
|
|
; DMA write is permitted only if [allow_dma_access]=1
|
|
|
|
cmp [allow_dma_access], 2
|
|
|
|
jae .nodma
|
2013-11-25 21:00:10 +01:00
|
|
|
|
2014-03-30 23:09:44 +02:00
|
|
|
push eax ecx
|
|
|
|
mov ecx, [hdpos]
|
|
|
|
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
|
|
|
|
pop ecx eax
|
2013-11-25 21:00:10 +01:00
|
|
|
jnz .nodma
|
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
call cache_write_dma
|
|
|
|
jmp .common
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
.nodma:
|
|
|
|
mov [cache_chain_size], 1
|
|
|
|
call cache_write_pio
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
.common:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz .fail
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
movzx ecx, [cache_chain_size]
|
|
|
|
mov eax, [numsectors]
|
|
|
|
add [eax], ecx
|
|
|
|
sub [sectors_todo], ecx
|
|
|
|
jz .done
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
add [edi], ecx
|
|
|
|
jc .fail
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
shl ecx, 9
|
|
|
|
add esi, ecx
|
|
|
|
jmp .sectors_loop
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
; 5. Loop is done, either due to error or because everything is done.
|
|
|
|
; Release the global lock and return the corresponding status.
|
|
|
|
.fail:
|
|
|
|
mov ecx, [channel_lock]
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
.done:
|
|
|
|
mov ecx, [channel_lock]
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
mov ecx, ide_mutex
|
|
|
|
call mutex_unlock
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
; This is a stub.
|
|
|
|
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
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
2013-07-01 18:29:16 +02:00
|
|
|
; input: eax = sector, edi -> buffer
|
|
|
|
; output: edi = edi + 512
|
2011-10-14 23:38:50 +02:00
|
|
|
hd_read_pio:
|
|
|
|
push eax edx
|
2013-06-27 08:11:10 +02:00
|
|
|
; Select the desired drive
|
2013-06-25 05:15:38 +02:00
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ;адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al; номер головки/номер диска
|
2013-06-27 01:35:43 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_hd_idle
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jne hd_read_error
|
2013-06-25 05:15:38 +02:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
|
|
|
mov eax, [esp+4]
|
|
|
|
cmp eax, 0x10000000
|
2013-06-27 01:35:43 +02:00
|
|
|
jae .lba48
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
2013-06-25 05:15:38 +02:00
|
|
|
.lba28:
|
2013-06-26 04:38:47 +02:00
|
|
|
pushfd
|
2011-10-14 23:38:50 +02:00
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
|
|
|
inc eax
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
mov eax, [esp+4+4]
|
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
and al, 1+2+4+8 ; LBA (27:24)
|
2011-10-14 23:38:50 +02:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 01:35:43 +02:00
|
|
|
mov al, 20h ; READ SECTOR(S)
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
popfd
|
2013-06-27 01:35:43 +02:00
|
|
|
jmp .continue
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
2013-06-25 05:15:38 +02:00
|
|
|
.lba48:
|
2013-06-26 04:38:47 +02:00
|
|
|
pushfd
|
2013-06-25 05:15:38 +02:00
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Features Previous Reserved
|
|
|
|
out dx, al ; Features Current Reserved
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Sector Count Previous Sector count (15:8)
|
|
|
|
inc eax
|
|
|
|
out dx, al ; Sector Count Current Sector count (7:0)
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
mov eax, [esp+4+4]
|
2013-06-27 01:35:43 +02:00
|
|
|
rol eax, 8
|
2013-06-25 05:15:38 +02:00
|
|
|
out dx, al ; LBA Low Previous LBA (31:24)
|
2013-06-27 08:11:10 +02:00
|
|
|
xor eax, eax ; because only 32 bit cache
|
2013-06-25 05:15:38 +02:00
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Previous LBA (39:32)
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Previous LBA (47:40)
|
2013-06-27 01:35:43 +02:00
|
|
|
sub edx, 2
|
2013-06-26 04:38:47 +02:00
|
|
|
mov eax, [esp+4+4]
|
2013-06-25 05:15:38 +02:00
|
|
|
out dx, al ; LBA Low Current LBA (7:0)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Current LBA (15:8)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Current LBA (23:16)
|
|
|
|
inc edx
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2013-06-25 05:15:38 +02:00
|
|
|
inc edx
|
2013-06-27 01:35:43 +02:00
|
|
|
mov al, 24h ; READ SECTOR(S) EXT
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; ATACommand регистр команд
|
2013-06-26 04:38:47 +02:00
|
|
|
popfd
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
2013-06-25 05:15:38 +02:00
|
|
|
.continue:
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_sector_buffer
|
|
|
|
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jne hd_read_error
|
|
|
|
|
2013-06-27 08:11:10 +02:00
|
|
|
pushfd
|
2011-10-14 23:38:50 +02:00
|
|
|
cli
|
|
|
|
mov ecx, 256
|
|
|
|
mov edx, [hdbase]
|
|
|
|
cld
|
|
|
|
rep insw
|
2013-06-27 08:11:10 +02:00
|
|
|
popfd
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
2013-07-01 18:29:16 +02:00
|
|
|
; edi -> sector, esi -> data
|
2011-10-14 23:38:50 +02:00
|
|
|
cache_write_pio:
|
2013-06-27 08:11:10 +02:00
|
|
|
; Select the desired drive
|
2013-06-25 05:15:38 +02:00
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ;адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2013-06-25 05:15:38 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_hd_idle
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jne hd_write_error
|
|
|
|
|
2013-06-26 04:38:47 +02:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
2013-07-01 18:29:16 +02:00
|
|
|
mov eax, [edi]
|
2013-06-26 04:38:47 +02:00
|
|
|
cmp eax, 0x10000000
|
|
|
|
jae .lba48
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
2013-06-26 04:38:47 +02:00
|
|
|
.lba28:
|
|
|
|
pushfd
|
2011-10-14 23:38:50 +02:00
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
|
|
|
inc eax
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-07-01 18:29:16 +02:00
|
|
|
mov eax, [edi] ; eax = sector to write
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
and al, 1+2+4+8 ; LBA (27:24)
|
2011-10-14 23:38:50 +02:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-26 04:38:47 +02:00
|
|
|
mov al, 30h ; WRITE SECTOR(S)
|
|
|
|
out dx, al ; ATACommand регистр команд
|
2013-06-27 01:35:43 +02:00
|
|
|
jmp .continue
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
2013-06-26 04:38:47 +02:00
|
|
|
.lba48:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Features Previous Reserved
|
|
|
|
out dx, al ; Features Current Reserved
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Sector Count Previous Sector count (15:8)
|
|
|
|
inc eax
|
|
|
|
out dx, al ; Sector Count Current Sector count (7:0)
|
|
|
|
inc edx
|
2013-07-01 18:29:16 +02:00
|
|
|
mov eax, [edi]
|
2013-06-27 01:35:43 +02:00
|
|
|
rol eax, 8
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA Low Previous LBA (31:24)
|
2013-06-27 08:11:10 +02:00
|
|
|
xor eax, eax ; because only 32 bit cache
|
2013-06-26 04:38:47 +02:00
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Previous LBA (39:32)
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Previous LBA (47:40)
|
2013-06-27 01:35:43 +02:00
|
|
|
sub edx, 2
|
2013-07-01 18:29:16 +02:00
|
|
|
mov eax, [edi]
|
2013-06-26 04:38:47 +02:00
|
|
|
out dx, al ; LBA Low Current LBA (7:0)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Current LBA (15:8)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Current LBA (23:16)
|
|
|
|
inc edx
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2013-06-26 04:38:47 +02:00
|
|
|
inc edx
|
2013-06-27 01:35:43 +02:00
|
|
|
mov al, 34h ; WRITE SECTOR(S) EXT
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
;--------------------------------------
|
2013-06-26 04:38:47 +02:00
|
|
|
.continue:
|
2013-09-01 23:29:56 +02:00
|
|
|
popfd
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_sector_buffer
|
|
|
|
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jne hd_write_error
|
|
|
|
|
|
|
|
push ecx esi
|
|
|
|
|
2013-06-27 08:11:10 +02:00
|
|
|
pushfd
|
2011-10-14 23:38:50 +02:00
|
|
|
cli
|
|
|
|
mov ecx, 256
|
|
|
|
mov edx, [hdbase]
|
|
|
|
cld
|
|
|
|
rep outsw
|
2013-06-27 08:11:10 +02:00
|
|
|
popfd
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
|
|
pop esi ecx
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2011-10-14 23:38:50 +02:00
|
|
|
save_hd_wait_timeout:
|
|
|
|
push eax
|
|
|
|
mov eax, [timer_ticks]
|
|
|
|
add eax, 300 ; 3 sec timeout
|
|
|
|
mov [hd_wait_timeout], eax
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
check_hd_wait_timeout:
|
|
|
|
push eax
|
|
|
|
mov eax, [hd_wait_timeout]
|
|
|
|
cmp [timer_ticks], eax
|
|
|
|
jg hd_timeout_error
|
2013-06-27 08:11:10 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
pop eax
|
|
|
|
mov [hd_error], 0
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
hd_timeout_error:
|
2013-06-27 08:11:10 +02: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
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [hd_error], 1
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
hd_read_error:
|
2013-06-27 08:11:10 +02: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
|
2011-10-14 23:38:50 +02:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
hd_write_error_dma:
|
2013-06-27 08:11:10 +02:00
|
|
|
pop esi
|
|
|
|
hd_write_error:
|
2013-03-02 21:57:38 +01: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
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
wait_for_hd_idle:
|
|
|
|
push eax edx
|
|
|
|
|
|
|
|
call save_hd_wait_timeout
|
|
|
|
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
|
|
|
wfhil1:
|
2011-10-14 23:38:50 +02:00
|
|
|
call check_hd_wait_timeout
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jne @f
|
|
|
|
|
|
|
|
in al, dx
|
|
|
|
test al, 128
|
|
|
|
jnz wfhil1
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-06-27 08:11:10 +02:00
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
wait_for_sector_buffer:
|
|
|
|
push eax edx
|
|
|
|
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
|
|
|
|
|
|
|
call save_hd_wait_timeout
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
|
|
|
hdwait_sbuf: ; wait for sector buffer to be ready
|
2011-10-14 23:38:50 +02:00
|
|
|
call check_hd_wait_timeout
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jne @f
|
|
|
|
|
|
|
|
in al, dx
|
|
|
|
test al, 8
|
|
|
|
jz hdwait_sbuf
|
|
|
|
|
|
|
|
mov [hd_error], 0
|
|
|
|
|
|
|
|
cmp [hd_setup], 1 ; do not mark error for setup request
|
|
|
|
je buf_wait_ok
|
|
|
|
|
|
|
|
test al, 1 ; previous command ended up with an error
|
|
|
|
jz buf_wait_ok
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-06-27 08:11:10 +02:00
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [hd_error], 1
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2013-06-27 08:11:10 +02:00
|
|
|
buf_wait_ok:
|
2011-10-14 23:38:50 +02:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-05 08:43:56 +02:00
|
|
|
irq14_num equ byte 14
|
|
|
|
irq15_num equ byte 15
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
wait_for_sector_dma_ide0:
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
call save_hd_wait_timeout
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2011-10-14 23:38:50 +02:00
|
|
|
.wait:
|
|
|
|
call change_task
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-08-24 01:22:21 +02:00
|
|
|
cmp [IDE_common_irq_param], 0
|
|
|
|
jz .done
|
2013-07-05 08:43:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call check_hd_wait_timeout
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jz .wait
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-05 08:43:56 +02:00
|
|
|
mov [IDE_common_irq_param], 0
|
2013-09-01 23:29:56 +02:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.done:
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
wait_for_sector_dma_ide1:
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
call save_hd_wait_timeout
|
2013-06-27 08:11:10 +02:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2011-10-14 23:38:50 +02:00
|
|
|
.wait:
|
|
|
|
call change_task
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-08-24 01:22:21 +02:00
|
|
|
cmp [IDE_common_irq_param], 0
|
|
|
|
jz .done
|
2013-07-05 08:43:56 +02:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call check_hd_wait_timeout
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jz .wait
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-05 08:43:56 +02:00
|
|
|
mov [IDE_common_irq_param], 0
|
2013-09-01 23:29:56 +02:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.done:
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
iglobal
|
|
|
|
align 4
|
2014-03-27 21:44:32 +01:00
|
|
|
; note that IDE descriptor table must be 4-byte aligned
|
|
|
|
; and do not cross 4K boundary
|
2011-10-14 23:38:50 +02:00
|
|
|
IDE_descriptor_table:
|
2013-06-27 08:11:10 +02:00
|
|
|
dd IDE_DMA
|
|
|
|
dw 0x2000
|
|
|
|
dw 0x8000
|
|
|
|
|
|
|
|
dma_cur_sector dd not 40h
|
|
|
|
dma_hdpos dd 0
|
2013-07-05 08:43:56 +02:00
|
|
|
IDE_common_irq_param db 0
|
2011-10-14 23:38:50 +02:00
|
|
|
endg
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
uglobal
|
|
|
|
; all uglobals are zeroed at boot
|
2013-06-27 08:11:10 +02:00
|
|
|
cache_chain_ptr dd 0
|
|
|
|
cache_chain_size db 0
|
|
|
|
allow_dma_access db 0
|
2011-10-14 23:38:50 +02:00
|
|
|
endg
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
2013-08-24 01:22:21 +02:00
|
|
|
IDE_irq_14_handler:
|
2014-04-15 12:01:23 +02:00
|
|
|
; DEBUGF 1, 'K : IDE_irq_14_handler %x\n', [IDE_common_irq_param]:2
|
2013-08-24 01:22:21 +02:00
|
|
|
cmp [IDE_common_irq_param], irq14_num
|
|
|
|
jne .exit
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
2013-08-24 01:22:21 +02:00
|
|
|
mov [IDE_common_irq_param], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
2013-11-25 21:00:10 +01:00
|
|
|
; test whether it is our interrupt?
|
|
|
|
add edx, 2
|
|
|
|
in al, dx
|
|
|
|
test al, 100b
|
|
|
|
jz @f
|
2013-09-01 23:29:56 +02:00
|
|
|
; clear Bus Master IDE Status register
|
|
|
|
; clear Interrupt bit
|
|
|
|
out dx, al
|
2013-11-25 21:00:10 +01:00
|
|
|
; clear Bus Master IDE Command register
|
|
|
|
sub edx, 2
|
|
|
|
xor eax, eax
|
|
|
|
out dx, al
|
|
|
|
; read status register and remove the interrupt request
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
|
|
|
in al, dx
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
mov al, 1
|
|
|
|
ret
|
|
|
|
;--------------------------------------
|
|
|
|
@@:
|
2013-08-24 01:22:21 +02:00
|
|
|
popad
|
|
|
|
popfd
|
2013-09-01 23:29:56 +02:00
|
|
|
;--------------------------------------
|
2013-08-24 01:22:21 +02:00
|
|
|
.exit:
|
2013-11-25 21:00:10 +01:00
|
|
|
mov al, 0
|
2013-08-24 01:22:21 +02:00
|
|
|
ret
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
2013-08-24 01:22:21 +02:00
|
|
|
IDE_irq_15_handler:
|
2014-04-15 12:01:23 +02:00
|
|
|
; DEBUGF 1, 'K : IDE_irq_15_handler %x\n', [IDE_common_irq_param]:2
|
2013-08-24 01:22:21 +02:00
|
|
|
cmp [IDE_common_irq_param], irq15_num
|
|
|
|
jne .exit
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
mov [IDE_common_irq_param], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
2011-10-14 23:38:50 +02:00
|
|
|
add dx, 8
|
2013-11-25 21:00:10 +01:00
|
|
|
; test whether it is our interrupt?
|
|
|
|
add edx, 2
|
|
|
|
in al, dx
|
|
|
|
test al, 100b
|
|
|
|
jz @f
|
2013-09-01 23:29:56 +02:00
|
|
|
; clear Bus Master IDE Status register
|
|
|
|
; clear Interrupt bit
|
|
|
|
out dx, al
|
2013-11-25 21:00:10 +01:00
|
|
|
; clear Bus Master IDE Command register
|
|
|
|
sub edx, 2
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
; read status register and remove the interrupt request
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
|
|
|
in al, dx
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
mov al, 1
|
|
|
|
ret
|
|
|
|
;--------------------------------------
|
|
|
|
@@:
|
2013-08-24 01:22:21 +02:00
|
|
|
popad
|
|
|
|
popfd
|
2013-09-01 23:29:56 +02:00
|
|
|
;--------------------------------------
|
2013-08-24 01:22:21 +02:00
|
|
|
.exit:
|
2013-11-25 21:00:10 +01:00
|
|
|
mov al, 0
|
2013-08-24 01:22:21 +02:00
|
|
|
ret
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
IDE_common_irq_handler:
|
2014-04-15 12:01:23 +02:00
|
|
|
; DEBUGF 1, 'K : IDE_common_irq_handler %x\n', [IDE_common_irq_param]:2
|
2014-04-15 14:54:18 +02:00
|
|
|
pushfd
|
|
|
|
cli
|
2013-08-24 01:22:21 +02:00
|
|
|
cmp [IDE_common_irq_param], 0
|
|
|
|
je .exit
|
|
|
|
|
|
|
|
pushad
|
|
|
|
xor ebx, ebx
|
2014-03-27 21:44:32 +01:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
2013-08-24 01:22:21 +02:00
|
|
|
mov eax, IDE_common_irq_param
|
|
|
|
cmp [eax], irq14_num
|
|
|
|
mov [eax], bl
|
|
|
|
je @f
|
|
|
|
|
|
|
|
add dx, 8
|
2013-07-05 08:43:56 +02:00
|
|
|
;--------------------------------------
|
2013-08-24 01:22:21 +02:00
|
|
|
@@:
|
2013-11-25 21:00:10 +01:00
|
|
|
; test whether it is our interrupt?
|
|
|
|
add edx, 2
|
|
|
|
in al, dx
|
|
|
|
test al, 100b
|
|
|
|
jz @f
|
2013-09-01 23:29:56 +02:00
|
|
|
; clear Bus Master IDE Status register
|
|
|
|
; clear Interrupt bit
|
|
|
|
out dx, al
|
2013-11-25 21:00:10 +01:00
|
|
|
; clear Bus Master IDE Command register
|
|
|
|
sub edx, 2
|
|
|
|
xor eax, eax
|
|
|
|
out dx, al
|
|
|
|
; read status register and remove the interrupt request
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
|
|
|
in al, dx
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
mov al, 1
|
|
|
|
ret
|
|
|
|
;--------------------------------------
|
|
|
|
@@:
|
2011-10-14 23:38:50 +02:00
|
|
|
popad
|
2013-09-01 23:29:56 +02:00
|
|
|
;--------------------------------------
|
2013-08-24 01:22:21 +02:00
|
|
|
.exit:
|
2014-04-15 14:54:18 +02:00
|
|
|
popfd
|
2013-11-25 21:00:10 +01:00
|
|
|
mov al, 0
|
2011-10-14 23:38:50 +02:00
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
align 4
|
|
|
|
hd_read_dma:
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
mov edx, [dma_hdpos]
|
|
|
|
cmp edx, [hdpos]
|
|
|
|
jne .notread
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov edx, [dma_cur_sector]
|
|
|
|
cmp eax, edx
|
|
|
|
jb .notread
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 15
|
|
|
|
cmp [esp+4], edx
|
|
|
|
ja .notread
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, [esp+4]
|
|
|
|
sub eax, [dma_cur_sector]
|
|
|
|
shl eax, 9
|
|
|
|
add eax, (OS_BASE+IDE_DMA)
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2013-07-01 18:29:16 +02:00
|
|
|
push ecx esi
|
2011-10-14 23:38:50 +02:00
|
|
|
mov esi, eax
|
|
|
|
mov ecx, 512/4
|
|
|
|
cld
|
|
|
|
rep movsd
|
2013-07-01 18:29:16 +02:00
|
|
|
pop esi ecx
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.notread:
|
2013-08-24 01:22:21 +02:00
|
|
|
; set data for PRD Table
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, IDE_descriptor_table
|
|
|
|
mov dword [eax], IDE_DMA
|
|
|
|
mov word [eax+4], 0x2000
|
|
|
|
sub eax, OS_BASE
|
2013-08-24 01:22:21 +02:00
|
|
|
; select controller Primary or Secondary
|
2014-03-30 23:09:44 +02:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
2014-03-27 21:44:32 +01:00
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
|
|
|
|
2013-07-07 04:10:50 +02:00
|
|
|
push eax
|
2014-03-27 21:44:32 +01:00
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2013-07-07 04:10:50 +02:00
|
|
|
pop eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 8
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
push edx
|
2013-08-24 01:22:21 +02:00
|
|
|
; Bus Master IDE PRD Table Address
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 4
|
2013-08-24 01:22:21 +02:00
|
|
|
; save IDE_descriptor_table
|
2011-10-14 23:38:50 +02:00
|
|
|
out dx, eax
|
|
|
|
pop edx
|
2013-08-24 01:22:21 +02:00
|
|
|
; clear Bus Master IDE Command register
|
2011-10-14 23:38:50 +02:00
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
2013-08-24 01:22:21 +02:00
|
|
|
; clear Bus Master IDE Status register
|
|
|
|
; clear Error bit and Interrupt bit
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 2
|
2013-08-24 01:22:21 +02:00
|
|
|
mov al, 6 ; 110b
|
2011-10-14 23:38:50 +02:00
|
|
|
out dx, al
|
2013-06-27 08:11:10 +02:00
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ; адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_hd_idle
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_read_error
|
2013-06-27 08:11:10 +02:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
|
|
|
mov eax, [esp+4]
|
|
|
|
; -10h because the PreCache hits the boundary between lba28 and lba48
|
|
|
|
; 10h = 16 - size of PreCache
|
|
|
|
cmp eax, 0x10000000-10h
|
|
|
|
jae .lba48
|
|
|
|
;--------------------------------------
|
|
|
|
.lba28:
|
|
|
|
pushfd
|
|
|
|
cli
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
mov eax, 10h ; Sector Counter = 16 ; PreCache
|
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
mov eax, [esp+4+4]
|
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
and al, 0xF ; LBA (27:24)
|
2011-10-14 23:38:50 +02:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 11100000b
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
mov al, 0xC8 ; READ DMA
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
jmp .continue
|
|
|
|
;--------------------------------------
|
|
|
|
.lba48:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Features Previous Reserved
|
|
|
|
out dx, al ; Features Current Reserved
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Sector Count Previous Sector count (15:8)
|
|
|
|
mov eax, 10h ; Sector Counter = 16 PreCache
|
|
|
|
out dx, al ; Sector Count Current Sector count (7:0)
|
|
|
|
inc edx
|
|
|
|
mov eax, [esp+4+4]
|
|
|
|
rol eax, 8
|
|
|
|
out dx, al ; LBA Low Previous LBA (31:24)
|
|
|
|
xor eax, eax ; because only 32 bit cache
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Previous LBA (39:32)
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Previous LBA (47:40)
|
|
|
|
sub edx, 2
|
|
|
|
mov eax, [esp+4+4]
|
|
|
|
out dx, al ; LBA Low Current LBA (7:0)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Current LBA (15:8)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Current LBA (23:16)
|
|
|
|
inc edx
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
inc edx
|
|
|
|
mov al, 25h ; READ DMA EXT
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
;--------------------------------------
|
|
|
|
.continue:
|
2013-08-24 01:22:21 +02:00
|
|
|
; select controller Primary or Secondary
|
2014-03-27 21:44:32 +01:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
|
|
|
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
add dx, 8
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
2013-08-24 01:22:21 +02:00
|
|
|
; set write to memory and Start Bus Master
|
2011-10-14 23:38:50 +02:00
|
|
|
mov al, 9
|
|
|
|
out dx, al
|
2013-08-24 01:22:21 +02:00
|
|
|
|
2014-03-27 21:44:32 +01:00
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .ide1
|
2013-07-05 08:43:56 +02:00
|
|
|
|
|
|
|
mov [IDE_common_irq_param], irq14_num
|
2011-10-14 23:38:50 +02:00
|
|
|
jmp @f
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.ide1:
|
2013-07-05 08:43:56 +02:00
|
|
|
mov [IDE_common_irq_param], irq15_num
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
2013-06-27 08:11:10 +02:00
|
|
|
popfd
|
2013-08-24 01:22:21 +02:00
|
|
|
; wait for interrupt
|
2014-03-27 21:44:32 +01:00
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .wait_ide1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_sector_dma_ide0
|
|
|
|
jmp @f
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.wait_ide1:
|
|
|
|
call wait_for_sector_dma_ide1
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_read_error
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, [hdpos]
|
|
|
|
mov [dma_hdpos], eax
|
|
|
|
pop edx
|
|
|
|
pop eax
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [dma_cur_sector], eax
|
|
|
|
jmp hd_read_dma
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2013-07-01 18:29:16 +02:00
|
|
|
cache_write_dma:
|
2013-09-01 23:29:56 +02:00
|
|
|
mov eax, [cache_chain_ptr] ; for what?
|
2011-10-14 23:38:50 +02:00
|
|
|
push esi
|
2013-09-01 23:29:56 +02:00
|
|
|
; set data for PRD Table
|
2011-10-14 23:38:50 +02:00
|
|
|
mov eax, IDE_descriptor_table
|
|
|
|
mov edx, eax
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
pusha
|
|
|
|
mov edi, (OS_BASE+IDE_DMA)
|
|
|
|
mov dword [edx], IDE_DMA
|
|
|
|
movzx ecx, [cache_chain_size]
|
|
|
|
shl ecx, 9
|
|
|
|
mov word [edx+4], cx
|
|
|
|
shr ecx, 2
|
|
|
|
cld
|
|
|
|
rep movsd
|
|
|
|
popa
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
sub eax, OS_BASE
|
2013-09-01 23:29:56 +02:00
|
|
|
; select controller Primary or Secondary
|
2014-03-30 23:09:44 +02:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
2014-03-27 21:44:32 +01:00
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
|
|
|
|
2013-07-07 04:10:50 +02:00
|
|
|
push eax
|
2014-03-27 21:44:32 +01:00
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2013-07-07 04:10:50 +02:00
|
|
|
pop eax
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 8
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
push edx
|
2013-09-01 23:29:56 +02:00
|
|
|
; Bus Master IDE PRD Table Address
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 4
|
2013-09-01 23:29:56 +02:00
|
|
|
; save IDE_descriptor_table
|
2011-10-14 23:38:50 +02:00
|
|
|
out dx, eax
|
|
|
|
pop edx
|
2013-09-01 23:29:56 +02:00
|
|
|
; clear Bus Master IDE Command register
|
2011-10-14 23:38:50 +02:00
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
2013-09-01 23:29:56 +02:00
|
|
|
; clear Bus Master IDE Status register
|
|
|
|
; clear Error bit and Interrupt bit
|
2011-10-14 23:38:50 +02:00
|
|
|
add edx, 2
|
|
|
|
mov al, 6
|
|
|
|
out dx, al
|
2013-06-27 08:11:10 +02:00
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ; адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_hd_idle
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_write_error_dma
|
2013-06-27 08:11:10 +02:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
|
|
|
mov esi, [cache_chain_ptr]
|
|
|
|
mov eax, [esi]
|
|
|
|
; -40h because the PreCache hits the boundary between lba28 and lba48
|
|
|
|
; 40h = 64 - the maximum number of sectors to be written for one command
|
|
|
|
cmp eax, 0x10000000-40h
|
|
|
|
jae .lba48
|
|
|
|
;--------------------------------------
|
|
|
|
.lba28:
|
|
|
|
pushfd
|
|
|
|
cli
|
2011-10-14 23:38:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
mov al, [cache_chain_size] ; Sector Counter
|
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
|
|
|
mov eax, [esi]
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2011-10-14 23:38:50 +02:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
and al, 0xF ; LBA (27:24)
|
2011-10-14 23:38:50 +02:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 11100000b
|
2013-06-27 08:11:10 +02:00
|
|
|
out dx, al ; номер головки/номер диска
|
2011-10-14 23:38:50 +02:00
|
|
|
inc edx
|
2013-06-27 08:11:10 +02:00
|
|
|
mov al, 0xCA ; WRITE DMA
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
jmp .continue
|
|
|
|
;--------------------------------------
|
|
|
|
.lba48:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Features Previous Reserved
|
|
|
|
out dx, al ; Features Current Reserved
|
|
|
|
inc edx
|
|
|
|
out dx, al ; Sector Count Previous Sector count (15:8)
|
|
|
|
mov al, [cache_chain_size] ; Sector Counter
|
|
|
|
out dx, al ; Sector Count Current Sector count (7:0)
|
|
|
|
inc edx
|
|
|
|
mov eax, [esi]
|
|
|
|
rol eax, 8
|
|
|
|
out dx, al ; LBA Low Previous LBA (31:24)
|
|
|
|
xor eax, eax ; because only 32 bit cache
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Previous LBA (39:32)
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Previous LBA (47:40)
|
|
|
|
sub edx, 2
|
|
|
|
mov eax, [esi]
|
|
|
|
out dx, al ; LBA Low Current LBA (7:0)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA Mid Current LBA (15:8)
|
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
|
|
|
out dx, al ; LBA High Current LBA (23:16)
|
|
|
|
inc edx
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
inc edx
|
|
|
|
mov al, 35h ; WRITE DMA EXT
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
;--------------------------------------
|
|
|
|
.continue:
|
2013-09-01 23:29:56 +02:00
|
|
|
; select controller Primary or Secondary
|
2014-03-27 21:44:32 +01:00
|
|
|
mov ecx, [IDE_controller_pointer]
|
|
|
|
mov dx, [ecx+IDE_DATA.RegsBaseAddres]
|
|
|
|
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jz @f
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
add dx, 8
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
2013-09-01 23:29:56 +02:00
|
|
|
; set write to device and Start Bus Master
|
2011-10-14 23:38:50 +02:00
|
|
|
mov al, 1
|
|
|
|
out dx, al
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .ide1
|
2013-07-05 08:43:56 +02:00
|
|
|
|
|
|
|
mov [IDE_common_irq_param], irq14_num
|
2011-10-14 23:38:50 +02:00
|
|
|
jmp @f
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.ide1:
|
2013-07-05 08:43:56 +02:00
|
|
|
mov [IDE_common_irq_param], irq15_num
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
2013-06-27 08:11:10 +02:00
|
|
|
popfd
|
2013-09-01 23:29:56 +02:00
|
|
|
; wait for interrupt
|
2011-10-14 23:38:50 +02:00
|
|
|
mov [dma_cur_sector], not 0x40
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
mov eax, [hdpos]
|
|
|
|
dec eax
|
|
|
|
test eax, 10b
|
2011-10-14 23:38:50 +02:00
|
|
|
jnz .wait_ide1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
call wait_for_sector_dma_ide0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2011-10-14 23:38:50 +02:00
|
|
|
jmp @f
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
.wait_ide1:
|
|
|
|
call wait_for_sector_dma_ide1
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_write_error_dma
|
|
|
|
pop esi
|
|
|
|
ret
|
2013-06-27 08:11:10 +02:00
|
|
|
;-----------------------------------------------------------------------------
|
2014-02-20 14:01:13 +01:00
|
|
|
proc clear_pci_ide_interrupts
|
|
|
|
mov esi, pcidev_list
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2014-02-20 14:01:13 +01:00
|
|
|
.loop:
|
|
|
|
mov esi, [esi+PCIDEV.fd]
|
|
|
|
cmp esi, pcidev_list
|
|
|
|
jz .done
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2014-03-30 23:09:44 +02:00
|
|
|
; cmp [esi+PCIDEV.class], 0x01018F
|
|
|
|
mov eax, [esi+PCIDEV.class]
|
|
|
|
shr eax, 4
|
|
|
|
cmp eax, 0x01018
|
2014-02-20 14:01:13 +01:00
|
|
|
jnz .loop
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2014-02-20 14:01:13 +01:00
|
|
|
mov ah, [esi+PCIDEV.bus]
|
|
|
|
mov al, 2
|
|
|
|
mov bh, [esi+PCIDEV.devfn]
|
|
|
|
mov bl, 0x20
|
|
|
|
call pci_read_reg
|
2014-03-27 21:44:32 +01:00
|
|
|
|
2014-02-20 14:01:13 +01: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
|
2014-03-27 21:44:32 +01:00
|
|
|
;--------------------------------------
|
2014-02-20 14:01:13 +01:00
|
|
|
.done:
|
|
|
|
ret
|
|
|
|
endp
|
2014-03-27 21:44:32 +01:00
|
|
|
;-----------------------------------------------------------------------------
|