Xref: utzoo comp.unix.questions:30073 comp.unix.internals:2483 comp.unix.programmer:1493 comp.lang.c:37928 Newsgroups: comp.unix.questions,comp.unix.internals,comp.unix.programmer,comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Subject: Re: Unix Stack Frame Questions Message-ID: <1991Apr4.181854.5016@Think.COM> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA References: <3465@unisoft.UUCP> <19157@rpp386.cactus.org> Distribution: na Date: Thu, 4 Apr 91 18:18:54 GMT In article <19157@rpp386.cactus.org> jfh@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@think.com {uunet,harvard}!think!barmar