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

📄 tc-sparc.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
/* tc-sparc.c -- Assemble for the SPARC   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 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 "opcode/sparc.h"#ifdef OBJ_ELF#include "elf/sparc.h"#include "dwarf2dbg.h"#endifstatic struct sparc_arch *lookup_arch PARAMS ((char *));static void init_default_arch PARAMS ((void));static int sparc_ip PARAMS ((char *, const struct sparc_opcode **));static int in_signed_range PARAMS ((bfd_signed_vma, bfd_signed_vma));static int in_unsigned_range PARAMS ((bfd_vma, bfd_vma));static int in_bitfield_range PARAMS ((bfd_signed_vma, bfd_signed_vma));static int sparc_ffs PARAMS ((unsigned int));static void synthetize_setuw PARAMS ((const struct sparc_opcode *));static void synthetize_setsw PARAMS ((const struct sparc_opcode *));static void synthetize_setx PARAMS ((const struct sparc_opcode *));static bfd_vma BSR PARAMS ((bfd_vma, int));static int cmp_reg_entry PARAMS ((const PTR, const PTR));static int parse_keyword_arg PARAMS ((int (*) (const char *), char **, int *));static int parse_const_expr_arg PARAMS ((char **, int *));static int get_expression PARAMS ((char *str));/* Default architecture.  *//* ??? The default value should be V8, but sparclite support was added   by making it the default.  GCC now passes -Asparclite, so maybe sometime in   the future we can set this to V8.  */#ifndef DEFAULT_ARCH#define DEFAULT_ARCH "sparclite"#endifstatic char *default_arch = DEFAULT_ARCH;/* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'   have been set.  */static int default_init_p;/* Current architecture.  We don't bump up unless necessary.  */static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6;/* The maximum architecture level we can bump up to.   In a 32 bit environment, don't allow bumping up to v9 by default.   The native assembler works this way.  The user is required to pass   an explicit argument before we'll create v9 object files.  However, if   we don't see any v9 insns, a v8plus object file is not created.  */static enum sparc_opcode_arch_val max_architecture;/* Either 32 or 64, selects file format.  */static int sparc_arch_size;/* Initial (default) value, recorded separately in case a user option   changes the value before md_show_usage is called.  */static int default_arch_size;#ifdef OBJ_ELF/* The currently selected v9 memory model.  Currently only used for   ELF.  */static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO;#endifstatic int architecture_requested;static int warn_on_bump;/* If warn_on_bump and the needed architecture is higher than this   architecture, issue a warning.  */static enum sparc_opcode_arch_val warn_after_architecture;/* Non-zero if as should generate error if an undeclared g[23] register   has been used in -64.  */static int no_undeclared_regs;/* Non-zero if we should try to relax jumps and calls.  */static int sparc_relax;/* Non-zero if we are generating PIC code.  */int sparc_pic_code;/* Non-zero if we should give an error when misaligned data is seen.  */static int enforce_aligned_data;extern int target_big_endian;static int target_little_endian_data;/* Symbols for global registers on v9.  */static symbolS *globals[8];/* V9 and 86x have big and little endian data, but instructions are always big   endian.  The sparclet has bi-endian support but both data and insns have   the same endianness.  Global `target_big_endian' is used for data.   The following macro is used for instructions.  */#ifndef INSN_BIG_ENDIAN#define INSN_BIG_ENDIAN (target_big_endian \			 || default_arch_type == sparc86x \			 || SPARC_OPCODE_ARCH_V9_P (max_architecture))#endif/* Handle of the OPCODE hash table.  */static struct hash_control *op_hash;static int log2 PARAMS ((int));static void s_data1 PARAMS ((void));static void s_seg PARAMS ((int));static void s_proc PARAMS ((int));static void s_reserve PARAMS ((int));static void s_common PARAMS ((int));static void s_empty PARAMS ((int));static void s_uacons PARAMS ((int));static void s_ncons PARAMS ((int));static void s_register PARAMS ((int));const pseudo_typeS md_pseudo_table[] ={  {"align", s_align_bytes, 0},	/* Defaulting is invalid (0).  */  {"common", s_common, 0},  {"empty", s_empty, 0},  {"global", s_globl, 0},  {"half", cons, 2},  {"nword", s_ncons, 0},  {"optim", s_ignore, 0},  {"proc", s_proc, 0},  {"reserve", s_reserve, 0},  {"seg", s_seg, 0},  {"skip", s_space, 0},  {"word", cons, 4},  {"xword", cons, 8},  {"uahalf", s_uacons, 2},  {"uaword", s_uacons, 4},  {"uaxword", s_uacons, 8},#ifdef OBJ_ELF  {"file", dwarf2_directive_file, 0},  {"loc", dwarf2_directive_loc, 0},  /* These are specific to sparc/svr4.  */  {"2byte", s_uacons, 2},  {"4byte", s_uacons, 4},  {"8byte", s_uacons, 8},  {"register", s_register, 0},#endif  {NULL, 0, 0},};/* Size of relocation record.  */const int md_reloc_size = 12;/* This array holds the chars that always start a comment.  If the   pre-processor is disabled, these aren't very useful.  */const char comment_chars[] = "!";	/* JF removed '|' from                                           comment_chars.  *//* This array holds the chars that only start a comment at the beginning of   a line.  If the line seems to have the form '# 123 filename'   .line and .file directives will appear in the pre-processed output.  *//* Note that input_file.c hand checks for '#' at the beginning of the   first line of the input file.  This is because the compiler outputs   #NO_APP at the beginning of its output.  *//* Also note that comments started like this one will always   work if '/' isn't otherwise defined.  */const char line_comment_chars[] = "#";const char line_separator_chars[] = ";";/* Chars that can be used to separate mant from exp in floating point   nums.  */const char EXP_CHARS[] = "eE";/* Chars that mean this number is a floating point constant.   As in 0f12.456   or    0d1.2345e12  */const char FLT_CHARS[] = "rRsSfFdDxXpP";/* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be   changed in read.c.  Ideally it shouldn't have to know about it at all,   but nothing is ideal around here.  */#define isoctal(c)  ((unsigned) ((c) - '0') < '8')struct sparc_it  {    char *error;    unsigned long opcode;    struct nlist *nlistp;    expressionS exp;    expressionS exp2;    int pcrel;    bfd_reloc_code_real_type reloc;  };struct sparc_it the_insn, set_insn;static void output_insn  PARAMS ((const struct sparc_opcode *, struct sparc_it *));/* Table of arguments to -A.   The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect   for this use.  That table is for opcodes only.  This table is for opcodes   and file formats.  */enum sparc_arch_types {v6, v7, v8, sparclet, sparclite, sparc86x, v8plus,		       v8plusa, v9, v9a, v9b, v9_64};static struct sparc_arch {  char *name;  char *opcode_arch;  enum sparc_arch_types arch_type;  /* Default word size, as specified during configuration.     A value of zero means can't be used to specify default architecture.  */  int default_arch_size;  /* Allowable arg to -A?  */  int user_option_p;} sparc_arch_table[] = {  { "v6", "v6", v6, 0, 1 },  { "v7", "v7", v7, 0, 1 },  { "v8", "v8", v8, 32, 1 },  { "sparclet", "sparclet", sparclet, 32, 1 },  { "sparclite", "sparclite", sparclite, 32, 1 },  { "sparc86x", "sparclite", sparc86x, 32, 1 },  { "v8plus", "v9", v9, 0, 1 },  { "v8plusa", "v9a", v9, 0, 1 },  { "v8plusb", "v9b", v9, 0, 1 },  { "v9", "v9", v9, 0, 1 },  { "v9a", "v9a", v9, 0, 1 },  { "v9b", "v9b", v9, 0, 1 },  /* This exists to allow configure.in/Makefile.in to pass one     value to specify both the default machine and default word size.  */  { "v9-64", "v9", v9, 64, 0 },  { NULL, NULL, v8, 0, 0 }};/* Variant of default_arch */static enum sparc_arch_types default_arch_type;static struct sparc_arch *lookup_arch (name)     char *name;{  struct sparc_arch *sa;  for (sa = &sparc_arch_table[0]; sa->name != NULL; sa++)    if (strcmp (sa->name, name) == 0)      break;  if (sa->name == NULL)    return NULL;  return sa;}/* Initialize the default opcode arch and word size from the default   architecture name.  */static voidinit_default_arch (){  struct sparc_arch *sa = lookup_arch (default_arch);  if (sa == NULL      || sa->default_arch_size == 0)    as_fatal (_("Invalid default architecture, broken assembler."));  max_architecture = sparc_opcode_lookup_arch (sa->opcode_arch);  if (max_architecture == SPARC_OPCODE_ARCH_BAD)    as_fatal (_("Bad opcode table, broken assembler."));  default_arch_size = sparc_arch_size = sa->default_arch_size;  default_init_p = 1;  default_arch_type = sa->arch_type;}/* Called by TARGET_FORMAT.  */const char *sparc_target_format (){  /* We don't get a chance to initialize anything before we're called,     so handle that now.  */  if (! default_init_p)    init_default_arch ();#ifdef OBJ_AOUT#ifdef TE_NetBSD  return "a.out-sparc-netbsd";#else#ifdef TE_SPARCAOUT  if (target_big_endian)    return "a.out-sunos-big";  else if (default_arch_type == sparc86x && target_little_endian_data)    return "a.out-sunos-big";  else    return "a.out-sparc-little";#else  return "a.out-sunos-big";#endif#endif#endif#ifdef OBJ_BOUT  return "b.out.big";#endif#ifdef OBJ_COFF#ifdef TE_LYNX  return "coff-sparc-lynx";#else  return "coff-sparc";#endif#endif#ifdef OBJ_ELF  return sparc_arch_size == 64 ? "elf64-sparc" : "elf32-sparc";#endif  abort ();}/* md_parse_option *	Invocation line includes a switch not recognized by the base assembler. *	See if it's a processor-specific option.  These are: * *	-bump *		Warn on architecture bumps.  See also -A. * *	-Av6, -Av7, -Av8, -Asparclite, -Asparclet *		Standard 32 bit architectures. *	-Av9, -Av9a, -Av9b *		Sparc64 in either a 32 or 64 bit world (-32/-64 says which). *		This used to only mean 64 bits, but properly specifying it *		complicated gcc's ASM_SPECs, so now opcode selection is *		specified orthogonally to word size (except when specifying *		the default, but that is an internal implementation detail). *	-Av8plus, -Av8plusa, -Av8plusb *		Same as -Av9{,a,b}. *	-xarch=v8plus, -xarch=v8plusa, -xarch=v8plusb *		Same as -Av8plus{,a,b} -32, for compatibility with Sun's *		assembler. *	-xarch=v9, -xarch=v9a, -xarch=v9b *		Same as -Av9{,a,b} -64, for compatibility with Sun's *		assembler. * *		Select the architecture and possibly the file format. *		Instructions or features not supported by the selected *		architecture cause fatal errors. * *		The default is to start at v6, and bump the architecture up *		whenever an instruction is seen at a higher level.  In 32 bit *		environments, v9 is not bumped up to, the user must pass * 		-Av8plus{,a,b}. * *		If -bump is specified, a warning is printing when bumping to *		higher levels. * *		If an architecture is specified, all instructions must match *		that architecture.  Any higher level instructions are flagged *		as errors.  Note that in the 32 bit environment specifying *		-Av8plus does not automatically create a v8plus object file, a *		v9 insn must be seen. * *		If both an architecture and -bump are specified, the *		architecture starts at the specified level, but bumps are *		warnings.  Note that we can't set `current_architecture' to *		the requested level in this case: in the 32 bit environment, *		we still must avoid creating v8plus object files unless v9 * 		insns are seen. * * Note: *		Bumping between incompatible architectures is always an *		error.  For example, from sparclite to v9. */#ifdef OBJ_ELFCONST char *md_shortopts = "A:K:VQ:sq";#else#ifdef OBJ_AOUTCONST char *md_shortopts = "A:k";#elseCONST char *md_shortopts = "A:";#endif#endifstruct option md_longopts[] = {#define OPTION_BUMP (OPTION_MD_BASE)  {"bump", no_argument, NULL, OPTION_BUMP},#define OPTION_SPARC (OPTION_MD_BASE + 1)  {"sparc", no_argument, NULL, OPTION_SPARC},#define OPTION_XARCH (OPTION_MD_BASE + 2)  {"xarch", required_argument, NULL, OPTION_XARCH},#ifdef OBJ_ELF#define OPTION_32 (OPTION_MD_BASE + 3)  {"32", no_argument, NULL, OPTION_32},#define OPTION_64 (OPTION_MD_BASE + 4)  {"64", no_argument, NULL, OPTION_64},#define OPTION_TSO (OPTION_MD_BASE + 5)  {"TSO", no_argument, NULL, OPTION_TSO},#define OPTION_PSO (OPTION_MD_BASE + 6)  {"PSO", no_argument, NULL, OPTION_PSO},#define OPTION_RMO (OPTION_MD_BASE + 7)  {"RMO", no_argument, NULL, OPTION_RMO},#endif#ifdef SPARC_BIENDIAN#define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)  {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},#define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)  {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},#endif#define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)  {"enforce-aligned-data", no_argument, NULL, OPTION_ENFORCE_ALIGNED_DATA},#define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)  {"little-endian-data", no_argument, NULL, OPTION_LITTLE_ENDIAN_DATA},#ifdef OBJ_ELF#define OPTION_NO_UNDECLARED_REGS (OPTION_MD_BASE + 12)  {"no-undeclared-regs", no_argument, NULL, OPTION_NO_UNDECLARED_REGS},#define OPTION_UNDECLARED_REGS (OPTION_MD_BASE + 13)  {"undeclared-regs", no_argument, NULL, OPTION_UNDECLARED_REGS},#endif#define OPTION_RELAX (OPTION_MD_BASE + 14)  {"relax", no_argument, NULL, OPTION_RELAX},#define OPTION_NO_RELAX (OPTION_MD_BASE + 15)  {"no-relax", no_argument, NULL, OPTION_NO_RELAX},  {NULL, no_argument, NULL, 0}};size_t md_longopts_size = sizeof (md_longopts);intmd_parse_option (c, arg)     int c;     char *arg;{  /* We don't get a chance to initialize anything before we're called,     so handle that now.  */  if (! default_init_p)    init_default_arch ();  switch (c)    {    case OPTION_BUMP:      warn_on_bump = 1;      warn_after_architecture = SPARC_OPCODE_ARCH_V6;      break;    case OPTION_XARCH:#ifdef OBJ_ELF      if (strncmp (arg, "v9", 2) != 0)	md_parse_option (OPTION_32, NULL);      else	md_parse_option (OPTION_64, NULL);#endif      /* Fall through.  */    case 'A':      {	struct sparc_arch *sa;	enum sparc_opcode_arch_val opcode_arch;	sa = lookup_arch (arg);	if (sa == NULL	    || ! sa->user_option_p)	  {	    if (c == OPTION_XARCH)	      as_bad (_("invalid architecture -xarch=%s"), arg);	    else	      as_bad (_("invalid architecture -A%s"), arg);	    return 0;	  }	opcode_arch = sparc_opcode_lookup_arch (sa->opcode_arch);	if (opcode_arch == SPARC_OPCODE_ARCH_BAD)	  as_fatal (_("Bad opcode table, broken assembler."));	max_architecture = opcode_arch;	architecture_requested = 1;      }      break;    case OPTION_SPARC:      /* Ignore -sparc, used by SunOS make default .s.o rule.  */      break;    case OPTION_ENFORCE_ALIGNED_DATA:      enforce_aligned_data = 1;      break;#ifdef SPARC_BIENDIAN    case OPTION_LITTLE_ENDIAN:      target_big_endian = 0;      if (default_arch_type != sparclet)	as_fatal ("This target does not support -EL");      break;    case OPTION_LITTLE_ENDIAN_DATA:      target_little_endian_data = 1;      target_big_endian = 0;      if (default_arch_type != sparc86x	  && default_arch_type != v9)	as_fatal ("This target does not support --little-endian-data");      break;    case OPTION_BIG_ENDIAN:      target_big_endian = 1;      break;#endif#ifdef OBJ_AOUT    case 'k':      sparc_pic_code = 1;      break;#endif#ifdef OBJ_ELF

⌨️ 快捷键说明

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