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

Last change on this file since 534 was 528, checked in by aitotat@…, 11 years ago

Changes to XTIDE Universal BIOS:

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