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

📄 tc-tic30.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 4 页
字号:
	      current_op->immediate.s_number = (int) atoi (token);	      current_op->immediate.u_number = (unsigned int) atoi (token);	      current_op->immediate.resolved = 1;	    }	  current_op->op_type = Disp | Abs24 | Imm16 | Imm24;	  if (current_op->immediate.u_number >= 0 && current_op->immediate.u_number <= 31)	    current_op->op_type |= IVector;	}    }  return current_op;}/* next_line points to the next line after the current instruction (current_line).   Search for the parallel bars, and if found, merge two lines into internal syntax   for a parallel instruction:   q_[INSN1]_[INSN2] [OPERANDS1] | [OPERANDS2]   By this stage, all comments are scrubbed, and only the bare lines are given. */#define NONE           0#define START_OPCODE   1#define END_OPCODE     2#define START_OPERANDS 3#define END_OPERANDS   4char *tic30_find_parallel_insn (current_line, next_line)     char *current_line;     char *next_line;{  int found_parallel = 0;  char first_opcode[256];  char second_opcode[256];  char first_operands[256];  char second_operands[256];  char *parallel_insn;  debug ("In tic30_find_parallel_insn()\n");  while (!is_end_of_line[(unsigned char) *next_line])    {      if (*next_line == PARALLEL_SEPARATOR && *(next_line + 1) == PARALLEL_SEPARATOR)	{	  found_parallel = 1;	  next_line++;	  break;	}      next_line++;    }  if (!found_parallel)    return NULL;  debug ("Found a parallel instruction\n");  {    int i;    char *opcode, *operands, *line;    for (i = 0; i < 2; i++)      {	if (i == 0)	  {	    opcode = &first_opcode[0];	    operands = &first_operands[0];	    line = current_line;	  }	else	  {	    opcode = &second_opcode[0];	    operands = &second_operands[0];	    line = next_line;	  }	{	  int search_status = NONE;	  int char_ptr = 0;	  char c;	  while (!is_end_of_line[(unsigned char) (c = *line)])	    {	      if (is_opcode_char (c) && search_status == NONE)		{		  opcode[char_ptr++] = tolower (c);		  search_status = START_OPCODE;		}	      else if (is_opcode_char (c) && search_status == START_OPCODE)		{		  opcode[char_ptr++] = tolower (c);		}	      else if (!is_opcode_char (c) && search_status == START_OPCODE)		{		  opcode[char_ptr] = '\0';		  char_ptr = 0;		  search_status = END_OPCODE;		}	      else if (is_operand_char (c) && search_status == START_OPERANDS)		{		  operands[char_ptr++] = c;		}	      if (is_operand_char (c) && search_status == END_OPCODE)		{		  operands[char_ptr++] = c;		  search_status = START_OPERANDS;		}	      line++;	    }	  if (search_status != START_OPERANDS)	    return NULL;	  operands[char_ptr] = '\0';	}      }  }  parallel_insn = (char *) malloc (strlen (first_opcode) + strlen (first_operands) +		     strlen (second_opcode) + strlen (second_operands) + 8);  sprintf (parallel_insn, "q_%s_%s %s | %s", first_opcode, second_opcode, first_operands, second_operands);  debug ("parallel insn = %s\n", parallel_insn);  return parallel_insn;}#undef NONE#undef START_OPCODE#undef END_OPCODE#undef START_OPERANDS#undef END_OPERANDS/* In order to get gas to ignore any | chars at the start of a line,   this function returns true if a | is found in a line.  */inttic30_unrecognized_line (c)     int c;{  debug ("In tc_unrecognized_line\n");  return (c == PARALLEL_SEPARATOR);}intmd_estimate_size_before_relax (fragP, segment)     fragS *fragP;     segT segment;{  debug ("In md_estimate_size_before_relax()\n");  return 0;}voidmd_convert_frag (abfd, sec, fragP)     bfd *abfd;     segT sec;     register fragS *fragP;{  debug ("In md_convert_frag()\n");}intmd_apply_fix (fixP, valP)     fixS *fixP;     valueT *valP;{  valueT value = *valP;  debug ("In md_apply_fix() with value = %ld\n", (long) value);  debug ("Values in fixP\n");  debug ("fx_size = %d\n", fixP->fx_size);  debug ("fx_pcrel = %d\n", fixP->fx_pcrel);  debug ("fx_where = %d\n", fixP->fx_where);  debug ("fx_offset = %d\n", (int) fixP->fx_offset);  {    char *buf = fixP->fx_frag->fr_literal + fixP->fx_where;    value /= INSN_SIZE;    if (fixP->fx_size == 1)      {				/* Special fix for LDP instruction.  */	value = (value & 0x00FF0000) >> 16;      }    debug ("new value = %ld\n", (long) value);    md_number_to_chars (buf, value, fixP->fx_size);  }  return 1;}intmd_parse_option (c, arg)     int c;     char *arg;{  int i;  debug ("In md_parse_option()\n");  for (i = 0; i < c; i++)    {      printf ("%c\n", arg[c]);    }  return 0;}voidmd_show_usage (stream)     FILE *stream;{  debug ("In md_show_usage()\n");}symbolS *md_undefined_symbol (name)     char *name;{  debug ("In md_undefined_symbol()\n");  return (symbolS *) 0;}valueTmd_section_align (segment, size)     segT segment;     valueT size;{  debug ("In md_section_align() segment = %d and size = %d\n", segment, size);  size = (size + 3) / 4;  size *= 4;  debug ("New size value = %d\n", size);  return size;}longmd_pcrel_from (fixP)     fixS *fixP;{  int offset;  debug ("In md_pcrel_from()\n");  debug ("fx_where = %d\n", fixP->fx_where);  debug ("fx_size = %d\n", fixP->fx_size);  /* Find the opcode that represents the current instruction in the fr_literal     storage area, and check bit 21.  Bit 21 contains whether the current instruction     is a delayed one or not, and then set the offset value appropriately.  */  if (fixP->fx_frag->fr_literal[fixP->fx_where - fixP->fx_size + 1] & 0x20)    offset = 3;  else    offset = 1;  debug ("offset = %d\n", offset);  /* PC Relative instructions have a format:     displacement = Label - (PC + offset)     This function returns PC + offset where:     fx_where - fx_size = PC     INSN_SIZE * offset = offset number of instructions   */  return fixP->fx_where - fixP->fx_size + (INSN_SIZE * offset);}char *md_atof (what_statement_type, literalP, sizeP)     int what_statement_type;     char *literalP;     int *sizeP;{  int prec;  char *token;  char keepval;  unsigned long value;  /*  char *atof_ieee (); */  float float_value;  debug ("In md_atof()\n");  debug ("precision = %c\n", what_statement_type);  debug ("literal = %s\n", literalP);  debug ("line = ");  token = input_line_pointer;  while (!is_end_of_line[(unsigned char) *input_line_pointer]	 && (*input_line_pointer != ','))    {      debug ("%c", *input_line_pointer);      input_line_pointer++;    }  keepval = *input_line_pointer;  *input_line_pointer = '\0';  debug ("\n");  float_value = (float) atof (token);  *input_line_pointer = keepval;  debug ("float_value = %f\n", float_value);  switch (what_statement_type)    {    case 'f':    case 'F':    case 's':    case 'S':      prec = 2;      break;    case 'd':    case 'D':    case 'r':    case 'R':      prec = 4;      break;    default:      *sizeP = 0;      return "Bad call to MD_ATOF()";    }  if (float_value == 0.0)    {      value = (prec == 2) ? 0x00008000L : 0x80000000L;    }  else    {      unsigned long exp, sign, mant, tmsfloat;      tmsfloat = *((long *) &float_value);      sign = tmsfloat & 0x80000000;      mant = tmsfloat & 0x007FFFFF;      exp = tmsfloat & 0x7F800000;      exp <<= 1;      if (exp == 0xFF000000)	{	  if (mant == 0)	    value = 0x7F7FFFFF;	  else if (sign == 0)	    value = 0x7F7FFFFF;	  else	    value = 0x7F800000;	}      else	{	  exp -= 0x7F000000;	  if (sign)	    {	      mant = mant & 0x007FFFFF;	      mant = -mant;	      mant = mant & 0x00FFFFFF;	      if (mant == 0)		{		  mant |= 0x00800000;		  exp = (long) exp - 0x01000000;		}	    }	  tmsfloat = exp | mant;	  value = tmsfloat;	}      if (prec == 2)	{	  long exp, mant;	  if (tmsfloat == 0x80000000)	    {	      value = 0x8000;	    }	  else	    {	      value = 0;	      exp = (tmsfloat & 0xFF000000);	      exp >>= 24;	      mant = tmsfloat & 0x007FFFFF;	      if (tmsfloat & 0x00800000)		{		  mant |= 0xFF000000;		  mant += 0x00000800;		  mant >>= 12;		  mant |= 0x00000800;		  mant &= 0x0FFF;		  if (exp > 7)		    value = 0x7800;		}	      else		{		  mant |= 0x00800000;		  mant += 0x00000800;		  exp += (mant >> 24);		  mant >>= 12;		  mant &= 0x07FF;		  if (exp > 7)		    value = 0x77FF;		}	      if (exp < -8)		value = 0x8000;	      if (value == 0)		{		  mant = (exp << 12) | mant;		  value = mant & 0xFFFF;		}	    }	}    }  md_number_to_chars (literalP, value, prec);  *sizeP = prec;  return 0;}voidmd_number_to_chars (buf, val, n)     char *buf;     valueT val;     int n;{  debug ("In md_number_to_chars()\n");  number_to_chars_bigendian (buf, val, n);  /*  number_to_chars_littleendian(buf,val,n); */}#define F(SZ,PCREL)		(((SZ) << 1) + (PCREL))#define MAP(SZ,PCREL,TYPE)	case F(SZ,PCREL): code = (TYPE); breakarelent *tc_gen_reloc (section, fixP)     asection *section;     fixS *fixP;{  arelent *rel;  bfd_reloc_code_real_type code = 0;  debug ("In tc_gen_reloc()\n");  debug ("fixP.size = %d\n", fixP->fx_size);  debug ("fixP.pcrel = %d\n", fixP->fx_pcrel);  debug ("addsy.name = %s\n", S_GET_NAME (fixP->fx_addsy));  switch (F (fixP->fx_size, fixP->fx_pcrel))    {      MAP (1, 0, BFD_RELOC_TIC30_LDP);      MAP (2, 0, BFD_RELOC_16);      MAP (3, 0, BFD_RELOC_24);      MAP (2, 1, BFD_RELOC_16_PCREL);      MAP (4, 0, BFD_RELOC_32);    default:      as_bad ("Can not do %d byte %srelocation", fixP->fx_size,	      fixP->fx_pcrel ? "pc-relative " : "");    }#undef MAP#undef F  rel = (arelent *) xmalloc (sizeof (arelent));  assert (rel != 0);  rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));  *rel->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);  rel->address = fixP->fx_frag->fr_address + fixP->fx_where;  if (fixP->fx_pcrel)    rel->addend = fixP->fx_addnumber;  else    rel->addend = 0;  rel->howto = bfd_reloc_type_lookup (stdoutput, code);  if (!rel->howto)    {      const char *name;      name = S_GET_NAME (fixP->fx_addsy);      if (name == NULL)	name = "<unknown>";      as_fatal ("Cannot generate relocation type for symbol %s, code %s", name, bfd_get_reloc_code_name (code));    }  return rel;}voidtc_aout_pre_write_hook (){  debug ("In tc_aout_pre_write_hook()\n");}voidmd_operand (expressionP)     expressionS *expressionP;{  debug ("In md_operand()\n");}char output_invalid_buf[8];char *output_invalid (c)     char c;{  if (isprint (c))    sprintf (output_invalid_buf, "'%c'", c);  else    sprintf (output_invalid_buf, "(0x%x)", (unsigned) c);  return output_invalid_buf;}

⌨️ 快捷键说明

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