1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for detecting drive for the BIOS.
|
---|
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 | ; Detects all IDE hard disks to be controlled by this BIOS.
|
---|
25 | ;
|
---|
26 | ; DetectDrives_FromAllIDEControllers
|
---|
27 | ; Parameters:
|
---|
28 | ; DS: RAMVARS segment
|
---|
29 | ; ES: BDA segment (zero)
|
---|
30 | ; Returns:
|
---|
31 | ; Nothing
|
---|
32 | ; Corrupts registers:
|
---|
33 | ; All (not segments)
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | DetectDrives_FromAllIDEControllers:
|
---|
36 | call RamVars_GetIdeControllerCountToCX
|
---|
37 | mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
|
---|
38 |
|
---|
39 | .DriveDetectLoop: ; Loop through IDEVARS
|
---|
40 | push cx
|
---|
41 |
|
---|
42 | mov cx, g_szDetectMaster
|
---|
43 | mov bh, MASK_DRVNHEAD_SET ; Select Master drive
|
---|
44 | call StartDetectionWithDriveSelectByteInBHandStringInCX ; Detect and create DPT + BOOTNFO
|
---|
45 |
|
---|
46 | mov cx, g_szDetectSlave
|
---|
47 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
|
---|
48 | call StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
49 |
|
---|
50 | %ifdef MODULE_HOTKEYS
|
---|
51 | call HotkeyBar_ScanHotkeysFromKeyBufferAndStoreToBootvars ; Done here while CX is still protected
|
---|
52 | %endif
|
---|
53 |
|
---|
54 | pop cx
|
---|
55 |
|
---|
56 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
57 |
|
---|
58 | %ifdef MODULE_SERIAL
|
---|
59 | jcxz .AddHardDisks ; Set to zero on .ideVarsSerialAuto iteration (if any)
|
---|
60 | %endif
|
---|
61 | loop .DriveDetectLoop
|
---|
62 |
|
---|
63 | %ifdef MODULE_SERIAL
|
---|
64 | ;----------------------------------------------------------------------
|
---|
65 | ;
|
---|
66 | ; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
|
---|
67 | ;
|
---|
68 | call FindDPT_ToDSDIforSerialDevice ; does not modify AX
|
---|
69 | jnc .AddHardDisks
|
---|
70 |
|
---|
71 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
|
---|
72 |
|
---|
73 | %ifdef MODULE_HOTKEYS
|
---|
74 | cmp al, COM_DETECT_HOTKEY_SCANCODE ; Set by last call to HotkeyBar_UpdateDuringDriveDetection above
|
---|
75 | jz .DriveDetectLoop
|
---|
76 | %endif
|
---|
77 |
|
---|
78 | mov al,[cs:ROMVARS.wFlags] ; Configurator set to always scan?
|
---|
79 | or al,[es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
|
---|
80 | and al,8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
|
---|
81 | jnz .DriveDetectLoop
|
---|
82 | %endif
|
---|
83 |
|
---|
84 | .AddHardDisks:
|
---|
85 | ;----------------------------------------------------------------------
|
---|
86 | ;
|
---|
87 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
88 | ;
|
---|
89 | ; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
|
---|
90 | ; This is done because we use the value of .bFirstDrv to know how many drives were in the system
|
---|
91 | ; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
|
---|
92 | ; FindDPT_ForDriveNumber will not find any drives that are ours.
|
---|
93 | ;
|
---|
94 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
95 |
|
---|
96 | mov al, [es:BDA.bHDCount]
|
---|
97 | add cl, al ; Add our drives to the system count
|
---|
98 | mov [es:BDA.bHDCount], cl
|
---|
99 | or al, 80h ; Or in hard disk flag
|
---|
100 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
101 |
|
---|
102 | .AddFloppies:
|
---|
103 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
104 | ;----------------------------------------------------------------------
|
---|
105 | ;
|
---|
106 | ; Add in any emulated serial floppy drives, finalize our packed Count and First variables
|
---|
107 | ;
|
---|
108 | dec ch
|
---|
109 | mov al, ch
|
---|
110 | js .NoFloppies ; if no drives are present, we store 0ffh
|
---|
111 |
|
---|
112 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
113 |
|
---|
114 | push ax
|
---|
115 |
|
---|
116 | add al, ch ; Add our drives to existing drive count
|
---|
117 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
118 | jb .MaxBDAFloppiesExceeded
|
---|
119 | mov al, 3
|
---|
120 | .MaxBDAFloppiesExceeded:
|
---|
121 | eROR_IM al, 2 ; move to bits 6-7
|
---|
122 | inc ax ; low order bit, indicating floppy drive exists
|
---|
123 |
|
---|
124 | mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
|
---|
125 | and ah, 03eh ; Mask off drive number and drives present bit
|
---|
126 | or al, ah ; Or in new values
|
---|
127 | mov [es:BDA.wEquipment], al ; and store
|
---|
128 |
|
---|
129 | mov al, 1eh ; BDA pointer to Floppy DPT
|
---|
130 | mov si, AH8h_FloppyDPT
|
---|
131 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
132 |
|
---|
133 | pop ax
|
---|
134 |
|
---|
135 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
136 | rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
137 | .NoFloppies:
|
---|
138 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
139 | %endif
|
---|
140 |
|
---|
141 | ret
|
---|
142 |
|
---|
143 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
144 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
|
---|
145 | %error "DetectDrives is currently coded to assume that FLG_ROMVARS_SERIAL_SCANDETECT is the same bit as the ALT key code in the BDA. Changes in the code will be needed if these values are no longer the same."
|
---|
146 | %endif
|
---|
147 | %endif
|
---|
148 |
|
---|
149 |
|
---|
150 | ;--------------------------------------------------------------------
|
---|
151 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
152 | ; Parameters:
|
---|
153 | ; BH: Drive Select byte for Drive and Head Register
|
---|
154 | ; CX: Offset to "Master" or "Slave" string
|
---|
155 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
156 | ; DS: RAMVARS segment
|
---|
157 | ; ES: Zero (BDA segment)
|
---|
158 | ; Returns:
|
---|
159 | ; None
|
---|
160 | ; Corrupts registers:
|
---|
161 | ; AX, BL, CX, DX, SI, DI
|
---|
162 | ;--------------------------------------------------------------------
|
---|
163 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
164 | %ifdef MODULE_8BIT_IDE
|
---|
165 | ; Autodetect port for XT-CF
|
---|
166 | call DetectDrives_DoesIdevarsInCSBPbelongToXTCF
|
---|
167 | jne SHORT .SkipXTCFportDetection
|
---|
168 |
|
---|
169 | ; XT-CF do not support slave drives so skip detection
|
---|
170 | test bh, FLG_DRVNHEAD_DRV
|
---|
171 | jnz SHORT NoSlaveDriveAvailable
|
---|
172 |
|
---|
173 | ; XT-CF do not support slave drives so we can safely update port
|
---|
174 | ; for next drive (another XT-CF card on same system)
|
---|
175 | .DetectNextPort:
|
---|
176 | mov dx, [es:BOOTVARS.wNextXTCFportToScan]
|
---|
177 | xor dl, 40h
|
---|
178 | jnz SHORT .StoreNextXTCFportToScan
|
---|
179 | inc dh
|
---|
180 | cmp dh, XTCF_BASE_PORT_4 >> 8
|
---|
181 | ja SHORT .SkipXTCFportDetection ; XT-CF not found from any port
|
---|
182 | .StoreNextXTCFportToScan:
|
---|
183 | mov [es:BOOTVARS.wNextXTCFportToScan], dx
|
---|
184 |
|
---|
185 | call AH1Eh_DetectXTCFwithBasePortInDX
|
---|
186 | jc SHORT .DetectNextPort ; XT-CF not found from this port
|
---|
187 |
|
---|
188 | ; We now have autodetected port in DX
|
---|
189 | push dx
|
---|
190 | xchg ax, dx ; Port to print in AX
|
---|
191 | call DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP
|
---|
192 | jmp SHORT .DriveDetectionStringPrintedOnScreen
|
---|
193 |
|
---|
194 | ; Print detect string for devices that do not support autodetection
|
---|
195 | .SkipXTCFportDetection:
|
---|
196 | push dx
|
---|
197 | %endif ; MODULE_8BIT_IDE
|
---|
198 |
|
---|
199 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
200 | .DriveDetectionStringPrintedOnScreen:
|
---|
201 | %ifdef MODULE_HOTKEYS
|
---|
202 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
203 | %endif
|
---|
204 |
|
---|
205 | %ifdef MODULE_8BIT_IDE
|
---|
206 | pop dx
|
---|
207 | %endif
|
---|
208 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
209 |
|
---|
210 |
|
---|
211 | ;--------------------------------------------------------------------
|
---|
212 | ; .ReadAtaInfoFromHardDisk
|
---|
213 | ; Parameters:
|
---|
214 | ; BH: Drive Select byte for Drive and Head Register
|
---|
215 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
216 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
217 | ; DS: RAMVARS segment
|
---|
218 | ; ES: Zero (BDA segment)
|
---|
219 | ; Returns:
|
---|
220 | ; CF: Cleared if ATA-information read successfully
|
---|
221 | ; Set if any error
|
---|
222 | ; Corrupts registers:
|
---|
223 | ; AX, BL, CX, DX, SI, DI
|
---|
224 | ;--------------------------------------------------------------------
|
---|
225 | .ReadAtaInfoFromHardDisk:
|
---|
226 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
227 | push es
|
---|
228 | push si
|
---|
229 | push dx
|
---|
230 | push bx
|
---|
231 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
232 | pop bx
|
---|
233 | pop dx
|
---|
234 | pop si
|
---|
235 | pop es
|
---|
236 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
237 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
238 |
|
---|
239 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
240 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
241 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
242 |
|
---|
243 | ;jmp short DetectDrives_DriveNotFound
|
---|
244 | ;;; fall-through instead of previous jmp instruction
|
---|
245 | ;--------------------------------------------------------------------
|
---|
246 | ; DetectDrives_DriveNotFound
|
---|
247 | ; Parameters:
|
---|
248 | ; Nothing
|
---|
249 | ; Returns:
|
---|
250 | ; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
251 | ; Corrupts registers:
|
---|
252 | ; AX, SI
|
---|
253 | ;--------------------------------------------------------------------
|
---|
254 | DetectDrives_DriveNotFound:
|
---|
255 | mov si, g_szNotFound
|
---|
256 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
257 |
|
---|
258 |
|
---|
259 | ;--------------------------------------------------------------------
|
---|
260 | ; CreateBiosTablesForHardDisk
|
---|
261 | ; Parameters:
|
---|
262 | ; BH: Drive Select byte for Drive and Head Register
|
---|
263 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
264 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
265 | ; ES:SI Ptr to ATA information for the drive
|
---|
266 | ; DS: RAMVARS segment
|
---|
267 | ; ES: BDA segment
|
---|
268 | ; Returns:
|
---|
269 | ; Nothing
|
---|
270 | ; Corrupts registers:
|
---|
271 | ; AX, BX, CX, DX, SI, DI
|
---|
272 | ;--------------------------------------------------------------------
|
---|
273 | CreateBiosTablesForHardDisk:
|
---|
274 | push bx
|
---|
275 | call AtaID_VerifyFromESSI
|
---|
276 | pop bx
|
---|
277 | jc SHORT DetectDrives_DriveNotFound
|
---|
278 | call CreateDPT_FromAtaInformation
|
---|
279 | jc SHORT DetectDrives_DriveNotFound
|
---|
280 | call DriveDetectInfo_CreateForHardDisk
|
---|
281 | jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
|
---|
282 |
|
---|
283 |
|
---|
284 | %ifdef MODULE_8BIT_IDE
|
---|
285 | ;--------------------------------------------------------------------
|
---|
286 | ; DetectDrives_DoesIdevarsInCSBPbelongToXTCF
|
---|
287 | ; Parameters:
|
---|
288 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
289 | ; Returns:
|
---|
290 | ; ZF: Set if IDEVARS belongs to XT-CF device
|
---|
291 | ; Cleared if some other device
|
---|
292 | ; Corrupts registers:
|
---|
293 | ; AL
|
---|
294 | ;--------------------------------------------------------------------
|
---|
295 | DetectDrives_DoesIdevarsInCSBPbelongToXTCF:
|
---|
296 | mov al, [cs:bp+IDEVARS.bDevice]
|
---|
297 | cmp al, DEVICE_8BIT_XTCF_PIO8
|
---|
298 | je SHORT .DeviceIsXTCF
|
---|
299 | cmp al, DEVICE_8BIT_XTCF_DMA
|
---|
300 | je SHORT .DeviceIsXTCF
|
---|
301 | cmp al, DEVICE_8BIT_XTCF_MEMMAP
|
---|
302 | .DeviceIsXTCF:
|
---|
303 | NoSlaveDriveAvailable:
|
---|
304 | ret
|
---|
305 | %endif ; MODULE_8BIT_IDE
|
---|