[99] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for accessing ATA information read with
|
---|
| 3 | ; IDENTIFY DEVICE command.
|
---|
| 4 |
|
---|
| 5 | ; Section containing code
|
---|
| 6 | SECTION .text
|
---|
| 7 |
|
---|
| 8 | ;--------------------------------------------------------------------
|
---|
[169] | 9 | ; AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
|
---|
[3] | 10 | ; Parameters:
|
---|
| 11 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 12 | ; Returns:
|
---|
| 13 | ; AX: Number of user specified P-CHS cylinders
|
---|
[99] | 14 | ; BH: Number of user specified P-CHS sectors per track
|
---|
| 15 | ; BL: Number of user specified P-CHS heads
|
---|
[3] | 16 | ; Corrupts registers:
|
---|
| 17 | ; Nothing
|
---|
| 18 | ;--------------------------------------------------------------------
|
---|
[169] | 19 | AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI:
|
---|
[3] | 20 | mov ax, [es:si+ATA1.wCylCnt] ; Cylinders (1...16383)
|
---|
[99] | 21 | mov bl, [es:si+ATA1.wHeadCnt] ; Heads (1...16)
|
---|
| 22 | mov bh, [es:si+ATA1.wSPT] ; Sectors per Track (1...63)
|
---|
[3] | 23 | ret
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | ;--------------------------------------------------------------------
|
---|
[165] | 27 | ; AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
|
---|
[3] | 28 | ; Parameters:
|
---|
| 29 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 30 | ; Returns:
|
---|
| 31 | ; BX:DX:AX: 48-bit sector count
|
---|
| 32 | ; Corrupts registers:
|
---|
| 33 | ; Nothing
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
[165] | 35 | AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI:
|
---|
[181] | 36 | mov bx, Registers_ExchangeDSSIwithESDI
|
---|
| 37 | call bx ; ATA info now in DS:DI
|
---|
| 38 | push bx ; We will return via Registers_ExchangeDSSIwithESDI
|
---|
[3] | 39 | xor bx, bx
|
---|
[173] | 40 | test BYTE [di+ATA1.wCaps+1], A1_wCaps_LBA>>8
|
---|
[99] | 41 | jz SHORT .GetChsSectorCount
|
---|
| 42 | ; Fall to .GetLbaSectorCount
|
---|
[3] | 43 |
|
---|
| 44 | ;--------------------------------------------------------------------
|
---|
[99] | 45 | ; .GetLbaSectorCount
|
---|
[173] | 46 | ; .GetLba28SectorCount
|
---|
| 47 | ; .GetChsSectorCount
|
---|
[3] | 48 | ; Parameters:
|
---|
| 49 | ; BX: Zero
|
---|
[181] | 50 | ; DS:DI: Ptr to 512-byte ATA information read from the drive
|
---|
[3] | 51 | ; Returns:
|
---|
| 52 | ; BX:DX:AX: 48-bit sector count
|
---|
| 53 | ; Corrupts registers:
|
---|
| 54 | ; Nothing
|
---|
| 55 | ;--------------------------------------------------------------------
|
---|
[99] | 56 | .GetLbaSectorCount:
|
---|
[173] | 57 | test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
|
---|
[3] | 58 | jz SHORT .GetLba28SectorCount
|
---|
[173] | 59 | mov ax, [di+ATA6.qwLBACnt]
|
---|
| 60 | mov dx, [di+ATA6.qwLBACnt+2]
|
---|
| 61 | mov bx, [di+ATA6.qwLBACnt+4]
|
---|
[181] | 62 | ret
|
---|
[173] | 63 |
|
---|
[3] | 64 | .GetLba28SectorCount:
|
---|
[173] | 65 | mov ax, [di+ATA1.dwLBACnt]
|
---|
| 66 | mov dx, [di+ATA1.dwLBACnt+2]
|
---|
[181] | 67 | ret
|
---|
[3] | 68 |
|
---|
[99] | 69 | .GetChsSectorCount:
|
---|
[173] | 70 | mov al, [di+ATA1.wSPT] ; AL=Sectors per track
|
---|
| 71 | mul BYTE [di+ATA1.wHeadCnt] ; AX=Sectors per track * number of heads
|
---|
| 72 | mul WORD [di+ATA1.wCylCnt] ; DX:AX=Sectors per track * number of heads * number of cylinders
|
---|
[181] | 73 | ret
|
---|
[363] | 74 |
|
---|
| 75 |
|
---|
| 76 | %ifdef MODULE_ADVANCED_ATA
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
[364] | 78 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
[363] | 79 | ; Parameters:
|
---|
| 80 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 81 | ; Returns:
|
---|
[364] | 82 | ; AL: Max supported PIO mode
|
---|
| 83 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
| 84 | ; CX: Minimum Cycle Time in nanosecs
|
---|
[363] | 85 | ; Corrupts registers:
|
---|
| 86 | ; BX
|
---|
| 87 | ;--------------------------------------------------------------------
|
---|
[364] | 88 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
[363] | 89 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
| 90 | mov bx, [es:si+ATA1.bPioMode]
|
---|
[370] | 91 | mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
[363] | 92 | shl bx, 1 ; Shift for WORD lookup
|
---|
[364] | 93 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
[363] | 94 |
|
---|
[364] | 95 | ; Check if IORDY is supported
|
---|
| 96 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
| 97 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
| 98 | mov ah, FLGH_DPT_IORDY
|
---|
| 99 |
|
---|
[363] | 100 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
| 101 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
| 102 | jz SHORT .ReturnPioTimings
|
---|
| 103 |
|
---|
| 104 | ; Get Advanced PIO mode
|
---|
[364] | 105 | ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
[370] | 106 | mov bl, [es:si+ATA2.bPIOSupp]
|
---|
[363] | 107 | .CheckNextFlag:
|
---|
| 108 | inc ax
|
---|
[370] | 109 | shr bl, 1
|
---|
[363] | 110 | jnz SHORT .CheckNextFlag
|
---|
[364] | 111 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
| 112 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
[363] | 113 | .ReturnPioTimings:
|
---|
| 114 | ret
|
---|
| 115 |
|
---|
| 116 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
| 117 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
| 118 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
| 119 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | ;--------------------------------------------------------------------
|
---|
[364] | 123 | ; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
|
---|
[363] | 124 | ; Parameters:
|
---|
[364] | 125 | ; BX: PIO Mode
|
---|
| 126 | ; CX: PIO Cycle Time in nanosecs
|
---|
[363] | 127 | ; Returns:
|
---|
[364] | 128 | ; AX: Active Time in nanosecs
|
---|
[363] | 129 | ; Corrupts registers:
|
---|
[364] | 130 | ; BX, CX
|
---|
[363] | 131 | ;--------------------------------------------------------------------
|
---|
[364] | 132 | AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
|
---|
| 133 | call AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 134 | mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
|
---|
| 135 | sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
|
---|
| 136 | sub cx, ax ; - Active Time (t2)
|
---|
| 137 | xchg ax, cx ; AX = Recovery Time (t2i)
|
---|
[363] | 138 | ret
|
---|
| 139 |
|
---|
| 140 | .rgbPioModeToAddressValidTimeNs:
|
---|
| 141 | db PIO_0_MIN_ADDRESS_VALID_NS
|
---|
| 142 | db PIO_1_MIN_ADDRESS_VALID_NS
|
---|
| 143 | db PIO_2_MIN_ADDRESS_VALID_NS
|
---|
| 144 | db PIO_3_MIN_ADDRESS_VALID_NS
|
---|
| 145 | db PIO_4_MIN_ADDRESS_VALID_NS
|
---|
[364] | 146 | db PIO_5_MIN_ADDRESS_VALID_NS
|
---|
| 147 | db PIO_6_MIN_ADDRESS_VALID_NS
|
---|
[363] | 148 |
|
---|
[364] | 149 |
|
---|
| 150 | ;--------------------------------------------------------------------
|
---|
| 151 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 152 | ; Parameters:
|
---|
| 153 | ; BX: PIO Mode
|
---|
| 154 | ; Returns:
|
---|
| 155 | ; AX: Active Time in nanosecs
|
---|
| 156 | ; Corrupts registers:
|
---|
| 157 | ; Nothing
|
---|
| 158 | ;--------------------------------------------------------------------
|
---|
| 159 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
| 160 | shl bx, 1
|
---|
| 161 | mov ax, [cs:bx+.rgwPioModeToActiveTimeNs]
|
---|
| 162 | shr bx, 1
|
---|
| 163 | ret
|
---|
| 164 |
|
---|
[363] | 165 | .rgwPioModeToActiveTimeNs:
|
---|
| 166 | dw PIO_0_MIN_ACTIVE_TIME_NS
|
---|
| 167 | dw PIO_1_MIN_ACTIVE_TIME_NS
|
---|
| 168 | dw PIO_2_MIN_ACTIVE_TIME_NS
|
---|
| 169 | dw PIO_3_MIN_ACTIVE_TIME_NS
|
---|
| 170 | dw PIO_4_MIN_ACTIVE_TIME_NS
|
---|
[364] | 171 | dw PIO_5_MIN_ACTIVE_TIME_NS
|
---|
| 172 | dw PIO_6_MIN_ACTIVE_TIME_NS
|
---|
[363] | 173 |
|
---|
| 174 | %endif ; MODULE_ADVANCED_ATA
|
---|