2011-10-14 23:38:50 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2024-05-22 17:15:14 +02:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
|
2015-10-21 00:51:18 +02:00
|
|
|
|
; HDD and CD search
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
2014-03-27 21:44:32 +01:00
|
|
|
|
cmp [ecx+IDE_DATA.ProgrammingInterface], 0
|
2013-07-09 02:34:01 +02:00
|
|
|
|
je EndFindHDD
|
2011-10-14 23:38:50 +02:00
|
|
|
|
FindHDD:
|
2014-03-27 21:44:32 +01:00
|
|
|
|
xor ebx, ebx
|
|
|
|
|
inc ebx
|
2015-10-21 00:51:18 +02:00
|
|
|
|
mov [DeviceNumber], 0
|
|
|
|
|
cmp ecx, IDE_controller_1
|
|
|
|
|
jz .find
|
|
|
|
|
add bl, 5
|
|
|
|
|
add [DeviceNumber], sizeof.HD_DATA*4
|
2014-03-27 21:44:32 +01:00
|
|
|
|
cmp ecx, IDE_controller_2
|
2015-10-21 00:51:18 +02:00
|
|
|
|
jz .find
|
2014-03-27 21:44:32 +01:00
|
|
|
|
add bl, 5
|
2015-10-21 00:51:18 +02:00
|
|
|
|
add [DeviceNumber], sizeof.HD_DATA*4
|
2014-03-27 21:44:32 +01:00
|
|
|
|
.find:
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ChannelNumber], 1
|
|
|
|
|
mov [DiskNumber], 0
|
2015-10-21 00:51:18 +02:00
|
|
|
|
call FindHDD_1
|
|
|
|
|
inc [DiskNumber]
|
2014-03-27 21:44:32 +01:00
|
|
|
|
call FindHDD_2
|
2011-10-14 23:38:50 +02:00
|
|
|
|
inc [ChannelNumber]
|
2015-10-21 00:51:18 +02:00
|
|
|
|
dec [DiskNumber]
|
2014-03-27 21:44:32 +01:00
|
|
|
|
call FindHDD_2
|
2015-10-21 00:51:18 +02:00
|
|
|
|
inc [DiskNumber]
|
|
|
|
|
call FindHDD_2
|
2014-03-27 21:44:32 +01:00
|
|
|
|
jmp EndFindHDD
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
|
FindHDD_2:
|
2015-10-21 00:51:18 +02:00
|
|
|
|
add [DeviceNumber], sizeof.HD_DATA
|
2014-03-27 21:44:32 +01:00
|
|
|
|
shl byte [ebx+DRIVE_DATA], 2
|
2011-10-14 23:38:50 +02:00
|
|
|
|
FindHDD_1:
|
2016-07-29 13:12:13 +02:00
|
|
|
|
DEBUGF 1, "K : Channel %d ",[ChannelNumber]:1
|
2013-06-26 04:38:47 +02:00
|
|
|
|
DEBUGF 1, "Disk %d\n",[DiskNumber]:1
|
2017-01-20 21:02:50 +01:00
|
|
|
|
push ecx ebx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
call ReadHDD_ID
|
2014-08-12 13:11:45 +02:00
|
|
|
|
cmp [DevErrorCode], 7
|
|
|
|
|
je .end
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp [DevErrorCode], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
jne .FindCD
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp [Sector512+6], word 16
|
2014-03-27 21:44:32 +01:00
|
|
|
|
ja .FindCD
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp [Sector512+12], word 255
|
2014-03-27 21:44:32 +01:00
|
|
|
|
ja .FindCD
|
2017-01-20 21:02:50 +01:00
|
|
|
|
pop ebx
|
2015-10-21 00:51:18 +02:00
|
|
|
|
movzx eax, [DeviceNumber]
|
2017-01-20 21:02:50 +01:00
|
|
|
|
mov ecx, [Sector512+120]
|
|
|
|
|
mov dword[eax+hd0_data.sectors], ecx
|
|
|
|
|
and dword[eax+hd0_data.sectors+4], 0
|
2015-10-21 00:51:18 +02:00
|
|
|
|
bt word [Sector512+166], 10
|
2017-01-20 21:02:50 +01:00
|
|
|
|
jnc .Print_Device_Name
|
|
|
|
|
mov [eax+hd0_data.hd48], 1
|
|
|
|
|
mov ecx, [Sector512+200]
|
|
|
|
|
mov dword[eax+hd0_data.sectors], ecx
|
|
|
|
|
mov ecx, [Sector512+204]
|
|
|
|
|
mov dword[eax+hd0_data.sectors+4], ecx
|
2014-03-27 21:44:32 +01:00
|
|
|
|
jmp .Print_Device_Name
|
|
|
|
|
;--------------------------------------
|
|
|
|
|
.FindCD:
|
2011-10-14 23:38:50 +02:00
|
|
|
|
call DeviceReset
|
|
|
|
|
cmp [DevErrorCode], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
jne .end
|
2011-10-14 23:38:50 +02:00
|
|
|
|
call ReadCD_ID
|
|
|
|
|
cmp [DevErrorCode], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
jne .end
|
2017-01-20 21:02:50 +01:00
|
|
|
|
pop ebx
|
|
|
|
|
inc byte [ebx+DRIVE_DATA]
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;--------------------------------------
|
2016-07-29 13:12:13 +02:00
|
|
|
|
.Print_Device_Name:
|
2017-01-20 21:02:50 +01:00
|
|
|
|
inc byte [ebx+DRIVE_DATA]
|
|
|
|
|
pop ecx
|
2013-06-27 01:35:43 +02:00
|
|
|
|
pushad
|
2016-07-29 13:12:13 +02:00
|
|
|
|
movzx ebx, [ChannelNumber]
|
2014-04-05 23:36:10 +02:00
|
|
|
|
dec ebx
|
|
|
|
|
shl ebx, 1
|
|
|
|
|
add bl, [DiskNumber]
|
|
|
|
|
shl ebx, 1
|
|
|
|
|
call calculate_IDE_device_values_storage
|
|
|
|
|
;--------------------------------------
|
|
|
|
|
.copy_dev_name:
|
2013-06-27 01:35:43 +02:00
|
|
|
|
mov esi, Sector512+27*2
|
|
|
|
|
mov edi, dev_name
|
|
|
|
|
mov ecx, 20
|
|
|
|
|
cld
|
2014-04-05 23:36:10 +02:00
|
|
|
|
;--------------------------------------
|
2013-06-25 05:15:38 +02:00
|
|
|
|
@@:
|
2013-06-27 01:35:43 +02:00
|
|
|
|
lodsw
|
|
|
|
|
xchg ah, al
|
|
|
|
|
stosw
|
|
|
|
|
loop @b
|
2013-06-25 05:15:38 +02:00
|
|
|
|
DEBUGF 1, "K : Dev: %s \n", dev_name
|
2013-09-01 23:29:56 +02:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov ax, [Sector512+64*2]
|
2014-04-05 23:36:10 +02:00
|
|
|
|
DEBUGF 1, "K : PIO possible modes %x\n", al
|
2014-03-10 01:09:59 +01:00
|
|
|
|
mov ax, [Sector512+51*2]
|
|
|
|
|
mov al, ah
|
|
|
|
|
call convert_Sector512_value
|
2014-04-05 23:36:10 +02:00
|
|
|
|
DEBUGF 1, "K : PIO set mode %x\n", ah
|
2013-09-01 23:29:56 +02:00
|
|
|
|
mov ax, [Sector512+63*2]
|
2014-03-10 01:09:59 +01:00
|
|
|
|
DEBUGF 1, "K : Multiword DMA possible modes %x\n", al
|
|
|
|
|
mov al, ah
|
|
|
|
|
call convert_Sector512_value
|
|
|
|
|
DEBUGF 1, "K : Multiword DMA set mode %x\n", ah
|
2013-09-01 23:29:56 +02:00
|
|
|
|
mov ax, [Sector512+88*2]
|
2014-03-10 01:09:59 +01:00
|
|
|
|
DEBUGF 1, "K : Ultra DMA possible modes %x\n", al
|
2014-04-05 23:36:10 +02:00
|
|
|
|
mov [ebx+IDE_DEVICE.UDMA_possible_modes], al
|
2014-03-10 01:09:59 +01:00
|
|
|
|
mov al, ah
|
|
|
|
|
call convert_Sector512_value
|
|
|
|
|
DEBUGF 1, "K : Ultra DMA set mode %x\n", ah
|
2014-04-05 23:36:10 +02:00
|
|
|
|
mov [ebx+IDE_DEVICE.UDMA_set_mode], ah
|
2014-03-27 21:44:32 +01:00
|
|
|
|
popad
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
2017-01-20 21:02:50 +01:00
|
|
|
|
|
2014-03-27 21:44:32 +01:00
|
|
|
|
.end:
|
|
|
|
|
DEBUGF 1, "K : Device not found\n"
|
2017-01-20 21:02:50 +01:00
|
|
|
|
pop ebx ecx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
2014-03-10 01:09:59 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2014-04-05 23:36:10 +02:00
|
|
|
|
calculate_IDE_device_values_storage:
|
|
|
|
|
cmp ecx, IDE_controller_1
|
|
|
|
|
jne @f
|
|
|
|
|
|
|
|
|
|
add ebx, IDE_device_1
|
|
|
|
|
jmp .exit
|
|
|
|
|
;--------------------------------------
|
|
|
|
|
@@:
|
|
|
|
|
cmp ecx, IDE_controller_2
|
|
|
|
|
jne @f
|
|
|
|
|
|
|
|
|
|
add ebx, IDE_device_2
|
|
|
|
|
jmp .exit
|
|
|
|
|
;--------------------------------------
|
|
|
|
|
@@:
|
|
|
|
|
add ebx, IDE_device_3
|
|
|
|
|
;--------------------------------------
|
|
|
|
|
.exit:
|
|
|
|
|
ret
|
|
|
|
|
;-----------------------------------------------------------------------------
|
2014-03-10 01:09:59 +01:00
|
|
|
|
convert_Sector512_value:
|
|
|
|
|
mov ecx, 8
|
|
|
|
|
xor ah, ah
|
2014-04-05 23:36:10 +02:00
|
|
|
|
;--------------------------------------
|
2014-03-10 01:09:59 +01:00
|
|
|
|
@@:
|
|
|
|
|
test al, 1b
|
|
|
|
|
jnz .end
|
2011-10-14 23:38:50 +02:00
|
|
|
|
|
2014-03-10 01:09:59 +01:00
|
|
|
|
shr al, 1
|
|
|
|
|
inc ah
|
|
|
|
|
loop @b
|
|
|
|
|
|
|
|
|
|
xor ah, ah
|
2014-04-05 23:36:10 +02:00
|
|
|
|
;--------------------------------------
|
2014-03-10 01:09:59 +01:00
|
|
|
|
.end:
|
|
|
|
|
ret
|
|
|
|
|
;-----------------------------------------------------------------------------
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Address of reading sector in LBA mode
|
2011-10-14 23:38:50 +02:00
|
|
|
|
uglobal
|
2014-03-27 21:44:32 +01:00
|
|
|
|
SectorAddress dd ?
|
2013-06-25 05:15:38 +02:00
|
|
|
|
dev_name:
|
2013-06-27 01:35:43 +02:00
|
|
|
|
rb 41
|
2011-10-14 23:38:50 +02:00
|
|
|
|
endg
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
2020-07-15 00:30:33 +02:00
|
|
|
|
;* READING THE HARD DISK IDENTIFIER *
|
|
|
|
|
;* Input parameters are passed through the global*
|
|
|
|
|
;* variables: *
|
|
|
|
|
;* ChannelNumber - channel number (1 or 2); *
|
|
|
|
|
;* DiskNumber - disk number on channel (0 or 1) *
|
|
|
|
|
;* Block of identificational data is reading *
|
|
|
|
|
;* to Sector512 array. *
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
|
|
|
|
ReadHDD_ID:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; set up CHS mode
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ATAAddressMode], 0
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; send device identification command
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ATAFeatures], 0
|
|
|
|
|
mov [ATAHead], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov [ATACommand], 0xEC
|
2011-10-14 23:38:50 +02:00
|
|
|
|
call SendCommandToHDD
|
2020-07-15 00:30:33 +02:00
|
|
|
|
cmp [DevErrorCode], 0 ; check the error code
|
|
|
|
|
jne @@End ; finish, saving the error code
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
|
|
mov dx, [ATABasePortAddr]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
add dx, 7 ; address of state register
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov ecx, 0xffff
|
|
|
|
|
@@WaitCompleet:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check command execution time
|
2011-10-14 23:38:50 +02:00
|
|
|
|
dec ecx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
jz @@Error1 ; timeout error
|
|
|
|
|
; Check if ready or not
|
2014-03-27 21:44:32 +01:00
|
|
|
|
in al, dx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 80h ; BSY signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@WaitCompleet
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 1 ; ERR signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@Error6
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 08h ; DRQ signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jz @@WaitCompleet
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Receive data block from controller
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov edi, Sector512
|
2020-07-15 00:30:33 +02:00
|
|
|
|
mov dx, [ATABasePortAddr]; data register
|
|
|
|
|
mov cx, 256 ; number of word to receive
|
|
|
|
|
rep insw ; receive data block
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; write the error code
|
2011-10-14 23:38:50 +02:00
|
|
|
|
@@Error1:
|
|
|
|
|
mov [DevErrorCode], 1
|
|
|
|
|
ret
|
|
|
|
|
@@Error6:
|
|
|
|
|
mov [DevErrorCode], 6
|
|
|
|
|
@@End:
|
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
uglobal
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Standart base addresses of channels 1 or 2
|
2014-03-27 21:44:32 +01:00
|
|
|
|
StandardATABases dw ?, ? ; 1F0h, 170h
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Channel number
|
2016-07-29 13:12:13 +02:00
|
|
|
|
ChannelNumber db ?
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Disk number
|
2014-03-27 21:44:32 +01:00
|
|
|
|
DiskNumber db ?
|
2015-10-21 00:51:18 +02:00
|
|
|
|
DeviceNumber db ?
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Base address of ATA controller's port group
|
2014-03-27 21:44:32 +01:00
|
|
|
|
ATABasePortAddr dw ?
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; ATA-command parameters
|
|
|
|
|
ATAFeatures db ? ; features
|
|
|
|
|
ATASectorCount db ? ; count of processing sectors
|
|
|
|
|
ATASectorNumber db ? ; initial sector number
|
|
|
|
|
ATACylinder dw ? ; initial cylinder number
|
|
|
|
|
ATAHead db ? ; initial head number
|
|
|
|
|
ATAAddressMode db ? ; addressing mode (0 - CHS, 1 - LBA)
|
|
|
|
|
ATACommand db ? ; executing command number
|
|
|
|
|
; Error code (0 - no errors, 1 - waiting time limit exceed
|
|
|
|
|
; 2 - incorrect code of addressing mode,
|
|
|
|
|
; 3 - incorrect channel number, 4 - incorrect disk number,
|
|
|
|
|
; 5 - incorrect head number, 6 - command execution error,
|
|
|
|
|
; 7 - time out when choosing channel)
|
2011-10-14 23:38:50 +02:00
|
|
|
|
DevErrorCode dd ?
|
|
|
|
|
endg
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;****************************************************
|
2020-07-15 00:30:33 +02:00
|
|
|
|
;* SEND COMMAND TO GIVEN DISK *
|
|
|
|
|
;* Input parameters are passed through the global *
|
|
|
|
|
;* variables: *
|
|
|
|
|
;* ChannelNumber - channel number (1 or 2); *
|
|
|
|
|
;* DiskNumber - disk number (0 or 1); *
|
|
|
|
|
;* ATAFeatures - "features"; *
|
|
|
|
|
;* ATASectorCount - sector count; *
|
|
|
|
|
;* ATASectorNumber - initial sector number; *
|
|
|
|
|
;* ATACylinder - initial cylinder number; *
|
|
|
|
|
;* ATAHead - initial head number; *
|
|
|
|
|
;* ATAAddressMode - addressing mode (0-CHS, 1-LBA); *
|
|
|
|
|
;* ATACommand - command code. *
|
|
|
|
|
;* If the function finished successfully: *
|
|
|
|
|
;* in ATABasePortAddr - base address of HDD; *
|
|
|
|
|
;* in DevErrorCode - zero. *
|
|
|
|
|
;* If error has occured then in DevErrorCode will *
|
|
|
|
|
;* be the error code. *
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;****************************************************
|
|
|
|
|
SendCommandToHDD:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the addressing mode code
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cmp [ATAAddressMode], 1
|
|
|
|
|
ja @@Err2
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the channel number correctness
|
2016-07-29 13:12:13 +02:00
|
|
|
|
movzx ebx, [ChannelNumber]
|
|
|
|
|
dec ebx
|
|
|
|
|
cmp ebx, 1
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ja @@Err3
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Set the base address
|
2016-07-29 13:12:13 +02:00
|
|
|
|
shl ebx, 1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov ax, [ebx+StandardATABases]
|
|
|
|
|
mov [ATABasePortAddr], ax
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Waiting for HDD ready to receive a command
|
|
|
|
|
; Choose desired disk
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov dx, [ATABasePortAddr]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
add dx, 6 ; address of the heads register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [DiskNumber]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
cmp al, 1 ; check the disk number
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ja @@Err4
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
|
|
shl al, 4
|
|
|
|
|
or al, 10100000b
|
|
|
|
|
out dx, al
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Waiting for disk ready
|
2014-03-27 21:44:32 +01:00
|
|
|
|
inc dx
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov ecx, 0xfff
|
|
|
|
|
@@WaitHDReady:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check waiting time
|
2011-10-14 23:38:50 +02:00
|
|
|
|
dec ecx
|
|
|
|
|
jz @@Err1
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Read the state register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
in al, dx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the state of BSY signal
|
2014-03-27 21:44:32 +01:00
|
|
|
|
test al, 80h
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@WaitHDReady
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the state of DRQ signal
|
2014-03-27 21:44:32 +01:00
|
|
|
|
test al, 08h
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@WaitHDReady
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; load command to controller's registers
|
2011-10-14 23:38:50 +02:00
|
|
|
|
cli
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov dx, [ATABasePortAddr]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; "features" register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [ATAFeatures]
|
|
|
|
|
out dx, AL
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; sector counter
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [ATASectorCount]
|
|
|
|
|
out dx, AL
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; sector number register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [ATASectorNumber]
|
|
|
|
|
out dx, AL
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; cylinder number (low byte)
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov ax, [ATACylinder]
|
|
|
|
|
out dx, AL
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; cylinder number (high byte)
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, AH
|
|
|
|
|
out dx, AL
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; head number / disk number
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [DiskNumber]
|
|
|
|
|
shl al, 4
|
2020-07-15 00:30:33 +02:00
|
|
|
|
cmp [ATAHead], 0xF ; check head number
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ja @@Err5
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
|
|
or al, [ATAHead]
|
|
|
|
|
or al, 10100000b
|
|
|
|
|
mov ah, [ATAAddressMode]
|
|
|
|
|
shl ah, 6
|
|
|
|
|
or al, ah
|
|
|
|
|
out dx, al
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Send command
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [ATACommand]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; command register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
out dx, al
|
2011-10-14 23:38:50 +02:00
|
|
|
|
sti
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; reset the error sign
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [DevErrorCode], 0
|
|
|
|
|
ret
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; write error code
|
2011-10-14 23:38:50 +02:00
|
|
|
|
@@Err1:
|
2014-08-12 13:11:45 +02:00
|
|
|
|
mov [DevErrorCode], 7
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
|
|
|
|
@@Err2:
|
|
|
|
|
mov [DevErrorCode], 2
|
|
|
|
|
ret
|
|
|
|
|
@@Err3:
|
|
|
|
|
mov [DevErrorCode], 3
|
|
|
|
|
ret
|
|
|
|
|
@@Err4:
|
|
|
|
|
mov [DevErrorCode], 4
|
|
|
|
|
ret
|
|
|
|
|
@@Err5:
|
|
|
|
|
mov [DevErrorCode], 5
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; finish work
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
2020-07-15 00:30:33 +02:00
|
|
|
|
;* READ ATAPI DEVICE IDENTIFIER *
|
|
|
|
|
;* Input parameters are passed through the global*
|
|
|
|
|
;* variables: *
|
|
|
|
|
;* ChannelNumber - channel number; *
|
|
|
|
|
;* DiskNumber - disk number on channel. *
|
|
|
|
|
;* Block of identificational data is reading *
|
|
|
|
|
;* to Sector512 array. * *
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
|
|
|
|
ReadCD_ID:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Set CHS mode
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ATAAddressMode], 0
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Send command for device identification
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [ATAFeatures], 0
|
|
|
|
|
mov [ATASectorCount], 0
|
|
|
|
|
mov [ATASectorNumber], 0
|
|
|
|
|
mov [ATACylinder], 0
|
|
|
|
|
mov [ATAHead], 0
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov [ATACommand], 0xA1
|
2011-10-14 23:38:50 +02:00
|
|
|
|
call SendCommandToHDD
|
2020-07-15 00:30:33 +02:00
|
|
|
|
cmp [DevErrorCode], 0 ; check the error code
|
|
|
|
|
jne @@End_1 ; finish, saving the error code
|
|
|
|
|
; Wait for HDD data ready
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov dx, [ATABasePortAddr]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
add dx, 7 ; port 1х7h
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov ecx, 0xffff
|
|
|
|
|
@@WaitCompleet_1:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check time
|
2011-10-14 23:38:50 +02:00
|
|
|
|
dec ecx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
jz @@Error1_1 ; time out error
|
|
|
|
|
; Check readyness
|
2014-03-27 21:44:32 +01:00
|
|
|
|
in al, dx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 80h ; BSY signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@WaitCompleet_1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 1 ; ERR signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@Error6_1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
2020-07-15 00:30:33 +02:00
|
|
|
|
test al, 08h ; DRQ signal state
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jz @@WaitCompleet_1
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Receive data block from controller
|
|
|
|
|
mov edi, Sector512 ; offset Sector512
|
|
|
|
|
mov dx, [ATABasePortAddr] ; port 1x0h
|
|
|
|
|
mov cx, 256 ; words read count
|
2011-10-14 23:38:50 +02:00
|
|
|
|
rep insw
|
|
|
|
|
ret
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; write the error code
|
2011-10-14 23:38:50 +02:00
|
|
|
|
@@Error1_1:
|
|
|
|
|
mov [DevErrorCode], 1
|
|
|
|
|
ret
|
|
|
|
|
@@Error6_1:
|
|
|
|
|
mov [DevErrorCode], 6
|
|
|
|
|
@@End_1:
|
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
2020-07-15 00:30:33 +02:00
|
|
|
|
;* DEVICE RESET *
|
|
|
|
|
;* Input parameters are passed through the global*
|
|
|
|
|
;* variables: *
|
|
|
|
|
;* ChannelNumber - channel number (1 or 2); *
|
|
|
|
|
;* DiskNumber - disk number (0 or 1). *
|
2011-10-14 23:38:50 +02:00
|
|
|
|
;*************************************************
|
|
|
|
|
DeviceReset:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the channel number correctness
|
2016-07-29 13:12:13 +02:00
|
|
|
|
movzx ebx, [ChannelNumber]
|
|
|
|
|
dec ebx
|
|
|
|
|
cmp ebx, 1
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ja @@Err3_2
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Set base address
|
2016-07-29 13:12:13 +02:00
|
|
|
|
shl ebx, 1
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov dx, [ebx+StandardATABases]
|
|
|
|
|
mov [ATABasePortAddr], dx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Choose desired disk
|
|
|
|
|
add dx, 6 ; address of heads register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, [DiskNumber]
|
2020-07-15 00:30:33 +02:00
|
|
|
|
cmp al, 1 ; check disk number
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ja @@Err4_2
|
2014-03-27 21:44:32 +01:00
|
|
|
|
|
|
|
|
|
shl al, 4
|
|
|
|
|
or al, 10100000b
|
|
|
|
|
out dx, al
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Send the "Reset" command
|
2014-03-27 21:44:32 +01:00
|
|
|
|
mov al, 0x8
|
2020-07-15 00:30:33 +02:00
|
|
|
|
inc dx ; command register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
out dx, al
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov ecx, 0x80000
|
|
|
|
|
@@WaitHDReady_1:
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check waiting time
|
2011-10-14 23:38:50 +02:00
|
|
|
|
dec ecx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
je @@Err1_2 ; time out error
|
|
|
|
|
; read the state register
|
2014-03-27 21:44:32 +01:00
|
|
|
|
in al, dx
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; Check the state of BSY signal
|
2014-03-27 21:44:32 +01:00
|
|
|
|
test al, 80h
|
2011-10-14 23:38:50 +02:00
|
|
|
|
jnz @@WaitHDReady_1
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; reset the error sign
|
2011-10-14 23:38:50 +02:00
|
|
|
|
mov [DevErrorCode], 0
|
|
|
|
|
ret
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; error processing
|
2011-10-14 23:38:50 +02:00
|
|
|
|
@@Err1_2:
|
|
|
|
|
mov [DevErrorCode], 1
|
|
|
|
|
ret
|
|
|
|
|
@@Err3_2:
|
|
|
|
|
mov [DevErrorCode], 3
|
|
|
|
|
ret
|
|
|
|
|
@@Err4_2:
|
|
|
|
|
mov [DevErrorCode], 4
|
2020-07-15 00:30:33 +02:00
|
|
|
|
; write error code
|
2011-10-14 23:38:50 +02:00
|
|
|
|
ret
|
2014-03-27 21:44:32 +01:00
|
|
|
|
;-----------------------------------------------------------------------------
|
2011-10-14 23:38:50 +02:00
|
|
|
|
EndFindHDD:
|