source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Size.asm@ 375

Last change on this file since 375 was 369, checked in by gregli@…, 13 years ago

Removed align directives for initalization code and added define for align in boot-time calls to the assembly library (defaulting to 1), resulting in a significant savings for the AT and 386 builds. Fixed a bug with switch command line handling in the serial server. Put in CR characters in licesnse.txt, so that it properly displays on Windows. In the configurator, added default values for user supplied CHS and LBA values, defaulting to values within range when those features are enabled. Updated the copyright message in the configurator as the literal word Copyright is important.

File size: 3.2 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for size calculations.
3
4struc BYTE_MULTIPLES
5 .B resb 1
6 .kiB resb 1
7 .MiB resb 1
8 .GiB resb 1
9 .TiB resb 1
10endstruc
11
12; Section containing code
13SECTION .text
14
15;--------------------------------------------------------------------
16; Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
17; Parameters:
18; BX:DX:AX: Size in magnitude
19; CX: Magnitude in BYTE_MULTIPLES
20; Returns:
21; AX: Size in magnitude
22; CX: Tenths
23; DL: Magnitude character:
24; 'k' = *1024 B = kiB
25; 'M' = *1024 kiB = MiB
26; 'G' = *1024 MiB = GiB
27; 'T' = *1024 GiB = TiB
28; 'P' = *1024 TiB = PiB
29; Corrupts registers:
30; BX, DH
31;--------------------------------------------------------------------
32ALIGN UTIL_SIZE_JUMP_ALIGN
33Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX:
34%ifndef USE_186 ; If 8086/8088
35 push di
36%endif
37 push si
38
39ALIGN UTIL_SIZE_JUMP_ALIGN
40.MagnitudeConversionLoop:
41 ePUSH_T di, .MagnitudeConversionLoop; DI corrupted only on 8086/8088 build
42 test bx, bx ; Bits 32...47 in use?
43 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
44 test dx, dx ; Bits 16...31 in use?
45 jnz SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
46 cmp ax, 10000 ; 5 digits needed?
47 jae SHORT Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
48 add sp, BYTE 2 ; Clean return address from stack
49 xchg si, cx ; CX = Remainder (0...1023), SI = Magnitude
50
51 ; Convert remainder to tenths
52 xchg bx, ax ; Store AX
53 mov ax, 10
54 mul cx ; DX:AX = remainder * 10
55 eSHR_IM ax, 10 ; Divide AX by 1024
56 xchg cx, ax ; CX = tenths
57 xchg ax, bx
58
59 ; Convert magnitude to character
60 mov dl, [cs:si+.rgbMagnitudeToChar]
61
62 pop si
63%ifndef USE_186
64 pop di
65%endif
66 ret
67.rgbMagnitudeToChar: db " kMGTP"
68
69
70;--------------------------------------------------------------------
71; Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
72; Parameters:
73; BX:DX:AX: Size
74; CX: Magnitude in BYTE_MULTIPLES
75; Returns:
76; BX:DX:AX: Size in magnitude
77; SI: Remainder (0...1023)
78; CX: Magnitude in BYTE_MULTIPLES
79; Corrupts registers:
80; Nothing
81;--------------------------------------------------------------------
82ALIGN UTIL_SIZE_JUMP_ALIGN
83Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX:
84 push cx
85 xor si, si ; Zero remainder
86 mov cl, 10 ; Divide by 1024
87ALIGN UTIL_SIZE_JUMP_ALIGN
88.ShiftLoop:
89 call Size_DivideBXDXAXbyTwo
90 rcr si, 1 ; Update remainder
91 loop .ShiftLoop
92 eSHR_IM si, 6 ; Remainder to SI beginning
93 pop cx
94 inc cx ; Increment magnitude
95 ret
96
97
98;--------------------------------------------------------------------
99; Size_ConvertSectorCountInBXDXAXtoKiB
100; Size_DivideBXDXAXbyTwo
101; Parameters:
102; BX:DX:AX: Total sector count
103; Returns:
104; BX:DX:AX: Total size in kiB
105; CF: Remainder from division
106; Corrupts registers:
107; Nothing
108;--------------------------------------------------------------------
109ALIGN UTIL_SIZE_JUMP_ALIGN
110Size_ConvertSectorCountInBXDXAXtoKiB:
111Size_DivideBXDXAXbyTwo:
112 shr bx, 1 ; Divide sector count by 2...
113 rcr dx, 1 ; ...to get disk size in...
114 rcr ax, 1 ; ...kiB
115 ret
Note: See TracBrowser for help on using the repository browser.