1*56bb7041Schristos /* tc-bfin.c -- Assembler for the ADI Blackfin.
2*56bb7041Schristos    Copyright (C) 2005-2020 Free Software Foundation, Inc.
3*56bb7041Schristos 
4*56bb7041Schristos    This file is part of GAS, the GNU Assembler.
5*56bb7041Schristos 
6*56bb7041Schristos    GAS is free software; you can redistribute it and/or modify
7*56bb7041Schristos    it under the terms of the GNU General Public License as published by
8*56bb7041Schristos    the Free Software Foundation; either version 3, or (at your option)
9*56bb7041Schristos    any later version.
10*56bb7041Schristos 
11*56bb7041Schristos    GAS is distributed in the hope that it will be useful,
12*56bb7041Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*56bb7041Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*56bb7041Schristos    GNU General Public License for more details.
15*56bb7041Schristos 
16*56bb7041Schristos    You should have received a copy of the GNU General Public License
17*56bb7041Schristos    along with GAS; see the file COPYING.  If not, write to the Free
18*56bb7041Schristos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19*56bb7041Schristos    02110-1301, USA.  */
20*56bb7041Schristos 
21*56bb7041Schristos #include "as.h"
22*56bb7041Schristos #include "bfin-defs.h"
23*56bb7041Schristos #include "obstack.h"
24*56bb7041Schristos #include "safe-ctype.h"
25*56bb7041Schristos #ifdef OBJ_ELF
26*56bb7041Schristos #include "dwarf2dbg.h"
27*56bb7041Schristos #endif
28*56bb7041Schristos #include "elf/common.h"
29*56bb7041Schristos #include "elf/bfin.h"
30*56bb7041Schristos 
31*56bb7041Schristos extern int yyparse (void);
32*56bb7041Schristos struct yy_buffer_state;
33*56bb7041Schristos typedef struct yy_buffer_state *YY_BUFFER_STATE;
34*56bb7041Schristos extern YY_BUFFER_STATE yy_scan_string (const char *yy_str);
35*56bb7041Schristos extern void yy_delete_buffer (YY_BUFFER_STATE b);
36*56bb7041Schristos static parse_state parse (char *line);
37*56bb7041Schristos 
38*56bb7041Schristos /* Global variables. */
39*56bb7041Schristos struct bfin_insn *insn;
40*56bb7041Schristos int last_insn_size;
41*56bb7041Schristos 
42*56bb7041Schristos extern struct obstack mempool;
43*56bb7041Schristos FILE *errorf;
44*56bb7041Schristos 
45*56bb7041Schristos /* Flags to set in the elf header */
46*56bb7041Schristos #define DEFAULT_FLAGS 0
47*56bb7041Schristos 
48*56bb7041Schristos #ifdef OBJ_FDPIC_ELF
49*56bb7041Schristos # define DEFAULT_FDPIC EF_BFIN_FDPIC
50*56bb7041Schristos #else
51*56bb7041Schristos # define DEFAULT_FDPIC 0
52*56bb7041Schristos #endif
53*56bb7041Schristos 
54*56bb7041Schristos static flagword bfin_flags = DEFAULT_FLAGS | DEFAULT_FDPIC;
55*56bb7041Schristos static const char *bfin_pic_flag = DEFAULT_FDPIC ? "-mfdpic" : (const char *)0;
56*56bb7041Schristos 
57*56bb7041Schristos /* Blackfin specific function to handle FD-PIC pointer initializations.  */
58*56bb7041Schristos 
59*56bb7041Schristos static void
bfin_pic_ptr(int nbytes)60*56bb7041Schristos bfin_pic_ptr (int nbytes)
61*56bb7041Schristos {
62*56bb7041Schristos   expressionS exp;
63*56bb7041Schristos   char *p;
64*56bb7041Schristos 
65*56bb7041Schristos   if (nbytes != 4)
66*56bb7041Schristos     abort ();
67*56bb7041Schristos 
68*56bb7041Schristos #ifdef md_flush_pending_output
69*56bb7041Schristos   md_flush_pending_output ();
70*56bb7041Schristos #endif
71*56bb7041Schristos 
72*56bb7041Schristos   if (is_it_end_of_statement ())
73*56bb7041Schristos     {
74*56bb7041Schristos       demand_empty_rest_of_line ();
75*56bb7041Schristos       return;
76*56bb7041Schristos     }
77*56bb7041Schristos 
78*56bb7041Schristos #ifdef md_cons_align
79*56bb7041Schristos   md_cons_align (nbytes);
80*56bb7041Schristos #endif
81*56bb7041Schristos 
82*56bb7041Schristos   do
83*56bb7041Schristos     {
84*56bb7041Schristos       bfd_reloc_code_real_type reloc_type = BFD_RELOC_BFIN_FUNCDESC;
85*56bb7041Schristos 
86*56bb7041Schristos       if (strncasecmp (input_line_pointer, "funcdesc(", 9) == 0)
87*56bb7041Schristos 	{
88*56bb7041Schristos 	  input_line_pointer += 9;
89*56bb7041Schristos 	  expression (&exp);
90*56bb7041Schristos 	  if (*input_line_pointer == ')')
91*56bb7041Schristos 	    input_line_pointer++;
92*56bb7041Schristos 	  else
93*56bb7041Schristos 	    as_bad (_("missing ')'"));
94*56bb7041Schristos 	}
95*56bb7041Schristos       else
96*56bb7041Schristos 	error ("missing funcdesc in picptr");
97*56bb7041Schristos 
98*56bb7041Schristos       p = frag_more (4);
99*56bb7041Schristos       memset (p, 0, 4);
100*56bb7041Schristos       fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
101*56bb7041Schristos 		   reloc_type);
102*56bb7041Schristos     }
103*56bb7041Schristos   while (*input_line_pointer++ == ',');
104*56bb7041Schristos 
105*56bb7041Schristos   input_line_pointer--;			/* Put terminator back into stream. */
106*56bb7041Schristos   demand_empty_rest_of_line ();
107*56bb7041Schristos }
108*56bb7041Schristos 
109*56bb7041Schristos static void
bfin_s_bss(int ignore ATTRIBUTE_UNUSED)110*56bb7041Schristos bfin_s_bss (int ignore ATTRIBUTE_UNUSED)
111*56bb7041Schristos {
112*56bb7041Schristos   int temp;
113*56bb7041Schristos 
114*56bb7041Schristos   temp = get_absolute_expression ();
115*56bb7041Schristos   subseg_set (bss_section, (subsegT) temp);
116*56bb7041Schristos   demand_empty_rest_of_line ();
117*56bb7041Schristos }
118*56bb7041Schristos 
119*56bb7041Schristos const pseudo_typeS md_pseudo_table[] = {
120*56bb7041Schristos   {"align", s_align_bytes, 0},
121*56bb7041Schristos   {"byte2", cons, 2},
122*56bb7041Schristos   {"byte4", cons, 4},
123*56bb7041Schristos   {"picptr", bfin_pic_ptr, 4},
124*56bb7041Schristos   {"code", obj_elf_section, 0},
125*56bb7041Schristos   {"db", cons, 1},
126*56bb7041Schristos   {"dd", cons, 4},
127*56bb7041Schristos   {"dw", cons, 2},
128*56bb7041Schristos   {"p", s_ignore, 0},
129*56bb7041Schristos   {"pdata", s_ignore, 0},
130*56bb7041Schristos   {"var", s_ignore, 0},
131*56bb7041Schristos   {"bss", bfin_s_bss, 0},
132*56bb7041Schristos   {0, 0, 0}
133*56bb7041Schristos };
134*56bb7041Schristos 
135*56bb7041Schristos /* Characters that are used to denote comments and line separators. */
136*56bb7041Schristos const char comment_chars[] = "#";
137*56bb7041Schristos const char line_comment_chars[] = "#";
138*56bb7041Schristos const char line_separator_chars[] = ";";
139*56bb7041Schristos 
140*56bb7041Schristos /* Characters that can be used to separate the mantissa from the
141*56bb7041Schristos    exponent in floating point numbers. */
142*56bb7041Schristos const char EXP_CHARS[] = "eE";
143*56bb7041Schristos 
144*56bb7041Schristos /* Characters that mean this number is a floating point constant.
145*56bb7041Schristos    As in 0f12.456 or  0d1.2345e12.  */
146*56bb7041Schristos const char FLT_CHARS[] = "fFdDxX";
147*56bb7041Schristos 
148*56bb7041Schristos typedef enum bfin_cpu_type
149*56bb7041Schristos {
150*56bb7041Schristos   BFIN_CPU_UNKNOWN,
151*56bb7041Schristos   BFIN_CPU_BF504,
152*56bb7041Schristos   BFIN_CPU_BF506,
153*56bb7041Schristos   BFIN_CPU_BF512,
154*56bb7041Schristos   BFIN_CPU_BF514,
155*56bb7041Schristos   BFIN_CPU_BF516,
156*56bb7041Schristos   BFIN_CPU_BF518,
157*56bb7041Schristos   BFIN_CPU_BF522,
158*56bb7041Schristos   BFIN_CPU_BF523,
159*56bb7041Schristos   BFIN_CPU_BF524,
160*56bb7041Schristos   BFIN_CPU_BF525,
161*56bb7041Schristos   BFIN_CPU_BF526,
162*56bb7041Schristos   BFIN_CPU_BF527,
163*56bb7041Schristos   BFIN_CPU_BF531,
164*56bb7041Schristos   BFIN_CPU_BF532,
165*56bb7041Schristos   BFIN_CPU_BF533,
166*56bb7041Schristos   BFIN_CPU_BF534,
167*56bb7041Schristos   BFIN_CPU_BF536,
168*56bb7041Schristos   BFIN_CPU_BF537,
169*56bb7041Schristos   BFIN_CPU_BF538,
170*56bb7041Schristos   BFIN_CPU_BF539,
171*56bb7041Schristos   BFIN_CPU_BF542,
172*56bb7041Schristos   BFIN_CPU_BF542M,
173*56bb7041Schristos   BFIN_CPU_BF544,
174*56bb7041Schristos   BFIN_CPU_BF544M,
175*56bb7041Schristos   BFIN_CPU_BF547,
176*56bb7041Schristos   BFIN_CPU_BF547M,
177*56bb7041Schristos   BFIN_CPU_BF548,
178*56bb7041Schristos   BFIN_CPU_BF548M,
179*56bb7041Schristos   BFIN_CPU_BF549,
180*56bb7041Schristos   BFIN_CPU_BF549M,
181*56bb7041Schristos   BFIN_CPU_BF561,
182*56bb7041Schristos   BFIN_CPU_BF592,
183*56bb7041Schristos } bfin_cpu_t;
184*56bb7041Schristos 
185*56bb7041Schristos bfin_cpu_t bfin_cpu_type = BFIN_CPU_UNKNOWN;
186*56bb7041Schristos /* -msi-revision support. There are three special values:
187*56bb7041Schristos    -1      -msi-revision=none.
188*56bb7041Schristos    0xffff  -msi-revision=any.  */
189*56bb7041Schristos int bfin_si_revision;
190*56bb7041Schristos 
191*56bb7041Schristos unsigned int bfin_anomaly_checks = 0;
192*56bb7041Schristos 
193*56bb7041Schristos struct bfin_cpu
194*56bb7041Schristos {
195*56bb7041Schristos   const char *name;
196*56bb7041Schristos   bfin_cpu_t type;
197*56bb7041Schristos   int si_revision;
198*56bb7041Schristos   unsigned int anomaly_checks;
199*56bb7041Schristos };
200*56bb7041Schristos 
201*56bb7041Schristos struct bfin_cpu bfin_cpus[] =
202*56bb7041Schristos {
203*56bb7041Schristos   {"bf504", BFIN_CPU_BF504, 0x0000, AC_05000074},
204*56bb7041Schristos 
205*56bb7041Schristos   {"bf506", BFIN_CPU_BF506, 0x0000, AC_05000074},
206*56bb7041Schristos 
207*56bb7041Schristos   {"bf512", BFIN_CPU_BF512, 0x0002, AC_05000074},
208*56bb7041Schristos   {"bf512", BFIN_CPU_BF512, 0x0001, AC_05000074},
209*56bb7041Schristos   {"bf512", BFIN_CPU_BF512, 0x0000, AC_05000074},
210*56bb7041Schristos 
211*56bb7041Schristos   {"bf514", BFIN_CPU_BF514, 0x0002, AC_05000074},
212*56bb7041Schristos   {"bf514", BFIN_CPU_BF514, 0x0001, AC_05000074},
213*56bb7041Schristos   {"bf514", BFIN_CPU_BF514, 0x0000, AC_05000074},
214*56bb7041Schristos 
215*56bb7041Schristos   {"bf516", BFIN_CPU_BF516, 0x0002, AC_05000074},
216*56bb7041Schristos   {"bf516", BFIN_CPU_BF516, 0x0001, AC_05000074},
217*56bb7041Schristos   {"bf516", BFIN_CPU_BF516, 0x0000, AC_05000074},
218*56bb7041Schristos 
219*56bb7041Schristos   {"bf518", BFIN_CPU_BF518, 0x0002, AC_05000074},
220*56bb7041Schristos   {"bf518", BFIN_CPU_BF518, 0x0001, AC_05000074},
221*56bb7041Schristos   {"bf518", BFIN_CPU_BF518, 0x0000, AC_05000074},
222*56bb7041Schristos 
223*56bb7041Schristos   {"bf522", BFIN_CPU_BF522, 0x0002, AC_05000074},
224*56bb7041Schristos   {"bf522", BFIN_CPU_BF522, 0x0001, AC_05000074},
225*56bb7041Schristos   {"bf522", BFIN_CPU_BF522, 0x0000, AC_05000074},
226*56bb7041Schristos 
227*56bb7041Schristos   {"bf523", BFIN_CPU_BF523, 0x0002, AC_05000074},
228*56bb7041Schristos   {"bf523", BFIN_CPU_BF523, 0x0001, AC_05000074},
229*56bb7041Schristos   {"bf523", BFIN_CPU_BF523, 0x0000, AC_05000074},
230*56bb7041Schristos 
231*56bb7041Schristos   {"bf524", BFIN_CPU_BF524, 0x0002, AC_05000074},
232*56bb7041Schristos   {"bf524", BFIN_CPU_BF524, 0x0001, AC_05000074},
233*56bb7041Schristos   {"bf524", BFIN_CPU_BF524, 0x0000, AC_05000074},
234*56bb7041Schristos 
235*56bb7041Schristos   {"bf525", BFIN_CPU_BF525, 0x0002, AC_05000074},
236*56bb7041Schristos   {"bf525", BFIN_CPU_BF525, 0x0001, AC_05000074},
237*56bb7041Schristos   {"bf525", BFIN_CPU_BF525, 0x0000, AC_05000074},
238*56bb7041Schristos 
239*56bb7041Schristos   {"bf526", BFIN_CPU_BF526, 0x0002, AC_05000074},
240*56bb7041Schristos   {"bf526", BFIN_CPU_BF526, 0x0001, AC_05000074},
241*56bb7041Schristos   {"bf526", BFIN_CPU_BF526, 0x0000, AC_05000074},
242*56bb7041Schristos 
243*56bb7041Schristos   {"bf527", BFIN_CPU_BF527, 0x0002, AC_05000074},
244*56bb7041Schristos   {"bf527", BFIN_CPU_BF527, 0x0001, AC_05000074},
245*56bb7041Schristos   {"bf527", BFIN_CPU_BF527, 0x0000, AC_05000074},
246*56bb7041Schristos 
247*56bb7041Schristos   {"bf531", BFIN_CPU_BF531, 0x0006, AC_05000074},
248*56bb7041Schristos   {"bf531", BFIN_CPU_BF531, 0x0005, AC_05000074},
249*56bb7041Schristos   {"bf531", BFIN_CPU_BF531, 0x0004, AC_05000074},
250*56bb7041Schristos   {"bf531", BFIN_CPU_BF531, 0x0003, AC_05000074},
251*56bb7041Schristos 
252*56bb7041Schristos   {"bf532", BFIN_CPU_BF532, 0x0006, AC_05000074},
253*56bb7041Schristos   {"bf532", BFIN_CPU_BF532, 0x0005, AC_05000074},
254*56bb7041Schristos   {"bf532", BFIN_CPU_BF532, 0x0004, AC_05000074},
255*56bb7041Schristos   {"bf532", BFIN_CPU_BF532, 0x0003, AC_05000074},
256*56bb7041Schristos 
257*56bb7041Schristos   {"bf533", BFIN_CPU_BF533, 0x0006, AC_05000074},
258*56bb7041Schristos   {"bf533", BFIN_CPU_BF533, 0x0005, AC_05000074},
259*56bb7041Schristos   {"bf533", BFIN_CPU_BF533, 0x0004, AC_05000074},
260*56bb7041Schristos   {"bf533", BFIN_CPU_BF533, 0x0003, AC_05000074},
261*56bb7041Schristos 
262*56bb7041Schristos   {"bf534", BFIN_CPU_BF534, 0x0003, AC_05000074},
263*56bb7041Schristos   {"bf534", BFIN_CPU_BF534, 0x0002, AC_05000074},
264*56bb7041Schristos   {"bf534", BFIN_CPU_BF534, 0x0001, AC_05000074},
265*56bb7041Schristos 
266*56bb7041Schristos   {"bf536", BFIN_CPU_BF536, 0x0003, AC_05000074},
267*56bb7041Schristos   {"bf536", BFIN_CPU_BF536, 0x0002, AC_05000074},
268*56bb7041Schristos   {"bf536", BFIN_CPU_BF536, 0x0001, AC_05000074},
269*56bb7041Schristos 
270*56bb7041Schristos   {"bf537", BFIN_CPU_BF537, 0x0003, AC_05000074},
271*56bb7041Schristos   {"bf537", BFIN_CPU_BF537, 0x0002, AC_05000074},
272*56bb7041Schristos   {"bf537", BFIN_CPU_BF537, 0x0001, AC_05000074},
273*56bb7041Schristos 
274*56bb7041Schristos   {"bf538", BFIN_CPU_BF538, 0x0005, AC_05000074},
275*56bb7041Schristos   {"bf538", BFIN_CPU_BF538, 0x0004, AC_05000074},
276*56bb7041Schristos   {"bf538", BFIN_CPU_BF538, 0x0003, AC_05000074},
277*56bb7041Schristos   {"bf538", BFIN_CPU_BF538, 0x0002, AC_05000074},
278*56bb7041Schristos 
279*56bb7041Schristos   {"bf539", BFIN_CPU_BF539, 0x0005, AC_05000074},
280*56bb7041Schristos   {"bf539", BFIN_CPU_BF539, 0x0004, AC_05000074},
281*56bb7041Schristos   {"bf539", BFIN_CPU_BF539, 0x0003, AC_05000074},
282*56bb7041Schristos   {"bf539", BFIN_CPU_BF539, 0x0002, AC_05000074},
283*56bb7041Schristos 
284*56bb7041Schristos   {"bf542m", BFIN_CPU_BF542M, 0x0003, AC_05000074},
285*56bb7041Schristos 
286*56bb7041Schristos   {"bf542", BFIN_CPU_BF542, 0x0004, AC_05000074},
287*56bb7041Schristos   {"bf542", BFIN_CPU_BF542, 0x0002, AC_05000074},
288*56bb7041Schristos   {"bf542", BFIN_CPU_BF542, 0x0001, AC_05000074},
289*56bb7041Schristos   {"bf542", BFIN_CPU_BF542, 0x0000, AC_05000074},
290*56bb7041Schristos 
291*56bb7041Schristos   {"bf544m", BFIN_CPU_BF544M, 0x0003, AC_05000074},
292*56bb7041Schristos 
293*56bb7041Schristos   {"bf544", BFIN_CPU_BF544, 0x0004, AC_05000074},
294*56bb7041Schristos   {"bf544", BFIN_CPU_BF544, 0x0002, AC_05000074},
295*56bb7041Schristos   {"bf544", BFIN_CPU_BF544, 0x0001, AC_05000074},
296*56bb7041Schristos   {"bf544", BFIN_CPU_BF544, 0x0000, AC_05000074},
297*56bb7041Schristos 
298*56bb7041Schristos   {"bf547m", BFIN_CPU_BF547M, 0x0003, AC_05000074},
299*56bb7041Schristos 
300*56bb7041Schristos   {"bf547", BFIN_CPU_BF547, 0x0004, AC_05000074},
301*56bb7041Schristos   {"bf547", BFIN_CPU_BF547, 0x0002, AC_05000074},
302*56bb7041Schristos   {"bf547", BFIN_CPU_BF547, 0x0001, AC_05000074},
303*56bb7041Schristos   {"bf547", BFIN_CPU_BF547, 0x0000, AC_05000074},
304*56bb7041Schristos 
305*56bb7041Schristos   {"bf548m", BFIN_CPU_BF548M, 0x0003, AC_05000074},
306*56bb7041Schristos 
307*56bb7041Schristos   {"bf548", BFIN_CPU_BF548, 0x0004, AC_05000074},
308*56bb7041Schristos   {"bf548", BFIN_CPU_BF548, 0x0002, AC_05000074},
309*56bb7041Schristos   {"bf548", BFIN_CPU_BF548, 0x0001, AC_05000074},
310*56bb7041Schristos   {"bf548", BFIN_CPU_BF548, 0x0000, AC_05000074},
311*56bb7041Schristos 
312*56bb7041Schristos   {"bf549m", BFIN_CPU_BF549M, 0x0003, AC_05000074},
313*56bb7041Schristos 
314*56bb7041Schristos   {"bf549", BFIN_CPU_BF549, 0x0004, AC_05000074},
315*56bb7041Schristos   {"bf549", BFIN_CPU_BF549, 0x0002, AC_05000074},
316*56bb7041Schristos   {"bf549", BFIN_CPU_BF549, 0x0001, AC_05000074},
317*56bb7041Schristos   {"bf549", BFIN_CPU_BF549, 0x0000, AC_05000074},
318*56bb7041Schristos 
319*56bb7041Schristos   {"bf561", BFIN_CPU_BF561, 0x0005, AC_05000074},
320*56bb7041Schristos   {"bf561", BFIN_CPU_BF561, 0x0003, AC_05000074},
321*56bb7041Schristos   {"bf561", BFIN_CPU_BF561, 0x0002, AC_05000074},
322*56bb7041Schristos 
323*56bb7041Schristos   {"bf592", BFIN_CPU_BF592, 0x0001, AC_05000074},
324*56bb7041Schristos   {"bf592", BFIN_CPU_BF592, 0x0000, AC_05000074},
325*56bb7041Schristos };
326*56bb7041Schristos 
327*56bb7041Schristos /* Define bfin-specific command-line options (there are none). */
328*56bb7041Schristos const char *md_shortopts = "";
329*56bb7041Schristos 
330*56bb7041Schristos #define OPTION_FDPIC		(OPTION_MD_BASE)
331*56bb7041Schristos #define OPTION_NOPIC		(OPTION_MD_BASE + 1)
332*56bb7041Schristos #define OPTION_MCPU		(OPTION_MD_BASE + 2)
333*56bb7041Schristos 
334*56bb7041Schristos struct option md_longopts[] =
335*56bb7041Schristos {
336*56bb7041Schristos   { "mcpu",		required_argument,	NULL, OPTION_MCPU	},
337*56bb7041Schristos   { "mfdpic",		no_argument,		NULL, OPTION_FDPIC      },
338*56bb7041Schristos   { "mnopic",		no_argument,		NULL, OPTION_NOPIC      },
339*56bb7041Schristos   { "mno-fdpic",	no_argument,		NULL, OPTION_NOPIC      },
340*56bb7041Schristos   { NULL,		no_argument,		NULL, 0                 },
341*56bb7041Schristos };
342*56bb7041Schristos 
343*56bb7041Schristos size_t md_longopts_size = sizeof (md_longopts);
344*56bb7041Schristos 
345*56bb7041Schristos 
346*56bb7041Schristos int
md_parse_option(int c ATTRIBUTE_UNUSED,const char * arg ATTRIBUTE_UNUSED)347*56bb7041Schristos md_parse_option (int c ATTRIBUTE_UNUSED, const char *arg ATTRIBUTE_UNUSED)
348*56bb7041Schristos {
349*56bb7041Schristos   switch (c)
350*56bb7041Schristos     {
351*56bb7041Schristos     default:
352*56bb7041Schristos       return 0;
353*56bb7041Schristos 
354*56bb7041Schristos     case OPTION_MCPU:
355*56bb7041Schristos       {
356*56bb7041Schristos 	const char *q;
357*56bb7041Schristos 	unsigned int i;
358*56bb7041Schristos 
359*56bb7041Schristos 	for (i = 0; i < ARRAY_SIZE (bfin_cpus); i++)
360*56bb7041Schristos 	  {
361*56bb7041Schristos 	    const char *p = bfin_cpus[i].name;
362*56bb7041Schristos 	    if (strncmp (arg, p, strlen (p)) == 0)
363*56bb7041Schristos 	      break;
364*56bb7041Schristos 	  }
365*56bb7041Schristos 
366*56bb7041Schristos 	if (i == ARRAY_SIZE (bfin_cpus))
367*56bb7041Schristos 	  as_fatal ("-mcpu=%s is not valid", arg);
368*56bb7041Schristos 
369*56bb7041Schristos 	bfin_cpu_type = bfin_cpus[i].type;
370*56bb7041Schristos 
371*56bb7041Schristos 	q = arg + strlen (bfin_cpus[i].name);
372*56bb7041Schristos 
373*56bb7041Schristos 	if (*q == '\0')
374*56bb7041Schristos 	  {
375*56bb7041Schristos 	    bfin_si_revision = bfin_cpus[i].si_revision;
376*56bb7041Schristos 	    bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
377*56bb7041Schristos 	  }
378*56bb7041Schristos 	else if (strcmp (q, "-none") == 0)
379*56bb7041Schristos 	  bfin_si_revision = -1;
380*56bb7041Schristos       	else if (strcmp (q, "-any") == 0)
381*56bb7041Schristos 	  {
382*56bb7041Schristos 	    bfin_si_revision = 0xffff;
383*56bb7041Schristos 	    while (i < ARRAY_SIZE (bfin_cpus)
384*56bb7041Schristos 		   && bfin_cpus[i].type == bfin_cpu_type)
385*56bb7041Schristos 	      {
386*56bb7041Schristos 		bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
387*56bb7041Schristos 		i++;
388*56bb7041Schristos 	      }
389*56bb7041Schristos 	  }
390*56bb7041Schristos 	else
391*56bb7041Schristos 	  {
392*56bb7041Schristos 	    unsigned int si_major, si_minor;
393*56bb7041Schristos 	    int rev_len, n;
394*56bb7041Schristos 
395*56bb7041Schristos 	    rev_len = strlen (q);
396*56bb7041Schristos 
397*56bb7041Schristos 	    if (sscanf (q, "-%u.%u%n", &si_major, &si_minor, &n) != 2
398*56bb7041Schristos 		|| n != rev_len
399*56bb7041Schristos 		|| si_major > 0xff || si_minor > 0xff)
400*56bb7041Schristos 	      {
401*56bb7041Schristos 	      invalid_silicon_revision:
402*56bb7041Schristos 		as_fatal ("-mcpu=%s has invalid silicon revision", arg);
403*56bb7041Schristos 	      }
404*56bb7041Schristos 
405*56bb7041Schristos 	    bfin_si_revision = (si_major << 8) | si_minor;
406*56bb7041Schristos 
407*56bb7041Schristos 	    while (i < ARRAY_SIZE (bfin_cpus)
408*56bb7041Schristos 		   && bfin_cpus[i].type == bfin_cpu_type
409*56bb7041Schristos 		   && bfin_cpus[i].si_revision != bfin_si_revision)
410*56bb7041Schristos 	      i++;
411*56bb7041Schristos 
412*56bb7041Schristos 	    if (i == ARRAY_SIZE (bfin_cpus)
413*56bb7041Schristos 	       	|| bfin_cpus[i].type != bfin_cpu_type)
414*56bb7041Schristos 	      goto invalid_silicon_revision;
415*56bb7041Schristos 
416*56bb7041Schristos 	    bfin_anomaly_checks |= bfin_cpus[i].anomaly_checks;
417*56bb7041Schristos 	  }
418*56bb7041Schristos 
419*56bb7041Schristos 	break;
420*56bb7041Schristos       }
421*56bb7041Schristos 
422*56bb7041Schristos     case OPTION_FDPIC:
423*56bb7041Schristos       bfin_flags |= EF_BFIN_FDPIC;
424*56bb7041Schristos       bfin_pic_flag = "-mfdpic";
425*56bb7041Schristos       break;
426*56bb7041Schristos 
427*56bb7041Schristos     case OPTION_NOPIC:
428*56bb7041Schristos       bfin_flags &= ~(EF_BFIN_FDPIC);
429*56bb7041Schristos       bfin_pic_flag = 0;
430*56bb7041Schristos       break;
431*56bb7041Schristos     }
432*56bb7041Schristos 
433*56bb7041Schristos   return 1;
434*56bb7041Schristos }
435*56bb7041Schristos 
436*56bb7041Schristos void
md_show_usage(FILE * stream)437*56bb7041Schristos md_show_usage (FILE * stream)
438*56bb7041Schristos {
439*56bb7041Schristos   fprintf (stream, _(" Blackfin specific assembler options:\n"));
440*56bb7041Schristos   fprintf (stream, _("  -mcpu=<cpu[-sirevision]> specify the name of the target CPU\n"));
441*56bb7041Schristos   fprintf (stream, _("  -mfdpic                  assemble for the FDPIC ABI\n"));
442*56bb7041Schristos   fprintf (stream, _("  -mno-fdpic/-mnopic       disable -mfdpic\n"));
443*56bb7041Schristos }
444*56bb7041Schristos 
445*56bb7041Schristos /* Perform machine-specific initializations.  */
446*56bb7041Schristos void
md_begin(void)447*56bb7041Schristos md_begin (void)
448*56bb7041Schristos {
449*56bb7041Schristos   /* Set the ELF flags if desired. */
450*56bb7041Schristos   if (bfin_flags)
451*56bb7041Schristos     bfd_set_private_flags (stdoutput, bfin_flags);
452*56bb7041Schristos 
453*56bb7041Schristos   /* Set the default machine type. */
454*56bb7041Schristos   if (!bfd_set_arch_mach (stdoutput, bfd_arch_bfin, 0))
455*56bb7041Schristos     as_warn (_("Could not set architecture and machine."));
456*56bb7041Schristos 
457*56bb7041Schristos   /* Ensure that lines can begin with '(', for multiple
458*56bb7041Schristos      register stack pops. */
459*56bb7041Schristos   lex_type ['('] = LEX_BEGIN_NAME;
460*56bb7041Schristos 
461*56bb7041Schristos #ifdef OBJ_ELF
462*56bb7041Schristos   record_alignment (text_section, 2);
463*56bb7041Schristos   record_alignment (data_section, 2);
464*56bb7041Schristos   record_alignment (bss_section, 2);
465*56bb7041Schristos #endif
466*56bb7041Schristos 
467*56bb7041Schristos   errorf = stderr;
468*56bb7041Schristos   obstack_init (&mempool);
469*56bb7041Schristos 
470*56bb7041Schristos #ifdef DEBUG
471*56bb7041Schristos   extern int debug_codeselection;
472*56bb7041Schristos   debug_codeselection = 1;
473*56bb7041Schristos #endif
474*56bb7041Schristos 
475*56bb7041Schristos   last_insn_size = 0;
476*56bb7041Schristos }
477*56bb7041Schristos 
478*56bb7041Schristos /* Perform the main parsing, and assembly of the input here.  Also,
479*56bb7041Schristos    call the required routines for alignment and fixups here.
480*56bb7041Schristos    This is called for every line that contains real assembly code.  */
481*56bb7041Schristos 
482*56bb7041Schristos void
md_assemble(char * line)483*56bb7041Schristos md_assemble (char *line)
484*56bb7041Schristos {
485*56bb7041Schristos   char *toP = 0;
486*56bb7041Schristos   int size, insn_size;
487*56bb7041Schristos   struct bfin_insn *tmp_insn;
488*56bb7041Schristos   size_t len;
489*56bb7041Schristos   static size_t buffer_len = 0;
490*56bb7041Schristos   static char *current_inputline;
491*56bb7041Schristos   parse_state state;
492*56bb7041Schristos 
493*56bb7041Schristos   len = strlen (line);
494*56bb7041Schristos   if (len + 2 > buffer_len)
495*56bb7041Schristos     {
496*56bb7041Schristos       buffer_len = len + 40;
497*56bb7041Schristos       current_inputline = XRESIZEVEC (char, current_inputline, buffer_len);
498*56bb7041Schristos     }
499*56bb7041Schristos   memcpy (current_inputline, line, len);
500*56bb7041Schristos   current_inputline[len] = ';';
501*56bb7041Schristos   current_inputline[len + 1] = '\0';
502*56bb7041Schristos 
503*56bb7041Schristos   state = parse (current_inputline);
504*56bb7041Schristos   if (state == NO_INSN_GENERATED)
505*56bb7041Schristos     return;
506*56bb7041Schristos 
507*56bb7041Schristos   for (insn_size = 0, tmp_insn = insn; tmp_insn; tmp_insn = tmp_insn->next)
508*56bb7041Schristos     if (!tmp_insn->reloc || !tmp_insn->exp->symbol)
509*56bb7041Schristos       insn_size += 2;
510*56bb7041Schristos 
511*56bb7041Schristos   if (insn_size)
512*56bb7041Schristos     toP = frag_more (insn_size);
513*56bb7041Schristos 
514*56bb7041Schristos   last_insn_size = insn_size;
515*56bb7041Schristos 
516*56bb7041Schristos #ifdef DEBUG
517*56bb7041Schristos   printf ("INS:");
518*56bb7041Schristos #endif
519*56bb7041Schristos   while (insn)
520*56bb7041Schristos     {
521*56bb7041Schristos       if (insn->reloc && insn->exp->symbol)
522*56bb7041Schristos 	{
523*56bb7041Schristos 	  char *prev_toP = toP - 2;
524*56bb7041Schristos 	  switch (insn->reloc)
525*56bb7041Schristos 	    {
526*56bb7041Schristos 	    case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
527*56bb7041Schristos 	    case BFD_RELOC_24_PCREL:
528*56bb7041Schristos 	    case BFD_RELOC_BFIN_16_LOW:
529*56bb7041Schristos 	    case BFD_RELOC_BFIN_16_HIGH:
530*56bb7041Schristos 	      size = 4;
531*56bb7041Schristos 	      break;
532*56bb7041Schristos 	    default:
533*56bb7041Schristos 	      size = 2;
534*56bb7041Schristos 	    }
535*56bb7041Schristos 
536*56bb7041Schristos 	  /* Following if condition checks for the arithmetic relocations.
537*56bb7041Schristos 	     If the case then it doesn't required to generate the code.
538*56bb7041Schristos 	     It has been assumed that, their ID will be contiguous.  */
539*56bb7041Schristos 	  if ((BFD_ARELOC_BFIN_PUSH <= insn->reloc
540*56bb7041Schristos                && BFD_ARELOC_BFIN_COMP >= insn->reloc)
541*56bb7041Schristos               || insn->reloc == BFD_RELOC_BFIN_16_IMM)
542*56bb7041Schristos 	    {
543*56bb7041Schristos 	      size = 2;
544*56bb7041Schristos 	    }
545*56bb7041Schristos 	  if (insn->reloc == BFD_ARELOC_BFIN_CONST
546*56bb7041Schristos               || insn->reloc == BFD_ARELOC_BFIN_PUSH)
547*56bb7041Schristos 	    size = 4;
548*56bb7041Schristos 
549*56bb7041Schristos 	  fix_new (frag_now,
550*56bb7041Schristos                    (prev_toP - frag_now->fr_literal),
551*56bb7041Schristos 		   size, insn->exp->symbol, insn->exp->value,
552*56bb7041Schristos                    insn->pcrel, insn->reloc);
553*56bb7041Schristos 	}
554*56bb7041Schristos       else
555*56bb7041Schristos 	{
556*56bb7041Schristos 	  md_number_to_chars (toP, insn->value, 2);
557*56bb7041Schristos 	  toP += 2;
558*56bb7041Schristos 	}
559*56bb7041Schristos 
560*56bb7041Schristos #ifdef DEBUG
561*56bb7041Schristos       printf (" reloc :");
562*56bb7041Schristos       printf (" %02x%02x", ((unsigned char *) &insn->value)[0],
563*56bb7041Schristos               ((unsigned char *) &insn->value)[1]);
564*56bb7041Schristos       printf ("\n");
565*56bb7041Schristos #endif
566*56bb7041Schristos       insn = insn->next;
567*56bb7041Schristos     }
568*56bb7041Schristos #ifdef OBJ_ELF
569*56bb7041Schristos   dwarf2_emit_insn (insn_size);
570*56bb7041Schristos #endif
571*56bb7041Schristos 
572*56bb7041Schristos   while (*line++ != '\0')
573*56bb7041Schristos     if (*line == '\n')
574*56bb7041Schristos       bump_line_counters ();
575*56bb7041Schristos }
576*56bb7041Schristos 
577*56bb7041Schristos /* Parse one line of instructions, and generate opcode for it.
578*56bb7041Schristos    To parse the line, YACC and LEX are used, because the instruction set
579*56bb7041Schristos    syntax doesn't confirm to the AT&T assembly syntax.
580*56bb7041Schristos    To call a YACC & LEX generated parser, we must provide the input via
581*56bb7041Schristos    a FILE stream, otherwise stdin is used by default.  Below the input
582*56bb7041Schristos    to the function will be put into a temporary file, then the generated
583*56bb7041Schristos    parser uses the temporary file for parsing.  */
584*56bb7041Schristos 
585*56bb7041Schristos static parse_state
parse(char * line)586*56bb7041Schristos parse (char *line)
587*56bb7041Schristos {
588*56bb7041Schristos   parse_state state;
589*56bb7041Schristos   YY_BUFFER_STATE buffstate;
590*56bb7041Schristos 
591*56bb7041Schristos   buffstate = yy_scan_string (line);
592*56bb7041Schristos 
593*56bb7041Schristos   /* our lex requires setting the start state to keyword
594*56bb7041Schristos      every line as the first word may be a keyword.
595*56bb7041Schristos      Fixes a bug where we could not have keywords as labels.  */
596*56bb7041Schristos   set_start_state ();
597*56bb7041Schristos 
598*56bb7041Schristos   /* Call yyparse here.  */
599*56bb7041Schristos   state = yyparse ();
600*56bb7041Schristos   if (state == SEMANTIC_ERROR)
601*56bb7041Schristos     {
602*56bb7041Schristos       as_bad (_("Parse failed."));
603*56bb7041Schristos       insn = 0;
604*56bb7041Schristos     }
605*56bb7041Schristos 
606*56bb7041Schristos   yy_delete_buffer (buffstate);
607*56bb7041Schristos   return state;
608*56bb7041Schristos }
609*56bb7041Schristos 
610*56bb7041Schristos /* We need to handle various expressions properly.
611*56bb7041Schristos    Such as, [SP--] = 34, concerned by md_assemble().  */
612*56bb7041Schristos 
613*56bb7041Schristos void
md_operand(expressionS * expressionP)614*56bb7041Schristos md_operand (expressionS * expressionP)
615*56bb7041Schristos {
616*56bb7041Schristos   if (*input_line_pointer == '[')
617*56bb7041Schristos     {
618*56bb7041Schristos       as_tsktsk ("We found a '['!");
619*56bb7041Schristos       input_line_pointer++;
620*56bb7041Schristos       expression (expressionP);
621*56bb7041Schristos     }
622*56bb7041Schristos }
623*56bb7041Schristos 
624*56bb7041Schristos /* Handle undefined symbols. */
625*56bb7041Schristos symbolS *
md_undefined_symbol(char * name ATTRIBUTE_UNUSED)626*56bb7041Schristos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
627*56bb7041Schristos {
628*56bb7041Schristos   return (symbolS *) 0;
629*56bb7041Schristos }
630*56bb7041Schristos 
631*56bb7041Schristos int
md_estimate_size_before_relax(fragS * fragP ATTRIBUTE_UNUSED,segT segment ATTRIBUTE_UNUSED)632*56bb7041Schristos md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
633*56bb7041Schristos                                segT segment ATTRIBUTE_UNUSED)
634*56bb7041Schristos {
635*56bb7041Schristos   return 0;
636*56bb7041Schristos }
637*56bb7041Schristos 
638*56bb7041Schristos /* Convert from target byte order to host byte order.  */
639*56bb7041Schristos 
640*56bb7041Schristos static int
md_chars_to_number(char * val,int n)641*56bb7041Schristos md_chars_to_number (char *val, int n)
642*56bb7041Schristos {
643*56bb7041Schristos   int retval;
644*56bb7041Schristos 
645*56bb7041Schristos   for (retval = 0; n--;)
646*56bb7041Schristos     {
647*56bb7041Schristos       retval <<= 8;
648*56bb7041Schristos       retval |= val[n];
649*56bb7041Schristos     }
650*56bb7041Schristos   return retval;
651*56bb7041Schristos }
652*56bb7041Schristos 
653*56bb7041Schristos void
md_apply_fix(fixS * fixP,valueT * valueP,segT seg ATTRIBUTE_UNUSED)654*56bb7041Schristos md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
655*56bb7041Schristos {
656*56bb7041Schristos   char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
657*56bb7041Schristos 
658*56bb7041Schristos   long value = *valueP;
659*56bb7041Schristos   long newval;
660*56bb7041Schristos 
661*56bb7041Schristos   switch (fixP->fx_r_type)
662*56bb7041Schristos     {
663*56bb7041Schristos     case BFD_RELOC_BFIN_GOT:
664*56bb7041Schristos     case BFD_RELOC_BFIN_GOT17M4:
665*56bb7041Schristos     case BFD_RELOC_BFIN_FUNCDESC_GOT17M4:
666*56bb7041Schristos       fixP->fx_no_overflow = 1;
667*56bb7041Schristos       newval = md_chars_to_number (where, 2);
668*56bb7041Schristos       newval |= 0x0 & 0x7f;
669*56bb7041Schristos       md_number_to_chars (where, newval, 2);
670*56bb7041Schristos       break;
671*56bb7041Schristos 
672*56bb7041Schristos     case BFD_RELOC_BFIN_10_PCREL:
673*56bb7041Schristos       if (!value)
674*56bb7041Schristos 	break;
675*56bb7041Schristos       if (value < -1024 || value > 1022)
676*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line,
677*56bb7041Schristos                       _("pcrel too far BFD_RELOC_BFIN_10"));
678*56bb7041Schristos 
679*56bb7041Schristos       /* 11 bit offset even numbered, so we remove right bit.  */
680*56bb7041Schristos       value = value >> 1;
681*56bb7041Schristos       newval = md_chars_to_number (where, 2);
682*56bb7041Schristos       newval |= value & 0x03ff;
683*56bb7041Schristos       md_number_to_chars (where, newval, 2);
684*56bb7041Schristos       break;
685*56bb7041Schristos 
686*56bb7041Schristos     case BFD_RELOC_BFIN_12_PCREL_JUMP:
687*56bb7041Schristos     case BFD_RELOC_BFIN_12_PCREL_JUMP_S:
688*56bb7041Schristos     case BFD_RELOC_12_PCREL:
689*56bb7041Schristos       if (!value)
690*56bb7041Schristos 	break;
691*56bb7041Schristos 
692*56bb7041Schristos       if (value < -4096 || value > 4094)
693*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_12"));
694*56bb7041Schristos       /* 13 bit offset even numbered, so we remove right bit.  */
695*56bb7041Schristos       value = value >> 1;
696*56bb7041Schristos       newval = md_chars_to_number (where, 2);
697*56bb7041Schristos       newval |= value & 0xfff;
698*56bb7041Schristos       md_number_to_chars (where, newval, 2);
699*56bb7041Schristos       break;
700*56bb7041Schristos 
701*56bb7041Schristos     case BFD_RELOC_BFIN_16_LOW:
702*56bb7041Schristos     case BFD_RELOC_BFIN_16_HIGH:
703*56bb7041Schristos       fixP->fx_done = FALSE;
704*56bb7041Schristos       break;
705*56bb7041Schristos 
706*56bb7041Schristos     case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
707*56bb7041Schristos     case BFD_RELOC_BFIN_24_PCREL_CALL_X:
708*56bb7041Schristos     case BFD_RELOC_24_PCREL:
709*56bb7041Schristos       if (!value)
710*56bb7041Schristos 	break;
711*56bb7041Schristos 
712*56bb7041Schristos       if (value < -16777216 || value > 16777214)
713*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_24"));
714*56bb7041Schristos 
715*56bb7041Schristos       /* 25 bit offset even numbered, so we remove right bit.  */
716*56bb7041Schristos       value = value >> 1;
717*56bb7041Schristos       value++;
718*56bb7041Schristos 
719*56bb7041Schristos       md_number_to_chars (where - 2, value >> 16, 1);
720*56bb7041Schristos       md_number_to_chars (where, value, 1);
721*56bb7041Schristos       md_number_to_chars (where + 1, value >> 8, 1);
722*56bb7041Schristos       break;
723*56bb7041Schristos 
724*56bb7041Schristos     case BFD_RELOC_BFIN_5_PCREL:	/* LSETUP (a, b) : "a" */
725*56bb7041Schristos       if (!value)
726*56bb7041Schristos 	break;
727*56bb7041Schristos       if (value < 4 || value > 30)
728*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_5"));
729*56bb7041Schristos       value = value >> 1;
730*56bb7041Schristos       newval = md_chars_to_number (where, 1);
731*56bb7041Schristos       newval = (newval & 0xf0) | (value & 0xf);
732*56bb7041Schristos       md_number_to_chars (where, newval, 1);
733*56bb7041Schristos       break;
734*56bb7041Schristos 
735*56bb7041Schristos     case BFD_RELOC_BFIN_11_PCREL:	/* LSETUP (a, b) : "b" */
736*56bb7041Schristos       if (!value)
737*56bb7041Schristos 	break;
738*56bb7041Schristos       value += 2;
739*56bb7041Schristos       if (value < 4 || value > 2046)
740*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far BFD_RELOC_BFIN_11_PCREL"));
741*56bb7041Schristos       /* 11 bit unsigned even, so we remove right bit.  */
742*56bb7041Schristos       value = value >> 1;
743*56bb7041Schristos       newval = md_chars_to_number (where, 2);
744*56bb7041Schristos       newval |= value & 0x03ff;
745*56bb7041Schristos       md_number_to_chars (where, newval, 2);
746*56bb7041Schristos       break;
747*56bb7041Schristos 
748*56bb7041Schristos     case BFD_RELOC_8:
749*56bb7041Schristos       if (value < -0x80 || value >= 0x7f)
750*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("rel too far BFD_RELOC_8"));
751*56bb7041Schristos       md_number_to_chars (where, value, 1);
752*56bb7041Schristos       break;
753*56bb7041Schristos 
754*56bb7041Schristos     case BFD_RELOC_BFIN_16_IMM:
755*56bb7041Schristos     case BFD_RELOC_16:
756*56bb7041Schristos       if (value < -0x8000 || value >= 0x7fff)
757*56bb7041Schristos 	as_bad_where (fixP->fx_file, fixP->fx_line, _("rel too far BFD_RELOC_16"));
758*56bb7041Schristos       md_number_to_chars (where, value, 2);
759*56bb7041Schristos       break;
760*56bb7041Schristos 
761*56bb7041Schristos     case BFD_RELOC_32:
762*56bb7041Schristos       md_number_to_chars (where, value, 4);
763*56bb7041Schristos       break;
764*56bb7041Schristos 
765*56bb7041Schristos     case BFD_RELOC_BFIN_PLTPC:
766*56bb7041Schristos       md_number_to_chars (where, value, 2);
767*56bb7041Schristos       break;
768*56bb7041Schristos 
769*56bb7041Schristos     case BFD_RELOC_BFIN_FUNCDESC:
770*56bb7041Schristos     case BFD_RELOC_VTABLE_INHERIT:
771*56bb7041Schristos     case BFD_RELOC_VTABLE_ENTRY:
772*56bb7041Schristos       fixP->fx_done = FALSE;
773*56bb7041Schristos       break;
774*56bb7041Schristos 
775*56bb7041Schristos     default:
776*56bb7041Schristos       if ((BFD_ARELOC_BFIN_PUSH > fixP->fx_r_type) || (BFD_ARELOC_BFIN_COMP < fixP->fx_r_type))
777*56bb7041Schristos 	{
778*56bb7041Schristos 	  fprintf (stderr, "Relocation %d not handled in gas." " Contact support.\n", fixP->fx_r_type);
779*56bb7041Schristos 	  return;
780*56bb7041Schristos 	}
781*56bb7041Schristos     }
782*56bb7041Schristos 
783*56bb7041Schristos   if (!fixP->fx_addsy)
784*56bb7041Schristos     fixP->fx_done = TRUE;
785*56bb7041Schristos 
786*56bb7041Schristos }
787*56bb7041Schristos 
788*56bb7041Schristos /* Round up a section size to the appropriate boundary.  */
789*56bb7041Schristos valueT
md_section_align(segT segment,valueT size)790*56bb7041Schristos md_section_align (segT segment, valueT size)
791*56bb7041Schristos {
792*56bb7041Schristos   int boundary = bfd_section_alignment (segment);
793*56bb7041Schristos   return ((size + (1 << boundary) - 1) & -(1 << boundary));
794*56bb7041Schristos }
795*56bb7041Schristos 
796*56bb7041Schristos 
797*56bb7041Schristos const char *
md_atof(int type,char * litP,int * sizeP)798*56bb7041Schristos md_atof (int type, char * litP, int * sizeP)
799*56bb7041Schristos {
800*56bb7041Schristos   return ieee_md_atof (type, litP, sizeP, FALSE);
801*56bb7041Schristos }
802*56bb7041Schristos 
803*56bb7041Schristos 
804*56bb7041Schristos /* If while processing a fixup, a reloc really needs to be created
805*56bb7041Schristos    then it is done here.  */
806*56bb7041Schristos 
807*56bb7041Schristos arelent *
tc_gen_reloc(asection * seg ATTRIBUTE_UNUSED,fixS * fixp)808*56bb7041Schristos tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
809*56bb7041Schristos {
810*56bb7041Schristos   arelent *reloc;
811*56bb7041Schristos 
812*56bb7041Schristos   reloc		      = XNEW (arelent);
813*56bb7041Schristos   reloc->sym_ptr_ptr  = XNEW (asymbol *);
814*56bb7041Schristos   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
815*56bb7041Schristos   reloc->address      = fixp->fx_frag->fr_address + fixp->fx_where;
816*56bb7041Schristos 
817*56bb7041Schristos   reloc->addend = fixp->fx_offset;
818*56bb7041Schristos   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
819*56bb7041Schristos 
820*56bb7041Schristos   if (reloc->howto == (reloc_howto_type *) NULL)
821*56bb7041Schristos     {
822*56bb7041Schristos       as_bad_where (fixp->fx_file, fixp->fx_line,
823*56bb7041Schristos 		    /* xgettext:c-format.  */
824*56bb7041Schristos 		    _("reloc %d not supported by object file format"),
825*56bb7041Schristos 		    (int) fixp->fx_r_type);
826*56bb7041Schristos 
827*56bb7041Schristos       xfree (reloc);
828*56bb7041Schristos 
829*56bb7041Schristos       return NULL;
830*56bb7041Schristos     }
831*56bb7041Schristos 
832*56bb7041Schristos   return reloc;
833*56bb7041Schristos }
834*56bb7041Schristos 
835*56bb7041Schristos /*  The location from which a PC relative jump should be calculated,
836*56bb7041Schristos     given a PC relative reloc.  */
837*56bb7041Schristos 
838*56bb7041Schristos long
md_pcrel_from_section(fixS * fixP,segT sec)839*56bb7041Schristos md_pcrel_from_section (fixS *fixP, segT sec)
840*56bb7041Schristos {
841*56bb7041Schristos   if (fixP->fx_addsy != (symbolS *) NULL
842*56bb7041Schristos       && (!S_IS_DEFINED (fixP->fx_addsy)
843*56bb7041Schristos       || S_GET_SEGMENT (fixP->fx_addsy) != sec))
844*56bb7041Schristos     {
845*56bb7041Schristos       /* The symbol is undefined (or is defined but not in this section).
846*56bb7041Schristos          Let the linker figure it out.  */
847*56bb7041Schristos       return 0;
848*56bb7041Schristos     }
849*56bb7041Schristos   return fixP->fx_frag->fr_address + fixP->fx_where;
850*56bb7041Schristos }
851*56bb7041Schristos 
852*56bb7041Schristos /* Return true if the fix can be handled by GAS, false if it must
853*56bb7041Schristos    be passed through to the linker.  */
854*56bb7041Schristos 
855*56bb7041Schristos bfd_boolean
bfin_fix_adjustable(fixS * fixP)856*56bb7041Schristos bfin_fix_adjustable (fixS *fixP)
857*56bb7041Schristos {
858*56bb7041Schristos   switch (fixP->fx_r_type)
859*56bb7041Schristos     {
860*56bb7041Schristos   /* Adjust_reloc_syms doesn't know about the GOT.  */
861*56bb7041Schristos     case BFD_RELOC_BFIN_GOT:
862*56bb7041Schristos     case BFD_RELOC_BFIN_PLTPC:
863*56bb7041Schristos   /* We need the symbol name for the VTABLE entries.  */
864*56bb7041Schristos     case BFD_RELOC_VTABLE_INHERIT:
865*56bb7041Schristos     case BFD_RELOC_VTABLE_ENTRY:
866*56bb7041Schristos       return 0;
867*56bb7041Schristos 
868*56bb7041Schristos     default:
869*56bb7041Schristos       return 1;
870*56bb7041Schristos     }
871*56bb7041Schristos }
872*56bb7041Schristos 
873*56bb7041Schristos /* Special extra functions that help bfin-parse.y perform its job.  */
874*56bb7041Schristos 
875*56bb7041Schristos struct obstack mempool;
876*56bb7041Schristos 
877*56bb7041Schristos INSTR_T
conscode(INSTR_T head,INSTR_T tail)878*56bb7041Schristos conscode (INSTR_T head, INSTR_T tail)
879*56bb7041Schristos {
880*56bb7041Schristos   if (!head)
881*56bb7041Schristos     return tail;
882*56bb7041Schristos   head->next = tail;
883*56bb7041Schristos   return head;
884*56bb7041Schristos }
885*56bb7041Schristos 
886*56bb7041Schristos INSTR_T
conctcode(INSTR_T head,INSTR_T tail)887*56bb7041Schristos conctcode (INSTR_T head, INSTR_T tail)
888*56bb7041Schristos {
889*56bb7041Schristos   INSTR_T temp = (head);
890*56bb7041Schristos   if (!head)
891*56bb7041Schristos     return tail;
892*56bb7041Schristos   while (temp->next)
893*56bb7041Schristos     temp = temp->next;
894*56bb7041Schristos   temp->next = tail;
895*56bb7041Schristos 
896*56bb7041Schristos   return head;
897*56bb7041Schristos }
898*56bb7041Schristos 
899*56bb7041Schristos INSTR_T
note_reloc(INSTR_T code,Expr_Node * symbol,int reloc,int pcrel)900*56bb7041Schristos note_reloc (INSTR_T code, Expr_Node * symbol, int reloc, int pcrel)
901*56bb7041Schristos {
902*56bb7041Schristos   /* Assert that the symbol is not an operator.  */
903*56bb7041Schristos   gas_assert (symbol->type == Expr_Node_Reloc);
904*56bb7041Schristos 
905*56bb7041Schristos   return note_reloc1 (code, symbol->value.s_value, reloc, pcrel);
906*56bb7041Schristos 
907*56bb7041Schristos }
908*56bb7041Schristos 
909*56bb7041Schristos INSTR_T
note_reloc1(INSTR_T code,const char * symbol,int reloc,int pcrel)910*56bb7041Schristos note_reloc1 (INSTR_T code, const char *symbol, int reloc, int pcrel)
911*56bb7041Schristos {
912*56bb7041Schristos   code->reloc = reloc;
913*56bb7041Schristos   code->exp = mkexpr (0, symbol_find_or_make (symbol));
914*56bb7041Schristos   code->pcrel = pcrel;
915*56bb7041Schristos   return code;
916*56bb7041Schristos }
917*56bb7041Schristos 
918*56bb7041Schristos INSTR_T
note_reloc2(INSTR_T code,const char * symbol,int reloc,int value,int pcrel)919*56bb7041Schristos note_reloc2 (INSTR_T code, const char *symbol, int reloc, int value, int pcrel)
920*56bb7041Schristos {
921*56bb7041Schristos   code->reloc = reloc;
922*56bb7041Schristos   code->exp = mkexpr (value, symbol_find_or_make (symbol));
923*56bb7041Schristos   code->pcrel = pcrel;
924*56bb7041Schristos   return code;
925*56bb7041Schristos }
926*56bb7041Schristos 
927*56bb7041Schristos INSTR_T
gencode(unsigned long x)928*56bb7041Schristos gencode (unsigned long x)
929*56bb7041Schristos {
930*56bb7041Schristos   INSTR_T cell = XOBNEW (&mempool, struct bfin_insn);
931*56bb7041Schristos   memset (cell, 0, sizeof (struct bfin_insn));
932*56bb7041Schristos   cell->value = (x);
933*56bb7041Schristos   return cell;
934*56bb7041Schristos }
935*56bb7041Schristos 
936*56bb7041Schristos int reloc;
937*56bb7041Schristos int ninsns;
938*56bb7041Schristos int count_insns;
939*56bb7041Schristos 
940*56bb7041Schristos static void *
allocate(size_t n)941*56bb7041Schristos allocate (size_t n)
942*56bb7041Schristos {
943*56bb7041Schristos   return obstack_alloc (&mempool, n);
944*56bb7041Schristos }
945*56bb7041Schristos 
946*56bb7041Schristos Expr_Node *
Expr_Node_Create(Expr_Node_Type type,Expr_Node_Value value,Expr_Node * Left_Child,Expr_Node * Right_Child)947*56bb7041Schristos Expr_Node_Create (Expr_Node_Type type,
948*56bb7041Schristos 	          Expr_Node_Value value,
949*56bb7041Schristos                   Expr_Node *Left_Child,
950*56bb7041Schristos                   Expr_Node *Right_Child)
951*56bb7041Schristos {
952*56bb7041Schristos 
953*56bb7041Schristos 
954*56bb7041Schristos   Expr_Node *node = (Expr_Node *) allocate (sizeof (Expr_Node));
955*56bb7041Schristos   node->type = type;
956*56bb7041Schristos   node->value = value;
957*56bb7041Schristos   node->Left_Child = Left_Child;
958*56bb7041Schristos   node->Right_Child = Right_Child;
959*56bb7041Schristos   return node;
960*56bb7041Schristos }
961*56bb7041Schristos 
962*56bb7041Schristos static const char *con = ".__constant";
963*56bb7041Schristos static const char *op = ".__operator";
964*56bb7041Schristos static INSTR_T Expr_Node_Gen_Reloc_R (Expr_Node * head);
965*56bb7041Schristos INSTR_T Expr_Node_Gen_Reloc (Expr_Node *head, int parent_reloc);
966*56bb7041Schristos 
967*56bb7041Schristos INSTR_T
Expr_Node_Gen_Reloc(Expr_Node * head,int parent_reloc)968*56bb7041Schristos Expr_Node_Gen_Reloc (Expr_Node * head, int parent_reloc)
969*56bb7041Schristos {
970*56bb7041Schristos   /* Top level relocation expression generator VDSP style.
971*56bb7041Schristos    If the relocation is just by itself, generate one item
972*56bb7041Schristos    else generate this convoluted expression.  */
973*56bb7041Schristos 
974*56bb7041Schristos   INSTR_T note = NULL_CODE;
975*56bb7041Schristos   INSTR_T note1 = NULL_CODE;
976*56bb7041Schristos   int pcrel = 1;  /* Is the parent reloc pc-relative?
977*56bb7041Schristos 		  This calculation here and HOWTO should match.  */
978*56bb7041Schristos 
979*56bb7041Schristos   if (parent_reloc)
980*56bb7041Schristos     {
981*56bb7041Schristos       /*  If it's 32 bit quantity then 16bit code needs to be added.  */
982*56bb7041Schristos       int value = 0;
983*56bb7041Schristos 
984*56bb7041Schristos       if (head->type == Expr_Node_Constant)
985*56bb7041Schristos 	{
986*56bb7041Schristos 	  /* If note1 is not null code, we have to generate a right
987*56bb7041Schristos              aligned value for the constant. Otherwise the reloc is
988*56bb7041Schristos              a part of the basic command and the yacc file
989*56bb7041Schristos              generates this.  */
990*56bb7041Schristos 	  value = head->value.i_value;
991*56bb7041Schristos 	}
992*56bb7041Schristos       switch (parent_reloc)
993*56bb7041Schristos 	{
994*56bb7041Schristos 	  /*  Some relocations will need to allocate extra words.  */
995*56bb7041Schristos 	case BFD_RELOC_BFIN_16_IMM:
996*56bb7041Schristos 	case BFD_RELOC_BFIN_16_LOW:
997*56bb7041Schristos 	case BFD_RELOC_BFIN_16_HIGH:
998*56bb7041Schristos 	  note1 = conscode (gencode (value), NULL_CODE);
999*56bb7041Schristos 	  pcrel = 0;
1000*56bb7041Schristos 	  break;
1001*56bb7041Schristos 	case BFD_RELOC_BFIN_PLTPC:
1002*56bb7041Schristos 	  note1 = conscode (gencode (value), NULL_CODE);
1003*56bb7041Schristos 	  pcrel = 0;
1004*56bb7041Schristos 	  break;
1005*56bb7041Schristos 	case BFD_RELOC_16:
1006*56bb7041Schristos 	case BFD_RELOC_BFIN_GOT:
1007*56bb7041Schristos 	case BFD_RELOC_BFIN_GOT17M4:
1008*56bb7041Schristos 	case BFD_RELOC_BFIN_FUNCDESC_GOT17M4:
1009*56bb7041Schristos 	  note1 = conscode (gencode (value), NULL_CODE);
1010*56bb7041Schristos 	  pcrel = 0;
1011*56bb7041Schristos 	  break;
1012*56bb7041Schristos 	case BFD_RELOC_24_PCREL:
1013*56bb7041Schristos 	case BFD_RELOC_BFIN_24_PCREL_JUMP_L:
1014*56bb7041Schristos 	case BFD_RELOC_BFIN_24_PCREL_CALL_X:
1015*56bb7041Schristos 	  /* These offsets are even numbered pcrel.  */
1016*56bb7041Schristos 	  note1 = conscode (gencode (value >> 1), NULL_CODE);
1017*56bb7041Schristos 	  break;
1018*56bb7041Schristos 	default:
1019*56bb7041Schristos 	  note1 = NULL_CODE;
1020*56bb7041Schristos 	}
1021*56bb7041Schristos     }
1022*56bb7041Schristos   if (head->type == Expr_Node_Constant)
1023*56bb7041Schristos     note = note1;
1024*56bb7041Schristos   else if (head->type == Expr_Node_Reloc)
1025*56bb7041Schristos     {
1026*56bb7041Schristos       note = note_reloc1 (gencode (0), head->value.s_value, parent_reloc, pcrel);
1027*56bb7041Schristos       if (note1 != NULL_CODE)
1028*56bb7041Schristos 	note = conscode (note1, note);
1029*56bb7041Schristos     }
1030*56bb7041Schristos   else if (head->type == Expr_Node_Binop
1031*56bb7041Schristos 	   && (head->value.op_value == Expr_Op_Type_Add
1032*56bb7041Schristos 	       || head->value.op_value == Expr_Op_Type_Sub)
1033*56bb7041Schristos 	   && head->Left_Child->type == Expr_Node_Reloc
1034*56bb7041Schristos 	   && head->Right_Child->type == Expr_Node_Constant)
1035*56bb7041Schristos     {
1036*56bb7041Schristos       int val = head->Right_Child->value.i_value;
1037*56bb7041Schristos       if (head->value.op_value == Expr_Op_Type_Sub)
1038*56bb7041Schristos 	val = -val;
1039*56bb7041Schristos       note = conscode (note_reloc2 (gencode (0), head->Left_Child->value.s_value,
1040*56bb7041Schristos 				    parent_reloc, val, 0),
1041*56bb7041Schristos 		       NULL_CODE);
1042*56bb7041Schristos       if (note1 != NULL_CODE)
1043*56bb7041Schristos 	note = conscode (note1, note);
1044*56bb7041Schristos     }
1045*56bb7041Schristos   else
1046*56bb7041Schristos     {
1047*56bb7041Schristos       /* Call the recursive function.  */
1048*56bb7041Schristos       note = note_reloc1 (gencode (0), op, parent_reloc, pcrel);
1049*56bb7041Schristos       if (note1 != NULL_CODE)
1050*56bb7041Schristos 	note = conscode (note1, note);
1051*56bb7041Schristos       note = conctcode (Expr_Node_Gen_Reloc_R (head), note);
1052*56bb7041Schristos     }
1053*56bb7041Schristos   return note;
1054*56bb7041Schristos }
1055*56bb7041Schristos 
1056*56bb7041Schristos static INSTR_T
Expr_Node_Gen_Reloc_R(Expr_Node * head)1057*56bb7041Schristos Expr_Node_Gen_Reloc_R (Expr_Node * head)
1058*56bb7041Schristos {
1059*56bb7041Schristos 
1060*56bb7041Schristos   INSTR_T note = 0;
1061*56bb7041Schristos   INSTR_T note1 = 0;
1062*56bb7041Schristos 
1063*56bb7041Schristos   switch (head->type)
1064*56bb7041Schristos     {
1065*56bb7041Schristos     case Expr_Node_Constant:
1066*56bb7041Schristos       note = conscode (note_reloc2 (gencode (0), con, BFD_ARELOC_BFIN_CONST, head->value.i_value, 0), NULL_CODE);
1067*56bb7041Schristos       break;
1068*56bb7041Schristos     case Expr_Node_Reloc:
1069*56bb7041Schristos       note = conscode (note_reloc (gencode (0), head, BFD_ARELOC_BFIN_PUSH, 0), NULL_CODE);
1070*56bb7041Schristos       break;
1071*56bb7041Schristos     case Expr_Node_Binop:
1072*56bb7041Schristos       note1 = conctcode (Expr_Node_Gen_Reloc_R (head->Left_Child), Expr_Node_Gen_Reloc_R (head->Right_Child));
1073*56bb7041Schristos       switch (head->value.op_value)
1074*56bb7041Schristos 	{
1075*56bb7041Schristos 	case Expr_Op_Type_Add:
1076*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_ADD, 0), NULL_CODE));
1077*56bb7041Schristos 	  break;
1078*56bb7041Schristos 	case Expr_Op_Type_Sub:
1079*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_SUB, 0), NULL_CODE));
1080*56bb7041Schristos 	  break;
1081*56bb7041Schristos 	case Expr_Op_Type_Mult:
1082*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_MULT, 0), NULL_CODE));
1083*56bb7041Schristos 	  break;
1084*56bb7041Schristos 	case Expr_Op_Type_Div:
1085*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_DIV, 0), NULL_CODE));
1086*56bb7041Schristos 	  break;
1087*56bb7041Schristos 	case Expr_Op_Type_Mod:
1088*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_MOD, 0), NULL_CODE));
1089*56bb7041Schristos 	  break;
1090*56bb7041Schristos 	case Expr_Op_Type_Lshift:
1091*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LSHIFT, 0), NULL_CODE));
1092*56bb7041Schristos 	  break;
1093*56bb7041Schristos 	case Expr_Op_Type_Rshift:
1094*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_RSHIFT, 0), NULL_CODE));
1095*56bb7041Schristos 	  break;
1096*56bb7041Schristos 	case Expr_Op_Type_BAND:
1097*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_AND, 0), NULL_CODE));
1098*56bb7041Schristos 	  break;
1099*56bb7041Schristos 	case Expr_Op_Type_BOR:
1100*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_OR, 0), NULL_CODE));
1101*56bb7041Schristos 	  break;
1102*56bb7041Schristos 	case Expr_Op_Type_BXOR:
1103*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_XOR, 0), NULL_CODE));
1104*56bb7041Schristos 	  break;
1105*56bb7041Schristos 	case Expr_Op_Type_LAND:
1106*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LAND, 0), NULL_CODE));
1107*56bb7041Schristos 	  break;
1108*56bb7041Schristos 	case Expr_Op_Type_LOR:
1109*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_LOR, 0), NULL_CODE));
1110*56bb7041Schristos 	  break;
1111*56bb7041Schristos 	default:
1112*56bb7041Schristos 	  fprintf (stderr, "%s:%d:Unknown operator found for arithmetic" " relocation", __FILE__, __LINE__);
1113*56bb7041Schristos 
1114*56bb7041Schristos 
1115*56bb7041Schristos 	}
1116*56bb7041Schristos       break;
1117*56bb7041Schristos     case Expr_Node_Unop:
1118*56bb7041Schristos       note1 = conscode (Expr_Node_Gen_Reloc_R (head->Left_Child), NULL_CODE);
1119*56bb7041Schristos       switch (head->value.op_value)
1120*56bb7041Schristos 	{
1121*56bb7041Schristos 	case Expr_Op_Type_NEG:
1122*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_NEG, 0), NULL_CODE));
1123*56bb7041Schristos 	  break;
1124*56bb7041Schristos 	case Expr_Op_Type_COMP:
1125*56bb7041Schristos 	  note = conctcode (note1, conscode (note_reloc1 (gencode (0), op, BFD_ARELOC_BFIN_COMP, 0), NULL_CODE));
1126*56bb7041Schristos 	  break;
1127*56bb7041Schristos 	default:
1128*56bb7041Schristos 	  fprintf (stderr, "%s:%d:Unknown operator found for arithmetic" " relocation", __FILE__, __LINE__);
1129*56bb7041Schristos 	}
1130*56bb7041Schristos       break;
1131*56bb7041Schristos     default:
1132*56bb7041Schristos       fprintf (stderr, "%s:%d:Unknown node expression found during " "arithmetic relocation generation", __FILE__, __LINE__);
1133*56bb7041Schristos     }
1134*56bb7041Schristos   return note;
1135*56bb7041Schristos }
1136*56bb7041Schristos 
1137*56bb7041Schristos /* Blackfin opcode generation.  */
1138*56bb7041Schristos 
1139*56bb7041Schristos /* These functions are called by the generated parser
1140*56bb7041Schristos    (from bfin-parse.y), the register type classification
1141*56bb7041Schristos    happens in bfin-lex.l.  */
1142*56bb7041Schristos 
1143*56bb7041Schristos #include "bfin-aux.h"
1144*56bb7041Schristos #include "opcode/bfin.h"
1145*56bb7041Schristos 
1146*56bb7041Schristos #define INIT(t)  t c_code = init_##t
1147*56bb7041Schristos #define ASSIGN(x) c_code.opcode |= ((x & c_code.mask_##x)<<c_code.bits_##x)
1148*56bb7041Schristos #define ASSIGNF(x,f) c_code.opcode |= ((x & c_code.mask_##f)<<c_code.bits_##f)
1149*56bb7041Schristos #define ASSIGN_R(x) c_code.opcode |= (((x ? (x->regno & CODE_MASK) : 0) & c_code.mask_##x)<<c_code.bits_##x)
1150*56bb7041Schristos 
1151*56bb7041Schristos #define HI(x) ((x >> 16) & 0xffff)
1152*56bb7041Schristos #define LO(x) ((x      ) & 0xffff)
1153*56bb7041Schristos 
1154*56bb7041Schristos #define GROUP(x) ((x->regno & CLASS_MASK) >> 4)
1155*56bb7041Schristos 
1156*56bb7041Schristos #define GEN_OPCODE32()  \
1157*56bb7041Schristos 	conscode (gencode (HI (c_code.opcode)), \
1158*56bb7041Schristos 	conscode (gencode (LO (c_code.opcode)), NULL_CODE))
1159*56bb7041Schristos 
1160*56bb7041Schristos #define GEN_OPCODE16()  \
1161*56bb7041Schristos 	conscode (gencode (c_code.opcode), NULL_CODE)
1162*56bb7041Schristos 
1163*56bb7041Schristos 
1164*56bb7041Schristos /*  32 BIT INSTRUCTIONS.  */
1165*56bb7041Schristos 
1166*56bb7041Schristos 
1167*56bb7041Schristos /* DSP32 instruction generation.  */
1168*56bb7041Schristos 
1169*56bb7041Schristos INSTR_T
bfin_gen_dsp32mac(int op1,int MM,int mmod,int w1,int P,int h01,int h11,int h00,int h10,int op0,REG_T dst,REG_T src0,REG_T src1,int w0)1170*56bb7041Schristos bfin_gen_dsp32mac (int op1, int MM, int mmod, int w1, int P,
1171*56bb7041Schristos 	           int h01, int h11, int h00, int h10, int op0,
1172*56bb7041Schristos                    REG_T dst, REG_T src0, REG_T src1, int w0)
1173*56bb7041Schristos {
1174*56bb7041Schristos   INIT (DSP32Mac);
1175*56bb7041Schristos 
1176*56bb7041Schristos   ASSIGN (op0);
1177*56bb7041Schristos   ASSIGN (op1);
1178*56bb7041Schristos   ASSIGN (MM);
1179*56bb7041Schristos   ASSIGN (mmod);
1180*56bb7041Schristos   ASSIGN (w0);
1181*56bb7041Schristos   ASSIGN (w1);
1182*56bb7041Schristos   ASSIGN (h01);
1183*56bb7041Schristos   ASSIGN (h11);
1184*56bb7041Schristos   ASSIGN (h00);
1185*56bb7041Schristos   ASSIGN (h10);
1186*56bb7041Schristos   ASSIGN (P);
1187*56bb7041Schristos 
1188*56bb7041Schristos   /* If we have full reg assignments, mask out LSB to encode
1189*56bb7041Schristos   single or simultaneous even/odd register moves.  */
1190*56bb7041Schristos   if (P)
1191*56bb7041Schristos     {
1192*56bb7041Schristos       dst->regno &= 0x06;
1193*56bb7041Schristos     }
1194*56bb7041Schristos 
1195*56bb7041Schristos   ASSIGN_R (dst);
1196*56bb7041Schristos   ASSIGN_R (src0);
1197*56bb7041Schristos   ASSIGN_R (src1);
1198*56bb7041Schristos 
1199*56bb7041Schristos   return GEN_OPCODE32 ();
1200*56bb7041Schristos }
1201*56bb7041Schristos 
1202*56bb7041Schristos INSTR_T
bfin_gen_dsp32mult(int op1,int MM,int mmod,int w1,int P,int h01,int h11,int h00,int h10,int op0,REG_T dst,REG_T src0,REG_T src1,int w0)1203*56bb7041Schristos bfin_gen_dsp32mult (int op1, int MM, int mmod, int w1, int P,
1204*56bb7041Schristos 	            int h01, int h11, int h00, int h10, int op0,
1205*56bb7041Schristos                     REG_T dst, REG_T src0, REG_T src1, int w0)
1206*56bb7041Schristos {
1207*56bb7041Schristos   INIT (DSP32Mult);
1208*56bb7041Schristos 
1209*56bb7041Schristos   ASSIGN (op0);
1210*56bb7041Schristos   ASSIGN (op1);
1211*56bb7041Schristos   ASSIGN (MM);
1212*56bb7041Schristos   ASSIGN (mmod);
1213*56bb7041Schristos   ASSIGN (w0);
1214*56bb7041Schristos   ASSIGN (w1);
1215*56bb7041Schristos   ASSIGN (h01);
1216*56bb7041Schristos   ASSIGN (h11);
1217*56bb7041Schristos   ASSIGN (h00);
1218*56bb7041Schristos   ASSIGN (h10);
1219*56bb7041Schristos   ASSIGN (P);
1220*56bb7041Schristos 
1221*56bb7041Schristos   if (P)
1222*56bb7041Schristos     {
1223*56bb7041Schristos       dst->regno &= 0x06;
1224*56bb7041Schristos     }
1225*56bb7041Schristos 
1226*56bb7041Schristos   ASSIGN_R (dst);
1227*56bb7041Schristos   ASSIGN_R (src0);
1228*56bb7041Schristos   ASSIGN_R (src1);
1229*56bb7041Schristos 
1230*56bb7041Schristos   return GEN_OPCODE32 ();
1231*56bb7041Schristos }
1232*56bb7041Schristos 
1233*56bb7041Schristos INSTR_T
bfin_gen_dsp32alu(int HL,int aopcde,int aop,int s,int x,REG_T dst0,REG_T dst1,REG_T src0,REG_T src1)1234*56bb7041Schristos bfin_gen_dsp32alu (int HL, int aopcde, int aop, int s, int x,
1235*56bb7041Schristos               REG_T dst0, REG_T dst1, REG_T src0, REG_T src1)
1236*56bb7041Schristos {
1237*56bb7041Schristos   INIT (DSP32Alu);
1238*56bb7041Schristos 
1239*56bb7041Schristos   ASSIGN (HL);
1240*56bb7041Schristos   ASSIGN (aopcde);
1241*56bb7041Schristos   ASSIGN (aop);
1242*56bb7041Schristos   ASSIGN (s);
1243*56bb7041Schristos   ASSIGN (x);
1244*56bb7041Schristos   ASSIGN_R (dst0);
1245*56bb7041Schristos   ASSIGN_R (dst1);
1246*56bb7041Schristos   ASSIGN_R (src0);
1247*56bb7041Schristos   ASSIGN_R (src1);
1248*56bb7041Schristos 
1249*56bb7041Schristos   return GEN_OPCODE32 ();
1250*56bb7041Schristos }
1251*56bb7041Schristos 
1252*56bb7041Schristos INSTR_T
bfin_gen_dsp32shift(int sopcde,REG_T dst0,REG_T src0,REG_T src1,int sop,int HLs)1253*56bb7041Schristos bfin_gen_dsp32shift (int sopcde, REG_T dst0, REG_T src0,
1254*56bb7041Schristos                 REG_T src1, int sop, int HLs)
1255*56bb7041Schristos {
1256*56bb7041Schristos   INIT (DSP32Shift);
1257*56bb7041Schristos 
1258*56bb7041Schristos   ASSIGN (sopcde);
1259*56bb7041Schristos   ASSIGN (sop);
1260*56bb7041Schristos   ASSIGN (HLs);
1261*56bb7041Schristos 
1262*56bb7041Schristos   ASSIGN_R (dst0);
1263*56bb7041Schristos   ASSIGN_R (src0);
1264*56bb7041Schristos   ASSIGN_R (src1);
1265*56bb7041Schristos 
1266*56bb7041Schristos   return GEN_OPCODE32 ();
1267*56bb7041Schristos }
1268*56bb7041Schristos 
1269*56bb7041Schristos INSTR_T
bfin_gen_dsp32shiftimm(int sopcde,REG_T dst0,int immag,REG_T src1,int sop,int HLs)1270*56bb7041Schristos bfin_gen_dsp32shiftimm (int sopcde, REG_T dst0, int immag,
1271*56bb7041Schristos                    REG_T src1, int sop, int HLs)
1272*56bb7041Schristos {
1273*56bb7041Schristos   INIT (DSP32ShiftImm);
1274*56bb7041Schristos 
1275*56bb7041Schristos   ASSIGN (sopcde);
1276*56bb7041Schristos   ASSIGN (sop);
1277*56bb7041Schristos   ASSIGN (HLs);
1278*56bb7041Schristos 
1279*56bb7041Schristos   ASSIGN_R (dst0);
1280*56bb7041Schristos   ASSIGN (immag);
1281*56bb7041Schristos   ASSIGN_R (src1);
1282*56bb7041Schristos 
1283*56bb7041Schristos   return GEN_OPCODE32 ();
1284*56bb7041Schristos }
1285*56bb7041Schristos 
1286*56bb7041Schristos /* LOOP SETUP.  */
1287*56bb7041Schristos 
1288*56bb7041Schristos INSTR_T
bfin_gen_loopsetup(Expr_Node * psoffset,REG_T c,int rop,Expr_Node * peoffset,REG_T reg)1289*56bb7041Schristos bfin_gen_loopsetup (Expr_Node * psoffset, REG_T c, int rop,
1290*56bb7041Schristos                Expr_Node * peoffset, REG_T reg)
1291*56bb7041Schristos {
1292*56bb7041Schristos   int soffset, eoffset;
1293*56bb7041Schristos   INIT (LoopSetup);
1294*56bb7041Schristos 
1295*56bb7041Schristos   soffset = (EXPR_VALUE (psoffset) >> 1);
1296*56bb7041Schristos   ASSIGN (soffset);
1297*56bb7041Schristos   eoffset = (EXPR_VALUE (peoffset) >> 1);
1298*56bb7041Schristos   ASSIGN (eoffset);
1299*56bb7041Schristos   ASSIGN (rop);
1300*56bb7041Schristos   ASSIGN_R (c);
1301*56bb7041Schristos   ASSIGN_R (reg);
1302*56bb7041Schristos 
1303*56bb7041Schristos   return
1304*56bb7041Schristos       conscode (gencode (HI (c_code.opcode)),
1305*56bb7041Schristos 		conctcode (Expr_Node_Gen_Reloc (psoffset, BFD_RELOC_BFIN_5_PCREL),
1306*56bb7041Schristos 			   conctcode (gencode (LO (c_code.opcode)), Expr_Node_Gen_Reloc (peoffset, BFD_RELOC_BFIN_11_PCREL))));
1307*56bb7041Schristos 
1308*56bb7041Schristos }
1309*56bb7041Schristos 
1310*56bb7041Schristos /*  Call, Link.  */
1311*56bb7041Schristos 
1312*56bb7041Schristos INSTR_T
bfin_gen_calla(Expr_Node * addr,int S)1313*56bb7041Schristos bfin_gen_calla (Expr_Node * addr, int S)
1314*56bb7041Schristos {
1315*56bb7041Schristos   int val;
1316*56bb7041Schristos   int high_val;
1317*56bb7041Schristos   int rel = 0;
1318*56bb7041Schristos   INIT (CALLa);
1319*56bb7041Schristos 
1320*56bb7041Schristos   switch(S){
1321*56bb7041Schristos    case 0 : rel = BFD_RELOC_BFIN_24_PCREL_JUMP_L; break;
1322*56bb7041Schristos    case 1 : rel = BFD_RELOC_24_PCREL; break;
1323*56bb7041Schristos    case 2 : rel = BFD_RELOC_BFIN_PLTPC; break;
1324*56bb7041Schristos    default : break;
1325*56bb7041Schristos   }
1326*56bb7041Schristos 
1327*56bb7041Schristos   ASSIGN (S);
1328*56bb7041Schristos 
1329*56bb7041Schristos   val = EXPR_VALUE (addr) >> 1;
1330*56bb7041Schristos   high_val = val >> 16;
1331*56bb7041Schristos 
1332*56bb7041Schristos   return conscode (gencode (HI (c_code.opcode) | (high_val & 0xff)),
1333*56bb7041Schristos                      Expr_Node_Gen_Reloc (addr, rel));
1334*56bb7041Schristos   }
1335*56bb7041Schristos 
1336*56bb7041Schristos INSTR_T
bfin_gen_linkage(int R,int framesize)1337*56bb7041Schristos bfin_gen_linkage (int R, int framesize)
1338*56bb7041Schristos {
1339*56bb7041Schristos   INIT (Linkage);
1340*56bb7041Schristos 
1341*56bb7041Schristos   ASSIGN (R);
1342*56bb7041Schristos   ASSIGN (framesize);
1343*56bb7041Schristos 
1344*56bb7041Schristos   return GEN_OPCODE32 ();
1345*56bb7041Schristos }
1346*56bb7041Schristos 
1347*56bb7041Schristos 
1348*56bb7041Schristos /* Load and Store.  */
1349*56bb7041Schristos 
1350*56bb7041Schristos INSTR_T
bfin_gen_ldimmhalf(REG_T reg,int H,int S,int Z,Expr_Node * phword,int rel)1351*56bb7041Schristos bfin_gen_ldimmhalf (REG_T reg, int H, int S, int Z, Expr_Node * phword, int rel)
1352*56bb7041Schristos {
1353*56bb7041Schristos   int grp, hword;
1354*56bb7041Schristos   unsigned val = EXPR_VALUE (phword);
1355*56bb7041Schristos   INIT (LDIMMhalf);
1356*56bb7041Schristos 
1357*56bb7041Schristos   ASSIGN (H);
1358*56bb7041Schristos   ASSIGN (S);
1359*56bb7041Schristos   ASSIGN (Z);
1360*56bb7041Schristos 
1361*56bb7041Schristos   ASSIGN_R (reg);
1362*56bb7041Schristos   grp = (GROUP (reg));
1363*56bb7041Schristos   ASSIGN (grp);
1364*56bb7041Schristos   if (rel == 2)
1365*56bb7041Schristos     {
1366*56bb7041Schristos       return conscode (gencode (HI (c_code.opcode)), Expr_Node_Gen_Reloc (phword, BFD_RELOC_BFIN_16_IMM));
1367*56bb7041Schristos     }
1368*56bb7041Schristos   else if (rel == 1)
1369*56bb7041Schristos     {
1370*56bb7041Schristos       return conscode (gencode (HI (c_code.opcode)), Expr_Node_Gen_Reloc (phword, IS_H (*reg) ? BFD_RELOC_BFIN_16_HIGH : BFD_RELOC_BFIN_16_LOW));
1371*56bb7041Schristos     }
1372*56bb7041Schristos   else
1373*56bb7041Schristos     {
1374*56bb7041Schristos       hword = val;
1375*56bb7041Schristos       ASSIGN (hword);
1376*56bb7041Schristos     }
1377*56bb7041Schristos   return GEN_OPCODE32 ();
1378*56bb7041Schristos }
1379*56bb7041Schristos 
1380*56bb7041Schristos INSTR_T
bfin_gen_ldstidxi(REG_T ptr,REG_T reg,int W,int sz,int Z,Expr_Node * poffset)1381*56bb7041Schristos bfin_gen_ldstidxi (REG_T ptr, REG_T reg, int W, int sz, int Z, Expr_Node * poffset)
1382*56bb7041Schristos {
1383*56bb7041Schristos   INIT (LDSTidxI);
1384*56bb7041Schristos 
1385*56bb7041Schristos   if (!IS_PREG (*ptr) || (!IS_DREG (*reg) && !Z))
1386*56bb7041Schristos     {
1387*56bb7041Schristos       fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1388*56bb7041Schristos       return 0;
1389*56bb7041Schristos     }
1390*56bb7041Schristos 
1391*56bb7041Schristos   ASSIGN_R (ptr);
1392*56bb7041Schristos   ASSIGN_R (reg);
1393*56bb7041Schristos   ASSIGN (W);
1394*56bb7041Schristos   ASSIGN (sz);
1395*56bb7041Schristos 
1396*56bb7041Schristos   ASSIGN (Z);
1397*56bb7041Schristos 
1398*56bb7041Schristos   if (poffset->type != Expr_Node_Constant)
1399*56bb7041Schristos     {
1400*56bb7041Schristos       /* a GOT relocation such as R0 = [P5 + symbol@GOT] */
1401*56bb7041Schristos       /* distinguish between R0 = [P5 + symbol@GOT] and
1402*56bb7041Schristos 	 P5 = [P5 + _current_shared_library_p5_offset_]
1403*56bb7041Schristos       */
1404*56bb7041Schristos       if (poffset->type == Expr_Node_Reloc
1405*56bb7041Schristos 	  && !strcmp (poffset->value.s_value,
1406*56bb7041Schristos 		      "_current_shared_library_p5_offset_"))
1407*56bb7041Schristos 	{
1408*56bb7041Schristos 	  return  conscode (gencode (HI (c_code.opcode)),
1409*56bb7041Schristos 			    Expr_Node_Gen_Reloc(poffset, BFD_RELOC_16));
1410*56bb7041Schristos 	}
1411*56bb7041Schristos       else if (poffset->type != Expr_Node_GOT_Reloc)
1412*56bb7041Schristos 	abort ();
1413*56bb7041Schristos 
1414*56bb7041Schristos       return conscode (gencode (HI (c_code.opcode)),
1415*56bb7041Schristos 		       Expr_Node_Gen_Reloc(poffset->Left_Child,
1416*56bb7041Schristos 					   poffset->value.i_value));
1417*56bb7041Schristos     }
1418*56bb7041Schristos   else
1419*56bb7041Schristos     {
1420*56bb7041Schristos       int value, offset;
1421*56bb7041Schristos       switch (sz)
1422*56bb7041Schristos 	{				/* load/store access size */
1423*56bb7041Schristos 	case 0:			/* 32 bit */
1424*56bb7041Schristos 	  value = EXPR_VALUE (poffset) >> 2;
1425*56bb7041Schristos 	  break;
1426*56bb7041Schristos 	case 1:			/* 16 bit */
1427*56bb7041Schristos 	  value = EXPR_VALUE (poffset) >> 1;
1428*56bb7041Schristos 	  break;
1429*56bb7041Schristos 	case 2:			/* 8 bit */
1430*56bb7041Schristos 	  value = EXPR_VALUE (poffset);
1431*56bb7041Schristos 	  break;
1432*56bb7041Schristos 	default:
1433*56bb7041Schristos 	  abort ();
1434*56bb7041Schristos 	}
1435*56bb7041Schristos 
1436*56bb7041Schristos       offset = (value & 0xffff);
1437*56bb7041Schristos       ASSIGN (offset);
1438*56bb7041Schristos       return GEN_OPCODE32 ();
1439*56bb7041Schristos     }
1440*56bb7041Schristos }
1441*56bb7041Schristos 
1442*56bb7041Schristos 
1443*56bb7041Schristos INSTR_T
bfin_gen_ldst(REG_T ptr,REG_T reg,int aop,int sz,int Z,int W)1444*56bb7041Schristos bfin_gen_ldst (REG_T ptr, REG_T reg, int aop, int sz, int Z, int W)
1445*56bb7041Schristos {
1446*56bb7041Schristos   INIT (LDST);
1447*56bb7041Schristos 
1448*56bb7041Schristos   if (!IS_PREG (*ptr) || (!IS_DREG (*reg) && !Z))
1449*56bb7041Schristos     {
1450*56bb7041Schristos       fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1451*56bb7041Schristos       return 0;
1452*56bb7041Schristos     }
1453*56bb7041Schristos 
1454*56bb7041Schristos   ASSIGN_R (ptr);
1455*56bb7041Schristos   ASSIGN_R (reg);
1456*56bb7041Schristos   ASSIGN (aop);
1457*56bb7041Schristos   ASSIGN (sz);
1458*56bb7041Schristos   ASSIGN (Z);
1459*56bb7041Schristos   ASSIGN (W);
1460*56bb7041Schristos 
1461*56bb7041Schristos   return GEN_OPCODE16 ();
1462*56bb7041Schristos }
1463*56bb7041Schristos 
1464*56bb7041Schristos INSTR_T
bfin_gen_ldstii(REG_T ptr,REG_T reg,Expr_Node * poffset,int W,int opc)1465*56bb7041Schristos bfin_gen_ldstii (REG_T ptr, REG_T reg, Expr_Node * poffset, int W, int opc)
1466*56bb7041Schristos {
1467*56bb7041Schristos   int offset;
1468*56bb7041Schristos   int value = 0;
1469*56bb7041Schristos   INIT (LDSTii);
1470*56bb7041Schristos 
1471*56bb7041Schristos   if (!IS_PREG (*ptr))
1472*56bb7041Schristos     {
1473*56bb7041Schristos       fprintf (stderr, "Warning: possible mixup of Preg/Dreg\n");
1474*56bb7041Schristos       return 0;
1475*56bb7041Schristos     }
1476*56bb7041Schristos 
1477*56bb7041Schristos   switch (opc)
1478*56bb7041Schristos     {
1479*56bb7041Schristos     case 1:
1480*56bb7041Schristos     case 2:
1481*56bb7041Schristos       value = EXPR_VALUE (poffset) >> 1;
1482*56bb7041Schristos       break;
1483*56bb7041Schristos     case 0:
1484*56bb7041Schristos     case 3:
1485*56bb7041Schristos       value = EXPR_VALUE (poffset) >> 2;
1486*56bb7041Schristos       break;
1487*56bb7041Schristos     }
1488*56bb7041Schristos 
1489*56bb7041Schristos   ASSIGN_R (ptr);
1490*56bb7041Schristos   ASSIGN_R (reg);
1491*56bb7041Schristos 
1492*56bb7041Schristos   offset = value;
1493*56bb7041Schristos   ASSIGN (offset);
1494*56bb7041Schristos   ASSIGN (W);
1495*56bb7041Schristos   ASSIGNF (opc, op);
1496*56bb7041Schristos 
1497*56bb7041Schristos   return GEN_OPCODE16 ();
1498*56bb7041Schristos }
1499*56bb7041Schristos 
1500*56bb7041Schristos INSTR_T
bfin_gen_ldstiifp(REG_T sreg,Expr_Node * poffset,int W)1501*56bb7041Schristos bfin_gen_ldstiifp (REG_T sreg, Expr_Node * poffset, int W)
1502*56bb7041Schristos {
1503*56bb7041Schristos   /* Set bit 4 if it's a Preg.  */
1504*56bb7041Schristos   int reg = (sreg->regno & CODE_MASK) | (IS_PREG (*sreg) ? 0x8 : 0x0);
1505*56bb7041Schristos   int offset = ((~(EXPR_VALUE (poffset) >> 2)) & 0x1f) + 1;
1506*56bb7041Schristos   INIT (LDSTiiFP);
1507*56bb7041Schristos   ASSIGN (reg);
1508*56bb7041Schristos   ASSIGN (offset);
1509*56bb7041Schristos   ASSIGN (W);
1510*56bb7041Schristos 
1511*56bb7041Schristos   return GEN_OPCODE16 ();
1512*56bb7041Schristos }
1513*56bb7041Schristos 
1514*56bb7041Schristos INSTR_T
bfin_gen_ldstpmod(REG_T ptr,REG_T reg,int aop,int W,REG_T idx)1515*56bb7041Schristos bfin_gen_ldstpmod (REG_T ptr, REG_T reg, int aop, int W, REG_T idx)
1516*56bb7041Schristos {
1517*56bb7041Schristos   INIT (LDSTpmod);
1518*56bb7041Schristos 
1519*56bb7041Schristos   ASSIGN_R (ptr);
1520*56bb7041Schristos   ASSIGN_R (reg);
1521*56bb7041Schristos   ASSIGN (aop);
1522*56bb7041Schristos   ASSIGN (W);
1523*56bb7041Schristos   ASSIGN_R (idx);
1524*56bb7041Schristos 
1525*56bb7041Schristos   return GEN_OPCODE16 ();
1526*56bb7041Schristos }
1527*56bb7041Schristos 
1528*56bb7041Schristos INSTR_T
bfin_gen_dspldst(REG_T i,REG_T reg,int aop,int W,int m)1529*56bb7041Schristos bfin_gen_dspldst (REG_T i, REG_T reg, int aop, int W, int m)
1530*56bb7041Schristos {
1531*56bb7041Schristos   INIT (DspLDST);
1532*56bb7041Schristos 
1533*56bb7041Schristos   ASSIGN_R (i);
1534*56bb7041Schristos   ASSIGN_R (reg);
1535*56bb7041Schristos   ASSIGN (aop);
1536*56bb7041Schristos   ASSIGN (W);
1537*56bb7041Schristos   ASSIGN (m);
1538*56bb7041Schristos 
1539*56bb7041Schristos   return GEN_OPCODE16 ();
1540*56bb7041Schristos }
1541*56bb7041Schristos 
1542*56bb7041Schristos INSTR_T
bfin_gen_logi2op(int opc,int src,int dst)1543*56bb7041Schristos bfin_gen_logi2op (int opc, int src, int dst)
1544*56bb7041Schristos {
1545*56bb7041Schristos   INIT (LOGI2op);
1546*56bb7041Schristos 
1547*56bb7041Schristos   ASSIGN (opc);
1548*56bb7041Schristos   ASSIGN (src);
1549*56bb7041Schristos   ASSIGN (dst);
1550*56bb7041Schristos 
1551*56bb7041Schristos   return GEN_OPCODE16 ();
1552*56bb7041Schristos }
1553*56bb7041Schristos 
1554*56bb7041Schristos INSTR_T
bfin_gen_brcc(int T,int B,Expr_Node * poffset)1555*56bb7041Schristos bfin_gen_brcc (int T, int B, Expr_Node * poffset)
1556*56bb7041Schristos {
1557*56bb7041Schristos   int offset;
1558*56bb7041Schristos   INIT (BRCC);
1559*56bb7041Schristos 
1560*56bb7041Schristos   ASSIGN (T);
1561*56bb7041Schristos   ASSIGN (B);
1562*56bb7041Schristos   offset = ((EXPR_VALUE (poffset) >> 1));
1563*56bb7041Schristos   ASSIGN (offset);
1564*56bb7041Schristos   return conscode (gencode (c_code.opcode), Expr_Node_Gen_Reloc (poffset, BFD_RELOC_BFIN_10_PCREL));
1565*56bb7041Schristos }
1566*56bb7041Schristos 
1567*56bb7041Schristos INSTR_T
bfin_gen_ujump(Expr_Node * poffset)1568*56bb7041Schristos bfin_gen_ujump (Expr_Node * poffset)
1569*56bb7041Schristos {
1570*56bb7041Schristos   int offset;
1571*56bb7041Schristos   INIT (UJump);
1572*56bb7041Schristos 
1573*56bb7041Schristos   offset = ((EXPR_VALUE (poffset) >> 1));
1574*56bb7041Schristos   ASSIGN (offset);
1575*56bb7041Schristos 
1576*56bb7041Schristos   return conscode (gencode (c_code.opcode),
1577*56bb7041Schristos                    Expr_Node_Gen_Reloc (
1578*56bb7041Schristos                        poffset, BFD_RELOC_BFIN_12_PCREL_JUMP_S));
1579*56bb7041Schristos }
1580*56bb7041Schristos 
1581*56bb7041Schristos INSTR_T
bfin_gen_alu2op(REG_T dst,REG_T src,int opc)1582*56bb7041Schristos bfin_gen_alu2op (REG_T dst, REG_T src, int opc)
1583*56bb7041Schristos {
1584*56bb7041Schristos   INIT (ALU2op);
1585*56bb7041Schristos 
1586*56bb7041Schristos   ASSIGN_R (dst);
1587*56bb7041Schristos   ASSIGN_R (src);
1588*56bb7041Schristos   ASSIGN (opc);
1589*56bb7041Schristos 
1590*56bb7041Schristos   return GEN_OPCODE16 ();
1591*56bb7041Schristos }
1592*56bb7041Schristos 
1593*56bb7041Schristos INSTR_T
bfin_gen_compi2opd(REG_T dst,int src,int opc)1594*56bb7041Schristos bfin_gen_compi2opd (REG_T dst, int src, int opc)
1595*56bb7041Schristos {
1596*56bb7041Schristos   INIT (COMPI2opD);
1597*56bb7041Schristos 
1598*56bb7041Schristos   ASSIGN_R (dst);
1599*56bb7041Schristos   ASSIGN (src);
1600*56bb7041Schristos   ASSIGNF (opc, op);
1601*56bb7041Schristos 
1602*56bb7041Schristos   return GEN_OPCODE16 ();
1603*56bb7041Schristos }
1604*56bb7041Schristos 
1605*56bb7041Schristos INSTR_T
bfin_gen_compi2opp(REG_T dst,int src,int opc)1606*56bb7041Schristos bfin_gen_compi2opp (REG_T dst, int src, int opc)
1607*56bb7041Schristos {
1608*56bb7041Schristos   INIT (COMPI2opP);
1609*56bb7041Schristos 
1610*56bb7041Schristos   ASSIGN_R (dst);
1611*56bb7041Schristos   ASSIGN (src);
1612*56bb7041Schristos   ASSIGNF (opc, op);
1613*56bb7041Schristos 
1614*56bb7041Schristos   return GEN_OPCODE16 ();
1615*56bb7041Schristos }
1616*56bb7041Schristos 
1617*56bb7041Schristos INSTR_T
bfin_gen_dagmodik(REG_T i,int opc)1618*56bb7041Schristos bfin_gen_dagmodik (REG_T i, int opc)
1619*56bb7041Schristos {
1620*56bb7041Schristos   INIT (DagMODik);
1621*56bb7041Schristos 
1622*56bb7041Schristos   ASSIGN_R (i);
1623*56bb7041Schristos   ASSIGNF (opc, op);
1624*56bb7041Schristos 
1625*56bb7041Schristos   return GEN_OPCODE16 ();
1626*56bb7041Schristos }
1627*56bb7041Schristos 
1628*56bb7041Schristos INSTR_T
bfin_gen_dagmodim(REG_T i,REG_T m,int opc,int br)1629*56bb7041Schristos bfin_gen_dagmodim (REG_T i, REG_T m, int opc, int br)
1630*56bb7041Schristos {
1631*56bb7041Schristos   INIT (DagMODim);
1632*56bb7041Schristos 
1633*56bb7041Schristos   ASSIGN_R (i);
1634*56bb7041Schristos   ASSIGN_R (m);
1635*56bb7041Schristos   ASSIGNF (opc, op);
1636*56bb7041Schristos   ASSIGN (br);
1637*56bb7041Schristos 
1638*56bb7041Schristos   return GEN_OPCODE16 ();
1639*56bb7041Schristos }
1640*56bb7041Schristos 
1641*56bb7041Schristos INSTR_T
bfin_gen_ptr2op(REG_T dst,REG_T src,int opc)1642*56bb7041Schristos bfin_gen_ptr2op (REG_T dst, REG_T src, int opc)
1643*56bb7041Schristos {
1644*56bb7041Schristos   INIT (PTR2op);
1645*56bb7041Schristos 
1646*56bb7041Schristos   ASSIGN_R (dst);
1647*56bb7041Schristos   ASSIGN_R (src);
1648*56bb7041Schristos   ASSIGN (opc);
1649*56bb7041Schristos 
1650*56bb7041Schristos   return GEN_OPCODE16 ();
1651*56bb7041Schristos }
1652*56bb7041Schristos 
1653*56bb7041Schristos INSTR_T
bfin_gen_comp3op(REG_T src0,REG_T src1,REG_T dst,int opc)1654*56bb7041Schristos bfin_gen_comp3op (REG_T src0, REG_T src1, REG_T dst, int opc)
1655*56bb7041Schristos {
1656*56bb7041Schristos   INIT (COMP3op);
1657*56bb7041Schristos 
1658*56bb7041Schristos   ASSIGN_R (src0);
1659*56bb7041Schristos   ASSIGN_R (src1);
1660*56bb7041Schristos   ASSIGN_R (dst);
1661*56bb7041Schristos   ASSIGN (opc);
1662*56bb7041Schristos 
1663*56bb7041Schristos   return GEN_OPCODE16 ();
1664*56bb7041Schristos }
1665*56bb7041Schristos 
1666*56bb7041Schristos INSTR_T
bfin_gen_ccflag(REG_T x,int y,int opc,int I,int G)1667*56bb7041Schristos bfin_gen_ccflag (REG_T x, int y, int opc, int I, int G)
1668*56bb7041Schristos {
1669*56bb7041Schristos   INIT (CCflag);
1670*56bb7041Schristos 
1671*56bb7041Schristos   ASSIGN_R (x);
1672*56bb7041Schristos   ASSIGN (y);
1673*56bb7041Schristos   ASSIGN (opc);
1674*56bb7041Schristos   ASSIGN (I);
1675*56bb7041Schristos   ASSIGN (G);
1676*56bb7041Schristos 
1677*56bb7041Schristos   return GEN_OPCODE16 ();
1678*56bb7041Schristos }
1679*56bb7041Schristos 
1680*56bb7041Schristos INSTR_T
bfin_gen_ccmv(REG_T src,REG_T dst,int T)1681*56bb7041Schristos bfin_gen_ccmv (REG_T src, REG_T dst, int T)
1682*56bb7041Schristos {
1683*56bb7041Schristos   int s, d;
1684*56bb7041Schristos   INIT (CCmv);
1685*56bb7041Schristos 
1686*56bb7041Schristos   ASSIGN_R (src);
1687*56bb7041Schristos   ASSIGN_R (dst);
1688*56bb7041Schristos   s = (GROUP (src));
1689*56bb7041Schristos   ASSIGN (s);
1690*56bb7041Schristos   d = (GROUP (dst));
1691*56bb7041Schristos   ASSIGN (d);
1692*56bb7041Schristos   ASSIGN (T);
1693*56bb7041Schristos 
1694*56bb7041Schristos   return GEN_OPCODE16 ();
1695*56bb7041Schristos }
1696*56bb7041Schristos 
1697*56bb7041Schristos INSTR_T
bfin_gen_cc2stat(int cbit,int opc,int D)1698*56bb7041Schristos bfin_gen_cc2stat (int cbit, int opc, int D)
1699*56bb7041Schristos {
1700*56bb7041Schristos   INIT (CC2stat);
1701*56bb7041Schristos 
1702*56bb7041Schristos   ASSIGN (cbit);
1703*56bb7041Schristos   ASSIGNF (opc, op);
1704*56bb7041Schristos   ASSIGN (D);
1705*56bb7041Schristos 
1706*56bb7041Schristos   return GEN_OPCODE16 ();
1707*56bb7041Schristos }
1708*56bb7041Schristos 
1709*56bb7041Schristos INSTR_T
bfin_gen_regmv(REG_T src,REG_T dst)1710*56bb7041Schristos bfin_gen_regmv (REG_T src, REG_T dst)
1711*56bb7041Schristos {
1712*56bb7041Schristos   int gs, gd;
1713*56bb7041Schristos   INIT (RegMv);
1714*56bb7041Schristos 
1715*56bb7041Schristos   ASSIGN_R (src);
1716*56bb7041Schristos   ASSIGN_R (dst);
1717*56bb7041Schristos 
1718*56bb7041Schristos   gs = (GROUP (src));
1719*56bb7041Schristos   ASSIGN (gs);
1720*56bb7041Schristos   gd = (GROUP (dst));
1721*56bb7041Schristos   ASSIGN (gd);
1722*56bb7041Schristos 
1723*56bb7041Schristos   return GEN_OPCODE16 ();
1724*56bb7041Schristos }
1725*56bb7041Schristos 
1726*56bb7041Schristos INSTR_T
bfin_gen_cc2dreg(int opc,REG_T reg)1727*56bb7041Schristos bfin_gen_cc2dreg (int opc, REG_T reg)
1728*56bb7041Schristos {
1729*56bb7041Schristos   INIT (CC2dreg);
1730*56bb7041Schristos 
1731*56bb7041Schristos   ASSIGNF (opc, op);
1732*56bb7041Schristos   ASSIGN_R (reg);
1733*56bb7041Schristos 
1734*56bb7041Schristos   return GEN_OPCODE16 ();
1735*56bb7041Schristos }
1736*56bb7041Schristos 
1737*56bb7041Schristos INSTR_T
bfin_gen_progctrl(int prgfunc,int poprnd)1738*56bb7041Schristos bfin_gen_progctrl (int prgfunc, int poprnd)
1739*56bb7041Schristos {
1740*56bb7041Schristos   INIT (ProgCtrl);
1741*56bb7041Schristos 
1742*56bb7041Schristos   ASSIGN (prgfunc);
1743*56bb7041Schristos   ASSIGN (poprnd);
1744*56bb7041Schristos 
1745*56bb7041Schristos   return GEN_OPCODE16 ();
1746*56bb7041Schristos }
1747*56bb7041Schristos 
1748*56bb7041Schristos INSTR_T
bfin_gen_cactrl(REG_T reg,int a,int opc)1749*56bb7041Schristos bfin_gen_cactrl (REG_T reg, int a, int opc)
1750*56bb7041Schristos {
1751*56bb7041Schristos   INIT (CaCTRL);
1752*56bb7041Schristos 
1753*56bb7041Schristos   ASSIGN_R (reg);
1754*56bb7041Schristos   ASSIGN (a);
1755*56bb7041Schristos   ASSIGNF (opc, op);
1756*56bb7041Schristos 
1757*56bb7041Schristos   return GEN_OPCODE16 ();
1758*56bb7041Schristos }
1759*56bb7041Schristos 
1760*56bb7041Schristos INSTR_T
bfin_gen_pushpopmultiple(int dr,int pr,int d,int p,int W)1761*56bb7041Schristos bfin_gen_pushpopmultiple (int dr, int pr, int d, int p, int W)
1762*56bb7041Schristos {
1763*56bb7041Schristos   INIT (PushPopMultiple);
1764*56bb7041Schristos 
1765*56bb7041Schristos   ASSIGN (dr);
1766*56bb7041Schristos   ASSIGN (pr);
1767*56bb7041Schristos   ASSIGN (d);
1768*56bb7041Schristos   ASSIGN (p);
1769*56bb7041Schristos   ASSIGN (W);
1770*56bb7041Schristos 
1771*56bb7041Schristos   return GEN_OPCODE16 ();
1772*56bb7041Schristos }
1773*56bb7041Schristos 
1774*56bb7041Schristos INSTR_T
bfin_gen_pushpopreg(REG_T reg,int W)1775*56bb7041Schristos bfin_gen_pushpopreg (REG_T reg, int W)
1776*56bb7041Schristos {
1777*56bb7041Schristos   int grp;
1778*56bb7041Schristos   INIT (PushPopReg);
1779*56bb7041Schristos 
1780*56bb7041Schristos   ASSIGN_R (reg);
1781*56bb7041Schristos   grp = (GROUP (reg));
1782*56bb7041Schristos   ASSIGN (grp);
1783*56bb7041Schristos   ASSIGN (W);
1784*56bb7041Schristos 
1785*56bb7041Schristos   return GEN_OPCODE16 ();
1786*56bb7041Schristos }
1787*56bb7041Schristos 
1788*56bb7041Schristos /* Pseudo Debugging Support.  */
1789*56bb7041Schristos 
1790*56bb7041Schristos INSTR_T
bfin_gen_pseudodbg(int fn,int reg,int grp)1791*56bb7041Schristos bfin_gen_pseudodbg (int fn, int reg, int grp)
1792*56bb7041Schristos {
1793*56bb7041Schristos   INIT (PseudoDbg);
1794*56bb7041Schristos 
1795*56bb7041Schristos   ASSIGN (fn);
1796*56bb7041Schristos   ASSIGN (reg);
1797*56bb7041Schristos   ASSIGN (grp);
1798*56bb7041Schristos 
1799*56bb7041Schristos   return GEN_OPCODE16 ();
1800*56bb7041Schristos }
1801*56bb7041Schristos 
1802*56bb7041Schristos INSTR_T
bfin_gen_pseudodbg_assert(int dbgop,REG_T regtest,int expected)1803*56bb7041Schristos bfin_gen_pseudodbg_assert (int dbgop, REG_T regtest, int expected)
1804*56bb7041Schristos {
1805*56bb7041Schristos   int grp;
1806*56bb7041Schristos   INIT (PseudoDbg_Assert);
1807*56bb7041Schristos 
1808*56bb7041Schristos   ASSIGN (dbgop);
1809*56bb7041Schristos   ASSIGN_R (regtest);
1810*56bb7041Schristos   grp = GROUP (regtest);
1811*56bb7041Schristos   ASSIGN (grp);
1812*56bb7041Schristos   ASSIGN (expected);
1813*56bb7041Schristos 
1814*56bb7041Schristos   return GEN_OPCODE32 ();
1815*56bb7041Schristos }
1816*56bb7041Schristos 
1817*56bb7041Schristos INSTR_T
bfin_gen_pseudochr(int ch)1818*56bb7041Schristos bfin_gen_pseudochr (int ch)
1819*56bb7041Schristos {
1820*56bb7041Schristos   INIT (PseudoChr);
1821*56bb7041Schristos 
1822*56bb7041Schristos   ASSIGN (ch);
1823*56bb7041Schristos 
1824*56bb7041Schristos   return GEN_OPCODE16 ();
1825*56bb7041Schristos }
1826*56bb7041Schristos 
1827*56bb7041Schristos /* Multiple instruction generation.  */
1828*56bb7041Schristos 
1829*56bb7041Schristos INSTR_T
bfin_gen_multi_instr(INSTR_T dsp32,INSTR_T dsp16_grp1,INSTR_T dsp16_grp2)1830*56bb7041Schristos bfin_gen_multi_instr (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
1831*56bb7041Schristos {
1832*56bb7041Schristos   INSTR_T walk;
1833*56bb7041Schristos 
1834*56bb7041Schristos   /* If it's a 0, convert into MNOP. */
1835*56bb7041Schristos   if (dsp32)
1836*56bb7041Schristos     {
1837*56bb7041Schristos       walk = dsp32->next;
1838*56bb7041Schristos       SET_MULTI_INSTRUCTION_BIT (dsp32);
1839*56bb7041Schristos     }
1840*56bb7041Schristos   else
1841*56bb7041Schristos     {
1842*56bb7041Schristos       dsp32 = gencode (0xc803);
1843*56bb7041Schristos       walk = gencode (0x1800);
1844*56bb7041Schristos       dsp32->next = walk;
1845*56bb7041Schristos     }
1846*56bb7041Schristos 
1847*56bb7041Schristos   if (!dsp16_grp1)
1848*56bb7041Schristos     {
1849*56bb7041Schristos       dsp16_grp1 = gencode (0x0000);
1850*56bb7041Schristos     }
1851*56bb7041Schristos 
1852*56bb7041Schristos   if (!dsp16_grp2)
1853*56bb7041Schristos     {
1854*56bb7041Schristos       dsp16_grp2 = gencode (0x0000);
1855*56bb7041Schristos     }
1856*56bb7041Schristos 
1857*56bb7041Schristos   walk->next = dsp16_grp1;
1858*56bb7041Schristos   dsp16_grp1->next = dsp16_grp2;
1859*56bb7041Schristos   dsp16_grp2->next = NULL_CODE;
1860*56bb7041Schristos 
1861*56bb7041Schristos   return dsp32;
1862*56bb7041Schristos }
1863*56bb7041Schristos 
1864*56bb7041Schristos INSTR_T
bfin_gen_loop(Expr_Node * exp,REG_T reg,int rop,REG_T preg)1865*56bb7041Schristos bfin_gen_loop (Expr_Node *exp, REG_T reg, int rop, REG_T preg)
1866*56bb7041Schristos {
1867*56bb7041Schristos   const char *loopsym;
1868*56bb7041Schristos   char *lbeginsym, *lendsym;
1869*56bb7041Schristos   Expr_Node_Value lbeginval, lendval;
1870*56bb7041Schristos   Expr_Node *lbegin, *lend;
1871*56bb7041Schristos   symbolS *sym;
1872*56bb7041Schristos 
1873*56bb7041Schristos   loopsym = exp->value.s_value;
1874*56bb7041Schristos   lbeginsym = (char *) xmalloc (strlen (loopsym) + strlen ("__BEGIN") + 5);
1875*56bb7041Schristos   lendsym = (char *) xmalloc (strlen (loopsym) + strlen ("__END") + 5);
1876*56bb7041Schristos 
1877*56bb7041Schristos   lbeginsym[0] = 0;
1878*56bb7041Schristos   lendsym[0] = 0;
1879*56bb7041Schristos 
1880*56bb7041Schristos   strcat (lbeginsym, "L$L$");
1881*56bb7041Schristos   strcat (lbeginsym, loopsym);
1882*56bb7041Schristos   strcat (lbeginsym, "__BEGIN");
1883*56bb7041Schristos 
1884*56bb7041Schristos   strcat (lendsym, "L$L$");
1885*56bb7041Schristos   strcat (lendsym, loopsym);
1886*56bb7041Schristos   strcat (lendsym, "__END");
1887*56bb7041Schristos 
1888*56bb7041Schristos   lbeginval.s_value = lbeginsym;
1889*56bb7041Schristos   lendval.s_value = lendsym;
1890*56bb7041Schristos 
1891*56bb7041Schristos   lbegin = Expr_Node_Create (Expr_Node_Reloc, lbeginval, NULL, NULL);
1892*56bb7041Schristos   lend   = Expr_Node_Create (Expr_Node_Reloc, lendval, NULL, NULL);
1893*56bb7041Schristos 
1894*56bb7041Schristos   sym = symbol_find(loopsym);
1895*56bb7041Schristos   if (!S_IS_LOCAL (sym) || (S_IS_LOCAL (sym) && !symbol_used_p (sym)))
1896*56bb7041Schristos     symbol_remove (sym, &symbol_rootP, &symbol_lastP);
1897*56bb7041Schristos 
1898*56bb7041Schristos   return bfin_gen_loopsetup (lbegin, reg, rop, lend, preg);
1899*56bb7041Schristos }
1900*56bb7041Schristos 
1901*56bb7041Schristos void
bfin_loop_attempt_create_label(Expr_Node * exp,int is_begin)1902*56bb7041Schristos bfin_loop_attempt_create_label (Expr_Node *exp, int is_begin)
1903*56bb7041Schristos {
1904*56bb7041Schristos   char *name;
1905*56bb7041Schristos   name = fb_label_name (exp->value.i_value, is_begin);
1906*56bb7041Schristos   exp->value.s_value = xstrdup (name);
1907*56bb7041Schristos   exp->type = Expr_Node_Reloc;
1908*56bb7041Schristos }
1909*56bb7041Schristos 
1910*56bb7041Schristos void
bfin_loop_beginend(Expr_Node * exp,int begin)1911*56bb7041Schristos bfin_loop_beginend (Expr_Node *exp, int begin)
1912*56bb7041Schristos {
1913*56bb7041Schristos   const char *loopsym;
1914*56bb7041Schristos   char *label_name;
1915*56bb7041Schristos   symbolS *linelabel;
1916*56bb7041Schristos   const char *suffix = begin ? "__BEGIN" : "__END";
1917*56bb7041Schristos 
1918*56bb7041Schristos   loopsym = exp->value.s_value;
1919*56bb7041Schristos   label_name = (char *) xmalloc (strlen (loopsym) + strlen (suffix) + 5);
1920*56bb7041Schristos 
1921*56bb7041Schristos   label_name[0] = 0;
1922*56bb7041Schristos 
1923*56bb7041Schristos   strcat (label_name, "L$L$");
1924*56bb7041Schristos   strcat (label_name, loopsym);
1925*56bb7041Schristos   strcat (label_name, suffix);
1926*56bb7041Schristos 
1927*56bb7041Schristos   linelabel = colon (label_name);
1928*56bb7041Schristos 
1929*56bb7041Schristos   /* LOOP_END follows the last instruction in the loop.
1930*56bb7041Schristos      Adjust label address.  */
1931*56bb7041Schristos   if (!begin)
1932*56bb7041Schristos     *symbol_X_add_number (linelabel) -= last_insn_size;
1933*56bb7041Schristos }
1934*56bb7041Schristos 
1935*56bb7041Schristos bfd_boolean
bfin_eol_in_insn(char * line)1936*56bb7041Schristos bfin_eol_in_insn (char *line)
1937*56bb7041Schristos {
1938*56bb7041Schristos    /* Allow a new-line to appear in the middle of a multi-issue instruction.  */
1939*56bb7041Schristos 
1940*56bb7041Schristos    char *temp = line;
1941*56bb7041Schristos 
1942*56bb7041Schristos   if (*line != '\n')
1943*56bb7041Schristos     return FALSE;
1944*56bb7041Schristos 
1945*56bb7041Schristos   /* A semi-colon followed by a newline is always the end of a line.  */
1946*56bb7041Schristos   if (line[-1] == ';')
1947*56bb7041Schristos     return FALSE;
1948*56bb7041Schristos 
1949*56bb7041Schristos   if (line[-1] == '|')
1950*56bb7041Schristos     return TRUE;
1951*56bb7041Schristos 
1952*56bb7041Schristos   /* If the || is on the next line, there might be leading whitespace.  */
1953*56bb7041Schristos   temp++;
1954*56bb7041Schristos   while (*temp == ' ' || *temp == '\t') temp++;
1955*56bb7041Schristos 
1956*56bb7041Schristos   if (*temp == '|')
1957*56bb7041Schristos     return TRUE;
1958*56bb7041Schristos 
1959*56bb7041Schristos   return FALSE;
1960*56bb7041Schristos }
1961*56bb7041Schristos 
1962*56bb7041Schristos bfd_boolean
bfin_start_label(char * s)1963*56bb7041Schristos bfin_start_label (char *s)
1964*56bb7041Schristos {
1965*56bb7041Schristos   while (*s != 0)
1966*56bb7041Schristos     {
1967*56bb7041Schristos       if (*s == '(' || *s == '[')
1968*56bb7041Schristos 	return FALSE;
1969*56bb7041Schristos       s++;
1970*56bb7041Schristos     }
1971*56bb7041Schristos 
1972*56bb7041Schristos   return TRUE;
1973*56bb7041Schristos }
1974*56bb7041Schristos 
1975*56bb7041Schristos int
bfin_force_relocation(struct fix * fixp)1976*56bb7041Schristos bfin_force_relocation (struct fix *fixp)
1977*56bb7041Schristos {
1978*56bb7041Schristos   if (fixp->fx_r_type ==BFD_RELOC_BFIN_16_LOW
1979*56bb7041Schristos       || fixp->fx_r_type == BFD_RELOC_BFIN_16_HIGH)
1980*56bb7041Schristos     return TRUE;
1981*56bb7041Schristos 
1982*56bb7041Schristos   return generic_force_reloc (fixp);
1983*56bb7041Schristos }
1984*56bb7041Schristos 
1985*56bb7041Schristos /* This is a stripped down version of the disassembler.  The only thing it
1986*56bb7041Schristos    does is return a mask of registers modified by an instruction.  Only
1987*56bb7041Schristos    instructions that can occur in a parallel-issue bundle are handled, and
1988*56bb7041Schristos    only the registers that can cause a conflict are recorded.  */
1989*56bb7041Schristos 
1990*56bb7041Schristos #define DREG_MASK(n) (0x101 << (n))
1991*56bb7041Schristos #define DREGH_MASK(n) (0x100 << (n))
1992*56bb7041Schristos #define DREGL_MASK(n) (0x001 << (n))
1993*56bb7041Schristos #define IREG_MASK(n) (1 << ((n) + 16))
1994*56bb7041Schristos 
1995*56bb7041Schristos static int
decode_ProgCtrl_0(int iw0)1996*56bb7041Schristos decode_ProgCtrl_0 (int iw0)
1997*56bb7041Schristos {
1998*56bb7041Schristos   if (iw0 == 0)
1999*56bb7041Schristos     return 0;
2000*56bb7041Schristos   abort ();
2001*56bb7041Schristos }
2002*56bb7041Schristos 
2003*56bb7041Schristos static int
decode_LDSTpmod_0(int iw0)2004*56bb7041Schristos decode_LDSTpmod_0 (int iw0)
2005*56bb7041Schristos {
2006*56bb7041Schristos   /* LDSTpmod
2007*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2008*56bb7041Schristos      | 1 | 0 | 0 | 0 |.W.|.aop...|.reg.......|.idx.......|.ptr.......|
2009*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2010*56bb7041Schristos   int W   = ((iw0 >> LDSTpmod_W_bits) & LDSTpmod_W_mask);
2011*56bb7041Schristos   int aop = ((iw0 >> LDSTpmod_aop_bits) & LDSTpmod_aop_mask);
2012*56bb7041Schristos   int idx = ((iw0 >> LDSTpmod_idx_bits) & LDSTpmod_idx_mask);
2013*56bb7041Schristos   int ptr = ((iw0 >> LDSTpmod_ptr_bits) & LDSTpmod_ptr_mask);
2014*56bb7041Schristos   int reg = ((iw0 >> LDSTpmod_reg_bits) & LDSTpmod_reg_mask);
2015*56bb7041Schristos 
2016*56bb7041Schristos   if (aop == 1 && W == 0 && idx == ptr)
2017*56bb7041Schristos     return DREGL_MASK (reg);
2018*56bb7041Schristos   else if (aop == 2 && W == 0 && idx == ptr)
2019*56bb7041Schristos     return DREGH_MASK (reg);
2020*56bb7041Schristos   else if (aop == 1 && W == 1 && idx == ptr)
2021*56bb7041Schristos     return 0;
2022*56bb7041Schristos   else if (aop == 2 && W == 1 && idx == ptr)
2023*56bb7041Schristos     return 0;
2024*56bb7041Schristos   else if (aop == 0 && W == 0)
2025*56bb7041Schristos     return DREG_MASK (reg);
2026*56bb7041Schristos   else if (aop == 1 && W == 0)
2027*56bb7041Schristos     return DREGL_MASK (reg);
2028*56bb7041Schristos   else if (aop == 2 && W == 0)
2029*56bb7041Schristos     return DREGH_MASK (reg);
2030*56bb7041Schristos   else if (aop == 3 && W == 0)
2031*56bb7041Schristos     return DREG_MASK (reg);
2032*56bb7041Schristos   else if (aop == 3 && W == 1)
2033*56bb7041Schristos     return DREG_MASK (reg);
2034*56bb7041Schristos   else if (aop == 0 && W == 1)
2035*56bb7041Schristos     return 0;
2036*56bb7041Schristos   else if (aop == 1 && W == 1)
2037*56bb7041Schristos     return 0;
2038*56bb7041Schristos   else if (aop == 2 && W == 1)
2039*56bb7041Schristos     return 0;
2040*56bb7041Schristos   else
2041*56bb7041Schristos     return 0;
2042*56bb7041Schristos 
2043*56bb7041Schristos   return 2;
2044*56bb7041Schristos }
2045*56bb7041Schristos 
2046*56bb7041Schristos static int
decode_dagMODim_0(int iw0)2047*56bb7041Schristos decode_dagMODim_0 (int iw0)
2048*56bb7041Schristos {
2049*56bb7041Schristos   /* dagMODim
2050*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2051*56bb7041Schristos      | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |.br| 1 | 1 |.op|.m.....|.i.....|
2052*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2053*56bb7041Schristos   int i  = ((iw0 >> DagMODim_i_bits) & DagMODim_i_mask);
2054*56bb7041Schristos   int opc  = ((iw0 >> DagMODim_op_bits) & DagMODim_op_mask);
2055*56bb7041Schristos 
2056*56bb7041Schristos   if (opc == 0 || opc == 1)
2057*56bb7041Schristos     return IREG_MASK (i);
2058*56bb7041Schristos   else
2059*56bb7041Schristos     return 0;
2060*56bb7041Schristos 
2061*56bb7041Schristos   return 2;
2062*56bb7041Schristos }
2063*56bb7041Schristos 
2064*56bb7041Schristos static int
decode_dagMODik_0(int iw0)2065*56bb7041Schristos decode_dagMODik_0 (int iw0)
2066*56bb7041Schristos {
2067*56bb7041Schristos   /* dagMODik
2068*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2069*56bb7041Schristos      | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 |.op....|.i.....|
2070*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2071*56bb7041Schristos   int i  = ((iw0 >> DagMODik_i_bits) & DagMODik_i_mask);
2072*56bb7041Schristos   return IREG_MASK (i);
2073*56bb7041Schristos }
2074*56bb7041Schristos 
2075*56bb7041Schristos /* GOOD */
2076*56bb7041Schristos static int
decode_dspLDST_0(int iw0)2077*56bb7041Schristos decode_dspLDST_0 (int iw0)
2078*56bb7041Schristos {
2079*56bb7041Schristos   /* dspLDST
2080*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2081*56bb7041Schristos      | 1 | 0 | 0 | 1 | 1 | 1 |.W.|.aop...|.m.....|.i.....|.reg.......|
2082*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2083*56bb7041Schristos   int i   = ((iw0 >> DspLDST_i_bits) & DspLDST_i_mask);
2084*56bb7041Schristos   int m   = ((iw0 >> DspLDST_m_bits) & DspLDST_m_mask);
2085*56bb7041Schristos   int W   = ((iw0 >> DspLDST_W_bits) & DspLDST_W_mask);
2086*56bb7041Schristos   int aop = ((iw0 >> DspLDST_aop_bits) & DspLDST_aop_mask);
2087*56bb7041Schristos   int reg = ((iw0 >> DspLDST_reg_bits) & DspLDST_reg_mask);
2088*56bb7041Schristos 
2089*56bb7041Schristos   if (aop == 0 && W == 0 && m == 0)
2090*56bb7041Schristos     return DREG_MASK (reg) | IREG_MASK (i);
2091*56bb7041Schristos   else if (aop == 0 && W == 0 && m == 1)
2092*56bb7041Schristos     return DREGL_MASK (reg) | IREG_MASK (i);
2093*56bb7041Schristos   else if (aop == 0 && W == 0 && m == 2)
2094*56bb7041Schristos     return DREGH_MASK (reg) | IREG_MASK (i);
2095*56bb7041Schristos   else if (aop == 1 && W == 0 && m == 0)
2096*56bb7041Schristos     return DREG_MASK (reg) | IREG_MASK (i);
2097*56bb7041Schristos   else if (aop == 1 && W == 0 && m == 1)
2098*56bb7041Schristos     return DREGL_MASK (reg) | IREG_MASK (i);
2099*56bb7041Schristos   else if (aop == 1 && W == 0 && m == 2)
2100*56bb7041Schristos     return DREGH_MASK (reg) | IREG_MASK (i);
2101*56bb7041Schristos   else if (aop == 2 && W == 0 && m == 0)
2102*56bb7041Schristos     return DREG_MASK (reg);
2103*56bb7041Schristos   else if (aop == 2 && W == 0 && m == 1)
2104*56bb7041Schristos     return DREGL_MASK (reg);
2105*56bb7041Schristos   else if (aop == 2 && W == 0 && m == 2)
2106*56bb7041Schristos     return DREGH_MASK (reg);
2107*56bb7041Schristos   else if (aop == 0 && W == 1 && m == 0)
2108*56bb7041Schristos     return IREG_MASK (i);
2109*56bb7041Schristos   else if (aop == 0 && W == 1 && m == 1)
2110*56bb7041Schristos     return IREG_MASK (i);
2111*56bb7041Schristos   else if (aop == 0 && W == 1 && m == 2)
2112*56bb7041Schristos     return IREG_MASK (i);
2113*56bb7041Schristos   else if (aop == 1 && W == 1 && m == 0)
2114*56bb7041Schristos     return IREG_MASK (i);
2115*56bb7041Schristos   else if (aop == 1 && W == 1 && m == 1)
2116*56bb7041Schristos     return IREG_MASK (i);
2117*56bb7041Schristos   else if (aop == 1 && W == 1 && m == 2)
2118*56bb7041Schristos     return IREG_MASK (i);
2119*56bb7041Schristos   else if (aop == 2 && W == 1 && m == 0)
2120*56bb7041Schristos     return 0;
2121*56bb7041Schristos   else if (aop == 2 && W == 1 && m == 1)
2122*56bb7041Schristos     return 0;
2123*56bb7041Schristos   else if (aop == 2 && W == 1 && m == 2)
2124*56bb7041Schristos     return 0;
2125*56bb7041Schristos   else if (aop == 3 && W == 0)
2126*56bb7041Schristos     return DREG_MASK (reg) | IREG_MASK (i);
2127*56bb7041Schristos   else if (aop == 3 && W == 1)
2128*56bb7041Schristos     return IREG_MASK (i);
2129*56bb7041Schristos 
2130*56bb7041Schristos   abort ();
2131*56bb7041Schristos }
2132*56bb7041Schristos 
2133*56bb7041Schristos /* GOOD */
2134*56bb7041Schristos static int
decode_LDST_0(int iw0)2135*56bb7041Schristos decode_LDST_0 (int iw0)
2136*56bb7041Schristos {
2137*56bb7041Schristos   /* LDST
2138*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2139*56bb7041Schristos      | 1 | 0 | 0 | 1 |.sz....|.W.|.aop...|.Z.|.ptr.......|.reg.......|
2140*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2141*56bb7041Schristos   int Z   = ((iw0 >> LDST_Z_bits) & LDST_Z_mask);
2142*56bb7041Schristos   int W   = ((iw0 >> LDST_W_bits) & LDST_W_mask);
2143*56bb7041Schristos   int sz  = ((iw0 >> LDST_sz_bits) & LDST_sz_mask);
2144*56bb7041Schristos   int aop = ((iw0 >> LDST_aop_bits) & LDST_aop_mask);
2145*56bb7041Schristos   int reg = ((iw0 >> LDST_reg_bits) & LDST_reg_mask);
2146*56bb7041Schristos 
2147*56bb7041Schristos   if (aop == 0 && sz == 0 && Z == 0 && W == 0)
2148*56bb7041Schristos     return DREG_MASK (reg);
2149*56bb7041Schristos   else if (aop == 0 && sz == 0 && Z == 1 && W == 0)
2150*56bb7041Schristos     return 0;
2151*56bb7041Schristos   else if (aop == 0 && sz == 1 && Z == 0 && W == 0)
2152*56bb7041Schristos     return DREG_MASK (reg);
2153*56bb7041Schristos   else if (aop == 0 && sz == 1 && Z == 1 && W == 0)
2154*56bb7041Schristos     return DREG_MASK (reg);
2155*56bb7041Schristos   else if (aop == 0 && sz == 2 && Z == 0 && W == 0)
2156*56bb7041Schristos     return DREG_MASK (reg);
2157*56bb7041Schristos   else if (aop == 0 && sz == 2 && Z == 1 && W == 0)
2158*56bb7041Schristos     return DREG_MASK (reg);
2159*56bb7041Schristos   else if (aop == 1 && sz == 0 && Z == 0 && W == 0)
2160*56bb7041Schristos     return DREG_MASK (reg);
2161*56bb7041Schristos   else if (aop == 1 && sz == 0 && Z == 1 && W == 0)
2162*56bb7041Schristos     return 0;
2163*56bb7041Schristos   else if (aop == 1 && sz == 1 && Z == 0 && W == 0)
2164*56bb7041Schristos     return DREG_MASK (reg);
2165*56bb7041Schristos   else if (aop == 1 && sz == 1 && Z == 1 && W == 0)
2166*56bb7041Schristos     return DREG_MASK (reg);
2167*56bb7041Schristos   else if (aop == 1 && sz == 2 && Z == 0 && W == 0)
2168*56bb7041Schristos     return DREG_MASK (reg);
2169*56bb7041Schristos   else if (aop == 1 && sz == 2 && Z == 1 && W == 0)
2170*56bb7041Schristos     return DREG_MASK (reg);
2171*56bb7041Schristos   else if (aop == 2 && sz == 0 && Z == 0 && W == 0)
2172*56bb7041Schristos     return DREG_MASK (reg);
2173*56bb7041Schristos   else if (aop == 2 && sz == 0 && Z == 1 && W == 0)
2174*56bb7041Schristos     return 0;
2175*56bb7041Schristos   else if (aop == 2 && sz == 1 && Z == 0 && W == 0)
2176*56bb7041Schristos     return DREG_MASK (reg);
2177*56bb7041Schristos   else if (aop == 2 && sz == 1 && Z == 1 && W == 0)
2178*56bb7041Schristos     return DREG_MASK (reg);
2179*56bb7041Schristos   else if (aop == 2 && sz == 2 && Z == 0 && W == 0)
2180*56bb7041Schristos     return DREG_MASK (reg);
2181*56bb7041Schristos   else if (aop == 2 && sz == 2 && Z == 1 && W == 0)
2182*56bb7041Schristos     return DREG_MASK (reg);
2183*56bb7041Schristos   else if (aop == 0 && sz == 0 && Z == 0 && W == 1)
2184*56bb7041Schristos     return 0;
2185*56bb7041Schristos   else if (aop == 0 && sz == 0 && Z == 1 && W == 1)
2186*56bb7041Schristos     return 0;
2187*56bb7041Schristos   else if (aop == 0 && sz == 1 && Z == 0 && W == 1)
2188*56bb7041Schristos     return 0;
2189*56bb7041Schristos   else if (aop == 0 && sz == 2 && Z == 0 && W == 1)
2190*56bb7041Schristos     return 0;
2191*56bb7041Schristos   else if (aop == 1 && sz == 0 && Z == 0 && W == 1)
2192*56bb7041Schristos     return 0;
2193*56bb7041Schristos   else if (aop == 1 && sz == 0 && Z == 1 && W == 1)
2194*56bb7041Schristos     return 0;
2195*56bb7041Schristos   else if (aop == 1 && sz == 1 && Z == 0 && W == 1)
2196*56bb7041Schristos     return 0;
2197*56bb7041Schristos   else if (aop == 1 && sz == 2 && Z == 0 && W == 1)
2198*56bb7041Schristos     return 0;
2199*56bb7041Schristos   else if (aop == 2 && sz == 0 && Z == 0 && W == 1)
2200*56bb7041Schristos     return 0;
2201*56bb7041Schristos   else if (aop == 2 && sz == 0 && Z == 1 && W == 1)
2202*56bb7041Schristos     return 0;
2203*56bb7041Schristos   else if (aop == 2 && sz == 1 && Z == 0 && W == 1)
2204*56bb7041Schristos     return 0;
2205*56bb7041Schristos   else if (aop == 2 && sz == 2 && Z == 0 && W == 1)
2206*56bb7041Schristos     return 0;
2207*56bb7041Schristos 
2208*56bb7041Schristos   abort ();
2209*56bb7041Schristos }
2210*56bb7041Schristos 
2211*56bb7041Schristos static int
decode_LDSTiiFP_0(int iw0)2212*56bb7041Schristos decode_LDSTiiFP_0 (int iw0)
2213*56bb7041Schristos {
2214*56bb7041Schristos   /* LDSTiiFP
2215*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2216*56bb7041Schristos      | 1 | 0 | 1 | 1 | 1 | 0 |.W.|.offset............|.reg...........|
2217*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2218*56bb7041Schristos   int reg = ((iw0 >> LDSTiiFP_reg_bits) & LDSTiiFP_reg_mask);
2219*56bb7041Schristos   int W = ((iw0 >> LDSTiiFP_W_bits) & LDSTiiFP_W_mask);
2220*56bb7041Schristos 
2221*56bb7041Schristos   if (W == 0)
2222*56bb7041Schristos     return reg < 8 ? DREG_MASK (reg) : 0;
2223*56bb7041Schristos   else
2224*56bb7041Schristos     return 0;
2225*56bb7041Schristos }
2226*56bb7041Schristos 
2227*56bb7041Schristos static int
decode_LDSTii_0(int iw0)2228*56bb7041Schristos decode_LDSTii_0 (int iw0)
2229*56bb7041Schristos {
2230*56bb7041Schristos   /* LDSTii
2231*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2232*56bb7041Schristos      | 1 | 0 | 1 |.W.|.op....|.offset........|.ptr.......|.reg.......|
2233*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2234*56bb7041Schristos   int reg = ((iw0 >> LDSTii_reg_bit) & LDSTii_reg_mask);
2235*56bb7041Schristos   int opc = ((iw0 >> LDSTii_op_bit) & LDSTii_op_mask);
2236*56bb7041Schristos   int W = ((iw0 >> LDSTii_W_bit) & LDSTii_W_mask);
2237*56bb7041Schristos 
2238*56bb7041Schristos   if (W == 0 && opc != 3)
2239*56bb7041Schristos     return DREG_MASK (reg);
2240*56bb7041Schristos   else if (W == 0 && opc == 3)
2241*56bb7041Schristos    return 0;
2242*56bb7041Schristos   else if (W == 1 && opc == 0)
2243*56bb7041Schristos     return 0;
2244*56bb7041Schristos   else if (W == 1 && opc == 1)
2245*56bb7041Schristos     return 0;
2246*56bb7041Schristos   else if (W == 1 && opc == 3)
2247*56bb7041Schristos     return 0;
2248*56bb7041Schristos 
2249*56bb7041Schristos   abort ();
2250*56bb7041Schristos }
2251*56bb7041Schristos 
2252*56bb7041Schristos static int
decode_dsp32mac_0(int iw0,int iw1)2253*56bb7041Schristos decode_dsp32mac_0 (int iw0, int iw1)
2254*56bb7041Schristos {
2255*56bb7041Schristos   int result = 0;
2256*56bb7041Schristos   /* dsp32mac
2257*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2258*56bb7041Schristos      | 1 | 1 | 0 | 0 |.M.| 0 | 0 |.mmod..........|.MM|.P.|.w1|.op1...|
2259*56bb7041Schristos      |.h01|.h11|.w0|.op0...|.h00|.h10|.dst.......|.src0......|.src1..|
2260*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2261*56bb7041Schristos   int op1  = ((iw0 >> (DSP32Mac_op1_bits - 16)) & DSP32Mac_op1_mask);
2262*56bb7041Schristos   int w1   = ((iw0 >> (DSP32Mac_w1_bits - 16)) & DSP32Mac_w1_mask);
2263*56bb7041Schristos   int P    = ((iw0 >> (DSP32Mac_p_bits - 16)) & DSP32Mac_p_mask);
2264*56bb7041Schristos   int mmod = ((iw0 >> (DSP32Mac_mmod_bits - 16)) & DSP32Mac_mmod_mask);
2265*56bb7041Schristos   int w0   = ((iw1 >> DSP32Mac_w0_bits) & DSP32Mac_w0_mask);
2266*56bb7041Schristos   int MM   = ((iw1 >> DSP32Mac_MM_bits) & DSP32Mac_MM_mask);
2267*56bb7041Schristos   int dst  = ((iw1 >> DSP32Mac_dst_bits) & DSP32Mac_dst_mask);
2268*56bb7041Schristos   int op0  = ((iw1 >> DSP32Mac_op0_bits) & DSP32Mac_op0_mask);
2269*56bb7041Schristos 
2270*56bb7041Schristos   if (w0 == 0 && w1 == 0 && op1 == 3 && op0 == 3)
2271*56bb7041Schristos     return 0;
2272*56bb7041Schristos 
2273*56bb7041Schristos   if (op1 == 3 && MM)
2274*56bb7041Schristos     return 0;
2275*56bb7041Schristos 
2276*56bb7041Schristos   if ((w1 || w0) && mmod == M_W32)
2277*56bb7041Schristos     return 0;
2278*56bb7041Schristos 
2279*56bb7041Schristos   if (((1 << mmod) & (P ? 0x131b : 0x1b5f)) == 0)
2280*56bb7041Schristos     return 0;
2281*56bb7041Schristos 
2282*56bb7041Schristos   if (w1 == 1 || op1 != 3)
2283*56bb7041Schristos     {
2284*56bb7041Schristos       if (w1)
2285*56bb7041Schristos 	{
2286*56bb7041Schristos 	  if (P)
2287*56bb7041Schristos 	    return DREG_MASK (dst + 1);
2288*56bb7041Schristos 	  else
2289*56bb7041Schristos 	    return DREGH_MASK (dst);
2290*56bb7041Schristos 	}
2291*56bb7041Schristos     }
2292*56bb7041Schristos 
2293*56bb7041Schristos   if (w0 == 1 || op0 != 3)
2294*56bb7041Schristos     {
2295*56bb7041Schristos       if (w0)
2296*56bb7041Schristos 	{
2297*56bb7041Schristos 	  if (P)
2298*56bb7041Schristos 	    return DREG_MASK (dst);
2299*56bb7041Schristos 	  else
2300*56bb7041Schristos 	    return DREGL_MASK (dst);
2301*56bb7041Schristos 	}
2302*56bb7041Schristos     }
2303*56bb7041Schristos 
2304*56bb7041Schristos   return result;
2305*56bb7041Schristos }
2306*56bb7041Schristos 
2307*56bb7041Schristos static int
decode_dsp32mult_0(int iw0,int iw1)2308*56bb7041Schristos decode_dsp32mult_0 (int iw0, int iw1)
2309*56bb7041Schristos {
2310*56bb7041Schristos   /* dsp32mult
2311*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2312*56bb7041Schristos      | 1 | 1 | 0 | 0 |.M.| 0 | 1 |.mmod..........|.MM|.P.|.w1|.op1...|
2313*56bb7041Schristos      |.h01|.h11|.w0|.op0...|.h00|.h10|.dst.......|.src0......|.src1..|
2314*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2315*56bb7041Schristos   int w1   = ((iw0 >> (DSP32Mac_w1_bits - 16)) & DSP32Mac_w1_mask);
2316*56bb7041Schristos   int P    = ((iw0 >> (DSP32Mac_p_bits - 16)) & DSP32Mac_p_mask);
2317*56bb7041Schristos   int mmod = ((iw0 >> (DSP32Mac_mmod_bits - 16)) & DSP32Mac_mmod_mask);
2318*56bb7041Schristos   int w0   = ((iw1 >> DSP32Mac_w0_bits) & DSP32Mac_w0_mask);
2319*56bb7041Schristos   int dst  = ((iw1 >> DSP32Mac_dst_bits) & DSP32Mac_dst_mask);
2320*56bb7041Schristos   int result = 0;
2321*56bb7041Schristos 
2322*56bb7041Schristos   if (w1 == 0 && w0 == 0)
2323*56bb7041Schristos     return 0;
2324*56bb7041Schristos 
2325*56bb7041Schristos   if (((1 << mmod) & (P ? 0x313 : 0x1b57)) == 0)
2326*56bb7041Schristos     return 0;
2327*56bb7041Schristos 
2328*56bb7041Schristos   if (w1)
2329*56bb7041Schristos     {
2330*56bb7041Schristos       if (P)
2331*56bb7041Schristos 	return DREG_MASK (dst | 1);
2332*56bb7041Schristos       else
2333*56bb7041Schristos 	return DREGH_MASK (dst);
2334*56bb7041Schristos     }
2335*56bb7041Schristos 
2336*56bb7041Schristos   if (w0)
2337*56bb7041Schristos     {
2338*56bb7041Schristos       if (P)
2339*56bb7041Schristos 	return DREG_MASK (dst);
2340*56bb7041Schristos       else
2341*56bb7041Schristos 	return DREGL_MASK (dst);
2342*56bb7041Schristos     }
2343*56bb7041Schristos 
2344*56bb7041Schristos   return result;
2345*56bb7041Schristos }
2346*56bb7041Schristos 
2347*56bb7041Schristos static int
decode_dsp32alu_0(int iw0,int iw1)2348*56bb7041Schristos decode_dsp32alu_0 (int iw0, int iw1)
2349*56bb7041Schristos {
2350*56bb7041Schristos   /* dsp32alu
2351*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2352*56bb7041Schristos      | 1 | 1 | 0 | 0 |.M.| 1 | 0 | - | - | - |.HL|.aopcde............|
2353*56bb7041Schristos      |.aop...|.s.|.x.|.dst0......|.dst1......|.src0......|.src1......|
2354*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2355*56bb7041Schristos   int s    = ((iw1 >> DSP32Alu_s_bits) & DSP32Alu_s_mask);
2356*56bb7041Schristos   int x    = ((iw1 >> DSP32Alu_x_bits) & DSP32Alu_x_mask);
2357*56bb7041Schristos   int aop  = ((iw1 >> DSP32Alu_aop_bits) & DSP32Alu_aop_mask);
2358*56bb7041Schristos   int dst0 = ((iw1 >> DSP32Alu_dst0_bits) & DSP32Alu_dst0_mask);
2359*56bb7041Schristos   int dst1 = ((iw1 >> DSP32Alu_dst1_bits) & DSP32Alu_dst1_mask);
2360*56bb7041Schristos   int HL   = ((iw0 >> (DSP32Alu_HL_bits - 16)) & DSP32Alu_HL_mask);
2361*56bb7041Schristos   int aopcde = ((iw0 >> (DSP32Alu_aopcde_bits - 16)) & DSP32Alu_aopcde_mask);
2362*56bb7041Schristos 
2363*56bb7041Schristos   if (aop == 0 && aopcde == 9 && s == 0)
2364*56bb7041Schristos     return 0;
2365*56bb7041Schristos   else if (aop == 2 && aopcde == 9 && HL == 0 && s == 0)
2366*56bb7041Schristos     return 0;
2367*56bb7041Schristos   else if (aop >= x * 2 && aopcde == 5)
2368*56bb7041Schristos     return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2369*56bb7041Schristos   else if (HL == 0 && aopcde == 2)
2370*56bb7041Schristos     return DREGL_MASK (dst0);
2371*56bb7041Schristos   else if (HL == 1 && aopcde == 2)
2372*56bb7041Schristos     return DREGH_MASK (dst0);
2373*56bb7041Schristos   else if (HL == 0 && aopcde == 3)
2374*56bb7041Schristos     return DREGL_MASK (dst0);
2375*56bb7041Schristos   else if (HL == 1 && aopcde == 3)
2376*56bb7041Schristos     return DREGH_MASK (dst0);
2377*56bb7041Schristos 
2378*56bb7041Schristos   else if (aop == 0 && aopcde == 9 && s == 1)
2379*56bb7041Schristos     return 0;
2380*56bb7041Schristos   else if (aop == 1 && aopcde == 9 && s == 0)
2381*56bb7041Schristos     return 0;
2382*56bb7041Schristos   else if (aop == 2 && aopcde == 9 && s == 1)
2383*56bb7041Schristos     return 0;
2384*56bb7041Schristos   else if (aop == 3 && aopcde == 9 && s == 0)
2385*56bb7041Schristos     return 0;
2386*56bb7041Schristos   else if (aopcde == 8)
2387*56bb7041Schristos     return 0;
2388*56bb7041Schristos   else if (aop == 0 && aopcde == 11)
2389*56bb7041Schristos     return DREG_MASK (dst0);
2390*56bb7041Schristos   else if (aop == 1 && aopcde == 11)
2391*56bb7041Schristos     return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2392*56bb7041Schristos   else if (aopcde == 11)
2393*56bb7041Schristos     return 0;
2394*56bb7041Schristos   else if (aopcde == 22)
2395*56bb7041Schristos     return DREG_MASK (dst0);
2396*56bb7041Schristos 
2397*56bb7041Schristos   else if ((aop == 0 || aop == 1) && aopcde == 14)
2398*56bb7041Schristos     return 0;
2399*56bb7041Schristos   else if (aop == 3 && HL == 0 && aopcde == 14)
2400*56bb7041Schristos     return 0;
2401*56bb7041Schristos 
2402*56bb7041Schristos   else if (aop == 3 && HL == 0 && aopcde == 15)
2403*56bb7041Schristos     return DREG_MASK (dst0);
2404*56bb7041Schristos 
2405*56bb7041Schristos   else if (aop == 1 && aopcde == 16)
2406*56bb7041Schristos     return 0;
2407*56bb7041Schristos 
2408*56bb7041Schristos   else if (aop == 0 && aopcde == 16)
2409*56bb7041Schristos     return 0;
2410*56bb7041Schristos 
2411*56bb7041Schristos   else if (aop == 3 && HL == 0 && aopcde == 16)
2412*56bb7041Schristos     return 0;
2413*56bb7041Schristos 
2414*56bb7041Schristos   else if (aop == 3 && HL == 0 && aopcde == 7)
2415*56bb7041Schristos     return DREG_MASK (dst0);
2416*56bb7041Schristos   else if ((aop == 0 || aop == 1 || aop == 2) && aopcde == 7)
2417*56bb7041Schristos     return DREG_MASK (dst0);
2418*56bb7041Schristos 
2419*56bb7041Schristos   else if (aop == 0 && aopcde == 12)
2420*56bb7041Schristos     return DREG_MASK (dst0);
2421*56bb7041Schristos   else if (aop == 1 && aopcde == 12)
2422*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2423*56bb7041Schristos   else if (aop == 3 && aopcde == 12)
2424*56bb7041Schristos     return HL ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2425*56bb7041Schristos 
2426*56bb7041Schristos   else if (aopcde == 0)
2427*56bb7041Schristos     return DREG_MASK (dst0);
2428*56bb7041Schristos   else if (aopcde == 1)
2429*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2430*56bb7041Schristos 
2431*56bb7041Schristos   else if (aop == 0 && aopcde == 10)
2432*56bb7041Schristos     return DREGL_MASK (dst0);
2433*56bb7041Schristos   else if (aop == 1 && aopcde == 10)
2434*56bb7041Schristos     return DREGL_MASK (dst0);
2435*56bb7041Schristos 
2436*56bb7041Schristos   else if ((aop == 1 || aop == 0) && aopcde == 4)
2437*56bb7041Schristos     return DREG_MASK (dst0);
2438*56bb7041Schristos   else if (aop == 2 && aopcde == 4)
2439*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2440*56bb7041Schristos 
2441*56bb7041Schristos   else if (aop == 0 && aopcde == 17)
2442*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2443*56bb7041Schristos   else if (aop == 1 && aopcde == 17)
2444*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2445*56bb7041Schristos   else if (aop == 0 && aopcde == 18)
2446*56bb7041Schristos     return 0;
2447*56bb7041Schristos   else if (aop == 3 && aopcde == 18)
2448*56bb7041Schristos     return 0;
2449*56bb7041Schristos 
2450*56bb7041Schristos   else if ((aop == 0 || aop == 1 || aop == 2) && aopcde == 6)
2451*56bb7041Schristos     return DREG_MASK (dst0);
2452*56bb7041Schristos 
2453*56bb7041Schristos   else if ((aop == 0 || aop == 1) && aopcde == 20)
2454*56bb7041Schristos     return DREG_MASK (dst0);
2455*56bb7041Schristos 
2456*56bb7041Schristos   else if ((aop == 0 || aop == 1) && aopcde == 21)
2457*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2458*56bb7041Schristos 
2459*56bb7041Schristos   else if (aop == 0 && aopcde == 23 && HL == 1)
2460*56bb7041Schristos     return DREG_MASK (dst0);
2461*56bb7041Schristos   else if (aop == 0 && aopcde == 23 && HL == 0)
2462*56bb7041Schristos     return DREG_MASK (dst0);
2463*56bb7041Schristos 
2464*56bb7041Schristos   else if (aop == 0 && aopcde == 24)
2465*56bb7041Schristos     return DREG_MASK (dst0);
2466*56bb7041Schristos   else if (aop == 1 && aopcde == 24)
2467*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2468*56bb7041Schristos   else if (aopcde == 13)
2469*56bb7041Schristos     return DREG_MASK (dst0) | DREG_MASK (dst1);
2470*56bb7041Schristos   else
2471*56bb7041Schristos     return 0;
2472*56bb7041Schristos 
2473*56bb7041Schristos   return 4;
2474*56bb7041Schristos }
2475*56bb7041Schristos 
2476*56bb7041Schristos static int
decode_dsp32shift_0(int iw0,int iw1)2477*56bb7041Schristos decode_dsp32shift_0 (int iw0, int iw1)
2478*56bb7041Schristos {
2479*56bb7041Schristos   /* dsp32shift
2480*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2481*56bb7041Schristos      | 1 | 1 | 0 | 0 |.M.| 1 | 1 | 0 | 0 | - | - |.sopcde............|
2482*56bb7041Schristos      |.sop...|.HLs...|.dst0......| - | - | - |.src0......|.src1......|
2483*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2484*56bb7041Schristos   int HLs  = ((iw1 >> DSP32Shift_HLs_bits) & DSP32Shift_HLs_mask);
2485*56bb7041Schristos   int sop  = ((iw1 >> DSP32Shift_sop_bits) & DSP32Shift_sop_mask);
2486*56bb7041Schristos   int src0 = ((iw1 >> DSP32Shift_src0_bits) & DSP32Shift_src0_mask);
2487*56bb7041Schristos   int src1 = ((iw1 >> DSP32Shift_src1_bits) & DSP32Shift_src1_mask);
2488*56bb7041Schristos   int dst0 = ((iw1 >> DSP32Shift_dst0_bits) & DSP32Shift_dst0_mask);
2489*56bb7041Schristos   int sopcde = ((iw0 >> (DSP32Shift_sopcde_bits - 16)) & DSP32Shift_sopcde_mask);
2490*56bb7041Schristos 
2491*56bb7041Schristos   if (sop == 0 && sopcde == 0)
2492*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2493*56bb7041Schristos   else if (sop == 1 && sopcde == 0)
2494*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2495*56bb7041Schristos   else if (sop == 2 && sopcde == 0)
2496*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2497*56bb7041Schristos   else if (sop == 0 && sopcde == 3)
2498*56bb7041Schristos     return 0;
2499*56bb7041Schristos   else if (sop == 1 && sopcde == 3)
2500*56bb7041Schristos     return 0;
2501*56bb7041Schristos   else if (sop == 2 && sopcde == 3)
2502*56bb7041Schristos     return 0;
2503*56bb7041Schristos   else if (sop == 3 && sopcde == 3)
2504*56bb7041Schristos     return DREG_MASK (dst0);
2505*56bb7041Schristos   else if (sop == 0 && sopcde == 1)
2506*56bb7041Schristos     return DREG_MASK (dst0);
2507*56bb7041Schristos   else if (sop == 1 && sopcde == 1)
2508*56bb7041Schristos     return DREG_MASK (dst0);
2509*56bb7041Schristos   else if (sop == 2 && sopcde == 1)
2510*56bb7041Schristos     return DREG_MASK (dst0);
2511*56bb7041Schristos   else if (sopcde == 2)
2512*56bb7041Schristos     return DREG_MASK (dst0);
2513*56bb7041Schristos   else if (sopcde == 4)
2514*56bb7041Schristos     return DREG_MASK (dst0);
2515*56bb7041Schristos   else if (sop == 0 && sopcde == 5)
2516*56bb7041Schristos     return DREGL_MASK (dst0);
2517*56bb7041Schristos   else if (sop == 1 && sopcde == 5)
2518*56bb7041Schristos     return DREGL_MASK (dst0);
2519*56bb7041Schristos   else if (sop == 2 && sopcde == 5)
2520*56bb7041Schristos     return DREGL_MASK (dst0);
2521*56bb7041Schristos   else if (sop == 0 && sopcde == 6)
2522*56bb7041Schristos     return DREGL_MASK (dst0);
2523*56bb7041Schristos   else if (sop == 1 && sopcde == 6)
2524*56bb7041Schristos     return DREGL_MASK (dst0);
2525*56bb7041Schristos   else if (sop == 3 && sopcde == 6)
2526*56bb7041Schristos     return DREGL_MASK (dst0);
2527*56bb7041Schristos   else if (sop == 0 && sopcde == 7)
2528*56bb7041Schristos     return DREGL_MASK (dst0);
2529*56bb7041Schristos   else if (sop == 1 && sopcde == 7)
2530*56bb7041Schristos     return DREGL_MASK (dst0);
2531*56bb7041Schristos   else if (sop == 2 && sopcde == 7)
2532*56bb7041Schristos     return DREGL_MASK (dst0);
2533*56bb7041Schristos   else if (sop == 3 && sopcde == 7)
2534*56bb7041Schristos     return DREGL_MASK (dst0);
2535*56bb7041Schristos   else if (sop == 0 && sopcde == 8)
2536*56bb7041Schristos     return DREG_MASK (src0) | DREG_MASK (src1);
2537*56bb7041Schristos #if 0
2538*56bb7041Schristos     {
2539*56bb7041Schristos       OUTS (outf, "BITMUX (");
2540*56bb7041Schristos       OUTS (outf, dregs (src0));
2541*56bb7041Schristos       OUTS (outf, ", ");
2542*56bb7041Schristos       OUTS (outf, dregs (src1));
2543*56bb7041Schristos       OUTS (outf, ", A0) (ASR)");
2544*56bb7041Schristos     }
2545*56bb7041Schristos #endif
2546*56bb7041Schristos   else if (sop == 1 && sopcde == 8)
2547*56bb7041Schristos     return DREG_MASK (src0) | DREG_MASK (src1);
2548*56bb7041Schristos #if 0
2549*56bb7041Schristos     {
2550*56bb7041Schristos       OUTS (outf, "BITMUX (");
2551*56bb7041Schristos       OUTS (outf, dregs (src0));
2552*56bb7041Schristos       OUTS (outf, ", ");
2553*56bb7041Schristos       OUTS (outf, dregs (src1));
2554*56bb7041Schristos       OUTS (outf, ", A0) (ASL)");
2555*56bb7041Schristos     }
2556*56bb7041Schristos #endif
2557*56bb7041Schristos   else if (sopcde == 9)
2558*56bb7041Schristos     return sop < 2 ? DREGL_MASK (dst0) : DREG_MASK (dst0);
2559*56bb7041Schristos   else if (sopcde == 10)
2560*56bb7041Schristos     return DREG_MASK (dst0);
2561*56bb7041Schristos   else if (sop == 0 && sopcde == 11)
2562*56bb7041Schristos     return DREGL_MASK (dst0);
2563*56bb7041Schristos   else if (sop == 1 && sopcde == 11)
2564*56bb7041Schristos     return DREGL_MASK (dst0);
2565*56bb7041Schristos   else if (sop == 0 && sopcde == 12)
2566*56bb7041Schristos     return 0;
2567*56bb7041Schristos   else if (sop == 1 && sopcde == 12)
2568*56bb7041Schristos     return DREGL_MASK (dst0);
2569*56bb7041Schristos   else if (sop == 0 && sopcde == 13)
2570*56bb7041Schristos     return DREG_MASK (dst0);
2571*56bb7041Schristos   else if (sop == 1 && sopcde == 13)
2572*56bb7041Schristos     return DREG_MASK (dst0);
2573*56bb7041Schristos   else if (sop == 2 && sopcde == 13)
2574*56bb7041Schristos     return DREG_MASK (dst0);
2575*56bb7041Schristos 
2576*56bb7041Schristos   abort ();
2577*56bb7041Schristos }
2578*56bb7041Schristos 
2579*56bb7041Schristos static int
decode_dsp32shiftimm_0(int iw0,int iw1)2580*56bb7041Schristos decode_dsp32shiftimm_0 (int iw0, int iw1)
2581*56bb7041Schristos {
2582*56bb7041Schristos   /* dsp32shiftimm
2583*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+
2584*56bb7041Schristos      | 1 | 1 | 0 | 0 |.M.| 1 | 1 | 0 | 1 | - | - |.sopcde............|
2585*56bb7041Schristos      |.sop...|.HLs...|.dst0......|.immag.................|.src1......|
2586*56bb7041Schristos      +---+---+---+---|---+---+---+---|---+---+---+---|---+---+---+---+  */
2587*56bb7041Schristos   int sop      = ((iw1 >> DSP32ShiftImm_sop_bits) & DSP32ShiftImm_sop_mask);
2588*56bb7041Schristos   int bit8     = ((iw1 >> 8) & 0x1);
2589*56bb7041Schristos   int dst0     = ((iw1 >> DSP32ShiftImm_dst0_bits) & DSP32ShiftImm_dst0_mask);
2590*56bb7041Schristos   int sopcde   = ((iw0 >> (DSP32ShiftImm_sopcde_bits - 16)) & DSP32ShiftImm_sopcde_mask);
2591*56bb7041Schristos   int HLs      = ((iw1 >> DSP32ShiftImm_HLs_bits) & DSP32ShiftImm_HLs_mask);
2592*56bb7041Schristos 
2593*56bb7041Schristos 
2594*56bb7041Schristos   if (sop == 0 && sopcde == 0)
2595*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2596*56bb7041Schristos   else if (sop == 1 && sopcde == 0 && bit8 == 0)
2597*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2598*56bb7041Schristos   else if (sop == 1 && sopcde == 0 && bit8 == 1)
2599*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2600*56bb7041Schristos   else if (sop == 2 && sopcde == 0 && bit8 == 0)
2601*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2602*56bb7041Schristos   else if (sop == 2 && sopcde == 0 && bit8 == 1)
2603*56bb7041Schristos     return HLs & 2 ? DREGH_MASK (dst0) : DREGL_MASK (dst0);
2604*56bb7041Schristos   else if (sop == 2 && sopcde == 3 && HLs == 1)
2605*56bb7041Schristos     return 0;
2606*56bb7041Schristos   else if (sop == 0 && sopcde == 3 && HLs == 0 && bit8 == 0)
2607*56bb7041Schristos     return 0;
2608*56bb7041Schristos   else if (sop == 0 && sopcde == 3 && HLs == 0 && bit8 == 1)
2609*56bb7041Schristos     return 0;
2610*56bb7041Schristos   else if (sop == 0 && sopcde == 3 && HLs == 1 && bit8 == 0)
2611*56bb7041Schristos     return 0;
2612*56bb7041Schristos   else if (sop == 0 && sopcde == 3 && HLs == 1 && bit8 == 1)
2613*56bb7041Schristos     return 0;
2614*56bb7041Schristos   else if (sop == 1 && sopcde == 3 && HLs == 0)
2615*56bb7041Schristos     return 0;
2616*56bb7041Schristos   else if (sop == 1 && sopcde == 3 && HLs == 1)
2617*56bb7041Schristos     return 0;
2618*56bb7041Schristos   else if (sop == 2 && sopcde == 3 && HLs == 0)
2619*56bb7041Schristos     return 0;
2620*56bb7041Schristos   else if (sop == 1 && sopcde == 1 && bit8 == 0)
2621*56bb7041Schristos     return DREG_MASK (dst0);
2622*56bb7041Schristos   else if (sop == 1 && sopcde == 1 && bit8 == 1)
2623*56bb7041Schristos     return DREG_MASK (dst0);
2624*56bb7041Schristos   else if (sop == 2 && sopcde == 1 && bit8 == 1)
2625*56bb7041Schristos     return DREG_MASK (dst0);
2626*56bb7041Schristos   else if (sop == 2 && sopcde == 1 && bit8 == 0)
2627*56bb7041Schristos     return DREG_MASK (dst0);
2628*56bb7041Schristos   else if (sop == 0 && sopcde == 1)
2629*56bb7041Schristos     return DREG_MASK (dst0);
2630*56bb7041Schristos   else if (sop == 1 && sopcde == 2)
2631*56bb7041Schristos     return DREG_MASK (dst0);
2632*56bb7041Schristos   else if (sop == 2 && sopcde == 2 && bit8 == 1)
2633*56bb7041Schristos     return DREG_MASK (dst0);
2634*56bb7041Schristos   else if (sop == 2 && sopcde == 2 && bit8 == 0)
2635*56bb7041Schristos     return DREG_MASK (dst0);
2636*56bb7041Schristos   else if (sop == 3 && sopcde == 2)
2637*56bb7041Schristos     return DREG_MASK (dst0);
2638*56bb7041Schristos   else if (sop == 0 && sopcde == 2)
2639*56bb7041Schristos     return DREG_MASK (dst0);
2640*56bb7041Schristos 
2641*56bb7041Schristos   abort ();
2642*56bb7041Schristos }
2643*56bb7041Schristos 
2644*56bb7041Schristos int
insn_regmask(int iw0,int iw1)2645*56bb7041Schristos insn_regmask (int iw0, int iw1)
2646*56bb7041Schristos {
2647*56bb7041Schristos   if ((iw0 & 0xf7ff) == 0xc003 && iw1 == 0x1800)
2648*56bb7041Schristos     return 0; /* MNOP */
2649*56bb7041Schristos   else if ((iw0 & 0xff00) == 0x0000)
2650*56bb7041Schristos     return decode_ProgCtrl_0 (iw0);
2651*56bb7041Schristos   else if ((iw0 & 0xffc0) == 0x0240)
2652*56bb7041Schristos     abort ();
2653*56bb7041Schristos   else if ((iw0 & 0xff80) == 0x0100)
2654*56bb7041Schristos     abort ();
2655*56bb7041Schristos   else if ((iw0 & 0xfe00) == 0x0400)
2656*56bb7041Schristos     abort ();
2657*56bb7041Schristos   else if ((iw0 & 0xfe00) == 0x0600)
2658*56bb7041Schristos     abort ();
2659*56bb7041Schristos   else if ((iw0 & 0xf800) == 0x0800)
2660*56bb7041Schristos     abort ();
2661*56bb7041Schristos   else if ((iw0 & 0xffe0) == 0x0200)
2662*56bb7041Schristos     abort ();
2663*56bb7041Schristos   else if ((iw0 & 0xff00) == 0x0300)
2664*56bb7041Schristos     abort ();
2665*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x1000)
2666*56bb7041Schristos     abort ();
2667*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x2000)
2668*56bb7041Schristos     abort ();
2669*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x3000)
2670*56bb7041Schristos     abort ();
2671*56bb7041Schristos   else if ((iw0 & 0xfc00) == 0x4000)
2672*56bb7041Schristos     abort ();
2673*56bb7041Schristos   else if ((iw0 & 0xfe00) == 0x4400)
2674*56bb7041Schristos     abort ();
2675*56bb7041Schristos   else if ((iw0 & 0xf800) == 0x4800)
2676*56bb7041Schristos     abort ();
2677*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x5000)
2678*56bb7041Schristos     abort ();
2679*56bb7041Schristos   else if ((iw0 & 0xf800) == 0x6000)
2680*56bb7041Schristos     abort ();
2681*56bb7041Schristos   else if ((iw0 & 0xf800) == 0x6800)
2682*56bb7041Schristos     abort ();
2683*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x8000)
2684*56bb7041Schristos     return decode_LDSTpmod_0 (iw0);
2685*56bb7041Schristos   else if ((iw0 & 0xff60) == 0x9e60)
2686*56bb7041Schristos     return decode_dagMODim_0 (iw0);
2687*56bb7041Schristos   else if ((iw0 & 0xfff0) == 0x9f60)
2688*56bb7041Schristos     return decode_dagMODik_0 (iw0);
2689*56bb7041Schristos   else if ((iw0 & 0xfc00) == 0x9c00)
2690*56bb7041Schristos     return decode_dspLDST_0 (iw0);
2691*56bb7041Schristos   else if ((iw0 & 0xf000) == 0x9000)
2692*56bb7041Schristos     return decode_LDST_0 (iw0);
2693*56bb7041Schristos   else if ((iw0 & 0xfc00) == 0xb800)
2694*56bb7041Schristos     return decode_LDSTiiFP_0 (iw0);
2695*56bb7041Schristos   else if ((iw0 & 0xe000) == 0xA000)
2696*56bb7041Schristos     return decode_LDSTii_0 (iw0);
2697*56bb7041Schristos   else if ((iw0 & 0xff80) == 0xe080 && (iw1 & 0x0C00) == 0x0000)
2698*56bb7041Schristos     abort ();
2699*56bb7041Schristos   else if ((iw0 & 0xff00) == 0xe100 && (iw1 & 0x0000) == 0x0000)
2700*56bb7041Schristos     abort ();
2701*56bb7041Schristos   else if ((iw0 & 0xfe00) == 0xe200 && (iw1 & 0x0000) == 0x0000)
2702*56bb7041Schristos     abort ();
2703*56bb7041Schristos   else if ((iw0 & 0xfc00) == 0xe400 && (iw1 & 0x0000) == 0x0000)
2704*56bb7041Schristos     abort ();
2705*56bb7041Schristos   else if ((iw0 & 0xfffe) == 0xe800 && (iw1 & 0x0000) == 0x0000)
2706*56bb7041Schristos     abort ();
2707*56bb7041Schristos   else if ((iw0 & 0xf600) == 0xc000 && (iw1 & 0x0000) == 0x0000)
2708*56bb7041Schristos     return decode_dsp32mac_0 (iw0, iw1);
2709*56bb7041Schristos   else if ((iw0 & 0xf600) == 0xc200 && (iw1 & 0x0000) == 0x0000)
2710*56bb7041Schristos     return decode_dsp32mult_0 (iw0, iw1);
2711*56bb7041Schristos   else if ((iw0 & 0xf7c0) == 0xc400 && (iw1 & 0x0000) == 0x0000)
2712*56bb7041Schristos     return decode_dsp32alu_0 (iw0, iw1);
2713*56bb7041Schristos   else if ((iw0 & 0xf780) == 0xc600 && (iw1 & 0x01c0) == 0x0000)
2714*56bb7041Schristos     return decode_dsp32shift_0 (iw0, iw1);
2715*56bb7041Schristos   else if ((iw0 & 0xf780) == 0xc680 && (iw1 & 0x0000) == 0x0000)
2716*56bb7041Schristos     return decode_dsp32shiftimm_0 (iw0, iw1);
2717*56bb7041Schristos   else if ((iw0 & 0xff00) == 0xf800)
2718*56bb7041Schristos     abort ();
2719*56bb7041Schristos   else if ((iw0 & 0xFFC0) == 0xf000 && (iw1 & 0x0000) == 0x0000)
2720*56bb7041Schristos     abort ();
2721*56bb7041Schristos 
2722*56bb7041Schristos   abort ();
2723*56bb7041Schristos }
2724