xref: /dragonfly/contrib/binutils-2.27/bfd/srec.c (revision a9fa9459)
1*a9fa9459Szrj /* BFD back-end for s-record objects.
2*a9fa9459Szrj    Copyright (C) 1990-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
4*a9fa9459Szrj 
5*a9fa9459Szrj    This file is part of BFD, the Binary File Descriptor library.
6*a9fa9459Szrj 
7*a9fa9459Szrj    This program is free software; you can redistribute it and/or modify
8*a9fa9459Szrj    it under the terms of the GNU General Public License as published by
9*a9fa9459Szrj    the Free Software Foundation; either version 3 of the License, or
10*a9fa9459Szrj    (at your option) any later version.
11*a9fa9459Szrj 
12*a9fa9459Szrj    This program is distributed in the hope that it will be useful,
13*a9fa9459Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a9fa9459Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a9fa9459Szrj    GNU General Public License for more details.
16*a9fa9459Szrj 
17*a9fa9459Szrj    You should have received a copy of the GNU General Public License
18*a9fa9459Szrj    along with this program; if not, write to the Free Software
19*a9fa9459Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20*a9fa9459Szrj    MA 02110-1301, USA.  */
21*a9fa9459Szrj 
22*a9fa9459Szrj 
23*a9fa9459Szrj /* SUBSECTION
24*a9fa9459Szrj 	S-Record handling
25*a9fa9459Szrj 
26*a9fa9459Szrj    DESCRIPTION
27*a9fa9459Szrj 
28*a9fa9459Szrj 	Ordinary S-Records cannot hold anything but addresses and
29*a9fa9459Szrj 	data, so that's all that we implement.
30*a9fa9459Szrj 
31*a9fa9459Szrj 	The only interesting thing is that S-Records may come out of
32*a9fa9459Szrj 	order and there is no header, so an initial scan is required
33*a9fa9459Szrj 	to discover the minimum and maximum addresses used to create
34*a9fa9459Szrj 	the vma and size of the only section we create.  We
35*a9fa9459Szrj 	arbitrarily call this section ".text".
36*a9fa9459Szrj 
37*a9fa9459Szrj 	When bfd_get_section_contents is called the file is read
38*a9fa9459Szrj 	again, and this time the data is placed into a bfd_alloc'd
39*a9fa9459Szrj 	area.
40*a9fa9459Szrj 
41*a9fa9459Szrj 	Any number of sections may be created for output, we save them
42*a9fa9459Szrj 	up and output them when it's time to close the bfd.
43*a9fa9459Szrj 
44*a9fa9459Szrj 	An s record looks like:
45*a9fa9459Szrj 
46*a9fa9459Szrj    EXAMPLE
47*a9fa9459Szrj 	S<type><length><address><data><checksum>
48*a9fa9459Szrj 
49*a9fa9459Szrj    DESCRIPTION
50*a9fa9459Szrj 	Where
51*a9fa9459Szrj 	o length
52*a9fa9459Szrj 	is the number of bytes following upto the checksum. Note that
53*a9fa9459Szrj 	this is not the number of chars following, since it takes two
54*a9fa9459Szrj 	chars to represent a byte.
55*a9fa9459Szrj 	o type
56*a9fa9459Szrj 	is one of:
57*a9fa9459Szrj 	0) header record
58*a9fa9459Szrj 	1) two byte address data record
59*a9fa9459Szrj 	2) three byte address data record
60*a9fa9459Szrj 	3) four byte address data record
61*a9fa9459Szrj 	7) four byte address termination record
62*a9fa9459Szrj 	8) three byte address termination record
63*a9fa9459Szrj 	9) two byte address termination record
64*a9fa9459Szrj 
65*a9fa9459Szrj 	o address
66*a9fa9459Szrj 	is the start address of the data following, or in the case of
67*a9fa9459Szrj 	a termination record, the start address of the image
68*a9fa9459Szrj 	o data
69*a9fa9459Szrj 	is the data.
70*a9fa9459Szrj 	o checksum
71*a9fa9459Szrj 	is the sum of all the raw byte data in the record, from the length
72*a9fa9459Szrj 	upwards, modulo 256 and subtracted from 255.
73*a9fa9459Szrj 
74*a9fa9459Szrj    SUBSECTION
75*a9fa9459Szrj 	Symbol S-Record handling
76*a9fa9459Szrj 
77*a9fa9459Szrj    DESCRIPTION
78*a9fa9459Szrj 	Some ICE equipment understands an addition to the standard
79*a9fa9459Szrj 	S-Record format; symbols and their addresses can be sent
80*a9fa9459Szrj 	before the data.
81*a9fa9459Szrj 
82*a9fa9459Szrj 	The format of this is:
83*a9fa9459Szrj 	($$ <modulename>
84*a9fa9459Szrj 		(<space> <symbol> <address>)*)
85*a9fa9459Szrj 	$$
86*a9fa9459Szrj 
87*a9fa9459Szrj 	so a short symbol table could look like:
88*a9fa9459Szrj 
89*a9fa9459Szrj    EXAMPLE
90*a9fa9459Szrj 	$$ flash.x
91*a9fa9459Szrj 	$$ flash.c
92*a9fa9459Szrj 	  _port6 $0
93*a9fa9459Szrj 	  _delay $4
94*a9fa9459Szrj 	  _start $14
95*a9fa9459Szrj 	  _etext $8036
96*a9fa9459Szrj 	  _edata $8036
97*a9fa9459Szrj  	  _end $8036
98*a9fa9459Szrj 	$$
99*a9fa9459Szrj 
100*a9fa9459Szrj    DESCRIPTION
101*a9fa9459Szrj 	We allow symbols to be anywhere in the data stream - the module names
102*a9fa9459Szrj 	are always ignored.  */
103*a9fa9459Szrj 
104*a9fa9459Szrj #include "sysdep.h"
105*a9fa9459Szrj #include "bfd.h"
106*a9fa9459Szrj #include "libbfd.h"
107*a9fa9459Szrj #include "libiberty.h"
108*a9fa9459Szrj #include "safe-ctype.h"
109*a9fa9459Szrj 
110*a9fa9459Szrj 
111*a9fa9459Szrj /* Macros for converting between hex and binary.  */
112*a9fa9459Szrj 
113*a9fa9459Szrj static const char digs[] = "0123456789ABCDEF";
114*a9fa9459Szrj 
115*a9fa9459Szrj #define NIBBLE(x)    hex_value(x)
116*a9fa9459Szrj #define HEX(buffer) ((NIBBLE ((buffer)[0])<<4) + NIBBLE ((buffer)[1]))
117*a9fa9459Szrj #define TOHEX(d, x, ch) \
118*a9fa9459Szrj 	d[1] = digs[(x) & 0xf]; \
119*a9fa9459Szrj 	d[0] = digs[((x)>>4)&0xf]; \
120*a9fa9459Szrj 	ch += ((x) & 0xff);
121*a9fa9459Szrj #define	ISHEX(x)    hex_p(x)
122*a9fa9459Szrj 
123*a9fa9459Szrj /* The maximum number of address+data+crc bytes on a line is FF.  */
124*a9fa9459Szrj #define MAXCHUNK 0xff
125*a9fa9459Szrj 
126*a9fa9459Szrj /* Default size for a CHUNK.  */
127*a9fa9459Szrj #define DEFAULT_CHUNK 16
128*a9fa9459Szrj 
129*a9fa9459Szrj /* The number of data bytes we actually fit onto a line on output.
130*a9fa9459Szrj    This variable can be modified by objcopy's --srec-len parameter.
131*a9fa9459Szrj    For a 0x75 byte record you should set --srec-len=0x70.  */
132*a9fa9459Szrj unsigned int Chunk = DEFAULT_CHUNK;
133*a9fa9459Szrj 
134*a9fa9459Szrj /* The type of srec output (free or forced to S3).
135*a9fa9459Szrj    This variable can be modified by objcopy's --srec-forceS3
136*a9fa9459Szrj    parameter.  */
137*a9fa9459Szrj bfd_boolean S3Forced = FALSE;
138*a9fa9459Szrj 
139*a9fa9459Szrj /* When writing an S-record file, the S-records can not be output as
140*a9fa9459Szrj    they are seen.  This structure is used to hold them in memory.  */
141*a9fa9459Szrj 
142*a9fa9459Szrj struct srec_data_list_struct
143*a9fa9459Szrj {
144*a9fa9459Szrj   struct srec_data_list_struct *next;
145*a9fa9459Szrj   bfd_byte *data;
146*a9fa9459Szrj   bfd_vma where;
147*a9fa9459Szrj   bfd_size_type size;
148*a9fa9459Szrj };
149*a9fa9459Szrj 
150*a9fa9459Szrj typedef struct srec_data_list_struct srec_data_list_type;
151*a9fa9459Szrj 
152*a9fa9459Szrj /* When scanning the S-record file, a linked list of srec_symbol
153*a9fa9459Szrj    structures is built to represent the symbol table (if there is
154*a9fa9459Szrj    one).  */
155*a9fa9459Szrj 
156*a9fa9459Szrj struct srec_symbol
157*a9fa9459Szrj {
158*a9fa9459Szrj   struct srec_symbol *next;
159*a9fa9459Szrj   const char *name;
160*a9fa9459Szrj   bfd_vma val;
161*a9fa9459Szrj };
162*a9fa9459Szrj 
163*a9fa9459Szrj /* The S-record tdata information.  */
164*a9fa9459Szrj 
165*a9fa9459Szrj typedef struct srec_data_struct
166*a9fa9459Szrj   {
167*a9fa9459Szrj     srec_data_list_type *head;
168*a9fa9459Szrj     srec_data_list_type *tail;
169*a9fa9459Szrj     unsigned int type;
170*a9fa9459Szrj     struct srec_symbol *symbols;
171*a9fa9459Szrj     struct srec_symbol *symtail;
172*a9fa9459Szrj     asymbol *csymbols;
173*a9fa9459Szrj   }
174*a9fa9459Szrj tdata_type;
175*a9fa9459Szrj 
176*a9fa9459Szrj /* Initialize by filling in the hex conversion array.  */
177*a9fa9459Szrj 
178*a9fa9459Szrj static void
srec_init(void)179*a9fa9459Szrj srec_init (void)
180*a9fa9459Szrj {
181*a9fa9459Szrj   static bfd_boolean inited = FALSE;
182*a9fa9459Szrj 
183*a9fa9459Szrj   if (! inited)
184*a9fa9459Szrj     {
185*a9fa9459Szrj       inited = TRUE;
186*a9fa9459Szrj       hex_init ();
187*a9fa9459Szrj     }
188*a9fa9459Szrj }
189*a9fa9459Szrj 
190*a9fa9459Szrj /* Set up the S-record tdata information.  */
191*a9fa9459Szrj 
192*a9fa9459Szrj static bfd_boolean
srec_mkobject(bfd * abfd)193*a9fa9459Szrj srec_mkobject (bfd *abfd)
194*a9fa9459Szrj {
195*a9fa9459Szrj   tdata_type *tdata;
196*a9fa9459Szrj 
197*a9fa9459Szrj   srec_init ();
198*a9fa9459Szrj 
199*a9fa9459Szrj   tdata = (tdata_type *) bfd_alloc (abfd, sizeof (tdata_type));
200*a9fa9459Szrj   if (tdata == NULL)
201*a9fa9459Szrj     return FALSE;
202*a9fa9459Szrj 
203*a9fa9459Szrj   abfd->tdata.srec_data = tdata;
204*a9fa9459Szrj   tdata->type = 1;
205*a9fa9459Szrj   tdata->head = NULL;
206*a9fa9459Szrj   tdata->tail = NULL;
207*a9fa9459Szrj   tdata->symbols = NULL;
208*a9fa9459Szrj   tdata->symtail = NULL;
209*a9fa9459Szrj   tdata->csymbols = NULL;
210*a9fa9459Szrj 
211*a9fa9459Szrj   return TRUE;
212*a9fa9459Szrj }
213*a9fa9459Szrj 
214*a9fa9459Szrj /* Read a byte from an S record file.  Set *ERRORPTR if an error
215*a9fa9459Szrj    occurred.  Return EOF on error or end of file.  */
216*a9fa9459Szrj 
217*a9fa9459Szrj static int
srec_get_byte(bfd * abfd,bfd_boolean * errorptr)218*a9fa9459Szrj srec_get_byte (bfd *abfd, bfd_boolean *errorptr)
219*a9fa9459Szrj {
220*a9fa9459Szrj   bfd_byte c;
221*a9fa9459Szrj 
222*a9fa9459Szrj   if (bfd_bread (&c, (bfd_size_type) 1, abfd) != 1)
223*a9fa9459Szrj     {
224*a9fa9459Szrj       if (bfd_get_error () != bfd_error_file_truncated)
225*a9fa9459Szrj 	*errorptr = TRUE;
226*a9fa9459Szrj       return EOF;
227*a9fa9459Szrj     }
228*a9fa9459Szrj 
229*a9fa9459Szrj   return (int) (c & 0xff);
230*a9fa9459Szrj }
231*a9fa9459Szrj 
232*a9fa9459Szrj /* Report a problem in an S record file.  FIXME: This probably should
233*a9fa9459Szrj    not call fprintf, but we really do need some mechanism for printing
234*a9fa9459Szrj    error messages.  */
235*a9fa9459Szrj 
236*a9fa9459Szrj static void
srec_bad_byte(bfd * abfd,unsigned int lineno,int c,bfd_boolean error)237*a9fa9459Szrj srec_bad_byte (bfd *abfd,
238*a9fa9459Szrj 	       unsigned int lineno,
239*a9fa9459Szrj 	       int c,
240*a9fa9459Szrj 	       bfd_boolean error)
241*a9fa9459Szrj {
242*a9fa9459Szrj   if (c == EOF)
243*a9fa9459Szrj     {
244*a9fa9459Szrj       if (! error)
245*a9fa9459Szrj 	bfd_set_error (bfd_error_file_truncated);
246*a9fa9459Szrj     }
247*a9fa9459Szrj   else
248*a9fa9459Szrj     {
249*a9fa9459Szrj       char buf[40];
250*a9fa9459Szrj 
251*a9fa9459Szrj       if (! ISPRINT (c))
252*a9fa9459Szrj 	sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
253*a9fa9459Szrj       else
254*a9fa9459Szrj 	{
255*a9fa9459Szrj 	  buf[0] = c;
256*a9fa9459Szrj 	  buf[1] = '\0';
257*a9fa9459Szrj 	}
258*a9fa9459Szrj       (*_bfd_error_handler)
259*a9fa9459Szrj 	(_("%B:%d: Unexpected character `%s' in S-record file\n"),
260*a9fa9459Szrj 	 abfd, lineno, buf);
261*a9fa9459Szrj       bfd_set_error (bfd_error_bad_value);
262*a9fa9459Szrj     }
263*a9fa9459Szrj }
264*a9fa9459Szrj 
265*a9fa9459Szrj /* Add a new symbol found in an S-record file.  */
266*a9fa9459Szrj 
267*a9fa9459Szrj static bfd_boolean
srec_new_symbol(bfd * abfd,const char * name,bfd_vma val)268*a9fa9459Szrj srec_new_symbol (bfd *abfd, const char *name, bfd_vma val)
269*a9fa9459Szrj {
270*a9fa9459Szrj   struct srec_symbol *n;
271*a9fa9459Szrj 
272*a9fa9459Szrj   n = (struct srec_symbol *) bfd_alloc (abfd, sizeof (* n));
273*a9fa9459Szrj   if (n == NULL)
274*a9fa9459Szrj     return FALSE;
275*a9fa9459Szrj 
276*a9fa9459Szrj   n->name = name;
277*a9fa9459Szrj   n->val = val;
278*a9fa9459Szrj 
279*a9fa9459Szrj   if (abfd->tdata.srec_data->symbols == NULL)
280*a9fa9459Szrj     abfd->tdata.srec_data->symbols = n;
281*a9fa9459Szrj   else
282*a9fa9459Szrj     abfd->tdata.srec_data->symtail->next = n;
283*a9fa9459Szrj   abfd->tdata.srec_data->symtail = n;
284*a9fa9459Szrj   n->next = NULL;
285*a9fa9459Szrj 
286*a9fa9459Szrj   ++abfd->symcount;
287*a9fa9459Szrj 
288*a9fa9459Szrj   return TRUE;
289*a9fa9459Szrj }
290*a9fa9459Szrj 
291*a9fa9459Szrj /* Read the S record file and turn it into sections.  We create a new
292*a9fa9459Szrj    section for each contiguous set of bytes.  */
293*a9fa9459Szrj 
294*a9fa9459Szrj static bfd_boolean
srec_scan(bfd * abfd)295*a9fa9459Szrj srec_scan (bfd *abfd)
296*a9fa9459Szrj {
297*a9fa9459Szrj   int c;
298*a9fa9459Szrj   unsigned int lineno = 1;
299*a9fa9459Szrj   bfd_boolean error = FALSE;
300*a9fa9459Szrj   bfd_byte *buf = NULL;
301*a9fa9459Szrj   size_t bufsize = 0;
302*a9fa9459Szrj   asection *sec = NULL;
303*a9fa9459Szrj   char *symbuf = NULL;
304*a9fa9459Szrj 
305*a9fa9459Szrj   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
306*a9fa9459Szrj     goto error_return;
307*a9fa9459Szrj 
308*a9fa9459Szrj   while ((c = srec_get_byte (abfd, &error)) != EOF)
309*a9fa9459Szrj     {
310*a9fa9459Szrj       /* We only build sections from contiguous S-records, so if this
311*a9fa9459Szrj 	 is not an S-record, then stop building a section.  */
312*a9fa9459Szrj       if (c != 'S' && c != '\r' && c != '\n')
313*a9fa9459Szrj 	sec = NULL;
314*a9fa9459Szrj 
315*a9fa9459Szrj       switch (c)
316*a9fa9459Szrj 	{
317*a9fa9459Szrj 	default:
318*a9fa9459Szrj 	  srec_bad_byte (abfd, lineno, c, error);
319*a9fa9459Szrj 	  goto error_return;
320*a9fa9459Szrj 
321*a9fa9459Szrj 	case '\n':
322*a9fa9459Szrj 	  ++lineno;
323*a9fa9459Szrj 	  break;
324*a9fa9459Szrj 
325*a9fa9459Szrj 	case '\r':
326*a9fa9459Szrj 	  break;
327*a9fa9459Szrj 
328*a9fa9459Szrj 	case '$':
329*a9fa9459Szrj 	  /* Starting a module name, which we ignore.  */
330*a9fa9459Szrj 	  while ((c = srec_get_byte (abfd, &error)) != '\n'
331*a9fa9459Szrj 		 && c != EOF)
332*a9fa9459Szrj 	    ;
333*a9fa9459Szrj 	  if (c == EOF)
334*a9fa9459Szrj 	    {
335*a9fa9459Szrj 	      srec_bad_byte (abfd, lineno, c, error);
336*a9fa9459Szrj 	      goto error_return;
337*a9fa9459Szrj 	    }
338*a9fa9459Szrj 
339*a9fa9459Szrj 	  ++lineno;
340*a9fa9459Szrj 	  break;
341*a9fa9459Szrj 
342*a9fa9459Szrj 	case ' ':
343*a9fa9459Szrj 	  do
344*a9fa9459Szrj 	    {
345*a9fa9459Szrj 	      bfd_size_type alc;
346*a9fa9459Szrj 	      char *p, *symname;
347*a9fa9459Szrj 	      bfd_vma symval;
348*a9fa9459Szrj 
349*a9fa9459Szrj 	      /* Starting a symbol definition.  */
350*a9fa9459Szrj 	      while ((c = srec_get_byte (abfd, &error)) != EOF
351*a9fa9459Szrj 		     && (c == ' ' || c == '\t'))
352*a9fa9459Szrj 		;
353*a9fa9459Szrj 
354*a9fa9459Szrj 	      if (c == '\n' || c == '\r')
355*a9fa9459Szrj 		break;
356*a9fa9459Szrj 
357*a9fa9459Szrj 	      if (c == EOF)
358*a9fa9459Szrj 		{
359*a9fa9459Szrj 		  srec_bad_byte (abfd, lineno, c, error);
360*a9fa9459Szrj 		  goto error_return;
361*a9fa9459Szrj 		}
362*a9fa9459Szrj 
363*a9fa9459Szrj 	      alc = 10;
364*a9fa9459Szrj 	      symbuf = (char *) bfd_malloc (alc + 1);
365*a9fa9459Szrj 	      if (symbuf == NULL)
366*a9fa9459Szrj 		goto error_return;
367*a9fa9459Szrj 
368*a9fa9459Szrj 	      p = symbuf;
369*a9fa9459Szrj 
370*a9fa9459Szrj 	      *p++ = c;
371*a9fa9459Szrj 	      while ((c = srec_get_byte (abfd, &error)) != EOF
372*a9fa9459Szrj 		     && ! ISSPACE (c))
373*a9fa9459Szrj 		{
374*a9fa9459Szrj 		  if ((bfd_size_type) (p - symbuf) >= alc)
375*a9fa9459Szrj 		    {
376*a9fa9459Szrj 		      char *n;
377*a9fa9459Szrj 
378*a9fa9459Szrj 		      alc *= 2;
379*a9fa9459Szrj 		      n = (char *) bfd_realloc (symbuf, alc + 1);
380*a9fa9459Szrj 		      if (n == NULL)
381*a9fa9459Szrj 			goto error_return;
382*a9fa9459Szrj 		      p = n + (p - symbuf);
383*a9fa9459Szrj 		      symbuf = n;
384*a9fa9459Szrj 		    }
385*a9fa9459Szrj 
386*a9fa9459Szrj 		  *p++ = c;
387*a9fa9459Szrj 		}
388*a9fa9459Szrj 
389*a9fa9459Szrj 	      if (c == EOF)
390*a9fa9459Szrj 		{
391*a9fa9459Szrj 		  srec_bad_byte (abfd, lineno, c, error);
392*a9fa9459Szrj 		  goto error_return;
393*a9fa9459Szrj 		}
394*a9fa9459Szrj 
395*a9fa9459Szrj 	      *p++ = '\0';
396*a9fa9459Szrj 	      symname = (char *) bfd_alloc (abfd, (bfd_size_type) (p - symbuf));
397*a9fa9459Szrj 	      if (symname == NULL)
398*a9fa9459Szrj 		goto error_return;
399*a9fa9459Szrj 	      strcpy (symname, symbuf);
400*a9fa9459Szrj 	      free (symbuf);
401*a9fa9459Szrj 	      symbuf = NULL;
402*a9fa9459Szrj 
403*a9fa9459Szrj 	      while ((c = srec_get_byte (abfd, &error)) != EOF
404*a9fa9459Szrj 		     && (c == ' ' || c == '\t'))
405*a9fa9459Szrj 		;
406*a9fa9459Szrj 	      if (c == EOF)
407*a9fa9459Szrj 		{
408*a9fa9459Szrj 		  srec_bad_byte (abfd, lineno, c, error);
409*a9fa9459Szrj 		  goto error_return;
410*a9fa9459Szrj 		}
411*a9fa9459Szrj 
412*a9fa9459Szrj 	      /* Skip a dollar sign before the hex value.  */
413*a9fa9459Szrj 	      if (c == '$')
414*a9fa9459Szrj 		{
415*a9fa9459Szrj 		  c = srec_get_byte (abfd, &error);
416*a9fa9459Szrj 		  if (c == EOF)
417*a9fa9459Szrj 		    {
418*a9fa9459Szrj 		      srec_bad_byte (abfd, lineno, c, error);
419*a9fa9459Szrj 		      goto error_return;
420*a9fa9459Szrj 		    }
421*a9fa9459Szrj 		}
422*a9fa9459Szrj 
423*a9fa9459Szrj 	      symval = 0;
424*a9fa9459Szrj 	      while (ISHEX (c))
425*a9fa9459Szrj 		{
426*a9fa9459Szrj 		  symval <<= 4;
427*a9fa9459Szrj 		  symval += NIBBLE (c);
428*a9fa9459Szrj 		  c = srec_get_byte (abfd, &error);
429*a9fa9459Szrj 		  if (c == EOF)
430*a9fa9459Szrj 		    {
431*a9fa9459Szrj 		      srec_bad_byte (abfd, lineno, c, error);
432*a9fa9459Szrj 		      goto error_return;
433*a9fa9459Szrj 		    }
434*a9fa9459Szrj 		}
435*a9fa9459Szrj 
436*a9fa9459Szrj 	      if (! srec_new_symbol (abfd, symname, symval))
437*a9fa9459Szrj 		goto error_return;
438*a9fa9459Szrj 	    }
439*a9fa9459Szrj 	  while (c == ' ' || c == '\t')
440*a9fa9459Szrj 	    ;
441*a9fa9459Szrj 
442*a9fa9459Szrj 	  if (c == '\n')
443*a9fa9459Szrj 	    ++lineno;
444*a9fa9459Szrj 	  else if (c != '\r')
445*a9fa9459Szrj 	    {
446*a9fa9459Szrj 	      srec_bad_byte (abfd, lineno, c, error);
447*a9fa9459Szrj 	      goto error_return;
448*a9fa9459Szrj 	    }
449*a9fa9459Szrj 
450*a9fa9459Szrj 	  break;
451*a9fa9459Szrj 
452*a9fa9459Szrj 	case 'S':
453*a9fa9459Szrj 	  {
454*a9fa9459Szrj 	    file_ptr pos;
455*a9fa9459Szrj 	    unsigned char hdr[3];
456*a9fa9459Szrj 	    unsigned int bytes, min_bytes;
457*a9fa9459Szrj 	    bfd_vma address;
458*a9fa9459Szrj 	    bfd_byte *data;
459*a9fa9459Szrj 	    unsigned char check_sum;
460*a9fa9459Szrj 
461*a9fa9459Szrj 	    /* Starting an S-record.  */
462*a9fa9459Szrj 
463*a9fa9459Szrj 	    pos = bfd_tell (abfd) - 1;
464*a9fa9459Szrj 
465*a9fa9459Szrj 	    if (bfd_bread (hdr, (bfd_size_type) 3, abfd) != 3)
466*a9fa9459Szrj 	      goto error_return;
467*a9fa9459Szrj 
468*a9fa9459Szrj 	    if (! ISHEX (hdr[1]) || ! ISHEX (hdr[2]))
469*a9fa9459Szrj 	      {
470*a9fa9459Szrj 		if (! ISHEX (hdr[1]))
471*a9fa9459Szrj 		  c = hdr[1];
472*a9fa9459Szrj 		else
473*a9fa9459Szrj 		  c = hdr[2];
474*a9fa9459Szrj 		srec_bad_byte (abfd, lineno, c, error);
475*a9fa9459Szrj 		goto error_return;
476*a9fa9459Szrj 	      }
477*a9fa9459Szrj 
478*a9fa9459Szrj 	    check_sum = bytes = HEX (hdr + 1);
479*a9fa9459Szrj 	    min_bytes = 3;
480*a9fa9459Szrj 	    if (hdr[0] == '2' || hdr[0] == '8')
481*a9fa9459Szrj 	      min_bytes = 4;
482*a9fa9459Szrj 	    else if (hdr[0] == '3' || hdr[0] == '7')
483*a9fa9459Szrj 	      min_bytes = 5;
484*a9fa9459Szrj 	    if (bytes < min_bytes)
485*a9fa9459Szrj 	      {
486*a9fa9459Szrj 		(*_bfd_error_handler) (_("%B:%d: byte count %d too small\n"),
487*a9fa9459Szrj 				       abfd, lineno, bytes);
488*a9fa9459Szrj 		bfd_set_error (bfd_error_bad_value);
489*a9fa9459Szrj 		goto error_return;
490*a9fa9459Szrj 	      }
491*a9fa9459Szrj 
492*a9fa9459Szrj 	    if (bytes * 2 > bufsize)
493*a9fa9459Szrj 	      {
494*a9fa9459Szrj 		if (buf != NULL)
495*a9fa9459Szrj 		  free (buf);
496*a9fa9459Szrj 		buf = (bfd_byte *) bfd_malloc ((bfd_size_type) bytes * 2);
497*a9fa9459Szrj 		if (buf == NULL)
498*a9fa9459Szrj 		  goto error_return;
499*a9fa9459Szrj 		bufsize = bytes * 2;
500*a9fa9459Szrj 	      }
501*a9fa9459Szrj 
502*a9fa9459Szrj 	    if (bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
503*a9fa9459Szrj 	      goto error_return;
504*a9fa9459Szrj 
505*a9fa9459Szrj 	    /* Ignore the checksum byte.  */
506*a9fa9459Szrj 	    --bytes;
507*a9fa9459Szrj 
508*a9fa9459Szrj 	    address = 0;
509*a9fa9459Szrj 	    data = buf;
510*a9fa9459Szrj 	    switch (hdr[0])
511*a9fa9459Szrj 	      {
512*a9fa9459Szrj 	      case '0':
513*a9fa9459Szrj 	      case '5':
514*a9fa9459Szrj 		/* Prologue--ignore the file name, but stop building a
515*a9fa9459Szrj 		   section at this point.  */
516*a9fa9459Szrj 		sec = NULL;
517*a9fa9459Szrj 		break;
518*a9fa9459Szrj 
519*a9fa9459Szrj 	      case '3':
520*a9fa9459Szrj 		check_sum += HEX (data);
521*a9fa9459Szrj 		address = HEX (data);
522*a9fa9459Szrj 		data += 2;
523*a9fa9459Szrj 		--bytes;
524*a9fa9459Szrj 		/* Fall through.  */
525*a9fa9459Szrj 	      case '2':
526*a9fa9459Szrj 		check_sum += HEX (data);
527*a9fa9459Szrj 		address = (address << 8) | HEX (data);
528*a9fa9459Szrj 		data += 2;
529*a9fa9459Szrj 		--bytes;
530*a9fa9459Szrj 		/* Fall through.  */
531*a9fa9459Szrj 	      case '1':
532*a9fa9459Szrj 		check_sum += HEX (data);
533*a9fa9459Szrj 		address = (address << 8) | HEX (data);
534*a9fa9459Szrj 		data += 2;
535*a9fa9459Szrj 		check_sum += HEX (data);
536*a9fa9459Szrj 		address = (address << 8) | HEX (data);
537*a9fa9459Szrj 		data += 2;
538*a9fa9459Szrj 		bytes -= 2;
539*a9fa9459Szrj 
540*a9fa9459Szrj 		if (sec != NULL
541*a9fa9459Szrj 		    && sec->vma + sec->size == address)
542*a9fa9459Szrj 		  {
543*a9fa9459Szrj 		    /* This data goes at the end of the section we are
544*a9fa9459Szrj 		       currently building.  */
545*a9fa9459Szrj 		    sec->size += bytes;
546*a9fa9459Szrj 		  }
547*a9fa9459Szrj 		else
548*a9fa9459Szrj 		  {
549*a9fa9459Szrj 		    char secbuf[20];
550*a9fa9459Szrj 		    char *secname;
551*a9fa9459Szrj 		    bfd_size_type amt;
552*a9fa9459Szrj 		    flagword flags;
553*a9fa9459Szrj 
554*a9fa9459Szrj 		    sprintf (secbuf, ".sec%d", bfd_count_sections (abfd) + 1);
555*a9fa9459Szrj 		    amt = strlen (secbuf) + 1;
556*a9fa9459Szrj 		    secname = (char *) bfd_alloc (abfd, amt);
557*a9fa9459Szrj 		    strcpy (secname, secbuf);
558*a9fa9459Szrj 		    flags = SEC_HAS_CONTENTS | SEC_LOAD | SEC_ALLOC;
559*a9fa9459Szrj 		    sec = bfd_make_section_with_flags (abfd, secname, flags);
560*a9fa9459Szrj 		    if (sec == NULL)
561*a9fa9459Szrj 		      goto error_return;
562*a9fa9459Szrj 		    sec->vma = address;
563*a9fa9459Szrj 		    sec->lma = address;
564*a9fa9459Szrj 		    sec->size = bytes;
565*a9fa9459Szrj 		    sec->filepos = pos;
566*a9fa9459Szrj 		  }
567*a9fa9459Szrj 
568*a9fa9459Szrj 		while (bytes > 0)
569*a9fa9459Szrj 		  {
570*a9fa9459Szrj 		    check_sum += HEX (data);
571*a9fa9459Szrj 		    data += 2;
572*a9fa9459Szrj 		    bytes--;
573*a9fa9459Szrj 		  }
574*a9fa9459Szrj 		check_sum = 255 - (check_sum & 0xff);
575*a9fa9459Szrj 		if (check_sum != HEX (data))
576*a9fa9459Szrj 		  {
577*a9fa9459Szrj 		    (*_bfd_error_handler)
578*a9fa9459Szrj 		      (_("%B:%d: Bad checksum in S-record file\n"),
579*a9fa9459Szrj 		       abfd, lineno);
580*a9fa9459Szrj 		    bfd_set_error (bfd_error_bad_value);
581*a9fa9459Szrj 		    goto error_return;
582*a9fa9459Szrj 		  }
583*a9fa9459Szrj 
584*a9fa9459Szrj 		break;
585*a9fa9459Szrj 
586*a9fa9459Szrj 	      case '7':
587*a9fa9459Szrj 		check_sum += HEX (data);
588*a9fa9459Szrj 		address = HEX (data);
589*a9fa9459Szrj 		data += 2;
590*a9fa9459Szrj 		/* Fall through.  */
591*a9fa9459Szrj 	      case '8':
592*a9fa9459Szrj 		check_sum += HEX (data);
593*a9fa9459Szrj 		address = (address << 8) | HEX (data);
594*a9fa9459Szrj 		data += 2;
595*a9fa9459Szrj 		/* Fall through.  */
596*a9fa9459Szrj 	      case '9':
597*a9fa9459Szrj 		check_sum += HEX (data);
598*a9fa9459Szrj 		address = (address << 8) | HEX (data);
599*a9fa9459Szrj 		data += 2;
600*a9fa9459Szrj 		check_sum += HEX (data);
601*a9fa9459Szrj 		address = (address << 8) | HEX (data);
602*a9fa9459Szrj 		data += 2;
603*a9fa9459Szrj 
604*a9fa9459Szrj 		/* This is a termination record.  */
605*a9fa9459Szrj 		abfd->start_address = address;
606*a9fa9459Szrj 
607*a9fa9459Szrj 		check_sum = 255 - (check_sum & 0xff);
608*a9fa9459Szrj 		if (check_sum != HEX (data))
609*a9fa9459Szrj 		  {
610*a9fa9459Szrj 		    (*_bfd_error_handler)
611*a9fa9459Szrj 		      (_("%B:%d: Bad checksum in S-record file\n"),
612*a9fa9459Szrj 		       abfd, lineno);
613*a9fa9459Szrj 		    bfd_set_error (bfd_error_bad_value);
614*a9fa9459Szrj 		    goto error_return;
615*a9fa9459Szrj 		  }
616*a9fa9459Szrj 
617*a9fa9459Szrj 		if (buf != NULL)
618*a9fa9459Szrj 		  free (buf);
619*a9fa9459Szrj 
620*a9fa9459Szrj 		return TRUE;
621*a9fa9459Szrj 	      }
622*a9fa9459Szrj 	  }
623*a9fa9459Szrj 	  break;
624*a9fa9459Szrj 	}
625*a9fa9459Szrj     }
626*a9fa9459Szrj 
627*a9fa9459Szrj   if (error)
628*a9fa9459Szrj     goto error_return;
629*a9fa9459Szrj 
630*a9fa9459Szrj   if (buf != NULL)
631*a9fa9459Szrj     free (buf);
632*a9fa9459Szrj 
633*a9fa9459Szrj   return TRUE;
634*a9fa9459Szrj 
635*a9fa9459Szrj  error_return:
636*a9fa9459Szrj   if (symbuf != NULL)
637*a9fa9459Szrj     free (symbuf);
638*a9fa9459Szrj   if (buf != NULL)
639*a9fa9459Szrj     free (buf);
640*a9fa9459Szrj   return FALSE;
641*a9fa9459Szrj }
642*a9fa9459Szrj 
643*a9fa9459Szrj /* Check whether an existing file is an S-record file.  */
644*a9fa9459Szrj 
645*a9fa9459Szrj static const bfd_target *
srec_object_p(bfd * abfd)646*a9fa9459Szrj srec_object_p (bfd *abfd)
647*a9fa9459Szrj {
648*a9fa9459Szrj   void * tdata_save;
649*a9fa9459Szrj   bfd_byte b[4];
650*a9fa9459Szrj 
651*a9fa9459Szrj   srec_init ();
652*a9fa9459Szrj 
653*a9fa9459Szrj   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
654*a9fa9459Szrj       || bfd_bread (b, (bfd_size_type) 4, abfd) != 4)
655*a9fa9459Szrj     return NULL;
656*a9fa9459Szrj 
657*a9fa9459Szrj   if (b[0] != 'S' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
658*a9fa9459Szrj     {
659*a9fa9459Szrj       bfd_set_error (bfd_error_wrong_format);
660*a9fa9459Szrj       return NULL;
661*a9fa9459Szrj     }
662*a9fa9459Szrj 
663*a9fa9459Szrj   tdata_save = abfd->tdata.any;
664*a9fa9459Szrj   if (! srec_mkobject (abfd) || ! srec_scan (abfd))
665*a9fa9459Szrj     {
666*a9fa9459Szrj       if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
667*a9fa9459Szrj 	bfd_release (abfd, abfd->tdata.any);
668*a9fa9459Szrj       abfd->tdata.any = tdata_save;
669*a9fa9459Szrj       return NULL;
670*a9fa9459Szrj     }
671*a9fa9459Szrj 
672*a9fa9459Szrj   if (abfd->symcount > 0)
673*a9fa9459Szrj     abfd->flags |= HAS_SYMS;
674*a9fa9459Szrj 
675*a9fa9459Szrj   return abfd->xvec;
676*a9fa9459Szrj }
677*a9fa9459Szrj 
678*a9fa9459Szrj /* Check whether an existing file is an S-record file with symbols.  */
679*a9fa9459Szrj 
680*a9fa9459Szrj static const bfd_target *
symbolsrec_object_p(bfd * abfd)681*a9fa9459Szrj symbolsrec_object_p (bfd *abfd)
682*a9fa9459Szrj {
683*a9fa9459Szrj   void * tdata_save;
684*a9fa9459Szrj   char b[2];
685*a9fa9459Szrj 
686*a9fa9459Szrj   srec_init ();
687*a9fa9459Szrj 
688*a9fa9459Szrj   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
689*a9fa9459Szrj       || bfd_bread (b, (bfd_size_type) 2, abfd) != 2)
690*a9fa9459Szrj     return NULL;
691*a9fa9459Szrj 
692*a9fa9459Szrj   if (b[0] != '$' || b[1] != '$')
693*a9fa9459Szrj     {
694*a9fa9459Szrj       bfd_set_error (bfd_error_wrong_format);
695*a9fa9459Szrj       return NULL;
696*a9fa9459Szrj     }
697*a9fa9459Szrj 
698*a9fa9459Szrj   tdata_save = abfd->tdata.any;
699*a9fa9459Szrj   if (! srec_mkobject (abfd) || ! srec_scan (abfd))
700*a9fa9459Szrj     {
701*a9fa9459Szrj       if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
702*a9fa9459Szrj 	bfd_release (abfd, abfd->tdata.any);
703*a9fa9459Szrj       abfd->tdata.any = tdata_save;
704*a9fa9459Szrj       return NULL;
705*a9fa9459Szrj     }
706*a9fa9459Szrj 
707*a9fa9459Szrj   if (abfd->symcount > 0)
708*a9fa9459Szrj     abfd->flags |= HAS_SYMS;
709*a9fa9459Szrj 
710*a9fa9459Szrj   return abfd->xvec;
711*a9fa9459Szrj }
712*a9fa9459Szrj 
713*a9fa9459Szrj /* Read in the contents of a section in an S-record file.  */
714*a9fa9459Szrj 
715*a9fa9459Szrj static bfd_boolean
srec_read_section(bfd * abfd,asection * section,bfd_byte * contents)716*a9fa9459Szrj srec_read_section (bfd *abfd, asection *section, bfd_byte *contents)
717*a9fa9459Szrj {
718*a9fa9459Szrj   int c;
719*a9fa9459Szrj   bfd_size_type sofar = 0;
720*a9fa9459Szrj   bfd_boolean error = FALSE;
721*a9fa9459Szrj   bfd_byte *buf = NULL;
722*a9fa9459Szrj   size_t bufsize = 0;
723*a9fa9459Szrj 
724*a9fa9459Szrj   if (bfd_seek (abfd, section->filepos, SEEK_SET) != 0)
725*a9fa9459Szrj     goto error_return;
726*a9fa9459Szrj 
727*a9fa9459Szrj   while ((c = srec_get_byte (abfd, &error)) != EOF)
728*a9fa9459Szrj     {
729*a9fa9459Szrj       bfd_byte hdr[3];
730*a9fa9459Szrj       unsigned int bytes;
731*a9fa9459Szrj       bfd_vma address;
732*a9fa9459Szrj       bfd_byte *data;
733*a9fa9459Szrj 
734*a9fa9459Szrj       if (c == '\r' || c == '\n')
735*a9fa9459Szrj 	continue;
736*a9fa9459Szrj 
737*a9fa9459Szrj       /* This is called after srec_scan has already been called, so we
738*a9fa9459Szrj 	 ought to know the exact format.  */
739*a9fa9459Szrj       BFD_ASSERT (c == 'S');
740*a9fa9459Szrj 
741*a9fa9459Szrj       if (bfd_bread (hdr, (bfd_size_type) 3, abfd) != 3)
742*a9fa9459Szrj 	goto error_return;
743*a9fa9459Szrj 
744*a9fa9459Szrj       BFD_ASSERT (ISHEX (hdr[1]) && ISHEX (hdr[2]));
745*a9fa9459Szrj 
746*a9fa9459Szrj       bytes = HEX (hdr + 1);
747*a9fa9459Szrj 
748*a9fa9459Szrj       if (bytes * 2 > bufsize)
749*a9fa9459Szrj 	{
750*a9fa9459Szrj 	  if (buf != NULL)
751*a9fa9459Szrj 	    free (buf);
752*a9fa9459Szrj 	  buf = (bfd_byte *) bfd_malloc ((bfd_size_type) bytes * 2);
753*a9fa9459Szrj 	  if (buf == NULL)
754*a9fa9459Szrj 	    goto error_return;
755*a9fa9459Szrj 	  bufsize = bytes * 2;
756*a9fa9459Szrj 	}
757*a9fa9459Szrj 
758*a9fa9459Szrj       if (bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
759*a9fa9459Szrj 	goto error_return;
760*a9fa9459Szrj 
761*a9fa9459Szrj       address = 0;
762*a9fa9459Szrj       data = buf;
763*a9fa9459Szrj       switch (hdr[0])
764*a9fa9459Szrj 	{
765*a9fa9459Szrj 	default:
766*a9fa9459Szrj 	  BFD_ASSERT (sofar == section->size);
767*a9fa9459Szrj 	  if (buf != NULL)
768*a9fa9459Szrj 	    free (buf);
769*a9fa9459Szrj 	  return TRUE;
770*a9fa9459Szrj 
771*a9fa9459Szrj 	case '3':
772*a9fa9459Szrj 	  address = HEX (data);
773*a9fa9459Szrj 	  data += 2;
774*a9fa9459Szrj 	  --bytes;
775*a9fa9459Szrj 	  /* Fall through.  */
776*a9fa9459Szrj 	case '2':
777*a9fa9459Szrj 	  address = (address << 8) | HEX (data);
778*a9fa9459Szrj 	  data += 2;
779*a9fa9459Szrj 	  --bytes;
780*a9fa9459Szrj 	  /* Fall through.  */
781*a9fa9459Szrj 	case '1':
782*a9fa9459Szrj 	  address = (address << 8) | HEX (data);
783*a9fa9459Szrj 	  data += 2;
784*a9fa9459Szrj 	  address = (address << 8) | HEX (data);
785*a9fa9459Szrj 	  data += 2;
786*a9fa9459Szrj 	  bytes -= 2;
787*a9fa9459Szrj 
788*a9fa9459Szrj 	  if (address != section->vma + sofar)
789*a9fa9459Szrj 	    {
790*a9fa9459Szrj 	      /* We've come to the end of this section.  */
791*a9fa9459Szrj 	      BFD_ASSERT (sofar == section->size);
792*a9fa9459Szrj 	      if (buf != NULL)
793*a9fa9459Szrj 		free (buf);
794*a9fa9459Szrj 	      return TRUE;
795*a9fa9459Szrj 	    }
796*a9fa9459Szrj 
797*a9fa9459Szrj 	  /* Don't consider checksum.  */
798*a9fa9459Szrj 	  --bytes;
799*a9fa9459Szrj 
800*a9fa9459Szrj 	  while (bytes-- != 0)
801*a9fa9459Szrj 	    {
802*a9fa9459Szrj 	      contents[sofar] = HEX (data);
803*a9fa9459Szrj 	      data += 2;
804*a9fa9459Szrj 	      ++sofar;
805*a9fa9459Szrj 	    }
806*a9fa9459Szrj 
807*a9fa9459Szrj 	  break;
808*a9fa9459Szrj 	}
809*a9fa9459Szrj     }
810*a9fa9459Szrj 
811*a9fa9459Szrj   if (error)
812*a9fa9459Szrj     goto error_return;
813*a9fa9459Szrj 
814*a9fa9459Szrj   BFD_ASSERT (sofar == section->size);
815*a9fa9459Szrj 
816*a9fa9459Szrj   if (buf != NULL)
817*a9fa9459Szrj     free (buf);
818*a9fa9459Szrj 
819*a9fa9459Szrj   return TRUE;
820*a9fa9459Szrj 
821*a9fa9459Szrj  error_return:
822*a9fa9459Szrj   if (buf != NULL)
823*a9fa9459Szrj     free (buf);
824*a9fa9459Szrj   return FALSE;
825*a9fa9459Szrj }
826*a9fa9459Szrj 
827*a9fa9459Szrj /* Get the contents of a section in an S-record file.  */
828*a9fa9459Szrj 
829*a9fa9459Szrj static bfd_boolean
srec_get_section_contents(bfd * abfd,asection * section,void * location,file_ptr offset,bfd_size_type count)830*a9fa9459Szrj srec_get_section_contents (bfd *abfd,
831*a9fa9459Szrj 			   asection *section,
832*a9fa9459Szrj 			   void * location,
833*a9fa9459Szrj 			   file_ptr offset,
834*a9fa9459Szrj 			   bfd_size_type count)
835*a9fa9459Szrj {
836*a9fa9459Szrj   if (count == 0)
837*a9fa9459Szrj     return TRUE;
838*a9fa9459Szrj 
839*a9fa9459Szrj   if (offset + count < count
840*a9fa9459Szrj       || offset + count > section->size)
841*a9fa9459Szrj     {
842*a9fa9459Szrj       bfd_set_error (bfd_error_invalid_operation);
843*a9fa9459Szrj       return FALSE;
844*a9fa9459Szrj     }
845*a9fa9459Szrj 
846*a9fa9459Szrj   if (section->used_by_bfd == NULL)
847*a9fa9459Szrj     {
848*a9fa9459Szrj       section->used_by_bfd = bfd_alloc (abfd, section->size);
849*a9fa9459Szrj       if (section->used_by_bfd == NULL)
850*a9fa9459Szrj 	return FALSE;
851*a9fa9459Szrj 
852*a9fa9459Szrj       if (! srec_read_section (abfd, section,
853*a9fa9459Szrj                                (bfd_byte *) section->used_by_bfd))
854*a9fa9459Szrj 	return FALSE;
855*a9fa9459Szrj     }
856*a9fa9459Szrj 
857*a9fa9459Szrj   memcpy (location, (bfd_byte *) section->used_by_bfd + offset,
858*a9fa9459Szrj 	  (size_t) count);
859*a9fa9459Szrj 
860*a9fa9459Szrj   return TRUE;
861*a9fa9459Szrj }
862*a9fa9459Szrj 
863*a9fa9459Szrj /* Set the architecture.  We accept an unknown architecture here.  */
864*a9fa9459Szrj 
865*a9fa9459Szrj static bfd_boolean
srec_set_arch_mach(bfd * abfd,enum bfd_architecture arch,unsigned long mach)866*a9fa9459Szrj srec_set_arch_mach (bfd *abfd, enum bfd_architecture arch, unsigned long mach)
867*a9fa9459Szrj {
868*a9fa9459Szrj   if (arch != bfd_arch_unknown)
869*a9fa9459Szrj     return bfd_default_set_arch_mach (abfd, arch, mach);
870*a9fa9459Szrj 
871*a9fa9459Szrj   abfd->arch_info = & bfd_default_arch_struct;
872*a9fa9459Szrj   return TRUE;
873*a9fa9459Szrj }
874*a9fa9459Szrj 
875*a9fa9459Szrj /* We have to save up all the Srecords for a splurge before output.  */
876*a9fa9459Szrj 
877*a9fa9459Szrj static bfd_boolean
srec_set_section_contents(bfd * abfd,sec_ptr section,const void * location,file_ptr offset,bfd_size_type bytes_to_do)878*a9fa9459Szrj srec_set_section_contents (bfd *abfd,
879*a9fa9459Szrj 			   sec_ptr section,
880*a9fa9459Szrj 			   const void * location,
881*a9fa9459Szrj 			   file_ptr offset,
882*a9fa9459Szrj 			   bfd_size_type bytes_to_do)
883*a9fa9459Szrj {
884*a9fa9459Szrj   int opb = bfd_octets_per_byte (abfd);
885*a9fa9459Szrj   tdata_type *tdata = abfd->tdata.srec_data;
886*a9fa9459Szrj   srec_data_list_type *entry;
887*a9fa9459Szrj 
888*a9fa9459Szrj   entry = (srec_data_list_type *) bfd_alloc (abfd, sizeof (* entry));
889*a9fa9459Szrj   if (entry == NULL)
890*a9fa9459Szrj     return FALSE;
891*a9fa9459Szrj 
892*a9fa9459Szrj   if (bytes_to_do
893*a9fa9459Szrj       && (section->flags & SEC_ALLOC)
894*a9fa9459Szrj       && (section->flags & SEC_LOAD))
895*a9fa9459Szrj     {
896*a9fa9459Szrj       bfd_byte *data;
897*a9fa9459Szrj 
898*a9fa9459Szrj       data = (bfd_byte *) bfd_alloc (abfd, bytes_to_do);
899*a9fa9459Szrj       if (data == NULL)
900*a9fa9459Szrj 	return FALSE;
901*a9fa9459Szrj       memcpy ((void *) data, location, (size_t) bytes_to_do);
902*a9fa9459Szrj 
903*a9fa9459Szrj       /* Ff S3Forced is TRUE then always select S3 records,
904*a9fa9459Szrj 	 regardless of the siez of the addresses.  */
905*a9fa9459Szrj       if (S3Forced)
906*a9fa9459Szrj 	tdata->type = 3;
907*a9fa9459Szrj       else if ((section->lma + (offset + bytes_to_do) / opb - 1) <= 0xffff)
908*a9fa9459Szrj 	;  /* The default, S1, is OK.  */
909*a9fa9459Szrj       else if ((section->lma + (offset + bytes_to_do) / opb - 1) <= 0xffffff
910*a9fa9459Szrj 	       && tdata->type <= 2)
911*a9fa9459Szrj 	tdata->type = 2;
912*a9fa9459Szrj       else
913*a9fa9459Szrj 	tdata->type = 3;
914*a9fa9459Szrj 
915*a9fa9459Szrj       entry->data = data;
916*a9fa9459Szrj       entry->where = section->lma + offset / opb;
917*a9fa9459Szrj       entry->size = bytes_to_do;
918*a9fa9459Szrj 
919*a9fa9459Szrj       /* Sort the records by address.  Optimize for the common case of
920*a9fa9459Szrj 	 adding a record to the end of the list.  */
921*a9fa9459Szrj       if (tdata->tail != NULL
922*a9fa9459Szrj 	  && entry->where >= tdata->tail->where)
923*a9fa9459Szrj 	{
924*a9fa9459Szrj 	  tdata->tail->next = entry;
925*a9fa9459Szrj 	  entry->next = NULL;
926*a9fa9459Szrj 	  tdata->tail = entry;
927*a9fa9459Szrj 	}
928*a9fa9459Szrj       else
929*a9fa9459Szrj 	{
930*a9fa9459Szrj 	  srec_data_list_type **look;
931*a9fa9459Szrj 
932*a9fa9459Szrj 	  for (look = &tdata->head;
933*a9fa9459Szrj 	       *look != NULL && (*look)->where < entry->where;
934*a9fa9459Szrj 	       look = &(*look)->next)
935*a9fa9459Szrj 	    ;
936*a9fa9459Szrj 	  entry->next = *look;
937*a9fa9459Szrj 	  *look = entry;
938*a9fa9459Szrj 	  if (entry->next == NULL)
939*a9fa9459Szrj 	    tdata->tail = entry;
940*a9fa9459Szrj 	}
941*a9fa9459Szrj     }
942*a9fa9459Szrj   return TRUE;
943*a9fa9459Szrj }
944*a9fa9459Szrj 
945*a9fa9459Szrj /* Write a record of type, of the supplied number of bytes. The
946*a9fa9459Szrj    supplied bytes and length don't have a checksum. That's worked out
947*a9fa9459Szrj    here.  */
948*a9fa9459Szrj 
949*a9fa9459Szrj static bfd_boolean
srec_write_record(bfd * abfd,unsigned int type,bfd_vma address,const bfd_byte * data,const bfd_byte * end)950*a9fa9459Szrj srec_write_record (bfd *abfd,
951*a9fa9459Szrj 		   unsigned int type,
952*a9fa9459Szrj 		   bfd_vma address,
953*a9fa9459Szrj 		   const bfd_byte *data,
954*a9fa9459Szrj 		   const bfd_byte *end)
955*a9fa9459Szrj {
956*a9fa9459Szrj   char buffer[2 * MAXCHUNK + 6];
957*a9fa9459Szrj   unsigned int check_sum = 0;
958*a9fa9459Szrj   const bfd_byte *src = data;
959*a9fa9459Szrj   char *dst = buffer;
960*a9fa9459Szrj   char *length;
961*a9fa9459Szrj   bfd_size_type wrlen;
962*a9fa9459Szrj 
963*a9fa9459Szrj   *dst++ = 'S';
964*a9fa9459Szrj   *dst++ = '0' + type;
965*a9fa9459Szrj 
966*a9fa9459Szrj   length = dst;
967*a9fa9459Szrj   dst += 2;			/* Leave room for dst.  */
968*a9fa9459Szrj 
969*a9fa9459Szrj   switch (type)
970*a9fa9459Szrj     {
971*a9fa9459Szrj     case 3:
972*a9fa9459Szrj     case 7:
973*a9fa9459Szrj       TOHEX (dst, (address >> 24), check_sum);
974*a9fa9459Szrj       dst += 2;
975*a9fa9459Szrj     case 8:
976*a9fa9459Szrj     case 2:
977*a9fa9459Szrj       TOHEX (dst, (address >> 16), check_sum);
978*a9fa9459Szrj       dst += 2;
979*a9fa9459Szrj     case 9:
980*a9fa9459Szrj     case 1:
981*a9fa9459Szrj     case 0:
982*a9fa9459Szrj       TOHEX (dst, (address >> 8), check_sum);
983*a9fa9459Szrj       dst += 2;
984*a9fa9459Szrj       TOHEX (dst, (address), check_sum);
985*a9fa9459Szrj       dst += 2;
986*a9fa9459Szrj       break;
987*a9fa9459Szrj 
988*a9fa9459Szrj     }
989*a9fa9459Szrj   for (src = data; src < end; src++)
990*a9fa9459Szrj     {
991*a9fa9459Szrj       TOHEX (dst, *src, check_sum);
992*a9fa9459Szrj       dst += 2;
993*a9fa9459Szrj     }
994*a9fa9459Szrj 
995*a9fa9459Szrj   /* Fill in the length.  */
996*a9fa9459Szrj   TOHEX (length, (dst - length) / 2, check_sum);
997*a9fa9459Szrj   check_sum &= 0xff;
998*a9fa9459Szrj   check_sum = 255 - check_sum;
999*a9fa9459Szrj   TOHEX (dst, check_sum, check_sum);
1000*a9fa9459Szrj   dst += 2;
1001*a9fa9459Szrj 
1002*a9fa9459Szrj   *dst++ = '\r';
1003*a9fa9459Szrj   *dst++ = '\n';
1004*a9fa9459Szrj   wrlen = dst - buffer;
1005*a9fa9459Szrj 
1006*a9fa9459Szrj   return bfd_bwrite ((void *) buffer, wrlen, abfd) == wrlen;
1007*a9fa9459Szrj }
1008*a9fa9459Szrj 
1009*a9fa9459Szrj static bfd_boolean
srec_write_header(bfd * abfd)1010*a9fa9459Szrj srec_write_header (bfd *abfd)
1011*a9fa9459Szrj {
1012*a9fa9459Szrj   unsigned int len = strlen (abfd->filename);
1013*a9fa9459Szrj 
1014*a9fa9459Szrj   /* I'll put an arbitrary 40 char limit on header size.  */
1015*a9fa9459Szrj   if (len > 40)
1016*a9fa9459Szrj     len = 40;
1017*a9fa9459Szrj 
1018*a9fa9459Szrj   return srec_write_record (abfd, 0, (bfd_vma) 0,
1019*a9fa9459Szrj 			    (bfd_byte *) abfd->filename,
1020*a9fa9459Szrj 			    (bfd_byte *) abfd->filename + len);
1021*a9fa9459Szrj }
1022*a9fa9459Szrj 
1023*a9fa9459Szrj static bfd_boolean
srec_write_section(bfd * abfd,tdata_type * tdata,srec_data_list_type * list)1024*a9fa9459Szrj srec_write_section (bfd *abfd,
1025*a9fa9459Szrj 		    tdata_type *tdata,
1026*a9fa9459Szrj 		    srec_data_list_type *list)
1027*a9fa9459Szrj {
1028*a9fa9459Szrj   unsigned int octets_written = 0;
1029*a9fa9459Szrj   bfd_byte *location = list->data;
1030*a9fa9459Szrj 
1031*a9fa9459Szrj   /* Validate number of data bytes to write.  The srec length byte
1032*a9fa9459Szrj      counts the address, data and crc bytes.  S1 (tdata->type == 1)
1033*a9fa9459Szrj      records have two address bytes, S2 (tdata->type == 2) records
1034*a9fa9459Szrj      have three, and S3 (tdata->type == 3) records have four.
1035*a9fa9459Szrj      The total length can't exceed 255, and a zero data length will
1036*a9fa9459Szrj      spin for a long time.  */
1037*a9fa9459Szrj   if (Chunk == 0)
1038*a9fa9459Szrj     Chunk = 1;
1039*a9fa9459Szrj   else if (Chunk > MAXCHUNK - tdata->type - 2)
1040*a9fa9459Szrj     Chunk = MAXCHUNK - tdata->type - 2;
1041*a9fa9459Szrj 
1042*a9fa9459Szrj   while (octets_written < list->size)
1043*a9fa9459Szrj     {
1044*a9fa9459Szrj       bfd_vma address;
1045*a9fa9459Szrj       unsigned int octets_this_chunk = list->size - octets_written;
1046*a9fa9459Szrj 
1047*a9fa9459Szrj       if (octets_this_chunk > Chunk)
1048*a9fa9459Szrj 	octets_this_chunk = Chunk;
1049*a9fa9459Szrj 
1050*a9fa9459Szrj       address = list->where + octets_written / bfd_octets_per_byte (abfd);
1051*a9fa9459Szrj 
1052*a9fa9459Szrj       if (! srec_write_record (abfd,
1053*a9fa9459Szrj 			       tdata->type,
1054*a9fa9459Szrj 			       address,
1055*a9fa9459Szrj 			       location,
1056*a9fa9459Szrj 			       location + octets_this_chunk))
1057*a9fa9459Szrj 	return FALSE;
1058*a9fa9459Szrj 
1059*a9fa9459Szrj       octets_written += octets_this_chunk;
1060*a9fa9459Szrj       location += octets_this_chunk;
1061*a9fa9459Szrj     }
1062*a9fa9459Szrj 
1063*a9fa9459Szrj   return TRUE;
1064*a9fa9459Szrj }
1065*a9fa9459Szrj 
1066*a9fa9459Szrj static bfd_boolean
srec_write_terminator(bfd * abfd,tdata_type * tdata)1067*a9fa9459Szrj srec_write_terminator (bfd *abfd, tdata_type *tdata)
1068*a9fa9459Szrj {
1069*a9fa9459Szrj   return srec_write_record (abfd, 10 - tdata->type,
1070*a9fa9459Szrj 			    abfd->start_address, NULL, NULL);
1071*a9fa9459Szrj }
1072*a9fa9459Szrj 
1073*a9fa9459Szrj static bfd_boolean
srec_write_symbols(bfd * abfd)1074*a9fa9459Szrj srec_write_symbols (bfd *abfd)
1075*a9fa9459Szrj {
1076*a9fa9459Szrj   /* Dump out the symbols of a bfd.  */
1077*a9fa9459Szrj   int i;
1078*a9fa9459Szrj   int count = bfd_get_symcount (abfd);
1079*a9fa9459Szrj 
1080*a9fa9459Szrj   if (count)
1081*a9fa9459Szrj     {
1082*a9fa9459Szrj       bfd_size_type len;
1083*a9fa9459Szrj       asymbol **table = bfd_get_outsymbols (abfd);
1084*a9fa9459Szrj 
1085*a9fa9459Szrj       len = strlen (abfd->filename);
1086*a9fa9459Szrj       if (bfd_bwrite ("$$ ", (bfd_size_type) 3, abfd) != 3
1087*a9fa9459Szrj 	  || bfd_bwrite (abfd->filename, len, abfd) != len
1088*a9fa9459Szrj 	  || bfd_bwrite ("\r\n", (bfd_size_type) 2, abfd) != 2)
1089*a9fa9459Szrj 	return FALSE;
1090*a9fa9459Szrj 
1091*a9fa9459Szrj       for (i = 0; i < count; i++)
1092*a9fa9459Szrj 	{
1093*a9fa9459Szrj 	  asymbol *s = table[i];
1094*a9fa9459Szrj 	  if (! bfd_is_local_label (abfd, s)
1095*a9fa9459Szrj 	      && (s->flags & BSF_DEBUGGING) == 0)
1096*a9fa9459Szrj 	    {
1097*a9fa9459Szrj 	      /* Just dump out non debug symbols.  */
1098*a9fa9459Szrj 	      char buf[43], *p;
1099*a9fa9459Szrj 
1100*a9fa9459Szrj 	      len = strlen (s->name);
1101*a9fa9459Szrj 	      if (bfd_bwrite ("  ", (bfd_size_type) 2, abfd) != 2
1102*a9fa9459Szrj 		  || bfd_bwrite (s->name, len, abfd) != len)
1103*a9fa9459Szrj 		return FALSE;
1104*a9fa9459Szrj 
1105*a9fa9459Szrj 	      sprintf_vma (buf + 2, (s->value
1106*a9fa9459Szrj 				     + s->section->output_section->lma
1107*a9fa9459Szrj 				     + s->section->output_offset));
1108*a9fa9459Szrj 	      p = buf + 2;
1109*a9fa9459Szrj 	      while (p[0] == '0' && p[1] != 0)
1110*a9fa9459Szrj 		p++;
1111*a9fa9459Szrj 	      len = strlen (p);
1112*a9fa9459Szrj 	      p[len] = '\r';
1113*a9fa9459Szrj 	      p[len + 1] = '\n';
1114*a9fa9459Szrj 	      *--p = '$';
1115*a9fa9459Szrj 	      *--p = ' ';
1116*a9fa9459Szrj 	      len += 4;
1117*a9fa9459Szrj 	      if (bfd_bwrite (p, len, abfd) != len)
1118*a9fa9459Szrj 		return FALSE;
1119*a9fa9459Szrj 	    }
1120*a9fa9459Szrj 	}
1121*a9fa9459Szrj       if (bfd_bwrite ("$$ \r\n", (bfd_size_type) 5, abfd) != 5)
1122*a9fa9459Szrj 	return FALSE;
1123*a9fa9459Szrj     }
1124*a9fa9459Szrj 
1125*a9fa9459Szrj   return TRUE;
1126*a9fa9459Szrj }
1127*a9fa9459Szrj 
1128*a9fa9459Szrj static bfd_boolean
internal_srec_write_object_contents(bfd * abfd,int symbols)1129*a9fa9459Szrj internal_srec_write_object_contents (bfd *abfd, int symbols)
1130*a9fa9459Szrj {
1131*a9fa9459Szrj   tdata_type *tdata = abfd->tdata.srec_data;
1132*a9fa9459Szrj   srec_data_list_type *list;
1133*a9fa9459Szrj 
1134*a9fa9459Szrj   if (symbols)
1135*a9fa9459Szrj     {
1136*a9fa9459Szrj       if (! srec_write_symbols (abfd))
1137*a9fa9459Szrj 	return FALSE;
1138*a9fa9459Szrj     }
1139*a9fa9459Szrj 
1140*a9fa9459Szrj   if (! srec_write_header (abfd))
1141*a9fa9459Szrj     return FALSE;
1142*a9fa9459Szrj 
1143*a9fa9459Szrj   /* Now wander though all the sections provided and output them.  */
1144*a9fa9459Szrj   list = tdata->head;
1145*a9fa9459Szrj 
1146*a9fa9459Szrj   while (list != (srec_data_list_type *) NULL)
1147*a9fa9459Szrj     {
1148*a9fa9459Szrj       if (! srec_write_section (abfd, tdata, list))
1149*a9fa9459Szrj 	return FALSE;
1150*a9fa9459Szrj       list = list->next;
1151*a9fa9459Szrj     }
1152*a9fa9459Szrj   return srec_write_terminator (abfd, tdata);
1153*a9fa9459Szrj }
1154*a9fa9459Szrj 
1155*a9fa9459Szrj static bfd_boolean
srec_write_object_contents(bfd * abfd)1156*a9fa9459Szrj srec_write_object_contents (bfd *abfd)
1157*a9fa9459Szrj {
1158*a9fa9459Szrj   return internal_srec_write_object_contents (abfd, 0);
1159*a9fa9459Szrj }
1160*a9fa9459Szrj 
1161*a9fa9459Szrj static bfd_boolean
symbolsrec_write_object_contents(bfd * abfd)1162*a9fa9459Szrj symbolsrec_write_object_contents (bfd *abfd)
1163*a9fa9459Szrj {
1164*a9fa9459Szrj   return internal_srec_write_object_contents (abfd, 1);
1165*a9fa9459Szrj }
1166*a9fa9459Szrj 
1167*a9fa9459Szrj static int
srec_sizeof_headers(bfd * abfd ATTRIBUTE_UNUSED,struct bfd_link_info * info ATTRIBUTE_UNUSED)1168*a9fa9459Szrj srec_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
1169*a9fa9459Szrj 		     struct bfd_link_info *info ATTRIBUTE_UNUSED)
1170*a9fa9459Szrj {
1171*a9fa9459Szrj   return 0;
1172*a9fa9459Szrj }
1173*a9fa9459Szrj 
1174*a9fa9459Szrj /* Return the amount of memory needed to read the symbol table.  */
1175*a9fa9459Szrj 
1176*a9fa9459Szrj static long
srec_get_symtab_upper_bound(bfd * abfd)1177*a9fa9459Szrj srec_get_symtab_upper_bound (bfd *abfd)
1178*a9fa9459Szrj {
1179*a9fa9459Szrj   return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *);
1180*a9fa9459Szrj }
1181*a9fa9459Szrj 
1182*a9fa9459Szrj /* Return the symbol table.  */
1183*a9fa9459Szrj 
1184*a9fa9459Szrj static long
srec_canonicalize_symtab(bfd * abfd,asymbol ** alocation)1185*a9fa9459Szrj srec_canonicalize_symtab (bfd *abfd, asymbol **alocation)
1186*a9fa9459Szrj {
1187*a9fa9459Szrj   bfd_size_type symcount = bfd_get_symcount (abfd);
1188*a9fa9459Szrj   asymbol *csymbols;
1189*a9fa9459Szrj   unsigned int i;
1190*a9fa9459Szrj 
1191*a9fa9459Szrj   csymbols = abfd->tdata.srec_data->csymbols;
1192*a9fa9459Szrj   if (csymbols == NULL && symcount != 0)
1193*a9fa9459Szrj     {
1194*a9fa9459Szrj       asymbol *c;
1195*a9fa9459Szrj       struct srec_symbol *s;
1196*a9fa9459Szrj 
1197*a9fa9459Szrj       csymbols = (asymbol *) bfd_alloc (abfd, symcount * sizeof (asymbol));
1198*a9fa9459Szrj       if (csymbols == NULL)
1199*a9fa9459Szrj 	return -1;
1200*a9fa9459Szrj       abfd->tdata.srec_data->csymbols = csymbols;
1201*a9fa9459Szrj 
1202*a9fa9459Szrj       for (s = abfd->tdata.srec_data->symbols, c = csymbols;
1203*a9fa9459Szrj 	   s != NULL;
1204*a9fa9459Szrj 	   s = s->next, ++c)
1205*a9fa9459Szrj 	{
1206*a9fa9459Szrj 	  c->the_bfd = abfd;
1207*a9fa9459Szrj 	  c->name = s->name;
1208*a9fa9459Szrj 	  c->value = s->val;
1209*a9fa9459Szrj 	  c->flags = BSF_GLOBAL;
1210*a9fa9459Szrj 	  c->section = bfd_abs_section_ptr;
1211*a9fa9459Szrj 	  c->udata.p = NULL;
1212*a9fa9459Szrj 	}
1213*a9fa9459Szrj     }
1214*a9fa9459Szrj 
1215*a9fa9459Szrj   for (i = 0; i < symcount; i++)
1216*a9fa9459Szrj     *alocation++ = csymbols++;
1217*a9fa9459Szrj   *alocation = NULL;
1218*a9fa9459Szrj 
1219*a9fa9459Szrj   return symcount;
1220*a9fa9459Szrj }
1221*a9fa9459Szrj 
1222*a9fa9459Szrj static void
srec_get_symbol_info(bfd * ignore_abfd ATTRIBUTE_UNUSED,asymbol * symbol,symbol_info * ret)1223*a9fa9459Szrj srec_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
1224*a9fa9459Szrj 		      asymbol *symbol,
1225*a9fa9459Szrj 		      symbol_info *ret)
1226*a9fa9459Szrj {
1227*a9fa9459Szrj   bfd_symbol_info (symbol, ret);
1228*a9fa9459Szrj }
1229*a9fa9459Szrj 
1230*a9fa9459Szrj static void
srec_print_symbol(bfd * abfd,void * afile,asymbol * symbol,bfd_print_symbol_type how)1231*a9fa9459Szrj srec_print_symbol (bfd *abfd,
1232*a9fa9459Szrj 		   void * afile,
1233*a9fa9459Szrj 		   asymbol *symbol,
1234*a9fa9459Szrj 		   bfd_print_symbol_type how)
1235*a9fa9459Szrj {
1236*a9fa9459Szrj   FILE *file = (FILE *) afile;
1237*a9fa9459Szrj 
1238*a9fa9459Szrj   switch (how)
1239*a9fa9459Szrj     {
1240*a9fa9459Szrj     case bfd_print_symbol_name:
1241*a9fa9459Szrj       fprintf (file, "%s", symbol->name);
1242*a9fa9459Szrj       break;
1243*a9fa9459Szrj     default:
1244*a9fa9459Szrj       bfd_print_symbol_vandf (abfd, (void *) file, symbol);
1245*a9fa9459Szrj       fprintf (file, " %-5s %s",
1246*a9fa9459Szrj 	       symbol->section->name,
1247*a9fa9459Szrj 	       symbol->name);
1248*a9fa9459Szrj     }
1249*a9fa9459Szrj }
1250*a9fa9459Szrj 
1251*a9fa9459Szrj #define	srec_close_and_cleanup                    _bfd_generic_close_and_cleanup
1252*a9fa9459Szrj #define srec_bfd_free_cached_info                 _bfd_generic_bfd_free_cached_info
1253*a9fa9459Szrj #define srec_new_section_hook                     _bfd_generic_new_section_hook
1254*a9fa9459Szrj #define srec_bfd_is_target_special_symbol         ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
1255*a9fa9459Szrj #define srec_bfd_is_local_label_name              bfd_generic_is_local_label_name
1256*a9fa9459Szrj #define srec_get_lineno                           _bfd_nosymbols_get_lineno
1257*a9fa9459Szrj #define srec_find_nearest_line                    _bfd_nosymbols_find_nearest_line
1258*a9fa9459Szrj #define srec_find_line                            _bfd_nosymbols_find_line
1259*a9fa9459Szrj #define srec_find_inliner_info                    _bfd_nosymbols_find_inliner_info
1260*a9fa9459Szrj #define srec_make_empty_symbol                    _bfd_generic_make_empty_symbol
1261*a9fa9459Szrj #define srec_get_symbol_version_string		  _bfd_nosymbols_get_symbol_version_string
1262*a9fa9459Szrj #define srec_bfd_make_debug_symbol                _bfd_nosymbols_bfd_make_debug_symbol
1263*a9fa9459Szrj #define srec_read_minisymbols                     _bfd_generic_read_minisymbols
1264*a9fa9459Szrj #define srec_minisymbol_to_symbol                 _bfd_generic_minisymbol_to_symbol
1265*a9fa9459Szrj #define srec_get_section_contents_in_window       _bfd_generic_get_section_contents_in_window
1266*a9fa9459Szrj #define srec_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
1267*a9fa9459Szrj #define srec_bfd_relax_section                    bfd_generic_relax_section
1268*a9fa9459Szrj #define srec_bfd_gc_sections                      bfd_generic_gc_sections
1269*a9fa9459Szrj #define srec_bfd_lookup_section_flags             bfd_generic_lookup_section_flags
1270*a9fa9459Szrj #define srec_bfd_merge_sections                   bfd_generic_merge_sections
1271*a9fa9459Szrj #define srec_bfd_is_group_section                 bfd_generic_is_group_section
1272*a9fa9459Szrj #define srec_bfd_discard_group                    bfd_generic_discard_group
1273*a9fa9459Szrj #define srec_section_already_linked               _bfd_generic_section_already_linked
1274*a9fa9459Szrj #define srec_bfd_define_common_symbol             bfd_generic_define_common_symbol
1275*a9fa9459Szrj #define srec_bfd_link_hash_table_create           _bfd_generic_link_hash_table_create
1276*a9fa9459Szrj #define srec_bfd_link_add_symbols                 _bfd_generic_link_add_symbols
1277*a9fa9459Szrj #define srec_bfd_link_just_syms                   _bfd_generic_link_just_syms
1278*a9fa9459Szrj #define srec_bfd_copy_link_hash_symbol_type       _bfd_generic_copy_link_hash_symbol_type
1279*a9fa9459Szrj #define srec_bfd_final_link                       _bfd_generic_final_link
1280*a9fa9459Szrj #define srec_bfd_link_split_section               _bfd_generic_link_split_section
1281*a9fa9459Szrj #define srec_bfd_link_check_relocs                _bfd_generic_link_check_relocs
1282*a9fa9459Szrj 
1283*a9fa9459Szrj const bfd_target srec_vec =
1284*a9fa9459Szrj {
1285*a9fa9459Szrj   "srec",			/* Name.  */
1286*a9fa9459Szrj   bfd_target_srec_flavour,
1287*a9fa9459Szrj   BFD_ENDIAN_UNKNOWN,		/* Target byte order.  */
1288*a9fa9459Szrj   BFD_ENDIAN_UNKNOWN,		/* Target headers byte order.  */
1289*a9fa9459Szrj   (HAS_RELOC | EXEC_P |		/* Object flags.  */
1290*a9fa9459Szrj    HAS_LINENO | HAS_DEBUG |
1291*a9fa9459Szrj    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1292*a9fa9459Szrj   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1293*a9fa9459Szrj    | SEC_ALLOC | SEC_LOAD | SEC_RELOC),	/* Section flags.  */
1294*a9fa9459Szrj   0,				/* Leading underscore.  */
1295*a9fa9459Szrj   ' ',				/* AR_pad_char.  */
1296*a9fa9459Szrj   16,				/* AR_max_namelen.  */
1297*a9fa9459Szrj   0,				/* match priority.  */
1298*a9fa9459Szrj   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1299*a9fa9459Szrj   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1300*a9fa9459Szrj   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Data.  */
1301*a9fa9459Szrj   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1302*a9fa9459Szrj   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1303*a9fa9459Szrj   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Hdrs.  */
1304*a9fa9459Szrj 
1305*a9fa9459Szrj   {
1306*a9fa9459Szrj     _bfd_dummy_target,
1307*a9fa9459Szrj     srec_object_p,		/* bfd_check_format.  */
1308*a9fa9459Szrj     _bfd_dummy_target,
1309*a9fa9459Szrj     _bfd_dummy_target,
1310*a9fa9459Szrj   },
1311*a9fa9459Szrj   {
1312*a9fa9459Szrj     bfd_false,
1313*a9fa9459Szrj     srec_mkobject,
1314*a9fa9459Szrj     _bfd_generic_mkarchive,
1315*a9fa9459Szrj     bfd_false,
1316*a9fa9459Szrj   },
1317*a9fa9459Szrj   {				/* bfd_write_contents.  */
1318*a9fa9459Szrj     bfd_false,
1319*a9fa9459Szrj     srec_write_object_contents,
1320*a9fa9459Szrj     _bfd_write_archive_contents,
1321*a9fa9459Szrj     bfd_false,
1322*a9fa9459Szrj   },
1323*a9fa9459Szrj 
1324*a9fa9459Szrj   BFD_JUMP_TABLE_GENERIC (srec),
1325*a9fa9459Szrj   BFD_JUMP_TABLE_COPY (_bfd_generic),
1326*a9fa9459Szrj   BFD_JUMP_TABLE_CORE (_bfd_nocore),
1327*a9fa9459Szrj   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
1328*a9fa9459Szrj   BFD_JUMP_TABLE_SYMBOLS (srec),
1329*a9fa9459Szrj   BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
1330*a9fa9459Szrj   BFD_JUMP_TABLE_WRITE (srec),
1331*a9fa9459Szrj   BFD_JUMP_TABLE_LINK (srec),
1332*a9fa9459Szrj   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
1333*a9fa9459Szrj 
1334*a9fa9459Szrj   NULL,
1335*a9fa9459Szrj 
1336*a9fa9459Szrj   NULL
1337*a9fa9459Szrj };
1338*a9fa9459Szrj 
1339*a9fa9459Szrj const bfd_target symbolsrec_vec =
1340*a9fa9459Szrj {
1341*a9fa9459Szrj   "symbolsrec",			/* Name.  */
1342*a9fa9459Szrj   bfd_target_srec_flavour,
1343*a9fa9459Szrj   BFD_ENDIAN_UNKNOWN,		/* Target byte order.  */
1344*a9fa9459Szrj   BFD_ENDIAN_UNKNOWN,		/* Target headers byte order.  */
1345*a9fa9459Szrj   (HAS_RELOC | EXEC_P |		/* Object flags.  */
1346*a9fa9459Szrj    HAS_LINENO | HAS_DEBUG |
1347*a9fa9459Szrj    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1348*a9fa9459Szrj   (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1349*a9fa9459Szrj    | SEC_ALLOC | SEC_LOAD | SEC_RELOC),	/* Section flags.  */
1350*a9fa9459Szrj   0,				/* Leading underscore.  */
1351*a9fa9459Szrj   ' ',				/* AR_pad_char.  */
1352*a9fa9459Szrj   16,				/* AR_max_namelen.  */
1353*a9fa9459Szrj   0,				/* match priority.  */
1354*a9fa9459Szrj   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1355*a9fa9459Szrj   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1356*a9fa9459Szrj   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Data.  */
1357*a9fa9459Szrj   bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1358*a9fa9459Szrj   bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1359*a9fa9459Szrj   bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* Headers.  */
1360*a9fa9459Szrj 
1361*a9fa9459Szrj   {
1362*a9fa9459Szrj     _bfd_dummy_target,
1363*a9fa9459Szrj     symbolsrec_object_p,	/* bfd_check_format.  */
1364*a9fa9459Szrj     _bfd_dummy_target,
1365*a9fa9459Szrj     _bfd_dummy_target,
1366*a9fa9459Szrj   },
1367*a9fa9459Szrj   {
1368*a9fa9459Szrj     bfd_false,
1369*a9fa9459Szrj     srec_mkobject,
1370*a9fa9459Szrj     _bfd_generic_mkarchive,
1371*a9fa9459Szrj     bfd_false,
1372*a9fa9459Szrj   },
1373*a9fa9459Szrj   {				/* bfd_write_contents.  */
1374*a9fa9459Szrj     bfd_false,
1375*a9fa9459Szrj     symbolsrec_write_object_contents,
1376*a9fa9459Szrj     _bfd_write_archive_contents,
1377*a9fa9459Szrj     bfd_false,
1378*a9fa9459Szrj   },
1379*a9fa9459Szrj 
1380*a9fa9459Szrj   BFD_JUMP_TABLE_GENERIC (srec),
1381*a9fa9459Szrj   BFD_JUMP_TABLE_COPY (_bfd_generic),
1382*a9fa9459Szrj   BFD_JUMP_TABLE_CORE (_bfd_nocore),
1383*a9fa9459Szrj   BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
1384*a9fa9459Szrj   BFD_JUMP_TABLE_SYMBOLS (srec),
1385*a9fa9459Szrj   BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
1386*a9fa9459Szrj   BFD_JUMP_TABLE_WRITE (srec),
1387*a9fa9459Szrj   BFD_JUMP_TABLE_LINK (srec),
1388*a9fa9459Szrj   BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
1389*a9fa9459Szrj 
1390*a9fa9459Szrj   NULL,
1391*a9fa9459Szrj 
1392*a9fa9459Szrj   NULL
1393*a9fa9459Szrj };
1394