3 This document describes the proposed ABI for the D30V processor. This is
4 revision 2 of the document.
9 Original revision of this document.
12 Done after consultation with Mitsubshi about the calling sequence.
13 This revision now reduces the number of registers the compiler will not
14 touch from 18 registers down to 8.
16 Register 1 is now a normal temporary register, since mvfacc rx,ay,32 is
19 Arguments greater than 4 bytes must be passed in an even register or at
20 a double word alignment.
22 The va_list type is a structure, not a char *.
24 The stack must be aligned to 8 byte boundary. Doubles and long longs
25 must also be aligned to 8 byte boundaries.
27 System calls are specified via trap 31.
30 I added discussion about compiler switches.
35 Registers Call Status Usage
36 --------- ----------- -----
37 R0 hardware Hardwired to 0
39 R2 volatile Arg 1 and main return value.
40 R3 volatile Arg 2 and low bits of 64 bit returns
41 R4 - R17 volatile Args 3-16
42 R18 volatile Static chain if used
43 R19 - R25 volatile temps
44 R26 - R33 saved Reserved for user use
45 R34 - R60 saved Registers preserved across calls
46 R61 saved Frame pointer if needed.
47 R62 saved Return address pointer (hardware)
48 R63 saved Stack pointer
49 CR0 - CR3 hardware {normal,backup} {psw,pc}
50 CR4 - CR6 hardware Reserved for future use
51 CR7 - CR9 volatile Repeat count, addresses
52 CR10 - CR11 saved Modulo start/end
53 CR12 - CR14 hardware Reserved for future use
54 CR15 - CR17 hardware Interrupt support
55 F0 - F1 volatile Execution flags
56 F2 - F3 volatile General flags
57 F4 - F7 volatile Special purpose flags
58 A0 volatile Accumulator
61 Notes on the register usage:
62 ============================
64 1) R61 will hold the frame pointer if it is needed. Normally the frame
65 pointer will not be needed, in which case this will become another
68 2) Repeat instructions and delayed branches cannot cross call boundaries.
69 Similarly, all flags are assumed to not be preserved across calls.
71 3) Since so many registers are available, I reserved 8 registers (r26-r33)
72 for the user to use for any purpose (global variables, interrupt
73 routines, thread pointer, etc.). These registers will not be used by
74 the compiler for any purpose.
76 4) One of the two accumulators is saved across calls.
78 5) Doubles and long longs will only be allocated to even/odd register
79 pairs to allow use of the ld2w/st2w instructions.
81 Miscellaneous call information:
82 ===============================
84 1) Structures are passed in registers, rounding them up to word
87 2) Any argument that is greater than word size (4 bytes) must be aligned
88 to a double word boundary and/or start in an even register. The
89 intention here is to be able to use the ld2w/st2w instructions for
90 moving doubles and long longs.
92 3) Variable argument functions are called with the same calling sequence
93 as non-variable argument functions. When called, a variable argument
94 function first saves the 16 registers (R2 - R17) used for passing
95 arguments. The va_list type is a structure. The first element of the
96 structure is a pointer to the first word saved on the stack, and the
97 second element is a number that gives which argument number is being
100 4) Word and double word sized structures/unions are returned in registers,
101 other functions returning structures expect a temporary area address to
102 be passed as the first argument.
105 The stack frame when a function is called looks like:
108 +-------------------------------+
109 | Argument word #20 |
110 +-------------------------------+
111 | Argument word #19 |
112 +-------------------------------+
113 | Argument word #18 |
114 +-------------------------------+
115 | Argument word #17 |
116 low SP----> +-------------------------------+
118 After the prologue is executed, the stack frame will look like:
121 +-------------------------------+
122 | Argument word #20 |
123 +-------------------------------+
124 | Argument word #19 |
125 +-------------------------------+
126 | Argument word #18 |
127 +-------------------------------+
128 | Argument word #17 |
129 Prev sp +-------------------------------+
131 | Save for arguments 1..16 if |
132 | the func. uses stdarg/varargs |
134 +-------------------------------+
136 | Save area for preserved regs |
138 +-------------------------------+
142 +-------------------------------+
144 | alloca space if used |
146 +-------------------------------+
148 | Space for outgoing arguments |
150 low SP----> +-------------------------------+
155 System calls will be done using "TRAP 31". Input arguments will be in R2 - R5,
156 and the system call number will be in R6. Return values from the system call
157 will be in R2. Negative values of the return indicate the system call failed,
158 and the value is the negative of the error code. Here are the assigned system
159 call numbers (value in R6):
171 (11 is reserved for sbrk)
183 The following d30v specific compiler switches are currently supported:
185 -mextmem Link .text/.data/.bss/etc in external memory.
187 -mextmemory Same as -mextmem.
189 -monchip Link .text/.data/.bss/etc in the onchip data/text
192 -mno-asm-optimize Do not pass -O to the assembler when optimizing (the -O
193 switch will mark two short instructions that don't
194 interfere with each other as being done parallel
195 instead of sequentially).
197 -masm-optimize [default] If optimizing, pass -O to the assembler.
199 -mbranch-cost=n Increase the internal costs of branches to n. Higher
200 costs means that the compiler will issue more
201 instructions to avoid doing a branch. The default is
204 -mcond-exec=n Replace branches around n insns with conditional
205 execution if we can. Default is 4.
211 You can override the effect of the -mextmem/-monchip options by putting
212 functions into either the ".stext" or ".etext" sections. If you put them into
213 the ".stext" section, the linker will always link the function into the onchip
214 memory area. Similarly, if you put the function in the ".etext" section, the
215 linker will always link the function into the external memory area.
217 Data can be controlled as well. If you put the data in the ".sdata" section,
218 the linker will put the data into the onchip data area. Similarly, if you put
219 the data in the ".edata" section, the linker will put the data into the
226 The crt0.o that we ship loads up the stack pointer with the value of the label
227 __stack. If you do not define a value for __stack, the linker will choose the
228 top of the onchip data area (0x20008000) for the stack pointer. You can set a
229 new value via the options:
231 -Wl,-defsym,__stack=0x20008000