-*- Text -*- This document describes the proposed ABI for the d10v. The register calling convention is: +-------+-----------------------+-----------------------+ | Reg. | At prologue | After epilogue | +-------+-----------------------+-----------------------+ | R0 | Argument #1 | Return value, word 1 | +-------+-----------------------+-----------------------+ | R1 | Argument #2 | Return value, word 2 | +-------+-----------------------+-----------------------+ | R2 | Argument #3 | Return value, word 3 | +-------+-----------------------+-----------------------+ | R3 | Argument #4 | Return value, word 4 | +-------+-----------------------+-----------------------+ | R4 | Static chain if needed| Don't care | +-------+-----------------------+-----------------------+ | R5 | Work | Don't care | +-------+-----------------------+-----------------------+ | R6 | Work | Previous value | +-------+-----------------------+-----------------------+ | R7 | Work | Previous value | +-------+-----------------------+-----------------------+ | R8 | Work | Previous value | +-------+-----------------------+-----------------------+ | R9 | Work | Previous value | +-------+-----------------------+-----------------------+ | R10 | Work | Previous value | +-------+-----------------------+-----------------------+ | R11 | Frame ptr if needed | Previous value | +-------+-----------------------+-----------------------+ | R12 | Work | Don't care | +-------+-----------------------+-----------------------+ | R13 | Return address | Don't care | +-------+-----------------------+-----------------------+ | R14 | memory base (0) | memory base (0) | +-------+-----------------------+-----------------------+ | R15 | Stack pointer | Previous value | +-------+-----------------------+-----------------------+ | A0 | Work | Previous value | +-------+-----------------------+-----------------------+ | A1 | Work | Previous value | +-------+-----------------------+-----------------------+ The 'int' type is 16 bits, unless the -mint32 switch is used. The 'long' type is always 32 bits, the 'short' type is always 16 bits, and pointers are 16 bits. The 'double' type is treated as 'float' and uses 32-bits unless the -mdouble64 switch is used. The long double type still uses 64 bits. If more than 4 words of arguments are passed, they are passed on the stack. The GCC compiler will omit the frame pointer for all functions except those that dynamically grow the stack frame (ie, the GNU extensions of variable sized arrays or calls to alloca). The GCC compiler will always eliminate the pseudo argument pointer the compiler synthesizes in favor of the stack or frame pointer. The GCC compiler only passes the static chain when calling nested functions, which is a GNU extension. The stack starts at high memory and descends downward. The heap starts at the end of the bss section and ascends upward. The stack is assumed to be aligned to a word boundary. Register r14 will be used as the index register in accessing global/static variables if no index register is used. The crt0 that we provide will place a zero in it, and the compiler will expect that. The varargs/stdarg support defines the va_list type as follows: typedef struct __va_list_tag { short *__va_arg_ptr; /* start of the register save area */ int __va_arg_num; /* argument number */ } va_list[1]; It is an array so that passing it to vprintf and friends passes just a pointer to the structure. Calls to varargs/stdarg functions push the four words corresponding to the first four arguments on the stack immediately before adjusting the stack pointer any further. The stack frame when a function is called looks like: high | .... | +-------------------------------+ | Argument word #8 | +-------------------------------+ | Argument word #7 | +-------------------------------+ | Argument word #6 | +-------------------------------+ | Argument word #5 | low SP----> +-------------------------------+ After the prologue is executed, the stack frame will look like: high | .... | +-------------------------------+ | Argument word #8 | +-------------------------------+ | Argument word #7 | +-------------------------------+ | Argument word #6 | +-------------------------------+ | Argument word #5 | Prev sp +-------------------------------+ | | | Save for arguments 1..4 if | | the func. uses stdarg/varargs | | | +-------------------------------+ | | | Local variables | | | +-------------------------------+ | | | Save area for preserved regs | | | +-------------------------------+ | | | alloca space if used | | | +-------------------------------+ | | | Space for outgoing arguments | | | low SP----> +-------------------------------+