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


Ignore:
Timestamp:
Feb 22, 2012, 7:01:53 PM (13 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

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

Legend:

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

    r227 r258  
    6363.StoreFlags:
    6464    mov     [di+DPT.wFlags], ax
    65 
    66 %ifdef MODULE_SERIAL
    67     cmp     byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
    68     jnz     .StoreAddressing
    69     or      byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
    70 %endif
    7165    ; Fall to .StoreAddressing
    7266
     
    205199.StoreDeviceSpecificParameters:
    206200    call    Device_FinalizeDPT
     201
     202%ifdef MODULE_SERIAL_FLOPPY
     203;
     204; These two instructions serve two purposes:
     205; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
     206; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
     207;    effectively discarded.  This is more of a safety check then code that should ever normally be hit (see below).
     208;    Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
     209;    this was necessary.  Now, this situation shouldn't happen in normal operation, for a couple of reasons:
     210;       A. xtidecfg always puts configured serial ports at the end fo the IDEVARS list
     211;       B. the auto serial code is always executed last
     212;       C. the serial server always returns floppy drives last
     213;
     214    adc     byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
     215    jnz     .AllDone   
     216%else
     217;
     218; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
     219; could lead to unpredictable results since no MBR will be present, etc.  The server doesn't know that
     220; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
     221;
     222    jc      .AllDone
     223%endif
     224
    207225    ; Fall to .StoreDriveNumberAndUpdateDriveCount
    208226
     
    230248    ja      SHORT .AllDone              ;  If so, return
    231249    mov     [RAMVARS.bFirstDrv], dl     ; Store first drive number
     250
     251.AllDone:
    232252    clc
    233 .AllDone:
    234253    ret
     254
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm

    r233 r258  
    1414;       DS:DI:  Ptr to first unused DPT
    1515;   Corrupts registers:
    16 ;       DL
     16;       DX
    1717;--------------------------------------------------------------------
    1818ALIGN JUMP_ALIGN
    1919FindDPT_ForNewDriveToDSDI:
    20     mov     dl, [RAMVARS.bFirstDrv]
    21     add     dl, [RAMVARS.bDrvCnt]
     20    mov     ax, [RAMVARS.wDrvCntAndFirst]
     21    add     al, ah
     22%ifdef MODULE_SERIAL_FLOPPY
     23    add     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
     24%endif
     25    xchg    ax, dx     
    2226    ; Fall to FindDPT_ForDriveNumber
    2327
     
    4145    xchg    di, ax  ; Save the contents of AX in DI
    4246
     47%ifdef MODULE_SERIAL_FLOPPY
     48    mov     ax, [RAMVARS.wDrvCntAndFirst]
     49       
     50    test    dl, dl
     51    js      .harddisk
     52
     53    call    RamVars_UnpackFlopCntAndFirstToAL
     54    add     dl, ah                      ; add in end of hard disk DPT list, floppies start immediately after
     55.harddisk:
     56    sub     dl, al                      ; subtract off beginning of either hard disk or floppy list (as appropriate)
     57%else
     58    sub     dl, [RAMVARS.bFirstDrv]     ; subtract off beginning of hard disk list
     59%endif
     60       
    4361    mov     al, LARGEST_DPT_SIZE
    44     sub     dl, [RAMVARS.bFirstDrv]
     62       
    4563    mul     dl
    4664    add     ax, BYTE RAMVARS_size
    4765
    48     xchg    di, ax  ; Restore AX and put result in DI
     66    xchg    di, ax                      ; Restore AX and put result in DI
    4967    pop     dx
    5068    ret
     
    89107; IterateToMasterAtPortCallback
    90108;   Parameters:
    91 ;       CH:     Drive number
    92109;       DX:     IDE Base Port address
    93110;       DS:DI:  Ptr to DPT to examine
    94111;   Returns:
    95 ;       DL:     Drive number if correct DPT
    96112;       CF:     Set if wanted DPT found
    97113;               Cleared if wrong DPT
     
    116132    pop     bx
    117133    jne     SHORT ReturnWrongDPT
    118     mov     dl, ch                              ; Return drive number in DL
    119134
    120135ReturnRightDPT:
     
    187202;   Returns:
    188203;       DS:DI:      Ptr to wanted DPT (if found)
     204;                   If not found, points to first empty DPT
    189205;       CF:         Set if wanted DPT found
    190206;                   Cleared if DPT not found, or no DPTs present
     
    195211IterateAllDPTs:
    196212    push    cx
    197     mov     cx, [RAMVARS.wDrvCntAndFirst]
     213
     214    mov     cl, [RAMVARS.bDrvCnt]       
     215    mov     ch, 0
     216       
     217    mov     di, RAMVARS_size            ; Point DS:DI to first DPT
     218       
    198219    jcxz    .NotFound                   ; Return if no drives
    199     mov     di, RAMVARS_size            ; Point DS:DI to first DPT
     220       
    200221ALIGN JUMP_ALIGN
    201222.LoopWhileDPTsLeft:
    202223    call    si                          ; Is wanted DPT?
    203224    jc      SHORT .AllDptsIterated      ;  If so, return
    204     inc     ch                          ; Increment drive number
    205225    add     di, BYTE LARGEST_DPT_SIZE   ; Point to next DPT
    206     dec     cl                          ; Decrement drives left
    207     jnz     SHORT .LoopWhileDPTsLeft
     226    loop    .LoopWhileDPTsLeft
     227       
    208228.NotFound:     
    209229    clc                                 ; Clear CF since DPT not found
     230       
    210231ALIGN JUMP_ALIGN
    211232.AllDptsIterated:
  • trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm

    r241 r258  
    123123;       DS:     RAMVARS segment
    124124;   Returns:
    125 ;       CF:     Set if function is handled by this BIOS
    126 ;               Cleared if function belongs to some other BIOS
     125;       CF:     Cleared if function is handled by this BIOS
     126;               Set if function belongs to some other BIOS
    127127;   Corrupts registers:
    128128;       Nothing
     
    131131RamVars_IsFunctionHandledByThisBIOS:
    132132    test    ah, ah          ; Reset for all floppy and hard disk drives?
    133     jz      SHORT .FunctionIsHandledByOurBIOS
    134     cmp     ah, 08h         ; Read Disk Drive Parameters?
    135     jne     SHORT RamVars_IsDriveHandledByThisBIOS
    136     test    dl, dl          ; We do not handle floppy drives
    137     jns     SHORT .FunctionIsNotHandledByOurBIOS
    138 ALIGN JUMP_ALIGN
    139 .FunctionIsHandledByOurBIOS:
    140     stc
    141 .FunctionIsNotHandledByOurBIOS:
    142     ret
    143 
     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       
    144144;--------------------------------------------------------------------
    145145; Checks if drive is handled by this BIOS.
     
    150150;       DS:     RAMVARS segment
    151151;   Returns:
    152 ;       CF:     Set if drive is handled by this BIOS
    153 ;               Cleared if drive belongs to some other BIOS
     152;       CF:     Cleared if drive is handled by this BIOS
     153;               Set if drive belongs to some other BIOS
    154154;   Corrupts registers:
    155155;       Nothing
     
    158158RamVars_IsDriveHandledByThisBIOS:
    159159    push    ax
    160     mov     ax, [RAMVARS.wDrvCntAndFirst]       ; Drive count to AL, First number to AH
    161     add     al, ah                              ; One past last drive to AL
    162     cmp     dl, al                              ; Above last supported?
    163     jae     SHORT .DriveNotHandledByThisBIOS
    164     cmp     ah, dl                              ; Below first supported?
    165     ja      SHORT .DriveNotHandledByThisBIOS
    166     stc
    167 .DriveNotHandledByThisBIOS:
     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:               
    168185    pop     ax
    169     ret
    170 
    171 
    172 ;--------------------------------------------------------------------
    173 ; RamVars_GetHardDiskCountFromBDAtoCX
    174 ;   Parameters:
    175 ;       DS:     RAMVARS segment
    176 ;   Returns:
    177 ;       CX:     Total hard disk count
    178 ;   Corrupts registers:
    179 ;       Nothing
    180 ;--------------------------------------------------------------------
    181 ALIGN JUMP_ALIGN
    182 RamVars_GetHardDiskCountFromBDAtoCX:
     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;--------------------------------------------------------------------
     201; RamVars_GetHardDiskCountFromBDAtoAX
     202;   Parameters:
     203;       DS:     RAMVARS segment
     204;   Returns:
     205;       AX:     Total hard disk count
     206;   Corrupts registers:
     207;       CX
     208;--------------------------------------------------------------------
     209ALIGN JUMP_ALIGN
     210RamVars_GetHardDiskCountFromBDAtoAX:
    183211    push    es
    184     push    dx
    185 
    186     LOAD_BDA_SEGMENT_TO es, cx, !       ; Zero CX
    187     call    RamVars_GetCountOfKnownDrivesToDL
     212
     213    LOAD_BDA_SEGMENT_TO es, ax
     214    call    RamVars_GetCountOfKnownDrivesToAX
    188215    mov     cl, [es:BDA.bHDCount]
    189     MAX_U   cl, dl
    190 
    191     pop     dx
     216    MAX_U   al, cl
     217       
    192218    pop     es
    193219    ret
    194220
    195221;--------------------------------------------------------------------
    196 ; RamVars_GetCountOfKnownDrivesToDL
    197 ;   Parameters:
    198 ;       DS:     RAMVARS segment
    199 ;   Returns:
    200 ;       DL:     Total hard disk count
    201 ;   Corrupts registers:
    202 ;       Nothing
    203 ;--------------------------------------------------------------------
    204 ALIGN JUMP_ALIGN
    205 RamVars_GetCountOfKnownDrivesToDL:
    206     mov     dl, [RAMVARS.bFirstDrv]     ; Number for our first drive
    207     add     dl, [RAMVARS.bDrvCnt]       ; Our drives
    208     and     dl, 7Fh                     ; Clear HD bit for drive count
    209     ret
    210 
    211 
     222; RamVars_GetCountOfKnownDrivesToAX
     223;   Parameters:
     224;       DS:     RAMVARS segment
     225;   Returns:
     226;       AX:     Total hard disk count
     227;   Corrupts registers:
     228;       None
     229;--------------------------------------------------------------------
     230ALIGN JUMP_ALIGN
     231RamVars_GetCountOfKnownDrivesToAX:
     232    mov     ax, [RAMVARS.wDrvCntAndFirst]
     233    add     al, ah
     234    and     al, 7fh
     235    cbw
     236    ret
     237   
    212238;--------------------------------------------------------------------
    213239; RamVars_GetIdeControllerCountToCX
     
    219245;       Nothing
    220246;--------------------------------------------------------------------
     247ALIGN JUMP_ALIGN
    221248RamVars_GetIdeControllerCountToCX:
    222249    eMOVZX  cx, BYTE [cs:ROMVARS.bIdeCnt]
    223250    ret
     251
     252%ifdef MODULE_SERIAL_FLOPPY
     253;--------------------------------------------------------------------
     254; RamVars_UnpackFlopCntAndFirstToAL
     255;   Parameters:
     256;       Nothing
     257;   Returns:
     258;       AL:     First floppy drive number supported
     259;       CF:     Number of floppy drives supported (clear = 1, set = 2)
     260;   Corrupts registers:
     261;       Nothing
     262;--------------------------------------------------------------------       
     263ALIGN JUMP_ALIGN
     264RamVars_UnpackFlopCntAndFirstToAL:
     265    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst]
     266    sar     al, 1       
     267    ret
     268%endif
Note: See TracChangeset for help on using the changeset viewer.