.title ALLOCA .ident /ta2:1.0/ ;***** ; void * alloca(long size); ; ; Dynamic memory allocation from the users stack. Code produced by Bison ; uses this routine but the VMS C runtimes don't provide it. ; ; To get the space allocated in the callers call frame, we take the approach ; of moving down our frame and its associated pointers. When we return, the ; stack pointer will fall short by the right amount - the new stack pointer ; pointing at the allocated space. ; ; 21-Dec-1987 Tom Allebrandi II ; ta2@esther.acci.com Advanced Computer Consulting, Inc. ; ;***** $sfdef size = 4 frame_size = sf$l_save_regs+<6*4> ;We have 6 regs saved .entry alloca,^m ; ; Compute the amount of space to allocate rounded up to the next multiple ; of 4. When we move the call frame at label 10, we must preserve the ; longword alignment. Thus, the multiple of 4. ; addl3 #3,size(ap),r6 bicl2 #3,r6 ; ; Compute the size of the call frame. To do this, we must take into account ; the number of stack alignment bytes and the number of arguments that were ; pushed on prior to a CALLS instruction. ; movl #frame_size,r7 ;Minimum size of the frame extzv #sf$v_stackoffs,- ;The number of stack alignment bytes #sf$s_stackoffs,- sf$w_save_mask(fp),- r0 addl2 r0,r7 ;Frame size after alignment bbc #sf$v_calls,- ;Were we called with a CALLS? Branch sf$w_save_mask(fp),- ; if not. 10$ movl (ap),r0 ;Get the argument count, adjust the incl r0 ; count to include the count longword mull2 #4,r0 ;Compute the number of bytes for arguments addl2 r0,r7 ; and fold into the frame size ; ; Move the call frame down by the number of bytes to be allocated. When we ; return from here, the stack pointer will point at the new space. There are ; a couple of subtleties in the move: we must adjust the fp in order to ; execute the return; and, since sp>fp is a fault, we must also move the sp. ; 10$: subl2 r6,sp movc3 r7,(fp),(sp) movl sp,fp ; ; Compute the value that the sp will contain upon return. Make that our ; function return value. ; addl3 r7,fp,r0 ret .end