xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/chkstk.S (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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// This clobbers registers x16 and x17.
12// Does not modify any memory or the stack pointer.
13
14//      mov     x15, #256 // Number of bytes of stack, in units of 16 byte
15//      bl      __chkstk
16//      sub     sp, sp, x15, lsl #4
17
18#ifdef __aarch64__
19
20#define PAGE_SIZE 4096
21
22        .p2align 2
23DEFINE_COMPILERRT_FUNCTION(__chkstk)
24        lsl    x16, x15, #4
25        mov    x17, sp
261:
27        sub    x17, x17, #PAGE_SIZE
28        subs   x16, x16, #PAGE_SIZE
29        ldr    xzr, [x17]
30        b.gt   1b
31
32        ret
33END_COMPILERRT_FUNCTION(__chkstk)
34
35#endif // __aarch64__
36