Changeset 504 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS_Configurator_v2


Ignore:
Timestamp:
Feb 13, 2013, 6:12:52 PM (12 years ago)
Author:
aitotat@…
google:author:
aitotat@gmail.com
Message:

Changes to Configurator v2:

  • Cleaned IDE autodetect code.
Location:
trunk/XTIDE_Universal_BIOS_Configurator_v2/Src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/AutoConfigure.asm

    r502 r504  
    101101    call    IdeAutodetect_IncrementDXtoNextIdeBasePort
    102102    jz      SHORT .AllPortsAlreadyDetected
    103     push    cx
    104     call    IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInCX
    105     mov     bx, cx
    106     pop     cx
     103    push    si
     104    call    IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInSI
     105    mov     bx, si
     106    pop     si
    107107    jc      SHORT .DetectFromNextPort
    108108
  • trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm

    r502 r504  
    2424; IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInCX
    2525;   Parameters:
    26 ;       DX:     IDE Base Port
     26;       DX:     IDE Base Port or segment address (Command Block)
    2727;       DS:DI:  Ptr to ROMVARS
    2828;   Returns:
    2929;       AL:     Device Type
    30 ;       CX:     Control Block Base port (detected since there is no
    31 ;               standard address for Tetriary and Quaternary IDE controllers)
     30;       SI:     IDE Control Block Base port (port mapped devices only)
    3231;       CF:     Clear if IDE Device found
    3332;               Set if IDE Device not found
     
    3534;       AH, BX
    3635;--------------------------------------------------------------------
    37 IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInCX:
     36IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInSI:
    3837    cmp     dx, FIRST_MEMORY_SEGMENT_ADDRESS
    39     jb      SHORT .DetectPortMappedDevices
    40 
     38    jb      SHORT DetectPortMappedDeviceFromPortDX
     39    ; Fall to DetectMemoryMappedDeviceFromSegmentDX
     40
     41;--------------------------------------------------------------------
     42; DetectMemoryMappedDeviceFromSegmentDX
     43;   Parameters:
     44;       DX:     Segment address for Memory Mapped Device
     45;       DS:DI:  Ptr to ROMVARS
     46;   Returns:
     47;       AL:     Device Type
     48;       CF:     Clear if IDE Device found
     49;               Set if IDE Device not found
     50;   Corrupts registers:
     51;       AH, BX
     52;--------------------------------------------------------------------
     53DetectMemoryMappedDeviceFromSegmentDX:
    4154    ; *** Try to detect JR-IDE/ISA (only if MODULE_8BIT_IDE_ADVANCED is present) ***
    4255    test    WORD [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
    43     jz      SHORT .SkipRestOfDetection
     56    jz      SHORT NoIdeDeviceFound
    4457
    4558    push    ds
     
    5366    mov     al, DEVICE_8BIT_JRIDE_ISA   ; Assume CF was cleared
    5467    ret                                 ; No need to return Control Block Port
    55 .DetectPortMappedDevices:
    56 
    57 
     68
     69
     70;--------------------------------------------------------------------
     71; DetectPortMappedDeviceFromPortDX
     72;   Parameters:
     73;       DX:     IDE Base Port (Command Block)
     74;       DS:DI:  Ptr to ROMVARS
     75;   Returns:
     76;       AL:     Device Type
     77;       SI:     IDE Control Block Base port
     78;       CF:     Clear if IDE Device found
     79;               Set if IDE Device not found
     80;   Corrupts registers:
     81;       AH, BX
     82;--------------------------------------------------------------------
     83DetectPortMappedDeviceFromPortDX:
    5884    ; *** Try to detect Standard 16- and 32-bit IDE Devices ***
    59     mov     bh, DEVICE_16BIT_ATA        ; Assume 16-bit ISA slot for AT builds
     85    mov     al, DEVICE_16BIT_ATA        ; Assume 16-bit ISA slot for AT builds
    6086    call    Buffers_IsXTbuildLoaded
    61     eCMOVE  bh, DEVICE_8BIT_ATA         ; Assume 8-bit ISA slot for XT builds
    62 
    63     mov     bl, STATUS_REGISTER_in
    64     mov     cx, STANDARD_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in
    65 .RedetectTertiaryOrQuaternaryWithDifferentAlternativeStatusRegisterPort:
    66     call    DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
    67     mov     al, bh
     87    eCMOVE  al, DEVICE_8BIT_ATA         ; Assume 8-bit ISA slot for XT builds
     88
     89    ; Start with standard Control Block base port used by Primary and Secondary IDE
     90    mov     si, dx
     91    add     si, STANDARD_CONTROL_BLOCK_OFFSET
     92    mov     bx, STATUS_REGISTER_in | (ALTERNATE_STATUS_REGISTER_in << 8)
     93.RedetectTertiaryOrQuaternaryWithDifferentControlBlockAddress:
     94    push    ax                          ; Store device type
     95    call    DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH
     96    pop     ax                          ; Restore device type
    6897    jnc     SHORT .IdeDeviceFound
    6998
     
    72101    ; example Promise FloppyMAX has Control Block at STANDARD_CONTROL_BLOCK_OFFSET but Sound Blaster 16 (CT2290)
    73102    ; use DEVICE_ATA_SECONDARY_PORTCTRL for Tertiary and Quaternary even though only Secondary should use that.
    74     cmp     cx, STANDARD_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in
    75     jne     SHORT .AlreadyTriedAlternativeControlBlock
    76     mov     cx, DEVICE_ATA_SECONDARY_PORTCTRL + ALTERNATE_STATUS_REGISTER_in
    77     sub     cx, dx                      ; Offset to add to DX
    78     cmp     dx, DEVICE_ATA_TERTIARY_PORT
    79     je      SHORT .RedetectTertiaryOrQuaternaryWithDifferentAlternativeStatusRegisterPort
    80     cmp     dx, DEVICE_ATA_QUATERNARY_PORT
    81     je      SHORT .RedetectTertiaryOrQuaternaryWithDifferentAlternativeStatusRegisterPort
    82 .AlreadyTriedAlternativeControlBlock:
     103    call    ChangeDifferentControlBlockAddressToSI
     104    je      SHORT .RedetectTertiaryOrQuaternaryWithDifferentControlBlockAddress
    83105
    84106
    85107    ; Detect 8-bit devices only if MODULE_8BIT_IDE is available
    86108    test    BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE
    87     jz      SHORT .SkipRestOfDetection
     109    jz      SHORT NoIdeDeviceFound
    88110
    89111    ; *** Try to detect XT-CF ***
    90     mov     bl, STATUS_REGISTER_in << 1
    91     mov     cx, (XTIDE_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in) << 1
    92     call    DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
    93     rcl     ax, 1                       ; Store CF
    94     shr     cx, 1                       ; XTIDE_CONTROL_BLOCK_OFFSET + ALTERNATE_STATUS_REGISTER_in
    95     rcr     ax, 1                       ; Restore CF
     112    mov     si, dx
     113    add     si, BYTE XTCF_CONTROL_BLOCK_OFFSET
     114    shl     bx, 1                       ; SHL 1 register offsets for XT-CF
     115    call    DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH
    96116    mov     al, DEVICE_8BIT_XTCF_PIO8
    97117    jnc     SHORT .IdeDeviceFound
     
    102122    ; Status Register addresses. That is why we need another step
    103123    ; to check is this XT-IDE rev 1 or rev 2.
    104     call    DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
    105     jc      SHORT .SkipRestOfDetection  ; No XT-IDE rev 1 or rev 2 found
     124    sub     si, BYTE XTCF_CONTROL_BLOCK_OFFSET >> 1
     125    shr     bx, 1
     126    call    DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH
     127    jc      SHORT NoIdeDeviceFound      ; No XT-IDE rev 1 or rev 2 found
    106128
    107129    ; Now we can be sure that we have XT-IDE rev 1 or rev 2.
     
    121143    mov     al, DEVICE_8BIT_XTIDE_REV1  ; We must have rev 1
    122144.IdeDeviceFound:
    123     sub     cl, ALTERNATE_STATUS_REGISTER_in    ; Clear CF
    124     add     cx, dx                              ; CX = Control Block address
    125145    ret
    126 .SkipRestOfDetection:
    127     stc
    128     ret
    129 
    130 
    131 ;--------------------------------------------------------------------
    132 ; DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX
     146
     147
     148;--------------------------------------------------------------------
     149; DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH
    133150;   Parameters:
    134151;       BL:     Offset to IDE Status Register
    135 ;       CX:     Offset to Alternative Status Register
    136 ;       DX:     IDE Base Port
     152;       BH:     Offset to Alternative Status Register
     153;       DX:     IDE Base Port address
     154;       SI:     IDE Control Block address
    137155;   Returns:
    138156;       CF:     Clear if IDE Device found
     
    141159;       AX
    142160;--------------------------------------------------------------------
    143 DetectIdeDeviceFromPortDXwithStatusRegOffsetsInBLandCX:
     161DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH:
    144162    ; Read Status and Alternative Status Registers
    145     push    cx
    146163    push    dx
    147164
    148     add     cx, dx              ; CX = Address to Alternative Status Register
    149     add     dl, bl              ; DX = Address to Status Register
     165    add     dl, bl
    150166    cli                         ; Disable Interrupts
    151     in      al, dx              ; Read Status Register
    152     mov     ah, al
    153     mov     dx, cx
    154     in      al, dx              ; Read Alternative Status Register
     167    in      al, dx              ; Read Status Register...
     168    mov     ah, al              ; ...to AH
     169    mov     dx, si
     170    add     dl, bh
     171    in      al, dx              ; Read Alternative Status Register to AL
    155172    sti                         ; Enable Interrupts
    156173
    157174    pop     dx
    158     pop     cx
    159175    ; Fall to CompareIdeStatusRegistersFromALandAH
    160176
     
    163179; CompareIdeStatusRegistersFromALandAH
    164180;   Parameters:
    165 ;       AL:     Possible IDE Status Register contents
    166 ;       AH:     Possible IDE Alternative Status Register contents
     181;       AH:     Possible IDE Status Register contents
     182;       AL:     Possible IDE Alternative Status Register contents
    167183;   Returns:
    168184;       CF:     Clear if valid Status Register Contents
     
    180196    ; example. We must make sure bits are what is expected from valid
    181197    ; IDE Status Register. So far all drives I've tested return 50h
    182     ; (FLG_STATUS_DRDY and FLG_STATUS_DSC set) but I don't want to assume
    183     ; just yet that all drives report 50h.
     198    ; (FLG_STATUS_DRDY and FLG_STATUS_DSC set) unless there is only
     199    ; one drive present but wrong drive is selected. For example if Master
     200    ; drive is present but Slave is selected from IDE Drive and Head Select Register,
     201    ; then the Status Register can be 00h.
    184202    test    al, FLG_STATUS_BSY | FLG_STATUS_DF | FLG_STATUS_DRQ | FLG_STATUS_ERR
    185203    jnz     SHORT .InvalidStatusRegister    ; Busy or Errors cannot be set
     
    189207
    190208.InvalidStatusRegister:
    191 AllPortsAlreadyDetected:
     209NoIdeDeviceFound:
    192210    stc
     211    ret
     212
     213
     214;--------------------------------------------------------------------
     215; ChangeDifferentControlBlockAddressToSI
     216;   Parameters:
     217;       DX:     IDE Base Port address
     218;       SI:     IDE Control Block address
     219;   Returns:
     220;       ZF:     Set if SI changed
     221;               Cleared if different control block address is not possible
     222;   Corrupts registers:
     223;       AH
     224;--------------------------------------------------------------------
     225ChangeDifferentControlBlockAddressToSI:
     226    cmp     si, 368h
     227    je      SHORT .TrySecondAlternative
     228    cmp     si, 3E8h
     229    je      SHORT .TrySecondAlternative
     230
     231    cmp     si, 360h
     232    je      SHORT .TryLastAlternative
     233    cmp     si, 3E0h
     234    je      SHORT .TryLastAlternative
     235    ret     ; Return with ZF cleared
     236
     237.TryLastAlternative:
     238    mov     si, DEVICE_ATA_SECONDARY_PORTCTRL + 8   ; Changes to 370h used by Sound Blaster 16 (CT2290)
     239    ; Fall to .TrySecondAlternative
     240.TrySecondAlternative:
     241    sub     si, BYTE 8h     ; 368h to 360h, 3E8h to 3E0h
     242    xor     ah, ah          ; Set ZF
    193243    ret
    194244
Note: See TracChangeset for help on using the changeset viewer.