1 /* tc-tic54x.c -- Assembly code for the Texas Instruments TMS320C54X
2 Copyright (C) 1999-2020 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 "opcode/tic54x.h"
60 symbolS
*sym
; /* Symbol for this stag; value is offset. */
61 const char *name
; /* Shortcut to symbol name. */
62 bfd_vma size
; /* Size of struct/union. */
63 int current_bitfield_offset
; /* Temporary for tracking fields. */
65 struct stag_field
/* List of fields. */
68 bfd_vma offset
; /* Of start of this field. */
69 int bitfield_offset
; /* Of start of this field. */
70 struct stag
*stag
; /* If field is struct/union. */
71 struct stag_field
*next
;
73 /* For nesting; used only in stag construction. */
74 struct stag
*inner
; /* Enclosed .struct. */
75 struct stag
*outer
; /* Enclosing .struct. */
76 } *current_stag
= NULL
;
78 #define MAX_LINE 256 /* Lines longer than this are truncated by TI's asm. */
80 typedef struct _tic54x_insn
82 const insn_template
*tm
; /* Opcode template. */
84 char mnemonic
[MAX_LINE
]; /* Opcode name/mnemonic. */
85 char parmnemonic
[MAX_LINE
]; /* 2nd mnemonic of parallel insn. */
93 } operands
[MAX_OPERANDS
];
96 struct opstruct paroperands
[MAX_OPERANDS
];
100 int words
; /* Size of insn in 16-bit words. */
101 int using_default_dst
; /* Do we need to explicitly set an
102 omitted OP_DST operand? */
105 unsigned short word
; /* Final encoded opcode data. */
107 int r_nchars
; /* Relocation size. */
108 bfd_reloc_code_real_type r_type
; /* Relocation type. */
109 expressionS addr_expr
; /* Storage for unresolved expressions. */
115 VNONE
= 0, V541
= 1, V542
= 2, V543
= 3, V545
= 5, V548
= 8, V549
= 9,
116 V545LP
= 15, V546LP
= 16
121 c_mode
, /* 16-bit addresses. */
122 far_mode
/* >16-bit addresses. */
125 static segT stag_saved_seg
;
126 static subsegT stag_saved_subseg
;
128 const char comment_chars
[] = ";";
129 const char line_comment_chars
[] = ";*#"; /* At column zero only. */
130 const char line_separator_chars
[] = ""; /* Not permitted. */
132 int emitting_long
= 0;
134 /* Characters which indicate that this is a floating point constant. */
135 const char FLT_CHARS
[] = "fF";
137 /* Characters that can be used to separate mantissa from exp in FP
139 const char EXP_CHARS
[] = "eE";
141 const char *md_shortopts
= "";
143 #define OPTION_ADDRESS_MODE (OPTION_MD_BASE)
144 #define OPTION_CPU_VERSION (OPTION_ADDRESS_MODE + 1)
145 #define OPTION_COFF_VERSION (OPTION_CPU_VERSION + 1)
146 #define OPTION_STDERR_TO_FILE (OPTION_COFF_VERSION + 1)
148 struct option md_longopts
[] =
150 { "mfar-mode", no_argument
, NULL
, OPTION_ADDRESS_MODE
},
151 { "mf", no_argument
, NULL
, OPTION_ADDRESS_MODE
},
152 { "mcpu", required_argument
, NULL
, OPTION_CPU_VERSION
},
153 { "merrors-to-file", required_argument
, NULL
, OPTION_STDERR_TO_FILE
},
154 { "me", required_argument
, NULL
, OPTION_STDERR_TO_FILE
},
155 { NULL
, no_argument
, NULL
, 0},
158 size_t md_longopts_size
= sizeof (md_longopts
);
160 static int assembly_begun
= 0;
161 /* Addressing mode is not entirely implemented; the latest rev of the Other
162 assembler doesn't seem to make any distinction whatsoever; all relocations
163 are stored as extended relocations. Older versions used REL16 vs RELEXT16,
164 but now it seems all relocations are RELEXT16. We use all RELEXT16.
166 The cpu version is kind of a waste of time as well. There is one
167 instruction (RND) for LP devices only, and several for devices with
168 extended addressing only. We include it for compatibility. */
169 static enum address_mode amode
= c_mode
;
170 static enum cpu_version cpu
= VNONE
;
172 /* Include string substitutions in listing? */
173 static int listing_sslist
= 0;
175 /* Did we do subsym substitutions on the line? */
176 static int substitution_line
= 0;
178 /* Last label seen. */
179 static symbolS
*last_label_seen
= NULL
;
181 /* This ensures that all new labels are unique. */
182 static int local_label_id
;
184 static htab_t subsym_recurse_hash
; /* Prevent infinite recurse. */
185 static htab_t math_hash
; /* Built-in math functions. */
186 /* Allow maximum levels of macro nesting; level 0 is the main substitution
187 symbol table. The other assembler only does 32 levels, so there! */
188 #define MAX_SUBSYM_HASH 100
189 static htab_t subsym_hash
[MAX_SUBSYM_HASH
];
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 htab_t local_label_hash
[100];
201 /* Keep track of struct/union tags. */
202 static htab_t stag_hash
;
203 static htab_t op_hash
;
204 static htab_t parop_hash
;
205 static htab_t reg_hash
;
206 static htab_t mmreg_hash
;
207 static htab_t cc_hash
;
208 static htab_t cc2_hash
;
209 static htab_t cc3_hash
;
210 static htab_t sbit_hash
;
211 static htab_t 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 octet 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
[(unsigned char) c
])
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 name
= xstrdup (name
);
411 (void) restore_line_pointer (c
);
413 if (!ISALPHA (*name
))
415 as_bad (_("symbols assigned with .eval must begin with a letter"));
416 ignore_rest_of_line ();
419 symbolP
= symbol_new (name
, absolute_section
, &zero_address_frag
, value
);
420 SF_SET_LOCAL (symbolP
);
421 symbol_table_insert (symbolP
);
423 /* The "other" assembler sometimes doesn't put .eval's in the subsym table
424 But since there's not written rule as to when, don't even bother trying
425 to match their behavior. */
426 sprintf (valuestr
, "%d", value
);
427 tmp
= xstrdup (valuestr
);
428 subsym_create_or_replace (name
, tmp
);
430 demand_empty_rest_of_line ();
433 /* .bss symbol, size [, [blocking flag] [, alignment flag]
435 alignment is to a longword boundary; blocking is to 128-word boundary.
437 1) if there is a hole in memory, this directive should attempt to fill it
438 (not yet implemented).
440 2) if the blocking flag is not set, allocate at the current SPC
441 otherwise, check to see if the current SPC plus the space to be
442 allocated crosses the page boundary (128 words).
443 if there's not enough space, create a hole and align with the next page
445 (not yet implemented). */
448 tic54x_bss (int x ATTRIBUTE_UNUSED
)
455 subsegT current_subseg
;
460 ILLEGAL_WITHIN_STRUCT ();
462 current_seg
= now_seg
; /* Save current seg. */
463 current_subseg
= now_subseg
; /* Save current subseg. */
465 c
= get_symbol_name (&name
); /* Get terminator. */
467 c
= * ++ input_line_pointer
;
470 as_bad (_(".bss size argument missing\n"));
471 ignore_rest_of_line ();
475 ++input_line_pointer
;
476 words
= get_absolute_expression ();
479 as_bad (_(".bss size %d < 0!"), words
);
480 ignore_rest_of_line ();
484 if (*input_line_pointer
== ',')
486 /* The blocking flag may be missing. */
487 ++input_line_pointer
;
488 if (*input_line_pointer
!= ',')
489 block
= get_absolute_expression ();
493 if (*input_line_pointer
== ',')
495 ++input_line_pointer
;
496 align
= get_absolute_expression ();
504 subseg_set (bss_section
, 0);
505 symbolP
= symbol_find_or_make (name
);
507 if (S_GET_SEGMENT (symbolP
) == bss_section
)
508 symbol_get_frag (symbolP
)->fr_symbol
= (symbolS
*) NULL
;
510 symbol_set_frag (symbolP
, frag_now
);
511 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
512 (offsetT
) (words
* OCTETS_PER_BYTE
), (char *) 0);
513 *p
= 0; /* Fill char. */
515 S_SET_SEGMENT (symbolP
, bss_section
);
517 /* The symbol may already have been created with a preceding
518 ".globl" directive -- be careful not to step on storage class
519 in that case. Otherwise, set it to static. */
520 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
521 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
525 /* s_align eats end of line; restore it */
527 --input_line_pointer
;
531 bss_section
->flags
|= SEC_TIC54X_BLOCK
;
533 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
534 demand_empty_rest_of_line ();
538 stag_add_field_symbols (struct stag
*stag
,
542 const char *root_stag_name
)
545 struct stag_field
*field
= stag
->field
;
547 /* Construct a symbol for every field contained within this structure
548 including fields within structure fields. */
549 prefix
= concat (path
, *path
? "." : "", NULL
);
551 while (field
!= NULL
)
553 char *name
= concat (prefix
, field
->name
, NULL
);
558 sym
= symbol_new (name
, absolute_section
, &zero_address_frag
,
559 (field
->stag
? field
->offset
560 : base_offset
+ field
->offset
));
562 symbol_table_insert (sym
);
568 replacement
= concat (S_GET_NAME (rootsym
), "+", root_stag_name
,
569 name
+ strlen (S_GET_NAME (rootsym
)), NULL
);
570 str_hash_insert (subsym_hash
[0], name
, replacement
, 0);
573 /* Recurse if the field is a structure.
574 Note the field offset is relative to the outermost struct. */
575 if (field
->stag
!= NULL
)
576 stag_add_field_symbols (field
->stag
, name
,
578 rootsym
, root_stag_name
);
585 /* Keep track of stag fields so that when structures are nested we can add the
586 complete dereferencing symbols to the symbol table. */
589 stag_add_field (struct stag
*parent
,
594 struct stag_field
*sfield
= XCNEW (struct stag_field
);
596 sfield
->name
= xstrdup (name
);
597 sfield
->offset
= offset
;
598 sfield
->bitfield_offset
= parent
->current_bitfield_offset
;
600 if (parent
->field
== NULL
)
601 parent
->field
= sfield
;
604 struct stag_field
*sf
= parent
->field
;
605 while (sf
->next
!= NULL
)
609 /* Only create a symbol for this field if the parent has no name. */
610 if (!strncmp (".fake", parent
->name
, 5))
612 symbolS
*sym
= symbol_new (name
, absolute_section
, &zero_address_frag
,
615 symbol_table_insert (sym
);
619 /* [STAG] .struct [OFFSET]
620 Start defining structure offsets (symbols in absolute section). */
623 tic54x_struct (int arg
)
625 int start_offset
= 0;
630 /* Starting a new struct, switch to absolute section. */
631 stag_saved_seg
= now_seg
;
632 stag_saved_subseg
= now_subseg
;
633 subseg_set (absolute_section
, 0);
635 /* Align the current pointer. */
636 else if (current_stag
->current_bitfield_offset
!= 0)
638 ++abs_section_offset
;
639 current_stag
->current_bitfield_offset
= 0;
642 /* Offset expression is only meaningful for global .structs. */
645 /* Offset is ignored in inner structs. */
647 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
648 start_offset
= get_absolute_expression ();
655 /* Nesting, link to outer one. */
656 current_stag
->inner
= XCNEW (struct stag
);
657 current_stag
->inner
->outer
= current_stag
;
658 current_stag
= current_stag
->inner
;
660 as_warn (_("Offset on nested structures is ignored"));
661 start_offset
= abs_section_offset
;
665 current_stag
= XCNEW (struct stag
);
666 abs_section_offset
= start_offset
;
668 current_stag
->is_union
= is_union
;
670 if (line_label
== NULL
)
672 static int struct_count
= 0;
673 char fake
[] = ".fake_stagNNNNNNN";
674 sprintf (fake
, ".fake_stag%d", struct_count
++);
675 current_stag
->sym
= symbol_new (fake
, absolute_section
,
681 char * label
= xstrdup (S_GET_NAME (line_label
));
682 current_stag
->sym
= symbol_new (label
,
688 current_stag
->name
= S_GET_NAME (current_stag
->sym
);
689 SF_SET_LOCAL (current_stag
->sym
);
690 /* Nested .structs don't go into the symbol table. */
691 if (current_stag
->outer
== NULL
)
692 symbol_table_insert (current_stag
->sym
);
697 /* [LABEL] .endstruct
698 finish defining structure offsets; optional LABEL's value will be the size
702 tic54x_endstruct (int is_union
)
706 !strncmp (current_stag
->name
, ".fake", 5) ? "" : current_stag
->name
;
708 if (!current_stag
|| current_stag
->is_union
!= is_union
)
710 as_bad (_(".end%s without preceding .%s"),
711 is_union
? "union" : "struct",
712 is_union
? "union" : "struct");
713 ignore_rest_of_line ();
717 /* Align end of structures. */
718 if (current_stag
->current_bitfield_offset
)
720 ++abs_section_offset
;
721 current_stag
->current_bitfield_offset
= 0;
724 if (current_stag
->is_union
)
725 size
= current_stag
->size
;
727 size
= abs_section_offset
- S_GET_VALUE (current_stag
->sym
);
728 if (line_label
!= NULL
)
730 S_SET_VALUE (line_label
, size
);
731 symbol_table_insert (line_label
);
735 /* Union size has already been calculated. */
736 if (!current_stag
->is_union
)
737 current_stag
->size
= size
;
738 /* Nested .structs don't get put in the stag table. */
739 if (current_stag
->outer
== NULL
)
741 str_hash_insert (stag_hash
, current_stag
->name
, current_stag
, 0);
742 stag_add_field_symbols (current_stag
, path
,
743 S_GET_VALUE (current_stag
->sym
),
746 current_stag
= current_stag
->outer
;
748 /* If this is a nested .struct/.union, add it as a field to the enclosing
749 one. otherwise, restore the section we were in. */
750 if (current_stag
!= NULL
)
752 stag_add_field (current_stag
, current_stag
->inner
->name
,
753 S_GET_VALUE (current_stag
->inner
->sym
),
754 current_stag
->inner
);
757 subseg_set (stag_saved_seg
, stag_saved_subseg
);
761 Reference a structure within a structure, as a sized field with an optional
763 If used outside of a .struct/.endstruct, overlays the given structure
764 format on the existing allocated space. */
767 tic54x_tag (int ignore ATTRIBUTE_UNUSED
)
770 int c
= get_symbol_name (&name
);
771 struct stag
*stag
= (struct stag
*) str_hash_find (stag_hash
, name
);
776 as_bad (_("Unrecognized struct/union tag '%s'"), name
);
778 as_bad (_(".tag requires a structure tag"));
779 ignore_rest_of_line ();
782 if (line_label
== NULL
)
784 as_bad (_("Label required for .tag"));
785 ignore_rest_of_line ();
792 label
= xstrdup (S_GET_NAME (line_label
));
793 if (current_stag
!= NULL
)
794 stag_add_field (current_stag
, label
,
795 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
799 symbolS
*sym
= symbol_find (label
);
803 as_bad (_(".tag target '%s' undefined"), label
);
804 ignore_rest_of_line ();
808 stag_add_field_symbols (stag
, S_GET_NAME (sym
),
809 S_GET_VALUE (stag
->sym
), sym
, stag
->name
);
814 /* Bump by the struct size, but only if we're within a .struct section. */
815 if (current_stag
!= NULL
&& !current_stag
->is_union
)
816 abs_section_offset
+= stag
->size
;
818 (void) restore_line_pointer (c
);
819 demand_empty_rest_of_line ();
823 /* Handle all .byte, .char, .double, .field, .float, .half, .int, .long,
824 .short, .string, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword,
828 tic54x_struct_field (int type
)
832 int new_bitfield_offset
= 0;
833 int field_align
= current_stag
->current_bitfield_offset
!= 0;
834 int longword_align
= 0;
837 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
838 count
= get_absolute_expression ();
854 case '*': /* String. */
863 case '.': /* Bitfield. */
865 if (count
< 1 || count
> 32)
867 as_bad (_(".field count '%d' out of range (1 <= X <= 32)"), count
);
868 ignore_rest_of_line ();
871 if (current_stag
->current_bitfield_offset
+ count
> 16)
873 /* Set the appropriate size and new field offset. */
883 new_bitfield_offset
= count
- 16;
886 new_bitfield_offset
= count
;
891 new_bitfield_offset
= current_stag
->current_bitfield_offset
+ count
;
895 as_bad (_("Unrecognized field type '%c'"), type
);
896 ignore_rest_of_line ();
902 /* Align to the actual starting position of the field. */
903 current_stag
->current_bitfield_offset
= 0;
904 ++abs_section_offset
;
906 /* Align to longword boundary. */
907 if (longword_align
&& (abs_section_offset
& 0x1))
908 ++abs_section_offset
;
910 if (line_label
== NULL
)
912 static int fieldno
= 0;
913 char fake
[] = ".fake_fieldNNNNN";
915 sprintf (fake
, ".fake_field%d", fieldno
++);
916 stag_add_field (current_stag
, fake
,
917 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
924 label
= xstrdup (S_GET_NAME (line_label
));
925 stag_add_field (current_stag
, label
,
926 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
931 if (current_stag
->is_union
)
933 /* Note we treat the element as if it were an array of COUNT. */
934 if (current_stag
->size
< (unsigned) size
* count
)
935 current_stag
->size
= size
* count
;
939 abs_section_offset
+= (unsigned) size
* count
;
940 current_stag
->current_bitfield_offset
= new_bitfield_offset
;
945 /* Handle .byte, .word. .int, .long and all variants. */
948 tic54x_cons (int type
)
953 /* If we're within a .struct construct, don't actually allocate space. */
954 if (current_stag
!= NULL
)
956 tic54x_struct_field (type
);
960 #ifdef md_flush_pending_output
961 md_flush_pending_output ();
964 generate_lineno_debug ();
966 /* Align long words to long word boundaries (4 octets). */
967 if (type
== 'l' || type
== 'L')
969 frag_align (2, 0, 2);
970 /* If there's a label, assign it to the first allocated word. */
971 if (line_label
!= NULL
)
973 symbol_set_frag (line_label
, frag_now
);
974 S_SET_VALUE (line_label
, frag_now_fix ());
998 if (*input_line_pointer
== '"')
1000 input_line_pointer
++;
1001 while (is_a_char (c
= next_char_of_string ()))
1002 tic54x_emit_char (c
);
1003 know (input_line_pointer
[-1] == '\"');
1009 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1010 if (expn
.X_op
== O_constant
)
1012 offsetT value
= expn
.X_add_number
;
1013 /* Truncate overflows. */
1017 if ((value
> 0 && value
> 0xFF)
1018 || (value
< 0 && value
< - 0x100))
1019 as_warn (_("Overflow in expression, truncated to 8 bits"));
1022 if ((value
> 0 && value
> 0xFFFF)
1023 || (value
< 0 && value
< - 0x10000))
1024 as_warn (_("Overflow in expression, truncated to 16 bits"));
1028 if (expn
.X_op
!= O_constant
&& octets
< 2)
1030 /* Disallow .byte with a non constant expression that will
1031 require relocation. */
1032 as_bad (_("Relocatable values require at least WORD storage"));
1033 ignore_rest_of_line ();
1037 if (expn
.X_op
!= O_constant
1041 /* FIXME -- at one point TI tools used to output REL16
1042 relocations, but I don't think the latest tools do at all
1043 The current tools output extended relocations regardless of
1044 the addressing mode (I actually think that ".c_mode" is
1045 totally ignored in the latest tools). */
1048 emit_expr (&expn
, 4);
1054 emitting_long
= octets
== 4;
1055 emit_expr (&expn
, (octets
== 1) ? 2 : octets
);
1060 while (*input_line_pointer
++ == ',');
1062 input_line_pointer
--; /* Put terminator back into stream. */
1063 demand_empty_rest_of_line ();
1066 /* .global <symbol>[,...,<symbolN>]
1067 .def <symbol>[,...,<symbolN>]
1068 .ref <symbol>[,...,<symbolN>]
1070 These all identify global symbols.
1072 .def means the symbol is defined in the current module and can be accessed
1073 by other files. The symbol should be placed in the symbol table.
1075 .ref means the symbol is used in the current module but defined in another
1076 module. The linker is to resolve this symbol's definition at link time.
1078 .global should act as a .ref or .def, as needed.
1080 global, def and ref all have symbol storage classes of C_EXT.
1082 I can't identify any difference in how the "other" c54x assembler treats
1083 these, so we ignore the type here. */
1086 tic54x_global (int type
)
1093 as_warn (_("Use of .def/.ref is deprecated. Use .global instead"));
1095 ILLEGAL_WITHIN_STRUCT ();
1099 c
= get_symbol_name (&name
);
1100 symbolP
= symbol_find_or_make (name
);
1101 c
= restore_line_pointer (c
);
1103 S_SET_STORAGE_CLASS (symbolP
, C_EXT
);
1106 input_line_pointer
++;
1107 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1108 c
= *input_line_pointer
;
1113 demand_empty_rest_of_line ();
1116 /* Remove the symbol from the local label hash lookup. */
1119 tic54x_remove_local_label (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1121 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
1122 void *elem
= str_hash_find (local_label_hash
[macro_level
], tuple
->key
);
1123 str_hash_delete (local_label_hash
[macro_level
], tuple
->key
);
1128 /* Reset all local labels. */
1131 tic54x_clear_local_labels (int ignored ATTRIBUTE_UNUSED
)
1133 htab_traverse (local_label_hash
[macro_level
], tic54x_remove_local_label
, NULL
);
1138 .sect "section name"
1141 make sure local labels get cleared when changing sections
1143 ARG is 't' for text, 'd' for data, or '*' for a named section
1145 For compatibility, '*' sections are SEC_CODE if instructions are
1146 encountered, or SEC_DATA if not.
1150 tic54x_sect (int arg
)
1152 ILLEGAL_WITHIN_STRUCT ();
1154 /* Local labels are cleared when changing sections. */
1155 tic54x_clear_local_labels (0);
1159 else if (arg
== 'd')
1165 /* Make sure all named initialized sections flagged properly. If we
1166 encounter instructions, we'll flag it with SEC_CODE as well. */
1167 const char *flags
= ",\"w\"\n";
1169 /* If there are quotes, remove them. */
1170 if (*input_line_pointer
== '"')
1172 name
= demand_copy_C_string (&len
);
1173 demand_empty_rest_of_line ();
1174 name
= concat (name
, flags
, (char *) NULL
);
1180 c
= get_symbol_name (&name
);
1181 name
= concat (name
, flags
, (char *) NULL
);
1182 (void) restore_line_pointer (c
);
1183 demand_empty_rest_of_line ();
1186 input_scrub_insert_line (name
);
1187 obj_coff_section (0);
1189 /* If there was a line label, make sure that it gets assigned the proper
1190 section. This is for compatibility, even though the actual behavior
1191 is not explicitly defined. For consistency, we make .sect behave
1192 like .usect, since that is probably what people expect. */
1193 if (line_label
!= NULL
)
1195 S_SET_SEGMENT (line_label
, now_seg
);
1196 symbol_set_frag (line_label
, frag_now
);
1197 S_SET_VALUE (line_label
, frag_now_fix ());
1198 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1199 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1204 /* [symbol] .space space_in_bits
1205 [symbol] .bes space_in_bits
1206 BES puts the symbol at the *last* word allocated
1208 cribbed from s_space. */
1211 tic54x_space (int arg
)
1217 int bits_per_byte
= (OCTETS_PER_BYTE
* 8);
1219 symbolS
*label
= line_label
;
1222 ILLEGAL_WITHIN_STRUCT ();
1224 #ifdef md_flush_pending_output
1225 md_flush_pending_output ();
1228 /* Read the bit count. */
1231 /* Some expressions are unresolvable until later in the assembly pass;
1232 postpone until relaxation/fixup. we also have to postpone if a previous
1233 partial allocation has not been completed yet. */
1234 if (expn
.X_op
!= O_constant
|| frag_bit_offset (frag_now
, now_seg
) == -1)
1236 struct bit_info
*bi
= XNEW (struct bit_info
);
1241 p
= frag_var (rs_machine_dependent
,
1242 65536 * 2, 1, (relax_substateT
) 0,
1243 make_expr_symbol (&expn
), (offsetT
) 0,
1251 /* Reduce the required size by any bit offsets currently left over
1252 from a previous .space/.bes/.field directive. */
1253 bit_offset
= frag_now
->tc_frag_data
;
1254 if (bit_offset
!= 0 && bit_offset
< 16)
1256 int spare_bits
= bits_per_byte
- bit_offset
;
1258 if (spare_bits
>= expn
.X_add_number
)
1260 /* Don't have to do anything; sufficient bits have already been
1261 allocated; just point the label to the right place. */
1264 symbol_set_frag (label
, frag_now
);
1265 S_SET_VALUE (label
, frag_now_fix () - 1);
1268 frag_now
->tc_frag_data
+= expn
.X_add_number
;
1271 expn
.X_add_number
-= spare_bits
;
1272 /* Set the label to point to the first word allocated, which in this
1273 case is the previous word, which was only partially filled. */
1274 if (!bes
&& label
!= NULL
)
1276 symbol_set_frag (label
, frag_now
);
1277 S_SET_VALUE (label
, frag_now_fix () - 1);
1281 /* Convert bits to bytes/words and octets, rounding up. */
1282 words
= ((expn
.X_add_number
+ bits_per_byte
- 1) / bits_per_byte
);
1283 /* How many do we have left over? */
1284 bit_offset
= expn
.X_add_number
% bits_per_byte
;
1285 octets
= words
* OCTETS_PER_BYTE
;
1288 as_warn (_(".space/.bes repeat count is negative, ignored"));
1291 else if (octets
== 0)
1293 as_warn (_(".space/.bes repeat count is zero, ignored"));
1297 /* If we are in the absolute section, just bump the offset. */
1298 if (now_seg
== absolute_section
)
1300 abs_section_offset
+= words
;
1301 if (bes
&& label
!= NULL
)
1302 S_SET_VALUE (label
, abs_section_offset
- 1);
1303 frag_now
->tc_frag_data
= bit_offset
;
1308 p
= frag_var (rs_fill
, 1, 1,
1309 (relax_substateT
) 0, (symbolS
*) 0,
1310 (offsetT
) octets
, (char *) 0);
1312 /* Make note of how many bits of this word we've allocated so far. */
1313 frag_now
->tc_frag_data
= bit_offset
;
1315 /* .bes puts label at *last* word allocated. */
1316 if (bes
&& label
!= NULL
)
1318 symbol_set_frag (label
, frag_now
);
1319 S_SET_VALUE (label
, frag_now_fix () - 1);
1327 demand_empty_rest_of_line ();
1330 /* [symbol] .usect "section-name", size-in-words
1331 [, [blocking-flag] [, alignment-flag]]
1333 Uninitialized section.
1334 Non-zero blocking means that if the section would cross a page (128-word)
1335 boundary, it will be page-aligned.
1336 Non-zero alignment aligns on a longword boundary.
1338 Has no effect on the current section. */
1341 tic54x_usect (int x ATTRIBUTE_UNUSED
)
1348 int size
, blocking_flag
, alignment_flag
;
1350 subsegT current_subseg
;
1353 ILLEGAL_WITHIN_STRUCT ();
1355 current_seg
= now_seg
; /* Save current seg. */
1356 current_subseg
= now_subseg
; /* Save current subseg. */
1358 c
= get_symbol_name (§ion_name
); /* Get terminator. */
1359 name
= xstrdup (section_name
);
1360 c
= restore_line_pointer (c
);
1363 ++input_line_pointer
;
1366 as_bad (_("Missing size argument"));
1367 ignore_rest_of_line ();
1371 size
= get_absolute_expression ();
1373 /* Read a possibly present third argument (blocking flag). */
1374 if (*input_line_pointer
== ',')
1376 ++input_line_pointer
;
1377 if (*input_line_pointer
!= ',')
1378 blocking_flag
= get_absolute_expression ();
1382 /* Read a possibly present fourth argument (alignment flag). */
1383 if (*input_line_pointer
== ',')
1385 ++input_line_pointer
;
1386 alignment_flag
= get_absolute_expression ();
1392 blocking_flag
= alignment_flag
= 0;
1394 seg
= subseg_new (name
, 0);
1395 flags
= bfd_section_flags (seg
) | SEC_ALLOC
;
1399 /* s_align eats end of line; restore it. */
1401 --input_line_pointer
;
1404 if (line_label
!= NULL
)
1406 S_SET_SEGMENT (line_label
, seg
);
1407 symbol_set_frag (line_label
, frag_now
);
1408 S_SET_VALUE (line_label
, frag_now_fix ());
1409 /* Set scl to label, since that's what TI does. */
1410 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1411 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1414 seg_info (seg
)->bss
= 1; /* Uninitialized data. */
1416 p
= frag_var (rs_fill
, 1, 1,
1417 (relax_substateT
) 0, (symbolS
*) line_label
,
1418 size
* OCTETS_PER_BYTE
, (char *) 0);
1422 flags
|= SEC_TIC54X_BLOCK
;
1424 if (!bfd_set_section_flags (seg
, flags
))
1425 as_warn (_("Error setting flags for \"%s\": %s"), name
,
1426 bfd_errmsg (bfd_get_error ()));
1428 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
1429 demand_empty_rest_of_line ();
1432 static enum cpu_version
1433 lookup_version (const char *ver
)
1435 enum cpu_version version
= VNONE
;
1437 if (ver
[0] == '5' && ver
[1] == '4')
1439 if (strlen (ver
) == 3
1440 && (ver
[2] == '1' || ver
[2] == '2' || ver
[2] == '3'
1441 || ver
[2] == '5' || ver
[2] == '8' || ver
[2] == '9'))
1442 version
= ver
[2] - '0';
1443 else if (strlen (ver
) == 5
1444 && TOUPPER (ver
[3]) == 'L'
1445 && TOUPPER (ver
[4]) == 'P'
1446 && (ver
[2] == '5' || ver
[2] == '6'))
1447 version
= ver
[2] - '0' + 10;
1454 set_cpu (enum cpu_version version
)
1457 if (version
== V545LP
|| version
== V546LP
)
1459 symbolS
*symbolP
= symbol_new ("__allow_lp", absolute_section
,
1460 &zero_address_frag
, 1);
1461 SF_SET_LOCAL (symbolP
);
1462 symbol_table_insert (symbolP
);
1466 /* .version cpu-version
1467 cpu-version may be one of the following:
1477 This is for compatibility only. It currently has no affect on assembly. */
1478 static int cpu_needs_set
= 1;
1481 tic54x_version (int x ATTRIBUTE_UNUSED
)
1483 enum cpu_version version
= VNONE
;
1484 enum cpu_version old_version
= cpu
;
1488 ILLEGAL_WITHIN_STRUCT ();
1491 ver
= input_line_pointer
;
1492 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1493 ++input_line_pointer
;
1494 c
= *input_line_pointer
;
1495 *input_line_pointer
= 0;
1497 version
= lookup_version (ver
);
1499 if (cpu
!= VNONE
&& cpu
!= version
)
1500 as_warn (_("CPU version has already been set"));
1502 if (version
== VNONE
)
1504 as_bad (_("Unrecognized version '%s'"), ver
);
1505 ignore_rest_of_line ();
1508 else if (assembly_begun
&& version
!= old_version
)
1510 as_bad (_("Changing of CPU version on the fly not supported"));
1511 ignore_rest_of_line ();
1517 *input_line_pointer
= c
;
1518 demand_empty_rest_of_line ();
1521 /* 'f' = float, 'x' = xfloat, 'd' = double, 'l' = ldouble. */
1524 tic54x_float_cons (int type
)
1526 if (current_stag
!= 0)
1527 tic54x_struct_field ('f');
1529 #ifdef md_flush_pending_output
1530 md_flush_pending_output ();
1533 /* Align to long word boundary (4 octets) unless it's ".xfloat". */
1536 frag_align (2, 0, 2);
1537 /* If there's a label, assign it to the first allocated word. */
1538 if (line_label
!= NULL
)
1540 symbol_set_frag (line_label
, frag_now
);
1541 S_SET_VALUE (line_label
, frag_now_fix ());
1548 /* The argument is capitalized if it should be zero-terminated
1549 's' is normal string with upper 8-bits zero-filled, 'p' is packed.
1550 Code copied from stringer, and slightly modified so that strings are packed
1551 and encoded into the correct octets. */
1554 tic54x_stringer (int type
)
1557 int append_zero
= type
== 'S' || type
== 'P';
1558 int packed
= type
== 'p' || type
== 'P';
1559 int last_char
= -1; /* Packed strings need two bytes at a time to encode. */
1561 if (current_stag
!= NULL
)
1563 tic54x_struct_field ('*');
1567 #ifdef md_flush_pending_output
1568 md_flush_pending_output ();
1571 c
= ','; /* Do loop. */
1575 switch (*input_line_pointer
)
1579 unsigned short value
= get_absolute_expression ();
1580 FRAG_APPEND_1_CHAR ( value
& 0xFF);
1581 FRAG_APPEND_1_CHAR ((value
>> 8) & 0xFF);
1585 ++input_line_pointer
; /* -> 1st char of string. */
1586 while (is_a_char (c
= next_char_of_string ()))
1590 FRAG_APPEND_1_CHAR (c
);
1591 FRAG_APPEND_1_CHAR (0);
1595 /* Packed strings are filled MS octet first. */
1596 if (last_char
== -1)
1600 FRAG_APPEND_1_CHAR (c
);
1601 FRAG_APPEND_1_CHAR (last_char
);
1608 if (packed
&& last_char
!= -1)
1610 FRAG_APPEND_1_CHAR (0);
1611 FRAG_APPEND_1_CHAR (last_char
);
1616 FRAG_APPEND_1_CHAR (0);
1617 FRAG_APPEND_1_CHAR (0);
1620 know (input_line_pointer
[-1] == '\"');
1624 c
= *input_line_pointer
;
1625 if (!is_end_of_line
[c
])
1626 ++input_line_pointer
;
1629 /* Finish up any leftover packed string. */
1630 if (packed
&& last_char
!= -1)
1632 FRAG_APPEND_1_CHAR (0);
1633 FRAG_APPEND_1_CHAR (last_char
);
1635 demand_empty_rest_of_line ();
1639 tic54x_p2align (int arg ATTRIBUTE_UNUSED
)
1641 as_bad (_("p2align not supported on this target"));
1645 tic54x_align_words (int arg
)
1647 /* Only ".align" with no argument is allowed within .struct/.union. */
1650 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1653 as_warn (_("Argument to .even ignored"));
1655 count
= get_absolute_expression ();
1658 if (current_stag
!= NULL
&& arg
== 128)
1660 if (current_stag
->current_bitfield_offset
!= 0)
1662 current_stag
->current_bitfield_offset
= 0;
1663 ++abs_section_offset
;
1665 demand_empty_rest_of_line ();
1669 ILLEGAL_WITHIN_STRUCT ();
1671 s_align_bytes (count
<< 1);
1674 /* Initialize multiple-bit fields within a single word of memory. */
1677 tic54x_field (int ignore ATTRIBUTE_UNUSED
)
1683 symbolS
*label
= line_label
;
1685 if (current_stag
!= NULL
)
1687 tic54x_struct_field ('.');
1691 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1693 if (*input_line_pointer
== ',')
1695 ++input_line_pointer
;
1696 size
= get_absolute_expression ();
1697 if (size
< 1 || size
> 32)
1699 as_bad (_("Invalid field size, must be from 1 to 32"));
1700 ignore_rest_of_line ();
1705 /* Truncate values to the field width. */
1706 if (expn
.X_op
!= O_constant
)
1708 /* If the expression value is relocatable, the field size *must*
1712 as_bad (_("field size must be 16 when value is relocatable"));
1713 ignore_rest_of_line ();
1717 frag_now
->tc_frag_data
= 0;
1718 emit_expr (&expn
, 2);
1722 unsigned long fmask
= (size
== 32) ? 0xFFFFFFFF : (1ul << size
) - 1;
1724 value
= expn
.X_add_number
;
1725 expn
.X_add_number
&= fmask
;
1726 if (value
!= (valueT
) expn
.X_add_number
)
1727 as_warn (_("field value truncated"));
1728 value
= expn
.X_add_number
;
1729 /* Bits are stored MS first. */
1732 frag_now
->tc_frag_data
= 0;
1734 md_number_to_chars (p
, (value
>> (size
- 16)) & 0xFFFF, 2);
1739 int bit_offset
= frag_bit_offset (frag_now
, now_seg
);
1741 fragS
*alloc_frag
= bit_offset_frag (frag_now
, now_seg
);
1742 if (bit_offset
== -1)
1744 struct bit_info
*bi
= XNEW (struct bit_info
);
1745 /* We don't know the previous offset at this time, so store the
1746 info we need and figure it out later. */
1747 expressionS size_exp
;
1749 size_exp
.X_op
= O_constant
;
1750 size_exp
.X_add_number
= size
;
1752 bi
->type
= TYPE_FIELD
;
1754 p
= frag_var (rs_machine_dependent
,
1755 4, 1, (relax_substateT
) 0,
1756 make_expr_symbol (&size_exp
), (offsetT
) 0,
1760 else if (bit_offset
== 0 || bit_offset
+ size
> 16)
1762 /* Align a new field. */
1764 frag_now
->tc_frag_data
= 0;
1765 alloc_frag
= frag_now
;
1769 /* Put the new value entirely within the existing one. */
1770 p
= alloc_frag
== frag_now
?
1771 frag_now
->fr_literal
+ frag_now_fix_octets () - 2 :
1772 alloc_frag
->fr_literal
;
1775 symbol_set_frag (label
, alloc_frag
);
1776 if (alloc_frag
== frag_now
)
1777 S_SET_VALUE (label
, frag_now_fix () - 1);
1781 value
<<= 16 - alloc_frag
->tc_frag_data
- size
;
1783 /* OR in existing value. */
1784 if (alloc_frag
->tc_frag_data
)
1785 value
|= ((unsigned short) p
[1] << 8) | p
[0];
1786 md_number_to_chars (p
, value
, 2);
1787 alloc_frag
->tc_frag_data
+= size
;
1788 if (alloc_frag
->tc_frag_data
== 16)
1789 alloc_frag
->tc_frag_data
= 0;
1793 demand_empty_rest_of_line ();
1796 /* Ideally, we want to check SEC_LOAD and SEC_HAS_CONTENTS, but those aren't
1797 available yet. seg_info ()->bss is the next best thing. */
1800 tic54x_initialized_section (segT seg
)
1802 return !seg_info (seg
)->bss
;
1805 /* .clink ["section name"]
1807 Marks the section as conditionally linked (link only if contents are
1808 referenced elsewhere.
1809 Without a name, refers to the current initialized section.
1810 Name is required for uninitialized sections. */
1813 tic54x_clink (int ignored ATTRIBUTE_UNUSED
)
1817 ILLEGAL_WITHIN_STRUCT ();
1819 if (*input_line_pointer
== '\"')
1821 char *section_name
= ++input_line_pointer
;
1824 while (is_a_char (next_char_of_string ()))
1826 know (input_line_pointer
[-1] == '\"');
1827 input_line_pointer
[-1] = 0;
1828 name
= xstrdup (section_name
);
1830 seg
= bfd_get_section_by_name (stdoutput
, name
);
1833 as_bad (_("Unrecognized section '%s'"), section_name
);
1834 ignore_rest_of_line ();
1840 if (!tic54x_initialized_section (seg
))
1842 as_bad (_("Current section is uninitialized, "
1843 "section name required for .clink"));
1844 ignore_rest_of_line ();
1849 seg
->flags
|= SEC_TIC54X_CLINK
;
1851 demand_empty_rest_of_line ();
1854 /* Change the default include directory to be the current source file's
1855 directory, instead of the current working directory. If DOT is non-zero,
1856 set to "." instead. */
1859 tic54x_set_default_include (void)
1861 char *dir
, *tmp
= NULL
;
1862 const char *curfile
;
1865 curfile
= as_where (&lineno
);
1866 dir
= xstrdup (curfile
);
1867 tmp
= strrchr (dir
, '/');
1874 if (include_dir_count
== 0)
1876 include_dirs
= XNEWVEC (const char *, 1);
1877 include_dir_count
= 1;
1879 include_dirs
[0] = dir
;
1880 if (len
> include_dir_maxlen
)
1881 include_dir_maxlen
= len
;
1883 else if (include_dirs
!= NULL
)
1884 include_dirs
[0] = ".";
1887 /* .include "filename" | filename
1888 .copy "filename" | filename
1890 FIXME 'include' file should be omitted from any output listing,
1891 'copy' should be included in any output listing
1892 FIXME -- prevent any included files from changing listing (compat only)
1893 FIXME -- need to include source file directory in search path; what's a
1894 good way to do this?
1896 Entering/exiting included/copied file clears all local labels. */
1899 tic54x_include (int ignored ATTRIBUTE_UNUSED
)
1901 char newblock
[] = " .newblock\n";
1906 ILLEGAL_WITHIN_STRUCT ();
1910 if (*input_line_pointer
== '"')
1912 filename
= demand_copy_C_string (&len
);
1913 demand_empty_rest_of_line ();
1917 filename
= input_line_pointer
;
1918 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1919 ++input_line_pointer
;
1920 c
= *input_line_pointer
;
1921 *input_line_pointer
= '\0';
1922 filename
= xstrdup (filename
);
1923 *input_line_pointer
= c
;
1924 demand_empty_rest_of_line ();
1926 /* Insert a partial line with the filename (for the sake of s_include)
1928 The included file will be inserted before the newblock, so that the
1929 newblock is executed after the included file is processed. */
1930 input
= concat ("\"", filename
, "\"\n", newblock
, (char *) NULL
);
1931 input_scrub_insert_line (input
);
1933 tic54x_clear_local_labels (0);
1935 tic54x_set_default_include ();
1941 tic54x_message (int type
)
1947 ILLEGAL_WITHIN_STRUCT ();
1949 if (*input_line_pointer
== '"')
1950 msg
= demand_copy_C_string (&len
);
1953 msg
= input_line_pointer
;
1954 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1955 ++input_line_pointer
;
1956 c
= *input_line_pointer
;
1957 *input_line_pointer
= 0;
1958 msg
= xstrdup (msg
);
1959 *input_line_pointer
= c
;
1965 as_tsktsk ("%s", msg
);
1968 as_warn ("%s", msg
);
1975 demand_empty_rest_of_line ();
1979 Define a special symbol that refers to the loadtime address rather than the
1980 runtime address within the current section.
1982 This symbol gets a special storage class so that when it is resolved, it is
1983 resolved relative to the load address (lma) of the section rather than the
1984 run address (vma). */
1987 tic54x_label (int ignored ATTRIBUTE_UNUSED
)
1993 ILLEGAL_WITHIN_STRUCT ();
1995 c
= get_symbol_name (&name
);
1996 symbolP
= colon (name
);
1997 S_SET_STORAGE_CLASS (symbolP
, C_STATLAB
);
1999 (void) restore_line_pointer (c
);
2000 demand_empty_rest_of_line ();
2004 Install all memory-mapped register names into the symbol table as
2005 absolute local symbols. */
2008 tic54x_mmregs (int ignored ATTRIBUTE_UNUSED
)
2012 ILLEGAL_WITHIN_STRUCT ();
2014 for (sym
= (tic54x_symbol
*) mmregs
; sym
->name
; sym
++)
2016 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
2017 &zero_address_frag
, sym
->value
);
2018 SF_SET_LOCAL (symbolP
);
2019 symbol_table_insert (symbolP
);
2024 Count defaults to 1024. */
2027 tic54x_loop (int count
)
2029 ILLEGAL_WITHIN_STRUCT ();
2032 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2033 count
= get_absolute_expression ();
2035 do_repeat ((size_t) count
, "LOOP", "ENDLOOP");
2038 /* Normally, endloop gets eaten by the preceding loop. */
2041 tic54x_endloop (int ignore ATTRIBUTE_UNUSED
)
2043 as_bad (_("ENDLOOP without corresponding LOOP"));
2044 ignore_rest_of_line ();
2047 /* .break [condition]. */
2050 tic54x_break (int ignore ATTRIBUTE_UNUSED
)
2054 ILLEGAL_WITHIN_STRUCT ();
2057 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2058 cond
= get_absolute_expression ();
2061 end_repeat (substitution_line
? 1 : 0);
2065 set_address_mode (int mode
)
2068 if (mode
== far_mode
)
2070 symbolS
*symbolP
= symbol_new ("__allow_far", absolute_section
,
2071 &zero_address_frag
, 1);
2072 SF_SET_LOCAL (symbolP
);
2073 symbol_table_insert (symbolP
);
2077 static int address_mode_needs_set
= 1;
2080 tic54x_address_mode (int mode
)
2082 if (assembly_begun
&& amode
!= (unsigned) mode
)
2084 as_bad (_("Mixing of normal and extended addressing not supported"));
2085 ignore_rest_of_line ();
2088 if (mode
== far_mode
&& cpu
!= VNONE
&& cpu
!= V548
&& cpu
!= V549
)
2090 as_bad (_("Extended addressing not supported on the specified CPU"));
2091 ignore_rest_of_line ();
2095 set_address_mode (mode
);
2096 demand_empty_rest_of_line ();
2099 /* .sblock "section"|section [,...,"section"|section]
2100 Designate initialized sections for blocking. */
2103 tic54x_sblock (int ignore ATTRIBUTE_UNUSED
)
2107 ILLEGAL_WITHIN_STRUCT ();
2114 if (*input_line_pointer
== '"')
2118 name
= demand_copy_C_string (&len
);
2124 c
= get_symbol_name (§ion_name
);
2125 name
= xstrdup (section_name
);
2126 (void) restore_line_pointer (c
);
2129 seg
= bfd_get_section_by_name (stdoutput
, name
);
2132 as_bad (_("Unrecognized section '%s'"), name
);
2133 ignore_rest_of_line ();
2136 else if (!tic54x_initialized_section (seg
))
2138 as_bad (_(".sblock may be used for initialized sections only"));
2139 ignore_rest_of_line ();
2142 seg
->flags
|= SEC_TIC54X_BLOCK
;
2144 c
= *input_line_pointer
;
2145 if (!is_end_of_line
[(unsigned char) c
])
2146 ++input_line_pointer
;
2149 demand_empty_rest_of_line ();
2152 /* symbol .set value
2155 value must be defined externals; no forward-referencing allowed
2156 symbols assigned with .set/.equ may not be redefined. */
2159 tic54x_set (int ignore ATTRIBUTE_UNUSED
)
2164 ILLEGAL_WITHIN_STRUCT ();
2168 as_bad (_("Symbol missing for .set/.equ"));
2169 ignore_rest_of_line ();
2172 name
= xstrdup (S_GET_NAME (line_label
));
2174 if ((symbolP
= symbol_find (name
)) == NULL
2175 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2177 symbolP
= symbol_new (name
, absolute_section
, &zero_address_frag
, 0);
2178 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2181 S_SET_DATA_TYPE (symbolP
, T_INT
);
2182 S_SET_SEGMENT (symbolP
, absolute_section
);
2183 symbol_table_insert (symbolP
);
2184 pseudo_set (symbolP
);
2185 demand_empty_rest_of_line ();
2190 List false conditional blocks. */
2193 tic54x_fclist (int show
)
2196 listing
&= ~LISTING_NOCOND
;
2198 listing
|= LISTING_NOCOND
;
2199 demand_empty_rest_of_line ();
2203 tic54x_sslist (int show
)
2205 ILLEGAL_WITHIN_STRUCT ();
2207 listing_sslist
= show
;
2210 /* .var SYM[,...,SYMN]
2211 Define a substitution string to be local to a macro. */
2214 tic54x_var (int ignore ATTRIBUTE_UNUSED
)
2216 static char empty
[] = "";
2220 ILLEGAL_WITHIN_STRUCT ();
2222 if (macro_level
== 0)
2224 as_bad (_(".var may only be used within a macro definition"));
2225 ignore_rest_of_line ();
2230 if (!ISALPHA (*input_line_pointer
))
2232 as_bad (_("Substitution symbols must begin with a letter"));
2233 ignore_rest_of_line ();
2236 c
= get_symbol_name (&name
);
2237 /* .var symbols start out with a null string. */
2238 name
= xstrdup (name
);
2239 str_hash_insert (subsym_hash
[macro_level
], name
, empty
, 0);
2240 c
= restore_line_pointer (c
);
2243 ++input_line_pointer
;
2244 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2245 c
= *input_line_pointer
;
2250 demand_empty_rest_of_line ();
2253 /* .mlib <macro library filename>
2255 Macro libraries are archived (standard AR-format) text macro definitions
2256 Expand the file and include it.
2258 FIXME need to try the source file directory as well. */
2261 tic54x_mlib (int ignore ATTRIBUTE_UNUSED
)
2268 ILLEGAL_WITHIN_STRUCT ();
2270 /* Parse the filename. */
2271 if (*input_line_pointer
== '"')
2273 if ((filename
= demand_copy_C_string (&len
)) == NULL
)
2280 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
2281 && !ISSPACE (*input_line_pointer
))
2283 obstack_1grow (¬es
, *input_line_pointer
);
2284 ++input_line_pointer
;
2287 obstack_1grow (¬es
, '\0');
2288 filename
= obstack_finish (¬es
);
2290 demand_empty_rest_of_line ();
2292 tic54x_set_default_include ();
2293 path
= XNEWVEC (char, (unsigned long) len
+ include_dir_maxlen
+ 5);
2295 for (i
= 0; i
< include_dir_count
; i
++)
2299 strcpy (path
, include_dirs
[i
]);
2301 strcat (path
, filename
);
2302 if ((try = fopen (path
, "r")) != NULL
)
2309 if (i
>= include_dir_count
)
2315 /* FIXME: if path is found, malloc'd storage is not freed. Of course, this
2316 happens all over the place, and since the assembler doesn't usually keep
2317 running for a very long time, it really doesn't matter. */
2318 register_dependency (path
);
2320 /* Expand all archive entries to temporary files and include them. */
2321 abfd
= bfd_openr (path
, NULL
);
2324 as_bad (_("can't open macro library file '%s' for reading: %s"),
2325 path
, bfd_errmsg (bfd_get_error ()));
2326 ignore_rest_of_line ();
2329 if (!bfd_check_format (abfd
, bfd_archive
))
2331 as_bad (_("File '%s' not in macro archive format"), path
);
2332 ignore_rest_of_line ();
2336 /* Open each BFD as binary (it should be straight ASCII text). */
2337 for (mbfd
= bfd_openr_next_archived_file (abfd
, NULL
);
2338 mbfd
!= NULL
; mbfd
= bfd_openr_next_archived_file (abfd
, mbfd
))
2340 /* Get a size at least as big as the archive member. */
2341 bfd_size_type size
= bfd_get_size (mbfd
);
2342 char *buf
= XNEWVEC (char, size
);
2343 char *fname
= tmpnam (NULL
);
2346 /* We're not sure how big it is, but it will be smaller than "size". */
2347 size
= bfd_bread (buf
, size
, mbfd
);
2349 /* Write to a temporary file, then use s_include to include it
2351 ftmp
= fopen (fname
, "w+b");
2352 fwrite ((void *) buf
, size
, 1, ftmp
);
2353 if (size
== 0 || buf
[size
- 1] != '\n')
2354 fwrite ("\n", 1, 1, ftmp
);
2357 input_scrub_insert_file (fname
);
2362 const pseudo_typeS md_pseudo_table
[] =
2364 { "algebraic", s_ignore
, 0 },
2365 { "align" , tic54x_align_words
, 128 },
2366 { "ascii" , tic54x_stringer
, 'p' },
2367 { "asciz" , tic54x_stringer
, 'P' },
2368 { "even" , tic54x_align_words
, 2 },
2369 { "asg" , tic54x_asg
, 0 },
2370 { "eval" , tic54x_eval
, 0 },
2371 { "bss" , tic54x_bss
, 0 },
2372 { "byte" , tic54x_cons
, 'b' },
2373 { "ubyte" , tic54x_cons
, 'B' },
2374 { "char" , tic54x_cons
, 'c' },
2375 { "uchar" , tic54x_cons
, 'C' },
2376 { "clink" , tic54x_clink
, 0 },
2377 { "c_mode" , tic54x_address_mode
, c_mode
},
2378 { "copy" , tic54x_include
, 'c' },
2379 { "include" , tic54x_include
, 'i' },
2380 { "data" , tic54x_sect
, 'd' },
2381 { "double" , tic54x_float_cons
, 'd' },
2382 { "ldouble" , tic54x_float_cons
, 'l' },
2383 { "drlist" , s_ignore
, 0 },
2384 { "drnolist" , s_ignore
, 0 },
2385 { "emsg" , tic54x_message
, 'e' },
2386 { "mmsg" , tic54x_message
, 'm' },
2387 { "wmsg" , tic54x_message
, 'w' },
2388 { "far_mode" , tic54x_address_mode
, far_mode
},
2389 { "fclist" , tic54x_fclist
, 1 },
2390 { "fcnolist" , tic54x_fclist
, 0 },
2391 { "field" , tic54x_field
, -1 },
2392 { "float" , tic54x_float_cons
, 'f' },
2393 { "xfloat" , tic54x_float_cons
, 'x' },
2394 { "global" , tic54x_global
, 'g' },
2395 { "def" , tic54x_global
, 'd' },
2396 { "ref" , tic54x_global
, 'r' },
2397 { "half" , tic54x_cons
, 'h' },
2398 { "uhalf" , tic54x_cons
, 'H' },
2399 { "short" , tic54x_cons
, 's' },
2400 { "ushort" , tic54x_cons
, 'S' },
2401 { "if" , s_if
, (int) O_ne
},
2402 { "elseif" , s_elseif
, (int) O_ne
},
2403 { "else" , s_else
, 0 },
2404 { "endif" , s_endif
, 0 },
2405 { "int" , tic54x_cons
, 'i' },
2406 { "uint" , tic54x_cons
, 'I' },
2407 { "word" , tic54x_cons
, 'w' },
2408 { "uword" , tic54x_cons
, 'W' },
2409 { "label" , tic54x_label
, 0 }, /* Loadtime
2411 { "length" , s_ignore
, 0 },
2412 { "width" , s_ignore
, 0 },
2413 { "long" , tic54x_cons
, 'l' },
2414 { "ulong" , tic54x_cons
, 'L' },
2415 { "xlong" , tic54x_cons
, 'x' },
2416 { "loop" , tic54x_loop
, 1024 },
2417 { "break" , tic54x_break
, 0 },
2418 { "endloop" , tic54x_endloop
, 0 },
2419 { "mlib" , tic54x_mlib
, 0 },
2420 { "mlist" , s_ignore
, 0 },
2421 { "mnolist" , s_ignore
, 0 },
2422 { "mmregs" , tic54x_mmregs
, 0 },
2423 { "newblock" , tic54x_clear_local_labels
, 0 },
2424 { "option" , s_ignore
, 0 },
2425 { "p2align" , tic54x_p2align
, 0 },
2426 { "sblock" , tic54x_sblock
, 0 },
2427 { "sect" , tic54x_sect
, '*' },
2428 { "set" , tic54x_set
, 0 },
2429 { "equ" , tic54x_set
, 0 },
2430 { "space" , tic54x_space
, 0 },
2431 { "bes" , tic54x_space
, 1 },
2432 { "sslist" , tic54x_sslist
, 1 },
2433 { "ssnolist" , tic54x_sslist
, 0 },
2434 { "string" , tic54x_stringer
, 's' },
2435 { "pstring" , tic54x_stringer
, 'p' },
2436 { "struct" , tic54x_struct
, 0 },
2437 { "tag" , tic54x_tag
, 0 },
2438 { "endstruct", tic54x_endstruct
, 0 },
2439 { "tab" , s_ignore
, 0 },
2440 { "text" , tic54x_sect
, 't' },
2441 { "union" , tic54x_struct
, 1 },
2442 { "endunion" , tic54x_endstruct
, 1 },
2443 { "usect" , tic54x_usect
, 0 },
2444 { "var" , tic54x_var
, 0 },
2445 { "version" , tic54x_version
, 0 },
2450 md_parse_option (int c
, const char *arg
)
2456 case OPTION_COFF_VERSION
:
2458 int version
= atoi (arg
);
2460 if (version
!= 0 && version
!= 1 && version
!= 2)
2461 as_fatal (_("Bad COFF version '%s'"), arg
);
2462 /* FIXME -- not yet implemented. */
2465 case OPTION_CPU_VERSION
:
2467 cpu
= lookup_version (arg
);
2470 as_fatal (_("Bad CPU version '%s'"), arg
);
2473 case OPTION_ADDRESS_MODE
:
2475 address_mode_needs_set
= 1;
2477 case OPTION_STDERR_TO_FILE
:
2479 const char *filename
= arg
;
2480 FILE *fp
= fopen (filename
, "w+");
2483 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2485 if ((fp
= freopen (filename
, "w+", stderr
)) == NULL
)
2486 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2494 /* Create a "local" substitution string hash table for a new macro level
2495 Some docs imply that macros have to use .newblock in order to be able
2496 to re-use a local label. We effectively do an automatic .newblock by
2497 deleting the local label hash between macro invocations. */
2500 tic54x_macro_start (void)
2502 if (++macro_level
>= MAX_SUBSYM_HASH
)
2504 as_fatal (_("Macro nesting is too deep"));
2507 subsym_hash
[macro_level
] = str_htab_create ();
2508 local_label_hash
[macro_level
] = str_htab_create ();
2512 tic54x_macro_info (const macro_entry
*macro
)
2514 const formal_entry
*entry
;
2516 /* Put the formal args into the substitution symbol table. */
2517 for (entry
= macro
->formals
; entry
; entry
= entry
->next
)
2519 char *name
= xstrndup (entry
->name
.ptr
, entry
->name
.len
);
2520 char *value
= xstrndup (entry
->actual
.ptr
, entry
->actual
.len
);
2522 name
[entry
->name
.len
] = '\0';
2523 value
[entry
->actual
.len
] = '\0';
2524 str_hash_insert (subsym_hash
[macro_level
], name
, value
, 0);
2528 /* Get rid of this macro's .var's, arguments, and local labels. */
2531 tic54x_macro_end (void)
2533 htab_delete (subsym_hash
[macro_level
]);
2534 subsym_hash
[macro_level
] = NULL
;
2535 htab_delete (local_label_hash
[macro_level
]);
2536 local_label_hash
[macro_level
] = NULL
;
2541 subsym_symlen (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2546 /* Compare symbol A to string B. */
2549 subsym_symcmp (char *a
, char *b
)
2551 return strcmp (a
, b
);
2554 /* Return the index of the first occurrence of B in A, or zero if none
2555 assumes b is an integer char value as a string. Index is one-based. */
2558 subsym_firstch (char *a
, char *b
)
2561 char *tmp
= strchr (a
, val
);
2563 return tmp
? tmp
- a
+ 1 : 0;
2566 /* Similar to firstch, but returns index of last occurrence of B in A. */
2569 subsym_lastch (char *a
, char *b
)
2572 char *tmp
= strrchr (a
, val
);
2574 return tmp
? tmp
- a
+ 1 : 0;
2577 /* Returns 1 if string A is defined in the symbol table (NOT the substitution
2581 subsym_isdefed (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2583 symbolS
*symbolP
= symbol_find (a
);
2585 return symbolP
!= NULL
;
2588 /* Assign first member of comma-separated list B (e.g. "1,2,3") to the symbol
2589 A, or zero if B is a null string. Both arguments *must* be substitution
2590 symbols, unsubstituted. */
2593 subsym_ismember (char *sym
, char *list
)
2595 char *elem
, *ptr
, *listv
;
2600 listv
= subsym_lookup (list
, macro_level
);
2603 as_bad (_("Undefined substitution symbol '%s'"), list
);
2604 ignore_rest_of_line ();
2608 ptr
= elem
= xstrdup (listv
);
2609 while (*ptr
&& *ptr
!= ',')
2613 subsym_create_or_replace (sym
, elem
);
2615 /* Reassign the list. */
2616 subsym_create_or_replace (list
, ptr
);
2618 /* Assume this value, docs aren't clear. */
2622 /* Return zero if not a constant; otherwise:
2630 subsym_iscons (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2634 parse_expression (a
, &expn
);
2636 if (expn
.X_op
== O_constant
)
2638 int len
= strlen (a
);
2640 switch (TOUPPER (a
[len
- 1]))
2653 /* No suffix; either octal, hex, or decimal. */
2654 if (*a
== '0' && len
> 1)
2656 if (TOUPPER (a
[1]) == 'X')
2666 /* Return 1 if A is a valid symbol name. Expects string input. */
2669 subsym_isname (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2671 if (!is_name_beginner (*a
))
2675 if (!is_part_of_name (*a
))
2682 /* Return whether the string is a register; accepts ar0-7, unless .mmregs has
2683 been seen; if so, recognize any memory-mapped register.
2684 Note this does not recognize "A" or "B" accumulators. */
2687 subsym_isreg (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2689 if (str_hash_find (reg_hash
, a
))
2691 if (str_hash_find (mmreg_hash
, a
))
2696 /* Return the structure size, given the stag. */
2699 subsym_structsz (char *name
, char *ignore ATTRIBUTE_UNUSED
)
2701 struct stag
*stag
= (struct stag
*) str_hash_find (stag_hash
, name
);
2709 /* If anybody actually uses this, they can fix it :)
2710 FIXME I'm not sure what the "reference point" of a structure is. It might
2711 be either the initial offset given .struct, or it may be the offset of the
2712 structure within another structure, or it might be something else
2713 altogether. since the TI assembler doesn't seem to ever do anything but
2714 return zero, we punt and return zero. */
2717 subsym_structacc (char *stag_name ATTRIBUTE_UNUSED
,
2718 char *ignore ATTRIBUTE_UNUSED
)
2724 math_ceil (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2726 return (float) ceil (arg1
);
2730 math_cvi (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2736 math_floor (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2738 return (float) floor (arg1
);
2742 math_fmod (float arg1
, float arg2
)
2744 return (int) arg1
% (int) arg2
;
2748 math_int (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2750 return ((float) ((int) arg1
)) == arg1
;
2754 math_round (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2756 return arg1
> 0 ? (int) (arg1
+ 0.5) : (int) (arg1
- 0.5);
2760 math_sgn (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2762 return (arg1
< 0) ? -1 : (arg1
? 1 : 0);
2766 math_trunc (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2772 math_acos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2774 return (float) acos (arg1
);
2778 math_asin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2780 return (float) asin (arg1
);
2784 math_atan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2786 return (float) atan (arg1
);
2790 math_atan2 (float arg1
, float arg2
)
2792 return (float) atan2 (arg1
, arg2
);
2796 math_cosh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2798 return (float) cosh (arg1
);
2802 math_cos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2804 return (float) cos (arg1
);
2808 math_cvf (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2810 return (float) arg1
;
2814 math_exp (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2816 return (float) exp (arg1
);
2820 math_fabs (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2822 return (float) fabs (arg1
);
2825 /* expr1 * 2^expr2. */
2828 math_ldexp (float arg1
, float arg2
)
2830 return arg1
* (float) pow (2.0, arg2
);
2834 math_log10 (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2836 return (float) log10 (arg1
);
2840 math_log (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2842 return (float) log (arg1
);
2846 math_max (float arg1
, float arg2
)
2848 return (arg1
> arg2
) ? arg1
: arg2
;
2852 math_min (float arg1
, float arg2
)
2854 return (arg1
< arg2
) ? arg1
: arg2
;
2858 math_pow (float arg1
, float arg2
)
2860 return (float) pow (arg1
, arg2
);
2864 math_sin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2866 return (float) sin (arg1
);
2870 math_sinh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2872 return (float) sinh (arg1
);
2876 math_sqrt (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2878 return (float) sqrt (arg1
);
2882 math_tan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2884 return (float) tan (arg1
);
2888 math_tanh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2890 return (float) tanh (arg1
);
2893 /* Built-in substitution symbol functions and math functions. */
2897 int (*proc
) (char *, char *);
2899 } subsym_proc_entry
;
2901 static const subsym_proc_entry subsym_procs
[] =
2903 /* Assembler built-in string substitution functions. */
2904 { "$symlen", subsym_symlen
, 1, },
2905 { "$symcmp", subsym_symcmp
, 2, },
2906 { "$firstch", subsym_firstch
, 2, },
2907 { "$lastch", subsym_lastch
, 2, },
2908 { "$isdefed", subsym_isdefed
, 1, },
2909 { "$ismember", subsym_ismember
, 2, },
2910 { "$iscons", subsym_iscons
, 1, },
2911 { "$isname", subsym_isname
, 1, },
2912 { "$isreg", subsym_isreg
, 1, },
2913 { "$structsz", subsym_structsz
, 1, },
2914 { "$structacc", subsym_structacc
, 1, },
2921 float (*proc
) (float, float);
2926 static const math_proc_entry math_procs
[] =
2928 /* Integer-returning built-in math functions. */
2929 { "$cvi", math_cvi
, 1, 1 },
2930 { "$int", math_int
, 1, 1 },
2931 { "$sgn", math_sgn
, 1, 1 },
2933 /* Float-returning built-in math functions. */
2934 { "$acos", math_acos
, 1, 0 },
2935 { "$asin", math_asin
, 1, 0 },
2936 { "$atan", math_atan
, 1, 0 },
2937 { "$atan2", math_atan2
, 2, 0 },
2938 { "$ceil", math_ceil
, 1, 0 },
2939 { "$cosh", math_cosh
, 1, 0 },
2940 { "$cos", math_cos
, 1, 0 },
2941 { "$cvf", math_cvf
, 1, 0 },
2942 { "$exp", math_exp
, 1, 0 },
2943 { "$fabs", math_fabs
, 1, 0 },
2944 { "$floor", math_floor
, 1, 0 },
2945 { "$fmod", math_fmod
, 2, 0 },
2946 { "$ldexp", math_ldexp
, 2, 0 },
2947 { "$log10", math_log10
, 1, 0 },
2948 { "$log", math_log
, 1, 0 },
2949 { "$max", math_max
, 2, 0 },
2950 { "$min", math_min
, 2, 0 },
2951 { "$pow", math_pow
, 2, 0 },
2952 { "$round", math_round
, 1, 0 },
2953 { "$sin", math_sin
, 1, 0 },
2954 { "$sinh", math_sinh
, 1, 0 },
2955 { "$sqrt", math_sqrt
, 1, 0 },
2956 { "$tan", math_tan
, 1, 0 },
2957 { "$tanh", math_tanh
, 1, 0 },
2958 { "$trunc", math_trunc
, 1, 0 },
2959 { NULL
, NULL
, 0, 0 },
2967 const subsym_proc_entry
*subsym_proc
;
2968 const math_proc_entry
*math_proc
;
2970 char *TIC54X_DIR
= getenv ("TIC54X_DIR");
2971 char *A_DIR
= TIC54X_DIR
? TIC54X_DIR
: getenv ("A_DIR");
2975 /* Look for A_DIR and add it to the include list. */
2978 char *tmp
= xstrdup (A_DIR
);
2982 char *next
= strchr (tmp
, ';');
2986 add_include_dir (tmp
);
2989 while (tmp
!= NULL
);
2992 op_hash
= str_htab_create ();
2993 for (tm
= (insn_template
*) tic54x_optab
; tm
->name
; tm
++)
2994 str_hash_insert (op_hash
, tm
->name
, tm
, 0);
2996 parop_hash
= str_htab_create ();
2997 for (tm
= (insn_template
*) tic54x_paroptab
; tm
->name
; tm
++)
2998 str_hash_insert (parop_hash
, tm
->name
, tm
, 0);
3000 reg_hash
= str_htab_create ();
3001 for (sym
= (tic54x_symbol
*) regs
; sym
->name
; sym
++)
3003 /* Add basic registers to the symbol table. */
3004 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
3005 &zero_address_frag
, sym
->value
);
3006 SF_SET_LOCAL (symbolP
);
3007 symbol_table_insert (symbolP
);
3008 str_hash_insert (reg_hash
, sym
->name
, sym
, 0);
3010 for (sym
= (tic54x_symbol
*) mmregs
; sym
->name
; sym
++)
3011 str_hash_insert (reg_hash
, sym
->name
, sym
, 0);
3012 mmreg_hash
= str_htab_create ();
3013 for (sym
= (tic54x_symbol
*) mmregs
; sym
->name
; sym
++)
3014 str_hash_insert (mmreg_hash
, sym
->name
, sym
, 0);
3016 cc_hash
= str_htab_create ();
3017 for (sym
= (tic54x_symbol
*) condition_codes
; sym
->name
; sym
++)
3018 str_hash_insert (cc_hash
, sym
->name
, sym
, 0);
3020 cc2_hash
= str_htab_create ();
3021 for (sym
= (tic54x_symbol
*) cc2_codes
; sym
->name
; sym
++)
3022 str_hash_insert (cc2_hash
, sym
->name
, sym
, 0);
3024 cc3_hash
= str_htab_create ();
3025 for (sym
= (tic54x_symbol
*) cc3_codes
; sym
->name
; sym
++)
3026 str_hash_insert (cc3_hash
, sym
->name
, sym
, 0);
3028 sbit_hash
= str_htab_create ();
3029 for (sym
= (tic54x_symbol
*) status_bits
; sym
->name
; sym
++)
3030 str_hash_insert (sbit_hash
, sym
->name
, sym
, 0);
3032 misc_symbol_hash
= str_htab_create ();
3033 for (symname
= (char **) misc_symbols
; *symname
; symname
++)
3034 str_hash_insert (misc_symbol_hash
, *symname
, *symname
, 0);
3036 /* Only the base substitution table and local label table are initialized;
3037 the others (for local macro substitution) get instantiated as needed. */
3038 local_label_hash
[0] = str_htab_create ();
3039 subsym_hash
[0] = str_htab_create ();
3040 for (subsym_proc
= subsym_procs
; subsym_proc
->name
; subsym_proc
++)
3041 str_hash_insert (subsym_hash
[0], subsym_proc
->name
, subsym_proc
, 0);
3043 math_hash
= str_htab_create ();
3044 for (math_proc
= math_procs
; math_proc
->name
; math_proc
++)
3046 /* Insert into the main subsym hash for recognition; insert into
3047 the math hash to actually store information. */
3048 str_hash_insert (subsym_hash
[0], math_proc
->name
, math_proc
, 0);
3049 str_hash_insert (math_hash
, math_proc
->name
, math_proc
, 0);
3051 subsym_recurse_hash
= str_htab_create ();
3052 stag_hash
= str_htab_create ();
3056 is_accumulator (struct opstruct
*operand
)
3058 return strcasecmp (operand
->buf
, "a") == 0
3059 || strcasecmp (operand
->buf
, "b") == 0;
3062 /* Return the number of operands found, or -1 on error, copying the
3063 operands into the given array and the accompanying expressions into
3067 get_operands (struct opstruct operands
[], char *line
)
3071 int expecting_operand
= 0;
3074 while (numexp
< MAX_OPERANDS
&& !is_end_of_line
[(unsigned char) *lptr
])
3076 int paren_not_balanced
= 0;
3077 char *op_start
, *op_end
;
3079 while (*lptr
&& ISSPACE (*lptr
))
3082 while (paren_not_balanced
|| *lptr
!= ',')
3086 if (paren_not_balanced
)
3088 as_bad (_("Unbalanced parenthesis in operand %d"), numexp
);
3095 ++paren_not_balanced
;
3096 else if (*lptr
== ')')
3097 --paren_not_balanced
;
3101 if (op_end
!= op_start
)
3103 int len
= op_end
- op_start
;
3105 strncpy (operands
[numexp
].buf
, op_start
, len
);
3106 operands
[numexp
].buf
[len
] = 0;
3107 /* Trim trailing spaces; while the preprocessor gets rid of most,
3108 there are weird usage patterns that can introduce them
3109 (i.e. using strings for macro args). */
3110 while (len
> 0 && ISSPACE (operands
[numexp
].buf
[len
- 1]))
3111 operands
[numexp
].buf
[--len
] = 0;
3117 if (expecting_operand
|| *lptr
== ',')
3119 as_bad (_("Expecting operand after ','"));
3125 if (*++lptr
== '\0')
3127 as_bad (_("Expecting operand after ','"));
3130 expecting_operand
= 1;
3134 while (*lptr
&& ISSPACE (*lptr
++))
3136 if (!is_end_of_line
[(unsigned char) *lptr
])
3138 as_bad (_("Extra junk on line"));
3142 /* OK, now parse them into expressions. */
3143 for (i
= 0; i
< numexp
; i
++)
3145 memset (&operands
[i
].exp
, 0, sizeof (operands
[i
].exp
));
3146 if (operands
[i
].buf
[0] == '#')
3149 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3151 else if (operands
[i
].buf
[0] == '@')
3153 /* Direct notation. */
3154 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3156 else if (operands
[i
].buf
[0] == '*')
3159 char *paren
= strchr (operands
[i
].buf
, '(');
3161 /* Allow immediate syntax in the inner expression. */
3162 if (paren
&& paren
[1] == '#')
3165 /* Pull out the lk expression or SP offset, if present. */
3168 int len
= strlen (paren
);
3169 char *end
= paren
+ len
;
3172 while (end
[-1] != ')')
3175 as_bad (_("Badly formed address expression"));
3180 parse_expression (paren
, &operands
[i
].exp
);
3184 operands
[i
].exp
.X_op
= O_absent
;
3187 parse_expression (operands
[i
].buf
, &operands
[i
].exp
);
3193 /* Predicates for different operand types. */
3196 is_immediate (struct opstruct
*operand
)
3198 return *operand
->buf
== '#';
3201 /* This is distinguished from immediate because some numbers must be constants
3202 and must *not* have the '#' prefix. */
3205 is_absolute (struct opstruct
*operand
)
3207 return operand
->exp
.X_op
== O_constant
&& !is_immediate (operand
);
3210 /* Is this an indirect operand? */
3213 is_indirect (struct opstruct
*operand
)
3215 return operand
->buf
[0] == '*';
3218 /* Is this a valid dual-memory operand? */
3221 is_dual (struct opstruct
*operand
)
3223 if (is_indirect (operand
) && strncasecmp (operand
->buf
, "*ar", 3) == 0)
3225 char *tmp
= operand
->buf
+ 3;
3230 /* Only allow *ARx, *ARx-, *ARx+, or *ARx+0%. */
3231 valid_mod
= *tmp
== '\0' ||
3232 strcasecmp (tmp
, "-") == 0 ||
3233 strcasecmp (tmp
, "+") == 0 ||
3234 strcasecmp (tmp
, "+0%") == 0;
3235 return arf
>= 2 && arf
<= 5 && valid_mod
;
3241 is_mmreg (struct opstruct
*operand
)
3243 return (is_absolute (operand
)
3244 || is_immediate (operand
)
3245 || str_hash_find (mmreg_hash
, operand
->buf
) != 0);
3249 is_type (struct opstruct
*operand
, enum optype type
)
3254 return operand
->buf
[0] == 0;
3257 return is_dual (operand
);
3259 return is_indirect (operand
);
3261 /* This one *must* be immediate. */
3262 return is_immediate (operand
);
3271 /* Address may be a numeric, indirect, or an expression. */
3272 return !is_immediate (operand
);
3275 return is_mmreg (operand
);
3280 return is_accumulator (operand
);
3282 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'B';
3284 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'A';
3286 return strncasecmp ("ar", operand
->buf
, 2) == 0
3287 && ISDIGIT (operand
->buf
[2]);
3289 return str_hash_find (sbit_hash
, operand
->buf
) != 0 || is_absolute (operand
);
3291 return str_hash_find (cc_hash
, operand
->buf
) != 0;
3293 return str_hash_find (cc2_hash
, operand
->buf
) != 0;
3295 return str_hash_find (cc3_hash
, operand
->buf
) != 0
3296 || is_immediate (operand
) || is_absolute (operand
);
3298 return (is_immediate (operand
) || is_absolute (operand
))
3299 && operand
->exp
.X_add_number
== 16;
3301 /* Allow st0 or st1 instead of a numeric. */
3302 return is_absolute (operand
) || is_immediate (operand
) ||
3303 strcasecmp ("st0", operand
->buf
) == 0 ||
3304 strcasecmp ("st1", operand
->buf
) == 0;
3307 return is_absolute (operand
) || is_immediate (operand
);
3309 return (is_immediate (operand
) || is_absolute (operand
))
3310 && operand
->exp
.X_add_number
>= 0 && operand
->exp
.X_add_number
< 16;
3312 /* Let this one catch out-of-range values. */
3313 return (is_immediate (operand
) || is_absolute (operand
))
3314 && operand
->exp
.X_add_number
!= 16;
3318 return is_absolute (operand
) || is_immediate (operand
);
3320 return is_immediate (operand
)
3321 && operand
->exp
.X_op
== O_constant
3322 && operand
->exp
.X_add_number
>= 0
3323 && operand
->exp
.X_add_number
< 256;
3326 /* Allow anything; assumes opcodes are ordered with Smem operands
3332 /* Just make sure it's an integer; check range later. */
3333 return is_immediate (operand
);
3335 return strcasecmp ("t", operand
->buf
) == 0 ||
3336 strcasecmp ("treg", operand
->buf
) == 0;
3338 return strcasecmp ("ts", operand
->buf
) == 0;
3340 return strcasecmp ("asm", operand
->buf
) == 0;
3342 return strcasecmp ("trn", operand
->buf
) == 0;
3344 return strcasecmp ("dp", operand
->buf
) == 0;
3346 return strcasecmp ("arp", operand
->buf
) == 0;
3353 operands_match (tic54x_insn
*insn
,
3354 struct opstruct
*operands
,
3356 const enum optype
*refoptype
,
3360 int op
= 0, refop
= 0;
3362 if (opcount
== 0 && minops
== 0)
3365 while (op
<= maxops
&& refop
<= maxops
)
3367 while (!is_type (&operands
[op
], OPTYPE (refoptype
[refop
])))
3369 /* Skip an optional template operand if it doesn't agree
3370 with the current operand. */
3371 if (refoptype
[refop
] & OPT
)
3382 /* Save the actual operand type for later use. */
3383 operands
[op
].type
= OPTYPE (refoptype
[refop
]);
3386 /* Have we matched them all yet? */
3391 /* If a later operand is *not* optional, no match. */
3392 if ((refoptype
[refop
] & OPT
) == 0)
3394 /* Flag any implicit default OP_DST operands so we know to add
3395 them explicitly when encoding the operand later. */
3396 if (OPTYPE (refoptype
[refop
]) == OP_DST
)
3397 insn
->using_default_dst
= 1;
3409 /* 16-bit direct memory address
3410 Explicit dmad operands are always in last word of insn (usually second
3411 word, but bumped to third if lk addressing is used)
3413 We allow *(dmad) notation because the TI assembler allows it.
3416 0 for 16-bit addresses
3417 1 for full 23-bit addresses
3418 2 for the upper 7 bits of a 23-bit address (LDX). */
3421 encode_dmad (tic54x_insn
*insn
, struct opstruct
*operand
, int xpc_code
)
3423 int op
= 1 + insn
->is_lkaddr
;
3425 /* Only allow *(dmad) expressions; all others are invalid. */
3426 if (is_indirect (operand
) && operand
->buf
[strlen (operand
->buf
) - 1] != ')')
3428 as_bad (_("Invalid dmad syntax '%s'"), operand
->buf
);
3432 insn
->opcode
[op
].addr_expr
= operand
->exp
;
3434 if (insn
->opcode
[op
].addr_expr
.X_op
== O_constant
)
3436 valueT value
= insn
->opcode
[op
].addr_expr
.X_add_number
;
3440 insn
->opcode
[0].word
&= 0xFF80;
3441 insn
->opcode
[0].word
|= (value
>> 16) & 0x7F;
3442 insn
->opcode
[1].word
= value
& 0xFFFF;
3444 else if (xpc_code
== 2)
3445 insn
->opcode
[op
].word
= (value
>> 16) & 0xFFFF;
3447 insn
->opcode
[op
].word
= value
;
3451 /* Do the fixup later; just store the expression. */
3452 insn
->opcode
[op
].word
= 0;
3453 insn
->opcode
[op
].r_nchars
= 2;
3455 if (amode
== c_mode
)
3456 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3457 else if (xpc_code
== 1)
3459 /* This relocation spans two words, so adjust accordingly. */
3460 insn
->opcode
[0].addr_expr
= operand
->exp
;
3461 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_23
;
3462 insn
->opcode
[0].r_nchars
= 4;
3463 insn
->opcode
[0].unresolved
= 1;
3464 /* It's really 2 words, but we want to stop encoding after the
3465 first, since we must encode both words at once. */
3468 else if (xpc_code
== 2)
3469 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_MS7_OF_23
;
3471 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3473 insn
->opcode
[op
].unresolved
= 1;
3479 /* 7-bit direct address encoding. */
3482 encode_address (tic54x_insn
*insn
, struct opstruct
*operand
)
3484 /* Assumes that dma addresses are *always* in word 0 of the opcode. */
3485 insn
->opcode
[0].addr_expr
= operand
->exp
;
3487 if (operand
->exp
.X_op
== O_constant
)
3488 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
& 0x7F);
3491 if (operand
->exp
.X_op
== O_register
)
3492 as_bad (_("Use the .mmregs directive to use memory-mapped register names such as '%s'"), operand
->buf
);
3493 /* Do the fixup later; just store the expression. */
3494 insn
->opcode
[0].r_nchars
= 1;
3495 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_PARTLS7
;
3496 insn
->opcode
[0].unresolved
= 1;
3503 encode_indirect (tic54x_insn
*insn
, struct opstruct
*operand
)
3508 if (insn
->is_lkaddr
)
3510 /* lk addresses always go in the second insn word. */
3511 mod
= ((TOUPPER (operand
->buf
[1]) == 'A') ? 12 :
3512 (operand
->buf
[1] == '(') ? 15 :
3513 (strchr (operand
->buf
, '%') != NULL
) ? 14 : 13);
3514 arf
= ((mod
== 12) ? operand
->buf
[3] - '0' :
3515 (mod
== 15) ? 0 : operand
->buf
[4] - '0');
3517 insn
->opcode
[1].addr_expr
= operand
->exp
;
3519 if (operand
->exp
.X_op
== O_constant
)
3520 insn
->opcode
[1].word
= operand
->exp
.X_add_number
;
3523 insn
->opcode
[1].word
= 0;
3524 insn
->opcode
[1].r_nchars
= 2;
3525 insn
->opcode
[1].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3526 insn
->opcode
[1].unresolved
= 1;
3529 else if (strncasecmp (operand
->buf
, "*sp (", 4) == 0)
3531 /* Stack offsets look the same as 7-bit direct addressing. */
3532 return encode_address (insn
, operand
);
3536 arf
= (TOUPPER (operand
->buf
[1]) == 'A' ?
3537 operand
->buf
[3] : operand
->buf
[4]) - '0';
3539 if (operand
->buf
[1] == '+')
3541 mod
= 3; /* *+ARx */
3542 if (insn
->tm
->flags
& FL_SMR
)
3543 as_warn (_("Address mode *+ARx is write-only. "
3544 "Results of reading are undefined."));
3546 else if (operand
->buf
[4] == '\0')
3548 else if (operand
->buf
[5] == '\0')
3549 mod
= (operand
->buf
[4] == '-' ? 1 : 2); /* *ARx+ / *ARx- */
3550 else if (operand
->buf
[6] == '\0')
3552 if (operand
->buf
[5] == '0')
3553 mod
= (operand
->buf
[4] == '-' ? 5 : 6); /* *ARx+0 / *ARx-0 */
3555 mod
= (operand
->buf
[4] == '-' ? 8 : 10);/* *ARx+% / *ARx-% */
3557 else if (TOUPPER (operand
->buf
[6]) == 'B')
3558 mod
= (operand
->buf
[4] == '-' ? 4 : 7); /* ARx+0B / *ARx-0B */
3559 else if (TOUPPER (operand
->buf
[6]) == '%')
3560 mod
= (operand
->buf
[4] == '-' ? 9 : 11); /* ARx+0% / *ARx - 0% */
3563 as_bad (_("Unrecognized indirect address format \"%s\""),
3569 insn
->opcode
[0].word
|= 0x80 | (mod
<< 3) | arf
;
3575 encode_integer (tic54x_insn
*insn
,
3576 struct opstruct
*operand
,
3580 unsigned short mask
)
3582 long parse
, integer
;
3584 insn
->opcode
[which
].addr_expr
= operand
->exp
;
3586 if (operand
->exp
.X_op
== O_constant
)
3588 parse
= operand
->exp
.X_add_number
;
3589 /* Hack -- fixup for 16-bit hex quantities that get converted positive
3590 instead of negative. */
3591 if ((parse
& 0x8000) && min
== -32768 && max
== 32767)
3592 integer
= (short) parse
;
3596 if (integer
>= min
&& integer
<= max
)
3598 insn
->opcode
[which
].word
|= (integer
& mask
);
3601 as_bad (_("Operand '%s' out of range (%d <= x <= %d)"),
3602 operand
->buf
, min
, max
);
3606 if (insn
->opcode
[which
].addr_expr
.X_op
== O_constant
)
3608 insn
->opcode
[which
].word
|=
3609 insn
->opcode
[which
].addr_expr
.X_add_number
& mask
;
3613 /* Do the fixup later; just store the expression. */
3614 bfd_reloc_code_real_type rtype
=
3615 (mask
== 0x1FF ? BFD_RELOC_TIC54X_PARTMS9
:
3616 mask
== 0xFFFF ? BFD_RELOC_TIC54X_16_OF_23
:
3617 mask
== 0x7F ? BFD_RELOC_TIC54X_PARTLS7
: BFD_RELOC_8
);
3618 int size
= (mask
== 0x1FF || mask
== 0xFFFF) ? 2 : 1;
3620 if (rtype
== BFD_RELOC_8
)
3621 as_bad (_("Error in relocation handling"));
3623 insn
->opcode
[which
].r_nchars
= size
;
3624 insn
->opcode
[which
].r_type
= rtype
;
3625 insn
->opcode
[which
].unresolved
= 1;
3635 encode_condition (tic54x_insn
*insn
, struct opstruct
*operand
)
3637 tic54x_symbol
*cc
= (tic54x_symbol
*) str_hash_find (cc_hash
, operand
->buf
);
3640 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3643 #define CC_GROUP 0x40
3645 #define CATG_A1 0x07
3646 #define CATG_B1 0x30
3647 #define CATG_A2 0x30
3648 #define CATG_B2 0x0C
3649 #define CATG_C2 0x03
3650 /* Disallow group 1 conditions mixed with group 2 conditions
3651 if group 1, allow only one category A and one category B
3652 if group 2, allow only one each of category A, B, and C. */
3653 if (((insn
->opcode
[0].word
& 0xFF) != 0))
3655 if ((insn
->opcode
[0].word
& CC_GROUP
) != (cc
->value
& CC_GROUP
))
3657 as_bad (_("Condition \"%s\" does not match preceding group"),
3661 if (insn
->opcode
[0].word
& CC_GROUP
)
3663 if ((insn
->opcode
[0].word
& CC_ACC
) != (cc
->value
& CC_ACC
))
3665 as_bad (_("Condition \"%s\" uses a different accumulator from "
3666 "a preceding condition"),
3670 if ((insn
->opcode
[0].word
& CATG_A1
) && (cc
->value
& CATG_A1
))
3672 as_bad (_("Only one comparison conditional allowed"));
3675 if ((insn
->opcode
[0].word
& CATG_B1
) && (cc
->value
& CATG_B1
))
3677 as_bad (_("Only one overflow conditional allowed"));
3681 else if ( ((insn
->opcode
[0].word
& CATG_A2
) && (cc
->value
& CATG_A2
))
3682 || ((insn
->opcode
[0].word
& CATG_B2
) && (cc
->value
& CATG_B2
))
3683 || ((insn
->opcode
[0].word
& CATG_C2
) && (cc
->value
& CATG_C2
)))
3685 as_bad (_("Duplicate %s conditional"), operand
->buf
);
3690 insn
->opcode
[0].word
|= cc
->value
;
3695 encode_cc3 (tic54x_insn
*insn
, struct opstruct
*operand
)
3697 tic54x_symbol
*cc3
= (tic54x_symbol
*) str_hash_find (cc3_hash
, operand
->buf
);
3698 int value
= cc3
? cc3
->value
: operand
->exp
.X_add_number
<< 8;
3700 if ((value
& 0x0300) != value
)
3702 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3705 insn
->opcode
[0].word
|= value
;
3710 encode_arx (tic54x_insn
*insn
, struct opstruct
*operand
)
3712 int arf
= strlen (operand
->buf
) >= 3 ? operand
->buf
[2] - '0' : -1;
3714 if (strncasecmp ("ar", operand
->buf
, 2) || arf
< 0 || arf
> 7)
3716 as_bad (_("Invalid auxiliary register (use AR0-AR7)"));
3719 insn
->opcode
[0].word
|= arf
;
3724 encode_cc2 (tic54x_insn
*insn
, struct opstruct
*operand
)
3726 tic54x_symbol
*cc2
= (tic54x_symbol
*) str_hash_find (cc2_hash
, operand
->buf
);
3730 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3733 insn
->opcode
[0].word
|= cc2
->value
;
3738 encode_operand (tic54x_insn
*insn
, enum optype type
, struct opstruct
*operand
)
3740 int ext
= (insn
->tm
->flags
& FL_EXT
) != 0;
3742 if (type
== OP_MMR
&& operand
->exp
.X_op
!= O_constant
)
3744 /* Disallow long-constant addressing for memory-mapped addressing. */
3745 if (insn
->is_lkaddr
)
3747 as_bad (_("lk addressing modes are invalid for memory-mapped "
3748 "register addressing"));
3752 /* Warn about *+ARx when used with MMR operands. */
3753 if (strncasecmp (operand
->buf
, "*+ar", 4) == 0)
3755 as_warn (_("Address mode *+ARx is not allowed in memory-mapped "
3756 "register addressing. Resulting behavior is "
3766 /* 16-bit immediate value. */
3767 return encode_dmad (insn
, operand
, 0);
3769 if (TOUPPER (*operand
->buf
) == 'B')
3771 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 9);
3772 if (insn
->using_default_dst
)
3773 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3777 /* Make sure this agrees with the OP_DST operand. */
3778 if (!((TOUPPER (operand
->buf
[0]) == 'B') ^
3779 ((insn
->opcode
[0].word
& (1 << 8)) != 0)))
3781 as_bad (_("Destination accumulator for each part of this parallel "
3782 "instruction must be different"));
3788 if (TOUPPER (operand
->buf
[0]) == 'B')
3789 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3794 int mod
= (operand
->buf
[4] == '\0' ? 0 : /* *arx */
3795 operand
->buf
[4] == '-' ? 1 : /* *arx- */
3796 operand
->buf
[5] == '\0' ? 2 : 3); /* *arx+, *arx+0% */
3797 int arf
= operand
->buf
[3] - '0' - 2;
3798 int code
= (mod
<< 2) | arf
;
3799 insn
->opcode
[0].word
|= (code
<< (type
== OP_Xmem
? 4 : 0));
3804 if (!is_indirect (operand
))
3805 return encode_address (insn
, operand
);
3808 return encode_indirect (insn
, operand
);
3810 return encode_dmad (insn
, operand
, 2);
3812 return encode_dmad (insn
, operand
, 1);
3815 return encode_dmad (insn
, operand
, 0);
3817 return encode_arx (insn
, operand
);
3822 int value
= operand
->exp
.X_add_number
;
3825 insn
->opcode
[0].word
|= value
;
3828 if (value
< 16 || value
> 24)
3830 as_bad (_("Memory mapped register \"%s\" out of range"),
3834 if (type
== OP_MMRX
)
3835 insn
->opcode
[0].word
|= (value
- 16) << 4;
3837 insn
->opcode
[0].word
|= (value
- 16);
3845 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3848 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3851 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3852 -32768, 32767, 0xFFFF);
3854 return encode_condition (insn
, operand
);
3856 return encode_cc2 (insn
, operand
);
3858 return encode_cc3 (insn
, operand
);
3860 return encode_integer (insn
, operand
, 0, 0, 15, 0xF);
3862 return encode_integer (insn
, operand
, 0, -128, 127, 0xFF);
3865 int value
= operand
->exp
.X_add_number
;
3867 if (value
< 1 || value
> 3)
3869 as_bad (_("Invalid operand (use 1, 2, or 3)"));
3872 code
= value
== 1 ? 0 : value
== 2 ? 0x2 : 0x1;
3873 insn
->opcode
[0].word
|= (code
<< 8);
3877 return encode_integer (insn
, operand
, 0, 0, 31, 0x1F);
3879 return encode_integer (insn
, operand
, 0, 0, 255, 0xFF);
3881 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3885 tic54x_symbol
*sbit
= (tic54x_symbol
*)
3886 str_hash_find (sbit_hash
, operand
->buf
);
3887 int value
= is_absolute (operand
) ?
3888 operand
->exp
.X_add_number
: (sbit
? sbit
->value
: -1);
3891 if (insn
->opcount
== 1)
3895 as_bad (_("A status register or status bit name is required"));
3898 /* Guess the register based on the status bit; "ovb" is the last
3899 status bit defined for st0. */
3900 if (sbit
> (tic54x_symbol
*) str_hash_find (sbit_hash
, "ovb"))
3905 as_bad (_("Unrecognized status bit \"%s\""), operand
->buf
);
3908 insn
->opcode
[0].word
|= value
;
3909 insn
->opcode
[0].word
|= (reg
<< 9);
3913 if (strcasecmp (operand
->buf
, "st0") == 0
3914 || strcasecmp (operand
->buf
, "st1") == 0)
3916 insn
->opcode
[0].word
|=
3917 ((unsigned short) (operand
->buf
[2] - '0')) << 9;
3920 else if (operand
->exp
.X_op
== O_constant
3921 && (operand
->exp
.X_add_number
== 0
3922 || operand
->exp
.X_add_number
== 1))
3924 insn
->opcode
[0].word
|=
3925 ((unsigned short) (operand
->exp
.X_add_number
)) << 9;
3928 as_bad (_("Invalid status register \"%s\""), operand
->buf
);
3931 return encode_integer (insn
, operand
, 0, -16, 15, 0x1F);
3933 return encode_integer (insn
, operand
, 0, 0, 7, 0x7);
3935 return encode_integer (insn
, operand
, 0, 0, 0x1FF, 0x1FF);
3937 if (operand
->exp
.X_add_number
!= 1
3938 && operand
->exp
.X_add_number
!= 2)
3940 as_bad (_("Operand \"%s\" out of range (use 1 or 2)"), operand
->buf
);
3943 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
- 1) << 9;
3952 /* No encoding necessary. */
3962 emit_insn (tic54x_insn
*insn
)
3965 flagword oldflags
= bfd_section_flags (now_seg
);
3966 flagword flags
= oldflags
| SEC_CODE
;
3968 if (!bfd_set_section_flags (now_seg
, flags
))
3969 as_warn (_("error setting flags for \"%s\": %s"),
3970 bfd_section_name (now_seg
),
3971 bfd_errmsg (bfd_get_error ()));
3973 for (i
= 0; i
< insn
->words
; i
++)
3975 int size
= (insn
->opcode
[i
].unresolved
3976 && insn
->opcode
[i
].r_type
== BFD_RELOC_TIC54X_23
) ? 4 : 2;
3977 char *p
= frag_more (size
);
3980 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
, 2);
3982 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
<< 16, 4);
3984 if (insn
->opcode
[i
].unresolved
)
3985 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
,
3986 insn
->opcode
[i
].r_nchars
, &insn
->opcode
[i
].addr_expr
,
3987 FALSE
, insn
->opcode
[i
].r_type
);
3991 /* Convert the operand strings into appropriate opcode values
3992 return the total number of words used by the instruction. */
3995 build_insn (tic54x_insn
*insn
)
3999 /* Only non-parallel instructions support lk addressing. */
4000 if (!(insn
->tm
->flags
& FL_PAR
))
4002 for (i
= 0; i
< insn
->opcount
; i
++)
4004 if ((OPTYPE (insn
->operands
[i
].type
) == OP_Smem
4005 || OPTYPE (insn
->operands
[i
].type
) == OP_Lmem
4006 || OPTYPE (insn
->operands
[i
].type
) == OP_Sind
)
4007 && strchr (insn
->operands
[i
].buf
, '(')
4008 /* Don't mistake stack-relative addressing for lk addressing. */
4009 && strncasecmp (insn
->operands
[i
].buf
, "*sp (", 4) != 0)
4011 insn
->is_lkaddr
= 1;
4012 insn
->lkoperand
= i
;
4017 insn
->words
= insn
->tm
->words
+ insn
->is_lkaddr
;
4019 insn
->opcode
[0].word
= insn
->tm
->opcode
;
4020 if (insn
->tm
->flags
& FL_EXT
)
4021 insn
->opcode
[1 + insn
->is_lkaddr
].word
= insn
->tm
->opcode2
;
4023 for (i
= 0; i
< insn
->opcount
; i
++)
4025 enum optype type
= insn
->operands
[i
].type
;
4027 if (!encode_operand (insn
, type
, &insn
->operands
[i
]))
4030 if (insn
->tm
->flags
& FL_PAR
)
4031 for (i
= 0; i
< insn
->paropcount
; i
++)
4033 enum optype partype
= insn
->paroperands
[i
].type
;
4035 if (!encode_operand (insn
, partype
, &insn
->paroperands
[i
]))
4045 optimize_insn (tic54x_insn
*insn
)
4047 /* Optimize some instructions, helping out the brain-dead programmer. */
4048 #define is_zero(op) ((op).exp.X_op == O_constant && (op).exp.X_add_number == 0)
4049 if (strcasecmp (insn
->tm
->name
, "add") == 0)
4051 if (insn
->opcount
> 1
4052 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4053 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4054 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4055 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4058 insn
->using_default_dst
= 1;
4062 /* Try to collapse if Xmem and shift count is zero. */
4063 if ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4064 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
4065 && is_zero (insn
->operands
[1]))
4066 /* Or if Smem, shift is zero or absent, and SRC == DST. */
4067 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4068 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4069 && is_type (&insn
->operands
[1], OP_SHIFT
)
4070 && is_zero (insn
->operands
[1]) && insn
->opcount
== 3))
4072 insn
->operands
[1] = insn
->operands
[2];
4077 else if (strcasecmp (insn
->tm
->name
, "ld") == 0)
4079 if (insn
->opcount
== 3 && insn
->operands
[0].type
!= OP_SRC
)
4081 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4082 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4083 && is_zero (insn
->operands
[1])
4084 && (OPTYPE (insn
->tm
->operand_types
[0]) != OP_lk
4085 || (insn
->operands
[0].exp
.X_op
== O_constant
4086 && insn
->operands
[0].exp
.X_add_number
<= 255
4087 && insn
->operands
[0].exp
.X_add_number
>= 0)))
4089 insn
->operands
[1] = insn
->operands
[2];
4095 else if (strcasecmp (insn
->tm
->name
, "sth") == 0
4096 || strcasecmp (insn
->tm
->name
, "stl") == 0)
4098 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4099 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4100 && is_zero (insn
->operands
[1]))
4102 insn
->operands
[1] = insn
->operands
[2];
4107 else if (strcasecmp (insn
->tm
->name
, "sub") == 0)
4109 if (insn
->opcount
> 1
4110 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4111 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4112 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4113 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4116 insn
->using_default_dst
= 1;
4120 if ( ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4121 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
)
4122 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4123 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
))
4124 && is_zero (insn
->operands
[1])
4125 && insn
->opcount
== 3)
4127 insn
->operands
[1] = insn
->operands
[2];
4135 /* Find a matching template if possible, and get the operand strings. */
4138 tic54x_parse_insn (tic54x_insn
*insn
, char *line
)
4140 insn
->tm
= (insn_template
*) str_hash_find (op_hash
, insn
->mnemonic
);
4143 as_bad (_("Unrecognized instruction \"%s\""), insn
->mnemonic
);
4147 insn
->opcount
= get_operands (insn
->operands
, line
);
4148 if (insn
->opcount
< 0)
4151 /* Check each variation of operands for this mnemonic. */
4152 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
, insn
->mnemonic
) == 0)
4154 if (insn
->opcount
>= insn
->tm
->minops
4155 && insn
->opcount
<= insn
->tm
->maxops
4156 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4157 insn
->tm
->operand_types
,
4158 insn
->tm
->minops
, insn
->tm
->maxops
))
4160 /* SUCCESS! now try some optimizations. */
4161 if (optimize_insn (insn
))
4163 insn
->tm
= (insn_template
*) str_hash_find (op_hash
,
4172 as_bad (_("Unrecognized operand list '%s' for instruction '%s'"),
4173 line
, insn
->mnemonic
);
4177 /* We set this in start_line_hook, 'cause if we do a line replacement, we
4178 won't be able to see the next line. */
4179 static int parallel_on_next_line_hint
= 0;
4181 /* See if this is part of a parallel instruction
4182 Look for a subsequent line starting with "||". */
4185 next_line_shows_parallel (char *next_line
)
4187 /* Look for the second half. */
4188 while (*next_line
!= 0 && ISSPACE (*next_line
))
4191 return (next_line
[0] == PARALLEL_SEPARATOR
4192 && next_line
[1] == PARALLEL_SEPARATOR
);
4196 tic54x_parse_parallel_insn_firstline (tic54x_insn
*insn
, char *line
)
4198 insn
->tm
= (insn_template
*) str_hash_find (parop_hash
, insn
->mnemonic
);
4201 as_bad (_("Unrecognized parallel instruction \"%s\""),
4206 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4207 insn
->mnemonic
) == 0)
4209 insn
->opcount
= get_operands (insn
->operands
, line
);
4210 if (insn
->opcount
< 0)
4212 if (insn
->opcount
== 2
4213 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4214 insn
->tm
->operand_types
, 2, 2))
4220 /* Didn't find a matching parallel; try for a normal insn. */
4224 /* Parse the second line of a two-line parallel instruction. */
4227 tic54x_parse_parallel_insn_lastline (tic54x_insn
*insn
, char *line
)
4229 int valid_mnemonic
= 0;
4231 insn
->paropcount
= get_operands (insn
->paroperands
, line
);
4232 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4233 insn
->mnemonic
) == 0)
4235 if (strcasecmp (insn
->tm
->parname
, insn
->parmnemonic
) == 0)
4239 if (insn
->paropcount
>= insn
->tm
->minops
4240 && insn
->paropcount
<= insn
->tm
->maxops
4241 && operands_match (insn
, insn
->paroperands
,
4243 insn
->tm
->paroperand_types
,
4244 insn
->tm
->minops
, insn
->tm
->maxops
))
4250 as_bad (_("Invalid operand (s) for parallel instruction \"%s\""),
4253 as_bad (_("Unrecognized parallel instruction combination \"%s || %s\""),
4254 insn
->mnemonic
, insn
->parmnemonic
);
4259 /* If quotes found, return copy of line up to closing quote;
4260 otherwise up until terminator.
4261 If it's a string, pass as-is; otherwise attempt substitution symbol
4262 replacement on the value. */
4265 subsym_get_arg (char *line
, const char *terminators
, char **str
, int nosub
)
4269 int is_string
= *line
== '"';
4270 int is_char
= ISDIGIT (*line
);
4274 while (ISDIGIT (*ptr
))
4277 *str
= xmemdup0 (line
, ptr
- line
);
4281 char *savedp
= input_line_pointer
;
4284 input_line_pointer
= ptr
;
4285 *str
= demand_copy_C_string (&len
);
4286 endp
= input_line_pointer
;
4287 input_line_pointer
= savedp
;
4289 /* Do forced substitutions if requested. */
4290 if (!nosub
&& **str
== ':')
4291 *str
= subsym_substitute (*str
, 1);
4295 const char *term
= terminators
;
4298 while (*ptr
&& *ptr
!= *term
)
4309 *str
= xmemdup0 (line
, ptr
- line
);
4310 /* Do simple substitution, if available. */
4311 if (!nosub
&& (value
= subsym_lookup (*str
, macro_level
)) != NULL
)
4318 /* Replace the given substitution string.
4319 We start at the innermost macro level, so that existing locals remain local
4320 Note: we're treating macro args identically to .var's; I don't know if
4321 that's compatible w/TI's assembler. */
4324 subsym_create_or_replace (char *name
, char *value
)
4328 for (i
= macro_level
; i
> 0; i
--)
4329 if (str_hash_find (subsym_hash
[i
], name
))
4331 str_hash_insert (subsym_hash
[i
], name
, value
, 1);
4334 str_hash_insert (subsym_hash
[0], name
, value
, 1);
4337 /* Look up the substitution string replacement for the given symbol.
4338 Start with the innermost macro substitution table given and work
4342 subsym_lookup (char *name
, int nest_level
)
4344 char *value
= str_hash_find (subsym_hash
[nest_level
], name
);
4346 if (value
|| nest_level
== 0)
4349 return subsym_lookup (name
, nest_level
- 1);
4352 /* Do substitution-symbol replacement on the given line (recursively).
4353 return the argument if no substitution was done
4355 Also look for built-in functions ($func (arg)) and local labels.
4357 If FORCED is set, look for forced substitutions of the form ':SYMBOL:'. */
4360 subsym_substitute (char *line
, int forced
)
4362 /* For each apparent symbol, see if it's a substitution symbol, and if so,
4363 replace it in the input. */
4364 char *replacement
; /* current replacement for LINE. */
4365 char *head
; /* Start of line. */
4366 char *ptr
; /* Current examination point. */
4367 int changed
= 0; /* Did we make a substitution? */
4368 int eval_line
= 0; /* Is this line a .eval/.asg statement? */
4369 int eval_symbol
= 0; /* Are we in the middle of the symbol for
4371 char *eval_end
= NULL
;
4373 int line_conditional
= 0;
4376 /* Work with a copy of the input line. */
4377 replacement
= xstrdup (line
);
4379 ptr
= head
= replacement
;
4381 /* Flag lines where we might need to replace a single '=' with two;
4382 GAS uses single '=' to assign macro args values, and possibly other
4383 places, so limit what we replace. */
4384 if (strstr (line
, ".if")
4385 || strstr (line
, ".elseif")
4386 || strstr (line
, ".break"))
4387 line_conditional
= 1;
4389 /* Watch out for .eval, so that we avoid doing substitution on the
4390 symbol being assigned a value. */
4391 if (strstr (line
, ".eval") || strstr (line
, ".asg"))
4394 /* If it's a macro definition, don't do substitution on the argument
4396 if (strstr (line
, ".macro"))
4399 unsigned char current_char
;
4400 while (!is_end_of_line
[(current_char
= * (unsigned char *) ptr
)])
4402 /* Need to update this since LINE may have been modified. */
4404 eval_end
= strrchr (ptr
, ',');
4406 /* Replace triple double quotes with bounding quote/escapes. */
4407 if (current_char
== '"' && ptr
[1] == '"' && ptr
[2] == '"')
4410 tmp
= strstr (ptr
+ 2, "\"\"\"");
4416 /* Replace a single '=' with a '==';
4417 for compatibility with older code only. */
4418 if (line_conditional
&& current_char
== '=')
4426 tmp
= concat (head
, "==", ptr
, (char *) NULL
);
4427 /* Continue examining after the '=='. */
4428 ptr
= tmp
+ strlen (head
) + 2;
4430 head
= replacement
= tmp
;
4434 /* Flag when we've reached the symbol part of .eval/.asg. */
4435 if (eval_line
&& ptr
>= eval_end
)
4438 /* For each apparent symbol, see if it's a substitution symbol, and if
4439 so, replace it in the input. */
4440 if ((forced
&& current_char
== ':')
4441 || (!forced
&& is_name_beginner (current_char
)))
4443 char *name
; /* Symbol to be replaced. */
4444 char *savedp
= input_line_pointer
;
4447 char *tail
; /* Rest of line after symbol. */
4449 /* Skip the colon. */
4453 input_line_pointer
= ptr
;
4454 c
= get_symbol_name (&name
);
4455 /* '?' is not normally part of a symbol, but it IS part of a local
4459 *input_line_pointer
++ = c
;
4460 c
= *input_line_pointer
;
4461 *input_line_pointer
= '\0';
4463 /* Avoid infinite recursion; if a symbol shows up a second time for
4464 substitution, leave it as is. */
4465 if (str_hash_find (subsym_recurse_hash
, name
) == NULL
)
4466 value
= subsym_lookup (name
, macro_level
);
4468 as_warn (_("%s symbol recursion stopped at "
4469 "second appearance of '%s'"),
4470 forced
? "Forced substitution" : "Substitution", name
);
4471 ptr
= tail
= input_line_pointer
;
4472 input_line_pointer
= savedp
;
4474 /* Check for local labels; replace them with the appropriate
4476 if ((*name
== '$' && ISDIGIT (name
[1]) && name
[2] == '\0')
4477 || name
[strlen (name
) - 1] == '?')
4479 /* Use an existing identifier for that label if, available, or
4480 create a new, unique identifier. */
4481 value
= str_hash_find (local_label_hash
[macro_level
], name
);
4485 char *namecopy
= xstrdup (name
);
4487 value
= strcpy (xmalloc (strlen (name
) + sizeof (digit
) + 1),
4490 value
[strlen (value
) - 1] = '\0';
4491 sprintf (digit
, ".%d", local_label_id
++);
4492 strcat (value
, digit
);
4493 str_hash_insert (local_label_hash
[macro_level
],
4494 namecopy
, value
, 0);
4496 /* Indicate where to continue looking for substitutions. */
4499 /* Check for built-in subsym and math functions. */
4500 else if (value
!= NULL
&& *name
== '$')
4502 subsym_proc_entry
*entry
= (subsym_proc_entry
*) value
;
4503 math_proc_entry
*math_entry
= str_hash_find (math_hash
, name
);
4504 char *arg1
, *arg2
= NULL
;
4509 as_bad (_("Unrecognized substitution symbol function"));
4512 else if (*ptr
!= '(')
4514 as_bad (_("Missing '(' after substitution symbol function"));
4518 if (math_entry
!= NULL
)
4520 float farg1
, farg2
= 0;
4521 volatile float fresult
;
4523 farg1
= (float) strtod (ptr
, &ptr
);
4524 if (math_entry
->nargs
== 2)
4528 as_bad (_("Expecting second argument"));
4531 farg2
= (float) strtod (ptr
, &ptr
);
4533 fresult
= (*math_entry
->proc
) (farg1
, farg2
);
4534 value
= XNEWVEC (char, 128);
4535 if (math_entry
->int_return
)
4536 sprintf (value
, "%d", (int) fresult
);
4538 sprintf (value
, "%f", fresult
);
4541 as_bad (_("Extra junk in function call, expecting ')'"));
4544 /* Don't bother recursing; the replacement isn't a
4551 int arg_type
[2] = { *ptr
== '"' , 0 };
4552 int ismember
= !strcmp (entry
->name
, "$ismember");
4554 /* Parse one or two args, which must be a substitution
4555 symbol, string or a character-string constant. */
4556 /* For all functions, a string or substitution symbol may be
4557 used, with the following exceptions:
4558 firstch/lastch: 2nd arg must be character constant
4559 ismember: both args must be substitution symbols. */
4560 ptr
= subsym_get_arg (ptr
, ",)", &arg1
, ismember
);
4563 if (entry
->nargs
== 2)
4567 as_bad (_("Function expects two arguments"));
4570 /* Character constants are converted to numerics
4571 by the preprocessor. */
4572 arg_type
[1] = (ISDIGIT (*ptr
)) ? 2 : (*ptr
== '"');
4573 ptr
= subsym_get_arg (ptr
, ")", &arg2
, ismember
);
4575 /* Args checking. */
4576 if ((!strcmp (entry
->name
, "$firstch")
4577 || !strcmp (entry
->name
, "$lastch"))
4578 && arg_type
[1] != 2)
4580 as_bad (_("Expecting character constant argument"));
4584 && (arg_type
[0] != 0 || arg_type
[1] != 0))
4586 as_bad (_("Both arguments must be substitution symbols"));
4591 as_bad (_("Extra junk in function call, expecting ')'"));
4594 val
= (*entry
->proc
) (arg1
, arg2
);
4595 value
= XNEWVEC (char, 64);
4596 sprintf (value
, "%d", val
);
4598 /* Fix things up to replace the entire expression, not just the
4604 if (value
!= NULL
&& !eval_symbol
)
4606 /* Replace the symbol with its string replacement and
4607 continue. Recursively replace VALUE until either no
4608 substitutions are performed, or a substitution that has been
4609 previously made is encountered again.
4611 Put the symbol into the recursion hash table so we only
4612 try to replace a symbol once. */
4615 str_hash_insert (subsym_recurse_hash
, name
, name
, 0);
4616 value
= subsym_substitute (value
, macro_level
> 0);
4617 str_hash_delete (subsym_recurse_hash
, name
);
4620 /* Temporarily zero-terminate where the symbol started. */
4626 /* Subscripted substitution symbol -- use just the
4627 indicated portion of the string; the description
4628 kinda indicates that forced substitution is not
4629 supposed to be recursive, but I'm not sure. */
4630 unsigned beg
, len
= 1; /* default to a single char */
4631 char *newval
= xstrdup (value
);
4633 savedp
= input_line_pointer
;
4634 input_line_pointer
= tail
+ 1;
4635 beg
= get_absolute_expression ();
4638 as_bad (_("Invalid subscript (use 1 to %d)"),
4639 (int) strlen (value
));
4642 if (*input_line_pointer
== ',')
4644 ++input_line_pointer
;
4645 len
= get_absolute_expression ();
4646 if (beg
+ len
> strlen (value
))
4648 as_bad (_("Invalid length (use 0 to %d)"),
4649 (int) strlen (value
) - beg
);
4655 tail
= input_line_pointer
;
4658 as_bad (_("Missing ')' in subscripted substitution "
4659 "symbol expression"));
4663 input_line_pointer
= savedp
;
4669 tmp
= xmalloc (strlen (head
) + strlen (value
) +
4670 strlen (tail
+ 1) + 2);
4672 strcat (tmp
, value
);
4673 /* Make sure forced substitutions are properly terminated. */
4678 as_bad (_("Missing forced substitution terminator ':'"));
4684 /* Restore the character after the symbol end. */
4687 /* Continue examining after the replacement value. */
4688 ptr
= tmp
+ strlen (head
) + strlen (value
);
4690 head
= replacement
= tmp
;
4708 /* We use this to handle substitution symbols
4709 hijack input_line_pointer, replacing it with our substituted string.
4711 .sslist should enable listing the line after replacements are made...
4713 returns the new buffer limit. */
4716 tic54x_start_line_hook (void)
4719 char *replacement
= NULL
;
4721 /* Work with a copy of the input line, including EOL char. */
4722 for (endp
= input_line_pointer
; *endp
!= 0; )
4723 if (is_end_of_line
[(unsigned char) *endp
++])
4726 line
= xmemdup0 (input_line_pointer
, endp
- input_line_pointer
);
4728 /* Scan ahead for parallel insns. */
4729 parallel_on_next_line_hint
= next_line_shows_parallel (endp
);
4731 /* If within a macro, first process forced replacements. */
4732 if (macro_level
> 0)
4733 replacement
= subsym_substitute (line
, 1);
4736 replacement
= subsym_substitute (replacement
, 0);
4738 if (replacement
!= line
)
4740 char *tmp
= replacement
;
4741 char *comment
= strchr (replacement
, ';');
4742 char endc
= replacement
[strlen (replacement
) - 1];
4744 /* Clean up the replacement; we'd prefer to have this done by the
4745 standard preprocessing equipment (maybe do_scrub_chars?)
4746 but for now, do a quick-and-dirty. */
4747 if (comment
!= NULL
)
4754 comment
= replacement
+ strlen (replacement
) - 1;
4756 /* Trim trailing whitespace. */
4757 while (ISSPACE (*comment
))
4764 /* Compact leading whitespace. */
4765 while (ISSPACE (tmp
[0]) && ISSPACE (tmp
[1]))
4768 input_line_pointer
= endp
;
4769 input_scrub_insert_line (tmp
);
4772 /* Keep track of whether we've done a substitution. */
4773 substitution_line
= 1;
4779 substitution_line
= 0;
4783 /* This is the guts of the machine-dependent assembler. STR points to a
4784 machine dependent instruction. This function is supposed to emit
4785 the frags/bytes it assembles to. */
4787 md_assemble (char *line
)
4789 static int repeat_slot
= 0;
4790 static int delay_slots
= 0; /* How many delay slots left to fill? */
4791 static int is_parallel
= 0;
4792 static tic54x_insn insn
;
4794 char *savedp
= input_line_pointer
;
4797 input_line_pointer
= line
;
4798 c
= get_symbol_name (&line
);
4802 if (address_mode_needs_set
)
4804 set_address_mode (amode
);
4805 address_mode_needs_set
= 0;
4818 strcpy (insn
.parmnemonic
, line
);
4819 lptr
= input_line_pointer
;
4821 input_line_pointer
= savedp
;
4823 if (tic54x_parse_parallel_insn_lastline (&insn
, lptr
))
4825 int words
= build_insn (&insn
);
4827 if (delay_slots
!= 0)
4829 if (words
> delay_slots
)
4831 as_bad (ngettext ("Instruction does not fit in available "
4832 "delay slots (%d-word insn, %d slot left)",
4833 "Instruction does not fit in available "
4834 "delay slots (%d-word insn, %d slots left)",
4836 words
, delay_slots
);
4840 delay_slots
-= words
;
4846 memset (&insn
, 0, sizeof (insn
));
4847 strcpy (insn
.mnemonic
, line
);
4848 lptr
= input_line_pointer
;
4850 input_line_pointer
= savedp
;
4852 /* See if this line is part of a parallel instruction; if so, either this
4853 line or the next line will have the "||" specifier preceding the
4854 mnemonic, and we look for it in the parallel insn hash table. */
4855 if (strstr (line
, "||") != NULL
|| parallel_on_next_line_hint
)
4857 char *tmp
= strstr (line
, "||");
4861 if (tic54x_parse_parallel_insn_firstline (&insn
, lptr
))
4864 /* If the parallel part is on the same line, process it now,
4865 otherwise let the assembler pick up the next line for us. */
4868 while (ISSPACE (tmp
[2]))
4870 md_assemble (tmp
+ 2);
4875 as_bad (_("Unrecognized parallel instruction '%s'"), line
);
4880 if (tic54x_parse_insn (&insn
, lptr
))
4884 if ((insn
.tm
->flags
& FL_LP
)
4885 && cpu
!= V545LP
&& cpu
!= V546LP
)
4887 as_bad (_("Instruction '%s' requires an LP cpu version"),
4891 if ((insn
.tm
->flags
& FL_FAR
)
4892 && amode
!= far_mode
)
4894 as_bad (_("Instruction '%s' requires far mode addressing"),
4899 words
= build_insn (&insn
);
4901 /* Is this instruction in a delay slot? */
4904 if (words
> delay_slots
)
4906 as_warn (ngettext ("Instruction does not fit in available "
4907 "delay slots (%d-word insn, %d slot left). "
4908 "Resulting behavior is undefined.",
4909 "Instruction does not fit in available "
4910 "delay slots (%d-word insn, %d slots left). "
4911 "Resulting behavior is undefined.",
4913 words
, delay_slots
);
4917 /* Branches in delay slots are not allowed. */
4918 if (insn
.tm
->flags
& FL_BMASK
)
4920 as_warn (_("Instructions which cause PC discontinuity are not "
4921 "allowed in a delay slot. "
4922 "Resulting behavior is undefined."));
4924 delay_slots
-= words
;
4927 /* Is this instruction the target of a repeat? */
4930 if (insn
.tm
->flags
& FL_NR
)
4931 as_warn (_("'%s' is not repeatable. "
4932 "Resulting behavior is undefined."),
4934 else if (insn
.is_lkaddr
)
4935 as_warn (_("Instructions using long offset modifiers or absolute "
4936 "addresses are not repeatable. "
4937 "Resulting behavior is undefined."));
4941 /* Make sure we check the target of a repeat instruction. */
4942 if (insn
.tm
->flags
& B_REPEAT
)
4945 /* FIXME -- warn if repeat_slot == 1 at EOF. */
4947 /* Make sure we check our delay slots for validity. */
4948 if (insn
.tm
->flags
& FL_DELAY
)
4951 /* FIXME -- warn if delay_slots != 0 at EOF. */
4956 /* Do a final adjustment on the symbol table; in this case, make sure we have
4957 a ".file" symbol. */
4960 tic54x_adjust_symtab (void)
4962 if (symbol_rootP
== NULL
4963 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
4966 const char * filename
= as_where (&lineno
);
4967 c_dot_file_symbol (filename
, 0);
4971 /* In order to get gas to ignore any | chars at the start of a line,
4972 this function returns true if a | is found in a line.
4973 This lets us process parallel instructions, which span two lines. */
4976 tic54x_unrecognized_line (int c
)
4978 return c
== PARALLEL_SEPARATOR
;
4981 /* Watch for local labels of the form $[0-9] and [_a-zA-Z][_a-zA-Z0-9]*?
4982 Encode their names so that only we see them and can map them to the
4984 FIXME -- obviously this isn't done yet. These locals still show up in the
4987 tic54x_define_label (symbolS
*sym
)
4989 /* Just in case we need this later; note that this is not necessarily the
4990 same thing as line_label...
4991 When aligning or assigning labels to fields, sometimes the label is
4992 assigned other than the address at which the label appears.
4993 FIXME -- is this really needed? I think all the proper label assignment
4994 is done in tic54x_cons. */
4995 last_label_seen
= sym
;
4998 /* Try to parse something that normal parsing failed at. */
5001 tic54x_undefined_symbol (char *name
)
5005 /* Not sure how to handle predefined symbols. */
5006 if ((sym
= (tic54x_symbol
*) str_hash_find (cc_hash
, name
)) != NULL
5007 || (sym
= (tic54x_symbol
*) str_hash_find (cc2_hash
, name
)) != NULL
5008 || (sym
= (tic54x_symbol
*) str_hash_find (cc3_hash
, name
)) != NULL
5009 || (sym
= (tic54x_symbol
*) str_hash_find (misc_symbol_hash
,
5011 || (sym
= (tic54x_symbol
*) str_hash_find (sbit_hash
, name
)) != NULL
)
5013 return symbol_new (name
, reg_section
, &zero_address_frag
, sym
->value
);
5016 if ((sym
= (tic54x_symbol
*) str_hash_find (reg_hash
, name
)) != NULL
5017 || (sym
= (tic54x_symbol
*) str_hash_find (mmreg_hash
, name
)) != NULL
5018 || !strcasecmp (name
, "a")
5019 || !strcasecmp (name
, "b"))
5021 return symbol_new (name
, reg_section
, &zero_address_frag
,
5022 sym
? sym
->value
: 0);
5028 /* Parse a name in an expression before the expression parser takes a stab at
5032 tic54x_parse_name (char *name ATTRIBUTE_UNUSED
,
5033 expressionS
*expn ATTRIBUTE_UNUSED
)
5039 md_atof (int type
, char *literalP
, int *sizeP
)
5041 /* Target data is little-endian, but floats are stored
5042 big-"word"ian. ugh. */
5043 return ieee_md_atof (type
, literalP
, sizeP
, TRUE
);
5047 tc_gen_reloc (asection
*section
, fixS
*fixP
)
5050 bfd_reloc_code_real_type code
= fixP
->fx_r_type
;
5051 asymbol
*sym
= symbol_get_bfdsym (fixP
->fx_addsy
);
5053 rel
= XNEW (arelent
);
5054 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
5055 *rel
->sym_ptr_ptr
= sym
;
5056 /* We assume that all rel->address are host byte offsets. */
5057 rel
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5058 rel
->address
/= OCTETS_PER_BYTE
;
5059 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
5060 if (!strcmp (sym
->name
, section
->name
))
5061 rel
->howto
+= HOWTO_BANK
;
5065 const char *name
= S_GET_NAME (fixP
->fx_addsy
);
5068 as_fatal ("Cannot generate relocation type for symbol %s, code %s",
5069 name
, bfd_get_reloc_code_name (code
));
5075 /* Handle cons expressions. */
5078 tic54x_cons_fix_new (fragS
*frag
, int where
, int octets
, expressionS
*expn
,
5079 bfd_reloc_code_real_type r
)
5084 as_bad (_("Unsupported relocation size %d"), octets
);
5085 r
= BFD_RELOC_TIC54X_16_OF_23
;
5088 r
= BFD_RELOC_TIC54X_16_OF_23
;
5091 /* TI assembler always uses this, regardless of addressing mode. */
5093 r
= BFD_RELOC_TIC54X_23
;
5095 /* We never want to directly generate this; this is provided for
5096 stabs support only. */
5100 fix_new_exp (frag
, where
, octets
, expn
, 0, r
);
5103 /* Attempt to simplify or even eliminate a fixup.
5104 To indicate that a fixup has been eliminated, set fixP->fx_done.
5106 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry. */
5109 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
5111 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
5112 valueT val
= * valP
;
5114 switch (fixP
->fx_r_type
)
5117 as_fatal ("Bad relocation type: 0x%02x", fixP
->fx_r_type
);
5119 case BFD_RELOC_TIC54X_MS7_OF_23
:
5120 val
= (val
>> 16) & 0x7F;
5122 case BFD_RELOC_TIC54X_16_OF_23
:
5124 bfd_put_16 (stdoutput
, val
, buf
);
5125 /* Indicate what we're actually writing, so that we don't get warnings
5126 about exceeding available space. */
5127 *valP
= val
& 0xFFFF;
5129 case BFD_RELOC_TIC54X_PARTLS7
:
5130 bfd_put_16 (stdoutput
,
5131 (bfd_get_16 (stdoutput
, buf
) & 0xFF80) | (val
& 0x7F),
5133 /* Indicate what we're actually writing, so that we don't get warnings
5134 about exceeding available space. */
5137 case BFD_RELOC_TIC54X_PARTMS9
:
5138 /* TI assembler doesn't shift its encoding for relocatable files, and is
5139 thus incompatible with this implementation's relocatable files. */
5140 bfd_put_16 (stdoutput
,
5141 (bfd_get_16 (stdoutput
, buf
) & 0xFE00) | (val
>> 7),
5145 case BFD_RELOC_TIC54X_23
:
5146 bfd_put_32 (stdoutput
,
5147 (bfd_get_32 (stdoutput
, buf
) & 0xFF800000) | val
,
5152 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
5156 /* This is our chance to record section alignment
5157 don't need to do anything here, since BFD does the proper encoding. */
5160 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT section_size
)
5162 return section_size
;
5166 md_pcrel_from (fixS
*fixP ATTRIBUTE_UNUSED
)
5171 /* Mostly little-endian, but longwords (4 octets) get MS word stored
5175 tic54x_number_to_chars (char *buf
, valueT val
, int n
)
5178 number_to_chars_littleendian (buf
, val
, n
);
5181 number_to_chars_littleendian (buf
, val
>> 16 , 2);
5182 number_to_chars_littleendian (buf
+ 2, val
& 0xFFFF, 2);
5187 tic54x_estimate_size_before_relax (fragS
*frag ATTRIBUTE_UNUSED
,
5188 segT seg ATTRIBUTE_UNUSED
)
5193 /* We use this to handle bit allocations which we couldn't handle before due
5194 to symbols being in different frags. return number of octets added. */
5197 tic54x_relax_frag (fragS
*frag
, long stretch ATTRIBUTE_UNUSED
)
5199 symbolS
*sym
= frag
->fr_symbol
;
5205 struct bit_info
*bi
= (struct bit_info
*) frag
->fr_opcode
;
5206 int bit_offset
= frag_bit_offset (frag_prev (frag
, bi
->seg
), bi
->seg
);
5207 int size
= S_GET_VALUE (sym
);
5208 fragS
*prev_frag
= bit_offset_frag (frag_prev (frag
, bi
->seg
), bi
->seg
);
5209 int available
= 16 - bit_offset
;
5211 if (symbol_get_frag (sym
) != &zero_address_frag
5212 || S_IS_COMMON (sym
)
5213 || !S_IS_DEFINED (sym
))
5214 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5215 _("non-absolute value used with .space/.bes"));
5219 as_warn (_("negative value ignored in %s"),
5220 bi
->type
== TYPE_SPACE
? ".space" :
5221 bi
->type
== TYPE_BES
? ".bes" : ".field");
5223 frag
->tc_frag_data
= frag
->fr_fix
= 0;
5227 if (bi
->type
== TYPE_FIELD
)
5229 /* Bit fields of 16 or larger will have already been handled. */
5230 if (bit_offset
!= 0 && available
>= size
)
5232 char *p
= prev_frag
->fr_literal
;
5234 valueT value
= bi
->value
;
5235 value
<<= available
- size
;
5236 value
|= ((unsigned short) p
[1] << 8) | p
[0];
5237 md_number_to_chars (p
, value
, 2);
5238 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5239 prev_frag
->tc_frag_data
= 0;
5241 symbol_set_frag (bi
->sym
, prev_frag
);
5242 /* This frag is no longer used. */
5243 growth
= -frag
->fr_fix
;
5245 frag
->tc_frag_data
= 0;
5249 char *p
= frag
->fr_literal
;
5251 valueT value
= bi
->value
<< (16 - size
);
5252 md_number_to_chars (p
, value
, 2);
5253 if ((frag
->tc_frag_data
= size
) == 16)
5254 frag
->tc_frag_data
= 0;
5260 if (bit_offset
!= 0 && bit_offset
< 16)
5262 if (available
>= size
)
5264 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5265 prev_frag
->tc_frag_data
= 0;
5267 symbol_set_frag (bi
->sym
, prev_frag
);
5268 /* This frag is no longer used. */
5269 growth
= -frag
->fr_fix
;
5271 frag
->tc_frag_data
= 0;
5274 if (bi
->type
== TYPE_SPACE
&& bi
->sym
)
5275 symbol_set_frag (bi
->sym
, prev_frag
);
5278 growth
= (size
+ 15) / 16 * OCTETS_PER_BYTE
- frag
->fr_fix
;
5279 for (i
= 0; i
< growth
; i
++)
5280 frag
->fr_literal
[i
] = 0;
5281 frag
->fr_fix
= growth
;
5282 frag
->tc_frag_data
= size
% 16;
5283 /* Make sure any BES label points to the LAST word allocated. */
5284 if (bi
->type
== TYPE_BES
&& bi
->sym
)
5285 S_SET_VALUE (bi
->sym
, frag
->fr_fix
/ OCTETS_PER_BYTE
- 1);
5288 frag
->fr_symbol
= 0;
5289 frag
->fr_opcode
= 0;
5296 tic54x_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5297 segT seg ATTRIBUTE_UNUSED
,
5300 /* Offset is in bytes. */
5301 frag
->fr_offset
= (frag
->fr_next
->fr_address
5303 - frag
->fr_fix
) / frag
->fr_var
;
5304 if (frag
->fr_offset
< 0)
5306 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5307 _("attempt to .space/.bes backwards? (%ld)"),
5308 (long) frag
->fr_offset
);
5310 frag
->fr_type
= rs_space
;
5313 /* We need to avoid having labels defined for certain directives/pseudo-ops
5314 since once the label is defined, it's in the symbol table for good. TI
5315 syntax puts the symbol *before* the pseudo (which is kinda like MRI syntax,
5316 I guess, except I've never seen a definition of MRI syntax).
5318 Don't allow labels to start with '.' */
5321 tic54x_start_label (char * label_start
, int nul_char
, int next_char
)
5325 /* If within .struct/.union, no auto line labels, please. */
5326 if (current_stag
!= NULL
)
5329 /* Disallow labels starting with "." */
5330 if (next_char
!= ':')
5332 if (*label_start
== '.')
5334 as_bad (_("Invalid label '%s'"), label_start
);
5339 if (is_end_of_line
[(unsigned char) next_char
])
5342 rest
= input_line_pointer
;
5343 if (nul_char
== '"')
5345 while (ISSPACE (next_char
))
5346 next_char
= *++rest
;
5347 if (next_char
!= '.')
5350 /* Don't let colon () define a label for any of these... */
5351 return ((strncasecmp (rest
, ".tag", 4) != 0 || !ISSPACE (rest
[4]))
5352 && (strncasecmp (rest
, ".struct", 7) != 0 || !ISSPACE (rest
[7]))
5353 && (strncasecmp (rest
, ".union", 6) != 0 || !ISSPACE (rest
[6]))
5354 && (strncasecmp (rest
, ".macro", 6) != 0 || !ISSPACE (rest
[6]))
5355 && (strncasecmp (rest
, ".set", 4) != 0 || !ISSPACE (rest
[4]))
5356 && (strncasecmp (rest
, ".equ", 4) != 0 || !ISSPACE (rest
[4])));