1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999 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
));
53 /*-----------------------------------------------------------------------------*/
56 check_section (abfd
, size
)
62 offset
= PRIV(image_ptr
) - PRIV(image_section
)->contents
;
63 if ((bfd_size_type
) (offset
+ size
) > PRIV(image_section
)->_raw_size
)
65 PRIV(image_section
)->contents
= bfd_realloc (PRIV(image_section
)->contents
, offset
+ size
);
66 if (PRIV(image_section
)->contents
== 0)
68 (*_bfd_error_handler
) (_("No Mem !"));
71 PRIV(image_section
)->_raw_size
= offset
+ size
;
72 PRIV(image_ptr
) = PRIV(image_section
)->contents
+ offset
;
78 /* routines to fill sections contents during tir/etir read */
80 /* Initialize image buffer pointer to be filled */
83 image_set_ptr (abfd
, psect
, offset
)
89 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
90 psect
, PRIV(sections
)[psect
]->name
, offset
);
93 PRIV(image_ptr
) = PRIV(sections
)[psect
]->contents
+ offset
;
94 PRIV(image_section
) = PRIV(sections
)[psect
];
98 /* Increment image buffer pointer by offset */
101 image_inc_ptr (abfd
, offset
)
106 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
109 PRIV(image_ptr
) += offset
;
114 /* Dump multiple bytes to section image */
117 image_dump (abfd
, ptr
, size
, offset
)
121 int offset ATTRIBUTE_UNUSED
;
124 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
, PRIV(image_ptr
));
125 _bfd_hexdump (9, ptr
, size
, offset
);
128 if (PRIV(is_vax
) && check_section (abfd
, size
))
132 *PRIV(image_ptr
)++ = *ptr
++;
136 /* Write byte to section image */
139 image_write_b (abfd
, value
)
144 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int)value
);
147 if (PRIV(is_vax
) && check_section (abfd
, 1))
150 *PRIV(image_ptr
)++ = (value
& 0xff);
154 /* Write 2-byte word to image */
157 image_write_w (abfd
, value
)
162 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int)value
);
165 if (PRIV(is_vax
) && check_section (abfd
, 2))
168 bfd_putl16 (value
, PRIV(image_ptr
));
169 PRIV(image_ptr
) += 2;
174 /* Write 4-byte long to image */
177 image_write_l (abfd
, value
)
182 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
185 if (PRIV(is_vax
) && check_section (abfd
, 4))
188 bfd_putl32 (value
, PRIV(image_ptr
));
189 PRIV(image_ptr
) += 4;
194 /* Write 8-byte quad to image */
197 image_write_q (abfd
, value
)
202 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
205 if (PRIV(is_vax
) && check_section (abfd
, 8))
208 bfd_putl64 (value
, PRIV(image_ptr
));
209 PRIV(image_ptr
) += 8;
215 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
221 handle sta_xxx commands in etir section
222 ptr points to data area in record
224 see table B-8 of the openVMS linker manual */
227 etir_sta (abfd
, cmd
, ptr
)
234 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
235 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
245 stack 32 bit value of symbol (high bits set to 0) */
247 case ETIR_S_C_STA_GBL
:
250 vms_symbol_entry
*entry
;
252 name
= _bfd_vms_save_counted_string (ptr
);
253 entry
= (vms_symbol_entry
*)
254 bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
255 if (entry
== (vms_symbol_entry
*)NULL
)
258 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name
);
260 _bfd_vms_push (abfd
, (uquad
)0, -1);
264 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
272 stack 32 bit value, sign extend to 64 bit */
274 case ETIR_S_C_STA_LW
:
275 _bfd_vms_push (abfd
, (uquad
)bfd_getl32 (ptr
), -1);
281 stack 64 bit value of symbol */
283 case ETIR_S_C_STA_QW
:
284 _bfd_vms_push (abfd
, (uquad
)bfd_getl64(ptr
), -1);
287 /* stack psect base plus quadword offset
288 arg: lw section index
289 qw signed quadword offset (low 32 bits)
291 stack qw argument and section index
292 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
294 case ETIR_S_C_STA_PQ
:
299 psect
= bfd_getl32 (ptr
);
300 if (psect
>= PRIV(section_count
))
302 (*_bfd_error_handler
) (_("Bad section index in ETIR_S_C_STA_PQ"));
303 bfd_set_error (bfd_error_bad_value
);
306 dummy
= bfd_getl64 (ptr
+4);
307 _bfd_vms_push (abfd
, dummy
, psect
);
311 /* all not supported */
313 case ETIR_S_C_STA_LI
:
314 case ETIR_S_C_STA_MOD
:
315 case ETIR_S_C_STA_CKARG
:
317 (*_bfd_error_handler
) (_("Unsupported STA cmd %d"), cmd
);
322 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), cmd
);
327 _bfd_vms_debug (5, "etir_sta true\n");
337 handle sto_xxx commands in etir section
338 ptr points to data area in record
340 see table B-9 of the openVMS linker manual */
343 etir_sto (abfd
, cmd
, ptr
)
352 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
353 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
359 /* store byte: pop stack, write byte
363 dummy
= _bfd_vms_pop (abfd
, &psect
);
365 if (is_share
) /* FIXME */
366 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: byte fixups not supported");
368 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
371 /* store word: pop stack, write word
375 dummy
= _bfd_vms_pop (abfd
, &psect
);
377 if (is_share
) /* FIXME */
378 (*_bfd_error_handler
) ("ETIR_S_C_STO_B: word fixups not supported");
380 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
383 /* store longword: pop stack, write longword
386 case ETIR_S_C_STO_LW
:
387 dummy
= _bfd_vms_pop (abfd
, &psect
);
388 dummy
+= (PRIV(sections
)[psect
])->vma
;
389 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
392 /* store quadword: pop stack, write quadword
395 case ETIR_S_C_STO_QW
:
396 dummy
= _bfd_vms_pop (abfd
, &psect
);
397 dummy
+= (PRIV(sections
)[psect
])->vma
;
398 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
401 /* store immediate repeated: pop stack for repeat count
405 case ETIR_S_C_STO_IMMR
:
409 size
= bfd_getl32 (ptr
);
410 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
412 image_dump (abfd
, ptr
+4, size
, 0);
416 /* store global: write symbol value
417 arg: cs global symbol name */
419 case ETIR_S_C_STO_GBL
:
421 vms_symbol_entry
*entry
;
424 name
= _bfd_vms_save_counted_string (ptr
);
425 entry
= (vms_symbol_entry
*)bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
426 if (entry
== (vms_symbol_entry
*)NULL
)
428 (*_bfd_error_handler
) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
433 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
437 /* store code address: write address of entry point
438 arg: cs global symbol name (procedure) */
440 case ETIR_S_C_STO_CA
:
442 vms_symbol_entry
*entry
;
445 name
= _bfd_vms_save_counted_string (ptr
);
446 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
447 if (entry
== (vms_symbol_entry
*)NULL
)
449 (*_bfd_error_handler
) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
454 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
460 case ETIR_S_C_STO_RB
:
461 case ETIR_S_C_STO_AB
:
462 (*_bfd_error_handler
) (_("ETIR_S_C_STO_RB/AB: Not supported"));
465 /* store offset to psect: pop stack, add low 32 bits to base of psect
468 case ETIR_S_C_STO_OFF
:
473 q
= _bfd_vms_pop (abfd
, &psect
);
474 q
+= (PRIV(sections
)[psect
])->vma
;
475 image_write_q (abfd
, q
);
480 arg: lw count of bytes
483 case ETIR_S_C_STO_IMM
:
487 size
= bfd_getl32 (ptr
);
488 image_dump (abfd
, ptr
+4, size
, 0);
492 /* this code is 'reserved to digital' according to the openVMS linker manual,
493 however it is generated by the DEC C compiler and defined in the include file.
494 FIXME, since the following is just a guess
495 store global longword: store 32bit value of symbol
496 arg: cs symbol name */
498 case ETIR_S_C_STO_GBL_LW
:
500 vms_symbol_entry
*entry
;
503 name
= _bfd_vms_save_counted_string (ptr
);
504 entry
= (vms_symbol_entry
*)bfd_hash_lookup (PRIV(vms_symbol_table
), name
, false, false);
505 if (entry
== (vms_symbol_entry
*)NULL
)
508 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name
);
510 image_write_l (abfd
, (unsigned long)0); /* FIXME, reloc */
513 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
)); /* FIXME, reloc */
519 case ETIR_S_C_STO_LP_PSB
:
520 (*_bfd_error_handler
) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
525 case ETIR_S_C_STO_HINT_GBL
:
526 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
531 case ETIR_S_C_STO_HINT_PS
:
532 (*_bfd_error_handler
) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
536 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), cmd
);
543 /* stack operator commands
544 all 32 bit signed arithmetic
545 all word just like a stack calculator
546 arguments are popped from stack, results are pushed on stack
548 see table B-10 of the openVMS linker manual */
551 etir_opr (abfd
, cmd
, ptr
)
554 unsigned char *ptr ATTRIBUTE_UNUSED
;
559 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
560 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
569 case ETIR_S_C_OPR_NOP
:
574 case ETIR_S_C_OPR_ADD
:
575 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
576 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
577 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
582 case ETIR_S_C_OPR_SUB
:
583 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
584 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
585 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
590 case ETIR_S_C_OPR_MUL
:
591 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
592 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
593 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
598 case ETIR_S_C_OPR_DIV
:
599 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
600 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
602 _bfd_vms_push (abfd
, (uquad
)0L, -1);
604 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
609 case ETIR_S_C_OPR_AND
:
610 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
611 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
612 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
615 /* logical inclusive or */
617 case ETIR_S_C_OPR_IOR
:
618 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
619 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
620 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
623 /* logical exclusive or */
625 case ETIR_S_C_OPR_EOR
:
626 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
627 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
628 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
633 case ETIR_S_C_OPR_NEG
:
634 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
635 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
640 case ETIR_S_C_OPR_COM
:
641 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
642 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
647 case ETIR_S_C_OPR_INSV
:
648 (void)_bfd_vms_pop (abfd
, NULL
);
649 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_INSV: Not supported"));
652 /* arithmetic shift */
654 case ETIR_S_C_OPR_ASH
:
655 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
656 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
657 if (op2
< 0) /* shift right */
659 else /* shift left */
661 _bfd_vms_push (abfd
, (uquad
)op1
, -1);
666 case ETIR_S_C_OPR_USH
:
667 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_USH: Not supported"));
672 case ETIR_S_C_OPR_ROT
:
673 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_ROT: Not supported"));
678 case ETIR_S_C_OPR_SEL
:
679 if ((long)_bfd_vms_pop (abfd
, NULL
) & 0x01L
)
680 (void)_bfd_vms_pop (abfd
, NULL
);
683 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
684 (void)_bfd_vms_pop (abfd
, NULL
);
685 _bfd_vms_push (abfd
, (uquad
)op1
, -1);
689 /* redefine symbol to current location */
691 case ETIR_S_C_OPR_REDEF
:
692 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_REDEF: Not supported"));
695 /* define a literal */
697 case ETIR_S_C_OPR_DFLIT
:
698 (*_bfd_error_handler
) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
702 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), cmd
);
711 see table B-11 of the openVMS linker manual */
714 etir_ctl (abfd
, cmd
, ptr
)
723 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
724 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
729 /* set relocation base: pop stack, set image location counter
732 case ETIR_S_C_CTL_SETRB
:
733 dummy
= _bfd_vms_pop (abfd
, &psect
);
734 image_set_ptr (abfd
, psect
, dummy
);
737 /* augment relocation base: increment image location counter by offset
738 arg: lw offset value */
740 case ETIR_S_C_CTL_AUGRB
:
741 dummy
= bfd_getl32 (ptr
);
742 image_inc_ptr (abfd
, dummy
);
745 /* define location: pop index, save location counter under index
748 case ETIR_S_C_CTL_DFLOC
:
749 dummy
= _bfd_vms_pop (abfd
, NULL
);
753 /* set location: pop index, restore location counter from index
756 case ETIR_S_C_CTL_STLOC
:
757 dummy
= _bfd_vms_pop (abfd
, &psect
);
761 /* stack defined location: pop index, push location counter from index
764 case ETIR_S_C_CTL_STKDL
:
765 dummy
= _bfd_vms_pop (abfd
, &psect
);
770 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), cmd
);
776 /* store conditional commands
778 see table B-12 and B-13 of the openVMS linker manual */
781 etir_stc (abfd
, cmd
, ptr
)
784 unsigned char *ptr ATTRIBUTE_UNUSED
;
788 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
789 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
794 /* 200 Store-conditional Linkage Pair
797 case ETIR_S_C_STC_LP
:
798 (*_bfd_error_handler
) (_("ETIR_S_C_STC_LP: not supported"));
801 /* 201 Store-conditional Linkage Pair with Procedure Signature
802 arg: lw linkage index
807 case ETIR_S_C_STC_LP_PSB
:
808 image_inc_ptr (abfd
, 16); /* skip entry,procval */
811 /* 202 Store-conditional Address at global address
812 arg: lw linkage index
815 case ETIR_S_C_STC_GBL
:
816 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GBL: not supported"));
819 /* 203 Store-conditional Code Address at global address
820 arg: lw linkage index
823 case ETIR_S_C_STC_GCA
:
824 (*_bfd_error_handler
) (_("ETIR_S_C_STC_GCA: not supported"));
827 /* 204 Store-conditional Address at psect + offset
828 arg: lw linkage index
832 case ETIR_S_C_STC_PS
:
833 (*_bfd_error_handler
) (_("ETIR_S_C_STC_PS: not supported"));
836 /* 205 Store-conditional NOP at address of global
839 case ETIR_S_C_STC_NOP_GBL
:
841 /* 206 Store-conditional NOP at pect + offset
844 case ETIR_S_C_STC_NOP_PS
:
846 /* 207 Store-conditional BSR at global address
849 case ETIR_S_C_STC_BSR_GBL
:
851 /* 208 Store-conditional BSR at pect + offset
854 case ETIR_S_C_STC_BSR_PS
:
856 /* 209 Store-conditional LDA at global address
859 case ETIR_S_C_STC_LDA_GBL
:
861 /* 210 Store-conditional LDA at psect + offset
864 case ETIR_S_C_STC_LDA_PS
:
866 /* 211 Store-conditional BSR or Hint at global address
869 case ETIR_S_C_STC_BOH_GBL
:
871 /* 212 Store-conditional BSR or Hint at pect + offset
874 case ETIR_S_C_STC_BOH_PS
:
876 /* 213 Store-conditional NOP,BSR or HINT at global address
879 case ETIR_S_C_STC_NBH_GBL
:
881 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
884 case ETIR_S_C_STC_NBH_PS
:
885 /* FIXME (*_bfd_error_handler) ("ETIR_S_C_STC_xx: (%d) not supported", cmd); */
890 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd
);
898 new_section (abfd
, idx
)
899 bfd
*abfd ATTRIBUTE_UNUSED
;
907 _bfd_vms_debug (5, "new_section %d\n", idx
);
909 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
911 name
= bfd_malloc (strlen (sname
) + 1);
914 strcpy (name
, sname
);
916 section
= bfd_malloc (sizeof (asection
));
920 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
925 section
->_raw_size
= 0;
927 section
->contents
= 0;
928 section
->_cooked_size
= 0;
929 section
->name
= name
;
930 section
->index
= idx
;
936 alloc_section (abfd
, idx
)
941 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
944 PRIV(sections
) = ((asection
**)
945 bfd_realloc (PRIV(sections
), (idx
+1) * sizeof (asection
*)));
946 if (PRIV(sections
) == 0)
949 while (PRIV(section_count
) <= idx
)
951 PRIV(sections
)[PRIV(section_count
)] = new_section (abfd
, PRIV(section_count
));
952 if (PRIV(sections
)[PRIV(section_count
)] == 0)
954 PRIV(section_count
)++;
965 * handle sta_xxx commands in tir section
966 * ptr points to data area in record
968 * see table 7-3 of the VAX/VMS linker manual
971 static unsigned char *
972 tir_sta (bfd
*abfd
, unsigned char *ptr
)
977 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
983 case TIR_S_C_STA_GBL
:
986 * arg: cs symbol name
988 * stack 32 bit value of symbol (high bits set to 0)
992 vms_symbol_entry
*entry
;
994 name
= _bfd_vms_save_counted_string (ptr
);
996 entry
= _bfd_vms_enter_symbol (abfd
, name
);
997 if (entry
== (vms_symbol_entry
*)NULL
)
1000 _bfd_vms_push (abfd
, (unsigned long) (entry
->symbol
->value
), -1);
1005 case TIR_S_C_STA_SB
:
1010 * stack byte value, sign extend to 32 bit
1012 _bfd_vms_push (abfd
, (long)*ptr
++, -1);
1015 case TIR_S_C_STA_SW
:
1017 * stack signed short word
1020 * stack 16 bit value, sign extend to 32 bit
1022 _bfd_vms_push (abfd
, (long)bfd_getl16(ptr
), -1);
1026 case TIR_S_C_STA_LW
:
1028 * stack signed longword
1031 * stack 32 bit value
1033 _bfd_vms_push (abfd
, (long)bfd_getl32 (ptr
), -1);
1037 case TIR_S_C_STA_PB
:
1038 case TIR_S_C_STA_WPB
:
1040 * stack psect base plus byte offset (word index)
1041 * arg: by section index
1042 * (sh section index)
1043 * by signed byte offset
1047 unsigned long dummy
;
1050 if (cmd
== TIR_S_C_STA_PB
)
1054 psect
= bfd_getl16(ptr
);
1058 if (psect
>= PRIV(section_count
))
1060 alloc_section (abfd
, psect
);
1063 dummy
= (long)*ptr
++;
1064 dummy
+= (PRIV(sections
)[psect
])->vma
;
1065 _bfd_vms_push (abfd
, dummy
, psect
);
1069 case TIR_S_C_STA_PW
:
1070 case TIR_S_C_STA_WPW
:
1072 * stack psect base plus word offset (word index)
1073 * arg: by section index
1074 * (sh section index)
1075 * sh signed short offset
1079 unsigned long dummy
;
1082 if (cmd
== TIR_S_C_STA_PW
)
1086 psect
= bfd_getl16(ptr
);
1090 if (psect
>= PRIV(section_count
))
1092 alloc_section (abfd
, psect
);
1095 dummy
= bfd_getl16(ptr
); ptr
+=2;
1096 dummy
+= (PRIV(sections
)[psect
])->vma
;
1097 _bfd_vms_push (abfd
, dummy
, psect
);
1101 case TIR_S_C_STA_PL
:
1102 case TIR_S_C_STA_WPL
:
1104 * stack psect base plus long offset (word index)
1105 * arg: by section index
1106 * (sh section index)
1107 * lw signed longword offset
1111 unsigned long dummy
;
1114 if (cmd
== TIR_S_C_STA_PL
)
1118 psect
= bfd_getl16(ptr
);
1122 if (psect
>= PRIV(section_count
))
1124 alloc_section (abfd
, psect
);
1127 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1128 dummy
+= (PRIV(sections
)[psect
])->vma
;
1129 _bfd_vms_push (abfd
, dummy
, psect
);
1133 case TIR_S_C_STA_UB
:
1135 * stack unsigned byte
1140 _bfd_vms_push (abfd
, (unsigned long)*ptr
++, -1);
1143 case TIR_S_C_STA_UW
:
1145 * stack unsigned short word
1148 * stack 16 bit value
1150 _bfd_vms_push (abfd
, (unsigned long)bfd_getl16(ptr
), -1);
1154 case TIR_S_C_STA_BFI
:
1156 * stack byte from image
1161 case TIR_S_C_STA_WFI
:
1163 * stack byte from image
1168 case TIR_S_C_STA_LFI
:
1170 * stack byte from image
1174 (*_bfd_error_handler
) (_("Stack-from-image not implemented"));
1177 case TIR_S_C_STA_EPM
:
1179 * stack entry point mask
1180 * arg: cs symbol name
1182 * stack (unsigned) entry point mask of symbol
1183 * err if symbol is no entry point
1187 vms_symbol_entry
*entry
;
1189 name
= _bfd_vms_save_counted_string (ptr
);
1190 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1191 if (entry
== (vms_symbol_entry
*)NULL
)
1194 (*_bfd_error_handler
) (_("Stack-entry-mask not fully implemented"));
1195 _bfd_vms_push (abfd
, 0L, -1);
1200 case TIR_S_C_STA_CKARG
:
1202 * compare procedure argument
1203 * arg: cs symbol name
1205 * da argument descriptor
1207 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1208 * and stack TRUE (args match) or FALSE (args dont match) value
1210 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1211 _bfd_vms_push (abfd
, 1L, -1);
1214 case TIR_S_C_STA_LSY
:
1216 * stack local symbol value
1217 * arg: sh environment index
1223 vms_symbol_entry
*entry
;
1225 envidx
= bfd_getl16(ptr
); ptr
+= 2;
1226 name
= _bfd_vms_save_counted_string (ptr
);
1227 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1228 if (entry
== (vms_symbol_entry
*)NULL
)
1230 (*_bfd_error_handler
) (_("Stack-local-symbol not fully implemented"));
1231 _bfd_vms_push (abfd
, 0L, -1);
1236 case TIR_S_C_STA_LIT
:
1239 * arg: by literal index
1244 _bfd_vms_push (abfd
, 0L, -1);
1245 (*_bfd_error_handler
) (_("Stack-literal not fully implemented"));
1248 case TIR_S_C_STA_LEPM
:
1250 * stack local symbol entry point mask
1251 * arg: sh environment index
1254 * stack (unsigned) entry point mask of symbol
1255 * err if symbol is no entry point
1260 vms_symbol_entry
*entry
;
1262 envidx
= bfd_getl16(ptr
); ptr
+= 2;
1263 name
= _bfd_vms_save_counted_string (ptr
);
1264 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1265 if (entry
== (vms_symbol_entry
*)NULL
)
1267 (*_bfd_error_handler
) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1268 _bfd_vms_push (abfd
, 0L, -1);
1274 (*_bfd_error_handler
) (_("Reserved STA cmd %d"), ptr
[-1]);
1285 * vax store commands
1287 * handle sto_xxx commands in tir section
1288 * ptr points to data area in record
1290 * see table 7-4 of the VAX/VMS linker manual
1293 static unsigned char *
1294 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1296 unsigned long dummy
;
1301 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1306 case TIR_S_C_STO_SB
:
1308 * 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
:
1317 * store signed word: pop stack, write word
1320 dummy
= _bfd_vms_pop (abfd
, &psect
);
1321 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1324 case TIR_S_C_STO_LW
:
1326 * store longword: pop stack, write longword
1329 dummy
= _bfd_vms_pop (abfd
, &psect
);
1330 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1333 case TIR_S_C_STO_BD
:
1335 * store byte displaced: pop stack, sub lc+1, write byte
1338 dummy
= _bfd_vms_pop (abfd
, &psect
);
1339 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 1);
1340 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1343 case TIR_S_C_STO_WD
:
1345 * store word displaced: pop stack, sub lc+2, write word
1348 dummy
= _bfd_vms_pop (abfd
, &psect
);
1349 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 2);
1350 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1352 case TIR_S_C_STO_LD
:
1354 * store long displaced: pop stack, sub lc+4, write long
1357 dummy
= _bfd_vms_pop (abfd
, &psect
);
1358 dummy
-= ((PRIV(sections
)[psect
])->vma
+ 4);
1359 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1361 case TIR_S_C_STO_LI
:
1363 * store short literal: pop stack, write byte
1366 dummy
= _bfd_vms_pop (abfd
, &psect
);
1367 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1369 case TIR_S_C_STO_PIDR
:
1371 * store position independent data reference: pop stack, write longword
1373 * FIXME: incomplete !
1375 dummy
= _bfd_vms_pop (abfd
, &psect
);
1376 image_write_l (abfd
, dummy
& 0xffffffff);
1378 case TIR_S_C_STO_PICR
:
1380 * store position independent code reference: pop stack, write longword
1382 * FIXME: incomplete !
1384 dummy
= _bfd_vms_pop (abfd
, &psect
);
1385 image_write_b (abfd
, 0x9f);
1386 image_write_l (abfd
, dummy
& 0xffffffff);
1388 case TIR_S_C_STO_RIVB
:
1390 * store repeated immediate variable bytes
1391 * 1-byte count n field followed by n bytes of data
1392 * pop stack, write n bytes <stack> times
1395 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1396 while (dummy
-- > 0L)
1397 image_dump (abfd
, ptr
, size
, 0);
1402 * store byte from top longword
1404 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1405 image_write_b (abfd
, dummy
& 0xff);
1409 * store word from top longword
1411 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1412 image_write_w (abfd
, dummy
& 0xffff);
1414 case TIR_S_C_STO_RB
:
1416 * store repeated byte from top longword
1418 size
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1419 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1421 image_write_b (abfd
, dummy
& 0xff);
1423 case TIR_S_C_STO_RW
:
1425 * store repeated word from top longword
1427 size
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1428 dummy
= (unsigned long)_bfd_vms_pop (abfd
, NULL
);
1430 image_write_w (abfd
, dummy
& 0xffff);
1433 case TIR_S_C_STO_RSB
:
1434 case TIR_S_C_STO_RSW
:
1435 case TIR_S_C_STO_RL
:
1436 case TIR_S_C_STO_VPS
:
1437 case TIR_S_C_STO_USB
:
1438 case TIR_S_C_STO_USW
:
1439 case TIR_S_C_STO_RUB
:
1440 case TIR_S_C_STO_RUW
:
1441 case TIR_S_C_STO_PIRR
:
1442 (*_bfd_error_handler
) (_("Unimplemented STO cmd %d"), ptr
[-1]);
1446 (*_bfd_error_handler
) (_("Reserved STO cmd %d"), ptr
[-1]);
1454 * stack operator commands
1455 * all 32 bit signed arithmetic
1456 * all word just like a stack calculator
1457 * arguments are popped from stack, results are pushed on stack
1459 * see table 7-5 of the VAX/VMS linker manual
1462 static unsigned char *
1463 tir_opr (bfd
*abfd
, unsigned char *ptr
)
1468 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1474 case TIR_S_C_OPR_NOP
:
1480 case TIR_S_C_OPR_ADD
:
1484 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1485 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1486 _bfd_vms_push (abfd
, (unsigned long) (op1
+ op2
), -1);
1489 case TIR_S_C_OPR_SUB
:
1493 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1494 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1495 _bfd_vms_push (abfd
, (unsigned long) (op2
- op1
), -1);
1498 case TIR_S_C_OPR_MUL
:
1502 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1503 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1504 _bfd_vms_push (abfd
, (unsigned long) (op1
* op2
), -1);
1507 case TIR_S_C_OPR_DIV
:
1511 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1512 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1514 _bfd_vms_push (abfd
, (unsigned long)0L, -1);
1516 _bfd_vms_push (abfd
, (unsigned long) (op2
/ op1
), -1);
1519 case TIR_S_C_OPR_AND
:
1523 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1524 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1525 _bfd_vms_push (abfd
, (unsigned long) (op1
& op2
), -1);
1528 case TIR_S_C_OPR_IOR
:
1529 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1531 * logical inclusive or
1533 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1534 _bfd_vms_push (abfd
, (unsigned long) (op1
| op2
), -1);
1537 case TIR_S_C_OPR_EOR
:
1539 * logical exclusive or
1541 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1542 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1543 _bfd_vms_push (abfd
, (unsigned long) (op1
^ op2
), -1);
1546 case TIR_S_C_OPR_NEG
:
1550 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1551 _bfd_vms_push (abfd
, (unsigned long) (-op1
), -1);
1554 case TIR_S_C_OPR_COM
:
1558 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1559 _bfd_vms_push (abfd
, (unsigned long) (op1
^ -1L), -1);
1562 case TIR_S_C_OPR_INSV
:
1566 (void)_bfd_vms_pop (abfd
, NULL
);
1567 (*_bfd_error_handler
) ("TIR_S_C_OPR_INSV incomplete");
1570 case TIR_S_C_OPR_ASH
:
1574 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1575 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1576 if (HIGHBIT(op1
)) /* shift right */
1578 else /* shift left */
1580 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1581 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ASH incomplete"));
1584 case TIR_S_C_OPR_USH
:
1588 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1589 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1590 if (HIGHBIT(op1
)) /* shift right */
1592 else /* shift left */
1594 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1595 (*_bfd_error_handler
) (_("TIR_S_C_OPR_USH incomplete"));
1598 case TIR_S_C_OPR_ROT
:
1602 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1603 op2
= (long)_bfd_vms_pop (abfd
, NULL
);
1604 if (HIGHBIT(0)) /* shift right */
1606 else /* shift left */
1608 _bfd_vms_push (abfd
, (unsigned long)op2
, -1);
1609 (*_bfd_error_handler
) (_("TIR_S_C_OPR_ROT incomplete"));
1612 case TIR_S_C_OPR_SEL
:
1616 if ((long)_bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1617 (void)_bfd_vms_pop (abfd
, NULL
);
1620 op1
= (long)_bfd_vms_pop (abfd
, NULL
);
1621 (void)_bfd_vms_pop (abfd
, NULL
);
1622 _bfd_vms_push (abfd
, (unsigned long)op1
, -1);
1626 case TIR_S_C_OPR_REDEF
:
1628 * redefine symbol to current location
1630 (*_bfd_error_handler
) (_("TIR_S_C_OPR_REDEF not supported"));
1633 case TIR_S_C_OPR_DFLIT
:
1637 (*_bfd_error_handler
) (_("TIR_S_C_OPR_DFLIT not supported"));
1641 (*_bfd_error_handler
) (_("Reserved OPR cmd %d"), ptr
[-1]);
1648 static unsigned char *
1649 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1653 * see table 7-6 of the VAX/VMS linker manual
1656 unsigned long dummy
;
1660 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1665 case TIR_S_C_CTL_SETRB
:
1667 * set relocation base: pop stack, set image location counter
1670 dummy
= _bfd_vms_pop (abfd
, &psect
);
1671 if (psect
>= PRIV(section_count
))
1673 alloc_section (abfd
, psect
);
1675 image_set_ptr (abfd
, psect
, dummy
);
1677 case TIR_S_C_CTL_AUGRB
:
1679 * augment relocation base: increment image location counter by offset
1680 * arg: lw offset value
1682 dummy
= bfd_getl32 (ptr
);
1683 image_inc_ptr (abfd
, dummy
);
1685 case TIR_S_C_CTL_DFLOC
:
1687 * define location: pop index, save location counter under index
1690 dummy
= _bfd_vms_pop (abfd
, NULL
);
1691 (*_bfd_error_handler
) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1693 case TIR_S_C_CTL_STLOC
:
1695 * set location: pop index, restore location counter from index
1698 dummy
= _bfd_vms_pop (abfd
, &psect
);
1699 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1701 case TIR_S_C_CTL_STKDL
:
1703 * stack defined location: pop index, push location counter from index
1706 dummy
= _bfd_vms_pop (abfd
, &psect
);
1707 (*_bfd_error_handler
) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1710 (*_bfd_error_handler
) (_("Reserved CTL cmd %d"), ptr
[-1]);
1717 * handle command from TIR section
1720 static unsigned char *
1721 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1726 unsigned char * (*explain
) (bfd
*, unsigned char *);
1728 { 0, TIR_S_C_MAXSTACOD
, tir_sta
}
1729 ,{ TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
}
1730 ,{ TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
}
1731 ,{ TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
}
1737 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1738 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
1741 if (*ptr
& 0x80) /* store immediate */
1743 i
= 128 - (*ptr
++ & 0x7f);
1744 image_dump (abfd
, ptr
, i
, 0);
1749 while (tir_table
[i
].mincod
>= 0)
1751 if ( (tir_table
[i
].mincod
<= *ptr
)
1752 && (*ptr
<= tir_table
[i
].maxcod
))
1754 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1759 if (tir_table
[i
].mincod
< 0)
1761 (*_bfd_error_handler
) (_("Obj code %d not found"), *ptr
);
1769 /* handle command from ETIR section */
1772 etir_cmd (abfd
, cmd
, ptr
)
1780 boolean (*explain
) PARAMS((bfd
*, int, unsigned char *));
1782 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1783 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1784 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1785 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1786 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1793 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1794 _bfd_hexdump (8, ptr
, 16, (int)ptr
);
1797 while (etir_table
[i
].mincod
>= 0)
1799 if ( (etir_table
[i
].mincod
<= cmd
)
1800 && (cmd
<= etir_table
[i
].maxcod
))
1802 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1810 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1815 /* Text Information and Relocation Records (OBJ$C_TIR)
1816 handle tir record */
1819 analyze_tir (abfd
, ptr
, length
)
1822 unsigned int length
;
1824 unsigned char *maxptr
;
1827 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1830 maxptr
= ptr
+ length
;
1832 while (ptr
< maxptr
)
1834 ptr
= tir_cmd (abfd
, ptr
);
1842 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1843 handle etir record */
1846 analyze_etir (abfd
, ptr
, length
)
1849 unsigned int length
;
1852 unsigned char *maxptr
;
1856 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1859 maxptr
= ptr
+ length
;
1861 while (ptr
< maxptr
)
1863 cmd
= bfd_getl16 (ptr
);
1864 length
= bfd_getl16 (ptr
+ 2);
1865 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1872 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1878 /* process ETIR record
1880 return 0 on success, -1 on error */
1883 _bfd_vms_slurp_tir (abfd
, objtype
)
1890 _bfd_vms_debug (2, "TIR/ETIR\n");
1896 PRIV(vms_rec
) += 4; /* skip type, size */
1897 PRIV(rec_size
) -= 4;
1898 result
= analyze_etir (abfd
, PRIV(vms_rec
), PRIV(rec_size
));
1901 PRIV(vms_rec
) += 1; /* skip type */
1902 PRIV(rec_size
) -= 1;
1903 result
= analyze_tir (abfd
, PRIV(vms_rec
), PRIV(rec_size
));
1913 /* process EDBG record
1914 return 0 on success, -1 on error
1916 not implemented yet */
1919 _bfd_vms_slurp_dbg (abfd
, objtype
)
1921 int objtype ATTRIBUTE_UNUSED
;
1924 _bfd_vms_debug (2, "DBG/EDBG\n");
1927 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1931 /* process ETBT record
1932 return 0 on success, -1 on error
1934 not implemented yet */
1937 _bfd_vms_slurp_tbt (abfd
, objtype
)
1938 bfd
*abfd ATTRIBUTE_UNUSED
;
1939 int objtype ATTRIBUTE_UNUSED
;
1942 _bfd_vms_debug (2, "TBT/ETBT\n");
1948 /* process LNK record
1949 return 0 on success, -1 on error
1951 not implemented yet */
1954 _bfd_vms_slurp_lnk (abfd
, objtype
)
1955 bfd
*abfd ATTRIBUTE_UNUSED
;
1956 int objtype ATTRIBUTE_UNUSED
;
1959 _bfd_vms_debug (2, "LNK\n");
1965 /*----------------------------------------------------------------------*/
1967 /* WRITE ETIR SECTION */
1969 /* this is still under construction and therefore not documented */
1971 /*----------------------------------------------------------------------*/
1973 static void start_etir_record
PARAMS ((bfd
*abfd
, int index
, uquad offset
, boolean justoffset
));
1974 static void sto_imm
PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1975 static void end_etir_record
PARAMS ((bfd
*abfd
));
1978 sto_imm (abfd
, sptr
, vaddr
, index
)
1986 unsigned char *cptr
;
1989 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1990 _bfd_hexdump (9, sptr
->contents
, (int)sptr
->size
, (int)vaddr
);
1994 cptr
= sptr
->contents
;
1999 size
= ssize
; /* try all the rest */
2001 if (_bfd_vms_output_check (abfd
, size
) < 0)
2002 { /* doesn't fit, split ! */
2003 end_etir_record (abfd
);
2004 start_etir_record (abfd
, index
, vaddr
, false);
2005 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
2006 if (size
> ssize
) /* more than what's left ? */
2010 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
2011 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
2012 _bfd_vms_output_dump (abfd
, cptr
, size
);
2013 _bfd_vms_output_flush (abfd
);
2016 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
2017 _bfd_hexdump (10, cptr
, (int)size
, (int)vaddr
);
2028 /*-------------------------------------------------------------------*/
2030 /* start ETIR record for section #index at virtual addr offset. */
2033 start_etir_record (abfd
, index
, offset
, justoffset
)
2041 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
2042 _bfd_vms_output_push (abfd
);
2045 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
2046 _bfd_vms_output_long (abfd
, (unsigned long)index
);
2047 _bfd_vms_output_quad (abfd
, (uquad
)offset
);
2048 _bfd_vms_output_flush (abfd
);
2050 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
2051 _bfd_vms_output_flush (abfd
);
2056 /* end etir record */
2058 end_etir_record (abfd
)
2061 _bfd_vms_output_pop (abfd
);
2062 _bfd_vms_output_end (abfd
);
2065 /* write section contents for bfd abfd */
2068 _bfd_vms_write_tir (abfd
, objtype
)
2070 int objtype ATTRIBUTE_UNUSED
;
2077 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2080 _bfd_vms_output_alignment (abfd
, 4);
2083 PRIV(vms_linkage_index
) = 1;
2085 /* dump all other sections */
2087 section
= abfd
->sections
;
2089 while (section
!= NULL
)
2093 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n", section
->index
, section
->name
, (int) (section
->_raw_size
));
2096 if (section
->flags
& SEC_RELOC
)
2100 if ((i
= section
->reloc_count
) <= 0)
2102 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2109 _bfd_vms_debug (4, "%d relocations:\n", i
);
2110 rptr
= section
->orelocation
;
2113 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2114 (*(*rptr
)->sym_ptr_ptr
)->name
,
2115 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2116 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2117 (*rptr
)->address
, (*rptr
)->addend
,
2118 bfd_get_reloc_size((*rptr
)->howto
),
2119 (*rptr
)->howto
->name
);
2126 if ((section
->flags
& SEC_HAS_CONTENTS
)
2127 && (! bfd_is_com_section (section
)))
2129 bfd_vma vaddr
; /* virtual addr in section */
2131 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2134 bfd_set_error (bfd_error_no_contents
);
2138 vaddr
= (bfd_vma
) (sptr
->offset
);
2140 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2143 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2146 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2148 arelent
**rptr
= section
->orelocation
;
2149 int i
= section
->reloc_count
;
2152 bfd_size_type addr
= (*rptr
)->address
;
2153 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2154 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2156 bfd_size_type before
= addr
- sptr
->offset
;
2157 if (sptr
->size
<= before
) /* complete before */
2159 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2160 vaddr
+= sptr
->size
;
2163 else /* partly before */
2165 int after
= sptr
->size
- before
;
2166 sptr
->size
= before
;
2167 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2168 vaddr
+= sptr
->size
;
2169 sptr
->contents
+= before
;
2170 sptr
->offset
+= before
;
2174 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2176 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2177 asection
*sec
= sym
->section
;
2179 switch ((*rptr
)->howto
->type
)
2181 case ALPHA_R_IGNORE
:
2184 case ALPHA_R_REFLONG
:
2186 if (bfd_is_und_section (sym
->section
))
2188 if (_bfd_vms_output_check (abfd
,
2189 strlen((char *)sym
->name
))
2192 end_etir_record (abfd
);
2193 start_etir_record (abfd
,
2197 _bfd_vms_output_begin (abfd
,
2198 ETIR_S_C_STO_GBL_LW
,
2200 _bfd_vms_output_counted (abfd
,
2201 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2202 _bfd_vms_output_flush (abfd
);
2204 else if (bfd_is_abs_section (sym
->section
))
2206 if (_bfd_vms_output_check (abfd
, 16) < 0)
2208 end_etir_record (abfd
);
2209 start_etir_record (abfd
,
2213 _bfd_vms_output_begin (abfd
,
2216 _bfd_vms_output_quad (abfd
,
2218 _bfd_vms_output_flush (abfd
);
2219 _bfd_vms_output_begin (abfd
,
2222 _bfd_vms_output_flush (abfd
);
2226 if (_bfd_vms_output_check (abfd
, 32) < 0)
2228 end_etir_record (abfd
);
2229 start_etir_record (abfd
,
2233 _bfd_vms_output_begin (abfd
,
2236 _bfd_vms_output_long (abfd
,
2237 (unsigned long) (sec
->index
));
2238 _bfd_vms_output_quad (abfd
,
2239 ((uquad
) (*rptr
)->addend
2240 + (uquad
)sym
->value
));
2241 _bfd_vms_output_flush (abfd
);
2242 _bfd_vms_output_begin (abfd
,
2245 _bfd_vms_output_flush (abfd
);
2250 case ALPHA_R_REFQUAD
:
2252 if (bfd_is_und_section (sym
->section
))
2254 if (_bfd_vms_output_check (abfd
,
2255 strlen((char *)sym
->name
))
2258 end_etir_record (abfd
);
2259 start_etir_record (abfd
,
2263 _bfd_vms_output_begin (abfd
,
2266 _bfd_vms_output_counted (abfd
,
2267 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2268 _bfd_vms_output_flush (abfd
);
2270 else if (bfd_is_abs_section (sym
->section
))
2272 if (_bfd_vms_output_check (abfd
, 16) < 0)
2274 end_etir_record (abfd
);
2275 start_etir_record (abfd
,
2279 _bfd_vms_output_begin (abfd
,
2282 _bfd_vms_output_quad (abfd
,
2284 _bfd_vms_output_flush (abfd
);
2285 _bfd_vms_output_begin (abfd
,
2288 _bfd_vms_output_flush (abfd
);
2292 if (_bfd_vms_output_check (abfd
, 32) < 0)
2294 end_etir_record (abfd
);
2295 start_etir_record (abfd
,
2299 _bfd_vms_output_begin (abfd
,
2302 _bfd_vms_output_long (abfd
,
2303 (unsigned long) (sec
->index
));
2304 _bfd_vms_output_quad (abfd
,
2305 ((uquad
) (*rptr
)->addend
2306 + (uquad
)sym
->value
));
2307 _bfd_vms_output_flush (abfd
);
2308 _bfd_vms_output_begin (abfd
,
2311 _bfd_vms_output_flush (abfd
);
2320 hint_size
= sptr
->size
;
2322 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2323 sptr
->size
= hint_size
;
2325 vms_output_begin(abfd
, ETIR_S_C_STO_HINT_GBL
, -1);
2326 vms_output_long(abfd
, (unsigned long) (sec
->index
));
2327 vms_output_quad(abfd
, (uquad
)addr
);
2329 vms_output_counted(abfd
, _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2330 vms_output_flush(abfd
);
2334 case ALPHA_R_LINKAGE
:
2336 if (_bfd_vms_output_check (abfd
, 64) < 0)
2338 end_etir_record (abfd
);
2339 start_etir_record (abfd
, section
->index
,
2342 _bfd_vms_output_begin (abfd
,
2343 ETIR_S_C_STC_LP_PSB
,
2345 _bfd_vms_output_long (abfd
,
2346 (unsigned long)PRIV(vms_linkage_index
));
2347 PRIV(vms_linkage_index
) += 2;
2348 _bfd_vms_output_counted (abfd
,
2349 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2350 _bfd_vms_output_byte (abfd
, 0);
2351 _bfd_vms_output_flush (abfd
);
2355 case ALPHA_R_CODEADDR
:
2357 if (_bfd_vms_output_check (abfd
,
2358 strlen((char *)sym
->name
))
2361 end_etir_record (abfd
);
2362 start_etir_record (abfd
,
2366 _bfd_vms_output_begin (abfd
,
2369 _bfd_vms_output_counted (abfd
,
2370 _bfd_vms_length_hash_symbol (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2371 _bfd_vms_output_flush (abfd
);
2376 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2377 (*rptr
)->howto
->name
);
2383 if (len
== sptr
->size
)
2389 sptr
->contents
+= len
;
2390 sptr
->offset
+= len
;
2396 else /* sptr starts after reloc */
2398 i
--; /* check next reloc */
2402 if (i
==0) /* all reloc checked */
2406 sto_imm (abfd
, sptr
, vaddr
, section
->index
); /* dump rest */
2407 vaddr
+= sptr
->size
;
2412 } /* if SEC_RELOC */
2413 else /* no relocs, just dump */
2415 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2416 vaddr
+= sptr
->size
;
2421 } /* while (sptr != 0) */
2423 end_etir_record (abfd
);
2425 } /* has_contents */
2427 section
= section
->next
;
2430 _bfd_vms_output_alignment(abfd
, 2);
2434 /* write traceback data for bfd abfd */
2437 _bfd_vms_write_tbt (abfd
, objtype
)
2438 bfd
*abfd ATTRIBUTE_UNUSED
;
2439 int objtype ATTRIBUTE_UNUSED
;
2442 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2448 /* write debug info for bfd abfd */
2451 _bfd_vms_write_dbg (abfd
, objtype
)
2452 bfd
*abfd ATTRIBUTE_UNUSED
;
2453 int objtype ATTRIBUTE_UNUSED
;
2456 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);