2010-10-01 13:21:55 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-03-15 16:41:29 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2010-10-01 13:21:55 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
; Low-level driver for HDD access
|
|
|
|
; DMA support by Mario79
|
|
|
|
; Access through BIOS by diamond
|
2013-06-28 12:02:49 +04:00
|
|
|
; LBA48 support by Mario79
|
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hd_read:
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
; input : eax = block to read
|
|
|
|
; ebx = destination
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
and [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
push ecx esi edi ; scan cache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call calculate_cache
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, 8
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edi, 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
hdreadcache:
|
|
|
|
cmp dword [esi+4], 0 ; empty
|
2013-05-28 23:09:31 +04:00
|
|
|
je nohdcache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [esi], eax ; correct sector
|
2013-05-28 23:09:31 +04:00
|
|
|
je yeshdcache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
nohdcache:
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edi
|
|
|
|
dec ecx
|
|
|
|
jnz hdreadcache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call find_empty_slot ; ret in edi
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne return_01
|
2010-10-01 13:21:55 +04:00
|
|
|
; 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
|
|
|
|
cmp [dma_hdd], 1
|
|
|
|
jnz .nodma
|
|
|
|
call hd_read_dma
|
|
|
|
jmp @f
|
|
|
|
.nodma:
|
|
|
|
call hd_read_pio
|
|
|
|
jmp @f
|
|
|
|
.bios:
|
|
|
|
call bd_read
|
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jne return_01
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call calculate_cache_1
|
2012-03-08 12:33:38 +04:00
|
|
|
lea esi, [edi*8+esi]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [esi], eax ; sector number
|
2013-06-28 12:02:49 +04:00
|
|
|
mov dword [esi+4], 1 ; hd read - mark as same as in hd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
yeshdcache:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, edi
|
|
|
|
shl esi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edi, ebx
|
|
|
|
mov ecx, 512/4
|
2013-05-28 23:09:31 +04:00
|
|
|
cld
|
|
|
|
rep movsd ; move data
|
2013-06-28 12:02:49 +04:00
|
|
|
|
|
|
|
return_01:
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edi esi ecx
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hd_read_pio:
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ;адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al; номер головки/номер диска
|
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call wait_for_hd_idle
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne hd_read_error
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
|
|
|
mov eax, [esp+4]
|
|
|
|
cmp eax, 0x10000000
|
|
|
|
jae .lba48
|
|
|
|
;--------------------------------------
|
|
|
|
.lba28:
|
|
|
|
pushfd
|
2013-05-28 23:09:31 +04:00
|
|
|
cli
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
|
|
|
inc eax
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [esp+4+4]
|
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
and al, 1+2+4+8 ; LBA (27:24)
|
2012-03-08 12:33:38 +04:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; номер головки/номер диска
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov al, 20h ; READ SECTOR(S)
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
popfd
|
|
|
|
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)
|
|
|
|
inc eax
|
|
|
|
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, 24h ; READ SECTOR(S) EXT
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
popfd
|
|
|
|
;--------------------------------------
|
|
|
|
.continue:
|
2013-05-28 23:09:31 +04:00
|
|
|
call wait_for_sector_buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne hd_read_error
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
pushfd
|
2013-05-28 23:09:31 +04:00
|
|
|
cli
|
|
|
|
push edi
|
2012-03-08 12:33:38 +04:00
|
|
|
shl edi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add edi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, 256
|
|
|
|
mov edx, [hdbase]
|
2013-05-28 23:09:31 +04:00
|
|
|
cld
|
|
|
|
rep insw
|
|
|
|
pop edi
|
2013-06-28 12:02:49 +04:00
|
|
|
popfd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hd_write:
|
|
|
|
;-----------------------------------------------------------
|
|
|
|
; input : eax = block
|
|
|
|
; ebx = pointer to memory
|
|
|
|
;-----------------------------------------------------------
|
2013-05-28 23:09:31 +04:00
|
|
|
push ecx esi edi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
; check if the cache already has the sector and overwrite it
|
2013-05-28 23:09:31 +04:00
|
|
|
call calculate_cache
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, 8
|
|
|
|
mov edi, 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
hdwritecache:
|
|
|
|
cmp dword [esi+4], 0 ; if cache slot is empty
|
2013-05-28 23:09:31 +04:00
|
|
|
je not_in_cache_write
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [esi], eax ; if the slot has the sector
|
2013-05-28 23:09:31 +04:00
|
|
|
je yes_in_cache_write
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
not_in_cache_write:
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edi
|
|
|
|
dec ecx
|
|
|
|
jnz hdwritecache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
; sector not found in cache
|
|
|
|
; write the block to a new location
|
2013-05-28 23:09:31 +04:00
|
|
|
call find_empty_slot ; ret in edi
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne hd_write_access_denied
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call calculate_cache_1
|
2012-03-08 12:33:38 +04:00
|
|
|
lea esi, [edi*8+esi]
|
|
|
|
mov [esi], eax ; sector number
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
yes_in_cache_write:
|
|
|
|
mov dword [esi+4], 2 ; write - differs from hd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
shl edi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add edi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, ebx
|
|
|
|
mov ecx, 512/4
|
2013-05-28 23:09:31 +04:00
|
|
|
cld
|
|
|
|
rep movsd ; move data
|
2013-06-28 12:02:49 +04:00
|
|
|
|
|
|
|
hd_write_access_denied:
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edi esi ecx
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
cache_write_pio:
|
2013-06-28 12:02:49 +04:00
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ;адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call wait_for_hd_idle
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne hd_write_error
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
; ATA with 28 or 48 bit for sector number?
|
|
|
|
mov eax, [esi]
|
|
|
|
cmp eax, 0x10000000
|
|
|
|
jae .lba48
|
|
|
|
;--------------------------------------
|
|
|
|
.lba28:
|
|
|
|
pushfd
|
2013-05-28 23:09:31 +04:00
|
|
|
cli
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
|
|
|
inc eax
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [esi] ; eax = sector to write
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2012-03-08 12:33:38 +04:00
|
|
|
shr eax, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
and al, 1+2+4+8 ; LBA (27:24)
|
2012-03-08 12:33:38 +04:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; номер головки/номер диска
|
2013-05-28 23:09:31 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov al, 30h ; WRITE SECTOR(S)
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
popfd
|
|
|
|
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)
|
|
|
|
inc eax
|
|
|
|
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, 34h ; WRITE SECTOR(S) EXT
|
|
|
|
out dx, al ; ATACommand регистр команд
|
|
|
|
popfd
|
|
|
|
;--------------------------------------
|
|
|
|
.continue:
|
2013-05-28 23:09:31 +04:00
|
|
|
call wait_for_sector_buffer
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne hd_write_error
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push ecx esi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
pushfd
|
2013-05-28 23:09:31 +04:00
|
|
|
cli
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, edi
|
|
|
|
shl esi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, 256
|
|
|
|
mov edx, [hdbase]
|
2013-05-28 23:09:31 +04:00
|
|
|
cld
|
|
|
|
rep outsw
|
2013-06-28 12:02:49 +04:00
|
|
|
popfd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
pop esi ecx
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
save_hd_wait_timeout:
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [timer_ticks]
|
|
|
|
add eax, 300 ; 3 sec timeout
|
|
|
|
mov [hd_wait_timeout], eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
check_hd_wait_timeout:
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [hd_wait_timeout]
|
2013-05-28 23:09:31 +04:00
|
|
|
cmp [timer_ticks], eax
|
|
|
|
jg hd_timeout_error
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
hd_timeout_error:
|
2013-05-11 16:38:27 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD tiempo de espera agotado\n"
|
|
|
|
else
|
2010-10-01 13:21:55 +04:00
|
|
|
DEBUGF 1,"K : FS - HD timeout\n"
|
2013-05-11 16:38:27 +04:00
|
|
|
end if
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [hd_error], 1
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
hd_read_error:
|
2013-05-11 16:38:27 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD error de lectura\n"
|
|
|
|
else
|
2010-10-01 13:21:55 +04:00
|
|
|
DEBUGF 1,"K : FS - HD read error\n"
|
2013-05-11 16:38:27 +04:00
|
|
|
end if
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
hd_write_error_dma:
|
|
|
|
pop esi
|
2010-10-01 13:21:55 +04:00
|
|
|
hd_write_error:
|
2013-05-11 16:38:27 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD error de escritura\n"
|
|
|
|
else
|
2010-10-01 13:21:55 +04:00
|
|
|
DEBUGF 1,"K : FS - HD write error\n"
|
2013-05-11 16:38:27 +04:00
|
|
|
end if
|
2013-05-28 23:09:31 +04:00
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
hd_lba_error:
|
2013-05-11 16:38:27 +04:00
|
|
|
if lang eq sp
|
|
|
|
DEBUGF 1,"K : FS - HD error en LBA\n"
|
|
|
|
else
|
2010-10-01 13:21:55 +04:00
|
|
|
DEBUGF 1,"K : FS - HD LBA error\n"
|
2013-05-11 16:38:27 +04:00
|
|
|
end if
|
2013-05-28 23:09:31 +04:00
|
|
|
jmp LBA_read_ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
wait_for_hd_idle:
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call save_hd_wait_timeout
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
2013-06-28 12:02:49 +04:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
|
|
|
wfhil1:
|
2013-05-28 23:09:31 +04:00
|
|
|
call check_hd_wait_timeout
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne @f
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
|
|
|
test al, 128
|
2013-05-28 23:09:31 +04:00
|
|
|
jnz wfhil1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
@@:
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
wait_for_sector_buffer:
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 0x7
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
call save_hd_wait_timeout
|
2013-06-28 12:02:49 +04:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
|
|
|
hdwait_sbuf: ; wait for sector buffer to be ready
|
2013-05-28 23:09:31 +04:00
|
|
|
call check_hd_wait_timeout
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_error], 0
|
2013-05-28 23:09:31 +04:00
|
|
|
jne @f
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
|
|
|
test al, 8
|
2013-05-28 23:09:31 +04:00
|
|
|
jz hdwait_sbuf
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [hd_error], 0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp [hd_setup], 1 ; do not mark error for setup request
|
2013-05-28 23:09:31 +04:00
|
|
|
je buf_wait_ok
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
test al, 1 ; previous command ended up with an error
|
2013-05-28 23:09:31 +04:00
|
|
|
jz buf_wait_ok
|
2013-06-28 12:02:49 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [hd_error], 1
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
buf_wait_ok:
|
2013-05-28 23:09:31 +04:00
|
|
|
pop edx eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
wait_for_sector_dma_ide0:
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
call save_hd_wait_timeout
|
2013-06-28 12:02:49 +04:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
.wait:
|
|
|
|
call change_task
|
|
|
|
cmp [irq14_func], hdd_irq14
|
|
|
|
jnz .done
|
|
|
|
call check_hd_wait_timeout
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jz .wait
|
|
|
|
mov [irq14_func], hdd_irq_null
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
.done:
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
wait_for_sector_dma_ide1:
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
call save_hd_wait_timeout
|
2013-06-28 12:02:49 +04:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
.wait:
|
|
|
|
call change_task
|
|
|
|
cmp [irq15_func], hdd_irq15
|
|
|
|
jnz .done
|
|
|
|
call check_hd_wait_timeout
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jz .wait
|
|
|
|
mov [irq15_func], hdd_irq_null
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
add dx, 8
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
.done:
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
; note that IDE descriptor table must be 4-byte aligned and do not cross 4K boundary
|
|
|
|
IDE_descriptor_table:
|
|
|
|
dd IDE_DMA
|
|
|
|
dw 0x2000
|
|
|
|
dw 0x8000
|
|
|
|
|
|
|
|
dma_cur_sector dd not 40h
|
|
|
|
dma_hdpos dd 0
|
|
|
|
irq14_func dd hdd_irq_null
|
|
|
|
irq15_func dd hdd_irq_null
|
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
uglobal
|
|
|
|
; all uglobals are zeroed at boot
|
|
|
|
dma_process dd 0
|
|
|
|
dma_slot_ptr dd 0
|
|
|
|
cache_chain_pos dd 0
|
|
|
|
cache_chain_ptr dd 0
|
|
|
|
cache_chain_size db 0
|
|
|
|
cache_chain_started db 0
|
|
|
|
dma_task_switched db 0
|
|
|
|
dma_hdd db 0
|
|
|
|
allow_dma_access db 0
|
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hdd_irq14:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
mov [irq14_func], hdd_irq_null
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
align 4
|
|
|
|
hdd_irq_null:
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hdd_irq15:
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
pushad
|
|
|
|
mov [irq15_func], hdd_irq_null
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
add dx, 8
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
popad
|
|
|
|
popfd
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
hd_read_dma:
|
|
|
|
push eax
|
|
|
|
push edx
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, [dma_hdpos]
|
|
|
|
cmp edx, [hdpos]
|
2010-10-01 13:21:55 +04:00
|
|
|
jne .notread
|
|
|
|
mov edx, [dma_cur_sector]
|
|
|
|
cmp eax, edx
|
|
|
|
jb .notread
|
|
|
|
add edx, 15
|
|
|
|
cmp [esp+4], edx
|
|
|
|
ja .notread
|
|
|
|
mov eax, [esp+4]
|
|
|
|
sub eax, [dma_cur_sector]
|
|
|
|
shl eax, 9
|
|
|
|
add eax, (OS_BASE+IDE_DMA)
|
|
|
|
push ecx esi edi
|
|
|
|
mov esi, eax
|
|
|
|
shl edi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add edi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
cld
|
2013-05-28 23:09:31 +04:00
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
pop edi esi ecx
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
ret
|
|
|
|
.notread:
|
|
|
|
mov eax, IDE_descriptor_table
|
2013-05-28 23:09:31 +04:00
|
|
|
mov dword [eax], IDE_DMA
|
2010-10-01 13:21:55 +04:00
|
|
|
mov word [eax+4], 0x2000
|
|
|
|
sub eax, OS_BASE
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
cmp [hdbase], 0x1F0
|
|
|
|
jz @f
|
|
|
|
add edx, 8
|
|
|
|
@@:
|
|
|
|
push edx
|
|
|
|
add edx, 4
|
|
|
|
out dx, eax
|
|
|
|
pop edx
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
add edx, 2
|
|
|
|
mov al, 6
|
|
|
|
out dx, al
|
2013-06-28 12:02:49 +04:00
|
|
|
|
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ; адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
|
2010-10-01 13:21:55 +04:00
|
|
|
call wait_for_hd_idle
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_read_error
|
2013-06-28 12:02:49 +04: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
|
2010-10-01 13:21:55 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, 10h ; Sector Counter = 16 ; PreCache
|
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [esp+4+4]
|
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
and al, 0xF ; LBA (27:24)
|
2010-10-01 13:21:55 +04:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 11100000b
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; номер головки/номер диска
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04: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:
|
2010-10-01 13:21:55 +04:00
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jz @f
|
|
|
|
add dx, 8
|
|
|
|
@@:
|
|
|
|
mov al, 9
|
|
|
|
out dx, al
|
|
|
|
mov eax, [CURRENT_TASK]
|
|
|
|
mov [dma_process], eax
|
|
|
|
mov eax, [TASK_BASE]
|
|
|
|
mov [dma_slot_ptr], eax
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jnz .ide1
|
|
|
|
mov [irq14_func], hdd_irq14
|
|
|
|
jmp @f
|
|
|
|
.ide1:
|
|
|
|
mov [irq15_func], hdd_irq15
|
|
|
|
@@:
|
2013-06-28 12:02:49 +04:00
|
|
|
popfd
|
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jnz .wait_ide1
|
|
|
|
call wait_for_sector_dma_ide0
|
|
|
|
jmp @f
|
|
|
|
.wait_ide1:
|
|
|
|
call wait_for_sector_dma_ide1
|
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_read_error
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [hdpos]
|
|
|
|
mov [dma_hdpos], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
mov [dma_cur_sector], eax
|
|
|
|
jmp hd_read_dma
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
align 4
|
|
|
|
write_cache_sector:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [cache_chain_size], 1
|
|
|
|
mov [cache_chain_pos], edi
|
2013-06-28 12:02:49 +04:00
|
|
|
;--------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
write_cache_chain:
|
|
|
|
cmp [hdpos], 0x80
|
|
|
|
jae bd_write_cache_chain
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, [cache_chain_ptr]
|
2010-10-01 13:21:55 +04:00
|
|
|
push esi
|
|
|
|
mov eax, IDE_descriptor_table
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
pusha
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, [cache_chain_pos]
|
2010-10-01 13:21:55 +04:00
|
|
|
shl esi, 9
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add esi, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
mov edi, (OS_BASE+IDE_DMA)
|
|
|
|
mov dword [edx], IDE_DMA
|
|
|
|
movzx ecx, [cache_chain_size]
|
|
|
|
shl ecx, 9
|
|
|
|
mov word [edx+4], cx
|
2012-03-08 12:33:38 +04:00
|
|
|
shr ecx, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
cld
|
|
|
|
rep movsd
|
|
|
|
popa
|
|
|
|
sub eax, OS_BASE
|
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
|
|
|
cmp [hdbase], 0x1F0
|
|
|
|
jz @f
|
|
|
|
add edx, 8
|
|
|
|
@@:
|
|
|
|
push edx
|
|
|
|
add edx, 4
|
|
|
|
out dx, eax
|
|
|
|
pop edx
|
|
|
|
mov al, 0
|
|
|
|
out dx, al
|
|
|
|
add edx, 2
|
|
|
|
mov al, 6
|
|
|
|
out dx, al
|
2013-06-28 12:02:49 +04:00
|
|
|
|
|
|
|
; Select the desired drive
|
|
|
|
mov edx, [hdbase]
|
|
|
|
add edx, 6 ; адрес регистра головок
|
|
|
|
mov al, byte [hdid]
|
|
|
|
add al, 128+64+32
|
|
|
|
out dx, al ; номер головки/номер диска
|
|
|
|
|
2010-10-01 13:21:55 +04:00
|
|
|
call wait_for_hd_idle
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_write_error_dma
|
2013-06-28 12:02:49 +04: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
|
2010-10-01 13:21:55 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov edx, [hdbase]
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; ATA Features регистр "особенностей"
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
mov al, [cache_chain_size] ; Sector Counter
|
|
|
|
out dx, al ; ATA Sector Counter счётчик секторов
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
|
|
|
mov eax, [esi]
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Low LBA (7:0)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA Mid LBA (15:8)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; LBA High LBA (23:16)
|
2010-10-01 13:21:55 +04:00
|
|
|
shr eax, 8
|
|
|
|
inc edx
|
2013-06-28 12:02:49 +04:00
|
|
|
and al, 0xF ; LBA (27:24)
|
2010-10-01 13:21:55 +04:00
|
|
|
add al, byte [hdid]
|
|
|
|
add al, 11100000b
|
2013-06-28 12:02:49 +04:00
|
|
|
out dx, al ; номер головки/номер диска
|
2010-10-01 13:21:55 +04:00
|
|
|
inc edx
|
2013-06-28 12:02:49 +04: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:
|
2010-10-01 13:21:55 +04:00
|
|
|
mov dx, [IDEContrRegsBaseAddr]
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jz @f
|
|
|
|
add dx, 8
|
|
|
|
@@:
|
|
|
|
mov al, 1
|
|
|
|
out dx, al
|
|
|
|
mov eax, [CURRENT_TASK]
|
|
|
|
mov [dma_process], eax
|
|
|
|
mov eax, [TASK_BASE]
|
|
|
|
mov [dma_slot_ptr], eax
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jnz .ide1
|
|
|
|
mov [irq14_func], hdd_irq14
|
|
|
|
jmp @f
|
|
|
|
.ide1:
|
|
|
|
mov [irq15_func], hdd_irq15
|
|
|
|
@@:
|
2013-06-28 12:02:49 +04:00
|
|
|
popfd
|
2010-10-01 13:21:55 +04:00
|
|
|
mov [dma_cur_sector], not 0x40
|
2013-06-28 12:02:49 +04:00
|
|
|
mov eax, [hd_address_table]
|
|
|
|
cmp [hdbase], eax ; 0x1F0
|
2010-10-01 13:21:55 +04:00
|
|
|
jnz .wait_ide1
|
|
|
|
call wait_for_sector_dma_ide0
|
|
|
|
jmp @f
|
|
|
|
.wait_ide1:
|
|
|
|
call wait_for_sector_dma_ide1
|
|
|
|
@@:
|
|
|
|
cmp [hd_error], 0
|
|
|
|
jnz hd_write_error_dma
|
|
|
|
pop esi
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
uglobal
|
|
|
|
IDEContrRegsBaseAddr dw ?
|
2013-06-28 12:02:49 +04:00
|
|
|
IDEContrProgrammingInterface dw ?
|
|
|
|
IDE_BAR0_val dw ?
|
|
|
|
IDE_BAR1_val dw ?
|
|
|
|
IDE_BAR2_val dw ?
|
|
|
|
IDE_BAR3_val dw ?
|
2010-10-01 13:21:55 +04:00
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
; \begin{diamond}
|
|
|
|
uglobal
|
|
|
|
bios_hdpos dd 0 ; 0 is invalid value for [hdpos]
|
|
|
|
bios_cur_sector dd ?
|
|
|
|
bios_read_len dd ?
|
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
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+0x9A000)
|
|
|
|
push ecx esi edi
|
|
|
|
mov esi, eax
|
|
|
|
shl edi, 9
|
2013-06-28 12:02:49 +04:00
|
|
|
|
2013-05-28 23:09:31 +04:00
|
|
|
push eax
|
|
|
|
call calculate_cache_2
|
2012-03-08 12:33:38 +04:00
|
|
|
add edi, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
mov ecx, 512/4
|
|
|
|
cld
|
2013-05-28 23:09:31 +04:00
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
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
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
bd_write_cache_chain:
|
|
|
|
pusha
|
|
|
|
mov esi, [cache_chain_pos]
|
|
|
|
shl esi, 9
|
|
|
|
call calculate_cache_2
|
|
|
|
add esi, eax
|
|
|
|
mov edi, OS_BASE + 0x9A000
|
|
|
|
movzx ecx, [cache_chain_size]
|
|
|
|
push ecx
|
|
|
|
shl ecx, 9-2
|
2013-05-28 23:09:31 +04:00
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
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
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2010-10-01 13:21:55 +04:00
|
|
|
uglobal
|
2012-03-08 12:33:38 +04:00
|
|
|
int13_regs_in rb sizeof.v86_regs
|
|
|
|
int13_regs_out rb sizeof.v86_regs
|
2010-10-01 13:21:55 +04:00
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
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 [OS_BASE + 510h], 10h ; packet length
|
|
|
|
mov word [OS_BASE + 512h], cx ; number of sectors
|
|
|
|
mov dword [OS_BASE + 514h], 9A000000h ; buffer 9A00:0000
|
|
|
|
mov dword [OS_BASE + 518h], eax
|
|
|
|
and dword [OS_BASE + 51Ch], 0
|
|
|
|
push ebx ecx esi edi
|
|
|
|
mov ebx, int13_regs_in
|
|
|
|
mov edi, ebx
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, sizeof.v86_regs/4
|
2010-10-01 13:21:55 +04:00
|
|
|
xor eax, eax
|
2013-05-28 23:09:31 +04:00
|
|
|
rep stosd
|
2010-10-01 13:21:55 +04:00
|
|
|
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.ss], 9000h
|
|
|
|
mov word [ebx+v86_regs.esp], 0A000h
|
|
|
|
mov word [ebx+v86_regs.eip], 500h
|
|
|
|
mov [ebx+v86_regs.eflags], 20200h
|
|
|
|
mov esi, [sys_v86_machine]
|
|
|
|
mov ecx, 0x502
|
2013-05-28 23:09:31 +04:00
|
|
|
push fs
|
2010-10-01 13:21:55 +04:00
|
|
|
call v86_start
|
2013-05-28 23:09:31 +04:00
|
|
|
pop fs
|
2010-10-01 13:21:55 +04:00
|
|
|
and [bios_hdpos], 0
|
|
|
|
pop edi esi ecx ebx
|
|
|
|
movzx edx, byte [OS_BASE + 512h]
|
|
|
|
test byte [int13_regs_out+v86_regs.eflags], 1
|
|
|
|
jnz @f
|
|
|
|
mov edx, ecx
|
|
|
|
@@:
|
|
|
|
ret
|
|
|
|
; \end{diamond}
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2012-10-12 22:24:48 +04:00
|
|
|
reserve_hd1:
|
|
|
|
cli
|
|
|
|
cmp [hd1_status], 0
|
|
|
|
je reserve_ok1
|
|
|
|
|
|
|
|
sti
|
|
|
|
call change_task
|
|
|
|
jmp reserve_hd1
|
|
|
|
|
2013-06-28 12:02:49 +04:00
|
|
|
reserve_ok1:
|
2012-10-12 22:24:48 +04:00
|
|
|
push eax
|
|
|
|
mov eax, [CURRENT_TASK]
|
|
|
|
shl eax, 5
|
|
|
|
mov eax, [eax+CURRENT_TASK+TASKDATA.pid]
|
|
|
|
mov [hd1_status], eax
|
|
|
|
pop eax
|
|
|
|
sti
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2012-10-12 22:24:48 +04:00
|
|
|
uglobal
|
|
|
|
hd_in_cache db ?
|
|
|
|
endg
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
2012-10-12 22:24:48 +04:00
|
|
|
reserve_hd_channel:
|
|
|
|
; BIOS disk accesses are protected with common mutex hd1_status
|
|
|
|
; This must be modified when hd1_status will not be valid!
|
|
|
|
cmp [hdpos], 0x80
|
|
|
|
jae .ret
|
|
|
|
cmp [hdbase], 0x1F0
|
|
|
|
jne .IDE_Channel_2
|
|
|
|
.IDE_Channel_1:
|
|
|
|
cli
|
|
|
|
cmp [IDE_Channel_1], 0
|
|
|
|
je .reserve_ok_1
|
|
|
|
sti
|
|
|
|
call change_task
|
|
|
|
jmp .IDE_Channel_1
|
|
|
|
.IDE_Channel_2:
|
|
|
|
cli
|
|
|
|
cmp [IDE_Channel_2], 0
|
|
|
|
je .reserve_ok_2
|
|
|
|
sti
|
|
|
|
call change_task
|
|
|
|
jmp .IDE_Channel_2
|
|
|
|
.reserve_ok_1:
|
|
|
|
mov [IDE_Channel_1], 1
|
|
|
|
push eax
|
|
|
|
mov al, 1
|
|
|
|
jmp @f
|
|
|
|
.reserve_ok_2:
|
|
|
|
mov [IDE_Channel_2], 1
|
|
|
|
push eax
|
|
|
|
mov al, 3
|
|
|
|
@@:
|
|
|
|
cmp [hdid], 1
|
|
|
|
sbb al, -1
|
|
|
|
mov [hd_in_cache], al
|
|
|
|
pop eax
|
|
|
|
sti
|
|
|
|
.ret:
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|
2012-10-12 22:24:48 +04:00
|
|
|
free_hd_channel:
|
|
|
|
; see comment at reserve_hd_channel
|
|
|
|
cmp [hdpos], 0x80
|
|
|
|
jae .ret
|
|
|
|
cmp [hdbase], 0x1F0
|
|
|
|
jne .IDE_Channel_2
|
|
|
|
.IDE_Channel_1:
|
|
|
|
mov [IDE_Channel_1], 0
|
|
|
|
.ret:
|
|
|
|
ret
|
|
|
|
.IDE_Channel_2:
|
|
|
|
mov [IDE_Channel_2], 0
|
|
|
|
ret
|
2013-06-28 12:02:49 +04:00
|
|
|
;-----------------------------------------------------------------------------
|