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