source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm@ 441

Last change on this file since 441 was 439, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Drive identify is now skipped for XT-CF if 8-bit mode is not successfully enabled.
File size: 8.4 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
2; Description : IDE Device Command functions.
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[150]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; IdeCommand_ResetMasterAndSlaveController
25; Parameters:
26; DS:DI: Ptr to DPT (in RAMVARS segment)
27; Returns:
28; AH: INT 13h Error Code
29; CF: Cleared if success, Set if error
30; Corrupts registers:
31; AL, BX, CX, DX
32;--------------------------------------------------------------------
[400]33IdeCommand_ResetMasterAndSlaveController:
[150]34 ; HSR0: Set_SRST
35 call AccessDPT_GetDeviceControlByteToAL
36 or al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN ; Set Reset bit
[267]37 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
[150]38 mov ax, HSR0_RESET_WAIT_US
[155]39 call Timer_DelayMicrosecondsFromAX
[150]40
41 ; HSR1: Clear_wait
42 call AccessDPT_GetDeviceControlByteToAL
43 or al, FLG_DEVCONTROL_nIEN
44 and al, ~FLG_DEVCONTROL_SRST ; Clear reset bit
[267]45 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
[150]46 mov ax, HSR1_RESET_WAIT_US
[155]47 call Timer_DelayMicrosecondsFromAX
[150]48
49 ; HSR2: Check_status
[432]50 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MAXIMUM, FLG_STATUS_BSY)
[400]51 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
[150]52
53
54;--------------------------------------------------------------------
55; IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
56; Parameters:
57; BH: Drive Select byte for Drive and Head Select Register
58; DS: Segment to RAMVARS
59; ES:SI: Ptr to buffer to receive 512-byte IDE Information
60; CS:BP: Ptr to IDEVARS
61; Returns:
62; AH: INT 13h Error Code
63; CF: Cleared if success, Set if error
64; Corrupts registers:
65; AL, BL, CX, DX, SI, DI, ES
66;--------------------------------------------------------------------
[400]67IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
[150]68 ; Create fake DPT to be able to use Device.asm functions
69 call FindDPT_ForNewDriveToDSDI
[158]70 eMOVZX ax, bh
[150]71 mov [di+DPT.wFlags], ax
72 mov [di+DPT.bIdevarsOffset], bp
[365]73 mov BYTE [di+DPT_ATA.bBlockSize], 1 ; Block = 1 sector
[363]74 call IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
[150]75
76 ; Wait until drive motors have reached max speed
77 cmp bp, BYTE ROMVARS.ideVars0
78 jne SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
[400]79 test bh, FLG_DRVNHEAD_DRV
[150]80 jnz SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
[428]81 call AHDh_WaitUnilDriveMotorHasReachedFullSpeed
[150]82.SkipLongWaitSinceDriveIsNotPrimaryMaster:
83
84 ; Create IDEPACK without INTPACK
85 push bp
86 call Idepack_FakeToSSBP
87
[439]88%ifdef MODULE_8BIT_IDE
[437]89 ; Enable 8-bit PIO mode for Lo-tech XT-CF
90 call AH9h_Enable8bitPioModeForXTCF
[439]91 jc SHORT .FailedToSet8bitMode
92%endif
[437]93
[150]94 ; Prepare to output Identify Device command
95 mov dl, 1 ; Sector count (required by IdeTransfer.asm)
96 mov al, COMMAND_IDENTIFY_DEVICE
[411]97 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
[150]98 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
99
100 ; Clean stack and return
[439]101.FailedToSet8bitMode:
[158]102 lea sp, [bp+EXTRA_BYTES_FOR_INTPACK] ; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
[150]103 pop bp
104 ret
105
106
107;--------------------------------------------------------------------
108; IdeCommand_OutputWithParameters
109; Parameters:
110; BH: System timer ticks for timeout
111; BL: IDE Status Register bit to poll after command
112; ES:SI: Ptr to buffer (for data transfer commands)
113; DS:DI: Ptr to DPT (in RAMVARS segment)
114; SS:BP: Ptr to IDEPACK
115; Returns:
116; AH: INT 13h Error Code
[249]117; CX: Number of successfully transferred sectors (for transfer commands)
[150]118; CF: Cleared if success, Set if error
119; Corrupts registers:
[249]120; AL, BX, (CX), DX, (ES:SI for data transfer commands)
[150]121;--------------------------------------------------------------------
122ALIGN JUMP_ALIGN
[400]123IdeCommand_OutputWithParameters:
[158]124 push bx ; Store status register bits to poll
[150]125
126 ; Select Master or Slave drive and output head number or LBA28 top bits
[400]127 call IdeCommand_SelectDrive
[150]128 jc SHORT .DriveNotReady
129
130 ; Output Device Control Byte to enable or disable interrupts
131 mov al, [bp+IDEPACK.bDeviceControl]
[400]132%ifdef MODULE_IRQ
[158]133 test al, FLG_DEVCONTROL_nIEN ; Interrupts disabled?
[152]134 jnz SHORT .DoNotSetInterruptInServiceFlag
[158]135
136 ; Clear Task Flag and set Interrupt In-Service Flag
137 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
[152]138 push ds
[158]139 LOAD_BDA_SEGMENT_TO ds, dx, ! ; Also zero DX
140 mov [BDA.bHDTaskFlg], dl
[152]141 pop ds
142.DoNotSetInterruptInServiceFlag:
[266]143%endif
[267]144 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
[150]145
146 ; Output Feature Number
147 mov al, [bp+IDEPACK.bFeatures]
[267]148 OUTPUT_AL_TO_IDE_REGISTER FEATURES_REGISTER_out
[150]149
150 ; Output Sector Address High (only used by LBA48)
[285]151%ifdef MODULE_EBIOS
[294]152 eMOVZX ax, [bp+IDEPACK.bLbaLowExt] ; Zero sector count
[150]153 mov cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
[400]154 call OutputSectorCountAndAddress
[285]155%endif
[150]156
157 ; Output Sector Address Low
158 mov ax, [bp+IDEPACK.wSectorCountAndLbaLow]
159 mov cx, [bp+IDEPACK.wLbaMiddleAndHigh]
[400]160 call OutputSectorCountAndAddress
[150]161
162 ; Output command
163 mov al, [bp+IDEPACK.bCommand]
[267]164 OUTPUT_AL_TO_IDE_REGISTER COMMAND_REGISTER_out
[150]165
166 ; Wait until command completed
[400]167 pop bx ; Pop status and timeout for polling
168 cmp bl, FLG_STATUS_DRQ ; Data transfer started?
169 jne SHORT .WaitUntilNonTransferCommandCompletes
170%ifdef MODULE_JRIDE
171 cmp BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
172 je SHORT JrIdeTransfer_StartWithCommandInAL
173%endif
174 jmp IdeTransfer_StartWithCommandInAL
175
176.WaitUntilNonTransferCommandCompletes:
177%ifdef MODULE_IRQ
[150]178 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
[400]179 jz SHORT .PollStatusFlagInsteadOfWaitIrq
180 jmp IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
181.PollStatusFlagInsteadOfWaitIrq:
182%endif
183 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
[150]184
185.DriveNotReady:
186 pop bx ; Clean stack
187 ret
188
189
190;--------------------------------------------------------------------
191; IdeCommand_SelectDrive
192; Parameters:
193; DS:DI: Ptr to DPT (in RAMVARS segment)
194; SS:BP: Ptr to IDEPACK
195; Returns:
196; AH: INT 13h Error Code
197; CF: Cleared if success, Set if error
198; Corrupts registers:
199; AL, BX, CX, DX
200;--------------------------------------------------------------------
201ALIGN JUMP_ALIGN
[400]202IdeCommand_SelectDrive:
[421]203%if 0
[408]204 ; Wait until neither Master or Slave Drive is busy
205 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
206 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
207 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
208 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
[421]209%endif
[408]210
[150]211 ; Select Master or Slave Drive
212 mov al, [bp+IDEPACK.bDrvAndHead]
[267]213 OUTPUT_AL_TO_IDE_REGISTER DRIVE_AND_HEAD_SELECT_REGISTER
[150]214 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
215 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
[158]216 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
[400]217 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
[150]218
[281]219 ; Ignore errors from IDE Error Register (set by previous command)
[285]220 cmp ah, RET_HD_TIMEOUT
221 je SHORT .FailedToSelectDrive
222 xor ax, ax ; Always success unless timeout
223 ret
224.FailedToSelectDrive:
[281]225 stc
[279]226 ret
[150]227
[279]228
[150]229;--------------------------------------------------------------------
230; OutputSectorCountAndAddress
231; Parameters:
232; AH: LBA low bits (Sector Number)
233; AL: Sector Count
234; CL: LBA middle bits (Cylinder Number low)
235; CH: LBA high bits (Cylinder Number high)
236; DS:DI: Ptr to DPT (in RAMVARS segment)
237; Returns:
238; Nothing
239; Corrupts registers:
240; AL, BX, DX
241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
[400]243OutputSectorCountAndAddress:
[267]244 OUTPUT_AL_TO_IDE_REGISTER SECTOR_COUNT_REGISTER
[150]245
246 mov al, ah
[267]247 OUTPUT_AL_TO_IDE_REGISTER LBA_LOW_REGISTER
[150]248
249 mov al, cl
[267]250 OUTPUT_AL_TO_IDE_REGISTER LBA_MIDDLE_REGISTER
[150]251
252 mov al, ch
[267]253 JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER LBA_HIGH_REGISTER
Note: See TracBrowser for help on using the repository browser.