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-2013 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 | test BYTE [cs:bp+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], FLG_DRVPARAMS_DO_NOT_DETECT
|
---|
47 | jnz SHORT .SkipSlaveDetection
|
---|
48 | mov cx, g_szDetectSlave
|
---|
49 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
|
---|
50 | call StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
51 | .SkipSlaveDetection:
|
---|
52 |
|
---|
53 | %ifdef MODULE_HOTKEYS
|
---|
54 | %ifdef MODULE_SERIAL
|
---|
55 | ; This is only needed for hotkey F6 (ComDtct) to work
|
---|
56 | call ScanHotkeysFromKeyBufferAndStoreToBootvars ; Done here while CX is still protected
|
---|
57 | %endif
|
---|
58 | %endif
|
---|
59 |
|
---|
60 | pop cx
|
---|
61 |
|
---|
62 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
63 |
|
---|
64 | %ifdef MODULE_SERIAL
|
---|
65 | jcxz .AddHardDisks ; Set to zero on .ideVarsSerialAuto iteration (if any)
|
---|
66 | %endif
|
---|
67 | loop .DriveDetectLoop
|
---|
68 |
|
---|
69 | %ifdef MODULE_SERIAL
|
---|
70 | ;----------------------------------------------------------------------
|
---|
71 | ;
|
---|
72 | ; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
|
---|
73 | ;
|
---|
74 | call FindDPT_ToDSDIforSerialDevice ; Does not modify AX
|
---|
75 | jnc SHORT .AddHardDisks
|
---|
76 |
|
---|
77 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
|
---|
78 |
|
---|
79 | %ifdef MODULE_HOTKEYS
|
---|
80 | cmp al, COM_DETECT_HOTKEY_SCANCODE ; Set by last call to ScanHotkeysFromKeyBufferAndStoreToBootvars above
|
---|
81 | je SHORT .DriveDetectLoop
|
---|
82 | %endif
|
---|
83 |
|
---|
84 | mov al, [cs:ROMVARS.wFlags] ; Configurator set to always scan?
|
---|
85 | or al, [es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
|
---|
86 | and al, 8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
|
---|
87 | jnz SHORT .DriveDetectLoop
|
---|
88 | %endif ; MODULE_SERIAL
|
---|
89 |
|
---|
90 | .AddHardDisks:
|
---|
91 | ;----------------------------------------------------------------------
|
---|
92 | ;
|
---|
93 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
94 | ;
|
---|
95 | ; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
|
---|
96 | ; This is done because we use the value of .bFirstDrv to know how many drives were in the system
|
---|
97 | ; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
|
---|
98 | ; FindDPT_ForDriveNumber will not find any drives that are ours.
|
---|
99 | ;
|
---|
100 |
|
---|
101 | ; This is a hack to get Windows 9x to load its built-in protected mode IDE driver.
|
---|
102 | ;
|
---|
103 | ; The Windows hack has two parts. First part is to try to alter CMOS address 12h as that
|
---|
104 | ; is what Windows 9x driver reads to detect IDE drives. Altering is not possible on all
|
---|
105 | ; systems since CMOS has a checksum but its location is not standardized. We will first
|
---|
106 | ; try to detect valid checksum. If it succeeds, then it is safe to assume this system
|
---|
107 | ; has compatible CMOS and we can alter it.
|
---|
108 | ; If verify fails, we do the more dirty hack to zero BDA drive count. Then Windows 9x works
|
---|
109 | ; as long as user has configured at least one drive in the BIOS setup.
|
---|
110 | %ifdef MODULE_WIN9X_CMOS_HACK
|
---|
111 | mov dl, HARD_DISK_TYPES
|
---|
112 | call CMOS_ReadFromIndexInDLtoAL
|
---|
113 | test al, 0F0h
|
---|
114 | jnz SHORT .ClearBdaDriveCount ; CMOS byte 12h is ready for Windows 9x
|
---|
115 | call CMOS_Verify10hTo2Dh ; Can we modify CMOS?
|
---|
116 | jnz SHORT .ClearBdaDriveCount ; Unsupported BIOS, use plan B
|
---|
117 |
|
---|
118 | ; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
|
---|
119 | ; (but accept changes to drive type 1). Windows 9x requires that the drive 0 type is
|
---|
120 | ; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
|
---|
121 | ; won't give problems but Windows 9x stays in MS-DOS compatibility mode.
|
---|
122 | ;
|
---|
123 | ; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
|
---|
124 | ; So essentially we could automatically do what user needs to do manually to get Windows 9x
|
---|
125 | ; working on Award BIOSes. However, I think that should be left to do manually since
|
---|
126 | ; there may be SCSI drives on the system or FLG_ROMVARS_CLEAR_BDA_HD_COUNT could
|
---|
127 | ; be intentionally cleared and forcing the dummy drive might cause only trouble.
|
---|
128 |
|
---|
129 | ; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
|
---|
130 | ; there will be no need to scan E000h segment)
|
---|
131 | mov cx, 65536 - 4
|
---|
132 | mov eax, 'Awar' ; Four characters should be enough
|
---|
133 | mov di, 0F000h ; Scan 64k starting from segment F000h
|
---|
134 | mov fs, di ; No need to preserve FS since we set it to zero soon when we boot
|
---|
135 | xor di, di
|
---|
136 | .ScanNextCharacters:
|
---|
137 | cmp [fs:di], eax
|
---|
138 | je SHORT .ClearBdaDriveCount ; Award detected, cannot modify CMOS
|
---|
139 | inc di ; Increment offset by one character (not four)
|
---|
140 | loop .ScanNextCharacters
|
---|
141 |
|
---|
142 | ; Now it should be safe to write
|
---|
143 | mov dl, HARD_DISK_TYPES
|
---|
144 | mov al, 0F0h ; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
|
---|
145 | call CMOS_WriteALtoIndexInDL
|
---|
146 | call CMOS_StoreNewChecksumFor10hto2Dh
|
---|
147 | .ClearBdaDriveCount:
|
---|
148 | %endif ; MODULE_WIN9X_CMOS_HACK
|
---|
149 |
|
---|
150 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
151 | mov al, [es:BDA.bHDCount]
|
---|
152 | %ifndef MODULE_MFM_COMPATIBILITY
|
---|
153 | ; This is excluded when MODULE_MFM_COMPATIBILITY is included because it doesn't make sense to use both at the same time anyway.
|
---|
154 | ; Note that the option to "Remove other hard drives" is still visible in XTIDECFG.COM for builds including MODULE_MFM_COMPATIBILITY.
|
---|
155 | ; Changing that option just won't do anything. We might want to remove the option for builds that contain MODULE_MFM_COMPATIBILITY
|
---|
156 | ; but that would require a ROMVARS flag that is probably better spent on other things.
|
---|
157 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_CLEAR_BDA_HD_COUNT ; Clears CF
|
---|
158 | jz SHORT .ContinueInitialization
|
---|
159 | %ifdef USE_UNDOC_INTEL
|
---|
160 | salc
|
---|
161 | %else
|
---|
162 | xor al, al
|
---|
163 | %endif
|
---|
164 | .ContinueInitialization:
|
---|
165 | %endif ; MODULE_MFM_COMPATIBILITY
|
---|
166 | add cl, al
|
---|
167 | mov [es:BDA.bHDCount], cl ; Update the system count
|
---|
168 | or al, 80h ; Or in hard disk flag
|
---|
169 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
170 |
|
---|
171 | .AddFloppies:
|
---|
172 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
173 | ;----------------------------------------------------------------------
|
---|
174 | ;
|
---|
175 | ; Add in any emulated serial floppy drives, finalize our packed Count and First variables
|
---|
176 | ;
|
---|
177 | dec ch
|
---|
178 | mov al, ch
|
---|
179 | js SHORT .NoFloppies ; If no drives are present, we store 0FFh
|
---|
180 |
|
---|
181 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
182 |
|
---|
183 | push ax
|
---|
184 |
|
---|
185 | add al, ch ; Add our drives to existing drive count
|
---|
186 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
187 | jb SHORT .MaxBDAFloppiesExceeded
|
---|
188 | mov al, 3
|
---|
189 | .MaxBDAFloppiesExceeded:
|
---|
190 | eROR_IM al, 2 ; move to bits 6-7
|
---|
191 | inc ax ; low order bit, indicating floppy drive exists
|
---|
192 |
|
---|
193 | mov ah, 3Eh ; AND mask to AH (all bits set except floppy drive count/present)
|
---|
194 | and ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte and mask off drive number and drives present bit
|
---|
195 | or al, ah ; Or in new values
|
---|
196 | mov [es:BDA.wEquipment], al ; and store
|
---|
197 |
|
---|
198 | mov al, 1Eh ; BDA pointer to Floppy DPT
|
---|
199 | mov si, AH8h_FloppyDPT
|
---|
200 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
201 |
|
---|
202 | pop ax
|
---|
203 |
|
---|
204 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
205 | eRCL_IM al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
206 | .NoFloppies:
|
---|
207 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
208 | %endif
|
---|
209 | ret
|
---|
210 |
|
---|
211 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
212 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
|
---|
213 | %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."
|
---|
214 | %endif
|
---|
215 | %endif
|
---|
216 |
|
---|
217 |
|
---|
218 | ;--------------------------------------------------------------------
|
---|
219 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
220 | ; Parameters:
|
---|
221 | ; BH: Drive Select byte for Drive and Head Register
|
---|
222 | ; CX: Offset to "Master" or "Slave" string
|
---|
223 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
224 | ; DS: RAMVARS segment
|
---|
225 | ; ES: Zero (BDA segment)
|
---|
226 | ; Returns:
|
---|
227 | ; Nothing
|
---|
228 | ; Corrupts registers:
|
---|
229 | ; AX, BL, CX, DX, SI, DI
|
---|
230 | ;--------------------------------------------------------------------
|
---|
231 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
232 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
233 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
234 |
|
---|
235 |
|
---|
236 | ;--------------------------------------------------------------------
|
---|
237 | ; .ReadAtaInfoFromHardDisk
|
---|
238 | ; Parameters:
|
---|
239 | ; BH: Drive Select byte for Drive and Head Register
|
---|
240 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
241 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
242 | ; DS: RAMVARS segment
|
---|
243 | ; ES: Zero (BDA segment)
|
---|
244 | ; Returns:
|
---|
245 | ; CF: Cleared if ATA-information read successfully
|
---|
246 | ; Set if any error
|
---|
247 | ; Corrupts registers:
|
---|
248 | ; AX, BL, CX, DX, SI, DI
|
---|
249 | ;--------------------------------------------------------------------
|
---|
250 | .ReadAtaInfoFromHardDisk:
|
---|
251 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
252 | push es
|
---|
253 | push si
|
---|
254 | push dx
|
---|
255 | push bx
|
---|
256 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
257 | pop bx
|
---|
258 | pop dx
|
---|
259 | pop si
|
---|
260 | pop es
|
---|
261 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
262 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
263 |
|
---|
264 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
265 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
266 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
267 |
|
---|
268 | ;jmp short DetectDrives_DriveNotFound
|
---|
269 | ;;; fall-through instead of previous jmp instruction
|
---|
270 | ;--------------------------------------------------------------------
|
---|
271 | ; DetectDrives_DriveNotFound
|
---|
272 | ; Parameters:
|
---|
273 | ; Nothing
|
---|
274 | ; Returns:
|
---|
275 | ; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
276 | ; Corrupts registers:
|
---|
277 | ; AX, SI
|
---|
278 | ;--------------------------------------------------------------------
|
---|
279 | DetectDrives_DriveNotFound:
|
---|
280 | mov si, g_szNotFound
|
---|
281 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
282 |
|
---|
283 |
|
---|
284 | ;--------------------------------------------------------------------
|
---|
285 | ; CreateBiosTablesForHardDisk
|
---|
286 | ; Parameters:
|
---|
287 | ; BH: Drive Select byte for Drive and Head Register
|
---|
288 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
289 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
290 | ; ES:SI Ptr to ATA information for the drive
|
---|
291 | ; DS: RAMVARS segment
|
---|
292 | ; ES: BDA segment
|
---|
293 | ; Returns:
|
---|
294 | ; Nothing
|
---|
295 | ; Corrupts registers:
|
---|
296 | ; AX, BX, CX, DX, SI, DI
|
---|
297 | ;--------------------------------------------------------------------
|
---|
298 | CreateBiosTablesForHardDisk:
|
---|
299 | %ifndef NO_ATAID_VALIDATION
|
---|
300 | push bx
|
---|
301 | call AtaID_VerifyFromESSI
|
---|
302 | pop bx
|
---|
303 | jnz SHORT DetectDrives_DriveNotFound
|
---|
304 | %endif
|
---|
305 | call CreateDPT_FromAtaInformation
|
---|
306 | jc SHORT DetectDrives_DriveNotFound
|
---|
307 | call DriveDetectInfo_CreateForHardDisk
|
---|
308 | jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
|
---|