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

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

Changes:

  • Renamed MODULE_FEATURE_SETS to MODULE_POWER_MANAGEMENT.
  • Renamed MODULE_VERY_LATE_INITIALIZATION to MODULE_VERY_LATE_INIT and removed it from the official builds.
  • Removed the code that skips detection of slave drives on XT-CF controllers since slave drives can be used with Lo-tech ISA CompactFlash boards.
  • Added autodetection of the SVC ADP50L controller to XTIDECFG.
  • The autodetection of XT-CF controllers now requires MODULE_8BIT_IDE_ADVANCED in the loaded BIOS.
  • Fixed a bug in XTIDECFG from r502 where the "Base (cmd block) address" menu option would be displayed when a serial device was selected as the IDE controller.
  • XTIDECFG would display the "Enable interrupt" menu option for the XTIDE r1 but not for the XTIDE r2. It's now displayed for both controller types.
  • Disabled the "Internal Write Cache" menu option in the Master/Slave Drive menus for serial device type drives.
  • Optimizations and other fixes.
File size: 8.0 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for detecting drive for the BIOS.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
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:
36 call RamVars_GetIdeControllerCountToCX
37 mov bp, ROMVARS.ideVars0 ; CS:BP now points to first IDEVARS
38
39.DriveDetectLoop: ; Loop through IDEVARS
40 push cx
41
42 mov cx, g_szDetectMaster
43 mov bh, MASK_DRVNHEAD_SET ; Select Master drive
44 call StartDetectionWithDriveSelectByteInBHandStringInCX ; Detect and create DPT + BOOTNFO
45
46 mov cx, g_szDetectSlave
47 mov bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
48 call StartDetectionWithDriveSelectByteInBHandStringInCX
49
50 pop cx
51
52 add bp, BYTE IDEVARS_size ; Point to next IDEVARS
53
54%ifdef MODULE_SERIAL
55 jcxz .AddHardDisks ; Set to zero on .ideVarsSerialAuto iteration (if any)
56%endif
57 loop .DriveDetectLoop
58
59%ifdef MODULE_SERIAL
60;----------------------------------------------------------------------
61;
62; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
63;
64 call FindDPT_ToDSDIforSerialDevice ; Does not modify AX
65 jnc .AddHardDisks
66
67 mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
68
69%ifdef MODULE_HOTKEYS
70 cmp al, COM_DETECT_HOTKEY_SCANCODE ; Set by last call to HotkeyBar_UpdateDuringDriveDetection above
71 je .DriveDetectLoop
72%endif
73
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
77 jnz .DriveDetectLoop
78%endif
79
80.AddHardDisks:
81;----------------------------------------------------------------------
82;
83; Add in hard disks to BDA, finalize our Count and First variables
84;
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;
90 mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
91
92 mov al, [es:BDA.bHDCount]
93 add cl, al ; Add our drives to the system count
94 mov [es:BDA.bHDCount], cl
95 or al, 80h ; Or in hard disk flag
96 mov [RAMVARS.bFirstDrv], al ; Store first drive number
97
98.AddFloppies:
99%ifdef MODULE_SERIAL_FLOPPY
100;----------------------------------------------------------------------
101;
102; Add in any emulated serial floppy drives, finalize our packed Count and First variables
103;
104 dec ch
105 mov al, ch
106 js .NoFloppies ; if no drives are present, we store 0ffh
107
108 call FloppyDrive_GetCountFromBIOS_or_BDA
109
110 push ax
111
112 add al, ch ; Add our drives to existing drive count
113 cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
114 jb .MaxBDAFloppiesExceeded
115 mov al, 3
116.MaxBDAFloppiesExceeded:
117 eROR_IM al, 2 ; move to bits 6-7
118 inc ax ; low order bit, indicating floppy drive exists
119
120 mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
121 and ah, 03eh ; Mask off drive number and drives present bit
122 or al, ah ; Or in new values
123 mov [es:BDA.wEquipment], al ; and store
124
125 mov al, 1eh ; BDA pointer to Floppy DPT
126 mov si, AH8h_FloppyDPT
127 call Interrupts_InstallHandlerToVectorInALFromCSSI
128
129 pop ax
130
131 shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
132 rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
133.NoFloppies:
134 mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
135%endif
136 ret
137
138%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
139 %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
140 %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."
141 %endif
142%endif
143
144
145;--------------------------------------------------------------------
146; StartDetectionWithDriveSelectByteInBHandStringInCX
147; Parameters:
148; BH: Drive Select byte for Drive and Head Register
149; CX: Offset to "Master" or "Slave" string
150; CS:BP: Ptr to IDEVARS for the drive
151; DS: RAMVARS segment
152; ES: Zero (BDA segment)
153; Returns:
154; Nothing
155; Corrupts registers:
156; AX, BL, CX, DX, SI, DI
157;--------------------------------------------------------------------
158StartDetectionWithDriveSelectByteInBHandStringInCX:
159 call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
160
161%ifdef MODULE_HOTKEYS
162 call HotkeyBar_UpdateDuringDriveDetection
163%endif
164 ; Fall to .ReadAtaInfoFromHardDisk
165
166
167;--------------------------------------------------------------------
168; .ReadAtaInfoFromHardDisk
169; Parameters:
170; BH: Drive Select byte for Drive and Head Register
171; DX: Autodetected port (for devices that support autodetection)
172; CS:BP: Ptr to IDEVARS for the drive
173; DS: RAMVARS segment
174; ES: Zero (BDA segment)
175; Returns:
176; CF: Cleared if ATA-information read successfully
177; Set if any error
178; Corrupts registers:
179; AX, BL, CX, DX, SI, DI
180;--------------------------------------------------------------------
181.ReadAtaInfoFromHardDisk:
182 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
183 push es
184 push si
185 push dx
186 push bx
187 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
188 pop bx
189 pop dx
190 pop si
191 pop es
192 jnc SHORT CreateBiosTablesForHardDisk
193 ; Fall to .ReadAtapiInfoFromDrive
194
195.ReadAtapiInfoFromDrive: ; Not yet implemented
196 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
197 ;jnc SHORT _CreateBiosTablesForCDROM
198
199 ;jmp short DetectDrives_DriveNotFound
200;;; fall-through instead of previous jmp instruction
201;--------------------------------------------------------------------
202; DetectDrives_DriveNotFound
203; Parameters:
204; Nothing
205; Returns:
206; CF: Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
207; Corrupts registers:
208; AX, SI
209;--------------------------------------------------------------------
210DetectDrives_DriveNotFound:
211 mov si, g_szNotFound
212 jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
213
214
215;--------------------------------------------------------------------
216; CreateBiosTablesForHardDisk
217; Parameters:
218; BH: Drive Select byte for Drive and Head Register
219; DX: Autodetected port (for devices that support autodetection)
220; CS:BP: Ptr to IDEVARS for the drive
221; ES:SI Ptr to ATA information for the drive
222; DS: RAMVARS segment
223; ES: BDA segment
224; Returns:
225; Nothing
226; Corrupts registers:
227; AX, BX, CX, DX, SI, DI
228;--------------------------------------------------------------------
229CreateBiosTablesForHardDisk:
230 push bx
231 call AtaID_VerifyFromESSI
232 pop bx
233 jnz SHORT DetectDrives_DriveNotFound
234 call CreateDPT_FromAtaInformation
235 jc SHORT DetectDrives_DriveNotFound
236 call DriveDetectInfo_CreateForHardDisk
237 jmp SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
Note: See TracBrowser for help on using the repository browser.