Everything
9.1.4 Stack frame

(1)

Structure of the stack frame

Below is shown the stack frame of functions f and g from the perspective of function f, when function f is called by function g.

Figure 9.1

Contents of Stack Frame

 

Below is the range of the area that function f can reference and set.

(a)

Parameter words 5 to n

This is the area where parameters beyond 4 words (16 bytes) are stored, when function f has parameters larger than 4 words in size. The size of this area is 0 when the parameter size is 4 words or less.

(b)

Parameter register area

This area is for storing parameters passed in the registers (r6 to r9). The size is not locked at 16 bytes; the size is 0 if not needed.

For details about the parameter register area, see "(2) Parameter register area".

(c)

Save area of Callee-Save register

This area is for saving the Callee-Save registers used in function f. If it is necessary to save registers, then this area must be large enough for the number of registers.

Registers are essentially saved and restored using prepare/dispose instructions, so registered are stored in this save area in order of ascending register number.

For example, r28 to r31 would be saved in the following order.

(d)

Local variable area

This stack area is used for local variables.

(e)

5th to nth argument words

Parameters beyond 4 words in size are stored in this area when function f is called by another function. The area for arguments needed when calling another function is allocated on function f's stack frame, and set there.

If fewer than 4 words are needed for the call's arguments, then the size of this area is 0.

(2)

Parameter register area

If the size of the parameters is greater than 4 words (16 bytes), then the required area for the size of the parameter register area is allocated. The size of this area will be either 0, 4, 8, 12, or 16 bytes, because it stores parameter registers r6 to r9, as necessary.

This area is for storing parameter registers when it is necessary to reference the contiguous placement relationship between the parameter register contents and parameters on the stack.

For example, when passing the value of a 20-byte structure argument, 16 bytes are passed in r6 to r9, and the remaining 4 bytes (the 5th parameter word) are passed on the stack.

Example

Function prototype : f(ST20 )

 

When referencing the value of the passed structure as a whole, it is necessary to align the entire structure contiguously in memory, but the structure is split unto the register portion and memory portion immediately after the function call.

In this case, the called function can reference the passed ST20 structure in memory be storing the parameter register on the stack.

 

Below is a concrete case of parameters where this area is needed.

If none of these apply, then the parameter register area is not needed (size 0) because it is not necessary to store the parameter registers in the parameter register area.

(a)

When a structure or union spans the parameter registers and stack

Example

Function prototype : f(char, ST20)

 

In this case, r7 to r9 are stored in the parameter register area.

r6 is not stored because it is not needed to align ST20 contiguously in memory.

Therefore the size of the parameter register area is 12 bytes.

 

If a structure or union does not span the parameter register and stack, then it is not necessary to store it in the parameter register area, and the size of the parameter register area is therefore 0.

Example

Function prototype : f(char, ST12, ST8)

 

In this case, all of ST12 fits in the parameter registers, ST8 is not passed in the parameter registers.

Since no arguments span the parameter registers and stack, the size of the parameter register area is 0 bytes.

If a structure or union is passed in its entirety via the parameter registers, the local variable area is used to expand it in memory.

(b)

Accepting variable number of actual arguments

To receive a variable number of arguments, the arguments (including the last parameter) need to be stored in the parameter register area.

Example

Function prototype : f(char, long, ...)

 

In this case, the parameter registers corresponding to the variable number of actual arguments (r8 and r9) are stored in the parameter register area.

Therefore the size of the parameter register area is 8 bytes.