1/* Id: macdefs.h,v 1.83 2011/06/23 13:41:25 ragge Exp */ 2/* $NetBSD$ */ 3/* 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 64 /* # 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 SZINT 32 48#define SZFLOAT 32 49#define SZDOUBLE 64 50#ifdef MACHOABI 51#define SZLDOUBLE 128 52#else 53#define SZLDOUBLE 96 54#endif 55#define SZLONG 32 56#define SZSHORT 16 57#define SZLONGLONG 64 58#define SZPOINT(t) 32 59 60/* 61 * Alignment constraints 62 */ 63#define ALCHAR 8 64#define ALBOOL 8 65#define ALINT 32 66#define ALFLOAT 32 67#define ALDOUBLE 32 68#ifdef MACHOABI 69#define ALLDOUBLE 128 70#else 71#define ALLDOUBLE 32 72#endif 73#define ALLONG 32 74#define ALLONGLONG 32 75#define ALSHORT 16 76#define ALPOINT 32 77#undef ALSTRUCT /* Not defined if ELF ABI */ 78#define ALSTACK 32 79#define ALMAX 128 /* not yet supported type */ 80 81/* 82 * Min/max values. 83 */ 84#define MIN_CHAR -128 85#define MAX_CHAR 127 86#define MAX_UCHAR 255 87#define MIN_SHORT -32768 88#define MAX_SHORT 32767 89#define MAX_USHORT 65535 90#define MIN_INT (-0x7fffffff-1) 91#define MAX_INT 0x7fffffff 92#define MAX_UNSIGNED 0xffffffff 93#define MIN_LONG MIN_INT 94#define MAX_LONG MAX_INT 95#define MAX_ULONG MAX_UNSIGNED 96#define MIN_LONGLONG 0x8000000000000000LL 97#define MAX_LONGLONG 0x7fffffffffffffffLL 98#define MAX_ULONGLONG 0xffffffffffffffffULL 99 100/* Default char is signed */ 101#undef CHAR_UNSIGNED 102#define BOOL_TYPE UCHAR /* what used to store _Bool */ 103 104/* 105 * Use large-enough types. 106 */ 107typedef long long CONSZ; 108typedef unsigned long long U_CONSZ; 109typedef long long OFFSZ; 110 111#define CONFMT "%lld" /* format for printing constants */ 112#if defined(ELFABI) 113#define LABFMT ".L%d" /* format for printing labels */ 114#define STABLBL ".LL%d" /* format for stab (debugging) labels */ 115#else 116#define LABFMT "L%d" /* format for printing labels */ 117#define STABLBL "LL%d" /* format for stab (debugging) labels */ 118#endif 119#ifdef LANG_F77 120#define BLANKCOMMON "_BLNK_" 121#define MSKIREG (M(TYSHORT)|M(TYLONG)) 122#define TYIREG TYLONG 123#define FSZLENG FSZLONG 124#define AUTOREG EBP 125#define ARGREG EBP 126#define ARGOFFSET 8 127#endif 128 129#ifdef MACHOABI 130#define STAB_LINE_ABSOLUTE /* S_LINE fields use absolute addresses */ 131#define MYALIGN /* user power-of-2 alignment */ 132#endif 133 134#define BACKAUTO /* stack grows negatively for automatics */ 135#define BACKTEMP /* stack grows negatively for temporaries */ 136 137#undef FIELDOPS /* no bit-field instructions */ 138#define TARGET_ENDIAN TARGET_LE 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 SSTDCALL SLOCAL2 323#define SDLLINDIRECT SLOCAL3 324 325/* 326 * i386-specific node flags. 327 */ 328#define FSTDCALL NLOCAL1 329#define FFPPOP NLOCAL2 330 331/* 332 * i386-specific interpass stuff. 333 */ 334 335#define TARGET_IPP_MEMBERS \ 336 int ipp_argstacksize; 337 338/* 339 * Extended assembler macros. 340 */ 341void targarg(char *w, void *arg); 342#define XASM_TARGARG(w, ary) \ 343 (w[1] == 'b' || w[1] == 'h' || w[1] == 'w' || w[1] == 'k' ? \ 344 w++, targarg(w, ary), 1 : 0) 345int numconv(void *ip, void *p, void *q); 346#define XASM_NUMCONV(ip, p, q) numconv(ip, p, q) 347int xasmconstregs(char *); 348#define XASMCONSTREGS(x) xasmconstregs(x) 349#define MYSETXARG if (XASMVAL(cw) == 'q') { \ 350 c = 'r'; addalledges(&ablock[ESI]); addalledges(&ablock[EDI]); } 351 352/* 353 * builtins. 354 */ 355#define TARGET_BUILTINS \ 356 { "__builtin_frame_address", i386_builtin_frame_address, -1 }, \ 357 { "__builtin_return_address", i386_builtin_return_address, -1 }, 358 359#define NODE struct node 360struct node; 361NODE *i386_builtin_frame_address(NODE *f, NODE *a, unsigned int); 362NODE *i386_builtin_return_address(NODE *f, NODE *a, unsigned int); 363#undef NODE 364 365#if defined(MACHOABI) 366struct stub { 367 struct { struct stub *q_forw, *q_back; } link; 368 char *name; 369}; 370extern struct stub stublist; 371extern struct stub nlplist; 372void addstub(struct stub *list, char *name); 373#endif 374