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
|
---|
22 | SECTION .text
|
---|
23 |
|
---|
24 | ;--------------------------------------------------------------------
|
---|
25 | ; AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
26 | ; Parameters:
|
---|
27 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
28 | ; Returns:
|
---|
29 | ; AX: Number of user specified P-CHS cylinders
|
---|
30 | ; BH: Number of user specified P-CHS sectors per track
|
---|
31 | ; BL: Number of user specified P-CHS heads
|
---|
32 | ; Corrupts registers:
|
---|
33 | ; Nothing
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI:
|
---|
36 | mov ax, [es:si+ATA1.wCylCnt] ; Cylinders (1...16383)
|
---|
37 | mov bl, [es:si+ATA1.wHeadCnt] ; Heads (1...16)
|
---|
38 | mov bh, [es:si+ATA1.wSPT] ; Sectors per Track (1...63)
|
---|
39 | ret
|
---|
40 |
|
---|
41 |
|
---|
42 | ;--------------------------------------------------------------------
|
---|
43 | ; AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
44 | ; Parameters:
|
---|
45 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
46 | ; Returns:
|
---|
47 | ; BX:DX:AX: 48-bit sector count
|
---|
48 | ; Corrupts registers:
|
---|
49 | ; Nothing
|
---|
50 | ;--------------------------------------------------------------------
|
---|
51 | AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI:
|
---|
52 | mov bx, Registers_ExchangeDSSIwithESDI
|
---|
53 | call bx ; ATA info now in DS:DI
|
---|
54 | push bx ; We will return via Registers_ExchangeDSSIwithESDI
|
---|
55 | xor bx, bx
|
---|
56 | test BYTE [di+ATA1.wCaps+1], A1_wCaps_LBA>>8
|
---|
57 | jz SHORT .GetChsSectorCount
|
---|
58 | ; Fall to .GetLbaSectorCount
|
---|
59 |
|
---|
60 | ;--------------------------------------------------------------------
|
---|
61 | ; .GetLbaSectorCount
|
---|
62 | ; .GetLba28SectorCount
|
---|
63 | ; .GetChsSectorCount
|
---|
64 | ; Parameters:
|
---|
65 | ; BX: Zero
|
---|
66 | ; DS:DI: Ptr to 512-byte ATA information read from the drive
|
---|
67 | ; Returns:
|
---|
68 | ; BX:DX:AX: 48-bit sector count
|
---|
69 | ; Corrupts registers:
|
---|
70 | ; Nothing
|
---|
71 | ;--------------------------------------------------------------------
|
---|
72 | .GetLbaSectorCount:
|
---|
73 | test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
|
---|
74 | jz SHORT .GetLba28SectorCount
|
---|
75 | mov ax, [di+ATA6.qwLBACnt]
|
---|
76 | mov dx, [di+ATA6.qwLBACnt+2]
|
---|
77 | mov bx, [di+ATA6.qwLBACnt+4]
|
---|
78 | ret
|
---|
79 |
|
---|
80 | .GetLba28SectorCount:
|
---|
81 | mov ax, [di+ATA1.dwLBACnt]
|
---|
82 | mov dx, [di+ATA1.dwLBACnt+2]
|
---|
83 | ret
|
---|
84 |
|
---|
85 | .GetChsSectorCount:
|
---|
86 | mov al, [di+ATA1.wSPT] ; AL=Sectors per track
|
---|
87 | mul BYTE [di+ATA1.wHeadCnt] ; AX=Sectors per track * number of heads
|
---|
88 | mul WORD [di+ATA1.wCylCnt] ; DX:AX=Sectors per track * number of heads * number of cylinders
|
---|
89 | ret
|
---|
90 |
|
---|
91 |
|
---|
92 | %ifdef MODULE_ADVANCED_ATA
|
---|
93 | ;--------------------------------------------------------------------
|
---|
94 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
95 | ; Parameters:
|
---|
96 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
97 | ; Returns:
|
---|
98 | ; AL: Max supported PIO mode
|
---|
99 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
100 | ; CX: Minimum Cycle Time in nanosecs
|
---|
101 | ; Corrupts registers:
|
---|
102 | ; BX
|
---|
103 | ;--------------------------------------------------------------------
|
---|
104 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
105 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
106 | mov bx, [es:si+ATA1.bPioMode]
|
---|
107 | mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
108 | shl bx, 1 ; Shift for WORD lookup
|
---|
109 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
110 |
|
---|
111 | ; Check if IORDY is supported
|
---|
112 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
113 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
114 | mov ah, FLGH_DPT_IORDY
|
---|
115 |
|
---|
116 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
117 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
118 | jz SHORT .ReturnPioTimings
|
---|
119 |
|
---|
120 | ; Get Advanced PIO mode
|
---|
121 | ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
122 | mov bl, [es:si+ATA2.bPIOSupp]
|
---|
123 | .CheckNextFlag:
|
---|
124 | inc ax
|
---|
125 | shr bl, 1
|
---|
126 | jnz SHORT .CheckNextFlag
|
---|
127 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
128 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
129 | .ReturnPioTimings:
|
---|
130 | ret
|
---|
131 |
|
---|
132 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
133 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
134 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
135 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
136 |
|
---|
137 |
|
---|
138 | ;--------------------------------------------------------------------
|
---|
139 | ; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
|
---|
140 | ; Parameters:
|
---|
141 | ; BX: PIO Mode
|
---|
142 | ; CX: PIO Cycle Time in nanosecs
|
---|
143 | ; Returns:
|
---|
144 | ; AX: Active Time in nanosecs
|
---|
145 | ; Corrupts registers:
|
---|
146 | ; BX, CX
|
---|
147 | ;--------------------------------------------------------------------
|
---|
148 | AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
|
---|
149 | call AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
150 | mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
|
---|
151 | sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
|
---|
152 | sub cx, ax ; - Active Time (t2)
|
---|
153 | xchg ax, cx ; AX = Recovery Time (t2i)
|
---|
154 | ret
|
---|
155 |
|
---|
156 | .rgbPioModeToAddressValidTimeNs:
|
---|
157 | db PIO_0_MIN_ADDRESS_VALID_NS
|
---|
158 | db PIO_1_MIN_ADDRESS_VALID_NS
|
---|
159 | db PIO_2_MIN_ADDRESS_VALID_NS
|
---|
160 | db PIO_3_MIN_ADDRESS_VALID_NS
|
---|
161 | db PIO_4_MIN_ADDRESS_VALID_NS
|
---|
162 | db PIO_5_MIN_ADDRESS_VALID_NS
|
---|
163 | db PIO_6_MIN_ADDRESS_VALID_NS
|
---|
164 |
|
---|
165 |
|
---|
166 | ;--------------------------------------------------------------------
|
---|
167 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
168 | ; Parameters:
|
---|
169 | ; BX: PIO Mode
|
---|
170 | ; Returns:
|
---|
171 | ; AX: Active Time in nanosecs
|
---|
172 | ; Corrupts registers:
|
---|
173 | ; Nothing
|
---|
174 | ;--------------------------------------------------------------------
|
---|
175 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
176 | shl bx, 1
|
---|
177 | mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
|
---|
178 | shr bx, 1
|
---|
179 | ret
|
---|
180 |
|
---|
181 | .rgwPioModeToActiveTimeNs:
|
---|
182 | dw PIO_0_MIN_ACTIVE_TIME_NS
|
---|
183 | dw PIO_1_MIN_ACTIVE_TIME_NS
|
---|
184 | dw PIO_2_MIN_ACTIVE_TIME_NS
|
---|
185 | dw PIO_3_MIN_ACTIVE_TIME_NS
|
---|
186 | dw PIO_4_MIN_ACTIVE_TIME_NS
|
---|
187 | dw PIO_5_MIN_ACTIVE_TIME_NS
|
---|
188 | dw PIO_6_MIN_ACTIVE_TIME_NS
|
---|
189 |
|
---|
190 | %endif ; MODULE_ADVANCED_ATA
|
---|