* MAINTAINERS: Update my email address.
[binutils.git] / bfd / vms-tir.c
blob1f3446c734649668ae14d4d70643968e2c452a3b
1 /* vms-tir.c -- BFD back-end for VAX (openVMS/VAX) and
2 EVAX (openVMS/Alpha) files.
3 Copyright 1996, 1997, 1998, 1999, 2000 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. */
27 /* The following type abbreviations are used:
29 cs counted string (ascii string with length byte)
30 by byte (1 byte)
31 sh short (2 byte, 16 bit)
32 lw longword (4 byte, 32 bit)
33 qw quadword (8 byte, 64 bit)
34 da data stream */
36 #include <ctype.h>
38 #include "bfd.h"
39 #include "sysdep.h"
40 #include "bfdlink.h"
41 #include "libbfd.h"
43 #include "vms.h"
45 static void image_set_ptr PARAMS ((bfd *abfd, int psect, uquad offset));
46 static void image_inc_ptr PARAMS ((bfd *abfd, uquad offset));
47 static void image_dump PARAMS ((bfd *abfd, unsigned char *ptr, int size, int offset));
48 static void image_write_b PARAMS ((bfd *abfd, unsigned int value));
49 static void image_write_w PARAMS ((bfd *abfd, unsigned int value));
50 static void image_write_l PARAMS ((bfd *abfd, unsigned long value));
51 static void image_write_q PARAMS ((bfd *abfd, uquad value));
53 /*-----------------------------------------------------------------------------*/
55 static int
56 check_section (abfd, size)
57 bfd *abfd;
58 int size;
60 int offset;
62 offset = PRIV(image_ptr) - PRIV(image_section)->contents;
63 if ((bfd_size_type) (offset + size) > PRIV(image_section)->_raw_size)
65 PRIV(image_section)->contents = bfd_realloc (PRIV(image_section)->contents, offset + size);
66 if (PRIV(image_section)->contents == 0)
68 (*_bfd_error_handler) (_("No Mem !"));
69 return -1;
71 PRIV(image_section)->_raw_size = offset + size;
72 PRIV(image_ptr) = PRIV(image_section)->contents + offset;
75 return 0;
78 /* routines to fill sections contents during tir/etir read */
80 /* Initialize image buffer pointer to be filled */
82 static void
83 image_set_ptr (abfd, psect, offset)
84 bfd *abfd;
85 int psect;
86 uquad offset;
88 #if VMS_DEBUG
89 _bfd_vms_debug (4, "image_set_ptr (%d=%s, %d)\n",
90 psect, PRIV(sections)[psect]->name, offset);
91 #endif
93 PRIV(image_ptr) = PRIV(sections)[psect]->contents + offset;
94 PRIV(image_section) = PRIV(sections)[psect];
95 return;
98 /* Increment image buffer pointer by offset */
100 static void
101 image_inc_ptr (abfd, offset)
102 bfd *abfd;
103 uquad offset;
105 #if VMS_DEBUG
106 _bfd_vms_debug (4, "image_inc_ptr (%d)\n", offset);
107 #endif
109 PRIV(image_ptr) += offset;
111 return;
114 /* Dump multiple bytes to section image */
116 static void
117 image_dump (abfd, ptr, size, offset)
118 bfd *abfd;
119 unsigned char *ptr;
120 int size;
121 int offset ATTRIBUTE_UNUSED;
123 #if VMS_DEBUG
124 _bfd_vms_debug (8, "image_dump from (%p, %d) to (%p)\n", ptr, size, PRIV(image_ptr));
125 _bfd_hexdump (9, ptr, size, offset);
126 #endif
128 if (PRIV(is_vax) && check_section (abfd, size))
129 return;
131 while (size-- > 0)
132 *PRIV(image_ptr)++ = *ptr++;
133 return;
136 /* Write byte to section image */
138 static void
139 image_write_b (abfd, value)
140 bfd *abfd;
141 unsigned int value;
143 #if VMS_DEBUG
144 _bfd_vms_debug (6, "image_write_b(%02x)\n", (int)value);
145 #endif
147 if (PRIV(is_vax) && check_section (abfd, 1))
148 return;
150 *PRIV(image_ptr)++ = (value & 0xff);
151 return;
154 /* Write 2-byte word to image */
156 static void
157 image_write_w (abfd, value)
158 bfd *abfd;
159 unsigned int value;
161 #if VMS_DEBUG
162 _bfd_vms_debug (6, "image_write_w(%04x)\n", (int)value);
163 #endif
165 if (PRIV(is_vax) && check_section (abfd, 2))
166 return;
168 bfd_putl16 (value, PRIV(image_ptr));
169 PRIV(image_ptr) += 2;
171 return;
174 /* Write 4-byte long to image */
176 static void
177 image_write_l (abfd, value)
178 bfd *abfd;
179 unsigned long value;
181 #if VMS_DEBUG
182 _bfd_vms_debug (6, "image_write_l (%08lx)\n", value);
183 #endif
185 if (PRIV(is_vax) && check_section (abfd, 4))
186 return;
188 bfd_putl32 (value, PRIV(image_ptr));
189 PRIV(image_ptr) += 4;
191 return;
194 /* Write 8-byte quad to image */
196 static void
197 image_write_q (abfd, value)
198 bfd *abfd;
199 uquad value;
201 #if VMS_DEBUG
202 _bfd_vms_debug (6, "image_write_q (%016lx)\n", value);
203 #endif
205 if (PRIV(is_vax) && check_section (abfd, 8))
206 return;
208 bfd_putl64 (value, PRIV(image_ptr));
209 PRIV(image_ptr) += 8;
211 return;
215 #define HIGHBIT(op) ((op & 0x80000000L) == 0x80000000L)
217 /* etir_sta
219 vms stack commands
221 handle sta_xxx commands in etir section
222 ptr points to data area in record
224 see table B-8 of the openVMS linker manual */
226 static boolean
227 etir_sta (abfd, cmd, ptr)
228 bfd *abfd;
229 int cmd;
230 unsigned char *ptr;
233 #if VMS_DEBUG
234 _bfd_vms_debug (5, "etir_sta %d/%x\n", cmd, cmd);
235 _bfd_hexdump (8, ptr, 16, (int)ptr);
236 #endif
238 switch (cmd)
240 /* stack */
242 /* stack global
243 arg: cs symbol name
245 stack 32 bit value of symbol (high bits set to 0) */
247 case ETIR_S_C_STA_GBL:
249 char *name;
250 vms_symbol_entry *entry;
252 name = _bfd_vms_save_counted_string (ptr);
253 entry = (vms_symbol_entry *)
254 bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
255 if (entry == (vms_symbol_entry *)NULL)
257 #if VMS_DEBUG
258 _bfd_vms_debug (3, "ETIR_S_C_STA_GBL: no symbol \"%s\"\n", name);
259 #endif
260 _bfd_vms_push (abfd, (uquad)0, -1);
262 else
264 _bfd_vms_push (abfd, (uquad) (entry->symbol->value), -1);
267 break;
269 /* stack longword
270 arg: lw value
272 stack 32 bit value, sign extend to 64 bit */
274 case ETIR_S_C_STA_LW:
275 _bfd_vms_push (abfd, (uquad)bfd_getl32 (ptr), -1);
276 break;
278 /* stack global
279 arg: qw value
281 stack 64 bit value of symbol */
283 case ETIR_S_C_STA_QW:
284 _bfd_vms_push (abfd, (uquad)bfd_getl64(ptr), -1);
285 break;
287 /* stack psect base plus quadword offset
288 arg: lw section index
289 qw signed quadword offset (low 32 bits)
291 stack qw argument and section index
292 (see ETIR_S_C_STO_OFF, ETIR_S_C_CTL_SETRB) */
294 case ETIR_S_C_STA_PQ:
296 uquad dummy;
297 unsigned int psect;
299 psect = bfd_getl32 (ptr);
300 if (psect >= PRIV(section_count))
302 (*_bfd_error_handler) (_("Bad section index in ETIR_S_C_STA_PQ"));
303 bfd_set_error (bfd_error_bad_value);
304 return false;
306 dummy = bfd_getl64 (ptr+4);
307 _bfd_vms_push (abfd, dummy, psect);
309 break;
311 /* all not supported */
313 case ETIR_S_C_STA_LI:
314 case ETIR_S_C_STA_MOD:
315 case ETIR_S_C_STA_CKARG:
317 (*_bfd_error_handler) (_("Unsupported STA cmd %d"), cmd);
318 return false;
319 break;
321 default:
322 (*_bfd_error_handler) (_("Reserved STA cmd %d"), cmd);
323 return false;
324 break;
326 #if VMS_DEBUG
327 _bfd_vms_debug (5, "etir_sta true\n");
328 #endif
329 return true;
333 etir_sto
335 vms store commands
337 handle sto_xxx commands in etir section
338 ptr points to data area in record
340 see table B-9 of the openVMS linker manual */
342 static boolean
343 etir_sto (abfd, cmd, ptr)
344 bfd *abfd;
345 int cmd;
346 unsigned char *ptr;
348 uquad dummy;
349 int psect;
351 #if VMS_DEBUG
352 _bfd_vms_debug (5, "etir_sto %d/%x\n", cmd, cmd);
353 _bfd_hexdump (8, ptr, 16, (int)ptr);
354 #endif
356 switch (cmd)
359 /* store byte: pop stack, write byte
360 arg: - */
362 case ETIR_S_C_STO_B:
363 dummy = _bfd_vms_pop (abfd, &psect);
364 #if 0
365 if (is_share) /* FIXME */
366 (*_bfd_error_handler) ("ETIR_S_C_STO_B: byte fixups not supported");
367 #endif
368 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
369 break;
371 /* store word: pop stack, write word
372 arg: - */
374 case ETIR_S_C_STO_W:
375 dummy = _bfd_vms_pop (abfd, &psect);
376 #if 0
377 if (is_share) /* FIXME */
378 (*_bfd_error_handler) ("ETIR_S_C_STO_B: word fixups not supported");
379 #endif
380 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
381 break;
383 /* store longword: pop stack, write longword
384 arg: - */
386 case ETIR_S_C_STO_LW:
387 dummy = _bfd_vms_pop (abfd, &psect);
388 dummy += (PRIV(sections)[psect])->vma;
389 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
390 break;
392 /* store quadword: pop stack, write quadword
393 arg: - */
395 case ETIR_S_C_STO_QW:
396 dummy = _bfd_vms_pop (abfd, &psect);
397 dummy += (PRIV(sections)[psect])->vma;
398 image_write_q (abfd, dummy); /* FIXME: check top bits */
399 break;
401 /* store immediate repeated: pop stack for repeat count
402 arg: lw byte count
403 da data */
405 case ETIR_S_C_STO_IMMR:
407 unsigned long size;
409 size = bfd_getl32 (ptr);
410 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
411 while (dummy-- > 0L)
412 image_dump (abfd, ptr+4, size, 0);
414 break;
416 /* store global: write symbol value
417 arg: cs global symbol name */
419 case ETIR_S_C_STO_GBL:
421 vms_symbol_entry *entry;
422 char *name;
424 name = _bfd_vms_save_counted_string (ptr);
425 entry = (vms_symbol_entry *)bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
426 if (entry == (vms_symbol_entry *)NULL)
428 (*_bfd_error_handler) (_("ETIR_S_C_STO_GBL: no symbol \"%s\""),
429 name);
430 return false;
432 else
433 image_write_q (abfd, (uquad) (entry->symbol->value)); /* FIXME, reloc */
435 break;
437 /* store code address: write address of entry point
438 arg: cs global symbol name (procedure) */
440 case ETIR_S_C_STO_CA:
442 vms_symbol_entry *entry;
443 char *name;
445 name = _bfd_vms_save_counted_string (ptr);
446 entry = (vms_symbol_entry *) bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
447 if (entry == (vms_symbol_entry *)NULL)
449 (*_bfd_error_handler) (_("ETIR_S_C_STO_CA: no symbol \"%s\""),
450 name);
451 return false;
453 else
454 image_write_q (abfd, (uquad) (entry->symbol->value)); /* FIXME, reloc */
456 break;
458 /* not supported */
460 case ETIR_S_C_STO_RB:
461 case ETIR_S_C_STO_AB:
462 (*_bfd_error_handler) (_("ETIR_S_C_STO_RB/AB: Not supported"));
463 break;
465 /* store offset to psect: pop stack, add low 32 bits to base of psect
466 arg: - */
468 case ETIR_S_C_STO_OFF:
470 uquad q;
471 int psect;
473 q = _bfd_vms_pop (abfd, &psect);
474 q += (PRIV(sections)[psect])->vma;
475 image_write_q (abfd, q);
477 break;
479 /* store immediate
480 arg: lw count of bytes
481 da data */
483 case ETIR_S_C_STO_IMM:
485 int size;
487 size = bfd_getl32 (ptr);
488 image_dump (abfd, ptr+4, size, 0);
490 break;
492 /* this code is 'reserved to digital' according to the openVMS linker manual,
493 however it is generated by the DEC C compiler and defined in the include file.
494 FIXME, since the following is just a guess
495 store global longword: store 32bit value of symbol
496 arg: cs symbol name */
498 case ETIR_S_C_STO_GBL_LW:
500 vms_symbol_entry *entry;
501 char *name;
503 name = _bfd_vms_save_counted_string (ptr);
504 entry = (vms_symbol_entry *)bfd_hash_lookup (PRIV(vms_symbol_table), name, false, false);
505 if (entry == (vms_symbol_entry *)NULL)
507 #if VMS_DEBUG
508 _bfd_vms_debug (3, "ETIR_S_C_STO_GBL_LW: no symbol \"%s\"\n", name);
509 #endif
510 image_write_l (abfd, (unsigned long)0); /* FIXME, reloc */
512 else
513 image_write_l (abfd, (unsigned long) (entry->symbol->value)); /* FIXME, reloc */
515 break;
517 /* not supported */
519 case ETIR_S_C_STO_LP_PSB:
520 (*_bfd_error_handler) (_("ETIR_S_C_STO_LP_PSB: Not supported"));
521 break;
523 /* */
525 case ETIR_S_C_STO_HINT_GBL:
526 (*_bfd_error_handler) (_("ETIR_S_C_STO_HINT_GBL: not implemented"));
527 break;
529 /* */
531 case ETIR_S_C_STO_HINT_PS:
532 (*_bfd_error_handler) (_("ETIR_S_C_STO_HINT_PS: not implemented"));
533 break;
535 default:
536 (*_bfd_error_handler) (_("Reserved STO cmd %d"), cmd);
537 break;
540 return true;
543 /* stack operator commands
544 all 32 bit signed arithmetic
545 all word just like a stack calculator
546 arguments are popped from stack, results are pushed on stack
548 see table B-10 of the openVMS linker manual */
550 static boolean
551 etir_opr (abfd, cmd, ptr)
552 bfd *abfd;
553 int cmd;
554 unsigned char *ptr ATTRIBUTE_UNUSED;
556 long op1, op2;
558 #if VMS_DEBUG
559 _bfd_vms_debug (5, "etir_opr %d/%x\n", cmd, cmd);
560 _bfd_hexdump (8, ptr, 16, (int)ptr);
561 #endif
563 switch (cmd)
565 /* operation */
567 /* no-op */
569 case ETIR_S_C_OPR_NOP:
570 break;
572 /* add */
574 case ETIR_S_C_OPR_ADD:
575 op1 = (long)_bfd_vms_pop (abfd, NULL);
576 op2 = (long)_bfd_vms_pop (abfd, NULL);
577 _bfd_vms_push (abfd, (uquad) (op1 + op2), -1);
578 break;
580 /* subtract */
582 case ETIR_S_C_OPR_SUB:
583 op1 = (long)_bfd_vms_pop (abfd, NULL);
584 op2 = (long)_bfd_vms_pop (abfd, NULL);
585 _bfd_vms_push (abfd, (uquad) (op2 - op1), -1);
586 break;
588 /* multiply */
590 case ETIR_S_C_OPR_MUL:
591 op1 = (long)_bfd_vms_pop (abfd, NULL);
592 op2 = (long)_bfd_vms_pop (abfd, NULL);
593 _bfd_vms_push (abfd, (uquad) (op1 * op2), -1);
594 break;
596 /* divide */
598 case ETIR_S_C_OPR_DIV:
599 op1 = (long)_bfd_vms_pop (abfd, NULL);
600 op2 = (long)_bfd_vms_pop (abfd, NULL);
601 if (op2 == 0)
602 _bfd_vms_push (abfd, (uquad)0L, -1);
603 else
604 _bfd_vms_push (abfd, (uquad) (op2 / op1), -1);
605 break;
607 /* logical and */
609 case ETIR_S_C_OPR_AND:
610 op1 = (long)_bfd_vms_pop (abfd, NULL);
611 op2 = (long)_bfd_vms_pop (abfd, NULL);
612 _bfd_vms_push (abfd, (uquad) (op1 & op2), -1);
613 break;
615 /* logical inclusive or */
617 case ETIR_S_C_OPR_IOR:
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 exclusive or */
625 case ETIR_S_C_OPR_EOR:
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 /* negate */
633 case ETIR_S_C_OPR_NEG:
634 op1 = (long)_bfd_vms_pop (abfd, NULL);
635 _bfd_vms_push (abfd, (uquad) (-op1), -1);
636 break;
638 /* complement */
640 case ETIR_S_C_OPR_COM:
641 op1 = (long)_bfd_vms_pop (abfd, NULL);
642 _bfd_vms_push (abfd, (uquad) (op1 ^ -1L), -1);
643 break;
645 /* insert field */
647 case ETIR_S_C_OPR_INSV:
648 (void)_bfd_vms_pop (abfd, NULL);
649 (*_bfd_error_handler) (_("ETIR_S_C_OPR_INSV: Not supported"));
650 break;
652 /* arithmetic shift */
654 case ETIR_S_C_OPR_ASH:
655 op1 = (long)_bfd_vms_pop (abfd, NULL);
656 op2 = (long)_bfd_vms_pop (abfd, NULL);
657 if (op2 < 0) /* shift right */
658 op1 >>= -op2;
659 else /* shift left */
660 op1 <<= op2;
661 _bfd_vms_push (abfd, (uquad)op1, -1);
662 break;
664 /* unsigned shift */
666 case ETIR_S_C_OPR_USH:
667 (*_bfd_error_handler) (_("ETIR_S_C_OPR_USH: Not supported"));
668 break;
670 /* rotate */
672 case ETIR_S_C_OPR_ROT:
673 (*_bfd_error_handler) (_("ETIR_S_C_OPR_ROT: Not supported"));
674 break;
676 /* select */
678 case ETIR_S_C_OPR_SEL:
679 if ((long)_bfd_vms_pop (abfd, NULL) & 0x01L)
680 (void)_bfd_vms_pop (abfd, NULL);
681 else
683 op1 = (long)_bfd_vms_pop (abfd, NULL);
684 (void)_bfd_vms_pop (abfd, NULL);
685 _bfd_vms_push (abfd, (uquad)op1, -1);
687 break;
689 /* redefine symbol to current location */
691 case ETIR_S_C_OPR_REDEF:
692 (*_bfd_error_handler) (_("ETIR_S_C_OPR_REDEF: Not supported"));
693 break;
695 /* define a literal */
697 case ETIR_S_C_OPR_DFLIT:
698 (*_bfd_error_handler) (_("ETIR_S_C_OPR_DFLIT: Not supported"));
699 break;
701 default:
702 (*_bfd_error_handler) (_("Reserved OPR cmd %d"), cmd);
703 break;
706 return true;
709 /* control commands
711 see table B-11 of the openVMS linker manual */
713 static boolean
714 etir_ctl (abfd, cmd, ptr)
715 bfd *abfd;
716 int cmd;
717 unsigned char *ptr;
719 uquad dummy;
720 int psect;
722 #if VMS_DEBUG
723 _bfd_vms_debug (5, "etir_ctl %d/%x\n", cmd, cmd);
724 _bfd_hexdump (8, ptr, 16, (int)ptr);
725 #endif
727 switch (cmd)
729 /* set relocation base: pop stack, set image location counter
730 arg: - */
732 case ETIR_S_C_CTL_SETRB:
733 dummy = _bfd_vms_pop (abfd, &psect);
734 image_set_ptr (abfd, psect, dummy);
735 break;
737 /* augment relocation base: increment image location counter by offset
738 arg: lw offset value */
740 case ETIR_S_C_CTL_AUGRB:
741 dummy = bfd_getl32 (ptr);
742 image_inc_ptr (abfd, dummy);
743 break;
745 /* define location: pop index, save location counter under index
746 arg: - */
748 case ETIR_S_C_CTL_DFLOC:
749 dummy = _bfd_vms_pop (abfd, NULL);
750 /* FIXME */
751 break;
753 /* set location: pop index, restore location counter from index
754 arg: - */
756 case ETIR_S_C_CTL_STLOC:
757 dummy = _bfd_vms_pop (abfd, &psect);
758 /* FIXME */
759 break;
761 /* stack defined location: pop index, push location counter from index
762 arg: - */
764 case ETIR_S_C_CTL_STKDL:
765 dummy = _bfd_vms_pop (abfd, &psect);
766 /* FIXME */
767 break;
769 default:
770 (*_bfd_error_handler) (_("Reserved CTL cmd %d"), cmd);
771 break;
773 return true;
776 /* store conditional commands
778 see table B-12 and B-13 of the openVMS linker manual */
780 static boolean
781 etir_stc (abfd, cmd, ptr)
782 bfd *abfd;
783 int cmd;
784 unsigned char *ptr ATTRIBUTE_UNUSED;
787 #if VMS_DEBUG
788 _bfd_vms_debug (5, "etir_stc %d/%x\n", cmd, cmd);
789 _bfd_hexdump (8, ptr, 16, (int)ptr);
790 #endif
792 switch (cmd)
794 /* 200 Store-conditional Linkage Pair
795 arg: */
797 case ETIR_S_C_STC_LP:
798 (*_bfd_error_handler) (_("ETIR_S_C_STC_LP: not supported"));
799 break;
801 /* 201 Store-conditional Linkage Pair with Procedure Signature
802 arg: lw linkage index
803 cs procedure name
804 by signature length
805 da signature */
807 case ETIR_S_C_STC_LP_PSB:
808 image_inc_ptr (abfd, 16); /* skip entry,procval */
809 break;
811 /* 202 Store-conditional Address at global address
812 arg: lw linkage index
813 cs global name */
815 case ETIR_S_C_STC_GBL:
816 (*_bfd_error_handler) (_("ETIR_S_C_STC_GBL: not supported"));
817 break;
819 /* 203 Store-conditional Code Address at global address
820 arg: lw linkage index
821 cs procedure name */
823 case ETIR_S_C_STC_GCA:
824 (*_bfd_error_handler) (_("ETIR_S_C_STC_GCA: not supported"));
825 break;
827 /* 204 Store-conditional Address at psect + offset
828 arg: lw linkage index
829 lw psect index
830 qw offset */
832 case ETIR_S_C_STC_PS:
833 (*_bfd_error_handler) (_("ETIR_S_C_STC_PS: not supported"));
834 break;
836 /* 205 Store-conditional NOP at address of global
837 arg: */
839 case ETIR_S_C_STC_NOP_GBL:
841 /* 206 Store-conditional NOP at pect + offset
842 arg: */
844 case ETIR_S_C_STC_NOP_PS:
846 /* 207 Store-conditional BSR at global address
847 arg: */
849 case ETIR_S_C_STC_BSR_GBL:
851 /* 208 Store-conditional BSR at pect + offset
852 arg: */
854 case ETIR_S_C_STC_BSR_PS:
856 /* 209 Store-conditional LDA at global address
857 arg: */
859 case ETIR_S_C_STC_LDA_GBL:
861 /* 210 Store-conditional LDA at psect + offset
862 arg: */
864 case ETIR_S_C_STC_LDA_PS:
866 /* 211 Store-conditional BSR or Hint at global address
867 arg: */
869 case ETIR_S_C_STC_BOH_GBL:
871 /* 212 Store-conditional BSR or Hint at pect + offset
872 arg: */
874 case ETIR_S_C_STC_BOH_PS:
876 /* 213 Store-conditional NOP,BSR or HINT at global address
877 arg: */
879 case ETIR_S_C_STC_NBH_GBL:
881 /* 214 Store-conditional NOP,BSR or HINT at psect + offset
882 arg: */
884 case ETIR_S_C_STC_NBH_PS:
885 /* FIXME (*_bfd_error_handler) ("ETIR_S_C_STC_xx: (%d) not supported", cmd); */
886 break;
888 default:
889 #if VMS_DEBUG
890 _bfd_vms_debug (3, "Reserved STC cmd %d", cmd);
891 #endif
892 break;
894 return true;
897 static asection *
898 new_section (abfd, idx)
899 bfd *abfd ATTRIBUTE_UNUSED;
900 int idx;
902 asection *section;
903 char sname[16];
904 char *name;
906 #if VMS_DEBUG
907 _bfd_vms_debug (5, "new_section %d\n", idx);
908 #endif
909 sprintf (sname, SECTION_NAME_TEMPLATE, idx);
911 name = bfd_malloc (strlen (sname) + 1);
912 if (name == 0)
913 return 0;
914 strcpy (name, sname);
916 section = bfd_malloc (sizeof (asection));
917 if (section == 0)
919 #if VMS_DEBUG
920 _bfd_vms_debug (6, "bfd_make_section (%s) failed", name);
921 #endif
922 return 0;
925 section->_raw_size = 0;
926 section->vma = 0;
927 section->contents = 0;
928 section->_cooked_size = 0;
929 section->name = name;
930 section->index = idx;
932 return section;
935 static int
936 alloc_section (abfd, idx)
937 bfd *abfd;
938 unsigned int idx;
940 #if VMS_DEBUG
941 _bfd_vms_debug (4, "alloc_section %d\n", idx);
942 #endif
944 PRIV(sections) = ((asection **)
945 bfd_realloc (PRIV(sections), (idx+1) * sizeof (asection *)));
946 if (PRIV(sections) == 0)
947 return -1;
949 while (PRIV(section_count) <= idx)
951 PRIV(sections)[PRIV(section_count)] = new_section (abfd, PRIV(section_count));
952 if (PRIV(sections)[PRIV(section_count)] == 0)
953 return -1;
954 PRIV(section_count)++;
957 return 0;
961 * tir_sta
963 * vax stack commands
965 * handle sta_xxx commands in tir section
966 * ptr points to data area in record
968 * see table 7-3 of the VAX/VMS linker manual
971 static unsigned char *
972 tir_sta (bfd *abfd, unsigned char *ptr)
974 int cmd = *ptr++;
976 #if VMS_DEBUG
977 _bfd_vms_debug (5, "tir_sta %d\n", cmd);
978 #endif
980 switch (cmd)
982 /* stack */
983 case TIR_S_C_STA_GBL:
985 * stack global
986 * arg: cs symbol name
988 * stack 32 bit value of symbol (high bits set to 0)
991 char *name;
992 vms_symbol_entry *entry;
994 name = _bfd_vms_save_counted_string (ptr);
996 entry = _bfd_vms_enter_symbol (abfd, name);
997 if (entry == (vms_symbol_entry *)NULL)
998 return 0;
1000 _bfd_vms_push (abfd, (unsigned long) (entry->symbol->value), -1);
1001 ptr += *ptr + 1;
1003 break;
1005 case TIR_S_C_STA_SB:
1007 * stack signed byte
1008 * arg: by value
1010 * stack byte value, sign extend to 32 bit
1012 _bfd_vms_push (abfd, (long)*ptr++, -1);
1013 break;
1015 case TIR_S_C_STA_SW:
1017 * stack signed short word
1018 * arg: sh value
1020 * stack 16 bit value, sign extend to 32 bit
1022 _bfd_vms_push (abfd, (long)bfd_getl16(ptr), -1);
1023 ptr += 2;
1024 break;
1026 case TIR_S_C_STA_LW:
1028 * stack signed longword
1029 * arg: lw value
1031 * stack 32 bit value
1033 _bfd_vms_push (abfd, (long)bfd_getl32 (ptr), -1);
1034 ptr += 4;
1035 break;
1037 case TIR_S_C_STA_PB:
1038 case TIR_S_C_STA_WPB:
1040 * stack psect base plus byte offset (word index)
1041 * arg: by section index
1042 * (sh section index)
1043 * by signed byte offset
1047 unsigned long dummy;
1048 unsigned int psect;
1050 if (cmd == TIR_S_C_STA_PB)
1051 psect = *ptr++;
1052 else
1054 psect = bfd_getl16(ptr);
1055 ptr += 2;
1058 if (psect >= PRIV(section_count))
1060 alloc_section (abfd, psect);
1063 dummy = (long)*ptr++;
1064 dummy += (PRIV(sections)[psect])->vma;
1065 _bfd_vms_push (abfd, dummy, psect);
1067 break;
1069 case TIR_S_C_STA_PW:
1070 case TIR_S_C_STA_WPW:
1072 * stack psect base plus word offset (word index)
1073 * arg: by section index
1074 * (sh section index)
1075 * sh signed short offset
1079 unsigned long dummy;
1080 unsigned int psect;
1082 if (cmd == TIR_S_C_STA_PW)
1083 psect = *ptr++;
1084 else
1086 psect = bfd_getl16(ptr);
1087 ptr += 2;
1090 if (psect >= PRIV(section_count))
1092 alloc_section (abfd, psect);
1095 dummy = bfd_getl16(ptr); ptr+=2;
1096 dummy += (PRIV(sections)[psect])->vma;
1097 _bfd_vms_push (abfd, dummy, psect);
1099 break;
1101 case TIR_S_C_STA_PL:
1102 case TIR_S_C_STA_WPL:
1104 * stack psect base plus long offset (word index)
1105 * arg: by section index
1106 * (sh section index)
1107 * lw signed longword offset
1111 unsigned long dummy;
1112 unsigned int psect;
1114 if (cmd == TIR_S_C_STA_PL)
1115 psect = *ptr++;
1116 else
1118 psect = bfd_getl16(ptr);
1119 ptr += 2;
1122 if (psect >= PRIV(section_count))
1124 alloc_section (abfd, psect);
1127 dummy = bfd_getl32 (ptr); ptr += 4;
1128 dummy += (PRIV(sections)[psect])->vma;
1129 _bfd_vms_push (abfd, dummy, psect);
1131 break;
1133 case TIR_S_C_STA_UB:
1135 * stack unsigned byte
1136 * arg: by value
1138 * stack byte value
1140 _bfd_vms_push (abfd, (unsigned long)*ptr++, -1);
1141 break;
1143 case TIR_S_C_STA_UW:
1145 * stack unsigned short word
1146 * arg: sh value
1148 * stack 16 bit value
1150 _bfd_vms_push (abfd, (unsigned long)bfd_getl16(ptr), -1);
1151 ptr += 2;
1152 break;
1154 case TIR_S_C_STA_BFI:
1156 * stack byte from image
1157 * arg: -
1160 /*FALLTHRU*/
1161 case TIR_S_C_STA_WFI:
1163 * stack byte from image
1164 * arg: -
1167 /*FALLTHRU*/
1168 case TIR_S_C_STA_LFI:
1170 * stack byte from image
1171 * arg: -
1174 (*_bfd_error_handler) (_("Stack-from-image not implemented"));
1175 return NULL;
1177 case TIR_S_C_STA_EPM:
1179 * stack entry point mask
1180 * arg: cs symbol name
1182 * stack (unsigned) entry point mask of symbol
1183 * err if symbol is no entry point
1186 char *name;
1187 vms_symbol_entry *entry;
1189 name = _bfd_vms_save_counted_string (ptr);
1190 entry = _bfd_vms_enter_symbol (abfd, name);
1191 if (entry == (vms_symbol_entry *)NULL)
1192 return 0;
1194 (*_bfd_error_handler) (_("Stack-entry-mask not fully implemented"));
1195 _bfd_vms_push (abfd, 0L, -1);
1196 ptr += *ptr + 1;
1198 break;
1200 case TIR_S_C_STA_CKARG:
1202 * compare procedure argument
1203 * arg: cs symbol name
1204 * by argument index
1205 * da argument descriptor
1207 * compare argument descriptor with symbol argument (ARG$V_PASSMECH)
1208 * and stack TRUE (args match) or FALSE (args dont match) value
1210 (*_bfd_error_handler) (_("PASSMECH not fully implemented"));
1211 _bfd_vms_push (abfd, 1L, -1);
1212 break;
1214 case TIR_S_C_STA_LSY:
1216 * stack local symbol value
1217 * arg: sh environment index
1218 * cs symbol name
1221 int envidx;
1222 char *name;
1223 vms_symbol_entry *entry;
1225 envidx = bfd_getl16(ptr); ptr += 2;
1226 name = _bfd_vms_save_counted_string (ptr);
1227 entry = _bfd_vms_enter_symbol (abfd, name);
1228 if (entry == (vms_symbol_entry *)NULL)
1229 return 0;
1230 (*_bfd_error_handler) (_("Stack-local-symbol not fully implemented"));
1231 _bfd_vms_push (abfd, 0L, -1);
1232 ptr += *ptr + 1;
1234 break;
1236 case TIR_S_C_STA_LIT:
1238 * stack literal
1239 * arg: by literal index
1241 * stack literal
1243 ptr++;
1244 _bfd_vms_push (abfd, 0L, -1);
1245 (*_bfd_error_handler) (_("Stack-literal not fully implemented"));
1246 break;
1248 case TIR_S_C_STA_LEPM:
1250 * stack local symbol entry point mask
1251 * arg: sh environment index
1252 * cs symbol name
1254 * stack (unsigned) entry point mask of symbol
1255 * err if symbol is no entry point
1258 int envidx;
1259 char *name;
1260 vms_symbol_entry *entry;
1262 envidx = bfd_getl16(ptr); ptr += 2;
1263 name = _bfd_vms_save_counted_string (ptr);
1264 entry = _bfd_vms_enter_symbol (abfd, name);
1265 if (entry == (vms_symbol_entry *)NULL)
1266 return 0;
1267 (*_bfd_error_handler) (_("Stack-local-symbol-entry-point-mask not fully implemented"));
1268 _bfd_vms_push (abfd, 0L, -1);
1269 ptr += *ptr + 1;
1271 break;
1273 default:
1274 (*_bfd_error_handler) (_("Reserved STA cmd %d"), ptr[-1]);
1275 return NULL;
1276 break;
1279 return ptr;
1283 * tir_sto
1285 * vax store commands
1287 * handle sto_xxx commands in tir section
1288 * ptr points to data area in record
1290 * see table 7-4 of the VAX/VMS linker manual
1293 static unsigned char *
1294 tir_sto (bfd *abfd, unsigned char *ptr)
1296 unsigned long dummy;
1297 int size;
1298 int psect;
1300 #if VMS_DEBUG
1301 _bfd_vms_debug (5, "tir_sto %d\n", *ptr);
1302 #endif
1304 switch (*ptr++)
1306 case TIR_S_C_STO_SB:
1308 * store signed byte: pop stack, write byte
1309 * arg: -
1311 dummy = _bfd_vms_pop (abfd, &psect);
1312 image_write_b (abfd, dummy & 0xff); /* FIXME: check top bits */
1313 break;
1315 case TIR_S_C_STO_SW:
1317 * store signed word: pop stack, write word
1318 * arg: -
1320 dummy = _bfd_vms_pop (abfd, &psect);
1321 image_write_w (abfd, dummy & 0xffff); /* FIXME: check top bits */
1322 break;
1324 case TIR_S_C_STO_LW:
1326 * store longword: pop stack, write longword
1327 * arg: -
1329 dummy = _bfd_vms_pop (abfd, &psect);
1330 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1331 break;
1333 case TIR_S_C_STO_BD:
1335 * store byte displaced: pop stack, sub lc+1, write byte
1336 * arg: -
1338 dummy = _bfd_vms_pop (abfd, &psect);
1339 dummy -= ((PRIV(sections)[psect])->vma + 1);
1340 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1341 break;
1343 case TIR_S_C_STO_WD:
1345 * store word displaced: pop stack, sub lc+2, write word
1346 * arg: -
1348 dummy = _bfd_vms_pop (abfd, &psect);
1349 dummy -= ((PRIV(sections)[psect])->vma + 2);
1350 image_write_w (abfd, dummy & 0xffff);/* FIXME: check top bits */
1351 break;
1352 case TIR_S_C_STO_LD:
1354 * store long displaced: pop stack, sub lc+4, write long
1355 * arg: -
1357 dummy = _bfd_vms_pop (abfd, &psect);
1358 dummy -= ((PRIV(sections)[psect])->vma + 4);
1359 image_write_l (abfd, dummy & 0xffffffff);/* FIXME: check top bits */
1360 break;
1361 case TIR_S_C_STO_LI:
1363 * store short literal: pop stack, write byte
1364 * arg: -
1366 dummy = _bfd_vms_pop (abfd, &psect);
1367 image_write_b (abfd, dummy & 0xff);/* FIXME: check top bits */
1368 break;
1369 case TIR_S_C_STO_PIDR:
1371 * store position independent data reference: pop stack, write longword
1372 * arg: -
1373 * FIXME: incomplete !
1375 dummy = _bfd_vms_pop (abfd, &psect);
1376 image_write_l (abfd, dummy & 0xffffffff);
1377 break;
1378 case TIR_S_C_STO_PICR:
1380 * store position independent code reference: pop stack, write longword
1381 * arg: -
1382 * FIXME: incomplete !
1384 dummy = _bfd_vms_pop (abfd, &psect);
1385 image_write_b (abfd, 0x9f);
1386 image_write_l (abfd, dummy & 0xffffffff);
1387 break;
1388 case TIR_S_C_STO_RIVB:
1390 * store repeated immediate variable bytes
1391 * 1-byte count n field followed by n bytes of data
1392 * pop stack, write n bytes <stack> times
1394 size = *ptr++;
1395 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1396 while (dummy-- > 0L)
1397 image_dump (abfd, ptr, size, 0);
1398 ptr += size;
1399 break;
1400 case TIR_S_C_STO_B:
1402 * store byte from top longword
1404 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1405 image_write_b (abfd, dummy & 0xff);
1406 break;
1407 case TIR_S_C_STO_W:
1409 * store word from top longword
1411 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1412 image_write_w (abfd, dummy & 0xffff);
1413 break;
1414 case TIR_S_C_STO_RB:
1416 * store repeated byte from top longword
1418 size = (unsigned long)_bfd_vms_pop (abfd, NULL);
1419 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1420 while (size-- > 0)
1421 image_write_b (abfd, dummy & 0xff);
1422 break;
1423 case TIR_S_C_STO_RW:
1425 * store repeated word from top longword
1427 size = (unsigned long)_bfd_vms_pop (abfd, NULL);
1428 dummy = (unsigned long)_bfd_vms_pop (abfd, NULL);
1429 while (size-- > 0)
1430 image_write_w (abfd, dummy & 0xffff);
1431 break;
1433 case TIR_S_C_STO_RSB:
1434 case TIR_S_C_STO_RSW:
1435 case TIR_S_C_STO_RL:
1436 case TIR_S_C_STO_VPS:
1437 case TIR_S_C_STO_USB:
1438 case TIR_S_C_STO_USW:
1439 case TIR_S_C_STO_RUB:
1440 case TIR_S_C_STO_RUW:
1441 case TIR_S_C_STO_PIRR:
1442 (*_bfd_error_handler) (_("Unimplemented STO cmd %d"), ptr[-1]);
1443 break;
1445 default:
1446 (*_bfd_error_handler) (_("Reserved STO cmd %d"), ptr[-1]);
1447 break;
1450 return ptr;
1454 * stack operator commands
1455 * all 32 bit signed arithmetic
1456 * all word just like a stack calculator
1457 * arguments are popped from stack, results are pushed on stack
1459 * see table 7-5 of the VAX/VMS linker manual
1462 static unsigned char *
1463 tir_opr (bfd *abfd, unsigned char *ptr)
1465 long op1, op2;
1467 #if VMS_DEBUG
1468 _bfd_vms_debug (5, "tir_opr %d\n", *ptr);
1469 #endif
1471 switch (*ptr++)
1473 /* operation */
1474 case TIR_S_C_OPR_NOP:
1476 * no-op
1478 break;
1480 case TIR_S_C_OPR_ADD:
1482 * add
1484 op1 = (long)_bfd_vms_pop (abfd, NULL);
1485 op2 = (long)_bfd_vms_pop (abfd, NULL);
1486 _bfd_vms_push (abfd, (unsigned long) (op1 + op2), -1);
1487 break;
1489 case TIR_S_C_OPR_SUB:
1491 * subtract
1493 op1 = (long)_bfd_vms_pop (abfd, NULL);
1494 op2 = (long)_bfd_vms_pop (abfd, NULL);
1495 _bfd_vms_push (abfd, (unsigned long) (op2 - op1), -1);
1496 break;
1498 case TIR_S_C_OPR_MUL:
1500 * multiply
1502 op1 = (long)_bfd_vms_pop (abfd, NULL);
1503 op2 = (long)_bfd_vms_pop (abfd, NULL);
1504 _bfd_vms_push (abfd, (unsigned long) (op1 * op2), -1);
1505 break;
1507 case TIR_S_C_OPR_DIV:
1509 * divide
1511 op1 = (long)_bfd_vms_pop (abfd, NULL);
1512 op2 = (long)_bfd_vms_pop (abfd, NULL);
1513 if (op2 == 0)
1514 _bfd_vms_push (abfd, (unsigned long)0L, -1);
1515 else
1516 _bfd_vms_push (abfd, (unsigned long) (op2 / op1), -1);
1517 break;
1519 case TIR_S_C_OPR_AND:
1521 * logical and
1523 op1 = (long)_bfd_vms_pop (abfd, NULL);
1524 op2 = (long)_bfd_vms_pop (abfd, NULL);
1525 _bfd_vms_push (abfd, (unsigned long) (op1 & op2), -1);
1526 break;
1528 case TIR_S_C_OPR_IOR:
1529 op1 = (long)_bfd_vms_pop (abfd, NULL);
1531 * logical inclusive or
1533 op2 = (long)_bfd_vms_pop (abfd, NULL);
1534 _bfd_vms_push (abfd, (unsigned long) (op1 | op2), -1);
1535 break;
1537 case TIR_S_C_OPR_EOR:
1539 * logical exclusive or
1541 op1 = (long)_bfd_vms_pop (abfd, NULL);
1542 op2 = (long)_bfd_vms_pop (abfd, NULL);
1543 _bfd_vms_push (abfd, (unsigned long) (op1 ^ op2), -1);
1544 break;
1546 case TIR_S_C_OPR_NEG:
1548 * negate
1550 op1 = (long)_bfd_vms_pop (abfd, NULL);
1551 _bfd_vms_push (abfd, (unsigned long) (-op1), -1);
1552 break;
1554 case TIR_S_C_OPR_COM:
1556 * complement
1558 op1 = (long)_bfd_vms_pop (abfd, NULL);
1559 _bfd_vms_push (abfd, (unsigned long) (op1 ^ -1L), -1);
1560 break;
1562 case TIR_S_C_OPR_INSV:
1564 * insert field
1566 (void)_bfd_vms_pop (abfd, NULL);
1567 (*_bfd_error_handler) ("TIR_S_C_OPR_INSV incomplete");
1568 break;
1570 case TIR_S_C_OPR_ASH:
1572 * arithmetic shift
1574 op1 = (long)_bfd_vms_pop (abfd, NULL);
1575 op2 = (long)_bfd_vms_pop (abfd, NULL);
1576 if (HIGHBIT(op1)) /* shift right */
1577 op2 >>= op1;
1578 else /* shift left */
1579 op2 <<= op1;
1580 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1581 (*_bfd_error_handler) (_("TIR_S_C_OPR_ASH incomplete"));
1582 break;
1584 case TIR_S_C_OPR_USH:
1586 * unsigned shift
1588 op1 = (long)_bfd_vms_pop (abfd, NULL);
1589 op2 = (long)_bfd_vms_pop (abfd, NULL);
1590 if (HIGHBIT(op1)) /* shift right */
1591 op2 >>= op1;
1592 else /* shift left */
1593 op2 <<= op1;
1594 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1595 (*_bfd_error_handler) (_("TIR_S_C_OPR_USH incomplete"));
1596 break;
1598 case TIR_S_C_OPR_ROT:
1600 * rotate
1602 op1 = (long)_bfd_vms_pop (abfd, NULL);
1603 op2 = (long)_bfd_vms_pop (abfd, NULL);
1604 if (HIGHBIT(0)) /* shift right */
1605 op2 >>= op1;
1606 else /* shift left */
1607 op2 <<= op1;
1608 _bfd_vms_push (abfd, (unsigned long)op2, -1);
1609 (*_bfd_error_handler) (_("TIR_S_C_OPR_ROT incomplete"));
1610 break;
1612 case TIR_S_C_OPR_SEL:
1614 * select
1616 if ((long)_bfd_vms_pop (abfd, NULL) & 0x01L)
1617 (void)_bfd_vms_pop (abfd, NULL);
1618 else
1620 op1 = (long)_bfd_vms_pop (abfd, NULL);
1621 (void)_bfd_vms_pop (abfd, NULL);
1622 _bfd_vms_push (abfd, (unsigned long)op1, -1);
1624 break;
1626 case TIR_S_C_OPR_REDEF:
1628 * redefine symbol to current location
1630 (*_bfd_error_handler) (_("TIR_S_C_OPR_REDEF not supported"));
1631 break;
1633 case TIR_S_C_OPR_DFLIT:
1635 * define a literal
1637 (*_bfd_error_handler) (_("TIR_S_C_OPR_DFLIT not supported"));
1638 break;
1640 default:
1641 (*_bfd_error_handler) (_("Reserved OPR cmd %d"), ptr[-1]);
1642 break;
1645 return ptr;
1648 static unsigned char *
1649 tir_ctl (bfd *abfd, unsigned char *ptr)
1651 * control commands
1653 * see table 7-6 of the VAX/VMS linker manual
1656 unsigned long dummy;
1657 unsigned int psect;
1659 #if VMS_DEBUG
1660 _bfd_vms_debug (5, "tir_ctl %d\n", *ptr);
1661 #endif
1663 switch (*ptr++)
1665 case TIR_S_C_CTL_SETRB:
1667 * set relocation base: pop stack, set image location counter
1668 * arg: -
1670 dummy = _bfd_vms_pop (abfd, &psect);
1671 if (psect >= PRIV(section_count))
1673 alloc_section (abfd, psect);
1675 image_set_ptr (abfd, psect, dummy);
1676 break;
1677 case TIR_S_C_CTL_AUGRB:
1679 * augment relocation base: increment image location counter by offset
1680 * arg: lw offset value
1682 dummy = bfd_getl32 (ptr);
1683 image_inc_ptr (abfd, dummy);
1684 break;
1685 case TIR_S_C_CTL_DFLOC:
1687 * define location: pop index, save location counter under index
1688 * arg: -
1690 dummy = _bfd_vms_pop (abfd, NULL);
1691 (*_bfd_error_handler) (_("TIR_S_C_CTL_DFLOC not fully implemented"));
1692 break;
1693 case TIR_S_C_CTL_STLOC:
1695 * set location: pop index, restore location counter from index
1696 * arg: -
1698 dummy = _bfd_vms_pop (abfd, &psect);
1699 (*_bfd_error_handler) (_("TIR_S_C_CTL_STLOC not fully implemented"));
1700 break;
1701 case TIR_S_C_CTL_STKDL:
1703 * stack defined location: pop index, push location counter from index
1704 * arg: -
1706 dummy = _bfd_vms_pop (abfd, &psect);
1707 (*_bfd_error_handler) (_("TIR_S_C_CTL_STKDL not fully implemented"));
1708 break;
1709 default:
1710 (*_bfd_error_handler) (_("Reserved CTL cmd %d"), ptr[-1]);
1711 break;
1713 return ptr;
1717 * handle command from TIR section
1720 static unsigned char *
1721 tir_cmd (bfd *abfd, unsigned char *ptr)
1723 struct {
1724 int mincod;
1725 int maxcod;
1726 unsigned char * (*explain) (bfd *, unsigned char *);
1727 } tir_table[] = {
1728 { 0, TIR_S_C_MAXSTACOD, tir_sta }
1729 ,{ TIR_S_C_MINSTOCOD, TIR_S_C_MAXSTOCOD, tir_sto }
1730 ,{ TIR_S_C_MINOPRCOD, TIR_S_C_MAXOPRCOD, tir_opr }
1731 ,{ TIR_S_C_MINCTLCOD, TIR_S_C_MAXCTLCOD, tir_ctl }
1732 ,{ -1, -1, NULL }
1734 int i = 0;
1736 #if VMS_DEBUG
1737 _bfd_vms_debug (4, "tir_cmd %d/%x\n", *ptr, *ptr);
1738 _bfd_hexdump (8, ptr, 16, (int)ptr);
1739 #endif
1741 if (*ptr & 0x80) /* store immediate */
1743 i = 128 - (*ptr++ & 0x7f);
1744 image_dump (abfd, ptr, i, 0);
1745 ptr += i;
1747 else
1749 while (tir_table[i].mincod >= 0)
1751 if ( (tir_table[i].mincod <= *ptr)
1752 && (*ptr <= tir_table[i].maxcod))
1754 ptr = tir_table[i].explain (abfd, ptr);
1755 break;
1757 i++;
1759 if (tir_table[i].mincod < 0)
1761 (*_bfd_error_handler) (_("Obj code %d not found"), *ptr);
1762 ptr = 0;
1766 return ptr;
1769 /* handle command from ETIR section */
1771 static int
1772 etir_cmd (abfd, cmd, ptr)
1773 bfd *abfd;
1774 int cmd;
1775 unsigned char *ptr;
1777 static struct {
1778 int mincod;
1779 int maxcod;
1780 boolean (*explain) PARAMS((bfd *, int, unsigned char *));
1781 } etir_table[] = {
1782 { ETIR_S_C_MINSTACOD, ETIR_S_C_MAXSTACOD, etir_sta },
1783 { ETIR_S_C_MINSTOCOD, ETIR_S_C_MAXSTOCOD, etir_sto },
1784 { ETIR_S_C_MINOPRCOD, ETIR_S_C_MAXOPRCOD, etir_opr },
1785 { ETIR_S_C_MINCTLCOD, ETIR_S_C_MAXCTLCOD, etir_ctl },
1786 { ETIR_S_C_MINSTCCOD, ETIR_S_C_MAXSTCCOD, etir_stc },
1787 { -1, -1, NULL }
1790 int i = 0;
1792 #if VMS_DEBUG
1793 _bfd_vms_debug (4, "etir_cmd %d/%x\n", cmd, cmd);
1794 _bfd_hexdump (8, ptr, 16, (int)ptr);
1795 #endif
1797 while (etir_table[i].mincod >= 0)
1799 if ( (etir_table[i].mincod <= cmd)
1800 && (cmd <= etir_table[i].maxcod))
1802 if (!etir_table[i].explain (abfd, cmd, ptr))
1803 return -1;
1804 break;
1806 i++;
1809 #if VMS_DEBUG
1810 _bfd_vms_debug (4, "etir_cmd: = 0\n");
1811 #endif
1812 return 0;
1815 /* Text Information and Relocation Records (OBJ$C_TIR)
1816 handle tir record */
1818 static int
1819 analyze_tir (abfd, ptr, length)
1820 bfd *abfd;
1821 unsigned char *ptr;
1822 unsigned int length;
1824 unsigned char *maxptr;
1826 #if VMS_DEBUG
1827 _bfd_vms_debug (3, "analyze_tir: %d bytes\n", length);
1828 #endif
1830 maxptr = ptr + length;
1832 while (ptr < maxptr)
1834 ptr = tir_cmd (abfd, ptr);
1835 if (ptr == 0)
1836 return -1;
1839 return 0;
1842 /* Text Information and Relocation Records (EOBJ$C_ETIR)
1843 handle etir record */
1845 static int
1846 analyze_etir (abfd, ptr, length)
1847 bfd *abfd;
1848 unsigned char *ptr;
1849 unsigned int length;
1851 int cmd;
1852 unsigned char *maxptr;
1853 int result = 0;
1855 #if VMS_DEBUG
1856 _bfd_vms_debug (3, "analyze_etir: %d bytes\n", length);
1857 #endif
1859 maxptr = ptr + length;
1861 while (ptr < maxptr)
1863 cmd = bfd_getl16 (ptr);
1864 length = bfd_getl16 (ptr + 2);
1865 result = etir_cmd (abfd, cmd, ptr+4);
1866 if (result != 0)
1867 break;
1868 ptr += length;
1871 #if VMS_DEBUG
1872 _bfd_vms_debug (3, "analyze_etir: = %d\n", result);
1873 #endif
1875 return result;
1878 /* process ETIR record
1880 return 0 on success, -1 on error */
1883 _bfd_vms_slurp_tir (abfd, objtype)
1884 bfd *abfd;
1885 int objtype;
1887 int result;
1889 #if VMS_DEBUG
1890 _bfd_vms_debug (2, "TIR/ETIR\n");
1891 #endif
1893 switch (objtype)
1895 case EOBJ_S_C_ETIR:
1896 PRIV(vms_rec) += 4; /* skip type, size */
1897 PRIV(rec_size) -= 4;
1898 result = analyze_etir (abfd, PRIV(vms_rec), PRIV(rec_size));
1899 break;
1900 case OBJ_S_C_TIR:
1901 PRIV(vms_rec) += 1; /* skip type */
1902 PRIV(rec_size) -= 1;
1903 result = analyze_tir (abfd, PRIV(vms_rec), PRIV(rec_size));
1904 break;
1905 default:
1906 result = -1;
1907 break;
1910 return result;
1913 /* process EDBG record
1914 return 0 on success, -1 on error
1916 not implemented yet */
1919 _bfd_vms_slurp_dbg (abfd, objtype)
1920 bfd *abfd;
1921 int objtype ATTRIBUTE_UNUSED;
1923 #if VMS_DEBUG
1924 _bfd_vms_debug (2, "DBG/EDBG\n");
1925 #endif
1927 abfd->flags |= (HAS_DEBUG | HAS_LINENO);
1928 return 0;
1931 /* process ETBT record
1932 return 0 on success, -1 on error
1934 not implemented yet */
1937 _bfd_vms_slurp_tbt (abfd, objtype)
1938 bfd *abfd ATTRIBUTE_UNUSED;
1939 int objtype ATTRIBUTE_UNUSED;
1941 #if VMS_DEBUG
1942 _bfd_vms_debug (2, "TBT/ETBT\n");
1943 #endif
1945 return 0;
1948 /* process LNK record
1949 return 0 on success, -1 on error
1951 not implemented yet */
1954 _bfd_vms_slurp_lnk (abfd, objtype)
1955 bfd *abfd ATTRIBUTE_UNUSED;
1956 int objtype ATTRIBUTE_UNUSED;
1958 #if VMS_DEBUG
1959 _bfd_vms_debug (2, "LNK\n");
1960 #endif
1962 return 0;
1965 /*----------------------------------------------------------------------*/
1966 /* */
1967 /* WRITE ETIR SECTION */
1968 /* */
1969 /* this is still under construction and therefore not documented */
1970 /* */
1971 /*----------------------------------------------------------------------*/
1973 static void start_etir_record PARAMS ((bfd *abfd, int index, uquad offset, boolean justoffset));
1974 static void sto_imm PARAMS ((bfd *abfd, vms_section *sptr, bfd_vma vaddr, int index));
1975 static void end_etir_record PARAMS ((bfd *abfd));
1977 static void
1978 sto_imm (abfd, sptr, vaddr, index)
1979 bfd *abfd;
1980 vms_section *sptr;
1981 bfd_vma vaddr;
1982 int index;
1984 int size;
1985 int ssize;
1986 unsigned char *cptr;
1988 #if VMS_DEBUG
1989 _bfd_vms_debug (8, "sto_imm %d bytes\n", sptr->size);
1990 _bfd_hexdump (9, sptr->contents, (int)sptr->size, (int)vaddr);
1991 #endif
1993 ssize = sptr->size;
1994 cptr = sptr->contents;
1996 while (ssize > 0)
1999 size = ssize; /* try all the rest */
2001 if (_bfd_vms_output_check (abfd, size) < 0)
2002 { /* doesn't fit, split ! */
2003 end_etir_record (abfd);
2004 start_etir_record (abfd, index, vaddr, false);
2005 size = _bfd_vms_output_check (abfd, 0); /* get max size */
2006 if (size > ssize) /* more than what's left ? */
2007 size = ssize;
2010 _bfd_vms_output_begin (abfd, ETIR_S_C_STO_IMM, -1);
2011 _bfd_vms_output_long (abfd, (unsigned long) (size));
2012 _bfd_vms_output_dump (abfd, cptr, size);
2013 _bfd_vms_output_flush (abfd);
2015 #if VMS_DEBUG
2016 _bfd_vms_debug (10, "dumped %d bytes\n", size);
2017 _bfd_hexdump (10, cptr, (int)size, (int)vaddr);
2018 #endif
2020 vaddr += size;
2021 ssize -= size;
2022 cptr += size;
2025 return;
2028 /*-------------------------------------------------------------------*/
2030 /* start ETIR record for section #index at virtual addr offset. */
2032 static void
2033 start_etir_record (abfd, index, offset, justoffset)
2034 bfd *abfd;
2035 int index;
2036 uquad offset;
2037 boolean justoffset;
2039 if (!justoffset)
2041 _bfd_vms_output_begin (abfd, EOBJ_S_C_ETIR, -1); /* one ETIR per section */
2042 _bfd_vms_output_push (abfd);
2045 _bfd_vms_output_begin (abfd, ETIR_S_C_STA_PQ, -1); /* push start offset */
2046 _bfd_vms_output_long (abfd, (unsigned long)index);
2047 _bfd_vms_output_quad (abfd, (uquad)offset);
2048 _bfd_vms_output_flush (abfd);
2050 _bfd_vms_output_begin (abfd, ETIR_S_C_CTL_SETRB, -1); /* start = pop () */
2051 _bfd_vms_output_flush (abfd);
2053 return;
2056 /* end etir record */
2057 static void
2058 end_etir_record (abfd)
2059 bfd *abfd;
2061 _bfd_vms_output_pop (abfd);
2062 _bfd_vms_output_end (abfd);
2065 /* write section contents for bfd abfd */
2068 _bfd_vms_write_tir (abfd, objtype)
2069 bfd *abfd;
2070 int objtype ATTRIBUTE_UNUSED;
2072 asection *section;
2073 vms_section *sptr;
2074 int nextoffset;
2076 #if VMS_DEBUG
2077 _bfd_vms_debug (2, "vms_write_tir (%p, %d)\n", abfd, objtype);
2078 #endif
2080 _bfd_vms_output_alignment (abfd, 4);
2082 nextoffset = 0;
2083 PRIV(vms_linkage_index) = 1;
2085 /* dump all other sections */
2087 section = abfd->sections;
2089 while (section != NULL)
2092 #if VMS_DEBUG
2093 _bfd_vms_debug (4, "writing %d. section '%s' (%d bytes)\n", section->index, section->name, (int) (section->_raw_size));
2094 #endif
2096 if (section->flags & SEC_RELOC)
2098 int i;
2100 if ((i = section->reloc_count) <= 0)
2102 (*_bfd_error_handler) (_("SEC_RELOC with no relocs in section %s"),
2103 section->name);
2105 #if VMS_DEBUG
2106 else
2108 arelent **rptr;
2109 _bfd_vms_debug (4, "%d relocations:\n", i);
2110 rptr = section->orelocation;
2111 while (i-- > 0)
2113 _bfd_vms_debug (4, "sym %s in sec %s, value %08lx, addr %08lx, off %08lx, len %d: %s\n",
2114 (*(*rptr)->sym_ptr_ptr)->name,
2115 (*(*rptr)->sym_ptr_ptr)->section->name,
2116 (long) (*(*rptr)->sym_ptr_ptr)->value,
2117 (*rptr)->address, (*rptr)->addend,
2118 bfd_get_reloc_size((*rptr)->howto),
2119 (*rptr)->howto->name);
2120 rptr++;
2123 #endif
2126 if ((section->flags & SEC_HAS_CONTENTS)
2127 && (! bfd_is_com_section (section)))
2129 bfd_vma vaddr; /* virtual addr in section */
2131 sptr = _bfd_get_vms_section (abfd, section->index);
2132 if (sptr == NULL)
2134 bfd_set_error (bfd_error_no_contents);
2135 return -1;
2138 vaddr = (bfd_vma) (sptr->offset);
2140 start_etir_record (abfd, section->index, (uquad) sptr->offset,
2141 false);
2143 while (sptr != NULL) /* one STA_PQ, CTL_SETRB per vms_section */
2146 if (section->flags & SEC_RELOC) /* check for relocs */
2148 arelent **rptr = section->orelocation;
2149 int i = section->reloc_count;
2150 for (;;)
2152 bfd_size_type addr = (*rptr)->address;
2153 bfd_size_type len = bfd_get_reloc_size ((*rptr)->howto);
2154 if (sptr->offset < addr) /* sptr starts before reloc */
2156 bfd_size_type before = addr - sptr->offset;
2157 if (sptr->size <= before) /* complete before */
2159 sto_imm (abfd, sptr, vaddr, section->index);
2160 vaddr += sptr->size;
2161 break;
2163 else /* partly before */
2165 int after = sptr->size - before;
2166 sptr->size = before;
2167 sto_imm (abfd, sptr, vaddr, section->index);
2168 vaddr += sptr->size;
2169 sptr->contents += before;
2170 sptr->offset += before;
2171 sptr->size = after;
2174 else if (sptr->offset == addr) /* sptr starts at reloc */
2176 asymbol *sym = *(*rptr)->sym_ptr_ptr;
2177 asection *sec = sym->section;
2179 switch ((*rptr)->howto->type)
2181 case ALPHA_R_IGNORE:
2182 break;
2184 case ALPHA_R_REFLONG:
2186 if (bfd_is_und_section (sym->section))
2188 if (_bfd_vms_output_check (abfd,
2189 strlen((char *)sym->name))
2190 < 0)
2192 end_etir_record (abfd);
2193 start_etir_record (abfd,
2194 section->index,
2195 vaddr, false);
2197 _bfd_vms_output_begin (abfd,
2198 ETIR_S_C_STO_GBL_LW,
2199 -1);
2200 _bfd_vms_output_counted (abfd,
2201 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2202 _bfd_vms_output_flush (abfd);
2204 else if (bfd_is_abs_section (sym->section))
2206 if (_bfd_vms_output_check (abfd, 16) < 0)
2208 end_etir_record (abfd);
2209 start_etir_record (abfd,
2210 section->index,
2211 vaddr, false);
2213 _bfd_vms_output_begin (abfd,
2214 ETIR_S_C_STA_LW,
2215 -1);
2216 _bfd_vms_output_quad (abfd,
2217 (uquad)sym->value);
2218 _bfd_vms_output_flush (abfd);
2219 _bfd_vms_output_begin (abfd,
2220 ETIR_S_C_STO_LW,
2221 -1);
2222 _bfd_vms_output_flush (abfd);
2224 else
2226 if (_bfd_vms_output_check (abfd, 32) < 0)
2228 end_etir_record (abfd);
2229 start_etir_record (abfd,
2230 section->index,
2231 vaddr, false);
2233 _bfd_vms_output_begin (abfd,
2234 ETIR_S_C_STA_PQ,
2235 -1);
2236 _bfd_vms_output_long (abfd,
2237 (unsigned long) (sec->index));
2238 _bfd_vms_output_quad (abfd,
2239 ((uquad) (*rptr)->addend
2240 + (uquad)sym->value));
2241 _bfd_vms_output_flush (abfd);
2242 _bfd_vms_output_begin (abfd,
2243 ETIR_S_C_STO_LW,
2244 -1);
2245 _bfd_vms_output_flush (abfd);
2248 break;
2250 case ALPHA_R_REFQUAD:
2252 if (bfd_is_und_section (sym->section))
2254 if (_bfd_vms_output_check (abfd,
2255 strlen((char *)sym->name))
2256 < 0)
2258 end_etir_record (abfd);
2259 start_etir_record (abfd,
2260 section->index,
2261 vaddr, false);
2263 _bfd_vms_output_begin (abfd,
2264 ETIR_S_C_STO_GBL,
2265 -1);
2266 _bfd_vms_output_counted (abfd,
2267 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2268 _bfd_vms_output_flush (abfd);
2270 else if (bfd_is_abs_section (sym->section))
2272 if (_bfd_vms_output_check (abfd, 16) < 0)
2274 end_etir_record (abfd);
2275 start_etir_record (abfd,
2276 section->index,
2277 vaddr, false);
2279 _bfd_vms_output_begin (abfd,
2280 ETIR_S_C_STA_QW,
2281 -1);
2282 _bfd_vms_output_quad (abfd,
2283 (uquad)sym->value);
2284 _bfd_vms_output_flush (abfd);
2285 _bfd_vms_output_begin (abfd,
2286 ETIR_S_C_STO_QW,
2287 -1);
2288 _bfd_vms_output_flush (abfd);
2290 else
2292 if (_bfd_vms_output_check (abfd, 32) < 0)
2294 end_etir_record (abfd);
2295 start_etir_record (abfd,
2296 section->index,
2297 vaddr, false);
2299 _bfd_vms_output_begin (abfd,
2300 ETIR_S_C_STA_PQ,
2301 -1);
2302 _bfd_vms_output_long (abfd,
2303 (unsigned long) (sec->index));
2304 _bfd_vms_output_quad (abfd,
2305 ((uquad) (*rptr)->addend
2306 + (uquad)sym->value));
2307 _bfd_vms_output_flush (abfd);
2308 _bfd_vms_output_begin (abfd,
2309 ETIR_S_C_STO_OFF,
2310 -1);
2311 _bfd_vms_output_flush (abfd);
2314 break;
2316 case ALPHA_R_HINT:
2318 int hint_size;
2320 hint_size = sptr->size;
2321 sptr->size = len;
2322 sto_imm (abfd, sptr, vaddr, section->index);
2323 sptr->size = hint_size;
2324 #if 0
2325 vms_output_begin(abfd, ETIR_S_C_STO_HINT_GBL, -1);
2326 vms_output_long(abfd, (unsigned long) (sec->index));
2327 vms_output_quad(abfd, (uquad)addr);
2329 vms_output_counted(abfd, _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2330 vms_output_flush(abfd);
2331 #endif
2333 break;
2334 case ALPHA_R_LINKAGE:
2336 if (_bfd_vms_output_check (abfd, 64) < 0)
2338 end_etir_record (abfd);
2339 start_etir_record (abfd, section->index,
2340 vaddr, false);
2342 _bfd_vms_output_begin (abfd,
2343 ETIR_S_C_STC_LP_PSB,
2344 -1);
2345 _bfd_vms_output_long (abfd,
2346 (unsigned long)PRIV(vms_linkage_index));
2347 PRIV(vms_linkage_index) += 2;
2348 _bfd_vms_output_counted (abfd,
2349 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2350 _bfd_vms_output_byte (abfd, 0);
2351 _bfd_vms_output_flush (abfd);
2353 break;
2355 case ALPHA_R_CODEADDR:
2357 if (_bfd_vms_output_check (abfd,
2358 strlen((char *)sym->name))
2359 < 0)
2361 end_etir_record (abfd);
2362 start_etir_record (abfd,
2363 section->index,
2364 vaddr, false);
2366 _bfd_vms_output_begin (abfd,
2367 ETIR_S_C_STO_CA,
2368 -1);
2369 _bfd_vms_output_counted (abfd,
2370 _bfd_vms_length_hash_symbol (abfd, sym->name, EOBJ_S_C_SYMSIZ));
2371 _bfd_vms_output_flush (abfd);
2373 break;
2375 default:
2376 (*_bfd_error_handler) (_("Unhandled relocation %s"),
2377 (*rptr)->howto->name);
2378 break;
2381 vaddr += len;
2383 if (len == sptr->size)
2385 break;
2387 else
2389 sptr->contents += len;
2390 sptr->offset += len;
2391 sptr->size -= len;
2392 i--;
2393 rptr++;
2396 else /* sptr starts after reloc */
2398 i--; /* check next reloc */
2399 rptr++;
2402 if (i==0) /* all reloc checked */
2404 if (sptr->size > 0)
2406 sto_imm (abfd, sptr, vaddr, section->index); /* dump rest */
2407 vaddr += sptr->size;
2409 break;
2411 } /* for (;;) */
2412 } /* if SEC_RELOC */
2413 else /* no relocs, just dump */
2415 sto_imm (abfd, sptr, vaddr, section->index);
2416 vaddr += sptr->size;
2419 sptr = sptr->next;
2421 } /* while (sptr != 0) */
2423 end_etir_record (abfd);
2425 } /* has_contents */
2427 section = section->next;
2430 _bfd_vms_output_alignment(abfd, 2);
2431 return 0;
2434 /* write traceback data for bfd abfd */
2437 _bfd_vms_write_tbt (abfd, objtype)
2438 bfd *abfd ATTRIBUTE_UNUSED;
2439 int objtype ATTRIBUTE_UNUSED;
2441 #if VMS_DEBUG
2442 _bfd_vms_debug (2, "vms_write_tbt (%p, %d)\n", abfd, objtype);
2443 #endif
2445 return 0;
2448 /* write debug info for bfd abfd */
2451 _bfd_vms_write_dbg (abfd, objtype)
2452 bfd *abfd ATTRIBUTE_UNUSED;
2453 int objtype ATTRIBUTE_UNUSED;
2455 #if VMS_DEBUG
2456 _bfd_vms_debug (2, "vms_write_dbg (%p, objtype)\n", abfd, objtype);
2457 #endif
2459 return 0;