xref: /netbsd/external/bsd/pcc/dist/pcc/arch/mips/macdefs.h (revision 6935091c)
1 /*	Id: macdefs.h,v 1.22 2015/12/31 16:31:09 ragge Exp 	*/
2 /*	$NetBSD: macdefs.h,v 1.1.1.6 2016/02/09 20:28:22 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 defined(os_netbsd) || defined(os_litebsd)
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		(-0x7fffffff-1)
93 #define	MAX_INT		0x7fffffff
94 #define	MAX_UNSIGNED	0xffffffffU
95 #define	MIN_LONG	MIN_INT
96 #define	MAX_LONG	MAX_INT
97 #define	MAX_ULONG	MAX_UNSIGNED
98 #define	MIN_LONGLONG	(-0x7fffffffffffffffLL-1)
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 TARGET_ENDIAN TARGET_LE
126 #define	MYALIGN
127 
128 /* Definitions mostly used in pass2 */
129 
130 #define BYTEOFF(x)	((x)&03)
131 
132 #define	szty(t)		(((t) == DOUBLE || (t) == LDOUBLE || \
133 	DEUNSIGN(t) == LONGLONG) ? 2 : 1)
134 
135 /*
136  * Register names.  These must match rnames[] and rstatus[] in local2.c.
137  */
138 #define ZERO	0
139 #define AT	1
140 #define V0	2
141 #define V1	3
142 #define A0	4
143 #define A1	5
144 #define A2	6
145 #define A3	7
146 #define A4	8
147 #define A5	9
148 #define A6	10
149 #define A7	11
150 #if defined(MIPS_N32) || defined(MIPS_N64)
151 #define T0	12
152 #define T1	13
153 #define	T2	14
154 #define	T3	15
155 #else
156 #define	T0	8
157 #define	T1	9
158 #define	T2	10
159 #define	T3	11
160 #endif
161 #define	T4	12
162 #define	T5	13
163 #define	T6	14
164 #define	T7	15
165 #define S0	16
166 #define S1	17
167 #define S2	18
168 #define S3	19
169 #define S4	20
170 #define S5	21
171 #define S6	22
172 #define S7	23
173 #define T8	24
174 #define T9	25
175 #define K0	26
176 #define K1	27
177 #define GP	28
178 #define SP	29
179 #define FP	30
180 #define RA	31
181 
182 #define V0V1	32
183 #define A0A1	33
184 #define A1A2	34
185 #define A2A3	35
186 
187 /* we just use o32 naming here, but it works ok for n32/n64 */
188 #define A3T0	36
189 #define T0T1	37
190 #define T1T2	38
191 #define T2T3	39
192 #define T3T4	40
193 #define T4T5	41
194 #define T5T6	42
195 #define T6T7	43
196 #define T7T8	44
197 
198 #define T8T9	45
199 #define S0S1	46
200 #define S1S2	47
201 #define S2S3	48
202 #define S3S4	49
203 #define S4S5	50
204 #define S5S6	51
205 #define S6S7	52
206 
207 #define F0	53
208 #define F2	54
209 #define F4	55
210 #define F6	56
211 #define F8	57
212 #define F10	58
213 #define F12	59
214 #define F14	60
215 #define F16	61
216 #define F18	62
217 #define F20	63
218 /* and the rest for later */
219 #define F22	64
220 #define F24	65
221 #define F26	66
222 #define F28	67
223 #define F30	68
224 
225 #define MAXREGS 64
226 #define NUMCLASS 3
227 
228 #define RETREG(x)	(DEUNSIGN(x) == LONGLONG ? V0V1 : \
229 			    (x) == DOUBLE || (x) == LDOUBLE || (x) == FLOAT ? \
230 			    F0 : V0)
231 #define FPREG	FP	/* frame pointer */
232 
233 #define MIPS_N32_NARGREGS	8
234 #define MIPS_O32_NARGREGS	4
235 
236 #define RSTATUS \
237 	0, 0,								\
238 	SAREG|TEMPREG, SAREG|TEMPREG, 					\
239 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
240 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
241 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
242 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
243 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
244 	SAREG|TEMPREG, SAREG|TEMPREG, 					\
245 	0, 0,								\
246 	0, 0, 0, 0,							\
247 	\
248 	SBREG|TEMPREG,							\
249 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,			\
250  	SBREG|TEMPREG,							\
251 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,			\
252 	SBREG|TEMPREG, SBREG|TEMPREG,					\
253 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
254 	SBREG, SBREG, SBREG, SBREG,					\
255 	SBREG, SBREG, SBREG, 						\
256 	SCREG, SCREG, SCREG, SCREG,					\
257 	SCREG, SCREG, SCREG, SCREG,					\
258 	SCREG, SCREG, SCREG, 						\
259 
260 #define ROVERLAP \
261 	{ -1 },				/* $zero */			\
262 	{ -1 },				/* $at */			\
263 	{ V0V1, -1 },			/* $v0 */			\
264 	{ V0V1, -1 },			/* $v1 */			\
265 	{ A0A1, -1 },			/* $a0 */			\
266 	{ A0A1, A1A2, -1 },		/* $a1 */			\
267 	{ A1A2, A2A3, -1 },		/* $a2 */			\
268 	{ A2A3, A3T0, -1 },		/* $a3 */			\
269 	{ A3T0, T0T1, -1 },		/* $t0 */			\
270 	{ T0T1, T1T2, -1 },		/* $t1 */			\
271 	{ T1T2, T2T3, -1 },		/* $t2 */			\
272 	{ T2T3, T3T4, -1 },		/* $t3 */			\
273 	{ T3T4, T4T5, -1 },		/* $t4 */			\
274 	{ T4T5, T5T6, -1 },		/* $t5 */			\
275 	{ T6T7, T7T8, -1 },		/* $t6 */			\
276 	{ T7T8, T8T9, -1 },		/* $t7 */			\
277 	\
278 	{ S0S1, -1 },			/* $s0 */			\
279 	{ S0S1, S1S2, -1 },		/* $s1 */			\
280 	{ S1S2, S2S3, -1 },		/* $s2 */			\
281 	{ S2S3, S3S4, -1 },		/* $s3 */			\
282 	{ S3S4, S4S5, -1 },		/* $s4 */			\
283 	{ S4S5, S5S6, -1 },		/* $s5 */			\
284 	{ S5S6, S6S7, -1 },		/* $s6 */			\
285 	{ S6S7, -1 },			/* $s7 */			\
286 	\
287 	{ T7T8, T8T9, -1 },		/* $t8 */			\
288 	{ T8T9, -1 },			/* $t9 */			\
289 	\
290 	{ -1 },				/* $k0 */			\
291 	{ -1 },				/* $k1 */			\
292 	{ -1 },				/* $gp */			\
293 	{ -1 },				/* $sp */			\
294 	{ -1 },				/* $fp */			\
295 	{ -1 },				/* $ra */			\
296 	\
297 	{ V0, V1, -1 },			/* $v0:$v1 */			\
298 	\
299 	{ A0, A1, A1A2, -1 },		/* $a0:$a1 */			\
300 	{ A1, A2, A0A1, A2A3, -1 },	/* $a1:$a2 */			\
301 	{ A2, A3, A1A2, A3T0, -1 },	/* $a2:$a3 */			\
302 	{ A3, T0, A2A3, T0T1, -1 },	/* $a3:$t0 */			\
303 	{ T0, T1, A3T0, T1T2, -1 },	/* $t0:$t1 */			\
304 	{ T1, T2, T0T1, T2T3, -1 },	/* $t1:$t2 */			\
305 	{ T2, T3, T1T2, T3T4, -1 },	/* $t2:$t3 */			\
306 	{ T3, T4, T2T3, T4T5, -1 },	/* $t3:$t4 */			\
307 	{ T4, T5, T3T4, T5T6, -1 },	/* $t4:$t5 */			\
308 	{ T5, T6, T4T5, T6T7, -1 },	/* $t5:$t6 */			\
309 	{ T6, T7, T5T6, T7T8, -1 },	/* $t6:$t7 */			\
310 	{ T7, T8, T6T7, T8T9, -1 },	/* $t7:$t8 */			\
311 	{ T8, T9, T7T8, -1 },		/* $t8:$t9 */			\
312 	\
313 	{ S0, S1, S1S2, -1 },		/* $s0:$s1 */			\
314 	{ S1, S2, S0S1, S2S3, -1 },					\
315 	{ S2, S3, S1S2, S3S4, -1 },					\
316 	{ S3, S4, S2S3, S4S5, -1 },					\
317 	{ S4, S5, S3S4, S5S6, -1 },					\
318 	{ S5, S6, S4S5, S6S7, -1 },					\
319 	{ S6, S7, S5S6, -1 },						\
320 	\
321 	{ -1 }, { -1 }, { -1 }, { -1 },					\
322 	{ -1 }, { -1 }, { -1 }, { -1 },					\
323 	{ -1 }, { -1 }, { -1 }, 					\
324 
325 #define GCLASS(x)	(x < 32 ? CLASSA : (x < 52 ? CLASSB : CLASSC))
326 #define PCLASS(p)	(1 << gclass((p)->n_type))
327 #define DECRA(x,y)	(((x) >> (y*6)) & 63)   /* decode encoded regs */
328 #define ENCRA(x,y)	((x) << (6+y*6))        /* encode regs in int */
329 #define ENCRD(x)	(x)			/* Encode dest reg in n_reg */
330 
331 int COLORMAP(int c, int *r);
332 
333 extern int bigendian;
334 extern int nargregs;
335 
336 #define SPCON           (MAXSPECIAL+1)  /* positive constant */
337 
338 #define TARGET_STDARGS
339 #define TARGET_BUILTINS							\
340 	{ "__builtin_stdarg_start", mips_builtin_stdarg_start,	       \
341 						0, 2, 0, VOID },	\
342 	{ "__builtin_va_start", mips_builtin_stdarg_start,	       \
343 						0, 2, 0, VOID },	\
344 	{ "__builtin_va_arg", mips_builtin_va_arg, BTNORVAL|BTNOPROTO, \
345 							2, 0, 0 },	\
346 	{ "__builtin_va_end", mips_builtin_va_end, 0, 1, 0, VOID },    \
347 	{ "__builtin_va_copy", mips_builtin_va_copy, 0, 2, 0, VOID },
348 
349 #ifdef LANG_CXX
350 #define P1ND struct node
351 #else
352 #define P1ND struct p1node
353 #endif
354 struct node;
355 struct bitable;
356 P1ND *mips_builtin_stdarg_start(const struct bitable *, P1ND *a);
357 P1ND *mips_builtin_va_arg(const struct bitable *, P1ND *a);
358 P1ND *mips_builtin_va_end(const struct bitable *, P1ND *a);
359 P1ND *mips_builtin_va_copy(const struct bitable *, P1ND *a);
360 #undef P1ND
361 #define NATIVE_FLOATING_POINT
362