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 ();
475 subseg_set (data_section, 1);
476 demand_empty_rest_of_line ();
484 while (!is_end_of_line[(unsigned char) *input_line_pointer])
486 ++input_line_pointer;
488 ++input_line_pointer;
492 /* start-sanitize-v9 */
495 struct priv_reg_entry
501 struct priv_reg_entry priv_reg_table[] =
520 {"", -1}, /* end marker */
530 #define MEMBAR_MASKS_SIZE 7
532 struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
535 {"MemIssue", 8, 0x20},
536 {"Lookaside", 9, 0x10},
537 {"StoreStore", 10, 0x08},
538 {"LoadStore", 9, 0x04},
539 {"StoreLoad", 9, 0x02},
540 {"LoadLoad", 8, 0x01},
545 struct priv_reg_entry *p, *q;
547 return strcmp (q->name, p->name);
551 /* end-sanitize-v9 */
553 /* This function is called once, at assembler startup time. It should
554 set up all the tables, etc. that the MD part of the assembler will need. */
558 register const char *retval = NULL;
560 register unsigned int i = 0;
562 op_hash = hash_new ();
564 as_fatal ("Virtual memory exhausted");
566 while (i < NUMOPCODES)
568 const char *name = sparc_opcodes[i].name;
569 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
572 fprintf (stderr, "internal error: can't hash `%s': %s\n",
573 sparc_opcodes[i].name, retval);
578 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
580 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
581 sparc_opcodes[i].name, sparc_opcodes[i].args);
586 while (i < NUMOPCODES
587 && !strcmp (sparc_opcodes[i].name, name));
591 as_fatal ("Broken assembler. No assembly attempted.");
593 for (i = '0'; i < '8'; ++i)
595 for (i = '0'; i <= '9'; ++i)
597 for (i = 'a'; i <= 'f'; ++i)
598 toHex[i] = i + 10 - 'a';
599 for (i = 'A'; i <= 'F'; ++i)
600 toHex[i] = i + 10 - 'A';
602 /* start-sanitize-v9 */
605 current_architecture = v9;
608 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
609 sizeof (priv_reg_table[0]), cmp_reg_entry);
611 /* end-sanitize-v9 */
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.");
703 char *error_message = "";
707 struct sparc_opcode *insn;
709 unsigned long opcode;
710 unsigned int mask = 0;
713 long immediate_max = 0;
715 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
733 as_bad ("Unknown opcode: `%s'", str);
736 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
738 as_bad ("Unknown opcode: `%s'", str);
748 opcode = insn->match;
749 memset (&the_insn, '\0', sizeof (the_insn));
750 the_insn.reloc = BFD_RELOC_NONE;
753 * Build the opcode, checking as we go to make
754 * sure that the operands match
756 for (args = insn->args;; ++args)
761 /* start-sanitize-v9 */
768 /* Parse a series of masks. */
774 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
775 if (!strncmp (s, membar_masks[i].name,
776 membar_masks[i].len))
778 if (i < MEMBAR_MASKS_SIZE)
780 kmask |= membar_masks[i].mask;
781 s += membar_masks[i].len;
785 error_message = ": invalid membar mask name";
792 else if (isdigit (*s))
796 kmask = strtol (s, &send, 0);
797 if (kmask < 0 || kmask > 127)
799 error_message = ": invalid membar mask number";
806 error_message = ": unrecognizable membar mask";
809 opcode |= SIMM13 (kmask);
815 int prefetch_fcn = 0;
817 /* Parse a prefetch function. */
821 if (!strncmp (s, "n_reads", 7))
822 prefetch_fcn = 0, s += 7;
823 else if (!strncmp (s, "one_read", 8))
824 prefetch_fcn = 1, s += 8;
825 else if (!strncmp (s, "n_writes", 8))
826 prefetch_fcn = 2, s += 8;
827 else if (!strncmp (s, "one_write", 9))
828 prefetch_fcn = 3, s += 9;
829 else if (!strncmp (s, "page", 4))
830 prefetch_fcn = 4, s += 4;
833 error_message = ": invalid prefetch function name";
837 else if (isdigit (*s))
841 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
845 if (prefetch_fcn < 0 || prefetch_fcn > 31)
847 error_message = ": invalid prefetch function number";
853 error_message = ": unrecognizable prefetch function";
856 opcode |= RD (prefetch_fcn);
862 /* Parse a privileged register. */
865 struct priv_reg_entry *p = priv_reg_table;
866 unsigned int len = 9999999; /* init to make gcc happy */
869 while (p->name[0] > s[0])
871 while (p->name[0] == s[0])
873 len = strlen (p->name);
874 if (strncmp (p->name, s, len) == 0)
878 if (p->name[0] != s[0])
880 error_message = ": unrecognizable privileged register";
884 opcode |= (p->regnum << 14);
886 opcode |= (p->regnum << 25);
892 error_message = ": unrecognizable privileged register";
896 /* end-sanitize-v9 */
900 if (strncmp (s, "%asr", 4) == 0)
910 num = num * 10 + *s - '0';
914 if (num < 16 || 31 < num)
916 error_message = ": asr number must be between 15 and 31";
920 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
925 error_message = ": expecting %asrN";
927 } /* if %asr followed by a number. */
932 /* start-sanitize-v9 */
935 the_insn.reloc = BFD_RELOC_SPARC_11;
936 immediate_max = 0x03FF;
940 the_insn.reloc = BFD_RELOC_SPARC_10;
941 immediate_max = 0x01FF;
945 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
950 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
955 if (*s == 'p' && s[1] == 'n')
963 if (*s == 'p' && s[1] == 't')
975 if (strncmp (s, "%icc", 4) == 0)
987 if (strncmp (s, "%xcc", 4) == 0)
999 if (strncmp (s, "%fcc0", 5) == 0)
1011 if (strncmp (s, "%fcc1", 5) == 0)
1023 if (strncmp (s, "%fcc2", 5) == 0)
1035 if (strncmp (s, "%fcc3", 5) == 0)
1043 if (strncmp (s, "%pc", 3) == 0)
1051 if (strncmp (s, "%tick", 5) == 0)
1058 /* end-sanitize-v9 */
1060 case '\0': /* end of args */
1079 case '[': /* these must match exactly */
1087 case '#': /* must be at least one digit */
1090 while (isdigit (*s))
1098 case 'C': /* coprocessor state register */
1099 if (strncmp (s, "%csr", 4) == 0)
1106 case 'b': /* next operand is a coprocessor register */
1109 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1114 mask = 10 * (mask - '0') + (*s++ - '0');
1128 opcode |= mask << 14;
1136 opcode |= mask << 25;
1142 case 'r': /* next operand must be a register */
1151 case 'f': /* frame pointer */
1159 case 'g': /* global register */
1160 if (isoctal (c = *s++))
1167 case 'i': /* in register */
1168 if (isoctal (c = *s++))
1170 mask = c - '0' + 24;
1175 case 'l': /* local register */
1176 if (isoctal (c = *s++))
1178 mask = (c - '0' + 16);
1183 case 'o': /* out register */
1184 if (isoctal (c = *s++))
1186 mask = (c - '0' + 8);
1191 case 's': /* stack pointer */
1199 case 'r': /* any register */
1200 if (!isdigit (c = *s++))
1217 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1233 * Got the register, now figure out where
1234 * it goes in the opcode.
1240 opcode |= mask << 14;
1248 opcode |= mask << 25;
1252 opcode |= (mask << 25) | (mask << 14);
1258 case 'e': /* next operand is a floating point register */
1273 && ((format = *s) == 'f')
1276 for (mask = 0; isdigit (*s); ++s)
1278 mask = 10 * mask + (*s - '0');
1279 } /* read the number */
1287 } /* register must be even numbered */
1295 } /* register must be multiple of 4 */
1297 /* start-sanitize-v9 */
1301 error_message = ": There are only 64 f registers; [0-63]";
1307 } /* wrap high bit */
1309 /* end-sanitize-v9 */
1312 error_message = ": There are only 32 f registers; [0-31]";
1315 /* start-sanitize-v9 */
1317 /* end-sanitize-v9 */
1322 } /* if not an 'f' register. */
1330 opcode |= RS1 (mask);
1337 opcode |= RS2 (mask);
1343 opcode |= RD (mask);
1352 if (strncmp (s, "%fsr", 4) == 0)
1359 case 'h': /* high 22 bits */
1360 the_insn.reloc = BFD_RELOC_HI22;
1363 case 'l': /* 22 bit PC relative immediate */
1364 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1368 case 'L': /* 30 bit immediate */
1369 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1373 case 'n': /* 22 bit immediate */
1374 the_insn.reloc = BFD_RELOC_SPARC22;
1377 case 'i': /* 13 bit immediate */
1378 /* What's the difference between base13 and 13? */
1379 the_insn.reloc = BFD_RELOC_SPARC_BASE13;
1380 immediate_max = 0x0FFF;
1389 if ((c = s[1]) == 'h' && s[2] == 'i')
1391 the_insn.reloc = BFD_RELOC_HI22;
1394 else if (c == 'l' && s[2] == 'o')
1396 the_insn.reloc = BFD_RELOC_LO10;
1399 /* start-sanitize-v9 */
1405 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1412 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1416 /* end-sanitize-v9 */
1420 /* Note that if the getExpression() fails, we will still
1421 have created U entries in the symbol table for the
1422 'symbols' in the input string. Try not to create U
1423 symbols for registers, etc. */
1425 /* This stuff checks to see if the expression ends in
1426 +%reg. If it does, it removes the register from
1427 the expression, and re-sets 's' to point to the
1432 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1434 if (s1 != s && isdigit (s1[-1]))
1436 if (s1[-2] == '%' && s1[-3] == '+')
1440 (void) getExpression (s);
1445 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1449 (void) getExpression (s);
1456 (void) getExpression (s);
1459 if (the_insn.exp.X_op == O_constant
1460 && the_insn.exp.X_add_symbol == 0
1461 && the_insn.exp.X_op_symbol == 0)
1463 /* start-sanitize-v9 */
1465 switch (the_insn.reloc)
1467 case BFD_RELOC_SPARC_HH22:
1468 the_insn.reloc = BFD_RELOC_HI22;
1469 the_insn.exp.X_add_number >>= 32;
1471 case BFD_RELOC_SPARC_HM10:
1472 the_insn.reloc = BFD_RELOC_LO10;
1473 the_insn.exp.X_add_number >>= 32;
1477 /* end-sanitize-v9 */
1478 /* Check for invalid constant values. Don't warn if
1479 constant was inside %hi or %lo, since these
1480 truncate the constant to fit. */
1481 if (immediate_max != 0
1482 && the_insn.reloc != BFD_RELOC_LO10
1483 && the_insn.reloc != BFD_RELOC_HI22
1484 && (the_insn.exp.X_add_number > immediate_max
1485 || the_insn.exp.X_add_number < ~immediate_max))
1486 as_bad ("constant value must be between %ld and %ld",
1487 ~immediate_max, immediate_max);
1490 /* Reset to prevent extraneous range check. */
1505 /* start-sanitize-v9 */
1507 /* end-sanitize-v9 */
1508 char *push = input_line_pointer;
1511 input_line_pointer = s;
1514 if (e.X_op == O_constant)
1516 opcode |= e.X_add_number << 5;
1517 s = input_line_pointer;
1518 input_line_pointer = push;
1523 /* start-sanitize-v9 */
1531 if (!strncmp (s, "ASI_AIUP", 8))
1533 else if (!strncmp (s, "ASI_AIUS", 8))
1535 else if (!strncmp (s, "ASI_PNF", 7))
1537 else if (!strncmp (s, "ASI_SNF", 7))
1539 else if (!strncmp (s, "ASI_P", 5))
1541 else if (!strncmp (s, "ASI_S", 5))
1545 error_message = ": invalid asi name";
1549 else if (isdigit (*s))
1551 char *push = input_line_pointer;
1552 input_line_pointer = s;
1553 asi = get_absolute_expression ();
1554 s = input_line_pointer;
1555 input_line_pointer = push;
1557 if (asi < 0 || asi > 255)
1559 error_message = ": invalid asi number";
1565 error_message = ": unrecognizable asi";
1568 opcode |= ASI (asi);
1571 /* end-sanitize-v9 */
1572 } /* alternate space */
1575 if (strncmp (s, "%psr", 4) == 0)
1582 case 'q': /* floating point queue */
1583 if (strncmp (s, "%fq", 3) == 0)
1590 case 'Q': /* coprocessor queue */
1591 if (strncmp (s, "%cq", 3) == 0)
1599 if (strcmp (str, "set") == 0)
1601 special_case = SPECIAL_CASE_SET;
1604 else if (strncmp (str, "fdiv", 4) == 0)
1606 special_case = SPECIAL_CASE_FDIV;
1611 /* start-sanitize-v9 */
1614 if (strncmp (s, "%asi", 4) != 0)
1620 if (strncmp (s, "%fprs", 5) != 0)
1626 if (strncmp (s, "%ccr", 4) != 0)
1631 /* end-sanitize-v9 */
1634 if (strncmp (s, "%tbr", 4) != 0)
1640 if (strncmp (s, "%wim", 4) != 0)
1646 if (strncmp (s, "%y", 2) != 0)
1652 as_fatal ("failed sanity check.");
1653 } /* switch on arg code */
1655 } /* for each arg that we expect */
1659 /* Args don't match. */
1660 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1661 && !strcmp (insn->name, insn[1].name))
1669 as_bad ("Illegal operands%s", error_message);
1675 if (insn->architecture > current_architecture)
1677 if ((!architecture_requested || warn_on_bump)
1679 /* start-sanitize-v9 */
1681 !ARCHITECTURES_CONFLICT_P (current_architecture,
1684 /* end-sanitize-v9 */
1686 /* start-sanitize-v9 */
1688 /* end-sanitize-v9 */
1693 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1694 architecture_pname[current_architecture],
1695 architecture_pname[insn->architecture],
1699 current_architecture = insn->architecture;
1703 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1705 architecture_pname[insn->architecture],
1706 architecture_pname[current_architecture]);
1708 } /* if bump ok else error */
1709 } /* if architecture higher */
1713 } /* forever looking for a match */
1715 the_insn.opcode = opcode;
1726 save_in = input_line_pointer;
1727 input_line_pointer = str;
1728 seg = expression (&the_insn.exp);
1729 if (seg != absolute_section
1730 && seg != text_section
1731 && seg != data_section
1732 && seg != bss_section
1733 && seg != undefined_section)
1735 the_insn.error = "bad segment";
1736 expr_end = input_line_pointer;
1737 input_line_pointer = save_in;
1740 expr_end = input_line_pointer;
1741 input_line_pointer = save_in;
1743 } /* getExpression() */
1747 This is identical to the md_atof in m68k.c. I think this is right,
1750 Turn a string in input_line_pointer into a floating point constant of type
1751 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1752 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1755 /* Equal to MAX_PRECISION in atof-ieee.c */
1756 #define MAX_LITTLENUMS 6
1759 md_atof (type, litP, sizeP)
1765 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1766 LITTLENUM_TYPE *wordP;
1799 return "Bad call to MD_ATOF()";
1801 t = atof_ieee (input_line_pointer, type, words);
1803 input_line_pointer = t;
1804 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1805 for (wordP = words; prec--;)
1807 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1808 litP += sizeof (LITTLENUM_TYPE);
1814 * Write out big-endian.
1817 md_number_to_chars (buf, val, n)
1825 /* start-sanitize-v9 */
1831 /* end-sanitize-v9 */
1842 as_fatal ("failed sanity check.");
1845 } /* md_number_to_chars() */
1847 /* Apply a fixS to the frags, now that we know the value it ought to
1851 md_apply_fix (fixP, value)
1855 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1860 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1862 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1865 /* FIXME: SPARC ELF relocations don't use an addend in the data
1866 field itself. This whole approach should be somehow combined
1867 with the calls to bfd_perform_relocation. */
1868 if (fixP->fx_addsy != NULL)
1873 * This is a hack. There should be a better way to
1876 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1878 val += fixP->fx_where + fixP->fx_frag->fr_address;
1881 switch (fixP->fx_r_type)
1896 case BFD_RELOC_32_PCREL_S2:
1897 val = (val >>= 2) + 1;
1898 buf[0] |= (val >> 24) & 0x3f;
1899 buf[1] = (val >> 16);
1904 /* start-sanitize-v9 */
1917 case BFD_RELOC_SPARC_11:
1918 if (((val > 0) && (val & ~0x7ff))
1919 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1921 as_bad ("relocation overflow.");
1924 buf[2] |= (val >> 8) & 0x7;
1925 buf[3] = val & 0xff;
1928 case BFD_RELOC_SPARC_10:
1929 if (((val > 0) && (val & ~0x3ff))
1930 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1932 as_bad ("relocation overflow.");
1935 buf[2] |= (val >> 8) & 0x3;
1936 buf[3] = val & 0xff;
1939 case BFD_RELOC_SPARC_WDISP16:
1940 if (((val > 0) && (val & ~0x3fffc))
1941 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1943 as_bad ("relocation overflow.");
1946 val = (val >>= 2) + 1;
1947 buf[1] |= ((val >> 14) & 0x3) << 4;
1948 buf[2] |= (val >> 8) & 0x3f;
1949 buf[3] = val & 0xff;
1952 case BFD_RELOC_SPARC_WDISP19:
1953 if (((val > 0) && (val & ~0x1ffffc))
1954 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1956 as_bad ("relocation overflow.");
1959 val = (val >>= 2) + 1;
1960 buf[1] |= (val >> 16) & 0x7;
1961 buf[2] = (val >> 8) & 0xff;
1962 buf[3] = val & 0xff;
1965 case BFD_RELOC_SPARC_HH22:
1967 /* intentional fallthrough */
1969 /* end-sanitize-v9 */
1971 /* start-sanitize-v9 */
1973 case BFD_RELOC_SPARC_LM22:
1975 /* end-sanitize-v9 */
1976 case BFD_RELOC_HI22:
1977 if (!fixP->fx_addsy)
1979 buf[1] |= (val >> 26) & 0x3f;
1990 case BFD_RELOC_SPARC22:
1991 if (val & ~0x003fffff)
1993 as_bad ("relocation overflow");
1995 buf[1] |= (val >> 16) & 0x3f;
1997 buf[3] = val & 0xff;
2000 case BFD_RELOC_SPARC13:
2001 if (val & ~0x00001fff)
2003 as_bad ("relocation overflow");
2005 buf[2] |= (val >> 8) & 0x1f;
2006 buf[3] = val & 0xff;
2009 /* start-sanitize-v9 */
2011 case BFD_RELOC_SPARC_HM10:
2013 /* intentional fallthrough */
2015 /* end-sanitize-v9 */
2017 case BFD_RELOC_LO10:
2018 if (!fixP->fx_addsy)
2020 buf[2] |= (val >> 8) & 0x03;
2026 case BFD_RELOC_SPARC_BASE13:
2027 if (((val > 0) && (val & ~(offsetT)0x00001fff))
2028 || ((val < 0) && (~(val - 1) & ~(offsetT)0x00001fff)))
2030 as_bad ("relocation overflow");
2032 buf[2] |= (val >> 8) & 0x1f;
2036 case BFD_RELOC_SPARC_WDISP22:
2037 val = (val >>= 2) + 1;
2039 case BFD_RELOC_SPARC_BASE22:
2040 buf[1] |= (val >> 16) & 0x3f;
2045 case BFD_RELOC_NONE:
2047 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2054 /* should never be called for sparc */
2056 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2063 as_fatal ("sparc_create_short_jmp\n");
2066 /* Translate internal representation of relocation info to BFD target
2069 tc_gen_reloc (section, fixp)
2074 bfd_reloc_code_real_type code;
2076 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2077 assert (reloc != 0);
2079 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2080 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2082 if (fixp->fx_pcrel == 0)
2083 reloc->addend += fixp->fx_addnumber;
2086 reloc->addend += fixp->fx_offset;
2087 switch (OUTPUT_FLAVOR)
2089 case bfd_target_elf_flavour:
2091 case bfd_target_aout_flavour:
2092 reloc->addend -= reloc->address;
2095 /* What's a good default here? Is there any?? */
2100 switch (fixp->fx_r_type)
2104 case BFD_RELOC_HI22:
2105 case BFD_RELOC_LO10:
2106 case BFD_RELOC_32_PCREL_S2:
2107 case BFD_RELOC_SPARC_BASE13:
2108 case BFD_RELOC_SPARC_WDISP22:
2109 /* start-sanitize-v9 */
2111 case BFD_RELOC_SPARC_10:
2112 case BFD_RELOC_SPARC_11:
2113 case BFD_RELOC_SPARC_HH22:
2114 case BFD_RELOC_SPARC_HM10:
2115 case BFD_RELOC_SPARC_LM22:
2116 case BFD_RELOC_SPARC_PC_HH22:
2117 case BFD_RELOC_SPARC_PC_HM10:
2118 case BFD_RELOC_SPARC_PC_LM22:
2119 /* end-sanitize-v9 */
2120 code = fixp->fx_r_type;
2125 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2126 assert (reloc->howto != 0);
2131 /* should never be called for sparc */
2133 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2135 addressT from_addr, to_addr;
2139 as_fatal ("sparc_create_long_jump\n");
2140 } /* md_create_long_jump() */
2142 /* should never be called for sparc */
2144 md_estimate_size_before_relax (fragP, segtype)
2148 as_fatal ("sparc_estimate_size_before_relax\n");
2150 } /* md_estimate_size_before_relax() */
2153 /* for debugging only */
2156 struct sparc_it *insn;
2189 fprintf (stderr, "ERROR: %s\n");
2191 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2192 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2193 fprintf (stderr, "exp = {\n");
2194 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2195 ((insn->exp.X_add_symbol != NULL)
2196 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2197 ? S_GET_NAME (insn->exp.X_add_symbol)
2200 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2201 ((insn->exp.X_op_symbol != NULL)
2202 ? (S_GET_NAME (insn->exp.X_op_symbol)
2203 ? S_GET_NAME (insn->exp.X_op_symbol)
2206 fprintf (stderr, "\t\tX_add_number = %d\n",
2207 insn->exp.X_add_number);
2208 fprintf (stderr, "}\n");
2210 } /* print_insn() */
2216 * Invocation line includes a switch not recognized by the base assembler.
2217 * See if it's a processor-specific option. These are:
2220 * Warn on architecture bumps. See also -A.
2222 * -Av6, -Av7, -Av8, -Asparclite
2223 * Select the architecture. Instructions or features not
2224 * supported by the selected architecture cause fatal errors.
2226 * The default is to start at v6, and bump the architecture up
2227 * whenever an instruction is seen at a higher level.
2229 * If -bump is specified, a warning is printing when bumping to
2232 * If an architecture is specified, all instructions must match
2233 * that architecture. Any higher level instructions are flagged
2236 * if both an architecture and -bump are specified, the
2237 * architecture starts at the specified level, but bumps are
2242 * Another architecture switch.
2245 * Bumping between incompatible architectures is always an
2246 * error. For example, from sparclite to v9.
2251 md_parse_option (argP, cntP, vecP)
2259 if (!strcmp (*argP, "bump"))
2264 else if (**argP == 'A')
2268 for (arch = architecture_pname; *arch != NULL; ++arch)
2270 if (strcmp (p, *arch) == 0)
2273 } /* found a match */
2274 } /* walk the pname table */
2278 as_bad ("unknown architecture: %s", p);
2282 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2283 architecture_requested = 1;
2287 else if (**argP == 'V')
2289 print_version_id ();
2291 else if (**argP == 'Q')
2293 /* Qy - do emit .comment
2294 Qn - do not emit .comment */
2296 else if (**argP == 's')
2298 /* use .stab instead of .stab.excl */
2301 else if (strcmp (*argP, "sparc") == 0)
2303 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2307 /* Unknown option */
2311 **argP = '\0'; /* Done parsing this switch */
2313 } /* md_parse_option() */
2315 /* We have no need to default values of symbols. */
2319 md_undefined_symbol (name)
2323 } /* md_undefined_symbol() */
2325 /* Parse an operand that is machine-specific.
2326 We just return without modifying the expression if we have nothing
2331 md_operand (expressionP)
2332 expressionS *expressionP;
2336 /* Round up a section size to the appropriate boundary. */
2338 md_section_align (segment, size)
2343 /* Round all sects to multiple of 8 */
2344 size = (size + 7) & (valueT) ~7;
2349 /* Exactly what point is a PC-relative offset relative TO?
2350 On the sparc, they're relative to the address of the offset, plus
2351 its size. This gets us to the following instruction.
2352 (??? Is this right? FIXME-SOON) */
2354 md_pcrel_from (fixP)
2357 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2360 /* end of tc-sparc.c */