]>
Commit | Line | Data |
---|---|---|
b341712e | 1 | #---------------------------------------------------------------------------\r |
2 | #/*++\r | |
3 | #\r | |
4ea9375a HT |
4 | #Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r |
5 | #This program and the accompanying materials \r | |
b341712e | 6 | #are licensed and made available under the terms and conditions of the BSD License \r |
7 | #which accompanies this distribution. The full text of the license may be found at \r | |
8 | #http://opensource.org/licenses/bsd-license.php \r | |
9 | # \r | |
10 | #THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | #WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | #\r | |
13 | #Module Name:\r | |
14 | #\r | |
15 | # DivU64x32.c\r | |
16 | #\r | |
17 | #Abstract:\r | |
18 | #\r | |
19 | # 64-bit division function for IA-32\r | |
20 | #\r | |
21 | #--*/\r | |
22 | \r | |
23 | #---------------------------------------------------------------------------\r | |
24 | #include "EfiBind.h" //For ASM_PFX\r | |
25 | #---------------------------------------------------------------------------\r | |
26 | \r | |
27 | #---------------------------------------------------------------------------\r | |
28 | .386: \r | |
29 | .code: \r | |
30 | \r | |
31 | #---------------------------------------------------------------------------\r | |
32 | \r | |
33 | .globl ASM_PFX(DivU64x32)\r | |
34 | \r | |
35 | #UINT64\r | |
36 | #DivU64x32 (\r | |
37 | # IN UINT64 Dividend,\r | |
38 | # IN UINTN Divisor,\r | |
39 | # OUT UINTN *Remainder OPTIONAL\r | |
40 | # )\r | |
41 | #/*++\r | |
42 | \r | |
43 | #Routine Description:\r | |
44 | \r | |
45 | # This routine allows a 64 bit value to be divided with a 32 bit value returns \r | |
46 | # 64bit result and the Remainder.\r | |
47 | #\r | |
48 | #Arguments:\r | |
49 | \r | |
50 | # Dividend - dividend\r | |
51 | # Divisor - divisor\r | |
52 | # Remainder - buffer for remainder\r | |
53 | # \r | |
54 | #Returns:\r | |
55 | \r | |
56 | # Dividend / Divisor\r | |
57 | # Remainder = Dividend mod Divisor\r | |
58 | # \r | |
59 | #N.B. only works for 31bit divisors!!\r | |
60 | #\r | |
61 | #--*/\r | |
62 | #---------------------------------------------------------------------------\r | |
63 | \r | |
64 | ASM_PFX(DivU64x32):\r | |
65 | pushl %ebp\r | |
66 | movl %esp, %ebp\r | |
67 | xorl %edx, %edx # Clear EDX\r | |
68 | \r | |
69 | movl 0xC(%ebp), %eax # Put high 32 bits of 64-bit dividend in EAX\r | |
70 | movl 0x10(%ebp), %ecx # Put 32 bits divisor in ECX\r | |
71 | divl %ecx # Dividend Divisor Quoitent...Remainder\r | |
72 | # 0:EAX / ECX = EAX EDX \r | |
73 | \r | |
74 | pushl %eax # Push quoitent in stack\r | |
75 | \r | |
76 | movl 8(%ebp), %eax # Put low 32 bits of 64-bit dividend in EAX \r | |
77 | divl %ecx # Leave the REMAINDER in EDX as High 32-bit of new dividend\r | |
78 | # Dividend Divisor Quoitent...Remainder \r | |
79 | # EDX:EAX / ECX = EAX EDX \r | |
80 | \r | |
81 | movl 0x14(%ebp), %ecx # Put &REMAINDER to ecx\r | |
82 | \r | |
83 | jecxz Label1 # If ecx == 0, no remainder exist, return with quoitent in EDX directly \r | |
84 | movl %edx, (%ecx) # Put EDX through REMAINDER pointer in ECX \r | |
85 | \r | |
86 | Label1: \r | |
87 | popl %edx # Pop High 32-bit QUOITENT to EDX\r | |
88 | popl %ebp\r | |
89 | \r | |
90 | ret\r | |
91 | \r |