* config/tc-mips.c (macro): Use $AT for any floating point load.
[deliverable/binutils-gdb.git] / bfd / seclet.c
1 /* seclet.c
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 /* 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"
49
50 /* Create a new seclet and attach it to a section. */
51
52 bfd_seclet_type *
53 DEFUN(bfd_new_seclet,(abfd, section),
54 bfd *abfd AND
55 asection *section)
56 {
57 bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type));
58 if (section->seclets_tail != (bfd_seclet_type *)NULL) {
59 section->seclets_tail->next = n;
60 }
61 else
62 {
63 section->seclets_head = n;
64 }
65 section->seclets_tail = n;
66
67 return n;
68 }
69
70 /* Given an indirect seclet which points to an input section, relocate
71 the contents of the seclet and put the data in its final
72 destination. */
73
74 static boolean
75 DEFUN(rel,(abfd, seclet, output_section, data, relocateable),
76 bfd *abfd AND
77 bfd_seclet_type *seclet AND
78 asection *output_section AND
79 PTR data AND
80 boolean relocateable)
81 {
82
83 if (output_section->flags & SEC_HAS_CONTENTS
84 && !(output_section->flags & SEC_NEVER_LOAD)
85 && (output_section->flags & SEC_LOAD)
86 && seclet->size)
87 {
88 data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data,
89 relocateable);
90 if(bfd_set_section_contents(abfd,
91 output_section,
92 data,
93 seclet->offset,
94 seclet->size) == false)
95 {
96 abort();
97 }
98 }
99 return true;
100 }
101
102 /* Put the contents of a seclet in its final destination. */
103
104 static boolean
105 DEFUN(seclet_dump_seclet,(abfd, seclet, section, data, relocateable),
106 bfd *abfd AND
107 bfd_seclet_type *seclet AND
108 asection *section AND
109 PTR data AND
110 boolean relocateable)
111 {
112 switch (seclet->type)
113 {
114 case bfd_indirect_seclet:
115 /* The contents of this section come from another one somewhere
116 else */
117 return rel(abfd, seclet, section, data, relocateable);
118
119 case bfd_fill_seclet:
120 /* Fill in the section with us */
121 {
122 char *d = bfd_xmalloc(seclet->size);
123 unsigned int i;
124 for (i =0; i < seclet->size; i+=2) {
125 d[i] = seclet->u.fill.value >> 8;
126 }
127 for (i = 1; i < seclet->size; i+=2) {
128 d[i] = seclet->u.fill.value ;
129 }
130 /* Don't bother to fill in empty sections */
131 if (!bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS)
132 {
133 return true;
134 }
135 return bfd_set_section_contents(abfd, section, d, seclet->offset,
136 seclet->size);
137 }
138
139 default:
140 abort();
141 }
142
143 return true;
144 }
145
146 /*
147 INTERNAL_FUNCTION
148 bfd_generic_seclet_link
149
150 SYNOPSIS
151 boolean bfd_generic_seclet_link
152 (bfd *abfd,
153 PTR data,
154 boolean relocateable);
155
156 DESCRIPTION
157
158 The generic seclet linking routine. The caller should have
159 set up seclets for all the output sections. The DATA argument
160 should point to a memory area large enough to hold the largest
161 section. This function looks through the seclets and moves
162 the contents into the output sections. If RELOCATEABLE is
163 true, the orelocation fields of the output sections must
164 already be initialized.
165
166 */
167
168 boolean
169 DEFUN(bfd_generic_seclet_link,(abfd, data, relocateable),
170 bfd *abfd AND
171 PTR data AND
172 boolean relocateable)
173 {
174 asection *o = abfd->sections;
175 while (o != (asection *)NULL)
176 {
177 bfd_seclet_type *p = o->seclets_head;
178 while (p != (bfd_seclet_type *)NULL)
179 {
180 if (seclet_dump_seclet(abfd, p, o, data, relocateable) == false)
181 return false;
182 p = p ->next;
183 }
184 o = o->next;
185 }
186
187 return true;
188 }
This page took 0.032369 seconds and 4 git commands to generate.