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