10b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 20b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 30b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 40b57cec5SDimitry Andric 50b57cec5SDimitry Andric#include "../assembly.h" 60b57cec5SDimitry Andric 70b57cec5SDimitry Andric// __chkstk routine 80b57cec5SDimitry Andric// This routine is windows specific. 90b57cec5SDimitry Andric// http://msdn.microsoft.com/en-us/library/ms648426.aspx 100b57cec5SDimitry Andric 110b57cec5SDimitry Andric// This clobbers the register r12, and the condition codes, and uses r5 and r6 120b57cec5SDimitry Andric// as temporaries by backing them up and restoring them afterwards. 130b57cec5SDimitry Andric// Does not modify any memory or the stack pointer. 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric// movw r4, #256 // Number of bytes of stack, in units of 4 byte 160b57cec5SDimitry Andric// bl __chkstk 170b57cec5SDimitry Andric// sub.w sp, sp, r4 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric#define PAGE_SIZE 4096 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric .p2align 2 220b57cec5SDimitry AndricDEFINE_COMPILERRT_FUNCTION(__chkstk) 230b57cec5SDimitry Andric lsl r4, r4, #2 240b57cec5SDimitry Andric mov r12, sp 250b57cec5SDimitry Andric push {r5, r6} 260b57cec5SDimitry Andric mov r5, r4 270b57cec5SDimitry Andric1: 280b57cec5SDimitry Andric sub r12, r12, #PAGE_SIZE 290b57cec5SDimitry Andric subs r5, r5, #PAGE_SIZE 300b57cec5SDimitry Andric ldr r6, [r12] 310b57cec5SDimitry Andric bgt 1b 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric pop {r5, r6} 340b57cec5SDimitry Andric bx lr 350b57cec5SDimitry AndricEND_COMPILERRT_FUNCTION(__chkstk) 36