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"
33 void md_number_to_chars ();
36 void md_convert_frag ();
37 void md_create_short_jump ();
38 void md_create_long_jump ();
39 int md_estimate_size_before_relax ();
40 void md_ri_to_chars ();
41 symbolS *md_undefined_symbol ();
42 static void sparc_ip ();
44 static enum sparc_architecture current_architecture = v6;
45 static int architecture_requested = 0;
46 static int warn_on_bump = 0;
48 const relax_typeS md_relax_table[] =
52 /* handle of the OPCODE hash table */
53 static struct hash_control *op_hash = NULL;
55 static void s_seg (), s_proc (), s_data1 (), s_reserve (), s_common ();
56 extern void s_globl (), s_long (), s_short (), s_space (), cons ();
57 extern void s_align_bytes (), s_ignore ();
59 const pseudo_typeS md_pseudo_table[] =
61 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
62 {"common", s_common, 0},
63 {"global", s_globl, 0},
65 {"optim", s_ignore, 0},
67 {"reserve", s_reserve, 0},
74 const int md_short_jump_size = 4;
75 const int md_long_jump_size = 4;
76 const int md_reloc_size = 12; /* Size of relocation record */
78 /* This array holds the chars that always start a comment. If the
79 pre-processor is disabled, these aren't very useful */
80 const char comment_chars[] = "!"; /* JF removed '|' from comment_chars */
82 /* This array holds the chars that only start a comment at the beginning of
83 a line. If the line seems to have the form '# 123 filename'
84 .line and .file directives will appear in the pre-processed output */
85 /* Note that input_file.c hand checks for '#' at the beginning of the
86 first line of the input file. This is because the compiler outputs
87 #NO_APP at the beginning of its output. */
88 /* Also note that comments started like this one will always
89 work if '/' isn't otherwise defined. */
90 const char line_comment_chars[] = "#";
92 const char line_separator_chars[] = "";
94 /* Chars that can be used to separate mant from exp in floating point nums */
95 const char EXP_CHARS[] = "eE";
97 /* Chars that mean this number is a floating point constant */
100 const char FLT_CHARS[] = "rRsSfFdDxXpP";
102 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
103 changed in read.c . Ideally it shouldn't have to know about it at all,
104 but nothing is ideal around here.
107 static unsigned char octal[256];
108 #define isoctal(c) octal[c]
109 static unsigned char toHex[256];
114 unsigned long opcode;
115 struct nlist *nlistp;
118 enum reloc_type reloc;
119 } the_insn, set_insn;
123 static void print_insn (struct sparc_it *insn);
125 static int getExpression (char *str);
126 #else /* not __STDC__ */
128 static void print_insn ();
130 static int getExpression ();
131 #endif /* not __STDC__ */
133 static char *expr_end;
134 static int special_case;
137 * Instructions that require wierd handling because they're longer than
140 #define SPECIAL_CASE_SET 1
141 #define SPECIAL_CASE_FDIV 2
144 * sort of like s_lcomm
147 static int max_alignment = 15;
160 name = input_line_pointer;
161 c = get_symbol_end ();
162 p = input_line_pointer;
166 if (*input_line_pointer != ',')
168 as_bad ("Expected comma after name");
169 ignore_rest_of_line ();
173 ++input_line_pointer;
175 if ((size = get_absolute_expression ()) < 0)
177 as_bad ("BSS length (%d.) <0! Ignored.", size);
178 ignore_rest_of_line ();
183 symbolP = symbol_find_or_make (name);
186 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0)
188 as_bad ("bad .reserve segment: `%s'", input_line_pointer);
192 input_line_pointer += 6;
195 if (*input_line_pointer == ',')
197 ++input_line_pointer;
200 if (*input_line_pointer == '\n')
202 as_bad ("Missing alignment");
206 align = get_absolute_expression ();
207 if (align > max_alignment)
209 align = max_alignment;
210 as_warn ("Alignment too large: %d. assumed.", align);
215 as_warn ("Alignment negative. 0 assumed.");
218 #define SEG_BSS SEG_E2
219 record_alignment (SEG_E2, align);
221 record_alignment (SEG_BSS, align);
224 /* convert to a power of 2 alignment */
225 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
229 as_bad ("Alignment not a power of 2");
230 ignore_rest_of_line ();
232 } /* not a power of two */
237 align = ~((~0) << align); /* Convert to a mask */
238 local_bss_counter = (local_bss_counter + align) & (~align);
239 } /* if has optional alignment */
241 if (S_GET_OTHER (symbolP) == 0
242 && S_GET_DESC (symbolP) == 0
243 && ((S_GET_SEGMENT (symbolP) == SEG_BSS
244 && S_GET_VALUE (symbolP) == local_bss_counter)
245 || !S_IS_DEFINED (symbolP)))
247 S_SET_VALUE (symbolP, local_bss_counter);
248 S_SET_SEGMENT (symbolP, SEG_BSS);
249 symbolP->sy_frag = &bss_address_frag;
250 local_bss_counter += size;
254 as_warn ("Ignoring attempt to re-define symbol from %d. to %d.",
255 S_GET_VALUE (symbolP), local_bss_counter);
256 } /* if not redefining */
258 demand_empty_rest_of_line ();
269 register symbolS *symbolP;
271 name = input_line_pointer;
272 c = get_symbol_end ();
273 /* just after name is now '\0' */
274 p = input_line_pointer;
277 if (*input_line_pointer != ',')
279 as_bad ("Expected comma after symbol-name");
280 ignore_rest_of_line ();
283 input_line_pointer++; /* skip ',' */
284 if ((temp = get_absolute_expression ()) < 0)
286 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
287 ignore_rest_of_line ();
291 symbolP = symbol_find_or_make (name);
293 if (S_IS_DEFINED (symbolP))
295 as_bad ("Ignoring attempt to re-define symbol");
296 ignore_rest_of_line ();
299 if (S_GET_VALUE (symbolP) != 0)
301 if (S_GET_VALUE (symbolP) != temp)
303 as_warn ("Length of .comm \"%s\" is already %d. Not changed to %d.",
304 S_GET_NAME (symbolP), S_GET_VALUE (symbolP), temp);
309 S_SET_VALUE (symbolP, temp);
310 S_SET_EXTERNAL (symbolP);
312 know (symbolP->sy_frag == &zero_address_frag);
313 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
314 && strncmp (input_line_pointer, ",\"data\"", 7) != 0)
316 p = input_line_pointer;
317 while (*p && *p != '\n')
321 as_bad ("bad .common segment: `%s'", input_line_pointer);
325 input_line_pointer += 6 + (input_line_pointer[2] == 'd'); /* Skip either */
326 demand_empty_rest_of_line ();
334 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
336 input_line_pointer += 6;
340 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
342 input_line_pointer += 6;
346 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
348 input_line_pointer += 7;
352 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
354 input_line_pointer += 5;
355 /* We only support 2 segments -- text and data -- for now, so
356 things in the "bss segment" will have to go into data for now.
357 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
358 subseg_new (SEG_DATA, 255); /* FIXME-SOMEDAY */
361 as_bad ("Unknown segment type");
362 demand_empty_rest_of_line ();
369 subseg_new (SEG_DATA, 1);
370 demand_empty_rest_of_line ();
377 extern char is_end_of_line[];
379 while (!is_end_of_line[*input_line_pointer])
381 ++input_line_pointer;
383 ++input_line_pointer;
387 /* start-sanitize-v9 */
389 struct priv_reg_entry
394 struct priv_reg_entry priv_reg_table[] =
413 {"", -1}, /* end marker */
418 struct priv_reg_entry *p, *q;
420 return strcmp (q->name, p->name);
424 /* end-sanitize-v9 */
426 /* This function is called once, at assembler startup time. It should
427 set up all the tables, etc. that the MD part of the assembler will need. */
431 register char *retval = NULL;
433 register unsigned int i = 0;
435 op_hash = hash_new ();
437 as_fatal ("Virtual memory exhausted");
439 while (i < NUMOPCODES)
441 const char *name = sparc_opcodes[i].name;
442 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
443 if (retval != NULL && *retval != '\0')
445 fprintf (stderr, "internal error: can't hash `%s': %s\n",
446 sparc_opcodes[i].name, retval);
451 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
453 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
454 sparc_opcodes[i].name, sparc_opcodes[i].args);
459 while (i < NUMOPCODES
460 && !strcmp (sparc_opcodes[i].name, name));
464 as_fatal ("Broken assembler. No assembly attempted.");
466 for (i = '0'; i < '8'; ++i)
468 for (i = '0'; i <= '9'; ++i)
470 for (i = 'a'; i <= 'f'; ++i)
471 toHex[i] = i + 10 - 'a';
472 for (i = 'A'; i <= 'F'; ++i)
473 toHex[i] = i + 10 - 'A';
475 /* start-sanitize-v9 */
477 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
478 sizeof (priv_reg_table[0]), cmp_reg_entry);
480 /* end-sanitize-v9 */
499 /* See if "set" operand is absolute and small; skip sethi if so. */
500 if (special_case == SPECIAL_CASE_SET && the_insn.exp.X_seg == SEG_ABSOLUTE)
502 if (the_insn.exp.X_add_number >= -(1 << 12)
503 && the_insn.exp.X_add_number < (1 << 12))
505 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
506 | (the_insn.opcode & 0x3E000000) /* dest reg */
507 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
508 special_case = 0; /* No longer special */
509 the_insn.reloc = NO_RELOC; /* No longer relocated */
514 /* put out the opcode */
515 md_number_to_chars (toP, the_insn.opcode, 4);
517 /* put out the symbol-dependent stuff */
518 if (the_insn.reloc != NO_RELOC)
520 fix_new (frag_now, /* which frag */
521 (toP - frag_now->fr_literal), /* where */
523 the_insn.exp.X_add_symbol,
524 the_insn.exp.X_subtract_symbol,
525 the_insn.exp.X_add_number,
529 switch (special_case)
532 case SPECIAL_CASE_SET:
534 assert (the_insn.reloc == RELOC_HI22);
535 /* See if "set" operand has no low-order bits; skip OR if so. */
536 if (the_insn.exp.X_seg == SEG_ABSOLUTE
537 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
540 rsd = (the_insn.opcode >> 25) & 0x1f;
541 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
542 md_number_to_chars (toP, the_insn.opcode, 4);
543 fix_new (frag_now, /* which frag */
544 (toP - frag_now->fr_literal), /* where */
546 the_insn.exp.X_add_symbol,
547 the_insn.exp.X_subtract_symbol,
548 the_insn.exp.X_add_number,
553 case SPECIAL_CASE_FDIV:
554 /* According to information leaked from Sun, the "fdiv" instructions
555 on early SPARC machines would produce incorrect results sometimes.
556 The workaround is to add an fmovs of the destination register to
557 itself just after the instruction. This was true on machines
558 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
560 assert (the_insn.reloc == NO_RELOC);
562 rsd = (the_insn.opcode >> 25) & 0x1f;
563 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
564 md_number_to_chars (toP, the_insn.opcode, 4);
571 as_fatal ("failed sanity check.");
573 } /* md_assemble() */
579 char *error_message = "";
583 struct sparc_opcode *insn;
585 unsigned long opcode;
586 unsigned int mask = 0;
589 long immediate_max = 0;
591 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
609 as_bad ("Unknown opcode: `%s'", str);
612 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
614 as_bad ("Unknown opcode: `%s'", str);
624 opcode = insn->match;
625 memset (&the_insn, '\0', sizeof (the_insn));
626 the_insn.reloc = NO_RELOC;
629 * Build the opcode, checking as we go to make
630 * sure that the operands match
632 for (args = insn->args;; ++args)
637 /* start-sanitize-v9 */
641 /* Load is 0; Store is 1.
642 We compute the mask based on the values
643 we find in S. OK is set set
644 if we see something we don't like. */
653 if (!(lo = (s[0] == 'S')))
655 if (!(hi = (s[1] == 'S')))
657 mask |= (1 << ((hi << 1) | lo));
662 /* Parse a number, somehow. */
670 error_message = "unrecognizable mmask";
673 opcode |= SIMM13 (mask);
678 /* Parse a prefetch function. */
681 int prefetch_fcn = 0;
684 if (!strncmp (s, "n_reads", 7))
685 prefetch_fcn = 0, s += 7;
686 else if (!strncmp (s, "one_read", 8))
687 prefetch_fcn = 1, s += 8;
688 else if (!strncmp (s, "n_writes", 8))
689 prefetch_fcn = 2, s += 8;
690 else if (!strncmp (s, "one_write", 9))
691 prefetch_fcn = 3, s += 9;
692 else if (!strncmp (s, "page", 4))
693 prefetch_fcn = 4, s += 4;
696 error_message = "unrecognizable prefetch fucntion";
702 /* Parse a number, somehow. */
703 error_message = "unrecognizable prefetch fucntion";
710 /* Parse a privileged register. */
713 struct priv_reg_entry *p = priv_reg_table;
717 while (p->name[0] > s[0])
719 while (p->name[0] == s[0])
721 len = strlen (p->name);
722 if (strncmp (p->name, s, len) == 0)
726 if (p->name[0] != s[0])
728 error_message = "unrecognizable privileged register";
732 opcode |= (p->regnum << 14);
734 opcode |= (p->regnum << 25);
740 error_message = "unrecognizable privileged register";
744 /* end-sanitize-v9 */
748 if (strncmp (s, "%asr", 4) == 0)
758 num = num * 10 + *s - '0';
762 if (num < 16 || 31 < num)
764 error_message = ": asr number must be between 15 and 31";
768 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
773 error_message = ": expecting %asrN";
775 } /* if %asr followed by a number. */
780 /* start-sanitize-v9 */
783 the_insn.reloc = RELOC_11;
784 immediate_max = 0x03FF;
788 the_insn.reloc = RELOC_10;
789 immediate_max = 0x01FF;
793 the_insn.reloc = RELOC_WDISP2_14;
798 the_insn.reloc = RELOC_WDISP19;
803 if (*s == 'p' && s[1] == 'n')
811 if (*s == 'p' && s[1] == 't')
823 if (strncmp (s, "%icc", 4) == 0)
835 if (strncmp (s, "%xcc", 4) == 0)
847 if (strncmp (s, "%fcc0", 5) == 0)
859 if (strncmp (s, "%fcc1", 5) == 0)
871 if (strncmp (s, "%fcc2", 5) == 0)
883 if (strncmp (s, "%fcc3", 5) == 0)
891 if (strncmp (s, "%pc", 3) == 0)
899 if (strncmp (s, "%tick", 5) == 0)
906 /* end-sanitize-v9 */
908 case '\0': /* end of args */
927 case '[': /* these must match exactly */
935 case '#': /* must be at least one digit */
946 case 'C': /* coprocessor state register */
947 if (strncmp (s, "%csr", 4) == 0)
954 case 'b': /* next operand is a coprocessor register */
957 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
962 mask = 10 * (mask - '0') + (*s++ - '0');
976 opcode |= mask << 14;
984 opcode |= mask << 25;
990 case 'r': /* next operand must be a register */
999 case 'f': /* frame pointer */
1007 case 'g': /* global register */
1008 if (isoctal (c = *s++))
1015 case 'i': /* in register */
1016 if (isoctal (c = *s++))
1018 mask = c - '0' + 24;
1023 case 'l': /* local register */
1024 if (isoctal (c = *s++))
1026 mask = (c - '0' + 16);
1031 case 'o': /* out register */
1032 if (isoctal (c = *s++))
1034 mask = (c - '0' + 8);
1039 case 's': /* stack pointer */
1047 case 'r': /* any register */
1048 if (!isdigit (c = *s++))
1065 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1081 * Got the register, now figure out where
1082 * it goes in the opcode.
1088 opcode |= mask << 14;
1096 opcode |= mask << 25;
1100 opcode |= (mask << 25) | (mask << 14);
1106 case 'e': /* next operand is a floating point register */
1122 /* start-sanitize-v9 */
1124 && ((format = *s) == 'f'
1128 /* end-sanitize-v9 */
1129 && ((format = *s) == 'f')
1131 /* start-sanitize-v9 */
1133 /* end-sanitize-v9 */
1139 for (mask = 0; isdigit (*s); ++s)
1141 mask = 10 * mask + (*s - '0');
1142 } /* read the number */
1150 } /* register must be even numbered */
1158 } /* register must be multiple of 4 */
1164 error_message = ": There are only 32 f registers; [0-31]";
1167 /* start-sanitize-v9 */
1176 error_message = ": There are only 32 d registers [0, 2, ... 62].";
1181 error_message = ": Only even numbered d registers exist.";
1186 else if (format == 'q')
1191 ": There are only 16 q registers [0, 4, ... 60].";
1197 ": Only q registers evenly divisible by four exist.";
1204 } /* depending on format */
1209 } /* wrap high bit */
1211 /* end-sanitize-v9 */
1212 } /* if not an 'f' register. */
1221 opcode |= RS1 (mask);
1228 opcode |= RS2 (mask);
1234 opcode |= RD (mask);
1243 if (strncmp (s, "%fsr", 4) == 0)
1250 case 'h': /* high 22 bits */
1251 the_insn.reloc = RELOC_HI22;
1254 case 'l': /* 22 bit PC relative immediate */
1255 the_insn.reloc = RELOC_WDISP22;
1259 case 'L': /* 30 bit immediate */
1260 the_insn.reloc = RELOC_WDISP30;
1264 case 'n': /* 22 bit immediate */
1265 the_insn.reloc = RELOC_22;
1268 case 'i': /* 13 bit immediate */
1269 the_insn.reloc = RELOC_BASE13;
1270 immediate_max = 0x0FFF;
1279 if ((c = s[1]) == 'h' && s[2] == 'i')
1281 the_insn.reloc = RELOC_HI22;
1284 else if (c == 'l' && s[2] == 'o')
1286 the_insn.reloc = RELOC_LO10;
1288 /* start-sanitize-v9 */
1295 the_insn.reloc = RELOC_HHI22;
1303 the_insn.reloc = RELOC_HLO10;
1306 /* end-sanitize-v9 */
1311 /* Note that if the getExpression() fails, we
1312 will still have created U entries in the
1313 symbol table for the 'symbols' in the input
1314 string. Try not to create U symbols for
1317 /* This stuff checks to see if the
1318 expression ends in +%reg If it does,
1319 it removes the register from the
1320 expression, and re-sets 's' to point
1321 to the right place */
1325 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1327 if (s1 != s && isdigit (s1[-1]))
1329 if (s1[-2] == '%' && s1[-3] == '+')
1333 (void) getExpression (s);
1338 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1342 (void) getExpression (s);
1349 (void) getExpression (s);
1352 /* Check for invalid constant values. Don't
1353 warn if constant was inside %hi or %lo,
1354 since these truncate the constant to
1356 if (immediate_max != 0
1357 && the_insn.reloc != RELOC_LO10
1358 && the_insn.reloc != RELOC_HI22
1359 /* start-sanitize-v9 */
1361 && the_insn.reloc != RELOC_HLO10
1362 && the_insn.reloc != RELOC_HHI22
1364 /* end-sanitize-v9 */
1365 && the_insn.exp.X_add_symbol == 0
1366 && the_insn.exp.X_subtract_symbol == 0
1367 && the_insn.exp.X_seg == SEG_ABSOLUTE
1368 && (the_insn.exp.X_add_number > immediate_max
1369 || the_insn.exp.X_add_number < ~immediate_max))
1370 as_bad ("constant value must be between %ld and %ld",
1371 ~immediate_max, immediate_max);
1372 /* Reset to prevent extraneous range check. */
1387 char *push = input_line_pointer;
1390 input_line_pointer = s;
1392 if (expression (&e) == SEG_ABSOLUTE)
1394 opcode |= e.X_add_number << 5;
1395 s = input_line_pointer;
1396 input_line_pointer = push;
1401 } /* alternate space */
1404 if (strncmp (s, "%psr", 4) == 0)
1411 case 'q': /* floating point queue */
1412 if (strncmp (s, "%fq", 3) == 0)
1419 case 'Q': /* coprocessor queue */
1420 if (strncmp (s, "%cq", 3) == 0)
1428 if (strcmp (str, "set") == 0)
1430 special_case = SPECIAL_CASE_SET;
1433 else if (strncmp (str, "fdiv", 4) == 0)
1435 special_case = SPECIAL_CASE_FDIV;
1440 /* start-sanitize-v9 */
1443 if (strncmp (s, "%asi", 4) != 0)
1449 if (strncmp (s, "%fprs", 5) != 0)
1455 if (strncmp (s, "%ccr", 4) != 0)
1460 /* end-sanitize-v9 */
1463 if (strncmp (s, "%tbr", 4) != 0)
1469 if (strncmp (s, "%wim", 4) != 0)
1475 if (strncmp (s, "%y", 2) != 0)
1481 as_fatal ("failed sanity check.");
1482 } /* switch on arg code */
1484 } /* for each arg that we expect */
1488 /* Args don't match. */
1489 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1490 && !strcmp (insn->name, insn[1].name))
1498 as_bad ("Illegal operands%s", error_message);
1504 if (insn->architecture > current_architecture)
1506 if ((!architecture_requested || warn_on_bump)
1508 /* start-sanitize-v9 */
1510 !ARCHITECTURES_CONFLICT_P (current_architecture,
1513 /* end-sanitize-v9 */
1515 /* start-sanitize-v9 */
1517 /* end-sanitize-v9 */
1522 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1523 architecture_pname[current_architecture],
1524 architecture_pname[insn->architecture],
1528 current_architecture = insn->architecture;
1532 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1534 architecture_pname[insn->architecture],
1535 architecture_pname[current_architecture]);
1537 } /* if bump ok else error */
1538 } /* if architecture higher */
1542 } /* forever looking for a match */
1544 the_insn.opcode = opcode;
1555 save_in = input_line_pointer;
1556 input_line_pointer = str;
1557 switch (seg = expression (&the_insn.exp))
1565 case SEG_DIFFERENCE:
1571 the_insn.error = "bad segment";
1572 expr_end = input_line_pointer;
1573 input_line_pointer = save_in;
1576 expr_end = input_line_pointer;
1577 input_line_pointer = save_in;
1579 } /* getExpression() */
1583 This is identical to the md_atof in m68k.c. I think this is right,
1586 Turn a string in input_line_pointer into a floating point constant of type
1587 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1588 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1591 /* Equal to MAX_PRECISION in atof-ieee.c */
1592 #define MAX_LITTLENUMS 6
1595 md_atof (type, litP, sizeP)
1601 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1602 LITTLENUM_TYPE *wordP;
1635 return "Bad call to MD_ATOF()";
1637 t = atof_ieee (input_line_pointer, type, words);
1639 input_line_pointer = t;
1640 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1641 for (wordP = words; prec--;)
1643 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1644 litP += sizeof (LITTLENUM_TYPE);
1646 return ""; /* Someone should teach Dean about null pointers */
1650 * Write out big-endian.
1653 md_number_to_chars (buf, val, n)
1672 as_fatal ("failed sanity check.");
1675 } /* md_number_to_chars() */
1677 /* Apply a fixS to the frags, now that we know the value it ought to
1681 md_apply_fix (fixP, val)
1685 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1687 assert (fixP->fx_size == 4);
1688 assert (fixP->fx_r_type < NO_RELOC);
1690 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1693 * This is a hack. There should be a better way to
1696 if (fixP->fx_r_type == RELOC_WDISP30 && fixP->fx_addsy)
1698 val += fixP->fx_where + fixP->fx_frag->fr_address;
1701 switch (fixP->fx_r_type)
1705 buf[0] = 0; /* val >> 24; */
1706 buf[1] = 0; /* val >> 16; */
1707 buf[2] = 0; /* val >> 8; */
1708 buf[3] = 0; /* val; */
1712 case RELOC_8: /* These don't seem to ever be needed. */
1719 val = (val >>= 2) + 1;
1720 buf[0] |= (val >> 24) & 0x3f;
1721 buf[1] = (val >> 16);
1726 /* start-sanitize-v9 */
1729 if (((val > 0) && (val & ~0x7ff))
1730 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1732 as_bad ("relocation overflow.");
1735 buf[2] |= (val >> 8) & 0x7;
1736 buf[3] = val & 0xff;
1740 if (((val > 0) && (val & ~0x3ff))
1741 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1743 as_bad ("relocation overflow.");
1746 buf[2] |= (val >> 8) & 0x3;
1747 buf[3] = val & 0xff;
1750 case RELOC_WDISP2_14:
1751 if (((val > 0) && (val & ~0x3fffc))
1752 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1754 as_bad ("relocation overflow.");
1757 val = (val >>= 2) + 1;
1758 buf[1] |= ((val >> 14) & 0x3) << 3;
1759 buf[2] |= (val >> 8) & 0x3f;
1760 buf[3] = val & 0xff;
1764 if (((val > 0) && (val & ~0x1ffffc))
1765 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
1767 as_bad ("relocation overflow.");
1770 val = (val >>= 2) + 1;
1771 buf[1] |= (val >> 16) & 0x7;
1772 buf[2] = (val >> 8) & 0xff;
1773 buf[3] = val & 0xff;
1778 /* intentional fallthrough */
1780 /* end-sanitize-v9 */
1783 if (!fixP->fx_addsy)
1785 buf[1] |= (val >> 26) & 0x3f;
1797 if (val & ~0x003fffff)
1799 as_bad ("relocation overflow");
1801 buf[1] |= (val >> 16) & 0x3f;
1803 buf[3] = val & 0xff;
1807 if (val & ~0x00001fff)
1809 as_bad ("relocation overflow");
1811 buf[2] |= (val >> 8) & 0x1f;
1812 buf[3] = val & 0xff;
1815 /* start-sanitize-v9 */
1819 /* intentional fallthrough */
1821 /* end-sanitize-v9 */
1824 if (!fixP->fx_addsy)
1826 buf[2] |= (val >> 8) & 0x03;
1833 case RELOC_SFA_BASE:
1834 case RELOC_SFA_OFF13:
1838 if (((val > 0) && (val & ~0x00001fff))
1839 || ((val < 0) && (~(val - 1) & ~0x00001fff)))
1841 as_bad ("relocation overflow");
1843 buf[2] |= (val >> 8) & 0x1f;
1848 val = (val >>= 2) + 1;
1851 buf[1] |= (val >> 16) & 0x3f;
1860 case RELOC_SEGOFF16:
1861 case RELOC_GLOB_DAT:
1862 case RELOC_JMP_SLOT:
1863 case RELOC_RELATIVE:
1868 as_bad ("bad relocation type: 0x%02x", fixP->fx_r_type);
1871 } /* md_apply_fix() */
1873 /* should never be called for sparc */
1875 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1882 as_fatal ("sparc_create_short_jmp\n");
1883 } /* md_create_short_jump() */
1885 /* Translate internal representation of relocation info to target format.
1887 On sparc: first 4 bytes are normal unsigned long address, next three
1888 bytes are index, most sig. byte first. Byte 7 is broken up with
1889 bit 7 as external, bits 6 & 5 unused, and the lower
1890 five bits as relocation type. Next 4 bytes are long addend. */
1891 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
1893 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
1896 relax_addressT segment_address_in_file;
1903 know (fixP->fx_addsy);
1905 if (!S_IS_DEFINED (fixP->fx_addsy))
1908 r_index = fixP->fx_addsy->sy_number;
1913 r_index = S_GET_TYPE (fixP->fx_addsy);
1917 md_number_to_chars (where,
1918 r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
1921 /* now the fun stuff */
1922 where[4] = (r_index >> 16) & 0x0ff;
1923 where[5] = (r_index >> 8) & 0x0ff;
1924 where[6] = r_index & 0x0ff;
1925 where[7] = ((r_extern << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
1928 if (fixP->fx_addsy->sy_frag)
1930 r_addend = fixP->fx_addsy->sy_frag->fr_address;
1935 r_addend += fixP->fx_offset - r_address;
1939 r_addend = fixP->fx_addnumber;
1942 md_number_to_chars (&where[8], r_addend, 4);
1945 } /* tc_aout_fix_to_chars() */
1947 /* should never be called for sparc */
1949 md_convert_frag (headers, fragP)
1950 object_headers *headers;
1951 register fragS *fragP;
1953 as_fatal ("sparc_convert_frag\n");
1954 } /* md_convert_frag() */
1956 /* should never be called for sparc */
1958 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1960 long from_addr, to_addr;
1964 as_fatal ("sparc_create_long_jump\n");
1965 } /* md_create_long_jump() */
1967 /* should never be called for sparc */
1969 md_estimate_size_before_relax (fragP, segtype)
1973 as_fatal ("sparc_estimate_size_before_relax\n");
1975 } /* md_estimate_size_before_relax() */
1978 /* for debugging only */
1981 struct sparc_it *insn;
2014 fprintf (stderr, "ERROR: %s\n");
2016 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2017 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2018 fprintf (stderr, "exp = {\n");
2019 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2020 ((insn->exp.X_add_symbol != NULL)
2021 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2022 ? S_GET_NAME (insn->exp.X_add_symbol)
2025 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2026 ((insn->exp.X_subtract_symbol != NULL)
2027 ? (S_GET_NAME (insn->exp.X_subtract_symbol)
2028 ? S_GET_NAME (insn->exp.X_subtract_symbol)
2031 fprintf (stderr, "\t\tX_add_number = %d\n",
2032 insn->exp.X_add_number);
2033 fprintf (stderr, "}\n");
2035 } /* print_insn() */
2039 /* Set the hook... */
2041 /* void emit_sparc_reloc();
2042 void (*md_emit_relocations)() = emit_sparc_reloc; */
2047 * Sparc/AM29K relocations are completely different, so it needs
2048 * this machine dependent routine to emit them.
2050 #if defined(OBJ_AOUT) || defined(OBJ_BOUT)
2052 emit_sparc_reloc (fixP, segment_address_in_file)
2053 register fixS *fixP;
2054 relax_addressT segment_address_in_file;
2056 struct reloc_info_generic ri;
2057 register symbolS *symbolP;
2058 extern char *next_object_file_charP;
2059 /* long add_number; */
2061 memset ((char *) &ri, '\0', sizeof (ri));
2062 for (; fixP; fixP = fixP->fx_next)
2065 if (fixP->fx_r_type >= NO_RELOC)
2067 as_fatal ("fixP->fx_r_type = %d\n", fixP->fx_r_type);
2070 if ((symbolP = fixP->fx_addsy) != NULL)
2072 ri.r_address = fixP->fx_frag->fr_address +
2073 fixP->fx_where - segment_address_in_file;
2074 if ((S_GET_TYPE (symbolP)) == N_UNDF)
2077 ri.r_index = symbolP->sy_number;
2082 ri.r_index = S_GET_TYPE (symbolP);
2084 if (symbolP && symbolP->sy_frag)
2086 ri.r_addend = symbolP->sy_frag->fr_address;
2088 ri.r_type = fixP->fx_r_type;
2091 /* ri.r_addend -= fixP->fx_where; */
2092 ri.r_addend -= ri.r_address;
2096 ri.r_addend = fixP->fx_addnumber;
2099 md_ri_to_chars (next_object_file_charP, &ri);
2100 next_object_file_charP += md_reloc_size;
2104 } /* emit_sparc_reloc() */
2106 #endif /* aout or bout */
2107 #endif /* comment */
2111 * Invocation line includes a switch not recognized by the base assembler.
2112 * See if it's a processor-specific option. These are:
2115 * Warn on architecture bumps. See also -A.
2117 * -Av6, -Av7, -Av8, -Asparclite
2118 * Select the architecture. Instructions or features not
2119 * supported by the selected architecture cause fatal errors.
2121 * The default is to start at v6, and bump the architecture up
2122 * whenever an instruction is seen at a higher level.
2124 * If -bump is specified, a warning is printing when bumping to
2127 * If an architecture is specified, all instructions must match
2128 * that architecture. Any higher level instructions are flagged
2131 * if both an architecture and -bump are specified, the
2132 * architecture starts at the specified level, but bumps are
2136 * Bumping between incompatible architectures is always an
2137 * error. For example, from sparclite to v9.
2140 /* start-sanitize-v9 */
2141 /* There is also a -Av9 architecture option. xoxorich. */
2142 /* end-sanitize-v9 */
2144 md_parse_option (argP, cntP, vecP)
2152 if (!strcmp (*argP, "bump"))
2157 else if (**argP == 'A')
2161 for (arch = architecture_pname; *arch != NULL; ++arch)
2163 if (strcmp (p, *arch) == 0)
2166 } /* found a match */
2167 } /* walk the pname table */
2171 as_bad ("unknown architecture: %s", p);
2175 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2176 architecture_requested = 1;
2181 /* Unknown option */
2185 **argP = '\0'; /* Done parsing this switch */
2187 } /* md_parse_option() */
2189 /* We have no need to default values of symbols. */
2193 md_undefined_symbol (name)
2197 } /* md_undefined_symbol() */
2199 /* Parse an operand that is machine-specific.
2200 We just return without modifying the expression if we have nothing
2205 md_operand (expressionP)
2206 expressionS *expressionP;
2208 } /* md_operand() */
2210 /* Round up a section size to the appropriate boundary. */
2212 md_section_align (segment, size)
2216 return (size + 7) & ~7; /* Round all sects to multiple of 8 */
2217 } /* md_section_align() */
2219 /* Exactly what point is a PC-relative offset relative TO?
2220 On the sparc, they're relative to the address of the offset, plus
2221 its size. This gets us to the following instruction.
2222 (??? Is this right? FIXME-SOON) */
2224 md_pcrel_from (fixP)
2227 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2228 } /* md_pcrel_from() */
2231 tc_aout_pre_write_hook (headers)
2232 object_headers *headers;
2234 H_SET_VERSION (headers, 1);
2236 } /* tc_aout_pre_write_hook() */
2245 /* end of tc-sparc.c */