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 | %ifdef MODULE_EBIOS
|
---|
74 | test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
|
---|
75 | jz SHORT .GetLba28SectorCount
|
---|
76 |
|
---|
77 | ; Get LBA48 sector count
|
---|
78 | mov ax, [di+ATA6.qwLBACnt]
|
---|
79 | mov dx, [di+ATA6.qwLBACnt+2]
|
---|
80 | mov bx, [di+ATA6.qwLBACnt+4]
|
---|
81 | ret
|
---|
82 | %endif
|
---|
83 |
|
---|
84 | .GetLba28SectorCount:
|
---|
85 | mov ax, [di+ATA1.dwLBACnt]
|
---|
86 | mov dx, [di+ATA1.dwLBACnt+2]
|
---|
87 | ret
|
---|
88 |
|
---|
89 | .GetChsSectorCount:
|
---|
90 | mov al, [di+ATA1.wSPT] ; AL=Sectors per track
|
---|
91 | mul BYTE [di+ATA1.wHeadCnt] ; AX=Sectors per track * number of heads
|
---|
92 | mul WORD [di+ATA1.wCylCnt] ; DX:AX=Sectors per track * number of heads * number of cylinders
|
---|
93 | ret
|
---|
94 |
|
---|
95 |
|
---|
96 | %ifdef MODULE_ADVANCED_ATA
|
---|
97 | ;--------------------------------------------------------------------
|
---|
98 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
99 | ; Parameters:
|
---|
100 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
101 | ; Returns:
|
---|
102 | ; AL: Max supported PIO mode
|
---|
103 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
104 | ; CX: Minimum Cycle Time in nanosecs
|
---|
105 | ; Corrupts registers:
|
---|
106 | ; BX
|
---|
107 | ;--------------------------------------------------------------------
|
---|
108 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
109 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
110 | mov bx, [es:si+ATA1.bPioMode]
|
---|
111 | mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
112 | shl bx, 1 ; Shift for WORD lookup
|
---|
113 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
114 |
|
---|
115 | ; Check if IORDY is supported
|
---|
116 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
117 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
118 | mov ah, FLGH_DPT_IORDY
|
---|
119 |
|
---|
120 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
121 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
122 | jz SHORT .ReturnPioTimings
|
---|
123 |
|
---|
124 | ; Get Advanced PIO mode
|
---|
125 | ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
126 | mov bl, [es:si+ATA2.bPIOSupp]
|
---|
127 | .CheckNextFlag:
|
---|
128 | inc ax
|
---|
129 | shr bl, 1
|
---|
130 | jnz SHORT .CheckNextFlag
|
---|
131 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
132 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
133 | .ReturnPioTimings:
|
---|
134 | ret
|
---|
135 |
|
---|
136 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
137 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
138 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
139 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
140 |
|
---|
141 |
|
---|
142 | ;--------------------------------------------------------------------
|
---|
143 | ; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
|
---|
144 | ; Parameters:
|
---|
145 | ; BX: PIO Mode
|
---|
146 | ; CX: PIO Cycle Time in nanosecs
|
---|
147 | ; Returns:
|
---|
148 | ; AX: Active Time in nanosecs
|
---|
149 | ; Corrupts registers:
|
---|
150 | ; BX, CX
|
---|
151 | ;--------------------------------------------------------------------
|
---|
152 | AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
|
---|
153 | call AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
154 | mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
|
---|
155 | sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
|
---|
156 | sub cx, ax ; - Active Time (t2)
|
---|
157 | xchg ax, cx ; AX = Recovery Time (t2i)
|
---|
158 | ret
|
---|
159 |
|
---|
160 | .rgbPioModeToAddressValidTimeNs:
|
---|
161 | db PIO_0_MIN_ADDRESS_VALID_NS
|
---|
162 | db PIO_1_MIN_ADDRESS_VALID_NS
|
---|
163 | db PIO_2_MIN_ADDRESS_VALID_NS
|
---|
164 | db PIO_3_MIN_ADDRESS_VALID_NS
|
---|
165 | db PIO_4_MIN_ADDRESS_VALID_NS
|
---|
166 | db PIO_5_MIN_ADDRESS_VALID_NS
|
---|
167 | db PIO_6_MIN_ADDRESS_VALID_NS
|
---|
168 |
|
---|
169 |
|
---|
170 | ;--------------------------------------------------------------------
|
---|
171 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
172 | ; Parameters:
|
---|
173 | ; BX: PIO Mode
|
---|
174 | ; Returns:
|
---|
175 | ; AX: Active Time in nanosecs
|
---|
176 | ; Corrupts registers:
|
---|
177 | ; Nothing
|
---|
178 | ;--------------------------------------------------------------------
|
---|
179 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
180 | shl bx, 1
|
---|
181 | mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
|
---|
182 | shr bx, 1
|
---|
183 | ret
|
---|
184 |
|
---|
185 | .rgwPioModeToActiveTimeNs:
|
---|
186 | dw PIO_0_MIN_ACTIVE_TIME_NS
|
---|
187 | dw PIO_1_MIN_ACTIVE_TIME_NS
|
---|
188 | dw PIO_2_MIN_ACTIVE_TIME_NS
|
---|
189 | dw PIO_3_MIN_ACTIVE_TIME_NS
|
---|
190 | dw PIO_4_MIN_ACTIVE_TIME_NS
|
---|
191 | dw PIO_5_MIN_ACTIVE_TIME_NS
|
---|
192 | dw PIO_6_MIN_ACTIVE_TIME_NS
|
---|
193 |
|
---|
194 | %endif ; MODULE_ADVANCED_ATA
|
---|