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

Last change on this file since 202 was 200, checked in by gregli@…, 13 years ago

Added logic to skip scanning COM ports if a COM port was already found during the normal detection process, to avoid finding the same serial drive twice and preseting the OS with two drives which in reality point to the same physical file on the server. Also added logic to skip scanning for the slave serial drive if the master was not found. And various small optimizations.

File size: 6.1 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for detecting drive for the BIOS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Detects all IDE hard disks to be controlled by this BIOS.
9;
10; DetectDrives_FromAllIDEControllers
11; Parameters:
12; DS: RAMVARS segment
13; ES: BDA segment (zero)
14; Returns:
15; Nothing
16; Corrupts registers:
17; All (not segments)
18;--------------------------------------------------------------------
19DetectDrives_FromAllIDEControllers:
[33]20 call RamVars_GetIdeControllerCountToCX
[3]21 mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
[200]22
23.DriveDetectLoop: ; Loop through IDEVARS
24 mov si, g_szDetect ; Setup standard print string
[196]25%ifdef MODULE_SERIAL
26 cmp byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
[200]27 jnz .DriveNotSerial ; Special print string for serial drives
[196]28 mov si, g_szDetectCOM
29.DriveNotSerial:
30%endif
[175]31 call .DetectDrives_WithIDEVARS ; Detect Master and Slave
[3]32 add bp, BYTE IDEVARS_size ; Point to next IDEVARS
33 loop .DriveDetectLoop
[200]34
[175]35%ifdef MODULE_SERIAL
[200]36 call FindDPT_ToDSDIforSerialDevice ; Did we already find any serial drives?
37 jc .done ; Yes, do not scan
38 mov al,[cs:ROMVARS.wFlags] ; Configurator set to always scan?
39 or al,[es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
40 and al,8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
41 jz .done
42 mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS sructure, just for serial scans
43 mov si, g_szDetectCOMAuto ; Special, special print string for serial drives during a scan
[199]44;;; fall-through
[175]45%else
[3]46 ret
[175]47%endif
[3]48
[199]49%if FLG_ROMVARS_SERIAL_SCANDETECT != 8
[200]50%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."
[199]51%endif
52
[3]53;--------------------------------------------------------------------
54; Detects IDE hard disks by using information from IDEVARS.
55;
56; DetectDrives_WithIDEVARS
57; Parameters:
58; CS:BP: Ptr to IDEVARS
59; DS: RAMVARS segment
60; ES: Zero (BDA segment)
[189]61; SI: Ptr to template string
[3]62; Returns:
63; Nothing
64; Corrupts registers:
65; AX, BX, DX, SI, DI
66;--------------------------------------------------------------------
[175]67.DetectDrives_WithIDEVARS:
[3]68 push cx
[196]69
70 push si
[97]71 mov ax, g_szMaster
[150]72 mov bh, MASK_DRVNHEAD_SET ; Select Master drive
[98]73 call StartDetectionWithDriveSelectByteInBHandStringInAX ; Detect and create DPT + BOOTNFO
[189]74 pop si
[196]75
[200]76%ifdef MODULE_SERIAL
77;
78; This block of code checks to see if we found a master during a serial drives scan. If no master
79; was found, there is no point in scanning for a slave as the server will not return a slave without a master,
80; as there is very little point given the drives are emulated. Performing the slave scan will take
81; time to rescan all the COM port and baud rate combinations.
82;
83 jnc .masterFound
84 pop cx
85 jcxz .done ; note that CX will only be zero after the .DriveDetectLoop, indicating a serial scan
86 push cx
87.masterFound:
88%endif
89
[97]90 mov ax, g_szSlave
[150]91 mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
[98]92 call StartDetectionWithDriveSelectByteInBHandStringInAX
[3]93 pop cx
[200]94
[175]95.done:
[3]96 ret
97
[175]98
[3]99;--------------------------------------------------------------------
[98]100; StartDetectionWithDriveSelectByteInBHandStringInAX
[3]101; Parameters:
[98]102; AX: Offset to "Master" or "Slave" string
[3]103; BH: Drive Select byte for Drive and Head Register
104; CS:BP: Ptr to IDEVARS for the drive
105; DS: RAMVARS segment
106; ES: Zero (BDA segment)
107; Returns:
[200]108; CF: Set on failure, Clear on success
109; Note that this is set in the last thing both cases
110; do: printing the drive name, or printing "Not Found"
[3]111; Corrupts registers:
[98]112; AX, BX, CX, DX, SI, DI
[3]113;--------------------------------------------------------------------
[98]114StartDetectionWithDriveSelectByteInBHandStringInAX:
115 call DetectPrint_StartDetectWithMasterOrSlaveStringInAXandIdeVarsInCSBP
[120]116 ; Fall to .ReadAtaInfoFromHardDisk
[3]117
118;--------------------------------------------------------------------
[120]119; .ReadAtaInfoFromHardDisk
[3]120; Parameters:
121; BH: Drive Select byte for Drive and Head Register
122; CS:BP: Ptr to IDEVARS for the drive
123; DS: RAMVARS segment
124; ES: Zero (BDA segment)
125; Returns:
126; CF: Cleared if ATA-information read successfully
127; Set if any error
128; Corrupts registers:
[150]129; AX, BL, CX, DX, SI, DI
[3]130;--------------------------------------------------------------------
[120]131.ReadAtaInfoFromHardDisk:
[150]132 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
133 push es
134 push si
135 push bx
136 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
137 pop bx
138 pop si
139 pop es
[120]140 jnc SHORT CreateBiosTablesForHardDisk
141 ; Fall to .ReadAtapiInfoFromDrive
[3]142
[120]143.ReadAtapiInfoFromDrive: ; Not yet implemented
144 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
145 ;jnc SHORT _CreateBiosTablesForCDROM
[196]146 jmp short DetectDrives_DriveNotFound
[3]147
[120]148
[3]149;--------------------------------------------------------------------
[98]150; CreateBiosTablesForHardDisk
[3]151; Parameters:
152; BH: Drive Select byte for Drive and Head Register
153; CS:BP: Ptr to IDEVARS for the drive
[150]154; ES:SI Ptr to ATA information for the drive
[3]155; DS: RAMVARS segment
[98]156; ES: BDA/Bootnfo segment
[3]157; Returns:
[98]158; Nothing
[3]159; Corrupts registers:
[98]160; AX, BX, CX, DX, SI, DI
[3]161;--------------------------------------------------------------------
[98]162CreateBiosTablesForHardDisk:
[3]163 call CreateDPT_FromAtaInformation
[196]164 jc SHORT DetectDrives_DriveNotFound
[3]165 call BootInfo_CreateForHardDisk
[196]166 jmp short DetectPrint_DriveNameFromBootnfoInESBX
167
168;--------------------------------------------------------------------
169; DetectDrives_DriveNotFound
170; Parameters:
171; Nothing
172; Returns:
[200]173; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
[196]174; Corrupts registers:
175; AX, SI
176;--------------------------------------------------------------------
177DetectDrives_DriveNotFound:
178 mov si, g_szNotFound
179 jmp BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
180
Note: See TracBrowser for help on using the repository browser.