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
|
---|
23 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
35 | CompatibleDPT_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
|
---|
66 | GetTemporaryBufferForDPTEtoESDI:
|
---|
67 | call GetBufferForDrive80hToESDI
|
---|
68 | add di, BYTE TRANSLATED_DPT_size * 2
|
---|
69 | ret
|
---|
70 | %endif
|
---|
71 |
|
---|
72 | GetBufferForDrive80hToESDI:
|
---|
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 | ;--------------------------------------------------------------------
|
---|
96 | FillToESDIusingDPTfromDSSI:
|
---|
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 | ;--------------------------------------------------------------------
|
---|
115 | FillTranslatedDPTtoESDIfromDPTinDSSI:
|
---|
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 | %ifndef USE_186
|
---|
142 | call StoswALandChecksumFromDL ; Bytes 14 (Logical sectors per track) and 15 (Checksum)
|
---|
143 | jmp SHORT FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
|
---|
144 | %else
|
---|
145 | push FillStandardDPTtoESDIfromDPTinDSSI.RestoreOffsetsAndReturn
|
---|
146 | ; Fall to StoswALandChecksumFromDL
|
---|
147 | %endif
|
---|
148 |
|
---|
149 |
|
---|
150 | ;--------------------------------------------------------------------
|
---|
151 | ; StoswALandChecksumFromDL
|
---|
152 | ; Parameters:
|
---|
153 | ; AL: Last byte to store before checksum byte
|
---|
154 | ; DL: Sum of bytes so far
|
---|
155 | ; ES:DI: Ptr to where to store AL and Checksum byte
|
---|
156 | ; Returns:
|
---|
157 | ; DL: Sum of bytes so far
|
---|
158 | ; DI: Incremented by 2
|
---|
159 | ; Corrupts registers:
|
---|
160 | ; Nothing
|
---|
161 | ;--------------------------------------------------------------------
|
---|
162 | StoswALandChecksumFromDL:
|
---|
163 | mov ah, al
|
---|
164 | add ah, dl
|
---|
165 | neg ah
|
---|
166 | stosw
|
---|
167 | ret
|
---|
168 |
|
---|
169 |
|
---|
170 | ;--------------------------------------------------------------------
|
---|
171 | ; FillStandardDPTtoESDIfromDPTinDSSI
|
---|
172 | ; Parameters:
|
---|
173 | ; AX: Number of Physical Cylinders == Number of Logical Cylinders
|
---|
174 | ; CL: Device Control Byte
|
---|
175 | ; DS:SI: Ptr to DPT
|
---|
176 | ; ES:DI: Ptr to destination buffer
|
---|
177 | ; Returns:
|
---|
178 | ; Nothing
|
---|
179 | ; Corrupts registers:
|
---|
180 | ; AX
|
---|
181 | ;--------------------------------------------------------------------
|
---|
182 | FillStandardDPTtoESDIfromDPTinDSSI:
|
---|
183 | stosw ; Bytes 0 and 1 (Physical number of cylinders)
|
---|
184 | eMOVZX ax, BYTE [si+DPT.bLchsHeads]
|
---|
185 | stosw ; Bytes 2 (Physical number of heads) and 3
|
---|
186 | mov al, ah ; Zero AX
|
---|
187 | stosw ; Bytes 4 and 5 (Write Precompensation Cylinder low)
|
---|
188 | stosw ; Bytes 6 (Write Precompensation Cylinder high) and 7
|
---|
189 | mov al, cl ; Device control byte to AL
|
---|
190 | stosw ; Bytes 8 (Drive Control Byte) and 9
|
---|
191 | mov al, ah ; Zero AX
|
---|
192 | stosw ; Bytes 10 and 11
|
---|
193 | stosw ; Bytes 12 and 13 (Landing Zone Cylinder)
|
---|
194 | mov al, [si+DPT.bLchsSectorsPerTrack]
|
---|
195 | stosw ; Bytes 14 (Physical sectors per track) and 15
|
---|
196 |
|
---|
197 | .RestoreOffsetsAndReturn:
|
---|
198 | sub di, BYTE STANDARD_DPT_size
|
---|
199 | ret
|
---|
200 |
|
---|
201 |
|
---|
202 | %ifdef MODULE_EBIOS
|
---|
203 | ;--------------------------------------------------------------------
|
---|
204 | ; CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI
|
---|
205 | ; Parameters:
|
---|
206 | ; DS:SI: Ptr to DPT (in RAMVARS segment)
|
---|
207 | ; Returns:
|
---|
208 | ; ES:BX: Ptr to Device Parameter Table Extension (DPTE)
|
---|
209 | ; Corrupts registers:
|
---|
210 | ; AX, CX, DX, DI
|
---|
211 | ;--------------------------------------------------------------------
|
---|
212 | CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI:
|
---|
213 | call GetTemporaryBufferForDPTEtoESDI ; valid until next AH=48h call
|
---|
214 |
|
---|
215 | ; Set 32-bit flag for 32-bit controllers
|
---|
216 | mov cx, FLG_LBA_TRANSLATION_ENABLED ; DPTE.wFlags
|
---|
217 | cmp BYTE [si+DPT_ATA.bDevice], DEVICE_32BIT_ATA
|
---|
218 | eCMOVE cl, FLG_LBA_TRANSLATION_ENABLED | FLG_32BIT_XFER_MODE
|
---|
219 |
|
---|
220 | ; DPTE.wBasePort
|
---|
221 | mov ax, [si+DPT.wBasePort]
|
---|
222 | call StoswThenAddALandAHtoDL ; Bytes 0 and 1
|
---|
223 |
|
---|
224 | ; DPTE.wControlBlockPort
|
---|
225 | eMOVZX bx, BYTE [si+DPT.bIdevarsOffset]
|
---|
226 | mov ax, [cs:bx+IDEVARS.wControlBlockPort]
|
---|
227 | call StoswThenAddALandAHtoDL ; Bytes 2 and 3
|
---|
228 |
|
---|
229 | ; DPTE.bDrvnhead and DPTE.bBiosVendor
|
---|
230 | xchg di, si
|
---|
231 | call AccessDPT_GetDriveSelectByteToAL
|
---|
232 | xchg si, di
|
---|
233 | call StoswThenAddALandAHtoDL ; Bytes 4 and 5
|
---|
234 |
|
---|
235 | ; DPTE.bIRQ and DPTE.bBlockSize
|
---|
236 | mov al, [cs:bx+IDEVARS.bIRQ] ; No way to define that we might not use IRQ
|
---|
237 | mov ah, [si+DPT_ATA.bBlockSize]
|
---|
238 | cmp ah, 1
|
---|
239 | jbe SHORT .DoNotSetBlockModeFlag
|
---|
240 | or cl, FLG_BLOCK_MODE_ENABLED
|
---|
241 | .DoNotSetBlockModeFlag:
|
---|
242 | call StoswThenAddALandAHtoDL ; Bytes 6 and 7
|
---|
243 |
|
---|
244 | ; DPTE.bDmaChannelAndType and DPTE.bPioMode
|
---|
245 | xor ax, ax
|
---|
246 | %ifdef MODULE_ADVANCED_ATA
|
---|
247 | or ah, [si+DPT_ADVANCED_ATA.bPioMode]
|
---|
248 | jz SHORT .DoNotSetFastPioFlag
|
---|
249 | cmp WORD [si+DPT_ADVANCED_ATA.wControllerID], BYTE 0
|
---|
250 | je SHORT .DoNotSetFastPioFlag
|
---|
251 | inc cx ; FLG_FAST_PIO_ENABLED
|
---|
252 | .DoNotSetFastPioFlag:
|
---|
253 | %endif
|
---|
254 | call StoswThenAddALandAHtoDL ; Bytes 8 and 9
|
---|
255 |
|
---|
256 | ; Set CHS translation flags and store DPTE.wFlags
|
---|
257 | mov al, [si+DPT.bFlagsLow]
|
---|
258 | and al, MASKL_DPT_TRANSLATEMODE
|
---|
259 | jz SHORT .NoChsTranslationOrBitShiftTranslationSet
|
---|
260 | or cl, FLG_CHS_TRANSLATION_ENABLED
|
---|
261 | test al, FLGL_DPT_ASSISTED_LBA
|
---|
262 | jz SHORT .NoChsTranslationOrBitShiftTranslationSet
|
---|
263 | or cx, LBA_ASSISTED_TRANSLATION << TRANSLATION_TYPE_FIELD_POSITION
|
---|
264 | .NoChsTranslationOrBitShiftTranslationSet:
|
---|
265 | xchg ax, cx
|
---|
266 | call StoswThenAddALandAHtoDL ; Bytes 10 and 11
|
---|
267 |
|
---|
268 | ; DPTE.wReserved (must be zero)
|
---|
269 | xor ax, ax
|
---|
270 | call StoswThenAddALandAHtoDL ; Bytes 12 and 13
|
---|
271 |
|
---|
272 | ; DPTE.bRevision and DPTE.bChecksum
|
---|
273 | mov al, DPTE_REVISION
|
---|
274 | call StoswALandChecksumFromDL ; Bytes 14 and 15
|
---|
275 | lea bx, [di-DPTE_size]
|
---|
276 | ret
|
---|
277 | %endif ; MODULE_EBIOS
|
---|
278 |
|
---|
279 |
|
---|
280 | ;--------------------------------------------------------------------
|
---|
281 | ; StoswThenAddALandAHtoDL
|
---|
282 | ; Parameters:
|
---|
283 | ; AX: WORD to store
|
---|
284 | ; DL: Sum of bytes so far
|
---|
285 | ; ES:DI: Ptr to where to store AX
|
---|
286 | ; Returns:
|
---|
287 | ; DL: Sum of bytes so far
|
---|
288 | ; DI: Incremented by 2
|
---|
289 | ; Corrupts registers:
|
---|
290 | ; Nothing
|
---|
291 | ;--------------------------------------------------------------------
|
---|
292 | StoswThenAddALandAHtoDL:
|
---|
293 | stosw
|
---|
294 | add dl, al
|
---|
295 | add dl, ah
|
---|
296 | ret
|
---|
297 |
|
---|