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
4 Free Software Foundation, Inc.
6 TIR record handling functions
7 ETIR record handling functions
9 go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
12 Written by Klaus K"ampf (kkaempf@rmi.de)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* The following type abbreviations are used:
30 cs counted string (ascii string with length byte)
32 sh short (2 byte, 16 bit)
33 lw longword (4 byte, 32 bit)
34 qw quadword (8 byte, 64 bit)
44 static void image_set_ptr
45 PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
46 static void image_inc_ptr
47 PARAMS ((bfd
*abfd
, uquad offset
));
48 static void image_dump
49 PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
50 static void image_write_b
51 PARAMS ((bfd
*abfd
, unsigned int value
));
52 static void image_write_w
53 PARAMS ((bfd
*abfd
, unsigned int value
));
54 static void image_write_l
55 PARAMS ((bfd
*abfd
, unsigned long value
));
56 static void image_write_q
57 PARAMS ((bfd
*abfd
, uquad value
));
58 static int check_section
59 PARAMS ((bfd
*, int));
60 static bfd_boolean etir_sta
61 PARAMS ((bfd
*, int, unsigned char *));
62 static bfd_boolean etir_sto
63 PARAMS ((bfd
*, int, unsigned char *));
64 static bfd_boolean etir_opr
65 PARAMS ((bfd
*, int, unsigned char *));
66 static bfd_boolean etir_ctl
67 PARAMS ((bfd
*, int, unsigned char *));
68 static bfd_boolean etir_stc
69 PARAMS ((bfd
*, int, unsigned char *));
70 static asection
*new_section
71 PARAMS ((bfd
*, int));
72 static int alloc_section
73 PARAMS ((bfd
*, unsigned int));
75 PARAMS ((bfd
*, int, unsigned char *));
76 static int analyze_tir
77 PARAMS ((bfd
*, unsigned char *, unsigned int));
78 static int analyze_etir
79 PARAMS ((bfd
*, unsigned char *, unsigned int));
80 static unsigned char * tir_opr
81 PARAMS ((bfd
*, unsigned char *));
82 static const char * tir_cmd_name
84 static const char * cmd_name
89 check_section (abfd
, size
)
95 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
96 if (offset
+ size
> PRIV (image_section
)->size
)
98 PRIV (image_section
)->contents
99 = bfd_realloc (PRIV (image_section
)->contents
, offset
+ size
);
100 if (PRIV (image_section
)->contents
== 0)
102 (*_bfd_error_handler
) (_("No Mem !"));
105 PRIV (image_section
)->size
= offset
+ size
;
106 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
112 /* Routines to fill sections contents during tir/etir read. */
114 /* Initialize image buffer pointer to be filled. */
117 image_set_ptr (abfd
, psect
, offset
)
123 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
124 psect
, PRIV (sections
)[psect
]->name
, offset
);
127 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
128 PRIV (image_section
) = PRIV (sections
)[psect
];
132 /* Increment image buffer pointer by offset. */
135 image_inc_ptr (abfd
, offset
)
140 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
143 PRIV (image_ptr
) += offset
;
148 /* Dump multiple bytes to section image. */
151 image_dump (abfd
, ptr
, size
, offset
)
155 int offset ATTRIBUTE_UNUSED
;
158 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
160 _bfd_hexdump (9, ptr
, size
, offset
);
163 if (PRIV (is_vax
) && check_section (abfd
, size
))
167 *PRIV (image_ptr
)++ = *ptr
++;
171 /* Write byte to section image. */
174 image_write_b (abfd
, value
)
179 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value
);
182 if (PRIV (is_vax
) && check_section (abfd
, 1))
185 *PRIV (image_ptr
)++ = (value
& 0xff);
189 /* Write 2-byte word to image. */
192 image_write_w (abfd
, value
)
197 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value
);
200 if (PRIV (is_vax
) && check_section (abfd
, 2))
203 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
204 PRIV (image_ptr
) += 2;
209 /* Write 4-byte long to image. */
212 image_write_l (abfd
, value
)
217 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
220 if (PRIV (is_vax
) && check_section (abfd
, 4))
223 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
224 PRIV (image_ptr
) += 4;
229 /* Write 8-byte quad to image. */
232 image_write_q (abfd
, value
)
237 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
240 if (PRIV (is_vax
) && check_section (abfd
, 8))
243 bfd_putl64 (value
, PRIV (image_ptr
));
244 PRIV (image_ptr
) += 8;
255 case ETIR_S_C_STA_GBL
: return "ETIR_S_C_STA_GBL";
256 case ETIR_S_C_STA_PQ
: return "ETIR_S_C_STA_PQ";
257 case ETIR_S_C_STA_LI
: return "ETIR_S_C_STA_LI";
258 case ETIR_S_C_STA_MOD
: return "ETIR_S_C_STA_MOD";
259 case ETIR_S_C_STA_CKARG
: return "ETIR_S_C_STA_CKARG";
260 case ETIR_S_C_STO_B
: return "ETIR_S_C_STO_B";
261 case ETIR_S_C_STO_W
: return "ETIR_S_C_STO_W";
262 case ETIR_S_C_STO_GBL
: return "ETIR_S_C_STO_GBL";
263 case ETIR_S_C_STO_CA
: return "ETIR_S_C_STO_CA";
264 case ETIR_S_C_STO_RB
: return "ETIR_S_C_STO_RB";
265 case ETIR_S_C_STO_AB
: return "ETIR_S_C_STO_AB";
266 case ETIR_S_C_STO_GBL_LW
: return "ETIR_S_C_STO_GBL_LW";
267 case ETIR_S_C_STO_LP_PSB
: return "ETIR_S_C_STO_LP_PSB";
268 case ETIR_S_C_STO_HINT_GBL
: return "ETIR_S_C_STO_HINT_GBL";
269 case ETIR_S_C_STO_HINT_PS
: return "ETIR_S_C_STO_HINT_PS";
270 case ETIR_S_C_OPR_INSV
: return "ETIR_S_C_OPR_INSV";
271 case ETIR_S_C_OPR_USH
: return "ETIR_S_C_OPR_USH";
272 case ETIR_S_C_OPR_ROT
: return "ETIR_S_C_OPR_ROT";
273 case ETIR_S_C_OPR_REDEF
: return "ETIR_S_C_OPR_REDEF";
274 case ETIR_S_C_OPR_DFLIT
: return "ETIR_S_C_OPR_DFLIT";
275 case ETIR_S_C_STC_LP
: return "ETIR_S_C_STC_LP";
276 case ETIR_S_C_STC_GBL
: return "ETIR_S_C_STC_GBL";
277 case ETIR_S_C_STC_GCA
: return "ETIR_S_C_STC_GCA";
278 case ETIR_S_C_STC_PS
: return "ETIR_S_C_STC_PS";
279 case ETIR_S_C_STC_NBH_PS
: return "ETIR_S_C_STC_NBH_PS";
280 case ETIR_S_C_STC_NOP_GBL
: return "ETIR_S_C_STC_NOP_GBL";
281 case ETIR_S_C_STC_NOP_PS
: return "ETIR_S_C_STC_NOP_PS";
282 case ETIR_S_C_STC_BSR_GBL
: return "ETIR_S_C_STC_BSR_GBL";
283 case ETIR_S_C_STC_BSR_PS
: return "ETIR_S_C_STC_BSR_PS";
284 case ETIR_S_C_STC_LDA_GBL
: return "ETIR_S_C_STC_LDA_GBL";
285 case ETIR_S_C_STC_LDA_PS
: return "ETIR_S_C_STC_LDA_PS";
286 case ETIR_S_C_STC_BOH_GBL
: return "ETIR_S_C_STC_BOH_GBL";
287 case ETIR_S_C_STC_BOH_PS
: return "ETIR_S_C_STC_BOH_PS";
288 case ETIR_S_C_STC_NBH_GBL
: return "ETIR_S_C_STC_NBH_GBL";
291 /* These names have not yet been added to this switch statement. */
295 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
301 handle sta_xxx commands in etir section
302 ptr points to data area in record
304 see table B-8 of the openVMS linker manual. */
307 etir_sta (abfd
, cmd
, ptr
)
314 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
315 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
325 stack 32 bit value of symbol (high bits set to 0) */
327 case ETIR_S_C_STA_GBL
:
330 vms_symbol_entry
*entry
;
332 name
= _bfd_vms_save_counted_string (ptr
);
333 entry
= (vms_symbol_entry
*)
334 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, FALSE
, FALSE
);
335 if (entry
== (vms_symbol_entry
*) NULL
)
338 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
339 cmd_name (cmd
), name
);
341 _bfd_vms_push (abfd
, (uquad
) 0, -1);
345 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
353 stack 32 bit value, sign extend to 64 bit */
355 case ETIR_S_C_STA_LW
:
356 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
362 stack 64 bit value of symbol */
364 case ETIR_S_C_STA_QW
:
365 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
368 /* stack psect base plus quadword offset
369 arg: lw section index
370 qw signed quadword offset (low 32 bits)
372 stack qw argument and section index
373 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
375 case ETIR_S_C_STA_PQ
:
380 psect
= bfd_getl32 (ptr
);
381 if (psect
>= PRIV (section_count
))
383 (*_bfd_error_handler
) (_("bad section index in %s"),
385 bfd_set_error (bfd_error_bad_value
);
388 dummy
= bfd_getl64 (ptr
+4);
389 _bfd_vms_push (abfd
, dummy
, (int) psect
);
393 case ETIR_S_C_STA_LI
:
394 case ETIR_S_C_STA_MOD
:
395 case ETIR_S_C_STA_CKARG
:
396 (*_bfd_error_handler
) (_("unsupported STA cmd %s"), cmd_name (cmd
));
401 (*_bfd_error_handler
) (_("reserved STA cmd %d"), cmd
);
406 _bfd_vms_debug (5, "etir_sta true\n");
416 handle sto_xxx commands in etir section
417 ptr points to data area in record
419 see table B-9 of the openVMS linker manual. */
422 etir_sto (abfd
, cmd
, ptr
)
431 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
432 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
437 /* store byte: pop stack, write byte
441 dummy
= _bfd_vms_pop (abfd
, &psect
);
443 if (is_share
) /* FIXME */
444 (*_bfd_error_handler
) ("%s: byte fixups not supported",
447 /* FIXME: check top bits */
448 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
451 /* store word: pop stack, write word
455 dummy
= _bfd_vms_pop (abfd
, &psect
);
457 if (is_share
) /* FIXME */
458 (*_bfd_error_handler
) ("%s: word fixups not supported",
461 /* FIXME: check top bits */
462 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
465 /* store longword: pop stack, write longword
468 case ETIR_S_C_STO_LW
:
469 dummy
= _bfd_vms_pop (abfd
, &psect
);
470 dummy
+= (PRIV (sections
)[psect
])->vma
;
471 /* FIXME: check top bits. */
472 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
475 /* store quadword: pop stack, write quadword
478 case ETIR_S_C_STO_QW
:
479 dummy
= _bfd_vms_pop (abfd
, &psect
);
480 dummy
+= (PRIV (sections
)[psect
])->vma
;
481 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
484 /* store immediate repeated: pop stack for repeat count
488 case ETIR_S_C_STO_IMMR
:
492 size
= bfd_getl32 (ptr
);
493 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
495 image_dump (abfd
, ptr
+4, size
, 0);
499 /* store global: write symbol value
500 arg: cs global symbol name. */
502 case ETIR_S_C_STO_GBL
:
504 vms_symbol_entry
*entry
;
507 name
= _bfd_vms_save_counted_string (ptr
);
508 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
510 if (entry
== (vms_symbol_entry
*) NULL
)
512 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
513 cmd_name (cmd
), name
);
518 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
));
522 /* store code address: write address of entry point
523 arg: cs global symbol name (procedure). */
525 case ETIR_S_C_STO_CA
:
527 vms_symbol_entry
*entry
;
530 name
= _bfd_vms_save_counted_string (ptr
);
531 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
533 if (entry
== (vms_symbol_entry
*) NULL
)
535 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
536 cmd_name (cmd
), name
);
540 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
544 /* Store offset to psect: pop stack, add low 32 bits to base of psect
547 case ETIR_S_C_STO_OFF
:
552 q
= _bfd_vms_pop (abfd
, &psect1
);
553 q
+= (PRIV (sections
)[psect1
])->vma
;
554 image_write_q (abfd
, q
);
559 arg: lw count of bytes
562 case ETIR_S_C_STO_IMM
:
566 size
= bfd_getl32 (ptr
);
567 image_dump (abfd
, ptr
+4, size
, 0);
571 /* This code is 'reserved to digital' according to the openVMS
572 linker manual, however it is generated by the DEC C compiler
573 and defined in the include file.
574 FIXME, since the following is just a guess
575 store global longword: store 32bit value of symbol
576 arg: cs symbol name. */
578 case ETIR_S_C_STO_GBL_LW
:
580 vms_symbol_entry
*entry
;
583 name
= _bfd_vms_save_counted_string (ptr
);
584 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
586 if (entry
== (vms_symbol_entry
*) NULL
)
589 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd
), name
);
591 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
595 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
));
599 case ETIR_S_C_STO_RB
:
600 case ETIR_S_C_STO_AB
:
601 case ETIR_S_C_STO_LP_PSB
:
602 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
605 case ETIR_S_C_STO_HINT_GBL
:
606 case ETIR_S_C_STO_HINT_PS
:
607 (*_bfd_error_handler
) (_("%s: not implemented"), cmd_name (cmd
));
611 (*_bfd_error_handler
) (_("reserved STO cmd %d"), cmd
);
618 /* Stack operator commands
619 all 32 bit signed arithmetic
620 all word just like a stack calculator
621 arguments are popped from stack, results are pushed on stack
623 see table B-10 of the openVMS linker manual. */
626 etir_opr (abfd
, cmd
, ptr
)
629 unsigned char *ptr ATTRIBUTE_UNUSED
;
634 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
635 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
640 case ETIR_S_C_OPR_NOP
: /* no-op */
643 case ETIR_S_C_OPR_ADD
: /* add */
644 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
645 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
646 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
649 case ETIR_S_C_OPR_SUB
: /* subtract */
650 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
651 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
652 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
655 case ETIR_S_C_OPR_MUL
: /* multiply */
656 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
657 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
658 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
661 case ETIR_S_C_OPR_DIV
: /* divide */
662 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
663 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
665 _bfd_vms_push (abfd
, (uquad
) 0, -1);
667 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
670 case ETIR_S_C_OPR_AND
: /* logical and */
671 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
672 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
673 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
676 case ETIR_S_C_OPR_IOR
: /* logical inclusive or */
677 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
678 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
679 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
682 case ETIR_S_C_OPR_EOR
: /* logical exclusive or */
683 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
684 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
685 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
688 case ETIR_S_C_OPR_NEG
: /* negate */
689 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
690 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
693 case ETIR_S_C_OPR_COM
: /* complement */
694 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
695 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
698 case ETIR_S_C_OPR_ASH
: /* arithmetic shift */
699 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
700 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
701 if (op2
< 0) /* shift right */
703 else /* shift left */
705 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
708 case ETIR_S_C_OPR_INSV
: /* insert field */
709 (void) _bfd_vms_pop (abfd
, NULL
);
710 case ETIR_S_C_OPR_USH
: /* unsigned shift */
711 case ETIR_S_C_OPR_ROT
: /* rotate */
712 case ETIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
713 case ETIR_S_C_OPR_DFLIT
: /* Define a literal. */
714 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
717 case ETIR_S_C_OPR_SEL
: /* select */
718 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
719 (void) _bfd_vms_pop (abfd
, NULL
);
722 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
723 (void) _bfd_vms_pop (abfd
, NULL
);
724 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
729 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), cmd
);
738 See table B-11 of the openVMS linker manual. */
741 etir_ctl (abfd
, cmd
, ptr
)
750 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
751 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
756 /* set relocation base: pop stack, set image location counter
759 case ETIR_S_C_CTL_SETRB
:
760 dummy
= _bfd_vms_pop (abfd
, &psect
);
761 image_set_ptr (abfd
, psect
, dummy
);
764 /* augment relocation base: increment image location counter by offset
765 arg: lw offset value */
767 case ETIR_S_C_CTL_AUGRB
:
768 dummy
= bfd_getl32 (ptr
);
769 image_inc_ptr (abfd
, dummy
);
772 /* define location: pop index, save location counter under index
775 case ETIR_S_C_CTL_DFLOC
:
776 dummy
= _bfd_vms_pop (abfd
, NULL
);
780 /* set location: pop index, restore location counter from index
783 case ETIR_S_C_CTL_STLOC
:
784 dummy
= _bfd_vms_pop (abfd
, &psect
);
788 /* stack defined location: pop index, push location counter from index
791 case ETIR_S_C_CTL_STKDL
:
792 dummy
= _bfd_vms_pop (abfd
, &psect
);
797 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), cmd
);
803 /* store conditional commands
805 See table B-12 and B-13 of the openVMS linker manual. */
808 etir_stc (abfd
, cmd
, ptr
)
811 unsigned char *ptr ATTRIBUTE_UNUSED
;
814 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
815 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
820 /* 200 Store-conditional Linkage Pair
823 case ETIR_S_C_STC_LP
:
824 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
827 /* 201 Store-conditional Linkage Pair with Procedure Signature
828 arg: lw linkage index
833 case ETIR_S_C_STC_LP_PSB
:
834 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
837 /* 202 Store-conditional Address at global address
838 arg: lw linkage index
841 case ETIR_S_C_STC_GBL
:
842 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
845 /* 203 Store-conditional Code Address at global address
846 arg: lw linkage index
847 cs procedure name. */
849 case ETIR_S_C_STC_GCA
:
850 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
853 /* 204 Store-conditional Address at psect + offset
854 arg: lw linkage index
858 case ETIR_S_C_STC_PS
:
859 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
862 /* 205 Store-conditional NOP at address of global
865 case ETIR_S_C_STC_NOP_GBL
:
867 /* 206 Store-conditional NOP at pect + offset
870 case ETIR_S_C_STC_NOP_PS
:
872 /* 207 Store-conditional BSR at global address
875 case ETIR_S_C_STC_BSR_GBL
:
877 /* 208 Store-conditional BSR at pect + offset
880 case ETIR_S_C_STC_BSR_PS
:
882 /* 209 Store-conditional LDA at global address
885 case ETIR_S_C_STC_LDA_GBL
:
887 /* 210 Store-conditional LDA at psect + offset
890 case ETIR_S_C_STC_LDA_PS
:
892 /* 211 Store-conditional BSR or Hint at global address
895 case ETIR_S_C_STC_BOH_GBL
:
897 /* 212 Store-conditional BSR or Hint at pect + offset
900 case ETIR_S_C_STC_BOH_PS
:
902 /* 213 Store-conditional NOP,BSR or HINT at global address
905 case ETIR_S_C_STC_NBH_GBL
:
907 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
910 case ETIR_S_C_STC_NBH_PS
:
913 (*_bfd_error_handler
) ("%s: not supported", cmd_name (cmd
));
919 _bfd_vms_debug (3, "reserved STC cmd %d", cmd
);
927 new_section (abfd
, idx
)
928 bfd
*abfd ATTRIBUTE_UNUSED
;
936 _bfd_vms_debug (5, "new_section %d\n", idx
);
938 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
940 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
943 strcpy (name
, sname
);
945 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
949 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
956 section
->contents
= 0;
957 section
->name
= name
;
958 section
->index
= idx
;
964 alloc_section (abfd
, idx
)
971 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
975 amt
*= sizeof (asection
*);
976 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
977 if (PRIV (sections
) == 0)
980 while (PRIV (section_count
) <= idx
)
982 PRIV (sections
)[PRIV (section_count
)]
983 = new_section (abfd
, (int) PRIV (section_count
));
984 if (PRIV (sections
)[PRIV (section_count
)] == 0)
986 PRIV (section_count
)++;
996 Handle sta_xxx commands in tir section
997 ptr points to data area in record
999 See table 7-3 of the VAX/VMS linker manual. */
1001 static unsigned char *
1002 tir_sta (bfd
*abfd
, unsigned char *ptr
)
1007 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
1013 case TIR_S_C_STA_GBL
:
1017 stack 32 bit value of symbol (high bits set to 0). */
1020 vms_symbol_entry
*entry
;
1022 name
= _bfd_vms_save_counted_string (ptr
);
1024 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1025 if (entry
== (vms_symbol_entry
*) NULL
)
1028 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1033 case TIR_S_C_STA_SB
:
1034 /* stack signed byte
1037 stack byte value, sign extend to 32 bit. */
1038 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1041 case TIR_S_C_STA_SW
:
1042 /* stack signed short word
1045 stack 16 bit value, sign extend to 32 bit. */
1046 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1050 case TIR_S_C_STA_LW
:
1051 /* stack signed longword
1054 stack 32 bit value. */
1055 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1059 case TIR_S_C_STA_PB
:
1060 case TIR_S_C_STA_WPB
:
1061 /* stack psect base plus byte offset (word index)
1062 arg: by section index
1064 by signed byte offset. */
1066 unsigned long dummy
;
1069 if (cmd
== TIR_S_C_STA_PB
)
1073 psect
= bfd_getl16 (ptr
);
1077 if (psect
>= PRIV (section_count
))
1078 alloc_section (abfd
, psect
);
1080 dummy
= (long) *ptr
++;
1081 dummy
+= (PRIV (sections
)[psect
])->vma
;
1082 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1086 case TIR_S_C_STA_PW
:
1087 case TIR_S_C_STA_WPW
:
1088 /* stack psect base plus word offset (word index)
1089 arg: by section index
1091 sh signed short offset. */
1093 unsigned long dummy
;
1096 if (cmd
== TIR_S_C_STA_PW
)
1100 psect
= bfd_getl16 (ptr
);
1104 if (psect
>= PRIV (section_count
))
1105 alloc_section (abfd
, psect
);
1107 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1108 dummy
+= (PRIV (sections
)[psect
])->vma
;
1109 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1113 case TIR_S_C_STA_PL
:
1114 case TIR_S_C_STA_WPL
:
1115 /* stack psect base plus long offset (word index)
1116 arg: by section index
1118 lw signed longword offset. */
1120 unsigned long dummy
;
1123 if (cmd
== TIR_S_C_STA_PL
)
1127 psect
= bfd_getl16 (ptr
);
1131 if (psect
>= PRIV (section_count
))
1132 alloc_section (abfd
, psect
);
1134 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1135 dummy
+= (PRIV (sections
)[psect
])->vma
;
1136 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1140 case TIR_S_C_STA_UB
:
1141 /* stack unsigned byte
1144 stack byte value. */
1145 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1148 case TIR_S_C_STA_UW
:
1149 /* stack unsigned short word
1152 stack 16 bit value. */
1153 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1157 case TIR_S_C_STA_BFI
:
1158 /* stack byte from image
1161 case TIR_S_C_STA_WFI
:
1162 /* stack byte from image
1165 case TIR_S_C_STA_LFI
:
1166 /* stack byte from image
1168 (*_bfd_error_handler
) (_("stack-from-image not implemented"));
1171 case TIR_S_C_STA_EPM
:
1172 /* stack entry point mask
1175 stack (unsigned) entry point mask of symbol
1176 err if symbol is no entry point. */
1179 vms_symbol_entry
*entry
;
1181 name
= _bfd_vms_save_counted_string (ptr
);
1182 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1183 if (entry
== (vms_symbol_entry
*) NULL
)
1186 (*_bfd_error_handler
) (_("stack-entry-mask not fully implemented"));
1187 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1192 case TIR_S_C_STA_CKARG
:
1193 /* compare procedure argument
1196 da argument descriptor
1198 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1199 and stack TRUE (args match) or FALSE (args dont match) value. */
1200 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1201 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1204 case TIR_S_C_STA_LSY
:
1205 /* stack local symbol value
1206 arg: sh environment index
1211 vms_symbol_entry
*entry
;
1213 envidx
= bfd_getl16 (ptr
);
1215 name
= _bfd_vms_save_counted_string (ptr
);
1216 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1217 if (entry
== (vms_symbol_entry
*) NULL
)
1219 (*_bfd_error_handler
) (_("stack-local-symbol not fully implemented"));
1220 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1225 case TIR_S_C_STA_LIT
:
1227 arg: by literal index
1231 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1232 (*_bfd_error_handler
) (_("stack-literal not fully implemented"));
1235 case TIR_S_C_STA_LEPM
:
1236 /* stack local symbol entry point mask
1237 arg: sh environment index
1240 stack (unsigned) entry point mask of symbol
1241 err if symbol is no entry point. */
1245 vms_symbol_entry
*entry
;
1247 envidx
= bfd_getl16 (ptr
);
1249 name
= _bfd_vms_save_counted_string (ptr
);
1250 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1251 if (entry
== (vms_symbol_entry
*) NULL
)
1253 (*_bfd_error_handler
) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1254 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1260 (*_bfd_error_handler
) (_("reserved STA cmd %d"), ptr
[-1]);
1274 case TIR_S_C_STO_RSB
: return "TIR_S_C_STO_RSB";
1275 case TIR_S_C_STO_RSW
: return "TIR_S_C_STO_RSW";
1276 case TIR_S_C_STO_RL
: return "TIR_S_C_STO_RL";
1277 case TIR_S_C_STO_VPS
: return "TIR_S_C_STO_VPS";
1278 case TIR_S_C_STO_USB
: return "TIR_S_C_STO_USB";
1279 case TIR_S_C_STO_USW
: return "TIR_S_C_STO_USW";
1280 case TIR_S_C_STO_RUB
: return "TIR_S_C_STO_RUB";
1281 case TIR_S_C_STO_RUW
: return "TIR_S_C_STO_RUW";
1282 case TIR_S_C_STO_PIRR
: return "TIR_S_C_STO_PIRR";
1283 case TIR_S_C_OPR_INSV
: return "TIR_S_C_OPR_INSV";
1284 case TIR_S_C_OPR_DFLIT
: return "TIR_S_C_OPR_DFLIT";
1285 case TIR_S_C_OPR_REDEF
: return "TIR_S_C_OPR_REDEF";
1286 case TIR_S_C_OPR_ROT
: return "TIR_S_C_OPR_ROT";
1287 case TIR_S_C_OPR_USH
: return "TIR_S_C_OPR_USH";
1288 case TIR_S_C_OPR_ASH
: return "TIR_S_C_OPR_ASH";
1289 case TIR_S_C_CTL_DFLOC
: return "TIR_S_C_CTL_DFLOC";
1290 case TIR_S_C_CTL_STLOC
: return "TIR_S_C_CTL_STLOC";
1291 case TIR_S_C_CTL_STKDL
: return "TIR_S_C_CTL_STKDL";
1294 /* These strings have not been added yet. */
1303 handle sto_xxx commands in tir section
1304 ptr points to data area in record
1306 See table 7-4 of the VAX/VMS linker manual. */
1308 static unsigned char *
1309 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1311 unsigned long dummy
;
1316 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1321 case TIR_S_C_STO_SB
:
1322 /* store signed byte: pop stack, write byte
1324 dummy
= _bfd_vms_pop (abfd
, &psect
);
1325 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1328 case TIR_S_C_STO_SW
:
1329 /* 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
:
1336 /* store longword: pop stack, write longword
1338 dummy
= _bfd_vms_pop (abfd
, &psect
);
1339 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1342 case TIR_S_C_STO_BD
:
1343 /* store byte displaced: pop stack, sub lc+1, write byte
1345 dummy
= _bfd_vms_pop (abfd
, &psect
);
1346 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1347 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1350 case TIR_S_C_STO_WD
:
1351 /* store word displaced: pop stack, sub lc+2, write word
1353 dummy
= _bfd_vms_pop (abfd
, &psect
);
1354 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1355 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1358 case TIR_S_C_STO_LD
:
1359 /* store long displaced: pop stack, sub lc+4, write long
1361 dummy
= _bfd_vms_pop (abfd
, &psect
);
1362 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1363 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1366 case TIR_S_C_STO_LI
:
1367 /* store short literal: pop stack, write byte
1369 dummy
= _bfd_vms_pop (abfd
, &psect
);
1370 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1373 case TIR_S_C_STO_PIDR
:
1374 /* store position independent data reference: pop stack, write longword
1376 FIXME: incomplete ! */
1377 dummy
= _bfd_vms_pop (abfd
, &psect
);
1378 image_write_l (abfd
, dummy
& 0xffffffff);
1381 case TIR_S_C_STO_PICR
:
1382 /* store position independent code reference: pop stack, write longword
1384 FIXME: incomplete ! */
1385 dummy
= _bfd_vms_pop (abfd
, &psect
);
1386 image_write_b (abfd
, 0x9f);
1387 image_write_l (abfd
, dummy
& 0xffffffff);
1390 case TIR_S_C_STO_RIVB
:
1391 /* store repeated immediate variable bytes
1392 1-byte count n field followed by n bytes of data
1393 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. */
1403 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1404 image_write_b (abfd
, dummy
& 0xff);
1408 /* store word from top longword. */
1409 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1410 image_write_w (abfd
, dummy
& 0xffff);
1413 case TIR_S_C_STO_RB
:
1414 /* store repeated byte from top longword. */
1415 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1416 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1418 image_write_b (abfd
, dummy
& 0xff);
1421 case TIR_S_C_STO_RW
:
1422 /* store repeated word from top longword. */
1423 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1424 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1426 image_write_w (abfd
, dummy
& 0xffff);
1429 case TIR_S_C_STO_RSB
:
1430 case TIR_S_C_STO_RSW
:
1431 case TIR_S_C_STO_RL
:
1432 case TIR_S_C_STO_VPS
:
1433 case TIR_S_C_STO_USB
:
1434 case TIR_S_C_STO_USW
:
1435 case TIR_S_C_STO_RUB
:
1436 case TIR_S_C_STO_RUW
:
1437 case TIR_S_C_STO_PIRR
:
1438 (*_bfd_error_handler
) (_("%s: not implemented"), tir_cmd_name (ptr
[-1]));
1442 (*_bfd_error_handler
) (_("reserved STO cmd %d"), ptr
[-1]);
1449 /* stack operator commands
1450 all 32 bit signed arithmetic
1451 all word just like a stack calculator
1452 arguments are popped from stack, results are pushed on stack
1454 See table 7-5 of the VAX/VMS linker manual. */
1456 static unsigned char *
1464 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1470 case TIR_S_C_OPR_NOP
: /* no-op */
1473 case TIR_S_C_OPR_ADD
: /* add */
1474 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1475 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1476 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1479 case TIR_S_C_OPR_SUB
: /* subtract */
1480 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1481 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1482 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1485 case TIR_S_C_OPR_MUL
: /* multiply */
1486 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1487 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1488 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1491 case TIR_S_C_OPR_DIV
: /* divide */
1492 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1493 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1495 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1497 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1500 case TIR_S_C_OPR_AND
: /* logical and */
1501 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1502 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1503 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1506 case TIR_S_C_OPR_IOR
: /* logical inclusive or */
1507 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1508 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1509 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1512 case TIR_S_C_OPR_EOR
: /* logical exclusive or */
1513 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1514 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1515 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1518 case TIR_S_C_OPR_NEG
: /* negate */
1519 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1520 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1523 case TIR_S_C_OPR_COM
: /* complement */
1524 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1525 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1528 case TIR_S_C_OPR_INSV
: /* insert field */
1529 (void) _bfd_vms_pop (abfd
, NULL
);
1530 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1531 tir_cmd_name (ptr
[-1]));
1534 case TIR_S_C_OPR_ASH
: /* arithmetic shift */
1535 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1536 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1537 if (HIGHBIT (op1
)) /* shift right */
1539 else /* shift left */
1541 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1542 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1543 tir_cmd_name (ptr
[-1]));
1546 case TIR_S_C_OPR_USH
: /* unsigned shift */
1547 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1548 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1549 if (HIGHBIT (op1
)) /* shift right */
1551 else /* shift left */
1553 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1554 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1555 tir_cmd_name (ptr
[-1]));
1558 case TIR_S_C_OPR_ROT
: /* rotate */
1559 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1560 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1561 if (HIGHBIT (0)) /* shift right */
1563 else /* shift left */
1565 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1566 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1567 tir_cmd_name (ptr
[-1]));
1570 case TIR_S_C_OPR_SEL
: /* select */
1571 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1572 (void) _bfd_vms_pop (abfd
, NULL
);
1575 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1576 (void) _bfd_vms_pop (abfd
, NULL
);
1577 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1581 case TIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
1582 case TIR_S_C_OPR_DFLIT
: /* Define a literal. */
1583 (*_bfd_error_handler
) (_("%s: not supported"),
1584 tir_cmd_name (ptr
[-1]));
1588 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), ptr
[-1]);
1597 See table 7-6 of the VAX/VMS linker manual. */
1599 static unsigned char *
1600 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1602 unsigned long dummy
;
1606 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1611 case TIR_S_C_CTL_SETRB
:
1612 /* Set relocation base: pop stack, set image location counter
1614 dummy
= _bfd_vms_pop (abfd
, &psect
);
1615 if (psect
>= PRIV (section_count
))
1616 alloc_section (abfd
, psect
);
1617 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1620 case TIR_S_C_CTL_AUGRB
:
1621 /* Augment relocation base: increment image location counter by offset
1622 arg: lw offset value. */
1623 dummy
= bfd_getl32 (ptr
);
1624 image_inc_ptr (abfd
, (uquad
) dummy
);
1627 case TIR_S_C_CTL_DFLOC
:
1628 /* Define location: pop index, save location counter under index
1630 dummy
= _bfd_vms_pop (abfd
, NULL
);
1631 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1632 tir_cmd_name (ptr
[-1]));
1635 case TIR_S_C_CTL_STLOC
:
1636 /* Set location: pop index, restore location counter from index
1638 dummy
= _bfd_vms_pop (abfd
, &psect
);
1639 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1640 tir_cmd_name (ptr
[-1]));
1643 case TIR_S_C_CTL_STKDL
:
1644 /* Stack defined location: pop index, push location counter from index
1646 dummy
= _bfd_vms_pop (abfd
, &psect
);
1647 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1648 tir_cmd_name (ptr
[-1]));
1652 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), ptr
[-1]);
1658 /* Handle command from TIR section. */
1660 static unsigned char *
1661 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1667 unsigned char * (*explain
) (bfd
*, unsigned char *);
1671 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1672 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1673 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1674 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1680 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1681 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1684 if (*ptr
& 0x80) /* store immediate */
1686 i
= 128 - (*ptr
++ & 0x7f);
1687 image_dump (abfd
, ptr
, i
, 0);
1692 while (tir_table
[i
].mincod
>= 0)
1694 if ( (tir_table
[i
].mincod
<= *ptr
)
1695 && (*ptr
<= tir_table
[i
].maxcod
))
1697 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1702 if (tir_table
[i
].mincod
< 0)
1704 (*_bfd_error_handler
) (_("obj code %d not found"), *ptr
);
1712 /* Handle command from ETIR section. */
1715 etir_cmd (abfd
, cmd
, ptr
)
1724 bfd_boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1728 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1729 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1730 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1731 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1732 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1739 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1740 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1743 while (etir_table
[i
].mincod
>= 0)
1745 if ( (etir_table
[i
].mincod
<= cmd
)
1746 && (cmd
<= etir_table
[i
].maxcod
))
1748 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1756 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1761 /* Text Information and Relocation Records (OBJ$C_TIR)
1762 handle tir record. */
1765 analyze_tir (abfd
, ptr
, length
)
1768 unsigned int length
;
1770 unsigned char *maxptr
;
1773 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1776 maxptr
= ptr
+ length
;
1778 while (ptr
< maxptr
)
1780 ptr
= tir_cmd (abfd
, ptr
);
1788 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1789 handle etir record. */
1792 analyze_etir (abfd
, ptr
, length
)
1795 unsigned int length
;
1798 unsigned char *maxptr
;
1802 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1805 maxptr
= ptr
+ length
;
1807 while (ptr
< maxptr
)
1809 cmd
= bfd_getl16 (ptr
);
1810 length
= bfd_getl16 (ptr
+ 2);
1811 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1818 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1824 /* Process ETIR record
1825 Return 0 on success, -1 on error. */
1828 _bfd_vms_slurp_tir (abfd
, objtype
)
1835 _bfd_vms_debug (2, "TIR/ETIR\n");
1841 PRIV (vms_rec
) += 4; /* skip type, size */
1842 PRIV (rec_size
) -= 4;
1843 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1846 PRIV (vms_rec
) += 1; /* skip type */
1847 PRIV (rec_size
) -= 1;
1848 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1858 /* Process EDBG record
1859 Return 0 on success, -1 on error
1861 Not implemented yet. */
1864 _bfd_vms_slurp_dbg (abfd
, objtype
)
1866 int objtype ATTRIBUTE_UNUSED
;
1869 _bfd_vms_debug (2, "DBG/EDBG\n");
1872 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1876 /* Process ETBT record
1877 Return 0 on success, -1 on error
1879 Not implemented yet. */
1882 _bfd_vms_slurp_tbt (abfd
, objtype
)
1883 bfd
*abfd ATTRIBUTE_UNUSED
;
1884 int objtype ATTRIBUTE_UNUSED
;
1887 _bfd_vms_debug (2, "TBT/ETBT\n");
1893 /* Process LNK record
1894 Return 0 on success, -1 on error
1896 Not implemented yet. */
1899 _bfd_vms_slurp_lnk (abfd
, objtype
)
1900 bfd
*abfd ATTRIBUTE_UNUSED
;
1901 int objtype ATTRIBUTE_UNUSED
;
1904 _bfd_vms_debug (2, "LNK\n");
1910 /* WRITE ETIR SECTION
1912 This is still under construction and therefore not documented. */
1914 static void start_etir_record
1915 PARAMS ((bfd
*abfd
, int index
, uquad offset
, bfd_boolean justoffset
));
1917 PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1918 static void end_etir_record
1919 PARAMS ((bfd
*abfd
));
1922 sto_imm (abfd
, sptr
, vaddr
, index
)
1930 unsigned char *cptr
;
1933 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1934 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
1938 cptr
= sptr
->contents
;
1942 size
= ssize
; /* try all the rest */
1944 if (_bfd_vms_output_check (abfd
, size
) < 0)
1945 { /* doesn't fit, split ! */
1946 end_etir_record (abfd
);
1947 start_etir_record (abfd
, index
, vaddr
, FALSE
);
1948 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
1949 if (size
> ssize
) /* more than what's left ? */
1953 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
1954 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
1955 _bfd_vms_output_dump (abfd
, cptr
, size
);
1956 _bfd_vms_output_flush (abfd
);
1959 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
1960 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
1969 /* Start ETIR record for section #index at virtual addr offset. */
1972 start_etir_record (abfd
, index
, offset
, justoffset
)
1976 bfd_boolean justoffset
;
1980 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
1981 _bfd_vms_output_push (abfd
);
1984 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
1985 _bfd_vms_output_long (abfd
, (unsigned long) index
);
1986 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
1987 _bfd_vms_output_flush (abfd
);
1989 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
1990 _bfd_vms_output_flush (abfd
);
1993 /* End etir record. */
1996 end_etir_record (abfd
)
1999 _bfd_vms_output_pop (abfd
);
2000 _bfd_vms_output_end (abfd
);
2003 /* Write section contents for bfd abfd. */
2006 _bfd_vms_write_tir (abfd
, objtype
)
2008 int objtype ATTRIBUTE_UNUSED
;
2015 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2018 _bfd_vms_output_alignment (abfd
, 4);
2021 PRIV (vms_linkage_index
) = 1;
2023 /* Dump all other sections. */
2025 section
= abfd
->sections
;
2027 while (section
!= NULL
)
2031 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2032 section
->index
, section
->name
,
2033 (int) (section
->size
));
2036 if (section
->flags
& SEC_RELOC
)
2040 if ((i
= section
->reloc_count
) <= 0)
2042 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2049 _bfd_vms_debug (4, "%d relocations:\n", i
);
2050 rptr
= section
->orelocation
;
2053 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2054 (*(*rptr
)->sym_ptr_ptr
)->name
,
2055 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2056 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2057 (*rptr
)->address
, (*rptr
)->addend
,
2058 bfd_get_reloc_size ((*rptr
)->howto
),
2059 (*rptr
)->howto
->name
);
2066 if ((section
->flags
& SEC_HAS_CONTENTS
)
2067 && (! bfd_is_com_section (section
)))
2069 bfd_vma vaddr
; /* Virtual addr in section. */
2071 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2074 bfd_set_error (bfd_error_no_contents
);
2078 vaddr
= (bfd_vma
) (sptr
->offset
);
2080 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2083 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2086 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2088 arelent
**rptr
= section
->orelocation
;
2089 int i
= section
->reloc_count
;
2093 bfd_size_type addr
= (*rptr
)->address
;
2094 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2095 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2097 bfd_size_type before
= addr
- sptr
->offset
;
2098 if (sptr
->size
<= before
) /* complete before */
2100 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2101 vaddr
+= sptr
->size
;
2104 else /* partly before */
2106 int after
= sptr
->size
- before
;
2107 sptr
->size
= before
;
2108 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2109 vaddr
+= sptr
->size
;
2110 sptr
->contents
+= before
;
2111 sptr
->offset
+= before
;
2115 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2117 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2118 asection
*sec
= sym
->section
;
2120 switch ((*rptr
)->howto
->type
)
2122 case ALPHA_R_IGNORE
:
2125 case ALPHA_R_REFLONG
:
2127 if (bfd_is_und_section (sym
->section
))
2129 int slen
= strlen ((char *) sym
->name
);
2132 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2134 end_etir_record (abfd
);
2135 start_etir_record (abfd
,
2139 _bfd_vms_output_begin (abfd
,
2140 ETIR_S_C_STO_GBL_LW
,
2142 hash
= (_bfd_vms_length_hash_symbol
2143 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2144 _bfd_vms_output_counted (abfd
, hash
);
2145 _bfd_vms_output_flush (abfd
);
2147 else if (bfd_is_abs_section (sym
->section
))
2149 if (_bfd_vms_output_check (abfd
, 16) < 0)
2151 end_etir_record (abfd
);
2152 start_etir_record (abfd
,
2156 _bfd_vms_output_begin (abfd
,
2159 _bfd_vms_output_quad (abfd
,
2160 (uquad
) sym
->value
);
2161 _bfd_vms_output_flush (abfd
);
2162 _bfd_vms_output_begin (abfd
,
2165 _bfd_vms_output_flush (abfd
);
2169 if (_bfd_vms_output_check (abfd
, 32) < 0)
2171 end_etir_record (abfd
);
2172 start_etir_record (abfd
,
2176 _bfd_vms_output_begin (abfd
,
2179 _bfd_vms_output_long (abfd
,
2180 (unsigned long) (sec
->index
));
2181 _bfd_vms_output_quad (abfd
,
2182 ((uquad
) (*rptr
)->addend
2183 + (uquad
) sym
->value
));
2184 _bfd_vms_output_flush (abfd
);
2185 _bfd_vms_output_begin (abfd
,
2188 _bfd_vms_output_flush (abfd
);
2193 case ALPHA_R_REFQUAD
:
2195 if (bfd_is_und_section (sym
->section
))
2197 int slen
= strlen ((char *) sym
->name
);
2199 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2201 end_etir_record (abfd
);
2202 start_etir_record (abfd
,
2206 _bfd_vms_output_begin (abfd
,
2209 hash
= (_bfd_vms_length_hash_symbol
2210 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2211 _bfd_vms_output_counted (abfd
, hash
);
2212 _bfd_vms_output_flush (abfd
);
2214 else if (bfd_is_abs_section (sym
->section
))
2216 if (_bfd_vms_output_check (abfd
, 16) < 0)
2218 end_etir_record (abfd
);
2219 start_etir_record (abfd
,
2223 _bfd_vms_output_begin (abfd
,
2226 _bfd_vms_output_quad (abfd
,
2227 (uquad
) sym
->value
);
2228 _bfd_vms_output_flush (abfd
);
2229 _bfd_vms_output_begin (abfd
,
2232 _bfd_vms_output_flush (abfd
);
2236 if (_bfd_vms_output_check (abfd
, 32) < 0)
2238 end_etir_record (abfd
);
2239 start_etir_record (abfd
,
2243 _bfd_vms_output_begin (abfd
,
2246 _bfd_vms_output_long (abfd
,
2247 (unsigned long) (sec
->index
));
2248 _bfd_vms_output_quad (abfd
,
2249 ((uquad
) (*rptr
)->addend
2250 + (uquad
) sym
->value
));
2251 _bfd_vms_output_flush (abfd
);
2252 _bfd_vms_output_begin (abfd
,
2255 _bfd_vms_output_flush (abfd
);
2263 char *hash ATTRIBUTE_UNUSED
;
2265 hint_size
= sptr
->size
;
2267 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2268 sptr
->size
= hint_size
;
2270 vms_output_begin (abfd
,
2271 ETIR_S_C_STO_HINT_GBL
, -1);
2272 vms_output_long (abfd
,
2273 (unsigned long) (sec
->index
));
2274 vms_output_quad (abfd
, (uquad
) addr
);
2276 hash
= (_bfd_vms_length_hash_symbol
2277 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2278 vms_output_counted (abfd
, hash
);
2280 vms_output_flush (abfd
);
2284 case ALPHA_R_LINKAGE
:
2288 if (_bfd_vms_output_check (abfd
, 64) < 0)
2290 end_etir_record (abfd
);
2291 start_etir_record (abfd
, section
->index
,
2294 _bfd_vms_output_begin (abfd
,
2295 ETIR_S_C_STC_LP_PSB
,
2297 _bfd_vms_output_long (abfd
,
2298 (unsigned long) PRIV (vms_linkage_index
));
2299 PRIV (vms_linkage_index
) += 2;
2300 hash
= (_bfd_vms_length_hash_symbol
2301 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2302 _bfd_vms_output_counted (abfd
, hash
);
2303 _bfd_vms_output_byte (abfd
, 0);
2304 _bfd_vms_output_flush (abfd
);
2308 case ALPHA_R_CODEADDR
:
2310 int slen
= strlen ((char *) sym
->name
);
2312 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2314 end_etir_record (abfd
);
2315 start_etir_record (abfd
,
2319 _bfd_vms_output_begin (abfd
,
2322 hash
= (_bfd_vms_length_hash_symbol
2323 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2324 _bfd_vms_output_counted (abfd
, hash
);
2325 _bfd_vms_output_flush (abfd
);
2330 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2331 (*rptr
)->howto
->name
);
2337 if (len
== sptr
->size
)
2343 sptr
->contents
+= len
;
2344 sptr
->offset
+= len
;
2350 else /* sptr starts after reloc */
2352 i
--; /* check next reloc */
2356 if (i
==0) /* all reloc checked */
2361 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2362 vaddr
+= sptr
->size
;
2367 } /* if SEC_RELOC */
2368 else /* no relocs, just dump */
2370 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2371 vaddr
+= sptr
->size
;
2376 } /* while (sptr != 0) */
2378 end_etir_record (abfd
);
2380 } /* has_contents */
2382 section
= section
->next
;
2385 _bfd_vms_output_alignment (abfd
, 2);
2389 /* Write traceback data for bfd abfd. */
2392 _bfd_vms_write_tbt (abfd
, objtype
)
2393 bfd
*abfd ATTRIBUTE_UNUSED
;
2394 int objtype ATTRIBUTE_UNUSED
;
2397 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2403 /* Write debug info for bfd abfd. */
2406 _bfd_vms_write_dbg (abfd
, objtype
)
2407 bfd
*abfd ATTRIBUTE_UNUSED
;
2408 int objtype ATTRIBUTE_UNUSED
;
2411 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);