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. */
28 /* careful, this file includes data *declarations* */
29 #include "opcode/sparc.h"
31 static void sparc_ip PARAMS ((char *));
33 static enum sparc_architecture current_architecture = v6;
34 static int architecture_requested;
35 static int warn_on_bump;
37 extern int target_big_endian;
39 const relax_typeS md_relax_table[1];
41 /* handle of the OPCODE hash table */
42 static struct hash_control *op_hash = NULL;
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},
62 /* start-sanitize-v9 */
71 /* these are specific to sparc/svr4 */
72 {"pushsection", obj_elf_section, 0},
73 {"popsection", obj_elf_previous, 0},
80 const int md_short_jump_size = 4;
81 const int md_long_jump_size = 4;
82 const int md_reloc_size = 12; /* Size of relocation record */
84 /* This array holds the chars that always start a comment. If the
85 pre-processor is disabled, these aren't very useful */
86 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
88 /* This array holds the chars that only start a comment at the beginning of
89 a line. If the line seems to have the form '# 123 filename'
90 .line and .file directives will appear in the pre-processed output */
91 /* Note that input_file.c hand checks for '#' at the beginning of the
92 first line of the input file. This is because the compiler outputs
93 #NO_APP at the beginning of its output. */
94 /* Also note that comments started like this one will always
95 work if '/' isn't otherwise defined. */
96 const char line_comment_chars[] = "#";
98 const char line_separator_chars[] = "";
100 /* Chars that can be used to separate mant from exp in floating point nums */
101 const char EXP_CHARS[] = "eE";
103 /* Chars that mean this number is a floating point constant */
106 const char FLT_CHARS[] = "rRsSfFdDxXpP";
108 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
109 changed in read.c. Ideally it shouldn't have to know about it at all,
110 but nothing is ideal around here. */
112 static unsigned char octal[256];
113 #define isoctal(c) octal[(unsigned char) (c)]
114 static unsigned char toHex[256];
119 unsigned long opcode;
120 struct nlist *nlistp;
123 bfd_reloc_code_real_type reloc;
126 struct sparc_it the_insn, set_insn;
129 in_signed_range (val, max)
130 bfd_signed_vma val, max;
142 static void print_insn PARAMS ((struct sparc_it *insn));
144 static int getExpression PARAMS ((char *str));
146 static char *expr_end;
147 static int special_case;
150 * Instructions that require wierd handling because they're longer than
153 #define SPECIAL_CASE_SET 1
154 #define SPECIAL_CASE_FDIV 2
157 * sort of like s_lcomm
161 static int max_alignment = 15;
176 name = input_line_pointer;
177 c = get_symbol_end ();
178 p = input_line_pointer;
182 if (*input_line_pointer != ',')
184 as_bad ("Expected comma after name");
185 ignore_rest_of_line ();
189 ++input_line_pointer;
191 if ((size = get_absolute_expression ()) < 0)
193 as_bad ("BSS length (%d.) <0! Ignored.", size);
194 ignore_rest_of_line ();
199 symbolP = symbol_find_or_make (name);
202 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
203 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
205 as_bad ("bad .reserve segment -- expected BSS segment", input_line_pointer);
209 if (input_line_pointer[2] == '.')
210 input_line_pointer += 7;
212 input_line_pointer += 6;
215 if (*input_line_pointer == ',')
217 ++input_line_pointer;
220 if (*input_line_pointer == '\n')
222 as_bad ("Missing alignment");
226 align = get_absolute_expression ();
228 if (align > max_alignment)
230 align = max_alignment;
231 as_warn ("Alignment too large: %d. assumed.", align);
237 as_warn ("Alignment negative. 0 assumed.");
240 record_alignment (bss_section, align);
242 /* convert to a power of 2 alignment */
243 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
247 as_bad ("Alignment not a power of 2");
248 ignore_rest_of_line ();
250 } /* not a power of two */
253 } /* if has optional alignment */
257 if ((S_GET_SEGMENT (symbolP) == bss_section
258 || !S_IS_DEFINED (symbolP))
260 && S_GET_OTHER (symbolP) == 0
261 && S_GET_DESC (symbolP) == 0
268 segT current_seg = now_seg;
269 subsegT current_subseg = now_subseg;
271 subseg_set (bss_section, 1); /* switch to bss */
274 frag_align (align, 0); /* do alignment */
276 /* detach from old frag */
277 if (S_GET_SEGMENT(symbolP) == bss_section)
278 symbolP->sy_frag->fr_symbol = NULL;
280 symbolP->sy_frag = frag_now;
281 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
285 S_SET_SEGMENT (symbolP, bss_section);
287 subseg_set (current_seg, current_subseg);
292 as_warn("Ignoring attempt to re-define symbol %s.", name);
293 } /* if not redefining */
295 demand_empty_rest_of_line ();
308 name = input_line_pointer;
309 c = get_symbol_end ();
310 /* just after name is now '\0' */
311 p = input_line_pointer;
314 if (*input_line_pointer != ',')
316 as_bad ("Expected comma after symbol-name");
317 ignore_rest_of_line ();
320 input_line_pointer++; /* skip ',' */
321 if ((temp = get_absolute_expression ()) < 0)
323 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
324 ignore_rest_of_line ();
329 symbolP = symbol_find_or_make (name);
331 if (S_IS_DEFINED (symbolP))
333 as_bad ("Ignoring attempt to re-define symbol");
334 ignore_rest_of_line ();
337 if (S_GET_VALUE (symbolP) != 0)
339 if (S_GET_VALUE (symbolP) != size)
341 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
342 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
348 S_SET_VALUE (symbolP, (valueT) size);
349 S_SET_EXTERNAL (symbolP);
352 know (symbolP->sy_frag == &zero_address_frag);
353 if (*input_line_pointer != ',')
355 as_bad ("Expected comma after common length");
356 ignore_rest_of_line ();
359 input_line_pointer++;
361 if (*input_line_pointer != '"')
363 temp = get_absolute_expression ();
365 if (temp > max_alignment)
367 temp = max_alignment;
368 as_warn ("Common alignment too large: %d. assumed", temp);
374 as_warn ("Common alignment negative; 0 assumed");
386 old_subsec = now_subseg;
388 record_alignment (bss_section, align);
389 subseg_set (bss_section, 0);
391 frag_align (align, 0);
392 if (S_GET_SEGMENT (symbolP) == bss_section)
393 symbolP->sy_frag->fr_symbol = 0;
394 symbolP->sy_frag = frag_now;
395 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
398 S_SET_SEGMENT (symbolP, bss_section);
399 S_CLEAR_EXTERNAL (symbolP);
400 subseg_set (old_sec, old_subsec);
406 S_SET_VALUE (symbolP, (valueT) size);
407 S_SET_EXTERNAL (symbolP);
408 /* should be common, but this is how gas does it for now */
409 S_SET_SEGMENT (symbolP, &bfd_und_section);
414 input_line_pointer++;
415 /* @@ Some use the dot, some don't. Can we get some consistency?? */
416 if (*input_line_pointer == '.')
417 input_line_pointer++;
418 /* @@ Some say data, some say bss. */
419 if (strncmp (input_line_pointer, "bss\"", 4)
420 && strncmp (input_line_pointer, "data\"", 5))
422 while (*--input_line_pointer != '"')
424 input_line_pointer--;
425 goto bad_common_segment;
427 while (*input_line_pointer++ != '"')
429 goto allocate_common;
431 demand_empty_rest_of_line ();
436 p = input_line_pointer;
437 while (*p && *p != '\n')
441 as_bad ("bad .common segment %s", input_line_pointer + 1);
443 input_line_pointer = p;
444 ignore_rest_of_line ();
454 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
456 input_line_pointer += 6;
460 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
462 input_line_pointer += 6;
466 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
468 input_line_pointer += 7;
472 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
474 input_line_pointer += 5;
475 /* We only support 2 segments -- text and data -- for now, so
476 things in the "bss segment" will have to go into data for now.
477 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
478 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
481 as_bad ("Unknown segment type");
482 demand_empty_rest_of_line ();
488 subseg_set (data_section, 1);
489 demand_empty_rest_of_line ();
496 while (!is_end_of_line[(unsigned char) *input_line_pointer])
498 ++input_line_pointer;
500 ++input_line_pointer;
503 /* start-sanitize-v9 */
506 struct priv_reg_entry
512 struct priv_reg_entry priv_reg_table[] =
531 {"", -1}, /* end marker */
541 #define MEMBAR_MASKS_SIZE 7
543 struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
546 {"MemIssue", 8, 0x20},
547 {"Lookaside", 9, 0x10},
548 {"StoreStore", 10, 0x08},
549 {"LoadStore", 9, 0x04},
550 {"StoreLoad", 9, 0x02},
551 {"LoadLoad", 8, 0x01},
556 struct priv_reg_entry *p, *q;
558 return strcmp (q->name, p->name);
562 /* end-sanitize-v9 */
564 /* This function is called once, at assembler startup time. It should
565 set up all the tables, etc. that the MD part of the assembler will need. */
569 register const char *retval = NULL;
571 register unsigned int i = 0;
573 op_hash = hash_new ();
575 while (i < NUMOPCODES)
577 const char *name = sparc_opcodes[i].name;
578 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
581 fprintf (stderr, "internal error: can't hash `%s': %s\n",
582 sparc_opcodes[i].name, retval);
587 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
589 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
590 sparc_opcodes[i].name, sparc_opcodes[i].args);
595 while (i < NUMOPCODES
596 && !strcmp (sparc_opcodes[i].name, name));
600 as_fatal ("Broken assembler. No assembly attempted.");
602 for (i = '0'; i < '8'; ++i)
604 for (i = '0'; i <= '9'; ++i)
606 for (i = 'a'; i <= 'f'; ++i)
607 toHex[i] = i + 10 - 'a';
608 for (i = 'A'; i <= 'F'; ++i)
609 toHex[i] = i + 10 - 'A';
611 /* start-sanitize-v9 */
614 current_architecture = v9;
617 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
618 sizeof (priv_reg_table[0]), cmp_reg_entry);
620 /* end-sanitize-v9 */
622 target_big_endian = 1;
635 /* See if "set" operand is absolute and small; skip sethi if so. */
636 if (special_case == SPECIAL_CASE_SET
637 && the_insn.exp.X_op == O_constant)
639 if (the_insn.exp.X_add_number >= -(1 << 12)
640 && the_insn.exp.X_add_number < (1 << 12))
642 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
643 | (the_insn.opcode & 0x3E000000) /* dest reg */
644 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
645 special_case = 0; /* No longer special */
646 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
651 /* put out the opcode */
652 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
654 /* put out the symbol-dependent stuff */
655 if (the_insn.reloc != BFD_RELOC_NONE)
657 fix_new_exp (frag_now, /* which frag */
658 (toP - frag_now->fr_literal), /* where */
665 switch (special_case)
667 case SPECIAL_CASE_SET:
669 assert (the_insn.reloc == BFD_RELOC_HI22);
670 /* See if "set" operand has no low-order bits; skip OR if so. */
671 if (the_insn.exp.X_op == O_constant
672 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
675 rsd = (the_insn.opcode >> 25) & 0x1f;
676 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
677 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
678 fix_new_exp (frag_now, /* which frag */
679 (toP - frag_now->fr_literal), /* where */
686 case SPECIAL_CASE_FDIV:
687 /* According to information leaked from Sun, the "fdiv" instructions
688 on early SPARC machines would produce incorrect results sometimes.
689 The workaround is to add an fmovs of the destination register to
690 itself just after the instruction. This was true on machines
691 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
693 assert (the_insn.reloc == BFD_RELOC_NONE);
695 rsd = (the_insn.opcode >> 25) & 0x1f;
696 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
697 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
704 as_fatal ("failed sanity check.");
712 char *error_message = "";
716 struct sparc_opcode *insn;
718 unsigned long opcode;
719 unsigned int mask = 0;
722 long immediate_max = 0;
724 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
742 as_bad ("Unknown opcode: `%s'", str);
745 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
747 as_bad ("Unknown opcode: `%s'", str);
757 opcode = insn->match;
758 memset (&the_insn, '\0', sizeof (the_insn));
759 the_insn.reloc = BFD_RELOC_NONE;
762 * Build the opcode, checking as we go to make
763 * sure that the operands match
765 for (args = insn->args;; ++args)
770 /* start-sanitize-v9 */
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";
912 /* end-sanitize-v9 */
916 if (strncmp (s, "%asr", 4) == 0)
926 num = num * 10 + *s - '0';
930 if (num < 16 || 31 < num)
932 error_message = ": asr number must be between 15 and 31";
936 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
941 error_message = ": expecting %asrN";
943 } /* if %asr followed by a number. */
948 /* start-sanitize-v9 */
951 the_insn.reloc = BFD_RELOC_SPARC_11;
952 immediate_max = 0x03FF;
956 the_insn.reloc = BFD_RELOC_SPARC_10;
957 immediate_max = 0x01FF;
961 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
966 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
971 if (*s == 'p' && s[1] == 'n')
979 if (*s == 'p' && s[1] == 't')
991 if (strncmp (s, "%icc", 4) == 0)
1003 if (strncmp (s, "%xcc", 4) == 0)
1015 if (strncmp (s, "%fcc0", 5) == 0)
1027 if (strncmp (s, "%fcc1", 5) == 0)
1039 if (strncmp (s, "%fcc2", 5) == 0)
1051 if (strncmp (s, "%fcc3", 5) == 0)
1059 if (strncmp (s, "%pc", 3) == 0)
1067 if (strncmp (s, "%tick", 5) == 0)
1074 /* end-sanitize-v9 */
1076 case '\0': /* end of args */
1095 case '[': /* these must match exactly */
1103 case '#': /* must be at least one digit */
1106 while (isdigit (*s))
1114 case 'C': /* coprocessor state register */
1115 if (strncmp (s, "%csr", 4) == 0)
1122 case 'b': /* next operand is a coprocessor register */
1125 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1130 mask = 10 * (mask - '0') + (*s++ - '0');
1144 opcode |= mask << 14;
1152 opcode |= mask << 25;
1158 case 'r': /* next operand must be a register */
1167 case 'f': /* frame pointer */
1175 case 'g': /* global register */
1176 if (isoctal (c = *s++))
1183 case 'i': /* in register */
1184 if (isoctal (c = *s++))
1186 mask = c - '0' + 24;
1191 case 'l': /* local register */
1192 if (isoctal (c = *s++))
1194 mask = (c - '0' + 16);
1199 case 'o': /* out register */
1200 if (isoctal (c = *s++))
1202 mask = (c - '0' + 8);
1207 case 's': /* stack pointer */
1215 case 'r': /* any register */
1216 if (!isdigit (c = *s++))
1233 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1249 * Got the register, now figure out where
1250 * it goes in the opcode.
1256 opcode |= mask << 14;
1264 opcode |= mask << 25;
1268 opcode |= (mask << 25) | (mask << 14);
1274 case 'e': /* next operand is a floating point register */
1289 && ((format = *s) == 'f')
1292 for (mask = 0; isdigit (*s); ++s)
1294 mask = 10 * mask + (*s - '0');
1295 } /* read the number */
1303 } /* register must be even numbered */
1311 } /* register must be multiple of 4 */
1313 /* start-sanitize-v9 */
1317 error_message = ": There are only 64 f registers; [0-63]";
1323 } /* wrap high bit */
1325 /* end-sanitize-v9 */
1328 error_message = ": There are only 32 f registers; [0-31]";
1331 /* start-sanitize-v9 */
1333 /* end-sanitize-v9 */
1338 } /* if not an 'f' register. */
1346 opcode |= RS1 (mask);
1353 opcode |= RS2 (mask);
1359 opcode |= RD (mask);
1368 if (strncmp (s, "%fsr", 4) == 0)
1375 case 'h': /* high 22 bits */
1376 the_insn.reloc = BFD_RELOC_HI22;
1379 case 'l': /* 22 bit PC relative immediate */
1380 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1384 case 'L': /* 30 bit immediate */
1385 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1389 case 'n': /* 22 bit immediate */
1390 the_insn.reloc = BFD_RELOC_SPARC22;
1393 case 'i': /* 13 bit immediate */
1394 the_insn.reloc = BFD_RELOC_SPARC13;
1395 immediate_max = 0x0FFF;
1404 if ((c = s[1]) == 'h' && s[2] == 'i')
1406 the_insn.reloc = BFD_RELOC_HI22;
1409 else if (c == 'l' && s[2] == 'o')
1411 the_insn.reloc = BFD_RELOC_LO10;
1414 /* start-sanitize-v9 */
1420 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1427 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1431 /* end-sanitize-v9 */
1435 /* Note that if the getExpression() fails, we will still
1436 have created U entries in the symbol table for the
1437 'symbols' in the input string. Try not to create U
1438 symbols for registers, etc. */
1440 /* This stuff checks to see if the expression ends in
1441 +%reg. If it does, it removes the register from
1442 the expression, and re-sets 's' to point to the
1447 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1449 if (s1 != s && isdigit (s1[-1]))
1451 if (s1[-2] == '%' && s1[-3] == '+')
1455 (void) getExpression (s);
1460 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1464 (void) getExpression (s);
1471 (void) getExpression (s);
1474 if (the_insn.exp.X_op == O_constant
1475 && the_insn.exp.X_add_symbol == 0
1476 && the_insn.exp.X_op_symbol == 0)
1478 /* start-sanitize-v9 */
1480 /* Handle %uhi/%ulo by moving the upper word to the lower
1481 one and pretending it's %hi/%lo. We also need to watch
1482 for %hi/%lo: the top word needs to be zeroed otherwise
1483 fixup_segment will complain the value is too big. */
1484 switch (the_insn.reloc)
1486 case BFD_RELOC_SPARC_HH22:
1487 the_insn.reloc = BFD_RELOC_HI22;
1488 the_insn.exp.X_add_number >>= 32;
1490 case BFD_RELOC_SPARC_HM10:
1491 the_insn.reloc = BFD_RELOC_LO10;
1492 the_insn.exp.X_add_number >>= 32;
1496 case BFD_RELOC_HI22:
1497 case BFD_RELOC_LO10:
1498 the_insn.exp.X_add_number &= 0xffffffff;
1502 /* end-sanitize-v9 */
1503 /* For pc-relative call instructions, we reject
1504 constants to get better code. */
1506 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
1507 && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
1510 error_message = ": PC-relative operand can't be a constant";
1513 /* Check for invalid constant values. Don't warn if
1514 constant was inside %hi or %lo, since these
1515 truncate the constant to fit. */
1516 if (immediate_max != 0
1517 && the_insn.reloc != BFD_RELOC_LO10
1518 && the_insn.reloc != BFD_RELOC_HI22
1519 && !in_signed_range (the_insn.exp.X_add_number,
1524 /* Who knows? After relocation, we may be within
1525 range. Let the linker figure it out. */
1527 the_insn.exp.X_op = O_symbol;
1528 the_insn.exp.X_add_symbol = section_symbol (absolute_section);
1531 /* Immediate value is non-pcrel, and out of
1533 as_bad ("constant value %ld out of range (%ld .. %ld)",
1534 the_insn.exp.X_add_number,
1535 ~immediate_max, immediate_max);
1539 /* Reset to prevent extraneous range check. */
1554 /* start-sanitize-v9 */
1556 /* end-sanitize-v9 */
1557 char *push = input_line_pointer;
1560 input_line_pointer = s;
1563 if (e.X_op == O_constant)
1565 opcode |= e.X_add_number << 5;
1566 s = input_line_pointer;
1567 input_line_pointer = push;
1572 /* start-sanitize-v9 */
1580 if (!strncmp (s, "ASI_AIUP", 8))
1582 else if (!strncmp (s, "ASI_AIUS", 8))
1584 else if (!strncmp (s, "ASI_PNF", 7))
1586 else if (!strncmp (s, "ASI_SNF", 7))
1588 else if (!strncmp (s, "ASI_P", 5))
1590 else if (!strncmp (s, "ASI_S", 5))
1594 error_message = ": invalid asi name";
1598 else if (isdigit (*s))
1600 char *push = input_line_pointer;
1601 input_line_pointer = s;
1602 asi = get_absolute_expression ();
1603 s = input_line_pointer;
1604 input_line_pointer = push;
1606 if (asi < 0 || asi > 255)
1608 error_message = ": invalid asi number";
1614 error_message = ": unrecognizable asi";
1617 opcode |= ASI (asi);
1620 /* end-sanitize-v9 */
1621 } /* alternate space */
1624 if (strncmp (s, "%psr", 4) == 0)
1631 case 'q': /* floating point queue */
1632 if (strncmp (s, "%fq", 3) == 0)
1639 case 'Q': /* coprocessor queue */
1640 if (strncmp (s, "%cq", 3) == 0)
1648 if (strcmp (str, "set") == 0)
1650 special_case = SPECIAL_CASE_SET;
1653 else if (strncmp (str, "fdiv", 4) == 0)
1655 special_case = SPECIAL_CASE_FDIV;
1660 /* start-sanitize-v9 */
1663 if (strncmp (s, "%asi", 4) != 0)
1669 if (strncmp (s, "%fprs", 5) != 0)
1675 if (strncmp (s, "%ccr", 4) != 0)
1680 /* end-sanitize-v9 */
1683 if (strncmp (s, "%tbr", 4) != 0)
1689 if (strncmp (s, "%wim", 4) != 0)
1695 if (strncmp (s, "%y", 2) != 0)
1701 as_fatal ("failed sanity check.");
1702 } /* switch on arg code */
1704 } /* for each arg that we expect */
1708 /* Args don't match. */
1709 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1710 && !strcmp (insn->name, insn[1].name))
1718 as_bad ("Illegal operands%s", error_message);
1724 if (insn->architecture > current_architecture)
1726 if ((!architecture_requested || warn_on_bump)
1728 /* start-sanitize-v9 */
1730 !ARCHITECTURES_CONFLICT_P (current_architecture,
1733 /* end-sanitize-v9 */
1735 /* start-sanitize-v9 */
1737 /* end-sanitize-v9 */
1742 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1743 architecture_pname[current_architecture],
1744 architecture_pname[insn->architecture],
1748 current_architecture = insn->architecture;
1752 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1754 architecture_pname[insn->architecture],
1755 architecture_pname[current_architecture]);
1757 } /* if bump ok else error */
1758 } /* if architecture higher */
1762 } /* forever looking for a match */
1764 the_insn.opcode = opcode;
1774 save_in = input_line_pointer;
1775 input_line_pointer = str;
1776 seg = expression (&the_insn.exp);
1777 if (seg != absolute_section
1778 && seg != text_section
1779 && seg != data_section
1780 && seg != bss_section
1781 && seg != undefined_section)
1783 the_insn.error = "bad segment";
1784 expr_end = input_line_pointer;
1785 input_line_pointer = save_in;
1788 expr_end = input_line_pointer;
1789 input_line_pointer = save_in;
1791 } /* getExpression() */
1795 This is identical to the md_atof in m68k.c. I think this is right,
1798 Turn a string in input_line_pointer into a floating point constant of type
1799 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1800 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1803 /* Equal to MAX_PRECISION in atof-ieee.c */
1804 #define MAX_LITTLENUMS 6
1807 md_atof (type, litP, sizeP)
1813 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1814 LITTLENUM_TYPE *wordP;
1847 return "Bad call to MD_ATOF()";
1849 t = atof_ieee (input_line_pointer, type, words);
1851 input_line_pointer = t;
1852 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1853 for (wordP = words; prec--;)
1855 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1856 litP += sizeof (LITTLENUM_TYPE);
1862 * Write out big-endian.
1865 md_number_to_chars (buf, val, n)
1870 number_to_chars_bigendian (buf, val, n);
1873 /* Apply a fixS to the frags, now that we know the value it ought to
1877 md_apply_fix (fixP, value)
1881 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1886 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1888 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1891 /* FIXME: SPARC ELF relocations don't use an addend in the data
1892 field itself. This whole approach should be somehow combined
1893 with the calls to bfd_perform_relocation. */
1894 if (fixP->fx_addsy != NULL)
1898 /* This is a hack. There should be a better way to
1899 handle this. Probably in terms of howto fields, once
1900 we can look at these fixups in terms of howtos. */
1901 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1902 val += fixP->fx_where + fixP->fx_frag->fr_address;
1904 switch (fixP->fx_r_type)
1918 case BFD_RELOC_32_PCREL_S2:
1919 val = (val >>= 2) + 1;
1920 buf[0] |= (val >> 24) & 0x3f;
1921 buf[1] = (val >> 16);
1926 /* start-sanitize-v9 */
1939 case BFD_RELOC_SPARC_11:
1940 if (((val > 0) && (val & ~0x7ff))
1941 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1943 as_bad ("relocation overflow.");
1946 buf[2] |= (val >> 8) & 0x7;
1947 buf[3] = val & 0xff;
1950 case BFD_RELOC_SPARC_10:
1951 if (((val > 0) && (val & ~0x3ff))
1952 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1954 as_bad ("relocation overflow.");
1957 buf[2] |= (val >> 8) & 0x3;
1958 buf[3] = val & 0xff;
1961 case BFD_RELOC_SPARC_WDISP16:
1962 if (((val > 0) && (val & ~0x3fffc))
1963 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1965 as_bad ("relocation overflow.");
1968 val = (val >>= 2) + 1;
1969 buf[1] |= ((val >> 14) & 0x3) << 4;
1970 buf[2] |= (val >> 8) & 0x3f;
1971 buf[3] = val & 0xff;
1974 case BFD_RELOC_SPARC_WDISP19:
1975 if (((val > 0) && (val & ~0x1ffffc))
1976 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1978 as_bad ("relocation overflow.");
1981 val = (val >>= 2) + 1;
1982 buf[1] |= (val >> 16) & 0x7;
1983 buf[2] = (val >> 8) & 0xff;
1984 buf[3] = val & 0xff;
1987 case BFD_RELOC_SPARC_HH22:
1989 /* intentional fallthrough */
1991 /* end-sanitize-v9 */
1993 /* start-sanitize-v9 */
1995 case BFD_RELOC_SPARC_LM22:
1997 /* end-sanitize-v9 */
1998 case BFD_RELOC_HI22:
1999 if (!fixP->fx_addsy)
2001 buf[1] |= (val >> 26) & 0x3f;
2012 case BFD_RELOC_SPARC22:
2013 if (val & ~0x003fffff)
2015 as_bad ("relocation overflow");
2017 buf[1] |= (val >> 16) & 0x3f;
2019 buf[3] = val & 0xff;
2022 /* start-sanitize-v9 */
2024 case BFD_RELOC_SPARC_HM10:
2026 /* intentional fallthrough */
2028 /* end-sanitize-v9 */
2030 case BFD_RELOC_LO10:
2031 if (!fixP->fx_addsy)
2033 buf[2] |= (val >> 8) & 0x03;
2040 case BFD_RELOC_SPARC13:
2041 if (! in_signed_range (val, 0x1fff))
2042 as_bad ("relocation overflow");
2044 buf[2] |= (val >> 8) & 0x1f;
2048 case BFD_RELOC_SPARC_WDISP22:
2049 val = (val >>= 2) + 1;
2051 case BFD_RELOC_SPARC_BASE22:
2052 buf[1] |= (val >> 16) & 0x3f;
2057 case BFD_RELOC_NONE:
2059 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2063 /* Are we finished with this relocation now? */
2064 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
2070 /* Translate internal representation of relocation info to BFD target
2073 tc_gen_reloc (section, fixp)
2078 bfd_reloc_code_real_type code;
2080 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2081 assert (reloc != 0);
2083 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2084 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2086 switch (fixp->fx_r_type)
2090 case BFD_RELOC_HI22:
2091 case BFD_RELOC_LO10:
2092 case BFD_RELOC_32_PCREL_S2:
2093 case BFD_RELOC_SPARC13:
2094 case BFD_RELOC_SPARC_BASE13:
2095 case BFD_RELOC_SPARC_WDISP22:
2096 /* start-sanitize-v9 */
2098 case BFD_RELOC_SPARC_10:
2099 case BFD_RELOC_SPARC_11:
2100 case BFD_RELOC_SPARC_HH22:
2101 case BFD_RELOC_SPARC_HM10:
2102 case BFD_RELOC_SPARC_LM22:
2103 case BFD_RELOC_SPARC_PC_HH22:
2104 case BFD_RELOC_SPARC_PC_HM10:
2105 case BFD_RELOC_SPARC_PC_LM22:
2106 /* end-sanitize-v9 */
2107 code = fixp->fx_r_type;
2112 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2113 if (reloc->howto == 0)
2115 as_bad_where (fixp->fx_file, fixp->fx_line,
2116 "internal error: can't export reloc type %d",
2120 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
2122 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2123 if (reloc->howto->pc_relative == 0)
2124 reloc->addend = fixp->fx_addnumber;
2125 #if defined (OBJ_ELF) || defined (OBJ_COFF)
2126 else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
2127 reloc->addend = (section->vma
2128 + fixp->fx_addnumber
2129 + md_pcrel_from (fixp));
2132 reloc->addend = fixp->fx_offset - reloc->address;
2139 /* for debugging only */
2142 struct sparc_it *insn;
2144 const char *const Reloc[] = {
2173 fprintf (stderr, "ERROR: %s\n");
2174 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2175 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2176 fprintf (stderr, "exp = {\n");
2177 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2178 ((insn->exp.X_add_symbol != NULL)
2179 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2180 ? S_GET_NAME (insn->exp.X_add_symbol)
2183 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2184 ((insn->exp.X_op_symbol != NULL)
2185 ? (S_GET_NAME (insn->exp.X_op_symbol)
2186 ? S_GET_NAME (insn->exp.X_op_symbol)
2189 fprintf (stderr, "\t\tX_add_number = %d\n",
2190 insn->exp.X_add_number);
2191 fprintf (stderr, "}\n");
2197 * Invocation line includes a switch not recognized by the base assembler.
2198 * See if it's a processor-specific option. These are:
2201 * Warn on architecture bumps. See also -A.
2203 * -Av6, -Av7, -Av8, -Asparclite
2204 * Select the architecture. Instructions or features not
2205 * supported by the selected architecture cause fatal errors.
2207 * The default is to start at v6, and bump the architecture up
2208 * whenever an instruction is seen at a higher level.
2210 * If -bump is specified, a warning is printing when bumping to
2213 * If an architecture is specified, all instructions must match
2214 * that architecture. Any higher level instructions are flagged
2217 * if both an architecture and -bump are specified, the
2218 * architecture starts at the specified level, but bumps are
2223 * Another architecture switch.
2226 * Bumping between incompatible architectures is always an
2227 * error. For example, from sparclite to v9.
2232 md_parse_option (argP, cntP, vecP)
2240 if (!strcmp (*argP, "bump"))
2245 else if (**argP == 'A')
2249 for (arch = architecture_pname; *arch != NULL; ++arch)
2251 if (strcmp (p, *arch) == 0)
2254 } /* found a match */
2255 } /* walk the pname table */
2259 as_bad ("unknown architecture: %s", p);
2263 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2264 architecture_requested = 1;
2268 else if (**argP == 'V')
2270 print_version_id ();
2272 else if (**argP == 'Q')
2274 /* Qy - do emit .comment
2275 Qn - do not emit .comment */
2277 else if (**argP == 's')
2279 /* use .stab instead of .stab.excl */
2282 else if (strcmp (*argP, "sparc") == 0)
2284 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2288 /* Unknown option */
2292 **argP = '\0'; /* Done parsing this switch */
2294 } /* md_parse_option() */
2296 /* We have no need to default values of symbols. */
2300 md_undefined_symbol (name)
2304 } /* md_undefined_symbol() */
2306 /* Parse an operand that is machine-specific.
2307 We just return without modifying the expression if we have nothing
2312 md_operand (expressionP)
2313 expressionS *expressionP;
2317 /* Round up a section size to the appropriate boundary. */
2319 md_section_align (segment, size)
2324 /* Round all sects to multiple of 8 */
2325 size = (size + 7) & (valueT) ~7;
2330 /* Exactly what point is a PC-relative offset relative TO?
2331 On the sparc, they're relative to the address of the offset, plus
2332 its size. This gets us to the following instruction.
2333 (??? Is this right? FIXME-SOON) */
2335 md_pcrel_from (fixP)
2338 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2341 /* end of tc-sparc.c */