source: mainline/uspace/app/pcc/arch/i386/macdefs.h@ 94f6df7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 94f6df7 was a7de7182, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

Added pcc source tree (contents of pcc-1.0.0.tgz)

  • Property mode set to 100644
File size: 11.6 KB
Line 
1/* $Id: macdefs.h,v 1.77 2011/02/04 15:08:58 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 * 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#define ARGINIT 64 /* # bits above fp where arguments start */
39#define AUTOINIT 0 /* # bits below fp where automatics start */
40
41/*
42 * Storage space requirements
43 */
44#define SZCHAR 8
45#define SZBOOL 8
46#define SZINT 32
47#define SZFLOAT 32
48#define SZDOUBLE 64
49#ifdef MACHOABI
50#define SZLDOUBLE 128
51#else
52#define SZLDOUBLE 96
53#endif
54#define SZLONG 32
55#define SZSHORT 16
56#define SZLONGLONG 64
57#define SZPOINT(t) 32
58
59/*
60 * Alignment constraints
61 */
62#define ALCHAR 8
63#define ALBOOL 8
64#define ALINT 32
65#define ALFLOAT 32
66#define ALDOUBLE 32
67#ifdef MACHOABI
68#define ALLDOUBLE 128
69#else
70#define ALLDOUBLE 32
71#endif
72#define ALLONG 32
73#define ALLONGLONG 32
74#define ALSHORT 16
75#define ALPOINT 32
76#undef ALSTRUCT /* Not defined if ELF ABI */
77#define ALSTACK 32
78#define ALMAX 128 /* not yet supported type */
79
80/*
81 * Min/max values.
82 */
83#define MIN_CHAR -128
84#define MAX_CHAR 127
85#define MAX_UCHAR 255
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
98
99/* Default char is signed */
100#undef CHAR_UNSIGNED
101#define BOOL_TYPE CHAR /* what used to store _Bool */
102
103/*
104 * Use large-enough types.
105 */
106typedef long long CONSZ;
107typedef unsigned long long U_CONSZ;
108typedef long long OFFSZ;
109
110#define CONFMT "%lld" /* format for printing constants */
111#if defined(ELFABI)
112#define LABFMT ".L%d" /* format for printing labels */
113#define STABLBL ".LL%d" /* format for stab (debugging) labels */
114#else
115#define LABFMT "L%d" /* format for printing labels */
116#define STABLBL "LL%d" /* format for stab (debugging) labels */
117#endif
118#ifdef LANG_F77
119#define BLANKCOMMON "_BLNK_"
120#define MSKIREG (M(TYSHORT)|M(TYLONG))
121#define TYIREG TYLONG
122#define FSZLENG FSZLONG
123#define AUTOREG EBP
124#define ARGREG EBP
125#define ARGOFFSET 8
126#endif
127
128#ifdef MACHOABI
129#define STAB_LINE_ABSOLUTE /* S_LINE fields use absolute addresses */
130#endif
131
132#define BACKAUTO /* stack grows negatively for automatics */
133#define BACKTEMP /* stack grows negatively for temporaries */
134
135#undef FIELDOPS /* no bit-field instructions */
136#define RTOLBYTES /* bytes are numbered right to left */
137
138#define ENUMSIZE(high,low) INT /* enums are always stored in full int */
139
140#define FINDMOPS /* i386 has instructions that modifies memory */
141#define CC_DIV_0 /* division by zero is safe in the compiler */
142
143/* Definitions mostly used in pass2 */
144
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! */
148
149#define STOARG(p)
150#define STOFARG(p)
151#define STOSTARG(p)
152#define genfcall(a,b) gencall(a,b)
153
154#define szty(t) (((t) == DOUBLE || (t) == FLOAT || \
155 (t) == LONGLONG || (t) == ULONGLONG) ? 2 : (t) == LDOUBLE ? 3 : 1)
156
157/*
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.
163 *
164 * The classes used on x86 are:
165 * A - short and int regs
166 * B - char regs
167 * C - long long regs
168 * D - floating point
169 */
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 */
178
179#define AL 010
180#define AH 011
181#define DL 012
182#define DH 013
183#define CL 014
184#define CH 015
185#define BL 016
186#define BH 017
187
188#define EAXEDX 020
189#define EAXECX 021
190#define EAXEBX 022
191#define EAXESI 023
192#define EAXEDI 024
193#define EDXECX 025
194#define EDXEBX 026
195#define EDXESI 027
196#define EDXEDI 030
197#define ECXEBX 031
198#define ECXESI 032
199#define ECXEDI 033
200#define EBXESI 034
201#define EBXEDI 035
202#define ESIEDI 036
203
204/* The 8 math registers in class D lacks names */
205
206#define MAXREGS 047 /* 39 registers */
207
208#define RSTATUS \
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,
215
216#define ROVERLAP \
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 },\
224 { -1 },\
225 { -1 },\
226\
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 },\
236\
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 },\
268\
269 /* The fp registers do not overlap with anything */\
270 { -1 },\
271 { -1 },\
272 { -1 },\
273 { -1 },\
274 { -1 },\
275 { -1 },\
276 { -1 },\
277 { -1 },
278
279
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)))
284
285#define NUMCLASS 4 /* highest number of reg classes used */
286
287int 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)
298
299#if 0
300#define R2REGS 1 /* permit double indexing */
301#endif
302
303/* XXX - to die */
304#define FPREG EBP /* frame pointer */
305#define STKREG ESP /* stack pointer */
306
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 */
310
311/*
312 * Specials that indicate the applicability of machine idioms.
313 */
314#define SMIXOR (MAXSPECIAL+4)
315#define SMILWXOR (MAXSPECIAL+5)
316#define SMIHWXOR (MAXSPECIAL+6)
317
318/*
319 * i386-specific symbol table flags.
320 */
321#define SSECTION SLOCAL1
322#define STLS SLOCAL2
323#define SSTDCALL SLOCAL2
324#define SDLLINDIRECT SLOCAL3
325
326/*
327 * i386-specific node flags.
328 */
329#define FSTDCALL NLOCAL1
330#define FFPPOP NLOCAL2
331
332/*
333 * i386-specific interpass stuff.
334 */
335
336#define TARGET_IPP_MEMBERS \
337 int ipp_argstacksize;
338
339/*
340 * Extended assembler macros.
341 */
342void 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)
346int numconv(void *ip, void *p, void *q);
347#define XASM_NUMCONV(ip, p, q) numconv(ip, p, q)
348int xasmconstregs(char *);
349#define XASMCONSTREGS(x) xasmconstregs(x)
350#define MYSETXARG if (XASMVAL(cw) == 'q') { \
351 c = 'r'; addalledges(&ablock[ESI]); addalledges(&ablock[EDI]); }
352
353/*
354 * builtins.
355 */
356#define TARGET_BUILTINS \
357 { "__builtin_frame_address", i386_builtin_frame_address, -1 }, \
358 { "__builtin_return_address", i386_builtin_return_address, -1 },
359
360#define NODE struct node
361struct node;
362NODE *i386_builtin_frame_address(NODE *f, NODE *a, unsigned int);
363NODE *i386_builtin_return_address(NODE *f, NODE *a, unsigned int);
364#undef NODE
365
366#if defined(MACHOABI)
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#endif
Note: See TracBrowser for help on using the repository browser.