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

📄 ieee.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
/* BFD back-end for ieee-695 objects.   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,   2000, 2001   Free Software Foundation, Inc.   Written by Steve Chamberlain of Cygnus Support.This file is part of BFD, the Binary File Descriptor library.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.  */#define KEEPMINUSPCININST 0/* IEEE 695 format is a stream of records, which we parse using a simple one-   token (which is one byte in this lexicon) lookahead recursive decent   parser.  */#include "bfd.h"#include "sysdep.h"#include "libbfd.h"#include "ieee.h"#include "libieee.h"#include <ctype.h>static boolean ieee_write_byte PARAMS ((bfd *, int));static boolean ieee_write_2bytes PARAMS ((bfd *, int));static boolean ieee_write_int PARAMS ((bfd *, bfd_vma));static boolean ieee_write_id PARAMS ((bfd *, const char *));static boolean ieee_write_expression  PARAMS ((bfd *, bfd_vma, asymbol *, boolean, unsigned int));static void ieee_write_int5 PARAMS ((bfd_byte *, bfd_vma));static boolean ieee_write_int5_out PARAMS ((bfd *, bfd_vma));static boolean ieee_write_section_part PARAMS ((bfd *));static boolean do_with_relocs PARAMS ((bfd *, asection *));static boolean do_as_repeat PARAMS ((bfd *, asection *));static boolean do_without_relocs PARAMS ((bfd *, asection *));static boolean ieee_write_external_part PARAMS ((bfd *));static boolean ieee_write_data_part PARAMS ((bfd *));static boolean ieee_write_debug_part PARAMS ((bfd *));static boolean ieee_write_me_part PARAMS ((bfd *));static boolean ieee_write_processor PARAMS ((bfd *));static boolean ieee_slurp_debug PARAMS ((bfd *));static boolean ieee_slurp_section_data PARAMS ((bfd *));/* Functions for writing to ieee files in the strange way that the   standard requires. */static booleanieee_write_byte (abfd, barg)     bfd *abfd;     int barg;{  bfd_byte byte;  byte = barg;  if (bfd_write ((PTR) &byte, 1, 1, abfd) != 1)    return false;  return true;}static booleanieee_write_2bytes (abfd, bytes)     bfd *abfd;     int bytes;{  bfd_byte buffer[2];  buffer[0] = bytes >> 8;  buffer[1] = bytes & 0xff;  if (bfd_write ((PTR) buffer, 1, 2, abfd) != 2)    return false;  return true;}static booleanieee_write_int (abfd, value)     bfd *abfd;     bfd_vma value;{  if (value <= 127)    {      if (! ieee_write_byte (abfd, (bfd_byte) value))	return false;    }  else    {      unsigned int length;      /* How many significant bytes ? */      /* FIXME FOR LONGER INTS */      if (value & 0xff000000)	length = 4;      else if (value & 0x00ff0000)	length = 3;      else if (value & 0x0000ff00)	length = 2;      else	length = 1;      if (! ieee_write_byte (abfd,			     (bfd_byte) ((int) ieee_number_repeat_start_enum					 + length)))	return false;      switch (length)	{	case 4:	  if (! ieee_write_byte (abfd, (bfd_byte) (value >> 24)))	    return false;	  /* Fall through.  */	case 3:	  if (! ieee_write_byte (abfd, (bfd_byte) (value >> 16)))	    return false;	  /* Fall through.  */	case 2:	  if (! ieee_write_byte (abfd, (bfd_byte) (value >> 8)))	    return false;	  /* Fall through.  */	case 1:	  if (! ieee_write_byte (abfd, (bfd_byte) (value)))	    return false;	}    }  return true;}static booleanieee_write_id (abfd, id)     bfd *abfd;     const char *id;{  size_t length = strlen (id);  if (length <= 127)    {      if (! ieee_write_byte (abfd, (bfd_byte) length))	return false;    }  else if (length < 255)    {      if (! ieee_write_byte (abfd, ieee_extension_length_1_enum)	  || ! ieee_write_byte (abfd, (bfd_byte) length))	return false;    }  else if (length < 65535)    {      if (! ieee_write_byte (abfd, ieee_extension_length_2_enum)	  || ! ieee_write_2bytes (abfd, (int) length))	return false;    }  else    {      (*_bfd_error_handler)	(_("%s: string too long (%d chars, max 65535)"),	 bfd_get_filename (abfd), length);      bfd_set_error (bfd_error_invalid_operation);      return false;    }  if (bfd_write ((PTR) id, 1, length, abfd) != length)    return false;  return true;}/***************************************************************************Functions for reading from ieee files in the strange way that thestandard requires:*/#define this_byte(ieee) *((ieee)->input_p)#define next_byte(ieee) ((ieee)->input_p++)#define this_byte_and_next(ieee) (*((ieee)->input_p++))static unsigned shortread_2bytes (ieee)     common_header_type *ieee;{  unsigned char c1 = this_byte_and_next (ieee);  unsigned char c2 = this_byte_and_next (ieee);  return (c1 << 8) | c2;}static voidbfd_get_string (ieee, string, length)     common_header_type *ieee;     char *string;     size_t length;{  size_t i;  for (i = 0; i < length; i++)    {      string[i] = this_byte_and_next (ieee);    }}static char *read_id (ieee)     common_header_type *ieee;{  size_t length;  char *string;  length = this_byte_and_next (ieee);  if (length <= 0x7f)    {      /* Simple string of length 0 to 127 */    }  else if (length == 0xde)    {      /* Length is next byte, allowing 0..255 */      length = this_byte_and_next (ieee);    }  else if (length == 0xdf)    {      /* Length is next two bytes, allowing 0..65535 */      length = this_byte_and_next (ieee);      length = (length * 256) + this_byte_and_next (ieee);    }  /* Buy memory and read string */  string = bfd_alloc (ieee->abfd, length + 1);  if (!string)    return NULL;  bfd_get_string (ieee, string, length);  string[length] = 0;  return string;}static booleanieee_write_expression (abfd, value, symbol, pcrel, index)     bfd *abfd;     bfd_vma value;     asymbol *symbol;     boolean pcrel;     unsigned int index;{  unsigned int term_count = 0;  if (value != 0)    {      if (! ieee_write_int (abfd, value))	return false;      term_count++;    }  if (bfd_is_com_section (symbol->section)      || bfd_is_und_section (symbol->section))    {      /* Def of a common symbol */      if (! ieee_write_byte (abfd, ieee_variable_X_enum)	  || ! ieee_write_int (abfd, symbol->value))	return false;      term_count++;    }  else if (! bfd_is_abs_section (symbol->section))    {      /* Ref to defined symbol - */      if (symbol->flags & BSF_GLOBAL)	{	  if (! ieee_write_byte (abfd, ieee_variable_I_enum)	      || ! ieee_write_int (abfd, symbol->value))	    return false;	  term_count++;	}      else if (symbol->flags & (BSF_LOCAL | BSF_SECTION_SYM))	{	  /* This is a reference to a defined local symbol.  We can	     easily do a local as a section+offset.  */	  if (! ieee_write_byte (abfd, ieee_variable_R_enum)	      || ! ieee_write_byte (abfd,				    (bfd_byte) (symbol->section->index						+ IEEE_SECTION_NUMBER_BASE)))	    return false;	  term_count++;	  if (symbol->value != 0)	    {	      if (! ieee_write_int (abfd, symbol->value))		return false;	      term_count++;	    }	}      else	{	  (*_bfd_error_handler)	    (_("%s: unrecognized symbol `%s' flags 0x%x"),	     bfd_get_filename (abfd), bfd_asymbol_name (symbol),	     symbol->flags);	  bfd_set_error (bfd_error_invalid_operation);	  return false;	}    }  if (pcrel)    {      /* subtract the pc from here by asking for PC of this section*/      if (! ieee_write_byte (abfd, ieee_variable_P_enum)	  || ! ieee_write_byte (abfd,				(bfd_byte) (index + IEEE_SECTION_NUMBER_BASE))	  || ! ieee_write_byte (abfd, ieee_function_minus_enum))	return false;    }  /* Handle the degenerate case of a 0 address.  */  if (term_count == 0)    {      if (! ieee_write_int (abfd, 0))	return false;    }  while (term_count > 1)    {      if (! ieee_write_byte (abfd, ieee_function_plus_enum))	return false;      term_count--;    }  return true;}/*****************************************************************************//*writes any integer into the buffer supplied and always takes 5 bytes*/static voidieee_write_int5 (buffer, value)     bfd_byte *buffer;     bfd_vma value;{  buffer[0] = (bfd_byte) ieee_number_repeat_4_enum;  buffer[1] = (value >> 24) & 0xff;  buffer[2] = (value >> 16) & 0xff;  buffer[3] = (value >> 8) & 0xff;  buffer[4] = (value >> 0) & 0xff;}static booleanieee_write_int5_out (abfd, value)     bfd *abfd;     bfd_vma value;{  bfd_byte b[5];  ieee_write_int5 (b, value);  if (bfd_write ((PTR) b, 1, 5, abfd) != 5)    return false;  return true;}static booleanparse_int (ieee, value_ptr)     common_header_type *ieee;     bfd_vma *value_ptr;{  int value = this_byte (ieee);  int result;  if (value >= 0 && value <= 127)    {      *value_ptr = value;      next_byte (ieee);      return true;    }  else if (value >= 0x80 && value <= 0x88)    {      unsigned int count = value & 0xf;      result = 0;      next_byte (ieee);      while (count)	{	  result = (result << 8) | this_byte_and_next (ieee);	  count--;	}      *value_ptr = result;      return true;    }  return false;}static intparse_i (ieee, ok)     common_header_type *ieee;     boolean *ok;{  bfd_vma x;  *ok = parse_int (ieee, &x);  return x;}static bfd_vmamust_parse_int (ieee)     common_header_type *ieee;{  bfd_vma result;  BFD_ASSERT (parse_int (ieee, &result) == true);  return result;}typedef struct{  bfd_vma value;  asection *section;  ieee_symbol_index_type symbol;} ieee_value_type;#if KEEPMINUSPCININST#define SRC_MASK(arg) arg#define PCREL_OFFSET false#else#define SRC_MASK(arg) 0#define PCREL_OFFSET true#endifstatic reloc_howto_type abs32_howto =  HOWTO (1,	 0,	 2,	 32,	 false,	 0,	 complain_overflow_bitfield,	 0,	 "abs32",	 true,	 0xffffffff,	 0xffffffff,	 false);static reloc_howto_type abs16_howto =  HOWTO (1,	 0,	 1,	 16,	 false,	 0,	 complain_overflow_bitfield,	 0,	 "abs16",	 true,	 0x0000ffff,	 0x0000ffff,	 false);static reloc_howto_type abs8_howto =  HOWTO (1,	 0,	 0,	 8,	 false,	 0,	 complain_overflow_bitfield,	 0,	 "abs8",	 true,	 0x000000ff,	 0x000000ff,	 false);static reloc_howto_type rel32_howto =  HOWTO (1,	 0,	 2,	 32,	 true,	 0,	 complain_overflow_signed,	 0,	 "rel32",	 true,	 SRC_MASK (0xffffffff),	 0xffffffff,	 PCREL_OFFSET);static reloc_howto_type rel16_howto =  HOWTO (1,	 0,	 1,	 16,	 true,	 0,	 complain_overflow_signed,	 0,	 "rel16",	 true,	 SRC_MASK (0x0000ffff),	 0x0000ffff,	 PCREL_OFFSET);static reloc_howto_type rel8_howto =  HOWTO (1,	 0,	 0,	 8,	 true,	 0,	 complain_overflow_signed,	 0,	 "rel8",	 true,	 SRC_MASK (0x000000ff),	 0x000000ff,	 PCREL_OFFSET);static ieee_symbol_index_type NOSYMBOL = {0, 0};static voidparse_expression (ieee, value, symbol, pcrel, extra, section)     ieee_data_type *ieee;     bfd_vma *value;     ieee_symbol_index_type *symbol;     boolean *pcrel;     unsigned int *extra;     asection **section;{#define POS sp[1]#define TOS sp[0]#define NOS sp[-1]#define INC sp++;#define DEC sp--;  boolean loop = true;  ieee_value_type stack[10];  /* The stack pointer always points to the next unused location */#define PUSH(x,y,z) TOS.symbol=x;TOS.section=y;TOS.value=z;INC;#define POP(x,y,z) DEC;x=TOS.symbol;y=TOS.section;z=TOS.value;  ieee_value_type *sp = stack;

⌨️ 快捷键说明

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