[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: |
---|
[542] | 40 | ; AX, BX, CX, DX |
---|
[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: |
---|
[542] | 98 | ; Apply any user limited values to ATA ID |
---|
| 99 | call AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX |
---|
[173] | 100 | |
---|
[422] | 101 | ; Translate P-CHS to L-CHS |
---|
| 102 | call AtaGeometry_GetLCHStoAXBLBHfromAtaInfoInESSIandTranslateModeInDX |
---|
[421] | 103 | mov [di+DPT.wLchsCylinders], ax |
---|
| 104 | mov [di+DPT.wLchsHeadsAndSectors], bx |
---|
[542] | 105 | mov al, dl |
---|
| 106 | eSHL_IM al, TRANSLATEMODE_FIELD_POSITION |
---|
| 107 | or cl, al |
---|
[421] | 108 | |
---|
[542] | 109 | ; Store P-CHS and flags |
---|
[421] | 110 | call AtaGeometry_GetPCHStoAXBLBHfromAtaInfoInESSI |
---|
[542] | 111 | dec dx ; Set ZF if TRANSLATEMODE_LARGE, SF if TRANSLATEMODE_NORMAL |
---|
| 112 | js SHORT .NothingToChange |
---|
| 113 | jz SHORT .LimitHeadsForLargeAddressingMode |
---|
| 114 | |
---|
| 115 | or cl, FLGL_DPT_LBA ; Set LBA bit for Assisted LBA |
---|
| 116 | jmp SHORT .NothingToChange |
---|
| 117 | .LimitHeadsForLargeAddressingMode: |
---|
| 118 | MIN_U bl, 15 ; Cannot have 16 P-Heads in LARGE addressing mode |
---|
| 119 | .NothingToChange: |
---|
| 120 | or [di+DPT.bFlagsLow], cl ; Shift count and addressing mode |
---|
| 121 | mov [di+DPT.wPchsHeadsAndSectors], bx |
---|
| 122 | |
---|
[421] | 123 | %ifdef MODULE_EBIOS |
---|
[544] | 124 | %ifdef CREATE_COMPATIBLE_DPT |
---|
| 125 | ; Store P-Cylinders here for Compatible DPTs when FLGL_DPT_LBA is not set |
---|
| 126 | ; or when drive has over 15,482,880 sectors |
---|
| 127 | mov [di+DPT.wPchsCylinders], ax |
---|
| 128 | %endif |
---|
[542] | 129 | test cl, FLGL_DPT_LBA |
---|
| 130 | jz SHORT .NoLbaSoNoEBIOS |
---|
[533] | 131 | |
---|
[542] | 132 | ; Store P-Cylinders but only if we have 15,482,880 or less sectors since |
---|
| 133 | ; we only need P-Cylinders so we can return it from AH=48h |
---|
| 134 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI |
---|
[544] | 135 | sub ax, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) & 0FFFFh |
---|
| 136 | sbb dx, (MAX_SECTOR_COUNT_TO_RETURN_PCHS+1) >> 16 |
---|
[542] | 137 | sbb bx, BYTE 0 |
---|
[544] | 138 | jnc SHORT .StoreNumberOfLbaSectors |
---|
[533] | 139 | |
---|
[542] | 140 | ; Since we might have altered the default P-CHS parameters to be |
---|
| 141 | ; presented to the drive (AH=09h), we need to calculate new |
---|
| 142 | ; P-Cylinders. It could be read from the ATA ID after |
---|
| 143 | ; COMMAND_INITIALIZE_DEVICE_PARAMETERS but that is too much trouble. |
---|
| 144 | ; P-Cyls = MIN(16383*16*63, LBA sector count) / (P-Heads * P-Sectors per track) |
---|
| 145 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI |
---|
| 146 | xchg cx, ax ; Sector count to DX:CX |
---|
| 147 | mov al, [di+DPT.bPchsHeads] |
---|
| 148 | mul BYTE [di+DPT.bPchsSectorsPerTrack] |
---|
| 149 | xchg cx, ax |
---|
| 150 | div cx ; AX = new P-Cylinders |
---|
[543] | 151 | |
---|
| 152 | ; We could remove wPchsCylinders from DPT if we calculate it on AH=48h |
---|
[544] | 153 | ; (and for compatible DPTs) but that would require extra code so we save ROM space instead. |
---|
[421] | 154 | mov [di+DPT.wPchsCylinders], ax |
---|
[542] | 155 | |
---|
[543] | 156 | ; Store CHS sector count as total sector count. We must not use |
---|
| 157 | ; LBA sector count if it is 15,482,880 or less. |
---|
[542] | 158 | mul cx |
---|
| 159 | xor bx, bx |
---|
[543] | 160 | jmp SHORT .StoreTotalSectorsFromBXDXAX |
---|
[421] | 161 | ; Fall to .StoreNumberOfLbaSectors |
---|
| 162 | |
---|
| 163 | ;-------------------------------------------------------------------- |
---|
| 164 | ; .StoreNumberOfLbaSectors |
---|
| 165 | ; Parameters: |
---|
| 166 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 167 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
| 168 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
| 169 | ; Returns: |
---|
| 170 | ; Nothing |
---|
| 171 | ; Corrupts registers: |
---|
| 172 | ; AX, BX, CX, DX |
---|
| 173 | ;-------------------------------------------------------------------- |
---|
[542] | 174 | .StoreNumberOfLbaSectors: |
---|
[421] | 175 | ; Store LBA 28/48 total sector count |
---|
| 176 | call AtaGeometry_GetLbaSectorCountToBXDXAXfromAtaInfoInESSI |
---|
[543] | 177 | or [di+DPT.bFlagsLow], cl ; LBA48 flag |
---|
| 178 | .StoreTotalSectorsFromBXDXAX: |
---|
[542] | 179 | mov [di+DPT.twLbaSectors], ax |
---|
| 180 | mov [di+DPT.twLbaSectors+2], dx |
---|
| 181 | mov [di+DPT.twLbaSectors+4], bx |
---|
| 182 | .NoLbaSoNoEBIOS: |
---|
[421] | 183 | %endif ; MODULE_EBIOS |
---|
[99] | 184 | ; Fall to .StoreBlockMode |
---|
[3] | 185 | |
---|
| 186 | ;-------------------------------------------------------------------- |
---|
[99] | 187 | ; .StoreBlockMode |
---|
[3] | 188 | ; Parameters: |
---|
| 189 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 190 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 191 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 192 | ; Returns: |
---|
[99] | 193 | ; Nothing |
---|
[3] | 194 | ; Corrupts registers: |
---|
[150] | 195 | ; Nothing |
---|
[3] | 196 | ;-------------------------------------------------------------------- |
---|
[99] | 197 | .StoreBlockMode: |
---|
[150] | 198 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors |
---|
| 199 | jbe SHORT .BlockModeTransfersNotSupported |
---|
[158] | 200 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED |
---|
[150] | 201 | .BlockModeTransfersNotSupported: |
---|
| 202 | ; Fall to .StoreDeviceSpecificParameters |
---|
[3] | 203 | |
---|
| 204 | ;-------------------------------------------------------------------- |
---|
[150] | 205 | ; .StoreDeviceSpecificParameters |
---|
[3] | 206 | ; Parameters: |
---|
| 207 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 208 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 209 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 210 | ; Returns: |
---|
[99] | 211 | ; Nothing |
---|
[3] | 212 | ; Corrupts registers: |
---|
[150] | 213 | ; AX, BX, CX, DX |
---|
[3] | 214 | ;-------------------------------------------------------------------- |
---|
[150] | 215 | .StoreDeviceSpecificParameters: |
---|
| 216 | call Device_FinalizeDPT |
---|
[258] | 217 | |
---|
[262] | 218 | ;---------------------------------------------------------------------- |
---|
| 219 | ; Update drive counts (hard and floppy) |
---|
[294] | 220 | ;---------------------------------------------------------------------- |
---|
| 221 | |
---|
[258] | 222 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 223 | ; |
---|
| 224 | ; These two instructions serve two purposes: |
---|
| 225 | ; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter. |
---|
[294] | 226 | ; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is |
---|
[258] | 227 | ; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below). |
---|
[294] | 228 | ; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT, |
---|
[258] | 229 | ; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons: |
---|
[294] | 230 | ; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list |
---|
[258] | 231 | ; B. the auto serial code is always executed last |
---|
| 232 | ; C. the serial server always returns floppy drives last |
---|
| 233 | ; |
---|
| 234 | adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0 |
---|
[294] | 235 | jnz .AllDone |
---|
[258] | 236 | %else |
---|
| 237 | ; |
---|
| 238 | ; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which |
---|
[294] | 239 | ; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that |
---|
[258] | 240 | ; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan. |
---|
| 241 | ; |
---|
| 242 | jc .AllDone |
---|
| 243 | %endif |
---|
| 244 | |
---|
[150] | 245 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS |
---|
[294] | 246 | |
---|
| 247 | .AllDone: |
---|
[162] | 248 | clc |
---|
[3] | 249 | ret |
---|
[258] | 250 | |
---|
[324] | 251 | |
---|
[422] | 252 | ;-------------------------------------------------------------------- |
---|
[473] | 253 | ; CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI |
---|
| 254 | ; Parameters: |
---|
| 255 | ; DX: Autodetected port (for devices that support autodetection) |
---|
| 256 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 257 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
| 258 | ; Returns: |
---|
| 259 | ; Nothing |
---|
| 260 | ; Corrupts registers: |
---|
| 261 | ; AX |
---|
| 262 | ;-------------------------------------------------------------------- |
---|
| 263 | CreateDPT_StoreIdevarsOffsetAndBasePortFromCSBPtoDPTinDSDI: |
---|
| 264 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM |
---|
| 265 | |
---|
[493] | 266 | %ifdef MODULE_8BIT_IDE_ADVANCED |
---|
[473] | 267 | call DetectDrives_DoesIdevarsInCSBPbelongToXTCF |
---|
| 268 | jne SHORT .DeviceUsesPortSpecifiedInIDEVARS |
---|
| 269 | mov [di+DPT.wBasePort], dx |
---|
| 270 | ret |
---|
| 271 | .DeviceUsesPortSpecifiedInIDEVARS: |
---|
[493] | 272 | %endif ; MODULE_8BIT_IDE_ADVANCED |
---|
[473] | 273 | |
---|
| 274 | mov ax, [cs:bp+IDEVARS.wBasePort] |
---|
| 275 | mov [di+DPT.wBasePort], ax |
---|
| 276 | ret |
---|