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
|
---|
21 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
35 | DetectDrives_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
|
---|
65 | jnc .AddHardDisks
|
---|
66 |
|
---|
67 | mov bp, ROMVARS.ideVarsSerialAuto ; Point to our special IDEVARS structure, just for serial scans
|
---|
68 |
|
---|
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
|
---|
72 | jnz .DriveDetectLoop
|
---|
73 | %endif
|
---|
74 |
|
---|
75 | .AddHardDisks:
|
---|
76 | ;----------------------------------------------------------------------
|
---|
77 | ;
|
---|
78 | ; Add in hard disks to BDA, finalize our Count and First variables
|
---|
79 | ;
|
---|
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 | ;
|
---|
85 | mov cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
|
---|
86 |
|
---|
87 | mov al, [es:BDA.bHDCount]
|
---|
88 | add cl, al ; Add our drives to the system count
|
---|
89 | mov [es:BDA.bHDCount], cl
|
---|
90 | or al, 80h ; Or in hard disk flag
|
---|
91 | mov [RAMVARS.bFirstDrv], al ; Store first drive number
|
---|
92 |
|
---|
93 | .AddFloppies:
|
---|
94 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
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
|
---|
101 | js .NoFloppies ; if no drives are present, we store 0ffh
|
---|
102 |
|
---|
103 | call FloppyDrive_GetCountFromBIOS_or_BDA
|
---|
104 |
|
---|
105 | push ax
|
---|
106 |
|
---|
107 | add al, ch ; Add our drives to existing drive count
|
---|
108 | cmp al, 3 ; For BDA, max out at 4 drives (ours is zero based)
|
---|
109 | jb .MaxBDAFloppiesExceeded
|
---|
110 | mov al, 3
|
---|
111 | .MaxBDAFloppiesExceeded:
|
---|
112 | eROR_IM al, 2 ; move to bits 6-7
|
---|
113 | inc ax ; low order bit, indicating floppy drive exists
|
---|
114 |
|
---|
115 | mov ah, [es:BDA.wEquipment] ; Load Equipment WORD low byte
|
---|
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 |
|
---|
126 | shr ch, 1 ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
|
---|
127 | rcl al, 1 ; starting drive number in upper 7 bits, number of drives in low bit
|
---|
128 | .NoFloppies:
|
---|
129 | mov [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
|
---|
130 | %endif
|
---|
131 |
|
---|
132 | ret
|
---|
133 |
|
---|
134 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
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
|
---|
138 | %endif
|
---|
139 |
|
---|
140 |
|
---|
141 | ;--------------------------------------------------------------------
|
---|
142 | ; StartDetectionWithDriveSelectByteInBHandStringInCX
|
---|
143 | ; Parameters:
|
---|
144 | ; BH: Drive Select byte for Drive and Head Register
|
---|
145 | ; CX: Offset to "Master" or "Slave" string
|
---|
146 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
147 | ; DS: RAMVARS segment
|
---|
148 | ; ES: Zero (BDA segment)
|
---|
149 | ; Returns:
|
---|
150 | ; None
|
---|
151 | ; Corrupts registers:
|
---|
152 | ; AX, BX, CX, DX, SI, DI
|
---|
153 | ;--------------------------------------------------------------------
|
---|
154 | StartDetectionWithDriveSelectByteInBHandStringInCX:
|
---|
155 | call DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
|
---|
156 | %ifdef MODULE_HOTKEYS
|
---|
157 | call HotkeyBar_UpdateDuringDriveDetection
|
---|
158 | %endif
|
---|
159 | ; Fall to .ReadAtaInfoFromHardDisk
|
---|
160 |
|
---|
161 | ;--------------------------------------------------------------------
|
---|
162 | ; .ReadAtaInfoFromHardDisk
|
---|
163 | ; Parameters:
|
---|
164 | ; BH: Drive Select byte for Drive and Head Register
|
---|
165 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
166 | ; DS: RAMVARS segment
|
---|
167 | ; ES: Zero (BDA segment)
|
---|
168 | ; Returns:
|
---|
169 | ; CF: Cleared if ATA-information read successfully
|
---|
170 | ; Set if any error
|
---|
171 | ; Corrupts registers:
|
---|
172 | ; AX, BL, CX, DX, SI, DI
|
---|
173 | ;--------------------------------------------------------------------
|
---|
174 | .ReadAtaInfoFromHardDisk:
|
---|
175 | mov si, BOOTVARS.rgbAtaInfo ; ES:SI now points to ATA info location
|
---|
176 | push es
|
---|
177 | push si
|
---|
178 | push bx
|
---|
179 | call Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
180 | pop bx
|
---|
181 | pop si
|
---|
182 | pop es
|
---|
183 | jnc SHORT CreateBiosTablesForHardDisk
|
---|
184 | ; Fall to .ReadAtapiInfoFromDrive
|
---|
185 |
|
---|
186 | .ReadAtapiInfoFromDrive: ; Not yet implemented
|
---|
187 | ;call ReadAtapiInfoFromDrive ; Assume CD-ROM
|
---|
188 | ;jnc SHORT _CreateBiosTablesForCDROM
|
---|
189 |
|
---|
190 | ;jmp short DetectDrives_DriveNotFound
|
---|
191 | ;;; fall-through instead of previous jmp instruction
|
---|
192 | ;--------------------------------------------------------------------
|
---|
193 | ; DetectDrives_DriveNotFound
|
---|
194 | ; Parameters:
|
---|
195 | ; Nothing
|
---|
196 | ; Returns:
|
---|
197 | ; CF: Set (from BootMenuPrint_NullTerminatedStringFromCSSIandSetCF)
|
---|
198 | ; Corrupts registers:
|
---|
199 | ; AX, SI
|
---|
200 | ;--------------------------------------------------------------------
|
---|
201 | DetectDrives_DriveNotFound:
|
---|
202 | mov si, g_szNotFound
|
---|
203 | jmp DetectPrint_NullTerminatedStringFromCSSIandSetCF
|
---|
204 |
|
---|
205 |
|
---|
206 | ;--------------------------------------------------------------------
|
---|
207 | ; CreateBiosTablesForHardDisk
|
---|
208 | ; Parameters:
|
---|
209 | ; BH: Drive Select byte for Drive and Head Register
|
---|
210 | ; CS:BP: Ptr to IDEVARS for the drive
|
---|
211 | ; ES:SI Ptr to ATA information for the drive
|
---|
212 | ; DS: RAMVARS segment
|
---|
213 | ; ES: BDA/Bootnfo segment
|
---|
214 | ; Returns:
|
---|
215 | ; Nothing
|
---|
216 | ; Corrupts registers:
|
---|
217 | ; AX, BX, CX, DX, SI, DI
|
---|
218 | ;--------------------------------------------------------------------
|
---|
219 | CreateBiosTablesForHardDisk:
|
---|
220 | call CreateDPT_FromAtaInformation
|
---|
221 | jc SHORT DetectDrives_DriveNotFound
|
---|
222 | call BootMenuInfo_CreateForHardDisk
|
---|
223 | jmp SHORT DetectPrint_DriveNameFromBootnfoInESBX
|
---|