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


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Device/MemoryMappedIDE/MemIdeTransfer.asm

    r238 r242  
    88    .wWordsLeft             resb    2   ; 2, WORDs left to transfer
    99    .wWordsDone             resb    2   ; 4, Number of sectors xferred
    10                             resb    1   ; 6,
     10    ; TODO: The above word vars could just as well be byte vars?
     11                            resb    1   ; 6,
    1112                            resb    1   ; 7, IDEPACK.bDeviceControl
    1213    .fpDPT                  resb    4   ; 8, Far pointer to DPT
     
    3435ALIGN JUMP_ALIGN
    3536MemIdeTransfer_StartWithCommandInAL:
     37    push    cs  ; We push CS here (segment of SAW) and later pop it to DS (reads) or ES (writes)
     38
    3639    ; Initialize MEMPIOVARS
    37     xchg    cx, ax                              ; IDE command to CL
    38     xor     al, al
    39     mov     ah, [bp+IDEPACK.bSectorCount]
    40     mov     [bp+MEMPIOVARS.wWordsLeft], ax
    41     cbw
    42     mov     [bp+MEMPIOVARS.wWordsDone], ax      ; Zero
    43     mov     ah, [di+DPT_ATA.bSetBlock]
    44     mov     [bp+MEMPIOVARS.wWordsInBlock], ax
     40    xor     cx, cx
     41    mov     [bp+MEMPIOVARS.wWordsDone], cx
     42    mov     ch, [bp+IDEPACK.bSectorCount]
     43    mov     [bp+MEMPIOVARS.wWordsLeft], cx
     44    mov     ch, [di+DPT_ATA.bSetBlock]
     45    mov     [bp+MEMPIOVARS.wWordsInBlock], cx
    4546    mov     [bp+MEMPIOVARS.fpDPT], di
    4647    mov     [bp+MEMPIOVARS.fpDPT+2], ds
    4748
    4849    ; Are we reading or writing?
    49     test    cl, 16  ; Bit 4 is cleared on all the read commands but set on 3 of the 4 write commands
    50     jnz     SHORT .PrepareToWriteDataFromESSI
    51     cmp     cl, COMMAND_WRITE_MULTIPLE
    52     je      SHORT .PrepareToWriteDataFromESSI
    53 
    54     ; Prepare to read data to ES:DI
    55     mov     di, si
    56     push    cs
    57     pop     ds
    58     mov     si, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
    59     jmp     SHORT ReadFromSectorAccessWindowInDSSItoESDI
    60 
    61 ALIGN JUMP_ALIGN
    62 .PrepareToWriteDataFromESSI:
    63     push    es
    64     pop     ds
    65     push    cs
    66     pop     es
    67     mov     di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
    68     ; Fall to WriteToSectorAccessWindowInESDIfromDSSI
    69 
    70 
    71 ;--------------------------------------------------------------------
    72 ; WriteToSectorAccessWindowInESDIfromDSSI
    73 ;   Parameters:
    74 ;       DS:SI:  Normalized ptr to buffer containing data
    75 ;       ES:DI:  Ptr to Sector Access Window
     50    test    al, 16  ; Bit 4 is cleared on all the read commands but set on 3 of the 4 write commands
     51    jnz     SHORT WriteToSectorAccessWindow
     52    cmp     al, COMMAND_WRITE_MULTIPLE
     53    je      SHORT WriteToSectorAccessWindow
     54    ; Fall to ReadFromSectorAccessWindow
     55
     56;--------------------------------------------------------------------
     57; ReadFromSectorAccessWindow
     58;   Parameters:
     59;       Stack:  Segment part of ptr to Sector Access Window
     60;       ES:SI:  Normalized ptr to buffer to receive data
    7661;       SS:BP:  Ptr to MEMPIOVARS
    7762;   Returns:
     
    8469;       AL, BX, DX, SI, ES
    8570;--------------------------------------------------------------------
    86 WriteToSectorAccessWindowInESDIfromDSSI:
    87     ; Always poll when writing first block (IRQs are generated for following blocks)
    88     call    WaitUntilReadyToTransferNextBlock
    89     jc      SHORT ReturnWithMemoryIOtransferErrorInAH
    90 
    91 ALIGN JUMP_ALIGN
    92 .WriteNextBlockToDrive:
    93     mov     cx, [bp+PIOVARS.wWordsInBlock]
    94     cmp     [bp+PIOVARS.wWordsLeft], cx
    95     jbe     SHORT .WriteLastBlockToDrive
    96     eMOVZX  dx, ch                              ; DX = Sectors in block
    97     call    WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
    98     call    WaitUntilReadyToTransferNextBlock
    99     jc      SHORT ReturnWithMemoryIOtransferErrorInAH
    100 
    101     ; Increment number of successfully written WORDs
    102     mov     ax, [bp+PIOVARS.wWordsInBlock]
    103     sub     [bp+PIOVARS.wWordsLeft], ax
    104     add     [bp+PIOVARS.wWordsDone], ax
    105     jmp     SHORT .WriteNextBlockToDrive
    106 
    107 ALIGN JUMP_ALIGN
    108 .WriteLastBlockToDrive:
    109     eMOVZX  dx, BYTE [bp+PIOVARS.wWordsLeft+1]  ; Sectors left
    110 %ifdef USE_186
    111     push    CheckErrorsAfterTransferringLastMemoryMappedBlock
    112     jmp     WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
    113 %else
    114     call    WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
    115     jmp     SHORT CheckErrorsAfterTransferringLastMemoryMappedBlock
    116 %endif
    117 
    118 
    119 ;--------------------------------------------------------------------
    120 ; WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
    121 ;   Parameters:
    122 ;       DX:     Number of sectors in block
    123 ;       DS:SI:  Normalized ptr to source buffer
    124 ;       ES:DI:  Ptr to Sector Access Window
    125 ;   Returns:
    126 ;       CX, DX: Zero
    127 ;       SI:     Updated
    128 ;   Corrupts registers:
    129 ;       Nothing
    130 ;--------------------------------------------------------------------
    131 ALIGN JUMP_ALIGN
    132 WriteSingleBlockFromDSSIToSectorAccessWindowInESDI:
    133     mov     cx, JRIDE_SECTOR_ACCESS_WINDOW_SIZE / 2
    134     rep movsw
    135     sub     di, JRIDE_SECTOR_ACCESS_WINDOW_SIZE ; Reset for next sector
    136     dec     dx
    137     jnz     SHORT WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
    138     ret
    139 
    140 
    141 ;--------------------------------------------------------------------
    142 ; ReadFromSectorAccessWindowInDSSItoESDI
    143 ;   Parameters:
    144 ;       ES:DI:  Normalized ptr to buffer to recieve data
    145 ;       DS:SI:  Ptr to Sector Access Window
    146 ;       SS:BP:  Ptr to MEMPIOVARS
    147 ;   Returns:
    148 ;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    149 ;       AH:     BIOS Error code
    150 ;       CX:     Number of successfully transferred sectors
    151 ;       CF:     0 if transfer succesfull
    152 ;               1 if any error
    153 ;   Corrupts registers:
    154 ;       AL, BX, DX, SI, ES
    155 ;--------------------------------------------------------------------
    156 ALIGN JUMP_ALIGN
    157 ReadFromSectorAccessWindowInDSSItoESDI:
    158     call    WaitUntilReadyToTransferNextBlock
    159     jc      SHORT ReturnWithMemoryIOtransferErrorInAH
     71ReadFromSectorAccessWindow:
     72    pop     ds  ; CS -> DS
     73    mov     di, si
     74    mov     si, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
     75
     76    call    WaitUntilReadyToTransferNextBlock
     77    jc      SHORT ReturnWithMemoryIOtransferErrorInAH
     78
     79    mov     cx, [bp+PIOVARS.wWordsInBlock]
    16080
    16181ALIGN JUMP_ALIGN
    16282.ReadNextBlockFromDrive:
    163     mov     cx, [bp+PIOVARS.wWordsInBlock]
    16483    cmp     [bp+PIOVARS.wWordsLeft], cx
    16584    jbe     SHORT .ReadLastBlockFromDrive
    166     eMOVZX  dx, ch                              ; DX = Sectors in block
    16785    call    ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
    16886    call    WaitUntilReadyToTransferNextBlock
     
    17088
    17189    ; Increment number of successfully read WORDs
    172     mov     ax, [bp+PIOVARS.wWordsInBlock]
    173     sub     [bp+PIOVARS.wWordsLeft], ax
    174     add     [bp+PIOVARS.wWordsDone], ax
     90    mov     cx, [bp+PIOVARS.wWordsInBlock]
     91    sub     [bp+PIOVARS.wWordsLeft], cx
     92    add     [bp+PIOVARS.wWordsDone], cx
    17593    jmp     SHORT .ReadNextBlockFromDrive
    17694
    17795ALIGN JUMP_ALIGN
    17896.ReadLastBlockFromDrive:
    179     eMOVZX  dx, BYTE [bp+PIOVARS.wWordsLeft+1]  ; Sectors left
     97    mov     ch, [bp+PIOVARS.wWordsLeft+1]       ; Sectors left
    18098    call    ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
    18199
     
    186104    call    IDEDEVICE%+Wait_PollStatusFlagInBLwithTimeoutInBH
    187105
    188     ; Return number of successfully read sectors
     106    ; Return number of successfully transferred sectors
    189107ReturnWithMemoryIOtransferErrorInAH:
    190108    lds     di, [bp+MEMPIOVARS.fpDPT]           ; DPT now in DS:DI
     
    198116
    199117;--------------------------------------------------------------------
     118; WriteToSectorAccessWindow
     119;   Parameters:
     120;       Stack:  Segment part of ptr to Sector Access Window
     121;       ES:SI:  Normalized ptr to buffer containing data
     122;       SS:BP:  Ptr to MEMPIOVARS
     123;   Returns:
     124;       DS:DI:  Ptr to DPT (in RAMVARS segment)
     125;       AH:     BIOS Error code
     126;       CX:     Number of successfully transferred sectors
     127;       CF:     0 if transfer succesfull
     128;               1 if any error
     129;   Corrupts registers:
     130;       AL, BX, DX, SI, ES
     131;--------------------------------------------------------------------
     132ALIGN JUMP_ALIGN
     133WriteToSectorAccessWindow:
     134    push    es
     135    pop     ds
     136    pop     es  ; CS -> ES
     137    mov     di, JRIDE_SECTOR_ACCESS_WINDOW_OFFSET
     138
     139    ; Always poll when writing first block (IRQs are generated for following blocks)
     140    call    WaitUntilReadyToTransferNextBlock
     141    jc      SHORT ReturnWithMemoryIOtransferErrorInAH
     142
     143    mov     cx, [bp+PIOVARS.wWordsInBlock]
     144
     145ALIGN JUMP_ALIGN
     146.WriteNextBlockToDrive:
     147    cmp     [bp+PIOVARS.wWordsLeft], cx
     148    jbe     SHORT .WriteLastBlockToDrive
     149    call    WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
     150    call    WaitUntilReadyToTransferNextBlock
     151    jc      SHORT ReturnWithMemoryIOtransferErrorInAH
     152
     153    ; Increment number of successfully written WORDs
     154    mov     cx, [bp+PIOVARS.wWordsInBlock]
     155    sub     [bp+PIOVARS.wWordsLeft], cx
     156    add     [bp+PIOVARS.wWordsDone], cx
     157    jmp     SHORT .WriteNextBlockToDrive
     158
     159ALIGN JUMP_ALIGN
     160.WriteLastBlockToDrive:
     161    mov     ch, [bp+PIOVARS.wWordsLeft+1]       ; Sectors left
     162%ifndef USE_186
     163    mov     bx, CheckErrorsAfterTransferringLastMemoryMappedBlock
     164    push    bx
     165%else
     166    push    CheckErrorsAfterTransferringLastMemoryMappedBlock
     167%endif
     168    ; Fall to WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
     169
     170;--------------------------------------------------------------------
     171; WriteSingleBlockFromDSSIToSectorAccessWindowInESDI
     172;   Parameters:
     173;       CH:     Number of sectors in block
     174;       DS:SI:  Normalized ptr to source buffer
     175;       ES:DI:  Ptr to Sector Access Window
     176;   Returns:
     177;       CX, DX: Zero
     178;       SI:     Updated
     179;   Corrupts registers:
     180;       BX
     181;--------------------------------------------------------------------
     182ALIGN JUMP_ALIGN
     183WriteSingleBlockFromDSSIToSectorAccessWindowInESDI:
     184    mov     bx, di
     185    eMOVZX  dx, ch
     186    xor     cl, cl
     187ALIGN JUMP_ALIGN
     188.WriteBlock:
     189    mov     ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
     190    rep movsw
     191    mov     di, bx  ; Reset for next sector
     192    dec     dx
     193    jnz     SHORT .WriteBlock
     194    ret
     195
     196
     197;--------------------------------------------------------------------
    200198; ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
    201199;   Parameters:
    202 ;       DX:     Number of sectors in block
    203 ;       ES:DI:  Normalized ptr to buffer to recieve data (destination)
     200;       CH:     Number of sectors in block
     201;       ES:DI:  Normalized ptr to buffer to receive data (destination)
    204202;       DS:SI:  Ptr to Sector Access Window (source)
    205203;   Returns:
     
    207205;       DI:     Updated
    208206;   Corrupts registers:
    209 ;       Nothing
     207;       BX
    210208;--------------------------------------------------------------------
    211209ALIGN JUMP_ALIGN
    212210ReadSingleBlockFromSectorAccessWindowInDSSItoESDI:
    213     mov     cx, JRIDE_SECTOR_ACCESS_WINDOW_SIZE / 2
     211    mov     bx, si
     212    eMOVZX  dx, ch
     213    xor     cl, cl
     214ALIGN JUMP_ALIGN
     215.ReadBlock:
     216    mov     ch, JRIDE_SECTOR_ACCESS_WINDOW_SIZE >> 9
    214217    rep movsw
    215     sub     si, JRIDE_SECTOR_ACCESS_WINDOW_SIZE ; Reset for next sector
     218    mov     si, bx  ; Reset for next sector
    216219    dec     dx
    217     jnz     SHORT ReadSingleBlockFromSectorAccessWindowInDSSItoESDI
     220    jnz     SHORT .ReadBlock
    218221    ret
    219222
     
    238241    pop     ds
    239242    ret
     243
     244
     245%if JRIDE_SECTOR_ACCESS_WINDOW_SIZE <> 512
     246    %error "JRIDE_SECTOR_ACCESS_WINDOW_SIZE is no longer equal to 512. MemIdeTransfer.asm needs changes."
     247%endif
     248
Note: See TracChangeset for help on using the changeset viewer.