[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 |
---|
[175] | 65 | |
---|
| 66 | %ifdef MODULE_SERIAL |
---|
| 67 | cmp byte [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT |
---|
[181] | 68 | jnz .StoreAddressing |
---|
[175] | 69 | or byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE |
---|
[181] | 70 | %endif |
---|
[173] | 71 | ; Fall to .StoreAddressing |
---|
[3] | 72 | |
---|
| 73 | ;-------------------------------------------------------------------- |
---|
[173] | 74 | ; .StoreAddressing |
---|
[3] | 75 | ; Parameters: |
---|
| 76 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 77 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
| 78 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
| 79 | ; Returns: |
---|
[173] | 80 | ; DX:AX or AX: Number of cylinders |
---|
| 81 | ; BH: Number of sectors per track |
---|
| 82 | ; BL: Number of heads |
---|
[3] | 83 | ; Corrupts registers: |
---|
[173] | 84 | ; CX, (DX) |
---|
[3] | 85 | ;-------------------------------------------------------------------- |
---|
[173] | 86 | .StoreAddressing: |
---|
| 87 | ; Check if CHS defined in ROMVARS |
---|
[99] | 88 | mov al, FLG_DRVPARAMS_USERCHS ; User specified CHS? |
---|
[3] | 89 | call AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive |
---|
[173] | 90 | jnz SHORT .StoreUserDefinedCHSaddressing |
---|
| 91 | |
---|
| 92 | ; Check if LBA supported |
---|
[169] | 93 | call AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI |
---|
[173] | 94 | test BYTE [es:si+ATA1.wCaps+1], A1_wCaps_LBA>>8 |
---|
| 95 | jz SHORT .StoreCHSaddressing |
---|
[3] | 96 | |
---|
[173] | 97 | ; Check if 48-bit LBA supported |
---|
| 98 | test BYTE [es:si+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8 |
---|
| 99 | jz SHORT .StoreLBA28addressing |
---|
| 100 | or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION |
---|
| 101 | .StoreLBA28addressing: |
---|
| 102 | or BYTE [di+DPT.bFlagsLow], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION |
---|
| 103 | call AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI |
---|
| 104 | call AtaID_GetLbaAssistedCHStoDXAXBLBH |
---|
| 105 | jmp SHORT .StoreChsFromDXAXBX |
---|
| 106 | |
---|
| 107 | ; Check if P-CHS to L-CHS translation required |
---|
| 108 | .StoreUserDefinedCHSaddressing: |
---|
[3] | 109 | call AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 110 | mov ax, [cs:bx+DRVPARAMS.wCylinders] |
---|
[99] | 111 | mov bx, [cs:bx+DRVPARAMS.wHeadsAndSectors] |
---|
[173] | 112 | .StoreCHSaddressing: |
---|
| 113 | cmp ax, MAX_LCHS_CYLINDERS |
---|
| 114 | jbe SHORT .StoreChsFromAXBX ; No translation required |
---|
[3] | 115 | |
---|
[173] | 116 | ; We need to get number of bits to shift for translation |
---|
| 117 | push ax |
---|
| 118 | eMOVZX dx, bl ; Heads now in DX |
---|
[181] | 119 | xchg bx, ax ; Cylinders now in BX |
---|
| 120 | call AccessDPT_ShiftPCHinBXDXtoLCH ; Leaves AX untouched |
---|
| 121 | xchg bx, ax ; Restore HeadsAndSectors to BX |
---|
[173] | 122 | or cl, ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION |
---|
| 123 | or [di+DPT.bFlagsLow], cl ; Store bits to shift |
---|
| 124 | pop ax |
---|
| 125 | ; Fall to .StoreChsFromAXBX |
---|
[3] | 126 | |
---|
| 127 | ;-------------------------------------------------------------------- |
---|
[173] | 128 | ; .StoreChsFromAXBX |
---|
| 129 | ; .StoreChsFromDXAXBX |
---|
[3] | 130 | ; Parameters: |
---|
[173] | 131 | ; DX:AX or AX: Number of cylinders |
---|
| 132 | ; BH: Number of sectors per track |
---|
| 133 | ; BL: Number of heads |
---|
[3] | 134 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 135 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 136 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 137 | ; Returns: |
---|
[99] | 138 | ; Nothing |
---|
[3] | 139 | ; Corrupts registers: |
---|
[173] | 140 | ; DX |
---|
[3] | 141 | ;-------------------------------------------------------------------- |
---|
[173] | 142 | .StoreChsFromAXBX: |
---|
| 143 | xor dx, dx |
---|
| 144 | .StoreChsFromDXAXBX: |
---|
| 145 | mov [di+DPT.dwCylinders], ax |
---|
| 146 | mov [di+DPT.dwCylinders+2], dx |
---|
| 147 | mov [di+DPT.wHeadsAndSectors], bx |
---|
[99] | 148 | ; Fall to .StoreBlockMode |
---|
[3] | 149 | |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
[99] | 151 | ; .StoreBlockMode |
---|
[3] | 152 | ; Parameters: |
---|
| 153 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 154 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 155 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 156 | ; Returns: |
---|
[99] | 157 | ; Nothing |
---|
[3] | 158 | ; Corrupts registers: |
---|
[150] | 159 | ; Nothing |
---|
[3] | 160 | ;-------------------------------------------------------------------- |
---|
[99] | 161 | .StoreBlockMode: |
---|
[150] | 162 | cmp BYTE [es:si+ATA1.bBlckSize], 1 ; Max block size in sectors |
---|
| 163 | jbe SHORT .BlockModeTransfersNotSupported |
---|
[158] | 164 | or BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED |
---|
[150] | 165 | .BlockModeTransfersNotSupported: |
---|
| 166 | ; Fall to .StoreDeviceSpecificParameters |
---|
[3] | 167 | |
---|
| 168 | ;-------------------------------------------------------------------- |
---|
[150] | 169 | ; .StoreDeviceSpecificParameters |
---|
[3] | 170 | ; Parameters: |
---|
| 171 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 172 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 173 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 174 | ; Returns: |
---|
[99] | 175 | ; Nothing |
---|
[3] | 176 | ; Corrupts registers: |
---|
[150] | 177 | ; AX, BX, CX, DX |
---|
[3] | 178 | ;-------------------------------------------------------------------- |
---|
[150] | 179 | .StoreDeviceSpecificParameters: |
---|
| 180 | call Device_FinalizeDPT |
---|
[99] | 181 | ; Fall to .StoreDriveNumberAndUpdateDriveCount |
---|
[3] | 182 | |
---|
| 183 | ;-------------------------------------------------------------------- |
---|
[99] | 184 | ; .StoreDriveNumberAndUpdateDriveCount |
---|
[3] | 185 | ; Parameters: |
---|
| 186 | ; DS:DI: Ptr to Disk Parameter Table |
---|
| 187 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
[160] | 188 | ; CS:BP: Ptr to IDEVARS for the controller |
---|
[3] | 189 | ; ES: BDA Segment |
---|
| 190 | ; Returns: |
---|
| 191 | ; DL: Drive number for new drive |
---|
[162] | 192 | ; CF: Always cleared |
---|
[3] | 193 | ; Corrupts registers: |
---|
| 194 | ; Nothing |
---|
| 195 | ;-------------------------------------------------------------------- |
---|
[99] | 196 | .StoreDriveNumberAndUpdateDriveCount: |
---|
[150] | 197 | mov dl, [es:BDA.bHDCount] |
---|
| 198 | or dl, 80h ; Set bit 7 since hard disk |
---|
[3] | 199 | |
---|
[150] | 200 | inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS |
---|
| 201 | inc BYTE [es:BDA.bHDCount] ; Increment drive count to BDA |
---|
[3] | 202 | |
---|
[150] | 203 | cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set? |
---|
| 204 | ja SHORT .AllDone ; If so, return |
---|
| 205 | mov [RAMVARS.bFirstDrv], dl ; Store first drive number |
---|
[162] | 206 | clc |
---|
[150] | 207 | .AllDone: |
---|
[3] | 208 | ret |
---|