[165] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Functions for address translations.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 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.
|
---|
[526] | 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
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
[526] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
[376] | 19 |
|
---|
[165] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;---------------------------------------------------------------------
|
---|
| 24 | ; Address_ExtractLCHSparametersFromOldInt13hAddress
|
---|
| 25 | ; Parameters:
|
---|
| 26 | ; CH: Cylinder number, bits 7...0
|
---|
| 27 | ; CL: Bits 7...6: Cylinder number bits 9 and 8
|
---|
| 28 | ; Bits 5...0: Sector number
|
---|
| 29 | ; DH: Head number
|
---|
| 30 | ; Returns:
|
---|
| 31 | ; BL: Sector number (1...63)
|
---|
| 32 | ; BH: Head number (0...255)
|
---|
| 33 | ; CX: Cylinder number (0...1023)
|
---|
| 34 | ; Corrupts registers:
|
---|
| 35 | ; Nothing
|
---|
| 36 | ;--------------------------------------------------------------------
|
---|
[191] | 37 | ALIGN JUMP_ALIGN
|
---|
[165] | 38 | Address_ExtractLCHSparametersFromOldInt13hAddress:
|
---|
[568] | 39 | mov bl, 3Fh ; Load sector number mask
|
---|
| 40 | and bl, cl ; Sector number now in BL
|
---|
[618] | 41 | %ifndef USE_186
|
---|
[165] | 42 | sub cl, bl ; Remove from cylinder number high
|
---|
[618] | 43 | rol cl, 1 ; High bits to beginning
|
---|
| 44 | rol cl, 1
|
---|
| 45 | %else
|
---|
| 46 | shr cl, 6
|
---|
| 47 | %endif
|
---|
[165] | 48 | mov bh, dh ; Copy Head number
|
---|
| 49 | xchg cl, ch ; Cylinder number now in CX
|
---|
| 50 | ret
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | ;---------------------------------------------------------------------
|
---|
[421] | 54 | ; Converts LARGE addressing mode LCHS parameters to IDE P-CHS parameters.
|
---|
[165] | 55 | ; PCylinder = (LCylinder << n) + (LHead / PHeadCount)
|
---|
| 56 | ; PHead = LHead % PHeadCount
|
---|
| 57 | ; PSector = LSector
|
---|
| 58 | ;
|
---|
[421] | 59 | ; ConvertLargeModeLCHStoPCHS:
|
---|
[165] | 60 | ; Parameters:
|
---|
| 61 | ; BL: Sector number (1...63)
|
---|
[421] | 62 | ; BH: Head number (0...239)
|
---|
[165] | 63 | ; CX: Cylinder number (0...1023)
|
---|
| 64 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 65 | ; Returns:
|
---|
| 66 | ; BL: Sector number (1...63)
|
---|
| 67 | ; BH: Head number (0...15)
|
---|
| 68 | ; CX: Cylinder number (0...16382)
|
---|
| 69 | ; Corrupts registers:
|
---|
| 70 | ; AX, DX
|
---|
| 71 | ;--------------------------------------------------------------------
|
---|
| 72 | ALIGN JUMP_ALIGN
|
---|
[421] | 73 | ConvertLargeModeLCHStoPCHS:
|
---|
[165] | 74 | ; LHead / PHeadCount and LHead % PHeadCount
|
---|
| 75 | eMOVZX ax, bh ; Copy L-CHS Head number to AX
|
---|
[227] | 76 | div BYTE [di+DPT.bPchsHeads]; AL = LHead / PHeadCount, AH = LHead % PHeadCount
|
---|
[165] | 77 | mov bh, ah ; Copy P-CHS Head number to BH
|
---|
| 78 | xor ah, ah ; AX = LHead / PHeadCount
|
---|
| 79 |
|
---|
| 80 | ; (LCylinder << n) + (LHead / PHeadCount)
|
---|
| 81 | mov dx, cx ; Copy L-CHS Cylinder number to DX
|
---|
[568] | 82 | mov cl, MASKL_DPT_CHS_SHIFT_COUNT ; Load shift count mask
|
---|
| 83 | and cl, [di+DPT.bFlagsLow] ; Shift count now in CL
|
---|
[165] | 84 | shl dx, cl ; DX = LCylinder << n
|
---|
| 85 | add ax, dx ; AX = P-CHS Cylinder number
|
---|
| 86 | xchg cx, ax ; Move P-CHS Cylinder number to CX
|
---|
| 87 | DoNotConvertLCHS:
|
---|
| 88 | ret
|
---|
| 89 |
|
---|
[568] | 90 | ; *FIXME* The above function description doesn't match the code.
|
---|
| 91 | ; If CX has a maximum value of 1023 on entry then there is no way CX can be 16382 on return.
|
---|
| 92 | ; 1023 SHL 3 (MASKL_DPT_CHS_SHIFT_COUNT) is 8184. With the addition of AX (at most 255?)
|
---|
| 93 | ; the result is 8439.
|
---|
[421] | 94 |
|
---|
[191] | 95 | ;--------------------------------------------------------------------
|
---|
| 96 | ; Address_OldInt13hAddressToIdeAddress
|
---|
| 97 | ; Parameters:
|
---|
| 98 | ; CH: Cylinder number, bits 7...0
|
---|
| 99 | ; CL: Bits 7...6: Cylinder number bits 9 and 8
|
---|
| 100 | ; Bits 5...0: Starting sector number (1...63)
|
---|
| 101 | ; DH: Starting head number (0...255)
|
---|
| 102 | ; DS:DI: Ptr to DPT
|
---|
| 103 | ; Returns:
|
---|
| 104 | ; BL: LBA Low Register / Sector Number Register (LBA 7...0)
|
---|
| 105 | ; CL: LBA Mid Register / Low Cylinder Register (LBA 15...8)
|
---|
| 106 | ; CH: LBA High Register / High Cylinder Register (LBA 23...16)
|
---|
| 107 | ; BH: Drive and Head Register (LBA 27...24)
|
---|
| 108 | ; Corrupts registers:
|
---|
| 109 | ; AX, DX
|
---|
| 110 | ;--------------------------------------------------------------------
|
---|
| 111 | ALIGN JUMP_ALIGN
|
---|
| 112 | Address_OldInt13hAddressToIdeAddress:
|
---|
[568] | 113 | call Address_ExtractLCHSparametersFromOldInt13hAddress
|
---|
| 114 | mov al, [di+DPT.bFlagsLow]
|
---|
| 115 | and al, MASKL_DPT_TRANSLATEMODE
|
---|
[230] | 116 |
|
---|
[592] | 117 | ;;; 0: TRANSLATEMODE_NORMAL
|
---|
[568] | 118 | jz SHORT DoNotConvertLCHS
|
---|
[230] | 119 |
|
---|
[592] | 120 | ;;; 1: TRANSLATEMODE_LARGE
|
---|
[568] | 121 | test al, FLGL_DPT_ASSISTED_LBA
|
---|
| 122 | jz SHORT ConvertLargeModeLCHStoPCHS
|
---|
[230] | 123 |
|
---|
[592] | 124 | ;;; 2: TRANSLATEMODE_ASSISTED_LBA
|
---|
[568] | 125 | ; Fall to ConvertAssistedLBAModeLCHStoLBARegisterValues
|
---|
[194] | 126 |
|
---|
[230] | 127 |
|
---|
[165] | 128 | ;---------------------------------------------------------------------
|
---|
| 129 | ; Converts LCHS parameters to 28-bit LBA address.
|
---|
| 130 | ; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
|
---|
| 131 | ; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
|
---|
[542] | 132 | ; headsPerCyl and sectPerTrack are the current translation values (L-CHS).
|
---|
[165] | 133 | ;
|
---|
| 134 | ; Returned address is in same registers that
|
---|
[421] | 135 | ; DoNotConvertLCHS and ConvertLargeModeLCHStoPCHS returns.
|
---|
[165] | 136 | ;
|
---|
[421] | 137 | ; ConvertAssistedLBAModeLCHStoLBARegisterValues:
|
---|
[165] | 138 | ; Parameters:
|
---|
| 139 | ; BL: Sector number (1...63)
|
---|
[421] | 140 | ; BH: Head number (0...254)
|
---|
[165] | 141 | ; CX: Cylinder number (0...1023)
|
---|
| 142 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 143 | ; Returns:
|
---|
| 144 | ; BL: LBA Low Register / Sector Number Register (LBA 7...0)
|
---|
| 145 | ; CL: LBA Mid Register / Low Cylinder Register (LBA 15...8)
|
---|
| 146 | ; CH: LBA High Register / High Cylinder Register (LBA 23...16)
|
---|
| 147 | ; BH: Drive and Head Register (LBA 27...24)
|
---|
| 148 | ; Corrupts registers:
|
---|
| 149 | ; AX, DX
|
---|
| 150 | ;--------------------------------------------------------------------
|
---|
[421] | 151 | ConvertAssistedLBAModeLCHStoLBARegisterValues:
|
---|
[165] | 152 | ; cylToSeek*headsPerCyl (18-bit result)
|
---|
[421] | 153 | ; Max = 1023 * 255 = 260,865 = 3FB01h
|
---|
[294] | 154 | mov ax, LBA_ASSIST_SPT ; Load Sectors per Track
|
---|
| 155 | xchg cx, ax ; Cylinder number to AX, Sectors per Track to CX
|
---|
| 156 | %ifdef USE_386
|
---|
[421] | 157 | movzx dx, [di+DPT.bLchsHeads]
|
---|
[294] | 158 | %else
|
---|
| 159 | cwd
|
---|
[421] | 160 | mov dl, [di+DPT.bLchsHeads]
|
---|
[294] | 161 | %endif
|
---|
[165] | 162 | mul dx ; DX:AX = cylToSeek*headsPerCyl
|
---|
| 163 |
|
---|
| 164 | ; +=headToSeek (18-bit result)
|
---|
[421] | 165 | ; Max = 260,865 + 254 = 261,119 = 3FBFFh
|
---|
[165] | 166 | add al, bh ; Add Head number to DX:AX
|
---|
| 167 | adc ah, dh ; DH = Zero after previous multiplication
|
---|
| 168 | adc dl, dh
|
---|
| 169 |
|
---|
| 170 | ; *=sectPerTrack (18-bit by 6-bit multiplication with 24-bit result)
|
---|
[421] | 171 | ; Max = 261,119 * 63 = 16,450,497 = FB03C1h
|
---|
[165] | 172 | xchg ax, dx ; Hiword to AX, loword to DX
|
---|
| 173 | mul cl ; AX = hiword * Sectors per Track
|
---|
| 174 | mov bh, al ; Backup hiword * Sectors per Track
|
---|
| 175 | xchg ax, dx ; Loword back to AX
|
---|
| 176 | mul cx ; DX:AX = loword * Sectors per Track
|
---|
| 177 | add dl, bh ; DX:AX = (cylToSeek*headsPerCyl+headToSeek)*sectPerTrack
|
---|
| 178 |
|
---|
| 179 | ; +=sectToSeek-1 (24-bit result)
|
---|
[421] | 180 | ; Max = 16,450,497 + 63 - 1 = 16,450,559 = FB03FFh
|
---|
[589] | 181 | mov bh, ch ; Sector number now in BX, CH=zero
|
---|
[165] | 182 | dec bx ; sectToSeek-=1
|
---|
[589] | 183 | add bx, ax ; Add loword to BX (BL = Sector Number Register (LBA 7...0))
|
---|
| 184 | adc ch, dl ; Add possible carry to byte2 (CH = High Cylinder Register (LBA 23...16))
|
---|
| 185 | mov cl, bh ; CL = Low Cylinder Register (LBA 15...8)
|
---|
| 186 | mov bh, dh ; BH = Drive and Head Register (LBA 27...24)
|
---|
[165] | 187 | ret
|
---|