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"
32 void md_number_to_chars ();
35 void md_create_short_jump ();
36 void md_create_long_jump ();
37 int md_estimate_size_before_relax ();
38 void md_ri_to_chars ();
39 symbolS *md_undefined_symbol ();
40 static void sparc_ip ();
42 static enum sparc_architecture current_architecture = v6;
43 static int architecture_requested;
44 static int warn_on_bump;
46 extern int target_big_endian;
48 const relax_typeS md_relax_table[1];
50 /* handle of the OPCODE hash table */
51 static struct hash_control *op_hash = NULL;
53 static void s_seg (), s_proc (), s_data1 (), s_reserve (), s_common ();
54 extern void s_globl (), s_long (), s_short (), s_space (), cons ();
55 extern void s_align_bytes (), s_ignore (), s_local();
56 /* start-sanitize-v9 */
58 static void s_xword ();
62 /* Ugly hack to keep non-BFD version working. */
64 #define BFD_RELOC_NONE NO_RELOC
65 #define BFD_RELOC_32 RELOC_32
66 #define BFD_RELOC_HI22 RELOC_HI22
67 #define BFD_RELOC_LO10 RELOC_LO10
68 #define BFD_RELOC_SPARC_WDISP22 RELOC_WDISP22
69 #define BFD_RELOC_32_PCREL_S2 RELOC_WDISP30
70 #define BFD_RELOC_SPARC22 RELOC_22
71 #define BFD_RELOC_SPARC_BASE13 RELOC_BASE13
72 #define BFD_RELOC_SPARC13 RELOC_13
73 #define BFD_RELOC_SPARC_BASE22 RELOC_BASE22
74 #define subseg_set subseg_new
77 const pseudo_typeS md_pseudo_table[] =
79 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
80 {"common", s_common, 0},
81 {"global", s_globl, 0},
84 {"local", s_local, 0},
86 {"optim", s_ignore, 0},
88 {"reserve", s_reserve, 0},
92 /* start-sanitize-v9 */
94 {"xword", s_xword, 0},
100 const int md_short_jump_size = 4;
101 const int md_long_jump_size = 4;
102 const int md_reloc_size = 12; /* Size of relocation record */
104 /* This array holds the chars that always start a comment. If the
105 pre-processor is disabled, these aren't very useful */
106 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
108 /* This array holds the chars that only start a comment at the beginning of
109 a line. If the line seems to have the form '# 123 filename'
110 .line and .file directives will appear in the pre-processed output */
111 /* Note that input_file.c hand checks for '#' at the beginning of the
112 first line of the input file. This is because the compiler outputs
113 #NO_APP at the beginning of its output. */
114 /* Also note that comments started like this one will always
115 work if '/' isn't otherwise defined. */
116 const char line_comment_chars[] = "#";
118 const char line_separator_chars[] = "";
120 /* Chars that can be used to separate mant from exp in floating point nums */
121 const char EXP_CHARS[] = "eE";
123 /* Chars that mean this number is a floating point constant */
126 const char FLT_CHARS[] = "rRsSfFdDxXpP";
128 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
129 changed in read.c . Ideally it shouldn't have to know about it at all,
130 but nothing is ideal around here.
133 static unsigned char octal[256];
134 #define isoctal(c) octal[c]
135 static unsigned char toHex[256];
140 unsigned long opcode;
141 struct nlist *nlistp;
145 bfd_reloc_code_real_type reloc;
147 enum reloc_type reloc;
151 struct sparc_it the_insn, set_insn;
154 static void print_insn PARAMS ((struct sparc_it *insn));
156 static int getExpression PARAMS ((char *str));
158 static char *expr_end;
159 static int special_case;
162 * Instructions that require wierd handling because they're longer than
165 #define SPECIAL_CASE_SET 1
166 #define SPECIAL_CASE_FDIV 2
169 * sort of like s_lcomm
172 static int max_alignment = 15;
185 name = input_line_pointer;
186 c = get_symbol_end ();
187 p = input_line_pointer;
191 if (*input_line_pointer != ',')
193 as_bad ("Expected comma after name");
194 ignore_rest_of_line ();
198 ++input_line_pointer;
200 if ((size = get_absolute_expression ()) < 0)
202 as_bad ("BSS length (%d.) <0! Ignored.", size);
203 ignore_rest_of_line ();
208 symbolP = symbol_find_or_make (name);
211 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
212 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
214 as_bad ("bad .reserve segment: `%s'", input_line_pointer);
218 if (input_line_pointer[2] == '.')
219 input_line_pointer += 7;
221 input_line_pointer += 6;
224 if (*input_line_pointer == ',')
226 ++input_line_pointer;
229 if (*input_line_pointer == '\n')
231 as_bad ("Missing alignment");
235 align = get_absolute_expression ();
236 if (align > max_alignment)
238 align = max_alignment;
239 as_warn ("Alignment too large: %d. assumed.", align);
244 as_warn ("Alignment negative. 0 assumed.");
247 record_alignment (bss_section, align);
249 /* convert to a power of 2 alignment */
250 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
254 as_bad ("Alignment not a power of 2");
255 ignore_rest_of_line ();
257 } /* not a power of two */
260 } /* if has optional alignment */
264 if ((S_GET_SEGMENT (symbolP) == bss_section
265 || !S_IS_DEFINED (symbolP))
267 && S_GET_OTHER (symbolP) == 0
268 && S_GET_DESC (symbolP) == 0
275 segT current_seg = now_seg;
276 subsegT current_subseg = now_subseg;
278 subseg_set (bss_section, 1); /* switch to bss */
281 frag_align (align, 0); /* do alignment */
283 /* detach from old frag */
284 if (S_GET_SEGMENT(symbolP) == bss_section)
285 symbolP->sy_frag->fr_symbol = NULL;
287 symbolP->sy_frag = frag_now;
288 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
292 S_SET_SEGMENT (symbolP, bss_section);
294 subseg_set (current_seg, current_subseg);
299 as_warn("Ignoring attempt to re-define symbol %s.", name);
300 } /* if not redefining */
302 demand_empty_rest_of_line ();
306 /* Currently used only by Solaris 2. */
316 name = input_line_pointer;
317 c = get_symbol_end ();
318 symbolP = symbol_find_or_make (name);
319 *input_line_pointer = c;
321 S_CLEAR_EXTERNAL (symbolP);
325 input_line_pointer++;
327 if (*input_line_pointer == '\n')
332 demand_empty_rest_of_line ();
345 name = input_line_pointer;
346 c = get_symbol_end ();
347 /* just after name is now '\0' */
348 p = input_line_pointer;
351 if (*input_line_pointer != ',')
353 as_bad ("Expected comma after symbol-name");
354 ignore_rest_of_line ();
357 input_line_pointer++; /* skip ',' */
358 if ((temp = get_absolute_expression ()) < 0)
360 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
361 ignore_rest_of_line ();
366 symbolP = symbol_find_or_make (name);
368 if (S_IS_DEFINED (symbolP))
370 as_bad ("Ignoring attempt to re-define symbol");
371 ignore_rest_of_line ();
374 if (S_GET_VALUE (symbolP) != 0)
376 if (S_GET_VALUE (symbolP) != size)
378 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
379 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
385 S_SET_VALUE (symbolP, size);
386 S_SET_EXTERNAL (symbolP);
389 know (symbolP->sy_frag == &zero_address_frag);
390 if (*input_line_pointer != ',')
392 as_bad ("Expected comma after common length");
393 ignore_rest_of_line ();
396 input_line_pointer++;
398 if (*input_line_pointer != '"')
400 temp = get_absolute_expression ();
401 if (temp > max_alignment)
403 temp = max_alignment;
404 as_warn ("Common alignment too large: %d. assumed", temp);
409 as_warn ("Common alignment negative; 0 assumed");
421 old_subsec = now_subseg;
423 record_alignment (bss_section, align);
424 subseg_set (bss_section, 0);
426 frag_align (align, 0);
427 if (S_GET_SEGMENT (symbolP) == bss_section)
428 symbolP->sy_frag->fr_symbol = 0;
429 symbolP->sy_frag = frag_now;
430 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
433 S_SET_SEGMENT (symbolP, bss_section);
434 S_CLEAR_EXTERNAL (symbolP);
435 subseg_set (old_sec, old_subsec);
441 S_SET_VALUE (symbolP, size);
442 S_SET_EXTERNAL (symbolP);
443 /* should be common, but this is how gas does it for now */
444 S_SET_SEGMENT (symbolP, &bfd_und_section);
449 input_line_pointer++;
450 /* @@ Some use the dot, some don't. Can we get some consistency?? */
451 if (*input_line_pointer == '.')
452 input_line_pointer++;
453 /* @@ Some say data, some say bss. */
454 if (strncmp (input_line_pointer, "bss\"", 4)
455 && strncmp (input_line_pointer, "data\"", 5))
457 while (*--input_line_pointer != '"')
459 input_line_pointer--;
460 goto bad_common_segment;
462 while (*input_line_pointer++ != '"')
464 goto allocate_common;
466 demand_empty_rest_of_line ();
471 p = input_line_pointer;
472 while (*p && *p != '\n')
476 as_bad ("bad .common segment %s", input_line_pointer + 1);
478 input_line_pointer = p;
479 ignore_rest_of_line ();
488 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
490 input_line_pointer += 6;
494 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
496 input_line_pointer += 6;
500 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
502 input_line_pointer += 7;
506 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
508 input_line_pointer += 5;
509 /* We only support 2 segments -- text and data -- for now, so
510 things in the "bss segment" will have to go into data for now.
511 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
512 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
515 as_bad ("Unknown segment type");
516 demand_empty_rest_of_line ();
523 subseg_set (data_section, 1);
524 demand_empty_rest_of_line ();
531 extern char is_end_of_line[];
533 while (!is_end_of_line[*input_line_pointer])
535 ++input_line_pointer;
537 ++input_line_pointer;
541 /* start-sanitize-v9 */
547 if (isdigit (*input_line_pointer))
553 struct priv_reg_entry
559 struct priv_reg_entry priv_reg_table[] =
578 {"", -1}, /* end marker */
588 #define MEMBAR_MASKS_SIZE 7
590 struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
593 {"MemIssue", 8, 0x20},
594 {"Lookaside", 9, 0x10},
595 {"StoreStore", 10, 0x08},
596 {"LoadStore", 9, 0x04},
597 {"StoreLoad", 9, 0x02},
598 {"LoadLoad", 8, 0x01},
603 struct priv_reg_entry *p, *q;
605 return strcmp (q->name, p->name);
609 /* end-sanitize-v9 */
611 /* This function is called once, at assembler startup time. It should
612 set up all the tables, etc. that the MD part of the assembler will need. */
616 register char *retval = NULL;
618 register unsigned int i = 0;
620 op_hash = hash_new ();
622 as_fatal ("Virtual memory exhausted");
624 while (i < NUMOPCODES)
626 const char *name = sparc_opcodes[i].name;
627 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
628 if (retval != NULL && *retval != '\0')
630 fprintf (stderr, "internal error: can't hash `%s': %s\n",
631 sparc_opcodes[i].name, retval);
636 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
638 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
639 sparc_opcodes[i].name, sparc_opcodes[i].args);
644 while (i < NUMOPCODES
645 && !strcmp (sparc_opcodes[i].name, name));
649 as_fatal ("Broken assembler. No assembly attempted.");
651 for (i = '0'; i < '8'; ++i)
653 for (i = '0'; i <= '9'; ++i)
655 for (i = 'a'; i <= 'f'; ++i)
656 toHex[i] = i + 10 - 'a';
657 for (i = 'A'; i <= 'F'; ++i)
658 toHex[i] = i + 10 - 'A';
660 /* start-sanitize-v9 */
663 current_architecture = v9;
666 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
667 sizeof (priv_reg_table[0]), cmp_reg_entry);
669 /* end-sanitize-v9 */
671 target_big_endian = 1;
690 /* See if "set" operand is absolute and small; skip sethi if so. */
691 if (special_case == SPECIAL_CASE_SET
692 && the_insn.exp.X_seg == absolute_section)
694 if (the_insn.exp.X_add_number >= -(1 << 12)
695 && the_insn.exp.X_add_number < (1 << 12))
697 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
698 | (the_insn.opcode & 0x3E000000) /* dest reg */
699 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
700 special_case = 0; /* No longer special */
701 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
706 /* put out the opcode */
707 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
709 /* put out the symbol-dependent stuff */
710 if (the_insn.reloc != BFD_RELOC_NONE)
712 fix_new (frag_now, /* which frag */
713 (toP - frag_now->fr_literal), /* where */
715 the_insn.exp.X_add_symbol,
716 the_insn.exp.X_subtract_symbol,
717 the_insn.exp.X_add_number,
722 switch (special_case)
724 case SPECIAL_CASE_SET:
726 assert (the_insn.reloc == BFD_RELOC_HI22);
727 /* See if "set" operand has no low-order bits; skip OR if so. */
728 if (the_insn.exp.X_seg == absolute_section
729 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
732 rsd = (the_insn.opcode >> 25) & 0x1f;
733 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
734 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
735 fix_new (frag_now, /* which frag */
736 (toP - frag_now->fr_literal), /* where */
738 the_insn.exp.X_add_symbol,
739 the_insn.exp.X_subtract_symbol,
740 the_insn.exp.X_add_number,
746 case SPECIAL_CASE_FDIV:
747 /* According to information leaked from Sun, the "fdiv" instructions
748 on early SPARC machines would produce incorrect results sometimes.
749 The workaround is to add an fmovs of the destination register to
750 itself just after the instruction. This was true on machines
751 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
753 assert (the_insn.reloc == BFD_RELOC_NONE);
755 rsd = (the_insn.opcode >> 25) & 0x1f;
756 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
757 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
764 as_fatal ("failed sanity check.");
766 } /* md_assemble() */
772 char *error_message = "";
776 struct sparc_opcode *insn;
778 unsigned long opcode;
779 unsigned int mask = 0;
782 long immediate_max = 0;
784 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
802 as_bad ("Unknown opcode: `%s'", str);
805 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
807 as_bad ("Unknown opcode: `%s'", str);
817 opcode = insn->match;
818 memset (&the_insn, '\0', sizeof (the_insn));
819 the_insn.reloc = BFD_RELOC_NONE;
822 * Build the opcode, checking as we go to make
823 * sure that the operands match
825 for (args = insn->args;; ++args)
830 /* start-sanitize-v9 */
837 /* Parse a series of masks. */
843 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
844 if (!strncmp (s, membar_masks[i].name,
845 membar_masks[i].len))
847 if (i < MEMBAR_MASKS_SIZE)
849 mask |= membar_masks[i].mask;
850 s += membar_masks[i].len;
854 error_message = ": invalid membar mask name";
861 else if (isdigit (*s))
865 mask = mask * 10 + *s - '0';
869 if (mask < 0 || mask > 127)
871 error_message = ": invalid membar mask number";
877 error_message = ": unrecognizable membar mask";
880 opcode |= SIMM13 (mask);
886 int prefetch_fcn = 0;
888 /* Parse a prefetch function. */
892 if (!strncmp (s, "n_reads", 7))
893 prefetch_fcn = 0, s += 7;
894 else if (!strncmp (s, "one_read", 8))
895 prefetch_fcn = 1, s += 8;
896 else if (!strncmp (s, "n_writes", 8))
897 prefetch_fcn = 2, s += 8;
898 else if (!strncmp (s, "one_write", 9))
899 prefetch_fcn = 3, s += 9;
900 else if (!strncmp (s, "page", 4))
901 prefetch_fcn = 4, s += 4;
904 error_message = ": invalid prefetch function name";
908 else if (isdigit (*s))
912 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
916 if (prefetch_fcn < 0 || prefetch_fcn > 31)
918 error_message = ": invalid prefetch function number";
924 error_message = ": unrecognizable prefetch function";
927 opcode |= RD (prefetch_fcn);
933 /* Parse a privileged register. */
936 struct priv_reg_entry *p = priv_reg_table;
937 int len = 9999999; /* init to make gcc happy */
940 while (p->name[0] > s[0])
942 while (p->name[0] == s[0])
944 len = strlen (p->name);
945 if (strncmp (p->name, s, len) == 0)
949 if (p->name[0] != s[0])
951 error_message = ": unrecognizable privileged register";
955 opcode |= (p->regnum << 14);
957 opcode |= (p->regnum << 25);
963 error_message = ": unrecognizable privileged register";
967 /* end-sanitize-v9 */
971 if (strncmp (s, "%asr", 4) == 0)
981 num = num * 10 + *s - '0';
985 if (num < 16 || 31 < num)
987 error_message = ": asr number must be between 15 and 31";
991 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
996 error_message = ": expecting %asrN";
998 } /* if %asr followed by a number. */
1003 /* start-sanitize-v9 */
1006 the_insn.reloc = BFD_RELOC_SPARC_11;
1007 immediate_max = 0x03FF;
1011 the_insn.reloc = BFD_RELOC_SPARC_10;
1012 immediate_max = 0x01FF;
1016 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
1021 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
1026 if (*s == 'p' && s[1] == 'n')
1034 if (*s == 'p' && s[1] == 't')
1046 if (strncmp (s, "%icc", 4) == 0)
1058 if (strncmp (s, "%xcc", 4) == 0)
1070 if (strncmp (s, "%fcc0", 5) == 0)
1082 if (strncmp (s, "%fcc1", 5) == 0)
1094 if (strncmp (s, "%fcc2", 5) == 0)
1106 if (strncmp (s, "%fcc3", 5) == 0)
1114 if (strncmp (s, "%pc", 3) == 0)
1122 if (strncmp (s, "%tick", 5) == 0)
1129 /* end-sanitize-v9 */
1131 case '\0': /* end of args */
1150 case '[': /* these must match exactly */
1158 case '#': /* must be at least one digit */
1161 while (isdigit (*s))
1169 case 'C': /* coprocessor state register */
1170 if (strncmp (s, "%csr", 4) == 0)
1177 case 'b': /* next operand is a coprocessor register */
1180 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1185 mask = 10 * (mask - '0') + (*s++ - '0');
1199 opcode |= mask << 14;
1207 opcode |= mask << 25;
1213 case 'r': /* next operand must be a register */
1222 case 'f': /* frame pointer */
1230 case 'g': /* global register */
1231 if (isoctal (c = *s++))
1238 case 'i': /* in register */
1239 if (isoctal (c = *s++))
1241 mask = c - '0' + 24;
1246 case 'l': /* local register */
1247 if (isoctal (c = *s++))
1249 mask = (c - '0' + 16);
1254 case 'o': /* out register */
1255 if (isoctal (c = *s++))
1257 mask = (c - '0' + 8);
1262 case 's': /* stack pointer */
1270 case 'r': /* any register */
1271 if (!isdigit (c = *s++))
1288 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1304 * Got the register, now figure out where
1305 * it goes in the opcode.
1311 opcode |= mask << 14;
1319 opcode |= mask << 25;
1323 opcode |= (mask << 25) | (mask << 14);
1329 case 'e': /* next operand is a floating point register */
1344 && ((format = *s) == 'f')
1347 for (mask = 0; isdigit (*s); ++s)
1349 mask = 10 * mask + (*s - '0');
1350 } /* read the number */
1358 } /* register must be even numbered */
1366 } /* register must be multiple of 4 */
1368 /* start-sanitize-v9 */
1372 error_message = ": There are only 64 f registers; [0-63]";
1378 } /* wrap high bit */
1380 /* end-sanitize-v9 */
1383 error_message = ": There are only 32 f registers; [0-31]";
1386 /* start-sanitize-v9 */
1388 /* end-sanitize-v9 */
1393 } /* if not an 'f' register. */
1401 opcode |= RS1 (mask);
1408 opcode |= RS2 (mask);
1414 opcode |= RD (mask);
1423 if (strncmp (s, "%fsr", 4) == 0)
1430 case 'h': /* high 22 bits */
1431 the_insn.reloc = BFD_RELOC_HI22;
1434 case 'l': /* 22 bit PC relative immediate */
1435 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1439 case 'L': /* 30 bit immediate */
1440 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1444 case 'n': /* 22 bit immediate */
1445 the_insn.reloc = BFD_RELOC_SPARC22;
1448 case 'i': /* 13 bit immediate */
1449 /* What's the difference between base13 and 13? */
1450 the_insn.reloc = BFD_RELOC_SPARC_BASE13;
1451 immediate_max = 0x0FFF;
1460 if ((c = s[1]) == 'h' && s[2] == 'i')
1462 the_insn.reloc = BFD_RELOC_HI22;
1465 else if (c == 'l' && s[2] == 'o')
1467 the_insn.reloc = BFD_RELOC_LO10;
1469 /* start-sanitize-v9 */
1476 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1483 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1486 /* end-sanitize-v9 */
1491 /* Note that if the getExpression() fails, we
1492 will still have created U entries in the
1493 symbol table for the 'symbols' in the input
1494 string. Try not to create U symbols for
1497 /* This stuff checks to see if the
1498 expression ends in +%reg If it does,
1499 it removes the register from the
1500 expression, and re-sets 's' to point
1501 to the right place */
1505 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1507 if (s1 != s && isdigit (s1[-1]))
1509 if (s1[-2] == '%' && s1[-3] == '+')
1513 (void) getExpression (s);
1518 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1522 (void) getExpression (s);
1529 (void) getExpression (s);
1532 /* Check for invalid constant values. Don't
1533 warn if constant was inside %hi or %lo,
1534 since these truncate the constant to
1536 if (immediate_max != 0
1537 && the_insn.reloc != BFD_RELOC_LO10
1538 && the_insn.reloc != BFD_RELOC_HI22
1539 /* start-sanitize-v9 */
1541 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1542 && the_insn.reloc != RELOC_HLO10
1543 && the_insn.reloc != RELOC_HHI22
1546 /* end-sanitize-v9 */
1547 && the_insn.exp.X_add_symbol == 0
1548 && the_insn.exp.X_subtract_symbol == 0
1549 && the_insn.exp.X_seg == absolute_section
1550 && (the_insn.exp.X_add_number > immediate_max
1551 || the_insn.exp.X_add_number < ~immediate_max))
1552 as_bad ("constant value must be between %ld and %ld",
1553 ~immediate_max, immediate_max);
1554 /* Reset to prevent extraneous range check. */
1569 /* start-sanitize-v9 */
1571 /* end-sanitize-v9 */
1572 char *push = input_line_pointer;
1575 input_line_pointer = s;
1577 if (expression (&e) == absolute_section)
1579 opcode |= e.X_add_number << 5;
1580 s = input_line_pointer;
1581 input_line_pointer = push;
1586 /* start-sanitize-v9 */
1594 if (!strncmp (s, "ASI_AIUP", 8))
1596 else if (!strncmp (s, "ASI_AIUS", 8))
1598 else if (!strncmp (s, "ASI_PNF", 7))
1600 else if (!strncmp (s, "ASI_SNF", 7))
1602 else if (!strncmp (s, "ASI_P", 5))
1604 else if (!strncmp (s, "ASI_S", 5))
1608 error_message = ": invalid asi name";
1612 else if (isdigit (*s))
1614 char *push = input_line_pointer;
1615 input_line_pointer = s;
1616 asi = get_absolute_expression ();
1617 s = input_line_pointer;
1618 input_line_pointer = push;
1620 if (asi < 0 || asi > 255)
1622 error_message = ": invalid asi number";
1628 error_message = ": unrecognizable asi";
1631 opcode |= ASI (asi);
1634 /* end-sanitize-v9 */
1635 } /* alternate space */
1638 if (strncmp (s, "%psr", 4) == 0)
1645 case 'q': /* floating point queue */
1646 if (strncmp (s, "%fq", 3) == 0)
1653 case 'Q': /* coprocessor queue */
1654 if (strncmp (s, "%cq", 3) == 0)
1662 if (strcmp (str, "set") == 0)
1664 special_case = SPECIAL_CASE_SET;
1667 else if (strncmp (str, "fdiv", 4) == 0)
1669 special_case = SPECIAL_CASE_FDIV;
1674 /* start-sanitize-v9 */
1677 if (strncmp (s, "%asi", 4) != 0)
1683 if (strncmp (s, "%fprs", 5) != 0)
1689 if (strncmp (s, "%ccr", 4) != 0)
1694 /* end-sanitize-v9 */
1697 if (strncmp (s, "%tbr", 4) != 0)
1703 if (strncmp (s, "%wim", 4) != 0)
1709 if (strncmp (s, "%y", 2) != 0)
1715 as_fatal ("failed sanity check.");
1716 } /* switch on arg code */
1718 } /* for each arg that we expect */
1722 /* Args don't match. */
1723 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1724 && !strcmp (insn->name, insn[1].name))
1732 as_bad ("Illegal operands%s", error_message);
1738 if (insn->architecture > current_architecture)
1740 if ((!architecture_requested || warn_on_bump)
1742 /* start-sanitize-v9 */
1744 !ARCHITECTURES_CONFLICT_P (current_architecture,
1747 /* end-sanitize-v9 */
1749 /* start-sanitize-v9 */
1751 /* end-sanitize-v9 */
1756 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1757 architecture_pname[current_architecture],
1758 architecture_pname[insn->architecture],
1762 current_architecture = insn->architecture;
1766 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1768 architecture_pname[insn->architecture],
1769 architecture_pname[current_architecture]);
1771 } /* if bump ok else error */
1772 } /* if architecture higher */
1776 } /* forever looking for a match */
1778 the_insn.opcode = opcode;
1789 save_in = input_line_pointer;
1790 input_line_pointer = str;
1791 seg = expression (&the_insn.exp);
1792 if (seg == absolute_section
1793 || seg == text_section
1794 || seg == data_section
1795 || seg == bss_section
1796 || seg == undefined_section
1797 || seg == diff_section
1798 || seg == big_section
1799 || seg == absent_section)
1803 the_insn.error = "bad segment";
1804 expr_end = input_line_pointer;
1805 input_line_pointer = save_in;
1808 expr_end = input_line_pointer;
1809 input_line_pointer = save_in;
1811 } /* getExpression() */
1815 This is identical to the md_atof in m68k.c. I think this is right,
1818 Turn a string in input_line_pointer into a floating point constant of type
1819 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1820 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1823 /* Equal to MAX_PRECISION in atof-ieee.c */
1824 #define MAX_LITTLENUMS 6
1827 md_atof (type, litP, sizeP)
1833 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1834 LITTLENUM_TYPE *wordP;
1867 return "Bad call to MD_ATOF()";
1869 t = atof_ieee (input_line_pointer, type, words);
1871 input_line_pointer = t;
1872 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1873 for (wordP = words; prec--;)
1875 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1876 litP += sizeof (LITTLENUM_TYPE);
1882 * Write out big-endian.
1885 md_number_to_chars (buf, val, n)
1893 /* start-sanitize-v9 */
1899 /* end-sanitize-v9 */
1910 as_fatal ("failed sanity check.");
1913 } /* md_number_to_chars() */
1915 /* Apply a fixS to the frags, now that we know the value it ought to
1918 #ifdef BFD_ASSEMBLER
1923 md_apply_fix (fixP, value)
1925 #ifdef BFD_ASSEMBLER
1931 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1934 #ifdef BFD_ASSEMBLER
1940 #ifdef BFD_ASSEMBLER
1941 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1943 assert (fixP->fx_r_type < NO_RELOC);
1946 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1949 * This is a hack. There should be a better way to
1952 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1954 val += fixP->fx_where + fixP->fx_frag->fr_address;
1957 switch (fixP->fx_r_type)
1961 buf[0] = 0; /* val >> 24; */
1962 buf[1] = 0; /* val >> 16; */
1963 buf[2] = 0; /* val >> 8; */
1964 buf[3] = 0; /* val; */
1967 case BFD_RELOC_32_PCREL_S2:
1968 val = (val >>= 2) + 1;
1969 buf[0] |= (val >> 24) & 0x3f;
1970 buf[1] = (val >> 16);
1975 /* start-sanitize-v9 */
1977 case BFD_RELOC_SPARC_11:
1978 if (((val > 0) && (val & ~0x7ff))
1979 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1981 as_bad ("relocation overflow.");
1984 buf[2] |= (val >> 8) & 0x7;
1985 buf[3] = val & 0xff;
1988 case BFD_RELOC_SPARC_10:
1989 if (((val > 0) && (val & ~0x3ff))
1990 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1992 as_bad ("relocation overflow.");
1995 buf[2] |= (val >> 8) & 0x3;
1996 buf[3] = val & 0xff;
1999 case BFD_RELOC_SPARC_WDISP16:
2000 if (((val > 0) && (val & ~0x3fffc))
2001 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
2003 as_bad ("relocation overflow.");
2006 val = (val >>= 2) + 1;
2007 buf[1] |= ((val >> 14) & 0x3) << 4;
2008 buf[2] |= (val >> 8) & 0x3f;
2009 buf[3] = val & 0xff;
2012 case BFD_RELOC_SPARC_WDISP19:
2013 if (((val > 0) && (val & ~0x1ffffc))
2014 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
2016 as_bad ("relocation overflow.");
2019 val = (val >>= 2) + 1;
2020 buf[1] |= (val >> 16) & 0x7;
2021 buf[2] = (val >> 8) & 0xff;
2022 buf[3] = val & 0xff;
2025 case BFD_RELOC_SPARC_HH22:
2027 /* intentional fallthrough */
2029 /* end-sanitize-v9 */
2031 /* start-sanitize-v9 */
2033 case BFD_RELOC_SPARC_LM22:
2035 /* end-sanitize-v9 */
2036 case BFD_RELOC_HI22:
2037 if (!fixP->fx_addsy)
2039 buf[1] |= (val >> 26) & 0x3f;
2050 case BFD_RELOC_SPARC22:
2051 if (val & ~0x003fffff)
2053 as_bad ("relocation overflow");
2055 buf[1] |= (val >> 16) & 0x3f;
2057 buf[3] = val & 0xff;
2060 case BFD_RELOC_SPARC13:
2061 if (val & ~0x00001fff)
2063 as_bad ("relocation overflow");
2065 buf[2] |= (val >> 8) & 0x1f;
2066 buf[3] = val & 0xff;
2069 /* start-sanitize-v9 */
2071 case BFD_RELOC_SPARC_HM10:
2073 /* intentional fallthrough */
2075 /* end-sanitize-v9 */
2077 case BFD_RELOC_LO10:
2078 if (!fixP->fx_addsy)
2080 buf[2] |= (val >> 8) & 0x03;
2086 case BFD_RELOC_SPARC_BASE13:
2087 if (((val > 0) && (val & ~(offsetT)0x00001fff))
2088 || ((val < 0) && (~(val - 1) & ~(offsetT)0x00001fff)))
2090 as_bad ("relocation overflow");
2092 buf[2] |= (val >> 8) & 0x1f;
2096 case BFD_RELOC_SPARC_WDISP22:
2097 val = (val >>= 2) + 1;
2099 case BFD_RELOC_SPARC_BASE22:
2100 buf[1] |= (val >> 16) & 0x3f;
2105 case BFD_RELOC_NONE:
2107 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2111 #ifdef BFD_ASSEMBLER
2116 /* should never be called for sparc */
2118 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2125 as_fatal ("sparc_create_short_jmp\n");
2128 #ifdef BFD_ASSEMBLER
2130 /* Translate internal representation of relocation info to BFD target
2133 tc_gen_reloc (section, fixp)
2138 bfd_reloc_code_real_type code;
2140 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2141 assert (reloc != 0);
2143 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2144 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2145 if (fixp->fx_pcrel == 0)
2146 reloc->addend = fixp->fx_addnumber;
2148 switch (OUTPUT_FLAVOR)
2150 case bfd_target_elf_flavour:
2153 case bfd_target_aout_flavour:
2154 reloc->addend = - reloc->address;
2157 /* What's a good default here? Is there any?? */
2161 switch (fixp->fx_r_type)
2164 case BFD_RELOC_HI22:
2165 case BFD_RELOC_LO10:
2166 case BFD_RELOC_32_PCREL_S2:
2167 case BFD_RELOC_SPARC_BASE13:
2168 case BFD_RELOC_SPARC_WDISP22:
2169 /* start-sanitize-v9 */
2170 case BFD_RELOC_SPARC_10:
2171 case BFD_RELOC_SPARC_11:
2172 case BFD_RELOC_SPARC_HH22:
2173 case BFD_RELOC_SPARC_HM10:
2174 case BFD_RELOC_SPARC_LM22:
2175 case BFD_RELOC_SPARC_PC_HH22:
2176 case BFD_RELOC_SPARC_PC_HM10:
2177 case BFD_RELOC_SPARC_PC_LM22:
2178 /* end-sanitize-v9 */
2179 code = fixp->fx_r_type;
2184 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2185 assert (reloc->howto != 0);
2192 /* Translate internal representation of relocation info to target format.
2194 On sparc: first 4 bytes are normal unsigned long address, next three
2195 bytes are index, most sig. byte first. Byte 7 is broken up with
2196 bit 7 as external, bits 6 & 5 unused, and the lower
2197 five bits as relocation type. Next 4 bytes are long addend. */
2198 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2200 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
2203 relax_addressT segment_address_in_file;
2210 know (fixP->fx_addsy);
2212 if (!S_IS_DEFINED (fixP->fx_addsy))
2215 r_index = fixP->fx_addsy->sy_number;
2220 r_index = S_GET_TYPE (fixP->fx_addsy);
2224 md_number_to_chars (where,
2225 r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
2228 /* now the fun stuff */
2229 where[4] = (r_index >> 16) & 0x0ff;
2230 where[5] = (r_index >> 8) & 0x0ff;
2231 where[6] = r_index & 0x0ff;
2232 where[7] = ((r_extern << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
2235 if (fixP->fx_addsy->sy_frag)
2237 r_addend = fixP->fx_addsy->sy_frag->fr_address;
2242 r_addend += fixP->fx_offset - r_address;
2246 r_addend = fixP->fx_addnumber;
2249 md_number_to_chars (&where[8], r_addend, 4);
2252 } /* tc_aout_fix_to_chars() */
2255 /* should never be called for sparc */
2257 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2259 addressT from_addr, to_addr;
2263 as_fatal ("sparc_create_long_jump\n");
2264 } /* md_create_long_jump() */
2266 /* should never be called for sparc */
2268 md_estimate_size_before_relax (fragP, segtype)
2272 as_fatal ("sparc_estimate_size_before_relax\n");
2274 } /* md_estimate_size_before_relax() */
2277 /* for debugging only */
2280 struct sparc_it *insn;
2313 fprintf (stderr, "ERROR: %s\n");
2315 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2316 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2317 fprintf (stderr, "exp = {\n");
2318 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2319 ((insn->exp.X_add_symbol != NULL)
2320 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2321 ? S_GET_NAME (insn->exp.X_add_symbol)
2324 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2325 ((insn->exp.X_subtract_symbol != NULL)
2326 ? (S_GET_NAME (insn->exp.X_subtract_symbol)
2327 ? S_GET_NAME (insn->exp.X_subtract_symbol)
2330 fprintf (stderr, "\t\tX_add_number = %d\n",
2331 insn->exp.X_add_number);
2332 fprintf (stderr, "}\n");
2334 } /* print_insn() */
2340 * Invocation line includes a switch not recognized by the base assembler.
2341 * See if it's a processor-specific option. These are:
2344 * Warn on architecture bumps. See also -A.
2346 * -Av6, -Av7, -Av8, -Asparclite
2347 * Select the architecture. Instructions or features not
2348 * supported by the selected architecture cause fatal errors.
2350 * The default is to start at v6, and bump the architecture up
2351 * whenever an instruction is seen at a higher level.
2353 * If -bump is specified, a warning is printing when bumping to
2356 * If an architecture is specified, all instructions must match
2357 * that architecture. Any higher level instructions are flagged
2360 * if both an architecture and -bump are specified, the
2361 * architecture starts at the specified level, but bumps are
2366 * Another architecture switch.
2369 * Bumping between incompatible architectures is always an
2370 * error. For example, from sparclite to v9.
2375 md_parse_option (argP, cntP, vecP)
2383 if (!strcmp (*argP, "bump"))
2388 else if (**argP == 'A')
2392 for (arch = architecture_pname; *arch != NULL; ++arch)
2394 if (strcmp (p, *arch) == 0)
2397 } /* found a match */
2398 } /* walk the pname table */
2402 as_bad ("unknown architecture: %s", p);
2406 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2407 architecture_requested = 1;
2411 else if (**argP == 'V')
2413 extern void print_version_id ();
2414 print_version_id ();
2416 else if (**argP == 'Q')
2418 /* Qy - do emit .comment
2419 Qn - do not emit .comment */
2421 else if (**argP == 's')
2423 /* use .stab instead of .stab.excl */
2428 /* Unknown option */
2432 **argP = '\0'; /* Done parsing this switch */
2434 } /* md_parse_option() */
2436 /* We have no need to default values of symbols. */
2440 md_undefined_symbol (name)
2444 } /* md_undefined_symbol() */
2446 /* Parse an operand that is machine-specific.
2447 We just return without modifying the expression if we have nothing
2452 md_operand (expressionP)
2453 expressionS *expressionP;
2457 /* Round up a section size to the appropriate boundary. */
2459 md_section_align (segment, size)
2463 /* Round all sects to multiple of 8 */
2464 return (size + 7) & ~7;
2467 /* Exactly what point is a PC-relative offset relative TO?
2468 On the sparc, they're relative to the address of the offset, plus
2469 its size. This gets us to the following instruction.
2470 (??? Is this right? FIXME-SOON) */
2472 md_pcrel_from (fixP)
2475 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2478 #ifndef BFD_ASSEMBLER
2480 tc_aout_pre_write_hook (headers)
2481 object_headers *headers;
2483 H_SET_VERSION (headers, 1);
2487 /* end of tc-sparc.c */