2008-07-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / gcc / config / i386 / cygwin.asm
blob90d9f31ca32c32dc8452e9b0cfda48e3f9b42177
1 /* stuff needed for libgcc on win32.
3 * Copyright (C) 1996, 1998, 2001, 2003 Free Software Foundation, Inc.
4 * Written By Steve Chamberlain
5 *
6 * This file is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
11 * In addition to the permissions in the GNU General Public License, the
12 * Free Software Foundation gives you unlimited permission to link the
13 * compiled version of this file with other programs, and to distribute
14 * those programs without any restriction coming from the use of this
15 * file. (The General Public License restrictions do apply in other
16 * respects; for example, they cover modification of the file, and
17 * distribution when not linked into another program.)
19 * This file is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; see the file COPYING. If not, write to
26 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27 * Boston, MA 02110-1301, USA.
29 * As a special exception, if you link this library with files
30 * compiled with GCC to produce an executable, this does not cause
31 * the resulting executable to be covered by the GNU General Public License.
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
36 #ifdef L_chkstk
38 /* Function prologue calls _alloca to probe the stack when allocating more
39 than CHECK_STACK_LIMIT bytes in one go. Touching the stack at 4K
40 increments is necessary to ensure that the guard pages used
41 by the OS virtual memory manger are allocated in correct sequence. */
43 .global ___chkstk
44 .global __alloca
45 #ifndef _WIN64
46 ___chkstk:
47 __alloca:
48 pushl %ecx /* save temp */
49 leal 8(%esp), %ecx /* point past return addr */
50 cmpl $0x1000, %eax /* > 4k ?*/
51 jb Ldone
53 Lprobe:
54 subl $0x1000, %ecx /* yes, move pointer down 4k*/
55 orl $0x0, (%ecx) /* probe there */
56 subl $0x1000, %eax /* decrement count */
57 cmpl $0x1000, %eax
58 ja Lprobe /* and do it again */
60 Ldone:
61 subl %eax, %ecx
62 orl $0x0, (%ecx) /* less than 4k, just peek here */
64 movl %esp, %eax /* save old stack pointer */
65 movl %ecx, %esp /* decrement stack */
66 movl (%eax), %ecx /* recover saved temp */
67 movl 4(%eax), %eax /* recover return address */
69 /* Push the return value back. Doing this instead of just
70 jumping to %eax preserves the cached call-return stack
71 used by most modern processors. */
72 pushl %eax
73 ret
74 #else
75 /* __alloca is a normal function call, which uses %rcx as the argument. And stack space
76 for the argument is saved. */
77 __alloca:
78 movq %rcx, %rax
79 addq $0x7, %rax
80 andq $0xfffffffffffffff8, %rax
81 popq %rcx /* pop return address */
82 popq %r10 /* Pop the reserved stack space. */
83 movq %rsp, %r10 /* get sp */
84 cmpq $0x1000, %rax /* > 4k ?*/
85 jb Ldone_alloca
87 Lprobe_alloca:
88 subq $0x1000, %r10 /* yes, move pointer down 4k*/
89 orq $0x0, (%r10) /* probe there */
90 subq $0x1000, %rax /* decrement count */
91 cmpq $0x1000, %rax
92 ja Lprobe_alloca /* and do it again */
94 Ldone_alloca:
95 subq %rax, %r10
96 orq $0x0, (%r10) /* less than 4k, just peek here */
97 movq %r10, %rax
98 subq $0x8, %r10 /* Reserve argument stack space. */
99 movq %r10, %rsp /* decrement stack */
101 /* Push the return value back. Doing this instead of just
102 jumping to %rcx preserves the cached call-return stack
103 used by most modern processors. */
104 pushq %rcx
107 /* ___chkstk is a *special* function call, which uses %rax as the argument.
108 We avoid clobbering the 4 integer argument registers, %rcx, %rdx,
109 %r8 and %r9, which leaves us with %rax, %r10, and %r11 to use. */
110 ___chkstk:
111 addq $0x7, %rax /* Make sure stack is on alignment of 8. */
112 andq $0xfffffffffffffff8, %rax
113 popq %r11 /* pop return address */
114 movq %rsp, %r10 /* get sp */
115 cmpq $0x1000, %rax /* > 4k ?*/
116 jb Ldone
118 Lprobe:
119 subq $0x1000, %r10 /* yes, move pointer down 4k*/
120 orl $0x0, (%r10) /* probe there */
121 subq $0x1000, %rax /* decrement count */
122 cmpq $0x1000, %rax
123 ja Lprobe /* and do it again */
125 Ldone:
126 subq %rax, %r10
127 orl $0x0, (%r10) /* less than 4k, just peek here */
128 movq %r10, %rsp /* decrement stack */
130 /* Push the return value back. Doing this instead of just
131 jumping to %r11 preserves the cached call-return stack
132 used by most modern processors. */
133 pushq %r11
135 #endif
136 #endif