source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm@ 606

Last change on this file since 606 was 605, checked in by Krister Nordvall, 4 years ago

Changes:

  • The "Remove other hard drives" option in the Boot settings menu in XTIDECFG is now exposed in all BIOS builds. This is needed because the system BIOS in at least two Zenith computer models (Z-161 and Z-171) does not clear the BDA HD count which causes it to increment on warm boot. Running "Auto Configure" in XTIDECFG now also tries to identify these machines by doing a CRC check on the system BIOS and sets the option to YES if a match is found.
  • WORD_ALIGN is now 2 for XT builds. This should benefit XT class machines with 8086 and NEC V30 CPU:s and the cost is negligible (1 byte for the XT BIOS builds and 12 bytes for XTIDECFG.COM).
  • Other minor optimizations.
File size: 11.6 KB
RevLine 
[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
21SECTION .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;--------------------------------------------------------------------
35DetectDrives_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
[605]72 jnc SHORT .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
[605]78 je SHORT .DriveDetectLoop
[505]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
[605]84 jnz SHORT .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
[605]98; This is a hack to get Windows 9x to load its built-in protected mode IDE driver.
[596]99;
[593]100; The Windows hack has two parts. First part is to try to alter CMOS address 12h as that
[605]101; is what Windows 9x driver reads to detect IDE drives. Altering is not possible on all
[596]102; systems since CMOS has a checksum but its location is not standardized. We will first
[593]103; try to detect valid checksum. If it succeeds, then it is safe to assume this system
104; has compatible CMOS and we can alter it.
[605]105; If verify fails, we do the more dirty hack to zero BDA drive count. Then Windows 9x works
[593]106; as long as user has configured at least one drive in the BIOS setup.
[605]107%ifdef MODULE_WIN9X_CMOS_HACK
[601]108 mov dl, HARD_DISK_TYPES
109 call CMOS_ReadFromIndexInDLtoAL
110 test al, 0F0h
[605]111 jnz SHORT .ClearBdaDriveCount ; CMOS byte 12h is ready for Windows 9x
[601]112 call CMOS_Verify10hTo2Dh ; Can we modify CMOS?
113 jnz SHORT .ClearBdaDriveCount ; Unsupported BIOS, use plan B
[593]114
[601]115 ; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
[605]116 ; (but accept changes to drive type 1). Windows 9x requires that the drive 0 type is
[601]117 ; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
[605]118 ; won't give problems but Windows 9x stays in MS-DOS compatibility mode.
[601]119 ;
120 ; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
[605]121 ; So essentially we could automatically do what user needs to do manually to get Windows 9x
[601]122 ; working on Award BIOSes. However, I think that should be left to do manually since
[605]123 ; there may be SCSI drives on the system or FLG_ROMVARS_CLEAR_BDA_HD_COUNT could
[601]124 ; be intentionally cleared and forcing the dummy drive might cause only trouble.
[596]125
[601]126 ; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
127 ; there will be no need to scan E000h segment)
128 mov cx, 65536 - 4
129 mov eax, 'Awar' ; Four characters should be enough
130 mov di, 0F000h ; Scan 64k starting from segment F000h
131 mov fs, di ; No need to preserve FS since we set it to zero soon when we boot
132 xor di, di
133.ScanNextCharacters:
134 cmp [fs:di], eax
135 je SHORT .ClearBdaDriveCount ; Award detected, cannot modify CMOS
136 inc di ; Increment offset by one character (not four)
137 loop .ScanNextCharacters
[598]138
[601]139 ; Now it should be safe to write
140 mov dl, HARD_DISK_TYPES
141 mov al, 0F0h ; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
142 call CMOS_WriteALtoIndexInDL
143 call CMOS_StoreNewChecksumFor10hto2Dh
[594]144.ClearBdaDriveCount:
[605]145%endif ; MODULE_WIN9X_CMOS_HACK
[593]146
[605]147 mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
148 mov al, [es:BDA.bHDCount]
149%ifndef MODULE_MFM_COMPATIBILITY
150 ; This is excluded when MODULE_MFM_COMPATIBILITY is included because it doesn't make sense to use both at the same time anyway.
151 ; Note that the option to "Remove other hard drives" is still visible in XTIDECFG.COM for builds including MODULE_MFM_COMPATIBILITY.
152 ; Changing that option just won't do anything. We might want to remove the option for builds that contain MODULE_MFM_COMPATIBILITY
153 ; but that would require a ROMVARS flag that is probably better spent on other things.
154 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_CLEAR_BDA_HD_COUNT ; Clears CF
[593]155 jz SHORT .ContinueInitialization
[605]156%ifdef USE_UNDOC_INTEL
157 salc
158%else
159 xor al, al
160%endif
[593]161.ContinueInitialization:
[605]162%endif ; MODULE_MFM_COMPATIBILITY
163 add cl, al
164 mov [es:BDA.bHDCount], cl ; Update the system count
[601]165 or al, 80h ; Or in hard disk flag
166 mov [RAMVARS.bFirstDrv], al ; Store first drive number
[262]167
[294]168.AddFloppies:
169%ifdef MODULE_SERIAL_FLOPPY
[262]170;----------------------------------------------------------------------
171;
172; Add in any emulated serial floppy drives, finalize our packed Count and First variables
173;
174 dec ch
175 mov al, ch
[601]176 js SHORT .NoFloppies ; If no drives are present, we store 0FFh
[262]177
[258]178 call FloppyDrive_GetCountFromBIOS_or_BDA
179
180 push ax
181
[262]182 add al, ch ; Add our drives to existing drive count
[258]183 cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
[605]184 jb SHORT .MaxBDAFloppiesExceeded
[294]185 mov al, 3
[258]186.MaxBDAFloppiesExceeded:
187 eROR_IM al, 2 ; move to bits 6-7
188 inc ax ; low order bit, indicating floppy drive exists
189
[568]190 mov ah, 3Eh ; AND mask to AH (all bits set except floppy drive count/present)
191 and ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte and mask off drive number and drives present bit
[258]192 or al, ah ; Or in new values
193 mov [es:BDA.wEquipment], al ; and store
194
[568]195 mov al, 1Eh ; BDA pointer to Floppy DPT
[258]196 mov si, AH8h_FloppyDPT
197 call Interrupts_InstallHandlerToVectorInALFromCSSI
198
199 pop ax
200
[262]201 shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
[589]202 eRCL_IM al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
[294]203.NoFloppies:
[258]204 mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
[263]205%endif
[3]206 ret
207
[294]208%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[261]209 %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
210 %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."
211 %endif
[199]212%endif
213
[242]214
[3]215;--------------------------------------------------------------------
[294]216; StartDetectionWithDriveSelectByteInBHandStringInCX
[3]217; Parameters:
218; BH: Drive Select byte for Drive and Head Register
[233]219; CX: Offset to "Master" or "Slave" string
[3]220; CS:BP: Ptr to IDEVARS for the drive
221; DS: RAMVARS segment
222; ES: Zero (BDA segment)
223; Returns:
[567]224; Nothing
[3]225; Corrupts registers:
[473]226; AX, BL, CX, DX, SI, DI
[3]227;--------------------------------------------------------------------
[294]228StartDetectionWithDriveSelectByteInBHandStringInCX:
[474]229 call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
230 ; Fall to .ReadAtaInfoFromHardDisk
[473]231
[474]232
[3]233;--------------------------------------------------------------------
[120]234; .ReadAtaInfoFromHardDisk
[3]235; Parameters:
236; BH: Drive Select byte for Drive and Head Register
[473]237; DX: Autodetected port (for devices that support autodetection)
[3]238; CS:BP: Ptr to IDEVARS for the drive
239; DS: RAMVARS segment
240; ES: Zero (BDA segment)
241; Returns:
242; CF: Cleared if ATA-information read successfully
243; Set if any error
244; Corrupts registers:
[150]245; AX, BL, CX, DX, SI, DI
[3]246;--------------------------------------------------------------------
[120]247.ReadAtaInfoFromHardDisk:
[601]248 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
[150]249 push es
250 push si
[473]251 push dx
[150]252 push bx
253 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
254 pop bx
[473]255 pop dx
[150]256 pop si
257 pop es
[120]258 jnc SHORT CreateBiosTablesForHardDisk
259 ; Fall to .ReadAtapiInfoFromDrive
[3]260
[601]261.ReadAtapiInfoFromDrive: ; Not yet implemented
262 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
[120]263 ;jnc SHORT _CreateBiosTablesForCDROM
[242]264
[203]265 ;jmp short DetectDrives_DriveNotFound
266;;; fall-through instead of previous jmp instruction
267;--------------------------------------------------------------------
268; DetectDrives_DriveNotFound
269; Parameters:
270; Nothing
271; Returns:
[567]272; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
[203]273; Corrupts registers:
274; AX, SI
275;--------------------------------------------------------------------
[242]276DetectDrives_DriveNotFound:
[203]277 mov si, g_szNotFound
[386]278 jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
[3]279
[120]280
[3]281;--------------------------------------------------------------------
[98]282; CreateBiosTablesForHardDisk
[3]283; Parameters:
284; BH: Drive Select byte for Drive and Head Register
[473]285; DX: Autodetected port (for devices that support autodetection)
[3]286; CS:BP: Ptr to IDEVARS for the drive
[150]287; ES:SI Ptr to ATA information for the drive
[3]288; DS: RAMVARS segment
[397]289; ES: BDA segment
[3]290; Returns:
[98]291; Nothing
[3]292; Corrupts registers:
[98]293; AX, BX, CX, DX, SI, DI
[3]294;--------------------------------------------------------------------
[98]295CreateBiosTablesForHardDisk:
[580]296%ifndef NO_ATAID_VALIDATION
[441]297 push bx
298 call AtaID_VerifyFromESSI
299 pop bx
[567]300 jnz SHORT DetectDrives_DriveNotFound
[580]301%endif
[3]302 call CreateDPT_FromAtaInformation
[196]303 jc SHORT DetectDrives_DriveNotFound
[397]304 call DriveDetectInfo_CreateForHardDisk
305 jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
Note: See TracBrowser for help on using the repository browser.