Subversion Repositories Kolibri OS

Rev

Rev 2827 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1693 serge 1
 
2
.global ___chkstk_ms
2827 Serge 3
.global __alloca
1693 serge 4
5
 
6
7
 
2827 Serge 8
#.def ___chkstk_ms;  .scl  2;  .type 32; .endef
9
#.def __alloca; .scl  2;  .type 32; .endef
10
11
 
1693 serge 12
__alloca:
13
        pushl   %ecx            /* save temp */
14
        leal    8(%esp), %ecx   /* point past return addr */
15
        subl    %eax, %ecx
16
        cmpl    %fs:8, %ecx     # check low stack limit
3805 Serge 17
        jb      1f
1693 serge 18
19
 
20
        movl    %ecx, %esp      /* decrement stack */
21
        movl    (%eax), %ecx    /* recover saved temp */
22
        movl    4(%eax), %eax   /* recover return address */
23
24
 
25
           jumping to %eax preserves the cached call-return stack
26
           used by most modern processors.  */
27
        pushl   %eax
28
        ret
29
1:
30
        int3                    #trap to debugger
31
        .ascii "Stack overflow"
32
33
 
1906 serge 34
 
2827 Serge 35
       pushl  %ecx            /* save temp */
36
       pushl  %eax
37
       cmpl $0x1000, %eax     /* > 4k ?*/
38
       leal 12(%esp), %ecx    /* point past return addr */
39
       jb 2f
40
41
 
42
       subl $0x1000, %ecx     /* yes, move pointer down 4k*/
43
       cmpl %fs:8, %ecx       /* check low stack limit    */
3805 Serge 44
       jb 3f
2827 Serge 45
46
 
47
       subl $0x1000, %eax     /* decrement count */
48
       cmpl $0x1000, %eax
49
       ja 1b                  /* and do it again */
50
51
 
52
       subl %eax, %ecx
53
       orl $0x0, (%ecx) /* less than 4k, just peek here */
54
55
 
56
       popl %ecx
57
       ret
58
3:
59
       int3                    #trap to debugger
60
       .ascii "Stack overflow"
61