* sunos.c (sunos_create_dynamic_sections): We need the dynamic
[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 /*-----------------------------------------------------------------------------*/
128 /* Output routines. */
129
130
131 /* Manufacure a VMS like time on a unix based system.
132 stolen from obj-vms.c */
133
134 static unsigned char *
135 get_vms_time_string ()
136 {
137 static unsigned char tbuf[18];
138 #ifndef VMS
139 #include <sys/types.h>
140 #include <time.h>
141
142 char *pnt;
143 time_t timeb;
144 time (&timeb);
145 pnt = ctime (&timeb);
146 pnt[3] = 0;
147 pnt[7] = 0;
148 pnt[10] = 0;
149 pnt[16] = 0;
150 pnt[24] = 0;
151 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
152 #else
153 #include <starlet.h>
154 struct
155 {
156 int Size;
157 unsigned char *Ptr;
158 } Descriptor;
159 Descriptor.Size = 17;
160 Descriptor.Ptr = tbuf;
161 sys$asctim (0, &Descriptor, 0, 0);
162 #endif /* not VMS */
163
164 #if EVAX_DEBUG
165 evax_debug (6, "vmstimestring:'%s'\n", tbuf);
166 #endif
167
168 return tbuf;
169 }
170
171
172 /* write object header for bfd abfd */
173
174 int
175 _bfd_evax_write_emh (abfd)
176 bfd *abfd;
177 {
178 asymbol *symbol;
179 int symnum;
180 int had_case = 0;
181 int had_file = 0;
182
183
184 #if EVAX_DEBUG
185 evax_debug (2, "evax_write_emh(%p)\n", abfd);
186 #endif
187
188 _bfd_evax_output_alignment (abfd, 2);
189
190 /* MHD */
191
192 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
193 _bfd_evax_output_short (abfd, EOBJ_S_C_STRLVL);
194 _bfd_evax_output_long (abfd, 0);
195 _bfd_evax_output_long (abfd, 0);
196 _bfd_evax_output_long (abfd, MAX_OUTREC_SIZE);
197
198 if (bfd_get_filename (abfd) != 0)
199 _bfd_evax_output_counted (abfd, bfd_get_filename (abfd));
200 else
201 _bfd_evax_output_counted (abfd, "NONAME");
202
203 _bfd_evax_output_counted (abfd, BFD_VERSION);
204 _bfd_evax_output_dump (abfd, get_vms_time_string (), 17);
205 _bfd_evax_output_fill (abfd, 0, 17);
206 _bfd_evax_output_flush (abfd);
207
208 /* LMN */
209
210 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
211 _bfd_evax_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
212 _bfd_evax_output_flush (abfd);
213
214 /* SRC */
215
216 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
217
218 for (symnum = 0; symnum < abfd->symcount; symnum++)
219 {
220 symbol = abfd->outsymbols[symnum];
221
222 if (symbol->flags & BSF_FILE)
223 {
224 char *s;
225
226 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
227 {
228 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
229 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
230 PRIV(flag_no_hash_mixed_case) = symbol->name[8] - '0';
231 PRIV(vms_name_mapping) = symbol->name[9] - '0';
232
233 if (had_file)
234 break;
235 had_case = 1;
236 continue;
237 }
238
239 _bfd_evax_output_dump (abfd, (char *)symbol->name, strlen (symbol->name));
240 if (had_case)
241 break;
242 had_file = 1;
243 }
244 }
245
246 if (symnum == abfd->symcount)
247 _bfd_evax_output_dump (abfd, "noname", 6);
248
249 _bfd_evax_output_flush (abfd);
250
251 /* TTL */
252
253 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
254 _bfd_evax_output_dump (abfd, (unsigned char *)"TTL", 3);
255 _bfd_evax_output_flush (abfd);
256
257 /* CPR */
258
259 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
260 _bfd_evax_output_dump (abfd,
261 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
262 39);
263 _bfd_evax_output_flush (abfd);
264
265 return 0;
266 }
267
268 /*-----------------------------------------------------------------------------*/
269
270 /* Process EEOM record
271 return 0 on success, -1 on error */
272
273 int
274 _bfd_evax_slurp_eeom (abfd)
275 bfd *abfd;
276 {
277 unsigned char *evax_rec;
278
279 #if EVAX_DEBUG
280 evax_debug(2, "EEOM\n");
281 #endif
282
283 evax_rec = PRIV(evax_rec);
284
285 PRIV(eeom_data).eeom_l_total_lps = bfd_getl32 (evax_rec + 4);
286 PRIV(eeom_data).eeom_b_comcod = *(evax_rec + 8);
287 if (PRIV(eeom_data).eeom_b_comcod > 1)
288 {
289 (*_bfd_error_handler) ("Object module NOT error-free !\n");
290 bfd_set_error (bfd_error_bad_value);
291 return -1;
292 }
293 PRIV(eeom_data).eeom_has_transfer = false;
294 if (PRIV(rec_size) > 10)
295 {
296 PRIV(eeom_data).eeom_has_transfer = true;
297 PRIV(eeom_data).eeom_b_tfrflg = *(evax_rec + 9);
298 PRIV(eeom_data).eeom_l_psindx = bfd_getl32 (evax_rec + 12);
299 PRIV(eeom_data).eeom_l_tfradr = bfd_getl32 (evax_rec + 16);
300
301 abfd->start_address = PRIV(eeom_data).eeom_l_tfradr;
302 }
303 return 0;
304 }
305
306
307 /* Write eom record for bfd abfd */
308
309 int
310 _bfd_evax_write_eeom (abfd)
311 bfd *abfd;
312 {
313 #if EVAX_DEBUG
314 evax_debug (2, "evax_write_eeom(%p)\n", abfd);
315 #endif
316
317 _bfd_evax_output_begin (abfd,EOBJ_S_C_EEOM, -1);
318 _bfd_evax_output_long (abfd, (unsigned long)(PRIV(evax_linkage_index) >> 1));
319 _bfd_evax_output_byte (abfd, 0); /* completion code */
320 _bfd_evax_output_byte (abfd, 0); /* fill byte */
321
322 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
323 {
324 asection *section;
325
326 section = bfd_get_section_by_name (abfd, ".link");
327 if (section == 0)
328 {
329 bfd_set_error (bfd_error_nonrepresentable_section);
330 return -1;
331 }
332 _bfd_evax_output_short (abfd, 0);
333 _bfd_evax_output_long (abfd, (unsigned long)(section->index));
334 _bfd_evax_output_long (abfd,
335 (unsigned long) bfd_get_start_address (abfd));
336 _bfd_evax_output_long (abfd, 0);
337 }
338
339 _bfd_evax_output_end (abfd);
340 return 0;
341 }
This page took 0.03666 seconds and 4 git commands to generate.