[88] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : IDE Status Register polling functions. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Waits Hard Disk IRQ when not transferring data. |
---|
| 9 | ; If interrupts are disabled, RDY flag is polled. |
---|
| 10 | ; |
---|
| 11 | ; HStatus_WaitIrqOrRdy |
---|
| 12 | ; Parameters: |
---|
| 13 | ; DS:BX: Ptr to DPT |
---|
| 14 | ; Returns: |
---|
| 15 | ; AH: BIOS Error code |
---|
| 16 | ; CF: 0 if wait succesfull |
---|
| 17 | ; 1 if any error |
---|
| 18 | ; Corrupts registers: |
---|
| 19 | ; AL, CX, DX |
---|
| 20 | ;-------------------------------------------------------------------- |
---|
| 21 | ALIGN JUMP_ALIGN |
---|
| 22 | HStatus_WaitIrqOrRdy: |
---|
[34] | 23 | call HIRQ_WaitForIRQ |
---|
| 24 | jnc SHORT .PollRdySinceNoWaitingOnOsHook |
---|
| 25 | jmp HError_ProcessErrorsAfterPollingBSY |
---|
[28] | 26 | |
---|
[10] | 27 | ALIGN JUMP_ALIGN |
---|
[34] | 28 | .PollRdySinceNoWaitingOnOsHook: |
---|
[3] | 29 | mov cl, B_TIMEOUT_DRQ ; Load DRQ (not RDY) timeout |
---|
| 30 | jmp SHORT HStatus_WaitRdy ; Jump to poll RDY |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | ;-------------------------------------------------------------------- |
---|
| 34 | ; Waits until Hard Disk is ready to transfer data. |
---|
| 35 | ; |
---|
| 36 | ; HStatus_WaitIrqOrDrq |
---|
| 37 | ; Parameters: |
---|
| 38 | ; DS:BX: Ptr to DPT (in RAMVARS segment) |
---|
| 39 | ; Returns: |
---|
| 40 | ; AH: BIOS Error code |
---|
| 41 | ; CF: 0 if wait succesfull |
---|
| 42 | ; 1 if any error |
---|
| 43 | ; Corrupts registers: |
---|
| 44 | ; AL |
---|
| 45 | ;-------------------------------------------------------------------- |
---|
| 46 | ALIGN JUMP_ALIGN |
---|
| 47 | HStatus_WaitIrqOrDrq: |
---|
[34] | 48 | call HIRQ_WaitForIRQ |
---|
| 49 | jnc SHORT .PollDrqSinceNoWaitingOnOsHook |
---|
| 50 | jmp HError_ProcessErrorsAfterPollingBSY |
---|
[3] | 51 | |
---|
| 52 | ALIGN JUMP_ALIGN |
---|
[34] | 53 | .PollDrqSinceNoWaitingOnOsHook: |
---|
[28] | 54 | push dx |
---|
| 55 | push cx |
---|
[3] | 56 | call HStatus_WaitDrqDefTime |
---|
| 57 | pop cx |
---|
| 58 | pop dx |
---|
| 59 | ret |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | ;-------------------------------------------------------------------- |
---|
| 63 | ; Waits until busy flag is cleared from selected Hard Disk drive. |
---|
| 64 | ; |
---|
| 65 | ; HStatus_WaitBsyDefTime Uses default timeout |
---|
| 66 | ; HStatus_WaitBsy Uses user defined timeout |
---|
| 67 | ; HStatus_WaitBsyBase Uses user base port address and timeout |
---|
| 68 | ; Parameters: |
---|
| 69 | ; CL: Timeout value in system timer ticks (not HStatus_WaitBsyDefTime) |
---|
| 70 | ; DX: IDE Base port address (HUtil_WaitBsyBase only) |
---|
| 71 | ; DS: Segment to RAMVARS |
---|
| 72 | ; Returns: |
---|
| 73 | ; AH: BIOS Error code |
---|
| 74 | ; DX: IDE Status Register Address |
---|
| 75 | ; CF: 0 if wait succesfull |
---|
| 76 | ; 1 if any error |
---|
| 77 | ; Corrupts registers: |
---|
| 78 | ; AL, CX |
---|
| 79 | ;-------------------------------------------------------------------- |
---|
| 80 | ALIGN JUMP_ALIGN |
---|
| 81 | HStatus_WaitBsyDefTime: |
---|
| 82 | mov cl, B_TIMEOUT_BSY ; Load timeout value |
---|
| 83 | ALIGN JUMP_ALIGN |
---|
| 84 | HStatus_WaitBsy: |
---|
| 85 | mov dx, [RAMVARS.wIdeBase] ; Load offset to base port |
---|
| 86 | ALIGN JUMP_ALIGN |
---|
| 87 | HStatus_WaitBsyBase: |
---|
| 88 | add dx, BYTE REGR_IDE_ST ; Add offset to status reg |
---|
| 89 | jmp SHORT HStatus_PollBsy ; Wait until not busy |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | ;-------------------------------------------------------------------- |
---|
| 93 | ; Waits until Hard Disk is ready to accept commands. |
---|
| 94 | ; |
---|
| 95 | ; HStatus_WaitRdyDefTime Uses default timeout |
---|
| 96 | ; HStatus_WaitRdy Uses user defined timeout |
---|
| 97 | ; HStatus_WaitRdyBase Uses user base port address and timeout |
---|
| 98 | ; Parameters: |
---|
| 99 | ; CL: Timeout value in system timer ticks (not HStatus_WaitRdyDefTime) |
---|
| 100 | ; DX: IDE Base port address (HStatus_WaitRdyBase only) |
---|
| 101 | ; DS: Segment to RAMVARS |
---|
| 102 | ; Returns: |
---|
| 103 | ; AH: BIOS Error code |
---|
| 104 | ; DX: IDE Status Register Address |
---|
| 105 | ; CF: 0 if wait succesfull |
---|
| 106 | ; 1 if any error |
---|
| 107 | ; Corrupts registers: |
---|
| 108 | ; AL, CX |
---|
| 109 | ;-------------------------------------------------------------------- |
---|
| 110 | ALIGN JUMP_ALIGN |
---|
| 111 | HStatus_WaitRdyDefTime: |
---|
| 112 | mov cl, B_TIMEOUT_RDY ; Load timeout value |
---|
| 113 | ALIGN JUMP_ALIGN |
---|
| 114 | HStatus_WaitRdy: |
---|
| 115 | mov dx, [RAMVARS.wIdeBase] ; Load offset to base port |
---|
| 116 | ALIGN JUMP_ALIGN |
---|
| 117 | HStatus_WaitRdyBase: |
---|
| 118 | add dx, BYTE REGR_IDE_ST ; Add offset to status reg |
---|
| 119 | mov ah, FLG_IDE_ST_DRDY ; Flag to poll |
---|
| 120 | jmp SHORT HStatus_PollBsyAndFlg ; Wait until flag set |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | ;-------------------------------------------------------------------- |
---|
| 124 | ; Waits until Hard Disk is ready to transfer data. |
---|
| 125 | ; Note! This function polls DRQ even if interrupts are enabled! |
---|
| 126 | ; |
---|
| 127 | ; HStatus_WaitDrqDefTime Uses default timeout |
---|
| 128 | ; HStatus_WaitDrq Uses user defined timeout |
---|
| 129 | ; HStatus_WaitDrqBase Uses user base port address and timeout |
---|
| 130 | ; Parameters: |
---|
| 131 | ; CL: Timeout value in system timer ticks (not HStatus_WaitDrqDefTime) |
---|
| 132 | ; DX: IDE Base port address (HStatus_WaitDrqBase only) |
---|
| 133 | ; DS: Segment to RAMVARS |
---|
| 134 | ; Returns: |
---|
| 135 | ; AH: BIOS Error code |
---|
| 136 | ; DX: IDE Status Register Address |
---|
| 137 | ; CF: 0 if wait succesfull |
---|
| 138 | ; 1 if any error |
---|
| 139 | ; Corrupts registers: |
---|
| 140 | ; AL, CX |
---|
| 141 | ;-------------------------------------------------------------------- |
---|
| 142 | ALIGN JUMP_ALIGN |
---|
| 143 | HStatus_WaitDrqDefTime: |
---|
| 144 | mov cl, B_TIMEOUT_DRQ ; Load timeout value |
---|
| 145 | ALIGN JUMP_ALIGN |
---|
| 146 | HStatus_WaitDrq: |
---|
| 147 | mov dx, [RAMVARS.wIdeBase] ; Load offset to base port |
---|
| 148 | ALIGN JUMP_ALIGN |
---|
| 149 | HStatus_WaitDrqBase: |
---|
| 150 | add dx, BYTE REGR_IDE_ST ; Add offset to status reg |
---|
| 151 | mov ah, FLG_IDE_ST_DRQ ; Flag to poll |
---|
| 152 | ; Fall to HStatus_PollBsyAndFlg |
---|
| 153 | |
---|
| 154 | ;-------------------------------------------------------------------- |
---|
| 155 | ; IDE Status register polling. |
---|
| 156 | ; This function first waits until controller is not busy. |
---|
[27] | 157 | ; When not busy, IDE Status Register is polled until wanted flag is set. |
---|
[3] | 158 | ; |
---|
| 159 | ; HStatus_PollBusyAndFlg |
---|
| 160 | ; Parameters: |
---|
| 161 | ; AH: Status Register Flag to poll (until set) when not busy |
---|
| 162 | ; CL: Timeout value in system timer ticks |
---|
| 163 | ; DX: IDE Status Register Address |
---|
| 164 | ; DS: Segment to RAMVARS |
---|
| 165 | ; Returns: |
---|
| 166 | ; AH: BIOS Error code |
---|
| 167 | ; CF: Clear if wait completed successfully (no errors) |
---|
| 168 | ; Set if any error |
---|
| 169 | ; Corrupts registers: |
---|
| 170 | ; AL, CX |
---|
| 171 | ;-------------------------------------------------------------------- |
---|
| 172 | ALIGN JUMP_ALIGN |
---|
| 173 | HStatus_PollBsyAndFlg: |
---|
[88] | 174 | call InitializeTimeoutWithTicksInCL ; Initialize timeout counter |
---|
[28] | 175 | in al, dx ; Discard contents for first read |
---|
| 176 | ; (should read Alternate Status Register) |
---|
[3] | 177 | ALIGN JUMP_ALIGN |
---|
| 178 | .PollLoop: |
---|
[27] | 179 | in al, dx ; Load IDE Status Register |
---|
| 180 | test al, FLG_IDE_ST_BSY ; Controller busy? |
---|
| 181 | jnz SHORT .UpdateTimeout ; If so, jump to timeout update |
---|
| 182 | test al, ah ; Test secondary flag |
---|
| 183 | jnz SHORT GetErrorCodeFromPollingToAH ; If set, break loop |
---|
[3] | 184 | ALIGN JUMP_ALIGN |
---|
| 185 | .UpdateTimeout: |
---|
[88] | 186 | call SetCFifTimeout |
---|
[27] | 187 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout) |
---|
[28] | 188 | jmp HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit |
---|
[3] | 189 | |
---|
| 190 | ;-------------------------------------------------------------------- |
---|
| 191 | ; IDE Status register polling. |
---|
| 192 | ; This function waits until controller is not busy. |
---|
| 193 | ; |
---|
| 194 | ; HStatus_PollBsy |
---|
| 195 | ; Parameters: |
---|
| 196 | ; CL: Timeout value in system timer ticks |
---|
| 197 | ; DX: IDE Status Register Address |
---|
| 198 | ; DS: Segment to RAMVARS |
---|
| 199 | ; Returns: |
---|
| 200 | ; AH: BIOS Error code |
---|
| 201 | ; CF: Clear if wait completed successfully (no errors) |
---|
| 202 | ; Set if any error |
---|
| 203 | ; Corrupts registers: |
---|
| 204 | ; AL, CX |
---|
| 205 | ;-------------------------------------------------------------------- |
---|
| 206 | ALIGN JUMP_ALIGN |
---|
| 207 | HStatus_PollBsy: |
---|
[88] | 208 | call InitializeTimeoutWithTicksInCL ; Initialize timeout counter |
---|
[28] | 209 | in al, dx ; Discard contents for first read |
---|
| 210 | ; (should read Alternate Status Register) |
---|
[3] | 211 | ALIGN JUMP_ALIGN |
---|
| 212 | .PollLoop: |
---|
[27] | 213 | in al, dx ; Load IDE Status Reg |
---|
| 214 | test al, FLG_IDE_ST_BSY ; Controller busy? |
---|
| 215 | jz SHORT GetErrorCodeFromPollingToAH ; If not, jump to check errors |
---|
[88] | 216 | call SetCFifTimeout ; Update timeout counter |
---|
[27] | 217 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout) |
---|
[3] | 218 | ALIGN JUMP_ALIGN |
---|
[27] | 219 | GetErrorCodeFromPollingToAH: |
---|
[28] | 220 | jmp HError_ProcessErrorsAfterPollingBSY |
---|
[88] | 221 | |
---|
| 222 | |
---|
| 223 | ;-------------------------------------------------------------------- |
---|
| 224 | ; InitializeTimeoutWithTicksInCL |
---|
| 225 | ; Parameters: |
---|
| 226 | ; CL: Timeout value in system timer ticks |
---|
| 227 | ; DS: Segment to RAMVARS |
---|
| 228 | ; Returns: |
---|
| 229 | ; Nothing |
---|
| 230 | ; Corrupts registers: |
---|
| 231 | ; CX |
---|
| 232 | ;-------------------------------------------------------------------- |
---|
| 233 | ALIGN JUMP_ALIGN |
---|
| 234 | InitializeTimeoutWithTicksInCL: |
---|
| 235 | push bx |
---|
| 236 | xchg cx, ax |
---|
| 237 | |
---|
| 238 | xor ah, ah ; Timeout ticks now in AX |
---|
| 239 | mov bx, RAMVARS.wTimeoutCounter |
---|
| 240 | call TimerTicks_InitializeTimeoutFromAX |
---|
| 241 | |
---|
| 242 | xchg ax, cx ; Restore AX |
---|
| 243 | pop bx |
---|
| 244 | ret |
---|
| 245 | |
---|
| 246 | ;-------------------------------------------------------------------- |
---|
| 247 | ; SetCFifTimeout |
---|
| 248 | ; Parameters: |
---|
| 249 | ; DS: Segment to RAMVARS |
---|
| 250 | ; Returns: |
---|
| 251 | ; Nothing |
---|
| 252 | ; Corrupts registers: |
---|
| 253 | ; CX |
---|
| 254 | ;-------------------------------------------------------------------- |
---|
| 255 | ALIGN JUMP_ALIGN |
---|
| 256 | SetCFifTimeout: |
---|
| 257 | push bx |
---|
| 258 | xchg cx, ax |
---|
| 259 | |
---|
| 260 | mov bx, RAMVARS.wTimeoutCounter |
---|
| 261 | call TimerTicks_GetTimeoutTicksLeftToAXfromDSBX |
---|
| 262 | |
---|
| 263 | xchg ax, cx ; Restore AX |
---|
| 264 | pop bx |
---|
| 265 | ret |
---|