1/* Id: macdefs.h,v 1.33 2011/06/05 10:19:24 ragge Exp */ 2/* $NetBSD: macdefs.h,v 1.1.1.4 2011/09/01 12:46:43 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28/* 29 * Machine-dependent defines for both passes. 30 */ 31 32/* 33 * Convert (multi-)character constant to integer. 34 * Assume: If only one value; store at left side (char size), otherwise 35 * treat it as an integer. 36 */ 37#define makecc(val,i) { \ 38 if (i == 0) { lastcon = val; \ 39 } else if (i == 1) { lastcon = (lastcon << 9) | val; lastcon <<= 18; \ 40 } else { lastcon |= (val << (27 - (i * 9))); } } 41 42#define ARGINIT 36 /* # bits below fp where arguments start */ 43#define AUTOINIT 36 /* # bits above fp where automatics start */ 44 45/* 46 * Storage space requirements 47 */ 48#define SZCHAR 9 49#define SZBOOL 36 50#define SZINT 36 51#define SZFLOAT 36 52#define SZDOUBLE 72 53#define SZLDOUBLE 72 54#define SZLONG 36 55#define SZSHORT 18 56#define SZPOINT(x) 36 57#define SZLONGLONG 72 58 59/* 60 * Alignment constraints 61 */ 62#define ALCHAR 9 63#define ALBOOL 36 64#define ALINT 36 65#define ALFLOAT 36 66#define ALDOUBLE 36 67#define ALLDOUBLE 36 68#define ALLONG 36 69#define ALLONGLONG 36 70#define ALSHORT 18 71#define ALPOINT 36 72#define ALSTRUCT 36 73#define ALSTACK 36 74 75/* 76 * Max values. 77 */ 78#define MIN_CHAR -256 79#define MAX_CHAR 255 80#define MAX_UCHAR 511 81#define MIN_SHORT -131072 82#define MAX_SHORT 131071 83#define MAX_USHORT 262143 84#define MIN_INT (-0377777777777LL-1) 85#define MAX_INT 0377777777777LL 86#define MAX_UNSIGNED 0777777777777ULL 87#define MIN_LONG (-0377777777777LL-1) 88#define MAX_LONG 0377777777777LL 89#define MAX_ULONG 0777777777777ULL 90#define MIN_LONGLONG (000777777777777777777777LL-1) /* XXX cross */ 91#define MAX_LONGLONG 000777777777777777777777LL /* XXX cross */ 92#define MAX_ULONGLONG 001777777777777777777777ULL /* XXX cross */ 93 94/* Default char is unsigned */ 95#define TARGET_STDARGS 96#define CHAR_UNSIGNED 97#define BOOL_TYPE INT 98#define WORD_ADDRESSED 99 100/* 101 * Use large-enough types. 102 */ 103typedef long long CONSZ; 104typedef unsigned long long U_CONSZ; 105typedef long long OFFSZ; 106 107#define CONFMT "0%llo" /* format for printing constants */ 108#define LABFMT ".L%d" /* format for printing labels */ 109#define STABLBL ".LL%d" /* format for stab (debugging) labels */ 110 111#undef BACKAUTO /* stack grows negatively for automatics */ 112#undef BACKTEMP /* stack grows negatively for temporaries */ 113 114#undef FIELDOPS /* no bit-field instructions */ 115#define TARGET_ENDIAN TARGET_BE 116 117/* Definitions mostly used in pass2 */ 118 119#define BYTEOFF(x) ((x)&03) 120#define wdal(k) (BYTEOFF(k)==0) 121#define BITOOR(x) ((x)/36) /* bit offset to oreg offset */ 122 123#define STOARG(p) 124#define STOFARG(p) 125#define STOSTARG(p) 126#define genfcall(a,b) gencall(a,b) 127 128#define szty(t) (((t) == DOUBLE || (t) == FLOAT || \ 129 (t) == LONGLONG || (t) == ULONGLONG) ? 2 : 1) 130 131#define shltype(o, p) \ 132 ((o) == REG || (o) == NAME || (o) == ICON || \ 133 (o) == OREG || ((o) == UMUL && shumul((p)->n_left, SOREG))) 134 135#undef SPECIAL_INTEGERS 136 137/* 138 * Special shapes used in code generation. 139 */ 140#define SUSHCON (SPECIAL|6) /* unsigned short constant */ 141#define SNSHCON (SPECIAL|7) /* negative short constant */ 142#define SILDB (SPECIAL|8) /* use ildb here */ 143 144/* 145 * Register allocator definitions. 146 * 147 * The pdp10 has 16 general-purpose registers, but the two 148 * highest are used as sp and fp. Register 0 has special 149 * constraints in its possible use as index register. 150 * All regs can be used as pairs, named by the lowest number. 151 * In here we call the registers Rn and the pairs XRn, in assembler 152 * just its number prefixed with %. 153 * 154 * R1/XR1 are return registers. 155 * 156 * R0 is currently not used. 157 */ 158 159#define MAXREGS 29 /* 16 + 13 regs */ 160#define NUMCLASS 2 161 162#define R0 00 163#define R1 01 164#define R2 02 165#define R3 03 166#define R4 04 167#define R5 05 168#define R6 06 169#define R7 07 170#define R10 010 171#define R11 011 172#define R12 012 173#define R13 013 174#define R14 014 175#define R15 015 176#define R16 016 177#define R17 017 178#define FPREG R16 /* frame pointer */ 179#define STKREG R17 /* stack pointer */ 180 181 182#define XR0 020 183#define XR1 021 184#define XR2 022 185#define XR3 023 186#define XR4 024 187#define XR5 025 188#define XR6 026 189#define XR7 027 190#define XR10 030 191#define XR11 031 192#define XR12 032 193#define XR13 033 194#define XR14 034 195 196 197#define RSTATUS \ 198 0, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, \ 199 SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, SAREG|TEMPREG, \ 200 SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, SAREG|PERMREG, \ 201 SAREG|PERMREG, SAREG|PERMREG, 0, 0, \ 202 SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, SBREG, \ 203 SBREG, SBREG, SBREG, SBREG, SBREG, 204 205#define ROVERLAP \ 206 { XR0, -1 }, \ 207 { XR0, XR1, -1 }, \ 208 { XR1, XR2, -1 }, \ 209 { XR2, XR3, -1 }, \ 210 { XR3, XR4, -1 }, \ 211 { XR4, XR5, -1 }, \ 212 { XR5, XR6, -1 }, \ 213 { XR6, XR7, -1 }, \ 214 { XR7, XR10, -1 }, \ 215 { XR10, XR11, -1 }, \ 216 { XR11, XR12, -1 }, \ 217 { XR12, XR13, -1 }, \ 218 { XR13, XR14, -1 }, \ 219 { XR14, -1 }, \ 220 { -1 }, \ 221 { -1 }, \ 222 { R0, R1, XR1, -1 }, \ 223 { R1, R2, XR0, XR2, -1 }, \ 224 { R2, R3, XR1, XR3, -1 }, \ 225 { R3, R4, XR2, XR4, -1 }, \ 226 { R4, R5, XR3, XR5, -1 }, \ 227 { R5, R6, XR4, XR6, -1 }, \ 228 { R6, R7, XR5, XR7, -1 }, \ 229 { R7, R10, XR6, XR10, -1 }, \ 230 { R10, R11, XR7, XR11, -1 }, \ 231 { R11, R12, XR10, XR12, -1 }, \ 232 { R12, R13, XR11, XR13, -1 }, \ 233 { R13, R14, XR12, XR14, -1 }, \ 234 { R14, R15, XR13, -1 }, 235 236/* Return a register class based on the type of the node */ 237#define PCLASS(p) (szty(p->n_type) == 2 ? SBREG : SAREG) 238#define RETREG(x) (szty(x) == 2 ? XR1 : R1) 239#define DECRA(x,y) (((x) >> (y*6)) & 63) /* decode encoded regs */ 240#define ENCRD(x) (x) /* Encode dest reg in n_reg */ 241#define ENCRA1(x) ((x) << 6) /* A1 */ 242#define ENCRA2(x) ((x) << 12) /* A2 */ 243#define ENCRA(x,y) ((x) << (6+y*6)) /* encode regs in int */ 244#define GCLASS(x) (x < 16 ? CLASSA : CLASSB) 245int COLORMAP(int c, int *r); 246