175fd0b74Schristos /* d30v.h -- Header file for D30V opcode table 2*e992f068Schristos Copyright (C) 1997-2022 Free Software Foundation, Inc. 375fd0b74Schristos Written by Martin Hunt (hunt@cygnus.com), Cygnus Solutions 475fd0b74Schristos 575fd0b74Schristos This file is part of GDB, GAS, and the GNU binutils. 675fd0b74Schristos 775fd0b74Schristos GDB, GAS, and the GNU binutils are free software; you can redistribute 875fd0b74Schristos them and/or modify them under the terms of the GNU General Public 975fd0b74Schristos License as published by the Free Software Foundation; either version 3, 1075fd0b74Schristos or (at your option) any later version. 1175fd0b74Schristos 1275fd0b74Schristos GDB, GAS, and the GNU binutils are distributed in the hope that they 1375fd0b74Schristos will be useful, but WITHOUT ANY WARRANTY; without even the implied 1475fd0b74Schristos warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 1575fd0b74Schristos the GNU General Public License for more details. 1675fd0b74Schristos 1775fd0b74Schristos You should have received a copy of the GNU General Public License 1875fd0b74Schristos along with this file; see the file COPYING3. If not, write to the Free 1975fd0b74Schristos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, 2075fd0b74Schristos MA 02110-1301, USA. */ 2175fd0b74Schristos 2275fd0b74Schristos #ifndef D30V_H 2375fd0b74Schristos #define D30V_H 2475fd0b74Schristos 2575fd0b74Schristos #ifdef __cplusplus 2675fd0b74Schristos extern "C" { 2775fd0b74Schristos #endif 2875fd0b74Schristos 2975fd0b74Schristos #define NOP 0x00F00000 3075fd0b74Schristos 3175fd0b74Schristos /* Structure to hold information about predefined registers. */ 3275fd0b74Schristos struct pd_reg 3375fd0b74Schristos { 3475fd0b74Schristos char *name; /* name to recognize */ 3575fd0b74Schristos char *pname; /* name to print for this register */ 36*e992f068Schristos unsigned int value; 3775fd0b74Schristos }; 3875fd0b74Schristos 3975fd0b74Schristos extern const struct pd_reg pre_defined_registers[]; 4075fd0b74Schristos int reg_name_cnt (void); 4175fd0b74Schristos 4275fd0b74Schristos /* the number of control registers */ 4375fd0b74Schristos #define MAX_CONTROL_REG 64 4475fd0b74Schristos 4575fd0b74Schristos /* define the format specifiers */ 4675fd0b74Schristos #define FM00 0 4775fd0b74Schristos #define FM01 0x80000000 4875fd0b74Schristos #define FM10 0x8000000000000000LL 4975fd0b74Schristos #define FM11 0x8000000080000000LL 5075fd0b74Schristos 5175fd0b74Schristos /* define the opcode classes */ 5275fd0b74Schristos #define BRA 0 5375fd0b74Schristos #define LOGIC 1 5475fd0b74Schristos #define IMEM 2 5575fd0b74Schristos #define IALU1 4 5675fd0b74Schristos #define IALU2 5 5775fd0b74Schristos 5875fd0b74Schristos /* define the execution condition codes */ 5975fd0b74Schristos #define ECC_AL 0 /* ALways (default) */ 6075fd0b74Schristos #define ECC_TX 1 /* F0=True, F1=Don't care */ 6175fd0b74Schristos #define ECC_FX 2 /* F0=False, F1=Don't care */ 6275fd0b74Schristos #define ECC_XT 3 /* F0=Don't care, F1=True */ 6375fd0b74Schristos #define ECC_XF 4 /* F0=Don't care, F1=False */ 6475fd0b74Schristos #define ECC_TT 5 /* F0=True, F1=True */ 6575fd0b74Schristos #define ECC_TF 6 /* F0=True, F1=False */ 6675fd0b74Schristos #define ECC_RESERVED 7 /* reserved */ 6775fd0b74Schristos #define ECC_MAX ECC_RESERVED 6875fd0b74Schristos 6975fd0b74Schristos extern const char *d30v_ecc_names[]; 7075fd0b74Schristos 7175fd0b74Schristos /* condition code table for CMP and CMPU */ 7275fd0b74Schristos extern const char *d30v_cc_names[]; 7375fd0b74Schristos 7475fd0b74Schristos /* The opcode table is an array of struct d30v_opcode. */ 7575fd0b74Schristos struct d30v_opcode 7675fd0b74Schristos { 7775fd0b74Schristos /* The opcode name. */ 7875fd0b74Schristos const char *name; 7975fd0b74Schristos 8075fd0b74Schristos /* the opcode */ 8175fd0b74Schristos int op1; /* first part, "IALU1" for example */ 8275fd0b74Schristos int op2; /* the rest of the opcode */ 8375fd0b74Schristos 8475fd0b74Schristos /* opcode format(s). These numbers correspond to entries */ 8575fd0b74Schristos /* in the d30v_format_table */ 8675fd0b74Schristos unsigned char format[4]; 8775fd0b74Schristos 8875fd0b74Schristos #define SHORT_M 1 8975fd0b74Schristos #define SHORT_M2 5 /* for ld2w and st2w */ 9075fd0b74Schristos #define SHORT_A 9 9175fd0b74Schristos #define SHORT_B1 11 9275fd0b74Schristos #define SHORT_B2 12 9375fd0b74Schristos #define SHORT_B2r 13 9475fd0b74Schristos #define SHORT_B3 14 9575fd0b74Schristos #define SHORT_B3r 16 9675fd0b74Schristos #define SHORT_B3b 18 9775fd0b74Schristos #define SHORT_B3br 20 9875fd0b74Schristos #define SHORT_D1r 22 9975fd0b74Schristos #define SHORT_D2 24 10075fd0b74Schristos #define SHORT_D2r 26 10175fd0b74Schristos #define SHORT_D2Br 28 10275fd0b74Schristos #define SHORT_U 30 /* unary SHORT_A. ABS for example */ 10375fd0b74Schristos #define SHORT_F 31 /* SHORT_A with flag registers */ 10475fd0b74Schristos #define SHORT_AF 33 /* SHORT_A with only the first register a flag register */ 10575fd0b74Schristos #define SHORT_T 35 /* for trap instruction */ 10675fd0b74Schristos #define SHORT_A5 36 /* SHORT_A with a 5-bit immediate instead of 6 */ 10775fd0b74Schristos #define SHORT_CMP 38 /* special form for CMPcc */ 10875fd0b74Schristos #define SHORT_CMPU 40 /* special form for CMPUcc */ 10975fd0b74Schristos #define SHORT_A1 42 /* special form of SHORT_A for MACa opcodes where a=1 */ 11075fd0b74Schristos #define SHORT_AA 44 /* SHORT_A with the first register an accumulator */ 11175fd0b74Schristos #define SHORT_RA 46 /* SHORT_A with the second register an accumulator */ 11275fd0b74Schristos #define SHORT_MODINC 48 11375fd0b74Schristos #define SHORT_MODDEC 49 11475fd0b74Schristos #define SHORT_C1 50 11575fd0b74Schristos #define SHORT_C2 51 11675fd0b74Schristos #define SHORT_UF 52 11775fd0b74Schristos #define SHORT_A2 53 11875fd0b74Schristos #define SHORT_NONE 55 /* no operands */ 11975fd0b74Schristos #define SHORT_AR 56 /* like SHORT_AA but only accept register as third parameter */ 12075fd0b74Schristos #define LONG 57 12175fd0b74Schristos #define LONG_U 58 /* unary LONG */ 12275fd0b74Schristos #define LONG_Ur 59 /* LONG pc-relative */ 12375fd0b74Schristos #define LONG_CMP 60 /* special form for CMPcc and CMPUcc */ 12475fd0b74Schristos #define LONG_M 61 /* Memory long for ldb, stb */ 12575fd0b74Schristos #define LONG_M2 62 /* Memory long for ld2w, st2w */ 12675fd0b74Schristos #define LONG_2 63 /* LONG with 2 operands; jmptnz */ 12775fd0b74Schristos #define LONG_2r 64 /* LONG with 2 operands; bratnz */ 12875fd0b74Schristos #define LONG_2b 65 /* LONG_2 with modifier of 3 */ 12975fd0b74Schristos #define LONG_2br 66 /* LONG_2r with modifier of 3 */ 13075fd0b74Schristos #define LONG_D 67 /* for DJMPI */ 13175fd0b74Schristos #define LONG_Dr 68 /* for DBRAI */ 13275fd0b74Schristos #define LONG_Dbr 69 /* for repeati */ 13375fd0b74Schristos 13475fd0b74Schristos /* the execution unit(s) used */ 13575fd0b74Schristos int unit; 13675fd0b74Schristos #define EITHER 0 13775fd0b74Schristos #define IU 1 13875fd0b74Schristos #define MU 2 13975fd0b74Schristos #define EITHER_BUT_PREFER_MU 3 14075fd0b74Schristos 14175fd0b74Schristos /* this field is used to decide if two instructions */ 14275fd0b74Schristos /* can be executed in parallel */ 14375fd0b74Schristos long flags_used; 14475fd0b74Schristos long flags_set; 14575fd0b74Schristos #define FLAG_0 (1L<<0) 14675fd0b74Schristos #define FLAG_1 (1L<<1) 14775fd0b74Schristos #define FLAG_2 (1L<<2) 14875fd0b74Schristos #define FLAG_3 (1L<<3) 14975fd0b74Schristos #define FLAG_4 (1L<<4) /* S (saturation) */ 15075fd0b74Schristos #define FLAG_5 (1L<<5) /* V (overflow) */ 15175fd0b74Schristos #define FLAG_6 (1L<<6) /* VA (accumulated overflow) */ 15275fd0b74Schristos #define FLAG_7 (1L<<7) /* C (carry/borrow) */ 15375fd0b74Schristos #define FLAG_SM (1L<<8) /* SM (stack mode) */ 15475fd0b74Schristos #define FLAG_RP (1L<<9) /* RP (repeat enable) */ 15575fd0b74Schristos #define FLAG_CONTROL (1L<<10) /* control registers */ 15675fd0b74Schristos #define FLAG_A0 (1L<<11) /* A0 */ 15775fd0b74Schristos #define FLAG_A1 (1L<<12) /* A1 */ 15875fd0b74Schristos #define FLAG_JMP (1L<<13) /* instruction is a branch */ 15975fd0b74Schristos #define FLAG_JSR (1L<<14) /* subroutine call. must be aligned */ 16075fd0b74Schristos #define FLAG_MEM (1L<<15) /* reads/writes memory */ 16175fd0b74Schristos #define FLAG_NOT_WITH_ADDSUBppp (1L<<16) /* Old meaning: a 2 word 4 byter operation 16275fd0b74Schristos New meaning: operation cannot be 16375fd0b74Schristos combined in parallel with ADD/SUBppp. */ 16475fd0b74Schristos #define FLAG_MUL16 (1L<<17) /* 16 bit multiply */ 16575fd0b74Schristos #define FLAG_MUL32 (1L<<18) /* 32 bit multiply */ 16675fd0b74Schristos #define FLAG_ADDSUBppp (1L<<19) /* ADDppp or SUBppp */ 16775fd0b74Schristos #define FLAG_DELAY (1L<<20) /* This is a delayed branch or jump */ 16875fd0b74Schristos #define FLAG_LKR (1L<<21) /* insn in left slot kills right slot */ 16975fd0b74Schristos #define FLAG_CVVA (FLAG_5|FLAG_6|FLAG_7) 17075fd0b74Schristos #define FLAG_C FLAG_7 17175fd0b74Schristos #define FLAG_ALL (FLAG_0 | \ 17275fd0b74Schristos FLAG_1 | \ 17375fd0b74Schristos FLAG_2 | \ 17475fd0b74Schristos FLAG_3 | \ 17575fd0b74Schristos FLAG_4 | \ 17675fd0b74Schristos FLAG_5 | \ 17775fd0b74Schristos FLAG_6 | \ 17875fd0b74Schristos FLAG_7 | \ 17975fd0b74Schristos FLAG_SM | \ 18075fd0b74Schristos FLAG_RP | \ 18175fd0b74Schristos FLAG_CONTROL) 18275fd0b74Schristos 18375fd0b74Schristos int reloc_flag; 18475fd0b74Schristos #define RELOC_PCREL 1 18575fd0b74Schristos #define RELOC_ABS 2 18675fd0b74Schristos }; 18775fd0b74Schristos 18875fd0b74Schristos extern const struct d30v_opcode d30v_opcode_table[]; 18975fd0b74Schristos extern const int d30v_num_opcodes; 19075fd0b74Schristos 19175fd0b74Schristos /* The operands table is an array of struct d30v_operand. */ 19275fd0b74Schristos struct d30v_operand 19375fd0b74Schristos { 19475fd0b74Schristos /* the length of the field */ 19575fd0b74Schristos int length; 19675fd0b74Schristos 19775fd0b74Schristos /* The number of significant bits in the operand. */ 19875fd0b74Schristos int bits; 19975fd0b74Schristos 20075fd0b74Schristos /* position relative to Ra */ 20175fd0b74Schristos int position; 20275fd0b74Schristos 20375fd0b74Schristos /* syntax flags. */ 20475fd0b74Schristos long flags; 20575fd0b74Schristos }; 20675fd0b74Schristos extern const struct d30v_operand d30v_operand_table[]; 20775fd0b74Schristos 20875fd0b74Schristos /* Values defined for the flags field of a struct d30v_operand. */ 20975fd0b74Schristos 21075fd0b74Schristos /* this is the destination register; it will be modified */ 21175fd0b74Schristos /* this is used by the optimizer */ 21275fd0b74Schristos #define OPERAND_DEST (1) 21375fd0b74Schristos 21475fd0b74Schristos /* number or symbol */ 21575fd0b74Schristos #define OPERAND_NUM (2) 21675fd0b74Schristos 21775fd0b74Schristos /* address or label */ 21875fd0b74Schristos #define OPERAND_ADDR (4) 21975fd0b74Schristos 22075fd0b74Schristos /* register */ 22175fd0b74Schristos #define OPERAND_REG (8) 22275fd0b74Schristos 22375fd0b74Schristos /* postincrement + */ 22475fd0b74Schristos #define OPERAND_PLUS (0x10) 22575fd0b74Schristos 22675fd0b74Schristos /* postdecrement - */ 22775fd0b74Schristos #define OPERAND_MINUS (0x20) 22875fd0b74Schristos 22975fd0b74Schristos /* signed number */ 23075fd0b74Schristos #define OPERAND_SIGNED (0x40) 23175fd0b74Schristos 23275fd0b74Schristos /* this operand must be shifted left by 3 */ 23375fd0b74Schristos #define OPERAND_SHIFT (0x80) 23475fd0b74Schristos 23575fd0b74Schristos /* flag register */ 23675fd0b74Schristos #define OPERAND_FLAG (0x100) 23775fd0b74Schristos 23875fd0b74Schristos /* control register */ 23975fd0b74Schristos #define OPERAND_CONTROL (0x200) 24075fd0b74Schristos 24175fd0b74Schristos /* accumulator */ 24275fd0b74Schristos #define OPERAND_ACC (0x400) 24375fd0b74Schristos 24475fd0b74Schristos /* @ */ 24575fd0b74Schristos #define OPERAND_ATSIGN (0x800) 24675fd0b74Schristos 24775fd0b74Schristos /* @( */ 24875fd0b74Schristos #define OPERAND_ATPAR (0x1000) 24975fd0b74Schristos 25075fd0b74Schristos /* predecrement mode '@-sp' */ 25175fd0b74Schristos #define OPERAND_ATMINUS (0x2000) 25275fd0b74Schristos 25375fd0b74Schristos /* this operand changes the instruction name */ 25475fd0b74Schristos /* for example, CPMcc, CMPUcc */ 25575fd0b74Schristos #define OPERAND_NAME (0x4000) 25675fd0b74Schristos 25775fd0b74Schristos /* fake operand for mvtsys and mvfsys */ 25875fd0b74Schristos #define OPERAND_SPECIAL (0x8000) 25975fd0b74Schristos 26075fd0b74Schristos /* let the optimizer know that two registers are affected */ 26175fd0b74Schristos #define OPERAND_2REG (0x10000) 26275fd0b74Schristos 26375fd0b74Schristos /* This operand is pc-relative. Note that repeati can have two immediate 26475fd0b74Schristos operands, one of which is pcrel, the other (the IMM6U one) is not. */ 26575fd0b74Schristos #define OPERAND_PCREL (0x20000) 26675fd0b74Schristos 26775fd0b74Schristos /* The format table is an array of struct d30v_format. */ 26875fd0b74Schristos struct d30v_format 26975fd0b74Schristos { 27075fd0b74Schristos int form; /* SHORT_A, LONG, etc */ 27175fd0b74Schristos int modifier; /* two bit modifier following opcode */ 27275fd0b74Schristos unsigned char operands[5]; 27375fd0b74Schristos }; 27475fd0b74Schristos extern const struct d30v_format d30v_format_table[]; 27575fd0b74Schristos 27675fd0b74Schristos 27775fd0b74Schristos /* an instruction is defined by an opcode and a format */ 27875fd0b74Schristos /* for example, "add" has one opcode, but three different */ 27975fd0b74Schristos /* formats, 2 SHORT_A forms and a LONG form. */ 28075fd0b74Schristos struct d30v_insn 28175fd0b74Schristos { 28275fd0b74Schristos struct d30v_opcode *op; /* pointer to an entry in the opcode table */ 28375fd0b74Schristos struct d30v_format *form; /* pointer to an entry in the format table */ 28475fd0b74Schristos int ecc; /* execution condition code */ 28575fd0b74Schristos }; 28675fd0b74Schristos 28775fd0b74Schristos /* an expressionS only has one register type, so we fake it */ 28875fd0b74Schristos /* by setting high bits to indicate type */ 28975fd0b74Schristos #define REGISTER_MASK 0xFF 29075fd0b74Schristos 29175fd0b74Schristos #ifdef __cplusplus 29275fd0b74Schristos } 29375fd0b74Schristos #endif 29475fd0b74Schristos 29575fd0b74Schristos #endif /* D30V_H */ 296