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