source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/LbaAssist.asm@ 359

Last change on this file since 359 was 358, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Moved BIOS title and version strings to Version.inc.
  • Moved LBA to L-CHS conversion function to LbaAssist.asm.
File size: 3.0 KB
Line 
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; Section containing code
8SECTION .text
9
10;--------------------------------------------------------------------
11; LBA assist calculation:
12; this is how to fit a big drive into INT13's skimpy size requirements,
13; with a maximum of 8.4G available.
14;
15; total LBAs (as obtained by words 60+61)
16; divided by 63 (sectors per track) (save as value A)
17; Sub 1 from A
18; divide A by 1024 + truncate.
19; == total number of heads to use.
20; add 1
21; this value must be either 16, 32, 64, 128, or 256 (round up)
22; then take the value A above and divide by # of heads
23; to get the # of cylinders to use.
24;
25;
26; so a LBA28 drive will have 268,435,456 as maximum LBAs
27;
28; 10000000h / 63 = 410410h (total cylinders or tracks)
29; 410410h / 1024 = 1041h, which is way more than 256 heads, but 256 is max.
30; 410410h / 256 = 4104h cylinders
31;
32; there's a wealth of information at: http://www.mossywell.com/boot-sequence
33; they show a slightly different approach to LBA assist calulations, but
34; the method here provides compatibility with phoenix BIOS
35;
36; we're using the values from 60+61 here because we're topping out at 8.4G
37; anyway, so there's no need to use the 48bit LBA values.
38;
39; LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
40; Parameters:
41; BX:DX:AX: Total number of sectors
42; Returns:
43; DX:AX: Number of cylinders
44; BH: Number of sectors per track (always 63)
45; BL: Number of heads (16, 32, 64, 128 or 255)
46; Corrupts registers:
47; CX
48;--------------------------------------------------------------------
49LbaAssist_ConvertSectorCountFromBXDXAXtoLbaAssistedCHSinDXAXBLBH:
50 push bp
51 push si
52
53 ; Value A = Total sector count / 63
54 xor cx, cx
55 push cx ; Push zero for bits 48...63
56 push bx
57 push dx
58 push ax ; 64-bit sector count now in stack
59 mov cl, LBA_ASSIST_SPT
60 mov bp, sp ; SS:BP now points sector count
61 call Math_DivQWatSSBPbyCX ; Temporary value A now in stack
62
63 ; BX = Number of heads = A / 1024
64 mov ax, [bp]
65 mov dx, [bp+2]
66 mov bx, [bp+4]
67 call Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
68
69 ; Heads must be 16, 32, 64, 128 or 256 (round up)
70 mov bx, 256 ; Max number of heads
71 test dx, dx ; 65536 or more heads?
72 jnz SHORT .GetNumberOfCylinders
73 mov cx, 128 ; Half BX for rounding up
74.FindMostSignificantBitForHeadSize:
75 cmp ax, cx
76 jae SHORT .GetNumberOfCylinders
77 shr cx, 1
78 shr bx, 1 ; Halve number of heads
79 jmp SHORT .FindMostSignificantBitForHeadSize
80
81 ; DX:AX = Number of cylinders = A / number of heads
82.GetNumberOfCylinders:
83 mov cx, bx
84 call Math_DivQWatSSBPbyCX
85 mov ax, [bp]
86 mov dx, [bp+2] ; Cylinders now in DX:AX
87
88 ; Return LBA assisted CHS
89 add sp, BYTE 8 ; Clean stack
90 sub bl, bh ; Limit heads to 255
91 mov bh, LBA_ASSIST_SPT
92 pop si
93 pop bp
94 ret
Note: See TracBrowser for help on using the repository browser.