198b9484cSchristos /* cris.h -- Header file for CRIS opcode and register tables. 2*02f41505Schristos Copyright (C) 2000-2024 Free Software Foundation, Inc. 398b9484cSchristos Contributed by Axis Communications AB, Lund, Sweden. 498b9484cSchristos Originally written for GAS 1.38.1 by Mikael Asker. 598b9484cSchristos Updated, BFDized and GNUified by Hans-Peter Nilsson. 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 __CRIS_H_INCLUDED_ 2598b9484cSchristos #define __CRIS_H_INCLUDED_ 2698b9484cSchristos 2798b9484cSchristos #if !defined(__STDC__) && !defined(const) 2898b9484cSchristos #define const 2998b9484cSchristos #endif 3098b9484cSchristos 3198b9484cSchristos 3298b9484cSchristos /* Registers. */ 3398b9484cSchristos #define MAX_REG (15) 3498b9484cSchristos #define REG_SP (14) 3598b9484cSchristos #define REG_PC (15) 3698b9484cSchristos 3798b9484cSchristos /* CPU version control of disassembly and assembly of instructions. 3898b9484cSchristos May affect how the instruction is assembled, at least the size of 3998b9484cSchristos immediate operands. */ 4098b9484cSchristos enum cris_insn_version_usage 4198b9484cSchristos { 4298b9484cSchristos /* Any version. */ 4398b9484cSchristos cris_ver_version_all=0, 4498b9484cSchristos 4598b9484cSchristos /* Indeterminate (intended for disassembly only, or obsolete). */ 4698b9484cSchristos cris_ver_warning, 4798b9484cSchristos 4898b9484cSchristos /* Only for v0..3 (Etrax 1..4). */ 4998b9484cSchristos cris_ver_v0_3, 5098b9484cSchristos 5198b9484cSchristos /* Only for v3 or higher (ETRAX 4 and beyond). */ 5298b9484cSchristos cris_ver_v3p, 5398b9484cSchristos 5498b9484cSchristos /* Only for v8 (Etrax 100). */ 5598b9484cSchristos cris_ver_v8, 5698b9484cSchristos 5798b9484cSchristos /* Only for v8 or higher (ETRAX 100, ETRAX 100 LX). */ 5898b9484cSchristos cris_ver_v8p, 5998b9484cSchristos 6098b9484cSchristos /* Only for v0..10. FIXME: Not sure what to do with this. */ 6198b9484cSchristos cris_ver_sim_v0_10, 6298b9484cSchristos 6398b9484cSchristos /* Only for v0..10. */ 6498b9484cSchristos cris_ver_v0_10, 6598b9484cSchristos 6698b9484cSchristos /* Only for v3..10. (ETRAX 4, ETRAX 100 and ETRAX 100 LX). */ 6798b9484cSchristos cris_ver_v3_10, 6898b9484cSchristos 6998b9484cSchristos /* Only for v8..10 (ETRAX 100 and ETRAX 100 LX). */ 7098b9484cSchristos cris_ver_v8_10, 7198b9484cSchristos 7298b9484cSchristos /* Only for v10 (ETRAX 100 LX) and same series. */ 7398b9484cSchristos cris_ver_v10, 7498b9484cSchristos 7598b9484cSchristos /* Only for v10 (ETRAX 100 LX) and same series. */ 7698b9484cSchristos cris_ver_v10p, 7798b9484cSchristos 7898b9484cSchristos /* Only for v32 or higher (codename GUINNESS). 7998b9484cSchristos Of course some or all these of may change to cris_ver_v32p if/when 8098b9484cSchristos there's a new revision. */ 8198b9484cSchristos cris_ver_v32p 8298b9484cSchristos }; 8398b9484cSchristos 8498b9484cSchristos 8598b9484cSchristos /* Special registers. */ 8698b9484cSchristos struct cris_spec_reg 8798b9484cSchristos { 8898b9484cSchristos const char *const name; 8998b9484cSchristos unsigned int number; 9098b9484cSchristos 9198b9484cSchristos /* The size of the register. */ 9298b9484cSchristos unsigned int reg_size; 9398b9484cSchristos 9498b9484cSchristos /* What CPU version the special register of that name is implemented 9598b9484cSchristos in. If cris_ver_warning, emit an unimplemented-warning. */ 9698b9484cSchristos enum cris_insn_version_usage applicable_version; 9798b9484cSchristos 9898b9484cSchristos /* There might be a specific warning for using a special register 9998b9484cSchristos here. */ 10098b9484cSchristos const char *const warning; 10198b9484cSchristos }; 10298b9484cSchristos extern const struct cris_spec_reg cris_spec_regs[]; 10398b9484cSchristos 10498b9484cSchristos 10598b9484cSchristos /* Support registers (kind of special too, but not named as such). */ 10698b9484cSchristos struct cris_support_reg 10798b9484cSchristos { 10898b9484cSchristos const char *const name; 10998b9484cSchristos unsigned int number; 11098b9484cSchristos }; 11198b9484cSchristos extern const struct cris_support_reg cris_support_regs[]; 11298b9484cSchristos 11398b9484cSchristos struct cris_cond15 11498b9484cSchristos { 11598b9484cSchristos /* The name of the condition. */ 11698b9484cSchristos const char *const name; 11798b9484cSchristos 11898b9484cSchristos /* What CPU version this condition name applies to. */ 11998b9484cSchristos enum cris_insn_version_usage applicable_version; 12098b9484cSchristos }; 12198b9484cSchristos extern const struct cris_cond15 cris_conds15[]; 12298b9484cSchristos 12398b9484cSchristos /* Opcode-dependent constants. */ 12498b9484cSchristos #define AUTOINCR_BIT (0x04) 12598b9484cSchristos 12698b9484cSchristos /* Prefixes. */ 12798b9484cSchristos #define BDAP_QUICK_OPCODE (0x0100) 12898b9484cSchristos #define BDAP_QUICK_Z_BITS (0x0e00) 12998b9484cSchristos 13098b9484cSchristos #define BIAP_OPCODE (0x0540) 13198b9484cSchristos #define BIAP_Z_BITS (0x0a80) 13298b9484cSchristos 13398b9484cSchristos #define DIP_OPCODE (0x0970) 13498b9484cSchristos #define DIP_Z_BITS (0xf280) 13598b9484cSchristos 13698b9484cSchristos #define BDAP_INDIR_LOW (0x40) 13798b9484cSchristos #define BDAP_INDIR_LOW_Z (0x80) 13898b9484cSchristos #define BDAP_INDIR_HIGH (0x09) 13998b9484cSchristos #define BDAP_INDIR_HIGH_Z (0x02) 14098b9484cSchristos 14198b9484cSchristos #define BDAP_INDIR_OPCODE (BDAP_INDIR_HIGH * 0x0100 + BDAP_INDIR_LOW) 14298b9484cSchristos #define BDAP_INDIR_Z_BITS (BDAP_INDIR_HIGH_Z * 0x100 + BDAP_INDIR_LOW_Z) 14398b9484cSchristos #define BDAP_PC_LOW (BDAP_INDIR_LOW + REG_PC) 14498b9484cSchristos #define BDAP_INCR_HIGH (BDAP_INDIR_HIGH + AUTOINCR_BIT) 14598b9484cSchristos 14698b9484cSchristos /* No prefix must have this code for its "match" bits in the 14798b9484cSchristos opcode-table. "BCC .+2" will do nicely. */ 14898b9484cSchristos #define NO_CRIS_PREFIX 0 14998b9484cSchristos 15098b9484cSchristos /* Definitions for condition codes. */ 15198b9484cSchristos #define CC_CC 0x0 15298b9484cSchristos #define CC_HS 0x0 15398b9484cSchristos #define CC_CS 0x1 15498b9484cSchristos #define CC_LO 0x1 15598b9484cSchristos #define CC_NE 0x2 15698b9484cSchristos #define CC_EQ 0x3 15798b9484cSchristos #define CC_VC 0x4 15898b9484cSchristos #define CC_VS 0x5 15998b9484cSchristos #define CC_PL 0x6 16098b9484cSchristos #define CC_MI 0x7 16198b9484cSchristos #define CC_LS 0x8 16298b9484cSchristos #define CC_HI 0x9 16398b9484cSchristos #define CC_GE 0xA 16498b9484cSchristos #define CC_LT 0xB 16598b9484cSchristos #define CC_GT 0xC 16698b9484cSchristos #define CC_LE 0xD 16798b9484cSchristos #define CC_A 0xE 16898b9484cSchristos #define CC_EXT 0xF 16998b9484cSchristos 17098b9484cSchristos /* A table of strings "cc", "cs"... indexed with condition code 17198b9484cSchristos values as above. */ 17298b9484cSchristos extern const char *const cris_cc_strings[]; 17398b9484cSchristos 17498b9484cSchristos /* Bcc quick. */ 17598b9484cSchristos #define BRANCH_QUICK_LOW (0) 17698b9484cSchristos #define BRANCH_QUICK_HIGH (0) 17798b9484cSchristos #define BRANCH_QUICK_OPCODE (BRANCH_QUICK_HIGH * 0x0100 + BRANCH_QUICK_LOW) 17898b9484cSchristos #define BRANCH_QUICK_Z_BITS (0x0F00) 17998b9484cSchristos 18098b9484cSchristos /* BA quick. */ 18198b9484cSchristos #define BA_QUICK_HIGH (BRANCH_QUICK_HIGH + CC_A * 0x10) 18298b9484cSchristos #define BA_QUICK_OPCODE (BA_QUICK_HIGH * 0x100 + BRANCH_QUICK_LOW) 18398b9484cSchristos 18498b9484cSchristos /* Bcc [PC+]. */ 18598b9484cSchristos #define BRANCH_PC_LOW (0xFF) 18698b9484cSchristos #define BRANCH_INCR_HIGH (0x0D) 18798b9484cSchristos #define BA_PC_INCR_OPCODE \ 18898b9484cSchristos ((BRANCH_INCR_HIGH + CC_A * 0x10) * 0x0100 + BRANCH_PC_LOW) 18998b9484cSchristos 19098b9484cSchristos /* Jump. */ 19198b9484cSchristos /* Note that old versions generated special register 8 (in high bits) 19298b9484cSchristos and not-that-old versions recognized it as a jump-instruction. 19398b9484cSchristos That opcode now belongs to JUMPU. */ 19498b9484cSchristos #define JUMP_INDIR_OPCODE (0x0930) 19598b9484cSchristos #define JUMP_INDIR_Z_BITS (0xf2c0) 19698b9484cSchristos #define JUMP_PC_INCR_OPCODE \ 19798b9484cSchristos (JUMP_INDIR_OPCODE + AUTOINCR_BIT * 0x0100 + REG_PC) 19898b9484cSchristos 19998b9484cSchristos #define MOVE_M_TO_PREG_OPCODE 0x0a30 20098b9484cSchristos #define MOVE_M_TO_PREG_ZBITS 0x01c0 20198b9484cSchristos 20298b9484cSchristos /* BDAP.D N,PC. */ 20398b9484cSchristos #define MOVE_PC_INCR_OPCODE_PREFIX \ 20498b9484cSchristos (((BDAP_INCR_HIGH | (REG_PC << 4)) << 8) | BDAP_PC_LOW | (2 << 4)) 20598b9484cSchristos #define MOVE_PC_INCR_OPCODE_SUFFIX \ 20698b9484cSchristos (MOVE_M_TO_PREG_OPCODE | REG_PC | (AUTOINCR_BIT << 8)) 20798b9484cSchristos 20898b9484cSchristos #define JUMP_PC_INCR_OPCODE_V32 (0x0DBF) 20998b9484cSchristos 21098b9484cSchristos /* BA DWORD (V32). */ 21198b9484cSchristos #define BA_DWORD_OPCODE (0x0EBF) 21298b9484cSchristos 21398b9484cSchristos /* Nop. */ 21498b9484cSchristos #define NOP_OPCODE (0x050F) 21598b9484cSchristos #define NOP_Z_BITS (0xFFFF ^ NOP_OPCODE) 21698b9484cSchristos 21798b9484cSchristos #define NOP_OPCODE_V32 (0x05B0) 21898b9484cSchristos #define NOP_Z_BITS_V32 (0xFFFF ^ NOP_OPCODE_V32) 21998b9484cSchristos 22098b9484cSchristos /* For the compatibility mode, let's use "MOVE R0,P0". Doesn't affect 22198b9484cSchristos registers or flags. Unfortunately shuts off interrupts for one cycle 22298b9484cSchristos for < v32, but there doesn't seem to be any alternative without that 22398b9484cSchristos effect. */ 22498b9484cSchristos #define NOP_OPCODE_COMMON (0x630) 22598b9484cSchristos #define NOP_OPCODE_ZBITS_COMMON (0xffff & ~NOP_OPCODE_COMMON) 22698b9484cSchristos 22798b9484cSchristos /* LAPC.D */ 22898b9484cSchristos #define LAPC_DWORD_OPCODE (0x0D7F) 22998b9484cSchristos #define LAPC_DWORD_Z_BITS (0x0fff & ~LAPC_DWORD_OPCODE) 23098b9484cSchristos 23198b9484cSchristos /* Structure of an opcode table entry. */ 23298b9484cSchristos enum cris_imm_oprnd_size_type 23398b9484cSchristos { 23498b9484cSchristos /* No size is applicable. */ 23598b9484cSchristos SIZE_NONE, 23698b9484cSchristos 23798b9484cSchristos /* Always 32 bits. */ 23898b9484cSchristos SIZE_FIX_32, 23998b9484cSchristos 24098b9484cSchristos /* Indicated by size of special register. */ 24198b9484cSchristos SIZE_SPEC_REG, 24298b9484cSchristos 24398b9484cSchristos /* Indicated by size field, signed. */ 24498b9484cSchristos SIZE_FIELD_SIGNED, 24598b9484cSchristos 24698b9484cSchristos /* Indicated by size field, unsigned. */ 24798b9484cSchristos SIZE_FIELD_UNSIGNED, 24898b9484cSchristos 24998b9484cSchristos /* Indicated by size field, no sign implied. */ 25098b9484cSchristos SIZE_FIELD 25198b9484cSchristos }; 25298b9484cSchristos 25398b9484cSchristos /* For GDB. FIXME: Is this the best way to handle opcode 25498b9484cSchristos interpretation? */ 25598b9484cSchristos enum cris_op_type 25698b9484cSchristos { 25798b9484cSchristos cris_not_implemented_op = 0, 25898b9484cSchristos cris_abs_op, 25998b9484cSchristos cris_addi_op, 26098b9484cSchristos cris_asr_op, 26198b9484cSchristos cris_asrq_op, 26298b9484cSchristos cris_ax_ei_setf_op, 26398b9484cSchristos cris_bdap_prefix, 26498b9484cSchristos cris_biap_prefix, 26598b9484cSchristos cris_break_op, 26698b9484cSchristos cris_btst_nop_op, 26798b9484cSchristos cris_clearf_di_op, 26898b9484cSchristos cris_dip_prefix, 26998b9484cSchristos cris_dstep_logshift_mstep_neg_not_op, 27098b9484cSchristos cris_eight_bit_offset_branch_op, 27198b9484cSchristos cris_move_mem_to_reg_movem_op, 27298b9484cSchristos cris_move_reg_to_mem_movem_op, 27398b9484cSchristos cris_move_to_preg_op, 27498b9484cSchristos cris_muls_op, 27598b9484cSchristos cris_mulu_op, 27698b9484cSchristos cris_none_reg_mode_add_sub_cmp_and_or_move_op, 27798b9484cSchristos cris_none_reg_mode_clear_test_op, 27898b9484cSchristos cris_none_reg_mode_jump_op, 27998b9484cSchristos cris_none_reg_mode_move_from_preg_op, 28098b9484cSchristos cris_quick_mode_add_sub_op, 28198b9484cSchristos cris_quick_mode_and_cmp_move_or_op, 28298b9484cSchristos cris_quick_mode_bdap_prefix, 28398b9484cSchristos cris_reg_mode_add_sub_cmp_and_or_move_op, 28498b9484cSchristos cris_reg_mode_clear_op, 28598b9484cSchristos cris_reg_mode_jump_op, 28698b9484cSchristos cris_reg_mode_move_from_preg_op, 28798b9484cSchristos cris_reg_mode_test_op, 28898b9484cSchristos cris_scc_op, 28998b9484cSchristos cris_sixteen_bit_offset_branch_op, 29098b9484cSchristos cris_three_operand_add_sub_cmp_and_or_op, 29198b9484cSchristos cris_three_operand_bound_op, 29298b9484cSchristos cris_two_operand_bound_op, 29398b9484cSchristos cris_xor_op 29498b9484cSchristos }; 29598b9484cSchristos 29698b9484cSchristos struct cris_opcode 29798b9484cSchristos { 29898b9484cSchristos /* The name of the insn. */ 29998b9484cSchristos const char *name; 30098b9484cSchristos 30198b9484cSchristos /* Bits that must be 1 for a match. */ 30298b9484cSchristos unsigned int match; 30398b9484cSchristos 30498b9484cSchristos /* Bits that must be 0 for a match. */ 30598b9484cSchristos unsigned int lose; 30698b9484cSchristos 30798b9484cSchristos /* See the table in "opcodes/cris-opc.c". */ 30898b9484cSchristos const char *args; 30998b9484cSchristos 31098b9484cSchristos /* Nonzero if this is a delayed branch instruction. */ 31198b9484cSchristos char delayed; 31298b9484cSchristos 31398b9484cSchristos /* Size of immediate operands. */ 31498b9484cSchristos enum cris_imm_oprnd_size_type imm_oprnd_size; 31598b9484cSchristos 31698b9484cSchristos /* Indicates which version this insn was first implemented in. */ 31798b9484cSchristos enum cris_insn_version_usage applicable_version; 31898b9484cSchristos 31998b9484cSchristos /* What kind of operation this is. */ 32098b9484cSchristos enum cris_op_type op; 32198b9484cSchristos }; 32298b9484cSchristos extern const struct cris_opcode cris_opcodes[]; 32398b9484cSchristos 32498b9484cSchristos 32598b9484cSchristos /* These macros are for the target-specific flags in disassemble_info 32698b9484cSchristos used at disassembly. */ 32798b9484cSchristos 32898b9484cSchristos /* This insn accesses memory. This flag is more trustworthy than 32998b9484cSchristos checking insn_type for "dis_dref" which does not work for 33098b9484cSchristos e.g. "JSR [foo]". */ 33198b9484cSchristos #define CRIS_DIS_FLAG_MEMREF (1 << 0) 33298b9484cSchristos 33398b9484cSchristos /* The "target" field holds a register number. */ 33498b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET_IS_REG (1 << 1) 33598b9484cSchristos 33698b9484cSchristos /* The "target2" field holds a register number; add it to "target". */ 33798b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_IS_REG (1 << 2) 33898b9484cSchristos 33998b9484cSchristos /* Yet another add-on: the register in "target2" must be multiplied 34098b9484cSchristos by 2 before adding to "target". */ 34198b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MULT2 (1 << 3) 34298b9484cSchristos 34398b9484cSchristos /* Yet another add-on: the register in "target2" must be multiplied 34498b9484cSchristos by 4 (mutually exclusive with .._MULT2). */ 34598b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MULT4 (1 << 4) 34698b9484cSchristos 34798b9484cSchristos /* The register in "target2" is an indirect memory reference (of the 34898b9484cSchristos register there), add to "target". Assumed size is dword (mutually 34998b9484cSchristos exclusive with .._MULT[24]). */ 35098b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM (1 << 5) 35198b9484cSchristos 35298b9484cSchristos /* Add-on to CRIS_DIS_FLAG_MEM_TARGET2_MEM; the memory access is "byte"; 35398b9484cSchristos sign-extended before adding to "target". */ 35498b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM_BYTE (1 << 6) 35598b9484cSchristos 35698b9484cSchristos /* Add-on to CRIS_DIS_FLAG_MEM_TARGET2_MEM; the memory access is "word"; 35798b9484cSchristos sign-extended before adding to "target". */ 35898b9484cSchristos #define CRIS_DIS_FLAG_MEM_TARGET2_MEM_WORD (1 << 7) 35998b9484cSchristos 36098b9484cSchristos #endif /* __CRIS_H_INCLUDED_ */ 36198b9484cSchristos 36298b9484cSchristos /* 36398b9484cSchristos * Local variables: 36498b9484cSchristos * eval: (c-set-style "gnu") 36598b9484cSchristos * indent-tabs-mode: t 36698b9484cSchristos * End: 36798b9484cSchristos */ 368