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 Free Software Foundation, Inc.
5 TIR record handling functions
6 ETIR record handling functions
8 go and read the openVMS linker manual (esp. appendix B)
9 if you don't know what's going on here :-)
11 Written by Klaus K"ampf (kkaempf@rmi.de)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 /* The following type abbreviations are used:
29 cs counted string (ascii string with length byte)
31 sh short (2 byte, 16 bit)
32 lw longword (4 byte, 32 bit)
33 qw quadword (8 byte, 64 bit)
45 static void image_set_ptr
PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
46 static void image_inc_ptr
PARAMS ((bfd
*abfd
, uquad offset
));
47 static void image_dump
PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
48 static void image_write_b
PARAMS ((bfd
*abfd
, unsigned int value
));
49 static void image_write_w
PARAMS ((bfd
*abfd
, unsigned int value
));
50 static void image_write_l
PARAMS ((bfd
*abfd
, unsigned long value
));
51 static void image_write_q
PARAMS ((bfd
*abfd
, uquad value
));
52 static int check_section
PARAMS ((bfd
*, int));
53 static boolean etir_sta
PARAMS ((bfd
*, int, unsigned char *));
54 static boolean etir_sto
PARAMS ((bfd
*, int, unsigned char *));
55 static boolean etir_opr
PARAMS ((bfd
*, int, unsigned char *));
56 static boolean etir_ctl
PARAMS ((bfd
*, int, unsigned char *));
57 static boolean etir_stc
PARAMS ((bfd
*, int, unsigned char *));
58 static asection
*new_section
PARAMS ((bfd
*, int));
59 static int alloc_section
PARAMS ((bfd
*, unsigned int));
60 static int etir_cmd
PARAMS ((bfd
*, int, unsigned char *));
61 static int analyze_tir
PARAMS ((bfd
*, unsigned char *, unsigned int));
62 static int analyze_etir
PARAMS ((bfd
*, unsigned char *, unsigned int));
64 /*-----------------------------------------------------------------------------*/
67 check_section (abfd
, size
)
73 offset
= PRIV(image_ptr
) - PRIV(image_section
)->contents
;
74 if ((bfd_size_type
) (offset
+ size
) > PRIV(image_section
)->_raw_size
)
76 PRIV(image_section
)->contents
= bfd_realloc (PRIV(image_section
)->contents
, offset
+ size
);
77 if (PRIV(image_section
)->contents
== 0)
79 (*_bfd_error_handler
) (_("No Mem !"));
82 PRIV(image_section
)->_raw_size
= offset
+ size
;
83 PRIV(image_ptr
) = PRIV(image_section
)->contents
+ offset
;
89 /* routines to fill sections contents during tir/etir read */
91 /* Initialize image buffer pointer to be filled */
94 image_set_ptr (abfd
, psect
, offset
)
100 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
101 psect
, PRIV(sections
)[psect
]->name
, offset
);
104 PRIV(image_ptr
) = PRIV(sections
)[psect
]->contents
+ offset
;
105 PRIV(image_section
) = PRIV(sections
)[psect
];
109 /* Increment image buffer pointer by offset */
112 image_inc_ptr (abfd
, offset
)
117 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
120 PRIV(image_ptr
) += offset
;
125 /* Dump multiple bytes to section image */
128 image_dump (abfd
, ptr
, size
, offset
)
132 int offset ATTRIBUTE_UNUSED
;
135 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
, PRIV(image_ptr
));
136 _bfd_hexdump (9, ptr
, size
, offset
);
139 if (PRIV(is_vax
) && check_section (abfd
, size
))
143 *PRIV(image_ptr
)++ = *ptr
++;
147 /* Write byte to section image */
150 image_write_b (abfd
, value
)
155 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int)value
);
158 if (PRIV(is_vax
) && check_section (abfd
, 1))
161 *PRIV(image_ptr
)++ = (value
& 0xff);
165 /* Write 2-byte word to image */
168 image_write_w (abfd
, value
)
173 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int)value
);
176 if (PRIV(is_vax
) && check_section (abfd
, 2))
179 bfd_putl16 (value
, PRIV(image_ptr
));
180 PRIV(image_ptr
) += 2;
185 /* Write 4-byte long to image */
188 image_write_l (abfd
, value
)
193 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
196 if (PRIV(is_vax
) && check_section (abfd
, 4))
199 bfd_putl32 (value
, PRIV(image_ptr
));
200 PRIV(image_ptr
) += 4;
205 /* Write 8-byte quad to image */
208 image_write_q (abfd
, value
)
213 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
216 if (PRIV(is_vax
) && check_section (abfd
, 8))
219 bfd_putl64 (value
, PRIV(image_ptr
));
220 PRIV(image_ptr
) += 8;
226 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
232 handle sta_xxx commands in etir section
233 ptr points to data area in record
235 see table B-8 of the openVMS linker manual */
238 etir_sta (abfd
, cmd
, ptr
)
245 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
246 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
256 stack 32 bit value of symbol (high bits set to 0) */
258 case ETIR_S_C_STA_GBL
:
261 vms_symbol_entry
*entry
;
263 name
= _bfd_vms_save_counted_string (ptr
);
264 entry
= (vms_symbol_entry
*)
265 bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
266 if (entry
== (vms_symbol_entry
*)NULL
)
269 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name
);
271 _bfd_vms_push (abfd
, (uquad
)0, -1);
275 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
283 stack 32 bit value, sign extend to 64 bit */
285 case ETIR_S_C_STA_LW
:
286 _bfd_vms_push (abfd
, (uquad
)bfd_getl32 (ptr
), -1);
292 stack 64 bit value of symbol */
294 case ETIR_S_C_STA_QW
:
295 _bfd_vms_push (abfd
, (uquad
)bfd_getl64(ptr
), -1);
298 /* stack psect base plus quadword offset
299 arg: lw section index
300 qw signed quadword offset (low 32 bits)
302 stack qw argument and section index
303 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
305 case ETIR_S_C_STA_PQ
:
310 psect
= bfd_getl32 (ptr
);
311 if (psect
>= PRIV(section_count
))
313 (*_bfd_error_handler
) (_("Bad section index in ETIR_S_C_STA_PQ"));
314 bfd_set_error (bfd_error_bad_value
);
317 dummy
= bfd_getl64 (ptr
+4);
318 _bfd_vms_push (abfd
, dummy
, psect
);
322 /* all not supported */
324 case ETIR_S_C_STA_LI
:
325 case ETIR_S_C_STA_MOD
:
326 case ETIR_S_C_STA_CKARG
:
328 (*_bfd_error_handler
) (_("Unsupported STA cmd %d"), cmd
);
333 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), cmd
);
338 _bfd_vms_debug (5, "etir_sta true\n");
348 handle sto_xxx commands in etir section
349 ptr points to data area in record
351 see table B-9 of the openVMS linker manual */
354 etir_sto (abfd
, cmd
, ptr
)
363 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
364 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
370 /* store byte: pop stack, write byte
374 dummy
= _bfd_vms_pop (abfd
, &psect
);
376 if (is_share
) /* FIXME */
377 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: byte fixups not supported");
379 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
382 /* store word: pop stack, write word
386 dummy
= _bfd_vms_pop (abfd
, &psect
);
388 if (is_share
) /* FIXME */
389 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: word fixups not supported");
391 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
394 /* store longword: pop stack, write longword
397 case ETIR_S_C_STO_LW
:
398 dummy
= _bfd_vms_pop (abfd
, &psect
);
399 dummy
+= (PRIV(sections
)[psect
])->vma
;
400 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
403 /* store quadword: pop stack, write quadword
406 case ETIR_S_C_STO_QW
:
407 dummy
= _bfd_vms_pop (abfd
, &psect
);
408 dummy
+= (PRIV(sections
)[psect
])->vma
;
409 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
412 /* store immediate repeated: pop stack for repeat count
416 case ETIR_S_C_STO_IMMR
:
420 size
= bfd_getl32 (ptr
);
421 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
423 image_dump (abfd
, ptr
+4, size
, 0);
427 /* store global: write symbol value
428 arg: cs global symbol name */
430 case ETIR_S_C_STO_GBL
:
432 vms_symbol_entry
*entry
;
435 name
= _bfd_vms_save_counted_string (ptr
);
436 entry
= (vms_symbol_entry
*)bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
437 if (entry
== (vms_symbol_entry
*)NULL
)
439 (*_bfd_error_handler
) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
444 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
448 /* store code address: write address of entry point
449 arg: cs global symbol name (procedure) */
451 case ETIR_S_C_STO_CA
:
453 vms_symbol_entry
*entry
;
456 name
= _bfd_vms_save_counted_string (ptr
);
457 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
458 if (entry
== (vms_symbol_entry
*)NULL
)
460 (*_bfd_error_handler
) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
465 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
471 case ETIR_S_C_STO_RB
:
472 case ETIR_S_C_STO_AB
:
473 (*_bfd_error_handler
) (_("ETIR_S_C_STO_RB/AB: Not supported"));
476 /* store offset to psect: pop stack, add low 32 bits to base of psect
479 case ETIR_S_C_STO_OFF
:
484 q
= _bfd_vms_pop (abfd
, &psect
);
485 q
+= (PRIV(sections
)[psect
])->vma
;
486 image_write_q (abfd
, q
);
491 arg: lw count of bytes
494 case ETIR_S_C_STO_IMM
:
498 size
= bfd_getl32 (ptr
);
499 image_dump (abfd
, ptr
+4, size
, 0);
503 /* this code is 'reserved to digital' according to the openVMS linker manual,
504 however it is generated by the DEC C compiler and defined in the include file.
505 FIXME, since the following is just a guess
506 store global longword: store 32bit value of symbol
507 arg: cs symbol name */
509 case ETIR_S_C_STO_GBL_LW
:
511 vms_symbol_entry
*entry
;
514 name
= _bfd_vms_save_counted_string (ptr
);
515 entry
= (vms_symbol_entry
*)bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
516 if (entry
== (vms_symbol_entry
*)NULL
)
519 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name
);
521 image_write_l (abfd
, (unsigned long)0); /* FIXME, reloc */
524 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
)); /* FIXME, reloc */
530 case ETIR_S_C_STO_LP_PSB
:
531 (*_bfd_error_handler
) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
536 case ETIR_S_C_STO_HINT_GBL
:
537 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
542 case ETIR_S_C_STO_HINT_PS
:
543 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
547 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), cmd
);
554 /* stack operator commands
555 all 32 bit signed arithmetic
556 all word just like a stack calculator
557 arguments are popped from stack, results are pushed on stack
559 see table B-10 of the openVMS linker manual */
562 etir_opr (abfd
, cmd
, ptr
)
565 unsigned char *ptr ATTRIBUTE_UNUSED
;
570 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
571 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
580 case ETIR_S_C_OPR_NOP
:
585 case ETIR_S_C_OPR_ADD
:
586 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
587 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
588 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
593 case ETIR_S_C_OPR_SUB
:
594 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
595 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
596 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
601 case ETIR_S_C_OPR_MUL
:
602 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
603 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
604 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
609 case ETIR_S_C_OPR_DIV
:
610 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
611 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
613 _bfd_vms_push (abfd
, (uquad
)0L, -1);
615 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
620 case ETIR_S_C_OPR_AND
:
621 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
622 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
623 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
626 /* logical inclusive or */
628 case ETIR_S_C_OPR_IOR
:
629 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
630 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
631 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
634 /* logical exclusive or */
636 case ETIR_S_C_OPR_EOR
:
637 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
638 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
639 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
644 case ETIR_S_C_OPR_NEG
:
645 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
646 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
651 case ETIR_S_C_OPR_COM
:
652 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
653 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
658 case ETIR_S_C_OPR_INSV
:
659 (void)_bfd_vms_pop (abfd
, NULL
);
660 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_INSV: Not supported"));
663 /* arithmetic shift */
665 case ETIR_S_C_OPR_ASH
:
666 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
667 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
668 if (op2
< 0) /* shift right */
670 else /* shift left */
672 _bfd_vms_push (abfd
, (uquad
)op1
, -1);
677 case ETIR_S_C_OPR_USH
:
678 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_USH: Not supported"));
683 case ETIR_S_C_OPR_ROT
:
684 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_ROT: Not supported"));
689 case ETIR_S_C_OPR_SEL
:
690 if ((long)_bfd_vms_pop (abfd
, NULL
) & 0x01L
)
691 (void)_bfd_vms_pop (abfd
, NULL
);
694 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
695 (void)_bfd_vms_pop (abfd
, NULL
);
696 _bfd_vms_push (abfd
, (uquad
)op1
, -1);
700 /* redefine symbol to current location */
702 case ETIR_S_C_OPR_REDEF
:
703 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_REDEF: Not supported"));
706 /* define a literal */
708 case ETIR_S_C_OPR_DFLIT
:
709 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
713 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), cmd
);
722 see table B-11 of the openVMS linker manual */
725 etir_ctl (abfd
, cmd
, ptr
)
734 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
735 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
740 /* set relocation base: pop stack, set image location counter
743 case ETIR_S_C_CTL_SETRB
:
744 dummy
= _bfd_vms_pop (abfd
, &psect
);
745 image_set_ptr (abfd
, psect
, dummy
);
748 /* augment relocation base: increment image location counter by offset
749 arg: lw offset value */
751 case ETIR_S_C_CTL_AUGRB
:
752 dummy
= bfd_getl32 (ptr
);
753 image_inc_ptr (abfd
, dummy
);
756 /* define location: pop index, save location counter under index
759 case ETIR_S_C_CTL_DFLOC
:
760 dummy
= _bfd_vms_pop (abfd
, NULL
);
764 /* set location: pop index, restore location counter from index
767 case ETIR_S_C_CTL_STLOC
:
768 dummy
= _bfd_vms_pop (abfd
, &psect
);
772 /* stack defined location: pop index, push location counter from index
775 case ETIR_S_C_CTL_STKDL
:
776 dummy
= _bfd_vms_pop (abfd
, &psect
);
781 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), cmd
);
787 /* store conditional commands
789 see table B-12 and B-13 of the openVMS linker manual */
792 etir_stc (abfd
, cmd
, ptr
)
795 unsigned char *ptr ATTRIBUTE_UNUSED
;
799 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
800 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
805 /* 200 Store-conditional Linkage Pair
808 case ETIR_S_C_STC_LP
:
809 (*_bfd_error_handler
) (_("ETIR_S_C_STC_LP: not supported"));
812 /* 201 Store-conditional Linkage Pair with Procedure Signature
813 arg: lw linkage index
818 case ETIR_S_C_STC_LP_PSB
:
819 image_inc_ptr (abfd
, 16); /* skip entry,procval */
822 /* 202 Store-conditional Address at global address
823 arg: lw linkage index
826 case ETIR_S_C_STC_GBL
:
827 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GBL: not supported"));
830 /* 203 Store-conditional Code Address at global address
831 arg: lw linkage index
834 case ETIR_S_C_STC_GCA
:
835 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GCA: not supported"));
838 /* 204 Store-conditional Address at psect + offset
839 arg: lw linkage index
843 case ETIR_S_C_STC_PS
:
844 (*_bfd_error_handler
) (_("ETIR_S_C_STC_PS: not supported"));
847 /* 205 Store-conditional NOP at address of global
850 case ETIR_S_C_STC_NOP_GBL
:
852 /* 206 Store-conditional NOP at pect + offset
855 case ETIR_S_C_STC_NOP_PS
:
857 /* 207 Store-conditional BSR at global address
860 case ETIR_S_C_STC_BSR_GBL
:
862 /* 208 Store-conditional BSR at pect + offset
865 case ETIR_S_C_STC_BSR_PS
:
867 /* 209 Store-conditional LDA at global address
870 case ETIR_S_C_STC_LDA_GBL
:
872 /* 210 Store-conditional LDA at psect + offset
875 case ETIR_S_C_STC_LDA_PS
:
877 /* 211 Store-conditional BSR or Hint at global address
880 case ETIR_S_C_STC_BOH_GBL
:
882 /* 212 Store-conditional BSR or Hint at pect + offset
885 case ETIR_S_C_STC_BOH_PS
:
887 /* 213 Store-conditional NOP,BSR or HINT at global address
890 case ETIR_S_C_STC_NBH_GBL
:
892 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
895 case ETIR_S_C_STC_NBH_PS
:
896 /* FIXME (*_bfd_error_handler) ("ETIR_S_C_STC_xx: (%d) not supported", cmd); */
901 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd
);
909 new_section (abfd
, idx
)
910 bfd
*abfd ATTRIBUTE_UNUSED
;
918 _bfd_vms_debug (5, "new_section %d\n", idx
);
920 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
922 name
= bfd_malloc (strlen (sname
) + 1);
925 strcpy (name
, sname
);
927 section
= bfd_malloc (sizeof (asection
));
931 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
936 section
->_raw_size
= 0;
938 section
->contents
= 0;
939 section
->_cooked_size
= 0;
940 section
->name
= name
;
941 section
->index
= idx
;
947 alloc_section (abfd
, idx
)
952 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
955 PRIV(sections
) = ((asection
**)
956 bfd_realloc (PRIV(sections
), (idx
+1) * sizeof (asection
*)));
957 if (PRIV(sections
) == 0)
960 while (PRIV(section_count
) <= idx
)
962 PRIV(sections
)[PRIV(section_count
)] = new_section (abfd
, PRIV(section_count
));
963 if (PRIV(sections
)[PRIV(section_count
)] == 0)
965 PRIV(section_count
)++;
976 * handle sta_xxx commands in tir section
977 * ptr points to data area in record
979 * see table 7-3 of the VAX/VMS linker manual
982 static unsigned char *
983 tir_sta (bfd
*abfd
, unsigned char *ptr
)
988 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
994 case TIR_S_C_STA_GBL
:
997 * arg: cs symbol name
999 * stack 32 bit value of symbol (high bits set to 0)
1003 vms_symbol_entry
*entry
;
1005 name
= _bfd_vms_save_counted_string (ptr
);
1007 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1008 if (entry
== (vms_symbol_entry
*)NULL
)
1011 _bfd_vms_push (abfd
, (unsigned long) (entry
->symbol
->value
), -1);
1016 case TIR_S_C_STA_SB
:
1021 * stack byte value, sign extend to 32 bit
1023 _bfd_vms_push (abfd
, (long)*ptr
++, -1);
1026 case TIR_S_C_STA_SW
:
1028 * stack signed short word
1031 * stack 16 bit value, sign extend to 32 bit
1033 _bfd_vms_push (abfd
, (long)bfd_getl16(ptr
), -1);
1037 case TIR_S_C_STA_LW
:
1039 * stack signed longword
1042 * stack 32 bit value
1044 _bfd_vms_push (abfd
, (long)bfd_getl32 (ptr
), -1);
1048 case TIR_S_C_STA_PB
:
1049 case TIR_S_C_STA_WPB
:
1051 * stack psect base plus byte offset (word index)
1052 * arg: by section index
1053 * (sh section index)
1054 * by signed byte offset
1058 unsigned long dummy
;
1061 if (cmd
== TIR_S_C_STA_PB
)
1065 psect
= bfd_getl16(ptr
);
1069 if (psect
>= PRIV(section_count
))
1071 alloc_section (abfd
, psect
);
1074 dummy
= (long)*ptr
++;
1075 dummy
+= (PRIV(sections
)[psect
])->vma
;
1076 _bfd_vms_push (abfd
, dummy
, psect
);
1080 case TIR_S_C_STA_PW
:
1081 case TIR_S_C_STA_WPW
:
1083 * stack psect base plus word offset (word index)
1084 * arg: by section index
1085 * (sh section index)
1086 * sh signed short offset
1090 unsigned long dummy
;
1093 if (cmd
== TIR_S_C_STA_PW
)
1097 psect
= bfd_getl16(ptr
);
1101 if (psect
>= PRIV(section_count
))
1103 alloc_section (abfd
, psect
);
1106 dummy
= bfd_getl16(ptr
); ptr
+=2;
1107 dummy
+= (PRIV(sections
)[psect
])->vma
;
1108 _bfd_vms_push (abfd
, dummy
, psect
);
1112 case TIR_S_C_STA_PL
:
1113 case TIR_S_C_STA_WPL
:
1115 * stack psect base plus long offset (word index)
1116 * arg: by section index
1117 * (sh section index)
1118 * lw signed longword offset
1122 unsigned long dummy
;
1125 if (cmd
== TIR_S_C_STA_PL
)
1129 psect
= bfd_getl16(ptr
);
1133 if (psect
>= PRIV(section_count
))
1135 alloc_section (abfd
, psect
);
1138 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1139 dummy
+= (PRIV(sections
)[psect
])->vma
;
1140 _bfd_vms_push (abfd
, dummy
, psect
);
1144 case TIR_S_C_STA_UB
:
1146 * stack unsigned byte
1151 _bfd_vms_push (abfd
, (unsigned long)*ptr
++, -1);
1154 case TIR_S_C_STA_UW
:
1156 * stack unsigned short word
1159 * stack 16 bit value
1161 _bfd_vms_push (abfd
, (unsigned long)bfd_getl16(ptr
), -1);
1165 case TIR_S_C_STA_BFI
:
1167 * stack byte from image
1172 case TIR_S_C_STA_WFI
:
1174 * stack byte from image
1179 case TIR_S_C_STA_LFI
:
1181 * stack byte from image
1185 (*_bfd_error_handler
) (_("Stack-from-image not implemented"));
1188 case TIR_S_C_STA_EPM
:
1190 * stack entry point mask
1191 * arg: cs symbol name
1193 * stack (unsigned) entry point mask of symbol
1194 * err if symbol is no entry point
1198 vms_symbol_entry
*entry
;
1200 name
= _bfd_vms_save_counted_string (ptr
);
1201 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1202 if (entry
== (vms_symbol_entry
*)NULL
)
1205 (*_bfd_error_handler
) (_("Stack-entry-mask not fully implemented"));
1206 _bfd_vms_push (abfd
, 0L, -1);
1211 case TIR_S_C_STA_CKARG
:
1213 * compare procedure argument
1214 * arg: cs symbol name
1216 * da argument descriptor
1218 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1219 * and stack TRUE (args match) or FALSE (args dont match) value
1221 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1222 _bfd_vms_push (abfd
, 1L, -1);
1225 case TIR_S_C_STA_LSY
:
1227 * stack local symbol value
1228 * arg: sh environment index
1234 vms_symbol_entry
*entry
;
1236 envidx
= bfd_getl16(ptr
); ptr
+= 2;
1237 name
= _bfd_vms_save_counted_string (ptr
);
1238 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1239 if (entry
== (vms_symbol_entry
*)NULL
)
1241 (*_bfd_error_handler
) (_("Stack-local-symbol not fully implemented"));
1242 _bfd_vms_push (abfd
, 0L, -1);
1247 case TIR_S_C_STA_LIT
:
1250 * arg: by literal index
1255 _bfd_vms_push (abfd
, 0L, -1);
1256 (*_bfd_error_handler
) (_("Stack-literal not fully implemented"));
1259 case TIR_S_C_STA_LEPM
:
1261 * stack local symbol entry point mask
1262 * arg: sh environment index
1265 * stack (unsigned) entry point mask of symbol
1266 * err if symbol is no entry point
1271 vms_symbol_entry
*entry
;
1273 envidx
= bfd_getl16(ptr
); ptr
+= 2;
1274 name
= _bfd_vms_save_counted_string (ptr
);
1275 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1276 if (entry
== (vms_symbol_entry
*)NULL
)
1278 (*_bfd_error_handler
) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1279 _bfd_vms_push (abfd
, 0L, -1);
1285 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), ptr
[-1]);
1296 * vax store commands
1298 * handle sto_xxx commands in tir section
1299 * ptr points to data area in record
1301 * see table 7-4 of the VAX/VMS linker manual
1304 static unsigned char *
1305 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1307 unsigned long dummy
;
1312 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1317 case TIR_S_C_STO_SB
:
1319 * store signed byte: pop stack, write byte
1322 dummy
= _bfd_vms_pop (abfd
, &psect
);
1323 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1326 case TIR_S_C_STO_SW
:
1328 * store signed word: pop stack, write word
1331 dummy
= _bfd_vms_pop (abfd
, &psect
);
1332 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1335 case TIR_S_C_STO_LW
:
1337 * store longword: pop stack, write longword
1340 dummy
= _bfd_vms_pop (abfd
, &psect
);
1341 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1344 case TIR_S_C_STO_BD
:
1346 * store byte displaced: pop stack, sub lc+1, write byte
1349 dummy
= _bfd_vms_pop (abfd
, &psect
);
1350 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 1);
1351 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1354 case TIR_S_C_STO_WD
:
1356 * store word displaced: pop stack, sub lc+2, write word
1359 dummy
= _bfd_vms_pop (abfd
, &psect
);
1360 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 2);
1361 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1363 case TIR_S_C_STO_LD
:
1365 * store long displaced: pop stack, sub lc+4, write long
1368 dummy
= _bfd_vms_pop (abfd
, &psect
);
1369 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 4);
1370 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1372 case TIR_S_C_STO_LI
:
1374 * store short literal: pop stack, write byte
1377 dummy
= _bfd_vms_pop (abfd
, &psect
);
1378 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1380 case TIR_S_C_STO_PIDR
:
1382 * store position independent data reference: pop stack, write longword
1384 * FIXME: incomplete !
1386 dummy
= _bfd_vms_pop (abfd
, &psect
);
1387 image_write_l (abfd
, dummy
& 0xffffffff);
1389 case TIR_S_C_STO_PICR
:
1391 * store position independent code reference: pop stack, write longword
1393 * FIXME: incomplete !
1395 dummy
= _bfd_vms_pop (abfd
, &psect
);
1396 image_write_b (abfd
, 0x9f);
1397 image_write_l (abfd
, dummy
& 0xffffffff);
1399 case TIR_S_C_STO_RIVB
:
1401 * store repeated immediate variable bytes
1402 * 1-byte count n field followed by n bytes of data
1403 * pop stack, write n bytes <stack> times
1406 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1407 while (dummy
-- > 0L)
1408 image_dump (abfd
, ptr
, size
, 0);
1413 * store byte from top longword
1415 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1416 image_write_b (abfd
, dummy
& 0xff);
1420 * store word from top longword
1422 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1423 image_write_w (abfd
, dummy
& 0xffff);
1425 case TIR_S_C_STO_RB
:
1427 * store repeated byte from top longword
1429 size
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1430 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1432 image_write_b (abfd
, dummy
& 0xff);
1434 case TIR_S_C_STO_RW
:
1436 * store repeated word from top longword
1438 size
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1439 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1441 image_write_w (abfd
, dummy
& 0xffff);
1444 case TIR_S_C_STO_RSB
:
1445 case TIR_S_C_STO_RSW
:
1446 case TIR_S_C_STO_RL
:
1447 case TIR_S_C_STO_VPS
:
1448 case TIR_S_C_STO_USB
:
1449 case TIR_S_C_STO_USW
:
1450 case TIR_S_C_STO_RUB
:
1451 case TIR_S_C_STO_RUW
:
1452 case TIR_S_C_STO_PIRR
:
1453 (*_bfd_error_handler
) (_("Unimplemented STO cmd %d"), ptr
[-1]);
1457 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), ptr
[-1]);
1465 * stack operator commands
1466 * all 32 bit signed arithmetic
1467 * all word just like a stack calculator
1468 * arguments are popped from stack, results are pushed on stack
1470 * see table 7-5 of the VAX/VMS linker manual
1473 static unsigned char *
1474 tir_opr (bfd
*abfd
, unsigned char *ptr
)
1479 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1485 case TIR_S_C_OPR_NOP
:
1491 case TIR_S_C_OPR_ADD
:
1495 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1496 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1497 _bfd_vms_push (abfd
, (unsigned long) (op1
+ op2
), -1);
1500 case TIR_S_C_OPR_SUB
:
1504 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1505 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1506 _bfd_vms_push (abfd
, (unsigned long) (op2
- op1
), -1);
1509 case TIR_S_C_OPR_MUL
:
1513 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1514 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1515 _bfd_vms_push (abfd
, (unsigned long) (op1
* op2
), -1);
1518 case TIR_S_C_OPR_DIV
:
1522 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1523 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1525 _bfd_vms_push (abfd
, (unsigned long)0L, -1);
1527 _bfd_vms_push (abfd
, (unsigned long) (op2
/ op1
), -1);
1530 case TIR_S_C_OPR_AND
:
1534 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1535 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1536 _bfd_vms_push (abfd
, (unsigned long) (op1
& op2
), -1);
1539 case TIR_S_C_OPR_IOR
:
1540 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1542 * logical inclusive or
1544 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1545 _bfd_vms_push (abfd
, (unsigned long) (op1
| op2
), -1);
1548 case TIR_S_C_OPR_EOR
:
1550 * logical exclusive or
1552 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1553 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1554 _bfd_vms_push (abfd
, (unsigned long) (op1
^ op2
), -1);
1557 case TIR_S_C_OPR_NEG
:
1561 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1562 _bfd_vms_push (abfd
, (unsigned long) (-op1
), -1);
1565 case TIR_S_C_OPR_COM
:
1569 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1570 _bfd_vms_push (abfd
, (unsigned long) (op1
^ -1L), -1);
1573 case TIR_S_C_OPR_INSV
:
1577 (void)_bfd_vms_pop (abfd
, NULL
);
1578 (*_bfd_error_handler
) ("TIR_S_C_OPR_INSV incomplete");
1581 case TIR_S_C_OPR_ASH
:
1585 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1586 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1587 if (HIGHBIT(op1
)) /* shift right */
1589 else /* shift left */
1591 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1592 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ASH incomplete"));
1595 case TIR_S_C_OPR_USH
:
1599 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1600 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1601 if (HIGHBIT(op1
)) /* shift right */
1603 else /* shift left */
1605 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1606 (*_bfd_error_handler
) (_("TIR_S_C_OPR_USH incomplete"));
1609 case TIR_S_C_OPR_ROT
:
1613 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1614 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1615 if (HIGHBIT(0)) /* shift right */
1617 else /* shift left */
1619 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1620 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ROT incomplete"));
1623 case TIR_S_C_OPR_SEL
:
1627 if ((long)_bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1628 (void)_bfd_vms_pop (abfd
, NULL
);
1631 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1632 (void)_bfd_vms_pop (abfd
, NULL
);
1633 _bfd_vms_push (abfd
, (unsigned long)op1
, -1);
1637 case TIR_S_C_OPR_REDEF
:
1639 * redefine symbol to current location
1641 (*_bfd_error_handler
) (_("TIR_S_C_OPR_REDEF not supported"));
1644 case TIR_S_C_OPR_DFLIT
:
1648 (*_bfd_error_handler
) (_("TIR_S_C_OPR_DFLIT not supported"));
1652 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), ptr
[-1]);
1659 static unsigned char *
1660 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1664 * see table 7-6 of the VAX/VMS linker manual
1667 unsigned long dummy
;
1671 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1676 case TIR_S_C_CTL_SETRB
:
1678 * set relocation base: pop stack, set image location counter
1681 dummy
= _bfd_vms_pop (abfd
, &psect
);
1682 if (psect
>= PRIV(section_count
))
1684 alloc_section (abfd
, psect
);
1686 image_set_ptr (abfd
, psect
, dummy
);
1688 case TIR_S_C_CTL_AUGRB
:
1690 * augment relocation base: increment image location counter by offset
1691 * arg: lw offset value
1693 dummy
= bfd_getl32 (ptr
);
1694 image_inc_ptr (abfd
, dummy
);
1696 case TIR_S_C_CTL_DFLOC
:
1698 * define location: pop index, save location counter under index
1701 dummy
= _bfd_vms_pop (abfd
, NULL
);
1702 (*_bfd_error_handler
) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1704 case TIR_S_C_CTL_STLOC
:
1706 * set location: pop index, restore location counter from index
1709 dummy
= _bfd_vms_pop (abfd
, &psect
);
1710 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1712 case TIR_S_C_CTL_STKDL
:
1714 * stack defined location: pop index, push location counter from index
1717 dummy
= _bfd_vms_pop (abfd
, &psect
);
1718 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1721 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), ptr
[-1]);
1728 * handle command from TIR section
1731 static unsigned char *
1732 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1737 unsigned char * (*explain
) (bfd
*, unsigned char *);
1739 { 0, TIR_S_C_MAXSTACOD
, tir_sta
}
1740 ,{ TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
}
1741 ,{ TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
}
1742 ,{ TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
}
1748 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1749 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
1752 if (*ptr
& 0x80) /* store immediate */
1754 i
= 128 - (*ptr
++ & 0x7f);
1755 image_dump (abfd
, ptr
, i
, 0);
1760 while (tir_table
[i
].mincod
>= 0)
1762 if ( (tir_table
[i
].mincod
<= *ptr
)
1763 && (*ptr
<= tir_table
[i
].maxcod
))
1765 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1770 if (tir_table
[i
].mincod
< 0)
1772 (*_bfd_error_handler
) (_("Obj code %d not found"), *ptr
);
1780 /* handle command from ETIR section */
1783 etir_cmd (abfd
, cmd
, ptr
)
1791 boolean (*explain
) PARAMS((bfd
*, int, unsigned char *));
1793 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1794 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1795 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1796 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1797 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1804 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1805 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
1808 while (etir_table
[i
].mincod
>= 0)
1810 if ( (etir_table
[i
].mincod
<= cmd
)
1811 && (cmd
<= etir_table
[i
].maxcod
))
1813 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1821 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1826 /* Text Information and Relocation Records (OBJ$C_TIR)
1827 handle tir record */
1830 analyze_tir (abfd
, ptr
, length
)
1833 unsigned int length
;
1835 unsigned char *maxptr
;
1838 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1841 maxptr
= ptr
+ length
;
1843 while (ptr
< maxptr
)
1845 ptr
= tir_cmd (abfd
, ptr
);
1853 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1854 handle etir record */
1857 analyze_etir (abfd
, ptr
, length
)
1860 unsigned int length
;
1863 unsigned char *maxptr
;
1867 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1870 maxptr
= ptr
+ length
;
1872 while (ptr
< maxptr
)
1874 cmd
= bfd_getl16 (ptr
);
1875 length
= bfd_getl16 (ptr
+ 2);
1876 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1883 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1889 /* process ETIR record
1891 return 0 on success, -1 on error */
1894 _bfd_vms_slurp_tir (abfd
, objtype
)
1901 _bfd_vms_debug (2, "TIR/ETIR\n");
1907 PRIV(vms_rec
) += 4; /* skip type, size */
1908 PRIV(rec_size
) -= 4;
1909 result
= analyze_etir (abfd
, PRIV(vms_rec
), PRIV(rec_size
));
1912 PRIV(vms_rec
) += 1; /* skip type */
1913 PRIV(rec_size
) -= 1;
1914 result
= analyze_tir (abfd
, PRIV(vms_rec
), PRIV(rec_size
));
1924 /* process EDBG record
1925 return 0 on success, -1 on error
1927 not implemented yet */
1930 _bfd_vms_slurp_dbg (abfd
, objtype
)
1932 int objtype ATTRIBUTE_UNUSED
;
1935 _bfd_vms_debug (2, "DBG/EDBG\n");
1938 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1942 /* process ETBT record
1943 return 0 on success, -1 on error
1945 not implemented yet */
1948 _bfd_vms_slurp_tbt (abfd
, objtype
)
1949 bfd
*abfd ATTRIBUTE_UNUSED
;
1950 int objtype ATTRIBUTE_UNUSED
;
1953 _bfd_vms_debug (2, "TBT/ETBT\n");
1959 /* process LNK record
1960 return 0 on success, -1 on error
1962 not implemented yet */
1965 _bfd_vms_slurp_lnk (abfd
, objtype
)
1966 bfd
*abfd ATTRIBUTE_UNUSED
;
1967 int objtype ATTRIBUTE_UNUSED
;
1970 _bfd_vms_debug (2, "LNK\n");
1976 /*----------------------------------------------------------------------*/
1978 /* WRITE ETIR SECTION */
1980 /* this is still under construction and therefore not documented */
1982 /*----------------------------------------------------------------------*/
1984 static void start_etir_record
PARAMS ((bfd
*abfd
, int index
, uquad offset
, boolean justoffset
));
1985 static void sto_imm
PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1986 static void end_etir_record
PARAMS ((bfd
*abfd
));
1989 sto_imm (abfd
, sptr
, vaddr
, index
)
1997 unsigned char *cptr
;
2000 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
2001 _bfd_hexdump (9, sptr
->contents
, (int)sptr
->size
, (int)vaddr
);
2005 cptr
= sptr
->contents
;
2010 size
= ssize
; /* try all the rest */
2012 if (_bfd_vms_output_check (abfd
, size
) < 0)
2013 { /* doesn't fit, split ! */
2014 end_etir_record (abfd
);
2015 start_etir_record (abfd
, index
, vaddr
, false);
2016 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
2017 if (size
> ssize
) /* more than what's left ? */
2021 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
2022 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
2023 _bfd_vms_output_dump (abfd
, cptr
, size
);
2024 _bfd_vms_output_flush (abfd
);
2027 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
2028 _bfd_hexdump (10, cptr
, (int)size
, (int)vaddr
);
2039 /*-------------------------------------------------------------------*/
2041 /* start ETIR record for section #index at virtual addr offset. */
2044 start_etir_record (abfd
, index
, offset
, justoffset
)
2052 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
2053 _bfd_vms_output_push (abfd
);
2056 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
2057 _bfd_vms_output_long (abfd
, (unsigned long)index
);
2058 _bfd_vms_output_quad (abfd
, (uquad
)offset
);
2059 _bfd_vms_output_flush (abfd
);
2061 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
2062 _bfd_vms_output_flush (abfd
);
2067 /* end etir record */
2069 end_etir_record (abfd
)
2072 _bfd_vms_output_pop (abfd
);
2073 _bfd_vms_output_end (abfd
);
2076 /* write section contents for bfd abfd */
2079 _bfd_vms_write_tir (abfd
, objtype
)
2081 int objtype ATTRIBUTE_UNUSED
;
2088 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2091 _bfd_vms_output_alignment (abfd
, 4);
2094 PRIV(vms_linkage_index
) = 1;
2096 /* dump all other sections */
2098 section
= abfd
->sections
;
2100 while (section
!= NULL
)
2104 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n", section
->index
, section
->name
, (int) (section
->_raw_size
));
2107 if (section
->flags
& SEC_RELOC
)
2111 if ((i
= section
->reloc_count
) <= 0)
2113 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2120 _bfd_vms_debug (4, "%d relocations:\n", i
);
2121 rptr
= section
->orelocation
;
2124 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2125 (*(*rptr
)->sym_ptr_ptr
)->name
,
2126 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2127 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2128 (*rptr
)->address
, (*rptr
)->addend
,
2129 bfd_get_reloc_size((*rptr
)->howto
),
2130 (*rptr
)->howto
->name
);
2137 if ((section
->flags
& SEC_HAS_CONTENTS
)
2138 && (! bfd_is_com_section (section
)))
2140 bfd_vma vaddr
; /* virtual addr in section */
2142 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2145 bfd_set_error (bfd_error_no_contents
);
2149 vaddr
= (bfd_vma
) (sptr
->offset
);
2151 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2154 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2157 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2159 arelent
**rptr
= section
->orelocation
;
2160 int i
= section
->reloc_count
;
2163 bfd_size_type addr
= (*rptr
)->address
;
2164 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2165 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2167 bfd_size_type before
= addr
- sptr
->offset
;
2168 if (sptr
->size
<= before
) /* complete before */
2170 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2171 vaddr
+= sptr
->size
;
2174 else /* partly before */
2176 int after
= sptr
->size
- before
;
2177 sptr
->size
= before
;
2178 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2179 vaddr
+= sptr
->size
;
2180 sptr
->contents
+= before
;
2181 sptr
->offset
+= before
;
2185 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2187 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2188 asection
*sec
= sym
->section
;
2190 switch ((*rptr
)->howto
->type
)
2192 case ALPHA_R_IGNORE
:
2195 case ALPHA_R_REFLONG
:
2197 if (bfd_is_und_section (sym
->section
))
2199 if (_bfd_vms_output_check (abfd
,
2200 strlen((char *)sym
->name
))
2203 end_etir_record (abfd
);
2204 start_etir_record (abfd
,
2208 _bfd_vms_output_begin (abfd
,
2209 ETIR_S_C_STO_GBL_LW
,
2211 _bfd_vms_output_counted (abfd
,
2212 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2213 _bfd_vms_output_flush (abfd
);
2215 else if (bfd_is_abs_section (sym
->section
))
2217 if (_bfd_vms_output_check (abfd
, 16) < 0)
2219 end_etir_record (abfd
);
2220 start_etir_record (abfd
,
2224 _bfd_vms_output_begin (abfd
,
2227 _bfd_vms_output_quad (abfd
,
2229 _bfd_vms_output_flush (abfd
);
2230 _bfd_vms_output_begin (abfd
,
2233 _bfd_vms_output_flush (abfd
);
2237 if (_bfd_vms_output_check (abfd
, 32) < 0)
2239 end_etir_record (abfd
);
2240 start_etir_record (abfd
,
2244 _bfd_vms_output_begin (abfd
,
2247 _bfd_vms_output_long (abfd
,
2248 (unsigned long) (sec
->index
));
2249 _bfd_vms_output_quad (abfd
,
2250 ((uquad
) (*rptr
)->addend
2251 + (uquad
)sym
->value
));
2252 _bfd_vms_output_flush (abfd
);
2253 _bfd_vms_output_begin (abfd
,
2256 _bfd_vms_output_flush (abfd
);
2261 case ALPHA_R_REFQUAD
:
2263 if (bfd_is_und_section (sym
->section
))
2265 if (_bfd_vms_output_check (abfd
,
2266 strlen((char *)sym
->name
))
2269 end_etir_record (abfd
);
2270 start_etir_record (abfd
,
2274 _bfd_vms_output_begin (abfd
,
2277 _bfd_vms_output_counted (abfd
,
2278 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2279 _bfd_vms_output_flush (abfd
);
2281 else if (bfd_is_abs_section (sym
->section
))
2283 if (_bfd_vms_output_check (abfd
, 16) < 0)
2285 end_etir_record (abfd
);
2286 start_etir_record (abfd
,
2290 _bfd_vms_output_begin (abfd
,
2293 _bfd_vms_output_quad (abfd
,
2295 _bfd_vms_output_flush (abfd
);
2296 _bfd_vms_output_begin (abfd
,
2299 _bfd_vms_output_flush (abfd
);
2303 if (_bfd_vms_output_check (abfd
, 32) < 0)
2305 end_etir_record (abfd
);
2306 start_etir_record (abfd
,
2310 _bfd_vms_output_begin (abfd
,
2313 _bfd_vms_output_long (abfd
,
2314 (unsigned long) (sec
->index
));
2315 _bfd_vms_output_quad (abfd
,
2316 ((uquad
) (*rptr
)->addend
2317 + (uquad
)sym
->value
));
2318 _bfd_vms_output_flush (abfd
);
2319 _bfd_vms_output_begin (abfd
,
2322 _bfd_vms_output_flush (abfd
);
2331 hint_size
= sptr
->size
;
2333 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2334 sptr
->size
= hint_size
;
2336 vms_output_begin(abfd
, ETIR_S_C_STO_HINT_GBL
, -1);
2337 vms_output_long(abfd
, (unsigned long) (sec
->index
));
2338 vms_output_quad(abfd
, (uquad
)addr
);
2340 vms_output_counted(abfd
, _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2341 vms_output_flush(abfd
);
2345 case ALPHA_R_LINKAGE
:
2347 if (_bfd_vms_output_check (abfd
, 64) < 0)
2349 end_etir_record (abfd
);
2350 start_etir_record (abfd
, section
->index
,
2353 _bfd_vms_output_begin (abfd
,
2354 ETIR_S_C_STC_LP_PSB
,
2356 _bfd_vms_output_long (abfd
,
2357 (unsigned long)PRIV(vms_linkage_index
));
2358 PRIV(vms_linkage_index
) += 2;
2359 _bfd_vms_output_counted (abfd
,
2360 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2361 _bfd_vms_output_byte (abfd
, 0);
2362 _bfd_vms_output_flush (abfd
);
2366 case ALPHA_R_CODEADDR
:
2368 if (_bfd_vms_output_check (abfd
,
2369 strlen((char *)sym
->name
))
2372 end_etir_record (abfd
);
2373 start_etir_record (abfd
,
2377 _bfd_vms_output_begin (abfd
,
2380 _bfd_vms_output_counted (abfd
,
2381 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2382 _bfd_vms_output_flush (abfd
);
2387 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2388 (*rptr
)->howto
->name
);
2394 if (len
== sptr
->size
)
2400 sptr
->contents
+= len
;
2401 sptr
->offset
+= len
;
2407 else /* sptr starts after reloc */
2409 i
--; /* check next reloc */
2413 if (i
==0) /* all reloc checked */
2417 sto_imm (abfd
, sptr
, vaddr
, section
->index
); /* dump rest */
2418 vaddr
+= sptr
->size
;
2423 } /* if SEC_RELOC */
2424 else /* no relocs, just dump */
2426 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2427 vaddr
+= sptr
->size
;
2432 } /* while (sptr != 0) */
2434 end_etir_record (abfd
);
2436 } /* has_contents */
2438 section
= section
->next
;
2441 _bfd_vms_output_alignment(abfd
, 2);
2445 /* write traceback data for bfd abfd */
2448 _bfd_vms_write_tbt (abfd
, objtype
)
2449 bfd
*abfd ATTRIBUTE_UNUSED
;
2450 int objtype ATTRIBUTE_UNUSED
;
2453 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2459 /* write debug info for bfd abfd */
2462 _bfd_vms_write_dbg (abfd
, objtype
)
2463 bfd
*abfd ATTRIBUTE_UNUSED
;
2464 int objtype ATTRIBUTE_UNUSED
;
2467 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);