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