[99] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for creating Disk Parameter Table.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | ;--------------------------------------------------------------------
|
---|
| 8 | ; Creates new Disk Parameter Table for detected hard disk.
|
---|
| 9 | ; Drive is then fully accessible using any BIOS function.
|
---|
| 10 | ;
|
---|
| 11 | ; CreateDPT_FromAtaInformation
|
---|
| 12 | ; Parameters:
|
---|
| 13 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 14 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 15 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 16 | ; DS: RAMVARS segment
|
---|
| 17 | ; ES: BDA Segment
|
---|
| 18 | ; Returns:
|
---|
| 19 | ; DL: Drive number for new drive
|
---|
| 20 | ; DS:DI: Ptr to Disk Parameter Table (if succesfull)
|
---|
| 21 | ; CF: Cleared if DPT created successfully
|
---|
| 22 | ; Set if any error
|
---|
| 23 | ; Corrupts registers:
|
---|
[99] | 24 | ; AX, BX, CX, DH
|
---|
[3] | 25 | ;--------------------------------------------------------------------
|
---|
| 26 | CreateDPT_FromAtaInformation:
|
---|
[150] | 27 | call FindDPT_ForNewDriveToDSDI
|
---|
[99] | 28 | ; Fall to .InitializeDPT
|
---|
[3] | 29 |
|
---|
| 30 | ;--------------------------------------------------------------------
|
---|
[99] | 31 | ; .InitializeDPT
|
---|
[3] | 32 | ; Parameters:
|
---|
| 33 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 34 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 35 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 36 | ; Returns:
|
---|
[150] | 37 | ; Nothing
|
---|
[3] | 38 | ; Corrupts registers:
|
---|
[150] | 39 | ; AX
|
---|
[3] | 40 | ;--------------------------------------------------------------------
|
---|
[99] | 41 | .InitializeDPT:
|
---|
[150] | 42 | mov [di+DPT.bIdevarsOffset], bp ; IDEVARS must start in first 256 bytes of ROM
|
---|
| 43 | ; Fall to .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 44 |
|
---|
| 45 | ;--------------------------------------------------------------------
|
---|
[150] | 46 | ; .StoreDriveSelectAndDriveControlByte
|
---|
[3] | 47 | ; Parameters:
|
---|
| 48 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 49 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 50 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 51 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 52 | ; Returns:
|
---|
[99] | 53 | ; Nothing
|
---|
[3] | 54 | ; Corrupts registers:
|
---|
| 55 | ; AX
|
---|
| 56 | ;--------------------------------------------------------------------
|
---|
[150] | 57 | .StoreDriveSelectAndDriveControlByte:
|
---|
| 58 | mov al, bh
|
---|
| 59 | and ax, BYTE FLG_DRVNHEAD_DRV ; AL now has Master/Slave bit
|
---|
| 60 | cmp [cs:bp+IDEVARS.bIRQ], ah ; Interrupts enabled?
|
---|
| 61 | jz SHORT .StoreFlags ; If not, do not set interrupt flag
|
---|
[158] | 62 | or al, FLGL_DPT_ENABLE_IRQ
|
---|
[150] | 63 | .StoreFlags:
|
---|
| 64 | mov [di+DPT.wFlags], ax
|
---|
[99] | 65 | ; Fall to .StorePCHS
|
---|
[3] | 66 |
|
---|
| 67 | ;--------------------------------------------------------------------
|
---|
[99] | 68 | ; .StorePCHS
|
---|
[3] | 69 | ; Parameters:
|
---|
| 70 | ; BH: Drive Select byte for Drive and Head Register
|
---|
| 71 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 72 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 73 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 74 | ; Returns:
|
---|
[99] | 75 | ; AX: P-CHS cylinders
|
---|
| 76 | ; BL: P-CHS heads
|
---|
| 77 | ; BH: P-CHS sectors
|
---|
[3] | 78 | ; Corrupts registers:
|
---|
| 79 | ; Nothing
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
[99] | 81 | .StorePCHS:
|
---|
| 82 | mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
|
---|
[3] | 83 | call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
|
---|
[99] | 84 | jnz SHORT .GetUserSpecifiedPCHS
|
---|
| 85 | call AtaID_GetPCHS ; Get from ATA information
|
---|
| 86 | jmp SHORT .StorePCHStoDPT
|
---|
[3] | 87 |
|
---|
[99] | 88 | .GetUserSpecifiedPCHS:
|
---|
[3] | 89 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 90 | mov ax, [cs:bx+DRVPARAMS.wCylinders]
|
---|
[99] | 91 | mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
|
---|
[3] | 92 |
|
---|
[99] | 93 | .StorePCHStoDPT:
|
---|
[150] | 94 | mov [di+DPT.wPchsCylinders], ax
|
---|
| 95 | mov [di+DPT.wPchsHeadsAndSectors], bx
|
---|
[99] | 96 | ; Fall to .StoreLCHS
|
---|
[3] | 97 |
|
---|
| 98 | ;--------------------------------------------------------------------
|
---|
[99] | 99 | ; .StoreLCHS
|
---|
[3] | 100 | ; Parameters:
|
---|
[99] | 101 | ; AX: P-CHS cylinders
|
---|
| 102 | ; BL: P-CHS heads
|
---|
[3] | 103 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 104 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 105 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 106 | ; Returns:
|
---|
[99] | 107 | ; Nothing
|
---|
[3] | 108 | ; Corrupts registers:
|
---|
[99] | 109 | ; AX, BX, CX
|
---|
[3] | 110 | ;--------------------------------------------------------------------
|
---|
[99] | 111 | .StoreLCHS:
|
---|
| 112 | xor bh, bh ; BX = P-CHS Heads (1...16)
|
---|
| 113 | xor cx, cx
|
---|
[3] | 114 | .ShiftLoop:
|
---|
[99] | 115 | cmp ax, 1024 ; Need to shift?
|
---|
| 116 | jbe SHORT .LimitHeadsTo255 ; If not, return
|
---|
| 117 | inc cx ; Increment shift count
|
---|
| 118 | shr ax, 1 ; Halve cylinders
|
---|
| 119 | shl bx, 1 ; Double heads
|
---|
[3] | 120 | jmp SHORT .ShiftLoop
|
---|
| 121 |
|
---|
[150] | 122 | .LimitHeadsTo255: ; DOS does not support drives with 256 heads
|
---|
| 123 | rcr bh, 1 ; Set CF if 256 heads
|
---|
| 124 | sbb bl, 0 ; Decrement to 255 if 256 heads
|
---|
| 125 | or [di+DPT.wFlags], cl
|
---|
| 126 | mov [di+DPT.bLchsHeads], bl
|
---|
[99] | 127 | ; Fall to .StoreAddressing
|
---|
[3] | 128 |
|
---|
| 129 | ;--------------------------------------------------------------------
|
---|
[99] | 130 | ; .StoreAddressing
|
---|
[3] | 131 | ; Parameters:
|
---|
| 132 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 133 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 134 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 135 | ; Returns:
|
---|
[99] | 136 | ; Nothing
|
---|
[3] | 137 | ; Corrupts registers:
|
---|
[150] | 138 | ; AX, BX
|
---|
[3] | 139 | ;--------------------------------------------------------------------
|
---|
[99] | 140 | .StoreAddressing:
|
---|
[150] | 141 | ; Check if L-CHS addressing should be used
|
---|
| 142 | cmp WORD [di+DPT.wPchsCylinders], 1024 ; L-CHS possible? (no translation needed)
|
---|
| 143 | jbe SHORT .StoreBlockMode ; If so, nothing needs to be changed
|
---|
| 144 |
|
---|
| 145 | ; Check if P-CHS addressing should be used
|
---|
| 146 | mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS?
|
---|
| 147 | call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
|
---|
| 148 | jnz SHORT .StorePCHSaddressing
|
---|
[3] | 149 | test WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
|
---|
[150] | 150 | jz SHORT .StorePCHSaddressing ; Use P-CHS since LBA not supported
|
---|
| 151 |
|
---|
| 152 | ; LBA needs to be used. Check if 48-bit LBA is supported
|
---|
[3] | 153 | test WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
|
---|
[150] | 154 | jz SHORT .StoreLBA28addressing ; Use LBA-28 since LBA-48 not supported
|
---|
| 155 | or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
|
---|
[99] | 156 | .StoreLBA28addressing:
|
---|
[150] | 157 | or BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
|
---|
[99] | 158 | jmp SHORT .StoreBlockMode
|
---|
| 159 | .StorePCHSaddressing:
|
---|
[150] | 160 | or BYTE [di+DPT.wFlags], ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
|
---|
[99] | 161 | ; Fall to .StoreBlockMode
|
---|
[3] | 162 |
|
---|
| 163 | ;--------------------------------------------------------------------
|
---|
[99] | 164 | ; .StoreBlockMode
|
---|
[3] | 165 | ; Parameters:
|
---|
| 166 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 167 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 168 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 169 | ; Returns:
|
---|
[99] | 170 | ; Nothing
|
---|
[3] | 171 | ; Corrupts registers:
|
---|
[150] | 172 | ; Nothing
|
---|
[3] | 173 | ;--------------------------------------------------------------------
|
---|
[99] | 174 | .StoreBlockMode:
|
---|
[150] | 175 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors
|
---|
| 176 | jbe SHORT .BlockModeTransfersNotSupported
|
---|
[158] | 177 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
|
---|
[150] | 178 | .BlockModeTransfersNotSupported:
|
---|
| 179 | ; Fall to .StoreDeviceSpecificParameters
|
---|
[3] | 180 |
|
---|
| 181 | ;--------------------------------------------------------------------
|
---|
[150] | 182 | ; .StoreDeviceSpecificParameters
|
---|
[3] | 183 | ; Parameters:
|
---|
| 184 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 185 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 186 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 187 | ; Returns:
|
---|
[99] | 188 | ; Nothing
|
---|
[3] | 189 | ; Corrupts registers:
|
---|
[150] | 190 | ; AX, BX, CX, DX
|
---|
[3] | 191 | ;--------------------------------------------------------------------
|
---|
[150] | 192 | .StoreDeviceSpecificParameters:
|
---|
| 193 | call Device_FinalizeDPT
|
---|
[99] | 194 | ; Fall to .StoreDriveNumberAndUpdateDriveCount
|
---|
[3] | 195 |
|
---|
| 196 | ;--------------------------------------------------------------------
|
---|
[99] | 197 | ; .StoreDriveNumberAndUpdateDriveCount
|
---|
[3] | 198 | ; Parameters:
|
---|
| 199 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 200 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 201 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[3] | 202 | ; ES: BDA Segment
|
---|
| 203 | ; Returns:
|
---|
| 204 | ; DL: Drive number for new drive
|
---|
| 205 | ; CF: Cleared if DPT parameters stored successfully
|
---|
| 206 | ; Set if any error
|
---|
| 207 | ; Corrupts registers:
|
---|
| 208 | ; Nothing
|
---|
| 209 | ;--------------------------------------------------------------------
|
---|
[99] | 210 | .StoreDriveNumberAndUpdateDriveCount:
|
---|
[150] | 211 | mov dl, [es:BDA.bHDCount]
|
---|
| 212 | or dl, 80h ; Set bit 7 since hard disk
|
---|
[3] | 213 |
|
---|
[150] | 214 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
|
---|
| 215 | inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA
|
---|
[3] | 216 |
|
---|
[150] | 217 | cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
|
---|
| 218 | ja SHORT .AllDone ; If so, return
|
---|
| 219 | mov [RAMVARS.bFirstDrv], dl ; Store first drive number
|
---|
| 220 | .AllDone:
|
---|
[3] | 221 | clc
|
---|
| 222 | ret
|
---|