Changeset 148 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm


Ignore:
Timestamp:
Mar 19, 2011, 8:09:41 PM (13 years ago)
Author:
aitotat
google:author:
aitotat
Message:

Changes to XTIDE Universal BIOS:

  • INT 13h optimizations to save almost 100 bytes.
File:
1 edited

Legend:

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

    r90 r148  
    44; Section containing code
    55SECTION .text
    6 
    7 ;--------------------------------------------------------------------
    8 ; Macro that prints drive and function number.
    9 ; Used only for debugging.
    10 ;
    11 ; DEBUG_PRINT_DRIVE_AND_FUNCTION
    12 ;   Parameters:
    13 ;       AH:     INT 13h function number
    14 ;       DL:     Drive number
    15 ;   Returns:
    16 ;       Nothing
    17 ;   Corrupts registers:
    18 ;       Nothing
    19 ;--------------------------------------------------------------------
    20 %macro DEBUG_PRINT_DRIVE_AND_FUNCTION 0
    21     push    dx
    22     push    ax
    23     mov     al, dl
    24     call    Print_IntHexW
    25     pop     ax
    26     pop     dx
    27 %endmacro
    28 
    296
    307;--------------------------------------------------------------------
     
    329; Jumps to specific function defined in AH.
    3310;
    34 ; Int13h_Jump
     11; Note to developers: Do not make recursive INT 13h calls!
     12;
     13; Int13h_DiskFunctionsHandler
    3514;   Parameters:
    3615;       AH:     Bios function
    3716;       DL:     Drive number
     17;       Other:  Depends on function
     18;   Returns:
     19;       Depends on function
     20;--------------------------------------------------------------------
     21ALIGN JUMP_ALIGN
     22Int13h_DiskFunctionsHandler:
     23    sti                                 ; Enable interrupts
     24    SAVE_AND_GET_INTPACK_TO_SSBP
     25
     26    call    RamVars_GetSegmentToDS
     27    call    DriveXlate_ToOrBack
     28    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
     29    call    RamVars_IsFunctionHandledByThisBIOS
     30    jnc     SHORT Int13h_DirectCallToAnotherBios
     31    call    FindDPT_ForDriveNumber      ; DS:DI now points to DPT
     32
     33    ; Jump to correct BIOS function
     34JumpToBiosFunctionInAH:
     35    cmp     ah, 25h                     ; Valid BIOS function?
     36    ja      SHORT Int13h_UnsupportedFunction
     37    eMOVZX  bx, ah
     38    shl     bx, 1
     39    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
     40
     41
     42;--------------------------------------------------------------------
     43; Int13h_UnsupportedFunction
     44; Int13h_DirectCallToAnotherBios
     45;   Parameters:
     46;       DL:     Translated drive number
     47;       DS:     RAMVARS segment
     48;       SS:BP:  Ptr to INTPACK
     49;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
     50;       Other:  Function specific INT 13h parameters
    3851;   Returns:
    3952;       Depends on function
     
    4255;--------------------------------------------------------------------
    4356ALIGN JUMP_ALIGN
    44 Int13h_DiskFunctions:
    45     ; Save registers
    46     sti                                 ; Enable interrupts
    47     push    ds                          ; Store DS
    48     push    di                          ; Store DI
    49 
    50     ;DEBUG_PRINT_DRIVE_AND_FUNCTION
     57Int13h_UnsupportedFunction:
     58Int13h_DirectCallToAnotherBios:
     59    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
     60    mov     bx, [bp+INTPACK.bx]
     61    mov     di, [bp+INTPACK.di]
     62    mov     ds, [bp+INTPACK.ds]
     63    push    WORD [bp+INTPACK.flags]
     64    popf
     65    push    bp
     66    mov     bp, [bp+INTPACK.bp]
     67    int     BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
     68
     69    ; Store returned values to INTPACK
     70    pop     bp  ; Standard INT 13h functions never uses BP as return register
     71%ifdef USE_386
     72    mov     [bp+INTPACK.gs], gs
     73    mov     [bp+INTPACK.fs], fs
     74%endif
     75    mov     [bp+INTPACK.es], es
     76    mov     [bp+INTPACK.ds], ds
     77    mov     [bp+INTPACK.di], di
     78    mov     [bp+INTPACK.si], si
     79    mov     [bp+INTPACK.bx], bx
     80    mov     [bp+INTPACK.dh], dh
     81    mov     [bp+INTPACK.cx], cx
     82    mov     [bp+INTPACK.ax], ax
     83    pushf
     84    pop     WORD [bp+INTPACK.flags]
    5185    call    RamVars_GetSegmentToDS
    52     call    DriveXlate_WhenEnteringInt13h
    53     call    RamVars_IsFunctionHandledByThisBIOS
    54     jnc     SHORT Int13h_DirectCallToAnotherBios
    55     ;DEBUG_PRINT_DRIVE_AND_FUNCTION
    56 
    57     ; Jump to correct BIOS function
    58     cmp     ah, 25h                     ; Valid BIOS function?
    59     ja      SHORT Int13h_UnsupportedFunction
    60     mov     di, ax
    61 %ifndef USE_186 ; This uses 9 bytes less and is about 5 cycles faster
    62     mov     al, ah                      ; Copy bits in AH to AL and then
    63     shl     al, 1                       ; shift them "back" 1 step
    64     and     al, 7Eh                     ; AND them (clears the MSB)
    65     cbw                                 ; Clear AH using sign extension
    66     xchg    di, ax                      ; and finally swap DI with AX
    67 %else
    68     eSHR_IM di, 7                       ; Shift function to DI...
    69     and     di, BYTE 7Eh                ; ...and prepare for word lookup
    70 %endif
    71     jmp     [cs:di+g_rgw13hFuncJump]    ; Jump to BIOS function
    72 
    73 
    74 ;--------------------------------------------------------------------
    75 ; Directs call to another INT13h function whose pointer is
    76 ; stored to RAMVARS.
    77 ;
    78 ; Int13h_DirectCallToAnotherBios
    79 ;   Parameters:
    80 ;       AH:     Bios function
     86    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
     87    je      SHORT .ExchangeInt13hHandlers
     88    mov     [bp+INTPACK.dl], dl     ; Something is returned in DL
     89ALIGN JUMP_ALIGN
     90.ExchangeInt13hHandlers:
     91    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
     92    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
     93
     94
     95;--------------------------------------------------------------------
     96; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
     97; Int13h_ReturnFromHandlerWithoutStoringErrorCode
     98;   Parameters:
     99;       AH:     BIOS Error code
     100;       SS:BP:  Ptr to INTPACK
     101;   Returns:
     102;       All registers are loaded from INTPACK
     103;--------------------------------------------------------------------
     104ALIGN JUMP_ALIGN
     105Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
     106    call    HError_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
     107Int13h_ReturnFromHandlerWithoutStoringErrorCode:
     108    or      WORD [bp+INTPACK.flags], FLG_FLAGS_IF   ; Return with interrupts enabled
     109    mov     sp, bp                                  ; Now we can exit anytime
     110    RESTORE_INTPACK_FROM_SSBP
     111
     112
     113;--------------------------------------------------------------------
     114; Int13h_CallPreviousInt13hHandler
     115;   Parameters:
     116;       AH:     INT 13h function to call
    81117;       DL:     Drive number
    82118;       DS:     RAMVARS segment
    83 ;       DI:     Corrupted
    84 ;       Stack from top to down:
    85 ;               Original DI
    86 ;               Original DS
    87119;   Returns:
    88120;       Depends on function
    89121;   Corrupts registers:
    90 ;       Flags
    91 ;--------------------------------------------------------------------
    92 ALIGN JUMP_ALIGN
    93 Int13h_UnsupportedFunction:
    94 Int13h_DirectCallToAnotherBios:
    95     ; Temporarily store original DI and DS from stack to RAMVARS
    96     pop     WORD [RAMVARS.wI13hDI]
    97     pop     WORD [RAMVARS.wI13hDS]
    98 
    99     ; Special return processing required if target function
    100     ; returns something in DL
    101     mov     di, Int13h_ReturnFromAnotherBiosWithValueInDL
    102     call    DriveXlate_DoesFunctionReturnSomethingInDL
    103     jc      SHORT .PushIretAddress
    104     add     di, BYTE Int13h_ReturnFromAnotherBios - Int13h_ReturnFromAnotherBiosWithValueInDL
    105 .PushIretAddress:
    106     pushf                               ; Push FLAGS to simulate INT
    107     push    cs                          ; Push return segment
    108     push    di                          ; Push return offset
    109 
    110     ; "Return" to another INT 13h with original DI and DS
    111     push    WORD [RAMVARS.fpOldI13h+2]  ; Segment
    112     push    WORD [RAMVARS.fpOldI13h]    ; Offset
    113     lds     di, [RAMVARS.dwI13DIDS]
    114     cli                                 ; Disable interrupts as INT would
    115     retf
    116 
    117 
    118 ;--------------------------------------------------------------------
    119 ; Int13h_CallPreviousInt13hHandler
    120 ;   Parameters:
    121 ;       AH:     Bios function
     122;       BX, DI, ES
     123;--------------------------------------------------------------------
     124ALIGN JUMP_ALIGN
     125Int13h_CallPreviousInt13hHandler:
     126    push    di
     127    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
     128    int     BIOS_DISK_INTERRUPT_13h
     129    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
     130    pop     di
     131    ret
     132
     133
     134;--------------------------------------------------------------------
     135; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
     136;   Parameters:
    122137;       DS:     RAMVARS segment
    123 ;       Other:  Depends on function to call
    124 ;   Returns:
    125 ;       Depends on function to call
     138;   Returns:
     139;       Nothing
    126140;   Corrupts registers:
    127 ;       Nothing
    128 ;--------------------------------------------------------------------
    129 ALIGN JUMP_ALIGN
    130 Int13h_CallPreviousInt13hHandler:
    131     pushf                               ; Push flags to simulate INT
    132     cli                                 ; Disable interrupts since INT does that
    133     call    FAR [RAMVARS.fpOldI13h]
    134     sti
     141;       DI
     142;--------------------------------------------------------------------
     143ALIGN JUMP_ALIGN
     144ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
     145    push    es
     146    LOAD_BDA_SEGMENT_TO es, di
     147    mov     di, [RAMVARS.fpOldI13h]
     148    xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4]
     149    mov     [RAMVARS.fpOldI13h], di
     150    mov     di, [RAMVARS.fpOldI13h+2]
     151    xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4+2]
     152    mov     [RAMVARS.fpOldI13h+2], di
     153    pop     es
    135154    ret
    136155
    137 
    138 ;--------------------------------------------------------------------
    139 ; Int13h_ReturnFromAnotherBiosWithValueInDL
    140 ; Int13h_ReturnFromAnotherBios
    141 ;   Parameters:
    142 ;       AH:     Error code
    143 ;       DL:     Drive number (only on Int13h_ReturnFromAnotherBios)
    144 ;       CF:     Error status
    145 ;   Returns:
    146 ;       Depends on function
    147 ;   Corrupts registers:
    148 ;       Nothing (not even FLAGS)
    149 ;--------------------------------------------------------------------
    150 ALIGN JUMP_ALIGN
    151 Int13h_ReturnFromAnotherBiosWithValueInDL:
    152     push    ds
    153     push    di
    154     pushf                               ; Store return flags
    155     call    RamVars_GetSegmentToDS
    156     call    DriveXlate_WhenLeavingInt13hWithReturnValueInDL
    157     jmp     SHORT Int13h_Leave
    158 
    159 ALIGN JUMP_ALIGN
    160 Int13h_ReturnFromAnotherBios:
    161     push    ds
    162     push    di
    163     pushf                               ; Store return flags
    164     call    RamVars_GetSegmentToDS
    165     call    DriveXlate_WhenLeavingInt13h
    166     jmp     SHORT Int13h_Leave
    167 
    168 
    169 ;--------------------------------------------------------------------
    170 ; Returns from any BIOS function implemented by this BIOS.
    171 ;
    172 ; Int13h_ReturnWithValueInDL
    173 ; Int13h_PopXRegsAndReturn
    174 ; Int13h_PopDiDsAndReturn
    175 ;   Parameters:
    176 ;       DL:     Drive number (not Int13h_ReturnWithoutSwappingDrives)
    177 ;       DS:     RAMVARS segment
    178 ;   Returns:
    179 ;       Depends on function
    180 ;   Corrupts registers:
    181 ;       Nothing (not even FLAGS)
    182 ;--------------------------------------------------------------------
    183 ALIGN JUMP_ALIGN
    184 Int13h_ReturnWithValueInDL:
    185     pushf
    186     call    DriveXlate_WhenLeavingInt13hWithReturnValueInDL
    187     jmp     SHORT Int13h_LeaveAfterStoringErrorCodeToBDA
    188 
    189 ALIGN JUMP_ALIGN
    190 Int13h_PopXRegsAndReturn:
    191     pop     bx                          ; Pop old AX to BX
    192     mov     al, bl                      ; Restore AL
    193     pop     bx
    194     pop     cx
    195     pop     dx
    196     ; Fall to Int13h_PopDiDsAndReturn
    197 
    198 ALIGN JUMP_ALIGN
    199 Int13h_PopDiDsAndReturn:
    200     pushf
    201     call    DriveXlate_WhenLeavingInt13h
    202     ; Fall to Int13h_LeaveAfterStoringErrorCodeToBDA
    203 
    204 Int13h_LeaveAfterStoringErrorCodeToBDA:
    205     LOAD_BDA_SEGMENT_TO ds, di
    206     mov     [BDA.bHDStatus], ah
    207     ; Fall to Int13h_Leave
    208 
    209 Int13h_Leave:
    210     popf
    211     pop     di
    212     pop     ds
    213     retf    2
    214156
    215157
Note: See TracChangeset for help on using the changeset viewer.