1 | ; Project name : XTIDE Universal BIOS Configurator v2
|
---|
2 | ; Description : Functions to detect ports and devices.
|
---|
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 | ; IdeAutodetect_DetectIdeDeviceFromPortDX
|
---|
25 | ; Parameters:
|
---|
26 | ; DX: IDE Base Port
|
---|
27 | ; DS:DI: Ptr to ROMVARS
|
---|
28 | ; Returns:
|
---|
29 | ; AL: Device Type
|
---|
30 | ; CF: Clear if IDE Device found
|
---|
31 | ; Set if IDE Device not found
|
---|
32 | ; Corrupts registers:
|
---|
33 | ; AH, BX, CX
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | IdeAutodetect_DetectIdeDeviceFromPortDX:
|
---|
36 | cmp dx, FIRST_MEMORY_SEGMENT_ADDRESS
|
---|
37 | jb SHORT .DetectPortMappedDevices
|
---|
38 |
|
---|
39 | ; Try to detect JR-IDE/ISA (only if MODULE_8BIT_IDE_ADVANCED is present)
|
---|
40 | test WORD [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
|
---|
41 | jz SHORT .SkipRestOfDetection
|
---|
42 |
|
---|
43 | push ds
|
---|
44 | mov ds, dx
|
---|
45 | cli ; Disable Interrupts
|
---|
46 | mov ah, [JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET + STATUS_REGISTER_in]
|
---|
47 | mov al, [JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET + ALTERNATE_STATUS_REGISTER_in]
|
---|
48 | sti ; Enable Interrupts
|
---|
49 | pop ds
|
---|
50 | call CompareIdeStatusRegistersFromALandAH
|
---|
51 | mov al, DEVICE_8BIT_JRIDE_ISA
|
---|
52 | ret
|
---|
53 | .DetectPortMappedDevices:
|
---|
54 |
|
---|
55 |
|
---|
56 | ; Try to detect Standard 16- and 32-bit IDE Devices
|
---|
57 | mov bh, DEVICE_16BIT_ATA ; Assume 16-bit ISA slot for AT builds
|
---|
58 | call Buffers_IsXTbuildLoaded
|
---|
59 | eCMOVE bh, DEVICE_8BIT_ATA ; Assume 8-bit ISA slot for XT builds
|
---|
60 | mov bl, STATUS_REGISTER_in
|
---|
61 | mov cx, STANDARD_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in
|
---|
62 | call DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
|
---|
63 | mov al, bh
|
---|
64 | jnc SHORT .IdeDeviceFound
|
---|
65 |
|
---|
66 |
|
---|
67 | ; Detect 8-bit devices only if MODULE_8BIT_IDE is available
|
---|
68 | test BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE
|
---|
69 | jz SHORT .SkipRestOfDetection
|
---|
70 |
|
---|
71 | ; Try to detect XT-CF
|
---|
72 | mov bl, STATUS_REGISTER_in << 1
|
---|
73 | mov cx, (XTIDE_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in) << 1
|
---|
74 | call DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
|
---|
75 | mov al, DEVICE_8BIT_XTCF_PIO8
|
---|
76 | jnc SHORT .IdeDeviceFound
|
---|
77 |
|
---|
78 | ; Try to detect 8-bit XT-IDE rev 1
|
---|
79 | shr cx, 1
|
---|
80 | call DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
|
---|
81 | mov al, DEVICE_8BIT_XTIDE_REV1
|
---|
82 | jnc SHORT .IdeDeviceFound
|
---|
83 |
|
---|
84 | ; Try to detect 8-bit XT-IDE rev 2 or modded rev 1
|
---|
85 | ; This doesn't actually work since Status Register and Alternative
|
---|
86 | ; Status Register swap place!!!
|
---|
87 | mov bl, 1110b ; STATUS_REGISTER_in with A0 and A3 swapped
|
---|
88 | mov cl, 0111b
|
---|
89 | call DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
|
---|
90 | mov al, DEVICE_8BIT_XTIDE_REV2
|
---|
91 | .IdeDeviceFound:
|
---|
92 | ret
|
---|
93 | .SkipRestOfDetection:
|
---|
94 | stc
|
---|
95 | ret
|
---|
96 |
|
---|
97 |
|
---|
98 | ;--------------------------------------------------------------------
|
---|
99 | ; DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
|
---|
100 | ; Parameters:
|
---|
101 | ; BL: Offset to IDE Status Register
|
---|
102 | ; CX: Offset to Alternative Status Register
|
---|
103 | ; DX: IDE Base Port
|
---|
104 | ; Returns:
|
---|
105 | ; CF: Clear if IDE Device found
|
---|
106 | ; Set if IDE Device not found
|
---|
107 | ; Corrupts registers:
|
---|
108 | ; AX
|
---|
109 | ;--------------------------------------------------------------------
|
---|
110 | DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX:
|
---|
111 | ; Read Status and Alternative Status Registers
|
---|
112 | push cx
|
---|
113 | push dx
|
---|
114 |
|
---|
115 | add cx, dx ; CX = Address to Alternative Status Register
|
---|
116 | add dl, bl ; DX = Address to Status Register
|
---|
117 | cli ; Disable Interrupts
|
---|
118 | in al, dx ; Read Status Register
|
---|
119 | mov ah, al
|
---|
120 | mov dx, cx
|
---|
121 | in al, dx ; Read Alternative Status Register
|
---|
122 | sti ; Enable Interrupts
|
---|
123 |
|
---|
124 | pop dx
|
---|
125 | pop cx
|
---|
126 | ; Fall to CompareIdeStatusRegistersFromALandAH
|
---|
127 |
|
---|
128 |
|
---|
129 | ;--------------------------------------------------------------------
|
---|
130 | ; CompareIdeStatusRegistersFromALandAH
|
---|
131 | ; Parameters:
|
---|
132 | ; AL: Possible IDE Status Register contents
|
---|
133 | ; AH: Possible IDE Alternative Status Register contents
|
---|
134 | ; Returns:
|
---|
135 | ; CF: Clear if valid Status Register Contents
|
---|
136 | ; Set if not possible IDE Status Registers
|
---|
137 | ; Corrupts registers:
|
---|
138 | ; Nothing
|
---|
139 | ;--------------------------------------------------------------------
|
---|
140 | CompareIdeStatusRegistersFromALandAH:
|
---|
141 | ; Status Register now in AH and Alternative Status Register in AL.
|
---|
142 | ; They must be the same if base port was in use by IDE device.
|
---|
143 | cmp al, ah
|
---|
144 | jne SHORT .InvalidStatusRegister
|
---|
145 |
|
---|
146 | ; Bytes were the same but it is possible they were both FFh, for
|
---|
147 | ; example. We must make sure bit are what is expected from valid
|
---|
148 | ; IDE Status Register.
|
---|
149 | test al, FLG_STATUS_BSY | FLG_STATUS_DF | FLG_STATUS_DRQ | FLG_STATUS_ERR
|
---|
150 | jnz SHORT .InvalidStatusRegister ; Busy or Errors cannot be set
|
---|
151 | test al, FLG_STATUS_DRDY
|
---|
152 | jz SHORT .InvalidStatusRegister ; Device needs to be ready
|
---|
153 | ret ; Return with CF cleared
|
---|
154 |
|
---|
155 | .InvalidStatusRegister:
|
---|
156 | AllPortsAlreadyDetected:
|
---|
157 | stc
|
---|
158 | ret
|
---|
159 |
|
---|
160 |
|
---|
161 | ;--------------------------------------------------------------------
|
---|
162 | ; IdeAutodetect_IncrementDXtoNextIdeBasePort
|
---|
163 | ; Parameters:
|
---|
164 | ; DX: Previous IDE Base Port
|
---|
165 | ; Returns:
|
---|
166 | ; DX: Next IDE Base Port
|
---|
167 | ; ZF: Set if no more Base Ports (DX was last base port on entry)
|
---|
168 | ; Clear if new base port returned in DX
|
---|
169 | ; Corrupts registers:
|
---|
170 | ; AX
|
---|
171 | ;--------------------------------------------------------------------
|
---|
172 | ALIGN JUMP_ALIGN
|
---|
173 | IdeAutodetect_IncrementDXtoNextIdeBasePort:
|
---|
174 | cmp dx, [cs:.wLastIdePort]
|
---|
175 | je SHORT .AllPortsAlreadyDetected
|
---|
176 |
|
---|
177 | push si
|
---|
178 | mov si, .rgwIdeBasePorts
|
---|
179 | .CompareNextIdeBasePort:
|
---|
180 | cmp [cs:si], dx
|
---|
181 | lea si, [si+2] ; Increment SI and preserve FLAGS
|
---|
182 | jne SHORT .CompareNextIdeBasePort
|
---|
183 |
|
---|
184 | mov dx, [cs:si] ; Get next port
|
---|
185 | test dx, dx ; Clear ZF
|
---|
186 | pop si
|
---|
187 | .AllPortsAlreadyDetected:
|
---|
188 | ret
|
---|
189 |
|
---|
190 |
|
---|
191 | ; All ports used in autodetection. Ports can be in any order.
|
---|
192 | ALIGN WORD_ALIGN
|
---|
193 | .rgwIdeBasePorts:
|
---|
194 | dw IDE_PORT_TO_START_DETECTION ; Must be first
|
---|
195 | ; JR-IDE/ISA (Memory Segment Addresses)
|
---|
196 | dw 0C000h
|
---|
197 | dw 0C400h
|
---|
198 | dw 0C800h
|
---|
199 | dw 0CC00h
|
---|
200 | dw 0D000h
|
---|
201 | dw 0D400h
|
---|
202 | dw 0D800h
|
---|
203 | dw 0DC00h
|
---|
204 | ; 8-bit Devices
|
---|
205 | dw 200h
|
---|
206 | dw 220h
|
---|
207 | dw 240h
|
---|
208 | dw 260h
|
---|
209 | dw 280h
|
---|
210 | dw 2A0h
|
---|
211 | dw 2C0h
|
---|
212 | dw 2E0h
|
---|
213 | dw 300h
|
---|
214 | dw 320h
|
---|
215 | dw 340h
|
---|
216 | dw 360h
|
---|
217 | dw 380h
|
---|
218 | dw 3A0h
|
---|
219 | dw 3C0h
|
---|
220 | dw 3E0h
|
---|
221 | ; Standard IDE
|
---|
222 | dw DEVICE_ATA_PRIMARY_PORT
|
---|
223 | dw DEVICE_ATA_SECONDARY_PORT
|
---|
224 | dw DEVICE_ATA_TERTIARY_PORT
|
---|
225 | .wLastIdePort:
|
---|
226 | dw DEVICE_ATA_QUATERNARY_PORT
|
---|