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

Last change on this file since 589 was 589, checked in by krille_n_, 8 years ago

Changes:

  • BIOS: Fixed a purely cosmetic bug from r542 where, in builds containing MODULE_EBIOS, the boot menu would display an incorrect drive size (0.4 kB with MODULE_STRINGS_COMPRESSED or 0.5 kB without) for old drives with no support for LBA.
  • Fixed a bug from r392 where Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent would return the ID in AL instead of AH (if DANGEROUS_DETECTION had been defined).
  • Fixed a bug from r587 in AdvAtaInit.asm that would prevent detection of QDI Vision controllers.
  • Also changed how the QDI Vision IDs are defined (removed the need for shifting) to avoid confusion. This fixed a potential bug from r587 in AdvAtaInit.asm where some IDs were not being shifted.
  • Fixed a bug in PDC20x30.asm from r587 where GetPdcIDtoAX would not return with the IDE base port in DX so DisablePdcProgrammingMode would fail.
  • Made some changes to ModuleDependency.inc and other files so that MODULE_ADVANCED_ATA now requires USE_386. Consequently it is no longer included in the regular AT-builds, only in the 386_8k-build.
  • Moved the UNROLL_SECTORS_IN_CX_TO_xWORDS macros from IDE_8bit.inc to IdeIO.inc which means it's now possible to build a BIOS without MODULE_8BIT_IDE.
  • XTIDECFG: Added a minimum DOS version check (since it needs DOS version 2+) to allow the program to quit gracefully in the unlikely scenario where someone tries to run it under DOS version 1.
  • Made some changes to Drive.asm to improve drive enumeration. The old method using GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE worked well in Windows XP but not in Windows 98 SE (in Windows or in DOS mode). The two problems were; 1) The function call would access the drives which on single floppy drive systems would cause Windows to swap between A: and B: (throwing a blue screen asking the user to insert a disk etc). 2) Only floppy drives and FAT16 drives would be available in the list of drives, no FAT32/optical/network drives.
  • Improved code in IdeControllerMenu.asm so that the default port addresses for all IDE interfaces are now restored when (re-)selecting the (same) type of IDE device.
  • Also made it impossible to select a device type unless the required module is included in the loaded BIOS.
  • The version check done when loading a BIOS now uses the FLASH_SIGNATURE definition from Version.inc. Any changes affecting RomVars now only requires updating that definition. This means that changes to RomVars must be implemented in both the BIOS and XTIDECFG before being committed to the repository.
  • Added a compatibility fix for 3Com 3C503 cards to the ROM checksumming code in Buffers.asm (Buffers_GenerateChecksum).
  • SerDrive: Made some minor changes to file names and paths to improve compatibility with case sensitive environments.
  • BIOSDRVS: Made a minor size optimization which as a side effect also makes it compatible with all DOS versions including DOS version 1.
  • Library: Renamed the WAIT_RETRACE_IF_NECESSARY_THEN macro to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN and made a tail-call-optimized version of it (JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN).
  • A speed optimization to the eRCL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Other minor optimizations and fixes.
File size: 8.3 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
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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
[580]50%ifdef MODULE_HOTKEYS
51%ifdef MODULE_SERIAL
52    ; This is only needed for hotkey F6 (ComDtct) to work
53    call    ScanHotkeysFromKeyBufferAndStoreToBootvars          ; Done here while CX is still protected
54%endif
55%endif
56
[233]57    pop     cx
58
59    add     bp, BYTE IDEVARS_size           ; Point to next IDEVARS
60
[242]61%ifdef MODULE_SERIAL
[262]62    jcxz    .AddHardDisks                   ; Set to zero on .ideVarsSerialAuto iteration (if any)
[196]63%endif
[3]64    loop    .DriveDetectLoop
[203]65
[242]66%ifdef MODULE_SERIAL
[258]67;----------------------------------------------------------------------
[203]68;
[233]69; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
[203]70;
[567]71    call    FindDPT_ToDSDIforSerialDevice   ; Does not modify AX
[262]72    jnc     .AddHardDisks
[233]73
[242]74    mov     bp, ROMVARS.ideVarsSerialAuto   ; Point to our special IDEVARS structure, just for serial scans
75
[492]76%ifdef MODULE_HOTKEYS
[580]77    cmp     al, COM_DETECT_HOTKEY_SCANCODE  ; Set by last call to ScanHotkeysFromKeyBufferAndStoreToBootvars above
[505]78    je      .DriveDetectLoop
79%endif
[492]80
[568]81    mov     al, [cs:ROMVARS.wFlags]         ; Configurator set to always scan?
82    or      al, [es:BDA.bKBFlgs1]           ; Or, did the user hold down the ALT key?
[589]83    and     al, 8                           ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
[242]84    jnz     .DriveDetectLoop
[580]85%endif ; MODULE_SERIAL
[203]86
[262]87.AddHardDisks:
[258]88;----------------------------------------------------------------------
89;
[262]90; Add in hard disks to BDA, finalize our Count and First variables
[258]91;
[269]92; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
93; This is done because we use the value of .bFirstDrv to know how many drives were in the system
94; at the time of boot, and to return that number on int13h/8h calls.  Because the count is zero,
95; FindDPT_ForDriveNumber will not find any drives that are ours.
96;
[262]97    mov     cx, [RAMVARS.wDrvCntAndFlopCnt]     ; Our count of hard disks
98    mov     al, [es:BDA.bHDCount]
[568]99    add     [es:BDA.bHDCount], cl       ; Add our drives to the system count
[294]100    or      al, 80h                     ; Or in hard disk flag
101    mov     [RAMVARS.bFirstDrv], al     ; Store first drive number
[262]102
[294]103.AddFloppies:
104%ifdef MODULE_SERIAL_FLOPPY
[262]105;----------------------------------------------------------------------
106;
107; Add in any emulated serial floppy drives, finalize our packed Count and First variables
108;
109    dec     ch
110    mov     al, ch
[294]111    js      .NoFloppies                     ; if no drives are present, we store 0ffh
[262]112
[258]113    call    FloppyDrive_GetCountFromBIOS_or_BDA
114
115    push    ax
116
[262]117    add     al, ch                          ; Add our drives to existing drive count
[258]118    cmp     al, 3                           ; For BDA, max out at 4 drives (ours is zero based)
[294]119    jb      .MaxBDAFloppiesExceeded
120    mov     al, 3
[258]121.MaxBDAFloppiesExceeded:
122    eROR_IM al, 2                           ; move to bits 6-7
123    inc     ax                              ; low order bit, indicating floppy drive exists
124
[568]125    mov     ah, 3Eh                         ; AND mask to AH (all bits set except floppy drive count/present)
126    and     ah, [es:BDA.wEquipment]         ; Load Equipment WORD low byte and mask off drive number and drives present bit
[258]127    or      al, ah                          ; Or in new values
128    mov     [es:BDA.wEquipment], al         ; and store
129
[568]130    mov     al, 1Eh                         ; BDA pointer to Floppy DPT
[258]131    mov     si, AH8h_FloppyDPT
132    call    Interrupts_InstallHandlerToVectorInALFromCSSI
133
134    pop     ax
135
[262]136    shr     ch, 1                           ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
[589]137    eRCL_IM al, 1                           ; starting drive number in upper 7 bits, number of drives in low bit
[294]138.NoFloppies:
[258]139    mov     [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
[263]140%endif
[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:
[567]159;       Nothing
[3]160;   Corrupts registers:
[473]161;       AX, BL, CX, DX, SI, DI
[3]162;--------------------------------------------------------------------
[294]163StartDetectionWithDriveSelectByteInBHandStringInCX:
[474]164    call    DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
[558]165
[474]166%ifdef MODULE_HOTKEYS
167    call    HotkeyBar_UpdateDuringDriveDetection
[505]168%endif
[474]169    ; Fall to .ReadAtaInfoFromHardDisk
[473]170
[474]171
[3]172;--------------------------------------------------------------------
[120]173; .ReadAtaInfoFromHardDisk
[3]174;   Parameters:
175;       BH:     Drive Select byte for Drive and Head Register
[473]176;       DX:     Autodetected port (for devices that support autodetection)
[3]177;       CS:BP:  Ptr to IDEVARS for the drive
178;       DS:     RAMVARS segment
179;       ES:     Zero (BDA segment)
180;   Returns:
181;       CF:     Cleared if ATA-information read successfully
182;               Set if any error
183;   Corrupts registers:
[150]184;       AX, BL, CX, DX, SI, DI
[3]185;--------------------------------------------------------------------
[120]186.ReadAtaInfoFromHardDisk:
[150]187    mov     si, BOOTVARS.rgbAtaInfo     ; ES:SI now points to ATA info location
188    push    es
189    push    si
[473]190    push    dx
[150]191    push    bx
192    call    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
193    pop     bx
[473]194    pop     dx
[150]195    pop     si
196    pop     es
[120]197    jnc     SHORT CreateBiosTablesForHardDisk
198    ; Fall to .ReadAtapiInfoFromDrive
[3]199
[120]200.ReadAtapiInfoFromDrive:                ; Not yet implemented
201    ;call   ReadAtapiInfoFromDrive      ; Assume CD-ROM
202    ;jnc    SHORT _CreateBiosTablesForCDROM
[242]203
[203]204    ;jmp    short DetectDrives_DriveNotFound
205;;; fall-through instead of previous jmp instruction
206;--------------------------------------------------------------------
207; DetectDrives_DriveNotFound
208;   Parameters:
209;       Nothing
210;   Returns:
[567]211;       CF:     Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
[203]212;   Corrupts registers:
213;       AX, SI
214;--------------------------------------------------------------------
[242]215DetectDrives_DriveNotFound:
[203]216    mov     si, g_szNotFound
[386]217    jmp     DetectPrint_NullTerminatedStringFromCSSIandSetCF
[3]218
[120]219
[3]220;--------------------------------------------------------------------
[98]221; CreateBiosTablesForHardDisk
[3]222;   Parameters:
223;       BH:     Drive Select byte for Drive and Head Register
[473]224;       DX:     Autodetected port (for devices that support autodetection)
[3]225;       CS:BP:  Ptr to IDEVARS for the drive
[150]226;       ES:SI   Ptr to ATA information for the drive
[3]227;       DS:     RAMVARS segment
[397]228;       ES:     BDA segment
[3]229;   Returns:
[98]230;       Nothing
[3]231;   Corrupts registers:
[98]232;       AX, BX, CX, DX, SI, DI
[3]233;--------------------------------------------------------------------
[98]234CreateBiosTablesForHardDisk:
[580]235%ifndef NO_ATAID_VALIDATION
[441]236    push    bx
237    call    AtaID_VerifyFromESSI
238    pop     bx
[567]239    jnz     SHORT DetectDrives_DriveNotFound
[580]240%endif
[3]241    call    CreateDPT_FromAtaInformation
[196]242    jc      SHORT DetectDrives_DriveNotFound
[397]243    call    DriveDetectInfo_CreateForHardDisk
244    jmp     SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
Note: See TracBrowser for help on using the repository browser.