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