x86-64: chkstk, alloca
[tinycc/kirr.git] / win32 / lib / chkstk.S
blob9be95978c210d2f73d6559b4650a870fd258c885
1 /* ---------------------------------------------- */
2 /* chkstk86.s */
4 #include "../../config.h"
6 /* ---------------------------------------------- */
7 #ifndef TCC_TARGET_X86_64
8 /* ---------------------------------------------- */
10 .globl __chkstk
12 __chkstk:
13     xchg    (%esp),%ebp     /* store ebp, get ret.addr */
14     push    %ebp            /* push ret.addr */
15     lea     4(%esp),%ebp    /* setup frame ptr */
16     push    %ecx            /* save ecx */
17     mov     %ebp,%ecx
18 P0:
19     sub     $4096,%ecx
20     test    %eax,(%ecx)
21     sub     $4096,%eax
22     cmp     $4096,%eax
23     jge     P0
24     sub     %eax,%ecx
25     test    %eax,(%ecx)
27     mov     %esp,%eax
28     mov     %ecx,%esp
29     mov     (%eax),%ecx     /* restore ecx */
30     jmp     *4(%eax)
32 /* ---------------------------------------------- */
33 #else
34 /* ---------------------------------------------- */
36 .globl __chkstk
38 __chkstk:
39     xchg    (%rsp),%rbp     /* store ebp, get ret.addr */
40     push    %rbp            /* push ret.addr */
41     lea     8(%rsp),%rbp    /* setup frame ptr */
42     push    %rcx            /* save ecx */
43     mov     %rbp,%rcx
44     movslq  %eax,%rax
45 P0:
46     sub     $4096,%rcx
47     test    %rax,(%rcx)
48     sub     $4096,%rax
49     cmp     $4096,%rax
50     jge     P0
51     sub     %rax,%rcx
52     test    %rax,(%rcx)
54     mov     %rsp,%rax
55     mov     %rcx,%rsp
56     mov     (%rax),%rcx     /* restore ecx */
57     jmp     *8(%rax)
59 /* ---------------------------------------------- */
60 #endif
61 /* ---------------------------------------------- */