[99] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for creating Disk Parameter Table.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[445] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[445] | 12 | ;
|
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[445] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[445] | 18 | ;
|
---|
[376] | 19 |
|
---|
[3] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; Creates new Disk Parameter Table for detected hard disk.
|
---|
| 25 | ; Drive is then fully accessible using any BIOS function.
|
---|
| 26 | ;
|
---|
| 27 | ; CreateDPT_FromAtaInformation
|
---|
| 28 | ; Parameters:
|
---|
| 29 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 30 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 31 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 32 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 33 | ; DS: RAMVARS segment
|
---|
| 34 | ; ES: BDA Segment
|
---|
| 35 | ; Returns:
|
---|
[294] | 36 | ; DS:DI: Ptr to Disk Parameter Table (if successful)
|
---|
[3] | 37 | ; CF: Cleared if DPT created successfully
|
---|
| 38 | ; Set if any error
|
---|
| 39 | ; Corrupts registers:
|
---|
[99] | 40 | ; AX, BX, CX, DH
|
---|
[3] | 41 | ;--------------------------------------------------------------------
|
---|
| 42 | CreateDPT_FromAtaInformation:
|
---|
[150] | 43 | call FindDPT_ForNewDriveToDSDI
|
---|
[99] | 44 | ; Fall to .InitializeDPT
|
---|
[3] | 45 |
|
---|
| 46 | ;--------------------------------------------------------------------
|
---|
[99] | 47 | ; .InitializeDPT
|
---|
[3] | 48 | ; Parameters:
|
---|
| 49 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 50 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 51 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 52 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 53 | ; Returns:
|
---|
[150] | 54 | ; Nothing
|
---|
[3] | 55 | ; Corrupts registers:
|
---|
[150] | 56 | ; AX
|
---|
[3] | 57 | ;--------------------------------------------------------------------
|
---|
[99] | 58 | .InitializeDPT:
|
---|
[473] | 59 | call CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
[150] | 60 | ; Fall to .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 61 |
|
---|
| 62 | ;--------------------------------------------------------------------
|
---|
[150] | 63 | ; .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 64 | ; Parameters:
|
---|
| 65 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 66 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 67 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 68 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 69 | ; Returns:
|
---|
[99] | 70 | ; Nothing
|
---|
[3] | 71 | ; Corrupts registers:
|
---|
| 72 | ; AX
|
---|
| 73 | ;--------------------------------------------------------------------
|
---|
[150] | 74 | .StoreDriveSelectAndDriveControlByte:
|
---|
| 75 | mov al, bh
|
---|
| 76 | and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
|
---|
[411] | 77 | %ifdef MODULE_IRQ
|
---|
[150] | 78 | cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
|
---|
| 79 | jz SHORT .StoreFlags ; If not, do not set interrupt flag
|
---|
[158] | 80 | or al, FLGL_DPT_ENABLE_IRQ
|
---|
[150] | 81 | .StoreFlags:
|
---|
[411] | 82 | %endif
|
---|
[150] | 83 | mov [di+DPT.wFlags], ax
|
---|
[421] | 84 | ; Fall to .StoreCHSparametersAndAddressingMode
|
---|
[3] | 85 |
|
---|
| 86 | ;--------------------------------------------------------------------
|
---|
[421] | 87 | ; .StoreCHSparametersAndAddressingMode
|
---|
[3] | 88 | ; Parameters:
|
---|
| 89 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 90 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 91 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 92 | ; Returns:
|
---|
[227] | 93 | ; Nothing
|
---|
[3] | 94 | ; Corrupts registers:
|
---|
[227] | 95 | ; AX, BX, CX, DX
|
---|
[3] | 96 | ;--------------------------------------------------------------------
|
---|
[421] | 97 | .StoreCHSparametersAndAddressingMode:
|
---|
[173] | 98 | ; Check if CHS defined in ROMVARS
|
---|
[422] | 99 | call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
|
---|
| 100 | test cl, FLG_DRVPARAMS_USERCHS
|
---|
[421] | 101 | jz SHORT .AutodetectPCHSvalues
|
---|
[173] | 102 |
|
---|
[422] | 103 | ; Translate P-CHS to L-CHS
|
---|
| 104 | call AtaGeometry_GetLCHStoAXBLBHfromPCHSinAXBLBHandTranslateModeInDX
|
---|
[421] | 105 | jmp SHORT .StoreLCHStoDPT
|
---|
| 106 | .AutodetectPCHSvalues:
|
---|
[422] | 107 | call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIandTranslateModeInDX
|
---|
[421] | 108 |
|
---|
| 109 | .StoreLCHStoDPT:
|
---|
[422] | 110 | eSHL_IM dl, TRANSLATEMODE_FIELD_POSITION
|
---|
[421] | 111 | or cl, dl
|
---|
| 112 | or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
|
---|
| 113 | mov [di+DPT.wLchsCylinders], ax
|
---|
| 114 | mov [di+DPT.wLchsHeadsAndSectors], bx
|
---|
| 115 |
|
---|
| 116 | ; Store P-CHS to DPT
|
---|
| 117 | call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
| 118 | mov [di+DPT.bPchsHeads], bl
|
---|
| 119 | %ifdef MODULE_EBIOS
|
---|
[533] | 120 | mov [di+DPT.bPchsSectorsPerTrack], bh
|
---|
| 121 |
|
---|
[535] | 122 | ; This is what Award BIOS from 1997 Pentium motherboard does. I can't think
|
---|
| 123 | ; of any good reason to do the same but let's keep this here just in case,
|
---|
| 124 | ; at least for a while.
|
---|
| 125 | %if 0
|
---|
[533] | 126 | %ifdef RESERVE_DIAGNOSTIC_CYLINDER
|
---|
| 127 | ; Do not store P-Cylinders, instead calculate it from L-CHS total sector count.
|
---|
| 128 | ; Read AH=48h_GetExtendedDriveParameters.asm for more info.
|
---|
| 129 | xchg ax, bx
|
---|
| 130 | mul ah
|
---|
| 131 | push ax ; P-Heads * P-Sectors per track
|
---|
| 132 | call AH15h_GetSectorCountToBXDXAX
|
---|
| 133 | pop bx
|
---|
| 134 | div bx ; AX = Calculated cylinders
|
---|
| 135 | %endif ; RESERVE_DIAGNOSTIC_CYLINDER
|
---|
[535] | 136 | %endif ; 0
|
---|
[533] | 137 |
|
---|
[421] | 138 | mov [di+DPT.wPchsCylinders], ax
|
---|
| 139 | ; Fall to .StoreNumberOfLbaSectors
|
---|
| 140 |
|
---|
| 141 | ;--------------------------------------------------------------------
|
---|
| 142 | ; .StoreNumberOfLbaSectors
|
---|
| 143 | ; Parameters:
|
---|
| 144 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 145 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 146 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 147 | ; Returns:
|
---|
| 148 | ; Nothing
|
---|
| 149 | ; Corrupts registers:
|
---|
| 150 | ; AX, BX, CX, DX
|
---|
| 151 | ;--------------------------------------------------------------------
|
---|
[173] | 152 | ; Check if LBA supported
|
---|
| 153 | test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
|
---|
[421] | 154 | jz SHORT .NoLbaSupportedSoNoEBIOS
|
---|
[3] | 155 |
|
---|
[421] | 156 | ; Store LBA 28/48 total sector count
|
---|
| 157 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
| 158 | call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
|
---|
[324] | 159 |
|
---|
[533] | 160 | ; If we have 15,482,880 or less sectors, we multiply P-CHS values
|
---|
| 161 | ; and use that as total sector count.
|
---|
| 162 | ; Read AH=48h_GetExtendedDriveParameters.asm for more info.
|
---|
| 163 | sub ax, 4001h
|
---|
| 164 | sbb dx, 0ECh
|
---|
| 165 | sbb bx, BYTE 0
|
---|
| 166 | jnc SHORT .NoNeedToUseCHSsectorCount ; More than EC4000h
|
---|
| 167 |
|
---|
| 168 | mov al, [di+DPT.bPchsHeads]
|
---|
| 169 | mul BYTE [di+DPT.bPchsSectorsPerTrack]
|
---|
| 170 | mul WORD [di+DPT.wPchsCylinders]
|
---|
| 171 | xor bx, bx
|
---|
| 172 | call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
|
---|
| 173 |
|
---|
[421] | 174 | ; Load user defined LBA
|
---|
[533] | 175 | .NoNeedToUseCHSsectorCount:
|
---|
[422] | 176 | call GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
|
---|
| 177 | test cl, FLG_DRVPARAMS_USERLBA
|
---|
[324] | 178 | jz SHORT .KeepTotalSectorsFromAtaID
|
---|
| 179 |
|
---|
| 180 | ; Compare user defined and ATA-ID sector count and select smaller
|
---|
[445] | 181 | mov dx, bx
|
---|
| 182 | xor bx, bx ; User defined LBA now in BX:DX:AX
|
---|
[324] | 183 | cmp bx, [di+DPT.twLbaSectors+4]
|
---|
| 184 | jb SHORT .StoreUserDefinedSectorCountToDPT
|
---|
| 185 | cmp dx, [di+DPT.twLbaSectors+2]
|
---|
| 186 | jb SHORT .StoreUserDefinedSectorCountToDPT
|
---|
| 187 | ja SHORT .KeepTotalSectorsFromAtaID
|
---|
| 188 | cmp ax, [di+DPT.twLbaSectors]
|
---|
| 189 | jae SHORT .KeepTotalSectorsFromAtaID
|
---|
| 190 | .StoreUserDefinedSectorCountToDPT:
|
---|
[422] | 191 | ; CL bit FLGL_DPT_LBA48 is clear at this point
|
---|
[421] | 192 | call StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
|
---|
[324] | 193 |
|
---|
| 194 | .KeepTotalSectorsFromAtaID:
|
---|
[421] | 195 | .NoLbaSupportedSoNoEBIOS:
|
---|
| 196 | %endif ; MODULE_EBIOS
|
---|
[99] | 197 | ; Fall to .StoreBlockMode
|
---|
[3] | 198 |
|
---|
| 199 | ;--------------------------------------------------------------------
|
---|
[99] | 200 | ; .StoreBlockMode
|
---|
[3] | 201 | ; Parameters:
|
---|
| 202 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 203 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 204 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 205 | ; Returns:
|
---|
[99] | 206 | ; Nothing
|
---|
[3] | 207 | ; Corrupts registers:
|
---|
[150] | 208 | ; Nothing
|
---|
[3] | 209 | ;--------------------------------------------------------------------
|
---|
[99] | 210 | .StoreBlockMode:
|
---|
[150] | 211 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
|
---|
| 212 | jbe SHORT .BlockModeTransfersNotSupported
|
---|
[158] | 213 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
|
---|
[150] | 214 | .BlockModeTransfersNotSupported:
|
---|
| 215 | ; Fall to .StoreDeviceSpecificParameters
|
---|
[3] | 216 |
|
---|
| 217 | ;--------------------------------------------------------------------
|
---|
[150] | 218 | ; .StoreDeviceSpecificParameters
|
---|
[3] | 219 | ; Parameters:
|
---|
| 220 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 221 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 222 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 223 | ; Returns:
|
---|
[99] | 224 | ; Nothing
|
---|
[3] | 225 | ; Corrupts registers:
|
---|
[150] | 226 | ; AX, BX, CX, DX
|
---|
[3] | 227 | ;--------------------------------------------------------------------
|
---|
[150] | 228 | .StoreDeviceSpecificParameters:
|
---|
| 229 | call Device_FinalizeDPT
|
---|
[258] | 230 |
|
---|
[262] | 231 | ;----------------------------------------------------------------------
|
---|
| 232 | ; Update drive counts (hard and floppy)
|
---|
[294] | 233 | ;----------------------------------------------------------------------
|
---|
| 234 |
|
---|
[258] | 235 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
| 236 | ;
|
---|
| 237 | ; These two instructions serve two purposes:
|
---|
| 238 | ; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
|
---|
[294] | 239 | ; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
|
---|
[258] | 240 | ; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
|
---|
[294] | 241 | ; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
|
---|
[258] | 242 | ; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
|
---|
[294] | 243 | ; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
|
---|
[258] | 244 | ; B. the auto serial code is always executed last
|
---|
| 245 | ; C. the serial server always returns floppy drives last
|
---|
| 246 | ;
|
---|
| 247 | adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
|
---|
[294] | 248 | jnz .AllDone
|
---|
[258] | 249 | %else
|
---|
| 250 | ;
|
---|
| 251 | ; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
|
---|
[294] | 252 | ; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
|
---|
[258] | 253 | ; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
|
---|
| 254 | ;
|
---|
| 255 | jc .AllDone
|
---|
| 256 | %endif
|
---|
| 257 |
|
---|
[150] | 258 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
[294] | 259 |
|
---|
| 260 | .AllDone:
|
---|
[162] | 261 | clc
|
---|
[3] | 262 | ret
|
---|
[258] | 263 |
|
---|
[324] | 264 |
|
---|
[422] | 265 | ;--------------------------------------------------------------------
|
---|
[473] | 266 | ; CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
| 267 | ; Parameters:
|
---|
| 268 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
| 269 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 270 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 271 | ; Returns:
|
---|
| 272 | ; Nothing
|
---|
| 273 | ; Corrupts registers:
|
---|
| 274 | ; AX
|
---|
| 275 | ;--------------------------------------------------------------------
|
---|
| 276 | CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI:
|
---|
| 277 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
|
---|
| 278 |
|
---|
[493] | 279 | %ifdef MODULE_8BIT_IDE_ADVANCED
|
---|
[473] | 280 | call DetectDrives_DoesIdevarsInCSBPbelongToXTCF
|
---|
| 281 | jne SHORT .DeviceUsesPortSpecifiedInIDEVARS
|
---|
| 282 | mov [di+DPT.wBasePort], dx
|
---|
| 283 | ret
|
---|
| 284 | .DeviceUsesPortSpecifiedInIDEVARS:
|
---|
[493] | 285 | %endif ; MODULE_8BIT_IDE_ADVANCED
|
---|
[473] | 286 |
|
---|
| 287 | mov ax, [cs:bp+IDEVARS.wBasePort]
|
---|
| 288 | mov [di+DPT.wBasePort], ax
|
---|
| 289 | ret
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | ;--------------------------------------------------------------------
|
---|
[422] | 293 | ; GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS
|
---|
| 294 | ; Parameters:
|
---|
| 295 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 296 | ; Returns:
|
---|
| 297 | ; AX: User defined P-CHS Cylinders or LBA low word
|
---|
| 298 | ; BX: User defined P-CHS Heads and Sectors or LBA high word
|
---|
| 299 | ; DX: Translate mode or TRANSLATEMODE_AUTO
|
---|
| 300 | ; CX: FLG_DRVPARAMS_USERCHS if user defined CHS in BX:AX
|
---|
| 301 | ; FLG_DRVPARAMS_USERLBA if user defined LBA in BX:AX
|
---|
| 302 | ; Zero if user has not defined capacity
|
---|
| 303 | ; Corrupts registers:
|
---|
| 304 | ; Nothing
|
---|
| 305 | ;--------------------------------------------------------------------
|
---|
| 306 | GetUserDefinedCapacityToBXAXandFlagsToCXandModeToDXfromROMVARS:
|
---|
| 307 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 308 |
|
---|
| 309 | ; Get settings
|
---|
| 310 | mov cx, [cs:bx+DRVPARAMS.wFlags]
|
---|
| 311 | mov dx, cx
|
---|
| 312 | and cx, BYTE FLG_DRVPARAMS_USERCHS | FLG_DRVPARAMS_USERLBA
|
---|
| 313 | and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
|
---|
| 314 | eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
|
---|
| 315 |
|
---|
| 316 | ; Get capacity
|
---|
| 317 | mov ax, [cs:bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
|
---|
| 318 | mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
|
---|
| 319 | ret
|
---|
| 320 |
|
---|
| 321 |
|
---|
[421] | 322 | %ifdef MODULE_EBIOS
|
---|
[324] | 323 | ;--------------------------------------------------------------------
|
---|
[421] | 324 | ; StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX
|
---|
[324] | 325 | ; Parameters:
|
---|
| 326 | ; BX:DX:AX: Total Sector Count
|
---|
[421] | 327 | ; CL: FLGL_DPT_LBA48 if LBA48 supported
|
---|
[324] | 328 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 329 | ; Returns:
|
---|
| 330 | ; Nothing
|
---|
| 331 | ; Corrupts registers:
|
---|
[421] | 332 | ; CL
|
---|
[324] | 333 | ;--------------------------------------------------------------------
|
---|
[421] | 334 | StoreLba48AddressingFromCLandTotalSectorCountFromBXDXAX:
|
---|
| 335 | or cl, FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
|
---|
| 336 | and BYTE [di+DPT.bFlagsLow], ~FLGL_DPT_LBA48
|
---|
| 337 | or [di+DPT.bFlagsLow], cl
|
---|
[324] | 338 | mov [di+DPT.twLbaSectors], ax
|
---|
| 339 | mov [di+DPT.twLbaSectors+2], dx
|
---|
| 340 | mov [di+DPT.twLbaSectors+4], bx
|
---|
| 341 | ret
|
---|
[421] | 342 | %endif ; MODULE_EBIOS
|
---|