]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/Ia32/Alloca.S
Add CryptoPkg (from UDK2010.UP3)
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / Ia32 / Alloca.S
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/Ia32/Alloca.S b/CryptoPkg/Library/BaseCryptLib/SysCall/Ia32/Alloca.S
new file mode 100644 (file)
index 0000000..8496833
--- /dev/null
@@ -0,0 +1,59 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2009 - 2010, 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
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+#   Alloca.S\r
+#\r
+# Abstract:\r
+#\r
+#   Implementation for allocation of automatically reclaimed memory, which is\r
+#   used to allocate space off the runtime stack.\r
+#   (NOTE: There is a assumption in this code that the page size equal to 4K)\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+\r
+    .686:\r
+    .code:\r
+\r
+ASM_GLOBAL ASM_PFX(_alloca)\r
+\r
+#------------------------------------------------------------------------------\r
+#\r
+# void __cdecl _alloca (unsigned size)\r
+#\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(_alloca):\r
+\r
+    pushl   %ecx\r
+    cmpl    $0x1000, %eax\r
+    leal    8(%esp), %ecx\r
+    jb      LastPage\r
+\r
+ProbePages:\r
+    subl    $0x1000, %ecx\r
+    subl    $0x1000, %eax\r
+    testl   %eax, 0(%ecx)\r
+    cmpl    $0x1000, %eax\r
+    jae     ProbePages\r
+\r
+LastPage:\r
+    subl    %eax, %ecx\r
+    movl    %esp, %eax\r
+    testl   %eax, 0(%ecx)\r
+\r
+    movl    %ecx, %esp\r
+    movl    0(%eax), %ecx\r
+    movl    4(%eax), %eax\r
+    pushl   %eax\r
+\r
+    ret\r