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, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* careful, this file includes data *declarations* */
28 #include "opcode/sparc.h"
30 static void sparc_ip PARAMS ((char *));
32 static enum sparc_architecture current_architecture = v6;
33 static int architecture_requested;
34 static int warn_on_bump;
36 extern int target_big_endian;
38 const relax_typeS md_relax_table[1];
40 /* handle of the OPCODE hash table */
41 static struct hash_control *op_hash = NULL;
43 static void s_data1 PARAMS ((void));
44 static void s_seg PARAMS ((int));
45 static void s_proc PARAMS ((int));
46 static void s_reserve PARAMS ((int));
47 static void s_common PARAMS ((int));
49 const pseudo_typeS md_pseudo_table[] =
51 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
52 {"common", s_common, 0},
53 {"global", s_globl, 0},
55 {"optim", s_ignore, 0},
57 {"reserve", s_reserve, 0},
61 /* start-sanitize-v9 */
70 /* these are specific to sparc/svr4 */
71 {"pushsection", obj_elf_section, 0},
72 {"popsection", obj_elf_previous, 0},
79 const int md_short_jump_size = 4;
80 const int md_long_jump_size = 4;
81 const int md_reloc_size = 12; /* Size of relocation record */
83 /* This array holds the chars that always start a comment. If the
84 pre-processor is disabled, these aren't very useful */
85 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
87 /* This array holds the chars that only start a comment at the beginning of
88 a line. If the line seems to have the form '# 123 filename'
89 .line and .file directives will appear in the pre-processed output */
90 /* Note that input_file.c hand checks for '#' at the beginning of the
91 first line of the input file. This is because the compiler outputs
92 #NO_APP at the beginning of its output. */
93 /* Also note that comments started like this one will always
94 work if '/' isn't otherwise defined. */
95 const char line_comment_chars[] = "#";
97 const char line_separator_chars[] = "";
99 /* Chars that can be used to separate mant from exp in floating point nums */
100 const char EXP_CHARS[] = "eE";
102 /* Chars that mean this number is a floating point constant */
105 const char FLT_CHARS[] = "rRsSfFdDxXpP";
107 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
108 changed in read.c. Ideally it shouldn't have to know about it at all,
109 but nothing is ideal around here. */
111 static unsigned char octal[256];
112 #define isoctal(c) octal[(unsigned char) (c)]
113 static unsigned char toHex[256];
118 unsigned long opcode;
119 struct nlist *nlistp;
122 bfd_reloc_code_real_type reloc;
125 struct sparc_it the_insn, set_insn;
128 static void print_insn PARAMS ((struct sparc_it *insn));
130 static int getExpression PARAMS ((char *str));
132 static char *expr_end;
133 static int special_case;
136 * Instructions that require wierd handling because they're longer than
139 #define SPECIAL_CASE_SET 1
140 #define SPECIAL_CASE_FDIV 2
143 * sort of like s_lcomm
147 static int max_alignment = 15;
162 name = input_line_pointer;
163 c = get_symbol_end ();
164 p = input_line_pointer;
168 if (*input_line_pointer != ',')
170 as_bad ("Expected comma after name");
171 ignore_rest_of_line ();
175 ++input_line_pointer;
177 if ((size = get_absolute_expression ()) < 0)
179 as_bad ("BSS length (%d.) <0! Ignored.", size);
180 ignore_rest_of_line ();
185 symbolP = symbol_find_or_make (name);
188 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
189 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
191 as_bad ("bad .reserve segment: `%s'", input_line_pointer);
195 if (input_line_pointer[2] == '.')
196 input_line_pointer += 7;
198 input_line_pointer += 6;
201 if (*input_line_pointer == ',')
203 ++input_line_pointer;
206 if (*input_line_pointer == '\n')
208 as_bad ("Missing alignment");
212 align = get_absolute_expression ();
214 if (align > max_alignment)
216 align = max_alignment;
217 as_warn ("Alignment too large: %d. assumed.", align);
223 as_warn ("Alignment negative. 0 assumed.");
226 record_alignment (bss_section, align);
228 /* convert to a power of 2 alignment */
229 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
233 as_bad ("Alignment not a power of 2");
234 ignore_rest_of_line ();
236 } /* not a power of two */
239 } /* if has optional alignment */
243 if ((S_GET_SEGMENT (symbolP) == bss_section
244 || !S_IS_DEFINED (symbolP))
246 && S_GET_OTHER (symbolP) == 0
247 && S_GET_DESC (symbolP) == 0
254 segT current_seg = now_seg;
255 subsegT current_subseg = now_subseg;
257 subseg_set (bss_section, 1); /* switch to bss */
260 frag_align (align, 0); /* do alignment */
262 /* detach from old frag */
263 if (S_GET_SEGMENT(symbolP) == bss_section)
264 symbolP->sy_frag->fr_symbol = NULL;
266 symbolP->sy_frag = frag_now;
267 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
271 S_SET_SEGMENT (symbolP, bss_section);
273 subseg_set (current_seg, current_subseg);
278 as_warn("Ignoring attempt to re-define symbol %s.", name);
279 } /* if not redefining */
281 demand_empty_rest_of_line ();
294 name = input_line_pointer;
295 c = get_symbol_end ();
296 /* just after name is now '\0' */
297 p = input_line_pointer;
300 if (*input_line_pointer != ',')
302 as_bad ("Expected comma after symbol-name");
303 ignore_rest_of_line ();
306 input_line_pointer++; /* skip ',' */
307 if ((temp = get_absolute_expression ()) < 0)
309 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
310 ignore_rest_of_line ();
315 symbolP = symbol_find_or_make (name);
317 if (S_IS_DEFINED (symbolP))
319 as_bad ("Ignoring attempt to re-define symbol");
320 ignore_rest_of_line ();
323 if (S_GET_VALUE (symbolP) != 0)
325 if (S_GET_VALUE (symbolP) != size)
327 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
328 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
334 S_SET_VALUE (symbolP, (valueT) size);
335 S_SET_EXTERNAL (symbolP);
338 know (symbolP->sy_frag == &zero_address_frag);
339 if (*input_line_pointer != ',')
341 as_bad ("Expected comma after common length");
342 ignore_rest_of_line ();
345 input_line_pointer++;
347 if (*input_line_pointer != '"')
349 temp = get_absolute_expression ();
351 if (temp > max_alignment)
353 temp = max_alignment;
354 as_warn ("Common alignment too large: %d. assumed", temp);
360 as_warn ("Common alignment negative; 0 assumed");
372 old_subsec = now_subseg;
374 record_alignment (bss_section, align);
375 subseg_set (bss_section, 0);
377 frag_align (align, 0);
378 if (S_GET_SEGMENT (symbolP) == bss_section)
379 symbolP->sy_frag->fr_symbol = 0;
380 symbolP->sy_frag = frag_now;
381 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
384 S_SET_SEGMENT (symbolP, bss_section);
385 S_CLEAR_EXTERNAL (symbolP);
386 subseg_set (old_sec, old_subsec);
392 S_SET_VALUE (symbolP, (valueT) size);
393 S_SET_EXTERNAL (symbolP);
394 /* should be common, but this is how gas does it for now */
395 S_SET_SEGMENT (symbolP, &bfd_und_section);
400 input_line_pointer++;
401 /* @@ Some use the dot, some don't. Can we get some consistency?? */
402 if (*input_line_pointer == '.')
403 input_line_pointer++;
404 /* @@ Some say data, some say bss. */
405 if (strncmp (input_line_pointer, "bss\"", 4)
406 && strncmp (input_line_pointer, "data\"", 5))
408 while (*--input_line_pointer != '"')
410 input_line_pointer--;
411 goto bad_common_segment;
413 while (*input_line_pointer++ != '"')
415 goto allocate_common;
417 demand_empty_rest_of_line ();
422 p = input_line_pointer;
423 while (*p && *p != '\n')
427 as_bad ("bad .common segment %s", input_line_pointer + 1);
429 input_line_pointer = p;
430 ignore_rest_of_line ();
440 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
442 input_line_pointer += 6;
446 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
448 input_line_pointer += 6;
452 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
454 input_line_pointer += 7;
458 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
460 input_line_pointer += 5;
461 /* We only support 2 segments -- text and data -- for now, so
462 things in the "bss segment" will have to go into data for now.
463 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
464 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
467 as_bad ("Unknown segment type");
468 demand_empty_rest_of_line ();
474 subseg_set (data_section, 1);
475 demand_empty_rest_of_line ();
482 while (!is_end_of_line[(unsigned char) *input_line_pointer])
484 ++input_line_pointer;
486 ++input_line_pointer;
489 /* start-sanitize-v9 */
492 struct priv_reg_entry
498 struct priv_reg_entry priv_reg_table[] =
517 {"", -1}, /* end marker */
527 #define MEMBAR_MASKS_SIZE 7
529 struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
532 {"MemIssue", 8, 0x20},
533 {"Lookaside", 9, 0x10},
534 {"StoreStore", 10, 0x08},
535 {"LoadStore", 9, 0x04},
536 {"StoreLoad", 9, 0x02},
537 {"LoadLoad", 8, 0x01},
542 struct priv_reg_entry *p, *q;
544 return strcmp (q->name, p->name);
548 /* end-sanitize-v9 */
550 /* This function is called once, at assembler startup time. It should
551 set up all the tables, etc. that the MD part of the assembler will need. */
555 register const char *retval = NULL;
557 register unsigned int i = 0;
559 op_hash = hash_new ();
561 while (i < NUMOPCODES)
563 const char *name = sparc_opcodes[i].name;
564 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
567 fprintf (stderr, "internal error: can't hash `%s': %s\n",
568 sparc_opcodes[i].name, retval);
573 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
575 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
576 sparc_opcodes[i].name, sparc_opcodes[i].args);
581 while (i < NUMOPCODES
582 && !strcmp (sparc_opcodes[i].name, name));
586 as_fatal ("Broken assembler. No assembly attempted.");
588 for (i = '0'; i < '8'; ++i)
590 for (i = '0'; i <= '9'; ++i)
592 for (i = 'a'; i <= 'f'; ++i)
593 toHex[i] = i + 10 - 'a';
594 for (i = 'A'; i <= 'F'; ++i)
595 toHex[i] = i + 10 - 'A';
597 /* start-sanitize-v9 */
600 current_architecture = v9;
603 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
604 sizeof (priv_reg_table[0]), cmp_reg_entry);
606 /* end-sanitize-v9 */
608 target_big_endian = 1;
621 /* See if "set" operand is absolute and small; skip sethi if so. */
622 if (special_case == SPECIAL_CASE_SET
623 && the_insn.exp.X_op == O_constant)
625 if (the_insn.exp.X_add_number >= -(1 << 12)
626 && the_insn.exp.X_add_number < (1 << 12))
628 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
629 | (the_insn.opcode & 0x3E000000) /* dest reg */
630 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
631 special_case = 0; /* No longer special */
632 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
637 /* put out the opcode */
638 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
640 /* put out the symbol-dependent stuff */
641 if (the_insn.reloc != BFD_RELOC_NONE)
643 fix_new_exp (frag_now, /* which frag */
644 (toP - frag_now->fr_literal), /* where */
651 switch (special_case)
653 case SPECIAL_CASE_SET:
655 assert (the_insn.reloc == BFD_RELOC_HI22);
656 /* See if "set" operand has no low-order bits; skip OR if so. */
657 if (the_insn.exp.X_op == O_constant
658 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
661 rsd = (the_insn.opcode >> 25) & 0x1f;
662 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
663 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
664 fix_new_exp (frag_now, /* which frag */
665 (toP - frag_now->fr_literal), /* where */
672 case SPECIAL_CASE_FDIV:
673 /* According to information leaked from Sun, the "fdiv" instructions
674 on early SPARC machines would produce incorrect results sometimes.
675 The workaround is to add an fmovs of the destination register to
676 itself just after the instruction. This was true on machines
677 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
679 assert (the_insn.reloc == BFD_RELOC_NONE);
681 rsd = (the_insn.opcode >> 25) & 0x1f;
682 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
683 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
690 as_fatal ("failed sanity check.");
698 char *error_message = "";
702 struct sparc_opcode *insn;
704 unsigned long opcode;
705 unsigned int mask = 0;
708 long immediate_max = 0;
710 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
728 as_bad ("Unknown opcode: `%s'", str);
731 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
733 as_bad ("Unknown opcode: `%s'", str);
743 opcode = insn->match;
744 memset (&the_insn, '\0', sizeof (the_insn));
745 the_insn.reloc = BFD_RELOC_NONE;
748 * Build the opcode, checking as we go to make
749 * sure that the operands match
751 for (args = insn->args;; ++args)
756 /* start-sanitize-v9 */
763 /* Parse a series of masks. */
769 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
770 if (!strncmp (s, membar_masks[i].name,
771 membar_masks[i].len))
773 if (i < MEMBAR_MASKS_SIZE)
775 kmask |= membar_masks[i].mask;
776 s += membar_masks[i].len;
780 error_message = ": invalid membar mask name";
793 hold = input_line_pointer;
794 input_line_pointer = s;
796 send = input_line_pointer;
797 input_line_pointer = hold;
799 kmask = exp.X_add_number;
800 if (exp.X_op != O_constant
804 error_message = ": invalid membar mask number";
811 opcode |= SIMM13 (kmask);
817 int prefetch_fcn = 0;
819 /* Parse a prefetch function. */
823 if (!strncmp (s, "n_reads", 7))
824 prefetch_fcn = 0, s += 7;
825 else if (!strncmp (s, "one_read", 8))
826 prefetch_fcn = 1, s += 8;
827 else if (!strncmp (s, "n_writes", 8))
828 prefetch_fcn = 2, s += 8;
829 else if (!strncmp (s, "one_write", 9))
830 prefetch_fcn = 3, s += 9;
831 else if (!strncmp (s, "page", 4))
832 prefetch_fcn = 4, s += 4;
835 error_message = ": invalid prefetch function name";
839 else if (isdigit (*s))
843 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
847 if (prefetch_fcn < 0 || prefetch_fcn > 31)
849 error_message = ": invalid prefetch function number";
855 error_message = ": unrecognizable prefetch function";
858 opcode |= RD (prefetch_fcn);
864 /* Parse a privileged register. */
867 struct priv_reg_entry *p = priv_reg_table;
868 unsigned int len = 9999999; /* init to make gcc happy */
871 while (p->name[0] > s[0])
873 while (p->name[0] == s[0])
875 len = strlen (p->name);
876 if (strncmp (p->name, s, len) == 0)
880 if (p->name[0] != s[0])
882 error_message = ": unrecognizable privileged register";
886 opcode |= (p->regnum << 14);
888 opcode |= (p->regnum << 25);
894 error_message = ": unrecognizable privileged register";
898 /* end-sanitize-v9 */
902 if (strncmp (s, "%asr", 4) == 0)
912 num = num * 10 + *s - '0';
916 if (num < 16 || 31 < num)
918 error_message = ": asr number must be between 15 and 31";
922 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
927 error_message = ": expecting %asrN";
929 } /* if %asr followed by a number. */
934 /* start-sanitize-v9 */
937 the_insn.reloc = BFD_RELOC_SPARC_11;
938 immediate_max = 0x03FF;
942 the_insn.reloc = BFD_RELOC_SPARC_10;
943 immediate_max = 0x01FF;
947 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
952 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
957 if (*s == 'p' && s[1] == 'n')
965 if (*s == 'p' && s[1] == 't')
977 if (strncmp (s, "%icc", 4) == 0)
989 if (strncmp (s, "%xcc", 4) == 0)
1001 if (strncmp (s, "%fcc0", 5) == 0)
1013 if (strncmp (s, "%fcc1", 5) == 0)
1025 if (strncmp (s, "%fcc2", 5) == 0)
1037 if (strncmp (s, "%fcc3", 5) == 0)
1045 if (strncmp (s, "%pc", 3) == 0)
1053 if (strncmp (s, "%tick", 5) == 0)
1060 /* end-sanitize-v9 */
1062 case '\0': /* end of args */
1081 case '[': /* these must match exactly */
1089 case '#': /* must be at least one digit */
1092 while (isdigit (*s))
1100 case 'C': /* coprocessor state register */
1101 if (strncmp (s, "%csr", 4) == 0)
1108 case 'b': /* next operand is a coprocessor register */
1111 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1116 mask = 10 * (mask - '0') + (*s++ - '0');
1130 opcode |= mask << 14;
1138 opcode |= mask << 25;
1144 case 'r': /* next operand must be a register */
1153 case 'f': /* frame pointer */
1161 case 'g': /* global register */
1162 if (isoctal (c = *s++))
1169 case 'i': /* in register */
1170 if (isoctal (c = *s++))
1172 mask = c - '0' + 24;
1177 case 'l': /* local register */
1178 if (isoctal (c = *s++))
1180 mask = (c - '0' + 16);
1185 case 'o': /* out register */
1186 if (isoctal (c = *s++))
1188 mask = (c - '0' + 8);
1193 case 's': /* stack pointer */
1201 case 'r': /* any register */
1202 if (!isdigit (c = *s++))
1219 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1235 * Got the register, now figure out where
1236 * it goes in the opcode.
1242 opcode |= mask << 14;
1250 opcode |= mask << 25;
1254 opcode |= (mask << 25) | (mask << 14);
1260 case 'e': /* next operand is a floating point register */
1275 && ((format = *s) == 'f')
1278 for (mask = 0; isdigit (*s); ++s)
1280 mask = 10 * mask + (*s - '0');
1281 } /* read the number */
1289 } /* register must be even numbered */
1297 } /* register must be multiple of 4 */
1299 /* start-sanitize-v9 */
1303 error_message = ": There are only 64 f registers; [0-63]";
1309 } /* wrap high bit */
1311 /* end-sanitize-v9 */
1314 error_message = ": There are only 32 f registers; [0-31]";
1317 /* start-sanitize-v9 */
1319 /* end-sanitize-v9 */
1324 } /* if not an 'f' register. */
1332 opcode |= RS1 (mask);
1339 opcode |= RS2 (mask);
1345 opcode |= RD (mask);
1354 if (strncmp (s, "%fsr", 4) == 0)
1361 case 'h': /* high 22 bits */
1362 the_insn.reloc = BFD_RELOC_HI22;
1365 case 'l': /* 22 bit PC relative immediate */
1366 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1370 case 'L': /* 30 bit immediate */
1371 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1375 case 'n': /* 22 bit immediate */
1376 the_insn.reloc = BFD_RELOC_SPARC22;
1379 case 'i': /* 13 bit immediate */
1380 /* What's the difference between base13 and 13? */
1381 the_insn.reloc = BFD_RELOC_SPARC_BASE13;
1382 immediate_max = 0x0FFF;
1391 if ((c = s[1]) == 'h' && s[2] == 'i')
1393 the_insn.reloc = BFD_RELOC_HI22;
1396 else if (c == 'l' && s[2] == 'o')
1398 the_insn.reloc = BFD_RELOC_LO10;
1401 /* start-sanitize-v9 */
1407 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1414 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1418 /* end-sanitize-v9 */
1422 /* Note that if the getExpression() fails, we will still
1423 have created U entries in the symbol table for the
1424 'symbols' in the input string. Try not to create U
1425 symbols for registers, etc. */
1427 /* This stuff checks to see if the expression ends in
1428 +%reg. If it does, it removes the register from
1429 the expression, and re-sets 's' to point to the
1434 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1436 if (s1 != s && isdigit (s1[-1]))
1438 if (s1[-2] == '%' && s1[-3] == '+')
1442 (void) getExpression (s);
1447 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1451 (void) getExpression (s);
1458 (void) getExpression (s);
1461 if (the_insn.exp.X_op == O_constant
1462 && the_insn.exp.X_add_symbol == 0
1463 && the_insn.exp.X_op_symbol == 0)
1465 /* start-sanitize-v9 */
1467 switch (the_insn.reloc)
1469 case BFD_RELOC_SPARC_HH22:
1470 the_insn.reloc = BFD_RELOC_HI22;
1471 the_insn.exp.X_add_number >>= 32;
1473 case BFD_RELOC_SPARC_HM10:
1474 the_insn.reloc = BFD_RELOC_LO10;
1475 the_insn.exp.X_add_number >>= 32;
1481 /* end-sanitize-v9 */
1482 /* Check for invalid constant values. Don't warn if
1483 constant was inside %hi or %lo, since these
1484 truncate the constant to fit. */
1485 if (immediate_max != 0
1486 && the_insn.reloc != BFD_RELOC_LO10
1487 && the_insn.reloc != BFD_RELOC_HI22
1488 && (the_insn.exp.X_add_number > immediate_max
1489 || the_insn.exp.X_add_number < ~immediate_max))
1490 as_bad ("constant value must be between %ld and %ld",
1491 ~immediate_max, immediate_max);
1494 /* Reset to prevent extraneous range check. */
1509 /* start-sanitize-v9 */
1511 /* end-sanitize-v9 */
1512 char *push = input_line_pointer;
1515 input_line_pointer = s;
1518 if (e.X_op == O_constant)
1520 opcode |= e.X_add_number << 5;
1521 s = input_line_pointer;
1522 input_line_pointer = push;
1527 /* start-sanitize-v9 */
1535 if (!strncmp (s, "ASI_AIUP", 8))
1537 else if (!strncmp (s, "ASI_AIUS", 8))
1539 else if (!strncmp (s, "ASI_PNF", 7))
1541 else if (!strncmp (s, "ASI_SNF", 7))
1543 else if (!strncmp (s, "ASI_P", 5))
1545 else if (!strncmp (s, "ASI_S", 5))
1549 error_message = ": invalid asi name";
1553 else if (isdigit (*s))
1555 char *push = input_line_pointer;
1556 input_line_pointer = s;
1557 asi = get_absolute_expression ();
1558 s = input_line_pointer;
1559 input_line_pointer = push;
1561 if (asi < 0 || asi > 255)
1563 error_message = ": invalid asi number";
1569 error_message = ": unrecognizable asi";
1572 opcode |= ASI (asi);
1575 /* end-sanitize-v9 */
1576 } /* alternate space */
1579 if (strncmp (s, "%psr", 4) == 0)
1586 case 'q': /* floating point queue */
1587 if (strncmp (s, "%fq", 3) == 0)
1594 case 'Q': /* coprocessor queue */
1595 if (strncmp (s, "%cq", 3) == 0)
1603 if (strcmp (str, "set") == 0)
1605 special_case = SPECIAL_CASE_SET;
1608 else if (strncmp (str, "fdiv", 4) == 0)
1610 special_case = SPECIAL_CASE_FDIV;
1615 /* start-sanitize-v9 */
1618 if (strncmp (s, "%asi", 4) != 0)
1624 if (strncmp (s, "%fprs", 5) != 0)
1630 if (strncmp (s, "%ccr", 4) != 0)
1635 /* end-sanitize-v9 */
1638 if (strncmp (s, "%tbr", 4) != 0)
1644 if (strncmp (s, "%wim", 4) != 0)
1650 if (strncmp (s, "%y", 2) != 0)
1656 as_fatal ("failed sanity check.");
1657 } /* switch on arg code */
1659 } /* for each arg that we expect */
1663 /* Args don't match. */
1664 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1665 && !strcmp (insn->name, insn[1].name))
1673 as_bad ("Illegal operands%s", error_message);
1679 if (insn->architecture > current_architecture)
1681 if ((!architecture_requested || warn_on_bump)
1683 /* start-sanitize-v9 */
1685 !ARCHITECTURES_CONFLICT_P (current_architecture,
1688 /* end-sanitize-v9 */
1690 /* start-sanitize-v9 */
1692 /* end-sanitize-v9 */
1697 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1698 architecture_pname[current_architecture],
1699 architecture_pname[insn->architecture],
1703 current_architecture = insn->architecture;
1707 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1709 architecture_pname[insn->architecture],
1710 architecture_pname[current_architecture]);
1712 } /* if bump ok else error */
1713 } /* if architecture higher */
1717 } /* forever looking for a match */
1719 the_insn.opcode = opcode;
1729 save_in = input_line_pointer;
1730 input_line_pointer = str;
1731 seg = expression (&the_insn.exp);
1732 if (seg != absolute_section
1733 && seg != text_section
1734 && seg != data_section
1735 && seg != bss_section
1736 && seg != undefined_section)
1738 the_insn.error = "bad segment";
1739 expr_end = input_line_pointer;
1740 input_line_pointer = save_in;
1743 expr_end = input_line_pointer;
1744 input_line_pointer = save_in;
1746 } /* getExpression() */
1750 This is identical to the md_atof in m68k.c. I think this is right,
1753 Turn a string in input_line_pointer into a floating point constant of type
1754 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1755 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1758 /* Equal to MAX_PRECISION in atof-ieee.c */
1759 #define MAX_LITTLENUMS 6
1762 md_atof (type, litP, sizeP)
1768 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1769 LITTLENUM_TYPE *wordP;
1802 return "Bad call to MD_ATOF()";
1804 t = atof_ieee (input_line_pointer, type, words);
1806 input_line_pointer = t;
1807 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1808 for (wordP = words; prec--;)
1810 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1811 litP += sizeof (LITTLENUM_TYPE);
1817 * Write out big-endian.
1820 md_number_to_chars (buf, val, n)
1825 number_to_chars_bigendian (buf, val, n);
1828 /* Apply a fixS to the frags, now that we know the value it ought to
1832 md_apply_fix (fixP, value)
1836 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1841 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1843 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1846 /* FIXME: SPARC ELF relocations don't use an addend in the data
1847 field itself. This whole approach should be somehow combined
1848 with the calls to bfd_perform_relocation. */
1849 if (fixP->fx_addsy != NULL)
1853 /* This is a hack. There should be a better way to
1854 handle this. Probably in terms of howto fields, once
1855 we can look at these fixups in terms of howtos. */
1856 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1857 val += fixP->fx_where + fixP->fx_frag->fr_address;
1859 switch (fixP->fx_r_type)
1873 case BFD_RELOC_32_PCREL_S2:
1874 val = (val >>= 2) + 1;
1875 buf[0] |= (val >> 24) & 0x3f;
1876 buf[1] = (val >> 16);
1881 /* start-sanitize-v9 */
1894 case BFD_RELOC_SPARC_11:
1895 if (((val > 0) && (val & ~0x7ff))
1896 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1898 as_bad ("relocation overflow.");
1901 buf[2] |= (val >> 8) & 0x7;
1902 buf[3] = val & 0xff;
1905 case BFD_RELOC_SPARC_10:
1906 if (((val > 0) && (val & ~0x3ff))
1907 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1909 as_bad ("relocation overflow.");
1912 buf[2] |= (val >> 8) & 0x3;
1913 buf[3] = val & 0xff;
1916 case BFD_RELOC_SPARC_WDISP16:
1917 if (((val > 0) && (val & ~0x3fffc))
1918 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1920 as_bad ("relocation overflow.");
1923 val = (val >>= 2) + 1;
1924 buf[1] |= ((val >> 14) & 0x3) << 4;
1925 buf[2] |= (val >> 8) & 0x3f;
1926 buf[3] = val & 0xff;
1929 case BFD_RELOC_SPARC_WDISP19:
1930 if (((val > 0) && (val & ~0x1ffffc))
1931 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1933 as_bad ("relocation overflow.");
1936 val = (val >>= 2) + 1;
1937 buf[1] |= (val >> 16) & 0x7;
1938 buf[2] = (val >> 8) & 0xff;
1939 buf[3] = val & 0xff;
1942 case BFD_RELOC_SPARC_HH22:
1944 /* intentional fallthrough */
1946 /* end-sanitize-v9 */
1948 /* start-sanitize-v9 */
1950 case BFD_RELOC_SPARC_LM22:
1952 /* end-sanitize-v9 */
1953 case BFD_RELOC_HI22:
1954 if (!fixP->fx_addsy)
1956 buf[1] |= (val >> 26) & 0x3f;
1967 case BFD_RELOC_SPARC22:
1968 if (val & ~0x003fffff)
1970 as_bad ("relocation overflow");
1972 buf[1] |= (val >> 16) & 0x3f;
1974 buf[3] = val & 0xff;
1977 case BFD_RELOC_SPARC13:
1978 if (val & ~0x00001fff)
1980 as_bad ("relocation overflow");
1982 buf[2] |= (val >> 8) & 0x1f;
1983 buf[3] = val & 0xff;
1986 /* start-sanitize-v9 */
1988 case BFD_RELOC_SPARC_HM10:
1990 /* intentional fallthrough */
1992 /* end-sanitize-v9 */
1994 case BFD_RELOC_LO10:
1995 if (!fixP->fx_addsy)
1997 buf[2] |= (val >> 8) & 0x03;
2003 case BFD_RELOC_SPARC_BASE13:
2004 if (((val > 0) && (val & ~(offsetT)0x00001fff))
2005 || ((val < 0) && (~(val - 1) & ~(offsetT)0x00001fff)))
2007 as_bad ("relocation overflow");
2009 buf[2] |= (val >> 8) & 0x1f;
2013 case BFD_RELOC_SPARC_WDISP22:
2014 val = (val >>= 2) + 1;
2016 case BFD_RELOC_SPARC_BASE22:
2017 buf[1] |= (val >> 16) & 0x3f;
2022 case BFD_RELOC_NONE:
2024 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2031 /* Translate internal representation of relocation info to BFD target
2034 tc_gen_reloc (section, fixp)
2039 bfd_reloc_code_real_type code;
2041 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2042 assert (reloc != 0);
2044 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2045 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2047 switch (fixp->fx_r_type)
2051 case BFD_RELOC_HI22:
2052 case BFD_RELOC_LO10:
2053 case BFD_RELOC_32_PCREL_S2:
2054 case BFD_RELOC_SPARC_BASE13:
2055 case BFD_RELOC_SPARC_WDISP22:
2056 /* start-sanitize-v9 */
2058 case BFD_RELOC_SPARC_10:
2059 case BFD_RELOC_SPARC_11:
2060 case BFD_RELOC_SPARC_HH22:
2061 case BFD_RELOC_SPARC_HM10:
2062 case BFD_RELOC_SPARC_LM22:
2063 case BFD_RELOC_SPARC_PC_HH22:
2064 case BFD_RELOC_SPARC_PC_HM10:
2065 case BFD_RELOC_SPARC_PC_LM22:
2066 /* end-sanitize-v9 */
2067 code = fixp->fx_r_type;
2072 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2073 assert (reloc->howto != 0);
2074 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
2076 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2077 if (reloc->howto->pc_relative == 0)
2078 reloc->addend = fixp->fx_addnumber;
2080 reloc->addend = fixp->fx_offset - reloc->address;
2087 /* for debugging only */
2090 struct sparc_it *insn;
2092 const char *const Reloc[] = {
2121 fprintf (stderr, "ERROR: %s\n");
2122 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2123 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2124 fprintf (stderr, "exp = {\n");
2125 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2126 ((insn->exp.X_add_symbol != NULL)
2127 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2128 ? S_GET_NAME (insn->exp.X_add_symbol)
2131 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2132 ((insn->exp.X_op_symbol != NULL)
2133 ? (S_GET_NAME (insn->exp.X_op_symbol)
2134 ? S_GET_NAME (insn->exp.X_op_symbol)
2137 fprintf (stderr, "\t\tX_add_number = %d\n",
2138 insn->exp.X_add_number);
2139 fprintf (stderr, "}\n");
2145 * Invocation line includes a switch not recognized by the base assembler.
2146 * See if it's a processor-specific option. These are:
2149 * Warn on architecture bumps. See also -A.
2151 * -Av6, -Av7, -Av8, -Asparclite
2152 * Select the architecture. Instructions or features not
2153 * supported by the selected architecture cause fatal errors.
2155 * The default is to start at v6, and bump the architecture up
2156 * whenever an instruction is seen at a higher level.
2158 * If -bump is specified, a warning is printing when bumping to
2161 * If an architecture is specified, all instructions must match
2162 * that architecture. Any higher level instructions are flagged
2165 * if both an architecture and -bump are specified, the
2166 * architecture starts at the specified level, but bumps are
2171 * Another architecture switch.
2174 * Bumping between incompatible architectures is always an
2175 * error. For example, from sparclite to v9.
2180 md_parse_option (argP, cntP, vecP)
2188 if (!strcmp (*argP, "bump"))
2193 else if (**argP == 'A')
2197 for (arch = architecture_pname; *arch != NULL; ++arch)
2199 if (strcmp (p, *arch) == 0)
2202 } /* found a match */
2203 } /* walk the pname table */
2207 as_bad ("unknown architecture: %s", p);
2211 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2212 architecture_requested = 1;
2216 else if (**argP == 'V')
2218 print_version_id ();
2220 else if (**argP == 'Q')
2222 /* Qy - do emit .comment
2223 Qn - do not emit .comment */
2225 else if (**argP == 's')
2227 /* use .stab instead of .stab.excl */
2230 else if (strcmp (*argP, "sparc") == 0)
2232 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2236 /* Unknown option */
2240 **argP = '\0'; /* Done parsing this switch */
2242 } /* md_parse_option() */
2244 /* We have no need to default values of symbols. */
2248 md_undefined_symbol (name)
2252 } /* md_undefined_symbol() */
2254 /* Parse an operand that is machine-specific.
2255 We just return without modifying the expression if we have nothing
2260 md_operand (expressionP)
2261 expressionS *expressionP;
2265 /* Round up a section size to the appropriate boundary. */
2267 md_section_align (segment, size)
2272 /* Round all sects to multiple of 8 */
2273 size = (size + 7) & (valueT) ~7;
2278 /* Exactly what point is a PC-relative offset relative TO?
2279 On the sparc, they're relative to the address of the offset, plus
2280 its size. This gets us to the following instruction.
2281 (??? Is this right? FIXME-SOON) */
2283 md_pcrel_from (fixP)
2286 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2289 /* end of tc-sparc.c */