Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
108
Call frame information
AVR® IAR C/C++ Compiler
Reference Guide
It is the responsibility of the calling function to allocate a memory location for the return 
value and pass a pointer to it as a hidden first parameter. The pointer to the location 
where the return value should be stored is passed in the first suitable register/register 
pair, which is 
R16
R17:R16
, and 
R18:R17:R16
 for the Tiny, Small, and Large memory 
model, respectively. The parameter 
x
 is passed in 
R19
:
R18
R19
:
R18
, and 
R21:R20
 for 
the Tiny, Small, and Large memory model, respectively.
Assume that the function instead would have been declared to return a pointer to the 
structure:
struct a_struct *  a_function(int x);
In this case, the return value is a scalar, so there is no hidden parameter. The parameter 
x
 is passed in 
R17:R16
. The return value is returned in 
R16
R17
:
R16
, and 
R18:R17
:
R16
 for the Tiny, Small, and Large memory model, respectively.
Call frame information
When debugging an application using C-SPY, it is possible to view the call stack, that 
is, the functions that have called the current function. The compiler makes this possible 
by supplying debug information that describes the layout of the call frame, in particular 
information about where the return address is stored.
If you want the call stack to be available when debugging a routine written in assembler 
language, you must supply equivalent debug information in your assembler source using 
the assembler directive CFI. This directive is described in detail in the AVR® IAR 
Assembler Reference Guide.
The CFI directives will provide C-SPY with information about the state of the calling 
function(s). Most important of this is the return address, and the value of the stack 
pointer at the entry of the function or assembler routine. Given this information, C-SPY 
can reconstruct the state for the calling function, and thereby unwind the stack. 
A full description about the calling convention may require extensive call frame 
information. In many cases, a more limited approach will suffice.
When describing the call frame information, the following three components must be 
present:
names block describing the available resources to be tracked
common block corresponding to the calling convention
data block describing the changes that are performed on the call frame. This 
typically includes information about when the stack pointer is changed, and when 
permanent registers are stored or restored on the stack.