Ignore:
Timestamp:
Jul 26, 2010, 6:30:33 PM (14 years ago)
Author:
Tomi Tilli
google:author:
aitotat
Message:

Fixed a bug where Disk Parameter Table was accessed with wrong pointer register after writing last block
Cleaned AH=00h, Disk Controller Reset a bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm

    r23 r26  
    22; Project name  :   IDE BIOS
    33; Created date  :   27.9.2007
    4 ; Last update   :   1.7.2010
     4; Last update   :   26.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=0h, Disk Controller Reset.
     
    3737
    3838    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
    39     call    AH0h_ResetFloppyDrivesWithInt40h
    40     test    bl, 80h                     ; Reset hard disks too?
    41     jz      SHORT .Return
    42     call    AH0h_ResetForeignHardDisks
    43     call    AH0h_ResetAllOurControllers
     39    call    ResetFloppyDrivesWithInt40h
     40    test    bl, 80h
     41    jz      SHORT .SkipHardDiskReset
     42    call    ResetForeignHardDisks
     43    call    ResetHardDisksHandledByOurBIOS
    4444ALIGN JUMP_ALIGN
    45 .Return:
     45.SkipHardDiskReset:
    4646    mov     ah, bh                      ; Copy error code to AH
    4747    xor     al, al                      ; Zero AL...
     
    5151
    5252;--------------------------------------------------------------------
    53 ; AH0h_ResetFloppyDrivesWithInt40h
     53; ResetFloppyDrivesWithInt40h
    5454;   Parameters:
    5555;       BL:     Requested drive (DL when entering AH=00h)
     
    6161;--------------------------------------------------------------------   
    6262ALIGN JUMP_ALIGN
    63 AH0h_ResetFloppyDrivesWithInt40h:
    64     xor     ax, ax                      ; Disk Controller Reset
     63ResetFloppyDrivesWithInt40h:
     64    xor     ah, ah                      ; Disk Controller Reset
    6565    and     dl, 7Fh                     ; Clear bit 7
    6666    int     INTV_FLOPPY_FUNC
    67     jmp     SHORT AH0h_BackupErrorCodeFromTheRequestedDriveToBH
     67    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
    6868
    6969
    7070;--------------------------------------------------------------------
    71 ; AH0h_ResetForeignHardDisks
     71; ResetForeignHardDisks
    7272;   Parameters:
    7373;       BL:     Requested drive (DL when entering AH=00h)
     
    7979;--------------------------------------------------------------------   
    8080ALIGN JUMP_ALIGN
    81 AH0h_ResetForeignHardDisks:
    82     mov     cl, [RAMVARS.bFirstDrv]     ; Load number of first our drive
    83     and     cx, BYTE 7Fh                ; CX = number of drives to reset
    84     jz      SHORT .Return
    85     mov     dl, 80h                     ; Start resetting from drive 80h
    86 ALIGN JUMP_ALIGN
    87 .DriveResetLoop:
     81ResetForeignHardDisks:
     82    mov     dl, bl                      ; Drive to reset
    8883    mov     ah, 0Dh                     ; Reset Hard Disk (Alternate reset)
     84
    8985    pushf                               ; Push flags to simulate INT
    9086    cli                                 ; Disable interrupts since INT does that
    9187    call    FAR [RAMVARS.fpOldI13h]
    9288    sti                                 ; Make sure interrupts are enabled again (some BIOSes fails to enable it)
    93     call    AH0h_BackupErrorCodeFromTheRequestedDriveToBH
    94     inc     dx                          ; Next drive to reset
    95     loop    .DriveResetLoop
    96 ALIGN JUMP_ALIGN
    97 .Return:
    98     ret
     89
     90    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
    9991
    10092
    10193;--------------------------------------------------------------------
    102 ; AH0h_ResetAllOurControllers
     94; ResetHardDisksHandledByOurBIOS
    10395;   Parameters:
    10496;       BL:     Requested drive (DL when entering AH=00h)
     
    10799;       BH:     Error code from requested drive (if available)
    108100;   Corrupts registers:
    109 ;       AX, CX, DX, DI
     101;       AX, CX, DX
    110102;--------------------------------------------------------------------
    111103ALIGN JUMP_ALIGN
    112 AH0h_ResetAllOurControllers:
    113     push    si
    114     mov     si, ROMVARS.ideVars0            ; Load offset to first IDEVARS
    115     call    Initialize_GetIdeControllerCountToCX
     104ResetHardDisksHandledByOurBIOS:
     105    mov     dh, [RAMVARS.bDrvCnt]       ; Load drive count to DH
     106    test    dh, dh
     107    jz      SHORT .AllDrivesReset       ; Return if no drives
     108    mov     dl, [RAMVARS.bFirstDrv]     ; Load number of first our drive
     109    add     dh, dl                      ; DH = one past last drive to reset
    116110ALIGN JUMP_ALIGN
    117 .ResetLoop:
    118     call    AH0h_ResetIdevarsControllerMasterAndSlaveDrives
    119     add     si, BYTE IDEVARS_size
    120     loop    .ResetLoop
    121 .Return:
    122     pop     si
     111.DriveResetLoop:
     112    call    AHDh_ResetDrive
     113    call    BackupErrorCodeFromTheRequestedDriveToBH
     114    call    .SkipNextDriveIfItIsSlaveForThisController
     115    inc     dx
     116    cmp     dl, dh                      ; All done?
     117    jb      SHORT .DriveResetLoop       ;  If not, reset next drive
     118.AllDrivesReset:
     119    ret
     120
     121;--------------------------------------------------------------------
     122; .SkipNextDriveIfItIsSlaveForThisController
     123;   Parameters:
     124;       DL:     Drive just resetted
     125;       DS:     RAMVARS segment
     126;   Returns:
     127;       DL:     Incremented if next drive is slave drive
     128;               (=already resetted)
     129;   Corrupts registers:
     130;       AX, CX
     131;--------------------------------------------------------------------
     132ALIGN JUMP_ALIGN
     133.SkipNextDriveIfItIsSlaveForThisController:
     134    push    di
     135
     136    call    .GetBasePortToAXfromDriveInDL
     137    xchg    cx, ax
     138
     139    inc     dx
     140    call    .GetBasePortToAXfromDriveInDL
     141    jnc     SHORT .SkipNextDrive
     142
     143    cmp     ax, cx
     144    je      SHORT .SkipNextDrive        ; Same controller so slave already reset
     145
     146    dec     dx                          ; Restore DX
     147.SkipNextDrive:
     148    pop     di
     149    ret
     150
     151;--------------------------------------------------------------------
     152; .GetBasePortToAXfromDriveInDL
     153;   Parameters:
     154;       DL:     Drive whose base port to find
     155;       DS:     RAMVARS segment
     156;   Returns:
     157;       AX:     Base port (if drive found)
     158;       CF:     Set if drive found
     159;               Cleared if drive not found
     160;   Corrupts registers:
     161;       DI
     162;--------------------------------------------------------------------
     163ALIGN JUMP_ALIGN
     164.GetBasePortToAXfromDriveInDL:
     165    call    FindDPT_ForDriveNumber      ; Get DPT to DS:DI
     166    jnc     SHORT .DriveNotFound
     167    eMOVZX  di, BYTE [di+DPT.bIdeOff]   ; CS:DI now points to IDEVARS
     168    mov     ax, [cs:di+IDEVARS.wPort]
     169.DriveNotFound:
    123170    ret
    124171
    125172
    126173;--------------------------------------------------------------------
    127 ; AH0h_ResetIdevarsControllerMasterAndSlaveDrives
    128 ;   Parameters:
    129 ;       BL:     Requested drive (DL when entering AH=00h)
    130 ;       CS:SI:  Ptr to IDEVARS
    131 ;       DS:     RAMVARS segment
    132 ;   Returns:
    133 ;       BH:     Error code from requested drive (if available)
    134 ;   Corrupts registers:
    135 ;       AX, DX, DI
    136 ;--------------------------------------------------------------------
    137 ALIGN JUMP_ALIGN
    138 AH0h_ResetIdevarsControllerMasterAndSlaveDrives:
    139     mov     dx, [cs:si+IDEVARS.wPort]
    140     call    FindDPT_ForIdeMasterAtPort      ; Find master drive to DL
    141     jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
    142     call    FindDPT_ForIdeSlaveAtPort       ; Find slave if master not present
    143     jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
    144     ret
    145 
    146 ;--------------------------------------------------------------------
    147 ; AH0h_ResetMasterAndSlaveDriveWithRetries
    148 ;   Parameters:
    149 ;       BL:     Requested drive (DL when entering AH=00h)
    150 ;       DL:     Drive number for master or slave drive
    151 ;       DS:     RAMVARS segment
    152 ;   Returns:
    153 ;       BH:     Error code from requested drive (if available)
    154 ;   Corrupts registers:
    155 ;       AX, DI
    156 ;--------------------------------------------------------------------
    157 ALIGN JUMP_ALIGN
    158 AH0h_ResetMasterAndSlaveDriveWithRetries:
    159     push    dx
    160     push    cx
    161     push    bx
    162     mov     di, RETRIES_IF_RESET_FAILS
    163 ALIGN JUMP_ALIGN
    164 .RetryLoop:
    165     call    AHDh_ResetDrive
    166     jnc     SHORT .Return               ; Jump if successful
    167     mov     cx, TIMEOUT_BEFORE_RESET_RETRY
    168     call    SoftDelay_TimerTicks
    169     dec     di
    170     jnz     SHORT .RetryLoop
    171 ALIGN JUMP_ALIGN
    172 .Return:
    173     pop     bx
    174     pop     cx
    175     pop     dx
    176     ; Fall to AH0h_BackupErrorCodeFromTheRequestedDriveToBH
    177 
    178 ;--------------------------------------------------------------------
    179 ; AH0h_BackupErrorCodeFromTheRequestedDriveToBH
     174; BackupErrorCodeFromTheRequestedDriveToBH
    180175;   Parameters:
    181176;       AH:     Error code from the last resetted drive
     
    188183;--------------------------------------------------------------------
    189184ALIGN JUMP_ALIGN
    190 AH0h_BackupErrorCodeFromTheRequestedDriveToBH:
    191     cmp     dl, bl                      ; Requested drive?
     185BackupErrorCodeFromTheRequestedDriveToBH:
     186    cmp     dl, bl              ; Requested drive?
    192187    jne     SHORT .Return
    193188    mov     bh, ah
Note: See TracChangeset for help on using the changeset viewer.