Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!ruuinf!piet From: piet@cs.ruu.nl (Piet van Oostrum) Newsgroups: comp.sys.hp Subject: Re: alloca() on the HP9000/300 Message-ID: <3715@ruuinf.cs.ruu.nl> Date: 29 Aug 90 12:29:38 GMT References: <1455@tub.UUCP> <5570477@hpfcdc.HP.COM> <10328@pt.cs.cmu.edu> Sender: news@ruuinf.cs.ruu.nl Reply-To: piet@cs.ruu.nl (Piet van Oostrum) Organization: Dept of Computer Science, Utrecht University, The Netherlands Lines: 44 In-reply-to: tgl@zog.cs.cmu.edu (Tom Lane) In article <10328@pt.cs.cmu.edu>, tgl@zog (Tom Lane) writes: | |Au contraire. Recent versions of GNU Emacs include both Gwyn's package and |assembly-level hacks for some specific machines, one of which is the 300 |series. The 300-specific code does a real alloca by decrementing SP. |It is fairly specific to HP's cc because it knows about the compiler's |register save/restore habits. I believe it stops working with the HPUX 7.0 |cc if you turn optimization up past +O1; presumably this is because the |compiler may start using SP-relative addressing instead of a frame pointer. |But Emacs works just fine with this code and +O1 optimization; I use it |daily. But note that the distributed version has a bug in it that can cause stack corruption. Here is the correct version: text set PROBE,-128 # safety for C frame temporaries set MAXREG,22 # d2-d7, a2-a5, fp2-fp7 may have been saved global _alloca _alloca: mov.l (%sp)+,%a0 # return addess mov.l (%sp)+,%d0 # number of bytes to allocate mov.l %sp,%a1 # save old sp for register copy mov.l %sp,%d1 # compute new sp sub.l %d0,%d1 # space requested and.l &-4,%d1 # round down to longword sub.l &MAXREG*4,%d1 # space for saving registers mov.l %d1,%sp # save new value of sp tst.b PROBE(%sp) # create pages (sigh) mov.l %a2,%d1 # save reg a2 mov.l %sp,%a2 move.w &MAXREG-1,%d0 copy_regs_loop: /* save caller's saved registers */ mov.l (%a1)+,(%a2)+ dbra %d0,copy_regs_loop mov.l %a2,%d0 # return value mov.l %d1,%a2 # restore a2 add.l &-4,%sp # adjust tos jmp (%a0) # rts -- Piet* van Oostrum, Dept of Computer Science, Utrecht University, Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands. Telephone: +31-30-531806 Uucp: uunet!mcsun!ruuinf!piet Telefax: +31-30-513791 Internet: piet@cs.ruu.nl (*`Pete')