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

Last change on this file was 614, checked in by krille_n_, 3 years ago

Changes:

  • BIOSDRVS should now build again (broke in r613).
  • Removed the NO_ATAID_CORRECTION define from the Tiny build.
  • Added a new configuration option to skip detection of slave drives.
  • Made FLASH_SIGNATURE 2 bytes shorter to free up ROM space.
  • "Auto Configure" in XTIDECFG should now detect if running on an Olivetti M24, AT&T PC6300, Xerox 6060 or Logabax Persona 1600 and automatically select the fastest compatible transfer mode/device type for any IDE controllers found in the system.
  • Cleaned out some duplicate/unused definitions.
File size: 11.7 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
[614]46    test    BYTE [cs:bp+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags], FLG_DRVPARAMS_DO_NOT_DETECT
47    jnz     SHORT .SkipSlaveDetection
[233]48    mov     cx, g_szDetectSlave
[242]49    mov     bh, MASK_DRVNHEAD_SET | FLG_DRVNHEAD_DRV
[294]50    call    StartDetectionWithDriveSelectByteInBHandStringInCX
[614]51.SkipSlaveDetection:
[242]52
[580]53%ifdef MODULE_HOTKEYS
54%ifdef MODULE_SERIAL
55    ; This is only needed for hotkey F6 (ComDtct) to work
56    call    ScanHotkeysFromKeyBufferAndStoreToBootvars          ; Done here while CX is still protected
57%endif
58%endif
59
[233]60    pop     cx
61
62    add     bp, BYTE IDEVARS_size           ; Point to next IDEVARS
63
[242]64%ifdef MODULE_SERIAL
[262]65    jcxz    .AddHardDisks                   ; Set to zero on .ideVarsSerialAuto iteration (if any)
[196]66%endif
[3]67    loop    .DriveDetectLoop
[203]68
[242]69%ifdef MODULE_SERIAL
[258]70;----------------------------------------------------------------------
[203]71;
[233]72; if serial drive detected, do not scan (avoids duplicate drives and isn't needed - we already have a connection)
[203]73;
[567]74    call    FindDPT_ToDSDIforSerialDevice   ; Does not modify AX
[605]75    jnc     SHORT .AddHardDisks
[233]76
[242]77    mov     bp, ROMVARS.ideVarsSerialAuto   ; Point to our special IDEVARS structure, just for serial scans
78
[492]79%ifdef MODULE_HOTKEYS
[580]80    cmp     al, COM_DETECT_HOTKEY_SCANCODE  ; Set by last call to ScanHotkeysFromKeyBufferAndStoreToBootvars above
[605]81    je      SHORT .DriveDetectLoop
[505]82%endif
[492]83
[568]84    mov     al, [cs:ROMVARS.wFlags]         ; Configurator set to always scan?
85    or      al, [es:BDA.bKBFlgs1]           ; Or, did the user hold down the ALT key?
[589]86    and     al, 8                           ; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
[605]87    jnz     SHORT .DriveDetectLoop
[580]88%endif ; MODULE_SERIAL
[203]89
[262]90.AddHardDisks:
[258]91;----------------------------------------------------------------------
92;
[262]93; Add in hard disks to BDA, finalize our Count and First variables
[258]94;
[269]95; Note that we perform the add to bHDCount and store bFirstDrv even if the count is zero.
96; This is done because we use the value of .bFirstDrv to know how many drives were in the system
97; at the time of boot, and to return that number on int13h/8h calls.  Because the count is zero,
98; FindDPT_ForDriveNumber will not find any drives that are ours.
99;
[593]100
[605]101; This is a hack to get Windows 9x to load its built-in protected mode IDE driver.
[596]102;
[593]103; The Windows hack has two parts. First part is to try to alter CMOS address 12h as that
[605]104; is what Windows 9x driver reads to detect IDE drives. Altering is not possible on all
[596]105; systems since CMOS has a checksum but its location is not standardized. We will first
[593]106; try to detect valid checksum. If it succeeds, then it is safe to assume this system
107; has compatible CMOS and we can alter it.
[605]108; If verify fails, we do the more dirty hack to zero BDA drive count. Then Windows 9x works
[593]109; as long as user has configured at least one drive in the BIOS setup.
[605]110%ifdef MODULE_WIN9X_CMOS_HACK
[601]111    mov     dl, HARD_DISK_TYPES
112    call    CMOS_ReadFromIndexInDLtoAL
113    test    al, 0F0h
[605]114    jnz     SHORT .ClearBdaDriveCount       ; CMOS byte 12h is ready for Windows 9x
[601]115    call    CMOS_Verify10hTo2Dh             ; Can we modify CMOS?
116    jnz     SHORT .ClearBdaDriveCount       ; Unsupported BIOS, use plan B
[593]117
[601]118    ; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
[605]119    ; (but accept changes to drive type 1). Windows 9x requires that the drive 0 type is
[601]120    ; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
[605]121    ; won't give problems but Windows 9x stays in MS-DOS compatibility mode.
[601]122    ;
123    ; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
[605]124    ; So essentially we could automatically do what user needs to do manually to get Windows 9x
[601]125    ; working on Award BIOSes. However, I think that should be left to do manually since
[605]126    ; there may be SCSI drives on the system or FLG_ROMVARS_CLEAR_BDA_HD_COUNT could
[601]127    ; be intentionally cleared and forcing the dummy drive might cause only trouble.
[596]128
[601]129    ; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
130    ; there will be no need to scan E000h segment)
131    mov     cx, 65536 - 4
132    mov     eax, 'Awar'                     ; Four characters should be enough
133    mov     di, 0F000h                      ; Scan 64k starting from segment F000h
134    mov     fs, di                          ; No need to preserve FS since we set it to zero soon when we boot
135    xor     di, di
136.ScanNextCharacters:
137    cmp     [fs:di], eax
138    je      SHORT .ClearBdaDriveCount       ; Award detected, cannot modify CMOS
139    inc     di                              ; Increment offset by one character (not four)
140    loop    .ScanNextCharacters
[598]141
[601]142    ; Now it should be safe to write
143    mov     dl, HARD_DISK_TYPES
144    mov     al, 0F0h                        ; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
145    call    CMOS_WriteALtoIndexInDL
146    call    CMOS_StoreNewChecksumFor10hto2Dh
[594]147.ClearBdaDriveCount:
[605]148%endif ; MODULE_WIN9X_CMOS_HACK
[593]149
[605]150    mov     cx, [RAMVARS.wDrvCntAndFlopCnt] ; Our count of hard disks
151    mov     al, [es:BDA.bHDCount]
152%ifndef MODULE_MFM_COMPATIBILITY
153    ; This is excluded when MODULE_MFM_COMPATIBILITY is included because it doesn't make sense to use both at the same time anyway.
154    ; Note that the option to "Remove other hard drives" is still visible in XTIDECFG.COM for builds including MODULE_MFM_COMPATIBILITY.
155    ; Changing that option just won't do anything. We might want to remove the option for builds that contain MODULE_MFM_COMPATIBILITY
156    ; but that would require a ROMVARS flag that is probably better spent on other things.
157    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_CLEAR_BDA_HD_COUNT    ; Clears CF
[593]158    jz      SHORT .ContinueInitialization
[605]159%ifdef USE_UNDOC_INTEL
160    salc
161%else
162    xor     al, al
163%endif
[593]164.ContinueInitialization:
[605]165%endif ; MODULE_MFM_COMPATIBILITY
166    add     cl, al
167    mov     [es:BDA.bHDCount], cl           ; Update the system count
[601]168    or      al, 80h                         ; Or in hard disk flag
169    mov     [RAMVARS.bFirstDrv], al         ; Store first drive number
[262]170
[294]171.AddFloppies:
172%ifdef MODULE_SERIAL_FLOPPY
[262]173;----------------------------------------------------------------------
174;
175; Add in any emulated serial floppy drives, finalize our packed Count and First variables
176;
177    dec     ch
178    mov     al, ch
[601]179    js      SHORT .NoFloppies               ; If no drives are present, we store 0FFh
[262]180
[258]181    call    FloppyDrive_GetCountFromBIOS_or_BDA
182
183    push    ax
184
[262]185    add     al, ch                          ; Add our drives to existing drive count
[258]186    cmp     al, 3                           ; For BDA, max out at 4 drives (ours is zero based)
[605]187    jb      SHORT .MaxBDAFloppiesExceeded
[294]188    mov     al, 3
[258]189.MaxBDAFloppiesExceeded:
190    eROR_IM al, 2                           ; move to bits 6-7
191    inc     ax                              ; low order bit, indicating floppy drive exists
192
[568]193    mov     ah, 3Eh                         ; AND mask to AH (all bits set except floppy drive count/present)
194    and     ah, [es:BDA.wEquipment]         ; Load Equipment WORD low byte and mask off drive number and drives present bit
[258]195    or      al, ah                          ; Or in new values
196    mov     [es:BDA.wEquipment], al         ; and store
197
[568]198    mov     al, 1Eh                         ; BDA pointer to Floppy DPT
[258]199    mov     si, AH8h_FloppyDPT
200    call    Interrupts_InstallHandlerToVectorInALFromCSSI
201
202    pop     ax
203
[262]204    shr     ch, 1                           ; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
[589]205    eRCL_IM al, 1                           ; starting drive number in upper 7 bits, number of drives in low bit
[294]206.NoFloppies:
[258]207    mov     [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
[263]208%endif
[3]209    ret
210
[294]211%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[261]212    %if FLG_ROMVARS_SERIAL_SCANDETECT != 8
213        %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."
214    %endif
[199]215%endif
216
[242]217
[3]218;--------------------------------------------------------------------
[294]219; StartDetectionWithDriveSelectByteInBHandStringInCX
[3]220;   Parameters:
221;       BH:     Drive Select byte for Drive and Head Register
[233]222;       CX:     Offset to "Master" or "Slave" string
[3]223;       CS:BP:  Ptr to IDEVARS for the drive
224;       DS:     RAMVARS segment
225;       ES:     Zero (BDA segment)
226;   Returns:
[567]227;       Nothing
[3]228;   Corrupts registers:
[473]229;       AX, BL, CX, DX, SI, DI
[3]230;--------------------------------------------------------------------
[294]231StartDetectionWithDriveSelectByteInBHandStringInCX:
[474]232    call    DetectPrint_StartDetectWithMasterOrSlaveStringInCXandIdeVarsInCSBP
233    ; Fall to .ReadAtaInfoFromHardDisk
[473]234
[474]235
[3]236;--------------------------------------------------------------------
[120]237; .ReadAtaInfoFromHardDisk
[3]238;   Parameters:
239;       BH:     Drive Select byte for Drive and Head Register
[473]240;       DX:     Autodetected port (for devices that support autodetection)
[3]241;       CS:BP:  Ptr to IDEVARS for the drive
242;       DS:     RAMVARS segment
243;       ES:     Zero (BDA segment)
244;   Returns:
245;       CF:     Cleared if ATA-information read successfully
246;               Set if any error
247;   Corrupts registers:
[150]248;       AX, BL, CX, DX, SI, DI
[3]249;--------------------------------------------------------------------
[120]250.ReadAtaInfoFromHardDisk:
[601]251    mov     si, BOOTVARS.rgbAtaInfo         ; ES:SI now points to ATA info location
[150]252    push    es
253    push    si
[473]254    push    dx
[150]255    push    bx
256    call    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
257    pop     bx
[473]258    pop     dx
[150]259    pop     si
260    pop     es
[120]261    jnc     SHORT CreateBiosTablesForHardDisk
262    ; Fall to .ReadAtapiInfoFromDrive
[3]263
[601]264.ReadAtapiInfoFromDrive:                    ; Not yet implemented
265    ;call   ReadAtapiInfoFromDrive          ; Assume CD-ROM
[120]266    ;jnc    SHORT _CreateBiosTablesForCDROM
[242]267
[203]268    ;jmp    short DetectDrives_DriveNotFound
269;;; fall-through instead of previous jmp instruction
270;--------------------------------------------------------------------
271; DetectDrives_DriveNotFound
272;   Parameters:
273;       Nothing
274;   Returns:
[567]275;       CF:     Set (from DetectPrint_NullTerminatedStringFromCSSIandSetCF)
[203]276;   Corrupts registers:
277;       AX, SI
278;--------------------------------------------------------------------
[242]279DetectDrives_DriveNotFound:
[203]280    mov     si, g_szNotFound
[386]281    jmp     DetectPrint_NullTerminatedStringFromCSSIandSetCF
[3]282
[120]283
[3]284;--------------------------------------------------------------------
[98]285; CreateBiosTablesForHardDisk
[3]286;   Parameters:
287;       BH:     Drive Select byte for Drive and Head Register
[473]288;       DX:     Autodetected port (for devices that support autodetection)
[3]289;       CS:BP:  Ptr to IDEVARS for the drive
[150]290;       ES:SI   Ptr to ATA information for the drive
[3]291;       DS:     RAMVARS segment
[397]292;       ES:     BDA segment
[3]293;   Returns:
[98]294;       Nothing
[3]295;   Corrupts registers:
[98]296;       AX, BX, CX, DX, SI, DI
[3]297;--------------------------------------------------------------------
[98]298CreateBiosTablesForHardDisk:
[580]299%ifndef NO_ATAID_VALIDATION
[441]300    push    bx
301    call    AtaID_VerifyFromESSI
302    pop     bx
[567]303    jnz     SHORT DetectDrives_DriveNotFound
[580]304%endif
[3]305    call    CreateDPT_FromAtaInformation
[196]306    jc      SHORT DetectDrives_DriveNotFound
[397]307    call    DriveDetectInfo_CreateForHardDisk
308    jmp     SHORT DetectPrint_DriveNameFromDrvDetectInfoInESBX
Note: See TracBrowser for help on using the repository browser.