1 /* stuff needed for libgcc on win32.
3 * Copyright (C) 1996-2017 Free Software Foundation, Inc.
4 * Written By Steve Chamberlain
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 3, or (at your option) any
11 * This file is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * Under Section 7 of GPL version 3, you are granted additional
17 * permissions described in the GCC Runtime Library Exception, version
18 * 3.1, as published by the Free Software Foundation.
20 * You should have received a copy of the GNU General Public License and
21 * a copy of the GCC Runtime Library Exception along with this program;
22 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 * <http://www.gnu.org/licenses/>.
26 #include "auto-host.h"
28 #ifdef HAVE_GAS_CFI_SECTIONS_DIRECTIVE
29 .cfi_sections .debug_frame
30 # define cfi_startproc() .cfi_startproc
31 # define cfi_endproc() .cfi_endproc
32 # define cfi_adjust_cfa_offset(X) .cfi_adjust_cfa_offset X
33 # define cfi_def_cfa_register(X) .cfi_def_cfa_register X
34 # define cfi_register(D,S) .cfi_register D, S
36 # define cfi_push(X) .cfi_adjust_cfa_offset 8; .cfi_rel_offset X, 0
37 # define cfi_pop(X) .cfi_adjust_cfa_offset -8; .cfi_restore X
39 # define cfi_push(X) .cfi_adjust_cfa_offset 4; .cfi_rel_offset X, 0
40 # define cfi_pop(X) .cfi_adjust_cfa_offset -4; .cfi_restore X
43 # define cfi_startproc()
44 # define cfi_endproc()
45 # define cfi_adjust_cfa_offset(X)
46 # define cfi_def_cfa_register(X)
47 # define cfi_register(D,S)
50 #endif /* HAVE_GAS_CFI_SECTIONS_DIRECTIVE */
53 /* Function prologue calls __chkstk to probe the stack when allocating more
54 than CHECK_STACK_LIMIT bytes in one go. Touching the stack at 4K
55 increments is necessary to ensure that the guard pages used
56 by the OS virtual memory manger are allocated in correct sequence. */
61 /* __alloca is a normal function call, which uses %rcx as the argument. */
67 /* ___chkstk is a *special* function call, which uses %rax as the argument.
68 We avoid clobbering the 4 integer argument registers, %rcx, %rdx,
69 %r8 and %r9, which leaves us with %rax, %r10, and %r11 to use. */
72 popq %r11 /* pop return address */
73 cfi_adjust_cfa_offset(-8) /* indicate return address in r11 */
74 cfi_register(%rip, %r11)
76 cmpq $0x1000, %rax /* > 4k ?*/
79 1: subq $0x1000, %r10 /* yes, move pointer down 4k*/
80 orl $0x0, (%r10) /* probe there */
81 subq $0x1000, %rax /* decrement count */
83 ja 1b /* and do it again */
86 movq %rsp, %rax /* hold CFA until return */
87 cfi_def_cfa_register(%rax)
88 orl $0x0, (%r10) /* less than 4k, just peek here */
89 movq %r10, %rsp /* decrement stack */
91 /* Push the return value back. Doing this instead of just
92 jumping to %r11 preserves the cached call-return stack
93 used by most modern processors. */
101 pushl %ecx /* save temp */
103 leal 8(%esp), %ecx /* point past return addr */
104 cmpl $0x1000, %eax /* > 4k ?*/
107 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
108 orl $0x0, (%ecx) /* probe there */
109 subl $0x1000, %eax /* decrement count */
111 ja 1b /* and do it again */
114 orl $0x0, (%ecx) /* less than 4k, just peek here */
115 movl %esp, %eax /* save current stack pointer */
116 cfi_def_cfa_register(%eax)
117 movl %ecx, %esp /* decrement stack */
118 movl (%eax), %ecx /* recover saved temp */
120 /* Copy the return register. Doing this instead of just jumping to
121 the address preserves the cached call-return stack used by most
122 modern processors. */
126 #endif /* __x86_64__ */
127 #endif /* L_chkstk */
130 /* ___chkstk_ms is a *special* function call, which uses %rax as the argument.
131 We avoid clobbering any registers. Unlike ___chkstk, it just probes the
132 stack and does no stack allocation. */
137 pushq %rcx /* save temps */
141 cmpq $0x1000, %rax /* > 4k ?*/
142 leaq 24(%rsp), %rcx /* point past return addr */
145 1: subq $0x1000, %rcx /* yes, move pointer down 4k */
146 orq $0x0, (%rcx) /* probe there */
147 subq $0x1000, %rax /* decrement count */
149 ja 1b /* and do it again */
152 orq $0x0, (%rcx) /* less than 4k, just peek here */
163 pushl %ecx /* save temp */
167 cmpl $0x1000, %eax /* > 4k ?*/
168 leal 12(%esp), %ecx /* point past return addr */
171 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
172 orl $0x0, (%ecx) /* probe there */
173 subl $0x1000, %eax /* decrement count */
175 ja 1b /* and do it again */
178 orl $0x0, (%ecx) /* less than 4k, just peek here */
186 #endif /* __x86_64__ */
187 #endif /* L_chkstk_ms */