Changeset 28 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src


Ignore:
Timestamp:
Aug 1, 2010, 5:57:24 PM (14 years ago)
Author:
aitotat
google:author:
aitotat
Message:
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Improved error handling a bit.
  • Longer DRQ and IRQ timeouts to minimize write timouts with some (bad) CF cards.
  • Default boot menu drive should now be properly selected.
Location:
trunk/XTIDE_Universal_BIOS/Src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenu.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   25.3.2010
    4 ; Last update   :   1.4.2010
     4; Last update   :   29.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Displays Boot Menu.
     
    323323;       DS:     RAMVARS segment
    324324;   Returns:
    325 ;       SF:     Set if drive number is valid
     325;       CF:     Set if drive number is valid
    326326;               Clear if drive is not present in system
    327327;   Corrupts registers:
    328 ;       AX
     328;       AX, CX
    329329;--------------------------------------------------------------------
    330330ALIGN JUMP_ALIGN
     
    332332    test    dl, 80h                 ; Floppy drive?
    333333    jz      SHORT .IsFloppyDriveIsInSystem
    334     call    RamVars_GetDriveCounts
    335     mov     ax, 7Fh                 ; Load mask to clear floppy bit
    336     and     ax, dx                  ; AX = Hard Disk index
    337     cmp     ax, cx                  ; Valid drive index?
    338     ret
    339 ALIGN JUMP_ALIGN
     334    call    RamVars_GetDriveCounts  ; Hard Disk count to CX
     335    or      cl, 80h                 ; Set Hard Disk bit to CX
     336    jmp     SHORT .CompareDriveNumberToDriveCount
    340337.IsFloppyDriveIsInSystem:
    341     call    FloppyDrive_GetCount
     338    call    FloppyDrive_GetCount    ; Floppy Drive count to CX
     339.CompareDriveNumberToDriveCount:
    342340    cmp     dl, cl
    343341    ret
  • trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuEvent.asm

    r3 r28  
    283283    mov     dl, [cs:ROMVARS.bBootDrv]   ; Default boot drive
    284284    call    BootMenu_IsDriveInSystem
    285     jns     SHORT .DoNotSetDefaultMenuitem
     285    jnc     SHORT .DoNotSetDefaultMenuitem
     286    call    DriveXlate_SetDriveToSwap
    286287    call    BootMenu_ConvertDriveToMenuitem
    287288    mov     ax, 1
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   21.9.2007
    4 ; Last update   :   12.4.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h BIOS functions (Floppy and Hard disk).
     
    5757    call    RamVars_IsFunctionHandledByThisBIOS
    5858    jnc     SHORT Int13h_DirectCallToAnotherBios
     59    ;DEBUG_PRINT_DRIVE_AND_FUNCTION
    5960
    6061    ; Jump to correct BIOS function
     
    147148;
    148149; Int13h_ReturnWithoutSwappingDrives
     150; Int13h_StoreErrorCodeToBDAandPopDSDIandReturn
     151; Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn
    149152; Int13h_PopXRegsAndReturn
    150153; Int13h_PopDiDsAndReturn
     
    160163Int13h_ReturnWithoutSwappingDrives:
    161164    pushf
    162     dec     BYTE [RAMVARS.xlateVars+XLATEVARS.bRecurCnt]
    163     jmp     SHORT Int13h_StoreErrorCodeAndLeave
     165    dec     BYTE [RAMVARS.xlateVars+XLATEVARS.bRecurCnt]    ; Preserves CF
     166    call    HError_StoreBiosErrorCodeFromAHtoBDA
     167    jmp     SHORT Int13h_Leave
     168
     169ALIGN JUMP_ALIGN
     170Int13h_StoreErrorCodeToBDAandPopDSDIandReturn:
     171    call    HError_StoreBiosErrorCodeFromAHtoBDA
     172    jmp     SHORT Int13h_PopDiDsAndReturn
     173
     174ALIGN JUMP_ALIGN
     175Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn:
     176    call    HError_StoreBiosErrorCodeFromAHtoBDA
    164177ALIGN JUMP_ALIGN
    165178Int13h_PopXRegsAndReturn:
     
    173186    pushf
    174187    call    DriveXlate_WhenLeavingInt13h
    175 Int13h_StoreErrorCodeAndLeave:
    176     LOAD_BDA_SEGMENT_TO ds, di
    177     mov     [BDA.bHDLastSt], ah         ; Store error code
    178188Int13h_Leave:
    179189    popf
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   27.9.2007
    4 ; Last update   :   28.7.2010
     4; Last update   :   29.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=0h, Disk Controller Reset.
     
    4747    xor     al, al                      ; Zero AL...
    4848    cmp     al, bh                      ; ...and set CF if error
    49     jmp     Int13h_PopXRegsAndReturn
     49    jmp     Int13h_StoreErrorCodeToBDAandPopXRegsAndReturn
    5050
    5151
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH11h_HRecal.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   28.9.2007
    4 ; Last update   :   12.4.2010
     4; Last update   :   29.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=11h, Recalibrate.
     
    5555    mov     cx, 1                       ; Seek to Cylinder 0, Sector 1
    5656    xor     dh, dh                      ; Head 0
    57     call    AHCh_SeekToCylinder
    58     ret
     57    jmp     AHCh_SeekToCylinder
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH14h_HDiag.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   28.9.2007
    4 ; Last update   :   12.4.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=14h, Controller Internal Diagnostic.
     
    3333    jnz     SHORT .ReturnError
    3434    xor     ah, ah                      ; Zero AH and CF since success
    35     jmp     Int13h_PopDiDsAndReturn
     35    jmp     Int13h_StoreErrorCodeToBDAandPopDSDIandReturn
    3636.ReturnError:
    3737    mov     ah, RET_HD_RESETFAIL
    3838    stc
    39     jmp     Int13h_PopDiDsAndReturn
     39    jmp     Int13h_StoreErrorCodeToBDAandPopDSDIandReturn
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1h_HStatus.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   27.9.2007
    4 ; Last update   :   12.4.2010
     4; Last update   :   29.7.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=1h, Read Disk Status.
     
    2828AH1h_HandlerForReadDiskStatus:
    2929    push    ds
     30
    3031    LOAD_BDA_SEGMENT_TO ds, di
    3132    xor     ah, ah                  ; Zero AH
    3233    cmp     ah, [BDA.bHDLastSt]     ; Set CF if error code is non-zero
    33     mov     ah, [BDA.bHDLastSt]
     34    xchg    ah, [BDA.bHDLastSt]     ; Last error to AH, zero to BDA
     35
    3436    pop     ds
    3537    jmp     Int13h_PopDiDsAndReturn
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   27.9.2007
    4 ; Last update   :   12.4.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=2h, Read Disk Sectors.
     
    6363    mov     ah, RET_HD_INVALID          ; Invalid value passed
    6464    stc                                 ; Set CF since error
    65     jmp     Int13h_PopDiDsAndReturn
     65    jmp     Int13h_StoreErrorCodeToBDAandPopDSDIandReturn
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm

    r3 r28  
    4141; Returns L-CHS parameters for drive and total hard disk count.
    4242;
    43 ; AH8h_HParams
     43; AH8h_GetDriveParameters
    4444;   Parameters:
    4545;       DL:     Drive number
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   9.12.2007
    4 ; Last update   :   26.4.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=9h, Initialize Drive Parameters.
     
    7878.InitializeBlockMode:
    7979    call    AH9h_InitializeBlockMode
    80     ;mov    dl, [di+DPT.bDrvNum]        ; Restore DL
     80    ;mov        dl, [di+DPT.bDrvNum]        ; Restore DL
    8181    jc      SHORT .ReturnNotSuccessfull
    8282    and     BYTE [di+DPT.bReset], ~FLG_RESET_nSETBLOCK
     83
     84    ; Force PIO mode 0
     85    ;call   AH9h_ForcePioMode0
    8386
    8487.ReturnNotSuccessfull:
     
    149152.Return:
    150153    ret
     154
     155
     156;--------------------------------------------------------------------
     157; AH9h_ForcePioMode0
     158;   Parameters:
     159;       DL:     Drive number
     160;       DS:DI:  Ptr to DPT
     161;   Returns:
     162;       AH:     BIOS Error code
     163;       CF:     Cleared if succesfull
     164;               Set if any error
     165;   Corrupts registers:
     166;       AX, BX
     167;--------------------------------------------------------------------
     168;ALIGN JUMP_ALIGN
     169;AH9h_ForcePioMode0:
     170;   mov     bh, 08h     ; Parameter to Sector Count Register (PIO Flow Control Transfer Mode 0)
     171;   mov     ax, 2303h   ; Feature: Set transfer mode based on value in Sector Count register
     172;   int     13h
     173;   jc      SHORT .FailedToForcePIO0
     174;   ; Debug output here
     175;   ret
     176;.FailedToForcePIO0:
     177;   ; Debug output here
     178;   ret
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   9.12.2007
    4 ; Last update   :   28.7.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 13h function AH=Dh, Reset Hard Disk (Alternate reset).
     
    2626AHDh_HandlerForResetHardDisk:
    2727    call    AHDh_ResetDrive
    28     jmp     Int13h_PopDiDsAndReturn
     28    jmp     Int13h_StoreErrorCodeToBDAandPopDSDIandReturn
    2929
    3030
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   30.11.2007
    4 ; Last update   :   28.7.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Error checking functions for BIOS Hard disk functions.
     
    1010
    1111;--------------------------------------------------------------------
    12 ; HError_GetErrorCodeToAHforBitPollingTimeout
     12; HError_ProcessErrorsAfterPollingTaskFlag
    1313;   Parameters:
    14 ;       AL:     IDE Status Register contents
    15 ;       DX:     IDE Status Register Address
     14;       DS:     RAMVARS segment
     15;       ES:     BDA segment (zero)
     16;       CF:     Set if timeout
     17;               Cleared if task flag was properly set
    1618;   Returns:
    17 ;       AH:     Hard disk BIOS error code
    18 ;       CF:     Set since error
    19 ;   Corrupts registers:
    20 ;       AL, CX
    21 ;--------------------------------------------------------------------
    22 ALIGN JUMP_ALIGN
    23 HError_GetErrorCodeToAHforBitPollingTimeout:
    24     test    al, FLG_IDE_ST_BSY                      ; Other bits undefined when BSY set
    25     jnz     SHORT HError_GetErrorCodeForStatusReg   ; Busy, normal timeout
    26     test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
    27     jnz     SHORT HError_GetErrorCodeForStatusReg   ; Not busy but some error
    28     or      al, FLG_IDE_ST_BSY                      ; Polled bit got never set, force timeout
    29     ; Fall to HError_GetErrorCodeForStatusReg
    30 
    31 ;--------------------------------------------------------------------
    32 ; Converts Status Register error to BIOS error code.
    33 ;
    34 ; HError_GetErrorCodeForStatusReg
    35 ;   Parameters:
    36 ;       AL:     IDE Status Register contents
    37 ;       DX:     IDE Status Register Address
    38 ;   Returns:
    39 ;       AH:     Hard disk BIOS error code
    40 ;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
    41 ;               1 if some error
    42 ;   Corrupts registers:
    43 ;       AL, CX
    44 ;--------------------------------------------------------------------
    45 ALIGN JUMP_ALIGN
    46 HError_GetErrorCodeForStatusReg:
    47     ; Get Error Register contents to AH
    48     mov     ah, al                              ; Backup Status Reg to AH
    49     sub     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Status Reg to Error Reg
    50     in      al, dx                              ; Read Error Register to AL
    51     xchg    al, ah                              ; Swap status and error
    52     add     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Restore DX
    53 
    54     ; Store Register contents to BDA
    55     push    ds
    56     LOAD_BDA_SEGMENT_TO ds, cx
    57     mov     [HDBDA.wHDStAndErr], ax         ; Store Status and Error to BDA
    58     pop     ds
    59     ; Fall to HError_ConvertIdeErrorToBiosRet
    60 
    61 ;--------------------------------------------------------------------
    62 ; Converts error flags from IDE status and error register contents
    63 ; to BIOS Int 13h return value.
    64 ;
    65 ; HError_ConvertIdeErrorToBiosRet
    66 ;   Parameters:
    67 ;       AL:     Status Register Contents
    68 ;       AH:     Error Register Contents
    69 ;   Returns:
    70 ;       AH:     Hard disk BIOS error code
    71 ;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
    72 ;               1 if any error
     19;       AH:     BIOS error code
     20;       CF:     Set if error
     21;               Cleared if no error
    7322;   Corrupts registers:
    7423;       AL
    7524;--------------------------------------------------------------------
    7625ALIGN JUMP_ALIGN
    77 HError_ConvertIdeErrorToBiosRet:
     26HError_ProcessErrorsAfterPollingTaskFlag:
     27    jc      SHORT HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
     28    mov     ax, [es:HDBDA.wHDStAndErr]
     29    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     30    mov     [es:BDA.bHDLastSt], ah
     31    mov     BYTE [es:BDA.bHDTaskFlg], 0
     32    ret
     33
     34;--------------------------------------------------------------------
     35; HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
     36; HError_ProcessErrorsAfterPollingBSY
     37;   Parameters:
     38;       DS:     RAMVARS segment
     39;   Returns:
     40;       AH:     BIOS error code
     41;       CF:     Set if error
     42;               Cleared if no error
     43;   Corrupts registers:
     44;       AL
     45;--------------------------------------------------------------------
     46ALIGN JUMP_ALIGN
     47HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit:
     48    push    ds
     49    push    dx
     50
     51    call    HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     52    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     53    jc      SHORT StoreErrorCodeFromAHtoBDA
     54    mov     ah, RET_HD_TIMEOUT          ; Force timeout since no actual error...
     55    stc                                 ; ...but wanted bit was never set
     56    jmp     SHORT StoreErrorCodeFromAHtoBDA
     57
     58
     59ALIGN JUMP_ALIGN
     60HError_ProcessErrorsAfterPollingBSY:
     61    push    ds
     62    push    dx
     63
     64    call    HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     65    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     66StoreErrorCodeFromAHtoBDA:
     67    mov     [BDA.bHDLastSt], ah         ; Store BIOS error code to BDA
     68
     69    pop     dx
     70    pop     ds
     71    ret
     72
     73
     74;--------------------------------------------------------------------
     75; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     76;   Parameters:
     77;       DS:     RAMVARS segment
     78;   Returns:
     79;       AL:     IDE Status Register contents
     80;       AH:     IDE Error Register contents
     81;       DS:     BDA segment
     82;   Corrupts registers:
     83;       DX
     84;--------------------------------------------------------------------
     85ALIGN JUMP_ALIGN
     86HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA:
     87    mov     dx, [RAMVARS.wIdeBase]      ; Load IDE base port address
     88    inc     dx                          ; Increment to Error Register
     89    in      al, dx                      ; Read Error Register...
     90    mov     ah, al                      ; ...and copy it to AH
     91    add     dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR
     92    in      al, dx                      ; Read Status Register to AL
     93    ; Fall to .StoreStatusAndErrorRegistersFromAXtoBDA
     94
     95;--------------------------------------------------------------------
     96; .StoreStatusAndErrorRegistersFromAXtoBDA
     97;   Parameters:
     98;       AL:     IDE Status Register contents
     99;       AH:     IDE Error Register contents
     100;   Returns:
     101;       DS:     BDA segment (zero)
     102;   Corrupts registers:
     103;       DX
     104;--------------------------------------------------------------------
     105.StoreStatusAndErrorRegistersFromAXtoBDA:
     106    LOAD_BDA_SEGMENT_TO ds, dx
     107    mov     [HDBDA.wHDStAndErr], ax
     108    ret
     109
     110
     111;--------------------------------------------------------------------
     112; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     113;   Parameters:
     114;       AL:     IDE Status Register contents
     115;       AH:     IDE Error Register contents
     116;   Returns:
     117;       AH:     BIOS INT 13h error code
     118;       CF:     Set if error
     119;               Cleared if no error
     120;   Corrupts registers:
     121;       Nothing
     122;--------------------------------------------------------------------
     123ALIGN JUMP_ALIGN
     124GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
    78125    test    al, FLG_IDE_ST_BSY
    79     jnz     SHORT .TimeoutError
     126    jz      SHORT .CheckErrorBitsFromStatusRegisterInAL
     127    mov     ah, RET_HD_TIMEOUT
     128    jmp     SHORT .ReturnBiosErrorCodeInAH
     129
     130ALIGN JUMP_ALIGN
     131.CheckErrorBitsFromStatusRegisterInAL:
    80132    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
    81     jnz     SHORT .ReadErrorFromStatusReg
     133    jnz     SHORT .ProcessErrorFromStatusRegisterInAL
    82134    xor     ah, ah                  ; No errors, zero AH and CF
    83135    ret
    84136
    85 .TimeoutError:
    86     mov     ah, RET_HD_TIMEOUT
    87     stc
    88     ret
    89 
    90 ; Convert error code based on status or error register
    91 .ReadErrorFromStatusReg:
     137.ProcessErrorFromStatusRegisterInAL:
    92138    test    al, FLG_IDE_ST_ERR      ; Error specified in Error register?
    93     jnz     SHORT .ReadErrorFromErrorReg
     139    jnz     SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
    94140    mov     ah, RET_HD_ECC          ; Assume ECC corrected error
    95141    test    al, FLG_IDE_ST_CORR     ; ECC corrected error?
    96     jnz     SHORT .Return
     142    jnz     SHORT .ReturnBiosErrorCodeInAH
    97143    mov     ah, RET_HD_CONTROLLER   ; Must be Device Fault
    98     jmp     SHORT .Return
     144    jmp     SHORT .ReturnBiosErrorCodeInAH
    99145
    100 ; Convert error register to bios error code
    101 .ReadErrorFromErrorReg:
     146.ConvertBiosErrorToAHfromErrorRegisterInAH:
    102147    push    bx
    103     mov     al, ah                  ; Copy error reg to AL...
    104     xor     ah, ah                  ; ...and zero extend to AX
    105     eBSF    bx, ax                  ; Get bit index to BX
    106     mov     ah, RET_HD_STATUSERR    ; Error code if Error Reg is zero
    107     jz      SHORT .SkipLookup       ; Return if error register is zero
     148    mov     bx, .rgbRetCodeLookup
     149.ErrorBitLoop:
     150    rcr     ah, 1                   ; Set CF if error bit set
     151    jc      SHORT .LookupErrorCode
     152    inc     bx
     153    cmp     bx, .rgbRetCodeLookup + 8
     154    jb      SHORT .ErrorBitLoop     ; Loop until all bits checked
     155.LookupErrorCode:
    108156    mov     ah, [cs:bx+.rgbRetCodeLookup]
    109 .SkipLookup:
    110157    pop     bx
    111 .Return:
     158
     159.ReturnBiosErrorCodeInAH:
    112160    stc                             ; Set CF since error
    113161    ret
     
    122170    db  RET_HD_UNCORRECC    ; Bit6=UNC, Uncorrectable Data Error
    123171    db  RET_HD_BADSECTOR    ; Bit7=BBK, Bad Block Detected
     172    db  RET_HD_STATUSERR    ; When Error Register is zero
     173
     174
     175;--------------------------------------------------------------------
     176; HError_StoreBiosErrorCodeFromAHtoBDA
     177;   Parameters:
     178;       AH:     BIOS error code
     179;   Returns:
     180;       Nothing
     181;   Corrupts registers:
     182;       DI
     183;--------------------------------------------------------------------
     184ALIGN JUMP_ALIGN
     185HError_StoreBiosErrorCodeFromAHtoBDA:
     186    push    ds
     187    mov     di, 0                   ; Zero DI and preserve FLAGS
     188    mov     ds, di                  ; Copy BDA segment to DS
     189    mov     [BDA.bHDLastSt], ah
     190    pop     ds
     191    ret
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   11.12.2009
    4 ; Last update   :   28.3.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Interrupt handling related functions.
     
    2020;               Set if any error
    2121;   Corrupts registers:
    22 ;       AL, CX
     22;       AL
    2323;--------------------------------------------------------------------
    2424ALIGN JUMP_ALIGN
    2525HIRQ_WaitIRQ:
    26     ; Load BDA segment to ES
    2726    push    es
    28     xor     ax, ax                      ; Zero AX and clear CF
    29     mov     es, ax                      ; Copy BDA segment (zero) to ES
    3027
    31     ; Check if interrupt has already occurred
     28    LOAD_BDA_SEGMENT_TO es, ax
     29%ifdef USE_AT   ; OS hook only available on AT+ machines
     30    call    .NotifyOperatingSystemAboutWaitingForIRQ
     31    cmc
     32    jnc     SHORT .TaskFlagPollingComplete
     33%endif
     34    call    .WaitUntilTaskFlagIsSet     ; Process errors
     35
     36ALIGN JUMP_ALIGN
     37.TaskFlagPollingComplete:
     38    call    HError_ProcessErrorsAfterPollingTaskFlag
     39    pop     es
     40    ret
     41
     42;--------------------------------------------------------------------
     43; .NotifyOperatingSystemAboutWaitingForIRQ
     44;   Parameters:
     45;       ES:     BDA segment (zero)
     46;   Returns:
     47;       CF:     Set if wait done by operating system
     48;               Cleared if BIOS must perform task flag polling
     49;   Corrupts registers:
     50;       AX
     51;--------------------------------------------------------------------
     52%ifdef USE_AT
     53ALIGN JUMP_ALIGN
     54.NotifyOperatingSystemAboutWaitingForIRQ:
    3255    cli                                 ; Disable interrupts
    33     cmp     [es:BDA.bHDTaskFlg], al     ; Interrupt ready?
    34     jne     SHORT .CheckIdeErrors       ;  If so, return
     56    xor     ax, ax
     57    cmp     al, [es:BDA.bHDTaskFlg]     ; Task flag already set?
     58    jc      SHORT .ReturnFromWaitNotify ;  If so, skip OS notification
    3559
    36 %ifdef USE_AT   ; OS hook only available on AT+ machines
    37     ; OS device busy notification
    3860    mov     ah, 90h                     ; Hard disk busy (AX=9000h)
    3961    int     INTV_SYSTEM_SERVICES        ; OS hook, device busy
    40     jnc     SHORT .WaitUntilTaskFlagSet ; CF cleared, BIOS handles waiting
    41     test    ah, ah                      ; OS hook supported? (clear CF)
    42     jz      SHORT .CheckIdeErrors       ;  If so, waiting completed
    43 ALIGN JUMP_ALIGN
    44 .WaitUntilTaskFlagSet:
    45 %endif
     62    jnc     SHORT .ReturnFromWaitNotify ; CF cleared, BIOS handles waiting
    4663
    47     ; Poll task flag until it has been set by interrupt service routine
    48     call    HIRQ_WaitUntilTaskFlagIsSet
    49     jc      SHORT .ReturnTimeout        ; Return if timeout
    50 
    51 ALIGN JUMP_ALIGN
    52 .CheckIdeErrors:
    53     mov     ax, [es:HDBDA.wHDStAndErr]  ; Load Status and Error regs stored by ISR
    54     call    HError_ConvertIdeErrorToBiosRet
    55 .ReturnTimeout:
    56     mov     BYTE [es:BDA.bHDTaskFlg], 0 ; Clear Task Flag
    57     pop     es
     64    ; Make sure that OS hooks are supported, otherwise the CF means unsupported function
     65    test    ah, ah                      ; OS hook supported? (clears CF)
     66    jnz     SHORT .ReturnFromWaitNotify ; AH has error, BIOS must do the wait
     67    stc                                 ; Set CF since wait done by OS
     68.ReturnFromWaitNotify:
    5869    sti                                 ; Enable interrupts
    5970    ret
    60 
     71%endif
    6172
    6273;--------------------------------------------------------------------
    6374; Polls IRQ Task Flag until it has been set or timeout.
    6475;
    65 ; HIRQ_WaitUntilTaskFlagIsSet
     76; .WaitUntilTaskFlagIsSet
    6677;   Parameters:
    6778;       DS:     RAMVARS segment
    6879;       ES:     BDA segment
    6980;   Returns:
    70 ;       AH:     BIOS Error code
    71 ;       CF:     Cleared if wait succesfull
    72 ;               Set if timeout
     81;       CF:     Set if timeout
     82;               Cleared if Task Flag set
    7383;   Corrupts registers:
    74 ;       AL, CX
     84;       AX
    7585;--------------------------------------------------------------------
    7686ALIGN JUMP_ALIGN
    77 HIRQ_WaitUntilTaskFlagIsSet:
    78     sti                             ; Enable interrupts
     87.WaitUntilTaskFlagIsSet:
     88    push    cx
     89
    7990    mov     cl, B_TIMEOUT_DRQ       ; Load timeout ticks
    8091    call    SoftDelay_InitTimeout   ; Initialize timeout counter
     
    8293ALIGN JUMP_ALIGN
    8394.PollIrqFlag:
    84     cli                             ; Disable interrupts
    85     cmp     [es:BDA.bHDTaskFlg], al ; Task flag set?
    86     jne     SHORT .TaskFlagIsSet    ;  If so, return
     95    cli                             ; Disable interrupt until next HLT
     96    cmp     [es:BDA.bHDTaskFlg], al ; Task flag set? (clears CF)
     97    jne     SHORT .Return
    8798    call    SoftDelay_UpdTimeout    ; Update timeout
    88     jc      SHORT .Timeout          ; Return if timeout
    89     sti                             ; Enable interrupts (one instruction delay)
     99    jc      SHORT .Return           ; Return if timeout
     100    sti                             ; Enable interrupts (STI has delay so HLT will catch all interrupts)
    90101    hlt                             ; Sleep until any interrupt
    91102    jmp     SHORT .PollIrqFlag      ; Jump to check if IDE interrupt
    92 
    93103ALIGN JUMP_ALIGN
    94 .TaskFlagIsSet:
    95     xor     ah, ah                  ; Zero AH, clear CF
    96     ret
    97 .Timeout:
    98     mov     ah, RET_HD_TIMEOUT      ; Load error code for timeout
     104.Return:
     105    pop     cx
     106    sti
    99107    ret
    100108
     
    134142ALIGN JUMP_ALIGN
    135143HIRQ_InterruptServiceRoutineForIrqs2to7:
    136     ; Acknowledge IDE interrupt by reading status register
    137144    push    ax
    138     call    ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA
     145    call    AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
     146
    139147    mov     al, CMD_END_OF_INTERRUPT
    140     jmp     SHORT HIRQ_AcknowledgeMasterController
     148    jmp     SHORT AcknowledgeMasterInterruptController
    141149
    142150ALIGN JUMP_ALIGN
    143151HIRQ_InterruptServiceRoutineForIrqs8to15:
    144152    push    ax
    145     call    ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA
     153    call    AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
    146154
    147155    mov     al, CMD_END_OF_INTERRUPT    ; Load EOI command to AL
    148156    out     WPORT_8259SL_COMMAND, al    ; Acknowledge Slave 8259
    149 HIRQ_AcknowledgeMasterController:
     157AcknowledgeMasterInterruptController:
    150158    out     WPORT_8259MA_COMMAND, al    ; Acknowledge Master 8259
    151159
     
    156164%endif
    157165
    158     ; Restore registers and return from interrupt
    159166    pop     ax                          ; Restore AX
    160167    iret
    161 
    162168
    163169;--------------------------------------------------------------------
     
    166172; also be set.
    167173;
    168 ; ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA
     174; AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
    169175;   Parameters:
    170176;       Nothing
     
    175181;--------------------------------------------------------------------
    176182ALIGN JUMP_ALIGN
    177 ISR_IDE_AcknowledgeIdeAndStoreStatusToBDA:
     183AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA:
    178184    push    ds
    179185    push    di
    180186    push    dx
    181187
    182     ; Read Status and Error registers.
    183188    ; Reading Status Register acknowledges IDE interrupt
    184189    call    RamVars_GetSegmentToDS
    185     mov     dx, [RAMVARS.wIdeBase]      ; Load IDE base port address
    186     inc     dx                          ; Increment to Error Register
    187     in      al, dx                      ; Read Error Register...
    188     mov     ah, al                      ; ...and copy it to AH
    189     add     dx, REGR_IDE_ST-REGR_IDE_ERROR
    190     in      al, dx                      ; Read Status Register to AL
    191 
    192     ; Store Status and Error register to BDA and set task flag
    193     LOAD_BDA_SEGMENT_TO ds, dx
    194     mov     [HDBDA.wHDStAndErr], ax     ; Store Status and Error Registers
    195     mov     BYTE [BDA.bHDTaskFlg], 0FFh ; Set task flag
     190    call    HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     191    mov     BYTE [BDA.bHDTaskFlg], 0FFh     ; Set task flag
    196192
    197193    pop     dx
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm

    r26 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   14.12.2007
    4 ; Last update   :   14.4.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   PIO transfer functions.
     
    168168    add     cx, [bp+PIOVARS.wWordsLeft] ; CX to partial block size
    169169    call    [bp+PIOVARS.fnXfer]         ; Transfer possibly partial block
    170     call    HStatus_ReadAndIgnoreAlternateStatus
    171170    jmp     HStatus_WaitBsyDefTime      ; Check for errors
    172171.RetError:
     
    232231HPIO_WriteToDrive:
    233232    cld                                     ; OUTS to increment SI
    234     call    HStatus_WaitDrqDefTime          ; Always poll DRQ for first block, get data port to DX
     233    call    HStatus_WaitDrqDefTime          ; Always poll DRQ for first block, get status reg to DX
    235234    jc      SHORT .RetError                 ; Return if error (code in AH)
    236235    sub     dx, BYTE REGR_IDE_ST            ; DX to Data Port address
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   15.12.2009
    4 ; Last update   :   28.7.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   IDE Status Register polling functions.
     
    2626HStatus_WaitIrqOrRdy:
    2727    test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
    28     jnz     SHORT .PollRdySinceIrqsAreDisabled
     28    jnz     SHORT .PollRdySinceInterruptsAreDisabled
    2929    jmp     HIRQ_WaitIRQ
    30 ALIGN JUMP_ALIGN
    31 .PollRdySinceIrqsAreDisabled:
    32     call    HStatus_ReadAndIgnoreAlternateStatus
     30
     31ALIGN JUMP_ALIGN
     32.PollRdySinceInterruptsAreDisabled:
    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 ;--------------------------------------------------------------------
    50 ALIGN JUMP_ALIGN
    51 HStatus_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 ;--------------------------------------------------------------------
    6238; Waits until Hard Disk is ready to transfer data.
    6339;
     
    7450ALIGN JUMP_ALIGN
    7551HStatus_WaitIrqOrDrq:
     52    test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
     53    jnz     SHORT .PollDrqSinceInterruptsAreDisabled
     54    jmp     HIRQ_WaitIRQ
     55
     56ALIGN JUMP_ALIGN
     57.PollDrqSinceInterruptsAreDisabled:
    7658    push    dx
    7759    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 
    85 ALIGN JUMP_ALIGN
    86 .PollDRQ:
    87     call    HStatus_ReadAndIgnoreAlternateStatus
    8860    call    HStatus_WaitDrqDefTime
    89 ALIGN JUMP_ALIGN
    90 .Return:
    9161    pop     cx
    9262    pop     dx
     
    207177HStatus_PollBsyAndFlg:
    208178    call    SoftDelay_InitTimeout               ; Initialize timeout counter
     179    in      al, dx                              ; Discard contents for first read
     180                                                ; (should read Alternate Status Register)
    209181ALIGN JUMP_ALIGN
    210182.PollLoop:
     
    218190    call    SoftDelay_UpdTimeout                ; Update timeout counter
    219191    jnc     SHORT .PollLoop                     ; Loop if time left (sets CF on timeout)
    220     jmp     HError_GetErrorCodeToAHforBitPollingTimeout
     192    jmp     HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
    221193
    222194;--------------------------------------------------------------------
     
    239211HStatus_PollBsy:
    240212    call    SoftDelay_InitTimeout               ; Initialize timeout counter
     213    in      al, dx                              ; Discard contents for first read
     214                                                ; (should read Alternate Status Register)
    241215ALIGN JUMP_ALIGN
    242216.PollLoop:
     
    248222ALIGN JUMP_ALIGN
    249223GetErrorCodeFromPollingToAH:
    250     jmp     HError_GetErrorCodeForStatusReg
     224    jmp     HError_ProcessErrorsAfterPollingBSY
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm

    r3 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   3.8.2007
    4 ; Last update   :   2.5.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Int 19h BIOS functions (Boot Strap Loader).
     
    1010
    1111B_READ_RETRY_TIMES  EQU 3   ; Number of times to retry
    12 B_READ_RETRY_DELAY  EQU 3   ; Timer ticks between retries
    1312
    1413
     
    110109ALIGN JUMP_ALIGN
    111110.ReadRetryLoop:
    112     call    Int19h_LoadFirstSectorFromDLToESBX
     111    call    .ResetBootDriveFromDL
     112    call    .LoadFirstSectorFromDLtoESBX
    113113    jnc     SHORT .Return
    114     call    Int19h_ResetDriveOrWait
    115114    dec     di                              ; Decrement retry counter
    116115    jnz     SHORT .ReadRetryLoop            ; Loop while retries left
     
    121120
    122121;--------------------------------------------------------------------
     122; .ResetBootDriveFromDL
     123;   Parameters:
     124;       DL:     Drive to boot from (translated, 00h or 80h)
     125;   Returns:
     126;       AH:     INT 13h error code
     127;       CF:     Cleared if read successfull
     128;               Set if any error
     129;   Corrupts registers:
     130;       AL
     131;--------------------------------------------------------------------
     132ALIGN JUMP_ALIGN
     133.ResetBootDriveFromDL:
     134    xor     ax, ax                          ; AH=0h, Disk Controller Reset
     135    test    dl, 80h                         ; Floppy drive?
     136    jz      SHORT .ResetDriveFromDL         ;  If so, jump to reset
     137    mov     ah, 0Dh                         ; AH=Dh, Reset Hard Disk (Alternate reset)
     138.ResetDriveFromDL:
     139    int     INTV_DISK_FUNC
     140    ret
     141
     142;--------------------------------------------------------------------
    123143; Reads first sector (boot sector) from drive DL to ES:BX.
    124144;
    125 ; Int19h_LoadFirstSectorFromDLToESBX
     145; .LoadFirstSectorFromDLtoESBX
    126146;   Parameters:
    127147;       DL:     Drive to boot from (translated, 00h or 80h)
     
    136156;--------------------------------------------------------------------
    137157ALIGN JUMP_ALIGN
    138 Int19h_LoadFirstSectorFromDLToESBX:
     158.LoadFirstSectorFromDLtoESBX:
    139159    mov     ax, 0201h                       ; Read 1 sector
    140160    mov     cx, 1                           ; Cylinder 0, Sector 1
    141161    xor     dh, dh                          ; Head 0
    142162    int     INTV_DISK_FUNC
    143     ret
    144 
    145 
    146 ;--------------------------------------------------------------------
    147 ; Reset drive controller or waits a while before retrying
    148 ; to load boot sector.
    149 ;
    150 ; Int19h_ResetDriveOrWait
    151 ;   Parameters:
    152 ;       DL:     Drive to boot from (translated, 00h or 80h)
    153 ;       DI:     Retry counter
    154 ;   Returns:
    155 ;       Nothing
    156 ;   Corrupts registers:
    157 ;       CX
    158 ;--------------------------------------------------------------------
    159 ALIGN JUMP_ALIGN
    160 Int19h_ResetDriveOrWait:
    161     test    di, 1<<0                        ; Reset on every other retry
    162     jnz     SHORT .ResetDrive
    163     mov     cx, B_READ_RETRY_DELAY          ; Wait for a while
    164     jmp     SoftDelay_TimerTicks
    165 ALIGN JUMP_ALIGN
    166 .ResetDrive:
    167     xor     cx, cx
    168     xchg    cx, ax                          ; AH=0h, Disk Controller Reset
    169     int     INTV_DISK_FUNC
    170     xchg    ax, cx                          ; Restore AX
    171163    ret
    172164
  • trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   23.3.2010
    4 ; Last update   :   28.7.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Functions for initializing the BIOS.
     
    418418ALIGN JUMP_ALIGN
    419419Initialize_ResetDetectedDrives:
    420     xor     bx, bx
    421     call    ResetFloppyDrivesWithInt40h
    422     mov     bl, 80h
    423     call    ResetForeignHardDisks
    424420    jmp     AH0h_ResetHardDisksHandledByOurBIOS
  • trunk/XTIDE_Universal_BIOS/Src/Main.asm

    r27 r28  
    3838    at  ROMVARS.bRomSize,   db  CNT_ROM_BLOCKS  ; ROM size in 512B blocks
    3939    at  ROMVARS.rgbJump,    jmp Initialize_FromMainBiosRomSearch
    40     at  ROMVARS.rgbDate,    db  "07/28/10"      ; Build data (mm/dd/yy)
     40    at  ROMVARS.rgbDate,    db  "08/01/10"      ; Build data (mm/dd/yy)
    4141    at  ROMVARS.rgbSign,    db  "XTIDE110"      ; Signature for flash program
    4242    at  ROMVARS.szTitle
     
    4949        db  " (XT)=-",STOP
    5050%endif
    51     at  ROMVARS.szVersion,  db  "v1.1.2 (07/28/10)",STOP
     51    at  ROMVARS.szVersion,  db  "v1.1.3 (08/01/10)",STOP
    5252
    5353;---------------------------;
Note: See TracChangeset for help on using the changeset viewer.