win64: add tiny unwind data for setjmp/longjmp
[tinycc.git] / win32 / lib / chkstk.S
bloba757b1610cbdcc5fadbb96fedbf3ab54f4b6431a
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 /* setjmp/longjmp support */
62 .globl tinyc_no_getbp
63 tinyc_no_getbp:
64     .byte 0x90
66 .globl tinyc_getbp
67 tinyc_getbp:
68     xor %rax,%rax
69     cmp %al,tinyc_no_getbp(%rax)
70     je t1
71     mov %rbp,%rax
72 t1:
73     ret
75 /* ---------------------------------------------- */
76 #endif
77 /* ---------------------------------------------- */