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

Last change on this file since 393 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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;--------------------------------------------------------------------
[238]33IDEDEVICE%+Command_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
50 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
[238]51 jmp IDEDEVICE%+Wait_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;--------------------------------------------------------------------
[238]67IDEDEVICE%+Command_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%ifdef MODULE_ADVANCED_ATA
75 call IdeDPT_StoreDeviceTypeFromIdevarsInCSBPtoDPTinDSDI
76%endif
[266]77%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
[160]78 call IdeDPT_StoreReversedAddressLinesFlagIfNecessary
[266]79%endif
[150]80
81 ; Wait until drive motors have reached max speed
82 cmp bp, BYTE ROMVARS.ideVars0
83 jne SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
[158]84 test al, FLG_DRVNHEAD_DRV
[150]85 jnz SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
86 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
[238]87 call IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
[150]88.SkipLongWaitSinceDriveIsNotPrimaryMaster:
89
90 ; Create IDEPACK without INTPACK
91 push bp
92 call Idepack_FakeToSSBP
93
94 ; Prepare to output Identify Device command
95 mov dl, 1 ; Sector count (required by IdeTransfer.asm)
96 mov al, COMMAND_IDENTIFY_DEVICE
97 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_DRQ)
98 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
99
100 ; Clean stack and return
[158]101 lea sp, [bp+EXTRA_BYTES_FOR_INTPACK] ; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
[150]102 pop bp
103 ret
104
105
106;--------------------------------------------------------------------
107; IdeCommand_OutputWithParameters
108; Parameters:
109; BH: System timer ticks for timeout
110; BL: IDE Status Register bit to poll after command
111; ES:SI: Ptr to buffer (for data transfer commands)
112; DS:DI: Ptr to DPT (in RAMVARS segment)
113; SS:BP: Ptr to IDEPACK
114; Returns:
115; AH: INT 13h Error Code
[249]116; CX: Number of successfully transferred sectors (for transfer commands)
[150]117; CF: Cleared if success, Set if error
118; Corrupts registers:
[249]119; AL, BX, (CX), DX, (ES:SI for data transfer commands)
[150]120;--------------------------------------------------------------------
121ALIGN JUMP_ALIGN
[238]122IDEDEVICE%+Command_OutputWithParameters:
[158]123 push bx ; Store status register bits to poll
[150]124
125 ; Select Master or Slave drive and output head number or LBA28 top bits
[238]126 call IDEDEVICE%+Command_SelectDrive
[150]127 jc SHORT .DriveNotReady
128
129 ; Output Device Control Byte to enable or disable interrupts
130 mov al, [bp+IDEPACK.bDeviceControl]
[266]131%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA
[158]132 test al, FLG_DEVCONTROL_nIEN ; Interrupts disabled?
[152]133 jnz SHORT .DoNotSetInterruptInServiceFlag
[158]134
135 ; Clear Task Flag and set Interrupt In-Service Flag
136 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
[152]137 push ds
[158]138 LOAD_BDA_SEGMENT_TO ds, dx, ! ; Also zero DX
139 mov [BDA.bHDTaskFlg], dl
[152]140 pop ds
141.DoNotSetInterruptInServiceFlag:
[266]142%endif
[267]143 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
[150]144
145 ; Output Feature Number
146 mov al, [bp+IDEPACK.bFeatures]
[267]147 OUTPUT_AL_TO_IDE_REGISTER FEATURES_REGISTER_out
[150]148
149 ; Output Sector Address High (only used by LBA48)
[285]150%ifdef MODULE_EBIOS
[294]151 eMOVZX ax, [bp+IDEPACK.bLbaLowExt] ; Zero sector count
[150]152 mov cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
[266]153 call IDEDEVICE%+OutputSectorCountAndAddress
[285]154%endif
[150]155
156 ; Output Sector Address Low
157 mov ax, [bp+IDEPACK.wSectorCountAndLbaLow]
158 mov cx, [bp+IDEPACK.wLbaMiddleAndHigh]
[266]159 call IDEDEVICE%+OutputSectorCountAndAddress
[150]160
161 ; Output command
162 mov al, [bp+IDEPACK.bCommand]
[267]163 OUTPUT_AL_TO_IDE_REGISTER COMMAND_REGISTER_out
[150]164
165 ; Wait until command completed
[158]166 pop bx ; Pop status and timeout for polling
167 cmp bl, FLG_STATUS_DRQ ; Data transfer started?
[238]168 je SHORT IDEDEVICE%+Transfer_StartWithCommandInAL
[150]169 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
170 jz SHORT .WaitForIrqOrRdy
[238]171 jmp IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
[150]172
173ALIGN JUMP_ALIGN
174.WaitForIrqOrRdy:
[238]175 jmp IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH
[150]176
177.DriveNotReady:
178 pop bx ; Clean stack
179 ret
180
181
182;--------------------------------------------------------------------
183; IdeCommand_SelectDrive
184; Parameters:
185; DS:DI: Ptr to DPT (in RAMVARS segment)
186; SS:BP: Ptr to IDEPACK
187; Returns:
188; AH: INT 13h Error Code
189; CF: Cleared if success, Set if error
190; Corrupts registers:
191; AL, BX, CX, DX
192;--------------------------------------------------------------------
193ALIGN JUMP_ALIGN
[238]194IDEDEVICE%+Command_SelectDrive:
[279]195 ; Wait until neither Master or Slave Drive is busy.
196 ; I don't think this wait is necessary.
197 ;mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
198 ;cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
199 ;eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
200 ;call IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
[150]201
202 ; Select Master or Slave Drive
203 mov al, [bp+IDEPACK.bDrvAndHead]
[267]204 OUTPUT_AL_TO_IDE_REGISTER DRIVE_AND_HEAD_SELECT_REGISTER
[150]205 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
206 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
[158]207 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
[279]208 call IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
[150]209
[281]210 ; Ignore errors from IDE Error Register (set by previous command)
[285]211 cmp ah, RET_HD_TIMEOUT
212 je SHORT .FailedToSelectDrive
213 xor ax, ax ; Always success unless timeout
214 ret
215.FailedToSelectDrive:
[281]216 stc
[279]217 ret
[150]218
[279]219
[150]220;--------------------------------------------------------------------
221; OutputSectorCountAndAddress
222; Parameters:
223; AH: LBA low bits (Sector Number)
224; AL: Sector Count
225; CL: LBA middle bits (Cylinder Number low)
226; CH: LBA high bits (Cylinder Number high)
227; DS:DI: Ptr to DPT (in RAMVARS segment)
228; Returns:
229; Nothing
230; Corrupts registers:
231; AL, BX, DX
232;--------------------------------------------------------------------
233ALIGN JUMP_ALIGN
[266]234IDEDEVICE%+OutputSectorCountAndAddress:
[267]235 OUTPUT_AL_TO_IDE_REGISTER SECTOR_COUNT_REGISTER
[150]236
237 mov al, ah
[267]238 OUTPUT_AL_TO_IDE_REGISTER LBA_LOW_REGISTER
[150]239
240 mov al, cl
[267]241 OUTPUT_AL_TO_IDE_REGISTER LBA_MIDDLE_REGISTER
[150]242
243 mov al, ch
[267]244 JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER LBA_HIGH_REGISTER
Note: See TracBrowser for help on using the repository browser.