jacob navia said:
(1)
All activation records save the current frame pointer value in a linked
list. I do this in the code generated for the x86, x86(64) power PC
and solaris back ends of lcc-win. This is even if all the stack is a
single memory area!
It's certainly common, but it's by no means universal. If you don't
allow variable dynamic stack allocation (e.g., alloca), the start of the
frame is always a known offset from the current stack pointer, so
there's no need for a separate frame pointer. And since the frame is a
fixed size, there's no need to save and restore the stack pointer,
either; just increment (or decrement, depending on which way the stack
grows) it by the fixed size on entry and decrement it by the same size
on exit.
(2)
The startup procedure install the stack where R13 points
to. And that stack must be allocated previously and be contiguous. Look
at the custom entry point (as I indicated to K Thompson)
You're again quoting text without understanding the context. The
section you're quoting is talking about creating and using non-standard
run-time environments; it's not talking about the standard C run-time
environment which is now integrated into the common IBM Language
Environment:
<
http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/CEEU1007/4.3.2?SHELF=&DT=19950913203351>
Note in particular:
4.3.2 Stack Storage Overview
The user stack is used by both library routines and compiled
code. Stack storage is also available in the library stack,
which is an independent area of stack storage, allocated below
the 16M line, designed to be used only by library routines.
So already it's clear that there isn't a single contiguous stack since
there is a separate stack available for library functions.
The storage stack is divided into large segments of storage
called stack segments, which are further divided into smaller
segments called stack frames (8), also known as dynamic storage
areas (DSAs). A stack frame, or DSA, is dynamically acquired
storage composed of a register save area and an area available
for dynamic storage allocation for items such as program
variables. ...
The first segment used for stack storage is called the initial
stack segment. When the initial stack segment becomes full, a
second segment, or stack increment is obtained from the
operating system. As each succeeding stack increment becomes
full, another is obtained from the operating system as needed.
So here we have the full picture: even the user stack isn't contiguous,
it's made up of a number of disjoint segments allocated from the OS
(i.e., the heap). If the segment size is small enough, each stack frame
will be separately allocated and thus disjoint. (Early implementations
of IBM C allocated each stack frame individually, which is what I based
my original comments on. Other mainframe compilers that I have used
[AT&T and SAS] worked similarly.)
(3)
There is no mention of any linked list anywhere in the docs I have
Where did you got this linked list allocation story?
That's part of the OS standard linkage convention that's implied when
the above refers to "register save areas". See:
said:
(4)
Can you imagine the incredible resource waste that would be to call
malloc at each function call ???? Just think a bit about that.
Nonetheless, that's essentially what most mainframe systems do/did.
Most mainframe code is not recursive, so each function can simply have a
statically allocated "stack frame". Languages that do allow recursion
pay the price by having to dynamically allocate their "stack frames".
(Although it's also possible for the compiler to use a statically
allocated "stack frame" for any function that doesn't make any function
calls.)
Think about the supposed call to "malloc" to allocate a stack
frame. How would that work in the "malloc" function?
In this case, "malloc" is a system service, not the actual C function
(although the actual C function calls the same system service). And
like I said, that's why it's the *caller's* responsibility to allocate
space for the callee to save the registers in -- the callee has to save
the registers before it's had a chance to allocate its stack frame.
-Larry Jones
Everybody's a slave to routine. -- Calvin