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

Last change on this file since 151 was 150, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS:

  • Redesigned Disk Parameter Tables.
  • Code generalizations for supporting non-IDE devices in the future.
File size: 7.2 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : IDE Device Command functions.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; IdeCommand_ResetMasterAndSlaveController
9; Parameters:
10; DS:DI: Ptr to DPT (in RAMVARS segment)
11; Returns:
12; AH: INT 13h Error Code
13; CF: Cleared if success, Set if error
14; Corrupts registers:
15; AL, BX, CX, DX
16;--------------------------------------------------------------------
17IdeCommand_ResetMasterAndSlaveController:
18 ; HSR0: Set_SRST
19 call AccessDPT_GetDeviceControlByteToAL
20 or al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN ; Set Reset bit
21 mov dl, DEVICE_CONTROL_REGISTER_out
22 call Device_OutputALtoIdeControlBlockRegisterInDL
23 mov ax, HSR0_RESET_WAIT_US
24 call HTimer_DelayMicrosecondsFromAX
25
26 ; HSR1: Clear_wait
27 call AccessDPT_GetDeviceControlByteToAL
28 or al, FLG_DEVCONTROL_nIEN
29 and al, ~FLG_DEVCONTROL_SRST ; Clear reset bit
30 mov dl, DEVICE_CONTROL_REGISTER_out
31 call Device_OutputALtoIdeControlBlockRegisterInDL
32 mov ax, HSR1_RESET_WAIT_US
33 call HTimer_DelayMicrosecondsFromAX
34
35 ; HSR2: Check_status
36 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
37 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
38
39
40;--------------------------------------------------------------------
41; IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
42; Parameters:
43; BH: Drive Select byte for Drive and Head Select Register
44; DS: Segment to RAMVARS
45; ES:SI: Ptr to buffer to receive 512-byte IDE Information
46; CS:BP: Ptr to IDEVARS
47; Returns:
48; AH: INT 13h Error Code
49; CF: Cleared if success, Set if error
50; Corrupts registers:
51; AL, BL, CX, DX, SI, DI, ES
52;--------------------------------------------------------------------
53IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
54 ; Create fake DPT to be able to use Device.asm functions
55 call FindDPT_ForNewDriveToDSDI
56 xor ax, ax
57 cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_XTIDE_WITH_REVERSED_A3_AND_A0
58 eCMOVE ax, FLG_DPT_REVERSED_A0_AND_A3
59 or al, bh
60 mov [di+DPT.wFlags], ax
61 mov [di+DPT.bIdevarsOffset], bp
62 mov BYTE [di+DPT_ATA.bSetBlock], 1 ; Block = 1 sector
63
64 ; Wait until drive motors have reached max speed
65 cmp bp, BYTE ROMVARS.ideVars0
66 jne SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
67 test bh, FLG_DRVNHEAD_DRV
68 jnz SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
69 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
70 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
71.SkipLongWaitSinceDriveIsNotPrimaryMaster:
72
73 ; Create IDEPACK without INTPACK
74 push bp
75 call Idepack_FakeToSSBP
76
77 ; Prepare to output Identify Device command
78 mov dl, 1 ; Sector count (required by IdeTransfer.asm)
79 mov al, COMMAND_IDENTIFY_DEVICE
80 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_DRQ)
81 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
82
83 ; Clean stack and return
84 rcl al, 1 ; Store CF
85 add sp, BYTE SIZE_OF_FAKE_IDEPACK
86 rcr al, 1 ; Restore CF
87 pop bp
88 ret
89
90
91;--------------------------------------------------------------------
92; IdeCommand_OutputWithParameters
93; Parameters:
94; BH: System timer ticks for timeout
95; BL: IDE Status Register bit to poll after command
96; ES:SI: Ptr to buffer (for data transfer commands)
97; DS:DI: Ptr to DPT (in RAMVARS segment)
98; SS:BP: Ptr to IDEPACK
99; Returns:
100; AH: INT 13h Error Code
101; CF: Cleared if success, Set if error
102; Corrupts registers:
103; AL, BX, CX, DX, (ES:SI for data transfer commands)
104;--------------------------------------------------------------------
105ALIGN JUMP_ALIGN
106IdeCommand_OutputWithParameters:
107 push bx ; Store status register bits to poll
108
109 ; Select Master or Slave drive and output head number or LBA28 top bits
110 call IdeCommand_SelectDrive
111 jc SHORT .DriveNotReady
112
113 ; Output Device Control Byte to enable or disable interrupts
114 mov dl, DEVICE_CONTROL_REGISTER_out
115 mov al, [bp+IDEPACK.bDeviceControl]
116 call Device_OutputALtoIdeControlBlockRegisterInDL
117
118 ; Output Feature Number
119 mov dl, FEATURES_REGISTER_out
120 mov al, [bp+IDEPACK.bFeatures]
121 call Device_OutputALtoIdeRegisterInDL
122
123 ; Output Sector Address High (only used by LBA48)
124 mov ax, [bp+IDEPACK.wSectorCountHighAndLbaLowExt]
125 mov cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
126 call OutputSectorCountAndAddress
127
128 ; Output Sector Address Low
129 mov ax, [bp+IDEPACK.wSectorCountAndLbaLow]
130 mov cx, [bp+IDEPACK.wLbaMiddleAndHigh]
131 call OutputSectorCountAndAddress
132
133 ; Output command
134 mov dl, COMMAND_REGISTER_out
135 mov al, [bp+IDEPACK.bCommand]
136 call Device_OutputALtoIdeRegisterInDL
137
138 ; Wait until command completed
139 pop bx ; Pop status and timeout for polling
140 cmp bl, FLG_STATUS_DRQ ; Data transfer started?
141 je SHORT .StartDataTransfer
142 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
143 jz SHORT .WaitForIrqOrRdy
144 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
145
146ALIGN JUMP_ALIGN
147.WaitForIrqOrRdy:
148 jmp IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
149ALIGN JUMP_ALIGN
150.StartDataTransfer:
151 jmp IdeTransfer_StartWithCommandInAL
152
153.DriveNotReady:
154 pop bx ; Clean stack
155ReturnSinceTimeoutWhenPollingBusy:
156 ret
157
158
159;--------------------------------------------------------------------
160; IdeCommand_SelectDrive
161; Parameters:
162; DS:DI: Ptr to DPT (in RAMVARS segment)
163; SS:BP: Ptr to IDEPACK
164; Returns:
165; AH: INT 13h Error Code
166; CF: Cleared if success, Set if error
167; Corrupts registers:
168; AL, BX, CX, DX
169;--------------------------------------------------------------------
170ALIGN JUMP_ALIGN
171IdeCommand_SelectDrive:
172 ; Wait until neither Master or Slave Drive is busy
173 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
174 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
175 eCMOVE bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_BSY)
176 call IdeWait_PollStatusFlagInBLwithTimeoutInBH
177 jc SHORT ReturnSinceTimeoutWhenPollingBusy
178
179 ; Select Master or Slave Drive
180 mov dl, DRIVE_AND_HEAD_SELECT_REGISTER
181 mov al, [bp+IDEPACK.bDrvAndHead]
182 call Device_OutputALtoIdeRegisterInDL
183 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
184 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
185 eCMOVE bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_DRDY)
186 jmp IdeWait_PollStatusFlagInBLwithTimeoutInBH
187
188
189;--------------------------------------------------------------------
190; OutputSectorCountAndAddress
191; Parameters:
192; AH: LBA low bits (Sector Number)
193; AL: Sector Count
194; CL: LBA middle bits (Cylinder Number low)
195; CH: LBA high bits (Cylinder Number high)
196; DS:DI: Ptr to DPT (in RAMVARS segment)
197; Returns:
198; Nothing
199; Corrupts registers:
200; AL, BX, DX
201;--------------------------------------------------------------------
202ALIGN JUMP_ALIGN
203OutputSectorCountAndAddress:
204 mov dl, SECTOR_COUNT_REGISTER
205 call Device_OutputALtoIdeRegisterInDL
206
207 mov al, ah
208 mov dl, LBA_LOW_REGISTER
209 call Device_OutputALtoIdeRegisterInDL
210
211 mov al, cl
212 mov dl, LBA_MIDDLE_REGISTER
213 call Device_OutputALtoIdeRegisterInDL
214
215 mov al, ch
216 mov dl, LBA_HIGH_REGISTER
217 jmp Device_OutputALtoIdeRegisterInDL
Note: See TracBrowser for help on using the repository browser.