1 /*	$Id: macdefs.h,v 1.20 2014/06/01 11:35:02 ragge Exp $	*/
2 
3 /*
4  * Copyright (c) 2007 Michael Shalayeff
5  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  * Convert (multi-)character constant to integer.
33  */
34 #define	makecc(val,i)	(lastcon = (lastcon<<8)|((val<<24)>>24))
35 
36 #define	ARGINIT		(32*8)	/* bits below fp where args start */
37 #define	AUTOINIT	(4*8)	/* bits above fp where locals start */
38 
39 /*
40  * storage sizes
41  */
42 #define	SZCHAR		8
43 #define	SZBOOL		8
44 #define	SZINT		32
45 #define	SZFLOAT		32
46 #define	SZDOUBLE	64
47 #define	SZLDOUBLE	64	/* or later 128 */
48 #define	SZLONG		32
49 #define	SZSHORT		16
50 #define	SZLONGLONG	64
51 #define	SZPOINT(t)	32
52 
53 /*
54  * alignment requirements
55  */
56 #define	ALCHAR		8
57 #define	ALBOOL		8
58 #define	ALINT		32
59 #define	ALFLOAT		32
60 #define	ALDOUBLE	64
61 #define	ALLDOUBLE	64	/* 128 later */
62 #define	ALLONG		32
63 #define	ALLONGLONG	32
64 #define	ALSHORT		16
65 #define	ALPOINT		32
66 #define	ALSTRUCT	32
67 #define	ALSTACK		64
68 
69 /*
70  * type value limits
71  */
72 #define	MIN_CHAR	-128
73 #define	MAX_CHAR	127
74 #define	MAX_UCHAR	255
75 #define	MIN_SHORT	-32768
76 #define	MAX_SHORT	32767
77 #define	MAX_USHORT	65535
78 #define	MIN_INT		(-0x7fffffff-1)
79 #define	MAX_INT		0x7fffffff
80 #define	MAX_UNSIGNED	0xffffffff
81 #define	MIN_LONG	MIN_INT
82 #define	MAX_LONG	MAX_INT
83 #define	MAX_ULONG	MAX_UNSIGNED
84 #define	MIN_LONGLONG	(-0x7fffffffffffffffLL-1)
85 #define	MAX_LONGLONG	0x7fffffffffffffffLL
86 #define	MAX_ULONGLONG	0xffffffffffffffffULL
87 
88 #undef	CHAR_UNSIGNED
89 #define	BOOL_TYPE	CHAR
90 
91 typedef long long CONSZ;
92 typedef unsigned long long U_CONSZ;
93 typedef long long OFFSZ;
94 
95 #define	CONFMT	"%lld"		/* format for printing constants */
96 #define	LABFMT	".L%d"		/* format for printing labels */
97 #define	STABLBL	".LL%d"		/* format for stab (debugging) labels */
98 
99 #undef	BACKAUTO	/* stack grows upwards */
100 #undef	BACKTEMP	/* stack grows upwards */
101 
102 #define	FIELDOPS	/* have bit field ops */
103 #define	TARGET_ENDIAN	TARGET_BE
104 #define	TARGET_FLT_EVAL_METHOD	0	/* all as their type */
105 
106 #define	BYTEOFF(x)	((x)&03)
107 #define	wdal(k)		(BYTEOFF(k)==0)
108 
109 #define	STOARG(p)
110 #define	STOFARG(p)
111 #define	STOSTARG(p)
112 
113 #define	szty(t)	(((t) == DOUBLE || (t) == LONGLONG || (t) == ULONGLONG) ? 2 : \
114 	    (t) == LDOUBLE ? 2 : 1)
115 
116 #define	R0	0
117 #define	R1	1
118 #define	RP	2
119 #define	FP	3
120 #define	R4	4
121 #define	R5	5
122 #define	R6	6
123 #define	R7	7
124 #define	R8	8
125 #define	R9	9
126 #define	R10	10
127 #define	R11	11
128 #define	R12	12
129 #define	R13	13
130 #define	R14	14
131 #define	R15	15
132 #define	R16	16
133 #define	R17	17
134 #define	R18	18
135 #define	T4	19
136 #define	T3	20
137 #define	T2	21
138 #define	T1	22
139 #define	ARG3	23
140 #define	ARG2	24
141 #define	ARG1	25
142 #define	ARG0	26
143 #define	DP	27
144 #define	RET0	28
145 #define	RET1	29
146 #define	SP	30
147 #define	R31	31
148 
149 /* double regs overlay */
150 #define	RD0	32	/* r0:r0 */
151 #define	RD1	33	/* r1:r31 */
152 #define	RD2	34	/* r1:t4 */
153 #define	RD3	35	/* r1:t3 */
154 #define	RD4	36	/* r1:t2 */
155 #define	RD5	37	/* r1:t1 */
156 #define	RD6	38	/* r31:t4 */
157 #define	RD7	39	/* r31:t3 */
158 #define	RD8	40	/* r31:t2 */
159 #define	RD9	41	/* r31:t1 */
160 #define	RD10	42	/* r4:r18 */
161 #define	RD11	43	/* r5:r4 */
162 #define	RD12	44	/* r6:r5 */
163 #define	RD13	45	/* r7:r6 */
164 #define	RD14	46	/* r8:r7 */
165 #define	RD15	47	/* r9:r8 */
166 #define	RD16	48	/* r10:r9 */
167 #define	RD17	49	/* r11:r10 */
168 #define	RD18	50	/* r12:r11 */
169 #define	RD19	51	/* r13:r12 */
170 #define	RD20	52	/* r14:r13 */
171 #define	RD21	53	/* r15:r14 */
172 #define	RD22	54	/* r16:r15 */
173 #define	RD23	55	/* r17:r16 */
174 #define	RD24	56	/* r18:r17 */
175 #define	TD4	57	/* t1:t4 */
176 #define	TD3	58	/* t4:t3 */
177 #define	TD2	59	/* t3:t2 */
178 #define	TD1	60	/* t2:t1 */
179 #define	AD2	61	/* arg3:arg2 */
180 #define	AD1	62	/* arg1:arg0 */
181 #define	RETD0	63	/* ret1:ret0 */
182 
183 /* FPU regs */
184 #define	FR0	64
185 #define	FR4	65
186 #define	FR5	66
187 #define	FR6	67
188 #define	FR7	68
189 #define	FR8	69
190 #define	FR9	70
191 #define	FR10	71
192 #define	FR11	72
193 #define	FR12	73
194 #define	FR13	74
195 #define	FR14	75
196 #define	FR15	76
197 #define	FR16	77
198 #define	FR17	78
199 #define	FR18	79
200 #define	FR19	80
201 #define	FR20	81
202 #define	FR21	82
203 #define	FR22	83
204 #define	FR23	84
205 #define	FR24	85
206 #define	FR25	86
207 #define	FR26	87
208 #define	FR27	88
209 #define	FR28	89
210 #define	FR29	90
211 #define	FR30	91
212 #define	FR31	92
213 
214 #define	FR0L	93
215 #define	FR0R	94
216 #define	FR4L	95
217 #define	FR4R	96
218 #define	FR5L	97
219 #define	FR5R	98
220 #define	FR6L	99
221 #define	FR6R	100
222 #define	FR7L	101
223 #define	FR7R	102
224 #define	FR8L	103
225 #define	FR8R	104
226 #define	FR9L	105
227 #define	FR9R	106
228 #define	FR10L	107
229 #define	FR10R	108
230 #define	FR11L	109
231 #define	FR11R	110
232 #define	FR12L	111
233 #define	FR12R	112
234 #define	FR13L	113
235 #define	FR13R	114
236 #define	FR14L	115
237 #define	FR14R	116
238 #define	FR15L	117
239 #define	FR15R	118
240 #define	FR16L	119
241 #define	FR16R	120
242 #define	FR17L	121
243 #define	FR17R	122
244 #define	FR18L	123
245 #define	FR18R	124
246 #ifdef __hppa64__
247 #define	FR19L	125
248 #define	FR19R	126
249 #define	FR20L	127
250 #define	FR20R	128
251 #define	FR21L	129
252 #define	FR21R	130
253 #define	FR22L	131
254 #define	FR22R	132
255 #define	FR23L	133
256 #define	FR23R	134
257 #define	FR24L	135
258 #define	FR24R	136
259 #define	FR25L	137
260 #define	FR25R	138
261 #define	FR26L	139
262 #define	FR26R	140
263 #define	FR27L	141
264 #define	FR27R	142
265 #define	FR28L	143
266 #define	FR28R	144
267 #define	FR29L	145
268 #define	FR29R	146
269 #define	FR30L	147
270 #define	FR30R	148
271 #define	FR31L	149
272 #define	FR31R	150
273 
274 #define	MAXREGS	151
275 #else
276 #define	MAXREGS	125
277 #endif
278 
279 #define	RSTATUS \
280 	0, SAREG|TEMPREG, 0, 0, SAREG|PERMREG, SAREG|PERMREG,		\
281 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
282 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
283 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
284 	SAREG|PERMREG,							\
285 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, 	\
286 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, 	\
287 	0, SAREG|TEMPREG, SAREG|TEMPREG, 0, SAREG|TEMPREG,		\
288 	/* double overlays */						\
289 	0,								\
290 	SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG,		\
291 	SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG,		\
292 	SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG,		\
293 	SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG,		\
294 	/* double-precision floats */					\
295 	0,								\
296 	SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG,	\
297 	SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG,	\
298 	SDREG|PERMREG, SDREG|PERMREG, SDREG|PERMREG, SDREG|PERMREG,	\
299 	SDREG|PERMREG, SDREG|PERMREG, SDREG|PERMREG, SDREG|PERMREG,	\
300 	SDREG|PERMREG, SDREG|PERMREG,					\
301 	SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG,	\
302 	SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG, SDREG|TEMPREG,	\
303 	SDREG|TEMPREG, SDREG|TEMPREG,					\
304 	/* single-precision floats */					\
305 	0, 0,								\
306 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,		\
307 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,		\
308 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,		\
309 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,
310 #ifdef __hppa64__
311 	SCREG, SCREG,		\
312 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,		\
313 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,		\
314 	SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG,
315 #endif
316 
317 #define	ROVERLAP \
318 	{ -1 },				\
319 	{ RD1, RD2, RD3, RD4, RD5, -1 },\
320 	{ -1 }, { -1 },			\
321 	{ RD10, RD11, -1 },		\
322 	{ RD11, RD12, -1 },		\
323 	{ RD12, RD13, -1 },		\
324 	{ RD13, RD14, -1 },		\
325 	{ RD14, RD15, -1 },		\
326 	{ RD15, RD16, -1 },		\
327 	{ RD16, RD17, -1 },		\
328 	{ RD17, RD18, -1 },		\
329 	{ RD18, RD19, -1 },		\
330 	{ RD19, RD20, -1 },		\
331 	{ RD20, RD21, -1 },		\
332 	{ RD21, RD22, -1 },		\
333 	{ RD22, RD23, -1 },		\
334 	{ RD23, RD24, -1 },		\
335 	{ RD24, RD10, -1 },		\
336 	{ TD1, TD4, -1 },		\
337 	{ TD3, TD2, -1 },		\
338 	{ TD1, TD2, -1 },		\
339 	{ TD1, TD4, -1 },		\
340 	{ AD2, -1 }, { AD2, -1 },	\
341 	{ AD1, -1 }, { AD1, -1 },	\
342 	{ -1 },				\
343 	{ RETD0, -1 }, { RETD0, -1 },	\
344 	{ -1 },				\
345 	{ RD1, RD5, RD6, RD7, RD8, -1 },\
346 	{ -1 },				\
347 	{ R1, R31, -1 },		\
348 	{ R1, T4, -1 },			\
349 	{ R1, T3, -1 },			\
350 	{ R1, T2, -1 },			\
351 	{ R1, T1, -1 },			\
352 	{ R31, T4, -1 },		\
353 	{ R31, T3, -1 },		\
354 	{ R31, T2, -1 },		\
355 	{ R31, T1, -1 },		\
356 	{ R4, R18, -1 },		\
357 	{ R5, R4, -1 },			\
358 	{ R6, R5, -1 },			\
359 	{ R7, R6, -1 },			\
360 	{ R8, R7, -1 },			\
361 	{ R9, R8, -1 },			\
362 	{ R10, R9, -1 },		\
363 	{ R11, R10, -1 },		\
364 	{ R12, R11, -1 },		\
365 	{ R13, R12, -1 },		\
366 	{ R14, R15, -1 },		\
367 	{ R15, R14, -1 },		\
368 	{ R16, R15, -1 },		\
369 	{ R17, R16, -1 },		\
370 	{ R18, R17, -1 },		\
371 	{ T1, T4, -1 },			\
372 	{ T4, T3, -1 },			\
373 	{ T3, T2, -1 },			\
374 	{ T2, T1, -1 },			\
375 	{ ARG3, ARG2, -1 },		\
376 	{ ARG1, ARG0, -1 },		\
377 	{ RET1, RET0, -1 },		\
378 	{ -1 },				\
379 	{ FR4L, FR4R, -1 },		\
380 	{ FR5L, FR5R, -1 },		\
381 	{ FR6L, FR6R, -1 },		\
382 	{ FR7L, FR7R, -1 },		\
383 	{ FR8L, FR8R, -1 },		\
384 	{ FR9L, FR9R, -1 },		\
385 	{ FR10L, FR10R, -1 },		\
386 	{ FR11L, FR11R, -1 },		\
387 	{ FR12L, FR12R, -1 },		\
388 	{ FR13L, FR13R, -1 },		\
389 	{ FR14L, FR14R, -1 },		\
390 	{ FR15L, FR15R, -1 },		\
391 	{ FR16L, FR16R, -1 },		\
392 	{ FR17L, FR17R, -1 },		\
393 	{ FR18L, FR18R, -1 },		\
394 	{ -1 },				\
395 	{ -1 },				\
396 	{ -1 },				\
397 	{ -1 },				\
398 	{ -1 },				\
399 	{ -1 },				\
400 	{ -1 },				\
401 	{ -1 },				\
402 	{ -1 },				\
403 	{ -1 },				\
404 	{ -1 },				\
405 	{ -1 },				\
406 	{ -1 },				\
407 	{ -1 }, { -1 },			\
408 	{ FR4, -1 }, { FR4, -1 },	\
409 	{ FR5, -1 }, { FR5, -1 },	\
410 	{ FR6, -1 }, { FR6, -1 },	\
411 	{ FR7, -1 }, { FR7, -1 },	\
412 	{ FR8, -1 }, { FR8, -1 },	\
413 	{ FR9, -1 }, { FR9, -1 },	\
414 	{ FR10, -1 }, { FR10, -1 },	\
415 	{ FR11, -1 }, { FR11, -1 },	\
416 	{ FR12, -1 }, { FR12, -1 },	\
417 	{ FR13, -1 }, { FR13, -1 },	\
418 	{ FR14, -1 }, { FR14, -1 },	\
419 	{ FR15, -1 }, { FR15, -1 },	\
420 	{ FR16, -1 }, { FR16, -1 },	\
421 	{ FR17, -1 }, { FR17, -1 },	\
422 	{ FR18, -1 }, { FR18, -1 },
423 #ifdef __hppa64__
424 	{ FR19, -1 }, { FR19, -1 },	\
425 	{ FR20, -1 }, { FR20, -1 },	\
426 	{ FR21, -1 }, { FR21, -1 },	\
427 	{ FR22, -1 }, { FR22, -1 },	\
428 	{ FR23, -1 }, { FR23, -1 },	\
429 	{ FR24, -1 }, { FR24, -1 },	\
430 	{ FR25, -1 }, { FR25, -1 },	\
431 	{ FR26, -1 }, { FR26, -1 },	\
432 	{ FR27, -1 }, { FR27, -1 },	\
433 	{ FR28, -1 }, { FR28, -1 },	\
434 	{ FR29, -1 }, { FR29, -1 },	\
435 	{ FR30, -1 }, { FR30, -1 },	\
436 	{ FR31, -1 }, { FR31, -1 },
437 #endif
438 
439 #define	PCLASS(p)	\
440 	(p->n_type == LONGLONG || p->n_type == ULONGLONG ? SBREG : \
441 	(p->n_type == FLOAT ? SCREG : \
442 	(p->n_type == DOUBLE || p->n_type == LDOUBLE ? SDREG : SAREG)))
443 
444 #define	NUMCLASS	4	/* highest number of reg classes used */
445 
446 int COLORMAP(int c, int *r);
447 #define	PERMTYPE(x) ((x) < 32? INT : ((x) < 64? LONGLONG : ((x) < 93? LDOUBLE : FLOAT)))
448 #define	GCLASS(x) ((x) < 32? CLASSA : ((x) < 64? CLASSB : ((x) < 93? CLASSD : CLASSC)))
449 #define	DECRA(x,y)	(((x) >> (y*8)) & 255)	/* decode encoded regs */
450 #define	ENCRD(x)	(x)			/* Encode dest reg in n_reg */
451 #define	ENCRA1(x)	((x) << 8)		/* A1 */
452 #define	ENCRA2(x)	((x) << 16)		/* A2 */
453 #define	ENCRA(x,y)	((x) << (8+y*8))	/* encode regs in int */
454 #define	RETREG(x)	(x == LONGLONG || x == ULONGLONG ? RETD0 : \
455 			 x == FLOAT? FR4L : \
456 			 x == DOUBLE || x == LDOUBLE ? FR4 : RET0)
457 
458 #define	FPREG	FP	/* frame pointer */
459 #define	STKREG	SP	/* stack pointer */
460 
461 #define	MYREADER(p)	myreader(p)
462 #define	MYCANON(p)	mycanon(p)
463 #define	MYOPTIM
464 
465 #define	SFUNCALL	(MAXSPECIAL+1)	/* struct assign after function call */
466 #define	SPCNHI		(MAXSPECIAL+2)	/* high 21bits constant */
467 #define	SPCON		(MAXSPECIAL+3)	/* smaller constant */
468 #define	SPICON		(MAXSPECIAL+4)	/* even smaller constant */
469 #define	SPCNHW		(MAXSPECIAL+5)	/* LL const w/ 0 in low word */
470 #define	SPCNLW		(MAXSPECIAL+6)	/* LL const w/ 0 in high word */
471 #define	SPIMM		(MAXSPECIAL+7)	/* immidiate const for depi/comib */
472 #define	SPNAME		(MAXSPECIAL+8)	/* ext symbol reference load/store */
473