hppa-dis.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,190 行 · 第 1/3 页

C
1,190
字号
/* Disassembler for the PA-RISC. Somewhat derived from sparc-pinsn.c.   Copyright 1989, 1990, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001   Free Software Foundation, Inc.   Contributed by the Center for Software Science at the   University of Utah (pa-gdb-bugs@cs.utah.edu).This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#include "sysdep.h"#include "dis-asm.h"#include "libhppa.h"#include "opcode/hppa.h"/* Integer register names, indexed by the numbers which appear in the   opcodes.  */static const char *const reg_names[] =  {"flags", "r1", "rp", "r3", "r4", "r5", "r6", "r7", "r8", "r9",  "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",  "r20", "r21", "r22", "r23", "r24", "r25", "r26", "dp", "ret0", "ret1",  "sp", "r31"};/* Floating point register names, indexed by the numbers which appear in the   opcodes.  */static const char *const fp_reg_names[] =  {"fpsr", "fpe2", "fpe4", "fpe6",   "fr4", "fr5", "fr6", "fr7", "fr8",   "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",   "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",  "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31"};typedef unsigned int CORE_ADDR;/* Get at various relevent fields of an instruction word.  */#define MASK_5 0x1f#define MASK_10 0x3ff#define MASK_11 0x7ff#define MASK_14 0x3fff#define MASK_16 0xffff#define MASK_21 0x1fffff/* These macros get bit fields using HP's numbering (MSB = 0) */#define GET_FIELD(X, FROM, TO) \  ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))#define GET_BIT(X, WHICH) \  GET_FIELD (X, WHICH, WHICH)/* Some of these have been converted to 2-d arrays because they   consume less storage this way.  If the maintenance becomes a   problem, convert them back to const 1-d pointer arrays.  */static const char *const control_reg[] = {  "rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",  "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4",  "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr",  "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3",  "tr4", "tr5", "tr6", "tr7"};static const char *const compare_cond_names[] = {  "", ",=", ",<", ",<=", ",<<", ",<<=", ",sv", ",od",  ",tr", ",<>", ",>=", ",>", ",>>=", ",>>", ",nsv", ",ev"};static const char *const compare_cond_64_names[] = {  "", ",*=", ",*<", ",*<=", ",*<<", ",*<<=", ",*sv", ",*od",  ",*tr", ",*<>", ",*>=", ",*>", ",*>>=", ",*>>", ",*nsv", ",*ev"};static const char *const cmpib_cond_64_names[] = {  ",*<<", ",*=", ",*<", ",*<=", ",*>>=", ",*<>", ",*>=", ",*>"};static const char *const add_cond_names[] = {  "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv", ",od",  ",tr", ",<>", ",>=", ",>", ",uv", ",vnz", ",nsv", ",ev"};static const char *const add_cond_64_names[] = {  "", ",*=", ",*<", ",*<=", ",*nuv", ",*znv", ",*sv", ",*od",  ",*tr", ",*<>", ",*>=", ",*>", ",*uv", ",*vnz", ",*nsv", ",*ev"};static const char *const wide_add_cond_names[] = {  "", ",=", ",<", ",<=", ",nuv", ",*=", ",*<", ",*<=",  ",tr", ",<>", ",>=", ",>", ",uv", ",*<>", ",*>=", ",*>"};static const char *const logical_cond_names[] = {  "", ",=", ",<", ",<=", 0, 0, 0, ",od",  ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};static const char *const logical_cond_64_names[] = {  "", ",*=", ",*<", ",*<=", 0, 0, 0, ",*od",  ",*tr", ",*<>", ",*>=", ",*>", 0, 0, 0, ",*ev"};static const char *const unit_cond_names[] = {  "", ",swz", ",sbz", ",shz", ",sdc", ",swc", ",sbc", ",shc",  ",tr", ",nwz", ",nbz", ",nhz", ",ndc", ",nwc", ",nbc", ",nhc"};static const char *const unit_cond_64_names[] = {  "", ",*swz", ",*sbz", ",*shz", ",*sdc", ",*swc", ",*sbc", ",*shc",  ",*tr", ",*nwz", ",*nbz", ",*nhz", ",*ndc", ",*nwc", ",*nbc", ",*nhc"};static const char *const shift_cond_names[] = {  "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"};static const char *const shift_cond_64_names[] = {  "", ",*=", ",*<", ",*od", ",*tr", ",*<>", ",*>=", ",*ev"};static const char *const bb_cond_64_names[] = {  ",*<", ",*>="};static const char *const index_compl_names[] = {"", ",m", ",s", ",sm"};static const char *const short_ldst_compl_names[] = {"", ",ma", "", ",mb"};static const char *const short_bytes_compl_names[] = {  "", ",b,m", ",e", ",e,m"};static const char *const float_format_names[] = {",sgl", ",dbl", "", ",quad"};static const char *const float_comp_names[] ={  ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",  ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",  ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",  ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"};static const char *const signed_unsigned_names[] = {",u", ",s"};static const char *const mix_half_names[] = {",l", ",r"};static const char *const saturation_names[] = {",us", ",ss", 0, ""};static const char *const read_write_names[] = {",r", ",w"};static const char *const add_compl_names[] = { 0, "", ",l", ",tsv" };/* For a bunch of different instructions form an index into a    completer name table.  */#define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \			 GET_FIELD (insn, 18, 18) << 1)#define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \			(GET_FIELD ((insn), 19, 19) ? 8 : 0))static void fput_reg PARAMS ((unsigned int, disassemble_info *));static void fput_fp_reg PARAMS ((unsigned int, disassemble_info *));static void fput_fp_reg_r PARAMS ((unsigned int, disassemble_info *));static void fput_creg PARAMS ((unsigned int, disassemble_info *));static void fput_const PARAMS ((unsigned int, disassemble_info *));static int extract_3 PARAMS ((unsigned int));static int extract_5_load PARAMS ((unsigned int));static int extract_5_store PARAMS ((unsigned int));static unsigned extract_5r_store PARAMS ((unsigned int));static unsigned extract_5R_store PARAMS ((unsigned int));static unsigned extract_10U_store PARAMS ((unsigned int));static unsigned extract_5Q_store PARAMS ((unsigned int));static int extract_11 PARAMS ((unsigned int));static int extract_14 PARAMS ((unsigned int));static int extract_16 PARAMS ((unsigned int));static int extract_21 PARAMS ((unsigned int));static int extract_12 PARAMS ((unsigned int));static int extract_17 PARAMS ((unsigned int));static int extract_22 PARAMS ((unsigned int));/* Utility function to print registers.  Put these first, so gcc's function   inlining can do its stuff.  */#define fputs_filtered(STR,F)	(*info->fprintf_func) (info->stream, "%s", STR)static voidfput_reg (reg, info)     unsigned reg;     disassemble_info *info;{  (*info->fprintf_func) (info->stream, reg ? reg_names[reg] : "r0");}static voidfput_fp_reg (reg, info)     unsigned reg;     disassemble_info *info;{  (*info->fprintf_func) (info->stream, reg ? fp_reg_names[reg] : "fr0");}static voidfput_fp_reg_r (reg, info)     unsigned reg;     disassemble_info *info;{  /* Special case floating point exception registers.  */  if (reg < 4)    (*info->fprintf_func) (info->stream, "fpe%d", reg * 2 + 1);  else    (*info->fprintf_func) (info->stream, "%sR", reg ? fp_reg_names[reg] 						    : "fr0");}static voidfput_creg (reg, info)     unsigned reg;     disassemble_info *info;{  (*info->fprintf_func) (info->stream, control_reg[reg]);}/* Print constants with sign.  */static voidfput_const (num, info)     unsigned num;     disassemble_info *info;{  if ((int)num < 0)    (*info->fprintf_func) (info->stream, "-%x", -(int)num);  else    (*info->fprintf_func) (info->stream, "%x", num);}/* Routines to extract various sized constants out of hppa   instructions.  *//* Extract a 3-bit space register number from a be, ble, mtsp or mfsp.  */static intextract_3 (word)     unsigned word;{  return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);}static intextract_5_load (word)     unsigned word;{  return low_sign_extend (word >> 16 & MASK_5, 5);}/* Extract the immediate field from a st{bhw}s instruction.  */static intextract_5_store (word)     unsigned word;{  return low_sign_extend (word & MASK_5, 5);}/* Extract the immediate field from a break instruction.  */static unsignedextract_5r_store (word)     unsigned word;{  return (word & MASK_5);}/* Extract the immediate field from a {sr}sm instruction.  */static unsignedextract_5R_store (word)     unsigned word;{  return (word >> 16 & MASK_5);}/* Extract the 10 bit immediate field from a {sr}sm instruction.  */static unsignedextract_10U_store (word)     unsigned word;{  return (word >> 16 & MASK_10);}/* Extract the immediate field from a bb instruction.  */static unsignedextract_5Q_store (word)     unsigned word;{  return (word >> 21 & MASK_5);}/* Extract an 11 bit immediate field.  */static intextract_11 (word)     unsigned word;{  return low_sign_extend (word & MASK_11, 11);}/* Extract a 14 bit immediate field.  */static intextract_14 (word)     unsigned word;{  return low_sign_extend (word & MASK_14, 14);}/* Extract a 16 bit immediate field (PA2.0 wide only).  */static intextract_16 (word)     unsigned word;{  int m15, m0, m1;  m0 = GET_BIT (word, 16);  m1 = GET_BIT (word, 17);  m15 = GET_BIT (word, 31);  word = (word >> 1) & 0x1fff;  word = word | (m15 << 15) | ((m15 ^ m0) << 14) | ((m15 ^ m1) << 13);  return sign_extend (word, 16);}/* Extract a 21 bit constant.  */static intextract_21 (word)     unsigned word;{  int val;  word &= MASK_21;  word <<= 11;  val = GET_FIELD (word, 20, 20);  val <<= 11;  val |= GET_FIELD (word, 9, 19);  val <<= 2;  val |= GET_FIELD (word, 5, 6);  val <<= 5;  val |= GET_FIELD (word, 0, 4);  val <<= 2;  val |= GET_FIELD (word, 7, 8);  return sign_extend (val, 21) << 11;}/* Extract a 12 bit constant from branch instructions.  */static intextract_12 (word)     unsigned word;{  return sign_extend (GET_FIELD (word, 19, 28) |                      GET_FIELD (word, 29, 29) << 10 |                      (word & 0x1) << 11, 12) << 2;}/* Extract a 17 bit constant from branch instructions, returning the   19 bit signed value.  */static intextract_17 (word)     unsigned word;{  return sign_extend (GET_FIELD (word, 19, 28) |                      GET_FIELD (word, 29, 29) << 10 |                      GET_FIELD (word, 11, 15) << 11 |                      (word & 0x1) << 16, 17) << 2;}static intextract_22 (word)     unsigned word;{  return sign_extend (GET_FIELD (word, 19, 28) |                      GET_FIELD (word, 29, 29) << 10 |                      GET_FIELD (word, 11, 15) << 11 |                      GET_FIELD (word, 6, 10) << 16 |                      (word & 0x1) << 21, 22) << 2;}/* Print one instruction.  */intprint_insn_hppa (memaddr, info)     bfd_vma memaddr;     disassemble_info *info;{  bfd_byte buffer[4];  unsigned int insn, i;  {    int status =      (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);    if (status != 0)      {	(*info->memory_error_func) (status, memaddr, info);	return -1;      }  }  insn = bfd_getb32 (buffer);  for (i = 0; i < NUMOPCODES; ++i)    {      const struct pa_opcode *opcode = &pa_opcodes[i];      if ((insn & opcode->mask) == opcode->match)	{	  register const char *s;#ifndef BFD64	  if (opcode->arch == pa20w)	    continue;#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?