1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : IDE Device wait functions.
|
---|
3 |
|
---|
4 | ;
|
---|
5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
7 | ;
|
---|
8 | ; This program is free software; you can redistribute it and/or modify
|
---|
9 | ; it under the terms of the GNU General Public License as published by
|
---|
10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
11 | ; (at your option) any later version.
|
---|
12 | ;
|
---|
13 | ; This program is distributed in the hope that it will be useful,
|
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
18 | ;
|
---|
19 |
|
---|
20 | ; Section containing code
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ; IdeWait_IRQorDRQ
|
---|
25 | ; Parameters:
|
---|
26 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
27 | ; SS:BP: Ptr to IDEPACK, PIOVARS or MEMPIOVARS
|
---|
28 | ; Returns:
|
---|
29 | ; AH: INT 13h Error Code
|
---|
30 | ; CF: Cleared if success, Set if error
|
---|
31 | ; Corrupts registers:
|
---|
32 | ; AL, BX, CX, DX
|
---|
33 | ;--------------------------------------------------------------------
|
---|
34 | IDEDEVICE%+Wait_IRQorDRQ:
|
---|
35 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
|
---|
36 | %ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
|
---|
37 | test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
|
---|
38 | jnz SHORT IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
|
---|
39 | %endif
|
---|
40 | ; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
41 |
|
---|
42 |
|
---|
43 | ;--------------------------------------------------------------------
|
---|
44 | ; IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
45 | ; Parameters:
|
---|
46 | ; BH: Timeout ticks
|
---|
47 | ; BL: IDE Status Register bit to wait
|
---|
48 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
49 | ; Returns:
|
---|
50 | ; AH: INT 13h Error Code
|
---|
51 | ; CF: Cleared if success, Set if error
|
---|
52 | ; Corrupts registers:
|
---|
53 | ; AL, BX, CX, DX
|
---|
54 | ;--------------------------------------------------------------------
|
---|
55 | IDEDEVICE%+Wait_IRQorStatusFlagInBLwithTimeoutInBH:
|
---|
56 | %ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS ; JR-IDE/ISA does not support IRQ
|
---|
57 | %ifdef MODULE_IRQ
|
---|
58 | call IdeIrq_WaitForIRQ
|
---|
59 | %endif
|
---|
60 | %endif
|
---|
61 | ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
|
---|
62 |
|
---|
63 |
|
---|
64 | ;--------------------------------------------------------------------
|
---|
65 | ; IdeWait_PollStatusFlagInBLwithTimeoutInBH
|
---|
66 | ; Parameters:
|
---|
67 | ; BH: Timeout ticks
|
---|
68 | ; BL: IDE Status Register bit to poll
|
---|
69 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
70 | ; Returns:
|
---|
71 | ; AH: INT 13h Error Code
|
---|
72 | ; CF: Cleared if success, Set if error
|
---|
73 | ; Corrupts registers:
|
---|
74 | ; AL, BX, CX, DX
|
---|
75 | ;--------------------------------------------------------------------
|
---|
76 | IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH:
|
---|
77 | mov ah, bl
|
---|
78 | mov cl, bh
|
---|
79 | call Timer_InitializeTimeoutWithTicksInCL
|
---|
80 | and ah, ~FLG_STATUS_BSY
|
---|
81 | jz SHORT IDEDEVICE%+PollBsyOnly
|
---|
82 | ; Fall to PollBsyAndFlgInAH
|
---|
83 |
|
---|
84 | ;--------------------------------------------------------------------
|
---|
85 | ; PollBsyAndFlgInAH
|
---|
86 | ; Parameters:
|
---|
87 | ; AH: Status Register Flag to poll (until set) when device not busy
|
---|
88 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
89 | ; Returns:
|
---|
90 | ; AH: BIOS Error code
|
---|
91 | ; CF: Clear if wait completed successfully (no errors)
|
---|
92 | ; Set if any error
|
---|
93 | ; Corrupts registers:
|
---|
94 | ; AL, BX, CX, DX
|
---|
95 | ;--------------------------------------------------------------------
|
---|
96 | IDEDEVICE%+PollBsyAndFlgInAH:
|
---|
97 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
|
---|
98 | ALIGN JUMP_ALIGN
|
---|
99 | .PollLoop:
|
---|
100 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
|
---|
101 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
102 | jnz SHORT .UpdateTimeout ; If so, jump to timeout update
|
---|
103 | test al, ah ; Test secondary flag
|
---|
104 | jnz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
105 | .UpdateTimeout:
|
---|
106 | call Timer_SetCFifTimeout
|
---|
107 | jnc SHORT .PollLoop ; Loop if time left
|
---|
108 | call IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
109 | jc SHORT .ReturnErrorCodeInAH
|
---|
110 | mov ah, RET_HD_TIMEOUT ; Expected bit never got set
|
---|
111 | stc
|
---|
112 | .ReturnErrorCodeInAH:
|
---|
113 | ret
|
---|
114 |
|
---|
115 |
|
---|
116 | ;--------------------------------------------------------------------
|
---|
117 | ; PollBsyOnly
|
---|
118 | ; Parameters:
|
---|
119 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
120 | ; Returns:
|
---|
121 | ; AH: BIOS Error code
|
---|
122 | ; CF: Clear if wait completed successfully (no errors)
|
---|
123 | ; Set if any error
|
---|
124 | ; Corrupts registers:
|
---|
125 | ; AL, BX, CX, DX
|
---|
126 | ;--------------------------------------------------------------------
|
---|
127 | IDEDEVICE%+PollBsyOnly:
|
---|
128 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in ; Discard contents for first read
|
---|
129 | ALIGN JUMP_ALIGN
|
---|
130 | .PollLoop:
|
---|
131 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
|
---|
132 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
133 | jz SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
134 | call Timer_SetCFifTimeout ; Update timeout counter
|
---|
135 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
|
---|
136 | jmp SHORT IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|