1 /* tc-tic54x.c -- Assembly code for the Texas Instruments TMS320C54X
2 Copyright (C) 1999-2016 Free Software Foundation, Inc.
3 Contributed by Timothy Wall (twall@cygnus.com)
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 /* Texas Instruments TMS320C54X machine specific gas.
23 Written by Timothy Wall (twall@alum.mit.edu).
25 Valuable things to do:
26 Pipeline conflict warnings
27 We encode/decode "ld #_label, dp" differently in relocatable files
28 This means we're not compatible with TI output containing those
29 expressions. We store the upper nine bits; TI stores the lower nine
30 bits. How they recover the original upper nine bits is beyond me.
32 Tests to add to expect testsuite:
33 '=' and '==' with .if, .elseif, and .break
35 Incompatibilities (mostly trivial):
37 We fill text section with zeroes instead of "nop"s
38 We don't convert '' or "" to a single instance
39 We don't convert '' to '\0'
40 We don't allow strings with .byte/.half/.short/.long
41 Probably details of the subsym stuff are different
42 TI sets labels to be data type 4 (T_INT); GAS uses T_NULL.
44 COFF1 limits section names to 8 characters.
45 Some of the default behavior changed from COFF1 to COFF2. */
49 #include "safe-ctype.h"
53 #include "struc-symbol.h"
54 #include "opcode/tic54x.h"
61 symbolS
*sym
; /* Symbol for this stag; value is offset. */
62 const char *name
; /* Shortcut to symbol name. */
63 bfd_vma size
; /* Size of struct/union. */
64 int current_bitfield_offset
; /* Temporary for tracking fields. */
66 struct stag_field
/* List of fields. */
69 bfd_vma offset
; /* Of start of this field. */
70 int bitfield_offset
; /* Of start of this field. */
71 struct stag
*stag
; /* If field is struct/union. */
72 struct stag_field
*next
;
74 /* For nesting; used only in stag construction. */
75 struct stag
*inner
; /* Enclosed .struct. */
76 struct stag
*outer
; /* Enclosing .struct. */
77 } *current_stag
= NULL
;
79 #define MAX_LINE 256 /* Lines longer than this are truncated by TI's asm. */
81 typedef struct _tic54x_insn
83 const insn_template
*tm
; /* Opcode template. */
85 char mnemonic
[MAX_LINE
]; /* Opcode name/mnemonic. */
86 char parmnemonic
[MAX_LINE
]; /* 2nd mnemonic of parallel insn. */
94 } operands
[MAX_OPERANDS
];
97 struct opstruct paroperands
[MAX_OPERANDS
];
101 int words
; /* Size of insn in 16-bit words. */
102 int using_default_dst
; /* Do we need to explicitly set an
103 omitted OP_DST operand? */
106 unsigned short word
; /* Final encoded opcode data. */
108 int r_nchars
; /* Relocation size. */
109 bfd_reloc_code_real_type r_type
; /* Relocation type. */
110 expressionS addr_expr
; /* Storage for unresolved expressions. */
116 VNONE
= 0, V541
= 1, V542
= 2, V543
= 3, V545
= 5, V548
= 8, V549
= 9,
117 V545LP
= 15, V546LP
= 16
122 c_mode
, /* 16-bit addresses. */
123 far_mode
/* >16-bit addresses. */
126 static segT stag_saved_seg
;
127 static subsegT stag_saved_subseg
;
129 const char comment_chars
[] = ";";
130 const char line_comment_chars
[] = ";*#"; /* At column zero only. */
131 const char line_separator_chars
[] = ""; /* Not permitted. */
133 int emitting_long
= 0;
135 /* Characters which indicate that this is a floating point constant. */
136 const char FLT_CHARS
[] = "fF";
138 /* Characters that can be used to separate mantissa from exp in FP
140 const char EXP_CHARS
[] = "eE";
142 const char *md_shortopts
= "";
144 #define OPTION_ADDRESS_MODE (OPTION_MD_BASE)
145 #define OPTION_CPU_VERSION (OPTION_ADDRESS_MODE + 1)
146 #define OPTION_COFF_VERSION (OPTION_CPU_VERSION + 1)
147 #define OPTION_STDERR_TO_FILE (OPTION_COFF_VERSION + 1)
149 struct option md_longopts
[] =
151 { "mfar-mode", no_argument
, NULL
, OPTION_ADDRESS_MODE
},
152 { "mf", no_argument
, NULL
, OPTION_ADDRESS_MODE
},
153 { "mcpu", required_argument
, NULL
, OPTION_CPU_VERSION
},
154 { "merrors-to-file", required_argument
, NULL
, OPTION_STDERR_TO_FILE
},
155 { "me", required_argument
, NULL
, OPTION_STDERR_TO_FILE
},
156 { NULL
, no_argument
, NULL
, 0},
159 size_t md_longopts_size
= sizeof (md_longopts
);
161 static int assembly_begun
= 0;
162 /* Addressing mode is not entirely implemented; the latest rev of the Other
163 assembler doesn't seem to make any distinction whatsoever; all relocations
164 are stored as extended relocatiosn. Older versions used REL16 vs RELEXT16,
165 but now it seems all relocations are RELEXT16. We use all RELEXT16.
167 The cpu version is kind of a waste of time as well. There is one
168 instruction (RND) for LP devices only, and several for devices with
169 extended addressing only. We include it for compatibility. */
170 static enum address_mode amode
= c_mode
;
171 static enum cpu_version cpu
= VNONE
;
173 /* Include string substitutions in listing? */
174 static int listing_sslist
= 0;
176 /* Did we do subsym substitutions on the line? */
177 static int substitution_line
= 0;
179 /* Last label seen. */
180 static symbolS
*last_label_seen
= NULL
;
182 /* This ensures that all new labels are unique. */
183 static int local_label_id
;
185 static struct hash_control
*subsym_recurse_hash
; /* Prevent infinite recurse. */
186 static struct hash_control
*math_hash
; /* Built-in math functions. */
187 /* Allow maximum levels of macro nesting; level 0 is the main substitution
188 symbol table. The other assembler only does 32 levels, so there! */
189 static struct hash_control
*subsym_hash
[100];
191 /* Keep track of local labels so we can substitute them before GAS sees them
192 since macros use their own 'namespace' for local labels, use a separate hash
194 We do our own local label handling 'cuz it's subtly different from the
197 We use our own macro nesting counter, since GAS overloads it when expanding
198 other things (like conditionals and repeat loops). */
199 static int macro_level
= 0;
200 static struct hash_control
*local_label_hash
[100];
201 /* Keep track of struct/union tags. */
202 static struct hash_control
*stag_hash
;
203 static struct hash_control
*op_hash
;
204 static struct hash_control
*parop_hash
;
205 static struct hash_control
*reg_hash
;
206 static struct hash_control
*mmreg_hash
;
207 static struct hash_control
*cc_hash
;
208 static struct hash_control
*cc2_hash
;
209 static struct hash_control
*cc3_hash
;
210 static struct hash_control
*sbit_hash
;
211 static struct hash_control
*misc_symbol_hash
;
213 /* Only word (et al.), align, or conditionals are allowed within
215 #define ILLEGAL_WITHIN_STRUCT() \
217 if (current_stag != NULL) \
219 as_bad (_("pseudo-op illegal within .struct/.union")); \
225 static void subsym_create_or_replace (char *, char *);
226 static char *subsym_lookup (char *, int);
227 static char *subsym_substitute (char *, int);
231 md_show_usage (FILE *stream
)
233 fprintf (stream
, _("C54x-specific command line options:\n"));
234 fprintf (stream
, _("-mfar-mode | -mf Use extended addressing\n"));
235 fprintf (stream
, _("-mcpu=<CPU version> Specify the CPU version\n"));
236 fprintf (stream
, _("-merrors-to-file <filename>\n"));
237 fprintf (stream
, _("-me <filename> Redirect errors to a file\n"));
240 /* Output a single character (upper octect is zero). */
243 tic54x_emit_char (char c
)
247 expn
.X_op
= O_constant
;
248 expn
.X_add_number
= c
;
249 emit_expr (&expn
, 2);
252 /* Walk backwards in the frag chain. */
255 frag_prev (fragS
*frag
, segT seg
)
257 segment_info_type
*seginfo
= seg_info (seg
);
260 for (fragp
= seginfo
->frchainP
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
261 if (fragp
->fr_next
== frag
)
268 bit_offset_frag (fragS
*frag
, segT seg
)
272 if (frag
->fr_fix
== 0
273 && frag
->fr_opcode
== NULL
274 && frag
->tc_frag_data
== 0)
275 frag
= frag_prev (frag
, seg
);
282 /* Return the number of bits allocated in the most recent word, or zero if
283 none. .field/.space/.bes may leave words partially allocated. */
286 frag_bit_offset (fragS
*frag
, segT seg
)
288 frag
= bit_offset_frag (frag
, seg
);
291 return frag
->fr_opcode
!= NULL
? -1 : frag
->tc_frag_data
;
296 /* Read an expression from a C string; returns a pointer past the end of the
300 parse_expression (char *str
, expressionS
*expn
)
305 tmp
= input_line_pointer
; /* Save line pointer. */
306 input_line_pointer
= str
;
308 s
= input_line_pointer
;
309 input_line_pointer
= tmp
; /* Restore line pointer. */
310 return s
; /* Return pointer to where parsing stopped. */
313 /* .asg "character-string"|character-string, symbol
315 .eval is the only pseudo-op allowed to perform arithmetic on substitution
316 symbols. all other use of symbols defined with .asg are currently
320 tic54x_asg (int x ATTRIBUTE_UNUSED
)
325 int quoted
= *input_line_pointer
== '"';
327 ILLEGAL_WITHIN_STRUCT ();
332 str
= demand_copy_C_string (&len
);
333 c
= *input_line_pointer
;
337 str
= input_line_pointer
;
338 while ((c
= *input_line_pointer
) != ',')
340 if (is_end_of_line
[(int) *input_line_pointer
])
342 ++input_line_pointer
;
344 *input_line_pointer
= 0;
348 as_bad (_("Comma and symbol expected for '.asg STRING, SYMBOL'"));
349 ignore_rest_of_line ();
353 ++input_line_pointer
;
354 c
= get_symbol_name (&name
); /* Get terminator. */
355 if (!ISALPHA (*name
))
357 as_bad (_("symbols assigned with .asg must begin with a letter"));
358 ignore_rest_of_line ();
363 name
= xstrdup (name
);
364 subsym_create_or_replace (name
, str
);
365 (void) restore_line_pointer (c
);
366 demand_empty_rest_of_line ();
369 /* .eval expression, symbol
370 There's something screwy about this. The other assembler sometimes does and
371 sometimes doesn't substitute symbols defined with .eval.
372 We'll put the symbols into the subsym table as well as the normal symbol
373 table, since that's what works best. */
376 tic54x_eval (int x ATTRIBUTE_UNUSED
)
382 char valuestr
[32], *tmp
;
385 ILLEGAL_WITHIN_STRUCT ();
389 quoted
= *input_line_pointer
== '"';
391 ++input_line_pointer
;
392 value
= get_absolute_expression ();
395 if (*input_line_pointer
!= '"')
397 as_bad (_("Unterminated string after absolute expression"));
398 ignore_rest_of_line ();
401 ++input_line_pointer
;
403 if (*input_line_pointer
++ != ',')
405 as_bad (_("Comma and symbol expected for '.eval EXPR, SYMBOL'"));
406 ignore_rest_of_line ();
409 c
= get_symbol_name (&name
); /* Get terminator. */
410 tmp
= xmalloc (strlen (name
) + 1);
411 name
= strcpy (tmp
, name
);
412 (void) restore_line_pointer (c
);
414 if (!ISALPHA (*name
))
416 as_bad (_("symbols assigned with .eval must begin with a letter"));
417 ignore_rest_of_line ();
420 symbolP
= symbol_new (name
, absolute_section
,
421 (valueT
) value
, &zero_address_frag
);
422 SF_SET_LOCAL (symbolP
);
423 symbol_table_insert (symbolP
);
425 /* The "other" assembler sometimes doesn't put .eval's in the subsym table
426 But since there's not written rule as to when, don't even bother trying
427 to match their behavior. */
428 sprintf (valuestr
, "%d", value
);
429 tmp
= xmalloc (strlen (valuestr
) + 1);
430 strcpy (tmp
, valuestr
);
431 subsym_create_or_replace (name
, tmp
);
433 demand_empty_rest_of_line ();
436 /* .bss symbol, size [, [blocking flag] [, alignment flag]
438 alignment is to a longword boundary; blocking is to 128-word boundary.
440 1) if there is a hole in memory, this directive should attempt to fill it
441 (not yet implemented).
443 2) if the blocking flag is not set, allocate at the current SPC
444 otherwise, check to see if the current SPC plus the space to be
445 allocated crosses the page boundary (128 words).
446 if there's not enough space, create a hole and align with the next page
448 (not yet implemented). */
451 tic54x_bss (int x ATTRIBUTE_UNUSED
)
458 subsegT current_subseg
;
463 ILLEGAL_WITHIN_STRUCT ();
465 current_seg
= now_seg
; /* Save current seg. */
466 current_subseg
= now_subseg
; /* Save current subseg. */
468 c
= get_symbol_name (&name
); /* Get terminator. */
470 c
= * ++ input_line_pointer
;
473 as_bad (_(".bss size argument missing\n"));
474 ignore_rest_of_line ();
478 ++input_line_pointer
;
479 words
= get_absolute_expression ();
482 as_bad (_(".bss size %d < 0!"), words
);
483 ignore_rest_of_line ();
487 if (*input_line_pointer
== ',')
489 /* The blocking flag may be missing. */
490 ++input_line_pointer
;
491 if (*input_line_pointer
!= ',')
492 block
= get_absolute_expression ();
496 if (*input_line_pointer
== ',')
498 ++input_line_pointer
;
499 align
= get_absolute_expression ();
507 subseg_set (bss_section
, 0);
508 symbolP
= symbol_find_or_make (name
);
510 if (S_GET_SEGMENT (symbolP
) == bss_section
)
511 symbolP
->sy_frag
->fr_symbol
= (symbolS
*) NULL
;
513 symbol_set_frag (symbolP
, frag_now
);
514 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
515 (offsetT
) (words
* OCTETS_PER_BYTE
), (char *) 0);
516 *p
= 0; /* Fill char. */
518 S_SET_SEGMENT (symbolP
, bss_section
);
520 /* The symbol may already have been created with a preceding
521 ".globl" directive -- be careful not to step on storage class
522 in that case. Otherwise, set it to static. */
523 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
524 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
528 /* s_align eats end of line; restore it */
530 --input_line_pointer
;
534 bss_section
->flags
|= SEC_TIC54X_BLOCK
;
536 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
537 demand_empty_rest_of_line ();
541 stag_add_field_symbols (struct stag
*stag
,
545 const char *root_stag_name
)
548 struct stag_field
*field
= stag
->field
;
550 /* Construct a symbol for every field contained within this structure
551 including fields within structure fields. */
552 prefix
= concat (path
, *path
? "." : "", NULL
);
554 while (field
!= NULL
)
556 char *name
= concat (prefix
, field
->name
, NULL
);
561 sym
= symbol_new (name
, absolute_section
,
562 (field
->stag
? field
->offset
:
563 (valueT
) (base_offset
+ field
->offset
)),
566 symbol_table_insert (sym
);
572 replacement
= concat (S_GET_NAME (rootsym
), "+", root_stag_name
,
573 name
+ strlen (S_GET_NAME (rootsym
)), NULL
);
574 hash_insert (subsym_hash
[0], name
, replacement
);
577 /* Recurse if the field is a structure.
578 Note the field offset is relative to the outermost struct. */
579 if (field
->stag
!= NULL
)
580 stag_add_field_symbols (field
->stag
, name
,
582 rootsym
, root_stag_name
);
589 /* Keep track of stag fields so that when structures are nested we can add the
590 complete dereferencing symbols to the symbol table. */
593 stag_add_field (struct stag
*parent
,
598 struct stag_field
*sfield
= xmalloc (sizeof (struct stag_field
));
600 memset (sfield
, 0, sizeof (*sfield
));
601 sfield
->name
= strcpy (xmalloc (strlen (name
) + 1), name
);
602 sfield
->offset
= offset
;
603 sfield
->bitfield_offset
= parent
->current_bitfield_offset
;
605 if (parent
->field
== NULL
)
606 parent
->field
= sfield
;
609 struct stag_field
*sf
= parent
->field
;
610 while (sf
->next
!= NULL
)
614 /* Only create a symbol for this field if the parent has no name. */
615 if (!strncmp (".fake", parent
->name
, 5))
617 symbolS
*sym
= symbol_new (name
, absolute_section
,
618 (valueT
) offset
, &zero_address_frag
);
620 symbol_table_insert (sym
);
624 /* [STAG] .struct [OFFSET]
625 Start defining structure offsets (symbols in absolute section). */
628 tic54x_struct (int arg
)
630 int start_offset
= 0;
635 /* Starting a new struct, switch to absolute section. */
636 stag_saved_seg
= now_seg
;
637 stag_saved_subseg
= now_subseg
;
638 subseg_set (absolute_section
, 0);
640 /* Align the current pointer. */
641 else if (current_stag
->current_bitfield_offset
!= 0)
643 ++abs_section_offset
;
644 current_stag
->current_bitfield_offset
= 0;
647 /* Offset expression is only meaningful for global .structs. */
650 /* Offset is ignored in inner structs. */
652 if (!is_end_of_line
[(int) *input_line_pointer
])
653 start_offset
= get_absolute_expression ();
660 /* Nesting, link to outer one. */
661 current_stag
->inner
= (struct stag
*) xmalloc (sizeof (struct stag
));
662 memset (current_stag
->inner
, 0, sizeof (struct stag
));
663 current_stag
->inner
->outer
= current_stag
;
664 current_stag
= current_stag
->inner
;
666 as_warn (_("Offset on nested structures is ignored"));
667 start_offset
= abs_section_offset
;
671 current_stag
= (struct stag
*) xmalloc (sizeof (struct stag
));
672 memset (current_stag
, 0, sizeof (struct stag
));
673 abs_section_offset
= start_offset
;
675 current_stag
->is_union
= is_union
;
677 if (line_label
== NULL
)
679 static int struct_count
= 0;
680 char fake
[] = ".fake_stagNNNNNNN";
681 sprintf (fake
, ".fake_stag%d", struct_count
++);
682 current_stag
->sym
= symbol_new (fake
, absolute_section
,
683 (valueT
) abs_section_offset
,
688 char * label
= xstrdup (S_GET_NAME (line_label
));
689 current_stag
->sym
= symbol_new (label
,
691 (valueT
) abs_section_offset
,
695 current_stag
->name
= S_GET_NAME (current_stag
->sym
);
696 SF_SET_LOCAL (current_stag
->sym
);
697 /* Nested .structs don't go into the symbol table. */
698 if (current_stag
->outer
== NULL
)
699 symbol_table_insert (current_stag
->sym
);
704 /* [LABEL] .endstruct
705 finish defining structure offsets; optional LABEL's value will be the size
709 tic54x_endstruct (int is_union
)
713 !strncmp (current_stag
->name
, ".fake", 5) ? "" : current_stag
->name
;
715 if (!current_stag
|| current_stag
->is_union
!= is_union
)
717 as_bad (_(".end%s without preceding .%s"),
718 is_union
? "union" : "struct",
719 is_union
? "union" : "struct");
720 ignore_rest_of_line ();
724 /* Align end of structures. */
725 if (current_stag
->current_bitfield_offset
)
727 ++abs_section_offset
;
728 current_stag
->current_bitfield_offset
= 0;
731 if (current_stag
->is_union
)
732 size
= current_stag
->size
;
734 size
= abs_section_offset
- S_GET_VALUE (current_stag
->sym
);
735 if (line_label
!= NULL
)
737 S_SET_VALUE (line_label
, size
);
738 symbol_table_insert (line_label
);
742 /* Union size has already been calculated. */
743 if (!current_stag
->is_union
)
744 current_stag
->size
= size
;
745 /* Nested .structs don't get put in the stag table. */
746 if (current_stag
->outer
== NULL
)
748 hash_insert (stag_hash
, current_stag
->name
, current_stag
);
749 stag_add_field_symbols (current_stag
, path
,
750 S_GET_VALUE (current_stag
->sym
),
753 current_stag
= current_stag
->outer
;
755 /* If this is a nested .struct/.union, add it as a field to the enclosing
756 one. otherwise, restore the section we were in. */
757 if (current_stag
!= NULL
)
759 stag_add_field (current_stag
, current_stag
->inner
->name
,
760 S_GET_VALUE (current_stag
->inner
->sym
),
761 current_stag
->inner
);
764 subseg_set (stag_saved_seg
, stag_saved_subseg
);
768 Reference a structure within a structure, as a sized field with an optional
770 If used outside of a .struct/.endstruct, overlays the given structure
771 format on the existing allocated space. */
774 tic54x_tag (int ignore ATTRIBUTE_UNUSED
)
777 int c
= get_symbol_name (&name
);
778 struct stag
*stag
= (struct stag
*) hash_find (stag_hash
, name
);
783 as_bad (_("Unrecognized struct/union tag '%s'"), name
);
785 as_bad (_(".tag requires a structure tag"));
786 ignore_rest_of_line ();
789 if (line_label
== NULL
)
791 as_bad (_("Label required for .tag"));
792 ignore_rest_of_line ();
799 label
= xstrdup (S_GET_NAME (line_label
));
800 if (current_stag
!= NULL
)
801 stag_add_field (current_stag
, label
,
802 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
806 symbolS
*sym
= symbol_find (label
);
810 as_bad (_(".tag target '%s' undefined"), label
);
811 ignore_rest_of_line ();
815 stag_add_field_symbols (stag
, S_GET_NAME (sym
),
816 S_GET_VALUE (stag
->sym
), sym
, stag
->name
);
821 /* Bump by the struct size, but only if we're within a .struct section. */
822 if (current_stag
!= NULL
&& !current_stag
->is_union
)
823 abs_section_offset
+= stag
->size
;
825 (void) restore_line_pointer (c
);
826 demand_empty_rest_of_line ();
830 /* Handle all .byte, .char, .double, .field, .float, .half, .int, .long,
831 .short, .string, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword,
835 tic54x_struct_field (int type
)
839 int new_bitfield_offset
= 0;
840 int field_align
= current_stag
->current_bitfield_offset
!= 0;
841 int longword_align
= 0;
844 if (!is_end_of_line
[(int) *input_line_pointer
])
845 count
= get_absolute_expression ();
861 case '*': /* String. */
870 case '.': /* Bitfield. */
872 if (count
< 1 || count
> 32)
874 as_bad (_(".field count '%d' out of range (1 <= X <= 32)"), count
);
875 ignore_rest_of_line ();
878 if (current_stag
->current_bitfield_offset
+ count
> 16)
880 /* Set the appropriate size and new field offset. */
890 new_bitfield_offset
= count
- 16;
893 new_bitfield_offset
= count
;
898 new_bitfield_offset
= current_stag
->current_bitfield_offset
+ count
;
902 as_bad (_("Unrecognized field type '%c'"), type
);
903 ignore_rest_of_line ();
909 /* Align to the actual starting position of the field. */
910 current_stag
->current_bitfield_offset
= 0;
911 ++abs_section_offset
;
913 /* Align to longword boundary. */
914 if (longword_align
&& (abs_section_offset
& 0x1))
915 ++abs_section_offset
;
917 if (line_label
== NULL
)
919 static int fieldno
= 0;
920 char fake
[] = ".fake_fieldNNNNN";
922 sprintf (fake
, ".fake_field%d", fieldno
++);
923 stag_add_field (current_stag
, fake
,
924 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
931 label
= xstrdup (S_GET_NAME (line_label
));
932 stag_add_field (current_stag
, label
,
933 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
938 if (current_stag
->is_union
)
940 /* Note we treat the element as if it were an array of COUNT. */
941 if (current_stag
->size
< (unsigned) size
* count
)
942 current_stag
->size
= size
* count
;
946 abs_section_offset
+= (unsigned) size
* count
;
947 current_stag
->current_bitfield_offset
= new_bitfield_offset
;
952 /* Handle .byte, .word. .int, .long and all variants. */
955 tic54x_cons (int type
)
960 /* If we're within a .struct construct, don't actually allocate space. */
961 if (current_stag
!= NULL
)
963 tic54x_struct_field (type
);
967 #ifdef md_flush_pending_output
968 md_flush_pending_output ();
971 generate_lineno_debug ();
973 /* Align long words to long word boundaries (4 octets). */
974 if (type
== 'l' || type
== 'L')
976 frag_align (2, 0, 2);
977 /* If there's a label, assign it to the first allocated word. */
978 if (line_label
!= NULL
)
980 symbol_set_frag (line_label
, frag_now
);
981 S_SET_VALUE (line_label
, frag_now_fix ());
1005 if (*input_line_pointer
== '"')
1007 input_line_pointer
++;
1008 while (is_a_char (c
= next_char_of_string ()))
1009 tic54x_emit_char (c
);
1010 know (input_line_pointer
[-1] == '\"');
1016 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1017 if (expn
.X_op
== O_constant
)
1019 offsetT value
= expn
.X_add_number
;
1020 /* Truncate overflows. */
1024 if ((value
> 0 && value
> 0xFF)
1025 || (value
< 0 && value
< - 0x100))
1026 as_warn (_("Overflow in expression, truncated to 8 bits"));
1029 if ((value
> 0 && value
> 0xFFFF)
1030 || (value
< 0 && value
< - 0x10000))
1031 as_warn (_("Overflow in expression, truncated to 16 bits"));
1035 if (expn
.X_op
!= O_constant
&& octets
< 2)
1037 /* Disallow .byte with a non constant expression that will
1038 require relocation. */
1039 as_bad (_("Relocatable values require at least WORD storage"));
1040 ignore_rest_of_line ();
1044 if (expn
.X_op
!= O_constant
1048 /* FIXME -- at one point TI tools used to output REL16
1049 relocations, but I don't think the latest tools do at all
1050 The current tools output extended relocations regardless of
1051 the addressing mode (I actually think that ".c_mode" is
1052 totally ignored in the latest tools). */
1055 emit_expr (&expn
, 4);
1061 emitting_long
= octets
== 4;
1062 emit_expr (&expn
, (octets
== 1) ? 2 : octets
);
1067 while (*input_line_pointer
++ == ',');
1069 input_line_pointer
--; /* Put terminator back into stream. */
1070 demand_empty_rest_of_line ();
1073 /* .global <symbol>[,...,<symbolN>]
1074 .def <symbol>[,...,<symbolN>]
1075 .ref <symbol>[,...,<symbolN>]
1077 These all identify global symbols.
1079 .def means the symbol is defined in the current module and can be accessed
1080 by other files. The symbol should be placed in the symbol table.
1082 .ref means the symbol is used in the current module but defined in another
1083 module. The linker is to resolve this symbol's definition at link time.
1085 .global should act as a .ref or .def, as needed.
1087 global, def and ref all have symbol storage classes of C_EXT.
1089 I can't identify any difference in how the "other" c54x assembler treats
1090 these, so we ignore the type here. */
1093 tic54x_global (int type
)
1100 as_warn (_("Use of .def/.ref is deprecated. Use .global instead"));
1102 ILLEGAL_WITHIN_STRUCT ();
1106 c
= get_symbol_name (&name
);
1107 symbolP
= symbol_find_or_make (name
);
1108 c
= restore_line_pointer (c
);
1110 S_SET_STORAGE_CLASS (symbolP
, C_EXT
);
1113 input_line_pointer
++;
1114 if (is_end_of_line
[(int) *input_line_pointer
])
1115 c
= *input_line_pointer
;
1120 demand_empty_rest_of_line ();
1123 /* Remove the symbol from the local label hash lookup. */
1126 tic54x_remove_local_label (const char *key
, void *value ATTRIBUTE_UNUSED
)
1128 void *elem
= hash_delete (local_label_hash
[macro_level
], key
, FALSE
);
1132 /* Reset all local labels. */
1135 tic54x_clear_local_labels (int ignored ATTRIBUTE_UNUSED
)
1137 hash_traverse (local_label_hash
[macro_level
], tic54x_remove_local_label
);
1142 .sect "section name"
1145 make sure local labels get cleared when changing sections
1147 ARG is 't' for text, 'd' for data, or '*' for a named section
1149 For compatibility, '*' sections are SEC_CODE if instructions are
1150 encountered, or SEC_DATA if not.
1154 tic54x_sect (int arg
)
1156 ILLEGAL_WITHIN_STRUCT ();
1158 /* Local labels are cleared when changing sections. */
1159 tic54x_clear_local_labels (0);
1163 else if (arg
== 'd')
1170 /* If there are quotes, remove them. */
1171 if (*input_line_pointer
== '"')
1173 name
= demand_copy_C_string (&len
);
1174 demand_empty_rest_of_line ();
1175 name
= strcpy (xmalloc (len
+ 10), name
);
1181 c
= get_symbol_name (&name
);
1183 name
= strcpy (xmalloc (len
+ 10), name
);
1184 (void) restore_line_pointer (c
);
1185 demand_empty_rest_of_line ();
1188 /* Make sure all named initialized sections flagged properly. If we
1189 encounter instructions, we'll flag it with SEC_CODE as well. */
1190 strcat (name
, ",\"w\"\n");
1191 input_scrub_insert_line (name
);
1192 obj_coff_section (0);
1194 /* If there was a line label, make sure that it gets assigned the proper
1195 section. This is for compatibility, even though the actual behavior
1196 is not explicitly defined. For consistency, we make .sect behave
1197 like .usect, since that is probably what people expect. */
1198 if (line_label
!= NULL
)
1200 S_SET_SEGMENT (line_label
, now_seg
);
1201 symbol_set_frag (line_label
, frag_now
);
1202 S_SET_VALUE (line_label
, frag_now_fix ());
1203 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1204 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1209 /* [symbol] .space space_in_bits
1210 [symbol] .bes space_in_bits
1211 BES puts the symbol at the *last* word allocated
1213 cribbed from s_space. */
1216 tic54x_space (int arg
)
1222 int bits_per_byte
= (OCTETS_PER_BYTE
* 8);
1224 symbolS
*label
= line_label
;
1227 ILLEGAL_WITHIN_STRUCT ();
1229 #ifdef md_flush_pending_output
1230 md_flush_pending_output ();
1233 /* Read the bit count. */
1236 /* Some expressions are unresolvable until later in the assembly pass;
1237 postpone until relaxation/fixup. we also have to postpone if a previous
1238 partial allocation has not been completed yet. */
1239 if (expn
.X_op
!= O_constant
|| frag_bit_offset (frag_now
, now_seg
) == -1)
1241 struct bit_info
*bi
= xmalloc (sizeof (struct bit_info
));
1246 p
= frag_var (rs_machine_dependent
,
1247 65536 * 2, 1, (relax_substateT
) 0,
1248 make_expr_symbol (&expn
), (offsetT
) 0,
1256 /* Reduce the required size by any bit offsets currently left over
1257 from a previous .space/.bes/.field directive. */
1258 bit_offset
= frag_now
->tc_frag_data
;
1259 if (bit_offset
!= 0 && bit_offset
< 16)
1261 int spare_bits
= bits_per_byte
- bit_offset
;
1263 if (spare_bits
>= expn
.X_add_number
)
1265 /* Don't have to do anything; sufficient bits have already been
1266 allocated; just point the label to the right place. */
1269 symbol_set_frag (label
, frag_now
);
1270 S_SET_VALUE (label
, frag_now_fix () - 1);
1273 frag_now
->tc_frag_data
+= expn
.X_add_number
;
1276 expn
.X_add_number
-= spare_bits
;
1277 /* Set the label to point to the first word allocated, which in this
1278 case is the previous word, which was only partially filled. */
1279 if (!bes
&& label
!= NULL
)
1281 symbol_set_frag (label
, frag_now
);
1282 S_SET_VALUE (label
, frag_now_fix () - 1);
1286 /* Convert bits to bytes/words and octets, rounding up. */
1287 words
= ((expn
.X_add_number
+ bits_per_byte
- 1) / bits_per_byte
);
1288 /* How many do we have left over? */
1289 bit_offset
= expn
.X_add_number
% bits_per_byte
;
1290 octets
= words
* OCTETS_PER_BYTE
;
1293 as_warn (_(".space/.bes repeat count is negative, ignored"));
1296 else if (octets
== 0)
1298 as_warn (_(".space/.bes repeat count is zero, ignored"));
1302 /* If we are in the absolute section, just bump the offset. */
1303 if (now_seg
== absolute_section
)
1305 abs_section_offset
+= words
;
1306 if (bes
&& label
!= NULL
)
1307 S_SET_VALUE (label
, abs_section_offset
- 1);
1308 frag_now
->tc_frag_data
= bit_offset
;
1313 p
= frag_var (rs_fill
, 1, 1,
1314 (relax_substateT
) 0, (symbolS
*) 0,
1315 (offsetT
) octets
, (char *) 0);
1317 /* Make note of how many bits of this word we've allocated so far. */
1318 frag_now
->tc_frag_data
= bit_offset
;
1320 /* .bes puts label at *last* word allocated. */
1321 if (bes
&& label
!= NULL
)
1323 symbol_set_frag (label
, frag_now
);
1324 S_SET_VALUE (label
, frag_now_fix () - 1);
1332 demand_empty_rest_of_line ();
1335 /* [symbol] .usect "section-name", size-in-words
1336 [, [blocking-flag] [, alignment-flag]]
1338 Uninitialized section.
1339 Non-zero blocking means that if the section would cross a page (128-word)
1340 boundary, it will be page-aligned.
1341 Non-zero alignment aligns on a longword boundary.
1343 Has no effect on the current section. */
1346 tic54x_usect (int x ATTRIBUTE_UNUSED
)
1353 int size
, blocking_flag
, alignment_flag
;
1355 subsegT current_subseg
;
1358 ILLEGAL_WITHIN_STRUCT ();
1360 current_seg
= now_seg
; /* Save current seg. */
1361 current_subseg
= now_subseg
; /* Save current subseg. */
1363 c
= get_symbol_name (§ion_name
); /* Get terminator. */
1364 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1365 strcpy (name
, section_name
);
1366 c
= restore_line_pointer (c
);
1369 ++input_line_pointer
;
1372 as_bad (_("Missing size argument"));
1373 ignore_rest_of_line ();
1377 size
= get_absolute_expression ();
1379 /* Read a possibly present third argument (blocking flag). */
1380 if (*input_line_pointer
== ',')
1382 ++input_line_pointer
;
1383 if (*input_line_pointer
!= ',')
1384 blocking_flag
= get_absolute_expression ();
1388 /* Read a possibly present fourth argument (alignment flag). */
1389 if (*input_line_pointer
== ',')
1391 ++input_line_pointer
;
1392 alignment_flag
= get_absolute_expression ();
1398 blocking_flag
= alignment_flag
= 0;
1400 seg
= subseg_new (name
, 0);
1401 flags
= bfd_get_section_flags (stdoutput
, seg
) | SEC_ALLOC
;
1405 /* s_align eats end of line; restore it. */
1407 --input_line_pointer
;
1410 if (line_label
!= NULL
)
1412 S_SET_SEGMENT (line_label
, seg
);
1413 symbol_set_frag (line_label
, frag_now
);
1414 S_SET_VALUE (line_label
, frag_now_fix ());
1415 /* Set scl to label, since that's what TI does. */
1416 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1417 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1420 seg_info (seg
)->bss
= 1; /* Uninitialized data. */
1422 p
= frag_var (rs_fill
, 1, 1,
1423 (relax_substateT
) 0, (symbolS
*) line_label
,
1424 size
* OCTETS_PER_BYTE
, (char *) 0);
1428 flags
|= SEC_TIC54X_BLOCK
;
1430 if (!bfd_set_section_flags (stdoutput
, seg
, flags
))
1431 as_warn (_("Error setting flags for \"%s\": %s"), name
,
1432 bfd_errmsg (bfd_get_error ()));
1434 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
1435 demand_empty_rest_of_line ();
1438 static enum cpu_version
1439 lookup_version (const char *ver
)
1441 enum cpu_version version
= VNONE
;
1443 if (ver
[0] == '5' && ver
[1] == '4')
1445 if (strlen (ver
) == 3
1446 && (ver
[2] == '1' || ver
[2] == '2' || ver
[2] == '3'
1447 || ver
[2] == '5' || ver
[2] == '8' || ver
[2] == '9'))
1448 version
= ver
[2] - '0';
1449 else if (strlen (ver
) == 5
1450 && TOUPPER (ver
[3]) == 'L'
1451 && TOUPPER (ver
[4]) == 'P'
1452 && (ver
[2] == '5' || ver
[2] == '6'))
1453 version
= ver
[2] - '0' + 10;
1460 set_cpu (enum cpu_version version
)
1463 if (version
== V545LP
|| version
== V546LP
)
1465 symbolS
*symbolP
= symbol_new ("__allow_lp", absolute_section
,
1466 (valueT
) 1, &zero_address_frag
);
1467 SF_SET_LOCAL (symbolP
);
1468 symbol_table_insert (symbolP
);
1472 /* .version cpu-version
1473 cpu-version may be one of the following:
1483 This is for compatibility only. It currently has no affect on assembly. */
1484 static int cpu_needs_set
= 1;
1487 tic54x_version (int x ATTRIBUTE_UNUSED
)
1489 enum cpu_version version
= VNONE
;
1490 enum cpu_version old_version
= cpu
;
1494 ILLEGAL_WITHIN_STRUCT ();
1497 ver
= input_line_pointer
;
1498 while (!is_end_of_line
[(int) *input_line_pointer
])
1499 ++input_line_pointer
;
1500 c
= *input_line_pointer
;
1501 *input_line_pointer
= 0;
1503 version
= lookup_version (ver
);
1505 if (cpu
!= VNONE
&& cpu
!= version
)
1506 as_warn (_("CPU version has already been set"));
1508 if (version
== VNONE
)
1510 as_bad (_("Unrecognized version '%s'"), ver
);
1511 ignore_rest_of_line ();
1514 else if (assembly_begun
&& version
!= old_version
)
1516 as_bad (_("Changing of CPU version on the fly not supported"));
1517 ignore_rest_of_line ();
1523 *input_line_pointer
= c
;
1524 demand_empty_rest_of_line ();
1527 /* 'f' = float, 'x' = xfloat, 'd' = double, 'l' = ldouble. */
1530 tic54x_float_cons (int type
)
1532 if (current_stag
!= 0)
1533 tic54x_struct_field ('f');
1535 #ifdef md_flush_pending_output
1536 md_flush_pending_output ();
1539 /* Align to long word boundary (4 octets) unless it's ".xfloat". */
1542 frag_align (2, 0, 2);
1543 /* If there's a label, assign it to the first allocated word. */
1544 if (line_label
!= NULL
)
1546 symbol_set_frag (line_label
, frag_now
);
1547 S_SET_VALUE (line_label
, frag_now_fix ());
1554 /* The argument is capitalized if it should be zero-terminated
1555 's' is normal string with upper 8-bits zero-filled, 'p' is packed.
1556 Code copied from stringer, and slightly modified so that strings are packed
1557 and encoded into the correct octets. */
1560 tic54x_stringer (int type
)
1563 int append_zero
= type
== 'S' || type
== 'P';
1564 int packed
= type
== 'p' || type
== 'P';
1565 int last_char
= -1; /* Packed strings need two bytes at a time to encode. */
1567 if (current_stag
!= NULL
)
1569 tic54x_struct_field ('*');
1573 #ifdef md_flush_pending_output
1574 md_flush_pending_output ();
1577 c
= ','; /* Do loop. */
1581 switch (*input_line_pointer
)
1585 unsigned short value
= get_absolute_expression ();
1586 FRAG_APPEND_1_CHAR ( value
& 0xFF);
1587 FRAG_APPEND_1_CHAR ((value
>> 8) & 0xFF);
1591 ++input_line_pointer
; /* -> 1st char of string. */
1592 while (is_a_char (c
= next_char_of_string ()))
1596 FRAG_APPEND_1_CHAR (c
);
1597 FRAG_APPEND_1_CHAR (0);
1601 /* Packed strings are filled MS octet first. */
1602 if (last_char
== -1)
1606 FRAG_APPEND_1_CHAR (c
);
1607 FRAG_APPEND_1_CHAR (last_char
);
1614 if (packed
&& last_char
!= -1)
1616 FRAG_APPEND_1_CHAR (0);
1617 FRAG_APPEND_1_CHAR (last_char
);
1622 FRAG_APPEND_1_CHAR (0);
1623 FRAG_APPEND_1_CHAR (0);
1626 know (input_line_pointer
[-1] == '\"');
1630 c
= *input_line_pointer
;
1631 if (!is_end_of_line
[c
])
1632 ++input_line_pointer
;
1635 /* Finish up any leftover packed string. */
1636 if (packed
&& last_char
!= -1)
1638 FRAG_APPEND_1_CHAR (0);
1639 FRAG_APPEND_1_CHAR (last_char
);
1641 demand_empty_rest_of_line ();
1645 tic54x_p2align (int arg ATTRIBUTE_UNUSED
)
1647 as_bad (_("p2align not supported on this target"));
1651 tic54x_align_words (int arg
)
1653 /* Only ".align" with no argument is allowed within .struct/.union. */
1656 if (!is_end_of_line
[(int) *input_line_pointer
])
1659 as_warn (_("Argument to .even ignored"));
1661 count
= get_absolute_expression ();
1664 if (current_stag
!= NULL
&& arg
== 128)
1666 if (current_stag
->current_bitfield_offset
!= 0)
1668 current_stag
->current_bitfield_offset
= 0;
1669 ++abs_section_offset
;
1671 demand_empty_rest_of_line ();
1675 ILLEGAL_WITHIN_STRUCT ();
1677 s_align_bytes (count
<< 1);
1680 /* Initialize multiple-bit fields withing a single word of memory. */
1683 tic54x_field (int ignore ATTRIBUTE_UNUSED
)
1689 symbolS
*label
= line_label
;
1691 if (current_stag
!= NULL
)
1693 tic54x_struct_field ('.');
1697 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1699 if (*input_line_pointer
== ',')
1701 ++input_line_pointer
;
1702 size
= get_absolute_expression ();
1703 if (size
< 1 || size
> 32)
1705 as_bad (_("Invalid field size, must be from 1 to 32"));
1706 ignore_rest_of_line ();
1711 /* Truncate values to the field width. */
1712 if (expn
.X_op
!= O_constant
)
1714 /* If the expression value is relocatable, the field size *must*
1718 as_bad (_("field size must be 16 when value is relocatable"));
1719 ignore_rest_of_line ();
1723 frag_now
->tc_frag_data
= 0;
1724 emit_expr (&expn
, 2);
1728 unsigned long fmask
= (size
== 32) ? 0xFFFFFFFF : (1ul << size
) - 1;
1730 value
= expn
.X_add_number
;
1731 expn
.X_add_number
&= fmask
;
1732 if (value
!= (valueT
) expn
.X_add_number
)
1733 as_warn (_("field value truncated"));
1734 value
= expn
.X_add_number
;
1735 /* Bits are stored MS first. */
1738 frag_now
->tc_frag_data
= 0;
1740 md_number_to_chars (p
, (value
>> (size
- 16)) & 0xFFFF, 2);
1745 int bit_offset
= frag_bit_offset (frag_now
, now_seg
);
1747 fragS
*alloc_frag
= bit_offset_frag (frag_now
, now_seg
);
1748 if (bit_offset
== -1)
1750 struct bit_info
*bi
= xmalloc (sizeof (struct bit_info
));
1751 /* We don't know the previous offset at this time, so store the
1752 info we need and figure it out later. */
1753 expressionS size_exp
;
1755 size_exp
.X_op
= O_constant
;
1756 size_exp
.X_add_number
= size
;
1758 bi
->type
= TYPE_FIELD
;
1760 p
= frag_var (rs_machine_dependent
,
1761 4, 1, (relax_substateT
) 0,
1762 make_expr_symbol (&size_exp
), (offsetT
) 0,
1766 else if (bit_offset
== 0 || bit_offset
+ size
> 16)
1768 /* Align a new field. */
1770 frag_now
->tc_frag_data
= 0;
1771 alloc_frag
= frag_now
;
1775 /* Put the new value entirely within the existing one. */
1776 p
= alloc_frag
== frag_now
?
1777 frag_now
->fr_literal
+ frag_now_fix_octets () - 2 :
1778 alloc_frag
->fr_literal
;
1781 symbol_set_frag (label
, alloc_frag
);
1782 if (alloc_frag
== frag_now
)
1783 S_SET_VALUE (label
, frag_now_fix () - 1);
1787 value
<<= 16 - alloc_frag
->tc_frag_data
- size
;
1789 /* OR in existing value. */
1790 if (alloc_frag
->tc_frag_data
)
1791 value
|= ((unsigned short) p
[1] << 8) | p
[0];
1792 md_number_to_chars (p
, value
, 2);
1793 alloc_frag
->tc_frag_data
+= size
;
1794 if (alloc_frag
->tc_frag_data
== 16)
1795 alloc_frag
->tc_frag_data
= 0;
1799 demand_empty_rest_of_line ();
1802 /* Ideally, we want to check SEC_LOAD and SEC_HAS_CONTENTS, but those aren't
1803 available yet. seg_info ()->bss is the next best thing. */
1806 tic54x_initialized_section (segT seg
)
1808 return !seg_info (seg
)->bss
;
1811 /* .clink ["section name"]
1813 Marks the section as conditionally linked (link only if contents are
1814 referenced elsewhere.
1815 Without a name, refers to the current initialized section.
1816 Name is required for uninitialized sections. */
1819 tic54x_clink (int ignored ATTRIBUTE_UNUSED
)
1823 ILLEGAL_WITHIN_STRUCT ();
1825 if (*input_line_pointer
== '\"')
1827 char *section_name
= ++input_line_pointer
;
1830 while (is_a_char (next_char_of_string ()))
1832 know (input_line_pointer
[-1] == '\"');
1833 input_line_pointer
[-1] = 0;
1834 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1835 strcpy (name
, section_name
);
1837 seg
= bfd_get_section_by_name (stdoutput
, name
);
1840 as_bad (_("Unrecognized section '%s'"), section_name
);
1841 ignore_rest_of_line ();
1847 if (!tic54x_initialized_section (seg
))
1849 as_bad (_("Current section is unitialized, "
1850 "section name required for .clink"));
1851 ignore_rest_of_line ();
1856 seg
->flags
|= SEC_TIC54X_CLINK
;
1858 demand_empty_rest_of_line ();
1861 /* Change the default include directory to be the current source file's
1862 directory, instead of the current working directory. If DOT is non-zero,
1863 set to "." instead. */
1866 tic54x_set_default_include (int dot
)
1868 const char *dir
= ".";
1873 const char *curfile
;
1876 curfile
= as_where (&lineno
);
1877 dir
= strcpy (xmalloc (strlen (curfile
) + 1), curfile
);
1878 tmp
= strrchr (dir
, '/');
1886 if (include_dir_count
== 0)
1888 include_dirs
= XNEWVEC (const char *, 1);
1889 include_dir_count
= 1;
1891 include_dirs
[0] = dir
;
1892 if (len
> include_dir_maxlen
)
1893 include_dir_maxlen
= len
;
1895 else if (include_dirs
!= NULL
)
1896 include_dirs
[0] = ".";
1899 /* .include "filename" | filename
1900 .copy "filename" | filename
1902 FIXME 'include' file should be omitted from any output listing,
1903 'copy' should be included in any output listing
1904 FIXME -- prevent any included files from changing listing (compat only)
1905 FIXME -- need to include source file directory in search path; what's a
1906 good way to do this?
1908 Entering/exiting included/copied file clears all local labels. */
1911 tic54x_include (int ignored ATTRIBUTE_UNUSED
)
1913 char newblock
[] = " .newblock\n";
1918 ILLEGAL_WITHIN_STRUCT ();
1922 if (*input_line_pointer
== '"')
1924 filename
= demand_copy_C_string (&len
);
1925 demand_empty_rest_of_line ();
1929 filename
= input_line_pointer
;
1930 while (!is_end_of_line
[(int) *input_line_pointer
])
1931 ++input_line_pointer
;
1932 c
= *input_line_pointer
;
1933 *input_line_pointer
= '\0';
1934 filename
= strcpy (xmalloc (strlen (filename
) + 1), filename
);
1935 *input_line_pointer
= c
;
1936 demand_empty_rest_of_line ();
1938 /* Insert a partial line with the filename (for the sake of s_include)
1940 The included file will be inserted before the newblock, so that the
1941 newblock is executed after the included file is processed. */
1942 input
= xmalloc (sizeof (newblock
) + strlen (filename
) + 4);
1943 sprintf (input
, "\"%s\"\n%s", filename
, newblock
);
1944 input_scrub_insert_line (input
);
1946 tic54x_clear_local_labels (0);
1948 tic54x_set_default_include (0);
1954 tic54x_message (int type
)
1960 ILLEGAL_WITHIN_STRUCT ();
1962 if (*input_line_pointer
== '"')
1963 msg
= demand_copy_C_string (&len
);
1966 msg
= input_line_pointer
;
1967 while (!is_end_of_line
[(int) *input_line_pointer
])
1968 ++input_line_pointer
;
1969 c
= *input_line_pointer
;
1970 *input_line_pointer
= 0;
1971 msg
= strcpy (xmalloc (strlen (msg
) + 1), msg
);
1972 *input_line_pointer
= c
;
1978 as_tsktsk ("%s", msg
);
1981 as_warn ("%s", msg
);
1988 demand_empty_rest_of_line ();
1992 Define a special symbol that refers to the loadtime address rather than the
1993 runtime address within the current section.
1995 This symbol gets a special storage class so that when it is resolved, it is
1996 resolved relative to the load address (lma) of the section rather than the
1997 run address (vma). */
2000 tic54x_label (int ignored ATTRIBUTE_UNUSED
)
2006 ILLEGAL_WITHIN_STRUCT ();
2008 c
= get_symbol_name (&name
);
2009 symbolP
= colon (name
);
2010 S_SET_STORAGE_CLASS (symbolP
, C_STATLAB
);
2012 (void) restore_line_pointer (c
);
2013 demand_empty_rest_of_line ();
2017 Install all memory-mapped register names into the symbol table as
2018 absolute local symbols. */
2021 tic54x_mmregs (int ignored ATTRIBUTE_UNUSED
)
2025 ILLEGAL_WITHIN_STRUCT ();
2027 for (sym
= (symbol
*) mmregs
; sym
->name
; sym
++)
2029 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
2030 (valueT
) sym
->value
, &zero_address_frag
);
2031 SF_SET_LOCAL (symbolP
);
2032 symbol_table_insert (symbolP
);
2037 Count defaults to 1024. */
2040 tic54x_loop (int count
)
2042 ILLEGAL_WITHIN_STRUCT ();
2045 if (!is_end_of_line
[(int) *input_line_pointer
])
2046 count
= get_absolute_expression ();
2048 do_repeat (count
, "LOOP", "ENDLOOP");
2051 /* Normally, endloop gets eaten by the preceding loop. */
2054 tic54x_endloop (int ignore ATTRIBUTE_UNUSED
)
2056 as_bad (_("ENDLOOP without corresponding LOOP"));
2057 ignore_rest_of_line ();
2060 /* .break [condition]. */
2063 tic54x_break (int ignore ATTRIBUTE_UNUSED
)
2067 ILLEGAL_WITHIN_STRUCT ();
2070 if (!is_end_of_line
[(int) *input_line_pointer
])
2071 cond
= get_absolute_expression ();
2074 end_repeat (substitution_line
? 1 : 0);
2078 set_address_mode (int mode
)
2081 if (mode
== far_mode
)
2083 symbolS
*symbolP
= symbol_new ("__allow_far", absolute_section
,
2084 (valueT
) 1, &zero_address_frag
);
2085 SF_SET_LOCAL (symbolP
);
2086 symbol_table_insert (symbolP
);
2090 static int address_mode_needs_set
= 1;
2093 tic54x_address_mode (int mode
)
2095 if (assembly_begun
&& amode
!= (unsigned) mode
)
2097 as_bad (_("Mixing of normal and extended addressing not supported"));
2098 ignore_rest_of_line ();
2101 if (mode
== far_mode
&& cpu
!= VNONE
&& cpu
!= V548
&& cpu
!= V549
)
2103 as_bad (_("Extended addressing not supported on the specified CPU"));
2104 ignore_rest_of_line ();
2108 set_address_mode (mode
);
2109 demand_empty_rest_of_line ();
2112 /* .sblock "section"|section [,...,"section"|section]
2113 Designate initialized sections for blocking. */
2116 tic54x_sblock (int ignore ATTRIBUTE_UNUSED
)
2120 ILLEGAL_WITHIN_STRUCT ();
2127 if (*input_line_pointer
== '"')
2131 name
= demand_copy_C_string (&len
);
2137 c
= get_symbol_name (§ion_name
);
2138 name
= xmalloc (strlen (section_name
) + 1);
2139 strcpy (name
, section_name
);
2140 (void) restore_line_pointer (c
);
2143 seg
= bfd_get_section_by_name (stdoutput
, name
);
2146 as_bad (_("Unrecognized section '%s'"), name
);
2147 ignore_rest_of_line ();
2150 else if (!tic54x_initialized_section (seg
))
2152 as_bad (_(".sblock may be used for initialized sections only"));
2153 ignore_rest_of_line ();
2156 seg
->flags
|= SEC_TIC54X_BLOCK
;
2158 c
= *input_line_pointer
;
2159 if (!is_end_of_line
[(int) c
])
2160 ++input_line_pointer
;
2163 demand_empty_rest_of_line ();
2166 /* symbol .set value
2169 value must be defined externals; no forward-referencing allowed
2170 symbols assigned with .set/.equ may not be redefined. */
2173 tic54x_set (int ignore ATTRIBUTE_UNUSED
)
2178 ILLEGAL_WITHIN_STRUCT ();
2182 as_bad (_("Symbol missing for .set/.equ"));
2183 ignore_rest_of_line ();
2186 name
= xstrdup (S_GET_NAME (line_label
));
2188 if ((symbolP
= symbol_find (name
)) == NULL
2189 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2191 symbolP
= symbol_new (name
, absolute_section
, 0, &zero_address_frag
);
2192 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2195 S_SET_DATA_TYPE (symbolP
, T_INT
);
2196 S_SET_SEGMENT (symbolP
, absolute_section
);
2197 symbol_table_insert (symbolP
);
2198 pseudo_set (symbolP
);
2199 demand_empty_rest_of_line ();
2204 List false conditional blocks. */
2207 tic54x_fclist (int show
)
2210 listing
&= ~LISTING_NOCOND
;
2212 listing
|= LISTING_NOCOND
;
2213 demand_empty_rest_of_line ();
2217 tic54x_sslist (int show
)
2219 ILLEGAL_WITHIN_STRUCT ();
2221 listing_sslist
= show
;
2224 /* .var SYM[,...,SYMN]
2225 Define a substitution string to be local to a macro. */
2228 tic54x_var (int ignore ATTRIBUTE_UNUSED
)
2230 static char empty
[] = "";
2234 ILLEGAL_WITHIN_STRUCT ();
2236 if (macro_level
== 0)
2238 as_bad (_(".var may only be used within a macro definition"));
2239 ignore_rest_of_line ();
2244 if (!ISALPHA (*input_line_pointer
))
2246 as_bad (_("Substitution symbols must begin with a letter"));
2247 ignore_rest_of_line ();
2250 c
= get_symbol_name (&name
);
2251 /* .var symbols start out with a null string. */
2252 name
= strcpy (xmalloc (strlen (name
) + 1), name
);
2253 hash_insert (subsym_hash
[macro_level
], name
, empty
);
2254 c
= restore_line_pointer (c
);
2257 ++input_line_pointer
;
2258 if (is_end_of_line
[(int) *input_line_pointer
])
2259 c
= *input_line_pointer
;
2264 demand_empty_rest_of_line ();
2267 /* .mlib <macro library filename>
2269 Macro libraries are archived (standard AR-format) text macro definitions
2270 Expand the file and include it.
2272 FIXME need to try the source file directory as well. */
2275 tic54x_mlib (int ignore ATTRIBUTE_UNUSED
)
2282 ILLEGAL_WITHIN_STRUCT ();
2284 /* Parse the filename. */
2285 if (*input_line_pointer
== '"')
2287 if ((filename
= demand_copy_C_string (&len
)) == NULL
)
2294 while (!is_end_of_line
[(int) *input_line_pointer
]
2295 && !ISSPACE (*input_line_pointer
))
2297 obstack_1grow (¬es
, *input_line_pointer
);
2298 ++input_line_pointer
;
2301 obstack_1grow (¬es
, '\0');
2302 filename
= obstack_finish (¬es
);
2304 demand_empty_rest_of_line ();
2306 tic54x_set_default_include (0);
2307 path
= xmalloc ((unsigned long) len
+ include_dir_maxlen
+ 5);
2309 for (i
= 0; i
< include_dir_count
; i
++)
2313 strcpy (path
, include_dirs
[i
]);
2315 strcat (path
, filename
);
2316 if ((try = fopen (path
, "r")) != NULL
)
2323 if (i
>= include_dir_count
)
2329 /* FIXME: if path is found, malloc'd storage is not freed. Of course, this
2330 happens all over the place, and since the assembler doesn't usually keep
2331 running for a very long time, it really doesn't matter. */
2332 register_dependency (path
);
2334 /* Expand all archive entries to temporary files and include them. */
2335 abfd
= bfd_openr (path
, NULL
);
2338 as_bad (_("can't open macro library file '%s' for reading: %s"),
2339 path
, bfd_errmsg (bfd_get_error ()));
2340 ignore_rest_of_line ();
2343 if (!bfd_check_format (abfd
, bfd_archive
))
2345 as_bad (_("File '%s' not in macro archive format"), path
);
2346 ignore_rest_of_line ();
2350 /* Open each BFD as binary (it should be straight ASCII text). */
2351 for (mbfd
= bfd_openr_next_archived_file (abfd
, NULL
);
2352 mbfd
!= NULL
; mbfd
= bfd_openr_next_archived_file (abfd
, mbfd
))
2354 /* Get a size at least as big as the archive member. */
2355 bfd_size_type size
= bfd_get_size (mbfd
);
2356 char *buf
= xmalloc (size
);
2357 char *fname
= tmpnam (NULL
);
2360 /* We're not sure how big it is, but it will be smaller than "size". */
2361 size
= bfd_bread (buf
, size
, mbfd
);
2363 /* Write to a temporary file, then use s_include to include it
2365 ftmp
= fopen (fname
, "w+b");
2366 fwrite ((void *) buf
, size
, 1, ftmp
);
2367 if (size
== 0 || buf
[size
- 1] != '\n')
2368 fwrite ("\n", 1, 1, ftmp
);
2371 input_scrub_insert_file (fname
);
2376 const pseudo_typeS md_pseudo_table
[] =
2378 { "algebraic", s_ignore
, 0 },
2379 { "align" , tic54x_align_words
, 128 },
2380 { "ascii" , tic54x_stringer
, 'p' },
2381 { "asciz" , tic54x_stringer
, 'P' },
2382 { "even" , tic54x_align_words
, 2 },
2383 { "asg" , tic54x_asg
, 0 },
2384 { "eval" , tic54x_eval
, 0 },
2385 { "bss" , tic54x_bss
, 0 },
2386 { "byte" , tic54x_cons
, 'b' },
2387 { "ubyte" , tic54x_cons
, 'B' },
2388 { "char" , tic54x_cons
, 'c' },
2389 { "uchar" , tic54x_cons
, 'C' },
2390 { "clink" , tic54x_clink
, 0 },
2391 { "c_mode" , tic54x_address_mode
, c_mode
},
2392 { "copy" , tic54x_include
, 'c' },
2393 { "include" , tic54x_include
, 'i' },
2394 { "data" , tic54x_sect
, 'd' },
2395 { "double" , tic54x_float_cons
, 'd' },
2396 { "ldouble" , tic54x_float_cons
, 'l' },
2397 { "drlist" , s_ignore
, 0 },
2398 { "drnolist" , s_ignore
, 0 },
2399 { "emsg" , tic54x_message
, 'e' },
2400 { "mmsg" , tic54x_message
, 'm' },
2401 { "wmsg" , tic54x_message
, 'w' },
2402 { "far_mode" , tic54x_address_mode
, far_mode
},
2403 { "fclist" , tic54x_fclist
, 1 },
2404 { "fcnolist" , tic54x_fclist
, 0 },
2405 { "field" , tic54x_field
, -1 },
2406 { "float" , tic54x_float_cons
, 'f' },
2407 { "xfloat" , tic54x_float_cons
, 'x' },
2408 { "global" , tic54x_global
, 'g' },
2409 { "def" , tic54x_global
, 'd' },
2410 { "ref" , tic54x_global
, 'r' },
2411 { "half" , tic54x_cons
, 'h' },
2412 { "uhalf" , tic54x_cons
, 'H' },
2413 { "short" , tic54x_cons
, 's' },
2414 { "ushort" , tic54x_cons
, 'S' },
2415 { "if" , s_if
, (int) O_ne
},
2416 { "elseif" , s_elseif
, (int) O_ne
},
2417 { "else" , s_else
, 0 },
2418 { "endif" , s_endif
, 0 },
2419 { "int" , tic54x_cons
, 'i' },
2420 { "uint" , tic54x_cons
, 'I' },
2421 { "word" , tic54x_cons
, 'w' },
2422 { "uword" , tic54x_cons
, 'W' },
2423 { "label" , tic54x_label
, 0 }, /* Loadtime
2425 { "length" , s_ignore
, 0 },
2426 { "width" , s_ignore
, 0 },
2427 { "long" , tic54x_cons
, 'l' },
2428 { "ulong" , tic54x_cons
, 'L' },
2429 { "xlong" , tic54x_cons
, 'x' },
2430 { "loop" , tic54x_loop
, 1024 },
2431 { "break" , tic54x_break
, 0 },
2432 { "endloop" , tic54x_endloop
, 0 },
2433 { "mlib" , tic54x_mlib
, 0 },
2434 { "mlist" , s_ignore
, 0 },
2435 { "mnolist" , s_ignore
, 0 },
2436 { "mmregs" , tic54x_mmregs
, 0 },
2437 { "newblock" , tic54x_clear_local_labels
, 0 },
2438 { "option" , s_ignore
, 0 },
2439 { "p2align" , tic54x_p2align
, 0 },
2440 { "sblock" , tic54x_sblock
, 0 },
2441 { "sect" , tic54x_sect
, '*' },
2442 { "set" , tic54x_set
, 0 },
2443 { "equ" , tic54x_set
, 0 },
2444 { "space" , tic54x_space
, 0 },
2445 { "bes" , tic54x_space
, 1 },
2446 { "sslist" , tic54x_sslist
, 1 },
2447 { "ssnolist" , tic54x_sslist
, 0 },
2448 { "string" , tic54x_stringer
, 's' },
2449 { "pstring" , tic54x_stringer
, 'p' },
2450 { "struct" , tic54x_struct
, 0 },
2451 { "tag" , tic54x_tag
, 0 },
2452 { "endstruct", tic54x_endstruct
, 0 },
2453 { "tab" , s_ignore
, 0 },
2454 { "text" , tic54x_sect
, 't' },
2455 { "union" , tic54x_struct
, 1 },
2456 { "endunion" , tic54x_endstruct
, 1 },
2457 { "usect" , tic54x_usect
, 0 },
2458 { "var" , tic54x_var
, 0 },
2459 { "version" , tic54x_version
, 0 },
2464 md_parse_option (int c
, const char *arg
)
2470 case OPTION_COFF_VERSION
:
2472 int version
= atoi (arg
);
2474 if (version
!= 0 && version
!= 1 && version
!= 2)
2475 as_fatal (_("Bad COFF version '%s'"), arg
);
2476 /* FIXME -- not yet implemented. */
2479 case OPTION_CPU_VERSION
:
2481 cpu
= lookup_version (arg
);
2484 as_fatal (_("Bad CPU version '%s'"), arg
);
2487 case OPTION_ADDRESS_MODE
:
2489 address_mode_needs_set
= 1;
2491 case OPTION_STDERR_TO_FILE
:
2493 const char *filename
= arg
;
2494 FILE *fp
= fopen (filename
, "w+");
2497 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2499 if ((fp
= freopen (filename
, "w+", stderr
)) == NULL
)
2500 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2508 /* Create a "local" substitution string hash table for a new macro level
2509 Some docs imply that macros have to use .newblock in order to be able
2510 to re-use a local label. We effectively do an automatic .newblock by
2511 deleting the local label hash between macro invocations. */
2514 tic54x_macro_start (void)
2517 subsym_hash
[macro_level
] = hash_new ();
2518 local_label_hash
[macro_level
] = hash_new ();
2522 tic54x_macro_info (const macro_entry
*macro
)
2524 const formal_entry
*entry
;
2526 /* Put the formal args into the substitution symbol table. */
2527 for (entry
= macro
->formals
; entry
; entry
= entry
->next
)
2529 char *name
= strncpy (xmalloc (entry
->name
.len
+ 1),
2530 entry
->name
.ptr
, entry
->name
.len
);
2531 char *value
= strncpy (xmalloc (entry
->actual
.len
+ 1),
2532 entry
->actual
.ptr
, entry
->actual
.len
);
2534 name
[entry
->name
.len
] = '\0';
2535 value
[entry
->actual
.len
] = '\0';
2536 hash_insert (subsym_hash
[macro_level
], name
, value
);
2540 /* Get rid of this macro's .var's, arguments, and local labels. */
2543 tic54x_macro_end (void)
2545 hash_die (subsym_hash
[macro_level
]);
2546 subsym_hash
[macro_level
] = NULL
;
2547 hash_die (local_label_hash
[macro_level
]);
2548 local_label_hash
[macro_level
] = NULL
;
2553 subsym_symlen (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2558 /* Compare symbol A to string B. */
2561 subsym_symcmp (char *a
, char *b
)
2563 return strcmp (a
, b
);
2566 /* Return the index of the first occurrence of B in A, or zero if none
2567 assumes b is an integer char value as a string. Index is one-based. */
2570 subsym_firstch (char *a
, char *b
)
2573 char *tmp
= strchr (a
, val
);
2575 return tmp
? tmp
- a
+ 1 : 0;
2578 /* Similar to firstch, but returns index of last occurrence of B in A. */
2581 subsym_lastch (char *a
, char *b
)
2584 char *tmp
= strrchr (a
, val
);
2586 return tmp
? tmp
- a
+ 1 : 0;
2589 /* Returns 1 if string A is defined in the symbol table (NOT the substitution
2593 subsym_isdefed (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2595 symbolS
*symbolP
= symbol_find (a
);
2597 return symbolP
!= NULL
;
2600 /* Assign first member of comma-separated list B (e.g. "1,2,3") to the symbol
2601 A, or zero if B is a null string. Both arguments *must* be substitution
2602 symbols, unsubstituted. */
2605 subsym_ismember (char *sym
, char *list
)
2607 char *elem
, *ptr
, *listv
;
2612 listv
= subsym_lookup (list
, macro_level
);
2615 as_bad (_("Undefined substitution symbol '%s'"), list
);
2616 ignore_rest_of_line ();
2620 ptr
= elem
= xmalloc (strlen (listv
) + 1);
2621 strcpy (elem
, listv
);
2622 while (*ptr
&& *ptr
!= ',')
2626 subsym_create_or_replace (sym
, elem
);
2628 /* Reassign the list. */
2629 subsym_create_or_replace (list
, ptr
);
2631 /* Assume this value, docs aren't clear. */
2635 /* Return zero if not a constant; otherwise:
2643 subsym_iscons (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2647 parse_expression (a
, &expn
);
2649 if (expn
.X_op
== O_constant
)
2651 int len
= strlen (a
);
2653 switch (TOUPPER (a
[len
- 1]))
2666 /* No suffix; either octal, hex, or decimal. */
2667 if (*a
== '0' && len
> 1)
2669 if (TOUPPER (a
[1]) == 'X')
2679 /* Return 1 if A is a valid symbol name. Expects string input. */
2682 subsym_isname (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2684 if (!is_name_beginner (*a
))
2688 if (!is_part_of_name (*a
))
2695 /* Return whether the string is a register; accepts ar0-7, unless .mmregs has
2696 been seen; if so, recognize any memory-mapped register.
2697 Note this does not recognize "A" or "B" accumulators. */
2700 subsym_isreg (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2702 if (hash_find (reg_hash
, a
))
2704 if (hash_find (mmreg_hash
, a
))
2709 /* Return the structure size, given the stag. */
2712 subsym_structsz (char *name
, char *ignore ATTRIBUTE_UNUSED
)
2714 struct stag
*stag
= (struct stag
*) hash_find (stag_hash
, name
);
2722 /* If anybody actually uses this, they can fix it :)
2723 FIXME I'm not sure what the "reference point" of a structure is. It might
2724 be either the initial offset given .struct, or it may be the offset of the
2725 structure within another structure, or it might be something else
2726 altogether. since the TI assembler doesn't seem to ever do anything but
2727 return zero, we punt and return zero. */
2730 subsym_structacc (char *stag_name ATTRIBUTE_UNUSED
,
2731 char *ignore ATTRIBUTE_UNUSED
)
2737 math_ceil (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2739 return (float) ceil (arg1
);
2743 math_cvi (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2749 math_floor (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2751 return (float) floor (arg1
);
2755 math_fmod (float arg1
, float arg2
)
2757 return (int) arg1
% (int) arg2
;
2761 math_int (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2763 return ((float) ((int) arg1
)) == arg1
;
2767 math_round (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2769 return arg1
> 0 ? (int) (arg1
+ 0.5) : (int) (arg1
- 0.5);
2773 math_sgn (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2775 return (arg1
< 0) ? -1 : (arg1
? 1 : 0);
2779 math_trunc (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2785 math_acos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2787 return (float) acos (arg1
);
2791 math_asin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2793 return (float) asin (arg1
);
2797 math_atan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2799 return (float) atan (arg1
);
2803 math_atan2 (float arg1
, float arg2
)
2805 return (float) atan2 (arg1
, arg2
);
2809 math_cosh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2811 return (float) cosh (arg1
);
2815 math_cos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2817 return (float) cos (arg1
);
2821 math_cvf (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2823 return (float) arg1
;
2827 math_exp (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2829 return (float) exp (arg1
);
2833 math_fabs (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2835 return (float) fabs (arg1
);
2838 /* expr1 * 2^expr2. */
2841 math_ldexp (float arg1
, float arg2
)
2843 return arg1
* (float) pow (2.0, arg2
);
2847 math_log10 (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2849 return (float) log10 (arg1
);
2853 math_log (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2855 return (float) log (arg1
);
2859 math_max (float arg1
, float arg2
)
2861 return (arg1
> arg2
) ? arg1
: arg2
;
2865 math_min (float arg1
, float arg2
)
2867 return (arg1
< arg2
) ? arg1
: arg2
;
2871 math_pow (float arg1
, float arg2
)
2873 return (float) pow (arg1
, arg2
);
2877 math_sin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2879 return (float) sin (arg1
);
2883 math_sinh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2885 return (float) sinh (arg1
);
2889 math_sqrt (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2891 return (float) sqrt (arg1
);
2895 math_tan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2897 return (float) tan (arg1
);
2901 math_tanh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2903 return (float) tanh (arg1
);
2906 /* Built-in substitution symbol functions and math functions. */
2910 int (*proc
) (char *, char *);
2912 } subsym_proc_entry
;
2914 static const subsym_proc_entry subsym_procs
[] =
2916 /* Assembler built-in string substitution functions. */
2917 { "$symlen", subsym_symlen
, 1, },
2918 { "$symcmp", subsym_symcmp
, 2, },
2919 { "$firstch", subsym_firstch
, 2, },
2920 { "$lastch", subsym_lastch
, 2, },
2921 { "$isdefed", subsym_isdefed
, 1, },
2922 { "$ismember", subsym_ismember
, 2, },
2923 { "$iscons", subsym_iscons
, 1, },
2924 { "$isname", subsym_isname
, 1, },
2925 { "$isreg", subsym_isreg
, 1, },
2926 { "$structsz", subsym_structsz
, 1, },
2927 { "$structacc", subsym_structacc
, 1, },
2934 float (*proc
) (float, float);
2939 static const math_proc_entry math_procs
[] =
2941 /* Integer-returning built-in math functions. */
2942 { "$cvi", math_cvi
, 1, 1 },
2943 { "$int", math_int
, 1, 1 },
2944 { "$sgn", math_sgn
, 1, 1 },
2946 /* Float-returning built-in math functions. */
2947 { "$acos", math_acos
, 1, 0 },
2948 { "$asin", math_asin
, 1, 0 },
2949 { "$atan", math_atan
, 1, 0 },
2950 { "$atan2", math_atan2
, 2, 0 },
2951 { "$ceil", math_ceil
, 1, 0 },
2952 { "$cosh", math_cosh
, 1, 0 },
2953 { "$cos", math_cos
, 1, 0 },
2954 { "$cvf", math_cvf
, 1, 0 },
2955 { "$exp", math_exp
, 1, 0 },
2956 { "$fabs", math_fabs
, 1, 0 },
2957 { "$floor", math_floor
, 1, 0 },
2958 { "$fmod", math_fmod
, 2, 0 },
2959 { "$ldexp", math_ldexp
, 2, 0 },
2960 { "$log10", math_log10
, 1, 0 },
2961 { "$log", math_log
, 1, 0 },
2962 { "$max", math_max
, 2, 0 },
2963 { "$min", math_min
, 2, 0 },
2964 { "$pow", math_pow
, 2, 0 },
2965 { "$round", math_round
, 1, 0 },
2966 { "$sin", math_sin
, 1, 0 },
2967 { "$sinh", math_sinh
, 1, 0 },
2968 { "$sqrt", math_sqrt
, 1, 0 },
2969 { "$tan", math_tan
, 1, 0 },
2970 { "$tanh", math_tanh
, 1, 0 },
2971 { "$trunc", math_trunc
, 1, 0 },
2972 { NULL
, NULL
, 0, 0 },
2980 const subsym_proc_entry
*subsym_proc
;
2981 const math_proc_entry
*math_proc
;
2982 const char *hash_err
;
2984 char *TIC54X_DIR
= getenv ("TIC54X_DIR");
2985 char *A_DIR
= TIC54X_DIR
? TIC54X_DIR
: getenv ("A_DIR");
2989 /* Look for A_DIR and add it to the include list. */
2992 char *tmp
= xstrdup (A_DIR
);
2996 char *next
= strchr (tmp
, ';');
3000 add_include_dir (tmp
);
3003 while (tmp
!= NULL
);
3006 op_hash
= hash_new ();
3007 for (tm
= (insn_template
*) tic54x_optab
; tm
->name
; tm
++)
3009 if (hash_find (op_hash
, tm
->name
))
3011 hash_err
= hash_insert (op_hash
, tm
->name
, (char *) tm
);
3013 as_fatal ("Internal Error: Can't hash %s: %s",
3014 tm
->name
, hash_err
);
3016 parop_hash
= hash_new ();
3017 for (tm
= (insn_template
*) tic54x_paroptab
; tm
->name
; tm
++)
3019 if (hash_find (parop_hash
, tm
->name
))
3021 hash_err
= hash_insert (parop_hash
, tm
->name
, (char *) tm
);
3023 as_fatal ("Internal Error: Can't hash %s: %s",
3024 tm
->name
, hash_err
);
3026 reg_hash
= hash_new ();
3027 for (sym
= (symbol
*) regs
; sym
->name
; sym
++)
3029 /* Add basic registers to the symbol table. */
3030 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
3031 (valueT
) sym
->value
, &zero_address_frag
);
3032 SF_SET_LOCAL (symbolP
);
3033 symbol_table_insert (symbolP
);
3034 hash_err
= hash_insert (reg_hash
, sym
->name
, (char *) sym
);
3036 for (sym
= (symbol
*) mmregs
; sym
->name
; sym
++)
3037 hash_err
= hash_insert (reg_hash
, sym
->name
, (char *) sym
);
3038 mmreg_hash
= hash_new ();
3039 for (sym
= (symbol
*) mmregs
; sym
->name
; sym
++)
3040 hash_err
= hash_insert (mmreg_hash
, sym
->name
, (char *) sym
);
3042 cc_hash
= hash_new ();
3043 for (sym
= (symbol
*) condition_codes
; sym
->name
; sym
++)
3044 hash_err
= hash_insert (cc_hash
, sym
->name
, (char *) sym
);
3046 cc2_hash
= hash_new ();
3047 for (sym
= (symbol
*) cc2_codes
; sym
->name
; sym
++)
3048 hash_err
= hash_insert (cc2_hash
, sym
->name
, (char *) sym
);
3050 cc3_hash
= hash_new ();
3051 for (sym
= (symbol
*) cc3_codes
; sym
->name
; sym
++)
3052 hash_err
= hash_insert (cc3_hash
, sym
->name
, (char *) sym
);
3054 sbit_hash
= hash_new ();
3055 for (sym
= (symbol
*) status_bits
; sym
->name
; sym
++)
3056 hash_err
= hash_insert (sbit_hash
, sym
->name
, (char *) sym
);
3058 misc_symbol_hash
= hash_new ();
3059 for (symname
= (char **) misc_symbols
; *symname
; symname
++)
3060 hash_err
= hash_insert (misc_symbol_hash
, *symname
, *symname
);
3062 /* Only the base substitution table and local label table are initialized;
3063 the others (for local macro substitution) get instantiated as needed. */
3064 local_label_hash
[0] = hash_new ();
3065 subsym_hash
[0] = hash_new ();
3066 for (subsym_proc
= subsym_procs
; subsym_proc
->name
; subsym_proc
++)
3067 hash_err
= hash_insert (subsym_hash
[0], subsym_proc
->name
,
3068 (char *) subsym_proc
);
3070 math_hash
= hash_new ();
3071 for (math_proc
= math_procs
; math_proc
->name
; math_proc
++)
3073 /* Insert into the main subsym hash for recognition; insert into
3074 the math hash to actually store information. */
3075 hash_err
= hash_insert (subsym_hash
[0], math_proc
->name
,
3076 (char *) math_proc
);
3077 hash_err
= hash_insert (math_hash
, math_proc
->name
,
3078 (char *) math_proc
);
3080 subsym_recurse_hash
= hash_new ();
3081 stag_hash
= hash_new ();
3085 is_accumulator (struct opstruct
*operand
)
3087 return strcasecmp (operand
->buf
, "a") == 0
3088 || strcasecmp (operand
->buf
, "b") == 0;
3091 /* Return the number of operands found, or -1 on error, copying the
3092 operands into the given array and the accompanying expressions into
3096 get_operands (struct opstruct operands
[], char *line
)
3100 int expecting_operand
= 0;
3103 while (numexp
< MAX_OPERANDS
&& !is_end_of_line
[(int) *lptr
])
3105 int paren_not_balanced
= 0;
3106 char *op_start
, *op_end
;
3108 while (*lptr
&& ISSPACE (*lptr
))
3111 while (paren_not_balanced
|| *lptr
!= ',')
3115 if (paren_not_balanced
)
3117 as_bad (_("Unbalanced parenthesis in operand %d"), numexp
);
3124 ++paren_not_balanced
;
3125 else if (*lptr
== ')')
3126 --paren_not_balanced
;
3130 if (op_end
!= op_start
)
3132 int len
= op_end
- op_start
;
3134 strncpy (operands
[numexp
].buf
, op_start
, len
);
3135 operands
[numexp
].buf
[len
] = 0;
3136 /* Trim trailing spaces; while the preprocessor gets rid of most,
3137 there are weird usage patterns that can introduce them
3138 (i.e. using strings for macro args). */
3139 while (len
> 0 && ISSPACE (operands
[numexp
].buf
[len
- 1]))
3140 operands
[numexp
].buf
[--len
] = 0;
3146 if (expecting_operand
|| *lptr
== ',')
3148 as_bad (_("Expecting operand after ','"));
3154 if (*++lptr
== '\0')
3156 as_bad (_("Expecting operand after ','"));
3159 expecting_operand
= 1;
3163 while (*lptr
&& ISSPACE (*lptr
++))
3165 if (!is_end_of_line
[(int) *lptr
])
3167 as_bad (_("Extra junk on line"));
3171 /* OK, now parse them into expressions. */
3172 for (i
= 0; i
< numexp
; i
++)
3174 memset (&operands
[i
].exp
, 0, sizeof (operands
[i
].exp
));
3175 if (operands
[i
].buf
[0] == '#')
3178 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3180 else if (operands
[i
].buf
[0] == '@')
3182 /* Direct notation. */
3183 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3185 else if (operands
[i
].buf
[0] == '*')
3188 char *paren
= strchr (operands
[i
].buf
, '(');
3190 /* Allow immediate syntax in the inner expression. */
3191 if (paren
&& paren
[1] == '#')
3194 /* Pull out the lk expression or SP offset, if present. */
3197 int len
= strlen (paren
);
3198 char *end
= paren
+ len
;
3201 while (end
[-1] != ')')
3204 as_bad (_("Badly formed address expression"));
3209 parse_expression (paren
, &operands
[i
].exp
);
3213 operands
[i
].exp
.X_op
= O_absent
;
3216 parse_expression (operands
[i
].buf
, &operands
[i
].exp
);
3222 /* Predicates for different operand types. */
3225 is_immediate (struct opstruct
*operand
)
3227 return *operand
->buf
== '#';
3230 /* This is distinguished from immediate because some numbers must be constants
3231 and must *not* have the '#' prefix. */
3234 is_absolute (struct opstruct
*operand
)
3236 return operand
->exp
.X_op
== O_constant
&& !is_immediate (operand
);
3239 /* Is this an indirect operand? */
3242 is_indirect (struct opstruct
*operand
)
3244 return operand
->buf
[0] == '*';
3247 /* Is this a valid dual-memory operand? */
3250 is_dual (struct opstruct
*operand
)
3252 if (is_indirect (operand
) && strncasecmp (operand
->buf
, "*ar", 3) == 0)
3254 char *tmp
= operand
->buf
+ 3;
3259 /* Only allow *ARx, *ARx-, *ARx+, or *ARx+0%. */
3260 valid_mod
= *tmp
== '\0' ||
3261 strcasecmp (tmp
, "-") == 0 ||
3262 strcasecmp (tmp
, "+") == 0 ||
3263 strcasecmp (tmp
, "+0%") == 0;
3264 return arf
>= 2 && arf
<= 5 && valid_mod
;
3270 is_mmreg (struct opstruct
*operand
)
3272 return (is_absolute (operand
)
3273 || is_immediate (operand
)
3274 || hash_find (mmreg_hash
, operand
->buf
) != 0);
3278 is_type (struct opstruct
*operand
, enum optype type
)
3283 return operand
->buf
[0] == 0;
3286 return is_dual (operand
);
3288 return is_indirect (operand
);
3290 /* This one *must* be immediate. */
3291 return is_immediate (operand
);
3300 /* Address may be a numeric, indirect, or an expression. */
3301 return !is_immediate (operand
);
3304 return is_mmreg (operand
);
3309 return is_accumulator (operand
);
3311 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'B';
3313 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'A';
3315 return strncasecmp ("ar", operand
->buf
, 2) == 0
3316 && ISDIGIT (operand
->buf
[2]);
3318 return hash_find (sbit_hash
, operand
->buf
) != 0 || is_absolute (operand
);
3320 return hash_find (cc_hash
, operand
->buf
) != 0;
3322 return hash_find (cc2_hash
, operand
->buf
) != 0;
3324 return hash_find (cc3_hash
, operand
->buf
) != 0
3325 || is_immediate (operand
) || is_absolute (operand
);
3327 return (is_immediate (operand
) || is_absolute (operand
))
3328 && operand
->exp
.X_add_number
== 16;
3330 /* Allow st0 or st1 instead of a numeric. */
3331 return is_absolute (operand
) || is_immediate (operand
) ||
3332 strcasecmp ("st0", operand
->buf
) == 0 ||
3333 strcasecmp ("st1", operand
->buf
) == 0;
3336 return is_absolute (operand
) || is_immediate (operand
);
3338 return (is_immediate (operand
) || is_absolute (operand
))
3339 && operand
->exp
.X_add_number
>= 0 && operand
->exp
.X_add_number
< 16;
3341 /* Let this one catch out-of-range values. */
3342 return (is_immediate (operand
) || is_absolute (operand
))
3343 && operand
->exp
.X_add_number
!= 16;
3347 return is_absolute (operand
) || is_immediate (operand
);
3349 return is_immediate (operand
)
3350 && operand
->exp
.X_op
== O_constant
3351 && operand
->exp
.X_add_number
>= 0
3352 && operand
->exp
.X_add_number
< 256;
3355 /* Allow anything; assumes opcodes are ordered with Smem operands
3361 /* Just make sure it's an integer; check range later. */
3362 return is_immediate (operand
);
3364 return strcasecmp ("t", operand
->buf
) == 0 ||
3365 strcasecmp ("treg", operand
->buf
) == 0;
3367 return strcasecmp ("ts", operand
->buf
) == 0;
3369 return strcasecmp ("asm", operand
->buf
) == 0;
3371 return strcasecmp ("trn", operand
->buf
) == 0;
3373 return strcasecmp ("dp", operand
->buf
) == 0;
3375 return strcasecmp ("arp", operand
->buf
) == 0;
3382 operands_match (tic54x_insn
*insn
,
3383 struct opstruct
*operands
,
3385 const enum optype
*refoptype
,
3389 int op
= 0, refop
= 0;
3391 if (opcount
== 0 && minops
== 0)
3394 while (op
<= maxops
&& refop
<= maxops
)
3396 while (!is_type (&operands
[op
], OPTYPE (refoptype
[refop
])))
3398 /* Skip an optional template operand if it doesn't agree
3399 with the current operand. */
3400 if (refoptype
[refop
] & OPT
)
3411 /* Save the actual operand type for later use. */
3412 operands
[op
].type
= OPTYPE (refoptype
[refop
]);
3415 /* Have we matched them all yet? */
3420 /* If a later operand is *not* optional, no match. */
3421 if ((refoptype
[refop
] & OPT
) == 0)
3423 /* Flag any implicit default OP_DST operands so we know to add
3424 them explicitly when encoding the operand later. */
3425 if (OPTYPE (refoptype
[refop
]) == OP_DST
)
3426 insn
->using_default_dst
= 1;
3438 /* 16-bit direct memory address
3439 Explicit dmad operands are always in last word of insn (usually second
3440 word, but bumped to third if lk addressing is used)
3442 We allow *(dmad) notation because the TI assembler allows it.
3445 0 for 16-bit addresses
3446 1 for full 23-bit addresses
3447 2 for the upper 7 bits of a 23-bit address (LDX). */
3450 encode_dmad (tic54x_insn
*insn
, struct opstruct
*operand
, int xpc_code
)
3452 int op
= 1 + insn
->is_lkaddr
;
3454 /* Only allow *(dmad) expressions; all others are invalid. */
3455 if (is_indirect (operand
) && operand
->buf
[strlen (operand
->buf
) - 1] != ')')
3457 as_bad (_("Invalid dmad syntax '%s'"), operand
->buf
);
3461 insn
->opcode
[op
].addr_expr
= operand
->exp
;
3463 if (insn
->opcode
[op
].addr_expr
.X_op
== O_constant
)
3465 valueT value
= insn
->opcode
[op
].addr_expr
.X_add_number
;
3469 insn
->opcode
[0].word
&= 0xFF80;
3470 insn
->opcode
[0].word
|= (value
>> 16) & 0x7F;
3471 insn
->opcode
[1].word
= value
& 0xFFFF;
3473 else if (xpc_code
== 2)
3474 insn
->opcode
[op
].word
= (value
>> 16) & 0xFFFF;
3476 insn
->opcode
[op
].word
= value
;
3480 /* Do the fixup later; just store the expression. */
3481 insn
->opcode
[op
].word
= 0;
3482 insn
->opcode
[op
].r_nchars
= 2;
3484 if (amode
== c_mode
)
3485 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3486 else if (xpc_code
== 1)
3488 /* This relocation spans two words, so adjust accordingly. */
3489 insn
->opcode
[0].addr_expr
= operand
->exp
;
3490 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_23
;
3491 insn
->opcode
[0].r_nchars
= 4;
3492 insn
->opcode
[0].unresolved
= 1;
3493 /* It's really 2 words, but we want to stop encoding after the
3494 first, since we must encode both words at once. */
3497 else if (xpc_code
== 2)
3498 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_MS7_OF_23
;
3500 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3502 insn
->opcode
[op
].unresolved
= 1;
3508 /* 7-bit direct address encoding. */
3511 encode_address (tic54x_insn
*insn
, struct opstruct
*operand
)
3513 /* Assumes that dma addresses are *always* in word 0 of the opcode. */
3514 insn
->opcode
[0].addr_expr
= operand
->exp
;
3516 if (operand
->exp
.X_op
== O_constant
)
3517 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
& 0x7F);
3520 if (operand
->exp
.X_op
== O_register
)
3521 as_bad (_("Use the .mmregs directive to use memory-mapped register names such as '%s'"), operand
->buf
);
3522 /* Do the fixup later; just store the expression. */
3523 insn
->opcode
[0].r_nchars
= 1;
3524 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_PARTLS7
;
3525 insn
->opcode
[0].unresolved
= 1;
3532 encode_indirect (tic54x_insn
*insn
, struct opstruct
*operand
)
3537 if (insn
->is_lkaddr
)
3539 /* lk addresses always go in the second insn word. */
3540 mod
= ((TOUPPER (operand
->buf
[1]) == 'A') ? 12 :
3541 (operand
->buf
[1] == '(') ? 15 :
3542 (strchr (operand
->buf
, '%') != NULL
) ? 14 : 13);
3543 arf
= ((mod
== 12) ? operand
->buf
[3] - '0' :
3544 (mod
== 15) ? 0 : operand
->buf
[4] - '0');
3546 insn
->opcode
[1].addr_expr
= operand
->exp
;
3548 if (operand
->exp
.X_op
== O_constant
)
3549 insn
->opcode
[1].word
= operand
->exp
.X_add_number
;
3552 insn
->opcode
[1].word
= 0;
3553 insn
->opcode
[1].r_nchars
= 2;
3554 insn
->opcode
[1].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3555 insn
->opcode
[1].unresolved
= 1;
3558 else if (strncasecmp (operand
->buf
, "*sp (", 4) == 0)
3560 /* Stack offsets look the same as 7-bit direct addressing. */
3561 return encode_address (insn
, operand
);
3565 arf
= (TOUPPER (operand
->buf
[1]) == 'A' ?
3566 operand
->buf
[3] : operand
->buf
[4]) - '0';
3568 if (operand
->buf
[1] == '+')
3570 mod
= 3; /* *+ARx */
3571 if (insn
->tm
->flags
& FL_SMR
)
3572 as_warn (_("Address mode *+ARx is write-only. "
3573 "Results of reading are undefined."));
3575 else if (operand
->buf
[4] == '\0')
3577 else if (operand
->buf
[5] == '\0')
3578 mod
= (operand
->buf
[4] == '-' ? 1 : 2); /* *ARx+ / *ARx- */
3579 else if (operand
->buf
[6] == '\0')
3581 if (operand
->buf
[5] == '0')
3582 mod
= (operand
->buf
[4] == '-' ? 5 : 6); /* *ARx+0 / *ARx-0 */
3584 mod
= (operand
->buf
[4] == '-' ? 8 : 10);/* *ARx+% / *ARx-% */
3586 else if (TOUPPER (operand
->buf
[6]) == 'B')
3587 mod
= (operand
->buf
[4] == '-' ? 4 : 7); /* ARx+0B / *ARx-0B */
3588 else if (TOUPPER (operand
->buf
[6]) == '%')
3589 mod
= (operand
->buf
[4] == '-' ? 9 : 11); /* ARx+0% / *ARx - 0% */
3592 as_bad (_("Unrecognized indirect address format \"%s\""),
3598 insn
->opcode
[0].word
|= 0x80 | (mod
<< 3) | arf
;
3604 encode_integer (tic54x_insn
*insn
,
3605 struct opstruct
*operand
,
3609 unsigned short mask
)
3611 long parse
, integer
;
3613 insn
->opcode
[which
].addr_expr
= operand
->exp
;
3615 if (operand
->exp
.X_op
== O_constant
)
3617 parse
= operand
->exp
.X_add_number
;
3618 /* Hack -- fixup for 16-bit hex quantities that get converted positive
3619 instead of negative. */
3620 if ((parse
& 0x8000) && min
== -32768 && max
== 32767)
3621 integer
= (short) parse
;
3625 if (integer
>= min
&& integer
<= max
)
3627 insn
->opcode
[which
].word
|= (integer
& mask
);
3630 as_bad (_("Operand '%s' out of range (%d <= x <= %d)"),
3631 operand
->buf
, min
, max
);
3635 if (insn
->opcode
[which
].addr_expr
.X_op
== O_constant
)
3637 insn
->opcode
[which
].word
|=
3638 insn
->opcode
[which
].addr_expr
.X_add_number
& mask
;
3642 /* Do the fixup later; just store the expression. */
3643 bfd_reloc_code_real_type rtype
=
3644 (mask
== 0x1FF ? BFD_RELOC_TIC54X_PARTMS9
:
3645 mask
== 0xFFFF ? BFD_RELOC_TIC54X_16_OF_23
:
3646 mask
== 0x7F ? BFD_RELOC_TIC54X_PARTLS7
: BFD_RELOC_8
);
3647 int size
= (mask
== 0x1FF || mask
== 0xFFFF) ? 2 : 1;
3649 if (rtype
== BFD_RELOC_8
)
3650 as_bad (_("Error in relocation handling"));
3652 insn
->opcode
[which
].r_nchars
= size
;
3653 insn
->opcode
[which
].r_type
= rtype
;
3654 insn
->opcode
[which
].unresolved
= 1;
3664 encode_condition (tic54x_insn
*insn
, struct opstruct
*operand
)
3666 symbol
*cc
= (symbol
*) hash_find (cc_hash
, operand
->buf
);
3669 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3672 #define CC_GROUP 0x40
3674 #define CATG_A1 0x07
3675 #define CATG_B1 0x30
3676 #define CATG_A2 0x30
3677 #define CATG_B2 0x0C
3678 #define CATG_C2 0x03
3679 /* Disallow group 1 conditions mixed with group 2 conditions
3680 if group 1, allow only one category A and one category B
3681 if group 2, allow only one each of category A, B, and C. */
3682 if (((insn
->opcode
[0].word
& 0xFF) != 0))
3684 if ((insn
->opcode
[0].word
& CC_GROUP
) != (cc
->value
& CC_GROUP
))
3686 as_bad (_("Condition \"%s\" does not match preceding group"),
3690 if (insn
->opcode
[0].word
& CC_GROUP
)
3692 if ((insn
->opcode
[0].word
& CC_ACC
) != (cc
->value
& CC_ACC
))
3694 as_bad (_("Condition \"%s\" uses a different accumulator from "
3695 "a preceding condition"),
3699 if ((insn
->opcode
[0].word
& CATG_A1
) && (cc
->value
& CATG_A1
))
3701 as_bad (_("Only one comparison conditional allowed"));
3704 if ((insn
->opcode
[0].word
& CATG_B1
) && (cc
->value
& CATG_B1
))
3706 as_bad (_("Only one overflow conditional allowed"));
3710 else if ( ((insn
->opcode
[0].word
& CATG_A2
) && (cc
->value
& CATG_A2
))
3711 || ((insn
->opcode
[0].word
& CATG_B2
) && (cc
->value
& CATG_B2
))
3712 || ((insn
->opcode
[0].word
& CATG_C2
) && (cc
->value
& CATG_C2
)))
3714 as_bad (_("Duplicate %s conditional"), operand
->buf
);
3719 insn
->opcode
[0].word
|= cc
->value
;
3724 encode_cc3 (tic54x_insn
*insn
, struct opstruct
*operand
)
3726 symbol
*cc3
= (symbol
*) hash_find (cc3_hash
, operand
->buf
);
3727 int value
= cc3
? cc3
->value
: operand
->exp
.X_add_number
<< 8;
3729 if ((value
& 0x0300) != value
)
3731 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3734 insn
->opcode
[0].word
|= value
;
3739 encode_arx (tic54x_insn
*insn
, struct opstruct
*operand
)
3741 int arf
= strlen (operand
->buf
) >= 3 ? operand
->buf
[2] - '0' : -1;
3743 if (strncasecmp ("ar", operand
->buf
, 2) || arf
< 0 || arf
> 7)
3745 as_bad (_("Invalid auxiliary register (use AR0-AR7)"));
3748 insn
->opcode
[0].word
|= arf
;
3753 encode_cc2 (tic54x_insn
*insn
, struct opstruct
*operand
)
3755 symbol
*cc2
= (symbol
*) hash_find (cc2_hash
, operand
->buf
);
3759 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3762 insn
->opcode
[0].word
|= cc2
->value
;
3767 encode_operand (tic54x_insn
*insn
, enum optype type
, struct opstruct
*operand
)
3769 int ext
= (insn
->tm
->flags
& FL_EXT
) != 0;
3771 if (type
== OP_MMR
&& operand
->exp
.X_op
!= O_constant
)
3773 /* Disallow long-constant addressing for memory-mapped addressing. */
3774 if (insn
->is_lkaddr
)
3776 as_bad (_("lk addressing modes are invalid for memory-mapped "
3777 "register addressing"));
3781 /* Warn about *+ARx when used with MMR operands. */
3782 if (strncasecmp (operand
->buf
, "*+ar", 4) == 0)
3784 as_warn (_("Address mode *+ARx is not allowed in memory-mapped "
3785 "register addressing. Resulting behavior is "
3795 /* 16-bit immediate value. */
3796 return encode_dmad (insn
, operand
, 0);
3798 if (TOUPPER (*operand
->buf
) == 'B')
3800 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 9);
3801 if (insn
->using_default_dst
)
3802 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3806 /* Make sure this agrees with the OP_DST operand. */
3807 if (!((TOUPPER (operand
->buf
[0]) == 'B') ^
3808 ((insn
->opcode
[0].word
& (1 << 8)) != 0)))
3810 as_bad (_("Destination accumulator for each part of this parallel "
3811 "instruction must be different"));
3817 if (TOUPPER (operand
->buf
[0]) == 'B')
3818 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3823 int mod
= (operand
->buf
[4] == '\0' ? 0 : /* *arx */
3824 operand
->buf
[4] == '-' ? 1 : /* *arx- */
3825 operand
->buf
[5] == '\0' ? 2 : 3); /* *arx+, *arx+0% */
3826 int arf
= operand
->buf
[3] - '0' - 2;
3827 int code
= (mod
<< 2) | arf
;
3828 insn
->opcode
[0].word
|= (code
<< (type
== OP_Xmem
? 4 : 0));
3833 if (!is_indirect (operand
))
3834 return encode_address (insn
, operand
);
3837 return encode_indirect (insn
, operand
);
3839 return encode_dmad (insn
, operand
, 2);
3841 return encode_dmad (insn
, operand
, 1);
3844 return encode_dmad (insn
, operand
, 0);
3846 return encode_arx (insn
, operand
);
3851 int value
= operand
->exp
.X_add_number
;
3854 insn
->opcode
[0].word
|= value
;
3857 if (value
< 16 || value
> 24)
3859 as_bad (_("Memory mapped register \"%s\" out of range"),
3863 if (type
== OP_MMRX
)
3864 insn
->opcode
[0].word
|= (value
- 16) << 4;
3866 insn
->opcode
[0].word
|= (value
- 16);
3874 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3877 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3880 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3881 -32768, 32767, 0xFFFF);
3883 return encode_condition (insn
, operand
);
3885 return encode_cc2 (insn
, operand
);
3887 return encode_cc3 (insn
, operand
);
3889 return encode_integer (insn
, operand
, 0, 0, 15, 0xF);
3891 return encode_integer (insn
, operand
, 0, -128, 127, 0xFF);
3894 int value
= operand
->exp
.X_add_number
;
3896 if (value
< 1 || value
> 3)
3898 as_bad (_("Invalid operand (use 1, 2, or 3)"));
3901 code
= value
== 1 ? 0 : value
== 2 ? 0x2 : 0x1;
3902 insn
->opcode
[0].word
|= (code
<< 8);
3906 return encode_integer (insn
, operand
, 0, 0, 31, 0x1F);
3908 return encode_integer (insn
, operand
, 0, 0, 255, 0xFF);
3910 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3914 symbol
*sbit
= (symbol
*) hash_find (sbit_hash
, operand
->buf
);
3915 int value
= is_absolute (operand
) ?
3916 operand
->exp
.X_add_number
: (sbit
? sbit
->value
: -1);
3919 if (insn
->opcount
== 1)
3923 as_bad (_("A status register or status bit name is required"));
3926 /* Guess the register based on the status bit; "ovb" is the last
3927 status bit defined for st0. */
3928 if (sbit
> (symbol
*) hash_find (sbit_hash
, "ovb"))
3933 as_bad (_("Unrecognized status bit \"%s\""), operand
->buf
);
3936 insn
->opcode
[0].word
|= value
;
3937 insn
->opcode
[0].word
|= (reg
<< 9);
3941 if (strcasecmp (operand
->buf
, "st0") == 0
3942 || strcasecmp (operand
->buf
, "st1") == 0)
3944 insn
->opcode
[0].word
|=
3945 ((unsigned short) (operand
->buf
[2] - '0')) << 9;
3948 else if (operand
->exp
.X_op
== O_constant
3949 && (operand
->exp
.X_add_number
== 0
3950 || operand
->exp
.X_add_number
== 1))
3952 insn
->opcode
[0].word
|=
3953 ((unsigned short) (operand
->exp
.X_add_number
)) << 9;
3956 as_bad (_("Invalid status register \"%s\""), operand
->buf
);
3959 return encode_integer (insn
, operand
, 0, -16, 15, 0x1F);
3961 return encode_integer (insn
, operand
, 0, 0, 7, 0x7);
3963 return encode_integer (insn
, operand
, 0, 0, 0x1FF, 0x1FF);
3965 if (operand
->exp
.X_add_number
!= 1
3966 && operand
->exp
.X_add_number
!= 2)
3968 as_bad (_("Operand \"%s\" out of range (use 1 or 2)"), operand
->buf
);
3971 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
- 1) << 9;
3980 /* No encoding necessary. */
3990 emit_insn (tic54x_insn
*insn
)
3993 flagword oldflags
= bfd_get_section_flags (stdoutput
, now_seg
);
3994 flagword flags
= oldflags
| SEC_CODE
;
3996 if (! bfd_set_section_flags (stdoutput
, now_seg
, flags
))
3997 as_warn (_("error setting flags for \"%s\": %s"),
3998 bfd_section_name (stdoutput
, now_seg
),
3999 bfd_errmsg (bfd_get_error ()));
4001 for (i
= 0; i
< insn
->words
; i
++)
4003 int size
= (insn
->opcode
[i
].unresolved
4004 && insn
->opcode
[i
].r_type
== BFD_RELOC_TIC54X_23
) ? 4 : 2;
4005 char *p
= frag_more (size
);
4008 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
, 2);
4010 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
<< 16, 4);
4012 if (insn
->opcode
[i
].unresolved
)
4013 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
,
4014 insn
->opcode
[i
].r_nchars
, &insn
->opcode
[i
].addr_expr
,
4015 FALSE
, insn
->opcode
[i
].r_type
);
4019 /* Convert the operand strings into appropriate opcode values
4020 return the total number of words used by the instruction. */
4023 build_insn (tic54x_insn
*insn
)
4027 /* Only non-parallel instructions support lk addressing. */
4028 if (!(insn
->tm
->flags
& FL_PAR
))
4030 for (i
= 0; i
< insn
->opcount
; i
++)
4032 if ((OPTYPE (insn
->operands
[i
].type
) == OP_Smem
4033 || OPTYPE (insn
->operands
[i
].type
) == OP_Lmem
4034 || OPTYPE (insn
->operands
[i
].type
) == OP_Sind
)
4035 && strchr (insn
->operands
[i
].buf
, '(')
4036 /* Don't mistake stack-relative addressing for lk addressing. */
4037 && strncasecmp (insn
->operands
[i
].buf
, "*sp (", 4) != 0)
4039 insn
->is_lkaddr
= 1;
4040 insn
->lkoperand
= i
;
4045 insn
->words
= insn
->tm
->words
+ insn
->is_lkaddr
;
4047 insn
->opcode
[0].word
= insn
->tm
->opcode
;
4048 if (insn
->tm
->flags
& FL_EXT
)
4049 insn
->opcode
[1 + insn
->is_lkaddr
].word
= insn
->tm
->opcode2
;
4051 for (i
= 0; i
< insn
->opcount
; i
++)
4053 enum optype type
= insn
->operands
[i
].type
;
4055 if (!encode_operand (insn
, type
, &insn
->operands
[i
]))
4058 if (insn
->tm
->flags
& FL_PAR
)
4059 for (i
= 0; i
< insn
->paropcount
; i
++)
4061 enum optype partype
= insn
->paroperands
[i
].type
;
4063 if (!encode_operand (insn
, partype
, &insn
->paroperands
[i
]))
4073 optimize_insn (tic54x_insn
*insn
)
4075 /* Optimize some instructions, helping out the brain-dead programmer. */
4076 #define is_zero(op) ((op).exp.X_op == O_constant && (op).exp.X_add_number == 0)
4077 if (strcasecmp (insn
->tm
->name
, "add") == 0)
4079 if (insn
->opcount
> 1
4080 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4081 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4082 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4083 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4086 insn
->using_default_dst
= 1;
4090 /* Try to collapse if Xmem and shift count is zero. */
4091 if ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4092 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
4093 && is_zero (insn
->operands
[1]))
4094 /* Or if Smem, shift is zero or absent, and SRC == DST. */
4095 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4096 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4097 && is_type (&insn
->operands
[1], OP_SHIFT
)
4098 && is_zero (insn
->operands
[1]) && insn
->opcount
== 3))
4100 insn
->operands
[1] = insn
->operands
[2];
4105 else if (strcasecmp (insn
->tm
->name
, "ld") == 0)
4107 if (insn
->opcount
== 3 && insn
->operands
[0].type
!= OP_SRC
)
4109 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4110 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4111 && is_zero (insn
->operands
[1])
4112 && (OPTYPE (insn
->tm
->operand_types
[0]) != OP_lk
4113 || (insn
->operands
[0].exp
.X_op
== O_constant
4114 && insn
->operands
[0].exp
.X_add_number
<= 255
4115 && insn
->operands
[0].exp
.X_add_number
>= 0)))
4117 insn
->operands
[1] = insn
->operands
[2];
4123 else if (strcasecmp (insn
->tm
->name
, "sth") == 0
4124 || strcasecmp (insn
->tm
->name
, "stl") == 0)
4126 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4127 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4128 && is_zero (insn
->operands
[1]))
4130 insn
->operands
[1] = insn
->operands
[2];
4135 else if (strcasecmp (insn
->tm
->name
, "sub") == 0)
4137 if (insn
->opcount
> 1
4138 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4139 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4140 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4141 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4144 insn
->using_default_dst
= 1;
4148 if ( ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4149 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
)
4150 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4151 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
))
4152 && is_zero (insn
->operands
[1])
4153 && insn
->opcount
== 3)
4155 insn
->operands
[1] = insn
->operands
[2];
4163 /* Find a matching template if possible, and get the operand strings. */
4166 tic54x_parse_insn (tic54x_insn
*insn
, char *line
)
4168 insn
->tm
= (insn_template
*) hash_find (op_hash
, insn
->mnemonic
);
4171 as_bad (_("Unrecognized instruction \"%s\""), insn
->mnemonic
);
4175 insn
->opcount
= get_operands (insn
->operands
, line
);
4176 if (insn
->opcount
< 0)
4179 /* Check each variation of operands for this mnemonic. */
4180 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
, insn
->mnemonic
) == 0)
4182 if (insn
->opcount
>= insn
->tm
->minops
4183 && insn
->opcount
<= insn
->tm
->maxops
4184 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4185 insn
->tm
->operand_types
,
4186 insn
->tm
->minops
, insn
->tm
->maxops
))
4188 /* SUCCESS! now try some optimizations. */
4189 if (optimize_insn (insn
))
4191 insn
->tm
= (insn_template
*) hash_find (op_hash
,
4200 as_bad (_("Unrecognized operand list '%s' for instruction '%s'"),
4201 line
, insn
->mnemonic
);
4205 /* We set this in start_line_hook, 'cause if we do a line replacement, we
4206 won't be able to see the next line. */
4207 static int parallel_on_next_line_hint
= 0;
4209 /* See if this is part of a parallel instruction
4210 Look for a subsequent line starting with "||". */
4213 next_line_shows_parallel (char *next_line
)
4215 /* Look for the second half. */
4216 while (ISSPACE (*next_line
))
4219 return (next_line
[0] == PARALLEL_SEPARATOR
4220 && next_line
[1] == PARALLEL_SEPARATOR
);
4224 tic54x_parse_parallel_insn_firstline (tic54x_insn
*insn
, char *line
)
4226 insn
->tm
= (insn_template
*) hash_find (parop_hash
, insn
->mnemonic
);
4229 as_bad (_("Unrecognized parallel instruction \"%s\""),
4234 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4235 insn
->mnemonic
) == 0)
4237 insn
->opcount
= get_operands (insn
->operands
, line
);
4238 if (insn
->opcount
< 0)
4240 if (insn
->opcount
== 2
4241 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4242 insn
->tm
->operand_types
, 2, 2))
4248 /* Didn't find a matching parallel; try for a normal insn. */
4252 /* Parse the second line of a two-line parallel instruction. */
4255 tic54x_parse_parallel_insn_lastline (tic54x_insn
*insn
, char *line
)
4257 int valid_mnemonic
= 0;
4259 insn
->paropcount
= get_operands (insn
->paroperands
, line
);
4260 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4261 insn
->mnemonic
) == 0)
4263 if (strcasecmp (insn
->tm
->parname
, insn
->parmnemonic
) == 0)
4267 if (insn
->paropcount
>= insn
->tm
->minops
4268 && insn
->paropcount
<= insn
->tm
->maxops
4269 && operands_match (insn
, insn
->paroperands
,
4271 insn
->tm
->paroperand_types
,
4272 insn
->tm
->minops
, insn
->tm
->maxops
))
4278 as_bad (_("Invalid operand (s) for parallel instruction \"%s\""),
4281 as_bad (_("Unrecognized parallel instruction combination \"%s || %s\""),
4282 insn
->mnemonic
, insn
->parmnemonic
);
4287 /* If quotes found, return copy of line up to closing quote;
4288 otherwise up until terminator.
4289 If it's a string, pass as-is; otherwise attempt substitution symbol
4290 replacement on the value. */
4293 subsym_get_arg (char *line
, const char *terminators
, char **str
, int nosub
)
4297 int is_string
= *line
== '"';
4298 int is_char
= ISDIGIT (*line
);
4302 while (ISDIGIT (*ptr
))
4305 *str
= xmalloc (ptr
- line
+ 1);
4306 strncpy (*str
, line
, ptr
- line
);
4307 (*str
)[ptr
- line
] = 0;
4311 char *savedp
= input_line_pointer
;
4314 input_line_pointer
= ptr
;
4315 *str
= demand_copy_C_string (&len
);
4316 endp
= input_line_pointer
;
4317 input_line_pointer
= savedp
;
4319 /* Do forced substitutions if requested. */
4320 if (!nosub
&& **str
== ':')
4321 *str
= subsym_substitute (*str
, 1);
4325 const char *term
= terminators
;
4328 while (*ptr
&& *ptr
!= *term
)
4339 *str
= xmalloc (ptr
- line
+ 1);
4340 strncpy (*str
, line
, ptr
- line
);
4341 (*str
)[ptr
- line
] = 0;
4342 /* Do simple substitution, if available. */
4343 if (!nosub
&& (value
= subsym_lookup (*str
, macro_level
)) != NULL
)
4350 /* Replace the given substitution string.
4351 We start at the innermost macro level, so that existing locals remain local
4352 Note: we're treating macro args identically to .var's; I don't know if
4353 that's compatible w/TI's assembler. */
4356 subsym_create_or_replace (char *name
, char *value
)
4360 for (i
= macro_level
; i
> 0; i
--)
4362 if (hash_find (subsym_hash
[i
], name
))
4364 hash_replace (subsym_hash
[i
], name
, value
);
4368 if (hash_find (subsym_hash
[0], name
))
4369 hash_replace (subsym_hash
[0], name
, value
);
4371 hash_insert (subsym_hash
[0], name
, value
);
4374 /* Look up the substitution string replacement for the given symbol.
4375 Start with the innermost macro substitution table given and work
4379 subsym_lookup (char *name
, int nest_level
)
4381 char *value
= hash_find (subsym_hash
[nest_level
], name
);
4383 if (value
|| nest_level
== 0)
4386 return subsym_lookup (name
, nest_level
- 1);
4389 /* Do substitution-symbol replacement on the given line (recursively).
4390 return the argument if no substitution was done
4392 Also look for built-in functions ($func (arg)) and local labels.
4394 If FORCED is set, look for forced substitutions of the form ':SYMBOL:'. */
4397 subsym_substitute (char *line
, int forced
)
4399 /* For each apparent symbol, see if it's a substitution symbol, and if so,
4400 replace it in the input. */
4401 char *replacement
; /* current replacement for LINE. */
4402 char *head
; /* Start of line. */
4403 char *ptr
; /* Current examination point. */
4404 int changed
= 0; /* Did we make a substitution? */
4405 int eval_line
= 0; /* Is this line a .eval/.asg statement? */
4406 int eval_symbol
= 0; /* Are we in the middle of the symbol for
4408 char *eval_end
= NULL
;
4410 int line_conditional
= 0;
4413 /* Work with a copy of the input line. */
4414 replacement
= xmalloc (strlen (line
) + 1);
4415 strcpy (replacement
, line
);
4417 ptr
= head
= replacement
;
4419 /* Flag lines where we might need to replace a single '=' with two;
4420 GAS uses single '=' to assign macro args values, and possibly other
4421 places, so limit what we replace. */
4422 if (strstr (line
, ".if")
4423 || strstr (line
, ".elseif")
4424 || strstr (line
, ".break"))
4425 line_conditional
= 1;
4427 /* Watch out for .eval, so that we avoid doing substitution on the
4428 symbol being assigned a value. */
4429 if (strstr (line
, ".eval") || strstr (line
, ".asg"))
4432 /* If it's a macro definition, don't do substitution on the argument
4434 if (strstr (line
, ".macro"))
4437 while (!is_end_of_line
[(int) *ptr
])
4439 int current_char
= *ptr
;
4441 /* Need to update this since LINE may have been modified. */
4443 eval_end
= strrchr (ptr
, ',');
4445 /* Replace triple double quotes with bounding quote/escapes. */
4446 if (current_char
== '"' && ptr
[1] == '"' && ptr
[2] == '"')
4449 tmp
= strstr (ptr
+ 2, "\"\"\"");
4455 /* Replace a single '=' with a '==';
4456 for compatibility with older code only. */
4457 if (line_conditional
&& current_char
== '=')
4465 tmp
= xmalloc (strlen (head
) + 2 + strlen (ptr
) + 1);
4466 sprintf (tmp
, "%s==%s", head
, ptr
);
4467 /* Continue examining after the '=='. */
4468 ptr
= tmp
+ strlen (head
) + 2;
4470 head
= replacement
= tmp
;
4474 /* Flag when we've reached the symbol part of .eval/.asg. */
4475 if (eval_line
&& ptr
>= eval_end
)
4478 /* For each apparent symbol, see if it's a substitution symbol, and if
4479 so, replace it in the input. */
4480 if ((forced
&& current_char
== ':')
4481 || (!forced
&& is_name_beginner (current_char
)))
4483 char *name
; /* Symbol to be replaced. */
4484 char *savedp
= input_line_pointer
;
4487 char *tail
; /* Rest of line after symbol. */
4489 /* Skip the colon. */
4493 input_line_pointer
= ptr
;
4494 c
= get_symbol_name (&name
);
4495 /* '?' is not normally part of a symbol, but it IS part of a local
4499 *input_line_pointer
++ = c
;
4500 c
= *input_line_pointer
;
4501 *input_line_pointer
= '\0';
4503 /* Avoid infinite recursion; if a symbol shows up a second time for
4504 substitution, leave it as is. */
4505 if (hash_find (subsym_recurse_hash
, name
) == NULL
)
4506 value
= subsym_lookup (name
, macro_level
);
4508 as_warn (_("%s symbol recursion stopped at "
4509 "second appearance of '%s'"),
4510 forced
? "Forced substitution" : "Substitution", name
);
4511 ptr
= tail
= input_line_pointer
;
4512 input_line_pointer
= savedp
;
4514 /* Check for local labels; replace them with the appropriate
4516 if ((*name
== '$' && ISDIGIT (name
[1]) && name
[2] == '\0')
4517 || name
[strlen (name
) - 1] == '?')
4519 /* Use an existing identifier for that label if, available, or
4520 create a new, unique identifier. */
4521 value
= hash_find (local_label_hash
[macro_level
], name
);
4525 char *namecopy
= xstrdup (name
);
4527 value
= strcpy (xmalloc (strlen (name
) + sizeof (digit
) + 1),
4530 value
[strlen (value
) - 1] = '\0';
4531 sprintf (digit
, ".%d", local_label_id
++);
4532 strcat (value
, digit
);
4533 hash_insert (local_label_hash
[macro_level
], namecopy
, value
);
4535 /* Indicate where to continue looking for substitutions. */
4538 /* Check for built-in subsym and math functions. */
4539 else if (value
!= NULL
&& *name
== '$')
4541 subsym_proc_entry
*entry
= (subsym_proc_entry
*) value
;
4542 math_proc_entry
*math_entry
= hash_find (math_hash
, name
);
4543 char *arg1
, *arg2
= NULL
;
4548 as_bad (_("Unrecognized substitution symbol function"));
4551 else if (*ptr
!= '(')
4553 as_bad (_("Missing '(' after substitution symbol function"));
4557 if (math_entry
!= NULL
)
4559 float farg1
, farg2
= 0;
4560 volatile float fresult
;
4562 farg1
= (float) strtod (ptr
, &ptr
);
4563 if (math_entry
->nargs
== 2)
4567 as_bad (_("Expecting second argument"));
4570 farg2
= (float) strtod (ptr
, &ptr
);
4572 fresult
= (*math_entry
->proc
) (farg1
, farg2
);
4573 value
= xmalloc (128);
4574 if (math_entry
->int_return
)
4575 sprintf (value
, "%d", (int) fresult
);
4577 sprintf (value
, "%f", fresult
);
4580 as_bad (_("Extra junk in function call, expecting ')'"));
4583 /* Don't bother recursing; the replacement isn't a
4590 int arg_type
[2] = { *ptr
== '"' , 0 };
4591 int ismember
= !strcmp (entry
->name
, "$ismember");
4593 /* Parse one or two args, which must be a substitution
4594 symbol, string or a character-string constant. */
4595 /* For all functions, a string or substitution symbol may be
4596 used, with the following exceptions:
4597 firstch/lastch: 2nd arg must be character constant
4598 ismember: both args must be substitution symbols. */
4599 ptr
= subsym_get_arg (ptr
, ",)", &arg1
, ismember
);
4602 if (entry
->nargs
== 2)
4606 as_bad (_("Function expects two arguments"));
4609 /* Character constants are converted to numerics
4610 by the preprocessor. */
4611 arg_type
[1] = (ISDIGIT (*ptr
)) ? 2 : (*ptr
== '"');
4612 ptr
= subsym_get_arg (ptr
, ")", &arg2
, ismember
);
4614 /* Args checking. */
4615 if ((!strcmp (entry
->name
, "$firstch")
4616 || !strcmp (entry
->name
, "$lastch"))
4617 && arg_type
[1] != 2)
4619 as_bad (_("Expecting character constant argument"));
4623 && (arg_type
[0] != 0 || arg_type
[1] != 0))
4625 as_bad (_("Both arguments must be substitution symbols"));
4630 as_bad (_("Extra junk in function call, expecting ')'"));
4633 val
= (*entry
->proc
) (arg1
, arg2
);
4634 value
= xmalloc (64);
4635 sprintf (value
, "%d", val
);
4637 /* Fix things up to replace the entire expression, not just the
4643 if (value
!= NULL
&& !eval_symbol
)
4645 /* Replace the symbol with its string replacement and
4646 continue. Recursively replace VALUE until either no
4647 substitutions are performed, or a substitution that has been
4648 previously made is encountered again.
4650 Put the symbol into the recursion hash table so we only
4651 try to replace a symbol once. */
4654 hash_insert (subsym_recurse_hash
, name
, name
);
4655 value
= subsym_substitute (value
, macro_level
> 0);
4656 hash_delete (subsym_recurse_hash
, name
, FALSE
);
4659 /* Temporarily zero-terminate where the symbol started. */
4665 /* Subscripted substitution symbol -- use just the
4666 indicated portion of the string; the description
4667 kinda indicates that forced substitution is not
4668 supposed to be recursive, but I'm not sure. */
4669 unsigned beg
, len
= 1; /* default to a single char */
4670 char *newval
= strcpy (xmalloc (strlen (value
) + 1),
4673 savedp
= input_line_pointer
;
4674 input_line_pointer
= tail
+ 1;
4675 beg
= get_absolute_expression ();
4678 as_bad (_("Invalid subscript (use 1 to %d)"),
4679 (int) strlen (value
));
4682 if (*input_line_pointer
== ',')
4684 ++input_line_pointer
;
4685 len
= get_absolute_expression ();
4686 if (beg
+ len
> strlen (value
))
4688 as_bad (_("Invalid length (use 0 to %d"),
4689 (int) strlen (value
) - beg
);
4695 tail
= input_line_pointer
;
4698 as_bad (_("Missing ')' in subscripted substitution "
4699 "symbol expression"));
4703 input_line_pointer
= savedp
;
4709 tmp
= xmalloc (strlen (head
) + strlen (value
) +
4710 strlen (tail
+ 1) + 2);
4712 strcat (tmp
, value
);
4713 /* Make sure forced substitutions are properly terminated. */
4718 as_bad (_("Missing forced substitution terminator ':'"));
4724 /* Restore the character after the symbol end. */
4727 /* Continue examining after the replacement value. */
4728 ptr
= tmp
+ strlen (head
) + strlen (value
);
4730 head
= replacement
= tmp
;
4748 /* We use this to handle substitution symbols
4749 hijack input_line_pointer, replacing it with our substituted string.
4751 .sslist should enable listing the line after replacements are made...
4753 returns the new buffer limit. */
4756 tic54x_start_line_hook (void)
4759 char *replacement
= NULL
;
4761 /* Work with a copy of the input line, including EOL char. */
4762 endp
= input_line_pointer
;
4763 while (!is_end_of_line
[(int) *endp
++])
4765 line
= xmalloc (endp
- input_line_pointer
+ 1);
4766 strncpy (line
, input_line_pointer
, endp
- input_line_pointer
+ 1);
4767 line
[endp
- input_line_pointer
] = 0;
4769 /* Scan ahead for parallel insns. */
4770 parallel_on_next_line_hint
= next_line_shows_parallel (endp
);
4772 /* If within a macro, first process forced replacements. */
4773 if (macro_level
> 0)
4774 replacement
= subsym_substitute (line
, 1);
4777 replacement
= subsym_substitute (replacement
, 0);
4779 if (replacement
!= line
)
4781 char *tmp
= replacement
;
4782 char *comment
= strchr (replacement
, ';');
4783 char endc
= replacement
[strlen (replacement
) - 1];
4785 /* Clean up the replacement; we'd prefer to have this done by the
4786 standard preprocessing equipment (maybe do_scrub_chars?)
4787 but for now, do a quick-and-dirty. */
4788 if (comment
!= NULL
)
4795 comment
= replacement
+ strlen (replacement
) - 1;
4797 /* Trim trailing whitespace. */
4798 while (ISSPACE (*comment
))
4805 /* Compact leading whitespace. */
4806 while (ISSPACE (tmp
[0]) && ISSPACE (tmp
[1]))
4809 input_line_pointer
= endp
;
4810 input_scrub_insert_line (tmp
);
4813 /* Keep track of whether we've done a substitution. */
4814 substitution_line
= 1;
4820 substitution_line
= 0;
4824 /* This is the guts of the machine-dependent assembler. STR points to a
4825 machine dependent instruction. This function is supposed to emit
4826 the frags/bytes it assembles to. */
4828 md_assemble (char *line
)
4830 static int repeat_slot
= 0;
4831 static int delay_slots
= 0; /* How many delay slots left to fill? */
4832 static int is_parallel
= 0;
4833 static tic54x_insn insn
;
4835 char *savedp
= input_line_pointer
;
4838 input_line_pointer
= line
;
4839 c
= get_symbol_name (&line
);
4843 if (address_mode_needs_set
)
4845 set_address_mode (amode
);
4846 address_mode_needs_set
= 0;
4859 strcpy (insn
.parmnemonic
, line
);
4860 lptr
= input_line_pointer
;
4862 input_line_pointer
= savedp
;
4864 if (tic54x_parse_parallel_insn_lastline (&insn
, lptr
))
4866 int words
= build_insn (&insn
);
4868 if (delay_slots
!= 0)
4870 if (words
> delay_slots
)
4872 as_bad (_("Instruction does not fit in available delay "
4873 "slots (%d-word insn, %d slots left)"),
4874 words
, delay_slots
);
4878 delay_slots
-= words
;
4884 memset (&insn
, 0, sizeof (insn
));
4885 strcpy (insn
.mnemonic
, line
);
4886 lptr
= input_line_pointer
;
4888 input_line_pointer
= savedp
;
4890 /* See if this line is part of a parallel instruction; if so, either this
4891 line or the next line will have the "||" specifier preceding the
4892 mnemonic, and we look for it in the parallel insn hash table. */
4893 if (strstr (line
, "||") != NULL
|| parallel_on_next_line_hint
)
4895 char *tmp
= strstr (line
, "||");
4899 if (tic54x_parse_parallel_insn_firstline (&insn
, lptr
))
4902 /* If the parallel part is on the same line, process it now,
4903 otherwise let the assembler pick up the next line for us. */
4906 while (ISSPACE (tmp
[2]))
4908 md_assemble (tmp
+ 2);
4913 as_bad (_("Unrecognized parallel instruction '%s'"), line
);
4918 if (tic54x_parse_insn (&insn
, lptr
))
4922 if ((insn
.tm
->flags
& FL_LP
)
4923 && cpu
!= V545LP
&& cpu
!= V546LP
)
4925 as_bad (_("Instruction '%s' requires an LP cpu version"),
4929 if ((insn
.tm
->flags
& FL_FAR
)
4930 && amode
!= far_mode
)
4932 as_bad (_("Instruction '%s' requires far mode addressing"),
4937 words
= build_insn (&insn
);
4939 /* Is this instruction in a delay slot? */
4942 if (words
> delay_slots
)
4944 as_warn (_("Instruction does not fit in available delay "
4945 "slots (%d-word insn, %d slots left). "
4946 "Resulting behavior is undefined."),
4947 words
, delay_slots
);
4951 /* Branches in delay slots are not allowed. */
4952 if (insn
.tm
->flags
& FL_BMASK
)
4954 as_warn (_("Instructions which cause PC discontinuity are not "
4955 "allowed in a delay slot. "
4956 "Resulting behavior is undefined."));
4958 delay_slots
-= words
;
4961 /* Is this instruction the target of a repeat? */
4964 if (insn
.tm
->flags
& FL_NR
)
4965 as_warn (_("'%s' is not repeatable. "
4966 "Resulting behavior is undefined."),
4968 else if (insn
.is_lkaddr
)
4969 as_warn (_("Instructions using long offset modifiers or absolute "
4970 "addresses are not repeatable. "
4971 "Resulting behavior is undefined."));
4975 /* Make sure we check the target of a repeat instruction. */
4976 if (insn
.tm
->flags
& B_REPEAT
)
4979 /* FIXME -- warn if repeat_slot == 1 at EOF. */
4981 /* Make sure we check our delay slots for validity. */
4982 if (insn
.tm
->flags
& FL_DELAY
)
4985 /* FIXME -- warn if delay_slots != 0 at EOF. */
4990 /* Do a final adjustment on the symbol table; in this case, make sure we have
4991 a ".file" symbol. */
4994 tic54x_adjust_symtab (void)
4996 if (symbol_rootP
== NULL
4997 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
5000 const char * filename
= as_where (&lineno
);
5001 c_dot_file_symbol (filename
, 0);
5005 /* In order to get gas to ignore any | chars at the start of a line,
5006 this function returns true if a | is found in a line.
5007 This lets us process parallel instructions, which span two lines. */
5010 tic54x_unrecognized_line (int c
)
5012 return c
== PARALLEL_SEPARATOR
;
5015 /* Watch for local labels of the form $[0-9] and [_a-zA-Z][_a-zA-Z0-9]*?
5016 Encode their names so that only we see them and can map them to the
5018 FIXME -- obviously this isn't done yet. These locals still show up in the
5021 tic54x_define_label (symbolS
*sym
)
5023 /* Just in case we need this later; note that this is not necessarily the
5024 same thing as line_label...
5025 When aligning or assigning labels to fields, sometimes the label is
5026 assigned other than the address at which the label appears.
5027 FIXME -- is this really needed? I think all the proper label assignment
5028 is done in tic54x_cons. */
5029 last_label_seen
= sym
;
5032 /* Try to parse something that normal parsing failed at. */
5035 tic54x_undefined_symbol (char *name
)
5039 /* Not sure how to handle predefined symbols. */
5040 if ((sym
= (symbol
*) hash_find (cc_hash
, name
)) != NULL
||
5041 (sym
= (symbol
*) hash_find (cc2_hash
, name
)) != NULL
||
5042 (sym
= (symbol
*) hash_find (cc3_hash
, name
)) != NULL
||
5043 (sym
= (symbol
*) hash_find (misc_symbol_hash
, name
)) != NULL
||
5044 (sym
= (symbol
*) hash_find (sbit_hash
, name
)) != NULL
)
5046 return symbol_new (name
, reg_section
,
5047 (valueT
) sym
->value
,
5048 &zero_address_frag
);
5051 if ((sym
= (symbol
*) hash_find (reg_hash
, name
)) != NULL
||
5052 (sym
= (symbol
*) hash_find (mmreg_hash
, name
)) != NULL
||
5053 !strcasecmp (name
, "a") || !strcasecmp (name
, "b"))
5055 return symbol_new (name
, reg_section
,
5056 (valueT
) sym
? sym
->value
: 0,
5057 &zero_address_frag
);
5063 /* Parse a name in an expression before the expression parser takes a stab at
5067 tic54x_parse_name (char *name ATTRIBUTE_UNUSED
,
5068 expressionS
*expn ATTRIBUTE_UNUSED
)
5074 md_atof (int type
, char *literalP
, int *sizeP
)
5076 /* Target data is little-endian, but floats are stored
5077 big-"word"ian. ugh. */
5078 return ieee_md_atof (type
, literalP
, sizeP
, TRUE
);
5082 tc_gen_reloc (asection
*section
, fixS
*fixP
)
5085 bfd_reloc_code_real_type code
= fixP
->fx_r_type
;
5086 asymbol
*sym
= symbol_get_bfdsym (fixP
->fx_addsy
);
5088 rel
= (arelent
*) xmalloc (sizeof (arelent
));
5089 rel
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5090 *rel
->sym_ptr_ptr
= sym
;
5091 /* We assume that all rel->address are host byte offsets. */
5092 rel
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5093 rel
->address
/= OCTETS_PER_BYTE
;
5094 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
5095 if (!strcmp (sym
->name
, section
->name
))
5096 rel
->howto
+= HOWTO_BANK
;
5100 const char *name
= S_GET_NAME (fixP
->fx_addsy
);
5103 as_fatal ("Cannot generate relocation type for symbol %s, code %s",
5104 name
, bfd_get_reloc_code_name (code
));
5110 /* Handle cons expressions. */
5113 tic54x_cons_fix_new (fragS
*frag
, int where
, int octets
, expressionS
*expn
,
5114 bfd_reloc_code_real_type r
)
5119 as_bad (_("Unsupported relocation size %d"), octets
);
5120 r
= BFD_RELOC_TIC54X_16_OF_23
;
5123 r
= BFD_RELOC_TIC54X_16_OF_23
;
5126 /* TI assembler always uses this, regardless of addressing mode. */
5128 r
= BFD_RELOC_TIC54X_23
;
5130 /* We never want to directly generate this; this is provided for
5131 stabs support only. */
5135 fix_new_exp (frag
, where
, octets
, expn
, 0, r
);
5138 /* Attempt to simplify or even eliminate a fixup.
5139 To indicate that a fixup has been eliminated, set fixP->fx_done.
5141 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry. */
5144 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
5146 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
5147 valueT val
= * valP
;
5149 switch (fixP
->fx_r_type
)
5152 as_fatal ("Bad relocation type: 0x%02x", fixP
->fx_r_type
);
5154 case BFD_RELOC_TIC54X_MS7_OF_23
:
5155 val
= (val
>> 16) & 0x7F;
5157 case BFD_RELOC_TIC54X_16_OF_23
:
5159 bfd_put_16 (stdoutput
, val
, buf
);
5160 /* Indicate what we're actually writing, so that we don't get warnings
5161 about exceeding available space. */
5162 *valP
= val
& 0xFFFF;
5164 case BFD_RELOC_TIC54X_PARTLS7
:
5165 bfd_put_16 (stdoutput
,
5166 (bfd_get_16 (stdoutput
, buf
) & 0xFF80) | (val
& 0x7F),
5168 /* Indicate what we're actually writing, so that we don't get warnings
5169 about exceeding available space. */
5172 case BFD_RELOC_TIC54X_PARTMS9
:
5173 /* TI assembler doesn't shift its encoding for relocatable files, and is
5174 thus incompatible with this implementation's relocatable files. */
5175 bfd_put_16 (stdoutput
,
5176 (bfd_get_16 (stdoutput
, buf
) & 0xFE00) | (val
>> 7),
5180 case BFD_RELOC_TIC54X_23
:
5181 bfd_put_32 (stdoutput
,
5182 (bfd_get_32 (stdoutput
, buf
) & 0xFF800000) | val
,
5187 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
5191 /* This is our chance to record section alignment
5192 don't need to do anything here, since BFD does the proper encoding. */
5195 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT section_size
)
5197 return section_size
;
5201 md_pcrel_from (fixS
*fixP ATTRIBUTE_UNUSED
)
5206 /* Mostly little-endian, but longwords (4 octets) get MS word stored
5210 tic54x_number_to_chars (char *buf
, valueT val
, int n
)
5213 number_to_chars_littleendian (buf
, val
, n
);
5216 number_to_chars_littleendian (buf
, val
>> 16 , 2);
5217 number_to_chars_littleendian (buf
+ 2, val
& 0xFFFF, 2);
5222 tic54x_estimate_size_before_relax (fragS
*frag ATTRIBUTE_UNUSED
,
5223 segT seg ATTRIBUTE_UNUSED
)
5228 /* We use this to handle bit allocations which we couldn't handle before due
5229 to symbols being in different frags. return number of octets added. */
5232 tic54x_relax_frag (fragS
*frag
, long stretch ATTRIBUTE_UNUSED
)
5234 symbolS
*sym
= frag
->fr_symbol
;
5240 struct bit_info
*bi
= (struct bit_info
*) frag
->fr_opcode
;
5241 int bit_offset
= frag_bit_offset (frag_prev (frag
, bi
->seg
), bi
->seg
);
5242 int size
= S_GET_VALUE (sym
);
5243 fragS
*prev_frag
= bit_offset_frag (frag_prev (frag
, bi
->seg
), bi
->seg
);
5244 int available
= 16 - bit_offset
;
5246 if (symbol_get_frag (sym
) != &zero_address_frag
5247 || S_IS_COMMON (sym
)
5248 || !S_IS_DEFINED (sym
))
5249 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5250 _("non-absolute value used with .space/.bes"));
5254 as_warn (_("negative value ignored in %s"),
5255 bi
->type
== TYPE_SPACE
? ".space" :
5256 bi
->type
== TYPE_BES
? ".bes" : ".field");
5258 frag
->tc_frag_data
= frag
->fr_fix
= 0;
5262 if (bi
->type
== TYPE_FIELD
)
5264 /* Bit fields of 16 or larger will have already been handled. */
5265 if (bit_offset
!= 0 && available
>= size
)
5267 char *p
= prev_frag
->fr_literal
;
5269 valueT value
= bi
->value
;
5270 value
<<= available
- size
;
5271 value
|= ((unsigned short) p
[1] << 8) | p
[0];
5272 md_number_to_chars (p
, value
, 2);
5273 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5274 prev_frag
->tc_frag_data
= 0;
5276 symbol_set_frag (bi
->sym
, prev_frag
);
5277 /* This frag is no longer used. */
5278 growth
= -frag
->fr_fix
;
5280 frag
->tc_frag_data
= 0;
5284 char *p
= frag
->fr_literal
;
5286 valueT value
= bi
->value
<< (16 - size
);
5287 md_number_to_chars (p
, value
, 2);
5288 if ((frag
->tc_frag_data
= size
) == 16)
5289 frag
->tc_frag_data
= 0;
5295 if (bit_offset
!= 0 && bit_offset
< 16)
5297 if (available
>= size
)
5299 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5300 prev_frag
->tc_frag_data
= 0;
5302 symbol_set_frag (bi
->sym
, prev_frag
);
5303 /* This frag is no longer used. */
5304 growth
= -frag
->fr_fix
;
5306 frag
->tc_frag_data
= 0;
5309 if (bi
->type
== TYPE_SPACE
&& bi
->sym
)
5310 symbol_set_frag (bi
->sym
, prev_frag
);
5313 growth
= (size
+ 15) / 16 * OCTETS_PER_BYTE
- frag
->fr_fix
;
5314 for (i
= 0; i
< growth
; i
++)
5315 frag
->fr_literal
[i
] = 0;
5316 frag
->fr_fix
= growth
;
5317 frag
->tc_frag_data
= size
% 16;
5318 /* Make sure any BES label points to the LAST word allocated. */
5319 if (bi
->type
== TYPE_BES
&& bi
->sym
)
5320 S_SET_VALUE (bi
->sym
, frag
->fr_fix
/ OCTETS_PER_BYTE
- 1);
5323 frag
->fr_symbol
= 0;
5324 frag
->fr_opcode
= 0;
5331 tic54x_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5332 segT seg ATTRIBUTE_UNUSED
,
5335 /* Offset is in bytes. */
5336 frag
->fr_offset
= (frag
->fr_next
->fr_address
5338 - frag
->fr_fix
) / frag
->fr_var
;
5339 if (frag
->fr_offset
< 0)
5341 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5342 _("attempt to .space/.bes backwards? (%ld)"),
5343 (long) frag
->fr_offset
);
5345 frag
->fr_type
= rs_space
;
5348 /* We need to avoid having labels defined for certain directives/pseudo-ops
5349 since once the label is defined, it's in the symbol table for good. TI
5350 syntax puts the symbol *before* the pseudo (which is kinda like MRI syntax,
5351 I guess, except I've never seen a definition of MRI syntax).
5353 Don't allow labels to start with '.' */
5356 tic54x_start_label (int nul_char
, int next_char
)
5360 /* If within .struct/.union, no auto line labels, please. */
5361 if (current_stag
!= NULL
)
5364 /* Disallow labels starting with "." */
5365 if (next_char
!= ':')
5367 char *label
= input_line_pointer
;
5369 while (!is_end_of_line
[(int) label
[-1]])
5373 as_bad (_("Invalid label '%s'"), label
);
5378 if (is_end_of_line
[(int) next_char
])
5381 rest
= input_line_pointer
;
5382 if (nul_char
== '"')
5384 while (ISSPACE (next_char
))
5385 next_char
= *++rest
;
5386 if (next_char
!= '.')
5389 /* Don't let colon () define a label for any of these... */
5390 return ((strncasecmp (rest
, ".tag", 4) != 0 || !ISSPACE (rest
[4]))
5391 && (strncasecmp (rest
, ".struct", 7) != 0 || !ISSPACE (rest
[7]))
5392 && (strncasecmp (rest
, ".union", 6) != 0 || !ISSPACE (rest
[6]))
5393 && (strncasecmp (rest
, ".macro", 6) != 0 || !ISSPACE (rest
[6]))
5394 && (strncasecmp (rest
, ".set", 4) != 0 || !ISSPACE (rest
[4]))
5395 && (strncasecmp (rest
, ".equ", 4) != 0 || !ISSPACE (rest
[4])));