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 | #if defined(__aarch64__) || defined(__arm64ec__) |
19 | |
20 | #ifdef __arm64ec__ |
21 | #define CHKSTK_FUNC __chkstk_arm64ec |
22 | #else |
23 | #define CHKSTK_FUNC __chkstk |
24 | #endif |
25 | |
26 | #define PAGE_SIZE 4096 |
27 | |
28 | .p2align 2 |
29 | DEFINE_COMPILERRT_FUNCTION(CHKSTK_FUNC) |
30 | lsl x16, x15, #4 |
31 | mov x17, sp |
32 | 1: |
33 | sub x17, x17, #PAGE_SIZE |
34 | subs x16, x16, #PAGE_SIZE |
35 | ldr xzr, [x17] |
36 | b.gt 1b |
37 | |
38 | ret |
39 | END_COMPILERRT_FUNCTION(CHKSTK_FUNC) |
40 | |
41 | #endif // defined(__aarch64__) || defined(__arm64ec__) |
42 |