198b9484cSchristos /* crx.h -- Header file for CRX opcode and register tables. 2*aab831ceSchristos Copyright (C) 2004-2024 Free Software Foundation, Inc. 398b9484cSchristos Contributed by Tomer Levi, NSC, Israel. 498b9484cSchristos Originally written for GAS 2.12 by Tomer Levi, NSC, Israel. 598b9484cSchristos Updates, BFDizing, GNUifying and ELF support by Tomer Levi. 698b9484cSchristos 798b9484cSchristos This file is part of GAS, GDB and the GNU binutils. 898b9484cSchristos 998b9484cSchristos GAS, GDB, and GNU binutils is free software; you can redistribute it 1098b9484cSchristos and/or modify it under the terms of the GNU General Public License as 1198b9484cSchristos published by the Free Software Foundation; either version 3, or (at your 1298b9484cSchristos option) any later version. 1398b9484cSchristos 1498b9484cSchristos GAS, GDB, and GNU binutils are distributed in the hope that they will be 1598b9484cSchristos useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 1698b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1798b9484cSchristos GNU General Public License for more details. 1898b9484cSchristos 1998b9484cSchristos You should have received a copy of the GNU General Public License 2098b9484cSchristos along with this program; if not, write to the Free Software 2198b9484cSchristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 2298b9484cSchristos MA 02110-1301, USA. */ 2398b9484cSchristos 2498b9484cSchristos #ifndef _CRX_H_ 2598b9484cSchristos #define _CRX_H_ 2698b9484cSchristos 2798b9484cSchristos /* CRX core/debug Registers : 2898b9484cSchristos The enums are used as indices to CRX registers table (crx_regtab). 2998b9484cSchristos Therefore, order MUST be preserved. */ 3098b9484cSchristos 3198b9484cSchristos typedef enum 3298b9484cSchristos { 3398b9484cSchristos /* 32-bit general purpose registers. */ 3498b9484cSchristos r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, 3598b9484cSchristos r10, r11, r12, r13, r14, r15, ra, sp, 3698b9484cSchristos /* 32-bit user registers. */ 3798b9484cSchristos u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, 3898b9484cSchristos u10, u11, u12, u13, u14, u15, ura, usp, 3998b9484cSchristos /* hi and lo registers. */ 4098b9484cSchristos hi, lo, 4198b9484cSchristos /* hi and lo user registers. */ 4298b9484cSchristos uhi, ulo, 4398b9484cSchristos /* Processor Status Register. */ 4498b9484cSchristos psr, 4598b9484cSchristos /* Interrupt Base Register. */ 4698b9484cSchristos intbase, 4798b9484cSchristos /* Interrupt Stack Pointer Register. */ 4898b9484cSchristos isp, 4998b9484cSchristos /* Configuration Register. */ 5098b9484cSchristos cfg, 5198b9484cSchristos /* Coprocessor Configuration Register. */ 5298b9484cSchristos cpcfg, 5398b9484cSchristos /* Coprocessor Enable Register. */ 5498b9484cSchristos cen, 5598b9484cSchristos /* Not a register. */ 5698b9484cSchristos nullregister, 5798b9484cSchristos MAX_REG 5898b9484cSchristos } 5998b9484cSchristos reg; 6098b9484cSchristos 6198b9484cSchristos /* CRX Coprocessor registers and special registers : 6298b9484cSchristos The enums are used as indices to CRX coprocessor registers table 6398b9484cSchristos (crx_copregtab). Therefore, order MUST be preserved. */ 6498b9484cSchristos 6598b9484cSchristos typedef enum 6698b9484cSchristos { 6798b9484cSchristos /* Coprocessor registers. */ 6898b9484cSchristos c0 = MAX_REG, c1, c2, c3, c4, c5, c6, c7, c8, 6998b9484cSchristos c9, c10, c11, c12, c13, c14, c15, 7098b9484cSchristos /* Coprocessor special registers. */ 7198b9484cSchristos cs0, cs1 ,cs2, cs3, cs4, cs5, cs6, cs7, cs8, 7298b9484cSchristos cs9, cs10, cs11, cs12, cs13, cs14, cs15, 7398b9484cSchristos /* Not a Coprocessor register. */ 7498b9484cSchristos nullcopregister, 7598b9484cSchristos MAX_COPREG 7698b9484cSchristos } 7798b9484cSchristos copreg; 7898b9484cSchristos 7998b9484cSchristos /* CRX Register types. */ 8098b9484cSchristos 8198b9484cSchristos typedef enum 8298b9484cSchristos { 8398b9484cSchristos CRX_R_REGTYPE, /* r<N> */ 8498b9484cSchristos CRX_U_REGTYPE, /* u<N> */ 8598b9484cSchristos CRX_C_REGTYPE, /* c<N> */ 8698b9484cSchristos CRX_CS_REGTYPE, /* cs<N> */ 8798b9484cSchristos CRX_CFG_REGTYPE /* configuration register */ 8898b9484cSchristos } 8998b9484cSchristos reg_type; 9098b9484cSchristos 9198b9484cSchristos /* CRX argument types : 9298b9484cSchristos The argument types correspond to instructions operands 9398b9484cSchristos 9498b9484cSchristos Argument types : 9598b9484cSchristos r - register 9698b9484cSchristos c - constant 9798b9484cSchristos i - immediate 9898b9484cSchristos idxr - index register 9998b9484cSchristos rbase - register base 10098b9484cSchristos s - star ('*') 10198b9484cSchristos copr - coprocessor register 10298b9484cSchristos copsr - coprocessor special register. */ 10398b9484cSchristos 10498b9484cSchristos typedef enum 10598b9484cSchristos { 10698b9484cSchristos arg_r, arg_c, arg_cr, arg_ic, arg_icr, arg_sc, 10798b9484cSchristos arg_idxr, arg_rbase, arg_copr, arg_copsr, 10898b9484cSchristos /* Not an argument. */ 10998b9484cSchristos nullargs 11098b9484cSchristos } 11198b9484cSchristos argtype; 11298b9484cSchristos 11398b9484cSchristos /* CRX operand types : 11498b9484cSchristos The operand types correspond to instructions operands. */ 11598b9484cSchristos 11698b9484cSchristos typedef enum 11798b9484cSchristos { 11898b9484cSchristos dummy, 11998b9484cSchristos /* 4-bit encoded constant. */ 12098b9484cSchristos cst4, 12198b9484cSchristos /* N-bit immediate. */ 12298b9484cSchristos i16, i32, 12398b9484cSchristos /* N-bit unsigned immediate. */ 12498b9484cSchristos ui3, ui4, ui5, ui16, 12598b9484cSchristos /* N-bit signed displacement. */ 12698b9484cSchristos disps9, disps17, disps25, disps32, 12798b9484cSchristos /* N-bit unsigned displacement. */ 12898b9484cSchristos dispu5, 12998b9484cSchristos /* N-bit escaped displacement. */ 13098b9484cSchristos dispe9, 13198b9484cSchristos /* N-bit absolute address. */ 13298b9484cSchristos abs16, abs32, 13398b9484cSchristos /* Register relative. */ 13498b9484cSchristos rbase, rbase_dispu4, 13598b9484cSchristos rbase_disps12, rbase_disps16, rbase_disps28, rbase_disps32, 13698b9484cSchristos /* Register index. */ 13798b9484cSchristos rindex_disps6, rindex_disps22, 13898b9484cSchristos /* 4-bit genaral-purpose register specifier. */ 13998b9484cSchristos regr, 14098b9484cSchristos /* 8-bit register address space. */ 14198b9484cSchristos regr8, 14298b9484cSchristos /* coprocessor register. */ 14398b9484cSchristos copregr, 14498b9484cSchristos /* coprocessor special register. */ 14598b9484cSchristos copsregr, 14698b9484cSchristos /* Not an operand. */ 14798b9484cSchristos nulloperand, 14898b9484cSchristos /* Maximum supported operand. */ 14998b9484cSchristos MAX_OPRD 15098b9484cSchristos } 15198b9484cSchristos operand_type; 15298b9484cSchristos 15398b9484cSchristos /* CRX instruction types. */ 15498b9484cSchristos 15598b9484cSchristos #define NO_TYPE_INS 0 15698b9484cSchristos #define ARITH_INS 1 15798b9484cSchristos #define LD_STOR_INS 2 15898b9484cSchristos #define BRANCH_INS 3 15998b9484cSchristos #define ARITH_BYTE_INS 4 16098b9484cSchristos #define CMPBR_INS 5 16198b9484cSchristos #define SHIFT_INS 6 16298b9484cSchristos #define BRANCH_NEQ_INS 7 16398b9484cSchristos #define LD_STOR_INS_INC 8 16498b9484cSchristos #define STOR_IMM_INS 9 16598b9484cSchristos #define CSTBIT_INS 10 16698b9484cSchristos #define COP_BRANCH_INS 11 16798b9484cSchristos #define COP_REG_INS 12 16898b9484cSchristos #define COPS_REG_INS 13 16998b9484cSchristos #define DCR_BRANCH_INS 14 17098b9484cSchristos 17198b9484cSchristos /* Maximum value supported for instruction types. */ 17298b9484cSchristos #define CRX_INS_MAX (1 << 4) 17398b9484cSchristos /* Mask to record an instruction type. */ 17498b9484cSchristos #define CRX_INS_MASK (CRX_INS_MAX - 1) 17598b9484cSchristos /* Return instruction type, given instruction's attributes. */ 17698b9484cSchristos #define CRX_INS_TYPE(attr) ((attr) & CRX_INS_MASK) 17798b9484cSchristos 17898b9484cSchristos /* Indicates whether this instruction has a register list as parameter. */ 17998b9484cSchristos #define REG_LIST CRX_INS_MAX 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 /* Kind of displacement map used DISPU[BWD]4. */ 18598b9484cSchristos #define DISPUB4 (1 << 6) 18698b9484cSchristos #define DISPUW4 (1 << 7) 18798b9484cSchristos #define DISPUD4 (1 << 8) 18898b9484cSchristos #define DISPU4MAP (DISPUB4 | DISPUW4 | DISPUD4) 18998b9484cSchristos 19098b9484cSchristos /* Printing formats, where the instruction prefix isn't consecutive. */ 19198b9484cSchristos #define FMT_1 (1 << 9) /* 0xF0F00000 */ 19298b9484cSchristos #define FMT_2 (1 << 10) /* 0xFFF0FF00 */ 19398b9484cSchristos #define FMT_3 (1 << 11) /* 0xFFF00F00 */ 19498b9484cSchristos #define FMT_4 (1 << 12) /* 0xFFF0F000 */ 19598b9484cSchristos #define FMT_5 (1 << 13) /* 0xFFF0FFF0 */ 19698b9484cSchristos #define FMT_CRX (FMT_1 | FMT_2 | FMT_3 | FMT_4 | FMT_5) 19798b9484cSchristos 19898b9484cSchristos /* Indicates whether this instruction can be relaxed. */ 19998b9484cSchristos #define RELAXABLE (1 << 14) 20098b9484cSchristos 20198b9484cSchristos /* Indicates that instruction uses user registers (and not 20298b9484cSchristos general-purpose registers) as operands. */ 20398b9484cSchristos #define USER_REG (1 << 15) 20498b9484cSchristos 20598b9484cSchristos /* Indicates that instruction can perfom a cst4 mapping. */ 20698b9484cSchristos #define CST4MAP (1 << 16) 20798b9484cSchristos 20898b9484cSchristos /* Instruction shouldn't allow 'sp' usage. */ 20998b9484cSchristos #define NO_SP (1 << 17) 21098b9484cSchristos 21198b9484cSchristos /* Instruction shouldn't allow to push a register which is used as a rptr. */ 21298b9484cSchristos #define NO_RPTR (1 << 18) 21398b9484cSchristos 21498b9484cSchristos /* Maximum operands per instruction. */ 21598b9484cSchristos #define MAX_OPERANDS 5 21698b9484cSchristos /* Maximum register name length. */ 21798b9484cSchristos #define MAX_REGNAME_LEN 10 21898b9484cSchristos /* Maximum instruction length. */ 21998b9484cSchristos #define MAX_INST_LEN 256 22098b9484cSchristos 22198b9484cSchristos 22298b9484cSchristos /* Values defined for the flags field of a struct operand_entry. */ 22398b9484cSchristos 22498b9484cSchristos /* Operand must be an unsigned number. */ 22598b9484cSchristos #define OP_UNSIGNED (1 << 0) 22698b9484cSchristos /* Operand must be a signed number. */ 22798b9484cSchristos #define OP_SIGNED (1 << 1) 22898b9484cSchristos /* A special arithmetic 4-bit constant operand. */ 22998b9484cSchristos #define OP_CST4 (1 << 2) 23098b9484cSchristos /* A special load/stor 4-bit unsigned displacement operand. */ 23198b9484cSchristos #define OP_DISPU4 (1 << 3) 23298b9484cSchristos /* Operand must be an even number. */ 23398b9484cSchristos #define OP_EVEN (1 << 4) 23498b9484cSchristos /* Operand is shifted right. */ 23598b9484cSchristos #define OP_SHIFT (1 << 5) 23698b9484cSchristos /* Operand is shifted right and decremented. */ 23798b9484cSchristos #define OP_SHIFT_DEC (1 << 6) 23898b9484cSchristos /* Operand has reserved escape sequences. */ 23998b9484cSchristos #define OP_ESC (1 << 7) 24098b9484cSchristos /* Operand is used only for the upper 64 KB (FFFF0000 to FFFFFFFF). */ 24198b9484cSchristos #define OP_UPPER_64KB (1 << 8) 24298b9484cSchristos 24398b9484cSchristos /* Single operand description. */ 24498b9484cSchristos 24598b9484cSchristos typedef struct 24698b9484cSchristos { 24798b9484cSchristos /* Operand type. */ 24898b9484cSchristos operand_type op_type; 24998b9484cSchristos /* Operand location within the opcode. */ 25098b9484cSchristos unsigned int shift; 25198b9484cSchristos } 25298b9484cSchristos operand_desc; 25398b9484cSchristos 25498b9484cSchristos /* Instruction data structure used in instruction table. */ 25598b9484cSchristos 25698b9484cSchristos typedef struct 25798b9484cSchristos { 25898b9484cSchristos /* Name. */ 25998b9484cSchristos const char *mnemonic; 26098b9484cSchristos /* Size (in words). */ 26198b9484cSchristos unsigned int size; 26298b9484cSchristos /* Constant prefix (matched by the disassembler). */ 2638dffb485Schristos unsigned int match; 26498b9484cSchristos /* Match size (in bits). */ 26598b9484cSchristos int match_bits; 26698b9484cSchristos /* Attributes. */ 26798b9484cSchristos unsigned int flags; 26898b9484cSchristos /* Operands (always last, so unreferenced operands are initialized). */ 26998b9484cSchristos operand_desc operands[MAX_OPERANDS]; 27098b9484cSchristos } 27198b9484cSchristos inst; 27298b9484cSchristos 27398b9484cSchristos /* Data structure for a single instruction's arguments (Operands). */ 27498b9484cSchristos 27598b9484cSchristos typedef struct 27698b9484cSchristos { 27798b9484cSchristos /* Register or base register. */ 27898b9484cSchristos reg r; 27998b9484cSchristos /* Index register. */ 28098b9484cSchristos reg i_r; 28198b9484cSchristos /* Coprocessor register. */ 28298b9484cSchristos copreg cr; 28398b9484cSchristos /* Constant/immediate/absolute value. */ 28498b9484cSchristos long constant; 28598b9484cSchristos /* Scaled index mode. */ 28698b9484cSchristos unsigned int scale; 28798b9484cSchristos /* Argument type. */ 28898b9484cSchristos argtype type; 28998b9484cSchristos /* Size of the argument (in bits) required to represent. */ 29098b9484cSchristos int size; 29198b9484cSchristos /* The type of the expression. */ 29298b9484cSchristos unsigned char X_op; 29398b9484cSchristos } 29498b9484cSchristos argument; 29598b9484cSchristos 29698b9484cSchristos /* Internal structure to hold the various entities 29798b9484cSchristos corresponding to the current assembling instruction. */ 29898b9484cSchristos 29998b9484cSchristos typedef struct 30098b9484cSchristos { 30198b9484cSchristos /* Number of arguments. */ 30298b9484cSchristos int nargs; 30398b9484cSchristos /* The argument data structure for storing args (operands). */ 30498b9484cSchristos argument arg[MAX_OPERANDS]; 30598b9484cSchristos /* The following fields are required only by CRX-assembler. */ 30698b9484cSchristos #ifdef TC_CRX 30798b9484cSchristos /* Expression used for setting the fixups (if any). */ 30898b9484cSchristos expressionS exp; 30998b9484cSchristos bfd_reloc_code_real_type rtype; 31098b9484cSchristos #endif /* TC_CRX */ 31198b9484cSchristos /* Instruction size (in bytes). */ 31298b9484cSchristos int size; 31398b9484cSchristos } 31498b9484cSchristos ins; 31598b9484cSchristos 31698b9484cSchristos /* Structure to hold information about predefined operands. */ 31798b9484cSchristos 31898b9484cSchristos typedef struct 31998b9484cSchristos { 32098b9484cSchristos /* Size (in bits). */ 32198b9484cSchristos unsigned int bit_size; 32298b9484cSchristos /* Argument type. */ 32398b9484cSchristos argtype arg_type; 32498b9484cSchristos /* One bit syntax flags. */ 32598b9484cSchristos int flags; 32698b9484cSchristos } 32798b9484cSchristos operand_entry; 32898b9484cSchristos 32998b9484cSchristos /* Structure to hold trap handler information. */ 33098b9484cSchristos 33198b9484cSchristos typedef struct 33298b9484cSchristos { 33398b9484cSchristos /* Trap name. */ 33498b9484cSchristos char *name; 33598b9484cSchristos /* Index in dispatch table. */ 33698b9484cSchristos unsigned int entry; 33798b9484cSchristos } 33898b9484cSchristos trap_entry; 33998b9484cSchristos 34098b9484cSchristos /* Structure to hold information about predefined registers. */ 34198b9484cSchristos 34298b9484cSchristos typedef struct 34398b9484cSchristos { 34498b9484cSchristos /* Name (string representation). */ 34598b9484cSchristos char *name; 34698b9484cSchristos /* Value (enum representation). */ 34798b9484cSchristos union 34898b9484cSchristos { 34998b9484cSchristos /* Register. */ 35098b9484cSchristos reg reg_val; 35198b9484cSchristos /* Coprocessor register. */ 35298b9484cSchristos copreg copreg_val; 35398b9484cSchristos } value; 35498b9484cSchristos /* Register image. */ 35598b9484cSchristos int image; 35698b9484cSchristos /* Register type. */ 35798b9484cSchristos reg_type type; 35898b9484cSchristos } 35998b9484cSchristos reg_entry; 36098b9484cSchristos 36198b9484cSchristos /* Structure to hold a cst4 operand mapping. */ 36298b9484cSchristos 36398b9484cSchristos /* CRX opcode table. */ 36498b9484cSchristos extern const inst crx_instruction[]; 36598b9484cSchristos extern const int crx_num_opcodes; 36698b9484cSchristos #define NUMOPCODES crx_num_opcodes 36798b9484cSchristos 36898b9484cSchristos /* CRX operands table. */ 36998b9484cSchristos extern const operand_entry crx_optab[]; 37098b9484cSchristos 37198b9484cSchristos /* CRX registers table. */ 37298b9484cSchristos extern const reg_entry crx_regtab[]; 37398b9484cSchristos extern const int crx_num_regs; 37498b9484cSchristos #define NUMREGS crx_num_regs 37598b9484cSchristos 37698b9484cSchristos /* CRX coprocessor registers table. */ 37798b9484cSchristos extern const reg_entry crx_copregtab[]; 37898b9484cSchristos extern const int crx_num_copregs; 37998b9484cSchristos #define NUMCOPREGS crx_num_copregs 38098b9484cSchristos 38198b9484cSchristos /* CRX trap/interrupt table. */ 38298b9484cSchristos extern const trap_entry crx_traps[]; 38398b9484cSchristos extern const int crx_num_traps; 38498b9484cSchristos #define NUMTRAPS crx_num_traps 38598b9484cSchristos 38698b9484cSchristos /* cst4 operand mapping. */ 3874559860eSchristos extern const int crx_cst4_map[]; 3884559860eSchristos extern const int crx_cst4_maps; 38998b9484cSchristos 39098b9484cSchristos /* Table of instructions with no operands. */ 3914559860eSchristos extern const char* crx_no_op_insn[]; 39298b9484cSchristos 39398b9484cSchristos /* A macro for representing the instruction "constant" opcode, that is, 39498b9484cSchristos the FIXED part of the instruction. The "constant" opcode is represented 39598b9484cSchristos as a 32-bit unsigned long, where OPC is expanded (by a left SHIFT) 39698b9484cSchristos over that range. */ 39798b9484cSchristos #define BIN(OPC,SHIFT) (OPC << SHIFT) 39898b9484cSchristos 39998b9484cSchristos /* Is the current instruction type is TYPE ? */ 40098b9484cSchristos #define IS_INSN_TYPE(TYPE) \ 40198b9484cSchristos (CRX_INS_TYPE(instruction->flags) == TYPE) 40298b9484cSchristos 40398b9484cSchristos /* Is the current instruction mnemonic is MNEMONIC ? */ 40498b9484cSchristos #define IS_INSN_MNEMONIC(MNEMONIC) \ 40598b9484cSchristos (strcmp(instruction->mnemonic,MNEMONIC) == 0) 40698b9484cSchristos 40798b9484cSchristos /* Does the current instruction has register list ? */ 40898b9484cSchristos #define INST_HAS_REG_LIST \ 40998b9484cSchristos (instruction->flags & REG_LIST) 41098b9484cSchristos 41198b9484cSchristos /* Long long type handling. */ 41298b9484cSchristos /* Replace all appearances of 'long long int' with LONGLONG. */ 41398b9484cSchristos typedef long long int LONGLONG; 41498b9484cSchristos typedef unsigned long long ULONGLONG; 41598b9484cSchristos 41698b9484cSchristos #endif /* _CRX_H_ */ 417