update copyright dates
[deliverable/binutils-gdb.git] / bfd / vms-hdr.c
1 /* vms-hdr.c -- BFD back-end for VMS/VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
4 Free Software Foundation, Inc.
5
6 HDR record handling functions
7 EMH record handling functions
8 and
9 EOM record handling functions
10 EEOM record handling functions
11
12 Written by Klaus K"ampf (kkaempf@rmi.de)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27
28 #include "bfd.h"
29 #include "bfdver.h"
30 #include "sysdep.h"
31 #include "bfdlink.h"
32 #include "safe-ctype.h"
33 #include "libbfd.h"
34
35 #include "vms.h"
36
37 #ifdef HAVE_ALLOCA_H
38 #include <alloca.h>
39 #endif
40
41 static unsigned char *get_vms_time_string PARAMS ((void));
42
43
44 /*---------------------------------------------------------------------------*/
45
46 /* Read & process emh record
47 return 0 on success, -1 on error */
48
49 int
50 _bfd_vms_slurp_hdr (abfd, objtype)
51 bfd *abfd;
52 int objtype;
53 {
54 unsigned char *ptr;
55 unsigned char *vms_rec;
56 int subtype;
57
58 vms_rec = PRIV(vms_rec);
59
60 #if VMS_DEBUG
61 vms_debug(2, "HDR/EMH\n");
62 #endif
63
64 switch (objtype)
65 {
66 case OBJ_S_C_HDR:
67 subtype = vms_rec[1];
68 break;
69 case EOBJ_S_C_EMH:
70 subtype = bfd_getl16 (vms_rec + 4) + EVAX_OFFSET;
71 break;
72 default:
73 subtype = -1;
74 }
75
76 #if VMS_DEBUG
77 vms_debug(3, "subtype %d\n", subtype);
78 #endif
79
80 switch (subtype)
81 {
82
83 case MHD_S_C_MHD:
84 /*
85 * module header
86 */
87 PRIV(hdr_data).hdr_b_strlvl = vms_rec[2];
88 PRIV(hdr_data).hdr_l_recsiz = bfd_getl16 (vms_rec + 3);
89 PRIV(hdr_data).hdr_t_name = _bfd_vms_save_counted_string (vms_rec + 5);
90 ptr = vms_rec + 5 + vms_rec[5] + 1;
91 PRIV(hdr_data).hdr_t_version = _bfd_vms_save_counted_string (ptr);
92 ptr += *ptr + 1;
93 PRIV(hdr_data).hdr_t_date = _bfd_vms_save_sized_string (ptr, 17);
94
95 break;
96
97 case MHD_S_C_LNM:
98 /*
99 *
100 */
101 PRIV(hdr_data).hdr_c_lnm = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
102 break;
103
104 case MHD_S_C_SRC:
105 /*
106 *
107 */
108 PRIV(hdr_data).hdr_c_src = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
109 break;
110
111 case MHD_S_C_TTL:
112 /*
113 *
114 */
115 PRIV(hdr_data).hdr_c_ttl = _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-2));
116 break;
117
118 case MHD_S_C_CPR:
119 /*
120 *
121 */
122 break;
123
124 case MHD_S_C_MTC:
125 /*
126 *
127 */
128 break;
129
130 case MHD_S_C_GTX:
131 /*
132 *
133 */
134 break;
135
136 case EMH_S_C_MHD + EVAX_OFFSET:
137 /*
138 * module header
139 */
140 PRIV(hdr_data).hdr_b_strlvl = vms_rec[6];
141 PRIV(hdr_data).hdr_l_arch1 = bfd_getl32 (vms_rec + 8);
142 PRIV(hdr_data).hdr_l_arch2 = bfd_getl32 (vms_rec + 12);
143 PRIV(hdr_data).hdr_l_recsiz = bfd_getl32 (vms_rec + 16);
144 PRIV(hdr_data).hdr_t_name =
145 _bfd_vms_save_counted_string (vms_rec + 20);
146 ptr = vms_rec + 20 + vms_rec[20] + 1;
147 PRIV(hdr_data).hdr_t_version =
148 _bfd_vms_save_counted_string (ptr);
149 ptr += *ptr + 1;
150 PRIV(hdr_data).hdr_t_date =
151 _bfd_vms_save_sized_string (ptr, 17);
152
153 break;
154
155 case EMH_S_C_LNM + EVAX_OFFSET:
156 /*
157 *
158 */
159 PRIV(hdr_data).hdr_c_lnm =
160 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
161 break;
162
163 case EMH_S_C_SRC + EVAX_OFFSET:
164 /*
165 *
166 */
167 PRIV(hdr_data).hdr_c_src =
168 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
169 break;
170
171 case EMH_S_C_TTL + EVAX_OFFSET:
172 /*
173 *
174 */
175 PRIV(hdr_data).hdr_c_ttl =
176 _bfd_vms_save_sized_string (vms_rec, PRIV(rec_length-6));
177 break;
178
179 case EMH_S_C_CPR + EVAX_OFFSET:
180 /*
181 *
182 */
183 break;
184
185 case EMH_S_C_MTC + EVAX_OFFSET:
186 /*
187 *
188 */
189 break;
190
191 case EMH_S_C_GTX + EVAX_OFFSET:
192 /*
193 *
194 */
195 break;
196
197 default:
198 bfd_set_error (bfd_error_wrong_format);
199 return -1;
200
201 } /* switch */
202
203 return 0;
204 }
205
206 /*-----------------------------------------------------------------------------*/
207 /* Output routines. */
208
209 /* Manufacture a VMS like time on a unix based system.
210 stolen from obj-vms.c */
211
212 static unsigned char *
213 get_vms_time_string ()
214 {
215 static unsigned char tbuf[18];
216 #ifndef VMS
217 #include <time.h>
218
219 char *pnt;
220 time_t timeb;
221 time (&timeb);
222 pnt = ctime (&timeb);
223 pnt[3] = 0;
224 pnt[7] = 0;
225 pnt[10] = 0;
226 pnt[16] = 0;
227 pnt[24] = 0;
228 sprintf ((char *) tbuf, "%2s-%3s-%s %s",
229 pnt + 8, pnt + 4, pnt + 20, pnt + 11);
230 #else
231 #include <starlet.h>
232 struct
233 {
234 int Size;
235 unsigned char *Ptr;
236 } Descriptor;
237 Descriptor.Size = 17;
238 Descriptor.Ptr = tbuf;
239 SYS$ASCTIM (0, &Descriptor, 0, 0);
240 #endif /* not VMS */
241
242 #if VMS_DEBUG
243 vms_debug (6, "vmstimestring:'%s'\n", tbuf);
244 #endif
245
246 return tbuf;
247 }
248
249 /* write object header for bfd abfd */
250
251 int
252 _bfd_vms_write_hdr (abfd, objtype)
253 bfd *abfd;
254 int objtype;
255 {
256 asymbol *symbol;
257 unsigned int symnum;
258 int had_case = 0;
259 int had_file = 0;
260
261 #if VMS_DEBUG
262 vms_debug (2, "vms_write_hdr (%p)\n", abfd);
263 #endif
264
265 _bfd_vms_output_alignment (abfd, 2);
266
267 /* MHD */
268
269 if (objtype == OBJ_S_C_HDR)
270 {
271 }
272 else
273 {
274 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
275 _bfd_vms_output_short (abfd, EOBJ_S_C_STRLVL);
276 _bfd_vms_output_long (abfd, 0);
277 _bfd_vms_output_long (abfd, 0);
278 _bfd_vms_output_long (abfd, MAX_OUTREC_SIZE);
279 }
280
281 if (bfd_get_filename (abfd) != 0)
282 {
283 /* strip path and suffix information */
284
285 char *fname, *fout, *fptr;
286
287 fptr = bfd_get_filename (abfd);
288 fname = (char *) alloca (strlen (fptr) + 1);
289 strcpy (fname, fptr);
290 fout = strrchr (fname, ']');
291 if (fout == 0)
292 fout = strchr (fname, ':');
293 if (fout != 0)
294 fout++;
295 else
296 fout = fname;
297
298 /* strip .obj suffix */
299
300 fptr = strrchr (fname, '.');
301 if ((fptr != 0)
302 && (strcasecmp (fptr, ".OBJ") == 0))
303 *fptr = 0;
304
305 fptr = fout;
306 while (*fptr != 0)
307 {
308 *fptr = TOUPPER (*fptr);
309 fptr++;
310 if ((*fptr == ';')
311 || ((fptr - fout) > 31))
312 *fptr = 0;
313 }
314 _bfd_vms_output_counted (abfd, fout);
315 }
316 else
317 _bfd_vms_output_counted (abfd, "NONAME");
318
319 _bfd_vms_output_counted (abfd, BFD_VERSION_STRING);
320 _bfd_vms_output_dump (abfd, get_vms_time_string (), 17);
321 _bfd_vms_output_fill (abfd, 0, 17);
322 _bfd_vms_output_flush (abfd);
323
324 /* LMN */
325
326 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
327 _bfd_vms_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
328 _bfd_vms_output_flush (abfd);
329
330 /* SRC */
331
332 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
333
334 for (symnum = 0; symnum < abfd->symcount; symnum++)
335 {
336 symbol = abfd->outsymbols[symnum];
337
338 if (symbol->flags & BSF_FILE)
339 {
340 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
341 {
342 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
343 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
344
345 if (had_file)
346 break;
347 had_case = 1;
348 continue;
349 }
350
351 _bfd_vms_output_dump (abfd, (unsigned char *) symbol->name,
352 (int) strlen (symbol->name));
353 if (had_case)
354 break;
355 had_file = 1;
356 }
357 }
358
359 if (symnum == abfd->symcount)
360 _bfd_vms_output_dump (abfd, (unsigned char *)"noname", 6);
361
362 _bfd_vms_output_flush (abfd);
363
364 /* TTL */
365
366 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
367 _bfd_vms_output_dump (abfd, (unsigned char *)"TTL", 3);
368 _bfd_vms_output_flush (abfd);
369
370 /* CPR */
371
372 _bfd_vms_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
373 _bfd_vms_output_dump (abfd,
374 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
375 39);
376 _bfd_vms_output_flush (abfd);
377
378 return 0;
379 }
380
381 /*-----------------------------------------------------------------------------*/
382
383 /* Process EOM/EEOM record
384 return 0 on success, -1 on error */
385
386 int
387 _bfd_vms_slurp_eom (abfd, objtype)
388 bfd *abfd;
389 int objtype;
390 {
391 unsigned char *vms_rec;
392
393 #if VMS_DEBUG
394 vms_debug(2, "EOM/EEOM\n");
395 #endif
396
397 vms_rec = PRIV(vms_rec);
398
399 if ((objtype == OBJ_S_C_EOM)
400 || (objtype == OBJ_S_C_EOMW))
401 {
402 }
403 else
404 {
405 PRIV(eom_data).eom_l_total_lps = bfd_getl32 (vms_rec + 4);
406 PRIV(eom_data).eom_b_comcod = *(vms_rec + 8);
407 if (PRIV(eom_data).eom_b_comcod > 1)
408 {
409 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
410 bfd_set_error (bfd_error_bad_value);
411 return -1;
412 }
413 PRIV(eom_data).eom_has_transfer = FALSE;
414 if (PRIV(rec_size) > 10)
415 {
416 PRIV(eom_data).eom_has_transfer = TRUE;
417 PRIV(eom_data).eom_b_tfrflg = *(vms_rec + 9);
418 PRIV(eom_data).eom_l_psindx = bfd_getl32 (vms_rec + 12);
419 PRIV(eom_data).eom_l_tfradr = bfd_getl32 (vms_rec + 16);
420
421 abfd->start_address = PRIV(eom_data).eom_l_tfradr;
422 }
423 }
424 return 0;
425 }
426
427 /* Write eom record for bfd abfd */
428
429 int
430 _bfd_vms_write_eom (abfd, objtype)
431 bfd *abfd;
432 int objtype;
433 {
434 #if VMS_DEBUG
435 vms_debug (2, "vms_write_eom (%p, %d)\n", abfd, objtype);
436 #endif
437
438 _bfd_vms_output_begin (abfd, objtype, -1);
439 _bfd_vms_output_long (abfd, (unsigned long) (PRIV(vms_linkage_index) >> 1));
440 _bfd_vms_output_byte (abfd, 0); /* completion code */
441 _bfd_vms_output_byte (abfd, 0); /* fill byte */
442
443 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
444 {
445 asection *section;
446
447 section = bfd_get_section_by_name (abfd, ".link");
448 if (section == 0)
449 {
450 bfd_set_error (bfd_error_nonrepresentable_section);
451 return -1;
452 }
453 _bfd_vms_output_short (abfd, 0);
454 _bfd_vms_output_long (abfd, (unsigned long) (section->index));
455 _bfd_vms_output_long (abfd,
456 (unsigned long) bfd_get_start_address (abfd));
457 _bfd_vms_output_long (abfd, 0);
458 }
459
460 _bfd_vms_output_end (abfd);
461 return 0;
462 }
This page took 0.047608 seconds and 5 git commands to generate.