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

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

Changes:

  • A speed optimization to the eSHL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Memory_SumCXbytesFromESSItoAL now returns with the zero flag set/cleared according to the result.
  • Unrolled all the 8 bit READ transfer loops to do 16 bytes per iteration. Added a new macro (UNROLL_SECTORS_IN_CX_TO_OWORDS) as part of it. Size wise this is expensive but I think it should be worth the ROM space. The WRITE transfer loops were left as is since writes are rare anyway (<10% of all disk I/O IIRC).
  • Minor optimizations and fixes here and there.
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 successfully
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 mov bl, ATA1.wHeadCnt & 0FFh
47 mov cx, MAX_VALID_PCHS_HEADS
48 call .CompareCHorSfromOffsetBXtoMaxValueInCX
49
50 mov bl, ATA1.wSPT & 0FFh
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 ; Returns with ZF set according to result
72 jnz SHORT .FailedToVerifyAtaID
73
74 ; ATA-ID is now verified to be valid
75.AtaIDverifiedSuccessfully:
76 clc
77 ret
78
79;--------------------------------------------------------------------
80; .CompareCHorSfromOffsetBXtoMaxValueInCX
81; Parameters:
82; BX: C, H or S offset to ATA-ID
83; CX: Maximum valid C, H or S value
84; ES:SI: Ptr to 512-byte ATA information read from the drive
85; Returns:
86; Exits from AtaID_VerifyFromESSI with CF set if invalid value
87; Corrupts registers:
88; AX
89;--------------------------------------------------------------------
90.CompareCHorSfromOffsetBXtoMaxValueInCX:
91 mov ax, [es:bx+si]
92 test ax, ax
93 jz SHORT .InvalidPCHorSinOffsetBX
94 cmp ax, cx ; Compare to max valid value
95 jbe SHORT .ValidPCHorSinOffsetBX
96.InvalidPCHorSinOffsetBX:
97 add sp, BYTE 2 ; Clear return address for this function
98.FailedToVerifyAtaID:
99 stc ; Set carry to indicate invalid ATA-ID
100.ValidPCHorSinOffsetBX:
101 ret
102
103
104%ifdef MODULE_ADVANCED_ATA
105;--------------------------------------------------------------------
106; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
107; Parameters:
108; ES:SI: Ptr to 512-byte ATA information read from the drive
109; Returns:
110; AL: Max supported PIO mode
111; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
112; CX: Minimum Cycle Time in nanosecs
113; Corrupts registers:
114; BX
115;--------------------------------------------------------------------
116AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
117 ; Get PIO mode and cycle time for PIO 0...2
118 mov bx, [es:si+ATA1.bPioMode]
119 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
120 eSHL_IM bx, 1 ; Shift for WORD lookup
121 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
122
123 ; Check if IORDY is supported
124 test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
125 jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
126 mov ah, FLGH_DPT_IORDY
127
128 ; Check if Advanced PIO modes are supported (3 and above)
129 test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
130 jz SHORT .ReturnPioTimings
131
132 ; Get Advanced PIO mode
133 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
134 mov bl, [es:si+ATA2.bPIOSupp]
135.CheckNextFlag:
136 inc ax
137 shr bl, 1
138 jnz SHORT .CheckNextFlag
139 MIN_U al, 6 ; Make sure not above lookup tables
140 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
141.ReturnPioTimings:
142 ret
143
144.rgwPio0to2CycleTimeInNanosecs:
145 dw PIO_0_MIN_CYCLE_TIME_NS
146 dw PIO_1_MIN_CYCLE_TIME_NS
147 dw PIO_2_MIN_CYCLE_TIME_NS
148
149
150;--------------------------------------------------------------------
151; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
152; Parameters:
153; BX: PIO Mode
154; CX: PIO Cycle Time in nanosecs
155; Returns:
156; AX: Active Time in nanosecs
157; Corrupts registers:
158; BX, CX
159;--------------------------------------------------------------------
160AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
161 call AtaID_GetActiveTimeToAXfromPioModeInBX
162 mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
163 sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
164 sub cx, ax ; - Active Time (t2)
165 xchg ax, cx ; AX = Recovery Time (t2i)
166 ret
167
168.rgbPioModeToAddressValidTimeNs:
169 db PIO_0_MIN_ADDRESS_VALID_NS
170 db PIO_1_MIN_ADDRESS_VALID_NS
171 db PIO_2_MIN_ADDRESS_VALID_NS
172 db PIO_3_MIN_ADDRESS_VALID_NS
173 db PIO_4_MIN_ADDRESS_VALID_NS
174 db PIO_5_MIN_ADDRESS_VALID_NS
175 db PIO_6_MIN_ADDRESS_VALID_NS
176
177
178;--------------------------------------------------------------------
179; AtaID_GetActiveTimeToAXfromPioModeInBX
180; Parameters:
181; BX: PIO Mode
182; Returns:
183; AX: Active Time in nanosecs
184; Corrupts registers:
185; Nothing
186;--------------------------------------------------------------------
187AtaID_GetActiveTimeToAXfromPioModeInBX:
188 eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
189 ret
190
191.rgbPioModeToActiveTimeNs:
192 db PIO_0_MIN_ACTIVE_TIME_NS
193 db PIO_1_MIN_ACTIVE_TIME_NS
194 db PIO_2_MIN_ACTIVE_TIME_NS
195 db PIO_3_MIN_ACTIVE_TIME_NS
196 db PIO_4_MIN_ACTIVE_TIME_NS
197 db PIO_5_MIN_ACTIVE_TIME_NS
198 db PIO_6_MIN_ACTIVE_TIME_NS
199
200%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.