summaryrefslogtreecommitdiff
path: root/gcc/config/d10v/abi
blob: 70ae6dc495db982ef1ec9bcb2ac5045770e90778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
 -*- 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---->	+-------------------------------+