If sysdep.h includes a header file, don't include it again:
[deliverable/binutils-gdb.git] / bfd / evax-emh.c
1 /* evax-emh.c -- BFD back-end for ALPHA EVAX (openVMS/Alpha) files.
2 Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
3
4 EMH record handling functions
5 and
6 EEOM record handling functions
7
8 Written by Klaus K"ampf (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 <ctype.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 <time.h>
140
141 char *pnt;
142 time_t timeb;
143 time (&timeb);
144 pnt = ctime (&timeb);
145 pnt[3] = 0;
146 pnt[7] = 0;
147 pnt[10] = 0;
148 pnt[16] = 0;
149 pnt[24] = 0;
150 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
151 #else
152 #include <starlet.h>
153 struct
154 {
155 int Size;
156 unsigned char *Ptr;
157 } Descriptor;
158 Descriptor.Size = 17;
159 Descriptor.Ptr = tbuf;
160 SYS$ASCTIM (0, &Descriptor, 0, 0);
161 #endif /* not VMS */
162
163 #if EVAX_DEBUG
164 evax_debug (6, "vmstimestring:'%s'\n", tbuf);
165 #endif
166
167 return tbuf;
168 }
169
170
171 /* write object header for bfd abfd */
172
173 int
174 _bfd_evax_write_emh (abfd)
175 bfd *abfd;
176 {
177 asymbol *symbol;
178 int symnum;
179 int had_case = 0;
180 int had_file = 0;
181
182
183 #if EVAX_DEBUG
184 evax_debug (2, "evax_write_emh(%p)\n", abfd);
185 #endif
186
187 _bfd_evax_output_alignment (abfd, 2);
188
189 /* MHD */
190
191 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_MHD);
192 _bfd_evax_output_short (abfd, EOBJ_S_C_STRLVL);
193 _bfd_evax_output_long (abfd, 0);
194 _bfd_evax_output_long (abfd, 0);
195 _bfd_evax_output_long (abfd, MAX_OUTREC_SIZE);
196
197 if (bfd_get_filename (abfd) != 0)
198 {
199 /* strip path and suffix information */
200
201 char *fname, *fout, *fptr;
202
203 fptr = bfd_get_filename (abfd);
204 fname = (char *) alloca (strlen (fptr) + 1);
205 strcpy (fname, fptr);
206 fout = strrchr (fname, ']');
207 if (fout == 0)
208 fout = strchr (fname, ':');
209 if (fout != 0)
210 fout++;
211 else
212 fout = fname;
213
214 /* strip .obj suffix */
215
216 fptr = strrchr (fname, '.');
217 if ((fptr != 0)
218 && (strcasecmp (fptr, ".OBJ") == 0))
219 *fptr = 0;
220
221 fptr = fout;
222 while (*fptr != 0)
223 {
224 if (islower (*fptr))
225 *fptr = toupper (*fptr);
226 fptr++;
227 if ((*fptr == ';')
228 || ((fptr - fout) > 31))
229 *fptr = 0;
230 }
231 _bfd_evax_output_counted (abfd, fout);
232 }
233 else
234 _bfd_evax_output_counted (abfd, "NONAME");
235
236 _bfd_evax_output_counted (abfd, BFD_VERSION);
237 _bfd_evax_output_dump (abfd, get_vms_time_string (), 17);
238 _bfd_evax_output_fill (abfd, 0, 17);
239 _bfd_evax_output_flush (abfd);
240
241 /* LMN */
242
243 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
244 _bfd_evax_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
245 _bfd_evax_output_flush (abfd);
246
247 /* SRC */
248
249 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
250
251 for (symnum = 0; symnum < abfd->symcount; symnum++)
252 {
253 symbol = abfd->outsymbols[symnum];
254
255 if (symbol->flags & BSF_FILE)
256 {
257 char *s;
258
259 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
260 {
261 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
262 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
263
264 if (had_file)
265 break;
266 had_case = 1;
267 continue;
268 }
269
270 _bfd_evax_output_dump (abfd, (unsigned char *)symbol->name, strlen (symbol->name));
271 if (had_case)
272 break;
273 had_file = 1;
274 }
275 }
276
277 if (symnum == abfd->symcount)
278 _bfd_evax_output_dump (abfd, (unsigned char *)"noname", 6);
279
280 _bfd_evax_output_flush (abfd);
281
282 /* TTL */
283
284 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
285 _bfd_evax_output_dump (abfd, (unsigned char *)"TTL", 3);
286 _bfd_evax_output_flush (abfd);
287
288 /* CPR */
289
290 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
291 _bfd_evax_output_dump (abfd,
292 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
293 39);
294 _bfd_evax_output_flush (abfd);
295
296 return 0;
297 }
298
299 /*-----------------------------------------------------------------------------*/
300
301 /* Process EEOM record
302 return 0 on success, -1 on error */
303
304 int
305 _bfd_evax_slurp_eeom (abfd)
306 bfd *abfd;
307 {
308 unsigned char *evax_rec;
309
310 #if EVAX_DEBUG
311 evax_debug(2, "EEOM\n");
312 #endif
313
314 evax_rec = PRIV(evax_rec);
315
316 PRIV(eeom_data).eeom_l_total_lps = bfd_getl32 (evax_rec + 4);
317 PRIV(eeom_data).eeom_b_comcod = *(evax_rec + 8);
318 if (PRIV(eeom_data).eeom_b_comcod > 1)
319 {
320 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
321 bfd_set_error (bfd_error_bad_value);
322 return -1;
323 }
324 PRIV(eeom_data).eeom_has_transfer = false;
325 if (PRIV(rec_size) > 10)
326 {
327 PRIV(eeom_data).eeom_has_transfer = true;
328 PRIV(eeom_data).eeom_b_tfrflg = *(evax_rec + 9);
329 PRIV(eeom_data).eeom_l_psindx = bfd_getl32 (evax_rec + 12);
330 PRIV(eeom_data).eeom_l_tfradr = bfd_getl32 (evax_rec + 16);
331
332 abfd->start_address = PRIV(eeom_data).eeom_l_tfradr;
333 }
334 return 0;
335 }
336
337
338 /* Write eom record for bfd abfd */
339
340 int
341 _bfd_evax_write_eeom (abfd)
342 bfd *abfd;
343 {
344 #if EVAX_DEBUG
345 evax_debug (2, "evax_write_eeom(%p)\n", abfd);
346 #endif
347
348 _bfd_evax_output_begin (abfd,EOBJ_S_C_EEOM, -1);
349 _bfd_evax_output_long (abfd, (unsigned long)(PRIV(evax_linkage_index) >> 1));
350 _bfd_evax_output_byte (abfd, 0); /* completion code */
351 _bfd_evax_output_byte (abfd, 0); /* fill byte */
352
353 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
354 {
355 asection *section;
356
357 section = bfd_get_section_by_name (abfd, ".link");
358 if (section == 0)
359 {
360 bfd_set_error (bfd_error_nonrepresentable_section);
361 return -1;
362 }
363 _bfd_evax_output_short (abfd, 0);
364 _bfd_evax_output_long (abfd, (unsigned long)(section->index));
365 _bfd_evax_output_long (abfd,
366 (unsigned long) bfd_get_start_address (abfd));
367 _bfd_evax_output_long (abfd, 0);
368 }
369
370 _bfd_evax_output_end (abfd);
371 return 0;
372 }
This page took 0.048329 seconds and 4 git commands to generate.