1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : IDE Device wait functions.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; IdeWait_IRQorDRQ
|
---|
9 | ; Parameters:
|
---|
10 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
11 | ; SS:BP: Ptr to IDEPACK or PIOVARS
|
---|
12 | ; Returns:
|
---|
13 | ; AH: INT 13h Error Code
|
---|
14 | ; CF: Cleared if success, Set if error
|
---|
15 | ; Corrupts registers:
|
---|
16 | ; AL, BX, CX, DX
|
---|
17 | ;--------------------------------------------------------------------
|
---|
18 | IdeWait_IRQorDRQ:
|
---|
19 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
|
---|
20 | test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
|
---|
21 | jnz SHORT IdeWait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
|
---|
22 | ; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
23 |
|
---|
24 |
|
---|
25 | ;--------------------------------------------------------------------
|
---|
26 | ; IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
27 | ; Parameters:
|
---|
28 | ; BH: Timeout ticks
|
---|
29 | ; BL: IDE Status Register bit to wait
|
---|
30 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
31 | ; Returns:
|
---|
32 | ; AH: INT 13h Error Code
|
---|
33 | ; CF: Cleared if success, Set if error
|
---|
34 | ; Corrupts registers:
|
---|
35 | ; AL, BX, CX, DX
|
---|
36 | ;--------------------------------------------------------------------
|
---|
37 | IdeWait_IRQorStatusFlagInBLwithTimeoutInBH:
|
---|
38 | call IdeIrq_WaitForIRQ
|
---|
39 | ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
|
---|
40 |
|
---|
41 |
|
---|
42 | ;--------------------------------------------------------------------
|
---|
43 | ; IdeWait_PollStatusFlagInBLwithTimeoutInBH
|
---|
44 | ; Parameters:
|
---|
45 | ; BH: Timeout ticks
|
---|
46 | ; BL: IDE Status Register bit to poll
|
---|
47 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
48 | ; Returns:
|
---|
49 | ; AH: INT 13h Error Code
|
---|
50 | ; CF: Cleared if success, Set if error
|
---|
51 | ; Corrupts registers:
|
---|
52 | ; AL, BX, CX, DX
|
---|
53 | ;--------------------------------------------------------------------
|
---|
54 | IdeWait_PollStatusFlagInBLwithTimeoutInBH:
|
---|
55 | mov ah, bl
|
---|
56 | mov cl, bh
|
---|
57 | call Timer_InitializeTimeoutWithTicksInCL
|
---|
58 | and ah, ~FLG_STATUS_BSY
|
---|
59 | jz SHORT PollBsyOnly
|
---|
60 | ; Fall to PollBsyAndFlgInAH
|
---|
61 |
|
---|
62 | ;--------------------------------------------------------------------
|
---|
63 | ; PollBsyAndFlgInAH
|
---|
64 | ; Parameters:
|
---|
65 | ; AH: Status Register Flag to poll (until set) when device not busy
|
---|
66 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
67 | ; Returns:
|
---|
68 | ; AH: BIOS Error code
|
---|
69 | ; CF: Clear if wait completed successfully (no errors)
|
---|
70 | ; Set if any error
|
---|
71 | ; Corrupts registers:
|
---|
72 | ; AL, BX, CX, DX
|
---|
73 | ;--------------------------------------------------------------------
|
---|
74 | PollBsyAndFlgInAH:
|
---|
75 | call ReadIdeStatusRegisterToAL ; Discard contents for first read
|
---|
76 | ALIGN JUMP_ALIGN
|
---|
77 | .PollLoop:
|
---|
78 | call ReadIdeStatusRegisterToAL
|
---|
79 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
80 | jnz SHORT .UpdateTimeout ; If so, jump to timeout update
|
---|
81 | test al, ah ; Test secondary flag
|
---|
82 | jnz SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
83 | .UpdateTimeout:
|
---|
84 | call Timer_SetCFifTimeout
|
---|
85 | jnc SHORT .PollLoop ; Loop if time left
|
---|
86 | call IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
87 | jc SHORT .ReturnErrorCodeInAH
|
---|
88 | mov ah, RET_HD_TIMEOUT ; Expected bit never got set
|
---|
89 | stc
|
---|
90 | .ReturnErrorCodeInAH:
|
---|
91 | ret
|
---|
92 |
|
---|
93 |
|
---|
94 | ;--------------------------------------------------------------------
|
---|
95 | ; PollBsyOnly
|
---|
96 | ; Parameters:
|
---|
97 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
98 | ; Returns:
|
---|
99 | ; AH: BIOS Error code
|
---|
100 | ; CF: Clear if wait completed successfully (no errors)
|
---|
101 | ; Set if any error
|
---|
102 | ; Corrupts registers:
|
---|
103 | ; AL, BX, CX, DX
|
---|
104 | ;--------------------------------------------------------------------
|
---|
105 | PollBsyOnly:
|
---|
106 | call ReadIdeStatusRegisterToAL ; Discard contents for first read
|
---|
107 | ALIGN JUMP_ALIGN
|
---|
108 | .PollLoop:
|
---|
109 | call ReadIdeStatusRegisterToAL
|
---|
110 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
111 | jz SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
112 | call Timer_SetCFifTimeout ; Update timeout counter
|
---|
113 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
|
---|
114 | jmp SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
115 |
|
---|
116 |
|
---|
117 | ;--------------------------------------------------------------------
|
---|
118 | ; ReadIdeStatusRegisterToAL
|
---|
119 | ; Parameters:
|
---|
120 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
121 | ; Returns:
|
---|
122 | ; AL: IDE Status Register contents
|
---|
123 | ; Corrupts registers:
|
---|
124 | ; BX, DX
|
---|
125 | ;--------------------------------------------------------------------
|
---|
126 | ALIGN JUMP_ALIGN
|
---|
127 | ReadIdeStatusRegisterToAL:
|
---|
128 | mov dl, STATUS_REGISTER_in
|
---|
129 | jmp IdeIO_InputToALfromIdeRegisterInDL
|
---|