macdefs.h revision 1.1.1.1
1/*	$Id: macdefs.h,v 1.1.1.1 2008/08/24 05:32:59 gmcgarry 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 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * Machine-dependent defines for both passes.
31 */
32
33/*
34 * Convert (multi-)character constant to integer.
35 */
36#define makecc(val,i)	lastcon = (lastcon<<8)|((val<<24)>>24);
37
38/*
39 * Storage space requirements
40 */
41#define SZCHAR		8
42#define SZBOOL		32
43#define SZINT		32
44#define SZFLOAT		32
45#define SZDOUBLE	64
46#define SZLDOUBLE	96
47#define SZLONG		32
48#define SZSHORT		16
49#define SZLONGLONG	64
50#define SZPOINT(t)	32
51
52/*
53 * Alignment constraints
54 */
55#define ALCHAR		8
56#define ALBOOL		32
57#define ALINT		32
58#define ALFLOAT		32
59#define ALDOUBLE	32
60#define ALLDOUBLE	32
61#define ALLONG		32
62#ifdef ELFABI
63#define ALLONGLONG	64
64#else
65#define ALLONGLONG	32
66#endif
67#define ALSHORT		16
68#define ALPOINT		32
69#define ALSTRUCT	32
70#define ALSTACK		(16*SZCHAR)
71
72/*
73 * Min/max values.
74 */
75#define	MIN_CHAR	-128
76#define	MAX_CHAR	127
77#define	MAX_UCHAR	255
78#define	MIN_SHORT	-32768
79#define	MAX_SHORT	32767
80#define	MAX_USHORT	65535
81#define	MIN_INT		-1
82#define	MAX_INT		0x7fffffff
83#define	MAX_UNSIGNED	0xffffffff
84#define	MIN_LONG	MIN_INT
85#define	MAX_LONG	MAX_INT
86#define	MAX_ULONG	MAX_UNSIGNED
87#define	MIN_LONGLONG	0x8000000000000000LL
88#define	MAX_LONGLONG	0x7fffffffffffffffLL
89#define	MAX_ULONGLONG	0xffffffffffffffffULL
90
91#define CHAR_UNSIGNED
92#define	BOOL_TYPE	INT	/* what used to store _Bool */
93#define	WCHAR_TYPE	INT	/* what used to store wchar_t */
94
95/*
96 * Use large-enough types.
97 */
98typedef	long long CONSZ;
99typedef	unsigned long long U_CONSZ;
100typedef long long OFFSZ;
101
102#define CONFMT	"%lld"		/* format for printing constants */
103#if defined(ELFABI)
104#define LABFMT	".L%d"		/* format for printing labels */
105#define REGPREFIX	"%"	/* format for printing registers */
106#elif defined(MACHOABI)
107#define LABFMT	"L%d"		/* format for printing labels */
108#define REGPREFIX
109#else
110#error undefined ABI
111#endif
112#define	STABLBL	"LL%d"		/* format for stab (debugging) labels */
113
114#ifdef MACHOABI
115#define STAB_LINE_ABSOLUTE	/* S_LINE fields use absolute addresses */
116#endif
117
118#undef	FIELDOPS		/* no bit-field instructions */
119
120#define ENUMSIZE(high,low) INT	/* enums are always stored in full int */
121
122/* Definitions mostly used in pass2 */
123
124#define BYTEOFF(x)	((x)&03)
125#define BITOOR(x)	(x)	/* bit offset to oreg offset XXX die! */
126
127#define	szty(t)	(((t) == DOUBLE || (t) == LDOUBLE || \
128	DEUNSIGN(t) == LONGLONG) ? 2 : 1)
129
130/*
131 * The PPC register definition are taken from apple docs.
132 *
133 * The classes used are:
134 *	A - general registers
135 *	B - 64-bit register pairs
136 *	C - floating-point registers
137 */
138
139#define R0	0	// scratch register
140#define R1	1	// stack base pointer
141#define R2	2
142#define R3	3	// return register / argument 0
143#define R4	4	// return register (for longlong) / argument 1
144#define R5	5	// scratch register / argument 2
145#define R6	6	// scratch register / argument 3
146#define R7	7	// scratch register / argument 4
147#define R8	8	// scratch register / argument 5
148#define R9	9	// scratch register / argument 6
149#define R10	10	// scratch register / argument 7
150#define R11	11	// scratch register
151#define R12	12	// scratch register
152#define R13	13
153#define R14	14
154#define R15	15
155#define R16	16
156#define R17	17
157#define R18	18
158#define R19	19
159#define R20	20
160#define R21	21
161#define R22	22
162#define R23	23
163#define R24	24
164#define R25	25
165#define R26	26
166#define R27	27
167#define R28	28
168#define R29	29
169#define R30	30
170#define R31	31
171
172#define R3R4	32
173#define R4R5	33
174#define R5R6	34
175#define R6R7	35
176#define R7R8	36
177#define R8R9	37
178#define R9R10	38
179#define R14R15	39
180#define R16R17	40
181#define R18R19	41
182#define R20R21	42
183#define R22R23	43
184#define R24R25	44
185#define R26R27	45
186#define R28R29	46
187#define R30R31	47
188
189#define F0	48	// scratch register
190#define F1	49	// return value 0 / argument 0
191#define F2	50	// return value 1 / argument 1
192#define F3	51	// return value 2 / argument 2
193#define F4	52	// return value 3 / argument 3
194#define F5	53	// argument 4
195#define F6	54	// argument 5
196#define F7	55	// argument 6
197#define F8	56	// argument 7
198#define F9	57	// argument 8
199#define F10	58	// argument 9
200#define F11	59	// argument 10
201#define F12	60	// argument 11
202#define F13	61	// argument 12
203#define F14	62
204#define F15	63
205#define F16	64
206#define F17	65
207#define F18	66
208#define F19	67
209#define F20	68
210#define F21	69
211#define F22	70
212#define F23	71
213#define F24	72
214#define F25	73
215#define F26	74
216#define F27	75
217#define F28	76
218#define F29	77
219#define F30	78
220#define F31	79
221
222#define NUMCLASS 3
223#define	MAXREGS	64		// XXX cannot have more than 64
224
225#define RSTATUS 				\
226	0,			/* R0 */	\
227	0,			/* R1 */	\
228	SAREG|TEMPREG,		/* R2 */	\
229	SAREG|TEMPREG,		/* R3 */	\
230	SAREG|TEMPREG,		/* R4 */	\
231	SAREG|TEMPREG,		/* R5 */	\
232	SAREG|TEMPREG,		/* R6 */	\
233	SAREG|TEMPREG,		/* R7 */	\
234	SAREG|TEMPREG,		/* R8 */	\
235	SAREG|TEMPREG,		/* R9 */	\
236	SAREG|TEMPREG,		/* R10 */	\
237	SAREG|TEMPREG,		/* R11 */	\
238	SAREG|TEMPREG,		/* R12 */	\
239	SAREG,			/* R13 */	\
240	SAREG,			/* R14 */	\
241	SAREG,			/* R15 */	\
242	SAREG,			/* R16 */	\
243	SAREG,			/* R17 */	\
244	SAREG,			/* R18 */	\
245	SAREG,			/* R19 */	\
246	SAREG,			/* R20 */	\
247	SAREG,			/* R21 */	\
248	SAREG,			/* R22 */	\
249	SAREG,			/* R23 */	\
250	SAREG,			/* R24 */	\
251	SAREG,			/* R25 */	\
252	SAREG,			/* R26 */	\
253	SAREG,			/* R27 */	\
254	SAREG,			/* R28 */	\
255	SAREG,			/* R29 */	\
256	SAREG,			/* R30 */	\
257	SAREG,			/* R31 */	\
258	\
259        SBREG|TEMPREG,		/* R3R4 */	\
260	SBREG|TEMPREG,		/* R4R5 */	\
261	SBREG|TEMPREG,		/* R5R6 */	\
262	SBREG|TEMPREG,		/* R6R7 */	\
263        SBREG|TEMPREG,		/* R7R8 */	\
264	SBREG|TEMPREG,		/* R8R9 */	\
265	SBREG|TEMPREG,		/* R9R10 */	\
266	\
267	SBREG,			/* R14R15 */	\
268	SBREG,			/* R16R17 */	\
269	SBREG,			/* R18R19 */	\
270	SBREG,			/* R20R21 */	\
271	SBREG,			/* R22R23 */	\
272	SBREG,			/* R24R25 */	\
273	SBREG,			/* R26R2k */	\
274	SBREG,			/* R28R29 */	\
275	SBREG, 			/* R30R31 */	\
276	\
277	SCREG|TEMPREG,		/* F0 */	\
278	SCREG|TEMPREG,		/* F1 */	\
279	SCREG|TEMPREG,		/* F2 */	\
280	SCREG|TEMPREG,		/* F3 */	\
281	SCREG|TEMPREG,		/* F4 */	\
282	SCREG|TEMPREG,		/* F5 */	\
283	SCREG|TEMPREG,		/* F6 */	\
284	SCREG|TEMPREG,		/* F7 */	\
285	SCREG|TEMPREG,		/* F8 */	\
286	SCREG|TEMPREG,		/* F9 */	\
287	SCREG|TEMPREG,		/* F10 */	\
288	SCREG|TEMPREG,		/* F11 */	\
289	SCREG|TEMPREG,		/* F12 */	\
290	SCREG|TEMPREG,		/* F13 */	\
291	SCREG,			/* F14 */	\
292	SCREG,			/* F15 */	\
293
294#define ROVERLAP \
295	{ -1 }, { -1 }, { -1 },			\
296	{ R3R4,       -1 }, { R3R4, R4R5, -1 },	\
297	{ R4R5, R5R6, -1 }, { R5R6, R6R7, -1 },	\
298	{ R6R7, R7R8, -1 }, { R7R8, R8R9, -1 },	\
299	{ R8R9, R9R10, -1 }, { R9R10, -1 },	\
300	{ -1 }, { -1 }, { -1 },			\
301	{ R14R15, -1 }, { R14R15, -1 }, 	\
302	{ R16R17, -1 }, { R16R17, -1 },		\
303	{ R18R19, -1 }, { R18R19, -1 }, 	\
304	{ R20R21, -1 }, { R20R21, -1 },		\
305	{ R22R23, -1 }, { R22R23, -1 }, 	\
306	{ R24R25, -1 }, { R24R25, -1 },		\
307	{ R26R27, -1 }, { R26R27, -1 }, 	\
308	{ R28R29, -1 }, { R28R29, -1 },		\
309	{ R30R31, -1 }, { R30R31, -1 }, 	\
310	\
311	{ R3, R4,       R4R5, -1 }, { R4, R5, R3R4, R5R6, -1 },	\
312	{ R5, R6, R4R5, R6R7, -1 }, { R6, R7, R5R6, R7R8, -1 },	\
313	{ R7, R8, R6R7, R8R9, -1 }, { R8, R9, R7R8, R8R9, -1 }, \
314	{ R9, R10, R8R9,      -1 }, 	\
315	{ R14, R15, -1 }, { R16, R17, -1 },	\
316	{ R18, R19, -1 }, { R20, R21, -1 }, 	\
317	{ R22, R23, -1 }, { R24, R25, -1 },	\
318	{ R26, R27, -1 }, { R28, R29, -1 }, 	\
319	{ R30, R31, -1 },		\
320	\
321	{ -1 }, { -1 }, { -1 }, { -1 },		\
322	{ -1 }, { -1 }, { -1 }, { -1 },		\
323	{ -1 }, { -1 }, { -1 }, { -1 },		\
324	{ -1 }, { -1 }, { -1 }, { -1 },		\
325
326/*
327 * According to the ABI documents, there isn't really a frame pointer;
328 * all references to data on the stack (autos and parameters) are
329 * indexed relative to the stack pointer.  However, pcc isn't really
330 * capable of running in this manner, and expects a frame pointer.
331 */
332#define SPREG   R1	/* stack pointer */
333#define FPREG   R30	/* frame pointer */
334#define GOTREG	R31	/* global offset table (PIC) */
335
336#ifdef FPREG
337#define ARGINIT		(24*8)	/* # bits above fp where arguments start */
338#define AUTOINIT	(8*8)	/* # bits above fp where automatics start */
339#define BACKAUTO 		/* stack grows negatively for automatics */
340#define BACKTEMP 		/* stack grows negatively for temporaries */
341#else
342#define ARGINIT		(24*8)	/* # bits above fp where arguments start */
343#define AUTOINIT	(56*8)	/* # bits above fp where automatics start */
344#endif
345
346/* Return a register class based on the type of the node */
347#define PCLASS(p)	(1 << gclass((p)->n_type))
348
349#define GCLASS(x)	((x) < 32 ? CLASSA : ((x) < 48 ? CLASSB : CLASSC))
350#define DECRA(x,y)	(((x) >> (y*6)) & 63)   /* decode encoded regs */
351#define ENCRA(x,y)	((x) << (6+y*6))        /* encode regs in int */
352#define ENCRD(x)	(x)		/* Encode dest reg in n_reg */
353#define RETREG(x)	retreg(x)
354
355int COLORMAP(int c, int *r);
356int retreg(int ty);
357
358#define	SHSTR		(MAXSPECIAL+1)	/* short struct */
359#define	SFUNCALL	(MAXSPECIAL+2)	/* struct assign after function call */
360#define SPCON		(MAXSPECIAL+3)  /* positive constant */
361
362int features(int f);
363#define FEATURE_BIGENDIAN	0x00010000
364#define FEATURE_PIC		0x00020000
365#define FEATURE_HARDFLOAT	0x00040000
366
367struct stub {
368	struct { struct stub *q_forw, *q_back; } link;
369	char *name;
370};
371extern struct stub stublist;
372extern struct stub nlplist;
373void addstub(struct stub *list, char *name);
374
375#define TARGET_STDARGS
376#define TARGET_BUILTINS							\
377	{ "__builtin_stdarg_start", powerpc_builtin_stdarg_start },	\
378	{ "__builtin_va_arg", powerpc_builtin_va_arg },			\
379	{ "__builtin_va_end", powerpc_builtin_va_end },			\
380	{ "__builtin_va_copy", powerpc_builtin_va_copy },		\
381	{ "__builtin_frame_address", powerpc_builtin_frame_address },	\
382	{ "__builtin_return_address", powerpc_builtin_return_address },
383
384#define NODE struct node
385struct node;
386NODE *powerpc_builtin_stdarg_start(NODE *f, NODE *a);
387NODE *powerpc_builtin_va_arg(NODE *f, NODE *a);
388NODE *powerpc_builtin_va_end(NODE *f, NODE *a);
389NODE *powerpc_builtin_va_copy(NODE *f, NODE *a);
390NODE *powerpc_builtin_frame_address(NODE *f, NODE *a);
391NODE *powerpc_builtin_return_address(NODE *f, NODE *a);
392#undef NODE
393
394#define NARGREGS	8
395
396#ifdef ELFABI
397#define COM     "       # "
398#else
399#define COM     "       ; "
400#endif
401