Altera Nios II User Manual page 163

Hide thumbs Also See for Nios II:
Table of Contents

Advertisement

Chapter 7: Application Binary Interface
Stacks
In order for varargs to work, functions that take variable arguments allocate 16 extra
bytes of storage on the stack. They copy to the stack the first 16 bytes of their
arguments from registers r4 through r7 as shown in
Figure 7–3. Stack Frame Using Variable Arguments
Higher addresses
Stack pointer
Lower addresses
Stack Frame for a Function with Structures Passed By Value
Functions that take struct value arguments still have their first 16 bytes of arguments
arriving in registers r4 through r7, just like other functions.
If part of a structure is passed using registers, the function might need to copy the
register contents back to the stack. This operation is similar to that required in the
variable arguments case as shown in
Function Prologues
The Nios II C/C++ compiler generates function prologues that allocate the stack
frame of a function for storage of stack temporaries and outgoing arguments. In
addition, each prologue is responsible for saving the state of the calling function. This
entails saving certain registers on the stack. These registers, the callee-saved registers,
are listed in
callee-saved register only if the function uses the register.
Given the function prologue algorithm, when doing a back trace, a debugger can
disassemble instructions and reconstruct the processor state of the calling function.
February 2014 Altera Corporation
In function a()
Just prior to calling b()
Outgoing
stack
arguments
Frame pointer
Stack pointer
Table 7–2 on page
Figure
In function b()
Just after executing prologue
Incoming
Allocated and freed by a()
stack
(i.e. the calling function)
arguments
Copy of r7
Copy of r6
Copy of r5
Copy of r4
Return address
Saved frame
pointer
Other saved
registers
Allocated and freed by b()
(i.e. the current function)
Space for
stack
temporaries
Space for
outgoing
stack
arguments
Figure
7–3.
7–2. A function prologue is required to save a
7–3.
Nios II Processor Reference Handbook
7–5

Advertisement

Table of Contents
loading

Table of Contents