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, 2007, 2008
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
30 /* The following type abbreviations are used:
32 cs counted string (ascii string with length byte)
34 sh short (2 byte, 16 bit)
35 lw longword (4 byte, 32 bit)
36 qw quadword (8 byte, 64 bit)
46 check_section (bfd
* abfd
, int size
)
50 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
51 if (offset
+ size
> PRIV (image_section
)->size
)
53 PRIV (image_section
)->contents
54 = bfd_realloc_or_free (PRIV (image_section
)->contents
, offset
+ size
);
55 if (PRIV (image_section
)->contents
== NULL
)
57 (*_bfd_error_handler
) (_("No Mem !"));
60 PRIV (image_section
)->size
= offset
+ size
;
61 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
67 /* Routines to fill sections contents during tir/etir read. */
69 /* Initialize image buffer pointer to be filled. */
72 image_set_ptr (bfd
* abfd
, int psect
, uquad offset
)
75 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
76 psect
, PRIV (sections
)[psect
]->name
, offset
);
79 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
80 PRIV (image_section
) = PRIV (sections
)[psect
];
83 /* Increment image buffer pointer by offset. */
86 image_inc_ptr (bfd
* abfd
, uquad offset
)
89 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
92 PRIV (image_ptr
) += offset
;
95 /* Dump multiple bytes to section image. */
98 image_dump (bfd
* abfd
,
101 int offset ATTRIBUTE_UNUSED
)
104 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
106 _bfd_hexdump (9, ptr
, size
, offset
);
109 if (PRIV (is_vax
) && check_section (abfd
, size
))
113 *PRIV (image_ptr
)++ = *ptr
++;
116 /* Write byte to section image. */
119 image_write_b (bfd
* abfd
, unsigned int value
)
122 _bfd_vms_debug (6, "image_write_b (%02x)\n", (int) value
);
125 if (PRIV (is_vax
) && check_section (abfd
, 1))
128 *PRIV (image_ptr
)++ = (value
& 0xff);
131 /* Write 2-byte word to image. */
134 image_write_w (bfd
* abfd
, unsigned int value
)
137 _bfd_vms_debug (6, "image_write_w (%04x)\n", (int) value
);
140 if (PRIV (is_vax
) && check_section (abfd
, 2))
143 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
144 PRIV (image_ptr
) += 2;
147 /* Write 4-byte long to image. */
150 image_write_l (bfd
* abfd
, unsigned long value
)
153 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
156 if (PRIV (is_vax
) && check_section (abfd
, 4))
159 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
160 PRIV (image_ptr
) += 4;
163 /* Write 8-byte quad to image. */
166 image_write_q (bfd
* abfd
, uquad value
)
169 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
172 if (PRIV (is_vax
) && check_section (abfd
, 8))
175 bfd_putl64 (value
, PRIV (image_ptr
));
176 PRIV (image_ptr
) += 8;
184 case ETIR_S_C_STA_GBL
: return "ETIR_S_C_STA_GBL";
185 case ETIR_S_C_STA_PQ
: return "ETIR_S_C_STA_PQ";
186 case ETIR_S_C_STA_LI
: return "ETIR_S_C_STA_LI";
187 case ETIR_S_C_STA_MOD
: return "ETIR_S_C_STA_MOD";
188 case ETIR_S_C_STA_CKARG
: return "ETIR_S_C_STA_CKARG";
189 case ETIR_S_C_STO_B
: return "ETIR_S_C_STO_B";
190 case ETIR_S_C_STO_W
: return "ETIR_S_C_STO_W";
191 case ETIR_S_C_STO_GBL
: return "ETIR_S_C_STO_GBL";
192 case ETIR_S_C_STO_CA
: return "ETIR_S_C_STO_CA";
193 case ETIR_S_C_STO_RB
: return "ETIR_S_C_STO_RB";
194 case ETIR_S_C_STO_AB
: return "ETIR_S_C_STO_AB";
195 case ETIR_S_C_STO_GBL_LW
: return "ETIR_S_C_STO_GBL_LW";
196 case ETIR_S_C_STO_LP_PSB
: return "ETIR_S_C_STO_LP_PSB";
197 case ETIR_S_C_STO_HINT_GBL
: return "ETIR_S_C_STO_HINT_GBL";
198 case ETIR_S_C_STO_HINT_PS
: return "ETIR_S_C_STO_HINT_PS";
199 case ETIR_S_C_OPR_INSV
: return "ETIR_S_C_OPR_INSV";
200 case ETIR_S_C_OPR_USH
: return "ETIR_S_C_OPR_USH";
201 case ETIR_S_C_OPR_ROT
: return "ETIR_S_C_OPR_ROT";
202 case ETIR_S_C_OPR_REDEF
: return "ETIR_S_C_OPR_REDEF";
203 case ETIR_S_C_OPR_DFLIT
: return "ETIR_S_C_OPR_DFLIT";
204 case ETIR_S_C_STC_LP
: return "ETIR_S_C_STC_LP";
205 case ETIR_S_C_STC_GBL
: return "ETIR_S_C_STC_GBL";
206 case ETIR_S_C_STC_GCA
: return "ETIR_S_C_STC_GCA";
207 case ETIR_S_C_STC_PS
: return "ETIR_S_C_STC_PS";
208 case ETIR_S_C_STC_NBH_PS
: return "ETIR_S_C_STC_NBH_PS";
209 case ETIR_S_C_STC_NOP_GBL
: return "ETIR_S_C_STC_NOP_GBL";
210 case ETIR_S_C_STC_NOP_PS
: return "ETIR_S_C_STC_NOP_PS";
211 case ETIR_S_C_STC_BSR_GBL
: return "ETIR_S_C_STC_BSR_GBL";
212 case ETIR_S_C_STC_BSR_PS
: return "ETIR_S_C_STC_BSR_PS";
213 case ETIR_S_C_STC_LDA_GBL
: return "ETIR_S_C_STC_LDA_GBL";
214 case ETIR_S_C_STC_LDA_PS
: return "ETIR_S_C_STC_LDA_PS";
215 case ETIR_S_C_STC_BOH_GBL
: return "ETIR_S_C_STC_BOH_GBL";
216 case ETIR_S_C_STC_BOH_PS
: return "ETIR_S_C_STC_BOH_PS";
217 case ETIR_S_C_STC_NBH_GBL
: return "ETIR_S_C_STC_NBH_GBL";
220 /* These names have not yet been added to this switch statement. */
224 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
230 handle sta_xxx commands in etir section
231 ptr points to data area in record
233 see table B-8 of the openVMS linker manual. */
236 etir_sta (bfd
* abfd
, int cmd
, unsigned char *ptr
)
239 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
240 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
248 stack 32 bit value of symbol (high bits set to 0). */
249 case ETIR_S_C_STA_GBL
:
252 vms_symbol_entry
*entry
;
254 name
= _bfd_vms_save_counted_string (ptr
);
255 entry
= (vms_symbol_entry
*)
256 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, FALSE
, FALSE
);
260 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
261 cmd_name (cmd
), name
);
263 _bfd_vms_push (abfd
, (uquad
) 0, -1);
266 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
273 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. */
282 case ETIR_S_C_STA_QW
:
283 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
286 /* stack psect base plus quadword offset
287 arg: lw section index
288 qw signed quadword offset (low 32 bits)
290 stack qw argument and section index
291 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB). */
292 case ETIR_S_C_STA_PQ
:
297 psect
= bfd_getl32 (ptr
);
298 if (psect
>= PRIV (section_count
))
300 (*_bfd_error_handler
) (_("bad section index in %s"),
302 bfd_set_error (bfd_error_bad_value
);
305 dummy
= bfd_getl64 (ptr
+ 4);
306 _bfd_vms_push (abfd
, dummy
, (int) psect
);
310 case ETIR_S_C_STA_LI
:
311 case ETIR_S_C_STA_MOD
:
312 case ETIR_S_C_STA_CKARG
:
313 (*_bfd_error_handler
) (_("unsupported STA cmd %s"), cmd_name (cmd
));
318 (*_bfd_error_handler
) (_("reserved STA cmd %d"), cmd
);
323 _bfd_vms_debug (5, "etir_sta true\n");
332 handle sto_xxx commands in etir section
333 ptr points to data area in record
335 see table B-9 of the openVMS linker manual. */
338 etir_sto (bfd
* abfd
, int cmd
, unsigned char *ptr
)
344 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
345 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
350 /* Store byte: pop stack, write byte
353 dummy
= _bfd_vms_pop (abfd
, &psect
);
354 /* FIXME: check top bits. */
355 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
358 /* Store word: pop stack, write word
361 dummy
= _bfd_vms_pop (abfd
, &psect
);
362 /* FIXME: check top bits */
363 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
366 /* Store longword: pop stack, write longword
368 case ETIR_S_C_STO_LW
:
369 dummy
= _bfd_vms_pop (abfd
, &psect
);
370 dummy
+= (PRIV (sections
)[psect
])->vma
;
371 /* FIXME: check top bits. */
372 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
375 /* Store quadword: pop stack, write quadword
377 case ETIR_S_C_STO_QW
:
378 dummy
= _bfd_vms_pop (abfd
, &psect
);
379 dummy
+= (PRIV (sections
)[psect
])->vma
;
380 /* FIXME: check top bits. */
381 image_write_q (abfd
, dummy
);
384 /* Store immediate repeated: pop stack for repeat count
387 case ETIR_S_C_STO_IMMR
:
391 size
= bfd_getl32 (ptr
);
392 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
394 image_dump (abfd
, ptr
+4, size
, 0);
398 /* Store global: write symbol value
399 arg: cs global symbol name. */
400 case ETIR_S_C_STO_GBL
:
402 vms_symbol_entry
*entry
;
405 name
= _bfd_vms_save_counted_string (ptr
);
406 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
410 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
411 cmd_name (cmd
), name
);
416 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
));
420 /* Store code address: write address of entry point
421 arg: cs global symbol name (procedure). */
422 case ETIR_S_C_STO_CA
:
424 vms_symbol_entry
*entry
;
427 name
= _bfd_vms_save_counted_string (ptr
);
428 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
432 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
433 cmd_name (cmd
), name
);
438 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
));
442 /* Store offset to psect: pop stack, add low 32 bits to base of psect
444 case ETIR_S_C_STO_OFF
:
449 q
= _bfd_vms_pop (abfd
, & psect1
);
450 q
+= (PRIV (sections
)[psect1
])->vma
;
451 image_write_q (abfd
, q
);
456 arg: lw count of bytes
458 case ETIR_S_C_STO_IMM
:
462 size
= bfd_getl32 (ptr
);
463 image_dump (abfd
, ptr
+4, size
, 0);
467 /* This code is 'reserved to digital' according to the openVMS
468 linker manual, however it is generated by the DEC C compiler
469 and defined in the include file.
470 FIXME, since the following is just a guess
471 store global longword: store 32bit value of symbol
472 arg: cs symbol name. */
473 case ETIR_S_C_STO_GBL_LW
:
475 vms_symbol_entry
*entry
;
478 name
= _bfd_vms_save_counted_string (ptr
);
479 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
484 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd
), name
);
486 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
490 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
));
494 case ETIR_S_C_STO_RB
:
495 case ETIR_S_C_STO_AB
:
496 case ETIR_S_C_STO_LP_PSB
:
497 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
500 case ETIR_S_C_STO_HINT_GBL
:
501 case ETIR_S_C_STO_HINT_PS
:
502 (*_bfd_error_handler
) (_("%s: not implemented"), cmd_name (cmd
));
506 (*_bfd_error_handler
) (_("reserved STO cmd %d"), cmd
);
513 /* Stack operator commands
514 all 32 bit signed arithmetic
515 all word just like a stack calculator
516 arguments are popped from stack, results are pushed on stack
518 see table B-10 of the openVMS linker manual. */
521 etir_opr (bfd
* abfd
, int cmd
, unsigned char *ptr ATTRIBUTE_UNUSED
)
526 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
527 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
532 case ETIR_S_C_OPR_NOP
: /* No-op. */
535 case ETIR_S_C_OPR_ADD
: /* Add. */
536 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
537 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
538 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
541 case ETIR_S_C_OPR_SUB
: /* Subtract. */
542 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
543 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
544 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
547 case ETIR_S_C_OPR_MUL
: /* Multiply. */
548 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
549 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
550 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
553 case ETIR_S_C_OPR_DIV
: /* Divide. */
554 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
555 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
557 _bfd_vms_push (abfd
, (uquad
) 0, -1);
559 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
562 case ETIR_S_C_OPR_AND
: /* Logical AND. */
563 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
564 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
565 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
568 case ETIR_S_C_OPR_IOR
: /* Logical inclusive OR. */
569 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
570 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
571 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
574 case ETIR_S_C_OPR_EOR
: /* Logical exclusive OR. */
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);
580 case ETIR_S_C_OPR_NEG
: /* Negate. */
581 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
582 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
585 case ETIR_S_C_OPR_COM
: /* Complement. */
586 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
587 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
590 case ETIR_S_C_OPR_ASH
: /* Arithmetic shift. */
591 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
592 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
593 if (op2
< 0) /* Shift right. */
595 else /* Shift left. */
597 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
600 case ETIR_S_C_OPR_INSV
: /* Insert field. */
601 (void) _bfd_vms_pop (abfd
, NULL
);
602 case ETIR_S_C_OPR_USH
: /* Unsigned shift. */
603 case ETIR_S_C_OPR_ROT
: /* Rotate. */
604 case ETIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
605 case ETIR_S_C_OPR_DFLIT
: /* Define a literal. */
606 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
609 case ETIR_S_C_OPR_SEL
: /* Select. */
610 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
611 (void) _bfd_vms_pop (abfd
, NULL
);
614 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
615 (void) _bfd_vms_pop (abfd
, NULL
);
616 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
621 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), cmd
);
630 See table B-11 of the openVMS linker manual. */
633 etir_ctl (bfd
* abfd
, int cmd
, unsigned char *ptr
)
639 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
640 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
645 /* Det relocation base: pop stack, set image location counter
647 case ETIR_S_C_CTL_SETRB
:
648 dummy
= _bfd_vms_pop (abfd
, &psect
);
649 image_set_ptr (abfd
, psect
, dummy
);
652 /* Augment relocation base: increment image location counter by offset
653 arg: lw offset value. */
654 case ETIR_S_C_CTL_AUGRB
:
655 dummy
= bfd_getl32 (ptr
);
656 image_inc_ptr (abfd
, dummy
);
659 /* Define location: pop index, save location counter under index
661 case ETIR_S_C_CTL_DFLOC
:
662 dummy
= _bfd_vms_pop (abfd
, NULL
);
666 /* Set location: pop index, restore location counter from index
668 case ETIR_S_C_CTL_STLOC
:
669 dummy
= _bfd_vms_pop (abfd
, &psect
);
673 /* Stack defined location: pop index, push location counter from index
675 case ETIR_S_C_CTL_STKDL
:
676 dummy
= _bfd_vms_pop (abfd
, &psect
);
681 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), cmd
);
687 /* Store conditional commands
689 See table B-12 and B-13 of the openVMS linker manual. */
692 etir_stc (bfd
* abfd
, int cmd
, unsigned char *ptr ATTRIBUTE_UNUSED
)
695 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
696 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
701 /* 200 Store-conditional Linkage Pair
703 case ETIR_S_C_STC_LP
:
704 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
707 /* 201 Store-conditional Linkage Pair with Procedure Signature
708 arg: lw linkage index
712 case ETIR_S_C_STC_LP_PSB
:
713 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
716 /* 202 Store-conditional Address at global address
717 arg: lw linkage index
720 case ETIR_S_C_STC_GBL
:
721 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
724 /* 203 Store-conditional Code Address at global address
725 arg: lw linkage index
726 cs procedure name. */
727 case ETIR_S_C_STC_GCA
:
728 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
731 /* 204 Store-conditional Address at psect + offset
732 arg: lw linkage index
735 case ETIR_S_C_STC_PS
:
736 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
739 /* 205 Store-conditional NOP at address of global
741 case ETIR_S_C_STC_NOP_GBL
:
743 /* 206 Store-conditional NOP at pect + offset
745 case ETIR_S_C_STC_NOP_PS
:
747 /* 207 Store-conditional BSR at global address
749 case ETIR_S_C_STC_BSR_GBL
:
751 /* 208 Store-conditional BSR at pect + offset
753 case ETIR_S_C_STC_BSR_PS
:
755 /* 209 Store-conditional LDA at global address
757 case ETIR_S_C_STC_LDA_GBL
:
759 /* 210 Store-conditional LDA at psect + offset
761 case ETIR_S_C_STC_LDA_PS
:
763 /* 211 Store-conditional BSR or Hint at global address
765 case ETIR_S_C_STC_BOH_GBL
:
767 /* 212 Store-conditional BSR or Hint at pect + offset
769 case ETIR_S_C_STC_BOH_PS
:
771 /* 213 Store-conditional NOP,BSR or HINT at global address
773 case ETIR_S_C_STC_NBH_GBL
:
775 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
777 case ETIR_S_C_STC_NBH_PS
:
783 _bfd_vms_debug (3, "reserved STC cmd %d", cmd
);
791 new_section (bfd
* abfd ATTRIBUTE_UNUSED
, int idx
)
798 _bfd_vms_debug (5, "new_section %d\n", idx
);
800 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
802 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
805 strcpy (name
, sname
);
807 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
811 _bfd_vms_debug (6, "new_section (%s) failed", name
);
818 section
->contents
= 0;
819 section
->name
= name
;
820 section
->index
= idx
;
826 alloc_section (bfd
* abfd
, unsigned int idx
)
831 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
835 amt
*= sizeof (asection
*);
836 PRIV (sections
) = bfd_realloc_or_free (PRIV (sections
), amt
);
837 if (PRIV (sections
) == NULL
)
840 while (PRIV (section_count
) <= idx
)
842 PRIV (sections
)[PRIV (section_count
)]
843 = new_section (abfd
, (int) PRIV (section_count
));
844 if (PRIV (sections
)[PRIV (section_count
)] == 0)
846 PRIV (section_count
)++;
856 Handle sta_xxx commands in tir section
857 ptr points to data area in record
859 See table 7-3 of the VAX/VMS linker manual. */
861 static unsigned char *
862 tir_sta (bfd
* abfd
, unsigned char *ptr
)
867 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
873 case TIR_S_C_STA_GBL
:
877 stack 32 bit value of symbol (high bits set to 0). */
880 vms_symbol_entry
*entry
;
882 name
= _bfd_vms_save_counted_string (ptr
);
884 entry
= _bfd_vms_enter_symbol (abfd
, name
);
888 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
897 stack byte value, sign extend to 32 bit. */
898 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
902 /* stack signed short word
905 stack 16 bit value, sign extend to 32 bit. */
906 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
911 /* stack signed longword
914 stack 32 bit value. */
915 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
920 case TIR_S_C_STA_WPB
:
921 /* stack psect base plus byte offset (word index)
922 arg: by section index
924 by signed byte offset. */
929 if (cmd
== TIR_S_C_STA_PB
)
933 psect
= bfd_getl16 (ptr
);
937 if (psect
>= PRIV (section_count
))
938 alloc_section (abfd
, psect
);
940 dummy
= (long) *ptr
++;
941 dummy
+= (PRIV (sections
)[psect
])->vma
;
942 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
947 case TIR_S_C_STA_WPW
:
948 /* stack psect base plus word offset (word index)
949 arg: by section index
951 sh signed short offset. */
956 if (cmd
== TIR_S_C_STA_PW
)
960 psect
= bfd_getl16 (ptr
);
964 if (psect
>= PRIV (section_count
))
965 alloc_section (abfd
, psect
);
967 dummy
= bfd_getl16 (ptr
); ptr
+=2;
968 dummy
+= (PRIV (sections
)[psect
])->vma
;
969 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
974 case TIR_S_C_STA_WPL
:
975 /* stack psect base plus long offset (word index)
976 arg: by section index
978 lw signed longword offset. */
983 if (cmd
== TIR_S_C_STA_PL
)
987 psect
= bfd_getl16 (ptr
);
991 if (psect
>= PRIV (section_count
))
992 alloc_section (abfd
, psect
);
994 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
995 dummy
+= (PRIV (sections
)[psect
])->vma
;
996 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1000 case TIR_S_C_STA_UB
:
1001 /* stack unsigned byte
1004 stack byte value. */
1005 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1008 case TIR_S_C_STA_UW
:
1009 /* stack unsigned short word
1012 stack 16 bit value. */
1013 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1017 case TIR_S_C_STA_BFI
:
1018 /* stack byte from image
1021 case TIR_S_C_STA_WFI
:
1022 /* stack byte from image
1025 case TIR_S_C_STA_LFI
:
1026 /* stack byte from image
1028 (*_bfd_error_handler
) (_("stack-from-image not implemented"));
1031 case TIR_S_C_STA_EPM
:
1032 /* stack entry point mask
1035 stack (unsigned) entry point mask of symbol
1036 err if symbol is no entry point. */
1039 vms_symbol_entry
*entry
;
1041 name
= _bfd_vms_save_counted_string (ptr
);
1042 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1046 (*_bfd_error_handler
) (_("stack-entry-mask not fully implemented"));
1047 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1052 case TIR_S_C_STA_CKARG
:
1053 /* compare procedure argument
1056 da argument descriptor
1058 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1059 and stack TRUE (args match) or FALSE (args dont match) value. */
1060 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1061 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1064 case TIR_S_C_STA_LSY
:
1065 /* stack local symbol value
1066 arg: sh environment index
1071 vms_symbol_entry
*entry
;
1073 envidx
= bfd_getl16 (ptr
);
1075 name
= _bfd_vms_save_counted_string (ptr
);
1076 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1079 (*_bfd_error_handler
) (_("stack-local-symbol not fully implemented"));
1080 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1085 case TIR_S_C_STA_LIT
:
1087 arg: by literal index
1091 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1092 (*_bfd_error_handler
) (_("stack-literal not fully implemented"));
1095 case TIR_S_C_STA_LEPM
:
1096 /* stack local symbol entry point mask
1097 arg: sh environment index
1100 stack (unsigned) entry point mask of symbol
1101 err if symbol is no entry point. */
1105 vms_symbol_entry
*entry
;
1107 envidx
= bfd_getl16 (ptr
);
1109 name
= _bfd_vms_save_counted_string (ptr
);
1110 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1113 (*_bfd_error_handler
) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1114 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1120 (*_bfd_error_handler
) (_("reserved STA cmd %d"), ptr
[-1]);
1129 tir_cmd_name (int cmd
)
1133 case TIR_S_C_STO_RSB
: return "TIR_S_C_STO_RSB";
1134 case TIR_S_C_STO_RSW
: return "TIR_S_C_STO_RSW";
1135 case TIR_S_C_STO_RL
: return "TIR_S_C_STO_RL";
1136 case TIR_S_C_STO_VPS
: return "TIR_S_C_STO_VPS";
1137 case TIR_S_C_STO_USB
: return "TIR_S_C_STO_USB";
1138 case TIR_S_C_STO_USW
: return "TIR_S_C_STO_USW";
1139 case TIR_S_C_STO_RUB
: return "TIR_S_C_STO_RUB";
1140 case TIR_S_C_STO_RUW
: return "TIR_S_C_STO_RUW";
1141 case TIR_S_C_STO_PIRR
: return "TIR_S_C_STO_PIRR";
1142 case TIR_S_C_OPR_INSV
: return "TIR_S_C_OPR_INSV";
1143 case TIR_S_C_OPR_DFLIT
: return "TIR_S_C_OPR_DFLIT";
1144 case TIR_S_C_OPR_REDEF
: return "TIR_S_C_OPR_REDEF";
1145 case TIR_S_C_OPR_ROT
: return "TIR_S_C_OPR_ROT";
1146 case TIR_S_C_OPR_USH
: return "TIR_S_C_OPR_USH";
1147 case TIR_S_C_OPR_ASH
: return "TIR_S_C_OPR_ASH";
1148 case TIR_S_C_CTL_DFLOC
: return "TIR_S_C_CTL_DFLOC";
1149 case TIR_S_C_CTL_STLOC
: return "TIR_S_C_CTL_STLOC";
1150 case TIR_S_C_CTL_STKDL
: return "TIR_S_C_CTL_STKDL";
1153 /* These strings have not been added yet. */
1162 handle sto_xxx commands in tir section
1163 ptr points to data area in record
1165 See table 7-4 of the VAX/VMS linker manual. */
1167 static unsigned char *
1168 tir_sto (bfd
* abfd
, unsigned char *ptr
)
1170 unsigned long dummy
;
1175 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1180 case TIR_S_C_STO_SB
:
1181 /* Store signed byte: pop stack, write byte
1183 dummy
= _bfd_vms_pop (abfd
, &psect
);
1184 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1187 case TIR_S_C_STO_SW
:
1188 /* Store signed word: pop stack, write word
1190 dummy
= _bfd_vms_pop (abfd
, &psect
);
1191 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1194 case TIR_S_C_STO_LW
:
1195 /* Store longword: pop stack, write longword
1197 dummy
= _bfd_vms_pop (abfd
, &psect
);
1198 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1201 case TIR_S_C_STO_BD
:
1202 /* Store byte displaced: pop stack, sub lc+1, write byte
1204 dummy
= _bfd_vms_pop (abfd
, &psect
);
1205 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1206 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1209 case TIR_S_C_STO_WD
:
1210 /* Store word displaced: pop stack, sub lc+2, write word
1212 dummy
= _bfd_vms_pop (abfd
, &psect
);
1213 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1214 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1217 case TIR_S_C_STO_LD
:
1218 /* Store long displaced: pop stack, sub lc+4, write long
1220 dummy
= _bfd_vms_pop (abfd
, &psect
);
1221 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1222 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1225 case TIR_S_C_STO_LI
:
1226 /* Store short literal: pop stack, write byte
1228 dummy
= _bfd_vms_pop (abfd
, &psect
);
1229 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1232 case TIR_S_C_STO_PIDR
:
1233 /* Store position independent data reference: pop stack, write longword
1235 FIXME: incomplete ! */
1236 dummy
= _bfd_vms_pop (abfd
, &psect
);
1237 image_write_l (abfd
, dummy
& 0xffffffff);
1240 case TIR_S_C_STO_PICR
:
1241 /* Store position independent code reference: pop stack, write longword
1243 FIXME: incomplete ! */
1244 dummy
= _bfd_vms_pop (abfd
, &psect
);
1245 image_write_b (abfd
, 0x9f);
1246 image_write_l (abfd
, dummy
& 0xffffffff);
1249 case TIR_S_C_STO_RIVB
:
1250 /* Store repeated immediate variable bytes
1251 1-byte count n field followed by n bytes of data
1252 pop stack, write n bytes <stack> times. */
1254 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1255 while (dummy
-- > 0L)
1256 image_dump (abfd
, ptr
, size
, 0);
1261 /* Store byte from top longword. */
1262 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1263 image_write_b (abfd
, dummy
& 0xff);
1267 /* Store word from top longword. */
1268 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1269 image_write_w (abfd
, dummy
& 0xffff);
1272 case TIR_S_C_STO_RB
:
1273 /* Store repeated byte from top longword. */
1274 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1275 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1277 image_write_b (abfd
, dummy
& 0xff);
1280 case TIR_S_C_STO_RW
:
1281 /* Store repeated word from top longword. */
1282 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1283 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1285 image_write_w (abfd
, dummy
& 0xffff);
1288 case TIR_S_C_STO_RSB
:
1289 case TIR_S_C_STO_RSW
:
1290 case TIR_S_C_STO_RL
:
1291 case TIR_S_C_STO_VPS
:
1292 case TIR_S_C_STO_USB
:
1293 case TIR_S_C_STO_USW
:
1294 case TIR_S_C_STO_RUB
:
1295 case TIR_S_C_STO_RUW
:
1296 case TIR_S_C_STO_PIRR
:
1297 (*_bfd_error_handler
) (_("%s: not implemented"), tir_cmd_name (ptr
[-1]));
1301 (*_bfd_error_handler
) (_("reserved STO cmd %d"), ptr
[-1]);
1308 /* Stack operator commands
1309 All 32 bit signed arithmetic
1310 All word just like a stack calculator
1311 Arguments are popped from stack, results are pushed on stack
1313 See table 7-5 of the VAX/VMS linker manual. */
1315 static unsigned char *
1316 tir_opr (bfd
* abfd
, unsigned char *ptr
)
1321 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1327 case TIR_S_C_OPR_NOP
: /* No-op. */
1330 case TIR_S_C_OPR_ADD
: /* Add. */
1331 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1332 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1333 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1336 case TIR_S_C_OPR_SUB
: /* Subtract. */
1337 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1338 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1339 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1342 case TIR_S_C_OPR_MUL
: /* Multiply. */
1343 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1344 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1345 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1348 case TIR_S_C_OPR_DIV
: /* Divide. */
1349 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1350 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1352 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1354 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1357 case TIR_S_C_OPR_AND
: /* Logical AND. */
1358 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1359 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1360 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1363 case TIR_S_C_OPR_IOR
: /* Logical inclusive OR. */
1364 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1365 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1366 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1369 case TIR_S_C_OPR_EOR
: /* Logical exclusive OR. */
1370 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1371 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1372 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1375 case TIR_S_C_OPR_NEG
: /* Negate. */
1376 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1377 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1380 case TIR_S_C_OPR_COM
: /* Complement. */
1381 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1382 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1385 case TIR_S_C_OPR_INSV
: /* Insert field. */
1386 (void) _bfd_vms_pop (abfd
, NULL
);
1387 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1388 tir_cmd_name (ptr
[-1]));
1391 case TIR_S_C_OPR_ASH
: /* Arithmetic shift. */
1392 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1393 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1394 if (HIGHBIT (op1
)) /* Shift right. */
1396 else /* Shift left. */
1398 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1399 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1400 tir_cmd_name (ptr
[-1]));
1403 case TIR_S_C_OPR_USH
: /* Unsigned shift. */
1404 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1405 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1406 if (HIGHBIT (op1
)) /* Shift right. */
1408 else /* Shift left. */
1410 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1411 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1412 tir_cmd_name (ptr
[-1]));
1415 case TIR_S_C_OPR_ROT
: /* Rotate. */
1416 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1417 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1418 if (HIGHBIT (0)) /* Shift right. */
1420 else /* Shift left. */
1422 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1423 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1424 tir_cmd_name (ptr
[-1]));
1427 case TIR_S_C_OPR_SEL
: /* Select. */
1428 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1429 (void) _bfd_vms_pop (abfd
, NULL
);
1432 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1433 (void) _bfd_vms_pop (abfd
, NULL
);
1434 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1438 case TIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
1439 case TIR_S_C_OPR_DFLIT
: /* Define a literal. */
1440 (*_bfd_error_handler
) (_("%s: not supported"),
1441 tir_cmd_name (ptr
[-1]));
1445 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), ptr
[-1]);
1454 See table 7-6 of the VAX/VMS linker manual. */
1456 static unsigned char *
1457 tir_ctl (bfd
* abfd
, unsigned char *ptr
)
1459 unsigned long dummy
;
1463 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1468 case TIR_S_C_CTL_SETRB
:
1469 /* Set relocation base: pop stack, set image location counter
1471 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1472 if (psect
>= PRIV (section_count
))
1473 alloc_section (abfd
, psect
);
1474 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1477 case TIR_S_C_CTL_AUGRB
:
1478 /* Augment relocation base: increment image location counter by offset
1479 arg: lw offset value. */
1480 dummy
= bfd_getl32 (ptr
);
1481 image_inc_ptr (abfd
, (uquad
) dummy
);
1484 case TIR_S_C_CTL_DFLOC
:
1485 /* Define location: pop index, save location counter under index
1487 dummy
= _bfd_vms_pop (abfd
, NULL
);
1488 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1489 tir_cmd_name (ptr
[-1]));
1492 case TIR_S_C_CTL_STLOC
:
1493 /* Set location: pop index, restore location counter from index
1495 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1496 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1497 tir_cmd_name (ptr
[-1]));
1500 case TIR_S_C_CTL_STKDL
:
1501 /* Stack defined location: pop index, push location counter from index
1503 dummy
= _bfd_vms_pop (abfd
, (int *) &psect
);
1504 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1505 tir_cmd_name (ptr
[-1]));
1509 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), ptr
[-1]);
1515 /* Handle command from TIR section. */
1517 static unsigned char *
1518 tir_cmd (bfd
* abfd
, unsigned char *ptr
)
1524 unsigned char * (*explain
) (bfd
*, unsigned char *);
1528 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1529 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1530 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1531 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1537 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1538 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1543 /* Store immediate. */
1544 i
= 128 - (*ptr
++ & 0x7f);
1545 image_dump (abfd
, ptr
, i
, 0);
1550 while (tir_table
[i
].mincod
>= 0)
1552 if ( (tir_table
[i
].mincod
<= *ptr
)
1553 && (*ptr
<= tir_table
[i
].maxcod
))
1555 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1560 if (tir_table
[i
].mincod
< 0)
1562 (*_bfd_error_handler
) (_("obj code %d not found"), *ptr
);
1570 /* Handle command from ETIR section. */
1573 etir_cmd (bfd
* abfd
, int cmd
, unsigned char *ptr
)
1579 bfd_boolean (*explain
) (bfd
*, int, unsigned char *);
1583 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1584 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1585 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1586 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1587 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1594 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1595 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1598 while (etir_table
[i
].mincod
>= 0)
1600 if ( (etir_table
[i
].mincod
<= cmd
)
1601 && (cmd
<= etir_table
[i
].maxcod
))
1603 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1611 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1616 /* Text Information and Relocation Records (OBJ$C_TIR)
1617 handle tir record. */
1620 analyze_tir (bfd
* abfd
, unsigned char *ptr
, unsigned int length
)
1622 unsigned char *maxptr
;
1625 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1628 maxptr
= ptr
+ length
;
1630 while (ptr
< maxptr
)
1632 ptr
= tir_cmd (abfd
, ptr
);
1640 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1641 handle etir record. */
1644 analyze_etir (bfd
* abfd
, unsigned char *ptr
, unsigned int length
)
1647 unsigned char *maxptr
;
1651 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1654 maxptr
= ptr
+ length
;
1656 while (ptr
< maxptr
)
1658 cmd
= bfd_getl16 (ptr
);
1659 length
= bfd_getl16 (ptr
+ 2);
1660 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1667 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1673 /* Process ETIR record
1674 Return 0 on success, -1 on error. */
1677 _bfd_vms_slurp_tir (bfd
* abfd
, int objtype
)
1682 _bfd_vms_debug (2, "TIR/ETIR\n");
1688 PRIV (vms_rec
) += 4; /* Skip type, size. */
1689 PRIV (rec_size
) -= 4;
1690 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1693 PRIV (vms_rec
) += 1; /* Skip type. */
1694 PRIV (rec_size
) -= 1;
1695 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1705 /* Process EDBG record
1706 Return 0 on success, -1 on error
1708 Not implemented yet. */
1711 _bfd_vms_slurp_dbg (bfd
* abfd
, int objtype ATTRIBUTE_UNUSED
)
1714 _bfd_vms_debug (2, "DBG/EDBG\n");
1717 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1721 /* Process ETBT record
1722 Return 0 on success, -1 on error
1724 Not implemented yet. */
1727 _bfd_vms_slurp_tbt (bfd
* abfd ATTRIBUTE_UNUSED
,
1728 int objtype ATTRIBUTE_UNUSED
)
1731 _bfd_vms_debug (2, "TBT/ETBT\n");
1737 /* Process LNK record
1738 Return 0 on success, -1 on error
1740 Not implemented yet. */
1743 _bfd_vms_slurp_lnk (bfd
* abfd ATTRIBUTE_UNUSED
,
1744 int objtype ATTRIBUTE_UNUSED
)
1747 _bfd_vms_debug (2, "LNK\n");
1753 /* Start ETIR record for section #index at virtual addr offset. */
1756 start_etir_record (bfd
* abfd
, int index
, uquad offset
, bfd_boolean justoffset
)
1760 /* One ETIR per section. */
1761 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1);
1762 _bfd_vms_output_push (abfd
);
1765 /* Push start offset. */
1766 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1);
1767 _bfd_vms_output_long (abfd
, (unsigned long) index
);
1768 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
1769 _bfd_vms_output_flush (abfd
);
1771 /* Start = pop (). */
1772 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1);
1773 _bfd_vms_output_flush (abfd
);
1777 end_etir_record (bfd
* abfd
)
1779 _bfd_vms_output_pop (abfd
);
1780 _bfd_vms_output_end (abfd
);
1783 /* WRITE ETIR SECTION
1785 This is still under construction and therefore not documented. */
1788 sto_imm (bfd
* abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
)
1792 unsigned char *cptr
;
1795 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1796 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
1800 cptr
= sptr
->contents
;
1804 /* Try all the rest. */
1807 if (_bfd_vms_output_check (abfd
, size
) < 0)
1809 /* Doesn't fit, split ! */
1810 end_etir_record (abfd
);
1811 start_etir_record (abfd
, index
, vaddr
, FALSE
);
1813 size
= _bfd_vms_output_check (abfd
, 0);
1814 /* More than what's left ? */
1819 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
1820 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
1821 _bfd_vms_output_dump (abfd
, cptr
, size
);
1822 _bfd_vms_output_flush (abfd
);
1825 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
1826 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
1835 /* Write section contents for bfd abfd. */
1838 _bfd_vms_write_tir (bfd
* abfd
, int objtype ATTRIBUTE_UNUSED
)
1845 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
1848 _bfd_vms_output_alignment (abfd
, 4);
1851 PRIV (vms_linkage_index
) = 1;
1853 /* Dump all other sections. */
1854 section
= abfd
->sections
;
1856 while (section
!= NULL
)
1860 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
1861 section
->index
, section
->name
,
1862 (int) (section
->size
));
1865 if (section
->flags
& SEC_RELOC
)
1869 if ((i
= section
->reloc_count
) <= 0)
1870 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
1876 _bfd_vms_debug (4, "%d relocations:\n", i
);
1877 rptr
= section
->orelocation
;
1880 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
1881 (*(*rptr
)->sym_ptr_ptr
)->name
,
1882 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
1883 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
1884 (*rptr
)->address
, (*rptr
)->addend
,
1885 bfd_get_reloc_size ((*rptr
)->howto
),
1886 (*rptr
)->howto
->name
);
1893 if ((section
->flags
& SEC_HAS_CONTENTS
)
1894 && (! bfd_is_com_section (section
)))
1896 /* Virtual addr in section. */
1899 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
1902 bfd_set_error (bfd_error_no_contents
);
1906 vaddr
= (bfd_vma
) (sptr
->offset
);
1908 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
1911 while (sptr
!= NULL
)
1913 /* One STA_PQ, CTL_SETRB per vms_section. */
1914 if (section
->flags
& SEC_RELOC
)
1916 /* Check for relocs. */
1917 arelent
**rptr
= section
->orelocation
;
1918 int i
= section
->reloc_count
;
1922 bfd_size_type addr
= (*rptr
)->address
;
1923 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
1924 if (sptr
->offset
< addr
)
1926 /* Sptr starts before reloc. */
1927 bfd_size_type before
= addr
- sptr
->offset
;
1928 if (sptr
->size
<= before
)
1930 /* Complete before. */
1931 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
1932 vaddr
+= sptr
->size
;
1937 /* Partly before. */
1938 int after
= sptr
->size
- before
;
1940 sptr
->size
= before
;
1941 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
1942 vaddr
+= sptr
->size
;
1943 sptr
->contents
+= before
;
1944 sptr
->offset
+= before
;
1948 else if (sptr
->offset
== addr
)
1950 /* Sptr starts at reloc. */
1951 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
1952 asection
*sec
= sym
->section
;
1954 switch ((*rptr
)->howto
->type
)
1956 case ALPHA_R_IGNORE
:
1959 case ALPHA_R_REFLONG
:
1961 if (bfd_is_und_section (sym
->section
))
1963 int slen
= strlen ((char *) sym
->name
);
1966 if (_bfd_vms_output_check (abfd
, slen
) < 0)
1968 end_etir_record (abfd
);
1969 start_etir_record (abfd
,
1973 _bfd_vms_output_begin (abfd
,
1974 ETIR_S_C_STO_GBL_LW
,
1976 hash
= (_bfd_vms_length_hash_symbol
1977 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
1978 _bfd_vms_output_counted (abfd
, hash
);
1979 _bfd_vms_output_flush (abfd
);
1981 else if (bfd_is_abs_section (sym
->section
))
1983 if (_bfd_vms_output_check (abfd
, 16) < 0)
1985 end_etir_record (abfd
);
1986 start_etir_record (abfd
,
1990 _bfd_vms_output_begin (abfd
,
1993 _bfd_vms_output_quad (abfd
,
1994 (uquad
) sym
->value
);
1995 _bfd_vms_output_flush (abfd
);
1996 _bfd_vms_output_begin (abfd
,
1999 _bfd_vms_output_flush (abfd
);
2003 if (_bfd_vms_output_check (abfd
, 32) < 0)
2005 end_etir_record (abfd
);
2006 start_etir_record (abfd
,
2010 _bfd_vms_output_begin (abfd
,
2013 _bfd_vms_output_long (abfd
,
2014 (unsigned long) (sec
->index
));
2015 _bfd_vms_output_quad (abfd
,
2016 ((uquad
) (*rptr
)->addend
2017 + (uquad
) sym
->value
));
2018 _bfd_vms_output_flush (abfd
);
2019 _bfd_vms_output_begin (abfd
,
2022 _bfd_vms_output_flush (abfd
);
2027 case ALPHA_R_REFQUAD
:
2029 if (bfd_is_und_section (sym
->section
))
2031 int slen
= strlen ((char *) sym
->name
);
2034 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2036 end_etir_record (abfd
);
2037 start_etir_record (abfd
,
2041 _bfd_vms_output_begin (abfd
,
2044 hash
= (_bfd_vms_length_hash_symbol
2045 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2046 _bfd_vms_output_counted (abfd
, hash
);
2047 _bfd_vms_output_flush (abfd
);
2049 else if (bfd_is_abs_section (sym
->section
))
2051 if (_bfd_vms_output_check (abfd
, 16) < 0)
2053 end_etir_record (abfd
);
2054 start_etir_record (abfd
,
2058 _bfd_vms_output_begin (abfd
,
2061 _bfd_vms_output_quad (abfd
,
2062 (uquad
) sym
->value
);
2063 _bfd_vms_output_flush (abfd
);
2064 _bfd_vms_output_begin (abfd
,
2067 _bfd_vms_output_flush (abfd
);
2071 if (_bfd_vms_output_check (abfd
, 32) < 0)
2073 end_etir_record (abfd
);
2074 start_etir_record (abfd
,
2078 _bfd_vms_output_begin (abfd
,
2081 _bfd_vms_output_long (abfd
,
2082 (unsigned long) (sec
->index
));
2083 _bfd_vms_output_quad (abfd
,
2084 ((uquad
) (*rptr
)->addend
2085 + (uquad
) sym
->value
));
2086 _bfd_vms_output_flush (abfd
);
2087 _bfd_vms_output_begin (abfd
,
2090 _bfd_vms_output_flush (abfd
);
2098 char *hash ATTRIBUTE_UNUSED
;
2100 hint_size
= sptr
->size
;
2102 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2103 sptr
->size
= hint_size
;
2106 case ALPHA_R_LINKAGE
:
2110 if (_bfd_vms_output_check (abfd
, 64) < 0)
2112 end_etir_record (abfd
);
2113 start_etir_record (abfd
, section
->index
,
2116 _bfd_vms_output_begin (abfd
,
2117 ETIR_S_C_STC_LP_PSB
,
2119 _bfd_vms_output_long (abfd
,
2120 (unsigned long) PRIV (vms_linkage_index
));
2121 PRIV (vms_linkage_index
) += 2;
2122 hash
= (_bfd_vms_length_hash_symbol
2123 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2124 _bfd_vms_output_counted (abfd
, hash
);
2125 _bfd_vms_output_byte (abfd
, 0);
2126 _bfd_vms_output_flush (abfd
);
2130 case ALPHA_R_CODEADDR
:
2132 int slen
= strlen ((char *) sym
->name
);
2134 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2136 end_etir_record (abfd
);
2137 start_etir_record (abfd
,
2141 _bfd_vms_output_begin (abfd
,
2144 hash
= (_bfd_vms_length_hash_symbol
2145 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2146 _bfd_vms_output_counted (abfd
, hash
);
2147 _bfd_vms_output_flush (abfd
);
2152 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2153 (*rptr
)->howto
->name
);
2159 if (len
== sptr
->size
)
2165 sptr
->contents
+= len
;
2166 sptr
->offset
+= len
;
2174 /* Sptr starts after reloc. */
2176 /* Check next reloc. */
2182 /* All reloc checked. */
2186 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2187 vaddr
+= sptr
->size
;
2195 /* No relocs, just dump. */
2196 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2197 vaddr
+= sptr
->size
;
2203 end_etir_record (abfd
);
2206 section
= section
->next
;
2209 _bfd_vms_output_alignment (abfd
, 2);
2213 /* Write traceback data for bfd abfd. */
2216 _bfd_vms_write_tbt (bfd
* abfd ATTRIBUTE_UNUSED
,
2217 int objtype ATTRIBUTE_UNUSED
)
2220 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2226 /* Write debug info for bfd abfd. */
2229 _bfd_vms_write_dbg (bfd
* abfd ATTRIBUTE_UNUSED
,
2230 int objtype ATTRIBUTE_UNUSED
)
2233 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);