1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2// See https://llvm.org/LICENSE.txt for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#include "../assembly.h"
6
7// _chkstk routine
8// This routine is windows specific
9// http://msdn.microsoft.com/en-us/library/ms648426.aspx
10
11// Notes from r227519
12// MSVC x64s __chkstk and cygmings ___chkstk_ms do not adjust %rsp
13// themselves. It also does not clobber %rax so we can reuse it when
14// adjusting %rsp.
15
16#ifdef __x86_64__
17
18.text
19.balign 4
20DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
21 push %rcx
22 push %rax
23 cmp $0x1000,%rax
24 lea 24(%rsp),%rcx
25 jb 1f
262:
27 sub $0x1000,%rcx
28 test %rcx,(%rcx)
29 sub $0x1000,%rax
30 cmp $0x1000,%rax
31 ja 2b
321:
33 sub %rax,%rcx
34 test %rcx,(%rcx)
35 pop %rax
36 pop %rcx
37 ret
38END_COMPILERRT_FUNCTION(___chkstk_ms)
39
40#endif // __x86_64__
41

source code of compiler-rt/lib/builtins/x86_64/chkstk.S