1 /*	$Id: macdefs.h,v 1.31 2014/06/01 11:35:02 ragge Exp $	*/
2 /*
3  * Copyright (c) 2008 Michael Shalayeff
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  * Machine-dependent defines for both passes.
32  */
33 
34 /*
35  * Convert (multi-)character constant to integer.
36  */
37 #define makecc(val,i)	lastcon = (lastcon<<8)|((val<<24)>>24);
38 
39 #define ARGINIT		128	/* # bits above fp where arguments start */
40 #define AUTOINIT	0	/* # bits below fp where automatics start */
41 
42 /*
43  * Storage space requirements
44  */
45 #define SZCHAR		8
46 #define SZBOOL		8
47 #define SZSHORT		16
48 #define SZINT		32
49 #define SZLONG		64
50 #define SZPOINT(t)	64
51 #define SZLONGLONG	64
52 #define SZFLOAT		32
53 #define SZDOUBLE	64
54 #define SZLDOUBLE	128
55 
56 /*
57  * Alignment constraints
58  */
59 #define ALCHAR		8
60 #define ALBOOL		8
61 #define ALSHORT		16
62 #define ALINT		32
63 #define ALLONG		64
64 #define ALPOINT		64
65 #define ALLONGLONG	64
66 #define ALFLOAT		32
67 #define ALDOUBLE	64
68 #define ALLDOUBLE	128
69 /* #undef ALSTRUCT	amd64 struct alignment is member defined */
70 #define ALSTACK		64
71 #define ALMAX		128
72 
73 /*
74  * Min/max values.
75  */
76 #define	MIN_CHAR	-128
77 #define	MAX_CHAR	127
78 #define	MAX_UCHAR	255
79 #define	MIN_SHORT	-32768
80 #define	MAX_SHORT	32767
81 #define	MAX_USHORT	65535
82 #define	MIN_INT		(-0x7fffffff-1)
83 #define	MAX_INT		0x7fffffff
84 #define	MAX_UNSIGNED	0xffffffffU
85 #define	MIN_LONG	0x8000000000000000LL
86 #define	MAX_LONG	0x7fffffffffffffffLL
87 #define	MAX_ULONG	0xffffffffffffffffULL
88 #define	MIN_LONGLONG	0x8000000000000000LL
89 #define	MAX_LONGLONG	0x7fffffffffffffffLL
90 #define	MAX_ULONGLONG	0xffffffffffffffffULL
91 
92 /* Default char is signed */
93 #undef	CHAR_UNSIGNED
94 #define	BOOL_TYPE	UCHAR	/* what used to store _Bool */
95 
96 /*
97  * Use large-enough types.
98  */
99 typedef	long long CONSZ;
100 typedef	unsigned long long U_CONSZ;
101 typedef long long OFFSZ;
102 
103 #define CONFMT	"%lld"		/* format for printing constants */
104 #define LABFMT	".L%d"		/* format for printing labels */
105 #define	STABLBL	".LL%d"		/* format for stab (debugging) labels */
106 #ifdef LANG_F77
107 #define BLANKCOMMON "_BLNK_"
108 #define MSKIREG  (M(TYSHORT)|M(TYLONG))
109 #define TYIREG TYLONG
110 #define FSZLENG  FSZLONG
111 #define	AUTOREG	EBP
112 #define	ARGREG	EBP
113 #define ARGOFFSET 8
114 #endif
115 
116 #define BACKAUTO 		/* stack grows negatively for automatics */
117 #define BACKTEMP 		/* stack grows negatively for temporaries */
118 
119 #undef	FIELDOPS		/* no bit-field instructions */
120 #define	TARGET_ENDIAN TARGET_LE	/* little-endian only */
121 
122 #define FINDMOPS	/* i386 has instructions that modifies memory */
123 
124 #define	CC_DIV_0	/* division by zero is safe in the compiler */
125 
126 #ifdef MACHOABI
127 #define	HASP2ALIGN
128 #endif
129 
130 /* Definitions mostly used in pass2 */
131 
132 #define BYTEOFF(x)	((x)&07)
133 #define wdal(k)		(BYTEOFF(k)==0)
134 
135 #define STOARG(p)
136 #define STOFARG(p)
137 #define STOSTARG(p)
138 #define genfcall(a,b)	gencall(a,b)
139 
140 /* How many integer registers are needed? (used for stack allocation) */
141 #define	szty(t)	(t < LONG || t == FLOAT ? 1 : t == LDOUBLE ? 4 : 2)
142 
143 /*
144  * The amd64 architecture has a much cleaner interface to its registers
145  * than the x86, even though a part of the register block comes from
146  * the x86 architecture.  Therefore currently only two non-overlapping
147  * register classes are used; integer and xmm registers.
148  *
149  * All registers are given a sequential number to
150  * identify it which must match rnames[] in local2.c.
151  *
152  * The classes used on amd64 are:
153  *	A - integer registers
154  *	B - xmm registers
155  *	C - x87 registers
156  */
157 #define	RAX	000
158 #define	RDX	001
159 #define	RCX	002
160 #define	RBX	003
161 #define	RSI	004
162 #define	RDI	005
163 #define	RBP	006
164 #define	RSP	007
165 #define	R08	010
166 #define	R09	011
167 #define	R10	012
168 #define	R11	013
169 #define	R12	014
170 #define	R13	015
171 #define	R14	016
172 #define	R15	017
173 
174 #define	XMM0	020
175 #define	XMM1	021
176 #define	XMM2	022
177 #define	XMM3	023
178 #define	XMM4	024
179 #define	XMM5	025
180 #define	XMM6	026
181 #define	XMM7	027
182 #define	XMM8	030
183 #define	XMM9	031
184 #define	XMM10	032
185 #define	XMM11	033
186 #define	XMM12	034
187 #define	XMM13	035
188 #define	XMM14	036
189 #define	XMM15	037
190 
191 #define	MAXREGS	050	/* 40 registers */
192 
193 #define	RSTATUS	\
194 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|PERMREG,	\
195 	SAREG|TEMPREG, SAREG|TEMPREG, 0, 0,	 			\
196 	SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG,	\
197 	SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, 	\
198 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
199 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
200 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
201 	SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG, SBREG|TEMPREG,	\
202 	SCREG, SCREG, SCREG, SCREG,  SCREG, SCREG, SCREG, SCREG,
203 
204 
205 /* no overlapping registers at all */
206 #define	ROVERLAP \
207 	{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \
208 	{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \
209 	{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \
210 	{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, \
211 	{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 },
212 
213 
214 /* Return a register class based on the type of the node */
215 #define PCLASS(p) (p->n_type == FLOAT || p->n_type == DOUBLE ? SBREG : \
216 		   p->n_type == LDOUBLE ? SCREG : SAREG)
217 
218 #define	NUMCLASS 	3	/* highest number of reg classes used */
219 
220 int COLORMAP(int c, int *r);
221 #define	GCLASS(x) (x < 16 ? CLASSA : x < 32 ? CLASSB : CLASSC)
222 #define DECRA(x,y)	(((x) >> (y*8)) & 255)	/* decode encoded regs */
223 #define	ENCRD(x)	(x)		/* Encode dest reg in n_reg */
224 #define ENCRA1(x)	((x) << 8)	/* A1 */
225 #define ENCRA2(x)	((x) << 16)	/* A2 */
226 #define ENCRA(x,y)	((x) << (8+y*8))	/* encode regs in int */
227 
228 #define	RETREG(x)	(x == FLOAT || x == DOUBLE ? XMM0 : \
229 			 x == LDOUBLE ? 32 : RAX)
230 
231 /* XXX - to die */
232 #define FPREG	RBP	/* frame pointer */
233 #define STKREG	RSP	/* stack pointer */
234 
235 #define	SHSTR		(MAXSPECIAL+1)	/* short struct */
236 #define	SFUNCALL	(MAXSPECIAL+2)	/* struct assign after function call */
237 #define	SPCON		(MAXSPECIAL+3)	/* positive nonnamed constant */
238 
239 /*
240  * Specials that indicate the applicability of machine idioms.
241  */
242 #define SMIXOR		(MAXSPECIAL+4)
243 #define SMILWXOR	(MAXSPECIAL+5)
244 #define SMIHWXOR	(MAXSPECIAL+6)
245 #define SCON32		(MAXSPECIAL+7)	/* 32-bit constant */
246 
247 /*
248  * i386-specific symbol table flags.
249  */
250 #define SBEENHERE	SLOCAL1
251 
252 /*
253  * Extended assembler macros.
254  */
255 int xasmconstregs(char *);
256 void targarg(char *w, void *arg, int n);
257 #define	XASM_TARGARG(w, ary)	\
258 	(w[1] == 'b' || w[1] == 'h' || w[1] == 'w' || w[1] == 'k' || \
259 	 w[1] == 'q' ? w++, targarg(w, ary, n), 1 : 0)
260 int numconv(void *ip, void *p, void *q);
261 #define	XASM_NUMCONV(ip, p, q)	numconv(ip, p, q)
262 #define	XASMCONSTREGS(x)	xasmconstregs(x)
263 
264 #define	HAVE_WEAKREF
265 #define TARGET_FLT_EVAL_METHOD	0	/* all as their type */
266 /*
267  * builtins.
268  */
269 #define TARGET_VALIST
270 #define TARGET_STDARGS
271 #define TARGET_BUILTINS							\
272 	{ "__builtin_stdarg_start", amd64_builtin_stdarg_start, 	\
273 						0, 2, 0, VOID },	\
274 	{ "__builtin_va_start", amd64_builtin_stdarg_start,		\
275 						0, 2, 0, VOID },	\
276 	{ "__builtin_va_arg", amd64_builtin_va_arg, BTNORVAL|BTNOPROTO,	\
277 							2, 0, 0 },	\
278 	{ "__builtin_va_end", amd64_builtin_va_end, 0, 1, 0, VOID },	\
279 	{ "__builtin_va_copy", amd64_builtin_va_copy, 0, 2, 0, VOID },
280 
281 #define NODE struct node
282 struct node;
283 struct bitable;
284 NODE *amd64_builtin_stdarg_start(const struct bitable *, NODE *a);
285 NODE *amd64_builtin_va_arg(const struct bitable *, NODE *a);
286 NODE *amd64_builtin_va_end(const struct bitable *, NODE *a);
287 NODE *amd64_builtin_va_copy(const struct bitable *, NODE *a);
288 #undef NODE
289