Changeset 262 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs


Ignore:
Timestamp:
Feb 24, 2012, 10:28:31 AM (12 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

More optimizations. Merged RamVars_IsFunction/DriveHandledByThisBIOS in with FindDPT_ForDriveNumber, since they are often used together, making a returned NULL DI pointer indicate a foreign drive in many places. Revamped the iteration done in the handlers for int13/0dh and int13h/0h. Added serial specific print string during drive detection.

Location:
trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm

    r258 r262  
    200200    call    Device_FinalizeDPT
    201201
     202;----------------------------------------------------------------------
     203; Update drive counts (hard and floppy)
     204;----------------------------------------------------------------------
     205       
    202206%ifdef MODULE_SERIAL_FLOPPY
    203207;
     
    223227%endif
    224228
    225     ; Fall to .StoreDriveNumberAndUpdateDriveCount
    226 
    227 ;--------------------------------------------------------------------
    228 ; .StoreDriveNumberAndUpdateDriveCount
    229 ;   Parameters:
    230 ;       DS:DI:  Ptr to Disk Parameter Table
    231 ;       ES:SI:  Ptr to 512-byte ATA information read from the drive
    232 ;       CS:BP:  Ptr to IDEVARS for the controller
    233 ;       ES:     BDA Segment
    234 ;   Returns:
    235 ;       DL:     Drive number for new drive
    236 ;       CF:     Always cleared
    237 ;   Corrupts registers:
    238 ;       Nothing
    239 ;--------------------------------------------------------------------
    240 .StoreDriveNumberAndUpdateDriveCount:
    241     mov     dl, [es:BDA.bHDCount]
    242     or      dl, 80h                     ; Set bit 7 since hard disk
    243 
    244229    inc     BYTE [RAMVARS.bDrvCnt]      ; Increment drive count to RAMVARS
    245     inc     BYTE [es:BDA.bHDCount]      ; Increment drive count to BDA
    246 
    247     cmp     BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
    248     ja      SHORT .AllDone              ;  If so, return
    249     mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
    250 
    251 .AllDone:
     230       
     231.AllDone:               
    252232    clc
    253233    ret
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm

    r259 r262  
    66
    77;--------------------------------------------------------------------
    8 ; Finds pointer to first unused Disk Parameter Table.
    9 ;
    10 ; FindDPT_ForNewDriveToDSDI
    11 ;   Parameters:
    12 ;       DS:     RAMVARS segment
    13 ;   Returns:
    14 ;       DS:DI:  Ptr to first unused DPT
    15 ;   Corrupts registers:
    16 ;       DX
    17 ;--------------------------------------------------------------------
    18 ALIGN JUMP_ALIGN
    19 FindDPT_ForNewDriveToDSDI:
    20     mov     ax, [RAMVARS.wDrvCntAndFirst]
    21     add     al, ah
     8; Checks if drive is handled by this BIOS, and return DPT pointer.
     9;
     10; FindDPT_ForDriveNumberInDL       
     11;   Parameters:
     12;       DL:     Drive number
     13;       DS:     RAMVARS segment
     14;   Returns:
     15;       CF:     Cleared if drive is handled by this BIOS
     16;               Set if drive belongs to some other BIOS
     17;       DI:     DPT Pointer if drive is handled by this BIOS
     18;               Zero if drive belongs to some other BIOS
     19;   Corrupts registers:
     20;       Nothing
     21;--------------------------------------------------------------------
     22ALIGN JUMP_ALIGN
     23FindDPT_ForDriveNumberInDL:     
     24    xchg    di, ax                              ; Save the contents of AX in DI
     25
     26;
     27; Check Our Hard Disks
     28;
     29    mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AH, First number to AL
     30    add     ah, al                              ; One past last drive to AH
     31
    2232%ifdef MODULE_SERIAL_FLOPPY
    23     add     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
     33    cmp     dl, ah                              ; Above last supported?
     34    jae     SHORT .HardDiskNotHandledByThisBIOS
     35       
     36    cmp     dl, al                              ; Below first supported?
     37    jae     SHORT .CalcDPTForDriveNumber
     38
     39ALIGN JUMP_ALIGN               
     40.HardDiskNotHandledByThisBIOS: 
     41;
     42; Check Our Floppy Disks
     43;
     44    call    RamVars_UnpackFlopCntAndFirstToAL
     45    cbw                                         ; normally 0h, could be ffh if no drives present
     46    adc     ah, al                              ; if no drives present, still ffh (ffh + ffh + 1 = ffh)
     47    js      SHORT .DiskIsNotHandledByThisBIOS
     48    cmp     ah, dl                              ; Check second drive if two, first drive if only one
     49    jz      SHORT .CalcDPTForDriveNumber
     50    cmp     al, dl                              ; Check first drive in all cases, redundant but OK to repeat
     51    jnz     SHORT .DiskIsNotHandledByThisBIOS           
     52%else
     53    cmp     dl, ah                              ; Above last supported?     
     54    jae     SHORT .DiskIsNotHandledByThisBIOS
     55       
     56    cmp     dl, al                              ; Below first supported?
     57    jb      SHORT .DiskIsNotHandledByThisBIOS           
    2458%endif
    25     xchg    ax, dx
    26     ; fall-through to FindDPT_ForDriveNumber
     59    ; fall-through to CalcDPTForDriveNumber
    2760
    2861;--------------------------------------------------------------------
    2962; Finds Disk Parameter Table for drive number.
    30 ; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
    31 ;
    32 ; FindDPT_ForDriveNumber
     63; Note intended to be called except by FindDPT_ForDriveNumber
     64;
     65; CalcDPTForDriveNumber
    3366;   Parameters:
    3467;       DL:     Drive number
    3568;       DS:     RAMVARS segment
     69;       DI:     Saved copy of AX from entry at FindDPT_ForDriveNumber
    3670;   Returns:
    3771;       DS:DI:  Ptr to DPT
     72;       CF:     Clear
    3873;   Corrupts registers:
    3974;       Nothing
    4075;--------------------------------------------------------------------
    4176ALIGN JUMP_ALIGN
    42 FindDPT_ForDriveNumber:
     77.CalcDPTForDriveNumber:
    4378    push    dx
    44     xchg    di, ax  ; Save the contents of AX in DI
    4579
    4680%ifdef MODULE_SERIAL_FLOPPY
     
    5286    call    RamVars_UnpackFlopCntAndFirstToAL
    5387    add     dl, ah                      ; add in end of hard disk DPT list, floppies start immediately after
     88       
     89ALIGN JUMP_ALIGN               
    5490.harddisk:
    5591    sub     dl, al                      ; subtract off beginning of either hard disk or floppy list (as appropriate)
     
    5793    sub     dl, [RAMVARS.bFirstDrv]     ; subtract off beginning of hard disk list
    5894%endif
    59        
     95
     96.CalcDPTForNewDrive:               
    6097    mov     al, LARGEST_DPT_SIZE
    6198       
    6299    mul     dl
    63     add     ax, BYTE RAMVARS_size
    64 
    65     xchg    di, ax                      ; Restore AX and put result in DI
     100    add     ax, BYTE RAMVARS_size       ; Clears CF (will not oveflow)
     101
    66102    pop     dx
    67        
    68     ret
    69 
    70 ;--------------------------------------------------------------------
    71 ; Consolidator for checking the result from RamVars_IsDriveHandledByThisBIOS
    72 ; and then if it is our drive, getting the DPT with FindDPT_ForDriveNumber
    73 ;
    74 ; RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
    75 ;   Parameters:
    76 ;       DL:     Drive number
    77 ;       DS:     RAMVARS segment
    78 ;   Returns:
    79 ;       DS:DI:  Ptr to DPT, if it is our drive
    80 ;       CF:     Set if not our drive, clear if it is our drive
    81 ;   Corrupts registers:
    82 ;       Nothing
    83 ;--------------------------------------------------------------------
    84 ALIGN JUMP_ALIGN
    85 RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber:
    86     call    RamVars_IsDriveHandledByThisBIOS
    87     jnc     FindDPT_ForDriveNumber
    88     ret
    89 
    90 
    91 ;--------------------------------------------------------------------
    92 ; Finds Disk Parameter Table for
    93 ; Master or Slave drive at wanted port.
    94 ;
    95 ; FindDPT_ToDSDIForIdeMasterAtPortDX
    96 ; FindDPT_ToDSDIForIdeSlaveAtPortDX
    97 ;   Parameters:
    98 ;       DX:     IDE Base Port address
    99 ;       DS:     RAMVARS segment
    100 ;   Returns:
    101 ;       DL:     Drive number (if DPT found)
    102 ;       DS:DI:  Ptr to DPT
    103 ;       CF:     Set if wanted DPT found
    104 ;               Cleared if DPT not found
    105 ;   Corrupts registers:
    106 ;       SI
    107 ;
    108 ; Converted to macros since there is only once call site for each of these
    109 ;
    110 ;--------------------------------------------------------------------
    111    
    112 %macro FindDPT_ToDSDIForIdeMasterAtPortDX 0
    113     mov     si, IterateToMasterAtPortCallback
    114     call    IterateAllDPTs
    115 %endmacro
    116 
    117 %macro FindDPT_ToDSDIForIdeSlaveAtPortDX 0
    118     mov     si, IterateToSlaveAtPortCallback
    119     call    IterateAllDPTs
    120 %endmacro
    121 
    122        
    123 ;--------------------------------------------------------------------
    124 ; Iteration callback for finding DPT using
    125 ; IDE base port for Master or Slave drive.
    126 ;
    127 ; IterateToSlaveAtPortCallback
    128 ; IterateToMasterAtPortCallback
    129 ;   Parameters:
    130 ;       DX:     IDE Base Port address
    131 ;       DS:DI:  Ptr to DPT to examine
    132 ;   Returns:
    133 ;       CF:     Set if wanted DPT found
    134 ;               Cleared if wrong DPT
    135 ;   Corrupts registers:
    136 ;       Nothing
    137 ;--------------------------------------------------------------------
    138 ALIGN JUMP_ALIGN
    139 IterateToSlaveAtPortCallback:
    140     test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
    141     jnz     SHORT CompareBasePortAddress
    142     ret     ; Wrong DPT
    143 
    144 ALIGN JUMP_ALIGN
    145 IterateToMasterAtPortCallback:
    146     test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
    147     jnz     SHORT ReturnWrongDPT                ; Return if slave drive
    148 
    149 CompareBasePortAddress:
    150     push    bx
    151     eMOVZX  bx, BYTE [di+DPT.bIdevarsOffset]    ; CS:BX now points to IDEVARS
    152     cmp     dx, [cs:bx+IDEVARS.wPort]           ; Wanted port?
    153     pop     bx
    154     jne     SHORT ReturnWrongDPT
    155 
    156 ReturnRightDPT:
    157     stc                                         ; Set CF since wanted DPT
    158     ret
    159 
     103
     104    xchg    di, ax                      ; Restore AX from entry at FindDPT_ForDriveNumber, put DPT pointer in DI
     105    ret
     106
     107ALIGN JUMP_ALIGN       
     108.DiskIsNotHandledByThisBIOS:           
     109;
     110; Drive not found...
     111;
     112    xor     ax, ax                              ; Clear DPT pointer
     113    stc                                         ; Is not supported by our BIOS     
     114       
     115    xchg    di, ax                              ; Restore AX from save at top
     116    ret
     117
     118;--------------------------------------------------------------------
     119; Finds pointer to first unused Disk Parameter Table.
     120; Should only be used before DetectDrives is complete (not valid after this time).
     121;
     122; FindDPT_ForNewDriveToDSDI
     123;   Parameters:
     124;       DS:     RAMVARS segment
     125;   Returns:
     126;       DS:DI:  Ptr to first unused DPT
     127;   Corrupts registers:
     128;       AX
     129;--------------------------------------------------------------------
     130ALIGN JUMP_ALIGN
     131FindDPT_ForNewDriveToDSDI:
     132    push    dx
     133       
     134%ifdef MODULE_SERIAL_FLOPPY
     135    mov     dx, [RAMVARS.wDrvCntAndFlopCnt]
     136    add     dl, dh
     137%else
     138    mov     dl, [RAMVARS.bDrvCnt]
     139%endif
     140       
     141    jmp     short FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
    160142
    161143;--------------------------------------------------------------------
     
    165147;       BL:     Bit(s) to test in DPT.bFlagsHigh
    166148;   Returns:
    167 ;       CF:     Set if wanted DPT found
    168 ;               Cleared if wrong DPT
     149;       CF:     Clear if wanted DPT found
     150;               Set if wrong DPT
    169151;   Corrupts registers:
    170152;       Nothing
     
    172154ALIGN JUMP_ALIGN
    173155IterateToDptWithFlagsHighInBL:     
    174     test    BYTE [di+DPT.bFlagsHigh], bl        ; Clears CF (but we need the clc
    175                                                 ; below anyway for callers above)
    176     jnz     SHORT ReturnRightDPT
    177 
    178 ReturnWrongDPT:
    179     clc                                     ; Clear CF since wrong DPT
     156    test    BYTE [di+DPT.bFlagsHigh], bl        ; Clears CF
     157    jnz     SHORT .ReturnRightDPT
     158    stc
     159.ReturnRightDPT:       
    180160    ret
    181161
     
    220200;       AX,BX,DX:   Parameters to callback function
    221201;       CS:SI:      Ptr to callback function
     202;                   Callback routine should return CF=clear if found
    222203;       DS:         RAMVARS segment
    223204;   Returns:
    224205;       DS:DI:      Ptr to wanted DPT (if found)
    225206;                   If not found, points to first empty DPT
    226 ;       CF:         Set if wanted DPT found
    227 ;                   Cleared if DPT not found, or no DPTs present
     207;       CF:         Clear if wanted DPT found
     208;                   Set if DPT not found, or no DPTs present
    228209;   Corrupts registers:
    229210;       Nothing unless corrupted by callback function
     
    238219    xor     ch, ch                      ; Clears CF 
    239220       
    240     jcxz    .AllDptsIterated            ; Return if no drives, CF will be clear from xor above
     221    jcxz    .NotFound                   ; Return if no drives
    241222       
    242223ALIGN JUMP_ALIGN
    243224.LoopWhileDPTsLeft:
    244225    call    si                          ; Is wanted DPT?
    245     jc      SHORT .AllDptsIterated      ;  If so, return
    246     add     di, BYTE LARGEST_DPT_SIZE   ; Point to next DPT, clears CF
     226    jnc     SHORT .Found                ;  If so, return
     227    add     di, BYTE LARGEST_DPT_SIZE   ; Point to next DPT
    247228    loop    .LoopWhileDPTsLeft
    248    
    249     ; fall-through: DPT was not found, CF is already clear from ADD di inside the loop
    250        
    251 ALIGN JUMP_ALIGN
    252 .AllDptsIterated:
     229
     230ALIGN JUMP_ALIGN
     231.NotFound:
     232    stc
     233
     234ALIGN JUMP_ALIGN
     235.Found:
    253236    pop     cx
    254237    ret
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm

    r258 r262  
    115115
    116116;--------------------------------------------------------------------
    117 ; Checks if INT 13h function is handled by this BIOS.
    118 ;
    119 ; RamVars_IsFunctionHandledByThisBIOS
    120 ;   Parameters:
    121 ;       AH:     INT 13h function number
    122 ;       DL:     Drive number
    123 ;       DS:     RAMVARS segment
    124 ;   Returns:
    125 ;       CF:     Cleared if function is handled by this BIOS
    126 ;               Set if function belongs to some other BIOS
    127 ;   Corrupts registers:
    128 ;       Nothing
    129 ;--------------------------------------------------------------------
    130 ALIGN JUMP_ALIGN
    131 RamVars_IsFunctionHandledByThisBIOS:
    132     test    ah, ah          ; Reset for all floppy and hard disk drives?
    133     jz      SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
    134     cmp     ah, 08h
    135 %ifdef MODULE_SERIAL_FLOPPY
    136 ; we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts
    137     je      SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
    138 %else
    139 ; we handle all *hard disk* traffic for function 08h, as we need to wrap the hard disk drive count
    140     je      SHORT RamVars_IsDriveHandledByThisBIOS.IsDriveAHardDisk
    141 %endif
    142 ;;; fall-through           
    143        
    144 ;--------------------------------------------------------------------
    145 ; Checks if drive is handled by this BIOS.
    146 ;
    147 ; RamVars_IsDriveHandledByThisBIOS
    148 ;   Parameters:
    149 ;       DL:     Drive number
    150 ;       DS:     RAMVARS segment
    151 ;   Returns:
    152 ;       CF:     Cleared if drive is handled by this BIOS
    153 ;               Set if drive belongs to some other BIOS
    154 ;   Corrupts registers:
    155 ;       Nothing
    156 ;--------------------------------------------------------------------
    157 ALIGN JUMP_ALIGN
    158 RamVars_IsDriveHandledByThisBIOS:
    159     push    ax
    160 
    161     mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AH, First number to AL
    162     add     ah, al                              ; One past last drive to AH
    163     cmp     dl, ah                              ; Above last supported?
    164     jae     SHORT .HardDiskIsNotHandledByThisBIOS
    165 .TestLowLimit:
    166     cmp     dl, al                              ; Below first supported?
    167     jae     SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX  ; note that CF is clear if the branch is taken
    168 
    169 .HardDiskIsNotHandledByThisBIOS:
    170 %ifdef MODULE_SERIAL_FLOPPY
    171     call    RamVars_UnpackFlopCntAndFirstToAL
    172     cbw                                         ; normally 0h, could be ffh if no drives present
    173     adc     ah, al                              ; if no drives present, still ffh (ffh + ffh + 1 = ffh)
    174     js      SHORT .DiskIsNotHandledByThisBIOS
    175     cmp     ah, dl
    176     jz      SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
    177     cmp     al, dl
    178     jz      SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
    179 .DiskIsNotHandledByThisBIOS:           
    180 %endif
    181 
    182     stc                                         ; Is not supported by our BIOS
    183        
    184 .CFAlreadyClear_IsHandledByOurBIOS_PopAX:               
    185     pop     ax
    186 .CFAlreadyClear_IsHandledByOurBIOS:
    187     ret
    188 
    189 %ifndef MODULE_SERIAL_FLOPPY       
    190 ;
    191 ; Note that we could have just checked for the high order bit in dl, but with the needed STC and jumps,
    192 ; leveraging the code above resulted in space savings.
    193 ;
    194 .IsDriveAHardDisk:     
    195     push    ax                                  ; match stack at the top of routine
    196     mov     al, 80h                             ; to catch all hard disks, lower limit is 80h vs. bFirstDrv
    197     jmp     .TestLowLimit                       ; and there is no need to test a high limit
    198 %endif
    199 
    200 ;--------------------------------------------------------------------
    201117; RamVars_GetHardDiskCountFromBDAtoAX
    202118;   Parameters:
Note: See TracChangeset for help on using the changeset viewer.