[99] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for creating Disk Parameter Table.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 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.
|
---|
| 12 | ;
|
---|
| 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
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
| 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
|
---|
| 30 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 31 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 32 | ; DS: RAMVARS segment
|
---|
| 33 | ; ES: BDA Segment
|
---|
| 34 | ; Returns:
|
---|
| 35 | ; DL: Drive number for new drive
|
---|
[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
|
---|
| 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:
|
---|
[150] | 58 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
|
---|
| 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
|
---|
| 76 | cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
|
---|
| 77 | jz SHORT .StoreFlags ; If not, do not set interrupt flag
|
---|
[158] | 78 | or al, FLGL_DPT_ENABLE_IRQ
|
---|
[150] | 79 | .StoreFlags:
|
---|
| 80 | mov [di+DPT.wFlags], ax
|
---|
[173] | 81 | ; Fall to .StoreAddressing
|
---|
[3] | 82 |
|
---|
| 83 | ;--------------------------------------------------------------------
|
---|
[173] | 84 | ; .StoreAddressing
|
---|
[3] | 85 | ; Parameters:
|
---|
| 86 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 87 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 88 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 89 | ; Returns:
|
---|
[227] | 90 | ; Nothing
|
---|
[3] | 91 | ; Corrupts registers:
|
---|
[227] | 92 | ; AX, BX, CX, DX
|
---|
[3] | 93 | ;--------------------------------------------------------------------
|
---|
[173] | 94 | .StoreAddressing:
|
---|
| 95 | ; Check if CHS defined in ROMVARS
|
---|
[193] | 96 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 97 | test byte [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified CHS?
|
---|
[227] | 98 | jnz SHORT .StoreUserDefinedPCHS
|
---|
[173] | 99 |
|
---|
| 100 | ; Check if LBA supported
|
---|
[169] | 101 | call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
[173] | 102 | test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8
|
---|
[227] | 103 | jz SHORT .StoreCHSfromAXBHBL ; Small old drive with CHS addressing only
|
---|
[3] | 104 |
|
---|
[324] | 105 | ; Store LBA 28/48 addressing and total sector count
|
---|
[173] | 106 | call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
[324] | 107 | call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
|
---|
| 108 |
|
---|
| 109 | ; Replace sector count with user defined if necessary
|
---|
| 110 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 111 | test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERLBA
|
---|
| 112 | jz SHORT .KeepTotalSectorsFromAtaID
|
---|
| 113 | mov ax, [cs:bx+DRVPARAMS.dwMaximumLBA]
|
---|
| 114 | mov dx, [cs:bx+DRVPARAMS.dwMaximumLBA+2]
|
---|
| 115 | xor bx, bx
|
---|
| 116 |
|
---|
| 117 | ; Compare user defined and ATA-ID sector count and select smaller
|
---|
| 118 | cmp bx, [di+DPT.twLbaSectors+4]
|
---|
| 119 | jb SHORT .StoreUserDefinedSectorCountToDPT
|
---|
| 120 | cmp dx, [di+DPT.twLbaSectors+2]
|
---|
| 121 | jb SHORT .StoreUserDefinedSectorCountToDPT
|
---|
| 122 | ja SHORT .KeepTotalSectorsFromAtaID
|
---|
| 123 | cmp ax, [di+DPT.twLbaSectors]
|
---|
| 124 | jae SHORT .KeepTotalSectorsFromAtaID
|
---|
| 125 | .StoreUserDefinedSectorCountToDPT:
|
---|
| 126 | call StoreLbaAddressingAndTotalSectorCountFromBXDXAX
|
---|
| 127 |
|
---|
| 128 | ; Calculate L-CHS for old INT 13h
|
---|
| 129 | .KeepTotalSectorsFromAtaID:
|
---|
| 130 | mov bx, [di+DPT.twLbaSectors+4] ; Restore BX
|
---|
[358] | 131 | call LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH
|
---|
[227] | 132 | mov [di+DPT.bLbaHeads], bl
|
---|
| 133 | jmp SHORT .StoreBlockMode
|
---|
[173] | 134 |
|
---|
[227] | 135 | ;--------------------------------------------------------------------
|
---|
| 136 | ; .StoreUserDefinedPCHS
|
---|
| 137 | ; Parameters:
|
---|
| 138 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 139 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 140 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 141 | ; Returns:
|
---|
| 142 | ; AX: Number of P-CHS cylinders
|
---|
| 143 | ; BH: Number of P-CHS sectors per track
|
---|
| 144 | ; BL: Number of P-CHS heads
|
---|
| 145 | ; Corrupts registers:
|
---|
| 146 | ; Nothing
|
---|
| 147 | ;--------------------------------------------------------------------
|
---|
| 148 | .StoreUserDefinedPCHS:
|
---|
[3] | 149 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 150 | mov ax, [cs:bx+DRVPARAMS.wCylinders]
|
---|
[99] | 151 | mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
|
---|
[227] | 152 | ; Fall to .StoreCHSfromAXBHBL
|
---|
[3] | 153 |
|
---|
[227] | 154 | ;--------------------------------------------------------------------
|
---|
| 155 | ; .StoreCHSfromAXBHBL
|
---|
| 156 | ; Parameters:
|
---|
| 157 | ; AX: Number of P-CHS cylinders
|
---|
| 158 | ; BH: Number of P-CHS sectors per track
|
---|
| 159 | ; BL: Number of P-CHS heads
|
---|
| 160 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 161 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 162 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 163 | ; Returns:
|
---|
| 164 | ; AX: Number of P-CHS cylinders
|
---|
| 165 | ; BH: Number of P-CHS sectors per track
|
---|
| 166 | ; BL: Number of P-CHS heads
|
---|
| 167 | ; Corrupts registers:
|
---|
| 168 | ; CX
|
---|
| 169 | ;--------------------------------------------------------------------
|
---|
| 170 | .StoreCHSfromAXBHBL:
|
---|
[173] | 171 | push ax
|
---|
[227] | 172 | push bx
|
---|
| 173 | call AccessDPT_ShiftPCHinAXBLtoLCH ; Get number of bits to shift
|
---|
| 174 | pop bx
|
---|
[173] | 175 | pop ax
|
---|
[227] | 176 | jcxz .StorePCHSfromAXDX ; Small drive so use L-CHS addressing
|
---|
[3] | 177 |
|
---|
[227] | 178 | ; Store P-CHS addressing mode and number of bits to shift in L-CHS to P-CHS translation
|
---|
| 179 | or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
|
---|
| 180 | or [di+DPT.bFlagsLow], cl
|
---|
| 181 | ; Fall to .StoreChsFromAXBLBH
|
---|
| 182 |
|
---|
[3] | 183 | ;--------------------------------------------------------------------
|
---|
[227] | 184 | ; .StoreChsFromAXBLBH
|
---|
[3] | 185 | ; Parameters:
|
---|
[227] | 186 | ; AX: Number of P-CHS cylinders
|
---|
| 187 | ; BH: Number of P-CHS sectors per track
|
---|
| 188 | ; BL: Number of P-CHS heads
|
---|
[3] | 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:
|
---|
[227] | 195 | ; Nothing
|
---|
[3] | 196 | ;--------------------------------------------------------------------
|
---|
[227] | 197 | .StorePCHSfromAXDX:
|
---|
| 198 | mov [di+DPT.wPchsCylinders], ax
|
---|
| 199 | mov [di+DPT.wPchsHeadsAndSectors], bx
|
---|
[99] | 200 | ; Fall to .StoreBlockMode
|
---|
[3] | 201 |
|
---|
| 202 | ;--------------------------------------------------------------------
|
---|
[99] | 203 | ; .StoreBlockMode
|
---|
[3] | 204 | ; Parameters:
|
---|
| 205 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 206 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 207 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 208 | ; Returns:
|
---|
[99] | 209 | ; Nothing
|
---|
[3] | 210 | ; Corrupts registers:
|
---|
[150] | 211 | ; Nothing
|
---|
[3] | 212 | ;--------------------------------------------------------------------
|
---|
[99] | 213 | .StoreBlockMode:
|
---|
[150] | 214 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
|
---|
| 215 | jbe SHORT .BlockModeTransfersNotSupported
|
---|
[158] | 216 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
|
---|
[150] | 217 | .BlockModeTransfersNotSupported:
|
---|
| 218 | ; Fall to .StoreDeviceSpecificParameters
|
---|
[3] | 219 |
|
---|
| 220 | ;--------------------------------------------------------------------
|
---|
[150] | 221 | ; .StoreDeviceSpecificParameters
|
---|
[3] | 222 | ; Parameters:
|
---|
| 223 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 224 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 225 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 226 | ; Returns:
|
---|
[99] | 227 | ; Nothing
|
---|
[3] | 228 | ; Corrupts registers:
|
---|
[150] | 229 | ; AX, BX, CX, DX
|
---|
[3] | 230 | ;--------------------------------------------------------------------
|
---|
[150] | 231 | .StoreDeviceSpecificParameters:
|
---|
| 232 | call Device_FinalizeDPT
|
---|
[258] | 233 |
|
---|
[262] | 234 | ;----------------------------------------------------------------------
|
---|
| 235 | ; Update drive counts (hard and floppy)
|
---|
[294] | 236 | ;----------------------------------------------------------------------
|
---|
| 237 |
|
---|
[258] | 238 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
| 239 | ;
|
---|
| 240 | ; These two instructions serve two purposes:
|
---|
| 241 | ; 1. If the drive is a floppy drive (CF set), then we effectively increment the counter.
|
---|
[294] | 242 | ; 2. If this is a hard disk, and there have been any floppy drives previously added, then the hard disk is
|
---|
[258] | 243 | ; effectively discarded. This is more of a safety check then code that should ever normally be hit (see below).
|
---|
[294] | 244 | ; Since the floppy DPT's come after the hard disk DPT's, without expensive (code size) code to relocate a DPT,
|
---|
[258] | 245 | ; this was necessary. Now, this situation shouldn't happen in normal operation, for a couple of reasons:
|
---|
[294] | 246 | ; A. xtidecfg always puts configured serial ports at the end of the IDEVARS list
|
---|
[258] | 247 | ; B. the auto serial code is always executed last
|
---|
| 248 | ; C. the serial server always returns floppy drives last
|
---|
| 249 | ;
|
---|
| 250 | adc byte [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt], 0
|
---|
[294] | 251 | jnz .AllDone
|
---|
[258] | 252 | %else
|
---|
| 253 | ;
|
---|
| 254 | ; Even without floppy support enabled, we shouldn't try to mount a floppy image as a hard disk, which
|
---|
[294] | 255 | ; could lead to unpredictable results since no MBR will be present, etc. The server doesn't know that
|
---|
[258] | 256 | ; floppies are supported, so it is important to still fail here if a floppy is seen during the drive scan.
|
---|
| 257 | ;
|
---|
| 258 | jc .AllDone
|
---|
| 259 | %endif
|
---|
| 260 |
|
---|
[150] | 261 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
[294] | 262 |
|
---|
| 263 | .AllDone:
|
---|
[162] | 264 | clc
|
---|
[3] | 265 | ret
|
---|
[258] | 266 |
|
---|
[324] | 267 |
|
---|
| 268 | ;--------------------------------------------------------------------
|
---|
| 269 | ; StoreLbaAddressingAndTotalSectorCountFromBXDXAX
|
---|
| 270 | ; Parameters:
|
---|
| 271 | ; BX:DX:AX: Total Sector Count
|
---|
| 272 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 273 | ; Returns:
|
---|
| 274 | ; Nothing
|
---|
| 275 | ; Corrupts registers:
|
---|
| 276 | ; CX
|
---|
| 277 | ;--------------------------------------------------------------------
|
---|
| 278 | StoreLbaAddressingAndTotalSectorCountFromBXDXAX:
|
---|
| 279 | mov [di+DPT.twLbaSectors], ax
|
---|
| 280 | mov [di+DPT.twLbaSectors+2], dx
|
---|
| 281 | mov [di+DPT.twLbaSectors+4], bx
|
---|
| 282 |
|
---|
| 283 | and BYTE [di+DPT.bFlagsLow], ~MASKL_DPT_ADDRESSING_MODE
|
---|
| 284 | test bx, bx
|
---|
[346] | 285 | jnz SHORT .SetLba48AddressingToDPT ; Must be LBA48
|
---|
| 286 |
|
---|
| 287 | ; Drives can report at most 0FFF FFFFh LBA28 sectors according to ATA specification.
|
---|
| 288 | ; That is (2^28)-1 so we can simply check if DH is zero or not.
|
---|
| 289 | test dh, dh
|
---|
[324] | 290 | jz SHORT .SetLba28AddressingToDPT
|
---|
| 291 | .SetLba48AddressingToDPT:
|
---|
| 292 | or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
|
---|
| 293 | .SetLba28AddressingToDPT:
|
---|
| 294 | or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
|
---|
| 295 | ret
|
---|