xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/cr16.h (revision 02f41505626a9ceb584d30d0789203495760ac88)
198b9484cSchristos /* cr16.h -- Header file for CR16 opcode and register tables.
2*02f41505Schristos    Copyright (C) 2007-2024 Free Software Foundation, Inc.
398b9484cSchristos    Contributed by M R Swami Reddy
498b9484cSchristos 
598b9484cSchristos    This file is part of GAS, GDB and the GNU binutils.
698b9484cSchristos 
798b9484cSchristos    GAS, GDB, and GNU binutils is free software; you can redistribute it
898b9484cSchristos    and/or modify it under the terms of the GNU General Public License as
998b9484cSchristos    published by the Free Software Foundation; either version 3, or (at your
1098b9484cSchristos    option) any later version.
1198b9484cSchristos 
1298b9484cSchristos    GAS, GDB, and GNU binutils are distributed in the hope that they will be
1398b9484cSchristos    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1498b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1598b9484cSchristos    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 program; if not, write to the Free Software Foundation,
1998b9484cSchristos    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2098b9484cSchristos 
2198b9484cSchristos #ifndef _CR16_H_
2298b9484cSchristos #define _CR16_H_
2398b9484cSchristos 
2498b9484cSchristos /* CR16 core Registers :
2598b9484cSchristos    The enums are used as indices to CR16 registers table (cr16_regtab).
2698b9484cSchristos    Therefore, order MUST be preserved.  */
2798b9484cSchristos 
2898b9484cSchristos typedef enum
2998b9484cSchristos {
3098b9484cSchristos   /* 16-bit general purpose registers.  */
3198b9484cSchristos   r0, r1, r2, r3,
3298b9484cSchristos   r4, r5, r6, r7,
3398b9484cSchristos   r8, r9, r10, r11,
3498b9484cSchristos   r12_L = 12, r13_L = 13, ra = 14, sp_L = 15,
3598b9484cSchristos 
3698b9484cSchristos   /* 32-bit general purpose registers.  */
3798b9484cSchristos   r12 = 12, r13 = 13, r14 = 14, r15 = 15,
3898b9484cSchristos   era = 14, sp = 15, RA,
3998b9484cSchristos 
4098b9484cSchristos   /* Not a register.  */
4198b9484cSchristos   nullregister,
4298b9484cSchristos   MAX_REG
4398b9484cSchristos }
4498b9484cSchristos reg;
4598b9484cSchristos 
4698b9484cSchristos /* CR16 processor registers and special registers :
4798b9484cSchristos    The enums are used as indices to CR16 processor registers table
4898b9484cSchristos    (cr16_pregtab). Therefore, order MUST be preserved.  */
4998b9484cSchristos 
5098b9484cSchristos typedef enum
5198b9484cSchristos {
5298b9484cSchristos   /* processor registers.  */
5398b9484cSchristos   dbs = MAX_REG,
5498b9484cSchristos   dsr, dcrl, dcrh,
5598b9484cSchristos   car0l, car0h, car1l, car1h,
5698b9484cSchristos   cfg, psr, intbasel, intbaseh,
5798b9484cSchristos   ispl, isph, uspl, usph,
5898b9484cSchristos   dcr =  dcrl,
5998b9484cSchristos   car0 = car0l,
6098b9484cSchristos   car1 = car1l,
6198b9484cSchristos   intbase = intbasel,
6298b9484cSchristos   isp =  ispl,
6398b9484cSchristos   usp =  uspl,
6498b9484cSchristos   /* Not a processor register.  */
6598b9484cSchristos   nullpregister = usph + 1,
6698b9484cSchristos   MAX_PREG
6798b9484cSchristos }
6898b9484cSchristos preg;
6998b9484cSchristos 
7098b9484cSchristos /* CR16 Register types. */
7198b9484cSchristos 
7298b9484cSchristos typedef enum
7398b9484cSchristos {
7498b9484cSchristos   CR16_R_REGTYPE,    /* r<N>      */
7598b9484cSchristos   CR16_RP_REGTYPE,   /* reg pair  */
7698b9484cSchristos   CR16_P_REGTYPE     /* Processor register  */
7798b9484cSchristos }
7898b9484cSchristos reg_type;
7998b9484cSchristos 
8098b9484cSchristos /* CR16 argument types :
8198b9484cSchristos    The argument types correspond to instructions operands
8298b9484cSchristos 
8398b9484cSchristos    Argument types :
8498b9484cSchristos    r - register
8598b9484cSchristos    rp - register pair
8698b9484cSchristos    c - constant
8798b9484cSchristos    i - immediate
8898b9484cSchristos    idxr - index with register
8998b9484cSchristos    idxrp - index with register pair
9098b9484cSchristos    rbase - register base
9198b9484cSchristos    rpbase - register pair base
92a2e2270fSchristos    pr - processor register.  */
9398b9484cSchristos 
9498b9484cSchristos typedef enum
9598b9484cSchristos {
9698b9484cSchristos   arg_r,
9798b9484cSchristos   arg_c,
9898b9484cSchristos   arg_cr,
9998b9484cSchristos   arg_crp,
10098b9484cSchristos   arg_ic,
10198b9484cSchristos   arg_icr,
10298b9484cSchristos   arg_idxr,
10398b9484cSchristos   arg_idxrp,
10498b9484cSchristos   arg_rbase,
10598b9484cSchristos   arg_rpbase,
10698b9484cSchristos   arg_rp,
10798b9484cSchristos   arg_pr,
10898b9484cSchristos   arg_prp,
10998b9484cSchristos   arg_cc,
11098b9484cSchristos   arg_ra,
11198b9484cSchristos   /* Not an argument.  */
11298b9484cSchristos   nullargs
11398b9484cSchristos }
11498b9484cSchristos argtype;
11598b9484cSchristos 
11698b9484cSchristos /* CR16 operand types:The operand types correspond to instructions operands.  */
11798b9484cSchristos 
11898b9484cSchristos typedef enum
11998b9484cSchristos {
12098b9484cSchristos   dummy,
12198b9484cSchristos   /* N-bit signed immediate.  */
12298b9484cSchristos   imm3, imm4, imm5, imm6, imm16, imm20, imm32,
12398b9484cSchristos   /* N-bit unsigned immediate.  */
12498b9484cSchristos   uimm3, uimm3_1, uimm4, uimm4_1, uimm5, uimm16, uimm20, uimm32,
12598b9484cSchristos   /* N-bit signed displacement.  */
12698b9484cSchristos   disps5, disps17, disps25,
12798b9484cSchristos   /* N-bit unsigned displacement.  */
12898b9484cSchristos   dispe9,
12998b9484cSchristos   /* N-bit absolute address.  */
13098b9484cSchristos   abs20, abs24,
13198b9484cSchristos   /* Register relative.  */
13298b9484cSchristos   rra, rbase, rbase_disps20, rbase_dispe20,
13398b9484cSchristos   /* Register pair relative.  */
13498b9484cSchristos   rpbase_disps0, rpbase_dispe4, rpbase_disps4, rpbase_disps16,
13598b9484cSchristos   rpbase_disps20, rpbase_dispe20,
13698b9484cSchristos   /* Register index.  */
13798b9484cSchristos   rindex7_abs20, rindex8_abs20,
13898b9484cSchristos   /* Register pair index.  */
13998b9484cSchristos   rpindex_disps0, rpindex_disps14, rpindex_disps20,
14098b9484cSchristos   /* register.  */
14198b9484cSchristos   regr,
14298b9484cSchristos   /* register pair.  */
14398b9484cSchristos   regp,
14498b9484cSchristos   /* processor register.  */
14598b9484cSchristos   pregr,
14698b9484cSchristos   /* processor register 32 bit.  */
14798b9484cSchristos   pregrp,
14898b9484cSchristos   /* condition code - 4 bit.  */
14998b9484cSchristos   cc,
15098b9484cSchristos   /* Not an operand.  */
15198b9484cSchristos   nulloperand,
15298b9484cSchristos   /* Maximum supported operand.  */
15398b9484cSchristos   MAX_OPRD
15498b9484cSchristos }
15598b9484cSchristos operand_type;
15698b9484cSchristos 
15798b9484cSchristos /* CR16 instruction types.  */
15898b9484cSchristos 
15998b9484cSchristos #define NO_TYPE_INS       0
16098b9484cSchristos #define ARITH_INS         1
16198b9484cSchristos #define LD_STOR_INS       2
16298b9484cSchristos #define BRANCH_INS        3
16398b9484cSchristos #define ARITH_BYTE_INS    4
16498b9484cSchristos #define SHIFT_INS         5
16598b9484cSchristos #define BRANCH_NEQ_INS    6
16698b9484cSchristos #define LD_STOR_INS_INC   7
16798b9484cSchristos #define STOR_IMM_INS      8
16898b9484cSchristos #define CSTBIT_INS        9
16998b9484cSchristos 
17098b9484cSchristos /* Maximum value supported for instruction types.  */
17198b9484cSchristos #define CR16_INS_MAX        (1 << 4)
17298b9484cSchristos /* Mask to record an instruction type.  */
17398b9484cSchristos #define CR16_INS_MASK       (CR16_INS_MAX - 1)
17498b9484cSchristos /* Return instruction type, given instruction's attributes.  */
17598b9484cSchristos #define CR16_INS_TYPE(attr) ((attr) & CR16_INS_MASK)
17698b9484cSchristos 
17798b9484cSchristos /* Indicates whether this instruction has a register list as parameter.  */
17898b9484cSchristos #define REG_LIST        CR16_INS_MAX
17998b9484cSchristos 
18098b9484cSchristos /* The operands in binary and assembly are placed in reverse order.
18198b9484cSchristos    load - (REVERSE_MATCH)/store - (! REVERSE_MATCH).  */
18298b9484cSchristos #define REVERSE_MATCH  (1 << 5)
18398b9484cSchristos 
18498b9484cSchristos /* Printing formats, where the instruction prefix isn't consecutive.  */
18598b9484cSchristos #define FMT_1          (1 << 9)    /* 0xF0F00000 */
18698b9484cSchristos #define FMT_2          (1 << 10)   /* 0xFFF0FF00 */
18798b9484cSchristos #define FMT_3          (1 << 11)   /* 0xFFF00F00 */
18898b9484cSchristos #define FMT_4          (1 << 12)   /* 0xFFF0F000 */
18998b9484cSchristos #define FMT_5          (1 << 13)   /* 0xFFF0FFF0 */
19098b9484cSchristos #define FMT_CR16       (FMT_1 | FMT_2 | FMT_3 | FMT_4 | FMT_5)
19198b9484cSchristos 
19298b9484cSchristos /* Indicates whether this instruction can be relaxed.  */
19398b9484cSchristos #define RELAXABLE      (1 << 14)
19498b9484cSchristos 
19598b9484cSchristos /* Indicates that instruction uses user registers (and not
19698b9484cSchristos    general-purpose registers) as operands.  */
19798b9484cSchristos #define USER_REG       (1 << 15)
19898b9484cSchristos 
19998b9484cSchristos 
20098b9484cSchristos /* Instruction shouldn't allow 'sp' usage.  */
20198b9484cSchristos #define NO_SP          (1 << 17)
20298b9484cSchristos 
20398b9484cSchristos /* Instruction shouldn't allow to push a register which is used as a rptr.  */
20498b9484cSchristos #define NO_RPTR        (1 << 18)
20598b9484cSchristos 
20698b9484cSchristos /* Maximum operands per instruction.  */
20798b9484cSchristos #define MAX_OPERANDS     5
20898b9484cSchristos /* Maximum register name length. */
20998b9484cSchristos #define MAX_REGNAME_LEN  10
21098b9484cSchristos /* Maximum instruction length. */
21198b9484cSchristos #define MAX_INST_LEN     256
21298b9484cSchristos 
21398b9484cSchristos 
21498b9484cSchristos /* Values defined for the flags field of a struct operand_entry.  */
21598b9484cSchristos 
21698b9484cSchristos /* Operand must be an unsigned number.  */
21798b9484cSchristos #define OP_UNSIGNED   (1 << 0)
21898b9484cSchristos /* Operand must be a signed number.  */
21998b9484cSchristos #define OP_SIGNED     (1 << 1)
22098b9484cSchristos /* Operand must be a negative number.  */
22198b9484cSchristos #define OP_NEG        (1 << 2)
22298b9484cSchristos /* A special load/stor 4-bit unsigned displacement operand.  */
22398b9484cSchristos #define OP_DEC        (1 << 3)
22498b9484cSchristos /* Operand must be an even number.  */
22598b9484cSchristos #define OP_EVEN       (1 << 4)
22698b9484cSchristos /* Operand is shifted right.  */
22798b9484cSchristos #define OP_SHIFT      (1 << 5)
22898b9484cSchristos /* Operand is shifted right and decremented.  */
22998b9484cSchristos #define OP_SHIFT_DEC  (1 << 6)
23098b9484cSchristos /* Operand has reserved escape sequences.  */
23198b9484cSchristos #define OP_ESC        (1 << 7)
23298b9484cSchristos /* Operand must be a ABS20 number.  */
23398b9484cSchristos #define OP_ABS20      (1 << 8)
23498b9484cSchristos /* Operand must be a ABS24 number.  */
23598b9484cSchristos #define OP_ABS24      (1 << 9)
23698b9484cSchristos /* Operand has reserved escape sequences type 1.  */
23798b9484cSchristos #define OP_ESC1       (1 << 10)
23898b9484cSchristos 
23998b9484cSchristos /* Single operand description.  */
24098b9484cSchristos 
24198b9484cSchristos typedef struct
24298b9484cSchristos {
24398b9484cSchristos   /* Operand type.  */
24498b9484cSchristos   operand_type op_type;
24598b9484cSchristos   /* Operand location within the opcode.  */
24698b9484cSchristos   unsigned int shift;
24798b9484cSchristos }
24898b9484cSchristos operand_desc;
24998b9484cSchristos 
25098b9484cSchristos /* Instruction data structure used in instruction table.  */
25198b9484cSchristos 
25298b9484cSchristos typedef struct
25398b9484cSchristos {
25498b9484cSchristos   /* Name.  */
25598b9484cSchristos   const char *mnemonic;
25698b9484cSchristos   /* Size (in words).  */
25798b9484cSchristos   unsigned int size;
25898b9484cSchristos   /* Constant prefix (matched by the disassembler).  */
25998b9484cSchristos   unsigned long match;  /* ie opcode */
26098b9484cSchristos   /* Match size (in bits).  */
26198b9484cSchristos   /* MASK: if( (i & match_bits) == match ) then match */
26298b9484cSchristos   int match_bits;
26398b9484cSchristos   /* Attributes.  */
26498b9484cSchristos   unsigned int flags;
26598b9484cSchristos   /* Operands (always last, so unreferenced operands are initialized).  */
26698b9484cSchristos   operand_desc operands[MAX_OPERANDS];
26798b9484cSchristos }
26898b9484cSchristos inst;
26998b9484cSchristos 
27098b9484cSchristos /* Data structure for a single instruction's arguments (Operands).  */
27198b9484cSchristos 
27298b9484cSchristos typedef struct
27398b9484cSchristos {
27498b9484cSchristos   /* Register or base register.  */
27598b9484cSchristos   reg r;
27698b9484cSchristos   /* Register pair register.  */
27798b9484cSchristos   reg rp;
27898b9484cSchristos   /* Index register.  */
27998b9484cSchristos   reg i_r;
28098b9484cSchristos   /* Processor register.  */
28198b9484cSchristos   preg pr;
28298b9484cSchristos   /* Processor register. 32 bit  */
28398b9484cSchristos   preg prp;
28498b9484cSchristos   /* Constant/immediate/absolute value.  */
28598b9484cSchristos   long constant;
28698b9484cSchristos   /* CC code.  */
28798b9484cSchristos   unsigned int cc;
28898b9484cSchristos   /* Scaled index mode.  */
28998b9484cSchristos   unsigned int scale;
29098b9484cSchristos   /* Argument type.  */
29198b9484cSchristos   argtype type;
29298b9484cSchristos   /* Size of the argument (in bits) required to represent.  */
29398b9484cSchristos   int size;
29498b9484cSchristos   /* The type of the expression.  */
29598b9484cSchristos   unsigned char X_op;
29698b9484cSchristos }
29798b9484cSchristos argument;
29898b9484cSchristos 
29998b9484cSchristos /* Internal structure to hold the various entities
30098b9484cSchristos    corresponding to the current assembling instruction.  */
30198b9484cSchristos 
30298b9484cSchristos typedef struct
30398b9484cSchristos {
30498b9484cSchristos   /* Number of arguments.  */
30598b9484cSchristos   int nargs;
30698b9484cSchristos   /* The argument data structure for storing args (operands).  */
30798b9484cSchristos   argument arg[MAX_OPERANDS];
30898b9484cSchristos /* The following fields are required only by CR16-assembler.  */
30998b9484cSchristos #ifdef TC_CR16
31098b9484cSchristos   /* Expression used for setting the fixups (if any).  */
31198b9484cSchristos   expressionS exp;
31298b9484cSchristos   bfd_reloc_code_real_type rtype;
31398b9484cSchristos #endif /* TC_CR16 */
31498b9484cSchristos   /* Instruction size (in bytes).  */
31598b9484cSchristos   int size;
31698b9484cSchristos }
31798b9484cSchristos ins;
31898b9484cSchristos 
31998b9484cSchristos /* Structure to hold information about predefined operands.  */
32098b9484cSchristos 
32198b9484cSchristos typedef struct
32298b9484cSchristos {
32398b9484cSchristos   /* Size (in bits).  */
32498b9484cSchristos   unsigned int bit_size;
32598b9484cSchristos   /* Argument type.  */
32698b9484cSchristos   argtype arg_type;
32798b9484cSchristos   /* One bit syntax flags.  */
32898b9484cSchristos   int flags;
32998b9484cSchristos }
33098b9484cSchristos operand_entry;
33198b9484cSchristos 
33298b9484cSchristos /* Structure to hold trap handler information.  */
33398b9484cSchristos 
33498b9484cSchristos typedef struct
33598b9484cSchristos {
33698b9484cSchristos   /* Trap name.  */
33798b9484cSchristos   char *name;
33898b9484cSchristos   /* Index in dispatch table.  */
33998b9484cSchristos   unsigned int entry;
34098b9484cSchristos }
34198b9484cSchristos trap_entry;
34298b9484cSchristos 
34398b9484cSchristos /* Structure to hold information about predefined registers.  */
34498b9484cSchristos 
34598b9484cSchristos typedef struct
34698b9484cSchristos {
34798b9484cSchristos   /* Name (string representation).  */
34898b9484cSchristos   char *name;
34998b9484cSchristos   /* Value (enum representation).  */
35098b9484cSchristos   union
35198b9484cSchristos   {
35298b9484cSchristos     /* Register.  */
35398b9484cSchristos     reg reg_val;
35498b9484cSchristos     /* processor register.  */
35598b9484cSchristos     preg preg_val;
35698b9484cSchristos   } value;
35798b9484cSchristos   /* Register image.  */
35898b9484cSchristos   int image;
35998b9484cSchristos   /* Register type.  */
36098b9484cSchristos   reg_type type;
36198b9484cSchristos }
36298b9484cSchristos reg_entry;
36398b9484cSchristos 
36498b9484cSchristos /* CR16 opcode table.  */
36598b9484cSchristos extern const inst cr16_instruction[];
36698b9484cSchristos extern const unsigned int cr16_num_opcodes;
36798b9484cSchristos #define NUMOPCODES cr16_num_opcodes
36898b9484cSchristos 
36998b9484cSchristos /* CR16 operands table.  */
37098b9484cSchristos extern const operand_entry cr16_optab[];
37198b9484cSchristos extern const unsigned int cr16_num_optab;
37298b9484cSchristos 
37398b9484cSchristos /* CR16 registers table.  */
37498b9484cSchristos extern const reg_entry cr16_regtab[];
37598b9484cSchristos extern const unsigned int cr16_num_regs;
37698b9484cSchristos #define NUMREGS cr16_num_regs
37798b9484cSchristos 
37898b9484cSchristos /* CR16 register pair table.  */
37998b9484cSchristos extern const reg_entry cr16_regptab[];
38098b9484cSchristos extern const unsigned int cr16_num_regps;
38198b9484cSchristos #define NUMREGPS cr16_num_regps
38298b9484cSchristos 
38398b9484cSchristos /* CR16 processor registers table.  */
38498b9484cSchristos extern const reg_entry cr16_pregtab[];
38598b9484cSchristos extern const unsigned int cr16_num_pregs;
38698b9484cSchristos #define NUMPREGS cr16_num_pregs
38798b9484cSchristos 
38898b9484cSchristos /* CR16 processor registers - 32 bit table.  */
38998b9484cSchristos extern const reg_entry cr16_pregptab[];
39098b9484cSchristos extern const unsigned int cr16_num_pregps;
39198b9484cSchristos #define NUMPREGPS cr16_num_pregps
39298b9484cSchristos 
39398b9484cSchristos /* CR16 trap/interrupt table.  */
39498b9484cSchristos extern const trap_entry cr16_traps[];
39598b9484cSchristos extern const unsigned int cr16_num_traps;
39698b9484cSchristos #define NUMTRAPS cr16_num_traps
39798b9484cSchristos 
39898b9484cSchristos /* CR16 CC - codes bit table.  */
39998b9484cSchristos extern const char * cr16_b_cond_tab[];
40098b9484cSchristos extern const unsigned int cr16_num_cc;
40198b9484cSchristos #define NUMCC cr16_num_cc;
40298b9484cSchristos 
40398b9484cSchristos 
40498b9484cSchristos /* Table of instructions with no operands.  */
40598b9484cSchristos extern const char * cr16_no_op_insn[];
40698b9484cSchristos 
40798b9484cSchristos /* A macro for representing the instruction "constant" opcode, that is,
40898b9484cSchristos    the FIXED part of the instruction. The "constant" opcode is represented
40998b9484cSchristos    as a 32-bit unsigned long, where OPC is expanded (by a left SHIFT)
41098b9484cSchristos    over that range.  */
41198b9484cSchristos #define BIN(OPC,SHIFT)        (OPC << SHIFT)
41298b9484cSchristos 
41398b9484cSchristos /* Is the current instruction type is TYPE ?  */
41498b9484cSchristos #define IS_INSN_TYPE(TYPE)              \
41598b9484cSchristos   (CR16_INS_TYPE (instruction->flags) == TYPE)
41698b9484cSchristos 
41798b9484cSchristos /* Is the current instruction mnemonic is MNEMONIC ?  */
41898b9484cSchristos #define IS_INSN_MNEMONIC(MNEMONIC)    \
41998b9484cSchristos   (strcmp (instruction->mnemonic, MNEMONIC) == 0)
42098b9484cSchristos 
42198b9484cSchristos /* Does the current instruction has register list ?  */
42298b9484cSchristos #define INST_HAS_REG_LIST              \
42398b9484cSchristos   (instruction->flags & REG_LIST)
42498b9484cSchristos 
42598b9484cSchristos 
42698b9484cSchristos /* Utility macros for string comparison.  */
42798b9484cSchristos #define streq(a, b)           (strcmp (a, b) == 0)
42898b9484cSchristos 
42998b9484cSchristos /* Long long type handling.  */
43098b9484cSchristos /* Replace all appearances of 'long long int' with LONGLONG.  */
43198b9484cSchristos typedef long long int LONGLONG;
43298b9484cSchristos typedef unsigned long long ULONGLONG;
43398b9484cSchristos 
434a2e2270fSchristos /* Data types for opcode handling.  */
435a2e2270fSchristos typedef unsigned long dwordU;
436a2e2270fSchristos typedef unsigned short wordU;
437a2e2270fSchristos 
438a2e2270fSchristos /* Prototypes for function in cr16-dis.c.  */
439a2e2270fSchristos extern void cr16_make_instruction (void);
440a2e2270fSchristos extern int  cr16_match_opcode (void);
441a2e2270fSchristos 
44298b9484cSchristos #endif /* _CR16_H_ */
443