1 /* stuff needed for libgcc on win32.
3 * Copyright (C) 1996, 1998, 2001, 2003, 2008, 2009, 2010
4 * Free Software Foundation, Inc.
5 * Written By Steve Chamberlain
7 * This file is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 3, or (at your option) any
12 * This file is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * Under Section 7 of GPL version 3, you are granted additional
18 * permissions described in the GCC Runtime Library Exception, version
19 * 3.1, as published by the Free Software Foundation.
21 * You should have received a copy of the GNU General Public License and
22 * a copy of the GCC Runtime Library Exception along with this program;
23 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 * <http://www.gnu.org/licenses/>.
27 #include "auto-host.h"
29 #ifdef HAVE_GAS_CFI_SECTIONS_DIRECTIVE
30 .cfi_sections .debug_frame
31 # define cfi_startproc() .cfi_startproc
32 # define cfi_endproc() .cfi_endproc
33 # define cfi_adjust_cfa_offset(X) .cfi_adjust_cfa_offset X
34 # define cfi_def_cfa_register(X) .cfi_def_cfa_register X
35 # define cfi_register(D,S) .cfi_register D, S
37 # define cfi_push(X) .cfi_adjust_cfa_offset 8; .cfi_rel_offset X, 0
38 # define cfi_pop(X) .cfi_adjust_cfa_offset -8; .cfi_restore X
40 # define cfi_push(X) .cfi_adjust_cfa_offset 4; .cfi_rel_offset X, 0
41 # define cfi_pop(X) .cfi_adjust_cfa_offset -4; .cfi_restore X
44 # define cfi_startproc()
45 # define cfi_endproc()
46 # define cfi_adjust_cfa_offset(X)
47 # define cfi_def_cfa_register(X)
48 # define cfi_register(D,S)
51 #endif /* HAVE_GAS_CFI_SECTIONS_DIRECTIVE */
54 /* Function prologue calls __chkstk to probe the stack when allocating more
55 than CHECK_STACK_LIMIT bytes in one go. Touching the stack at 4K
56 increments is necessary to ensure that the guard pages used
57 by the OS virtual memory manger are allocated in correct sequence. */
62 /* __alloca is a normal function call, which uses %rcx as the argument. */
68 /* ___chkstk is a *special* function call, which uses %rax as the argument.
69 We avoid clobbering the 4 integer argument registers, %rcx, %rdx,
70 %r8 and %r9, which leaves us with %rax, %r10, and %r11 to use. */
73 popq %r11 /* pop return address */
74 cfi_adjust_cfa_offset(-8) /* indicate return address in r11 */
75 cfi_register(%rip, %r11)
77 cmpq $0x1000, %rax /* > 4k ?*/
80 1: subq $0x1000, %r10 /* yes, move pointer down 4k*/
81 orl $0x0, (%r10) /* probe there */
82 subq $0x1000, %rax /* decrement count */
84 ja 1b /* and do it again */
87 movq %rsp, %rax /* hold CFA until return */
88 cfi_def_cfa_register(%rax)
89 orl $0x0, (%r10) /* less than 4k, just peek here */
90 movq %r10, %rsp /* decrement stack */
92 /* Push the return value back. Doing this instead of just
93 jumping to %r11 preserves the cached call-return stack
94 used by most modern processors. */
102 pushl %ecx /* save temp */
104 leal 8(%esp), %ecx /* point past return addr */
105 cmpl $0x1000, %eax /* > 4k ?*/
108 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
109 orl $0x0, (%ecx) /* probe there */
110 subl $0x1000, %eax /* decrement count */
112 ja 1b /* and do it again */
115 orl $0x0, (%ecx) /* less than 4k, just peek here */
116 movl %esp, %eax /* save current stack pointer */
117 cfi_def_cfa_register(%eax)
118 movl %ecx, %esp /* decrement stack */
119 movl (%eax), %ecx /* recover saved temp */
121 /* Copy the return register. Doing this instead of just jumping to
122 the address preserves the cached call-return stack used by most
123 modern processors. */
128 #endif /* L_chkstk */
131 /* ___chkstk_ms is a *special* function call, which uses %rax as the argument.
132 We avoid clobbering any registers. Unlike ___chkstk, it just probes the
133 stack and does no stack allocation. */
138 pushq %rcx /* save temps */
142 cmpq $0x1000, %rax /* > 4k ?*/
143 leaq 24(%rsp), %rcx /* point past return addr */
146 1: subq $0x1000, %rcx /* yes, move pointer down 4k */
147 orq $0x0, (%rcx) /* probe there */
148 subq $0x1000, %rax /* decrement count */
150 ja 1b /* and do it again */
153 orq $0x0, (%rcx) /* less than 4k, just peek here */
164 pushl %ecx /* save temp */
168 cmpl $0x1000, %eax /* > 4k ?*/
169 leal 12(%esp), %ecx /* point past return addr */
172 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
173 orl $0x0, (%ecx) /* probe there */
174 subl $0x1000, %eax /* decrement count */
176 ja 1b /* and do it again */
179 orl $0x0, (%ecx) /* less than 4k, just peek here */
188 #endif /* L_chkstk_ms */