]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/CRT/Ia32/lldiv.c
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / LibC / CRT / Ia32 / lldiv.c
1 /** @file
2 64-bit Math Worker Function.
3 The 32-bit versions of C compiler generate calls to library routines
4 to handle 64-bit math. These functions use non-standard calling conventions.
5
6 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include <Library/BaseLib.h>
18
19
20 /*
21 * Divides a 64-bit signed value with a 64-bit signed value and returns
22 * a 64-bit signed result.
23 */
24 __declspec(naked) void __cdecl _alldiv (void)
25 {
26 //
27 // Wrapper Implementation over EDKII DivS64x64Remainder() routine
28 // INT64
29 // EFIAPI
30 // DivS64x64Remainder (
31 // IN UINT64 Dividend,
32 // IN UINT64 Divisor,
33 // OUT UINT64 *Remainder OPTIONAL
34 // )
35 //
36 _asm {
37
38 ;Entry:
39 ; Arguments are passed on the stack:
40 ; 1st pushed: divisor (QWORD)
41 ; 2nd pushed: dividend (QWORD)
42 ;
43 ;Exit:
44 ; EDX:EAX contains the quotient (dividend/divisor)
45 ; NOTE: this routine removes the parameters from the stack.
46 ;
47 ; Original local stack when calling _alldiv
48 ; -----------------
49 ; | |
50 ; |---------------|
51 ; | |
52 ; |-- Divisor --|
53 ; | |
54 ; |---------------|
55 ; | |
56 ; |-- Dividend --|
57 ; | |
58 ; |---------------|
59 ; | ReturnAddr** |
60 ; ESP---->|---------------|
61 ;
62
63 ;
64 ; Set up the local stack for NULL Reminder pointer
65 ;
66 xor eax, eax
67 push eax
68
69 ;
70 ; Set up the local stack for Divisor parameter
71 ;
72 mov eax, [esp + 20]
73 push eax
74 mov eax, [esp + 20]
75 push eax
76
77 ;
78 ; Set up the local stack for Dividend parameter
79 ;
80 mov eax, [esp + 20]
81 push eax
82 mov eax, [esp + 20]
83 push eax
84
85 ;
86 ; Call native DivS64x64Remainder of BaseLib
87 ;
88 call DivS64x64Remainder
89
90 ;
91 ; Adjust stack
92 ;
93 add esp, 20
94
95 ret 16
96 }
97 }