(sparc_ip): Initialize `len' variable to make gcc shut up.
[deliverable/binutils-gdb.git] / gas / config / tc-sparc.c
1 /* tc-sparc.c -- Assemble for the SPARC
2 Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
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)
9 any later version.
10
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.
15
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. */
19
20 #define cypress 1234
21
22 #include <stdio.h>
23 #include <ctype.h>
24
25 #include "as.h"
26
27 /* careful, this file includes data *declarations* */
28 #include "opcode/sparc.h"
29
30 void md_begin ();
31 void md_end ();
32 void md_number_to_chars ();
33 void md_assemble ();
34 char *md_atof ();
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 ();
41
42 static enum sparc_architecture current_architecture = v6;
43 static int architecture_requested;
44 static int warn_on_bump;
45
46 extern int target_big_endian;
47
48 const relax_typeS md_relax_table[1];
49
50 /* handle of the OPCODE hash table */
51 static struct hash_control *op_hash = NULL;
52
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 */
57 #ifndef NO_V9
58 static void s_xword ();
59 #endif
60 /* end-sanitize-v9 */
61
62 /* Ugly hack to keep non-BFD version working. */
63 #ifndef BFD_ASSEMBLER
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
75 #endif
76
77 const pseudo_typeS md_pseudo_table[] =
78 {
79 {"align", s_align_bytes, 0}, /* Defaulting is invalid (0) */
80 {"common", s_common, 0},
81 {"global", s_globl, 0},
82 {"half", cons, 2},
83 #ifdef OBJ_ELF
84 {"local", s_local, 0},
85 #endif
86 {"optim", s_ignore, 0},
87 {"proc", s_proc, 0},
88 {"reserve", s_reserve, 0},
89 {"seg", s_seg, 0},
90 {"skip", s_space, 0},
91 {"word", cons, 4},
92 /* start-sanitize-v9 */
93 #ifndef NO_V9
94 {"xword", s_xword, 0},
95 #endif
96 /* end-sanitize-v9 */
97 {NULL, 0, 0},
98 };
99
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 */
103
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 */
107
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[] = "#";
117
118 const char line_separator_chars[] = "";
119
120 /* Chars that can be used to separate mant from exp in floating point nums */
121 const char EXP_CHARS[] = "eE";
122
123 /* Chars that mean this number is a floating point constant */
124 /* As in 0f12.456 */
125 /* or 0d1.2345e12 */
126 const char FLT_CHARS[] = "rRsSfFdDxXpP";
127
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.
131 */
132
133 static unsigned char octal[256];
134 #define isoctal(c) octal[c]
135 static unsigned char toHex[256];
136
137 struct sparc_it
138 {
139 char *error;
140 unsigned long opcode;
141 struct nlist *nlistp;
142 expressionS exp;
143 int pcrel;
144 #ifdef BFD_ASSEMBLER
145 bfd_reloc_code_real_type reloc;
146 #else
147 enum reloc_type reloc;
148 #endif
149 };
150
151 struct sparc_it the_insn, set_insn;
152
153 #if 0
154 static void print_insn PARAMS ((struct sparc_it *insn));
155 #endif
156 static int getExpression PARAMS ((char *str));
157
158 static char *expr_end;
159 static int special_case;
160
161 /*
162 * Instructions that require wierd handling because they're longer than
163 * 4 bytes.
164 */
165 #define SPECIAL_CASE_SET 1
166 #define SPECIAL_CASE_FDIV 2
167
168 /*
169 * sort of like s_lcomm
170 *
171 */
172 static int max_alignment = 15;
173
174 static void
175 s_reserve ()
176 {
177 char *name;
178 char *p;
179 char c;
180 int align;
181 int size;
182 int temp;
183 symbolS *symbolP;
184
185 name = input_line_pointer;
186 c = get_symbol_end ();
187 p = input_line_pointer;
188 *p = c;
189 SKIP_WHITESPACE ();
190
191 if (*input_line_pointer != ',')
192 {
193 as_bad ("Expected comma after name");
194 ignore_rest_of_line ();
195 return;
196 }
197
198 ++input_line_pointer;
199
200 if ((size = get_absolute_expression ()) < 0)
201 {
202 as_bad ("BSS length (%d.) <0! Ignored.", size);
203 ignore_rest_of_line ();
204 return;
205 } /* bad length */
206
207 *p = 0;
208 symbolP = symbol_find_or_make (name);
209 *p = c;
210
211 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
212 && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
213 {
214 as_bad ("bad .reserve segment: `%s'", input_line_pointer);
215 return;
216 } /* if not bss */
217
218 if (input_line_pointer[2] == '.')
219 input_line_pointer += 7;
220 else
221 input_line_pointer += 6;
222 SKIP_WHITESPACE ();
223
224 if (*input_line_pointer == ',')
225 {
226 ++input_line_pointer;
227
228 SKIP_WHITESPACE ();
229 if (*input_line_pointer == '\n')
230 {
231 as_bad ("Missing alignment");
232 return;
233 }
234
235 align = get_absolute_expression ();
236 if (align > max_alignment)
237 {
238 align = max_alignment;
239 as_warn ("Alignment too large: %d. assumed.", align);
240 }
241 else if (align < 0)
242 {
243 align = 0;
244 as_warn ("Alignment negative. 0 assumed.");
245 }
246
247 record_alignment (bss_section, align);
248
249 /* convert to a power of 2 alignment */
250 for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
251
252 if (align != 1)
253 {
254 as_bad ("Alignment not a power of 2");
255 ignore_rest_of_line ();
256 return;
257 } /* not a power of two */
258
259 align = temp;
260 } /* if has optional alignment */
261 else
262 align = 0;
263
264 if ((S_GET_SEGMENT (symbolP) == bss_section
265 || !S_IS_DEFINED (symbolP))
266 #ifdef OBJ_AOUT
267 && S_GET_OTHER (symbolP) == 0
268 && S_GET_DESC (symbolP) == 0
269 #endif
270 )
271 {
272 if (! need_pass_2)
273 {
274 char *p;
275 segT current_seg = now_seg;
276 subsegT current_subseg = now_subseg;
277
278 subseg_set (bss_section, 1); /* switch to bss */
279
280 if (align)
281 frag_align (align, 0); /* do alignment */
282
283 /* detach from old frag */
284 if (S_GET_SEGMENT(symbolP) == bss_section)
285 symbolP->sy_frag->fr_symbol = NULL;
286
287 symbolP->sy_frag = frag_now;
288 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
289 size, (char *)0);
290 *p = 0;
291
292 S_SET_SEGMENT (symbolP, bss_section);
293
294 subseg_set (current_seg, current_subseg);
295 }
296 }
297 else
298 {
299 as_warn("Ignoring attempt to re-define symbol %s.", name);
300 } /* if not redefining */
301
302 demand_empty_rest_of_line ();
303 }
304
305 #ifdef OBJ_ELF
306 /* Currently used only by Solaris 2. */
307 void
308 s_local ()
309 {
310 char *name;
311 int c;
312 symbolS *symbolP;
313
314 do
315 {
316 name = input_line_pointer;
317 c = get_symbol_end ();
318 symbolP = symbol_find_or_make (name);
319 *input_line_pointer = c;
320 SKIP_WHITESPACE ();
321 S_CLEAR_EXTERNAL (symbolP);
322 symbolP->local = 1;
323 if (c == ',')
324 {
325 input_line_pointer++;
326 SKIP_WHITESPACE ();
327 if (*input_line_pointer == '\n')
328 c = '\n';
329 }
330 }
331 while (c == ',');
332 demand_empty_rest_of_line ();
333 }
334 #endif
335
336 static void
337 s_common ()
338 {
339 char *name;
340 char c;
341 char *p;
342 int temp, size;
343 symbolS *symbolP;
344
345 name = input_line_pointer;
346 c = get_symbol_end ();
347 /* just after name is now '\0' */
348 p = input_line_pointer;
349 *p = c;
350 SKIP_WHITESPACE ();
351 if (*input_line_pointer != ',')
352 {
353 as_bad ("Expected comma after symbol-name");
354 ignore_rest_of_line ();
355 return;
356 }
357 input_line_pointer++; /* skip ',' */
358 if ((temp = get_absolute_expression ()) < 0)
359 {
360 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
361 ignore_rest_of_line ();
362 return;
363 }
364 size = temp;
365 *p = 0;
366 symbolP = symbol_find_or_make (name);
367 *p = c;
368 if (S_IS_DEFINED (symbolP))
369 {
370 as_bad ("Ignoring attempt to re-define symbol");
371 ignore_rest_of_line ();
372 return;
373 }
374 if (S_GET_VALUE (symbolP) != 0)
375 {
376 if (S_GET_VALUE (symbolP) != size)
377 {
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);
380 }
381 }
382 else
383 {
384 #ifndef OBJ_ELF
385 S_SET_VALUE (symbolP, size);
386 S_SET_EXTERNAL (symbolP);
387 #endif
388 }
389 know (symbolP->sy_frag == &zero_address_frag);
390 #ifdef OBJ_ELF
391 if (*input_line_pointer != ',')
392 {
393 as_bad ("Expected comma after common length");
394 ignore_rest_of_line ();
395 return;
396 }
397 input_line_pointer++;
398 SKIP_WHITESPACE ();
399 if (*input_line_pointer != '"')
400 {
401 temp = get_absolute_expression ();
402 if (temp > max_alignment)
403 {
404 temp = max_alignment;
405 as_warn ("Common alignment too large: %d. assumed", temp);
406 }
407 else if (temp < 0)
408 {
409 temp = 0;
410 as_warn ("Common alignment negative; 0 assumed");
411 }
412 if (symbolP->local)
413 {
414 segT old_sec = now_seg;
415 int old_subsec = now_subseg;
416 char *p;
417 int align = temp;
418
419 record_alignment (bss_section, align);
420 subseg_set (bss_section, 0);
421 if (align)
422 frag_align (align, 0);
423 if (S_GET_SEGMENT (symbolP) == bss_section)
424 symbolP->sy_frag->fr_symbol = 0;
425 symbolP->sy_frag = frag_now;
426 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
427 (char *) 0);
428 *p = 0;
429 S_SET_SEGMENT (symbolP, bss_section);
430 S_CLEAR_EXTERNAL (symbolP);
431 subseg_set (old_sec, old_subsec);
432 }
433 else
434 {
435 S_SET_VALUE (symbolP, size);
436 S_SET_EXTERNAL (symbolP);
437 /* should be common, but this is how gas does it for now */
438 S_SET_SEGMENT (symbolP, &bfd_und_section);
439 }
440 }
441 else
442 {
443 input_line_pointer++;
444 if (strncmp (input_line_pointer, "bss\"", 4)
445 && strncmp (input_line_pointer, ".bss\"", 5))
446 {
447 input_line_pointer -= 2;
448 goto bad_common_segment;
449 }
450 while (*input_line_pointer++ != '"')
451 ;
452 demand_empty_rest_of_line ();
453 return;
454 }
455 #endif
456 if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
457 && strncmp (input_line_pointer, ",\"data\"", 7) != 0)
458 {
459 bad_common_segment:
460 p = input_line_pointer;
461 while (*p && *p != '\n')
462 p++;
463 c = *p;
464 *p = '\0';
465 as_bad ("bad .common segment %s", input_line_pointer + 1);
466 *p = c;
467 return;
468 }
469 input_line_pointer += 6 + (input_line_pointer[2] == 'd'); /* Skip either */
470 demand_empty_rest_of_line ();
471 return;
472 } /* s_common() */
473
474 static void
475 s_seg ()
476 {
477
478 if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
479 {
480 input_line_pointer += 6;
481 s_text ();
482 return;
483 }
484 if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
485 {
486 input_line_pointer += 6;
487 s_data ();
488 return;
489 }
490 if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
491 {
492 input_line_pointer += 7;
493 s_data1 ();
494 return;
495 }
496 if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
497 {
498 input_line_pointer += 5;
499 /* We only support 2 segments -- text and data -- for now, so
500 things in the "bss segment" will have to go into data for now.
501 You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
502 subseg_set (data_section, 255); /* FIXME-SOMEDAY */
503 return;
504 }
505 as_bad ("Unknown segment type");
506 demand_empty_rest_of_line ();
507 return;
508 } /* s_seg() */
509
510 static void
511 s_data1 ()
512 {
513 subseg_set (data_section, 1);
514 demand_empty_rest_of_line ();
515 return;
516 } /* s_data1() */
517
518 static void
519 s_proc ()
520 {
521 extern char is_end_of_line[];
522
523 while (!is_end_of_line[*input_line_pointer])
524 {
525 ++input_line_pointer;
526 }
527 ++input_line_pointer;
528 return;
529 } /* s_proc() */
530
531 /* start-sanitize-v9 */
532 #ifndef NO_V9
533 static void
534 s_xword ()
535 {
536 SKIP_WHITESPACE ();
537 if (isdigit (*input_line_pointer))
538 big_cons (8);
539 else
540 cons (8);
541 }
542
543 struct priv_reg_entry
544 {
545 char *name;
546 int regnum;
547 };
548
549 struct priv_reg_entry priv_reg_table[] =
550 {
551 {"tpc", 0},
552 {"tnpc", 1},
553 {"tstate", 2},
554 {"tt", 3},
555 {"tick", 4},
556 {"tba", 5},
557 {"pstate", 6},
558 {"tl", 7},
559 {"pil", 8},
560 {"cwp", 9},
561 {"cansave", 10},
562 {"canrestore", 11},
563 {"cleanwin", 12},
564 {"otherwin", 13},
565 {"wstate", 14},
566 {"fq", 15},
567 {"ver", 31},
568 {"", -1}, /* end marker */
569 };
570
571 struct membar_masks
572 {
573 char *name;
574 int len;
575 int mask;
576 };
577
578 #define MEMBAR_MASKS_SIZE 7
579
580 struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
581 {
582 {"Sync", 4, 0x40},
583 {"MemIssue", 8, 0x20},
584 {"Lookaside", 9, 0x10},
585 {"StoreStore", 10, 0x08},
586 {"LoadStore", 9, 0x04},
587 {"StoreLoad", 9, 0x02},
588 {"LoadLoad", 8, 0x01},
589 };
590
591 static int
592 cmp_reg_entry (p, q)
593 struct priv_reg_entry *p, *q;
594 {
595 return strcmp (q->name, p->name);
596 }
597
598 #endif
599 /* end-sanitize-v9 */
600
601 /* This function is called once, at assembler startup time. It should
602 set up all the tables, etc. that the MD part of the assembler will need. */
603 void
604 md_begin ()
605 {
606 register char *retval = NULL;
607 int lose = 0;
608 register unsigned int i = 0;
609
610 op_hash = hash_new ();
611 if (op_hash == NULL)
612 as_fatal ("Virtual memory exhausted");
613
614 while (i < NUMOPCODES)
615 {
616 const char *name = sparc_opcodes[i].name;
617 retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
618 if (retval != NULL && *retval != '\0')
619 {
620 fprintf (stderr, "internal error: can't hash `%s': %s\n",
621 sparc_opcodes[i].name, retval);
622 lose = 1;
623 }
624 do
625 {
626 if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
627 {
628 fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
629 sparc_opcodes[i].name, sparc_opcodes[i].args);
630 lose = 1;
631 }
632 ++i;
633 }
634 while (i < NUMOPCODES
635 && !strcmp (sparc_opcodes[i].name, name));
636 }
637
638 if (lose)
639 as_fatal ("Broken assembler. No assembly attempted.");
640
641 for (i = '0'; i < '8'; ++i)
642 octal[i] = 1;
643 for (i = '0'; i <= '9'; ++i)
644 toHex[i] = i - '0';
645 for (i = 'a'; i <= 'f'; ++i)
646 toHex[i] = i + 10 - 'a';
647 for (i = 'A'; i <= 'F'; ++i)
648 toHex[i] = i + 10 - 'A';
649
650 /* start-sanitize-v9 */
651 #ifndef NO_V9
652 #ifdef sparcv9
653 current_architecture = v9;
654 #endif
655
656 qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
657 sizeof (priv_reg_table[0]), cmp_reg_entry);
658 #endif
659 /* end-sanitize-v9 */
660
661 target_big_endian = 1;
662 } /* md_begin() */
663
664 void
665 md_end ()
666 {
667 return;
668 } /* md_end() */
669
670 void
671 md_assemble (str)
672 char *str;
673 {
674 char *toP;
675 int rsd;
676
677 know (str);
678 sparc_ip (str);
679
680 /* See if "set" operand is absolute and small; skip sethi if so. */
681 if (special_case == SPECIAL_CASE_SET
682 && the_insn.exp.X_seg == absolute_section)
683 {
684 if (the_insn.exp.X_add_number >= -(1 << 12)
685 && the_insn.exp.X_add_number < (1 << 12))
686 {
687 the_insn.opcode = 0x80102000 /* or %g0,imm,... */
688 | (the_insn.opcode & 0x3E000000) /* dest reg */
689 | (the_insn.exp.X_add_number & 0x1FFF); /* imm */
690 special_case = 0; /* No longer special */
691 the_insn.reloc = BFD_RELOC_NONE; /* No longer relocated */
692 }
693 }
694
695 toP = frag_more (4);
696 /* put out the opcode */
697 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
698
699 /* put out the symbol-dependent stuff */
700 if (the_insn.reloc != BFD_RELOC_NONE)
701 {
702 fix_new (frag_now, /* which frag */
703 (toP - frag_now->fr_literal), /* where */
704 4, /* size */
705 the_insn.exp.X_add_symbol,
706 the_insn.exp.X_subtract_symbol,
707 the_insn.exp.X_add_number,
708 the_insn.pcrel,
709 the_insn.reloc);
710 }
711
712 switch (special_case)
713 {
714 case SPECIAL_CASE_SET:
715 special_case = 0;
716 assert (the_insn.reloc == BFD_RELOC_HI22);
717 /* See if "set" operand has no low-order bits; skip OR if so. */
718 if (the_insn.exp.X_seg == absolute_section
719 && ((the_insn.exp.X_add_number & 0x3FF) == 0))
720 return;
721 toP = frag_more (4);
722 rsd = (the_insn.opcode >> 25) & 0x1f;
723 the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
724 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
725 fix_new (frag_now, /* which frag */
726 (toP - frag_now->fr_literal), /* where */
727 4, /* size */
728 the_insn.exp.X_add_symbol,
729 the_insn.exp.X_subtract_symbol,
730 the_insn.exp.X_add_number,
731 the_insn.pcrel,
732 BFD_RELOC_LO10
733 );
734 return;
735
736 case SPECIAL_CASE_FDIV:
737 /* According to information leaked from Sun, the "fdiv" instructions
738 on early SPARC machines would produce incorrect results sometimes.
739 The workaround is to add an fmovs of the destination register to
740 itself just after the instruction. This was true on machines
741 with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
742 special_case = 0;
743 assert (the_insn.reloc == BFD_RELOC_NONE);
744 toP = frag_more (4);
745 rsd = (the_insn.opcode >> 25) & 0x1f;
746 the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd; /* fmovs dest,dest */
747 md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
748 return;
749
750 case 0:
751 return;
752
753 default:
754 as_fatal ("failed sanity check.");
755 }
756 } /* md_assemble() */
757
758 static void
759 sparc_ip (str)
760 char *str;
761 {
762 char *error_message = "";
763 char *s;
764 const char *args;
765 char c;
766 struct sparc_opcode *insn;
767 char *argsStart;
768 unsigned long opcode;
769 unsigned int mask = 0;
770 int match = 0;
771 int comma = 0;
772 long immediate_max = 0;
773
774 for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
775 ;
776 switch (*s)
777 {
778
779 case '\0':
780 break;
781
782 case ',':
783 comma = 1;
784
785 /*FALLTHROUGH */
786
787 case ' ':
788 *s++ = '\0';
789 break;
790
791 default:
792 as_bad ("Unknown opcode: `%s'", str);
793 exit (1);
794 }
795 if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
796 {
797 as_bad ("Unknown opcode: `%s'", str);
798 return;
799 }
800 if (comma)
801 {
802 *--s = ',';
803 }
804 argsStart = s;
805 for (;;)
806 {
807 opcode = insn->match;
808 memset (&the_insn, '\0', sizeof (the_insn));
809 the_insn.reloc = BFD_RELOC_NONE;
810
811 /*
812 * Build the opcode, checking as we go to make
813 * sure that the operands match
814 */
815 for (args = insn->args;; ++args)
816 {
817 switch (*args)
818 {
819
820 /* start-sanitize-v9 */
821 #ifndef NO_V9
822 case 'K':
823 {
824 int mask = 0;
825 int i;
826
827 /* Parse a series of masks. */
828 if (*s == '#')
829 {
830 while (*s == '#')
831 {
832 ++s;
833 for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
834 if (!strncmp (s, membar_masks[i].name,
835 membar_masks[i].len))
836 break;
837 if (i < MEMBAR_MASKS_SIZE)
838 {
839 mask |= membar_masks[i].mask;
840 s += membar_masks[i].len;
841 }
842 else
843 {
844 error_message = ": invalid membar mask name";
845 goto error;
846 }
847 if (*s == '|')
848 ++s;
849 }
850 }
851 else if (isdigit (*s))
852 {
853 while (isdigit (*s))
854 {
855 mask = mask * 10 + *s - '0';
856 ++s;
857 }
858
859 if (mask < 0 || mask > 127)
860 {
861 error_message = ": invalid membar mask number";
862 goto error;
863 }
864 }
865 else
866 {
867 error_message = ": unrecognizable membar mask";
868 goto error;
869 }
870 opcode |= SIMM13 (mask);
871 continue;
872 }
873
874 case '*':
875 {
876 int prefetch_fcn = 0;
877
878 /* Parse a prefetch function. */
879 if (*s == '#')
880 {
881 s += 1;
882 if (!strncmp (s, "n_reads", 7))
883 prefetch_fcn = 0, s += 7;
884 else if (!strncmp (s, "one_read", 8))
885 prefetch_fcn = 1, s += 8;
886 else if (!strncmp (s, "n_writes", 8))
887 prefetch_fcn = 2, s += 8;
888 else if (!strncmp (s, "one_write", 9))
889 prefetch_fcn = 3, s += 9;
890 else if (!strncmp (s, "page", 4))
891 prefetch_fcn = 4, s += 4;
892 else
893 {
894 error_message = ": invalid prefetch function name";
895 goto error;
896 }
897 }
898 else if (isdigit (*s))
899 {
900 while (isdigit (*s))
901 {
902 prefetch_fcn = prefetch_fcn * 10 + *s - '0';
903 ++s;
904 }
905
906 if (prefetch_fcn < 0 || prefetch_fcn > 31)
907 {
908 error_message = ": invalid prefetch function number";
909 goto error;
910 }
911 }
912 else
913 {
914 error_message = ": unrecognizable prefetch function";
915 goto error;
916 }
917 opcode |= RD (prefetch_fcn);
918 continue;
919 }
920
921 case '!':
922 case '?':
923 /* Parse a privileged register. */
924 if (*s == '%')
925 {
926 struct priv_reg_entry *p = priv_reg_table;
927 int len = 9999999; /* init to make gcc happy */
928
929 s += 1;
930 while (p->name[0] > s[0])
931 p++;
932 while (p->name[0] == s[0])
933 {
934 len = strlen (p->name);
935 if (strncmp (p->name, s, len) == 0)
936 break;
937 p++;
938 }
939 if (p->name[0] != s[0])
940 {
941 error_message = ": unrecognizable privileged register";
942 goto error;
943 }
944 if (*args == '?')
945 opcode |= (p->regnum << 14);
946 else
947 opcode |= (p->regnum << 25);
948 s += len;
949 continue;
950 }
951 else
952 {
953 error_message = ": unrecognizable privileged register";
954 goto error;
955 }
956 #endif
957 /* end-sanitize-v9 */
958
959 case 'M':
960 case 'm':
961 if (strncmp (s, "%asr", 4) == 0)
962 {
963 s += 4;
964
965 if (isdigit (*s))
966 {
967 long num = 0;
968
969 while (isdigit (*s))
970 {
971 num = num * 10 + *s - '0';
972 ++s;
973 }
974
975 if (num < 16 || 31 < num)
976 {
977 error_message = ": asr number must be between 15 and 31";
978 goto error;
979 } /* out of range */
980
981 opcode |= (*args == 'M' ? RS1 (num) : RD (num));
982 continue;
983 }
984 else
985 {
986 error_message = ": expecting %asrN";
987 goto error;
988 } /* if %asr followed by a number. */
989
990 } /* if %asr */
991 break;
992
993 /* start-sanitize-v9 */
994 #ifndef NO_V9
995 case 'I':
996 the_insn.reloc = BFD_RELOC_SPARC_11;
997 immediate_max = 0x03FF;
998 goto immediate;
999
1000 case 'j':
1001 the_insn.reloc = BFD_RELOC_SPARC_10;
1002 immediate_max = 0x01FF;
1003 goto immediate;
1004
1005 case 'k':
1006 the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
1007 the_insn.pcrel = 1;
1008 goto immediate;
1009
1010 case 'G':
1011 the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
1012 the_insn.pcrel = 1;
1013 goto immediate;
1014
1015 case 'N':
1016 if (*s == 'p' && s[1] == 'n')
1017 {
1018 s += 2;
1019 continue;
1020 }
1021 break;
1022
1023 case 'T':
1024 if (*s == 'p' && s[1] == 't')
1025 {
1026 s += 2;
1027 continue;
1028 }
1029 break;
1030
1031 case 'z':
1032 if (*s == ' ')
1033 {
1034 ++s;
1035 }
1036 if (strncmp (s, "%icc", 4) == 0)
1037 {
1038 s += 4;
1039 continue;
1040 }
1041 break;
1042
1043 case 'Z':
1044 if (*s == ' ')
1045 {
1046 ++s;
1047 }
1048 if (strncmp (s, "%xcc", 4) == 0)
1049 {
1050 s += 4;
1051 continue;
1052 }
1053 break;
1054
1055 case '6':
1056 if (*s == ' ')
1057 {
1058 ++s;
1059 }
1060 if (strncmp (s, "%fcc0", 5) == 0)
1061 {
1062 s += 5;
1063 continue;
1064 }
1065 break;
1066
1067 case '7':
1068 if (*s == ' ')
1069 {
1070 ++s;
1071 }
1072 if (strncmp (s, "%fcc1", 5) == 0)
1073 {
1074 s += 5;
1075 continue;
1076 }
1077 break;
1078
1079 case '8':
1080 if (*s == ' ')
1081 {
1082 ++s;
1083 }
1084 if (strncmp (s, "%fcc2", 5) == 0)
1085 {
1086 s += 5;
1087 continue;
1088 }
1089 break;
1090
1091 case '9':
1092 if (*s == ' ')
1093 {
1094 ++s;
1095 }
1096 if (strncmp (s, "%fcc3", 5) == 0)
1097 {
1098 s += 5;
1099 continue;
1100 }
1101 break;
1102
1103 case 'P':
1104 if (strncmp (s, "%pc", 3) == 0)
1105 {
1106 s += 3;
1107 continue;
1108 }
1109 break;
1110
1111 case 'W':
1112 if (strncmp (s, "%tick", 5) == 0)
1113 {
1114 s += 5;
1115 continue;
1116 }
1117 break;
1118 #endif /* NO_V9 */
1119 /* end-sanitize-v9 */
1120
1121 case '\0': /* end of args */
1122 if (*s == '\0')
1123 {
1124 match = 1;
1125 }
1126 break;
1127
1128 case '+':
1129 if (*s == '+')
1130 {
1131 ++s;
1132 continue;
1133 }
1134 if (*s == '-')
1135 {
1136 continue;
1137 }
1138 break;
1139
1140 case '[': /* these must match exactly */
1141 case ']':
1142 case ',':
1143 case ' ':
1144 if (*s++ == *args)
1145 continue;
1146 break;
1147
1148 case '#': /* must be at least one digit */
1149 if (isdigit (*s++))
1150 {
1151 while (isdigit (*s))
1152 {
1153 ++s;
1154 }
1155 continue;
1156 }
1157 break;
1158
1159 case 'C': /* coprocessor state register */
1160 if (strncmp (s, "%csr", 4) == 0)
1161 {
1162 s += 4;
1163 continue;
1164 }
1165 break;
1166
1167 case 'b': /* next operand is a coprocessor register */
1168 case 'c':
1169 case 'D':
1170 if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
1171 {
1172 mask = *s++;
1173 if (isdigit (*s))
1174 {
1175 mask = 10 * (mask - '0') + (*s++ - '0');
1176 if (mask >= 32)
1177 {
1178 break;
1179 }
1180 }
1181 else
1182 {
1183 mask -= '0';
1184 }
1185 switch (*args)
1186 {
1187
1188 case 'b':
1189 opcode |= mask << 14;
1190 continue;
1191
1192 case 'c':
1193 opcode |= mask;
1194 continue;
1195
1196 case 'D':
1197 opcode |= mask << 25;
1198 continue;
1199 }
1200 }
1201 break;
1202
1203 case 'r': /* next operand must be a register */
1204 case '1':
1205 case '2':
1206 case 'd':
1207 if (*s++ == '%')
1208 {
1209 switch (c = *s++)
1210 {
1211
1212 case 'f': /* frame pointer */
1213 if (*s++ == 'p')
1214 {
1215 mask = 0x1e;
1216 break;
1217 }
1218 goto error;
1219
1220 case 'g': /* global register */
1221 if (isoctal (c = *s++))
1222 {
1223 mask = c - '0';
1224 break;
1225 }
1226 goto error;
1227
1228 case 'i': /* in register */
1229 if (isoctal (c = *s++))
1230 {
1231 mask = c - '0' + 24;
1232 break;
1233 }
1234 goto error;
1235
1236 case 'l': /* local register */
1237 if (isoctal (c = *s++))
1238 {
1239 mask = (c - '0' + 16);
1240 break;
1241 }
1242 goto error;
1243
1244 case 'o': /* out register */
1245 if (isoctal (c = *s++))
1246 {
1247 mask = (c - '0' + 8);
1248 break;
1249 }
1250 goto error;
1251
1252 case 's': /* stack pointer */
1253 if (*s++ == 'p')
1254 {
1255 mask = 0xe;
1256 break;
1257 }
1258 goto error;
1259
1260 case 'r': /* any register */
1261 if (!isdigit (c = *s++))
1262 {
1263 goto error;
1264 }
1265 /* FALLTHROUGH */
1266 case '0':
1267 case '1':
1268 case '2':
1269 case '3':
1270 case '4':
1271 case '5':
1272 case '6':
1273 case '7':
1274 case '8':
1275 case '9':
1276 if (isdigit (*s))
1277 {
1278 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
1279 {
1280 goto error;
1281 }
1282 }
1283 else
1284 {
1285 c -= '0';
1286 }
1287 mask = c;
1288 break;
1289
1290 default:
1291 goto error;
1292 }
1293 /*
1294 * Got the register, now figure out where
1295 * it goes in the opcode.
1296 */
1297 switch (*args)
1298 {
1299
1300 case '1':
1301 opcode |= mask << 14;
1302 continue;
1303
1304 case '2':
1305 opcode |= mask;
1306 continue;
1307
1308 case 'd':
1309 opcode |= mask << 25;
1310 continue;
1311
1312 case 'r':
1313 opcode |= (mask << 25) | (mask << 14);
1314 continue;
1315 }
1316 }
1317 break;
1318
1319 case 'e': /* next operand is a floating point register */
1320 case 'v':
1321 case 'V':
1322
1323 case 'f':
1324 case 'B':
1325 case 'R':
1326
1327 case 'g':
1328 case 'H':
1329 case 'J':
1330 {
1331 char format;
1332
1333 if (*s++ == '%'
1334 && ((format = *s) == 'f')
1335 && isdigit (*++s))
1336 {
1337 for (mask = 0; isdigit (*s); ++s)
1338 {
1339 mask = 10 * mask + (*s - '0');
1340 } /* read the number */
1341
1342 if ((*args == 'v'
1343 || *args == 'B'
1344 || *args == 'H')
1345 && (mask & 1))
1346 {
1347 break;
1348 } /* register must be even numbered */
1349
1350 if ((*args == 'V'
1351 || *args == 'R'
1352 || *args == 'J')
1353 && (mask & 3))
1354 {
1355 break;
1356 } /* register must be multiple of 4 */
1357
1358 /* start-sanitize-v9 */
1359 #ifndef NO_V9
1360 if (mask >= 64)
1361 {
1362 error_message = ": There are only 64 f registers; [0-63]";
1363 goto error;
1364 } /* on error */
1365 if (mask >= 32)
1366 {
1367 mask -= 31;
1368 } /* wrap high bit */
1369 #else
1370 /* end-sanitize-v9 */
1371 if (mask >= 32)
1372 {
1373 error_message = ": There are only 32 f registers; [0-31]";
1374 goto error;
1375 } /* on error */
1376 /* start-sanitize-v9 */
1377 #endif
1378 /* end-sanitize-v9 */
1379 }
1380 else
1381 {
1382 break;
1383 } /* if not an 'f' register. */
1384
1385 switch (*args)
1386 {
1387
1388 case 'v':
1389 case 'V':
1390 case 'e':
1391 opcode |= RS1 (mask);
1392 continue;
1393
1394
1395 case 'f':
1396 case 'B':
1397 case 'R':
1398 opcode |= RS2 (mask);
1399 continue;
1400
1401 case 'g':
1402 case 'H':
1403 case 'J':
1404 opcode |= RD (mask);
1405 continue;
1406 } /* pack it in. */
1407
1408 know (0);
1409 break;
1410 } /* float arg */
1411
1412 case 'F':
1413 if (strncmp (s, "%fsr", 4) == 0)
1414 {
1415 s += 4;
1416 continue;
1417 }
1418 break;
1419
1420 case 'h': /* high 22 bits */
1421 the_insn.reloc = BFD_RELOC_HI22;
1422 goto immediate;
1423
1424 case 'l': /* 22 bit PC relative immediate */
1425 the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
1426 the_insn.pcrel = 1;
1427 goto immediate;
1428
1429 case 'L': /* 30 bit immediate */
1430 the_insn.reloc = BFD_RELOC_32_PCREL_S2;
1431 the_insn.pcrel = 1;
1432 goto immediate;
1433
1434 case 'n': /* 22 bit immediate */
1435 the_insn.reloc = BFD_RELOC_SPARC22;
1436 goto immediate;
1437
1438 case 'i': /* 13 bit immediate */
1439 /* What's the difference between base13 and 13? */
1440 the_insn.reloc = BFD_RELOC_SPARC_BASE13;
1441 immediate_max = 0x0FFF;
1442
1443 /*FALLTHROUGH */
1444
1445 immediate:
1446 if (*s == ' ')
1447 s++;
1448 if (*s == '%')
1449 {
1450 if ((c = s[1]) == 'h' && s[2] == 'i')
1451 {
1452 the_insn.reloc = BFD_RELOC_HI22;
1453 s += 3;
1454 }
1455 else if (c == 'l' && s[2] == 'o')
1456 {
1457 the_insn.reloc = BFD_RELOC_LO10;
1458 s += 3;
1459 /* start-sanitize-v9 */
1460 #ifndef NO_V9
1461 }
1462 else if (c == 'u'
1463 && s[2] == 'h'
1464 && s[3] == 'i')
1465 {
1466 the_insn.reloc = BFD_RELOC_SPARC_HH22;
1467 s += 4;
1468 }
1469 else if (c == 'u'
1470 && s[2] == 'l'
1471 && s[3] == 'o')
1472 {
1473 the_insn.reloc = BFD_RELOC_SPARC_HM10;
1474 s += 4;
1475 #endif /* NO_V9 */
1476 /* end-sanitize-v9 */
1477 }
1478 else
1479 break;
1480 }
1481 /* Note that if the getExpression() fails, we
1482 will still have created U entries in the
1483 symbol table for the 'symbols' in the input
1484 string. Try not to create U symbols for
1485 registers, etc. */
1486 {
1487 /* This stuff checks to see if the
1488 expression ends in +%reg If it does,
1489 it removes the register from the
1490 expression, and re-sets 's' to point
1491 to the right place */
1492
1493 char *s1;
1494
1495 for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
1496
1497 if (s1 != s && isdigit (s1[-1]))
1498 {
1499 if (s1[-2] == '%' && s1[-3] == '+')
1500 {
1501 s1 -= 3;
1502 *s1 = '\0';
1503 (void) getExpression (s);
1504 *s1 = '+';
1505 s = s1;
1506 continue;
1507 }
1508 else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
1509 {
1510 s1 -= 4;
1511 *s1 = '\0';
1512 (void) getExpression (s);
1513 *s1 = '+';
1514 s = s1;
1515 continue;
1516 }
1517 }
1518 }
1519 (void) getExpression (s);
1520 s = expr_end;
1521
1522 /* Check for invalid constant values. Don't
1523 warn if constant was inside %hi or %lo,
1524 since these truncate the constant to
1525 fit. */
1526 if (immediate_max != 0
1527 && the_insn.reloc != BFD_RELOC_LO10
1528 && the_insn.reloc != BFD_RELOC_HI22
1529 /* start-sanitize-v9 */
1530 #ifndef NO_V9
1531 #ifndef BFD_ASSEMBLER /* the bfd backend doesn't support these relocs yet */
1532 && the_insn.reloc != RELOC_HLO10
1533 && the_insn.reloc != RELOC_HHI22
1534 #endif
1535 #endif
1536 /* end-sanitize-v9 */
1537 && the_insn.exp.X_add_symbol == 0
1538 && the_insn.exp.X_subtract_symbol == 0
1539 && the_insn.exp.X_seg == absolute_section
1540 && (the_insn.exp.X_add_number > immediate_max
1541 || the_insn.exp.X_add_number < ~immediate_max))
1542 as_bad ("constant value must be between %ld and %ld",
1543 ~immediate_max, immediate_max);
1544 /* Reset to prevent extraneous range check. */
1545 immediate_max = 0;
1546
1547 continue;
1548
1549 case 'a':
1550 if (*s++ == 'a')
1551 {
1552 opcode |= ANNUL;
1553 continue;
1554 }
1555 break;
1556
1557 case 'A':
1558 {
1559 /* start-sanitize-v9 */
1560 #ifdef NO_V9
1561 /* end-sanitize-v9 */
1562 char *push = input_line_pointer;
1563 expressionS e;
1564
1565 input_line_pointer = s;
1566
1567 if (expression (&e) == absolute_section)
1568 {
1569 opcode |= e.X_add_number << 5;
1570 s = input_line_pointer;
1571 input_line_pointer = push;
1572 continue;
1573 } /* if absolute */
1574
1575 break;
1576 /* start-sanitize-v9 */
1577 #else
1578 int asi = 0;
1579
1580 /* Parse an asi. */
1581 if (*s == '#')
1582 {
1583 s += 1;
1584 if (!strncmp (s, "ASI_AIUP", 8))
1585 asi = 0x10, s += 8;
1586 else if (!strncmp (s, "ASI_AIUS", 8))
1587 asi = 0x11, s += 8;
1588 else if (!strncmp (s, "ASI_PNF", 7))
1589 asi = 0x82, s += 7;
1590 else if (!strncmp (s, "ASI_SNF", 7))
1591 asi = 0x83, s += 7;
1592 else if (!strncmp (s, "ASI_P", 5))
1593 asi = 0x80, s += 5;
1594 else if (!strncmp (s, "ASI_S", 5))
1595 asi = 0x81, s += 5;
1596 else
1597 {
1598 error_message = ": invalid asi name";
1599 goto error;
1600 }
1601 }
1602 else if (isdigit (*s))
1603 {
1604 char *push = input_line_pointer;
1605 input_line_pointer = s;
1606 asi = get_absolute_expression ();
1607 s = input_line_pointer;
1608 input_line_pointer = push;
1609
1610 if (asi < 0 || asi > 255)
1611 {
1612 error_message = ": invalid asi number";
1613 goto error;
1614 }
1615 }
1616 else
1617 {
1618 error_message = ": unrecognizable asi";
1619 goto error;
1620 }
1621 opcode |= ASI (asi);
1622 continue;
1623 #endif
1624 /* end-sanitize-v9 */
1625 } /* alternate space */
1626
1627 case 'p':
1628 if (strncmp (s, "%psr", 4) == 0)
1629 {
1630 s += 4;
1631 continue;
1632 }
1633 break;
1634
1635 case 'q': /* floating point queue */
1636 if (strncmp (s, "%fq", 3) == 0)
1637 {
1638 s += 3;
1639 continue;
1640 }
1641 break;
1642
1643 case 'Q': /* coprocessor queue */
1644 if (strncmp (s, "%cq", 3) == 0)
1645 {
1646 s += 3;
1647 continue;
1648 }
1649 break;
1650
1651 case 'S':
1652 if (strcmp (str, "set") == 0)
1653 {
1654 special_case = SPECIAL_CASE_SET;
1655 continue;
1656 }
1657 else if (strncmp (str, "fdiv", 4) == 0)
1658 {
1659 special_case = SPECIAL_CASE_FDIV;
1660 continue;
1661 }
1662 break;
1663
1664 /* start-sanitize-v9 */
1665 #ifndef NO_V9
1666 case 'o':
1667 if (strncmp (s, "%asi", 4) != 0)
1668 break;
1669 s += 4;
1670 continue;
1671
1672 case 's':
1673 if (strncmp (s, "%fprs", 5) != 0)
1674 break;
1675 s += 5;
1676 continue;
1677
1678 case 'E':
1679 if (strncmp (s, "%ccr", 4) != 0)
1680 break;
1681 s += 4;
1682 continue;
1683 #endif /* NO_V9 */
1684 /* end-sanitize-v9 */
1685
1686 case 't':
1687 if (strncmp (s, "%tbr", 4) != 0)
1688 break;
1689 s += 4;
1690 continue;
1691
1692 case 'w':
1693 if (strncmp (s, "%wim", 4) != 0)
1694 break;
1695 s += 4;
1696 continue;
1697
1698 case 'y':
1699 if (strncmp (s, "%y", 2) != 0)
1700 break;
1701 s += 2;
1702 continue;
1703
1704 default:
1705 as_fatal ("failed sanity check.");
1706 } /* switch on arg code */
1707 break;
1708 } /* for each arg that we expect */
1709 error:
1710 if (match == 0)
1711 {
1712 /* Args don't match. */
1713 if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
1714 && !strcmp (insn->name, insn[1].name))
1715 {
1716 ++insn;
1717 s = argsStart;
1718 continue;
1719 }
1720 else
1721 {
1722 as_bad ("Illegal operands%s", error_message);
1723 return;
1724 }
1725 }
1726 else
1727 {
1728 if (insn->architecture > current_architecture)
1729 {
1730 if ((!architecture_requested || warn_on_bump)
1731 &&
1732 /* start-sanitize-v9 */
1733 #ifndef NO_V9
1734 !ARCHITECTURES_CONFLICT_P (current_architecture,
1735 insn->architecture)
1736 #else
1737 /* end-sanitize-v9 */
1738 1
1739 /* start-sanitize-v9 */
1740 #endif
1741 /* end-sanitize-v9 */
1742 )
1743 {
1744 if (warn_on_bump)
1745 {
1746 as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
1747 architecture_pname[current_architecture],
1748 architecture_pname[insn->architecture],
1749 str);
1750 } /* if warning */
1751
1752 current_architecture = insn->architecture;
1753 }
1754 else
1755 {
1756 as_bad ("architecture mismatch on \"%s\" (\"%s\"). current architecture is \"%s\"",
1757 str,
1758 architecture_pname[insn->architecture],
1759 architecture_pname[current_architecture]);
1760 return;
1761 } /* if bump ok else error */
1762 } /* if architecture higher */
1763 } /* if no match */
1764
1765 break;
1766 } /* forever looking for a match */
1767
1768 the_insn.opcode = opcode;
1769 return;
1770 } /* sparc_ip() */
1771
1772 static int
1773 getExpression (str)
1774 char *str;
1775 {
1776 char *save_in;
1777 segT seg;
1778
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
1787 || seg == diff_section
1788 || seg == big_section
1789 || seg == absent_section)
1790 /* ok */;
1791 else
1792 {
1793 the_insn.error = "bad segment";
1794 expr_end = input_line_pointer;
1795 input_line_pointer = save_in;
1796 return 1;
1797 }
1798 expr_end = input_line_pointer;
1799 input_line_pointer = save_in;
1800 return 0;
1801 } /* getExpression() */
1802
1803
1804 /*
1805 This is identical to the md_atof in m68k.c. I think this is right,
1806 but I'm not sure.
1807
1808 Turn a string in input_line_pointer into a floating point constant of type
1809 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1810 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1811 */
1812
1813 /* Equal to MAX_PRECISION in atof-ieee.c */
1814 #define MAX_LITTLENUMS 6
1815
1816 char *
1817 md_atof (type, litP, sizeP)
1818 char type;
1819 char *litP;
1820 int *sizeP;
1821 {
1822 int prec;
1823 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1824 LITTLENUM_TYPE *wordP;
1825 char *t;
1826 char *atof_ieee ();
1827
1828 switch (type)
1829 {
1830
1831 case 'f':
1832 case 'F':
1833 case 's':
1834 case 'S':
1835 prec = 2;
1836 break;
1837
1838 case 'd':
1839 case 'D':
1840 case 'r':
1841 case 'R':
1842 prec = 4;
1843 break;
1844
1845 case 'x':
1846 case 'X':
1847 prec = 6;
1848 break;
1849
1850 case 'p':
1851 case 'P':
1852 prec = 6;
1853 break;
1854
1855 default:
1856 *sizeP = 0;
1857 return "Bad call to MD_ATOF()";
1858 }
1859 t = atof_ieee (input_line_pointer, type, words);
1860 if (t)
1861 input_line_pointer = t;
1862 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1863 for (wordP = words; prec--;)
1864 {
1865 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
1866 litP += sizeof (LITTLENUM_TYPE);
1867 }
1868 return 0;
1869 }
1870
1871 /*
1872 * Write out big-endian.
1873 */
1874 void
1875 md_number_to_chars (buf, val, n)
1876 char *buf;
1877 valueT val;
1878 int n;
1879 {
1880
1881 switch (n)
1882 {
1883 /* start-sanitize-v9 */
1884 case 8:
1885 *buf++ = val >> 56;
1886 *buf++ = val >> 48;
1887 *buf++ = val >> 40;
1888 *buf++ = val >> 32;
1889 /* end-sanitize-v9 */
1890 case 4:
1891 *buf++ = val >> 24;
1892 *buf++ = val >> 16;
1893 case 2:
1894 *buf++ = val >> 8;
1895 case 1:
1896 *buf = val;
1897 break;
1898
1899 default:
1900 as_fatal ("failed sanity check.");
1901 }
1902 return;
1903 } /* md_number_to_chars() */
1904
1905 /* Apply a fixS to the frags, now that we know the value it ought to
1906 hold. */
1907
1908 #ifdef BFD_ASSEMBLER
1909 int
1910 #else
1911 void
1912 #endif
1913 md_apply_fix (fixP, value)
1914 fixS *fixP;
1915 #ifdef BFD_ASSEMBLER
1916 valueT *value;
1917 #else
1918 long value;
1919 #endif
1920 {
1921 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1922 offsetT val;
1923
1924 #ifdef BFD_ASSEMBLER
1925 val = *value;
1926 #else
1927 val = value;
1928 #endif
1929
1930 #ifdef BFD_ASSEMBLER
1931 assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
1932 #else
1933 assert (fixP->fx_r_type < NO_RELOC);
1934 #endif
1935
1936 fixP->fx_addnumber = val; /* Remember value for emit_reloc */
1937
1938 /*
1939 * This is a hack. There should be a better way to
1940 * handle this.
1941 */
1942 if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
1943 {
1944 val += fixP->fx_where + fixP->fx_frag->fr_address;
1945 }
1946
1947 switch (fixP->fx_r_type)
1948 {
1949
1950 case BFD_RELOC_32:
1951 buf[0] = 0; /* val >> 24; */
1952 buf[1] = 0; /* val >> 16; */
1953 buf[2] = 0; /* val >> 8; */
1954 buf[3] = 0; /* val; */
1955 break;
1956
1957 case BFD_RELOC_32_PCREL_S2:
1958 val = (val >>= 2) + 1;
1959 buf[0] |= (val >> 24) & 0x3f;
1960 buf[1] = (val >> 16);
1961 buf[2] = val >> 8;
1962 buf[3] = val;
1963 break;
1964
1965 /* start-sanitize-v9 */
1966 #ifndef NO_V9
1967 case BFD_RELOC_SPARC_11:
1968 if (((val > 0) && (val & ~0x7ff))
1969 || ((val < 0) && (~(val - 1) & ~0x7ff)))
1970 {
1971 as_bad ("relocation overflow.");
1972 } /* on overflow */
1973
1974 buf[2] |= (val >> 8) & 0x7;
1975 buf[3] = val & 0xff;
1976 break;
1977
1978 case BFD_RELOC_SPARC_10:
1979 if (((val > 0) && (val & ~0x3ff))
1980 || ((val < 0) && (~(val - 1) & ~0x3ff)))
1981 {
1982 as_bad ("relocation overflow.");
1983 } /* on overflow */
1984
1985 buf[2] |= (val >> 8) & 0x3;
1986 buf[3] = val & 0xff;
1987 break;
1988
1989 case BFD_RELOC_SPARC_WDISP16:
1990 if (((val > 0) && (val & ~0x3fffc))
1991 || ((val < 0) && (~(val - 1) & ~0x3fffc)))
1992 {
1993 as_bad ("relocation overflow.");
1994 } /* on overflow */
1995
1996 val = (val >>= 2) + 1;
1997 buf[1] |= ((val >> 14) & 0x3) << 4;
1998 buf[2] |= (val >> 8) & 0x3f;
1999 buf[3] = val & 0xff;
2000 break;
2001
2002 case BFD_RELOC_SPARC_WDISP19:
2003 if (((val > 0) && (val & ~0x1ffffc))
2004 || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
2005 {
2006 as_bad ("relocation overflow.");
2007 } /* on overflow */
2008
2009 val = (val >>= 2) + 1;
2010 buf[1] |= (val >> 16) & 0x7;
2011 buf[2] = (val >> 8) & 0xff;
2012 buf[3] = val & 0xff;
2013 break;
2014
2015 case BFD_RELOC_SPARC_HH22:
2016 val >>= 32;
2017 /* intentional fallthrough */
2018 #endif /* NO_V9 */
2019 /* end-sanitize-v9 */
2020
2021 /* start-sanitize-v9 */
2022 #ifndef NO_V9
2023 case BFD_RELOC_SPARC_LM22:
2024 #endif
2025 /* end-sanitize-v9 */
2026 case BFD_RELOC_HI22:
2027 if (!fixP->fx_addsy)
2028 {
2029 buf[1] |= (val >> 26) & 0x3f;
2030 buf[2] = val >> 18;
2031 buf[3] = val >> 10;
2032 }
2033 else
2034 {
2035 buf[2] = 0;
2036 buf[3] = 0;
2037 }
2038 break;
2039
2040 case BFD_RELOC_SPARC22:
2041 if (val & ~0x003fffff)
2042 {
2043 as_bad ("relocation overflow");
2044 } /* on overflow */
2045 buf[1] |= (val >> 16) & 0x3f;
2046 buf[2] = val >> 8;
2047 buf[3] = val & 0xff;
2048 break;
2049
2050 case BFD_RELOC_SPARC13:
2051 if (val & ~0x00001fff)
2052 {
2053 as_bad ("relocation overflow");
2054 } /* on overflow */
2055 buf[2] |= (val >> 8) & 0x1f;
2056 buf[3] = val & 0xff;
2057 break;
2058
2059 /* start-sanitize-v9 */
2060 #ifndef NO_V9
2061 case BFD_RELOC_SPARC_HM10:
2062 val >>= 32;
2063 /* intentional fallthrough */
2064 #endif /* NO_V9 */
2065 /* end-sanitize-v9 */
2066
2067 case BFD_RELOC_LO10:
2068 if (!fixP->fx_addsy)
2069 {
2070 buf[2] |= (val >> 8) & 0x03;
2071 buf[3] = val;
2072 }
2073 else
2074 buf[3] = 0;
2075 break;
2076 case BFD_RELOC_SPARC_BASE13:
2077 if (((val > 0) && (val & ~(offsetT)0x00001fff))
2078 || ((val < 0) && (~(val - 1) & ~(offsetT)0x00001fff)))
2079 {
2080 as_bad ("relocation overflow");
2081 }
2082 buf[2] |= (val >> 8) & 0x1f;
2083 buf[3] = val;
2084 break;
2085
2086 case BFD_RELOC_SPARC_WDISP22:
2087 val = (val >>= 2) + 1;
2088 /* FALLTHROUGH */
2089 case BFD_RELOC_SPARC_BASE22:
2090 buf[1] |= (val >> 16) & 0x3f;
2091 buf[2] = val >> 8;
2092 buf[3] = val;
2093 break;
2094
2095 case BFD_RELOC_NONE:
2096 default:
2097 as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
2098 break;
2099 }
2100
2101 #ifdef BFD_ASSEMBLER
2102 return 1;
2103 #endif
2104 }
2105
2106 /* should never be called for sparc */
2107 void
2108 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2109 char *ptr;
2110 addressT from_addr;
2111 addressT to_addr;
2112 fragS *frag;
2113 symbolS *to_symbol;
2114 {
2115 as_fatal ("sparc_create_short_jmp\n");
2116 }
2117
2118 #ifdef BFD_ASSEMBLER
2119
2120 /* Translate internal representation of relocation info to BFD target
2121 format. */
2122 arelent *
2123 tc_gen_reloc (section, fixp)
2124 asection *section;
2125 fixS *fixp;
2126 {
2127 arelent *reloc;
2128 bfd_reloc_code_real_type code;
2129
2130 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
2131 assert (reloc != 0);
2132
2133 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2134 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2135 if (fixp->fx_pcrel == 0)
2136 reloc->addend = fixp->fx_addnumber;
2137 else
2138 switch (OUTPUT_FLAVOR)
2139 {
2140 case bfd_target_elf_flavour:
2141 reloc->addend = 0;
2142 break;
2143 case bfd_target_aout_flavour:
2144 reloc->addend = - reloc->address;
2145 break;
2146 default:
2147 /* What's a good default here? Is there any?? */
2148 abort ();
2149 }
2150
2151 switch (fixp->fx_r_type)
2152 {
2153 case BFD_RELOC_32:
2154 case BFD_RELOC_HI22:
2155 case BFD_RELOC_LO10:
2156 case BFD_RELOC_32_PCREL_S2:
2157 case BFD_RELOC_SPARC_BASE13:
2158 case BFD_RELOC_SPARC_WDISP22:
2159 /* start-sanitize-v9 */
2160 case BFD_RELOC_SPARC_10:
2161 case BFD_RELOC_SPARC_11:
2162 case BFD_RELOC_SPARC_HH22:
2163 case BFD_RELOC_SPARC_HM10:
2164 case BFD_RELOC_SPARC_LM22:
2165 case BFD_RELOC_SPARC_PC_HH22:
2166 case BFD_RELOC_SPARC_PC_HM10:
2167 case BFD_RELOC_SPARC_PC_LM22:
2168 /* end-sanitize-v9 */
2169 code = fixp->fx_r_type;
2170 break;
2171 default:
2172 abort ();
2173 }
2174 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2175 assert (reloc->howto != 0);
2176
2177 return reloc;
2178 }
2179
2180 #else
2181
2182 /* Translate internal representation of relocation info to target format.
2183
2184 On sparc: first 4 bytes are normal unsigned long address, next three
2185 bytes are index, most sig. byte first. Byte 7 is broken up with
2186 bit 7 as external, bits 6 & 5 unused, and the lower
2187 five bits as relocation type. Next 4 bytes are long addend. */
2188 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
2189 void
2190 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
2191 char *where;
2192 fixS *fixP;
2193 relax_addressT segment_address_in_file;
2194 {
2195 long r_index;
2196 long r_extern;
2197 long r_addend = 0;
2198 long r_address;
2199
2200 know (fixP->fx_addsy);
2201
2202 if (!S_IS_DEFINED (fixP->fx_addsy))
2203 {
2204 r_extern = 1;
2205 r_index = fixP->fx_addsy->sy_number;
2206 }
2207 else
2208 {
2209 r_extern = 0;
2210 r_index = S_GET_TYPE (fixP->fx_addsy);
2211 }
2212
2213 /* this is easy */
2214 md_number_to_chars (where,
2215 r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
2216 4);
2217
2218 /* now the fun stuff */
2219 where[4] = (r_index >> 16) & 0x0ff;
2220 where[5] = (r_index >> 8) & 0x0ff;
2221 where[6] = r_index & 0x0ff;
2222 where[7] = ((r_extern << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
2223
2224 /* Also easy */
2225 if (fixP->fx_addsy->sy_frag)
2226 {
2227 r_addend = fixP->fx_addsy->sy_frag->fr_address;
2228 }
2229
2230 if (fixP->fx_pcrel)
2231 {
2232 r_addend += fixP->fx_offset - r_address;
2233 }
2234 else
2235 {
2236 r_addend = fixP->fx_addnumber;
2237 }
2238
2239 md_number_to_chars (&where[8], r_addend, 4);
2240
2241 return;
2242 } /* tc_aout_fix_to_chars() */
2243 #endif
2244
2245 /* should never be called for sparc */
2246 void
2247 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2248 char *ptr;
2249 addressT from_addr, to_addr;
2250 fragS *frag;
2251 symbolS *to_symbol;
2252 {
2253 as_fatal ("sparc_create_long_jump\n");
2254 } /* md_create_long_jump() */
2255
2256 /* should never be called for sparc */
2257 int
2258 md_estimate_size_before_relax (fragP, segtype)
2259 fragS *fragP;
2260 segT segtype;
2261 {
2262 as_fatal ("sparc_estimate_size_before_relax\n");
2263 return (1);
2264 } /* md_estimate_size_before_relax() */
2265
2266 #if 0
2267 /* for debugging only */
2268 static void
2269 print_insn (insn)
2270 struct sparc_it *insn;
2271 {
2272 char *Reloc[] =
2273 {
2274 "RELOC_8",
2275 "RELOC_16",
2276 "RELOC_32",
2277 "RELOC_DISP8",
2278 "RELOC_DISP16",
2279 "RELOC_DISP32",
2280 "RELOC_WDISP30",
2281 "RELOC_WDISP22",
2282 "RELOC_HI22",
2283 "RELOC_22",
2284 "RELOC_13",
2285 "RELOC_LO10",
2286 "RELOC_SFA_BASE",
2287 "RELOC_SFA_OFF13",
2288 "RELOC_BASE10",
2289 "RELOC_BASE13",
2290 "RELOC_BASE22",
2291 "RELOC_PC10",
2292 "RELOC_PC22",
2293 "RELOC_JMP_TBL",
2294 "RELOC_SEGOFF16",
2295 "RELOC_GLOB_DAT",
2296 "RELOC_JMP_SLOT",
2297 "RELOC_RELATIVE",
2298 "NO_RELOC"
2299 };
2300
2301 if (insn->error)
2302 {
2303 fprintf (stderr, "ERROR: %s\n");
2304 }
2305 fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
2306 fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
2307 fprintf (stderr, "exp = {\n");
2308 fprintf (stderr, "\t\tX_add_symbol = %s\n",
2309 ((insn->exp.X_add_symbol != NULL)
2310 ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
2311 ? S_GET_NAME (insn->exp.X_add_symbol)
2312 : "???")
2313 : "0"));
2314 fprintf (stderr, "\t\tX_sub_symbol = %s\n",
2315 ((insn->exp.X_subtract_symbol != NULL)
2316 ? (S_GET_NAME (insn->exp.X_subtract_symbol)
2317 ? S_GET_NAME (insn->exp.X_subtract_symbol)
2318 : "???")
2319 : "0"));
2320 fprintf (stderr, "\t\tX_add_number = %d\n",
2321 insn->exp.X_add_number);
2322 fprintf (stderr, "}\n");
2323 return;
2324 } /* print_insn() */
2325
2326 #endif
2327
2328 /*
2329 * md_parse_option
2330 * Invocation line includes a switch not recognized by the base assembler.
2331 * See if it's a processor-specific option. These are:
2332 *
2333 * -bump
2334 * Warn on architecture bumps. See also -A.
2335 *
2336 * -Av6, -Av7, -Av8, -Asparclite
2337 * Select the architecture. Instructions or features not
2338 * supported by the selected architecture cause fatal errors.
2339 *
2340 * The default is to start at v6, and bump the architecture up
2341 * whenever an instruction is seen at a higher level.
2342 *
2343 * If -bump is specified, a warning is printing when bumping to
2344 * higher levels.
2345 *
2346 * If an architecture is specified, all instructions must match
2347 * that architecture. Any higher level instructions are flagged
2348 * as errors.
2349 *
2350 * if both an architecture and -bump are specified, the
2351 * architecture starts at the specified level, but bumps are
2352 * warnings.
2353 *
2354 * start-sanitize-v9
2355 * -Av9
2356 * Another architecture switch.
2357 *
2358 * Note:
2359 * Bumping between incompatible architectures is always an
2360 * error. For example, from sparclite to v9.
2361 * end-sanitize-v9
2362 */
2363
2364 int
2365 md_parse_option (argP, cntP, vecP)
2366 char **argP;
2367 int *cntP;
2368 char ***vecP;
2369 {
2370 char *p;
2371 const char **arch;
2372
2373 if (!strcmp (*argP, "bump"))
2374 {
2375 warn_on_bump = 1;
2376
2377 }
2378 else if (**argP == 'A')
2379 {
2380 p = (*argP) + 1;
2381
2382 for (arch = architecture_pname; *arch != NULL; ++arch)
2383 {
2384 if (strcmp (p, *arch) == 0)
2385 {
2386 break;
2387 } /* found a match */
2388 } /* walk the pname table */
2389
2390 if (*arch == NULL)
2391 {
2392 as_bad ("unknown architecture: %s", p);
2393 }
2394 else
2395 {
2396 current_architecture = (enum sparc_architecture) (arch - architecture_pname);
2397 architecture_requested = 1;
2398 }
2399 }
2400 #ifdef OBJ_ELF
2401 else if (**argP == 'V')
2402 {
2403 extern void print_version_id ();
2404 print_version_id ();
2405 }
2406 else if (**argP == 'Q')
2407 {
2408 /* Qy - do emit .comment
2409 Qn - do not emit .comment */
2410 }
2411 else if (**argP == 's')
2412 {
2413 /* use .stab instead of .stab.excl */
2414 }
2415 #endif
2416 else
2417 {
2418 /* Unknown option */
2419 (*argP)++;
2420 return 0;
2421 }
2422 **argP = '\0'; /* Done parsing this switch */
2423 return 1;
2424 } /* md_parse_option() */
2425
2426 /* We have no need to default values of symbols. */
2427
2428 /* ARGSUSED */
2429 symbolS *
2430 md_undefined_symbol (name)
2431 char *name;
2432 {
2433 return 0;
2434 } /* md_undefined_symbol() */
2435
2436 /* Parse an operand that is machine-specific.
2437 We just return without modifying the expression if we have nothing
2438 to do. */
2439
2440 /* ARGSUSED */
2441 void
2442 md_operand (expressionP)
2443 expressionS *expressionP;
2444 {
2445 }
2446
2447 /* Round up a section size to the appropriate boundary. */
2448 valueT
2449 md_section_align (segment, size)
2450 segT segment;
2451 valueT size;
2452 {
2453 /* Round all sects to multiple of 8 */
2454 return (size + 7) & ~7;
2455 }
2456
2457 /* Exactly what point is a PC-relative offset relative TO?
2458 On the sparc, they're relative to the address of the offset, plus
2459 its size. This gets us to the following instruction.
2460 (??? Is this right? FIXME-SOON) */
2461 long
2462 md_pcrel_from (fixP)
2463 fixS *fixP;
2464 {
2465 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
2466 }
2467
2468 #ifndef BFD_ASSEMBLER
2469 void
2470 tc_aout_pre_write_hook (headers)
2471 object_headers *headers;
2472 {
2473 H_SET_VERSION (headers, 1);
2474 }
2475 #endif
2476
2477 /* end of tc-sparc.c */
This page took 0.094702 seconds and 4 git commands to generate.