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