SH-3 Parameter Passing
In general, the SH-3 argument list layout resembles a memory-based structure with padding inserted to achieve appropriate alignment. The calling function passes the first four 32-bit words in registers R4 through R7. If a called function takes the address of any of the arguments passed in these registers, and if the resulting pointer has any possibility of being used to reference subsequent arguments, the routine must copy that argument and all that follow it in the registers to the stack area reserved for that purpose. All argument registers are stored regardless of which argument has its address taken. The reserved area is adjacent to the rest of the argument list so that all varargs techniques work.
The following list shows parameter passing conventions:
- If integer and integer-equivalent arguments such as char or pointer are not larger than 32-bits, a calling function passes them as 32-bit words. If the argument is 64-bits, the function passes it as a 4-byte aligned scalar.
- A calling function passes 64-bit floating-point arguments of type double as 4-byte aligned scalars, and passed 32-bit floating-point arguments of type float as 32-bit words.
- It passes a structure or union parameter as a copy. The function then passes the first four words of the resulting memory image in integer registers, and places the remaining words of the argument list image on the stack. If a structure or union parameter is too large to fit completely in the first four words of the argument list, the remainder is stored on the stack.
- If a routine requires stack probes, it uses R1 to pass the requested size for stack memory allocation to chkstk(). If a routine needs half page or more of stack space for the stack frame, a prolog calls the routine. It is also called whenever an alloca() call is made.
The SH-3 calling sequence provides a varargs implementation to enable a variable argument list.
- A routine can implement va_list as a C pointer.
- A routine can implement va_arg() to properly cast and de-reference the va_list. It can then increment the va_list by the size of the given type.
- A routine can implement va_start() to return the address of the item immediately following the start address.
- A routine can implement va_end() as a no operation instruction (NOP).
See Also
SH-3 Calling Sequence Specification | SH-3 Registers | SH-3 Stack Frame Layout | SH-3 Return Values | SH-3 Prolog and Epilog | SH-3 pdata Format | SH-3 Assembler Macros
Last updated on Thursday, April 08, 2004
© 1992-2003 Microsoft Corporation. All rights reserved.