1 /* evax-emh.c -- BFD back-end for ALPHA EVAX (openVMS/Alpha) files.
2 Copyright 1996, 1997 Free Software Foundation, Inc.
4 EMH record handling functions
6 EEOM record handling functions
9 of proGIS Softwareentwicklung, Aachen, Germany
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.
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.
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. */
35 /*---------------------------------------------------------------------------*/
38 /* Read & process emh record
39 return 0 on success, -1 on error */
42 _bfd_evax_slurp_emh (abfd)
46 unsigned char *evax_rec;
48 evax_rec = PRIV(evax_rec);
51 evax_debug(2, "EMH\n");
54 switch (bfd_getl16 (evax_rec + 4))
61 PRIV(emh_data).emh_b_strlvl = evax_rec[6];
62 PRIV(emh_data).emh_l_arch1 = bfd_getl32 (evax_rec + 8);
63 PRIV(emh_data).emh_l_arch2 = bfd_getl32 (evax_rec + 12);
64 PRIV(emh_data).emh_l_recsiz = bfd_getl32 (evax_rec + 16);
65 PRIV(emh_data).emh_t_name =
66 _bfd_evax_save_counted_string ((char *)evax_rec + 20);
67 ptr = evax_rec + 20 + evax_rec[20] + 1;
68 PRIV(emh_data).emh_t_version =
69 _bfd_evax_save_counted_string ((char *)ptr);
71 PRIV(emh_data).emh_t_date =
72 _bfd_evax_save_sized_string ((char *)ptr, 17);
80 PRIV(emh_data).emh_c_lnm =
81 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
88 PRIV(emh_data).emh_c_src =
89 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
96 PRIV(emh_data).emh_c_ttl =
97 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
119 bfd_set_error (bfd_error_wrong_format);
128 /*-----------------------------------------------------------------------------*/
129 /* Output routines. */
132 /* Manufacure a VMS like time on a unix based system.
133 stolen from obj-vms.c */
135 static unsigned char *
136 get_vms_time_string ()
138 static unsigned char tbuf[18];
140 #include <sys/types.h>
146 pnt = ctime (&timeb);
152 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
160 Descriptor.Size = 17;
161 Descriptor.Ptr = tbuf;
162 sys$asctim (0, &Descriptor, 0, 0);
166 evax_debug (6, "vmstimestring:'%s'\n", tbuf);
173 /* write object header for bfd abfd */
176 _bfd_evax_write_emh (abfd)
186 evax_debug (2, "evax_write_emh(%p)\n", abfd);
189 _bfd_evax_output_alignment (abfd, 2);
193 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
194 _bfd_evax_output_short (abfd, EOBJ_S_C_STRLVL);
195 _bfd_evax_output_long (abfd, 0);
196 _bfd_evax_output_long (abfd, 0);
197 _bfd_evax_output_long (abfd, MAX_OUTREC_SIZE);
199 if (bfd_get_filename (abfd) != 0)
201 /* strip path and suffix information */
203 char *fname, *fout, *fptr;
205 fname = strdup (bfd_get_filename (abfd));
208 bfd_set_error (bfd_error_no_memory);
211 fout = strrchr (fname, ']');
213 fout = strchr (fname, ':');
219 /* strip .obj suffix */
221 fptr = strrchr (fname, '.');
223 && (strcasecmp (fptr, ".OBJ") == 0))
230 *fptr = toupper (*fptr);
233 || ((fptr - fout) > 31))
236 _bfd_evax_output_counted (abfd, fout);
240 _bfd_evax_output_counted (abfd, "NONAME");
242 _bfd_evax_output_counted (abfd, BFD_VERSION);
243 _bfd_evax_output_dump (abfd, get_vms_time_string (), 17);
244 _bfd_evax_output_fill (abfd, 0, 17);
245 _bfd_evax_output_flush (abfd);
249 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
250 _bfd_evax_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
251 _bfd_evax_output_flush (abfd);
255 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
257 for (symnum = 0; symnum < abfd->symcount; symnum++)
259 symbol = abfd->outsymbols[symnum];
261 if (symbol->flags & BSF_FILE)
265 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
267 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
268 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
276 _bfd_evax_output_dump (abfd, (char *)symbol->name, strlen (symbol->name));
283 if (symnum == abfd->symcount)
284 _bfd_evax_output_dump (abfd, "noname", 6);
286 _bfd_evax_output_flush (abfd);
290 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
291 _bfd_evax_output_dump (abfd, (unsigned char *)"TTL", 3);
292 _bfd_evax_output_flush (abfd);
296 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
297 _bfd_evax_output_dump (abfd,
298 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
300 _bfd_evax_output_flush (abfd);
305 /*-----------------------------------------------------------------------------*/
307 /* Process EEOM record
308 return 0 on success, -1 on error */
311 _bfd_evax_slurp_eeom (abfd)
314 unsigned char *evax_rec;
317 evax_debug(2, "EEOM\n");
320 evax_rec = PRIV(evax_rec);
322 PRIV(eeom_data).eeom_l_total_lps = bfd_getl32 (evax_rec + 4);
323 PRIV(eeom_data).eeom_b_comcod = *(evax_rec + 8);
324 if (PRIV(eeom_data).eeom_b_comcod > 1)
326 (*_bfd_error_handler) ("Object module NOT error-free !\n");
327 bfd_set_error (bfd_error_bad_value);
330 PRIV(eeom_data).eeom_has_transfer = false;
331 if (PRIV(rec_size) > 10)
333 PRIV(eeom_data).eeom_has_transfer = true;
334 PRIV(eeom_data).eeom_b_tfrflg = *(evax_rec + 9);
335 PRIV(eeom_data).eeom_l_psindx = bfd_getl32 (evax_rec + 12);
336 PRIV(eeom_data).eeom_l_tfradr = bfd_getl32 (evax_rec + 16);
338 abfd->start_address = PRIV(eeom_data).eeom_l_tfradr;
344 /* Write eom record for bfd abfd */
347 _bfd_evax_write_eeom (abfd)
351 evax_debug (2, "evax_write_eeom(%p)\n", abfd);
354 _bfd_evax_output_begin (abfd,EOBJ_S_C_EEOM, -1);
355 _bfd_evax_output_long (abfd, (unsigned long)(PRIV(evax_linkage_index) >> 1));
356 _bfd_evax_output_byte (abfd, 0); /* completion code */
357 _bfd_evax_output_byte (abfd, 0); /* fill byte */
359 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
363 section = bfd_get_section_by_name (abfd, ".link");
366 bfd_set_error (bfd_error_nonrepresentable_section);
369 _bfd_evax_output_short (abfd, 0);
370 _bfd_evax_output_long (abfd, (unsigned long)(section->index));
371 _bfd_evax_output_long (abfd,
372 (unsigned long) bfd_get_start_address (abfd));
373 _bfd_evax_output_long (abfd, 0);
376 _bfd_evax_output_end (abfd);