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

📄 mcs51-dis.c

📁 circuit calculation program
💻 C
字号:
/* Print instructions for the Motorola 88000, for GDB and GNU Binutils.   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1998, 2000, 2001   Free Software Foundation, Inc.   Contributed by Data General Corporation, November 1989.   Partially derived from an earlier printcmd.c.This file is part of GDB and the GNU Binutils.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 "opcode/mcs51.h"#include "opintl.h"template * insn[256];static intmcs51dis PARAMS ((bfd_byte *, unsigned long, struct disassemble_info *));static voidprintop PARAMS ((struct disassemble_info *, unsigned long, bfd_byte *, unsigned long));static voidinit_disasm PARAMS ((void));/* Disassemble a mcs51 instruction at `memaddr'.  */intprint_insn_mcs51 (memaddr, info)     bfd_vma memaddr;     struct disassemble_info *info;{  bfd_byte buffer[4];  int status;  static int ihashtab_initialized = 0;  template *insn_fmt;  int i;    if (! ihashtab_initialized) {    ihashtab_initialized = 1;    init_disasm ();   }     status = (*info->read_memory_func) (memaddr, buffer, 1, info);  if (status != 0)    {fail:    	      (*info->memory_error_func) (status, memaddr, info);      return -1;    }      insn_fmt = insn [buffer [0]];  if (!insn_fmt) return 1;  status = (*info->read_memory_func) (memaddr, buffer, insn_fmt->insn_size, info);  if (status != 0) goto fail;        return mcs51dis (buffer, memaddr, info);}/* * Disassemble the instruction in `instruction'. * `pc' should be the address of this instruction, it will be used to * print the target address if this is a relative jump or call the * disassembled instruction is written to `info'. * * The function returns the length of this instruction in bytes. */static intmcs51dis (instruction, pc, info)     bfd_byte *instruction;     bfd_vma pc;          struct disassemble_info *info;{  template *insn_fmt;  int i;    insn_fmt = insn [instruction [0]];  (*info->fprintf_func) (info->stream, "%s\t", insn_fmt->name);    for (i=0; i<insn_fmt->op_num; i++ ) {      if (i) (*info->fprintf_func) (info->stream, ", ");	      printop (info, insn_fmt->op_types [i], instruction, pc );        }    return insn_fmt->insn_size;}/* * Decode an Operand of an instruction. * * This function formats and writes an operand of an instruction to * info based on the operand specification.  When the `first' flag is * set this is the first operand of an instruction.  Undefined operand * types cause a <dis error> message. * * Parameters: *  disassemble_info	where the operand may be printed *  OPSPEC  *opptr      pointer to an operand specification *  UINT    inst        instruction from which operand is extracted *  UINT    pc		pc of instruction; used for pc-relative disp. *  int     first       flag which if nonzero indicates the first *                      operand of an instruction * * The operand specified is extracted from the instruction and is * written to buf in the format specified. The operand is preceded by * a comma if it is not the first operand of an instruction and it is * not a register indirect form.  Registers are preceded by 'r' and * hex values by '0x'. */static voidprintop (info, fmt, insn, pc )     struct disassemble_info *info;     unsigned long fmt;     bfd_byte *insn;     bfd_vma pc;  {	unsigned char b;			switch (OPERAND_ENCODE (fmt) )		{		case mcs51_implied:						switch (OPERAND_TYPE (fmt) )			{			case mcs51_A:				(*info->fprintf_func) (info->stream, "A" );				break;			 			case mcs51_C:						(*info->fprintf_func) (info->stream, "C" );				break;								case mcs51_AB:				(*info->fprintf_func) (info->stream, "AB" );				break;								case mcs51_mem16:					(*info->fprintf_func) (info->stream, "@DPTR" );				break;						case mcs51_mem16_x:					(*info->fprintf_func) (info->stream, "@A+DPTR" );				break;								case mcs51_mem16_p:				(*info->fprintf_func) (info->stream, "@A+PC" );				break;								case mcs51_dptr:					(*info->fprintf_func) (info->stream, "DPTR" );				break;			default:			abort(); /* internal error */			}			break;		case mcs51_oct_1:			b = insn[1];			goto l1;		case mcs51_oct_2:					b = insn[2];l1:			switch (OPERAND_TYPE (fmt) )			{			case mcs51_direct:							case mcs51_bit:				(*info->fprintf_func) (info->stream, "0x%x",b );				break;									case mcs51_not_bit:							(*info->fprintf_func) (info->stream, "/0x%x",b );				break;						case mcs51_imm8:							(*info->fprintf_func) (info->stream, "#0x%x",b );				break;			default:			abort(); /* internal error */							}			break;				case mcs51_or1_0:				(*info->fprintf_func) (info->stream, "@R%d",												insn[0] & 0x1 );			break;					case mcs51_or3_0:						(*info->fprintf_func) (info->stream, "R%d",										insn[0] & 0x7 );			break;					case mcs51_pcrel8_1:			(*info->fprintf_func) (info->stream, "#0x%X",								pc+2+insn[1] );			break;							case mcs51_pcrel8_2:		      			(*info->fprintf_func) (info->stream, "#0x%X",								pc+3+insn[2] );	       		break;		case mcs51_reloc11:      			(*info->fprintf_func) (info->stream, "#0x%X",						(pc &0xf800) | insn[1] | ((insn[0]&0xe0)<<3) );			break;		case mcs51_reloc16:		case mcs51_reloc16b:	       				      			(*info->fprintf_func) (info->stream, "#0x%X",								(*(short *)(insn+1)) );	       		break;		}	}/* * Initialize the disassembler instruction table. * * Initialize the hash table and instruction table for the * disassembler.  This should be called once before the first call to * disasm(). */static voidinit_disasm (){  int   i;  char *s;    for (i = 0; i < sizeof (mcs51_optab) / sizeof (mcs51_optab[0]); i++) {  	unsigned char j;  	if (mcs51_optab [i].op_mask == 0 ) continue;  	  	if (mcs51_optab [i].name == NULL) mcs51_optab [i].name=s; 	else s=mcs51_optab [i].name;  		  	 	  		  	  	if( (mcs51_optab [i].op_mask & 0x80)  ) {  /* mask in form like 0xf3 */  		j = ~mcs51_optab [i].op_mask;  	  		do insn [mcs51_optab [i].op_code + j] = &mcs51_optab [i];  		while (j--);  	  	} else {/* mask in form like 0x3f */  		unsigned char k;  		k = mcs51_optab [i].op_mask + 1; /* 0..010...0 */  		j = 0;  	  		do {  			insn [mcs51_optab [i].op_code + j] = &mcs51_optab [i];  			(j += k);  		} while (j);  	  	}  }}

⌨️ 快捷键说明

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