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

Last change on this file since 418 was 411, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Moved some IRQ and LBA48 code to related modules.
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:
[411]73%ifdef MODULE_EBIOS
[173]74 test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
[3]75 jz SHORT .GetLba28SectorCount
[411]76
77 ; Get LBA48 sector count
[173]78 mov ax, [di+ATA6.qwLBACnt]
79 mov dx, [di+ATA6.qwLBACnt+2]
80 mov bx, [di+ATA6.qwLBACnt+4]
[181]81 ret
[411]82%endif
[173]83
[3]84.GetLba28SectorCount:
[173]85 mov ax, [di+ATA1.dwLBACnt]
86 mov dx, [di+ATA1.dwLBACnt+2]
[181]87 ret
[3]88
[99]89.GetChsSectorCount:
[173]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
[181]93 ret
[363]94
95
96%ifdef MODULE_ADVANCED_ATA
97;--------------------------------------------------------------------
[364]98; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
[363]99; Parameters:
100; ES:SI: Ptr to 512-byte ATA information read from the drive
101; Returns:
[364]102; AL: Max supported PIO mode
103; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
104; CX: Minimum Cycle Time in nanosecs
[363]105; Corrupts registers:
106; BX
107;--------------------------------------------------------------------
[364]108AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
[363]109 ; Get PIO mode and cycle time for PIO 0...2
110 mov bx, [es:si+ATA1.bPioMode]
[370]111 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
[363]112 shl bx, 1 ; Shift for WORD lookup
[364]113 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
[363]114
[364]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
[363]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
[364]125 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
[370]126 mov bl, [es:si+ATA2.bPIOSupp]
[363]127.CheckNextFlag:
128 inc ax
[370]129 shr bl, 1
[363]130 jnz SHORT .CheckNextFlag
[364]131 MIN_U al, 6 ; Make sure not above lookup tables
132 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
[363]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;--------------------------------------------------------------------
[364]143; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
[363]144; Parameters:
[364]145; BX: PIO Mode
146; CX: PIO Cycle Time in nanosecs
[363]147; Returns:
[364]148; AX: Active Time in nanosecs
[363]149; Corrupts registers:
[364]150; BX, CX
[363]151;--------------------------------------------------------------------
[364]152AtaID_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)
[363]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
[364]166 db PIO_5_MIN_ADDRESS_VALID_NS
167 db PIO_6_MIN_ADDRESS_VALID_NS
[363]168
[364]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;--------------------------------------------------------------------
179AtaID_GetActiveTimeToAXfromPioModeInBX:
180 shl bx, 1
181 mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
182 shr bx, 1
183 ret
184
[363]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
[364]191 dw PIO_5_MIN_ACTIVE_TIME_NS
192 dw PIO_6_MIN_ACTIVE_TIME_NS
[363]193
194%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.