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

Last change on this file since 491 was 491, checked in by krille_n_@…, 12 years ago

Changes:

  • Added a new define (USE_UNDOC_INTEL) that enables optimizations possible by using undocumented instructions available on all Intel processors and truly compatible clones. AFAIK the only exceptions are the NEC V-series and the Sony CXQ70108 processors so this option should be safe for use on the AT builds.
  • Building BIOSDRVS or the BIOS without MODULE_STRINGS_COMPRESSED would fail due to the recent code exclusions so I changed them a bit. Also fixed the mistaken change to Main.asm
  • Changed the Tandy specific info in Configuration_FullMode.txt so it matches the info in the Wiki.
  • Optimizations and fixes in general.
File size: 9.7 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
[376]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 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.
[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
[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;
[233]64 call FindDPT_ToDSDIforSerialDevice
[262]65 jnc .AddHardDisks
[233]66
[242]67 mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
68
[200]69 mov al,[cs:ROMVARS.wFlags] ; Configurator set to always scan?
70 or al,[es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
71 and al,8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
[242]72 jnz .DriveDetectLoop
[233]73%endif
[203]74
[262]75.AddHardDisks:
[258]76;----------------------------------------------------------------------
77;
[262]78; Add in hard disks to BDA, finalize our Count and First variables
[258]79;
[269]80; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
81; This is done because we use the value of .bFirstDrv to know how many drives were in the system
82; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
83; FindDPT_ForDriveNumber will not find any drives that are ours.
84;
[262]85 mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
[258]86
[262]87 mov al, [es:BDA.bHDCount]
88 add cl, al ; Add our drives to the system count
[294]89 mov [es:BDA.bHDCount], cl
90 or al, 80h ; Or in hard disk flag
91 mov [RAMVARS.bFirstDrv], al ; Store first drive number
[262]92
[294]93.AddFloppies:
94%ifdef MODULE_SERIAL_FLOPPY
[262]95;----------------------------------------------------------------------
96;
97; Add in any emulated serial floppy drives, finalize our packed Count and First variables
98;
99 dec ch
100 mov al, ch
[294]101 js .NoFloppies ; if no drives are present, we store 0ffh
[262]102
[258]103 call FloppyDrive_GetCountFromBIOS_or_BDA
104
105 push ax
106
[262]107 add al, ch ; Add our drives to existing drive count
[258]108 cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
[294]109 jb .MaxBDAFloppiesExceeded
110 mov al, 3
[258]111.MaxBDAFloppiesExceeded:
112 eROR_IM al, 2 ; move to bits 6-7
113 inc ax ; low order bit, indicating floppy drive exists
114
[294]115 mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
[258]116 and ah, 03eh ; Mask off drive number and drives present bit
117 or al, ah ; Or in new values
118 mov [es:BDA.wEquipment], al ; and store
119
120 mov al, 1eh ; BDA pointer to Floppy DPT
121 mov si, AH8h_FloppyDPT
122 call Interrupts_InstallHandlerToVectorInALFromCSSI
123
124 pop ax
125
[262]126 shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
[258]127 rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
[294]128.NoFloppies:
[258]129 mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
[263]130%endif
[294]131
[3]132 ret
133
[294]134%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[261]135 %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
136 %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."
137 %endif
[199]138%endif
139
[242]140
[3]141;--------------------------------------------------------------------
[294]142; StartDetectionWithDriveSelectByteInBHandStringInCX
[3]143; Parameters:
144; BH: Drive Select byte for Drive and Head Register
[233]145; CX: Offset to "Master" or "Slave" string
[3]146; CS:BP: Ptr to IDEVARS for the drive
147; DS: RAMVARS segment
148; ES: Zero (BDA segment)
149; Returns:
[203]150; None
[3]151; Corrupts registers:
[473]152; AX, BL, CX, DX, SI, DI
[3]153;--------------------------------------------------------------------
[294]154StartDetectionWithDriveSelectByteInBHandStringInCX:
[491]155%ifdef MODULE_8BIT_IDE
[474]156 ; Autodetect port for XT-CF
[473]157 call DetectDrives_DoesIdevarsInCSBPbelongToXTCF
158 jne SHORT .SkipXTCFportDetection
159
[474]160 ; XT-CF do not support slave drives so skip detection
161 test bh, FLG_DRVNHEAD_DRV
162 jnz SHORT NoSlaveDriveAvailable
163
[473]164 ; XT-CF do not support slave drives so we can safely update port
165 ; for next drive (another XT-CF card on same system)
166.DetectNextPort:
[491]167 mov dx, [es:BOOTVARS.wNextXTCFportToScan]
168 xor dl, 40h
169 jnz SHORT .StoreNextXTCFportToScan
170 inc dh
171 cmp dh, XTCF_BASE_PORT_4 >> 8
[474]172 ja SHORT .SkipXTCFportDetection ; XT-CF not found from any port
[491]173.StoreNextXTCFportToScan:
174 mov [es:BOOTVARS.wNextXTCFportToScan], dx
[473]175
176 call AH1Eh_DetectXTCFwithBasePortInDX
177 jc SHORT .DetectNextPort ; XT-CF not found from this port
[474]178
179 ; We now have autodetected port in DX
180 push dx
181 xchg ax, dx ; Port to print in AX
182 call DetectPrint_StartDetectWithAutodetectedBasePortInAXandIdeVarsInCSBP
183 jmp SHORT .DriveDetectionStringPrintedOnScreen
184
[491]185 ; Print detect string for devices that do not support autodetection
[473]186.SkipXTCFportDetection:
[474]187 push dx
[473]188%endif ; MODULE_8BIT_IDE
[3]189
[474]190 call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
191.DriveDetectionStringPrintedOnScreen:
192%ifdef MODULE_HOTKEYS
193 call HotkeyBar_UpdateDuringDriveDetection
194%endif
195%ifdef MODULE_8BIT_IDE
196 pop dx
197%endif
198 ; Fall to .ReadAtaInfoFromHardDisk
[473]199
[474]200
[3]201;--------------------------------------------------------------------
[120]202; .ReadAtaInfoFromHardDisk
[3]203; Parameters:
204; BH: Drive Select byte for Drive and Head Register
[473]205; DX: Autodetected port (for devices that support autodetection)
[3]206; CS:BP: Ptr to IDEVARS for the drive
207; DS: RAMVARS segment
208; ES: Zero (BDA segment)
209; Returns:
210; CF: Cleared if ATA-information read successfully
211; Set if any error
212; Corrupts registers:
[150]213; AX, BL, CX, DX, SI, DI
[3]214;--------------------------------------------------------------------
[120]215.ReadAtaInfoFromHardDisk:
[150]216 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
217 push es
218 push si
[473]219 push dx
[150]220 push bx
221 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
222 pop bx
[473]223 pop dx
[150]224 pop si
225 pop es
[120]226 jnc SHORT CreateBiosTablesForHardDisk
227 ; Fall to .ReadAtapiInfoFromDrive
[3]228
[120]229.ReadAtapiInfoFromDrive: ; Not yet implemented
230 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
231 ;jnc SHORT _CreateBiosTablesForCDROM
[242]232
[203]233 ;jmp short DetectDrives_DriveNotFound
234;;; fall-through instead of previous jmp instruction
235;--------------------------------------------------------------------
236; DetectDrives_DriveNotFound
237; Parameters:
238; Nothing
239; Returns:
240; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
241; Corrupts registers:
242; AX, SI
243;--------------------------------------------------------------------
[242]244DetectDrives_DriveNotFound:
[203]245 mov si, g_szNotFound
[386]246 jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
[3]247
[120]248
[3]249;--------------------------------------------------------------------
[98]250; CreateBiosTablesForHardDisk
[3]251; Parameters:
252; BH: Drive Select byte for Drive and Head Register
[473]253; DX: Autodetected port (for devices that support autodetection)
[3]254; CS:BP: Ptr to IDEVARS for the drive
[150]255; ES:SI Ptr to ATA information for the drive
[3]256; DS: RAMVARS segment
[397]257; ES: BDA segment
[3]258; Returns:
[98]259; Nothing
[3]260; Corrupts registers:
[98]261; AX, BX, CX, DX, SI, DI
[3]262;--------------------------------------------------------------------
[98]263CreateBiosTablesForHardDisk:
[441]264 push bx
265 call AtaID_VerifyFromESSI
266 pop bx
267 jc SHORT DetectDrives_DriveNotFound
[3]268 call CreateDPT_FromAtaInformation
[196]269 jc SHORT DetectDrives_DriveNotFound
[397]270 call DriveDetectInfo_CreateForHardDisk
271 jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
[473]272
273
274%ifdef MODULE_8BIT_IDE
275;--------------------------------------------------------------------
276; DetectDrives_DoesIdevarsInCSBPbelongToXTCF
277; Parameters:
278; CS:BP: Ptr to IDEVARS for the drive
279; Returns:
280; ZF: Set if IDEVARS belongs to XT-CF device
281; Cleared if some other device
282; Corrupts registers:
283; AL
284;--------------------------------------------------------------------
285DetectDrives_DoesIdevarsInCSBPbelongToXTCF:
286 mov al, [cs:bp+IDEVARS.bDevice]
287 cmp al, DEVICE_8BIT_XTCF_PIO8
288 je SHORT .DeviceIsXTCF
289 cmp al, DEVICE_8BIT_XTCF_DMA
290 je SHORT .DeviceIsXTCF
291 cmp al, DEVICE_8BIT_XTCF_MEMMAP
292.DeviceIsXTCF:
[474]293NoSlaveDriveAvailable:
[473]294 ret
295%endif ; MODULE_8BIT_IDE
Note: See TracBrowser for help on using the repository browser.