175fd0b74Schristos /* v850.h -- Header file for NEC V850 opcode table 2*e992f068Schristos Copyright (C) 1996-2022 Free Software Foundation, Inc. 375fd0b74Schristos Written by J.T. Conklin, Cygnus Support 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 V850_H 2375fd0b74Schristos #define V850_H 2475fd0b74Schristos 2575fd0b74Schristos #ifdef __cplusplus 2675fd0b74Schristos extern "C" { 2775fd0b74Schristos #endif 2875fd0b74Schristos 2975fd0b74Schristos /* The opcode table is an array of struct v850_opcode. */ 3075fd0b74Schristos 3175fd0b74Schristos struct v850_opcode 3275fd0b74Schristos { 3375fd0b74Schristos /* The opcode name. */ 3475fd0b74Schristos const char *name; 3575fd0b74Schristos 3675fd0b74Schristos /* The opcode itself. Those bits which will be filled in with 3775fd0b74Schristos operands are zeroes. */ 3875fd0b74Schristos unsigned long opcode; 3975fd0b74Schristos 4075fd0b74Schristos /* The opcode mask. This is used by the disassembler. This is a 4175fd0b74Schristos mask containing ones indicating those bits which must match the 4275fd0b74Schristos opcode field, and zeroes indicating those bits which need not 4375fd0b74Schristos match (and are presumably filled in by operands). */ 4475fd0b74Schristos unsigned long mask; 4575fd0b74Schristos 4675fd0b74Schristos /* An array of operand codes. Each code is an index into the 4775fd0b74Schristos operand table. They appear in the order which the operands must 4875fd0b74Schristos appear in assembly code, and are terminated by a zero. */ 4975fd0b74Schristos unsigned char operands[8]; 5075fd0b74Schristos 5175fd0b74Schristos /* Which (if any) operand is a memory operand. */ 5275fd0b74Schristos unsigned int memop; 5375fd0b74Schristos 5475fd0b74Schristos /* Target processor(s). A bit field of processors which support 5575fd0b74Schristos this instruction. Note a bit field is used as some instructions 5675fd0b74Schristos are available on multiple, different processor types, whereas 5775fd0b74Schristos other instructions are only available on one specific type. */ 5875fd0b74Schristos unsigned int processors; 5975fd0b74Schristos }; 6075fd0b74Schristos 6175fd0b74Schristos /* Values for architecture number. */ 6275fd0b74Schristos #define arch_V850 0 6375fd0b74Schristos #define arch_V850E (arch_V850 + 1) 6475fd0b74Schristos #define arch_V850E1 (arch_V850E + 1) 6575fd0b74Schristos #define arch_V850E2 (arch_V850E1 + 1) 6675fd0b74Schristos #define arch_V850E2V3 (arch_V850E2 + 1) 6775fd0b74Schristos #define arch_V850E3V5 (arch_V850E2V3 + 1) 6875fd0b74Schristos #define arch_separator (arch_V850E3V5 + 1) 6975fd0b74Schristos 7075fd0b74Schristos #define opt_EXTENSION (arch_separator) 7175fd0b74Schristos #define opt_ALIAS (opt_EXTENSION + 1) 7275fd0b74Schristos 7375fd0b74Schristos /* Values for the processors field in the v850_opcode structure. */ 7475fd0b74Schristos #define PROCESSOR_V850 (1 << (arch_V850)) /* Just the V850. */ 7575fd0b74Schristos #define PROCESSOR_V850E (1 << (arch_V850E)) /* Just the V850E. */ 7675fd0b74Schristos #define PROCESSOR_V850E1 (1 << (arch_V850E1)) /* Just the V850E1. */ 7775fd0b74Schristos #define PROCESSOR_V850E2 (1 << (arch_V850E2)) /* Just the V850E2. */ 7875fd0b74Schristos #define PROCESSOR_V850E2V3 (1 << (arch_V850E2V3)) /* Just the V850E2V3. */ 7975fd0b74Schristos #define PROCESSOR_V850E3V5 (1 << (arch_V850E3V5)) /* Just the V850E3V5. */ 8075fd0b74Schristos 8175fd0b74Schristos /* UPPERS */ 8275fd0b74Schristos #define PROCESSOR_V850E3V5_UP (PROCESSOR_V850E3V5) 8375fd0b74Schristos #define PROCESSOR_V850E2V3_UP (PROCESSOR_V850E2V3 | PROCESSOR_V850E3V5_UP) 8475fd0b74Schristos #define PROCESSOR_V850E2_UP (PROCESSOR_V850E2 | PROCESSOR_V850E2V3_UP) 8575fd0b74Schristos #define PROCESSOR_V850E_UP (PROCESSOR_V850E | PROCESSOR_V850E1 | PROCESSOR_V850E2_UP) 8675fd0b74Schristos #define PROCESSOR_ALL (PROCESSOR_V850 | PROCESSOR_V850E_UP) 8775fd0b74Schristos 8875fd0b74Schristos #define PROCESSOR_MASK (PROCESSOR_ALL) 8975fd0b74Schristos #define PROCESSOR_NOT_V850 (PROCESSOR_ALL & (~ PROCESSOR_V850)) /* Any processor except the V850. */ 9075fd0b74Schristos 9175fd0b74Schristos #define PROCESSOR_UNKNOWN ~(PROCESSOR_MASK) 9275fd0b74Schristos 9375fd0b74Schristos /* OPTIONS */ 9475fd0b74Schristos #define PROCESSOR_OPTION_EXTENSION (1 << (opt_EXTENSION)) /* Enable extension opcodes. */ 9575fd0b74Schristos #define PROCESSOR_OPTION_ALIAS (1 << (opt_ALIAS)) /* Enable alias opcodes. */ 9675fd0b74Schristos 9775fd0b74Schristos #define SET_PROCESSOR_MASK(mask,set) ((mask) = ((mask) & ~PROCESSOR_MASK) | (set)) 9875fd0b74Schristos 9975fd0b74Schristos /* The table itself is sorted by major opcode number, and is otherwise 10075fd0b74Schristos in the order in which the disassembler should consider 10175fd0b74Schristos instructions. */ 10275fd0b74Schristos extern const struct v850_opcode v850_opcodes[]; 10375fd0b74Schristos extern const int v850_num_opcodes; 10475fd0b74Schristos 10575fd0b74Schristos 10675fd0b74Schristos /* The operands table is an array of struct v850_operand. */ 10775fd0b74Schristos 10875fd0b74Schristos struct v850_operand 10975fd0b74Schristos { 11075fd0b74Schristos /* The number of bits in the operand. */ 11175fd0b74Schristos /* If this value is -1 then the operand's bits are in a discontinous 11275fd0b74Schristos distribution in the instruction. */ 11375fd0b74Schristos int bits; 11475fd0b74Schristos 11575fd0b74Schristos /* (bits >= 0): How far the operand is left shifted in the instruction. */ 11675fd0b74Schristos /* (bits == -1): Bit mask of the bits in the operand. */ 11775fd0b74Schristos int shift; 11875fd0b74Schristos 11975fd0b74Schristos /* Insertion function. This is used by the assembler. To insert an 12075fd0b74Schristos operand value into an instruction, check this field. 12175fd0b74Schristos 12275fd0b74Schristos If it is NULL, execute 12375fd0b74Schristos i |= (op & ((1 << o->bits) - 1)) << o->shift; 12475fd0b74Schristos (i is the instruction which we are filling in, o is a pointer to 12575fd0b74Schristos this structure, and op is the opcode value; this assumes twos 12675fd0b74Schristos complement arithmetic). 12775fd0b74Schristos 12875fd0b74Schristos If this field is not NULL, then simply call it with the 12975fd0b74Schristos instruction and the operand value. It will return the new value 13075fd0b74Schristos of the instruction. If the ERRMSG argument is not NULL, then if 13175fd0b74Schristos the operand value is illegal, *ERRMSG will be set to a warning 13275fd0b74Schristos string (the operand will be inserted in any case). If the 13375fd0b74Schristos operand value is legal, *ERRMSG will be unchanged (most operands 13475fd0b74Schristos can accept any value). */ 13575fd0b74Schristos unsigned long (* insert) 136*e992f068Schristos (unsigned long instruction, unsigned long op, const char ** errmsg); 13775fd0b74Schristos 13875fd0b74Schristos /* Extraction function. This is used by the disassembler. To 13975fd0b74Schristos extract this operand type from an instruction, check this field. 14075fd0b74Schristos 14175fd0b74Schristos If it is NULL, compute 14275fd0b74Schristos op = o->bits == -1 ? ((i) & o->shift) : ((i) >> o->shift) & ((1 << o->bits) - 1); 14375fd0b74Schristos if (o->flags & V850_OPERAND_SIGNED) 14475fd0b74Schristos op = (op << (32 - o->bits)) >> (32 - o->bits); 14575fd0b74Schristos (i is the instruction, o is a pointer to this structure, and op 14675fd0b74Schristos is the result; this assumes twos complement arithmetic). 14775fd0b74Schristos 14875fd0b74Schristos If this field is not NULL, then simply call it with the 14975fd0b74Schristos instruction value. It will return the value of the operand. If 15075fd0b74Schristos the INVALID argument is not NULL, *INVALID will be set to 15175fd0b74Schristos non-zero if this operand type can not actually be extracted from 15275fd0b74Schristos this operand (i.e., the instruction does not match). If the 15375fd0b74Schristos operand is valid, *INVALID will not be changed. */ 15475fd0b74Schristos unsigned long (* extract) (unsigned long instruction, int * invalid); 15575fd0b74Schristos 15675fd0b74Schristos /* One bit syntax flags. */ 15775fd0b74Schristos int flags; 15875fd0b74Schristos 15975fd0b74Schristos int default_reloc; 16075fd0b74Schristos }; 16175fd0b74Schristos 16275fd0b74Schristos /* Elements in the table are retrieved by indexing with values from 16375fd0b74Schristos the operands field of the v850_opcodes table. */ 16475fd0b74Schristos 16575fd0b74Schristos extern const struct v850_operand v850_operands[]; 16675fd0b74Schristos 16775fd0b74Schristos /* Values defined for the flags field of a struct v850_operand. */ 16875fd0b74Schristos 16975fd0b74Schristos /* This operand names a general purpose register. */ 17075fd0b74Schristos #define V850_OPERAND_REG 0x01 17175fd0b74Schristos 17275fd0b74Schristos /* This operand is the ep register. */ 17375fd0b74Schristos #define V850_OPERAND_EP 0x02 17475fd0b74Schristos 17575fd0b74Schristos /* This operand names a system register. */ 17675fd0b74Schristos #define V850_OPERAND_SRG 0x04 17775fd0b74Schristos 17875fd0b74Schristos /* Prologue eilogue type instruction, V850E specific. */ 17975fd0b74Schristos #define V850E_OPERAND_REG_LIST 0x08 18075fd0b74Schristos 18175fd0b74Schristos /* This operand names a condition code used in the setf instruction. */ 18275fd0b74Schristos #define V850_OPERAND_CC 0x10 18375fd0b74Schristos 18475fd0b74Schristos #define V850_OPERAND_FLOAT_CC 0x20 18575fd0b74Schristos 18675fd0b74Schristos /* This operand names a vector purpose register. */ 18775fd0b74Schristos #define V850_OPERAND_VREG 0x40 18875fd0b74Schristos 18975fd0b74Schristos /* 16 bit immediate follows instruction, V850E specific. */ 19075fd0b74Schristos #define V850E_IMMEDIATE16 0x80 19175fd0b74Schristos 19275fd0b74Schristos /* hi16 bit immediate follows instruction, V850E specific. */ 19375fd0b74Schristos #define V850E_IMMEDIATE16HI 0x100 19475fd0b74Schristos 19575fd0b74Schristos /* 23 bit immediate follows instruction, V850E specific. */ 19675fd0b74Schristos #define V850E_IMMEDIATE23 0x200 19775fd0b74Schristos 19875fd0b74Schristos /* 32 bit immediate follows instruction, V850E specific. */ 19975fd0b74Schristos #define V850E_IMMEDIATE32 0x400 20075fd0b74Schristos 20175fd0b74Schristos /* This is a relaxable operand. Only used for D9->D22 branch relaxing 20275fd0b74Schristos right now. We may need others in the future (or maybe handle them like 20375fd0b74Schristos promoted operands on the mn10300?). */ 20475fd0b74Schristos #define V850_OPERAND_RELAX 0x800 20575fd0b74Schristos 20675fd0b74Schristos /* This operand takes signed values. */ 20775fd0b74Schristos #define V850_OPERAND_SIGNED 0x1000 20875fd0b74Schristos 20975fd0b74Schristos /* This operand is a displacement. */ 21075fd0b74Schristos #define V850_OPERAND_DISP 0x2000 21175fd0b74Schristos 21275fd0b74Schristos /* This operand is a PC displacement. */ 21375fd0b74Schristos #define V850_PCREL 0x4000 21475fd0b74Schristos 21575fd0b74Schristos /* The register specified must be even number. */ 21675fd0b74Schristos #define V850_REG_EVEN 0x8000 21775fd0b74Schristos 21875fd0b74Schristos /* The register specified must not be r0. */ 21975fd0b74Schristos #define V850_NOT_R0 0x20000 22075fd0b74Schristos 22175fd0b74Schristos /* The register specified must not be 0. */ 22275fd0b74Schristos #define V850_NOT_IMM0 0x40000 22375fd0b74Schristos 22475fd0b74Schristos /* The condition code must not be SA CONDITION. */ 22575fd0b74Schristos #define V850_NOT_SA 0x80000 22675fd0b74Schristos 22775fd0b74Schristos /* The operand has '!' prefix. */ 22875fd0b74Schristos #define V850_OPERAND_BANG 0x100000 22975fd0b74Schristos 23075fd0b74Schristos /* The operand has '%' prefix. */ 23175fd0b74Schristos #define V850_OPERAND_PERCENT 0x200000 23275fd0b74Schristos 233ede78133Schristos /* This operand is a cache operation. */ 23475fd0b74Schristos #define V850_OPERAND_CACHEOP 0x400000 23575fd0b74Schristos 236ede78133Schristos /* This operand is a prefetch operation. */ 23775fd0b74Schristos #define V850_OPERAND_PREFOP 0x800000 23875fd0b74Schristos 23975fd0b74Schristos /* A PC-relative displacement where a positive value indicates a backwards displacement. */ 24075fd0b74Schristos #define V850_INVERSE_PCREL 0x1000000 24175fd0b74Schristos 24275fd0b74Schristos extern int v850_msg_is_out_of_range (const char *); 24375fd0b74Schristos 24475fd0b74Schristos #ifdef __cplusplus 24575fd0b74Schristos } 24675fd0b74Schristos #endif 24775fd0b74Schristos 24875fd0b74Schristos #endif /* V850_H */ 249