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

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

Changes to XTIDE Universal BIOS:

  • Increased IDE software reset protocol timeout value from 10 to 14 seconds.
File size: 8.2 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : IDE Device Command functions.
3
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
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;--------------------------------------------------------------------
33IdeCommand_ResetMasterAndSlaveController:
34 ; HSR0: Set_SRST
35 call AccessDPT_GetDeviceControlByteToAL
36 or al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN ; Set Reset bit
37 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
38 mov ax, HSR0_RESET_WAIT_US
39 call Timer_DelayMicrosecondsFromAX
40
41 ; HSR1: Clear_wait
42 call AccessDPT_GetDeviceControlByteToAL
43 or al, FLG_DEVCONTROL_nIEN
44 and al, ~FLG_DEVCONTROL_SRST ; Clear reset bit
45 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
46 mov ax, HSR1_RESET_WAIT_US
47 call Timer_DelayMicrosecondsFromAX
48
49 ; HSR2: Check_status
50 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MAXIMUM, FLG_STATUS_BSY)
51 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
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;--------------------------------------------------------------------
67IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
68 ; Create fake DPT to be able to use Device.asm functions
69 call FindDPT_ForNewDriveToDSDI
70 eMOVZX ax, bh
71 mov [di+DPT.wFlags], ax
72 mov [di+DPT.bIdevarsOffset], bp
73 mov BYTE [di+DPT_ATA.bBlockSize], 1 ; Block = 1 sector
74 call IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
75
76 ; Wait until drive motors have reached max speed
77 cmp bp, BYTE ROMVARS.ideVars0
78 jne SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
79 test bh, FLG_DRVNHEAD_DRV
80 jnz SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
81 call AHDh_WaitUnilDriveMotorHasReachedFullSpeed
82.SkipLongWaitSinceDriveIsNotPrimaryMaster:
83
84 ; Create IDEPACK without INTPACK
85 push bp
86 call Idepack_FakeToSSBP
87
88 ; Prepare to output Identify Device command
89 mov dl, 1 ; Sector count (required by IdeTransfer.asm)
90 mov al, COMMAND_IDENTIFY_DEVICE
91 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
92 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
93
94 ; Clean stack and return
95 lea sp, [bp+EXTRA_BYTES_FOR_INTPACK] ; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
96 pop bp
97 ret
98
99
100;--------------------------------------------------------------------
101; IdeCommand_OutputWithParameters
102; Parameters:
103; BH: System timer ticks for timeout
104; BL: IDE Status Register bit to poll after command
105; ES:SI: Ptr to buffer (for data transfer commands)
106; DS:DI: Ptr to DPT (in RAMVARS segment)
107; SS:BP: Ptr to IDEPACK
108; Returns:
109; AH: INT 13h Error Code
110; CX: Number of successfully transferred sectors (for transfer commands)
111; CF: Cleared if success, Set if error
112; Corrupts registers:
113; AL, BX, (CX), DX, (ES:SI for data transfer commands)
114;--------------------------------------------------------------------
115ALIGN JUMP_ALIGN
116IdeCommand_OutputWithParameters:
117 push bx ; Store status register bits to poll
118
119 ; Select Master or Slave drive and output head number or LBA28 top bits
120 call IdeCommand_SelectDrive
121 jc SHORT .DriveNotReady
122
123 ; Output Device Control Byte to enable or disable interrupts
124 mov al, [bp+IDEPACK.bDeviceControl]
125%ifdef MODULE_IRQ
126 test al, FLG_DEVCONTROL_nIEN ; Interrupts disabled?
127 jnz SHORT .DoNotSetInterruptInServiceFlag
128
129 ; Clear Task Flag and set Interrupt In-Service Flag
130 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
131 push ds
132 LOAD_BDA_SEGMENT_TO ds, dx, ! ; Also zero DX
133 mov [BDA.bHDTaskFlg], dl
134 pop ds
135.DoNotSetInterruptInServiceFlag:
136%endif
137 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
138
139 ; Output Feature Number
140 mov al, [bp+IDEPACK.bFeatures]
141 OUTPUT_AL_TO_IDE_REGISTER FEATURES_REGISTER_out
142
143 ; Output Sector Address High (only used by LBA48)
144%ifdef MODULE_EBIOS
145 eMOVZX ax, [bp+IDEPACK.bLbaLowExt] ; Zero sector count
146 mov cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
147 call OutputSectorCountAndAddress
148%endif
149
150 ; Output Sector Address Low
151 mov ax, [bp+IDEPACK.wSectorCountAndLbaLow]
152 mov cx, [bp+IDEPACK.wLbaMiddleAndHigh]
153 call OutputSectorCountAndAddress
154
155 ; Output command
156 mov al, [bp+IDEPACK.bCommand]
157 OUTPUT_AL_TO_IDE_REGISTER COMMAND_REGISTER_out
158
159 ; Wait until command completed
160 pop bx ; Pop status and timeout for polling
161 cmp bl, FLG_STATUS_DRQ ; Data transfer started?
162 jne SHORT .WaitUntilNonTransferCommandCompletes
163%ifdef MODULE_JRIDE
164 cmp BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_JRIDE_ISA
165 je SHORT JrIdeTransfer_StartWithCommandInAL
166%endif
167 jmp IdeTransfer_StartWithCommandInAL
168
169.WaitUntilNonTransferCommandCompletes:
170%ifdef MODULE_IRQ
171 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
172 jz SHORT .PollStatusFlagInsteadOfWaitIrq
173 jmp IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
174.PollStatusFlagInsteadOfWaitIrq:
175%endif
176 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
177
178.DriveNotReady:
179 pop bx ; Clean stack
180 ret
181
182
183;--------------------------------------------------------------------
184; IdeCommand_SelectDrive
185; Parameters:
186; DS:DI: Ptr to DPT (in RAMVARS segment)
187; SS:BP: Ptr to IDEPACK
188; Returns:
189; AH: INT 13h Error Code
190; CF: Cleared if success, Set if error
191; Corrupts registers:
192; AL, BX, CX, DX
193;--------------------------------------------------------------------
194ALIGN JUMP_ALIGN
195IdeCommand_SelectDrive:
196%if 0
197 ; Wait until neither Master or Slave Drive is busy
198 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
199 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
200 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
201 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
202%endif
203
204 ; Select Master or Slave Drive
205 mov al, [bp+IDEPACK.bDrvAndHead]
206 OUTPUT_AL_TO_IDE_REGISTER DRIVE_AND_HEAD_SELECT_REGISTER
207 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
208 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
209 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
210 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
211
212 ; Ignore errors from IDE Error Register (set by previous command)
213 cmp ah, RET_HD_TIMEOUT
214 je SHORT .FailedToSelectDrive
215 xor ax, ax ; Always success unless timeout
216 ret
217.FailedToSelectDrive:
218 stc
219 ret
220
221
222;--------------------------------------------------------------------
223; OutputSectorCountAndAddress
224; Parameters:
225; AH: LBA low bits (Sector Number)
226; AL: Sector Count
227; CL: LBA middle bits (Cylinder Number low)
228; CH: LBA high bits (Cylinder Number high)
229; DS:DI: Ptr to DPT (in RAMVARS segment)
230; Returns:
231; Nothing
232; Corrupts registers:
233; AL, BX, DX
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
236OutputSectorCountAndAddress:
237 OUTPUT_AL_TO_IDE_REGISTER SECTOR_COUNT_REGISTER
238
239 mov al, ah
240 OUTPUT_AL_TO_IDE_REGISTER LBA_LOW_REGISTER
241
242 mov al, cl
243 OUTPUT_AL_TO_IDE_REGISTER LBA_MIDDLE_REGISTER
244
245 mov al, ch
246 JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER LBA_HIGH_REGISTER
Note: See TracBrowser for help on using the repository browser.