1 /* Id: macdefs.h,v 1.15 2011/07/28 14:21:49 ragge Exp */ 2 /* $NetBSD: macdefs.h,v 1.1.1.4 2011/09/01 12:46:48 plunky Exp $ */ 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 /* 40 * Storage space requirements 41 */ 42 #define SZCHAR 8 43 #define SZBOOL 32 44 #define SZINT 32 45 #define SZFLOAT 32 46 #define SZDOUBLE 64 47 #ifdef ELFABI 48 #define SZLDOUBLE 96 49 #else 50 #define SZLDOUBLE 128 51 #endif 52 #define SZLONG 32 53 #define SZSHORT 16 54 #define SZLONGLONG 64 55 #define SZPOINT(t) 32 56 57 /* 58 * Alignment constraints 59 */ 60 #define ALCHAR 8 61 #define ALBOOL 32 62 #define ALINT 32 63 #define ALFLOAT 32 64 #define ALDOUBLE 32 65 #ifdef ELFABI 66 #define ALLDOUBLE 32 67 #else 68 #define ALLDOUBLE 128 69 #endif 70 #define ALLONG 32 71 #ifdef ELFABI 72 #define ALLONGLONG 64 73 #else 74 #define ALLONGLONG 32 75 #endif 76 #define ALSHORT 16 77 #define ALPOINT 32 78 #define ALSTRUCT 32 79 #define ALSTACK (16*SZCHAR) 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 -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 #define CHAR_UNSIGNED 101 #define BOOL_TYPE INT /* what used to store _Bool */ 102 103 /* 104 * Use large-enough types. 105 */ 106 typedef long long CONSZ; 107 typedef unsigned long long U_CONSZ; 108 typedef 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 REGPREFIX "%" /* format for printing registers */ 114 #elif defined(MACHOABI) 115 #define LABFMT "L%d" /* format for printing labels */ 116 #define REGPREFIX 117 #else 118 #error undefined ABI 119 #endif 120 #define STABLBL "LL%d" /* format for stab (debugging) labels */ 121 122 #ifdef MACHOABI 123 #define STAB_LINE_ABSOLUTE /* S_LINE fields use absolute addresses */ 124 #endif 125 126 #undef FIELDOPS /* no bit-field instructions */ 127 #define TARGET_ENDIAN TARGET_BE 128 #define MYINSTRING 129 #define MYALIGN 130 131 /* Definitions mostly used in pass2 */ 132 133 #define BYTEOFF(x) ((x)&03) 134 #define BITOOR(x) (x) /* bit offset to oreg offset XXX die! */ 135 136 #define szty(t) (((t) == DOUBLE || (t) == LDOUBLE || \ 137 DEUNSIGN(t) == LONGLONG) ? 2 : 1) 138 139 /* 140 * The PPC register definition are taken from apple docs. 141 * 142 * The classes used are: 143 * A - general registers 144 * B - 64-bit register pairs 145 * C - floating-point registers 146 */ 147 148 #define R0 0 /* scratch register */ 149 #define R1 1 /* stack base pointer */ 150 #define R2 2 151 #define R3 3 /* return register / argument 0 */ 152 #define R4 4 /* return register (for longlong) / argument 1 */ 153 #define R5 5 /* scratch register / argument 2 */ 154 #define R6 6 /* scratch register / argument 3 */ 155 #define R7 7 /* scratch register / argument 4 */ 156 #define R8 8 /* scratch register / argument 5 */ 157 #define R9 9 /* scratch register / argument 6 */ 158 #define R10 10 /* scratch register / argument 7 */ 159 #define R11 11 /* scratch register */ 160 #define R12 12 /* scratch register */ 161 #define R13 13 162 #define R14 14 163 #define R15 15 164 #define R16 16 165 #define R17 17 166 #define R18 18 167 #define R19 19 168 #define R20 20 169 #define R21 21 170 #define R22 22 171 #define R23 23 172 #define R24 24 173 #define R25 25 174 #define R26 26 175 #define R27 27 176 #define R28 28 177 #define R29 29 178 #define R30 30 179 #define R31 31 180 181 #define R3R4 32 182 #define R4R5 33 183 #define R5R6 34 184 #define R6R7 35 185 #define R7R8 36 186 #define R8R9 37 187 #define R9R10 38 188 #define R14R15 39 189 #define R16R17 40 190 #define R18R19 41 191 #define R20R21 42 192 #define R22R23 43 193 #define R24R25 44 194 #define R26R27 45 195 #define R28R29 46 196 #define R30R31 47 197 198 #define F0 48 /* scratch register */ 199 #define F1 49 /* return value 0 / argument 0 */ 200 #define F2 50 /* return value 1 / argument 1 */ 201 #define F3 51 /* return value 2 / argument 2 */ 202 #define F4 52 /* return value 3 / argument 3 */ 203 #define F5 53 /* argument 4 */ 204 #define F6 54 /* argument 5 */ 205 #define F7 55 /* argument 6 */ 206 #define F8 56 /* argument 7 */ 207 #define F9 57 /* argument 8 */ 208 #define F10 58 /* argument 9 */ 209 #define F11 59 /* argument 10 */ 210 #define F12 60 /* argument 11 */ 211 #define F13 61 /* argument 12 */ 212 #define F14 62 213 #define F15 63 214 #define F16 64 215 #define F17 65 216 #define F18 66 217 #define F19 67 218 #define F20 68 219 #define F21 69 220 #define F22 70 221 #define F23 71 222 #define F24 72 223 #define F25 73 224 #define F26 74 225 #define F27 75 226 #define F28 76 227 #define F29 77 228 #define F30 78 229 #define F31 79 230 231 #define NUMCLASS 3 232 #define MAXREGS 64 /* XXX cannot have more than 64 */ 233 234 #define RSTATUS \ 235 0, /* R0 */ \ 236 0, /* R1 */ \ 237 SAREG|TEMPREG, /* R2 */ \ 238 SAREG|TEMPREG, /* R3 */ \ 239 SAREG|TEMPREG, /* R4 */ \ 240 SAREG|TEMPREG, /* R5 */ \ 241 SAREG|TEMPREG, /* R6 */ \ 242 SAREG|TEMPREG, /* R7 */ \ 243 SAREG|TEMPREG, /* R8 */ \ 244 SAREG|TEMPREG, /* R9 */ \ 245 SAREG|TEMPREG, /* R10 */ \ 246 SAREG|TEMPREG, /* R11 */ \ 247 SAREG|TEMPREG, /* R12 */ \ 248 SAREG, /* R13 */ \ 249 SAREG, /* R14 */ \ 250 SAREG, /* R15 */ \ 251 SAREG, /* R16 */ \ 252 SAREG, /* R17 */ \ 253 SAREG, /* R18 */ \ 254 SAREG, /* R19 */ \ 255 SAREG, /* R20 */ \ 256 SAREG, /* R21 */ \ 257 SAREG, /* R22 */ \ 258 SAREG, /* R23 */ \ 259 SAREG, /* R24 */ \ 260 SAREG, /* R25 */ \ 261 SAREG, /* R26 */ \ 262 SAREG, /* R27 */ \ 263 SAREG, /* R28 */ \ 264 SAREG, /* R29 */ \ 265 SAREG, /* R30 */ \ 266 SAREG, /* R31 */ \ 267 \ 268 SBREG|TEMPREG, /* R3R4 */ \ 269 SBREG|TEMPREG, /* R4R5 */ \ 270 SBREG|TEMPREG, /* R5R6 */ \ 271 SBREG|TEMPREG, /* R6R7 */ \ 272 SBREG|TEMPREG, /* R7R8 */ \ 273 SBREG|TEMPREG, /* R8R9 */ \ 274 SBREG|TEMPREG, /* R9R10 */ \ 275 \ 276 SBREG, /* R14R15 */ \ 277 SBREG, /* R16R17 */ \ 278 SBREG, /* R18R19 */ \ 279 SBREG, /* R20R21 */ \ 280 SBREG, /* R22R23 */ \ 281 SBREG, /* R24R25 */ \ 282 SBREG, /* R26R2k */ \ 283 SBREG, /* R28R29 */ \ 284 SBREG, /* R30R31 */ \ 285 \ 286 SCREG|TEMPREG, /* F0 */ \ 287 SCREG|TEMPREG, /* F1 */ \ 288 SCREG|TEMPREG, /* F2 */ \ 289 SCREG|TEMPREG, /* F3 */ \ 290 SCREG|TEMPREG, /* F4 */ \ 291 SCREG|TEMPREG, /* F5 */ \ 292 SCREG|TEMPREG, /* F6 */ \ 293 SCREG|TEMPREG, /* F7 */ \ 294 SCREG|TEMPREG, /* F8 */ \ 295 SCREG|TEMPREG, /* F9 */ \ 296 SCREG|TEMPREG, /* F10 */ \ 297 SCREG|TEMPREG, /* F11 */ \ 298 SCREG|TEMPREG, /* F12 */ \ 299 SCREG|TEMPREG, /* F13 */ \ 300 SCREG, /* F14 */ \ 301 SCREG, /* F15 */ \ 302 303 #define ROVERLAP \ 304 { -1 }, { -1 }, { -1 }, \ 305 { R3R4, -1 }, { R3R4, R4R5, -1 }, \ 306 { R4R5, R5R6, -1 }, { R5R6, R6R7, -1 }, \ 307 { R6R7, R7R8, -1 }, { R7R8, R8R9, -1 }, \ 308 { R8R9, R9R10, -1 }, { R9R10, -1 }, \ 309 { -1 }, { -1 }, { -1 }, \ 310 { R14R15, -1 }, { R14R15, -1 }, \ 311 { R16R17, -1 }, { R16R17, -1 }, \ 312 { R18R19, -1 }, { R18R19, -1 }, \ 313 { R20R21, -1 }, { R20R21, -1 }, \ 314 { R22R23, -1 }, { R22R23, -1 }, \ 315 { R24R25, -1 }, { R24R25, -1 }, \ 316 { R26R27, -1 }, { R26R27, -1 }, \ 317 { R28R29, -1 }, { R28R29, -1 }, \ 318 { R30R31, -1 }, { R30R31, -1 }, \ 319 \ 320 { R3, R4, R4R5, -1 }, { R4, R5, R3R4, R5R6, -1 }, \ 321 { R5, R6, R4R5, R6R7, -1 }, { R6, R7, R5R6, R7R8, -1 }, \ 322 { R7, R8, R6R7, R8R9, -1 }, { R8, R9, R7R8, R8R9, -1 }, \ 323 { R9, R10, R8R9, -1 }, \ 324 { R14, R15, -1 }, { R16, R17, -1 }, \ 325 { R18, R19, -1 }, { R20, R21, -1 }, \ 326 { R22, R23, -1 }, { R24, R25, -1 }, \ 327 { R26, R27, -1 }, { R28, R29, -1 }, \ 328 { R30, R31, -1 }, \ 329 \ 330 { -1 }, { -1 }, { -1 }, { -1 }, \ 331 { -1 }, { -1 }, { -1 }, { -1 }, \ 332 { -1 }, { -1 }, { -1 }, { -1 }, \ 333 { -1 }, { -1 }, { -1 }, { -1 }, \ 334 335 /* 336 * According to the ABI documents, there isn't really a frame pointer; 337 * all references to data on the stack (autos and parameters) are 338 * indexed relative to the stack pointer. However, pcc isn't really 339 * capable of running in this manner, and expects a frame pointer. 340 */ 341 #define SPREG R1 /* stack pointer */ 342 #define FPREG R30 /* frame pointer */ 343 #define GOTREG R31 /* global offset table (PIC) */ 344 345 #ifdef FPREG 346 #define ARGINIT (24*8) /* # bits above fp where arguments start */ 347 #define AUTOINIT (8*8) /* # bits above fp where automatics start */ 348 #define BACKAUTO /* stack grows negatively for automatics */ 349 #define BACKTEMP /* stack grows negatively for temporaries */ 350 #else 351 #define ARGINIT (24*8) /* # bits above fp where arguments start */ 352 #define AUTOINIT (56*8) /* # bits above fp where automatics start */ 353 #endif 354 355 /* Return a register class based on the type of the node */ 356 #define PCLASS(p) (1 << gclass((p)->n_type)) 357 358 #define GCLASS(x) ((x) < 32 ? CLASSA : ((x) < 48 ? CLASSB : CLASSC)) 359 #define DECRA(x,y) (((x) >> (y*6)) & 63) /* decode encoded regs */ 360 #define ENCRA(x,y) ((x) << (6+y*6)) /* encode regs in int */ 361 #define ENCRD(x) (x) /* Encode dest reg in n_reg */ 362 #define RETREG(x) retreg(x) 363 364 int COLORMAP(int c, int *r); 365 int retreg(int ty); 366 367 #define SHSTR (MAXSPECIAL+1) /* short struct */ 368 #define SFUNCALL (MAXSPECIAL+2) /* struct assign after function call */ 369 #define SPCON (MAXSPECIAL+3) /* positive constant */ 370 371 int features(int f); 372 #define FEATURE_BIGENDIAN 0x00010000 373 #define FEATURE_PIC 0x00020000 374 #define FEATURE_HARDFLOAT 0x00040000 375 376 struct stub { 377 struct { struct stub *q_forw, *q_back; } link; 378 char *name; 379 }; 380 extern struct stub stublist; 381 extern struct stub nlplist; 382 void addstub(struct stub *list, char *name); 383 384 #define TARGET_STDARGS 385 #define TARGET_BUILTINS \ 386 { "__builtin_stdarg_start", powerpc_builtin_stdarg_start }, \ 387 { "__builtin_va_arg", powerpc_builtin_va_arg }, \ 388 { "__builtin_va_end", powerpc_builtin_va_end }, \ 389 { "__builtin_va_copy", powerpc_builtin_va_copy }, \ 390 { "__builtin_frame_address", powerpc_builtin_frame_address }, \ 391 { "__builtin_return_address", powerpc_builtin_return_address }, 392 393 #define NODE struct node 394 struct node; 395 NODE *powerpc_builtin_stdarg_start(NODE *f, NODE *a, unsigned int); 396 NODE *powerpc_builtin_va_arg(NODE *f, NODE *a, unsigned int); 397 NODE *powerpc_builtin_va_end(NODE *f, NODE *a, unsigned int); 398 NODE *powerpc_builtin_va_copy(NODE *f, NODE *a, unsigned int); 399 NODE *powerpc_builtin_frame_address(NODE *f, NODE *a, unsigned int); 400 NODE *powerpc_builtin_return_address(NODE *f, NODE *a, unsigned int); 401 #undef NODE 402 403 #define NARGREGS 8 404 405 #ifdef ELFABI 406 #define COM " # " 407 #else 408 #define COM " ; " 409 #endif 410