Ignore:
File:
1 edited

Legend:

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

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   27.9.2007
    4 ; Last update   :   2.5.2010
     4; Last update   :   29.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=0h, Disk Controller Reset.
     
    2323;       DS:     RAMVARS segment
    2424;   Returns:
    25 ;       AH:     Int 13h return status
     25;       AH:     Int 13h return status (from drive requested in DL)
    2626;       CF:     0 if succesfull, 1 if error
    2727;       IF:     1
     
    3636    push    ax
    3737
    38     test    dl, 80h                     ; Reset floppy drives only?
    39     jz      SHORT .ResetForeignControllers
    40     call    AH0h_ResetOurControllers
    41 .ResetForeignControllers:
    42     call    AH0h_ResetFloppyAndForeignHardDiskControllers
    43     jmp     Int13h_PopXRegsAndReturn    ; Return since error
     38    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
     39    call    ResetFloppyDrivesWithInt40h
     40    test    bl, 80h
     41    jz      SHORT .SkipHardDiskReset
     42    call    ResetForeignHardDisks
     43    call    AH0h_ResetHardDisksHandledByOurBIOS
     44ALIGN JUMP_ALIGN
     45.SkipHardDiskReset:
     46    mov     ah, bh                      ; Copy error code to AH
     47    xor     al, al                      ; Zero AL...
     48    cmp     al, bh                      ; ...and set CF if error
     49    jmp     Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn
    4450
    4551
    4652;--------------------------------------------------------------------
    47 ; Resets all IDE controllers handled by this BIOS.
    48 ;
    49 ; AH0h_ResetOurControllers
     53; ResetFloppyDrivesWithInt40h
    5054;   Parameters:
     55;       BL:     Requested drive (DL when entering AH=00h)
     56;   Returns:
     57;       BH:     Error code from requested drive (if available)
     58;   Corrupts registers:
     59;       AX, DL, DI
     60;--------------------------------------------------------------------   
     61ALIGN JUMP_ALIGN
     62ResetFloppyDrivesWithInt40h:
     63    call    GetDriveNumberForForeignBiosesToDL
     64    and     dl, 7Fh                     ; Clear hard disk bit
     65    xor     ah, ah                      ; Disk Controller Reset
     66    int     INTV_FLOPPY_FUNC
     67    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
     68
     69
     70;--------------------------------------------------------------------
     71; ResetForeignHardDisks
     72;   Parameters:
     73;       BL:     Requested drive (DL when entering AH=00h)
    5174;       DS:     RAMVARS segment
    5275;   Returns:
    53 ;       AH:     Int 13h return status
    54 ;       CF:     0 if succesfull, 1 if error
     76;       BH:     Error code from requested drive (if available)
    5577;   Corrupts registers:
    56 ;       AL, BX, CX, DI
     78;       AX, DL, DI
     79;--------------------------------------------------------------------   
     80ALIGN JUMP_ALIGN
     81ResetForeignHardDisks:
     82    call    GetDriveNumberForForeignBiosesToDL
     83    xor     ah, ah                      ; Disk Controller Reset
     84    pushf                               ; Push flags to simulate INT
     85    cli                                 ; Disable interrupts since INT does that
     86    call    FAR [RAMVARS.fpOldI13h]
     87    sti                                 ; Make sure interrupts are enabled again (some BIOSes fails to enable it)
     88    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
     89
     90
    5791;--------------------------------------------------------------------
     92; GetDriveNumberForForeignBiosesToDL
     93;   Parameters:
     94;       BL:     Requested drive (DL when entering AH=00h)
     95;       DS:     RAMVARS segment
     96;   Returns:
     97;       DL:     BL if foreign drive
     98;               80h if our drive
     99;   Corrupts registers:
     100;       DI
     101;--------------------------------------------------------------------   
    58102ALIGN JUMP_ALIGN
    59 AH0h_ResetOurControllers:
    60     push    dx
    61     mov     bx, ROMVARS.ideVars0            ; Load offset to first IDEVARS
    62     call    Initialize_GetIdeControllerCountToCX
     103GetDriveNumberForForeignBiosesToDL:
     104    mov     dl, bl
     105    call    RamVars_IsDriveHandledByThisBIOS
     106    jc      SHORT .GetFirstDriveForForeignBios
     107    ret     ; Return what was in BL unmodified
    63108ALIGN JUMP_ALIGN
    64 .ResetLoop:
    65     call    AH0h_ResetIdevarsController
    66     jc      SHORT .Return
    67     add     bx, BYTE IDEVARS_size
    68     loop    .ResetLoop
    69     xor     ax, ax                          ; Clear AH and CF since no errors
    70 .Return:
    71     pop     dx
     109.GetFirstDriveForForeignBios:
     110    mov     dl, 80h
    72111    ret
    73112
    74113
    75114;--------------------------------------------------------------------
    76 ; Resets master and slave drive based on either drive number.
    77 ;
    78 ; AH0h_ResetIdevarsController
     115; ResetHardDisksHandledByOurBIOS
    79116;   Parameters:
    80 ;       CS:BX:  Ptr to IDEVARS
     117;       BL:     Requested drive (DL when entering AH=00h)
    81118;       DS:     RAMVARS segment
    82119;   Returns:
    83 ;       AH:     Int 13h return status
    84 ;       CF:     0 if succesfull, 1 if error
     120;       BH:     Error code from requested drive (if available)
    85121;   Corrupts registers:
    86 ;       AL, DX, DI
     122;       AX, CX, DX, DI
    87123;--------------------------------------------------------------------
    88124ALIGN JUMP_ALIGN
    89 AH0h_ResetIdevarsController:
    90     mov     dx, [cs:bx+IDEVARS.wPort]
    91     call    FindDPT_ForIdeMasterAtPort      ; Find master drive to DL
    92     jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
    93     call    FindDPT_ForIdeSlaveAtPort       ; Find slave if master not present
    94     jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
    95     clc
     125AH0h_ResetHardDisksHandledByOurBIOS:
     126    mov     dh, [RAMVARS.bDrvCnt]       ; Load drive count to DH
     127    test    dh, dh
     128    jz      SHORT .AllDrivesReset       ; Return if no drives
     129    mov     dl, [RAMVARS.bFirstDrv]     ; Load number of first our drive
     130    add     dh, dl                      ; DH = one past last drive to reset
     131ALIGN JUMP_ALIGN
     132.DriveResetLoop:
     133    call    AHDh_ResetDrive
     134    call    .BackupErrorCodeFromMasterOrSlaveToBH
     135    inc     dx
     136    cmp     dl, dh                      ; All done?
     137    jb      SHORT .DriveResetLoop       ;  If not, reset next drive
     138.AllDrivesReset:
     139    ret
     140
     141;--------------------------------------------------------------------
     142; .BackupErrorCodeFromMasterOrSlaveToBH
     143;   Parameters:
     144;       AH:     Error code for drive DL reset
     145;       BL:     Requested drive (DL when entering AH=00h)
     146;       DL:     Drive just resetted
     147;       DS:     RAMVARS segment
     148;   Returns:
     149;       BH:     Backuped error code
     150;       DL:     Incremented if next drive is slave drive
     151;               (=already resetted)
     152;   Corrupts registers:
     153;       CX, DI
     154;--------------------------------------------------------------------
     155ALIGN JUMP_ALIGN
     156.BackupErrorCodeFromMasterOrSlaveToBH:
     157    call    BackupErrorCodeFromTheRequestedDriveToBH
     158    mov     cx, [RAMVARS.wIdeBase]      ; Load base port for resetted drive
     159
     160    inc     dx                          ; DL to next drive
     161    call    FindDPT_ForDriveNumber      ; Get DPT to DS:DI, store port to RAMVARS
     162    jnc     SHORT .NoMoreDrivesOrNoSlaveDrive
     163    cmp     cx, [RAMVARS.wIdeBase]      ; Next drive is from same controller?
     164    je      SHORT BackupErrorCodeFromTheRequestedDriveToBH
     165.NoMoreDrivesOrNoSlaveDrive:
     166    dec     dx
    96167    ret
    97168
    98169
    99170;--------------------------------------------------------------------
    100 ; Resets master and slave drive based on either drive number.
    101 ;
    102 ; AH0h_ResetMasterAndSlaveDriveWithRetries
     171; BackupErrorCodeFromTheRequestedDriveToBH
    103172;   Parameters:
    104 ;       DL:     Drive number for master or slave drive
     173;       AH:     Error code from the last resetted drive
     174;       DL:     Drive last resetted
     175;       BL:     Requested drive (DL when entering AH=00h)
    105176;   Returns:
    106 ;       AH:     Int 13h return status
    107 ;       CF:     0 if succesfull, 1 if error
    108 ;   Corrupts registers:
    109 ;       AL, DX, DI
    110 ;--------------------------------------------------------------------
    111 ALIGN JUMP_ALIGN
    112 AH0h_ResetMasterAndSlaveDriveWithRetries:
    113     push    cx
    114     push    bx
    115     mov     cx, RETRIES_IF_RESET_FAILS
    116 ALIGN JUMP_ALIGN
    117 .RetryLoop:
    118     mov     di, cx                      ; Backup counter
    119     call    AHDh_ResetDrive
    120     jnc     SHORT .Return
    121     mov     cx, TIMEOUT_BEFORE_RESET_RETRY
    122     call    SoftDelay_TimerTicks
    123     mov     cx, di
    124     loop    .RetryLoop
    125     mov     ah, RET_HD_RESETFAIL
    126     stc
    127 ALIGN JUMP_ALIGN
    128 .Return:
    129     pop     bx
    130     pop     cx
    131     ret
    132 
    133 
    134 ;--------------------------------------------------------------------
    135 ; Resets floppy drives and foreign hard disks.
    136 ;
    137 ; AH0h_ResetFloppyAndForeignHardDiskControllers
    138 ;   Parameters:
    139 ;       DL:     Drive number (ignored so all drives are reset)
    140 ;               If bit 7 is set all hard disks and floppy disks reset.
    141 ;   Returns:
    142 ;       AH:     Int 13h return status
    143 ;       CF:     0 if succesfull, 1 if error
     177;       BH:     Backuped error code
    144178;   Corrupts registers:
    145179;       Nothing
    146180;--------------------------------------------------------------------
    147181ALIGN JUMP_ALIGN
    148 AH0h_ResetFloppyAndForeignHardDiskControllers:
    149     xor     ah, ah                      ; AH=0h, Disk Controller Reset
    150     pushf                               ; Push flags to simulate INT
    151     cli                                 ; Disable interrupts
    152     call    FAR [RAMVARS.fpOldI13h]
     182BackupErrorCodeFromTheRequestedDriveToBH:
     183    cmp     dl, bl              ; Requested drive?
     184    jne     SHORT .Return
     185    mov     bh, ah
     186ALIGN JUMP_ALIGN
     187.Return:
    153188    ret
Note: See TracChangeset for help on using the changeset viewer.