aout-tic30.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,065 行 · 第 1/3 页

C
1,065
字号
/* BFD back-end for TMS320C30 a.out binaries.   Copyright 1998, 1999, 2000 Free Software Foundation, Inc.   Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)   This file is part of BFD, the Binary File Descriptor library.   This program 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 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 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 this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA   02111-1307, USA.  */#define TARGET_IS_BIG_ENDIAN_P#define N_HEADER_IN_TEXT(x) 1#define BYTES_IN_WORD 4#define TEXT_START_ADDR 1024#define TARGET_PAGE_SIZE 128#define SEGMENT_SIZE TARGET_PAGE_SIZE#define DEFAULT_ARCH bfd_arch_tic30#define ARCH_SIZE 32#define MY(OP) CAT(tic30_aout_,OP)#define TARGETNAME "a.out-tic30"#define NAME(x,y) CAT3(tic30_aout,_32_,y)#include "bfd.h"#include "sysdep.h"#include "libaout.h"#include "aout/aout64.h"#include "aout/stab_gnu.h"#include "aout/ar.h"static bfd_reloc_status_type tic30_aout_fix_16  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));static bfd_reloc_status_type tic30_aout_fix_32  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));static bfd_reloc_status_type tic30_aout_fix_pcrel_16  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));static reloc_howto_type *tic30_aout_reloc_howto  PARAMS ((bfd *, struct reloc_std_external *, int *, int *, int *));static bfd_reloc_status_type tic30_aout_relocate_contents  PARAMS ((reloc_howto_type *, bfd *, bfd_vma, bfd_byte *));static bfd_reloc_status_type tic30_aout_final_link_relocate  PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma,	   bfd_vma, bfd_vma));static const bfd_target *tic30_aout_object_p PARAMS ((bfd *));static boolean tic30_aout_write_object_contents PARAMS ((bfd *));static boolean tic30_aout_set_sizes PARAMS ((bfd *));#define MY_reloc_howto(BFD,REL,IN,EX,PC) tic30_aout_reloc_howto(BFD,REL,&IN,&EX,&PC)#define MY_final_link_relocate tic30_aout_final_link_relocate#define MY_object_p tic30_aout_object_p#define MY_mkobject NAME(aout,mkobject)#define MY_write_object_contents tic30_aout_write_object_contents#define MY_set_sizes tic30_aout_set_sizes#ifndef MY_exec_hdr_flags#define MY_exec_hdr_flags 1#endif#ifndef MY_backend_data#ifndef MY_zmagic_contiguous#define MY_zmagic_contiguous 0#endif#ifndef MY_text_includes_header#define MY_text_includes_header 0#endif#ifndef MY_entry_is_text_address#define MY_entry_is_text_address 0#endif#ifndef MY_exec_header_not_counted#define MY_exec_header_not_counted 1#endif#ifndef MY_add_dynamic_symbols#define MY_add_dynamic_symbols 0#endif#ifndef MY_add_one_symbol#define MY_add_one_symbol 0#endif#ifndef MY_link_dynamic_object#define MY_link_dynamic_object 0#endif#ifndef MY_write_dynamic_symbol#define MY_write_dynamic_symbol 0#endif#ifndef MY_check_dynamic_reloc#define MY_check_dynamic_reloc 0#endif#ifndef MY_finish_dynamic_link#define MY_finish_dynamic_link 0#endifstatic CONST struct aout_backend_data tic30_aout_backend_data ={  MY_zmagic_contiguous,  MY_text_includes_header,  MY_entry_is_text_address,  MY_exec_hdr_flags,  0,				/* text vma? */  MY_set_sizes,  MY_exec_header_not_counted,  MY_add_dynamic_symbols,  MY_add_one_symbol,  MY_link_dynamic_object,  MY_write_dynamic_symbol,  MY_check_dynamic_reloc,  MY_finish_dynamic_link};#define MY_backend_data &tic30_aout_backend_data#endif/* FIXME: This is wrong.  aoutx.h should really only be included by   aout32.c.  */#include "aoutx.h"/* This table lists the relocation types for the TMS320C30.  There are   only a few relocations required, and all must be divided by 4 (>>   2) to get the 32-bit addresses in the format the TMS320C30 likes   it.  */reloc_howto_type tic30_aout_howto_table[] ={  EMPTY_HOWTO (-1),  HOWTO (1, 2, 1, 16, false, 0, 0, tic30_aout_fix_16,	 "16", false, 0x0000FFFF, 0x0000FFFF, false),  HOWTO (2, 2, 2, 24, false, 0, complain_overflow_bitfield, NULL,	 "24", false, 0x00FFFFFF, 0x00FFFFFF, false),  HOWTO (3, 18, 3, 24, false, 0, complain_overflow_bitfield, NULL,	 "LDP", false, 0x00FF0000, 0x000000FF, false),  HOWTO (4, 2, 4, 32, false, 0, complain_overflow_bitfield, tic30_aout_fix_32,	 "32", false, 0xFFFFFFFF, 0xFFFFFFFF, false),  HOWTO (5, 2, 1, 16, true, 0, complain_overflow_signed,	 tic30_aout_fix_pcrel_16, "PCREL", true, 0x0000FFFF, 0x0000FFFF, true),  EMPTY_HOWTO (-1),  EMPTY_HOWTO (-1),  EMPTY_HOWTO (-1),  EMPTY_HOWTO (-1),  EMPTY_HOWTO (-1)};extern reloc_howto_type *NAME (aout, reloc_type_lookup) ();reloc_howto_type *tic30_aout_reloc_type_lookup (abfd, code)     bfd *abfd ATTRIBUTE_UNUSED;     bfd_reloc_code_real_type code;{  switch (code)    {    case BFD_RELOC_8:    case BFD_RELOC_TIC30_LDP:      return &tic30_aout_howto_table[3];    case BFD_RELOC_16:      return &tic30_aout_howto_table[1];    case BFD_RELOC_24:      return &tic30_aout_howto_table[2];    case BFD_RELOC_16_PCREL:      return &tic30_aout_howto_table[5];    case BFD_RELOC_32:      return &tic30_aout_howto_table[4];    default:      return (reloc_howto_type *) NULL;    }}static reloc_howto_type *tic30_aout_reloc_howto (abfd, relocs, r_index, r_extern, r_pcrel)     bfd *abfd;     struct reloc_std_external *relocs;     int *r_index;     int *r_extern;     int *r_pcrel;{  unsigned int r_length;  unsigned int r_pcrel_done;  int index;  *r_pcrel = 0;  if (bfd_header_big_endian (abfd))    {      *r_index = ((relocs->r_index[0] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[2]);      *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));      r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_BIG));      r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) >> RELOC_STD_BITS_LENGTH_SH_BIG);    }  else    {      *r_index = ((relocs->r_index[2] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[0]);      *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));      r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));      r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) >> RELOC_STD_BITS_LENGTH_SH_LITTLE);    }  index = r_length + 4 * r_pcrel_done;  return tic30_aout_howto_table + index;}/* This function is used as a callback for 16-bit relocs.  This is   required for relocations between segments.  A line in aoutx.h   requires that any relocations for the data section should point to   the end of the aligned text section, plus an offset.  By default,   this does not happen, therefore this function takes care of   that.  */static bfd_reloc_status_typetic30_aout_fix_16 (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message)     bfd *abfd;     arelent *reloc_entry;     asymbol *symbol;     PTR data;     asection *input_section ATTRIBUTE_UNUSED;     bfd *output_bfd;     char **error_message ATTRIBUTE_UNUSED;{  bfd_vma relocation;  /* Make sure that the symbol's section is defined.  */  if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)    return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;  /* Get the size of the input section and turn it into the TMS320C30     32-bit address format.  */  relocation = (symbol->section->vma >> 2);  relocation += bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);  bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);  return bfd_reloc_ok;}/* This function does the same thing as tic30_aout_fix_16 except for 32   bit relocations.  */static bfd_reloc_status_typetic30_aout_fix_32 (abfd, reloc_entry, symbol, data, input_section,		   output_bfd, error_message)     bfd *abfd;     arelent *reloc_entry;     asymbol *symbol;     PTR data;     asection *input_section ATTRIBUTE_UNUSED;     bfd *output_bfd;     char **error_message ATTRIBUTE_UNUSED;{  bfd_vma relocation;  /* Make sure that the symbol's section is defined.  */  if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)    return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;  /* Get the size of the input section and turn it into the TMS320C30     32-bit address format.  */  relocation = (symbol->section->vma >> 2);  relocation += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);  bfd_put_32 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);  return bfd_reloc_ok;}/* This function is used to work out pc-relative offsets for the   TMS320C30.  The data already placed by md_pcrel_from within gas is   useless for a relocation, so we just get the offset value and place   a version of this within the object code.   tic30_aout_final_link_relocate will then calculate the required   relocation to add on to the value in the object code.  */static bfd_reloc_status_typetic30_aout_fix_pcrel_16 (abfd, reloc_entry, symbol, data, input_section,			 output_bfd, error_message)     bfd *abfd;     arelent *reloc_entry;     asymbol *symbol ATTRIBUTE_UNUSED;     PTR data;     asection *input_section ATTRIBUTE_UNUSED;     bfd *output_bfd ATTRIBUTE_UNUSED;     char **error_message ATTRIBUTE_UNUSED;{  bfd_vma relocation = 1;  bfd_byte offset_data = bfd_get_8 (abfd, (bfd_byte *) data + reloc_entry->address - 1);  /* The byte before the location of the fix contains bits 23-16 of     the pcrel instruction.  Bit 21 is set for a delayed instruction     which requires on offset of 3 instead of 1.  */  if (offset_data & 0x20)    relocation -= 3;  else    relocation -= 1;  bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);  return bfd_reloc_ok;}/* These macros will get 24-bit values from the bfd definition.   Big-endian only.  */#define bfd_getb_24(BFD,ADDR)			\ (bfd_get_8 (BFD, ADDR    ) << 16) |		\ (bfd_get_8 (BFD, ADDR + 1) <<  8) |		\ (bfd_get_8 (BFD, ADDR + 2)      )#define bfd_putb_24(BFD,DATA,ADDR)				\ bfd_put_8 (BFD, (bfd_byte) ((DATA >> 16) & 0xFF), ADDR    );	\ bfd_put_8 (BFD, (bfd_byte) ((DATA >>  8) & 0xFF), ADDR + 1);	\ bfd_put_8 (BFD, (bfd_byte) ( DATA        & 0xFF), ADDR + 2)/* Set parameters about this a.out file that are machine-dependent.   This routine is called from some_aout_object_p just before it returns.  */static const bfd_target *tic30_aout_callback (abfd)     bfd *abfd;{  struct internal_exec *execp = exec_hdr (abfd);  unsigned int arch_align_power;  unsigned long arch_align;  /* Calculate the file positions of the parts of a newly read aout header */  obj_textsec (abfd)->_raw_size = N_TXTSIZE (*execp);  /* The virtual memory addresses of the sections */  obj_textsec (abfd)->vma = N_TXTADDR (*execp);  obj_datasec (abfd)->vma = N_DATADDR (*execp);  obj_bsssec (abfd)->vma = N_BSSADDR (*execp);  obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;  obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;  obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;  /* The file offsets of the sections */  obj_textsec (abfd)->filepos = N_TXTOFF (*execp);  obj_datasec (abfd)->filepos = N_DATOFF (*execp);  /* The file offsets of the relocation info */  obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);  obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);  /* The file offsets of the string table and symbol table.  */  obj_sym_filepos (abfd) = N_SYMOFF (*execp);  obj_str_filepos (abfd) = N_STROFF (*execp);  /* Determine the architecture and machine type of the object file.  */#ifdef SET_ARCH_MACH  SET_ARCH_MACH (abfd, *execp);#else  bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0);#endif  /* Now that we know the architecture, set the alignments of the     sections.  This is normally done by NAME(aout,new_section_hook),     but when the initial sections were created the architecture had     not yet been set.  However, for backward compatibility, we don't     set the alignment power any higher than as required by the size

⌨️ 快捷键说明

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