xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/v850.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
198b9484cSchristos /* v850.h -- Header file for NEC V850 opcode table
2*aab831ceSchristos    Copyright (C) 1996-2024 Free Software Foundation, Inc.
398b9484cSchristos    Written by J.T. Conklin, Cygnus Support
498b9484cSchristos 
598b9484cSchristos    This file is part of GDB, GAS, and the GNU binutils.
698b9484cSchristos 
798b9484cSchristos    GDB, GAS, and the GNU binutils are free software; you can redistribute
898b9484cSchristos    them and/or modify them under the terms of the GNU General Public
998b9484cSchristos    License as published by the Free Software Foundation; either version 3,
1098b9484cSchristos    or (at your option) any later version.
1198b9484cSchristos 
1298b9484cSchristos    GDB, GAS, and the GNU binutils are distributed in the hope that they
1398b9484cSchristos    will be useful, but WITHOUT ANY WARRANTY; without even the implied
1498b9484cSchristos    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
1598b9484cSchristos    the GNU General Public License for more details.
1698b9484cSchristos 
1798b9484cSchristos    You should have received a copy of the GNU General Public License
1898b9484cSchristos    along with this file; see the file COPYING3.  If not, write to the Free
1998b9484cSchristos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
2098b9484cSchristos    MA 02110-1301, USA.  */
2198b9484cSchristos 
2298b9484cSchristos #ifndef V850_H
2398b9484cSchristos #define V850_H
2498b9484cSchristos 
25ba340e45Schristos #ifdef __cplusplus
26ba340e45Schristos extern "C" {
27ba340e45Schristos #endif
28ba340e45Schristos 
2998b9484cSchristos /* The opcode table is an array of struct v850_opcode.  */
3098b9484cSchristos 
3198b9484cSchristos struct v850_opcode
3298b9484cSchristos {
3398b9484cSchristos   /* The opcode name.  */
3498b9484cSchristos   const char *name;
3598b9484cSchristos 
3698b9484cSchristos   /* The opcode itself.  Those bits which will be filled in with
3798b9484cSchristos      operands are zeroes.  */
3898b9484cSchristos   unsigned long opcode;
3998b9484cSchristos 
4098b9484cSchristos   /* The opcode mask.  This is used by the disassembler.  This is a
4198b9484cSchristos      mask containing ones indicating those bits which must match the
4298b9484cSchristos      opcode field, and zeroes indicating those bits which need not
4398b9484cSchristos      match (and are presumably filled in by operands).  */
4498b9484cSchristos   unsigned long mask;
4598b9484cSchristos 
4698b9484cSchristos   /* An array of operand codes.  Each code is an index into the
4798b9484cSchristos      operand table.  They appear in the order which the operands must
4898b9484cSchristos      appear in assembly code, and are terminated by a zero.  */
4998b9484cSchristos   unsigned char operands[8];
5098b9484cSchristos 
5198b9484cSchristos   /* Which (if any) operand is a memory operand.  */
5298b9484cSchristos   unsigned int memop;
5398b9484cSchristos 
5498b9484cSchristos   /* Target processor(s).  A bit field of processors which support
5598b9484cSchristos      this instruction.  Note a bit field is used as some instructions
5698b9484cSchristos      are available on multiple, different processor types, whereas
5798b9484cSchristos      other instructions are only available on one specific type.  */
5898b9484cSchristos   unsigned int processors;
5998b9484cSchristos };
6098b9484cSchristos 
61a2e2270fSchristos /* Values for architecture number.  */
62a2e2270fSchristos #define arch_V850      0
63a2e2270fSchristos #define arch_V850E     (arch_V850 + 1)
64a2e2270fSchristos #define arch_V850E1    (arch_V850E + 1)
65a2e2270fSchristos #define arch_V850E2    (arch_V850E1 + 1)
66a2e2270fSchristos #define arch_V850E2V3  (arch_V850E2 + 1)
67a2e2270fSchristos #define arch_V850E3V5  (arch_V850E2V3 + 1)
68a2e2270fSchristos #define arch_separator (arch_V850E3V5 + 1)
69a2e2270fSchristos 
70a2e2270fSchristos #define opt_EXTENSION  (arch_separator)
71a2e2270fSchristos #define opt_ALIAS      (opt_EXTENSION + 1)
72a2e2270fSchristos 
7398b9484cSchristos /* Values for the processors field in the v850_opcode structure.  */
74a2e2270fSchristos #define PROCESSOR_V850       (1 << (arch_V850))     /* Just the V850.  */
75a2e2270fSchristos #define PROCESSOR_V850E      (1 << (arch_V850E))    /* Just the V850E.  */
76a2e2270fSchristos #define PROCESSOR_V850E1     (1 << (arch_V850E1))   /* Just the V850E1.  */
77a2e2270fSchristos #define PROCESSOR_V850E2     (1 << (arch_V850E2))   /* Just the V850E2.  */
78a2e2270fSchristos #define PROCESSOR_V850E2V3   (1 << (arch_V850E2V3)) /* Just the V850E2V3.  */
79a2e2270fSchristos #define PROCESSOR_V850E3V5   (1 << (arch_V850E3V5)) /* Just the V850E3V5.  */
80a2e2270fSchristos 
81a2e2270fSchristos /* UPPERS */
82a2e2270fSchristos #define PROCESSOR_V850E3V5_UP (PROCESSOR_V850E3V5)
83a2e2270fSchristos #define PROCESSOR_V850E2V3_UP (PROCESSOR_V850E2V3 | PROCESSOR_V850E3V5_UP)
84a2e2270fSchristos #define PROCESSOR_V850E2_UP   (PROCESSOR_V850E2   | PROCESSOR_V850E2V3_UP)
85a2e2270fSchristos #define PROCESSOR_V850E_UP    (PROCESSOR_V850E    | PROCESSOR_V850E1 | PROCESSOR_V850E2_UP)
86a2e2270fSchristos #define PROCESSOR_ALL         (PROCESSOR_V850     | PROCESSOR_V850E_UP)
87a2e2270fSchristos 
88a2e2270fSchristos #define PROCESSOR_MASK        (PROCESSOR_ALL)
8998b9484cSchristos #define PROCESSOR_NOT_V850    (PROCESSOR_ALL & (~ PROCESSOR_V850))         /* Any processor except the V850.  */
90a2e2270fSchristos 
91a2e2270fSchristos #define PROCESSOR_UNKNOWN    ~(PROCESSOR_MASK)
92a2e2270fSchristos 
93a2e2270fSchristos /* OPTIONS */
94a2e2270fSchristos #define PROCESSOR_OPTION_EXTENSION (1 << (opt_EXTENSION))                  /* Enable extension opcodes.  */
95a2e2270fSchristos #define PROCESSOR_OPTION_ALIAS     (1 << (opt_ALIAS))                      /* Enable alias opcodes.  */
96a2e2270fSchristos 
9798b9484cSchristos #define SET_PROCESSOR_MASK(mask,set)	((mask) = ((mask) & ~PROCESSOR_MASK) | (set))
9898b9484cSchristos 
9998b9484cSchristos /* The table itself is sorted by major opcode number, and is otherwise
10098b9484cSchristos    in the order in which the disassembler should consider
10198b9484cSchristos    instructions.  */
10298b9484cSchristos extern const struct v850_opcode v850_opcodes[];
10398b9484cSchristos extern const int v850_num_opcodes;
10498b9484cSchristos 
10598b9484cSchristos 
10698b9484cSchristos /* The operands table is an array of struct v850_operand.  */
10798b9484cSchristos 
10898b9484cSchristos struct v850_operand
10998b9484cSchristos {
11098b9484cSchristos   /* The number of bits in the operand.  */
11198b9484cSchristos   /* If this value is -1 then the operand's bits are in a discontinous
11298b9484cSchristos      distribution in the instruction. */
11398b9484cSchristos   int bits;
11498b9484cSchristos 
11598b9484cSchristos   /* (bits >= 0):  How far the operand is left shifted in the instruction.  */
11698b9484cSchristos   /* (bits == -1): Bit mask of the bits in the operand.  */
11798b9484cSchristos   int shift;
11898b9484cSchristos 
11998b9484cSchristos   /* Insertion function.  This is used by the assembler.  To insert an
12098b9484cSchristos      operand value into an instruction, check this field.
12198b9484cSchristos 
12298b9484cSchristos      If it is NULL, execute
12398b9484cSchristos          i |= (op & ((1 << o->bits) - 1)) << o->shift;
12498b9484cSchristos      (i is the instruction which we are filling in, o is a pointer to
12598b9484cSchristos      this structure, and op is the opcode value; this assumes twos
12698b9484cSchristos      complement arithmetic).
12798b9484cSchristos 
12898b9484cSchristos      If this field is not NULL, then simply call it with the
12998b9484cSchristos      instruction and the operand value.  It will return the new value
13098b9484cSchristos      of the instruction.  If the ERRMSG argument is not NULL, then if
13198b9484cSchristos      the operand value is illegal, *ERRMSG will be set to a warning
13298b9484cSchristos      string (the operand will be inserted in any case).  If the
13398b9484cSchristos      operand value is legal, *ERRMSG will be unchanged (most operands
13498b9484cSchristos      can accept any value).  */
13598b9484cSchristos   unsigned long (* insert)
1368dffb485Schristos     (unsigned long instruction, unsigned long op, const char ** errmsg);
13798b9484cSchristos 
13898b9484cSchristos   /* Extraction function.  This is used by the disassembler.  To
13998b9484cSchristos      extract this operand type from an instruction, check this field.
14098b9484cSchristos 
14198b9484cSchristos      If it is NULL, compute
14298b9484cSchristos          op = o->bits == -1 ? ((i) & o->shift) : ((i) >> o->shift) & ((1 << o->bits) - 1);
14398b9484cSchristos 	 if (o->flags & V850_OPERAND_SIGNED)
14498b9484cSchristos 	     op = (op << (32 - o->bits)) >> (32 - o->bits);
14598b9484cSchristos      (i is the instruction, o is a pointer to this structure, and op
14698b9484cSchristos      is the result; this assumes twos complement arithmetic).
14798b9484cSchristos 
14898b9484cSchristos      If this field is not NULL, then simply call it with the
14998b9484cSchristos      instruction value.  It will return the value of the operand.  If
15098b9484cSchristos      the INVALID argument is not NULL, *INVALID will be set to
15198b9484cSchristos      non-zero if this operand type can not actually be extracted from
15298b9484cSchristos      this operand (i.e., the instruction does not match).  If the
15398b9484cSchristos      operand is valid, *INVALID will not be changed.  */
15498b9484cSchristos   unsigned long (* extract) (unsigned long instruction, int * invalid);
15598b9484cSchristos 
15698b9484cSchristos   /* One bit syntax flags.  */
15798b9484cSchristos   int flags;
15898b9484cSchristos 
15998b9484cSchristos   int default_reloc;
16098b9484cSchristos };
16198b9484cSchristos 
16298b9484cSchristos /* Elements in the table are retrieved by indexing with values from
16398b9484cSchristos    the operands field of the v850_opcodes table.  */
16498b9484cSchristos 
16598b9484cSchristos extern const struct v850_operand v850_operands[];
16698b9484cSchristos 
16798b9484cSchristos /* Values defined for the flags field of a struct v850_operand.  */
16898b9484cSchristos 
16998b9484cSchristos /* This operand names a general purpose register.  */
17098b9484cSchristos #define V850_OPERAND_REG	0x01
17198b9484cSchristos 
17298b9484cSchristos /* This operand is the ep register.  */
17398b9484cSchristos #define V850_OPERAND_EP		0x02
17498b9484cSchristos 
17598b9484cSchristos /* This operand names a system register.  */
17698b9484cSchristos #define V850_OPERAND_SRG	0x04
17798b9484cSchristos 
17898b9484cSchristos /* Prologue eilogue type instruction, V850E specific.  */
17998b9484cSchristos #define V850E_OPERAND_REG_LIST	0x08
18098b9484cSchristos 
18198b9484cSchristos /* This operand names a condition code used in the setf instruction.  */
18298b9484cSchristos #define V850_OPERAND_CC		0x10
18398b9484cSchristos 
18498b9484cSchristos #define V850_OPERAND_FLOAT_CC	0x20
18598b9484cSchristos 
18698b9484cSchristos /* This operand names a vector purpose register.  */
18798b9484cSchristos #define V850_OPERAND_VREG	0x40
18898b9484cSchristos 
18998b9484cSchristos /* 16 bit immediate follows instruction, V850E specific.  */
19098b9484cSchristos #define V850E_IMMEDIATE16	0x80
19198b9484cSchristos 
19298b9484cSchristos /* hi16 bit immediate follows instruction, V850E specific.  */
19398b9484cSchristos #define V850E_IMMEDIATE16HI	0x100
19498b9484cSchristos 
19598b9484cSchristos /* 23 bit immediate follows instruction, V850E specific.  */
19698b9484cSchristos #define V850E_IMMEDIATE23	0x200
19798b9484cSchristos 
19898b9484cSchristos /* 32 bit immediate follows instruction, V850E specific.  */
19998b9484cSchristos #define V850E_IMMEDIATE32	0x400
20098b9484cSchristos 
20198b9484cSchristos /* This is a relaxable operand.   Only used for D9->D22 branch relaxing
20298b9484cSchristos    right now.  We may need others in the future (or maybe handle them like
20398b9484cSchristos    promoted operands on the mn10300?).  */
20498b9484cSchristos #define V850_OPERAND_RELAX	0x800
20598b9484cSchristos 
20698b9484cSchristos /* This operand takes signed values.  */
20798b9484cSchristos #define V850_OPERAND_SIGNED	0x1000
20898b9484cSchristos 
20998b9484cSchristos /* This operand is a displacement.  */
21098b9484cSchristos #define V850_OPERAND_DISP	0x2000
21198b9484cSchristos 
21298b9484cSchristos /* This operand is a PC displacement.  */
21398b9484cSchristos #define V850_PCREL		0x4000
21498b9484cSchristos 
21598b9484cSchristos /* The register specified must be even number.  */
21698b9484cSchristos #define V850_REG_EVEN		0x8000
21798b9484cSchristos 
21898b9484cSchristos /* The register specified must not be r0.  */
21998b9484cSchristos #define V850_NOT_R0	        0x20000
22098b9484cSchristos 
22198b9484cSchristos /* The register specified must not be 0.  */
22298b9484cSchristos #define V850_NOT_IMM0	        0x40000
22398b9484cSchristos 
22498b9484cSchristos /* The condition code must not be SA CONDITION.  */
22598b9484cSchristos #define V850_NOT_SA		0x80000
22698b9484cSchristos 
22798b9484cSchristos /* The operand has '!' prefix.  */
22898b9484cSchristos #define V850_OPERAND_BANG	0x100000
22998b9484cSchristos 
23098b9484cSchristos /* The operand has '%' prefix.  */
23198b9484cSchristos #define V850_OPERAND_PERCENT	0x200000
23298b9484cSchristos 
2334559860eSchristos /* This operand is a cache operation.  */
234a2e2270fSchristos #define V850_OPERAND_CACHEOP	0x400000
235a2e2270fSchristos 
2364559860eSchristos /* This operand is a prefetch operation.  */
237a2e2270fSchristos #define V850_OPERAND_PREFOP	0x800000
238a2e2270fSchristos 
23903467a24Schristos /* A PC-relative displacement where a positive value indicates a backwards displacement.  */
24003467a24Schristos #define V850_INVERSE_PCREL	0x1000000
24103467a24Schristos 
242a2e2270fSchristos extern int v850_msg_is_out_of_range (const char *);
24398b9484cSchristos 
244ba340e45Schristos #ifdef __cplusplus
245ba340e45Schristos }
246ba340e45Schristos #endif
247ba340e45Schristos 
24898b9484cSchristos #endif /* V850_H */
249