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

📄 tc-m32r.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 4 页
字号:
/* tc-m32r.c -- Assembler for the Mitsubishi M32R.   Copyright 1996, 1997, 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/m32r-desc.h"#include "opcodes/m32r-opc.h"#include "cgen.h"/* Linked list of symbols that are debugging symbols to be defined as the   beginning of the current instruction.  */typedef struct sym_link{  struct sym_link *next;  symbolS *symbol;} sym_linkS;static sym_linkS *debug_sym_link = (sym_linkS *) 0;/* 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];  sym_linkS *debug_sym_link;}m32r_insn;/* prev_insn.insn is non-null if last insn was a 16 bit insn on a 32 bit   boundary (i.e. was the first of two 16 bit insns).  */static m32r_insn prev_insn;/* Non-zero if we've seen a relaxable insn since the last 32 bit   alignment request.  */static int seen_relaxable_p = 0;/* Non-zero if -relax specified, in which case sufficient relocs are output   for the linker to do relaxing.   We do simple forms of relaxing internally, but they are always done.   This flag does not apply to them.  */static int m32r_relax;#if 0/* Not supported yet.  *//* If non-NULL, pointer to cpu description file to read.   This allows runtime additions to the assembler.  */static const char *m32r_cpu_desc;#endif/* Non-zero if warn when a high/shigh reloc has no matching low reloc.   Each high/shigh reloc must be paired with it's low cousin in order to   properly calculate the addend in a relocatable link (since there is a   potential carry from the low to the high/shigh).   This option is off by default though for user-written assembler code it   might make sense to make the default be on (i.e. have gcc pass a flag   to turn it off).  This warning must not be on for GCC created code as   optimization may delete the low but not the high/shigh (at least we   shouldn't assume or require it to).  */static int warn_unmatched_high = 0;/* Non-zero if -m32rx has been specified, in which case support for the   extended M32RX instruction set should be enabled.  */static int enable_m32rx = 0;/* Non-zero if -m32rx -hidden has been specified, in which case support for   the special M32RX instruction set should be enabled.  */static int enable_special = 0;/* Non-zero if the programmer should be warned when an explicit parallel   instruction might have constraint violations.  */static int warn_explicit_parallel_conflicts = 1;/* Non-zero if insns can be made parallel.  */static int optimize;/* Stuff for .scomm symbols.  */static segT     sbss_section;static asection scom_section;static asymbol  scom_symbol;const char comment_chars[]        = ";";const char line_comment_chars[]   = "#";const char line_separator_chars[] = "";const char EXP_CHARS[]            = "eE";const char FLT_CHARS[]            = "dD";/* Relocations against symbols are done in two   parts, with a HI relocation and a LO relocation.  Each relocation   has only 16 bits of space to store an addend.  This means that in   order for the linker to handle carries correctly, it must be able   to locate both the HI and the LO relocation.  This means that the   relocations must appear in order in the relocation table.   In order to implement this, we keep track of each unmatched HI   relocation.  We then sort them so that they immediately precede the   corresponding LO relocation.  */struct m32r_hi_fixup{  /* Next HI fixup.  */  struct m32r_hi_fixup *next;  /* This fixup.  */  fixS *fixp;  /* The section this fixup is in.  */  segT seg;};/* The list of unmatched HI relocs.  */static struct m32r_hi_fixup *m32r_hi_fixup_list;static voidallow_m32rx (on)     int on;{  enable_m32rx = on;  if (stdoutput != NULL)    bfd_set_arch_mach (stdoutput, TARGET_ARCH,		       enable_m32rx ? bfd_mach_m32rx : bfd_mach_m32r);}#define M32R_SHORTOPTS "O"const char *md_shortopts = M32R_SHORTOPTS;struct option md_longopts[] ={#define OPTION_M32R		(OPTION_MD_BASE)#define OPTION_M32RX		(OPTION_M32R + 1)#define OPTION_WARN_PARALLEL	(OPTION_M32RX + 1)#define OPTION_NO_WARN_PARALLEL	(OPTION_WARN_PARALLEL + 1)#define OPTION_SPECIAL		(OPTION_NO_WARN_PARALLEL + 1)#define OPTION_WARN_UNMATCHED 	(OPTION_SPECIAL + 1)#define OPTION_NO_WARN_UNMATCHED (OPTION_WARN_UNMATCHED + 1)  {"m32r",  no_argument, NULL, OPTION_M32R},  {"m32rx", no_argument, NULL, OPTION_M32RX},  {"warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_WARN_PARALLEL},  {"Wp", no_argument, NULL, OPTION_WARN_PARALLEL},  {"no-warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_NO_WARN_PARALLEL},  {"Wnp", no_argument, NULL, OPTION_NO_WARN_PARALLEL},  {"hidden", no_argument, NULL, OPTION_SPECIAL},  /* Sigh.  I guess all warnings must now have both variants.  */  {"warn-unmatched-high", no_argument, NULL, OPTION_WARN_UNMATCHED},  {"Wuh", no_argument, NULL, OPTION_WARN_UNMATCHED},  {"no-warn-unmatched-high", no_argument, NULL, OPTION_NO_WARN_UNMATCHED},  {"Wnuh", no_argument, NULL, OPTION_NO_WARN_UNMATCHED},#if 0  /* Not supported yet.  */#define OPTION_RELAX		(OPTION_NO_WARN_UNMATCHED + 1)#define OPTION_CPU_DESC		(OPTION_RELAX + 1)  {"relax", no_argument, NULL, OPTION_RELAX},  {"cpu-desc", required_argument, NULL, OPTION_CPU_DESC},#endif  {NULL, no_argument, NULL, 0}};size_t md_longopts_size = sizeof (md_longopts);intmd_parse_option (c, arg)     int c;     char *arg;{  switch (c)    {    case 'O':      optimize = 1;      break;    case OPTION_M32R:      allow_m32rx (0);      break;    case OPTION_M32RX:      allow_m32rx (1);      break;    case OPTION_WARN_PARALLEL:      warn_explicit_parallel_conflicts = 1;      break;    case OPTION_NO_WARN_PARALLEL:      warn_explicit_parallel_conflicts = 0;      break;    case OPTION_SPECIAL:      if (enable_m32rx)	enable_special = 1;      else	{	  /* Pretend that we do not recognise this option.  */	  as_bad (_("Unrecognised option: -hidden"));	  return 0;	}      break;    case OPTION_WARN_UNMATCHED:      warn_unmatched_high = 1;      break;    case OPTION_NO_WARN_UNMATCHED:      warn_unmatched_high = 0;      break;#if 0    /* Not supported yet.  */    case OPTION_RELAX:      m32r_relax = 1;      break;    case OPTION_CPU_DESC:      m32r_cpu_desc = arg;      break;#endif    default:      return 0;    }  return 1;}voidmd_show_usage (stream)     FILE *stream;{  fprintf (stream, _(" M32R specific command line options:\n"));  fprintf (stream, _("\  -m32r                   disable support for the m32rx instruction set\n"));  fprintf (stream, _("\  -m32rx                  support the extended m32rx instruction set\n"));  fprintf (stream, _("\  -O                      try to combine instructions in parallel\n"));  fprintf (stream, _("\  -warn-explicit-parallel-conflicts     warn when parallel instructions\n"));  fprintf (stream, _("\                                         violate contraints\n"));  fprintf (stream, _("\  -no-warn-explicit-parallel-conflicts  do not warn when parallel\n"));  fprintf (stream, _("\                                         instructions violate contraints\n"));  fprintf (stream, _("\  -Wp                     synonym for -warn-explicit-parallel-conflicts\n"));  fprintf (stream, _("\  -Wnp                    synonym for -no-warn-explicit-parallel-conflicts\n"));  fprintf (stream, _("\  -warn-unmatched-high    warn when an (s)high reloc has no matching low reloc\n"));  fprintf (stream, _("\  -no-warn-unmatched-high do not warn about missing low relocs\n"));  fprintf (stream, _("\  -Wuh                    synonym for -warn-unmatched-high\n"));  fprintf (stream, _("\  -Wnuh                   synonym for -no-warn-unmatched-high\n"));#if 0  fprintf (stream, _("\  -relax                 create linker relaxable code\n"));  fprintf (stream, _("\  -cpu-desc              provide runtime cpu description file\n"));#endif}static void fill_insn PARAMS ((int));static void m32r_scomm PARAMS ((int));static void debug_sym PARAMS ((int));static void expand_debug_syms PARAMS ((sym_linkS *, int));/* Set by md_assemble for use by m32r_fill_insn.  */static subsegT prev_subseg;static segT prev_seg;/* The target specific pseudo-ops which we support.  */const pseudo_typeS md_pseudo_table[] ={  { "word",	cons,		4 },  { "fillinsn", fill_insn,	0 },  { "scomm",	m32r_scomm,	0 },  { "debugsym",	debug_sym,	0 },  /* Not documented as so far there is no need for them....  */  { "m32r",	allow_m32rx,	0 },  { "m32rx",	allow_m32rx,	1 },  { NULL, NULL, 0 }};/* FIXME: Should be machine generated.  */#define NOP_INSN 0x7000#define PAR_NOP_INSN 0xf000 /* Can only be used in 2nd slot.  *//* This is called from HANDLE_ALIGN in write.c.  Fill in the contents   of an rs_align_code fragment.  */voidm32r_handle_align (fragp)     fragS *fragp;{  static const unsigned char nop_pattern[] = { 0xf0, 0x00 };  static const unsigned char multi_nop_pattern[] = { 0x70, 0x00, 0xf0, 0x00 };  int bytes, fix;  char *p;  if (fragp->fr_type != rs_align_code)    return;  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;  p = fragp->fr_literal + fragp->fr_fix;  fix = 0;  if (bytes & 1)    {      fix = 1;      *p++ = 0;      bytes--;    }  if (bytes & 2)    {      memcpy (p, nop_pattern, 2);      p += 2;      bytes -= 2;      fix += 2;    }  memcpy (p, multi_nop_pattern, 4);  fragp->fr_fix += fix;  fragp->fr_var = 4;}/* If the last instruction was the first of 2 16 bit insns,   output a nop to move the PC to a 32 bit boundary.   This is done via an alignment specification since branch relaxing   may make it unnecessary.   Internally, we need to output one of these each time a 32 bit insn is   seen after an insn that is relaxable.  */static voidfill_insn (ignore)     int ignore;{  frag_align_code (2, 0);  prev_insn.insn = NULL;  seen_relaxable_p = 0;}/* Record the symbol so that when we output the insn, we can create   a symbol that is at the start of the instruction.  This is used   to emit the label for the start of a breakpoint without causing   the assembler to emit a NOP if the previous instruction was a   16 bit instruction.  */static voiddebug_sym (ignore)     int ignore;{  register char *name;  register char delim;  register char *end_name;  register symbolS *symbolP;  register sym_linkS *link;  name = input_line_pointer;  delim = get_symbol_end ();  end_name = input_line_pointer;  if ((symbolP = symbol_find (name)) == NULL      && (symbolP = md_undefined_symbol (name)) == NULL)    {      symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);    }  symbol_table_insert (symbolP);  if (S_IS_DEFINED (symbolP) && S_GET_SEGMENT (symbolP) != reg_section)    /* xgettext:c-format */    as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));  else    {      link = (sym_linkS *) xmalloc (sizeof (sym_linkS));      link->symbol = symbolP;      link->next = debug_sym_link;      debug_sym_link = link;      symbol_get_obj (symbolP)->local = 1;    }  *end_name = delim;  demand_empty_rest_of_line ();}/* Second pass to expanding the debug symbols, go through linked   list of symbols and reassign the address.  */static voidexpand_debug_syms (syms, align)     sym_linkS *syms;     int align;{  char *save_input_line = input_line_pointer;  sym_linkS *next_syms;  if (!syms)    return;  (void) frag_align_code (align, 0);  for (; syms != (sym_linkS *) 0; syms = next_syms)    {      symbolS *symbolP = syms->symbol;      next_syms = syms->next;      input_line_pointer = ".\n";      pseudo_set (symbolP);      free ((char *) syms);    }  input_line_pointer = save_input_line;}/* Cover function to fill_insn called after a label and at end of assembly.   The result is always 1: we're called in a conditional to see if the   current line is a label.  */intm32r_fill_insn (done)     int done;{  if (prev_seg != NULL)    {      segT seg = now_seg;      subsegT subseg = now_subseg;      subseg_set (prev_seg, prev_subseg);      fill_insn (0);      subseg_set (seg, subseg);    }  if (done && debug_sym_link)    {      expand_debug_syms (debug_sym_link, 1);      debug_sym_link = (sym_linkS *) 0;    }  return 1;}

⌨️ 快捷键说明

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