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

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

Changes:

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