Tue Jun 25 11:41:24 1996 Richard Henderson <rth@tamu.edu>
[deliverable/binutils-gdb.git] / bfd / evax-emh.c
1 /* evax-emh.c -- BFD back-end for ALPHA EVAX (openVMS/AXP) files.
2 Copyright 1996 Free Software Foundation, Inc.
3
4 EMH record handling functions
5 and
6 EEOM record handling functions
7
8 Written by Klaus Kämpf (kkaempf@progis.de)
9 of proGIS Softwareentwicklung, Aachen, Germany
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25 #include <stdio.h>
26
27 #include "bfd.h"
28 #include "sysdep.h"
29 #include "bfdlink.h"
30 #include "libbfd.h"
31
32 #include "evax.h"
33
34 /*---------------------------------------------------------------------------*/
35
36
37 /* Read & process emh record
38 return 0 on success, -1 on error */
39
40 int
41 _bfd_evax_slurp_emh (abfd)
42 bfd *abfd;
43 {
44 unsigned char *ptr;
45 unsigned char *evax_rec;
46
47 evax_rec = PRIV(evax_rec);
48
49 #if EVAX_DEBUG
50 evax_debug(2, "EMH\n");
51 #endif
52
53 switch (bfd_getl16 (evax_rec + 4))
54 {
55
56 case EMH_S_C_MHD:
57 /*
58 * module header
59 */
60 PRIV(emh_data).emh_b_strlvl = evax_rec[6];
61 PRIV(emh_data).emh_l_arch1 = bfd_getl32 (evax_rec + 8);
62 PRIV(emh_data).emh_l_arch2 = bfd_getl32 (evax_rec + 12);
63 PRIV(emh_data).emh_l_recsiz = bfd_getl32 (evax_rec + 16);
64 PRIV(emh_data).emh_t_name =
65 _bfd_evax_save_counted_string ((char *)evax_rec + 20);
66 ptr = evax_rec + 20 + evax_rec[20] + 1;
67 PRIV(emh_data).emh_t_version =
68 _bfd_evax_save_counted_string ((char *)ptr);
69 ptr += *ptr + 1;
70 PRIV(emh_data).emh_t_date =
71 _bfd_evax_save_sized_string ((char *)ptr, 17);
72
73 break;
74
75 case EMH_S_C_LNM:
76 /*
77 *
78 */
79 PRIV(emh_data).emh_c_lnm =
80 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
81 break;
82
83 case EMH_S_C_SRC:
84 /*
85 *
86 */
87 PRIV(emh_data).emh_c_src =
88 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
89 break;
90
91 case EMH_S_C_TTL:
92 /*
93 *
94 */
95 PRIV(emh_data).emh_c_ttl =
96 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
97 break;
98
99 case EMH_S_C_CPR:
100 /*
101 *
102 */
103 break;
104
105 case EMH_S_C_MTC:
106 /*
107 *
108 */
109 break;
110
111 case EMH_S_C_GTX:
112 /*
113 *
114 */
115 break;
116
117 default:
118 bfd_set_error (bfd_error_wrong_format);
119 return -1;
120
121 } /* switch */
122
123 return 0;
124 }
125
126
127 #if 0
128
129 /* register a file name */
130
131 int
132 _bfd_evax_register_filename (abfd, name)
133 bfd *abfd;
134 char *name;
135 {
136 if (PRIV(filename) != NULL)
137 {
138 #if EVAX_DEBUG
139 evax_debug(3, "Second filename %s, first was %s\n", name, PRIV(filename));
140 #endif
141 return -1;
142 }
143 PRIV(filename) = strdup (name);
144 return 0;
145 }
146
147 #endif /* 0 */
148
149 /* write object header for bfd abfd */
150
151 int
152 _bfd_evax_write_emh (abfd)
153 bfd *abfd;
154 {
155 char *name;
156
157 #if EVAX_DEBUG
158 evax_debug (2, "evax_write_emh(%p)\n", abfd);
159 #endif
160
161 _bfd_evax_output_alignment (abfd, 2);
162
163 /* MHD */
164
165 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
166 _bfd_evax_output_short (abfd, EOBJ_S_C_STRLVL);
167 _bfd_evax_output_long (abfd, 0);
168 _bfd_evax_output_long (abfd, 0);
169 _bfd_evax_output_long (abfd, MAX_OUTREC_SIZE);
170 if (bfd_get_filename (abfd) != NULL)
171 {
172 name = strdup (bfd_get_filename (abfd));
173 _bfd_evax_output_counted (abfd, _bfd_evax_basename (name));
174 }
175 else
176 _bfd_evax_output_counted (abfd, "NONAME");
177 _bfd_evax_output_counted (abfd, BFD_VERSION);
178 _bfd_evax_output_dump (abfd, (unsigned char *)_bfd_get_vms_time_string (),
179 17);
180 _bfd_evax_output_fill (abfd, 0, 17);
181 _bfd_evax_output_flush (abfd);
182
183 /* LMN */
184
185 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
186 _bfd_evax_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
187 _bfd_evax_output_flush (abfd);
188
189 /* SRC */
190
191 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
192 if (PRIV(filename) != 0)
193 _bfd_evax_output_dump (abfd, (unsigned char *)PRIV(filename), strlen (PRIV(filename)));
194 else
195 _bfd_evax_output_dump (abfd, (unsigned char *)"noname", 6);
196 _bfd_evax_output_flush (abfd);
197
198 /* TTL */
199
200 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
201 _bfd_evax_output_dump (abfd, (unsigned char *)"TTL", 3);
202 _bfd_evax_output_flush (abfd);
203
204 /* CPR */
205
206 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
207 _bfd_evax_output_dump (abfd,
208 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
209 39);
210 _bfd_evax_output_flush (abfd);
211
212 return 0;
213 }
214
215 /*-----------------------------------------------------------------------------*/
216
217 /* Process EEOM record
218 return 0 on success, -1 on error */
219
220 int
221 _bfd_evax_slurp_eeom (abfd)
222 bfd *abfd;
223 {
224 unsigned char *evax_rec;
225
226 #if EVAX_DEBUG
227 evax_debug(2, "EEOM\n");
228 #endif
229
230 evax_rec = PRIV(evax_rec);
231
232 PRIV(eeom_data).eeom_l_total_lps = bfd_getl32 (evax_rec + 4);
233 PRIV(eeom_data).eeom_b_comcod = *(evax_rec + 8);
234 if (PRIV(eeom_data).eeom_b_comcod > 1)
235 {
236 (*_bfd_error_handler) ("Object module NOT error-free !\n");
237 bfd_set_error (bfd_error_bad_value);
238 return -1;
239 }
240 PRIV(eeom_data).eeom_has_transfer = false;
241 if (PRIV(rec_size) > 10)
242 {
243 PRIV(eeom_data).eeom_has_transfer = true;
244 PRIV(eeom_data).eeom_b_tfrflg = *(evax_rec + 9);
245 PRIV(eeom_data).eeom_l_psindx = bfd_getl32 (evax_rec + 12);
246 PRIV(eeom_data).eeom_l_tfradr = bfd_getl32 (evax_rec + 16);
247
248 abfd->start_address = PRIV(eeom_data).eeom_l_tfradr;
249 }
250 return 0;
251 }
252
253
254 /* Write eom record for bfd abfd */
255
256 int
257 _bfd_evax_write_eeom (abfd)
258 bfd *abfd;
259 {
260 #if EVAX_DEBUG
261 evax_debug (2, "evax_write_eeom(%p)\n", abfd);
262 #endif
263
264 _bfd_evax_output_begin (abfd,EOBJ_S_C_EEOM, -1);
265 _bfd_evax_output_long (abfd, (unsigned long)(PRIV(evax_linkage_index) >> 1));
266 _bfd_evax_output_byte (abfd, 0); /* completion code */
267 _bfd_evax_output_byte (abfd, 0); /* fill byte */
268
269 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
270 {
271 asection *section;
272
273 section = bfd_get_section_by_name (abfd, ".link");
274 if (section == 0)
275 {
276 bfd_set_error (bfd_error_nonrepresentable_section);
277 return -1;
278 }
279 _bfd_evax_output_short (abfd, 0);
280 _bfd_evax_output_long (abfd, (unsigned long)(section->index));
281 _bfd_evax_output_long (abfd,
282 (unsigned long) bfd_get_start_address (abfd));
283 _bfd_evax_output_long (abfd, 0);
284 }
285
286 _bfd_evax_output_end (abfd);
287 return 0;
288 }
This page took 0.050699 seconds and 4 git commands to generate.