xref: /netbsd/external/bsd/pcc/dist/pcc/arch/mips/macdefs.h (revision 6550d01e)
1 /*	Id: macdefs.h,v 1.10 2009/01/24 21:43:49 gmcgarry Exp 	*/
2 /*	$NetBSD: macdefs.h,v 1.1.1.3 2010/06/03 18:57:19 plunky Exp $	*/
3 /*
4  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * MIPS port by Jan Enoksson (janeno-1@student.ltu.se) and
32  * Simon Olsson (simols-1@student.ltu.se) 2005.
33  */
34 
35 /*
36  * Machine-dependent defines for both passes.
37  */
38 
39 #if TARGOS == netbsd
40 #define USE_GAS
41 #endif
42 
43 /*
44  * Convert (multi-)character constant to integer.
45  * Assume: If only one value; store at left side (char size), otherwise
46  * treat it as an integer.
47  */
48 #define makecc(val,i)	lastcon = (lastcon<<8)|((val<<24)>>24);
49 
50 #define ARGINIT		(16*8)	/* # bits above fp where arguments start */
51 #define AUTOINIT	(0)	/* # bits below fp where automatics start */
52 
53 /*
54  * Storage space requirements
55  */
56 #define SZCHAR		8
57 #define SZBOOL		32
58 #define SZINT		32
59 #define SZFLOAT		32
60 #define SZDOUBLE	64
61 #define SZLDOUBLE	64
62 #define SZLONG		32
63 #define SZSHORT		16
64 #define SZLONGLONG	64
65 #define SZPOINT(t)	32
66 
67 /*
68  * Alignment constraints
69  */
70 #define ALCHAR		8
71 #define ALBOOL		32
72 #define ALINT		32
73 #define ALFLOAT		32
74 #define ALDOUBLE	64
75 #define ALLDOUBLE	64
76 #define ALLONG		32
77 #define ALLONGLONG	64
78 #define ALSHORT		16
79 #define ALPOINT		32
80 #define ALSTRUCT	64
81 #define ALSTACK		32
82 
83 /*
84  * Min/max values.
85  */
86 #define	MIN_CHAR	-128
87 #define	MAX_CHAR	127
88 #define	MAX_UCHAR	255
89 #define	MIN_SHORT	-32768
90 #define	MAX_SHORT	32767
91 #define	MAX_USHORT	65535
92 #define	MIN_INT		-1
93 #define	MAX_INT		0x7fffffff
94 #define	MAX_UNSIGNED	0xffffffff
95 #define	MIN_LONG	MIN_INT
96 #define	MAX_LONG	MAX_INT
97 #define	MAX_ULONG	MAX_UNSIGNED
98 #define	MIN_LONGLONG	0x8000000000000000LL
99 #define	MAX_LONGLONG	0x7fffffffffffffffLL
100 #define	MAX_ULONGLONG	0xffffffffffffffffULL
101 
102 #undef	CHAR_UNSIGNED
103 #define BOOL_TYPE	INT
104 
105 /*
106  * Use large-enough types.
107  */
108 typedef	long long CONSZ;
109 typedef	unsigned long long U_CONSZ;
110 typedef long long OFFSZ;
111 
112 #define CONFMT	"%lld"		/* format for printing constants */
113 #ifdef USE_GAS
114 #define LABFMT	"$L%d"		/* format for printing labels */
115 #define	STABLBL	"$LL%d"		/* format for stab (debugging) labels */
116 #else
117 #define LABFMT	"L%d"		/* format for printing labels */
118 #define	STABLBL	"LL%d"		/* format for stab (debugging) labels */
119 #endif
120 
121 #define BACKAUTO 		/* stack grows negatively for automatics */
122 #define BACKTEMP 		/* stack grows negatively for temporaries */
123 
124 #undef	FIELDOPS		/* no bit-field instructions */
125 #define RTOLBYTES 1		/* bytes are numbered right to left */
126 
127 #define ENUMSIZE(high,low) INT	/* enums are always stored in full int */
128 
129 /* Definitions mostly used in pass2 */
130 
131 #define BYTEOFF(x)	((x)&03)
132 #define BITOOR(x)	(x)	/* bit offset to oreg offset */
133 
134 #define	szty(t)		(((t) == DOUBLE || (t) == LDOUBLE || \
135 	DEUNSIGN(t) == LONGLONG) ? 2 : 1)
136 
137 /*
138  * Register names.  These must match rnames[] and rstatus[] in local2.c.
139  */
140 #define ZERO	0
141 #define AT	1
142 #define V0	2
143 #define V1	3
144 #define A0	4
145 #define A1	5
146 #define A2	6
147 #define A3	7
148 #define A4	8
149 #define A5	9
150 #define A6	10
151 #define A7	11
152 #if defined(MIPS_N32) || defined(MIPS_N64)
153 #define T0	12
154 #define T1	13
155 #define	T2	14
156 #define	T3	15
157 #else
158 #define	T0	8
159 #define	T1	9
160 #define	T2	10
161 #define	T3	11
162 #endif
163 #define	T4	12
164 #define	T5	13
165 #define	T6	14
166 #define	T7	15
167 #define S0	16
168 #define S1	17
169 #define S2	18
170 #define S3	19
171 #define S4	20
172 #define S5	21
173 #define S6	22
174 #define S7	23
175 #define T8	24
176 #define T9	25
177 #define K0	26
178 #define K1	27
179 #define GP	28
180 #define SP	29
181 #define FP	30
182 #define RA	31
183 
184 #define V0V1	32
185 #define A0A1	33
186 #define A1A2	34
187 #define A2A3	35
188 
189 /* we just use o32 naming here, but it works ok for n32/n64 */
190 #define A3T0	36
191 #define T0T1	37
192 #define T1T2	38
193 #define T2T3	39
194 #define T3T4	40
195 #define T4T5	41
196 #define T5T6	42
197 #define T6T7	43
198 #define T7T8	44
199 
200 #define T8T9	45
201 #define S0S1	46
202 #define S1S2	47
203 #define S2S3	48
204 #define S3S4	49
205 #define S4S5	50
206 #define S5S6	51
207 #define S6S7	52
208 
209 #define F0	53
210 #define F2	54
211 #define F4	55
212 #define F6	56
213 #define F8	57
214 #define F10	58
215 #define F12	59
216 #define F14	60
217 #define F16	61
218 #define F18	62
219 #define F20	63
220 /* and the rest for later */
221 #define F22	64
222 #define F24	65
223 #define F26	66
224 #define F28	67
225 #define F30	68
226 
227 #define MAXREGS 64
228 #define NUMCLASS 3
229 
230 #define RETREG(x)	(DEUNSIGN(x) == LONGLONG ? V0V1 : \
231 			    (x) == DOUBLE || (x) == LDOUBLE || (x) == FLOAT ? \
232 			    F0 : V0)
233 #define FPREG	FP	/* frame pointer */
234 
235 #define MIPS_N32_NARGREGS	8
236 #define MIPS_O32_NARGREGS	4
237 
238 #define RSTATUS \
239 	0, 0,								\
240 	SAREG|TEMPREG, SAREG|TEMPREG, 					\
241 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
242 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
243 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
244 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
245 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
246 	SAREG|TEMPREG, SAREG|TEMPREG, 					\
247 	0, 0,								\
248 	0, 0, 0, 0,							\
249 	\
250 	SBREG|TEMPREG,							\
251 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,			\
252  	SBREG|TEMPREG,							\
253 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,			\
254 	SBREG|TEMPREG, SBREG|TEMPREG,					\
255 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
256 	SBREG, SBREG, SBREG, SBREG,					\
257 	SBREG, SBREG, SBREG, 						\
258 	SCREG, SCREG, SCREG, SCREG,					\
259 	SCREG, SCREG, SCREG, SCREG,					\
260 	SCREG, SCREG, SCREG, 						\
261 
262 #define ROVERLAP \
263 	{ -1 },				/* $zero */			\
264 	{ -1 },				/* $at */			\
265 	{ V0V1, -1 },			/* $v0 */			\
266 	{ V0V1, -1 },			/* $v1 */			\
267 	{ A0A1, -1 },			/* $a0 */			\
268 	{ A0A1, A1A2, -1 },		/* $a1 */			\
269 	{ A1A2, A2A3, -1 },		/* $a2 */			\
270 	{ A2A3, A3T0, -1 },		/* $a3 */			\
271 	{ A3T0, T0T1, -1 },		/* $t0 */			\
272 	{ T0T1, T1T2, -1 },		/* $t1 */			\
273 	{ T1T2, T2T3, -1 },		/* $t2 */			\
274 	{ T2T3, T3T4, -1 },		/* $t3 */			\
275 	{ T3T4, T4T5, -1 },		/* $t4 */			\
276 	{ T4T5, T5T6, -1 },		/* $t5 */			\
277 	{ T6T7, T7T8, -1 },		/* $t6 */			\
278 	{ T7T8, T8T9, -1 },		/* $t7 */			\
279 	\
280 	{ S0S1, -1 },			/* $s0 */			\
281 	{ S0S1, S1S2, -1 },		/* $s1 */			\
282 	{ S1S2, S2S3, -1 },		/* $s2 */			\
283 	{ S2S3, S3S4, -1 },		/* $s3 */			\
284 	{ S3S4, S4S5, -1 },		/* $s4 */			\
285 	{ S4S5, S5S6, -1 },		/* $s5 */			\
286 	{ S5S6, S6S7, -1 },		/* $s6 */			\
287 	{ S6S7, -1 },			/* $s7 */			\
288 	\
289 	{ T7T8, T8T9, -1 },		/* $t8 */			\
290 	{ T8T9, -1 },			/* $t9 */			\
291 	\
292 	{ -1 },				/* $k0 */			\
293 	{ -1 },				/* $k1 */			\
294 	{ -1 },				/* $gp */			\
295 	{ -1 },				/* $sp */			\
296 	{ -1 },				/* $fp */			\
297 	{ -1 },				/* $ra */			\
298 	\
299 	{ V0, V1, -1 },			/* $v0:$v1 */			\
300 	\
301 	{ A0, A1, A1A2, -1 },		/* $a0:$a1 */			\
302 	{ A1, A2, A0A1, A2A3, -1 },	/* $a1:$a2 */			\
303 	{ A2, A3, A1A2, A3T0, -1 },	/* $a2:$a3 */			\
304 	{ A3, T0, A2A3, T0T1, -1 },	/* $a3:$t0 */			\
305 	{ T0, T1, A3T0, T1T2, -1 },	/* $t0:$t1 */			\
306 	{ T1, T2, T0T1, T2T3, -1 },	/* $t1:$t2 */			\
307 	{ T2, T3, T1T2, T3T4, -1 },	/* $t2:$t3 */			\
308 	{ T3, T4, T2T3, T4T5, -1 },	/* $t3:$t4 */			\
309 	{ T4, T5, T3T4, T5T6, -1 },	/* $t4:$t5 */			\
310 	{ T5, T6, T4T5, T6T7, -1 },	/* $t5:$t6 */			\
311 	{ T6, T7, T5T6, T7T8, -1 },	/* $t6:$t7 */			\
312 	{ T7, T8, T6T7, T8T9, -1 },	/* $t7:$t8 */			\
313 	{ T8, T9, T7T8, -1 },		/* $t8:$t9 */			\
314 	\
315 	{ S0, S1, S1S2, -1 },		/* $s0:$s1 */			\
316 	{ S1, S2, S0S1, S2S3, -1 },					\
317 	{ S2, S3, S1S2, S3S4, -1 },					\
318 	{ S3, S4, S2S3, S4S5, -1 },					\
319 	{ S4, S5, S3S4, S5S6, -1 },					\
320 	{ S5, S6, S4S5, S6S7, -1 },					\
321 	{ S6, S7, S5S6, -1 },						\
322 	\
323 	{ -1 }, { -1 }, { -1 }, { -1 },					\
324 	{ -1 }, { -1 }, { -1 }, { -1 },					\
325 	{ -1 }, { -1 }, { -1 }, 					\
326 
327 #define GCLASS(x)	(x < 32 ? CLASSA : (x < 52 ? CLASSB : CLASSC))
328 #define PCLASS(p)	(1 << gclass((p)->n_type))
329 #define DECRA(x,y)	(((x) >> (y*6)) & 63)   /* decode encoded regs */
330 #define ENCRA(x,y)	((x) << (6+y*6))        /* encode regs in int */
331 #define ENCRD(x)	(x)			/* Encode dest reg in n_reg */
332 
333 int COLORMAP(int c, int *r);
334 
335 extern int bigendian;
336 extern int nargregs;
337 
338 #define SPCON           (MAXSPECIAL+1)  /* positive constant */
339 
340 #define TARGET_STDARGS
341 #define TARGET_BUILTINS						\
342 	{ "__builtin_stdarg_start", mips_builtin_stdarg_start },	\
343 	{ "__builtin_va_arg", mips_builtin_va_arg },		\
344 	{ "__builtin_va_end", mips_builtin_va_end },		\
345 	{ "__builtin_va_copy", mips_builtin_va_copy },
346 
347 struct node;
348 struct node *mips_builtin_stdarg_start(struct node *f, struct node *a);
349 struct node *mips_builtin_va_arg(struct node *f, struct node *a);
350 struct node *mips_builtin_va_end(struct node *f, struct node *a);
351 struct node *mips_builtin_va_copy(struct node *f, struct node *a);
352