source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm@ 547

Last change on this file since 547 was 543, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Compatible DPTs can no longer have more than 1024 cylinders.
File size: 9.2 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Functions to handle DPT structs to present drive geometry
3; to ill behaving applications that want
4; to read DPT from interrupt vectors 41h and 46h.
5
6;
7; XTIDE Universal BIOS and Associated Tools
8; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
9;
10; This program is free software; you can redistribute it and/or modify
11; it under the terms of the GNU General Public License as published by
12; the Free Software Foundation; either version 2 of the License, or
13; (at your option) any later version.
14;
15; This program is distributed in the hope that it will be useful,
16; but WITHOUT ANY WARRANTY; without even the implied warranty of
17; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18; GNU General Public License for more details.
19; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20;
21
22; Section containing code
23SECTION .text
24
25;--------------------------------------------------------------------
26; CompatibleDPT_CreateToAXSIforDriveDL
27; Parameters:
28; DL: Drive number (80h or 81h)
29; DS:DI: Ptr to DPT
30; Returns:
31; AX:SI Ptr to destination buffer
32; Corrupts registers:
33; CX, DX
34;--------------------------------------------------------------------
35CompatibleDPT_CreateToAXSIforDriveDL:
36 push es
37
38 call AccessDPT_GetDeviceControlByteToAL
39 xchg cx, ax ; Device control byte to CL
40 mov si, di ; DPT now in DS:SI
41 call GetBufferForDrive80hToESDI
42 shr dx, 1
43 jnc SHORT .BufferLoadedToESDI
44 add di, BYTE TRANSLATED_DPT_size ; For drive 81h
45.BufferLoadedToESDI:
46
47 call FillToESDIusingDPTfromDSSI
48 xchg di, si
49 mov ax, es
50
51 pop es
52 ret
53
54
55;--------------------------------------------------------------------
56; GetTemporaryBufferForDPTEtoESDI
57; GetBufferForDrive80hToESDI
58; Parameters:
59; DS: RAMVARS segment
60; Returns:
61; ES:DI: Ptr to buffer (in RAMVARS segment)
62; Corrupts registers:
63; Nothing
64;--------------------------------------------------------------------
65GetTemporaryBufferForDPTEtoESDI:
66 call GetBufferForDrive80hToESDI
67 add di, BYTE TRANSLATED_DPT_size * 2
68 ret
69
70GetBufferForDrive80hToESDI:
71 push ds
72 pop es
73 mov di, [cs:ROMVARS.bStealSize] ; No harm to read WORD
74 eSHL_IM di, 10 ; DI = RAMVARS size in bytes
75 sub di, BYTE (TRANSLATED_DPT_size * 2) + DPTE_size
76 ret
77
78
79;--------------------------------------------------------------------
80; FillToESDIusingDPTfromDSSI
81; Parameters:
82; CL: Device Control Byte
83; DS:SI: Ptr to DPT
84; ES:DI Ptr to destination buffer
85; Returns:
86; Nothing
87; Corrupts registers:
88; AX, CX, DX
89;--------------------------------------------------------------------
90FillToESDIusingDPTfromDSSI:
91 mov ax, [si+DPT.wLchsCylinders]
92 call AH8h_LimitAXtoMaximumLCylinders
93 test BYTE [si+DPT.bFlagsLow], MASKL_DPT_TRANSLATEMODE
94 jz SHORT FillStandardDPTtoESDIfromDPTinDSSI
95 ; Fall to FillTranslatedDPTtoESDIfromDPTinDSSI
96
97;--------------------------------------------------------------------
98; FillTranslatedDPTtoESDIfromDPTinDSSI
99; Parameters:
100; AX: Number of Logical Cylinders
101; CL: Device Control Byte
102; DS:SI: Ptr to DPT
103; ES:DI: Ptr to destination buffer
104; Returns:
105; Nothing
106; Corrupts registers:
107; AX, CX, DX
108;--------------------------------------------------------------------
109FillTranslatedDPTtoESDIfromDPTinDSSI:
110 xor dx, dx ; Clear for checksum
111 call StoswThenAddALandAHtoDL ; Bytes 0 and 1 (Logical number of cylinders)
112
113 mov al, BYTE [si+DPT.bLchsHeads]
114 mov ah, TRANSLATED_DPT_SIGNATURE
115 call StoswThenAddALandAHtoDL ; Bytes 2 (Logical number of heads) and 3 (Axh signature to indicate Translated DPT)
116
117 eMOVZX ax, BYTE [si+DPT.bPchsSectorsPerTrack]
118 call StoswThenAddALandAHtoDL ; Bytes 4 (Physical sectors per track) and 5 (Write Precompensation Cylinder low)
119
120 mov al, ah
121 call StoswThenAddALandAHtoDL ; Bytes 6 (Write Precompensation Cylinder high) and 7
122
123 xchg ax, cx ; Device Control byte to AL
124 mov ah, [si+DPT.wPchsCylinders]
125 call StoswThenAddALandAHtoDL ; Bytes 8 (Drive Control Byte) and 9 (Physical number of cylinders low)
126
127 mov al, [si+DPT.wPchsCylinders+1]
128 mov ah, [si+DPT.bPchsHeads]
129 call StoswThenAddALandAHtoDL ; Bytes 10 (Physical number of cylinders high) and 11 (Physical number of heads)
130
131 xor ax, ax
132 call StoswThenAddALandAHtoDL ; Bytes 12 and 13 (Landing Zone Cylinder)
133
134 mov al, [si+DPT.bLchsSectorsPerTrack]
135%ifdef USE_186
136 push FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
137 jmp StoswALandChecksumFromDL ; Bytes 14 (Logical sectors per track) and 15 (Checksum)
138%else
139 call StoswALandChecksumFromDL
140 jmp SHORT FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
141%endif
142
143
144;--------------------------------------------------------------------
145; FillStandardDPTtoESDIfromDPTinDSSI
146; Parameters:
147; AX: Number of Physical Cylinders == Number of Logical Cylinders
148; CL: Device Control Byte
149; DS:SI: Ptr to DPT
150; ES:DI: Ptr to destination buffer
151; Returns:
152; Nothing
153; Corrupts registers:
154; AX
155;--------------------------------------------------------------------
156FillStandardDPTtoESDIfromDPTinDSSI:
157 stosw ; Bytes 0 and 1 (Physical number of cylinders)
158 eMOVZX ax, BYTE [si+DPT.bLchsHeads]
159 stosw ; Bytes 2 (Physical number of heads) and 3
160 mov al, ah ; Zero AX
161 stosw ; Bytes 4 and 5 (Write Precompensation Cylinder low)
162 stosw ; Bytes 6 (Write Precompensation Cylinder high) and 7
163 mov al, cl ; Device control byte to AL
164 stosw ; Bytes 8 (Drive Control Byte) and 9
165 mov al, ah ; Zero AX
166 stosw ; Bytes 10 and 11
167 stosw ; Bytes 12 and 13 (Landing Zone Cylinder)
168 mov al, [si+DPT.bLchsSectorsPerTrack]
169 stosw ; Bytes 14 (Physical sectors per track) and 15
170
171.RestoreOffsetsAndReturn:
172 sub di, BYTE STANDARD_DPT_size
173 ret
174
175
176;--------------------------------------------------------------------
177; CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI
178; Parameters:
179; DS:SI: Ptr to DPT (in RAMVARS segment)
180; Returns:
181; ES:BX: Ptr to Device Parameter Table Extension (DPTE)
182; Corrupts registers:
183; AX, CX, DX, DI
184;--------------------------------------------------------------------
185CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI:
186 call GetTemporaryBufferForDPTEtoESDI ; valid until next AH=48h call
187
188 ; Set 32-bit flag for 32-bit controllers
189 mov cx, FLG_LBA_TRANSLATION_ENABLED ; DPTE.wFlags
190 cmp BYTE [si+DPT_ATA.bDevice], DEVICE_32BIT_ATA
191 eCMOVE cl, FLG_LBA_TRANSLATION_ENABLED | FLG_32BIT_XFER_MODE
192
193 ; DPTE.wBasePort
194 mov ax, [si+DPT.wBasePort]
195 call StoswThenAddALandAHtoDL ; Bytes 0 and 1
196
197 ; DPTE.wControlBlockPort
198 eMOVZX bx, BYTE [si+DPT.bIdevarsOffset]
199 mov ax, [cs:bx+IDEVARS.wControlBlockPort]
200 call StoswThenAddALandAHtoDL ; Bytes 2 and 3
201
202 ; DPTE.bDrvnhead and DPTE.bBiosVendor
203 xchg di, si
204 call AccessDPT_GetDriveSelectByteToAL
205 xchg si, di
206 call StoswThenAddALandAHtoDL ; Bytes 4 and 5
207
208 ; DPTE.bIRQ and DPTE.bBlockSize
209 mov al, [cs:bx+IDEVARS.bIRQ] ; No way to define that we might not use IRQ
210 mov ah, [si+DPT_ATA.bBlockSize]
211 cmp ah, 1
212 jbe SHORT .DoNotSetBlockModeFlag
213 or cl, FLG_BLOCK_MODE_ENABLED
214.DoNotSetBlockModeFlag:
215 call StoswThenAddALandAHtoDL ; Bytes 6 and 7
216
217 ; DPTE.bDmaChannelAndType and DPTE.bPioMode
218 xor ax, ax
219%ifdef MODULE_ADVANCED_ATA
220 or ah, [si+DPT_ADVANCED_ATA.bPioMode]
221 jz SHORT .NoDotSetFastPioFlag
222 cmp WORD [si+DPT_ADVANCED_ATA.wControllerID], BYTE 0
223 je SHORT .NoDotSetFastPioFlag
224 inc cx ; FLG_FAST_PIO_ENABLED
225.NoDotSetFastPioFlag:
226%endif
227 call StoswThenAddALandAHtoDL ; Bytes 8 and 9
228
229 ; Set CHS translation flags and store DPTE.wFlags
230 mov al, [si+DPT.bFlagsLow]
231 and al, MASKL_DPT_TRANSLATEMODE
232 jz SHORT .NoChsTranslationOrBitShiftTranslationSet
233 or cl, FLG_CHS_TRANSLATION_ENABLED
234 test al, FLGL_DPT_ASSISTED_LBA
235 jz SHORT .NoChsTranslationOrBitShiftTranslationSet
236 or cx, LBA_ASSISTED_TRANSLATION << TRANSLATION_TYPE_FIELD_POSITION
237.NoChsTranslationOrBitShiftTranslationSet:
238 xchg ax, cx
239 call StoswThenAddALandAHtoDL ; Bytes 10 and 11
240
241 ; DPTE.wReserved (must be zero)
242 xor ax, ax
243 call StoswThenAddALandAHtoDL ; Bytes 12 and 13
244
245 ; DPTE.bRevision and DPTE.bChecksum
246 mov al, DPTE_REVISION
247 call StoswALandChecksumFromDL ; Bytes 14 and 15
248 lea bx, [di-DPTE_size]
249 ret
250
251
252;--------------------------------------------------------------------
253; StoswThenAddALandAHtoDL
254; Parameters:
255; AX: WORD to store
256; DL: Sum of bytes so far
257; ES:DI: Ptr to where to store AX
258; Returns:
259; DL: Sum of bytes so far
260; DI: Incremented by 2
261; Corrupts registers:
262; Nothing
263;--------------------------------------------------------------------
264StoswThenAddALandAHtoDL:
265 stosw
266 add dl, al
267 add dl, ah
268 ret
269
270
271;--------------------------------------------------------------------
272; StoswALandChecksumFromDL
273; Parameters:
274; AL: Last byte to store before checksum byte
275; DL: Sum of bytes so far
276; ES:DI: Ptr to where to store AL and Checksum byte
277; Returns:
278; DL: Sum of bytes so far
279; DI: Incremented by 2
280; Corrupts registers:
281; Nothing
282;--------------------------------------------------------------------
283StoswALandChecksumFromDL:
284 mov ah, al
285 add ah, dl
286 neg ah
287 stosw
288 ret
Note: See TracBrowser for help on using the repository browser.