1 /*	$Id: macdefs.h,v 1.34 2014/06/01 11:35:03 ragge Exp $	*/
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 /*
28  * Machine-dependent defines for both passes.
29  */
30 
31 /*
32  * Convert (multi-)character constant to integer.
33  * Assume: If only one value; store at left side (char size), otherwise
34  * treat it as an integer.
35  */
36 #define makecc(val,i) {			\
37 	if (i == 0) { lastcon = val;	\
38 	} else if (i == 1) { lastcon = (lastcon << 9) | val; lastcon <<= 18; \
39 	} else { lastcon |= (val << (27 - (i * 9))); } }
40 
41 #define ARGINIT		36	/* # bits below fp where arguments start */
42 #define AUTOINIT	36	/* # bits above fp where automatics start */
43 
44 /*
45  * Storage space requirements
46  */
47 #define SZCHAR		9
48 #define SZBOOL		36
49 #define SZINT		36
50 #define SZFLOAT		36
51 #define SZDOUBLE	72
52 #define SZLDOUBLE	72
53 #define SZLONG		36
54 #define SZSHORT		18
55 #define SZPOINT(x)	36
56 #define SZLONGLONG	72
57 
58 /*
59  * Alignment constraints
60  */
61 #define ALCHAR		9
62 #define ALBOOL		36
63 #define ALINT		36
64 #define ALFLOAT		36
65 #define ALDOUBLE	36
66 #define ALLDOUBLE	36
67 #define ALLONG		36
68 #define ALLONGLONG	36
69 #define ALSHORT		18
70 #define ALPOINT		36
71 #define ALSTRUCT	36
72 #define ALSTACK		36
73 
74 /*
75  * Max values.
76  */
77 #define	MIN_CHAR	-256
78 #define	MAX_CHAR	255
79 #define	MAX_UCHAR	511
80 #define	MIN_SHORT	-131072
81 #define	MAX_SHORT	131071
82 #define	MAX_USHORT	262143
83 #define	MIN_INT		(-0377777777777LL-1)
84 #define	MAX_INT		0377777777777LL
85 #define	MAX_UNSIGNED	0777777777777ULL
86 #define	MIN_LONG	(-0377777777777LL-1)
87 #define	MAX_LONG	0377777777777LL
88 #define	MAX_ULONG	0777777777777ULL
89 #define	MIN_LONGLONG	(000777777777777777777777LL-1)	/* XXX cross */
90 #define	MAX_LONGLONG	000777777777777777777777LL	/* XXX cross */
91 #define	MAX_ULONGLONG	001777777777777777777777ULL	/* XXX cross */
92 
93 /* Default char is unsigned */
94 #define TARGET_STDARGS
95 #define	CHAR_UNSIGNED
96 #define	BOOL_TYPE	INT
97 #define	WORD_ADDRESSED
98 
99 /*
100  * Use large-enough types.
101  */
102 typedef	long long CONSZ;
103 typedef	unsigned long long U_CONSZ;
104 typedef long long OFFSZ;
105 
106 #define CONFMT	"0%llo"		/* format for printing constants */
107 #define LABFMT	".L%d"		/* format for printing labels */
108 #define STABLBL ".LL%d"		/* format for stab (debugging) labels */
109 
110 #undef BACKAUTO 		/* stack grows negatively for automatics */
111 #undef BACKTEMP 		/* stack grows negatively for temporaries */
112 
113 #undef	FIELDOPS		/* no bit-field instructions */
114 #define TARGET_ENDIAN TARGET_BE
115 
116 /* Definitions mostly used in pass2 */
117 
118 #define BYTEOFF(x)	((x)&03)
119 #define wdal(k)		(BYTEOFF(k)==0)
120 
121 #define STOARG(p)
122 #define STOFARG(p)
123 #define STOSTARG(p)
124 #define genfcall(a,b)	gencall(a,b)
125 
126 #define	szty(t)	(((t) == DOUBLE || (t) == FLOAT || \
127 	(t) == LONGLONG || (t) == ULONGLONG) ? 2 : 1)
128 
129 #define	shltype(o, p) \
130 	((o) == REG || (o) == NAME || (o) == ICON || \
131 	 (o) == OREG || ((o) == UMUL && shumul((p)->n_left, SOREG)))
132 
133 #undef	SPECIAL_INTEGERS
134 
135 /*
136  * Special shapes used in code generation.
137  */
138 #define	SUSHCON	(SPECIAL|6)	/* unsigned short constant */
139 #define	SNSHCON	(SPECIAL|7)	/* negative short constant */
140 #define	SILDB	(SPECIAL|8)	/* use ildb here */
141 
142 /*
143  * Register allocator definitions.
144  *
145  * The pdp10 has 16 general-purpose registers, but the two
146  * highest are used as sp and fp.  Register 0 has special
147  * constraints in its possible use as index register.
148  * All regs can be used as pairs, named by the lowest number.
149  * In here we call the registers Rn and the pairs XRn, in assembler
150  * just its number prefixed with %.
151  *
152  * R1/XR1 are return registers.
153  *
154  * R0 is currently not used.
155  */
156 
157 #define	MAXREGS		29 /* 16 + 13 regs */
158 #define	NUMCLASS	2
159 
160 #define R0	00
161 #define R1	01
162 #define R2	02
163 #define R3	03
164 #define R4	04
165 #define R5	05
166 #define R6	06
167 #define R7	07
168 #define R10	010
169 #define R11	011
170 #define R12	012
171 #define R13	013
172 #define R14	014
173 #define R15	015
174 #define R16	016
175 #define R17	017
176 #define FPREG	R16		/* frame pointer */
177 #define STKREG	R17		/* stack pointer */
178 
179 
180 #define XR0	020
181 #define XR1	021
182 #define XR2	022
183 #define XR3	023
184 #define XR4	024
185 #define XR5	025
186 #define XR6	026
187 #define XR7	027
188 #define XR10	030
189 #define XR11	031
190 #define XR12	032
191 #define XR13	033
192 #define XR14	034
193 
194 
195 #define RSTATUS \
196 	0, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,			\
197 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
198 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG,	\
199 	SAREG|PERMREG, SAREG|PERMREG, 0, 0,				\
200 	SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG,		\
201 	SBREG, SBREG, SBREG, SBREG, SBREG,
202 
203 #define ROVERLAP \
204         { XR0, -1 },			\
205         { XR0, XR1, -1 },		\
206         { XR1, XR2, -1 },		\
207         { XR2, XR3, -1 },		\
208         { XR3, XR4, -1 },		\
209         { XR4, XR5, -1 },		\
210         { XR5, XR6, -1 },		\
211         { XR6, XR7, -1 },		\
212         { XR7, XR10, -1 },		\
213         { XR10, XR11, -1 },		\
214         { XR11, XR12, -1 },		\
215         { XR12, XR13, -1 },		\
216         { XR13, XR14, -1 },		\
217         { XR14, -1 },			\
218         { -1 },				\
219         { -1 },				\
220         { R0, R1, XR1, -1 },		\
221         { R1, R2, XR0, XR2, -1 },	\
222         { R2, R3, XR1, XR3, -1 },	\
223         { R3, R4, XR2, XR4, -1 },	\
224         { R4, R5, XR3, XR5, -1 },	\
225         { R5, R6, XR4, XR6, -1 },	\
226         { R6, R7, XR5, XR7, -1 },	\
227         { R7, R10, XR6, XR10, -1 },	\
228         { R10, R11, XR7, XR11, -1 },	\
229         { R11, R12, XR10, XR12, -1 },	\
230         { R12, R13, XR11, XR13, -1 },	\
231         { R13, R14, XR12, XR14, -1 },	\
232         { R14, R15, XR13, -1 },
233 
234 /* Return a register class based on the type of the node */
235 #define PCLASS(p) (szty(p->n_type) == 2 ? SBREG : SAREG)
236 #define RETREG(x) (szty(x) == 2 ? XR1 : R1)
237 #define DECRA(x,y)      (((x) >> (y*6)) & 63)   /* decode encoded regs */
238 #define ENCRD(x)        (x)             /* Encode dest reg in n_reg */
239 #define ENCRA1(x)       ((x) << 6)      /* A1 */
240 #define ENCRA2(x)       ((x) << 12)     /* A2 */
241 #define ENCRA(x,y)      ((x) << (6+y*6))        /* encode regs in int */
242 #define GCLASS(x)	(x < 16 ? CLASSA : CLASSB)
243 int COLORMAP(int c, int *r);
244