Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Chapter 4 - PowerPC Runtime Conventions / PowerPC Stack Structure


Prologs and Epilogs

The called routine is responsible for allocating its own stack frame, making sure to preserve 16-byte alignment on the stack. This action is accomplished by the prolog before entering the actual routine. The compiler-generated prolog code does the following:

Note
The order in which the prolog executes these actions is determined by convention, not by any requirements of the PowerPC runtime architecture.
Listing 4-1 shows some sample prolog code. Note that the order of these actions differs from the order previously described.

Listing 4-1 Sample prolog code

linkageArea: set 24     ; size in PowerPC environment
params: set 32          ; callee parameter area
localVars: set 0        ; callee local variables
numGPRs: set 0          ; volatile GPRs used by callee
numFPRs: set 0          ; volatile FPRs used by callee)

spaceToSave: set linkageArea + params + localVars
spaceToSave: set spaceToSave + 4*numGPRs + 8*numFPRs

.moo:                   ; PROLOG
   mflr  r0,            ; extract return address 
   stw   r0,8(SP)       ; save the return address
   stwu  SP, -spaceToSave(SP); skip over caller save area
After the called routine exits, the epilog code executes, which does the following:

Listing 4-2 shows some sample epilog code.

Listing 4-2 Sample epilog code

                           ; EPILOG
   lwz   r0,spaceToSave(SP)+8; get the return address
   mtlr  R0                ; reset Link Register
   addic SP,SP,spaceToSave ; restore stack pointer
   blr                     ; return
The calling routine is responsible for restoring its GPR2 value immediately after returning from the called routine.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997