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