1 /* tc-tic54x.c -- Assembly code for the Texas Instruments TMS320C54X
2 Copyright (C) 1999-2022 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
);
554 char *freename
= name
;
559 sym
= symbol_new (name
, absolute_section
, &zero_address_frag
,
560 (field
->stag
? field
->offset
561 : base_offset
+ field
->offset
));
563 symbol_table_insert (sym
);
569 replacement
= concat (S_GET_NAME (rootsym
), "+", root_stag_name
,
570 name
+ strlen (S_GET_NAME (rootsym
)), NULL
);
571 str_hash_insert (subsym_hash
[0], name
, replacement
, 0);
575 /* Recurse if the field is a structure.
576 Note the field offset is relative to the outermost struct. */
577 if (field
->stag
!= NULL
)
578 stag_add_field_symbols (field
->stag
, name
,
580 rootsym
, root_stag_name
);
587 /* Keep track of stag fields so that when structures are nested we can add the
588 complete dereferencing symbols to the symbol table. */
591 stag_add_field (struct stag
*parent
,
596 struct stag_field
*sfield
= XCNEW (struct stag_field
);
598 sfield
->name
= xstrdup (name
);
599 sfield
->offset
= offset
;
600 sfield
->bitfield_offset
= parent
->current_bitfield_offset
;
602 if (parent
->field
== NULL
)
603 parent
->field
= sfield
;
606 struct stag_field
*sf
= parent
->field
;
607 while (sf
->next
!= NULL
)
611 /* Only create a symbol for this field if the parent has no name. */
612 if (startswith (parent
->name
, ".fake"))
614 symbolS
*sym
= symbol_new (name
, absolute_section
, &zero_address_frag
,
617 symbol_table_insert (sym
);
621 /* [STAG] .struct [OFFSET]
622 Start defining structure offsets (symbols in absolute section). */
625 tic54x_struct (int arg
)
627 int start_offset
= 0;
632 /* Starting a new struct, switch to absolute section. */
633 stag_saved_seg
= now_seg
;
634 stag_saved_subseg
= now_subseg
;
635 subseg_set (absolute_section
, 0);
637 /* Align the current pointer. */
638 else if (current_stag
->current_bitfield_offset
!= 0)
640 ++abs_section_offset
;
641 current_stag
->current_bitfield_offset
= 0;
644 /* Offset expression is only meaningful for global .structs. */
647 /* Offset is ignored in inner structs. */
649 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
650 start_offset
= get_absolute_expression ();
657 /* Nesting, link to outer one. */
658 current_stag
->inner
= XCNEW (struct stag
);
659 current_stag
->inner
->outer
= current_stag
;
660 current_stag
= current_stag
->inner
;
662 as_warn (_("Offset on nested structures is ignored"));
663 start_offset
= abs_section_offset
;
667 current_stag
= XCNEW (struct stag
);
668 abs_section_offset
= start_offset
;
670 current_stag
->is_union
= is_union
;
672 if (line_label
== NULL
)
674 static int struct_count
= 0;
675 char fake
[] = ".fake_stagNNNNNNN";
676 sprintf (fake
, ".fake_stag%d", struct_count
++);
677 current_stag
->sym
= symbol_new (fake
, absolute_section
,
683 char * label
= xstrdup (S_GET_NAME (line_label
));
684 current_stag
->sym
= symbol_new (label
,
690 current_stag
->name
= S_GET_NAME (current_stag
->sym
);
691 SF_SET_LOCAL (current_stag
->sym
);
692 /* Nested .structs don't go into the symbol table. */
693 if (current_stag
->outer
== NULL
)
694 symbol_table_insert (current_stag
->sym
);
699 /* [LABEL] .endstruct
700 finish defining structure offsets; optional LABEL's value will be the size
704 tic54x_endstruct (int is_union
)
708 startswith (current_stag
->name
, ".fake") ? "" : current_stag
->name
;
710 if (!current_stag
|| current_stag
->is_union
!= is_union
)
712 as_bad (_(".end%s without preceding .%s"),
713 is_union
? "union" : "struct",
714 is_union
? "union" : "struct");
715 ignore_rest_of_line ();
719 /* Align end of structures. */
720 if (current_stag
->current_bitfield_offset
)
722 ++abs_section_offset
;
723 current_stag
->current_bitfield_offset
= 0;
726 if (current_stag
->is_union
)
727 size
= current_stag
->size
;
729 size
= abs_section_offset
- S_GET_VALUE (current_stag
->sym
);
730 if (line_label
!= NULL
)
732 S_SET_VALUE (line_label
, size
);
733 symbol_table_insert (line_label
);
737 /* Union size has already been calculated. */
738 if (!current_stag
->is_union
)
739 current_stag
->size
= size
;
740 /* Nested .structs don't get put in the stag table. */
741 if (current_stag
->outer
== NULL
)
743 str_hash_insert (stag_hash
, current_stag
->name
, current_stag
, 0);
744 stag_add_field_symbols (current_stag
, path
,
745 S_GET_VALUE (current_stag
->sym
),
748 current_stag
= current_stag
->outer
;
750 /* If this is a nested .struct/.union, add it as a field to the enclosing
751 one. otherwise, restore the section we were in. */
752 if (current_stag
!= NULL
)
754 stag_add_field (current_stag
, current_stag
->inner
->name
,
755 S_GET_VALUE (current_stag
->inner
->sym
),
756 current_stag
->inner
);
759 subseg_set (stag_saved_seg
, stag_saved_subseg
);
763 Reference a structure within a structure, as a sized field with an optional
765 If used outside of a .struct/.endstruct, overlays the given structure
766 format on the existing allocated space. */
769 tic54x_tag (int ignore ATTRIBUTE_UNUSED
)
772 int c
= get_symbol_name (&name
);
773 struct stag
*stag
= (struct stag
*) str_hash_find (stag_hash
, name
);
778 as_bad (_("Unrecognized struct/union tag '%s'"), name
);
780 as_bad (_(".tag requires a structure tag"));
781 ignore_rest_of_line ();
784 if (line_label
== NULL
)
786 as_bad (_("Label required for .tag"));
787 ignore_rest_of_line ();
794 label
= xstrdup (S_GET_NAME (line_label
));
795 if (current_stag
!= NULL
)
796 stag_add_field (current_stag
, label
,
797 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
801 symbolS
*sym
= symbol_find (label
);
805 as_bad (_(".tag target '%s' undefined"), label
);
806 ignore_rest_of_line ();
810 stag_add_field_symbols (stag
, S_GET_NAME (sym
),
811 S_GET_VALUE (stag
->sym
), sym
, stag
->name
);
816 /* Bump by the struct size, but only if we're within a .struct section. */
817 if (current_stag
!= NULL
&& !current_stag
->is_union
)
818 abs_section_offset
+= stag
->size
;
820 (void) restore_line_pointer (c
);
821 demand_empty_rest_of_line ();
825 /* Handle all .byte, .char, .double, .field, .float, .half, .int, .long,
826 .short, .string, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword,
830 tic54x_struct_field (int type
)
834 int new_bitfield_offset
= 0;
835 int field_align
= current_stag
->current_bitfield_offset
!= 0;
836 int longword_align
= 0;
839 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
840 count
= get_absolute_expression ();
856 case '*': /* String. */
865 case '.': /* Bitfield. */
867 if (count
< 1 || count
> 32)
869 as_bad (_(".field count '%d' out of range (1 <= X <= 32)"), count
);
870 ignore_rest_of_line ();
873 if (current_stag
->current_bitfield_offset
+ count
> 16)
875 /* Set the appropriate size and new field offset. */
885 new_bitfield_offset
= count
- 16;
888 new_bitfield_offset
= count
;
893 new_bitfield_offset
= current_stag
->current_bitfield_offset
+ count
;
897 as_bad (_("Unrecognized field type '%c'"), type
);
898 ignore_rest_of_line ();
904 /* Align to the actual starting position of the field. */
905 current_stag
->current_bitfield_offset
= 0;
906 ++abs_section_offset
;
908 /* Align to longword boundary. */
909 if (longword_align
&& (abs_section_offset
& 0x1))
910 ++abs_section_offset
;
912 if (line_label
== NULL
)
914 static int fieldno
= 0;
915 char fake
[] = ".fake_fieldNNNNN";
917 sprintf (fake
, ".fake_field%d", fieldno
++);
918 stag_add_field (current_stag
, fake
,
919 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
926 label
= xstrdup (S_GET_NAME (line_label
));
927 stag_add_field (current_stag
, label
,
928 abs_section_offset
- S_GET_VALUE (current_stag
->sym
),
933 if (current_stag
->is_union
)
935 /* Note we treat the element as if it were an array of COUNT. */
936 if (current_stag
->size
< (unsigned) size
* count
)
937 current_stag
->size
= size
* count
;
941 abs_section_offset
+= (unsigned) size
* count
;
942 current_stag
->current_bitfield_offset
= new_bitfield_offset
;
947 /* Handle .byte, .word. .int, .long and all variants. */
950 tic54x_cons (int type
)
955 /* If we're within a .struct construct, don't actually allocate space. */
956 if (current_stag
!= NULL
)
958 tic54x_struct_field (type
);
962 #ifdef md_flush_pending_output
963 md_flush_pending_output ();
966 generate_lineno_debug ();
968 /* Align long words to long word boundaries (4 octets). */
969 if (type
== 'l' || type
== 'L')
971 frag_align (2, 0, 2);
972 /* If there's a label, assign it to the first allocated word. */
973 if (line_label
!= NULL
)
975 symbol_set_frag (line_label
, frag_now
);
976 S_SET_VALUE (line_label
, frag_now_fix ());
1000 if (*input_line_pointer
== '"')
1002 input_line_pointer
++;
1003 while (is_a_char (c
= next_char_of_string ()))
1004 tic54x_emit_char (c
);
1005 know (input_line_pointer
[-1] == '\"');
1011 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1012 if (expn
.X_op
== O_constant
)
1014 offsetT value
= expn
.X_add_number
;
1015 /* Truncate overflows. */
1019 if ((value
> 0 && value
> 0xFF)
1020 || (value
< 0 && value
< - 0x100))
1021 as_warn (_("Overflow in expression, truncated to 8 bits"));
1024 if ((value
> 0 && value
> 0xFFFF)
1025 || (value
< 0 && value
< - 0x10000))
1026 as_warn (_("Overflow in expression, truncated to 16 bits"));
1030 if (expn
.X_op
!= O_constant
&& octets
< 2)
1032 /* Disallow .byte with a non constant expression that will
1033 require relocation. */
1034 as_bad (_("Relocatable values require at least WORD storage"));
1035 ignore_rest_of_line ();
1039 if (expn
.X_op
!= O_constant
1043 /* FIXME -- at one point TI tools used to output REL16
1044 relocations, but I don't think the latest tools do at all
1045 The current tools output extended relocations regardless of
1046 the addressing mode (I actually think that ".c_mode" is
1047 totally ignored in the latest tools). */
1050 emit_expr (&expn
, 4);
1056 emitting_long
= octets
== 4;
1057 emit_expr (&expn
, (octets
== 1) ? 2 : octets
);
1062 while (*input_line_pointer
++ == ',');
1064 input_line_pointer
--; /* Put terminator back into stream. */
1065 demand_empty_rest_of_line ();
1068 /* .global <symbol>[,...,<symbolN>]
1069 .def <symbol>[,...,<symbolN>]
1070 .ref <symbol>[,...,<symbolN>]
1072 These all identify global symbols.
1074 .def means the symbol is defined in the current module and can be accessed
1075 by other files. The symbol should be placed in the symbol table.
1077 .ref means the symbol is used in the current module but defined in another
1078 module. The linker is to resolve this symbol's definition at link time.
1080 .global should act as a .ref or .def, as needed.
1082 global, def and ref all have symbol storage classes of C_EXT.
1084 I can't identify any difference in how the "other" c54x assembler treats
1085 these, so we ignore the type here. */
1088 tic54x_global (int type
)
1095 as_warn (_("Use of .def/.ref is deprecated. Use .global instead"));
1097 ILLEGAL_WITHIN_STRUCT ();
1101 c
= get_symbol_name (&name
);
1102 symbolP
= symbol_find_or_make (name
);
1103 c
= restore_line_pointer (c
);
1105 S_SET_STORAGE_CLASS (symbolP
, C_EXT
);
1108 input_line_pointer
++;
1109 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1110 c
= *input_line_pointer
;
1115 demand_empty_rest_of_line ();
1118 /* Remove the symbol from the local label hash lookup. */
1121 tic54x_remove_local_label (void **slot
, void *arg ATTRIBUTE_UNUSED
)
1123 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
1124 void *elem
= str_hash_find (local_label_hash
[macro_level
], tuple
->key
);
1125 str_hash_delete (local_label_hash
[macro_level
], tuple
->key
);
1130 /* Reset all local labels. */
1133 tic54x_clear_local_labels (int ignored ATTRIBUTE_UNUSED
)
1135 htab_traverse (local_label_hash
[macro_level
], tic54x_remove_local_label
, NULL
);
1140 .sect "section name"
1143 make sure local labels get cleared when changing sections
1145 ARG is 't' for text, 'd' for data, or '*' for a named section
1147 For compatibility, '*' sections are SEC_CODE if instructions are
1148 encountered, or SEC_DATA if not.
1152 tic54x_sect (int arg
)
1154 ILLEGAL_WITHIN_STRUCT ();
1156 /* Local labels are cleared when changing sections. */
1157 tic54x_clear_local_labels (0);
1161 else if (arg
== 'd')
1167 /* Make sure all named initialized sections flagged properly. If we
1168 encounter instructions, we'll flag it with SEC_CODE as well. */
1169 const char *flags
= ",\"w\"\n";
1171 /* If there are quotes, remove them. */
1172 if (*input_line_pointer
== '"')
1174 name
= demand_copy_C_string (&len
);
1175 demand_empty_rest_of_line ();
1176 name
= concat (name
, flags
, (char *) NULL
);
1182 c
= get_symbol_name (&name
);
1183 name
= concat (name
, flags
, (char *) NULL
);
1184 (void) restore_line_pointer (c
);
1185 demand_empty_rest_of_line ();
1188 input_scrub_insert_line (name
);
1189 obj_coff_section (0);
1191 /* If there was a line label, make sure that it gets assigned the proper
1192 section. This is for compatibility, even though the actual behavior
1193 is not explicitly defined. For consistency, we make .sect behave
1194 like .usect, since that is probably what people expect. */
1195 if (line_label
!= NULL
)
1197 S_SET_SEGMENT (line_label
, now_seg
);
1198 symbol_set_frag (line_label
, frag_now
);
1199 S_SET_VALUE (line_label
, frag_now_fix ());
1200 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1201 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1206 /* [symbol] .space space_in_bits
1207 [symbol] .bes space_in_bits
1208 BES puts the symbol at the *last* word allocated
1210 cribbed from s_space. */
1213 tic54x_space (int arg
)
1219 int bits_per_byte
= (OCTETS_PER_BYTE
* 8);
1221 symbolS
*label
= line_label
;
1224 ILLEGAL_WITHIN_STRUCT ();
1226 #ifdef md_flush_pending_output
1227 md_flush_pending_output ();
1230 /* Read the bit count. */
1233 /* Some expressions are unresolvable until later in the assembly pass;
1234 postpone until relaxation/fixup. we also have to postpone if a previous
1235 partial allocation has not been completed yet. */
1236 if (expn
.X_op
!= O_constant
|| frag_bit_offset (frag_now
, now_seg
) == -1)
1238 struct bit_info
*bi
= XNEW (struct bit_info
);
1243 p
= frag_var (rs_machine_dependent
,
1244 65536 * 2, 1, (relax_substateT
) 0,
1245 make_expr_symbol (&expn
), (offsetT
) 0,
1253 /* Reduce the required size by any bit offsets currently left over
1254 from a previous .space/.bes/.field directive. */
1255 bit_offset
= frag_now
->tc_frag_data
;
1256 if (bit_offset
!= 0 && bit_offset
< 16)
1258 int spare_bits
= bits_per_byte
- bit_offset
;
1260 if (spare_bits
>= expn
.X_add_number
)
1262 /* Don't have to do anything; sufficient bits have already been
1263 allocated; just point the label to the right place. */
1266 symbol_set_frag (label
, frag_now
);
1267 S_SET_VALUE (label
, frag_now_fix () - 1);
1270 frag_now
->tc_frag_data
+= expn
.X_add_number
;
1273 expn
.X_add_number
-= spare_bits
;
1274 /* Set the label to point to the first word allocated, which in this
1275 case is the previous word, which was only partially filled. */
1276 if (!bes
&& label
!= NULL
)
1278 symbol_set_frag (label
, frag_now
);
1279 S_SET_VALUE (label
, frag_now_fix () - 1);
1283 /* Convert bits to bytes/words and octets, rounding up. */
1284 words
= ((expn
.X_add_number
+ bits_per_byte
- 1) / bits_per_byte
);
1285 /* How many do we have left over? */
1286 bit_offset
= expn
.X_add_number
% bits_per_byte
;
1287 octets
= words
* OCTETS_PER_BYTE
;
1290 as_warn (_(".space/.bes repeat count is negative, ignored"));
1293 else if (octets
== 0)
1295 as_warn (_(".space/.bes repeat count is zero, ignored"));
1299 /* If we are in the absolute section, just bump the offset. */
1300 if (now_seg
== absolute_section
)
1302 abs_section_offset
+= words
;
1303 if (bes
&& label
!= NULL
)
1304 S_SET_VALUE (label
, abs_section_offset
- 1);
1305 frag_now
->tc_frag_data
= bit_offset
;
1310 p
= frag_var (rs_fill
, 1, 1,
1311 (relax_substateT
) 0, (symbolS
*) 0,
1312 (offsetT
) octets
, (char *) 0);
1314 /* Make note of how many bits of this word we've allocated so far. */
1315 frag_now
->tc_frag_data
= bit_offset
;
1317 /* .bes puts label at *last* word allocated. */
1318 if (bes
&& label
!= NULL
)
1320 symbol_set_frag (label
, frag_now
);
1321 S_SET_VALUE (label
, frag_now_fix () - 1);
1329 demand_empty_rest_of_line ();
1332 /* [symbol] .usect "section-name", size-in-words
1333 [, [blocking-flag] [, alignment-flag]]
1335 Uninitialized section.
1336 Non-zero blocking means that if the section would cross a page (128-word)
1337 boundary, it will be page-aligned.
1338 Non-zero alignment aligns on a longword boundary.
1340 Has no effect on the current section. */
1343 tic54x_usect (int x ATTRIBUTE_UNUSED
)
1350 int size
, blocking_flag
, alignment_flag
;
1352 subsegT current_subseg
;
1355 ILLEGAL_WITHIN_STRUCT ();
1357 current_seg
= now_seg
; /* Save current seg. */
1358 current_subseg
= now_subseg
; /* Save current subseg. */
1360 c
= get_symbol_name (§ion_name
); /* Get terminator. */
1361 name
= xstrdup (section_name
);
1362 c
= restore_line_pointer (c
);
1365 ++input_line_pointer
;
1368 as_bad (_("Missing size argument"));
1369 ignore_rest_of_line ();
1373 size
= get_absolute_expression ();
1375 /* Read a possibly present third argument (blocking flag). */
1376 if (*input_line_pointer
== ',')
1378 ++input_line_pointer
;
1379 if (*input_line_pointer
!= ',')
1380 blocking_flag
= get_absolute_expression ();
1384 /* Read a possibly present fourth argument (alignment flag). */
1385 if (*input_line_pointer
== ',')
1387 ++input_line_pointer
;
1388 alignment_flag
= get_absolute_expression ();
1394 blocking_flag
= alignment_flag
= 0;
1396 seg
= subseg_new (name
, 0);
1397 flags
= bfd_section_flags (seg
) | SEC_ALLOC
;
1401 /* s_align eats end of line; restore it. */
1403 --input_line_pointer
;
1406 if (line_label
!= NULL
)
1408 S_SET_SEGMENT (line_label
, seg
);
1409 symbol_set_frag (line_label
, frag_now
);
1410 S_SET_VALUE (line_label
, frag_now_fix ());
1411 /* Set scl to label, since that's what TI does. */
1412 if (S_GET_STORAGE_CLASS (line_label
) != C_EXT
)
1413 S_SET_STORAGE_CLASS (line_label
, C_LABEL
);
1416 seg_info (seg
)->bss
= 1; /* Uninitialized data. */
1418 p
= frag_var (rs_fill
, 1, 1,
1419 (relax_substateT
) 0, (symbolS
*) line_label
,
1420 size
* OCTETS_PER_BYTE
, (char *) 0);
1424 flags
|= SEC_TIC54X_BLOCK
;
1426 if (!bfd_set_section_flags (seg
, flags
))
1427 as_warn (_("Error setting flags for \"%s\": %s"), name
,
1428 bfd_errmsg (bfd_get_error ()));
1430 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
1431 demand_empty_rest_of_line ();
1434 static enum cpu_version
1435 lookup_version (const char *ver
)
1437 enum cpu_version version
= VNONE
;
1439 if (ver
[0] == '5' && ver
[1] == '4')
1441 if (strlen (ver
) == 3
1442 && (ver
[2] == '1' || ver
[2] == '2' || ver
[2] == '3'
1443 || ver
[2] == '5' || ver
[2] == '8' || ver
[2] == '9'))
1444 version
= ver
[2] - '0';
1445 else if (strlen (ver
) == 5
1446 && TOUPPER (ver
[3]) == 'L'
1447 && TOUPPER (ver
[4]) == 'P'
1448 && (ver
[2] == '5' || ver
[2] == '6'))
1449 version
= ver
[2] - '0' + 10;
1456 set_cpu (enum cpu_version version
)
1459 if (version
== V545LP
|| version
== V546LP
)
1461 symbolS
*symbolP
= symbol_new ("__allow_lp", absolute_section
,
1462 &zero_address_frag
, 1);
1463 SF_SET_LOCAL (symbolP
);
1464 symbol_table_insert (symbolP
);
1468 /* .version cpu-version
1469 cpu-version may be one of the following:
1479 This is for compatibility only. It currently has no affect on assembly. */
1480 static int cpu_needs_set
= 1;
1483 tic54x_version (int x ATTRIBUTE_UNUSED
)
1485 enum cpu_version version
= VNONE
;
1486 enum cpu_version old_version
= cpu
;
1490 ILLEGAL_WITHIN_STRUCT ();
1493 ver
= input_line_pointer
;
1494 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1495 ++input_line_pointer
;
1496 c
= *input_line_pointer
;
1497 *input_line_pointer
= 0;
1499 version
= lookup_version (ver
);
1501 if (cpu
!= VNONE
&& cpu
!= version
)
1502 as_warn (_("CPU version has already been set"));
1504 if (version
== VNONE
)
1506 as_bad (_("Unrecognized version '%s'"), ver
);
1507 ignore_rest_of_line ();
1510 else if (assembly_begun
&& version
!= old_version
)
1512 as_bad (_("Changing of CPU version on the fly not supported"));
1513 ignore_rest_of_line ();
1519 *input_line_pointer
= c
;
1520 demand_empty_rest_of_line ();
1523 /* 'f' = float, 'x' = xfloat, 'd' = double, 'l' = ldouble. */
1526 tic54x_float_cons (int type
)
1528 if (current_stag
!= 0)
1529 tic54x_struct_field ('f');
1531 #ifdef md_flush_pending_output
1532 md_flush_pending_output ();
1535 /* Align to long word boundary (4 octets) unless it's ".xfloat". */
1538 frag_align (2, 0, 2);
1539 /* If there's a label, assign it to the first allocated word. */
1540 if (line_label
!= NULL
)
1542 symbol_set_frag (line_label
, frag_now
);
1543 S_SET_VALUE (line_label
, frag_now_fix ());
1550 /* The argument is capitalized if it should be zero-terminated
1551 's' is normal string with upper 8-bits zero-filled, 'p' is packed.
1552 Code copied from stringer, and slightly modified so that strings are packed
1553 and encoded into the correct octets. */
1556 tic54x_stringer (int type
)
1559 int append_zero
= type
== 'S' || type
== 'P';
1560 int packed
= type
== 'p' || type
== 'P';
1561 int last_char
= -1; /* Packed strings need two bytes at a time to encode. */
1563 if (current_stag
!= NULL
)
1565 tic54x_struct_field ('*');
1569 #ifdef md_flush_pending_output
1570 md_flush_pending_output ();
1573 c
= ','; /* Do loop. */
1577 switch (*input_line_pointer
)
1581 unsigned short value
= get_absolute_expression ();
1582 FRAG_APPEND_1_CHAR ( value
& 0xFF);
1583 FRAG_APPEND_1_CHAR ((value
>> 8) & 0xFF);
1587 ++input_line_pointer
; /* -> 1st char of string. */
1588 while (is_a_char (c
= next_char_of_string ()))
1592 FRAG_APPEND_1_CHAR (c
);
1593 FRAG_APPEND_1_CHAR (0);
1597 /* Packed strings are filled MS octet first. */
1598 if (last_char
== -1)
1602 FRAG_APPEND_1_CHAR (c
);
1603 FRAG_APPEND_1_CHAR (last_char
);
1610 if (packed
&& last_char
!= -1)
1612 FRAG_APPEND_1_CHAR (0);
1613 FRAG_APPEND_1_CHAR (last_char
);
1618 FRAG_APPEND_1_CHAR (0);
1619 FRAG_APPEND_1_CHAR (0);
1622 know (input_line_pointer
[-1] == '\"');
1626 c
= *input_line_pointer
;
1627 if (!is_end_of_line
[c
])
1628 ++input_line_pointer
;
1631 /* Finish up any leftover packed string. */
1632 if (packed
&& last_char
!= -1)
1634 FRAG_APPEND_1_CHAR (0);
1635 FRAG_APPEND_1_CHAR (last_char
);
1637 demand_empty_rest_of_line ();
1641 tic54x_p2align (int arg ATTRIBUTE_UNUSED
)
1643 as_bad (_("p2align not supported on this target"));
1647 tic54x_align_words (int arg
)
1649 /* Only ".align" with no argument is allowed within .struct/.union. */
1652 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1655 as_warn (_("Argument to .even ignored"));
1657 count
= get_absolute_expression ();
1660 if (current_stag
!= NULL
&& arg
== 128)
1662 if (current_stag
->current_bitfield_offset
!= 0)
1664 current_stag
->current_bitfield_offset
= 0;
1665 ++abs_section_offset
;
1667 demand_empty_rest_of_line ();
1671 ILLEGAL_WITHIN_STRUCT ();
1673 s_align_bytes (count
<< 1);
1676 /* Initialize multiple-bit fields within a single word of memory. */
1679 tic54x_field (int ignore ATTRIBUTE_UNUSED
)
1685 symbolS
*label
= line_label
;
1687 if (current_stag
!= NULL
)
1689 tic54x_struct_field ('.');
1693 input_line_pointer
= parse_expression (input_line_pointer
, &expn
);
1695 if (*input_line_pointer
== ',')
1697 ++input_line_pointer
;
1698 size
= get_absolute_expression ();
1699 if (size
< 1 || size
> 32)
1701 as_bad (_("Invalid field size, must be from 1 to 32"));
1702 ignore_rest_of_line ();
1707 /* Truncate values to the field width. */
1708 if (expn
.X_op
!= O_constant
)
1710 /* If the expression value is relocatable, the field size *must*
1714 as_bad (_("field size must be 16 when value is relocatable"));
1715 ignore_rest_of_line ();
1719 frag_now
->tc_frag_data
= 0;
1720 emit_expr (&expn
, 2);
1724 unsigned long fmask
= (size
== 32) ? 0xFFFFFFFF : (1ul << size
) - 1;
1726 value
= expn
.X_add_number
;
1727 expn
.X_add_number
&= fmask
;
1728 if (value
!= (valueT
) expn
.X_add_number
)
1729 as_warn (_("field value truncated"));
1730 value
= expn
.X_add_number
;
1731 /* Bits are stored MS first. */
1734 frag_now
->tc_frag_data
= 0;
1736 md_number_to_chars (p
, (value
>> (size
- 16)) & 0xFFFF, 2);
1741 int bit_offset
= frag_bit_offset (frag_now
, now_seg
);
1743 fragS
*alloc_frag
= bit_offset_frag (frag_now
, now_seg
);
1744 if (bit_offset
== -1)
1746 struct bit_info
*bi
= XNEW (struct bit_info
);
1747 /* We don't know the previous offset at this time, so store the
1748 info we need and figure it out later. */
1749 expressionS size_exp
;
1751 size_exp
.X_op
= O_constant
;
1752 size_exp
.X_add_number
= size
;
1754 bi
->type
= TYPE_FIELD
;
1756 p
= frag_var (rs_machine_dependent
,
1757 4, 1, (relax_substateT
) 0,
1758 make_expr_symbol (&size_exp
), (offsetT
) 0,
1762 else if (bit_offset
== 0 || bit_offset
+ size
> 16)
1764 /* Align a new field. */
1766 frag_now
->tc_frag_data
= 0;
1767 alloc_frag
= frag_now
;
1771 /* Put the new value entirely within the existing one. */
1772 p
= alloc_frag
== frag_now
?
1773 frag_now
->fr_literal
+ frag_now_fix_octets () - 2 :
1774 alloc_frag
->fr_literal
;
1777 symbol_set_frag (label
, alloc_frag
);
1778 if (alloc_frag
== frag_now
)
1779 S_SET_VALUE (label
, frag_now_fix () - 1);
1783 value
<<= 16 - alloc_frag
->tc_frag_data
- size
;
1785 /* OR in existing value. */
1786 if (alloc_frag
->tc_frag_data
)
1787 value
|= ((unsigned short) p
[1] << 8) | p
[0];
1788 md_number_to_chars (p
, value
, 2);
1789 alloc_frag
->tc_frag_data
+= size
;
1790 if (alloc_frag
->tc_frag_data
== 16)
1791 alloc_frag
->tc_frag_data
= 0;
1795 demand_empty_rest_of_line ();
1798 /* Ideally, we want to check SEC_LOAD and SEC_HAS_CONTENTS, but those aren't
1799 available yet. seg_info ()->bss is the next best thing. */
1802 tic54x_initialized_section (segT seg
)
1804 return !seg_info (seg
)->bss
;
1807 /* .clink ["section name"]
1809 Marks the section as conditionally linked (link only if contents are
1810 referenced elsewhere.
1811 Without a name, refers to the current initialized section.
1812 Name is required for uninitialized sections. */
1815 tic54x_clink (int ignored ATTRIBUTE_UNUSED
)
1819 ILLEGAL_WITHIN_STRUCT ();
1821 if (*input_line_pointer
== '\"')
1823 char *section_name
= ++input_line_pointer
;
1826 while (is_a_char (next_char_of_string ()))
1828 know (input_line_pointer
[-1] == '\"');
1829 input_line_pointer
[-1] = 0;
1830 name
= xstrdup (section_name
);
1832 seg
= bfd_get_section_by_name (stdoutput
, name
);
1835 as_bad (_("Unrecognized section '%s'"), section_name
);
1836 ignore_rest_of_line ();
1842 if (!tic54x_initialized_section (seg
))
1844 as_bad (_("Current section is uninitialized, "
1845 "section name required for .clink"));
1846 ignore_rest_of_line ();
1851 seg
->flags
|= SEC_TIC54X_CLINK
;
1853 demand_empty_rest_of_line ();
1856 /* Change the default include directory to be the current source file's
1857 directory, instead of the current working directory. If DOT is non-zero,
1858 set to "." instead. */
1861 tic54x_set_default_include (void)
1863 char *dir
, *tmp
= NULL
;
1864 const char *curfile
;
1867 curfile
= as_where (&lineno
);
1868 dir
= xstrdup (curfile
);
1869 tmp
= strrchr (dir
, '/');
1876 if (include_dir_count
== 0)
1878 include_dirs
= XNEWVEC (const char *, 1);
1879 include_dir_count
= 1;
1881 include_dirs
[0] = dir
;
1882 if (len
> include_dir_maxlen
)
1883 include_dir_maxlen
= len
;
1885 else if (include_dirs
!= NULL
)
1886 include_dirs
[0] = ".";
1889 /* .include "filename" | filename
1890 .copy "filename" | filename
1892 FIXME 'include' file should be omitted from any output listing,
1893 'copy' should be included in any output listing
1894 FIXME -- prevent any included files from changing listing (compat only)
1895 FIXME -- need to include source file directory in search path; what's a
1896 good way to do this?
1898 Entering/exiting included/copied file clears all local labels. */
1901 tic54x_include (int ignored ATTRIBUTE_UNUSED
)
1903 char newblock
[] = " .newblock\n";
1908 ILLEGAL_WITHIN_STRUCT ();
1912 if (*input_line_pointer
== '"')
1914 filename
= demand_copy_C_string (&len
);
1915 demand_empty_rest_of_line ();
1919 filename
= input_line_pointer
;
1920 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1921 ++input_line_pointer
;
1922 c
= *input_line_pointer
;
1923 *input_line_pointer
= '\0';
1924 filename
= xstrdup (filename
);
1925 *input_line_pointer
= c
;
1926 demand_empty_rest_of_line ();
1928 /* Insert a partial line with the filename (for the sake of s_include)
1930 The included file will be inserted before the newblock, so that the
1931 newblock is executed after the included file is processed. */
1932 input
= concat ("\"", filename
, "\"\n", newblock
, (char *) NULL
);
1933 input_scrub_insert_line (input
);
1935 tic54x_clear_local_labels (0);
1937 tic54x_set_default_include ();
1943 tic54x_message (int type
)
1949 ILLEGAL_WITHIN_STRUCT ();
1951 if (*input_line_pointer
== '"')
1952 msg
= demand_copy_C_string (&len
);
1955 msg
= input_line_pointer
;
1956 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1957 ++input_line_pointer
;
1958 c
= *input_line_pointer
;
1959 *input_line_pointer
= 0;
1960 msg
= xstrdup (msg
);
1961 *input_line_pointer
= c
;
1967 as_tsktsk ("%s", msg
);
1970 as_warn ("%s", msg
);
1977 demand_empty_rest_of_line ();
1981 Define a special symbol that refers to the loadtime address rather than the
1982 runtime address within the current section.
1984 This symbol gets a special storage class so that when it is resolved, it is
1985 resolved relative to the load address (lma) of the section rather than the
1986 run address (vma). */
1989 tic54x_label (int ignored ATTRIBUTE_UNUSED
)
1995 ILLEGAL_WITHIN_STRUCT ();
1997 c
= get_symbol_name (&name
);
1998 symbolP
= colon (name
);
1999 S_SET_STORAGE_CLASS (symbolP
, C_STATLAB
);
2001 (void) restore_line_pointer (c
);
2002 demand_empty_rest_of_line ();
2006 Install all memory-mapped register names into the symbol table as
2007 absolute local symbols. */
2010 tic54x_register_mmregs (int ignored ATTRIBUTE_UNUSED
)
2012 const tic54x_symbol
*sym
;
2014 ILLEGAL_WITHIN_STRUCT ();
2016 for (sym
= tic54x_mmregs
; sym
->name
; sym
++)
2018 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
2019 &zero_address_frag
, sym
->value
);
2020 SF_SET_LOCAL (symbolP
);
2021 symbol_table_insert (symbolP
);
2026 Count defaults to 1024. */
2029 tic54x_loop (int count
)
2031 ILLEGAL_WITHIN_STRUCT ();
2034 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2035 count
= get_absolute_expression ();
2037 do_repeat ((size_t) count
, "LOOP", "ENDLOOP", NULL
);
2040 /* Normally, endloop gets eaten by the preceding loop. */
2043 tic54x_endloop (int ignore ATTRIBUTE_UNUSED
)
2045 as_bad (_("ENDLOOP without corresponding LOOP"));
2046 ignore_rest_of_line ();
2049 /* .break [condition]. */
2052 tic54x_break (int ignore ATTRIBUTE_UNUSED
)
2056 ILLEGAL_WITHIN_STRUCT ();
2059 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2060 cond
= get_absolute_expression ();
2063 end_repeat (substitution_line
? 1 : 0);
2067 set_address_mode (int mode
)
2070 if (mode
== far_mode
)
2072 symbolS
*symbolP
= symbol_new ("__allow_far", absolute_section
,
2073 &zero_address_frag
, 1);
2074 SF_SET_LOCAL (symbolP
);
2075 symbol_table_insert (symbolP
);
2079 static int address_mode_needs_set
= 1;
2082 tic54x_address_mode (int mode
)
2084 if (assembly_begun
&& amode
!= (unsigned) mode
)
2086 as_bad (_("Mixing of normal and extended addressing not supported"));
2087 ignore_rest_of_line ();
2090 if (mode
== far_mode
&& cpu
!= VNONE
&& cpu
!= V548
&& cpu
!= V549
)
2092 as_bad (_("Extended addressing not supported on the specified CPU"));
2093 ignore_rest_of_line ();
2097 set_address_mode (mode
);
2098 demand_empty_rest_of_line ();
2101 /* .sblock "section"|section [,...,"section"|section]
2102 Designate initialized sections for blocking. */
2105 tic54x_sblock (int ignore ATTRIBUTE_UNUSED
)
2109 ILLEGAL_WITHIN_STRUCT ();
2116 if (*input_line_pointer
== '"')
2120 name
= demand_copy_C_string (&len
);
2126 c
= get_symbol_name (§ion_name
);
2127 name
= xstrdup (section_name
);
2128 (void) restore_line_pointer (c
);
2131 seg
= bfd_get_section_by_name (stdoutput
, name
);
2134 as_bad (_("Unrecognized section '%s'"), name
);
2135 ignore_rest_of_line ();
2138 else if (!tic54x_initialized_section (seg
))
2140 as_bad (_(".sblock may be used for initialized sections only"));
2141 ignore_rest_of_line ();
2144 seg
->flags
|= SEC_TIC54X_BLOCK
;
2146 c
= *input_line_pointer
;
2147 if (!is_end_of_line
[(unsigned char) c
])
2148 ++input_line_pointer
;
2151 demand_empty_rest_of_line ();
2154 /* symbol .set value
2157 value must be defined externals; no forward-referencing allowed
2158 symbols assigned with .set/.equ may not be redefined. */
2161 tic54x_set (int ignore ATTRIBUTE_UNUSED
)
2166 ILLEGAL_WITHIN_STRUCT ();
2170 as_bad (_("Symbol missing for .set/.equ"));
2171 ignore_rest_of_line ();
2174 name
= xstrdup (S_GET_NAME (line_label
));
2176 if ((symbolP
= symbol_find (name
)) == NULL
2177 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
2179 symbolP
= symbol_new (name
, absolute_section
, &zero_address_frag
, 0);
2180 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2183 S_SET_DATA_TYPE (symbolP
, T_INT
);
2184 S_SET_SEGMENT (symbolP
, absolute_section
);
2185 symbol_table_insert (symbolP
);
2186 pseudo_set (symbolP
);
2187 demand_empty_rest_of_line ();
2192 List false conditional blocks. */
2195 tic54x_fclist (int show
)
2198 listing
&= ~LISTING_NOCOND
;
2200 listing
|= LISTING_NOCOND
;
2201 demand_empty_rest_of_line ();
2205 tic54x_sslist (int show
)
2207 ILLEGAL_WITHIN_STRUCT ();
2209 listing_sslist
= show
;
2212 /* .var SYM[,...,SYMN]
2213 Define a substitution string to be local to a macro. */
2216 tic54x_var (int ignore ATTRIBUTE_UNUSED
)
2218 static char empty
[] = "";
2222 ILLEGAL_WITHIN_STRUCT ();
2224 if (macro_level
== 0)
2226 as_bad (_(".var may only be used within a macro definition"));
2227 ignore_rest_of_line ();
2232 if (!ISALPHA (*input_line_pointer
))
2234 as_bad (_("Substitution symbols must begin with a letter"));
2235 ignore_rest_of_line ();
2238 c
= get_symbol_name (&name
);
2239 /* .var symbols start out with a null string. */
2240 name
= xstrdup (name
);
2241 str_hash_insert (subsym_hash
[macro_level
], name
, empty
, 0);
2242 c
= restore_line_pointer (c
);
2245 ++input_line_pointer
;
2246 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2247 c
= *input_line_pointer
;
2252 demand_empty_rest_of_line ();
2255 /* .mlib <macro library filename>
2257 Macro libraries are archived (standard AR-format) text macro definitions
2258 Expand the file and include it.
2260 FIXME need to try the source file directory as well. */
2263 tic54x_mlib (int ignore ATTRIBUTE_UNUSED
)
2270 ILLEGAL_WITHIN_STRUCT ();
2272 /* Parse the filename. */
2273 if (*input_line_pointer
== '"')
2275 if ((filename
= demand_copy_C_string (&len
)) == NULL
)
2282 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
2283 && !ISSPACE (*input_line_pointer
))
2285 obstack_1grow (¬es
, *input_line_pointer
);
2286 ++input_line_pointer
;
2289 obstack_1grow (¬es
, '\0');
2290 filename
= obstack_finish (¬es
);
2292 demand_empty_rest_of_line ();
2294 tic54x_set_default_include ();
2295 path
= XNEWVEC (char, (unsigned long) len
+ include_dir_maxlen
+ 5);
2297 for (i
= 0; i
< include_dir_count
; i
++)
2301 strcpy (path
, include_dirs
[i
]);
2303 strcat (path
, filename
);
2304 if ((try = fopen (path
, "r")) != NULL
)
2311 if (i
>= include_dir_count
)
2317 /* FIXME: if path is found, malloc'd storage is not freed. Of course, this
2318 happens all over the place, and since the assembler doesn't usually keep
2319 running for a very long time, it really doesn't matter. */
2320 register_dependency (path
);
2322 /* Expand all archive entries to temporary files and include them. */
2323 abfd
= bfd_openr (path
, NULL
);
2326 as_bad (_("can't open macro library file '%s' for reading: %s"),
2327 path
, bfd_errmsg (bfd_get_error ()));
2328 ignore_rest_of_line ();
2331 if (!bfd_check_format (abfd
, bfd_archive
))
2333 as_bad (_("File '%s' not in macro archive format"), path
);
2334 ignore_rest_of_line ();
2338 /* Open each BFD as binary (it should be straight ASCII text). */
2339 for (mbfd
= bfd_openr_next_archived_file (abfd
, NULL
);
2340 mbfd
!= NULL
; mbfd
= bfd_openr_next_archived_file (abfd
, mbfd
))
2342 /* Get a size at least as big as the archive member. */
2343 bfd_size_type size
= bfd_get_size (mbfd
);
2344 char *buf
= XNEWVEC (char, size
);
2345 char *fname
= tmpnam (NULL
);
2348 /* We're not sure how big it is, but it will be smaller than "size". */
2349 size
= bfd_bread (buf
, size
, mbfd
);
2351 /* Write to a temporary file, then use s_include to include it
2353 ftmp
= fopen (fname
, "w+b");
2354 fwrite ((void *) buf
, size
, 1, ftmp
);
2355 if (size
== 0 || buf
[size
- 1] != '\n')
2356 fwrite ("\n", 1, 1, ftmp
);
2359 input_scrub_insert_file (fname
);
2364 const pseudo_typeS md_pseudo_table
[] =
2366 { "algebraic", s_ignore
, 0 },
2367 { "align" , tic54x_align_words
, 128 },
2368 { "ascii" , tic54x_stringer
, 'p' },
2369 { "asciz" , tic54x_stringer
, 'P' },
2370 { "even" , tic54x_align_words
, 2 },
2371 { "asg" , tic54x_asg
, 0 },
2372 { "eval" , tic54x_eval
, 0 },
2373 { "bss" , tic54x_bss
, 0 },
2374 { "byte" , tic54x_cons
, 'b' },
2375 { "ubyte" , tic54x_cons
, 'B' },
2376 { "char" , tic54x_cons
, 'c' },
2377 { "uchar" , tic54x_cons
, 'C' },
2378 { "clink" , tic54x_clink
, 0 },
2379 { "c_mode" , tic54x_address_mode
, c_mode
},
2380 { "copy" , tic54x_include
, 'c' },
2381 { "include" , tic54x_include
, 'i' },
2382 { "data" , tic54x_sect
, 'd' },
2383 { "double" , tic54x_float_cons
, 'd' },
2384 { "ldouble" , tic54x_float_cons
, 'l' },
2385 { "drlist" , s_ignore
, 0 },
2386 { "drnolist" , s_ignore
, 0 },
2387 { "emsg" , tic54x_message
, 'e' },
2388 { "mmsg" , tic54x_message
, 'm' },
2389 { "wmsg" , tic54x_message
, 'w' },
2390 { "far_mode" , tic54x_address_mode
, far_mode
},
2391 { "fclist" , tic54x_fclist
, 1 },
2392 { "fcnolist" , tic54x_fclist
, 0 },
2393 { "field" , tic54x_field
, -1 },
2394 { "float" , tic54x_float_cons
, 'f' },
2395 { "xfloat" , tic54x_float_cons
, 'x' },
2396 { "global" , tic54x_global
, 'g' },
2397 { "def" , tic54x_global
, 'd' },
2398 { "ref" , tic54x_global
, 'r' },
2399 { "half" , tic54x_cons
, 'h' },
2400 { "uhalf" , tic54x_cons
, 'H' },
2401 { "short" , tic54x_cons
, 's' },
2402 { "ushort" , tic54x_cons
, 'S' },
2403 { "if" , s_if
, (int) O_ne
},
2404 { "elseif" , s_elseif
, (int) O_ne
},
2405 { "else" , s_else
, 0 },
2406 { "endif" , s_endif
, 0 },
2407 { "int" , tic54x_cons
, 'i' },
2408 { "uint" , tic54x_cons
, 'I' },
2409 { "word" , tic54x_cons
, 'w' },
2410 { "uword" , tic54x_cons
, 'W' },
2411 { "label" , tic54x_label
, 0 }, /* Loadtime
2413 { "length" , s_ignore
, 0 },
2414 { "width" , s_ignore
, 0 },
2415 { "long" , tic54x_cons
, 'l' },
2416 { "ulong" , tic54x_cons
, 'L' },
2417 { "xlong" , tic54x_cons
, 'x' },
2418 { "loop" , tic54x_loop
, 1024 },
2419 { "break" , tic54x_break
, 0 },
2420 { "endloop" , tic54x_endloop
, 0 },
2421 { "mlib" , tic54x_mlib
, 0 },
2422 { "mlist" , s_ignore
, 0 },
2423 { "mnolist" , s_ignore
, 0 },
2424 { "mmregs" , tic54x_register_mmregs
, 0 },
2425 { "newblock" , tic54x_clear_local_labels
, 0 },
2426 { "option" , s_ignore
, 0 },
2427 { "p2align" , tic54x_p2align
, 0 },
2428 { "sblock" , tic54x_sblock
, 0 },
2429 { "sect" , tic54x_sect
, '*' },
2430 { "set" , tic54x_set
, 0 },
2431 { "equ" , tic54x_set
, 0 },
2432 { "space" , tic54x_space
, 0 },
2433 { "bes" , tic54x_space
, 1 },
2434 { "sslist" , tic54x_sslist
, 1 },
2435 { "ssnolist" , tic54x_sslist
, 0 },
2436 { "string" , tic54x_stringer
, 's' },
2437 { "pstring" , tic54x_stringer
, 'p' },
2438 { "struct" , tic54x_struct
, 0 },
2439 { "tag" , tic54x_tag
, 0 },
2440 { "endstruct", tic54x_endstruct
, 0 },
2441 { "tab" , s_ignore
, 0 },
2442 { "text" , tic54x_sect
, 't' },
2443 { "union" , tic54x_struct
, 1 },
2444 { "endunion" , tic54x_endstruct
, 1 },
2445 { "usect" , tic54x_usect
, 0 },
2446 { "var" , tic54x_var
, 0 },
2447 { "version" , tic54x_version
, 0 },
2452 md_parse_option (int c
, const char *arg
)
2458 case OPTION_COFF_VERSION
:
2460 int version
= atoi (arg
);
2462 if (version
!= 0 && version
!= 1 && version
!= 2)
2463 as_fatal (_("Bad COFF version '%s'"), arg
);
2464 /* FIXME -- not yet implemented. */
2467 case OPTION_CPU_VERSION
:
2469 cpu
= lookup_version (arg
);
2472 as_fatal (_("Bad CPU version '%s'"), arg
);
2475 case OPTION_ADDRESS_MODE
:
2477 address_mode_needs_set
= 1;
2479 case OPTION_STDERR_TO_FILE
:
2481 const char *filename
= arg
;
2482 FILE *fp
= fopen (filename
, "w+");
2485 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2487 if ((fp
= freopen (filename
, "w+", stderr
)) == NULL
)
2488 as_fatal (_("Can't redirect stderr to the file '%s'"), filename
);
2496 /* Create a "local" substitution string hash table for a new macro level
2497 Some docs imply that macros have to use .newblock in order to be able
2498 to re-use a local label. We effectively do an automatic .newblock by
2499 deleting the local label hash between macro invocations. */
2502 tic54x_macro_start (void)
2504 if (++macro_level
>= MAX_SUBSYM_HASH
)
2506 as_fatal (_("Macro nesting is too deep"));
2509 subsym_hash
[macro_level
] = str_htab_create ();
2510 local_label_hash
[macro_level
] = str_htab_create ();
2514 tic54x_macro_info (const macro_entry
*macro
)
2516 const formal_entry
*entry
;
2518 /* Put the formal args into the substitution symbol table. */
2519 for (entry
= macro
->formals
; entry
; entry
= entry
->next
)
2521 char *name
= xstrndup (entry
->name
.ptr
, entry
->name
.len
);
2522 char *value
= xstrndup (entry
->actual
.ptr
, entry
->actual
.len
);
2524 name
[entry
->name
.len
] = '\0';
2525 value
[entry
->actual
.len
] = '\0';
2526 str_hash_insert (subsym_hash
[macro_level
], name
, value
, 0);
2530 /* Get rid of this macro's .var's, arguments, and local labels. */
2533 tic54x_macro_end (void)
2535 htab_delete (subsym_hash
[macro_level
]);
2536 subsym_hash
[macro_level
] = NULL
;
2537 htab_delete (local_label_hash
[macro_level
]);
2538 local_label_hash
[macro_level
] = NULL
;
2543 subsym_symlen (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2548 /* Compare symbol A to string B. */
2551 subsym_symcmp (char *a
, char *b
)
2553 return strcmp (a
, b
);
2556 /* Return the index of the first occurrence of B in A, or zero if none
2557 assumes b is an integer char value as a string. Index is one-based. */
2560 subsym_firstch (char *a
, char *b
)
2563 char *tmp
= strchr (a
, val
);
2565 return tmp
? tmp
- a
+ 1 : 0;
2568 /* Similar to firstch, but returns index of last occurrence of B in A. */
2571 subsym_lastch (char *a
, char *b
)
2574 char *tmp
= strrchr (a
, val
);
2576 return tmp
? tmp
- a
+ 1 : 0;
2579 /* Returns 1 if string A is defined in the symbol table (NOT the substitution
2583 subsym_isdefed (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2585 symbolS
*symbolP
= symbol_find (a
);
2587 return symbolP
!= NULL
;
2590 /* Assign first member of comma-separated list B (e.g. "1,2,3") to the symbol
2591 A, or zero if B is a null string. Both arguments *must* be substitution
2592 symbols, unsubstituted. */
2595 subsym_ismember (char *sym
, char *list
)
2597 char *elem
, *ptr
, *listv
;
2602 listv
= subsym_lookup (list
, macro_level
);
2605 as_bad (_("Undefined substitution symbol '%s'"), list
);
2606 ignore_rest_of_line ();
2610 ptr
= elem
= xstrdup (listv
);
2611 while (*ptr
&& *ptr
!= ',')
2615 subsym_create_or_replace (sym
, elem
);
2617 /* Reassign the list. */
2618 subsym_create_or_replace (list
, ptr
);
2620 /* Assume this value, docs aren't clear. */
2624 /* Return zero if not a constant; otherwise:
2632 subsym_iscons (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2636 parse_expression (a
, &expn
);
2638 if (expn
.X_op
== O_constant
)
2640 int len
= strlen (a
);
2642 switch (TOUPPER (a
[len
- 1]))
2655 /* No suffix; either octal, hex, or decimal. */
2656 if (*a
== '0' && len
> 1)
2658 if (TOUPPER (a
[1]) == 'X')
2668 /* Return 1 if A is a valid symbol name. Expects string input. */
2671 subsym_isname (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2673 if (!is_name_beginner (*a
))
2677 if (!is_part_of_name (*a
))
2684 /* Return whether the string is a register; accepts ar0-7, unless .mmregs has
2685 been seen; if so, recognize any memory-mapped register.
2686 Note this does not recognize "A" or "B" accumulators. */
2689 subsym_isreg (char *a
, char *ignore ATTRIBUTE_UNUSED
)
2691 if (str_hash_find (reg_hash
, a
))
2693 if (str_hash_find (mmreg_hash
, a
))
2698 /* Return the structure size, given the stag. */
2701 subsym_structsz (char *name
, char *ignore ATTRIBUTE_UNUSED
)
2703 struct stag
*stag
= (struct stag
*) str_hash_find (stag_hash
, name
);
2711 /* If anybody actually uses this, they can fix it :)
2712 FIXME I'm not sure what the "reference point" of a structure is. It might
2713 be either the initial offset given .struct, or it may be the offset of the
2714 structure within another structure, or it might be something else
2715 altogether. since the TI assembler doesn't seem to ever do anything but
2716 return zero, we punt and return zero. */
2719 subsym_structacc (char *stag_name ATTRIBUTE_UNUSED
,
2720 char *ignore ATTRIBUTE_UNUSED
)
2726 math_ceil (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2728 return (float) ceil (arg1
);
2732 math_cvi (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2738 math_floor (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2740 return (float) floor (arg1
);
2744 math_fmod (float arg1
, float arg2
)
2746 return (int) arg1
% (int) arg2
;
2750 math_int (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2752 return ((float) ((int) arg1
)) == arg1
;
2756 math_round (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2758 return arg1
> 0 ? (int) (arg1
+ 0.5) : (int) (arg1
- 0.5);
2762 math_sgn (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2764 return (arg1
< 0) ? -1 : (arg1
? 1 : 0);
2768 math_trunc (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2774 math_acos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2776 return (float) acos (arg1
);
2780 math_asin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2782 return (float) asin (arg1
);
2786 math_atan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2788 return (float) atan (arg1
);
2792 math_atan2 (float arg1
, float arg2
)
2794 return (float) atan2 (arg1
, arg2
);
2798 math_cosh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2800 return (float) cosh (arg1
);
2804 math_cos (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2806 return (float) cos (arg1
);
2810 math_cvf (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2812 return (float) arg1
;
2816 math_exp (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2818 return (float) exp (arg1
);
2822 math_fabs (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2824 return (float) fabs (arg1
);
2827 /* expr1 * 2^expr2. */
2830 math_ldexp (float arg1
, float arg2
)
2832 return arg1
* (float) pow (2.0, arg2
);
2836 math_log10 (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2838 return (float) log10 (arg1
);
2842 math_log (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2844 return (float) log (arg1
);
2848 math_max (float arg1
, float arg2
)
2850 return (arg1
> arg2
) ? arg1
: arg2
;
2854 math_min (float arg1
, float arg2
)
2856 return (arg1
< arg2
) ? arg1
: arg2
;
2860 math_pow (float arg1
, float arg2
)
2862 return (float) pow (arg1
, arg2
);
2866 math_sin (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2868 return (float) sin (arg1
);
2872 math_sinh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2874 return (float) sinh (arg1
);
2878 math_sqrt (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2880 return (float) sqrt (arg1
);
2884 math_tan (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2886 return (float) tan (arg1
);
2890 math_tanh (float arg1
, float ignore ATTRIBUTE_UNUSED
)
2892 return (float) tanh (arg1
);
2895 /* Built-in substitution symbol functions and math functions. */
2899 int (*proc
) (char *, char *);
2901 } subsym_proc_entry
;
2903 static const subsym_proc_entry subsym_procs
[] =
2905 /* Assembler built-in string substitution functions. */
2906 { "$symlen", subsym_symlen
, 1, },
2907 { "$symcmp", subsym_symcmp
, 2, },
2908 { "$firstch", subsym_firstch
, 2, },
2909 { "$lastch", subsym_lastch
, 2, },
2910 { "$isdefed", subsym_isdefed
, 1, },
2911 { "$ismember", subsym_ismember
, 2, },
2912 { "$iscons", subsym_iscons
, 1, },
2913 { "$isname", subsym_isname
, 1, },
2914 { "$isreg", subsym_isreg
, 1, },
2915 { "$structsz", subsym_structsz
, 1, },
2916 { "$structacc", subsym_structacc
, 1, },
2923 float (*proc
) (float, float);
2928 static const math_proc_entry math_procs
[] =
2930 /* Integer-returning built-in math functions. */
2931 { "$cvi", math_cvi
, 1, 1 },
2932 { "$int", math_int
, 1, 1 },
2933 { "$sgn", math_sgn
, 1, 1 },
2935 /* Float-returning built-in math functions. */
2936 { "$acos", math_acos
, 1, 0 },
2937 { "$asin", math_asin
, 1, 0 },
2938 { "$atan", math_atan
, 1, 0 },
2939 { "$atan2", math_atan2
, 2, 0 },
2940 { "$ceil", math_ceil
, 1, 0 },
2941 { "$cosh", math_cosh
, 1, 0 },
2942 { "$cos", math_cos
, 1, 0 },
2943 { "$cvf", math_cvf
, 1, 0 },
2944 { "$exp", math_exp
, 1, 0 },
2945 { "$fabs", math_fabs
, 1, 0 },
2946 { "$floor", math_floor
, 1, 0 },
2947 { "$fmod", math_fmod
, 2, 0 },
2948 { "$ldexp", math_ldexp
, 2, 0 },
2949 { "$log10", math_log10
, 1, 0 },
2950 { "$log", math_log
, 1, 0 },
2951 { "$max", math_max
, 2, 0 },
2952 { "$min", math_min
, 2, 0 },
2953 { "$pow", math_pow
, 2, 0 },
2954 { "$round", math_round
, 1, 0 },
2955 { "$sin", math_sin
, 1, 0 },
2956 { "$sinh", math_sinh
, 1, 0 },
2957 { "$sqrt", math_sqrt
, 1, 0 },
2958 { "$tan", math_tan
, 1, 0 },
2959 { "$tanh", math_tanh
, 1, 0 },
2960 { "$trunc", math_trunc
, 1, 0 },
2961 { NULL
, NULL
, 0, 0 },
2968 const tic54x_symbol
*sym
;
2969 const subsym_proc_entry
*subsym_proc
;
2970 const math_proc_entry
*math_proc
;
2971 const char **symname
;
2972 char *TIC54X_DIR
= getenv ("TIC54X_DIR");
2973 char *A_DIR
= TIC54X_DIR
? TIC54X_DIR
: getenv ("A_DIR");
2977 /* Look for A_DIR and add it to the include list. */
2980 char *tmp
= xstrdup (A_DIR
);
2984 char *next
= strchr (tmp
, ';');
2988 add_include_dir (tmp
);
2991 while (tmp
!= NULL
);
2994 op_hash
= str_htab_create ();
2995 for (tm
= (insn_template
*) tic54x_optab
; tm
->name
; tm
++)
2996 str_hash_insert (op_hash
, tm
->name
, tm
, 0);
2998 parop_hash
= str_htab_create ();
2999 for (tm
= (insn_template
*) tic54x_paroptab
; tm
->name
; tm
++)
3000 str_hash_insert (parop_hash
, tm
->name
, tm
, 0);
3002 reg_hash
= str_htab_create ();
3003 for (sym
= tic54x_regs
; sym
->name
; sym
++)
3005 /* Add basic registers to the symbol table. */
3006 symbolS
*symbolP
= symbol_new (sym
->name
, absolute_section
,
3007 &zero_address_frag
, sym
->value
);
3008 SF_SET_LOCAL (symbolP
);
3009 symbol_table_insert (symbolP
);
3010 str_hash_insert (reg_hash
, sym
->name
, sym
, 0);
3012 for (sym
= tic54x_mmregs
; sym
->name
; sym
++)
3013 str_hash_insert (reg_hash
, sym
->name
, sym
, 0);
3014 mmreg_hash
= str_htab_create ();
3015 for (sym
= tic54x_mmregs
; sym
->name
; sym
++)
3016 str_hash_insert (mmreg_hash
, sym
->name
, sym
, 0);
3018 cc_hash
= str_htab_create ();
3019 for (sym
= tic54x_condition_codes
; sym
->name
; sym
++)
3020 str_hash_insert (cc_hash
, sym
->name
, sym
, 0);
3022 cc2_hash
= str_htab_create ();
3023 for (sym
= tic54x_cc2_codes
; sym
->name
; sym
++)
3024 str_hash_insert (cc2_hash
, sym
->name
, sym
, 0);
3026 cc3_hash
= str_htab_create ();
3027 for (sym
= tic54x_cc3_codes
; sym
->name
; sym
++)
3028 str_hash_insert (cc3_hash
, sym
->name
, sym
, 0);
3030 sbit_hash
= str_htab_create ();
3031 for (sym
= tic54x_status_bits
; sym
->name
; sym
++)
3032 str_hash_insert (sbit_hash
, sym
->name
, sym
, 0);
3034 misc_symbol_hash
= str_htab_create ();
3035 for (symname
= tic54x_misc_symbols
; *symname
; symname
++)
3036 str_hash_insert (misc_symbol_hash
, *symname
, *symname
, 0);
3038 /* Only the base substitution table and local label table are initialized;
3039 the others (for local macro substitution) get instantiated as needed. */
3040 local_label_hash
[0] = str_htab_create ();
3041 subsym_hash
[0] = str_htab_create ();
3042 for (subsym_proc
= subsym_procs
; subsym_proc
->name
; subsym_proc
++)
3043 str_hash_insert (subsym_hash
[0], subsym_proc
->name
, subsym_proc
, 0);
3045 math_hash
= str_htab_create ();
3046 for (math_proc
= math_procs
; math_proc
->name
; math_proc
++)
3048 /* Insert into the main subsym hash for recognition; insert into
3049 the math hash to actually store information. */
3050 str_hash_insert (subsym_hash
[0], math_proc
->name
, math_proc
, 0);
3051 str_hash_insert (math_hash
, math_proc
->name
, math_proc
, 0);
3053 subsym_recurse_hash
= str_htab_create ();
3054 stag_hash
= str_htab_create ();
3058 is_accumulator (struct opstruct
*operand
)
3060 return strcasecmp (operand
->buf
, "a") == 0
3061 || strcasecmp (operand
->buf
, "b") == 0;
3064 /* Return the number of operands found, or -1 on error, copying the
3065 operands into the given array and the accompanying expressions into
3069 get_operands (struct opstruct operands
[], char *line
)
3073 int expecting_operand
= 0;
3076 while (numexp
< MAX_OPERANDS
&& !is_end_of_line
[(unsigned char) *lptr
])
3078 int paren_not_balanced
= 0;
3079 char *op_start
, *op_end
;
3081 while (*lptr
&& ISSPACE (*lptr
))
3084 while (paren_not_balanced
|| *lptr
!= ',')
3088 if (paren_not_balanced
)
3090 as_bad (_("Unbalanced parenthesis in operand %d"), numexp
);
3097 ++paren_not_balanced
;
3098 else if (*lptr
== ')')
3099 --paren_not_balanced
;
3103 if (op_end
!= op_start
)
3105 int len
= op_end
- op_start
;
3107 strncpy (operands
[numexp
].buf
, op_start
, len
);
3108 operands
[numexp
].buf
[len
] = 0;
3109 /* Trim trailing spaces; while the preprocessor gets rid of most,
3110 there are weird usage patterns that can introduce them
3111 (i.e. using strings for macro args). */
3112 while (len
> 0 && ISSPACE (operands
[numexp
].buf
[len
- 1]))
3113 operands
[numexp
].buf
[--len
] = 0;
3119 if (expecting_operand
|| *lptr
== ',')
3121 as_bad (_("Expecting operand after ','"));
3127 if (*++lptr
== '\0')
3129 as_bad (_("Expecting operand after ','"));
3132 expecting_operand
= 1;
3136 while (*lptr
&& ISSPACE (*lptr
++))
3138 if (!is_end_of_line
[(unsigned char) *lptr
])
3140 as_bad (_("Extra junk on line"));
3144 /* OK, now parse them into expressions. */
3145 for (i
= 0; i
< numexp
; i
++)
3147 memset (&operands
[i
].exp
, 0, sizeof (operands
[i
].exp
));
3148 if (operands
[i
].buf
[0] == '#')
3151 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3153 else if (operands
[i
].buf
[0] == '@')
3155 /* Direct notation. */
3156 parse_expression (operands
[i
].buf
+ 1, &operands
[i
].exp
);
3158 else if (operands
[i
].buf
[0] == '*')
3161 char *paren
= strchr (operands
[i
].buf
, '(');
3163 /* Allow immediate syntax in the inner expression. */
3164 if (paren
&& paren
[1] == '#')
3167 /* Pull out the lk expression or SP offset, if present. */
3170 int len
= strlen (paren
);
3171 char *end
= paren
+ len
;
3174 while (end
[-1] != ')')
3177 as_bad (_("Badly formed address expression"));
3182 parse_expression (paren
, &operands
[i
].exp
);
3186 operands
[i
].exp
.X_op
= O_absent
;
3189 parse_expression (operands
[i
].buf
, &operands
[i
].exp
);
3195 /* Predicates for different operand types. */
3198 is_immediate (struct opstruct
*operand
)
3200 return *operand
->buf
== '#';
3203 /* This is distinguished from immediate because some numbers must be constants
3204 and must *not* have the '#' prefix. */
3207 is_absolute (struct opstruct
*operand
)
3209 return operand
->exp
.X_op
== O_constant
&& !is_immediate (operand
);
3212 /* Is this an indirect operand? */
3215 is_indirect (struct opstruct
*operand
)
3217 return operand
->buf
[0] == '*';
3220 /* Is this a valid dual-memory operand? */
3223 is_dual (struct opstruct
*operand
)
3225 if (is_indirect (operand
) && strncasecmp (operand
->buf
, "*ar", 3) == 0)
3227 char *tmp
= operand
->buf
+ 3;
3232 /* Only allow *ARx, *ARx-, *ARx+, or *ARx+0%. */
3233 valid_mod
= *tmp
== '\0' ||
3234 strcasecmp (tmp
, "-") == 0 ||
3235 strcasecmp (tmp
, "+") == 0 ||
3236 strcasecmp (tmp
, "+0%") == 0;
3237 return arf
>= 2 && arf
<= 5 && valid_mod
;
3243 is_mmreg (struct opstruct
*operand
)
3245 return (is_absolute (operand
)
3246 || is_immediate (operand
)
3247 || str_hash_find (mmreg_hash
, operand
->buf
) != 0);
3251 is_type (struct opstruct
*operand
, enum optype type
)
3256 return operand
->buf
[0] == 0;
3259 return is_dual (operand
);
3261 return is_indirect (operand
);
3263 /* This one *must* be immediate. */
3264 return is_immediate (operand
);
3273 /* Address may be a numeric, indirect, or an expression. */
3274 return !is_immediate (operand
);
3277 return is_mmreg (operand
);
3282 return is_accumulator (operand
);
3284 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'B';
3286 return is_accumulator (operand
) && TOUPPER (operand
->buf
[0]) == 'A';
3288 return strncasecmp ("ar", operand
->buf
, 2) == 0
3289 && ISDIGIT (operand
->buf
[2]);
3291 return str_hash_find (sbit_hash
, operand
->buf
) != 0 || is_absolute (operand
);
3293 return str_hash_find (cc_hash
, operand
->buf
) != 0;
3295 return str_hash_find (cc2_hash
, operand
->buf
) != 0;
3297 return str_hash_find (cc3_hash
, operand
->buf
) != 0
3298 || is_immediate (operand
) || is_absolute (operand
);
3300 return (is_immediate (operand
) || is_absolute (operand
))
3301 && operand
->exp
.X_add_number
== 16;
3303 /* Allow st0 or st1 instead of a numeric. */
3304 return is_absolute (operand
) || is_immediate (operand
) ||
3305 strcasecmp ("st0", operand
->buf
) == 0 ||
3306 strcasecmp ("st1", operand
->buf
) == 0;
3309 return is_absolute (operand
) || is_immediate (operand
);
3311 return (is_immediate (operand
) || is_absolute (operand
))
3312 && operand
->exp
.X_add_number
>= 0 && operand
->exp
.X_add_number
< 16;
3314 /* Let this one catch out-of-range values. */
3315 return (is_immediate (operand
) || is_absolute (operand
))
3316 && operand
->exp
.X_add_number
!= 16;
3320 return is_absolute (operand
) || is_immediate (operand
);
3322 return is_immediate (operand
)
3323 && operand
->exp
.X_op
== O_constant
3324 && operand
->exp
.X_add_number
>= 0
3325 && operand
->exp
.X_add_number
< 256;
3328 /* Allow anything; assumes opcodes are ordered with Smem operands
3334 /* Just make sure it's an integer; check range later. */
3335 return is_immediate (operand
);
3337 return strcasecmp ("t", operand
->buf
) == 0 ||
3338 strcasecmp ("treg", operand
->buf
) == 0;
3340 return strcasecmp ("ts", operand
->buf
) == 0;
3342 return strcasecmp ("asm", operand
->buf
) == 0;
3344 return strcasecmp ("trn", operand
->buf
) == 0;
3346 return strcasecmp ("dp", operand
->buf
) == 0;
3348 return strcasecmp ("arp", operand
->buf
) == 0;
3355 operands_match (tic54x_insn
*insn
,
3356 struct opstruct
*operands
,
3358 const enum optype
*refoptype
,
3362 int op
= 0, refop
= 0;
3364 if (opcount
== 0 && minops
== 0)
3367 while (op
<= maxops
&& refop
<= maxops
)
3369 while (!is_type (&operands
[op
], OPTYPE (refoptype
[refop
])))
3371 /* Skip an optional template operand if it doesn't agree
3372 with the current operand. */
3373 if (refoptype
[refop
] & OPT
)
3384 /* Save the actual operand type for later use. */
3385 operands
[op
].type
= OPTYPE (refoptype
[refop
]);
3388 /* Have we matched them all yet? */
3393 /* If a later operand is *not* optional, no match. */
3394 if ((refoptype
[refop
] & OPT
) == 0)
3396 /* Flag any implicit default OP_DST operands so we know to add
3397 them explicitly when encoding the operand later. */
3398 if (OPTYPE (refoptype
[refop
]) == OP_DST
)
3399 insn
->using_default_dst
= 1;
3411 /* 16-bit direct memory address
3412 Explicit dmad operands are always in last word of insn (usually second
3413 word, but bumped to third if lk addressing is used)
3415 We allow *(dmad) notation because the TI assembler allows it.
3418 0 for 16-bit addresses
3419 1 for full 23-bit addresses
3420 2 for the upper 7 bits of a 23-bit address (LDX). */
3423 encode_dmad (tic54x_insn
*insn
, struct opstruct
*operand
, int xpc_code
)
3425 int op
= 1 + insn
->is_lkaddr
;
3427 /* Only allow *(dmad) expressions; all others are invalid. */
3428 if (is_indirect (operand
) && operand
->buf
[strlen (operand
->buf
) - 1] != ')')
3430 as_bad (_("Invalid dmad syntax '%s'"), operand
->buf
);
3434 insn
->opcode
[op
].addr_expr
= operand
->exp
;
3436 if (insn
->opcode
[op
].addr_expr
.X_op
== O_constant
)
3438 valueT value
= insn
->opcode
[op
].addr_expr
.X_add_number
;
3442 insn
->opcode
[0].word
&= 0xFF80;
3443 insn
->opcode
[0].word
|= (value
>> 16) & 0x7F;
3444 insn
->opcode
[1].word
= value
& 0xFFFF;
3446 else if (xpc_code
== 2)
3447 insn
->opcode
[op
].word
= (value
>> 16) & 0xFFFF;
3449 insn
->opcode
[op
].word
= value
;
3453 /* Do the fixup later; just store the expression. */
3454 insn
->opcode
[op
].word
= 0;
3455 insn
->opcode
[op
].r_nchars
= 2;
3457 if (amode
== c_mode
)
3458 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3459 else if (xpc_code
== 1)
3461 /* This relocation spans two words, so adjust accordingly. */
3462 insn
->opcode
[0].addr_expr
= operand
->exp
;
3463 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_23
;
3464 insn
->opcode
[0].r_nchars
= 4;
3465 insn
->opcode
[0].unresolved
= 1;
3466 /* It's really 2 words, but we want to stop encoding after the
3467 first, since we must encode both words at once. */
3470 else if (xpc_code
== 2)
3471 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_MS7_OF_23
;
3473 insn
->opcode
[op
].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3475 insn
->opcode
[op
].unresolved
= 1;
3481 /* 7-bit direct address encoding. */
3484 encode_address (tic54x_insn
*insn
, struct opstruct
*operand
)
3486 /* Assumes that dma addresses are *always* in word 0 of the opcode. */
3487 insn
->opcode
[0].addr_expr
= operand
->exp
;
3489 if (operand
->exp
.X_op
== O_constant
)
3490 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
& 0x7F);
3493 if (operand
->exp
.X_op
== O_register
)
3494 as_bad (_("Use the .mmregs directive to use memory-mapped register names such as '%s'"), operand
->buf
);
3495 /* Do the fixup later; just store the expression. */
3496 insn
->opcode
[0].r_nchars
= 1;
3497 insn
->opcode
[0].r_type
= BFD_RELOC_TIC54X_PARTLS7
;
3498 insn
->opcode
[0].unresolved
= 1;
3505 encode_indirect (tic54x_insn
*insn
, struct opstruct
*operand
)
3510 if (insn
->is_lkaddr
)
3512 /* lk addresses always go in the second insn word. */
3513 mod
= ((TOUPPER (operand
->buf
[1]) == 'A') ? 12 :
3514 (operand
->buf
[1] == '(') ? 15 :
3515 (strchr (operand
->buf
, '%') != NULL
) ? 14 : 13);
3516 arf
= ((mod
== 12) ? operand
->buf
[3] - '0' :
3517 (mod
== 15) ? 0 : operand
->buf
[4] - '0');
3519 insn
->opcode
[1].addr_expr
= operand
->exp
;
3521 if (operand
->exp
.X_op
== O_constant
)
3522 insn
->opcode
[1].word
= operand
->exp
.X_add_number
;
3525 insn
->opcode
[1].word
= 0;
3526 insn
->opcode
[1].r_nchars
= 2;
3527 insn
->opcode
[1].r_type
= BFD_RELOC_TIC54X_16_OF_23
;
3528 insn
->opcode
[1].unresolved
= 1;
3531 else if (strncasecmp (operand
->buf
, "*sp (", 4) == 0)
3533 /* Stack offsets look the same as 7-bit direct addressing. */
3534 return encode_address (insn
, operand
);
3538 arf
= (TOUPPER (operand
->buf
[1]) == 'A' ?
3539 operand
->buf
[3] : operand
->buf
[4]) - '0';
3541 if (operand
->buf
[1] == '+')
3543 mod
= 3; /* *+ARx */
3544 if (insn
->tm
->flags
& FL_SMR
)
3545 as_warn (_("Address mode *+ARx is write-only. "
3546 "Results of reading are undefined."));
3548 else if (operand
->buf
[4] == '\0')
3550 else if (operand
->buf
[5] == '\0')
3551 mod
= (operand
->buf
[4] == '-' ? 1 : 2); /* *ARx+ / *ARx- */
3552 else if (operand
->buf
[6] == '\0')
3554 if (operand
->buf
[5] == '0')
3555 mod
= (operand
->buf
[4] == '-' ? 5 : 6); /* *ARx+0 / *ARx-0 */
3557 mod
= (operand
->buf
[4] == '-' ? 8 : 10);/* *ARx+% / *ARx-% */
3559 else if (TOUPPER (operand
->buf
[6]) == 'B')
3560 mod
= (operand
->buf
[4] == '-' ? 4 : 7); /* ARx+0B / *ARx-0B */
3561 else if (TOUPPER (operand
->buf
[6]) == '%')
3562 mod
= (operand
->buf
[4] == '-' ? 9 : 11); /* ARx+0% / *ARx - 0% */
3565 as_bad (_("Unrecognized indirect address format \"%s\""),
3571 insn
->opcode
[0].word
|= 0x80 | (mod
<< 3) | arf
;
3577 encode_integer (tic54x_insn
*insn
,
3578 struct opstruct
*operand
,
3582 unsigned short mask
)
3584 long parse
, integer
;
3586 insn
->opcode
[which
].addr_expr
= operand
->exp
;
3588 if (operand
->exp
.X_op
== O_constant
)
3590 parse
= operand
->exp
.X_add_number
;
3591 /* Hack -- fixup for 16-bit hex quantities that get converted positive
3592 instead of negative. */
3593 if ((parse
& 0x8000) && min
== -32768 && max
== 32767)
3594 integer
= (short) parse
;
3598 if (integer
>= min
&& integer
<= max
)
3600 insn
->opcode
[which
].word
|= (integer
& mask
);
3603 as_bad (_("Operand '%s' out of range (%d <= x <= %d)"),
3604 operand
->buf
, min
, max
);
3608 if (insn
->opcode
[which
].addr_expr
.X_op
== O_constant
)
3610 insn
->opcode
[which
].word
|=
3611 insn
->opcode
[which
].addr_expr
.X_add_number
& mask
;
3615 /* Do the fixup later; just store the expression. */
3616 bfd_reloc_code_real_type rtype
=
3617 (mask
== 0x1FF ? BFD_RELOC_TIC54X_PARTMS9
:
3618 mask
== 0xFFFF ? BFD_RELOC_TIC54X_16_OF_23
:
3619 mask
== 0x7F ? BFD_RELOC_TIC54X_PARTLS7
: BFD_RELOC_8
);
3620 int size
= (mask
== 0x1FF || mask
== 0xFFFF) ? 2 : 1;
3622 if (rtype
== BFD_RELOC_8
)
3623 as_bad (_("Error in relocation handling"));
3625 insn
->opcode
[which
].r_nchars
= size
;
3626 insn
->opcode
[which
].r_type
= rtype
;
3627 insn
->opcode
[which
].unresolved
= 1;
3637 encode_condition (tic54x_insn
*insn
, struct opstruct
*operand
)
3639 tic54x_symbol
*cc
= (tic54x_symbol
*) str_hash_find (cc_hash
, operand
->buf
);
3642 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3645 #define CC_GROUP 0x40
3647 #define CATG_A1 0x07
3648 #define CATG_B1 0x30
3649 #define CATG_A2 0x30
3650 #define CATG_B2 0x0C
3651 #define CATG_C2 0x03
3652 /* Disallow group 1 conditions mixed with group 2 conditions
3653 if group 1, allow only one category A and one category B
3654 if group 2, allow only one each of category A, B, and C. */
3655 if (((insn
->opcode
[0].word
& 0xFF) != 0))
3657 if ((insn
->opcode
[0].word
& CC_GROUP
) != (cc
->value
& CC_GROUP
))
3659 as_bad (_("Condition \"%s\" does not match preceding group"),
3663 if (insn
->opcode
[0].word
& CC_GROUP
)
3665 if ((insn
->opcode
[0].word
& CC_ACC
) != (cc
->value
& CC_ACC
))
3667 as_bad (_("Condition \"%s\" uses a different accumulator from "
3668 "a preceding condition"),
3672 if ((insn
->opcode
[0].word
& CATG_A1
) && (cc
->value
& CATG_A1
))
3674 as_bad (_("Only one comparison conditional allowed"));
3677 if ((insn
->opcode
[0].word
& CATG_B1
) && (cc
->value
& CATG_B1
))
3679 as_bad (_("Only one overflow conditional allowed"));
3683 else if ( ((insn
->opcode
[0].word
& CATG_A2
) && (cc
->value
& CATG_A2
))
3684 || ((insn
->opcode
[0].word
& CATG_B2
) && (cc
->value
& CATG_B2
))
3685 || ((insn
->opcode
[0].word
& CATG_C2
) && (cc
->value
& CATG_C2
)))
3687 as_bad (_("Duplicate %s conditional"), operand
->buf
);
3692 insn
->opcode
[0].word
|= cc
->value
;
3697 encode_cc3 (tic54x_insn
*insn
, struct opstruct
*operand
)
3699 tic54x_symbol
*cc3
= (tic54x_symbol
*) str_hash_find (cc3_hash
, operand
->buf
);
3700 int value
= cc3
? cc3
->value
: operand
->exp
.X_add_number
<< 8;
3702 if ((value
& 0x0300) != value
)
3704 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3707 insn
->opcode
[0].word
|= value
;
3712 encode_arx (tic54x_insn
*insn
, struct opstruct
*operand
)
3714 int arf
= strlen (operand
->buf
) >= 3 ? operand
->buf
[2] - '0' : -1;
3716 if (strncasecmp ("ar", operand
->buf
, 2) || arf
< 0 || arf
> 7)
3718 as_bad (_("Invalid auxiliary register (use AR0-AR7)"));
3721 insn
->opcode
[0].word
|= arf
;
3726 encode_cc2 (tic54x_insn
*insn
, struct opstruct
*operand
)
3728 tic54x_symbol
*cc2
= (tic54x_symbol
*) str_hash_find (cc2_hash
, operand
->buf
);
3732 as_bad (_("Unrecognized condition code \"%s\""), operand
->buf
);
3735 insn
->opcode
[0].word
|= cc2
->value
;
3740 encode_operand (tic54x_insn
*insn
, enum optype type
, struct opstruct
*operand
)
3742 int ext
= (insn
->tm
->flags
& FL_EXT
) != 0;
3744 if (type
== OP_MMR
&& operand
->exp
.X_op
!= O_constant
)
3746 /* Disallow long-constant addressing for memory-mapped addressing. */
3747 if (insn
->is_lkaddr
)
3749 as_bad (_("lk addressing modes are invalid for memory-mapped "
3750 "register addressing"));
3754 /* Warn about *+ARx when used with MMR operands. */
3755 if (strncasecmp (operand
->buf
, "*+ar", 4) == 0)
3757 as_warn (_("Address mode *+ARx is not allowed in memory-mapped "
3758 "register addressing. Resulting behavior is "
3768 /* 16-bit immediate value. */
3769 return encode_dmad (insn
, operand
, 0);
3771 if (TOUPPER (*operand
->buf
) == 'B')
3773 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 9);
3774 if (insn
->using_default_dst
)
3775 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3779 /* Make sure this agrees with the OP_DST operand. */
3780 if (!((TOUPPER (operand
->buf
[0]) == 'B') ^
3781 ((insn
->opcode
[0].word
& (1 << 8)) != 0)))
3783 as_bad (_("Destination accumulator for each part of this parallel "
3784 "instruction must be different"));
3790 if (TOUPPER (operand
->buf
[0]) == 'B')
3791 insn
->opcode
[ext
? (1 + insn
->is_lkaddr
) : 0].word
|= (1 << 8);
3796 int mod
= (operand
->buf
[4] == '\0' ? 0 : /* *arx */
3797 operand
->buf
[4] == '-' ? 1 : /* *arx- */
3798 operand
->buf
[5] == '\0' ? 2 : 3); /* *arx+, *arx+0% */
3799 int arf
= operand
->buf
[3] - '0' - 2;
3800 int code
= (mod
<< 2) | arf
;
3801 insn
->opcode
[0].word
|= (code
<< (type
== OP_Xmem
? 4 : 0));
3806 if (!is_indirect (operand
))
3807 return encode_address (insn
, operand
);
3810 return encode_indirect (insn
, operand
);
3812 return encode_dmad (insn
, operand
, 2);
3814 return encode_dmad (insn
, operand
, 1);
3817 return encode_dmad (insn
, operand
, 0);
3819 return encode_arx (insn
, operand
);
3824 int value
= operand
->exp
.X_add_number
;
3827 insn
->opcode
[0].word
|= value
;
3830 if (value
< 16 || value
> 24)
3832 as_bad (_("Memory mapped register \"%s\" out of range"),
3836 if (type
== OP_MMRX
)
3837 insn
->opcode
[0].word
|= (value
- 16) << 4;
3839 insn
->opcode
[0].word
|= (value
- 16);
3847 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3850 return encode_integer (insn
, operand
, ext
+ insn
->is_lkaddr
,
3853 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3854 -32768, 32767, 0xFFFF);
3856 return encode_condition (insn
, operand
);
3858 return encode_cc2 (insn
, operand
);
3860 return encode_cc3 (insn
, operand
);
3862 return encode_integer (insn
, operand
, 0, 0, 15, 0xF);
3864 return encode_integer (insn
, operand
, 0, -128, 127, 0xFF);
3867 int value
= operand
->exp
.X_add_number
;
3869 if (value
< 1 || value
> 3)
3871 as_bad (_("Invalid operand (use 1, 2, or 3)"));
3874 code
= value
== 1 ? 0 : value
== 2 ? 0x2 : 0x1;
3875 insn
->opcode
[0].word
|= (code
<< 8);
3879 return encode_integer (insn
, operand
, 0, 0, 31, 0x1F);
3881 return encode_integer (insn
, operand
, 0, 0, 255, 0xFF);
3883 return encode_integer (insn
, operand
, 1 + insn
->is_lkaddr
,
3887 tic54x_symbol
*sbit
= (tic54x_symbol
*)
3888 str_hash_find (sbit_hash
, operand
->buf
);
3889 int value
= is_absolute (operand
) ?
3890 operand
->exp
.X_add_number
: (sbit
? sbit
->value
: -1);
3893 if (insn
->opcount
== 1)
3897 as_bad (_("A status register or status bit name is required"));
3900 /* Guess the register based on the status bit; "ovb" is the last
3901 status bit defined for st0. */
3902 if (sbit
> (tic54x_symbol
*) str_hash_find (sbit_hash
, "ovb"))
3907 as_bad (_("Unrecognized status bit \"%s\""), operand
->buf
);
3910 insn
->opcode
[0].word
|= value
;
3911 insn
->opcode
[0].word
|= (reg
<< 9);
3915 if (strcasecmp (operand
->buf
, "st0") == 0
3916 || strcasecmp (operand
->buf
, "st1") == 0)
3918 insn
->opcode
[0].word
|=
3919 ((unsigned short) (operand
->buf
[2] - '0')) << 9;
3922 else if (operand
->exp
.X_op
== O_constant
3923 && (operand
->exp
.X_add_number
== 0
3924 || operand
->exp
.X_add_number
== 1))
3926 insn
->opcode
[0].word
|=
3927 ((unsigned short) (operand
->exp
.X_add_number
)) << 9;
3930 as_bad (_("Invalid status register \"%s\""), operand
->buf
);
3933 return encode_integer (insn
, operand
, 0, -16, 15, 0x1F);
3935 return encode_integer (insn
, operand
, 0, 0, 7, 0x7);
3937 return encode_integer (insn
, operand
, 0, 0, 0x1FF, 0x1FF);
3939 if (operand
->exp
.X_add_number
!= 1
3940 && operand
->exp
.X_add_number
!= 2)
3942 as_bad (_("Operand \"%s\" out of range (use 1 or 2)"), operand
->buf
);
3945 insn
->opcode
[0].word
|= (operand
->exp
.X_add_number
- 1) << 9;
3954 /* No encoding necessary. */
3964 emit_insn (tic54x_insn
*insn
)
3967 flagword oldflags
= bfd_section_flags (now_seg
);
3968 flagword flags
= oldflags
| SEC_CODE
;
3970 if (!bfd_set_section_flags (now_seg
, flags
))
3971 as_warn (_("error setting flags for \"%s\": %s"),
3972 bfd_section_name (now_seg
),
3973 bfd_errmsg (bfd_get_error ()));
3975 for (i
= 0; i
< insn
->words
; i
++)
3977 int size
= (insn
->opcode
[i
].unresolved
3978 && insn
->opcode
[i
].r_type
== BFD_RELOC_TIC54X_23
) ? 4 : 2;
3979 char *p
= frag_more (size
);
3982 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
, 2);
3984 md_number_to_chars (p
, (valueT
) insn
->opcode
[i
].word
<< 16, 4);
3986 if (insn
->opcode
[i
].unresolved
)
3987 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
,
3988 insn
->opcode
[i
].r_nchars
, &insn
->opcode
[i
].addr_expr
,
3989 false, insn
->opcode
[i
].r_type
);
3993 /* Convert the operand strings into appropriate opcode values
3994 return the total number of words used by the instruction. */
3997 build_insn (tic54x_insn
*insn
)
4001 /* Only non-parallel instructions support lk addressing. */
4002 if (!(insn
->tm
->flags
& FL_PAR
))
4004 for (i
= 0; i
< insn
->opcount
; i
++)
4006 if ((OPTYPE (insn
->operands
[i
].type
) == OP_Smem
4007 || OPTYPE (insn
->operands
[i
].type
) == OP_Lmem
4008 || OPTYPE (insn
->operands
[i
].type
) == OP_Sind
)
4009 && strchr (insn
->operands
[i
].buf
, '(')
4010 /* Don't mistake stack-relative addressing for lk addressing. */
4011 && strncasecmp (insn
->operands
[i
].buf
, "*sp (", 4) != 0)
4013 insn
->is_lkaddr
= 1;
4014 insn
->lkoperand
= i
;
4019 insn
->words
= insn
->tm
->words
+ insn
->is_lkaddr
;
4021 insn
->opcode
[0].word
= insn
->tm
->opcode
;
4022 if (insn
->tm
->flags
& FL_EXT
)
4023 insn
->opcode
[1 + insn
->is_lkaddr
].word
= insn
->tm
->opcode2
;
4025 for (i
= 0; i
< insn
->opcount
; i
++)
4027 enum optype type
= insn
->operands
[i
].type
;
4029 if (!encode_operand (insn
, type
, &insn
->operands
[i
]))
4032 if (insn
->tm
->flags
& FL_PAR
)
4033 for (i
= 0; i
< insn
->paropcount
; i
++)
4035 enum optype partype
= insn
->paroperands
[i
].type
;
4037 if (!encode_operand (insn
, partype
, &insn
->paroperands
[i
]))
4047 optimize_insn (tic54x_insn
*insn
)
4049 /* Optimize some instructions, helping out the brain-dead programmer. */
4050 #define is_zero(op) ((op).exp.X_op == O_constant && (op).exp.X_add_number == 0)
4051 if (strcasecmp (insn
->tm
->name
, "add") == 0)
4053 if (insn
->opcount
> 1
4054 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4055 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4056 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4057 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4060 insn
->using_default_dst
= 1;
4064 /* Try to collapse if Xmem and shift count is zero. */
4065 if ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4066 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
4067 && is_zero (insn
->operands
[1]))
4068 /* Or if Smem, shift is zero or absent, and SRC == DST. */
4069 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4070 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4071 && is_type (&insn
->operands
[1], OP_SHIFT
)
4072 && is_zero (insn
->operands
[1]) && insn
->opcount
== 3))
4074 insn
->operands
[1] = insn
->operands
[2];
4079 else if (strcasecmp (insn
->tm
->name
, "ld") == 0)
4081 if (insn
->opcount
== 3 && insn
->operands
[0].type
!= OP_SRC
)
4083 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4084 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4085 && is_zero (insn
->operands
[1])
4086 && (OPTYPE (insn
->tm
->operand_types
[0]) != OP_lk
4087 || (insn
->operands
[0].exp
.X_op
== O_constant
4088 && insn
->operands
[0].exp
.X_add_number
<= 255
4089 && insn
->operands
[0].exp
.X_add_number
>= 0)))
4091 insn
->operands
[1] = insn
->operands
[2];
4097 else if (strcasecmp (insn
->tm
->name
, "sth") == 0
4098 || strcasecmp (insn
->tm
->name
, "stl") == 0)
4100 if ((OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
4101 || OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
)
4102 && is_zero (insn
->operands
[1]))
4104 insn
->operands
[1] = insn
->operands
[2];
4109 else if (strcasecmp (insn
->tm
->name
, "sub") == 0)
4111 if (insn
->opcount
> 1
4112 && is_accumulator (&insn
->operands
[insn
->opcount
- 2])
4113 && is_accumulator (&insn
->operands
[insn
->opcount
- 1])
4114 && strcasecmp (insn
->operands
[insn
->opcount
- 2].buf
,
4115 insn
->operands
[insn
->opcount
- 1].buf
) == 0)
4118 insn
->using_default_dst
= 1;
4122 if ( ((OPTYPE (insn
->tm
->operand_types
[0]) == OP_Smem
4123 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHIFT
)
4124 || (OPTYPE (insn
->tm
->operand_types
[0]) == OP_Xmem
4125 && OPTYPE (insn
->tm
->operand_types
[1]) == OP_SHFT
))
4126 && is_zero (insn
->operands
[1])
4127 && insn
->opcount
== 3)
4129 insn
->operands
[1] = insn
->operands
[2];
4137 /* Find a matching template if possible, and get the operand strings. */
4140 tic54x_parse_insn (tic54x_insn
*insn
, char *line
)
4142 insn
->tm
= (insn_template
*) str_hash_find (op_hash
, insn
->mnemonic
);
4145 as_bad (_("Unrecognized instruction \"%s\""), insn
->mnemonic
);
4149 insn
->opcount
= get_operands (insn
->operands
, line
);
4150 if (insn
->opcount
< 0)
4153 /* Check each variation of operands for this mnemonic. */
4154 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
, insn
->mnemonic
) == 0)
4156 if (insn
->opcount
>= insn
->tm
->minops
4157 && insn
->opcount
<= insn
->tm
->maxops
4158 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4159 insn
->tm
->operand_types
,
4160 insn
->tm
->minops
, insn
->tm
->maxops
))
4162 /* SUCCESS! now try some optimizations. */
4163 if (optimize_insn (insn
))
4165 insn
->tm
= (insn_template
*) str_hash_find (op_hash
,
4174 as_bad (_("Unrecognized operand list '%s' for instruction '%s'"),
4175 line
, insn
->mnemonic
);
4179 /* We set this in start_line_hook, 'cause if we do a line replacement, we
4180 won't be able to see the next line. */
4181 static int parallel_on_next_line_hint
= 0;
4183 /* See if this is part of a parallel instruction
4184 Look for a subsequent line starting with "||". */
4187 next_line_shows_parallel (char *next_line
)
4189 /* Look for the second half. */
4190 while (*next_line
!= 0 && ISSPACE (*next_line
))
4193 return (next_line
[0] == PARALLEL_SEPARATOR
4194 && next_line
[1] == PARALLEL_SEPARATOR
);
4198 tic54x_parse_parallel_insn_firstline (tic54x_insn
*insn
, char *line
)
4200 insn
->tm
= (insn_template
*) str_hash_find (parop_hash
, insn
->mnemonic
);
4203 as_bad (_("Unrecognized parallel instruction \"%s\""),
4208 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4209 insn
->mnemonic
) == 0)
4211 insn
->opcount
= get_operands (insn
->operands
, line
);
4212 if (insn
->opcount
< 0)
4214 if (insn
->opcount
== 2
4215 && operands_match (insn
, &insn
->operands
[0], insn
->opcount
,
4216 insn
->tm
->operand_types
, 2, 2))
4222 /* Didn't find a matching parallel; try for a normal insn. */
4226 /* Parse the second line of a two-line parallel instruction. */
4229 tic54x_parse_parallel_insn_lastline (tic54x_insn
*insn
, char *line
)
4231 int valid_mnemonic
= 0;
4233 insn
->paropcount
= get_operands (insn
->paroperands
, line
);
4234 while (insn
->tm
->name
&& strcasecmp (insn
->tm
->name
,
4235 insn
->mnemonic
) == 0)
4237 if (strcasecmp (insn
->tm
->parname
, insn
->parmnemonic
) == 0)
4241 if (insn
->paropcount
>= insn
->tm
->minops
4242 && insn
->paropcount
<= insn
->tm
->maxops
4243 && operands_match (insn
, insn
->paroperands
,
4245 insn
->tm
->paroperand_types
,
4246 insn
->tm
->minops
, insn
->tm
->maxops
))
4252 as_bad (_("Invalid operand (s) for parallel instruction \"%s\""),
4255 as_bad (_("Unrecognized parallel instruction combination \"%s || %s\""),
4256 insn
->mnemonic
, insn
->parmnemonic
);
4261 /* If quotes found, return copy of line up to closing quote;
4262 otherwise up until terminator.
4263 If it's a string, pass as-is; otherwise attempt substitution symbol
4264 replacement on the value. */
4267 subsym_get_arg (char *line
, const char *terminators
, char **str
, int nosub
)
4271 int is_string
= *line
== '"';
4272 int is_char
= ISDIGIT (*line
);
4276 while (ISDIGIT (*ptr
))
4279 *str
= xmemdup0 (line
, ptr
- line
);
4283 char *savedp
= input_line_pointer
;
4286 input_line_pointer
= ptr
;
4287 *str
= demand_copy_C_string (&len
);
4288 endp
= input_line_pointer
;
4289 input_line_pointer
= savedp
;
4291 /* Do forced substitutions if requested. */
4292 if (!nosub
&& **str
== ':')
4293 *str
= subsym_substitute (*str
, 1);
4297 const char *term
= terminators
;
4300 while (*ptr
&& *ptr
!= *term
)
4311 *str
= xmemdup0 (line
, ptr
- line
);
4312 /* Do simple substitution, if available. */
4313 if (!nosub
&& (value
= subsym_lookup (*str
, macro_level
)) != NULL
)
4320 /* Replace the given substitution string.
4321 We start at the innermost macro level, so that existing locals remain local
4322 Note: we're treating macro args identically to .var's; I don't know if
4323 that's compatible w/TI's assembler. */
4326 subsym_create_or_replace (char *name
, char *value
)
4330 for (i
= macro_level
; i
> 0; i
--)
4331 if (str_hash_find (subsym_hash
[i
], name
))
4333 str_hash_insert (subsym_hash
[i
], name
, value
, 1);
4336 str_hash_insert (subsym_hash
[0], name
, value
, 1);
4339 /* Look up the substitution string replacement for the given symbol.
4340 Start with the innermost macro substitution table given and work
4344 subsym_lookup (char *name
, int nest_level
)
4346 char *value
= str_hash_find (subsym_hash
[nest_level
], name
);
4348 if (value
|| nest_level
== 0)
4351 return subsym_lookup (name
, nest_level
- 1);
4354 /* Do substitution-symbol replacement on the given line (recursively).
4355 return the argument if no substitution was done
4357 Also look for built-in functions ($func (arg)) and local labels.
4359 If FORCED is set, look for forced substitutions of the form ':SYMBOL:'. */
4362 subsym_substitute (char *line
, int forced
)
4364 /* For each apparent symbol, see if it's a substitution symbol, and if so,
4365 replace it in the input. */
4366 char *replacement
; /* current replacement for LINE. */
4367 char *head
; /* Start of line. */
4368 char *ptr
; /* Current examination point. */
4369 int changed
= 0; /* Did we make a substitution? */
4370 int eval_line
= 0; /* Is this line a .eval/.asg statement? */
4371 int eval_symbol
= 0; /* Are we in the middle of the symbol for
4373 char *eval_end
= NULL
;
4375 int line_conditional
= 0;
4378 /* Work with a copy of the input line. */
4379 replacement
= xstrdup (line
);
4381 ptr
= head
= replacement
;
4383 /* Flag lines where we might need to replace a single '=' with two;
4384 GAS uses single '=' to assign macro args values, and possibly other
4385 places, so limit what we replace. */
4386 if (strstr (line
, ".if")
4387 || strstr (line
, ".elseif")
4388 || strstr (line
, ".break"))
4389 line_conditional
= 1;
4391 /* Watch out for .eval, so that we avoid doing substitution on the
4392 symbol being assigned a value. */
4393 if (strstr (line
, ".eval") || strstr (line
, ".asg"))
4396 /* If it's a macro definition, don't do substitution on the argument
4398 if (strstr (line
, ".macro"))
4401 unsigned char current_char
;
4402 while (!is_end_of_line
[(current_char
= * (unsigned char *) ptr
)])
4404 /* Need to update this since LINE may have been modified. */
4406 eval_end
= strrchr (ptr
, ',');
4408 /* Replace triple double quotes with bounding quote/escapes. */
4409 if (current_char
== '"' && ptr
[1] == '"' && ptr
[2] == '"')
4412 tmp
= strstr (ptr
+ 2, "\"\"\"");
4418 /* Replace a single '=' with a '==';
4419 for compatibility with older code only. */
4420 if (line_conditional
&& current_char
== '=')
4428 tmp
= concat (head
, "==", ptr
, (char *) NULL
);
4429 /* Continue examining after the '=='. */
4430 ptr
= tmp
+ strlen (head
) + 2;
4432 head
= replacement
= tmp
;
4436 /* Flag when we've reached the symbol part of .eval/.asg. */
4437 if (eval_line
&& ptr
>= eval_end
)
4440 /* For each apparent symbol, see if it's a substitution symbol, and if
4441 so, replace it in the input. */
4442 if ((forced
&& current_char
== ':')
4443 || (!forced
&& is_name_beginner (current_char
)))
4445 char *name
; /* Symbol to be replaced. */
4446 char *savedp
= input_line_pointer
;
4449 char *tail
; /* Rest of line after symbol. */
4451 /* Skip the colon. */
4455 input_line_pointer
= ptr
;
4456 c
= get_symbol_name (&name
);
4457 /* '?' is not normally part of a symbol, but it IS part of a local
4461 *input_line_pointer
++ = c
;
4462 c
= *input_line_pointer
;
4463 *input_line_pointer
= '\0';
4465 /* Avoid infinite recursion; if a symbol shows up a second time for
4466 substitution, leave it as is. */
4467 if (str_hash_find (subsym_recurse_hash
, name
) == NULL
)
4468 value
= subsym_lookup (name
, macro_level
);
4470 as_warn (_("%s symbol recursion stopped at "
4471 "second appearance of '%s'"),
4472 forced
? "Forced substitution" : "Substitution", name
);
4473 ptr
= tail
= input_line_pointer
;
4474 input_line_pointer
= savedp
;
4476 /* Check for local labels; replace them with the appropriate
4478 if ((*name
== '$' && ISDIGIT (name
[1]) && name
[2] == '\0')
4479 || name
[strlen (name
) - 1] == '?')
4481 /* Use an existing identifier for that label if, available, or
4482 create a new, unique identifier. */
4483 value
= str_hash_find (local_label_hash
[macro_level
], name
);
4487 char *namecopy
= xstrdup (name
);
4489 value
= strcpy (xmalloc (strlen (name
) + sizeof (digit
) + 1),
4492 value
[strlen (value
) - 1] = '\0';
4493 sprintf (digit
, ".%d", local_label_id
++);
4494 strcat (value
, digit
);
4495 str_hash_insert (local_label_hash
[macro_level
],
4496 namecopy
, value
, 0);
4498 /* Indicate where to continue looking for substitutions. */
4501 /* Check for built-in subsym and math functions. */
4502 else if (value
!= NULL
&& *name
== '$')
4504 subsym_proc_entry
*entry
= (subsym_proc_entry
*) value
;
4505 math_proc_entry
*math_entry
= str_hash_find (math_hash
, name
);
4506 char *arg1
, *arg2
= NULL
;
4511 as_bad (_("Unrecognized substitution symbol function"));
4514 else if (*ptr
!= '(')
4516 as_bad (_("Missing '(' after substitution symbol function"));
4520 if (math_entry
!= NULL
)
4522 float farg1
, farg2
= 0;
4523 volatile float fresult
;
4525 farg1
= (float) strtod (ptr
, &ptr
);
4526 if (math_entry
->nargs
== 2)
4530 as_bad (_("Expecting second argument"));
4533 farg2
= (float) strtod (ptr
, &ptr
);
4535 fresult
= (*math_entry
->proc
) (farg1
, farg2
);
4536 value
= XNEWVEC (char, 128);
4537 if (math_entry
->int_return
)
4538 sprintf (value
, "%d", (int) fresult
);
4540 sprintf (value
, "%f", fresult
);
4543 as_bad (_("Extra junk in function call, expecting ')'"));
4546 /* Don't bother recursing; the replacement isn't a
4553 int arg_type
[2] = { *ptr
== '"' , 0 };
4554 int ismember
= !strcmp (entry
->name
, "$ismember");
4556 /* Parse one or two args, which must be a substitution
4557 symbol, string or a character-string constant. */
4558 /* For all functions, a string or substitution symbol may be
4559 used, with the following exceptions:
4560 firstch/lastch: 2nd arg must be character constant
4561 ismember: both args must be substitution symbols. */
4562 ptr
= subsym_get_arg (ptr
, ",)", &arg1
, ismember
);
4565 if (entry
->nargs
== 2)
4569 as_bad (_("Function expects two arguments"));
4572 /* Character constants are converted to numerics
4573 by the preprocessor. */
4574 arg_type
[1] = (ISDIGIT (*ptr
)) ? 2 : (*ptr
== '"');
4575 ptr
= subsym_get_arg (ptr
, ")", &arg2
, ismember
);
4577 /* Args checking. */
4578 if ((!strcmp (entry
->name
, "$firstch")
4579 || !strcmp (entry
->name
, "$lastch"))
4580 && arg_type
[1] != 2)
4582 as_bad (_("Expecting character constant argument"));
4586 && (arg_type
[0] != 0 || arg_type
[1] != 0))
4588 as_bad (_("Both arguments must be substitution symbols"));
4593 as_bad (_("Extra junk in function call, expecting ')'"));
4596 val
= (*entry
->proc
) (arg1
, arg2
);
4597 value
= XNEWVEC (char, 64);
4598 sprintf (value
, "%d", val
);
4600 /* Fix things up to replace the entire expression, not just the
4606 if (value
!= NULL
&& !eval_symbol
)
4608 /* Replace the symbol with its string replacement and
4609 continue. Recursively replace VALUE until either no
4610 substitutions are performed, or a substitution that has been
4611 previously made is encountered again.
4613 Put the symbol into the recursion hash table so we only
4614 try to replace a symbol once. */
4617 str_hash_insert (subsym_recurse_hash
, name
, name
, 0);
4618 value
= subsym_substitute (value
, macro_level
> 0);
4619 str_hash_delete (subsym_recurse_hash
, name
);
4622 /* Temporarily zero-terminate where the symbol started. */
4628 /* Subscripted substitution symbol -- use just the
4629 indicated portion of the string; the description
4630 kinda indicates that forced substitution is not
4631 supposed to be recursive, but I'm not sure. */
4632 unsigned beg
, len
= 1; /* default to a single char */
4633 char *newval
= xstrdup (value
);
4635 savedp
= input_line_pointer
;
4636 input_line_pointer
= tail
+ 1;
4637 beg
= get_absolute_expression ();
4640 as_bad (_("Invalid subscript (use 1 to %d)"),
4641 (int) strlen (value
));
4644 if (*input_line_pointer
== ',')
4646 ++input_line_pointer
;
4647 len
= get_absolute_expression ();
4648 if (beg
+ len
> strlen (value
))
4650 as_bad (_("Invalid length (use 0 to %d)"),
4651 (int) strlen (value
) - beg
);
4657 tail
= input_line_pointer
;
4660 as_bad (_("Missing ')' in subscripted substitution "
4661 "symbol expression"));
4665 input_line_pointer
= savedp
;
4671 tmp
= xmalloc (strlen (head
) + strlen (value
) +
4672 strlen (tail
+ 1) + 2);
4674 strcat (tmp
, value
);
4675 /* Make sure forced substitutions are properly terminated. */
4680 as_bad (_("Missing forced substitution terminator ':'"));
4686 /* Restore the character after the symbol end. */
4689 /* Continue examining after the replacement value. */
4690 ptr
= tmp
+ strlen (head
) + strlen (value
);
4692 head
= replacement
= tmp
;
4710 /* We use this to handle substitution symbols
4711 hijack input_line_pointer, replacing it with our substituted string.
4713 .sslist should enable listing the line after replacements are made...
4715 returns the new buffer limit. */
4718 tic54x_start_line_hook (void)
4721 char *replacement
= NULL
;
4723 /* Work with a copy of the input line, including EOL char. */
4724 for (endp
= input_line_pointer
; *endp
!= 0; )
4725 if (is_end_of_line
[(unsigned char) *endp
++])
4728 line
= xmemdup0 (input_line_pointer
, endp
- input_line_pointer
);
4730 /* Scan ahead for parallel insns. */
4731 parallel_on_next_line_hint
= next_line_shows_parallel (endp
);
4733 /* If within a macro, first process forced replacements. */
4734 if (macro_level
> 0)
4735 replacement
= subsym_substitute (line
, 1);
4738 replacement
= subsym_substitute (replacement
, 0);
4740 if (replacement
!= line
)
4742 char *tmp
= replacement
;
4743 char *comment
= strchr (replacement
, ';');
4744 char endc
= replacement
[strlen (replacement
) - 1];
4746 /* Clean up the replacement; we'd prefer to have this done by the
4747 standard preprocessing equipment (maybe do_scrub_chars?)
4748 but for now, do a quick-and-dirty. */
4749 if (comment
!= NULL
)
4756 comment
= replacement
+ strlen (replacement
) - 1;
4758 /* Trim trailing whitespace. */
4759 while (ISSPACE (*comment
))
4766 /* Compact leading whitespace. */
4767 while (ISSPACE (tmp
[0]) && ISSPACE (tmp
[1]))
4770 input_line_pointer
= endp
;
4771 input_scrub_insert_line (tmp
);
4774 /* Keep track of whether we've done a substitution. */
4775 substitution_line
= 1;
4781 substitution_line
= 0;
4785 /* This is the guts of the machine-dependent assembler. STR points to a
4786 machine dependent instruction. This function is supposed to emit
4787 the frags/bytes it assembles to. */
4789 md_assemble (char *line
)
4791 static int repeat_slot
= 0;
4792 static int delay_slots
= 0; /* How many delay slots left to fill? */
4793 static int is_parallel
= 0;
4794 static tic54x_insn insn
;
4796 char *savedp
= input_line_pointer
;
4799 input_line_pointer
= line
;
4800 c
= get_symbol_name (&line
);
4804 if (address_mode_needs_set
)
4806 set_address_mode (amode
);
4807 address_mode_needs_set
= 0;
4820 strcpy (insn
.parmnemonic
, line
);
4821 lptr
= input_line_pointer
;
4823 input_line_pointer
= savedp
;
4825 if (tic54x_parse_parallel_insn_lastline (&insn
, lptr
))
4827 int words
= build_insn (&insn
);
4829 if (delay_slots
!= 0)
4831 if (words
> delay_slots
)
4833 as_bad (ngettext ("Instruction does not fit in available "
4834 "delay slots (%d-word insn, %d slot left)",
4835 "Instruction does not fit in available "
4836 "delay slots (%d-word insn, %d slots left)",
4838 words
, delay_slots
);
4842 delay_slots
-= words
;
4848 memset (&insn
, 0, sizeof (insn
));
4849 strcpy (insn
.mnemonic
, line
);
4850 lptr
= input_line_pointer
;
4852 input_line_pointer
= savedp
;
4854 /* See if this line is part of a parallel instruction; if so, either this
4855 line or the next line will have the "||" specifier preceding the
4856 mnemonic, and we look for it in the parallel insn hash table. */
4857 if (strstr (line
, "||") != NULL
|| parallel_on_next_line_hint
)
4859 char *tmp
= strstr (line
, "||");
4863 if (tic54x_parse_parallel_insn_firstline (&insn
, lptr
))
4866 /* If the parallel part is on the same line, process it now,
4867 otherwise let the assembler pick up the next line for us. */
4870 while (ISSPACE (tmp
[2]))
4872 md_assemble (tmp
+ 2);
4877 as_bad (_("Unrecognized parallel instruction '%s'"), line
);
4882 if (tic54x_parse_insn (&insn
, lptr
))
4886 if ((insn
.tm
->flags
& FL_LP
)
4887 && cpu
!= V545LP
&& cpu
!= V546LP
)
4889 as_bad (_("Instruction '%s' requires an LP cpu version"),
4893 if ((insn
.tm
->flags
& FL_FAR
)
4894 && amode
!= far_mode
)
4896 as_bad (_("Instruction '%s' requires far mode addressing"),
4901 words
= build_insn (&insn
);
4903 /* Is this instruction in a delay slot? */
4906 if (words
> delay_slots
)
4908 as_warn (ngettext ("Instruction does not fit in available "
4909 "delay slots (%d-word insn, %d slot left). "
4910 "Resulting behavior is undefined.",
4911 "Instruction does not fit in available "
4912 "delay slots (%d-word insn, %d slots left). "
4913 "Resulting behavior is undefined.",
4915 words
, delay_slots
);
4919 /* Branches in delay slots are not allowed. */
4920 if (insn
.tm
->flags
& FL_BMASK
)
4922 as_warn (_("Instructions which cause PC discontinuity are not "
4923 "allowed in a delay slot. "
4924 "Resulting behavior is undefined."));
4926 delay_slots
-= words
;
4929 /* Is this instruction the target of a repeat? */
4932 if (insn
.tm
->flags
& FL_NR
)
4933 as_warn (_("'%s' is not repeatable. "
4934 "Resulting behavior is undefined."),
4936 else if (insn
.is_lkaddr
)
4937 as_warn (_("Instructions using long offset modifiers or absolute "
4938 "addresses are not repeatable. "
4939 "Resulting behavior is undefined."));
4943 /* Make sure we check the target of a repeat instruction. */
4944 if (insn
.tm
->flags
& B_REPEAT
)
4947 /* FIXME -- warn if repeat_slot == 1 at EOF. */
4949 /* Make sure we check our delay slots for validity. */
4950 if (insn
.tm
->flags
& FL_DELAY
)
4953 /* FIXME -- warn if delay_slots != 0 at EOF. */
4958 /* Do a final adjustment on the symbol table; in this case, make sure we have
4959 a ".file" symbol. */
4962 tic54x_adjust_symtab (void)
4964 if (symbol_rootP
== NULL
4965 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
4968 const char * filename
= as_where (&lineno
);
4969 c_dot_file_symbol (filename
);
4973 /* In order to get gas to ignore any | chars at the start of a line,
4974 this function returns true if a | is found in a line.
4975 This lets us process parallel instructions, which span two lines. */
4978 tic54x_unrecognized_line (int c
)
4980 return c
== PARALLEL_SEPARATOR
;
4983 /* Watch for local labels of the form $[0-9] and [_a-zA-Z][_a-zA-Z0-9]*?
4984 Encode their names so that only we see them and can map them to the
4986 FIXME -- obviously this isn't done yet. These locals still show up in the
4989 tic54x_define_label (symbolS
*sym
)
4991 /* Just in case we need this later; note that this is not necessarily the
4992 same thing as line_label...
4993 When aligning or assigning labels to fields, sometimes the label is
4994 assigned other than the address at which the label appears.
4995 FIXME -- is this really needed? I think all the proper label assignment
4996 is done in tic54x_cons. */
4997 last_label_seen
= sym
;
5000 /* Try to parse something that normal parsing failed at. */
5003 tic54x_undefined_symbol (char *name
)
5007 /* Not sure how to handle predefined symbols. */
5008 if ((sym
= (tic54x_symbol
*) str_hash_find (cc_hash
, name
)) != NULL
5009 || (sym
= (tic54x_symbol
*) str_hash_find (cc2_hash
, name
)) != NULL
5010 || (sym
= (tic54x_symbol
*) str_hash_find (cc3_hash
, name
)) != NULL
5011 || str_hash_find (misc_symbol_hash
, name
) != NULL
5012 || (sym
= (tic54x_symbol
*) str_hash_find (sbit_hash
, name
)) != NULL
5013 || (sym
= (tic54x_symbol
*) str_hash_find (reg_hash
, name
)) != NULL
5014 || (sym
= (tic54x_symbol
*) str_hash_find (mmreg_hash
, name
)) != NULL
5015 || !strcasecmp (name
, "a")
5016 || !strcasecmp (name
, "b"))
5018 return symbol_new (name
, reg_section
, &zero_address_frag
,
5019 sym
? sym
->value
: 0);
5025 /* Parse a name in an expression before the expression parser takes a stab at
5029 tic54x_parse_name (char *name ATTRIBUTE_UNUSED
,
5030 expressionS
*expn ATTRIBUTE_UNUSED
)
5036 md_atof (int type
, char *literalP
, int *sizeP
)
5038 /* Target data is little-endian, but floats are stored
5039 big-"word"ian. ugh. */
5040 return ieee_md_atof (type
, literalP
, sizeP
, true);
5044 tc_gen_reloc (asection
*section
, fixS
*fixP
)
5047 bfd_reloc_code_real_type code
= fixP
->fx_r_type
;
5048 asymbol
*sym
= symbol_get_bfdsym (fixP
->fx_addsy
);
5050 rel
= XNEW (arelent
);
5051 rel
->sym_ptr_ptr
= XNEW (asymbol
*);
5052 *rel
->sym_ptr_ptr
= sym
;
5053 /* We assume that all rel->address are host byte offsets. */
5054 rel
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5055 rel
->address
/= OCTETS_PER_BYTE
;
5056 rel
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
5057 if (!strcmp (sym
->name
, section
->name
))
5058 rel
->howto
+= HOWTO_BANK
;
5062 const char *name
= S_GET_NAME (fixP
->fx_addsy
);
5065 as_fatal ("Cannot generate relocation type for symbol %s, code %s",
5066 name
, bfd_get_reloc_code_name (code
));
5072 /* Handle cons expressions. */
5075 tic54x_cons_fix_new (fragS
*frag
, int where
, int octets
, expressionS
*expn
,
5076 bfd_reloc_code_real_type r
)
5081 as_bad (_("Unsupported relocation size %d"), octets
);
5082 r
= BFD_RELOC_TIC54X_16_OF_23
;
5085 r
= BFD_RELOC_TIC54X_16_OF_23
;
5088 /* TI assembler always uses this, regardless of addressing mode. */
5090 r
= BFD_RELOC_TIC54X_23
;
5092 /* We never want to directly generate this; this is provided for
5093 stabs support only. */
5097 fix_new_exp (frag
, where
, octets
, expn
, 0, r
);
5100 /* Attempt to simplify or even eliminate a fixup.
5101 To indicate that a fixup has been eliminated, set fixP->fx_done.
5103 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry. */
5106 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
5108 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
5109 valueT val
= * valP
;
5111 switch (fixP
->fx_r_type
)
5114 as_fatal ("Bad relocation type: 0x%02x", fixP
->fx_r_type
);
5116 case BFD_RELOC_TIC54X_MS7_OF_23
:
5117 val
= (val
>> 16) & 0x7F;
5119 case BFD_RELOC_TIC54X_16_OF_23
:
5121 bfd_put_16 (stdoutput
, val
, buf
);
5122 /* Indicate what we're actually writing, so that we don't get warnings
5123 about exceeding available space. */
5124 *valP
= val
& 0xFFFF;
5126 case BFD_RELOC_TIC54X_PARTLS7
:
5127 bfd_put_16 (stdoutput
,
5128 (bfd_get_16 (stdoutput
, buf
) & 0xFF80) | (val
& 0x7F),
5130 /* Indicate what we're actually writing, so that we don't get warnings
5131 about exceeding available space. */
5134 case BFD_RELOC_TIC54X_PARTMS9
:
5135 /* TI assembler doesn't shift its encoding for relocatable files, and is
5136 thus incompatible with this implementation's relocatable files. */
5137 bfd_put_16 (stdoutput
,
5138 (bfd_get_16 (stdoutput
, buf
) & 0xFE00) | (val
>> 7),
5142 case BFD_RELOC_TIC54X_23
:
5143 bfd_put_32 (stdoutput
,
5144 (bfd_get_32 (stdoutput
, buf
) & 0xFF800000) | val
,
5149 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
5153 /* This is our chance to record section alignment
5154 don't need to do anything here, since BFD does the proper encoding. */
5157 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT section_size
)
5159 return section_size
;
5163 md_pcrel_from (fixS
*fixP ATTRIBUTE_UNUSED
)
5168 /* Mostly little-endian, but longwords (4 octets) get MS word stored
5172 tic54x_number_to_chars (char *buf
, valueT val
, int n
)
5175 number_to_chars_littleendian (buf
, val
, n
);
5178 number_to_chars_littleendian (buf
, val
>> 16 , 2);
5179 number_to_chars_littleendian (buf
+ 2, val
& 0xFFFF, 2);
5184 tic54x_estimate_size_before_relax (fragS
*frag ATTRIBUTE_UNUSED
,
5185 segT seg ATTRIBUTE_UNUSED
)
5190 /* We use this to handle bit allocations which we couldn't handle before due
5191 to symbols being in different frags. return number of octets added. */
5194 tic54x_relax_frag (fragS
*frag
, long stretch ATTRIBUTE_UNUSED
)
5196 symbolS
*sym
= frag
->fr_symbol
;
5202 struct bit_info
*bi
= (struct bit_info
*) frag
->fr_opcode
;
5203 int bit_offset
= frag_bit_offset (frag_prev (frag
, bi
->seg
), bi
->seg
);
5204 int size
= S_GET_VALUE (sym
);
5205 fragS
*prev_frag
= bit_offset_frag (frag_prev (frag
, bi
->seg
), bi
->seg
);
5206 int available
= 16 - bit_offset
;
5208 if (symbol_get_frag (sym
) != &zero_address_frag
5209 || S_IS_COMMON (sym
)
5210 || !S_IS_DEFINED (sym
))
5211 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5212 _("non-absolute value used with .space/.bes"));
5216 as_warn (_("negative value ignored in %s"),
5217 bi
->type
== TYPE_SPACE
? ".space" :
5218 bi
->type
== TYPE_BES
? ".bes" : ".field");
5220 frag
->tc_frag_data
= frag
->fr_fix
= 0;
5224 if (bi
->type
== TYPE_FIELD
)
5226 /* Bit fields of 16 or larger will have already been handled. */
5227 if (bit_offset
!= 0 && available
>= size
)
5229 char *p
= prev_frag
->fr_literal
;
5231 valueT value
= bi
->value
;
5232 value
<<= available
- size
;
5233 value
|= ((unsigned short) p
[1] << 8) | p
[0];
5234 md_number_to_chars (p
, value
, 2);
5235 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5236 prev_frag
->tc_frag_data
= 0;
5238 symbol_set_frag (bi
->sym
, prev_frag
);
5239 /* This frag is no longer used. */
5240 growth
= -frag
->fr_fix
;
5242 frag
->tc_frag_data
= 0;
5246 char *p
= frag
->fr_literal
;
5248 valueT value
= bi
->value
<< (16 - size
);
5249 md_number_to_chars (p
, value
, 2);
5250 if ((frag
->tc_frag_data
= size
) == 16)
5251 frag
->tc_frag_data
= 0;
5257 if (bit_offset
!= 0 && bit_offset
< 16)
5259 if (available
>= size
)
5261 if ((prev_frag
->tc_frag_data
+= size
) == 16)
5262 prev_frag
->tc_frag_data
= 0;
5264 symbol_set_frag (bi
->sym
, prev_frag
);
5265 /* This frag is no longer used. */
5266 growth
= -frag
->fr_fix
;
5268 frag
->tc_frag_data
= 0;
5271 if (bi
->type
== TYPE_SPACE
&& bi
->sym
)
5272 symbol_set_frag (bi
->sym
, prev_frag
);
5275 growth
= (size
+ 15) / 16 * OCTETS_PER_BYTE
- frag
->fr_fix
;
5276 for (i
= 0; i
< growth
; i
++)
5277 frag
->fr_literal
[i
] = 0;
5278 frag
->fr_fix
= growth
;
5279 frag
->tc_frag_data
= size
% 16;
5280 /* Make sure any BES label points to the LAST word allocated. */
5281 if (bi
->type
== TYPE_BES
&& bi
->sym
)
5282 S_SET_VALUE (bi
->sym
, frag
->fr_fix
/ OCTETS_PER_BYTE
- 1);
5285 frag
->fr_symbol
= 0;
5286 frag
->fr_opcode
= 0;
5293 tic54x_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5294 segT seg ATTRIBUTE_UNUSED
,
5297 /* Offset is in bytes. */
5298 frag
->fr_offset
= (frag
->fr_next
->fr_address
5300 - frag
->fr_fix
) / frag
->fr_var
;
5301 if (frag
->fr_offset
< 0)
5303 as_bad_where (frag
->fr_file
, frag
->fr_line
,
5304 _("attempt to .space/.bes backwards? (%ld)"),
5305 (long) frag
->fr_offset
);
5307 frag
->fr_type
= rs_space
;
5310 /* We need to avoid having labels defined for certain directives/pseudo-ops
5311 since once the label is defined, it's in the symbol table for good. TI
5312 syntax puts the symbol *before* the pseudo (which is kinda like MRI syntax,
5313 I guess, except I've never seen a definition of MRI syntax).
5315 Don't allow labels to start with '.' */
5318 tic54x_start_label (char * label_start
, int nul_char
, int next_char
)
5322 /* If within .struct/.union, no auto line labels, please. */
5323 if (current_stag
!= NULL
)
5326 /* Disallow labels starting with "." */
5327 if (next_char
!= ':')
5329 if (*label_start
== '.')
5331 as_bad (_("Invalid label '%s'"), label_start
);
5336 if (is_end_of_line
[(unsigned char) next_char
])
5339 rest
= input_line_pointer
;
5340 if (nul_char
== '"')
5342 while (ISSPACE (next_char
))
5343 next_char
= *++rest
;
5344 if (next_char
!= '.')
5347 /* Don't let colon () define a label for any of these... */
5348 return ((strncasecmp (rest
, ".tag", 4) != 0 || !ISSPACE (rest
[4]))
5349 && (strncasecmp (rest
, ".struct", 7) != 0 || !ISSPACE (rest
[7]))
5350 && (strncasecmp (rest
, ".union", 6) != 0 || !ISSPACE (rest
[6]))
5351 && (strncasecmp (rest
, ".macro", 6) != 0 || !ISSPACE (rest
[6]))
5352 && (strncasecmp (rest
, ".set", 4) != 0 || !ISSPACE (rest
[4]))
5353 && (strncasecmp (rest
, ".equ", 4) != 0 || !ISSPACE (rest
[4])));