* hppa.c: Get rid of DEFUN, use more conventional prolog stuff.
[deliverable/binutils-gdb.git] / bfd / seclet.c
CommitLineData
2afc285d
PB
1/* seclet.c
2 Copyright (C) 1992 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
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
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
e98e6ec1
SC
21/* This module is part of BFD */
22
23
24/* The intention is that one day, all the code which uses sections
25 will change and use seclets instead - maybe seglet would have been
26 a better name..
27
28 Anyway, a seclet contains enough info to be able to describe an
29 area of output memory in one go.
30
31 The only description so far catered for is that of the
32 <<bfd_indirect_seclet>>, which is a select which points to a
33 <<section>> and the <<asymbols>> associated with the section, so
34 that relocation can be done when needed.
35
36 One day there will be more types - they will at least migrate from
37 the linker's data structures - also there could be extra stuff,
38 like a bss seclet, which descibes a lump of memory as containing
39 zeros compactly, without the horrible SEC_* flag cruft.
40
41
42*/
43
44#include "bfd.h"
45#include "sysdep.h"
46#include "libbfd.h"
47#include "seclet.h"
48#include "coff/internal.h"
49bfd_seclet_type *
50DEFUN(bfd_new_seclet,(abfd, section),
51 bfd *abfd AND
52 asection *section)
53{
54 bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type));
55 if (section->seclets_tail != (bfd_seclet_type *)NULL) {
56 section->seclets_tail->next = n;
57 }
58 else
59 {
60 section->seclets_head = n;
61 }
62 section->seclets_tail = n;
63
64 return n;
e98e6ec1
SC
65}
66
67
68
69
70#define MAX_ERRORS_IN_A_ROW 10
71extern bfd_error_vector_type bfd_error_vector;
e98e6ec1 72
e98e6ec1
SC
73
74void
3be56062 75DEFUN(rel,(abfd, seclet, output_section, data),
e98e6ec1
SC
76 bfd *abfd AND
77 bfd_seclet_type *seclet AND
3be56062
SC
78 asection *output_section AND
79 PTR data)
e98e6ec1 80{
2cfd0562 81
ab98fd5d 82 if (output_section->flags & SEC_HAS_CONTENTS
b58e9180 83 && !(output_section->flags & SEC_NEVER_LOAD)
c26d7d17 84 && (output_section->flags & SEC_LOAD)
b58e9180 85 && seclet->size)
e98e6ec1 86 {
2652a49c 87 data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data);
e5932011
SC
88 if(bfd_set_section_contents(abfd,
89 output_section,
90 data,
91 seclet->offset,
92 seclet->size) == false)
93 {
94 abort();
95 }
e98e6ec1 96 }
e98e6ec1
SC
97}
98
99void
3be56062 100DEFUN(seclet_dump_seclet,(abfd, seclet, section, data),
e98e6ec1
SC
101 bfd *abfd AND
102 bfd_seclet_type *seclet AND
3be56062
SC
103 asection *section AND
104 PTR data)
e98e6ec1
SC
105{
106 switch (seclet->type)
107 {
e5932011 108 case bfd_indirect_seclet:
e98e6ec1
SC
109 /* The contents of this section come from another one somewhere
110 else */
3be56062 111 rel(abfd, seclet, section, data);
e98e6ec1 112 break;
e5932011
SC
113 case bfd_fill_seclet:
114 /* Fill in the section with us */
115 {
116 char *d = malloc(seclet->size);
117 unsigned int i;
118 for (i =0; i < seclet->size; i+=2) {
119 d[i] = seclet->u.fill.value >> 8;
120 }
121 for (i = 1; i < seclet->size; i+=2) {
122 d[i] = seclet->u.fill.value ;
123 }
124 bfd_set_section_contents(abfd, section, d, seclet->offset, seclet->size);
125
126 }
127 break;
128 default:
e98e6ec1
SC
129 abort();
130 }
e98e6ec1
SC
131}
132
133void
3be56062
SC
134DEFUN(seclet_dump,(abfd, data),
135 bfd *abfd AND
136 PTR data)
e98e6ec1
SC
137{
138 /* Write all the seclets on the bfd out, relocate etc according to the
139 rules */
140
141 asection *o = abfd->sections;
142 while (o != (asection *)NULL)
143 {
144 bfd_seclet_type *p = o->seclets_head;
145 while (p != (bfd_seclet_type *)NULL)
146 {
3be56062 147 seclet_dump_seclet(abfd, p, o, data);
e98e6ec1
SC
148 p = p ->next;
149 }
e98e6ec1
SC
150 o = o->next;
151 }
e98e6ec1 152}
This page took 0.048974 seconds and 4 git commands to generate.