1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* careful, this file includes data *declarations* */
27 #include "opcode/sparc.h"
29 static void sparc_ip PARAMS ((char *));
32 static enum sparc_architecture current_architecture = v9;
34 static enum sparc_architecture current_architecture = v6;
36 static int architecture_requested;
37 static int warn_on_bump;
39 extern int target_big_endian;
41 /* handle of the OPCODE hash table */
42 static struct hash_control *op_hash;
44 static void s_data1 PARAMS ((void));
45 static void s_seg PARAMS ((int));
46 static void s_proc PARAMS ((int));
47 static void s_reserve PARAMS ((int));
48 static void s_common PARAMS ((int));
50 const pseudo_typeS md_pseudo_table[] =
52 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
53 {"common", s_common, 0},
54 {"global", s_globl, 0},
56 {"optim", s_ignore, 0},
58 {"reserve", s_reserve, 0},
69 /* these are specific to sparc/svr4 */
70 {"pushsection", obj_elf_section, 0},
71 {"popsection", obj_elf_previous, 0},
78 const int md_reloc_size = 12; /* Size of relocation record */
80 /* This array holds the chars that always start a comment. If the
81 pre-processor is disabled, these aren't very useful */
82 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
84 /* This array holds the chars that only start a comment at the beginning of
85 a line. If the line seems to have the form '# 123 filename'
86 .line and .file directives will appear in the pre-processed output */
87 /* Note that input_file.c hand checks for '#' at the beginning of the
88 first line of the input file. This is because the compiler outputs
89 #NO_APP at the beginning of its output. */
90 /* Also note that comments started like this one will always
91 work if '/' isn't otherwise defined. */
92 const char line_comment_chars[] = "#";
94 const char line_separator_chars[] = "";
96 /* Chars that can be used to separate mant from exp in floating point nums */
97 const char EXP_CHARS[] = "eE";
99 /* Chars that mean this number is a floating point constant */
102 const char FLT_CHARS[] = "rRsSfFdDxXpP";
104 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
105 changed in read.c. Ideally it shouldn't have to know about it at all,
106 but nothing is ideal around here. */
108 static unsigned char octal[256];
109 #define isoctal(c) octal[(unsigned char) (c)]
110 static unsigned char toHex[256];
115 unsigned long opcode;
116 struct nlist *nlistp;
119 bfd_reloc_code_real_type reloc;
122 struct sparc_it the_insn, set_insn;
125 in_signed_range (val, max)
126 bfd_signed_vma val, max;
138 static void print_insn PARAMS ((struct sparc_it *insn));
140 static int getExpression PARAMS ((char *str));
142 static char *expr_end;
143 static int special_case;
146 * Instructions that require wierd handling because they're longer than
149 #define SPECIAL_CASE_SET 1
150 #define SPECIAL_CASE_FDIV 2
153 * sort of like s_lcomm
157 static int max_alignment = 15;
172 name = input_line_pointer;
173 c = get_symbol_end ();
174 p = input_line_pointer;
178 if (*input_line_pointer != ',')
180 as_bad ("Expected comma after name");
181 ignore_rest_of_line ();
185 ++input_line_pointer;
187 if ((size = get_absolute_expression ()) < 0)
189 as_bad ("BSS length (%d.) <0! Ignored.", size);
190 ignore_rest_of_line ();
195 symbolP = symbol_find_or_make (name);
198 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
199 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
201 as_bad ("bad .reserve segment -- expected BSS segment");
205 if (input_line_pointer[2] == '.')
206 input_line_pointer += 7;
208 input_line_pointer += 6;
211 if (*input_line_pointer == ',')
213 ++input_line_pointer;
216 if (*input_line_pointer == '\n')
218 as_bad ("Missing alignment");
222 align = get_absolute_expression ();
224 if (align > max_alignment)
226 align = max_alignment;
227 as_warn ("Alignment too large: %d. assumed.", align);
233 as_warn ("Alignment negative. 0 assumed.");
236 record_alignment (bss_section, align);
238 /* convert to a power of 2 alignment */
239 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
243 as_bad ("Alignment not a power of 2");
244 ignore_rest_of_line ();
246 } /* not a power of two */
249 } /* if has optional alignment */
253 if (!S_IS_DEFINED (symbolP)
255 && S_GET_OTHER (symbolP) == 0
256 && S_GET_DESC (symbolP) == 0
263 segT current_seg = now_seg;
264 subsegT current_subseg = now_subseg;
266 subseg_set (bss_section, 1); /* switch to bss */
269 frag_align (align, 0); /* do alignment */
271 /* detach from old frag */
272 if (S_GET_SEGMENT(symbolP) == bss_section)
273 symbolP->sy_frag->fr_symbol = NULL;
275 symbolP->sy_frag = frag_now;
276 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
280 S_SET_SEGMENT (symbolP, bss_section);
282 subseg_set (current_seg, current_subseg);
287 as_warn("Ignoring attempt to re-define symbol %s",
288 S_GET_NAME (symbolP));
289 } /* if not redefining */
291 demand_empty_rest_of_line ();
304 name = input_line_pointer;
305 c = get_symbol_end ();
306 /* just after name is now '\0' */
307 p = input_line_pointer;
310 if (*input_line_pointer != ',')
312 as_bad ("Expected comma after symbol-name");
313 ignore_rest_of_line ();
316 input_line_pointer++; /* skip ',' */
317 if ((temp = get_absolute_expression ()) < 0)
319 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
320 ignore_rest_of_line ();
325 symbolP = symbol_find_or_make (name);
327 if (S_IS_DEFINED (symbolP))
329 as_bad ("Ignoring attempt to re-define symbol");
330 ignore_rest_of_line ();
333 if (S_GET_VALUE (symbolP) != 0)
335 if (S_GET_VALUE (symbolP) != size)
337 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
338 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
344 S_SET_VALUE (symbolP, (valueT) size);
345 S_SET_EXTERNAL (symbolP);
348 know (symbolP->sy_frag == &zero_address_frag);
349 if (*input_line_pointer != ',')
351 as_bad ("Expected comma after common length");
352 ignore_rest_of_line ();
355 input_line_pointer++;
357 if (*input_line_pointer != '"')
359 temp = get_absolute_expression ();
361 if (temp > max_alignment)
363 temp = max_alignment;
364 as_warn ("Common alignment too large: %d. assumed", temp);
370 as_warn ("Common alignment negative; 0 assumed");
382 old_subsec = now_subseg;
384 record_alignment (bss_section, align);
385 subseg_set (bss_section, 0);
387 frag_align (align, 0);
388 if (S_GET_SEGMENT (symbolP) == bss_section)
389 symbolP->sy_frag->fr_symbol = 0;
390 symbolP->sy_frag = frag_now;
391 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
394 S_SET_SEGMENT (symbolP, bss_section);
395 S_CLEAR_EXTERNAL (symbolP);
396 subseg_set (old_sec, old_subsec);
402 S_SET_VALUE (symbolP, (valueT) size);
404 S_SET_ALIGN (symbolP, temp);
406 S_SET_EXTERNAL (symbolP);
407 /* should be common, but this is how gas does it for now */
408 S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
413 input_line_pointer++;
414 /* @@ Some use the dot, some don't. Can we get some consistency?? */
415 if (*input_line_pointer == '.')
416 input_line_pointer++;
417 /* @@ Some say data, some say bss. */
418 if (strncmp (input_line_pointer, "bss\"", 4)
419 && strncmp (input_line_pointer, "data\"", 5))
421 while (*--input_line_pointer != '"')
423 input_line_pointer--;
424 goto bad_common_segment;
426 while (*input_line_pointer++ != '"')
428 goto allocate_common;
430 demand_empty_rest_of_line ();
435 p = input_line_pointer;
436 while (*p && *p != '\n')
440 as_bad ("bad .common segment %s", input_line_pointer + 1);
442 input_line_pointer = p;
443 ignore_rest_of_line ();
453 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
455 input_line_pointer += 6;
459 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
461 input_line_pointer += 6;
465 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
467 input_line_pointer += 7;
471 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
473 input_line_pointer += 5;
474 /* We only support 2 segments -- text and data -- for now, so
475 things in the "bss segment" will have to go into data for now.
476 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
477 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
480 as_bad ("Unknown segment type");
481 demand_empty_rest_of_line ();
487 subseg_set (data_section, 1);
488 demand_empty_rest_of_line ();
495 while (!is_end_of_line[(unsigned char) *input_line_pointer])
497 ++input_line_pointer;
499 ++input_line_pointer;
504 struct priv_reg_entry
510 struct priv_reg_entry priv_reg_table[] =
529 {"", -1}, /* end marker */
539 #define MEMBAR_MASKS_SIZE 7
541 static const struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
544 {"MemIssue", 8, 0x20},
545 {"Lookaside", 9, 0x10},
546 {"StoreStore", 10, 0x08},
547 {"LoadStore", 9, 0x04},
548 {"StoreLoad", 9, 0x02},
549 {"LoadLoad", 8, 0x01},
554 struct priv_reg_entry *p, *q;
556 return strcmp (q->name, p->name);
561 /* This function is called once, at assembler startup time. It should
562 set up all the tables, etc. that the MD part of the assembler will need. */
566 register const char *retval = NULL;
568 register unsigned int i = 0;
570 op_hash = hash_new ();
572 while (i < NUMOPCODES)
574 const char *name = sparc_opcodes[i].name;
575 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
578 fprintf (stderr, "internal error: can't hash `%s': %s\n",
579 sparc_opcodes[i].name, retval);
584 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
586 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
587 sparc_opcodes[i].name, sparc_opcodes[i].args);
592 while (i < NUMOPCODES
593 && !strcmp (sparc_opcodes[i].name, name));
597 as_fatal ("Broken assembler. No assembly attempted.");
599 for (i = '0'; i < '8'; ++i)
601 for (i = '0'; i <= '9'; ++i)
603 for (i = 'a'; i <= 'f'; ++i)
604 toHex[i] = i + 10 - 'a';
605 for (i = 'A'; i <= 'F'; ++i)
606 toHex[i] = i + 10 - 'A';
609 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
610 sizeof (priv_reg_table[0]), cmp_reg_entry);
613 target_big_endian = 1;
626 /* See if "set" operand is absolute and small; skip sethi if so. */
627 if (special_case == SPECIAL_CASE_SET
628 && the_insn.exp.X_op == O_constant)
630 if (the_insn.exp.X_add_number >= -(1 << 12)
631 && the_insn.exp.X_add_number < (1 << 12))
633 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
634 | (the_insn.opcode & 0x3E000000) /* dest reg */
635 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
636 special_case = 0; /* No longer special */
637 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
642 /* put out the opcode */
643 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
645 /* put out the symbol-dependent stuff */
646 if (the_insn.reloc != BFD_RELOC_NONE)
648 fix_new_exp (frag_now, /* which frag */
649 (toP - frag_now->fr_literal), /* where */
656 switch (special_case)
658 case SPECIAL_CASE_SET:
660 assert (the_insn.reloc == BFD_RELOC_HI22);
661 /* See if "set" operand has no low-order bits; skip OR if so. */
662 if (the_insn.exp.X_op == O_constant
663 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
666 rsd = (the_insn.opcode >> 25) & 0x1f;
667 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
668 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
669 fix_new_exp (frag_now, /* which frag */
670 (toP - frag_now->fr_literal), /* where */
677 case SPECIAL_CASE_FDIV:
678 /* According to information leaked from Sun, the "fdiv" instructions
679 on early SPARC machines would produce incorrect results sometimes.
680 The workaround is to add an fmovs of the destination register to
681 itself just after the instruction. This was true on machines
682 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
684 assert (the_insn.reloc == BFD_RELOC_NONE);
686 rsd = (the_insn.opcode >> 25) & 0x1f;
687 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
688 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
695 as_fatal ("failed sanity check.");
699 /* Implement big shift right. */
705 if (sizeof (bfd_vma) <= 4 && amount >= 32)
706 as_fatal ("Support for 64-bit arithmetic not compiled in.");
707 return val >> amount;
714 char *error_message = "";
718 const struct sparc_opcode *insn;
720 unsigned long opcode;
721 unsigned int mask = 0;
724 long immediate_max = 0;
726 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
744 as_fatal ("Unknown opcode: `%s'", str);
746 insn = (struct sparc_opcode *) hash_find (op_hash, str);
749 as_bad ("Unknown opcode: `%s'", str);
759 opcode = insn->match;
760 memset (&the_insn, '\0', sizeof (the_insn));
761 the_insn.reloc = BFD_RELOC_NONE;
764 * Build the opcode, checking as we go to make
765 * sure that the operands match
767 for (args = insn->args;; ++args)
777 /* Parse a series of masks. */
783 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
784 if (!strncmp (s, membar_masks[i].name,
785 membar_masks[i].len))
787 if (i < MEMBAR_MASKS_SIZE)
789 kmask |= membar_masks[i].mask;
790 s += membar_masks[i].len;
794 error_message = ": invalid membar mask name";
807 hold = input_line_pointer;
808 input_line_pointer = s;
810 send = input_line_pointer;
811 input_line_pointer = hold;
813 kmask = exp.X_add_number;
814 if (exp.X_op != O_constant
818 error_message = ": invalid membar mask number";
825 opcode |= SIMM13 (kmask);
831 int prefetch_fcn = 0;
833 /* Parse a prefetch function. */
837 if (!strncmp (s, "n_reads", 7))
838 prefetch_fcn = 0, s += 7;
839 else if (!strncmp (s, "one_read", 8))
840 prefetch_fcn = 1, s += 8;
841 else if (!strncmp (s, "n_writes", 8))
842 prefetch_fcn = 2, s += 8;
843 else if (!strncmp (s, "one_write", 9))
844 prefetch_fcn = 3, s += 9;
845 else if (!strncmp (s, "page", 4))
846 prefetch_fcn = 4, s += 4;
849 error_message = ": invalid prefetch function name";
853 else if (isdigit (*s))
857 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
861 if (prefetch_fcn < 0 || prefetch_fcn > 31)
863 error_message = ": invalid prefetch function number";
869 error_message = ": unrecognizable prefetch function";
872 opcode |= RD (prefetch_fcn);
878 /* Parse a privileged register. */
881 struct priv_reg_entry *p = priv_reg_table;
882 unsigned int len = 9999999; /* init to make gcc happy */
885 while (p->name[0] > s[0])
887 while (p->name[0] == s[0])
889 len = strlen (p->name);
890 if (strncmp (p->name, s, len) == 0)
894 if (p->name[0] != s[0])
896 error_message = ": unrecognizable privileged register";
900 opcode |= (p->regnum << 14);
902 opcode |= (p->regnum << 25);
908 error_message = ": unrecognizable privileged register";
915 if (strncmp (s, "%asr", 4) == 0)
925 num = num * 10 + *s - '0';
929 if (num < 16 || 31 < num)
931 error_message = ": asr number must be between 15 and 31";
935 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
940 error_message = ": expecting %asrN";
942 } /* if %asr followed by a number. */
949 the_insn.reloc = BFD_RELOC_SPARC_11;
950 immediate_max = 0x03FF;
954 the_insn.reloc = BFD_RELOC_SPARC_10;
955 immediate_max = 0x01FF;
959 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
964 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
969 if (*s == 'p' && s[1] == 'n')
977 if (*s == 'p' && s[1] == 't')
989 if (strncmp (s, "%icc", 4) == 0)
1001 if (strncmp (s, "%xcc", 4) == 0)
1013 if (strncmp (s, "%fcc0", 5) == 0)
1025 if (strncmp (s, "%fcc1", 5) == 0)
1037 if (strncmp (s, "%fcc2", 5) == 0)
1049 if (strncmp (s, "%fcc3", 5) == 0)
1057 if (strncmp (s, "%pc", 3) == 0)
1065 if (strncmp (s, "%tick", 5) == 0)
1073 case '\0': /* end of args */
1092 case '[': /* these must match exactly */
1100 case '#': /* must be at least one digit */
1103 while (isdigit (*s))
1111 case 'C': /* coprocessor state register */
1112 if (strncmp (s, "%csr", 4) == 0)
1119 case 'b': /* next operand is a coprocessor register */
1122 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1127 mask = 10 * (mask - '0') + (*s++ - '0');
1141 opcode |= mask << 14;
1149 opcode |= mask << 25;
1155 case 'r': /* next operand must be a register */
1164 case 'f': /* frame pointer */
1172 case 'g': /* global register */
1173 if (isoctal (c = *s++))
1180 case 'i': /* in register */
1181 if (isoctal (c = *s++))
1183 mask = c - '0' + 24;
1188 case 'l': /* local register */
1189 if (isoctal (c = *s++))
1191 mask = (c - '0' + 16);
1196 case 'o': /* out register */
1197 if (isoctal (c = *s++))
1199 mask = (c - '0' + 8);
1204 case 's': /* stack pointer */
1212 case 'r': /* any register */
1213 if (!isdigit (c = *s++))
1230 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1246 * Got the register, now figure out where
1247 * it goes in the opcode.
1253 opcode |= mask << 14;
1261 opcode |= mask << 25;
1265 opcode |= (mask << 25) | (mask << 14);
1271 case 'e': /* next operand is a floating point register */
1286 && ((format = *s) == 'f')
1289 for (mask = 0; isdigit (*s); ++s)
1291 mask = 10 * mask + (*s - '0');
1292 } /* read the number */
1300 } /* register must be even numbered */
1308 } /* register must be multiple of 4 */
1313 error_message = ": There are only 64 f registers; [0-63]";
1319 } /* wrap high bit */
1323 error_message = ": There are only 32 f registers; [0-31]";
1331 } /* if not an 'f' register. */
1339 opcode |= RS1 (mask);
1346 opcode |= RS2 (mask);
1352 opcode |= RD (mask);
1361 if (strncmp (s, "%fsr", 4) == 0)
1368 case 'h': /* high 22 bits */
1369 the_insn.reloc = BFD_RELOC_HI22;
1372 case 'l': /* 22 bit PC relative immediate */
1373 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1377 case 'L': /* 30 bit immediate */
1378 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1382 case 'n': /* 22 bit immediate */
1383 the_insn.reloc = BFD_RELOC_SPARC22;
1386 case 'i': /* 13 bit immediate */
1387 the_insn.reloc = BFD_RELOC_SPARC13;
1388 immediate_max = 0x0FFF;
1397 if ((c = s[1]) == 'h' && s[2] == 'i')
1399 the_insn.reloc = BFD_RELOC_HI22;
1402 else if (c == 'l' && s[2] == 'o')
1404 the_insn.reloc = BFD_RELOC_LO10;
1412 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1419 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1426 /* Note that if the getExpression() fails, we will still
1427 have created U entries in the symbol table for the
1428 'symbols' in the input string. Try not to create U
1429 symbols for registers, etc. */
1431 /* This stuff checks to see if the expression ends in
1432 +%reg. If it does, it removes the register from
1433 the expression, and re-sets 's' to point to the
1438 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1440 if (s1 != s && isdigit (s1[-1]))
1442 if (s1[-2] == '%' && s1[-3] == '+')
1446 (void) getExpression (s);
1451 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1455 (void) getExpression (s);
1462 (void) getExpression (s);
1465 if (the_insn.exp.X_op == O_constant
1466 && the_insn.exp.X_add_symbol == 0
1467 && the_insn.exp.X_op_symbol == 0)
1470 /* Handle %uhi/%ulo by moving the upper word to the lower
1471 one and pretending it's %hi/%lo. We also need to watch
1472 for %hi/%lo: the top word needs to be zeroed otherwise
1473 fixup_segment will complain the value is too big. */
1474 switch (the_insn.reloc)
1476 case BFD_RELOC_SPARC_HH22:
1477 the_insn.reloc = BFD_RELOC_HI22;
1478 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1480 case BFD_RELOC_SPARC_HM10:
1481 the_insn.reloc = BFD_RELOC_LO10;
1482 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1486 case BFD_RELOC_HI22:
1487 case BFD_RELOC_LO10:
1488 the_insn.exp.X_add_number &= 0xffffffff;
1492 /* For pc-relative call instructions, we reject
1493 constants to get better code. */
1495 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
1496 && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
1499 error_message = ": PC-relative operand can't be a constant";
1502 /* Check for invalid constant values. Don't warn if
1503 constant was inside %hi or %lo, since these
1504 truncate the constant to fit. */
1505 if (immediate_max != 0
1506 && the_insn.reloc != BFD_RELOC_LO10
1507 && the_insn.reloc != BFD_RELOC_HI22
1508 && !in_signed_range (the_insn.exp.X_add_number,
1513 /* Who knows? After relocation, we may be within
1514 range. Let the linker figure it out. */
1516 the_insn.exp.X_op = O_symbol;
1517 the_insn.exp.X_add_symbol = section_symbol (absolute_section);
1520 /* Immediate value is non-pcrel, and out of
1522 as_bad ("constant value %ld out of range (%ld .. %ld)",
1523 the_insn.exp.X_add_number,
1524 ~immediate_max, immediate_max);
1528 /* Reset to prevent extraneous range check. */
1549 if (!strncmp (s, "ASI_AIUP", 8))
1551 else if (!strncmp (s, "ASI_AIUS", 8))
1553 else if (!strncmp (s, "ASI_PNF", 7))
1555 else if (!strncmp (s, "ASI_SNF", 7))
1557 else if (!strncmp (s, "ASI_P", 5))
1559 else if (!strncmp (s, "ASI_S", 5))
1563 error_message = ": invalid asi name";
1569 char *push = input_line_pointer;
1571 input_line_pointer = s;
1574 if (e.X_op != O_constant)
1576 error_message = ": constant required for ASI";
1579 asi = e.X_add_number;
1580 s = input_line_pointer;
1581 input_line_pointer = push;
1583 if (asi < 0 || asi > 255)
1585 error_message = ": invalid asi number";
1589 opcode |= ASI (asi);
1591 } /* alternate space */
1594 if (strncmp (s, "%psr", 4) == 0)
1601 case 'q': /* floating point queue */
1602 if (strncmp (s, "%fq", 3) == 0)
1609 case 'Q': /* coprocessor queue */
1610 if (strncmp (s, "%cq", 3) == 0)
1618 if (strcmp (str, "set") == 0)
1620 special_case = SPECIAL_CASE_SET;
1623 else if (strncmp (str, "fdiv", 4) == 0)
1625 special_case = SPECIAL_CASE_FDIV;
1632 if (strncmp (s, "%asi", 4) != 0)
1638 if (strncmp (s, "%fprs", 5) != 0)
1644 if (strncmp (s, "%ccr", 4) != 0)
1651 if (strncmp (s, "%tbr", 4) != 0)
1657 if (strncmp (s, "%wim", 4) != 0)
1665 char *push = input_line_pointer;
1668 input_line_pointer = s;
1670 if (e.X_op == O_constant)
1672 int n = e.X_add_number;
1673 if (n != e.X_add_number || (n & ~0x1ff) != 0)
1674 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1676 opcode |= e.X_add_number << 5;
1679 as_bad ("non-immediate OPF operand, ignored");
1680 s = input_line_pointer;
1681 input_line_pointer = push;
1687 if (strncmp (s, "%y", 2) != 0)
1693 as_fatal ("failed sanity check.");
1694 } /* switch on arg code */
1696 } /* for each arg that we expect */
1700 /* Args don't match. */
1701 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1702 && (insn->name == insn[1].name
1703 || !strcmp (insn->name, insn[1].name)))
1711 as_bad ("Illegal operands%s", error_message);
1717 if (insn->architecture > current_architecture
1718 || (insn->architecture != current_architecture
1719 && current_architecture > v8))
1721 if ((!architecture_requested || warn_on_bump)
1722 && !ARCHITECTURES_CONFLICT_P (current_architecture,
1724 && !ARCHITECTURES_CONFLICT_P (insn->architecture,
1725 current_architecture))
1729 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1730 architecture_pname[current_architecture],
1731 architecture_pname[insn->architecture],
1735 current_architecture = insn->architecture;
1739 as_bad ("Architecture mismatch on \"%s\".", str);
1740 as_tsktsk (" (Requires %s; current architecture is %s.)",
1741 architecture_pname[insn->architecture],
1742 architecture_pname[current_architecture]);
1744 } /* if bump ok else error */
1745 } /* if architecture higher */
1749 } /* forever looking for a match */
1751 the_insn.opcode = opcode;
1761 save_in = input_line_pointer;
1762 input_line_pointer = str;
1763 seg = expression (&the_insn.exp);
1764 if (seg != absolute_section
1765 && seg != text_section
1766 && seg != data_section
1767 && seg != bss_section
1768 && seg != undefined_section)
1770 the_insn.error = "bad segment";
1771 expr_end = input_line_pointer;
1772 input_line_pointer = save_in;
1775 expr_end = input_line_pointer;
1776 input_line_pointer = save_in;
1778 } /* getExpression() */
1782 This is identical to the md_atof in m68k.c. I think this is right,
1785 Turn a string in input_line_pointer into a floating point constant of type
1786 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1787 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1790 /* Equal to MAX_PRECISION in atof-ieee.c */
1791 #define MAX_LITTLENUMS 6
1794 md_atof (type, litP, sizeP)
1800 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1801 LITTLENUM_TYPE *wordP;
1834 return "Bad call to MD_ATOF()";
1836 t = atof_ieee (input_line_pointer, type, words);
1838 input_line_pointer = t;
1839 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1840 for (wordP = words; prec--;)
1842 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1843 litP += sizeof (LITTLENUM_TYPE);
1849 * Write out big-endian.
1852 md_number_to_chars (buf, val, n)
1857 number_to_chars_bigendian (buf, val, n);
1860 /* Apply a fixS to the frags, now that we know the value it ought to
1864 md_apply_fix (fixP, value)
1868 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1873 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1875 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1878 /* FIXME: SPARC ELF relocations don't use an addend in the data
1879 field itself. This whole approach should be somehow combined
1880 with the calls to bfd_perform_relocation. Also, the value passed
1881 in by fixup_segment includes the value of a defined symbol. We
1882 don't want to include the value of an externally visible symbol. */
1883 if (fixP->fx_addsy != NULL)
1885 if (S_IS_EXTERN (fixP->fx_addsy)
1886 && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section
1887 && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section
1888 && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy)))
1889 fixP->fx_addnumber -= S_GET_VALUE (fixP->fx_addsy);
1894 /* This is a hack. There should be a better way to
1895 handle this. Probably in terms of howto fields, once
1896 we can look at these fixups in terms of howtos. */
1897 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1898 val += fixP->fx_where + fixP->fx_frag->fr_address;
1901 /* FIXME: More ridiculous gas reloc hacking. If we are going to
1902 generate a reloc, then we just want to let the reloc addend set
1903 the value. We do not want to also stuff the addend into the
1904 object file. Including the addend in the object file works when
1905 doing a static link, because the linker will ignore the object
1906 file contents. However, the dynamic linker does not ignore the
1907 object file contents. */
1908 if (fixP->fx_addsy != NULL
1909 && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
1913 switch (fixP->fx_r_type)
1927 case BFD_RELOC_32_PCREL_S2:
1928 val = (val >>= 2) + 1;
1929 buf[0] |= (val >> 24) & 0x3f;
1930 buf[1] = (val >> 16);
1938 bfd_vma valh = BSR (val, 32);
1939 buf[0] = valh >> 24;
1940 buf[1] = valh >> 16;
1950 case BFD_RELOC_SPARC_11:
1951 if (((val > 0) && (val & ~0x7ff))
1952 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1954 as_bad ("relocation overflow.");
1957 buf[2] |= (val >> 8) & 0x7;
1958 buf[3] = val & 0xff;
1961 case BFD_RELOC_SPARC_10:
1962 if (((val > 0) && (val & ~0x3ff))
1963 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1965 as_bad ("relocation overflow.");
1968 buf[2] |= (val >> 8) & 0x3;
1969 buf[3] = val & 0xff;
1972 case BFD_RELOC_SPARC_WDISP16:
1973 if (((val > 0) && (val & ~0x3fffc))
1974 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1976 as_bad ("relocation overflow.");
1979 val = (val >>= 2) + 1;
1980 buf[1] |= ((val >> 14) & 0x3) << 4;
1981 buf[2] |= (val >> 8) & 0x3f;
1982 buf[3] = val & 0xff;
1985 case BFD_RELOC_SPARC_WDISP19:
1986 if (((val > 0) && (val & ~0x1ffffc))
1987 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1989 as_bad ("relocation overflow.");
1992 val = (val >>= 2) + 1;
1993 buf[1] |= (val >> 16) & 0x7;
1994 buf[2] = (val >> 8) & 0xff;
1995 buf[3] = val & 0xff;
1998 case BFD_RELOC_SPARC_HH22:
1999 val = BSR (val, 32);
2000 /* intentional fallthrough */
2004 case BFD_RELOC_SPARC_LM22:
2006 case BFD_RELOC_HI22:
2007 if (!fixP->fx_addsy)
2009 buf[1] |= (val >> 26) & 0x3f;
2020 case BFD_RELOC_SPARC22:
2021 if (val & ~0x003fffff)
2023 as_bad ("relocation overflow");
2025 buf[1] |= (val >> 16) & 0x3f;
2027 buf[3] = val & 0xff;
2031 case BFD_RELOC_SPARC_HM10:
2032 val = BSR (val, 32);
2033 /* intentional fallthrough */
2036 case BFD_RELOC_LO10:
2037 if (!fixP->fx_addsy)
2039 buf[2] |= (val >> 8) & 0x03;
2046 case BFD_RELOC_SPARC13:
2047 if (! in_signed_range (val, 0x1fff))
2048 as_bad ("relocation overflow");
2050 buf[2] |= (val >> 8) & 0x1f;
2054 case BFD_RELOC_SPARC_WDISP22:
2055 val = (val >> 2) + 1;
2057 case BFD_RELOC_SPARC_BASE22:
2058 buf[1] |= (val >> 16) & 0x3f;
2063 case BFD_RELOC_NONE:
2065 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2069 /* Are we finished with this relocation now? */
2070 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
2076 /* Translate internal representation of relocation info to BFD target
2079 tc_gen_reloc (section, fixp)
2084 bfd_reloc_code_real_type code;
2086 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2087 assert (reloc != 0);
2089 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2090 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2092 switch (fixp->fx_r_type)
2096 case BFD_RELOC_HI22:
2097 case BFD_RELOC_LO10:
2098 case BFD_RELOC_32_PCREL_S2:
2099 case BFD_RELOC_SPARC13:
2100 case BFD_RELOC_SPARC_BASE13:
2101 case BFD_RELOC_SPARC_WDISP16:
2102 case BFD_RELOC_SPARC_WDISP19:
2103 case BFD_RELOC_SPARC_WDISP22:
2105 case BFD_RELOC_SPARC_10:
2106 case BFD_RELOC_SPARC_11:
2107 case BFD_RELOC_SPARC_HH22:
2108 case BFD_RELOC_SPARC_HM10:
2109 case BFD_RELOC_SPARC_LM22:
2110 case BFD_RELOC_SPARC_PC_HH22:
2111 case BFD_RELOC_SPARC_PC_HM10:
2112 case BFD_RELOC_SPARC_PC_LM22:
2113 code = fixp->fx_r_type;
2118 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2119 if (reloc->howto == 0)
2121 as_bad_where (fixp->fx_file, fixp->fx_line,
2122 "internal error: can't export reloc type %d (`%s')",
2123 fixp->fx_r_type, bfd_get_reloc_code_name (code));
2126 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
2128 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2131 if (reloc->howto->pc_relative == 0)
2132 reloc->addend = fixp->fx_addnumber;
2134 reloc->addend = fixp->fx_offset - reloc->address;
2136 #else /* elf or coff */
2138 if (reloc->howto->pc_relative == 0)
2139 reloc->addend = fixp->fx_addnumber;
2140 else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
2141 reloc->addend = (section->vma
2142 + fixp->fx_addnumber
2143 + md_pcrel_from (fixp));
2145 reloc->addend = fixp->fx_offset;
2154 /* for debugging only */
2157 struct sparc_it *insn;
2159 const char *const Reloc[] = {
2188 fprintf (stderr, "ERROR: %s\n");
2189 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2190 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2191 fprintf (stderr, "exp = {\n");
2192 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2193 ((insn->exp.X_add_symbol != NULL)
2194 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2195 ? S_GET_NAME (insn->exp.X_add_symbol)
2198 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2199 ((insn->exp.X_op_symbol != NULL)
2200 ? (S_GET_NAME (insn->exp.X_op_symbol)
2201 ? S_GET_NAME (insn->exp.X_op_symbol)
2204 fprintf (stderr, "\t\tX_add_number = %d\n",
2205 insn->exp.X_add_number);
2206 fprintf (stderr, "}\n");
2212 * Invocation line includes a switch not recognized by the base assembler.
2213 * See if it's a processor-specific option. These are:
2216 * Warn on architecture bumps. See also -A.
2218 * -Av6, -Av7, -Av8, -Av9, -Asparclite
2219 * Select the architecture. Instructions or features not
2220 * supported by the selected architecture cause fatal errors.
2222 * The default is to start at v6, and bump the architecture up
2223 * whenever an instruction is seen at a higher level.
2225 * If -bump is specified, a warning is printing when bumping to
2228 * If an architecture is specified, all instructions must match
2229 * that architecture. Any higher level instructions are flagged
2232 * if both an architecture and -bump are specified, the
2233 * architecture starts at the specified level, but bumps are
2237 * Bumping between incompatible architectures is always an
2238 * error. For example, from sparclite to v9.
2242 CONST char *md_shortopts = "A:K:VQ:sq";
2244 CONST char *md_shortopts = "A:";
2246 struct option md_longopts[] = {
2247 #define OPTION_BUMP (OPTION_MD_BASE)
2248 {"bump", no_argument, NULL, OPTION_BUMP},
2249 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2250 {"sparc", no_argument, NULL, OPTION_SPARC},
2251 {NULL, no_argument, NULL, 0}
2253 size_t md_longopts_size = sizeof(md_longopts);
2256 md_parse_option (c, arg)
2271 for (arch = architecture_pname; *arch != NULL; ++arch)
2273 if (strcmp (p, *arch) == 0)
2279 as_bad ("invalid architecture -A%s", p);
2284 enum sparc_architecture new_arch = arch - architecture_pname;
2288 as_error ("v9 support not compiled in");
2292 current_architecture = new_arch;
2293 architecture_requested = 1;
2299 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2304 print_version_id ();
2308 /* Qy - do emit .comment
2309 Qn - do not emit .comment */
2313 /* use .stab instead of .stab.excl */
2317 /* quick -- native assembler does fewer checks */
2321 if (strcmp (arg, "PIC") != 0)
2322 as_warn ("Unrecognized option following -K");
2325 as_warn ("gas does not currently support PIC code for the SPARC");
2326 as_fatal ("use /usr/ccs/bin/as instead");
2338 md_show_usage (stream)
2342 fprintf(stream, "SPARC options:\n");
2343 for (arch = architecture_pname; *arch; arch++)
2345 if (arch != architecture_pname)
2346 fprintf (stream, " | ");
2347 fprintf (stream, "-A%s", *arch);
2349 fprintf (stream, "\n\
2350 specify variant of SPARC architecture\n\
2351 -bump warn when assembler switches architectures\n\
2355 -V print assembler version number\n\
2362 /* We have no need to default values of symbols. */
2366 md_undefined_symbol (name)
2370 } /* md_undefined_symbol() */
2372 /* Round up a section size to the appropriate boundary. */
2374 md_section_align (segment, size)
2379 /* This is not right for ELF; a.out wants it, and COFF will force
2380 the alignment anyways. */
2381 valueT align = ((valueT) 1
2382 << (valueT) bfd_get_section_alignment (stdoutput, segment));
2384 /* turn alignment value into a mask */
2386 newsize = (size + align) & ~align;
2393 /* Exactly what point is a PC-relative offset relative TO?
2394 On the sparc, they're relative to the address of the offset, plus
2395 its size. This gets us to the following instruction.
2396 (??? Is this right? FIXME-SOON) */
2398 md_pcrel_from (fixP)
2401 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2404 /* end of tc-sparc.c */