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