tccpp: tcc_warning("extra tokens after directive")
[tinycc.git] / win32 / lib / chkstk.S
blob6f583a5319a09d7507476eec121786e85c9bfc29
1 /* ---------------------------------------------- */
2 /* chkstk86.s */
4 #ifdef __leading_underscore
5 # define _(s) _##s
6 #else
7 # define _(s) s
8 #endif
10 /* ---------------------------------------------- */
11 #ifndef __x86_64__
12 /* ---------------------------------------------- */
14 .globl _(__chkstk)
15 _(__chkstk):
16     xchg    (%esp),%ebp     /* store ebp, get ret.addr */
17     push    %ebp            /* push ret.addr */
18     lea     4(%esp),%ebp    /* setup frame ptr */
19     push    %ecx            /* save ecx */
20     mov     %ebp,%ecx
21 P0:
22     sub     $4096,%ecx
23     test    %eax,(%ecx)
24     sub     $4096,%eax
25     cmp     $4096,%eax
26     jge     P0
27     sub     %eax,%ecx
28     test    %eax,(%ecx)
30     mov     %esp,%eax
31     mov     %ecx,%esp
32     mov     (%eax),%ecx     /* restore ecx */
33     jmp     *4(%eax)
35 /* ---------------------------------------------- */
36 #else
37 /* ---------------------------------------------- */
39 .globl _(__chkstk)
40 _(__chkstk):
41     xchg    (%rsp),%rbp     /* store ebp, get ret.addr */
42     push    %rbp            /* push ret.addr */
43     lea     8(%rsp),%rbp    /* setup frame ptr */
44     push    %rcx            /* save ecx */
45     mov     %rbp,%rcx
46     movslq  %eax,%rax
47 P0:
48     sub     $4096,%rcx
49     test    %rax,(%rcx)
50     sub     $4096,%rax
51     cmp     $4096,%rax
52     jge     P0
53     sub     %rax,%rcx
54     test    %rax,(%rcx)
56     mov     %rsp,%rax
57     mov     %rcx,%rsp
58     mov     (%rax),%rcx     /* restore ecx */
59     jmp     *8(%rax)
61 /* ---------------------------------------------- */
62 /* setjmp/longjmp support */
64 .globl _(tinyc_getbp)
65 _(tinyc_getbp):
66     mov %rbp,%rax
67     ret
69 /* ---------------------------------------------- */
70 #endif
71 /* ---------------------------------------------- */