Changeset 242 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/Device/IDE


Ignore:
Timestamp:
Feb 10, 2012, 3:12:40 AM (13 years ago)
Author:
krille_n_@…
google:author:
krille_n_@hotmail.com
Message:

Changes:

  • Optimizations (both for size and speed) in IdeTransfer.asm and MemIdeTransfer.asm
  • Fixed a bug where the SingleByteRead/Write functions in IdeTransfer.asm would fail on 128 sector transfers.
  • Fixed some typos and errors in general, comments etc.
Location:
trunk/XTIDE_Universal_BIOS/Src/Device/IDE
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm

    r160 r242  
    1414;       Nothing
    1515;   Corrupts registers:
    16 ;       AX, BX, CX, DX
     16;       AX
    1717;--------------------------------------------------------------------
    1818IdeDPT_Finalize:
     
    2828;       Nothing
    2929;   Corrupts registers:
    30 ;       Nothing
     30;       AX
    3131;--------------------------------------------------------------------
    3232.StoreBlockMode:
  • trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm

    r238 r242  
    3535ALIGN JUMP_ALIGN
    3636IdeTransfer_StartWithCommandInAL:
    37     mov     ah, [bp+IDEPACK.bSectorCount]
    38 
    3937    ; Are we reading or writing?
    4038    test    al, 16  ; Bit 4 is cleared on all the read commands but set on 3 of the 4 write commands
    41     jnz     SHORT .PrepareToWriteDataFromESSI
     39    mov     ah, [bp+IDEPACK.bSectorCount]
     40    jnz     SHORT WriteToDrive
    4241    cmp     al, COMMAND_WRITE_MULTIPLE
    43     je      SHORT .PrepareToWriteDataFromESSI
    44 
    45     ; Prepare to read data to ESSI
    46     mov     bx, g_rgfnPioRead
    47     call    InitializePiovarsInSSBPwithSectorCountInAH
    48     xchg    si, di
    49     jmp     SHORT ReadFromDrive
    50 
    51 ALIGN JUMP_ALIGN
    52 .PrepareToWriteDataFromESSI:
    53     mov     bx, g_rgfnPioWrite
    54     call    InitializePiovarsInSSBPwithSectorCountInAH
    55     ; Fall to WriteToDrive
    56 
    57 
    58 ;--------------------------------------------------------------------
    59 ; WriteToDrive
    60 ;   Parameters:
     42    je      SHORT WriteToDrive
     43    ; Fall to ReadFromDrive
     44
     45;--------------------------------------------------------------------
     46; ReadFromDrive
     47;   Parameters:
     48;       AH:     Number of sectors to transfer (1...128)
     49;       ES:SI:  Normalized ptr to buffer to receive data
    6150;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    62 ;       ES:SI:  Normalized ptr to buffer containing data
    6351;       SS:BP:  Ptr to PIOVARS
    6452;   Returns:
     53;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    6554;       AH:     BIOS Error code
    6655;       CX:     Number of successfully transferred sectors
     
    7059;       AL, BX, DX, SI, ES
    7160;--------------------------------------------------------------------
     61ReadFromDrive:
     62    ; Prepare to read data to ESSI
     63    mov     bx, g_rgfnPioRead
     64    call    InitializePiovarsInSSBPwithSectorCountInAH
     65
     66    ; Wait until drive is ready to transfer
     67    call    IdeWait_IRQorDRQ                    ; Wait until ready to transfer
     68    jc      SHORT ReturnWithTransferErrorInAH
     69    xchg    si, di                              ; ES:DI now points buffer
     70
     71    mov     cx, [bp+PIOVARS.wWordsInBlock]
     72
     73ALIGN JUMP_ALIGN
     74.ReadNextBlockFromDrive:
     75    mov     dx, [bp+PIOVARS.wDataPort]
     76    cmp     [bp+PIOVARS.wWordsLeft], cx
     77    jbe     SHORT .ReadLastBlockFromDrive
     78    call    [bp+PIOVARS.fnXfer]
     79
     80    ; Wait until ready for next block and check for errors
     81    xchg    di, si                              ; DS:DI now points DPT
     82    call    IdeWait_IRQorDRQ                    ; Wait until ready to transfer
     83    jc      SHORT ReturnWithTransferErrorInAH
     84    xchg    si, di                              ; ES:DI now points buffer
     85
     86    ; Increment number of successfully read WORDs
     87    mov     cx, [bp+PIOVARS.wWordsInBlock]
     88    sub     [bp+PIOVARS.wWordsLeft], cx
     89    add     [bp+PIOVARS.wWordsDone], cx
     90    jmp     SHORT .ReadNextBlockFromDrive
     91
     92ALIGN JUMP_ALIGN
     93.ReadLastBlockFromDrive:
     94    mov     cx, [bp+PIOVARS.wWordsLeft]
     95    call    [bp+PIOVARS.fnXfer]                 ; Transfer possibly partial block
     96
     97    ; Check for errors in last block
     98    mov     di, si                              ; DS:DI now points DPT
     99CheckErrorsAfterTransferringLastBlock:
     100    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
     101    call    IdeWait_PollStatusFlagInBLwithTimeoutInBH
     102
     103    ; Return number of successfully read sectors
     104ReturnWithTransferErrorInAH:
     105    mov     cx, [bp+PIOVARS.wWordsDone]
     106    jc      SHORT .ConvertTransferredWordsInCXtoSectors
     107    add     cx, [bp+PIOVARS.wWordsLeft]         ; Never sets CF
     108.ConvertTransferredWordsInCXtoSectors:
     109    xchg    cl, ch
     110    ret
     111
     112
     113;--------------------------------------------------------------------
     114; WriteToDrive
     115;   Parameters:
     116;       AH:     Number of sectors to transfer (1...128)
     117;       DS:DI:  Ptr to DPT (in RAMVARS segment)
     118;       ES:SI:  Normalized ptr to buffer containing data
     119;       SS:BP:  Ptr to PIOVARS
     120;   Returns:
     121;       AH:     BIOS Error code
     122;       CX:     Number of successfully transferred sectors
     123;       CF:     0 if transfer succesfull
     124;               1 if any error
     125;   Corrupts registers:
     126;       AL, BX, DX, SI, ES
     127;--------------------------------------------------------------------
     128ALIGN JUMP_ALIGN
    72129WriteToDrive:
     130    ; Prepare to write data from ESSI
     131    mov     bx, g_rgfnPioWrite
     132    call    InitializePiovarsInSSBPwithSectorCountInAH
     133
    73134    ; Always poll when writing first block (IRQs are generated for following blocks)
    74135    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
     
    76137    jc      SHORT ReturnWithTransferErrorInAH
    77138
     139    mov     cx, [bp+PIOVARS.wWordsInBlock]
     140
    78141ALIGN JUMP_ALIGN
    79142.WriteNextBlockToDrive:
    80     mov     cx, [bp+PIOVARS.wWordsInBlock]
    81143    mov     dx, [bp+PIOVARS.wDataPort]
    82144    cmp     [bp+PIOVARS.wWordsLeft], cx
     
    89151
    90152    ; Increment number of successfully written WORDs
    91     mov     ax, [bp+PIOVARS.wWordsInBlock]
    92     sub     [bp+PIOVARS.wWordsLeft], ax
    93     add     [bp+PIOVARS.wWordsDone], ax
     153    mov     cx, [bp+PIOVARS.wWordsInBlock]
     154    sub     [bp+PIOVARS.wWordsLeft], cx
     155    add     [bp+PIOVARS.wWordsDone], cx
    94156    jmp     SHORT .WriteNextBlockToDrive
    95157
     
    107169
    108170;--------------------------------------------------------------------
    109 ; ReadFromDrive
    110 ;   Parameters:
    111 ;       ES:DI:  Normalized ptr to buffer to recieve data
    112 ;       DS:SI:  Ptr to DPT (in RAMVARS segment)
    113 ;       SS:BP:  Ptr to PIOVARS
    114 ;   Returns:
    115 ;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    116 ;       AH:     BIOS Error code
    117 ;       CX:     Number of successfully transferred sectors
    118 ;       CF:     0 if transfer succesfull
    119 ;               1 if any error
    120 ;   Corrupts registers:
    121 ;       AL, BX, DX, SI, ES
    122 ;--------------------------------------------------------------------
    123 ALIGN JUMP_ALIGN
    124 ReadFromDrive:
    125     ; Wait until drive is ready to transfer
    126     xchg    di, si                              ; DS:DI now points DPT
    127     call    IdeWait_IRQorDRQ                    ; Wait until ready to transfer
    128     jc      SHORT ReturnWithTransferErrorInAH
    129     xchg    si, di                              ; ES:DI now points buffer
    130 
    131 ALIGN JUMP_ALIGN
    132 .ReadNextBlockFromDrive:
    133     mov     cx, [bp+PIOVARS.wWordsInBlock]
    134     mov     dx, [bp+PIOVARS.wDataPort]
    135     cmp     [bp+PIOVARS.wWordsLeft], cx
    136     jbe     SHORT .ReadLastBlockFromDrive
    137     call    [bp+PIOVARS.fnXfer]
    138 
    139     ; Wait until ready for next block and check for errors
    140     xchg    di, si                              ; DS:DI now points DPT
    141     call    IdeWait_IRQorDRQ                    ; Wait until ready to transfer
    142     jc      SHORT ReturnWithTransferErrorInAH
    143     xchg    si, di                              ; ES:DI now points buffer
    144 
    145     ; Increment number of successfully read WORDs
    146     mov     ax, [bp+PIOVARS.wWordsInBlock]
    147     sub     [bp+PIOVARS.wWordsLeft], ax
    148     add     [bp+PIOVARS.wWordsDone], ax
    149     jmp     SHORT .ReadNextBlockFromDrive
    150 
    151 ALIGN JUMP_ALIGN
    152 .ReadLastBlockFromDrive:
    153     mov     cx, [bp+PIOVARS.wWordsLeft]
    154     call    [bp+PIOVARS.fnXfer]                 ; Transfer possibly partial block
    155 
    156     ; Check for errors in last block
    157     mov     di, si                              ; DS:DI now points DPT
    158 CheckErrorsAfterTransferringLastBlock:
    159     mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
    160     call    IdeWait_PollStatusFlagInBLwithTimeoutInBH
    161 
    162     ; Return number of successfully read sectors
    163 ReturnWithTransferErrorInAH:
    164     mov     cx, [bp+PIOVARS.wWordsDone]
    165     jc      SHORT .ConvertTransferredWordsInCXtoSectors
    166     add     cx, [bp+PIOVARS.wWordsLeft]         ; Never sets CF
    167 .ConvertTransferredWordsInCXtoSectors:
    168     xchg    cl, ch
    169     ret
    170 
    171 
    172 ;--------------------------------------------------------------------
    173171; InitializePiovarsInSSBPwithSectorCountInAH
    174172;   Parameters:
     
    180178;       Nothing
    181179;   Corrupts registers:
    182 ;       AX, BX, CX, DX
     180;       AX, BX, DX
    183181;--------------------------------------------------------------------
    184182ALIGN JUMP_ALIGN
     
    187185    xor     al, al
    188186    mov     [bp+PIOVARS.wWordsLeft], ax
     187    mov     ah, [di+DPT_ATA.bSetBlock]
     188    mov     [bp+PIOVARS.wWordsInBlock], ax
    189189    cbw
    190190    mov     [bp+PIOVARS.wWordsDone], ax         ; Zero
    191     mov     ah, [di+DPT_ATA.bSetBlock]
    192     mov     [bp+PIOVARS.wWordsInBlock], ax
    193191
    194192    ; Get transfer function based on bus type
    195193    xchg    ax, bx                              ; Lookup table offset to AX
    196     eMOVZX  bx, BYTE [di+DPT.bIdevarsOffset]    ; CS:BX now points to IDEVARS
     194    mov     bl, [di+DPT.bIdevarsOffset]         ; CS:BX now points to IDEVARS
    197195    mov     dx, [cs:bx+IDEVARS.wPort]           ; Load IDE Data port address
    198196    mov     bl, [cs:bx+IDEVARS.bDevice]         ; Load device type to BX
    199197    add     bx, ax
     198    mov     [bp+PIOVARS.wDataPort], dx
    200199    mov     ax, [cs:bx]                         ; Load offset to transfer function
    201     mov     [bp+PIOVARS.wDataPort], dx
    202200    mov     [bp+PIOVARS.fnXfer], ax
    203201    ret
     
    213211;       CX:     Block size in WORDs
    214212;       DX:     IDE Data port address
    215 ;       ES:DI:  Normalized ptr to buffer to recieve data
     213;       ES:DI:  Normalized ptr to buffer to receive data
    216214;   Returns:
    217215;       Nothing
     
    236234SingleByteRead:
    237235%ifdef USE_186  ; INS instruction available
     236    dec     cx          ; Avoid overflowing CX on a 128 sector transfer
    238237    shl     cx, 1       ; WORD count to BYTE count
     238    inc     cx
    239239    rep insb
     240    insb
    240241%else           ; If 8088/8086
    241242    shr     cx, 1       ; WORD count to DWORD count
     
    328329SingleByteWrite:
    329330%ifdef USE_186  ; OUTS instruction available
     331    dec     cx          ; Avoid overflowing CX on a 128 sector transfer
    330332    shl     cx, 1       ; WORD count to BYTE count
     333    inc     cx
    331334    es                  ; Source is ES segment
    332335    rep outsb
     336    es outsb
    333337%else           ; If 8088/8086
    334338    shr     cx, 1       ; WORD count to DWORD count
     
    386390
    387391
    388 
    389392; Lookup tables to get transfer function based on bus type
    390393ALIGN WORD_ALIGN
Note: See TracChangeset for help on using the changeset viewer.