xref: /openbsd-src/gnu/llvm/compiler-rt/lib/builtins/arm/chkstk.S (revision 3cab2bb3f667058bece8e38b12449a63a9d73c4b)
1*3cab2bb3Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2*3cab2bb3Spatrick// See https://llvm.org/LICENSE.txt for license information.
3*3cab2bb3Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4*3cab2bb3Spatrick
5*3cab2bb3Spatrick#include "../assembly.h"
6*3cab2bb3Spatrick
7*3cab2bb3Spatrick// __chkstk routine
8*3cab2bb3Spatrick// This routine is windows specific.
9*3cab2bb3Spatrick// http://msdn.microsoft.com/en-us/library/ms648426.aspx
10*3cab2bb3Spatrick
11*3cab2bb3Spatrick// This clobbers the register r12, and the condition codes, and uses r5 and r6
12*3cab2bb3Spatrick// as temporaries by backing them up and restoring them afterwards.
13*3cab2bb3Spatrick// Does not modify any memory or the stack pointer.
14*3cab2bb3Spatrick
15*3cab2bb3Spatrick//      movw    r4,  #256 // Number of bytes of stack, in units of 4 byte
16*3cab2bb3Spatrick//      bl      __chkstk
17*3cab2bb3Spatrick//      sub.w   sp, sp, r4
18*3cab2bb3Spatrick
19*3cab2bb3Spatrick#define PAGE_SIZE 4096
20*3cab2bb3Spatrick
21*3cab2bb3Spatrick        .p2align 2
22*3cab2bb3SpatrickDEFINE_COMPILERRT_FUNCTION(__chkstk)
23*3cab2bb3Spatrick        lsl    r4,  r4,  #2
24*3cab2bb3Spatrick        mov    r12, sp
25*3cab2bb3Spatrick        push   {r5, r6}
26*3cab2bb3Spatrick        mov    r5,  r4
27*3cab2bb3Spatrick1:
28*3cab2bb3Spatrick        sub    r12, r12, #PAGE_SIZE
29*3cab2bb3Spatrick        subs   r5,  r5,  #PAGE_SIZE
30*3cab2bb3Spatrick        ldr    r6,  [r12]
31*3cab2bb3Spatrick        bgt    1b
32*3cab2bb3Spatrick
33*3cab2bb3Spatrick        pop    {r5, r6}
34*3cab2bb3Spatrick        bx     lr
35*3cab2bb3SpatrickEND_COMPILERRT_FUNCTION(__chkstk)
36