1132718Skan/* stuff needed for libgcc on win32.
2132718Skan *
3132718Skan *   Copyright (C) 1996, 1998, 2001, 2003 Free Software Foundation, Inc.
4132718Skan *   Written By Steve Chamberlain
5132718Skan * 
6132718Skan * This file is free software; you can redistribute it and/or modify it
7132718Skan * under the terms of the GNU General Public License as published by the
8132718Skan * Free Software Foundation; either version 2, or (at your option) any
9132718Skan * later version.
10132718Skan * 
11132718Skan * In addition to the permissions in the GNU General Public License, the
12132718Skan * Free Software Foundation gives you unlimited permission to link the
13132718Skan * compiled version of this file with other programs, and to distribute
14132718Skan * those programs without any restriction coming from the use of this
15132718Skan * file.  (The General Public License restrictions do apply in other
16132718Skan * respects; for example, they cover modification of the file, and
17132718Skan * distribution when not linked into another program.)
18132718Skan * 
19132718Skan * This file is distributed in the hope that it will be useful, but
20132718Skan * WITHOUT ANY WARRANTY; without even the implied warranty of
21132718Skan * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22132718Skan * General Public License for more details.
23132718Skan * 
24132718Skan * You should have received a copy of the GNU General Public License
25132718Skan * along with this program; see the file COPYING.  If not, write to
26169689Skan * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27169689Skan * Boston, MA 02110-1301, USA.
28132718Skan * 
29132718Skan *    As a special exception, if you link this library with files
30132718Skan *    compiled with GCC to produce an executable, this does not cause
31132718Skan *    the resulting executable to be covered by the GNU General Public License.
32132718Skan *    This exception does not however invalidate any other reasons why
33132718Skan *    the executable file might be covered by the GNU General Public License.
34132718Skan */
3552284Sobrien
3652284Sobrien#ifdef L_chkstk
3752284Sobrien
38132718Skan/* Function prologue calls _alloca to probe the stack when allocating more
39132718Skan   than CHECK_STACK_LIMIT bytes in one go.  Touching the stack at 4K
40132718Skan   increments is necessary to ensure that the guard pages used
41132718Skan   by the OS virtual memory manger are allocated in correct sequence.  */
42132718Skan
4352284Sobrien	.global ___chkstk
4452284Sobrien	.global	__alloca
4552284Sobrien___chkstk:
4652284Sobrien__alloca:
4752284Sobrien	pushl  %ecx		/* save temp */
4852284Sobrien	movl   %esp,%ecx	/* get sp */
4952284Sobrien	addl   $0x8,%ecx	/* and point to return addr */
5052284Sobrien
5152284Sobrienprobe: 	cmpl   $0x1000,%eax	/* > 4k ?*/
5252284Sobrien	jb    done		
5352284Sobrien
5452284Sobrien	subl   $0x1000,%ecx  		/* yes, move pointer down 4k*/
5552284Sobrien	orl    $0x0,(%ecx)   		/* probe there */
5652284Sobrien	subl   $0x1000,%eax  	 	/* decrement count */
5752284Sobrien	jmp    probe           	 	/* and do it again */
5852284Sobrien
5952284Sobriendone: 	subl   %eax,%ecx	   
6052284Sobrien	orl    $0x0,(%ecx)	/* less that 4k, just peek here */
6152284Sobrien
6252284Sobrien	movl   %esp,%eax
6352284Sobrien	movl   %ecx,%esp	/* decrement stack */
6452284Sobrien
6552284Sobrien	movl   (%eax),%ecx	/* recover saved temp */
6652284Sobrien	movl   4(%eax),%eax	/* get return address */
6752284Sobrien	jmp    *%eax	
6852284Sobrien#endif
69