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

Last change on this file since 378 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 6.2 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;
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
[3]21; Section containing code
22SECTION .text
23
24;--------------------------------------------------------------------
[169]25; AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
[3]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
[99]30; BH: Number of user specified P-CHS sectors per track
31; BL: Number of user specified P-CHS heads
[3]32; Corrupts registers:
33; Nothing
34;--------------------------------------------------------------------
[169]35AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI:
[3]36 mov ax, [es:si+ATA1.wCylCnt] ; Cylinders (1...16383)
[99]37 mov bl, [es:si+ATA1.wHeadCnt] ; Heads (1...16)
38 mov bh, [es:si+ATA1.wSPT] ; Sectors per Track (1...63)
[3]39 ret
40
41
42;--------------------------------------------------------------------
[165]43; AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
[3]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;--------------------------------------------------------------------
[165]51AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI:
[181]52 mov bx, Registers_ExchangeDSSIwithESDI
53 call bx ; ATA info now in DS:DI
54 push bx ; We will return via Registers_ExchangeDSSIwithESDI
[3]55 xor bx, bx
[173]56 test BYTE [di+ATA1.wCaps+1], A1_wCaps_LBA>>8
[99]57 jz SHORT .GetChsSectorCount
58 ; Fall to .GetLbaSectorCount
[3]59
60;--------------------------------------------------------------------
[99]61; .GetLbaSectorCount
[173]62; .GetLba28SectorCount
63; .GetChsSectorCount
[3]64; Parameters:
65; BX: Zero
[181]66; DS:DI: Ptr to 512-byte ATA information read from the drive
[3]67; Returns:
68; BX:DX:AX: 48-bit sector count
69; Corrupts registers:
70; Nothing
71;--------------------------------------------------------------------
[99]72.GetLbaSectorCount:
[173]73 test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
[3]74 jz SHORT .GetLba28SectorCount
[173]75 mov ax, [di+ATA6.qwLBACnt]
76 mov dx, [di+ATA6.qwLBACnt+2]
77 mov bx, [di+ATA6.qwLBACnt+4]
[181]78 ret
[173]79
[3]80.GetLba28SectorCount:
[173]81 mov ax, [di+ATA1.dwLBACnt]
82 mov dx, [di+ATA1.dwLBACnt+2]
[181]83 ret
[3]84
[99]85.GetChsSectorCount:
[173]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
[181]89 ret
[363]90
91
92%ifdef MODULE_ADVANCED_ATA
93;--------------------------------------------------------------------
[364]94; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
[363]95; Parameters:
96; ES:SI: Ptr to 512-byte ATA information read from the drive
97; Returns:
[364]98; AL: Max supported PIO mode
99; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
100; CX: Minimum Cycle Time in nanosecs
[363]101; Corrupts registers:
102; BX
103;--------------------------------------------------------------------
[364]104AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
[363]105 ; Get PIO mode and cycle time for PIO 0...2
106 mov bx, [es:si+ATA1.bPioMode]
[370]107 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
[363]108 shl bx, 1 ; Shift for WORD lookup
[364]109 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
[363]110
[364]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
[363]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
[364]121 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
[370]122 mov bl, [es:si+ATA2.bPIOSupp]
[363]123.CheckNextFlag:
124 inc ax
[370]125 shr bl, 1
[363]126 jnz SHORT .CheckNextFlag
[364]127 MIN_U al, 6 ; Make sure not above lookup tables
128 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
[363]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;--------------------------------------------------------------------
[364]139; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
[363]140; Parameters:
[364]141; BX: PIO Mode
142; CX: PIO Cycle Time in nanosecs
[363]143; Returns:
[364]144; AX: Active Time in nanosecs
[363]145; Corrupts registers:
[364]146; BX, CX
[363]147;--------------------------------------------------------------------
[364]148AtaID_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)
[363]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
[364]162 db PIO_5_MIN_ADDRESS_VALID_NS
163 db PIO_6_MIN_ADDRESS_VALID_NS
[363]164
[364]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;--------------------------------------------------------------------
175AtaID_GetActiveTimeToAXfromPioModeInBX:
176 shl bx, 1
177 mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
178 shr bx, 1
179 ret
180
[363]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
[364]187 dw PIO_5_MIN_ACTIVE_TIME_NS
188 dw PIO_6_MIN_ACTIVE_TIME_NS
[363]189
190%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.