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, 2004, 2005
4 Free Software Foundation, Inc.
6 TIR record handling functions
7 ETIR record handling functions
9 go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
12 Written by Klaus K"ampf (kkaempf@rmi.de)
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.
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.
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. */
28 /* The following type abbreviations are used:
30 cs counted string (ascii string with length byte)
32 sh short (2 byte, 16 bit)
33 lw longword (4 byte, 32 bit)
34 qw quadword (8 byte, 64 bit)
44 static void image_set_ptr
45 PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
46 static void image_inc_ptr
47 PARAMS ((bfd
*abfd
, uquad offset
));
48 static void image_dump
49 PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
50 static void image_write_b
51 PARAMS ((bfd
*abfd
, unsigned int value
));
52 static void image_write_w
53 PARAMS ((bfd
*abfd
, unsigned int value
));
54 static void image_write_l
55 PARAMS ((bfd
*abfd
, unsigned long value
));
56 static void image_write_q
57 PARAMS ((bfd
*abfd
, uquad value
));
58 static int check_section
59 PARAMS ((bfd
*, int));
60 static bfd_boolean etir_sta
61 PARAMS ((bfd
*, int, unsigned char *));
62 static bfd_boolean etir_sto
63 PARAMS ((bfd
*, int, unsigned char *));
64 static bfd_boolean etir_opr
65 PARAMS ((bfd
*, int, unsigned char *));
66 static bfd_boolean etir_ctl
67 PARAMS ((bfd
*, int, unsigned char *));
68 static bfd_boolean etir_stc
69 PARAMS ((bfd
*, int, unsigned char *));
70 static asection
*new_section
71 PARAMS ((bfd
*, int));
72 static int alloc_section
73 PARAMS ((bfd
*, unsigned int));
75 PARAMS ((bfd
*, int, unsigned char *));
76 static int analyze_tir
77 PARAMS ((bfd
*, unsigned char *, unsigned int));
78 static int analyze_etir
79 PARAMS ((bfd
*, unsigned char *, unsigned int));
80 static unsigned char * tir_opr
81 PARAMS ((bfd
*, unsigned char *));
82 static const char * tir_cmd_name
84 static const char * cmd_name
89 check_section (abfd
, size
)
95 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
96 if (offset
+ size
> PRIV (image_section
)->size
)
98 PRIV (image_section
)->contents
99 = bfd_realloc (PRIV (image_section
)->contents
, offset
+ size
);
100 if (PRIV (image_section
)->contents
== 0)
102 (*_bfd_error_handler
) (_("No Mem !"));
105 PRIV (image_section
)->size
= offset
+ size
;
106 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
112 /* Routines to fill sections contents during tir/etir read. */
114 /* Initialize image buffer pointer to be filled. */
117 image_set_ptr (abfd
, psect
, offset
)
123 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
124 psect
, PRIV (sections
)[psect
]->name
, offset
);
127 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
128 PRIV (image_section
) = PRIV (sections
)[psect
];
132 /* Increment image buffer pointer by offset. */
135 image_inc_ptr (abfd
, offset
)
140 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
143 PRIV (image_ptr
) += offset
;
148 /* Dump multiple bytes to section image. */
151 image_dump (abfd
, ptr
, size
, offset
)
155 int offset ATTRIBUTE_UNUSED
;
158 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
160 _bfd_hexdump (9, ptr
, size
, offset
);
163 if (PRIV (is_vax
) && check_section (abfd
, size
))
167 *PRIV (image_ptr
)++ = *ptr
++;
171 /* Write byte to section image. */
174 image_write_b (abfd
, value
)
179 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value
);
182 if (PRIV (is_vax
) && check_section (abfd
, 1))
185 *PRIV (image_ptr
)++ = (value
& 0xff);
189 /* Write 2-byte word to image. */
192 image_write_w (abfd
, value
)
197 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value
);
200 if (PRIV (is_vax
) && check_section (abfd
, 2))
203 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
204 PRIV (image_ptr
) += 2;
209 /* Write 4-byte long to image. */
212 image_write_l (abfd
, value
)
217 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
220 if (PRIV (is_vax
) && check_section (abfd
, 4))
223 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
224 PRIV (image_ptr
) += 4;
229 /* Write 8-byte quad to image. */
232 image_write_q (abfd
, value
)
237 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
240 if (PRIV (is_vax
) && check_section (abfd
, 8))
243 bfd_putl64 (value
, PRIV (image_ptr
));
244 PRIV (image_ptr
) += 8;
255 case ETIR_S_C_STA_GBL
: return "ETIR_S_C_STA_GBL";
256 case ETIR_S_C_STA_PQ
: return "ETIR_S_C_STA_PQ";
257 case ETIR_S_C_STA_LI
: return "ETIR_S_C_STA_LI";
258 case ETIR_S_C_STA_MOD
: return "ETIR_S_C_STA_MOD";
259 case ETIR_S_C_STA_CKARG
: return "ETIR_S_C_STA_CKARG";
260 case ETIR_S_C_STO_B
: return "ETIR_S_C_STO_B";
261 case ETIR_S_C_STO_W
: return "ETIR_S_C_STO_W";
262 case ETIR_S_C_STO_GBL
: return "ETIR_S_C_STO_GBL";
263 case ETIR_S_C_STO_CA
: return "ETIR_S_C_STO_CA";
264 case ETIR_S_C_STO_RB
: return "ETIR_S_C_STO_RB";
265 case ETIR_S_C_STO_AB
: return "ETIR_S_C_STO_AB";
266 case ETIR_S_C_STO_GBL_LW
: return "ETIR_S_C_STO_GBL_LW";
267 case ETIR_S_C_STO_LP_PSB
: return "ETIR_S_C_STO_LP_PSB";
268 case ETIR_S_C_STO_HINT_GBL
: return "ETIR_S_C_STO_HINT_GBL";
269 case ETIR_S_C_STO_HINT_PS
: return "ETIR_S_C_STO_HINT_PS";
270 case ETIR_S_C_OPR_INSV
: return "ETIR_S_C_OPR_INSV";
271 case ETIR_S_C_OPR_USH
: return "ETIR_S_C_OPR_USH";
272 case ETIR_S_C_OPR_ROT
: return "ETIR_S_C_OPR_ROT";
273 case ETIR_S_C_OPR_REDEF
: return "ETIR_S_C_OPR_REDEF";
274 case ETIR_S_C_OPR_DFLIT
: return "ETIR_S_C_OPR_DFLIT";
275 case ETIR_S_C_STC_LP
: return "ETIR_S_C_STC_LP";
276 case ETIR_S_C_STC_GBL
: return "ETIR_S_C_STC_GBL";
277 case ETIR_S_C_STC_GCA
: return "ETIR_S_C_STC_GCA";
278 case ETIR_S_C_STC_PS
: return "ETIR_S_C_STC_PS";
279 case ETIR_S_C_STC_NBH_PS
: return "ETIR_S_C_STC_NBH_PS";
280 case ETIR_S_C_STC_NOP_GBL
: return "ETIR_S_C_STC_NOP_GBL";
281 case ETIR_S_C_STC_NOP_PS
: return "ETIR_S_C_STC_NOP_PS";
282 case ETIR_S_C_STC_BSR_GBL
: return "ETIR_S_C_STC_BSR_GBL";
283 case ETIR_S_C_STC_BSR_PS
: return "ETIR_S_C_STC_BSR_PS";
284 case ETIR_S_C_STC_LDA_GBL
: return "ETIR_S_C_STC_LDA_GBL";
285 case ETIR_S_C_STC_LDA_PS
: return "ETIR_S_C_STC_LDA_PS";
286 case ETIR_S_C_STC_BOH_GBL
: return "ETIR_S_C_STC_BOH_GBL";
287 case ETIR_S_C_STC_BOH_PS
: return "ETIR_S_C_STC_BOH_PS";
288 case ETIR_S_C_STC_NBH_GBL
: return "ETIR_S_C_STC_NBH_GBL";
291 /* These names have not yet been added to this switch statement. */
295 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
301 handle sta_xxx commands in etir section
302 ptr points to data area in record
304 see table B-8 of the openVMS linker manual. */
307 etir_sta (abfd
, cmd
, ptr
)
314 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
315 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
325 stack 32 bit value of symbol (high bits set to 0) */
327 case ETIR_S_C_STA_GBL
:
330 vms_symbol_entry
*entry
;
332 name
= _bfd_vms_save_counted_string (ptr
);
333 entry
= (vms_symbol_entry
*)
334 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, FALSE
, FALSE
);
335 if (entry
== (vms_symbol_entry
*) NULL
)
338 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
339 cmd_name (cmd
), name
);
341 _bfd_vms_push (abfd
, (uquad
) 0, -1);
345 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
353 stack 32 bit value, sign extend to 64 bit */
355 case ETIR_S_C_STA_LW
:
356 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
362 stack 64 bit value of symbol */
364 case ETIR_S_C_STA_QW
:
365 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
368 /* stack psect base plus quadword offset
369 arg: lw section index
370 qw signed quadword offset (low 32 bits)
372 stack qw argument and section index
373 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
375 case ETIR_S_C_STA_PQ
:
380 psect
= bfd_getl32 (ptr
);
381 if (psect
>= PRIV (section_count
))
383 (*_bfd_error_handler
) (_("bad section index in %s"),
385 bfd_set_error (bfd_error_bad_value
);
388 dummy
= bfd_getl64 (ptr
+4);
389 _bfd_vms_push (abfd
, dummy
, (int) psect
);
393 case ETIR_S_C_STA_LI
:
394 case ETIR_S_C_STA_MOD
:
395 case ETIR_S_C_STA_CKARG
:
396 (*_bfd_error_handler
) (_("unsupported STA cmd %s"), cmd_name (cmd
));
401 (*_bfd_error_handler
) (_("reserved STA cmd %d"), cmd
);
406 _bfd_vms_debug (5, "etir_sta true\n");
416 handle sto_xxx commands in etir section
417 ptr points to data area in record
419 see table B-9 of the openVMS linker manual. */
422 etir_sto (abfd
, cmd
, ptr
)
431 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
432 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
437 /* store byte: pop stack, write byte
441 dummy
= _bfd_vms_pop (abfd
, &psect
);
442 /* FIXME: check top bits */
443 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
446 /* store word: pop stack, write word
450 dummy
= _bfd_vms_pop (abfd
, &psect
);
451 /* FIXME: check top bits */
452 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
455 /* store longword: pop stack, write longword
458 case ETIR_S_C_STO_LW
:
459 dummy
= _bfd_vms_pop (abfd
, &psect
);
460 dummy
+= (PRIV (sections
)[psect
])->vma
;
461 /* FIXME: check top bits. */
462 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
465 /* store quadword: pop stack, write quadword
468 case ETIR_S_C_STO_QW
:
469 dummy
= _bfd_vms_pop (abfd
, &psect
);
470 dummy
+= (PRIV (sections
)[psect
])->vma
;
471 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
474 /* store immediate repeated: pop stack for repeat count
478 case ETIR_S_C_STO_IMMR
:
482 size
= bfd_getl32 (ptr
);
483 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
485 image_dump (abfd
, ptr
+4, size
, 0);
489 /* store global: write symbol value
490 arg: cs global symbol name. */
492 case ETIR_S_C_STO_GBL
:
494 vms_symbol_entry
*entry
;
497 name
= _bfd_vms_save_counted_string (ptr
);
498 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
500 if (entry
== (vms_symbol_entry
*) NULL
)
502 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
503 cmd_name (cmd
), name
);
508 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
));
512 /* store code address: write address of entry point
513 arg: cs global symbol name (procedure). */
515 case ETIR_S_C_STO_CA
:
517 vms_symbol_entry
*entry
;
520 name
= _bfd_vms_save_counted_string (ptr
);
521 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
523 if (entry
== (vms_symbol_entry
*) NULL
)
525 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
526 cmd_name (cmd
), name
);
530 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
534 /* Store offset to psect: pop stack, add low 32 bits to base of psect
537 case ETIR_S_C_STO_OFF
:
542 q
= _bfd_vms_pop (abfd
, &psect1
);
543 q
+= (PRIV (sections
)[psect1
])->vma
;
544 image_write_q (abfd
, q
);
549 arg: lw count of bytes
552 case ETIR_S_C_STO_IMM
:
556 size
= bfd_getl32 (ptr
);
557 image_dump (abfd
, ptr
+4, size
, 0);
561 /* This code is 'reserved to digital' according to the openVMS
562 linker manual, however it is generated by the DEC C compiler
563 and defined in the include file.
564 FIXME, since the following is just a guess
565 store global longword: store 32bit value of symbol
566 arg: cs symbol name. */
568 case ETIR_S_C_STO_GBL_LW
:
570 vms_symbol_entry
*entry
;
573 name
= _bfd_vms_save_counted_string (ptr
);
574 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
576 if (entry
== (vms_symbol_entry
*) NULL
)
579 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd
), name
);
581 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
585 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
));
589 case ETIR_S_C_STO_RB
:
590 case ETIR_S_C_STO_AB
:
591 case ETIR_S_C_STO_LP_PSB
:
592 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
595 case ETIR_S_C_STO_HINT_GBL
:
596 case ETIR_S_C_STO_HINT_PS
:
597 (*_bfd_error_handler
) (_("%s: not implemented"), cmd_name (cmd
));
601 (*_bfd_error_handler
) (_("reserved STO cmd %d"), cmd
);
608 /* Stack operator commands
609 all 32 bit signed arithmetic
610 all word just like a stack calculator
611 arguments are popped from stack, results are pushed on stack
613 see table B-10 of the openVMS linker manual. */
616 etir_opr (abfd
, cmd
, ptr
)
619 unsigned char *ptr ATTRIBUTE_UNUSED
;
624 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
625 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
630 case ETIR_S_C_OPR_NOP
: /* no-op */
633 case ETIR_S_C_OPR_ADD
: /* add */
634 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
635 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
636 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
639 case ETIR_S_C_OPR_SUB
: /* subtract */
640 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
641 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
642 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
645 case ETIR_S_C_OPR_MUL
: /* multiply */
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);
651 case ETIR_S_C_OPR_DIV
: /* divide */
652 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
653 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
655 _bfd_vms_push (abfd
, (uquad
) 0, -1);
657 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
660 case ETIR_S_C_OPR_AND
: /* logical and */
661 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
662 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
663 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
666 case ETIR_S_C_OPR_IOR
: /* logical inclusive or */
667 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
668 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
669 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
672 case ETIR_S_C_OPR_EOR
: /* logical exclusive or */
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);
678 case ETIR_S_C_OPR_NEG
: /* negate */
679 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
680 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
683 case ETIR_S_C_OPR_COM
: /* complement */
684 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
685 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
688 case ETIR_S_C_OPR_ASH
: /* arithmetic shift */
689 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
690 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
691 if (op2
< 0) /* shift right */
693 else /* shift left */
695 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
698 case ETIR_S_C_OPR_INSV
: /* insert field */
699 (void) _bfd_vms_pop (abfd
, NULL
);
700 case ETIR_S_C_OPR_USH
: /* unsigned shift */
701 case ETIR_S_C_OPR_ROT
: /* rotate */
702 case ETIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
703 case ETIR_S_C_OPR_DFLIT
: /* Define a literal. */
704 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
707 case ETIR_S_C_OPR_SEL
: /* select */
708 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
709 (void) _bfd_vms_pop (abfd
, NULL
);
712 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
713 (void) _bfd_vms_pop (abfd
, NULL
);
714 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
719 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), cmd
);
728 See table B-11 of the openVMS linker manual. */
731 etir_ctl (abfd
, cmd
, ptr
)
740 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
741 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
746 /* set relocation base: pop stack, set image location counter
749 case ETIR_S_C_CTL_SETRB
:
750 dummy
= _bfd_vms_pop (abfd
, &psect
);
751 image_set_ptr (abfd
, psect
, dummy
);
754 /* augment relocation base: increment image location counter by offset
755 arg: lw offset value */
757 case ETIR_S_C_CTL_AUGRB
:
758 dummy
= bfd_getl32 (ptr
);
759 image_inc_ptr (abfd
, dummy
);
762 /* define location: pop index, save location counter under index
765 case ETIR_S_C_CTL_DFLOC
:
766 dummy
= _bfd_vms_pop (abfd
, NULL
);
770 /* set location: pop index, restore location counter from index
773 case ETIR_S_C_CTL_STLOC
:
774 dummy
= _bfd_vms_pop (abfd
, &psect
);
778 /* stack defined location: pop index, push location counter from index
781 case ETIR_S_C_CTL_STKDL
:
782 dummy
= _bfd_vms_pop (abfd
, &psect
);
787 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), cmd
);
793 /* store conditional commands
795 See table B-12 and B-13 of the openVMS linker manual. */
798 etir_stc (abfd
, cmd
, ptr
)
801 unsigned char *ptr ATTRIBUTE_UNUSED
;
804 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
805 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
810 /* 200 Store-conditional Linkage Pair
813 case ETIR_S_C_STC_LP
:
814 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
817 /* 201 Store-conditional Linkage Pair with Procedure Signature
818 arg: lw linkage index
823 case ETIR_S_C_STC_LP_PSB
:
824 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
827 /* 202 Store-conditional Address at global address
828 arg: lw linkage index
831 case ETIR_S_C_STC_GBL
:
832 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
835 /* 203 Store-conditional Code Address at global address
836 arg: lw linkage index
837 cs procedure name. */
839 case ETIR_S_C_STC_GCA
:
840 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
843 /* 204 Store-conditional Address at psect + offset
844 arg: lw linkage index
848 case ETIR_S_C_STC_PS
:
849 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
852 /* 205 Store-conditional NOP at address of global
855 case ETIR_S_C_STC_NOP_GBL
:
857 /* 206 Store-conditional NOP at pect + offset
860 case ETIR_S_C_STC_NOP_PS
:
862 /* 207 Store-conditional BSR at global address
865 case ETIR_S_C_STC_BSR_GBL
:
867 /* 208 Store-conditional BSR at pect + offset
870 case ETIR_S_C_STC_BSR_PS
:
872 /* 209 Store-conditional LDA at global address
875 case ETIR_S_C_STC_LDA_GBL
:
877 /* 210 Store-conditional LDA at psect + offset
880 case ETIR_S_C_STC_LDA_PS
:
882 /* 211 Store-conditional BSR or Hint at global address
885 case ETIR_S_C_STC_BOH_GBL
:
887 /* 212 Store-conditional BSR or Hint at pect + offset
890 case ETIR_S_C_STC_BOH_PS
:
892 /* 213 Store-conditional NOP,BSR or HINT at global address
895 case ETIR_S_C_STC_NBH_GBL
:
897 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
900 case ETIR_S_C_STC_NBH_PS
:
906 _bfd_vms_debug (3, "reserved STC cmd %d", cmd
);
914 new_section (abfd
, idx
)
915 bfd
*abfd ATTRIBUTE_UNUSED
;
923 _bfd_vms_debug (5, "new_section %d\n", idx
);
925 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
927 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
930 strcpy (name
, sname
);
932 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
936 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
943 section
->contents
= 0;
944 section
->name
= name
;
945 section
->index
= idx
;
951 alloc_section (abfd
, idx
)
958 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
962 amt
*= sizeof (asection
*);
963 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
964 if (PRIV (sections
) == 0)
967 while (PRIV (section_count
) <= idx
)
969 PRIV (sections
)[PRIV (section_count
)]
970 = new_section (abfd
, (int) PRIV (section_count
));
971 if (PRIV (sections
)[PRIV (section_count
)] == 0)
973 PRIV (section_count
)++;
983 Handle sta_xxx commands in tir section
984 ptr points to data area in record
986 See table 7-3 of the VAX/VMS linker manual. */
988 static unsigned char *
989 tir_sta (bfd
*abfd
, unsigned char *ptr
)
994 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
1000 case TIR_S_C_STA_GBL
:
1004 stack 32 bit value of symbol (high bits set to 0). */
1007 vms_symbol_entry
*entry
;
1009 name
= _bfd_vms_save_counted_string (ptr
);
1011 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1012 if (entry
== (vms_symbol_entry
*) NULL
)
1015 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1020 case TIR_S_C_STA_SB
:
1021 /* stack signed byte
1024 stack byte value, sign extend to 32 bit. */
1025 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1028 case TIR_S_C_STA_SW
:
1029 /* stack signed short word
1032 stack 16 bit value, sign extend to 32 bit. */
1033 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1037 case TIR_S_C_STA_LW
:
1038 /* stack signed longword
1041 stack 32 bit value. */
1042 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1046 case TIR_S_C_STA_PB
:
1047 case TIR_S_C_STA_WPB
:
1048 /* stack psect base plus byte offset (word index)
1049 arg: by section index
1051 by signed byte offset. */
1053 unsigned long dummy
;
1056 if (cmd
== TIR_S_C_STA_PB
)
1060 psect
= bfd_getl16 (ptr
);
1064 if (psect
>= PRIV (section_count
))
1065 alloc_section (abfd
, psect
);
1067 dummy
= (long) *ptr
++;
1068 dummy
+= (PRIV (sections
)[psect
])->vma
;
1069 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1073 case TIR_S_C_STA_PW
:
1074 case TIR_S_C_STA_WPW
:
1075 /* stack psect base plus word offset (word index)
1076 arg: by section index
1078 sh signed short offset. */
1080 unsigned long dummy
;
1083 if (cmd
== TIR_S_C_STA_PW
)
1087 psect
= bfd_getl16 (ptr
);
1091 if (psect
>= PRIV (section_count
))
1092 alloc_section (abfd
, psect
);
1094 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1095 dummy
+= (PRIV (sections
)[psect
])->vma
;
1096 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1100 case TIR_S_C_STA_PL
:
1101 case TIR_S_C_STA_WPL
:
1102 /* stack psect base plus long offset (word index)
1103 arg: by section index
1105 lw signed longword offset. */
1107 unsigned long dummy
;
1110 if (cmd
== TIR_S_C_STA_PL
)
1114 psect
= bfd_getl16 (ptr
);
1118 if (psect
>= PRIV (section_count
))
1119 alloc_section (abfd
, psect
);
1121 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1122 dummy
+= (PRIV (sections
)[psect
])->vma
;
1123 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1127 case TIR_S_C_STA_UB
:
1128 /* stack unsigned byte
1131 stack byte value. */
1132 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1135 case TIR_S_C_STA_UW
:
1136 /* stack unsigned short word
1139 stack 16 bit value. */
1140 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1144 case TIR_S_C_STA_BFI
:
1145 /* stack byte from image
1148 case TIR_S_C_STA_WFI
:
1149 /* stack byte from image
1152 case TIR_S_C_STA_LFI
:
1153 /* stack byte from image
1155 (*_bfd_error_handler
) (_("stack-from-image not implemented"));
1158 case TIR_S_C_STA_EPM
:
1159 /* stack entry point mask
1162 stack (unsigned) entry point mask of symbol
1163 err if symbol is no entry point. */
1166 vms_symbol_entry
*entry
;
1168 name
= _bfd_vms_save_counted_string (ptr
);
1169 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1170 if (entry
== (vms_symbol_entry
*) NULL
)
1173 (*_bfd_error_handler
) (_("stack-entry-mask not fully implemented"));
1174 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1179 case TIR_S_C_STA_CKARG
:
1180 /* compare procedure argument
1183 da argument descriptor
1185 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1186 and stack TRUE (args match) or FALSE (args dont match) value. */
1187 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1188 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1191 case TIR_S_C_STA_LSY
:
1192 /* stack local symbol value
1193 arg: sh environment index
1198 vms_symbol_entry
*entry
;
1200 envidx
= bfd_getl16 (ptr
);
1202 name
= _bfd_vms_save_counted_string (ptr
);
1203 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1204 if (entry
== (vms_symbol_entry
*) NULL
)
1206 (*_bfd_error_handler
) (_("stack-local-symbol not fully implemented"));
1207 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1212 case TIR_S_C_STA_LIT
:
1214 arg: by literal index
1218 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1219 (*_bfd_error_handler
) (_("stack-literal not fully implemented"));
1222 case TIR_S_C_STA_LEPM
:
1223 /* stack local symbol entry point mask
1224 arg: sh environment index
1227 stack (unsigned) entry point mask of symbol
1228 err if symbol is no entry point. */
1232 vms_symbol_entry
*entry
;
1234 envidx
= bfd_getl16 (ptr
);
1236 name
= _bfd_vms_save_counted_string (ptr
);
1237 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1238 if (entry
== (vms_symbol_entry
*) NULL
)
1240 (*_bfd_error_handler
) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1241 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1247 (*_bfd_error_handler
) (_("reserved STA cmd %d"), ptr
[-1]);
1261 case TIR_S_C_STO_RSB
: return "TIR_S_C_STO_RSB";
1262 case TIR_S_C_STO_RSW
: return "TIR_S_C_STO_RSW";
1263 case TIR_S_C_STO_RL
: return "TIR_S_C_STO_RL";
1264 case TIR_S_C_STO_VPS
: return "TIR_S_C_STO_VPS";
1265 case TIR_S_C_STO_USB
: return "TIR_S_C_STO_USB";
1266 case TIR_S_C_STO_USW
: return "TIR_S_C_STO_USW";
1267 case TIR_S_C_STO_RUB
: return "TIR_S_C_STO_RUB";
1268 case TIR_S_C_STO_RUW
: return "TIR_S_C_STO_RUW";
1269 case TIR_S_C_STO_PIRR
: return "TIR_S_C_STO_PIRR";
1270 case TIR_S_C_OPR_INSV
: return "TIR_S_C_OPR_INSV";
1271 case TIR_S_C_OPR_DFLIT
: return "TIR_S_C_OPR_DFLIT";
1272 case TIR_S_C_OPR_REDEF
: return "TIR_S_C_OPR_REDEF";
1273 case TIR_S_C_OPR_ROT
: return "TIR_S_C_OPR_ROT";
1274 case TIR_S_C_OPR_USH
: return "TIR_S_C_OPR_USH";
1275 case TIR_S_C_OPR_ASH
: return "TIR_S_C_OPR_ASH";
1276 case TIR_S_C_CTL_DFLOC
: return "TIR_S_C_CTL_DFLOC";
1277 case TIR_S_C_CTL_STLOC
: return "TIR_S_C_CTL_STLOC";
1278 case TIR_S_C_CTL_STKDL
: return "TIR_S_C_CTL_STKDL";
1281 /* These strings have not been added yet. */
1290 handle sto_xxx commands in tir section
1291 ptr points to data area in record
1293 See table 7-4 of the VAX/VMS linker manual. */
1295 static unsigned char *
1296 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1298 unsigned long dummy
;
1303 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1308 case TIR_S_C_STO_SB
:
1309 /* store signed byte: pop stack, write byte
1311 dummy
= _bfd_vms_pop (abfd
, &psect
);
1312 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1315 case TIR_S_C_STO_SW
:
1316 /* store signed word: pop stack, write word
1318 dummy
= _bfd_vms_pop (abfd
, &psect
);
1319 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1322 case TIR_S_C_STO_LW
:
1323 /* store longword: pop stack, write longword
1325 dummy
= _bfd_vms_pop (abfd
, &psect
);
1326 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1329 case TIR_S_C_STO_BD
:
1330 /* store byte displaced: pop stack, sub lc+1, write byte
1332 dummy
= _bfd_vms_pop (abfd
, &psect
);
1333 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1334 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1337 case TIR_S_C_STO_WD
:
1338 /* store word displaced: pop stack, sub lc+2, write word
1340 dummy
= _bfd_vms_pop (abfd
, &psect
);
1341 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1342 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1345 case TIR_S_C_STO_LD
:
1346 /* store long displaced: pop stack, sub lc+4, write long
1348 dummy
= _bfd_vms_pop (abfd
, &psect
);
1349 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1350 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1353 case TIR_S_C_STO_LI
:
1354 /* store short literal: pop stack, write byte
1356 dummy
= _bfd_vms_pop (abfd
, &psect
);
1357 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1360 case TIR_S_C_STO_PIDR
:
1361 /* store position independent data reference: pop stack, write longword
1363 FIXME: incomplete ! */
1364 dummy
= _bfd_vms_pop (abfd
, &psect
);
1365 image_write_l (abfd
, dummy
& 0xffffffff);
1368 case TIR_S_C_STO_PICR
:
1369 /* store position independent code reference: pop stack, write longword
1371 FIXME: incomplete ! */
1372 dummy
= _bfd_vms_pop (abfd
, &psect
);
1373 image_write_b (abfd
, 0x9f);
1374 image_write_l (abfd
, dummy
& 0xffffffff);
1377 case TIR_S_C_STO_RIVB
:
1378 /* store repeated immediate variable bytes
1379 1-byte count n field followed by n bytes of data
1380 pop stack, write n bytes <stack> times. */
1382 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1383 while (dummy
-- > 0L)
1384 image_dump (abfd
, ptr
, size
, 0);
1389 /* store byte from top longword. */
1390 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1391 image_write_b (abfd
, dummy
& 0xff);
1395 /* store word from top longword. */
1396 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1397 image_write_w (abfd
, dummy
& 0xffff);
1400 case TIR_S_C_STO_RB
:
1401 /* store repeated byte from top longword. */
1402 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1403 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1405 image_write_b (abfd
, dummy
& 0xff);
1408 case TIR_S_C_STO_RW
:
1409 /* store repeated word from top longword. */
1410 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1411 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1413 image_write_w (abfd
, dummy
& 0xffff);
1416 case TIR_S_C_STO_RSB
:
1417 case TIR_S_C_STO_RSW
:
1418 case TIR_S_C_STO_RL
:
1419 case TIR_S_C_STO_VPS
:
1420 case TIR_S_C_STO_USB
:
1421 case TIR_S_C_STO_USW
:
1422 case TIR_S_C_STO_RUB
:
1423 case TIR_S_C_STO_RUW
:
1424 case TIR_S_C_STO_PIRR
:
1425 (*_bfd_error_handler
) (_("%s: not implemented"), tir_cmd_name (ptr
[-1]));
1429 (*_bfd_error_handler
) (_("reserved STO cmd %d"), ptr
[-1]);
1436 /* stack operator commands
1437 all 32 bit signed arithmetic
1438 all word just like a stack calculator
1439 arguments are popped from stack, results are pushed on stack
1441 See table 7-5 of the VAX/VMS linker manual. */
1443 static unsigned char *
1451 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1457 case TIR_S_C_OPR_NOP
: /* no-op */
1460 case TIR_S_C_OPR_ADD
: /* add */
1461 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1462 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1463 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1466 case TIR_S_C_OPR_SUB
: /* subtract */
1467 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1468 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1469 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1472 case TIR_S_C_OPR_MUL
: /* multiply */
1473 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1474 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1475 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1478 case TIR_S_C_OPR_DIV
: /* divide */
1479 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1480 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1482 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1484 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1487 case TIR_S_C_OPR_AND
: /* logical and */
1488 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1489 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1490 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1493 case TIR_S_C_OPR_IOR
: /* logical inclusive or */
1494 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1495 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1496 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1499 case TIR_S_C_OPR_EOR
: /* logical exclusive or */
1500 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1501 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1502 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1505 case TIR_S_C_OPR_NEG
: /* negate */
1506 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1507 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1510 case TIR_S_C_OPR_COM
: /* complement */
1511 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1512 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1515 case TIR_S_C_OPR_INSV
: /* insert field */
1516 (void) _bfd_vms_pop (abfd
, NULL
);
1517 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1518 tir_cmd_name (ptr
[-1]));
1521 case TIR_S_C_OPR_ASH
: /* arithmetic shift */
1522 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1523 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1524 if (HIGHBIT (op1
)) /* shift right */
1526 else /* shift left */
1528 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1529 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1530 tir_cmd_name (ptr
[-1]));
1533 case TIR_S_C_OPR_USH
: /* unsigned shift */
1534 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1535 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1536 if (HIGHBIT (op1
)) /* shift right */
1538 else /* shift left */
1540 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1541 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1542 tir_cmd_name (ptr
[-1]));
1545 case TIR_S_C_OPR_ROT
: /* rotate */
1546 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1547 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1548 if (HIGHBIT (0)) /* shift right */
1550 else /* shift left */
1552 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1553 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1554 tir_cmd_name (ptr
[-1]));
1557 case TIR_S_C_OPR_SEL
: /* select */
1558 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1559 (void) _bfd_vms_pop (abfd
, NULL
);
1562 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1563 (void) _bfd_vms_pop (abfd
, NULL
);
1564 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1568 case TIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
1569 case TIR_S_C_OPR_DFLIT
: /* Define a literal. */
1570 (*_bfd_error_handler
) (_("%s: not supported"),
1571 tir_cmd_name (ptr
[-1]));
1575 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), ptr
[-1]);
1584 See table 7-6 of the VAX/VMS linker manual. */
1586 static unsigned char *
1587 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1589 unsigned long dummy
;
1593 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1598 case TIR_S_C_CTL_SETRB
:
1599 /* Set relocation base: pop stack, set image location counter
1601 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1602 if (psect
>= PRIV (section_count
))
1603 alloc_section (abfd
, psect
);
1604 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1607 case TIR_S_C_CTL_AUGRB
:
1608 /* Augment relocation base: increment image location counter by offset
1609 arg: lw offset value. */
1610 dummy
= bfd_getl32 (ptr
);
1611 image_inc_ptr (abfd
, (uquad
) dummy
);
1614 case TIR_S_C_CTL_DFLOC
:
1615 /* Define location: pop index, save location counter under index
1617 dummy
= _bfd_vms_pop (abfd
, NULL
);
1618 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1619 tir_cmd_name (ptr
[-1]));
1622 case TIR_S_C_CTL_STLOC
:
1623 /* Set location: pop index, restore location counter from index
1625 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1626 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1627 tir_cmd_name (ptr
[-1]));
1630 case TIR_S_C_CTL_STKDL
:
1631 /* Stack defined location: pop index, push location counter from index
1633 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1634 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1635 tir_cmd_name (ptr
[-1]));
1639 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), ptr
[-1]);
1645 /* Handle command from TIR section. */
1647 static unsigned char *
1648 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1654 unsigned char * (*explain
) (bfd
*, unsigned char *);
1658 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1659 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1660 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1661 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1667 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1668 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1671 if (*ptr
& 0x80) /* store immediate */
1673 i
= 128 - (*ptr
++ & 0x7f);
1674 image_dump (abfd
, ptr
, i
, 0);
1679 while (tir_table
[i
].mincod
>= 0)
1681 if ( (tir_table
[i
].mincod
<= *ptr
)
1682 && (*ptr
<= tir_table
[i
].maxcod
))
1684 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1689 if (tir_table
[i
].mincod
< 0)
1691 (*_bfd_error_handler
) (_("obj code %d not found"), *ptr
);
1699 /* Handle command from ETIR section. */
1702 etir_cmd (abfd
, cmd
, ptr
)
1711 bfd_boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1715 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1716 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1717 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1718 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1719 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1726 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1727 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1730 while (etir_table
[i
].mincod
>= 0)
1732 if ( (etir_table
[i
].mincod
<= cmd
)
1733 && (cmd
<= etir_table
[i
].maxcod
))
1735 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1743 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1748 /* Text Information and Relocation Records (OBJ$C_TIR)
1749 handle tir record. */
1752 analyze_tir (abfd
, ptr
, length
)
1755 unsigned int length
;
1757 unsigned char *maxptr
;
1760 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1763 maxptr
= ptr
+ length
;
1765 while (ptr
< maxptr
)
1767 ptr
= tir_cmd (abfd
, ptr
);
1775 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1776 handle etir record. */
1779 analyze_etir (abfd
, ptr
, length
)
1782 unsigned int length
;
1785 unsigned char *maxptr
;
1789 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1792 maxptr
= ptr
+ length
;
1794 while (ptr
< maxptr
)
1796 cmd
= bfd_getl16 (ptr
);
1797 length
= bfd_getl16 (ptr
+ 2);
1798 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1805 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1811 /* Process ETIR record
1812 Return 0 on success, -1 on error. */
1815 _bfd_vms_slurp_tir (abfd
, objtype
)
1822 _bfd_vms_debug (2, "TIR/ETIR\n");
1828 PRIV (vms_rec
) += 4; /* skip type, size */
1829 PRIV (rec_size
) -= 4;
1830 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1833 PRIV (vms_rec
) += 1; /* skip type */
1834 PRIV (rec_size
) -= 1;
1835 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1845 /* Process EDBG record
1846 Return 0 on success, -1 on error
1848 Not implemented yet. */
1851 _bfd_vms_slurp_dbg (abfd
, objtype
)
1853 int objtype ATTRIBUTE_UNUSED
;
1856 _bfd_vms_debug (2, "DBG/EDBG\n");
1859 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1863 /* Process ETBT record
1864 Return 0 on success, -1 on error
1866 Not implemented yet. */
1869 _bfd_vms_slurp_tbt (abfd
, objtype
)
1870 bfd
*abfd ATTRIBUTE_UNUSED
;
1871 int objtype ATTRIBUTE_UNUSED
;
1874 _bfd_vms_debug (2, "TBT/ETBT\n");
1880 /* Process LNK record
1881 Return 0 on success, -1 on error
1883 Not implemented yet. */
1886 _bfd_vms_slurp_lnk (abfd
, objtype
)
1887 bfd
*abfd ATTRIBUTE_UNUSED
;
1888 int objtype ATTRIBUTE_UNUSED
;
1891 _bfd_vms_debug (2, "LNK\n");
1897 /* WRITE ETIR SECTION
1899 This is still under construction and therefore not documented. */
1901 static void start_etir_record
1902 PARAMS ((bfd
*abfd
, int index
, uquad offset
, bfd_boolean justoffset
));
1904 PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1905 static void end_etir_record
1906 PARAMS ((bfd
*abfd
));
1909 sto_imm (abfd
, sptr
, vaddr
, index
)
1917 unsigned char *cptr
;
1920 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1921 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
1925 cptr
= sptr
->contents
;
1929 size
= ssize
; /* try all the rest */
1931 if (_bfd_vms_output_check (abfd
, size
) < 0)
1932 { /* doesn't fit, split ! */
1933 end_etir_record (abfd
);
1934 start_etir_record (abfd
, index
, vaddr
, FALSE
);
1935 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
1936 if (size
> ssize
) /* more than what's left ? */
1940 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
1941 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
1942 _bfd_vms_output_dump (abfd
, cptr
, size
);
1943 _bfd_vms_output_flush (abfd
);
1946 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
1947 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
1956 /* Start ETIR record for section #index at virtual addr offset. */
1959 start_etir_record (abfd
, index
, offset
, justoffset
)
1963 bfd_boolean justoffset
;
1967 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
1968 _bfd_vms_output_push (abfd
);
1971 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
1972 _bfd_vms_output_long (abfd
, (unsigned long) index
);
1973 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
1974 _bfd_vms_output_flush (abfd
);
1976 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
1977 _bfd_vms_output_flush (abfd
);
1980 /* End etir record. */
1983 end_etir_record (abfd
)
1986 _bfd_vms_output_pop (abfd
);
1987 _bfd_vms_output_end (abfd
);
1990 /* Write section contents for bfd abfd. */
1993 _bfd_vms_write_tir (abfd
, objtype
)
1995 int objtype ATTRIBUTE_UNUSED
;
2002 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2005 _bfd_vms_output_alignment (abfd
, 4);
2008 PRIV (vms_linkage_index
) = 1;
2010 /* Dump all other sections. */
2012 section
= abfd
->sections
;
2014 while (section
!= NULL
)
2018 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2019 section
->index
, section
->name
,
2020 (int) (section
->size
));
2023 if (section
->flags
& SEC_RELOC
)
2027 if ((i
= section
->reloc_count
) <= 0)
2029 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2036 _bfd_vms_debug (4, "%d relocations:\n", i
);
2037 rptr
= section
->orelocation
;
2040 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2041 (*(*rptr
)->sym_ptr_ptr
)->name
,
2042 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2043 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2044 (*rptr
)->address
, (*rptr
)->addend
,
2045 bfd_get_reloc_size ((*rptr
)->howto
),
2046 (*rptr
)->howto
->name
);
2053 if ((section
->flags
& SEC_HAS_CONTENTS
)
2054 && (! bfd_is_com_section (section
)))
2056 bfd_vma vaddr
; /* Virtual addr in section. */
2058 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2061 bfd_set_error (bfd_error_no_contents
);
2065 vaddr
= (bfd_vma
) (sptr
->offset
);
2067 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2070 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2073 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2075 arelent
**rptr
= section
->orelocation
;
2076 int i
= section
->reloc_count
;
2080 bfd_size_type addr
= (*rptr
)->address
;
2081 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2082 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2084 bfd_size_type before
= addr
- sptr
->offset
;
2085 if (sptr
->size
<= before
) /* complete before */
2087 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2088 vaddr
+= sptr
->size
;
2091 else /* partly before */
2093 int after
= sptr
->size
- before
;
2094 sptr
->size
= before
;
2095 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2096 vaddr
+= sptr
->size
;
2097 sptr
->contents
+= before
;
2098 sptr
->offset
+= before
;
2102 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2104 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2105 asection
*sec
= sym
->section
;
2107 switch ((*rptr
)->howto
->type
)
2109 case ALPHA_R_IGNORE
:
2112 case ALPHA_R_REFLONG
:
2114 if (bfd_is_und_section (sym
->section
))
2116 int slen
= strlen ((char *) sym
->name
);
2119 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2121 end_etir_record (abfd
);
2122 start_etir_record (abfd
,
2126 _bfd_vms_output_begin (abfd
,
2127 ETIR_S_C_STO_GBL_LW
,
2129 hash
= (_bfd_vms_length_hash_symbol
2130 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2131 _bfd_vms_output_counted (abfd
, hash
);
2132 _bfd_vms_output_flush (abfd
);
2134 else if (bfd_is_abs_section (sym
->section
))
2136 if (_bfd_vms_output_check (abfd
, 16) < 0)
2138 end_etir_record (abfd
);
2139 start_etir_record (abfd
,
2143 _bfd_vms_output_begin (abfd
,
2146 _bfd_vms_output_quad (abfd
,
2147 (uquad
) sym
->value
);
2148 _bfd_vms_output_flush (abfd
);
2149 _bfd_vms_output_begin (abfd
,
2152 _bfd_vms_output_flush (abfd
);
2156 if (_bfd_vms_output_check (abfd
, 32) < 0)
2158 end_etir_record (abfd
);
2159 start_etir_record (abfd
,
2163 _bfd_vms_output_begin (abfd
,
2166 _bfd_vms_output_long (abfd
,
2167 (unsigned long) (sec
->index
));
2168 _bfd_vms_output_quad (abfd
,
2169 ((uquad
) (*rptr
)->addend
2170 + (uquad
) sym
->value
));
2171 _bfd_vms_output_flush (abfd
);
2172 _bfd_vms_output_begin (abfd
,
2175 _bfd_vms_output_flush (abfd
);
2180 case ALPHA_R_REFQUAD
:
2182 if (bfd_is_und_section (sym
->section
))
2184 int slen
= strlen ((char *) sym
->name
);
2186 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2188 end_etir_record (abfd
);
2189 start_etir_record (abfd
,
2193 _bfd_vms_output_begin (abfd
,
2196 hash
= (_bfd_vms_length_hash_symbol
2197 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2198 _bfd_vms_output_counted (abfd
, hash
);
2199 _bfd_vms_output_flush (abfd
);
2201 else if (bfd_is_abs_section (sym
->section
))
2203 if (_bfd_vms_output_check (abfd
, 16) < 0)
2205 end_etir_record (abfd
);
2206 start_etir_record (abfd
,
2210 _bfd_vms_output_begin (abfd
,
2213 _bfd_vms_output_quad (abfd
,
2214 (uquad
) sym
->value
);
2215 _bfd_vms_output_flush (abfd
);
2216 _bfd_vms_output_begin (abfd
,
2219 _bfd_vms_output_flush (abfd
);
2223 if (_bfd_vms_output_check (abfd
, 32) < 0)
2225 end_etir_record (abfd
);
2226 start_etir_record (abfd
,
2230 _bfd_vms_output_begin (abfd
,
2233 _bfd_vms_output_long (abfd
,
2234 (unsigned long) (sec
->index
));
2235 _bfd_vms_output_quad (abfd
,
2236 ((uquad
) (*rptr
)->addend
2237 + (uquad
) sym
->value
));
2238 _bfd_vms_output_flush (abfd
);
2239 _bfd_vms_output_begin (abfd
,
2242 _bfd_vms_output_flush (abfd
);
2250 char *hash ATTRIBUTE_UNUSED
;
2252 hint_size
= sptr
->size
;
2254 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2255 sptr
->size
= hint_size
;
2258 case ALPHA_R_LINKAGE
:
2262 if (_bfd_vms_output_check (abfd
, 64) < 0)
2264 end_etir_record (abfd
);
2265 start_etir_record (abfd
, section
->index
,
2268 _bfd_vms_output_begin (abfd
,
2269 ETIR_S_C_STC_LP_PSB
,
2271 _bfd_vms_output_long (abfd
,
2272 (unsigned long) PRIV (vms_linkage_index
));
2273 PRIV (vms_linkage_index
) += 2;
2274 hash
= (_bfd_vms_length_hash_symbol
2275 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2276 _bfd_vms_output_counted (abfd
, hash
);
2277 _bfd_vms_output_byte (abfd
, 0);
2278 _bfd_vms_output_flush (abfd
);
2282 case ALPHA_R_CODEADDR
:
2284 int slen
= strlen ((char *) sym
->name
);
2286 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2288 end_etir_record (abfd
);
2289 start_etir_record (abfd
,
2293 _bfd_vms_output_begin (abfd
,
2296 hash
= (_bfd_vms_length_hash_symbol
2297 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2298 _bfd_vms_output_counted (abfd
, hash
);
2299 _bfd_vms_output_flush (abfd
);
2304 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2305 (*rptr
)->howto
->name
);
2311 if (len
== sptr
->size
)
2317 sptr
->contents
+= len
;
2318 sptr
->offset
+= len
;
2324 else /* sptr starts after reloc */
2326 i
--; /* check next reloc */
2330 if (i
==0) /* all reloc checked */
2335 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2336 vaddr
+= sptr
->size
;
2341 } /* if SEC_RELOC */
2342 else /* no relocs, just dump */
2344 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2345 vaddr
+= sptr
->size
;
2350 } /* while (sptr != 0) */
2352 end_etir_record (abfd
);
2354 } /* has_contents */
2356 section
= section
->next
;
2359 _bfd_vms_output_alignment (abfd
, 2);
2363 /* Write traceback data for bfd abfd. */
2366 _bfd_vms_write_tbt (abfd
, objtype
)
2367 bfd
*abfd ATTRIBUTE_UNUSED
;
2368 int objtype ATTRIBUTE_UNUSED
;
2371 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2377 /* Write debug info for bfd abfd. */
2380 _bfd_vms_write_dbg (abfd
, objtype
)
2381 bfd
*abfd ATTRIBUTE_UNUSED
;
2382 int objtype ATTRIBUTE_UNUSED
;
2385 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);