source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm @ 534

Last change on this file since 534 was 526, checked in by krille_n_@…, 11 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 6.4 KB
RevLine 
[99]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Functions for accessing ATA information read with
3;                   IDENTIFY DEVICE command.
4
[376]5;
[445]6; XTIDE Universal BIOS and Associated Tools
[526]7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]8;
9; This program is free software; you can redistribute it and/or modify
10; it under the terms of the GNU General Public License as published by
11; the Free Software Foundation; either version 2 of the License, or
12; (at your option) any later version.
[445]13;
[376]14; This program is distributed in the hope that it will be useful,
15; but WITHOUT ANY WARRANTY; without even the implied warranty of
16; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[445]17; GNU General Public License for more details.
[376]18; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]19;
[376]20
[3]21; Section containing code
22SECTION .text
23
[441]24;--------------------------------------------------------------------
25; AtaID_VerifyFromESSI
26;   Parameters:
27;       ES:SI:  Ptr to 512-byte ATA information read from the drive
28;   Returns:
29;       CF:     Set if failed to verify ATA-ID
[445]30;               Cleared if ATA-ID verified successfully
[441]31;   Corrupts registers:
32;       AX, BX, CX
33;--------------------------------------------------------------------
34AtaID_VerifyFromESSI:
35    ; We cannot start by reading ATA version since the ID might be
36    ; corrupted. We start by making sure P-CHS values are valid.
37    ; If they are, we assume the ATA ID to be valid. Fortunately we can do
[491]38    ; further checking for ATA-5 and later since they contain signature and
[441]39    ; checksum bytes. Those are not available for ATA-4 and older.
40
41    ; Verify P-CHS cylinders
42    mov     bx, ATA1.wCylCnt
43    mov     cx, MAX_VALID_PCHS_CYLINDERS
44    call    .CompareCHorSfromOffsetBXtoMaxValueInCX
45
[445]46    mov     bl, ATA1.wHeadCnt & 0FFh
[442]47    mov     cx, MAX_VALID_PCHS_HEADS
[441]48    call    .CompareCHorSfromOffsetBXtoMaxValueInCX
49
[445]50    mov     bl, ATA1.wSPT & 0FFh
[441]51    mov     cl, MAX_VALID_PCHS_SECTORS_PER_TRACK
52    call    .CompareCHorSfromOffsetBXtoMaxValueInCX
53
[487]54    ; Check signature byte. It is only found on ATA-5 and later. It should be zero on
55    ; ATA-4 and older.
56    mov     al, [es:si+ATA6.bSignature]
57    test    al, al
58    jz      SHORT .AtaIDverifiedSuccessfully    ; Old ATA so Signature and Checksum is not available
59    cmp     al, A6_wIntegrity_SIGNATURE
[441]60    jne     SHORT .FailedToVerifyAtaID
61
[487]62    ; Check checksum byte since signature was present
[441]63    mov     cx, ATA6_size
[445]64    call    Memory_SumCXbytesFromESSItoAL       ; Returns with ZF set according to result
[441]65    jnz     SHORT .FailedToVerifyAtaID
66
67    ; ATA-ID is now verified to be valid
68.AtaIDverifiedSuccessfully:
69    clc
70    ret
71
72;--------------------------------------------------------------------
73; .CompareCHorSfromOffsetBXtoMaxValueInCX
74;   Parameters:
75;       BX:     C, H or S offset to ATA-ID
76;       CX:     Maximum valid C, H or S value
77;       ES:SI:  Ptr to 512-byte ATA information read from the drive
78;   Returns:
79;       Exits from AtaID_VerifyFromESSI with CF set if invalid value
80;   Corrupts registers:
81;       AX
82;--------------------------------------------------------------------
83.CompareCHorSfromOffsetBXtoMaxValueInCX:
84    mov     ax, [es:bx+si]
85    test    ax, ax
86    jz      SHORT .InvalidPCHorSinOffsetBX
87    cmp     ax, cx          ; Compare to max valid value
88    jbe     SHORT .ValidPCHorSinOffsetBX
89.InvalidPCHorSinOffsetBX:
[442]90    add     sp, BYTE 2      ; Clear return address for this function
[441]91.FailedToVerifyAtaID:
92    stc                     ; Set carry to indicate invalid ATA-ID
93.ValidPCHorSinOffsetBX:
94    ret
95
96
[363]97%ifdef MODULE_ADVANCED_ATA
98;--------------------------------------------------------------------
[364]99; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
[363]100;   Parameters:
101;       ES:SI:  Ptr to 512-byte ATA information read from the drive
102;   Returns:
[364]103;       AL:     Max supported PIO mode
104;       AH:     FLGH_DPT_IORDY if IORDY supported, zero otherwise
105;       CX:     Minimum Cycle Time in nanosecs
[363]106;   Corrupts registers:
107;       BX
108;--------------------------------------------------------------------
[364]109AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
[363]110    ; Get PIO mode and cycle time for PIO 0...2
111    mov     bx, [es:si+ATA1.bPioMode]
[370]112    mov     ax, bx                  ; AH = 0, AL = PIO mode 0, 1 or 2
[445]113    eSHL_IM bx, 1                   ; Shift for WORD lookup
[364]114    mov     cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
[363]115
[364]116    ; Check if IORDY is supported
117    test    BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
118    jz      SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
119    mov     ah, FLGH_DPT_IORDY
120
[363]121    ; Check if Advanced PIO modes are supported (3 and above)
122    test    BYTE [es:si+ATA2.wFields], A2_wFields_64to70
123    jz      SHORT .ReturnPioTimings
124
125    ; Get Advanced PIO mode
[364]126    ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
[370]127    mov     bl, [es:si+ATA2.bPIOSupp]
[363]128.CheckNextFlag:
129    inc     ax
[370]130    shr     bl, 1
[363]131    jnz     SHORT .CheckNextFlag
[364]132    MIN_U   al, 6                       ; Make sure not above lookup tables
133    mov     cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
[363]134.ReturnPioTimings:
135    ret
136
137.rgwPio0to2CycleTimeInNanosecs:
138    dw      PIO_0_MIN_CYCLE_TIME_NS
139    dw      PIO_1_MIN_CYCLE_TIME_NS
140    dw      PIO_2_MIN_CYCLE_TIME_NS
141
142
143;--------------------------------------------------------------------
[364]144; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
[363]145;   Parameters:
[364]146;       BX:     PIO Mode
147;       CX:     PIO Cycle Time in nanosecs
[363]148;   Returns:
[364]149;       AX:     Active Time in nanosecs
[363]150;   Corrupts registers:
[364]151;       BX, CX
[363]152;--------------------------------------------------------------------
[364]153AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
154    call    AtaID_GetActiveTimeToAXfromPioModeInBX
155    mov     bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
156    sub     cx, bx  ; Cycle Time (t0) - Address Valid Time (t1)
157    sub     cx, ax  ; - Active Time (t2)
158    xchg    ax, cx  ; AX = Recovery Time (t2i)
[363]159    ret
160
161.rgbPioModeToAddressValidTimeNs:
162    db      PIO_0_MIN_ADDRESS_VALID_NS
163    db      PIO_1_MIN_ADDRESS_VALID_NS
164    db      PIO_2_MIN_ADDRESS_VALID_NS
165    db      PIO_3_MIN_ADDRESS_VALID_NS
166    db      PIO_4_MIN_ADDRESS_VALID_NS
[364]167    db      PIO_5_MIN_ADDRESS_VALID_NS
168    db      PIO_6_MIN_ADDRESS_VALID_NS
[363]169
[364]170
171;--------------------------------------------------------------------
172; AtaID_GetActiveTimeToAXfromPioModeInBX
173;   Parameters:
174;       BX:     PIO Mode
175;   Returns:
176;       AX:     Active Time in nanosecs
177;   Corrupts registers:
178;       Nothing
179;--------------------------------------------------------------------
180AtaID_GetActiveTimeToAXfromPioModeInBX:
[445]181    eMOVZX  ax, [cs:bx+.rgbPioModeToActiveTimeNs]
[364]182    ret
183
[445]184.rgbPioModeToActiveTimeNs:
185    db      PIO_0_MIN_ACTIVE_TIME_NS
186    db      PIO_1_MIN_ACTIVE_TIME_NS
187    db      PIO_2_MIN_ACTIVE_TIME_NS
188    db      PIO_3_MIN_ACTIVE_TIME_NS
189    db      PIO_4_MIN_ACTIVE_TIME_NS
190    db      PIO_5_MIN_ACTIVE_TIME_NS
191    db      PIO_6_MIN_ACTIVE_TIME_NS
[363]192
193%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.