]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.S
Fix X64 native function call prolog. Prepare space for at least 4 arguments,
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / X64 / EbcLowLevel.S
index 859cbce24cd1e8d3140f8d265974f23d4a58164a..b01486a87188b262e94c9ae3e37ba972be9dc0f3 100644 (file)
@@ -3,7 +3,7 @@
 #    This code provides low level routines that support the Virtual Machine\r
 #   for option ROMs.\r
 #  \r
-#  Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
@@ -46,7 +46,34 @@ ASM_PFX(EbcLLCALLEXNative):
 \r
       # Set stack pointer to new value\r
       sub    %rdx, %r8  \r
+      \r
+      #\r
+      # Fix X64 native function call prolog. Prepare space for at least 4 arguments,\r
+      # even if the native function's arguments are less than 4.\r
+      #\r
+      # From MSDN x64 Software Conventions, Overview of x64 Calling Conventions:\r
+      #   "The caller is responsible for allocating space for parameters to the\r
+      #   callee, and must always allocate sufficient space for the 4 register\r
+      #   parameters, even if the callee doesn't have that many parameters.\r
+      #   This aids in the simplicity of supporting C unprototyped functions,\r
+      #   and vararg C/C++ functions."\r
+      #\r
+      cmp    $0x20, %r8\r
+      jae    skip_expansion\r
+      mov    $0x20, %r8\r
+skip_expansion:\r
+      \r
       sub    %r8,  %rsp \r
+      \r
+      #\r
+      # Fix X64 native function call 16-byte alignment.\r
+      #\r
+      # From MSDN x64 Software Conventions, Stack Usage:\r
+      #   "The stack will always be maintained 16-byte aligned, except within \r
+      #   the prolog (for example, after the return address is pushed)."\r
+      #\r
+      and    $0xFFFFFFFFFFFFFFF0, %rsp\r
+      \r
       mov    %rsp, %rcx\r
       sub    $0x20, %rsp \r
       call   ASM_PFX(CopyMem)\r