2002-09-29 Andrew Cagney <ac131313@redhat.com>
[binutils.git] / bfd / vms-tir.c
blob8e9eef41e12c2f66c107022c327cf953f44d3564
1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 TIR record handling functions
7 ETIR record handling functions
9 go and read the openVMS linker manual (esp. appendix B)
10 if you don't know what's going on here :-)
12 Written by Klaus K"ampf (kkaempf@rmi.de)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* The following type abbreviations are used:
30 cs counted string (ascii string with length byte)
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 PARAMS ((bfd *abfd, int psect, uquad offset));
45 static void image_inc_ptr PARAMS ((bfd *abfd, uquad offset));
46 static void image_dump PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
47 static void image_write_b PARAMS ((bfd *abfd, unsigned int value));
48 static void image_write_w PARAMS ((bfd *abfd, unsigned int value));
49 static void image_write_l PARAMS ((bfd *abfd, unsigned long value));
50 static void image_write_q PARAMS ((bfd *abfd, uquad value));
51 static int check_section PARAMS ((bfd *, int));
52 static boolean etir_sta PARAMS ((bfd *, int, unsigned char *));
53 static boolean etir_sto PARAMS ((bfd *, int, unsigned char *));
54 static boolean etir_opr PARAMS ((bfd *, int, unsigned char *));
55 static boolean etir_ctl PARAMS ((bfd *, int, unsigned char *));
56 static boolean etir_stc PARAMS ((bfd *, int, unsigned char *));
57 static asection *new_section PARAMS ((bfd *, int));
58 static int alloc_section PARAMS ((bfd *, unsigned int));
59 static int etir_cmd PARAMS ((bfd *, int, unsigned char *));
60 static int analyze_tir PARAMS ((bfd *, unsigned char *, unsigned int));
61 static int analyze_etir PARAMS ((bfd *, unsigned char *, unsigned int));
62 static unsigned char * tir_opr PARAMS ((bfd *, unsigned char *));
63 static const char * tir_cmd_name PARAMS ((int));
64 static const char * cmd_name PARAMS ((int));
67 static int
68 check_section (abfd, size)
69 bfd *abfd;
70 int size;
72 bfd_size_type offset;
74 offset = PRIV (image_ptr) - PRIV (image_section)->contents;
75 if (offset + size > PRIV (image_section)->_raw_size)
77 PRIV (image_section)->contents
78 = bfd_realloc (PRIV (image_section)->contents, offset + size);
79 if (PRIV (image_section)->contents == 0)
81 (*_bfd_error_handler) (_("No Mem !"));
82 return -1;
84 PRIV (image_section)->_raw_size = offset + size;
85 PRIV (image_ptr) = PRIV (image_section)->contents + offset;
88 return 0;
91 /* Routines to fill sections contents during tir/etir read. */
93 /* Initialize image buffer pointer to be filled. */
95 static void
96 image_set_ptr (abfd, psect, offset)
97 bfd *abfd;
98 int psect;
99 uquad offset;
101 #if VMS_DEBUG
102 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
103 psect, PRIV (sections)[psect]->name, offset);
104 #endif
106 PRIV (image_ptr) = PRIV (sections)[psect]->contents + offset;
107 PRIV (image_section) = PRIV (sections)[psect];
108 return;
111 /* Increment image buffer pointer by offset. */
113 static void
114 image_inc_ptr (abfd, offset)
115 bfd *abfd;
116 uquad offset;
118 #if VMS_DEBUG
119 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
120 #endif
122 PRIV (image_ptr) += offset;
124 return;
127 /* Dump multiple bytes to section image. */
129 static void
130 image_dump (abfd, ptr, size, offset)
131 bfd *abfd;
132 unsigned char *ptr;
133 int size;
134 int offset ATTRIBUTE_UNUSED;
136 #if VMS_DEBUG
137 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size,
138 PRIV (image_ptr));
139 _bfd_hexdump (9, ptr, size, offset);
140 #endif
142 if (PRIV (is_vax) && check_section (abfd, size))
143 return;
145 while (size-- > 0)
146 *PRIV (image_ptr)++ = *ptr++;
147 return;
150 /* Write byte to section image. */
152 static void
153 image_write_b (abfd, value)
154 bfd *abfd;
155 unsigned int value;
157 #if VMS_DEBUG
158 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int) value);
159 #endif
161 if (PRIV (is_vax) && check_section (abfd, 1))
162 return;
164 *PRIV (image_ptr)++ = (value & 0xff);
165 return;
168 /* Write 2-byte word to image. */
170 static void
171 image_write_w (abfd, value)
172 bfd *abfd;
173 unsigned int value;
175 #if VMS_DEBUG
176 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int) value);
177 #endif
179 if (PRIV (is_vax) && check_section (abfd, 2))
180 return;
182 bfd_putl16 ((bfd_vma) value, PRIV (image_ptr));
183 PRIV (image_ptr) += 2;
185 return;
188 /* Write 4-byte long to image. */
190 static void
191 image_write_l (abfd, value)
192 bfd *abfd;
193 unsigned long value;
195 #if VMS_DEBUG
196 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
197 #endif
199 if (PRIV (is_vax) && check_section (abfd, 4))
200 return;
202 bfd_putl32 ((bfd_vma) value, PRIV (image_ptr));
203 PRIV (image_ptr) += 4;
205 return;
208 /* Write 8-byte quad to image. */
210 static void
211 image_write_q (abfd, value)
212 bfd *abfd;
213 uquad value;
215 #if VMS_DEBUG
216 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
217 #endif
219 if (PRIV (is_vax) && check_section (abfd, 8))
220 return;
222 bfd_putl64 (value, PRIV (image_ptr));
223 PRIV (image_ptr) += 8;
225 return;
228 static const char *
229 cmd_name (cmd)
230 int cmd;
232 switch (cmd)
234 case ETIR_S_C_STA_GBL: return "ETIR_S_C_STA_GBL";
235 case ETIR_S_C_STA_PQ: return "ETIR_S_C_STA_PQ";
236 case ETIR_S_C_STA_LI: return "ETIR_S_C_STA_LI";
237 case ETIR_S_C_STA_MOD: return "ETIR_S_C_STA_MOD";
238 case ETIR_S_C_STA_CKARG: return "ETIR_S_C_STA_CKARG";
239 case ETIR_S_C_STO_B: return "ETIR_S_C_STO_B";
240 case ETIR_S_C_STO_W: return "ETIR_S_C_STO_W";
241 case ETIR_S_C_STO_GBL: return "ETIR_S_C_STO_GBL";
242 case ETIR_S_C_STO_CA: return "ETIR_S_C_STO_CA";
243 case ETIR_S_C_STO_RB: return "ETIR_S_C_STO_RB";
244 case ETIR_S_C_STO_AB: return "ETIR_S_C_STO_AB";
245 case ETIR_S_C_STO_GBL_LW: return "ETIR_S_C_STO_GBL_LW";
246 case ETIR_S_C_STO_LP_PSB: return "ETIR_S_C_STO_LP_PSB";
247 case ETIR_S_C_STO_HINT_GBL: return "ETIR_S_C_STO_HINT_GBL";
248 case ETIR_S_C_STO_HINT_PS: return "ETIR_S_C_STO_HINT_PS";
249 case ETIR_S_C_OPR_INSV: return "ETIR_S_C_OPR_INSV";
250 case ETIR_S_C_OPR_USH: return "ETIR_S_C_OPR_USH";
251 case ETIR_S_C_OPR_ROT: return "ETIR_S_C_OPR_ROT";
252 case ETIR_S_C_OPR_REDEF: return "ETIR_S_C_OPR_REDEF";
253 case ETIR_S_C_OPR_DFLIT: return "ETIR_S_C_OPR_DFLIT";
254 case ETIR_S_C_STC_LP: return "ETIR_S_C_STC_LP";
255 case ETIR_S_C_STC_GBL: return "ETIR_S_C_STC_GBL";
256 case ETIR_S_C_STC_GCA: return "ETIR_S_C_STC_GCA";
257 case ETIR_S_C_STC_PS: return "ETIR_S_C_STC_PS";
258 case ETIR_S_C_STC_NBH_PS: return "ETIR_S_C_STC_NBH_PS";
259 case ETIR_S_C_STC_NOP_GBL: return "ETIR_S_C_STC_NOP_GBL";
260 case ETIR_S_C_STC_NOP_PS: return "ETIR_S_C_STC_NOP_PS";
261 case ETIR_S_C_STC_BSR_GBL: return "ETIR_S_C_STC_BSR_GBL";
262 case ETIR_S_C_STC_BSR_PS: return "ETIR_S_C_STC_BSR_PS";
263 case ETIR_S_C_STC_LDA_GBL: return "ETIR_S_C_STC_LDA_GBL";
264 case ETIR_S_C_STC_LDA_PS: return "ETIR_S_C_STC_LDA_PS";
265 case ETIR_S_C_STC_BOH_GBL: return "ETIR_S_C_STC_BOH_GBL";
266 case ETIR_S_C_STC_BOH_PS: return "ETIR_S_C_STC_BOH_PS";
267 case ETIR_S_C_STC_NBH_GBL: return "ETIR_S_C_STC_NBH_GBL";
269 default:
270 /* These names have not yet been added to this switch statement. */
271 abort ();
274 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
276 /* etir_sta
278 vms stack commands
280 handle sta_xxx commands in etir section
281 ptr points to data area in record
283 see table B-8 of the openVMS linker manual. */
285 static boolean
286 etir_sta (abfd, cmd, ptr)
287 bfd *abfd;
288 int cmd;
289 unsigned char *ptr;
292 #if VMS_DEBUG
293 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
294 _bfd_hexdump (8, ptr, 16, (int) ptr);
295 #endif
297 switch (cmd)
299 /* stack */
301 /* stack global
302 arg: cs symbol name
304 stack 32 bit value of symbol (high bits set to 0) */
306 case ETIR_S_C_STA_GBL:
308 char *name;
309 vms_symbol_entry *entry;
311 name = _bfd_vms_save_counted_string (ptr);
312 entry = (vms_symbol_entry *)
313 bfd_hash_lookup (PRIV (vms_symbol_table), name, false, false);
314 if (entry == (vms_symbol_entry *) NULL)
316 #if VMS_DEBUG
317 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n",
318 cmd_name (cmd), name);
319 #endif
320 _bfd_vms_push (abfd, (uquad) 0, -1);
322 else
324 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
327 break;
329 /* stack longword
330 arg: lw value
332 stack 32 bit value, sign extend to 64 bit */
334 case ETIR_S_C_STA_LW:
335 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
336 break;
338 /* stack global
339 arg: qw value
341 stack 64 bit value of symbol */
343 case ETIR_S_C_STA_QW:
344 _bfd_vms_push (abfd, (uquad) bfd_getl64 (ptr), -1);
345 break;
347 /* stack psect base plus quadword offset
348 arg: lw section index
349 qw signed quadword offset (low 32 bits)
351 stack qw argument and section index
352 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
354 case ETIR_S_C_STA_PQ:
356 uquad dummy;
357 unsigned int psect;
359 psect = bfd_getl32 (ptr);
360 if (psect >= PRIV (section_count))
362 (*_bfd_error_handler) (_("bad section index in %s"),
363 cmd_name (cmd));
364 bfd_set_error (bfd_error_bad_value);
365 return false;
367 dummy = bfd_getl64 (ptr+4);
368 _bfd_vms_push (abfd, dummy, (int) psect);
370 break;
372 case ETIR_S_C_STA_LI:
373 case ETIR_S_C_STA_MOD:
374 case ETIR_S_C_STA_CKARG:
375 (*_bfd_error_handler) (_("unsupported STA cmd %s"), cmd_name (cmd));
376 return false;
377 break;
379 default:
380 (*_bfd_error_handler) (_("reserved STA cmd %d"), cmd);
381 return false;
382 break;
384 #if VMS_DEBUG
385 _bfd_vms_debug (5, "etir_sta true\n");
386 #endif
387 return true;
391 etir_sto
393 vms store commands
395 handle sto_xxx commands in etir section
396 ptr points to data area in record
398 see table B-9 of the openVMS linker manual. */
400 static boolean
401 etir_sto (abfd, cmd, ptr)
402 bfd *abfd;
403 int cmd;
404 unsigned char *ptr;
406 uquad dummy;
407 int psect;
409 #if VMS_DEBUG
410 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
411 _bfd_hexdump (8, ptr, 16, (int) ptr);
412 #endif
414 switch (cmd)
416 /* store byte: pop stack, write byte
417 arg: - */
419 case ETIR_S_C_STO_B:
420 dummy = _bfd_vms_pop (abfd, &psect);
421 #if 0
422 if (is_share) /* FIXME */
423 (*_bfd_error_handler) ("%s: byte fixups not supported",
424 cmd_name (cmd));
425 #endif
426 /* FIXME: check top bits */
427 image_write_b (abfd, (unsigned int) dummy & 0xff);
428 break;
430 /* store word: pop stack, write word
431 arg: - */
433 case ETIR_S_C_STO_W:
434 dummy = _bfd_vms_pop (abfd, &psect);
435 #if 0
436 if (is_share) /* FIXME */
437 (*_bfd_error_handler) ("%s: word fixups not supported",
438 cmd_name (cmd));
439 #endif
440 /* FIXME: check top bits */
441 image_write_w (abfd, (unsigned int) dummy & 0xffff);
442 break;
444 /* store longword: pop stack, write longword
445 arg: - */
447 case ETIR_S_C_STO_LW:
448 dummy = _bfd_vms_pop (abfd, &psect);
449 dummy += (PRIV (sections)[psect])->vma;
450 /* FIXME: check top bits. */
451 image_write_l (abfd, (unsigned int) dummy & 0xffffffff);
452 break;
454 /* store quadword: pop stack, write quadword
455 arg: - */
457 case ETIR_S_C_STO_QW:
458 dummy = _bfd_vms_pop (abfd, &psect);
459 dummy += (PRIV (sections)[psect])->vma;
460 image_write_q (abfd, dummy); /* FIXME: check top bits */
461 break;
463 /* store immediate repeated: pop stack for repeat count
464 arg: lw byte count
465 da data */
467 case ETIR_S_C_STO_IMMR:
469 int size;
471 size = bfd_getl32 (ptr);
472 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
473 while (dummy-- > 0)
474 image_dump (abfd, ptr+4, size, 0);
476 break;
478 /* store global: write symbol value
479 arg: cs global symbol name. */
481 case ETIR_S_C_STO_GBL:
483 vms_symbol_entry *entry;
484 char *name;
486 name = _bfd_vms_save_counted_string (ptr);
487 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
488 name, false, false);
489 if (entry == (vms_symbol_entry *) NULL)
491 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
492 cmd_name (cmd), name);
493 return false;
495 else
496 /* FIXME, reloc. */
497 image_write_q (abfd, (uquad) (entry->symbol->value));
499 break;
501 /* store code address: write address of entry point
502 arg: cs global symbol name (procedure). */
504 case ETIR_S_C_STO_CA:
506 vms_symbol_entry *entry;
507 char *name;
509 name = _bfd_vms_save_counted_string (ptr);
510 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
511 name, false, false);
512 if (entry == (vms_symbol_entry *) NULL)
514 (*_bfd_error_handler) (_("%s: no symbol \"%s\""),
515 cmd_name (cmd), name);
516 return false;
518 else
519 image_write_q (abfd, (uquad) (entry->symbol->value)); /* FIXME, reloc */
521 break;
523 /* Store offset to psect: pop stack, add low 32 bits to base of psect
524 arg: none. */
526 case ETIR_S_C_STO_OFF:
528 uquad q;
529 int psect1;
531 q = _bfd_vms_pop (abfd, &psect1);
532 q += (PRIV (sections)[psect1])->vma;
533 image_write_q (abfd, q);
535 break;
537 /* Store immediate
538 arg: lw count of bytes
539 da data. */
541 case ETIR_S_C_STO_IMM:
543 int size;
545 size = bfd_getl32 (ptr);
546 image_dump (abfd, ptr+4, size, 0);
548 break;
550 /* This code is 'reserved to digital' according to the openVMS
551 linker manual, however it is generated by the DEC C compiler
552 and defined in the include file.
553 FIXME, since the following is just a guess
554 store global longword: store 32bit value of symbol
555 arg: cs symbol name. */
557 case ETIR_S_C_STO_GBL_LW:
559 vms_symbol_entry *entry;
560 char *name;
562 name = _bfd_vms_save_counted_string (ptr);
563 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV (vms_symbol_table),
564 name, false, false);
565 if (entry == (vms_symbol_entry *) NULL)
567 #if VMS_DEBUG
568 _bfd_vms_debug (3, "%s: no symbol \"%s\"\n", cmd_name (cmd), name);
569 #endif
570 image_write_l (abfd, (unsigned long) 0); /* FIXME, reloc */
572 else
573 /* FIXME, reloc. */
574 image_write_l (abfd, (unsigned long) (entry->symbol->value));
576 break;
578 case ETIR_S_C_STO_RB:
579 case ETIR_S_C_STO_AB:
580 case ETIR_S_C_STO_LP_PSB:
581 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
582 break;
584 case ETIR_S_C_STO_HINT_GBL:
585 case ETIR_S_C_STO_HINT_PS:
586 (*_bfd_error_handler) (_("%s: not implemented"), cmd_name (cmd));
587 break;
589 default:
590 (*_bfd_error_handler) (_("reserved STO cmd %d"), cmd);
591 break;
594 return true;
597 /* Stack operator commands
598 all 32 bit signed arithmetic
599 all word just like a stack calculator
600 arguments are popped from stack, results are pushed on stack
602 see table B-10 of the openVMS linker manual. */
604 static boolean
605 etir_opr (abfd, cmd, ptr)
606 bfd *abfd;
607 int cmd;
608 unsigned char *ptr ATTRIBUTE_UNUSED;
610 long op1, op2;
612 #if VMS_DEBUG
613 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
614 _bfd_hexdump (8, ptr, 16, (int) ptr);
615 #endif
617 switch (cmd)
619 case ETIR_S_C_OPR_NOP: /* no-op */
620 break;
622 case ETIR_S_C_OPR_ADD: /* add */
623 op1 = (long) _bfd_vms_pop (abfd, NULL);
624 op2 = (long) _bfd_vms_pop (abfd, NULL);
625 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
626 break;
628 case ETIR_S_C_OPR_SUB: /* subtract */
629 op1 = (long) _bfd_vms_pop (abfd, NULL);
630 op2 = (long) _bfd_vms_pop (abfd, NULL);
631 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
632 break;
634 case ETIR_S_C_OPR_MUL: /* multiply */
635 op1 = (long) _bfd_vms_pop (abfd, NULL);
636 op2 = (long) _bfd_vms_pop (abfd, NULL);
637 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
638 break;
640 case ETIR_S_C_OPR_DIV: /* divide */
641 op1 = (long) _bfd_vms_pop (abfd, NULL);
642 op2 = (long) _bfd_vms_pop (abfd, NULL);
643 if (op2 == 0)
644 _bfd_vms_push (abfd, (uquad) 0, -1);
645 else
646 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
647 break;
649 case ETIR_S_C_OPR_AND: /* logical and */
650 op1 = (long) _bfd_vms_pop (abfd, NULL);
651 op2 = (long) _bfd_vms_pop (abfd, NULL);
652 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
653 break;
655 case ETIR_S_C_OPR_IOR: /* logical inclusive or */
656 op1 = (long) _bfd_vms_pop (abfd, NULL);
657 op2 = (long) _bfd_vms_pop (abfd, NULL);
658 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
659 break;
661 case ETIR_S_C_OPR_EOR: /* logical exclusive or */
662 op1 = (long) _bfd_vms_pop (abfd, NULL);
663 op2 = (long) _bfd_vms_pop (abfd, NULL);
664 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
665 break;
667 case ETIR_S_C_OPR_NEG: /* negate */
668 op1 = (long) _bfd_vms_pop (abfd, NULL);
669 _bfd_vms_push (abfd, (uquad) (-op1), -1);
670 break;
672 case ETIR_S_C_OPR_COM: /* complement */
673 op1 = (long) _bfd_vms_pop (abfd, NULL);
674 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
675 break;
677 case ETIR_S_C_OPR_ASH: /* arithmetic shift */
678 op1 = (long) _bfd_vms_pop (abfd, NULL);
679 op2 = (long) _bfd_vms_pop (abfd, NULL);
680 if (op2 < 0) /* shift right */
681 op1 >>= -op2;
682 else /* shift left */
683 op1 <<= op2;
684 _bfd_vms_push (abfd, (uquad) op1, -1);
685 break;
687 case ETIR_S_C_OPR_INSV: /* insert field */
688 (void) _bfd_vms_pop (abfd, NULL);
689 case ETIR_S_C_OPR_USH: /* unsigned shift */
690 case ETIR_S_C_OPR_ROT: /* rotate */
691 case ETIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
692 case ETIR_S_C_OPR_DFLIT: /* Define a literal. */
693 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
694 break;
696 case ETIR_S_C_OPR_SEL: /* select */
697 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
698 (void) _bfd_vms_pop (abfd, NULL);
699 else
701 op1 = (long) _bfd_vms_pop (abfd, NULL);
702 (void) _bfd_vms_pop (abfd, NULL);
703 _bfd_vms_push (abfd, (uquad) op1, -1);
705 break;
707 default:
708 (*_bfd_error_handler) (_("reserved OPR cmd %d"), cmd);
709 break;
712 return true;
715 /* Control commands.
717 See table B-11 of the openVMS linker manual. */
719 static boolean
720 etir_ctl (abfd, cmd, ptr)
721 bfd *abfd;
722 int cmd;
723 unsigned char *ptr;
725 uquad dummy;
726 int psect;
728 #if VMS_DEBUG
729 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
730 _bfd_hexdump (8, ptr, 16, (int) ptr);
731 #endif
733 switch (cmd)
735 /* set relocation base: pop stack, set image location counter
736 arg: none. */
738 case ETIR_S_C_CTL_SETRB:
739 dummy = _bfd_vms_pop (abfd, &psect);
740 image_set_ptr (abfd, psect, dummy);
741 break;
743 /* augment relocation base: increment image location counter by offset
744 arg: lw offset value */
746 case ETIR_S_C_CTL_AUGRB:
747 dummy = bfd_getl32 (ptr);
748 image_inc_ptr (abfd, dummy);
749 break;
751 /* define location: pop index, save location counter under index
752 arg: none. */
754 case ETIR_S_C_CTL_DFLOC:
755 dummy = _bfd_vms_pop (abfd, NULL);
756 /* FIXME */
757 break;
759 /* set location: pop index, restore location counter from index
760 arg: none. */
762 case ETIR_S_C_CTL_STLOC:
763 dummy = _bfd_vms_pop (abfd, &psect);
764 /* FIXME */
765 break;
767 /* stack defined location: pop index, push location counter from index
768 arg: none. */
770 case ETIR_S_C_CTL_STKDL:
771 dummy = _bfd_vms_pop (abfd, &psect);
772 /* FIXME */
773 break;
775 default:
776 (*_bfd_error_handler) (_("reserved CTL cmd %d"), cmd);
777 break;
779 return true;
782 /* store conditional commands
784 See table B-12 and B-13 of the openVMS linker manual. */
786 static boolean
787 etir_stc (abfd, cmd, ptr)
788 bfd *abfd;
789 int cmd;
790 unsigned char *ptr ATTRIBUTE_UNUSED;
792 #if VMS_DEBUG
793 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
794 _bfd_hexdump (8, ptr, 16, (int) ptr);
795 #endif
797 switch (cmd)
799 /* 200 Store-conditional Linkage Pair
800 arg: none. */
802 case ETIR_S_C_STC_LP:
803 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
804 break;
806 /* 201 Store-conditional Linkage Pair with Procedure Signature
807 arg: lw linkage index
808 cs procedure name
809 by signature length
810 da signature. */
812 case ETIR_S_C_STC_LP_PSB:
813 image_inc_ptr (abfd, (uquad) 16); /* skip entry,procval */
814 break;
816 /* 202 Store-conditional Address at global address
817 arg: lw linkage index
818 cs global name */
820 case ETIR_S_C_STC_GBL:
821 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
822 break;
824 /* 203 Store-conditional Code Address at global address
825 arg: lw linkage index
826 cs procedure name */
828 case ETIR_S_C_STC_GCA:
829 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
830 break;
832 /* 204 Store-conditional Address at psect + offset
833 arg: lw linkage index
834 lw psect index
835 qw offset */
837 case ETIR_S_C_STC_PS:
838 (*_bfd_error_handler) (_("%s: not supported"), cmd_name (cmd));
839 break;
841 /* 205 Store-conditional NOP at address of global
842 arg: none. */
844 case ETIR_S_C_STC_NOP_GBL:
846 /* 206 Store-conditional NOP at pect + offset
847 arg: none. */
849 case ETIR_S_C_STC_NOP_PS:
851 /* 207 Store-conditional BSR at global address
852 arg: none. */
854 case ETIR_S_C_STC_BSR_GBL:
856 /* 208 Store-conditional BSR at pect + offset
857 arg: none. */
859 case ETIR_S_C_STC_BSR_PS:
861 /* 209 Store-conditional LDA at global address
862 arg: none. */
864 case ETIR_S_C_STC_LDA_GBL:
866 /* 210 Store-conditional LDA at psect + offset
867 arg: none. */
869 case ETIR_S_C_STC_LDA_PS:
871 /* 211 Store-conditional BSR or Hint at global address
872 arg: none. */
874 case ETIR_S_C_STC_BOH_GBL:
876 /* 212 Store-conditional BSR or Hint at pect + offset
877 arg: none. */
879 case ETIR_S_C_STC_BOH_PS:
881 /* 213 Store-conditional NOP,BSR or HINT at global address
882 arg: none. */
884 case ETIR_S_C_STC_NBH_GBL:
886 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
887 arg: none. */
889 case ETIR_S_C_STC_NBH_PS:
890 /* FIXME */
891 #if 0
892 (*_bfd_error_handler) ("%s: not supported", cmd_name (cmd));
893 #endif
894 break;
896 default:
897 #if VMS_DEBUG
898 _bfd_vms_debug (3, "reserved STC cmd %d", cmd);
899 #endif
900 break;
902 return true;
905 static asection *
906 new_section (abfd, idx)
907 bfd *abfd ATTRIBUTE_UNUSED;
908 int idx;
910 asection *section;
911 char sname[16];
912 char *name;
914 #if VMS_DEBUG
915 _bfd_vms_debug (5, "new_section %d\n", idx);
916 #endif
917 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
919 name = bfd_malloc ((bfd_size_type) strlen (sname) + 1);
920 if (name == 0)
921 return 0;
922 strcpy (name, sname);
924 section = bfd_malloc ((bfd_size_type) sizeof (asection));
925 if (section == 0)
927 #if VMS_DEBUG
928 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
929 #endif
930 return 0;
933 section->_raw_size = 0;
934 section->vma = 0;
935 section->contents = 0;
936 section->_cooked_size = 0;
937 section->name = name;
938 section->index = idx;
940 return section;
943 static int
944 alloc_section (abfd, idx)
945 bfd *abfd;
946 unsigned int idx;
948 bfd_size_type amt;
950 #if VMS_DEBUG
951 _bfd_vms_debug (4, "alloc_section %d\n", idx);
952 #endif
954 amt = idx + 1;
955 amt *= sizeof (asection *);
956 PRIV (sections) = (asection **) bfd_realloc (PRIV (sections), amt);
957 if (PRIV (sections) == 0)
958 return -1;
960 while (PRIV (section_count) <= idx)
962 PRIV (sections)[PRIV (section_count)]
963 = new_section (abfd, (int) PRIV (section_count));
964 if (PRIV (sections)[PRIV (section_count)] == 0)
965 return -1;
966 PRIV (section_count)++;
969 return 0;
972 /* tir_sta
974 vax stack commands
976 Handle sta_xxx commands in tir section
977 ptr points to data area in record
979 See table 7-3 of the VAX/VMS linker manual. */
981 static unsigned char *
982 tir_sta (bfd *abfd, unsigned char *ptr)
984 int cmd = *ptr++;
986 #if VMS_DEBUG
987 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
988 #endif
990 switch (cmd)
992 /* stack */
993 case TIR_S_C_STA_GBL:
994 /* stack global
995 arg: cs symbol name
997 stack 32 bit value of symbol (high bits set to 0). */
999 char *name;
1000 vms_symbol_entry *entry;
1002 name = _bfd_vms_save_counted_string (ptr);
1004 entry = _bfd_vms_enter_symbol (abfd, name);
1005 if (entry == (vms_symbol_entry *) NULL)
1006 return 0;
1008 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
1009 ptr += *ptr + 1;
1011 break;
1013 case TIR_S_C_STA_SB:
1014 /* stack signed byte
1015 arg: by value
1017 stack byte value, sign extend to 32 bit. */
1018 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1019 break;
1021 case TIR_S_C_STA_SW:
1022 /* stack signed short word
1023 arg: sh value
1025 stack 16 bit value, sign extend to 32 bit. */
1026 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1027 ptr += 2;
1028 break;
1030 case TIR_S_C_STA_LW:
1031 /* stack signed longword
1032 arg: lw value
1034 stack 32 bit value. */
1035 _bfd_vms_push (abfd, (uquad) bfd_getl32 (ptr), -1);
1036 ptr += 4;
1037 break;
1039 case TIR_S_C_STA_PB:
1040 case TIR_S_C_STA_WPB:
1041 /* stack psect base plus byte offset (word index)
1042 arg: by section index
1043 (sh section index)
1044 by signed byte offset. */
1046 unsigned long dummy;
1047 unsigned int psect;
1049 if (cmd == TIR_S_C_STA_PB)
1050 psect = *ptr++;
1051 else
1053 psect = bfd_getl16 (ptr);
1054 ptr += 2;
1057 if (psect >= PRIV (section_count))
1058 alloc_section (abfd, psect);
1060 dummy = (long) *ptr++;
1061 dummy += (PRIV (sections)[psect])->vma;
1062 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1064 break;
1066 case TIR_S_C_STA_PW:
1067 case TIR_S_C_STA_WPW:
1068 /* stack psect base plus word offset (word index)
1069 arg: by section index
1070 (sh section index)
1071 sh signed short offset. */
1073 unsigned long dummy;
1074 unsigned int psect;
1076 if (cmd == TIR_S_C_STA_PW)
1077 psect = *ptr++;
1078 else
1080 psect = bfd_getl16 (ptr);
1081 ptr += 2;
1084 if (psect >= PRIV (section_count))
1085 alloc_section (abfd, psect);
1087 dummy = bfd_getl16 (ptr); ptr+=2;
1088 dummy += (PRIV (sections)[psect])->vma;
1089 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1091 break;
1093 case TIR_S_C_STA_PL:
1094 case TIR_S_C_STA_WPL:
1095 /* stack psect base plus long offset (word index)
1096 arg: by section index
1097 (sh section index)
1098 lw signed longword offset. */
1100 unsigned long dummy;
1101 unsigned int psect;
1103 if (cmd == TIR_S_C_STA_PL)
1104 psect = *ptr++;
1105 else
1107 psect = bfd_getl16 (ptr);
1108 ptr += 2;
1111 if (psect >= PRIV (section_count))
1112 alloc_section (abfd, psect);
1114 dummy = bfd_getl32 (ptr); ptr += 4;
1115 dummy += (PRIV (sections)[psect])->vma;
1116 _bfd_vms_push (abfd, (uquad) dummy, (int) psect);
1118 break;
1120 case TIR_S_C_STA_UB:
1121 /* stack unsigned byte
1122 arg: by value
1124 stack byte value. */
1125 _bfd_vms_push (abfd, (uquad) *ptr++, -1);
1126 break;
1128 case TIR_S_C_STA_UW:
1129 /* stack unsigned short word
1130 arg: sh value
1132 stack 16 bit value. */
1133 _bfd_vms_push (abfd, (uquad) bfd_getl16 (ptr), -1);
1134 ptr += 2;
1135 break;
1137 case TIR_S_C_STA_BFI:
1138 /* stack byte from image
1139 arg: none. */
1140 /* FALLTHRU */
1141 case TIR_S_C_STA_WFI:
1142 /* stack byte from image
1143 arg: none. */
1144 /* FALLTHRU */
1145 case TIR_S_C_STA_LFI:
1146 /* stack byte from image
1147 arg: none. */
1148 (*_bfd_error_handler) (_("stack-from-image not implemented"));
1149 return NULL;
1151 case TIR_S_C_STA_EPM:
1152 /* stack entry point mask
1153 arg: cs symbol name
1155 stack (unsigned) entry point mask of symbol
1156 err if symbol is no entry point. */
1158 char *name;
1159 vms_symbol_entry *entry;
1161 name = _bfd_vms_save_counted_string (ptr);
1162 entry = _bfd_vms_enter_symbol (abfd, name);
1163 if (entry == (vms_symbol_entry *) NULL)
1164 return 0;
1166 (*_bfd_error_handler) (_("stack-entry-mask not fully implemented"));
1167 _bfd_vms_push (abfd, (uquad) 0, -1);
1168 ptr += *ptr + 1;
1170 break;
1172 case TIR_S_C_STA_CKARG:
1173 /* compare procedure argument
1174 arg: cs symbol name
1175 by argument index
1176 da argument descriptor
1178 compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1179 and stack TRUE (args match) or FALSE (args dont match) value. */
1180 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1181 _bfd_vms_push (abfd, (uquad) 1, -1);
1182 break;
1184 case TIR_S_C_STA_LSY:
1185 /* stack local symbol value
1186 arg: sh environment index
1187 cs symbol name. */
1189 int envidx;
1190 char *name;
1191 vms_symbol_entry *entry;
1193 envidx = bfd_getl16 (ptr);
1194 ptr += 2;
1195 name = _bfd_vms_save_counted_string (ptr);
1196 entry = _bfd_vms_enter_symbol (abfd, name);
1197 if (entry == (vms_symbol_entry *) NULL)
1198 return 0;
1199 (*_bfd_error_handler) (_("stack-local-symbol not fully implemented"));
1200 _bfd_vms_push (abfd, (uquad) 0, -1);
1201 ptr += *ptr + 1;
1203 break;
1205 case TIR_S_C_STA_LIT:
1206 /* stack literal
1207 arg: by literal index
1209 stack literal. */
1210 ptr++;
1211 _bfd_vms_push (abfd, (uquad) 0, -1);
1212 (*_bfd_error_handler) (_("stack-literal not fully implemented"));
1213 break;
1215 case TIR_S_C_STA_LEPM:
1216 /* stack local symbol entry point mask
1217 arg: sh environment index
1218 cs symbol name
1220 stack (unsigned) entry point mask of symbol
1221 err if symbol is no entry point. */
1223 int envidx;
1224 char *name;
1225 vms_symbol_entry *entry;
1227 envidx = bfd_getl16 (ptr);
1228 ptr += 2;
1229 name = _bfd_vms_save_counted_string (ptr);
1230 entry = _bfd_vms_enter_symbol (abfd, name);
1231 if (entry == (vms_symbol_entry *) NULL)
1232 return 0;
1233 (*_bfd_error_handler) (_("stack-local-symbol-entry-point-mask not fully implemented"));
1234 _bfd_vms_push (abfd, (uquad) 0, -1);
1235 ptr += *ptr + 1;
1237 break;
1239 default:
1240 (*_bfd_error_handler) (_("reserved STA cmd %d"), ptr[-1]);
1241 return NULL;
1242 break;
1245 return ptr;
1248 static const char *
1249 tir_cmd_name (cmd)
1250 int cmd;
1252 switch (cmd)
1254 case TIR_S_C_STO_RSB: return "TIR_S_C_STO_RSB";
1255 case TIR_S_C_STO_RSW: return "TIR_S_C_STO_RSW";
1256 case TIR_S_C_STO_RL: return "TIR_S_C_STO_RL";
1257 case TIR_S_C_STO_VPS: return "TIR_S_C_STO_VPS";
1258 case TIR_S_C_STO_USB: return "TIR_S_C_STO_USB";
1259 case TIR_S_C_STO_USW: return "TIR_S_C_STO_USW";
1260 case TIR_S_C_STO_RUB: return "TIR_S_C_STO_RUB";
1261 case TIR_S_C_STO_RUW: return "TIR_S_C_STO_RUW";
1262 case TIR_S_C_STO_PIRR: return "TIR_S_C_STO_PIRR";
1263 case TIR_S_C_OPR_INSV: return "TIR_S_C_OPR_INSV";
1264 case TIR_S_C_OPR_DFLIT: return "TIR_S_C_OPR_DFLIT";
1265 case TIR_S_C_OPR_REDEF: return "TIR_S_C_OPR_REDEF";
1266 case TIR_S_C_OPR_ROT: return "TIR_S_C_OPR_ROT";
1267 case TIR_S_C_OPR_USH: return "TIR_S_C_OPR_USH";
1268 case TIR_S_C_OPR_ASH: return "TIR_S_C_OPR_ASH";
1269 case TIR_S_C_CTL_DFLOC: return "TIR_S_C_CTL_DFLOC";
1270 case TIR_S_C_CTL_STLOC: return "TIR_S_C_CTL_STLOC";
1271 case TIR_S_C_CTL_STKDL: return "TIR_S_C_CTL_STKDL";
1273 default:
1274 /* These strings have not been added yet. */
1275 abort ();
1279 /* tir_sto
1281 vax store commands
1283 handle sto_xxx commands in tir section
1284 ptr points to data area in record
1286 See table 7-4 of the VAX/VMS linker manual. */
1288 static unsigned char *
1289 tir_sto (bfd *abfd, unsigned char *ptr)
1291 unsigned long dummy;
1292 int size;
1293 int psect;
1295 #if VMS_DEBUG
1296 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1297 #endif
1299 switch (*ptr++)
1301 case TIR_S_C_STO_SB:
1302 /* store signed byte: pop stack, write byte
1303 arg: none. */
1304 dummy = _bfd_vms_pop (abfd, &psect);
1305 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1306 break;
1308 case TIR_S_C_STO_SW:
1309 /* store signed word: pop stack, write word
1310 arg: none. */
1311 dummy = _bfd_vms_pop (abfd, &psect);
1312 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1313 break;
1315 case TIR_S_C_STO_LW:
1316 /* store longword: pop stack, write longword
1317 arg: none. */
1318 dummy = _bfd_vms_pop (abfd, &psect);
1319 image_write_l (abfd, dummy & 0xffffffff); /* FIXME: check top bits */
1320 break;
1322 case TIR_S_C_STO_BD:
1323 /* store byte displaced: pop stack, sub lc+1, write byte
1324 arg: none. */
1325 dummy = _bfd_vms_pop (abfd, &psect);
1326 dummy -= ((PRIV (sections)[psect])->vma + 1);
1327 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1328 break;
1330 case TIR_S_C_STO_WD:
1331 /* store word displaced: pop stack, sub lc+2, write word
1332 arg: none. */
1333 dummy = _bfd_vms_pop (abfd, &psect);
1334 dummy -= ((PRIV (sections)[psect])->vma + 2);
1335 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1336 break;
1338 case TIR_S_C_STO_LD:
1339 /* store long displaced: pop stack, sub lc+4, write long
1340 arg: none. */
1341 dummy = _bfd_vms_pop (abfd, &psect);
1342 dummy -= ((PRIV (sections)[psect])->vma + 4);
1343 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1344 break;
1346 case TIR_S_C_STO_LI:
1347 /* store short literal: pop stack, write byte
1348 arg: none. */
1349 dummy = _bfd_vms_pop (abfd, &psect);
1350 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1351 break;
1353 case TIR_S_C_STO_PIDR:
1354 /* store position independent data reference: pop stack, write longword
1355 arg: none.
1356 FIXME: incomplete ! */
1357 dummy = _bfd_vms_pop (abfd, &psect);
1358 image_write_l (abfd, dummy & 0xffffffff);
1359 break;
1361 case TIR_S_C_STO_PICR:
1362 /* store position independent code reference: pop stack, write longword
1363 arg: none.
1364 FIXME: incomplete ! */
1365 dummy = _bfd_vms_pop (abfd, &psect);
1366 image_write_b (abfd, 0x9f);
1367 image_write_l (abfd, dummy & 0xffffffff);
1368 break;
1370 case TIR_S_C_STO_RIVB:
1371 /* store repeated immediate variable bytes
1372 1-byte count n field followed by n bytes of data
1373 pop stack, write n bytes <stack> times. */
1374 size = *ptr++;
1375 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1376 while (dummy-- > 0L)
1377 image_dump (abfd, ptr, size, 0);
1378 ptr += size;
1379 break;
1381 case TIR_S_C_STO_B:
1382 /* store byte from top longword. */
1383 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1384 image_write_b (abfd, dummy & 0xff);
1385 break;
1387 case TIR_S_C_STO_W:
1388 /* store word from top longword. */
1389 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1390 image_write_w (abfd, dummy & 0xffff);
1391 break;
1393 case TIR_S_C_STO_RB:
1394 /* store repeated byte from top longword. */
1395 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1396 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1397 while (size-- > 0)
1398 image_write_b (abfd, dummy & 0xff);
1399 break;
1401 case TIR_S_C_STO_RW:
1402 /* store repeated word from top longword. */
1403 size = (unsigned long) _bfd_vms_pop (abfd, NULL);
1404 dummy = (unsigned long) _bfd_vms_pop (abfd, NULL);
1405 while (size-- > 0)
1406 image_write_w (abfd, dummy & 0xffff);
1407 break;
1409 case TIR_S_C_STO_RSB:
1410 case TIR_S_C_STO_RSW:
1411 case TIR_S_C_STO_RL:
1412 case TIR_S_C_STO_VPS:
1413 case TIR_S_C_STO_USB:
1414 case TIR_S_C_STO_USW:
1415 case TIR_S_C_STO_RUB:
1416 case TIR_S_C_STO_RUW:
1417 case TIR_S_C_STO_PIRR:
1418 (*_bfd_error_handler) (_("%s: not implemented"), tir_cmd_name (ptr[-1]));
1419 break;
1421 default:
1422 (*_bfd_error_handler) (_("reserved STO cmd %d"), ptr[-1]);
1423 break;
1426 return ptr;
1429 /* stack operator commands
1430 all 32 bit signed arithmetic
1431 all word just like a stack calculator
1432 arguments are popped from stack, results are pushed on stack
1434 See table 7-5 of the VAX/VMS linker manual. */
1436 static unsigned char *
1437 tir_opr (abfd, ptr)
1438 bfd *abfd;
1439 unsigned char *ptr;
1441 long op1, op2;
1443 #if VMS_DEBUG
1444 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1445 #endif
1447 switch (*ptr++)
1449 /* operation */
1450 case TIR_S_C_OPR_NOP: /* no-op */
1451 break;
1453 case TIR_S_C_OPR_ADD: /* add */
1454 op1 = (long) _bfd_vms_pop (abfd, NULL);
1455 op2 = (long) _bfd_vms_pop (abfd, NULL);
1456 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
1457 break;
1459 case TIR_S_C_OPR_SUB: /* subtract */
1460 op1 = (long) _bfd_vms_pop (abfd, NULL);
1461 op2 = (long) _bfd_vms_pop (abfd, NULL);
1462 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
1463 break;
1465 case TIR_S_C_OPR_MUL: /* multiply */
1466 op1 = (long) _bfd_vms_pop (abfd, NULL);
1467 op2 = (long) _bfd_vms_pop (abfd, NULL);
1468 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
1469 break;
1471 case TIR_S_C_OPR_DIV: /* divide */
1472 op1 = (long) _bfd_vms_pop (abfd, NULL);
1473 op2 = (long) _bfd_vms_pop (abfd, NULL);
1474 if (op2 == 0)
1475 _bfd_vms_push (abfd, (uquad) 0, -1);
1476 else
1477 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
1478 break;
1480 case TIR_S_C_OPR_AND: /* logical and */
1481 op1 = (long) _bfd_vms_pop (abfd, NULL);
1482 op2 = (long) _bfd_vms_pop (abfd, NULL);
1483 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
1484 break;
1486 case TIR_S_C_OPR_IOR: /* logical inclusive or */
1487 op1 = (long) _bfd_vms_pop (abfd, NULL);
1488 op2 = (long) _bfd_vms_pop (abfd, NULL);
1489 _bfd_vms_push (abfd, (uquad) (op1 | op2), -1);
1490 break;
1492 case TIR_S_C_OPR_EOR: /* logical exclusive or */
1493 op1 = (long) _bfd_vms_pop (abfd, NULL);
1494 op2 = (long) _bfd_vms_pop (abfd, NULL);
1495 _bfd_vms_push (abfd, (uquad) (op1 ^ op2), -1);
1496 break;
1498 case TIR_S_C_OPR_NEG: /* negate */
1499 op1 = (long) _bfd_vms_pop (abfd, NULL);
1500 _bfd_vms_push (abfd, (uquad) (-op1), -1);
1501 break;
1503 case TIR_S_C_OPR_COM: /* complement */
1504 op1 = (long) _bfd_vms_pop (abfd, NULL);
1505 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
1506 break;
1508 case TIR_S_C_OPR_INSV: /* insert field */
1509 (void) _bfd_vms_pop (abfd, NULL);
1510 (*_bfd_error_handler) (_("%s: not fully implemented"),
1511 tir_cmd_name (ptr[-1]));
1512 break;
1514 case TIR_S_C_OPR_ASH: /* arithmetic shift */
1515 op1 = (long) _bfd_vms_pop (abfd, NULL);
1516 op2 = (long) _bfd_vms_pop (abfd, NULL);
1517 if (HIGHBIT (op1)) /* shift right */
1518 op2 >>= op1;
1519 else /* shift left */
1520 op2 <<= op1;
1521 _bfd_vms_push (abfd, (uquad) op2, -1);
1522 (*_bfd_error_handler) (_("%s: not fully implemented"),
1523 tir_cmd_name (ptr[-1]));
1524 break;
1526 case TIR_S_C_OPR_USH: /* unsigned shift */
1527 op1 = (long) _bfd_vms_pop (abfd, NULL);
1528 op2 = (long) _bfd_vms_pop (abfd, NULL);
1529 if (HIGHBIT (op1)) /* shift right */
1530 op2 >>= op1;
1531 else /* shift left */
1532 op2 <<= op1;
1533 _bfd_vms_push (abfd, (uquad) op2, -1);
1534 (*_bfd_error_handler) (_("%s: not fully implemented"),
1535 tir_cmd_name (ptr[-1]));
1536 break;
1538 case TIR_S_C_OPR_ROT: /* rotate */
1539 op1 = (long) _bfd_vms_pop (abfd, NULL);
1540 op2 = (long) _bfd_vms_pop (abfd, NULL);
1541 if (HIGHBIT (0)) /* shift right */
1542 op2 >>= op1;
1543 else /* shift left */
1544 op2 <<= op1;
1545 _bfd_vms_push (abfd, (uquad) op2, -1);
1546 (*_bfd_error_handler) (_("%s: not fully implemented"),
1547 tir_cmd_name (ptr[-1]));
1548 break;
1550 case TIR_S_C_OPR_SEL: /* select */
1551 if ((long) _bfd_vms_pop (abfd, NULL) & 0x01L)
1552 (void) _bfd_vms_pop (abfd, NULL);
1553 else
1555 op1 = (long) _bfd_vms_pop (abfd, NULL);
1556 (void) _bfd_vms_pop (abfd, NULL);
1557 _bfd_vms_push (abfd, (uquad) op1, -1);
1559 break;
1561 case TIR_S_C_OPR_REDEF: /* Redefine symbol to current location. */
1562 case TIR_S_C_OPR_DFLIT: /* Define a literal. */
1563 (*_bfd_error_handler) (_("%s: not supported"),
1564 tir_cmd_name (ptr[-1]));
1565 break;
1567 default:
1568 (*_bfd_error_handler) (_("reserved OPR cmd %d"), ptr[-1]);
1569 break;
1572 return ptr;
1575 /* control commands
1577 See table 7-6 of the VAX/VMS linker manual. */
1579 static unsigned char *
1580 tir_ctl (bfd *abfd, unsigned char *ptr)
1582 unsigned long dummy;
1583 unsigned int psect;
1585 #if VMS_DEBUG
1586 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1587 #endif
1589 switch (*ptr++)
1591 case TIR_S_C_CTL_SETRB:
1592 /* Set relocation base: pop stack, set image location counter
1593 arg: none. */
1594 dummy = _bfd_vms_pop (abfd, &psect);
1595 if (psect >= PRIV (section_count))
1596 alloc_section (abfd, psect);
1597 image_set_ptr (abfd, (int) psect, (uquad) dummy);
1598 break;
1600 case TIR_S_C_CTL_AUGRB:
1601 /* Augment relocation base: increment image location counter by offset
1602 arg: lw offset value. */
1603 dummy = bfd_getl32 (ptr);
1604 image_inc_ptr (abfd, (uquad) dummy);
1605 break;
1607 case TIR_S_C_CTL_DFLOC:
1608 /* Define location: pop index, save location counter under index
1609 arg: none. */
1610 dummy = _bfd_vms_pop (abfd, NULL);
1611 (*_bfd_error_handler) (_("%s: not fully implemented"),
1612 tir_cmd_name (ptr[-1]));
1613 break;
1615 case TIR_S_C_CTL_STLOC:
1616 /* Set location: pop index, restore location counter from index
1617 arg: none. */
1618 dummy = _bfd_vms_pop (abfd, &psect);
1619 (*_bfd_error_handler) (_("%s: not fully implemented"),
1620 tir_cmd_name (ptr[-1]));
1621 break;
1623 case TIR_S_C_CTL_STKDL:
1624 /* Stack defined location: pop index, push location counter from index
1625 arg: none. */
1626 dummy = _bfd_vms_pop (abfd, &psect);
1627 (*_bfd_error_handler) (_("%s: not fully implemented"),
1628 tir_cmd_name (ptr[-1]));
1629 break;
1631 default:
1632 (*_bfd_error_handler) (_("reserved CTL cmd %d"), ptr[-1]);
1633 break;
1635 return ptr;
1638 /* Handle command from TIR section. */
1640 static unsigned char *
1641 tir_cmd (bfd *abfd, unsigned char *ptr)
1643 struct
1645 int mincod;
1646 int maxcod;
1647 unsigned char * (*explain) (bfd *, unsigned char *);
1649 tir_table[] =
1651 { 0, TIR_S_C_MAXSTACOD, tir_sta },
1652 { TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto },
1653 { TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr },
1654 { TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl },
1655 { -1, -1, NULL }
1657 int i = 0;
1659 #if VMS_DEBUG
1660 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1661 _bfd_hexdump (8, ptr, 16, (int) ptr);
1662 #endif
1664 if (*ptr & 0x80) /* store immediate */
1666 i = 128 - (*ptr++ & 0x7f);
1667 image_dump (abfd, ptr, i, 0);
1668 ptr += i;
1670 else
1672 while (tir_table[i].mincod >= 0)
1674 if ( (tir_table[i].mincod <= *ptr)
1675 && (*ptr <= tir_table[i].maxcod))
1677 ptr = tir_table[i].explain (abfd, ptr);
1678 break;
1680 i++;
1682 if (tir_table[i].mincod < 0)
1684 (*_bfd_error_handler) (_("obj code %d not found"), *ptr);
1685 ptr = 0;
1689 return ptr;
1692 /* Handle command from ETIR section. */
1694 static int
1695 etir_cmd (abfd, cmd, ptr)
1696 bfd *abfd;
1697 int cmd;
1698 unsigned char *ptr;
1700 static struct
1702 int mincod;
1703 int maxcod;
1704 boolean (*explain) PARAMS ((bfd *, int, unsigned char *));
1706 etir_table[] =
1708 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1709 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1710 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1711 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1712 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1713 { -1, -1, NULL }
1716 int i = 0;
1718 #if VMS_DEBUG
1719 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1720 _bfd_hexdump (8, ptr, 16, (int) ptr);
1721 #endif
1723 while (etir_table[i].mincod >= 0)
1725 if ( (etir_table[i].mincod <= cmd)
1726 && (cmd <= etir_table[i].maxcod))
1728 if (!etir_table[i].explain (abfd, cmd, ptr))
1729 return -1;
1730 break;
1732 i++;
1735 #if VMS_DEBUG
1736 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1737 #endif
1738 return 0;
1741 /* Text Information and Relocation Records (OBJ$C_TIR)
1742 handle tir record. */
1744 static int
1745 analyze_tir (abfd, ptr, length)
1746 bfd *abfd;
1747 unsigned char *ptr;
1748 unsigned int length;
1750 unsigned char *maxptr;
1752 #if VMS_DEBUG
1753 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1754 #endif
1756 maxptr = ptr + length;
1758 while (ptr < maxptr)
1760 ptr = tir_cmd (abfd, ptr);
1761 if (ptr == 0)
1762 return -1;
1765 return 0;
1768 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1769 handle etir record. */
1771 static int
1772 analyze_etir (abfd, ptr, length)
1773 bfd *abfd;
1774 unsigned char *ptr;
1775 unsigned int length;
1777 int cmd;
1778 unsigned char *maxptr;
1779 int result = 0;
1781 #if VMS_DEBUG
1782 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1783 #endif
1785 maxptr = ptr + length;
1787 while (ptr < maxptr)
1789 cmd = bfd_getl16 (ptr);
1790 length = bfd_getl16 (ptr + 2);
1791 result = etir_cmd (abfd, cmd, ptr+4);
1792 if (result != 0)
1793 break;
1794 ptr += length;
1797 #if VMS_DEBUG
1798 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1799 #endif
1801 return result;
1804 /* Process ETIR record
1805 Return 0 on success, -1 on error. */
1808 _bfd_vms_slurp_tir (abfd, objtype)
1809 bfd *abfd;
1810 int objtype;
1812 int result;
1814 #if VMS_DEBUG
1815 _bfd_vms_debug (2, "TIR/ETIR\n");
1816 #endif
1818 switch (objtype)
1820 case EOBJ_S_C_ETIR:
1821 PRIV (vms_rec) += 4; /* skip type, size */
1822 PRIV (rec_size) -= 4;
1823 result = analyze_etir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1824 break;
1825 case OBJ_S_C_TIR:
1826 PRIV (vms_rec) += 1; /* skip type */
1827 PRIV (rec_size) -= 1;
1828 result = analyze_tir (abfd, PRIV (vms_rec), (unsigned) PRIV (rec_size));
1829 break;
1830 default:
1831 result = -1;
1832 break;
1835 return result;
1838 /* Process EDBG record
1839 Return 0 on success, -1 on error
1841 Not implemented yet. */
1844 _bfd_vms_slurp_dbg (abfd, objtype)
1845 bfd *abfd;
1846 int objtype ATTRIBUTE_UNUSED;
1848 #if VMS_DEBUG
1849 _bfd_vms_debug (2, "DBG/EDBG\n");
1850 #endif
1852 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1853 return 0;
1856 /* Process ETBT record
1857 Return 0 on success, -1 on error
1859 Not implemented yet. */
1862 _bfd_vms_slurp_tbt (abfd, objtype)
1863 bfd *abfd ATTRIBUTE_UNUSED;
1864 int objtype ATTRIBUTE_UNUSED;
1866 #if VMS_DEBUG
1867 _bfd_vms_debug (2, "TBT/ETBT\n");
1868 #endif
1870 return 0;
1873 /* Process LNK record
1874 Return 0 on success, -1 on error
1876 Not implemented yet. */
1879 _bfd_vms_slurp_lnk (abfd, objtype)
1880 bfd *abfd ATTRIBUTE_UNUSED;
1881 int objtype ATTRIBUTE_UNUSED;
1883 #if VMS_DEBUG
1884 _bfd_vms_debug (2, "LNK\n");
1885 #endif
1887 return 0;
1890 /* WRITE ETIR SECTION
1892 This is still under construction and therefore not documented. */
1894 static void start_etir_record PARAMS ((bfd *abfd, int index, uquad offset, boolean justoffset));
1895 static void sto_imm PARAMS ((bfd *abfd, vms_section *sptr, bfd_vma vaddr, int index));
1896 static void end_etir_record PARAMS ((bfd *abfd));
1898 static void
1899 sto_imm (abfd, sptr, vaddr, index)
1900 bfd *abfd;
1901 vms_section *sptr;
1902 bfd_vma vaddr;
1903 int index;
1905 int size;
1906 int ssize;
1907 unsigned char *cptr;
1909 #if VMS_DEBUG
1910 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
1911 _bfd_hexdump (9, sptr->contents, (int) sptr->size, (int) vaddr);
1912 #endif
1914 ssize = sptr->size;
1915 cptr = sptr->contents;
1917 while (ssize > 0)
1919 size = ssize; /* try all the rest */
1921 if (_bfd_vms_output_check (abfd, size) < 0)
1922 { /* doesn't fit, split ! */
1923 end_etir_record (abfd);
1924 start_etir_record (abfd, index, vaddr, false);
1925 size = _bfd_vms_output_check (abfd, 0); /* get max size */
1926 if (size > ssize) /* more than what's left ? */
1927 size = ssize;
1930 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
1931 _bfd_vms_output_long (abfd, (unsigned long) (size));
1932 _bfd_vms_output_dump (abfd, cptr, size);
1933 _bfd_vms_output_flush (abfd);
1935 #if VMS_DEBUG
1936 _bfd_vms_debug (10, "dumped %d bytes\n", size);
1937 _bfd_hexdump (10, cptr, (int) size, (int) vaddr);
1938 #endif
1940 vaddr += size;
1941 ssize -= size;
1942 cptr += size;
1946 /* Start ETIR record for section #index at virtual addr offset. */
1948 static void
1949 start_etir_record (abfd, index, offset, justoffset)
1950 bfd *abfd;
1951 int index;
1952 uquad offset;
1953 boolean justoffset;
1955 if (!justoffset)
1957 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
1958 _bfd_vms_output_push (abfd);
1961 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
1962 _bfd_vms_output_long (abfd, (unsigned long) index);
1963 _bfd_vms_output_quad (abfd, (uquad) offset);
1964 _bfd_vms_output_flush (abfd);
1966 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop () */
1967 _bfd_vms_output_flush (abfd);
1970 /* End etir record. */
1972 static void
1973 end_etir_record (abfd)
1974 bfd *abfd;
1976 _bfd_vms_output_pop (abfd);
1977 _bfd_vms_output_end (abfd);
1980 /* Write section contents for bfd abfd. */
1983 _bfd_vms_write_tir (abfd, objtype)
1984 bfd *abfd;
1985 int objtype ATTRIBUTE_UNUSED;
1987 asection *section;
1988 vms_section *sptr;
1989 int nextoffset;
1991 #if VMS_DEBUG
1992 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
1993 #endif
1995 _bfd_vms_output_alignment (abfd, 4);
1997 nextoffset = 0;
1998 PRIV (vms_linkage_index) = 1;
2000 /* Dump all other sections. */
2002 section = abfd->sections;
2004 while (section != NULL)
2007 #if VMS_DEBUG
2008 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n",
2009 section->index, section->name,
2010 (int) (section->_raw_size));
2011 #endif
2013 if (section->flags & SEC_RELOC)
2015 int i;
2017 if ((i = section->reloc_count) <= 0)
2019 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
2020 section->name);
2022 #if VMS_DEBUG
2023 else
2025 arelent **rptr;
2026 _bfd_vms_debug (4, "%d relocations:\n", i);
2027 rptr = section->orelocation;
2028 while (i-- > 0)
2030 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2031 (*(*rptr)->sym_ptr_ptr)->name,
2032 (*(*rptr)->sym_ptr_ptr)->section->name,
2033 (long) (*(*rptr)->sym_ptr_ptr)->value,
2034 (*rptr)->address, (*rptr)->addend,
2035 bfd_get_reloc_size ((*rptr)->howto),
2036 (*rptr)->howto->name);
2037 rptr++;
2040 #endif
2043 if ((section->flags & SEC_HAS_CONTENTS)
2044 && (! bfd_is_com_section (section)))
2046 bfd_vma vaddr; /* Virtual addr in section. */
2048 sptr = _bfd_get_vms_section (abfd, section->index);
2049 if (sptr == NULL)
2051 bfd_set_error (bfd_error_no_contents);
2052 return -1;
2055 vaddr = (bfd_vma) (sptr->offset);
2057 start_etir_record (abfd, section->index, (uquad) sptr->offset,
2058 false);
2060 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per vms_section */
2063 if (section->flags & SEC_RELOC) /* check for relocs */
2065 arelent **rptr = section->orelocation;
2066 int i = section->reloc_count;
2068 for (;;)
2070 bfd_size_type addr = (*rptr)->address;
2071 bfd_size_type len = bfd_get_reloc_size ((*rptr)->howto);
2072 if (sptr->offset < addr) /* sptr starts before reloc */
2074 bfd_size_type before = addr - sptr->offset;
2075 if (sptr->size <= before) /* complete before */
2077 sto_imm (abfd, sptr, vaddr, section->index);
2078 vaddr += sptr->size;
2079 break;
2081 else /* partly before */
2083 int after = sptr->size - before;
2084 sptr->size = before;
2085 sto_imm (abfd, sptr, vaddr, section->index);
2086 vaddr += sptr->size;
2087 sptr->contents += before;
2088 sptr->offset += before;
2089 sptr->size = after;
2092 else if (sptr->offset == addr) /* sptr starts at reloc */
2094 asymbol *sym = *(*rptr)->sym_ptr_ptr;
2095 asection *sec = sym->section;
2097 switch ((*rptr)->howto->type)
2099 case ALPHA_R_IGNORE:
2100 break;
2102 case ALPHA_R_REFLONG:
2104 if (bfd_is_und_section (sym->section))
2106 int slen = strlen ((char *) sym->name);
2107 char *hash;
2109 if (_bfd_vms_output_check (abfd, slen) < 0)
2111 end_etir_record (abfd);
2112 start_etir_record (abfd,
2113 section->index,
2114 vaddr, false);
2116 _bfd_vms_output_begin (abfd,
2117 ETIR_S_C_STO_GBL_LW,
2118 -1);
2119 hash = (_bfd_vms_length_hash_symbol
2120 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2121 _bfd_vms_output_counted (abfd, hash);
2122 _bfd_vms_output_flush (abfd);
2124 else if (bfd_is_abs_section (sym->section))
2126 if (_bfd_vms_output_check (abfd, 16) < 0)
2128 end_etir_record (abfd);
2129 start_etir_record (abfd,
2130 section->index,
2131 vaddr, false);
2133 _bfd_vms_output_begin (abfd,
2134 ETIR_S_C_STA_LW,
2135 -1);
2136 _bfd_vms_output_quad (abfd,
2137 (uquad) sym->value);
2138 _bfd_vms_output_flush (abfd);
2139 _bfd_vms_output_begin (abfd,
2140 ETIR_S_C_STO_LW,
2141 -1);
2142 _bfd_vms_output_flush (abfd);
2144 else
2146 if (_bfd_vms_output_check (abfd, 32) < 0)
2148 end_etir_record (abfd);
2149 start_etir_record (abfd,
2150 section->index,
2151 vaddr, false);
2153 _bfd_vms_output_begin (abfd,
2154 ETIR_S_C_STA_PQ,
2155 -1);
2156 _bfd_vms_output_long (abfd,
2157 (unsigned long) (sec->index));
2158 _bfd_vms_output_quad (abfd,
2159 ((uquad) (*rptr)->addend
2160 + (uquad) sym->value));
2161 _bfd_vms_output_flush (abfd);
2162 _bfd_vms_output_begin (abfd,
2163 ETIR_S_C_STO_LW,
2164 -1);
2165 _bfd_vms_output_flush (abfd);
2168 break;
2170 case ALPHA_R_REFQUAD:
2172 if (bfd_is_und_section (sym->section))
2174 int slen = strlen ((char *) sym->name);
2175 char *hash;
2176 if (_bfd_vms_output_check (abfd, slen) < 0)
2178 end_etir_record (abfd);
2179 start_etir_record (abfd,
2180 section->index,
2181 vaddr, false);
2183 _bfd_vms_output_begin (abfd,
2184 ETIR_S_C_STO_GBL,
2185 -1);
2186 hash = (_bfd_vms_length_hash_symbol
2187 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2188 _bfd_vms_output_counted (abfd, hash);
2189 _bfd_vms_output_flush (abfd);
2191 else if (bfd_is_abs_section (sym->section))
2193 if (_bfd_vms_output_check (abfd, 16) < 0)
2195 end_etir_record (abfd);
2196 start_etir_record (abfd,
2197 section->index,
2198 vaddr, false);
2200 _bfd_vms_output_begin (abfd,
2201 ETIR_S_C_STA_QW,
2202 -1);
2203 _bfd_vms_output_quad (abfd,
2204 (uquad) sym->value);
2205 _bfd_vms_output_flush (abfd);
2206 _bfd_vms_output_begin (abfd,
2207 ETIR_S_C_STO_QW,
2208 -1);
2209 _bfd_vms_output_flush (abfd);
2211 else
2213 if (_bfd_vms_output_check (abfd, 32) < 0)
2215 end_etir_record (abfd);
2216 start_etir_record (abfd,
2217 section->index,
2218 vaddr, false);
2220 _bfd_vms_output_begin (abfd,
2221 ETIR_S_C_STA_PQ,
2222 -1);
2223 _bfd_vms_output_long (abfd,
2224 (unsigned long) (sec->index));
2225 _bfd_vms_output_quad (abfd,
2226 ((uquad) (*rptr)->addend
2227 + (uquad) sym->value));
2228 _bfd_vms_output_flush (abfd);
2229 _bfd_vms_output_begin (abfd,
2230 ETIR_S_C_STO_OFF,
2231 -1);
2232 _bfd_vms_output_flush (abfd);
2235 break;
2237 case ALPHA_R_HINT:
2239 int hint_size;
2240 char *hash ATTRIBUTE_UNUSED;
2242 hint_size = sptr->size;
2243 sptr->size = len;
2244 sto_imm (abfd, sptr, vaddr, section->index);
2245 sptr->size = hint_size;
2246 #if 0
2247 vms_output_begin (abfd,
2248 ETIR_S_C_STO_HINT_GBL, -1);
2249 vms_output_long (abfd,
2250 (unsigned long) (sec->index));
2251 vms_output_quad (abfd, (uquad) addr);
2253 hash = (_bfd_vms_length_hash_symbol
2254 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2255 vms_output_counted (abfd, hash);
2257 vms_output_flush (abfd);
2258 #endif
2260 break;
2261 case ALPHA_R_LINKAGE:
2263 char *hash;
2265 if (_bfd_vms_output_check (abfd, 64) < 0)
2267 end_etir_record (abfd);
2268 start_etir_record (abfd, section->index,
2269 vaddr, false);
2271 _bfd_vms_output_begin (abfd,
2272 ETIR_S_C_STC_LP_PSB,
2273 -1);
2274 _bfd_vms_output_long (abfd,
2275 (unsigned long) PRIV (vms_linkage_index));
2276 PRIV (vms_linkage_index) += 2;
2277 hash = (_bfd_vms_length_hash_symbol
2278 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2279 _bfd_vms_output_counted (abfd, hash);
2280 _bfd_vms_output_byte (abfd, 0);
2281 _bfd_vms_output_flush (abfd);
2283 break;
2285 case ALPHA_R_CODEADDR:
2287 int slen = strlen ((char *) sym->name);
2288 char *hash;
2289 if (_bfd_vms_output_check (abfd, slen) < 0)
2291 end_etir_record (abfd);
2292 start_etir_record (abfd,
2293 section->index,
2294 vaddr, false);
2296 _bfd_vms_output_begin (abfd,
2297 ETIR_S_C_STO_CA,
2298 -1);
2299 hash = (_bfd_vms_length_hash_symbol
2300 (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2301 _bfd_vms_output_counted (abfd, hash);
2302 _bfd_vms_output_flush (abfd);
2304 break;
2306 default:
2307 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2308 (*rptr)->howto->name);
2309 break;
2312 vaddr += len;
2314 if (len == sptr->size)
2316 break;
2318 else
2320 sptr->contents += len;
2321 sptr->offset += len;
2322 sptr->size -= len;
2323 i--;
2324 rptr++;
2327 else /* sptr starts after reloc */
2329 i--; /* check next reloc */
2330 rptr++;
2333 if (i==0) /* all reloc checked */
2335 if (sptr->size > 0)
2337 /* dump rest */
2338 sto_imm (abfd, sptr, vaddr, section->index);
2339 vaddr += sptr->size;
2341 break;
2343 } /* for (;;) */
2344 } /* if SEC_RELOC */
2345 else /* no relocs, just dump */
2347 sto_imm (abfd, sptr, vaddr, section->index);
2348 vaddr += sptr->size;
2351 sptr = sptr->next;
2353 } /* while (sptr != 0) */
2355 end_etir_record (abfd);
2357 } /* has_contents */
2359 section = section->next;
2362 _bfd_vms_output_alignment (abfd, 2);
2363 return 0;
2366 /* Write traceback data for bfd abfd. */
2369 _bfd_vms_write_tbt (abfd, objtype)
2370 bfd *abfd ATTRIBUTE_UNUSED;
2371 int objtype ATTRIBUTE_UNUSED;
2373 #if VMS_DEBUG
2374 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2375 #endif
2377 return 0;
2380 /* Write debug info for bfd abfd. */
2383 _bfd_vms_write_dbg (abfd, objtype)
2384 bfd *abfd ATTRIBUTE_UNUSED;
2385 int objtype ATTRIBUTE_UNUSED;
2387 #if VMS_DEBUG
2388 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);
2389 #endif
2391 return 0;