1 /* $Id: macdefs.h,v 1.77 2011/02/04 15:08:58 ragge Exp $ */
3 * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
30 * Machine-dependent defines for both passes.
34 * Convert (multi-)character constant to integer.
36 #define makecc(val,i) lastcon = (lastcon<<8)|((val<<24)>>24);
38 #define ARGINIT 64 /* # bits above fp where arguments start */
39 #define AUTOINIT 0 /* # bits below fp where automatics start */
42 * Storage space requirements
60 * Alignment constraints
76 #undef ALSTRUCT /* Not defined if ELF ABI */
78 #define ALMAX 128 /* not yet supported type */
86 #define MIN_SHORT -32768
87 #define MAX_SHORT 32767
88 #define MAX_USHORT 65535
89 #define MIN_INT (-0x7fffffff-1)
90 #define MAX_INT 0x7fffffff
91 #define MAX_UNSIGNED 0xffffffff
92 #define MIN_LONG MIN_INT
93 #define MAX_LONG MAX_INT
94 #define MAX_ULONG MAX_UNSIGNED
95 #define MIN_LONGLONG 0x8000000000000000LL
96 #define MAX_LONGLONG 0x7fffffffffffffffLL
97 #define MAX_ULONGLONG 0xffffffffffffffffULL
99 /* Default char is signed */
101 #define BOOL_TYPE CHAR /* what used to store _Bool */
104 * Use large-enough types.
106 typedef long long CONSZ
;
107 typedef unsigned long long U_CONSZ
;
108 typedef long long OFFSZ
;
110 #define CONFMT "%lld" /* format for printing constants */
112 #define LABFMT ".L%d" /* format for printing labels */
113 #define STABLBL ".LL%d" /* format for stab (debugging) labels */
115 #define LABFMT "L%d" /* format for printing labels */
116 #define STABLBL "LL%d" /* format for stab (debugging) labels */
119 #define BLANKCOMMON "_BLNK_"
120 #define MSKIREG (M(TYSHORT)|M(TYLONG))
121 #define TYIREG TYLONG
122 #define FSZLENG FSZLONG
129 #define STAB_LINE_ABSOLUTE /* S_LINE fields use absolute addresses */
132 #define BACKAUTO /* stack grows negatively for automatics */
133 #define BACKTEMP /* stack grows negatively for temporaries */
135 #undef FIELDOPS /* no bit-field instructions */
136 #define RTOLBYTES /* bytes are numbered right to left */
138 #define ENUMSIZE(high,low) INT /* enums are always stored in full int */
140 #define FINDMOPS /* i386 has instructions that modifies memory */
141 #define CC_DIV_0 /* division by zero is safe in the compiler */
143 /* Definitions mostly used in pass2 */
145 #define BYTEOFF(x) ((x)&03)
146 #define wdal(k) (BYTEOFF(k)==0)
147 #define BITOOR(x) (x) /* bit offset to oreg offset XXX die! */
152 #define genfcall(a,b) gencall(a,b)
154 #define szty(t) (((t) == DOUBLE || (t) == FLOAT || \
155 (t) == LONGLONG || (t) == ULONGLONG) ? 2 : (t) == LDOUBLE ? 3 : 1)
158 * The x86 has a bunch of register classes, most of them interfering
159 * with each other. All registers are given a sequential number to
160 * identify it which must match rnames[] in local2.c.
161 * Class membership and overlaps are defined in the macros RSTATUS
162 * and ROVERLAP below.
164 * The classes used on x86 are:
165 * A - short and int regs
170 #define EAX 000 /* Scratch and return register */
171 #define EDX 001 /* Scratch and secondary return register */
172 #define ECX 002 /* Scratch (and shift count) register */
173 #define EBX 003 /* GDT pointer or callee-saved temporary register */
174 #define ESI 004 /* Callee-saved temporary register */
175 #define EDI 005 /* Callee-saved temporary register */
176 #define EBP 006 /* Frame pointer */
177 #define ESP 007 /* Stack pointer */
204 /* The 8 math registers in class D lacks names */
206 #define MAXREGS 047 /* 39 registers */
209 SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|PERMREG, \
210 SAREG|PERMREG, SAREG|PERMREG, 0, 0, \
211 SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, \
212 SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, \
213 SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, SCREG, \
214 SDREG, SDREG, SDREG, SDREG, SDREG, SDREG, SDREG, SDREG,
217 /* 8 basic registers */\
218 { AL, AH, EAXEDX, EAXECX, EAXEBX, EAXESI, EAXEDI, -1 },\
219 { DL, DH, EAXEDX, EDXECX, EDXEBX, EDXESI, EDXEDI, -1 },\
220 { CL, CH, EAXECX, EDXECX, ECXEBX, ECXESI, ECXEDI, -1 },\
221 { BL, BH, EAXEBX, EDXEBX, ECXEBX, EBXESI, EBXEDI, -1 },\
222 { EAXESI, EDXESI, ECXESI, EBXESI, ESIEDI, -1 },\
223 { EAXEDI, EDXEDI, ECXEDI, EBXEDI, ESIEDI, -1 },\
227 /* 8 char registers */\
228 { EAX, EAXEDX, EAXECX, EAXEBX, EAXESI, EAXEDI, -1 },\
229 { EAX, EAXEDX, EAXECX, EAXEBX, EAXESI, EAXEDI, -1 },\
230 { EDX, EAXEDX, EDXECX, EDXEBX, EDXESI, EDXEDI, -1 },\
231 { EDX, EAXEDX, EDXECX, EDXEBX, EDXESI, EDXEDI, -1 },\
232 { ECX, EAXECX, EDXECX, ECXEBX, ECXESI, ECXEDI, -1 },\
233 { ECX, EAXECX, EDXECX, ECXEBX, ECXESI, ECXEDI, -1 },\
234 { EBX, EAXEBX, EDXEBX, ECXEBX, EBXESI, EBXEDI, -1 },\
235 { EBX, EAXEBX, EDXEBX, ECXEBX, EBXESI, EBXEDI, -1 },\
237 /* 15 long-long-emulating registers */\
238 { EAX, AL, AH, EDX, DL, DH, EAXECX, EAXEBX, EAXESI, /* eaxedx */\
239 EAXEDI, EDXECX, EDXEBX, EDXESI, EDXEDI, -1, },\
240 { EAX, AL, AH, ECX, CL, CH, EAXEDX, EAXEBX, EAXESI, /* eaxecx */\
241 EAXEDI, EDXECX, ECXEBX, ECXESI, ECXEDI, -1 },\
242 { EAX, AL, AH, EBX, BL, BH, EAXEDX, EAXECX, EAXESI, /* eaxebx */\
243 EAXEDI, EDXEBX, ECXEBX, EBXESI, EBXEDI, -1 },\
244 { EAX, AL, AH, ESI, EAXEDX, EAXECX, EAXEBX, EAXEDI, /* eaxesi */\
245 EDXESI, ECXESI, EBXESI, ESIEDI, -1 },\
246 { EAX, AL, AH, EDI, EAXEDX, EAXECX, EAXEBX, EAXESI, /* eaxedi */\
247 EDXEDI, ECXEDI, EBXEDI, ESIEDI, -1 },\
248 { EDX, DL, DH, ECX, CL, CH, EAXEDX, EAXECX, EDXEBX, /* edxecx */\
249 EDXESI, EDXEDI, ECXEBX, ECXESI, ECXEDI, -1 },\
250 { EDX, DL, DH, EBX, BL, BH, EAXEDX, EDXECX, EDXESI, /* edxebx */\
251 EDXEDI, EAXEBX, ECXEBX, EBXESI, EBXEDI, -1 },\
252 { EDX, DL, DH, ESI, EAXEDX, EDXECX, EDXEBX, EDXEDI, /* edxesi */\
253 EAXESI, ECXESI, EBXESI, ESIEDI, -1 },\
254 { EDX, DL, DH, EDI, EAXEDX, EDXECX, EDXEBX, EDXESI, /* edxedi */\
255 EAXEDI, ECXEDI, EBXEDI, ESIEDI, -1 },\
256 { ECX, CL, CH, EBX, BL, BH, EAXECX, EDXECX, ECXESI, /* ecxebx */\
257 ECXEDI, EAXEBX, EDXEBX, EBXESI, EBXEDI, -1 },\
258 { ECX, CL, CH, ESI, EAXECX, EDXECX, ECXEBX, ECXEDI, /* ecxesi */\
259 EAXESI, EDXESI, EBXESI, ESIEDI, -1 },\
260 { ECX, CL, CH, EDI, EAXECX, EDXECX, ECXEBX, ECXESI, /* ecxedi */\
261 EAXEDI, EDXEDI, EBXEDI, ESIEDI, -1 },\
262 { EBX, BL, BH, ESI, EAXEBX, EDXEBX, ECXEBX, EBXEDI, /* ebxesi */\
263 EAXESI, EDXESI, ECXESI, ESIEDI, -1 },\
264 { EBX, BL, BH, EDI, EAXEBX, EDXEBX, ECXEBX, EBXESI, /* ebxedi */\
265 EAXEDI, EDXEDI, ECXEDI, ESIEDI, -1 },\
266 { ESI, EDI, EAXESI, EDXESI, ECXESI, EBXESI, /* esiedi */\
267 EAXEDI, EDXEDI, ECXEDI, EBXEDI, -1 },\
269 /* The fp registers do not overlap with anything */\
280 /* Return a register class based on the type of the node */
281 #define PCLASS(p) (p->n_type <= UCHAR ? SBREG : \
282 (p->n_type == LONGLONG || p->n_type == ULONGLONG ? SCREG : \
283 (p->n_type >= FLOAT && p->n_type <= LDOUBLE ? SDREG : SAREG)))
285 #define NUMCLASS 4 /* highest number of reg classes used */
287 int COLORMAP(int c
, int *r
);
288 #define GCLASS(x) (x < 8 ? CLASSA : x < 16 ? CLASSB : x < 31 ? CLASSC : CLASSD)
289 #define DECRA(x,y) (((x) >> (y*6)) & 63) /* decode encoded regs */
290 #define ENCRD(x) (x) /* Encode dest reg in n_reg */
291 #define ENCRA1(x) ((x) << 6) /* A1 */
292 #define ENCRA2(x) ((x) << 12) /* A2 */
293 #define ENCRA(x,y) ((x) << (6+y*6)) /* encode regs in int */
294 /* XXX - return char in al? */
295 #define RETREG(x) (x == CHAR || x == UCHAR ? AL : \
296 x == LONGLONG || x == ULONGLONG ? EAXEDX : \
297 x == FLOAT || x == DOUBLE || x == LDOUBLE ? 31 : EAX)
300 #define R2REGS 1 /* permit double indexing */
304 #define FPREG EBP /* frame pointer */
305 #define STKREG ESP /* stack pointer */
307 #define SHSTR (MAXSPECIAL+1) /* short struct */
308 #define SFUNCALL (MAXSPECIAL+2) /* struct assign after function call */
309 #define SPCON (MAXSPECIAL+3) /* positive nonnamed constant */
312 * Specials that indicate the applicability of machine idioms.
314 #define SMIXOR (MAXSPECIAL+4)
315 #define SMILWXOR (MAXSPECIAL+5)
316 #define SMIHWXOR (MAXSPECIAL+6)
319 * i386-specific symbol table flags.
321 #define SSECTION SLOCAL1
323 #define SSTDCALL SLOCAL2
324 #define SDLLINDIRECT SLOCAL3
327 * i386-specific node flags.
329 #define FSTDCALL NLOCAL1
330 #define FFPPOP NLOCAL2
333 * i386-specific interpass stuff.
336 #define TARGET_IPP_MEMBERS \
337 int ipp_argstacksize;
340 * Extended assembler macros.
342 void targarg(char *w
, void *arg
);
343 #define XASM_TARGARG(w, ary) \
344 (w[1] == 'b' || w[1] == 'h' || w[1] == 'w' || w[1] == 'k' ? \
345 w++, targarg(w, ary), 1 : 0)
346 int numconv(void *ip
, void *p
, void *q
);
347 #define XASM_NUMCONV(ip, p, q) numconv(ip, p, q)
348 int xasmconstregs(char *);
349 #define XASMCONSTREGS(x) xasmconstregs(x)
350 #define MYSETXARG if (XASMVAL(cw) == 'q') { \
351 c = 'r'; addalledges(&ablock[ESI]); addalledges(&ablock[EDI]); }
356 #define TARGET_BUILTINS \
357 { "__builtin_frame_address", i386_builtin_frame_address, -1 }, \
358 { "__builtin_return_address", i386_builtin_return_address, -1 },
360 #define NODE struct node
362 NODE
*i386_builtin_frame_address(NODE
*f
, NODE
*a
, unsigned int);
363 NODE
*i386_builtin_return_address(NODE
*f
, NODE
*a
, unsigned int);
366 #if defined(MACHOABI)
368 struct { struct stub
*q_forw
, *q_back
; } link
;
371 extern struct stub stublist
;
372 extern struct stub nlplist
;
373 void addstub(struct stub
*list
, char *name
);