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. */
26 /* careful, this file includes data *declarations* */
27 #include "opcode/sparc.h"
29 static void sparc_ip PARAMS ((char *));
32 static enum sparc_architecture current_architecture = v9;
34 static enum sparc_architecture current_architecture = v6;
36 static int architecture_requested;
37 static int warn_on_bump;
39 extern int target_big_endian;
41 const relax_typeS md_relax_table[1];
43 /* handle of the OPCODE hash table */
44 static struct hash_control *op_hash;
46 static void s_data1 PARAMS ((void));
47 static void s_seg PARAMS ((int));
48 static void s_proc PARAMS ((int));
49 static void s_reserve PARAMS ((int));
50 static void s_common PARAMS ((int));
52 const pseudo_typeS md_pseudo_table[] =
54 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
55 {"common", s_common, 0},
56 {"global", s_globl, 0},
58 {"optim", s_ignore, 0},
60 {"reserve", s_reserve, 0},
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");
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);
408 S_SET_ALIGN (symbolP, temp);
410 S_SET_EXTERNAL (symbolP);
411 /* should be common, but this is how gas does it for now */
412 S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
417 input_line_pointer++;
418 /* @@ Some use the dot, some don't. Can we get some consistency?? */
419 if (*input_line_pointer == '.')
420 input_line_pointer++;
421 /* @@ Some say data, some say bss. */
422 if (strncmp (input_line_pointer, "bss\"", 4)
423 && strncmp (input_line_pointer, "data\"", 5))
425 while (*--input_line_pointer != '"')
427 input_line_pointer--;
428 goto bad_common_segment;
430 while (*input_line_pointer++ != '"')
432 goto allocate_common;
434 demand_empty_rest_of_line ();
439 p = input_line_pointer;
440 while (*p && *p != '\n')
444 as_bad ("bad .common segment %s", input_line_pointer + 1);
446 input_line_pointer = p;
447 ignore_rest_of_line ();
457 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
459 input_line_pointer += 6;
463 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
465 input_line_pointer += 6;
469 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
471 input_line_pointer += 7;
475 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
477 input_line_pointer += 5;
478 /* We only support 2 segments -- text and data -- for now, so
479 things in the "bss segment" will have to go into data for now.
480 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
481 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
484 as_bad ("Unknown segment type");
485 demand_empty_rest_of_line ();
491 subseg_set (data_section, 1);
492 demand_empty_rest_of_line ();
499 while (!is_end_of_line[(unsigned char) *input_line_pointer])
501 ++input_line_pointer;
503 ++input_line_pointer;
508 struct priv_reg_entry
514 struct priv_reg_entry priv_reg_table[] =
533 {"", -1}, /* end marker */
543 #define MEMBAR_MASKS_SIZE 7
545 static const struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
548 {"MemIssue", 8, 0x20},
549 {"Lookaside", 9, 0x10},
550 {"StoreStore", 10, 0x08},
551 {"LoadStore", 9, 0x04},
552 {"StoreLoad", 9, 0x02},
553 {"LoadLoad", 8, 0x01},
558 struct priv_reg_entry *p, *q;
560 return strcmp (q->name, p->name);
565 /* This function is called once, at assembler startup time. It should
566 set up all the tables, etc. that the MD part of the assembler will need. */
570 register const char *retval = NULL;
572 register unsigned int i = 0;
574 op_hash = hash_new ();
576 while (i < NUMOPCODES)
578 const char *name = sparc_opcodes[i].name;
579 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
582 fprintf (stderr, "internal error: can't hash `%s': %s\n",
583 sparc_opcodes[i].name, retval);
588 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
590 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
591 sparc_opcodes[i].name, sparc_opcodes[i].args);
596 while (i < NUMOPCODES
597 && !strcmp (sparc_opcodes[i].name, name));
601 as_fatal ("Broken assembler. No assembly attempted.");
603 for (i = '0'; i < '8'; ++i)
605 for (i = '0'; i <= '9'; ++i)
607 for (i = 'a'; i <= 'f'; ++i)
608 toHex[i] = i + 10 - 'a';
609 for (i = 'A'; i <= 'F'; ++i)
610 toHex[i] = i + 10 - 'A';
613 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
614 sizeof (priv_reg_table[0]), cmp_reg_entry);
617 target_big_endian = 1;
630 /* See if "set" operand is absolute and small; skip sethi if so. */
631 if (special_case == SPECIAL_CASE_SET
632 && the_insn.exp.X_op == O_constant)
634 if (the_insn.exp.X_add_number >= -(1 << 12)
635 && the_insn.exp.X_add_number < (1 << 12))
637 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
638 | (the_insn.opcode & 0x3E000000) /* dest reg */
639 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
640 special_case = 0; /* No longer special */
641 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
646 /* put out the opcode */
647 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
649 /* put out the symbol-dependent stuff */
650 if (the_insn.reloc != BFD_RELOC_NONE)
652 fix_new_exp (frag_now, /* which frag */
653 (toP - frag_now->fr_literal), /* where */
660 switch (special_case)
662 case SPECIAL_CASE_SET:
664 assert (the_insn.reloc == BFD_RELOC_HI22);
665 /* See if "set" operand has no low-order bits; skip OR if so. */
666 if (the_insn.exp.X_op == O_constant
667 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
670 rsd = (the_insn.opcode >> 25) & 0x1f;
671 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
672 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
673 fix_new_exp (frag_now, /* which frag */
674 (toP - frag_now->fr_literal), /* where */
681 case SPECIAL_CASE_FDIV:
682 /* According to information leaked from Sun, the "fdiv" instructions
683 on early SPARC machines would produce incorrect results sometimes.
684 The workaround is to add an fmovs of the destination register to
685 itself just after the instruction. This was true on machines
686 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
688 assert (the_insn.reloc == BFD_RELOC_NONE);
690 rsd = (the_insn.opcode >> 25) & 0x1f;
691 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
692 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
699 as_fatal ("failed sanity check.");
703 /* Implement big shift right. */
709 if (sizeof (bfd_vma) <= 4 && amount >= 32)
710 as_fatal ("Support for 64-bit arithmetic not compiled in.");
711 return val >> amount;
718 char *error_message = "";
722 struct sparc_opcode *insn;
724 unsigned long opcode;
725 unsigned int mask = 0;
728 long immediate_max = 0;
730 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
748 as_bad ("Unknown opcode: `%s'", str);
751 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
753 as_bad ("Unknown opcode: `%s'", str);
763 opcode = insn->match;
764 memset (&the_insn, '\0', sizeof (the_insn));
765 the_insn.reloc = BFD_RELOC_NONE;
768 * Build the opcode, checking as we go to make
769 * sure that the operands match
771 for (args = insn->args;; ++args)
781 /* Parse a series of masks. */
787 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
788 if (!strncmp (s, membar_masks[i].name,
789 membar_masks[i].len))
791 if (i < MEMBAR_MASKS_SIZE)
793 kmask |= membar_masks[i].mask;
794 s += membar_masks[i].len;
798 error_message = ": invalid membar mask name";
811 hold = input_line_pointer;
812 input_line_pointer = s;
814 send = input_line_pointer;
815 input_line_pointer = hold;
817 kmask = exp.X_add_number;
818 if (exp.X_op != O_constant
822 error_message = ": invalid membar mask number";
829 opcode |= SIMM13 (kmask);
835 int prefetch_fcn = 0;
837 /* Parse a prefetch function. */
841 if (!strncmp (s, "n_reads", 7))
842 prefetch_fcn = 0, s += 7;
843 else if (!strncmp (s, "one_read", 8))
844 prefetch_fcn = 1, s += 8;
845 else if (!strncmp (s, "n_writes", 8))
846 prefetch_fcn = 2, s += 8;
847 else if (!strncmp (s, "one_write", 9))
848 prefetch_fcn = 3, s += 9;
849 else if (!strncmp (s, "page", 4))
850 prefetch_fcn = 4, s += 4;
853 error_message = ": invalid prefetch function name";
857 else if (isdigit (*s))
861 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
865 if (prefetch_fcn < 0 || prefetch_fcn > 31)
867 error_message = ": invalid prefetch function number";
873 error_message = ": unrecognizable prefetch function";
876 opcode |= RD (prefetch_fcn);
882 /* Parse a privileged register. */
885 struct priv_reg_entry *p = priv_reg_table;
886 unsigned int len = 9999999; /* init to make gcc happy */
889 while (p->name[0] > s[0])
891 while (p->name[0] == s[0])
893 len = strlen (p->name);
894 if (strncmp (p->name, s, len) == 0)
898 if (p->name[0] != s[0])
900 error_message = ": unrecognizable privileged register";
904 opcode |= (p->regnum << 14);
906 opcode |= (p->regnum << 25);
912 error_message = ": unrecognizable privileged register";
919 if (strncmp (s, "%asr", 4) == 0)
929 num = num * 10 + *s - '0';
933 if (num < 16 || 31 < num)
935 error_message = ": asr number must be between 15 and 31";
939 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
944 error_message = ": expecting %asrN";
946 } /* if %asr followed by a number. */
953 the_insn.reloc = BFD_RELOC_SPARC_11;
954 immediate_max = 0x03FF;
958 the_insn.reloc = BFD_RELOC_SPARC_10;
959 immediate_max = 0x01FF;
963 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
968 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
973 if (*s == 'p' && s[1] == 'n')
981 if (*s == 'p' && s[1] == 't')
993 if (strncmp (s, "%icc", 4) == 0)
1005 if (strncmp (s, "%xcc", 4) == 0)
1017 if (strncmp (s, "%fcc0", 5) == 0)
1029 if (strncmp (s, "%fcc1", 5) == 0)
1041 if (strncmp (s, "%fcc2", 5) == 0)
1053 if (strncmp (s, "%fcc3", 5) == 0)
1061 if (strncmp (s, "%pc", 3) == 0)
1069 if (strncmp (s, "%tick", 5) == 0)
1077 case '\0': /* end of args */
1096 case '[': /* these must match exactly */
1104 case '#': /* must be at least one digit */
1107 while (isdigit (*s))
1115 case 'C': /* coprocessor state register */
1116 if (strncmp (s, "%csr", 4) == 0)
1123 case 'b': /* next operand is a coprocessor register */
1126 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1131 mask = 10 * (mask - '0') + (*s++ - '0');
1145 opcode |= mask << 14;
1153 opcode |= mask << 25;
1159 case 'r': /* next operand must be a register */
1168 case 'f': /* frame pointer */
1176 case 'g': /* global register */
1177 if (isoctal (c = *s++))
1184 case 'i': /* in register */
1185 if (isoctal (c = *s++))
1187 mask = c - '0' + 24;
1192 case 'l': /* local register */
1193 if (isoctal (c = *s++))
1195 mask = (c - '0' + 16);
1200 case 'o': /* out register */
1201 if (isoctal (c = *s++))
1203 mask = (c - '0' + 8);
1208 case 's': /* stack pointer */
1216 case 'r': /* any register */
1217 if (!isdigit (c = *s++))
1234 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1250 * Got the register, now figure out where
1251 * it goes in the opcode.
1257 opcode |= mask << 14;
1265 opcode |= mask << 25;
1269 opcode |= (mask << 25) | (mask << 14);
1275 case 'e': /* next operand is a floating point register */
1290 && ((format = *s) == 'f')
1293 for (mask = 0; isdigit (*s); ++s)
1295 mask = 10 * mask + (*s - '0');
1296 } /* read the number */
1304 } /* register must be even numbered */
1312 } /* register must be multiple of 4 */
1317 error_message = ": There are only 64 f registers; [0-63]";
1323 } /* wrap high bit */
1327 error_message = ": There are only 32 f registers; [0-31]";
1335 } /* if not an 'f' register. */
1343 opcode |= RS1 (mask);
1350 opcode |= RS2 (mask);
1356 opcode |= RD (mask);
1365 if (strncmp (s, "%fsr", 4) == 0)
1372 case 'h': /* high 22 bits */
1373 the_insn.reloc = BFD_RELOC_HI22;
1376 case 'l': /* 22 bit PC relative immediate */
1377 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1381 case 'L': /* 30 bit immediate */
1382 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1386 case 'n': /* 22 bit immediate */
1387 the_insn.reloc = BFD_RELOC_SPARC22;
1390 case 'i': /* 13 bit immediate */
1391 the_insn.reloc = BFD_RELOC_SPARC13;
1392 immediate_max = 0x0FFF;
1401 if ((c = s[1]) == 'h' && s[2] == 'i')
1403 the_insn.reloc = BFD_RELOC_HI22;
1406 else if (c == 'l' && s[2] == 'o')
1408 the_insn.reloc = BFD_RELOC_LO10;
1416 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1423 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1430 /* Note that if the getExpression() fails, we will still
1431 have created U entries in the symbol table for the
1432 'symbols' in the input string. Try not to create U
1433 symbols for registers, etc. */
1435 /* This stuff checks to see if the expression ends in
1436 +%reg. If it does, it removes the register from
1437 the expression, and re-sets 's' to point to the
1442 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1444 if (s1 != s && isdigit (s1[-1]))
1446 if (s1[-2] == '%' && s1[-3] == '+')
1450 (void) getExpression (s);
1455 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1459 (void) getExpression (s);
1466 (void) getExpression (s);
1469 if (the_insn.exp.X_op == O_constant
1470 && the_insn.exp.X_add_symbol == 0
1471 && the_insn.exp.X_op_symbol == 0)
1474 /* Handle %uhi/%ulo by moving the upper word to the lower
1475 one and pretending it's %hi/%lo. We also need to watch
1476 for %hi/%lo: the top word needs to be zeroed otherwise
1477 fixup_segment will complain the value is too big. */
1478 switch (the_insn.reloc)
1480 case BFD_RELOC_SPARC_HH22:
1481 the_insn.reloc = BFD_RELOC_HI22;
1482 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1484 case BFD_RELOC_SPARC_HM10:
1485 the_insn.reloc = BFD_RELOC_LO10;
1486 the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
1490 case BFD_RELOC_HI22:
1491 case BFD_RELOC_LO10:
1492 the_insn.exp.X_add_number &= 0xffffffff;
1496 /* For pc-relative call instructions, we reject
1497 constants to get better code. */
1499 && the_insn.reloc == BFD_RELOC_32_PCREL_S2
1500 && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
1503 error_message = ": PC-relative operand can't be a constant";
1506 /* Check for invalid constant values. Don't warn if
1507 constant was inside %hi or %lo, since these
1508 truncate the constant to fit. */
1509 if (immediate_max != 0
1510 && the_insn.reloc != BFD_RELOC_LO10
1511 && the_insn.reloc != BFD_RELOC_HI22
1512 && !in_signed_range (the_insn.exp.X_add_number,
1517 /* Who knows? After relocation, we may be within
1518 range. Let the linker figure it out. */
1520 the_insn.exp.X_op = O_symbol;
1521 the_insn.exp.X_add_symbol = section_symbol (absolute_section);
1524 /* Immediate value is non-pcrel, and out of
1526 as_bad ("constant value %ld out of range (%ld .. %ld)",
1527 the_insn.exp.X_add_number,
1528 ~immediate_max, immediate_max);
1532 /* Reset to prevent extraneous range check. */
1548 char *push = input_line_pointer;
1551 input_line_pointer = s;
1554 if (e.X_op == O_constant)
1556 opcode |= e.X_add_number << 5;
1557 s = input_line_pointer;
1558 input_line_pointer = push;
1570 if (!strncmp (s, "ASI_AIUP", 8))
1572 else if (!strncmp (s, "ASI_AIUS", 8))
1574 else if (!strncmp (s, "ASI_PNF", 7))
1576 else if (!strncmp (s, "ASI_SNF", 7))
1578 else if (!strncmp (s, "ASI_P", 5))
1580 else if (!strncmp (s, "ASI_S", 5))
1584 error_message = ": invalid asi name";
1588 else if (isdigit (*s))
1590 char *push = input_line_pointer;
1591 input_line_pointer = s;
1592 asi = get_absolute_expression ();
1593 s = input_line_pointer;
1594 input_line_pointer = push;
1596 if (asi < 0 || asi > 255)
1598 error_message = ": invalid asi number";
1604 error_message = ": unrecognizable asi";
1607 opcode |= ASI (asi);
1610 } /* alternate space */
1613 if (strncmp (s, "%psr", 4) == 0)
1620 case 'q': /* floating point queue */
1621 if (strncmp (s, "%fq", 3) == 0)
1628 case 'Q': /* coprocessor queue */
1629 if (strncmp (s, "%cq", 3) == 0)
1637 if (strcmp (str, "set") == 0)
1639 special_case = SPECIAL_CASE_SET;
1642 else if (strncmp (str, "fdiv", 4) == 0)
1644 special_case = SPECIAL_CASE_FDIV;
1651 if (strncmp (s, "%asi", 4) != 0)
1657 if (strncmp (s, "%fprs", 5) != 0)
1663 if (strncmp (s, "%ccr", 4) != 0)
1670 if (strncmp (s, "%tbr", 4) != 0)
1676 if (strncmp (s, "%wim", 4) != 0)
1684 char *push = input_line_pointer;
1687 input_line_pointer = s;
1689 if (e.X_op == O_constant)
1691 int n = e.X_add_number;
1692 if (n != e.X_add_number || (n & ~0x1ff) != 0)
1693 as_bad ("OPF immediate operand out of range (0-0x1ff)");
1695 opcode |= e.X_add_number << 5;
1698 as_bad ("non-immediate OPF operand, ignored");
1699 s = input_line_pointer;
1700 input_line_pointer = push;
1706 if (strncmp (s, "%y", 2) != 0)
1712 as_fatal ("failed sanity check.");
1713 } /* switch on arg code */
1715 } /* for each arg that we expect */
1719 /* Args don't match. */
1720 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1721 && !strcmp (insn->name, insn[1].name))
1729 as_bad ("Illegal operands%s", error_message);
1735 if (insn->architecture > current_architecture
1736 || (insn->architecture != current_architecture
1737 && current_architecture > v8))
1739 if ((!architecture_requested || warn_on_bump)
1740 && !ARCHITECTURES_CONFLICT_P (current_architecture,
1742 && !ARCHITECTURES_CONFLICT_P (insn->architecture,
1743 current_architecture))
1747 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1748 architecture_pname[current_architecture],
1749 architecture_pname[insn->architecture],
1753 current_architecture = insn->architecture;
1757 as_bad ("Architecture mismatch on \"%s\".", str);
1758 as_tsktsk (" (Requires %s; current architecture is %s.)",
1759 architecture_pname[insn->architecture],
1760 architecture_pname[current_architecture]);
1762 } /* if bump ok else error */
1763 } /* if architecture higher */
1767 } /* forever looking for a match */
1769 the_insn.opcode = opcode;
1779 save_in = input_line_pointer;
1780 input_line_pointer = str;
1781 seg = expression (&the_insn.exp);
1782 if (seg != absolute_section
1783 && seg != text_section
1784 && seg != data_section
1785 && seg != bss_section
1786 && seg != undefined_section)
1788 the_insn.error = "bad segment";
1789 expr_end = input_line_pointer;
1790 input_line_pointer = save_in;
1793 expr_end = input_line_pointer;
1794 input_line_pointer = save_in;
1796 } /* getExpression() */
1800 This is identical to the md_atof in m68k.c. I think this is right,
1803 Turn a string in input_line_pointer into a floating point constant of type
1804 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1805 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1808 /* Equal to MAX_PRECISION in atof-ieee.c */
1809 #define MAX_LITTLENUMS 6
1812 md_atof (type, litP, sizeP)
1818 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1819 LITTLENUM_TYPE *wordP;
1852 return "Bad call to MD_ATOF()";
1854 t = atof_ieee (input_line_pointer, type, words);
1856 input_line_pointer = t;
1857 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1858 for (wordP = words; prec--;)
1860 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1861 litP += sizeof (LITTLENUM_TYPE);
1867 * Write out big-endian.
1870 md_number_to_chars (buf, val, n)
1875 number_to_chars_bigendian (buf, val, n);
1878 /* Apply a fixS to the frags, now that we know the value it ought to
1882 md_apply_fix (fixP, value)
1886 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1891 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1893 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1896 /* FIXME: SPARC ELF relocations don't use an addend in the data
1897 field itself. This whole approach should be somehow combined
1898 with the calls to bfd_perform_relocation. */
1899 if (fixP->fx_addsy != NULL)
1903 /* This is a hack. There should be a better way to
1904 handle this. Probably in terms of howto fields, once
1905 we can look at these fixups in terms of howtos. */
1906 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1907 val += fixP->fx_where + fixP->fx_frag->fr_address;
1910 /* FIXME: More ridiculous gas reloc hacking. If we are going to
1911 generate a reloc, then we just want to let the reloc addend set
1912 the value. We do not want to also stuff the addend into the
1913 object file. Including the addend in the object file works when
1914 doing a static link, because the linker will ignore the object
1915 file contents. However, the dynamic linker does not ignore the
1916 object file contents. */
1917 if (fixP->fx_addsy != NULL
1918 && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
1922 switch (fixP->fx_r_type)
1936 case BFD_RELOC_32_PCREL_S2:
1937 val = (val >>= 2) + 1;
1938 buf[0] |= (val >> 24) & 0x3f;
1939 buf[1] = (val >> 16);
1947 bfd_vma valh = BSR (val, 32);
1948 buf[0] = valh >> 24;
1949 buf[1] = valh >> 16;
1959 case BFD_RELOC_SPARC_11:
1960 if (((val > 0) && (val & ~0x7ff))
1961 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1963 as_bad ("relocation overflow.");
1966 buf[2] |= (val >> 8) & 0x7;
1967 buf[3] = val & 0xff;
1970 case BFD_RELOC_SPARC_10:
1971 if (((val > 0) && (val & ~0x3ff))
1972 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1974 as_bad ("relocation overflow.");
1977 buf[2] |= (val >> 8) & 0x3;
1978 buf[3] = val & 0xff;
1981 case BFD_RELOC_SPARC_WDISP16:
1982 if (((val > 0) && (val & ~0x3fffc))
1983 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1985 as_bad ("relocation overflow.");
1988 val = (val >>= 2) + 1;
1989 buf[1] |= ((val >> 14) & 0x3) << 4;
1990 buf[2] |= (val >> 8) & 0x3f;
1991 buf[3] = val & 0xff;
1994 case BFD_RELOC_SPARC_WDISP19:
1995 if (((val > 0) && (val & ~0x1ffffc))
1996 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1998 as_bad ("relocation overflow.");
2001 val = (val >>= 2) + 1;
2002 buf[1] |= (val >> 16) & 0x7;
2003 buf[2] = (val >> 8) & 0xff;
2004 buf[3] = val & 0xff;
2007 case BFD_RELOC_SPARC_HH22:
2008 val = BSR (val, 32);
2009 /* intentional fallthrough */
2013 case BFD_RELOC_SPARC_LM22:
2015 case BFD_RELOC_HI22:
2016 if (!fixP->fx_addsy)
2018 buf[1] |= (val >> 26) & 0x3f;
2029 case BFD_RELOC_SPARC22:
2030 if (val & ~0x003fffff)
2032 as_bad ("relocation overflow");
2034 buf[1] |= (val >> 16) & 0x3f;
2036 buf[3] = val & 0xff;
2040 case BFD_RELOC_SPARC_HM10:
2041 val = BSR (val, 32);
2042 /* intentional fallthrough */
2045 case BFD_RELOC_LO10:
2046 if (!fixP->fx_addsy)
2048 buf[2] |= (val >> 8) & 0x03;
2055 case BFD_RELOC_SPARC13:
2056 if (! in_signed_range (val, 0x1fff))
2057 as_bad ("relocation overflow");
2059 buf[2] |= (val >> 8) & 0x1f;
2063 case BFD_RELOC_SPARC_WDISP22:
2064 val = (val >> 2) + 1;
2066 case BFD_RELOC_SPARC_BASE22:
2067 buf[1] |= (val >> 16) & 0x3f;
2072 case BFD_RELOC_NONE:
2074 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2078 /* Are we finished with this relocation now? */
2079 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
2085 /* Translate internal representation of relocation info to BFD target
2088 tc_gen_reloc (section, fixp)
2093 bfd_reloc_code_real_type code;
2095 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2096 assert (reloc != 0);
2098 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2099 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2101 switch (fixp->fx_r_type)
2105 case BFD_RELOC_HI22:
2106 case BFD_RELOC_LO10:
2107 case BFD_RELOC_32_PCREL_S2:
2108 case BFD_RELOC_SPARC13:
2109 case BFD_RELOC_SPARC_BASE13:
2110 case BFD_RELOC_SPARC_WDISP22:
2112 case BFD_RELOC_SPARC_10:
2113 case BFD_RELOC_SPARC_11:
2114 case BFD_RELOC_SPARC_HH22:
2115 case BFD_RELOC_SPARC_HM10:
2116 case BFD_RELOC_SPARC_LM22:
2117 case BFD_RELOC_SPARC_PC_HH22:
2118 case BFD_RELOC_SPARC_PC_HM10:
2119 case BFD_RELOC_SPARC_PC_LM22:
2120 code = fixp->fx_r_type;
2125 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2126 if (reloc->howto == 0)
2128 as_bad_where (fixp->fx_file, fixp->fx_line,
2129 "internal error: can't export reloc type %d (`%s')",
2130 fixp->fx_r_type, bfd_get_reloc_code_name (code));
2133 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
2135 /* @@ Why fx_addnumber sometimes and fx_offset other times? */
2136 if (reloc->howto->pc_relative == 0)
2137 reloc->addend = fixp->fx_addnumber;
2138 #if defined (OBJ_ELF) || defined (OBJ_COFF)
2139 else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
2140 reloc->addend = (section->vma
2141 + fixp->fx_addnumber
2142 + md_pcrel_from (fixp));
2145 reloc->addend = fixp->fx_offset - reloc->address;
2152 /* for debugging only */
2155 struct sparc_it *insn;
2157 const char *const Reloc[] = {
2186 fprintf (stderr, "ERROR: %s\n");
2187 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2188 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2189 fprintf (stderr, "exp = {\n");
2190 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2191 ((insn->exp.X_add_symbol != NULL)
2192 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2193 ? S_GET_NAME (insn->exp.X_add_symbol)
2196 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2197 ((insn->exp.X_op_symbol != NULL)
2198 ? (S_GET_NAME (insn->exp.X_op_symbol)
2199 ? S_GET_NAME (insn->exp.X_op_symbol)
2202 fprintf (stderr, "\t\tX_add_number = %d\n",
2203 insn->exp.X_add_number);
2204 fprintf (stderr, "}\n");
2210 * Invocation line includes a switch not recognized by the base assembler.
2211 * See if it's a processor-specific option. These are:
2214 * Warn on architecture bumps. See also -A.
2216 * -Av6, -Av7, -Av8, -Av9, -Asparclite
2217 * Select the architecture. Instructions or features not
2218 * supported by the selected architecture cause fatal errors.
2220 * The default is to start at v6, and bump the architecture up
2221 * whenever an instruction is seen at a higher level.
2223 * If -bump is specified, a warning is printing when bumping to
2226 * If an architecture is specified, all instructions must match
2227 * that architecture. Any higher level instructions are flagged
2230 * if both an architecture and -bump are specified, the
2231 * architecture starts at the specified level, but bumps are
2235 * Bumping between incompatible architectures is always an
2236 * error. For example, from sparclite to v9.
2240 CONST char *md_shortopts = "A:VQ:sq";
2242 CONST char *md_shortopts = "A:";
2244 struct option md_longopts[] = {
2245 #define OPTION_BUMP (OPTION_MD_BASE)
2246 {"bump", no_argument, NULL, OPTION_BUMP},
2247 #define OPTION_SPARC (OPTION_MD_BASE + 1)
2248 {"sparc", no_argument, NULL, OPTION_SPARC},
2249 {NULL, no_argument, NULL, 0}
2251 size_t md_longopts_size = sizeof(md_longopts);
2254 md_parse_option (c, arg)
2269 for (arch = architecture_pname; *arch != NULL; ++arch)
2271 if (strcmp (p, *arch) == 0)
2277 as_bad ("invalid architecture -A%s", p);
2282 enum sparc_architecture new_arch = arch - architecture_pname;
2286 as_error ("v9 support not compiled in");
2290 current_architecture = new_arch;
2291 architecture_requested = 1;
2297 /* Ignore -sparc, used by SunOS make default .s.o rule. */
2302 print_version_id ();
2306 /* Qy - do emit .comment
2307 Qn - do not emit .comment */
2311 /* use .stab instead of .stab.excl */
2315 /* quick -- native assembler does fewer checks */
2327 md_show_usage (stream)
2331 fprintf(stream, "SPARC options:\n");
2332 for (arch = architecture_pname; *arch; arch++)
2334 if (arch != architecture_pname)
2335 fprintf (stream, " | ");
2336 fprintf (stream, "-A%s", *arch);
2338 fprintf (stream, "\n\
2339 specify variant of SPARC architecture\n\
2340 -bump warn when assembler switches architectures\n\
2344 -V print assembler version number\n\
2351 /* We have no need to default values of symbols. */
2355 md_undefined_symbol (name)
2359 } /* md_undefined_symbol() */
2361 /* Parse an operand that is machine-specific.
2362 We just return without modifying the expression if we have nothing
2367 md_operand (expressionP)
2368 expressionS *expressionP;
2372 /* Round up a section size to the appropriate boundary. */
2374 md_section_align (segment, size)
2379 /* This is not right for ELF; a.out wants it, and COFF will force
2380 the alignment anyways. */
2381 valueT align = (valueT) 1 << (valueT) (stdoutput->xvec->align_power_min);
2383 /* turn alignment value into a mask */
2385 newsize = (size + align) & ~align;
2392 /* Exactly what point is a PC-relative offset relative TO?
2393 On the sparc, they're relative to the address of the offset, plus
2394 its size. This gets us to the following instruction.
2395 (??? Is this right? FIXME-SOON) */
2397 md_pcrel_from (fixP)
2400 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2403 /* end of tc-sparc.c */