source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm @ 588

Last change on this file since 588 was 588, checked in by krille_n_@…, 9 years ago

Changes:

  • Fixed a bug in AH24h_HSetBlocks.asm from r550. Trying to set a too large block size with an XT-CF card in DMA transfer mode would corrupt the stack.
  • Fixed a bug from r545 where the list of devices under g_szDeviceTypeValues in Strings.asm was no longer up to date causing the boot menu to display the wrong string for devices numbered higher than DEVICE_8BIT_XTCF_PIO8.
  • Made some fairly significant changes to the XT-CF code to reduce size. Two changes in functionality; 1) Added a simple check to validate the request for a change of the XT-CF transfer mode. 2) Changing transfer mode to use DMA no longer calls AH24h_SetBlockSize if the block size already is within the limits of DMA transfers. UNTESTED
  • XTIDECFG now clears IDEVARS.bIRQ when changing IDE controller to a serial device to keep the boot menu from displaying it since the serial device doesn't use IRQs at all.
  • Other minor optimizations.
File size: 7.6 KB
RevLine 
[471]1; Project name  :   XTIDE Universal BIOS
[545]2; Description   :   Int 13h function AH=1Eh, Lo-tech XT-CF features
3;
4; More information at http://www.lo-tech.co.uk/XT-CF
[471]5
6;
[491]7; XTIDE Universal BIOS and Associated Tools
[526]8; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[471]9;
10; This program is free software; you can redistribute it and/or modify
11; it under the terms of the GNU General Public License as published by
12; the Free Software Foundation; either version 2 of the License, or
13; (at your option) any later version.
[491]14;
[471]15; This program is distributed in the hope that it will be useful,
16; but WITHOUT ANY WARRANTY; without even the implied warranty of
17; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[491]18; GNU General Public License for more details.
[471]19; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[491]20;
[471]21
22; Section containing code
23SECTION .text
24
25;--------------------------------------------------------------------
26; Int 13h function AH=1Eh, Lo-tech XT-CF features.
27; This function is supported only by XTIDE Universal BIOS.
28;
29; AH1Eh_HandlerForXTCFfeatures
30;   Parameters:
31;       AL, CX: Same as in INTPACK
32;       DL:     Translated Drive number
33;       DS:DI:  Ptr to DPT (in RAMVARS segment)
34;       SS:BP:  Ptr to IDEPACK
35;   Parameters on INTPACK:
36;       AL:     XT-CF subcommand (see XTCF.inc for more info)
37;   Returns with INTPACK:
38;       AH:     Int 13h return status
39;       CF:     0 if successful, 1 if error
[558]40;       DX:     Command return values (see XTCF.inc)
[471]41;--------------------------------------------------------------------
42AH1Eh_HandlerForXTCFfeatures:
43%ifndef USE_186
[475]44    call    ProcessXTCFsubcommandFromAL
[471]45    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
46%else
[558]47    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[475]48    ; Fall to ProcessXTCFsubcommandFromAL
[471]49%endif
50
51
52;--------------------------------------------------------------------
[475]53; ProcessXTCFsubcommandFromAL
[471]54;   Parameters:
[473]55;       AL:     XT-CF subcommand (see XTCF.inc for more info)
[471]56;       DS:DI:  Ptr to DPT (in RAMVARS segment)
57;       SS:BP:  Ptr to IDEPACK
58;   Returns:
59;       AH:     Int 13h return status
60;       CF:     0 if successful, 1 if error
61;   Corrupts registers:
[473]62;       AL, BX, CX, DX, SI
[471]63;--------------------------------------------------------------------
[475]64ProcessXTCFsubcommandFromAL:
[472]65    ; IS_THIS_DRIVE_XTCF. We check this for all commands.
[473]66    call    AccessDPT_IsThisDeviceXTCF
[588]67    jc      SHORT .XTCFnotFound
[558]68    and     ax, 0FFh                    ; Subcommand now in AX (clears AH and CF)
[545]69    jz      SHORT .XTCFfound            ; Sub-function IS_THIS_DRIVE_XTCF (=0)
[472]70
[545]71    dec     ax                          ; Test subcommand...
72    jz      SHORT .SetXTCFtransferMode  ; ...for value 1 (SET_XTCF_TRANSFER_MODE)
[491]73
[545]74    dec     ax                          ; Test subcommand for value 2 (GET_XTCF_TRANSFER_MODE)
[558]75    jnz     SHORT .AH1Eh_LoadInvalidCommandToAHandSetCF
[473]76
[545]77    ; GET_XTCF_TRANSFER_MODE
78    call    AH1Eh_GetCurrentXTCFmodeToAX
[558]79    mov     dh, al
[545]80    mov     dl, [di+DPT_ATA.bBlockSize]
[558]81    mov     [bp+IDEPACK.intpack+INTPACK.dx], dx ; Return mode value (DH) and block size (DL) via INTPACK
[545]82.XTCFfound:
[558]83    ret     ; With AH and CF cleared
[473]84
[545]85.XTCFnotFound:
86.AH1Eh_LoadInvalidCommandToAHandSetCF:
[558]87    stc     ; Set carry flag since XT-CF not found or invalid subcommand
[545]88    mov     ah, RET_HD_INVALID
[558]89    ret
[545]90
91.SetXTCFtransferMode:
[558]92    mov     al, [bp+IDEPACK.intpack+INTPACK.dh] ; Get specified mode (eg XTCF_DMA_MODE)
93    ; Fall to AH1Eh_ChangeXTCFmodeBasedOnModeInAL
[545]94
95
[473]96;--------------------------------------------------------------------
[545]97; AH1Eh_ChangeXTCFmodeBasedOnModeInAL
[473]98;   Parameters:
[545]99;       AL:     XT-CF Mode (see XTCF.inc)
[473]100;       DS:DI:  Ptr to DPT (in RAMVARS segment)
101;       SS:BP:  Ptr to IDEPACK
[558]102;   Returns:
[473]103;       AH:     Int 13h return status
104;       CF:     0 if successful, 1 if error
105;   Corrupts registers:
106;       AL, BX, CX, DX, SI
107;--------------------------------------------------------------------
[545]108AH1Eh_ChangeXTCFmodeBasedOnModeInAL:
109    ; Note: Control register (as of XT-CFv3) is now a write-only register,
[558]110    ;       whose purpose is *only* to raise DRQ.  The register cannot be read.
[545]111    ;       Selected transfer mode is stored in BIOS variable (DPT_ATA.bDevice).
[472]112
[588]113    ; Note that when selecting 'XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD' mode,
[545]114    ; the ATA device (i.e. CompactFlash card) will operate in 8-bit mode, but
[558]115    ; data will be transferred from its data register using 16-bit CPU instructions
[545]116    ; like REP INSW.  This works because XT-CF adapters are 8-bit cards, and
117    ; the BIU in the machine splits each WORD requested by the CPU into two 8-bit
118    ; ISA cycles at base+0h and base+1h.  The XT-CF cards do not decode A0, hence
119    ; both accesses appear the same to the card and the BIU then re-constructs
120    ; the data for presentation to the CPU.
121    ;
[558]122    ; Also note that some machines, noteably the Olivetti M24 (also known as
123    ; the AT&T PC6300 and Xerox 6060), have hardware errors in the BIU logic,
[588]124    ; resulting in reversed byte ordering.  Therefore, XTCF_8BIT_PIO_MODE is
[558]125    ; the default transfer mode for best system compatibility.
[545]126
[588]127
128    ; Is requested mode valid?
129    cmp     al, 3                       ; Valid modes are 0...3
130    ja      SHORT ProcessXTCFsubcommandFromAL.AH1Eh_LoadInvalidCommandToAHandSetCF
131
132    ; Convert mode to XT-CF device type (see RomVars.inc and XTCF.inc for full details)
133    eSHL_IM al, 1                       ; Shift requested mode
134    add     al, XTCF_DEVICE_OFFSET      ; Add the device offset (already shifted)
135    mov     [di+DPT_ATA.bDevice], al    ; Set the new mode (or device actually)
136
137    cmp     al, DEVICE_8BIT_XTCF_PIO16_WITH_BIU_OFFLOAD
138    je      SHORT AH23h_Disable8bitPioMode
139
[558]140    ; We always need to enable 8-bit mode since 16-bit mode is restored
141    ; when controller is reset (AH=00h or 0Dh)
[588]142
143    cmp     al, DEVICE_8BIT_XTCF_DMA
144    jne     SHORT AH23h_Enable8bitPioMode
145
146    ; DMA transfers have limited block size
147    mov     al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
148    cmp     [di+DPT_ATA.bBlockSize], al
149    jbe     SHORT AH23h_Enable8bitPioMode   ; No need to limit block size
150    call    AH24h_SetBlockSize
151    jmp     SHORT AH23h_Enable8bitPioMode
152
153
154%if 0
155    ; We always need to enable 8-bit mode since 16-bit mode is restored
156    ; when controller is reset (AH=00h or 0Dh)
[505]157    ePUSH_T bx, AH23h_Enable8bitPioMode
158
[545]159    ; Convert mode to device type (see XTCF.inc for full details)
160    and     ax, 3
[558]161    jz      SHORT .Set8bitPioMode   ; XTCF_8BIT_PIO_MODE = 0
162    dec     ax                      ; XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD = 1
163    jz      SHORT .Set8bitPioModeWithBIUOffload
[588]164    dec     ax                      ; XTCF_16BIT_PIO_WITH_BIU_OFFLOAD = 2
[584]165    jz      SHORT .Set16bitPioModeWithBIUOffload
[472]166
[588]167    ; XTCF_DMA_MODE = 3
[473]168    mov     BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
[545]169
[558]170    ; DMA transfers have limited block size
[474]171    mov     al, [di+DPT_ATA.bBlockSize]
[558]172    cmp     al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
173    jbe     SHORT AH24h_SetBlockSize
174    mov     al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
175    jmp     SHORT AH24h_SetBlockSize
[473]176
[584]177.Set16bitPioModeWithBIUOffload:
178    pop     bx                              ; Do not enable 8-bit PIO...
179    ePUSH_T bx, AH23h_Disable8bitPioMode    ; ...disable it instead
180    mov     al, DEVICE_8BIT_XTCF_PIO16_WITH_BIU_OFFLOAD
181    SKIP2B  bx
182
[473]183.Set8bitPioMode:
[558]184    mov     al, DEVICE_8BIT_XTCF_PIO8
185    SKIP2B  bx
[491]186
[545]187.Set8bitPioModeWithBIUOffload:
[558]188    mov     al, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
189    mov     [di+DPT_ATA.bDevice], al
190    ret
[588]191%endif ; 0
[473]192
[545]193
[472]194;--------------------------------------------------------------------
[545]195; AH1Eh_GetCurrentXTCFmodeToAX
[472]196;   Parameters:
[545]197;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[558]198;   Returns:
[588]199;       AX:     XT-CF mode (XTCF_8BIT_PIO_MODE, XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD, XTCF_16BIT_PIO_WITH_BIU_OFFLOAD or XTCF_DMA_MODE)
[545]200;       CF:     Clear
[472]201;   Corrupts registers:
[545]202;       Nothing
[472]203;--------------------------------------------------------------------
[545]204AH1Eh_GetCurrentXTCFmodeToAX:
[588]205    mov     ax, -XTCF_DEVICE_OFFSET & 0FFh
206    add     al, [di+DPT_ATA.bDevice]
207    shr     al, 1
208    ret
209
210%if 0
[558]211    mov     al, [di+DPT_ATA.bDevice]
212    shr     al, 1
213    cbw
[588]214    sub     al, XTCF_DEVICE_OFFSET >> 1
[545]215    ret
[588]216%endif ; 0
Note: See TracBrowser for help on using the repository browser.