2000-09-11 Kazu Hirata <kazu@hxi.com>
[binutils-gdb.git] / gas / config / tc-i370.c
1 /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
2 Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99
3 Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 /* This assembler implements a very hacked version of an elf-like thing
24 * that gcc emits (when gcc is suitably hacked). To make it behave more
25 * HLASM-like, try turning on the -M or --mri flag (as there are various
26 * similarities between HLASM and the MRI assemblers, such as section
27 * names, lack of leading . in pseudo-ops, DC and DS, etc ...
28 */
29
30 #include <stdio.h>
31 #include <ctype.h>
32 #include "as.h"
33 #include "subsegs.h"
34 #include "struc-symbol.h"
35
36 #include "opcode/i370.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/i370.h"
40 #endif
41
42 /* This is the assembler for the System/390 Architecture */
43
44 /* Tell the main code what the endianness is. */
45 extern int target_big_endian;
46
47 \f
48 /* Generic assembler global variables which must be defined by all
49 targets. */
50
51 #ifdef OBJ_ELF
52 /* This string holds the chars that always start a comment. If the
53 pre-processor is disabled, these aren't very useful. The macro
54 tc_comment_chars points to this. We use this, rather than the
55 usual comment_chars, so that we can switch for Solaris conventions. */
56 static const char i370_eabi_comment_chars[] = "#";
57
58 const char *i370_comment_chars = i370_eabi_comment_chars;
59 #else
60 const char comment_chars[] = "#";
61 #endif
62
63 /* Characters which start a comment at the beginning of a line. */
64 const char line_comment_chars[] = "#*";
65
66 /* Characters which may be used to separate multiple commands on a
67 single line. */
68 const char line_separator_chars[] = ";";
69
70 /* Characters which are used to indicate an exponent in a floating
71 point number. */
72 const char EXP_CHARS[] = "eE";
73
74 /* Characters which mean that a number is a floating point constant,
75 as in 0d1.0. */
76 const char FLT_CHARS[] = "dD";
77
78 void
79 md_show_usage (stream)
80 FILE *stream;
81 {
82 fprintf(stream, "\
83 S/370 options: (these have not yet been tested and may not work) \n\
84 -u ignored\n\
85 -mregnames Allow symbolic names for registers\n\
86 -mno-regnames Do not allow symbolic names for registers\n");
87 #ifdef OBJ_ELF
88 fprintf(stream, "\
89 -mrelocatable support for GCC's -mrelocatble option\n\
90 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
91 -V print assembler version number\n");
92 #endif
93 }
94
95 \f
96 static void i370_byte PARAMS ((int));
97 static void i370_tc PARAMS ((int));
98 static void i370_ebcdic PARAMS ((int));
99
100 static void i370_dc PARAMS ((int));
101 static void i370_ds PARAMS ((int));
102 static void i370_rmode PARAMS ((int));
103 static void i370_csect PARAMS ((int));
104 static void i370_dsect PARAMS ((int));
105 static void i370_ltorg PARAMS ((int));
106 static void i370_using PARAMS ((int));
107 static void i370_drop PARAMS ((int));
108 static void i370_make_relative PARAMS ((expressionS *exp, expressionS *baseaddr));
109
110 #ifdef OBJ_ELF
111 static bfd_reloc_code_real_type i370_elf_suffix PARAMS ((char **, expressionS *));
112 static void i370_elf_cons PARAMS ((int));
113 static void i370_elf_rdata PARAMS ((int));
114 static void i370_elf_lcomm PARAMS ((int));
115 static void i370_elf_validate_fix PARAMS ((fixS *, segT));
116 #endif
117
118 \f
119 /* The target specific pseudo-ops which we support. */
120
121 const pseudo_typeS md_pseudo_table[] =
122 {
123 /* Pseudo-ops which must be overridden. */
124 { "byte", i370_byte, 0 },
125
126 { "dc", i370_dc, 0 },
127 { "ds", i370_ds, 0 },
128 { "rmode", i370_rmode, 0 },
129 { "csect", i370_csect, 0 },
130 { "dsect", i370_dsect, 0 },
131
132 /* enable ebcdic strings e.g. for 3270 support */
133 { "ebcdic", i370_ebcdic, 0 },
134
135 #ifdef OBJ_ELF
136 { "long", i370_elf_cons, 4 },
137 { "word", i370_elf_cons, 4 },
138 { "short", i370_elf_cons, 2 },
139 { "rdata", i370_elf_rdata, 0 },
140 { "rodata", i370_elf_rdata, 0 },
141 { "lcomm", i370_elf_lcomm, 0 },
142 #endif
143
144 /* This pseudo-op is used even when not generating XCOFF output. */
145 { "tc", i370_tc, 0 },
146
147 /* dump the literal pool */
148 { "ltorg", i370_ltorg, 0 },
149
150 /* support the hlasm-style USING directive */
151 { "using", i370_using, 0 },
152 { "drop", i370_drop, 0 },
153
154 { NULL, NULL, 0 }
155 };
156
157 /* ***************************************************************** */
158
159 /* Whether to use user friendly register names. */
160 #define TARGET_REG_NAMES_P true
161
162 static boolean reg_names_p = TARGET_REG_NAMES_P;
163
164 static boolean register_name PARAMS ((expressionS *));
165 static void i370_set_cpu PARAMS ((void));
166 static i370_insn_t i370_insert_operand
167 PARAMS ((i370_insn_t insn, const struct i370_operand *operand, offsetT val));
168 static void i370_macro PARAMS ((char *str, const struct i370_macro *macro));
169 \f
170 /* Predefined register names if -mregnames */
171 /* In general, there are lots of them, in an attempt to be compatible */
172 /* with a number of assemblers. */
173
174 /* Structure to hold information about predefined registers. */
175 struct pd_reg
176 {
177 char *name;
178 int value;
179 };
180
181 /* List of registers that are pre-defined:
182
183 Each general register has predefined names of the form:
184 1. r<reg_num> which has the value <reg_num>.
185 2. r.<reg_num> which has the value <reg_num>.
186
187 Each floating point register has predefined names of the form:
188 1. f<reg_num> which has the value <reg_num>.
189 2. f.<reg_num> which has the value <reg_num>.
190
191 There are only four floating point registers, and these are
192 commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc.
193
194 There are individual registers as well:
195 rbase or r.base has the value 3 (base register)
196 rpgt or r.pgt has the value 4 (page origin table pointer)
197 rarg or r.arg has the value 11 (argument pointer)
198 rtca or r.tca has the value 12 (table of contents pointer)
199 rtoc or r.toc has the value 12 (table of contents pointer)
200 sp or r.sp has the value 13 (stack pointer)
201 dsa or r.dsa has the value 13 (stack pointer)
202 lr has the value 14 (link reg)
203
204 The table is sorted. Suitable for searching by a binary search. */
205
206 static const struct pd_reg pre_defined_registers[] =
207 {
208 { "arg", 11 }, /* Argument Pointer */
209 { "base", 3 }, /* Base Reg */
210
211 { "f.0", 0 }, /* Floating point registers */
212 { "f.2", 2 },
213 { "f.4", 4 },
214 { "f.6", 6 },
215
216 { "f0", 0 },
217 { "f2", 2 },
218 { "f4", 4 },
219 { "f6", 6 },
220
221 { "dsa",13 }, /* stack pointer */
222 { "lr", 14 }, /* Link Register */
223 { "pgt", 4 }, /* Page Origin Table Pointer */
224
225 { "r.0", 0 }, /* General Purpose Registers */
226 { "r.1", 1 },
227 { "r.10", 10 },
228 { "r.11", 11 },
229 { "r.12", 12 },
230 { "r.13", 13 },
231 { "r.14", 14 },
232 { "r.15", 15 },
233 { "r.2", 2 },
234 { "r.3", 3 },
235 { "r.4", 4 },
236 { "r.5", 5 },
237 { "r.6", 6 },
238 { "r.7", 7 },
239 { "r.8", 8 },
240 { "r.9", 9 },
241
242 { "r.arg", 11 }, /* Argument Pointer */
243 { "r.base", 3 }, /* Base Reg */
244 { "r.dsa", 13 }, /* Stack Pointer */
245 { "r.pgt", 4 }, /* Page Origin Table Pointer */
246 { "r.sp", 13 }, /* Stack Pointer */
247
248 { "r.tca", 12 }, /* Pointer to the table of contents */
249 { "r.toc", 12 }, /* Pointer to the table of contents */
250
251 { "r0", 0 }, /* More general purpose registers */
252 { "r1", 1 },
253 { "r10", 10 },
254 { "r11", 11 },
255 { "r12", 12 },
256 { "r13", 13 },
257 { "r14", 14 },
258 { "r15", 15 },
259 { "r2", 2 },
260 { "r3", 3 },
261 { "r4", 4 },
262 { "r5", 5 },
263 { "r6", 6 },
264 { "r7", 7 },
265 { "r8", 8 },
266 { "r9", 9 },
267
268 { "rbase", 3 }, /* Base Reg */
269
270 { "rtca", 12 }, /* Pointer to the table of contents */
271 { "rtoc", 12 }, /* Pointer to the table of contents */
272
273 { "sp", 13 }, /* Stack Pointer */
274
275 };
276
277 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
278
279 /* Given NAME, find the register number associated with that name, return
280 the integer value associated with the given name or -1 on failure. */
281
282 static int reg_name_search
283 PARAMS ((const struct pd_reg *, int, const char * name));
284
285 static int
286 reg_name_search (regs, regcount, name)
287 const struct pd_reg *regs;
288 int regcount;
289 const char *name;
290 {
291 int middle, low, high;
292 int cmp;
293
294 low = 0;
295 high = regcount - 1;
296
297 do
298 {
299 middle = (low + high) / 2;
300 cmp = strcasecmp (name, regs[middle].name);
301 if (cmp < 0)
302 high = middle - 1;
303 else if (cmp > 0)
304 low = middle + 1;
305 else
306 return regs[middle].value;
307 }
308 while (low <= high);
309
310 return -1;
311 }
312
313 /*
314 * Summary of register_name().
315 *
316 * in: Input_line_pointer points to 1st char of operand.
317 *
318 * out: A expressionS.
319 * The operand may have been a register: in this case, X_op == O_register,
320 * X_add_number is set to the register number, and truth is returned.
321 * Input_line_pointer->(next non-blank) char after operand, or is in its
322 * original state.
323 */
324
325 static boolean
326 register_name (expressionP)
327 expressionS *expressionP;
328 {
329 int reg_number;
330 char *name;
331 char *start;
332 char c;
333
334 /* Find the spelling of the operand */
335 start = name = input_line_pointer;
336 if (name[0] == '%' && isalpha (name[1]))
337 name = ++input_line_pointer;
338
339 else if (!reg_names_p)
340 return false;
341
342 while (' ' == *name)
343 name = ++input_line_pointer;
344
345 /* if its a number, treat it as a number */
346 /* if its alpha, look to see if it's in the register table */
347 if (!isalpha (name[0]))
348 {
349 reg_number = get_single_number();
350 c = get_symbol_end ();
351 }
352 else
353 {
354 c = get_symbol_end ();
355 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
356 }
357
358 /* if numeric, make sure its not out of bounds */
359 if ((0 <= reg_number) && (16 >= reg_number))
360 {
361 expressionP->X_op = O_register;
362 expressionP->X_add_number = reg_number;
363
364 /* make the rest nice */
365 expressionP->X_add_symbol = NULL;
366 expressionP->X_op_symbol = NULL;
367 *input_line_pointer = c; /* put back the delimiting char */
368 return true;
369 }
370
371 /* reset the line as if we had not done anything */
372 *input_line_pointer = c; /* put back the delimiting char */
373 input_line_pointer = start; /* reset input_line pointer */
374 return false;
375 }
376 \f
377 /* Local variables. */
378
379 /* The type of processor we are assembling for. This is one or more
380 of the I370_OPCODE flags defined in opcode/i370.h. */
381 static int i370_cpu = 0;
382
383 /* The base register to use for opcode with optional operands.
384 * We define two of these: "text" and "other". Normally, "text"
385 * would get used in the .text section for branches, while "other"
386 * gets used in the .data section for address constants.
387 *
388 * The idea of a second base register in a different section
389 * is foreign to the usual HLASM-style semantics; however, it
390 * allows us to provide support for dynamically loaded libraries,
391 * by allowing us to place address constants in a section other
392 * than the text section. The "other" section need not be the
393 * .data section, it can be any section that isn't the .text section.
394 *
395 * Note that HLASM defines a multiple, concurrent .using semantic
396 * that we do not: in calculating offsets, it uses either the most
397 * recent .using directive, or the one with the smallest displacement.
398 * This allows HLASM to support a quasi-block-scope-like behaviour.
399 * Handy for people writing assembly by hand ... but not supported
400 * by us.
401 */
402 static int i370_using_text_regno = -1;
403 static int i370_using_other_regno = -1;
404
405 /* The base address for address literals */
406 static expressionS i370_using_text_baseaddr;
407 static expressionS i370_using_other_baseaddr;
408
409 /* the "other" section, used only for syntax error detection */
410 static segT i370_other_section = undefined_section;
411
412 /* Opcode hash table. */
413 static struct hash_control *i370_hash;
414
415 /* Macro hash table. */
416 static struct hash_control *i370_macro_hash;
417
418 #ifdef OBJ_ELF
419 /* What type of shared library support to use */
420 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
421 #endif
422
423 /* Flags to set in the elf header */
424 static flagword i370_flags = 0;
425
426 #ifndef WORKING_DOT_WORD
427 const int md_short_jump_size = 4;
428 const int md_long_jump_size = 4;
429 #endif
430 \f
431 #ifdef OBJ_ELF
432 CONST char *md_shortopts = "l:um:K:VQ:";
433 #else
434 CONST char *md_shortopts = "um:";
435 #endif
436 struct option md_longopts[] =
437 {
438 {NULL, no_argument, NULL, 0}
439 };
440 size_t md_longopts_size = sizeof(md_longopts);
441
442 int
443 md_parse_option (c, arg)
444 int c;
445 char *arg;
446 {
447 switch (c)
448 {
449 case 'u':
450 /* -u means that any undefined symbols should be treated as
451 external, which is the default for gas anyhow. */
452 break;
453
454 #ifdef OBJ_ELF
455 case 'K':
456 /* Recognize -K PIC */
457 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
458 {
459 shlib = SHLIB_PIC;
460 i370_flags |= EF_I370_RELOCATABLE_LIB;
461 }
462 else
463 return 0;
464
465 break;
466 #endif
467
468 case 'm':
469
470 /* -m360 mean to assemble for the ancient 360 architecture */
471 if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0)
472 i370_cpu = I370_OPCODE_360;
473 /* -mxa means to assemble for the IBM 370 XA */
474 else if (strcmp (arg, "xa") == 0)
475 i370_cpu = I370_OPCODE_370_XA;
476 /* -many means to assemble for any architecture (370/XA). */
477 else if (strcmp (arg, "any") == 0)
478 i370_cpu = I370_OPCODE_370;
479
480 else if (strcmp (arg, "regnames") == 0)
481 reg_names_p = true;
482
483 else if (strcmp (arg, "no-regnames") == 0)
484 reg_names_p = false;
485
486 #ifdef OBJ_ELF
487 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
488 else if (strcmp (arg, "relocatable") == 0)
489 {
490 shlib = SHILB_MRELOCATABLE;
491 i370_flags |= EF_I370_RELOCATABLE;
492 }
493
494 else if (strcmp (arg, "relocatable-lib") == 0)
495 {
496 shlib = SHILB_MRELOCATABLE;
497 i370_flags |= EF_I370_RELOCATABLE_LIB;
498 }
499
500 #endif
501 else
502 {
503 as_bad ("invalid switch -m%s", arg);
504 return 0;
505 }
506 break;
507
508 #ifdef OBJ_ELF
509 /* -V: SVR4 argument to print version ID. */
510 case 'V':
511 print_version_id ();
512 break;
513
514 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
515 should be emitted or not. FIXME: Not implemented. */
516 case 'Q':
517 break;
518
519 #endif
520
521 default:
522 return 0;
523 }
524
525 return 1;
526 }
527
528 \f
529 /* Set i370_cpu if it is not already set.
530 Currently defaults to the reasonable superset;
531 but can be made more fine grained if desred. */
532
533 static void
534 i370_set_cpu ()
535 {
536 const char *default_os = TARGET_OS;
537 const char *default_cpu = TARGET_CPU;
538
539 /* override with the superset for the moment. */
540 i370_cpu = I370_OPCODE_ESA390_SUPERSET;
541 if (i370_cpu == 0)
542 {
543 if (strcmp (default_cpu, "i360") == 0)
544 i370_cpu = I370_OPCODE_360;
545 else if (strcmp (default_cpu, "i370") == 0)
546 i370_cpu = I370_OPCODE_370;
547 else if (strcmp (default_cpu, "XA") == 0)
548 i370_cpu = I370_OPCODE_370_XA;
549 else
550 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
551 }
552 }
553
554 /* Figure out the BFD architecture to use. */
555 // hack alert -- specify the different 370 architectures
556
557 enum bfd_architecture
558 i370_arch ()
559 {
560 return bfd_arch_i370;
561 }
562
563 /* This function is called when the assembler starts up. It is called
564 after the options have been parsed and the output file has been
565 opened. */
566
567 void
568 md_begin ()
569 {
570 register const struct i370_opcode *op;
571 const struct i370_opcode *op_end;
572 const struct i370_macro *macro;
573 const struct i370_macro *macro_end;
574 boolean dup_insn = false;
575
576 i370_set_cpu ();
577
578 #ifdef OBJ_ELF
579 /* Set the ELF flags if desired. */
580 if (i370_flags)
581 bfd_set_private_flags (stdoutput, i370_flags);
582 #endif
583
584 /* Insert the opcodes into a hash table. */
585 i370_hash = hash_new ();
586
587 op_end = i370_opcodes + i370_num_opcodes;
588 for (op = i370_opcodes; op < op_end; op++)
589 {
590 know ((op->opcode & op->mask) == op->opcode);
591
592 if ((op->flags & i370_cpu) != 0)
593 {
594 const char *retval;
595
596 retval = hash_insert (i370_hash, op->name, (PTR) op);
597 if (retval != (const char *) NULL)
598 {
599 as_bad ("Internal assembler error for instruction %s", op->name);
600 dup_insn = true;
601 }
602 }
603 }
604
605 /* Insert the macros into a hash table. */
606 i370_macro_hash = hash_new ();
607
608 macro_end = i370_macros + i370_num_macros;
609 for (macro = i370_macros; macro < macro_end; macro++)
610 {
611 if ((macro->flags & i370_cpu) != 0)
612 {
613 const char *retval;
614
615 retval = hash_insert (i370_macro_hash, macro->name, (PTR) macro);
616 if (retval != (const char *) NULL)
617 {
618 as_bad ("Internal assembler error for macro %s", macro->name);
619 dup_insn = true;
620 }
621 }
622 }
623
624 if (dup_insn)
625 abort ();
626 }
627
628 /* Insert an operand value into an instruction. */
629
630 static i370_insn_t
631 i370_insert_operand (insn, operand, val)
632 i370_insn_t insn;
633 const struct i370_operand *operand;
634 offsetT val;
635 {
636 if (operand->insert)
637 {
638 const char *errmsg;
639
640 /* used for 48-bit insn's */
641 errmsg = NULL;
642 insn = (*operand->insert) (insn, (long) val, &errmsg);
643 if (errmsg)
644 as_bad ("%s", errmsg);
645 }
646 else
647 {
648 /* this is used only for 16, 32 bit insn's */
649 insn.i[0] |= (((long) val & ((1 << operand->bits) - 1))
650 << operand->shift);
651 }
652
653 return insn;
654 }
655
656 \f
657 #ifdef OBJ_ELF
658 /* Parse @got, etc. and return the desired relocation.
659 * Currently, i370 does not support (don't really need to support) any
660 * of these fancier markups ... for example, no one is going to
661 * write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
662 * So basically, we could get away with this routine returning
663 * BFD_RELOC_UNUSED in all circumstances. However, I'll leave
664 * in for now in case someone ambitious finds a good use for this stuff ...
665 * this routine was pretty much just copied from the powerpc code ...
666 */
667 static bfd_reloc_code_real_type
668 i370_elf_suffix (str_p, exp_p)
669 char **str_p;
670 expressionS *exp_p;
671 {
672 struct map_bfd
673 {
674 char *string;
675 int length;
676 bfd_reloc_code_real_type reloc;
677 };
678
679 char ident[20];
680 char *str = *str_p;
681 char *str2;
682 int ch;
683 int len;
684 struct map_bfd *ptr;
685
686 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
687
688 static struct map_bfd mapping[] =
689 {
690 // MAP ("l", BFD_RELOC_LO16),
691 // MAP ("h", BFD_RELOC_HI16),
692 // MAP ("ha", BFD_RELOC_HI16_S),
693 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
694 { (char *)0, 0, BFD_RELOC_UNUSED }
695 };
696
697 if (*str++ != '@')
698 return BFD_RELOC_UNUSED;
699
700 for (ch = *str, str2 = ident;
701 (str2 < ident + sizeof (ident) - 1
702 && (isalnum (ch) || ch == '@'));
703 ch = *++str)
704 {
705 *str2++ = (islower (ch)) ? ch : tolower (ch);
706 }
707
708 *str2 = '\0';
709 len = str2 - ident;
710
711 ch = ident[0];
712 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
713 if (ch == ptr->string[0]
714 && len == ptr->length
715 && memcmp (ident, ptr->string, ptr->length) == 0)
716 {
717 if (exp_p->X_add_number != 0
718 && (ptr->reloc == BFD_RELOC_16_GOTOFF
719 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
720 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
721 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
722 as_warn ("identifier+constant@got means identifier@got+constant");
723
724 /* Now check for identifier@suffix+constant */
725 if (*str == '-' || *str == '+')
726 {
727 char *orig_line = input_line_pointer;
728 expressionS new_exp;
729
730 input_line_pointer = str;
731 expression (&new_exp);
732 if (new_exp.X_op == O_constant)
733 {
734 exp_p->X_add_number += new_exp.X_add_number;
735 str = input_line_pointer;
736 }
737
738 if (&input_line_pointer != str_p)
739 input_line_pointer = orig_line;
740 }
741
742 *str_p = str;
743 return ptr->reloc;
744 }
745
746 return BFD_RELOC_UNUSED;
747 }
748
749 /* Like normal .long/.short/.word, except support @got, etc. */
750 /* clobbers input_line_pointer, checks end-of-line. */
751 static void
752 i370_elf_cons (nbytes)
753 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
754 {
755 expressionS exp;
756 bfd_reloc_code_real_type reloc;
757
758 if (is_it_end_of_statement ())
759 {
760 demand_empty_rest_of_line ();
761 return;
762 }
763
764 do
765 {
766 expression (&exp);
767 if (exp.X_op == O_symbol
768 && *input_line_pointer == '@'
769 && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
770 {
771 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
772 int size = bfd_get_reloc_size (reloc_howto);
773
774 if (size > nbytes)
775 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
776
777 else
778 {
779 register char *p = frag_more ((int) nbytes);
780 int offset = nbytes - size;
781
782 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
783 }
784 }
785 else
786 emit_expr (&exp, (unsigned int) nbytes);
787 }
788 while (*input_line_pointer++ == ',');
789
790 input_line_pointer--; /* Put terminator back into stream. */
791 demand_empty_rest_of_line ();
792 }
793
794 \f
795 /* ASCII to EBCDIC conversion table. */
796 static unsigned char ascebc[256] =
797 {
798 /*00 NL SH SX EX ET NQ AK BL */
799 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
800 /*08 BS HT LF VT FF CR SO SI */
801 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
802 /*10 DL D1 D2 D3 D4 NK SN EB */
803 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
804 /*18 CN EM SB EC FS GS RS US */
805 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
806 /*20 SP ! " # $ % & ' */
807 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
808 /*28 ( ) * + , - . / */
809 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
810 /*30 0 1 2 3 4 5 6 7 */
811 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
812 /*38 8 9 : ; < = > ? */
813 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
814 /*40 @ A B C D E F G */
815 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
816 /*48 H I J K L M N O */
817 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
818 /*50 P Q R S T U V W */
819 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
820 /*58 X Y Z [ \ ] ^ _ */
821 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
822 /*60 ` a b c d e f g */
823 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
824 /*68 h i j k l m n o */
825 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
826 /*70 p q r s t u v w */
827 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
828 /*78 x y z { | } ~ DL */
829 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
830 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
831 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
832 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
833 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
834 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
835 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
836 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
837 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
838 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
839 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
840 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
841 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
842 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
843 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
844 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
845 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
846 };
847
848 /* EBCDIC to ASCII conversion table. */
849 unsigned char ebcasc[256] =
850 {
851 /*00 NU SH SX EX PF HT LC DL */
852 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
853 /*08 SM VT FF CR SO SI */
854 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
855 /*10 DE D1 D2 TM RS NL BS IL */
856 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
857 /*18 CN EM CC C1 FS GS RS US */
858 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
859 /*20 DS SS FS BP LF EB EC */
860 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
861 /*28 SM C2 EQ AK BL */
862 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
863 /*30 SY PN RS UC ET */
864 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
865 /*38 C3 D4 NK SU */
866 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
867 /*40 SP */
868 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
869 /*48 . < ( + | */
870 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
871 /*50 & */
872 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
873 /*58 ! $ * ) ; ^ */
874 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
875 /*60 - / */
876 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
877 /*68 , % _ > ? */
878 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
879 /*70 */
880 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
881 /*78 ` : # @ ' = " */
882 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
883 /*80 a b c d e f g */
884 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
885 /*88 h i { */
886 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
887 /*90 j k l m n o p */
888 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
889 /*98 q r } */
890 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
891 /*A0 ~ s t u v w x */
892 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
893 /*A8 y z [ */
894 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
895 /*B0 */
896 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
897 /*B8 ] */
898 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
899 /*C0 { A B C D E F G */
900 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
901 /*C8 H I */
902 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
903 /*D0 } J K L M N O P */
904 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
905 /*D8 Q R */
906 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
907 /*E0 \ S T U V W X */
908 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
909 /*E8 Y Z */
910 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
911 /*F0 0 1 2 3 4 5 6 7 */
912 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
913 /*F8 8 9 */
914 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
915 };
916
917 /* ebcdic translation tables needed for 3270 support */
918 static void
919 i370_ebcdic (unused)
920 int unused;
921 {
922 char *p, *end;
923 char delim = 0;
924 size_t nbytes;
925
926 nbytes = strlen (input_line_pointer);
927 end = input_line_pointer + nbytes;
928 while ('\r' == *end) end --;
929 while ('\n' == *end) end --;
930
931 delim = *input_line_pointer;
932 if (('\'' == delim) || ('\"' == delim)) {
933 input_line_pointer ++;
934 end = rindex (input_line_pointer, delim);
935 }
936
937 if (end > input_line_pointer)
938 {
939 nbytes = end - input_line_pointer +1;
940 p = frag_more (nbytes);
941 while (end > input_line_pointer)
942 {
943 *p = ascebc [(unsigned char)(*input_line_pointer)];
944 ++p; ++input_line_pointer;
945 }
946 *p = '\0';
947 }
948 if (delim == *input_line_pointer) ++input_line_pointer;
949 }
950
951 \f
952 /* stub out a couple of routines */
953 static void
954 i370_rmode (unused)
955 int unused;
956 {
957 as_tsktsk ("rmode ignored");
958 }
959
960 static void
961 i370_dsect (sect)
962 int sect;
963 {
964 char *save_line = input_line_pointer;
965 static char section[] = ".data\n";
966
967 /* Just pretend this is .section .data */
968 input_line_pointer = section;
969 obj_elf_section (sect);
970
971 input_line_pointer = save_line;
972 }
973
974 static void
975 i370_csect (unused)
976 int unused;
977 {
978 as_tsktsk ("csect not supported");
979 }
980
981 \f
982 /* DC Define Const is only partially supported.
983 * For samplecode on what to do, look at i370_elf_cons() above.
984 * This code handles pseudoops of the style
985 * DC D'3.141592653' # in sysv4, .double 3.14159265
986 * DC F'1' # in sysv4, .long 1
987 */
988 static void
989 i370_dc(unused)
990 int unused;
991 {
992 char * p, tmp[50];
993 int nbytes=0;
994 expressionS exp;
995 char type=0;
996
997 if (is_it_end_of_statement ())
998 {
999 demand_empty_rest_of_line ();
1000 return;
1001 }
1002
1003 /* figure out the size */
1004 type = *input_line_pointer++;
1005 switch (type)
1006 {
1007 case 'H': /* 16-bit */
1008 nbytes = 2;
1009 break;
1010 case 'E': /* 32-bit */
1011 case 'F': /* 32-bit */
1012 nbytes = 4;
1013 break;
1014 case 'D': /* 64-bit */
1015 nbytes = 8;
1016 break;
1017 default:
1018 as_bad ("unsupported DC type");
1019 return;
1020 }
1021
1022 /* get rid of pesky quotes */
1023 if ('\'' == *input_line_pointer)
1024 {
1025 char * close;
1026 ++input_line_pointer;
1027 close = strchr (input_line_pointer, '\'');
1028 if (close)
1029 *close= ' ';
1030 else
1031 as_bad ("missing end-quote");
1032 }
1033 if ('\"' == *input_line_pointer)
1034 {
1035 char * close;
1036 ++input_line_pointer;
1037 close = strchr (input_line_pointer, '\"');
1038 if (close)
1039 *close= ' ';
1040 else
1041 as_bad ("missing end-quote");
1042 }
1043
1044 switch (type)
1045 {
1046 case 'H': /* 16-bit */
1047 case 'F': /* 32-bit */
1048 expression (&exp);
1049 emit_expr (&exp, nbytes);
1050 break;
1051 case 'E': /* 32-bit */
1052 case 'D': /* 64-bit */
1053 md_atof (type, tmp, &nbytes);
1054 p = frag_more (nbytes);
1055 memcpy (p, tmp, nbytes);
1056 break;
1057 default:
1058 as_bad ("unsupported DC type");
1059 return;
1060 }
1061
1062 demand_empty_rest_of_line ();
1063 }
1064
1065 \f
1066 /* provide minimal support for DS Define Storage */
1067 static void
1068 i370_ds (unused)
1069 int unused;
1070 {
1071 /* DS 0H or DS 0F or DS 0D */
1072 if ('0' == *input_line_pointer)
1073 {
1074 int alignment = 0; /* left shift 1<<align */
1075 input_line_pointer ++;
1076 switch (*input_line_pointer++)
1077 {
1078 case 'H': /* 16-bit */
1079 alignment = 1;
1080 break;
1081 case 'F': /* 32-bit */
1082 alignment = 2;
1083 break;
1084 case 'D': /* 64-bit */
1085 alignment = 3;
1086 break;
1087 default:
1088 as_bad ("unsupported alignment");
1089 return;
1090 }
1091 frag_align (alignment, 0, 0);
1092 record_alignment (now_seg, alignment);
1093 }
1094 else
1095 {
1096 as_bad ("this DS form not yet supported");
1097 }
1098 }
1099
1100 /* Solaris pseudo op to change to the .rodata section. */
1101 static void
1102 i370_elf_rdata (sect)
1103 int sect;
1104 {
1105 char *save_line = input_line_pointer;
1106 static char section[] = ".rodata\n";
1107
1108 /* Just pretend this is .section .rodata */
1109 input_line_pointer = section;
1110 obj_elf_section (sect);
1111
1112 input_line_pointer = save_line;
1113 }
1114
1115 /* Pseudo op to make file scope bss items */
1116 static void
1117 i370_elf_lcomm(unused)
1118 int unused;
1119 {
1120 register char *name;
1121 register char c;
1122 register char *p;
1123 offsetT size;
1124 register symbolS *symbolP;
1125 offsetT align;
1126 segT old_sec;
1127 int old_subsec;
1128 char *pfrag;
1129 int align2;
1130
1131 name = input_line_pointer;
1132 c = get_symbol_end ();
1133
1134 /* just after name is now '\0' */
1135 p = input_line_pointer;
1136 *p = c;
1137 SKIP_WHITESPACE ();
1138 if (*input_line_pointer != ',')
1139 {
1140 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1141 ignore_rest_of_line ();
1142 return;
1143 }
1144
1145 input_line_pointer++; /* skip ',' */
1146 if ((size = get_absolute_expression ()) < 0)
1147 {
1148 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size);
1149 ignore_rest_of_line ();
1150 return;
1151 }
1152
1153 /* The third argument to .lcomm is the alignment. */
1154 if (*input_line_pointer != ',')
1155 align = 8;
1156 else
1157 {
1158 ++input_line_pointer;
1159 align = get_absolute_expression ();
1160 if (align <= 0)
1161 {
1162 as_warn ("ignoring bad alignment");
1163 align = 8;
1164 }
1165 }
1166
1167 *p = 0;
1168 symbolP = symbol_find_or_make (name);
1169 *p = c;
1170
1171 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1172 {
1173 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1174 S_GET_NAME (symbolP));
1175 ignore_rest_of_line ();
1176 return;
1177 }
1178
1179 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1180 {
1181 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1182 S_GET_NAME (symbolP),
1183 (long) S_GET_VALUE (symbolP),
1184 (long) size);
1185
1186 ignore_rest_of_line ();
1187 return;
1188 }
1189
1190 /* allocate_bss: */
1191 old_sec = now_seg;
1192 old_subsec = now_subseg;
1193 if (align)
1194 {
1195 /* convert to a power of 2 alignment */
1196 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
1197 ;
1198 if (align != 1)
1199 {
1200 as_bad ("Common alignment not a power of 2");
1201 ignore_rest_of_line ();
1202 return;
1203 }
1204 }
1205 else
1206 align2 = 0;
1207
1208 record_alignment (bss_section, align2);
1209 subseg_set (bss_section, 0);
1210 if (align2)
1211 frag_align (align2, 0, 0);
1212 if (S_GET_SEGMENT (symbolP) == bss_section)
1213 symbol_get_frag (symbolP)->fr_symbol = 0;
1214 symbol_set_frag (symbolP, frag_now);
1215 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1216 (char *) 0);
1217 *pfrag = 0;
1218 S_SET_SIZE (symbolP, size);
1219 S_SET_SEGMENT (symbolP, bss_section);
1220 subseg_set (old_sec, old_subsec);
1221 demand_empty_rest_of_line ();
1222 }
1223
1224 /* Validate any relocations emitted for -mrelocatable, possibly adding
1225 fixups for word relocations in writable segments, so we can adjust
1226 them at runtime. */
1227 static void
1228 i370_elf_validate_fix (fixp, seg)
1229 fixS *fixp;
1230 segT seg;
1231 {
1232 if (fixp->fx_done || fixp->fx_pcrel)
1233 return;
1234
1235 switch (shlib)
1236 {
1237 case SHLIB_NONE:
1238 case SHLIB_PIC:
1239 return;
1240
1241 case SHILB_MRELOCATABLE:
1242 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1243 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1244 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1245 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1246 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1247 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1248 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1249 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1250 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1251 && strcmp (segment_name (seg), ".got2") != 0
1252 && strcmp (segment_name (seg), ".dtors") != 0
1253 && strcmp (segment_name (seg), ".ctors") != 0
1254 && strcmp (segment_name (seg), ".fixup") != 0
1255 && strcmp (segment_name (seg), ".stab") != 0
1256 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1257 && strcmp (segment_name (seg), ".ex_shared") != 0)
1258 {
1259 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1260 || fixp->fx_r_type != BFD_RELOC_CTOR)
1261 {
1262 as_bad_where (fixp->fx_file, fixp->fx_line,
1263 "Relocation cannot be done when using -mrelocatable");
1264 }
1265 }
1266 return;
1267 }
1268 }
1269 #endif /* OBJ_ELF */
1270
1271 \f
1272 #define LITERAL_POOL_SUPPORT
1273 #ifdef LITERAL_POOL_SUPPORT
1274 /* Provide support for literal pools within the text section. */
1275 /* Loosely based on similar code from tc-arm.c */
1276 /*
1277 * We will use four symbols to locate four parts of the literal pool.
1278 * These four sections contain 64,32,16 and 8-bit constants; we use
1279 * four sections so that all memory access can be appropriately aligned.
1280 * That is, we want to avoid mixing these together so that we don't
1281 * waste space padding out to alignments. The four pointers
1282 * longlong_poolP, word_poolP, etc. point to a symbol labeling the
1283 * start of each pool part.
1284 *
1285 * lit_pool_num increments from zero to infinity and uniquely id's
1286 * -- its used to generate the *_poolP symbol name.
1287 */
1288
1289 #define MAX_LITERAL_POOL_SIZE 1024
1290
1291 typedef struct literalS
1292 {
1293 struct expressionS exp;
1294 char * sym_name;
1295 char size; /* 1,2,4 or 8 */
1296 short offset;
1297 } literalT;
1298
1299 literalT literals[MAX_LITERAL_POOL_SIZE];
1300 int next_literal_pool_place = 0; /* Next free entry in the pool */
1301
1302 static symbolS *longlong_poolP = NULL; /* 64-bit pool entries */
1303 static symbolS *word_poolP = NULL; /* 32-bit pool entries */
1304 static symbolS *short_poolP = NULL; /* 16-bit pool entries */
1305 static symbolS *byte_poolP = NULL; /* 8-bit pool entries */
1306
1307 static int lit_pool_num = 1;
1308
1309 /* create a new, empty symbol */
1310 static symbolS *
1311 symbol_make_empty (void)
1312 {
1313 return symbol_create (FAKE_LABEL_NAME, undefined_section,
1314 (valueT) 0, &zero_address_frag);
1315 }
1316
1317 /* add an expression to the literal pool */
1318 static void
1319 add_to_lit_pool (expressionS *exx, char *name, int sz)
1320 {
1321 int lit_count = 0;
1322 int offset_in_pool = 0;
1323
1324 /* start a new pool, if necessary */
1325 if (8 == sz && NULL == longlong_poolP)
1326 longlong_poolP = symbol_make_empty();
1327 else if (4 == sz && NULL == word_poolP)
1328 word_poolP = symbol_make_empty();
1329 else if (2 == sz && NULL == short_poolP)
1330 short_poolP = symbol_make_empty();
1331 else if (1 == sz && NULL == byte_poolP)
1332 byte_poolP = symbol_make_empty();
1333
1334 /* Check if this literal value is already in the pool: */
1335 /* hack alert -- we should probably be checking expressions
1336 * of type O_symbol as well ... */
1337 /* hack alert XXX this is probably(certainly?) broken for O_big,
1338 * which includes 64-bit long-longs ...
1339 */
1340 while (lit_count < next_literal_pool_place)
1341 {
1342 if (exx->X_op == O_constant
1343 && literals[lit_count].exp.X_op == exx->X_op
1344 && literals[lit_count].exp.X_add_number == exx->X_add_number
1345 && literals[lit_count].exp.X_unsigned == exx->X_unsigned
1346 && literals[lit_count].size == sz)
1347 break;
1348 else if (literals[lit_count].sym_name
1349 && name
1350 && !strcmp (name, literals[lit_count].sym_name))
1351 break;
1352 if (sz == literals[lit_count].size)
1353 offset_in_pool += sz;
1354 lit_count ++;
1355 }
1356
1357 if (lit_count == next_literal_pool_place) /* new entry */
1358 {
1359 if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
1360 {
1361 as_bad("Literal Pool Overflow");
1362 }
1363
1364 literals[next_literal_pool_place].exp = *exx;
1365 literals[next_literal_pool_place].size = sz;
1366 literals[next_literal_pool_place].offset = offset_in_pool;
1367 if (name)
1368 {
1369 literals[next_literal_pool_place].sym_name = strdup (name);
1370 }
1371 else
1372 {
1373 literals[next_literal_pool_place].sym_name = NULL;
1374 }
1375 next_literal_pool_place++;
1376 }
1377
1378 /* ???_poolP points to the begining of the literal pool.
1379 * X_add_number is the offset from the begining of the
1380 * literal pool to this expr minus the location of the most
1381 * recent .using directive. Thus, the grand total value of the
1382 * expression is the distance from .using to the literal.
1383 */
1384 if (8 == sz)
1385 exx->X_add_symbol = longlong_poolP;
1386 else if (4 == sz)
1387 exx->X_add_symbol = word_poolP;
1388 else if (2 == sz)
1389 exx->X_add_symbol = short_poolP;
1390 else if (1 == sz)
1391 exx->X_add_symbol = byte_poolP;
1392 exx->X_add_number = offset_in_pool;
1393 exx->X_op_symbol = NULL;
1394
1395 /* If the user has set up a base reg in another section,
1396 * use that; otherwise use the text section. */
1397 if (0 < i370_using_other_regno)
1398 {
1399 i370_make_relative (exx, &i370_using_other_baseaddr);
1400 }
1401 else
1402 {
1403 i370_make_relative (exx, &i370_using_text_baseaddr);
1404 }
1405 }
1406
1407 /* The symbol setup for the literal pool is done in two steps. First,
1408 * a symbol that represents the start of the literal pool is created,
1409 * above, in the add_to_pool() routine. This sym ???_poolP.
1410 * However, we don't know what fragment its in until a bit later.
1411 * So we defer the frag_now thing, and the symbol name, until .ltorg time
1412 */
1413
1414 /* Can't use symbol_new here, so have to create a symbol and then at
1415 a later date assign it a value. Thats what these functions do */
1416 static void
1417 symbol_locate (symbolP, name, segment, valu, frag)
1418 symbolS *symbolP;
1419 CONST char *name; /* It is copied, the caller can modify */
1420 segT segment; /* Segment identifier (SEG_<something>) */
1421 valueT valu; /* Symbol value */
1422 fragS *frag; /* Associated fragment */
1423 {
1424 size_t name_length;
1425 char *preserved_copy_of_name;
1426
1427 name_length = strlen (name) + 1; /* +1 for \0 */
1428 obstack_grow (&notes, name, name_length);
1429 preserved_copy_of_name = obstack_finish (&notes);
1430
1431 S_SET_NAME (symbolP, preserved_copy_of_name);
1432
1433 S_SET_SEGMENT (symbolP, segment);
1434 S_SET_VALUE (symbolP, valu);
1435 symbol_clear_list_pointers(symbolP);
1436
1437 symbol_set_frag (symbolP, frag);
1438
1439 /*
1440 * Link to end of symbol chain.
1441 */
1442 {
1443 extern int symbol_table_frozen;
1444 if (symbol_table_frozen)
1445 abort ();
1446 }
1447
1448 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
1449
1450 obj_symbol_new_hook (symbolP);
1451
1452 #ifdef tc_symbol_new_hook
1453 tc_symbol_new_hook (symbolP);
1454 #endif
1455
1456 #define DEBUG_SYMS
1457 #ifdef DEBUG_SYMS
1458 verify_symbol_chain(symbol_rootP, symbol_lastP);
1459 #endif /* DEBUG_SYMS */
1460 }
1461
1462 /* i370_addr_offset() will convert operand expressions
1463 * that appear to be absolute into thier base-register
1464 * relative form. These expressions come in two types:
1465 *
1466 * (1) of the form "* + const" * where "*" means
1467 * relative offset since the last using
1468 * i.e. "*" means ".-using_baseaddr"
1469 *
1470 * (2) labels, which are never absolute, but are always
1471 * relative to the last "using". Anything with an alpha
1472 * character is considered to be a label (since symbols
1473 * can never be operands), and since we've already handled
1474 * register operands. For example, "BL .L33" branch low
1475 * to .L33 RX form insn frequently terminates for-loops,
1476 */
1477 static boolean
1478 i370_addr_offset (expressionS *exx)
1479 {
1480 char *dot, *lab;
1481 int islabel = 0;
1482 int all_digits = 0;
1483
1484 /* search for a label; anything with an alpha char will do */
1485 /* local labels consist of N digits followed by either b or f */
1486 lab = input_line_pointer;
1487 while (*lab && (',' != *lab) && ('(' != *lab))
1488 {
1489 if (isdigit(*lab))
1490 {
1491 all_digits = 1;
1492 }
1493 else if (isalpha(*lab))
1494 {
1495 if (!all_digits)
1496 {
1497 islabel = 1;
1498 break;
1499 }
1500 else if (('f' == *lab) || ('b' == *lab))
1501 {
1502 islabel = 1;
1503 break;
1504 }
1505 if (all_digits)
1506 break;
1507 }
1508 else if ('.' != *lab)
1509 break;
1510 ++lab;
1511 }
1512
1513 /* See if operand has a * in it */
1514 dot = strchr (input_line_pointer, '*');
1515
1516 if (!dot && !islabel)
1517 return false;
1518
1519 /* replace * with . and let expr munch on it. */
1520 if (dot)
1521 *dot = '.';
1522 expression (exx);
1523
1524 /* OK, now we have to subtract the "using" location */
1525 /* normally branches appear in the text section only... */
1526 if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno)
1527 {
1528 i370_make_relative (exx, &i370_using_text_baseaddr);
1529 }
1530 else
1531 {
1532 i370_make_relative (exx, &i370_using_other_baseaddr);
1533 }
1534
1535 /* put the * back */
1536 if (dot)
1537 *dot = '*';
1538
1539 return true;
1540 }
1541
1542 /* handle address constants of various sorts */
1543 /* The currently supported types are
1544 * =A(some_symb)
1545 * =V(some_extern)
1546 * =X'deadbeef' hexadecimal
1547 * =F'1234' 32-bit const int
1548 * =H'1234' 16-bit const int
1549 */
1550 static boolean
1551 i370_addr_cons (expressionS *exp)
1552 {
1553 char *name;
1554 char *sym_name, delim;
1555 int name_len;
1556 int hex_len=0;
1557 int cons_len=0;
1558
1559 name = input_line_pointer;
1560 sym_name = input_line_pointer;
1561 /* Find the spelling of the operand */
1562 if (name[0] == '=' && isalpha (name[1]))
1563 {
1564 name = ++input_line_pointer;
1565 }
1566 else
1567 {
1568 return false;
1569 }
1570 switch (name[0])
1571 {
1572 case 'A':
1573 case 'V':
1574 /* A == address-of */
1575 /* V == extern */
1576 ++input_line_pointer;
1577 expression (exp);
1578
1579 /* we use a simple string name to collapse together
1580 * multiple refrences to the same address literal
1581 */
1582 name_len = strcspn (sym_name, ", ");
1583 delim = *(sym_name + name_len);
1584 *(sym_name + name_len) = 0x0;
1585 add_to_lit_pool (exp, sym_name, 4);
1586 *(sym_name + name_len) = delim;
1587
1588 break;
1589 case 'H':
1590 case 'F':
1591 case 'X':
1592 case 'E': /* single-precision float point */
1593 case 'D': /* double-precision float point */
1594
1595 /* H == 16-bit fixed-point const; expression must be const */
1596 /* F == fixed-point const; expression must be const */
1597 /* X == fixed-point const; expression must be const */
1598 if ('H' == name[0]) cons_len = 2;
1599 else if ('F' == name[0]) cons_len = 4;
1600 else if ('X' == name[0]) cons_len = -1;
1601 else if ('E' == name[0]) cons_len = 4;
1602 else if ('D' == name[0]) cons_len = 8;
1603
1604 /* extract length, if it is present; hack alert -- assume single-digit
1605 * length */
1606 if ('L' == name[1])
1607 {
1608 cons_len = name[2] - '0'; /* should work for ascii and ebcdic */
1609 input_line_pointer += 2;
1610 }
1611
1612 ++input_line_pointer;
1613
1614 /* get rid of pesky quotes */
1615 if ('\'' == *input_line_pointer)
1616 {
1617 char * close;
1618 ++input_line_pointer;
1619 close = strchr (input_line_pointer, '\'');
1620 if (close)
1621 *close= ' ';
1622 else
1623 as_bad ("missing end-quote");
1624 }
1625 if ('\"' == *input_line_pointer)
1626 {
1627 char * close;
1628 ++input_line_pointer;
1629 close = strchr (input_line_pointer, '\"');
1630 if (close)
1631 *close= ' ';
1632 else
1633 as_bad ("missing end-quote");
1634 }
1635 if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0]))
1636 {
1637 char tmp[50];
1638 char *save;
1639
1640 /* The length of hex constants is specified directly with L,
1641 * or implied through the number of hex digits. For example:
1642 * =X'AB' one byte
1643 * =X'abcd' two bytes
1644 * =X'000000AB' four bytes
1645 * =XL4'AB' four bytes, left-padded withn zero
1646 */
1647 if (('X' == name[0]) && (0 > cons_len))
1648 {
1649 save = input_line_pointer;
1650 while (*save)
1651 {
1652 if (isxdigit(*save))
1653 hex_len++;
1654 save++;
1655 }
1656 cons_len = (hex_len+1) /2;
1657 }
1658 /* I beleive this works even for =XL8'dada0000beeebaaa'
1659 * which should parse out to X_op == O_big
1660 * Note that floats and doubles get represented as
1661 * 0d3.14159265358979 or 0f 2.7
1662 */
1663 tmp[0] = '0';
1664 tmp[1] = name[0];
1665 tmp[2] = 0;
1666 strcat (tmp, input_line_pointer);
1667 save = input_line_pointer;
1668 input_line_pointer = tmp;
1669 expression (exp);
1670 input_line_pointer = save + (input_line_pointer-tmp-2);
1671
1672 /* fix up lengths for floats and doubles */
1673 if (O_big == exp->X_op)
1674 {
1675 exp->X_add_number = cons_len / CHARS_PER_LITTLENUM;
1676 }
1677 }
1678 else
1679 {
1680 expression (exp);
1681 }
1682 /* O_big occurs when more than 4 bytes worth gets parsed */
1683 if ((exp->X_op != O_constant) && (exp->X_op != O_big))
1684 {
1685 as_bad ("expression not a constant");
1686 return false;
1687 }
1688 add_to_lit_pool (exp, 0x0, cons_len);
1689 break;
1690
1691 default:
1692 as_bad ("Unknown/unsupported address literal type");
1693 return false;
1694 }
1695
1696 return true;
1697 }
1698
1699 \f
1700 /* Dump the contents of the literal pool that we've accumulated so far.
1701 * This aligns the pool to the size of the largest literal in the pool.
1702 */
1703
1704 static void
1705 i370_ltorg (ignore)
1706 int ignore;
1707 {
1708 int litsize;
1709 int lit_count = 0;
1710 int biggest_literal_size = 0;
1711 int biggest_align = 0;
1712 char pool_name[20];
1713
1714 if (strncmp (now_seg->name, ".text", 5))
1715 {
1716 if (i370_other_section == undefined_section)
1717 {
1718 as_bad (".ltorg without prior .using in section %s",
1719 now_seg->name);
1720 }
1721 if (i370_other_section != now_seg)
1722 {
1723 as_bad (".ltorg in section %s paired to .using in section %s",
1724 now_seg->name, i370_other_section->name);
1725 }
1726 }
1727 if (! longlong_poolP
1728 && ! word_poolP
1729 && ! short_poolP
1730 && ! byte_poolP)
1731 {
1732 /* Nothing to do */
1733 /* as_tsktsk ("Nothing to put in the pool\n"); */
1734 return;
1735 }
1736
1737 /* find largest literal .. 2 4 or 8 */
1738 lit_count = 0;
1739 while (lit_count < next_literal_pool_place)
1740 {
1741 if (biggest_literal_size < literals[lit_count].size)
1742 biggest_literal_size = literals[lit_count].size;
1743 lit_count ++;
1744 }
1745 if (1 == biggest_literal_size) biggest_align = 0;
1746 else if (2 == biggest_literal_size) biggest_align = 1;
1747 else if (4 == biggest_literal_size) biggest_align = 2;
1748 else if (8 == biggest_literal_size) biggest_align = 3;
1749 else as_bad ("bad alignment of %d bytes in literal pool", biggest_literal_size);
1750 if (0 == biggest_align) biggest_align = 1;
1751
1752 /* Align pool for short, word, double word accesses */
1753 frag_align (biggest_align, 0, 0);
1754 record_alignment (now_seg, biggest_align);
1755
1756 /* Note that the gas listing will print only the first five
1757 * entries in the pool .... wonder how to make it print more ...
1758 */
1759 /* output largest literals first, then the smaller ones. */
1760 for (litsize=8; litsize; litsize /=2)
1761 {
1762 symbolS *current_poolP = NULL;
1763 switch (litsize)
1764 {
1765 case 8:
1766 current_poolP = longlong_poolP; break;
1767 case 4:
1768 current_poolP = word_poolP; break;
1769 case 2:
1770 current_poolP = short_poolP; break;
1771 case 1:
1772 current_poolP = byte_poolP; break;
1773 default:
1774 as_bad ("bad literal size\n");
1775 }
1776 if (NULL == current_poolP)
1777 continue;
1778 sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num);
1779 symbol_locate (current_poolP, pool_name, now_seg,
1780 (valueT) frag_now_fix (), frag_now);
1781 symbol_table_insert (current_poolP);
1782
1783 lit_count = 0;
1784 while (lit_count < next_literal_pool_place)
1785 {
1786 if (litsize == literals[lit_count].size)
1787 {
1788 #define EMIT_ADDR_CONS_SYMBOLS
1789 #ifdef EMIT_ADDR_CONS_SYMBOLS
1790 /* create a bogus symbol, add it to the pool ...
1791 * For the most part, I think this is a useless excercise,
1792 * except that having these symbol names in the objects
1793 * is vaguely useful for debugging ...
1794 */
1795 if (literals[lit_count].sym_name)
1796 {
1797 symbolS * symP = symbol_make_empty();
1798 symbol_locate (symP, literals[lit_count].sym_name, now_seg,
1799 (valueT) frag_now_fix (), frag_now);
1800 symbol_table_insert (symP);
1801 }
1802 #endif /* EMIT_ADDR_CONS_SYMBOLS */
1803
1804 emit_expr (&(literals[lit_count].exp), literals[lit_count].size);
1805 }
1806 lit_count ++;
1807 }
1808 }
1809
1810 next_literal_pool_place = 0;
1811 longlong_poolP = NULL;
1812 word_poolP = NULL;
1813 short_poolP = NULL;
1814 byte_poolP = NULL;
1815 lit_pool_num++;
1816 }
1817
1818 #endif /* LITERAL_POOL_SUPPORT */
1819
1820 \f
1821 /* add support for the HLASM-like USING directive to indicate
1822 * the base register to use ... we don't support the full
1823 * hlasm semantics for this ... we merely pluck a base address
1824 * and a register number out. We print a warning if using is
1825 * called multiple times. I suppose we should check to see
1826 * if the regno is valid ...
1827 */
1828 static void
1829 i370_using (ignore)
1830 int ignore;
1831 {
1832 expressionS ex, baseaddr;
1833 int iregno;
1834 char *star;
1835
1836 /* if "*" appears in a using, it means "." */
1837 /* replace it with "." so that expr doesn't get confused. */
1838 star = strchr (input_line_pointer, '*');
1839 if (star)
1840 *star = '.';
1841
1842 /* the first arg to using will usually be ".", but it can
1843 * be a more complex exprsssion too ... */
1844 expression (&baseaddr);
1845 if (star)
1846 *star = '*';
1847 if (O_constant != baseaddr.X_op
1848 && O_symbol != baseaddr.X_op
1849 && O_uminus != baseaddr.X_op)
1850 {
1851 as_bad (".using: base address expression illegal or too complex");
1852 }
1853
1854 if (*input_line_pointer != '\0') ++input_line_pointer;
1855
1856 /* the second arg to using had better be a register */
1857 register_name (&ex);
1858 demand_empty_rest_of_line ();
1859 iregno = ex.X_add_number;
1860
1861 if (0 == strncmp (now_seg->name, ".text", 5))
1862 {
1863 i370_using_text_baseaddr = baseaddr;
1864 i370_using_text_regno = iregno;
1865 }
1866 else
1867 {
1868 i370_using_other_baseaddr = baseaddr;
1869 i370_using_other_regno = iregno;
1870 i370_other_section = now_seg;
1871 }
1872 }
1873
1874 static void
1875 i370_drop (ignore)
1876 int ignore;
1877 {
1878 expressionS ex;
1879 int iregno;
1880
1881 register_name (&ex);
1882 demand_empty_rest_of_line ();
1883 iregno = ex.X_add_number;
1884
1885 if (0 == strncmp (now_seg->name, ".text", 5))
1886 {
1887 if (iregno != i370_using_text_regno)
1888 {
1889 as_bad ("droping register %d in section %s does not match using register %d",
1890 iregno, now_seg->name, i370_using_text_regno);
1891 }
1892 i370_using_text_regno = -1;
1893 i370_using_text_baseaddr.X_op = O_absent;
1894 }
1895 else
1896 {
1897 if (iregno != i370_using_other_regno)
1898 {
1899 as_bad ("droping register %d in section %s does not match using register %d",
1900 iregno, now_seg->name, i370_using_other_regno);
1901 }
1902 if (i370_other_section != now_seg)
1903 {
1904 as_bad ("droping register %d in section %s previously used in section %s",
1905 iregno, now_seg->name, i370_other_section->name);
1906 }
1907 i370_using_other_regno = -1;
1908 i370_using_other_baseaddr.X_op = O_absent;
1909 i370_other_section = undefined_section;
1910 }
1911 }
1912
1913 /* Make the first argument an address-relative expression
1914 * by subtracting the second argument.
1915 */
1916 static void
1917 i370_make_relative (expressionS *exx, expressionS *baseaddr)
1918 {
1919
1920 if (O_constant == baseaddr->X_op)
1921 {
1922 exx->X_op = O_symbol;
1923 exx->X_add_number -= baseaddr->X_add_number;
1924 }
1925 else if (O_symbol == baseaddr->X_op)
1926 {
1927 exx->X_op = O_subtract;
1928 exx->X_op_symbol = baseaddr->X_add_symbol;
1929 exx->X_add_number -= baseaddr->X_add_number;
1930 }
1931 else if (O_uminus == baseaddr->X_op)
1932 {
1933 exx->X_op = O_add;
1934 exx->X_op_symbol = baseaddr->X_add_symbol;
1935 exx->X_add_number += baseaddr->X_add_number;
1936 }
1937 else
1938 {
1939 as_bad ("Missing or bad .using directive");
1940 }
1941 }
1942 \f
1943 /* We need to keep a list of fixups. We can't simply generate them as
1944 we go, because that would require us to first create the frag, and
1945 that would screw up references to ``.''. */
1946
1947 struct i370_fixup
1948 {
1949 expressionS exp;
1950 int opindex;
1951 bfd_reloc_code_real_type reloc;
1952 };
1953
1954 #define MAX_INSN_FIXUPS (5)
1955
1956 /* This routine is called for each instruction to be assembled. */
1957
1958 void
1959 md_assemble (str)
1960 char *str;
1961 {
1962 char *s, *opcode_str;
1963 const struct i370_opcode *opcode;
1964 i370_insn_t insn;
1965 const unsigned char *opindex_ptr;
1966 int have_optional_index, have_optional_basereg, have_optional_reg;
1967 int skip_optional_index, skip_optional_basereg, skip_optional_reg;
1968 int use_text=0, use_other=0;
1969 int off_by_one;
1970 struct i370_fixup fixups[MAX_INSN_FIXUPS];
1971 int fc;
1972 char *f;
1973 int i;
1974 #ifdef OBJ_ELF
1975 bfd_reloc_code_real_type reloc;
1976 #endif
1977
1978 /* Get the opcode. */
1979 for (s = str; *s != '\0' && ! isspace (*s); s++)
1980 ;
1981 if (*s != '\0')
1982 *s++ = '\0';
1983 opcode_str = str;
1984
1985 /* Look up the opcode in the hash table. */
1986 opcode = (const struct i370_opcode *) hash_find (i370_hash, str);
1987 if (opcode == (const struct i370_opcode *) NULL)
1988 {
1989 const struct i370_macro *macro;
1990
1991 assert (i370_macro_hash);
1992 macro = (const struct i370_macro *) hash_find (i370_macro_hash, str);
1993 if (macro == (const struct i370_macro *) NULL)
1994 as_bad ("Unrecognized opcode: `%s'", str);
1995 else
1996 i370_macro (s, macro);
1997
1998 return;
1999 }
2000
2001 insn = opcode->opcode;
2002
2003 str = s;
2004 while (isspace (*str))
2005 ++str;
2006
2007 /* I370 operands are either expressions or address constants.
2008 Many operand types are optional. The optional operands
2009 are always surrounded by parens, and are used to denote the base
2010 register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
2011 the fully-formed "A R1, D2(X2,B2)". Note also the = sign,
2012 such as A R1,=A(i) where the address-of operator =A implies
2013 use of both a base register, and a missing index register.
2014
2015 So, before we start seriously parsing the operands, we check
2016 to see if we have an optional operand, and, if we do, we count
2017 the number of commas to see which operand should be omitted. */
2018
2019 have_optional_index = have_optional_basereg = have_optional_reg = 0;
2020 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2021 {
2022 const struct i370_operand *operand;
2023 operand = &i370_operands[*opindex_ptr];
2024 if ((operand->flags & I370_OPERAND_INDEX) != 0)
2025 have_optional_index = 1;
2026 if ((operand->flags & I370_OPERAND_BASE) != 0)
2027 have_optional_basereg = 1;
2028 if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
2029 have_optional_reg = 1;
2030 }
2031
2032 skip_optional_index = skip_optional_basereg = skip_optional_reg = 0;
2033 if (have_optional_index || have_optional_basereg)
2034 {
2035 unsigned int opcount, nwanted;
2036
2037 /* There is an optional operand. Count the number of
2038 commas and open-parens in the input line. */
2039 if (*str == '\0')
2040 opcount = 0;
2041 else
2042 {
2043 opcount = 1;
2044 s = str;
2045 while ((s = strpbrk (s, ",(=")) != (char *) NULL)
2046 {
2047 ++opcount;
2048 ++s;
2049 if (',' == *s) ++s; /* avoid counting things like (, */
2050 if ('=' == *s) { ++s; --opcount; }
2051 }
2052 }
2053
2054 /* If there are fewer operands in the line then are called
2055 for by the instruction, we want to skip the optional
2056 operand. */
2057 nwanted = strlen (opcode->operands);
2058 if (have_optional_index)
2059 {
2060 if (opcount < nwanted)
2061 skip_optional_index = 1;
2062 if (have_optional_basereg && ((opcount+1) < nwanted))
2063 skip_optional_basereg = 1;
2064 if (have_optional_reg && ((opcount+1) < nwanted))
2065 skip_optional_reg = 1;
2066 }
2067 else
2068 {
2069 if (have_optional_basereg && (opcount < nwanted))
2070 skip_optional_basereg = 1;
2071 if (have_optional_reg && (opcount < nwanted))
2072 skip_optional_reg = 1;
2073 }
2074 }
2075
2076 /* Perform some off-by-one hacks on the length field of certain instructions.
2077 * Its such a shame to have to do this, but the problem is that HLASM got
2078 * defined so that the lengths differ by one from the actual machine instructions.
2079 * this code should probably be moved to a special inster-operand routine.
2080 * Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
2081 * hack alert -- aren't *all* SS instructions affected ??
2082 */
2083 off_by_one = 0;
2084 if (0 == strcasecmp ("CLC", opcode->name)
2085 || 0 == strcasecmp ("ED", opcode->name)
2086 || 0 == strcasecmp ("EDMK", opcode->name)
2087 || 0 == strcasecmp ("MVC", opcode->name)
2088 || 0 == strcasecmp ("MVCIN", opcode->name)
2089 || 0 == strcasecmp ("MVN", opcode->name)
2090 || 0 == strcasecmp ("MVZ", opcode->name)
2091 || 0 == strcasecmp ("NC", opcode->name)
2092 || 0 == strcasecmp ("OC", opcode->name)
2093 || 0 == strcasecmp ("XC", opcode->name))
2094 off_by_one = 1;
2095
2096 /* Gather the operands. */
2097 fc = 0;
2098 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2099 {
2100 const struct i370_operand *operand;
2101 const char *errmsg;
2102 char *hold;
2103 expressionS ex;
2104
2105 operand = &i370_operands[*opindex_ptr];
2106 errmsg = NULL;
2107
2108 /* If this is an index operand, and we are skipping it,
2109 just insert a zero. */
2110 if (skip_optional_index &&
2111 ((operand->flags & I370_OPERAND_INDEX) != 0))
2112 {
2113 insn = i370_insert_operand (insn, operand, 0);
2114 continue;
2115 }
2116
2117 /* If this is the base operand, and we are skipping it,
2118 just insert the current using basreg. */
2119 if (skip_optional_basereg &&
2120 ((operand->flags & I370_OPERAND_BASE) != 0))
2121 {
2122 int basereg = -1;
2123 if (use_text)
2124 {
2125 if (0 == strncmp (now_seg->name, ".text", 5)
2126 || 0 > i370_using_other_regno)
2127 {
2128 basereg = i370_using_text_regno;
2129 }
2130 else
2131 {
2132 basereg = i370_using_other_regno;
2133 }
2134 }
2135 else if (use_other)
2136 {
2137 if (0 > i370_using_other_regno)
2138 {
2139 basereg = i370_using_text_regno;
2140 }
2141 else
2142 {
2143 basereg = i370_using_other_regno;
2144 }
2145 }
2146 if (0 > basereg)
2147 {
2148 as_bad ("not using any base register");
2149 }
2150 insn = i370_insert_operand (insn, operand, basereg);
2151 continue;
2152 }
2153
2154 /* If this is an optional operand, and we are skipping it,
2155 Use zero (since a non-zero value would denote a register) */
2156 if (skip_optional_reg
2157 && ((operand->flags & I370_OPERAND_OPTIONAL) != 0))
2158 {
2159 insn = i370_insert_operand (insn, operand, 0);
2160 continue;
2161 }
2162
2163 /* Gather the operand. */
2164 hold = input_line_pointer;
2165 input_line_pointer = str;
2166
2167 /* register names are only allowed where there are registers ... */
2168 if ((operand->flags & I370_OPERAND_GPR) != 0)
2169 {
2170 /* quickie hack to get past things like (,r13) */
2171 if (skip_optional_index && (',' == *input_line_pointer))
2172 {
2173 *input_line_pointer = ' ';
2174 input_line_pointer ++;
2175 }
2176 if (! register_name (&ex))
2177 {
2178 as_bad ("expecting a register for operand %d",
2179 opindex_ptr - opcode->operands + 1);
2180 }
2181 }
2182
2183 /* check for a address constant expression */
2184 /* We will put PSW-relative addresses in the text section,
2185 * and adress literals in the .data (or other) section. */
2186 else if (i370_addr_cons (&ex))
2187 use_other=1;
2188 else if (i370_addr_offset (&ex))
2189 use_text=1;
2190 else expression (&ex);
2191
2192 str = input_line_pointer;
2193 input_line_pointer = hold;
2194
2195 /* perform some off-by-one hacks on the length field of certain instructions.
2196 * Its such a shame to have to do this, but the problem is that HLASM got
2197 * defined so that the programmer specifies a length that is one greater
2198 * than what the machine instruction wants.
2199 * Sigh.
2200 */
2201 if (off_by_one && (0 == strcasecmp ("SS L", operand->name)))
2202 {
2203 ex.X_add_number --;
2204 }
2205
2206 if (ex.X_op == O_illegal)
2207 as_bad ("illegal operand");
2208 else if (ex.X_op == O_absent)
2209 as_bad ("missing operand");
2210 else if (ex.X_op == O_register)
2211 {
2212 insn = i370_insert_operand (insn, operand, ex.X_add_number);
2213 }
2214 else if (ex.X_op == O_constant)
2215 {
2216 #ifdef OBJ_ELF
2217 /* Allow @HA, @L, @H on constants.
2218 * Well actually, no we don't; there really don't make sense
2219 * (at least not to me) for the i370. However, this code is
2220 * left here for any dubious future expansion reasons ... */
2221 char *orig_str = str;
2222
2223 if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2224 switch (reloc)
2225 {
2226 default:
2227 str = orig_str;
2228 break;
2229
2230 case BFD_RELOC_LO16:
2231 /* X_unsigned is the default, so if the user has done
2232 something which cleared it, we always produce a
2233 signed value. */
2234 ex.X_add_number = (((ex.X_add_number & 0xffff)
2235 ^ 0x8000)
2236 - 0x8000);
2237 break;
2238
2239 case BFD_RELOC_HI16:
2240 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
2241 break;
2242
2243 case BFD_RELOC_HI16_S:
2244 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
2245 + ((ex.X_add_number >> 15) & 1));
2246 break;
2247 }
2248 #endif
2249 insn = i370_insert_operand (insn, operand, ex.X_add_number);
2250 }
2251 #ifdef OBJ_ELF
2252 else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2253 {
2254 as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
2255
2256 /* We need to generate a fixup for this expression. */
2257 if (fc >= MAX_INSN_FIXUPS)
2258 as_fatal ("too many fixups");
2259 fixups[fc].exp = ex;
2260 fixups[fc].opindex = 0;
2261 fixups[fc].reloc = reloc;
2262 ++fc;
2263 }
2264 #endif /* OBJ_ELF */
2265
2266 else
2267 {
2268 /* We need to generate a fixup for this expression. */
2269 /* Typically, the expression will just be a symbol ...
2270 * printf ("insn %s needs fixup for %s \n",
2271 * opcode->name, ex.X_add_symbol->bsym->name);
2272 */
2273
2274 if (fc >= MAX_INSN_FIXUPS)
2275 as_fatal ("too many fixups");
2276 fixups[fc].exp = ex;
2277 fixups[fc].opindex = *opindex_ptr;
2278 fixups[fc].reloc = BFD_RELOC_UNUSED;
2279 ++fc;
2280 }
2281
2282 /* skip over delimiter (close paren, or comma) */
2283 if ((')' == *str) && (',' == *(str+1)))
2284 ++str;
2285 if (*str != '\0')
2286 ++str;
2287 }
2288
2289 while (isspace (*str))
2290 ++str;
2291
2292 if (*str != '\0')
2293 as_bad ("junk at end of line: `%s'", str);
2294
2295 /* Write out the instruction. */
2296 f = frag_more (opcode->len);
2297 if (4 >= opcode->len)
2298 {
2299 md_number_to_chars (f, insn.i[0], opcode->len);
2300 }
2301 else
2302 {
2303 md_number_to_chars (f, insn.i[0], 4);
2304 if (6 == opcode->len)
2305 {
2306 md_number_to_chars ((f+4), ((insn.i[1])>>16), 2);
2307 }
2308 else
2309 {
2310 /* not used --- don't have any 8 byte instructions */
2311 as_bad ("Internal Error: bad instruction length");
2312 md_number_to_chars ((f+4), insn.i[1], opcode->len -4);
2313 }
2314 }
2315
2316 /* Create any fixups. At this point we do not use a
2317 bfd_reloc_code_real_type, but instead just use the
2318 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2319 handle fixups for any operand type, although that is admittedly
2320 not a very exciting feature. We pick a BFD reloc type in
2321 md_apply_fix. */
2322 for (i = 0; i < fc; i++)
2323 {
2324 const struct i370_operand *operand;
2325
2326 operand = &i370_operands[fixups[i].opindex];
2327 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2328 {
2329 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2330 int size;
2331 fixS *fixP;
2332
2333 if (!reloc_howto)
2334 abort ();
2335
2336 size = bfd_get_reloc_size (reloc_howto);
2337
2338 if (size < 1 || size > 4)
2339 abort();
2340
2341 printf (" gwana doo fixup %d \n", i);
2342 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
2343 &fixups[i].exp, reloc_howto->pc_relative,
2344 fixups[i].reloc);
2345
2346 /* Turn off complaints that the addend is too large for things like
2347 foo+100000@ha. */
2348 switch (fixups[i].reloc)
2349 {
2350 case BFD_RELOC_16_GOTOFF:
2351 case BFD_RELOC_LO16:
2352 case BFD_RELOC_HI16:
2353 case BFD_RELOC_HI16_S:
2354 fixP->fx_no_overflow = 1;
2355 break;
2356 default:
2357 break;
2358 }
2359 }
2360 else
2361 {
2362 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len,
2363 &fixups[i].exp,
2364 (operand->flags & I370_OPERAND_RELATIVE) != 0,
2365 ((bfd_reloc_code_real_type)
2366 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2367 }
2368 }
2369 }
2370
2371 /* Handle a macro. Gather all the operands, transform them as
2372 described by the macro, and call md_assemble recursively. All the
2373 operands are separated by commas; we don't accept parentheses
2374 around operands here. */
2375
2376 static void
2377 i370_macro (str, macro)
2378 char *str;
2379 const struct i370_macro *macro;
2380 {
2381 char *operands[10];
2382 unsigned int count;
2383 char *s;
2384 unsigned int len;
2385 const char *format;
2386 int arg;
2387 char *send;
2388 char *complete;
2389
2390 /* Gather the users operands into the operands array. */
2391 count = 0;
2392 s = str;
2393 while (1)
2394 {
2395 if (count >= sizeof operands / sizeof operands[0])
2396 break;
2397 operands[count++] = s;
2398 s = strchr (s, ',');
2399 if (s == (char *) NULL)
2400 break;
2401 *s++ = '\0';
2402 }
2403
2404 if (count != macro->operands)
2405 {
2406 as_bad ("wrong number of operands");
2407 return;
2408 }
2409
2410 /* Work out how large the string must be (the size is unbounded
2411 because it includes user input). */
2412 len = 0;
2413 format = macro->format;
2414 while (*format != '\0')
2415 {
2416 if (*format != '%')
2417 {
2418 ++len;
2419 ++format;
2420 }
2421 else
2422 {
2423 arg = strtol (format + 1, &send, 10);
2424 know (send != format && arg >= 0 && arg < count);
2425 len += strlen (operands[arg]);
2426 format = send;
2427 }
2428 }
2429
2430 /* Put the string together. */
2431 complete = s = (char *) alloca (len + 1);
2432 format = macro->format;
2433 while (*format != '\0')
2434 {
2435 if (*format != '%')
2436 *s++ = *format++;
2437 else
2438 {
2439 arg = strtol (format + 1, &send, 10);
2440 strcpy (s, operands[arg]);
2441 s += strlen (s);
2442 format = send;
2443 }
2444 }
2445 *s = '\0';
2446
2447 /* Assemble the constructed instruction. */
2448 md_assemble (complete);
2449 }
2450 \f
2451 #ifdef OBJ_ELF
2452 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2453
2454 int
2455 i370_section_letter (letter, ptr_msg)
2456 int letter;
2457 char **ptr_msg;
2458 {
2459 if (letter == 'e')
2460 return SHF_EXCLUDE;
2461
2462 *ptr_msg = "Bad .section directive: want a,w,x,e in string";
2463 return 0;
2464 }
2465
2466 int
2467 i370_section_word (str, len)
2468 char *str;
2469 size_t len;
2470 {
2471 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2472 return SHF_EXCLUDE;
2473
2474 return -1;
2475 }
2476
2477 int
2478 i370_section_type (str, len)
2479 char *str;
2480 size_t len;
2481 {
2482 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2483 return SHT_ORDERED;
2484
2485 return -1;
2486 }
2487
2488 int
2489 i370_section_flags (flags, attr, type)
2490 int flags;
2491 int attr;
2492 int type;
2493 {
2494 if (type == SHT_ORDERED)
2495 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2496
2497 if (attr & SHF_EXCLUDE)
2498 flags |= SEC_EXCLUDE;
2499
2500 return flags;
2501 }
2502 #endif /* OBJ_ELF */
2503
2504 \f
2505 /* Pseudo-op handling. */
2506
2507 /* The .byte pseudo-op. This is similar to the normal .byte
2508 pseudo-op, but it can also take a single ASCII string. */
2509
2510 static void
2511 i370_byte (ignore)
2512 int ignore;
2513 {
2514 if (*input_line_pointer != '\"')
2515 {
2516 cons (1);
2517 return;
2518 }
2519
2520 /* Gather characters. A real double quote is doubled. Unusual
2521 characters are not permitted. */
2522 ++input_line_pointer;
2523 while (1)
2524 {
2525 char c;
2526
2527 c = *input_line_pointer++;
2528
2529 if (c == '\"')
2530 {
2531 if (*input_line_pointer != '\"')
2532 break;
2533 ++input_line_pointer;
2534 }
2535
2536 FRAG_APPEND_1_CHAR (c);
2537 }
2538
2539 demand_empty_rest_of_line ();
2540 }
2541 \f
2542 /* The .tc pseudo-op. This is used when generating XCOFF and ELF.
2543 This takes two or more arguments.
2544
2545 When generating XCOFF output, the first argument is the name to
2546 give to this location in the toc; this will be a symbol with class
2547 TC. The rest of the arguments are 4 byte values to actually put at
2548 this location in the TOC; often there is just one more argument, a
2549 relocateable symbol reference.
2550
2551 When not generating XCOFF output, the arguments are the same, but
2552 the first argument is simply ignored. */
2553
2554 static void
2555 i370_tc (ignore)
2556 int ignore;
2557 {
2558
2559 /* Skip the TOC symbol name. */
2560 while (is_part_of_name (*input_line_pointer)
2561 || *input_line_pointer == '['
2562 || *input_line_pointer == ']'
2563 || *input_line_pointer == '{'
2564 || *input_line_pointer == '}')
2565 ++input_line_pointer;
2566
2567 /* Align to a four byte boundary. */
2568 frag_align (2, 0, 0);
2569 record_alignment (now_seg, 2);
2570
2571 if (*input_line_pointer != ',')
2572 demand_empty_rest_of_line ();
2573 else
2574 {
2575 ++input_line_pointer;
2576 cons (4);
2577 }
2578 }
2579 \f
2580 /* Turn a string in input_line_pointer into a floating point constant
2581 of type TYPE, and store the appropriate bytes in *LITP. The number
2582 of LITTLENUMS emitted is stored in *SIZEP. An error message is
2583 returned, or NULL on OK. */
2584
2585 char *
2586 md_atof (type, litp, sizep)
2587 int type;
2588 char *litp;
2589 int *sizep;
2590 {
2591 int prec;
2592 LITTLENUM_TYPE words[4];
2593 char *t;
2594 int i;
2595
2596 switch (type)
2597 {
2598 case 'f':
2599 case 'E':
2600 type = 'f';
2601 prec = 2;
2602 break;
2603
2604 case 'd':
2605 case 'D':
2606 type = 'd';
2607 prec = 4;
2608 break;
2609
2610 default:
2611 *sizep = 0;
2612 return "bad call to md_atof";
2613 }
2614
2615 /* 360/370/390 have two float formats: an old, funky 360 single-precision
2616 * format, and the ieee format. Support only the ieee format. */
2617 t = atof_ieee (input_line_pointer, type, words);
2618 if (t)
2619 input_line_pointer = t;
2620
2621 *sizep = prec * 2;
2622
2623 for (i = 0; i < prec; i++)
2624 {
2625 md_number_to_chars (litp, (valueT) words[i], 2);
2626 litp += 2;
2627 }
2628
2629 return NULL;
2630 }
2631
2632 /* Write a value out to the object file, using the appropriate
2633 endianness. */
2634
2635 void
2636 md_number_to_chars (buf, val, n)
2637 char *buf;
2638 valueT val;
2639 int n;
2640 {
2641 number_to_chars_bigendian (buf, val, n);
2642 }
2643
2644 /* Align a section (I don't know why this is machine dependent). */
2645
2646 valueT
2647 md_section_align (seg, addr)
2648 asection *seg;
2649 valueT addr;
2650 {
2651 int align = bfd_get_section_alignment (stdoutput, seg);
2652
2653 return (addr + (1 << align) - 1) & (-1 << align);
2654 }
2655
2656 /* We don't have any form of relaxing. */
2657
2658 int
2659 md_estimate_size_before_relax (fragp, seg)
2660 fragS *fragp;
2661 asection *seg;
2662 {
2663 abort ();
2664 return 0;
2665 }
2666
2667 /* Convert a machine dependent frag. We never generate these. */
2668
2669 void
2670 md_convert_frag (abfd, sec, fragp)
2671 bfd *abfd;
2672 asection *sec;
2673 fragS *fragp;
2674 {
2675 abort ();
2676 }
2677
2678 /* We have no need to default values of symbols. */
2679
2680 /*ARGSUSED*/
2681 symbolS *
2682 md_undefined_symbol (name)
2683 char *name;
2684 {
2685 return 0;
2686 }
2687 \f
2688 /* Functions concerning relocs. */
2689
2690 /* The location from which a PC relative jump should be calculated,
2691 given a PC relative reloc. */
2692
2693 long
2694 md_pcrel_from_section (fixp, sec)
2695 fixS *fixp;
2696 segT sec;
2697 {
2698 return fixp->fx_frag->fr_address + fixp->fx_where;
2699 }
2700
2701 /* Apply a fixup to the object code. This is called for all the
2702 fixups we generated by the call to fix_new_exp, above. In the call
2703 above we used a reloc code which was the largest legal reloc code
2704 plus the operand index. Here we undo that to recover the operand
2705 index. At this point all symbol values should be fully resolved,
2706 and we attempt to completely resolve the reloc. If we can not do
2707 that, we determine the correct reloc code and put it back in the
2708 fixup.
2709
2710 See gas/cgen.c for more sample code and explanations of what's
2711 going on here ...
2712 */
2713
2714 int
2715 md_apply_fix3 (fixp, valuep, seg)
2716 fixS *fixp;
2717 valueT *valuep;
2718 segT seg;
2719 {
2720 valueT value;
2721
2722 value = *valuep;
2723 if (fixp->fx_addsy != NULL)
2724 {
2725 /* Notes:
2726 Branches to labels will come in here with fixp->fx_pcrel set to 1
2727 and fixp->fx_subsy not null, and holding the value of the base
2728 (i.e. the value of the .using). These we want to ignore.
2729
2730 'Strong' and 'weak' symbols will come in here with
2731 fixp->fx_pcrel==0, fixp->fx_addsy defined, and
2732 *valuep holding the value of the symbol.
2733
2734 'Strong' symbols will have S_GET_VALUE(fx_addsy) equal to zero,
2735 whereas 'weak' symbols will have S_GET_VALUE(fx_addsy) set to the
2736 symbol value (usually).
2737
2738 We want to subtract S_GET_VALUE(fx_addsy) if it set, and
2739 for all practical purposes, do a fixup with value zero. This
2740 is because the linker/loader, at a later time, will do this
2741 fixup with the correct value. If we fixup now with a value,
2742 it will get double-fixed, leading to garbage.
2743
2744 Note that subsy will also be set for strong/weak symbols
2745 when the user program was compiled with -g. In that case,
2746 subsy will hold the base address (i.e. the .using address).
2747 */
2748
2749 if (fixp->fx_addsy->sy_used_in_reloc
2750 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
2751 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
2752 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
2753 value -= S_GET_VALUE (fixp->fx_addsy);
2754
2755 #ifdef DEBUG
2756 printf ("\nmd_apply_fix3: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
2757 S_GET_NAME (fixp->fx_addsy),
2758 fixp->fx_frag->fr_address + fixp->fx_where,
2759 fixp->fx_file, fixp->fx_line,
2760 S_GET_VALUE (fixp->fx_addsy), value);
2761 #endif
2762 }
2763 else
2764 {
2765 fixp->fx_done = 1;
2766 return 1;
2767 }
2768
2769 /* Apply fixups to operands. Note that there should be no relocations
2770 for any operands, since no instruction ever takes an operand
2771 that requires reloc. */
2772 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2773 {
2774 int opindex;
2775 const struct i370_operand *operand;
2776 char *where;
2777 i370_insn_t insn;
2778
2779 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2780
2781 operand = &i370_operands[opindex];
2782
2783 #ifdef DEBUG
2784 printf ("\nmd_apply_fix3: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
2785 operand->name,
2786 fixp->fx_frag->fr_address + fixp->fx_where,
2787 fixp->fx_file, fixp->fx_line,
2788 value);
2789 #endif
2790 /* Fetch the instruction, insert the fully resolved operand
2791 value, and stuff the instruction back again.
2792 fisxp->fx_size is the length of the instruction. */
2793 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2794 insn.i[0] = bfd_getb32 ((unsigned char *) where);
2795 if (6 <= fixp->fx_size)
2796 { /* deal with 48-bit insn's */
2797 insn.i[1] = bfd_getb32 (((unsigned char *) where)+4);
2798 }
2799 insn = i370_insert_operand (insn, operand, (offsetT) value);
2800 bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where);
2801 if (6 <= fixp->fx_size)
2802 { /* deal with 48-bit insn's */
2803 bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4));
2804 }
2805
2806 /* we are done, right? right !! */
2807 fixp->fx_done = 1;
2808 if (fixp->fx_done)
2809 {
2810 /* Nothing else to do here. */
2811 return 1;
2812 }
2813
2814 /* Determine a BFD reloc value based on the operand information.
2815 We are only prepared to turn a few of the operands into
2816 relocs. In fact, we support *zero* operand relocations ...
2817 Why? Because we are not expecting the compiler to generate
2818 any operands that need relocation. Due to the 12-bit naturew of
2819 i370 addressing, this would be unusual. */
2820 #if 0
2821 if ((operand->flags & I370_OPERAND_RELATIVE) != 0
2822 && operand->bits == 12
2823 && operand->shift == 0)
2824 fixp->fx_r_type = BFD_RELOC_I370_D12;
2825 else
2826 #endif
2827 {
2828 char *sfile;
2829 unsigned int sline;
2830
2831 /* Use expr_symbol_where to see if this is an expression
2832 symbol. */
2833 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
2834 as_bad_where (fixp->fx_file, fixp->fx_line,
2835 "unresolved expression that must be resolved");
2836 else
2837 as_bad_where (fixp->fx_file, fixp->fx_line,
2838 "unsupported relocation type");
2839 fixp->fx_done = 1;
2840 return 1;
2841 }
2842 }
2843 else
2844 {
2845 /* We branch to here if the fixup is not to a symbol that
2846 * appears in an instruction operand, but is rather some
2847 * declared storage.
2848 */
2849 #ifdef OBJ_ELF
2850 i370_elf_validate_fix (fixp, seg);
2851 #endif
2852 #ifdef DEBUG
2853 printf ("md_apply_fix3: reloc case %d in segment %s %s:%d\n",
2854 fixp->fx_r_type, segment_name (seg), fixp->fx_file, fixp->fx_line);
2855 printf ("\tcurrent fixup value is 0x%x \n", value);
2856 #endif
2857 switch (fixp->fx_r_type)
2858 {
2859 case BFD_RELOC_32:
2860 case BFD_RELOC_CTOR:
2861 if (fixp->fx_pcrel)
2862 fixp->fx_r_type = BFD_RELOC_32_PCREL;
2863 /* fall through */
2864
2865 case BFD_RELOC_RVA:
2866 case BFD_RELOC_32_PCREL:
2867 case BFD_RELOC_32_BASEREL:
2868 #ifdef DEBUG
2869 printf ("\t32 bit relocation at 0x%x\n",
2870 fixp->fx_frag->fr_address + fixp->fx_where);
2871 #endif
2872 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2873 value, 4);
2874 break;
2875
2876 case BFD_RELOC_LO16:
2877 case BFD_RELOC_16:
2878 if (fixp->fx_pcrel)
2879 as_bad_where (fixp->fx_file, fixp->fx_line,
2880 "cannot emit PC relative %s relocation%s%s",
2881 bfd_get_reloc_code_name (fixp->fx_r_type),
2882 fixp->fx_addsy != NULL ? " against " : "",
2883 (fixp->fx_addsy != NULL
2884 ? S_GET_NAME (fixp->fx_addsy)
2885 : ""));
2886
2887 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2888 value, 2);
2889 break;
2890
2891 /* This case happens when you write, for example,
2892 lis %r3,(L1-L2)@ha
2893 where L1 and L2 are defined later. */
2894 case BFD_RELOC_HI16:
2895 if (fixp->fx_pcrel)
2896 abort ();
2897 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2898 value >> 16, 2);
2899 break;
2900 case BFD_RELOC_HI16_S:
2901 if (fixp->fx_pcrel)
2902 abort ();
2903 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2904 (value + 0x8000) >> 16, 2);
2905 break;
2906
2907 case BFD_RELOC_8:
2908 if (fixp->fx_pcrel)
2909 abort ();
2910
2911 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2912 value, 1);
2913 break;
2914
2915 default:
2916 fprintf(stderr,
2917 "Gas failure, reloc value %d\n", fixp->fx_r_type);
2918 fflush(stderr);
2919 abort ();
2920 }
2921 }
2922
2923 fixp->fx_addnumber = value;
2924
2925 return 1;
2926 }
2927
2928 /* Generate a reloc for a fixup. */
2929
2930 arelent *
2931 tc_gen_reloc (seg, fixp)
2932 asection *seg;
2933 fixS *fixp;
2934 {
2935 arelent *reloc;
2936
2937 reloc = (arelent *) xmalloc (sizeof (arelent));
2938
2939 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2940 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2941 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2942 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2943 if (reloc->howto == (reloc_howto_type *) NULL)
2944 {
2945 as_bad_where (fixp->fx_file, fixp->fx_line,
2946 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
2947 return NULL;
2948 }
2949 reloc->addend = fixp->fx_addnumber;
2950
2951 #ifdef DEBUG
2952 printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
2953 fixp->fx_addsy->bsym->name,
2954 fixp->fx_file, fixp->fx_line,
2955 reloc->address, reloc->addend);
2956 #endif
2957
2958 return reloc;
2959 }