# This assembly routine implements alloca (n) # The HP compiler does "move.m (%sp)" to save registers, # so we must copy the possibly saved registers to the top of stack. # The stack layout at entry is: # possibly saved regs # n # return address <--- sp set MAXREG,22 # d2-d7, a2-a5, fp2-fp7 may have been saved text global _alloca _alloca: mov.l (%sp)+,%a0 # save return addess move.l %sp,%d0 # old stack pointer sub.l (%sp)+,%d0 # subtract number of bytes requested or.l &3,%d0 # prepare for longword alignment # now d0 = return value - 1! sub.l &MAXREG*4-1,%d0 # allocate space for saving registers mov.l %sp,%a1 # source for reg copy mov.l %a2,%d1 # save reg a2 mov.l %d0,%a2 # dest for reg copy mov.l %d0,%sp # save new value of sp move.w &MAXREG-1,%d0 # loop counter copy: # save possibly saved registers mov.l (%a1)+,(%a2)+ dbra %d0,copy mov.l %a2,%d0 # return value mov.l %d1,%a2 # restore reg a2 add.l &-4,%sp # this compensates for add.l &4,%sp # generated by the compiler jmp (%a0) # rts