1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005
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 :-)
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 check_section (bfd * abfd, int size)
48 offset = PRIV (image_ptr) - PRIV (image_section)->contents;
49 if (offset + size > PRIV (image_section)->size)
51 PRIV (image_section)->contents
52 = bfd_realloc (PRIV (image_section)->contents, offset + size);
53 if (PRIV (image_section)->contents == 0)
55 (*_bfd_error_handler) (_("No Mem !"));
58 PRIV (image_section)->size = offset + size;
59 PRIV (image_ptr) = PRIV (image_section)->contents + offset;
65 /* Routines to fill sections contents during tir/etir read. */
67 /* Initialize image buffer pointer to be filled. */
70 image_set_ptr (bfd * abfd, int psect, uquad offset)
73 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
74 psect, PRIV (sections)[psect]->name, offset);
77 PRIV (image_ptr) = PRIV (sections)[psect]->contents + offset;
78 PRIV (image_section) = PRIV (sections)[psect];
81 /* Increment image buffer pointer by offset. */
84 image_inc_ptr (bfd * abfd, uquad offset)
87 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
90 PRIV (image_ptr) += offset;
93 /* Dump multiple bytes to section image. */
96 image_dump (bfd * abfd,
99 int offset ATTRIBUTE_UNUSED)
102 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size,
104 _bfd_hexdump (9, ptr, size, offset);
107 if (PRIV (is_vax) && check_section (abfd, size))
111 *PRIV (image_ptr)++ = *ptr++;
114 /* Write byte to section image. */
117 image_write_b (bfd * abfd, unsigned int value)
120 _bfd_vms_debug (6, "image_write_b (%02x)\n", (int) value);
123 if (PRIV (is_vax) && check_section (abfd, 1))
126 *PRIV (image_ptr)++ = (value & 0xff);
129 /* Write 2-byte word to image. */
132 image_write_w (bfd * abfd, unsigned int value)
135 _bfd_vms_debug (6, "image_write_w (%04x)\n", (int) value);
138 if (PRIV (is_vax) && check_section (abfd, 2))
141 bfd_putl16 ((bfd_vma) value, PRIV (image_ptr));
142 PRIV (image_ptr) += 2;
145 /* Write 4-byte long to image. */
148 image_write_l (bfd * abfd, unsigned long value)
151 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
154 if (PRIV (is_vax) && check_section (abfd, 4))
157 bfd_putl32 ((bfd_vma) value, PRIV (image_ptr));
158 PRIV (image_ptr) += 4;
161 /* Write 8-byte quad to image. */
164 image_write_q (bfd * abfd, uquad value)
167 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
170 if (PRIV (is_vax) && check_section (abfd, 8))
173 bfd_putl64 (value, PRIV (image_ptr));
174 PRIV (image_ptr) += 8;
182 case ETIR_S_C_STA_GBL: return "ETIR_S_C_STA_GBL";
183 case ETIR_S_C_STA_PQ: return "ETIR_S_C_STA_PQ";
184 case ETIR_S_C_STA_LI: return "ETIR_S_C_STA_LI";
185 case ETIR_S_C_STA_MOD: return "ETIR_S_C_STA_MOD";
186 case ETIR_S_C_STA_CKARG: return "ETIR_S_C_STA_CKARG";
187 case ETIR_S_C_STO_B: return "ETIR_S_C_STO_B";
188 case ETIR_S_C_STO_W: return "ETIR_S_C_STO_W";
189 case ETIR_S_C_STO_GBL: return "ETIR_S_C_STO_GBL";
190 case ETIR_S_C_STO_CA: return "ETIR_S_C_STO_CA";
191 case ETIR_S_C_STO_RB: return "ETIR_S_C_STO_RB";
192 case ETIR_S_C_STO_AB: return "ETIR_S_C_STO_AB";
193 case ETIR_S_C_STO_GBL_LW: return "ETIR_S_C_STO_GBL_LW";
194 case ETIR_S_C_STO_LP_PSB: return "ETIR_S_C_STO_LP_PSB";
195 case ETIR_S_C_STO_HINT_GBL: return "ETIR_S_C_STO_HINT_GBL";
196 case ETIR_S_C_STO_HINT_PS: return "ETIR_S_C_STO_HINT_PS";
197 case ETIR_S_C_OPR_INSV: return "ETIR_S_C_OPR_INSV";
198 case ETIR_S_C_OPR_USH: return "ETIR_S_C_OPR_USH";
199 case ETIR_S_C_OPR_ROT: return "ETIR_S_C_OPR_ROT";
200 case ETIR_S_C_OPR_REDEF: return "ETIR_S_C_OPR_REDEF";
201 case ETIR_S_C_OPR_DFLIT: return "ETIR_S_C_OPR_DFLIT";
202 case ETIR_S_C_STC_LP: return "ETIR_S_C_STC_LP";
203 case ETIR_S_C_STC_GBL: return "ETIR_S_C_STC_GBL";
204 case ETIR_S_C_STC_GCA: return "ETIR_S_C_STC_GCA";
205 case ETIR_S_C_STC_PS: return "ETIR_S_C_STC_PS";
206 case ETIR_S_C_STC_NBH_PS: return "ETIR_S_C_STC_NBH_PS";
207 case ETIR_S_C_STC_NOP_GBL: return "ETIR_S_C_STC_NOP_GBL";
208 case ETIR_S_C_STC_NOP_PS: return "ETIR_S_C_STC_NOP_PS";
209 case ETIR_S_C_STC_BSR_GBL: return "ETIR_S_C_STC_BSR_GBL";
210 case ETIR_S_C_STC_BSR_PS: return "ETIR_S_C_STC_BSR_PS";
211 case ETIR_S_C_STC_LDA_GBL: return "ETIR_S_C_STC_LDA_GBL";
212 case ETIR_S_C_STC_LDA_PS: return "ETIR_S_C_STC_LDA_PS";
213 case ETIR_S_C_STC_BOH_GBL: return "ETIR_S_C_STC_BOH_GBL";
214 case ETIR_S_C_STC_BOH_PS: return "ETIR_S_C_STC_BOH_PS";
215 case ETIR_S_C_STC_NBH_GBL: return "ETIR_S_C_STC_NBH_GBL";
218 /* These names have not yet been added to this switch statement. */
222 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
228 handle sta_xxx commands in etir section
229 ptr points to data area in record
231 see table B-8 of the openVMS linker manual. */
234 etir_sta (bfd * abfd, int cmd, unsigned char *ptr)
237 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
238 _bfd_hexdump (8, ptr, 16, (int) ptr);
246 stack 32 bit value of symbol (high bits set to 0). */
247 case ETIR_S_C_STA_GBL:
250 vms_symbol_entry *entry;
252 name = _bfd_vms_save_counted_string (ptr);
253 entry = (vms_symbol_entry *)
254 bfd_hash_lookup (PRIV (vms_symbol_table), name, FALSE, FALSE);
258 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
259 cmd_name (cmd), name);
261 _bfd_vms_push (abfd, (uquad) 0, -1);
264 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
271 stack 32 bit value, sign extend to 64 bit. */
272 case ETIR_S_C_STA_LW:
273 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
279 stack 64 bit value of symbol. */
280 case ETIR_S_C_STA_QW:
281 _bfd_vms_push (abfd, (uquad) bfd_getl64 (ptr), -1);
284 /* stack psect base plus quadword offset
285 arg: lw section index
286 qw signed quadword offset (low 32 bits)
288 stack qw argument and section index
289 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB). */
290 case ETIR_S_C_STA_PQ:
295 psect = bfd_getl32 (ptr);
296 if (psect >= PRIV (section_count))
298 (*_bfd_error_handler) (_("bad section index in %s"),
300 bfd_set_error (bfd_error_bad_value);
303 dummy = bfd_getl64 (ptr + 4);
304 _bfd_vms_push (abfd, dummy, (int) psect);
308 case ETIR_S_C_STA_LI:
309 case ETIR_S_C_STA_MOD:
310 case ETIR_S_C_STA_CKARG:
311 (*_bfd_error_handler) (_("unsupported STA cmd %s"), cmd_name (cmd));
316 (*_bfd_error_handler) (_("reserved STA cmd %d"), cmd);
321 _bfd_vms_debug (5, "etir_sta true\n");
330 handle sto_xxx commands in etir section
331 ptr points to data area in record
333 see table B-9 of the openVMS linker manual. */
336 etir_sto (bfd * abfd, int cmd, unsigned char *ptr)
342 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
343 _bfd_hexdump (8, ptr, 16, (int) ptr);
348 /* Store byte: pop stack, write byte
351 dummy = _bfd_vms_pop (abfd, &psect);
352 /* FIXME: check top bits. */
353 image_write_b (abfd, (unsigned int) dummy & 0xff);
356 /* Store word: pop stack, write word
359 dummy = _bfd_vms_pop (abfd, &psect);
360 /* FIXME: check top bits */
361 image_write_w (abfd, (unsigned int) dummy & 0xffff);
364 /* Store longword: pop stack, write longword
366 case ETIR_S_C_STO_LW:
367 dummy = _bfd_vms_pop (abfd, &psect);
368 dummy += (PRIV (sections)[psect])->vma;
369 /* FIXME: check top bits. */
370 image_write_l (abfd, (unsigned int) dummy & 0xffffffff);
373 /* Store quadword: pop stack, write quadword
375 case ETIR_S_C_STO_QW:
376 dummy = _bfd_vms_pop (abfd, &psect);
377 dummy += (PRIV (sections)[psect])->vma;
378 /* FIXME: check top bits. */
379 image_write_q (abfd, dummy);
382 /* Store immediate repeated: pop stack for repeat count
385 case ETIR_S_C_STO_IMMR:
389 size = bfd_getl32 (ptr);
390 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
392 image_dump (abfd, ptr+4, size, 0);
396 /* Store global: write symbol value
397 arg: cs global symbol name. */
398 case ETIR_S_C_STO_GBL:
400 vms_symbol_entry *entry;
403 name = _bfd_vms_save_counted_string (ptr);
404 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
408 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
409 cmd_name (cmd), name);
414 image_write_q (abfd, (uquad) (entry->symbol->value));
418 /* Store code address: write address of entry point
419 arg: cs global symbol name (procedure). */
420 case ETIR_S_C_STO_CA:
422 vms_symbol_entry *entry;
425 name = _bfd_vms_save_counted_string (ptr);
426 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
430 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
431 cmd_name (cmd), name);
436 image_write_q (abfd, (uquad) (entry->symbol->value));
440 /* Store offset to psect: pop stack, add low 32 bits to base of psect
442 case ETIR_S_C_STO_OFF:
447 q = _bfd_vms_pop (abfd, & psect1);
448 q += (PRIV (sections)[psect1])->vma;
449 image_write_q (abfd, q);
454 arg: lw count of bytes
456 case ETIR_S_C_STO_IMM:
460 size = bfd_getl32 (ptr);
461 image_dump (abfd, ptr+4, size, 0);
465 /* This code is 'reserved to digital' according to the openVMS
466 linker manual, however it is generated by the DEC C compiler
467 and defined in the include file.
468 FIXME, since the following is just a guess
469 store global longword: store 32bit value of symbol
470 arg: cs symbol name. */
471 case ETIR_S_C_STO_GBL_LW:
473 vms_symbol_entry *entry;
476 name = _bfd_vms_save_counted_string (ptr);
477 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
482 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd), name);
484 image_write_l (abfd, (unsigned long) 0); /* FIXME, reloc */
488 image_write_l (abfd, (unsigned long) (entry->symbol->value));
492 case ETIR_S_C_STO_RB:
493 case ETIR_S_C_STO_AB:
494 case ETIR_S_C_STO_LP_PSB:
495 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
498 case ETIR_S_C_STO_HINT_GBL:
499 case ETIR_S_C_STO_HINT_PS:
500 (*_bfd_error_handler) (_("%s: not implemented"), cmd_name (cmd));
504 (*_bfd_error_handler) (_("reserved STO cmd %d"), cmd);
511 /* Stack operator commands
512 all 32 bit signed arithmetic
513 all word just like a stack calculator
514 arguments are popped from stack, results are pushed on stack
516 see table B-10 of the openVMS linker manual. */
519 etir_opr (bfd * abfd, int cmd, unsigned char *ptr ATTRIBUTE_UNUSED)
524 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
525 _bfd_hexdump (8, ptr, 16, (int) ptr);
530 case ETIR_S_C_OPR_NOP: /* No-op. */
533 case ETIR_S_C_OPR_ADD: /* Add. */
534 op1 = (long) _bfd_vms_pop (abfd, NULL);
535 op2 = (long) _bfd_vms_pop (abfd, NULL);
536 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
539 case ETIR_S_C_OPR_SUB: /* Subtract. */
540 op1 = (long) _bfd_vms_pop (abfd, NULL);
541 op2 = (long) _bfd_vms_pop (abfd, NULL);
542 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
545 case ETIR_S_C_OPR_MUL: /* Multiply. */
546 op1 = (long) _bfd_vms_pop (abfd, NULL);
547 op2 = (long) _bfd_vms_pop (abfd, NULL);
548 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
551 case ETIR_S_C_OPR_DIV: /* Divide. */
552 op1 = (long) _bfd_vms_pop (abfd, NULL);
553 op2 = (long) _bfd_vms_pop (abfd, NULL);
555 _bfd_vms_push (abfd, (uquad) 0, -1);
557 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
560 case ETIR_S_C_OPR_AND: /* Logical AND. */
561 op1 = (long) _bfd_vms_pop (abfd, NULL);
562 op2 = (long) _bfd_vms_pop (abfd, NULL);
563 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
566 case ETIR_S_C_OPR_IOR: /* Logical inclusive OR. */
567 op1 = (long) _bfd_vms_pop (abfd, NULL);
568 op2 = (long) _bfd_vms_pop (abfd, NULL);
569 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
572 case ETIR_S_C_OPR_EOR: /* Logical exclusive OR. */
573 op1 = (long) _bfd_vms_pop (abfd, NULL);
574 op2 = (long) _bfd_vms_pop (abfd, NULL);
575 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
578 case ETIR_S_C_OPR_NEG: /* Negate. */
579 op1 = (long) _bfd_vms_pop (abfd, NULL);
580 _bfd_vms_push (abfd, (uquad) (-op1), -1);
583 case ETIR_S_C_OPR_COM: /* Complement. */
584 op1 = (long) _bfd_vms_pop (abfd, NULL);
585 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
588 case ETIR_S_C_OPR_ASH: /* Arithmetic shift. */
589 op1 = (long) _bfd_vms_pop (abfd, NULL);
590 op2 = (long) _bfd_vms_pop (abfd, NULL);
591 if (op2 < 0) /* Shift right. */
593 else /* Shift left. */
595 _bfd_vms_push (abfd, (uquad) op1, -1);
598 case ETIR_S_C_OPR_INSV: /* Insert field. */
599 (void) _bfd_vms_pop (abfd, NULL);
600 case ETIR_S_C_OPR_USH: /* Unsigned shift. */
601 case ETIR_S_C_OPR_ROT: /* Rotate. */
602 case ETIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
603 case ETIR_S_C_OPR_DFLIT: /* Define a literal. */
604 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
607 case ETIR_S_C_OPR_SEL: /* Select. */
608 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
609 (void) _bfd_vms_pop (abfd, NULL);
612 op1 = (long) _bfd_vms_pop (abfd, NULL);
613 (void) _bfd_vms_pop (abfd, NULL);
614 _bfd_vms_push (abfd, (uquad) op1, -1);
619 (*_bfd_error_handler) (_("reserved OPR cmd %d"), cmd);
628 See table B-11 of the openVMS linker manual. */
631 etir_ctl (bfd * abfd, int cmd, unsigned char *ptr)
637 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
638 _bfd_hexdump (8, ptr, 16, (int) ptr);
643 /* Det relocation base: pop stack, set image location counter
645 case ETIR_S_C_CTL_SETRB:
646 dummy = _bfd_vms_pop (abfd, &psect);
647 image_set_ptr (abfd, psect, dummy);
650 /* Augment relocation base: increment image location counter by offset
651 arg: lw offset value. */
652 case ETIR_S_C_CTL_AUGRB:
653 dummy = bfd_getl32 (ptr);
654 image_inc_ptr (abfd, dummy);
657 /* Define location: pop index, save location counter under index
659 case ETIR_S_C_CTL_DFLOC:
660 dummy = _bfd_vms_pop (abfd, NULL);
664 /* Set location: pop index, restore location counter from index
666 case ETIR_S_C_CTL_STLOC:
667 dummy = _bfd_vms_pop (abfd, &psect);
671 /* Stack defined location: pop index, push location counter from index
673 case ETIR_S_C_CTL_STKDL:
674 dummy = _bfd_vms_pop (abfd, &psect);
679 (*_bfd_error_handler) (_("reserved CTL cmd %d"), cmd);
685 /* Store conditional commands
687 See table B-12 and B-13 of the openVMS linker manual. */
690 etir_stc (bfd * abfd, int cmd, unsigned char *ptr ATTRIBUTE_UNUSED)
693 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
694 _bfd_hexdump (8, ptr, 16, (int) ptr);
699 /* 200 Store-conditional Linkage Pair
701 case ETIR_S_C_STC_LP:
702 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
705 /* 201 Store-conditional Linkage Pair with Procedure Signature
706 arg: lw linkage index
710 case ETIR_S_C_STC_LP_PSB:
711 image_inc_ptr (abfd, (uquad) 16); /* skip entry,procval */
714 /* 202 Store-conditional Address at global address
715 arg: lw linkage index
718 case ETIR_S_C_STC_GBL:
719 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
722 /* 203 Store-conditional Code Address at global address
723 arg: lw linkage index
724 cs procedure name. */
725 case ETIR_S_C_STC_GCA:
726 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
729 /* 204 Store-conditional Address at psect + offset
730 arg: lw linkage index
733 case ETIR_S_C_STC_PS:
734 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
737 /* 205 Store-conditional NOP at address of global
739 case ETIR_S_C_STC_NOP_GBL:
741 /* 206 Store-conditional NOP at pect + offset
743 case ETIR_S_C_STC_NOP_PS:
745 /* 207 Store-conditional BSR at global address
747 case ETIR_S_C_STC_BSR_GBL:
749 /* 208 Store-conditional BSR at pect + offset
751 case ETIR_S_C_STC_BSR_PS:
753 /* 209 Store-conditional LDA at global address
755 case ETIR_S_C_STC_LDA_GBL:
757 /* 210 Store-conditional LDA at psect + offset
759 case ETIR_S_C_STC_LDA_PS:
761 /* 211 Store-conditional BSR or Hint at global address
763 case ETIR_S_C_STC_BOH_GBL:
765 /* 212 Store-conditional BSR or Hint at pect + offset
767 case ETIR_S_C_STC_BOH_PS:
769 /* 213 Store-conditional NOP,BSR or HINT at global address
771 case ETIR_S_C_STC_NBH_GBL:
773 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
775 case ETIR_S_C_STC_NBH_PS:
781 _bfd_vms_debug (3, "reserved STC cmd %d", cmd);
789 new_section (bfd * abfd ATTRIBUTE_UNUSED, int idx)
796 _bfd_vms_debug (5, "new_section %d\n", idx);
798 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
800 name = bfd_malloc ((bfd_size_type) strlen (sname) + 1);
803 strcpy (name, sname);
805 section = bfd_malloc ((bfd_size_type) sizeof (asection));
809 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
816 section->contents = 0;
817 section->name = name;
818 section->index = idx;
824 alloc_section (bfd * abfd, unsigned int idx)
829 _bfd_vms_debug (4, "alloc_section %d\n", idx);
833 amt *= sizeof (asection *);
834 PRIV (sections) = bfd_realloc (PRIV (sections), amt);
835 if (PRIV (sections) == 0)
838 while (PRIV (section_count) <= idx)
840 PRIV (sections)[PRIV (section_count)]
841 = new_section (abfd, (int) PRIV (section_count));
842 if (PRIV (sections)[PRIV (section_count)] == 0)
844 PRIV (section_count)++;
854 Handle sta_xxx commands in tir section
855 ptr points to data area in record
857 See table 7-3 of the VAX/VMS linker manual. */
859 static unsigned char *
860 tir_sta (bfd * abfd, unsigned char *ptr)
865 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
871 case TIR_S_C_STA_GBL:
875 stack 32 bit value of symbol (high bits set to 0). */
878 vms_symbol_entry *entry;
880 name = _bfd_vms_save_counted_string (ptr);
882 entry = _bfd_vms_enter_symbol (abfd, name);
886 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
895 stack byte value, sign extend to 32 bit. */
896 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
900 /* stack signed short word
903 stack 16 bit value, sign extend to 32 bit. */
904 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
909 /* stack signed longword
912 stack 32 bit value. */
913 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
918 case TIR_S_C_STA_WPB:
919 /* stack psect base plus byte offset (word index)
920 arg: by section index
922 by signed byte offset. */
927 if (cmd == TIR_S_C_STA_PB)
931 psect = bfd_getl16 (ptr);
935 if (psect >= PRIV (section_count))
936 alloc_section (abfd, psect);
938 dummy = (long) *ptr++;
939 dummy += (PRIV (sections)[psect])->vma;
940 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
945 case TIR_S_C_STA_WPW:
946 /* stack psect base plus word offset (word index)
947 arg: by section index
949 sh signed short offset. */
954 if (cmd == TIR_S_C_STA_PW)
958 psect = bfd_getl16 (ptr);
962 if (psect >= PRIV (section_count))
963 alloc_section (abfd, psect);
965 dummy = bfd_getl16 (ptr); ptr+=2;
966 dummy += (PRIV (sections)[psect])->vma;
967 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
972 case TIR_S_C_STA_WPL:
973 /* stack psect base plus long offset (word index)
974 arg: by section index
976 lw signed longword offset. */
981 if (cmd == TIR_S_C_STA_PL)
985 psect = bfd_getl16 (ptr);
989 if (psect >= PRIV (section_count))
990 alloc_section (abfd, psect);
992 dummy = bfd_getl32 (ptr); ptr += 4;
993 dummy += (PRIV (sections)[psect])->vma;
994 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
999 /* stack unsigned byte
1002 stack byte value. */
1003 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1006 case TIR_S_C_STA_UW:
1007 /* stack unsigned short word
1010 stack 16 bit value. */
1011 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1015 case TIR_S_C_STA_BFI:
1016 /* stack byte from image
1019 case TIR_S_C_STA_WFI:
1020 /* stack byte from image
1023 case TIR_S_C_STA_LFI:
1024 /* stack byte from image
1026 (*_bfd_error_handler) (_("stack-from-image not implemented"));
1029 case TIR_S_C_STA_EPM:
1030 /* stack entry point mask
1033 stack (unsigned) entry point mask of symbol
1034 err if symbol is no entry point. */
1037 vms_symbol_entry *entry;
1039 name = _bfd_vms_save_counted_string (ptr);
1040 entry = _bfd_vms_enter_symbol (abfd, name);
1044 (*_bfd_error_handler) (_("stack-entry-mask not fully implemented"));
1045 _bfd_vms_push (abfd, (uquad) 0, -1);
1050 case TIR_S_C_STA_CKARG:
1051 /* compare procedure argument
1054 da argument descriptor
1056 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1057 and stack TRUE (args match) or FALSE (args dont match) value. */
1058 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1059 _bfd_vms_push (abfd, (uquad) 1, -1);
1062 case TIR_S_C_STA_LSY:
1063 /* stack local symbol value
1064 arg: sh environment index
1069 vms_symbol_entry *entry;
1071 envidx = bfd_getl16 (ptr);
1073 name = _bfd_vms_save_counted_string (ptr);
1074 entry = _bfd_vms_enter_symbol (abfd, name);
1077 (*_bfd_error_handler) (_("stack-local-symbol not fully implemented"));
1078 _bfd_vms_push (abfd, (uquad) 0, -1);
1083 case TIR_S_C_STA_LIT:
1085 arg: by literal index
1089 _bfd_vms_push (abfd, (uquad) 0, -1);
1090 (*_bfd_error_handler) (_("stack-literal not fully implemented"));
1093 case TIR_S_C_STA_LEPM:
1094 /* stack local symbol entry point mask
1095 arg: sh environment index
1098 stack (unsigned) entry point mask of symbol
1099 err if symbol is no entry point. */
1103 vms_symbol_entry *entry;
1105 envidx = bfd_getl16 (ptr);
1107 name = _bfd_vms_save_counted_string (ptr);
1108 entry = _bfd_vms_enter_symbol (abfd, name);
1111 (*_bfd_error_handler) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1112 _bfd_vms_push (abfd, (uquad) 0, -1);
1118 (*_bfd_error_handler) (_("reserved STA cmd %d"), ptr[-1]);
1127 tir_cmd_name (int cmd)
1131 case TIR_S_C_STO_RSB: return "TIR_S_C_STO_RSB";
1132 case TIR_S_C_STO_RSW: return "TIR_S_C_STO_RSW";
1133 case TIR_S_C_STO_RL: return "TIR_S_C_STO_RL";
1134 case TIR_S_C_STO_VPS: return "TIR_S_C_STO_VPS";
1135 case TIR_S_C_STO_USB: return "TIR_S_C_STO_USB";
1136 case TIR_S_C_STO_USW: return "TIR_S_C_STO_USW";
1137 case TIR_S_C_STO_RUB: return "TIR_S_C_STO_RUB";
1138 case TIR_S_C_STO_RUW: return "TIR_S_C_STO_RUW";
1139 case TIR_S_C_STO_PIRR: return "TIR_S_C_STO_PIRR";
1140 case TIR_S_C_OPR_INSV: return "TIR_S_C_OPR_INSV";
1141 case TIR_S_C_OPR_DFLIT: return "TIR_S_C_OPR_DFLIT";
1142 case TIR_S_C_OPR_REDEF: return "TIR_S_C_OPR_REDEF";
1143 case TIR_S_C_OPR_ROT: return "TIR_S_C_OPR_ROT";
1144 case TIR_S_C_OPR_USH: return "TIR_S_C_OPR_USH";
1145 case TIR_S_C_OPR_ASH: return "TIR_S_C_OPR_ASH";
1146 case TIR_S_C_CTL_DFLOC: return "TIR_S_C_CTL_DFLOC";
1147 case TIR_S_C_CTL_STLOC: return "TIR_S_C_CTL_STLOC";
1148 case TIR_S_C_CTL_STKDL: return "TIR_S_C_CTL_STKDL";
1151 /* These strings have not been added yet. */
1160 handle sto_xxx commands in tir section
1161 ptr points to data area in record
1163 See table 7-4 of the VAX/VMS linker manual. */
1165 static unsigned char *
1166 tir_sto (bfd * abfd, unsigned char *ptr)
1168 unsigned long dummy;
1173 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1178 case TIR_S_C_STO_SB:
1179 /* Store signed byte: pop stack, write byte
1181 dummy = _bfd_vms_pop (abfd, &psect);
1182 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1185 case TIR_S_C_STO_SW:
1186 /* Store signed word: pop stack, write word
1188 dummy = _bfd_vms_pop (abfd, &psect);
1189 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1192 case TIR_S_C_STO_LW:
1193 /* Store longword: pop stack, write longword
1195 dummy = _bfd_vms_pop (abfd, &psect);
1196 image_write_l (abfd, dummy & 0xffffffff); /* FIXME: check top bits */
1199 case TIR_S_C_STO_BD:
1200 /* Store byte displaced: pop stack, sub lc+1, write byte
1202 dummy = _bfd_vms_pop (abfd, &psect);
1203 dummy -= ((PRIV (sections)[psect])->vma + 1);
1204 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1207 case TIR_S_C_STO_WD:
1208 /* Store word displaced: pop stack, sub lc+2, write word
1210 dummy = _bfd_vms_pop (abfd, &psect);
1211 dummy -= ((PRIV (sections)[psect])->vma + 2);
1212 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1215 case TIR_S_C_STO_LD:
1216 /* Store long displaced: pop stack, sub lc+4, write long
1218 dummy = _bfd_vms_pop (abfd, &psect);
1219 dummy -= ((PRIV (sections)[psect])->vma + 4);
1220 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1223 case TIR_S_C_STO_LI:
1224 /* Store short literal: pop stack, write byte
1226 dummy = _bfd_vms_pop (abfd, &psect);
1227 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1230 case TIR_S_C_STO_PIDR:
1231 /* Store position independent data reference: pop stack, write longword
1233 FIXME: incomplete ! */
1234 dummy = _bfd_vms_pop (abfd, &psect);
1235 image_write_l (abfd, dummy & 0xffffffff);
1238 case TIR_S_C_STO_PICR:
1239 /* Store position independent code reference: pop stack, write longword
1241 FIXME: incomplete ! */
1242 dummy = _bfd_vms_pop (abfd, &psect);
1243 image_write_b (abfd, 0x9f);
1244 image_write_l (abfd, dummy & 0xffffffff);
1247 case TIR_S_C_STO_RIVB:
1248 /* Store repeated immediate variable bytes
1249 1-byte count n field followed by n bytes of data
1250 pop stack, write n bytes <stack> times. */
1252 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1253 while (dummy-- > 0L)
1254 image_dump (abfd, ptr, size, 0);
1259 /* Store byte from top longword. */
1260 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1261 image_write_b (abfd, dummy & 0xff);
1265 /* Store word from top longword. */
1266 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1267 image_write_w (abfd, dummy & 0xffff);
1270 case TIR_S_C_STO_RB:
1271 /* Store repeated byte from top longword. */
1272 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1273 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1275 image_write_b (abfd, dummy & 0xff);
1278 case TIR_S_C_STO_RW:
1279 /* Store repeated word from top longword. */
1280 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1281 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1283 image_write_w (abfd, dummy & 0xffff);
1286 case TIR_S_C_STO_RSB:
1287 case TIR_S_C_STO_RSW:
1288 case TIR_S_C_STO_RL:
1289 case TIR_S_C_STO_VPS:
1290 case TIR_S_C_STO_USB:
1291 case TIR_S_C_STO_USW:
1292 case TIR_S_C_STO_RUB:
1293 case TIR_S_C_STO_RUW:
1294 case TIR_S_C_STO_PIRR:
1295 (*_bfd_error_handler) (_("%s: not implemented"), tir_cmd_name (ptr[-1]));
1299 (*_bfd_error_handler) (_("reserved STO cmd %d"), ptr[-1]);
1306 /* Stack operator commands
1307 All 32 bit signed arithmetic
1308 All word just like a stack calculator
1309 Arguments are popped from stack, results are pushed on stack
1311 See table 7-5 of the VAX/VMS linker manual. */
1313 static unsigned char *
1314 tir_opr (bfd * abfd, unsigned char *ptr)
1319 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1325 case TIR_S_C_OPR_NOP: /* No-op. */
1328 case TIR_S_C_OPR_ADD: /* Add. */
1329 op1 = (long) _bfd_vms_pop (abfd, NULL);
1330 op2 = (long) _bfd_vms_pop (abfd, NULL);
1331 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
1334 case TIR_S_C_OPR_SUB: /* Subtract. */
1335 op1 = (long) _bfd_vms_pop (abfd, NULL);
1336 op2 = (long) _bfd_vms_pop (abfd, NULL);
1337 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
1340 case TIR_S_C_OPR_MUL: /* Multiply. */
1341 op1 = (long) _bfd_vms_pop (abfd, NULL);
1342 op2 = (long) _bfd_vms_pop (abfd, NULL);
1343 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
1346 case TIR_S_C_OPR_DIV: /* Divide. */
1347 op1 = (long) _bfd_vms_pop (abfd, NULL);
1348 op2 = (long) _bfd_vms_pop (abfd, NULL);
1350 _bfd_vms_push (abfd, (uquad) 0, -1);
1352 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
1355 case TIR_S_C_OPR_AND: /* Logical AND. */
1356 op1 = (long) _bfd_vms_pop (abfd, NULL);
1357 op2 = (long) _bfd_vms_pop (abfd, NULL);
1358 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
1361 case TIR_S_C_OPR_IOR: /* Logical inclusive OR. */
1362 op1 = (long) _bfd_vms_pop (abfd, NULL);
1363 op2 = (long) _bfd_vms_pop (abfd, NULL);
1364 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
1367 case TIR_S_C_OPR_EOR: /* Logical exclusive OR. */
1368 op1 = (long) _bfd_vms_pop (abfd, NULL);
1369 op2 = (long) _bfd_vms_pop (abfd, NULL);
1370 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
1373 case TIR_S_C_OPR_NEG: /* Negate. */
1374 op1 = (long) _bfd_vms_pop (abfd, NULL);
1375 _bfd_vms_push (abfd, (uquad) (-op1), -1);
1378 case TIR_S_C_OPR_COM: /* Complement. */
1379 op1 = (long) _bfd_vms_pop (abfd, NULL);
1380 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
1383 case TIR_S_C_OPR_INSV: /* Insert field. */
1384 (void) _bfd_vms_pop (abfd, NULL);
1385 (*_bfd_error_handler) (_("%s: not fully implemented"),
1386 tir_cmd_name (ptr[-1]));
1389 case TIR_S_C_OPR_ASH: /* Arithmetic shift. */
1390 op1 = (long) _bfd_vms_pop (abfd, NULL);
1391 op2 = (long) _bfd_vms_pop (abfd, NULL);
1392 if (HIGHBIT (op1)) /* Shift right. */
1394 else /* Shift left. */
1396 _bfd_vms_push (abfd, (uquad) op2, -1);
1397 (*_bfd_error_handler) (_("%s: not fully implemented"),
1398 tir_cmd_name (ptr[-1]));
1401 case TIR_S_C_OPR_USH: /* Unsigned shift. */
1402 op1 = (long) _bfd_vms_pop (abfd, NULL);
1403 op2 = (long) _bfd_vms_pop (abfd, NULL);
1404 if (HIGHBIT (op1)) /* Shift right. */
1406 else /* Shift left. */
1408 _bfd_vms_push (abfd, (uquad) op2, -1);
1409 (*_bfd_error_handler) (_("%s: not fully implemented"),
1410 tir_cmd_name (ptr[-1]));
1413 case TIR_S_C_OPR_ROT: /* Rotate. */
1414 op1 = (long) _bfd_vms_pop (abfd, NULL);
1415 op2 = (long) _bfd_vms_pop (abfd, NULL);
1416 if (HIGHBIT (0)) /* Shift right. */
1418 else /* Shift left. */
1420 _bfd_vms_push (abfd, (uquad) op2, -1);
1421 (*_bfd_error_handler) (_("%s: not fully implemented"),
1422 tir_cmd_name (ptr[-1]));
1425 case TIR_S_C_OPR_SEL: /* Select. */
1426 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
1427 (void) _bfd_vms_pop (abfd, NULL);
1430 op1 = (long) _bfd_vms_pop (abfd, NULL);
1431 (void) _bfd_vms_pop (abfd, NULL);
1432 _bfd_vms_push (abfd, (uquad) op1, -1);
1436 case TIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
1437 case TIR_S_C_OPR_DFLIT: /* Define a literal. */
1438 (*_bfd_error_handler) (_("%s: not supported"),
1439 tir_cmd_name (ptr[-1]));
1443 (*_bfd_error_handler) (_("reserved OPR cmd %d"), ptr[-1]);
1452 See table 7-6 of the VAX/VMS linker manual. */
1454 static unsigned char *
1455 tir_ctl (bfd * abfd, unsigned char *ptr)
1457 unsigned long dummy;
1461 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1466 case TIR_S_C_CTL_SETRB:
1467 /* Set relocation base: pop stack, set image location counter
1469 dummy = _bfd_vms_pop (abfd, (int *) &psect);
1470 if (psect >= PRIV (section_count))
1471 alloc_section (abfd, psect);
1472 image_set_ptr (abfd, (int) psect, (uquad) dummy);
1475 case TIR_S_C_CTL_AUGRB:
1476 /* Augment relocation base: increment image location counter by offset
1477 arg: lw offset value. */
1478 dummy = bfd_getl32 (ptr);
1479 image_inc_ptr (abfd, (uquad) dummy);
1482 case TIR_S_C_CTL_DFLOC:
1483 /* Define location: pop index, save location counter under index
1485 dummy = _bfd_vms_pop (abfd, NULL);
1486 (*_bfd_error_handler) (_("%s: not fully implemented"),
1487 tir_cmd_name (ptr[-1]));
1490 case TIR_S_C_CTL_STLOC:
1491 /* Set location: pop index, restore location counter from index
1493 dummy = _bfd_vms_pop (abfd, (int *) &psect);
1494 (*_bfd_error_handler) (_("%s: not fully implemented"),
1495 tir_cmd_name (ptr[-1]));
1498 case TIR_S_C_CTL_STKDL:
1499 /* Stack defined location: pop index, push location counter from index
1501 dummy = _bfd_vms_pop (abfd, (int *) &psect);
1502 (*_bfd_error_handler) (_("%s: not fully implemented"),
1503 tir_cmd_name (ptr[-1]));
1507 (*_bfd_error_handler) (_("reserved CTL cmd %d"), ptr[-1]);
1513 /* Handle command from TIR section. */
1515 static unsigned char *
1516 tir_cmd (bfd * abfd, unsigned char *ptr)
1522 unsigned char * (*explain) (bfd *, unsigned char *);
1526 { 0, TIR_S_C_MAXSTACOD, tir_sta },
1527 { TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto },
1528 { TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr },
1529 { TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl },
1535 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1536 _bfd_hexdump (8, ptr, 16, (int) ptr);
1541 /* Store immediate. */
1542 i = 128 - (*ptr++ & 0x7f);
1543 image_dump (abfd, ptr, i, 0);
1548 while (tir_table[i].mincod >= 0)
1550 if ( (tir_table[i].mincod <= *ptr)
1551 && (*ptr <= tir_table[i].maxcod))
1553 ptr = tir_table[i].explain (abfd, ptr);
1558 if (tir_table[i].mincod < 0)
1560 (*_bfd_error_handler) (_("obj code %d not found"), *ptr);
1568 /* Handle command from ETIR section. */
1571 etir_cmd (bfd * abfd, int cmd, unsigned char *ptr)
1577 bfd_boolean (*explain) (bfd *, int, unsigned char *);
1581 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1582 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1583 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1584 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1585 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1592 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1593 _bfd_hexdump (8, ptr, 16, (int) ptr);
1596 while (etir_table[i].mincod >= 0)
1598 if ( (etir_table[i].mincod <= cmd)
1599 && (cmd <= etir_table[i].maxcod))
1601 if (!etir_table[i].explain (abfd, cmd, ptr))
1609 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1614 /* Text Information and Relocation Records (OBJ$C_TIR)
1615 handle tir record. */
1618 analyze_tir (bfd * abfd, unsigned char *ptr, unsigned int length)
1620 unsigned char *maxptr;
1623 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1626 maxptr = ptr + length;
1628 while (ptr < maxptr)
1630 ptr = tir_cmd (abfd, ptr);
1638 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1639 handle etir record. */
1642 analyze_etir (bfd * abfd, unsigned char *ptr, unsigned int length)
1645 unsigned char *maxptr;
1649 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1652 maxptr = ptr + length;
1654 while (ptr < maxptr)
1656 cmd = bfd_getl16 (ptr);
1657 length = bfd_getl16 (ptr + 2);
1658 result = etir_cmd (abfd, cmd, ptr+4);
1665 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1671 /* Process ETIR record
1672 Return 0 on success, -1 on error. */
1675 _bfd_vms_slurp_tir (bfd * abfd, int objtype)
1680 _bfd_vms_debug (2, "TIR/ETIR\n");
1686 PRIV (vms_rec) += 4; /* Skip type, size. */
1687 PRIV (rec_size) -= 4;
1688 result = analyze_etir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1691 PRIV (vms_rec) += 1; /* Skip type. */
1692 PRIV (rec_size) -= 1;
1693 result = analyze_tir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1703 /* Process EDBG record
1704 Return 0 on success, -1 on error
1706 Not implemented yet. */
1709 _bfd_vms_slurp_dbg (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
1712 _bfd_vms_debug (2, "DBG/EDBG\n");
1715 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1719 /* Process ETBT record
1720 Return 0 on success, -1 on error
1722 Not implemented yet. */
1725 _bfd_vms_slurp_tbt (bfd * abfd ATTRIBUTE_UNUSED,
1726 int objtype ATTRIBUTE_UNUSED)
1729 _bfd_vms_debug (2, "TBT/ETBT\n");
1735 /* Process LNK record
1736 Return 0 on success, -1 on error
1738 Not implemented yet. */
1741 _bfd_vms_slurp_lnk (bfd * abfd ATTRIBUTE_UNUSED,
1742 int objtype ATTRIBUTE_UNUSED)
1745 _bfd_vms_debug (2, "LNK\n");
1751 /* Start ETIR record for section #index at virtual addr offset. */
1754 start_etir_record (bfd * abfd, int index, uquad offset, bfd_boolean justoffset)
1758 /* One ETIR per section. */
1759 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1);
1760 _bfd_vms_output_push (abfd);
1763 /* Push start offset. */
1764 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1);
1765 _bfd_vms_output_long (abfd, (unsigned long) index);
1766 _bfd_vms_output_quad (abfd, (uquad) offset);
1767 _bfd_vms_output_flush (abfd);
1769 /* Start = pop (). */
1770 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1);
1771 _bfd_vms_output_flush (abfd);
1775 end_etir_record (bfd * abfd)
1777 _bfd_vms_output_pop (abfd);
1778 _bfd_vms_output_end (abfd);
1781 /* WRITE ETIR SECTION
1783 This is still under construction and therefore not documented. */
1786 sto_imm (bfd * abfd, vms_section *sptr, bfd_vma vaddr, int index)
1790 unsigned char *cptr;
1793 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
1794 _bfd_hexdump (9, sptr->contents, (int) sptr->size, (int) vaddr);
1798 cptr = sptr->contents;
1802 /* Try all the rest. */
1805 if (_bfd_vms_output_check (abfd, size) < 0)
1807 /* Doesn't fit, split ! */
1808 end_etir_record (abfd);
1809 start_etir_record (abfd, index, vaddr, FALSE);
1811 size = _bfd_vms_output_check (abfd, 0);
1812 /* More than what's left ? */
1817 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
1818 _bfd_vms_output_long (abfd, (unsigned long) (size));
1819 _bfd_vms_output_dump (abfd, cptr, size);
1820 _bfd_vms_output_flush (abfd);
1823 _bfd_vms_debug (10, "dumped %d bytes\n", size);
1824 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
1833 /* Write section contents for bfd abfd. */
1836 _bfd_vms_write_tir (bfd * abfd, int objtype ATTRIBUTE_UNUSED)
1843 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
1846 _bfd_vms_output_alignment (abfd, 4);
1849 PRIV (vms_linkage_index) = 1;
1851 /* Dump all other sections. */
1852 section = abfd->sections;
1854 while (section != NULL)
1858 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
1859 section->index, section->name,
1860 (int) (section->size));
1863 if (section->flags & SEC_RELOC)
1867 if ((i = section->reloc_count) <= 0)
1868 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
1874 _bfd_vms_debug (4, "%d relocations:\n", i);
1875 rptr = section->orelocation;
1878 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
1879 (*(*rptr)->sym_ptr_ptr)->name,
1880 (*(*rptr)->sym_ptr_ptr)->section->name,
1881 (long) (*(*rptr)->sym_ptr_ptr)->value,
1882 (*rptr)->address, (*rptr)->addend,
1883 bfd_get_reloc_size ((*rptr)->howto),
1884 (*rptr)->howto->name);
1891 if ((section->flags & SEC_HAS_CONTENTS)
1892 && (! bfd_is_com_section (section)))
1894 /* Virtual addr in section. */
1897 sptr = _bfd_get_vms_section (abfd, section->index);
1900 bfd_set_error (bfd_error_no_contents);
1904 vaddr = (bfd_vma) (sptr->offset);
1906 start_etir_record (abfd, section->index, (uquad) sptr->offset,
1909 while (sptr != NULL)
1911 /* One STA_PQ, CTL_SETRB per vms_section. */
1912 if (section->flags & SEC_RELOC)
1914 /* Check for relocs. */
1915 arelent **rptr = section->orelocation;
1916 int i = section->reloc_count;
1920 bfd_size_type addr = (*rptr)->address;
1921 bfd_size_type len = bfd_get_reloc_size ((*rptr)->howto);
1922 if (sptr->offset < addr)
1924 /* Sptr starts before reloc. */
1925 bfd_size_type before = addr - sptr->offset;
1926 if (sptr->size <= before)
1928 /* Complete before. */
1929 sto_imm (abfd, sptr, vaddr, section->index);
1930 vaddr += sptr->size;
1935 /* Partly before. */
1936 int after = sptr->size - before;
1938 sptr->size = before;
1939 sto_imm (abfd, sptr, vaddr, section->index);
1940 vaddr += sptr->size;
1941 sptr->contents += before;
1942 sptr->offset += before;
1946 else if (sptr->offset == addr)
1948 /* Sptr starts at reloc. */
1949 asymbol *sym = *(*rptr)->sym_ptr_ptr;
1950 asection *sec = sym->section;
1952 switch ((*rptr)->howto->type)
1954 case ALPHA_R_IGNORE:
1957 case ALPHA_R_REFLONG:
1959 if (bfd_is_und_section (sym->section))
1961 int slen = strlen ((char *) sym->name);
1964 if (_bfd_vms_output_check (abfd, slen) < 0)
1966 end_etir_record (abfd);
1967 start_etir_record (abfd,
1971 _bfd_vms_output_begin (abfd,
1972 ETIR_S_C_STO_GBL_LW,
1974 hash = (_bfd_vms_length_hash_symbol
1975 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
1976 _bfd_vms_output_counted (abfd, hash);
1977 _bfd_vms_output_flush (abfd);
1979 else if (bfd_is_abs_section (sym->section))
1981 if (_bfd_vms_output_check (abfd, 16) < 0)
1983 end_etir_record (abfd);
1984 start_etir_record (abfd,
1988 _bfd_vms_output_begin (abfd,
1991 _bfd_vms_output_quad (abfd,
1992 (uquad) sym->value);
1993 _bfd_vms_output_flush (abfd);
1994 _bfd_vms_output_begin (abfd,
1997 _bfd_vms_output_flush (abfd);
2001 if (_bfd_vms_output_check (abfd, 32) < 0)
2003 end_etir_record (abfd);
2004 start_etir_record (abfd,
2008 _bfd_vms_output_begin (abfd,
2011 _bfd_vms_output_long (abfd,
2012 (unsigned long) (sec->index));
2013 _bfd_vms_output_quad (abfd,
2014 ((uquad) (*rptr)->addend
2015 + (uquad) sym->value));
2016 _bfd_vms_output_flush (abfd);
2017 _bfd_vms_output_begin (abfd,
2020 _bfd_vms_output_flush (abfd);
2025 case ALPHA_R_REFQUAD:
2027 if (bfd_is_und_section (sym->section))
2029 int slen = strlen ((char *) sym->name);
2032 if (_bfd_vms_output_check (abfd, slen) < 0)
2034 end_etir_record (abfd);
2035 start_etir_record (abfd,
2039 _bfd_vms_output_begin (abfd,
2042 hash = (_bfd_vms_length_hash_symbol
2043 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2044 _bfd_vms_output_counted (abfd, hash);
2045 _bfd_vms_output_flush (abfd);
2047 else if (bfd_is_abs_section (sym->section))
2049 if (_bfd_vms_output_check (abfd, 16) < 0)
2051 end_etir_record (abfd);
2052 start_etir_record (abfd,
2056 _bfd_vms_output_begin (abfd,
2059 _bfd_vms_output_quad (abfd,
2060 (uquad) sym->value);
2061 _bfd_vms_output_flush (abfd);
2062 _bfd_vms_output_begin (abfd,
2065 _bfd_vms_output_flush (abfd);
2069 if (_bfd_vms_output_check (abfd, 32) < 0)
2071 end_etir_record (abfd);
2072 start_etir_record (abfd,
2076 _bfd_vms_output_begin (abfd,
2079 _bfd_vms_output_long (abfd,
2080 (unsigned long) (sec->index));
2081 _bfd_vms_output_quad (abfd,
2082 ((uquad) (*rptr)->addend
2083 + (uquad) sym->value));
2084 _bfd_vms_output_flush (abfd);
2085 _bfd_vms_output_begin (abfd,
2088 _bfd_vms_output_flush (abfd);
2096 char *hash ATTRIBUTE_UNUSED;
2098 hint_size = sptr->size;
2100 sto_imm (abfd, sptr, vaddr, section->index);
2101 sptr->size = hint_size;
2104 case ALPHA_R_LINKAGE:
2108 if (_bfd_vms_output_check (abfd, 64) < 0)
2110 end_etir_record (abfd);
2111 start_etir_record (abfd, section->index,
2114 _bfd_vms_output_begin (abfd,
2115 ETIR_S_C_STC_LP_PSB,
2117 _bfd_vms_output_long (abfd,
2118 (unsigned long) PRIV (vms_linkage_index));
2119 PRIV (vms_linkage_index) += 2;
2120 hash = (_bfd_vms_length_hash_symbol
2121 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2122 _bfd_vms_output_counted (abfd, hash);
2123 _bfd_vms_output_byte (abfd, 0);
2124 _bfd_vms_output_flush (abfd);
2128 case ALPHA_R_CODEADDR:
2130 int slen = strlen ((char *) sym->name);
2132 if (_bfd_vms_output_check (abfd, slen) < 0)
2134 end_etir_record (abfd);
2135 start_etir_record (abfd,
2139 _bfd_vms_output_begin (abfd,
2142 hash = (_bfd_vms_length_hash_symbol
2143 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2144 _bfd_vms_output_counted (abfd, hash);
2145 _bfd_vms_output_flush (abfd);
2150 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2151 (*rptr)->howto->name);
2157 if (len == sptr->size)
2163 sptr->contents += len;
2164 sptr->offset += len;
2172 /* Sptr starts after reloc. */
2174 /* Check next reloc. */
2180 /* All reloc checked. */
2184 sto_imm (abfd, sptr, vaddr, section->index);
2185 vaddr += sptr->size;
2193 /* No relocs, just dump. */
2194 sto_imm (abfd, sptr, vaddr, section->index);
2195 vaddr += sptr->size;
2201 end_etir_record (abfd);
2204 section = section->next;
2207 _bfd_vms_output_alignment (abfd, 2);
2211 /* Write traceback data for bfd abfd. */
2214 _bfd_vms_write_tbt (bfd * abfd ATTRIBUTE_UNUSED,
2215 int objtype ATTRIBUTE_UNUSED)
2218 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2224 /* Write debug info for bfd abfd. */
2227 _bfd_vms_write_dbg (bfd * abfd ATTRIBUTE_UNUSED,
2228 int objtype ATTRIBUTE_UNUSED)
2231 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);