1 // This file is dual licensed under the MIT and the University of Illinois Open
2 // Source Licenses. See LICENSE.TXT for details.
4 #include "../assembly.h"
8 // _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments,
9 // then decrement %esp by %eax. Preserves all registers except %esp and flags.
10 // This routine is windows specific
11 // http://msdn.microsoft.com/en-us/library/ms648426.aspx
15 DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
16 DEFINE_COMPILERRT_FUNCTION(__chkstk)
19 lea 8(%esp),%ecx // esp before calling this routine -> ecx
31 lea 4(%esp),%eax // load pointer to the return address into eax
32 mov %ecx,%esp // install the new top of stack pointer into esp
33 mov -4(%eax),%ecx // restore ecx
34 push (%eax) // push return address onto the stack
35 sub %esp,%eax // restore the original value in eax
37 END_COMPILERRT_FUNCTION(__chkstk)
38 END_COMPILERRT_FUNCTION(_alloca)