OSDN Git Service

Fix Turbo's LPRng compilation failure due to assembler errors.
[pf3gnuchains/gcc-fork.git] / gcc / config / d30v / abi
1 -*- Text -*-
2
3 This document describes the proposed ABI for the D30V processor.  This is
4 revision 2 of the document.
5
6 Revision history:
7
8 Revision 1:
9         Original revision of this document.
10
11 Revision 2:
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.
15
16         Register 1 is now a normal temporary register, since mvfacc rx,ay,32 is
17         legal.
18
19         Arguments greater than 4 bytes must be passed in an even register or at
20         a double word alignment.
21
22         The va_list type is a structure, not a char *.
23
24         The stack must be aligned to 8 byte boundary.  Doubles and long longs
25         must also be aligned to 8 byte boundaries.
26
27         System calls are specified via trap 31.
28
29 Revision 3:
30         I added discussion about compiler switches.
31
32 Register usage:
33 ===============
34
35         Registers       Call Status     Usage
36         ---------       -----------     -----
37         R0              hardware        Hardwired to 0
38         R1              volatile        temp
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
59         A1              saved           Accumulator
60
61 Notes on the register usage:
62 ============================
63
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
66         saved register.
67
68    2)   Repeat instructions and delayed branches cannot cross call boundaries.
69         Similarly, all flags are assumed to not be preserved across calls.
70
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.
75
76    4)   One of the two accumulators is saved across calls.
77
78    5)   Doubles and long longs will only be allocated to even/odd register
79         pairs to allow use of the ld2w/st2w instructions.
80
81 Miscellaneous call information:
82 ===============================
83
84    1)   Structures are passed in registers, rounding them up to word
85         boundaries.
86
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.
91
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
98         processed.
99
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.
103
104
105 The stack frame when a function is called looks like:
106
107 high            |  ....                         |
108                 +-------------------------------+
109                 | Argument word #20             |
110                 +-------------------------------+
111                 | Argument word #19             |
112                 +-------------------------------+
113                 | Argument word #18             |
114                 +-------------------------------+
115                 | Argument word #17             |
116 low     SP----> +-------------------------------+
117
118 After the prologue is executed, the stack frame will look like:
119
120 high            |  ....                         |
121                 +-------------------------------+
122                 | Argument word #20             |
123                 +-------------------------------+
124                 | Argument word #19             |
125                 +-------------------------------+
126                 | Argument word #18             |
127                 +-------------------------------+
128                 | Argument word #17             |
129         Prev sp +-------------------------------+
130                 |                               |
131                 | Save for arguments 1..16 if   |
132                 | the func. uses stdarg/varargs |
133                 |                               |
134                 +-------------------------------+
135                 |                               |
136                 | Save area for preserved regs  |
137                 |                               |
138                 +-------------------------------+
139                 |                               |
140                 | Local variables               |
141                 |                               |
142                 +-------------------------------+
143                 |                               |
144                 | alloca space if used          |
145                 |                               |
146                 +-------------------------------+
147                 |                               |
148                 | Space for outgoing arguments  |
149                 |                               |
150 low     SP----> +-------------------------------+
151
152 System Calls
153 ============
154
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):
160
161         exit    1
162         open    2
163         close   3
164         read    4
165         write   5
166         lseek   6
167         unlink  7
168         getpid  8
169         kill    9
170         fstat   10
171                         (11 is reserved for sbrk)
172         argvlen 12
173         argv    13
174         chdir   14
175         stat    15
176         chmod   16
177         utime   17
178         time    18
179
180 Compiler Switches
181 =================
182
183 The following d30v specific compiler switches are currently supported:
184
185     -mextmem            Link .text/.data/.bss/etc in external memory.
186
187     -mextmemory         Same as -mextmem.
188
189     -monchip            Link .text/.data/.bss/etc in the onchip data/text
190                         memory.
191
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).
196
197     -masm-optimize      [default] If optimizing, pass -O to the assembler.
198
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
202                         2.
203
204     -mcond-exec=n       Replace branches around n insns with conditional
205                         execution if we can.  Default is 4.
206
207
208 Sections
209 ========
210
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.
216
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
220 external memory.
221
222
223 Stack pointer
224 =============
225
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:
230
231         -Wl,-defsym,__stack=0x20008000