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 | ; 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. |
---|
36 | ; |
---|
37 | ; There's a wealth of information at: http://www.mossywell.com/boot-sequence |
---|
38 | ; they show a slightly different approach to LBA assist calulations, but |
---|
39 | ; the method here provides compatibility with phoenix BIOS. |
---|
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 | |
---|
55 | ; Value CH = Total sector count / 63 |
---|
56 | xor cx, cx |
---|
57 | push cx ; Push zero for bits 48...63 |
---|
58 | push bx |
---|
59 | push dx |
---|
60 | push ax ; 64-bit sector count now in stack |
---|
61 | mov cl, LBA_ASSIST_SPT |
---|
62 | mov bp, sp ; SS:BP now points sector count |
---|
63 | call Math_DivQWatSSBPbyCX ; Temporary value A now in stack |
---|
64 | |
---|
65 | ; BX:DX:AX = Value CH - 1 |
---|
66 | mov ax, [bp] |
---|
67 | mov dx, [bp+2] |
---|
68 | mov bx, [bp+4] |
---|
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 |
---|
74 | call Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX |
---|
75 | add ax, BYTE 1 ; Add 1 |
---|
76 | adc dx, bx ; BX = 0 |
---|
77 | |
---|
78 | ; Heads must be 16, 32, 64, 128 or 255 (round up to the nearest) |
---|
79 | test dx, dx ; 65536 or more heads? |
---|
80 | jnz SHORT .LimitHeadsTo255 |
---|
81 | mov cx, 16 ; Min number of heads |
---|
82 | .CompareNextValidNumberOfHeads: |
---|
83 | cmp ax, cx |
---|
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 |
---|
93 | |
---|
94 | ; DX:AX = Number of cylinders = Value CH (without - 1) / number of heads |
---|
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 |
---|