Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/tekhex.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD backend for Extended Tektronix Hex Format  objects.
    2    Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
     2   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44   Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
     
    105105static void tekhex_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
    106106static asymbol *tekhex_make_empty_symbol PARAMS ((bfd *));
    107 static int tekhex_sizeof_headers PARAMS ((bfd *, boolean));
    108 static boolean tekhex_write_object_contents PARAMS ((bfd *));
     107static int tekhex_sizeof_headers PARAMS ((bfd *, bfd_boolean));
     108static bfd_boolean tekhex_write_object_contents PARAMS ((bfd *));
    109109static void out PARAMS ((bfd *, int, char *, char *));
    110 static void writesym PARAMS ((char **, CONST char *));
     110static void writesym PARAMS ((char **, const char *));
    111111static void writevalue PARAMS ((char **, bfd_vma));
    112 static boolean tekhex_set_section_contents
     112static bfd_boolean tekhex_set_section_contents
    113113 PARAMS ((bfd*, sec_ptr, PTR, file_ptr, bfd_size_type));
    114 static boolean tekhex_set_arch_mach
     114static bfd_boolean tekhex_set_arch_mach
    115115 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
    116 static boolean tekhex_get_section_contents
     116static bfd_boolean tekhex_get_section_contents
    117117 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
    118118static void move_section_contents
    119  PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type, boolean));
     119 PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type, bfd_boolean));
    120120static const bfd_target *tekhex_object_p PARAMS ((bfd *));
    121 static boolean tekhex_mkobject PARAMS ((bfd *));
     121static bfd_boolean tekhex_mkobject PARAMS ((bfd *));
    122122static long tekhex_get_symtab_upper_bound PARAMS ((bfd *));
    123123static long tekhex_get_symtab PARAMS ((bfd *, asymbol **));
     
    240240{
    241241  unsigned int i;
    242   static boolean inited = false;
     242  static bfd_boolean inited = FALSE;
    243243  int val;
    244244
    245   if (inited == false)
    246     {
    247       inited = true;
     245  if (! inited)
     246    {
     247      inited = TRUE;
    248248      hex_init ();
    249249      val = 0;
     
    355355  if (!d)
    356356    {
    357       char *sname = bfd_alloc (abfd, 12);
    358 
    359357      /* No chunk for this address, so make one up */
    360       d = (struct data_struct *)
    361         bfd_alloc (abfd, sizeof (struct data_struct));
    362 
    363       if (!sname || !d)
     358      d = ((struct data_struct *)
     359           bfd_zalloc (abfd, (bfd_size_type) sizeof (struct data_struct)));
     360
     361      if (!d)
    364362        return NULL;
    365363
    366       memset (d->chunk_init, 0, CHUNK_MASK + 1);
    367       memset (d->chunk_data, 0, CHUNK_MASK + 1);
    368364      d->next = abfd->tdata.tekhex_data->data;
    369365      d->vma = vma;
     
    395391{
    396392  asection *section = bfd_abs_section_ptr;
    397   int len;
     393  unsigned int len;
    398394  char sym[17];                 /* A symbol can only be 16chars long */
    399395
     
    420416      if (section == (asection *) NULL)
    421417        {
    422           char *n = bfd_alloc (abfd, len + 1);
     418          char *n = bfd_alloc (abfd, (bfd_size_type) len + 1);
    423419
    424420          if (!n)
     
    446442              /* Symbols, add to section */
    447443              {
     444                bfd_size_type amt = sizeof (tekhex_symbol_type);
    448445                tekhex_symbol_type *new =
    449                 (tekhex_symbol_type *) bfd_alloc (abfd,
    450                                                sizeof (tekhex_symbol_type));
    451                 char type = (*src);
     446                  (tekhex_symbol_type *) bfd_alloc (abfd, amt);
     447                char stype = (*src);
    452448
    453449                if (!new)
     
    460456                abfd->tdata.tekhex_data->symbols = new;
    461457                len = getsym (sym, &src);
    462                 new->symbol.name = bfd_alloc (abfd, len + 1);
     458                new->symbol.name = bfd_alloc (abfd, (bfd_size_type) len + 1);
    463459                if (!new->symbol.name)
    464460                  abort ();     /* FIXME */
    465461                memcpy ((char *) (new->symbol.name), sym, len + 1);
    466462                new->symbol.section = section;
    467                 if (type <= '4')
     463                if (stype <= '4')
    468464                  new->symbol.flags = (BSF_GLOBAL | BSF_EXPORT);
    469465                else
     
    476472}
    477473
    478 /* Pass over an tekhex, calling one of the above functions on each
     474/* Pass over a tekhex, calling one of the above functions on each
    479475   record.  */
    480476
     
    485481{
    486482  unsigned int chars_on_line;
    487   boolean eof = false;
     483  bfd_boolean eof = FALSE;
    488484
    489485  /* To the front of the file */
    490486  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
    491487    abort ();
    492   while (eof == false)
     488  while (! eof)
    493489    {
    494490      char buffer[MAXCHUNK];
     
    497493
    498494      /* Find first '%' */
    499       eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
     495      eof = (bfd_boolean) (bfd_bread (src, (bfd_size_type) 1, abfd) != 1);
    500496      while (*src != '%' && !eof)
    501497        {
    502           eof = (boolean) (bfd_read (src, 1, 1, abfd) != 1);
     498          eof = (bfd_boolean) (bfd_bread (src, (bfd_size_type) 1, abfd) != 1);
    503499        }
    504500      if (eof)
     
    507503
    508504      /* Fetch the type and the length and the checksum */
    509       if (bfd_read (src, 1, 5, abfd) != 5)
     505      if (bfd_bread (src, (bfd_size_type) 5, abfd) != 5)
    510506        abort (); /* FIXME */
    511507
     
    517513      chars_on_line = HEX (src) - 5;    /* Already read five char */
    518514
    519       if (bfd_read (src, 1, chars_on_line, abfd) != chars_on_line)
     515      if (bfd_bread (src, (bfd_size_type) chars_on_line, abfd) != chars_on_line)
    520516        abort (); /* FIXME */
    521517      src[chars_on_line] = 0;   /* put a null at the end */
     
    552548}
    553549
    554 static boolean
     550static bfd_boolean
    555551tekhex_mkobject (abfd)
    556552     bfd *abfd;
    557553{
    558   tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, sizeof (tdata_type));
    559 
     554  tdata_type *tdata;
     555
     556  tdata = (tdata_type *) bfd_alloc (abfd, (bfd_size_type) sizeof (tdata_type));
    560557  if (!tdata)
    561     return false;
     558    return FALSE;
    562559  abfd->tdata.tekhex_data = tdata;
    563560  tdata->type = 1;
     
    565562  tdata->symbols = (struct tekhex_symbol_struct *) NULL;
    566563  tdata->data = (struct data_struct *) NULL;
    567   return true;
     564  return TRUE;
    568565}
    569566
    570567/*
    571   Return true if the file looks like it's in TekHex format. Just look
     568  Return TRUE if the file looks like it's in TekHex format. Just look
    572569  for a percent sign and some hex digits */
    573570
     
    581578
    582579  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
    583       || bfd_read (b, 1, 4, abfd) != 4)
     580      || bfd_bread (b, (bfd_size_type) 4, abfd) != 4)
    584581    return NULL;
    585582
     
    598595     asection *section;
    599596     PTR locationp;
    600      file_ptr offset ATTRIBUTE_UNUSED;
     597     file_ptr offset;
    601598     bfd_size_type count;
    602      boolean get;
     599     bfd_boolean get;
    603600{
    604601  bfd_vma addr;
     
    607604  struct data_struct *d = (struct data_struct *) NULL;
    608605
     606  BFD_ASSERT (offset == 0);
    609607  for (addr = section->vma; count != 0; count--, addr++)
    610608    {
    611 
    612       bfd_vma chunk_number = addr & ~CHUNK_MASK;        /* Get high bits of address */
     609      /* Get high bits of address.  */
     610      bfd_vma chunk_number = addr & ~(bfd_vma) CHUNK_MASK;
    613611      bfd_vma low_bits = addr & CHUNK_MASK;
    614612
     
    642640}
    643641
    644 static boolean
     642static bfd_boolean
    645643tekhex_get_section_contents (abfd, section, locationp, offset, count)
    646644     bfd *abfd;
     
    652650  if (section->flags & (SEC_LOAD | SEC_ALLOC))
    653651    {
    654       move_section_contents (abfd, section, locationp, offset, count, true);
    655       return true;
     652      move_section_contents (abfd, section, locationp, offset, count, TRUE);
     653      return TRUE;
    656654    }
    657655  else
    658     return false;
    659 }
    660 
    661 static boolean
     656    return FALSE;
     657}
     658
     659static bfd_boolean
    662660tekhex_set_arch_mach (abfd, arch, machine)
    663661     bfd *abfd;
     
    671669    */
    672670
    673 static boolean
     671static bfd_boolean
    674672tekhex_set_section_contents (abfd, section, locationp, offset, bytes_to_do)
    675673     bfd *abfd;
     
    680678{
    681679
    682   if (abfd->output_has_begun == false)
     680  if (! abfd->output_has_begun)
    683681    {
    684682      /* The first time around, allocate enough sections to hold all the chunks */
     
    690688          if (s->flags & SEC_LOAD)
    691689            {
    692               for (vma = s->vma & ~CHUNK_MASK;
     690              for (vma = s->vma & ~(bfd_vma) CHUNK_MASK;
    693691                   vma < s->vma + s->_raw_size;
    694692                   vma += CHUNK_MASK)
     
    700698  if (section->flags & (SEC_LOAD | SEC_ALLOC))
    701699    {
    702       move_section_contents (abfd, section, locationp, offset, bytes_to_do, false);
    703       return true;
     700      move_section_contents (abfd, section, locationp, offset, bytes_to_do,
     701                             FALSE);
     702      return TRUE;
    704703    }
    705704  else
    706     return false;
     705    return FALSE;
    707706
    708707}
     
    741740writesym (dst, sym)
    742741     char **dst;
    743      CONST char *sym;
     742     const char *sym;
    744743{
    745744  char *p = *dst;
     
    798797  sum += sum_block[(unsigned char) front[3]];   /* type */
    799798  TOHEX (front + 4, sum);
    800   if (bfd_write (front, 1, 6, abfd) != 6)
     799  if (bfd_bwrite (front, (bfd_size_type) 6, abfd) != 6)
    801800    abort ();
    802801  end[0] = '\n';
    803802  wrlen = end - start + 1;
    804   if (bfd_write (start, 1, wrlen, abfd) != wrlen)
     803  if (bfd_bwrite (start, wrlen, abfd) != wrlen)
    805804    abort ();
    806805}
    807806
    808 static boolean
     807static bfd_boolean
    809808tekhex_write_object_contents (abfd)
    810809     bfd *abfd;
     
    827826      int low;
    828827
    829       CONST int span = 32;
     828      const int span = 32;
    830829      int addr;
    831830
     
    877876          if (section_code != '?')
    878877            {                   /* do not include debug symbols */
    879               asymbol *s = *p;
     878              asymbol *sym = *p;
    880879              char *dst = buffer;
    881880
    882               writesym (&dst, s->section->name);
     881              writesym (&dst, sym->section->name);
    883882
    884883              switch (section_code)
     
    909908                case 'U':
    910909                  bfd_set_error (bfd_error_wrong_format);
    911                   return false;
     910                  return FALSE;
    912911                }
    913912
    914               writesym (&dst, s->name);
    915               writevalue (&dst, s->value + s->section->vma);
     913              writesym (&dst, sym->name);
     914              writevalue (&dst, sym->value + sym->section->vma);
    916915              out (abfd, '3', buffer, dst);
    917916            }
     
    920919
    921920  /* And the terminator */
    922   if (bfd_write ("%0781010\n", 1, 9, abfd) != 9)
     921  if (bfd_bwrite ("%0781010\n", (bfd_size_type) 9, abfd) != 9)
    923922    abort ();
    924   return true;
     923  return TRUE;
    925924}
    926925
     
    928927tekhex_sizeof_headers (abfd, exec)
    929928     bfd *abfd ATTRIBUTE_UNUSED;
    930      boolean exec ATTRIBUTE_UNUSED;
     929     bfd_boolean exec ATTRIBUTE_UNUSED;
    931930
    932931{
     
    938937     bfd *abfd;
    939938{
    940   tekhex_symbol_type *new =
    941   (tekhex_symbol_type *) bfd_zalloc (abfd, sizeof (struct tekhex_symbol_struct));
     939  bfd_size_type amt = sizeof (struct tekhex_symbol_struct);
     940  tekhex_symbol_type *new = (tekhex_symbol_type *) bfd_zalloc (abfd, amt);
    942941
    943942  if (!new)
     
    958957
    959958static void
    960 tekhex_print_symbol (ignore_abfd, filep, symbol, how)
    961      bfd *ignore_abfd ATTRIBUTE_UNUSED;
     959tekhex_print_symbol (abfd, filep, symbol, how)
     960     bfd *abfd;
    962961     PTR filep;
    963962     asymbol *symbol;
     
    976975    case bfd_print_symbol_all:
    977976      {
    978         CONST char *section_name = symbol->section->name;
    979 
    980         bfd_print_symbol_vandf ((PTR) file, symbol);
     977        const char *section_name = symbol->section->name;
     978
     979        bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
    981980
    982981        fprintf (file, " %-5s %s",
     
    10021001#define tekhex_bfd_relax_section bfd_generic_relax_section
    10031002#define tekhex_bfd_gc_sections bfd_generic_gc_sections
     1003#define tekhex_bfd_merge_sections bfd_generic_merge_sections
     1004#define tekhex_bfd_discard_group bfd_generic_discard_group
    10041005#define tekhex_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
     1006#define tekhex_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
    10051007#define tekhex_bfd_link_add_symbols _bfd_generic_link_add_symbols
     1008#define tekhex_bfd_link_just_syms _bfd_generic_link_just_syms
    10061009#define tekhex_bfd_final_link _bfd_generic_final_link
    10071010#define tekhex_bfd_link_split_section _bfd_generic_link_split_section
Note: See TracChangeset for help on using the changeset viewer.