[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 |
|
---|
[233] | 50 | pop cx
|
---|
| 51 |
|
---|
| 52 | add bp, BYTE IDEVARS_size ; Point to next IDEVARS
|
---|
| 53 |
|
---|
[242] | 54 | %ifdef MODULE_SERIAL
|
---|
[262] | 55 | jcxz .AddHardDisks ; Set to zero on .ideVarsSerialAuto iteration (if any)
|
---|
[196] | 56 | %endif
|
---|
[3] | 57 | loop .DriveDetectLoop
|
---|
[203] | 58 |
|
---|
[242] | 59 | %ifdef MODULE_SERIAL
|
---|
[258] | 60 | ;----------------------------------------------------------------------
|
---|
[203] | 61 | ;
|
---|
[233] | 62 | ; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
|
---|
[203] | 63 | ;
|
---|
[567] | 64 | call FindDPT_ToDSDIforSerialDevice ; Does not modify AX
|
---|
[262] | 65 | jnc .AddHardDisks
|
---|
[233] | 66 |
|
---|
[242] | 67 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
|
---|
| 68 |
|
---|
[492] | 69 | %ifdef MODULE_HOTKEYS
|
---|
[567] | 70 | cmp al, COM_DETECT_HOTKEY_SCANCODE ; Set by last call to HotkeyBar_UpdateDuringDriveDetection above
|
---|
[505] | 71 | je .DriveDetectLoop
|
---|
| 72 | %endif
|
---|
[492] | 73 |
|
---|
[568] | 74 | mov al, [cs:ROMVARS.wFlags] ; Configurator set to always scan?
|
---|
| 75 | or al, [es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
|
---|
| 76 | and al, 8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
|
---|
[242] | 77 | jnz .DriveDetectLoop
|
---|
[233] | 78 | %endif
|
---|
[203] | 79 |
|
---|
[262] | 80 | .AddHardDisks:
|
---|
[258] | 81 | ;----------------------------------------------------------------------
|
---|
| 82 | ;
|
---|
[262] | 83 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
[258] | 84 | ;
|
---|
[269] | 85 | ; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
|
---|
| 86 | ; This is done because we use the value of .bFirstDrv to know how many drives were in the system
|
---|
| 87 | ; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
|
---|
| 88 | ; FindDPT_ForDriveNumber will not find any drives that are ours.
|
---|
| 89 | ;
|
---|
[262] | 90 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
| 91 | mov al, [es:BDA.bHDCount]
|
---|
[568] | 92 | add [es:BDA.bHDCount], cl ; Add our drives to the system count
|
---|
[294] | 93 | or al, 80h ; Or in hard disk flag
|
---|
| 94 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
[262] | 95 |
|
---|
[294] | 96 | .AddFloppies:
|
---|
| 97 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
[262] | 98 | ;----------------------------------------------------------------------
|
---|
| 99 | ;
|
---|
| 100 | ; Add in any emulated serial floppy drives, finalize our packed Count and First variables
|
---|
| 101 | ;
|
---|
| 102 | dec ch
|
---|
| 103 | mov al, ch
|
---|
[294] | 104 | js .NoFloppies ; if no drives are present, we store 0ffh
|
---|
[262] | 105 |
|
---|
[258] | 106 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
| 107 |
|
---|
| 108 | push ax
|
---|
| 109 |
|
---|
[262] | 110 | add al, ch ; Add our drives to existing drive count
|
---|
[258] | 111 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
[294] | 112 | jb .MaxBDAFloppiesExceeded
|
---|
| 113 | mov al, 3
|
---|
[258] | 114 | .MaxBDAFloppiesExceeded:
|
---|
| 115 | eROR_IM al, 2 ; move to bits 6-7
|
---|
| 116 | inc ax ; low order bit, indicating floppy drive exists
|
---|
| 117 |
|
---|
[568] | 118 | mov ah, 3Eh ; AND mask to AH (all bits set except floppy drive count/present)
|
---|
| 119 | and ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte and mask off drive number and drives present bit
|
---|
[258] | 120 | or al, ah ; Or in new values
|
---|
| 121 | mov [es:BDA.wEquipment], al ; and store
|
---|
| 122 |
|
---|
[568] | 123 | mov al, 1Eh ; BDA pointer to Floppy DPT
|
---|
[258] | 124 | mov si, AH8h_FloppyDPT
|
---|
| 125 | call Interrupts_InstallHandlerToVectorInALFromCSSI
|
---|
| 126 |
|
---|
| 127 | pop ax
|
---|
| 128 |
|
---|
[262] | 129 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
[258] | 130 | rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
[294] | 131 | .NoFloppies:
|
---|
[258] | 132 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
[263] | 133 | %endif
|
---|
[3] | 134 | ret
|
---|
| 135 |
|
---|
[294] | 136 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[261] | 137 | %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
|
---|
| 138 | %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."
|
---|
| 139 | %endif
|
---|
[199] | 140 | %endif
|
---|
| 141 |
|
---|
[242] | 142 |
|
---|
[3] | 143 | ;--------------------------------------------------------------------
|
---|
[294] | 144 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
[3] | 145 | ; Parameters:
|
---|
| 146 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[233] | 147 | ; CX: Offset to "Master" or "Slave" string
|
---|
[3] | 148 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 149 | ; DS: RAMVARS segment
|
---|
| 150 | ; ES: Zero (BDA segment)
|
---|
| 151 | ; Returns:
|
---|
[567] | 152 | ; Nothing
|
---|
[3] | 153 | ; Corrupts registers:
|
---|
[473] | 154 | ; AX, BL, CX, DX, SI, DI
|
---|
[3] | 155 | ;--------------------------------------------------------------------
|
---|
[294] | 156 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
[474] | 157 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
[558] | 158 |
|
---|
[474] | 159 | %ifdef MODULE_HOTKEYS
|
---|
| 160 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
[505] | 161 | %endif
|
---|
[474] | 162 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
[473] | 163 |
|
---|
[474] | 164 |
|
---|
[3] | 165 | ;--------------------------------------------------------------------
|
---|
[120] | 166 | ; .ReadAtaInfoFromHardDisk
|
---|
[3] | 167 | ; Parameters:
|
---|
| 168 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 169 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 170 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
| 171 | ; DS: RAMVARS segment
|
---|
| 172 | ; ES: Zero (BDA segment)
|
---|
| 173 | ; Returns:
|
---|
| 174 | ; CF: Cleared if ATA-information read successfully
|
---|
| 175 | ; Set if any error
|
---|
| 176 | ; Corrupts registers:
|
---|
[150] | 177 | ; AX, BL, CX, DX, SI, DI
|
---|
[3] | 178 | ;--------------------------------------------------------------------
|
---|
[120] | 179 | .ReadAtaInfoFromHardDisk:
|
---|
[150] | 180 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
| 181 | push es
|
---|
| 182 | push si
|
---|
[473] | 183 | push dx
|
---|
[150] | 184 | push bx
|
---|
| 185 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 186 | pop bx
|
---|
[473] | 187 | pop dx
|
---|
[150] | 188 | pop si
|
---|
| 189 | pop es
|
---|
[120] | 190 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
| 191 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
[3] | 192 |
|
---|
[120] | 193 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
| 194 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
| 195 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
[242] | 196 |
|
---|
[203] | 197 | ;jmp short DetectDrives_DriveNotFound
|
---|
| 198 | ;;; fall-through instead of previous jmp instruction
|
---|
| 199 | ;--------------------------------------------------------------------
|
---|
| 200 | ; DetectDrives_DriveNotFound
|
---|
| 201 | ; Parameters:
|
---|
| 202 | ; Nothing
|
---|
| 203 | ; Returns:
|
---|
[567] | 204 | ; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
[203] | 205 | ; Corrupts registers:
|
---|
| 206 | ; AX, SI
|
---|
| 207 | ;--------------------------------------------------------------------
|
---|
[242] | 208 | DetectDrives_DriveNotFound:
|
---|
[203] | 209 | mov si, g_szNotFound
|
---|
[386] | 210 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
[3] | 211 |
|
---|
[120] | 212 |
|
---|
[3] | 213 | ;--------------------------------------------------------------------
|
---|
[98] | 214 | ; CreateBiosTablesForHardDisk
|
---|
[3] | 215 | ; Parameters:
|
---|
| 216 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 217 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 218 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
[150] | 219 | ; ES:SI Ptr to ATA information for the drive
|
---|
[3] | 220 | ; DS: RAMVARS segment
|
---|
[397] | 221 | ; ES: BDA segment
|
---|
[3] | 222 | ; Returns:
|
---|
[98] | 223 | ; Nothing
|
---|
[3] | 224 | ; Corrupts registers:
|
---|
[98] | 225 | ; AX, BX, CX, DX, SI, DI
|
---|
[3] | 226 | ;--------------------------------------------------------------------
|
---|
[98] | 227 | CreateBiosTablesForHardDisk:
|
---|
[441] | 228 | push bx
|
---|
| 229 | call AtaID_VerifyFromESSI
|
---|
| 230 | pop bx
|
---|
[567] | 231 | jnz SHORT DetectDrives_DriveNotFound
|
---|
[3] | 232 | call CreateDPT_FromAtaInformation
|
---|
[196] | 233 | jc SHORT DetectDrives_DriveNotFound
|
---|
[397] | 234 | call DriveDetectInfo_CreateForHardDisk
|
---|
| 235 | jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
|
---|