win32 merge
[tinycc.git] / win32 / lib / chkstk.S
blob8e16d74bcb5fcbc87c5acb24b6c9847637a6befe
1 // =================================================\r
2 // chkstk.s\r
3 \r
4 .text\r
5 .globl __chkstk\r
6 \r
7 __chkstk:\r
8         xchg    (%esp), %ebp   // store ebp, get ret.addr\r
9         push    %ebp           // push ret.addr\r
10         lea     4(%esp), %ebp  // setup frame ptr\r
11         push    %ecx           // save ecx\r
12         mov     %ebp, %ecx\r
13 P0:\r
14         sub     $4096,%ecx\r
15         test    %eax,(%ecx)\r
16         sub     $4096,%eax\r
17         cmp     $4096,%eax\r
18         jge     P0\r
20         sub     %eax,%ecx\r
21         mov     %esp,%eax\r
22         test    %eax,(%ecx)\r
23         mov     %ecx,%esp\r
25         mov     (%eax),%ecx     // restore ecx\r
26         mov     4(%eax),%eax\r
27         push    %eax\r
28         ret\r