source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm @ 370

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

Changes:

  • Added some missing PIO mode timings to ATA_ID.inc (based on info from http://www.singlix.net/specs/cfspc4_0.pdf)
  • Updated Configuration_FullMode.txt but it may need additional changes as the Tandy info doesn't match the wiki.
  • Optimizations.
  • Excluded some unused code from XTIDECFG.
File size: 7.1 KB
RevLine 
[148]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Int 13h function AH=9h, Initialize Drive Parameters.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=9h, Initialize Drive Parameters.
9;
10; AH9h_HandlerForInitializeDriveParameters
11;   Parameters:
[148]12;       DL:     Translated Drive number
13;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[150]14;       SS:BP:  Ptr to IDEPACK
15;   Returns with INTPACK:
[3]16;       AH:     Int 13h return status
[294]17;       CF:     0 if successful, 1 if error
[3]18;--------------------------------------------------------------------
19AH9h_HandlerForInitializeDriveParameters:
[84]20%ifndef USE_186
[3]21    call    AH9h_InitializeDriveForUse
[148]22    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[84]23%else
[148]24    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[162]25    ; Fall to AH9h_InitializeDriveForUse
[84]26%endif
[3]27
28
29;--------------------------------------------------------------------
30; Initialized drive to be ready for use.
31;
32; AH9h_InitializeDriveForUse
33;   Parameters:
[148]34;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[150]35;       SS:BP:  Ptr to IDEPACK
[3]36;   Returns:
37;       AH:     Int 13h return status
[294]38;       CF:     0 if successful, 1 if error
[3]39;   Corrupts registers:
[363]40;       AL, BX, CX, DX
[3]41;--------------------------------------------------------------------
42AH9h_InitializeDriveForUse:
[363]43    push    es
[276]44    push    si
[3]45
[258]46%ifdef MODULE_SERIAL
[363]47    ; no need to do this for serial devices
[258]48    xor     ah, ah
49    test    byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE    ; Clears CF
[363]50    jnz     .ReturnWithErrorCodeInAH
51
52%else
[365]53    ; Clear Initialization Error flags from DPT
54    mov     BYTE [di+DPT_ATA.bInitError], 0
[258]55%endif
[294]56
[3]57    ; Try to select drive and wait until ready
[150]58    call    AccessDPT_GetDriveSelectByteToAL
59    mov     [bp+IDEPACK.bDrvAndHead], al
60    call    Device_SelectDrive
[365]61    mov     al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
62    call    SetErrorFlagFromALwithErrorCodeInAH
[363]63    jc      SHORT .ReturnWithErrorCodeInAH
[3]64
65    ; Initialize CHS parameters if LBA is not used
[150]66    call    InitializeDeviceParameters
[365]67    mov     al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
68    call    SetErrorFlagFromALwithErrorCodeInAH
[3]69
[276]70    ; Enable or Disable Write Cache
[279]71    call    SetWriteCache
[365]72    mov     al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
73    call    SetErrorFlagFromALwithErrorCodeInAH
[276]74
[3]75    ; Recalibrate drive by seeking to cylinder 0
76.RecalibrateDrive:
77    call    AH11h_RecalibrateDrive
[365]78    mov     al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
79    call    SetErrorFlagFromALwithErrorCodeInAH
[3]80
81    ; Initialize block mode transfers
82.InitializeBlockMode:
[150]83    call    InitializeBlockMode
[365]84    mov     al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
85    call    SetErrorFlagFromALwithErrorCodeInAH
[3]86
[363]87%ifdef MODULE_ADVANCED_ATA
88; Initialize fastest supported PIO mode
89.InitializePioMode:
90    call    InitializePioMode
[365]91    mov     al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
92    call    SetErrorFlagFromALwithErrorCodeInAH
[363]93%endif
94
95    ; There might have been several errors so just return
96    ; one error code for them all
[365]97    cmp     BYTE [di+DPT_ATA.bInitError], 0
98    je      SHORT .ReturnWithErrorCodeInAH
[363]99    mov     ah, RET_HD_RESETFAIL
100    stc
101
102.ReturnWithErrorCodeInAH:
[276]103    pop     si
[363]104    pop     es
[3]105    ret
106
107
108;--------------------------------------------------------------------
[150]109; InitializeDeviceParameters
[3]110;   Parameters:
[150]111;       DS:DI:  Ptr to DPT (in RAMVARS segment)
112;       SS:BP:  Ptr to IDEPACK
[3]113;   Returns:
114;       AH:     BIOS Error code
[294]115;       CF:     Cleared if successful
[3]116;               Set if any error
117;   Corrupts registers:
[150]118;       AL, BX, CX, DX
[3]119;--------------------------------------------------------------------
[150]120InitializeDeviceParameters:
[3]121    ; No need to initialize CHS parameters if LBA mode enabled
[158]122    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA   ; Clear CF
[150]123    jnz     SHORT ReturnSuccessSinceInitializationNotNeeded
[3]124
[157]125    ; Initialize Logical Sectors per Track and Max Head number
[227]126    mov     ah, [di+DPT.bPchsHeads]
[150]127    dec     ah                          ; Max Head number
[227]128    mov     dl, [di+DPT.bPchsSectors]   ; Sectors per Track
[150]129    mov     al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
130    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
131    jmp     Idepack_StoreNonExtParametersAndIssueCommandFromAL
[3]132
133
134;--------------------------------------------------------------------
[276]135; SetWriteCache
136;   Parameters:
137;       DS:DI:  Ptr to DPT (in RAMVARS segment)
138;   Returns:
139;       AH:     BIOS Error code
[294]140;       CF:     Cleared if successful
[276]141;               Set if any error
142;   Corrupts registers:
143;       AL, BX, CX, DX, SI
144;--------------------------------------------------------------------
145SetWriteCache:
146    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
147    mov     bl, [cs:bx+DRVPARAMS.wFlags]
148    and     bx, BYTE MASK_DRVPARAMS_WRITECACHE
149    jz      SHORT ReturnSuccessSinceInitializationNotNeeded     ; DEFAULT_WRITE_CACHE
150    mov     si, [cs:bx+.rgbWriteCacheCommands]
151    jmp     AH23h_SetControllerFeatures
152
153.rgbWriteCacheCommands:
154    db      0                               ; DEFAULT_WRITE_CACHE
155    db      FEATURE_DISABLE_WRITE_CACHE     ; DISABLE_WRITE_CACHE
156    db      FEATURE_ENABLE_WRITE_CACHE      ; ENABLE_WRITE_CACHE
157
158
[363]159%ifdef MODULE_ADVANCED_ATA
[276]160;--------------------------------------------------------------------
[363]161; InitializePioMode
162;   Parameters:
163;       DS:DI:  Ptr to DPT (in RAMVARS segment)
164;   Returns:
165;       AH:     BIOS Error code
166;       CF:     Cleared if successful
167;               Set if any error
168;   Corrupts registers:
169;       AL, BX, CX, DX
170;--------------------------------------------------------------------
171InitializePioMode:
[364]172    mov     dl, PIO_DEFAULT_MODE_DISABLE_IORDY
173    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY
174    jz      SHORT .IordyNotSupported
175
176    ; Advanced PIO mode 3 and above
177    mov     dl, [di+DPT_ADVANCED_ATA.bPioMode]
178    or      dl, PIO_FLOW_CONTROL_MODE_xxx
179
180.IordyNotSupported:
[363]181    mov     si, FEATURE_SET_TRANSFER_MODE
182    jmp     AH23h_SetControllerFeatures
183%endif
184
185
186;--------------------------------------------------------------------
[150]187; InitializeBlockMode
[3]188;   Parameters:
[150]189;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[3]190;   Returns:
191;       AH:     BIOS Error code
[294]192;       CF:     Cleared if successful
[3]193;               Set if any error
194;   Corrupts registers:
195;       AL, BX, CX, DX
196;--------------------------------------------------------------------
[150]197InitializeBlockMode:
[158]198    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
[365]199    jz      SHORT .BlockModeNotSupportedOrDisabled
[276]200    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
201    test    BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE
[365]202    jz      SHORT .BlockModeNotSupportedOrDisabled
[363]203
[365]204    ; Try block sizes until we find largest possible supported by drive
205    mov     bl, 128
206.TryNextBlockSize:
207    mov     al, bl
208    call    AH24h_SetBlockSize
209    jnc     SHORT .SupportedBlockSizeFound
210    shr     bl, 1                       ; Try next size
211    jmp     SHORT .TryNextBlockSize
212.SupportedBlockSizeFound:
213    mov     [di+DPT_ATA.bBlockSize], bl
214.BlockModeNotSupportedOrDisabled:
215ReturnSuccessSinceInitializationNotNeeded:
[363]216    ret
217
218
219;--------------------------------------------------------------------
[365]220; SetErrorFlagFromALwithErrorCodeInAH
[363]221;   Parameters:
222;       AH:     BIOS Error Code
223;       AL:     Error flag to set
224;       DS:DI:  Ptr to DPT
225;   Returns:
226;       CF:     Clear if no error
227;               Set if error flag was set
228;   Corrupts registers:
[370]229;       Nothing
[363]230;--------------------------------------------------------------------
[365]231SetErrorFlagFromALwithErrorCodeInAH:
232    jnc     SHORT .NoErrorFlagToSet
[363]233    cmp     ah, RET_HD_INVALID
234    jbe     SHORT .IgnoreInvalidCommandError
235
[365]236    or      [di+DPT_ATA.bInitError], al
[363]237    stc
238    ret
239.IgnoreInvalidCommandError:
[276]240    xor     ah, ah
[365]241.NoErrorFlagToSet:
[3]242    ret
Note: See TracBrowser for help on using the repository browser.