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

Last change on this file since 444 was 442, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • ATA ID validation now compares heads to correct maximum number of heads.
  • Added XTCF 8-bit mode transfer functions.
File size: 6.7 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions for accessing ATA information read with
3; IDENTIFY DEVICE command.
4
5;
6; XTIDE Universal BIOS and Associated Tools
7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
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.
13;
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
17; GNU General Public License for more details.
18; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19;
20
21; Section containing code
22SECTION .text
23
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
30; Cleared if ATA-ID verified succesfully
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
38 ; futher checking for ATA-5 and later since they contain signature and
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
46 add bx, BYTE ATA1.wHeadCnt - ATA1.wCylCnt
47 mov cx, MAX_VALID_PCHS_HEADS
48 call .CompareCHorSfromOffsetBXtoMaxValueInCX
49
50 add bx, BYTE ATA1.wSPT - ATA1.wHeadCnt
51 mov cl, MAX_VALID_PCHS_SECTORS_PER_TRACK
52 call .CompareCHorSfromOffsetBXtoMaxValueInCX
53
54 ; We now verified P-CHS parameters so we assume ATA ID to be valid
55 ; for ATA-4 and older. For ATA-5 and later we check signature
56 ; and checksum.
57 mov ax, [es:si+ATA6.wMajorVer] ; ATA-3 and later have this word
58 inc ax
59 jz SHORT .AtaIDverifiedSuccessfully ; FFFFh means no version info available
60 dec ax
61 jz SHORT .AtaIDverifiedSuccessfully ; Zero means no version info available
62 cmp ax, A6_wMajorVer_ATA5
63 jb SHORT .AtaIDverifiedSuccessfully ; ATA-3 and ATA-4 do not have checksum
64
65 ; Check signature byte
66 cmp BYTE [es:si+ATA6.bSignature], A6_wIntegrity_SIGNATURE
67 jne SHORT .FailedToVerifyAtaID
68
69 ; Check checksum byte
70 mov cx, ATA6_size
71 call Memory_SumCXbytesFromESSItoAL
72 test al, al
73 jnz SHORT .FailedToVerifyAtaID
74
75 ; ATA-ID is now verified to be valid
76.AtaIDverifiedSuccessfully:
77 clc
78 ret
79
80;--------------------------------------------------------------------
81; .CompareCHorSfromOffsetBXtoMaxValueInCX
82; Parameters:
83; BX: C, H or S offset to ATA-ID
84; CX: Maximum valid C, H or S value
85; ES:SI: Ptr to 512-byte ATA information read from the drive
86; Returns:
87; Exits from AtaID_VerifyFromESSI with CF set if invalid value
88; Corrupts registers:
89; AX
90;--------------------------------------------------------------------
91.CompareCHorSfromOffsetBXtoMaxValueInCX:
92 mov ax, [es:bx+si]
93 test ax, ax
94 jz SHORT .InvalidPCHorSinOffsetBX
95 cmp ax, cx ; Compare to max valid value
96 jbe SHORT .ValidPCHorSinOffsetBX
97.InvalidPCHorSinOffsetBX:
98 add sp, BYTE 2 ; Clear return address for this function
99.FailedToVerifyAtaID:
100 stc ; Set carry to indicate invalid ATA-ID
101.ValidPCHorSinOffsetBX:
102 ret
103
104
105%ifdef MODULE_ADVANCED_ATA
106;--------------------------------------------------------------------
107; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
108; Parameters:
109; ES:SI: Ptr to 512-byte ATA information read from the drive
110; Returns:
111; AL: Max supported PIO mode
112; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
113; CX: Minimum Cycle Time in nanosecs
114; Corrupts registers:
115; BX
116;--------------------------------------------------------------------
117AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
118 ; Get PIO mode and cycle time for PIO 0...2
119 mov bx, [es:si+ATA1.bPioMode]
120 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
121 shl bx, 1 ; Shift for WORD lookup
122 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
123
124 ; Check if IORDY is supported
125 test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
126 jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
127 mov ah, FLGH_DPT_IORDY
128
129 ; Check if Advanced PIO modes are supported (3 and above)
130 test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
131 jz SHORT .ReturnPioTimings
132
133 ; Get Advanced PIO mode
134 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
135 mov bl, [es:si+ATA2.bPIOSupp]
136.CheckNextFlag:
137 inc ax
138 shr bl, 1
139 jnz SHORT .CheckNextFlag
140 MIN_U al, 6 ; Make sure not above lookup tables
141 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
142.ReturnPioTimings:
143 ret
144
145.rgwPio0to2CycleTimeInNanosecs:
146 dw PIO_0_MIN_CYCLE_TIME_NS
147 dw PIO_1_MIN_CYCLE_TIME_NS
148 dw PIO_2_MIN_CYCLE_TIME_NS
149
150
151;--------------------------------------------------------------------
152; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
153; Parameters:
154; BX: PIO Mode
155; CX: PIO Cycle Time in nanosecs
156; Returns:
157; AX: Active Time in nanosecs
158; Corrupts registers:
159; BX, CX
160;--------------------------------------------------------------------
161AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
162 call AtaID_GetActiveTimeToAXfromPioModeInBX
163 mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
164 sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
165 sub cx, ax ; - Active Time (t2)
166 xchg ax, cx ; AX = Recovery Time (t2i)
167 ret
168
169.rgbPioModeToAddressValidTimeNs:
170 db PIO_0_MIN_ADDRESS_VALID_NS
171 db PIO_1_MIN_ADDRESS_VALID_NS
172 db PIO_2_MIN_ADDRESS_VALID_NS
173 db PIO_3_MIN_ADDRESS_VALID_NS
174 db PIO_4_MIN_ADDRESS_VALID_NS
175 db PIO_5_MIN_ADDRESS_VALID_NS
176 db PIO_6_MIN_ADDRESS_VALID_NS
177
178
179;--------------------------------------------------------------------
180; AtaID_GetActiveTimeToAXfromPioModeInBX
181; Parameters:
182; BX: PIO Mode
183; Returns:
184; AX: Active Time in nanosecs
185; Corrupts registers:
186; Nothing
187;--------------------------------------------------------------------
188AtaID_GetActiveTimeToAXfromPioModeInBX:
189 shl bx, 1
190 mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
191 shr bx, 1
192 ret
193
194.rgwPioModeToActiveTimeNs:
195 dw PIO_0_MIN_ACTIVE_TIME_NS
196 dw PIO_1_MIN_ACTIVE_TIME_NS
197 dw PIO_2_MIN_ACTIVE_TIME_NS
198 dw PIO_3_MIN_ACTIVE_TIME_NS
199 dw PIO_4_MIN_ACTIVE_TIME_NS
200 dw PIO_5_MIN_ACTIVE_TIME_NS
201 dw PIO_6_MIN_ACTIVE_TIME_NS
202
203%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.