[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:
|
---|
[558] | 36 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 37 | ; CF: Cleared
|
---|
[3] | 38 | ; Corrupts registers:
|
---|
[542] | 39 | ; AX, BX, CX, DX
|
---|
[3] | 40 | ;--------------------------------------------------------------------
|
---|
| 41 | CreateDPT_FromAtaInformation:
|
---|
[150] | 42 | call FindDPT_ForNewDriveToDSDI
|
---|
[99] | 43 | ; Fall to .InitializeDPT
|
---|
[3] | 44 |
|
---|
| 45 | ;--------------------------------------------------------------------
|
---|
[99] | 46 | ; .InitializeDPT
|
---|
[3] | 47 | ; Parameters:
|
---|
| 48 | ; BH: Drive Select byte for Drive and Head Register
|
---|
[473] | 49 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[3] | 50 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 51 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 52 | ; Returns:
|
---|
[150] | 53 | ; Nothing
|
---|
[3] | 54 | ; Corrupts registers:
|
---|
[150] | 55 | ; AX
|
---|
[3] | 56 | ;--------------------------------------------------------------------
|
---|
[99] | 57 | .InitializeDPT:
|
---|
[473] | 58 | call CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
[150] | 59 | ; Fall to .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 60 |
|
---|
| 61 | ;--------------------------------------------------------------------
|
---|
[150] | 62 | ; .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 63 | ; Parameters:
|
---|
| 64 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 65 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 66 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 67 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 68 | ; Returns:
|
---|
[99] | 69 | ; Nothing
|
---|
[3] | 70 | ; Corrupts registers:
|
---|
| 71 | ; AX
|
---|
| 72 | ;--------------------------------------------------------------------
|
---|
[150] | 73 | .StoreDriveSelectAndDriveControlByte:
|
---|
| 74 | mov al, bh
|
---|
| 75 | and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
|
---|
[411] | 76 | %ifdef MODULE_IRQ
|
---|
[150] | 77 | cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
|
---|
| 78 | jz SHORT .StoreFlags ; If not, do not set interrupt flag
|
---|
[158] | 79 | or al, FLGL_DPT_ENABLE_IRQ
|
---|
[150] | 80 | .StoreFlags:
|
---|
[411] | 81 | %endif
|
---|
[150] | 82 | mov [di+DPT.wFlags], ax
|
---|
[421] | 83 | ; Fall to .StoreCHSparametersAndAddressingMode
|
---|
[3] | 84 |
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
[421] | 86 | ; .StoreCHSparametersAndAddressingMode
|
---|
[3] | 87 | ; Parameters:
|
---|
| 88 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 89 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 90 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 91 | ; Returns:
|
---|
[227] | 92 | ; Nothing
|
---|
[3] | 93 | ; Corrupts registers:
|
---|
[227] | 94 | ; AX, BX, CX, DX
|
---|
[3] | 95 | ;--------------------------------------------------------------------
|
---|
[421] | 96 | .StoreCHSparametersAndAddressingMode:
|
---|
[542] | 97 | ; Apply any user limited values to ATA ID
|
---|
| 98 | call AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
|
---|
[173] | 99 |
|
---|
[422] | 100 | ; Translate P-CHS to L-CHS
|
---|
[549] | 101 | call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIwithTranslateModeInDX
|
---|
[421] | 102 | mov [di+DPT.wLchsCylinders], ax
|
---|
| 103 | mov [di+DPT.wLchsHeadsAndSectors], bx
|
---|
[542] | 104 | mov al, dl
|
---|
| 105 | eSHL_IM al, TRANSLATEMODE_FIELD_POSITION
|
---|
| 106 | or cl, al
|
---|
[421] | 107 |
|
---|
[542] | 108 | ; Store P-CHS and flags
|
---|
[421] | 109 | call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
[547] | 110 | dec dl ; Set ZF if TRANSLATEMODE_LARGE, SF if TRANSLATEMODE_NORMAL
|
---|
[542] | 111 | js SHORT .NothingToChange
|
---|
| 112 | jz SHORT .LimitHeadsForLargeAddressingMode
|
---|
| 113 |
|
---|
[549] | 114 | ; Set LBA bit for Assisted LBA
|
---|
| 115 | or cl, FLGL_DPT_LBA
|
---|
[542] | 116 | jmp SHORT .NothingToChange
|
---|
[549] | 117 |
|
---|
[542] | 118 | .LimitHeadsForLargeAddressingMode:
|
---|
[549] | 119 | ; We cannot have 16 P-Heads heads in Revised ECHS mode (8193 or more cylinders)
|
---|
| 120 | ; but 16 heads are allowed when there are 8192 or less cylinders (ECHS).
|
---|
| 121 | ; Both of these are LARGE modes so do not confuse with NORMAL mode.
|
---|
| 122 | call AtaGeometry_IsDriveSmallEnoughForECHS
|
---|
| 123 | jc SHORT .NothingToChange
|
---|
| 124 | dec bx ; Adjust 16 P-Heads to 15
|
---|
| 125 |
|
---|
[542] | 126 | .NothingToChange:
|
---|
| 127 | or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode
|
---|
| 128 | mov [di+DPT.wPchsHeadsAndSectors], bx
|
---|
[550] | 129 | %ifdef MODULE_COMPATIBLE_TABLES OR MODULE_EBIOS
|
---|
[544] | 130 | ; Store P-Cylinders here for Compatible DPTs when FLGL_DPT_LBA is not set
|
---|
| 131 | ; or when drive has over 15,482,880 sectors
|
---|
| 132 | mov [di+DPT.wPchsCylinders], ax
|
---|
[550] | 133 | %endif
|
---|
| 134 |
|
---|
| 135 | %ifdef MODULE_EBIOS
|
---|
[542] | 136 | test cl, FLGL_DPT_LBA
|
---|
| 137 | jz SHORT .NoLbaSoNoEBIOS
|
---|
[533] | 138 |
|
---|
[542] | 139 | ; Store P-Cylinders but only if we have 15,482,880 or less sectors since
|
---|
| 140 | ; we only need P-Cylinders so we can return it from AH=48h
|
---|
| 141 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
[544] | 142 | sub ax, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) & 0FFFFh
|
---|
| 143 | sbb dx, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) >> 16
|
---|
[542] | 144 | sbb bx, BYTE 0
|
---|
[544] | 145 | jnc SHORT .StoreNumberOfLbaSectors
|
---|
[533] | 146 |
|
---|
[542] | 147 | ; Since we might have altered the default P-CHS parameters to be
|
---|
| 148 | ; presented to the drive (AH=09h), we need to calculate new
|
---|
| 149 | ; P-Cylinders. It could be read from the ATA ID after
|
---|
| 150 | ; COMMAND_INITIALIZE_DEVICE_PARAMETERS but that is too much trouble.
|
---|
| 151 | ; P-Cyls = MIN(16383*16*63, LBA sector count) / (P-Heads * P-Sectors per track)
|
---|
| 152 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
| 153 | xchg cx, ax ; Sector count to DX:CX
|
---|
| 154 | mov al, [di+DPT.bPchsHeads]
|
---|
| 155 | mul BYTE [di+DPT.bPchsSectorsPerTrack]
|
---|
| 156 | xchg cx, ax
|
---|
| 157 | div cx ; AX = new P-Cylinders
|
---|
[543] | 158 |
|
---|
| 159 | ; We could remove wPchsCylinders from DPT if we calculate it on AH=48h
|
---|
[544] | 160 | ; (and for compatible DPTs) but that would require extra code so we save ROM space instead.
|
---|
[421] | 161 | mov [di+DPT.wPchsCylinders], ax
|
---|
[542] | 162 |
|
---|
[543] | 163 | ; Store CHS sector count as total sector count. We must not use
|
---|
| 164 | ; LBA sector count if it is 15,482,880 or less.
|
---|
[542] | 165 | mul cx
|
---|
| 166 | xor bx, bx
|
---|
[543] | 167 | jmp SHORT .StoreTotalSectorsFromBXDXAX
|
---|
[421] | 168 |
|
---|
[558] | 169 |
|
---|
[421] | 170 | ;--------------------------------------------------------------------
|
---|
| 171 | ; .StoreNumberOfLbaSectors
|
---|
| 172 | ; Parameters:
|
---|
| 173 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 174 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 175 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 176 | ; Returns:
|
---|
| 177 | ; Nothing
|
---|
| 178 | ; Corrupts registers:
|
---|
| 179 | ; AX, BX, CX, DX
|
---|
| 180 | ;--------------------------------------------------------------------
|
---|
[542] | 181 | .StoreNumberOfLbaSectors:
|
---|
[421] | 182 | ; Store LBA 28/48 total sector count
|
---|
| 183 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
[543] | 184 | or [di+DPT.bFlagsLow], cl ; LBA48 flag
|
---|
| 185 | .StoreTotalSectorsFromBXDXAX:
|
---|
[542] | 186 | mov [di+DPT.twLbaSectors], ax
|
---|
| 187 | mov [di+DPT.twLbaSectors+2], dx
|
---|
| 188 | mov [di+DPT.twLbaSectors+4], bx
|
---|
| 189 | .NoLbaSoNoEBIOS:
|
---|
[421] | 190 | %endif ; MODULE_EBIOS
|
---|
[150] | 191 | ; Fall to .StoreDeviceSpecificParameters
|
---|
[3] | 192 |
|
---|
| 193 | ;--------------------------------------------------------------------
|
---|
[150] | 194 | ; .StoreDeviceSpecificParameters
|
---|
[3] | 195 | ; Parameters:
|
---|
| 196 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 197 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 198 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 199 | ; Returns:
|
---|
[99] | 200 | ; Nothing
|
---|
[3] | 201 | ; Corrupts registers:
|
---|
[150] | 202 | ; AX, BX, CX, DX
|
---|
[3] | 203 | ;--------------------------------------------------------------------
|
---|
[150] | 204 | .StoreDeviceSpecificParameters:
|
---|
| 205 | call Device_FinalizeDPT
|
---|
[258] | 206 |
|
---|
[262] | 207 | ;----------------------------------------------------------------------
|
---|
| 208 | ; Update drive counts (hard and floppy)
|
---|
[294] | 209 | ;----------------------------------------------------------------------
|
---|
[558] | 210 | %ifdef MODULE_SERIAL
|
---|
| 211 | ; Device_FinalizeDPT returns with CF set only when a floppy was found which can't happen without MODULE_SERIAL
|
---|
[258] | 212 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
| 213 | ;
|
---|
| 214 | ; These two instructions serve two purposes:
|
---|
| 215 | ; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
|
---|
[294] | 216 | ; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
|
---|
[258] | 217 | ; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
|
---|
[294] | 218 | ; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
|
---|
[258] | 219 | ; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
|
---|
[294] | 220 | ; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
|
---|
[258] | 221 | ; B. the auto serial code is always executed last
|
---|
| 222 | ; C. the serial server always returns floppy drives last
|
---|
| 223 | ;
|
---|
| 224 | adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
|
---|
[294] | 225 | jnz .AllDone
|
---|
[558] | 226 | %else ; ~MODULE_SERIAL_FLOPPY
|
---|
[258] | 227 | ;
|
---|
| 228 | ; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
|
---|
[294] | 229 | ; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
|
---|
[258] | 230 | ; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
|
---|
| 231 | ;
|
---|
| 232 | jc .AllDone
|
---|
[558] | 233 | %endif ; MODULE_SERIAL_FLOPPY
|
---|
| 234 | %endif ; MODULE_SERIAL
|
---|
[258] | 235 |
|
---|
[150] | 236 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
[294] | 237 |
|
---|
[558] | 238 | %ifdef MODULE_SERIAL
|
---|
[294] | 239 | .AllDone:
|
---|
[162] | 240 | clc
|
---|
[558] | 241 | %endif
|
---|
| 242 |
|
---|
[3] | 243 | ret
|
---|
[258] | 244 |
|
---|
[324] | 245 |
|
---|
[422] | 246 | ;--------------------------------------------------------------------
|
---|
[473] | 247 | ; CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI
|
---|
| 248 | ; Parameters:
|
---|
| 249 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
| 250 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 251 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 252 | ; Returns:
|
---|
| 253 | ; Nothing
|
---|
| 254 | ; Corrupts registers:
|
---|
| 255 | ; AX
|
---|
| 256 | ;--------------------------------------------------------------------
|
---|
| 257 | CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI:
|
---|
| 258 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
|
---|
| 259 | mov ax, [cs:bp+IDEVARS.wBasePort]
|
---|
| 260 | mov [di+DPT.wBasePort], ax
|
---|
| 261 | ret
|
---|