⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s390-dis.c.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
/* s390-dis.c -- Disassemble S390 instructions   Copyright 2000, 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc.   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).   This file is part of the GNU opcodes library.   This library is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3, or (at your option)   any later version.   It is distributed in the hope that it will be useful, but WITHOUT   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public   License for more details.   You should have received a copy of the GNU General Public License   along with this file; see the file COPYING.  If not, write to the   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,   MA 02110-1301, USA.  */#include <stdio.h>#include "dis-asm.h"/* s390.h -- Header file for S390 opcode table   Copyright 2000, 2001, 2003 Free Software Foundation, Inc.   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).   This file is part of BFD, the Binary File Descriptor library.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the 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 of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA   02110-1301, USA.  */#ifndef S390_H#define S390_H/* List of instruction sets variations. */enum s390_opcode_mode_val  {    S390_OPCODE_ESA = 0,    S390_OPCODE_ZARCH  };enum s390_opcode_cpu_val  {    S390_OPCODE_G5 = 0,    S390_OPCODE_G6,    S390_OPCODE_Z900,    S390_OPCODE_Z990,    S390_OPCODE_Z9_109,    S390_OPCODE_Z9_EC  };/* The opcode table is an array of struct s390_opcode.  */struct s390_opcode  {    /* The opcode name.  */    const char * name;    /* The opcode itself.  Those bits which will be filled in with       operands are zeroes.  */    unsigned char opcode[6];    /* The opcode mask.  This is used by the disassembler.  This is a       mask containing ones indicating those bits which must match the       opcode field, and zeroes indicating those bits which need not       match (and are presumably filled in by operands).  */    unsigned char mask[6];    /* The opcode length in bytes. */    int oplen;    /* An array of operand codes.  Each code is an index into the       operand table.  They appear in the order which the operands must       appear in assembly code, and are terminated by a zero.  */    unsigned char operands[6];    /* Bitmask of execution modes this opcode is available for.  */    unsigned int modes;    /* First cpu this opcode is available for.  */    enum s390_opcode_cpu_val min_cpu;  };/* The table itself is sorted by major opcode number, and is otherwise   in the order in which the disassembler should consider   instructions.  */extern const struct s390_opcode s390_opcodes[];extern const int                s390_num_opcodes;/* A opcode format table for the .insn pseudo mnemonic.  */extern const struct s390_opcode s390_opformats[];extern const int                s390_num_opformats;/* Values defined for the flags field of a struct powerpc_opcode.  *//* The operands table is an array of struct s390_operand.  */struct s390_operand  {    /* The number of bits in the operand.  */    int bits;    /* How far the operand is left shifted in the instruction.  */    int shift;    /* One bit syntax flags.  */    unsigned long flags;  };/* Elements in the table are retrieved by indexing with values from   the operands field of the powerpc_opcodes table.  */extern const struct s390_operand s390_operands[];/* Values defined for the flags field of a struct s390_operand.  *//* This operand names a register.  The disassembler uses this to print   register names with a leading 'r'.  */#define S390_OPERAND_GPR 0x1/* This operand names a floating point register.  The disassembler   prints these with a leading 'f'. */#define S390_OPERAND_FPR 0x2/* This operand names an access register.  The disassembler   prints these with a leading 'a'.  */#define S390_OPERAND_AR 0x4/* This operand names a control register.  The disassembler   prints these with a leading 'c'.  */#define S390_OPERAND_CR 0x8/* This operand is a displacement.  */#define S390_OPERAND_DISP 0x10/* This operand names a base register.  */#define S390_OPERAND_BASE 0x20/* This operand names an index register, it can be skipped.  */#define S390_OPERAND_INDEX 0x40/* This operand is a relative branch displacement.  The disassembler   prints these symbolically if possible.  */#define S390_OPERAND_PCREL 0x80/* This operand takes signed values.  */#define S390_OPERAND_SIGNED 0x100/* This operand is a length.  */#define S390_OPERAND_LENGTH 0x200/* This operand is optional. Only a single operand at the end of   the instruction may be optional.  */#define S390_OPERAND_OPTIONAL 0x400	#endif /* S390_H */static int init_flag = 0;static int opc_index[256];static int current_arch_mask = 0;/* Set up index table for first opcode byte.  */static voidinit_disasm (struct disassemble_info *info){  const struct s390_opcode *opcode;  const struct s390_opcode *opcode_end;  memset (opc_index, 0, sizeof (opc_index));  opcode_end = s390_opcodes + s390_num_opcodes;  for (opcode = s390_opcodes; opcode < opcode_end; opcode++)    {      opc_index[(int) opcode->opcode[0]] = opcode - s390_opcodes;      while ((opcode < opcode_end) &&	     (opcode[1].opcode[0] == opcode->opcode[0]))	opcode++;    }//  switch (info->mach)//    {//    case bfd_mach_s390_31:      current_arch_mask = 1 << S390_OPCODE_ESA;//      break;//    case bfd_mach_s390_64://      current_arch_mask = 1 << S390_OPCODE_ZARCH;//      break;//    default://      abort ();//    }  init_flag = 1;}/* Extracts an operand value from an instruction.  */static inline unsigned ints390_extract_operand (unsigned char *insn, const struct s390_operand *operand){  unsigned int val;  int bits;  /* Extract fragments of the operand byte for byte.  */  insn += operand->shift / 8;  bits = (operand->shift & 7) + operand->bits;  val = 0;  do    {      val <<= 8;      val |= (unsigned int) *insn++;      bits -= 8;    }  while (bits > 0);  val >>= -bits;  val &= ((1U << (operand->bits - 1)) << 1) - 1;  /* Check for special long displacement case.  */  if (operand->bits == 20 && operand->shift == 20)    val = (val & 0xff) << 12 | (val & 0xfff00) >> 8;  /* Sign extend value if the operand is signed or pc relative.  */  if ((operand->flags & (S390_OPERAND_SIGNED | S390_OPERAND_PCREL))      && (val & (1U << (operand->bits - 1))))    val |= (-1U << (operand->bits - 1)) << 1;  /* Double value if the operand is pc relative.  */  if (operand->flags & S390_OPERAND_PCREL)    val <<= 1;  /* Length x in an instructions has real length x + 1.  */  if (operand->flags & S390_OPERAND_LENGTH)    val++;  return val;}/* Print a S390 instruction.  */int

⌨️ 快捷键说明

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