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