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
5 #include "../assembly.h"
9 // _chkstk (_alloca) routine - probe stack between %rsp and (%rsp-%rax) in 4k increments,
10 // then decrement %rsp by %rax. Preserves all registers except %rsp and flags.
11 // This routine is windows specific
12 // http://msdn.microsoft.com/en-us/library/ms648426.aspx
16 DEFINE_COMPILERRT_FUNCTION(__alloca)
17 mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
19 DEFINE_COMPILERRT_FUNCTION(___chkstk)
22 lea 16(%rsp),%rcx // rsp before calling this routine -> rcx
34 lea 8(%rsp),%rax // load pointer to the return address into rax
35 mov %rcx,%rsp // install the new top of stack pointer into rsp
36 mov -8(%rax),%rcx // restore rcx
37 push (%rax) // push return address onto the stack
38 sub %rsp,%rax // restore the original value in rax
40 END_COMPILERRT_FUNCTION(___chkstk)
41 END_COMPILERRT_FUNCTION(__alloca)