Unix Stack Frame Questions

Barry Margolin barmar at think.com
Fri Apr 5 04:18:54 AEST 1991


In article <19157 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F Haugh II) writes:
>>I didn't think that a CPU ever "enforced" a stack frame; ostensibly one
>>could ignore the references to "4(fp)" in the manual and do it their own
>>way.
>
>Yes, there are CPU's which have notions about stack frame and
>support the conventions in hardware.  If you "ignore" the
>convention, you go whirring off into space when you get around
>to executing that "ret" instruction and the machine expects
>the stack frame it pushed to still be of the right shape and
>size.

You're right, there are machines which provide instructions that manipulate
the stack and assume a particular stack frame layout.  However, there's
nothing *forcing* programs to use those instructions.  So, if you ignore
the convention, don't use that "ret" instruction!  You're only *forced* to
follow conventions when you want to interoperate with other routines.  For
instance, when calling a library routine or system call you have to follow
the conventions it expects (usually the standard calling sequence), and if
you want standard debuggers to be usable you should use the standard frame
layout.

Many Lisp implementations use a nonstandard stack frame layout, since they
generally provide their own higher-level debugger.  Disassembling Lisp
functions often reveals that they don't use the call and return
instructions.  When calling out to conventional libraries they translate
from the Lisp calling sequence to the standard calling sequence, and vice
versa when implementing callbacks.
--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list