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

Last change on this file since 241 was 238, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Makefile now builds small (8k) and large versions.
  • Completely untested support for JR-IDE/ISA.
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;--------------------------------------------------------------------
17IDEDEVICE%+Command_ResetMasterAndSlaveController:
18 ; HSR0: Set_SRST
19 call AccessDPT_GetDeviceControlByteToAL
20 or al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN ; Set Reset bit
21 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
22 mov ax, HSR0_RESET_WAIT_US
23 call Timer_DelayMicrosecondsFromAX
24
25 ; HSR1: Clear_wait
26 call AccessDPT_GetDeviceControlByteToAL
27 or al, FLG_DEVCONTROL_nIEN
28 and al, ~FLG_DEVCONTROL_SRST ; Clear reset bit
29 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
30 mov ax, HSR1_RESET_WAIT_US
31 call Timer_DelayMicrosecondsFromAX
32
33 ; HSR2: Check_status
34 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
35 jmp IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
36
37
38;--------------------------------------------------------------------
39; IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
40; Parameters:
41; BH: Drive Select byte for Drive and Head Select Register
42; DS: Segment to RAMVARS
43; ES:SI: Ptr to buffer to receive 512-byte IDE Information
44; CS:BP: Ptr to IDEVARS
45; Returns:
46; AH: INT 13h Error Code
47; CF: Cleared if success, Set if error
48; Corrupts registers:
49; AL, BL, CX, DX, SI, DI, ES
50;--------------------------------------------------------------------
51IDEDEVICE%+Command_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH:
52 ; Create fake DPT to be able to use Device.asm functions
53 call FindDPT_ForNewDriveToDSDI
54 eMOVZX ax, bh
55 mov [di+DPT.wFlags], ax
56 mov [di+DPT.bIdevarsOffset], bp
57 mov BYTE [di+DPT_ATA.bSetBlock], 1 ; Block = 1 sector
58 call IdeDPT_StoreReversedAddressLinesFlagIfNecessary
59
60 ; Wait until drive motors have reached max speed
61 cmp bp, BYTE ROMVARS.ideVars0
62 jne SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
63 test al, FLG_DRVNHEAD_DRV
64 jnz SHORT .SkipLongWaitSinceDriveIsNotPrimaryMaster
65 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_MOTOR_STARTUP, FLG_STATUS_BSY)
66 call IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
67.SkipLongWaitSinceDriveIsNotPrimaryMaster:
68
69 ; Create IDEPACK without INTPACK
70 push bp
71 call Idepack_FakeToSSBP
72
73 ; Prepare to output Identify Device command
74 mov dl, 1 ; Sector count (required by IdeTransfer.asm)
75 mov al, COMMAND_IDENTIFY_DEVICE
76 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_IDENTIFY_DEVICE, FLG_STATUS_DRQ)
77 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
78
79 ; Clean stack and return
80 lea sp, [bp+EXTRA_BYTES_FOR_INTPACK] ; This assumes BP hasn't changed between Idepack_FakeToSSBP and here
81 pop bp
82 ret
83
84
85;--------------------------------------------------------------------
86; IdeCommand_OutputWithParameters
87; Parameters:
88; BH: System timer ticks for timeout
89; BL: IDE Status Register bit to poll after command
90; ES:SI: Ptr to buffer (for data transfer commands)
91; DS:DI: Ptr to DPT (in RAMVARS segment)
92; SS:BP: Ptr to IDEPACK
93; Returns:
94; AH: INT 13h Error Code
95; CF: Cleared if success, Set if error
96; Corrupts registers:
97; AL, BX, CX, DX, (ES:SI for data transfer commands)
98;--------------------------------------------------------------------
99ALIGN JUMP_ALIGN
100IDEDEVICE%+Command_OutputWithParameters:
101 push bx ; Store status register bits to poll
102
103 ; Select Master or Slave drive and output head number or LBA28 top bits
104 call IDEDEVICE%+Command_SelectDrive
105 jc SHORT .DriveNotReady
106
107 ; Output Device Control Byte to enable or disable interrupts
108 mov al, [bp+IDEPACK.bDeviceControl]
109 test al, FLG_DEVCONTROL_nIEN ; Interrupts disabled?
110 jnz SHORT .DoNotSetInterruptInServiceFlag
111
112 ; Clear Task Flag and set Interrupt In-Service Flag
113 or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
114 push ds
115 LOAD_BDA_SEGMENT_TO ds, dx, ! ; Also zero DX
116 mov [BDA.bHDTaskFlg], dl
117 pop ds
118.DoNotSetInterruptInServiceFlag:
119 OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER DEVICE_CONTROL_REGISTER_out
120
121 ; Output Feature Number
122 mov al, [bp+IDEPACK.bFeatures]
123 OUTPUT_AL_TO_IDE_REGISTER FEATURES_REGISTER_out
124
125 ; Output Sector Address High (only used by LBA48)
126 eMOVZX ax, BYTE [bp+IDEPACK.bLbaLowExt]
127 mov cx, [bp+IDEPACK.wLbaMiddleAndHighExt]
128 call OutputSectorCountAndAddress
129
130 ; Output Sector Address Low
131 mov ax, [bp+IDEPACK.wSectorCountAndLbaLow]
132 mov cx, [bp+IDEPACK.wLbaMiddleAndHigh]
133 call OutputSectorCountAndAddress
134
135 ; Output command
136 mov al, [bp+IDEPACK.bCommand]
137 OUTPUT_AL_TO_IDE_REGISTER COMMAND_REGISTER_out
138
139 ; Wait until command completed
140 pop bx ; Pop status and timeout for polling
141 cmp bl, FLG_STATUS_DRQ ; Data transfer started?
142 je SHORT IDEDEVICE%+Transfer_StartWithCommandInAL
143 test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
144 jz SHORT .WaitForIrqOrRdy
145 jmp IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
146
147ALIGN JUMP_ALIGN
148.WaitForIrqOrRdy:
149 jmp IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH
150
151.DriveNotReady:
152 pop bx ; Clean stack
153IDEDEVICE%+ReturnSinceTimeoutWhenPollingBusy:
154 ret
155
156
157;--------------------------------------------------------------------
158; IdeCommand_SelectDrive
159; Parameters:
160; DS:DI: Ptr to DPT (in RAMVARS segment)
161; SS:BP: Ptr to IDEPACK
162; Returns:
163; AH: INT 13h Error Code
164; CF: Cleared if success, Set if error
165; Corrupts registers:
166; AL, BX, CX, DX
167;--------------------------------------------------------------------
168ALIGN JUMP_ALIGN
169IDEDEVICE%+Command_SelectDrive:
170 ; Wait until neither Master or Slave Drive is busy
171 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
172 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
173 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
174 call IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
175 jc SHORT IDEDEVICE%+ReturnSinceTimeoutWhenPollingBusy
176
177 ; Select Master or Slave Drive
178 mov al, [bp+IDEPACK.bDrvAndHead]
179 OUTPUT_AL_TO_IDE_REGISTER DRIVE_AND_HEAD_SELECT_REGISTER
180 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
181 cmp BYTE [bp+IDEPACK.bCommand], COMMAND_IDENTIFY_DEVICE
182 eCMOVE bh, TIMEOUT_IDENTIFY_DEVICE
183 jmp IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
184
185
186;--------------------------------------------------------------------
187; OutputSectorCountAndAddress
188; Parameters:
189; AH: LBA low bits (Sector Number)
190; AL: Sector Count
191; CL: LBA middle bits (Cylinder Number low)
192; CH: LBA high bits (Cylinder Number high)
193; DS:DI: Ptr to DPT (in RAMVARS segment)
194; Returns:
195; Nothing
196; Corrupts registers:
197; AL, BX, DX
198;--------------------------------------------------------------------
199%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
200ALIGN JUMP_ALIGN
201OutputSectorCountAndAddress:
202 OUTPUT_AL_TO_IDE_REGISTER SECTOR_COUNT_REGISTER
203
204 mov al, ah
205 OUTPUT_AL_TO_IDE_REGISTER LBA_LOW_REGISTER
206
207 mov al, cl
208 OUTPUT_AL_TO_IDE_REGISTER LBA_MIDDLE_REGISTER
209
210 mov al, ch
211 JUMP_TO_OUTPUT_AL_TO_IDE_REGISTER LBA_HIGH_REGISTER
212%endif
Note: See TracBrowser for help on using the repository browser.