1353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2353358Sdim// See https://llvm.org/LICENSE.txt for license information.
3353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4336817Sdim
5336817Sdim#include "../assembly.h"
6336817Sdim
7336817Sdim// __chkstk routine
8336817Sdim// This routine is windows specific.
9336817Sdim// http://msdn.microsoft.com/en-us/library/ms648426.aspx
10336817Sdim
11336817Sdim// This clobbers the register r12, and the condition codes, and uses r5 and r6
12336817Sdim// as temporaries by backing them up and restoring them afterwards.
13336817Sdim// Does not modify any memory or the stack pointer.
14336817Sdim
15336817Sdim//      movw    r4,  #256 // Number of bytes of stack, in units of 4 byte
16336817Sdim//      bl      __chkstk
17336817Sdim//      sub.w   sp, sp, r4
18336817Sdim
19336817Sdim#define PAGE_SIZE 4096
20336817Sdim
21336817Sdim        .p2align 2
22336817SdimDEFINE_COMPILERRT_FUNCTION(__chkstk)
23336817Sdim        lsl    r4,  r4,  #2
24336817Sdim        mov    r12, sp
25336817Sdim        push   {r5, r6}
26336817Sdim        mov    r5,  r4
27336817Sdim1:
28336817Sdim        sub    r12, r12, #PAGE_SIZE
29336817Sdim        subs   r5,  r5,  #PAGE_SIZE
30336817Sdim        ldr    r6,  [r12]
31336817Sdim        bgt    1b
32336817Sdim
33336817Sdim        pop    {r5, r6}
34336817Sdim        bx     lr
35336817SdimEND_COMPILERRT_FUNCTION(__chkstk)
36