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
PARAMS ((bfd
*abfd
, int psect
, uquad offset
));
45 static void image_inc_ptr
PARAMS ((bfd
*abfd
, uquad offset
));
46 static void image_dump
PARAMS ((bfd
*abfd
, unsigned char *ptr
, int size
, int offset
));
47 static void image_write_b
PARAMS ((bfd
*abfd
, unsigned int value
));
48 static void image_write_w
PARAMS ((bfd
*abfd
, unsigned int value
));
49 static void image_write_l
PARAMS ((bfd
*abfd
, unsigned long value
));
50 static void image_write_q
PARAMS ((bfd
*abfd
, uquad value
));
51 static int check_section
PARAMS ((bfd
*, int));
52 static boolean etir_sta
PARAMS ((bfd
*, int, unsigned char *));
53 static boolean etir_sto
PARAMS ((bfd
*, int, unsigned char *));
54 static boolean etir_opr
PARAMS ((bfd
*, int, unsigned char *));
55 static boolean etir_ctl
PARAMS ((bfd
*, int, unsigned char *));
56 static boolean etir_stc
PARAMS ((bfd
*, int, unsigned char *));
57 static asection
*new_section
PARAMS ((bfd
*, int));
58 static int alloc_section
PARAMS ((bfd
*, unsigned int));
59 static int etir_cmd
PARAMS ((bfd
*, int, unsigned char *));
60 static int analyze_tir
PARAMS ((bfd
*, unsigned char *, unsigned int));
61 static int analyze_etir
PARAMS ((bfd
*, unsigned char *, unsigned int));
62 static unsigned char * tir_opr
PARAMS ((bfd
*, unsigned char *));
63 static const char * tir_cmd_name
PARAMS ((int));
64 static const char * cmd_name
PARAMS ((int));
68 check_section (abfd
, size
)
74 offset
= PRIV (image_ptr
) - PRIV (image_section
)->contents
;
75 if (offset
+ size
> PRIV (image_section
)->_raw_size
)
77 PRIV (image_section
)->contents
78 = bfd_realloc (PRIV (image_section
)->contents
, offset
+ size
);
79 if (PRIV (image_section
)->contents
== 0)
81 (*_bfd_error_handler
) (_("No Mem !"));
84 PRIV (image_section
)->_raw_size
= offset
+ size
;
85 PRIV (image_ptr
) = PRIV (image_section
)->contents
+ offset
;
91 /* Routines to fill sections contents during tir/etir read. */
93 /* Initialize image buffer pointer to be filled. */
96 image_set_ptr (abfd
, psect
, offset
)
102 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
103 psect
, PRIV (sections
)[psect
]->name
, offset
);
106 PRIV (image_ptr
) = PRIV (sections
)[psect
]->contents
+ offset
;
107 PRIV (image_section
) = PRIV (sections
)[psect
];
111 /* Increment image buffer pointer by offset. */
114 image_inc_ptr (abfd
, offset
)
119 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset
);
122 PRIV (image_ptr
) += offset
;
127 /* Dump multiple bytes to section image. */
130 image_dump (abfd
, ptr
, size
, offset
)
134 int offset ATTRIBUTE_UNUSED
;
137 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr
, size
,
139 _bfd_hexdump (9, ptr
, size
, offset
);
142 if (PRIV (is_vax
) && check_section (abfd
, size
))
146 *PRIV (image_ptr
)++ = *ptr
++;
150 /* Write byte to section image. */
153 image_write_b (abfd
, value
)
158 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value
);
161 if (PRIV (is_vax
) && check_section (abfd
, 1))
164 *PRIV (image_ptr
)++ = (value
& 0xff);
168 /* Write 2-byte word to image. */
171 image_write_w (abfd
, value
)
176 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value
);
179 if (PRIV (is_vax
) && check_section (abfd
, 2))
182 bfd_putl16 ((bfd_vma
) value
, PRIV (image_ptr
));
183 PRIV (image_ptr
) += 2;
188 /* Write 4-byte long to image. */
191 image_write_l (abfd
, value
)
196 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value
);
199 if (PRIV (is_vax
) && check_section (abfd
, 4))
202 bfd_putl32 ((bfd_vma
) value
, PRIV (image_ptr
));
203 PRIV (image_ptr
) += 4;
208 /* Write 8-byte quad to image. */
211 image_write_q (abfd
, value
)
216 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value
);
219 if (PRIV (is_vax
) && check_section (abfd
, 8))
222 bfd_putl64 (value
, PRIV (image_ptr
));
223 PRIV (image_ptr
) += 8;
234 case ETIR_S_C_STA_GBL
: return "ETIR_S_C_STA_GBL";
235 case ETIR_S_C_STA_PQ
: return "ETIR_S_C_STA_PQ";
236 case ETIR_S_C_STA_LI
: return "ETIR_S_C_STA_LI";
237 case ETIR_S_C_STA_MOD
: return "ETIR_S_C_STA_MOD";
238 case ETIR_S_C_STA_CKARG
: return "ETIR_S_C_STA_CKARG";
239 case ETIR_S_C_STO_B
: return "ETIR_S_C_STO_B";
240 case ETIR_S_C_STO_W
: return "ETIR_S_C_STO_W";
241 case ETIR_S_C_STO_GBL
: return "ETIR_S_C_STO_GBL";
242 case ETIR_S_C_STO_CA
: return "ETIR_S_C_STO_CA";
243 case ETIR_S_C_STO_RB
: return "ETIR_S_C_STO_RB";
244 case ETIR_S_C_STO_AB
: return "ETIR_S_C_STO_AB";
245 case ETIR_S_C_STO_GBL_LW
: return "ETIR_S_C_STO_GBL_LW";
246 case ETIR_S_C_STO_LP_PSB
: return "ETIR_S_C_STO_LP_PSB";
247 case ETIR_S_C_STO_HINT_GBL
: return "ETIR_S_C_STO_HINT_GBL";
248 case ETIR_S_C_STO_HINT_PS
: return "ETIR_S_C_STO_HINT_PS";
249 case ETIR_S_C_OPR_INSV
: return "ETIR_S_C_OPR_INSV";
250 case ETIR_S_C_OPR_USH
: return "ETIR_S_C_OPR_USH";
251 case ETIR_S_C_OPR_ROT
: return "ETIR_S_C_OPR_ROT";
252 case ETIR_S_C_OPR_REDEF
: return "ETIR_S_C_OPR_REDEF";
253 case ETIR_S_C_OPR_DFLIT
: return "ETIR_S_C_OPR_DFLIT";
254 case ETIR_S_C_STC_LP
: return "ETIR_S_C_STC_LP";
255 case ETIR_S_C_STC_GBL
: return "ETIR_S_C_STC_GBL";
256 case ETIR_S_C_STC_GCA
: return "ETIR_S_C_STC_GCA";
257 case ETIR_S_C_STC_PS
: return "ETIR_S_C_STC_PS";
258 case ETIR_S_C_STC_NBH_PS
: return "ETIR_S_C_STC_NBH_PS";
259 case ETIR_S_C_STC_NOP_GBL
: return "ETIR_S_C_STC_NOP_GBL";
260 case ETIR_S_C_STC_NOP_PS
: return "ETIR_S_C_STC_NOP_PS";
261 case ETIR_S_C_STC_BSR_GBL
: return "ETIR_S_C_STC_BSR_GBL";
262 case ETIR_S_C_STC_BSR_PS
: return "ETIR_S_C_STC_BSR_PS";
263 case ETIR_S_C_STC_LDA_GBL
: return "ETIR_S_C_STC_LDA_GBL";
264 case ETIR_S_C_STC_LDA_PS
: return "ETIR_S_C_STC_LDA_PS";
265 case ETIR_S_C_STC_BOH_GBL
: return "ETIR_S_C_STC_BOH_GBL";
266 case ETIR_S_C_STC_BOH_PS
: return "ETIR_S_C_STC_BOH_PS";
267 case ETIR_S_C_STC_NBH_GBL
: return "ETIR_S_C_STC_NBH_GBL";
270 /* These names have not yet been added to this switch statement. */
274 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
280 handle sta_xxx commands in etir section
281 ptr points to data area in record
283 see table B-8 of the openVMS linker manual. */
286 etir_sta (abfd
, cmd
, ptr
)
293 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd
, cmd
);
294 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
304 stack 32 bit value of symbol (high bits set to 0) */
306 case ETIR_S_C_STA_GBL
:
309 vms_symbol_entry
*entry
;
311 name
= _bfd_vms_save_counted_string (ptr
);
312 entry
= (vms_symbol_entry
*)
313 bfd_hash_lookup (PRIV (vms_symbol_table
), name
, false, false);
314 if (entry
== (vms_symbol_entry
*) NULL
)
317 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
318 cmd_name (cmd
), name
);
320 _bfd_vms_push (abfd
, (uquad
) 0, -1);
324 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
332 stack 32 bit value, sign extend to 64 bit */
334 case ETIR_S_C_STA_LW
:
335 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
341 stack 64 bit value of symbol */
343 case ETIR_S_C_STA_QW
:
344 _bfd_vms_push (abfd
, (uquad
) bfd_getl64 (ptr
), -1);
347 /* stack psect base plus quadword offset
348 arg: lw section index
349 qw signed quadword offset (low 32 bits)
351 stack qw argument and section index
352 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
354 case ETIR_S_C_STA_PQ
:
359 psect
= bfd_getl32 (ptr
);
360 if (psect
>= PRIV (section_count
))
362 (*_bfd_error_handler
) (_("bad section index in %s"),
364 bfd_set_error (bfd_error_bad_value
);
367 dummy
= bfd_getl64 (ptr
+4);
368 _bfd_vms_push (abfd
, dummy
, (int) psect
);
372 case ETIR_S_C_STA_LI
:
373 case ETIR_S_C_STA_MOD
:
374 case ETIR_S_C_STA_CKARG
:
375 (*_bfd_error_handler
) (_("unsupported STA cmd %s"), cmd_name (cmd
));
380 (*_bfd_error_handler
) (_("reserved STA cmd %d"), cmd
);
385 _bfd_vms_debug (5, "etir_sta true\n");
395 handle sto_xxx commands in etir section
396 ptr points to data area in record
398 see table B-9 of the openVMS linker manual. */
401 etir_sto (abfd
, cmd
, ptr
)
410 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd
, cmd
);
411 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
416 /* store byte: pop stack, write byte
420 dummy
= _bfd_vms_pop (abfd
, &psect
);
422 if (is_share
) /* FIXME */
423 (*_bfd_error_handler
) ("%s: byte fixups not supported",
426 /* FIXME: check top bits */
427 image_write_b (abfd
, (unsigned int) dummy
& 0xff);
430 /* store word: pop stack, write word
434 dummy
= _bfd_vms_pop (abfd
, &psect
);
436 if (is_share
) /* FIXME */
437 (*_bfd_error_handler
) ("%s: word fixups not supported",
440 /* FIXME: check top bits */
441 image_write_w (abfd
, (unsigned int) dummy
& 0xffff);
444 /* store longword: pop stack, write longword
447 case ETIR_S_C_STO_LW
:
448 dummy
= _bfd_vms_pop (abfd
, &psect
);
449 dummy
+= (PRIV (sections
)[psect
])->vma
;
450 /* FIXME: check top bits. */
451 image_write_l (abfd
, (unsigned int) dummy
& 0xffffffff);
454 /* store quadword: pop stack, write quadword
457 case ETIR_S_C_STO_QW
:
458 dummy
= _bfd_vms_pop (abfd
, &psect
);
459 dummy
+= (PRIV (sections
)[psect
])->vma
;
460 image_write_q (abfd
, dummy
); /* FIXME: check top bits */
463 /* store immediate repeated: pop stack for repeat count
467 case ETIR_S_C_STO_IMMR
:
471 size
= bfd_getl32 (ptr
);
472 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
474 image_dump (abfd
, ptr
+4, size
, 0);
478 /* store global: write symbol value
479 arg: cs global symbol name. */
481 case ETIR_S_C_STO_GBL
:
483 vms_symbol_entry
*entry
;
486 name
= _bfd_vms_save_counted_string (ptr
);
487 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
489 if (entry
== (vms_symbol_entry
*) NULL
)
491 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
492 cmd_name (cmd
), name
);
497 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
));
501 /* store code address: write address of entry point
502 arg: cs global symbol name (procedure). */
504 case ETIR_S_C_STO_CA
:
506 vms_symbol_entry
*entry
;
509 name
= _bfd_vms_save_counted_string (ptr
);
510 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
512 if (entry
== (vms_symbol_entry
*) NULL
)
514 (*_bfd_error_handler
) (_("%s: no symbol \"%s\""),
515 cmd_name (cmd
), name
);
519 image_write_q (abfd
, (uquad
) (entry
->symbol
->value
)); /* FIXME, reloc */
523 /* Store offset to psect: pop stack, add low 32 bits to base of psect
526 case ETIR_S_C_STO_OFF
:
531 q
= _bfd_vms_pop (abfd
, &psect1
);
532 q
+= (PRIV (sections
)[psect1
])->vma
;
533 image_write_q (abfd
, q
);
538 arg: lw count of bytes
541 case ETIR_S_C_STO_IMM
:
545 size
= bfd_getl32 (ptr
);
546 image_dump (abfd
, ptr
+4, size
, 0);
550 /* This code is 'reserved to digital' according to the openVMS
551 linker manual, however it is generated by the DEC C compiler
552 and defined in the include file.
553 FIXME, since the following is just a guess
554 store global longword: store 32bit value of symbol
555 arg: cs symbol name. */
557 case ETIR_S_C_STO_GBL_LW
:
559 vms_symbol_entry
*entry
;
562 name
= _bfd_vms_save_counted_string (ptr
);
563 entry
= (vms_symbol_entry
*) bfd_hash_lookup (PRIV (vms_symbol_table
),
565 if (entry
== (vms_symbol_entry
*) NULL
)
568 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd
), name
);
570 image_write_l (abfd
, (unsigned long) 0); /* FIXME, reloc */
574 image_write_l (abfd
, (unsigned long) (entry
->symbol
->value
));
578 case ETIR_S_C_STO_RB
:
579 case ETIR_S_C_STO_AB
:
580 case ETIR_S_C_STO_LP_PSB
:
581 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
584 case ETIR_S_C_STO_HINT_GBL
:
585 case ETIR_S_C_STO_HINT_PS
:
586 (*_bfd_error_handler
) (_("%s: not implemented"), cmd_name (cmd
));
590 (*_bfd_error_handler
) (_("reserved STO cmd %d"), cmd
);
597 /* Stack operator commands
598 all 32 bit signed arithmetic
599 all word just like a stack calculator
600 arguments are popped from stack, results are pushed on stack
602 see table B-10 of the openVMS linker manual. */
605 etir_opr (abfd
, cmd
, ptr
)
608 unsigned char *ptr ATTRIBUTE_UNUSED
;
613 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd
, cmd
);
614 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
619 case ETIR_S_C_OPR_NOP
: /* no-op */
622 case ETIR_S_C_OPR_ADD
: /* add */
623 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
624 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
625 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
628 case ETIR_S_C_OPR_SUB
: /* subtract */
629 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
630 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
631 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
634 case ETIR_S_C_OPR_MUL
: /* multiply */
635 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
636 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
637 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
640 case ETIR_S_C_OPR_DIV
: /* divide */
641 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
642 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
644 _bfd_vms_push (abfd
, (uquad
) 0, -1);
646 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
649 case ETIR_S_C_OPR_AND
: /* logical and */
650 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
651 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
652 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
655 case ETIR_S_C_OPR_IOR
: /* logical inclusive or */
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_EOR
: /* logical exclusive or */
662 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
663 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
664 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
667 case ETIR_S_C_OPR_NEG
: /* negate */
668 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
669 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
672 case ETIR_S_C_OPR_COM
: /* complement */
673 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
674 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
677 case ETIR_S_C_OPR_ASH
: /* arithmetic shift */
678 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
679 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
680 if (op2
< 0) /* shift right */
682 else /* shift left */
684 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
687 case ETIR_S_C_OPR_INSV
: /* insert field */
688 (void) _bfd_vms_pop (abfd
, NULL
);
689 case ETIR_S_C_OPR_USH
: /* unsigned shift */
690 case ETIR_S_C_OPR_ROT
: /* rotate */
691 case ETIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
692 case ETIR_S_C_OPR_DFLIT
: /* Define a literal. */
693 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
696 case ETIR_S_C_OPR_SEL
: /* select */
697 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
698 (void) _bfd_vms_pop (abfd
, NULL
);
701 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
702 (void) _bfd_vms_pop (abfd
, NULL
);
703 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
708 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), cmd
);
717 See table B-11 of the openVMS linker manual. */
720 etir_ctl (abfd
, cmd
, ptr
)
729 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd
, cmd
);
730 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
735 /* set relocation base: pop stack, set image location counter
738 case ETIR_S_C_CTL_SETRB
:
739 dummy
= _bfd_vms_pop (abfd
, &psect
);
740 image_set_ptr (abfd
, psect
, dummy
);
743 /* augment relocation base: increment image location counter by offset
744 arg: lw offset value */
746 case ETIR_S_C_CTL_AUGRB
:
747 dummy
= bfd_getl32 (ptr
);
748 image_inc_ptr (abfd
, dummy
);
751 /* define location: pop index, save location counter under index
754 case ETIR_S_C_CTL_DFLOC
:
755 dummy
= _bfd_vms_pop (abfd
, NULL
);
759 /* set location: pop index, restore location counter from index
762 case ETIR_S_C_CTL_STLOC
:
763 dummy
= _bfd_vms_pop (abfd
, &psect
);
767 /* stack defined location: pop index, push location counter from index
770 case ETIR_S_C_CTL_STKDL
:
771 dummy
= _bfd_vms_pop (abfd
, &psect
);
776 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), cmd
);
782 /* store conditional commands
784 See table B-12 and B-13 of the openVMS linker manual. */
787 etir_stc (abfd
, cmd
, ptr
)
790 unsigned char *ptr ATTRIBUTE_UNUSED
;
793 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd
, cmd
);
794 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
799 /* 200 Store-conditional Linkage Pair
802 case ETIR_S_C_STC_LP
:
803 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
806 /* 201 Store-conditional Linkage Pair with Procedure Signature
807 arg: lw linkage index
812 case ETIR_S_C_STC_LP_PSB
:
813 image_inc_ptr (abfd
, (uquad
) 16); /* skip entry,procval */
816 /* 202 Store-conditional Address at global address
817 arg: lw linkage index
820 case ETIR_S_C_STC_GBL
:
821 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
824 /* 203 Store-conditional Code Address at global address
825 arg: lw linkage index
828 case ETIR_S_C_STC_GCA
:
829 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
832 /* 204 Store-conditional Address at psect + offset
833 arg: lw linkage index
837 case ETIR_S_C_STC_PS
:
838 (*_bfd_error_handler
) (_("%s: not supported"), cmd_name (cmd
));
841 /* 205 Store-conditional NOP at address of global
844 case ETIR_S_C_STC_NOP_GBL
:
846 /* 206 Store-conditional NOP at pect + offset
849 case ETIR_S_C_STC_NOP_PS
:
851 /* 207 Store-conditional BSR at global address
854 case ETIR_S_C_STC_BSR_GBL
:
856 /* 208 Store-conditional BSR at pect + offset
859 case ETIR_S_C_STC_BSR_PS
:
861 /* 209 Store-conditional LDA at global address
864 case ETIR_S_C_STC_LDA_GBL
:
866 /* 210 Store-conditional LDA at psect + offset
869 case ETIR_S_C_STC_LDA_PS
:
871 /* 211 Store-conditional BSR or Hint at global address
874 case ETIR_S_C_STC_BOH_GBL
:
876 /* 212 Store-conditional BSR or Hint at pect + offset
879 case ETIR_S_C_STC_BOH_PS
:
881 /* 213 Store-conditional NOP,BSR or HINT at global address
884 case ETIR_S_C_STC_NBH_GBL
:
886 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
889 case ETIR_S_C_STC_NBH_PS
:
892 (*_bfd_error_handler
) ("%s: not supported", cmd_name (cmd
));
898 _bfd_vms_debug (3, "reserved STC cmd %d", cmd
);
906 new_section (abfd
, idx
)
907 bfd
*abfd ATTRIBUTE_UNUSED
;
915 _bfd_vms_debug (5, "new_section %d\n", idx
);
917 sprintf (sname
, SECTION_NAME_TEMPLATE
, idx
);
919 name
= bfd_malloc ((bfd_size_type
) strlen (sname
) + 1);
922 strcpy (name
, sname
);
924 section
= bfd_malloc ((bfd_size_type
) sizeof (asection
));
928 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name
);
933 section
->_raw_size
= 0;
935 section
->contents
= 0;
936 section
->_cooked_size
= 0;
937 section
->name
= name
;
938 section
->index
= idx
;
944 alloc_section (abfd
, idx
)
951 _bfd_vms_debug (4, "alloc_section %d\n", idx
);
955 amt
*= sizeof (asection
*);
956 PRIV (sections
) = (asection
**) bfd_realloc (PRIV (sections
), amt
);
957 if (PRIV (sections
) == 0)
960 while (PRIV (section_count
) <= idx
)
962 PRIV (sections
)[PRIV (section_count
)]
963 = new_section (abfd
, (int) PRIV (section_count
));
964 if (PRIV (sections
)[PRIV (section_count
)] == 0)
966 PRIV (section_count
)++;
976 Handle sta_xxx commands in tir section
977 ptr points to data area in record
979 See table 7-3 of the VAX/VMS linker manual. */
981 static unsigned char *
982 tir_sta (bfd
*abfd
, unsigned char *ptr
)
987 _bfd_vms_debug (5, "tir_sta %d\n", cmd
);
993 case TIR_S_C_STA_GBL
:
997 stack 32 bit value of symbol (high bits set to 0). */
1000 vms_symbol_entry
*entry
;
1002 name
= _bfd_vms_save_counted_string (ptr
);
1004 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1005 if (entry
== (vms_symbol_entry
*) NULL
)
1008 _bfd_vms_push (abfd
, (uquad
) (entry
->symbol
->value
), -1);
1013 case TIR_S_C_STA_SB
:
1014 /* stack signed byte
1017 stack byte value, sign extend to 32 bit. */
1018 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1021 case TIR_S_C_STA_SW
:
1022 /* stack signed short word
1025 stack 16 bit value, sign extend to 32 bit. */
1026 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1030 case TIR_S_C_STA_LW
:
1031 /* stack signed longword
1034 stack 32 bit value. */
1035 _bfd_vms_push (abfd
, (uquad
) bfd_getl32 (ptr
), -1);
1039 case TIR_S_C_STA_PB
:
1040 case TIR_S_C_STA_WPB
:
1041 /* stack psect base plus byte offset (word index)
1042 arg: by section index
1044 by signed byte offset. */
1046 unsigned long dummy
;
1049 if (cmd
== TIR_S_C_STA_PB
)
1053 psect
= bfd_getl16 (ptr
);
1057 if (psect
>= PRIV (section_count
))
1058 alloc_section (abfd
, psect
);
1060 dummy
= (long) *ptr
++;
1061 dummy
+= (PRIV (sections
)[psect
])->vma
;
1062 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1066 case TIR_S_C_STA_PW
:
1067 case TIR_S_C_STA_WPW
:
1068 /* stack psect base plus word offset (word index)
1069 arg: by section index
1071 sh signed short offset. */
1073 unsigned long dummy
;
1076 if (cmd
== TIR_S_C_STA_PW
)
1080 psect
= bfd_getl16 (ptr
);
1084 if (psect
>= PRIV (section_count
))
1085 alloc_section (abfd
, psect
);
1087 dummy
= bfd_getl16 (ptr
); ptr
+=2;
1088 dummy
+= (PRIV (sections
)[psect
])->vma
;
1089 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1093 case TIR_S_C_STA_PL
:
1094 case TIR_S_C_STA_WPL
:
1095 /* stack psect base plus long offset (word index)
1096 arg: by section index
1098 lw signed longword offset. */
1100 unsigned long dummy
;
1103 if (cmd
== TIR_S_C_STA_PL
)
1107 psect
= bfd_getl16 (ptr
);
1111 if (psect
>= PRIV (section_count
))
1112 alloc_section (abfd
, psect
);
1114 dummy
= bfd_getl32 (ptr
); ptr
+= 4;
1115 dummy
+= (PRIV (sections
)[psect
])->vma
;
1116 _bfd_vms_push (abfd
, (uquad
) dummy
, (int) psect
);
1120 case TIR_S_C_STA_UB
:
1121 /* stack unsigned byte
1124 stack byte value. */
1125 _bfd_vms_push (abfd
, (uquad
) *ptr
++, -1);
1128 case TIR_S_C_STA_UW
:
1129 /* stack unsigned short word
1132 stack 16 bit value. */
1133 _bfd_vms_push (abfd
, (uquad
) bfd_getl16 (ptr
), -1);
1137 case TIR_S_C_STA_BFI
:
1138 /* stack byte from image
1141 case TIR_S_C_STA_WFI
:
1142 /* stack byte from image
1145 case TIR_S_C_STA_LFI
:
1146 /* stack byte from image
1148 (*_bfd_error_handler
) (_("stack-from-image not implemented"));
1151 case TIR_S_C_STA_EPM
:
1152 /* stack entry point mask
1155 stack (unsigned) entry point mask of symbol
1156 err if symbol is no entry point. */
1159 vms_symbol_entry
*entry
;
1161 name
= _bfd_vms_save_counted_string (ptr
);
1162 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1163 if (entry
== (vms_symbol_entry
*) NULL
)
1166 (*_bfd_error_handler
) (_("stack-entry-mask not fully implemented"));
1167 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1172 case TIR_S_C_STA_CKARG
:
1173 /* compare procedure argument
1176 da argument descriptor
1178 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1179 and stack TRUE (args match) or FALSE (args dont match) value. */
1180 (*_bfd_error_handler
) (_("PASSMECH not fully implemented"));
1181 _bfd_vms_push (abfd
, (uquad
) 1, -1);
1184 case TIR_S_C_STA_LSY
:
1185 /* stack local symbol value
1186 arg: sh environment index
1191 vms_symbol_entry
*entry
;
1193 envidx
= bfd_getl16 (ptr
);
1195 name
= _bfd_vms_save_counted_string (ptr
);
1196 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1197 if (entry
== (vms_symbol_entry
*) NULL
)
1199 (*_bfd_error_handler
) (_("stack-local-symbol not fully implemented"));
1200 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1205 case TIR_S_C_STA_LIT
:
1207 arg: by literal index
1211 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1212 (*_bfd_error_handler
) (_("stack-literal not fully implemented"));
1215 case TIR_S_C_STA_LEPM
:
1216 /* stack local symbol entry point mask
1217 arg: sh environment index
1220 stack (unsigned) entry point mask of symbol
1221 err if symbol is no entry point. */
1225 vms_symbol_entry
*entry
;
1227 envidx
= bfd_getl16 (ptr
);
1229 name
= _bfd_vms_save_counted_string (ptr
);
1230 entry
= _bfd_vms_enter_symbol (abfd
, name
);
1231 if (entry
== (vms_symbol_entry
*) NULL
)
1233 (*_bfd_error_handler
) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1234 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1240 (*_bfd_error_handler
) (_("reserved STA cmd %d"), ptr
[-1]);
1254 case TIR_S_C_STO_RSB
: return "TIR_S_C_STO_RSB";
1255 case TIR_S_C_STO_RSW
: return "TIR_S_C_STO_RSW";
1256 case TIR_S_C_STO_RL
: return "TIR_S_C_STO_RL";
1257 case TIR_S_C_STO_VPS
: return "TIR_S_C_STO_VPS";
1258 case TIR_S_C_STO_USB
: return "TIR_S_C_STO_USB";
1259 case TIR_S_C_STO_USW
: return "TIR_S_C_STO_USW";
1260 case TIR_S_C_STO_RUB
: return "TIR_S_C_STO_RUB";
1261 case TIR_S_C_STO_RUW
: return "TIR_S_C_STO_RUW";
1262 case TIR_S_C_STO_PIRR
: return "TIR_S_C_STO_PIRR";
1263 case TIR_S_C_OPR_INSV
: return "TIR_S_C_OPR_INSV";
1264 case TIR_S_C_OPR_DFLIT
: return "TIR_S_C_OPR_DFLIT";
1265 case TIR_S_C_OPR_REDEF
: return "TIR_S_C_OPR_REDEF";
1266 case TIR_S_C_OPR_ROT
: return "TIR_S_C_OPR_ROT";
1267 case TIR_S_C_OPR_USH
: return "TIR_S_C_OPR_USH";
1268 case TIR_S_C_OPR_ASH
: return "TIR_S_C_OPR_ASH";
1269 case TIR_S_C_CTL_DFLOC
: return "TIR_S_C_CTL_DFLOC";
1270 case TIR_S_C_CTL_STLOC
: return "TIR_S_C_CTL_STLOC";
1271 case TIR_S_C_CTL_STKDL
: return "TIR_S_C_CTL_STKDL";
1274 /* These strings have not been added yet. */
1283 handle sto_xxx commands in tir section
1284 ptr points to data area in record
1286 See table 7-4 of the VAX/VMS linker manual. */
1288 static unsigned char *
1289 tir_sto (bfd
*abfd
, unsigned char *ptr
)
1291 unsigned long dummy
;
1296 _bfd_vms_debug (5, "tir_sto %d\n", *ptr
);
1301 case TIR_S_C_STO_SB
:
1302 /* store signed byte: pop stack, write byte
1304 dummy
= _bfd_vms_pop (abfd
, &psect
);
1305 image_write_b (abfd
, dummy
& 0xff); /* FIXME: check top bits */
1308 case TIR_S_C_STO_SW
:
1309 /* store signed word: pop stack, write word
1311 dummy
= _bfd_vms_pop (abfd
, &psect
);
1312 image_write_w (abfd
, dummy
& 0xffff); /* FIXME: check top bits */
1315 case TIR_S_C_STO_LW
:
1316 /* store longword: pop stack, write longword
1318 dummy
= _bfd_vms_pop (abfd
, &psect
);
1319 image_write_l (abfd
, dummy
& 0xffffffff); /* FIXME: check top bits */
1322 case TIR_S_C_STO_BD
:
1323 /* store byte displaced: pop stack, sub lc+1, write byte
1325 dummy
= _bfd_vms_pop (abfd
, &psect
);
1326 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 1);
1327 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1330 case TIR_S_C_STO_WD
:
1331 /* store word displaced: pop stack, sub lc+2, write word
1333 dummy
= _bfd_vms_pop (abfd
, &psect
);
1334 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 2);
1335 image_write_w (abfd
, dummy
& 0xffff);/* FIXME: check top bits */
1338 case TIR_S_C_STO_LD
:
1339 /* store long displaced: pop stack, sub lc+4, write long
1341 dummy
= _bfd_vms_pop (abfd
, &psect
);
1342 dummy
-= ((PRIV (sections
)[psect
])->vma
+ 4);
1343 image_write_l (abfd
, dummy
& 0xffffffff);/* FIXME: check top bits */
1346 case TIR_S_C_STO_LI
:
1347 /* store short literal: pop stack, write byte
1349 dummy
= _bfd_vms_pop (abfd
, &psect
);
1350 image_write_b (abfd
, dummy
& 0xff);/* FIXME: check top bits */
1353 case TIR_S_C_STO_PIDR
:
1354 /* store position independent data reference: pop stack, write longword
1356 FIXME: incomplete ! */
1357 dummy
= _bfd_vms_pop (abfd
, &psect
);
1358 image_write_l (abfd
, dummy
& 0xffffffff);
1361 case TIR_S_C_STO_PICR
:
1362 /* store position independent code reference: pop stack, write longword
1364 FIXME: incomplete ! */
1365 dummy
= _bfd_vms_pop (abfd
, &psect
);
1366 image_write_b (abfd
, 0x9f);
1367 image_write_l (abfd
, dummy
& 0xffffffff);
1370 case TIR_S_C_STO_RIVB
:
1371 /* store repeated immediate variable bytes
1372 1-byte count n field followed by n bytes of data
1373 pop stack, write n bytes <stack> times. */
1375 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1376 while (dummy
-- > 0L)
1377 image_dump (abfd
, ptr
, size
, 0);
1382 /* store byte from top longword. */
1383 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1384 image_write_b (abfd
, dummy
& 0xff);
1388 /* store word from top longword. */
1389 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1390 image_write_w (abfd
, dummy
& 0xffff);
1393 case TIR_S_C_STO_RB
:
1394 /* store repeated byte from top longword. */
1395 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1396 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1398 image_write_b (abfd
, dummy
& 0xff);
1401 case TIR_S_C_STO_RW
:
1402 /* store repeated word from top longword. */
1403 size
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1404 dummy
= (unsigned long) _bfd_vms_pop (abfd
, NULL
);
1406 image_write_w (abfd
, dummy
& 0xffff);
1409 case TIR_S_C_STO_RSB
:
1410 case TIR_S_C_STO_RSW
:
1411 case TIR_S_C_STO_RL
:
1412 case TIR_S_C_STO_VPS
:
1413 case TIR_S_C_STO_USB
:
1414 case TIR_S_C_STO_USW
:
1415 case TIR_S_C_STO_RUB
:
1416 case TIR_S_C_STO_RUW
:
1417 case TIR_S_C_STO_PIRR
:
1418 (*_bfd_error_handler
) (_("%s: not implemented"), tir_cmd_name (ptr
[-1]));
1422 (*_bfd_error_handler
) (_("reserved STO cmd %d"), ptr
[-1]);
1429 /* stack operator commands
1430 all 32 bit signed arithmetic
1431 all word just like a stack calculator
1432 arguments are popped from stack, results are pushed on stack
1434 See table 7-5 of the VAX/VMS linker manual. */
1436 static unsigned char *
1444 _bfd_vms_debug (5, "tir_opr %d\n", *ptr
);
1450 case TIR_S_C_OPR_NOP
: /* no-op */
1453 case TIR_S_C_OPR_ADD
: /* add */
1454 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1455 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1456 _bfd_vms_push (abfd
, (uquad
) (op1
+ op2
), -1);
1459 case TIR_S_C_OPR_SUB
: /* subtract */
1460 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1461 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1462 _bfd_vms_push (abfd
, (uquad
) (op2
- op1
), -1);
1465 case TIR_S_C_OPR_MUL
: /* multiply */
1466 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1467 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1468 _bfd_vms_push (abfd
, (uquad
) (op1
* op2
), -1);
1471 case TIR_S_C_OPR_DIV
: /* divide */
1472 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1473 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1475 _bfd_vms_push (abfd
, (uquad
) 0, -1);
1477 _bfd_vms_push (abfd
, (uquad
) (op2
/ op1
), -1);
1480 case TIR_S_C_OPR_AND
: /* logical and */
1481 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1482 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1483 _bfd_vms_push (abfd
, (uquad
) (op1
& op2
), -1);
1486 case TIR_S_C_OPR_IOR
: /* logical inclusive or */
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_EOR
: /* logical exclusive or */
1493 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1494 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1495 _bfd_vms_push (abfd
, (uquad
) (op1
^ op2
), -1);
1498 case TIR_S_C_OPR_NEG
: /* negate */
1499 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1500 _bfd_vms_push (abfd
, (uquad
) (-op1
), -1);
1503 case TIR_S_C_OPR_COM
: /* complement */
1504 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1505 _bfd_vms_push (abfd
, (uquad
) (op1
^ -1L), -1);
1508 case TIR_S_C_OPR_INSV
: /* insert field */
1509 (void) _bfd_vms_pop (abfd
, NULL
);
1510 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1511 tir_cmd_name (ptr
[-1]));
1514 case TIR_S_C_OPR_ASH
: /* arithmetic shift */
1515 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1516 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1517 if (HIGHBIT (op1
)) /* shift right */
1519 else /* shift left */
1521 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1522 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1523 tir_cmd_name (ptr
[-1]));
1526 case TIR_S_C_OPR_USH
: /* unsigned shift */
1527 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1528 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1529 if (HIGHBIT (op1
)) /* shift right */
1531 else /* shift left */
1533 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1534 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1535 tir_cmd_name (ptr
[-1]));
1538 case TIR_S_C_OPR_ROT
: /* rotate */
1539 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1540 op2
= (long) _bfd_vms_pop (abfd
, NULL
);
1541 if (HIGHBIT (0)) /* shift right */
1543 else /* shift left */
1545 _bfd_vms_push (abfd
, (uquad
) op2
, -1);
1546 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1547 tir_cmd_name (ptr
[-1]));
1550 case TIR_S_C_OPR_SEL
: /* select */
1551 if ((long) _bfd_vms_pop (abfd
, NULL
) & 0x01L
)
1552 (void) _bfd_vms_pop (abfd
, NULL
);
1555 op1
= (long) _bfd_vms_pop (abfd
, NULL
);
1556 (void) _bfd_vms_pop (abfd
, NULL
);
1557 _bfd_vms_push (abfd
, (uquad
) op1
, -1);
1561 case TIR_S_C_OPR_REDEF
: /* Redefine symbol to current location. */
1562 case TIR_S_C_OPR_DFLIT
: /* Define a literal. */
1563 (*_bfd_error_handler
) (_("%s: not supported"),
1564 tir_cmd_name (ptr
[-1]));
1568 (*_bfd_error_handler
) (_("reserved OPR cmd %d"), ptr
[-1]);
1577 See table 7-6 of the VAX/VMS linker manual. */
1579 static unsigned char *
1580 tir_ctl (bfd
*abfd
, unsigned char *ptr
)
1582 unsigned long dummy
;
1586 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr
);
1591 case TIR_S_C_CTL_SETRB
:
1592 /* Set relocation base: pop stack, set image location counter
1594 dummy
= _bfd_vms_pop (abfd
, &psect
);
1595 if (psect
>= PRIV (section_count
))
1596 alloc_section (abfd
, psect
);
1597 image_set_ptr (abfd
, (int) psect
, (uquad
) dummy
);
1600 case TIR_S_C_CTL_AUGRB
:
1601 /* Augment relocation base: increment image location counter by offset
1602 arg: lw offset value. */
1603 dummy
= bfd_getl32 (ptr
);
1604 image_inc_ptr (abfd
, (uquad
) dummy
);
1607 case TIR_S_C_CTL_DFLOC
:
1608 /* Define location: pop index, save location counter under index
1610 dummy
= _bfd_vms_pop (abfd
, NULL
);
1611 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1612 tir_cmd_name (ptr
[-1]));
1615 case TIR_S_C_CTL_STLOC
:
1616 /* Set location: pop index, restore location counter from index
1618 dummy
= _bfd_vms_pop (abfd
, &psect
);
1619 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1620 tir_cmd_name (ptr
[-1]));
1623 case TIR_S_C_CTL_STKDL
:
1624 /* Stack defined location: pop index, push location counter from index
1626 dummy
= _bfd_vms_pop (abfd
, &psect
);
1627 (*_bfd_error_handler
) (_("%s: not fully implemented"),
1628 tir_cmd_name (ptr
[-1]));
1632 (*_bfd_error_handler
) (_("reserved CTL cmd %d"), ptr
[-1]);
1638 /* Handle command from TIR section. */
1640 static unsigned char *
1641 tir_cmd (bfd
*abfd
, unsigned char *ptr
)
1647 unsigned char * (*explain
) (bfd
*, unsigned char *);
1651 { 0, TIR_S_C_MAXSTACOD
, tir_sta
},
1652 { TIR_S_C_MINSTOCOD
, TIR_S_C_MAXSTOCOD
, tir_sto
},
1653 { TIR_S_C_MINOPRCOD
, TIR_S_C_MAXOPRCOD
, tir_opr
},
1654 { TIR_S_C_MINCTLCOD
, TIR_S_C_MAXCTLCOD
, tir_ctl
},
1660 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr
, *ptr
);
1661 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1664 if (*ptr
& 0x80) /* store immediate */
1666 i
= 128 - (*ptr
++ & 0x7f);
1667 image_dump (abfd
, ptr
, i
, 0);
1672 while (tir_table
[i
].mincod
>= 0)
1674 if ( (tir_table
[i
].mincod
<= *ptr
)
1675 && (*ptr
<= tir_table
[i
].maxcod
))
1677 ptr
= tir_table
[i
].explain (abfd
, ptr
);
1682 if (tir_table
[i
].mincod
< 0)
1684 (*_bfd_error_handler
) (_("obj code %d not found"), *ptr
);
1692 /* Handle command from ETIR section. */
1695 etir_cmd (abfd
, cmd
, ptr
)
1704 boolean (*explain
) PARAMS ((bfd
*, int, unsigned char *));
1708 { ETIR_S_C_MINSTACOD
, ETIR_S_C_MAXSTACOD
, etir_sta
},
1709 { ETIR_S_C_MINSTOCOD
, ETIR_S_C_MAXSTOCOD
, etir_sto
},
1710 { ETIR_S_C_MINOPRCOD
, ETIR_S_C_MAXOPRCOD
, etir_opr
},
1711 { ETIR_S_C_MINCTLCOD
, ETIR_S_C_MAXCTLCOD
, etir_ctl
},
1712 { ETIR_S_C_MINSTCCOD
, ETIR_S_C_MAXSTCCOD
, etir_stc
},
1719 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd
, cmd
);
1720 _bfd_hexdump (8, ptr
, 16, (int) ptr
);
1723 while (etir_table
[i
].mincod
>= 0)
1725 if ( (etir_table
[i
].mincod
<= cmd
)
1726 && (cmd
<= etir_table
[i
].maxcod
))
1728 if (!etir_table
[i
].explain (abfd
, cmd
, ptr
))
1736 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1741 /* Text Information and Relocation Records (OBJ$C_TIR)
1742 handle tir record. */
1745 analyze_tir (abfd
, ptr
, length
)
1748 unsigned int length
;
1750 unsigned char *maxptr
;
1753 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length
);
1756 maxptr
= ptr
+ length
;
1758 while (ptr
< maxptr
)
1760 ptr
= tir_cmd (abfd
, ptr
);
1768 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1769 handle etir record. */
1772 analyze_etir (abfd
, ptr
, length
)
1775 unsigned int length
;
1778 unsigned char *maxptr
;
1782 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length
);
1785 maxptr
= ptr
+ length
;
1787 while (ptr
< maxptr
)
1789 cmd
= bfd_getl16 (ptr
);
1790 length
= bfd_getl16 (ptr
+ 2);
1791 result
= etir_cmd (abfd
, cmd
, ptr
+4);
1798 _bfd_vms_debug (3, "analyze_etir: = %d\n", result
);
1804 /* Process ETIR record
1805 Return 0 on success, -1 on error. */
1808 _bfd_vms_slurp_tir (abfd
, objtype
)
1815 _bfd_vms_debug (2, "TIR/ETIR\n");
1821 PRIV (vms_rec
) += 4; /* skip type, size */
1822 PRIV (rec_size
) -= 4;
1823 result
= analyze_etir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1826 PRIV (vms_rec
) += 1; /* skip type */
1827 PRIV (rec_size
) -= 1;
1828 result
= analyze_tir (abfd
, PRIV (vms_rec
), (unsigned) PRIV (rec_size
));
1838 /* Process EDBG record
1839 Return 0 on success, -1 on error
1841 Not implemented yet. */
1844 _bfd_vms_slurp_dbg (abfd
, objtype
)
1846 int objtype ATTRIBUTE_UNUSED
;
1849 _bfd_vms_debug (2, "DBG/EDBG\n");
1852 abfd
->flags
|= (HAS_DEBUG
| HAS_LINENO
);
1856 /* Process ETBT record
1857 Return 0 on success, -1 on error
1859 Not implemented yet. */
1862 _bfd_vms_slurp_tbt (abfd
, objtype
)
1863 bfd
*abfd ATTRIBUTE_UNUSED
;
1864 int objtype ATTRIBUTE_UNUSED
;
1867 _bfd_vms_debug (2, "TBT/ETBT\n");
1873 /* Process LNK record
1874 Return 0 on success, -1 on error
1876 Not implemented yet. */
1879 _bfd_vms_slurp_lnk (abfd
, objtype
)
1880 bfd
*abfd ATTRIBUTE_UNUSED
;
1881 int objtype ATTRIBUTE_UNUSED
;
1884 _bfd_vms_debug (2, "LNK\n");
1890 /* WRITE ETIR SECTION
1892 This is still under construction and therefore not documented. */
1894 static void start_etir_record
PARAMS ((bfd
*abfd
, int index
, uquad offset
, boolean justoffset
));
1895 static void sto_imm
PARAMS ((bfd
*abfd
, vms_section
*sptr
, bfd_vma vaddr
, int index
));
1896 static void end_etir_record
PARAMS ((bfd
*abfd
));
1899 sto_imm (abfd
, sptr
, vaddr
, index
)
1907 unsigned char *cptr
;
1910 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr
->size
);
1911 _bfd_hexdump (9, sptr
->contents
, (int) sptr
->size
, (int) vaddr
);
1915 cptr
= sptr
->contents
;
1919 size
= ssize
; /* try all the rest */
1921 if (_bfd_vms_output_check (abfd
, size
) < 0)
1922 { /* doesn't fit, split ! */
1923 end_etir_record (abfd
);
1924 start_etir_record (abfd
, index
, vaddr
, false);
1925 size
= _bfd_vms_output_check (abfd
, 0); /* get max size */
1926 if (size
> ssize
) /* more than what's left ? */
1930 _bfd_vms_output_begin (abfd
, ETIR_S_C_STO_IMM
, -1);
1931 _bfd_vms_output_long (abfd
, (unsigned long) (size
));
1932 _bfd_vms_output_dump (abfd
, cptr
, size
);
1933 _bfd_vms_output_flush (abfd
);
1936 _bfd_vms_debug (10, "dumped %d bytes\n", size
);
1937 _bfd_hexdump (10, cptr
, (int) size
, (int) vaddr
);
1946 /* Start ETIR record for section #index at virtual addr offset. */
1949 start_etir_record (abfd
, index
, offset
, justoffset
)
1957 _bfd_vms_output_begin (abfd
, EOBJ_S_C_ETIR
, -1); /* one ETIR per section */
1958 _bfd_vms_output_push (abfd
);
1961 _bfd_vms_output_begin (abfd
, ETIR_S_C_STA_PQ
, -1); /* push start offset */
1962 _bfd_vms_output_long (abfd
, (unsigned long) index
);
1963 _bfd_vms_output_quad (abfd
, (uquad
) offset
);
1964 _bfd_vms_output_flush (abfd
);
1966 _bfd_vms_output_begin (abfd
, ETIR_S_C_CTL_SETRB
, -1); /* start = pop () */
1967 _bfd_vms_output_flush (abfd
);
1970 /* End etir record. */
1973 end_etir_record (abfd
)
1976 _bfd_vms_output_pop (abfd
);
1977 _bfd_vms_output_end (abfd
);
1980 /* Write section contents for bfd abfd. */
1983 _bfd_vms_write_tir (abfd
, objtype
)
1985 int objtype ATTRIBUTE_UNUSED
;
1992 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd
, objtype
);
1995 _bfd_vms_output_alignment (abfd
, 4);
1998 PRIV (vms_linkage_index
) = 1;
2000 /* Dump all other sections. */
2002 section
= abfd
->sections
;
2004 while (section
!= NULL
)
2008 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2009 section
->index
, section
->name
,
2010 (int) (section
->_raw_size
));
2013 if (section
->flags
& SEC_RELOC
)
2017 if ((i
= section
->reloc_count
) <= 0)
2019 (*_bfd_error_handler
) (_("SEC_RELOC with no relocs in section %s"),
2026 _bfd_vms_debug (4, "%d relocations:\n", i
);
2027 rptr
= section
->orelocation
;
2030 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2031 (*(*rptr
)->sym_ptr_ptr
)->name
,
2032 (*(*rptr
)->sym_ptr_ptr
)->section
->name
,
2033 (long) (*(*rptr
)->sym_ptr_ptr
)->value
,
2034 (*rptr
)->address
, (*rptr
)->addend
,
2035 bfd_get_reloc_size ((*rptr
)->howto
),
2036 (*rptr
)->howto
->name
);
2043 if ((section
->flags
& SEC_HAS_CONTENTS
)
2044 && (! bfd_is_com_section (section
)))
2046 bfd_vma vaddr
; /* Virtual addr in section. */
2048 sptr
= _bfd_get_vms_section (abfd
, section
->index
);
2051 bfd_set_error (bfd_error_no_contents
);
2055 vaddr
= (bfd_vma
) (sptr
->offset
);
2057 start_etir_record (abfd
, section
->index
, (uquad
) sptr
->offset
,
2060 while (sptr
!= NULL
) /* one STA_PQ, CTL_SETRB per vms_section */
2063 if (section
->flags
& SEC_RELOC
) /* check for relocs */
2065 arelent
**rptr
= section
->orelocation
;
2066 int i
= section
->reloc_count
;
2070 bfd_size_type addr
= (*rptr
)->address
;
2071 bfd_size_type len
= bfd_get_reloc_size ((*rptr
)->howto
);
2072 if (sptr
->offset
< addr
) /* sptr starts before reloc */
2074 bfd_size_type before
= addr
- sptr
->offset
;
2075 if (sptr
->size
<= before
) /* complete before */
2077 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2078 vaddr
+= sptr
->size
;
2081 else /* partly before */
2083 int after
= sptr
->size
- before
;
2084 sptr
->size
= before
;
2085 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2086 vaddr
+= sptr
->size
;
2087 sptr
->contents
+= before
;
2088 sptr
->offset
+= before
;
2092 else if (sptr
->offset
== addr
) /* sptr starts at reloc */
2094 asymbol
*sym
= *(*rptr
)->sym_ptr_ptr
;
2095 asection
*sec
= sym
->section
;
2097 switch ((*rptr
)->howto
->type
)
2099 case ALPHA_R_IGNORE
:
2102 case ALPHA_R_REFLONG
:
2104 if (bfd_is_und_section (sym
->section
))
2106 int slen
= strlen ((char *) sym
->name
);
2109 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2111 end_etir_record (abfd
);
2112 start_etir_record (abfd
,
2116 _bfd_vms_output_begin (abfd
,
2117 ETIR_S_C_STO_GBL_LW
,
2119 hash
= (_bfd_vms_length_hash_symbol
2120 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2121 _bfd_vms_output_counted (abfd
, hash
);
2122 _bfd_vms_output_flush (abfd
);
2124 else if (bfd_is_abs_section (sym
->section
))
2126 if (_bfd_vms_output_check (abfd
, 16) < 0)
2128 end_etir_record (abfd
);
2129 start_etir_record (abfd
,
2133 _bfd_vms_output_begin (abfd
,
2136 _bfd_vms_output_quad (abfd
,
2137 (uquad
) sym
->value
);
2138 _bfd_vms_output_flush (abfd
);
2139 _bfd_vms_output_begin (abfd
,
2142 _bfd_vms_output_flush (abfd
);
2146 if (_bfd_vms_output_check (abfd
, 32) < 0)
2148 end_etir_record (abfd
);
2149 start_etir_record (abfd
,
2153 _bfd_vms_output_begin (abfd
,
2156 _bfd_vms_output_long (abfd
,
2157 (unsigned long) (sec
->index
));
2158 _bfd_vms_output_quad (abfd
,
2159 ((uquad
) (*rptr
)->addend
2160 + (uquad
) sym
->value
));
2161 _bfd_vms_output_flush (abfd
);
2162 _bfd_vms_output_begin (abfd
,
2165 _bfd_vms_output_flush (abfd
);
2170 case ALPHA_R_REFQUAD
:
2172 if (bfd_is_und_section (sym
->section
))
2174 int slen
= strlen ((char *) sym
->name
);
2176 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2178 end_etir_record (abfd
);
2179 start_etir_record (abfd
,
2183 _bfd_vms_output_begin (abfd
,
2186 hash
= (_bfd_vms_length_hash_symbol
2187 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2188 _bfd_vms_output_counted (abfd
, hash
);
2189 _bfd_vms_output_flush (abfd
);
2191 else if (bfd_is_abs_section (sym
->section
))
2193 if (_bfd_vms_output_check (abfd
, 16) < 0)
2195 end_etir_record (abfd
);
2196 start_etir_record (abfd
,
2200 _bfd_vms_output_begin (abfd
,
2203 _bfd_vms_output_quad (abfd
,
2204 (uquad
) sym
->value
);
2205 _bfd_vms_output_flush (abfd
);
2206 _bfd_vms_output_begin (abfd
,
2209 _bfd_vms_output_flush (abfd
);
2213 if (_bfd_vms_output_check (abfd
, 32) < 0)
2215 end_etir_record (abfd
);
2216 start_etir_record (abfd
,
2220 _bfd_vms_output_begin (abfd
,
2223 _bfd_vms_output_long (abfd
,
2224 (unsigned long) (sec
->index
));
2225 _bfd_vms_output_quad (abfd
,
2226 ((uquad
) (*rptr
)->addend
2227 + (uquad
) sym
->value
));
2228 _bfd_vms_output_flush (abfd
);
2229 _bfd_vms_output_begin (abfd
,
2232 _bfd_vms_output_flush (abfd
);
2240 char *hash ATTRIBUTE_UNUSED
;
2242 hint_size
= sptr
->size
;
2244 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2245 sptr
->size
= hint_size
;
2247 vms_output_begin (abfd
,
2248 ETIR_S_C_STO_HINT_GBL
, -1);
2249 vms_output_long (abfd
,
2250 (unsigned long) (sec
->index
));
2251 vms_output_quad (abfd
, (uquad
) addr
);
2253 hash
= (_bfd_vms_length_hash_symbol
2254 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2255 vms_output_counted (abfd
, hash
);
2257 vms_output_flush (abfd
);
2261 case ALPHA_R_LINKAGE
:
2265 if (_bfd_vms_output_check (abfd
, 64) < 0)
2267 end_etir_record (abfd
);
2268 start_etir_record (abfd
, section
->index
,
2271 _bfd_vms_output_begin (abfd
,
2272 ETIR_S_C_STC_LP_PSB
,
2274 _bfd_vms_output_long (abfd
,
2275 (unsigned long) PRIV (vms_linkage_index
));
2276 PRIV (vms_linkage_index
) += 2;
2277 hash
= (_bfd_vms_length_hash_symbol
2278 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2279 _bfd_vms_output_counted (abfd
, hash
);
2280 _bfd_vms_output_byte (abfd
, 0);
2281 _bfd_vms_output_flush (abfd
);
2285 case ALPHA_R_CODEADDR
:
2287 int slen
= strlen ((char *) sym
->name
);
2289 if (_bfd_vms_output_check (abfd
, slen
) < 0)
2291 end_etir_record (abfd
);
2292 start_etir_record (abfd
,
2296 _bfd_vms_output_begin (abfd
,
2299 hash
= (_bfd_vms_length_hash_symbol
2300 (abfd
, sym
->name
, EOBJ_S_C_SYMSIZ
));
2301 _bfd_vms_output_counted (abfd
, hash
);
2302 _bfd_vms_output_flush (abfd
);
2307 (*_bfd_error_handler
) (_("Unhandled relocation %s"),
2308 (*rptr
)->howto
->name
);
2314 if (len
== sptr
->size
)
2320 sptr
->contents
+= len
;
2321 sptr
->offset
+= len
;
2327 else /* sptr starts after reloc */
2329 i
--; /* check next reloc */
2333 if (i
==0) /* all reloc checked */
2338 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2339 vaddr
+= sptr
->size
;
2344 } /* if SEC_RELOC */
2345 else /* no relocs, just dump */
2347 sto_imm (abfd
, sptr
, vaddr
, section
->index
);
2348 vaddr
+= sptr
->size
;
2353 } /* while (sptr != 0) */
2355 end_etir_record (abfd
);
2357 } /* has_contents */
2359 section
= section
->next
;
2362 _bfd_vms_output_alignment (abfd
, 2);
2366 /* Write traceback data for bfd abfd. */
2369 _bfd_vms_write_tbt (abfd
, objtype
)
2370 bfd
*abfd ATTRIBUTE_UNUSED
;
2371 int objtype ATTRIBUTE_UNUSED
;
2374 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd
, objtype
);
2380 /* Write debug info for bfd abfd. */
2383 _bfd_vms_write_dbg (abfd
, objtype
)
2384 bfd
*abfd ATTRIBUTE_UNUSED
;
2385 int objtype ATTRIBUTE_UNUSED
;
2388 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd
, objtype
);