1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 #include "../assembly.h"
9 // _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments,
10 // then decrement %esp by %eax. Preserves all registers except %esp and flags.
11 // This routine is windows specific
12 // http://msdn.microsoft.com/en-us/library/ms648426.aspx
16 DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
17 DEFINE_COMPILERRT_FUNCTION(_chkstk)
20 lea 8(%esp),%ecx // esp before calling this routine -> ecx
32 lea 4(%esp),%eax // load pointer to the return address into eax
33 mov %ecx,%esp // install the new top of stack pointer into esp
34 mov -4(%eax),%ecx // restore ecx
35 push (%eax) // push return address onto the stack
36 sub %esp,%eax // restore the original value in eax
38 END_COMPILERRT_FUNCTION(_chkstk)
39 END_COMPILERRT_FUNCTION(_alloca)