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 |
|
---|
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 |
|
---|
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 | ;
|
---|
31 | ; total LBAs (as obtained by words 60+61)
|
---|
32 | ; divided by 63 (sectors per track) (save as value A)
|
---|
33 | ; Sub 1 from A
|
---|
34 | ; divide A by 1024 + truncate.
|
---|
35 | ; == total number of heads to use.
|
---|
36 | ; add 1
|
---|
37 | ; this value must be either 16, 32, 64, 128, or 256 (round up)
|
---|
38 | ; then take the value A above and divide by # of heads
|
---|
39 | ; to get the # of cylinders to use.
|
---|
40 | ;
|
---|
41 | ;
|
---|
42 | ; so a LBA28 drive will have 268,435,456 as maximum LBAs
|
---|
43 | ;
|
---|
44 | ; 10000000h / 63 = 410410h (total cylinders or tracks)
|
---|
45 | ; 410410h / 1024 = 1041h, which is way more than 256 heads, but 256 is max.
|
---|
46 | ; 410410h / 256 = 4104h cylinders
|
---|
47 | ;
|
---|
48 | ; there's a wealth of information at: http://www.mossywell.com/boot-sequence
|
---|
49 | ; they show a slightly different approach to LBA assist calulations, but
|
---|
50 | ; the method here provides compatibility with phoenix BIOS
|
---|
51 | ;
|
---|
52 | ; we're using the values from 60+61 here because we're topping out at 8.4G
|
---|
53 | ; anyway, so there's no need to use the 48bit LBA values.
|
---|
54 | ;
|
---|
55 | ; LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
|
---|
56 | ; Parameters:
|
---|
57 | ; BX:DX:AX: Total number of sectors
|
---|
58 | ; Returns:
|
---|
59 | ; DX:AX: Number of cylinders
|
---|
60 | ; BH: Number of sectors per track (always 63)
|
---|
61 | ; BL: Number of heads (16, 32, 64, 128 or 255)
|
---|
62 | ; Corrupts registers:
|
---|
63 | ; CX
|
---|
64 | ;--------------------------------------------------------------------
|
---|
65 | LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
|
---|
66 | push bp
|
---|
67 | push si
|
---|
68 |
|
---|
69 | ; Value A = Total sector count / 63
|
---|
70 | xor cx, cx
|
---|
71 | push cx ; Push zero for bits 48...63
|
---|
72 | push bx
|
---|
73 | push dx
|
---|
74 | push ax ; 64-bit sector count now in stack
|
---|
75 | mov cl, LBA_ASSIST_SPT
|
---|
76 | mov bp, sp ; SS:BP now points sector count
|
---|
77 | call Math_DivQWatSSBPbyCX ; Temporary value A now in stack
|
---|
78 |
|
---|
79 | ; BX = Number of heads = A / 1024
|
---|
80 | mov ax, [bp]
|
---|
81 | mov dx, [bp+2]
|
---|
82 | mov bx, [bp+4]
|
---|
83 | call Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
|
---|
84 |
|
---|
85 | ; Heads must be 16, 32, 64, 128 or 256 (round up)
|
---|
86 | mov bx, 256 ; Max number of heads
|
---|
87 | test dx, dx ; 65536 or more heads?
|
---|
88 | jnz SHORT .GetNumberOfCylinders
|
---|
89 | mov cx, 128 ; Half BX for rounding up
|
---|
90 | .FindMostSignificantBitForHeadSize:
|
---|
91 | cmp ax, cx
|
---|
92 | jae SHORT .GetNumberOfCylinders
|
---|
93 | shr cx, 1
|
---|
94 | shr bx, 1 ; Halve number of heads
|
---|
95 | jmp SHORT .FindMostSignificantBitForHeadSize
|
---|
96 |
|
---|
97 | ; DX:AX = Number of cylinders = A / number of heads
|
---|
98 | .GetNumberOfCylinders:
|
---|
99 | mov cx, bx
|
---|
100 | call Math_DivQWatSSBPbyCX
|
---|
101 | mov ax, [bp]
|
---|
102 | mov dx, [bp+2] ; Cylinders now in DX:AX
|
---|
103 |
|
---|
104 | ; Return LBA assisted CHS
|
---|
105 | add sp, BYTE 8 ; Clean stack
|
---|
106 | sub bl, bh ; Limit heads to 255
|
---|
107 | mov bh, LBA_ASSIST_SPT
|
---|
108 | pop si
|
---|
109 | pop bp
|
---|
110 | ret
|
---|