1 /* stuff needed for libgcc on win32.
3 * Copyright (C) 1996-2018 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 #ifdef HAVE_GAS_CFI_SECTIONS_DIRECTIVE
27 # define USE_GAS_CFI_DIRECTIVES 1
28 .cfi_sections .debug_frame
30 # define USE_GAS_CFI_DIRECTIVES 0
35 /* Function prologue calls __chkstk to probe the stack when allocating more
36 than CHECK_STACK_LIMIT bytes in one go. Touching the stack at 4K
37 increments is necessary to ensure that the guard pages used
38 by the OS virtual memory manger are allocated in correct sequence. */
43 /* __alloca is a normal function call, which uses %rcx as the argument. */
49 /* ___chkstk is a *special* function call, which uses %rax as the argument.
50 We avoid clobbering the 4 integer argument registers, %rcx, %rdx,
51 %r8 and %r9, which leaves us with %rax, %r10, and %r11 to use. */
54 popq %r11 /* pop return address */
55 cfi_adjust_cfa_offset(-8) /* indicate return address in r11 */
56 cfi_register(%rip, %r11)
58 cmpq $0x1000, %rax /* > 4k ?*/
61 1: subq $0x1000, %r10 /* yes, move pointer down 4k*/
62 orl $0x0, (%r10) /* probe there */
63 subq $0x1000, %rax /* decrement count */
65 ja 1b /* and do it again */
68 movq %rsp, %rax /* hold CFA until return */
69 cfi_def_cfa_register(%rax)
70 orl $0x0, (%r10) /* less than 4k, just peek here */
71 movq %r10, %rsp /* decrement stack */
73 /* Push the return value back. Doing this instead of just
74 jumping to %r11 preserves the cached call-return stack
75 used by most modern processors. */
83 pushl %ecx /* save temp */
85 leal 8(%esp), %ecx /* point past return addr */
86 cmpl $0x1000, %eax /* > 4k ?*/
89 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
90 orl $0x0, (%ecx) /* probe there */
91 subl $0x1000, %eax /* decrement count */
93 ja 1b /* and do it again */
96 orl $0x0, (%ecx) /* less than 4k, just peek here */
97 movl %esp, %eax /* save current stack pointer */
98 cfi_def_cfa_register(%eax)
99 movl %ecx, %esp /* decrement stack */
100 movl (%eax), %ecx /* recover saved temp */
102 /* Copy the return register. Doing this instead of just jumping to
103 the address preserves the cached call-return stack used by most
104 modern processors. */
108 #endif /* __x86_64__ */
109 #endif /* L_chkstk */
112 /* ___chkstk_ms is a *special* function call, which uses %rax as the argument.
113 We avoid clobbering any registers. Unlike ___chkstk, it just probes the
114 stack and does no stack allocation. */
119 pushq %rcx /* save temps */
123 cmpq $0x1000, %rax /* > 4k ?*/
124 leaq 24(%rsp), %rcx /* point past return addr */
127 1: subq $0x1000, %rcx /* yes, move pointer down 4k */
128 orq $0x0, (%rcx) /* probe there */
129 subq $0x1000, %rax /* decrement count */
131 ja 1b /* and do it again */
134 orq $0x0, (%rcx) /* less than 4k, just peek here */
145 pushl %ecx /* save temp */
149 cmpl $0x1000, %eax /* > 4k ?*/
150 leal 12(%esp), %ecx /* point past return addr */
153 1: subl $0x1000, %ecx /* yes, move pointer down 4k*/
154 orl $0x0, (%ecx) /* probe there */
155 subl $0x1000, %eax /* decrement count */
157 ja 1b /* and do it again */
160 orl $0x0, (%ecx) /* less than 4k, just peek here */
168 #endif /* __x86_64__ */
169 #endif /* L_chkstk_ms */