pro64-contrib
[Top] [All Lists]

Re: Layout of stack frame

To: pro64-contrib@xxxxxxxxxxx, "Benedict R. Gaster" <benedict.gaster@xxxxxx>
Subject: Re: Layout of stack frame
From: mpm@xxxxxxxxxxxxxxxxx (Michael Murphy)
Date: Tue, 31 Jul 2001 10:51:43 -0700 (PDT)
Sender: owner-pro64-contrib@xxxxxxxxxxx
        From: "Benedict R. Gaster" <benedict.gaster@xxxxxx>
        
        Hello,
        
        We have been working on porting the Pro64 to a new risc style processor
        and have for the last week or  so had the compiler generating code,
        albeit not completly correct due to stack frame layout being wrong.
        
        Our ABI states that, in general, a stack frame takes the form:
        
          |--------------------------------| Previous SP 8-byte aligned
          | Parameter Register Save Area |
          |--------------------------------| 8-byte aligned
          | Register Save Area                  |             |
          |--------------------------------|             | direction of stack
        growth
          | Local variables Area                |            \/
          |--------------------------------|    <--- SP or FP, 8-byte aligned
          | Dynamic Variable Area            |
          |--------------------------------|
          | Argument Area (for calls)         |
          |---------------------------------| 8-byte aligned
        
        The default stack alignment, set in data_layout.cxx, is 8-bytes, unlike
        the IA64, which seems to be 16.
        
        Currently compiling the following program, at -O0,:
        
        int foo(int x, int y)
        {
           int local = 100;
        
           return x + y + local;
        }
        
        produces the stackframe
        
        |-----------------|
        | SP-0: local        |
        |-----------------|
        | SP-8:   x           |
        | SP-12: y           |
        |-----------------| <------ SP after function prolog.
        
        The problem is that this does not conform to our ABI, as the locals
        appear before the formals!
        
        For simplicity we are currently we are using at small stack frame model
        (SMODEL_SMALL), which does not require a frame pointer
        
        The Pro64 compiler builds the stack frame from a set of sub-segments, of
        type SF_SEGMENT, again defined in data_layout.cxx.
        
        How are these sections ordered?
        
        Is it possible to change the ordering of these sections so that the
        final stack frame calculations apply to our ABI rather than that of the
        IA64?
        
Yes, in data_layout.cxx, the Merge_Fixed_Stack_Frame() and
Finalize_Stack_Frame() routines control the order of the frame sections.
You can think of data layout as operating on a tree of blocks.
When you allocate something, you assign its base to another object,
with an offset pointing into that base object.  So all the formals
are allocated (based) on the formal_stack_segment, and then the formal
stack segment (together with local stack segment) is based on the sp_sym
object.  The MERGE_SEGMENT calls are doing that allocation,
and those can be changed to be done in a different order.

An interesting thing about your example is that somehow you are not
doing the ia64 abi either, as IA64 also has formals appearing before
locals.

-- Mike Murphy
-- mpm@xxxxxxx
-- quote of the day:
--  "Air power is an unusually seductive form of military strength
--   because, like modern courtship, it appears to offer gratification
--   without commitment."  (Eliot Cohen)

<Prev in Thread] Current Thread [Next in Thread>