1a1ba9ba4Schristos /* v850.h -- Header file for NEC V850 opcode table 2*184b2d41Schristos Copyright (C) 1996-2020 Free Software Foundation, Inc. 3a1ba9ba4Schristos Written by J.T. Conklin, Cygnus Support 4a1ba9ba4Schristos 5a1ba9ba4Schristos This file is part of GDB, GAS, and the GNU binutils. 6a1ba9ba4Schristos 7a1ba9ba4Schristos GDB, GAS, and the GNU binutils are free software; you can redistribute 8a1ba9ba4Schristos them and/or modify them under the terms of the GNU General Public 9a1ba9ba4Schristos License as published by the Free Software Foundation; either version 3, 10a1ba9ba4Schristos or (at your option) any later version. 11a1ba9ba4Schristos 12a1ba9ba4Schristos GDB, GAS, and the GNU binutils are distributed in the hope that they 13a1ba9ba4Schristos will be useful, but WITHOUT ANY WARRANTY; without even the implied 14a1ba9ba4Schristos warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15a1ba9ba4Schristos the GNU General Public License for more details. 16a1ba9ba4Schristos 17a1ba9ba4Schristos You should have received a copy of the GNU General Public License 18a1ba9ba4Schristos along with this file; see the file COPYING3. If not, write to the Free 19a1ba9ba4Schristos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, 20a1ba9ba4Schristos MA 02110-1301, USA. */ 21a1ba9ba4Schristos 22a1ba9ba4Schristos #ifndef V850_H 23a1ba9ba4Schristos #define V850_H 24a1ba9ba4Schristos 25b2396a7bSchristos #ifdef __cplusplus 26b2396a7bSchristos extern "C" { 27b2396a7bSchristos #endif 28b2396a7bSchristos 29a1ba9ba4Schristos /* The opcode table is an array of struct v850_opcode. */ 30a1ba9ba4Schristos 31a1ba9ba4Schristos struct v850_opcode 32a1ba9ba4Schristos { 33a1ba9ba4Schristos /* The opcode name. */ 34a1ba9ba4Schristos const char *name; 35a1ba9ba4Schristos 36a1ba9ba4Schristos /* The opcode itself. Those bits which will be filled in with 37a1ba9ba4Schristos operands are zeroes. */ 38a1ba9ba4Schristos unsigned long opcode; 39a1ba9ba4Schristos 40a1ba9ba4Schristos /* The opcode mask. This is used by the disassembler. This is a 41a1ba9ba4Schristos mask containing ones indicating those bits which must match the 42a1ba9ba4Schristos opcode field, and zeroes indicating those bits which need not 43a1ba9ba4Schristos match (and are presumably filled in by operands). */ 44a1ba9ba4Schristos unsigned long mask; 45a1ba9ba4Schristos 46a1ba9ba4Schristos /* An array of operand codes. Each code is an index into the 47a1ba9ba4Schristos operand table. They appear in the order which the operands must 48a1ba9ba4Schristos appear in assembly code, and are terminated by a zero. */ 49a1ba9ba4Schristos unsigned char operands[8]; 50a1ba9ba4Schristos 51a1ba9ba4Schristos /* Which (if any) operand is a memory operand. */ 52a1ba9ba4Schristos unsigned int memop; 53a1ba9ba4Schristos 54a1ba9ba4Schristos /* Target processor(s). A bit field of processors which support 55a1ba9ba4Schristos this instruction. Note a bit field is used as some instructions 56a1ba9ba4Schristos are available on multiple, different processor types, whereas 57a1ba9ba4Schristos other instructions are only available on one specific type. */ 58a1ba9ba4Schristos unsigned int processors; 59a1ba9ba4Schristos }; 60a1ba9ba4Schristos 61a1ba9ba4Schristos /* Values for architecture number. */ 62a1ba9ba4Schristos #define arch_V850 0 63a1ba9ba4Schristos #define arch_V850E (arch_V850 + 1) 64a1ba9ba4Schristos #define arch_V850E1 (arch_V850E + 1) 65a1ba9ba4Schristos #define arch_V850E2 (arch_V850E1 + 1) 66a1ba9ba4Schristos #define arch_V850E2V3 (arch_V850E2 + 1) 67a1ba9ba4Schristos #define arch_V850E3V5 (arch_V850E2V3 + 1) 68a1ba9ba4Schristos #define arch_separator (arch_V850E3V5 + 1) 69a1ba9ba4Schristos 70a1ba9ba4Schristos #define opt_EXTENSION (arch_separator) 71a1ba9ba4Schristos #define opt_ALIAS (opt_EXTENSION + 1) 72a1ba9ba4Schristos 73a1ba9ba4Schristos /* Values for the processors field in the v850_opcode structure. */ 74a1ba9ba4Schristos #define PROCESSOR_V850 (1 << (arch_V850)) /* Just the V850. */ 75a1ba9ba4Schristos #define PROCESSOR_V850E (1 << (arch_V850E)) /* Just the V850E. */ 76a1ba9ba4Schristos #define PROCESSOR_V850E1 (1 << (arch_V850E1)) /* Just the V850E1. */ 77a1ba9ba4Schristos #define PROCESSOR_V850E2 (1 << (arch_V850E2)) /* Just the V850E2. */ 78a1ba9ba4Schristos #define PROCESSOR_V850E2V3 (1 << (arch_V850E2V3)) /* Just the V850E2V3. */ 79a1ba9ba4Schristos #define PROCESSOR_V850E3V5 (1 << (arch_V850E3V5)) /* Just the V850E3V5. */ 80a1ba9ba4Schristos 81a1ba9ba4Schristos /* UPPERS */ 82a1ba9ba4Schristos #define PROCESSOR_V850E3V5_UP (PROCESSOR_V850E3V5) 83a1ba9ba4Schristos #define PROCESSOR_V850E2V3_UP (PROCESSOR_V850E2V3 | PROCESSOR_V850E3V5_UP) 84a1ba9ba4Schristos #define PROCESSOR_V850E2_UP (PROCESSOR_V850E2 | PROCESSOR_V850E2V3_UP) 85a1ba9ba4Schristos #define PROCESSOR_V850E_UP (PROCESSOR_V850E | PROCESSOR_V850E1 | PROCESSOR_V850E2_UP) 86a1ba9ba4Schristos #define PROCESSOR_ALL (PROCESSOR_V850 | PROCESSOR_V850E_UP) 87a1ba9ba4Schristos 88a1ba9ba4Schristos #define PROCESSOR_MASK (PROCESSOR_ALL) 89a1ba9ba4Schristos #define PROCESSOR_NOT_V850 (PROCESSOR_ALL & (~ PROCESSOR_V850)) /* Any processor except the V850. */ 90a1ba9ba4Schristos 91a1ba9ba4Schristos #define PROCESSOR_UNKNOWN ~(PROCESSOR_MASK) 92a1ba9ba4Schristos 93a1ba9ba4Schristos /* OPTIONS */ 94a1ba9ba4Schristos #define PROCESSOR_OPTION_EXTENSION (1 << (opt_EXTENSION)) /* Enable extension opcodes. */ 95a1ba9ba4Schristos #define PROCESSOR_OPTION_ALIAS (1 << (opt_ALIAS)) /* Enable alias opcodes. */ 96a1ba9ba4Schristos 97a1ba9ba4Schristos #define SET_PROCESSOR_MASK(mask,set) ((mask) = ((mask) & ~PROCESSOR_MASK) | (set)) 98a1ba9ba4Schristos 99a1ba9ba4Schristos /* The table itself is sorted by major opcode number, and is otherwise 100a1ba9ba4Schristos in the order in which the disassembler should consider 101a1ba9ba4Schristos instructions. */ 102a1ba9ba4Schristos extern const struct v850_opcode v850_opcodes[]; 103a1ba9ba4Schristos extern const int v850_num_opcodes; 104a1ba9ba4Schristos 105a1ba9ba4Schristos 106a1ba9ba4Schristos /* The operands table is an array of struct v850_operand. */ 107a1ba9ba4Schristos 108a1ba9ba4Schristos struct v850_operand 109a1ba9ba4Schristos { 110a1ba9ba4Schristos /* The number of bits in the operand. */ 111a1ba9ba4Schristos /* If this value is -1 then the operand's bits are in a discontinous 112a1ba9ba4Schristos distribution in the instruction. */ 113a1ba9ba4Schristos int bits; 114a1ba9ba4Schristos 115a1ba9ba4Schristos /* (bits >= 0): How far the operand is left shifted in the instruction. */ 116a1ba9ba4Schristos /* (bits == -1): Bit mask of the bits in the operand. */ 117a1ba9ba4Schristos int shift; 118a1ba9ba4Schristos 119a1ba9ba4Schristos /* Insertion function. This is used by the assembler. To insert an 120a1ba9ba4Schristos operand value into an instruction, check this field. 121a1ba9ba4Schristos 122a1ba9ba4Schristos If it is NULL, execute 123a1ba9ba4Schristos i |= (op & ((1 << o->bits) - 1)) << o->shift; 124a1ba9ba4Schristos (i is the instruction which we are filling in, o is a pointer to 125a1ba9ba4Schristos this structure, and op is the opcode value; this assumes twos 126a1ba9ba4Schristos complement arithmetic). 127a1ba9ba4Schristos 128a1ba9ba4Schristos If this field is not NULL, then simply call it with the 129a1ba9ba4Schristos instruction and the operand value. It will return the new value 130a1ba9ba4Schristos of the instruction. If the ERRMSG argument is not NULL, then if 131a1ba9ba4Schristos the operand value is illegal, *ERRMSG will be set to a warning 132a1ba9ba4Schristos string (the operand will be inserted in any case). If the 133a1ba9ba4Schristos operand value is legal, *ERRMSG will be unchanged (most operands 134a1ba9ba4Schristos can accept any value). */ 135a1ba9ba4Schristos unsigned long (* insert) 136*184b2d41Schristos (unsigned long instruction, unsigned long op, const char ** errmsg); 137a1ba9ba4Schristos 138a1ba9ba4Schristos /* Extraction function. This is used by the disassembler. To 139a1ba9ba4Schristos extract this operand type from an instruction, check this field. 140a1ba9ba4Schristos 141a1ba9ba4Schristos If it is NULL, compute 142a1ba9ba4Schristos op = o->bits == -1 ? ((i) & o->shift) : ((i) >> o->shift) & ((1 << o->bits) - 1); 143a1ba9ba4Schristos if (o->flags & V850_OPERAND_SIGNED) 144a1ba9ba4Schristos op = (op << (32 - o->bits)) >> (32 - o->bits); 145a1ba9ba4Schristos (i is the instruction, o is a pointer to this structure, and op 146a1ba9ba4Schristos is the result; this assumes twos complement arithmetic). 147a1ba9ba4Schristos 148a1ba9ba4Schristos If this field is not NULL, then simply call it with the 149a1ba9ba4Schristos instruction value. It will return the value of the operand. If 150a1ba9ba4Schristos the INVALID argument is not NULL, *INVALID will be set to 151a1ba9ba4Schristos non-zero if this operand type can not actually be extracted from 152a1ba9ba4Schristos this operand (i.e., the instruction does not match). If the 153a1ba9ba4Schristos operand is valid, *INVALID will not be changed. */ 154a1ba9ba4Schristos unsigned long (* extract) (unsigned long instruction, int * invalid); 155a1ba9ba4Schristos 156a1ba9ba4Schristos /* One bit syntax flags. */ 157a1ba9ba4Schristos int flags; 158a1ba9ba4Schristos 159a1ba9ba4Schristos int default_reloc; 160a1ba9ba4Schristos }; 161a1ba9ba4Schristos 162a1ba9ba4Schristos /* Elements in the table are retrieved by indexing with values from 163a1ba9ba4Schristos the operands field of the v850_opcodes table. */ 164a1ba9ba4Schristos 165a1ba9ba4Schristos extern const struct v850_operand v850_operands[]; 166a1ba9ba4Schristos 167a1ba9ba4Schristos /* Values defined for the flags field of a struct v850_operand. */ 168a1ba9ba4Schristos 169a1ba9ba4Schristos /* This operand names a general purpose register. */ 170a1ba9ba4Schristos #define V850_OPERAND_REG 0x01 171a1ba9ba4Schristos 172a1ba9ba4Schristos /* This operand is the ep register. */ 173a1ba9ba4Schristos #define V850_OPERAND_EP 0x02 174a1ba9ba4Schristos 175a1ba9ba4Schristos /* This operand names a system register. */ 176a1ba9ba4Schristos #define V850_OPERAND_SRG 0x04 177a1ba9ba4Schristos 178a1ba9ba4Schristos /* Prologue eilogue type instruction, V850E specific. */ 179a1ba9ba4Schristos #define V850E_OPERAND_REG_LIST 0x08 180a1ba9ba4Schristos 181a1ba9ba4Schristos /* This operand names a condition code used in the setf instruction. */ 182a1ba9ba4Schristos #define V850_OPERAND_CC 0x10 183a1ba9ba4Schristos 184a1ba9ba4Schristos #define V850_OPERAND_FLOAT_CC 0x20 185a1ba9ba4Schristos 186a1ba9ba4Schristos /* This operand names a vector purpose register. */ 187a1ba9ba4Schristos #define V850_OPERAND_VREG 0x40 188a1ba9ba4Schristos 189a1ba9ba4Schristos /* 16 bit immediate follows instruction, V850E specific. */ 190a1ba9ba4Schristos #define V850E_IMMEDIATE16 0x80 191a1ba9ba4Schristos 192a1ba9ba4Schristos /* hi16 bit immediate follows instruction, V850E specific. */ 193a1ba9ba4Schristos #define V850E_IMMEDIATE16HI 0x100 194a1ba9ba4Schristos 195a1ba9ba4Schristos /* 23 bit immediate follows instruction, V850E specific. */ 196a1ba9ba4Schristos #define V850E_IMMEDIATE23 0x200 197a1ba9ba4Schristos 198a1ba9ba4Schristos /* 32 bit immediate follows instruction, V850E specific. */ 199a1ba9ba4Schristos #define V850E_IMMEDIATE32 0x400 200a1ba9ba4Schristos 201a1ba9ba4Schristos /* This is a relaxable operand. Only used for D9->D22 branch relaxing 202a1ba9ba4Schristos right now. We may need others in the future (or maybe handle them like 203a1ba9ba4Schristos promoted operands on the mn10300?). */ 204a1ba9ba4Schristos #define V850_OPERAND_RELAX 0x800 205a1ba9ba4Schristos 206a1ba9ba4Schristos /* This operand takes signed values. */ 207a1ba9ba4Schristos #define V850_OPERAND_SIGNED 0x1000 208a1ba9ba4Schristos 209a1ba9ba4Schristos /* This operand is a displacement. */ 210a1ba9ba4Schristos #define V850_OPERAND_DISP 0x2000 211a1ba9ba4Schristos 212a1ba9ba4Schristos /* This operand is a PC displacement. */ 213a1ba9ba4Schristos #define V850_PCREL 0x4000 214a1ba9ba4Schristos 215a1ba9ba4Schristos /* The register specified must be even number. */ 216a1ba9ba4Schristos #define V850_REG_EVEN 0x8000 217a1ba9ba4Schristos 218a1ba9ba4Schristos /* The register specified must not be r0. */ 219a1ba9ba4Schristos #define V850_NOT_R0 0x20000 220a1ba9ba4Schristos 221a1ba9ba4Schristos /* The register specified must not be 0. */ 222a1ba9ba4Schristos #define V850_NOT_IMM0 0x40000 223a1ba9ba4Schristos 224a1ba9ba4Schristos /* The condition code must not be SA CONDITION. */ 225a1ba9ba4Schristos #define V850_NOT_SA 0x80000 226a1ba9ba4Schristos 227a1ba9ba4Schristos /* The operand has '!' prefix. */ 228a1ba9ba4Schristos #define V850_OPERAND_BANG 0x100000 229a1ba9ba4Schristos 230a1ba9ba4Schristos /* The operand has '%' prefix. */ 231a1ba9ba4Schristos #define V850_OPERAND_PERCENT 0x200000 232a1ba9ba4Schristos 233dc268d07Schristos /* This operand is a cache operation. */ 234a1ba9ba4Schristos #define V850_OPERAND_CACHEOP 0x400000 235a1ba9ba4Schristos 236dc268d07Schristos /* This operand is a prefetch operation. */ 237a1ba9ba4Schristos #define V850_OPERAND_PREFOP 0x800000 238a1ba9ba4Schristos 239a1ba9ba4Schristos /* A PC-relative displacement where a positive value indicates a backwards displacement. */ 240a1ba9ba4Schristos #define V850_INVERSE_PCREL 0x1000000 241a1ba9ba4Schristos 242a1ba9ba4Schristos extern int v850_msg_is_out_of_range (const char *); 243a1ba9ba4Schristos 244b2396a7bSchristos #ifdef __cplusplus 245b2396a7bSchristos } 246b2396a7bSchristos #endif 247b2396a7bSchristos 248a1ba9ba4Schristos #endif /* V850_H */ 249