add relocation code and ELF docs
[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 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 <stdio.h>
26 #include <ctype.h>
27
28 #include "bfd.h"
29 #include "sysdep.h"
30 #include "bfdlink.h"
31 #include "libbfd.h"
32
33 #include "evax.h"
34
35 /*---------------------------------------------------------------------------*/
36
37
38 /* Read & process emh record
39 return 0 on success, -1 on error */
40
41 int
42 _bfd_evax_slurp_emh (abfd)
43 bfd *abfd;
44 {
45 unsigned char *ptr;
46 unsigned char *evax_rec;
47
48 evax_rec = PRIV(evax_rec);
49
50 #if EVAX_DEBUG
51 evax_debug(2, "EMH\n");
52 #endif
53
54 switch (bfd_getl16 (evax_rec + 4))
55 {
56
57 case EMH_S_C_MHD:
58 /*
59 * module header
60 */
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);
70 ptr += *ptr + 1;
71 PRIV(emh_data).emh_t_date =
72 _bfd_evax_save_sized_string ((char *)ptr, 17);
73
74 break;
75
76 case EMH_S_C_LNM:
77 /*
78 *
79 */
80 PRIV(emh_data).emh_c_lnm =
81 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
82 break;
83
84 case EMH_S_C_SRC:
85 /*
86 *
87 */
88 PRIV(emh_data).emh_c_src =
89 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
90 break;
91
92 case EMH_S_C_TTL:
93 /*
94 *
95 */
96 PRIV(emh_data).emh_c_ttl =
97 _bfd_evax_save_sized_string ((char *)evax_rec, PRIV(rec_length-6));
98 break;
99
100 case EMH_S_C_CPR:
101 /*
102 *
103 */
104 break;
105
106 case EMH_S_C_MTC:
107 /*
108 *
109 */
110 break;
111
112 case EMH_S_C_GTX:
113 /*
114 *
115 */
116 break;
117
118 default:
119 bfd_set_error (bfd_error_wrong_format);
120 return -1;
121
122 } /* switch */
123
124 return 0;
125 }
126
127
128 /*-----------------------------------------------------------------------------*/
129 /* Output routines. */
130
131
132 /* Manufacure a VMS like time on a unix based system.
133 stolen from obj-vms.c */
134
135 static unsigned char *
136 get_vms_time_string ()
137 {
138 static unsigned char tbuf[18];
139 #ifndef VMS
140 #include <sys/types.h>
141 #include <time.h>
142
143 char *pnt;
144 time_t timeb;
145 time (&timeb);
146 pnt = ctime (&timeb);
147 pnt[3] = 0;
148 pnt[7] = 0;
149 pnt[10] = 0;
150 pnt[16] = 0;
151 pnt[24] = 0;
152 sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
153 #else
154 #include <starlet.h>
155 struct
156 {
157 int Size;
158 unsigned char *Ptr;
159 } Descriptor;
160 Descriptor.Size = 17;
161 Descriptor.Ptr = tbuf;
162 SYS$ASCTIM (0, &Descriptor, 0, 0);
163 #endif /* not VMS */
164
165 #if EVAX_DEBUG
166 evax_debug (6, "vmstimestring:'%s'\n", tbuf);
167 #endif
168
169 return tbuf;
170 }
171
172
173 /* write object header for bfd abfd */
174
175 int
176 _bfd_evax_write_emh (abfd)
177 bfd *abfd;
178 {
179 asymbol *symbol;
180 int symnum;
181 int had_case = 0;
182 int had_file = 0;
183
184
185 #if EVAX_DEBUG
186 evax_debug (2, "evax_write_emh(%p)\n", abfd);
187 #endif
188
189 _bfd_evax_output_alignment (abfd, 2);
190
191 /* MHD */
192
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);
198
199 if (bfd_get_filename (abfd) != 0)
200 {
201 /* strip path and suffix information */
202
203 char *fname, *fout, *fptr;
204
205 fptr = bfd_get_filename (abfd);
206 fname = (char *) alloca (strlen (fptr) + 1);
207 strcpy (fname, fptr);
208 fout = strrchr (fname, ']');
209 if (fout == 0)
210 fout = strchr (fname, ':');
211 if (fout != 0)
212 fout++;
213 else
214 fout = fname;
215
216 /* strip .obj suffix */
217
218 fptr = strrchr (fname, '.');
219 if ((fptr != 0)
220 && (strcasecmp (fptr, ".OBJ") == 0))
221 *fptr = 0;
222
223 fptr = fout;
224 while (*fptr != 0)
225 {
226 if (islower (*fptr))
227 *fptr = toupper (*fptr);
228 fptr++;
229 if ((*fptr == ';')
230 || ((fptr - fout) > 31))
231 *fptr = 0;
232 }
233 _bfd_evax_output_counted (abfd, fout);
234 }
235 else
236 _bfd_evax_output_counted (abfd, "NONAME");
237
238 _bfd_evax_output_counted (abfd, BFD_VERSION);
239 _bfd_evax_output_dump (abfd, get_vms_time_string (), 17);
240 _bfd_evax_output_fill (abfd, 0, 17);
241 _bfd_evax_output_flush (abfd);
242
243 /* LMN */
244
245 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_LNM);
246 _bfd_evax_output_dump (abfd, (unsigned char *)"GAS proGIS", 10);
247 _bfd_evax_output_flush (abfd);
248
249 /* SRC */
250
251 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC);
252
253 for (symnum = 0; symnum < abfd->symcount; symnum++)
254 {
255 symbol = abfd->outsymbols[symnum];
256
257 if (symbol->flags & BSF_FILE)
258 {
259 char *s;
260
261 if (strncmp ((char *)symbol->name, "<CASE:", 6) == 0)
262 {
263 PRIV(flag_hash_long_names) = symbol->name[6] - '0';
264 PRIV(flag_show_after_trunc) = symbol->name[7] - '0';
265
266 if (had_file)
267 break;
268 had_case = 1;
269 continue;
270 }
271
272 _bfd_evax_output_dump (abfd, (unsigned char *)symbol->name, strlen (symbol->name));
273 if (had_case)
274 break;
275 had_file = 1;
276 }
277 }
278
279 if (symnum == abfd->symcount)
280 _bfd_evax_output_dump (abfd, (unsigned char *)"noname", 6);
281
282 _bfd_evax_output_flush (abfd);
283
284 /* TTL */
285
286 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_TTL);
287 _bfd_evax_output_dump (abfd, (unsigned char *)"TTL", 3);
288 _bfd_evax_output_flush (abfd);
289
290 /* CPR */
291
292 _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_CPR);
293 _bfd_evax_output_dump (abfd,
294 (unsigned char *)"GNU BFD ported by Klaus Kämpf 1994-1996",
295 39);
296 _bfd_evax_output_flush (abfd);
297
298 return 0;
299 }
300
301 /*-----------------------------------------------------------------------------*/
302
303 /* Process EEOM record
304 return 0 on success, -1 on error */
305
306 int
307 _bfd_evax_slurp_eeom (abfd)
308 bfd *abfd;
309 {
310 unsigned char *evax_rec;
311
312 #if EVAX_DEBUG
313 evax_debug(2, "EEOM\n");
314 #endif
315
316 evax_rec = PRIV(evax_rec);
317
318 PRIV(eeom_data).eeom_l_total_lps = bfd_getl32 (evax_rec + 4);
319 PRIV(eeom_data).eeom_b_comcod = *(evax_rec + 8);
320 if (PRIV(eeom_data).eeom_b_comcod > 1)
321 {
322 (*_bfd_error_handler) (_("Object module NOT error-free !\n"));
323 bfd_set_error (bfd_error_bad_value);
324 return -1;
325 }
326 PRIV(eeom_data).eeom_has_transfer = false;
327 if (PRIV(rec_size) > 10)
328 {
329 PRIV(eeom_data).eeom_has_transfer = true;
330 PRIV(eeom_data).eeom_b_tfrflg = *(evax_rec + 9);
331 PRIV(eeom_data).eeom_l_psindx = bfd_getl32 (evax_rec + 12);
332 PRIV(eeom_data).eeom_l_tfradr = bfd_getl32 (evax_rec + 16);
333
334 abfd->start_address = PRIV(eeom_data).eeom_l_tfradr;
335 }
336 return 0;
337 }
338
339
340 /* Write eom record for bfd abfd */
341
342 int
343 _bfd_evax_write_eeom (abfd)
344 bfd *abfd;
345 {
346 #if EVAX_DEBUG
347 evax_debug (2, "evax_write_eeom(%p)\n", abfd);
348 #endif
349
350 _bfd_evax_output_begin (abfd,EOBJ_S_C_EEOM, -1);
351 _bfd_evax_output_long (abfd, (unsigned long)(PRIV(evax_linkage_index) >> 1));
352 _bfd_evax_output_byte (abfd, 0); /* completion code */
353 _bfd_evax_output_byte (abfd, 0); /* fill byte */
354
355 if (bfd_get_start_address (abfd) != (bfd_vma)-1)
356 {
357 asection *section;
358
359 section = bfd_get_section_by_name (abfd, ".link");
360 if (section == 0)
361 {
362 bfd_set_error (bfd_error_nonrepresentable_section);
363 return -1;
364 }
365 _bfd_evax_output_short (abfd, 0);
366 _bfd_evax_output_long (abfd, (unsigned long)(section->index));
367 _bfd_evax_output_long (abfd,
368 (unsigned long) bfd_get_start_address (abfd));
369 _bfd_evax_output_long (abfd, 0);
370 }
371
372 _bfd_evax_output_end (abfd);
373 return 0;
374 }
This page took 0.132531 seconds and 4 git commands to generate.