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

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

Changes to XTIDE Universal BIOS:

  • CREATE_COMPATIBLE_DPT is now MODULE_COMPATIBLE_TABLES.
  • DPTs pointed by INT 41h and INT 46h are now swapped when swapping drives 81h and 80h.
  • Block mode commands are no longer used when block size is set to 1 with AH=24h.
File size: 9.3 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;--------------------------------------------------------------------
65%ifdef MODULE_EBIOS
66GetTemporaryBufferForDPTEtoESDI:
67 call GetBufferForDrive80hToESDI
68 add di, BYTE TRANSLATED_DPT_size * 2
69 ret
70%endif
71
72GetBufferForDrive80hToESDI:
73 push ds
74 pop es
75 mov di, [cs:ROMVARS.bStealSize] ; No harm to read WORD
76 eSHL_IM di, 10 ; DI = RAMVARS size in bytes
77%ifdef MODULE_EBIOS
78 sub di, BYTE (TRANSLATED_DPT_size * 2) + DPTE_size
79%else
80 sub di, BYTE TRANSLATED_DPT_size * 2
81%endif
82 ret
83
84
85;--------------------------------------------------------------------
86; FillToESDIusingDPTfromDSSI
87; Parameters:
88; CL: Device Control Byte
89; DS:SI: Ptr to DPT
90; ES:DI Ptr to destination buffer
91; Returns:
92; Nothing
93; Corrupts registers:
94; AX, CX, DX
95;--------------------------------------------------------------------
96FillToESDIusingDPTfromDSSI:
97 mov ax, [si+DPT.wLchsCylinders]
98 call AH8h_LimitAXtoMaximumLCylinders
99 test BYTE [si+DPT.bFlagsLow], MASKL_DPT_TRANSLATEMODE
100 jz SHORT FillStandardDPTtoESDIfromDPTinDSSI
101 ; Fall to FillTranslatedDPTtoESDIfromDPTinDSSI
102
103;--------------------------------------------------------------------
104; FillTranslatedDPTtoESDIfromDPTinDSSI
105; Parameters:
106; AX: Number of Logical Cylinders
107; CL: Device Control Byte
108; DS:SI: Ptr to DPT
109; ES:DI: Ptr to destination buffer
110; Returns:
111; Nothing
112; Corrupts registers:
113; AX, CX, DX
114;--------------------------------------------------------------------
115FillTranslatedDPTtoESDIfromDPTinDSSI:
116 xor dx, dx ; Clear for checksum
117 call StoswThenAddALandAHtoDL ; Bytes 0 and 1 (Logical number of cylinders)
118
119 mov al, BYTE [si+DPT.bLchsHeads]
120 mov ah, TRANSLATED_DPT_SIGNATURE
121 call StoswThenAddALandAHtoDL ; Bytes 2 (Logical number of heads) and 3 (Axh signature to indicate Translated DPT)
122
123 eMOVZX ax, BYTE [si+DPT.bPchsSectorsPerTrack]
124 call StoswThenAddALandAHtoDL ; Bytes 4 (Physical sectors per track) and 5 (Write Precompensation Cylinder low)
125
126 mov al, ah
127 call StoswThenAddALandAHtoDL ; Bytes 6 (Write Precompensation Cylinder high) and 7
128
129 xchg ax, cx ; Device Control byte to AL
130 mov ah, [si+DPT.wPchsCylinders]
131 call StoswThenAddALandAHtoDL ; Bytes 8 (Drive Control Byte) and 9 (Physical number of cylinders low)
132
133 mov al, [si+DPT.wPchsCylinders+1]
134 mov ah, [si+DPT.bPchsHeads]
135 call StoswThenAddALandAHtoDL ; Bytes 10 (Physical number of cylinders high) and 11 (Physical number of heads)
136
137 xor ax, ax
138 call StoswThenAddALandAHtoDL ; Bytes 12 and 13 (Landing Zone Cylinder)
139
140 mov al, [si+DPT.bLchsSectorsPerTrack]
141%ifdef USE_186
142 push FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
143 jmp StoswALandChecksumFromDL ; Bytes 14 (Logical sectors per track) and 15 (Checksum)
144%else
145 call StoswALandChecksumFromDL
146 jmp SHORT FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
147%endif
148
149
150;--------------------------------------------------------------------
151; FillStandardDPTtoESDIfromDPTinDSSI
152; Parameters:
153; AX: Number of Physical Cylinders == Number of Logical Cylinders
154; CL: Device Control Byte
155; DS:SI: Ptr to DPT
156; ES:DI: Ptr to destination buffer
157; Returns:
158; Nothing
159; Corrupts registers:
160; AX
161;--------------------------------------------------------------------
162FillStandardDPTtoESDIfromDPTinDSSI:
163 stosw ; Bytes 0 and 1 (Physical number of cylinders)
164 eMOVZX ax, BYTE [si+DPT.bLchsHeads]
165 stosw ; Bytes 2 (Physical number of heads) and 3
166 mov al, ah ; Zero AX
167 stosw ; Bytes 4 and 5 (Write Precompensation Cylinder low)
168 stosw ; Bytes 6 (Write Precompensation Cylinder high) and 7
169 mov al, cl ; Device control byte to AL
170 stosw ; Bytes 8 (Drive Control Byte) and 9
171 mov al, ah ; Zero AX
172 stosw ; Bytes 10 and 11
173 stosw ; Bytes 12 and 13 (Landing Zone Cylinder)
174 mov al, [si+DPT.bLchsSectorsPerTrack]
175 stosw ; Bytes 14 (Physical sectors per track) and 15
176
177.RestoreOffsetsAndReturn:
178 sub di, BYTE STANDARD_DPT_size
179 ret
180
181
182%ifdef MODULE_EBIOS
183;--------------------------------------------------------------------
184; CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI
185; Parameters:
186; DS:SI: Ptr to DPT (in RAMVARS segment)
187; Returns:
188; ES:BX: Ptr to Device Parameter Table Extension (DPTE)
189; Corrupts registers:
190; AX, CX, DX, DI
191;--------------------------------------------------------------------
192CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI:
193 call GetTemporaryBufferForDPTEtoESDI ; valid until next AH=48h call
194
195 ; Set 32-bit flag for 32-bit controllers
196 mov cx, FLG_LBA_TRANSLATION_ENABLED ; DPTE.wFlags
197 cmp BYTE [si+DPT_ATA.bDevice], DEVICE_32BIT_ATA
198 eCMOVE cl, FLG_LBA_TRANSLATION_ENABLED | FLG_32BIT_XFER_MODE
199
200 ; DPTE.wBasePort
201 mov ax, [si+DPT.wBasePort]
202 call StoswThenAddALandAHtoDL ; Bytes 0 and 1
203
204 ; DPTE.wControlBlockPort
205 eMOVZX bx, BYTE [si+DPT.bIdevarsOffset]
206 mov ax, [cs:bx+IDEVARS.wControlBlockPort]
207 call StoswThenAddALandAHtoDL ; Bytes 2 and 3
208
209 ; DPTE.bDrvnhead and DPTE.bBiosVendor
210 xchg di, si
211 call AccessDPT_GetDriveSelectByteToAL
212 xchg si, di
213 call StoswThenAddALandAHtoDL ; Bytes 4 and 5
214
215 ; DPTE.bIRQ and DPTE.bBlockSize
216 mov al, [cs:bx+IDEVARS.bIRQ] ; No way to define that we might not use IRQ
217 mov ah, [si+DPT_ATA.bBlockSize]
218 cmp ah, 1
219 jbe SHORT .DoNotSetBlockModeFlag
220 or cl, FLG_BLOCK_MODE_ENABLED
221.DoNotSetBlockModeFlag:
222 call StoswThenAddALandAHtoDL ; Bytes 6 and 7
223
224 ; DPTE.bDmaChannelAndType and DPTE.bPioMode
225 xor ax, ax
226%ifdef MODULE_ADVANCED_ATA
227 or ah, [si+DPT_ADVANCED_ATA.bPioMode]
228 jz SHORT .NoDotSetFastPioFlag
229 cmp WORD [si+DPT_ADVANCED_ATA.wControllerID], BYTE 0
230 je SHORT .NoDotSetFastPioFlag
231 inc cx ; FLG_FAST_PIO_ENABLED
232.NoDotSetFastPioFlag:
233%endif
234 call StoswThenAddALandAHtoDL ; Bytes 8 and 9
235
236 ; Set CHS translation flags and store DPTE.wFlags
237 mov al, [si+DPT.bFlagsLow]
238 and al, MASKL_DPT_TRANSLATEMODE
239 jz SHORT .NoChsTranslationOrBitShiftTranslationSet
240 or cl, FLG_CHS_TRANSLATION_ENABLED
241 test al, FLGL_DPT_ASSISTED_LBA
242 jz SHORT .NoChsTranslationOrBitShiftTranslationSet
243 or cx, LBA_ASSISTED_TRANSLATION << TRANSLATION_TYPE_FIELD_POSITION
244.NoChsTranslationOrBitShiftTranslationSet:
245 xchg ax, cx
246 call StoswThenAddALandAHtoDL ; Bytes 10 and 11
247
248 ; DPTE.wReserved (must be zero)
249 xor ax, ax
250 call StoswThenAddALandAHtoDL ; Bytes 12 and 13
251
252 ; DPTE.bRevision and DPTE.bChecksum
253 mov al, DPTE_REVISION
254 call StoswALandChecksumFromDL ; Bytes 14 and 15
255 lea bx, [di-DPTE_size]
256 ret
257%endif ; MODULE_EBIOS
258
259
260;--------------------------------------------------------------------
261; StoswThenAddALandAHtoDL
262; Parameters:
263; AX: WORD to store
264; DL: Sum of bytes so far
265; ES:DI: Ptr to where to store AX
266; Returns:
267; DL: Sum of bytes so far
268; DI: Incremented by 2
269; Corrupts registers:
270; Nothing
271;--------------------------------------------------------------------
272StoswThenAddALandAHtoDL:
273 stosw
274 add dl, al
275 add dl, ah
276 ret
277
278
279;--------------------------------------------------------------------
280; StoswALandChecksumFromDL
281; Parameters:
282; AL: Last byte to store before checksum byte
283; DL: Sum of bytes so far
284; ES:DI: Ptr to where to store AL and Checksum byte
285; Returns:
286; DL: Sum of bytes so far
287; DI: Incremented by 2
288; Corrupts registers:
289; Nothing
290;--------------------------------------------------------------------
291StoswALandChecksumFromDL:
292 mov ah, al
293 add ah, dl
294 neg ah
295 stosw
296 ret
Note: See TracBrowser for help on using the repository browser.