home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / purec / alloca.s next >
Text File  |  1993-02-22  |  1KB  |  67 lines

  1. ; alloca(nbytes) allocate junk in stack frame
  2. ; Pure C version 19-6-92 bm
  3. ;
  4. ; Poor C doesn't handle stack frames correctly. It tries to restore
  5. ; registers sp-relative *before* unlk, so if we change the stack
  6. ; pointer, we must copy up to 36 bytes :-(
  7. ;
  8. ;  void *alloca(size_t size)
  9. ;
  10.  
  11. ; the caller MUST be compiled with option -S !!!
  12.  
  13. .globl alloca
  14.  
  15. ; STACKCH = 1
  16. ; FPU = 0
  17.  
  18. .text
  19. alloca:
  20.     tst.l d0            ;alloca(0)?
  21.     beq ret
  22.  
  23.     movea.l (sp)+,a0    ;get return address
  24.     movea.l sp,a1        ;old stack pointer
  25.     addq.l #1,d0        ;ensure address in d0 even
  26.     bclr.l #0,d0        ;lop off extra bits
  27.  
  28.     suba.l d0,sp        ;increase stack frame
  29.  
  30. .if STACKCH
  31.     cmpa.l _StkLim, sp    ;enough stack space?
  32.     bcs no_space
  33. .endif
  34.     
  35.     move.l a6,d1        ;calculate amount of bytes to be copied
  36.     sub.l a1,d1
  37. .iff FPU
  38.     cmpi.l #37,d1        ;maximum 36 bytes (a2-a5/d3-d7)
  39. .else
  40.     cmpi.l #97,d1        ;unless FPU is used
  41. .endif
  42.     bcs alloca1
  43.     moveq.l #36,d1
  44.     
  45. alloca1:
  46.     suba.l d1,sp        ;space for the copy
  47.     move.l a0,-(sp)        ;push return address
  48.     lea 4(sp),a0        ;a0 <- sp + 4
  49.     
  50.     bra alloca3            ;start copying:
  51.                         ;d1 bytes from (a1) to (a0)
  52. alloca2:
  53.     move.w (a1)+,(a0)+
  54. alloca3:
  55.     subq.l #2,d1
  56.     bne alloca2
  57. ret:
  58.     rts                    ;a0 is start of free block
  59.  
  60. .if STACKCH
  61. .globl _StkLim
  62. .globl _StkOver
  63. no_space:
  64.     adda.l    d0,sp
  65.     jmp _StkOver        ;und tschü₧
  66. .endif
  67.