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

Last change on this file since 602 was 601, checked in by Krister Nordvall, 6 years ago

Changes:

  • Building the BIOS now works again.
  • Added a new IDE device type/transfer mode for use only with XT-IDE rev 2+ (or Chuck(G)-modded rev 1) cards installed in any of the following machines: Olivetti M24, AT&T PC6300, Xerox 6060 and Logabax Persona 1600. This new transfer mode is slightly faster than the regular XT-IDE rev 1 device type and requires that the card is configured for High Speed mode (or, in case of the card being a rev 1 card, has the Chuck(G) mod done). The new device type is called "XTIDE rev 2 (Olivetti M24)" in XTIDECFG.
  • Made some minor improvements to the library code that handles 'Drive Not Ready' errors in XTIDECFG.
  • Optimizations.
File size: 11.3 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
[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
[601]100; is a hack to get Windows 95 to load its built-in protected mode IDE driver.
[596]101;
[593]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
[596]104; systems since CMOS has a checksum but its location is not standardized. We will first
[593]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
[601]111%ifdef MODULE_WIN95_CMOS_HACK
112 mov dl, HARD_DISK_TYPES
113 call CMOS_ReadFromIndexInDLtoAL
114 test al, 0F0h
115 jnz SHORT .ClearBdaDriveCount ; CMOS byte 12h is ready for Windows 95
116 call CMOS_Verify10hTo2Dh ; Can we modify CMOS?
117 jnz SHORT .ClearBdaDriveCount ; Unsupported BIOS, use plan B
[593]118
[601]119 ; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
120 ; (but accept changes to drive type 1). Windows 95 requires that the drive 0 type is
121 ; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
122 ; won't give problems but Windows 95 stays in MS-DOS compatibility mode.
123 ;
124 ; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
125 ; So essentially we could automatically do what user needs to do manually to get Windows 95
126 ; working on Award BIOSes. However, I think that should be left to do manually since
127 ; there may be SCSI drives on the system or FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES could
128 ; be intentionally cleared and forcing the dummy drive might cause only trouble.
[596]129
[601]130 ; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
131 ; there will be no need to scan E000h segment)
132 mov cx, 65536 - 4
133 mov eax, 'Awar' ; Four characters should be enough
134 mov di, 0F000h ; Scan 64k starting from segment F000h
135 mov fs, di ; No need to preserve FS since we set it to zero soon when we boot
136 xor di, di
137.ScanNextCharacters:
138 cmp [fs:di], eax
139 je SHORT .ClearBdaDriveCount ; Award detected, cannot modify CMOS
140 inc di ; Increment offset by one character (not four)
141 loop .ScanNextCharacters
[598]142
[601]143 ; Now it should be safe to write
144 mov dl, HARD_DISK_TYPES
145 mov al, 0F0h ; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
146 call CMOS_WriteALtoIndexInDL
147 call CMOS_StoreNewChecksumFor10hto2Dh
[594]148.ClearBdaDriveCount:
[601]149%endif ; MODULE_WIN95_CMOS_HACK
[593]150
151 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES
152 jz SHORT .ContinueInitialization
[601]153 mov BYTE [es:BDA.bHDCount], 0 ; Set hard disk count to zero
[593]154.ContinueInitialization:
[601]155%endif ; USE_AT
[593]156
[601]157 mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
[262]158 mov al, [es:BDA.bHDCount]
[601]159 add [es:BDA.bHDCount], cl ; Add our drives to the system count
160 or al, 80h ; Or in hard disk flag
161 mov [RAMVARS.bFirstDrv], al ; Store first drive number
[262]162
[294]163.AddFloppies:
164%ifdef MODULE_SERIAL_FLOPPY
[262]165;----------------------------------------------------------------------
166;
167; Add in any emulated serial floppy drives, finalize our packed Count and First variables
168;
169 dec ch
170 mov al, ch
[601]171 js SHORT .NoFloppies ; If no drives are present, we store 0FFh
[262]172
[258]173 call FloppyDrive_GetCountFromBIOS_or_BDA
174
175 push ax
176
[262]177 add al, ch ; Add our drives to existing drive count
[258]178 cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
[294]179 jb .MaxBDAFloppiesExceeded
180 mov al, 3
[258]181.MaxBDAFloppiesExceeded:
182 eROR_IM al, 2 ; move to bits 6-7
183 inc ax ; low order bit, indicating floppy drive exists
184
[568]185 mov ah, 3Eh ; AND mask to AH (all bits set except floppy drive count/present)
186 and ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte and mask off drive number and drives present bit
[258]187 or al, ah ; Or in new values
188 mov [es:BDA.wEquipment], al ; and store
189
[568]190 mov al, 1Eh ; BDA pointer to Floppy DPT
[258]191 mov si, AH8h_FloppyDPT
192 call Interrupts_InstallHandlerToVectorInALFromCSSI
193
194 pop ax
195
[262]196 shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
[589]197 eRCL_IM al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
[294]198.NoFloppies:
[258]199 mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
[263]200%endif
[3]201 ret
202
[294]203%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[261]204 %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
205 %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."
206 %endif
[199]207%endif
208
[242]209
[3]210;--------------------------------------------------------------------
[294]211; StartDetectionWithDriveSelectByteInBHandStringInCX
[3]212; Parameters:
213; BH: Drive Select byte for Drive and Head Register
[233]214; CX: Offset to "Master" or "Slave" string
[3]215; CS:BP: Ptr to IDEVARS for the drive
216; DS: RAMVARS segment
217; ES: Zero (BDA segment)
218; Returns:
[567]219; Nothing
[3]220; Corrupts registers:
[473]221; AX, BL, CX, DX, SI, DI
[3]222;--------------------------------------------------------------------
[294]223StartDetectionWithDriveSelectByteInBHandStringInCX:
[474]224 call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
225 ; Fall to .ReadAtaInfoFromHardDisk
[473]226
[474]227
[3]228;--------------------------------------------------------------------
[120]229; .ReadAtaInfoFromHardDisk
[3]230; Parameters:
231; BH: Drive Select byte for Drive and Head Register
[473]232; DX: Autodetected port (for devices that support autodetection)
[3]233; CS:BP: Ptr to IDEVARS for the drive
234; DS: RAMVARS segment
235; ES: Zero (BDA segment)
236; Returns:
237; CF: Cleared if ATA-information read successfully
238; Set if any error
239; Corrupts registers:
[150]240; AX, BL, CX, DX, SI, DI
[3]241;--------------------------------------------------------------------
[120]242.ReadAtaInfoFromHardDisk:
[601]243 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
[150]244 push es
245 push si
[473]246 push dx
[150]247 push bx
248 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
249 pop bx
[473]250 pop dx
[150]251 pop si
252 pop es
[120]253 jnc SHORT CreateBiosTablesForHardDisk
254 ; Fall to .ReadAtapiInfoFromDrive
[3]255
[601]256.ReadAtapiInfoFromDrive: ; Not yet implemented
257 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
[120]258 ;jnc SHORT _CreateBiosTablesForCDROM
[242]259
[203]260 ;jmp short DetectDrives_DriveNotFound
261;;; fall-through instead of previous jmp instruction
262;--------------------------------------------------------------------
263; DetectDrives_DriveNotFound
264; Parameters:
265; Nothing
266; Returns:
[567]267; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
[203]268; Corrupts registers:
269; AX, SI
270;--------------------------------------------------------------------
[242]271DetectDrives_DriveNotFound:
[203]272 mov si, g_szNotFound
[386]273 jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
[3]274
[120]275
[3]276;--------------------------------------------------------------------
[98]277; CreateBiosTablesForHardDisk
[3]278; Parameters:
279; BH: Drive Select byte for Drive and Head Register
[473]280; DX: Autodetected port (for devices that support autodetection)
[3]281; CS:BP: Ptr to IDEVARS for the drive
[150]282; ES:SI Ptr to ATA information for the drive
[3]283; DS: RAMVARS segment
[397]284; ES: BDA segment
[3]285; Returns:
[98]286; Nothing
[3]287; Corrupts registers:
[98]288; AX, BX, CX, DX, SI, DI
[3]289;--------------------------------------------------------------------
[98]290CreateBiosTablesForHardDisk:
[580]291%ifndef NO_ATAID_VALIDATION
[441]292 push bx
293 call AtaID_VerifyFromESSI
294 pop bx
[567]295 jnz SHORT DetectDrives_DriveNotFound
[580]296%endif
[3]297 call CreateDPT_FromAtaInformation
[196]298 jc SHORT DetectDrives_DriveNotFound
[397]299 call DriveDetectInfo_CreateForHardDisk
300 jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
Note: See TracBrowser for help on using the repository browser.