Ignore:
File:
1 edited

Legend:

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

    r28 r10  
    22; Project name  :   IDE BIOS
    33; Created date  :   15.12.2009
    4 ; Last update   :   1.8.2010
     4; Last update   :   25.5.2010
    55; Author        :   Tomi Tilli
    66; Description   :   IDE Status Register polling functions.
     
    2525ALIGN JUMP_ALIGN
    2626HStatus_WaitIrqOrRdy:
    27     test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
    28     jnz     SHORT .PollRdySinceInterruptsAreDisabled
     27    test    BYTE [di+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
     28    jnz     SHORT .PollRdySinceIrqsAreDisabled
    2929    jmp     HIRQ_WaitIRQ
    30 
    31 ALIGN JUMP_ALIGN
    32 .PollRdySinceInterruptsAreDisabled:
     30ALIGN JUMP_ALIGN
     31.PollRdySinceIrqsAreDisabled:
     32    call    HStatus_ReadAndIgnoreAlternateStatus
    3333    mov     cl, B_TIMEOUT_DRQ               ; Load DRQ (not RDY) timeout
    3434    jmp     SHORT HStatus_WaitRdy           ; Jump to poll RDY
     
    3636
    3737;--------------------------------------------------------------------
     38; Reads Alternate Status Register and ignores result.
     39; Alternate Status Register is read to prevent polling host from
     40; reading status before it is valid.
     41;
     42; HStatus_ReadAndIgnoreAlternateStatus
     43;   Parameters:
     44;       DS:BX:  Ptr to DPT
     45;   Returns:
     46;       Nothing
     47;   Corrupts registers:
     48;       AL, CX, DX
     49;--------------------------------------------------------------------
     50ALIGN JUMP_ALIGN
     51HStatus_ReadAndIgnoreAlternateStatus:
     52    mov     cx, bx                          ; Backup BX
     53    eMOVZX  bx, BYTE [bx+DPT.bIdeOff]       ; CS:BX now points to IDEVARS
     54    mov     dx, [cs:bx+IDEVARS.wPortCtrl]   ; DX = Control Block base port
     55    add     dx, BYTE REGR_IDEC_AST          ; DX = Alternate Status Register address
     56    in      al, dx                          ; Read Alternate Status Register
     57    mov     bx, cx                          ; Restore BX
     58    ret
     59
     60
     61;--------------------------------------------------------------------
    3862; Waits until Hard Disk is ready to transfer data.
    3963;
     
    5074ALIGN JUMP_ALIGN
    5175HStatus_WaitIrqOrDrq:
    52     test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
    53     jnz     SHORT .PollDrqSinceInterruptsAreDisabled
    54     jmp     HIRQ_WaitIRQ
    55 
    56 ALIGN JUMP_ALIGN
    57 .PollDrqSinceInterruptsAreDisabled:
    5876    push    dx
    5977    push    cx
     78
     79    ; Check if interrupts are enabled
     80    test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
     81    jnz     SHORT .PollDRQ                  ; Poll DRQ if IRQ disabled
     82    call    HIRQ_WaitIRQ                    ; Wait for IRQ
     83    jmp     SHORT .Return
     84
     85ALIGN JUMP_ALIGN
     86.PollDRQ:
     87    call    HStatus_ReadAndIgnoreAlternateStatus
    6088    call    HStatus_WaitDrqDefTime
     89ALIGN JUMP_ALIGN
     90.Return:
    6191    pop     cx
    6292    pop     dx
     
    159189; IDE Status register polling.
    160190; This function first waits until controller is not busy.
    161 ; When not busy, IDE Status Register is polled until wanted flag is set.
     191; When not busy, IDE Status Register is polled until wanted
     192; flag (HBIT_ST_DRDY or HBIT_ST_DRQ) is set.
    162193;
    163194; HStatus_PollBusyAndFlg
     
    176207ALIGN JUMP_ALIGN
    177208HStatus_PollBsyAndFlg:
    178     call    SoftDelay_InitTimeout               ; Initialize timeout counter
    179     in      al, dx                              ; Discard contents for first read
    180                                                 ; (should read Alternate Status Register)
     209    call    SoftDelay_InitTimeout       ; Initialize timeout counter
    181210ALIGN JUMP_ALIGN
    182211.PollLoop:
    183     in      al, dx                              ; Load IDE Status Register
    184     test    al, FLG_IDE_ST_BSY                  ; Controller busy?
    185     jnz     SHORT .UpdateTimeout                ;  If so, jump to timeout update
    186     test    al, ah                              ; Test secondary flag
    187     jnz     SHORT GetErrorCodeFromPollingToAH   ; If set, break loop
     212    in      al, dx                      ; Load IDE Status Register
     213    test    al, FLG_IDE_ST_BSY          ; Controller busy?
     214    jnz     SHORT .UpdateTimeout        ;  If so, jump to timeout update
     215    test    al, ah                      ; Test secondary flag
     216    jnz     SHORT HStatus_PollCompleted ; If set, break loop
    188217ALIGN JUMP_ALIGN
    189218.UpdateTimeout:
    190     call    SoftDelay_UpdTimeout                ; Update timeout counter
    191     jnc     SHORT .PollLoop                     ; Loop if time left (sets CF on timeout)
    192     jmp     HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
     219    call    SoftDelay_UpdTimeout        ; Update timeout counter
     220    jnc     SHORT .PollLoop             ; Loop if time left (sets CF on timeout)
     221    mov     ah, RET_HD_TIMEOUT          ; Load error code for timeout
     222    ret
     223
    193224
    194225;--------------------------------------------------------------------
     
    210241ALIGN JUMP_ALIGN
    211242HStatus_PollBsy:
    212     call    SoftDelay_InitTimeout               ; Initialize timeout counter
    213     in      al, dx                              ; Discard contents for first read
    214                                                 ; (should read Alternate Status Register)
     243    call    SoftDelay_InitTimeout       ; Initialize timeout counter
    215244ALIGN JUMP_ALIGN
    216245.PollLoop:
    217     in      al, dx                              ; Load IDE Status Reg
    218     test    al, FLG_IDE_ST_BSY                  ; Controller busy?
    219     jz      SHORT GetErrorCodeFromPollingToAH   ;  If not, jump to check errors
    220     call    SoftDelay_UpdTimeout                ; Update timeout counter
    221     jnc     SHORT .PollLoop                     ; Loop if time left (sets CF on timeout)
    222 ALIGN JUMP_ALIGN
    223 GetErrorCodeFromPollingToAH:
    224     jmp     HError_ProcessErrorsAfterPollingBSY
     246    in      al, dx                      ; Load IDE Status Reg
     247    test    al, FLG_IDE_ST_BSY          ; Controller busy? (clears CF)
     248    jz      SHORT HStatus_PollCompleted ;  If not, jump to check errors
     249    call    SoftDelay_UpdTimeout        ; Update timeout counter
     250    jnc     SHORT .PollLoop             ; Loop if time left (sets CF on timeout)
     251    mov     ah, RET_HD_TIMEOUT          ; Load error code for timeout
     252    ret
     253
     254ALIGN JUMP_ALIGN
     255HStatus_PollCompleted:
     256    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_ERR
     257    jnz     SHORT .GetErrorCode         ;  If errors, jump to get error code
     258    xor     ah, ah                      ; Zero AH and clear CF
     259    ret
     260.GetErrorCode:
     261    jmp     HError_GetErrorCodeForStatusReg
Note: See TracChangeset for help on using the changeset viewer.