Home | History | Annotate | Download | only in Ia32
      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 unsigned value with a 64-bit unsigned value and returns
     22  * a 64-bit unsigned result.
     23  */
     24 __declspec(naked) void __cdecl _aulldiv (void)
     25 {
     26   //
     27   // Wrapper Implementation over EDKII DivU64x64Reminder() routine
     28   //    UINT64
     29   //    EFIAPI
     30   //    DivU64x64Remainder (
     31   //      IN      UINT64     Dividend,
     32   //      IN      UINT64     Divisor,
     33   //      OUT     UINT64     *Remainder  OPTIONAL
     34   //      )
     35   //
     36   _asm {
     37 
     38     ; Original local stack when calling _aulldiv
     39     ;               -----------------
     40     ;               |               |
     41     ;               |---------------|
     42     ;               |               |
     43     ;               |--  Divisor  --|
     44     ;               |               |
     45     ;               |---------------|
     46     ;               |               |
     47     ;               |--  Dividend --|
     48     ;               |               |
     49     ;               |---------------|
     50     ;               |  ReturnAddr** |
     51     ;       ESP---->|---------------|
     52     ;
     53 
     54     ;
     55     ; Set up the local stack for NULL Reminder pointer
     56     ;
     57     xor  eax, eax
     58     push eax
     59 
     60     ;
     61     ; Set up the local stack for Divisor parameter
     62     ;
     63     mov  eax, [esp + 20]
     64     push eax
     65     mov  eax, [esp + 20]
     66     push eax
     67 
     68     ;
     69     ; Set up the local stack for Dividend parameter
     70     ;
     71     mov  eax, [esp + 20]
     72     push eax
     73     mov  eax, [esp + 20]
     74     push eax
     75 
     76     ;
     77     ; Call native DivU64x64Remainder of BaseLib
     78     ;
     79     call DivU64x64Remainder
     80 
     81     ;
     82     ; Adjust stack
     83     ;
     84     add  esp, 20
     85 
     86     ret  16
     87   }
     88 }
     89