source: branches/libc-0.6/src/binutils/bfd/vms-tir.c

Last change on this file was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 57.6 KB
Line 
1/* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
5
6 TIR record handling functions
7 ETIR record handling functions
8
9 go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
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/* The following type abbreviations are used:
29
30 cs counted string (ascii string with length byte)
31 by byte (1 byte)
32 sh short (2 byte, 16 bit)
33 lw longword (4 byte, 32 bit)
34 qw quadword (8 byte, 64 bit)
35 da data stream */
36
37#include "bfd.h"
38#include "sysdep.h"
39#include "bfdlink.h"
40#include "libbfd.h"
41
42#include "vms.h"
43
44static void image_set_ptr
45 PARAMS ((bfd *abfd, int psect, uquad offset));
46static void image_inc_ptr
47 PARAMS ((bfd *abfd, uquad offset));
48static void image_dump
49 PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
50static void image_write_b
51 PARAMS ((bfd *abfd, unsigned int value));
52static void image_write_w
53 PARAMS ((bfd *abfd, unsigned int value));
54static void image_write_l
55 PARAMS ((bfd *abfd, unsigned long value));
56static void image_write_q
57 PARAMS ((bfd *abfd, uquad value));
58static int check_section
59 PARAMS ((bfd *, int));
60static bfd_boolean etir_sta
61 PARAMS ((bfd *, int, unsigned char *));
62static bfd_boolean etir_sto
63 PARAMS ((bfd *, int, unsigned char *));
64static bfd_boolean etir_opr
65 PARAMS ((bfd *, int, unsigned char *));
66static bfd_boolean etir_ctl
67 PARAMS ((bfd *, int, unsigned char *));
68static bfd_boolean etir_stc
69 PARAMS ((bfd *, int, unsigned char *));
70static asection *new_section
71 PARAMS ((bfd *, int));
72static int alloc_section
73 PARAMS ((bfd *, unsigned int));
74static int etir_cmd
75 PARAMS ((bfd *, int, unsigned char *));
76static int analyze_tir
77 PARAMS ((bfd *, unsigned char *, unsigned int));
78static int analyze_etir
79 PARAMS ((bfd *, unsigned char *, unsigned int));
80static unsigned char * tir_opr
81 PARAMS ((bfd *, unsigned char *));
82static const char * tir_cmd_name
83 PARAMS ((int));
84static const char * cmd_name
85 PARAMS ((int));
86
87
88
89static int
90check_section (abfd, size)
91 bfd *abfd;
92 int size;
93{
94 bfd_size_type offset;
95
96 offset = PRIV (image_ptr) - PRIV (image_section)->contents;
97 if (offset + size > PRIV (image_section)->_raw_size)
98 {
99 PRIV (image_section)->contents
100 = bfd_realloc (PRIV (image_section)->contents, offset + size);
101 if (PRIV (image_section)->contents == 0)
102 {
103 (*_bfd_error_handler) (_("No Mem !"));
104 return -1;
105 }
106 PRIV (image_section)->_raw_size = offset + size;
107 PRIV (image_ptr) = PRIV (image_section)->contents + offset;
108 }
109
110 return 0;
111}
112
113/* Routines to fill sections contents during tir/etir read. */
114
115/* Initialize image buffer pointer to be filled. */
116
117static void
118image_set_ptr (abfd, psect, offset)
119 bfd *abfd;
120 int psect;
121 uquad offset;
122{
123#if VMS_DEBUG
124 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
125 psect, PRIV (sections)[psect]->name, offset);
126#endif
127
128 PRIV (image_ptr) = PRIV (sections)[psect]->contents + offset;
129 PRIV (image_section) = PRIV (sections)[psect];
130 return;
131}
132
133/* Increment image buffer pointer by offset. */
134
135static void
136image_inc_ptr (abfd, offset)
137 bfd *abfd;
138 uquad offset;
139{
140#if VMS_DEBUG
141 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
142#endif
143
144 PRIV (image_ptr) += offset;
145
146 return;
147}
148
149/* Dump multiple bytes to section image. */
150
151static void
152image_dump (abfd, ptr, size, offset)
153 bfd *abfd;
154 unsigned char *ptr;
155 int size;
156 int offset ATTRIBUTE_UNUSED;
157{
158#if VMS_DEBUG
159 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size,
160 PRIV (image_ptr));
161 _bfd_hexdump (9, ptr, size, offset);
162#endif
163
164 if (PRIV (is_vax) && check_section (abfd, size))
165 return;
166
167 while (size-- > 0)
168 *PRIV (image_ptr)++ = *ptr++;
169 return;
170}
171
172/* Write byte to section image. */
173
174static void
175image_write_b (abfd, value)
176 bfd *abfd;
177 unsigned int value;
178{
179#if VMS_DEBUG
180 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value);
181#endif
182
183 if (PRIV (is_vax) && check_section (abfd, 1))
184 return;
185
186 *PRIV (image_ptr)++ = (value & 0xff);
187 return;
188}
189
190/* Write 2-byte word to image. */
191
192static void
193image_write_w (abfd, value)
194 bfd *abfd;
195 unsigned int value;
196{
197#if VMS_DEBUG
198 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value);
199#endif
200
201 if (PRIV (is_vax) && check_section (abfd, 2))
202 return;
203
204 bfd_putl16 ((bfd_vma) value, PRIV (image_ptr));
205 PRIV (image_ptr) += 2;
206
207 return;
208}
209
210/* Write 4-byte long to image. */
211
212static void
213image_write_l (abfd, value)
214 bfd *abfd;
215 unsigned long value;
216{
217#if VMS_DEBUG
218 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
219#endif
220
221 if (PRIV (is_vax) && check_section (abfd, 4))
222 return;
223
224 bfd_putl32 ((bfd_vma) value, PRIV (image_ptr));
225 PRIV (image_ptr) += 4;
226
227 return;
228}
229
230/* Write 8-byte quad to image. */
231
232static void
233image_write_q (abfd, value)
234 bfd *abfd;
235 uquad value;
236{
237#if VMS_DEBUG
238 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
239#endif
240
241 if (PRIV (is_vax) && check_section (abfd, 8))
242 return;
243
244 bfd_putl64 (value, PRIV (image_ptr));
245 PRIV (image_ptr) += 8;
246
247 return;
248}
249
250
251static const char *
252cmd_name (cmd)
253 int cmd;
254{
255 switch (cmd)
256 {
257 case ETIR_S_C_STA_GBL: return "ETIR_S_C_STA_GBL";
258 case ETIR_S_C_STA_PQ: return "ETIR_S_C_STA_PQ";
259 case ETIR_S_C_STA_LI: return "ETIR_S_C_STA_LI";
260 case ETIR_S_C_STA_MOD: return "ETIR_S_C_STA_MOD";
261 case ETIR_S_C_STA_CKARG: return "ETIR_S_C_STA_CKARG";
262 case ETIR_S_C_STO_B: return "ETIR_S_C_STO_B";
263 case ETIR_S_C_STO_W: return "ETIR_S_C_STO_W";
264 case ETIR_S_C_STO_GBL: return "ETIR_S_C_STO_GBL";
265 case ETIR_S_C_STO_CA: return "ETIR_S_C_STO_CA";
266 case ETIR_S_C_STO_RB: return "ETIR_S_C_STO_RB";
267 case ETIR_S_C_STO_AB: return "ETIR_S_C_STO_AB";
268 case ETIR_S_C_STO_GBL_LW: return "ETIR_S_C_STO_GBL_LW";
269 case ETIR_S_C_STO_LP_PSB: return "ETIR_S_C_STO_LP_PSB";
270 case ETIR_S_C_STO_HINT_GBL: return "ETIR_S_C_STO_HINT_GBL";
271 case ETIR_S_C_STO_HINT_PS: return "ETIR_S_C_STO_HINT_PS";
272 case ETIR_S_C_OPR_INSV: return "ETIR_S_C_OPR_INSV";
273 case ETIR_S_C_OPR_USH: return "ETIR_S_C_OPR_USH";
274 case ETIR_S_C_OPR_ROT: return "ETIR_S_C_OPR_ROT";
275 case ETIR_S_C_OPR_REDEF: return "ETIR_S_C_OPR_REDEF";
276 case ETIR_S_C_OPR_DFLIT: return "ETIR_S_C_OPR_DFLIT";
277 case ETIR_S_C_STC_LP: return "ETIR_S_C_STC_LP";
278 case ETIR_S_C_STC_GBL: return "ETIR_S_C_STC_GBL";
279 case ETIR_S_C_STC_GCA: return "ETIR_S_C_STC_GCA";
280 case ETIR_S_C_STC_PS: return "ETIR_S_C_STC_PS";
281 case ETIR_S_C_STC_NBH_PS: return "ETIR_S_C_STC_NBH_PS";
282 case ETIR_S_C_STC_NOP_GBL: return "ETIR_S_C_STC_NOP_GBL";
283 case ETIR_S_C_STC_NOP_PS: return "ETIR_S_C_STC_NOP_PS";
284 case ETIR_S_C_STC_BSR_GBL: return "ETIR_S_C_STC_BSR_GBL";
285 case ETIR_S_C_STC_BSR_PS: return "ETIR_S_C_STC_BSR_PS";
286 case ETIR_S_C_STC_LDA_GBL: return "ETIR_S_C_STC_LDA_GBL";
287 case ETIR_S_C_STC_LDA_PS: return "ETIR_S_C_STC_LDA_PS";
288 case ETIR_S_C_STC_BOH_GBL: return "ETIR_S_C_STC_BOH_GBL";
289 case ETIR_S_C_STC_BOH_PS: return "ETIR_S_C_STC_BOH_PS";
290 case ETIR_S_C_STC_NBH_GBL: return "ETIR_S_C_STC_NBH_GBL";
291
292 default:
293 /* These names have not yet been added to this switch statement. */
294 abort ();
295 }
296}
297#define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
298
299/* etir_sta
300
301 vms stack commands
302
303 handle sta_xxx commands in etir section
304 ptr points to data area in record
305
306 see table B-8 of the openVMS linker manual. */
307
308static bfd_boolean
309etir_sta (abfd, cmd, ptr)
310 bfd *abfd;
311 int cmd;
312 unsigned char *ptr;
313{
314
315#if VMS_DEBUG
316 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
317 _bfd_hexdump (8, ptr, 16, (int) ptr);
318#endif
319
320 switch (cmd)
321 {
322 /* stack */
323
324 /* stack global
325 arg: cs symbol name
326
327 stack 32 bit value of symbol (high bits set to 0) */
328
329 case ETIR_S_C_STA_GBL:
330 {
331 char *name;
332 vms_symbol_entry *entry;
333
334 name = _bfd_vms_save_counted_string (ptr);
335 entry = (vms_symbol_entry *)
336 bfd_hash_lookup (PRIV (vms_symbol_table), name, FALSE, FALSE);
337 if (entry == (vms_symbol_entry *) NULL)
338 {
339#if VMS_DEBUG
340 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
341 cmd_name (cmd), name);
342#endif
343 _bfd_vms_push (abfd, (uquad) 0, -1);
344 }
345 else
346 {
347 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
348 }
349 }
350 break;
351
352 /* stack longword
353 arg: lw value
354
355 stack 32 bit value, sign extend to 64 bit */
356
357 case ETIR_S_C_STA_LW:
358 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
359 break;
360
361 /* stack global
362 arg: qw value
363
364 stack 64 bit value of symbol */
365
366 case ETIR_S_C_STA_QW:
367 _bfd_vms_push (abfd, (uquad) bfd_getl64 (ptr), -1);
368 break;
369
370 /* stack psect base plus quadword offset
371 arg: lw section index
372 qw signed quadword offset (low 32 bits)
373
374 stack qw argument and section index
375 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
376
377 case ETIR_S_C_STA_PQ:
378 {
379 uquad dummy;
380 unsigned int psect;
381
382 psect = bfd_getl32 (ptr);
383 if (psect >= PRIV (section_count))
384 {
385 (*_bfd_error_handler) (_("bad section index in %s"),
386 cmd_name (cmd));
387 bfd_set_error (bfd_error_bad_value);
388 return FALSE;
389 }
390 dummy = bfd_getl64 (ptr+4);
391 _bfd_vms_push (abfd, dummy, (int) psect);
392 }
393 break;
394
395 case ETIR_S_C_STA_LI:
396 case ETIR_S_C_STA_MOD:
397 case ETIR_S_C_STA_CKARG:
398 (*_bfd_error_handler) (_("unsupported STA cmd %s"), cmd_name (cmd));
399 return FALSE;
400 break;
401
402 default:
403 (*_bfd_error_handler) (_("reserved STA cmd %d"), cmd);
404 return FALSE;
405 break;
406 }
407#if VMS_DEBUG
408 _bfd_vms_debug (5, "etir_sta true\n");
409#endif
410 return TRUE;
411}
412
413/*
414 etir_sto
415
416 vms store commands
417
418 handle sto_xxx commands in etir section
419 ptr points to data area in record
420
421 see table B-9 of the openVMS linker manual. */
422
423static bfd_boolean
424etir_sto (abfd, cmd, ptr)
425 bfd *abfd;
426 int cmd;
427 unsigned char *ptr;
428{
429 uquad dummy;
430 int psect;
431
432#if VMS_DEBUG
433 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
434 _bfd_hexdump (8, ptr, 16, (int) ptr);
435#endif
436
437 switch (cmd)
438 {
439 /* store byte: pop stack, write byte
440 arg: - */
441
442 case ETIR_S_C_STO_B:
443 dummy = _bfd_vms_pop (abfd, &psect);
444#if 0
445 if (is_share) /* FIXME */
446 (*_bfd_error_handler) ("%s: byte fixups not supported",
447 cmd_name (cmd));
448#endif
449 /* FIXME: check top bits */
450 image_write_b (abfd, (unsigned int) dummy & 0xff);
451 break;
452
453 /* store word: pop stack, write word
454 arg: - */
455
456 case ETIR_S_C_STO_W:
457 dummy = _bfd_vms_pop (abfd, &psect);
458#if 0
459 if (is_share) /* FIXME */
460 (*_bfd_error_handler) ("%s: word fixups not supported",
461 cmd_name (cmd));
462#endif
463 /* FIXME: check top bits */
464 image_write_w (abfd, (unsigned int) dummy & 0xffff);
465 break;
466
467 /* store longword: pop stack, write longword
468 arg: - */
469
470 case ETIR_S_C_STO_LW:
471 dummy = _bfd_vms_pop (abfd, &psect);
472 dummy += (PRIV (sections)[psect])->vma;
473 /* FIXME: check top bits. */
474 image_write_l (abfd, (unsigned int) dummy & 0xffffffff);
475 break;
476
477 /* store quadword: pop stack, write quadword
478 arg: - */
479
480 case ETIR_S_C_STO_QW:
481 dummy = _bfd_vms_pop (abfd, &psect);
482 dummy += (PRIV (sections)[psect])->vma;
483 image_write_q (abfd, dummy); /* FIXME: check top bits */
484 break;
485
486 /* store immediate repeated: pop stack for repeat count
487 arg: lw byte count
488 da data */
489
490 case ETIR_S_C_STO_IMMR:
491 {
492 int size;
493
494 size = bfd_getl32 (ptr);
495 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
496 while (dummy-- > 0)
497 image_dump (abfd, ptr+4, size, 0);
498 }
499 break;
500
501 /* store global: write symbol value
502 arg: cs global symbol name. */
503
504 case ETIR_S_C_STO_GBL:
505 {
506 vms_symbol_entry *entry;
507 char *name;
508
509 name = _bfd_vms_save_counted_string (ptr);
510 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
511 name, FALSE, FALSE);
512 if (entry == (vms_symbol_entry *) NULL)
513 {
514 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
515 cmd_name (cmd), name);
516 return FALSE;
517 }
518 else
519 /* FIXME, reloc. */
520 image_write_q (abfd, (uquad) (entry->symbol->value));
521 }
522 break;
523
524 /* store code address: write address of entry point
525 arg: cs global symbol name (procedure). */
526
527 case ETIR_S_C_STO_CA:
528 {
529 vms_symbol_entry *entry;
530 char *name;
531
532 name = _bfd_vms_save_counted_string (ptr);
533 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
534 name, FALSE, FALSE);
535 if (entry == (vms_symbol_entry *) NULL)
536 {
537 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
538 cmd_name (cmd), name);
539 return FALSE;
540 }
541 else
542 image_write_q (abfd, (uquad) (entry->symbol->value)); /* FIXME, reloc */
543 }
544 break;
545
546 /* Store offset to psect: pop stack, add low 32 bits to base of psect
547 arg: none. */
548
549 case ETIR_S_C_STO_OFF:
550 {
551 uquad q;
552 int psect1;
553
554 q = _bfd_vms_pop (abfd, &psect1);
555 q += (PRIV (sections)[psect1])->vma;
556 image_write_q (abfd, q);
557 }
558 break;
559
560 /* Store immediate
561 arg: lw count of bytes
562 da data. */
563
564 case ETIR_S_C_STO_IMM:
565 {
566 int size;
567
568 size = bfd_getl32 (ptr);
569 image_dump (abfd, ptr+4, size, 0);
570 }
571 break;
572
573 /* This code is 'reserved to digital' according to the openVMS
574 linker manual, however it is generated by the DEC C compiler
575 and defined in the include file.
576 FIXME, since the following is just a guess
577 store global longword: store 32bit value of symbol
578 arg: cs symbol name. */
579
580 case ETIR_S_C_STO_GBL_LW:
581 {
582 vms_symbol_entry *entry;
583 char *name;
584
585 name = _bfd_vms_save_counted_string (ptr);
586 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
587 name, FALSE, FALSE);
588 if (entry == (vms_symbol_entry *) NULL)
589 {
590#if VMS_DEBUG
591 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd), name);
592#endif
593 image_write_l (abfd, (unsigned long) 0); /* FIXME, reloc */
594 }
595 else
596 /* FIXME, reloc. */
597 image_write_l (abfd, (unsigned long) (entry->symbol->value));
598 }
599 break;
600
601 case ETIR_S_C_STO_RB:
602 case ETIR_S_C_STO_AB:
603 case ETIR_S_C_STO_LP_PSB:
604 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
605 break;
606
607 case ETIR_S_C_STO_HINT_GBL:
608 case ETIR_S_C_STO_HINT_PS:
609 (*_bfd_error_handler) (_("%s: not implemented"), cmd_name (cmd));
610 break;
611
612 default:
613 (*_bfd_error_handler) (_("reserved STO cmd %d"), cmd);
614 break;
615 }
616
617 return TRUE;
618}
619
620/* Stack operator commands
621 all 32 bit signed arithmetic
622 all word just like a stack calculator
623 arguments are popped from stack, results are pushed on stack
624
625 see table B-10 of the openVMS linker manual. */
626
627static bfd_boolean
628etir_opr (abfd, cmd, ptr)
629 bfd *abfd;
630 int cmd;
631 unsigned char *ptr ATTRIBUTE_UNUSED;
632{
633 long op1, op2;
634
635#if VMS_DEBUG
636 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
637 _bfd_hexdump (8, ptr, 16, (int) ptr);
638#endif
639
640 switch (cmd)
641 {
642 case ETIR_S_C_OPR_NOP: /* no-op */
643 break;
644
645 case ETIR_S_C_OPR_ADD: /* add */
646 op1 = (long) _bfd_vms_pop (abfd, NULL);
647 op2 = (long) _bfd_vms_pop (abfd, NULL);
648 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
649 break;
650
651 case ETIR_S_C_OPR_SUB: /* subtract */
652 op1 = (long) _bfd_vms_pop (abfd, NULL);
653 op2 = (long) _bfd_vms_pop (abfd, NULL);
654 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
655 break;
656
657 case ETIR_S_C_OPR_MUL: /* multiply */
658 op1 = (long) _bfd_vms_pop (abfd, NULL);
659 op2 = (long) _bfd_vms_pop (abfd, NULL);
660 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
661 break;
662
663 case ETIR_S_C_OPR_DIV: /* divide */
664 op1 = (long) _bfd_vms_pop (abfd, NULL);
665 op2 = (long) _bfd_vms_pop (abfd, NULL);
666 if (op2 == 0)
667 _bfd_vms_push (abfd, (uquad) 0, -1);
668 else
669 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
670 break;
671
672 case ETIR_S_C_OPR_AND: /* logical and */
673 op1 = (long) _bfd_vms_pop (abfd, NULL);
674 op2 = (long) _bfd_vms_pop (abfd, NULL);
675 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
676 break;
677
678 case ETIR_S_C_OPR_IOR: /* logical inclusive or */
679 op1 = (long) _bfd_vms_pop (abfd, NULL);
680 op2 = (long) _bfd_vms_pop (abfd, NULL);
681 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
682 break;
683
684 case ETIR_S_C_OPR_EOR: /* logical exclusive or */
685 op1 = (long) _bfd_vms_pop (abfd, NULL);
686 op2 = (long) _bfd_vms_pop (abfd, NULL);
687 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
688 break;
689
690 case ETIR_S_C_OPR_NEG: /* negate */
691 op1 = (long) _bfd_vms_pop (abfd, NULL);
692 _bfd_vms_push (abfd, (uquad) (-op1), -1);
693 break;
694
695 case ETIR_S_C_OPR_COM: /* complement */
696 op1 = (long) _bfd_vms_pop (abfd, NULL);
697 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
698 break;
699
700 case ETIR_S_C_OPR_ASH: /* arithmetic shift */
701 op1 = (long) _bfd_vms_pop (abfd, NULL);
702 op2 = (long) _bfd_vms_pop (abfd, NULL);
703 if (op2 < 0) /* shift right */
704 op1 >>= -op2;
705 else /* shift left */
706 op1 <<= op2;
707 _bfd_vms_push (abfd, (uquad) op1, -1);
708 break;
709
710 case ETIR_S_C_OPR_INSV: /* insert field */
711 (void) _bfd_vms_pop (abfd, NULL);
712 case ETIR_S_C_OPR_USH: /* unsigned shift */
713 case ETIR_S_C_OPR_ROT: /* rotate */
714 case ETIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
715 case ETIR_S_C_OPR_DFLIT: /* Define a literal. */
716 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
717 break;
718
719 case ETIR_S_C_OPR_SEL: /* select */
720 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
721 (void) _bfd_vms_pop (abfd, NULL);
722 else
723 {
724 op1 = (long) _bfd_vms_pop (abfd, NULL);
725 (void) _bfd_vms_pop (abfd, NULL);
726 _bfd_vms_push (abfd, (uquad) op1, -1);
727 }
728 break;
729
730 default:
731 (*_bfd_error_handler) (_("reserved OPR cmd %d"), cmd);
732 break;
733 }
734
735 return TRUE;
736}
737
738/* Control commands.
739
740 See table B-11 of the openVMS linker manual. */
741
742static bfd_boolean
743etir_ctl (abfd, cmd, ptr)
744 bfd *abfd;
745 int cmd;
746 unsigned char *ptr;
747{
748 uquad dummy;
749 int psect;
750
751#if VMS_DEBUG
752 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
753 _bfd_hexdump (8, ptr, 16, (int) ptr);
754#endif
755
756 switch (cmd)
757 {
758 /* set relocation base: pop stack, set image location counter
759 arg: none. */
760
761 case ETIR_S_C_CTL_SETRB:
762 dummy = _bfd_vms_pop (abfd, &psect);
763 image_set_ptr (abfd, psect, dummy);
764 break;
765
766 /* augment relocation base: increment image location counter by offset
767 arg: lw offset value */
768
769 case ETIR_S_C_CTL_AUGRB:
770 dummy = bfd_getl32 (ptr);
771 image_inc_ptr (abfd, dummy);
772 break;
773
774 /* define location: pop index, save location counter under index
775 arg: none. */
776
777 case ETIR_S_C_CTL_DFLOC:
778 dummy = _bfd_vms_pop (abfd, NULL);
779 /* FIXME */
780 break;
781
782 /* set location: pop index, restore location counter from index
783 arg: none. */
784
785 case ETIR_S_C_CTL_STLOC:
786 dummy = _bfd_vms_pop (abfd, &psect);
787 /* FIXME */
788 break;
789
790 /* stack defined location: pop index, push location counter from index
791 arg: none. */
792
793 case ETIR_S_C_CTL_STKDL:
794 dummy = _bfd_vms_pop (abfd, &psect);
795 /* FIXME */
796 break;
797
798 default:
799 (*_bfd_error_handler) (_("reserved CTL cmd %d"), cmd);
800 break;
801 }
802 return TRUE;
803}
804
805/* store conditional commands
806
807 See table B-12 and B-13 of the openVMS linker manual. */
808
809static bfd_boolean
810etir_stc (abfd, cmd, ptr)
811 bfd *abfd;
812 int cmd;
813 unsigned char *ptr ATTRIBUTE_UNUSED;
814{
815#if VMS_DEBUG
816 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
817 _bfd_hexdump (8, ptr, 16, (int) ptr);
818#endif
819
820 switch (cmd)
821 {
822 /* 200 Store-conditional Linkage Pair
823 arg: none. */
824
825 case ETIR_S_C_STC_LP:
826 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
827 break;
828
829 /* 201 Store-conditional Linkage Pair with Procedure Signature
830 arg: lw linkage index
831 cs procedure name
832 by signature length
833 da signature. */
834
835 case ETIR_S_C_STC_LP_PSB:
836 image_inc_ptr (abfd, (uquad) 16); /* skip entry,procval */
837 break;
838
839 /* 202 Store-conditional Address at global address
840 arg: lw linkage index
841 cs global name. */
842
843 case ETIR_S_C_STC_GBL:
844 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
845 break;
846
847 /* 203 Store-conditional Code Address at global address
848 arg: lw linkage index
849 cs procedure name. */
850
851 case ETIR_S_C_STC_GCA:
852 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
853 break;
854
855 /* 204 Store-conditional Address at psect + offset
856 arg: lw linkage index
857 lw psect index
858 qw offset. */
859
860 case ETIR_S_C_STC_PS:
861 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
862 break;
863
864 /* 205 Store-conditional NOP at address of global
865 arg: none. */
866
867 case ETIR_S_C_STC_NOP_GBL:
868
869 /* 206 Store-conditional NOP at pect + offset
870 arg: none. */
871
872 case ETIR_S_C_STC_NOP_PS:
873
874 /* 207 Store-conditional BSR at global address
875 arg: none. */
876
877 case ETIR_S_C_STC_BSR_GBL:
878
879 /* 208 Store-conditional BSR at pect + offset
880 arg: none. */
881
882 case ETIR_S_C_STC_BSR_PS:
883
884 /* 209 Store-conditional LDA at global address
885 arg: none. */
886
887 case ETIR_S_C_STC_LDA_GBL:
888
889 /* 210 Store-conditional LDA at psect + offset
890 arg: none. */
891
892 case ETIR_S_C_STC_LDA_PS:
893
894 /* 211 Store-conditional BSR or Hint at global address
895 arg: none. */
896
897 case ETIR_S_C_STC_BOH_GBL:
898
899 /* 212 Store-conditional BSR or Hint at pect + offset
900 arg: none. */
901
902 case ETIR_S_C_STC_BOH_PS:
903
904 /* 213 Store-conditional NOP,BSR or HINT at global address
905 arg: none. */
906
907 case ETIR_S_C_STC_NBH_GBL:
908
909 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
910 arg: none. */
911
912 case ETIR_S_C_STC_NBH_PS:
913 /* FIXME */
914#if 0
915 (*_bfd_error_handler) ("%s: not supported", cmd_name (cmd));
916#endif
917 break;
918
919 default:
920#if VMS_DEBUG
921 _bfd_vms_debug (3, "reserved STC cmd %d", cmd);
922#endif
923 break;
924 }
925 return TRUE;
926}
927
928static asection *
929new_section (abfd, idx)
930 bfd *abfd ATTRIBUTE_UNUSED;
931 int idx;
932{
933 asection *section;
934 char sname[16];
935 char *name;
936
937#if VMS_DEBUG
938 _bfd_vms_debug (5, "new_section %d\n", idx);
939#endif
940 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
941
942 name = bfd_malloc ((bfd_size_type) strlen (sname) + 1);
943 if (name == 0)
944 return 0;
945 strcpy (name, sname);
946
947 section = bfd_malloc ((bfd_size_type) sizeof (asection));
948 if (section == 0)
949 {
950#if VMS_DEBUG
951 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
952#endif
953 return 0;
954 }
955
956 section->_raw_size = 0;
957 section->vma = 0;
958 section->contents = 0;
959 section->_cooked_size = 0;
960 section->name = name;
961 section->index = idx;
962
963 return section;
964}
965
966static int
967alloc_section (abfd, idx)
968 bfd *abfd;
969 unsigned int idx;
970{
971 bfd_size_type amt;
972
973#if VMS_DEBUG
974 _bfd_vms_debug (4, "alloc_section %d\n", idx);
975#endif
976
977 amt = idx + 1;
978 amt *= sizeof (asection *);
979 PRIV (sections) = (asection **) bfd_realloc (PRIV (sections), amt);
980 if (PRIV (sections) == 0)
981 return -1;
982
983 while (PRIV (section_count) <= idx)
984 {
985 PRIV (sections)[PRIV (section_count)]
986 = new_section (abfd, (int) PRIV (section_count));
987 if (PRIV (sections)[PRIV (section_count)] == 0)
988 return -1;
989 PRIV (section_count)++;
990 }
991
992 return 0;
993}
994
995/* tir_sta
996
997 vax stack commands
998
999 Handle sta_xxx commands in tir section
1000 ptr points to data area in record
1001
1002 See table 7-3 of the VAX/VMS linker manual. */
1003
1004static unsigned char *
1005tir_sta (bfd *abfd, unsigned char *ptr)
1006{
1007 int cmd = *ptr++;
1008
1009#if VMS_DEBUG
1010 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
1011#endif
1012
1013 switch (cmd)
1014 {
1015 /* stack */
1016 case TIR_S_C_STA_GBL:
1017 /* stack global
1018 arg: cs symbol name
1019
1020 stack 32 bit value of symbol (high bits set to 0). */
1021 {
1022 char *name;
1023 vms_symbol_entry *entry;
1024
1025 name = _bfd_vms_save_counted_string (ptr);
1026
1027 entry = _bfd_vms_enter_symbol (abfd, name);
1028 if (entry == (vms_symbol_entry *) NULL)
1029 return 0;
1030
1031 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
1032 ptr += *ptr + 1;
1033 }
1034 break;
1035
1036 case TIR_S_C_STA_SB:
1037 /* stack signed byte
1038 arg: by value
1039
1040 stack byte value, sign extend to 32 bit. */
1041 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1042 break;
1043
1044 case TIR_S_C_STA_SW:
1045 /* stack signed short word
1046 arg: sh value
1047
1048 stack 16 bit value, sign extend to 32 bit. */
1049 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1050 ptr += 2;
1051 break;
1052
1053 case TIR_S_C_STA_LW:
1054 /* stack signed longword
1055 arg: lw value
1056
1057 stack 32 bit value. */
1058 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
1059 ptr += 4;
1060 break;
1061
1062 case TIR_S_C_STA_PB:
1063 case TIR_S_C_STA_WPB:
1064 /* stack psect base plus byte offset (word index)
1065 arg: by section index
1066 (sh section index)
1067 by signed byte offset. */
1068 {
1069 unsigned long dummy;
1070 unsigned int psect;
1071
1072 if (cmd == TIR_S_C_STA_PB)
1073 psect = *ptr++;
1074 else
1075 {
1076 psect = bfd_getl16 (ptr);
1077 ptr += 2;
1078 }
1079
1080 if (psect >= PRIV (section_count))
1081 alloc_section (abfd, psect);
1082
1083 dummy = (long) *ptr++;
1084 dummy += (PRIV (sections)[psect])->vma;
1085 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1086 }
1087 break;
1088
1089 case TIR_S_C_STA_PW:
1090 case TIR_S_C_STA_WPW:
1091 /* stack psect base plus word offset (word index)
1092 arg: by section index
1093 (sh section index)
1094 sh signed short offset. */
1095 {
1096 unsigned long dummy;
1097 unsigned int psect;
1098
1099 if (cmd == TIR_S_C_STA_PW)
1100 psect = *ptr++;
1101 else
1102 {
1103 psect = bfd_getl16 (ptr);
1104 ptr += 2;
1105 }
1106
1107 if (psect >= PRIV (section_count))
1108 alloc_section (abfd, psect);
1109
1110 dummy = bfd_getl16 (ptr); ptr+=2;
1111 dummy += (PRIV (sections)[psect])->vma;
1112 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1113 }
1114 break;
1115
1116 case TIR_S_C_STA_PL:
1117 case TIR_S_C_STA_WPL:
1118 /* stack psect base plus long offset (word index)
1119 arg: by section index
1120 (sh section index)
1121 lw signed longword offset. */
1122 {
1123 unsigned long dummy;
1124 unsigned int psect;
1125
1126 if (cmd == TIR_S_C_STA_PL)
1127 psect = *ptr++;
1128 else
1129 {
1130 psect = bfd_getl16 (ptr);
1131 ptr += 2;
1132 }
1133
1134 if (psect >= PRIV (section_count))
1135 alloc_section (abfd, psect);
1136
1137 dummy = bfd_getl32 (ptr); ptr += 4;
1138 dummy += (PRIV (sections)[psect])->vma;
1139 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1140 }
1141 break;
1142
1143 case TIR_S_C_STA_UB:
1144 /* stack unsigned byte
1145 arg: by value
1146
1147 stack byte value. */
1148 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1149 break;
1150
1151 case TIR_S_C_STA_UW:
1152 /* stack unsigned short word
1153 arg: sh value
1154
1155 stack 16 bit value. */
1156 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1157 ptr += 2;
1158 break;
1159
1160 case TIR_S_C_STA_BFI:
1161 /* stack byte from image
1162 arg: none. */
1163 /* FALLTHRU */
1164 case TIR_S_C_STA_WFI:
1165 /* stack byte from image
1166 arg: none. */
1167 /* FALLTHRU */
1168 case TIR_S_C_STA_LFI:
1169 /* stack byte from image
1170 arg: none. */
1171 (*_bfd_error_handler) (_("stack-from-image not implemented"));
1172 return NULL;
1173
1174 case TIR_S_C_STA_EPM:
1175 /* stack entry point mask
1176 arg: cs symbol name
1177
1178 stack (unsigned) entry point mask of symbol
1179 err if symbol is no entry point. */
1180 {
1181 char *name;
1182 vms_symbol_entry *entry;
1183
1184 name = _bfd_vms_save_counted_string (ptr);
1185 entry = _bfd_vms_enter_symbol (abfd, name);
1186 if (entry == (vms_symbol_entry *) NULL)
1187 return 0;
1188
1189 (*_bfd_error_handler) (_("stack-entry-mask not fully implemented"));
1190 _bfd_vms_push (abfd, (uquad) 0, -1);
1191 ptr += *ptr + 1;
1192 }
1193 break;
1194
1195 case TIR_S_C_STA_CKARG:
1196 /* compare procedure argument
1197 arg: cs symbol name
1198 by argument index
1199 da argument descriptor
1200
1201 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1202 and stack TRUE (args match) or FALSE (args dont match) value. */
1203 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1204 _bfd_vms_push (abfd, (uquad) 1, -1);
1205 break;
1206
1207 case TIR_S_C_STA_LSY:
1208 /* stack local symbol value
1209 arg: sh environment index
1210 cs symbol name. */
1211 {
1212 int envidx;
1213 char *name;
1214 vms_symbol_entry *entry;
1215
1216 envidx = bfd_getl16 (ptr);
1217 ptr += 2;
1218 name = _bfd_vms_save_counted_string (ptr);
1219 entry = _bfd_vms_enter_symbol (abfd, name);
1220 if (entry == (vms_symbol_entry *) NULL)
1221 return 0;
1222 (*_bfd_error_handler) (_("stack-local-symbol not fully implemented"));
1223 _bfd_vms_push (abfd, (uquad) 0, -1);
1224 ptr += *ptr + 1;
1225 }
1226 break;
1227
1228 case TIR_S_C_STA_LIT:
1229 /* stack literal
1230 arg: by literal index
1231
1232 stack literal. */
1233 ptr++;
1234 _bfd_vms_push (abfd, (uquad) 0, -1);
1235 (*_bfd_error_handler) (_("stack-literal not fully implemented"));
1236 break;
1237
1238 case TIR_S_C_STA_LEPM:
1239 /* stack local symbol entry point mask
1240 arg: sh environment index
1241 cs symbol name
1242
1243 stack (unsigned) entry point mask of symbol
1244 err if symbol is no entry point. */
1245 {
1246 int envidx;
1247 char *name;
1248 vms_symbol_entry *entry;
1249
1250 envidx = bfd_getl16 (ptr);
1251 ptr += 2;
1252 name = _bfd_vms_save_counted_string (ptr);
1253 entry = _bfd_vms_enter_symbol (abfd, name);
1254 if (entry == (vms_symbol_entry *) NULL)
1255 return 0;
1256 (*_bfd_error_handler) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1257 _bfd_vms_push (abfd, (uquad) 0, -1);
1258 ptr += *ptr + 1;
1259 }
1260 break;
1261
1262 default:
1263 (*_bfd_error_handler) (_("reserved STA cmd %d"), ptr[-1]);
1264 return NULL;
1265 break;
1266 }
1267
1268 return ptr;
1269}
1270
1271static const char *
1272tir_cmd_name (cmd)
1273 int cmd;
1274{
1275 switch (cmd)
1276 {
1277 case TIR_S_C_STO_RSB: return "TIR_S_C_STO_RSB";
1278 case TIR_S_C_STO_RSW: return "TIR_S_C_STO_RSW";
1279 case TIR_S_C_STO_RL: return "TIR_S_C_STO_RL";
1280 case TIR_S_C_STO_VPS: return "TIR_S_C_STO_VPS";
1281 case TIR_S_C_STO_USB: return "TIR_S_C_STO_USB";
1282 case TIR_S_C_STO_USW: return "TIR_S_C_STO_USW";
1283 case TIR_S_C_STO_RUB: return "TIR_S_C_STO_RUB";
1284 case TIR_S_C_STO_RUW: return "TIR_S_C_STO_RUW";
1285 case TIR_S_C_STO_PIRR: return "TIR_S_C_STO_PIRR";
1286 case TIR_S_C_OPR_INSV: return "TIR_S_C_OPR_INSV";
1287 case TIR_S_C_OPR_DFLIT: return "TIR_S_C_OPR_DFLIT";
1288 case TIR_S_C_OPR_REDEF: return "TIR_S_C_OPR_REDEF";
1289 case TIR_S_C_OPR_ROT: return "TIR_S_C_OPR_ROT";
1290 case TIR_S_C_OPR_USH: return "TIR_S_C_OPR_USH";
1291 case TIR_S_C_OPR_ASH: return "TIR_S_C_OPR_ASH";
1292 case TIR_S_C_CTL_DFLOC: return "TIR_S_C_CTL_DFLOC";
1293 case TIR_S_C_CTL_STLOC: return "TIR_S_C_CTL_STLOC";
1294 case TIR_S_C_CTL_STKDL: return "TIR_S_C_CTL_STKDL";
1295
1296 default:
1297 /* These strings have not been added yet. */
1298 abort ();
1299 }
1300}
1301
1302/* tir_sto
1303
1304 vax store commands
1305
1306 handle sto_xxx commands in tir section
1307 ptr points to data area in record
1308
1309 See table 7-4 of the VAX/VMS linker manual. */
1310
1311static unsigned char *
1312tir_sto (bfd *abfd, unsigned char *ptr)
1313{
1314 unsigned long dummy;
1315 int size;
1316 int psect;
1317
1318#if VMS_DEBUG
1319 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1320#endif
1321
1322 switch (*ptr++)
1323 {
1324 case TIR_S_C_STO_SB:
1325 /* store signed byte: pop stack, write byte
1326 arg: none. */
1327 dummy = _bfd_vms_pop (abfd, &psect);
1328 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1329 break;
1330
1331 case TIR_S_C_STO_SW:
1332 /* store signed word: pop stack, write word
1333 arg: none. */
1334 dummy = _bfd_vms_pop (abfd, &psect);
1335 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1336 break;
1337
1338 case TIR_S_C_STO_LW:
1339 /* store longword: pop stack, write longword
1340 arg: none. */
1341 dummy = _bfd_vms_pop (abfd, &psect);
1342 image_write_l (abfd, dummy & 0xffffffff); /* FIXME: check top bits */
1343 break;
1344
1345 case TIR_S_C_STO_BD:
1346 /* store byte displaced: pop stack, sub lc+1, write byte
1347 arg: none. */
1348 dummy = _bfd_vms_pop (abfd, &psect);
1349 dummy -= ((PRIV (sections)[psect])->vma + 1);
1350 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1351 break;
1352
1353 case TIR_S_C_STO_WD:
1354 /* store word displaced: pop stack, sub lc+2, write word
1355 arg: none. */
1356 dummy = _bfd_vms_pop (abfd, &psect);
1357 dummy -= ((PRIV (sections)[psect])->vma + 2);
1358 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1359 break;
1360
1361 case TIR_S_C_STO_LD:
1362 /* store long displaced: pop stack, sub lc+4, write long
1363 arg: none. */
1364 dummy = _bfd_vms_pop (abfd, &psect);
1365 dummy -= ((PRIV (sections)[psect])->vma + 4);
1366 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1367 break;
1368
1369 case TIR_S_C_STO_LI:
1370 /* store short literal: pop stack, write byte
1371 arg: none. */
1372 dummy = _bfd_vms_pop (abfd, &psect);
1373 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1374 break;
1375
1376 case TIR_S_C_STO_PIDR:
1377 /* store position independent data reference: pop stack, write longword
1378 arg: none.
1379 FIXME: incomplete ! */
1380 dummy = _bfd_vms_pop (abfd, &psect);
1381 image_write_l (abfd, dummy & 0xffffffff);
1382 break;
1383
1384 case TIR_S_C_STO_PICR:
1385 /* store position independent code reference: pop stack, write longword
1386 arg: none.
1387 FIXME: incomplete ! */
1388 dummy = _bfd_vms_pop (abfd, &psect);
1389 image_write_b (abfd, 0x9f);
1390 image_write_l (abfd, dummy & 0xffffffff);
1391 break;
1392
1393 case TIR_S_C_STO_RIVB:
1394 /* store repeated immediate variable bytes
1395 1-byte count n field followed by n bytes of data
1396 pop stack, write n bytes <stack> times. */
1397 size = *ptr++;
1398 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1399 while (dummy-- > 0L)
1400 image_dump (abfd, ptr, size, 0);
1401 ptr += size;
1402 break;
1403
1404 case TIR_S_C_STO_B:
1405 /* store byte from top longword. */
1406 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1407 image_write_b (abfd, dummy & 0xff);
1408 break;
1409
1410 case TIR_S_C_STO_W:
1411 /* store word from top longword. */
1412 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1413 image_write_w (abfd, dummy & 0xffff);
1414 break;
1415
1416 case TIR_S_C_STO_RB:
1417 /* store repeated byte from top longword. */
1418 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1419 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1420 while (size-- > 0)
1421 image_write_b (abfd, dummy & 0xff);
1422 break;
1423
1424 case TIR_S_C_STO_RW:
1425 /* store repeated word from top longword. */
1426 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1427 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1428 while (size-- > 0)
1429 image_write_w (abfd, dummy & 0xffff);
1430 break;
1431
1432 case TIR_S_C_STO_RSB:
1433 case TIR_S_C_STO_RSW:
1434 case TIR_S_C_STO_RL:
1435 case TIR_S_C_STO_VPS:
1436 case TIR_S_C_STO_USB:
1437 case TIR_S_C_STO_USW:
1438 case TIR_S_C_STO_RUB:
1439 case TIR_S_C_STO_RUW:
1440 case TIR_S_C_STO_PIRR:
1441 (*_bfd_error_handler) (_("%s: not implemented"), tir_cmd_name (ptr[-1]));
1442 break;
1443
1444 default:
1445 (*_bfd_error_handler) (_("reserved STO cmd %d"), ptr[-1]);
1446 break;
1447 }
1448
1449 return ptr;
1450}
1451
1452/* stack operator commands
1453 all 32 bit signed arithmetic
1454 all word just like a stack calculator
1455 arguments are popped from stack, results are pushed on stack
1456
1457 See table 7-5 of the VAX/VMS linker manual. */
1458
1459static unsigned char *
1460tir_opr (abfd, ptr)
1461 bfd *abfd;
1462 unsigned char *ptr;
1463{
1464 long op1, op2;
1465
1466#if VMS_DEBUG
1467 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1468#endif
1469
1470 switch (*ptr++)
1471 {
1472 /* operation */
1473 case TIR_S_C_OPR_NOP: /* no-op */
1474 break;
1475
1476 case TIR_S_C_OPR_ADD: /* add */
1477 op1 = (long) _bfd_vms_pop (abfd, NULL);
1478 op2 = (long) _bfd_vms_pop (abfd, NULL);
1479 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
1480 break;
1481
1482 case TIR_S_C_OPR_SUB: /* subtract */
1483 op1 = (long) _bfd_vms_pop (abfd, NULL);
1484 op2 = (long) _bfd_vms_pop (abfd, NULL);
1485 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
1486 break;
1487
1488 case TIR_S_C_OPR_MUL: /* multiply */
1489 op1 = (long) _bfd_vms_pop (abfd, NULL);
1490 op2 = (long) _bfd_vms_pop (abfd, NULL);
1491 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
1492 break;
1493
1494 case TIR_S_C_OPR_DIV: /* divide */
1495 op1 = (long) _bfd_vms_pop (abfd, NULL);
1496 op2 = (long) _bfd_vms_pop (abfd, NULL);
1497 if (op2 == 0)
1498 _bfd_vms_push (abfd, (uquad) 0, -1);
1499 else
1500 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
1501 break;
1502
1503 case TIR_S_C_OPR_AND: /* logical and */
1504 op1 = (long) _bfd_vms_pop (abfd, NULL);
1505 op2 = (long) _bfd_vms_pop (abfd, NULL);
1506 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
1507 break;
1508
1509 case TIR_S_C_OPR_IOR: /* logical inclusive or */
1510 op1 = (long) _bfd_vms_pop (abfd, NULL);
1511 op2 = (long) _bfd_vms_pop (abfd, NULL);
1512 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
1513 break;
1514
1515 case TIR_S_C_OPR_EOR: /* logical exclusive or */
1516 op1 = (long) _bfd_vms_pop (abfd, NULL);
1517 op2 = (long) _bfd_vms_pop (abfd, NULL);
1518 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
1519 break;
1520
1521 case TIR_S_C_OPR_NEG: /* negate */
1522 op1 = (long) _bfd_vms_pop (abfd, NULL);
1523 _bfd_vms_push (abfd, (uquad) (-op1), -1);
1524 break;
1525
1526 case TIR_S_C_OPR_COM: /* complement */
1527 op1 = (long) _bfd_vms_pop (abfd, NULL);
1528 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
1529 break;
1530
1531 case TIR_S_C_OPR_INSV: /* insert field */
1532 (void) _bfd_vms_pop (abfd, NULL);
1533 (*_bfd_error_handler) (_("%s: not fully implemented"),
1534 tir_cmd_name (ptr[-1]));
1535 break;
1536
1537 case TIR_S_C_OPR_ASH: /* arithmetic shift */
1538 op1 = (long) _bfd_vms_pop (abfd, NULL);
1539 op2 = (long) _bfd_vms_pop (abfd, NULL);
1540 if (HIGHBIT (op1)) /* shift right */
1541 op2 >>= op1;
1542 else /* shift left */
1543 op2 <<= op1;
1544 _bfd_vms_push (abfd, (uquad) op2, -1);
1545 (*_bfd_error_handler) (_("%s: not fully implemented"),
1546 tir_cmd_name (ptr[-1]));
1547 break;
1548
1549 case TIR_S_C_OPR_USH: /* unsigned shift */
1550 op1 = (long) _bfd_vms_pop (abfd, NULL);
1551 op2 = (long) _bfd_vms_pop (abfd, NULL);
1552 if (HIGHBIT (op1)) /* shift right */
1553 op2 >>= op1;
1554 else /* shift left */
1555 op2 <<= op1;
1556 _bfd_vms_push (abfd, (uquad) op2, -1);
1557 (*_bfd_error_handler) (_("%s: not fully implemented"),
1558 tir_cmd_name (ptr[-1]));
1559 break;
1560
1561 case TIR_S_C_OPR_ROT: /* rotate */
1562 op1 = (long) _bfd_vms_pop (abfd, NULL);
1563 op2 = (long) _bfd_vms_pop (abfd, NULL);
1564 if (HIGHBIT (0)) /* shift right */
1565 op2 >>= op1;
1566 else /* shift left */
1567 op2 <<= op1;
1568 _bfd_vms_push (abfd, (uquad) op2, -1);
1569 (*_bfd_error_handler) (_("%s: not fully implemented"),
1570 tir_cmd_name (ptr[-1]));
1571 break;
1572
1573 case TIR_S_C_OPR_SEL: /* select */
1574 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
1575 (void) _bfd_vms_pop (abfd, NULL);
1576 else
1577 {
1578 op1 = (long) _bfd_vms_pop (abfd, NULL);
1579 (void) _bfd_vms_pop (abfd, NULL);
1580 _bfd_vms_push (abfd, (uquad) op1, -1);
1581 }
1582 break;
1583
1584 case TIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
1585 case TIR_S_C_OPR_DFLIT: /* Define a literal. */
1586 (*_bfd_error_handler) (_("%s: not supported"),
1587 tir_cmd_name (ptr[-1]));
1588 break;
1589
1590 default:
1591 (*_bfd_error_handler) (_("reserved OPR cmd %d"), ptr[-1]);
1592 break;
1593 }
1594
1595 return ptr;
1596}
1597
1598/* control commands
1599
1600 See table 7-6 of the VAX/VMS linker manual. */
1601
1602static unsigned char *
1603tir_ctl (bfd *abfd, unsigned char *ptr)
1604{
1605 unsigned long dummy;
1606 unsigned int psect;
1607
1608#if VMS_DEBUG
1609 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1610#endif
1611
1612 switch (*ptr++)
1613 {
1614 case TIR_S_C_CTL_SETRB:
1615 /* Set relocation base: pop stack, set image location counter
1616 arg: none. */
1617 dummy = _bfd_vms_pop (abfd, &psect);
1618 if (psect >= PRIV (section_count))
1619 alloc_section (abfd, psect);
1620 image_set_ptr (abfd, (int) psect, (uquad) dummy);
1621 break;
1622
1623 case TIR_S_C_CTL_AUGRB:
1624 /* Augment relocation base: increment image location counter by offset
1625 arg: lw offset value. */
1626 dummy = bfd_getl32 (ptr);
1627 image_inc_ptr (abfd, (uquad) dummy);
1628 break;
1629
1630 case TIR_S_C_CTL_DFLOC:
1631 /* Define location: pop index, save location counter under index
1632 arg: none. */
1633 dummy = _bfd_vms_pop (abfd, NULL);
1634 (*_bfd_error_handler) (_("%s: not fully implemented"),
1635 tir_cmd_name (ptr[-1]));
1636 break;
1637
1638 case TIR_S_C_CTL_STLOC:
1639 /* Set location: pop index, restore location counter from index
1640 arg: none. */
1641 dummy = _bfd_vms_pop (abfd, &psect);
1642 (*_bfd_error_handler) (_("%s: not fully implemented"),
1643 tir_cmd_name (ptr[-1]));
1644 break;
1645
1646 case TIR_S_C_CTL_STKDL:
1647 /* Stack defined location: pop index, push location counter from index
1648 arg: none. */
1649 dummy = _bfd_vms_pop (abfd, &psect);
1650 (*_bfd_error_handler) (_("%s: not fully implemented"),
1651 tir_cmd_name (ptr[-1]));
1652 break;
1653
1654 default:
1655 (*_bfd_error_handler) (_("reserved CTL cmd %d"), ptr[-1]);
1656 break;
1657 }
1658 return ptr;
1659}
1660
1661/* Handle command from TIR section. */
1662
1663static unsigned char *
1664tir_cmd (bfd *abfd, unsigned char *ptr)
1665{
1666 struct
1667 {
1668 int mincod;
1669 int maxcod;
1670 unsigned char * (*explain) (bfd *, unsigned char *);
1671 }
1672 tir_table[] =
1673 {
1674 { 0, TIR_S_C_MAXSTACOD, tir_sta },
1675 { TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto },
1676 { TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr },
1677 { TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl },
1678 { -1, -1, NULL }
1679 };
1680 int i = 0;
1681
1682#if VMS_DEBUG
1683 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1684 _bfd_hexdump (8, ptr, 16, (int) ptr);
1685#endif
1686
1687 if (*ptr & 0x80) /* store immediate */
1688 {
1689 i = 128 - (*ptr++ & 0x7f);
1690 image_dump (abfd, ptr, i, 0);
1691 ptr += i;
1692 }
1693 else
1694 {
1695 while (tir_table[i].mincod >= 0)
1696 {
1697 if ( (tir_table[i].mincod <= *ptr)
1698 && (*ptr <= tir_table[i].maxcod))
1699 {
1700 ptr = tir_table[i].explain (abfd, ptr);
1701 break;
1702 }
1703 i++;
1704 }
1705 if (tir_table[i].mincod < 0)
1706 {
1707 (*_bfd_error_handler) (_("obj code %d not found"), *ptr);
1708 ptr = 0;
1709 }
1710 }
1711
1712 return ptr;
1713}
1714
1715/* Handle command from ETIR section. */
1716
1717static int
1718etir_cmd (abfd, cmd, ptr)
1719 bfd *abfd;
1720 int cmd;
1721 unsigned char *ptr;
1722{
1723 static struct
1724 {
1725 int mincod;
1726 int maxcod;
1727 bfd_boolean (*explain) PARAMS ((bfd *, int, unsigned char *));
1728 }
1729 etir_table[] =
1730 {
1731 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1732 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1733 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1734 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1735 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1736 { -1, -1, NULL }
1737 };
1738
1739 int i = 0;
1740
1741#if VMS_DEBUG
1742 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1743 _bfd_hexdump (8, ptr, 16, (int) ptr);
1744#endif
1745
1746 while (etir_table[i].mincod >= 0)
1747 {
1748 if ( (etir_table[i].mincod <= cmd)
1749 && (cmd <= etir_table[i].maxcod))
1750 {
1751 if (!etir_table[i].explain (abfd, cmd, ptr))
1752 return -1;
1753 break;
1754 }
1755 i++;
1756 }
1757
1758#if VMS_DEBUG
1759 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1760#endif
1761 return 0;
1762}
1763
1764/* Text Information and Relocation Records (OBJ$C_TIR)
1765 handle tir record. */
1766
1767static int
1768analyze_tir (abfd, ptr, length)
1769 bfd *abfd;
1770 unsigned char *ptr;
1771 unsigned int length;
1772{
1773 unsigned char *maxptr;
1774
1775#if VMS_DEBUG
1776 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1777#endif
1778
1779 maxptr = ptr + length;
1780
1781 while (ptr < maxptr)
1782 {
1783 ptr = tir_cmd (abfd, ptr);
1784 if (ptr == 0)
1785 return -1;
1786 }
1787
1788 return 0;
1789}
1790
1791/* Text Information and Relocation Records (EOBJ$C_ETIR)
1792 handle etir record. */
1793
1794static int
1795analyze_etir (abfd, ptr, length)
1796 bfd *abfd;
1797 unsigned char *ptr;
1798 unsigned int length;
1799{
1800 int cmd;
1801 unsigned char *maxptr;
1802 int result = 0;
1803
1804#if VMS_DEBUG
1805 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1806#endif
1807
1808 maxptr = ptr + length;
1809
1810 while (ptr < maxptr)
1811 {
1812 cmd = bfd_getl16 (ptr);
1813 length = bfd_getl16 (ptr + 2);
1814 result = etir_cmd (abfd, cmd, ptr+4);
1815 if (result != 0)
1816 break;
1817 ptr += length;
1818 }
1819
1820#if VMS_DEBUG
1821 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1822#endif
1823
1824 return result;
1825}
1826
1827/* Process ETIR record
1828 Return 0 on success, -1 on error. */
1829
1830int
1831_bfd_vms_slurp_tir (abfd, objtype)
1832 bfd *abfd;
1833 int objtype;
1834{
1835 int result;
1836
1837#if VMS_DEBUG
1838 _bfd_vms_debug (2, "TIR/ETIR\n");
1839#endif
1840
1841 switch (objtype)
1842 {
1843 case EOBJ_S_C_ETIR:
1844 PRIV (vms_rec) += 4; /* skip type, size */
1845 PRIV (rec_size) -= 4;
1846 result = analyze_etir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1847 break;
1848 case OBJ_S_C_TIR:
1849 PRIV (vms_rec) += 1; /* skip type */
1850 PRIV (rec_size) -= 1;
1851 result = analyze_tir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1852 break;
1853 default:
1854 result = -1;
1855 break;
1856 }
1857
1858 return result;
1859}
1860
1861/* Process EDBG record
1862 Return 0 on success, -1 on error
1863
1864 Not implemented yet. */
1865
1866int
1867_bfd_vms_slurp_dbg (abfd, objtype)
1868 bfd *abfd;
1869 int objtype ATTRIBUTE_UNUSED;
1870{
1871#if VMS_DEBUG
1872 _bfd_vms_debug (2, "DBG/EDBG\n");
1873#endif
1874
1875 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1876 return 0;
1877}
1878
1879/* Process ETBT record
1880 Return 0 on success, -1 on error
1881
1882 Not implemented yet. */
1883
1884int
1885_bfd_vms_slurp_tbt (abfd, objtype)
1886 bfd *abfd ATTRIBUTE_UNUSED;
1887 int objtype ATTRIBUTE_UNUSED;
1888{
1889#if VMS_DEBUG
1890 _bfd_vms_debug (2, "TBT/ETBT\n");
1891#endif
1892
1893 return 0;
1894}
1895
1896/* Process LNK record
1897 Return 0 on success, -1 on error
1898
1899 Not implemented yet. */
1900
1901int
1902_bfd_vms_slurp_lnk (abfd, objtype)
1903 bfd *abfd ATTRIBUTE_UNUSED;
1904 int objtype ATTRIBUTE_UNUSED;
1905{
1906#if VMS_DEBUG
1907 _bfd_vms_debug (2, "LNK\n");
1908#endif
1909
1910 return 0;
1911}
1912
1913
1914/* WRITE ETIR SECTION
1915
1916 This is still under construction and therefore not documented. */
1917
1918static void start_etir_record
1919 PARAMS ((bfd *abfd, int index, uquad offset, bfd_boolean justoffset));
1920static void sto_imm
1921 PARAMS ((bfd *abfd, vms_section *sptr, bfd_vma vaddr, int index));
1922static void end_etir_record
1923 PARAMS ((bfd *abfd));
1924
1925static void
1926sto_imm (abfd, sptr, vaddr, index)
1927 bfd *abfd;
1928 vms_section *sptr;
1929 bfd_vma vaddr;
1930 int index;
1931{
1932 int size;
1933 int ssize;
1934 unsigned char *cptr;
1935
1936#if VMS_DEBUG
1937 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
1938 _bfd_hexdump (9, sptr->contents, (int) sptr->size, (int) vaddr);
1939#endif
1940
1941 ssize = sptr->size;
1942 cptr = sptr->contents;
1943
1944 while (ssize > 0)
1945 {
1946 size = ssize; /* try all the rest */
1947
1948 if (_bfd_vms_output_check (abfd, size) < 0)
1949 { /* doesn't fit, split ! */
1950 end_etir_record (abfd);
1951 start_etir_record (abfd, index, vaddr, FALSE);
1952 size = _bfd_vms_output_check (abfd, 0); /* get max size */
1953 if (size > ssize) /* more than what's left ? */
1954 size = ssize;
1955 }
1956
1957 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
1958 _bfd_vms_output_long (abfd, (unsigned long) (size));
1959 _bfd_vms_output_dump (abfd, cptr, size);
1960 _bfd_vms_output_flush (abfd);
1961
1962#if VMS_DEBUG
1963 _bfd_vms_debug (10, "dumped %d bytes\n", size);
1964 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
1965#endif
1966
1967 vaddr += size;
1968 ssize -= size;
1969 cptr += size;
1970 }
1971}
1972
1973/* Start ETIR record for section #index at virtual addr offset. */
1974
1975static void
1976start_etir_record (abfd, index, offset, justoffset)
1977 bfd *abfd;
1978 int index;
1979 uquad offset;
1980 bfd_boolean justoffset;
1981{
1982 if (!justoffset)
1983 {
1984 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
1985 _bfd_vms_output_push (abfd);
1986 }
1987
1988 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
1989 _bfd_vms_output_long (abfd, (unsigned long) index);
1990 _bfd_vms_output_quad (abfd, (uquad) offset);
1991 _bfd_vms_output_flush (abfd);
1992
1993 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop () */
1994 _bfd_vms_output_flush (abfd);
1995}
1996
1997/* End etir record. */
1998
1999static void
2000end_etir_record (abfd)
2001 bfd *abfd;
2002{
2003 _bfd_vms_output_pop (abfd);
2004 _bfd_vms_output_end (abfd);
2005}
2006
2007/* Write section contents for bfd abfd. */
2008
2009int
2010_bfd_vms_write_tir (abfd, objtype)
2011 bfd *abfd;
2012 int objtype ATTRIBUTE_UNUSED;
2013{
2014 asection *section;
2015 vms_section *sptr;
2016 int nextoffset;
2017
2018#if VMS_DEBUG
2019 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
2020#endif
2021
2022 _bfd_vms_output_alignment (abfd, 4);
2023
2024 nextoffset = 0;
2025 PRIV (vms_linkage_index) = 1;
2026
2027 /* Dump all other sections. */
2028
2029 section = abfd->sections;
2030
2031 while (section != NULL)
2032 {
2033
2034#if VMS_DEBUG
2035 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2036 section->index, section->name,
2037 (int) (section->_raw_size));
2038#endif
2039
2040 if (section->flags & SEC_RELOC)
2041 {
2042 int i;
2043
2044 if ((i = section->reloc_count) <= 0)
2045 {
2046 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
2047 section->name);
2048 }
2049#if VMS_DEBUG
2050 else
2051 {
2052 arelent **rptr;
2053 _bfd_vms_debug (4, "%d relocations:\n", i);
2054 rptr = section->orelocation;
2055 while (i-- > 0)
2056 {
2057 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2058 (*(*rptr)->sym_ptr_ptr)->name,
2059 (*(*rptr)->sym_ptr_ptr)->section->name,
2060 (long) (*(*rptr)->sym_ptr_ptr)->value,
2061 (*rptr)->address, (*rptr)->addend,
2062 bfd_get_reloc_size ((*rptr)->howto),
2063 (*rptr)->howto->name);
2064 rptr++;
2065 }
2066 }
2067#endif
2068 }
2069
2070 if ((section->flags & SEC_HAS_CONTENTS)
2071 && (! bfd_is_com_section (section)))
2072 {
2073 bfd_vma vaddr; /* Virtual addr in section. */
2074
2075 sptr = _bfd_get_vms_section (abfd, section->index);
2076 if (sptr == NULL)
2077 {
2078 bfd_set_error (bfd_error_no_contents);
2079 return -1;
2080 }
2081
2082 vaddr = (bfd_vma) (sptr->offset);
2083
2084 start_etir_record (abfd, section->index, (uquad) sptr->offset,
2085 FALSE);
2086
2087 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per vms_section */
2088 {
2089
2090 if (section->flags & SEC_RELOC) /* check for relocs */
2091 {
2092 arelent **rptr = section->orelocation;
2093 int i = section->reloc_count;
2094
2095 for (;;)
2096 {
2097 bfd_size_type addr = (*rptr)->address;
2098 bfd_size_type len = bfd_get_reloc_size ((*rptr)->howto);
2099 if (sptr->offset < addr) /* sptr starts before reloc */
2100 {
2101 bfd_size_type before = addr - sptr->offset;
2102 if (sptr->size <= before) /* complete before */
2103 {
2104 sto_imm (abfd, sptr, vaddr, section->index);
2105 vaddr += sptr->size;
2106 break;
2107 }
2108 else /* partly before */
2109 {
2110 int after = sptr->size - before;
2111 sptr->size = before;
2112 sto_imm (abfd, sptr, vaddr, section->index);
2113 vaddr += sptr->size;
2114 sptr->contents += before;
2115 sptr->offset += before;
2116 sptr->size = after;
2117 }
2118 }
2119 else if (sptr->offset == addr) /* sptr starts at reloc */
2120 {
2121 asymbol *sym = *(*rptr)->sym_ptr_ptr;
2122 asection *sec = sym->section;
2123
2124 switch ((*rptr)->howto->type)
2125 {
2126 case ALPHA_R_IGNORE:
2127 break;
2128
2129 case ALPHA_R_REFLONG:
2130 {
2131 if (bfd_is_und_section (sym->section))
2132 {
2133 int slen = strlen ((char *) sym->name);
2134 char *hash;
2135
2136 if (_bfd_vms_output_check (abfd, slen) < 0)
2137 {
2138 end_etir_record (abfd);
2139 start_etir_record (abfd,
2140 section->index,
2141 vaddr, FALSE);
2142 }
2143 _bfd_vms_output_begin (abfd,
2144 ETIR_S_C_STO_GBL_LW,
2145 -1);
2146 hash = (_bfd_vms_length_hash_symbol
2147 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2148 _bfd_vms_output_counted (abfd, hash);
2149 _bfd_vms_output_flush (abfd);
2150 }
2151 else if (bfd_is_abs_section (sym->section))
2152 {
2153 if (_bfd_vms_output_check (abfd, 16) < 0)
2154 {
2155 end_etir_record (abfd);
2156 start_etir_record (abfd,
2157 section->index,
2158 vaddr, FALSE);
2159 }
2160 _bfd_vms_output_begin (abfd,
2161 ETIR_S_C_STA_LW,
2162 -1);
2163 _bfd_vms_output_quad (abfd,
2164 (uquad) sym->value);
2165 _bfd_vms_output_flush (abfd);
2166 _bfd_vms_output_begin (abfd,
2167 ETIR_S_C_STO_LW,
2168 -1);
2169 _bfd_vms_output_flush (abfd);
2170 }
2171 else
2172 {
2173 if (_bfd_vms_output_check (abfd, 32) < 0)
2174 {
2175 end_etir_record (abfd);
2176 start_etir_record (abfd,
2177 section->index,
2178 vaddr, FALSE);
2179 }
2180 _bfd_vms_output_begin (abfd,
2181 ETIR_S_C_STA_PQ,
2182 -1);
2183 _bfd_vms_output_long (abfd,
2184 (unsigned long) (sec->index));
2185 _bfd_vms_output_quad (abfd,
2186 ((uquad) (*rptr)->addend
2187 + (uquad) sym->value));
2188 _bfd_vms_output_flush (abfd);
2189 _bfd_vms_output_begin (abfd,
2190 ETIR_S_C_STO_LW,
2191 -1);
2192 _bfd_vms_output_flush (abfd);
2193 }
2194 }
2195 break;
2196
2197 case ALPHA_R_REFQUAD:
2198 {
2199 if (bfd_is_und_section (sym->section))
2200 {
2201 int slen = strlen ((char *) sym->name);
2202 char *hash;
2203 if (_bfd_vms_output_check (abfd, slen) < 0)
2204 {
2205 end_etir_record (abfd);
2206 start_etir_record (abfd,
2207 section->index,
2208 vaddr, FALSE);
2209 }
2210 _bfd_vms_output_begin (abfd,
2211 ETIR_S_C_STO_GBL,
2212 -1);
2213 hash = (_bfd_vms_length_hash_symbol
2214 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2215 _bfd_vms_output_counted (abfd, hash);
2216 _bfd_vms_output_flush (abfd);
2217 }
2218 else if (bfd_is_abs_section (sym->section))
2219 {
2220 if (_bfd_vms_output_check (abfd, 16) < 0)
2221 {
2222 end_etir_record (abfd);
2223 start_etir_record (abfd,
2224 section->index,
2225 vaddr, FALSE);
2226 }
2227 _bfd_vms_output_begin (abfd,
2228 ETIR_S_C_STA_QW,
2229 -1);
2230 _bfd_vms_output_quad (abfd,
2231 (uquad) sym->value);
2232 _bfd_vms_output_flush (abfd);
2233 _bfd_vms_output_begin (abfd,
2234 ETIR_S_C_STO_QW,
2235 -1);
2236 _bfd_vms_output_flush (abfd);
2237 }
2238 else
2239 {
2240 if (_bfd_vms_output_check (abfd, 32) < 0)
2241 {
2242 end_etir_record (abfd);
2243 start_etir_record (abfd,
2244 section->index,
2245 vaddr, FALSE);
2246 }
2247 _bfd_vms_output_begin (abfd,
2248 ETIR_S_C_STA_PQ,
2249 -1);
2250 _bfd_vms_output_long (abfd,
2251 (unsigned long) (sec->index));
2252 _bfd_vms_output_quad (abfd,
2253 ((uquad) (*rptr)->addend
2254 + (uquad) sym->value));
2255 _bfd_vms_output_flush (abfd);
2256 _bfd_vms_output_begin (abfd,
2257 ETIR_S_C_STO_OFF,
2258 -1);
2259 _bfd_vms_output_flush (abfd);
2260 }
2261 }
2262 break;
2263
2264 case ALPHA_R_HINT:
2265 {
2266 int hint_size;
2267 char *hash ATTRIBUTE_UNUSED;
2268
2269 hint_size = sptr->size;
2270 sptr->size = len;
2271 sto_imm (abfd, sptr, vaddr, section->index);
2272 sptr->size = hint_size;
2273#if 0
2274 vms_output_begin (abfd,
2275 ETIR_S_C_STO_HINT_GBL, -1);
2276 vms_output_long (abfd,
2277 (unsigned long) (sec->index));
2278 vms_output_quad (abfd, (uquad) addr);
2279
2280 hash = (_bfd_vms_length_hash_symbol
2281 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2282 vms_output_counted (abfd, hash);
2283
2284 vms_output_flush (abfd);
2285#endif
2286 }
2287 break;
2288 case ALPHA_R_LINKAGE:
2289 {
2290 char *hash;
2291
2292 if (_bfd_vms_output_check (abfd, 64) < 0)
2293 {
2294 end_etir_record (abfd);
2295 start_etir_record (abfd, section->index,
2296 vaddr, FALSE);
2297 }
2298 _bfd_vms_output_begin (abfd,
2299 ETIR_S_C_STC_LP_PSB,
2300 -1);
2301 _bfd_vms_output_long (abfd,
2302 (unsigned long) PRIV (vms_linkage_index));
2303 PRIV (vms_linkage_index) += 2;
2304 hash = (_bfd_vms_length_hash_symbol
2305 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2306 _bfd_vms_output_counted (abfd, hash);
2307 _bfd_vms_output_byte (abfd, 0);
2308 _bfd_vms_output_flush (abfd);
2309 }
2310 break;
2311
2312 case ALPHA_R_CODEADDR:
2313 {
2314 int slen = strlen ((char *) sym->name);
2315 char *hash;
2316 if (_bfd_vms_output_check (abfd, slen) < 0)
2317 {
2318 end_etir_record (abfd);
2319 start_etir_record (abfd,
2320 section->index,
2321 vaddr, FALSE);
2322 }
2323 _bfd_vms_output_begin (abfd,
2324 ETIR_S_C_STO_CA,
2325 -1);
2326 hash = (_bfd_vms_length_hash_symbol
2327 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2328 _bfd_vms_output_counted (abfd, hash);
2329 _bfd_vms_output_flush (abfd);
2330 }
2331 break;
2332
2333 default:
2334 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2335 (*rptr)->howto->name);
2336 break;
2337 }
2338
2339 vaddr += len;
2340
2341 if (len == sptr->size)
2342 {
2343 break;
2344 }
2345 else
2346 {
2347 sptr->contents += len;
2348 sptr->offset += len;
2349 sptr->size -= len;
2350 i--;
2351 rptr++;
2352 }
2353 }
2354 else /* sptr starts after reloc */
2355 {
2356 i--; /* check next reloc */
2357 rptr++;
2358 }
2359
2360 if (i==0) /* all reloc checked */
2361 {
2362 if (sptr->size > 0)
2363 {
2364 /* dump rest */
2365 sto_imm (abfd, sptr, vaddr, section->index);
2366 vaddr += sptr->size;
2367 }
2368 break;
2369 }
2370 } /* for (;;) */
2371 } /* if SEC_RELOC */
2372 else /* no relocs, just dump */
2373 {
2374 sto_imm (abfd, sptr, vaddr, section->index);
2375 vaddr += sptr->size;
2376 }
2377
2378 sptr = sptr->next;
2379
2380 } /* while (sptr != 0) */
2381
2382 end_etir_record (abfd);
2383
2384 } /* has_contents */
2385
2386 section = section->next;
2387 }
2388
2389 _bfd_vms_output_alignment (abfd, 2);
2390 return 0;
2391}
2392
2393/* Write traceback data for bfd abfd. */
2394
2395int
2396_bfd_vms_write_tbt (abfd, objtype)
2397 bfd *abfd ATTRIBUTE_UNUSED;
2398 int objtype ATTRIBUTE_UNUSED;
2399{
2400#if VMS_DEBUG
2401 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2402#endif
2403
2404 return 0;
2405}
2406
2407/* Write debug info for bfd abfd. */
2408
2409int
2410_bfd_vms_write_dbg (abfd, objtype)
2411 bfd *abfd ATTRIBUTE_UNUSED;
2412 int objtype ATTRIBUTE_UNUSED;
2413{
2414#if VMS_DEBUG
2415 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);
2416#endif
2417
2418 return 0;
2419}
Note: See TracBrowser for help on using the repository browser.