Home | History | Annotate | Line # | Download | only in i386
      1  1.1  joerg // This file is dual licensed under the MIT and the University of Illinois Open
      2  1.1  joerg // Source Licenses. See LICENSE.TXT for details.
      3  1.1  joerg 
      4  1.1  joerg #include "../assembly.h"
      5  1.1  joerg 
      6  1.1  joerg #ifdef __i386__
      7  1.1  joerg 
      8  1.1  joerg // _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments,
      9  1.1  joerg // then decrement %esp by %eax.  Preserves all registers except %esp and flags.
     10  1.1  joerg // This routine is windows specific
     11  1.1  joerg // http://msdn.microsoft.com/en-us/library/ms648426.aspx
     12  1.1  joerg 
     13  1.1  joerg .text
     14  1.1  joerg .balign 4
     15  1.1  joerg DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
     16  1.1  joerg DEFINE_COMPILERRT_FUNCTION(__chkstk)
     17  1.1  joerg         push   %ecx
     18  1.1  joerg         cmp    $0x1000,%eax
     19  1.1  joerg         lea    8(%esp),%ecx     // esp before calling this routine -> ecx
     20  1.1  joerg         jb     1f
     21  1.1  joerg 2:
     22  1.1  joerg         sub    $0x1000,%ecx
     23  1.1  joerg         test   %ecx,(%ecx)
     24  1.1  joerg         sub    $0x1000,%eax
     25  1.1  joerg         cmp    $0x1000,%eax
     26  1.1  joerg         ja     2b
     27  1.1  joerg 1:
     28  1.1  joerg         sub    %eax,%ecx
     29  1.1  joerg         test   %ecx,(%ecx)
     30  1.1  joerg 
     31  1.1  joerg         lea    4(%esp),%eax     // load pointer to the return address into eax
     32  1.1  joerg         mov    %ecx,%esp        // install the new top of stack pointer into esp
     33  1.1  joerg         mov    -4(%eax),%ecx    // restore ecx
     34  1.1  joerg         push   (%eax)           // push return address onto the stack
     35  1.1  joerg         sub    %esp,%eax        // restore the original value in eax
     36  1.1  joerg         ret
     37  1.1  joerg END_COMPILERRT_FUNCTION(__chkstk)
     38  1.1  joerg END_COMPILERRT_FUNCTION(_alloca)
     39  1.1  joerg 
     40  1.1  joerg #endif // __i386__
     41