1*3d8817e4Smiod /* crx.h -- Header file for CRX opcode and register tables. 2*3d8817e4Smiod Copyright 2004 Free Software Foundation, Inc. 3*3d8817e4Smiod Contributed by Tomer Levi, NSC, Israel. 4*3d8817e4Smiod Originally written for GAS 2.12 by Tomer Levi, NSC, Israel. 5*3d8817e4Smiod Updates, BFDizing, GNUifying and ELF support by Tomer Levi. 6*3d8817e4Smiod 7*3d8817e4Smiod This file is part of GAS, GDB and the GNU binutils. 8*3d8817e4Smiod 9*3d8817e4Smiod GAS, GDB, and GNU binutils is free software; you can redistribute it 10*3d8817e4Smiod and/or modify it under the terms of the GNU General Public License as 11*3d8817e4Smiod published by the Free Software Foundation; either version 2, or (at your 12*3d8817e4Smiod option) any later version. 13*3d8817e4Smiod 14*3d8817e4Smiod GAS, GDB, and GNU binutils are distributed in the hope that they will be 15*3d8817e4Smiod useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 16*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*3d8817e4Smiod GNU General Public License for more details. 18*3d8817e4Smiod 19*3d8817e4Smiod You should have received a copy of the GNU General Public License 20*3d8817e4Smiod along with this program; if not, write to the Free Software 21*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 22*3d8817e4Smiod 23*3d8817e4Smiod #ifndef _CRX_H_ 24*3d8817e4Smiod #define _CRX_H_ 25*3d8817e4Smiod 26*3d8817e4Smiod /* CRX core/debug Registers : 27*3d8817e4Smiod The enums are used as indices to CRX registers table (crx_regtab). 28*3d8817e4Smiod Therefore, order MUST be preserved. */ 29*3d8817e4Smiod 30*3d8817e4Smiod typedef enum 31*3d8817e4Smiod { 32*3d8817e4Smiod /* 32-bit general purpose registers. */ 33*3d8817e4Smiod r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, 34*3d8817e4Smiod r10, r11, r12, r13, r14, r15, ra, sp, 35*3d8817e4Smiod /* 32-bit user registers. */ 36*3d8817e4Smiod u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, 37*3d8817e4Smiod u10, u11, u12, u13, u14, u15, ura, usp, 38*3d8817e4Smiod /* hi and lo registers. */ 39*3d8817e4Smiod hi, lo, 40*3d8817e4Smiod /* hi and lo user registers. */ 41*3d8817e4Smiod uhi, ulo, 42*3d8817e4Smiod /* Processor Status Register. */ 43*3d8817e4Smiod psr, 44*3d8817e4Smiod /* Interrupt Base Register. */ 45*3d8817e4Smiod intbase, 46*3d8817e4Smiod /* Interrupt Stack Pointer Register. */ 47*3d8817e4Smiod isp, 48*3d8817e4Smiod /* Configuration Register. */ 49*3d8817e4Smiod cfg, 50*3d8817e4Smiod /* Coprocessor Configuration Register. */ 51*3d8817e4Smiod cpcfg, 52*3d8817e4Smiod /* Coprocessor Enable Register. */ 53*3d8817e4Smiod cen, 54*3d8817e4Smiod /* Not a register. */ 55*3d8817e4Smiod nullregister, 56*3d8817e4Smiod MAX_REG 57*3d8817e4Smiod } 58*3d8817e4Smiod reg; 59*3d8817e4Smiod 60*3d8817e4Smiod /* CRX Coprocessor registers and special registers : 61*3d8817e4Smiod The enums are used as indices to CRX coprocessor registers table 62*3d8817e4Smiod (crx_copregtab). Therefore, order MUST be preserved. */ 63*3d8817e4Smiod 64*3d8817e4Smiod typedef enum 65*3d8817e4Smiod { 66*3d8817e4Smiod /* Coprocessor registers. */ 67*3d8817e4Smiod c0 = MAX_REG, c1, c2, c3, c4, c5, c6, c7, c8, 68*3d8817e4Smiod c9, c10, c11, c12, c13, c14, c15, 69*3d8817e4Smiod /* Coprocessor special registers. */ 70*3d8817e4Smiod cs0, cs1 ,cs2, cs3, cs4, cs5, cs6, cs7, cs8, 71*3d8817e4Smiod cs9, cs10, cs11, cs12, cs13, cs14, cs15, 72*3d8817e4Smiod /* Not a Coprocessor register. */ 73*3d8817e4Smiod nullcopregister, 74*3d8817e4Smiod MAX_COPREG 75*3d8817e4Smiod } 76*3d8817e4Smiod copreg; 77*3d8817e4Smiod 78*3d8817e4Smiod /* CRX Register types. */ 79*3d8817e4Smiod 80*3d8817e4Smiod typedef enum 81*3d8817e4Smiod { 82*3d8817e4Smiod CRX_R_REGTYPE, /* r<N> */ 83*3d8817e4Smiod CRX_U_REGTYPE, /* u<N> */ 84*3d8817e4Smiod CRX_C_REGTYPE, /* c<N> */ 85*3d8817e4Smiod CRX_CS_REGTYPE, /* cs<N> */ 86*3d8817e4Smiod CRX_CFG_REGTYPE /* configuration register */ 87*3d8817e4Smiod } 88*3d8817e4Smiod reg_type; 89*3d8817e4Smiod 90*3d8817e4Smiod /* CRX argument types : 91*3d8817e4Smiod The argument types correspond to instructions operands 92*3d8817e4Smiod 93*3d8817e4Smiod Argument types : 94*3d8817e4Smiod r - register 95*3d8817e4Smiod c - constant 96*3d8817e4Smiod i - immediate 97*3d8817e4Smiod idxr - index register 98*3d8817e4Smiod rbase - register base 99*3d8817e4Smiod s - star ('*') 100*3d8817e4Smiod copr - coprocessor register 101*3d8817e4Smiod copsr - coprocessor special register. */ 102*3d8817e4Smiod 103*3d8817e4Smiod typedef enum 104*3d8817e4Smiod { 105*3d8817e4Smiod arg_r, arg_c, arg_cr, arg_ic, arg_icr, arg_sc, 106*3d8817e4Smiod arg_idxr, arg_rbase, arg_copr, arg_copsr, 107*3d8817e4Smiod /* Not an argument. */ 108*3d8817e4Smiod nullargs 109*3d8817e4Smiod } 110*3d8817e4Smiod argtype; 111*3d8817e4Smiod 112*3d8817e4Smiod /* CRX operand types : 113*3d8817e4Smiod The operand types correspond to instructions operands. */ 114*3d8817e4Smiod 115*3d8817e4Smiod typedef enum 116*3d8817e4Smiod { 117*3d8817e4Smiod dummy, 118*3d8817e4Smiod /* 4-bit encoded constant. */ 119*3d8817e4Smiod cst4, 120*3d8817e4Smiod /* N-bit immediate. */ 121*3d8817e4Smiod i16, i32, 122*3d8817e4Smiod /* N-bit unsigned immediate. */ 123*3d8817e4Smiod ui3, ui4, ui5, ui16, 124*3d8817e4Smiod /* N-bit signed displacement. */ 125*3d8817e4Smiod disps9, disps17, disps25, disps32, 126*3d8817e4Smiod /* N-bit unsigned displacement. */ 127*3d8817e4Smiod dispu5, 128*3d8817e4Smiod /* N-bit escaped displacement. */ 129*3d8817e4Smiod dispe9, 130*3d8817e4Smiod /* N-bit absolute address. */ 131*3d8817e4Smiod abs16, abs32, 132*3d8817e4Smiod /* Register relative. */ 133*3d8817e4Smiod rbase, rbase_dispu4, 134*3d8817e4Smiod rbase_disps12, rbase_disps16, rbase_disps28, rbase_disps32, 135*3d8817e4Smiod /* Register index. */ 136*3d8817e4Smiod rindex_disps6, rindex_disps22, 137*3d8817e4Smiod /* 4-bit genaral-purpose register specifier. */ 138*3d8817e4Smiod regr, 139*3d8817e4Smiod /* 8-bit register address space. */ 140*3d8817e4Smiod regr8, 141*3d8817e4Smiod /* coprocessor register. */ 142*3d8817e4Smiod copregr, 143*3d8817e4Smiod /* coprocessor special register. */ 144*3d8817e4Smiod copsregr, 145*3d8817e4Smiod /* Not an operand. */ 146*3d8817e4Smiod nulloperand, 147*3d8817e4Smiod /* Maximum supported operand. */ 148*3d8817e4Smiod MAX_OPRD 149*3d8817e4Smiod } 150*3d8817e4Smiod operand_type; 151*3d8817e4Smiod 152*3d8817e4Smiod /* CRX instruction types. */ 153*3d8817e4Smiod 154*3d8817e4Smiod #define NO_TYPE_INS 0 155*3d8817e4Smiod #define ARITH_INS 1 156*3d8817e4Smiod #define LD_STOR_INS 2 157*3d8817e4Smiod #define BRANCH_INS 3 158*3d8817e4Smiod #define ARITH_BYTE_INS 4 159*3d8817e4Smiod #define CMPBR_INS 5 160*3d8817e4Smiod #define SHIFT_INS 6 161*3d8817e4Smiod #define BRANCH_NEQ_INS 7 162*3d8817e4Smiod #define LD_STOR_INS_INC 8 163*3d8817e4Smiod #define STOR_IMM_INS 9 164*3d8817e4Smiod #define CSTBIT_INS 10 165*3d8817e4Smiod #define COP_BRANCH_INS 11 166*3d8817e4Smiod #define COP_REG_INS 12 167*3d8817e4Smiod #define COPS_REG_INS 13 168*3d8817e4Smiod #define DCR_BRANCH_INS 14 169*3d8817e4Smiod 170*3d8817e4Smiod /* Maximum value supported for instruction types. */ 171*3d8817e4Smiod #define CRX_INS_MAX (1 << 4) 172*3d8817e4Smiod /* Mask to record an instruction type. */ 173*3d8817e4Smiod #define CRX_INS_MASK (CRX_INS_MAX - 1) 174*3d8817e4Smiod /* Return instruction type, given instruction's attributes. */ 175*3d8817e4Smiod #define CRX_INS_TYPE(attr) ((attr) & CRX_INS_MASK) 176*3d8817e4Smiod 177*3d8817e4Smiod /* Indicates whether this instruction has a register list as parameter. */ 178*3d8817e4Smiod #define REG_LIST CRX_INS_MAX 179*3d8817e4Smiod /* The operands in binary and assembly are placed in reverse order. 180*3d8817e4Smiod load - (REVERSE_MATCH)/store - (! REVERSE_MATCH). */ 181*3d8817e4Smiod #define REVERSE_MATCH (1 << 5) 182*3d8817e4Smiod 183*3d8817e4Smiod /* Kind of displacement map used DISPU[BWD]4. */ 184*3d8817e4Smiod #define DISPUB4 (1 << 6) 185*3d8817e4Smiod #define DISPUW4 (1 << 7) 186*3d8817e4Smiod #define DISPUD4 (1 << 8) 187*3d8817e4Smiod #define DISPU4MAP (DISPUB4 | DISPUW4 | DISPUD4) 188*3d8817e4Smiod 189*3d8817e4Smiod /* Printing formats, where the instruction prefix isn't consecutive. */ 190*3d8817e4Smiod #define FMT_1 (1 << 9) /* 0xF0F00000 */ 191*3d8817e4Smiod #define FMT_2 (1 << 10) /* 0xFFF0FF00 */ 192*3d8817e4Smiod #define FMT_3 (1 << 11) /* 0xFFF00F00 */ 193*3d8817e4Smiod #define FMT_4 (1 << 12) /* 0xFFF0F000 */ 194*3d8817e4Smiod #define FMT_5 (1 << 13) /* 0xFFF0FFF0 */ 195*3d8817e4Smiod #define FMT_CRX (FMT_1 | FMT_2 | FMT_3 | FMT_4 | FMT_5) 196*3d8817e4Smiod 197*3d8817e4Smiod /* Indicates whether this instruction can be relaxed. */ 198*3d8817e4Smiod #define RELAXABLE (1 << 14) 199*3d8817e4Smiod 200*3d8817e4Smiod /* Indicates that instruction uses user registers (and not 201*3d8817e4Smiod general-purpose registers) as operands. */ 202*3d8817e4Smiod #define USER_REG (1 << 15) 203*3d8817e4Smiod 204*3d8817e4Smiod /* Indicates that instruction can perfom a cst4 mapping. */ 205*3d8817e4Smiod #define CST4MAP (1 << 16) 206*3d8817e4Smiod 207*3d8817e4Smiod /* Instruction shouldn't allow 'sp' usage. */ 208*3d8817e4Smiod #define NO_SP (1 << 17) 209*3d8817e4Smiod 210*3d8817e4Smiod /* Instruction shouldn't allow to push a register which is used as a rptr. */ 211*3d8817e4Smiod #define NO_RPTR (1 << 18) 212*3d8817e4Smiod 213*3d8817e4Smiod /* Maximum operands per instruction. */ 214*3d8817e4Smiod #define MAX_OPERANDS 5 215*3d8817e4Smiod /* Maximum register name length. */ 216*3d8817e4Smiod #define MAX_REGNAME_LEN 10 217*3d8817e4Smiod /* Maximum instruction length. */ 218*3d8817e4Smiod #define MAX_INST_LEN 256 219*3d8817e4Smiod 220*3d8817e4Smiod 221*3d8817e4Smiod /* Values defined for the flags field of a struct operand_entry. */ 222*3d8817e4Smiod 223*3d8817e4Smiod /* Operand must be an unsigned number. */ 224*3d8817e4Smiod #define OP_UNSIGNED (1 << 0) 225*3d8817e4Smiod /* Operand must be a signed number. */ 226*3d8817e4Smiod #define OP_SIGNED (1 << 1) 227*3d8817e4Smiod /* A special arithmetic 4-bit constant operand. */ 228*3d8817e4Smiod #define OP_CST4 (1 << 2) 229*3d8817e4Smiod /* A special load/stor 4-bit unsigned displacement operand. */ 230*3d8817e4Smiod #define OP_DISPU4 (1 << 3) 231*3d8817e4Smiod /* Operand must be an even number. */ 232*3d8817e4Smiod #define OP_EVEN (1 << 4) 233*3d8817e4Smiod /* Operand is shifted right. */ 234*3d8817e4Smiod #define OP_SHIFT (1 << 5) 235*3d8817e4Smiod /* Operand is shifted right and decremented. */ 236*3d8817e4Smiod #define OP_SHIFT_DEC (1 << 6) 237*3d8817e4Smiod /* Operand has reserved escape sequences. */ 238*3d8817e4Smiod #define OP_ESC (1 << 7) 239*3d8817e4Smiod /* Operand is used only for the upper 64 KB (FFFF0000 to FFFFFFFF). */ 240*3d8817e4Smiod #define OP_UPPER_64KB (1 << 8) 241*3d8817e4Smiod 242*3d8817e4Smiod /* Single operand description. */ 243*3d8817e4Smiod 244*3d8817e4Smiod typedef struct 245*3d8817e4Smiod { 246*3d8817e4Smiod /* Operand type. */ 247*3d8817e4Smiod operand_type op_type; 248*3d8817e4Smiod /* Operand location within the opcode. */ 249*3d8817e4Smiod unsigned int shift; 250*3d8817e4Smiod } 251*3d8817e4Smiod operand_desc; 252*3d8817e4Smiod 253*3d8817e4Smiod /* Instruction data structure used in instruction table. */ 254*3d8817e4Smiod 255*3d8817e4Smiod typedef struct 256*3d8817e4Smiod { 257*3d8817e4Smiod /* Name. */ 258*3d8817e4Smiod const char *mnemonic; 259*3d8817e4Smiod /* Size (in words). */ 260*3d8817e4Smiod unsigned int size; 261*3d8817e4Smiod /* Constant prefix (matched by the disassembler). */ 262*3d8817e4Smiod unsigned long match; 263*3d8817e4Smiod /* Match size (in bits). */ 264*3d8817e4Smiod int match_bits; 265*3d8817e4Smiod /* Attributes. */ 266*3d8817e4Smiod unsigned int flags; 267*3d8817e4Smiod /* Operands (always last, so unreferenced operands are initialized). */ 268*3d8817e4Smiod operand_desc operands[MAX_OPERANDS]; 269*3d8817e4Smiod } 270*3d8817e4Smiod inst; 271*3d8817e4Smiod 272*3d8817e4Smiod /* Data structure for a single instruction's arguments (Operands). */ 273*3d8817e4Smiod 274*3d8817e4Smiod typedef struct 275*3d8817e4Smiod { 276*3d8817e4Smiod /* Register or base register. */ 277*3d8817e4Smiod reg r; 278*3d8817e4Smiod /* Index register. */ 279*3d8817e4Smiod reg i_r; 280*3d8817e4Smiod /* Coprocessor register. */ 281*3d8817e4Smiod copreg cr; 282*3d8817e4Smiod /* Constant/immediate/absolute value. */ 283*3d8817e4Smiod long constant; 284*3d8817e4Smiod /* Scaled index mode. */ 285*3d8817e4Smiod unsigned int scale; 286*3d8817e4Smiod /* Argument type. */ 287*3d8817e4Smiod argtype type; 288*3d8817e4Smiod /* Size of the argument (in bits) required to represent. */ 289*3d8817e4Smiod int size; 290*3d8817e4Smiod /* The type of the expression. */ 291*3d8817e4Smiod unsigned char X_op; 292*3d8817e4Smiod } 293*3d8817e4Smiod argument; 294*3d8817e4Smiod 295*3d8817e4Smiod /* Internal structure to hold the various entities 296*3d8817e4Smiod corresponding to the current assembling instruction. */ 297*3d8817e4Smiod 298*3d8817e4Smiod typedef struct 299*3d8817e4Smiod { 300*3d8817e4Smiod /* Number of arguments. */ 301*3d8817e4Smiod int nargs; 302*3d8817e4Smiod /* The argument data structure for storing args (operands). */ 303*3d8817e4Smiod argument arg[MAX_OPERANDS]; 304*3d8817e4Smiod /* The following fields are required only by CRX-assembler. */ 305*3d8817e4Smiod #ifdef TC_CRX 306*3d8817e4Smiod /* Expression used for setting the fixups (if any). */ 307*3d8817e4Smiod expressionS exp; 308*3d8817e4Smiod bfd_reloc_code_real_type rtype; 309*3d8817e4Smiod #endif /* TC_CRX */ 310*3d8817e4Smiod /* Instruction size (in bytes). */ 311*3d8817e4Smiod int size; 312*3d8817e4Smiod } 313*3d8817e4Smiod ins; 314*3d8817e4Smiod 315*3d8817e4Smiod /* Structure to hold information about predefined operands. */ 316*3d8817e4Smiod 317*3d8817e4Smiod typedef struct 318*3d8817e4Smiod { 319*3d8817e4Smiod /* Size (in bits). */ 320*3d8817e4Smiod unsigned int bit_size; 321*3d8817e4Smiod /* Argument type. */ 322*3d8817e4Smiod argtype arg_type; 323*3d8817e4Smiod /* One bit syntax flags. */ 324*3d8817e4Smiod int flags; 325*3d8817e4Smiod } 326*3d8817e4Smiod operand_entry; 327*3d8817e4Smiod 328*3d8817e4Smiod /* Structure to hold trap handler information. */ 329*3d8817e4Smiod 330*3d8817e4Smiod typedef struct 331*3d8817e4Smiod { 332*3d8817e4Smiod /* Trap name. */ 333*3d8817e4Smiod char *name; 334*3d8817e4Smiod /* Index in dispatch table. */ 335*3d8817e4Smiod unsigned int entry; 336*3d8817e4Smiod } 337*3d8817e4Smiod trap_entry; 338*3d8817e4Smiod 339*3d8817e4Smiod /* Structure to hold information about predefined registers. */ 340*3d8817e4Smiod 341*3d8817e4Smiod typedef struct 342*3d8817e4Smiod { 343*3d8817e4Smiod /* Name (string representation). */ 344*3d8817e4Smiod char *name; 345*3d8817e4Smiod /* Value (enum representation). */ 346*3d8817e4Smiod union 347*3d8817e4Smiod { 348*3d8817e4Smiod /* Register. */ 349*3d8817e4Smiod reg reg_val; 350*3d8817e4Smiod /* Coprocessor register. */ 351*3d8817e4Smiod copreg copreg_val; 352*3d8817e4Smiod } value; 353*3d8817e4Smiod /* Register image. */ 354*3d8817e4Smiod int image; 355*3d8817e4Smiod /* Register type. */ 356*3d8817e4Smiod reg_type type; 357*3d8817e4Smiod } 358*3d8817e4Smiod reg_entry; 359*3d8817e4Smiod 360*3d8817e4Smiod /* Structure to hold a cst4 operand mapping. */ 361*3d8817e4Smiod 362*3d8817e4Smiod /* CRX opcode table. */ 363*3d8817e4Smiod extern const inst crx_instruction[]; 364*3d8817e4Smiod extern const int crx_num_opcodes; 365*3d8817e4Smiod #define NUMOPCODES crx_num_opcodes 366*3d8817e4Smiod 367*3d8817e4Smiod /* CRX operands table. */ 368*3d8817e4Smiod extern const operand_entry crx_optab[]; 369*3d8817e4Smiod 370*3d8817e4Smiod /* CRX registers table. */ 371*3d8817e4Smiod extern const reg_entry crx_regtab[]; 372*3d8817e4Smiod extern const int crx_num_regs; 373*3d8817e4Smiod #define NUMREGS crx_num_regs 374*3d8817e4Smiod 375*3d8817e4Smiod /* CRX coprocessor registers table. */ 376*3d8817e4Smiod extern const reg_entry crx_copregtab[]; 377*3d8817e4Smiod extern const int crx_num_copregs; 378*3d8817e4Smiod #define NUMCOPREGS crx_num_copregs 379*3d8817e4Smiod 380*3d8817e4Smiod /* CRX trap/interrupt table. */ 381*3d8817e4Smiod extern const trap_entry crx_traps[]; 382*3d8817e4Smiod extern const int crx_num_traps; 383*3d8817e4Smiod #define NUMTRAPS crx_num_traps 384*3d8817e4Smiod 385*3d8817e4Smiod /* cst4 operand mapping. */ 386*3d8817e4Smiod extern const long cst4_map[]; 387*3d8817e4Smiod extern const int cst4_maps; 388*3d8817e4Smiod 389*3d8817e4Smiod /* Table of instructions with no operands. */ 390*3d8817e4Smiod extern const char* no_op_insn[]; 391*3d8817e4Smiod 392*3d8817e4Smiod /* Current instruction we're assembling. */ 393*3d8817e4Smiod extern const inst *instruction; 394*3d8817e4Smiod 395*3d8817e4Smiod /* A macro for representing the instruction "constant" opcode, that is, 396*3d8817e4Smiod the FIXED part of the instruction. The "constant" opcode is represented 397*3d8817e4Smiod as a 32-bit unsigned long, where OPC is expanded (by a left SHIFT) 398*3d8817e4Smiod over that range. */ 399*3d8817e4Smiod #define BIN(OPC,SHIFT) (OPC << SHIFT) 400*3d8817e4Smiod 401*3d8817e4Smiod /* Is the current instruction type is TYPE ? */ 402*3d8817e4Smiod #define IS_INSN_TYPE(TYPE) \ 403*3d8817e4Smiod (CRX_INS_TYPE(instruction->flags) == TYPE) 404*3d8817e4Smiod 405*3d8817e4Smiod /* Is the current instruction mnemonic is MNEMONIC ? */ 406*3d8817e4Smiod #define IS_INSN_MNEMONIC(MNEMONIC) \ 407*3d8817e4Smiod (strcmp(instruction->mnemonic,MNEMONIC) == 0) 408*3d8817e4Smiod 409*3d8817e4Smiod /* Does the current instruction has register list ? */ 410*3d8817e4Smiod #define INST_HAS_REG_LIST \ 411*3d8817e4Smiod (instruction->flags & REG_LIST) 412*3d8817e4Smiod 413*3d8817e4Smiod /* Long long type handling. */ 414*3d8817e4Smiod /* Replace all appearances of 'long long int' with LONGLONG. */ 415*3d8817e4Smiod typedef long long int LONGLONG; 416*3d8817e4Smiod typedef unsigned long long ULONGLONG; 417*3d8817e4Smiod 418*3d8817e4Smiod #endif /* _CRX_H_ */ 419