xref: /openbsd-src/gnu/usr.bin/binutils-2.17/gas/config/tc-tic4x.c (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* tc-tic4x.c -- Assemble for the Texas Instruments TMS320C[34]x.
2*3d8817e4Smiod    Copyright (C) 1997,1998, 2002, 2003, 2005 Free Software Foundation.
3*3d8817e4Smiod 
4*3d8817e4Smiod    Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
5*3d8817e4Smiod 
6*3d8817e4Smiod    This file is part of GAS, the GNU Assembler.
7*3d8817e4Smiod 
8*3d8817e4Smiod    GAS is free software; you can redistribute it and/or modify
9*3d8817e4Smiod    it under the terms of the GNU General Public License as published by
10*3d8817e4Smiod    the Free Software Foundation; either version 2, or (at your option)
11*3d8817e4Smiod    any later version.
12*3d8817e4Smiod 
13*3d8817e4Smiod    GAS is distributed in the hope that it will be useful,
14*3d8817e4Smiod    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*3d8817e4Smiod    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*3d8817e4Smiod    GNU General Public License for more details.
17*3d8817e4Smiod 
18*3d8817e4Smiod    You should have received a copy of the GNU General Public License
19*3d8817e4Smiod    along with GAS; see the file COPYING.  If not, write to
20*3d8817e4Smiod    the Free Software Foundation, 51 Franklin Street - Fifth Floor,
21*3d8817e4Smiod    Boston, MA 02110-1301, USA.  */
22*3d8817e4Smiod /*
23*3d8817e4Smiod   TODOs:
24*3d8817e4Smiod   ------
25*3d8817e4Smiod 
26*3d8817e4Smiod   o .align cannot handle fill-data-width larger than 0xFF/8-bits. It
27*3d8817e4Smiod     should be possible to define a 32-bits pattern.
28*3d8817e4Smiod 
29*3d8817e4Smiod   o .align fills all section with NOP's when used regardless if has
30*3d8817e4Smiod     been used in .text or .data. (However the .align is primarily
31*3d8817e4Smiod     intended used in .text sections. If you require something else,
32*3d8817e4Smiod     use .align <size>,0x00)
33*3d8817e4Smiod 
34*3d8817e4Smiod   o .align: Implement a 'bu' insn if the number of nop's exceeds 4
35*3d8817e4Smiod     within the align frag. if(fragsize>4words) insert bu fragend+1
36*3d8817e4Smiod     first.
37*3d8817e4Smiod 
38*3d8817e4Smiod   o .usect if has symbol on previous line not implemented
39*3d8817e4Smiod 
40*3d8817e4Smiod   o .sym, .eos, .stag, .etag, .member not implemented
41*3d8817e4Smiod 
42*3d8817e4Smiod   o Evaluation of constant floating point expressions (expr.c needs
43*3d8817e4Smiod     work!)
44*3d8817e4Smiod 
45*3d8817e4Smiod   o Support 'abc' constants (that is 0x616263)
46*3d8817e4Smiod */
47*3d8817e4Smiod 
48*3d8817e4Smiod #include <stdio.h>
49*3d8817e4Smiod #include "safe-ctype.h"
50*3d8817e4Smiod #include "as.h"
51*3d8817e4Smiod #include "opcode/tic4x.h"
52*3d8817e4Smiod #include "subsegs.h"
53*3d8817e4Smiod #include "obstack.h"
54*3d8817e4Smiod #include "symbols.h"
55*3d8817e4Smiod #include "listing.h"
56*3d8817e4Smiod 
57*3d8817e4Smiod /* OK, we accept a syntax similar to the other well known C30
58*3d8817e4Smiod    assembly tools.  With TIC4X_ALT_SYNTAX defined we are more
59*3d8817e4Smiod    flexible, allowing a more Unix-like syntax:  `%' in front of
60*3d8817e4Smiod    register names, `#' in front of immediate constants, and
61*3d8817e4Smiod    not requiring `@' in front of direct addresses.  */
62*3d8817e4Smiod 
63*3d8817e4Smiod #define TIC4X_ALT_SYNTAX
64*3d8817e4Smiod 
65*3d8817e4Smiod /* Equal to MAX_PRECISION in atof-ieee.c.  */
66*3d8817e4Smiod #define MAX_LITTLENUMS 6	/* (12 bytes) */
67*3d8817e4Smiod 
68*3d8817e4Smiod /* Handle of the inst mnemonic hash table.  */
69*3d8817e4Smiod static struct hash_control *tic4x_op_hash = NULL;
70*3d8817e4Smiod 
71*3d8817e4Smiod /* Handle asg pseudo.  */
72*3d8817e4Smiod static struct hash_control *tic4x_asg_hash = NULL;
73*3d8817e4Smiod 
74*3d8817e4Smiod static unsigned int tic4x_cpu = 0;        /* Default to TMS320C40.  */
75*3d8817e4Smiod static unsigned int tic4x_revision = 0;   /* CPU revision */
76*3d8817e4Smiod static unsigned int tic4x_idle2 = 0;      /* Idle2 support */
77*3d8817e4Smiod static unsigned int tic4x_lowpower = 0;   /* Lowpower support */
78*3d8817e4Smiod static unsigned int tic4x_enhanced = 0;   /* Enhanced opcode support */
79*3d8817e4Smiod static unsigned int tic4x_big_model = 0;  /* Default to small memory model.  */
80*3d8817e4Smiod static unsigned int tic4x_reg_args = 0;   /* Default to args passed on stack.  */
81*3d8817e4Smiod static unsigned long tic4x_oplevel = 0;   /* Opcode level */
82*3d8817e4Smiod 
83*3d8817e4Smiod #define OPTION_CPU      'm'
84*3d8817e4Smiod #define OPTION_BIG      (OPTION_MD_BASE + 1)
85*3d8817e4Smiod #define OPTION_SMALL    (OPTION_MD_BASE + 2)
86*3d8817e4Smiod #define OPTION_MEMPARM  (OPTION_MD_BASE + 3)
87*3d8817e4Smiod #define OPTION_REGPARM  (OPTION_MD_BASE + 4)
88*3d8817e4Smiod #define OPTION_IDLE2    (OPTION_MD_BASE + 5)
89*3d8817e4Smiod #define OPTION_LOWPOWER (OPTION_MD_BASE + 6)
90*3d8817e4Smiod #define OPTION_ENHANCED (OPTION_MD_BASE + 7)
91*3d8817e4Smiod #define OPTION_REV      (OPTION_MD_BASE + 8)
92*3d8817e4Smiod 
93*3d8817e4Smiod CONST char *md_shortopts = "bm:prs";
94*3d8817e4Smiod struct option md_longopts[] =
95*3d8817e4Smiod {
96*3d8817e4Smiod   { "mcpu",   required_argument, NULL, OPTION_CPU },
97*3d8817e4Smiod   { "mdsp",   required_argument, NULL, OPTION_CPU },
98*3d8817e4Smiod   { "mbig",         no_argument, NULL, OPTION_BIG },
99*3d8817e4Smiod   { "msmall",       no_argument, NULL, OPTION_SMALL },
100*3d8817e4Smiod   { "mmemparm",     no_argument, NULL, OPTION_MEMPARM },
101*3d8817e4Smiod   { "mregparm",     no_argument, NULL, OPTION_REGPARM },
102*3d8817e4Smiod   { "midle2",       no_argument, NULL, OPTION_IDLE2 },
103*3d8817e4Smiod   { "mlowpower",    no_argument, NULL, OPTION_LOWPOWER },
104*3d8817e4Smiod   { "menhanced",    no_argument, NULL, OPTION_ENHANCED },
105*3d8817e4Smiod   { "mrev",   required_argument, NULL, OPTION_REV },
106*3d8817e4Smiod   { NULL, no_argument, NULL, 0 }
107*3d8817e4Smiod };
108*3d8817e4Smiod 
109*3d8817e4Smiod size_t md_longopts_size = sizeof (md_longopts);
110*3d8817e4Smiod 
111*3d8817e4Smiod 
112*3d8817e4Smiod typedef enum
113*3d8817e4Smiod   {
114*3d8817e4Smiod     M_UNKNOWN, M_IMMED, M_DIRECT, M_REGISTER, M_INDIRECT,
115*3d8817e4Smiod     M_IMMED_F, M_PARALLEL, M_HI
116*3d8817e4Smiod   }
117*3d8817e4Smiod tic4x_addr_mode_t;
118*3d8817e4Smiod 
119*3d8817e4Smiod typedef struct tic4x_operand
120*3d8817e4Smiod   {
121*3d8817e4Smiod     tic4x_addr_mode_t mode;	/* Addressing mode.  */
122*3d8817e4Smiod     expressionS expr;		/* Expression.  */
123*3d8817e4Smiod     int disp;			/* Displacement for indirect addressing.  */
124*3d8817e4Smiod     int aregno;			/* Aux. register number.  */
125*3d8817e4Smiod     LITTLENUM_TYPE fwords[MAX_LITTLENUMS];	/* Float immed. number.  */
126*3d8817e4Smiod   }
127*3d8817e4Smiod tic4x_operand_t;
128*3d8817e4Smiod 
129*3d8817e4Smiod typedef struct tic4x_insn
130*3d8817e4Smiod   {
131*3d8817e4Smiod     char name[TIC4X_NAME_MAX];	/* Mnemonic of instruction.  */
132*3d8817e4Smiod     unsigned int in_use;	/* True if in_use.  */
133*3d8817e4Smiod     unsigned int parallel;	/* True if parallel instruction.  */
134*3d8817e4Smiod     unsigned int nchars;	/* This is always 4 for the C30.  */
135*3d8817e4Smiod     unsigned long opcode;	/* Opcode number.  */
136*3d8817e4Smiod     expressionS exp;		/* Expression required for relocation.  */
137*3d8817e4Smiod     int reloc;			/* Relocation type required.  */
138*3d8817e4Smiod     int pcrel;			/* True if relocation PC relative.  */
139*3d8817e4Smiod     char *pname;		/* Name of instruction in parallel.  */
140*3d8817e4Smiod     unsigned int num_operands;	/* Number of operands in total.  */
141*3d8817e4Smiod     tic4x_inst_t *inst;		/* Pointer to first template.  */
142*3d8817e4Smiod     tic4x_operand_t operands[TIC4X_OPERANDS_MAX];
143*3d8817e4Smiod   }
144*3d8817e4Smiod tic4x_insn_t;
145*3d8817e4Smiod 
146*3d8817e4Smiod static tic4x_insn_t the_insn;	/* Info about our instruction.  */
147*3d8817e4Smiod static tic4x_insn_t *insn = &the_insn;
148*3d8817e4Smiod 
149*3d8817e4Smiod static int tic4x_gen_to_words
150*3d8817e4Smiod   PARAMS ((FLONUM_TYPE, LITTLENUM_TYPE *, int ));
151*3d8817e4Smiod static char *tic4x_atof
152*3d8817e4Smiod   PARAMS ((char *, char, LITTLENUM_TYPE * ));
153*3d8817e4Smiod static void tic4x_insert_reg
154*3d8817e4Smiod   PARAMS ((char *, int ));
155*3d8817e4Smiod static void tic4x_insert_sym
156*3d8817e4Smiod   PARAMS ((char *, int ));
157*3d8817e4Smiod static char *tic4x_expression
158*3d8817e4Smiod   PARAMS ((char *, expressionS *));
159*3d8817e4Smiod static char *tic4x_expression_abs
160*3d8817e4Smiod   PARAMS ((char *, offsetT *));
161*3d8817e4Smiod static void tic4x_emit_char
162*3d8817e4Smiod   PARAMS ((char, int));
163*3d8817e4Smiod static void tic4x_seg_alloc
164*3d8817e4Smiod   PARAMS ((char *, segT, int, symbolS *));
165*3d8817e4Smiod static void tic4x_asg
166*3d8817e4Smiod   PARAMS ((int));
167*3d8817e4Smiod static void tic4x_bss
168*3d8817e4Smiod   PARAMS ((int));
169*3d8817e4Smiod static void tic4x_globl
170*3d8817e4Smiod   PARAMS ((int));
171*3d8817e4Smiod static void tic4x_cons
172*3d8817e4Smiod   PARAMS ((int));
173*3d8817e4Smiod static void tic4x_stringer
174*3d8817e4Smiod   PARAMS ((int));
175*3d8817e4Smiod static void tic4x_eval
176*3d8817e4Smiod   PARAMS ((int));
177*3d8817e4Smiod static void tic4x_newblock
178*3d8817e4Smiod   PARAMS ((int));
179*3d8817e4Smiod static void tic4x_sect
180*3d8817e4Smiod   PARAMS ((int));
181*3d8817e4Smiod static void tic4x_set
182*3d8817e4Smiod   PARAMS ((int));
183*3d8817e4Smiod static void tic4x_usect
184*3d8817e4Smiod   PARAMS ((int));
185*3d8817e4Smiod static void tic4x_version
186*3d8817e4Smiod   PARAMS ((int));
187*3d8817e4Smiod static void tic4x_init_regtable
188*3d8817e4Smiod   PARAMS ((void));
189*3d8817e4Smiod static void tic4x_init_symbols
190*3d8817e4Smiod   PARAMS ((void));
191*3d8817e4Smiod static int tic4x_inst_insert
192*3d8817e4Smiod   PARAMS ((tic4x_inst_t *));
193*3d8817e4Smiod static tic4x_inst_t *tic4x_inst_make
194*3d8817e4Smiod   PARAMS ((char *, unsigned long, char *));
195*3d8817e4Smiod static int tic4x_inst_add
196*3d8817e4Smiod   PARAMS ((tic4x_inst_t *));
197*3d8817e4Smiod void tic4x_end
198*3d8817e4Smiod   PARAMS ((void));
199*3d8817e4Smiod static int tic4x_indirect_parse
200*3d8817e4Smiod   PARAMS ((tic4x_operand_t *, const tic4x_indirect_t *));
201*3d8817e4Smiod static char *tic4x_operand_parse
202*3d8817e4Smiod   PARAMS ((char *, tic4x_operand_t *));
203*3d8817e4Smiod static int tic4x_operands_match
204*3d8817e4Smiod   PARAMS ((tic4x_inst_t *, tic4x_insn_t *, int));
205*3d8817e4Smiod static void tic4x_insn_check
206*3d8817e4Smiod   PARAMS ((tic4x_insn_t *));
207*3d8817e4Smiod static void tic4x_insn_output
208*3d8817e4Smiod   PARAMS ((tic4x_insn_t *));
209*3d8817e4Smiod static int tic4x_operands_parse
210*3d8817e4Smiod   PARAMS ((char *, tic4x_operand_t *, int ));
211*3d8817e4Smiod void tic4x_cleanup
212*3d8817e4Smiod   PARAMS ((void));
213*3d8817e4Smiod int tic4x_unrecognized_line
214*3d8817e4Smiod   PARAMS ((int));
215*3d8817e4Smiod static int tic4x_pc_offset
216*3d8817e4Smiod   PARAMS ((unsigned int));
217*3d8817e4Smiod int tic4x_do_align
218*3d8817e4Smiod   PARAMS ((int, const char *, int, int));
219*3d8817e4Smiod void tic4x_start_line
220*3d8817e4Smiod   PARAMS ((void));
221*3d8817e4Smiod arelent *tc_gen_reloc
222*3d8817e4Smiod   PARAMS ((asection *, fixS *));
223*3d8817e4Smiod 
224*3d8817e4Smiod 
225*3d8817e4Smiod const pseudo_typeS
226*3d8817e4Smiod   md_pseudo_table[] =
227*3d8817e4Smiod {
228*3d8817e4Smiod   {"align", s_align_bytes, 32},
229*3d8817e4Smiod   {"ascii", tic4x_stringer, 1},
230*3d8817e4Smiod   {"asciz", tic4x_stringer, 0},
231*3d8817e4Smiod   {"asg", tic4x_asg, 0},
232*3d8817e4Smiod   {"block", s_space, 4},
233*3d8817e4Smiod   {"byte", tic4x_cons, 1},
234*3d8817e4Smiod   {"bss", tic4x_bss, 0},
235*3d8817e4Smiod   {"copy", s_include, 0},
236*3d8817e4Smiod   {"def", tic4x_globl, 0},
237*3d8817e4Smiod   {"equ", tic4x_set, 0},
238*3d8817e4Smiod   {"eval", tic4x_eval, 0},
239*3d8817e4Smiod   {"global", tic4x_globl, 0},
240*3d8817e4Smiod   {"globl", tic4x_globl, 0},
241*3d8817e4Smiod   {"hword", tic4x_cons, 2},
242*3d8817e4Smiod   {"ieee", float_cons, 'i'},
243*3d8817e4Smiod   {"int", tic4x_cons, 4},		 /* .int allocates 4 bytes.  */
244*3d8817e4Smiod   {"ldouble", float_cons, 'e'},
245*3d8817e4Smiod   {"newblock", tic4x_newblock, 0},
246*3d8817e4Smiod   {"ref", s_ignore, 0},	         /* All undefined treated as external.  */
247*3d8817e4Smiod   {"set", tic4x_set, 0},
248*3d8817e4Smiod   {"sect", tic4x_sect, 1},	 /* Define named section.  */
249*3d8817e4Smiod   {"space", s_space, 4},
250*3d8817e4Smiod   {"string", tic4x_stringer, 0},
251*3d8817e4Smiod   {"usect", tic4x_usect, 0},       /* Reserve space in uninit. named sect.  */
252*3d8817e4Smiod   {"version", tic4x_version, 0},
253*3d8817e4Smiod   {"word", tic4x_cons, 4},	 /* .word allocates 4 bytes.  */
254*3d8817e4Smiod   {"xdef", tic4x_globl, 0},
255*3d8817e4Smiod   {NULL, 0, 0},
256*3d8817e4Smiod };
257*3d8817e4Smiod 
258*3d8817e4Smiod int md_short_jump_size = 4;
259*3d8817e4Smiod int md_long_jump_size = 4;
260*3d8817e4Smiod 
261*3d8817e4Smiod /* This array holds the chars that always start a comment.  If the
262*3d8817e4Smiod    pre-processor is disabled, these aren't very useful.  */
263*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
264*3d8817e4Smiod const char comment_chars[] = ";!";
265*3d8817e4Smiod #else
266*3d8817e4Smiod const char comment_chars[] = ";";
267*3d8817e4Smiod #endif
268*3d8817e4Smiod 
269*3d8817e4Smiod /* This array holds the chars that only start a comment at the beginning of
270*3d8817e4Smiod    a line.  If the line seems to have the form '# 123 filename'
271*3d8817e4Smiod    .line and .file directives will appear in the pre-processed output.
272*3d8817e4Smiod    Note that input_file.c hand checks for '#' at the beginning of the
273*3d8817e4Smiod    first line of the input file.  This is because the compiler outputs
274*3d8817e4Smiod    #NO_APP at the beginning of its output.
275*3d8817e4Smiod    Also note that comments like this one will always work.  */
276*3d8817e4Smiod const char line_comment_chars[] = "#*";
277*3d8817e4Smiod 
278*3d8817e4Smiod /* We needed an unused char for line separation to work around the
279*3d8817e4Smiod    lack of macros, using sed and such.  */
280*3d8817e4Smiod const char line_separator_chars[] = "&";
281*3d8817e4Smiod 
282*3d8817e4Smiod /* Chars that can be used to separate mant from exp in floating point nums.  */
283*3d8817e4Smiod const char EXP_CHARS[] = "eE";
284*3d8817e4Smiod 
285*3d8817e4Smiod /* Chars that mean this number is a floating point constant.  */
286*3d8817e4Smiod /* As in 0f12.456 */
287*3d8817e4Smiod /* or    0d1.2345e12 */
288*3d8817e4Smiod const char FLT_CHARS[] = "fFilsS";
289*3d8817e4Smiod 
290*3d8817e4Smiod /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
291*3d8817e4Smiod    changed in read.c.  Ideally it shouldn't have to know about it at
292*3d8817e4Smiod    all, but nothing is ideal around here.  */
293*3d8817e4Smiod 
294*3d8817e4Smiod /* Flonums returned here.  */
295*3d8817e4Smiod extern FLONUM_TYPE generic_floating_point_number;
296*3d8817e4Smiod 
297*3d8817e4Smiod /* Precision in LittleNums.  */
298*3d8817e4Smiod #define MAX_PRECISION (4)       /* Its a bit overkill for us, but the code
299*3d8817e4Smiod                                    requires it... */
300*3d8817e4Smiod #define S_PRECISION (1)		/* Short float constants 16-bit.  */
301*3d8817e4Smiod #define F_PRECISION (2)		/* Float and double types 32-bit.  */
302*3d8817e4Smiod #define E_PRECISION (4)         /* Extended precision, 64-bit (real 40-bit). */
303*3d8817e4Smiod #define GUARD (2)
304*3d8817e4Smiod 
305*3d8817e4Smiod /* Turn generic_floating_point_number into a real short/float/double.  */
306*3d8817e4Smiod static int
tic4x_gen_to_words(flonum,words,precision)307*3d8817e4Smiod tic4x_gen_to_words (flonum, words, precision)
308*3d8817e4Smiod      FLONUM_TYPE flonum;
309*3d8817e4Smiod      LITTLENUM_TYPE *words;
310*3d8817e4Smiod      int precision;
311*3d8817e4Smiod {
312*3d8817e4Smiod   int return_value = 0;
313*3d8817e4Smiod   LITTLENUM_TYPE *p;		/* Littlenum pointer.  */
314*3d8817e4Smiod   int mantissa_bits;		/* Bits in mantissa field.  */
315*3d8817e4Smiod   int exponent_bits;		/* Bits in exponent field.  */
316*3d8817e4Smiod   int exponent;
317*3d8817e4Smiod   unsigned int sone;		/* Scaled one.  */
318*3d8817e4Smiod   unsigned int sfract;		/* Scaled fraction.  */
319*3d8817e4Smiod   unsigned int smant;		/* Scaled mantissa.  */
320*3d8817e4Smiod   unsigned int tmp;
321*3d8817e4Smiod   unsigned int mover;           /* Mantissa overflow bits */
322*3d8817e4Smiod   unsigned int rbit;            /* Round bit. */
323*3d8817e4Smiod   int shift;			/* Shift count.  */
324*3d8817e4Smiod 
325*3d8817e4Smiod   /* NOTE: Svein Seldal <Svein@dev.seldal.com>
326*3d8817e4Smiod      The code in this function is altered slightly to support floats
327*3d8817e4Smiod      with 31-bits mantissas, thus the documentation below may be a
328*3d8817e4Smiod      little bit inaccurate.
329*3d8817e4Smiod 
330*3d8817e4Smiod      By Michael P. Hayes <m.hayes@elec.canterbury.ac.nz>
331*3d8817e4Smiod      Here is how a generic floating point number is stored using
332*3d8817e4Smiod      flonums (an extension of bignums) where p is a pointer to an
333*3d8817e4Smiod      array of LITTLENUMs.
334*3d8817e4Smiod 
335*3d8817e4Smiod      For example 2e-3 is stored with exp = -4 and
336*3d8817e4Smiod      bits[0] = 0x0000
337*3d8817e4Smiod      bits[1] = 0x0000
338*3d8817e4Smiod      bits[2] = 0x4fde
339*3d8817e4Smiod      bits[3] = 0x978d
340*3d8817e4Smiod      bits[4] = 0x126e
341*3d8817e4Smiod      bits[5] = 0x0083
342*3d8817e4Smiod      with low = &bits[2], high = &bits[5], and leader = &bits[5].
343*3d8817e4Smiod 
344*3d8817e4Smiod      This number can be written as
345*3d8817e4Smiod      0x0083126e978d4fde.00000000 * 65536**-4  or
346*3d8817e4Smiod      0x0.0083126e978d4fde        * 65536**0   or
347*3d8817e4Smiod      0x0.83126e978d4fde          * 2**-8   = 2e-3
348*3d8817e4Smiod 
349*3d8817e4Smiod      Note that low points to the 65536**0 littlenum (bits[2]) and
350*3d8817e4Smiod      leader points to the most significant non-zero littlenum
351*3d8817e4Smiod      (bits[5]).
352*3d8817e4Smiod 
353*3d8817e4Smiod      TMS320C3X floating point numbers are a bit of a strange beast.
354*3d8817e4Smiod      The 32-bit flavour has the 8 MSBs representing the exponent in
355*3d8817e4Smiod      twos complement format (-128 to +127).  There is then a sign bit
356*3d8817e4Smiod      followed by 23 bits of mantissa.  The mantissa is expressed in
357*3d8817e4Smiod      twos complement format with the binary point after the most
358*3d8817e4Smiod      significant non sign bit.  The bit after the binary point is
359*3d8817e4Smiod      suppressed since it is the complement of the sign bit.  The
360*3d8817e4Smiod      effective mantissa is thus 24 bits.  Zero is represented by an
361*3d8817e4Smiod      exponent of -128.
362*3d8817e4Smiod 
363*3d8817e4Smiod      The 16-bit flavour has the 4 MSBs representing the exponent in
364*3d8817e4Smiod      twos complement format (-8 to +7).  There is then a sign bit
365*3d8817e4Smiod      followed by 11 bits of mantissa.  The mantissa is expressed in
366*3d8817e4Smiod      twos complement format with the binary point after the most
367*3d8817e4Smiod      significant non sign bit.  The bit after the binary point is
368*3d8817e4Smiod      suppressed since it is the complement of the sign bit.  The
369*3d8817e4Smiod      effective mantissa is thus 12 bits.  Zero is represented by an
370*3d8817e4Smiod      exponent of -8.  For example,
371*3d8817e4Smiod 
372*3d8817e4Smiod      number       norm mant m  x  e  s  i    fraction f
373*3d8817e4Smiod      +0.500 =>  1.00000000000 -1 -1  0  1  .00000000000   (1 + 0) * 2^(-1)
374*3d8817e4Smiod      +0.999 =>  1.11111111111 -1 -1  0  1  .11111111111   (1 + 0.99) * 2^(-1)
375*3d8817e4Smiod      +1.000 =>  1.00000000000  0  0  0  1  .00000000000   (1 + 0) * 2^(0)
376*3d8817e4Smiod      +1.500 =>  1.10000000000  0  0  0  1  .10000000000   (1 + 0.5) * 2^(0)
377*3d8817e4Smiod      +1.999 =>  1.11111111111  0  0  0  1  .11111111111   (1 + 0.9) * 2^(0)
378*3d8817e4Smiod      +2.000 =>  1.00000000000  1  1  0  1  .00000000000   (1 + 0) * 2^(1)
379*3d8817e4Smiod      +4.000 =>  1.00000000000  2  2  0  1  .00000000000   (1 + 0) * 2^(2)
380*3d8817e4Smiod      -0.500 =>  1.00000000000 -1 -1  1  0  .10000000000   (-2 + 0) * 2^(-2)
381*3d8817e4Smiod      -1.000 =>  1.00000000000  0 -1  1  0  .00000000000   (-2 + 0) * 2^(-1)
382*3d8817e4Smiod      -1.500 =>  1.10000000000  0  0  1  0  .10000000000   (-2 + 0.5) * 2^(0)
383*3d8817e4Smiod      -1.999 =>  1.11111111111  0  0  1  0  .00000000001   (-2 + 0.11) * 2^(0)
384*3d8817e4Smiod      -2.000 =>  1.00000000000  1  1  1  0  .00000000000   (-2 + 0) * 2^(0)
385*3d8817e4Smiod      -4.000 =>  1.00000000000  2  1  1  0  .00000000000   (-2 + 0) * 2^(1)
386*3d8817e4Smiod 
387*3d8817e4Smiod      where e is the exponent, s is the sign bit, i is the implied bit,
388*3d8817e4Smiod      and f is the fraction stored in the mantissa field.
389*3d8817e4Smiod 
390*3d8817e4Smiod      num = (1 + f) * 2^x   =  m * 2^e if s = 0
391*3d8817e4Smiod      num = (-2 + f) * 2^x  = -m * 2^e if s = 1
392*3d8817e4Smiod      where 0 <= f < 1.0  and 1.0 <= m < 2.0
393*3d8817e4Smiod 
394*3d8817e4Smiod      The fraction (f) and exponent (e) fields for the TMS320C3X format
395*3d8817e4Smiod      can be derived from the normalised mantissa (m) and exponent (x) using:
396*3d8817e4Smiod 
397*3d8817e4Smiod      f = m - 1, e = x       if s = 0
398*3d8817e4Smiod      f = 2 - m, e = x       if s = 1 and m != 1.0
399*3d8817e4Smiod      f = 0,     e = x - 1   if s = 1 and m = 1.0
400*3d8817e4Smiod      f = 0,     e = -8      if m = 0
401*3d8817e4Smiod 
402*3d8817e4Smiod 
403*3d8817e4Smiod      OK, the other issue we have to consider is rounding since the
404*3d8817e4Smiod      mantissa has a much higher potential precision than what we can
405*3d8817e4Smiod      represent.  To do this we add half the smallest storable fraction.
406*3d8817e4Smiod      We then have to renormalise the number to allow for overflow.
407*3d8817e4Smiod 
408*3d8817e4Smiod      To convert a generic flonum into a TMS320C3X floating point
409*3d8817e4Smiod      number, here's what we try to do....
410*3d8817e4Smiod 
411*3d8817e4Smiod      The first thing is to generate a normalised mantissa (m) where
412*3d8817e4Smiod      1.0 <= m < 2 and to convert the exponent from base 16 to base 2.
413*3d8817e4Smiod      We desire the binary point to be placed after the most significant
414*3d8817e4Smiod      non zero bit.  This process is done in two steps: firstly, the
415*3d8817e4Smiod      littlenum with the most significant non zero bit is located (this
416*3d8817e4Smiod      is done for us since leader points to this littlenum) and the
417*3d8817e4Smiod      binary point (which is currently after the LSB of the littlenum
418*3d8817e4Smiod      pointed to by low) is moved to before the MSB of the littlenum
419*3d8817e4Smiod      pointed to by leader.  This requires the exponent to be adjusted
420*3d8817e4Smiod      by leader - low + 1.  In the earlier example, the new exponent is
421*3d8817e4Smiod      thus -4 + (5 - 2 + 1) = 0 (base 65536).  We now need to convert
422*3d8817e4Smiod      the exponent to base 2 by multiplying the exponent by 16 (log2
423*3d8817e4Smiod      65536).  The exponent base 2 is thus also zero.
424*3d8817e4Smiod 
425*3d8817e4Smiod      The second step is to hunt for the most significant non zero bit
426*3d8817e4Smiod      in the leader littlenum.  We do this by left shifting a copy of
427*3d8817e4Smiod      the leader littlenum until bit 16 is set (0x10000) and counting
428*3d8817e4Smiod      the number of shifts, S, required.  The number of shifts then has to
429*3d8817e4Smiod      be added to correct the exponent (base 2).  For our example, this
430*3d8817e4Smiod      will require 9 shifts and thus our normalised exponent (base 2) is
431*3d8817e4Smiod      0 + 9 = 9.  Note that the worst case scenario is when the leader
432*3d8817e4Smiod      littlenum is 1, thus requiring 16 shifts.
433*3d8817e4Smiod 
434*3d8817e4Smiod      We now have to left shift the other littlenums by the same amount,
435*3d8817e4Smiod      propagating the shifted bits into the more significant littlenums.
436*3d8817e4Smiod      To save a lot of unnecessary shifting we only have to consider
437*3d8817e4Smiod      two or three littlenums, since the greatest number of mantissa
438*3d8817e4Smiod      bits required is 24 + 1 rounding bit.  While two littlenums
439*3d8817e4Smiod      provide 32 bits of precision, the most significant littlenum
440*3d8817e4Smiod      may only contain a single significant bit  and thus an extra
441*3d8817e4Smiod      littlenum is required.
442*3d8817e4Smiod 
443*3d8817e4Smiod      Denoting the number of bits in the fraction field as F, we require
444*3d8817e4Smiod      G = F + 2 bits (one extra bit is for rounding, the other gets
445*3d8817e4Smiod      suppressed).  Say we required S shifts to find the most
446*3d8817e4Smiod      significant bit in the leader littlenum, the number of left shifts
447*3d8817e4Smiod      required to move this bit into bit position G - 1 is L = G + S - 17.
448*3d8817e4Smiod      Note that this shift count may be negative for the short floating
449*3d8817e4Smiod      point flavour (where F = 11 and thus G = 13 and potentially S < 3).
450*3d8817e4Smiod      If L > 0 we have to shunt the next littlenum into position.  Bit
451*3d8817e4Smiod      15 (the MSB) of the next littlenum needs to get moved into position
452*3d8817e4Smiod      L - 1 (If L > 15 we need all the bits of this littlenum and
453*3d8817e4Smiod      some more from the next one.).  We subtract 16 from L and use this
454*3d8817e4Smiod      as the left shift count;  the resultant value we or with the
455*3d8817e4Smiod      previous result.  If L > 0, we repeat this operation.   */
456*3d8817e4Smiod 
457*3d8817e4Smiod   if (precision != S_PRECISION)
458*3d8817e4Smiod     words[1] = 0x0000;
459*3d8817e4Smiod   if (precision == E_PRECISION)
460*3d8817e4Smiod     words[2] = words[3] = 0x0000;
461*3d8817e4Smiod 
462*3d8817e4Smiod   /* 0.0e0 or NaN seen.  */
463*3d8817e4Smiod   if (flonum.low > flonum.leader  /* = 0.0e0 */
464*3d8817e4Smiod       || flonum.sign == 0) /* = NaN */
465*3d8817e4Smiod     {
466*3d8817e4Smiod       if(flonum.sign == 0)
467*3d8817e4Smiod         as_bad ("Nan, using zero.");
468*3d8817e4Smiod       words[0] = 0x8000;
469*3d8817e4Smiod       return return_value;
470*3d8817e4Smiod     }
471*3d8817e4Smiod 
472*3d8817e4Smiod   if (flonum.sign == 'P')
473*3d8817e4Smiod     {
474*3d8817e4Smiod       /* +INF:  Replace with maximum float.  */
475*3d8817e4Smiod       if (precision == S_PRECISION)
476*3d8817e4Smiod 	words[0] = 0x77ff;
477*3d8817e4Smiod       else
478*3d8817e4Smiod 	{
479*3d8817e4Smiod 	  words[0] = 0x7f7f;
480*3d8817e4Smiod 	  words[1] = 0xffff;
481*3d8817e4Smiod 	}
482*3d8817e4Smiod       if (precision == E_PRECISION)
483*3d8817e4Smiod         {
484*3d8817e4Smiod           words[2] = 0x7fff;
485*3d8817e4Smiod           words[3] = 0xffff;
486*3d8817e4Smiod         }
487*3d8817e4Smiod       return return_value;
488*3d8817e4Smiod     }
489*3d8817e4Smiod   else if (flonum.sign == 'N')
490*3d8817e4Smiod     {
491*3d8817e4Smiod       /* -INF:  Replace with maximum float.  */
492*3d8817e4Smiod       if (precision == S_PRECISION)
493*3d8817e4Smiod 	words[0] = 0x7800;
494*3d8817e4Smiod       else
495*3d8817e4Smiod         words[0] = 0x7f80;
496*3d8817e4Smiod       if (precision == E_PRECISION)
497*3d8817e4Smiod         words[2] = 0x8000;
498*3d8817e4Smiod       return return_value;
499*3d8817e4Smiod     }
500*3d8817e4Smiod 
501*3d8817e4Smiod   exponent = (flonum.exponent + flonum.leader - flonum.low + 1) * 16;
502*3d8817e4Smiod 
503*3d8817e4Smiod   if (!(tmp = *flonum.leader))
504*3d8817e4Smiod     abort ();			/* Hmmm.  */
505*3d8817e4Smiod   shift = 0;			/* Find position of first sig. bit.  */
506*3d8817e4Smiod   while (tmp >>= 1)
507*3d8817e4Smiod     shift++;
508*3d8817e4Smiod   exponent -= (16 - shift);	/* Adjust exponent.  */
509*3d8817e4Smiod 
510*3d8817e4Smiod   if (precision == S_PRECISION)	/* Allow 1 rounding bit.  */
511*3d8817e4Smiod     {
512*3d8817e4Smiod       exponent_bits = 4;
513*3d8817e4Smiod       mantissa_bits = 11;
514*3d8817e4Smiod     }
515*3d8817e4Smiod   else if(precision == F_PRECISION)
516*3d8817e4Smiod     {
517*3d8817e4Smiod       exponent_bits = 8;
518*3d8817e4Smiod       mantissa_bits = 23;
519*3d8817e4Smiod     }
520*3d8817e4Smiod   else /* E_PRECISION */
521*3d8817e4Smiod     {
522*3d8817e4Smiod       exponent_bits = 8;
523*3d8817e4Smiod       mantissa_bits = 31;
524*3d8817e4Smiod     }
525*3d8817e4Smiod 
526*3d8817e4Smiod   shift = mantissa_bits - shift;
527*3d8817e4Smiod 
528*3d8817e4Smiod   smant = 0;
529*3d8817e4Smiod   mover = 0;
530*3d8817e4Smiod   rbit = 0;
531*3d8817e4Smiod   /* Store the mantissa data into smant and the roundbit into rbit */
532*3d8817e4Smiod   for (p = flonum.leader; p >= flonum.low && shift > -16; p--)
533*3d8817e4Smiod     {
534*3d8817e4Smiod       tmp = shift >= 0 ? *p << shift : *p >> -shift;
535*3d8817e4Smiod       rbit = shift < 0 ? ((*p >> (-shift-1)) & 0x1) : 0;
536*3d8817e4Smiod       smant |= tmp;
537*3d8817e4Smiod       shift -= 16;
538*3d8817e4Smiod     }
539*3d8817e4Smiod 
540*3d8817e4Smiod   /* OK, we've got our scaled mantissa so let's round it up */
541*3d8817e4Smiod   if(rbit)
542*3d8817e4Smiod     {
543*3d8817e4Smiod       /* If the mantissa is going to overflow when added, lets store
544*3d8817e4Smiod          the extra bit in mover. -- A special case exists when
545*3d8817e4Smiod          mantissa_bits is 31 (E_PRECISION). Then the first test cannot
546*3d8817e4Smiod          be trusted, as result is host-dependent, thus the second
547*3d8817e4Smiod          test. */
548*3d8817e4Smiod       if( smant == ((unsigned)(1<<(mantissa_bits+1))-1)
549*3d8817e4Smiod           || smant == (unsigned)-1 )  /* This is to catch E_PRECISION cases */
550*3d8817e4Smiod         mover=1;
551*3d8817e4Smiod       smant++;
552*3d8817e4Smiod     }
553*3d8817e4Smiod 
554*3d8817e4Smiod   /* Get the scaled one value */
555*3d8817e4Smiod   sone = (1 << (mantissa_bits));
556*3d8817e4Smiod 
557*3d8817e4Smiod   /* The number may be unnormalised so renormalise it...  */
558*3d8817e4Smiod   if(mover)
559*3d8817e4Smiod     {
560*3d8817e4Smiod       smant >>= 1;
561*3d8817e4Smiod       smant |= sone; /* Insert the bit from mover into smant */
562*3d8817e4Smiod       exponent++;
563*3d8817e4Smiod     }
564*3d8817e4Smiod 
565*3d8817e4Smiod   /* The binary point is now between bit positions 11 and 10 or 23 and 22,
566*3d8817e4Smiod      i.e., between mantissa_bits - 1 and mantissa_bits - 2 and the
567*3d8817e4Smiod      bit at mantissa_bits - 1 should be set.  */
568*3d8817e4Smiod   if (!(sone&smant))
569*3d8817e4Smiod     abort ();                   /* Ooops.  */
570*3d8817e4Smiod 
571*3d8817e4Smiod   if (flonum.sign == '+')
572*3d8817e4Smiod     sfract = smant - sone;	/* smant - 1.0.  */
573*3d8817e4Smiod   else
574*3d8817e4Smiod     {
575*3d8817e4Smiod       /* This seems to work.  */
576*3d8817e4Smiod       if (smant == sone)
577*3d8817e4Smiod 	{
578*3d8817e4Smiod 	  exponent--;
579*3d8817e4Smiod 	  sfract = 0;
580*3d8817e4Smiod 	}
581*3d8817e4Smiod       else
582*3d8817e4Smiod         {
583*3d8817e4Smiod           sfract = -smant & (sone-1);   /* 2.0 - smant.  */
584*3d8817e4Smiod         }
585*3d8817e4Smiod       sfract |= sone;		/* Insert sign bit.  */
586*3d8817e4Smiod     }
587*3d8817e4Smiod 
588*3d8817e4Smiod   if (abs (exponent) >= (1 << (exponent_bits - 1)))
589*3d8817e4Smiod     as_bad ("Cannot represent exponent in %d bits", exponent_bits);
590*3d8817e4Smiod 
591*3d8817e4Smiod   /* Force exponent to fit in desired field width.  */
592*3d8817e4Smiod   exponent &= (1 << (exponent_bits)) - 1;
593*3d8817e4Smiod 
594*3d8817e4Smiod   if (precision == E_PRECISION)
595*3d8817e4Smiod     {
596*3d8817e4Smiod       /* Map the float part first (100% equal format as F_PRECISION) */
597*3d8817e4Smiod       words[0]  = exponent << (mantissa_bits+1-24);
598*3d8817e4Smiod       words[0] |= sfract >> 24;
599*3d8817e4Smiod       words[1]  = sfract >> 8;
600*3d8817e4Smiod 
601*3d8817e4Smiod       /* Map the mantissa in the next */
602*3d8817e4Smiod       words[2]  = sfract >> 16;
603*3d8817e4Smiod       words[3]  = sfract & 0xffff;
604*3d8817e4Smiod     }
605*3d8817e4Smiod   else
606*3d8817e4Smiod     {
607*3d8817e4Smiod       /* Insert the exponent data into the word */
608*3d8817e4Smiod       sfract |= exponent << (mantissa_bits+1);
609*3d8817e4Smiod 
610*3d8817e4Smiod       if (precision == S_PRECISION)
611*3d8817e4Smiod         words[0] = sfract;
612*3d8817e4Smiod       else
613*3d8817e4Smiod         {
614*3d8817e4Smiod           words[0] = sfract >> 16;
615*3d8817e4Smiod           words[1] = sfract & 0xffff;
616*3d8817e4Smiod         }
617*3d8817e4Smiod     }
618*3d8817e4Smiod 
619*3d8817e4Smiod   return return_value;
620*3d8817e4Smiod }
621*3d8817e4Smiod 
622*3d8817e4Smiod /* Returns pointer past text consumed.  */
623*3d8817e4Smiod static char *
tic4x_atof(str,what_kind,words)624*3d8817e4Smiod tic4x_atof (str, what_kind, words)
625*3d8817e4Smiod      char *str;
626*3d8817e4Smiod      char what_kind;
627*3d8817e4Smiod      LITTLENUM_TYPE *words;
628*3d8817e4Smiod {
629*3d8817e4Smiod   /* Extra bits for zeroed low-order bits.  The 1st MAX_PRECISION are
630*3d8817e4Smiod      zeroed, the last contain flonum bits.  */
631*3d8817e4Smiod   static LITTLENUM_TYPE bits[MAX_PRECISION + MAX_PRECISION + GUARD];
632*3d8817e4Smiod   char *return_value;
633*3d8817e4Smiod   /* Number of 16-bit words in the format.  */
634*3d8817e4Smiod   int precision;
635*3d8817e4Smiod   FLONUM_TYPE save_gen_flonum;
636*3d8817e4Smiod 
637*3d8817e4Smiod   /* We have to save the generic_floating_point_number because it
638*3d8817e4Smiod      contains storage allocation about the array of LITTLENUMs where
639*3d8817e4Smiod      the value is actually stored.  We will allocate our own array of
640*3d8817e4Smiod      littlenums below, but have to restore the global one on exit.  */
641*3d8817e4Smiod   save_gen_flonum = generic_floating_point_number;
642*3d8817e4Smiod 
643*3d8817e4Smiod   return_value = str;
644*3d8817e4Smiod   generic_floating_point_number.low = bits + MAX_PRECISION;
645*3d8817e4Smiod   generic_floating_point_number.high = NULL;
646*3d8817e4Smiod   generic_floating_point_number.leader = NULL;
647*3d8817e4Smiod   generic_floating_point_number.exponent = 0;
648*3d8817e4Smiod   generic_floating_point_number.sign = '\0';
649*3d8817e4Smiod 
650*3d8817e4Smiod   /* Use more LittleNums than seems necessary: the highest flonum may
651*3d8817e4Smiod      have 15 leading 0 bits, so could be useless.  */
652*3d8817e4Smiod 
653*3d8817e4Smiod   memset (bits, '\0', sizeof (LITTLENUM_TYPE) * MAX_PRECISION);
654*3d8817e4Smiod 
655*3d8817e4Smiod   switch (what_kind)
656*3d8817e4Smiod     {
657*3d8817e4Smiod     case 's':
658*3d8817e4Smiod     case 'S':
659*3d8817e4Smiod       precision = S_PRECISION;
660*3d8817e4Smiod       break;
661*3d8817e4Smiod 
662*3d8817e4Smiod     case 'd':
663*3d8817e4Smiod     case 'D':
664*3d8817e4Smiod     case 'f':
665*3d8817e4Smiod     case 'F':
666*3d8817e4Smiod       precision = F_PRECISION;
667*3d8817e4Smiod       break;
668*3d8817e4Smiod 
669*3d8817e4Smiod     case 'E':
670*3d8817e4Smiod     case 'e':
671*3d8817e4Smiod       precision = E_PRECISION;
672*3d8817e4Smiod       break;
673*3d8817e4Smiod 
674*3d8817e4Smiod     default:
675*3d8817e4Smiod       as_bad ("Invalid floating point number");
676*3d8817e4Smiod       return (NULL);
677*3d8817e4Smiod     }
678*3d8817e4Smiod 
679*3d8817e4Smiod   generic_floating_point_number.high
680*3d8817e4Smiod     = generic_floating_point_number.low + precision - 1 + GUARD;
681*3d8817e4Smiod 
682*3d8817e4Smiod   if (atof_generic (&return_value, ".", EXP_CHARS,
683*3d8817e4Smiod 		    &generic_floating_point_number))
684*3d8817e4Smiod     {
685*3d8817e4Smiod       as_bad ("Invalid floating point number");
686*3d8817e4Smiod       return (NULL);
687*3d8817e4Smiod     }
688*3d8817e4Smiod 
689*3d8817e4Smiod   tic4x_gen_to_words (generic_floating_point_number,
690*3d8817e4Smiod 		    words, precision);
691*3d8817e4Smiod 
692*3d8817e4Smiod   /* Restore the generic_floating_point_number's storage alloc (and
693*3d8817e4Smiod      everything else).  */
694*3d8817e4Smiod   generic_floating_point_number = save_gen_flonum;
695*3d8817e4Smiod 
696*3d8817e4Smiod   return return_value;
697*3d8817e4Smiod }
698*3d8817e4Smiod 
699*3d8817e4Smiod static void
tic4x_insert_reg(regname,regnum)700*3d8817e4Smiod tic4x_insert_reg (regname, regnum)
701*3d8817e4Smiod      char *regname;
702*3d8817e4Smiod      int regnum;
703*3d8817e4Smiod {
704*3d8817e4Smiod   char buf[32];
705*3d8817e4Smiod   int i;
706*3d8817e4Smiod 
707*3d8817e4Smiod   symbol_table_insert (symbol_new (regname, reg_section, (valueT) regnum,
708*3d8817e4Smiod 				   &zero_address_frag));
709*3d8817e4Smiod   for (i = 0; regname[i]; i++)
710*3d8817e4Smiod     buf[i] = ISLOWER (regname[i]) ? TOUPPER (regname[i]) : regname[i];
711*3d8817e4Smiod   buf[i] = '\0';
712*3d8817e4Smiod 
713*3d8817e4Smiod   symbol_table_insert (symbol_new (buf, reg_section, (valueT) regnum,
714*3d8817e4Smiod 				   &zero_address_frag));
715*3d8817e4Smiod }
716*3d8817e4Smiod 
717*3d8817e4Smiod static void
tic4x_insert_sym(symname,value)718*3d8817e4Smiod tic4x_insert_sym (symname, value)
719*3d8817e4Smiod      char *symname;
720*3d8817e4Smiod      int value;
721*3d8817e4Smiod {
722*3d8817e4Smiod   symbolS *symbolP;
723*3d8817e4Smiod 
724*3d8817e4Smiod   symbolP = symbol_new (symname, absolute_section,
725*3d8817e4Smiod 			(valueT) value, &zero_address_frag);
726*3d8817e4Smiod   SF_SET_LOCAL (symbolP);
727*3d8817e4Smiod   symbol_table_insert (symbolP);
728*3d8817e4Smiod }
729*3d8817e4Smiod 
730*3d8817e4Smiod static char *
tic4x_expression(str,exp)731*3d8817e4Smiod tic4x_expression (str, exp)
732*3d8817e4Smiod      char *str;
733*3d8817e4Smiod      expressionS *exp;
734*3d8817e4Smiod {
735*3d8817e4Smiod   char *s;
736*3d8817e4Smiod   char *t;
737*3d8817e4Smiod 
738*3d8817e4Smiod   t = input_line_pointer;	/* Save line pointer.  */
739*3d8817e4Smiod   input_line_pointer = str;
740*3d8817e4Smiod   expression (exp);
741*3d8817e4Smiod   s = input_line_pointer;
742*3d8817e4Smiod   input_line_pointer = t;	/* Restore line pointer.  */
743*3d8817e4Smiod   return s;			/* Return pointer to where parsing stopped.  */
744*3d8817e4Smiod }
745*3d8817e4Smiod 
746*3d8817e4Smiod static char *
tic4x_expression_abs(str,value)747*3d8817e4Smiod tic4x_expression_abs (str, value)
748*3d8817e4Smiod      char *str;
749*3d8817e4Smiod      offsetT *value;
750*3d8817e4Smiod {
751*3d8817e4Smiod   char *s;
752*3d8817e4Smiod   char *t;
753*3d8817e4Smiod 
754*3d8817e4Smiod   t = input_line_pointer;	/* Save line pointer.  */
755*3d8817e4Smiod   input_line_pointer = str;
756*3d8817e4Smiod   *value = get_absolute_expression ();
757*3d8817e4Smiod   s = input_line_pointer;
758*3d8817e4Smiod   input_line_pointer = t;	/* Restore line pointer.  */
759*3d8817e4Smiod   return s;
760*3d8817e4Smiod }
761*3d8817e4Smiod 
762*3d8817e4Smiod static void
tic4x_emit_char(c,b)763*3d8817e4Smiod tic4x_emit_char (c,b)
764*3d8817e4Smiod      char c;
765*3d8817e4Smiod      int b;
766*3d8817e4Smiod {
767*3d8817e4Smiod   expressionS exp;
768*3d8817e4Smiod 
769*3d8817e4Smiod   exp.X_op = O_constant;
770*3d8817e4Smiod   exp.X_add_number = c;
771*3d8817e4Smiod   emit_expr (&exp, b);
772*3d8817e4Smiod }
773*3d8817e4Smiod 
774*3d8817e4Smiod static void
tic4x_seg_alloc(name,seg,size,symbolP)775*3d8817e4Smiod tic4x_seg_alloc (name, seg, size, symbolP)
776*3d8817e4Smiod      char *name ATTRIBUTE_UNUSED;
777*3d8817e4Smiod      segT seg ATTRIBUTE_UNUSED;
778*3d8817e4Smiod      int size;
779*3d8817e4Smiod      symbolS *symbolP;
780*3d8817e4Smiod {
781*3d8817e4Smiod   /* Note that the size is in words
782*3d8817e4Smiod      so we multiply it by 4 to get the number of bytes to allocate.  */
783*3d8817e4Smiod 
784*3d8817e4Smiod   /* If we have symbol:  .usect  ".fred", size etc.,
785*3d8817e4Smiod      the symbol needs to point to the first location reserved
786*3d8817e4Smiod      by the pseudo op.  */
787*3d8817e4Smiod 
788*3d8817e4Smiod   if (size)
789*3d8817e4Smiod     {
790*3d8817e4Smiod       char *p;
791*3d8817e4Smiod 
792*3d8817e4Smiod       p = frag_var (rs_fill, 1, 1, (relax_substateT) 0,
793*3d8817e4Smiod 		    (symbolS *) symbolP,
794*3d8817e4Smiod 		    size * OCTETS_PER_BYTE, (char *) 0);
795*3d8817e4Smiod       *p = 0;
796*3d8817e4Smiod     }
797*3d8817e4Smiod }
798*3d8817e4Smiod 
799*3d8817e4Smiod /* .asg ["]character-string["], symbol */
800*3d8817e4Smiod static void
tic4x_asg(x)801*3d8817e4Smiod tic4x_asg (x)
802*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
803*3d8817e4Smiod {
804*3d8817e4Smiod   char c;
805*3d8817e4Smiod   char *name;
806*3d8817e4Smiod   char *str;
807*3d8817e4Smiod   char *tmp;
808*3d8817e4Smiod 
809*3d8817e4Smiod   SKIP_WHITESPACE ();
810*3d8817e4Smiod   str = input_line_pointer;
811*3d8817e4Smiod 
812*3d8817e4Smiod   /* Skip string expression.  */
813*3d8817e4Smiod   while (*input_line_pointer != ',' && *input_line_pointer)
814*3d8817e4Smiod     input_line_pointer++;
815*3d8817e4Smiod   if (*input_line_pointer != ',')
816*3d8817e4Smiod     {
817*3d8817e4Smiod       as_bad ("Comma expected\n");
818*3d8817e4Smiod       return;
819*3d8817e4Smiod     }
820*3d8817e4Smiod   *input_line_pointer++ = '\0';
821*3d8817e4Smiod   name = input_line_pointer;
822*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
823*3d8817e4Smiod   tmp = xmalloc (strlen (str) + 1);
824*3d8817e4Smiod   strcpy (tmp, str);
825*3d8817e4Smiod   str = tmp;
826*3d8817e4Smiod   tmp = xmalloc (strlen (name) + 1);
827*3d8817e4Smiod   strcpy (tmp, name);
828*3d8817e4Smiod   name = tmp;
829*3d8817e4Smiod   if (hash_find (tic4x_asg_hash, name))
830*3d8817e4Smiod     hash_replace (tic4x_asg_hash, name, (PTR) str);
831*3d8817e4Smiod   else
832*3d8817e4Smiod     hash_insert (tic4x_asg_hash, name, (PTR) str);
833*3d8817e4Smiod   *input_line_pointer = c;
834*3d8817e4Smiod   demand_empty_rest_of_line ();
835*3d8817e4Smiod }
836*3d8817e4Smiod 
837*3d8817e4Smiod /* .bss symbol, size  */
838*3d8817e4Smiod static void
tic4x_bss(x)839*3d8817e4Smiod tic4x_bss (x)
840*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
841*3d8817e4Smiod {
842*3d8817e4Smiod   char c;
843*3d8817e4Smiod   char *name;
844*3d8817e4Smiod   char *p;
845*3d8817e4Smiod   offsetT size;
846*3d8817e4Smiod   segT current_seg;
847*3d8817e4Smiod   subsegT current_subseg;
848*3d8817e4Smiod   symbolS *symbolP;
849*3d8817e4Smiod 
850*3d8817e4Smiod   current_seg = now_seg;	/* Save current seg.  */
851*3d8817e4Smiod   current_subseg = now_subseg;	/* Save current subseg.  */
852*3d8817e4Smiod 
853*3d8817e4Smiod   SKIP_WHITESPACE ();
854*3d8817e4Smiod   name = input_line_pointer;
855*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
856*3d8817e4Smiod   if (c != ',')
857*3d8817e4Smiod     {
858*3d8817e4Smiod       as_bad (".bss size argument missing\n");
859*3d8817e4Smiod       return;
860*3d8817e4Smiod     }
861*3d8817e4Smiod 
862*3d8817e4Smiod   input_line_pointer =
863*3d8817e4Smiod     tic4x_expression_abs (++input_line_pointer, &size);
864*3d8817e4Smiod   if (size < 0)
865*3d8817e4Smiod     {
866*3d8817e4Smiod       as_bad (".bss size %ld < 0!", (long) size);
867*3d8817e4Smiod       return;
868*3d8817e4Smiod     }
869*3d8817e4Smiod   subseg_set (bss_section, 0);
870*3d8817e4Smiod   symbolP = symbol_find_or_make (name);
871*3d8817e4Smiod 
872*3d8817e4Smiod   if (S_GET_SEGMENT (symbolP) == bss_section)
873*3d8817e4Smiod     symbol_get_frag (symbolP)->fr_symbol = 0;
874*3d8817e4Smiod 
875*3d8817e4Smiod   symbol_set_frag (symbolP, frag_now);
876*3d8817e4Smiod 
877*3d8817e4Smiod   p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
878*3d8817e4Smiod 		size * OCTETS_PER_BYTE, (char *) 0);
879*3d8817e4Smiod   *p = 0;			/* Fill char.  */
880*3d8817e4Smiod 
881*3d8817e4Smiod   S_SET_SEGMENT (symbolP, bss_section);
882*3d8817e4Smiod 
883*3d8817e4Smiod   /* The symbol may already have been created with a preceding
884*3d8817e4Smiod      ".globl" directive -- be careful not to step on storage class
885*3d8817e4Smiod      in that case.  Otherwise, set it to static.  */
886*3d8817e4Smiod   if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
887*3d8817e4Smiod     S_SET_STORAGE_CLASS (symbolP, C_STAT);
888*3d8817e4Smiod 
889*3d8817e4Smiod   subseg_set (current_seg, current_subseg); /* Restore current seg.  */
890*3d8817e4Smiod   demand_empty_rest_of_line ();
891*3d8817e4Smiod }
892*3d8817e4Smiod 
893*3d8817e4Smiod static void
tic4x_globl(ignore)894*3d8817e4Smiod tic4x_globl (ignore)
895*3d8817e4Smiod      int ignore ATTRIBUTE_UNUSED;
896*3d8817e4Smiod {
897*3d8817e4Smiod   char *name;
898*3d8817e4Smiod   int c;
899*3d8817e4Smiod   symbolS *symbolP;
900*3d8817e4Smiod 
901*3d8817e4Smiod   do
902*3d8817e4Smiod     {
903*3d8817e4Smiod       name = input_line_pointer;
904*3d8817e4Smiod       c = get_symbol_end ();
905*3d8817e4Smiod       symbolP = symbol_find_or_make (name);
906*3d8817e4Smiod       *input_line_pointer = c;
907*3d8817e4Smiod       SKIP_WHITESPACE ();
908*3d8817e4Smiod       S_SET_STORAGE_CLASS (symbolP, C_EXT);
909*3d8817e4Smiod       if (c == ',')
910*3d8817e4Smiod 	{
911*3d8817e4Smiod 	  input_line_pointer++;
912*3d8817e4Smiod 	  SKIP_WHITESPACE ();
913*3d8817e4Smiod 	  if (*input_line_pointer == '\n')
914*3d8817e4Smiod 	    c = '\n';
915*3d8817e4Smiod 	}
916*3d8817e4Smiod     }
917*3d8817e4Smiod   while (c == ',');
918*3d8817e4Smiod 
919*3d8817e4Smiod   demand_empty_rest_of_line ();
920*3d8817e4Smiod }
921*3d8817e4Smiod 
922*3d8817e4Smiod /* Handle .byte, .word. .int, .long */
923*3d8817e4Smiod static void
tic4x_cons(bytes)924*3d8817e4Smiod tic4x_cons (bytes)
925*3d8817e4Smiod      int bytes;
926*3d8817e4Smiod {
927*3d8817e4Smiod   register unsigned int c;
928*3d8817e4Smiod   do
929*3d8817e4Smiod     {
930*3d8817e4Smiod       SKIP_WHITESPACE ();
931*3d8817e4Smiod       if (*input_line_pointer == '"')
932*3d8817e4Smiod 	{
933*3d8817e4Smiod 	  input_line_pointer++;
934*3d8817e4Smiod 	  while (is_a_char (c = next_char_of_string ()))
935*3d8817e4Smiod 	    tic4x_emit_char (c, 4);
936*3d8817e4Smiod 	  know (input_line_pointer[-1] == '\"');
937*3d8817e4Smiod 	}
938*3d8817e4Smiod       else
939*3d8817e4Smiod 	{
940*3d8817e4Smiod 	  expressionS exp;
941*3d8817e4Smiod 
942*3d8817e4Smiod 	  input_line_pointer = tic4x_expression (input_line_pointer, &exp);
943*3d8817e4Smiod 	  if (exp.X_op == O_constant)
944*3d8817e4Smiod 	    {
945*3d8817e4Smiod 	      switch (bytes)
946*3d8817e4Smiod 		{
947*3d8817e4Smiod 		case 1:
948*3d8817e4Smiod 		  exp.X_add_number &= 255;
949*3d8817e4Smiod 		  break;
950*3d8817e4Smiod 		case 2:
951*3d8817e4Smiod 		  exp.X_add_number &= 65535;
952*3d8817e4Smiod 		  break;
953*3d8817e4Smiod 		}
954*3d8817e4Smiod 	    }
955*3d8817e4Smiod 	  /* Perhaps we should disallow .byte and .hword with
956*3d8817e4Smiod 	     a non constant expression that will require relocation.  */
957*3d8817e4Smiod 	  emit_expr (&exp, 4);
958*3d8817e4Smiod 	}
959*3d8817e4Smiod     }
960*3d8817e4Smiod   while (*input_line_pointer++ == ',');
961*3d8817e4Smiod 
962*3d8817e4Smiod   input_line_pointer--;		/* Put terminator back into stream.  */
963*3d8817e4Smiod   demand_empty_rest_of_line ();
964*3d8817e4Smiod }
965*3d8817e4Smiod 
966*3d8817e4Smiod /* Handle .ascii, .asciz, .string */
967*3d8817e4Smiod static void
tic4x_stringer(append_zero)968*3d8817e4Smiod tic4x_stringer (append_zero)
969*3d8817e4Smiod      int append_zero; /*ex: bytes */
970*3d8817e4Smiod {
971*3d8817e4Smiod   int bytes;
972*3d8817e4Smiod   register unsigned int c;
973*3d8817e4Smiod 
974*3d8817e4Smiod   bytes = 0;
975*3d8817e4Smiod   do
976*3d8817e4Smiod     {
977*3d8817e4Smiod       SKIP_WHITESPACE ();
978*3d8817e4Smiod       if (*input_line_pointer == '"')
979*3d8817e4Smiod 	{
980*3d8817e4Smiod 	  input_line_pointer++;
981*3d8817e4Smiod 	  while (is_a_char (c = next_char_of_string ()))
982*3d8817e4Smiod             {
983*3d8817e4Smiod               tic4x_emit_char (c, 1);
984*3d8817e4Smiod               bytes++;
985*3d8817e4Smiod             }
986*3d8817e4Smiod 
987*3d8817e4Smiod           if (append_zero)
988*3d8817e4Smiod             {
989*3d8817e4Smiod               tic4x_emit_char (c, 1);
990*3d8817e4Smiod               bytes++;
991*3d8817e4Smiod             }
992*3d8817e4Smiod 
993*3d8817e4Smiod 	  know (input_line_pointer[-1] == '\"');
994*3d8817e4Smiod 	}
995*3d8817e4Smiod       else
996*3d8817e4Smiod 	{
997*3d8817e4Smiod 	  expressionS exp;
998*3d8817e4Smiod 
999*3d8817e4Smiod 	  input_line_pointer = tic4x_expression (input_line_pointer, &exp);
1000*3d8817e4Smiod 	  if (exp.X_op != O_constant)
1001*3d8817e4Smiod             {
1002*3d8817e4Smiod               as_bad("Non-constant symbols not allowed\n");
1003*3d8817e4Smiod               return;
1004*3d8817e4Smiod             }
1005*3d8817e4Smiod           exp.X_add_number &= 255; /* Limit numeber to 8-bit */
1006*3d8817e4Smiod 	  emit_expr (&exp, 1);
1007*3d8817e4Smiod           bytes++;
1008*3d8817e4Smiod 	}
1009*3d8817e4Smiod     }
1010*3d8817e4Smiod   while (*input_line_pointer++ == ',');
1011*3d8817e4Smiod 
1012*3d8817e4Smiod   /* Fill out the rest of the expression with 0's to fill up a full word */
1013*3d8817e4Smiod   if ( bytes&0x3 )
1014*3d8817e4Smiod     tic4x_emit_char (0, 4-(bytes&0x3));
1015*3d8817e4Smiod 
1016*3d8817e4Smiod   input_line_pointer--;		/* Put terminator back into stream.  */
1017*3d8817e4Smiod   demand_empty_rest_of_line ();
1018*3d8817e4Smiod }
1019*3d8817e4Smiod 
1020*3d8817e4Smiod /* .eval expression, symbol */
1021*3d8817e4Smiod static void
tic4x_eval(x)1022*3d8817e4Smiod tic4x_eval (x)
1023*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1024*3d8817e4Smiod {
1025*3d8817e4Smiod   char c;
1026*3d8817e4Smiod   offsetT value;
1027*3d8817e4Smiod   char *name;
1028*3d8817e4Smiod 
1029*3d8817e4Smiod   SKIP_WHITESPACE ();
1030*3d8817e4Smiod   input_line_pointer =
1031*3d8817e4Smiod     tic4x_expression_abs (input_line_pointer, &value);
1032*3d8817e4Smiod   if (*input_line_pointer++ != ',')
1033*3d8817e4Smiod     {
1034*3d8817e4Smiod       as_bad ("Symbol missing\n");
1035*3d8817e4Smiod       return;
1036*3d8817e4Smiod     }
1037*3d8817e4Smiod   name = input_line_pointer;
1038*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
1039*3d8817e4Smiod   demand_empty_rest_of_line ();
1040*3d8817e4Smiod   tic4x_insert_sym (name, value);
1041*3d8817e4Smiod }
1042*3d8817e4Smiod 
1043*3d8817e4Smiod /* Reset local labels.  */
1044*3d8817e4Smiod static void
tic4x_newblock(x)1045*3d8817e4Smiod tic4x_newblock (x)
1046*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1047*3d8817e4Smiod {
1048*3d8817e4Smiod   dollar_label_clear ();
1049*3d8817e4Smiod }
1050*3d8817e4Smiod 
1051*3d8817e4Smiod /* .sect "section-name" [, value] */
1052*3d8817e4Smiod /* .sect ["]section-name[:subsection-name]["] [, value] */
1053*3d8817e4Smiod static void
tic4x_sect(x)1054*3d8817e4Smiod tic4x_sect (x)
1055*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1056*3d8817e4Smiod {
1057*3d8817e4Smiod   char c;
1058*3d8817e4Smiod   char *section_name;
1059*3d8817e4Smiod   char *subsection_name;
1060*3d8817e4Smiod   char *name;
1061*3d8817e4Smiod   segT seg;
1062*3d8817e4Smiod   offsetT num;
1063*3d8817e4Smiod 
1064*3d8817e4Smiod   SKIP_WHITESPACE ();
1065*3d8817e4Smiod   if (*input_line_pointer == '"')
1066*3d8817e4Smiod     input_line_pointer++;
1067*3d8817e4Smiod   section_name = input_line_pointer;
1068*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
1069*3d8817e4Smiod   input_line_pointer++;		/* Skip null symbol terminator.  */
1070*3d8817e4Smiod   name = xmalloc (input_line_pointer - section_name + 1);
1071*3d8817e4Smiod   strcpy (name, section_name);
1072*3d8817e4Smiod 
1073*3d8817e4Smiod   /* TI C from version 5.0 allows a section name to contain a
1074*3d8817e4Smiod      subsection name as well. The subsection name is separated by a
1075*3d8817e4Smiod      ':' from the section name.  Currently we scan the subsection
1076*3d8817e4Smiod      name and discard it.
1077*3d8817e4Smiod      Volker Kuhlmann  <v.kuhlmann@elec.canterbury.ac.nz>.  */
1078*3d8817e4Smiod   if (c == ':')
1079*3d8817e4Smiod     {
1080*3d8817e4Smiod       subsection_name = input_line_pointer;
1081*3d8817e4Smiod       c = get_symbol_end ();	/* Get terminator.  */
1082*3d8817e4Smiod       input_line_pointer++;	/* Skip null symbol terminator.  */
1083*3d8817e4Smiod       as_warn (".sect: subsection name ignored");
1084*3d8817e4Smiod     }
1085*3d8817e4Smiod 
1086*3d8817e4Smiod   /* We might still have a '"' to discard, but the character after a
1087*3d8817e4Smiod      symbol name will be overwritten with a \0 by get_symbol_end()
1088*3d8817e4Smiod      [VK].  */
1089*3d8817e4Smiod 
1090*3d8817e4Smiod   if (c == ',')
1091*3d8817e4Smiod     input_line_pointer =
1092*3d8817e4Smiod       tic4x_expression_abs (input_line_pointer, &num);
1093*3d8817e4Smiod   else if (*input_line_pointer == ',')
1094*3d8817e4Smiod     {
1095*3d8817e4Smiod       input_line_pointer =
1096*3d8817e4Smiod 	tic4x_expression_abs (++input_line_pointer, &num);
1097*3d8817e4Smiod     }
1098*3d8817e4Smiod   else
1099*3d8817e4Smiod     num = 0;
1100*3d8817e4Smiod 
1101*3d8817e4Smiod   seg = subseg_new (name, num);
1102*3d8817e4Smiod   if (line_label != NULL)
1103*3d8817e4Smiod     {
1104*3d8817e4Smiod       S_SET_SEGMENT (line_label, seg);
1105*3d8817e4Smiod       symbol_set_frag (line_label, frag_now);
1106*3d8817e4Smiod     }
1107*3d8817e4Smiod 
1108*3d8817e4Smiod   if (bfd_get_section_flags (stdoutput, seg) == SEC_NO_FLAGS)
1109*3d8817e4Smiod     {
1110*3d8817e4Smiod       if (!bfd_set_section_flags (stdoutput, seg, SEC_DATA))
1111*3d8817e4Smiod 	as_warn ("Error setting flags for \"%s\": %s", name,
1112*3d8817e4Smiod 		 bfd_errmsg (bfd_get_error ()));
1113*3d8817e4Smiod     }
1114*3d8817e4Smiod 
1115*3d8817e4Smiod   /* If the last character overwritten by get_symbol_end() was an
1116*3d8817e4Smiod      end-of-line, we must restore it or the end of the line will not be
1117*3d8817e4Smiod      recognised and scanning extends into the next line, stopping with
1118*3d8817e4Smiod      an error (blame Volker Kuhlmann <v.kuhlmann@elec.canterbury.ac.nz>
1119*3d8817e4Smiod      if this is not true).  */
1120*3d8817e4Smiod   if (is_end_of_line[(unsigned char) c])
1121*3d8817e4Smiod     *(--input_line_pointer) = c;
1122*3d8817e4Smiod 
1123*3d8817e4Smiod   demand_empty_rest_of_line ();
1124*3d8817e4Smiod }
1125*3d8817e4Smiod 
1126*3d8817e4Smiod /* symbol[:] .set value  or  .set symbol, value */
1127*3d8817e4Smiod static void
tic4x_set(x)1128*3d8817e4Smiod tic4x_set (x)
1129*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1130*3d8817e4Smiod {
1131*3d8817e4Smiod   symbolS *symbolP;
1132*3d8817e4Smiod 
1133*3d8817e4Smiod   SKIP_WHITESPACE ();
1134*3d8817e4Smiod   if ((symbolP = line_label) == NULL)
1135*3d8817e4Smiod     {
1136*3d8817e4Smiod       char c;
1137*3d8817e4Smiod       char *name;
1138*3d8817e4Smiod 
1139*3d8817e4Smiod       name = input_line_pointer;
1140*3d8817e4Smiod       c = get_symbol_end ();	/* Get terminator.  */
1141*3d8817e4Smiod       if (c != ',')
1142*3d8817e4Smiod 	{
1143*3d8817e4Smiod 	  as_bad (".set syntax invalid\n");
1144*3d8817e4Smiod 	  ignore_rest_of_line ();
1145*3d8817e4Smiod 	  return;
1146*3d8817e4Smiod 	}
1147*3d8817e4Smiod       ++input_line_pointer;
1148*3d8817e4Smiod       symbolP = symbol_find_or_make (name);
1149*3d8817e4Smiod     }
1150*3d8817e4Smiod   else
1151*3d8817e4Smiod     symbol_table_insert (symbolP);
1152*3d8817e4Smiod 
1153*3d8817e4Smiod   pseudo_set (symbolP);
1154*3d8817e4Smiod   demand_empty_rest_of_line ();
1155*3d8817e4Smiod }
1156*3d8817e4Smiod 
1157*3d8817e4Smiod /* [symbol] .usect ["]section-name["], size-in-words [, alignment-flag] */
1158*3d8817e4Smiod static void
tic4x_usect(x)1159*3d8817e4Smiod tic4x_usect (x)
1160*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1161*3d8817e4Smiod {
1162*3d8817e4Smiod   char c;
1163*3d8817e4Smiod   char *name;
1164*3d8817e4Smiod   char *section_name;
1165*3d8817e4Smiod   segT seg;
1166*3d8817e4Smiod   offsetT size, alignment_flag;
1167*3d8817e4Smiod   segT current_seg;
1168*3d8817e4Smiod   subsegT current_subseg;
1169*3d8817e4Smiod 
1170*3d8817e4Smiod   current_seg = now_seg;	/* save current seg.  */
1171*3d8817e4Smiod   current_subseg = now_subseg;	/* save current subseg.  */
1172*3d8817e4Smiod 
1173*3d8817e4Smiod   SKIP_WHITESPACE ();
1174*3d8817e4Smiod   if (*input_line_pointer == '"')
1175*3d8817e4Smiod     input_line_pointer++;
1176*3d8817e4Smiod   section_name = input_line_pointer;
1177*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
1178*3d8817e4Smiod   input_line_pointer++;		/* Skip null symbol terminator.  */
1179*3d8817e4Smiod   name = xmalloc (input_line_pointer - section_name + 1);
1180*3d8817e4Smiod   strcpy (name, section_name);
1181*3d8817e4Smiod 
1182*3d8817e4Smiod   if (c == ',')
1183*3d8817e4Smiod     input_line_pointer =
1184*3d8817e4Smiod       tic4x_expression_abs (input_line_pointer, &size);
1185*3d8817e4Smiod   else if (*input_line_pointer == ',')
1186*3d8817e4Smiod     {
1187*3d8817e4Smiod       input_line_pointer =
1188*3d8817e4Smiod 	tic4x_expression_abs (++input_line_pointer, &size);
1189*3d8817e4Smiod     }
1190*3d8817e4Smiod   else
1191*3d8817e4Smiod     size = 0;
1192*3d8817e4Smiod 
1193*3d8817e4Smiod   /* Read a possibly present third argument (alignment flag) [VK].  */
1194*3d8817e4Smiod   if (*input_line_pointer == ',')
1195*3d8817e4Smiod     {
1196*3d8817e4Smiod       input_line_pointer =
1197*3d8817e4Smiod 	tic4x_expression_abs (++input_line_pointer, &alignment_flag);
1198*3d8817e4Smiod     }
1199*3d8817e4Smiod   else
1200*3d8817e4Smiod     alignment_flag = 0;
1201*3d8817e4Smiod   if (alignment_flag)
1202*3d8817e4Smiod     as_warn (".usect: non-zero alignment flag ignored");
1203*3d8817e4Smiod 
1204*3d8817e4Smiod   seg = subseg_new (name, 0);
1205*3d8817e4Smiod   if (line_label != NULL)
1206*3d8817e4Smiod     {
1207*3d8817e4Smiod       S_SET_SEGMENT (line_label, seg);
1208*3d8817e4Smiod       symbol_set_frag (line_label, frag_now);
1209*3d8817e4Smiod       S_SET_VALUE (line_label, frag_now_fix ());
1210*3d8817e4Smiod     }
1211*3d8817e4Smiod   seg_info (seg)->bss = 1;	/* Uninitialised data.  */
1212*3d8817e4Smiod   if (!bfd_set_section_flags (stdoutput, seg, SEC_ALLOC))
1213*3d8817e4Smiod     as_warn ("Error setting flags for \"%s\": %s", name,
1214*3d8817e4Smiod 	     bfd_errmsg (bfd_get_error ()));
1215*3d8817e4Smiod   tic4x_seg_alloc (name, seg, size, line_label);
1216*3d8817e4Smiod 
1217*3d8817e4Smiod   if (S_GET_STORAGE_CLASS (line_label) != C_EXT)
1218*3d8817e4Smiod     S_SET_STORAGE_CLASS (line_label, C_STAT);
1219*3d8817e4Smiod 
1220*3d8817e4Smiod   subseg_set (current_seg, current_subseg);	/* Restore current seg.  */
1221*3d8817e4Smiod   demand_empty_rest_of_line ();
1222*3d8817e4Smiod }
1223*3d8817e4Smiod 
1224*3d8817e4Smiod /* .version cpu-version.  */
1225*3d8817e4Smiod static void
tic4x_version(x)1226*3d8817e4Smiod tic4x_version (x)
1227*3d8817e4Smiod      int x ATTRIBUTE_UNUSED;
1228*3d8817e4Smiod {
1229*3d8817e4Smiod   offsetT temp;
1230*3d8817e4Smiod 
1231*3d8817e4Smiod   input_line_pointer =
1232*3d8817e4Smiod     tic4x_expression_abs (input_line_pointer, &temp);
1233*3d8817e4Smiod   if (!IS_CPU_TIC3X (temp) && !IS_CPU_TIC4X (temp))
1234*3d8817e4Smiod     as_bad ("This assembler does not support processor generation %ld",
1235*3d8817e4Smiod 	    (long) temp);
1236*3d8817e4Smiod 
1237*3d8817e4Smiod   if (tic4x_cpu && temp != (offsetT) tic4x_cpu)
1238*3d8817e4Smiod     as_warn ("Changing processor generation on fly not supported...");
1239*3d8817e4Smiod   tic4x_cpu = temp;
1240*3d8817e4Smiod   demand_empty_rest_of_line ();
1241*3d8817e4Smiod }
1242*3d8817e4Smiod 
1243*3d8817e4Smiod static void
tic4x_init_regtable()1244*3d8817e4Smiod tic4x_init_regtable ()
1245*3d8817e4Smiod {
1246*3d8817e4Smiod   unsigned int i;
1247*3d8817e4Smiod 
1248*3d8817e4Smiod   for (i = 0; i < tic3x_num_registers; i++)
1249*3d8817e4Smiod     tic4x_insert_reg (tic3x_registers[i].name,
1250*3d8817e4Smiod 		    tic3x_registers[i].regno);
1251*3d8817e4Smiod 
1252*3d8817e4Smiod   if (IS_CPU_TIC4X (tic4x_cpu))
1253*3d8817e4Smiod     {
1254*3d8817e4Smiod       /* Add additional Tic4x registers, overriding some C3x ones.  */
1255*3d8817e4Smiod       for (i = 0; i < tic4x_num_registers; i++)
1256*3d8817e4Smiod 	tic4x_insert_reg (tic4x_registers[i].name,
1257*3d8817e4Smiod 			tic4x_registers[i].regno);
1258*3d8817e4Smiod     }
1259*3d8817e4Smiod }
1260*3d8817e4Smiod 
1261*3d8817e4Smiod static void
tic4x_init_symbols()1262*3d8817e4Smiod tic4x_init_symbols ()
1263*3d8817e4Smiod {
1264*3d8817e4Smiod   /* The TI tools accept case insensitive versions of these symbols,
1265*3d8817e4Smiod      we don't !
1266*3d8817e4Smiod 
1267*3d8817e4Smiod      For TI C/Asm 5.0
1268*3d8817e4Smiod 
1269*3d8817e4Smiod      .TMS320xx       30,31,32,40,or 44       set according to -v flag
1270*3d8817e4Smiod      .C3X or .C3x    1 or 0                  1 if -v30,-v31,or -v32
1271*3d8817e4Smiod      .C30            1 or 0                  1 if -v30
1272*3d8817e4Smiod      .C31            1 or 0                  1 if -v31
1273*3d8817e4Smiod      .C32            1 or 0                  1 if -v32
1274*3d8817e4Smiod      .C4X or .C4x    1 or 0                  1 if -v40, or -v44
1275*3d8817e4Smiod      .C40            1 or 0                  1 if -v40
1276*3d8817e4Smiod      .C44            1 or 0                  1 if -v44
1277*3d8817e4Smiod 
1278*3d8817e4Smiod      .REGPARM 1 or 0                  1 if -mr option used
1279*3d8817e4Smiod      .BIGMODEL        1 or 0                  1 if -mb option used
1280*3d8817e4Smiod 
1281*3d8817e4Smiod      These symbols are currently supported but will be removed in a
1282*3d8817e4Smiod      later version:
1283*3d8817e4Smiod      .TMS320C30      1 or 0                  1 if -v30,-v31,or -v32
1284*3d8817e4Smiod      .TMS320C31      1 or 0                  1 if -v31
1285*3d8817e4Smiod      .TMS320C32      1 or 0                  1 if -v32
1286*3d8817e4Smiod      .TMS320C40      1 or 0                  1 if -v40, or -v44
1287*3d8817e4Smiod      .TMS320C44      1 or 0                  1 if -v44
1288*3d8817e4Smiod 
1289*3d8817e4Smiod      Source: TI: TMS320C3x/C4x Assembly Language Tools User's Guide,
1290*3d8817e4Smiod      1997, SPRU035C, p. 3-17/3-18.  */
1291*3d8817e4Smiod   tic4x_insert_sym (".REGPARM", tic4x_reg_args);
1292*3d8817e4Smiod   tic4x_insert_sym (".MEMPARM", !tic4x_reg_args);
1293*3d8817e4Smiod   tic4x_insert_sym (".BIGMODEL", tic4x_big_model);
1294*3d8817e4Smiod   tic4x_insert_sym (".C30INTERRUPT", 0);
1295*3d8817e4Smiod   tic4x_insert_sym (".TMS320xx", tic4x_cpu == 0 ? 40 : tic4x_cpu);
1296*3d8817e4Smiod   tic4x_insert_sym (".C3X", tic4x_cpu == 30 || tic4x_cpu == 31 || tic4x_cpu == 32 || tic4x_cpu == 33);
1297*3d8817e4Smiod   tic4x_insert_sym (".C3x", tic4x_cpu == 30 || tic4x_cpu == 31 || tic4x_cpu == 32 || tic4x_cpu == 33);
1298*3d8817e4Smiod   tic4x_insert_sym (".C4X", tic4x_cpu == 0 || tic4x_cpu == 40 || tic4x_cpu == 44);
1299*3d8817e4Smiod   tic4x_insert_sym (".C4x", tic4x_cpu == 0 || tic4x_cpu == 40 || tic4x_cpu == 44);
1300*3d8817e4Smiod   /* Do we need to have the following symbols also in lower case?  */
1301*3d8817e4Smiod   tic4x_insert_sym (".TMS320C30", tic4x_cpu == 30 || tic4x_cpu == 31 || tic4x_cpu == 32 || tic4x_cpu == 33);
1302*3d8817e4Smiod   tic4x_insert_sym (".tms320C30", tic4x_cpu == 30 || tic4x_cpu == 31 || tic4x_cpu == 32 || tic4x_cpu == 33);
1303*3d8817e4Smiod   tic4x_insert_sym (".TMS320C31", tic4x_cpu == 31);
1304*3d8817e4Smiod   tic4x_insert_sym (".tms320C31", tic4x_cpu == 31);
1305*3d8817e4Smiod   tic4x_insert_sym (".TMS320C32", tic4x_cpu == 32);
1306*3d8817e4Smiod   tic4x_insert_sym (".tms320C32", tic4x_cpu == 32);
1307*3d8817e4Smiod   tic4x_insert_sym (".TMS320C33", tic4x_cpu == 33);
1308*3d8817e4Smiod   tic4x_insert_sym (".tms320C33", tic4x_cpu == 33);
1309*3d8817e4Smiod   tic4x_insert_sym (".TMS320C40", tic4x_cpu == 40 || tic4x_cpu == 44 || tic4x_cpu == 0);
1310*3d8817e4Smiod   tic4x_insert_sym (".tms320C40", tic4x_cpu == 40 || tic4x_cpu == 44 || tic4x_cpu == 0);
1311*3d8817e4Smiod   tic4x_insert_sym (".TMS320C44", tic4x_cpu == 44);
1312*3d8817e4Smiod   tic4x_insert_sym (".tms320C44", tic4x_cpu == 44);
1313*3d8817e4Smiod   tic4x_insert_sym (".TMX320C40", 0);	/* C40 first pass silicon ?  */
1314*3d8817e4Smiod   tic4x_insert_sym (".tmx320C40", 0);
1315*3d8817e4Smiod }
1316*3d8817e4Smiod 
1317*3d8817e4Smiod /* Insert a new instruction template into hash table.  */
1318*3d8817e4Smiod static int
tic4x_inst_insert(inst)1319*3d8817e4Smiod tic4x_inst_insert (inst)
1320*3d8817e4Smiod      tic4x_inst_t *inst;
1321*3d8817e4Smiod {
1322*3d8817e4Smiod   static char prev_name[16];
1323*3d8817e4Smiod   const char *retval = NULL;
1324*3d8817e4Smiod 
1325*3d8817e4Smiod   /* Only insert the first name if have several similar entries.  */
1326*3d8817e4Smiod   if (!strcmp (inst->name, prev_name) || inst->name[0] == '\0')
1327*3d8817e4Smiod     return 1;
1328*3d8817e4Smiod 
1329*3d8817e4Smiod   retval = hash_insert (tic4x_op_hash, inst->name, (PTR) inst);
1330*3d8817e4Smiod   if (retval != NULL)
1331*3d8817e4Smiod     fprintf (stderr, "internal error: can't hash `%s': %s\n",
1332*3d8817e4Smiod 	     inst->name, retval);
1333*3d8817e4Smiod   else
1334*3d8817e4Smiod     strcpy (prev_name, inst->name);
1335*3d8817e4Smiod   return retval == NULL;
1336*3d8817e4Smiod }
1337*3d8817e4Smiod 
1338*3d8817e4Smiod /* Make a new instruction template.  */
1339*3d8817e4Smiod static tic4x_inst_t *
tic4x_inst_make(name,opcode,args)1340*3d8817e4Smiod tic4x_inst_make (name, opcode, args)
1341*3d8817e4Smiod      char *name;
1342*3d8817e4Smiod      unsigned long opcode;
1343*3d8817e4Smiod      char *args;
1344*3d8817e4Smiod {
1345*3d8817e4Smiod   static tic4x_inst_t *insts = NULL;
1346*3d8817e4Smiod   static char *names = NULL;
1347*3d8817e4Smiod   static int index = 0;
1348*3d8817e4Smiod 
1349*3d8817e4Smiod   if (insts == NULL)
1350*3d8817e4Smiod     {
1351*3d8817e4Smiod       /* Allocate memory to store name strings.  */
1352*3d8817e4Smiod       names = (char *) xmalloc (sizeof (char) * 8192);
1353*3d8817e4Smiod       /* Allocate memory for additional insts.  */
1354*3d8817e4Smiod       insts = (tic4x_inst_t *)
1355*3d8817e4Smiod 	xmalloc (sizeof (tic4x_inst_t) * 1024);
1356*3d8817e4Smiod     }
1357*3d8817e4Smiod   insts[index].name = names;
1358*3d8817e4Smiod   insts[index].opcode = opcode;
1359*3d8817e4Smiod   insts[index].opmask = 0xffffffff;
1360*3d8817e4Smiod   insts[index].args = args;
1361*3d8817e4Smiod   index++;
1362*3d8817e4Smiod 
1363*3d8817e4Smiod   do
1364*3d8817e4Smiod     *names++ = *name++;
1365*3d8817e4Smiod   while (*name);
1366*3d8817e4Smiod   *names++ = '\0';
1367*3d8817e4Smiod 
1368*3d8817e4Smiod   return &insts[index - 1];
1369*3d8817e4Smiod }
1370*3d8817e4Smiod 
1371*3d8817e4Smiod /* Add instruction template, creating dynamic templates as required.  */
1372*3d8817e4Smiod static int
tic4x_inst_add(insts)1373*3d8817e4Smiod tic4x_inst_add (insts)
1374*3d8817e4Smiod      tic4x_inst_t *insts;
1375*3d8817e4Smiod {
1376*3d8817e4Smiod   char *s = insts->name;
1377*3d8817e4Smiod   char *d;
1378*3d8817e4Smiod   unsigned int i;
1379*3d8817e4Smiod   int ok = 1;
1380*3d8817e4Smiod   char name[16];
1381*3d8817e4Smiod 
1382*3d8817e4Smiod   d = name;
1383*3d8817e4Smiod 
1384*3d8817e4Smiod   /* We do not care about INSNs that is not a part of our
1385*3d8817e4Smiod      oplevel setting */
1386*3d8817e4Smiod   if (!insts->oplevel & tic4x_oplevel)
1387*3d8817e4Smiod     return ok;
1388*3d8817e4Smiod 
1389*3d8817e4Smiod   while (1)
1390*3d8817e4Smiod     {
1391*3d8817e4Smiod       switch (*s)
1392*3d8817e4Smiod 	{
1393*3d8817e4Smiod 	case 'B':
1394*3d8817e4Smiod 	case 'C':
1395*3d8817e4Smiod 	  /* Dynamically create all the conditional insts.  */
1396*3d8817e4Smiod 	  for (i = 0; i < tic4x_num_conds; i++)
1397*3d8817e4Smiod 	    {
1398*3d8817e4Smiod 	      tic4x_inst_t *inst;
1399*3d8817e4Smiod 	      int k = 0;
1400*3d8817e4Smiod 	      char *c = tic4x_conds[i].name;
1401*3d8817e4Smiod 	      char *e = d;
1402*3d8817e4Smiod 
1403*3d8817e4Smiod 	      while (*c)
1404*3d8817e4Smiod 		*e++ = *c++;
1405*3d8817e4Smiod 	      c = s + 1;
1406*3d8817e4Smiod 	      while (*c)
1407*3d8817e4Smiod 		*e++ = *c++;
1408*3d8817e4Smiod 	      *e = '\0';
1409*3d8817e4Smiod 
1410*3d8817e4Smiod 	      /* If instruction found then have already processed it.  */
1411*3d8817e4Smiod 	      if (hash_find (tic4x_op_hash, name))
1412*3d8817e4Smiod 		return 1;
1413*3d8817e4Smiod 
1414*3d8817e4Smiod 	      do
1415*3d8817e4Smiod 		{
1416*3d8817e4Smiod 		  inst = tic4x_inst_make (name, insts[k].opcode +
1417*3d8817e4Smiod 					(tic4x_conds[i].cond <<
1418*3d8817e4Smiod 					 (*s == 'B' ? 16 : 23)),
1419*3d8817e4Smiod 					insts[k].args);
1420*3d8817e4Smiod 		  if (k == 0)	/* Save strcmp() with following func.  */
1421*3d8817e4Smiod 		    ok &= tic4x_inst_insert (inst);
1422*3d8817e4Smiod 		  k++;
1423*3d8817e4Smiod 		}
1424*3d8817e4Smiod 	      while (!strcmp (insts->name,
1425*3d8817e4Smiod 			      insts[k].name));
1426*3d8817e4Smiod 	    }
1427*3d8817e4Smiod 	  return ok;
1428*3d8817e4Smiod 	  break;
1429*3d8817e4Smiod 
1430*3d8817e4Smiod 	case '\0':
1431*3d8817e4Smiod 	  return tic4x_inst_insert (insts);
1432*3d8817e4Smiod 	  break;
1433*3d8817e4Smiod 
1434*3d8817e4Smiod 	default:
1435*3d8817e4Smiod 	  *d++ = *s++;
1436*3d8817e4Smiod 	  break;
1437*3d8817e4Smiod 	}
1438*3d8817e4Smiod     }
1439*3d8817e4Smiod }
1440*3d8817e4Smiod 
1441*3d8817e4Smiod /* This function is called once, at assembler startup time.  It should
1442*3d8817e4Smiod    set up all the tables, etc., that the MD part of the assembler will
1443*3d8817e4Smiod    need.  */
1444*3d8817e4Smiod void
md_begin()1445*3d8817e4Smiod md_begin ()
1446*3d8817e4Smiod {
1447*3d8817e4Smiod   int ok = 1;
1448*3d8817e4Smiod   unsigned int i;
1449*3d8817e4Smiod 
1450*3d8817e4Smiod   /* Setup the proper opcode level according to the
1451*3d8817e4Smiod      commandline parameters */
1452*3d8817e4Smiod   tic4x_oplevel = OP_C3X;
1453*3d8817e4Smiod 
1454*3d8817e4Smiod   if ( IS_CPU_TIC4X(tic4x_cpu) )
1455*3d8817e4Smiod     tic4x_oplevel |= OP_C4X;
1456*3d8817e4Smiod 
1457*3d8817e4Smiod   if ( (   tic4x_cpu == 31 && tic4x_revision >= 6)
1458*3d8817e4Smiod        || (tic4x_cpu == 32 && tic4x_revision >= 2)
1459*3d8817e4Smiod        || (tic4x_cpu == 33)
1460*3d8817e4Smiod        || tic4x_enhanced )
1461*3d8817e4Smiod     tic4x_oplevel |= OP_ENH;
1462*3d8817e4Smiod 
1463*3d8817e4Smiod   if ( (   tic4x_cpu == 30 && tic4x_revision >= 7)
1464*3d8817e4Smiod        || (tic4x_cpu == 31 && tic4x_revision >= 5)
1465*3d8817e4Smiod        || (tic4x_cpu == 32)
1466*3d8817e4Smiod        || tic4x_lowpower )
1467*3d8817e4Smiod     tic4x_oplevel |= OP_LPWR;
1468*3d8817e4Smiod 
1469*3d8817e4Smiod   if ( (   tic4x_cpu == 30 && tic4x_revision >= 7)
1470*3d8817e4Smiod        || (tic4x_cpu == 31 && tic4x_revision >= 5)
1471*3d8817e4Smiod        || (tic4x_cpu == 32)
1472*3d8817e4Smiod        || (tic4x_cpu == 33)
1473*3d8817e4Smiod        || (tic4x_cpu == 40 && tic4x_revision >= 5)
1474*3d8817e4Smiod        || (tic4x_cpu == 44)
1475*3d8817e4Smiod        || tic4x_idle2 )
1476*3d8817e4Smiod     tic4x_oplevel |= OP_IDLE2;
1477*3d8817e4Smiod 
1478*3d8817e4Smiod   /* Create hash table for mnemonics.  */
1479*3d8817e4Smiod   tic4x_op_hash = hash_new ();
1480*3d8817e4Smiod 
1481*3d8817e4Smiod   /* Create hash table for asg pseudo.  */
1482*3d8817e4Smiod   tic4x_asg_hash = hash_new ();
1483*3d8817e4Smiod 
1484*3d8817e4Smiod   /* Add mnemonics to hash table, expanding conditional mnemonics on fly.  */
1485*3d8817e4Smiod   for (i = 0; i < tic4x_num_insts; i++)
1486*3d8817e4Smiod     ok &= tic4x_inst_add ((void *) &tic4x_insts[i]);
1487*3d8817e4Smiod 
1488*3d8817e4Smiod   /* Create dummy inst to avoid errors accessing end of table.  */
1489*3d8817e4Smiod   tic4x_inst_make ("", 0, "");
1490*3d8817e4Smiod 
1491*3d8817e4Smiod   if (!ok)
1492*3d8817e4Smiod     as_fatal ("Broken assembler.  No assembly attempted.");
1493*3d8817e4Smiod 
1494*3d8817e4Smiod   /* Add registers to symbol table.  */
1495*3d8817e4Smiod   tic4x_init_regtable ();
1496*3d8817e4Smiod 
1497*3d8817e4Smiod   /* Add predefined symbols to symbol table.  */
1498*3d8817e4Smiod   tic4x_init_symbols ();
1499*3d8817e4Smiod }
1500*3d8817e4Smiod 
1501*3d8817e4Smiod void
tic4x_end()1502*3d8817e4Smiod tic4x_end ()
1503*3d8817e4Smiod {
1504*3d8817e4Smiod   bfd_set_arch_mach (stdoutput, bfd_arch_tic4x,
1505*3d8817e4Smiod 		     IS_CPU_TIC4X (tic4x_cpu) ? bfd_mach_tic4x : bfd_mach_tic3x);
1506*3d8817e4Smiod }
1507*3d8817e4Smiod 
1508*3d8817e4Smiod static int
tic4x_indirect_parse(operand,indirect)1509*3d8817e4Smiod tic4x_indirect_parse (operand, indirect)
1510*3d8817e4Smiod      tic4x_operand_t *operand;
1511*3d8817e4Smiod      const tic4x_indirect_t *indirect;
1512*3d8817e4Smiod {
1513*3d8817e4Smiod   char *n = indirect->name;
1514*3d8817e4Smiod   char *s = input_line_pointer;
1515*3d8817e4Smiod   char *b;
1516*3d8817e4Smiod   symbolS *symbolP;
1517*3d8817e4Smiod   char name[32];
1518*3d8817e4Smiod 
1519*3d8817e4Smiod   operand->disp = 0;
1520*3d8817e4Smiod   for (; *n; n++)
1521*3d8817e4Smiod     {
1522*3d8817e4Smiod       switch (*n)
1523*3d8817e4Smiod 	{
1524*3d8817e4Smiod 	case 'a':		/* Need to match aux register.  */
1525*3d8817e4Smiod 	  b = name;
1526*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
1527*3d8817e4Smiod 	  if (*s == '%')
1528*3d8817e4Smiod 	    s++;
1529*3d8817e4Smiod #endif
1530*3d8817e4Smiod 	  while (ISALNUM (*s))
1531*3d8817e4Smiod 	    *b++ = *s++;
1532*3d8817e4Smiod 	  *b++ = '\0';
1533*3d8817e4Smiod 	  if (!(symbolP = symbol_find (name)))
1534*3d8817e4Smiod 	    return 0;
1535*3d8817e4Smiod 
1536*3d8817e4Smiod 	  if (S_GET_SEGMENT (symbolP) != reg_section)
1537*3d8817e4Smiod 	    return 0;
1538*3d8817e4Smiod 
1539*3d8817e4Smiod 	  operand->aregno = S_GET_VALUE (symbolP);
1540*3d8817e4Smiod 	  if (operand->aregno >= REG_AR0 && operand->aregno <= REG_AR7)
1541*3d8817e4Smiod 	    break;
1542*3d8817e4Smiod 
1543*3d8817e4Smiod 	  as_bad ("Auxiliary register AR0--AR7 required for indirect");
1544*3d8817e4Smiod 	  return -1;
1545*3d8817e4Smiod 
1546*3d8817e4Smiod 	case 'd':		/* Need to match constant for disp.  */
1547*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
1548*3d8817e4Smiod 	  if (*s == '%')	/* expr() will die if we don't skip this.  */
1549*3d8817e4Smiod 	    s++;
1550*3d8817e4Smiod #endif
1551*3d8817e4Smiod 	  s = tic4x_expression (s, &operand->expr);
1552*3d8817e4Smiod 	  if (operand->expr.X_op != O_constant)
1553*3d8817e4Smiod 	    return 0;
1554*3d8817e4Smiod 	  operand->disp = operand->expr.X_add_number;
1555*3d8817e4Smiod 	  if (operand->disp < 0 || operand->disp > 255)
1556*3d8817e4Smiod 	    {
1557*3d8817e4Smiod 	      as_bad ("Bad displacement %d (require 0--255)\n",
1558*3d8817e4Smiod 		      operand->disp);
1559*3d8817e4Smiod 	      return -1;
1560*3d8817e4Smiod 	    }
1561*3d8817e4Smiod 	  break;
1562*3d8817e4Smiod 
1563*3d8817e4Smiod 	case 'y':		/* Need to match IR0.  */
1564*3d8817e4Smiod 	case 'z':		/* Need to match IR1.  */
1565*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
1566*3d8817e4Smiod 	  if (*s == '%')
1567*3d8817e4Smiod 	    s++;
1568*3d8817e4Smiod #endif
1569*3d8817e4Smiod 	  s = tic4x_expression (s, &operand->expr);
1570*3d8817e4Smiod 	  if (operand->expr.X_op != O_register)
1571*3d8817e4Smiod 	    return 0;
1572*3d8817e4Smiod 	  if (operand->expr.X_add_number != REG_IR0
1573*3d8817e4Smiod 	      && operand->expr.X_add_number != REG_IR1)
1574*3d8817e4Smiod 	    {
1575*3d8817e4Smiod 	      as_bad ("Index register IR0,IR1 required for displacement");
1576*3d8817e4Smiod 	      return -1;
1577*3d8817e4Smiod 	    }
1578*3d8817e4Smiod 
1579*3d8817e4Smiod 	  if (*n == 'y' && operand->expr.X_add_number == REG_IR0)
1580*3d8817e4Smiod 	    break;
1581*3d8817e4Smiod 	  if (*n == 'z' && operand->expr.X_add_number == REG_IR1)
1582*3d8817e4Smiod 	    break;
1583*3d8817e4Smiod 	  return 0;
1584*3d8817e4Smiod 
1585*3d8817e4Smiod 	case '(':
1586*3d8817e4Smiod 	  if (*s != '(')	/* No displacement, assume to be 1.  */
1587*3d8817e4Smiod 	    {
1588*3d8817e4Smiod 	      operand->disp = 1;
1589*3d8817e4Smiod 	      while (*n != ')')
1590*3d8817e4Smiod 		n++;
1591*3d8817e4Smiod 	    }
1592*3d8817e4Smiod 	  else
1593*3d8817e4Smiod 	    s++;
1594*3d8817e4Smiod 	  break;
1595*3d8817e4Smiod 
1596*3d8817e4Smiod 	default:
1597*3d8817e4Smiod 	  if (TOLOWER (*s) != *n)
1598*3d8817e4Smiod 	    return 0;
1599*3d8817e4Smiod 	  s++;
1600*3d8817e4Smiod 	}
1601*3d8817e4Smiod     }
1602*3d8817e4Smiod   if (*s != ' ' && *s != ',' && *s != '\0')
1603*3d8817e4Smiod     return 0;
1604*3d8817e4Smiod   input_line_pointer = s;
1605*3d8817e4Smiod   return 1;
1606*3d8817e4Smiod }
1607*3d8817e4Smiod 
1608*3d8817e4Smiod static char *
tic4x_operand_parse(s,operand)1609*3d8817e4Smiod tic4x_operand_parse (s, operand)
1610*3d8817e4Smiod      char *s;
1611*3d8817e4Smiod      tic4x_operand_t *operand;
1612*3d8817e4Smiod {
1613*3d8817e4Smiod   unsigned int i;
1614*3d8817e4Smiod   char c;
1615*3d8817e4Smiod   int ret;
1616*3d8817e4Smiod   expressionS *exp = &operand->expr;
1617*3d8817e4Smiod   char *save = input_line_pointer;
1618*3d8817e4Smiod   char *str;
1619*3d8817e4Smiod   char *new;
1620*3d8817e4Smiod   struct hash_entry *entry = NULL;
1621*3d8817e4Smiod 
1622*3d8817e4Smiod   input_line_pointer = s;
1623*3d8817e4Smiod   SKIP_WHITESPACE ();
1624*3d8817e4Smiod 
1625*3d8817e4Smiod   str = input_line_pointer;
1626*3d8817e4Smiod   c = get_symbol_end ();	/* Get terminator.  */
1627*3d8817e4Smiod   new = input_line_pointer;
1628*3d8817e4Smiod   if (strlen (str) && (entry = hash_find (tic4x_asg_hash, str)) != NULL)
1629*3d8817e4Smiod     {
1630*3d8817e4Smiod       *input_line_pointer = c;
1631*3d8817e4Smiod       input_line_pointer = (char *) entry;
1632*3d8817e4Smiod     }
1633*3d8817e4Smiod   else
1634*3d8817e4Smiod     {
1635*3d8817e4Smiod       *input_line_pointer = c;
1636*3d8817e4Smiod       input_line_pointer = str;
1637*3d8817e4Smiod     }
1638*3d8817e4Smiod 
1639*3d8817e4Smiod   operand->mode = M_UNKNOWN;
1640*3d8817e4Smiod   switch (*input_line_pointer)
1641*3d8817e4Smiod     {
1642*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
1643*3d8817e4Smiod     case '%':
1644*3d8817e4Smiod       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
1645*3d8817e4Smiod       if (exp->X_op != O_register)
1646*3d8817e4Smiod 	as_bad ("Expecting a register name");
1647*3d8817e4Smiod       operand->mode = M_REGISTER;
1648*3d8817e4Smiod       break;
1649*3d8817e4Smiod 
1650*3d8817e4Smiod     case '^':
1651*3d8817e4Smiod       /* Denotes high 16 bits.  */
1652*3d8817e4Smiod       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
1653*3d8817e4Smiod       if (exp->X_op == O_constant)
1654*3d8817e4Smiod 	operand->mode = M_IMMED;
1655*3d8817e4Smiod       else if (exp->X_op == O_big)
1656*3d8817e4Smiod 	{
1657*3d8817e4Smiod 	  if (exp->X_add_number)
1658*3d8817e4Smiod 	    as_bad ("Number too large");	/* bignum required */
1659*3d8817e4Smiod 	  else
1660*3d8817e4Smiod 	    {
1661*3d8817e4Smiod 	      tic4x_gen_to_words (generic_floating_point_number,
1662*3d8817e4Smiod 				operand->fwords, S_PRECISION);
1663*3d8817e4Smiod 	      operand->mode = M_IMMED_F;
1664*3d8817e4Smiod 	    }
1665*3d8817e4Smiod 	}
1666*3d8817e4Smiod       /* Allow ori ^foo, ar0 to be equivalent to ldi .hi.foo, ar0  */
1667*3d8817e4Smiod       /* WARNING : The TI C40 assembler cannot do this.  */
1668*3d8817e4Smiod       else if (exp->X_op == O_symbol)
1669*3d8817e4Smiod 	{
1670*3d8817e4Smiod 	  operand->mode = M_HI;
1671*3d8817e4Smiod 	  break;
1672*3d8817e4Smiod 	}
1673*3d8817e4Smiod 
1674*3d8817e4Smiod     case '#':
1675*3d8817e4Smiod       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
1676*3d8817e4Smiod       if (exp->X_op == O_constant)
1677*3d8817e4Smiod 	operand->mode = M_IMMED;
1678*3d8817e4Smiod       else if (exp->X_op == O_big)
1679*3d8817e4Smiod 	{
1680*3d8817e4Smiod 	  if (exp->X_add_number > 0)
1681*3d8817e4Smiod 	    as_bad ("Number too large");	/* bignum required.  */
1682*3d8817e4Smiod 	  else
1683*3d8817e4Smiod 	    {
1684*3d8817e4Smiod 	      tic4x_gen_to_words (generic_floating_point_number,
1685*3d8817e4Smiod 				operand->fwords, S_PRECISION);
1686*3d8817e4Smiod 	      operand->mode = M_IMMED_F;
1687*3d8817e4Smiod 	    }
1688*3d8817e4Smiod 	}
1689*3d8817e4Smiod       /* Allow ori foo, ar0 to be equivalent to ldi .lo.foo, ar0  */
1690*3d8817e4Smiod       /* WARNING : The TI C40 assembler cannot do this.  */
1691*3d8817e4Smiod       else if (exp->X_op == O_symbol)
1692*3d8817e4Smiod 	{
1693*3d8817e4Smiod 	  operand->mode = M_IMMED;
1694*3d8817e4Smiod 	  break;
1695*3d8817e4Smiod 	}
1696*3d8817e4Smiod 
1697*3d8817e4Smiod       else
1698*3d8817e4Smiod 	as_bad ("Expecting a constant value");
1699*3d8817e4Smiod       break;
1700*3d8817e4Smiod     case '\\':
1701*3d8817e4Smiod #endif
1702*3d8817e4Smiod     case '@':
1703*3d8817e4Smiod       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
1704*3d8817e4Smiod       if (exp->X_op != O_constant && exp->X_op != O_symbol)
1705*3d8817e4Smiod 	as_bad ("Bad direct addressing construct %s", s);
1706*3d8817e4Smiod       if (exp->X_op == O_constant)
1707*3d8817e4Smiod 	{
1708*3d8817e4Smiod 	  if (exp->X_add_number < 0)
1709*3d8817e4Smiod 	    as_bad ("Direct value of %ld is not suitable",
1710*3d8817e4Smiod 		    (long) exp->X_add_number);
1711*3d8817e4Smiod 	}
1712*3d8817e4Smiod       operand->mode = M_DIRECT;
1713*3d8817e4Smiod       break;
1714*3d8817e4Smiod 
1715*3d8817e4Smiod     case '*':
1716*3d8817e4Smiod       ret = -1;
1717*3d8817e4Smiod       for (i = 0; i < tic4x_num_indirects; i++)
1718*3d8817e4Smiod 	if ((ret = tic4x_indirect_parse (operand, &tic4x_indirects[i])))
1719*3d8817e4Smiod 	  break;
1720*3d8817e4Smiod       if (ret < 0)
1721*3d8817e4Smiod 	break;
1722*3d8817e4Smiod       if (i < tic4x_num_indirects)
1723*3d8817e4Smiod 	{
1724*3d8817e4Smiod 	  operand->mode = M_INDIRECT;
1725*3d8817e4Smiod 	  /* Indirect addressing mode number.  */
1726*3d8817e4Smiod 	  operand->expr.X_add_number = tic4x_indirects[i].modn;
1727*3d8817e4Smiod 	  /* Convert *+ARn(0) to *ARn etc.  Maybe we should
1728*3d8817e4Smiod 	     squeal about silly ones?  */
1729*3d8817e4Smiod 	  if (operand->expr.X_add_number < 0x08 && !operand->disp)
1730*3d8817e4Smiod 	    operand->expr.X_add_number = 0x18;
1731*3d8817e4Smiod 	}
1732*3d8817e4Smiod       else
1733*3d8817e4Smiod 	as_bad ("Unknown indirect addressing mode");
1734*3d8817e4Smiod       break;
1735*3d8817e4Smiod 
1736*3d8817e4Smiod     default:
1737*3d8817e4Smiod       operand->mode = M_IMMED;	/* Assume immediate.  */
1738*3d8817e4Smiod       str = input_line_pointer;
1739*3d8817e4Smiod       input_line_pointer = tic4x_expression (input_line_pointer, exp);
1740*3d8817e4Smiod       if (exp->X_op == O_register)
1741*3d8817e4Smiod 	{
1742*3d8817e4Smiod 	  know (exp->X_add_symbol == 0);
1743*3d8817e4Smiod 	  know (exp->X_op_symbol == 0);
1744*3d8817e4Smiod 	  operand->mode = M_REGISTER;
1745*3d8817e4Smiod 	  break;
1746*3d8817e4Smiod 	}
1747*3d8817e4Smiod       else if (exp->X_op == O_big)
1748*3d8817e4Smiod 	{
1749*3d8817e4Smiod 	  if (exp->X_add_number > 0)
1750*3d8817e4Smiod 	    as_bad ("Number too large");	/* bignum required.  */
1751*3d8817e4Smiod 	  else
1752*3d8817e4Smiod 	    {
1753*3d8817e4Smiod 	      tic4x_gen_to_words (generic_floating_point_number,
1754*3d8817e4Smiod 				operand->fwords, S_PRECISION);
1755*3d8817e4Smiod 	      operand->mode = M_IMMED_F;
1756*3d8817e4Smiod 	    }
1757*3d8817e4Smiod 	  break;
1758*3d8817e4Smiod 	}
1759*3d8817e4Smiod #ifdef TIC4X_ALT_SYNTAX
1760*3d8817e4Smiod       /* Allow ldi foo, ar0 to be equivalent to ldi @foo, ar0.  */
1761*3d8817e4Smiod       else if (exp->X_op == O_symbol)
1762*3d8817e4Smiod 	{
1763*3d8817e4Smiod 	  operand->mode = M_DIRECT;
1764*3d8817e4Smiod 	  break;
1765*3d8817e4Smiod 	}
1766*3d8817e4Smiod #endif
1767*3d8817e4Smiod     }
1768*3d8817e4Smiod   if (entry == NULL)
1769*3d8817e4Smiod     new = input_line_pointer;
1770*3d8817e4Smiod   input_line_pointer = save;
1771*3d8817e4Smiod   return new;
1772*3d8817e4Smiod }
1773*3d8817e4Smiod 
1774*3d8817e4Smiod static int
tic4x_operands_match(inst,insn,check)1775*3d8817e4Smiod tic4x_operands_match (inst, insn, check)
1776*3d8817e4Smiod      tic4x_inst_t *inst;
1777*3d8817e4Smiod      tic4x_insn_t *insn;
1778*3d8817e4Smiod      int check;
1779*3d8817e4Smiod {
1780*3d8817e4Smiod   const char *args = inst->args;
1781*3d8817e4Smiod   unsigned long opcode = inst->opcode;
1782*3d8817e4Smiod   int num_operands = insn->num_operands;
1783*3d8817e4Smiod   tic4x_operand_t *operand = insn->operands;
1784*3d8817e4Smiod   expressionS *exp = &operand->expr;
1785*3d8817e4Smiod   int ret = 1;
1786*3d8817e4Smiod   int reg;
1787*3d8817e4Smiod 
1788*3d8817e4Smiod   /* Build the opcode, checking as we go to make sure that the
1789*3d8817e4Smiod      operands match.
1790*3d8817e4Smiod 
1791*3d8817e4Smiod      If an operand matches, we modify insn or opcode appropriately,
1792*3d8817e4Smiod      and do a "continue".  If an operand fails to match, we "break".  */
1793*3d8817e4Smiod 
1794*3d8817e4Smiod   insn->nchars = 4;		/* Instructions always 4 bytes.  */
1795*3d8817e4Smiod   insn->reloc = NO_RELOC;
1796*3d8817e4Smiod   insn->pcrel = 0;
1797*3d8817e4Smiod 
1798*3d8817e4Smiod   if (*args == '\0')
1799*3d8817e4Smiod     {
1800*3d8817e4Smiod       insn->opcode = opcode;
1801*3d8817e4Smiod       return num_operands == 0;
1802*3d8817e4Smiod     }
1803*3d8817e4Smiod 
1804*3d8817e4Smiod   for (;; ++args)
1805*3d8817e4Smiod     {
1806*3d8817e4Smiod       switch (*args)
1807*3d8817e4Smiod 	{
1808*3d8817e4Smiod 
1809*3d8817e4Smiod 	case '\0':		/* End of args.  */
1810*3d8817e4Smiod 	  if (num_operands == 1)
1811*3d8817e4Smiod 	    {
1812*3d8817e4Smiod 	      insn->opcode = opcode;
1813*3d8817e4Smiod 	      return ret;
1814*3d8817e4Smiod 	    }
1815*3d8817e4Smiod 	  break;		/* Too many operands.  */
1816*3d8817e4Smiod 
1817*3d8817e4Smiod 	case '#':		/* This is only used for ldp.  */
1818*3d8817e4Smiod 	  if (operand->mode != M_DIRECT && operand->mode != M_IMMED)
1819*3d8817e4Smiod 	    break;
1820*3d8817e4Smiod 	  /* While this looks like a direct addressing mode, we actually
1821*3d8817e4Smiod 	     use an immediate mode form of ldiu or ldpk instruction.  */
1822*3d8817e4Smiod 	  if (exp->X_op == O_constant)
1823*3d8817e4Smiod 	    {
1824*3d8817e4Smiod               if( ( IS_CPU_TIC4X (tic4x_cpu) && exp->X_add_number <= 65535 )
1825*3d8817e4Smiod                   || ( IS_CPU_TIC3X (tic4x_cpu) && exp->X_add_number <= 255 ) )
1826*3d8817e4Smiod                 {
1827*3d8817e4Smiod                   INSERTS (opcode, exp->X_add_number, 15, 0);
1828*3d8817e4Smiod                   continue;
1829*3d8817e4Smiod                 }
1830*3d8817e4Smiod               else
1831*3d8817e4Smiod                 {
1832*3d8817e4Smiod 		  if (!check)
1833*3d8817e4Smiod                     as_bad ("Immediate value of %ld is too large for ldf",
1834*3d8817e4Smiod                             (long) exp->X_add_number);
1835*3d8817e4Smiod 		  ret = -1;
1836*3d8817e4Smiod 		  continue;
1837*3d8817e4Smiod                 }
1838*3d8817e4Smiod 	    }
1839*3d8817e4Smiod 	  else if (exp->X_op == O_symbol)
1840*3d8817e4Smiod 	    {
1841*3d8817e4Smiod 	      insn->reloc = BFD_RELOC_HI16;
1842*3d8817e4Smiod 	      insn->exp = *exp;
1843*3d8817e4Smiod 	      continue;
1844*3d8817e4Smiod 	    }
1845*3d8817e4Smiod 	  break;		/* Not direct (dp) addressing.  */
1846*3d8817e4Smiod 
1847*3d8817e4Smiod 	case '@':		/* direct.  */
1848*3d8817e4Smiod 	  if (operand->mode != M_DIRECT)
1849*3d8817e4Smiod 	    break;
1850*3d8817e4Smiod 	  if (exp->X_op == O_constant)
1851*3d8817e4Smiod             {
1852*3d8817e4Smiod               /* Store only the 16 LSBs of the number.  */
1853*3d8817e4Smiod               INSERTS (opcode, exp->X_add_number, 15, 0);
1854*3d8817e4Smiod               continue;
1855*3d8817e4Smiod 	    }
1856*3d8817e4Smiod 	  else if (exp->X_op == O_symbol)
1857*3d8817e4Smiod 	    {
1858*3d8817e4Smiod 	      insn->reloc = BFD_RELOC_LO16;
1859*3d8817e4Smiod 	      insn->exp = *exp;
1860*3d8817e4Smiod 	      continue;
1861*3d8817e4Smiod 	    }
1862*3d8817e4Smiod 	  break;		/* Not direct addressing.  */
1863*3d8817e4Smiod 
1864*3d8817e4Smiod 	case 'A':
1865*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
1866*3d8817e4Smiod 	    break;
1867*3d8817e4Smiod 	  reg = exp->X_add_number;
1868*3d8817e4Smiod 	  if (reg >= REG_AR0 && reg <= REG_AR7)
1869*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_AR0, 24, 22);
1870*3d8817e4Smiod 	  else
1871*3d8817e4Smiod 	    {
1872*3d8817e4Smiod               if (!check)
1873*3d8817e4Smiod                 as_bad ("Destination register must be ARn");
1874*3d8817e4Smiod 	      ret = -1;
1875*3d8817e4Smiod 	    }
1876*3d8817e4Smiod 	  continue;
1877*3d8817e4Smiod 
1878*3d8817e4Smiod 	case 'B':		/* Unsigned integer immediate.  */
1879*3d8817e4Smiod 	  /* Allow br label or br @label.  */
1880*3d8817e4Smiod 	  if (operand->mode != M_IMMED && operand->mode != M_DIRECT)
1881*3d8817e4Smiod 	    break;
1882*3d8817e4Smiod 	  if (exp->X_op == O_constant)
1883*3d8817e4Smiod 	    {
1884*3d8817e4Smiod 	      if (exp->X_add_number < (1 << 24))
1885*3d8817e4Smiod 		{
1886*3d8817e4Smiod 		  INSERTU (opcode, exp->X_add_number, 23, 0);
1887*3d8817e4Smiod 		  continue;
1888*3d8817e4Smiod 		}
1889*3d8817e4Smiod 	      else
1890*3d8817e4Smiod 		{
1891*3d8817e4Smiod 		  if (!check)
1892*3d8817e4Smiod                     as_bad ("Immediate value of %ld is too large",
1893*3d8817e4Smiod                             (long) exp->X_add_number);
1894*3d8817e4Smiod 		  ret = -1;
1895*3d8817e4Smiod 		  continue;
1896*3d8817e4Smiod 		}
1897*3d8817e4Smiod 	    }
1898*3d8817e4Smiod 	  if (IS_CPU_TIC4X (tic4x_cpu))
1899*3d8817e4Smiod 	    {
1900*3d8817e4Smiod 	      insn->reloc = BFD_RELOC_24_PCREL;
1901*3d8817e4Smiod 	      insn->pcrel = 1;
1902*3d8817e4Smiod 	    }
1903*3d8817e4Smiod 	  else
1904*3d8817e4Smiod 	    {
1905*3d8817e4Smiod 	      insn->reloc = BFD_RELOC_24;
1906*3d8817e4Smiod 	      insn->pcrel = 0;
1907*3d8817e4Smiod 	    }
1908*3d8817e4Smiod 	  insn->exp = *exp;
1909*3d8817e4Smiod 	  continue;
1910*3d8817e4Smiod 
1911*3d8817e4Smiod 	case 'C':
1912*3d8817e4Smiod 	  if (!IS_CPU_TIC4X (tic4x_cpu))
1913*3d8817e4Smiod 	    break;
1914*3d8817e4Smiod 	  if (operand->mode != M_INDIRECT)
1915*3d8817e4Smiod 	    break;
1916*3d8817e4Smiod 	  /* Require either *+ARn(disp) or *ARn.  */
1917*3d8817e4Smiod 	  if (operand->expr.X_add_number != 0
1918*3d8817e4Smiod 	      && operand->expr.X_add_number != 0x18)
1919*3d8817e4Smiod 	    {
1920*3d8817e4Smiod               if (!check)
1921*3d8817e4Smiod                 as_bad ("Invalid indirect addressing mode");
1922*3d8817e4Smiod               ret = -1;
1923*3d8817e4Smiod 	      continue;
1924*3d8817e4Smiod 	    }
1925*3d8817e4Smiod 	  INSERTU (opcode, operand->aregno - REG_AR0, 2, 0);
1926*3d8817e4Smiod 	  INSERTU (opcode, operand->disp, 7, 3);
1927*3d8817e4Smiod 	  continue;
1928*3d8817e4Smiod 
1929*3d8817e4Smiod 	case 'E':
1930*3d8817e4Smiod 	  if (!(operand->mode == M_REGISTER))
1931*3d8817e4Smiod 	    break;
1932*3d8817e4Smiod 	  INSERTU (opcode, exp->X_add_number, 7, 0);
1933*3d8817e4Smiod 	  continue;
1934*3d8817e4Smiod 
1935*3d8817e4Smiod         case 'e':
1936*3d8817e4Smiod           if (!(operand->mode == M_REGISTER))
1937*3d8817e4Smiod             break;
1938*3d8817e4Smiod 	  reg = exp->X_add_number;
1939*3d8817e4Smiod 	  if ( (reg >= REG_R0 && reg <= REG_R7)
1940*3d8817e4Smiod                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
1941*3d8817e4Smiod 	    INSERTU (opcode, reg, 7, 0);
1942*3d8817e4Smiod 	  else
1943*3d8817e4Smiod 	    {
1944*3d8817e4Smiod               if (!check)
1945*3d8817e4Smiod                 as_bad ("Register must be Rn");
1946*3d8817e4Smiod 	      ret = -1;
1947*3d8817e4Smiod 	    }
1948*3d8817e4Smiod           continue;
1949*3d8817e4Smiod 
1950*3d8817e4Smiod 	case 'F':
1951*3d8817e4Smiod 	  if (operand->mode != M_IMMED_F
1952*3d8817e4Smiod 	      && !(operand->mode == M_IMMED && exp->X_op == O_constant))
1953*3d8817e4Smiod 	    break;
1954*3d8817e4Smiod 
1955*3d8817e4Smiod 	  if (operand->mode != M_IMMED_F)
1956*3d8817e4Smiod 	    {
1957*3d8817e4Smiod 	      /* OK, we 've got something like cmpf 0, r0
1958*3d8817e4Smiod 	         Why can't they stick in a bloody decimal point ?!  */
1959*3d8817e4Smiod 	      char string[16];
1960*3d8817e4Smiod 
1961*3d8817e4Smiod 	      /* Create floating point number string.  */
1962*3d8817e4Smiod 	      sprintf (string, "%d.0", (int) exp->X_add_number);
1963*3d8817e4Smiod 	      tic4x_atof (string, 's', operand->fwords);
1964*3d8817e4Smiod 	    }
1965*3d8817e4Smiod 
1966*3d8817e4Smiod 	  INSERTU (opcode, operand->fwords[0], 15, 0);
1967*3d8817e4Smiod 	  continue;
1968*3d8817e4Smiod 
1969*3d8817e4Smiod 	case 'G':
1970*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
1971*3d8817e4Smiod 	    break;
1972*3d8817e4Smiod 	  INSERTU (opcode, exp->X_add_number, 15, 8);
1973*3d8817e4Smiod 	  continue;
1974*3d8817e4Smiod 
1975*3d8817e4Smiod         case 'g':
1976*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
1977*3d8817e4Smiod 	    break;
1978*3d8817e4Smiod 	  reg = exp->X_add_number;
1979*3d8817e4Smiod 	  if ( (reg >= REG_R0 && reg <= REG_R7)
1980*3d8817e4Smiod                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
1981*3d8817e4Smiod 	    INSERTU (opcode, reg, 15, 8);
1982*3d8817e4Smiod 	  else
1983*3d8817e4Smiod 	    {
1984*3d8817e4Smiod               if (!check)
1985*3d8817e4Smiod                 as_bad ("Register must be Rn");
1986*3d8817e4Smiod 	      ret = -1;
1987*3d8817e4Smiod 	    }
1988*3d8817e4Smiod           continue;
1989*3d8817e4Smiod 
1990*3d8817e4Smiod 	case 'H':
1991*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
1992*3d8817e4Smiod 	    break;
1993*3d8817e4Smiod 	  reg = exp->X_add_number;
1994*3d8817e4Smiod 	  if (reg >= REG_R0 && reg <= REG_R7)
1995*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_R0, 18, 16);
1996*3d8817e4Smiod 	  else
1997*3d8817e4Smiod 	    {
1998*3d8817e4Smiod               if (!check)
1999*3d8817e4Smiod                 as_bad ("Register must be R0--R7");
2000*3d8817e4Smiod 	      ret = -1;
2001*3d8817e4Smiod 	    }
2002*3d8817e4Smiod 	  continue;
2003*3d8817e4Smiod 
2004*3d8817e4Smiod         case 'i':
2005*3d8817e4Smiod           if ( operand->mode == M_REGISTER
2006*3d8817e4Smiod                && tic4x_oplevel & OP_ENH )
2007*3d8817e4Smiod             {
2008*3d8817e4Smiod               reg = exp->X_add_number;
2009*3d8817e4Smiod               INSERTU (opcode, reg, 4, 0);
2010*3d8817e4Smiod               INSERTU (opcode, 7, 7, 5);
2011*3d8817e4Smiod               continue;
2012*3d8817e4Smiod             }
2013*3d8817e4Smiod           /* Fallthrough */
2014*3d8817e4Smiod 
2015*3d8817e4Smiod 	case 'I':
2016*3d8817e4Smiod 	  if (operand->mode != M_INDIRECT)
2017*3d8817e4Smiod 	    break;
2018*3d8817e4Smiod 	  if (operand->disp != 0 && operand->disp != 1)
2019*3d8817e4Smiod 	    {
2020*3d8817e4Smiod 	      if (IS_CPU_TIC4X (tic4x_cpu))
2021*3d8817e4Smiod 		break;
2022*3d8817e4Smiod               if (!check)
2023*3d8817e4Smiod                 as_bad ("Invalid indirect addressing mode displacement %d",
2024*3d8817e4Smiod                         operand->disp);
2025*3d8817e4Smiod 	      ret = -1;
2026*3d8817e4Smiod 	      continue;
2027*3d8817e4Smiod 	    }
2028*3d8817e4Smiod 	  INSERTU (opcode, operand->aregno - REG_AR0, 2, 0);
2029*3d8817e4Smiod 	  INSERTU (opcode, operand->expr.X_add_number, 7, 3);
2030*3d8817e4Smiod 	  continue;
2031*3d8817e4Smiod 
2032*3d8817e4Smiod         case 'j':
2033*3d8817e4Smiod           if ( operand->mode == M_REGISTER
2034*3d8817e4Smiod                && tic4x_oplevel & OP_ENH )
2035*3d8817e4Smiod             {
2036*3d8817e4Smiod               reg = exp->X_add_number;
2037*3d8817e4Smiod               INSERTU (opcode, reg, 12, 8);
2038*3d8817e4Smiod               INSERTU (opcode, 7, 15, 13);
2039*3d8817e4Smiod               continue;
2040*3d8817e4Smiod             }
2041*3d8817e4Smiod           /* Fallthrough */
2042*3d8817e4Smiod 
2043*3d8817e4Smiod 	case 'J':
2044*3d8817e4Smiod 	  if (operand->mode != M_INDIRECT)
2045*3d8817e4Smiod 	    break;
2046*3d8817e4Smiod 	  if (operand->disp != 0 && operand->disp != 1)
2047*3d8817e4Smiod 	    {
2048*3d8817e4Smiod 	      if (IS_CPU_TIC4X (tic4x_cpu))
2049*3d8817e4Smiod 		break;
2050*3d8817e4Smiod               if (!check)
2051*3d8817e4Smiod                 as_bad ("Invalid indirect addressing mode displacement %d",
2052*3d8817e4Smiod                         operand->disp);
2053*3d8817e4Smiod 	      ret = -1;
2054*3d8817e4Smiod 	      continue;
2055*3d8817e4Smiod 	    }
2056*3d8817e4Smiod 	  INSERTU (opcode, operand->aregno - REG_AR0, 10, 8);
2057*3d8817e4Smiod 	  INSERTU (opcode, operand->expr.X_add_number, 15, 11);
2058*3d8817e4Smiod 	  continue;
2059*3d8817e4Smiod 
2060*3d8817e4Smiod 	case 'K':
2061*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2062*3d8817e4Smiod 	    break;
2063*3d8817e4Smiod 	  reg = exp->X_add_number;
2064*3d8817e4Smiod 	  if (reg >= REG_R0 && reg <= REG_R7)
2065*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_R0, 21, 19);
2066*3d8817e4Smiod 	  else
2067*3d8817e4Smiod 	    {
2068*3d8817e4Smiod               if (!check)
2069*3d8817e4Smiod                 as_bad ("Register must be R0--R7");
2070*3d8817e4Smiod 	      ret = -1;
2071*3d8817e4Smiod 	    }
2072*3d8817e4Smiod 	  continue;
2073*3d8817e4Smiod 
2074*3d8817e4Smiod 	case 'L':
2075*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2076*3d8817e4Smiod 	    break;
2077*3d8817e4Smiod 	  reg = exp->X_add_number;
2078*3d8817e4Smiod 	  if (reg >= REG_R0 && reg <= REG_R7)
2079*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_R0, 24, 22);
2080*3d8817e4Smiod 	  else
2081*3d8817e4Smiod 	    {
2082*3d8817e4Smiod               if (!check)
2083*3d8817e4Smiod                 as_bad ("Register must be R0--R7");
2084*3d8817e4Smiod 	      ret = -1;
2085*3d8817e4Smiod 	    }
2086*3d8817e4Smiod 	  continue;
2087*3d8817e4Smiod 
2088*3d8817e4Smiod 	case 'M':
2089*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2090*3d8817e4Smiod 	    break;
2091*3d8817e4Smiod 	  reg = exp->X_add_number;
2092*3d8817e4Smiod 	  if (reg == REG_R2 || reg == REG_R3)
2093*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_R2, 22, 22);
2094*3d8817e4Smiod 	  else
2095*3d8817e4Smiod 	    {
2096*3d8817e4Smiod               if (!check)
2097*3d8817e4Smiod                 as_bad ("Destination register must be R2 or R3");
2098*3d8817e4Smiod 	      ret = -1;
2099*3d8817e4Smiod 	    }
2100*3d8817e4Smiod 	  continue;
2101*3d8817e4Smiod 
2102*3d8817e4Smiod 	case 'N':
2103*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2104*3d8817e4Smiod 	    break;
2105*3d8817e4Smiod 	  reg = exp->X_add_number;
2106*3d8817e4Smiod 	  if (reg == REG_R0 || reg == REG_R1)
2107*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_R0, 23, 23);
2108*3d8817e4Smiod 	  else
2109*3d8817e4Smiod 	    {
2110*3d8817e4Smiod               if (!check)
2111*3d8817e4Smiod                 as_bad ("Destination register must be R0 or R1");
2112*3d8817e4Smiod 	      ret = -1;
2113*3d8817e4Smiod 	    }
2114*3d8817e4Smiod 	  continue;
2115*3d8817e4Smiod 
2116*3d8817e4Smiod 	case 'O':
2117*3d8817e4Smiod 	  if (!IS_CPU_TIC4X (tic4x_cpu))
2118*3d8817e4Smiod 	    break;
2119*3d8817e4Smiod 	  if (operand->mode != M_INDIRECT)
2120*3d8817e4Smiod 	    break;
2121*3d8817e4Smiod 	  /* Require either *+ARn(disp) or *ARn.  */
2122*3d8817e4Smiod 	  if (operand->expr.X_add_number != 0
2123*3d8817e4Smiod 	      && operand->expr.X_add_number != 0x18)
2124*3d8817e4Smiod 	    {
2125*3d8817e4Smiod               if (!check)
2126*3d8817e4Smiod                 as_bad ("Invalid indirect addressing mode");
2127*3d8817e4Smiod 	      ret = -1;
2128*3d8817e4Smiod 	      continue;
2129*3d8817e4Smiod 	    }
2130*3d8817e4Smiod 	  INSERTU (opcode, operand->aregno - REG_AR0, 10, 8);
2131*3d8817e4Smiod 	  INSERTU (opcode, operand->disp, 15, 11);
2132*3d8817e4Smiod 	  continue;
2133*3d8817e4Smiod 
2134*3d8817e4Smiod 	case 'P':		/* PC relative displacement.  */
2135*3d8817e4Smiod 	  /* Allow br label or br @label.  */
2136*3d8817e4Smiod 	  if (operand->mode != M_IMMED && operand->mode != M_DIRECT)
2137*3d8817e4Smiod 	    break;
2138*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2139*3d8817e4Smiod 	    {
2140*3d8817e4Smiod 	      if (exp->X_add_number >= -32768 && exp->X_add_number <= 32767)
2141*3d8817e4Smiod 		{
2142*3d8817e4Smiod 		  INSERTS (opcode, exp->X_add_number, 15, 0);
2143*3d8817e4Smiod 		  continue;
2144*3d8817e4Smiod 		}
2145*3d8817e4Smiod 	      else
2146*3d8817e4Smiod 		{
2147*3d8817e4Smiod                   if (!check)
2148*3d8817e4Smiod                     as_bad ("Displacement value of %ld is too large",
2149*3d8817e4Smiod                             (long) exp->X_add_number);
2150*3d8817e4Smiod 		  ret = -1;
2151*3d8817e4Smiod 		  continue;
2152*3d8817e4Smiod 		}
2153*3d8817e4Smiod 	    }
2154*3d8817e4Smiod 	  insn->reloc = BFD_RELOC_16_PCREL;
2155*3d8817e4Smiod 	  insn->pcrel = 1;
2156*3d8817e4Smiod 	  insn->exp = *exp;
2157*3d8817e4Smiod 	  continue;
2158*3d8817e4Smiod 
2159*3d8817e4Smiod 	case 'Q':
2160*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2161*3d8817e4Smiod 	    break;
2162*3d8817e4Smiod 	  reg = exp->X_add_number;
2163*3d8817e4Smiod 	  INSERTU (opcode, reg, 15, 0);
2164*3d8817e4Smiod 	  continue;
2165*3d8817e4Smiod 
2166*3d8817e4Smiod         case 'q':
2167*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2168*3d8817e4Smiod 	    break;
2169*3d8817e4Smiod 	  reg = exp->X_add_number;
2170*3d8817e4Smiod 	  if ( (reg >= REG_R0 && reg <= REG_R7)
2171*3d8817e4Smiod                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
2172*3d8817e4Smiod 	    INSERTU (opcode, reg, 15, 0);
2173*3d8817e4Smiod 	  else
2174*3d8817e4Smiod 	    {
2175*3d8817e4Smiod               if (!check)
2176*3d8817e4Smiod                 as_bad ("Register must be Rn");
2177*3d8817e4Smiod 	      ret = -1;
2178*3d8817e4Smiod 	    }
2179*3d8817e4Smiod           continue;
2180*3d8817e4Smiod 
2181*3d8817e4Smiod 	case 'R':
2182*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2183*3d8817e4Smiod 	    break;
2184*3d8817e4Smiod 	  reg = exp->X_add_number;
2185*3d8817e4Smiod 	  INSERTU (opcode, reg, 20, 16);
2186*3d8817e4Smiod 	  continue;
2187*3d8817e4Smiod 
2188*3d8817e4Smiod         case 'r':
2189*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2190*3d8817e4Smiod 	    break;
2191*3d8817e4Smiod 	  reg = exp->X_add_number;
2192*3d8817e4Smiod 	  if ( (reg >= REG_R0 && reg <= REG_R7)
2193*3d8817e4Smiod                || (IS_CPU_TIC4X (tic4x_cpu) && reg >= REG_R8 && reg <= REG_R11) )
2194*3d8817e4Smiod 	    INSERTU (opcode, reg, 20, 16);
2195*3d8817e4Smiod 	  else
2196*3d8817e4Smiod 	    {
2197*3d8817e4Smiod               if (!check)
2198*3d8817e4Smiod                 as_bad ("Register must be Rn");
2199*3d8817e4Smiod 	      ret = -1;
2200*3d8817e4Smiod 	    }
2201*3d8817e4Smiod           continue;
2202*3d8817e4Smiod 
2203*3d8817e4Smiod 	case 'S':		/* Short immediate int.  */
2204*3d8817e4Smiod 	  if (operand->mode != M_IMMED && operand->mode != M_HI)
2205*3d8817e4Smiod 	    break;
2206*3d8817e4Smiod 	  if (exp->X_op == O_big)
2207*3d8817e4Smiod 	    {
2208*3d8817e4Smiod               if (!check)
2209*3d8817e4Smiod                 as_bad ("Floating point number not valid in expression");
2210*3d8817e4Smiod 	      ret = -1;
2211*3d8817e4Smiod 	      continue;
2212*3d8817e4Smiod 	    }
2213*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2214*3d8817e4Smiod 	    {
2215*3d8817e4Smiod 	      if (exp->X_add_number >= -32768 && exp->X_add_number <= 65535)
2216*3d8817e4Smiod 		{
2217*3d8817e4Smiod 		  INSERTS (opcode, exp->X_add_number, 15, 0);
2218*3d8817e4Smiod 		  continue;
2219*3d8817e4Smiod 		}
2220*3d8817e4Smiod 	      else
2221*3d8817e4Smiod 		{
2222*3d8817e4Smiod 		  if (!check)
2223*3d8817e4Smiod                     as_bad ("Signed immediate value %ld too large",
2224*3d8817e4Smiod                             (long) exp->X_add_number);
2225*3d8817e4Smiod 		  ret = -1;
2226*3d8817e4Smiod 		  continue;
2227*3d8817e4Smiod 		}
2228*3d8817e4Smiod 	    }
2229*3d8817e4Smiod 	  else if (exp->X_op == O_symbol)
2230*3d8817e4Smiod 	    {
2231*3d8817e4Smiod 	      if (operand->mode == M_HI)
2232*3d8817e4Smiod 		{
2233*3d8817e4Smiod 		  insn->reloc = BFD_RELOC_HI16;
2234*3d8817e4Smiod 		}
2235*3d8817e4Smiod 	      else
2236*3d8817e4Smiod 		{
2237*3d8817e4Smiod 		  insn->reloc = BFD_RELOC_LO16;
2238*3d8817e4Smiod 		}
2239*3d8817e4Smiod 	      insn->exp = *exp;
2240*3d8817e4Smiod 	      continue;
2241*3d8817e4Smiod 	    }
2242*3d8817e4Smiod 	  /* Handle cases like ldi foo - $, ar0  where foo
2243*3d8817e4Smiod 	     is a forward reference.  Perhaps we should check
2244*3d8817e4Smiod 	     for X_op == O_symbol and disallow things like
2245*3d8817e4Smiod 	     ldi foo, ar0.  */
2246*3d8817e4Smiod 	  insn->reloc = BFD_RELOC_16;
2247*3d8817e4Smiod 	  insn->exp = *exp;
2248*3d8817e4Smiod 	  continue;
2249*3d8817e4Smiod 
2250*3d8817e4Smiod 	case 'T':		/* 5-bit immediate value for tic4x stik.  */
2251*3d8817e4Smiod 	  if (!IS_CPU_TIC4X (tic4x_cpu))
2252*3d8817e4Smiod 	    break;
2253*3d8817e4Smiod 	  if (operand->mode != M_IMMED)
2254*3d8817e4Smiod 	    break;
2255*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2256*3d8817e4Smiod 	    {
2257*3d8817e4Smiod 	      if (exp->X_add_number < 16 && exp->X_add_number >= -16)
2258*3d8817e4Smiod 		{
2259*3d8817e4Smiod 		  INSERTS (opcode, exp->X_add_number, 20, 16);
2260*3d8817e4Smiod 		  continue;
2261*3d8817e4Smiod 		}
2262*3d8817e4Smiod 	      else
2263*3d8817e4Smiod 		{
2264*3d8817e4Smiod                   if (!check)
2265*3d8817e4Smiod                     as_bad ("Immediate value of %ld is too large",
2266*3d8817e4Smiod                             (long) exp->X_add_number);
2267*3d8817e4Smiod 		  ret = -1;
2268*3d8817e4Smiod 		  continue;
2269*3d8817e4Smiod 		}
2270*3d8817e4Smiod 	    }
2271*3d8817e4Smiod 	  break;		/* No relocations allowed.  */
2272*3d8817e4Smiod 
2273*3d8817e4Smiod 	case 'U':		/* Unsigned integer immediate.  */
2274*3d8817e4Smiod 	  if (operand->mode != M_IMMED && operand->mode != M_HI)
2275*3d8817e4Smiod 	    break;
2276*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2277*3d8817e4Smiod 	    {
2278*3d8817e4Smiod 	      if (exp->X_add_number < (1 << 16) && exp->X_add_number >= 0)
2279*3d8817e4Smiod 		{
2280*3d8817e4Smiod 		  INSERTU (opcode, exp->X_add_number, 15, 0);
2281*3d8817e4Smiod 		  continue;
2282*3d8817e4Smiod 		}
2283*3d8817e4Smiod 	      else
2284*3d8817e4Smiod 		{
2285*3d8817e4Smiod                   if (!check)
2286*3d8817e4Smiod                     as_bad ("Unsigned immediate value %ld too large",
2287*3d8817e4Smiod                             (long) exp->X_add_number);
2288*3d8817e4Smiod 		  ret = -1;
2289*3d8817e4Smiod 		  continue;
2290*3d8817e4Smiod 		}
2291*3d8817e4Smiod 	    }
2292*3d8817e4Smiod 	  else if (exp->X_op == O_symbol)
2293*3d8817e4Smiod 	    {
2294*3d8817e4Smiod 	      if (operand->mode == M_HI)
2295*3d8817e4Smiod 		insn->reloc = BFD_RELOC_HI16;
2296*3d8817e4Smiod 	      else
2297*3d8817e4Smiod 		insn->reloc = BFD_RELOC_LO16;
2298*3d8817e4Smiod 
2299*3d8817e4Smiod 	      insn->exp = *exp;
2300*3d8817e4Smiod 	      continue;
2301*3d8817e4Smiod 	    }
2302*3d8817e4Smiod 	  insn->reloc = BFD_RELOC_16;
2303*3d8817e4Smiod 	  insn->exp = *exp;
2304*3d8817e4Smiod 	  continue;
2305*3d8817e4Smiod 
2306*3d8817e4Smiod 	case 'V':		/* Trap numbers (immediate field).  */
2307*3d8817e4Smiod 	  if (operand->mode != M_IMMED)
2308*3d8817e4Smiod 	    break;
2309*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2310*3d8817e4Smiod 	    {
2311*3d8817e4Smiod 	      if (exp->X_add_number < 512 && IS_CPU_TIC4X (tic4x_cpu))
2312*3d8817e4Smiod 		{
2313*3d8817e4Smiod 		  INSERTU (opcode, exp->X_add_number, 8, 0);
2314*3d8817e4Smiod 		  continue;
2315*3d8817e4Smiod 		}
2316*3d8817e4Smiod 	      else if (exp->X_add_number < 32 && IS_CPU_TIC3X (tic4x_cpu))
2317*3d8817e4Smiod 		{
2318*3d8817e4Smiod 		  INSERTU (opcode, exp->X_add_number | 0x20, 4, 0);
2319*3d8817e4Smiod 		  continue;
2320*3d8817e4Smiod 		}
2321*3d8817e4Smiod 	      else
2322*3d8817e4Smiod 		{
2323*3d8817e4Smiod                   if (!check)
2324*3d8817e4Smiod                     as_bad ("Immediate value of %ld is too large",
2325*3d8817e4Smiod                             (long) exp->X_add_number);
2326*3d8817e4Smiod 		  ret = -1;
2327*3d8817e4Smiod 		  continue;
2328*3d8817e4Smiod 		}
2329*3d8817e4Smiod 	    }
2330*3d8817e4Smiod 	  break;		/* No relocations allowed.  */
2331*3d8817e4Smiod 
2332*3d8817e4Smiod 	case 'W':		/* Short immediate int (0--7).  */
2333*3d8817e4Smiod 	  if (!IS_CPU_TIC4X (tic4x_cpu))
2334*3d8817e4Smiod 	    break;
2335*3d8817e4Smiod 	  if (operand->mode != M_IMMED)
2336*3d8817e4Smiod 	    break;
2337*3d8817e4Smiod 	  if (exp->X_op == O_big)
2338*3d8817e4Smiod 	    {
2339*3d8817e4Smiod               if (!check)
2340*3d8817e4Smiod                 as_bad ("Floating point number not valid in expression");
2341*3d8817e4Smiod 	      ret = -1;
2342*3d8817e4Smiod 	      continue;
2343*3d8817e4Smiod 	    }
2344*3d8817e4Smiod 	  if (exp->X_op == O_constant)
2345*3d8817e4Smiod 	    {
2346*3d8817e4Smiod 	      if (exp->X_add_number >= -256 && exp->X_add_number <= 127)
2347*3d8817e4Smiod 		{
2348*3d8817e4Smiod 		  INSERTS (opcode, exp->X_add_number, 7, 0);
2349*3d8817e4Smiod 		  continue;
2350*3d8817e4Smiod 		}
2351*3d8817e4Smiod 	      else
2352*3d8817e4Smiod 		{
2353*3d8817e4Smiod                   if (!check)
2354*3d8817e4Smiod                     as_bad ("Immediate value %ld too large",
2355*3d8817e4Smiod                             (long) exp->X_add_number);
2356*3d8817e4Smiod 		  ret = -1;
2357*3d8817e4Smiod 		  continue;
2358*3d8817e4Smiod 		}
2359*3d8817e4Smiod 	    }
2360*3d8817e4Smiod 	  insn->reloc = BFD_RELOC_16;
2361*3d8817e4Smiod 	  insn->exp = *exp;
2362*3d8817e4Smiod 	  continue;
2363*3d8817e4Smiod 
2364*3d8817e4Smiod 	case 'X':		/* Expansion register for tic4x.  */
2365*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2366*3d8817e4Smiod 	    break;
2367*3d8817e4Smiod 	  reg = exp->X_add_number;
2368*3d8817e4Smiod 	  if (reg >= REG_IVTP && reg <= REG_TVTP)
2369*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_IVTP, 4, 0);
2370*3d8817e4Smiod 	  else
2371*3d8817e4Smiod 	    {
2372*3d8817e4Smiod               if (!check)
2373*3d8817e4Smiod                 as_bad ("Register must be ivtp or tvtp");
2374*3d8817e4Smiod 	      ret = -1;
2375*3d8817e4Smiod 	    }
2376*3d8817e4Smiod 	  continue;
2377*3d8817e4Smiod 
2378*3d8817e4Smiod 	case 'Y':		/* Address register for tic4x lda.  */
2379*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2380*3d8817e4Smiod 	    break;
2381*3d8817e4Smiod 	  reg = exp->X_add_number;
2382*3d8817e4Smiod 	  if (reg >= REG_AR0 && reg <= REG_SP)
2383*3d8817e4Smiod 	    INSERTU (opcode, reg, 20, 16);
2384*3d8817e4Smiod 	  else
2385*3d8817e4Smiod 	    {
2386*3d8817e4Smiod               if (!check)
2387*3d8817e4Smiod                 as_bad ("Register must be address register");
2388*3d8817e4Smiod 	      ret = -1;
2389*3d8817e4Smiod 	    }
2390*3d8817e4Smiod 	  continue;
2391*3d8817e4Smiod 
2392*3d8817e4Smiod 	case 'Z':		/* Expansion register for tic4x.  */
2393*3d8817e4Smiod 	  if (operand->mode != M_REGISTER)
2394*3d8817e4Smiod 	    break;
2395*3d8817e4Smiod 	  reg = exp->X_add_number;
2396*3d8817e4Smiod 	  if (reg >= REG_IVTP && reg <= REG_TVTP)
2397*3d8817e4Smiod 	    INSERTU (opcode, reg - REG_IVTP, 20, 16);
2398*3d8817e4Smiod 	  else
2399*3d8817e4Smiod 	    {
2400*3d8817e4Smiod               if (!check)
2401*3d8817e4Smiod                 as_bad ("Register must be ivtp or tvtp");
2402*3d8817e4Smiod 	      ret = -1;
2403*3d8817e4Smiod 	    }
2404*3d8817e4Smiod 	  continue;
2405*3d8817e4Smiod 
2406*3d8817e4Smiod 	case '*':
2407*3d8817e4Smiod 	  if (operand->mode != M_INDIRECT)
2408*3d8817e4Smiod 	    break;
2409*3d8817e4Smiod 	  INSERTS (opcode, operand->disp, 7, 0);
2410*3d8817e4Smiod 	  INSERTU (opcode, operand->aregno - REG_AR0, 10, 8);
2411*3d8817e4Smiod 	  INSERTU (opcode, operand->expr.X_add_number, 15, 11);
2412*3d8817e4Smiod 	  continue;
2413*3d8817e4Smiod 
2414*3d8817e4Smiod 	case '|':		/* treat as `,' if have ldi_ldi form.  */
2415*3d8817e4Smiod 	  if (insn->parallel)
2416*3d8817e4Smiod 	    {
2417*3d8817e4Smiod 	      if (--num_operands < 0)
2418*3d8817e4Smiod 		break;		/* Too few operands.  */
2419*3d8817e4Smiod 	      operand++;
2420*3d8817e4Smiod 	      if (operand->mode != M_PARALLEL)
2421*3d8817e4Smiod 		break;
2422*3d8817e4Smiod 	    }
2423*3d8817e4Smiod 	  /* Fall through.  */
2424*3d8817e4Smiod 
2425*3d8817e4Smiod 	case ',':		/* Another operand.  */
2426*3d8817e4Smiod 	  if (--num_operands < 0)
2427*3d8817e4Smiod 	    break;		/* Too few operands.  */
2428*3d8817e4Smiod 	  operand++;
2429*3d8817e4Smiod 	  exp = &operand->expr;
2430*3d8817e4Smiod 	  continue;
2431*3d8817e4Smiod 
2432*3d8817e4Smiod 	case ';':		/* Another optional operand.  */
2433*3d8817e4Smiod 	  if (num_operands == 1 || operand[1].mode == M_PARALLEL)
2434*3d8817e4Smiod 	    continue;
2435*3d8817e4Smiod 	  if (--num_operands < 0)
2436*3d8817e4Smiod 	    break;		/* Too few operands.  */
2437*3d8817e4Smiod 	  operand++;
2438*3d8817e4Smiod 	  exp = &operand->expr;
2439*3d8817e4Smiod 	  continue;
2440*3d8817e4Smiod 
2441*3d8817e4Smiod 	default:
2442*3d8817e4Smiod 	  BAD_CASE (*args);
2443*3d8817e4Smiod 	}
2444*3d8817e4Smiod       return 0;
2445*3d8817e4Smiod     }
2446*3d8817e4Smiod }
2447*3d8817e4Smiod 
2448*3d8817e4Smiod static void
tic4x_insn_check(insn)2449*3d8817e4Smiod tic4x_insn_check (insn)
2450*3d8817e4Smiod      tic4x_insn_t *insn;
2451*3d8817e4Smiod {
2452*3d8817e4Smiod 
2453*3d8817e4Smiod   if (!strcmp(insn->name, "lda"))
2454*3d8817e4Smiod     {
2455*3d8817e4Smiod       if (insn->num_operands < 2 || insn->num_operands > 2)
2456*3d8817e4Smiod         as_fatal ("Illegal internal LDA insn definition");
2457*3d8817e4Smiod 
2458*3d8817e4Smiod       if ( insn->operands[0].mode == M_REGISTER
2459*3d8817e4Smiod            && insn->operands[1].mode == M_REGISTER
2460*3d8817e4Smiod            && insn->operands[0].expr.X_add_number == insn->operands[1].expr.X_add_number )
2461*3d8817e4Smiod         as_bad ("Source and destination register should not be equal");
2462*3d8817e4Smiod     }
2463*3d8817e4Smiod   else if( !strcmp(insn->name, "ldi_ldi")
2464*3d8817e4Smiod            || !strcmp(insn->name, "ldi1_ldi2")
2465*3d8817e4Smiod            || !strcmp(insn->name, "ldi2_ldi1")
2466*3d8817e4Smiod            || !strcmp(insn->name, "ldf_ldf")
2467*3d8817e4Smiod            || !strcmp(insn->name, "ldf1_ldf2")
2468*3d8817e4Smiod            || !strcmp(insn->name, "ldf2_ldf1") )
2469*3d8817e4Smiod     {
2470*3d8817e4Smiod       if ( insn->num_operands < 4 && insn->num_operands > 5 )
2471*3d8817e4Smiod         as_fatal ("Illegal internal %s insn definition", insn->name);
2472*3d8817e4Smiod 
2473*3d8817e4Smiod       if ( insn->operands[1].mode == M_REGISTER
2474*3d8817e4Smiod            && insn->operands[insn->num_operands-1].mode == M_REGISTER
2475*3d8817e4Smiod            && insn->operands[1].expr.X_add_number == insn->operands[insn->num_operands-1].expr.X_add_number )
2476*3d8817e4Smiod         as_warn ("Equal parallell destination registers, one result will be discarded");
2477*3d8817e4Smiod     }
2478*3d8817e4Smiod }
2479*3d8817e4Smiod 
2480*3d8817e4Smiod static void
tic4x_insn_output(insn)2481*3d8817e4Smiod tic4x_insn_output (insn)
2482*3d8817e4Smiod      tic4x_insn_t *insn;
2483*3d8817e4Smiod {
2484*3d8817e4Smiod   char *dst;
2485*3d8817e4Smiod 
2486*3d8817e4Smiod   /* Grab another fragment for opcode.  */
2487*3d8817e4Smiod   dst = frag_more (insn->nchars);
2488*3d8817e4Smiod 
2489*3d8817e4Smiod   /* Put out opcode word as a series of bytes in little endian order.  */
2490*3d8817e4Smiod   md_number_to_chars (dst, insn->opcode, insn->nchars);
2491*3d8817e4Smiod 
2492*3d8817e4Smiod   /* Put out the symbol-dependent stuff.  */
2493*3d8817e4Smiod   if (insn->reloc != NO_RELOC)
2494*3d8817e4Smiod     {
2495*3d8817e4Smiod       /* Where is the offset into the fragment for this instruction.  */
2496*3d8817e4Smiod       fix_new_exp (frag_now,
2497*3d8817e4Smiod 		   dst - frag_now->fr_literal,	/* where */
2498*3d8817e4Smiod 		   insn->nchars,	/* size */
2499*3d8817e4Smiod 		   &insn->exp,
2500*3d8817e4Smiod 		   insn->pcrel,
2501*3d8817e4Smiod 		   insn->reloc);
2502*3d8817e4Smiod     }
2503*3d8817e4Smiod }
2504*3d8817e4Smiod 
2505*3d8817e4Smiod /* Parse the operands.  */
2506*3d8817e4Smiod int
tic4x_operands_parse(s,operands,num_operands)2507*3d8817e4Smiod tic4x_operands_parse (s, operands, num_operands)
2508*3d8817e4Smiod      char *s;
2509*3d8817e4Smiod      tic4x_operand_t *operands;
2510*3d8817e4Smiod      int num_operands;
2511*3d8817e4Smiod {
2512*3d8817e4Smiod   if (!*s)
2513*3d8817e4Smiod     return num_operands;
2514*3d8817e4Smiod 
2515*3d8817e4Smiod   do
2516*3d8817e4Smiod     s = tic4x_operand_parse (s, &operands[num_operands++]);
2517*3d8817e4Smiod   while (num_operands < TIC4X_OPERANDS_MAX && *s++ == ',');
2518*3d8817e4Smiod 
2519*3d8817e4Smiod   if (num_operands > TIC4X_OPERANDS_MAX)
2520*3d8817e4Smiod     {
2521*3d8817e4Smiod       as_bad ("Too many operands scanned");
2522*3d8817e4Smiod       return -1;
2523*3d8817e4Smiod     }
2524*3d8817e4Smiod   return num_operands;
2525*3d8817e4Smiod }
2526*3d8817e4Smiod 
2527*3d8817e4Smiod /* Assemble a single instruction.  Its label has already been handled
2528*3d8817e4Smiod    by the generic front end.  We just parse mnemonic and operands, and
2529*3d8817e4Smiod    produce the bytes of data and relocation.  */
2530*3d8817e4Smiod void
md_assemble(str)2531*3d8817e4Smiod md_assemble (str)
2532*3d8817e4Smiod      char *str;
2533*3d8817e4Smiod {
2534*3d8817e4Smiod   int ok = 0;
2535*3d8817e4Smiod   char *s;
2536*3d8817e4Smiod   int i;
2537*3d8817e4Smiod   int parsed = 0;
2538*3d8817e4Smiod   tic4x_inst_t *inst;		/* Instruction template.  */
2539*3d8817e4Smiod   tic4x_inst_t *first_inst;
2540*3d8817e4Smiod 
2541*3d8817e4Smiod   /* Scan for parallel operators */
2542*3d8817e4Smiod   if (str)
2543*3d8817e4Smiod     {
2544*3d8817e4Smiod       s = str;
2545*3d8817e4Smiod       while (*s && *s != '|')
2546*3d8817e4Smiod         s++;
2547*3d8817e4Smiod 
2548*3d8817e4Smiod       if (*s && s[1]=='|')
2549*3d8817e4Smiod         {
2550*3d8817e4Smiod           if(insn->parallel)
2551*3d8817e4Smiod             {
2552*3d8817e4Smiod               as_bad ("Parallel opcode cannot contain more than two instructions");
2553*3d8817e4Smiod               insn->parallel = 0;
2554*3d8817e4Smiod               insn->in_use = 0;
2555*3d8817e4Smiod               return;
2556*3d8817e4Smiod             }
2557*3d8817e4Smiod 
2558*3d8817e4Smiod           /* Lets take care of the first part of the parallel insn */
2559*3d8817e4Smiod           *s++ = 0;
2560*3d8817e4Smiod           md_assemble(str);
2561*3d8817e4Smiod           insn->parallel = 1;
2562*3d8817e4Smiod           str = ++s;
2563*3d8817e4Smiod           /* .. and let the second run though here */
2564*3d8817e4Smiod         }
2565*3d8817e4Smiod     }
2566*3d8817e4Smiod 
2567*3d8817e4Smiod   if (str && insn->parallel)
2568*3d8817e4Smiod     {
2569*3d8817e4Smiod       /* Find mnemonic (second part of parallel instruction).  */
2570*3d8817e4Smiod       s = str;
2571*3d8817e4Smiod       /* Skip past instruction mnemonic.  */
2572*3d8817e4Smiod       while (*s && *s != ' ')
2573*3d8817e4Smiod 	s++;
2574*3d8817e4Smiod       if (*s)			/* Null terminate for hash_find.  */
2575*3d8817e4Smiod 	*s++ = '\0';		/* and skip past null.  */
2576*3d8817e4Smiod       strcat (insn->name, "_");
2577*3d8817e4Smiod       strncat (insn->name, str, TIC4X_NAME_MAX - strlen (insn->name));
2578*3d8817e4Smiod 
2579*3d8817e4Smiod       insn->operands[insn->num_operands++].mode = M_PARALLEL;
2580*3d8817e4Smiod 
2581*3d8817e4Smiod       if ((i = tic4x_operands_parse
2582*3d8817e4Smiod 	   (s, insn->operands, insn->num_operands)) < 0)
2583*3d8817e4Smiod 	{
2584*3d8817e4Smiod 	  insn->parallel = 0;
2585*3d8817e4Smiod 	  insn->in_use = 0;
2586*3d8817e4Smiod 	  return;
2587*3d8817e4Smiod 	}
2588*3d8817e4Smiod       insn->num_operands = i;
2589*3d8817e4Smiod       parsed = 1;
2590*3d8817e4Smiod     }
2591*3d8817e4Smiod 
2592*3d8817e4Smiod   if (insn->in_use)
2593*3d8817e4Smiod     {
2594*3d8817e4Smiod       if ((insn->inst = (struct tic4x_inst *)
2595*3d8817e4Smiod 	   hash_find (tic4x_op_hash, insn->name)) == NULL)
2596*3d8817e4Smiod 	{
2597*3d8817e4Smiod 	  as_bad ("Unknown opcode `%s'.", insn->name);
2598*3d8817e4Smiod 	  insn->parallel = 0;
2599*3d8817e4Smiod 	  insn->in_use = 0;
2600*3d8817e4Smiod 	  return;
2601*3d8817e4Smiod 	}
2602*3d8817e4Smiod 
2603*3d8817e4Smiod       inst = insn->inst;
2604*3d8817e4Smiod       first_inst = NULL;
2605*3d8817e4Smiod       do
2606*3d8817e4Smiod         {
2607*3d8817e4Smiod           ok = tic4x_operands_match (inst, insn, 1);
2608*3d8817e4Smiod           if (ok < 0)
2609*3d8817e4Smiod             {
2610*3d8817e4Smiod               if (!first_inst)
2611*3d8817e4Smiod                 first_inst = inst;
2612*3d8817e4Smiod               ok = 0;
2613*3d8817e4Smiod             }
2614*3d8817e4Smiod       } while (!ok && !strcmp (inst->name, inst[1].name) && inst++);
2615*3d8817e4Smiod 
2616*3d8817e4Smiod       if (ok > 0)
2617*3d8817e4Smiod         {
2618*3d8817e4Smiod           tic4x_insn_check (insn);
2619*3d8817e4Smiod           tic4x_insn_output (insn);
2620*3d8817e4Smiod         }
2621*3d8817e4Smiod       else if (!ok)
2622*3d8817e4Smiod         {
2623*3d8817e4Smiod           if (first_inst)
2624*3d8817e4Smiod             tic4x_operands_match (first_inst, insn, 0);
2625*3d8817e4Smiod           as_bad ("Invalid operands for %s", insn->name);
2626*3d8817e4Smiod         }
2627*3d8817e4Smiod       else
2628*3d8817e4Smiod 	as_bad ("Invalid instruction %s", insn->name);
2629*3d8817e4Smiod     }
2630*3d8817e4Smiod 
2631*3d8817e4Smiod   if (str && !parsed)
2632*3d8817e4Smiod     {
2633*3d8817e4Smiod       /* Find mnemonic.  */
2634*3d8817e4Smiod       s = str;
2635*3d8817e4Smiod       while (*s && *s != ' ')	/* Skip past instruction mnemonic.  */
2636*3d8817e4Smiod 	s++;
2637*3d8817e4Smiod       if (*s)			/* Null terminate for hash_find.  */
2638*3d8817e4Smiod 	*s++ = '\0';		/* and skip past null.  */
2639*3d8817e4Smiod       strncpy (insn->name, str, TIC4X_NAME_MAX - 3);
2640*3d8817e4Smiod 
2641*3d8817e4Smiod       if ((i = tic4x_operands_parse (s, insn->operands, 0)) < 0)
2642*3d8817e4Smiod 	{
2643*3d8817e4Smiod 	  insn->inst = NULL;	/* Flag that error occured.  */
2644*3d8817e4Smiod 	  insn->parallel = 0;
2645*3d8817e4Smiod 	  insn->in_use = 0;
2646*3d8817e4Smiod 	  return;
2647*3d8817e4Smiod 	}
2648*3d8817e4Smiod       insn->num_operands = i;
2649*3d8817e4Smiod       insn->in_use = 1;
2650*3d8817e4Smiod     }
2651*3d8817e4Smiod   else
2652*3d8817e4Smiod     insn->in_use = 0;
2653*3d8817e4Smiod   insn->parallel = 0;
2654*3d8817e4Smiod }
2655*3d8817e4Smiod 
2656*3d8817e4Smiod void
tic4x_cleanup()2657*3d8817e4Smiod tic4x_cleanup ()
2658*3d8817e4Smiod {
2659*3d8817e4Smiod   if (insn->in_use)
2660*3d8817e4Smiod     md_assemble (NULL);
2661*3d8817e4Smiod }
2662*3d8817e4Smiod 
2663*3d8817e4Smiod /* Turn a string in input_line_pointer into a floating point constant
2664*3d8817e4Smiod    of type type, and store the appropriate bytes in *litP.  The number
2665*3d8817e4Smiod    of LITTLENUMS emitted is stored in *sizeP.  An error message is
2666*3d8817e4Smiod    returned, or NULL on OK.  */
2667*3d8817e4Smiod 
2668*3d8817e4Smiod char *
md_atof(type,litP,sizeP)2669*3d8817e4Smiod md_atof (type, litP, sizeP)
2670*3d8817e4Smiod      int type;
2671*3d8817e4Smiod      char *litP;
2672*3d8817e4Smiod      int *sizeP;
2673*3d8817e4Smiod {
2674*3d8817e4Smiod   int prec;
2675*3d8817e4Smiod   int ieee;
2676*3d8817e4Smiod   LITTLENUM_TYPE words[MAX_LITTLENUMS];
2677*3d8817e4Smiod   LITTLENUM_TYPE *wordP;
2678*3d8817e4Smiod   char *t;
2679*3d8817e4Smiod 
2680*3d8817e4Smiod   switch (type)
2681*3d8817e4Smiod     {
2682*3d8817e4Smiod     case 's':			/* .single */
2683*3d8817e4Smiod     case 'S':
2684*3d8817e4Smiod       ieee = 0;
2685*3d8817e4Smiod       prec = 1;
2686*3d8817e4Smiod       break;
2687*3d8817e4Smiod 
2688*3d8817e4Smiod     case 'd':			/* .double */
2689*3d8817e4Smiod     case 'D':
2690*3d8817e4Smiod     case 'f':			/* .float or .single */
2691*3d8817e4Smiod     case 'F':
2692*3d8817e4Smiod       ieee = 0;
2693*3d8817e4Smiod       prec = 2;			/* 1 32-bit word */
2694*3d8817e4Smiod       break;
2695*3d8817e4Smiod 
2696*3d8817e4Smiod     case 'i':			/* .ieee */
2697*3d8817e4Smiod     case 'I':
2698*3d8817e4Smiod       prec = 2;
2699*3d8817e4Smiod       ieee = 1;
2700*3d8817e4Smiod       type = 'f';  /* Rewrite type to be usable by atof_ieee() */
2701*3d8817e4Smiod       break;
2702*3d8817e4Smiod 
2703*3d8817e4Smiod     case 'e':			/* .ldouble */
2704*3d8817e4Smiod     case 'E':
2705*3d8817e4Smiod       prec = 4;			/* 2 32-bit words */
2706*3d8817e4Smiod       ieee = 0;
2707*3d8817e4Smiod       break;
2708*3d8817e4Smiod 
2709*3d8817e4Smiod     default:
2710*3d8817e4Smiod       *sizeP = 0;
2711*3d8817e4Smiod       return "Bad call to md_atof()";
2712*3d8817e4Smiod     }
2713*3d8817e4Smiod 
2714*3d8817e4Smiod   if (ieee)
2715*3d8817e4Smiod     t = atof_ieee (input_line_pointer, type, words);
2716*3d8817e4Smiod   else
2717*3d8817e4Smiod     t = tic4x_atof (input_line_pointer, type, words);
2718*3d8817e4Smiod   if (t)
2719*3d8817e4Smiod     input_line_pointer = t;
2720*3d8817e4Smiod   *sizeP = prec * sizeof (LITTLENUM_TYPE);
2721*3d8817e4Smiod 
2722*3d8817e4Smiod   /* This loops outputs the LITTLENUMs in REVERSE order; in accord with
2723*3d8817e4Smiod      little endian byte order.  */
2724*3d8817e4Smiod   /* SES: However it is required to put the words (32-bits) out in the
2725*3d8817e4Smiod      correct order, hence we write 2 and 2 littlenums in little endian
2726*3d8817e4Smiod      order, while we keep the original order on successive words. */
2727*3d8817e4Smiod   for(wordP = words; wordP<(words+prec) ; wordP+=2)
2728*3d8817e4Smiod     {
2729*3d8817e4Smiod       if (wordP<(words+prec-1)) /* Dump wordP[1] (if we have one) */
2730*3d8817e4Smiod         {
2731*3d8817e4Smiod           md_number_to_chars (litP, (valueT) (wordP[1]),
2732*3d8817e4Smiod                               sizeof (LITTLENUM_TYPE));
2733*3d8817e4Smiod           litP += sizeof (LITTLENUM_TYPE);
2734*3d8817e4Smiod         }
2735*3d8817e4Smiod 
2736*3d8817e4Smiod       /* Dump wordP[0] */
2737*3d8817e4Smiod       md_number_to_chars (litP, (valueT) (wordP[0]),
2738*3d8817e4Smiod                           sizeof (LITTLENUM_TYPE));
2739*3d8817e4Smiod       litP += sizeof (LITTLENUM_TYPE);
2740*3d8817e4Smiod     }
2741*3d8817e4Smiod   return 0;
2742*3d8817e4Smiod }
2743*3d8817e4Smiod 
2744*3d8817e4Smiod void
md_apply_fix(fixP,value,seg)2745*3d8817e4Smiod md_apply_fix (fixP, value, seg)
2746*3d8817e4Smiod      fixS *fixP;
2747*3d8817e4Smiod      valueT *value;
2748*3d8817e4Smiod      segT seg ATTRIBUTE_UNUSED;
2749*3d8817e4Smiod {
2750*3d8817e4Smiod   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2751*3d8817e4Smiod   valueT val = *value;
2752*3d8817e4Smiod 
2753*3d8817e4Smiod   switch (fixP->fx_r_type)
2754*3d8817e4Smiod     {
2755*3d8817e4Smiod     case BFD_RELOC_HI16:
2756*3d8817e4Smiod       val >>= 16;
2757*3d8817e4Smiod       break;
2758*3d8817e4Smiod 
2759*3d8817e4Smiod     case BFD_RELOC_LO16:
2760*3d8817e4Smiod       val &= 0xffff;
2761*3d8817e4Smiod       break;
2762*3d8817e4Smiod     default:
2763*3d8817e4Smiod       break;
2764*3d8817e4Smiod     }
2765*3d8817e4Smiod 
2766*3d8817e4Smiod   switch (fixP->fx_r_type)
2767*3d8817e4Smiod     {
2768*3d8817e4Smiod     case BFD_RELOC_32:
2769*3d8817e4Smiod       buf[3] = val >> 24;
2770*3d8817e4Smiod     case BFD_RELOC_24:
2771*3d8817e4Smiod     case BFD_RELOC_24_PCREL:
2772*3d8817e4Smiod       buf[2] = val >> 16;
2773*3d8817e4Smiod     case BFD_RELOC_16:
2774*3d8817e4Smiod     case BFD_RELOC_16_PCREL:
2775*3d8817e4Smiod     case BFD_RELOC_LO16:
2776*3d8817e4Smiod     case BFD_RELOC_HI16:
2777*3d8817e4Smiod       buf[1] = val >> 8;
2778*3d8817e4Smiod       buf[0] = val;
2779*3d8817e4Smiod       break;
2780*3d8817e4Smiod 
2781*3d8817e4Smiod     case NO_RELOC:
2782*3d8817e4Smiod     default:
2783*3d8817e4Smiod       as_bad ("Bad relocation type: 0x%02x", fixP->fx_r_type);
2784*3d8817e4Smiod       break;
2785*3d8817e4Smiod     }
2786*3d8817e4Smiod 
2787*3d8817e4Smiod   if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) fixP->fx_done = 1;
2788*3d8817e4Smiod }
2789*3d8817e4Smiod 
2790*3d8817e4Smiod /* Should never be called for tic4x.  */
2791*3d8817e4Smiod void
md_convert_frag(headers,sec,fragP)2792*3d8817e4Smiod md_convert_frag (headers, sec, fragP)
2793*3d8817e4Smiod      bfd *headers ATTRIBUTE_UNUSED;
2794*3d8817e4Smiod      segT sec ATTRIBUTE_UNUSED;
2795*3d8817e4Smiod      fragS *fragP ATTRIBUTE_UNUSED;
2796*3d8817e4Smiod {
2797*3d8817e4Smiod   as_fatal ("md_convert_frag");
2798*3d8817e4Smiod }
2799*3d8817e4Smiod 
2800*3d8817e4Smiod /* Should never be called for tic4x.  */
2801*3d8817e4Smiod void
md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)2802*3d8817e4Smiod md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2803*3d8817e4Smiod      char *ptr ATTRIBUTE_UNUSED;
2804*3d8817e4Smiod      addressT from_addr ATTRIBUTE_UNUSED;
2805*3d8817e4Smiod      addressT to_addr ATTRIBUTE_UNUSED;
2806*3d8817e4Smiod      fragS *frag ATTRIBUTE_UNUSED;
2807*3d8817e4Smiod      symbolS *to_symbol ATTRIBUTE_UNUSED;
2808*3d8817e4Smiod {
2809*3d8817e4Smiod   as_fatal ("md_create_short_jmp\n");
2810*3d8817e4Smiod }
2811*3d8817e4Smiod 
2812*3d8817e4Smiod /* Should never be called for tic4x.  */
2813*3d8817e4Smiod void
md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)2814*3d8817e4Smiod md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2815*3d8817e4Smiod      char *ptr ATTRIBUTE_UNUSED;
2816*3d8817e4Smiod      addressT from_addr ATTRIBUTE_UNUSED;
2817*3d8817e4Smiod      addressT to_addr ATTRIBUTE_UNUSED;
2818*3d8817e4Smiod      fragS *frag ATTRIBUTE_UNUSED;
2819*3d8817e4Smiod      symbolS *to_symbol ATTRIBUTE_UNUSED;
2820*3d8817e4Smiod {
2821*3d8817e4Smiod   as_fatal ("md_create_long_jump\n");
2822*3d8817e4Smiod }
2823*3d8817e4Smiod 
2824*3d8817e4Smiod /* Should never be called for tic4x.  */
2825*3d8817e4Smiod int
md_estimate_size_before_relax(fragP,segtype)2826*3d8817e4Smiod md_estimate_size_before_relax (fragP, segtype)
2827*3d8817e4Smiod      register fragS *fragP ATTRIBUTE_UNUSED;
2828*3d8817e4Smiod      segT segtype ATTRIBUTE_UNUSED;
2829*3d8817e4Smiod {
2830*3d8817e4Smiod   as_fatal ("md_estimate_size_before_relax\n");
2831*3d8817e4Smiod   return 0;
2832*3d8817e4Smiod }
2833*3d8817e4Smiod 
2834*3d8817e4Smiod 
2835*3d8817e4Smiod int
md_parse_option(c,arg)2836*3d8817e4Smiod md_parse_option (c, arg)
2837*3d8817e4Smiod      int c;
2838*3d8817e4Smiod      char *arg;
2839*3d8817e4Smiod {
2840*3d8817e4Smiod   switch (c)
2841*3d8817e4Smiod     {
2842*3d8817e4Smiod     case OPTION_CPU:             /* cpu brand */
2843*3d8817e4Smiod       if (TOLOWER (*arg) == 'c')
2844*3d8817e4Smiod 	arg++;
2845*3d8817e4Smiod       tic4x_cpu = atoi (arg);
2846*3d8817e4Smiod       if (!IS_CPU_TIC3X (tic4x_cpu) && !IS_CPU_TIC4X (tic4x_cpu))
2847*3d8817e4Smiod 	as_warn ("Unsupported processor generation %d", tic4x_cpu);
2848*3d8817e4Smiod       break;
2849*3d8817e4Smiod 
2850*3d8817e4Smiod     case OPTION_REV:             /* cpu revision */
2851*3d8817e4Smiod       tic4x_revision = atoi (arg);
2852*3d8817e4Smiod       break;
2853*3d8817e4Smiod 
2854*3d8817e4Smiod     case 'b':
2855*3d8817e4Smiod       as_warn ("Option -b is depreciated, please use -mbig");
2856*3d8817e4Smiod     case OPTION_BIG:             /* big model */
2857*3d8817e4Smiod       tic4x_big_model = 1;
2858*3d8817e4Smiod       break;
2859*3d8817e4Smiod 
2860*3d8817e4Smiod     case 'p':
2861*3d8817e4Smiod       as_warn ("Option -p is depreciated, please use -mmemparm");
2862*3d8817e4Smiod     case OPTION_MEMPARM:         /* push args */
2863*3d8817e4Smiod       tic4x_reg_args = 0;
2864*3d8817e4Smiod       break;
2865*3d8817e4Smiod 
2866*3d8817e4Smiod     case 'r':
2867*3d8817e4Smiod       as_warn ("Option -r is depreciated, please use -mregparm");
2868*3d8817e4Smiod     case OPTION_REGPARM:        /* register args */
2869*3d8817e4Smiod       tic4x_reg_args = 1;
2870*3d8817e4Smiod       break;
2871*3d8817e4Smiod 
2872*3d8817e4Smiod     case 's':
2873*3d8817e4Smiod       as_warn ("Option -s is depreciated, please use -msmall");
2874*3d8817e4Smiod     case OPTION_SMALL:		/* small model */
2875*3d8817e4Smiod       tic4x_big_model = 0;
2876*3d8817e4Smiod       break;
2877*3d8817e4Smiod 
2878*3d8817e4Smiod     case OPTION_IDLE2:
2879*3d8817e4Smiod       tic4x_idle2 = 1;
2880*3d8817e4Smiod       break;
2881*3d8817e4Smiod 
2882*3d8817e4Smiod     case OPTION_LOWPOWER:
2883*3d8817e4Smiod       tic4x_lowpower = 1;
2884*3d8817e4Smiod       break;
2885*3d8817e4Smiod 
2886*3d8817e4Smiod     case OPTION_ENHANCED:
2887*3d8817e4Smiod       tic4x_enhanced = 1;
2888*3d8817e4Smiod       break;
2889*3d8817e4Smiod 
2890*3d8817e4Smiod     default:
2891*3d8817e4Smiod       return 0;
2892*3d8817e4Smiod     }
2893*3d8817e4Smiod 
2894*3d8817e4Smiod   return 1;
2895*3d8817e4Smiod }
2896*3d8817e4Smiod 
2897*3d8817e4Smiod void
md_show_usage(stream)2898*3d8817e4Smiod md_show_usage (stream)
2899*3d8817e4Smiod      FILE *stream;
2900*3d8817e4Smiod {
2901*3d8817e4Smiod   fprintf (stream,
2902*3d8817e4Smiod       _("\nTIC4X options:\n"
2903*3d8817e4Smiod 	"  -mcpu=CPU  -mCPU        select architecture variant. CPU can be:\n"
2904*3d8817e4Smiod 	"                            30 - TMS320C30\n"
2905*3d8817e4Smiod 	"                            31 - TMS320C31, TMS320LC31\n"
2906*3d8817e4Smiod 	"                            32 - TMS320C32\n"
2907*3d8817e4Smiod         "                            33 - TMS320VC33\n"
2908*3d8817e4Smiod 	"                            40 - TMS320C40\n"
2909*3d8817e4Smiod 	"                            44 - TMS320C44\n"
2910*3d8817e4Smiod         "  -mrev=REV               set cpu hardware revision (integer numbers).\n"
2911*3d8817e4Smiod         "                          Combinations of -mcpu and -mrev will enable/disable\n"
2912*3d8817e4Smiod         "                          the appropriate options (-midle2, -mlowpower and\n"
2913*3d8817e4Smiod         "                          -menhanced) according to the selected type\n"
2914*3d8817e4Smiod         "  -mbig                   select big memory model\n"
2915*3d8817e4Smiod         "  -msmall                 select small memory model (default)\n"
2916*3d8817e4Smiod         "  -mregparm               select register parameters (default)\n"
2917*3d8817e4Smiod         "  -mmemparm               select memory parameters\n"
2918*3d8817e4Smiod         "  -midle2                 enable IDLE2 support\n"
2919*3d8817e4Smiod         "  -mlowpower              enable LOPOWER and MAXSPEED support\n"
2920*3d8817e4Smiod         "  -menhanced              enable enhanced opcode support\n"));
2921*3d8817e4Smiod }
2922*3d8817e4Smiod 
2923*3d8817e4Smiod /* This is called when a line is unrecognized.  This is used to handle
2924*3d8817e4Smiod    definitions of TI C3x tools style local labels $n where n is a single
2925*3d8817e4Smiod    decimal digit.  */
2926*3d8817e4Smiod int
tic4x_unrecognized_line(c)2927*3d8817e4Smiod tic4x_unrecognized_line (c)
2928*3d8817e4Smiod      int c;
2929*3d8817e4Smiod {
2930*3d8817e4Smiod   int lab;
2931*3d8817e4Smiod   char *s;
2932*3d8817e4Smiod 
2933*3d8817e4Smiod   if (c != '$' || ! ISDIGIT (input_line_pointer[0]))
2934*3d8817e4Smiod     return 0;
2935*3d8817e4Smiod 
2936*3d8817e4Smiod   s = input_line_pointer;
2937*3d8817e4Smiod 
2938*3d8817e4Smiod   /* Let's allow multiple digit local labels.  */
2939*3d8817e4Smiod   lab = 0;
2940*3d8817e4Smiod   while (ISDIGIT (*s))
2941*3d8817e4Smiod     {
2942*3d8817e4Smiod       lab = lab * 10 + *s - '0';
2943*3d8817e4Smiod       s++;
2944*3d8817e4Smiod     }
2945*3d8817e4Smiod 
2946*3d8817e4Smiod   if (dollar_label_defined (lab))
2947*3d8817e4Smiod     {
2948*3d8817e4Smiod       as_bad ("Label \"$%d\" redefined", lab);
2949*3d8817e4Smiod       return 0;
2950*3d8817e4Smiod     }
2951*3d8817e4Smiod 
2952*3d8817e4Smiod   define_dollar_label (lab);
2953*3d8817e4Smiod   colon (dollar_label_name (lab, 0));
2954*3d8817e4Smiod   input_line_pointer = s + 1;
2955*3d8817e4Smiod 
2956*3d8817e4Smiod   return 1;
2957*3d8817e4Smiod }
2958*3d8817e4Smiod 
2959*3d8817e4Smiod /* Handle local labels peculiar to us referred to in an expression.  */
2960*3d8817e4Smiod symbolS *
md_undefined_symbol(name)2961*3d8817e4Smiod md_undefined_symbol (name)
2962*3d8817e4Smiod      char *name;
2963*3d8817e4Smiod {
2964*3d8817e4Smiod   /* Look for local labels of the form $n.  */
2965*3d8817e4Smiod   if (name[0] == '$' && ISDIGIT (name[1]))
2966*3d8817e4Smiod     {
2967*3d8817e4Smiod       symbolS *symbolP;
2968*3d8817e4Smiod       char *s = name + 1;
2969*3d8817e4Smiod       int lab = 0;
2970*3d8817e4Smiod 
2971*3d8817e4Smiod       while (ISDIGIT ((unsigned char) *s))
2972*3d8817e4Smiod 	{
2973*3d8817e4Smiod 	  lab = lab * 10 + *s - '0';
2974*3d8817e4Smiod 	  s++;
2975*3d8817e4Smiod 	}
2976*3d8817e4Smiod       if (dollar_label_defined (lab))
2977*3d8817e4Smiod 	{
2978*3d8817e4Smiod 	  name = dollar_label_name (lab, 0);
2979*3d8817e4Smiod 	  symbolP = symbol_find (name);
2980*3d8817e4Smiod 	}
2981*3d8817e4Smiod       else
2982*3d8817e4Smiod 	{
2983*3d8817e4Smiod 	  name = dollar_label_name (lab, 1);
2984*3d8817e4Smiod 	  symbolP = symbol_find_or_make (name);
2985*3d8817e4Smiod 	}
2986*3d8817e4Smiod 
2987*3d8817e4Smiod       return symbolP;
2988*3d8817e4Smiod     }
2989*3d8817e4Smiod   return NULL;
2990*3d8817e4Smiod }
2991*3d8817e4Smiod 
2992*3d8817e4Smiod /* Parse an operand that is machine-specific.  */
2993*3d8817e4Smiod void
md_operand(expressionP)2994*3d8817e4Smiod md_operand (expressionP)
2995*3d8817e4Smiod      expressionS *expressionP ATTRIBUTE_UNUSED;
2996*3d8817e4Smiod {
2997*3d8817e4Smiod }
2998*3d8817e4Smiod 
2999*3d8817e4Smiod /* Round up a section size to the appropriate boundary---do we need this?  */
3000*3d8817e4Smiod valueT
md_section_align(segment,size)3001*3d8817e4Smiod md_section_align (segment, size)
3002*3d8817e4Smiod      segT segment ATTRIBUTE_UNUSED;
3003*3d8817e4Smiod      valueT size;
3004*3d8817e4Smiod {
3005*3d8817e4Smiod   return size;			/* Byte (i.e., 32-bit) alignment is fine?  */
3006*3d8817e4Smiod }
3007*3d8817e4Smiod 
3008*3d8817e4Smiod static int
tic4x_pc_offset(op)3009*3d8817e4Smiod tic4x_pc_offset (op)
3010*3d8817e4Smiod      unsigned int op;
3011*3d8817e4Smiod {
3012*3d8817e4Smiod   /* Determine the PC offset for a C[34]x instruction.
3013*3d8817e4Smiod      This could be simplified using some boolean algebra
3014*3d8817e4Smiod      but at the expense of readability.  */
3015*3d8817e4Smiod   switch (op >> 24)
3016*3d8817e4Smiod     {
3017*3d8817e4Smiod     case 0x60:			/* br */
3018*3d8817e4Smiod     case 0x62:			/* call  (C4x) */
3019*3d8817e4Smiod     case 0x64:			/* rptb  (C4x) */
3020*3d8817e4Smiod       return 1;
3021*3d8817e4Smiod     case 0x61:			/* brd */
3022*3d8817e4Smiod     case 0x63:			/* laj */
3023*3d8817e4Smiod     case 0x65:			/* rptbd (C4x) */
3024*3d8817e4Smiod       return 3;
3025*3d8817e4Smiod     case 0x66:			/* swi */
3026*3d8817e4Smiod     case 0x67:
3027*3d8817e4Smiod       return 0;
3028*3d8817e4Smiod     default:
3029*3d8817e4Smiod       break;
3030*3d8817e4Smiod     }
3031*3d8817e4Smiod 
3032*3d8817e4Smiod   switch ((op & 0xffe00000) >> 20)
3033*3d8817e4Smiod     {
3034*3d8817e4Smiod     case 0x6a0:		/* bB */
3035*3d8817e4Smiod     case 0x720:		/* callB */
3036*3d8817e4Smiod     case 0x740:		/* trapB */
3037*3d8817e4Smiod       return 1;
3038*3d8817e4Smiod 
3039*3d8817e4Smiod     case 0x6a2:		/* bBd */
3040*3d8817e4Smiod     case 0x6a6:		/* bBat */
3041*3d8817e4Smiod     case 0x6aa:		/* bBaf */
3042*3d8817e4Smiod     case 0x722:		/* lajB */
3043*3d8817e4Smiod     case 0x748:		/* latB */
3044*3d8817e4Smiod     case 0x798:		/* rptbd */
3045*3d8817e4Smiod       return 3;
3046*3d8817e4Smiod 
3047*3d8817e4Smiod     default:
3048*3d8817e4Smiod       break;
3049*3d8817e4Smiod     }
3050*3d8817e4Smiod 
3051*3d8817e4Smiod   switch ((op & 0xfe200000) >> 20)
3052*3d8817e4Smiod     {
3053*3d8817e4Smiod     case 0x6e0:		/* dbB */
3054*3d8817e4Smiod       return 1;
3055*3d8817e4Smiod 
3056*3d8817e4Smiod     case 0x6e2:		/* dbBd */
3057*3d8817e4Smiod       return 3;
3058*3d8817e4Smiod 
3059*3d8817e4Smiod     default:
3060*3d8817e4Smiod       break;
3061*3d8817e4Smiod     }
3062*3d8817e4Smiod 
3063*3d8817e4Smiod   return 0;
3064*3d8817e4Smiod }
3065*3d8817e4Smiod 
3066*3d8817e4Smiod /* Exactly what point is a PC-relative offset relative TO?
3067*3d8817e4Smiod    With the C3x we have the following:
3068*3d8817e4Smiod    DBcond,  Bcond   disp + PC + 1 => PC
3069*3d8817e4Smiod    DBcondD, BcondD  disp + PC + 3 => PC
3070*3d8817e4Smiod  */
3071*3d8817e4Smiod long
md_pcrel_from(fixP)3072*3d8817e4Smiod md_pcrel_from (fixP)
3073*3d8817e4Smiod      fixS *fixP;
3074*3d8817e4Smiod {
3075*3d8817e4Smiod   unsigned char *buf;
3076*3d8817e4Smiod   unsigned int op;
3077*3d8817e4Smiod 
3078*3d8817e4Smiod   buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
3079*3d8817e4Smiod   op = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
3080*3d8817e4Smiod 
3081*3d8817e4Smiod   return ((fixP->fx_where + fixP->fx_frag->fr_address) >> 2) +
3082*3d8817e4Smiod     tic4x_pc_offset (op);
3083*3d8817e4Smiod }
3084*3d8817e4Smiod 
3085*3d8817e4Smiod /* Fill the alignment area with NOP's on .text, unless fill-data
3086*3d8817e4Smiod    was specified. */
3087*3d8817e4Smiod int
tic4x_do_align(alignment,fill,len,max)3088*3d8817e4Smiod tic4x_do_align (alignment, fill, len, max)
3089*3d8817e4Smiod      int alignment ATTRIBUTE_UNUSED;
3090*3d8817e4Smiod      const char *fill ATTRIBUTE_UNUSED;
3091*3d8817e4Smiod      int len ATTRIBUTE_UNUSED;
3092*3d8817e4Smiod      int max ATTRIBUTE_UNUSED;
3093*3d8817e4Smiod {
3094*3d8817e4Smiod   unsigned long nop = TIC_NOP_OPCODE;
3095*3d8817e4Smiod 
3096*3d8817e4Smiod   /* Because we are talking lwords, not bytes, adjust alignment to do words */
3097*3d8817e4Smiod   alignment += 2;
3098*3d8817e4Smiod 
3099*3d8817e4Smiod   if (alignment != 0 && !need_pass_2)
3100*3d8817e4Smiod     {
3101*3d8817e4Smiod       if (fill == NULL)
3102*3d8817e4Smiod         {
3103*3d8817e4Smiod           /*if (subseg_text_p (now_seg))*/  /* FIXME: doesn't work for .text for some reason */
3104*3d8817e4Smiod           frag_align_pattern( alignment, (const char *)&nop, sizeof(nop), max);
3105*3d8817e4Smiod           return 1;
3106*3d8817e4Smiod           /*else
3107*3d8817e4Smiod             frag_align (alignment, 0, max);*/
3108*3d8817e4Smiod 	}
3109*3d8817e4Smiod       else if (len <= 1)
3110*3d8817e4Smiod 	frag_align (alignment, *fill, max);
3111*3d8817e4Smiod       else
3112*3d8817e4Smiod 	frag_align_pattern (alignment, fill, len, max);
3113*3d8817e4Smiod     }
3114*3d8817e4Smiod 
3115*3d8817e4Smiod   /* Return 1 to skip the default alignment function */
3116*3d8817e4Smiod   return 1;
3117*3d8817e4Smiod }
3118*3d8817e4Smiod 
3119*3d8817e4Smiod /* Look for and remove parallel instruction operator ||.  */
3120*3d8817e4Smiod void
tic4x_start_line()3121*3d8817e4Smiod tic4x_start_line ()
3122*3d8817e4Smiod {
3123*3d8817e4Smiod   char *s = input_line_pointer;
3124*3d8817e4Smiod 
3125*3d8817e4Smiod   SKIP_WHITESPACE ();
3126*3d8817e4Smiod 
3127*3d8817e4Smiod   /* If parallel instruction prefix found at start of line, skip it.  */
3128*3d8817e4Smiod   if (*input_line_pointer == '|' && input_line_pointer[1] == '|')
3129*3d8817e4Smiod     {
3130*3d8817e4Smiod       if (insn->in_use)
3131*3d8817e4Smiod 	{
3132*3d8817e4Smiod 	  insn->parallel = 1;
3133*3d8817e4Smiod 	  input_line_pointer ++;
3134*3d8817e4Smiod           *input_line_pointer = ' ';
3135*3d8817e4Smiod 	  /* So line counters get bumped.  */
3136*3d8817e4Smiod 	  input_line_pointer[-1] = '\n';
3137*3d8817e4Smiod 	}
3138*3d8817e4Smiod     }
3139*3d8817e4Smiod   else
3140*3d8817e4Smiod     {
3141*3d8817e4Smiod       /* Write out the previous insn here */
3142*3d8817e4Smiod       if (insn->in_use)
3143*3d8817e4Smiod 	md_assemble (NULL);
3144*3d8817e4Smiod       input_line_pointer = s;
3145*3d8817e4Smiod     }
3146*3d8817e4Smiod }
3147*3d8817e4Smiod 
3148*3d8817e4Smiod arelent *
tc_gen_reloc(seg,fixP)3149*3d8817e4Smiod tc_gen_reloc (seg, fixP)
3150*3d8817e4Smiod      asection *seg ATTRIBUTE_UNUSED;
3151*3d8817e4Smiod      fixS *fixP;
3152*3d8817e4Smiod {
3153*3d8817e4Smiod   arelent *reloc;
3154*3d8817e4Smiod 
3155*3d8817e4Smiod   reloc = (arelent *) xmalloc (sizeof (arelent));
3156*3d8817e4Smiod 
3157*3d8817e4Smiod   reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
3158*3d8817e4Smiod   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
3159*3d8817e4Smiod   reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
3160*3d8817e4Smiod   reloc->address /= OCTETS_PER_BYTE;
3161*3d8817e4Smiod   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
3162*3d8817e4Smiod   if (reloc->howto == (reloc_howto_type *) NULL)
3163*3d8817e4Smiod     {
3164*3d8817e4Smiod       as_bad_where (fixP->fx_file, fixP->fx_line,
3165*3d8817e4Smiod 		    "Reloc %d not supported by object file format",
3166*3d8817e4Smiod 		    (int) fixP->fx_r_type);
3167*3d8817e4Smiod       return NULL;
3168*3d8817e4Smiod     }
3169*3d8817e4Smiod 
3170*3d8817e4Smiod   if (fixP->fx_r_type == BFD_RELOC_HI16)
3171*3d8817e4Smiod     reloc->addend = fixP->fx_offset;
3172*3d8817e4Smiod   else
3173*3d8817e4Smiod     reloc->addend = fixP->fx_addnumber;
3174*3d8817e4Smiod 
3175*3d8817e4Smiod   return reloc;
3176*3d8817e4Smiod }
3177