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

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

Changes to XTIDE Universal BIOS:

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