[358] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Functions for generating L-CHS parameters for
|
---|
| 3 | ; LBA drives.
|
---|
| 4 | ;
|
---|
| 5 | ; This file is shared with BIOS Drive Information Tool.
|
---|
| 6 |
|
---|
[376] | 7 | ;
|
---|
| 8 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 9 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 10 | ;
|
---|
| 11 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 12 | ; it under the terms of the GNU General Public License as published by
|
---|
| 13 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | ; (at your option) any later version.
|
---|
| 15 | ;
|
---|
| 16 | ; This program is distributed in the hope that it will be useful,
|
---|
| 17 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | ; GNU General Public License for more details.
|
---|
| 20 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 21 | ;
|
---|
| 22 |
|
---|
[358] | 23 | ; Section containing code
|
---|
| 24 | SECTION .text
|
---|
| 25 |
|
---|
| 26 | ;--------------------------------------------------------------------
|
---|
| 27 | ; LBA assist calculation:
|
---|
| 28 | ; this is how to fit a big drive into INT13's skimpy size requirements,
|
---|
| 29 | ; with a maximum of 8.4G available.
|
---|
| 30 | ;
|
---|
[419] | 31 | ; If cylinders > 8192
|
---|
| 32 | ; Variable CH = Total Sectors / 63
|
---|
| 33 | ; Divide (CH 1) by 1024 (as an assembler bitwise right shift) and add 1
|
---|
| 34 | ; Round the result up to the nearest of 16, 32, 64, 128 and 255. This is the value to be used for the number of heads.
|
---|
| 35 | ; Divide CH by the number of heads. This is the value to be used for the number of cylinders.
|
---|
[358] | 36 | ;
|
---|
[419] | 37 | ; There's a wealth of information at: http://www.mossywell.com/boot-sequence
|
---|
[358] | 38 | ; they show a slightly different approach to LBA assist calulations, but
|
---|
[419] | 39 | ; the method here provides compatibility with phoenix BIOS.
|
---|
[358] | 40 | ;
|
---|
| 41 | ; LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
|
---|
| 42 | ; Parameters:
|
---|
| 43 | ; BX:DX:AX: Total number of sectors
|
---|
| 44 | ; Returns:
|
---|
| 45 | ; DX:AX: Number of cylinders
|
---|
| 46 | ; BH: Number of sectors per track (always 63)
|
---|
| 47 | ; BL: Number of heads (16, 32, 64, 128 or 255)
|
---|
| 48 | ; Corrupts registers:
|
---|
| 49 | ; CX
|
---|
| 50 | ;--------------------------------------------------------------------
|
---|
| 51 | LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
|
---|
| 52 | push bp
|
---|
| 53 | push si
|
---|
| 54 |
|
---|
[419] | 55 | ; Value CH = Total sector count / 63
|
---|
[358] | 56 | xor cx, cx
|
---|
[419] | 57 | push cx ; Push zero for bits 48...63
|
---|
[358] | 58 | push bx
|
---|
| 59 | push dx
|
---|
[419] | 60 | push ax ; 64-bit sector count now in stack
|
---|
[358] | 61 | mov cl, LBA_ASSIST_SPT
|
---|
[419] | 62 | mov bp, sp ; SS:BP now points sector count
|
---|
| 63 | call Math_DivQWatSSBPbyCX ; Temporary value A now in stack
|
---|
[358] | 64 |
|
---|
[419] | 65 | ; BX:DX:AX = Value CH - 1
|
---|
[358] | 66 | mov ax, [bp]
|
---|
| 67 | mov dx, [bp+2]
|
---|
| 68 | mov bx, [bp+4]
|
---|
[419] | 69 | sub ax, BYTE 1 ; Subtract 1
|
---|
| 70 | sbb dx, BYTE 0
|
---|
| 71 | sbb bx, BYTE 0
|
---|
| 72 |
|
---|
| 73 | ; DX:AX = Number of heads = ((Value CH - 1) / 1024) + 1
|
---|
[358] | 74 | call Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
[419] | 75 | add ax, BYTE 1 ; Add 1
|
---|
| 76 | adc dx, bx ; BX = 0
|
---|
[358] | 77 |
|
---|
[419] | 78 | ; Heads must be 16, 32, 64, 128 or 255 (round up to the nearest)
|
---|
[358] | 79 | test dx, dx ; 65536 or more heads?
|
---|
[419] | 80 | jnz SHORT .LimitHeadsTo255
|
---|
| 81 | mov cx, 16 ; Min number of heads
|
---|
| 82 | .CompareNextValidNumberOfHeads:
|
---|
[358] | 83 | cmp ax, cx
|
---|
[419] | 84 | jbe SHORT .NumberOfHeadsNowInCX
|
---|
| 85 | shl cx, 1 ; Double number of heads
|
---|
| 86 | test ch, ch ; Reached 256 heads?
|
---|
| 87 | jnz SHORT .CompareNextValidNumberOfHeads
|
---|
| 88 | .LimitHeadsTo255:
|
---|
| 89 | mov cx, 255
|
---|
| 90 | .NumberOfHeadsNowInCX:
|
---|
| 91 | mov bx, cx ; Number of heads are returned in BL
|
---|
| 92 | mov bh, LBA_ASSIST_SPT ; Sectors per Track
|
---|
[358] | 93 |
|
---|
[419] | 94 | ; DX:AX = Number of cylinders = Value CH (without - 1) / number of heads
|
---|
[358] | 95 | call Math_DivQWatSSBPbyCX
|
---|
| 96 | mov ax, [bp]
|
---|
| 97 | mov dx, [bp+2] ; Cylinders now in DX:AX
|
---|
| 98 |
|
---|
| 99 | ; Return LBA assisted CHS
|
---|
| 100 | add sp, BYTE 8 ; Clean stack
|
---|
| 101 | pop si
|
---|
| 102 | pop bp
|
---|
| 103 | ret
|
---|