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
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
)->_raw_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
)->_raw_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
);
954 section
->_raw_size
= 0;
956 section
->contents
= 0;
957 section
->_cooked_size
= 0;
958 section
->name
= name
;
959 section
->index
= idx
;
965 alloc_section (abfd
, idx
)
972 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
976 amt
*= sizeof (asection
*);
977 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
978 if (PRIV (sections
) == 0)
981 while (PRIV (section_count
) <= idx
)
983 PRIV (sections
)[PRIV (section_count
)]
984 = new_section (abfd
, (int) PRIV (section_count
));
985 if (PRIV (sections
)[PRIV (section_count
)] == 0)
987 PRIV (section_count
)++;
997 Handle sta_xxx commands in tir section
998 ptr points to data area in record
1000 See table 7-3 of the VAX/VMS linker manual. */
1002 static unsigned char *
1003 tir_sta (bfd
*abfd
, unsigned char *ptr
)
1008 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
1014 case TIR_S_C_STA_GBL
:
1018 stack 32 bit value of symbol (high bits set to 0). */
1021 vms_symbol_entry
*entry
;
1023 name
= _bfd_vms_save_counted_string (ptr
);
1025 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1026 if (entry
== (vms_symbol_entry
*) NULL
)
1029 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1034 case TIR_S_C_STA_SB
:
1035 /* stack signed byte
1038 stack byte value, sign extend to 32 bit. */
1039 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1042 case TIR_S_C_STA_SW
:
1043 /* stack signed short word
1046 stack 16 bit value, sign extend to 32 bit. */
1047 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1051 case TIR_S_C_STA_LW
:
1052 /* stack signed longword
1055 stack 32 bit value. */
1056 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1060 case TIR_S_C_STA_PB
:
1061 case TIR_S_C_STA_WPB
:
1062 /* stack psect base plus byte offset (word index)
1063 arg: by section index
1065 by signed byte offset. */
1067 unsigned long dummy
;
1070 if (cmd
== TIR_S_C_STA_PB
)
1074 psect
= bfd_getl16 (ptr
);
1078 if (psect
>= PRIV (section_count
))
1079 alloc_section (abfd
, psect
);
1081 dummy
= (long) *ptr
++;
1082 dummy
+= (PRIV (sections
)[psect
])->vma
;
1083 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1087 case TIR_S_C_STA_PW
:
1088 case TIR_S_C_STA_WPW
:
1089 /* stack psect base plus word offset (word index)
1090 arg: by section index
1092 sh signed short offset. */
1094 unsigned long dummy
;
1097 if (cmd
== TIR_S_C_STA_PW
)
1101 psect
= bfd_getl16 (ptr
);
1105 if (psect
>= PRIV (section_count
))
1106 alloc_section (abfd
, psect
);
1108 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1109 dummy
+= (PRIV (sections
)[psect
])->vma
;
1110 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1114 case TIR_S_C_STA_PL
:
1115 case TIR_S_C_STA_WPL
:
1116 /* stack psect base plus long offset (word index)
1117 arg: by section index
1119 lw signed longword offset. */
1121 unsigned long dummy
;
1124 if (cmd
== TIR_S_C_STA_PL
)
1128 psect
= bfd_getl16 (ptr
);
1132 if (psect
>= PRIV (section_count
))
1133 alloc_section (abfd
, psect
);
1135 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1136 dummy
+= (PRIV (sections
)[psect
])->vma
;
1137 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1141 case TIR_S_C_STA_UB
:
1142 /* stack unsigned byte
1145 stack byte value. */
1146 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1149 case TIR_S_C_STA_UW
:
1150 /* stack unsigned short word
1153 stack 16 bit value. */
1154 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1158 case TIR_S_C_STA_BFI
:
1159 /* stack byte from image
1162 case TIR_S_C_STA_WFI
:
1163 /* stack byte from image
1166 case TIR_S_C_STA_LFI
:
1167 /* stack byte from image
1169 (*_bfd_error_handler
) (_("stack-from-image not implemented"));
1172 case TIR_S_C_STA_EPM
:
1173 /* stack entry point mask
1176 stack (unsigned) entry point mask of symbol
1177 err if symbol is no entry point. */
1180 vms_symbol_entry
*entry
;
1182 name
= _bfd_vms_save_counted_string (ptr
);
1183 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1184 if (entry
== (vms_symbol_entry
*) NULL
)
1187 (*_bfd_error_handler
) (_("stack-entry-mask not fully implemented"));
1188 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1193 case TIR_S_C_STA_CKARG
:
1194 /* compare procedure argument
1197 da argument descriptor
1199 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1200 and stack TRUE (args match) or FALSE (args dont match) value. */
1201 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1202 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1205 case TIR_S_C_STA_LSY
:
1206 /* stack local symbol value
1207 arg: sh environment index
1212 vms_symbol_entry
*entry
;
1214 envidx
= bfd_getl16 (ptr
);
1216 name
= _bfd_vms_save_counted_string (ptr
);
1217 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1218 if (entry
== (vms_symbol_entry
*) NULL
)
1220 (*_bfd_error_handler
) (_("stack-local-symbol not fully implemented"));
1221 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1226 case TIR_S_C_STA_LIT
:
1228 arg: by literal index
1232 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1233 (*_bfd_error_handler
) (_("stack-literal not fully implemented"));
1236 case TIR_S_C_STA_LEPM
:
1237 /* stack local symbol entry point mask
1238 arg: sh environment index
1241 stack (unsigned) entry point mask of symbol
1242 err if symbol is no entry point. */
1246 vms_symbol_entry
*entry
;
1248 envidx
= bfd_getl16 (ptr
);
1250 name
= _bfd_vms_save_counted_string (ptr
);
1251 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1252 if (entry
== (vms_symbol_entry
*) NULL
)
1254 (*_bfd_error_handler
) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1255 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1261 (*_bfd_error_handler
) (_("reserved STA cmd %d"), ptr
[-1]);
1275 case TIR_S_C_STO_RSB
: return "TIR_S_C_STO_RSB";
1276 case TIR_S_C_STO_RSW
: return "TIR_S_C_STO_RSW";
1277 case TIR_S_C_STO_RL
: return "TIR_S_C_STO_RL";
1278 case TIR_S_C_STO_VPS
: return "TIR_S_C_STO_VPS";
1279 case TIR_S_C_STO_USB
: return "TIR_S_C_STO_USB";
1280 case TIR_S_C_STO_USW
: return "TIR_S_C_STO_USW";
1281 case TIR_S_C_STO_RUB
: return "TIR_S_C_STO_RUB";
1282 case TIR_S_C_STO_RUW
: return "TIR_S_C_STO_RUW";
1283 case TIR_S_C_STO_PIRR
: return "TIR_S_C_STO_PIRR";
1284 case TIR_S_C_OPR_INSV
: return "TIR_S_C_OPR_INSV";
1285 case TIR_S_C_OPR_DFLIT
: return "TIR_S_C_OPR_DFLIT";
1286 case TIR_S_C_OPR_REDEF
: return "TIR_S_C_OPR_REDEF";
1287 case TIR_S_C_OPR_ROT
: return "TIR_S_C_OPR_ROT";
1288 case TIR_S_C_OPR_USH
: return "TIR_S_C_OPR_USH";
1289 case TIR_S_C_OPR_ASH
: return "TIR_S_C_OPR_ASH";
1290 case TIR_S_C_CTL_DFLOC
: return "TIR_S_C_CTL_DFLOC";
1291 case TIR_S_C_CTL_STLOC
: return "TIR_S_C_CTL_STLOC";
1292 case TIR_S_C_CTL_STKDL
: return "TIR_S_C_CTL_STKDL";
1295 /* These strings have not been added yet. */
1304 handle sto_xxx commands in tir section
1305 ptr points to data area in record
1307 See table 7-4 of the VAX/VMS linker manual. */
1309 static unsigned char *
1310 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1312 unsigned long dummy
;
1317 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1322 case TIR_S_C_STO_SB
:
1323 /* store signed byte: pop stack, write byte
1325 dummy
= _bfd_vms_pop (abfd
, &psect
);
1326 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1329 case TIR_S_C_STO_SW
:
1330 /* store signed word: pop stack, write word
1332 dummy
= _bfd_vms_pop (abfd
, &psect
);
1333 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1336 case TIR_S_C_STO_LW
:
1337 /* store longword: pop stack, write longword
1339 dummy
= _bfd_vms_pop (abfd
, &psect
);
1340 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1343 case TIR_S_C_STO_BD
:
1344 /* store byte displaced: pop stack, sub lc+1, write byte
1346 dummy
= _bfd_vms_pop (abfd
, &psect
);
1347 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1348 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1351 case TIR_S_C_STO_WD
:
1352 /* store word displaced: pop stack, sub lc+2, write word
1354 dummy
= _bfd_vms_pop (abfd
, &psect
);
1355 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1356 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1359 case TIR_S_C_STO_LD
:
1360 /* store long displaced: pop stack, sub lc+4, write long
1362 dummy
= _bfd_vms_pop (abfd
, &psect
);
1363 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1364 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1367 case TIR_S_C_STO_LI
:
1368 /* store short literal: pop stack, write byte
1370 dummy
= _bfd_vms_pop (abfd
, &psect
);
1371 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1374 case TIR_S_C_STO_PIDR
:
1375 /* store position independent data reference: pop stack, write longword
1377 FIXME: incomplete ! */
1378 dummy
= _bfd_vms_pop (abfd
, &psect
);
1379 image_write_l (abfd
, dummy
& 0xffffffff);
1382 case TIR_S_C_STO_PICR
:
1383 /* store position independent code reference: pop stack, write longword
1385 FIXME: incomplete ! */
1386 dummy
= _bfd_vms_pop (abfd
, &psect
);
1387 image_write_b (abfd
, 0x9f);
1388 image_write_l (abfd
, dummy
& 0xffffffff);
1391 case TIR_S_C_STO_RIVB
:
1392 /* store repeated immediate variable bytes
1393 1-byte count n field followed by n bytes of data
1394 pop stack, write n bytes <stack> times. */
1396 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1397 while (dummy
-- > 0L)
1398 image_dump (abfd
, ptr
, size
, 0);
1403 /* store byte from top longword. */
1404 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1405 image_write_b (abfd
, dummy
& 0xff);
1409 /* store word from top longword. */
1410 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1411 image_write_w (abfd
, dummy
& 0xffff);
1414 case TIR_S_C_STO_RB
:
1415 /* store repeated byte from top longword. */
1416 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1417 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1419 image_write_b (abfd
, dummy
& 0xff);
1422 case TIR_S_C_STO_RW
:
1423 /* store repeated word from top longword. */
1424 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1425 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1427 image_write_w (abfd
, dummy
& 0xffff);
1430 case TIR_S_C_STO_RSB
:
1431 case TIR_S_C_STO_RSW
:
1432 case TIR_S_C_STO_RL
:
1433 case TIR_S_C_STO_VPS
:
1434 case TIR_S_C_STO_USB
:
1435 case TIR_S_C_STO_USW
:
1436 case TIR_S_C_STO_RUB
:
1437 case TIR_S_C_STO_RUW
:
1438 case TIR_S_C_STO_PIRR
:
1439 (*_bfd_error_handler
) (_("%s: not implemented"), tir_cmd_name (ptr
[-1]));
1443 (*_bfd_error_handler
) (_("reserved STO cmd %d"), ptr
[-1]);
1450 /* stack operator commands
1451 all 32 bit signed arithmetic
1452 all word just like a stack calculator
1453 arguments are popped from stack, results are pushed on stack
1455 See table 7-5 of the VAX/VMS linker manual. */
1457 static unsigned char *
1465 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1471 case TIR_S_C_OPR_NOP
: /* no-op */
1474 case TIR_S_C_OPR_ADD
: /* add */
1475 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1476 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1477 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1480 case TIR_S_C_OPR_SUB
: /* subtract */
1481 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1482 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1483 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1486 case TIR_S_C_OPR_MUL
: /* multiply */
1487 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1488 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1489 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1492 case TIR_S_C_OPR_DIV
: /* divide */
1493 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1494 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1496 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1498 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1501 case TIR_S_C_OPR_AND
: /* logical and */
1502 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1503 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1504 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1507 case TIR_S_C_OPR_IOR
: /* logical inclusive or */
1508 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1509 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1510 _bfd_vms_push (abfd
, (uquad
) (op1
| op2
), -1);
1513 case TIR_S_C_OPR_EOR
: /* logical exclusive or */
1514 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1515 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1516 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1519 case TIR_S_C_OPR_NEG
: /* negate */
1520 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1521 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1524 case TIR_S_C_OPR_COM
: /* complement */
1525 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1526 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1529 case TIR_S_C_OPR_INSV
: /* insert field */
1530 (void) _bfd_vms_pop (abfd
, NULL
);
1531 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1532 tir_cmd_name (ptr
[-1]));
1535 case TIR_S_C_OPR_ASH
: /* arithmetic shift */
1536 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1537 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1538 if (HIGHBIT (op1
)) /* shift right */
1540 else /* shift left */
1542 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1543 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1544 tir_cmd_name (ptr
[-1]));
1547 case TIR_S_C_OPR_USH
: /* unsigned shift */
1548 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1549 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1550 if (HIGHBIT (op1
)) /* shift right */
1552 else /* shift left */
1554 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1555 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1556 tir_cmd_name (ptr
[-1]));
1559 case TIR_S_C_OPR_ROT
: /* rotate */
1560 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1561 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1562 if (HIGHBIT (0)) /* shift right */
1564 else /* shift left */
1566 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1567 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1568 tir_cmd_name (ptr
[-1]));
1571 case TIR_S_C_OPR_SEL
: /* select */
1572 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1573 (void) _bfd_vms_pop (abfd
, NULL
);
1576 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1577 (void) _bfd_vms_pop (abfd
, NULL
);
1578 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1582 case TIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
1583 case TIR_S_C_OPR_DFLIT
: /* Define a literal. */
1584 (*_bfd_error_handler
) (_("%s: not supported"),
1585 tir_cmd_name (ptr
[-1]));
1589 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), ptr
[-1]);
1598 See table 7-6 of the VAX/VMS linker manual. */
1600 static unsigned char *
1601 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1603 unsigned long dummy
;
1607 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1612 case TIR_S_C_CTL_SETRB
:
1613 /* Set relocation base: pop stack, set image location counter
1615 dummy
= _bfd_vms_pop (abfd
, &psect
);
1616 if (psect
>= PRIV (section_count
))
1617 alloc_section (abfd
, psect
);
1618 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1621 case TIR_S_C_CTL_AUGRB
:
1622 /* Augment relocation base: increment image location counter by offset
1623 arg: lw offset value. */
1624 dummy
= bfd_getl32 (ptr
);
1625 image_inc_ptr (abfd
, (uquad
) dummy
);
1628 case TIR_S_C_CTL_DFLOC
:
1629 /* Define location: pop index, save location counter under index
1631 dummy
= _bfd_vms_pop (abfd
, NULL
);
1632 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1633 tir_cmd_name (ptr
[-1]));
1636 case TIR_S_C_CTL_STLOC
:
1637 /* Set location: pop index, restore location counter from index
1639 dummy
= _bfd_vms_pop (abfd
, &psect
);
1640 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1641 tir_cmd_name (ptr
[-1]));
1644 case TIR_S_C_CTL_STKDL
:
1645 /* Stack defined location: pop index, push location counter from index
1647 dummy
= _bfd_vms_pop (abfd
, &psect
);
1648 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1649 tir_cmd_name (ptr
[-1]));
1653 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), ptr
[-1]);
1659 /* Handle command from TIR section. */
1661 static unsigned char *
1662 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1668 unsigned char * (*explain
) (bfd
*, unsigned char *);
1672 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1673 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1674 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1675 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1681 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1682 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1685 if (*ptr
& 0x80) /* store immediate */
1687 i
= 128 - (*ptr
++ & 0x7f);
1688 image_dump (abfd
, ptr
, i
, 0);
1693 while (tir_table
[i
].mincod
>= 0)
1695 if ( (tir_table
[i
].mincod
<= *ptr
)
1696 && (*ptr
<= tir_table
[i
].maxcod
))
1698 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1703 if (tir_table
[i
].mincod
< 0)
1705 (*_bfd_error_handler
) (_("obj code %d not found"), *ptr
);
1713 /* Handle command from ETIR section. */
1716 etir_cmd (abfd
, cmd
, ptr
)
1725 bfd_boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1729 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1730 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1731 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1732 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1733 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1740 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1741 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1744 while (etir_table
[i
].mincod
>= 0)
1746 if ( (etir_table
[i
].mincod
<= cmd
)
1747 && (cmd
<= etir_table
[i
].maxcod
))
1749 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1757 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1762 /* Text Information and Relocation Records (OBJ$C_TIR)
1763 handle tir record. */
1766 analyze_tir (abfd
, ptr
, length
)
1769 unsigned int length
;
1771 unsigned char *maxptr
;
1774 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1777 maxptr
= ptr
+ length
;
1779 while (ptr
< maxptr
)
1781 ptr
= tir_cmd (abfd
, ptr
);
1789 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1790 handle etir record. */
1793 analyze_etir (abfd
, ptr
, length
)
1796 unsigned int length
;
1799 unsigned char *maxptr
;
1803 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1806 maxptr
= ptr
+ length
;
1808 while (ptr
< maxptr
)
1810 cmd
= bfd_getl16 (ptr
);
1811 length
= bfd_getl16 (ptr
+ 2);
1812 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1819 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1825 /* Process ETIR record
1826 Return 0 on success, -1 on error. */
1829 _bfd_vms_slurp_tir (abfd
, objtype
)
1836 _bfd_vms_debug (2, "TIR/ETIR\n");
1842 PRIV (vms_rec
) += 4; /* skip type, size */
1843 PRIV (rec_size
) -= 4;
1844 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1847 PRIV (vms_rec
) += 1; /* skip type */
1848 PRIV (rec_size
) -= 1;
1849 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1859 /* Process EDBG record
1860 Return 0 on success, -1 on error
1862 Not implemented yet. */
1865 _bfd_vms_slurp_dbg (abfd
, objtype
)
1867 int objtype ATTRIBUTE_UNUSED
;
1870 _bfd_vms_debug (2, "DBG/EDBG\n");
1873 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1877 /* Process ETBT record
1878 Return 0 on success, -1 on error
1880 Not implemented yet. */
1883 _bfd_vms_slurp_tbt (abfd
, objtype
)
1884 bfd
*abfd ATTRIBUTE_UNUSED
;
1885 int objtype ATTRIBUTE_UNUSED
;
1888 _bfd_vms_debug (2, "TBT/ETBT\n");
1894 /* Process LNK record
1895 Return 0 on success, -1 on error
1897 Not implemented yet. */
1900 _bfd_vms_slurp_lnk (abfd
, objtype
)
1901 bfd
*abfd ATTRIBUTE_UNUSED
;
1902 int objtype ATTRIBUTE_UNUSED
;
1905 _bfd_vms_debug (2, "LNK\n");
1911 /* WRITE ETIR SECTION
1913 This is still under construction and therefore not documented. */
1915 static void start_etir_record
1916 PARAMS ((bfd
*abfd
, int index
, uquad offset
, bfd_boolean justoffset
));
1918 PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1919 static void end_etir_record
1920 PARAMS ((bfd
*abfd
));
1923 sto_imm (abfd
, sptr
, vaddr
, index
)
1931 unsigned char *cptr
;
1934 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1935 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
1939 cptr
= sptr
->contents
;
1943 size
= ssize
; /* try all the rest */
1945 if (_bfd_vms_output_check (abfd
, size
) < 0)
1946 { /* doesn't fit, split ! */
1947 end_etir_record (abfd
);
1948 start_etir_record (abfd
, index
, vaddr
, FALSE
);
1949 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
1950 if (size
> ssize
) /* more than what's left ? */
1954 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
1955 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
1956 _bfd_vms_output_dump (abfd
, cptr
, size
);
1957 _bfd_vms_output_flush (abfd
);
1960 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
1961 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
1970 /* Start ETIR record for section #index at virtual addr offset. */
1973 start_etir_record (abfd
, index
, offset
, justoffset
)
1977 bfd_boolean justoffset
;
1981 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
1982 _bfd_vms_output_push (abfd
);
1985 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
1986 _bfd_vms_output_long (abfd
, (unsigned long) index
);
1987 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
1988 _bfd_vms_output_flush (abfd
);
1990 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
1991 _bfd_vms_output_flush (abfd
);
1994 /* End etir record. */
1997 end_etir_record (abfd
)
2000 _bfd_vms_output_pop (abfd
);
2001 _bfd_vms_output_end (abfd
);
2004 /* Write section contents for bfd abfd. */
2007 _bfd_vms_write_tir (abfd
, objtype
)
2009 int objtype ATTRIBUTE_UNUSED
;
2016 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
2019 _bfd_vms_output_alignment (abfd
, 4);
2022 PRIV (vms_linkage_index
) = 1;
2024 /* Dump all other sections. */
2026 section
= abfd
->sections
;
2028 while (section
!= NULL
)
2032 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2033 section
->index
, section
->name
,
2034 (int) (section
->_raw_size
));
2037 if (section
->flags
& SEC_RELOC
)
2041 if ((i
= section
->reloc_count
) <= 0)
2043 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2050 _bfd_vms_debug (4, "%d relocations:\n", i
);
2051 rptr
= section
->orelocation
;
2054 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2055 (*(*rptr
)->sym_ptr_ptr
)->name
,
2056 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2057 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2058 (*rptr
)->address
, (*rptr
)->addend
,
2059 bfd_get_reloc_size ((*rptr
)->howto
),
2060 (*rptr
)->howto
->name
);
2067 if ((section
->flags
& SEC_HAS_CONTENTS
)
2068 && (! bfd_is_com_section (section
)))
2070 bfd_vma vaddr
; /* Virtual addr in section. */
2072 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2075 bfd_set_error (bfd_error_no_contents
);
2079 vaddr
= (bfd_vma
) (sptr
->offset
);
2081 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2084 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2087 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2089 arelent
**rptr
= section
->orelocation
;
2090 int i
= section
->reloc_count
;
2094 bfd_size_type addr
= (*rptr
)->address
;
2095 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2096 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2098 bfd_size_type before
= addr
- sptr
->offset
;
2099 if (sptr
->size
<= before
) /* complete before */
2101 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2102 vaddr
+= sptr
->size
;
2105 else /* partly before */
2107 int after
= sptr
->size
- before
;
2108 sptr
->size
= before
;
2109 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2110 vaddr
+= sptr
->size
;
2111 sptr
->contents
+= before
;
2112 sptr
->offset
+= before
;
2116 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2118 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2119 asection
*sec
= sym
->section
;
2121 switch ((*rptr
)->howto
->type
)
2123 case ALPHA_R_IGNORE
:
2126 case ALPHA_R_REFLONG
:
2128 if (bfd_is_und_section (sym
->section
))
2130 int slen
= strlen ((char *) sym
->name
);
2133 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2135 end_etir_record (abfd
);
2136 start_etir_record (abfd
,
2140 _bfd_vms_output_begin (abfd
,
2141 ETIR_S_C_STO_GBL_LW
,
2143 hash
= (_bfd_vms_length_hash_symbol
2144 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2145 _bfd_vms_output_counted (abfd
, hash
);
2146 _bfd_vms_output_flush (abfd
);
2148 else if (bfd_is_abs_section (sym
->section
))
2150 if (_bfd_vms_output_check (abfd
, 16) < 0)
2152 end_etir_record (abfd
);
2153 start_etir_record (abfd
,
2157 _bfd_vms_output_begin (abfd
,
2160 _bfd_vms_output_quad (abfd
,
2161 (uquad
) sym
->value
);
2162 _bfd_vms_output_flush (abfd
);
2163 _bfd_vms_output_begin (abfd
,
2166 _bfd_vms_output_flush (abfd
);
2170 if (_bfd_vms_output_check (abfd
, 32) < 0)
2172 end_etir_record (abfd
);
2173 start_etir_record (abfd
,
2177 _bfd_vms_output_begin (abfd
,
2180 _bfd_vms_output_long (abfd
,
2181 (unsigned long) (sec
->index
));
2182 _bfd_vms_output_quad (abfd
,
2183 ((uquad
) (*rptr
)->addend
2184 + (uquad
) sym
->value
));
2185 _bfd_vms_output_flush (abfd
);
2186 _bfd_vms_output_begin (abfd
,
2189 _bfd_vms_output_flush (abfd
);
2194 case ALPHA_R_REFQUAD
:
2196 if (bfd_is_und_section (sym
->section
))
2198 int slen
= strlen ((char *) sym
->name
);
2200 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2202 end_etir_record (abfd
);
2203 start_etir_record (abfd
,
2207 _bfd_vms_output_begin (abfd
,
2210 hash
= (_bfd_vms_length_hash_symbol
2211 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2212 _bfd_vms_output_counted (abfd
, hash
);
2213 _bfd_vms_output_flush (abfd
);
2215 else if (bfd_is_abs_section (sym
->section
))
2217 if (_bfd_vms_output_check (abfd
, 16) < 0)
2219 end_etir_record (abfd
);
2220 start_etir_record (abfd
,
2224 _bfd_vms_output_begin (abfd
,
2227 _bfd_vms_output_quad (abfd
,
2228 (uquad
) sym
->value
);
2229 _bfd_vms_output_flush (abfd
);
2230 _bfd_vms_output_begin (abfd
,
2233 _bfd_vms_output_flush (abfd
);
2237 if (_bfd_vms_output_check (abfd
, 32) < 0)
2239 end_etir_record (abfd
);
2240 start_etir_record (abfd
,
2244 _bfd_vms_output_begin (abfd
,
2247 _bfd_vms_output_long (abfd
,
2248 (unsigned long) (sec
->index
));
2249 _bfd_vms_output_quad (abfd
,
2250 ((uquad
) (*rptr
)->addend
2251 + (uquad
) sym
->value
));
2252 _bfd_vms_output_flush (abfd
);
2253 _bfd_vms_output_begin (abfd
,
2256 _bfd_vms_output_flush (abfd
);
2264 char *hash ATTRIBUTE_UNUSED
;
2266 hint_size
= sptr
->size
;
2268 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2269 sptr
->size
= hint_size
;
2271 vms_output_begin (abfd
,
2272 ETIR_S_C_STO_HINT_GBL
, -1);
2273 vms_output_long (abfd
,
2274 (unsigned long) (sec
->index
));
2275 vms_output_quad (abfd
, (uquad
) addr
);
2277 hash
= (_bfd_vms_length_hash_symbol
2278 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2279 vms_output_counted (abfd
, hash
);
2281 vms_output_flush (abfd
);
2285 case ALPHA_R_LINKAGE
:
2289 if (_bfd_vms_output_check (abfd
, 64) < 0)
2291 end_etir_record (abfd
);
2292 start_etir_record (abfd
, section
->index
,
2295 _bfd_vms_output_begin (abfd
,
2296 ETIR_S_C_STC_LP_PSB
,
2298 _bfd_vms_output_long (abfd
,
2299 (unsigned long) PRIV (vms_linkage_index
));
2300 PRIV (vms_linkage_index
) += 2;
2301 hash
= (_bfd_vms_length_hash_symbol
2302 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2303 _bfd_vms_output_counted (abfd
, hash
);
2304 _bfd_vms_output_byte (abfd
, 0);
2305 _bfd_vms_output_flush (abfd
);
2309 case ALPHA_R_CODEADDR
:
2311 int slen
= strlen ((char *) sym
->name
);
2313 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2315 end_etir_record (abfd
);
2316 start_etir_record (abfd
,
2320 _bfd_vms_output_begin (abfd
,
2323 hash
= (_bfd_vms_length_hash_symbol
2324 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2325 _bfd_vms_output_counted (abfd
, hash
);
2326 _bfd_vms_output_flush (abfd
);
2331 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2332 (*rptr
)->howto
->name
);
2338 if (len
== sptr
->size
)
2344 sptr
->contents
+= len
;
2345 sptr
->offset
+= len
;
2351 else /* sptr starts after reloc */
2353 i
--; /* check next reloc */
2357 if (i
==0) /* all reloc checked */
2362 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2363 vaddr
+= sptr
->size
;
2368 } /* if SEC_RELOC */
2369 else /* no relocs, just dump */
2371 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2372 vaddr
+= sptr
->size
;
2377 } /* while (sptr != 0) */
2379 end_etir_record (abfd
);
2381 } /* has_contents */
2383 section
= section
->next
;
2386 _bfd_vms_output_alignment (abfd
, 2);
2390 /* Write traceback data for bfd abfd. */
2393 _bfd_vms_write_tbt (abfd
, objtype
)
2394 bfd
*abfd ATTRIBUTE_UNUSED
;
2395 int objtype ATTRIBUTE_UNUSED
;
2398 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2404 /* Write debug info for bfd abfd. */
2407 _bfd_vms_write_dbg (abfd
, objtype
)
2408 bfd
*abfd ATTRIBUTE_UNUSED
;
2409 int objtype ATTRIBUTE_UNUSED
;
2412 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);