1 /* 2 ** cpu.h PowerPC cpu-description header-file 3 ** (c) in 2002,2006,2011-2016 by Frank Wille 4 */ 5 6 extern int ppc_endianess; 7 #define BIGENDIAN (ppc_endianess) 8 #define LITTLEENDIAN (!ppc_endianess) 9 #define VASM_CPU_PPC 1 10 #define MNEMOHTABSIZE 0x18000 11 12 /* maximum number of operands for one mnemonic */ 13 #define MAX_OPERANDS 5 14 15 /* maximum number of mnemonic-qualifiers per mnemonic */ 16 #define MAX_QUALIFIERS 0 17 18 /* data type to represent a target-address */ 19 typedef int64_t taddr; 20 typedef uint64_t utaddr; 21 22 /* minimum instruction alignment */ 23 #define INST_ALIGN 4 24 25 /* default alignment for n-bit data */ 26 #define DATA_ALIGN(n) ppc_data_align(n) 27 28 /* operand class for n-bit data definitions */ 29 #define DATA_OPERAND(n) ppc_data_operand(n) 30 31 /* returns true when instruction is valid for selected cpu */ 32 #define MNEMONIC_VALID(i) ppc_available(i) 33 34 /* returns true when operand type is optional; may init default operand */ 35 #define OPERAND_OPTIONAL(p,t) ppc_operand_optional(p,t) 36 37 /* special data operand types: */ 38 #define OP_D8 0x1001 39 #define OP_D16 0x1002 40 #define OP_D32 0x1003 41 #define OP_D64 0x1004 42 #define OP_F32 0x1005 43 #define OP_F64 0x1006 44 45 #define OP_DATA(t) (t >= OP_D8) 46 #define OP_FLOAT(t) (t >= OP_F32) 47 48 /* PPC specific relocations */ 49 #define REL_PPCEABI_SDA2 (LAST_STANDARD_RELOC+1) 50 #define REL_PPCEABI_SDA21 (LAST_STANDARD_RELOC+2) 51 #define REL_PPCEABI_SDAI16 (LAST_STANDARD_RELOC+3) 52 #define REL_PPCEABI_SDA2I16 (LAST_STANDARD_RELOC+4) 53 #define REL_MORPHOS_DREL (LAST_STANDARD_RELOC+5) 54 #define REL_AMIGAOS_BREL (LAST_STANDARD_RELOC+6) 55 #define LAST_PPC_RELOC (LAST_STANDARD_RELOC+6) 56 57 58 /* type to store each operand */ 59 typedef struct { 60 int16_t type; 61 unsigned char attr; /* reloc attribute != REL_NONE when present */ 62 unsigned char mode; /* @l/h/ha */ 63 expr *value; 64 expr *basereg; /* only for d(Rn) load/store addressing mode */ 65 } operand; 66 67 /* operand modifier */ 68 #define OPM_NONE 0 69 #define OPM_LO 1 /* low 16 bits */ 70 #define OPM_HI 2 /* high 16 bits */ 71 #define OPM_HA 3 /* high 16 bits with addi compensation */ 72 73 74 /* additional mnemonic data */ 75 typedef struct { 76 uint64_t available; 77 uint32_t opcode; 78 } mnemonic_extension; 79 80 /* Values defined for the 'available' field of mnemonic_extension. */ 81 #define CPU_TYPE_PPC (1ULL) 82 #define CPU_TYPE_POWER (2ULL) 83 #define CPU_TYPE_POWER2 (4ULL) 84 #define CPU_TYPE_601 (8ULL) 85 #define CPU_TYPE_COMMON (0x10ULL) 86 #define CPU_TYPE_ALTIVEC (0x20ULL) 87 #define CPU_TYPE_403 (0x40ULL) 88 #define CPU_TYPE_405 (0x80ULL) 89 #define CPU_TYPE_440 (0x100ULL) 90 #define CPU_TYPE_476 (0x200ULL) 91 #define CPU_TYPE_BOOKE (0x400ULL) 92 #define CPU_TYPE_E300 (0x800ULL) 93 #define CPU_TYPE_E500 (0x1000ULL) 94 #define CPU_TYPE_VLE (0x2000ULL) 95 #define CPU_TYPE_E500MC (0x4000ULL) 96 #define CPU_TYPE_750 (0x8000ULL) 97 #define CPU_TYPE_7450 (0x10000ULL) 98 #define CPU_TYPE_ISEL (0x20000ULL) 99 #define CPU_TYPE_RFMCI (0x40000ULL) 100 #define CPU_TYPE_PMR (0x80000ULL) 101 #define CPU_TYPE_TMR (0x100000ULL) 102 #define CPU_TYPE_SPE (0x200000ULL) 103 #define CPU_TYPE_EFS (0x400000ULL) 104 #define CPU_TYPE_860 (0x800000ULL) 105 #define CPU_TYPE_ANY (0x1000000000000000ULL) 106 #define CPU_TYPE_64_BRIDGE (0x2000000000000000ULL) 107 #define CPU_TYPE_32 (0x4000000000000000ULL) 108 #define CPU_TYPE_64 (0x8000000000000000ULL) 109 110 /* Shortcuts for PPC instruction sets */ 111 #undef PPC 112 #define PPC CPU_TYPE_PPC 113 #define PPCCOM (CPU_TYPE_PPC | CPU_TYPE_COMMON) 114 #define PPC32 (CPU_TYPE_PPC | CPU_TYPE_32) 115 #define PPC64 (CPU_TYPE_PPC | CPU_TYPE_64) 116 #define PPCONLY CPU_TYPE_PPC 117 #define PPC403 CPU_TYPE_403 118 #define PPC405 CPU_TYPE_405 119 #define PPC440 CPU_TYPE_440 120 #define PPC750 PPC 121 #define PPC860 CPU_TYPE_860 122 #define AVEC CPU_TYPE_ALTIVEC 123 #define BOOKE CPU_TYPE_BOOKE 124 #define E300 CPU_TYPE_E300 125 #define E500 CPU_TYPE_E500 126 #define E500MC CPU_TYPE_E500MC 127 #define RFMCI CPU_TYPE_RFMCI 128 #define ISEL (CPU_TYPE_ISEL | CPU_TYPE_VLE) 129 #define SPE (CPU_TYPE_SPE | CPU_TYPE_VLE) 130 #define EFS (CPU_TYPE_EFS | CPU_TYPE_VLE) 131 #define PPCPMR CPU_TYPE_PMR 132 #define PPC43 (CPU_TYPE_403 | CPU_TYPE_440) 133 #define PPC45 (CPU_TYPE_405 | CPU_TYPE_440) 134 #define BE3403 (CPU_TYPE_403 | CPU_TYPE_476 | CPU_TYPE_E300 | CPU_TYPE_BOOKE) 135 #define BE403 (CPU_TYPE_403 | CPU_TYPE_476 | CPU_TYPE_BOOKE) 136 #define BE476 (CPU_TYPE_476 | CPU_TYPE_BOOKE) 137 #define VLCOM (CPU_TYPE_PPC | CPU_TYPE_COMMON | CPU_TYPE_VLE) 138 #define RFMC476 (CPU_TYPE_RFMCI | CPU_TYPE_476) 139 #define VLRFMCI (CPU_TYPE_RFMCI | CPU_TYPE_VLE) 140 #define VLBE403 (CPU_TYPE_403 | CPU_TYPE_476 | CPU_TYPE_BOOKE | CPU_TYPE_VLE) 141 #define VLBE405 (CPU_TYPE_405 | CPU_TYPE_BOOKE | CPU_TYPE_VLE) 142 #define VL43 (CPU_TYPE_403 | CPU_TYPE_440 | CPU_TYPE_VLE) 143 #define VL45 (CPU_TYPE_405 | CPU_TYPE_440 | CPU_TYPE_VLE) 144 #define VL4376 (CPU_TYPE_403 | CPU_TYPE_440 | CPU_TYPE_476 | CPU_TYPE_VLE) 145 #define VLBE (CPU_TYPE_BOOKE | CPU_TYPE_VLE) 146 #define VLBE476 (CPU_TYPE_476 | CPU_TYPE_BOOKE | CPU_TYPE_VLE) 147 #define VLBE3 (CPU_TYPE_476 | CPU_TYPE_E300 | CPU_TYPE_BOOKE | CPU_TYPE_VLE) 148 #define VL7450 (CPU_TYPE_405 | CPU_TYPE_476 | CPU_TYPE_BOOKE | CPU_TYPE_7450 | CPU_TYPE_VLE) 149 #define VLBEPMR (CPU_TYPE_PMR | CPU_TYPE_BOOKE | CPU_TYPE_VLE) 150 #define POWER CPU_TYPE_POWER 151 #define POWER2 (CPU_TYPE_POWER | CPU_TYPE_POWER2) 152 #define PPCPWR2 (CPU_TYPE_PPC | CPU_TYPE_POWER | CPU_TYPE_POWER2) 153 #define POWER32 (CPU_TYPE_POWER | CPU_TYPE_32) 154 #define COM (CPU_TYPE_POWER | CPU_TYPE_PPC | CPU_TYPE_COMMON) 155 #define COM32 (CPU_TYPE_POWER | CPU_TYPE_PPC | CPU_TYPE_COMMON | CPU_TYPE_32) 156 #define M601 (CPU_TYPE_POWER | CPU_TYPE_601) 157 #define PWRCOM (CPU_TYPE_POWER | CPU_TYPE_601 | CPU_TYPE_COMMON) 158 #define MFDEC1 CPU_TYPE_POWER 159 #define MFDEC2 (CPU_TYPE_PPC | CPU_TYPE_601) 160 161 162 /* Macros used to form opcodes */ 163 #define OP(x) ((((uint32_t)(x)) & 0x3f) << 26) 164 #define OPTO(x,to) (OP (x) | ((((uint32_t)(to)) & 0x1f) << 21)) 165 #define OPL(x,l) (OP (x) | ((((uint32_t)(l)) & 1) << 21)) 166 #define A(op, xop, rc) \ 167 (OP (op) | ((((uint32_t)(xop)) & 0x1f) << 1) | (((uint32_t)(rc)) & 1)) 168 #define B(op, aa, lk) (OP (op) | ((((uint32_t)(aa)) & 1) << 1) | ((lk) & 1)) 169 #define BBO(op, bo, aa, lk) (B ((op), (aa), (lk)) | ((((uint32_t)(bo)) & 0x1f) << 21)) 170 #define BBOCB(op, bo, cb, aa, lk) \ 171 (BBO ((op), (bo), (aa), (lk)) | ((((uint32_t)(cb)) & 0x3) << 16)) 172 #define DSO(op, xop) (OP (op) | ((xop) & 0x3)) 173 #define M(op, rc) (OP (op) | ((rc) & 1)) 174 #define MME(op, me, rc) (M ((op), (rc)) | ((((uint32_t)(me)) & 0x1f) << 1)) 175 #define MD(op, xop, rc) \ 176 (OP (op) | ((((uint32_t)(xop)) & 0x7) << 2) | ((rc) & 1)) 177 #define MDS(op, xop, rc) \ 178 (OP (op) | ((((uint32_t)(xop)) & 0xf) << 1) | ((rc) & 1)) 179 #define SC(op, sa, lk) (OP (op) | ((((uint32_t)(sa)) & 1) << 1) | ((lk) & 1)) 180 #define VX(op, xop) (OP (op) | (((uint32_t)(xop)) & 0x7ff)) 181 #define VXA(op, xop) (OP (op) | (((uint32_t)(xop)) & 0x07f)) 182 #define VXR(op, xop, rc) \ 183 (OP (op) | (((rc) & 1) << 10) | (((uint32_t)(xop)) & 0x3ff)) 184 #define X(op, xop) (OP (op) | ((((uint32_t)(xop)) & 0x3ff) << 1)) 185 #define XRC(op, xop, rc) (X ((op), (xop)) | ((rc) & 1)) 186 #define XCMPL(op, xop, l) (X ((op), (xop)) | ((((uint32_t)(l)) & 1) << 21)) 187 #define XTO(op, xop, to) (X ((op), (xop)) | ((((uint32_t)(to)) & 0x1f) << 21)) 188 #define XTLB(op, xop, sh) (X ((op), (xop)) | ((((uint32_t)(sh)) & 0x1f) << 11)) 189 #define XFL(op, xop, rc) \ 190 (OP (op) | ((((uint32_t)(xop)) & 0x3ff) << 1) | (((uint32_t)(rc)) & 1)) 191 #define XL(op, xop) (OP (op) | ((((uint32_t)(xop)) & 0x3ff) << 1)) 192 #define XLLK(op, xop, lk) (XL ((op), (xop)) | ((lk) & 1)) 193 #define XLO(op, bo, xop, lk) \ 194 (XLLK ((op), (xop), (lk)) | ((((uint32_t)(bo)) & 0x1f) << 21)) 195 #define XLYLK(op, xop, y, lk) \ 196 (XLLK ((op), (xop), (lk)) | ((((uint32_t)(y)) & 1) << 21)) 197 #define XLOCB(op, bo, cb, xop, lk) \ 198 (XLO ((op), (bo), (xop), (lk)) | ((((uint32_t)(cb)) & 3) << 16)) 199 #define XO(op, xop, oe, rc) \ 200 (OP (op) | ((((uint32_t)(xop)) & 0x1ff) << 1) | \ 201 ((((uint32_t)(oe)) & 1) << 10) | (((uint32_t)(rc)) & 1)) 202 #define XS(op, xop, rc) \ 203 (OP (op) | ((((uint32_t)(xop)) & 0x1ff) << 2) | (((uint32_t)(rc)) & 1)) 204 #define XFXM(op, xop, fxm) \ 205 (X ((op), (xop)) | ((((uint32_t)(fxm)) & 0xff) << 12)) 206 #define XSPR(op, xop, spr) \ 207 (X ((op), (xop)) | ((((uint32_t)(spr)) & 0x1f) << 16) | \ 208 ((((uint32_t)(spr)) & 0x3e0) << 6)) 209 #define XDS(op, xop, at) \ 210 (X ((op), (xop)) | ((((uint32_t)(at)) & 1) << 25)) 211 #define XISEL(op, xop) (OP (op) | ((((uint32_t)(xop)) & 0x1f) << 1)) 212 #define XSYNC(op, xop, l) (X ((op), (xop)) | ((((uint32_t)(l)) & 3) << 21)) 213 #define EVSEL(op, xop) (OP (op) | (((uint32_t)(xop)) & 0xff) << 3) 214 215 216 /* The BO encodings used in extended conditional branch mnemonics. */ 217 #define BODNZF (0x0) 218 #define BODNZFP (0x1) 219 #define BODZF (0x2) 220 #define BODZFP (0x3) 221 #define BOF (0x4) 222 #define BOFP (0x5) 223 #define BODNZT (0x8) 224 #define BODNZTP (0x9) 225 #define BODZT (0xa) 226 #define BODZTP (0xb) 227 #define BOT (0xc) 228 #define BOTP (0xd) 229 #define BODNZ (0x10) 230 #define BODNZP (0x11) 231 #define BODZ (0x12) 232 #define BODZP (0x13) 233 #define BOU (0x14) 234 235 /* The BI condition bit encodings used in extended conditional branch 236 mnemonics. */ 237 #define CBLT (0) 238 #define CBGT (1) 239 #define CBEQ (2) 240 #define CBSO (3) 241 242 /* The TO encodings used in extended trap mnemonics. */ 243 #define TOLGT (0x1) 244 #define TOLLT (0x2) 245 #define TOEQ (0x4) 246 #define TOLGE (0x5) 247 #define TOLNL (0x5) 248 #define TOLLE (0x6) 249 #define TOLNG (0x6) 250 #define TOGT (0x8) 251 #define TOGE (0xc) 252 #define TONL (0xc) 253 #define TOLT (0x10) 254 #define TOLE (0x14) 255 #define TONG (0x14) 256 #define TONE (0x18) 257 #define TOU (0x1f) 258 259 260 /* Prototypes */ 261 int ppc_data_align(int); 262 int ppc_data_operand(int); 263 int ppc_available(int); 264 int ppc_operand_optional(operand *,int); 265