PR gas/619
[binutils.git] / bfd / vms-tir.c
blobaa3e536044254b70fc8a23af6d03399d4d957a1b
1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004
4 Free Software Foundation, Inc.
6 TIR record handling functions
7 ETIR record handling functions
9 go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
12 Written by Klaus K"ampf (kkaempf@rmi.de)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* The following type abbreviations are used:
30 cs counted string (ascii string with length byte)
31 by byte (1 byte)
32 sh short (2 byte, 16 bit)
33 lw longword (4 byte, 32 bit)
34 qw quadword (8 byte, 64 bit)
35 da data stream */
37 #include "bfd.h"
38 #include "sysdep.h"
39 #include "bfdlink.h"
40 #include "libbfd.h"
42 #include "vms.h"
44 static void image_set_ptr
45 PARAMS ((bfd *abfd, int psect, uquad offset));
46 static void image_inc_ptr
47 PARAMS ((bfd *abfd, uquad offset));
48 static void image_dump
49 PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
50 static void image_write_b
51 PARAMS ((bfd *abfd, unsigned int value));
52 static void image_write_w
53 PARAMS ((bfd *abfd, unsigned int value));
54 static void image_write_l
55 PARAMS ((bfd *abfd, unsigned long value));
56 static void image_write_q
57 PARAMS ((bfd *abfd, uquad value));
58 static int check_section
59 PARAMS ((bfd *, int));
60 static bfd_boolean etir_sta
61 PARAMS ((bfd *, int, unsigned char *));
62 static bfd_boolean etir_sto
63 PARAMS ((bfd *, int, unsigned char *));
64 static bfd_boolean etir_opr
65 PARAMS ((bfd *, int, unsigned char *));
66 static bfd_boolean etir_ctl
67 PARAMS ((bfd *, int, unsigned char *));
68 static bfd_boolean etir_stc
69 PARAMS ((bfd *, int, unsigned char *));
70 static asection *new_section
71 PARAMS ((bfd *, int));
72 static int alloc_section
73 PARAMS ((bfd *, unsigned int));
74 static int etir_cmd
75 PARAMS ((bfd *, int, unsigned char *));
76 static int analyze_tir
77 PARAMS ((bfd *, unsigned char *, unsigned int));
78 static int analyze_etir
79 PARAMS ((bfd *, unsigned char *, unsigned int));
80 static unsigned char * tir_opr
81 PARAMS ((bfd *, unsigned char *));
82 static const char * tir_cmd_name
83 PARAMS ((int));
84 static const char * cmd_name
85 PARAMS ((int));
88 static int
89 check_section (abfd, size)
90 bfd *abfd;
91 int size;
93 bfd_size_type offset;
95 offset = PRIV (image_ptr) - PRIV (image_section)->contents;
96 if (offset + size > PRIV (image_section)->size)
98 PRIV (image_section)->contents
99 = bfd_realloc (PRIV (image_section)->contents, offset + size);
100 if (PRIV (image_section)->contents == 0)
102 (*_bfd_error_handler) (_("No Mem !"));
103 return -1;
105 PRIV (image_section)->size = offset + size;
106 PRIV (image_ptr) = PRIV (image_section)->contents + offset;
109 return 0;
112 /* Routines to fill sections contents during tir/etir read. */
114 /* Initialize image buffer pointer to be filled. */
116 static void
117 image_set_ptr (abfd, psect, offset)
118 bfd *abfd;
119 int psect;
120 uquad offset;
122 #if VMS_DEBUG
123 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
124 psect, PRIV (sections)[psect]->name, offset);
125 #endif
127 PRIV (image_ptr) = PRIV (sections)[psect]->contents + offset;
128 PRIV (image_section) = PRIV (sections)[psect];
129 return;
132 /* Increment image buffer pointer by offset. */
134 static void
135 image_inc_ptr (abfd, offset)
136 bfd *abfd;
137 uquad offset;
139 #if VMS_DEBUG
140 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
141 #endif
143 PRIV (image_ptr) += offset;
145 return;
148 /* Dump multiple bytes to section image. */
150 static void
151 image_dump (abfd, ptr, size, offset)
152 bfd *abfd;
153 unsigned char *ptr;
154 int size;
155 int offset ATTRIBUTE_UNUSED;
157 #if VMS_DEBUG
158 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size,
159 PRIV (image_ptr));
160 _bfd_hexdump (9, ptr, size, offset);
161 #endif
163 if (PRIV (is_vax) && check_section (abfd, size))
164 return;
166 while (size-- > 0)
167 *PRIV (image_ptr)++ = *ptr++;
168 return;
171 /* Write byte to section image. */
173 static void
174 image_write_b (abfd, value)
175 bfd *abfd;
176 unsigned int value;
178 #if VMS_DEBUG
179 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value);
180 #endif
182 if (PRIV (is_vax) && check_section (abfd, 1))
183 return;
185 *PRIV (image_ptr)++ = (value & 0xff);
186 return;
189 /* Write 2-byte word to image. */
191 static void
192 image_write_w (abfd, value)
193 bfd *abfd;
194 unsigned int value;
196 #if VMS_DEBUG
197 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value);
198 #endif
200 if (PRIV (is_vax) && check_section (abfd, 2))
201 return;
203 bfd_putl16 ((bfd_vma) value, PRIV (image_ptr));
204 PRIV (image_ptr) += 2;
206 return;
209 /* Write 4-byte long to image. */
211 static void
212 image_write_l (abfd, value)
213 bfd *abfd;
214 unsigned long value;
216 #if VMS_DEBUG
217 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
218 #endif
220 if (PRIV (is_vax) && check_section (abfd, 4))
221 return;
223 bfd_putl32 ((bfd_vma) value, PRIV (image_ptr));
224 PRIV (image_ptr) += 4;
226 return;
229 /* Write 8-byte quad to image. */
231 static void
232 image_write_q (abfd, value)
233 bfd *abfd;
234 uquad value;
236 #if VMS_DEBUG
237 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
238 #endif
240 if (PRIV (is_vax) && check_section (abfd, 8))
241 return;
243 bfd_putl64 (value, PRIV (image_ptr));
244 PRIV (image_ptr) += 8;
246 return;
249 static const char *
250 cmd_name (cmd)
251 int cmd;
253 switch (cmd)
255 case ETIR_S_C_STA_GBL: return "ETIR_S_C_STA_GBL";
256 case ETIR_S_C_STA_PQ: return "ETIR_S_C_STA_PQ";
257 case ETIR_S_C_STA_LI: return "ETIR_S_C_STA_LI";
258 case ETIR_S_C_STA_MOD: return "ETIR_S_C_STA_MOD";
259 case ETIR_S_C_STA_CKARG: return "ETIR_S_C_STA_CKARG";
260 case ETIR_S_C_STO_B: return "ETIR_S_C_STO_B";
261 case ETIR_S_C_STO_W: return "ETIR_S_C_STO_W";
262 case ETIR_S_C_STO_GBL: return "ETIR_S_C_STO_GBL";
263 case ETIR_S_C_STO_CA: return "ETIR_S_C_STO_CA";
264 case ETIR_S_C_STO_RB: return "ETIR_S_C_STO_RB";
265 case ETIR_S_C_STO_AB: return "ETIR_S_C_STO_AB";
266 case ETIR_S_C_STO_GBL_LW: return "ETIR_S_C_STO_GBL_LW";
267 case ETIR_S_C_STO_LP_PSB: return "ETIR_S_C_STO_LP_PSB";
268 case ETIR_S_C_STO_HINT_GBL: return "ETIR_S_C_STO_HINT_GBL";
269 case ETIR_S_C_STO_HINT_PS: return "ETIR_S_C_STO_HINT_PS";
270 case ETIR_S_C_OPR_INSV: return "ETIR_S_C_OPR_INSV";
271 case ETIR_S_C_OPR_USH: return "ETIR_S_C_OPR_USH";
272 case ETIR_S_C_OPR_ROT: return "ETIR_S_C_OPR_ROT";
273 case ETIR_S_C_OPR_REDEF: return "ETIR_S_C_OPR_REDEF";
274 case ETIR_S_C_OPR_DFLIT: return "ETIR_S_C_OPR_DFLIT";
275 case ETIR_S_C_STC_LP: return "ETIR_S_C_STC_LP";
276 case ETIR_S_C_STC_GBL: return "ETIR_S_C_STC_GBL";
277 case ETIR_S_C_STC_GCA: return "ETIR_S_C_STC_GCA";
278 case ETIR_S_C_STC_PS: return "ETIR_S_C_STC_PS";
279 case ETIR_S_C_STC_NBH_PS: return "ETIR_S_C_STC_NBH_PS";
280 case ETIR_S_C_STC_NOP_GBL: return "ETIR_S_C_STC_NOP_GBL";
281 case ETIR_S_C_STC_NOP_PS: return "ETIR_S_C_STC_NOP_PS";
282 case ETIR_S_C_STC_BSR_GBL: return "ETIR_S_C_STC_BSR_GBL";
283 case ETIR_S_C_STC_BSR_PS: return "ETIR_S_C_STC_BSR_PS";
284 case ETIR_S_C_STC_LDA_GBL: return "ETIR_S_C_STC_LDA_GBL";
285 case ETIR_S_C_STC_LDA_PS: return "ETIR_S_C_STC_LDA_PS";
286 case ETIR_S_C_STC_BOH_GBL: return "ETIR_S_C_STC_BOH_GBL";
287 case ETIR_S_C_STC_BOH_PS: return "ETIR_S_C_STC_BOH_PS";
288 case ETIR_S_C_STC_NBH_GBL: return "ETIR_S_C_STC_NBH_GBL";
290 default:
291 /* These names have not yet been added to this switch statement. */
292 abort ();
295 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
297 /* etir_sta
299 vms stack commands
301 handle sta_xxx commands in etir section
302 ptr points to data area in record
304 see table B-8 of the openVMS linker manual. */
306 static bfd_boolean
307 etir_sta (abfd, cmd, ptr)
308 bfd *abfd;
309 int cmd;
310 unsigned char *ptr;
313 #if VMS_DEBUG
314 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
315 _bfd_hexdump (8, ptr, 16, (int) ptr);
316 #endif
318 switch (cmd)
320 /* stack */
322 /* stack global
323 arg: cs symbol name
325 stack 32 bit value of symbol (high bits set to 0) */
327 case ETIR_S_C_STA_GBL:
329 char *name;
330 vms_symbol_entry *entry;
332 name = _bfd_vms_save_counted_string (ptr);
333 entry = (vms_symbol_entry *)
334 bfd_hash_lookup (PRIV (vms_symbol_table), name, FALSE, FALSE);
335 if (entry == (vms_symbol_entry *) NULL)
337 #if VMS_DEBUG
338 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
339 cmd_name (cmd), name);
340 #endif
341 _bfd_vms_push (abfd, (uquad) 0, -1);
343 else
345 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
348 break;
350 /* stack longword
351 arg: lw value
353 stack 32 bit value, sign extend to 64 bit */
355 case ETIR_S_C_STA_LW:
356 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
357 break;
359 /* stack global
360 arg: qw value
362 stack 64 bit value of symbol */
364 case ETIR_S_C_STA_QW:
365 _bfd_vms_push (abfd, (uquad) bfd_getl64 (ptr), -1);
366 break;
368 /* stack psect base plus quadword offset
369 arg: lw section index
370 qw signed quadword offset (low 32 bits)
372 stack qw argument and section index
373 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
375 case ETIR_S_C_STA_PQ:
377 uquad dummy;
378 unsigned int psect;
380 psect = bfd_getl32 (ptr);
381 if (psect >= PRIV (section_count))
383 (*_bfd_error_handler) (_("bad section index in %s"),
384 cmd_name (cmd));
385 bfd_set_error (bfd_error_bad_value);
386 return FALSE;
388 dummy = bfd_getl64 (ptr+4);
389 _bfd_vms_push (abfd, dummy, (int) psect);
391 break;
393 case ETIR_S_C_STA_LI:
394 case ETIR_S_C_STA_MOD:
395 case ETIR_S_C_STA_CKARG:
396 (*_bfd_error_handler) (_("unsupported STA cmd %s"), cmd_name (cmd));
397 return FALSE;
398 break;
400 default:
401 (*_bfd_error_handler) (_("reserved STA cmd %d"), cmd);
402 return FALSE;
403 break;
405 #if VMS_DEBUG
406 _bfd_vms_debug (5, "etir_sta true\n");
407 #endif
408 return TRUE;
412 etir_sto
414 vms store commands
416 handle sto_xxx commands in etir section
417 ptr points to data area in record
419 see table B-9 of the openVMS linker manual. */
421 static bfd_boolean
422 etir_sto (abfd, cmd, ptr)
423 bfd *abfd;
424 int cmd;
425 unsigned char *ptr;
427 uquad dummy;
428 int psect;
430 #if VMS_DEBUG
431 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
432 _bfd_hexdump (8, ptr, 16, (int) ptr);
433 #endif
435 switch (cmd)
437 /* store byte: pop stack, write byte
438 arg: - */
440 case ETIR_S_C_STO_B:
441 dummy = _bfd_vms_pop (abfd, &psect);
442 #if 0
443 if (is_share) /* FIXME */
444 (*_bfd_error_handler) ("%s: byte fixups not supported",
445 cmd_name (cmd));
446 #endif
447 /* FIXME: check top bits */
448 image_write_b (abfd, (unsigned int) dummy & 0xff);
449 break;
451 /* store word: pop stack, write word
452 arg: - */
454 case ETIR_S_C_STO_W:
455 dummy = _bfd_vms_pop (abfd, &psect);
456 #if 0
457 if (is_share) /* FIXME */
458 (*_bfd_error_handler) ("%s: word fixups not supported",
459 cmd_name (cmd));
460 #endif
461 /* FIXME: check top bits */
462 image_write_w (abfd, (unsigned int) dummy & 0xffff);
463 break;
465 /* store longword: pop stack, write longword
466 arg: - */
468 case ETIR_S_C_STO_LW:
469 dummy = _bfd_vms_pop (abfd, &psect);
470 dummy += (PRIV (sections)[psect])->vma;
471 /* FIXME: check top bits. */
472 image_write_l (abfd, (unsigned int) dummy & 0xffffffff);
473 break;
475 /* store quadword: pop stack, write quadword
476 arg: - */
478 case ETIR_S_C_STO_QW:
479 dummy = _bfd_vms_pop (abfd, &psect);
480 dummy += (PRIV (sections)[psect])->vma;
481 image_write_q (abfd, dummy); /* FIXME: check top bits */
482 break;
484 /* store immediate repeated: pop stack for repeat count
485 arg: lw byte count
486 da data */
488 case ETIR_S_C_STO_IMMR:
490 int size;
492 size = bfd_getl32 (ptr);
493 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
494 while (dummy-- > 0)
495 image_dump (abfd, ptr+4, size, 0);
497 break;
499 /* store global: write symbol value
500 arg: cs global symbol name. */
502 case ETIR_S_C_STO_GBL:
504 vms_symbol_entry *entry;
505 char *name;
507 name = _bfd_vms_save_counted_string (ptr);
508 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
509 name, FALSE, FALSE);
510 if (entry == (vms_symbol_entry *) NULL)
512 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
513 cmd_name (cmd), name);
514 return FALSE;
516 else
517 /* FIXME, reloc. */
518 image_write_q (abfd, (uquad) (entry->symbol->value));
520 break;
522 /* store code address: write address of entry point
523 arg: cs global symbol name (procedure). */
525 case ETIR_S_C_STO_CA:
527 vms_symbol_entry *entry;
528 char *name;
530 name = _bfd_vms_save_counted_string (ptr);
531 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
532 name, FALSE, FALSE);
533 if (entry == (vms_symbol_entry *) NULL)
535 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
536 cmd_name (cmd), name);
537 return FALSE;
539 else
540 image_write_q (abfd, (uquad) (entry->symbol->value)); /* FIXME, reloc */
542 break;
544 /* Store offset to psect: pop stack, add low 32 bits to base of psect
545 arg: none. */
547 case ETIR_S_C_STO_OFF:
549 uquad q;
550 int psect1;
552 q = _bfd_vms_pop (abfd, &psect1);
553 q += (PRIV (sections)[psect1])->vma;
554 image_write_q (abfd, q);
556 break;
558 /* Store immediate
559 arg: lw count of bytes
560 da data. */
562 case ETIR_S_C_STO_IMM:
564 int size;
566 size = bfd_getl32 (ptr);
567 image_dump (abfd, ptr+4, size, 0);
569 break;
571 /* This code is 'reserved to digital' according to the openVMS
572 linker manual, however it is generated by the DEC C compiler
573 and defined in the include file.
574 FIXME, since the following is just a guess
575 store global longword: store 32bit value of symbol
576 arg: cs symbol name. */
578 case ETIR_S_C_STO_GBL_LW:
580 vms_symbol_entry *entry;
581 char *name;
583 name = _bfd_vms_save_counted_string (ptr);
584 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
585 name, FALSE, FALSE);
586 if (entry == (vms_symbol_entry *) NULL)
588 #if VMS_DEBUG
589 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd), name);
590 #endif
591 image_write_l (abfd, (unsigned long) 0); /* FIXME, reloc */
593 else
594 /* FIXME, reloc. */
595 image_write_l (abfd, (unsigned long) (entry->symbol->value));
597 break;
599 case ETIR_S_C_STO_RB:
600 case ETIR_S_C_STO_AB:
601 case ETIR_S_C_STO_LP_PSB:
602 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
603 break;
605 case ETIR_S_C_STO_HINT_GBL:
606 case ETIR_S_C_STO_HINT_PS:
607 (*_bfd_error_handler) (_("%s: not implemented"), cmd_name (cmd));
608 break;
610 default:
611 (*_bfd_error_handler) (_("reserved STO cmd %d"), cmd);
612 break;
615 return TRUE;
618 /* Stack operator commands
619 all 32 bit signed arithmetic
620 all word just like a stack calculator
621 arguments are popped from stack, results are pushed on stack
623 see table B-10 of the openVMS linker manual. */
625 static bfd_boolean
626 etir_opr (abfd, cmd, ptr)
627 bfd *abfd;
628 int cmd;
629 unsigned char *ptr ATTRIBUTE_UNUSED;
631 long op1, op2;
633 #if VMS_DEBUG
634 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
635 _bfd_hexdump (8, ptr, 16, (int) ptr);
636 #endif
638 switch (cmd)
640 case ETIR_S_C_OPR_NOP: /* no-op */
641 break;
643 case ETIR_S_C_OPR_ADD: /* add */
644 op1 = (long) _bfd_vms_pop (abfd, NULL);
645 op2 = (long) _bfd_vms_pop (abfd, NULL);
646 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
647 break;
649 case ETIR_S_C_OPR_SUB: /* subtract */
650 op1 = (long) _bfd_vms_pop (abfd, NULL);
651 op2 = (long) _bfd_vms_pop (abfd, NULL);
652 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
653 break;
655 case ETIR_S_C_OPR_MUL: /* multiply */
656 op1 = (long) _bfd_vms_pop (abfd, NULL);
657 op2 = (long) _bfd_vms_pop (abfd, NULL);
658 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
659 break;
661 case ETIR_S_C_OPR_DIV: /* divide */
662 op1 = (long) _bfd_vms_pop (abfd, NULL);
663 op2 = (long) _bfd_vms_pop (abfd, NULL);
664 if (op2 == 0)
665 _bfd_vms_push (abfd, (uquad) 0, -1);
666 else
667 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
668 break;
670 case ETIR_S_C_OPR_AND: /* logical and */
671 op1 = (long) _bfd_vms_pop (abfd, NULL);
672 op2 = (long) _bfd_vms_pop (abfd, NULL);
673 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
674 break;
676 case ETIR_S_C_OPR_IOR: /* logical inclusive or */
677 op1 = (long) _bfd_vms_pop (abfd, NULL);
678 op2 = (long) _bfd_vms_pop (abfd, NULL);
679 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
680 break;
682 case ETIR_S_C_OPR_EOR: /* logical exclusive or */
683 op1 = (long) _bfd_vms_pop (abfd, NULL);
684 op2 = (long) _bfd_vms_pop (abfd, NULL);
685 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
686 break;
688 case ETIR_S_C_OPR_NEG: /* negate */
689 op1 = (long) _bfd_vms_pop (abfd, NULL);
690 _bfd_vms_push (abfd, (uquad) (-op1), -1);
691 break;
693 case ETIR_S_C_OPR_COM: /* complement */
694 op1 = (long) _bfd_vms_pop (abfd, NULL);
695 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
696 break;
698 case ETIR_S_C_OPR_ASH: /* arithmetic shift */
699 op1 = (long) _bfd_vms_pop (abfd, NULL);
700 op2 = (long) _bfd_vms_pop (abfd, NULL);
701 if (op2 < 0) /* shift right */
702 op1 >>= -op2;
703 else /* shift left */
704 op1 <<= op2;
705 _bfd_vms_push (abfd, (uquad) op1, -1);
706 break;
708 case ETIR_S_C_OPR_INSV: /* insert field */
709 (void) _bfd_vms_pop (abfd, NULL);
710 case ETIR_S_C_OPR_USH: /* unsigned shift */
711 case ETIR_S_C_OPR_ROT: /* rotate */
712 case ETIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
713 case ETIR_S_C_OPR_DFLIT: /* Define a literal. */
714 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
715 break;
717 case ETIR_S_C_OPR_SEL: /* select */
718 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
719 (void) _bfd_vms_pop (abfd, NULL);
720 else
722 op1 = (long) _bfd_vms_pop (abfd, NULL);
723 (void) _bfd_vms_pop (abfd, NULL);
724 _bfd_vms_push (abfd, (uquad) op1, -1);
726 break;
728 default:
729 (*_bfd_error_handler) (_("reserved OPR cmd %d"), cmd);
730 break;
733 return TRUE;
736 /* Control commands.
738 See table B-11 of the openVMS linker manual. */
740 static bfd_boolean
741 etir_ctl (abfd, cmd, ptr)
742 bfd *abfd;
743 int cmd;
744 unsigned char *ptr;
746 uquad dummy;
747 int psect;
749 #if VMS_DEBUG
750 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
751 _bfd_hexdump (8, ptr, 16, (int) ptr);
752 #endif
754 switch (cmd)
756 /* set relocation base: pop stack, set image location counter
757 arg: none. */
759 case ETIR_S_C_CTL_SETRB:
760 dummy = _bfd_vms_pop (abfd, &psect);
761 image_set_ptr (abfd, psect, dummy);
762 break;
764 /* augment relocation base: increment image location counter by offset
765 arg: lw offset value */
767 case ETIR_S_C_CTL_AUGRB:
768 dummy = bfd_getl32 (ptr);
769 image_inc_ptr (abfd, dummy);
770 break;
772 /* define location: pop index, save location counter under index
773 arg: none. */
775 case ETIR_S_C_CTL_DFLOC:
776 dummy = _bfd_vms_pop (abfd, NULL);
777 /* FIXME */
778 break;
780 /* set location: pop index, restore location counter from index
781 arg: none. */
783 case ETIR_S_C_CTL_STLOC:
784 dummy = _bfd_vms_pop (abfd, &psect);
785 /* FIXME */
786 break;
788 /* stack defined location: pop index, push location counter from index
789 arg: none. */
791 case ETIR_S_C_CTL_STKDL:
792 dummy = _bfd_vms_pop (abfd, &psect);
793 /* FIXME */
794 break;
796 default:
797 (*_bfd_error_handler) (_("reserved CTL cmd %d"), cmd);
798 break;
800 return TRUE;
803 /* store conditional commands
805 See table B-12 and B-13 of the openVMS linker manual. */
807 static bfd_boolean
808 etir_stc (abfd, cmd, ptr)
809 bfd *abfd;
810 int cmd;
811 unsigned char *ptr ATTRIBUTE_UNUSED;
813 #if VMS_DEBUG
814 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
815 _bfd_hexdump (8, ptr, 16, (int) ptr);
816 #endif
818 switch (cmd)
820 /* 200 Store-conditional Linkage Pair
821 arg: none. */
823 case ETIR_S_C_STC_LP:
824 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
825 break;
827 /* 201 Store-conditional Linkage Pair with Procedure Signature
828 arg: lw linkage index
829 cs procedure name
830 by signature length
831 da signature. */
833 case ETIR_S_C_STC_LP_PSB:
834 image_inc_ptr (abfd, (uquad) 16); /* skip entry,procval */
835 break;
837 /* 202 Store-conditional Address at global address
838 arg: lw linkage index
839 cs global name. */
841 case ETIR_S_C_STC_GBL:
842 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
843 break;
845 /* 203 Store-conditional Code Address at global address
846 arg: lw linkage index
847 cs procedure name. */
849 case ETIR_S_C_STC_GCA:
850 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
851 break;
853 /* 204 Store-conditional Address at psect + offset
854 arg: lw linkage index
855 lw psect index
856 qw offset. */
858 case ETIR_S_C_STC_PS:
859 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
860 break;
862 /* 205 Store-conditional NOP at address of global
863 arg: none. */
865 case ETIR_S_C_STC_NOP_GBL:
867 /* 206 Store-conditional NOP at pect + offset
868 arg: none. */
870 case ETIR_S_C_STC_NOP_PS:
872 /* 207 Store-conditional BSR at global address
873 arg: none. */
875 case ETIR_S_C_STC_BSR_GBL:
877 /* 208 Store-conditional BSR at pect + offset
878 arg: none. */
880 case ETIR_S_C_STC_BSR_PS:
882 /* 209 Store-conditional LDA at global address
883 arg: none. */
885 case ETIR_S_C_STC_LDA_GBL:
887 /* 210 Store-conditional LDA at psect + offset
888 arg: none. */
890 case ETIR_S_C_STC_LDA_PS:
892 /* 211 Store-conditional BSR or Hint at global address
893 arg: none. */
895 case ETIR_S_C_STC_BOH_GBL:
897 /* 212 Store-conditional BSR or Hint at pect + offset
898 arg: none. */
900 case ETIR_S_C_STC_BOH_PS:
902 /* 213 Store-conditional NOP,BSR or HINT at global address
903 arg: none. */
905 case ETIR_S_C_STC_NBH_GBL:
907 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
908 arg: none. */
910 case ETIR_S_C_STC_NBH_PS:
911 /* FIXME */
912 #if 0
913 (*_bfd_error_handler) ("%s: not supported", cmd_name (cmd));
914 #endif
915 break;
917 default:
918 #if VMS_DEBUG
919 _bfd_vms_debug (3, "reserved STC cmd %d", cmd);
920 #endif
921 break;
923 return TRUE;
926 static asection *
927 new_section (abfd, idx)
928 bfd *abfd ATTRIBUTE_UNUSED;
929 int idx;
931 asection *section;
932 char sname[16];
933 char *name;
935 #if VMS_DEBUG
936 _bfd_vms_debug (5, "new_section %d\n", idx);
937 #endif
938 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
940 name = bfd_malloc ((bfd_size_type) strlen (sname) + 1);
941 if (name == 0)
942 return 0;
943 strcpy (name, sname);
945 section = bfd_malloc ((bfd_size_type) sizeof (asection));
946 if (section == 0)
948 #if VMS_DEBUG
949 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
950 #endif
951 return 0;
954 section->size = 0;
955 section->vma = 0;
956 section->contents = 0;
957 section->name = name;
958 section->index = idx;
960 return section;
963 static int
964 alloc_section (abfd, idx)
965 bfd *abfd;
966 unsigned int idx;
968 bfd_size_type amt;
970 #if VMS_DEBUG
971 _bfd_vms_debug (4, "alloc_section %d\n", idx);
972 #endif
974 amt = idx + 1;
975 amt *= sizeof (asection *);
976 PRIV (sections) = (asection **) bfd_realloc (PRIV (sections), amt);
977 if (PRIV (sections) == 0)
978 return -1;
980 while (PRIV (section_count) <= idx)
982 PRIV (sections)[PRIV (section_count)]
983 = new_section (abfd, (int) PRIV (section_count));
984 if (PRIV (sections)[PRIV (section_count)] == 0)
985 return -1;
986 PRIV (section_count)++;
989 return 0;
992 /* tir_sta
994 vax stack commands
996 Handle sta_xxx commands in tir section
997 ptr points to data area in record
999 See table 7-3 of the VAX/VMS linker manual. */
1001 static unsigned char *
1002 tir_sta (bfd *abfd, unsigned char *ptr)
1004 int cmd = *ptr++;
1006 #if VMS_DEBUG
1007 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
1008 #endif
1010 switch (cmd)
1012 /* stack */
1013 case TIR_S_C_STA_GBL:
1014 /* stack global
1015 arg: cs symbol name
1017 stack 32 bit value of symbol (high bits set to 0). */
1019 char *name;
1020 vms_symbol_entry *entry;
1022 name = _bfd_vms_save_counted_string (ptr);
1024 entry = _bfd_vms_enter_symbol (abfd, name);
1025 if (entry == (vms_symbol_entry *) NULL)
1026 return 0;
1028 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
1029 ptr += *ptr + 1;
1031 break;
1033 case TIR_S_C_STA_SB:
1034 /* stack signed byte
1035 arg: by value
1037 stack byte value, sign extend to 32 bit. */
1038 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1039 break;
1041 case TIR_S_C_STA_SW:
1042 /* stack signed short word
1043 arg: sh value
1045 stack 16 bit value, sign extend to 32 bit. */
1046 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1047 ptr += 2;
1048 break;
1050 case TIR_S_C_STA_LW:
1051 /* stack signed longword
1052 arg: lw value
1054 stack 32 bit value. */
1055 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
1056 ptr += 4;
1057 break;
1059 case TIR_S_C_STA_PB:
1060 case TIR_S_C_STA_WPB:
1061 /* stack psect base plus byte offset (word index)
1062 arg: by section index
1063 (sh section index)
1064 by signed byte offset. */
1066 unsigned long dummy;
1067 unsigned int psect;
1069 if (cmd == TIR_S_C_STA_PB)
1070 psect = *ptr++;
1071 else
1073 psect = bfd_getl16 (ptr);
1074 ptr += 2;
1077 if (psect >= PRIV (section_count))
1078 alloc_section (abfd, psect);
1080 dummy = (long) *ptr++;
1081 dummy += (PRIV (sections)[psect])->vma;
1082 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1084 break;
1086 case TIR_S_C_STA_PW:
1087 case TIR_S_C_STA_WPW:
1088 /* stack psect base plus word offset (word index)
1089 arg: by section index
1090 (sh section index)
1091 sh signed short offset. */
1093 unsigned long dummy;
1094 unsigned int psect;
1096 if (cmd == TIR_S_C_STA_PW)
1097 psect = *ptr++;
1098 else
1100 psect = bfd_getl16 (ptr);
1101 ptr += 2;
1104 if (psect >= PRIV (section_count))
1105 alloc_section (abfd, psect);
1107 dummy = bfd_getl16 (ptr); ptr+=2;
1108 dummy += (PRIV (sections)[psect])->vma;
1109 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1111 break;
1113 case TIR_S_C_STA_PL:
1114 case TIR_S_C_STA_WPL:
1115 /* stack psect base plus long offset (word index)
1116 arg: by section index
1117 (sh section index)
1118 lw signed longword offset. */
1120 unsigned long dummy;
1121 unsigned int psect;
1123 if (cmd == TIR_S_C_STA_PL)
1124 psect = *ptr++;
1125 else
1127 psect = bfd_getl16 (ptr);
1128 ptr += 2;
1131 if (psect >= PRIV (section_count))
1132 alloc_section (abfd, psect);
1134 dummy = bfd_getl32 (ptr); ptr += 4;
1135 dummy += (PRIV (sections)[psect])->vma;
1136 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1138 break;
1140 case TIR_S_C_STA_UB:
1141 /* stack unsigned byte
1142 arg: by value
1144 stack byte value. */
1145 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1146 break;
1148 case TIR_S_C_STA_UW:
1149 /* stack unsigned short word
1150 arg: sh value
1152 stack 16 bit value. */
1153 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1154 ptr += 2;
1155 break;
1157 case TIR_S_C_STA_BFI:
1158 /* stack byte from image
1159 arg: none. */
1160 /* FALLTHRU */
1161 case TIR_S_C_STA_WFI:
1162 /* stack byte from image
1163 arg: none. */
1164 /* FALLTHRU */
1165 case TIR_S_C_STA_LFI:
1166 /* stack byte from image
1167 arg: none. */
1168 (*_bfd_error_handler) (_("stack-from-image not implemented"));
1169 return NULL;
1171 case TIR_S_C_STA_EPM:
1172 /* stack entry point mask
1173 arg: cs symbol name
1175 stack (unsigned) entry point mask of symbol
1176 err if symbol is no entry point. */
1178 char *name;
1179 vms_symbol_entry *entry;
1181 name = _bfd_vms_save_counted_string (ptr);
1182 entry = _bfd_vms_enter_symbol (abfd, name);
1183 if (entry == (vms_symbol_entry *) NULL)
1184 return 0;
1186 (*_bfd_error_handler) (_("stack-entry-mask not fully implemented"));
1187 _bfd_vms_push (abfd, (uquad) 0, -1);
1188 ptr += *ptr + 1;
1190 break;
1192 case TIR_S_C_STA_CKARG:
1193 /* compare procedure argument
1194 arg: cs symbol name
1195 by argument index
1196 da argument descriptor
1198 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1199 and stack TRUE (args match) or FALSE (args dont match) value. */
1200 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1201 _bfd_vms_push (abfd, (uquad) 1, -1);
1202 break;
1204 case TIR_S_C_STA_LSY:
1205 /* stack local symbol value
1206 arg: sh environment index
1207 cs symbol name. */
1209 int envidx;
1210 char *name;
1211 vms_symbol_entry *entry;
1213 envidx = bfd_getl16 (ptr);
1214 ptr += 2;
1215 name = _bfd_vms_save_counted_string (ptr);
1216 entry = _bfd_vms_enter_symbol (abfd, name);
1217 if (entry == (vms_symbol_entry *) NULL)
1218 return 0;
1219 (*_bfd_error_handler) (_("stack-local-symbol not fully implemented"));
1220 _bfd_vms_push (abfd, (uquad) 0, -1);
1221 ptr += *ptr + 1;
1223 break;
1225 case TIR_S_C_STA_LIT:
1226 /* stack literal
1227 arg: by literal index
1229 stack literal. */
1230 ptr++;
1231 _bfd_vms_push (abfd, (uquad) 0, -1);
1232 (*_bfd_error_handler) (_("stack-literal not fully implemented"));
1233 break;
1235 case TIR_S_C_STA_LEPM:
1236 /* stack local symbol entry point mask
1237 arg: sh environment index
1238 cs symbol name
1240 stack (unsigned) entry point mask of symbol
1241 err if symbol is no entry point. */
1243 int envidx;
1244 char *name;
1245 vms_symbol_entry *entry;
1247 envidx = bfd_getl16 (ptr);
1248 ptr += 2;
1249 name = _bfd_vms_save_counted_string (ptr);
1250 entry = _bfd_vms_enter_symbol (abfd, name);
1251 if (entry == (vms_symbol_entry *) NULL)
1252 return 0;
1253 (*_bfd_error_handler) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1254 _bfd_vms_push (abfd, (uquad) 0, -1);
1255 ptr += *ptr + 1;
1257 break;
1259 default:
1260 (*_bfd_error_handler) (_("reserved STA cmd %d"), ptr[-1]);
1261 return NULL;
1262 break;
1265 return ptr;
1268 static const char *
1269 tir_cmd_name (cmd)
1270 int cmd;
1272 switch (cmd)
1274 case TIR_S_C_STO_RSB: return "TIR_S_C_STO_RSB";
1275 case TIR_S_C_STO_RSW: return "TIR_S_C_STO_RSW";
1276 case TIR_S_C_STO_RL: return "TIR_S_C_STO_RL";
1277 case TIR_S_C_STO_VPS: return "TIR_S_C_STO_VPS";
1278 case TIR_S_C_STO_USB: return "TIR_S_C_STO_USB";
1279 case TIR_S_C_STO_USW: return "TIR_S_C_STO_USW";
1280 case TIR_S_C_STO_RUB: return "TIR_S_C_STO_RUB";
1281 case TIR_S_C_STO_RUW: return "TIR_S_C_STO_RUW";
1282 case TIR_S_C_STO_PIRR: return "TIR_S_C_STO_PIRR";
1283 case TIR_S_C_OPR_INSV: return "TIR_S_C_OPR_INSV";
1284 case TIR_S_C_OPR_DFLIT: return "TIR_S_C_OPR_DFLIT";
1285 case TIR_S_C_OPR_REDEF: return "TIR_S_C_OPR_REDEF";
1286 case TIR_S_C_OPR_ROT: return "TIR_S_C_OPR_ROT";
1287 case TIR_S_C_OPR_USH: return "TIR_S_C_OPR_USH";
1288 case TIR_S_C_OPR_ASH: return "TIR_S_C_OPR_ASH";
1289 case TIR_S_C_CTL_DFLOC: return "TIR_S_C_CTL_DFLOC";
1290 case TIR_S_C_CTL_STLOC: return "TIR_S_C_CTL_STLOC";
1291 case TIR_S_C_CTL_STKDL: return "TIR_S_C_CTL_STKDL";
1293 default:
1294 /* These strings have not been added yet. */
1295 abort ();
1299 /* tir_sto
1301 vax store commands
1303 handle sto_xxx commands in tir section
1304 ptr points to data area in record
1306 See table 7-4 of the VAX/VMS linker manual. */
1308 static unsigned char *
1309 tir_sto (bfd *abfd, unsigned char *ptr)
1311 unsigned long dummy;
1312 int size;
1313 int psect;
1315 #if VMS_DEBUG
1316 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1317 #endif
1319 switch (*ptr++)
1321 case TIR_S_C_STO_SB:
1322 /* store signed byte: pop stack, write byte
1323 arg: none. */
1324 dummy = _bfd_vms_pop (abfd, &psect);
1325 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1326 break;
1328 case TIR_S_C_STO_SW:
1329 /* store signed word: pop stack, write word
1330 arg: none. */
1331 dummy = _bfd_vms_pop (abfd, &psect);
1332 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1333 break;
1335 case TIR_S_C_STO_LW:
1336 /* store longword: pop stack, write longword
1337 arg: none. */
1338 dummy = _bfd_vms_pop (abfd, &psect);
1339 image_write_l (abfd, dummy & 0xffffffff); /* FIXME: check top bits */
1340 break;
1342 case TIR_S_C_STO_BD:
1343 /* store byte displaced: pop stack, sub lc+1, write byte
1344 arg: none. */
1345 dummy = _bfd_vms_pop (abfd, &psect);
1346 dummy -= ((PRIV (sections)[psect])->vma + 1);
1347 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1348 break;
1350 case TIR_S_C_STO_WD:
1351 /* store word displaced: pop stack, sub lc+2, write word
1352 arg: none. */
1353 dummy = _bfd_vms_pop (abfd, &psect);
1354 dummy -= ((PRIV (sections)[psect])->vma + 2);
1355 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1356 break;
1358 case TIR_S_C_STO_LD:
1359 /* store long displaced: pop stack, sub lc+4, write long
1360 arg: none. */
1361 dummy = _bfd_vms_pop (abfd, &psect);
1362 dummy -= ((PRIV (sections)[psect])->vma + 4);
1363 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1364 break;
1366 case TIR_S_C_STO_LI:
1367 /* store short literal: pop stack, write byte
1368 arg: none. */
1369 dummy = _bfd_vms_pop (abfd, &psect);
1370 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1371 break;
1373 case TIR_S_C_STO_PIDR:
1374 /* store position independent data reference: pop stack, write longword
1375 arg: none.
1376 FIXME: incomplete ! */
1377 dummy = _bfd_vms_pop (abfd, &psect);
1378 image_write_l (abfd, dummy & 0xffffffff);
1379 break;
1381 case TIR_S_C_STO_PICR:
1382 /* store position independent code reference: pop stack, write longword
1383 arg: none.
1384 FIXME: incomplete ! */
1385 dummy = _bfd_vms_pop (abfd, &psect);
1386 image_write_b (abfd, 0x9f);
1387 image_write_l (abfd, dummy & 0xffffffff);
1388 break;
1390 case TIR_S_C_STO_RIVB:
1391 /* store repeated immediate variable bytes
1392 1-byte count n field followed by n bytes of data
1393 pop stack, write n bytes <stack> times. */
1394 size = *ptr++;
1395 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1396 while (dummy-- > 0L)
1397 image_dump (abfd, ptr, size, 0);
1398 ptr += size;
1399 break;
1401 case TIR_S_C_STO_B:
1402 /* store byte from top longword. */
1403 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1404 image_write_b (abfd, dummy & 0xff);
1405 break;
1407 case TIR_S_C_STO_W:
1408 /* store word from top longword. */
1409 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1410 image_write_w (abfd, dummy & 0xffff);
1411 break;
1413 case TIR_S_C_STO_RB:
1414 /* store repeated byte from top longword. */
1415 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1416 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1417 while (size-- > 0)
1418 image_write_b (abfd, dummy & 0xff);
1419 break;
1421 case TIR_S_C_STO_RW:
1422 /* store repeated word from top longword. */
1423 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1424 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1425 while (size-- > 0)
1426 image_write_w (abfd, dummy & 0xffff);
1427 break;
1429 case TIR_S_C_STO_RSB:
1430 case TIR_S_C_STO_RSW:
1431 case TIR_S_C_STO_RL:
1432 case TIR_S_C_STO_VPS:
1433 case TIR_S_C_STO_USB:
1434 case TIR_S_C_STO_USW:
1435 case TIR_S_C_STO_RUB:
1436 case TIR_S_C_STO_RUW:
1437 case TIR_S_C_STO_PIRR:
1438 (*_bfd_error_handler) (_("%s: not implemented"), tir_cmd_name (ptr[-1]));
1439 break;
1441 default:
1442 (*_bfd_error_handler) (_("reserved STO cmd %d"), ptr[-1]);
1443 break;
1446 return ptr;
1449 /* stack operator commands
1450 all 32 bit signed arithmetic
1451 all word just like a stack calculator
1452 arguments are popped from stack, results are pushed on stack
1454 See table 7-5 of the VAX/VMS linker manual. */
1456 static unsigned char *
1457 tir_opr (abfd, ptr)
1458 bfd *abfd;
1459 unsigned char *ptr;
1461 long op1, op2;
1463 #if VMS_DEBUG
1464 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1465 #endif
1467 switch (*ptr++)
1469 /* operation */
1470 case TIR_S_C_OPR_NOP: /* no-op */
1471 break;
1473 case TIR_S_C_OPR_ADD: /* add */
1474 op1 = (long) _bfd_vms_pop (abfd, NULL);
1475 op2 = (long) _bfd_vms_pop (abfd, NULL);
1476 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
1477 break;
1479 case TIR_S_C_OPR_SUB: /* subtract */
1480 op1 = (long) _bfd_vms_pop (abfd, NULL);
1481 op2 = (long) _bfd_vms_pop (abfd, NULL);
1482 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
1483 break;
1485 case TIR_S_C_OPR_MUL: /* multiply */
1486 op1 = (long) _bfd_vms_pop (abfd, NULL);
1487 op2 = (long) _bfd_vms_pop (abfd, NULL);
1488 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
1489 break;
1491 case TIR_S_C_OPR_DIV: /* divide */
1492 op1 = (long) _bfd_vms_pop (abfd, NULL);
1493 op2 = (long) _bfd_vms_pop (abfd, NULL);
1494 if (op2 == 0)
1495 _bfd_vms_push (abfd, (uquad) 0, -1);
1496 else
1497 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
1498 break;
1500 case TIR_S_C_OPR_AND: /* logical and */
1501 op1 = (long) _bfd_vms_pop (abfd, NULL);
1502 op2 = (long) _bfd_vms_pop (abfd, NULL);
1503 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
1504 break;
1506 case TIR_S_C_OPR_IOR: /* logical inclusive or */
1507 op1 = (long) _bfd_vms_pop (abfd, NULL);
1508 op2 = (long) _bfd_vms_pop (abfd, NULL);
1509 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
1510 break;
1512 case TIR_S_C_OPR_EOR: /* logical exclusive or */
1513 op1 = (long) _bfd_vms_pop (abfd, NULL);
1514 op2 = (long) _bfd_vms_pop (abfd, NULL);
1515 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
1516 break;
1518 case TIR_S_C_OPR_NEG: /* negate */
1519 op1 = (long) _bfd_vms_pop (abfd, NULL);
1520 _bfd_vms_push (abfd, (uquad) (-op1), -1);
1521 break;
1523 case TIR_S_C_OPR_COM: /* complement */
1524 op1 = (long) _bfd_vms_pop (abfd, NULL);
1525 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
1526 break;
1528 case TIR_S_C_OPR_INSV: /* insert field */
1529 (void) _bfd_vms_pop (abfd, NULL);
1530 (*_bfd_error_handler) (_("%s: not fully implemented"),
1531 tir_cmd_name (ptr[-1]));
1532 break;
1534 case TIR_S_C_OPR_ASH: /* arithmetic shift */
1535 op1 = (long) _bfd_vms_pop (abfd, NULL);
1536 op2 = (long) _bfd_vms_pop (abfd, NULL);
1537 if (HIGHBIT (op1)) /* shift right */
1538 op2 >>= op1;
1539 else /* shift left */
1540 op2 <<= op1;
1541 _bfd_vms_push (abfd, (uquad) op2, -1);
1542 (*_bfd_error_handler) (_("%s: not fully implemented"),
1543 tir_cmd_name (ptr[-1]));
1544 break;
1546 case TIR_S_C_OPR_USH: /* unsigned shift */
1547 op1 = (long) _bfd_vms_pop (abfd, NULL);
1548 op2 = (long) _bfd_vms_pop (abfd, NULL);
1549 if (HIGHBIT (op1)) /* shift right */
1550 op2 >>= op1;
1551 else /* shift left */
1552 op2 <<= op1;
1553 _bfd_vms_push (abfd, (uquad) op2, -1);
1554 (*_bfd_error_handler) (_("%s: not fully implemented"),
1555 tir_cmd_name (ptr[-1]));
1556 break;
1558 case TIR_S_C_OPR_ROT: /* rotate */
1559 op1 = (long) _bfd_vms_pop (abfd, NULL);
1560 op2 = (long) _bfd_vms_pop (abfd, NULL);
1561 if (HIGHBIT (0)) /* shift right */
1562 op2 >>= op1;
1563 else /* shift left */
1564 op2 <<= op1;
1565 _bfd_vms_push (abfd, (uquad) op2, -1);
1566 (*_bfd_error_handler) (_("%s: not fully implemented"),
1567 tir_cmd_name (ptr[-1]));
1568 break;
1570 case TIR_S_C_OPR_SEL: /* select */
1571 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
1572 (void) _bfd_vms_pop (abfd, NULL);
1573 else
1575 op1 = (long) _bfd_vms_pop (abfd, NULL);
1576 (void) _bfd_vms_pop (abfd, NULL);
1577 _bfd_vms_push (abfd, (uquad) op1, -1);
1579 break;
1581 case TIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
1582 case TIR_S_C_OPR_DFLIT: /* Define a literal. */
1583 (*_bfd_error_handler) (_("%s: not supported"),
1584 tir_cmd_name (ptr[-1]));
1585 break;
1587 default:
1588 (*_bfd_error_handler) (_("reserved OPR cmd %d"), ptr[-1]);
1589 break;
1592 return ptr;
1595 /* control commands
1597 See table 7-6 of the VAX/VMS linker manual. */
1599 static unsigned char *
1600 tir_ctl (bfd *abfd, unsigned char *ptr)
1602 unsigned long dummy;
1603 unsigned int psect;
1605 #if VMS_DEBUG
1606 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1607 #endif
1609 switch (*ptr++)
1611 case TIR_S_C_CTL_SETRB:
1612 /* Set relocation base: pop stack, set image location counter
1613 arg: none. */
1614 dummy = _bfd_vms_pop (abfd, &psect);
1615 if (psect >= PRIV (section_count))
1616 alloc_section (abfd, psect);
1617 image_set_ptr (abfd, (int) psect, (uquad) dummy);
1618 break;
1620 case TIR_S_C_CTL_AUGRB:
1621 /* Augment relocation base: increment image location counter by offset
1622 arg: lw offset value. */
1623 dummy = bfd_getl32 (ptr);
1624 image_inc_ptr (abfd, (uquad) dummy);
1625 break;
1627 case TIR_S_C_CTL_DFLOC:
1628 /* Define location: pop index, save location counter under index
1629 arg: none. */
1630 dummy = _bfd_vms_pop (abfd, NULL);
1631 (*_bfd_error_handler) (_("%s: not fully implemented"),
1632 tir_cmd_name (ptr[-1]));
1633 break;
1635 case TIR_S_C_CTL_STLOC:
1636 /* Set location: pop index, restore location counter from index
1637 arg: none. */
1638 dummy = _bfd_vms_pop (abfd, &psect);
1639 (*_bfd_error_handler) (_("%s: not fully implemented"),
1640 tir_cmd_name (ptr[-1]));
1641 break;
1643 case TIR_S_C_CTL_STKDL:
1644 /* Stack defined location: pop index, push location counter from index
1645 arg: none. */
1646 dummy = _bfd_vms_pop (abfd, &psect);
1647 (*_bfd_error_handler) (_("%s: not fully implemented"),
1648 tir_cmd_name (ptr[-1]));
1649 break;
1651 default:
1652 (*_bfd_error_handler) (_("reserved CTL cmd %d"), ptr[-1]);
1653 break;
1655 return ptr;
1658 /* Handle command from TIR section. */
1660 static unsigned char *
1661 tir_cmd (bfd *abfd, unsigned char *ptr)
1663 struct
1665 int mincod;
1666 int maxcod;
1667 unsigned char * (*explain) (bfd *, unsigned char *);
1669 tir_table[] =
1671 { 0, TIR_S_C_MAXSTACOD, tir_sta },
1672 { TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto },
1673 { TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr },
1674 { TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl },
1675 { -1, -1, NULL }
1677 int i = 0;
1679 #if VMS_DEBUG
1680 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1681 _bfd_hexdump (8, ptr, 16, (int) ptr);
1682 #endif
1684 if (*ptr & 0x80) /* store immediate */
1686 i = 128 - (*ptr++ & 0x7f);
1687 image_dump (abfd, ptr, i, 0);
1688 ptr += i;
1690 else
1692 while (tir_table[i].mincod >= 0)
1694 if ( (tir_table[i].mincod <= *ptr)
1695 && (*ptr <= tir_table[i].maxcod))
1697 ptr = tir_table[i].explain (abfd, ptr);
1698 break;
1700 i++;
1702 if (tir_table[i].mincod < 0)
1704 (*_bfd_error_handler) (_("obj code %d not found"), *ptr);
1705 ptr = 0;
1709 return ptr;
1712 /* Handle command from ETIR section. */
1714 static int
1715 etir_cmd (abfd, cmd, ptr)
1716 bfd *abfd;
1717 int cmd;
1718 unsigned char *ptr;
1720 static struct
1722 int mincod;
1723 int maxcod;
1724 bfd_boolean (*explain) PARAMS ((bfd *, int, unsigned char *));
1726 etir_table[] =
1728 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1729 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1730 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1731 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1732 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1733 { -1, -1, NULL }
1736 int i = 0;
1738 #if VMS_DEBUG
1739 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1740 _bfd_hexdump (8, ptr, 16, (int) ptr);
1741 #endif
1743 while (etir_table[i].mincod >= 0)
1745 if ( (etir_table[i].mincod <= cmd)
1746 && (cmd <= etir_table[i].maxcod))
1748 if (!etir_table[i].explain (abfd, cmd, ptr))
1749 return -1;
1750 break;
1752 i++;
1755 #if VMS_DEBUG
1756 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1757 #endif
1758 return 0;
1761 /* Text Information and Relocation Records (OBJ$C_TIR)
1762 handle tir record. */
1764 static int
1765 analyze_tir (abfd, ptr, length)
1766 bfd *abfd;
1767 unsigned char *ptr;
1768 unsigned int length;
1770 unsigned char *maxptr;
1772 #if VMS_DEBUG
1773 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1774 #endif
1776 maxptr = ptr + length;
1778 while (ptr < maxptr)
1780 ptr = tir_cmd (abfd, ptr);
1781 if (ptr == 0)
1782 return -1;
1785 return 0;
1788 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1789 handle etir record. */
1791 static int
1792 analyze_etir (abfd, ptr, length)
1793 bfd *abfd;
1794 unsigned char *ptr;
1795 unsigned int length;
1797 int cmd;
1798 unsigned char *maxptr;
1799 int result = 0;
1801 #if VMS_DEBUG
1802 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1803 #endif
1805 maxptr = ptr + length;
1807 while (ptr < maxptr)
1809 cmd = bfd_getl16 (ptr);
1810 length = bfd_getl16 (ptr + 2);
1811 result = etir_cmd (abfd, cmd, ptr+4);
1812 if (result != 0)
1813 break;
1814 ptr += length;
1817 #if VMS_DEBUG
1818 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1819 #endif
1821 return result;
1824 /* Process ETIR record
1825 Return 0 on success, -1 on error. */
1828 _bfd_vms_slurp_tir (abfd, objtype)
1829 bfd *abfd;
1830 int objtype;
1832 int result;
1834 #if VMS_DEBUG
1835 _bfd_vms_debug (2, "TIR/ETIR\n");
1836 #endif
1838 switch (objtype)
1840 case EOBJ_S_C_ETIR:
1841 PRIV (vms_rec) += 4; /* skip type, size */
1842 PRIV (rec_size) -= 4;
1843 result = analyze_etir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1844 break;
1845 case OBJ_S_C_TIR:
1846 PRIV (vms_rec) += 1; /* skip type */
1847 PRIV (rec_size) -= 1;
1848 result = analyze_tir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1849 break;
1850 default:
1851 result = -1;
1852 break;
1855 return result;
1858 /* Process EDBG record
1859 Return 0 on success, -1 on error
1861 Not implemented yet. */
1864 _bfd_vms_slurp_dbg (abfd, objtype)
1865 bfd *abfd;
1866 int objtype ATTRIBUTE_UNUSED;
1868 #if VMS_DEBUG
1869 _bfd_vms_debug (2, "DBG/EDBG\n");
1870 #endif
1872 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1873 return 0;
1876 /* Process ETBT record
1877 Return 0 on success, -1 on error
1879 Not implemented yet. */
1882 _bfd_vms_slurp_tbt (abfd, objtype)
1883 bfd *abfd ATTRIBUTE_UNUSED;
1884 int objtype ATTRIBUTE_UNUSED;
1886 #if VMS_DEBUG
1887 _bfd_vms_debug (2, "TBT/ETBT\n");
1888 #endif
1890 return 0;
1893 /* Process LNK record
1894 Return 0 on success, -1 on error
1896 Not implemented yet. */
1899 _bfd_vms_slurp_lnk (abfd, objtype)
1900 bfd *abfd ATTRIBUTE_UNUSED;
1901 int objtype ATTRIBUTE_UNUSED;
1903 #if VMS_DEBUG
1904 _bfd_vms_debug (2, "LNK\n");
1905 #endif
1907 return 0;
1910 /* WRITE ETIR SECTION
1912 This is still under construction and therefore not documented. */
1914 static void start_etir_record
1915 PARAMS ((bfd *abfd, int index, uquad offset, bfd_boolean justoffset));
1916 static void sto_imm
1917 PARAMS ((bfd *abfd, vms_section *sptr, bfd_vma vaddr, int index));
1918 static void end_etir_record
1919 PARAMS ((bfd *abfd));
1921 static void
1922 sto_imm (abfd, sptr, vaddr, index)
1923 bfd *abfd;
1924 vms_section *sptr;
1925 bfd_vma vaddr;
1926 int index;
1928 int size;
1929 int ssize;
1930 unsigned char *cptr;
1932 #if VMS_DEBUG
1933 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
1934 _bfd_hexdump (9, sptr->contents, (int) sptr->size, (int) vaddr);
1935 #endif
1937 ssize = sptr->size;
1938 cptr = sptr->contents;
1940 while (ssize > 0)
1942 size = ssize; /* try all the rest */
1944 if (_bfd_vms_output_check (abfd, size) < 0)
1945 { /* doesn't fit, split ! */
1946 end_etir_record (abfd);
1947 start_etir_record (abfd, index, vaddr, FALSE);
1948 size = _bfd_vms_output_check (abfd, 0); /* get max size */
1949 if (size > ssize) /* more than what's left ? */
1950 size = ssize;
1953 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
1954 _bfd_vms_output_long (abfd, (unsigned long) (size));
1955 _bfd_vms_output_dump (abfd, cptr, size);
1956 _bfd_vms_output_flush (abfd);
1958 #if VMS_DEBUG
1959 _bfd_vms_debug (10, "dumped %d bytes\n", size);
1960 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
1961 #endif
1963 vaddr += size;
1964 ssize -= size;
1965 cptr += size;
1969 /* Start ETIR record for section #index at virtual addr offset. */
1971 static void
1972 start_etir_record (abfd, index, offset, justoffset)
1973 bfd *abfd;
1974 int index;
1975 uquad offset;
1976 bfd_boolean justoffset;
1978 if (!justoffset)
1980 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
1981 _bfd_vms_output_push (abfd);
1984 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
1985 _bfd_vms_output_long (abfd, (unsigned long) index);
1986 _bfd_vms_output_quad (abfd, (uquad) offset);
1987 _bfd_vms_output_flush (abfd);
1989 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop () */
1990 _bfd_vms_output_flush (abfd);
1993 /* End etir record. */
1995 static void
1996 end_etir_record (abfd)
1997 bfd *abfd;
1999 _bfd_vms_output_pop (abfd);
2000 _bfd_vms_output_end (abfd);
2003 /* Write section contents for bfd abfd. */
2006 _bfd_vms_write_tir (abfd, objtype)
2007 bfd *abfd;
2008 int objtype ATTRIBUTE_UNUSED;
2010 asection *section;
2011 vms_section *sptr;
2012 int nextoffset;
2014 #if VMS_DEBUG
2015 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
2016 #endif
2018 _bfd_vms_output_alignment (abfd, 4);
2020 nextoffset = 0;
2021 PRIV (vms_linkage_index) = 1;
2023 /* Dump all other sections. */
2025 section = abfd->sections;
2027 while (section != NULL)
2030 #if VMS_DEBUG
2031 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2032 section->index, section->name,
2033 (int) (section->size));
2034 #endif
2036 if (section->flags & SEC_RELOC)
2038 int i;
2040 if ((i = section->reloc_count) <= 0)
2042 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
2043 section->name);
2045 #if VMS_DEBUG
2046 else
2048 arelent **rptr;
2049 _bfd_vms_debug (4, "%d relocations:\n", i);
2050 rptr = section->orelocation;
2051 while (i-- > 0)
2053 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2054 (*(*rptr)->sym_ptr_ptr)->name,
2055 (*(*rptr)->sym_ptr_ptr)->section->name,
2056 (long) (*(*rptr)->sym_ptr_ptr)->value,
2057 (*rptr)->address, (*rptr)->addend,
2058 bfd_get_reloc_size ((*rptr)->howto),
2059 (*rptr)->howto->name);
2060 rptr++;
2063 #endif
2066 if ((section->flags & SEC_HAS_CONTENTS)
2067 && (! bfd_is_com_section (section)))
2069 bfd_vma vaddr; /* Virtual addr in section. */
2071 sptr = _bfd_get_vms_section (abfd, section->index);
2072 if (sptr == NULL)
2074 bfd_set_error (bfd_error_no_contents);
2075 return -1;
2078 vaddr = (bfd_vma) (sptr->offset);
2080 start_etir_record (abfd, section->index, (uquad) sptr->offset,
2081 FALSE);
2083 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per vms_section */
2086 if (section->flags & SEC_RELOC) /* check for relocs */
2088 arelent **rptr = section->orelocation;
2089 int i = section->reloc_count;
2091 for (;;)
2093 bfd_size_type addr = (*rptr)->address;
2094 bfd_size_type len = bfd_get_reloc_size ((*rptr)->howto);
2095 if (sptr->offset < addr) /* sptr starts before reloc */
2097 bfd_size_type before = addr - sptr->offset;
2098 if (sptr->size <= before) /* complete before */
2100 sto_imm (abfd, sptr, vaddr, section->index);
2101 vaddr += sptr->size;
2102 break;
2104 else /* partly before */
2106 int after = sptr->size - before;
2107 sptr->size = before;
2108 sto_imm (abfd, sptr, vaddr, section->index);
2109 vaddr += sptr->size;
2110 sptr->contents += before;
2111 sptr->offset += before;
2112 sptr->size = after;
2115 else if (sptr->offset == addr) /* sptr starts at reloc */
2117 asymbol *sym = *(*rptr)->sym_ptr_ptr;
2118 asection *sec = sym->section;
2120 switch ((*rptr)->howto->type)
2122 case ALPHA_R_IGNORE:
2123 break;
2125 case ALPHA_R_REFLONG:
2127 if (bfd_is_und_section (sym->section))
2129 int slen = strlen ((char *) sym->name);
2130 char *hash;
2132 if (_bfd_vms_output_check (abfd, slen) < 0)
2134 end_etir_record (abfd);
2135 start_etir_record (abfd,
2136 section->index,
2137 vaddr, FALSE);
2139 _bfd_vms_output_begin (abfd,
2140 ETIR_S_C_STO_GBL_LW,
2141 -1);
2142 hash = (_bfd_vms_length_hash_symbol
2143 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2144 _bfd_vms_output_counted (abfd, hash);
2145 _bfd_vms_output_flush (abfd);
2147 else if (bfd_is_abs_section (sym->section))
2149 if (_bfd_vms_output_check (abfd, 16) < 0)
2151 end_etir_record (abfd);
2152 start_etir_record (abfd,
2153 section->index,
2154 vaddr, FALSE);
2156 _bfd_vms_output_begin (abfd,
2157 ETIR_S_C_STA_LW,
2158 -1);
2159 _bfd_vms_output_quad (abfd,
2160 (uquad) sym->value);
2161 _bfd_vms_output_flush (abfd);
2162 _bfd_vms_output_begin (abfd,
2163 ETIR_S_C_STO_LW,
2164 -1);
2165 _bfd_vms_output_flush (abfd);
2167 else
2169 if (_bfd_vms_output_check (abfd, 32) < 0)
2171 end_etir_record (abfd);
2172 start_etir_record (abfd,
2173 section->index,
2174 vaddr, FALSE);
2176 _bfd_vms_output_begin (abfd,
2177 ETIR_S_C_STA_PQ,
2178 -1);
2179 _bfd_vms_output_long (abfd,
2180 (unsigned long) (sec->index));
2181 _bfd_vms_output_quad (abfd,
2182 ((uquad) (*rptr)->addend
2183 + (uquad) sym->value));
2184 _bfd_vms_output_flush (abfd);
2185 _bfd_vms_output_begin (abfd,
2186 ETIR_S_C_STO_LW,
2187 -1);
2188 _bfd_vms_output_flush (abfd);
2191 break;
2193 case ALPHA_R_REFQUAD:
2195 if (bfd_is_und_section (sym->section))
2197 int slen = strlen ((char *) sym->name);
2198 char *hash;
2199 if (_bfd_vms_output_check (abfd, slen) < 0)
2201 end_etir_record (abfd);
2202 start_etir_record (abfd,
2203 section->index,
2204 vaddr, FALSE);
2206 _bfd_vms_output_begin (abfd,
2207 ETIR_S_C_STO_GBL,
2208 -1);
2209 hash = (_bfd_vms_length_hash_symbol
2210 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2211 _bfd_vms_output_counted (abfd, hash);
2212 _bfd_vms_output_flush (abfd);
2214 else if (bfd_is_abs_section (sym->section))
2216 if (_bfd_vms_output_check (abfd, 16) < 0)
2218 end_etir_record (abfd);
2219 start_etir_record (abfd,
2220 section->index,
2221 vaddr, FALSE);
2223 _bfd_vms_output_begin (abfd,
2224 ETIR_S_C_STA_QW,
2225 -1);
2226 _bfd_vms_output_quad (abfd,
2227 (uquad) sym->value);
2228 _bfd_vms_output_flush (abfd);
2229 _bfd_vms_output_begin (abfd,
2230 ETIR_S_C_STO_QW,
2231 -1);
2232 _bfd_vms_output_flush (abfd);
2234 else
2236 if (_bfd_vms_output_check (abfd, 32) < 0)
2238 end_etir_record (abfd);
2239 start_etir_record (abfd,
2240 section->index,
2241 vaddr, FALSE);
2243 _bfd_vms_output_begin (abfd,
2244 ETIR_S_C_STA_PQ,
2245 -1);
2246 _bfd_vms_output_long (abfd,
2247 (unsigned long) (sec->index));
2248 _bfd_vms_output_quad (abfd,
2249 ((uquad) (*rptr)->addend
2250 + (uquad) sym->value));
2251 _bfd_vms_output_flush (abfd);
2252 _bfd_vms_output_begin (abfd,
2253 ETIR_S_C_STO_OFF,
2254 -1);
2255 _bfd_vms_output_flush (abfd);
2258 break;
2260 case ALPHA_R_HINT:
2262 int hint_size;
2263 char *hash ATTRIBUTE_UNUSED;
2265 hint_size = sptr->size;
2266 sptr->size = len;
2267 sto_imm (abfd, sptr, vaddr, section->index);
2268 sptr->size = hint_size;
2269 #if 0
2270 vms_output_begin (abfd,
2271 ETIR_S_C_STO_HINT_GBL, -1);
2272 vms_output_long (abfd,
2273 (unsigned long) (sec->index));
2274 vms_output_quad (abfd, (uquad) addr);
2276 hash = (_bfd_vms_length_hash_symbol
2277 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2278 vms_output_counted (abfd, hash);
2280 vms_output_flush (abfd);
2281 #endif
2283 break;
2284 case ALPHA_R_LINKAGE:
2286 char *hash;
2288 if (_bfd_vms_output_check (abfd, 64) < 0)
2290 end_etir_record (abfd);
2291 start_etir_record (abfd, section->index,
2292 vaddr, FALSE);
2294 _bfd_vms_output_begin (abfd,
2295 ETIR_S_C_STC_LP_PSB,
2296 -1);
2297 _bfd_vms_output_long (abfd,
2298 (unsigned long) PRIV (vms_linkage_index));
2299 PRIV (vms_linkage_index) += 2;
2300 hash = (_bfd_vms_length_hash_symbol
2301 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2302 _bfd_vms_output_counted (abfd, hash);
2303 _bfd_vms_output_byte (abfd, 0);
2304 _bfd_vms_output_flush (abfd);
2306 break;
2308 case ALPHA_R_CODEADDR:
2310 int slen = strlen ((char *) sym->name);
2311 char *hash;
2312 if (_bfd_vms_output_check (abfd, slen) < 0)
2314 end_etir_record (abfd);
2315 start_etir_record (abfd,
2316 section->index,
2317 vaddr, FALSE);
2319 _bfd_vms_output_begin (abfd,
2320 ETIR_S_C_STO_CA,
2321 -1);
2322 hash = (_bfd_vms_length_hash_symbol
2323 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2324 _bfd_vms_output_counted (abfd, hash);
2325 _bfd_vms_output_flush (abfd);
2327 break;
2329 default:
2330 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2331 (*rptr)->howto->name);
2332 break;
2335 vaddr += len;
2337 if (len == sptr->size)
2339 break;
2341 else
2343 sptr->contents += len;
2344 sptr->offset += len;
2345 sptr->size -= len;
2346 i--;
2347 rptr++;
2350 else /* sptr starts after reloc */
2352 i--; /* check next reloc */
2353 rptr++;
2356 if (i==0) /* all reloc checked */
2358 if (sptr->size > 0)
2360 /* dump rest */
2361 sto_imm (abfd, sptr, vaddr, section->index);
2362 vaddr += sptr->size;
2364 break;
2366 } /* for (;;) */
2367 } /* if SEC_RELOC */
2368 else /* no relocs, just dump */
2370 sto_imm (abfd, sptr, vaddr, section->index);
2371 vaddr += sptr->size;
2374 sptr = sptr->next;
2376 } /* while (sptr != 0) */
2378 end_etir_record (abfd);
2380 } /* has_contents */
2382 section = section->next;
2385 _bfd_vms_output_alignment (abfd, 2);
2386 return 0;
2389 /* Write traceback data for bfd abfd. */
2392 _bfd_vms_write_tbt (abfd, objtype)
2393 bfd *abfd ATTRIBUTE_UNUSED;
2394 int objtype ATTRIBUTE_UNUSED;
2396 #if VMS_DEBUG
2397 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2398 #endif
2400 return 0;
2403 /* Write debug info for bfd abfd. */
2406 _bfd_vms_write_dbg (abfd, objtype)
2407 bfd *abfd ATTRIBUTE_UNUSED;
2408 int objtype ATTRIBUTE_UNUSED;
2410 #if VMS_DEBUG
2411 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);
2412 #endif
2414 return 0;