[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for detecting drive for the BIOS.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[491] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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.
|
---|
[491] | 12 | ;
|
---|
[376] | 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
|
---|
[491] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[491] | 18 | ;
|
---|
[376] | 19 |
|
---|
[3] | 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:
|
---|
[33] | 36 | call RamVars_GetIdeControllerCountToCX
|
---|
[3] | 37 | mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
|
---|
[200] | 38 |
|
---|
| 39 | .DriveDetectLoop: ; Loop through IDEVARS
|
---|
[233] | 40 | push cx
|
---|
| 41 |
|
---|
| 42 | mov cx, g_szDetectMaster
|
---|
| 43 | mov bh, MASK_DRVNHEAD_SET ; Select Master drive
|
---|
[294] | 44 | call StartDetectionWithDriveSelectByteInBHandStringInCX ; Detect and create DPT + BOOTNFO
|
---|
[233] | 45 |
|
---|
| 46 | mov cx, g_szDetectSlave
|
---|
[242] | 47 | mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
|
---|
[294] | 48 | call StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
[242] | 49 |
|
---|
[580] | 50 | %ifdef MODULE_HOTKEYS
|
---|
| 51 | %ifdef MODULE_SERIAL
|
---|
| 52 | ; This is only needed for hotkey F6 (ComDtct) to work
|
---|
| 53 | call ScanHotkeysFromKeyBufferAndStoreToBootvars ; Done here while CX is still protected
|
---|
| 54 | %endif
|
---|
| 55 | %endif
|
---|
| 56 |
|
---|
[233] | 57 | pop cx
|
---|
| 58 |
|
---|
| 59 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
| 60 |
|
---|
[242] | 61 | %ifdef MODULE_SERIAL
|
---|
[262] | 62 | jcxz .AddHardDisks ; Set to zero on .ideVarsSerialAuto iteration (if any)
|
---|
[196] | 63 | %endif
|
---|
[3] | 64 | loop .DriveDetectLoop
|
---|
[203] | 65 |
|
---|
[242] | 66 | %ifdef MODULE_SERIAL
|
---|
[258] | 67 | ;----------------------------------------------------------------------
|
---|
[203] | 68 | ;
|
---|
[233] | 69 | ; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
|
---|
[203] | 70 | ;
|
---|
[567] | 71 | call FindDPT_ToDSDIforSerialDevice ; Does not modify AX
|
---|
[262] | 72 | jnc .AddHardDisks
|
---|
[233] | 73 |
|
---|
[242] | 74 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
|
---|
| 75 |
|
---|
[492] | 76 | %ifdef MODULE_HOTKEYS
|
---|
[580] | 77 | cmp al, COM_DETECT_HOTKEY_SCANCODE ; Set by last call to ScanHotkeysFromKeyBufferAndStoreToBootvars above
|
---|
[505] | 78 | je .DriveDetectLoop
|
---|
| 79 | %endif
|
---|
[492] | 80 |
|
---|
[568] | 81 | mov al, [cs:ROMVARS.wFlags] ; Configurator set to always scan?
|
---|
| 82 | or al, [es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
|
---|
[589] | 83 | and al, 8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
|
---|
[242] | 84 | jnz .DriveDetectLoop
|
---|
[580] | 85 | %endif ; MODULE_SERIAL
|
---|
[203] | 86 |
|
---|
[262] | 87 | .AddHardDisks:
|
---|
[258] | 88 | ;----------------------------------------------------------------------
|
---|
| 89 | ;
|
---|
[262] | 90 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
[258] | 91 | ;
|
---|
[269] | 92 | ; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
|
---|
| 93 | ; This is done because we use the value of .bFirstDrv to know how many drives were in the system
|
---|
| 94 | ; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
|
---|
| 95 | ; FindDPT_ForDriveNumber will not find any drives that are ours.
|
---|
| 96 | ;
|
---|
[593] | 97 |
|
---|
| 98 | ; Here we might want to replace BIOS configured drives with the ones we detected.
|
---|
| 99 | ; Primary reason is to support dynamic overlay feature in the future. Second reason
|
---|
| 100 | ; is a hack to get Windows 95 load proper IDE drivers.
|
---|
| 101 | ;
|
---|
| 102 | ; The Windows hack has two parts. First part is to try to alter CMOS address 12h as that
|
---|
| 103 | ; is what Windows 95 driver reads to detect IDE drives. Altering is not possible on all
|
---|
| 104 | ; systems since CMOS has a checksum but it's location is not standardized. We will first
|
---|
| 105 | ; try to detect valid checksum. If it succeeds, then it is safe to assume this system
|
---|
| 106 | ; has compatible CMOS and we can alter it.
|
---|
| 107 | ; If verify fails, we do the more dirty hack to zero BDA drive count. Then Windows 95 works
|
---|
| 108 | ; as long as user has configured at least one drive in the BIOS setup.
|
---|
| 109 |
|
---|
| 110 | %ifdef USE_AT ; FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES is for AT builds only
|
---|
| 111 |
|
---|
| 112 | %ifdef MODULE_WIN95_CMOS_HACK
|
---|
| 113 | mov dl, HARD_DISK_TYPES
|
---|
| 114 | call CMOS_ReadFromIndexInDLtoAL
|
---|
| 115 | test al, al
|
---|
| 116 | jnz SHORT .ContinueInitialization ; CMOS byte 12h is ready for Windows 95
|
---|
[594] | 117 | call CMOS_Verify10hTo2Dh ; Can we modify CMOS?
|
---|
[593] | 118 | jnz SHORT .ClearBdaDriveCount ; Unsupported BIOS, use plan B
|
---|
| 119 |
|
---|
| 120 | ; Now we can alter CMOS location 12h
|
---|
| 121 | mov dl, HARD_DISK_TYPES
|
---|
| 122 | mov al, 0F0h ; Drive 0 type 16...47 but Windows doesn't care as long as this is not zero
|
---|
| 123 | call CMOS_WriteALtoIndexInDL
|
---|
| 124 | call CMOS_StoreNewChecksumFor10hto2Dh
|
---|
[594] | 125 | .ClearBdaDriveCount:
|
---|
| 126 | %endif ; MODULE_WIN95_CMOS_HACK
|
---|
[593] | 127 |
|
---|
| 128 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES
|
---|
| 129 | jz SHORT .ContinueInitialization
|
---|
| 130 | mov BYTE [es:BDA.bHDCount], 0 ; Set hard disk count to zero
|
---|
| 131 | .ContinueInitialization:
|
---|
| 132 | %endif
|
---|
| 133 |
|
---|
[262] | 134 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
| 135 | mov al, [es:BDA.bHDCount]
|
---|
[568] | 136 | add [es:BDA.bHDCount], cl ; Add our drives to the system count
|
---|
[294] | 137 | or al, 80h ; Or in hard disk flag
|
---|
| 138 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
[262] | 139 |
|
---|
[294] | 140 | .AddFloppies:
|
---|
| 141 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
[262] | 142 | ;----------------------------------------------------------------------
|
---|
| 143 | ;
|
---|
| 144 | ; Add in any emulated serial floppy drives, finalize our packed Count and First variables
|
---|
| 145 | ;
|
---|
| 146 | dec ch
|
---|
| 147 | mov al, ch
|
---|
[294] | 148 | js .NoFloppies ; if no drives are present, we store 0ffh
|
---|
[262] | 149 |
|
---|
[258] | 150 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
| 151 |
|
---|
| 152 | push ax
|
---|
| 153 |
|
---|
[262] | 154 | add al, ch ; Add our drives to existing drive count
|
---|
[258] | 155 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
[294] | 156 | jb .MaxBDAFloppiesExceeded
|
---|
| 157 | mov al, 3
|
---|
[258] | 158 | .MaxBDAFloppiesExceeded:
|
---|
| 159 | eROR_IM al, 2 ; move to bits 6-7
|
---|
| 160 | inc ax ; low order bit, indicating floppy drive exists
|
---|
| 161 |
|
---|
[568] | 162 | mov ah, 3Eh ; AND mask to AH (all bits set except floppy drive count/present)
|
---|
| 163 | and ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte and mask off drive number and drives present bit
|
---|
[258] | 164 | or al, ah ; Or in new values
|
---|
| 165 | mov [es:BDA.wEquipment], al ; and store
|
---|
| 166 |
|
---|
[568] | 167 | mov al, 1Eh ; BDA pointer to Floppy DPT
|
---|
[258] | 168 | mov si, AH8h_FloppyDPT
|
---|
| 169 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
| 170 |
|
---|
| 171 | pop ax
|
---|
| 172 |
|
---|
[262] | 173 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
[589] | 174 | eRCL_IM al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
[294] | 175 | .NoFloppies:
|
---|
[258] | 176 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
[263] | 177 | %endif
|
---|
[3] | 178 | ret
|
---|
| 179 |
|
---|
[294] | 180 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[261] | 181 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
|
---|
| 182 | %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."
|
---|
| 183 | %endif
|
---|
[199] | 184 | %endif
|
---|
| 185 |
|
---|
[242] | 186 |
|
---|
[3] | 187 | ;--------------------------------------------------------------------
|
---|
[294] | 188 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
[3] | 189 | ; Parameters:
|
---|
| 190 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[233] | 191 | ; CX: Offset to "Master" or "Slave" string
|
---|
[3] | 192 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 193 | ; DS: RAMVARS segment
|
---|
| 194 | ; ES: Zero (BDA segment)
|
---|
| 195 | ; Returns:
|
---|
[567] | 196 | ; Nothing
|
---|
[3] | 197 | ; Corrupts registers:
|
---|
[473] | 198 | ; AX, BL, CX, DX, SI, DI
|
---|
[3] | 199 | ;--------------------------------------------------------------------
|
---|
[294] | 200 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
[474] | 201 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
[558] | 202 |
|
---|
[474] | 203 | %ifdef MODULE_HOTKEYS
|
---|
| 204 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
[505] | 205 | %endif
|
---|
[474] | 206 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
[473] | 207 |
|
---|
[474] | 208 |
|
---|
[3] | 209 | ;--------------------------------------------------------------------
|
---|
[120] | 210 | ; .ReadAtaInfoFromHardDisk
|
---|
[3] | 211 | ; Parameters:
|
---|
| 212 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 213 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 214 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 215 | ; DS: RAMVARS segment
|
---|
| 216 | ; ES: Zero (BDA segment)
|
---|
| 217 | ; Returns:
|
---|
| 218 | ; CF: Cleared if ATA-information read successfully
|
---|
| 219 | ; Set if any error
|
---|
| 220 | ; Corrupts registers:
|
---|
[150] | 221 | ; AX, BL, CX, DX, SI, DI
|
---|
[3] | 222 | ;--------------------------------------------------------------------
|
---|
[120] | 223 | .ReadAtaInfoFromHardDisk:
|
---|
[150] | 224 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
| 225 | push es
|
---|
| 226 | push si
|
---|
[473] | 227 | push dx
|
---|
[150] | 228 | push bx
|
---|
| 229 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 230 | pop bx
|
---|
[473] | 231 | pop dx
|
---|
[150] | 232 | pop si
|
---|
| 233 | pop es
|
---|
[120] | 234 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
| 235 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
[3] | 236 |
|
---|
[120] | 237 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
| 238 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
| 239 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
[242] | 240 |
|
---|
[203] | 241 | ;jmp short DetectDrives_DriveNotFound
|
---|
| 242 | ;;; fall-through instead of previous jmp instruction
|
---|
| 243 | ;--------------------------------------------------------------------
|
---|
| 244 | ; DetectDrives_DriveNotFound
|
---|
| 245 | ; Parameters:
|
---|
| 246 | ; Nothing
|
---|
| 247 | ; Returns:
|
---|
[567] | 248 | ; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
[203] | 249 | ; Corrupts registers:
|
---|
| 250 | ; AX, SI
|
---|
| 251 | ;--------------------------------------------------------------------
|
---|
[242] | 252 | DetectDrives_DriveNotFound:
|
---|
[203] | 253 | mov si, g_szNotFound
|
---|
[386] | 254 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
[3] | 255 |
|
---|
[120] | 256 |
|
---|
[3] | 257 | ;--------------------------------------------------------------------
|
---|
[98] | 258 | ; CreateBiosTablesForHardDisk
|
---|
[3] | 259 | ; Parameters:
|
---|
| 260 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 261 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 262 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
[150] | 263 | ; ES:SI Ptr to ATA information for the drive
|
---|
[3] | 264 | ; DS: RAMVARS segment
|
---|
[397] | 265 | ; ES: BDA segment
|
---|
[3] | 266 | ; Returns:
|
---|
[98] | 267 | ; Nothing
|
---|
[3] | 268 | ; Corrupts registers:
|
---|
[98] | 269 | ; AX, BX, CX, DX, SI, DI
|
---|
[3] | 270 | ;--------------------------------------------------------------------
|
---|
[98] | 271 | CreateBiosTablesForHardDisk:
|
---|
[580] | 272 | %ifndef NO_ATAID_VALIDATION
|
---|
[441] | 273 | push bx
|
---|
| 274 | call AtaID_VerifyFromESSI
|
---|
| 275 | pop bx
|
---|
[567] | 276 | jnz SHORT DetectDrives_DriveNotFound
|
---|
[580] | 277 | %endif
|
---|
[3] | 278 | call CreateDPT_FromAtaInformation
|
---|
[196] | 279 | jc SHORT DetectDrives_DriveNotFound
|
---|
[397] | 280 | call DriveDetectInfo_CreateForHardDisk
|
---|
| 281 | jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
|
---|