Initial revision
[binutils.git] / bfd / vms-tir.c
blob782f52bfc04b3a3f810f9fee72efe7e6a4b58c84
1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998 Free Software Foundation, Inc.
5 TIR record handling functions
6 ETIR record handling functions
8 go and read the openVMS linker manual (esp. appendix B)
9 if you don't know what's going on here :-)
11 Written by Klaus K"ampf (kkaempf@rmi.de)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 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 <ctype.h>
39 #include "bfd.h"
40 #include "sysdep.h"
41 #include "bfdlink.h"
42 #include "libbfd.h"
44 #include "vms.h"
46 static void image_set_ptr PARAMS ((bfd *abfd, int psect, uquad offset));
47 static void image_inc_ptr PARAMS ((bfd *abfd, uquad offset));
48 static void image_dump PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
49 static void image_write_b PARAMS ((bfd *abfd, unsigned int value));
50 static void image_write_w PARAMS ((bfd *abfd, unsigned int value));
51 static void image_write_l PARAMS ((bfd *abfd, unsigned long value));
52 static void image_write_q PARAMS ((bfd *abfd, uquad value));
54 /*-----------------------------------------------------------------------------*/
56 static int
57 check_section (abfd, size)
58 bfd *abfd;
59 int size;
61 int offset;
63 offset = PRIV(image_ptr) - PRIV(image_section)->contents;
64 if ((offset + size) > PRIV(image_section)->_raw_size)
66 PRIV(image_section)->contents = bfd_realloc (PRIV(image_section)->contents, offset + size);
67 if (PRIV(image_section)->contents == 0)
69 (*_bfd_error_handler) (_("No Mem !"));
70 return -1;
72 PRIV(image_section)->_raw_size = offset + size;
73 PRIV(image_ptr) = PRIV(image_section)->contents + offset;
76 return 0;
79 /* routines to fill sections contents during tir/etir read */
81 /* Initialize image buffer pointer to be filled */
83 static void
84 image_set_ptr (abfd, psect, offset)
85 bfd *abfd;
86 int psect;
87 uquad offset;
89 #if VMS_DEBUG
90 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
91 psect, PRIV(sections)[psect]->name, offset);
92 #endif
94 PRIV(image_ptr) = PRIV(sections)[psect]->contents + offset;
95 PRIV(image_section) = PRIV(sections)[psect];
96 return;
100 /* Increment image buffer pointer by offset */
102 static void
103 image_inc_ptr (abfd, offset)
104 bfd *abfd;
105 uquad offset;
107 #if VMS_DEBUG
108 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
109 #endif
111 PRIV(image_ptr) += offset;
113 return;
117 /* Dump multiple bytes to section image */
119 static void
120 image_dump (abfd, ptr, size, offset)
121 bfd *abfd;
122 unsigned char *ptr;
123 int size;
124 int offset;
126 #if VMS_DEBUG
127 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size, PRIV(image_ptr));
128 _bfd_hexdump (9, ptr, size, offset);
129 #endif
131 if (PRIV(is_vax) && check_section (abfd, size))
132 return;
134 while (size-- > 0)
135 *PRIV(image_ptr)++ = *ptr++;
136 return;
140 /* Write byte to section image */
142 static void
143 image_write_b (abfd, value)
144 bfd *abfd;
145 unsigned int value;
147 #if VMS_DEBUG
148 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int)value);
149 #endif
151 if (PRIV(is_vax) && check_section (abfd, 1))
152 return;
154 *PRIV(image_ptr)++ = (value & 0xff);
155 return;
159 /* Write 2-byte word to image */
161 static void
162 image_write_w (abfd, value)
163 bfd *abfd;
164 unsigned int value;
166 #if VMS_DEBUG
167 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int)value);
168 #endif
170 if (PRIV(is_vax) && check_section (abfd, 2))
171 return;
173 bfd_putl16 (value, PRIV(image_ptr));
174 PRIV(image_ptr) += 2;
176 return;
180 /* Write 4-byte long to image */
182 static void
183 image_write_l (abfd, value)
184 bfd *abfd;
185 unsigned long value;
187 #if VMS_DEBUG
188 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
189 #endif
191 if (PRIV(is_vax) && check_section (abfd, 4))
192 return;
194 bfd_putl32 (value, PRIV(image_ptr));
195 PRIV(image_ptr) += 4;
197 return;
201 /* Write 8-byte quad to image */
203 static void
204 image_write_q (abfd, value)
205 bfd *abfd;
206 uquad value;
208 #if VMS_DEBUG
209 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
210 #endif
212 if (PRIV(is_vax) && check_section (abfd, 8))
213 return;
215 bfd_putl64 (value, PRIV(image_ptr));
216 PRIV(image_ptr) += 8;
218 return;
222 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
224 /* etir_sta
226 vms stack commands
228 handle sta_xxx commands in etir section
229 ptr points to data area in record
231 see table B-8 of the openVMS linker manual */
233 static boolean
234 etir_sta (abfd, cmd, ptr)
235 bfd *abfd;
236 int cmd;
237 unsigned char *ptr;
240 #if VMS_DEBUG
241 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
242 _bfd_hexdump (8, ptr, 16, (int)ptr);
243 #endif
245 switch (cmd)
247 /* stack */
249 /* stack global
250 arg: cs symbol name
252 stack 32 bit value of symbol (high bits set to 0) */
254 case ETIR_S_C_STA_GBL:
256 char *name;
257 vms_symbol_entry *entry;
259 name = _bfd_vms_save_counted_string (ptr);
260 entry = (vms_symbol_entry *)
261 bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
262 if (entry == (vms_symbol_entry *)NULL)
264 #if VMS_DEBUG
265 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name);
266 #endif
267 _bfd_vms_push (abfd, (uquad)0, -1);
269 else
271 _bfd_vms_push (abfd, (uquad)(entry->symbol->value), -1);
274 break;
276 /* stack longword
277 arg: lw value
279 stack 32 bit value, sign extend to 64 bit */
281 case ETIR_S_C_STA_LW:
282 _bfd_vms_push (abfd, (uquad)bfd_getl32 (ptr), -1);
283 break;
285 /* stack global
286 arg: qw value
288 stack 64 bit value of symbol */
290 case ETIR_S_C_STA_QW:
291 _bfd_vms_push (abfd, (uquad)bfd_getl64(ptr), -1);
292 break;
294 /* stack psect base plus quadword offset
295 arg: lw section index
296 qw signed quadword offset (low 32 bits)
298 stack qw argument and section index
299 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
301 case ETIR_S_C_STA_PQ:
303 uquad dummy;
304 int psect;
306 psect = bfd_getl32 (ptr);
307 if (psect >= PRIV(section_count))
309 (*_bfd_error_handler) (_("Bad section index in ETIR_S_C_STA_PQ"));
310 bfd_set_error (bfd_error_bad_value);
311 return false;
313 dummy = bfd_getl64 (ptr+4);
314 _bfd_vms_push (abfd, dummy, psect);
316 break;
318 /* all not supported */
320 case ETIR_S_C_STA_LI:
321 case ETIR_S_C_STA_MOD:
322 case ETIR_S_C_STA_CKARG:
324 (*_bfd_error_handler) (_("Unsupported STA cmd %d"), cmd);
325 return false;
326 break;
328 default:
329 (*_bfd_error_handler) (_("Reserved STA cmd %d"), cmd);
330 return false;
331 break;
333 #if VMS_DEBUG
334 _bfd_vms_debug (5, "etir_sta true\n");
335 #endif
336 return true;
341 etir_sto
343 vms store commands
345 handle sto_xxx commands in etir section
346 ptr points to data area in record
348 see table B-9 of the openVMS linker manual */
350 static boolean
351 etir_sto (abfd, cmd, ptr)
352 bfd *abfd;
353 int cmd;
354 unsigned char *ptr;
356 uquad dummy;
357 int psect;
359 #if VMS_DEBUG
360 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
361 _bfd_hexdump (8, ptr, 16, (int)ptr);
362 #endif
364 switch (cmd)
367 /* store byte: pop stack, write byte
368 arg: - */
370 case ETIR_S_C_STO_B:
371 dummy = _bfd_vms_pop (abfd, &psect);
372 #if 0
373 if (is_share) /* FIXME */
374 (*_bfd_error_handler) ("ETIR_S_C_STO_B: byte fixups not supported");
375 #endif
376 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
377 break;
379 /* store word: pop stack, write word
380 arg: - */
382 case ETIR_S_C_STO_W:
383 dummy = _bfd_vms_pop (abfd, &psect);
384 #if 0
385 if (is_share) /* FIXME */
386 (*_bfd_error_handler) ("ETIR_S_C_STO_B: word fixups not supported");
387 #endif
388 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
389 break;
391 /* store longword: pop stack, write longword
392 arg: - */
394 case ETIR_S_C_STO_LW:
395 dummy = _bfd_vms_pop (abfd, &psect);
396 dummy += (PRIV(sections)[psect])->vma;
397 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
398 break;
400 /* store quadword: pop stack, write quadword
401 arg: - */
403 case ETIR_S_C_STO_QW:
404 dummy = _bfd_vms_pop (abfd, &psect);
405 dummy += (PRIV(sections)[psect])->vma;
406 image_write_q (abfd, dummy); /* FIXME: check top bits */
407 break;
409 /* store immediate repeated: pop stack for repeat count
410 arg: lw byte count
411 da data */
413 case ETIR_S_C_STO_IMMR:
415 unsigned long size;
417 size = bfd_getl32 (ptr);
418 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
419 while (dummy-- > 0L)
420 image_dump (abfd, ptr+4, size, 0);
422 break;
424 /* store global: write symbol value
425 arg: cs global symbol name */
427 case ETIR_S_C_STO_GBL:
429 vms_symbol_entry *entry;
430 char *name;
432 name = _bfd_vms_save_counted_string (ptr);
433 entry = (vms_symbol_entry *)bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
434 if (entry == (vms_symbol_entry *)NULL)
436 (*_bfd_error_handler) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
437 name);
438 return false;
440 else
441 image_write_q (abfd, (uquad)(entry->symbol->value)); /* FIXME, reloc */
443 break;
445 /* store code address: write address of entry point
446 arg: cs global symbol name (procedure) */
448 case ETIR_S_C_STO_CA:
450 vms_symbol_entry *entry;
451 char *name;
453 name = _bfd_vms_save_counted_string (ptr);
454 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
455 if (entry == (vms_symbol_entry *)NULL)
457 (*_bfd_error_handler) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
458 name);
459 return false;
461 else
462 image_write_q (abfd, (uquad)(entry->symbol->value)); /* FIXME, reloc */
464 break;
466 /* not supported */
468 case ETIR_S_C_STO_RB:
469 case ETIR_S_C_STO_AB:
470 (*_bfd_error_handler) (_("ETIR_S_C_STO_RB/AB: Not supported"));
471 break;
473 /* store offset to psect: pop stack, add low 32 bits to base of psect
474 arg: - */
476 case ETIR_S_C_STO_OFF:
478 uquad q;
479 int psect;
481 q = _bfd_vms_pop (abfd, &psect);
482 q += (PRIV(sections)[psect])->vma;
483 image_write_q (abfd, q);
485 break;
487 /* store immediate
488 arg: lw count of bytes
489 da data */
491 case ETIR_S_C_STO_IMM:
493 int size;
495 size = bfd_getl32 (ptr);
496 image_dump (abfd, ptr+4, size, 0);
498 break;
500 /* this code is 'reserved to digital' according to the openVMS linker manual,
501 however it is generated by the DEC C compiler and defined in the include file.
502 FIXME, since the following is just a guess
503 store global longword: store 32bit value of symbol
504 arg: cs symbol name */
506 case ETIR_S_C_STO_GBL_LW:
508 vms_symbol_entry *entry;
509 char *name;
511 name = _bfd_vms_save_counted_string (ptr);
512 entry = (vms_symbol_entry *)bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
513 if (entry == (vms_symbol_entry *)NULL)
515 #if VMS_DEBUG
516 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name);
517 #endif
518 image_write_l (abfd, (unsigned long)0); /* FIXME, reloc */
520 else
521 image_write_l (abfd, (unsigned long)(entry->symbol->value)); /* FIXME, reloc */
523 break;
525 /* not supported */
527 case ETIR_S_C_STO_LP_PSB:
528 (*_bfd_error_handler) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
529 break;
531 /* */
533 case ETIR_S_C_STO_HINT_GBL:
534 (*_bfd_error_handler) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
535 break;
537 /* */
539 case ETIR_S_C_STO_HINT_PS:
540 (*_bfd_error_handler) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
541 break;
543 default:
544 (*_bfd_error_handler) (_("Reserved STO cmd %d"), cmd);
545 break;
548 return true;
551 /* stack operator commands
552 all 32 bit signed arithmetic
553 all word just like a stack calculator
554 arguments are popped from stack, results are pushed on stack
556 see table B-10 of the openVMS linker manual */
558 static boolean
559 etir_opr (abfd, cmd, ptr)
560 bfd *abfd;
561 int cmd;
562 unsigned char *ptr;
564 long op1, op2;
566 #if VMS_DEBUG
567 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
568 _bfd_hexdump (8, ptr, 16, (int)ptr);
569 #endif
571 switch (cmd)
573 /* operation */
575 /* no-op */
577 case ETIR_S_C_OPR_NOP:
578 break;
580 /* add */
582 case ETIR_S_C_OPR_ADD:
583 op1 = (long)_bfd_vms_pop (abfd, NULL);
584 op2 = (long)_bfd_vms_pop (abfd, NULL);
585 _bfd_vms_push (abfd, (uquad)(op1 + op2), -1);
586 break;
588 /* subtract */
590 case ETIR_S_C_OPR_SUB:
591 op1 = (long)_bfd_vms_pop (abfd, NULL);
592 op2 = (long)_bfd_vms_pop (abfd, NULL);
593 _bfd_vms_push (abfd, (uquad)(op2 - op1), -1);
594 break;
596 /* multiply */
598 case ETIR_S_C_OPR_MUL:
599 op1 = (long)_bfd_vms_pop (abfd, NULL);
600 op2 = (long)_bfd_vms_pop (abfd, NULL);
601 _bfd_vms_push (abfd, (uquad)(op1 * op2), -1);
602 break;
604 /* divide */
606 case ETIR_S_C_OPR_DIV:
607 op1 = (long)_bfd_vms_pop (abfd, NULL);
608 op2 = (long)_bfd_vms_pop (abfd, NULL);
609 if (op2 == 0)
610 _bfd_vms_push (abfd, (uquad)0L, -1);
611 else
612 _bfd_vms_push (abfd, (uquad)(op2 / op1), -1);
613 break;
615 /* logical and */
617 case ETIR_S_C_OPR_AND:
618 op1 = (long)_bfd_vms_pop (abfd, NULL);
619 op2 = (long)_bfd_vms_pop (abfd, NULL);
620 _bfd_vms_push (abfd, (uquad)(op1 & op2), -1);
621 break;
623 /* logical inclusive or */
625 case ETIR_S_C_OPR_IOR:
626 op1 = (long)_bfd_vms_pop (abfd, NULL);
627 op2 = (long)_bfd_vms_pop (abfd, NULL);
628 _bfd_vms_push (abfd, (uquad)(op1 | op2), -1);
629 break;
631 /* logical exclusive or */
633 case ETIR_S_C_OPR_EOR:
634 op1 = (long)_bfd_vms_pop (abfd, NULL);
635 op2 = (long)_bfd_vms_pop (abfd, NULL);
636 _bfd_vms_push (abfd, (uquad)(op1 ^ op2), -1);
637 break;
639 /* negate */
641 case ETIR_S_C_OPR_NEG:
642 op1 = (long)_bfd_vms_pop (abfd, NULL);
643 _bfd_vms_push (abfd, (uquad)(-op1), -1);
644 break;
646 /* complement */
648 case ETIR_S_C_OPR_COM:
649 op1 = (long)_bfd_vms_pop (abfd, NULL);
650 _bfd_vms_push (abfd, (uquad)(op1 ^ -1L), -1);
651 break;
653 /* insert field */
655 case ETIR_S_C_OPR_INSV:
656 (void)_bfd_vms_pop (abfd, NULL);
657 (*_bfd_error_handler) (_("ETIR_S_C_OPR_INSV: Not supported"));
658 break;
660 /* arithmetic shift */
662 case ETIR_S_C_OPR_ASH:
663 op1 = (long)_bfd_vms_pop (abfd, NULL);
664 op2 = (long)_bfd_vms_pop (abfd, NULL);
665 if (op2 < 0) /* shift right */
666 op1 >>= -op2;
667 else /* shift left */
668 op1 <<= op2;
669 _bfd_vms_push (abfd, (uquad)op1, -1);
670 break;
672 /* unsigned shift */
674 case ETIR_S_C_OPR_USH:
675 (*_bfd_error_handler) (_("ETIR_S_C_OPR_USH: Not supported"));
676 break;
678 /* rotate */
680 case ETIR_S_C_OPR_ROT:
681 (*_bfd_error_handler) (_("ETIR_S_C_OPR_ROT: Not supported"));
682 break;
684 /* select */
686 case ETIR_S_C_OPR_SEL:
687 if ((long)_bfd_vms_pop (abfd, NULL) & 0x01L)
688 (void)_bfd_vms_pop (abfd, NULL);
689 else
691 op1 = (long)_bfd_vms_pop (abfd, NULL);
692 (void)_bfd_vms_pop (abfd, NULL);
693 _bfd_vms_push (abfd, (uquad)op1, -1);
695 break;
697 /* redefine symbol to current location */
699 case ETIR_S_C_OPR_REDEF:
700 (*_bfd_error_handler) (_("ETIR_S_C_OPR_REDEF: Not supported"));
701 break;
703 /* define a literal */
705 case ETIR_S_C_OPR_DFLIT:
706 (*_bfd_error_handler) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
707 break;
709 default:
710 (*_bfd_error_handler) (_("Reserved OPR cmd %d"), cmd);
711 break;
714 return true;
718 /* control commands
720 see table B-11 of the openVMS linker manual */
722 static boolean
723 etir_ctl (abfd, cmd, ptr)
724 bfd *abfd;
725 int cmd;
726 unsigned char *ptr;
728 uquad dummy;
729 int psect;
731 #if VMS_DEBUG
732 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
733 _bfd_hexdump (8, ptr, 16, (int)ptr);
734 #endif
736 switch (cmd)
738 /* set relocation base: pop stack, set image location counter
739 arg: - */
741 case ETIR_S_C_CTL_SETRB:
742 dummy = _bfd_vms_pop (abfd, &psect);
743 image_set_ptr (abfd, psect, dummy);
744 break;
746 /* augment relocation base: increment image location counter by offset
747 arg: lw offset value */
749 case ETIR_S_C_CTL_AUGRB:
750 dummy = bfd_getl32 (ptr);
751 image_inc_ptr (abfd, dummy);
752 break;
754 /* define location: pop index, save location counter under index
755 arg: - */
757 case ETIR_S_C_CTL_DFLOC:
758 dummy = _bfd_vms_pop (abfd, NULL);
759 /* FIXME */
760 break;
762 /* set location: pop index, restore location counter from index
763 arg: - */
765 case ETIR_S_C_CTL_STLOC:
766 dummy = _bfd_vms_pop (abfd, &psect);
767 /* FIXME */
768 break;
770 /* stack defined location: pop index, push location counter from index
771 arg: - */
773 case ETIR_S_C_CTL_STKDL:
774 dummy = _bfd_vms_pop (abfd, &psect);
775 /* FIXME */
776 break;
778 default:
779 (*_bfd_error_handler) (_("Reserved CTL cmd %d"), cmd);
780 break;
782 return true;
786 /* store conditional commands
788 see table B-12 and B-13 of the openVMS linker manual */
790 static boolean
791 etir_stc (abfd, cmd, ptr)
792 bfd *abfd;
793 int cmd;
794 unsigned char *ptr;
797 #if VMS_DEBUG
798 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
799 _bfd_hexdump (8, ptr, 16, (int)ptr);
800 #endif
802 switch (cmd)
804 /* 200 Store-conditional Linkage Pair
805 arg: */
807 case ETIR_S_C_STC_LP:
808 (*_bfd_error_handler) (_("ETIR_S_C_STC_LP: not supported"));
809 break;
811 /* 201 Store-conditional Linkage Pair with Procedure Signature
812 arg: lw linkage index
813 cs procedure name
814 by signature length
815 da signature */
817 case ETIR_S_C_STC_LP_PSB:
818 image_inc_ptr (abfd, 16); /* skip entry,procval */
819 break;
821 /* 202 Store-conditional Address at global address
822 arg: lw linkage index
823 cs global name */
825 case ETIR_S_C_STC_GBL:
826 (*_bfd_error_handler) (_("ETIR_S_C_STC_GBL: not supported"));
827 break;
829 /* 203 Store-conditional Code Address at global address
830 arg: lw linkage index
831 cs procedure name */
833 case ETIR_S_C_STC_GCA:
834 (*_bfd_error_handler) (_("ETIR_S_C_STC_GCA: not supported"));
835 break;
837 /* 204 Store-conditional Address at psect + offset
838 arg: lw linkage index
839 lw psect index
840 qw offset */
842 case ETIR_S_C_STC_PS:
843 (*_bfd_error_handler) (_("ETIR_S_C_STC_PS: not supported"));
844 break;
846 /* 205 Store-conditional NOP at address of global
847 arg: */
849 case ETIR_S_C_STC_NOP_GBL:
851 /* 206 Store-conditional NOP at pect + offset
852 arg: */
854 case ETIR_S_C_STC_NOP_PS:
856 /* 207 Store-conditional BSR at global address
857 arg: */
859 case ETIR_S_C_STC_BSR_GBL:
861 /* 208 Store-conditional BSR at pect + offset
862 arg: */
864 case ETIR_S_C_STC_BSR_PS:
866 /* 209 Store-conditional LDA at global address
867 arg: */
869 case ETIR_S_C_STC_LDA_GBL:
871 /* 210 Store-conditional LDA at psect + offset
872 arg: */
874 case ETIR_S_C_STC_LDA_PS:
876 /* 211 Store-conditional BSR or Hint at global address
877 arg: */
879 case ETIR_S_C_STC_BOH_GBL:
881 /* 212 Store-conditional BSR or Hint at pect + offset
882 arg: */
884 case ETIR_S_C_STC_BOH_PS:
886 /* 213 Store-conditional NOP,BSR or HINT at global address
887 arg: */
889 case ETIR_S_C_STC_NBH_GBL:
891 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
892 arg: */
894 case ETIR_S_C_STC_NBH_PS:
895 /* FIXME (*_bfd_error_handler) ("ETIR_S_C_STC_xx: (%d) not supported", cmd); */
896 break;
898 default:
899 #if VMS_DEBUG
900 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd);
901 #endif
902 break;
904 return true;
908 static asection *
909 new_section (abfd, idx)
910 bfd *abfd;
911 int idx;
913 asection *section;
914 char sname[16];
915 char *name;
917 #if VMS_DEBUG
918 _bfd_vms_debug (5, "new_section %d\n", idx);
919 #endif
920 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
922 name = bfd_malloc (strlen (sname) + 1);
923 if (name == 0)
924 return 0;
925 strcpy (name, sname);
927 section = bfd_malloc (sizeof (asection));
928 if (section == 0)
930 #if VMS_DEBUG
931 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
932 #endif
933 return 0;
936 section->_raw_size = 0;
937 section->vma = 0;
938 section->contents = 0;
939 section->_cooked_size = 0;
940 section->name = name;
941 section->index = idx;
943 return section;
947 static int
948 alloc_section (abfd, idx)
949 bfd *abfd;
950 int idx;
952 asection *section;
954 #if VMS_DEBUG
955 _bfd_vms_debug (4, "alloc_section %d\n", idx);
956 #endif
958 PRIV(sections) = ((asection **)
959 bfd_realloc (PRIV(sections), (idx+1) * sizeof (asection *)));
960 if (PRIV(sections) == 0)
961 return -1;
963 while (PRIV(section_count) <= idx)
965 PRIV(sections)[PRIV(section_count)] = new_section (abfd, PRIV(section_count));
966 if (PRIV(sections)[PRIV(section_count)] == 0)
967 return -1;
968 PRIV(section_count)++;
971 return 0;
976 * tir_sta
978 * vax stack commands
980 * handle sta_xxx commands in tir section
981 * ptr points to data area in record
983 * see table 7-3 of the VAX/VMS linker manual
986 static unsigned char *
987 tir_sta (bfd *abfd, unsigned char *ptr)
989 int cmd = *ptr++;
991 #if VMS_DEBUG
992 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
993 #endif
995 switch (cmd)
997 /* stack */
998 case TIR_S_C_STA_GBL:
1000 * stack global
1001 * arg: cs symbol name
1003 * stack 32 bit value of symbol (high bits set to 0)
1006 char *name;
1007 vms_symbol_entry *entry;
1009 name = _bfd_vms_save_counted_string (ptr);
1011 entry = _bfd_vms_enter_symbol (abfd, name);
1012 if (entry == (vms_symbol_entry *)NULL)
1013 return 0;
1015 _bfd_vms_push (abfd, (unsigned long)(entry->symbol->value), -1);
1016 ptr += *ptr + 1;
1018 break;
1020 case TIR_S_C_STA_SB:
1022 * stack signed byte
1023 * arg: by value
1025 * stack byte value, sign extend to 32 bit
1027 _bfd_vms_push (abfd, (long)*ptr++, -1);
1028 break;
1030 case TIR_S_C_STA_SW:
1032 * stack signed short word
1033 * arg: sh value
1035 * stack 16 bit value, sign extend to 32 bit
1037 _bfd_vms_push (abfd, (long)bfd_getl16(ptr), -1);
1038 ptr += 2;
1039 break;
1041 case TIR_S_C_STA_LW:
1043 * stack signed longword
1044 * arg: lw value
1046 * stack 32 bit value
1048 _bfd_vms_push (abfd, (long)bfd_getl32 (ptr), -1);
1049 ptr += 4;
1050 break;
1052 case TIR_S_C_STA_PB:
1053 case TIR_S_C_STA_WPB:
1055 * stack psect base plus byte offset (word index)
1056 * arg: by section index
1057 * (sh section index)
1058 * by signed byte offset
1062 unsigned long dummy;
1063 int psect;
1065 if (cmd == TIR_S_C_STA_PB)
1066 psect = *ptr++;
1067 else
1069 psect = bfd_getl16(ptr);
1070 ptr += 2;
1073 if (psect >= PRIV(section_count))
1075 alloc_section (abfd, psect);
1078 dummy = (long)*ptr++;
1079 dummy += (PRIV(sections)[psect])->vma;
1080 _bfd_vms_push (abfd, dummy, psect);
1082 break;
1084 case TIR_S_C_STA_PW:
1085 case TIR_S_C_STA_WPW:
1087 * stack psect base plus word offset (word index)
1088 * arg: by section index
1089 * (sh section index)
1090 * sh signed short offset
1094 unsigned long dummy;
1095 int psect;
1097 if (cmd == TIR_S_C_STA_PW)
1098 psect = *ptr++;
1099 else
1101 psect = bfd_getl16(ptr);
1102 ptr += 2;
1105 if (psect >= PRIV(section_count))
1107 alloc_section (abfd, psect);
1110 dummy = bfd_getl16(ptr); ptr+=2;
1111 dummy += (PRIV(sections)[psect])->vma;
1112 _bfd_vms_push (abfd, dummy, psect);
1114 break;
1116 case TIR_S_C_STA_PL:
1117 case TIR_S_C_STA_WPL:
1119 * stack psect base plus long offset (word index)
1120 * arg: by section index
1121 * (sh section index)
1122 * lw signed longword offset
1126 unsigned long dummy;
1127 int psect;
1129 if (cmd == TIR_S_C_STA_PL)
1130 psect = *ptr++;
1131 else
1133 psect = bfd_getl16(ptr);
1134 ptr += 2;
1137 if (psect >= PRIV(section_count))
1139 alloc_section (abfd, psect);
1142 dummy = bfd_getl32 (ptr); ptr += 4;
1143 dummy += (PRIV(sections)[psect])->vma;
1144 _bfd_vms_push (abfd, dummy, psect);
1146 break;
1148 case TIR_S_C_STA_UB:
1150 * stack unsigned byte
1151 * arg: by value
1153 * stack byte value
1155 _bfd_vms_push (abfd, (unsigned long)*ptr++, -1);
1156 break;
1158 case TIR_S_C_STA_UW:
1160 * stack unsigned short word
1161 * arg: sh value
1163 * stack 16 bit value
1165 _bfd_vms_push (abfd, (unsigned long)bfd_getl16(ptr), -1);
1166 ptr += 2;
1167 break;
1169 case TIR_S_C_STA_BFI:
1171 * stack byte from image
1172 * arg: -
1175 /*FALLTHRU*/
1176 case TIR_S_C_STA_WFI:
1178 * stack byte from image
1179 * arg: -
1182 /*FALLTHRU*/
1183 case TIR_S_C_STA_LFI:
1185 * stack byte from image
1186 * arg: -
1189 (*_bfd_error_handler) (_("Stack-from-image not implemented"));
1190 return NULL;
1192 case TIR_S_C_STA_EPM:
1194 * stack entry point mask
1195 * arg: cs symbol name
1197 * stack (unsigned) entry point mask of symbol
1198 * err if symbol is no entry point
1201 char *name;
1202 vms_symbol_entry *entry;
1204 name = _bfd_vms_save_counted_string (ptr);
1205 entry = _bfd_vms_enter_symbol (abfd, name);
1206 if (entry == (vms_symbol_entry *)NULL)
1207 return 0;
1209 (*_bfd_error_handler) (_("Stack-entry-mask not fully implemented"));
1210 _bfd_vms_push (abfd, 0L, -1);
1211 ptr += *ptr + 1;
1213 break;
1215 case TIR_S_C_STA_CKARG:
1217 * compare procedure argument
1218 * arg: cs symbol name
1219 * by argument index
1220 * da argument descriptor
1222 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1223 * and stack TRUE (args match) or FALSE (args dont match) value
1225 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1226 _bfd_vms_push (abfd, 1L, -1);
1227 break;
1229 case TIR_S_C_STA_LSY:
1231 * stack local symbol value
1232 * arg: sh environment index
1233 * cs symbol name
1236 int envidx;
1237 char *name;
1238 vms_symbol_entry *entry;
1240 envidx = bfd_getl16(ptr); ptr += 2;
1241 name = _bfd_vms_save_counted_string (ptr);
1242 entry = _bfd_vms_enter_symbol (abfd, name);
1243 if (entry == (vms_symbol_entry *)NULL)
1244 return 0;
1245 (*_bfd_error_handler) (_("Stack-local-symbol not fully implemented"));
1246 _bfd_vms_push (abfd, 0L, -1);
1247 ptr += *ptr + 1;
1249 break;
1251 case TIR_S_C_STA_LIT:
1253 * stack literal
1254 * arg: by literal index
1256 * stack literal
1258 ptr++;
1259 _bfd_vms_push (abfd, 0L, -1);
1260 (*_bfd_error_handler) (_("Stack-literal not fully implemented"));
1261 break;
1263 case TIR_S_C_STA_LEPM:
1265 * stack local symbol entry point mask
1266 * arg: sh environment index
1267 * cs symbol name
1269 * stack (unsigned) entry point mask of symbol
1270 * err if symbol is no entry point
1273 int envidx;
1274 char *name;
1275 vms_symbol_entry *entry;
1277 envidx = bfd_getl16(ptr); ptr += 2;
1278 name = _bfd_vms_save_counted_string (ptr);
1279 entry = _bfd_vms_enter_symbol (abfd, name);
1280 if (entry == (vms_symbol_entry *)NULL)
1281 return 0;
1282 (*_bfd_error_handler) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1283 _bfd_vms_push (abfd, 0L, -1);
1284 ptr += *ptr + 1;
1286 break;
1288 default:
1289 (*_bfd_error_handler) (_("Reserved STA cmd %d"), ptr[-1]);
1290 return NULL;
1291 break;
1294 return ptr;
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
1309 static unsigned char *
1310 tir_sto (bfd *abfd, unsigned char *ptr)
1312 unsigned long dummy;
1313 int size;
1314 int psect;
1316 #if VMS_DEBUG
1317 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1318 #endif
1320 switch (*ptr++)
1322 case TIR_S_C_STO_SB:
1324 * store signed byte: pop stack, write byte
1325 * arg: -
1327 dummy = _bfd_vms_pop (abfd, &psect);
1328 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1329 break;
1331 case TIR_S_C_STO_SW:
1333 * store signed word: pop stack, write word
1334 * arg: -
1336 dummy = _bfd_vms_pop (abfd, &psect);
1337 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1338 break;
1340 case TIR_S_C_STO_LW:
1342 * store longword: pop stack, write longword
1343 * arg: -
1345 dummy = _bfd_vms_pop (abfd, &psect);
1346 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1347 break;
1349 case TIR_S_C_STO_BD:
1351 * store byte displaced: pop stack, sub lc+1, write byte
1352 * arg: -
1354 dummy = _bfd_vms_pop (abfd, &psect);
1355 dummy -= ((PRIV(sections)[psect])->vma + 1);
1356 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1357 break;
1359 case TIR_S_C_STO_WD:
1361 * store word displaced: pop stack, sub lc+2, write word
1362 * arg: -
1364 dummy = _bfd_vms_pop (abfd, &psect);
1365 dummy -= ((PRIV(sections)[psect])->vma + 2);
1366 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1367 break;
1368 case TIR_S_C_STO_LD:
1370 * store long displaced: pop stack, sub lc+4, write long
1371 * arg: -
1373 dummy = _bfd_vms_pop (abfd, &psect);
1374 dummy -= ((PRIV(sections)[psect])->vma + 4);
1375 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1376 break;
1377 case TIR_S_C_STO_LI:
1379 * store short literal: pop stack, write byte
1380 * arg: -
1382 dummy = _bfd_vms_pop (abfd, &psect);
1383 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1384 break;
1385 case TIR_S_C_STO_PIDR:
1387 * store position independent data reference: pop stack, write longword
1388 * arg: -
1389 * FIXME: incomplete !
1391 dummy = _bfd_vms_pop (abfd, &psect);
1392 image_write_l (abfd, dummy & 0xffffffff);
1393 break;
1394 case TIR_S_C_STO_PICR:
1396 * store position independent code reference: pop stack, write longword
1397 * arg: -
1398 * FIXME: incomplete !
1400 dummy = _bfd_vms_pop (abfd, &psect);
1401 image_write_b (abfd, 0x9f);
1402 image_write_l (abfd, dummy & 0xffffffff);
1403 break;
1404 case TIR_S_C_STO_RIVB:
1406 * store repeated immediate variable bytes
1407 * 1-byte count n field followed by n bytes of data
1408 * pop stack, write n bytes <stack> times
1410 size = *ptr++;
1411 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1412 while (dummy-- > 0L)
1413 image_dump (abfd, ptr, size, 0);
1414 ptr += size;
1415 break;
1416 case TIR_S_C_STO_B:
1418 * store byte from top longword
1420 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1421 image_write_b (abfd, dummy & 0xff);
1422 break;
1423 case TIR_S_C_STO_W:
1425 * store word from top longword
1427 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1428 image_write_w (abfd, dummy & 0xffff);
1429 break;
1430 case TIR_S_C_STO_RB:
1432 * store repeated byte from top longword
1434 size = (unsigned long)_bfd_vms_pop (abfd, NULL);
1435 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1436 while (size-- > 0)
1437 image_write_b (abfd, dummy & 0xff);
1438 break;
1439 case TIR_S_C_STO_RW:
1441 * store repeated word from top longword
1443 size = (unsigned long)_bfd_vms_pop (abfd, NULL);
1444 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1445 while (size-- > 0)
1446 image_write_w (abfd, dummy & 0xffff);
1447 break;
1449 case TIR_S_C_STO_RSB:
1450 case TIR_S_C_STO_RSW:
1451 case TIR_S_C_STO_RL:
1452 case TIR_S_C_STO_VPS:
1453 case TIR_S_C_STO_USB:
1454 case TIR_S_C_STO_USW:
1455 case TIR_S_C_STO_RUB:
1456 case TIR_S_C_STO_RUW:
1457 case TIR_S_C_STO_PIRR:
1458 (*_bfd_error_handler) (_("Unimplemented STO cmd %d"), ptr[-1]);
1459 break;
1461 default:
1462 (*_bfd_error_handler) (_("Reserved STO cmd %d"), ptr[-1]);
1463 break;
1466 return ptr;
1471 * stack operator commands
1472 * all 32 bit signed arithmetic
1473 * all word just like a stack calculator
1474 * arguments are popped from stack, results are pushed on stack
1476 * see table 7-5 of the VAX/VMS linker manual
1479 static unsigned char *
1480 tir_opr (bfd *abfd, unsigned char *ptr)
1482 long op1, op2;
1484 #if VMS_DEBUG
1485 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1486 #endif
1488 switch (*ptr++)
1490 /* operation */
1491 case TIR_S_C_OPR_NOP:
1493 * no-op
1495 break;
1497 case TIR_S_C_OPR_ADD:
1499 * add
1501 op1 = (long)_bfd_vms_pop (abfd, NULL);
1502 op2 = (long)_bfd_vms_pop (abfd, NULL);
1503 _bfd_vms_push (abfd, (unsigned long)(op1 + op2), -1);
1504 break;
1506 case TIR_S_C_OPR_SUB:
1508 * subtract
1510 op1 = (long)_bfd_vms_pop (abfd, NULL);
1511 op2 = (long)_bfd_vms_pop (abfd, NULL);
1512 _bfd_vms_push (abfd, (unsigned long)(op2 - op1), -1);
1513 break;
1515 case TIR_S_C_OPR_MUL:
1517 * multiply
1519 op1 = (long)_bfd_vms_pop (abfd, NULL);
1520 op2 = (long)_bfd_vms_pop (abfd, NULL);
1521 _bfd_vms_push (abfd, (unsigned long)(op1 * op2), -1);
1522 break;
1524 case TIR_S_C_OPR_DIV:
1526 * divide
1528 op1 = (long)_bfd_vms_pop (abfd, NULL);
1529 op2 = (long)_bfd_vms_pop (abfd, NULL);
1530 if (op2 == 0)
1531 _bfd_vms_push (abfd, (unsigned long)0L, -1);
1532 else
1533 _bfd_vms_push (abfd, (unsigned long)(op2 / op1), -1);
1534 break;
1536 case TIR_S_C_OPR_AND:
1538 * logical and
1540 op1 = (long)_bfd_vms_pop (abfd, NULL);
1541 op2 = (long)_bfd_vms_pop (abfd, NULL);
1542 _bfd_vms_push (abfd, (unsigned long)(op1 & op2), -1);
1543 break;
1545 case TIR_S_C_OPR_IOR:
1546 op1 = (long)_bfd_vms_pop (abfd, NULL);
1548 * logical inclusive or
1550 op2 = (long)_bfd_vms_pop (abfd, NULL);
1551 _bfd_vms_push (abfd, (unsigned long)(op1 | op2), -1);
1552 break;
1554 case TIR_S_C_OPR_EOR:
1556 * logical exclusive or
1558 op1 = (long)_bfd_vms_pop (abfd, NULL);
1559 op2 = (long)_bfd_vms_pop (abfd, NULL);
1560 _bfd_vms_push (abfd, (unsigned long)(op1 ^ op2), -1);
1561 break;
1563 case TIR_S_C_OPR_NEG:
1565 * negate
1567 op1 = (long)_bfd_vms_pop (abfd, NULL);
1568 _bfd_vms_push (abfd, (unsigned long)(-op1), -1);
1569 break;
1571 case TIR_S_C_OPR_COM:
1573 * complement
1575 op1 = (long)_bfd_vms_pop (abfd, NULL);
1576 _bfd_vms_push (abfd, (unsigned long)(op1 ^ -1L), -1);
1577 break;
1579 case TIR_S_C_OPR_INSV:
1581 * insert field
1583 (void)_bfd_vms_pop (abfd, NULL);
1584 (*_bfd_error_handler) ("TIR_S_C_OPR_INSV incomplete");
1585 break;
1587 case TIR_S_C_OPR_ASH:
1589 * arithmetic shift
1591 op1 = (long)_bfd_vms_pop (abfd, NULL);
1592 op2 = (long)_bfd_vms_pop (abfd, NULL);
1593 if (HIGHBIT(op1)) /* shift right */
1594 op2 >>= op1;
1595 else /* shift left */
1596 op2 <<= op1;
1597 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1598 (*_bfd_error_handler) (_("TIR_S_C_OPR_ASH incomplete"));
1599 break;
1601 case TIR_S_C_OPR_USH:
1603 * unsigned shift
1605 op1 = (long)_bfd_vms_pop (abfd, NULL);
1606 op2 = (long)_bfd_vms_pop (abfd, NULL);
1607 if (HIGHBIT(op1)) /* shift right */
1608 op2 >>= op1;
1609 else /* shift left */
1610 op2 <<= op1;
1611 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1612 (*_bfd_error_handler) (_("TIR_S_C_OPR_USH incomplete"));
1613 break;
1615 case TIR_S_C_OPR_ROT:
1617 * rotate
1619 op1 = (long)_bfd_vms_pop (abfd, NULL);
1620 op2 = (long)_bfd_vms_pop (abfd, NULL);
1621 if (HIGHBIT(0)) /* shift right */
1622 op2 >>= op1;
1623 else /* shift left */
1624 op2 <<= op1;
1625 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1626 (*_bfd_error_handler) (_("TIR_S_C_OPR_ROT incomplete"));
1627 break;
1629 case TIR_S_C_OPR_SEL:
1631 * select
1633 if ((long)_bfd_vms_pop (abfd, NULL) & 0x01L)
1634 (void)_bfd_vms_pop (abfd, NULL);
1635 else
1637 op1 = (long)_bfd_vms_pop (abfd, NULL);
1638 (void)_bfd_vms_pop (abfd, NULL);
1639 _bfd_vms_push (abfd, (unsigned long)op1, -1);
1641 break;
1643 case TIR_S_C_OPR_REDEF:
1645 * redefine symbol to current location
1647 (*_bfd_error_handler) (_("TIR_S_C_OPR_REDEF not supported"));
1648 break;
1650 case TIR_S_C_OPR_DFLIT:
1652 * define a literal
1654 (*_bfd_error_handler) (_("TIR_S_C_OPR_DFLIT not supported"));
1655 break;
1657 default:
1658 (*_bfd_error_handler) (_("Reserved OPR cmd %d"), ptr[-1]);
1659 break;
1662 return ptr;
1666 static unsigned char *
1667 tir_ctl (bfd *abfd, unsigned char *ptr)
1669 * control commands
1671 * see table 7-6 of the VAX/VMS linker manual
1674 unsigned long dummy;
1675 int psect;
1677 #if VMS_DEBUG
1678 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1679 #endif
1681 switch (*ptr++)
1683 case TIR_S_C_CTL_SETRB:
1685 * set relocation base: pop stack, set image location counter
1686 * arg: -
1688 dummy = _bfd_vms_pop (abfd, &psect);
1689 if (psect >= PRIV(section_count))
1691 alloc_section (abfd, psect);
1693 image_set_ptr (abfd, psect, dummy);
1694 break;
1695 case TIR_S_C_CTL_AUGRB:
1697 * augment relocation base: increment image location counter by offset
1698 * arg: lw offset value
1700 dummy = bfd_getl32 (ptr);
1701 image_inc_ptr (abfd, dummy);
1702 break;
1703 case TIR_S_C_CTL_DFLOC:
1705 * define location: pop index, save location counter under index
1706 * arg: -
1708 dummy = _bfd_vms_pop (abfd, NULL);
1709 (*_bfd_error_handler) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1710 break;
1711 case TIR_S_C_CTL_STLOC:
1713 * set location: pop index, restore location counter from index
1714 * arg: -
1716 dummy = _bfd_vms_pop (abfd, &psect);
1717 (*_bfd_error_handler) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1718 break;
1719 case TIR_S_C_CTL_STKDL:
1721 * stack defined location: pop index, push location counter from index
1722 * arg: -
1724 dummy = _bfd_vms_pop (abfd, &psect);
1725 (*_bfd_error_handler) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1726 break;
1727 default:
1728 (*_bfd_error_handler) (_("Reserved CTL cmd %d"), ptr[-1]);
1729 break;
1731 return ptr;
1736 * handle command from TIR section
1739 static unsigned char *
1740 tir_cmd (bfd *abfd, unsigned char *ptr)
1742 struct {
1743 int mincod;
1744 int maxcod;
1745 unsigned char * (*explain)(bfd *, unsigned char *);
1746 } tir_table[] = {
1747 { 0, TIR_S_C_MAXSTACOD, tir_sta }
1748 ,{ TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto }
1749 ,{ TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr }
1750 ,{ TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl }
1751 ,{ -1, -1, NULL }
1753 int i = 0;
1755 #if VMS_DEBUG
1756 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1757 _bfd_hexdump (8, ptr, 16, (int)ptr);
1758 #endif
1760 if (*ptr & 0x80) /* store immediate */
1762 i = 128 - (*ptr++ & 0x7f);
1763 image_dump (abfd, ptr, i, 0);
1764 ptr += i;
1766 else
1768 while (tir_table[i].mincod >= 0)
1770 if ( (tir_table[i].mincod <= *ptr)
1771 && (*ptr <= tir_table[i].maxcod))
1773 ptr = tir_table[i].explain (abfd, ptr);
1774 break;
1776 i++;
1778 if (tir_table[i].mincod < 0)
1780 (*_bfd_error_handler) (_("Obj code %d not found"), *ptr);
1781 ptr = 0;
1785 return ptr;
1789 /* handle command from ETIR section */
1791 static int
1792 etir_cmd (abfd, cmd, ptr)
1793 bfd *abfd;
1794 int cmd;
1795 unsigned char *ptr;
1797 static struct {
1798 int mincod;
1799 int maxcod;
1800 boolean (*explain) PARAMS((bfd *, int, unsigned char *));
1801 } etir_table[] = {
1802 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1803 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1804 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1805 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1806 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1807 { -1, -1, NULL }
1810 int i = 0;
1812 #if VMS_DEBUG
1813 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1814 _bfd_hexdump (8, ptr, 16, (int)ptr);
1815 #endif
1817 while (etir_table[i].mincod >= 0)
1819 if ( (etir_table[i].mincod <= cmd)
1820 && (cmd <= etir_table[i].maxcod))
1822 if (!etir_table[i].explain (abfd, cmd, ptr))
1823 return -1;
1824 break;
1826 i++;
1829 #if VMS_DEBUG
1830 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1831 #endif
1832 return 0;
1836 /* Text Information and Relocation Records (OBJ$C_TIR)
1837 handle tir record */
1839 static int
1840 analyze_tir (abfd, ptr, length)
1841 bfd *abfd;
1842 unsigned char *ptr;
1843 unsigned int length;
1845 unsigned char *maxptr;
1847 #if VMS_DEBUG
1848 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1849 #endif
1851 maxptr = ptr + length;
1853 while (ptr < maxptr)
1855 ptr = tir_cmd (abfd, ptr);
1856 if (ptr == 0)
1857 return -1;
1860 return 0;
1864 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1865 handle etir record */
1867 static int
1868 analyze_etir (abfd, ptr, length)
1869 bfd *abfd;
1870 unsigned char *ptr;
1871 unsigned int length;
1873 int cmd;
1874 unsigned char *maxptr;
1875 int result = 0;
1877 #if VMS_DEBUG
1878 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1879 #endif
1881 maxptr = ptr + length;
1883 while (ptr < maxptr)
1885 cmd = bfd_getl16 (ptr);
1886 length = bfd_getl16 (ptr + 2);
1887 result = etir_cmd (abfd, cmd, ptr+4);
1888 if (result != 0)
1889 break;
1890 ptr += length;
1893 #if VMS_DEBUG
1894 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1895 #endif
1897 return result;
1901 /* process ETIR record
1903 return 0 on success, -1 on error */
1906 _bfd_vms_slurp_tir (abfd, objtype)
1907 bfd *abfd;
1908 int objtype;
1910 int result;
1912 #if VMS_DEBUG
1913 _bfd_vms_debug (2, "TIR/ETIR\n");
1914 #endif
1916 switch (objtype)
1918 case EOBJ_S_C_ETIR:
1919 PRIV(vms_rec) += 4; /* skip type, size */
1920 PRIV(rec_size) -= 4;
1921 result = analyze_etir (abfd, PRIV(vms_rec), PRIV(rec_size));
1922 break;
1923 case OBJ_S_C_TIR:
1924 PRIV(vms_rec) += 1; /* skip type */
1925 PRIV(rec_size) -= 1;
1926 result = analyze_tir (abfd, PRIV(vms_rec), PRIV(rec_size));
1927 break;
1928 default:
1929 result = -1;
1930 break;
1933 return result;
1937 /* process EDBG record
1938 return 0 on success, -1 on error
1940 not implemented yet */
1943 _bfd_vms_slurp_dbg (abfd, objtype)
1944 bfd *abfd;
1945 int objtype;
1947 #if VMS_DEBUG
1948 _bfd_vms_debug (2, "DBG/EDBG\n");
1949 #endif
1951 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1952 return 0;
1956 /* process ETBT record
1957 return 0 on success, -1 on error
1959 not implemented yet */
1962 _bfd_vms_slurp_tbt (abfd, objtype)
1963 bfd *abfd;
1964 int objtype;
1966 #if VMS_DEBUG
1967 _bfd_vms_debug (2, "TBT/ETBT\n");
1968 #endif
1970 return 0;
1974 /* process LNK record
1975 return 0 on success, -1 on error
1977 not implemented yet */
1980 _bfd_vms_slurp_lnk (abfd, objtype)
1981 bfd *abfd;
1982 int objtype;
1984 #if VMS_DEBUG
1985 _bfd_vms_debug (2, "LNK\n");
1986 #endif
1988 return 0;
1991 /*----------------------------------------------------------------------*/
1992 /* */
1993 /* WRITE ETIR SECTION */
1994 /* */
1995 /* this is still under construction and therefore not documented */
1996 /* */
1997 /*----------------------------------------------------------------------*/
1999 static void start_etir_record PARAMS ((bfd *abfd, int index, uquad offset, boolean justoffset));
2000 static void sto_imm PARAMS ((bfd *abfd, vms_section *sptr, bfd_vma vaddr, int index));
2001 static void end_etir_record PARAMS ((bfd *abfd));
2003 static void
2004 sto_imm (abfd, sptr, vaddr, index)
2005 bfd *abfd;
2006 vms_section *sptr;
2007 bfd_vma vaddr;
2008 int index;
2010 int size;
2011 int ssize;
2012 unsigned char *cptr;
2014 #if VMS_DEBUG
2015 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
2016 _bfd_hexdump (9, sptr->contents, (int)sptr->size, (int)vaddr);
2017 #endif
2019 ssize = sptr->size;
2020 cptr = sptr->contents;
2022 while (ssize > 0)
2025 size = ssize; /* try all the rest */
2027 if (_bfd_vms_output_check (abfd, size) < 0)
2028 { /* doesn't fit, split ! */
2029 end_etir_record (abfd);
2030 start_etir_record (abfd, index, vaddr, false);
2031 size = _bfd_vms_output_check (abfd, 0); /* get max size */
2032 if (size > ssize) /* more than what's left ? */
2033 size = ssize;
2036 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
2037 _bfd_vms_output_long (abfd, (unsigned long)(size));
2038 _bfd_vms_output_dump (abfd, cptr, size);
2039 _bfd_vms_output_flush (abfd);
2041 #if VMS_DEBUG
2042 _bfd_vms_debug (10, "dumped %d bytes\n", size);
2043 _bfd_hexdump (10, cptr, (int)size, (int)vaddr);
2044 #endif
2046 vaddr += size;
2047 ssize -= size;
2048 cptr += size;
2051 return;
2054 /*-------------------------------------------------------------------*/
2056 /* start ETIR record for section #index at virtual addr offset. */
2058 static void
2059 start_etir_record (abfd, index, offset, justoffset)
2060 bfd *abfd;
2061 int index;
2062 uquad offset;
2063 boolean justoffset;
2065 if (!justoffset)
2067 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
2068 _bfd_vms_output_push (abfd);
2071 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
2072 _bfd_vms_output_long (abfd, (unsigned long)index);
2073 _bfd_vms_output_quad (abfd, (uquad)offset);
2074 _bfd_vms_output_flush (abfd);
2076 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop () */
2077 _bfd_vms_output_flush (abfd);
2079 return;
2083 /* end etir record */
2084 static void
2085 end_etir_record (abfd)
2086 bfd *abfd;
2088 _bfd_vms_output_pop (abfd);
2089 _bfd_vms_output_end (abfd);
2092 /* write section contents for bfd abfd */
2095 _bfd_vms_write_tir (abfd, objtype)
2096 bfd *abfd;
2097 int objtype;
2099 asection *section;
2100 vms_section *sptr;
2101 int nextoffset;
2103 #if VMS_DEBUG
2104 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
2105 #endif
2107 _bfd_vms_output_alignment (abfd, 4);
2109 nextoffset = 0;
2110 PRIV(vms_linkage_index) = 1;
2112 /* dump all other sections */
2114 section = abfd->sections;
2116 while (section != NULL)
2119 #if VMS_DEBUG
2120 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n", section->index, section->name, (int)(section->_raw_size));
2121 #endif
2123 if (section->flags & SEC_RELOC)
2125 int i;
2127 if ((i = section->reloc_count) <= 0)
2129 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
2130 section->name);
2132 #if VMS_DEBUG
2133 else
2135 arelent **rptr;
2136 _bfd_vms_debug (4, "%d relocations:\n", i);
2137 rptr = section->orelocation;
2138 while (i-- > 0)
2140 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2141 (*(*rptr)->sym_ptr_ptr)->name,
2142 (*(*rptr)->sym_ptr_ptr)->section->name,
2143 (long)(*(*rptr)->sym_ptr_ptr)->value,
2144 (*rptr)->address, (*rptr)->addend,
2145 bfd_get_reloc_size((*rptr)->howto),
2146 (*rptr)->howto->name);
2147 rptr++;
2150 #endif
2153 if ((section->flags & SEC_HAS_CONTENTS)
2154 && (! bfd_is_com_section (section)))
2156 bfd_vma vaddr; /* virtual addr in section */
2158 sptr = _bfd_get_vms_section (abfd, section->index);
2159 if (sptr == NULL)
2161 bfd_set_error (bfd_error_no_contents);
2162 return -1;
2165 vaddr = (bfd_vma)(sptr->offset);
2167 start_etir_record (abfd, section->index, (uquad) sptr->offset,
2168 false);
2170 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per vms_section */
2173 if (section->flags & SEC_RELOC) /* check for relocs */
2175 arelent **rptr = section->orelocation;
2176 int i = section->reloc_count;
2177 for (;;)
2179 bfd_size_type addr = (*rptr)->address;
2180 int len = bfd_get_reloc_size ((*rptr)->howto);
2181 if (sptr->offset < addr) /* sptr starts before reloc */
2183 int before = addr - sptr->offset;
2184 if (sptr->size <= before) /* complete before */
2186 sto_imm (abfd, sptr, vaddr, section->index);
2187 vaddr += sptr->size;
2188 break;
2190 else /* partly before */
2192 int after = sptr->size - before;
2193 sptr->size = before;
2194 sto_imm (abfd, sptr, vaddr, section->index);
2195 vaddr += sptr->size;
2196 sptr->contents += before;
2197 sptr->offset += before;
2198 sptr->size = after;
2201 else if (sptr->offset == addr) /* sptr starts at reloc */
2203 asymbol *sym = *(*rptr)->sym_ptr_ptr;
2204 asection *sec = sym->section;
2206 switch ((*rptr)->howto->type)
2208 case ALPHA_R_IGNORE:
2209 break;
2211 case ALPHA_R_REFLONG:
2213 if (bfd_is_und_section (sym->section))
2215 if (_bfd_vms_output_check (abfd,
2216 strlen((char *)sym->name))
2217 < 0)
2219 end_etir_record (abfd);
2220 start_etir_record (abfd,
2221 section->index,
2222 vaddr, false);
2224 _bfd_vms_output_begin (abfd,
2225 ETIR_S_C_STO_GBL_LW,
2226 -1);
2227 _bfd_vms_output_counted (abfd,
2228 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2229 _bfd_vms_output_flush (abfd);
2231 else if (bfd_is_abs_section (sym->section))
2233 if (_bfd_vms_output_check (abfd, 16) < 0)
2235 end_etir_record (abfd);
2236 start_etir_record (abfd,
2237 section->index,
2238 vaddr, false);
2240 _bfd_vms_output_begin (abfd,
2241 ETIR_S_C_STA_LW,
2242 -1);
2243 _bfd_vms_output_quad (abfd,
2244 (uquad)sym->value);
2245 _bfd_vms_output_flush (abfd);
2246 _bfd_vms_output_begin (abfd,
2247 ETIR_S_C_STO_LW,
2248 -1);
2249 _bfd_vms_output_flush (abfd);
2251 else
2253 if (_bfd_vms_output_check (abfd, 32) < 0)
2255 end_etir_record (abfd);
2256 start_etir_record (abfd,
2257 section->index,
2258 vaddr, false);
2260 _bfd_vms_output_begin (abfd,
2261 ETIR_S_C_STA_PQ,
2262 -1);
2263 _bfd_vms_output_long (abfd,
2264 (unsigned long)(sec->index));
2265 _bfd_vms_output_quad (abfd,
2266 ((uquad)(*rptr)->addend
2267 + (uquad)sym->value));
2268 _bfd_vms_output_flush (abfd);
2269 _bfd_vms_output_begin (abfd,
2270 ETIR_S_C_STO_LW,
2271 -1);
2272 _bfd_vms_output_flush (abfd);
2275 break;
2277 case ALPHA_R_REFQUAD:
2279 if (bfd_is_und_section (sym->section))
2281 if (_bfd_vms_output_check (abfd,
2282 strlen((char *)sym->name))
2283 < 0)
2285 end_etir_record (abfd);
2286 start_etir_record (abfd,
2287 section->index,
2288 vaddr, false);
2290 _bfd_vms_output_begin (abfd,
2291 ETIR_S_C_STO_GBL,
2292 -1);
2293 _bfd_vms_output_counted (abfd,
2294 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2295 _bfd_vms_output_flush (abfd);
2297 else if (bfd_is_abs_section (sym->section))
2299 if (_bfd_vms_output_check (abfd, 16) < 0)
2301 end_etir_record (abfd);
2302 start_etir_record (abfd,
2303 section->index,
2304 vaddr, false);
2306 _bfd_vms_output_begin (abfd,
2307 ETIR_S_C_STA_QW,
2308 -1);
2309 _bfd_vms_output_quad (abfd,
2310 (uquad)sym->value);
2311 _bfd_vms_output_flush (abfd);
2312 _bfd_vms_output_begin (abfd,
2313 ETIR_S_C_STO_QW,
2314 -1);
2315 _bfd_vms_output_flush (abfd);
2317 else
2319 if (_bfd_vms_output_check (abfd, 32) < 0)
2321 end_etir_record (abfd);
2322 start_etir_record (abfd,
2323 section->index,
2324 vaddr, false);
2326 _bfd_vms_output_begin (abfd,
2327 ETIR_S_C_STA_PQ,
2328 -1);
2329 _bfd_vms_output_long (abfd,
2330 (unsigned long)(sec->index));
2331 _bfd_vms_output_quad (abfd,
2332 ((uquad)(*rptr)->addend
2333 + (uquad)sym->value));
2334 _bfd_vms_output_flush (abfd);
2335 _bfd_vms_output_begin (abfd,
2336 ETIR_S_C_STO_OFF,
2337 -1);
2338 _bfd_vms_output_flush (abfd);
2341 break;
2343 case ALPHA_R_HINT:
2345 int hint_size;
2347 hint_size = sptr->size;
2348 sptr->size = len;
2349 sto_imm (abfd, sptr, vaddr, section->index);
2350 sptr->size = hint_size;
2351 #if 0
2352 vms_output_begin(abfd, ETIR_S_C_STO_HINT_GBL, -1);
2353 vms_output_long(abfd, (unsigned long)(sec->index));
2354 vms_output_quad(abfd, (uquad)addr);
2356 vms_output_counted(abfd, _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2357 vms_output_flush(abfd);
2358 #endif
2360 break;
2361 case ALPHA_R_LINKAGE:
2363 if (_bfd_vms_output_check (abfd, 64) < 0)
2365 end_etir_record (abfd);
2366 start_etir_record (abfd, section->index,
2367 vaddr, false);
2369 _bfd_vms_output_begin (abfd,
2370 ETIR_S_C_STC_LP_PSB,
2371 -1);
2372 _bfd_vms_output_long (abfd,
2373 (unsigned long)PRIV(vms_linkage_index));
2374 PRIV(vms_linkage_index) += 2;
2375 _bfd_vms_output_counted (abfd,
2376 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2377 _bfd_vms_output_byte (abfd, 0);
2378 _bfd_vms_output_flush (abfd);
2380 break;
2382 case ALPHA_R_CODEADDR:
2384 if (_bfd_vms_output_check (abfd,
2385 strlen((char *)sym->name))
2386 < 0)
2388 end_etir_record (abfd);
2389 start_etir_record (abfd,
2390 section->index,
2391 vaddr, false);
2393 _bfd_vms_output_begin (abfd,
2394 ETIR_S_C_STO_CA,
2395 -1);
2396 _bfd_vms_output_counted (abfd,
2397 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2398 _bfd_vms_output_flush (abfd);
2400 break;
2402 default:
2403 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2404 (*rptr)->howto->name);
2405 break;
2408 vaddr += len;
2410 if (len == sptr->size)
2412 break;
2414 else
2416 sptr->contents += len;
2417 sptr->offset += len;
2418 sptr->size -= len;
2419 i--;
2420 rptr++;
2423 else /* sptr starts after reloc */
2425 i--; /* check next reloc */
2426 rptr++;
2429 if (i==0) /* all reloc checked */
2431 if (sptr->size > 0)
2433 sto_imm (abfd, sptr, vaddr, section->index); /* dump rest */
2434 vaddr += sptr->size;
2436 break;
2438 } /* for (;;) */
2439 } /* if SEC_RELOC */
2440 else /* no relocs, just dump */
2442 sto_imm (abfd, sptr, vaddr, section->index);
2443 vaddr += sptr->size;
2446 sptr = sptr->next;
2448 } /* while (sptr != 0) */
2450 end_etir_record (abfd);
2452 } /* has_contents */
2454 section = section->next;
2457 _bfd_vms_output_alignment(abfd, 2);
2458 return 0;
2462 /* write traceback data for bfd abfd */
2465 _bfd_vms_write_tbt (abfd, objtype)
2466 bfd *abfd;
2467 int objtype;
2469 #if VMS_DEBUG
2470 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2471 #endif
2473 return 0;
2477 /* write debug info for bfd abfd */
2480 _bfd_vms_write_dbg (abfd, objtype)
2481 bfd *abfd;
2482 int objtype;
2484 #if VMS_DEBUG
2485 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);
2486 #endif
2488 return 0;