Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1.  
  2. #tls:0  pid process id
  3. #tls:4  tid reserved for thread slot
  4. #tls:8  thread's stack low limit
  5. #tls:12 thread's stack high limit
  6. #tls:16 reseved for libc
  7.  
  8. #ifdef L_start
  9.  
  10.           .section .init
  11.           .global __start
  12.  
  13. .align 4
  14. __start:
  15.           movl  $68, %eax
  16.           movl  $12, %ebx
  17.           lea  __size_of_stack_reserve__, %ecx
  18.           addl  $4095, %ecx       #load stack size
  19.           andl  $-4096, %ecx      #align to page granularity
  20.           int   $0x40             #and allocate
  21.           testl %eax, %eax
  22.           jz    1f
  23.  
  24.           addl %eax, %ecx
  25.           movl %eax, %fs:8
  26.           movl %ecx, %fs:12       #save stack base - low limit
  27.                                   #save stack top  - high limit
  28.           movl %ecx, %esp         #reload stack
  29.  
  30.           subl $1024, %esp
  31.  
  32.           movl $9, %eax
  33.           movl %esp, %ebx
  34.           movl $-1, %ecx
  35.           int $0x40
  36.  
  37.           movl 30(%ebx), %eax
  38.           movl %eax, %fs:0        #save pid
  39.  
  40.           addl $1024, %esp
  41.  
  42.           jmp  ___crt_startup
  43. 1:
  44.           int3                    #trap to debugger
  45.  
  46.           .ascii "No enough memory for stack allocation"
  47.  
  48. #endif
  49.  
  50.  
  51. #ifdef L_chkstk
  52.  
  53.           .section .text
  54.           .global ___chkstk
  55.           .global __alloca
  56.  
  57. ___chkstk:
  58. __alloca:
  59.           pushl   %ecx            /* save temp */
  60.           leal    8(%esp), %ecx   /* point past return addr */
  61.           subl    %eax, %ecx
  62.           cmpl    %fs:8, %ecx     # check low stack limit
  63.           jb      1f
  64.  
  65.           movl    %esp, %eax      /* save old stack pointer */
  66.           movl    %ecx, %esp      /* decrement stack */
  67.           movl    (%eax), %ecx    /* recover saved temp */
  68.           movl    4(%eax), %eax   /* recover return address */
  69.  
  70.         /* Push the return value back.  Doing this instead of just
  71.            jumping to %eax preserves the cached call-return stack
  72.            used by most modern processors.  */
  73.           pushl   %eax
  74.           ret
  75. 1:
  76.           int3                    #trap to debugger
  77.           .ascii "Stack overflow"
  78. #endif
  79.  
  80. #ifdef L_chkstk_ms
  81.  
  82.           .section .text
  83.           .global ___chkstk_ms
  84.  
  85. ___chkstk_ms:
  86.           pushl  %ecx            /* save temp */
  87.           pushl  %eax
  88.           cmpl $0x1000, %eax     /* > 4k ?*/
  89.           leal 12(%esp), %ecx    /* point past return addr */
  90.           jb 2f
  91. 1:
  92.           subl $0x1000, %ecx     /* yes, move pointer down 4k*/
  93.           cmpl %fs:8, %ecx       /* check low stack limit    */
  94.           jb 3f
  95.  
  96.           orl $0x0, (%ecx)       /* probe there */
  97.           subl $0x1000, %eax     /* decrement count */
  98.           cmpl $0x1000, %eax
  99.           ja 1b                  /* and do it again */
  100.  
  101. 2:
  102.           subl %eax, %ecx
  103.           orl $0x0, (%ecx) /* less than 4k, just peek here */
  104.  
  105.           popl %eax
  106.           popl %ecx
  107.           ret
  108. 3:
  109.           int3                    #trap to debugger
  110.           .ascii "Stack overflow"
  111. #endif
  112.  
  113.