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

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

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 7.6 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-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.
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
58 loop .DriveDetectLoop
59
60%ifdef MODULE_SERIAL
61;----------------------------------------------------------------------
62;
63; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
64;
65 call FindDPT_ToDSDIforSerialDevice
66 jnc .AddHardDisks
67
68 mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
69
70 mov al,[cs:ROMVARS.wFlags] ; Configurator set to always scan?
71 or al,[es:BDA.bKBFlgs1] ; Or, did the user hold down the ALT key?
72 and al,8 ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
73 jnz .DriveDetectLoop
74%endif
75
76.AddHardDisks:
77;----------------------------------------------------------------------
78;
79; Add in hard disks to BDA, finalize our Count and First variables
80;
81; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
82; This is done because we use the value of .bFirstDrv to know how many drives were in the system
83; at the time of boot, and to return that number on int13h/8h calls. Because the count is zero,
84; FindDPT_ForDriveNumber will not find any drives that are ours.
85;
86 mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
87
88 mov al, [es:BDA.bHDCount]
89 add cl, al ; Add our drives to the system count
90 mov [es:BDA.bHDCount], cl
91 or al, 80h ; Or in hard disk flag
92 mov [RAMVARS.bFirstDrv], al ; Store first drive number
93
94.AddFloppies:
95%ifdef MODULE_SERIAL_FLOPPY
96;----------------------------------------------------------------------
97;
98; Add in any emulated serial floppy drives, finalize our packed Count and First variables
99;
100 dec ch
101 mov al, ch
102 js .NoFloppies ; if no drives are present, we store 0ffh
103
104 call FloppyDrive_GetCountFromBIOS_or_BDA
105
106 push ax
107
108 add al, ch ; Add our drives to existing drive count
109 cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
110 jb .MaxBDAFloppiesExceeded
111 mov al, 3
112.MaxBDAFloppiesExceeded:
113 eROR_IM al, 2 ; move to bits 6-7
114 inc ax ; low order bit, indicating floppy drive exists
115
116 mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
117 and ah, 03eh ; Mask off drive number and drives present bit
118 or al, ah ; Or in new values
119 mov [es:BDA.wEquipment], al ; and store
120
121 mov al, 1eh ; BDA pointer to Floppy DPT
122 mov si, AH8h_FloppyDPT
123 call Interrupts_InstallHandlerToVectorInALFromCSSI
124
125 pop ax
126
127 shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
128 rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
129.NoFloppies:
130 mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
131%endif
132
133 ret
134
135%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
136 %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
137 %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."
138 %endif
139%endif
140
141
142;--------------------------------------------------------------------
143; StartDetectionWithDriveSelectByteInBHandStringInCX
144; Parameters:
145; BH: Drive Select byte for Drive and Head Register
146; CX: Offset to "Master" or "Slave" string
147; CS:BP: Ptr to IDEVARS for the drive
148; DS: RAMVARS segment
149; ES: Zero (BDA segment)
150; Returns:
151; None
152; Corrupts registers:
153; AX, BX, CX, DX, SI, DI
154;--------------------------------------------------------------------
155StartDetectionWithDriveSelectByteInBHandStringInCX:
156 call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
157 ; Fall to .ReadAtaInfoFromHardDisk
158
159;--------------------------------------------------------------------
160; .ReadAtaInfoFromHardDisk
161; Parameters:
162; BH: Drive Select byte for Drive and Head Register
163; CS:BP: Ptr to IDEVARS for the drive
164; DS: RAMVARS segment
165; ES: Zero (BDA segment)
166; Returns:
167; CF: Cleared if ATA-information read successfully
168; Set if any error
169; Corrupts registers:
170; AX, BL, CX, DX, SI, DI
171;--------------------------------------------------------------------
172.ReadAtaInfoFromHardDisk:
173 mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
174 push es
175 push si
176 push bx
177 call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
178 pop bx
179 pop si
180 pop es
181 jnc SHORT CreateBiosTablesForHardDisk
182 ; Fall to .ReadAtapiInfoFromDrive
183
184.ReadAtapiInfoFromDrive: ; Not yet implemented
185 ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
186 ;jnc SHORT _CreateBiosTablesForCDROM
187
188 ;jmp short DetectDrives_DriveNotFound
189;;; fall-through instead of previous jmp instruction
190;--------------------------------------------------------------------
191; DetectDrives_DriveNotFound
192; Parameters:
193; Nothing
194; Returns:
195; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
196; Corrupts registers:
197; AX, SI
198;--------------------------------------------------------------------
199DetectDrives_DriveNotFound:
200 mov si, g_szNotFound
201 jmp BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
202
203
204;--------------------------------------------------------------------
205; CreateBiosTablesForHardDisk
206; Parameters:
207; BH: Drive Select byte for Drive and Head Register
208; CS:BP: Ptr to IDEVARS for the drive
209; ES:SI Ptr to ATA information for the drive
210; DS: RAMVARS segment
211; ES: BDA/Bootnfo segment
212; Returns:
213; Nothing
214; Corrupts registers:
215; AX, BX, CX, DX, SI, DI
216;--------------------------------------------------------------------
217CreateBiosTablesForHardDisk:
218 call CreateDPT_FromAtaInformation
219 jc SHORT DetectDrives_DriveNotFound
220 call BootMenuInfo_CreateForHardDisk
221 jmp short DetectPrint_DriveNameFromBootnfoInESBX
Note: See TracBrowser for help on using the repository browser.