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