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

📄 tc-fr30.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 2 页
字号:
/* tc-fr30.c -- Assembler for the Fujitsu FR30.   Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.   This file is part of GAS, the GNU Assembler.   GAS 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, or (at your option)   any later version.   GAS 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 GAS; see the file COPYING.  If not, write to   the Free Software Foundation, 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  */#include <stdio.h>#include <ctype.h>#include "as.h"#include "subsegs.h"#include "symcat.h"#include "opcodes/fr30-desc.h"#include "opcodes/fr30-opc.h"#include "cgen.h"/* Structure to hold all of the different components describing   an individual instruction.  */typedef struct{  const CGEN_INSN *	insn;  const CGEN_INSN *	orig_insn;  CGEN_FIELDS		fields;#if CGEN_INT_INSN_P  CGEN_INSN_INT         buffer [1];#define INSN_VALUE(buf) (*(buf))#else  unsigned char         buffer [CGEN_MAX_INSN_SIZE];#define INSN_VALUE(buf) (buf)#endif  char *		addr;  fragS *		frag;  int                   num_fixups;  fixS *                fixups [GAS_CGEN_MAX_FIXUPS];  int                   indices [MAX_OPERAND_INSTANCES];}fr30_insn;const char comment_chars[]        = ";";const char line_comment_chars[]   = "#";const char line_separator_chars[] = "|";const char EXP_CHARS[]            = "eE";const char FLT_CHARS[]            = "dD";#define FR30_SHORTOPTS ""const char * md_shortopts = FR30_SHORTOPTS;struct option md_longopts[] ={  {NULL, no_argument, NULL, 0}};size_t md_longopts_size = sizeof (md_longopts);intmd_parse_option (c, arg)     int    c;     char * arg;{  switch (c)    {    default:      return 0;    }  return 1;}voidmd_show_usage (stream)  FILE * stream;{  fprintf (stream, _(" FR30 specific command line options:\n"));}/* The target specific pseudo-ops which we support.  */const pseudo_typeS md_pseudo_table[] ={  { "word",	cons,		4 },  { NULL, 	NULL, 		0 }};voidmd_begin (){  flagword applicable;  segT     seg;  subsegT  subseg;  /* Initialize the `cgen' interface.  */  /* Set the machine number and endian.  */  gas_cgen_cpu_desc = fr30_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,					  CGEN_CPU_OPEN_ENDIAN,					  CGEN_ENDIAN_BIG,					  CGEN_CPU_OPEN_END);  fr30_cgen_init_asm (gas_cgen_cpu_desc);  /* This is a callback from cgen to gas to parse operands.  */  cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);}voidmd_assemble (str)     char * str;{  static int last_insn_had_delay_slot = 0;  fr30_insn insn;  char *    errmsg;  char *    str2 = NULL;  /* Initialize GAS's cgen interface for a new instruction.  */  gas_cgen_init_parse ();  insn.insn = fr30_cgen_assemble_insn    (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);  if (!insn.insn)    {      as_bad (errmsg);      return;    }  /* Doesn't really matter what we pass for RELAX_P here.  */  gas_cgen_finish_insn (insn.insn, insn.buffer,			CGEN_FIELDS_BITSIZE (& insn.fields), 1, NULL);  /* Warn about invalid insns in delay slots.  */  if (last_insn_had_delay_slot      && CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_NOT_IN_DELAY_SLOT))    as_warn (_("Instruction %s not allowed in a delay slot."),	     CGEN_INSN_NAME (insn.insn));  last_insn_had_delay_slot    = CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_DELAY_SLOT);}/* The syntax in the manual says constants begin with '#'.   We just ignore it.  */voidmd_operand (expressionP)     expressionS * expressionP;{  if (* input_line_pointer == '#')    {      input_line_pointer ++;      expression (expressionP);    }}valueTmd_section_align (segment, size)     segT   segment;     valueT size;{  int align = bfd_get_section_alignment (stdoutput, segment);  return ((size + (1 << align) - 1) & (-1 << align));}symbolS *md_undefined_symbol (name)  char * name;{  return 0;}/* Interface to relax_segment.  *//* FIXME: Build table by hand, get it working, then machine generate.  */const relax_typeS md_relax_table[] ={/* The fields are:   1) most positive reach of this state,   2) most negative reach of this state,   3) how many bytes this mode will add to the size of the current frag   4) which index into the table to try if we can't fit into this one.  */  /* The first entry must be unused because an `rlx_more' value of zero ends     each list.  */  {1, 1, 0, 0},  /* The displacement used by GAS is from the end of the 2 byte insn,     so we subtract 2 from the following.  */  /* 16 bit insn, 8 bit disp -> 10 bit range.     This doesn't handle a branch in the right slot at the border:     the "& -4" isn't taken into account.  It's not important enough to     complicate things over it, so we subtract an extra 2 (or + 2 in -ve     case).  */  {511 - 2 - 2, -512 - 2 + 2, 0, 2 },  /* 32 bit insn, 24 bit disp -> 26 bit range.  */  {0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },  /* Same thing, but with leading nop for alignment.  */  {0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }};longfr30_relax_frag (segment, fragP, stretch)     segT    segment;     fragS * fragP;     long    stretch;{  /* Address of branch insn.  */  long address = fragP->fr_address + fragP->fr_fix - 2;  long growth = 0;  /* Keep 32 bit insns aligned on 32 bit boundaries.  */  if (fragP->fr_subtype == 2)    {      if ((address & 3) != 0)	{	  fragP->fr_subtype = 3;	  growth = 2;	}    }  else if (fragP->fr_subtype == 3)    {      if ((address & 3) == 0)	{	  fragP->fr_subtype = 2;	  growth = -2;	}    }  else    {      growth = relax_frag (segment, fragP, stretch);      /* Long jump on odd halfword boundary?  */      if (fragP->fr_subtype == 2 && (address & 3) != 0)	{	  fragP->fr_subtype = 3;	  growth += 2;	}    }  return growth;}/* Return an initial guess of the length by which a fragment must grow to   hold a branch to reach its destination.   Also updates fr_type/fr_subtype as necessary.   Called just before doing relaxation.   Any symbol that is now undefined will not become defined.   The guess for fr_var is ACTUALLY the growth beyond fr_fix.   Whatever we do to grow fr_fix or fr_var contributes to our returned value.   Although it may not be explicit in the frag, pretend fr_var starts with a   0 value.  */intmd_estimate_size_before_relax (fragP, segment)     fragS * fragP;     segT    segment;{  /* The only thing we have to handle here are symbols outside of the     current segment.  They may be undefined or in a different segment in     which case linker scripts may place them anywhere.     However, we can't finish the fragment here and emit the reloc as insn     alignment requirements may move the insn about.  */  if (S_GET_SEGMENT (fragP->fr_symbol) != segment)    {      int    old_fr_fix = fragP->fr_fix;      /* The symbol is undefined in this segment.	 Change the relaxation subtype to the max allowable and leave	 all further handling to md_convert_frag.  */      fragP->fr_subtype = 2;#if 0 /* Can't use this, but leave in for illustration.  */      /* Change 16 bit insn to 32 bit insn.  */      fragP->fr_opcode[0] |= 0x80;      /* Increase known (fixed) size of fragment.  */      fragP->fr_fix += 2;      /* Create a relocation for it.  */      fix_new (fragP, old_fr_fix, 4,	       fragP->fr_symbol,	       fragP->fr_offset, 1 /* pcrel */,	       /* FIXME: Can't use a real BFD reloc here.		  gas_cgen_md_apply_fix3 can't handle it.  */	       BFD_RELOC_FR30_26_PCREL);      /* Mark this fragment as finished.  */      frag_wane (fragP);      return fragP->fr_fix - old_fr_fix;#else      {	const CGEN_INSN * insn;	int               i;	/* Update the recorded insn.	   Fortunately we don't have to look very far.	   FIXME: Change this to record in the instruction the next higher	   relaxable insn to use.  */	for (i = 0, insn = fragP->fr_cgen.insn; i < 4; i++, insn++)	  {	    if ((strcmp (CGEN_INSN_MNEMONIC (insn),			 CGEN_INSN_MNEMONIC (fragP->fr_cgen.insn))		 == 0)		&& CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAX))	      break;	  }	if (i == 4)	  abort ();	fragP->fr_cgen.insn = insn;	return 2;      }#endif    }  /* Return the size of the variable part of the frag.  */  return md_relax_table[fragP->fr_subtype].rlx_length;}/* *fragP has been relaxed to its final size, and now needs to have   the bytes inside it modified to conform to the new size.   Called after relaxation is finished.

⌨️ 快捷键说明

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