home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / gdb-4.12.tar.gz / gdb-4.12.tar / gdb-4.12 / bfd / srec.c < prev    next >
C/C++ Source or Header  |  1994-02-03  |  24KB  |  1,008 lines

  1. /* BFD back-end for s-record objects.
  2.    Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /*
  22. SUBSECTION
  23.     S-Record handling
  24.  
  25. DESCRIPTION
  26.     
  27.     Ordinary S-Records cannot hold anything but addresses and
  28.     data, so that's all that we implement.
  29.    
  30.     The only interesting thing is that S-Records may come out of
  31.     order and there is no header, so an initial scan is required
  32.     to discover the minimum and maximum addresses used to create
  33.     the vma and size of the only section we create.  We
  34.     arbitrarily call this section ".text". 
  35.  
  36.     When bfd_get_section_contents is called the file is read
  37.     again, and this time the data is placed into a bfd_alloc'd
  38.     area.
  39.  
  40.     Any number of sections may be created for output, we save them
  41.     up and output them when it's time to close the bfd.
  42.  
  43.     An s record looks like:
  44.     
  45. EXAMPLE
  46.     S<type><length><address><data><checksum>
  47.     
  48. DESCRIPTION
  49.     Where
  50.     o length
  51.     is the number of bytes following upto the checksum. Note that
  52.     this is not the number of chars following, since it takes two
  53.     chars to represent a byte.
  54.     o type
  55.     is one of:
  56.     0) header record
  57.     1) two byte address data record
  58.     2) three byte address data record
  59.     3) four byte address data record
  60.     7) four byte address termination record
  61.     8) three byte address termination record
  62.     9) two byte address termination record
  63.     
  64.     o address
  65.     is the start address of the data following, or in the case of
  66.     a termination record, the start address of the image
  67.     o data
  68.     is the data.
  69.     o checksum
  70.     is the sum of all the raw byte data in the record, from the length
  71.     upwards, modulo 256 and subtracted from 255.
  72.  
  73.  
  74. SUBSECTION
  75.     Symbol S-Record handling
  76.  
  77. DESCRIPTION
  78.     Some ICE equipment understands an addition to the standard
  79.     S-Record format; symbols and their addresses can be sent
  80.     before the data.
  81.  
  82.     The format of this is:
  83.     ($$ <modulename>
  84.         (<space> <symbol> <address>)*)
  85.     $$
  86.  
  87.     so a short symbol table could look like:
  88.  
  89. EXAMPLE
  90.     $$ flash.x
  91.     $$ flash.c
  92.       _port6 $0
  93.       _delay $4
  94.       _start $14
  95.       _etext $8036
  96.       _edata $8036
  97.        _end $8036
  98.     $$ 
  99.  
  100. DESCRIPTION
  101.     We allow symbols to be anywhere in the data stream - the module names
  102.     are always ignored.
  103.         
  104. */
  105.  
  106. #include "bfd.h"
  107. #include "sysdep.h"
  108. #include "libbfd.h"
  109.  
  110. /* Macros for converting between hex and binary */
  111.  
  112. static CONST char digs[] = "0123456789ABCDEF";
  113.  
  114. static char hex_value[1 + (unsigned char)~0];
  115.  
  116. #define NOT_HEX 20
  117. #define NIBBLE(x) hex_value[(unsigned char)(x)]
  118. #define HEX(buffer) ((NIBBLE((buffer)[0])<<4) + NIBBLE((buffer)[1]))
  119. #define TOHEX(d, x, ch) \
  120.     d[1] = digs[(x) & 0xf]; \
  121.     d[0] = digs[((x)>>4)&0xf]; \
  122.     ch += ((x) & 0xff);
  123. #define    ISHEX(x)  (hex_value[(unsigned char)(x)] != NOT_HEX)
  124.  
  125.  
  126.  
  127. static void
  128. DEFUN_VOID(srec_init) 
  129. {
  130.     unsigned int i;
  131.     static boolean inited = false;
  132.     
  133.     if (inited == false) 
  134.     {
  135.     
  136.     inited = true;
  137.     
  138.     for (i = 0; i < sizeof (hex_value); i++) 
  139.     {
  140.         hex_value[i] = NOT_HEX;
  141.     }
  142.     
  143.     for (i = 0; i < 10; i++) 
  144.     {
  145.         hex_value[i + '0'] = i;
  146.     
  147.     }
  148.     for (i = 0; i < 6; i++) 
  149.     {
  150.         hex_value[i + 'a'] = i+10;
  151.         hex_value[i + 'A'] = i+10;
  152.     }
  153.     }    
  154. }
  155.  
  156.  
  157. /* The maximum number of bytes on a line is FF */
  158. #define MAXCHUNK 0xff 
  159. /* The number of bytes we fit onto a line on output */
  160. #define CHUNK 21
  161.  
  162. /* We cannot output our srecords as we see them, we have to glue them
  163.    together, this is done in this structure : */
  164.  
  165. struct srec_data_list_struct
  166. {
  167.     unsigned    char *data;
  168.     bfd_vma where;
  169.     bfd_size_type size;
  170.     struct srec_data_list_struct *next;
  171.  
  172.     
  173. } ;
  174. typedef struct srec_data_list_struct srec_data_list_type;
  175.  
  176.  
  177. typedef struct  srec_data_struct
  178. {
  179.     srec_data_list_type *head;    
  180.     unsigned int type;
  181.     
  182.     int done_symbol_read;
  183.     int count;
  184.     asymbol *symbols;
  185.     char *strings;
  186.     int symbol_idx;
  187.     int string_size;
  188.     int string_idx;
  189. } tdata_type;
  190.  
  191.  
  192. /* 
  193.    called once per input S-Record, used to work out vma and size of data.
  194.  */
  195.  
  196. static bfd_vma low,high;
  197.  
  198. /*ARGSUSED*/
  199. static void
  200. size_symbols(abfd, buf, len, val)
  201. bfd *abfd;
  202. char *buf;
  203. int len;
  204. int val;
  205. {
  206.   abfd->symcount ++;
  207.   abfd->tdata.srec_data->string_size  += len + 1;
  208. }
  209.  
  210. static void
  211. fillup_symbols(abfd, buf, len, val)
  212. bfd *abfd;
  213. char *buf;
  214. int len;
  215. int val;
  216. {
  217.   if (!abfd->tdata.srec_data->done_symbol_read)
  218.   {
  219.     asymbol *p;
  220.     if (abfd->tdata.srec_data->symbols == 0)
  221.     {
  222.       abfd->tdata.srec_data->symbols = (asymbol *)bfd_alloc(abfd, abfd->symcount * sizeof(asymbol));
  223.       abfd->tdata.srec_data->strings = (char*)bfd_alloc(abfd, abfd->tdata.srec_data->string_size);
  224.       abfd->tdata.srec_data->symbol_idx = 0;
  225.       abfd->tdata.srec_data->string_idx = 0;
  226.     }
  227.  
  228.     p = abfd->tdata.srec_data->symbols + abfd->tdata.srec_data->symbol_idx++;
  229.     p->the_bfd = abfd;
  230.     p->name = abfd->tdata.srec_data->strings + abfd->tdata.srec_data->string_idx;
  231.     memcpy((char *)(p->name), buf, len+1);
  232.     abfd->tdata.srec_data->string_idx += len + 1;
  233.     p->value = val;
  234.     p->flags = BSF_EXPORT | BSF_GLOBAL;
  235.     p->section = &bfd_abs_section;
  236.     p->udata = 0;
  237.   }
  238. }
  239. /*ARGSUSED*/
  240. static void
  241. DEFUN(size_srec,(abfd, section, address, raw, length),
  242.       bfd *abfd AND
  243.       asection *section AND
  244.       bfd_vma address AND
  245.       bfd_byte *raw AND
  246.       unsigned int length)
  247. {
  248.   if (address < low)
  249.     low = address;
  250.   if (address + length > high) 
  251.     high = address + length -1;
  252. }
  253.  
  254.  
  255. /*
  256.  called once per input S-Record, copies data from input into bfd_alloc'd area
  257.  */
  258.  
  259. /*ARGSUSED*/
  260. static void
  261. DEFUN(fillup,(abfd, section, address, raw, length),
  262. bfd *abfd AND
  263. asection *section AND
  264. bfd_vma address AND
  265. bfd_byte *raw AND
  266. unsigned int length)
  267. {
  268.     unsigned int i;
  269.     bfd_byte *dst =
  270.      (bfd_byte *)(section->used_by_bfd) + address - section->vma;
  271.     /* length -1 because we don't read in the checksum */
  272.     for (i = 0; i < length -1 ; i++) {
  273.         *dst = HEX(raw);
  274.         dst++;
  275.         raw+=2;
  276.     }
  277. }
  278.  
  279. /* Pass over an S-Record file, calling one of the above functions on each
  280.    record.  */
  281.  
  282. static int white(x)
  283. char x;
  284. {
  285.   return (x== ' ' || x == '\t' || x == '\n' || x == '\r');
  286. }
  287. static int
  288. skipwhite(src,abfd)
  289. char *src;
  290. bfd *abfd;
  291. {
  292.   int eof = 0;
  293.   while (white(*src) && !eof)
  294.   {
  295.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  296.   }
  297.   return eof;
  298. }
  299.  
  300. static boolean
  301. DEFUN(srec_mkobject, (abfd), 
  302.       bfd *abfd)
  303. {
  304.   if (abfd->tdata.srec_data == 0) 
  305.   {
  306.     tdata_type *tdata = (tdata_type *)bfd_alloc(abfd,  sizeof(tdata_type));
  307.     abfd->tdata.srec_data = tdata;
  308.     tdata->type = 1;
  309.     tdata->head = (srec_data_list_type *)NULL;
  310.   }
  311.   return true;
  312.     
  313. }
  314.  
  315. static void pass_over(abfd, func, symbolfunc, section)
  316.      bfd *abfd;
  317.      void (*func)();
  318.      void (*symbolfunc)();
  319.      asection *section;
  320. {
  321.   unsigned int bytes_on_line;
  322.   boolean eof = false;
  323.  
  324.   srec_mkobject(abfd);
  325.   /* To the front of the file */
  326.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  327.   while (eof == false)
  328.   {
  329.     char buffer[MAXCHUNK];
  330.     char *src = buffer;
  331.     char type;
  332.     bfd_vma address = 0;
  333.  
  334.     /* Find first 'S' or $ */
  335.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  336.     switch (*src) 
  337.     {
  338.      default:
  339.       eof = (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  340.       if (eof)  return;
  341.       break;
  342.  
  343.      case '$':
  344.       /* Inside a symbol definition - just ignore the module name */
  345.       while (*src != '\n' && !eof) 
  346.       {
  347.     eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  348.       }
  349.       break;
  350.  
  351.      case ' ':
  352.       /* spaces - maybe just before a symbol */
  353.       while (*src != '\n' && *src != '\r' && white(*src)) 
  354.     {
  355.       eof = skipwhite(src, abfd);
  356.  
  357.       {
  358.         int val = 0;
  359.         int slen = 0;
  360.         char symbol[MAXCHUNK];
  361.  
  362.         /* get the symbol part */
  363.         while (!eof && !white(*src) && slen < MAXCHUNK)
  364.           {
  365.         symbol[slen++] = *src;
  366.         eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);      
  367.           }
  368.         symbol[slen] = 0;
  369.         eof = skipwhite(src, abfd);
  370.         /* skip the $ for the hex value */
  371.         if (*src == '$') 
  372.           {
  373.         eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  374.           }
  375.  
  376.         /* Scan off the hex number */
  377.         while (isxdigit(*src ))
  378.           {
  379.         val *= 16;
  380.         if (isdigit(*src))
  381.           val += *src - '0';
  382.         else if (isupper(*src)) {
  383.           val += *src - 'A' + 10;
  384.         }
  385.         else {
  386.           val += *src - 'a' + 10;
  387.         }
  388.         eof =  (boolean)(bfd_read(src, 1, 1, abfd) != 1);
  389.           }
  390.         symbolfunc(abfd, symbol, slen, val);
  391.       }
  392.     }
  393.       break;
  394.      case 'S':
  395.       src++;
  396.  
  397.       /* Fetch the type and the length */
  398.       bfd_read(src, 1, 3, abfd);
  399.  
  400.       type = *src++;
  401.  
  402.       if (!ISHEX (src[0]) || !ISHEX (src[1]))
  403.        break;
  404.  
  405.       bytes_on_line = HEX(src);
  406.  
  407.       if (bytes_on_line > MAXCHUNK/2)
  408.        break;
  409.       src+=2 ;
  410.  
  411.       bfd_read(src, 1 , bytes_on_line * 2, abfd);
  412.  
  413.       switch (type) {
  414.        case '0':
  415.        case '5':
  416.     /* Prologue - ignore */
  417.     break;
  418.        case '3':
  419.     address = HEX(src);
  420.     src+=2;
  421.     bytes_on_line--;
  422.         
  423.        case '2':
  424.     address = HEX(src) | (address<<8) ;
  425.     src+=2;
  426.     bytes_on_line--;
  427.        case '1':
  428.     address = HEX(src) | (address<<8) ;
  429.     src+=2;
  430.     address = HEX(src) | (address<<8) ;
  431.     src+=2;
  432.     bytes_on_line-=2;
  433.     func(abfd,section, address, src, bytes_on_line);
  434.     break;
  435.        default:
  436.     return;
  437.       }
  438.     }
  439.   }
  440.  
  441. }
  442.  
  443. static bfd_target *
  444. object_p(abfd)
  445. bfd *abfd;
  446. {
  447.   asection *section;
  448.   /* We create one section called .text for all the contents, 
  449.      and allocate enough room for the entire file.  */
  450.   
  451.   section =  bfd_make_section(abfd, ".text");
  452.   section->_raw_size = 0;
  453.   section->vma = 0xffffffff;
  454.   low = 0xffffffff;
  455.   high = 0;
  456.   pass_over(abfd, size_srec, size_symbols, section);
  457.   section->_raw_size = high - low;
  458.   section->vma = low;
  459.   section->flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
  460.  
  461.   if (abfd->symcount)
  462.    abfd->flags |= HAS_SYMS;  
  463.   return abfd->xvec;
  464. }
  465.  
  466. static bfd_target *
  467. DEFUN(srec_object_p, (abfd),
  468.       bfd *abfd)
  469. {
  470.   char b[4];
  471.  
  472.   srec_init();
  473.   
  474.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  475.   bfd_read(b, 1, 4, abfd);
  476.  
  477.   if (b[0] != 'S' || !ISHEX(b[1]) || !ISHEX(b[2]) || !ISHEX(b[3]))
  478.    return (bfd_target*) NULL;
  479.   
  480.   /* We create one section called .text for all the contents, 
  481.      and allocate enough room for the entire file.  */
  482.  
  483.   return object_p(abfd); 
  484. }
  485.  
  486.  
  487. static bfd_target *
  488. DEFUN(symbolsrec_object_p, (abfd),
  489.       bfd *abfd)
  490. {
  491.   char b[4];
  492.  
  493.   srec_init();
  494.   
  495.   bfd_seek(abfd, (file_ptr)0, SEEK_SET);
  496.   bfd_read(b, 1, 4, abfd);
  497.  
  498.   if (b[0] != '$' || b[1] != '$')
  499.     return (bfd_target*) NULL;
  500.  
  501.   return object_p(abfd);   
  502. }
  503.  
  504.  
  505. static boolean
  506. DEFUN(srec_get_section_contents,(abfd, section, location, offset, count),
  507.       bfd *abfd AND
  508.       asection *section AND
  509.       PTR location AND
  510.       file_ptr offset AND
  511.       bfd_size_type count)
  512. {
  513.     if (section->used_by_bfd == (PTR)NULL) 
  514.     {
  515.     section->used_by_bfd = (PTR)bfd_alloc (abfd, section->_raw_size);
  516.     
  517.     pass_over(abfd, fillup, fillup_symbols, section);
  518.     }
  519.     (void) memcpy((PTR)location,
  520.           (PTR)((char *)(section->used_by_bfd) + offset),
  521.           count);
  522.     return true;
  523. }
  524.       
  525.  
  526.  
  527. boolean
  528. DEFUN(srec_set_arch_mach,(abfd, arch, machine),
  529.       bfd *abfd AND
  530.       enum bfd_architecture arch AND
  531.       unsigned long machine)
  532. {
  533.   return bfd_default_set_arch_mach(abfd, arch, machine);
  534. }
  535.  
  536.  
  537. /* we have to save up all the Srecords for a splurge before output,
  538.    also remember   */
  539.  
  540. static boolean
  541. DEFUN(srec_set_section_contents,(abfd, section, location, offset, bytes_to_do),
  542.       bfd *abfd AND
  543.       sec_ptr section AND
  544.       PTR location AND
  545.       file_ptr offset AND
  546.       bfd_size_type bytes_to_do)
  547. {
  548.   tdata_type  *tdata = abfd->tdata.srec_data;
  549.   srec_data_list_type *entry = (srec_data_list_type *)
  550.     bfd_alloc(abfd, sizeof(srec_data_list_type));
  551.  
  552.   if ((section->flags & SEC_ALLOC)
  553.       && (section->flags & SEC_LOAD)) 
  554.     {
  555.       unsigned  char *data = (unsigned char *) bfd_alloc(abfd, bytes_to_do);
  556.       memcpy(data, location, bytes_to_do);
  557.  
  558.       if ((section->lma + offset + bytes_to_do) <= 0xffff)  
  559.     {
  560.  
  561.     }
  562.       else if ((section->lma + offset + bytes_to_do) <= 0xffffff 
  563.            && tdata->type < 2) 
  564.     {
  565.       tdata->type = 2;
  566.     }
  567.       else 
  568.     {
  569.       tdata->type = 3;
  570.     }
  571.  
  572.       entry->data = data;
  573.       entry->where = section->lma + offset;
  574.       entry->size = bytes_to_do;
  575.       entry->next = tdata->head;
  576.       tdata->head = entry;
  577.     }
  578.   return true;    
  579. }
  580.  
  581. /* Write a record of type, of the supplied number of bytes. The
  582.    supplied bytes and length don't have a checksum. That's worked out
  583.    here
  584. */
  585. static
  586. void DEFUN(srec_write_record,(abfd, type, address, data, end),
  587.        bfd *abfd AND
  588.        char type AND
  589.        bfd_vma address AND
  590.        CONST unsigned char *data AND
  591.        CONST unsigned char *end)
  592.  
  593. {
  594.     char buffer[MAXCHUNK];
  595.     
  596.     unsigned int check_sum = 0;
  597.     unsigned CONST char *src = data;
  598.     char *dst =buffer;
  599.     char *length;
  600.     
  601.  
  602.     *dst++ = 'S';
  603.     *dst++ = '0' + type;
  604.  
  605.     length = dst;
  606.     dst+=2;            /* leave room for dst*/
  607.     
  608.     switch (type) 
  609.     {
  610.       case 3:
  611.       case 7:
  612.     TOHEX(dst, (address >> 24), check_sum);
  613.     dst+=2;
  614.       case 8:
  615.       case 2:
  616.     TOHEX(dst, (address >> 16), check_sum);
  617.     dst+=2;
  618.       case 9:
  619.       case 1:
  620.       case 0:
  621.     TOHEX(dst, (address >> 8), check_sum);
  622.     dst+=2;
  623.     TOHEX(dst, (address), check_sum);
  624.     dst+=2;
  625.     break;
  626.  
  627.     }
  628.     for (src = data; src < end; src++) 
  629.     {
  630.     TOHEX(dst, *src, check_sum);
  631.     dst+=2;
  632.     }
  633.  
  634.     /* Fill in the length */
  635.     TOHEX(length, (dst - length)/2, check_sum);
  636.     check_sum &= 0xff;
  637.     check_sum = 255 - check_sum;
  638.     TOHEX(dst, check_sum, check_sum);
  639.     dst+=2;
  640.     
  641.     *dst ++ = '\r';
  642.     *dst ++ = '\n';
  643.     bfd_write((PTR)buffer, 1, dst - buffer , abfd);
  644. }
  645.  
  646.  
  647.  
  648. static void
  649. DEFUN(srec_write_header,(abfd),
  650.       bfd *abfd)
  651. {
  652.     unsigned char buffer[MAXCHUNK];
  653.     unsigned char *dst = buffer;
  654.     unsigned int i;
  655.  
  656.     /* I'll put an arbitary 40 char limit on header size */
  657.     for (i = 0; i < 40 && abfd->filename[i];  i++) 
  658.     {
  659.     *dst++ = abfd->filename[i];
  660.     }
  661.     srec_write_record(abfd,0, 0, buffer, dst);
  662. }
  663.  
  664. static void
  665. DEFUN(srec_write_section,(abfd, tdata, list),
  666.        bfd *abfd AND
  667.        tdata_type *tdata AND
  668.        srec_data_list_type *list)
  669. {
  670.     unsigned int bytes_written = 0;
  671.     unsigned char *location = list->data;
  672.  
  673.     while (bytes_written < list->size)
  674.     {
  675.     bfd_vma address;
  676.     
  677.     unsigned int bytes_this_chunk = list->size - bytes_written;
  678.  
  679.     if (bytes_this_chunk > CHUNK) 
  680.     {
  681.         bytes_this_chunk = CHUNK;
  682.     }
  683.  
  684.     address = list->where +  bytes_written;
  685.  
  686.     srec_write_record(abfd,
  687.               tdata->type,
  688.               address,
  689.               location,
  690.               location + bytes_this_chunk);
  691.  
  692.     bytes_written += bytes_this_chunk;
  693.     location += bytes_this_chunk;
  694.     }
  695.  
  696. }
  697.  
  698. static void
  699. DEFUN(srec_write_terminator,(abfd, tdata),
  700.       bfd *abfd AND
  701.       tdata_type *tdata)
  702. {
  703.     unsigned    char buffer[2];
  704.     
  705.     srec_write_record(abfd, 10 - tdata->type,
  706.               abfd->start_address, buffer, buffer);
  707. }
  708.  
  709.  
  710.       
  711. static void
  712. srec_write_symbols(abfd)
  713.      bfd *abfd;
  714. {
  715.   char buffer[MAXCHUNK];
  716.   /* Dump out the symbols of a bfd */
  717.   int i;
  718.   int len = bfd_get_symcount(abfd);
  719.  
  720.   if (len) 
  721.   {
  722.     asymbol **table = bfd_get_outsymbols(abfd);
  723.     sprintf(buffer, "$$ %s\r\n", abfd->filename);
  724.  
  725.     bfd_write(buffer, strlen(buffer), 1, abfd);
  726.  
  727.     for (i = 0; i < len; i++) 
  728.     {
  729.       asymbol *s = table[i];
  730. #if 0
  731.       int len = strlen(s->name);
  732.  
  733.       /* If this symbol has a .[ocs] in it, it's probably a file name
  734.      and we'll output that as the module name */
  735.  
  736.       if (len > 3 && s->name[len-2] == '.') 
  737.       {
  738.     int l;
  739.     sprintf(buffer, "$$ %s\r\n", s->name);
  740.     l = strlen(buffer);
  741.     bfd_write(buffer, l, 1, abfd);
  742.       }
  743.       else
  744. #endif
  745.        if (s->flags & (BSF_GLOBAL | BSF_LOCAL) 
  746.            && (s->flags & BSF_DEBUGGING) == 0
  747.            && s->name[0] != '.'
  748.            && s->name[0] != 't')
  749.       {
  750.     /* Just dump out non debug symbols */
  751.  
  752.     int l;
  753.     char buf2[40], *p;
  754.  
  755.     sprintf_vma (buf2,
  756.              s->value + s->section->output_section->lma 
  757.              + s->section->output_offset);
  758.     p = buf2;
  759.     while (p[0] == '0' && p[1] != 0)
  760.       p++;
  761.     sprintf (buffer, "  %s $%s\r\n", s->name, p);
  762.     l = strlen(buffer);
  763.     bfd_write(buffer, l, 1,abfd);
  764.       }
  765.     }
  766.     sprintf(buffer, "$$ \r\n");
  767.     bfd_write(buffer, strlen(buffer), 1, abfd);
  768.   }
  769. }
  770.  
  771. static boolean
  772. internal_srec_write_object_contents(abfd, symbols)
  773.      bfd *abfd;
  774.      int symbols;
  775. {
  776.     tdata_type *tdata = abfd->tdata.srec_data;
  777.     srec_data_list_type *list;
  778.  
  779.     if (symbols)
  780.      srec_write_symbols(abfd);
  781.  
  782.     srec_write_header(abfd);
  783.  
  784.     /* Now wander though all the sections provided and output them */
  785.     list = tdata->head;
  786.  
  787.     while (list != (srec_data_list_type*)NULL) 
  788.     {
  789.     srec_write_section(abfd, tdata, list); 
  790.     list = list->next;
  791.     }
  792.     srec_write_terminator(abfd, tdata);
  793.     return true;
  794. }
  795.  
  796. static boolean
  797. srec_write_object_contents(abfd)
  798.      bfd *abfd;
  799. {
  800.   return internal_srec_write_object_contents(abfd, 0);
  801. }
  802.  
  803. static boolean
  804. symbolsrec_write_object_contents(abfd)
  805.      bfd *abfd;
  806. {
  807.   return internal_srec_write_object_contents(abfd, 1);
  808. }
  809.  
  810. /*ARGSUSED*/
  811. static int 
  812. DEFUN(srec_sizeof_headers,(abfd, exec),
  813.       bfd *abfd AND
  814.       boolean exec)
  815. {
  816. return 0;
  817. }
  818.  
  819. static asymbol *
  820. DEFUN(srec_make_empty_symbol, (abfd),
  821.       bfd*abfd)
  822. {
  823.   asymbol *new=  (asymbol *)bfd_zalloc (abfd, sizeof (asymbol));
  824.   new->the_bfd = abfd;
  825.   return new;
  826. }
  827.  
  828. static unsigned int
  829. srec_get_symtab_upper_bound(abfd)
  830. bfd *abfd;
  831. {
  832.   /* Read in all the info */
  833.   srec_get_section_contents(abfd,abfd->sections,0,0,0);
  834.   return (bfd_get_symcount(abfd) + 1) * (sizeof(asymbol *));
  835. }
  836.  
  837. static unsigned int
  838. DEFUN(srec_get_symtab, (abfd, alocation),
  839.       bfd            *abfd AND
  840.       asymbol       **alocation)
  841. {
  842.   int lim = abfd->symcount;
  843.   int i;
  844.   for (i = 0; i < lim; i++) {
  845.     alocation[i] = abfd->tdata.srec_data->symbols + i;
  846.   }
  847.   alocation[i] = 0;
  848.   return lim;
  849. }
  850.  
  851. /*ARGSUSED*/
  852. void 
  853. DEFUN(srec_get_symbol_info,(ignore_abfd, symbol, ret),
  854.       bfd *ignore_abfd AND
  855.       asymbol *symbol AND
  856.       symbol_info *ret)
  857. {
  858.   bfd_symbol_info (symbol, ret);
  859. }
  860.  
  861. /*ARGSUSED*/
  862. void 
  863. DEFUN(srec_print_symbol,(ignore_abfd, afile, symbol, how),
  864.       bfd *ignore_abfd AND
  865.       PTR afile AND
  866.       asymbol *symbol AND
  867.       bfd_print_symbol_type how)
  868. {
  869.   FILE *file = (FILE *)afile;
  870.   switch (how) 
  871.   {
  872.    case bfd_print_symbol_name:
  873.     fprintf (file, "%s", symbol->name);
  874.     break;
  875.    default:
  876.     bfd_print_symbol_vandf ((PTR) file, symbol);
  877.     fprintf (file, " %-5s %s",
  878.          symbol->section->name,
  879.          symbol->name);
  880.  
  881.   }
  882. }
  883.  
  884. #define FOO PROTO
  885. #define srec_new_section_hook (FOO(boolean, (*), (bfd *, asection *)))bfd_true
  886.  
  887. #define srec_get_reloc_upper_bound (FOO(unsigned int, (*),(bfd*, asection *)))bfd_false
  888. #define srec_canonicalize_reloc (FOO(unsigned int, (*),(bfd*,asection *, arelent **, asymbol **))) bfd_0
  889.  
  890.  
  891.  
  892. #define srec_openr_next_archived_file (FOO(bfd *, (*), (bfd*,bfd*))) bfd_nullvoidptr
  893. #define srec_find_nearest_line (FOO(boolean, (*),(bfd*,asection*,asymbol**,bfd_vma, CONST char**, CONST char**, unsigned int *))) bfd_false
  894. #define srec_generic_stat_arch_elt  (FOO(int, (*), (bfd *,struct stat *))) bfd_0
  895.  
  896.  
  897. #define srec_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
  898. #define srec_core_file_failing_signal (int (*)())bfd_0
  899. #define srec_core_file_matches_executable_p (FOO(boolean, (*),(bfd*, bfd*)))bfd_false
  900. #define srec_slurp_armap bfd_true
  901. #define srec_slurp_extended_name_table bfd_true
  902. #define srec_truncate_arname (void (*)())bfd_nullvoidptr
  903. #define srec_write_armap  (FOO( boolean, (*),(bfd *, unsigned int, struct orl *, unsigned int, int))) bfd_nullvoidptr
  904. #define srec_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
  905. #define    srec_close_and_cleanup    bfd_generic_close_and_cleanup
  906. #define srec_bfd_debug_info_start bfd_void
  907. #define srec_bfd_debug_info_end bfd_void
  908. #define srec_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *,     asection *))) bfd_void
  909. #define srec_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  910. #define srec_bfd_relax_section bfd_generic_relax_section
  911. #define srec_bfd_reloc_type_lookup \
  912.   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
  913. #define srec_bfd_make_debug_symbol \
  914.   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
  915. #define srec_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  916. #define srec_bfd_link_add_symbols _bfd_generic_link_add_symbols
  917. #define srec_bfd_final_link _bfd_generic_final_link
  918.  
  919. bfd_target srec_vec =
  920. {
  921.     "srec",            /* name */
  922.     bfd_target_srec_flavour,
  923.     true,            /* target byte order */
  924.     true,            /* target headers byte order */
  925.     (HAS_RELOC | EXEC_P |    /* object flags */
  926.      HAS_LINENO | HAS_DEBUG |
  927.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  928.     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
  929.      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  930.      0,                /* leading underscore */
  931.     ' ',            /* ar_pad_char */
  932.     16,                /* ar_max_namelen */
  933.     1,                /* minimum alignment */
  934.     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  935.       bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
  936.       bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
  937.     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  938.       bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
  939.       bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  940.  
  941.   {
  942.       _bfd_dummy_target,
  943.       srec_object_p,        /* bfd_check_format */
  944.       (struct bfd_target *(*)()) bfd_nullvoidptr,
  945.       (struct bfd_target *(*)())     bfd_nullvoidptr,
  946.   },
  947.   {
  948.       bfd_false,
  949.       srec_mkobject,
  950.       _bfd_generic_mkarchive,
  951.       bfd_false,
  952.   },
  953.   {                /* bfd_write_contents */
  954.       bfd_false,
  955.       srec_write_object_contents,
  956.       _bfd_write_archive_contents,
  957.       bfd_false,
  958.   },
  959.     JUMP_TABLE(srec)
  960.  };
  961.  
  962.  
  963.  
  964. bfd_target symbolsrec_vec =
  965. {
  966.     "symbolsrec",        /* name */
  967.     bfd_target_srec_flavour,
  968.     true,            /* target byte order */
  969.     true,            /* target headers byte order */
  970.     (HAS_RELOC | EXEC_P |    /* object flags */
  971.      HAS_LINENO | HAS_DEBUG |
  972.      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  973.     (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
  974.      |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  975.      0,                /* leading underscore */
  976.     ' ',            /* ar_pad_char */
  977.     16,                /* ar_max_namelen */
  978.     1,                /* minimum alignment */
  979.     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  980.       bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
  981.       bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
  982.     bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  983.       bfd_getb32, bfd_getb_signed_32,     bfd_putb32,
  984.       bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
  985.  
  986.   {
  987.       _bfd_dummy_target,
  988.       symbolsrec_object_p,        /* bfd_check_format */
  989.       (struct bfd_target *(*)()) bfd_nullvoidptr,
  990.       (struct bfd_target *(*)())     bfd_nullvoidptr,
  991.   },
  992.   {
  993.       bfd_false,
  994.       srec_mkobject,
  995.       _bfd_generic_mkarchive,
  996.       bfd_false,
  997.   },
  998.   {                /* bfd_write_contents */
  999.       bfd_false,
  1000.       symbolsrec_write_object_contents,
  1001.       _bfd_write_archive_contents,
  1002.       bfd_false,
  1003.   },
  1004.     JUMP_TABLE(srec),
  1005.     (PTR) 0
  1006.  };
  1007.  
  1008.