A function (parent function) performs the
following tasks when it calls another function (child function).
The
C7000 has dedicated instructions and registers to manage call and return operations. The
CALL instruction saves the return address in the Return Pointer (RP) register and transfers
control to the called function. The RET instruction restores the PC from the RP, thereby
returning control to the callee.
The C7000 CPU has a pipeline model that can function in both a
protected or unprotected state. The CPU must be in the protected state. not unprotected
state, when a call or return is made.
A function (parent function) performs the following tasks when
it calls another function (child function):
- Arguments passed to a function are placed
in registers or on the stack.
- If arguments are passed to a
function, as many as can fit are placed in the nine "scalar" and sixteen "vector"
registers that are available for argument passing.
- Arguments whose declared type is 64 bits or less are assigned to
scalar registers A4 through A12.
- Arguments whose declared is between 64 and 512 bits in size are
passed in vector registers VB0-VB15.
- Arguments that are declared as vector predicates are passed in
vector predicate registers P0-P7.
- Arguments larger than 512 bits are passed by reference. See the
"Values Passed and Returned by Reference" section in the C7000 Embedded Application
Binary Interface (EABI) Reference Guide (SPRUIG4).
- Any remaining arguments are placed on the stack at increasing
addresses, such that the first one will be at address SP+16 upon entry to the
callee.
- Each argument with a scalar or vector type is placed at the next
available address correctly aligned for its type.
- Structures are aligned to the next power of two greater than or
equal to their size, up to a maximum of 8 bytes.
- Each argument reserves an amount of stack space equal to its size
rounded up to the next multiple of its alignment.
- For a variadic C function (declared with an ellipsis indicating that
it is called with varying numbers of arguments), the last explicitly declared argument
and all remaining arguments are passed on the stack, so that its stack address can act
as a reference for accessing the undeclared arguments.
- An argument that is not declared in a prototype and whose size is
less than the size of int is passed as an int, in accordance with the C language.
- The calling function must save register
RP so that it is not overwritten by the CALL instruction. It must also save any live local
or global registers that are not preserved by the called function (as part of the
save-on-entry register set). The save-on-entry register set includes A8-A15, B14/VB14, and
B15/VB15.
- The caller (parent) calls the function
(child).
See the
"Calling Conventions" chapter in the C7000 Embedded Application Binary Interface (EABI)
Reference Guide (SPRUIG4) for more information.