Commit | Line | Data |
---|---|---|
8696b2db | 1 | /* evax-emh.c -- BFD back-end for ALPHA EVAX (openVMS/Alpha) files. |
980381af | 2 | Copyright 1996, 1997, 1998 Free Software Foundation, Inc. |
c3d8e071 ILT |
3 | |
4 | EMH record handling functions | |
5 | and | |
6 | EEOM record handling functions | |
7 | ||
8696b2db | 8 | Written by Klaus K"ampf (kkaempf@progis.de) |
c3d8e071 ILT |
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 | ||
8696b2db | 25 | #include <ctype.h> |
c3d8e071 ILT |
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 | ||
bf53bd9f ILT |
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 | |
bf53bd9f ILT |
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; | |
412222d9 | 160 | SYS$ASCTIM (0, &Descriptor, 0, 0); |
bf53bd9f ILT |
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 | ||
c3d8e071 ILT |
171 | /* write object header for bfd abfd */ |
172 | ||
173 | int | |
174 | _bfd_evax_write_emh (abfd) | |
175 | bfd *abfd; | |
176 | { | |
bf53bd9f ILT |
177 | asymbol *symbol; |
178 | int symnum; | |
179 | int had_case = 0; | |
180 | int had_file = 0; | |
181 | ||
c3d8e071 ILT |
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); | |
bf53bd9f ILT |
196 | |
197 | if (bfd_get_filename (abfd) != 0) | |
8696b2db ILT |
198 | { |
199 | /* strip path and suffix information */ | |
200 | ||
201 | char *fname, *fout, *fptr; | |
202 | ||
f3fb08f6 ILT |
203 | fptr = bfd_get_filename (abfd); |
204 | fname = (char *) alloca (strlen (fptr) + 1); | |
205 | strcpy (fname, fptr); | |
8696b2db ILT |
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); | |
8696b2db | 232 | } |
c3d8e071 ILT |
233 | else |
234 | _bfd_evax_output_counted (abfd, "NONAME"); | |
bf53bd9f | 235 | |
c3d8e071 | 236 | _bfd_evax_output_counted (abfd, BFD_VERSION); |
bf53bd9f | 237 | _bfd_evax_output_dump (abfd, get_vms_time_string (), 17); |
c3d8e071 ILT |
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); | |
bf53bd9f ILT |
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'; | |
bf53bd9f ILT |
263 | |
264 | if (had_file) | |
265 | break; | |
266 | had_case = 1; | |
267 | continue; | |
268 | } | |
269 | ||
412222d9 | 270 | _bfd_evax_output_dump (abfd, (unsigned char *)symbol->name, strlen (symbol->name)); |
bf53bd9f ILT |
271 | if (had_case) |
272 | break; | |
273 | had_file = 1; | |
274 | } | |
275 | } | |
276 | ||
277 | if (symnum == abfd->symcount) | |
412222d9 | 278 | _bfd_evax_output_dump (abfd, (unsigned char *)"noname", 6); |
bf53bd9f | 279 | |
c3d8e071 ILT |
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, |