1 /* tc-m68k.c -- Assemble for the m68k family
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #include "as.h"
23 #include "safe-ctype.h"
24 #include "obstack.h"
25 #include "subsegs.h"
26 #include "dwarf2dbg.h"
27 #include "dw2gencfi.h"
28
29 #include "opcode/m68k.h"
30 #include "m68k-parse.h"
31
32 #if defined (OBJ_ELF)
33 #include "elf/m68k.h"
34 #endif
35
36 #ifdef M68KCOFF
37 #include "obj-coff.h"
38 #endif
39
40 /* This string holds the chars that always start a comment. If the
41 pre-processor is disabled, these aren't very useful. The macro
42 tc_comment_chars points to this. We use this, rather than the
43 usual comment_chars, so that the --bitwise-or option will work. */
44 #if defined (TE_SVR4) || defined (TE_DELTA)
45 const char *m68k_comment_chars = "|#";
46 #else
47 const char *m68k_comment_chars = "|";
48 #endif
49
50 /* This array holds the chars that only start a comment at the beginning of
51 a line. If the line seems to have the form '# 123 filename'
52 .line and .file directives will appear in the pre-processed output */
53 /* Note that input_file.c hand checks for '#' at the beginning of the
54 first line of the input file. This is because the compiler outputs
55 #NO_APP at the beginning of its output. */
56 /* Also note that comments like this one will always work. */
57 const char line_comment_chars[] = "#*";
58
59 const char line_separator_chars[] = ";";
60
61 /* Chars that can be used to separate mant from exp in floating point nums. */
62 const char EXP_CHARS[] = "eE";
63
64 /* Chars that mean this number is a floating point constant, as
65 in "0f12.456" or "0d1.2345e12". */
66
67 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
68
69 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
70 changed in read.c . Ideally it shouldn't have to know about it at all,
71 but nothing is ideal around here. */
72
73 const int md_reloc_size = 8; /* Size of relocation record. */
74
75 /* Are we trying to generate PIC code? If so, absolute references
76 ought to be made into linkage table references or pc-relative
77 references. Not implemented. For ELF there are other means
78 to denote pic relocations. */
79 int flag_want_pic;
80
81 static int flag_short_refs; /* -l option. */
82 static int flag_short_jumps; /* --short-jumps option */
83 static int flag_long_jumps; /* -S option. */
84 static int flag_keep_pcrel; /* --pcrel option. */
85
86 #ifdef REGISTER_PREFIX_OPTIONAL
87 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
88 #else
89 int flag_reg_prefix_optional;
90 #endif
91
92 /* Whether --register-prefix-optional was used on the command line. */
93 static int reg_prefix_optional_seen;
94
95 /* The floating point coprocessor to use by default. */
96 static enum m68k_register m68k_float_copnum = COP1;
97
98 /* If this is non-zero, then references to number(%pc) will be taken
99 to refer to number, rather than to %pc + number. */
100 static int m68k_abspcadd;
101
102 /* If this is non-zero, then the quick forms of the move, add, and sub
103 instructions are used when possible. */
104 static int m68k_quick = 1;
105
106 /* If this is non-zero, then if the size is not specified for a base
107 or outer displacement, the assembler assumes that the size should
108 be 32 bits. */
109 static int m68k_rel32 = 1;
110
111 /* This is non-zero if m68k_rel32 was set from the command line. */
112 static int m68k_rel32_from_cmdline;
113
114 /* The default width to use for an index register when using a base
115 displacement. */
116 static enum m68k_size m68k_index_width_default = SIZE_LONG;
117
118 /* We want to warn if any text labels are misaligned. In order to get
119 the right line number, we need to record the line number for each
120 label. */
121 struct label_line
122 {
123 struct label_line *next;
124 symbolS *label;
125 char *file;
126 unsigned int line;
127 int text;
128 };
129
130 /* The list of labels. */
131
132 static struct label_line *labels;
133
134 /* The current label. */
135
136 static struct label_line *current_label;
137
138 /* Pointer to list holding the opcodes sorted by name. */
139 static struct m68k_opcode const ** m68k_sorted_opcodes;
140
141 /* Its an arbitrary name: This means I don't approve of it.
142 See flames below. */
143 static struct obstack robyn;
144
145 struct m68k_incant
146 {
147 const char *m_operands;
148 unsigned long m_opcode;
149 short m_opnum;
150 short m_codenum;
151 int m_arch;
152 struct m68k_incant *m_next;
153 };
154
155 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
156 #define gettwo(x) (((x)->m_opcode)&0xffff)
157
158 static const enum m68k_register m68000_control_regs[] = { 0 };
159 static const enum m68k_register m68010_control_regs[] = {
160 SFC, DFC, USP, VBR,
161 0
162 };
163 static const enum m68k_register m68020_control_regs[] = {
164 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
165 0
166 };
167 static const enum m68k_register m68040_control_regs[] = {
168 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
169 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
170 0
171 };
172 static const enum m68k_register m68060_control_regs[] = {
173 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
174 USP, VBR, URP, SRP, PCR,
175 0
176 };
177 static const enum m68k_register mcf_control_regs[] = {
178 CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
179 RAMBAR0, RAMBAR1, MBAR,
180 0
181 };
182 static const enum m68k_register mcf5249_control_regs[] = {
183 CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR1, MBAR, MBAR2,
184 0
185 };
186 static const enum m68k_register mcf528x_control_regs[] = {
187 CACR, ACR0, ACR1, VBR, FLASHBAR, RAMBAR,
188 0
189 };
190 static const enum m68k_register mcfv4e_control_regs[] = {
191 CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
192 ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
193 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
194 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
195 0
196 };
197 #define cpu32_control_regs m68010_control_regs
198
199 static const enum m68k_register *control_regs;
200
201 /* Internal form of a 68020 instruction. */
202 struct m68k_it
203 {
204 const char *error;
205 const char *args; /* List of opcode info. */
206 int numargs;
207
208 int numo; /* Number of shorts in opcode. */
209 short opcode[11];
210
211 struct m68k_op operands[6];
212
213 int nexp; /* Number of exprs in use. */
214 struct m68k_exp exprs[4];
215
216 int nfrag; /* Number of frags we have to produce. */
217 struct
218 {
219 int fragoff; /* Where in the current opcode the frag ends. */
220 symbolS *fadd;
221 offsetT foff;
222 int fragty;
223 }
224 fragb[4];
225
226 int nrel; /* Num of reloc strucs in use. */
227 struct
228 {
229 int n;
230 expressionS exp;
231 char wid;
232 char pcrel;
233 /* In a pc relative address the difference between the address
234 of the offset and the address that the offset is relative
235 to. This depends on the addressing mode. Basically this
236 is the value to put in the offset field to address the
237 first byte of the offset, without regarding the special
238 significance of some values (in the branch instruction, for
239 example). */
240 int pcrel_fix;
241 #ifdef OBJ_ELF
242 /* Whether this expression needs special pic relocation, and if
243 so, which. */
244 enum pic_relocation pic_reloc;
245 #endif
246 }
247 reloc[5]; /* Five is enough??? */
248 };
249
250 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
251 #define float_of_arch(x) ((x) & mfloat)
252 #define mmu_of_arch(x) ((x) & mmmu)
253 #define arch_coldfire_p(x) ((x) & mcfisa_a)
254 #define arch_coldfire_fpu(x) ((x) & cfloat)
255
256 /* Macros for determining if cpu supports a specific addressing mode. */
257 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
258
259 static struct m68k_it the_ins; /* The instruction being assembled. */
260
261 #define op(ex) ((ex)->exp.X_op)
262 #define adds(ex) ((ex)->exp.X_add_symbol)
263 #define subs(ex) ((ex)->exp.X_op_symbol)
264 #define offs(ex) ((ex)->exp.X_add_number)
265
266 /* Macros for adding things to the m68k_it struct. */
267 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
268
269 /* Like addword, but goes BEFORE general operands. */
270
271 static void
insop(int w,const struct m68k_incant * opcode)272 insop (int w, const struct m68k_incant *opcode)
273 {
274 int z;
275 for (z = the_ins.numo; z > opcode->m_codenum; --z)
276 the_ins.opcode[z] = the_ins.opcode[z - 1];
277 for (z = 0; z < the_ins.nrel; z++)
278 the_ins.reloc[z].n += 2;
279 for (z = 0; z < the_ins.nfrag; z++)
280 the_ins.fragb[z].fragoff++;
281 the_ins.opcode[opcode->m_codenum] = w;
282 the_ins.numo++;
283 }
284
285 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
286 Blecch. */
287 static void
add_fix(int width,struct m68k_exp * exp,int pc_rel,int pc_fix)288 add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
289 {
290 the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
291 ? the_ins.numo * 2 - 1
292 : (width == 'b'
293 ? the_ins.numo * 2 + 1
294 : the_ins.numo * 2));
295 the_ins.reloc[the_ins.nrel].exp = exp->exp;
296 the_ins.reloc[the_ins.nrel].wid = width;
297 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
298 #ifdef OBJ_ELF
299 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
300 #endif
301 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
302 }
303
304 /* Cause an extra frag to be generated here, inserting up to 10 bytes
305 (that value is chosen in the frag_var call in md_assemble). TYPE
306 is the subtype of the frag to be generated; its primary type is
307 rs_machine_dependent.
308
309 The TYPE parameter is also used by md_convert_frag_1 and
310 md_estimate_size_before_relax. The appropriate type of fixup will
311 be emitted by md_convert_frag_1.
312
313 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
314 static void
add_frag(symbolS * add,offsetT off,int type)315 add_frag (symbolS *add, offsetT off, int type)
316 {
317 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
318 the_ins.fragb[the_ins.nfrag].fadd = add;
319 the_ins.fragb[the_ins.nfrag].foff = off;
320 the_ins.fragb[the_ins.nfrag++].fragty = type;
321 }
322
323 #define isvar(ex) \
324 (op (ex) != O_constant && op (ex) != O_big)
325
326 static char *crack_operand (char *str, struct m68k_op *opP);
327 static int get_num (struct m68k_exp *exp, int ok);
328 static int reverse_16_bits (int in);
329 static int reverse_8_bits (int in);
330 static void install_gen_operand (int mode, int val);
331 static void install_operand (int mode, int val);
332 static void s_bss (int);
333 static void s_data1 (int);
334 static void s_data2 (int);
335 static void s_even (int);
336 static void s_proc (int);
337 static void s_chip (int);
338 static void s_fopt (int);
339 static void s_opt (int);
340 static void s_reg (int);
341 static void s_restore (int);
342 static void s_save (int);
343 static void s_mri_if (int);
344 static void s_mri_else (int);
345 static void s_mri_endi (int);
346 static void s_mri_break (int);
347 static void s_mri_next (int);
348 static void s_mri_for (int);
349 static void s_mri_endf (int);
350 static void s_mri_repeat (int);
351 static void s_mri_until (int);
352 static void s_mri_while (int);
353 static void s_mri_endw (int);
354
355 static int current_architecture;
356 static int current_chip;
357
358 struct m68k_cpu
359 {
360 unsigned long arch;
361 unsigned long chip;
362 const char *name;
363 int alias;
364 };
365
366 static const struct m68k_cpu archs[] =
367 {
368 { m68000, m68000, "68000", 0 },
369 { m68010, m68010, "68010", 0 },
370 { m68020, m68020, "68020", 0 },
371 { m68030, m68030, "68030", 0 },
372 { m68040, m68040, "68040", 0 },
373 { m68060, m68060, "68060", 0 },
374 { cpu32, cpu32, "cpu32", 0 },
375 { m68881, m68881, "68881", 0 },
376 { m68851, m68851, "68851", 0 },
377 { mcfisa_a, mcf5200, "5200", 0 },
378 { mcfisa_a|mcfhwdiv|mcfmac, mcf5206e, "5206e", 0 },
379 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf521x, "521x", 0 },
380 { mcfisa_a|mcfhwdiv|mcfemac, mcf5249, "5249", 0 },
381 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf528x, "528x", 0 },
382 { mcfisa_a|mcfhwdiv|mcfmac, mcf5307, "5307", 0 },
383 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "5407", 0 },
384 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "547x", 0 },
385 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5480, "548x", 0 },
386 /* Aliases (effectively, so far as gas is concerned) for the above
387 cpus. */
388 { m68020, m68020, "68k", 1 },
389 { m68000, m68000, "68008", 1 },
390 { m68000, m68000, "68302", 1 },
391 { m68000, m68000, "68306", 1 },
392 { m68000, m68000, "68307", 1 },
393 { m68000, m68000, "68322", 1 },
394 { m68000, m68000, "68356", 1 },
395 { m68000, m68000, "68ec000", 1 },
396 { m68000, m68000, "68hc000", 1 },
397 { m68000, m68000, "68hc001", 1 },
398 { m68020, m68020, "68ec020", 1 },
399 { m68030, m68030, "68ec030", 1 },
400 { m68040, m68040, "68ec040", 1 },
401 { m68060, m68060, "68ec060", 1 },
402 { cpu32, cpu32, "68330", 1 },
403 { cpu32, cpu32, "68331", 1 },
404 { cpu32, cpu32, "68332", 1 },
405 { cpu32, cpu32, "68333", 1 },
406 { cpu32, cpu32, "68334", 1 },
407 { cpu32, cpu32, "68336", 1 },
408 { cpu32, cpu32, "68340", 1 },
409 { cpu32, cpu32, "68341", 1 },
410 { cpu32, cpu32, "68349", 1 },
411 { cpu32, cpu32, "68360", 1 },
412 { m68881, m68881, "68882", 1 },
413 { mcfisa_a, mcf5200, "5202", 1 },
414 { mcfisa_a, mcf5200, "5204", 1 },
415 { mcfisa_a, mcf5200, "5206", 1 },
416 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5214", 1 },
417 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5216", 1 },
418 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5280", 1 },
419 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5281", 1 },
420 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5282", 1 },
421 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "cfv4", 1 },
422 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5470", 1 },
423 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5471", 1 },
424 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5472", 1 },
425 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5473", 1 },
426 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5474", 1 },
427 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5475", 1 },
428 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5480", 1 },
429 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5481", 1 },
430 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5482", 1 },
431 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5483", 1 },
432 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5484", 1 },
433 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5485", 1 },
434 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "cfv4e", 1 },
435 };
436
437 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
438
439 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
440 architecture and we have a lot of relaxation modes. */
441
442 /* Macros used in the relaxation code. */
443 #define TAB(x,y) (((x) << 2) + (y))
444 #define TABTYPE(x) ((x) >> 2)
445
446 /* Relaxation states. */
447 #define BYTE 0
448 #define SHORT 1
449 #define LONG 2
450 #define SZ_UNDEF 3
451
452 /* Here are all the relaxation modes we support. First we can relax ordinary
453 branches. On 68020 and higher and on CPU32 all branch instructions take
454 three forms, so on these CPUs all branches always remain as such. When we
455 have to expand to the LONG form on a 68000, though, we substitute an
456 absolute jump instead. This is a direct replacement for unconditional
457 branches and a branch over a jump for conditional branches. However, if the
458 user requires PIC and disables this with --pcrel, we can only relax between
459 BYTE and SHORT forms, punting if that isn't enough. This gives us four
460 different relaxation modes for branches: */
461
462 #define BRANCHBWL 0 /* Branch byte, word, or long. */
463 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
464 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
465 #define BRANCHBW 3 /* Branch byte or word. */
466
467 /* We also relax coprocessor branches and DBcc's. All CPUs that support
468 coprocessor branches support them in word and long forms, so we have only
469 one relaxation mode for them. DBcc's are word only on all CPUs. We can
470 relax them to the LONG form with a branch-around sequence. This sequence
471 can use a long branch (if available) or an absolute jump (if acceptable).
472 This gives us two relaxation modes. If long branches are not available and
473 absolute jumps are not acceptable, we don't relax DBcc's. */
474
475 #define FBRANCH 4 /* Coprocessor branch. */
476 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
477 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
478
479 /* That's all for instruction relaxation. However, we also relax PC-relative
480 operands. Specifically, we have three operand relaxation modes. On the
481 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
482 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
483 two. Also PC+displacement+index operands in their simple form (with a non-
484 suppressed index without memory indirection) are supported on all CPUs, but
485 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
486 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
487 form of the PC+displacement+index operand. Finally, some absolute operands
488 can be relaxed down to 16-bit PC-relative. */
489
490 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
491 #define PCINDEX 8 /* PC + displacement + index. */
492 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
493
494 /* Note that calls to frag_var need to specify the maximum expansion
495 needed; this is currently 10 bytes for DBCC. */
496
497 /* The fields are:
498 How far Forward this mode will reach:
499 How far Backward this mode will reach:
500 How many bytes this mode will add to the size of the frag
501 Which mode to go to if the offset won't fit in this one
502
503 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
504 relax_typeS md_relax_table[] =
505 {
506 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
507 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
508 { 0, 0, 4, 0 },
509 { 1, 1, 0, 0 },
510
511 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
512 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
513 { 0, 0, 4, 0 },
514 { 1, 1, 0, 0 },
515
516 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
517 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
518 { 0, 0, 6, 0 },
519 { 1, 1, 0, 0 },
520
521 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
522 { 0, 0, 2, 0 },
523 { 1, 1, 0, 0 },
524 { 1, 1, 0, 0 },
525
526 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
527 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
528 { 0, 0, 4, 0 },
529 { 1, 1, 0, 0 },
530
531 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
532 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
533 { 0, 0, 10, 0 },
534 { 1, 1, 0, 0 },
535
536 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
537 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
538 { 0, 0, 10, 0 },
539 { 1, 1, 0, 0 },
540
541 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
542 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
543 { 0, 0, 6, 0 },
544 { 1, 1, 0, 0 },
545
546 { 125, -130, 0, TAB (PCINDEX, SHORT) },
547 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
548 { 0, 0, 4, 0 },
549 { 1, 1, 0, 0 },
550
551 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
552 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
553 { 0, 0, 4, 0 },
554 { 1, 1, 0, 0 },
555 };
556
557 /* These are the machine dependent pseudo-ops. These are included so
558 the assembler can work on the output from the SUN C compiler, which
559 generates these. */
560
561 /* This table describes all the machine specific pseudo-ops the assembler
562 has to support. The fields are:
563 pseudo-op name without dot
564 function to call to execute this pseudo-op
565 Integer arg to pass to the function. */
566 const pseudo_typeS md_pseudo_table[] =
567 {
568 {"data1", s_data1, 0},
569 {"data2", s_data2, 0},
570 {"bss", s_bss, 0},
571 {"even", s_even, 0},
572 {"skip", s_space, 0},
573 {"proc", s_proc, 0},
574 #if defined (TE_SUN3) || defined (OBJ_ELF)
575 {"align", s_align_bytes, 0},
576 #endif
577 #ifdef OBJ_ELF
578 {"swbeg", s_ignore, 0},
579 #endif
580 {"extend", float_cons, 'x'},
581 {"ldouble", float_cons, 'x'},
582
583 /* Dwarf2 support for Gcc. */
584 {"file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0},
585 {"loc", dwarf2_directive_loc, 0},
586
587 /* The following pseudo-ops are supported for MRI compatibility. */
588 {"chip", s_chip, 0},
589 {"comline", s_space, 1},
590 {"fopt", s_fopt, 0},
591 {"mask2", s_ignore, 0},
592 {"opt", s_opt, 0},
593 {"reg", s_reg, 0},
594 {"restore", s_restore, 0},
595 {"save", s_save, 0},
596
597 {"if", s_mri_if, 0},
598 {"if.b", s_mri_if, 'b'},
599 {"if.w", s_mri_if, 'w'},
600 {"if.l", s_mri_if, 'l'},
601 {"else", s_mri_else, 0},
602 {"else.s", s_mri_else, 's'},
603 {"else.l", s_mri_else, 'l'},
604 {"endi", s_mri_endi, 0},
605 {"break", s_mri_break, 0},
606 {"break.s", s_mri_break, 's'},
607 {"break.l", s_mri_break, 'l'},
608 {"next", s_mri_next, 0},
609 {"next.s", s_mri_next, 's'},
610 {"next.l", s_mri_next, 'l'},
611 {"for", s_mri_for, 0},
612 {"for.b", s_mri_for, 'b'},
613 {"for.w", s_mri_for, 'w'},
614 {"for.l", s_mri_for, 'l'},
615 {"endf", s_mri_endf, 0},
616 {"repeat", s_mri_repeat, 0},
617 {"until", s_mri_until, 0},
618 {"until.b", s_mri_until, 'b'},
619 {"until.w", s_mri_until, 'w'},
620 {"until.l", s_mri_until, 'l'},
621 {"while", s_mri_while, 0},
622 {"while.b", s_mri_while, 'b'},
623 {"while.w", s_mri_while, 'w'},
624 {"while.l", s_mri_while, 'l'},
625 {"endw", s_mri_endw, 0},
626
627 {0, 0, 0}
628 };
629
630 /* The mote pseudo ops are put into the opcode table, since they
631 don't start with a . they look like opcodes to gas. */
632
633 const pseudo_typeS mote_pseudo_table[] =
634 {
635
636 {"dcl", cons, 4},
637 {"dc", cons, 2},
638 {"dcw", cons, 2},
639 {"dcb", cons, 1},
640
641 {"dsl", s_space, 4},
642 {"ds", s_space, 2},
643 {"dsw", s_space, 2},
644 {"dsb", s_space, 1},
645
646 {"xdef", s_globl, 0},
647 #ifdef OBJ_ELF
648 {"align", s_align_bytes, 0},
649 #else
650 {"align", s_align_ptwo, 0},
651 #endif
652 #ifdef M68KCOFF
653 {"sect", obj_coff_section, 0},
654 {"section", obj_coff_section, 0},
655 #endif
656 {0, 0, 0}
657 };
658
659 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
660 gives identical results to a 32-bit host. */
661 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
662 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
663
664 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
665 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
666 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
667 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
668
669 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
670 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
671 #define islong(x) (1)
672
673 static char notend_table[256];
674 static char alt_notend_table[256];
675 #define notend(s) \
676 (! (notend_table[(unsigned char) *s] \
677 || (*s == ':' \
678 && alt_notend_table[(unsigned char) s[1]])))
679
680 /* Return a human readable string holding the list of chips that are
681 valid for a particular architecture, suppressing aliases (unless
682 there is only one of them). */
683
684 static char *
find_cf_chip(int architecture)685 find_cf_chip (int architecture)
686 {
687 static char buf[1024];
688 int i, j, n_chips, n_alias;
689 char *cp;
690
691 strcpy (buf, " (");
692 cp = buf + strlen (buf);
693
694 for (i = 0, n_chips = 0, n_alias = 0; i < n_archs; ++i)
695 if (archs[i].arch & architecture)
696 {
697 n_chips++;
698 if (archs[i].alias)
699 n_alias++;
700 }
701
702 if (n_chips == 0)
703 as_fatal (_("no matching ColdFire architectures found"));
704
705 if (n_alias > 1)
706 n_chips -= n_alias;
707
708 for (i = 0, j = 0; i < n_archs && j < n_chips; ++i)
709 if (archs[i].arch & architecture)
710 {
711 if (j)
712 {
713 if ((j == n_chips - 1 && !(n_alias > 1)) || ! n_alias)
714 {
715 if (n_chips == 2)
716 {
717 strncpy (cp, _(" or "), (sizeof (buf) - (cp - buf)));
718 cp += strlen (cp);
719 }
720 else
721 {
722 strncpy (cp, _(", or "), (sizeof (buf) - (cp - buf)));
723 cp += strlen (cp);
724 }
725 }
726 else
727 {
728 strncpy (cp, ", ", (sizeof (buf) - (cp - buf)));
729 cp += strlen (cp);
730 }
731 }
732 strncpy (cp, archs[i].name, (sizeof (buf) - (cp - buf)));
733 cp += strlen (cp);
734 j++;
735 }
736
737 if (n_alias > 1)
738 {
739 strncpy (cp, _(", or aliases"), (sizeof (buf) - (cp - buf)));
740 cp += strlen (cp);
741 }
742
743 strncpy (cp, ")", (sizeof (buf) - (cp - buf)));
744
745 return buf;
746 }
747
748 #if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
749
750 #ifdef NO_PCREL_RELOCS
751
752 int
make_pcrel_absolute(fixS * fixP,long * add_number)753 make_pcrel_absolute (fixS *fixP, long *add_number)
754 {
755 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
756
757 /* Rewrite the PC relative instructions to absolute address ones.
758 these are rumored to be faster, and the apollo linker refuses
759 to deal with the PC relative relocations. */
760 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP. */
761 {
762 if (flag_keep_pcrel)
763 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
764 opcode[0] = 0x4e;
765 opcode[1] = 0xf9;
766 }
767 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR. */
768 {
769 if (flag_keep_pcrel)
770 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
771 opcode[0] = 0x4e;
772 opcode[1] = 0xb9;
773 }
774 else
775 as_fatal (_("Unknown PC relative instruction"));
776 *add_number -= 4;
777 return 0;
778 }
779
780 #endif /* NO_PCREL_RELOCS */
781
782 short
tc_coff_fix2rtype(fixS * fixP)783 tc_coff_fix2rtype (fixS *fixP)
784 {
785 /* (TIGCC 20040920) Handle unoptimizable relocs. -- Kevin Kofler */
786 short isunopt;
787 isunopt = (fixP->fx_unoptimizable) ? R_UNOPTIMIZABLE : 0;
788
789 if (fixP->fx_tcbit && fixP->fx_size == 4)
790 return isunopt | R_RELLONG_NEG;
791 /* (TIGCC 20030716) Handle word and byte negative relocs. -- Kevin Kofler */
792 if (fixP->fx_tcbit && fixP->fx_size == 2)
793 return isunopt | R_RELWORD_NEG;
794 if (fixP->fx_tcbit && fixP->fx_size == 1)
795 return isunopt | R_RELBYTE_NEG;
796 #ifdef NO_PCREL_RELOCS
797 know (fixP->fx_pcrel == 0);
798 return isunopt | (fixP->fx_size == 1 ? R_RELBYTE
799 : fixP->fx_size == 2 ? R_DIR16
800 : R_DIR32);
801 #else
802 return isunopt | (fixP->fx_pcrel
803 ? (fixP->fx_size == 1 ? R_PCRBYTE
804 : fixP->fx_size == 2 ? R_PCRWORD
805 : R_PCRLONG)
806 : (fixP->fx_size == 1 ? R_RELBYTE
807 : fixP->fx_size == 2 ? R_RELWORD
808 : R_RELLONG));
809 #endif
810 }
811
812 #endif
813
814 #ifdef OBJ_ELF
815
816 /* Return zero if the reference to SYMBOL from within the same segment may
817 be relaxed. */
818
819 /* On an ELF system, we can't relax an externally visible symbol,
820 because it may be overridden by a shared library. However, if
821 TARGET_OS is "elf", then we presume that we are assembling for an
822 embedded system, in which case we don't have to worry about shared
823 libraries, and we can relax any external sym. */
824
825 #define relaxable_symbol(symbol) \
826 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
827 || S_IS_WEAK (symbol)))
828
829 /* Compute the relocation code for a fixup of SIZE bytes, using pc
830 relative relocation if PCREL is non-zero. PIC says whether a special
831 pic relocation was requested. */
832
833 static bfd_reloc_code_real_type
get_reloc_code(int size,int pcrel,enum pic_relocation pic)834 get_reloc_code (int size, int pcrel, enum pic_relocation pic)
835 {
836 switch (pic)
837 {
838 case pic_got_pcrel:
839 switch (size)
840 {
841 case 1:
842 return BFD_RELOC_8_GOT_PCREL;
843 case 2:
844 return BFD_RELOC_16_GOT_PCREL;
845 case 4:
846 return BFD_RELOC_32_GOT_PCREL;
847 }
848 break;
849
850 case pic_got_off:
851 switch (size)
852 {
853 case 1:
854 return BFD_RELOC_8_GOTOFF;
855 case 2:
856 return BFD_RELOC_16_GOTOFF;
857 case 4:
858 return BFD_RELOC_32_GOTOFF;
859 }
860 break;
861
862 case pic_plt_pcrel:
863 switch (size)
864 {
865 case 1:
866 return BFD_RELOC_8_PLT_PCREL;
867 case 2:
868 return BFD_RELOC_16_PLT_PCREL;
869 case 4:
870 return BFD_RELOC_32_PLT_PCREL;
871 }
872 break;
873
874 case pic_plt_off:
875 switch (size)
876 {
877 case 1:
878 return BFD_RELOC_8_PLTOFF;
879 case 2:
880 return BFD_RELOC_16_PLTOFF;
881 case 4:
882 return BFD_RELOC_32_PLTOFF;
883 }
884 break;
885
886 case pic_none:
887 if (pcrel)
888 {
889 switch (size)
890 {
891 case 1:
892 return BFD_RELOC_8_PCREL;
893 case 2:
894 return BFD_RELOC_16_PCREL;
895 case 4:
896 return BFD_RELOC_32_PCREL;
897 }
898 }
899 else
900 {
901 switch (size)
902 {
903 case 1:
904 return BFD_RELOC_8;
905 case 2:
906 return BFD_RELOC_16;
907 case 4:
908 return BFD_RELOC_32;
909 }
910 }
911 }
912
913 if (pcrel)
914 {
915 if (pic == pic_none)
916 as_bad (_("Can not do %d byte pc-relative relocation"), size);
917 else
918 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
919 }
920 else
921 {
922 if (pic == pic_none)
923 as_bad (_("Can not do %d byte relocation"), size);
924 else
925 as_bad (_("Can not do %d byte pic relocation"), size);
926 }
927
928 return BFD_RELOC_NONE;
929 }
930
931 /* Here we decide which fixups can be adjusted to make them relative
932 to the beginning of the section instead of the symbol. Basically
933 we need to make sure that the dynamic relocations are done
934 correctly, so in some cases we force the original symbol to be
935 used. */
936 int
tc_m68k_fix_adjustable(fixS * fixP)937 tc_m68k_fix_adjustable (fixS *fixP)
938 {
939 /* Adjust_reloc_syms doesn't know about the GOT. */
940 switch (fixP->fx_r_type)
941 {
942 case BFD_RELOC_8_GOT_PCREL:
943 case BFD_RELOC_16_GOT_PCREL:
944 case BFD_RELOC_32_GOT_PCREL:
945 case BFD_RELOC_8_GOTOFF:
946 case BFD_RELOC_16_GOTOFF:
947 case BFD_RELOC_32_GOTOFF:
948 case BFD_RELOC_8_PLT_PCREL:
949 case BFD_RELOC_16_PLT_PCREL:
950 case BFD_RELOC_32_PLT_PCREL:
951 case BFD_RELOC_8_PLTOFF:
952 case BFD_RELOC_16_PLTOFF:
953 case BFD_RELOC_32_PLTOFF:
954 return 0;
955
956 case BFD_RELOC_VTABLE_INHERIT:
957 case BFD_RELOC_VTABLE_ENTRY:
958 return 0;
959
960 default:
961 return 1;
962 }
963 }
964
965 #else /* !OBJ_ELF */
966
967 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
968
969 #define relaxable_symbol(symbol) 1
970
971 #endif /* OBJ_ELF */
972
973 #ifdef BFD_ASSEMBLER
974
975 arelent *
tc_gen_reloc(asection * section ATTRIBUTE_UNUSED,fixS * fixp)976 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
977 {
978 arelent *reloc;
979 bfd_reloc_code_real_type code;
980
981 /* If the tcbit is set, then this was a fixup of a negative value
982 that was never resolved. We do not have a reloc to handle this,
983 so just return. We assume that other code will have detected this
984 situation and produced a helpful error message, so we just tell the
985 user that the reloc cannot be produced. */
986 if (fixp->fx_tcbit)
987 {
988 if (fixp->fx_addsy)
989 as_bad_where (fixp->fx_file, fixp->fx_line,
990 _("Unable to produce reloc against symbol '%s'"),
991 S_GET_NAME (fixp->fx_addsy));
992 return NULL;
993 }
994
995 if (fixp->fx_r_type != BFD_RELOC_NONE)
996 {
997 code = fixp->fx_r_type;
998
999 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
1000 that fixup_segment converted a non-PC relative reloc into a
1001 PC relative reloc. In such a case, we need to convert the
1002 reloc code. */
1003 if (fixp->fx_pcrel)
1004 {
1005 switch (code)
1006 {
1007 case BFD_RELOC_8:
1008 code = BFD_RELOC_8_PCREL;
1009 break;
1010 case BFD_RELOC_16:
1011 code = BFD_RELOC_16_PCREL;
1012 break;
1013 case BFD_RELOC_32:
1014 code = BFD_RELOC_32_PCREL;
1015 break;
1016 case BFD_RELOC_8_PCREL:
1017 case BFD_RELOC_16_PCREL:
1018 case BFD_RELOC_32_PCREL:
1019 case BFD_RELOC_8_GOT_PCREL:
1020 case BFD_RELOC_16_GOT_PCREL:
1021 case BFD_RELOC_32_GOT_PCREL:
1022 case BFD_RELOC_8_GOTOFF:
1023 case BFD_RELOC_16_GOTOFF:
1024 case BFD_RELOC_32_GOTOFF:
1025 case BFD_RELOC_8_PLT_PCREL:
1026 case BFD_RELOC_16_PLT_PCREL:
1027 case BFD_RELOC_32_PLT_PCREL:
1028 case BFD_RELOC_8_PLTOFF:
1029 case BFD_RELOC_16_PLTOFF:
1030 case BFD_RELOC_32_PLTOFF:
1031 break;
1032 default:
1033 as_bad_where (fixp->fx_file, fixp->fx_line,
1034 _("Cannot make %s relocation PC relative"),
1035 bfd_get_reloc_code_name (code));
1036 }
1037 }
1038 }
1039 else
1040 {
1041 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
1042 switch (F (fixp->fx_size, fixp->fx_pcrel))
1043 {
1044 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
1045 MAP (1, 0, BFD_RELOC_8);
1046 MAP (2, 0, BFD_RELOC_16);
1047 MAP (4, 0, BFD_RELOC_32);
1048 MAP (1, 1, BFD_RELOC_8_PCREL);
1049 MAP (2, 1, BFD_RELOC_16_PCREL);
1050 MAP (4, 1, BFD_RELOC_32_PCREL);
1051 default:
1052 abort ();
1053 }
1054 }
1055 #undef F
1056 #undef MAP
1057
1058 reloc = (arelent *) xmalloc (sizeof (arelent));
1059 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1060 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1061 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1062 #ifndef OBJ_ELF
1063 if (fixp->fx_pcrel)
1064 reloc->addend = fixp->fx_addnumber;
1065 else
1066 reloc->addend = 0;
1067 #else
1068 if (!fixp->fx_pcrel)
1069 reloc->addend = fixp->fx_addnumber;
1070 else
1071 reloc->addend = (section->vma
1072 /* Explicit sign extension in case char is
1073 unsigned. */
1074 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
1075 + fixp->fx_addnumber
1076 + md_pcrel_from (fixp));
1077 #endif
1078
1079 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1080 assert (reloc->howto != 0);
1081
1082 return reloc;
1083 }
1084
1085 #endif /* BFD_ASSEMBLER */
1086
1087 /* Handle of the OPCODE hash table. NULL means any use before
1088 m68k_ip_begin() will crash. */
1089 static struct hash_control *op_hash;
1090
1091 /* Assemble an m68k instruction. */
1092
1093 static void
m68k_ip(char * instring)1094 m68k_ip (char *instring)
1095 {
1096 register char *p;
1097 register struct m68k_op *opP;
1098 register const struct m68k_incant *opcode;
1099 register const char *s;
1100 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1101 char *pdot, *pdotmove;
1102 enum m68k_size siz1, siz2;
1103 char c;
1104 int losing;
1105 int opsfound;
1106 LITTLENUM_TYPE words[6];
1107 LITTLENUM_TYPE *wordp;
1108 unsigned long ok_arch = 0;
1109
1110 if (*instring == ' ')
1111 instring++; /* Skip leading whitespace. */
1112
1113 /* Scan up to end of operation-code, which MUST end in end-of-string
1114 or exactly 1 space. */
1115 pdot = 0;
1116 for (p = instring; *p != '\0'; p++)
1117 {
1118 if (*p == ' ')
1119 break;
1120 if (*p == '.')
1121 pdot = p;
1122 }
1123
1124 if (p == instring)
1125 {
1126 the_ins.error = _("No operator");
1127 return;
1128 }
1129
1130 /* p now points to the end of the opcode name, probably whitespace.
1131 Make sure the name is null terminated by clobbering the
1132 whitespace, look it up in the hash table, then fix it back.
1133 Remove a dot, first, since the opcode tables have none. */
1134 if (pdot != NULL)
1135 {
1136 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1137 *pdotmove = pdotmove[1];
1138 p--;
1139 }
1140
1141 c = *p;
1142 *p = '\0';
1143 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1144 *p = c;
1145
1146 if (pdot != NULL)
1147 {
1148 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1149 *pdotmove = pdotmove[-1];
1150 *pdot = '.';
1151 ++p;
1152 }
1153
1154 if (opcode == NULL)
1155 {
1156 the_ins.error = _("Unknown operator");
1157 return;
1158 }
1159
1160 /* Found a legitimate opcode, start matching operands. */
1161 while (*p == ' ')
1162 ++p;
1163
1164 if (opcode->m_operands == 0)
1165 {
1166 char *old = input_line_pointer;
1167 *old = '\n';
1168 input_line_pointer = p;
1169 /* Ahh - it's a motorola style psuedo op. */
1170 mote_pseudo_table[opcode->m_opnum].poc_handler
1171 (mote_pseudo_table[opcode->m_opnum].poc_val);
1172 input_line_pointer = old;
1173 *old = 0;
1174
1175 return;
1176 }
1177
1178 if (flag_mri && opcode->m_opnum == 0)
1179 {
1180 /* In MRI mode, random garbage is allowed after an instruction
1181 which accepts no operands. */
1182 the_ins.args = opcode->m_operands;
1183 the_ins.numargs = opcode->m_opnum;
1184 the_ins.numo = opcode->m_codenum;
1185 the_ins.opcode[0] = getone (opcode);
1186 the_ins.opcode[1] = gettwo (opcode);
1187 return;
1188 }
1189
1190 for (opP = &the_ins.operands[0]; *p; opP++)
1191 {
1192 p = crack_operand (p, opP);
1193
1194 if (opP->error)
1195 {
1196 the_ins.error = opP->error;
1197 return;
1198 }
1199 }
1200
1201 opsfound = opP - &the_ins.operands[0];
1202
1203 /* This ugly hack is to support the floating pt opcodes in their
1204 standard form. Essentially, we fake a first enty of type COP#1 */
1205 if (opcode->m_operands[0] == 'I')
1206 {
1207 int n;
1208
1209 for (n = opsfound; n > 0; --n)
1210 the_ins.operands[n] = the_ins.operands[n - 1];
1211
1212 memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
1213 the_ins.operands[0].mode = CONTROL;
1214 the_ins.operands[0].reg = m68k_float_copnum;
1215 opsfound++;
1216 }
1217
1218 /* We've got the operands. Find an opcode that'll accept them. */
1219 for (losing = 0;;)
1220 {
1221 /* If we didn't get the right number of ops, or we have no
1222 common model with this pattern then reject this pattern. */
1223
1224 ok_arch |= opcode->m_arch;
1225 if (opsfound != opcode->m_opnum
1226 || ((opcode->m_arch & current_architecture) == 0))
1227 ++losing;
1228 else
1229 {
1230 for (s = opcode->m_operands, opP = &the_ins.operands[0];
1231 *s && !losing;
1232 s += 2, opP++)
1233 {
1234 /* Warning: this switch is huge! */
1235 /* I've tried to organize the cases into this order:
1236 non-alpha first, then alpha by letter. Lower-case
1237 goes directly before uppercase counterpart. */
1238 /* Code with multiple case ...: gets sorted by the lowest
1239 case ... it belongs to. I hope this makes sense. */
1240 switch (*s)
1241 {
1242 case '!':
1243 switch (opP->mode)
1244 {
1245 case IMMED:
1246 case DREG:
1247 case AREG:
1248 case FPREG:
1249 case CONTROL:
1250 case AINC:
1251 case ADEC:
1252 case REGLST:
1253 losing++;
1254 break;
1255 default:
1256 break;
1257 }
1258 break;
1259
1260 case '<':
1261 switch (opP->mode)
1262 {
1263 case DREG:
1264 case AREG:
1265 case FPREG:
1266 case CONTROL:
1267 case IMMED:
1268 case ADEC:
1269 case REGLST:
1270 losing++;
1271 break;
1272 default:
1273 break;
1274 }
1275 break;
1276
1277 case '>':
1278 switch (opP->mode)
1279 {
1280 case DREG:
1281 case AREG:
1282 case FPREG:
1283 case CONTROL:
1284 case IMMED:
1285 case AINC:
1286 case REGLST:
1287 losing++;
1288 break;
1289 case ABSL:
1290 break;
1291 default:
1292 if (opP->reg == PC
1293 || opP->reg == ZPC)
1294 losing++;
1295 break;
1296 }
1297 break;
1298
1299 case 'm':
1300 switch (opP->mode)
1301 {
1302 case DREG:
1303 case AREG:
1304 case AINDR:
1305 case AINC:
1306 case ADEC:
1307 break;
1308 default:
1309 losing++;
1310 }
1311 break;
1312
1313 case 'n':
1314 switch (opP->mode)
1315 {
1316 case DISP:
1317 break;
1318 default:
1319 losing++;
1320 }
1321 break;
1322
1323 case 'o':
1324 switch (opP->mode)
1325 {
1326 case BASE:
1327 case ABSL:
1328 case IMMED:
1329 break;
1330 default:
1331 losing++;
1332 }
1333 break;
1334
1335 case 'p':
1336 switch (opP->mode)
1337 {
1338 case DREG:
1339 case AREG:
1340 case AINDR:
1341 case AINC:
1342 case ADEC:
1343 break;
1344 case DISP:
1345 if (opP->reg == PC || opP->reg == ZPC)
1346 losing++;
1347 break;
1348 default:
1349 losing++;
1350 }
1351 break;
1352
1353 case 'q':
1354 switch (opP->mode)
1355 {
1356 case DREG:
1357 case AINDR:
1358 case AINC:
1359 case ADEC:
1360 break;
1361 case DISP:
1362 if (opP->reg == PC || opP->reg == ZPC)
1363 losing++;
1364 break;
1365 default:
1366 losing++;
1367 break;
1368 }
1369 break;
1370
1371 case 'v':
1372 switch (opP->mode)
1373 {
1374 case DREG:
1375 case AINDR:
1376 case AINC:
1377 case ADEC:
1378 case ABSL:
1379 break;
1380 case DISP:
1381 if (opP->reg == PC || opP->reg == ZPC)
1382 losing++;
1383 break;
1384 default:
1385 losing++;
1386 break;
1387 }
1388 break;
1389
1390 case '#':
1391 if (opP->mode != IMMED)
1392 losing++;
1393 else if (s[1] == 'b'
1394 && ! isvar (&opP->disp)
1395 && (opP->disp.exp.X_op != O_constant
1396 || ! isbyte (opP->disp.exp.X_add_number)))
1397 losing++;
1398 else if (s[1] == 'B'
1399 && ! isvar (&opP->disp)
1400 && (opP->disp.exp.X_op != O_constant
1401 || ! issbyte (opP->disp.exp.X_add_number)))
1402 losing++;
1403 else if (s[1] == 'w'
1404 && ! isvar (&opP->disp)
1405 && (opP->disp.exp.X_op != O_constant
1406 || ! isword (opP->disp.exp.X_add_number)))
1407 losing++;
1408 else if (s[1] == 'W'
1409 && ! isvar (&opP->disp)
1410 && (opP->disp.exp.X_op != O_constant
1411 || ! issword (opP->disp.exp.X_add_number)))
1412 losing++;
1413 break;
1414
1415 case '^':
1416 case 'T':
1417 if (opP->mode != IMMED)
1418 losing++;
1419 break;
1420
1421 case '$':
1422 if (opP->mode == AREG
1423 || opP->mode == CONTROL
1424 || opP->mode == FPREG
1425 || opP->mode == IMMED
1426 || opP->mode == REGLST
1427 || (opP->mode != ABSL
1428 && (opP->reg == PC
1429 || opP->reg == ZPC)))
1430 losing++;
1431 break;
1432
1433 case '%':
1434 if (opP->mode == CONTROL
1435 || opP->mode == FPREG
1436 || opP->mode == REGLST
1437 || opP->mode == IMMED
1438 || (opP->mode != ABSL
1439 && (opP->reg == PC
1440 || opP->reg == ZPC)))
1441 losing++;
1442 break;
1443
1444 case '&':
1445 switch (opP->mode)
1446 {
1447 case DREG:
1448 case AREG:
1449 case FPREG:
1450 case CONTROL:
1451 case IMMED:
1452 case AINC:
1453 case ADEC:
1454 case REGLST:
1455 losing++;
1456 break;
1457 case ABSL:
1458 break;
1459 default:
1460 if (opP->reg == PC
1461 || opP->reg == ZPC)
1462 losing++;
1463 break;
1464 }
1465 break;
1466
1467 case '*':
1468 if (opP->mode == CONTROL
1469 || opP->mode == FPREG
1470 || opP->mode == REGLST)
1471 losing++;
1472 break;
1473
1474 case '+':
1475 if (opP->mode != AINC)
1476 losing++;
1477 break;
1478
1479 case '-':
1480 if (opP->mode != ADEC)
1481 losing++;
1482 break;
1483
1484 case '/':
1485 switch (opP->mode)
1486 {
1487 case AREG:
1488 case CONTROL:
1489 case FPREG:
1490 case AINC:
1491 case ADEC:
1492 case IMMED:
1493 case REGLST:
1494 losing++;
1495 break;
1496 default:
1497 break;
1498 }
1499 break;
1500
1501 case ';':
1502 switch (opP->mode)
1503 {
1504 case AREG:
1505 case CONTROL:
1506 case FPREG:
1507 case REGLST:
1508 losing++;
1509 break;
1510 default:
1511 break;
1512 }
1513 break;
1514
1515 case '?':
1516 switch (opP->mode)
1517 {
1518 case AREG:
1519 case CONTROL:
1520 case FPREG:
1521 case AINC:
1522 case ADEC:
1523 case IMMED:
1524 case REGLST:
1525 losing++;
1526 break;
1527 case ABSL:
1528 break;
1529 default:
1530 if (opP->reg == PC || opP->reg == ZPC)
1531 losing++;
1532 break;
1533 }
1534 break;
1535
1536 case '@':
1537 switch (opP->mode)
1538 {
1539 case AREG:
1540 case CONTROL:
1541 case FPREG:
1542 case IMMED:
1543 case REGLST:
1544 losing++;
1545 break;
1546 default:
1547 break;
1548 }
1549 break;
1550
1551 case '~': /* For now! (JF FOO is this right?) */
1552 switch (opP->mode)
1553 {
1554 case DREG:
1555 case AREG:
1556 case CONTROL:
1557 case FPREG:
1558 case IMMED:
1559 case REGLST:
1560 losing++;
1561 break;
1562 case ABSL:
1563 break;
1564 default:
1565 if (opP->reg == PC
1566 || opP->reg == ZPC)
1567 losing++;
1568 break;
1569 }
1570 break;
1571
1572 case '3':
1573 if (opP->mode != CONTROL
1574 || (opP->reg != TT0 && opP->reg != TT1))
1575 losing++;
1576 break;
1577
1578 case 'A':
1579 if (opP->mode != AREG)
1580 losing++;
1581 break;
1582
1583 case 'a':
1584 if (opP->mode != AINDR)
1585 ++losing;
1586 break;
1587
1588 case '4':
1589 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1590 && (opP->mode != DISP
1591 || opP->reg < ADDR0
1592 || opP->reg > ADDR7))
1593 ++losing;
1594 break;
1595
1596 case 'B': /* FOO */
1597 if (opP->mode != ABSL
1598 || (flag_long_jumps
1599 && strncmp (instring, "jbsr", 4) == 0))
1600 losing++;
1601 break;
1602
1603 case 'b':
1604 switch (opP->mode)
1605 {
1606 case IMMED:
1607 case ABSL:
1608 case AREG:
1609 case FPREG:
1610 case CONTROL:
1611 case POST:
1612 case PRE:
1613 case REGLST:
1614 losing++;
1615 break;
1616 default:
1617 break;
1618 }
1619 break;
1620
1621 case 'C':
1622 if (opP->mode != CONTROL || opP->reg != CCR)
1623 losing++;
1624 break;
1625
1626 case 'd':
1627 if (opP->mode != DISP
1628 || opP->reg < ADDR0
1629 || opP->reg > ADDR7)
1630 losing++;
1631 break;
1632
1633 case 'D':
1634 if (opP->mode != DREG)
1635 losing++;
1636 break;
1637
1638 case 'E':
1639 if (opP->reg != ACC)
1640 losing++;
1641 break;
1642
1643 case 'e':
1644 if (opP->reg != ACC && opP->reg != ACC1
1645 && opP->reg != ACC2 && opP->reg != ACC3)
1646 losing++;
1647 break;
1648
1649 case 'F':
1650 if (opP->mode != FPREG)
1651 losing++;
1652 break;
1653
1654 case 'G':
1655 if (opP->reg != MACSR)
1656 losing++;
1657 break;
1658
1659 case 'g':
1660 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1661 losing++;
1662 break;
1663
1664 case 'H':
1665 if (opP->reg != MASK)
1666 losing++;
1667 break;
1668
1669 case 'I':
1670 if (opP->mode != CONTROL
1671 || opP->reg < COP0
1672 || opP->reg > COP7)
1673 losing++;
1674 break;
1675
1676 case 'i':
1677 if (opP->mode != LSH && opP->mode != RSH)
1678 losing++;
1679 break;
1680
1681 case 'J':
1682 if (opP->mode != CONTROL
1683 || opP->reg < USP
1684 || opP->reg > last_movec_reg)
1685 losing++;
1686 else
1687 {
1688 const enum m68k_register *rp;
1689 for (rp = control_regs; *rp; rp++)
1690 if (*rp == opP->reg)
1691 break;
1692 if (*rp == 0)
1693 losing++;
1694 }
1695 break;
1696
1697 case 'k':
1698 if (opP->mode != IMMED)
1699 losing++;
1700 break;
1701
1702 case 'l':
1703 case 'L':
1704 if (opP->mode == DREG
1705 || opP->mode == AREG
1706 || opP->mode == FPREG)
1707 {
1708 if (s[1] == '8')
1709 losing++;
1710 else
1711 {
1712 switch (opP->mode)
1713 {
1714 case DREG:
1715 opP->mask = 1 << (opP->reg - DATA0);
1716 break;
1717 case AREG:
1718 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1719 break;
1720 case FPREG:
1721 opP->mask = 1 << (opP->reg - FP0 + 16);
1722 break;
1723 default:
1724 abort ();
1725 }
1726 opP->mode = REGLST;
1727 }
1728 }
1729 else if (opP->mode == CONTROL)
1730 {
1731 if (s[1] != '8')
1732 losing++;
1733 else
1734 {
1735 switch (opP->reg)
1736 {
1737 case FPI:
1738 opP->mask = 1 << 24;
1739 break;
1740 case FPS:
1741 opP->mask = 1 << 25;
1742 break;
1743 case FPC:
1744 opP->mask = 1 << 26;
1745 break;
1746 default:
1747 losing++;
1748 break;
1749 }
1750 opP->mode = REGLST;
1751 }
1752 }
1753 else if (opP->mode != REGLST)
1754 losing++;
1755 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1756 losing++;
1757 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1758 losing++;
1759 break;
1760
1761 case 'M':
1762 if (opP->mode != IMMED)
1763 losing++;
1764 else if (opP->disp.exp.X_op != O_constant
1765 || ! issbyte (opP->disp.exp.X_add_number))
1766 losing++;
1767 else if (! m68k_quick
1768 && instring[3] != 'q'
1769 && instring[4] != 'q')
1770 losing++;
1771 break;
1772
1773 case 'O':
1774 if (opP->mode != DREG
1775 && opP->mode != IMMED
1776 && opP->mode != ABSL)
1777 losing++;
1778 break;
1779
1780 case 'Q':
1781 if (opP->mode != IMMED)
1782 losing++;
1783 else if (opP->disp.exp.X_op != O_constant
1784 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
1785 losing++;
1786 else if (! m68k_quick
1787 && (strncmp (instring, "add", 3) == 0
1788 || strncmp (instring, "sub", 3) == 0)
1789 && instring[3] != 'q')
1790 losing++;
1791 break;
1792
1793 case 'R':
1794 if (opP->mode != DREG && opP->mode != AREG)
1795 losing++;
1796 break;
1797
1798 case 'r':
1799 if (opP->mode != AINDR
1800 && (opP->mode != BASE
1801 || (opP->reg != 0
1802 && opP->reg != ZADDR0)
1803 || opP->disp.exp.X_op != O_absent
1804 || ((opP->index.reg < DATA0
1805 || opP->index.reg > DATA7)
1806 && (opP->index.reg < ADDR0
1807 || opP->index.reg > ADDR7))
1808 || opP->index.size != SIZE_UNSPEC
1809 || opP->index.scale != 1))
1810 losing++;
1811 break;
1812
1813 case 's':
1814 if (opP->mode != CONTROL
1815 || ! (opP->reg == FPI
1816 || opP->reg == FPS
1817 || opP->reg == FPC))
1818 losing++;
1819 break;
1820
1821 case 'S':
1822 if (opP->mode != CONTROL || opP->reg != SR)
1823 losing++;
1824 break;
1825
1826 case 't':
1827 if (opP->mode != IMMED)
1828 losing++;
1829 else if (opP->disp.exp.X_op != O_constant
1830 || TRUNC (opP->disp.exp.X_add_number) > 7)
1831 losing++;
1832 break;
1833
1834 case 'U':
1835 if (opP->mode != CONTROL || opP->reg != USP)
1836 losing++;
1837 break;
1838
1839 case 'x':
1840 if (opP->mode != IMMED)
1841 losing++;
1842 else if (opP->disp.exp.X_op != O_constant
1843 || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
1844 && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
1845 losing++;
1846 break;
1847
1848 /* JF these are out of order. We could put them
1849 in order if we were willing to put up with
1850 bunches of #ifdef m68851s in the code.
1851
1852 Don't forget that you need these operands
1853 to use 68030 MMU instructions. */
1854 #ifndef NO_68851
1855 /* Memory addressing mode used by pflushr. */
1856 case '|':
1857 if (opP->mode == CONTROL
1858 || opP->mode == FPREG
1859 || opP->mode == DREG
1860 || opP->mode == AREG
1861 || opP->mode == REGLST)
1862 losing++;
1863 /* We should accept immediate operands, but they
1864 supposedly have to be quad word, and we don't
1865 handle that. I would like to see what a Motorola
1866 assembler does before doing something here. */
1867 if (opP->mode == IMMED)
1868 losing++;
1869 break;
1870
1871 case 'f':
1872 if (opP->mode != CONTROL
1873 || (opP->reg != SFC && opP->reg != DFC))
1874 losing++;
1875 break;
1876
1877 case '0':
1878 if (opP->mode != CONTROL || opP->reg != TC)
1879 losing++;
1880 break;
1881
1882 case '1':
1883 if (opP->mode != CONTROL || opP->reg != AC)
1884 losing++;
1885 break;
1886
1887 case '2':
1888 if (opP->mode != CONTROL
1889 || (opP->reg != CAL
1890 && opP->reg != VAL
1891 && opP->reg != SCC))
1892 losing++;
1893 break;
1894
1895 case 'V':
1896 if (opP->mode != CONTROL
1897 || opP->reg != VAL)
1898 losing++;
1899 break;
1900
1901 case 'W':
1902 if (opP->mode != CONTROL
1903 || (opP->reg != DRP
1904 && opP->reg != SRP
1905 && opP->reg != CRP))
1906 losing++;
1907 break;
1908
1909 case 'w':
1910 switch (opP->mode)
1911 {
1912 case IMMED:
1913 case ABSL:
1914 case AREG:
1915 case DREG:
1916 case FPREG:
1917 case CONTROL:
1918 case POST:
1919 case PRE:
1920 case REGLST:
1921 losing++;
1922 break;
1923 default:
1924 break;
1925 }
1926 break;
1927
1928 case 'X':
1929 if (opP->mode != CONTROL
1930 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1931 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1932 losing++;
1933 break;
1934
1935 case 'Y':
1936 if (opP->mode != CONTROL || opP->reg != PSR)
1937 losing++;
1938 break;
1939
1940 case 'Z':
1941 if (opP->mode != CONTROL || opP->reg != PCSR)
1942 losing++;
1943 break;
1944 #endif
1945 case 'c':
1946 if (opP->mode != CONTROL
1947 || (opP->reg != NC
1948 && opP->reg != IC
1949 && opP->reg != DC
1950 && opP->reg != BC))
1951 losing++;
1952 break;
1953
1954 case '_':
1955 if (opP->mode != ABSL)
1956 ++losing;
1957 break;
1958
1959 case 'u':
1960 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1961 losing++;
1962 /* FIXME: kludge instead of fixing parser:
1963 upper/lower registers are *not* CONTROL
1964 registers, but ordinary ones. */
1965 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1966 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1967 opP->mode = DREG;
1968 else
1969 opP->mode = AREG;
1970 break;
1971
1972 case 'y':
1973 if (!(opP->mode == AINDR
1974 || (opP->mode == DISP
1975 && !(opP->reg == PC || opP->reg == ZPC))))
1976 losing++;
1977 break;
1978
1979 case 'z':
1980 if (!(opP->mode == AINDR || opP->mode == DISP))
1981 losing++;
1982 break;
1983
1984 default:
1985 abort ();
1986 }
1987
1988 if (losing)
1989 break;
1990 }
1991 }
1992
1993 if (!losing)
1994 break;
1995
1996 opcode = opcode->m_next;
1997
1998 if (!opcode)
1999 {
2000 if (ok_arch
2001 && !(ok_arch & current_architecture))
2002 {
2003 char buf[200], *cp;
2004
2005 strncpy (buf,
2006 _("invalid instruction for this architecture; needs "),
2007 sizeof (buf));
2008 cp = buf + strlen (buf);
2009 switch (ok_arch)
2010 {
2011 case mcfisa_a:
2012 strncpy (cp, _("ColdFire ISA_A"),
2013 sizeof (buf) - (cp - buf));
2014 cp += strlen (cp);
2015 strncpy (cp, find_cf_chip (ok_arch),
2016 sizeof (buf) - (cp - buf));
2017 cp += strlen (cp);
2018 break;
2019 case mcfhwdiv:
2020 strncpy (cp, _("ColdFire hardware divide"),
2021 sizeof (buf) - (cp - buf));
2022 cp += strlen (cp);
2023 strncpy (cp, find_cf_chip (ok_arch),
2024 sizeof (buf) - (cp - buf));
2025 cp += strlen (cp);
2026 break;
2027 case mcfisa_aa:
2028 strncpy (cp, _("ColdFire ISA_A+"),
2029 sizeof (buf) - (cp - buf));
2030 cp += strlen (cp);
2031 strncpy (cp, find_cf_chip (ok_arch),
2032 sizeof (buf) - (cp - buf));
2033 cp += strlen (cp);
2034 break;
2035 case mcfisa_b:
2036 strncpy (cp, _("ColdFire ISA_B"),
2037 sizeof (buf) - (cp - buf));
2038 cp += strlen (cp);
2039 strncpy (cp, find_cf_chip (ok_arch),
2040 sizeof (buf) - (cp - buf));
2041 cp += strlen (cp);
2042 break;
2043 case cfloat:
2044 strncpy (cp, _("ColdFire fpu"), sizeof (buf) - (cp - buf));
2045 cp += strlen (cp);
2046 strncpy (cp, find_cf_chip (ok_arch),
2047 sizeof (buf) - (cp - buf));
2048 cp += strlen (cp);
2049 break;
2050 case mfloat:
2051 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
2052 break;
2053 case mmmu:
2054 strcpy (cp, _("mmu (68030 or 68851)"));
2055 break;
2056 case m68020up:
2057 strcpy (cp, _("68020 or higher"));
2058 break;
2059 case m68000up:
2060 strcpy (cp, _("68000 or higher"));
2061 break;
2062 case m68010up:
2063 strcpy (cp, _("68010 or higher"));
2064 break;
2065 default:
2066 {
2067 int got_one = 0, idx;
2068
2069 for (idx = 0; idx < n_archs; idx++)
2070 {
2071 if ((archs[idx].arch & ok_arch)
2072 && ! archs[idx].alias)
2073 {
2074 if (got_one)
2075 {
2076 strcpy (cp, " or ");
2077 cp += strlen (cp);
2078 }
2079 got_one = 1;
2080 strcpy (cp, archs[idx].name);
2081 cp += strlen (cp);
2082 }
2083 }
2084 }
2085 }
2086 cp = xmalloc (strlen (buf) + 1);
2087 strcpy (cp, buf);
2088 the_ins.error = cp;
2089 }
2090 else
2091 the_ins.error = _("operands mismatch");
2092 return;
2093 }
2094
2095 losing = 0;
2096 }
2097
2098 /* Now assemble it. */
2099 the_ins.args = opcode->m_operands;
2100 the_ins.numargs = opcode->m_opnum;
2101 the_ins.numo = opcode->m_codenum;
2102 the_ins.opcode[0] = getone (opcode);
2103 the_ins.opcode[1] = gettwo (opcode);
2104
2105 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2106 {
2107 /* This switch is a doozy.
2108 Watch the first step; its a big one! */
2109 switch (s[0])
2110 {
2111
2112 case '*':
2113 case '~':
2114 case '%':
2115 case ';':
2116 case '@':
2117 case '!':
2118 case '&':
2119 case '$':
2120 case '?':
2121 case '/':
2122 case '<':
2123 case '>':
2124 case 'b':
2125 case 'm':
2126 case 'n':
2127 case 'o':
2128 case 'p':
2129 case 'q':
2130 case 'v':
2131 case 'w':
2132 case 'y':
2133 case 'z':
2134 case '4':
2135 #ifndef NO_68851
2136 case '|':
2137 #endif
2138 switch (opP->mode)
2139 {
2140 case IMMED:
2141 tmpreg = 0x3c; /* 7.4 */
2142 if (strchr ("bwl", s[1]))
2143 nextword = get_num (&opP->disp, 90);
2144 else
2145 nextword = get_num (&opP->disp, 0);
2146 if (isvar (&opP->disp))
2147 add_fix (s[1], &opP->disp, 0, 0);
2148 switch (s[1])
2149 {
2150 case 'b':
2151 if (!isbyte (nextword))
2152 opP->error = _("operand out of range");
2153 addword (nextword);
2154 baseo = 0;
2155 break;
2156 case 'w':
2157 if (!isword (nextword))
2158 opP->error = _("operand out of range");
2159 addword (nextword);
2160 baseo = 0;
2161 break;
2162 case 'W':
2163 if (!issword (nextword))
2164 opP->error = _("operand out of range");
2165 addword (nextword);
2166 baseo = 0;
2167 break;
2168 case 'l':
2169 addword (nextword >> 16);
2170 addword (nextword);
2171 baseo = 0;
2172 break;
2173
2174 case 'f':
2175 baseo = 2;
2176 outro = 8;
2177 break;
2178 case 'F':
2179 baseo = 4;
2180 outro = 11;
2181 break;
2182 case 'x':
2183 baseo = 6;
2184 outro = 15;
2185 break;
2186 case 'p':
2187 baseo = 6;
2188 outro = -1;
2189 break;
2190 default:
2191 abort ();
2192 }
2193 if (!baseo)
2194 break;
2195
2196 /* We gotta put out some float. */
2197 if (op (&opP->disp) != O_big)
2198 {
2199 valueT val;
2200 int gencnt;
2201
2202 /* Can other cases happen here? */
2203 if (op (&opP->disp) != O_constant)
2204 abort ();
2205
2206 val = (valueT) offs (&opP->disp);
2207 gencnt = 0;
2208 do
2209 {
2210 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2211 val >>= LITTLENUM_NUMBER_OF_BITS;
2212 ++gencnt;
2213 }
2214 while (val != 0);
2215 offs (&opP->disp) = gencnt;
2216 }
2217 if (offs (&opP->disp) > 0)
2218 {
2219 if (offs (&opP->disp) > baseo)
2220 {
2221 as_warn (_("Bignum too big for %c format; truncated"),
2222 s[1]);
2223 offs (&opP->disp) = baseo;
2224 }
2225 baseo -= offs (&opP->disp);
2226 while (baseo--)
2227 addword (0);
2228 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2229 offs (&opP->disp)--;
2230 --wordp)
2231 addword (*wordp);
2232 break;
2233 }
2234 gen_to_words (words, baseo, (long) outro);
2235 for (wordp = words; baseo--; wordp++)
2236 addword (*wordp);
2237 break;
2238 case DREG:
2239 tmpreg = opP->reg - DATA; /* 0.dreg */
2240 break;
2241 case AREG:
2242 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2243 break;
2244 case AINDR:
2245 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2246 break;
2247 case ADEC:
2248 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2249 break;
2250 case AINC:
2251 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2252 break;
2253 case DISP:
2254
2255 nextword = get_num (&opP->disp, 90);
2256
2257 /* Convert mode 5 addressing with a zero offset into
2258 mode 2 addressing to reduce the instruction size by a
2259 word. */
2260 if (! isvar (&opP->disp)
2261 && (nextword == 0)
2262 && (opP->disp.size == SIZE_UNSPEC)
2263 && (opP->reg >= ADDR0)
2264 && (opP->reg <= ADDR7))
2265 {
2266 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2267 break;
2268 }
2269
2270 if (opP->reg == PC
2271 && ! isvar (&opP->disp)
2272 && m68k_abspcadd)
2273 {
2274 opP->disp.exp.X_op = O_symbol;
2275 #ifndef BFD_ASSEMBLER
2276 opP->disp.exp.X_add_symbol = &abs_symbol;
2277 #else
2278 opP->disp.exp.X_add_symbol =
2279 section_symbol (absolute_section);
2280 #endif
2281 }
2282
2283 /* Force into index mode. Hope this works. */
2284
2285 /* We do the first bit for 32-bit displacements, and the
2286 second bit for 16 bit ones. It is possible that we
2287 should make the default be WORD instead of LONG, but
2288 I think that'd break GCC, so we put up with a little
2289 inefficiency for the sake of working output. */
2290
2291 if (!issword (nextword)
2292 || (isvar (&opP->disp)
2293 && ((opP->disp.size == SIZE_UNSPEC
2294 && flag_short_refs == 0
2295 && cpu_of_arch (current_architecture) >= m68020
2296 && ! arch_coldfire_p (current_architecture))
2297 || opP->disp.size == SIZE_LONG)))
2298 {
2299 if (cpu_of_arch (current_architecture) < m68020
2300 || arch_coldfire_p (current_architecture))
2301 opP->error =
2302 _("displacement too large for this architecture; needs 68020 or higher");
2303 if (opP->reg == PC)
2304 tmpreg = 0x3B; /* 7.3 */
2305 else
2306 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2307 if (isvar (&opP->disp))
2308 {
2309 if (opP->reg == PC)
2310 {
2311 if (opP->disp.size == SIZE_LONG
2312 #ifdef OBJ_ELF
2313 /* If the displacement needs pic
2314 relocation it cannot be relaxed. */
2315 || opP->disp.pic_reloc != pic_none
2316 #endif
2317 )
2318 {
2319 addword (0x0170);
2320 add_fix ('l', &opP->disp, 1, 2);
2321 }
2322 else
2323 {
2324 add_frag (adds (&opP->disp),
2325 SEXT (offs (&opP->disp)),
2326 TAB (PCREL1632, SZ_UNDEF));
2327 break;
2328 }
2329 }
2330 else
2331 {
2332 addword (0x0170);
2333 add_fix ('l', &opP->disp, 0, 0);
2334 }
2335 }
2336 else
2337 addword (0x0170);
2338 addword (nextword >> 16);
2339 }
2340 else
2341 {
2342 if (opP->reg == PC)
2343 tmpreg = 0x3A; /* 7.2 */
2344 else
2345 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2346
2347 if (isvar (&opP->disp))
2348 {
2349 if (opP->reg == PC)
2350 {
2351 add_fix ('w', &opP->disp, 1, 0);
2352 }
2353 else
2354 add_fix ('w', &opP->disp, 0, 0);
2355 }
2356 }
2357 addword (nextword);
2358 break;
2359
2360 case POST:
2361 case PRE:
2362 case BASE:
2363 nextword = 0;
2364 baseo = get_num (&opP->disp, 90);
2365 if (opP->mode == POST || opP->mode == PRE)
2366 outro = get_num (&opP->odisp, 90);
2367 /* Figure out the `addressing mode'.
2368 Also turn on the BASE_DISABLE bit, if needed. */
2369 if (opP->reg == PC || opP->reg == ZPC)
2370 {
2371 tmpreg = 0x3b; /* 7.3 */
2372 if (opP->reg == ZPC)
2373 nextword |= 0x80;
2374 }
2375 else if (opP->reg == 0)
2376 {
2377 nextword |= 0x80;
2378 tmpreg = 0x30; /* 6.garbage */
2379 }
2380 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2381 {
2382 nextword |= 0x80;
2383 tmpreg = 0x30 + opP->reg - ZADDR0;
2384 }
2385 else
2386 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2387
2388 siz1 = opP->disp.size;
2389 if (opP->mode == POST || opP->mode == PRE)
2390 siz2 = opP->odisp.size;
2391 else
2392 siz2 = SIZE_UNSPEC;
2393
2394 /* Index register stuff. */
2395 if (opP->index.reg != 0
2396 && opP->index.reg >= DATA
2397 && opP->index.reg <= ADDR7)
2398 {
2399 nextword |= (opP->index.reg - DATA) << 12;
2400
2401 if (opP->index.size == SIZE_LONG
2402 || (opP->index.size == SIZE_UNSPEC
2403 && m68k_index_width_default == SIZE_LONG))
2404 nextword |= 0x800;
2405
2406 if ((opP->index.scale != 1
2407 && cpu_of_arch (current_architecture) < m68020)
2408 || (opP->index.scale == 8
2409 && (arch_coldfire_p (current_architecture)
2410 && !arch_coldfire_fpu (current_architecture))))
2411 {
2412 opP->error =
2413 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2414 }
2415
2416 if (arch_coldfire_p (current_architecture)
2417 && opP->index.size == SIZE_WORD)
2418 opP->error = _("invalid index size for coldfire");
2419
2420 switch (opP->index.scale)
2421 {
2422 case 1:
2423 break;
2424 case 2:
2425 nextword |= 0x200;
2426 break;
2427 case 4:
2428 nextword |= 0x400;
2429 break;
2430 case 8:
2431 nextword |= 0x600;
2432 break;
2433 default:
2434 abort ();
2435 }
2436 /* IF its simple,
2437 GET US OUT OF HERE! */
2438
2439 /* Must be INDEX, with an index register. Address
2440 register cannot be ZERO-PC, and either :b was
2441 forced, or we know it will fit. For a 68000 or
2442 68010, force this mode anyways, because the
2443 larger modes aren't supported. */
2444 if (opP->mode == BASE
2445 && ((opP->reg >= ADDR0
2446 && opP->reg <= ADDR7)
2447 || opP->reg == PC))
2448 {
2449 if (siz1 == SIZE_BYTE
2450 || cpu_of_arch (current_architecture) < m68020
2451 || arch_coldfire_p (current_architecture)
2452 || (siz1 == SIZE_UNSPEC
2453 && ! isvar (&opP->disp)
2454 && issbyte (baseo)))
2455 {
2456 nextword += baseo & 0xff;
2457 addword (nextword);
2458 if (isvar (&opP->disp))
2459 {
2460 /* Do a byte relocation. If it doesn't
2461 fit (possible on m68000) let the
2462 fixup processing complain later. */
2463 if (opP->reg == PC)
2464 add_fix ('B', &opP->disp, 1, 1);
2465 else
2466 add_fix ('B', &opP->disp, 0, 0);
2467 }
2468 else if (siz1 != SIZE_BYTE)
2469 {
2470 if (siz1 != SIZE_UNSPEC)
2471 as_warn (_("Forcing byte displacement"));
2472 if (! issbyte (baseo))
2473 opP->error = _("byte displacement out of range");
2474 }
2475
2476 break;
2477 }
2478 else if (siz1 == SIZE_UNSPEC
2479 && opP->reg == PC
2480 && isvar (&opP->disp)
2481 && subs (&opP->disp) == NULL
2482 #ifdef OBJ_ELF
2483 /* If the displacement needs pic
2484 relocation it cannot be relaxed. */
2485 && opP->disp.pic_reloc == pic_none
2486 #endif
2487 )
2488 {
2489 /* The code in md_convert_frag_1 needs to be
2490 able to adjust nextword. Call frag_grow
2491 to ensure that we have enough space in
2492 the frag obstack to make all the bytes
2493 contiguous. */
2494 frag_grow (14);
2495 nextword += baseo & 0xff;
2496 addword (nextword);
2497 add_frag (adds (&opP->disp),
2498 SEXT (offs (&opP->disp)),
2499 TAB (PCINDEX, SZ_UNDEF));
2500
2501 break;
2502 }
2503 }
2504 }
2505 else
2506 {
2507 nextword |= 0x40; /* No index reg. */
2508 if (opP->index.reg >= ZDATA0
2509 && opP->index.reg <= ZDATA7)
2510 nextword |= (opP->index.reg - ZDATA0) << 12;
2511 else if (opP->index.reg >= ZADDR0
2512 || opP->index.reg <= ZADDR7)
2513 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2514 }
2515
2516 /* It isn't simple. */
2517
2518 if (cpu_of_arch (current_architecture) < m68020
2519 || arch_coldfire_p (current_architecture))
2520 opP->error =
2521 _("invalid operand mode for this architecture; needs 68020 or higher");
2522
2523 nextword |= 0x100;
2524 /* If the guy specified a width, we assume that it is
2525 wide enough. Maybe it isn't. If so, we lose. */
2526 switch (siz1)
2527 {
2528 case SIZE_UNSPEC:
2529 if (isvar (&opP->disp)
2530 ? m68k_rel32
2531 : ! issword (baseo))
2532 {
2533 siz1 = SIZE_LONG;
2534 nextword |= 0x30;
2535 }
2536 else if (! isvar (&opP->disp) && baseo == 0)
2537 nextword |= 0x10;
2538 else
2539 {
2540 nextword |= 0x20;
2541 siz1 = SIZE_WORD;
2542 }
2543 break;
2544 case SIZE_BYTE:
2545 as_warn (_(":b not permitted; defaulting to :w"));
2546 /* Fall through. */
2547 case SIZE_WORD:
2548 nextword |= 0x20;
2549 break;
2550 case SIZE_LONG:
2551 nextword |= 0x30;
2552 break;
2553 }
2554
2555 /* Figure out inner displacement stuff. */
2556 if (opP->mode == POST || opP->mode == PRE)
2557 {
2558 if (cpu_of_arch (current_architecture) & cpu32)
2559 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2560 switch (siz2)
2561 {
2562 case SIZE_UNSPEC:
2563 if (isvar (&opP->odisp)
2564 ? m68k_rel32
2565 : ! issword (outro))
2566 {
2567 siz2 = SIZE_LONG;
2568 nextword |= 0x3;
2569 }
2570 else if (! isvar (&opP->odisp) && outro == 0)
2571 nextword |= 0x1;
2572 else
2573 {
2574 nextword |= 0x2;
2575 siz2 = SIZE_WORD;
2576 }
2577 break;
2578 case 1:
2579 as_warn (_(":b not permitted; defaulting to :w"));
2580 /* Fall through. */
2581 case 2:
2582 nextword |= 0x2;
2583 break;
2584 case 3:
2585 nextword |= 0x3;
2586 break;
2587 }
2588 if (opP->mode == POST
2589 && (nextword & 0x40) == 0)
2590 nextword |= 0x04;
2591 }
2592 addword (nextword);
2593
2594 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2595 {
2596 if (opP->reg == PC || opP->reg == ZPC)
2597 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2598 else
2599 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2600 }
2601 if (siz1 == SIZE_LONG)
2602 addword (baseo >> 16);
2603 if (siz1 != SIZE_UNSPEC)
2604 addword (baseo);
2605
2606 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2607 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2608 if (siz2 == SIZE_LONG)
2609 addword (outro >> 16);
2610 if (siz2 != SIZE_UNSPEC)
2611 addword (outro);
2612
2613 break;
2614
2615 case ABSL:
2616 nextword = get_num (&opP->disp, 90);
2617 switch (opP->disp.size)
2618 {
2619 default:
2620 abort ();
2621 case SIZE_UNSPEC:
2622 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2623 {
2624 tmpreg = 0x38; /* 7.0 */
2625 addword (nextword);
2626 break;
2627 }
2628 if (isvar (&opP->disp)
2629 && !subs (&opP->disp)
2630 && adds (&opP->disp)
2631 #ifdef OBJ_ELF
2632 /* If the displacement needs pic relocation it
2633 cannot be relaxed. */
2634 && opP->disp.pic_reloc == pic_none
2635 #endif
2636 && !flag_long_jumps
2637 && !strchr ("~%&$?", s[0]))
2638 {
2639 tmpreg = 0x3A; /* 7.2 */
2640 add_frag (adds (&opP->disp),
2641 SEXT (offs (&opP->disp)),
2642 TAB (ABSTOPCREL, SZ_UNDEF));
2643 break;
2644 }
2645 /* Fall through into long. */
2646 case SIZE_LONG:
2647 if (isvar (&opP->disp))
2648 add_fix ('l', &opP->disp, 0, 0);
2649
2650 tmpreg = 0x39;/* 7.1 mode */
2651 addword (nextword >> 16);
2652 addword (nextword);
2653 break;
2654
2655 case SIZE_BYTE:
2656 as_bad (_("unsupported byte value; use a different suffix"));
2657 /* Fall through. */
2658
2659 case SIZE_WORD:
2660 if (isvar (&opP->disp))
2661 add_fix ('w', &opP->disp, 0, 0);
2662
2663 tmpreg = 0x38;/* 7.0 mode */
2664 addword (nextword);
2665 break;
2666 }
2667 break;
2668 case CONTROL:
2669 case FPREG:
2670 default:
2671 as_bad (_("unknown/incorrect operand"));
2672 /* abort (); */
2673 }
2674
2675 /* If s[0] is '4', then this is for the mac instructions
2676 that can have a trailing_ampersand set. If so, set 0x100
2677 bit on tmpreg so install_gen_operand can check for it and
2678 set the appropriate bit (word2, bit 5). */
2679 if (s[0] == '4')
2680 {
2681 if (opP->trailing_ampersand)
2682 tmpreg |= 0x100;
2683 }
2684 install_gen_operand (s[1], tmpreg);
2685 break;
2686
2687 case '#':
2688 case '^':
2689 switch (s[1])
2690 { /* JF: I hate floating point! */
2691 case 'j':
2692 tmpreg = 70;
2693 break;
2694 case '8':
2695 tmpreg = 20;
2696 break;
2697 case 'C':
2698 tmpreg = 50;
2699 break;
2700 case '3':
2701 default:
2702 tmpreg = 90;
2703 break;
2704 }
2705 tmpreg = get_num (&opP->disp, tmpreg);
2706 if (isvar (&opP->disp))
2707 add_fix (s[1], &opP->disp, 0, 0);
2708 switch (s[1])
2709 {
2710 case 'b': /* Danger: These do no check for
2711 certain types of overflow.
2712 user beware! */
2713 if (!isbyte (tmpreg))
2714 opP->error = _("out of range");
2715 insop (tmpreg, opcode);
2716 if (isvar (&opP->disp))
2717 the_ins.reloc[the_ins.nrel - 1].n =
2718 (opcode->m_codenum) * 2 + 1;
2719 break;
2720 case 'B':
2721 if (!issbyte (tmpreg))
2722 opP->error = _("out of range");
2723 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2724 if (isvar (&opP->disp))
2725 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2726 break;
2727 case 'w':
2728 if (!isword (tmpreg))
2729 opP->error = _("out of range");
2730 insop (tmpreg, opcode);
2731 if (isvar (&opP->disp))
2732 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2733 break;
2734 case 'W':
2735 if (!issword (tmpreg))
2736 opP->error = _("out of range");
2737 insop (tmpreg, opcode);
2738 if (isvar (&opP->disp))
2739 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2740 break;
2741 case 'l':
2742 /* Because of the way insop works, we put these two out
2743 backwards. */
2744 insop (tmpreg, opcode);
2745 insop (tmpreg >> 16, opcode);
2746 if (isvar (&opP->disp))
2747 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2748 break;
2749 case '3':
2750 tmpreg &= 0xFF;
2751 case '8':
2752 case 'C':
2753 case 'j':
2754 install_operand (s[1], tmpreg);
2755 break;
2756 default:
2757 abort ();
2758 }
2759 break;
2760
2761 case '+':
2762 case '-':
2763 case 'A':
2764 case 'a':
2765 install_operand (s[1], opP->reg - ADDR);
2766 break;
2767
2768 case 'B':
2769 tmpreg = get_num (&opP->disp, 90);
2770 switch (s[1])
2771 {
2772 case 'B':
2773 add_fix ('B', &opP->disp, 1, -1);
2774 break;
2775 case 'W':
2776 word_branch: /* (TIGCC 20050130) */
2777 add_fix ('w', &opP->disp, 1, 0);
2778 addword (0);
2779 break;
2780 case 'L':
2781 long_branch:
2782 if (! HAVE_LONG_BRANCH (current_architecture))
2783 as_warn (_("Can't use long branches on 68000/68010/5200"));
2784 the_ins.opcode[0] |= 0xff;
2785 add_fix ('l', &opP->disp, 1, 0);
2786 addword (0);
2787 addword (0);
2788 break;
2789 case 'G': /* (TIGCC 20050130) */
2790 /* (TIGCC 20050130) We want only branches (word). -- Kevin Kofler */
2791 if (subs (&opP->disp)) /* We can't relax it. */
2792 goto word_branch;
2793
2794 #ifdef OBJ_ELF
2795 /* If the displacement needs pic relocation it cannot be
2796 relaxed. */
2797 if (opP->disp.pic_reloc != pic_none)
2798 goto word_branch;
2799 #endif
2800 add_frag (adds (&opP->disp), offs (&opP->disp),
2801 TAB (BRANCHBW, SZ_UNDEF));
2802 break;
2803 case 'g':
2804 if (subs (&opP->disp)) /* We can't relax it. */
2805 goto long_branch;
2806
2807 #ifdef OBJ_ELF
2808 /* If the displacement needs pic relocation it cannot be
2809 relaxed. */
2810 if (opP->disp.pic_reloc != pic_none)
2811 goto long_branch;
2812 #endif
2813 /* This could either be a symbol, or an absolute
2814 address. If it's an absolute address, turn it into
2815 an absolute jump right here and keep it out of the
2816 relaxer. */
2817 if (adds (&opP->disp) == 0)
2818 {
2819 if (the_ins.opcode[0] == 0x6000) /* jbra */
2820 the_ins.opcode[0] = 0x4EF9;
2821 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2822 the_ins.opcode[0] = 0x4EB9;
2823 else /* jCC */
2824 {
2825 /* (TIGCC 20030902) Add a PC-relative reloc (unconditionally, because
2826 it will be removed later on if not in all-relocs
2827 mode). -- Kevin Kofler */
2828 struct m68k_exp temp_expr = {SIZE_UNSPEC,
2829 {symbol_new (FAKE_LABEL_NAME, now_seg, (valueT) frag_now_fix () + 8, frag_now),
2830 NULL, 0, O_symbol, 0, 0}};
2831 the_ins.opcode[0] ^= 0x0100;
2832 the_ins.opcode[0] |= 0x0006;
2833 add_fix ('B' /*case-sensitive!*/, &temp_expr, 1 /*PCREL*/, -1 /*PCREL fix for bytes*/);
2834 addword (0x4EF9);
2835 }
2836 add_fix ('l', &opP->disp, 0, 0);
2837 addword (0);
2838 addword (0);
2839 break;
2840 }
2841
2842 /* Now we know it's going into the relaxer. Now figure
2843 out which mode. We try in this order of preference:
2844 long branch, absolute jump, byte/word branches only. */
2845 if (HAVE_LONG_BRANCH (current_architecture))
2846 add_frag (adds (&opP->disp),
2847 SEXT (offs (&opP->disp)),
2848 TAB (BRANCHBWL, SZ_UNDEF));
2849 else if (! flag_keep_pcrel)
2850 {
2851 if ((the_ins.opcode[0] == 0x6000)
2852 || (the_ins.opcode[0] == 0x6100))
2853 add_frag (adds (&opP->disp),
2854 SEXT (offs (&opP->disp)),
2855 TAB (BRABSJUNC, SZ_UNDEF));
2856 else
2857 add_frag (adds (&opP->disp),
2858 SEXT (offs (&opP->disp)),
2859 TAB (BRABSJCOND, SZ_UNDEF));
2860 }
2861 else
2862 add_frag (adds (&opP->disp),
2863 SEXT (offs (&opP->disp)),
2864 TAB (BRANCHBW, SZ_UNDEF));
2865 break;
2866 case 'w':
2867 if (isvar (&opP->disp))
2868 {
2869 /* Check for DBcc instructions. We can relax them,
2870 but only if we have long branches and/or absolute
2871 jumps. */
2872 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2873 && (HAVE_LONG_BRANCH (current_architecture)
2874 || (! flag_keep_pcrel)))
2875 {
2876 if (HAVE_LONG_BRANCH (current_architecture))
2877 add_frag (adds (&opP->disp),
2878 SEXT (offs (&opP->disp)),
2879 TAB (DBCCLBR, SZ_UNDEF));
2880 else
2881 add_frag (adds (&opP->disp),
2882 SEXT (offs (&opP->disp)),
2883 TAB (DBCCABSJ, SZ_UNDEF));
2884 break;
2885 }
2886 add_fix ('w', &opP->disp, 1, 0);
2887 }
2888 addword (0);
2889 break;
2890 case 'C': /* Fixed size LONG coproc branches. */
2891 add_fix ('l', &opP->disp, 1, 0);
2892 addword (0);
2893 addword (0);
2894 break;
2895 case 'c': /* Var size Coprocesssor branches. */
2896 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2897 {
2898 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2899 add_fix ('l', &opP->disp, 1, 0);
2900 addword (0);
2901 addword (0);
2902 }
2903 else
2904 add_frag (adds (&opP->disp),
2905 SEXT (offs (&opP->disp)),
2906 TAB (FBRANCH, SZ_UNDEF));
2907 break;
2908 default:
2909 abort ();
2910 }
2911 break;
2912
2913 case 'C': /* Ignore it. */
2914 break;
2915
2916 case 'd': /* JF this is a kludge. */
2917 install_operand ('s', opP->reg - ADDR);
2918 tmpreg = get_num (&opP->disp, 90);
2919 if (!issword (tmpreg))
2920 {
2921 as_warn (_("Expression out of range, using 0"));
2922 tmpreg = 0;
2923 }
2924 addword (tmpreg);
2925 break;
2926
2927 case 'D':
2928 install_operand (s[1], opP->reg - DATA);
2929 break;
2930
2931 case 'e': /* EMAC ACCx, reg/reg. */
2932 install_operand (s[1], opP->reg - ACC);
2933 break;
2934
2935 case 'E': /* Ignore it. */
2936 break;
2937
2938 case 'F':
2939 install_operand (s[1], opP->reg - FP0);
2940 break;
2941
2942 case 'g': /* EMAC ACCEXTx. */
2943 install_operand (s[1], opP->reg - ACCEXT01);
2944 break;
2945
2946 case 'G': /* Ignore it. */
2947 case 'H':
2948 break;
2949
2950 case 'I':
2951 tmpreg = opP->reg - COP0;
2952 install_operand (s[1], tmpreg);
2953 break;
2954
2955 case 'i': /* MAC/EMAC scale factor. */
2956 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
2957 break;
2958
2959 case 'J': /* JF foo. */
2960 switch (opP->reg)
2961 {
2962 case SFC:
2963 tmpreg = 0x000;
2964 break;
2965 case DFC:
2966 tmpreg = 0x001;
2967 break;
2968 case CACR:
2969 tmpreg = 0x002;
2970 break;
2971 case TC:
2972 tmpreg = 0x003;
2973 break;
2974 case ACR0:
2975 case ITT0:
2976 tmpreg = 0x004;
2977 break;
2978 case ACR1:
2979 case ITT1:
2980 tmpreg = 0x005;
2981 break;
2982 case ACR2:
2983 case DTT0:
2984 tmpreg = 0x006;
2985 break;
2986 case ACR3:
2987 case DTT1:
2988 tmpreg = 0x007;
2989 break;
2990 case BUSCR:
2991 tmpreg = 0x008;
2992 break;
2993
2994 case USP:
2995 tmpreg = 0x800;
2996 break;
2997 case VBR:
2998 tmpreg = 0x801;
2999 break;
3000 case CAAR:
3001 tmpreg = 0x802;
3002 break;
3003 case MSP:
3004 tmpreg = 0x803;
3005 break;
3006 case ISP:
3007 tmpreg = 0x804;
3008 break;
3009 case MMUSR:
3010 tmpreg = 0x805;
3011 break;
3012 case URP:
3013 tmpreg = 0x806;
3014 break;
3015 case SRP:
3016 tmpreg = 0x807;
3017 break;
3018 case PCR:
3019 tmpreg = 0x808;
3020 break;
3021 case ROMBAR:
3022 tmpreg = 0xC00;
3023 break;
3024 case ROMBAR1:
3025 tmpreg = 0xC01;
3026 break;
3027 case FLASHBAR:
3028 case RAMBAR0:
3029 tmpreg = 0xC04;
3030 break;
3031 case RAMBAR:
3032 case RAMBAR1:
3033 tmpreg = 0xC05;
3034 break;
3035 case MPCR:
3036 tmpreg = 0xC0C;
3037 break;
3038 case EDRAMBAR:
3039 tmpreg = 0xC0D;
3040 break;
3041 case MBAR0:
3042 case MBAR2:
3043 case SECMBAR:
3044 tmpreg = 0xC0E;
3045 break;
3046 case MBAR1:
3047 case MBAR:
3048 tmpreg = 0xC0F;
3049 break;
3050 case PCR1U0:
3051 tmpreg = 0xD02;
3052 break;
3053 case PCR1L0:
3054 tmpreg = 0xD03;
3055 break;
3056 case PCR2U0:
3057 tmpreg = 0xD04;
3058 break;
3059 case PCR2L0:
3060 tmpreg = 0xD05;
3061 break;
3062 case PCR3U0:
3063 tmpreg = 0xD06;
3064 break;
3065 case PCR3L0:
3066 tmpreg = 0xD07;
3067 break;
3068 case PCR1L1:
3069 tmpreg = 0xD0A;
3070 break;
3071 case PCR1U1:
3072 tmpreg = 0xD0B;
3073 break;
3074 case PCR2L1:
3075 tmpreg = 0xD0C;
3076 break;
3077 case PCR2U1:
3078 tmpreg = 0xD0D;
3079 break;
3080 case PCR3L1:
3081 tmpreg = 0xD0E;
3082 break;
3083 case PCR3U1:
3084 tmpreg = 0xD0F;
3085 break;
3086 default:
3087 abort ();
3088 }
3089 install_operand (s[1], tmpreg);
3090 break;
3091
3092 case 'k':
3093 tmpreg = get_num (&opP->disp, 55);
3094 install_operand (s[1], tmpreg & 0x7f);
3095 break;
3096
3097 case 'l':
3098 tmpreg = opP->mask;
3099 if (s[1] == 'w')
3100 {
3101 if (tmpreg & 0x7FF0000)
3102 as_bad (_("Floating point register in register list"));
3103 insop (reverse_16_bits (tmpreg), opcode);
3104 }
3105 else
3106 {
3107 if (tmpreg & 0x700FFFF)
3108 as_bad (_("Wrong register in floating-point reglist"));
3109 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3110 }
3111 break;
3112
3113 case 'L':
3114 tmpreg = opP->mask;
3115 if (s[1] == 'w')
3116 {
3117 if (tmpreg & 0x7FF0000)
3118 as_bad (_("Floating point register in register list"));
3119 insop (tmpreg, opcode);
3120 }
3121 else if (s[1] == '8')
3122 {
3123 if (tmpreg & 0x0FFFFFF)
3124 as_bad (_("incorrect register in reglist"));
3125 install_operand (s[1], tmpreg >> 24);
3126 }
3127 else
3128 {
3129 if (tmpreg & 0x700FFFF)
3130 as_bad (_("wrong register in floating-point reglist"));
3131 else
3132 install_operand (s[1], tmpreg >> 16);
3133 }
3134 break;
3135
3136 case 'M':
3137 install_operand (s[1], get_num (&opP->disp, 60));
3138 break;
3139
3140 case 'O':
3141 tmpreg = ((opP->mode == DREG)
3142 ? 0x20 + (int) (opP->reg - DATA)
3143 : (get_num (&opP->disp, 40) & 0x1F));
3144 install_operand (s[1], tmpreg);
3145 break;
3146
3147 case 'Q':
3148 tmpreg = get_num (&opP->disp, 10);
3149 if (tmpreg == 8)
3150 tmpreg = 0;
3151 install_operand (s[1], tmpreg);
3152 break;
3153
3154 case 'R':
3155 /* This depends on the fact that ADDR registers are eight
3156 more than their corresponding DATA regs, so the result
3157 will have the ADDR_REG bit set. */
3158 install_operand (s[1], opP->reg - DATA);
3159 break;
3160
3161 case 'r':
3162 if (opP->mode == AINDR)
3163 install_operand (s[1], opP->reg - DATA);
3164 else
3165 install_operand (s[1], opP->index.reg - DATA);
3166 break;
3167
3168 case 's':
3169 if (opP->reg == FPI)
3170 tmpreg = 0x1;
3171 else if (opP->reg == FPS)
3172 tmpreg = 0x2;
3173 else if (opP->reg == FPC)
3174 tmpreg = 0x4;
3175 else
3176 abort ();
3177 install_operand (s[1], tmpreg);
3178 break;
3179
3180 case 'S': /* Ignore it. */
3181 break;
3182
3183 case 'T':
3184 install_operand (s[1], get_num (&opP->disp, 30));
3185 break;
3186
3187 case 'U': /* Ignore it. */
3188 break;
3189
3190 case 'c':
3191 switch (opP->reg)
3192 {
3193 case NC:
3194 tmpreg = 0;
3195 break;
3196 case DC:
3197 tmpreg = 1;
3198 break;
3199 case IC:
3200 tmpreg = 2;
3201 break;
3202 case BC:
3203 tmpreg = 3;
3204 break;
3205 default:
3206 as_fatal (_("failed sanity check"));
3207 } /* switch on cache token. */
3208 install_operand (s[1], tmpreg);
3209 break;
3210 #ifndef NO_68851
3211 /* JF: These are out of order, I fear. */
3212 case 'f':
3213 switch (opP->reg)
3214 {
3215 case SFC:
3216 tmpreg = 0;
3217 break;
3218 case DFC:
3219 tmpreg = 1;
3220 break;
3221 default:
3222 abort ();
3223 }
3224 install_operand (s[1], tmpreg);
3225 break;
3226
3227 case '0':
3228 case '1':
3229 case '2':
3230 switch (opP->reg)
3231 {
3232 case TC:
3233 tmpreg = 0;
3234 break;
3235 case CAL:
3236 tmpreg = 4;
3237 break;
3238 case VAL:
3239 tmpreg = 5;
3240 break;
3241 case SCC:
3242 tmpreg = 6;
3243 break;
3244 case AC:
3245 tmpreg = 7;
3246 break;
3247 default:
3248 abort ();
3249 }
3250 install_operand (s[1], tmpreg);
3251 break;
3252
3253 case 'V':
3254 if (opP->reg == VAL)
3255 break;
3256 abort ();
3257
3258 case 'W':
3259 switch (opP->reg)
3260 {
3261 case DRP:
3262 tmpreg = 1;
3263 break;
3264 case SRP:
3265 tmpreg = 2;
3266 break;
3267 case CRP:
3268 tmpreg = 3;
3269 break;
3270 default:
3271 abort ();
3272 }
3273 install_operand (s[1], tmpreg);
3274 break;
3275
3276 case 'X':
3277 switch (opP->reg)
3278 {
3279 case BAD:
3280 case BAD + 1:
3281 case BAD + 2:
3282 case BAD + 3:
3283 case BAD + 4:
3284 case BAD + 5:
3285 case BAD + 6:
3286 case BAD + 7:
3287 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3288 break;
3289
3290 case BAC:
3291 case BAC + 1:
3292 case BAC + 2:
3293 case BAC + 3:
3294 case BAC + 4:
3295 case BAC + 5:
3296 case BAC + 6:
3297 case BAC + 7:
3298 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3299 break;
3300
3301 default:
3302 abort ();
3303 }
3304 install_operand (s[1], tmpreg);
3305 break;
3306 case 'Y':
3307 know (opP->reg == PSR);
3308 break;
3309 case 'Z':
3310 know (opP->reg == PCSR);
3311 break;
3312 #endif /* m68851 */
3313 case '3':
3314 switch (opP->reg)
3315 {
3316 case TT0:
3317 tmpreg = 2;
3318 break;
3319 case TT1:
3320 tmpreg = 3;
3321 break;
3322 default:
3323 abort ();
3324 }
3325 install_operand (s[1], tmpreg);
3326 break;
3327 case 't':
3328 tmpreg = get_num (&opP->disp, 20);
3329 install_operand (s[1], tmpreg);
3330 break;
3331 case '_': /* used only for move16 absolute 32-bit address. */
3332 if (isvar (&opP->disp))
3333 add_fix ('l', &opP->disp, 0, 0);
3334 tmpreg = get_num (&opP->disp, 90);
3335 addword (tmpreg >> 16);
3336 addword (tmpreg & 0xFFFF);
3337 break;
3338 case 'u':
3339 install_operand (s[1], opP->reg - DATA0L);
3340 opP->reg -= (DATA0L);
3341 opP->reg &= 0x0F; /* remove upper/lower bit. */
3342 break;
3343 case 'x':
3344 tmpreg = get_num (&opP->disp, 80);
3345 if (tmpreg == -1)
3346 tmpreg = 0;
3347 install_operand (s[1], tmpreg);
3348 break;
3349 default:
3350 abort ();
3351 }
3352 }
3353
3354 /* By the time whe get here (FINALLY) the_ins contains the complete
3355 instruction, ready to be emitted. . . */
3356 }
3357
3358 static int
reverse_16_bits(int in)3359 reverse_16_bits (int in)
3360 {
3361 int out = 0;
3362 int n;
3363
3364 static int mask[16] =
3365 {
3366 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3367 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3368 };
3369 for (n = 0; n < 16; n++)
3370 {
3371 if (in & mask[n])
3372 out |= mask[15 - n];
3373 }
3374 return out;
3375 } /* reverse_16_bits() */
3376
3377 static int
reverse_8_bits(int in)3378 reverse_8_bits (int in)
3379 {
3380 int out = 0;
3381 int n;
3382
3383 static int mask[8] =
3384 {
3385 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3386 };
3387
3388 for (n = 0; n < 8; n++)
3389 {
3390 if (in & mask[n])
3391 out |= mask[7 - n];
3392 }
3393 return out;
3394 } /* reverse_8_bits() */
3395
3396 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3397 (that value is chosen in the frag_var call in md_assemble). TYPE
3398 is the subtype of the frag to be generated; its primary type is
3399 rs_machine_dependent.
3400
3401 The TYPE parameter is also used by md_convert_frag_1 and
3402 md_estimate_size_before_relax. The appropriate type of fixup will
3403 be emitted by md_convert_frag_1.
3404
3405 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3406 static void
install_operand(int mode,int val)3407 install_operand (int mode, int val)
3408 {
3409 switch (mode)
3410 {
3411 case 's':
3412 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3413 break;
3414 case 'd':
3415 the_ins.opcode[0] |= val << 9;
3416 break;
3417 case '1':
3418 the_ins.opcode[1] |= val << 12;
3419 break;
3420 case '2':
3421 the_ins.opcode[1] |= val << 6;
3422 break;
3423 case '3':
3424 the_ins.opcode[1] |= val;
3425 break;
3426 case '4':
3427 the_ins.opcode[2] |= val << 12;
3428 break;
3429 case '5':
3430 the_ins.opcode[2] |= val << 6;
3431 break;
3432 case '6':
3433 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3434 three words long! */
3435 the_ins.numo++;
3436 the_ins.opcode[2] |= val;
3437 break;
3438 case '7':
3439 the_ins.opcode[1] |= val << 7;
3440 break;
3441 case '8':
3442 the_ins.opcode[1] |= val << 10;
3443 break;
3444 #ifndef NO_68851
3445 case '9':
3446 the_ins.opcode[1] |= val << 5;
3447 break;
3448 #endif
3449
3450 case 't':
3451 the_ins.opcode[1] |= (val << 10) | (val << 7);
3452 break;
3453 case 'D':
3454 the_ins.opcode[1] |= (val << 12) | val;
3455 break;
3456 case 'g':
3457 the_ins.opcode[0] |= val = 0xff;
3458 break;
3459 case 'i':
3460 the_ins.opcode[0] |= val << 9;
3461 break;
3462 case 'C':
3463 the_ins.opcode[1] |= val;
3464 break;
3465 case 'j':
3466 the_ins.opcode[1] |= val;
3467 the_ins.numo++; /* What a hack. */
3468 break;
3469 case 'k':
3470 the_ins.opcode[1] |= val << 4;
3471 break;
3472 case 'b':
3473 case 'w':
3474 case 'W':
3475 case 'l':
3476 break;
3477 case 'e':
3478 the_ins.opcode[0] |= (val << 6);
3479 break;
3480 case 'L':
3481 the_ins.opcode[1] = (val >> 16);
3482 the_ins.opcode[2] = val & 0xffff;
3483 break;
3484 case 'm':
3485 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3486 the_ins.opcode[0] |= ((val & 0x7) << 9);
3487 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3488 break;
3489 case 'n': /* MAC/EMAC Rx on !load. */
3490 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3491 the_ins.opcode[0] |= ((val & 0x7) << 9);
3492 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3493 break;
3494 case 'o': /* MAC/EMAC Rx on load. */
3495 the_ins.opcode[1] |= val << 12;
3496 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3497 break;
3498 case 'M': /* MAC/EMAC Ry on !load. */
3499 the_ins.opcode[0] |= (val & 0xF);
3500 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3501 break;
3502 case 'N': /* MAC/EMAC Ry on load. */
3503 the_ins.opcode[1] |= (val & 0xF);
3504 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3505 break;
3506 case 'h':
3507 the_ins.opcode[1] |= ((val != 1) << 10);
3508 break;
3509 case 'F':
3510 the_ins.opcode[0] |= ((val & 0x3) << 9);
3511 break;
3512 case 'f':
3513 the_ins.opcode[0] |= ((val & 0x3) << 0);
3514 break;
3515 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3516 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3517 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3518 break;
3519 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3520 the_ins.opcode[0] |= ((val & 0x1) << 7);
3521 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3522 break;
3523 case 'I':
3524 the_ins.opcode[1] |= ((val & 0x3) << 9);
3525 break;
3526 case ']':
3527 the_ins.opcode[0] |= (val & 0x1) <<10;
3528 break;
3529 case 'c':
3530 default:
3531 as_fatal (_("failed sanity check."));
3532 }
3533 }
3534
3535 static void
install_gen_operand(int mode,int val)3536 install_gen_operand (int mode, int val)
3537 {
3538 switch (mode)
3539 {
3540 case '/': /* Special for mask loads for mac/msac insns with
3541 possible mask; trailing_ampersend set in bit 8. */
3542 the_ins.opcode[0] |= (val & 0x3f);
3543 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3544 break;
3545 case 's':
3546 the_ins.opcode[0] |= val;
3547 break;
3548 case 'd':
3549 /* This is a kludge!!! */
3550 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3551 break;
3552 case 'b':
3553 case 'w':
3554 case 'l':
3555 case 'f':
3556 case 'F':
3557 case 'x':
3558 case 'p':
3559 the_ins.opcode[0] |= val;
3560 break;
3561 /* more stuff goes here. */
3562 default:
3563 as_fatal (_("failed sanity check."));
3564 }
3565 }
3566
3567 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3568 then deal with the bitfield hack. */
3569
3570 static char *
crack_operand(char * str,struct m68k_op * opP)3571 crack_operand (char *str, struct m68k_op *opP)
3572 {
3573 register int parens;
3574 register int c;
3575 register char *beg_str;
3576 int inquote = 0;
3577
3578 if (!str)
3579 {
3580 return str;
3581 }
3582 beg_str = str;
3583 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3584 {
3585 if (! inquote)
3586 {
3587 if (*str == '(')
3588 parens++;
3589 else if (*str == ')')
3590 {
3591 if (!parens)
3592 { /* ERROR. */
3593 opP->error = _("Extra )");
3594 return str;
3595 }
3596 --parens;
3597 }
3598 }
3599 if (flag_mri && *str == '\'')
3600 inquote = ! inquote;
3601 }
3602 if (!*str && parens)
3603 { /* ERROR. */
3604 opP->error = _("Missing )");
3605 return str;
3606 }
3607 c = *str;
3608 *str = '\0';
3609 if (m68k_ip_op (beg_str, opP) != 0)
3610 {
3611 *str = c;
3612 return str;
3613 }
3614 *str = c;
3615 if (c == '}')
3616 c = *++str; /* JF bitfield hack. */
3617 if (c)
3618 {
3619 c = *++str;
3620 if (!c)
3621 as_bad (_("Missing operand"));
3622 }
3623
3624 /* Detect MRI REG symbols and convert them to REGLSTs. */
3625 if (opP->mode == CONTROL && (int)opP->reg < 0)
3626 {
3627 opP->mode = REGLST;
3628 opP->mask = ~(int)opP->reg;
3629 opP->reg = 0;
3630 }
3631
3632 return str;
3633 }
3634
3635 /* This is the guts of the machine-dependent assembler. STR points to a
3636 machine dependent instruction. This function is supposed to emit
3637 the frags/bytes it assembles to.
3638 */
3639
3640 static void
insert_reg(const char * regname,int regnum)3641 insert_reg (const char *regname, int regnum)
3642 {
3643 char buf[100];
3644 int i;
3645
3646 #ifdef REGISTER_PREFIX
3647 if (!flag_reg_prefix_optional)
3648 {
3649 buf[0] = REGISTER_PREFIX;
3650 strcpy (buf + 1, regname);
3651 regname = buf;
3652 }
3653 #endif
3654
3655 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3656 &zero_address_frag));
3657
3658 for (i = 0; regname[i]; i++)
3659 buf[i] = TOUPPER (regname[i]);
3660 buf[i] = '\0';
3661
3662 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3663 &zero_address_frag));
3664 }
3665
3666 struct init_entry
3667 {
3668 const char *name;
3669 int number;
3670 };
3671
3672 static const struct init_entry init_table[] =
3673 {
3674 { "d0", DATA0 },
3675 { "d1", DATA1 },
3676 { "d2", DATA2 },
3677 { "d3", DATA3 },
3678 { "d4", DATA4 },
3679 { "d5", DATA5 },
3680 { "d6", DATA6 },
3681 { "d7", DATA7 },
3682 { "a0", ADDR0 },
3683 { "a1", ADDR1 },
3684 { "a2", ADDR2 },
3685 { "a3", ADDR3 },
3686 { "a4", ADDR4 },
3687 { "a5", ADDR5 },
3688 { "a6", ADDR6 },
3689 { "fp", ADDR6 },
3690 { "a7", ADDR7 },
3691 { "sp", ADDR7 },
3692 { "ssp", ADDR7 },
3693 { "fp0", FP0 },
3694 { "fp1", FP1 },
3695 { "fp2", FP2 },
3696 { "fp3", FP3 },
3697 { "fp4", FP4 },
3698 { "fp5", FP5 },
3699 { "fp6", FP6 },
3700 { "fp7", FP7 },
3701 { "fpi", FPI },
3702 { "fpiar", FPI },
3703 { "fpc", FPI },
3704 { "fps", FPS },
3705 { "fpsr", FPS },
3706 { "fpc", FPC },
3707 { "fpcr", FPC },
3708 { "control", FPC },
3709 { "status", FPS },
3710 { "iaddr", FPI },
3711
3712 { "cop0", COP0 },
3713 { "cop1", COP1 },
3714 { "cop2", COP2 },
3715 { "cop3", COP3 },
3716 { "cop4", COP4 },
3717 { "cop5", COP5 },
3718 { "cop6", COP6 },
3719 { "cop7", COP7 },
3720 { "pc", PC },
3721 { "zpc", ZPC },
3722 { "sr", SR },
3723
3724 { "ccr", CCR },
3725 { "cc", CCR },
3726
3727 { "acc", ACC },
3728 { "acc0", ACC },
3729 { "acc1", ACC1 },
3730 { "acc2", ACC2 },
3731 { "acc3", ACC3 },
3732 { "accext01", ACCEXT01 },
3733 { "accext23", ACCEXT23 },
3734 { "macsr", MACSR },
3735 { "mask", MASK },
3736
3737 /* Control registers. */
3738 { "sfc", SFC }, /* Source Function Code. */
3739 { "sfcr", SFC },
3740 { "dfc", DFC }, /* Destination Function Code. */
3741 { "dfcr", DFC },
3742 { "cacr", CACR }, /* Cache Control Register. */
3743 { "caar", CAAR }, /* Cache Address Register. */
3744
3745 { "usp", USP }, /* User Stack Pointer. */
3746 { "vbr", VBR }, /* Vector Base Register. */
3747 { "msp", MSP }, /* Master Stack Pointer. */
3748 { "isp", ISP }, /* Interrupt Stack Pointer. */
3749
3750 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
3751 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
3752 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
3753 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
3754
3755 /* 68ec040 versions of same */
3756 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
3757 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
3758 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
3759 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
3760
3761 /* mcf5200 versions of same. The ColdFire programmer's reference
3762 manual indicated that the order is 2,3,0,1, but Ken Rose
3763 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3764 { "acr0", ACR0 }, /* Access Control Unit 0. */
3765 { "acr1", ACR1 }, /* Access Control Unit 1. */
3766 { "acr2", ACR2 }, /* Access Control Unit 2. */
3767 { "acr3", ACR3 }, /* Access Control Unit 3. */
3768
3769 { "tc", TC }, /* MMU Translation Control Register. */
3770 { "tcr", TC },
3771
3772 { "mmusr", MMUSR }, /* MMU Status Register. */
3773 { "srp", SRP }, /* User Root Pointer. */
3774 { "urp", URP }, /* Supervisor Root Pointer. */
3775
3776 { "buscr", BUSCR },
3777 { "pcr", PCR },
3778
3779 { "rombar", ROMBAR }, /* ROM Base Address Register. */
3780 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
3781 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
3782 { "mbar", MBAR }, /* Module Base Address Register. */
3783
3784 { "mbar0", MBAR0 }, /* mcfv4e registers. */
3785 { "mbar1", MBAR1 }, /* mcfv4e registers. */
3786 { "rombar0", ROMBAR }, /* mcfv4e registers. */
3787 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
3788 { "mpcr", MPCR }, /* mcfv4e registers. */
3789 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
3790 { "secmbar", SECMBAR }, /* mcfv4e registers. */
3791 { "asid", TC }, /* mcfv4e registers. */
3792 { "mmubar", BUSCR }, /* mcfv4e registers. */
3793 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
3794 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
3795 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
3796 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
3797 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
3798 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
3799 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
3800 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
3801 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
3802 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
3803 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
3804 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
3805
3806 { "flashbar", FLASHBAR }, /* mcf528x registers. */
3807 { "rambar", RAMBAR }, /* mcf528x registers. */
3808
3809 { "mbar2", MBAR2 }, /* mcf5249 registers. */
3810 /* End of control registers. */
3811
3812 { "ac", AC },
3813 { "bc", BC },
3814 { "cal", CAL },
3815 { "crp", CRP },
3816 { "drp", DRP },
3817 { "pcsr", PCSR },
3818 { "psr", PSR },
3819 { "scc", SCC },
3820 { "val", VAL },
3821 { "bad0", BAD0 },
3822 { "bad1", BAD1 },
3823 { "bad2", BAD2 },
3824 { "bad3", BAD3 },
3825 { "bad4", BAD4 },
3826 { "bad5", BAD5 },
3827 { "bad6", BAD6 },
3828 { "bad7", BAD7 },
3829 { "bac0", BAC0 },
3830 { "bac1", BAC1 },
3831 { "bac2", BAC2 },
3832 { "bac3", BAC3 },
3833 { "bac4", BAC4 },
3834 { "bac5", BAC5 },
3835 { "bac6", BAC6 },
3836 { "bac7", BAC7 },
3837
3838 { "ic", IC },
3839 { "dc", DC },
3840 { "nc", NC },
3841
3842 { "tt0", TT0 },
3843 { "tt1", TT1 },
3844 /* 68ec030 versions of same. */
3845 { "ac0", TT0 },
3846 { "ac1", TT1 },
3847 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3848 { "acusr", PSR },
3849
3850 /* Suppressed data and address registers. */
3851 { "zd0", ZDATA0 },
3852 { "zd1", ZDATA1 },
3853 { "zd2", ZDATA2 },
3854 { "zd3", ZDATA3 },
3855 { "zd4", ZDATA4 },
3856 { "zd5", ZDATA5 },
3857 { "zd6", ZDATA6 },
3858 { "zd7", ZDATA7 },
3859 { "za0", ZADDR0 },
3860 { "za1", ZADDR1 },
3861 { "za2", ZADDR2 },
3862 { "za3", ZADDR3 },
3863 { "za4", ZADDR4 },
3864 { "za5", ZADDR5 },
3865 { "za6", ZADDR6 },
3866 { "za7", ZADDR7 },
3867
3868 /* Upper and lower data and address registers, used by macw and msacw. */
3869 { "d0l", DATA0L },
3870 { "d1l", DATA1L },
3871 { "d2l", DATA2L },
3872 { "d3l", DATA3L },
3873 { "d4l", DATA4L },
3874 { "d5l", DATA5L },
3875 { "d6l", DATA6L },
3876 { "d7l", DATA7L },
3877
3878 { "a0l", ADDR0L },
3879 { "a1l", ADDR1L },
3880 { "a2l", ADDR2L },
3881 { "a3l", ADDR3L },
3882 { "a4l", ADDR4L },
3883 { "a5l", ADDR5L },
3884 { "a6l", ADDR6L },
3885 { "a7l", ADDR7L },
3886
3887 { "d0u", DATA0U },
3888 { "d1u", DATA1U },
3889 { "d2u", DATA2U },
3890 { "d3u", DATA3U },
3891 { "d4u", DATA4U },
3892 { "d5u", DATA5U },
3893 { "d6u", DATA6U },
3894 { "d7u", DATA7U },
3895
3896 { "a0u", ADDR0U },
3897 { "a1u", ADDR1U },
3898 { "a2u", ADDR2U },
3899 { "a3u", ADDR3U },
3900 { "a4u", ADDR4U },
3901 { "a5u", ADDR5U },
3902 { "a6u", ADDR6U },
3903 { "a7u", ADDR7U },
3904
3905 { 0, 0 }
3906 };
3907
3908 static void
init_regtable(void)3909 init_regtable (void)
3910 {
3911 int i;
3912 for (i = 0; init_table[i].name; i++)
3913 insert_reg (init_table[i].name, init_table[i].number);
3914 }
3915
3916 static int no_68851, no_68881;
3917
3918 #ifdef OBJ_AOUT
3919 /* a.out machine type. Default to 68020. */
3920 int m68k_aout_machtype = 2;
3921 #endif
3922
3923 void
md_assemble(char * str)3924 md_assemble (char *str)
3925 {
3926 const char *er;
3927 short *fromP;
3928 char *toP = NULL;
3929 int m, n = 0;
3930 char *to_beg_P;
3931 int shorts_this_frag;
3932 fixS *fixP;
3933
3934 /* In MRI mode, the instruction and operands are separated by a
3935 space. Anything following the operands is a comment. The label
3936 has already been removed. */
3937 if (flag_mri)
3938 {
3939 char *s;
3940 int fields = 0;
3941 int infield = 0;
3942 int inquote = 0;
3943
3944 for (s = str; *s != '\0'; s++)
3945 {
3946 if ((*s == ' ' || *s == '\t') && ! inquote)
3947 {
3948 if (infield)
3949 {
3950 ++fields;
3951 if (fields >= 2)
3952 {
3953 *s = '\0';
3954 break;
3955 }
3956 infield = 0;
3957 }
3958 }
3959 else
3960 {
3961 if (! infield)
3962 infield = 1;
3963 if (*s == '\'')
3964 inquote = ! inquote;
3965 }
3966 }
3967 }
3968
3969 memset (&the_ins, '\0', sizeof (the_ins));
3970 m68k_ip (str);
3971 er = the_ins.error;
3972 if (!er)
3973 {
3974 for (n = 0; n < the_ins.numargs; n++)
3975 if (the_ins.operands[n].error)
3976 {
3977 er = the_ins.operands[n].error;
3978 break;
3979 }
3980 }
3981 if (er)
3982 {
3983 as_bad (_("%s -- statement `%s' ignored"), er, str);
3984 return;
3985 }
3986
3987 /* If there is a current label, record that it marks an instruction. */
3988 if (current_label != NULL)
3989 {
3990 current_label->text = 1;
3991 current_label = NULL;
3992 }
3993
3994 #if 1 /*def OBJ_ELF*/
3995 /* Tie dwarf2 debug info to the address at the start of the insn. */
3996 dwarf2_emit_insn (0);
3997 #endif
3998
3999 if (the_ins.nfrag == 0)
4000 {
4001 /* No frag hacking involved; just put it out. */
4002 toP = frag_more (2 * the_ins.numo);
4003 fromP = &the_ins.opcode[0];
4004 for (m = the_ins.numo; m; --m)
4005 {
4006 md_number_to_chars (toP, (long) (*fromP), 2);
4007 toP += 2;
4008 fromP++;
4009 }
4010 /* Put out symbol-dependent info. */
4011 for (m = 0; m < the_ins.nrel; m++)
4012 {
4013 switch (the_ins.reloc[m].wid)
4014 {
4015 case 'B':
4016 n = 1;
4017 break;
4018 case 'b':
4019 n = 1;
4020 break;
4021 case '3':
4022 n = 1;
4023 break;
4024 case 'w':
4025 case 'W':
4026 n = 2;
4027 break;
4028 case 'l':
4029 n = 4;
4030 break;
4031 default:
4032 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
4033 the_ins.reloc[m].wid);
4034 }
4035
4036 fixP = fix_new_exp (frag_now,
4037 ((toP - frag_now->fr_literal)
4038 - the_ins.numo * 2 + the_ins.reloc[m].n),
4039 n,
4040 &the_ins.reloc[m].exp,
4041 the_ins.reloc[m].pcrel,
4042 get_reloc_code (n, the_ins.reloc[m].pcrel,
4043 the_ins.reloc[m].pic_reloc));
4044 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4045 if (the_ins.reloc[m].wid == 'B')
4046 fixP->fx_signed = 1;
4047 /* (TIGCC 20050130) These relocs are by definition the ones which cannot
4048 be "relaxed" - or "optimized" in ld-tigcc terms.
4049 Excepted from this are byte branches because the
4050 linker must be able to remove them entirely.
4051 -- Kevin Kofler */
4052 else
4053 fixP->fx_unoptimizable = 1;
4054 }
4055 return;
4056 }
4057
4058 /* There's some frag hacking. */
4059 {
4060 /* Calculate the max frag size. */
4061 int wid;
4062
4063 wid = 2 * the_ins.fragb[0].fragoff;
4064 for (n = 1; n < the_ins.nfrag; n++)
4065 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4066 /* frag_var part. */
4067 wid += 10;
4068 /* Make sure the whole insn fits in one chunk, in particular that
4069 the var part is attached, as we access one byte before the
4070 variable frag for byte branches. */
4071 frag_grow (wid);
4072 }
4073
4074 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
4075 {
4076 int wid;
4077
4078 if (n == 0)
4079 wid = 2 * the_ins.fragb[n].fragoff;
4080 else
4081 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4082 toP = frag_more (wid);
4083 to_beg_P = toP;
4084 shorts_this_frag = 0;
4085 for (m = wid / 2; m; --m)
4086 {
4087 md_number_to_chars (toP, (long) (*fromP), 2);
4088 toP += 2;
4089 fromP++;
4090 shorts_this_frag++;
4091 }
4092 for (m = 0; m < the_ins.nrel; m++)
4093 {
4094 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
4095 {
4096 the_ins.reloc[m].n -= 2 * shorts_this_frag;
4097 break;
4098 }
4099 wid = the_ins.reloc[m].wid;
4100 if (wid == 0)
4101 continue;
4102 the_ins.reloc[m].wid = 0;
4103 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4104
4105 fixP = fix_new_exp (frag_now,
4106 ((toP - frag_now->fr_literal)
4107 - the_ins.numo * 2 + the_ins.reloc[m].n),
4108 wid,
4109 &the_ins.reloc[m].exp,
4110 the_ins.reloc[m].pcrel,
4111 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4112 the_ins.reloc[m].pic_reloc));
4113 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4114 /* (TIGCC 20050130) These relocs are by definition the ones which cannot
4115 be "relaxed" - or "optimized" in ld-tigcc terms.
4116 -- Kevin Kofler */
4117 fixP->fx_unoptimizable = 1;
4118 }
4119 (void) frag_var (rs_machine_dependent, 10, 0,
4120 (relax_substateT) (the_ins.fragb[n].fragty),
4121 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4122 }
4123 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4124 shorts_this_frag = 0;
4125 if (n)
4126 {
4127 toP = frag_more (n * 2);
4128 while (n--)
4129 {
4130 md_number_to_chars (toP, (long) (*fromP), 2);
4131 toP += 2;
4132 fromP++;
4133 shorts_this_frag++;
4134 }
4135 }
4136 for (m = 0; m < the_ins.nrel; m++)
4137 {
4138 int wid;
4139
4140 wid = the_ins.reloc[m].wid;
4141 if (wid == 0)
4142 continue;
4143 the_ins.reloc[m].wid = 0;
4144 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4145
4146 fixP = fix_new_exp (frag_now,
4147 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4148 - shorts_this_frag * 2),
4149 wid,
4150 &the_ins.reloc[m].exp,
4151 the_ins.reloc[m].pcrel,
4152 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4153 the_ins.reloc[m].pic_reloc));
4154 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4155 /* (TIGCC 20050130) These relocs are by definition the ones which cannot
4156 be "relaxed" - or "optimized" in ld-tigcc terms.
4157 -- Kevin Kofler */
4158 fixP->fx_unoptimizable = 1;
4159 }
4160 }
4161
4162 /* Comparison function used by qsort to rank the opcode entries by name. */
4163
4164 static int
m68k_compare_opcode(const void * v1,const void * v2)4165 m68k_compare_opcode (const void * v1, const void * v2)
4166 {
4167 struct m68k_opcode * op1, * op2;
4168 int ret;
4169
4170 op1 = *(struct m68k_opcode **) v1;
4171 op2 = *(struct m68k_opcode **) v2;
4172
4173 /* Compare the two names. If different, return the comparison.
4174 If the same, return the order they are in the opcode table. */
4175 ret = strcmp (op1->name, op2->name);
4176 if (ret)
4177 return ret;
4178 if (op1 < op2)
4179 return -1;
4180 if (op1 > op2)
4181 return 1; /* (TIGCC 200505611) This is required for Windows. -- Kevin Kofler */
4182 return 0;
4183 }
4184
4185 void
md_begin(void)4186 md_begin (void)
4187 {
4188 const struct m68k_opcode *ins;
4189 struct m68k_incant *hack, *slak;
4190 const char *retval = 0; /* Empty string, or error msg text. */
4191 int i;
4192
4193 /* Set up hash tables with 68000 instructions.
4194 similar to what the vax assembler does. */
4195 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4196 a copy of it at runtime, adding in the information we want but isn't
4197 there. I think it'd be better to have an awk script hack the table
4198 at compile time. Or even just xstr the table and use it as-is. But
4199 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4200 names. */
4201
4202 if (flag_mri)
4203 {
4204 flag_reg_prefix_optional = 1;
4205 m68k_abspcadd = 1;
4206 if (! m68k_rel32_from_cmdline)
4207 m68k_rel32 = 0;
4208 }
4209
4210 /* First sort the opcode table into alphabetical order to seperate
4211 the order that the assembler wants to see the opcodes from the
4212 order that the disassembler wants to see them. */
4213 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4214 if (!m68k_sorted_opcodes)
4215 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4216 m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4217
4218 for (i = m68k_numopcodes; i--;)
4219 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4220
4221 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4222 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4223
4224 op_hash = hash_new ();
4225
4226 obstack_begin (&robyn, 4000);
4227 for (i = 0; i < m68k_numopcodes; i++)
4228 {
4229 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
4230 do
4231 {
4232 ins = m68k_sorted_opcodes[i];
4233
4234 /* We *could* ignore insns that don't match our
4235 arch here by just leaving them out of the hash. */
4236 slak->m_operands = ins->args;
4237 slak->m_opnum = strlen (slak->m_operands) / 2;
4238 slak->m_arch = ins->arch;
4239 slak->m_opcode = ins->opcode;
4240 /* This is kludgey. */
4241 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
4242 if (i + 1 != m68k_numopcodes
4243 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4244 {
4245 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4246 i++;
4247 }
4248 else
4249 slak->m_next = 0;
4250 slak = slak->m_next;
4251 }
4252 while (slak);
4253
4254 retval = hash_insert (op_hash, ins->name, (char *) hack);
4255 if (retval)
4256 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4257 }
4258
4259 for (i = 0; i < m68k_numaliases; i++)
4260 {
4261 const char *name = m68k_opcode_aliases[i].primary;
4262 const char *alias = m68k_opcode_aliases[i].alias;
4263 PTR val = hash_find (op_hash, name);
4264
4265 if (!val)
4266 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4267 retval = hash_insert (op_hash, alias, val);
4268 if (retval)
4269 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4270 }
4271
4272 /* In MRI mode, all unsized branches are variable sized. Normally,
4273 they are word sized. */
4274 if (flag_mri)
4275 {
4276 static struct m68k_opcode_alias mri_aliases[] =
4277 {
4278 { "bhi", "jhi", },
4279 { "bls", "jls", },
4280 { "bcc", "jcc", },
4281 { "bcs", "jcs", },
4282 { "bne", "jne", },
4283 { "beq", "jeq", },
4284 { "bvc", "jvc", },
4285 { "bvs", "jvs", },
4286 { "bpl", "jpl", },
4287 { "bmi", "jmi", },
4288 { "bge", "jge", },
4289 { "blt", "jlt", },
4290 { "bgt", "jgt", },
4291 { "ble", "jle", },
4292 { "bra", "jra", },
4293 { "bsr", "jbsr", },
4294 };
4295
4296 for (i = 0;
4297 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4298 i++)
4299 {
4300 const char *name = mri_aliases[i].primary;
4301 const char *alias = mri_aliases[i].alias;
4302 PTR val = hash_find (op_hash, name);
4303
4304 if (!val)
4305 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4306 retval = hash_jam (op_hash, alias, val);
4307 if (retval)
4308 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4309 }
4310 }
4311
4312 for (i = 0; i < (int) sizeof (notend_table); i++)
4313 {
4314 notend_table[i] = 0;
4315 alt_notend_table[i] = 0;
4316 }
4317
4318 notend_table[','] = 1;
4319 notend_table['{'] = 1;
4320 notend_table['}'] = 1;
4321 alt_notend_table['a'] = 1;
4322 alt_notend_table['A'] = 1;
4323 alt_notend_table['d'] = 1;
4324 alt_notend_table['D'] = 1;
4325 alt_notend_table['#'] = 1;
4326 alt_notend_table['&'] = 1;
4327 alt_notend_table['f'] = 1;
4328 alt_notend_table['F'] = 1;
4329 #ifdef REGISTER_PREFIX
4330 alt_notend_table[REGISTER_PREFIX] = 1;
4331 #endif
4332
4333 /* We need to put '(' in alt_notend_table to handle
4334 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4335 alt_notend_table['('] = 1;
4336
4337 /* We need to put '@' in alt_notend_table to handle
4338 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4339 alt_notend_table['@'] = 1;
4340
4341 /* We need to put digits in alt_notend_table to handle
4342 bfextu %d0{24:1},%d0 */
4343 alt_notend_table['0'] = 1;
4344 alt_notend_table['1'] = 1;
4345 alt_notend_table['2'] = 1;
4346 alt_notend_table['3'] = 1;
4347 alt_notend_table['4'] = 1;
4348 alt_notend_table['5'] = 1;
4349 alt_notend_table['6'] = 1;
4350 alt_notend_table['7'] = 1;
4351 alt_notend_table['8'] = 1;
4352 alt_notend_table['9'] = 1;
4353
4354 #ifndef MIT_SYNTAX_ONLY
4355 /* Insert pseudo ops, these have to go into the opcode table since
4356 gas expects pseudo ops to start with a dot. */
4357 {
4358 int n = 0;
4359
4360 while (mote_pseudo_table[n].poc_name)
4361 {
4362 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4363 hash_insert (op_hash,
4364 mote_pseudo_table[n].poc_name, (char *) hack);
4365 hack->m_operands = 0;
4366 hack->m_opnum = n;
4367 n++;
4368 }
4369 }
4370 #endif
4371
4372 init_regtable ();
4373
4374 #ifdef OBJ_ELF
4375 record_alignment (text_section, 2);
4376 record_alignment (data_section, 2);
4377 record_alignment (bss_section, 2);
4378 #endif
4379 }
4380
4381 static void
select_control_regs(void)4382 select_control_regs (void)
4383 {
4384 /* Note which set of "movec" control registers is available. */
4385 switch (current_chip)
4386 {
4387 case 0:
4388 if (verbose)
4389 as_warn (_("architecture not yet selected: defaulting to 68020"));
4390 control_regs = m68020_control_regs;
4391 break;
4392
4393 case m68000:
4394 control_regs = m68000_control_regs;
4395 break;
4396 case m68010:
4397 control_regs = m68010_control_regs;
4398 break;
4399 case m68020:
4400 case m68030:
4401 control_regs = m68020_control_regs;
4402 break;
4403 case m68040:
4404 control_regs = m68040_control_regs;
4405 break;
4406 case m68060:
4407 control_regs = m68060_control_regs;
4408 break;
4409 case cpu32:
4410 control_regs = cpu32_control_regs;
4411 break;
4412 case mcf5200:
4413 case mcf5206e:
4414 case mcf5307:
4415 case mcf5407:
4416 control_regs = mcf_control_regs;
4417 break;
4418 case mcf5249:
4419 control_regs = mcf5249_control_regs;
4420 break;
4421 case mcf528x:
4422 case mcf521x:
4423 control_regs = mcf528x_control_regs;
4424 break;
4425 case mcf5470:
4426 case mcf5480:
4427 control_regs = mcfv4e_control_regs;
4428 break;
4429 default:
4430 abort ();
4431 }
4432 }
4433
4434 void
m68k_init_after_args(void)4435 m68k_init_after_args (void)
4436 {
4437 if (cpu_of_arch (current_architecture) == 0)
4438 {
4439 int i;
4440 const char *default_cpu = TARGET_CPU;
4441
4442 if (*default_cpu == 'm')
4443 default_cpu++;
4444 for (i = 0; i < n_archs; i++)
4445 if (strcasecmp (default_cpu, archs[i].name) == 0)
4446 break;
4447 if (i == n_archs)
4448 {
4449 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
4450 current_architecture |= m68020;
4451 }
4452 else
4453 current_architecture |= archs[i].arch;
4454 }
4455 /* Permit m68881 specification with all cpus; those that can't work
4456 with a coprocessor could be doing emulation. */
4457 if (current_architecture & m68851)
4458 {
4459 if (current_architecture & m68040)
4460 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4461 }
4462 /* What other incompatibilities could we check for? */
4463
4464 /* Toss in some default assumptions about coprocessors. */
4465 if (!no_68881
4466 && (cpu_of_arch (current_architecture)
4467 /* Can CPU32 have a 68881 coprocessor?? */
4468 & (m68020 | m68030 | cpu32)))
4469 current_architecture |= m68881;
4470
4471 if (!no_68851
4472 && (cpu_of_arch (current_architecture) & m68020up) != 0
4473 && (cpu_of_arch (current_architecture) & m68040up) == 0)
4474 current_architecture |= m68851;
4475
4476 if (no_68881 && (current_architecture & m68881))
4477 as_bad (_("options for 68881 and no-68881 both given"));
4478
4479 if (no_68851 && (current_architecture & m68851))
4480 as_bad (_("options for 68851 and no-68851 both given"));
4481
4482 #ifdef OBJ_AOUT
4483 /* Work out the magic number. This isn't very general. */
4484 if (current_architecture & m68000)
4485 m68k_aout_machtype = 0;
4486 else if (current_architecture & m68010)
4487 m68k_aout_machtype = 1;
4488 else if (current_architecture & m68020)
4489 m68k_aout_machtype = 2;
4490 else
4491 m68k_aout_machtype = 2;
4492 #endif
4493
4494 /* Note which set of "movec" control registers is available. */
4495 select_control_regs ();
4496
4497 if (cpu_of_arch (current_architecture) < m68020
4498 || arch_coldfire_p (current_architecture))
4499 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
4500 }
4501
4502 /* This is called when a label is defined. */
4503
4504 void
m68k_frob_label(symbolS * sym)4505 m68k_frob_label (symbolS *sym)
4506 {
4507 struct label_line *n;
4508
4509 n = (struct label_line *) xmalloc (sizeof *n);
4510 n->next = labels;
4511 n->label = sym;
4512 as_where (&n->file, &n->line);
4513 n->text = 0;
4514 labels = n;
4515 current_label = n;
4516 }
4517
4518 /* This is called when a value that is not an instruction is emitted. */
4519
4520 void
m68k_flush_pending_output(void)4521 m68k_flush_pending_output (void)
4522 {
4523 current_label = NULL;
4524 }
4525
4526 /* This is called at the end of the assembly, when the final value of
4527 the label is known. We warn if this is a text symbol aligned at an
4528 odd location. */
4529
4530 void
m68k_frob_symbol(symbolS * sym)4531 m68k_frob_symbol (symbolS *sym)
4532 {
4533 if (S_GET_SEGMENT (sym) == reg_section
4534 && (int) S_GET_VALUE (sym) < 0)
4535 {
4536 S_SET_SEGMENT (sym, absolute_section);
4537 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4538 }
4539 else if ((S_GET_VALUE (sym) & 1) != 0)
4540 {
4541 struct label_line *l;
4542
4543 for (l = labels; l != NULL; l = l->next)
4544 {
4545 if (l->label == sym)
4546 {
4547 if (l->text)
4548 as_warn_where (l->file, l->line,
4549 _("text label `%s' aligned to odd boundary"),
4550 S_GET_NAME (sym));
4551 break;
4552 }
4553 }
4554 }
4555 }
4556
4557 /* This is called if we go in or out of MRI mode because of the .mri
4558 pseudo-op. */
4559
4560 void
m68k_mri_mode_change(int on)4561 m68k_mri_mode_change (int on)
4562 {
4563 if (on)
4564 {
4565 if (! flag_reg_prefix_optional)
4566 {
4567 flag_reg_prefix_optional = 1;
4568 #ifdef REGISTER_PREFIX
4569 init_regtable ();
4570 #endif
4571 }
4572 m68k_abspcadd = 1;
4573 if (! m68k_rel32_from_cmdline)
4574 m68k_rel32 = 0;
4575 }
4576 else
4577 {
4578 if (! reg_prefix_optional_seen)
4579 {
4580 #ifdef REGISTER_PREFIX_OPTIONAL
4581 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4582 #else
4583 flag_reg_prefix_optional = 0;
4584 #endif
4585 #ifdef REGISTER_PREFIX
4586 init_regtable ();
4587 #endif
4588 }
4589 m68k_abspcadd = 0;
4590 if (! m68k_rel32_from_cmdline)
4591 m68k_rel32 = 1;
4592 }
4593 }
4594
4595 /* Equal to MAX_PRECISION in atof-ieee.c. */
4596 #define MAX_LITTLENUMS 6
4597
4598 /* Turn a string in input_line_pointer into a floating point constant
4599 of type TYPE, and store the appropriate bytes in *LITP. The number
4600 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4601 returned, or NULL on OK. */
4602
4603 char *
md_atof(int type,char * litP,int * sizeP)4604 md_atof (int type, char *litP, int *sizeP)
4605 {
4606 int prec;
4607 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4608 LITTLENUM_TYPE *wordP;
4609 char *t;
4610
4611 switch (type)
4612 {
4613 case 'f':
4614 case 'F':
4615 case 's':
4616 case 'S':
4617 prec = 2;
4618 break;
4619
4620 case 'd':
4621 case 'D':
4622 case 'r':
4623 case 'R':
4624 prec = 4;
4625 break;
4626
4627 case 'x':
4628 case 'X':
4629 prec = 6;
4630 break;
4631
4632 case 'p':
4633 case 'P':
4634 prec = 6;
4635 break;
4636
4637 default:
4638 *sizeP = 0;
4639 return _("Bad call to MD_ATOF()");
4640 }
4641 t = atof_ieee (input_line_pointer, type, words);
4642 if (t)
4643 input_line_pointer = t;
4644
4645 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4646 for (wordP = words; prec--;)
4647 {
4648 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4649 litP += sizeof (LITTLENUM_TYPE);
4650 }
4651 return 0;
4652 }
4653
4654 void
md_number_to_chars(char * buf,valueT val,int n)4655 md_number_to_chars (char *buf, valueT val, int n)
4656 {
4657 number_to_chars_bigendian (buf, val, n);
4658 }
4659
4660 void
md_apply_fix3(fixS * fixP,valueT * valP,segT seg ATTRIBUTE_UNUSED)4661 md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
4662 {
4663 offsetT val = *valP;
4664 addressT upper_limit;
4665 offsetT lower_limit;
4666
4667 /* This is unnecessary but it convinces the native rs6000 compiler
4668 to generate the code we want. */
4669 char *buf = fixP->fx_frag->fr_literal;
4670 buf += fixP->fx_where;
4671 /* End ibm compiler workaround. */
4672
4673 val = SEXT (val);
4674
4675 /* (TIGCC 20030716) We aren't done when we still have something to subtract.
4676 -- Kevin Kofler */
4677 if (fixP->fx_addsy == NULL && fixP->fx_subsy == NULL && fixP->fx_pcrel == 0)
4678 fixP->fx_done = 1;
4679
4680 #ifdef OBJ_ELF
4681 if (fixP->fx_addsy)
4682 {
4683 memset (buf, 0, fixP->fx_size);
4684 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4685
4686 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4687 && !S_IS_DEFINED (fixP->fx_addsy)
4688 && !S_IS_WEAK (fixP->fx_addsy))
4689 S_SET_WEAK (fixP->fx_addsy);
4690 return;
4691 }
4692 #endif
4693
4694 #ifdef BFD_ASSEMBLER
4695 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4696 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4697 return;
4698 #endif
4699
4700 /* Fix up a negative reloc. */
4701 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4702 {
4703 fixP->fx_addsy = fixP->fx_subsy;
4704 fixP->fx_subsy = NULL;
4705 fixP->fx_tcbit = 1;
4706 val = -val; /* (TIGCC 20030716) */
4707 }
4708 /* (TIGCC 20030716) Fix up an address difference by splitting it into its
4709 components.
4710 Fix up subtraction of the dot symbol by changing the reloc
4711 to PC-relative (disabled 20030717). -- Kevin Kofler
4712 (TIGCC 20040807) For common symbols, the value is the size, not the
4713 position, so don't use it. -- Kevin Kofler */
4714 else if (fixP->fx_addsy != NULL && fixP->fx_subsy != NULL)
4715 {
4716 #if 0 /* (TIGCC 20030717) This is unnecessary (see expr.c fix) and probably wrong. */
4717 if (!~fixP->fx_subsy->sy_number) { /* detect the dot symbol */
4718 /* make the reloc PC-relative: */
4719 val += md_pcrel_from (fixP);
4720 fixP->fx_offset = *valP = val;
4721 fixP->fx_pcrel = 1;
4722 fixP->fx_subsy = NULL;
4723 } else {
4724 #endif
4725 fixS *negreloc = fix_new (fixP->fx_frag, fixP->fx_where, fixP->fx_size,
4726 fixP->fx_subsy, fixP->fx_offset
4727 + (S_IS_COMMON (fixP->fx_addsy) ? 0 : S_GET_VALUE (fixP->fx_addsy))
4728 + segment_info[S_GET_SEGMENT (fixP->fx_addsy)].scnhdr.s_paddr
4729 - (((S_IS_COMMON (fixP->fx_subsy) ? 0 : S_GET_VALUE (fixP->fx_subsy))
4730 + segment_info[S_GET_SEGMENT (fixP->fx_subsy)].scnhdr.s_paddr)
4731 << 1) /* (TIGCC 20030717) Yes, we need to subtract this twice!
4732 This kludge compensates for later incorrect
4733 computations in obj-coff.c. -- Kevin Kofler */,
4734 0, 0);
4735 if (negreloc) {
4736 fixP->fx_offset = 0; /* We have transferred the offset to the negative reloc. */
4737 fixP->fx_pcrel = 0;
4738 fixP->fx_subsy = NULL;
4739 negreloc->fx_tcbit = 1;
4740 /* turn off range checking for both relocs: */
4741 fixP->fx_im_disp = negreloc->fx_im_disp = 1;
4742 }
4743 #if 0
4744 }
4745 #endif
4746 }
4747
4748 /* (TIGCC 20030716) Moved this down so val can be adjusted. -- Kevin Kofler */
4749 switch (fixP->fx_size)
4750 {
4751 /* The cast to offsetT below are necessary to make code
4752 correct for machines where ints are smaller than offsetT. */
4753 case 1:
4754 *buf++ = val;
4755 upper_limit = 0x7f;
4756 lower_limit = - (offsetT) 0x80;
4757 break;
4758 case 2:
4759 *buf++ = (val >> 8);
4760 *buf++ = val;
4761 upper_limit = 0x7fff;
4762 lower_limit = - (offsetT) 0x8000;
4763 break;
4764 case 4:
4765 *buf++ = (val >> 24);
4766 *buf++ = (val >> 16);
4767 *buf++ = (val >> 8);
4768 *buf++ = val;
4769 upper_limit = 0x7fffffff;
4770 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4771 break;
4772 default:
4773 BAD_CASE (fixP->fx_size);
4774 }
4775
4776 /* (TIGCC 20030716) Reuse fx_im_disp to turn off range checking. -- Kevin Kofler */
4777 if (fixP->fx_im_disp) return;
4778
4779 /* For non-pc-relative values, it's conceivable we might get something
4780 like "0xff" for a byte field. So extend the upper part of the range
4781 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4782 so that we can do any range checking at all. */
4783 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4784 upper_limit = upper_limit * 2 + 1;
4785
4786 /* (TIGCC 20050507) We can't properly range-check PC-relative relocs in
4787 all-relocs mode because of COFF VMA annoyances. Ideally, the section
4788 contents should be just unrelocated offsets which can be properly
4789 range-checked, but unfortunately COFF is designed with unrelocated use in
4790 mind and relocation as an afterthought. And moreover, we need to
4791 range-check in the linker anyway, as only the linker knows the final
4792 section disposition. So let's just let the linker worry about
4793 range-checking. */
4794 if (fixP->fx_pcrel)
4795 fixP->fx_im_disp = 1;
4796 else if ((addressT) val > upper_limit
4797 && (val > 0 || val < lower_limit))
4798 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4799
4800 /* A one byte PC-relative reloc means a short branch. We can't use
4801 a short branch with a value of 0 or -1, because those indicate
4802 different opcodes (branches with longer offsets). fixup_segment
4803 in write.c may have clobbered fx_pcrel, so we need to examine the
4804 reloc type. */
4805 if ((fixP->fx_pcrel
4806 #ifdef BFD_ASSEMBLER
4807 || fixP->fx_r_type == BFD_RELOC_8_PCREL
4808 #endif
4809 )
4810 && fixP->fx_size == 1
4811 && (fixP->fx_addsy == NULL
4812 || S_IS_DEFINED (fixP->fx_addsy))
4813 && (val == 0 || val == -1))
4814 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4815 }
4816
4817 /* *fragP has been relaxed to its final size, and now needs to have
4818 the bytes inside it modified to conform to the new size There is UGLY
4819 MAGIC here. ..
4820 */
4821 static void
md_convert_frag_1(fragS * fragP)4822 md_convert_frag_1 (fragS *fragP)
4823 {
4824 long disp;
4825 fixS *fixP;
4826
4827 /* Address in object code of the displacement. */
4828 register int object_address = fragP->fr_fix + fragP->fr_address;
4829
4830 /* Address in gas core of the place to store the displacement. */
4831 /* This convinces the native rs6000 compiler to generate the code we
4832 want. */
4833 register char *buffer_address = fragP->fr_literal;
4834 buffer_address += fragP->fr_fix;
4835 /* End ibm compiler workaround. */
4836
4837 /* The displacement of the address, from current location. */
4838 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4839 disp = (disp + fragP->fr_offset) - object_address;
4840
4841 switch (fragP->fr_subtype)
4842 {
4843 case TAB (BRANCHBWL, BYTE):
4844 case TAB (BRABSJUNC, BYTE):
4845 case TAB (BRABSJCOND, BYTE):
4846 case TAB (BRANCHBW, BYTE):
4847 know (issbyte (disp));
4848 if (disp == 0)
4849 as_bad_where (fragP->fr_file, fragP->fr_line,
4850 _("short branch with zero offset: use :w"));
4851 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4852 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4853 fixP->fx_pcrel_adjust = -1;
4854 break;
4855 case TAB (BRANCHBWL, SHORT):
4856 case TAB (BRABSJUNC, SHORT):
4857 case TAB (BRABSJCOND, SHORT):
4858 case TAB (BRANCHBW, SHORT):
4859 fragP->fr_opcode[1] = 0x00;
4860 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4861 1, RELAX_RELOC_PC16);
4862 fragP->fr_fix += 2;
4863 break;
4864 case TAB (BRANCHBWL, LONG):
4865 fragP->fr_opcode[1] = (char) 0xFF;
4866 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4867 1, RELAX_RELOC_PC32);
4868 fragP->fr_fix += 4;
4869 break;
4870 case TAB (BRABSJUNC, LONG):
4871 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4872 {
4873 if (flag_keep_pcrel)
4874 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4875 fragP->fr_opcode[0] = 0x4E;
4876 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4877 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4878 0, RELAX_RELOC_ABS32);
4879 fragP->fr_fix += 4;
4880 }
4881 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4882 {
4883 if (flag_keep_pcrel)
4884 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4885 fragP->fr_opcode[0] = 0x4E;
4886 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4887 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4888 0, RELAX_RELOC_ABS32);
4889 fragP->fr_fix += 4;
4890 }
4891 else
4892 {
4893 /* This cannot happen, because jbsr and jbra are the only two
4894 unconditional branches. */
4895 abort ();
4896 }
4897 break;
4898 case TAB (BRABSJCOND, LONG):
4899 if (flag_keep_pcrel)
4900 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4901
4902 /* Only Bcc 68000 instructions can come here
4903 Change bcc into b!cc/jmp absl long. */
4904 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
4905 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
4906
4907 /* (TIGCC 20030902) Add a PC-relative reloc (unconditionally, because
4908 it will be removed later on if not in all-relocs
4909 mode). -- Kevin Kofler
4910 (TIGCC 20030908) Unfortunately, we cannot create symbols here for some
4911 reason, so we create the symbol in advance in
4912 md_estimate_size_before_relax and store it into the
4913 frag structure of the next frag. Here, we only have to
4914 read it. -- Kevin Kofler, patch by Sebastian Reichelt
4915 */
4916 {
4917 fragS *nextFragP = fragP->fr_next;
4918 symbolS *symbolP = NULL;
4919 if (nextFragP)
4920 symbolP = nextFragP->fr_start_symbol;
4921
4922 if (symbolP)
4923 fix_new (fragP, fragP->fr_fix - 1, 1, symbolP, -1, 1, RELAX_RELOC_PC8);
4924 else
4925 as_warn_where (fragP->fr_file, fragP->fr_line, _("no symbol available for pseudo-op code"));
4926 }
4927
4928 /* JF: these used to be fr_opcode[2,3], but they may be in a
4929 different frag, in which case referring to them is a no-no.
4930 Only fr_opcode[0,1] are guaranteed to work. */
4931 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4932 *buffer_address++ = (char) 0xf9;
4933 fragP->fr_fix += 2; /* Account for jmp instruction. */
4934 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4935 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4936 fragP->fr_fix += 4;
4937 break;
4938 case TAB (FBRANCH, SHORT):
4939 know ((fragP->fr_opcode[1] & 0x40) == 0);
4940 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4941 1, RELAX_RELOC_PC16);
4942 fragP->fr_fix += 2;
4943 break;
4944 case TAB (FBRANCH, LONG):
4945 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
4946 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4947 1, RELAX_RELOC_PC32);
4948 fragP->fr_fix += 4;
4949 break;
4950 case TAB (DBCCLBR, SHORT):
4951 case TAB (DBCCABSJ, SHORT):
4952 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4953 1, RELAX_RELOC_PC16);
4954 fragP->fr_fix += 2;
4955 break;
4956 case TAB (DBCCLBR, LONG):
4957 /* Only DBcc instructions can come here.
4958 Change dbcc into dbcc/bral.
4959 JF: these used to be fr_opcode[2-7], but that's wrong. */
4960 if (flag_keep_pcrel)
4961 as_fatal (_("Tried to convert DBcc to absolute jump"));
4962
4963 *buffer_address++ = 0x00; /* Branch offset = 4. */
4964 *buffer_address++ = 0x04;
4965 *buffer_address++ = 0x60; /* Put in bra pc+6. */
4966 *buffer_address++ = 0x06;
4967 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4968 *buffer_address++ = (char) 0xff;
4969
4970 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4971 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4972 RELAX_RELOC_PC32);
4973 fragP->fr_fix += 4;
4974 break;
4975 case TAB (DBCCABSJ, LONG):
4976 /* Only DBcc instructions can come here.
4977 Change dbcc into dbcc/jmp.
4978 JF: these used to be fr_opcode[2-7], but that's wrong. */
4979 if (flag_keep_pcrel)
4980 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4981
4982 *buffer_address++ = 0x00; /* Branch offset = 4. */
4983 *buffer_address++ = 0x04;
4984 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
4985 *buffer_address++ = 0x06;
4986 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4987 *buffer_address++ = (char) 0xf9;
4988
4989 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4990 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4991 RELAX_RELOC_ABS32);
4992 fragP->fr_fix += 4;
4993 break;
4994 case TAB (PCREL1632, SHORT):
4995 fragP->fr_opcode[1] &= ~0x3F;
4996 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4997 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4998 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4999 fragP->fr_fix += 2;
5000 break;
5001 case TAB (PCREL1632, LONG):
5002 /* Already set to mode 7.3; this indicates: PC indirect with
5003 suppressed index, 32-bit displacement. */
5004 *buffer_address++ = 0x01;
5005 *buffer_address++ = 0x70;
5006 fragP->fr_fix += 2;
5007 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
5008 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5009 fixP->fx_pcrel_adjust = 2;
5010 fragP->fr_fix += 4;
5011 break;
5012 case TAB (PCINDEX, BYTE):
5013 assert (fragP->fr_fix >= 2);
5014 buffer_address[-2] &= ~1;
5015 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
5016 fragP->fr_offset, 1, RELAX_RELOC_PC8);
5017 fixP->fx_pcrel_adjust = 1;
5018 break;
5019 case TAB (PCINDEX, SHORT):
5020 assert (fragP->fr_fix >= 2);
5021 buffer_address[-2] |= 0x1;
5022 buffer_address[-1] = 0x20;
5023 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
5024 fragP->fr_offset, 1, RELAX_RELOC_PC16);
5025 fixP->fx_pcrel_adjust = 2;
5026 fragP->fr_fix += 2;
5027 break;
5028 case TAB (PCINDEX, LONG):
5029 assert (fragP->fr_fix >= 2);
5030 buffer_address[-2] |= 0x1;
5031 buffer_address[-1] = 0x30;
5032 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
5033 fragP->fr_offset, 1, RELAX_RELOC_PC32);
5034 fixP->fx_pcrel_adjust = 2;
5035 fragP->fr_fix += 4;
5036 break;
5037 case TAB (ABSTOPCREL, SHORT):
5038 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
5039 1, RELAX_RELOC_PC16);
5040 fragP->fr_fix += 2;
5041 break;
5042 case TAB (ABSTOPCREL, LONG):
5043 if (flag_keep_pcrel)
5044 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
5045 /* The thing to do here is force it to ABSOLUTE LONG, since
5046 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
5047 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
5048 abort ();
5049 fragP->fr_opcode[1] &= ~0x3F;
5050 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
5051 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
5052 0, RELAX_RELOC_ABS32);
5053 fragP->fr_fix += 4;
5054 break;
5055 }
5056 }
5057
5058 #ifndef BFD_ASSEMBLER
5059
5060 void
md_convert_frag(object_headers * headers ATTRIBUTE_UNUSED,segT sec ATTRIBUTE_UNUSED,fragS * fragP)5061 md_convert_frag (object_headers *headers ATTRIBUTE_UNUSED,
5062 segT sec ATTRIBUTE_UNUSED,
5063 fragS *fragP)
5064 {
5065 md_convert_frag_1 (fragP);
5066 }
5067
5068 #else
5069
5070 void
md_convert_frag(bfd * abfd ATTRIBUTE_UNUSED,segT sec ATTRIBUTE_UNUSED,fragS * fragP)5071 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
5072 segT sec ATTRIBUTE_UNUSED,
5073 fragS *fragP)
5074 {
5075 md_convert_frag_1 (fragP);
5076 }
5077 #endif
5078
5079 /* Force truly undefined symbols to their maximum size, and generally set up
5080 the frag list to be relaxed
5081 */
5082 int
md_estimate_size_before_relax(fragS * fragP,segT segment)5083 md_estimate_size_before_relax (fragS *fragP, segT segment)
5084 {
5085 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
5086 switch (fragP->fr_subtype)
5087 {
5088 case TAB (BRANCHBWL, SZ_UNDEF):
5089 case TAB (BRABSJUNC, SZ_UNDEF):
5090 case TAB (BRABSJCOND, SZ_UNDEF):
5091 {
5092 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5093 && relaxable_symbol (fragP->fr_symbol))
5094 {
5095 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5096 /* (TIGCC 20030909) Create a symbol at the beginning of the next frag
5097 and store it into the frag structure, because
5098 md_convert_frag_1 might need a symbol there, but
5099 can't create it itself. This is necessary only for
5100 conditional jumps. -- Kevin Kofler */
5101 if ((TABTYPE (fragP->fr_subtype) == BRABSJCOND) && fragP->fr_next)
5102 {
5103 fragP->fr_next->fr_start_symbol = symbol_new (FAKE_LABEL_NAME, segment, fragP->fr_next->fr_address, fragP->fr_next);
5104 }
5105 }
5106 else if (flag_short_jumps)
5107 {
5108 /* Symbol is undefined and we want short ref. */
5109 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5110 }
5111 else
5112 {
5113 /* Symbol is still undefined. Make it LONG. */
5114 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5115 /* (TIGCC 20030908) Create a symbol at the beginning of the next frag
5116 and store it into the frag structure, because
5117 md_convert_frag_1 might need a symbol there, but
5118 can't create it itself.
5119 -- Kevin Kofler, patch by Sebastian Reichelt
5120 (TIGCC 20030909) This is necessary only for conditional jumps.
5121 -- Kevin Kofler */
5122 if ((TABTYPE (fragP->fr_subtype) == BRABSJCOND) && fragP->fr_next)
5123 {
5124 fragP->fr_next->fr_start_symbol = symbol_new (FAKE_LABEL_NAME, segment, fragP->fr_next->fr_address, fragP->fr_next);
5125 }
5126 }
5127 break;
5128 }
5129
5130 case TAB (BRANCHBW, SZ_UNDEF):
5131 {
5132 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
5133 && relaxable_symbol (fragP->fr_symbol))
5134 {
5135 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
5136 }
5137 else
5138 {
5139 /* Symbol is undefined and we don't have long branches. */
5140 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5141 }
5142 break;
5143 }
5144
5145 case TAB (FBRANCH, SZ_UNDEF):
5146 case TAB (DBCCLBR, SZ_UNDEF):
5147 case TAB (DBCCABSJ, SZ_UNDEF):
5148 case TAB (PCREL1632, SZ_UNDEF):
5149 {
5150 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5151 && relaxable_symbol (fragP->fr_symbol))
5152 || flag_short_jumps)
5153 {
5154 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5155 }
5156 else
5157 {
5158 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
5159 }
5160 break;
5161 }
5162
5163 case TAB (PCINDEX, SZ_UNDEF):
5164 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5165 && relaxable_symbol (fragP->fr_symbol)))
5166 {
5167 fragP->fr_subtype = TAB (PCINDEX, BYTE);
5168 }
5169 else
5170 {
5171 fragP->fr_subtype = TAB (PCINDEX, LONG);
5172 }
5173 break;
5174
5175 case TAB (ABSTOPCREL, SZ_UNDEF):
5176 {
5177 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
5178 && relaxable_symbol (fragP->fr_symbol))
5179 || flag_short_refs)
5180 {
5181 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
5182 }
5183 else
5184 {
5185 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
5186 }
5187 break;
5188 }
5189
5190 default:
5191 break;
5192 }
5193
5194 /* Now that SZ_UNDEF are taken care of, check others. */
5195 switch (fragP->fr_subtype)
5196 {
5197 case TAB (BRANCHBWL, BYTE):
5198 case TAB (BRABSJUNC, BYTE):
5199 case TAB (BRABSJCOND, BYTE):
5200 case TAB (BRANCHBW, BYTE):
5201 /* We can't do a short jump to the next instruction, so in that
5202 case we force word mode. If the symbol is at the start of a
5203 frag, and it is the next frag with any data in it (usually
5204 this is just the next frag, but assembler listings may
5205 introduce empty frags), we must use word mode. */
5206 if (fragP->fr_symbol)
5207 {
5208 fragS *sym_frag;
5209
5210 sym_frag = symbol_get_frag (fragP->fr_symbol);
5211 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
5212 {
5213 fragS *l;
5214
5215 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
5216 if (l->fr_fix != 0)
5217 break;
5218 if (l == sym_frag)
5219 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
5220 }
5221 }
5222 break;
5223
5224 default:
5225 break;
5226 }
5227 return md_relax_table[fragP->fr_subtype].rlx_length;
5228 }
5229
5230 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
5231 /* the bit-field entries in the relocation_info struct plays hell
5232 with the byte-order problems of cross-assembly. So as a hack,
5233 I added this mach. dependent ri twiddler. Ugly, but it gets
5234 you there. -KWK */
5235 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5236 are symbolnum, most sig. byte first. Last byte is broken up with
5237 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5238 nibble as nuthin. (on Sun 3 at least) */
5239 /* Translate the internal relocation information into target-specific
5240 format. */
5241 #ifdef comment
5242 void
md_ri_to_chars(char * the_bytes,struct reloc_info_generic * ri)5243 md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
5244 {
5245 /* This is easy. */
5246 md_number_to_chars (the_bytes, ri->r_address, 4);
5247 /* Now the fun stuff. */
5248 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
5249 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
5250 the_bytes[6] = ri->r_symbolnum & 0x0ff;
5251 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
5252 | ((ri->r_length << 5) & 0x60)
5253 | ((ri->r_extern << 4) & 0x10));
5254 }
5255
5256 #endif
5257
5258 #ifndef BFD_ASSEMBLER
5259 void
tc_aout_fix_to_chars(char * where,fixS * fixP,relax_addressT segment_address_in_file)5260 tc_aout_fix_to_chars (char *where, fixS *fixP,
5261 relax_addressT segment_address_in_file)
5262 {
5263 /*
5264 * In: length of relocation (or of address) in chars: 1, 2 or 4.
5265 * Out: GNU LD relocation length code: 0, 1, or 2.
5266 */
5267
5268 static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
5269 long r_symbolnum;
5270
5271 know (fixP->fx_addsy != NULL);
5272
5273 md_number_to_chars (where,
5274 (fixP->fx_frag->fr_address
5275 + fixP->fx_where - segment_address_in_file), 4);
5276
5277 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
5278 ? S_GET_TYPE (fixP->fx_addsy)
5279 : fixP->fx_addsy->sy_number);
5280
5281 where[4] = (r_symbolnum >> 16) & 0x0ff;
5282 where[5] = (r_symbolnum >> 8) & 0x0ff;
5283 where[6] = r_symbolnum & 0x0ff;
5284 where[7] = (((fixP->fx_pcrel << 7) & 0x80)
5285 | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60)
5286 | ((!S_IS_DEFINED (fixP->fx_addsy) << 4) & 0x10));
5287 }
5288 #endif
5289
5290 #endif /* OBJ_AOUT or OBJ_BOUT */
5291
5292 #ifndef WORKING_DOT_WORD
5293 int md_short_jump_size = 4;
5294 int md_long_jump_size = 6;
5295
5296 void
md_create_short_jump(char * ptr,addressT from_addr,addressT to_addr,fragS * frag ATTRIBUTE_UNUSED,symbolS * to_symbol ATTRIBUTE_UNUSED)5297 md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
5298 fragS *frag ATTRIBUTE_UNUSED,
5299 symbolS *to_symbol ATTRIBUTE_UNUSED)
5300 {
5301 valueT offset;
5302
5303 offset = to_addr - (from_addr + 2);
5304
5305 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5306 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5307 }
5308
5309 void
md_create_long_jump(char * ptr,addressT from_addr,addressT to_addr,fragS * frag,symbolS * to_symbol)5310 md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
5311 fragS *frag, symbolS *to_symbol)
5312 {
5313 valueT offset;
5314
5315 if (!HAVE_LONG_BRANCH (current_architecture))
5316 {
5317 if (flag_keep_pcrel)
5318 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5319 offset = to_addr - S_GET_VALUE (to_symbol);
5320 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5321 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5322 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5323 0, NO_RELOC);
5324 }
5325 else
5326 {
5327 offset = to_addr - (from_addr + 2);
5328 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5329 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5330 }
5331 }
5332
5333 #endif
5334
5335 /* Different values of OK tell what its OK to return. Things that
5336 aren't OK are an error (what a shock, no?)
5337
5338 0: Everything is OK
5339 10: Absolute 1:8 only
5340 20: Absolute 0:7 only
5341 30: absolute 0:15 only
5342 40: Absolute 0:31 only
5343 50: absolute 0:127 only
5344 55: absolute -64:63 only
5345 60: absolute -128:127 only
5346 70: absolute 0:4095 only
5347 80: absolute -1, 1:7 only
5348 90: No bignums. */
5349
5350 static int
get_num(struct m68k_exp * exp,int ok)5351 get_num (struct m68k_exp *exp, int ok)
5352 {
5353 if (exp->exp.X_op == O_absent)
5354 {
5355 /* Do the same thing the VAX asm does. */
5356 op (exp) = O_constant;
5357 adds (exp) = 0;
5358 subs (exp) = 0;
5359 offs (exp) = 0;
5360 if (ok == 10)
5361 {
5362 as_warn (_("expression out of range: defaulting to 1"));
5363 offs (exp) = 1;
5364 }
5365 }
5366 else if (exp->exp.X_op == O_constant)
5367 {
5368 switch (ok)
5369 {
5370 case 10:
5371 if ((valueT) TRUNC (offs (exp)) - 1 > 7)
5372 {
5373 as_warn (_("expression out of range: defaulting to 1"));
5374 offs (exp) = 1;
5375 }
5376 break;
5377 case 20:
5378 if ((valueT) TRUNC (offs (exp)) > 7)
5379 goto outrange;
5380 break;
5381 case 30:
5382 if ((valueT) TRUNC (offs (exp)) > 15)
5383 goto outrange;
5384 break;
5385 case 40:
5386 if ((valueT) TRUNC (offs (exp)) > 32)
5387 goto outrange;
5388 break;
5389 case 50:
5390 if ((valueT) TRUNC (offs (exp)) > 127)
5391 goto outrange;
5392 break;
5393 case 55:
5394 if ((valueT) SEXT (offs (exp)) + 64 > 127)
5395 goto outrange;
5396 break;
5397 case 60:
5398 if ((valueT) SEXT (offs (exp)) + 128 > 255)
5399 goto outrange;
5400 break;
5401 case 70:
5402 if ((valueT) TRUNC (offs (exp)) > 4095)
5403 {
5404 outrange:
5405 as_warn (_("expression out of range: defaulting to 0"));
5406 offs (exp) = 0;
5407 }
5408 break;
5409 case 80:
5410 if ((valueT) TRUNC (offs (exp)) != 0xffffffff
5411 && (valueT) TRUNC (offs (exp)) - 1 > 6)
5412 {
5413 as_warn (_("expression out of range: defaulting to 1"));
5414 offs (exp) = 1;
5415 }
5416 break;
5417 default:
5418 break;
5419 }
5420 }
5421 else if (exp->exp.X_op == O_big)
5422 {
5423 if (offs (exp) <= 0 /* flonum. */
5424 && (ok == 90 /* no bignums */
5425 || (ok > 10 /* Small-int ranges including 0 ok. */
5426 /* If we have a flonum zero, a zero integer should
5427 do as well (e.g., in moveq). */
5428 && generic_floating_point_number.exponent == 0
5429 && generic_floating_point_number.low[0] == 0)))
5430 {
5431 /* HACK! Turn it into a long. */
5432 LITTLENUM_TYPE words[6];
5433
5434 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5435 op (exp) = O_constant;
5436 adds (exp) = 0;
5437 subs (exp) = 0;
5438 offs (exp) = words[1] | (words[0] << 16);
5439 }
5440 else if (ok != 0)
5441 {
5442 op (exp) = O_constant;
5443 adds (exp) = 0;
5444 subs (exp) = 0;
5445 offs (exp) = (ok == 10) ? 1 : 0;
5446 as_warn (_("Can't deal with expression; defaulting to %ld"),
5447 offs (exp));
5448 }
5449 }
5450 else
5451 {
5452 if (ok >= 10 && ok <= 80)
5453 {
5454 op (exp) = O_constant;
5455 adds (exp) = 0;
5456 subs (exp) = 0;
5457 offs (exp) = (ok == 10) ? 1 : 0;
5458 as_warn (_("Can't deal with expression; defaulting to %ld"),
5459 offs (exp));
5460 }
5461 }
5462
5463 if (exp->size != SIZE_UNSPEC)
5464 {
5465 switch (exp->size)
5466 {
5467 case SIZE_UNSPEC:
5468 case SIZE_LONG:
5469 break;
5470 case SIZE_BYTE:
5471 if (!isbyte (offs (exp)))
5472 as_warn (_("expression doesn't fit in BYTE"));
5473 break;
5474 case SIZE_WORD:
5475 if (!isword (offs (exp)))
5476 as_warn (_("expression doesn't fit in WORD"));
5477 break;
5478 }
5479 }
5480
5481 return offs (exp);
5482 }
5483
5484 /* These are the back-ends for the various machine dependent pseudo-ops. */
5485
5486 static void
s_data1(int ignore ATTRIBUTE_UNUSED)5487 s_data1 (int ignore ATTRIBUTE_UNUSED)
5488 {
5489 subseg_set (data_section, 1);
5490 demand_empty_rest_of_line ();
5491 }
5492
5493 static void
s_data2(int ignore ATTRIBUTE_UNUSED)5494 s_data2 (int ignore ATTRIBUTE_UNUSED)
5495 {
5496 subseg_set (data_section, 2);
5497 demand_empty_rest_of_line ();
5498 }
5499
5500 static void
s_bss(int ignore ATTRIBUTE_UNUSED)5501 s_bss (int ignore ATTRIBUTE_UNUSED)
5502 {
5503 /* We don't support putting frags in the BSS segment, we fake it
5504 by marking in_bss, then looking at s_skip for clues. */
5505
5506 subseg_set (bss_section, 0);
5507 demand_empty_rest_of_line ();
5508 }
5509
5510 static void
s_even(int ignore ATTRIBUTE_UNUSED)5511 s_even (int ignore ATTRIBUTE_UNUSED)
5512 {
5513 register int temp;
5514 register long temp_fill;
5515
5516 temp = 1; /* JF should be 2? */
5517 temp_fill = get_absolute_expression ();
5518 if (!need_pass_2) /* Never make frag if expect extra pass. */
5519 frag_align (temp, (int) temp_fill, 0);
5520 demand_empty_rest_of_line ();
5521 record_alignment (now_seg, temp);
5522 }
5523
5524 static void
s_proc(int ignore ATTRIBUTE_UNUSED)5525 s_proc (int ignore ATTRIBUTE_UNUSED)
5526 {
5527 demand_empty_rest_of_line ();
5528 }
5529
5530 /* Pseudo-ops handled for MRI compatibility. */
5531
5532 /* This function returns non-zero if the argument is a conditional
5533 pseudo-op. This is called when checking whether a pending
5534 alignment is needed. */
5535
5536 int
m68k_conditional_pseudoop(pseudo_typeS * pop)5537 m68k_conditional_pseudoop (pseudo_typeS *pop)
5538 {
5539 return (pop->poc_handler == s_mri_if
5540 || pop->poc_handler == s_mri_else);
5541 }
5542
5543 /* Handle an MRI style chip specification. */
5544
5545 static void
mri_chip(void)5546 mri_chip (void)
5547 {
5548 char *s;
5549 char c;
5550 int i;
5551
5552 s = input_line_pointer;
5553 /* We can't use get_symbol_end since the processor names are not proper
5554 symbols. */
5555 while (is_part_of_name (c = *input_line_pointer++))
5556 ;
5557 *--input_line_pointer = 0;
5558 for (i = 0; i < n_archs; i++)
5559 if (strcasecmp (s, archs[i].name) == 0)
5560 break;
5561 if (i >= n_archs)
5562 {
5563 as_bad (_("%s: unrecognized processor name"), s);
5564 *input_line_pointer = c;
5565 ignore_rest_of_line ();
5566 return;
5567 }
5568 *input_line_pointer = c;
5569
5570 if (*input_line_pointer == '/')
5571 current_architecture = 0;
5572 else
5573 current_architecture &= m68881 | m68851;
5574 current_architecture |= archs[i].arch;
5575 current_chip = archs[i].chip;
5576
5577 while (*input_line_pointer == '/')
5578 {
5579 ++input_line_pointer;
5580 s = input_line_pointer;
5581 /* We can't use get_symbol_end since the processor names are not
5582 proper symbols. */
5583 while (is_part_of_name (c = *input_line_pointer++))
5584 ;
5585 *--input_line_pointer = 0;
5586 if (strcmp (s, "68881") == 0)
5587 current_architecture |= m68881;
5588 else if (strcmp (s, "68851") == 0)
5589 current_architecture |= m68851;
5590 *input_line_pointer = c;
5591 }
5592
5593 /* Update info about available control registers. */
5594 select_control_regs ();
5595 }
5596
5597 /* The MRI CHIP pseudo-op. */
5598
5599 static void
s_chip(int ignore ATTRIBUTE_UNUSED)5600 s_chip (int ignore ATTRIBUTE_UNUSED)
5601 {
5602 char *stop = NULL;
5603 char stopc;
5604
5605 if (flag_mri)
5606 stop = mri_comment_field (&stopc);
5607 mri_chip ();
5608 if (flag_mri)
5609 mri_comment_end (stop, stopc);
5610 demand_empty_rest_of_line ();
5611 }
5612
5613 /* The MRI FOPT pseudo-op. */
5614
5615 static void
s_fopt(int ignore ATTRIBUTE_UNUSED)5616 s_fopt (int ignore ATTRIBUTE_UNUSED)
5617 {
5618 SKIP_WHITESPACE ();
5619
5620 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5621 {
5622 int temp;
5623
5624 input_line_pointer += 3;
5625 temp = get_absolute_expression ();
5626 if (temp < 0 || temp > 7)
5627 as_bad (_("bad coprocessor id"));
5628 else
5629 m68k_float_copnum = COP0 + temp;
5630 }
5631 else
5632 {
5633 as_bad (_("unrecognized fopt option"));
5634 ignore_rest_of_line ();
5635 return;
5636 }
5637
5638 demand_empty_rest_of_line ();
5639 }
5640
5641 /* The structure used to handle the MRI OPT pseudo-op. */
5642
5643 struct opt_action
5644 {
5645 /* The name of the option. */
5646 const char *name;
5647
5648 /* If this is not NULL, just call this function. The first argument
5649 is the ARG field of this structure, the second argument is
5650 whether the option was negated. */
5651 void (*pfn) (int arg, int on);
5652
5653 /* If this is not NULL, and the PFN field is NULL, set the variable
5654 this points to. Set it to the ARG field if the option was not
5655 negated, and the NOTARG field otherwise. */
5656 int *pvar;
5657
5658 /* The value to pass to PFN or to assign to *PVAR. */
5659 int arg;
5660
5661 /* The value to assign to *PVAR if the option is negated. If PFN is
5662 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5663 the option may not be negated. */
5664 int notarg;
5665 };
5666
5667 /* The table used to handle the MRI OPT pseudo-op. */
5668
5669 static void skip_to_comma (int, int);
5670 static void opt_nest (int, int);
5671 static void opt_chip (int, int);
5672 static void opt_list (int, int);
5673 static void opt_list_symbols (int, int);
5674
5675 static const struct opt_action opt_table[] =
5676 {
5677 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5678
5679 /* We do relaxing, so there is little use for these options. */
5680 { "b", 0, 0, 0, 0 },
5681 { "brs", 0, 0, 0, 0 },
5682 { "brb", 0, 0, 0, 0 },
5683 { "brl", 0, 0, 0, 0 },
5684 { "brw", 0, 0, 0, 0 },
5685
5686 { "c", 0, 0, 0, 0 },
5687 { "cex", 0, 0, 0, 0 },
5688 { "case", 0, &symbols_case_sensitive, 1, 0 },
5689 { "cl", 0, 0, 0, 0 },
5690 { "cre", 0, 0, 0, 0 },
5691 { "d", 0, &flag_keep_locals, 1, 0 },
5692 { "e", 0, 0, 0, 0 },
5693 { "f", 0, &flag_short_refs, 1, 0 },
5694 { "frs", 0, &flag_short_refs, 1, 0 },
5695 { "frl", 0, &flag_short_refs, 0, 1 },
5696 { "g", 0, 0, 0, 0 },
5697 { "i", 0, 0, 0, 0 },
5698 { "m", 0, 0, 0, 0 },
5699 { "mex", 0, 0, 0, 0 },
5700 { "mc", 0, 0, 0, 0 },
5701 { "md", 0, 0, 0, 0 },
5702 { "nest", opt_nest, 0, 0, 0 },
5703 { "next", skip_to_comma, 0, 0, 0 },
5704 { "o", 0, 0, 0, 0 },
5705 { "old", 0, 0, 0, 0 },
5706 { "op", skip_to_comma, 0, 0, 0 },
5707 { "pco", 0, 0, 0, 0 },
5708 { "p", opt_chip, 0, 0, 0 },
5709 { "pcr", 0, 0, 0, 0 },
5710 { "pcs", 0, 0, 0, 0 },
5711 { "r", 0, 0, 0, 0 },
5712 { "quick", 0, &m68k_quick, 1, 0 },
5713 { "rel32", 0, &m68k_rel32, 1, 0 },
5714 { "s", opt_list, 0, 0, 0 },
5715 { "t", opt_list_symbols, 0, 0, 0 },
5716 { "w", 0, &flag_no_warnings, 0, 1 },
5717 { "x", 0, 0, 0, 0 }
5718 };
5719
5720 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5721
5722 /* The MRI OPT pseudo-op. */
5723
5724 static void
s_opt(int ignore ATTRIBUTE_UNUSED)5725 s_opt (int ignore ATTRIBUTE_UNUSED)
5726 {
5727 do
5728 {
5729 int t;
5730 char *s;
5731 char c;
5732 int i;
5733 const struct opt_action *o;
5734
5735 SKIP_WHITESPACE ();
5736
5737 t = 1;
5738 if (*input_line_pointer == '-')
5739 {
5740 ++input_line_pointer;
5741 t = 0;
5742 }
5743 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5744 {
5745 input_line_pointer += 2;
5746 t = 0;
5747 }
5748
5749 s = input_line_pointer;
5750 c = get_symbol_end ();
5751
5752 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5753 {
5754 if (strcasecmp (s, o->name) == 0)
5755 {
5756 if (o->pfn)
5757 {
5758 /* Restore input_line_pointer now in case the option
5759 takes arguments. */
5760 *input_line_pointer = c;
5761 (*o->pfn) (o->arg, t);
5762 }
5763 else if (o->pvar != NULL)
5764 {
5765 if (! t && o->arg == o->notarg)
5766 as_bad (_("option `%s' may not be negated"), s);
5767 *input_line_pointer = c;
5768 *o->pvar = t ? o->arg : o->notarg;
5769 }
5770 else
5771 *input_line_pointer = c;
5772 break;
5773 }
5774 }
5775 if (i >= OPTCOUNT)
5776 {
5777 as_bad (_("option `%s' not recognized"), s);
5778 *input_line_pointer = c;
5779 }
5780 }
5781 while (*input_line_pointer++ == ',');
5782
5783 /* Move back to terminating character. */
5784 --input_line_pointer;
5785 demand_empty_rest_of_line ();
5786 }
5787
5788 /* Skip ahead to a comma. This is used for OPT options which we do
5789 not support and which take arguments. */
5790
5791 static void
skip_to_comma(int arg ATTRIBUTE_UNUSED,int on ATTRIBUTE_UNUSED)5792 skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5793 {
5794 while (*input_line_pointer != ','
5795 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5796 ++input_line_pointer;
5797 }
5798
5799 /* Handle the OPT NEST=depth option. */
5800
5801 static void
opt_nest(int arg ATTRIBUTE_UNUSED,int on ATTRIBUTE_UNUSED)5802 opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5803 {
5804 if (*input_line_pointer != '=')
5805 {
5806 as_bad (_("bad format of OPT NEST=depth"));
5807 return;
5808 }
5809
5810 ++input_line_pointer;
5811 max_macro_nest = get_absolute_expression ();
5812 }
5813
5814 /* Handle the OPT P=chip option. */
5815
5816 static void
opt_chip(int arg ATTRIBUTE_UNUSED,int on ATTRIBUTE_UNUSED)5817 opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5818 {
5819 if (*input_line_pointer != '=')
5820 {
5821 /* This is just OPT P, which we do not support. */
5822 return;
5823 }
5824
5825 ++input_line_pointer;
5826 mri_chip ();
5827 }
5828
5829 /* Handle the OPT S option. */
5830
5831 static void
opt_list(int arg ATTRIBUTE_UNUSED,int on)5832 opt_list (int arg ATTRIBUTE_UNUSED, int on)
5833 {
5834 listing_list (on);
5835 }
5836
5837 /* Handle the OPT T option. */
5838
5839 static void
opt_list_symbols(int arg ATTRIBUTE_UNUSED,int on)5840 opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
5841 {
5842 if (on)
5843 listing |= LISTING_SYMBOLS;
5844 else
5845 listing &= ~LISTING_SYMBOLS;
5846 }
5847
5848 /* Handle the MRI REG pseudo-op. */
5849
5850 static void
s_reg(int ignore ATTRIBUTE_UNUSED)5851 s_reg (int ignore ATTRIBUTE_UNUSED)
5852 {
5853 char *s;
5854 int c;
5855 struct m68k_op rop;
5856 int mask;
5857 char *stop = NULL;
5858 char stopc;
5859
5860 if (line_label == NULL)
5861 {
5862 as_bad (_("missing label"));
5863 ignore_rest_of_line ();
5864 return;
5865 }
5866
5867 if (flag_mri)
5868 stop = mri_comment_field (&stopc);
5869
5870 SKIP_WHITESPACE ();
5871
5872 s = input_line_pointer;
5873 while (ISALNUM (*input_line_pointer)
5874 #ifdef REGISTER_PREFIX
5875 || *input_line_pointer == REGISTER_PREFIX
5876 #endif
5877 || *input_line_pointer == '/'
5878 || *input_line_pointer == '-')
5879 ++input_line_pointer;
5880 c = *input_line_pointer;
5881 *input_line_pointer = '\0';
5882
5883 if (m68k_ip_op (s, &rop) != 0)
5884 {
5885 if (rop.error == NULL)
5886 as_bad (_("bad register list"));
5887 else
5888 as_bad (_("bad register list: %s"), rop.error);
5889 *input_line_pointer = c;
5890 ignore_rest_of_line ();
5891 return;
5892 }
5893
5894 *input_line_pointer = c;
5895
5896 if (rop.mode == REGLST)
5897 mask = rop.mask;
5898 else if (rop.mode == DREG)
5899 mask = 1 << (rop.reg - DATA0);
5900 else if (rop.mode == AREG)
5901 mask = 1 << (rop.reg - ADDR0 + 8);
5902 else if (rop.mode == FPREG)
5903 mask = 1 << (rop.reg - FP0 + 16);
5904 else if (rop.mode == CONTROL
5905 && rop.reg == FPI)
5906 mask = 1 << 24;
5907 else if (rop.mode == CONTROL
5908 && rop.reg == FPS)
5909 mask = 1 << 25;
5910 else if (rop.mode == CONTROL
5911 && rop.reg == FPC)
5912 mask = 1 << 26;
5913 else
5914 {
5915 as_bad (_("bad register list"));
5916 ignore_rest_of_line ();
5917 return;
5918 }
5919
5920 S_SET_SEGMENT (line_label, reg_section);
5921 S_SET_VALUE (line_label, ~mask);
5922 symbol_set_frag (line_label, &zero_address_frag);
5923
5924 if (flag_mri)
5925 mri_comment_end (stop, stopc);
5926
5927 demand_empty_rest_of_line ();
5928 }
5929
5930 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5931
5932 struct save_opts
5933 {
5934 struct save_opts *next;
5935 int abspcadd;
5936 int symbols_case_sensitive;
5937 int keep_locals;
5938 int short_refs;
5939 int architecture;
5940 int chip;
5941 int quick;
5942 int rel32;
5943 int listing;
5944 int no_warnings;
5945 /* FIXME: We don't save OPT S. */
5946 };
5947
5948 /* This variable holds the stack of saved options. */
5949
5950 static struct save_opts *save_stack;
5951
5952 /* The MRI SAVE pseudo-op. */
5953
5954 static void
s_save(int ignore ATTRIBUTE_UNUSED)5955 s_save (int ignore ATTRIBUTE_UNUSED)
5956 {
5957 struct save_opts *s;
5958
5959 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5960 s->abspcadd = m68k_abspcadd;
5961 s->symbols_case_sensitive = symbols_case_sensitive;
5962 s->keep_locals = flag_keep_locals;
5963 s->short_refs = flag_short_refs;
5964 s->architecture = current_architecture;
5965 s->chip = current_chip;
5966 s->quick = m68k_quick;
5967 s->rel32 = m68k_rel32;
5968 s->listing = listing;
5969 s->no_warnings = flag_no_warnings;
5970
5971 s->next = save_stack;
5972 save_stack = s;
5973
5974 demand_empty_rest_of_line ();
5975 }
5976
5977 /* The MRI RESTORE pseudo-op. */
5978
5979 static void
s_restore(int ignore ATTRIBUTE_UNUSED)5980 s_restore (int ignore ATTRIBUTE_UNUSED)
5981 {
5982 struct save_opts *s;
5983
5984 if (save_stack == NULL)
5985 {
5986 as_bad (_("restore without save"));
5987 ignore_rest_of_line ();
5988 return;
5989 }
5990
5991 s = save_stack;
5992 save_stack = s->next;
5993
5994 m68k_abspcadd = s->abspcadd;
5995 symbols_case_sensitive = s->symbols_case_sensitive;
5996 flag_keep_locals = s->keep_locals;
5997 flag_short_refs = s->short_refs;
5998 current_architecture = s->architecture;
5999 current_chip = s->chip;
6000 m68k_quick = s->quick;
6001 m68k_rel32 = s->rel32;
6002 listing = s->listing;
6003 flag_no_warnings = s->no_warnings;
6004
6005 free (s);
6006
6007 demand_empty_rest_of_line ();
6008 }
6009
6010 /* Types of MRI structured control directives. */
6011
6012 enum mri_control_type
6013 {
6014 mri_for,
6015 mri_if,
6016 mri_repeat,
6017 mri_while
6018 };
6019
6020 /* This structure is used to stack the MRI structured control
6021 directives. */
6022
6023 struct mri_control_info
6024 {
6025 /* The directive within which this one is enclosed. */
6026 struct mri_control_info *outer;
6027
6028 /* The type of directive. */
6029 enum mri_control_type type;
6030
6031 /* Whether an ELSE has been in an IF. */
6032 int else_seen;
6033
6034 /* The add or sub statement at the end of a FOR. */
6035 char *incr;
6036
6037 /* The label of the top of a FOR or REPEAT loop. */
6038 char *top;
6039
6040 /* The label to jump to for the next iteration, or the else
6041 expression of a conditional. */
6042 char *next;
6043
6044 /* The label to jump to to break out of the loop, or the label past
6045 the end of a conditional. */
6046 char *bottom;
6047 };
6048
6049 /* The stack of MRI structured control directives. */
6050
6051 static struct mri_control_info *mri_control_stack;
6052
6053 /* The current MRI structured control directive index number, used to
6054 generate label names. */
6055
6056 static int mri_control_index;
6057
6058 /* Assemble an instruction for an MRI structured control directive. */
6059
6060 static void
mri_assemble(char * str)6061 mri_assemble (char *str)
6062 {
6063 char *s;
6064
6065 /* md_assemble expects the opcode to be in lower case. */
6066 for (s = str; *s != ' ' && *s != '\0'; s++)
6067 *s = TOLOWER (*s);
6068
6069 md_assemble (str);
6070 }
6071
6072 /* Generate a new MRI label structured control directive label name. */
6073
6074 static char *
mri_control_label(void)6075 mri_control_label (void)
6076 {
6077 char *n;
6078
6079 n = (char *) xmalloc (20);
6080 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
6081 ++mri_control_index;
6082 return n;
6083 }
6084
6085 /* Create a new MRI structured control directive. */
6086
6087 static struct mri_control_info *
push_mri_control(enum mri_control_type type)6088 push_mri_control (enum mri_control_type type)
6089 {
6090 struct mri_control_info *n;
6091
6092 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
6093
6094 n->type = type;
6095 n->else_seen = 0;
6096 if (type == mri_if || type == mri_while)
6097 n->top = NULL;
6098 else
6099 n->top = mri_control_label ();
6100 n->next = mri_control_label ();
6101 n->bottom = mri_control_label ();
6102
6103 n->outer = mri_control_stack;
6104 mri_control_stack = n;
6105
6106 return n;
6107 }
6108
6109 /* Pop off the stack of MRI structured control directives. */
6110
6111 static void
pop_mri_control(void)6112 pop_mri_control (void)
6113 {
6114 struct mri_control_info *n;
6115
6116 n = mri_control_stack;
6117 mri_control_stack = n->outer;
6118 if (n->top != NULL)
6119 free (n->top);
6120 free (n->next);
6121 free (n->bottom);
6122 free (n);
6123 }
6124
6125 /* Recognize a condition code in an MRI structured control expression. */
6126
6127 static int
parse_mri_condition(int * pcc)6128 parse_mri_condition (int *pcc)
6129 {
6130 char c1, c2;
6131
6132 know (*input_line_pointer == '<');
6133
6134 ++input_line_pointer;
6135 c1 = *input_line_pointer++;
6136 c2 = *input_line_pointer++;
6137
6138 if (*input_line_pointer != '>')
6139 {
6140 as_bad (_("syntax error in structured control directive"));
6141 return 0;
6142 }
6143
6144 ++input_line_pointer;
6145 SKIP_WHITESPACE ();
6146
6147 c1 = TOLOWER (c1);
6148 c2 = TOLOWER (c2);
6149
6150 *pcc = (c1 << 8) | c2;
6151
6152 return 1;
6153 }
6154
6155 /* Parse a single operand in an MRI structured control expression. */
6156
6157 static int
parse_mri_control_operand(int * pcc,char ** leftstart,char ** leftstop,char ** rightstart,char ** rightstop)6158 parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
6159 char **rightstart, char **rightstop)
6160 {
6161 char *s;
6162
6163 SKIP_WHITESPACE ();
6164
6165 *pcc = -1;
6166 *leftstart = NULL;
6167 *leftstop = NULL;
6168 *rightstart = NULL;
6169 *rightstop = NULL;
6170
6171 if (*input_line_pointer == '<')
6172 {
6173 /* It's just a condition code. */
6174 return parse_mri_condition (pcc);
6175 }
6176
6177 /* Look ahead for the condition code. */
6178 for (s = input_line_pointer; *s != '\0'; ++s)
6179 {
6180 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
6181 break;
6182 }
6183 if (*s == '\0')
6184 {
6185 as_bad (_("missing condition code in structured control directive"));
6186 return 0;
6187 }
6188
6189 *leftstart = input_line_pointer;
6190 *leftstop = s;
6191 if (*leftstop > *leftstart
6192 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
6193 --*leftstop;
6194
6195 input_line_pointer = s;
6196 if (! parse_mri_condition (pcc))
6197 return 0;
6198
6199 /* Look ahead for AND or OR or end of line. */
6200 for (s = input_line_pointer; *s != '\0'; ++s)
6201 {
6202 /* We must make sure we don't misinterpret AND/OR at the end of labels!
6203 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
6204 ^^^ ^^ */
6205 if ((s == input_line_pointer
6206 || *(s-1) == ' '
6207 || *(s-1) == '\t')
6208 && ((strncasecmp (s, "AND", 3) == 0
6209 && (s[3] == '.' || ! is_part_of_name (s[3])))
6210 || (strncasecmp (s, "OR", 2) == 0
6211 && (s[2] == '.' || ! is_part_of_name (s[2])))))
6212 break;
6213 }
6214
6215 *rightstart = input_line_pointer;
6216 *rightstop = s;
6217 if (*rightstop > *rightstart
6218 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
6219 --*rightstop;
6220
6221 input_line_pointer = s;
6222
6223 return 1;
6224 }
6225
6226 #define MCC(b1, b2) (((b1) << 8) | (b2))
6227
6228 /* Swap the sense of a condition. This changes the condition so that
6229 it generates the same result when the operands are swapped. */
6230
6231 static int
swap_mri_condition(int cc)6232 swap_mri_condition (int cc)
6233 {
6234 switch (cc)
6235 {
6236 case MCC ('h', 'i'): return MCC ('c', 's');
6237 case MCC ('l', 's'): return MCC ('c', 'c');
6238 /* <HS> is an alias for <CC>. */
6239 case MCC ('h', 's'):
6240 case MCC ('c', 'c'): return MCC ('l', 's');
6241 /* <LO> is an alias for <CS>. */
6242 case MCC ('l', 'o'):
6243 case MCC ('c', 's'): return MCC ('h', 'i');
6244 case MCC ('p', 'l'): return MCC ('m', 'i');
6245 case MCC ('m', 'i'): return MCC ('p', 'l');
6246 case MCC ('g', 'e'): return MCC ('l', 'e');
6247 case MCC ('l', 't'): return MCC ('g', 't');
6248 case MCC ('g', 't'): return MCC ('l', 't');
6249 case MCC ('l', 'e'): return MCC ('g', 'e');
6250 /* Issue a warning for conditions we can not swap. */
6251 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
6252 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
6253 case MCC ('v', 'c'):
6254 case MCC ('v', 's'):
6255 default :
6256 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
6257 (char) (cc >> 8), (char) (cc));
6258 break;
6259 }
6260 return cc;
6261 }
6262
6263 /* Reverse the sense of a condition. */
6264
6265 static int
reverse_mri_condition(int cc)6266 reverse_mri_condition (int cc)
6267 {
6268 switch (cc)
6269 {
6270 case MCC ('h', 'i'): return MCC ('l', 's');
6271 case MCC ('l', 's'): return MCC ('h', 'i');
6272 /* <HS> is an alias for <CC> */
6273 case MCC ('h', 's'): return MCC ('l', 'o');
6274 case MCC ('c', 'c'): return MCC ('c', 's');
6275 /* <LO> is an alias for <CS> */
6276 case MCC ('l', 'o'): return MCC ('h', 's');
6277 case MCC ('c', 's'): return MCC ('c', 'c');
6278 case MCC ('n', 'e'): return MCC ('e', 'q');
6279 case MCC ('e', 'q'): return MCC ('n', 'e');
6280 case MCC ('v', 'c'): return MCC ('v', 's');
6281 case MCC ('v', 's'): return MCC ('v', 'c');
6282 case MCC ('p', 'l'): return MCC ('m', 'i');
6283 case MCC ('m', 'i'): return MCC ('p', 'l');
6284 case MCC ('g', 'e'): return MCC ('l', 't');
6285 case MCC ('l', 't'): return MCC ('g', 'e');
6286 case MCC ('g', 't'): return MCC ('l', 'e');
6287 case MCC ('l', 'e'): return MCC ('g', 't');
6288 }
6289 return cc;
6290 }
6291
6292 /* Build an MRI structured control expression. This generates test
6293 and branch instructions. It goes to TRUELAB if the condition is
6294 true, and to FALSELAB if the condition is false. Exactly one of
6295 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6296 is the size qualifier for the expression. EXTENT is the size to
6297 use for the branch. */
6298
6299 static void
build_mri_control_operand(int qual,int cc,char * leftstart,char * leftstop,char * rightstart,char * rightstop,const char * truelab,const char * falselab,int extent)6300 build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
6301 char *rightstart, char *rightstop,
6302 const char *truelab, const char *falselab,
6303 int extent)
6304 {
6305 char *buf;
6306 char *s;
6307
6308 if (leftstart != NULL)
6309 {
6310 struct m68k_op leftop, rightop;
6311 char c;
6312
6313 /* Swap the compare operands, if necessary, to produce a legal
6314 m68k compare instruction. Comparing a register operand with
6315 a non-register operand requires the register to be on the
6316 right (cmp, cmpa). Comparing an immediate value with
6317 anything requires the immediate value to be on the left
6318 (cmpi). */
6319
6320 c = *leftstop;
6321 *leftstop = '\0';
6322 (void) m68k_ip_op (leftstart, &leftop);
6323 *leftstop = c;
6324
6325 c = *rightstop;
6326 *rightstop = '\0';
6327 (void) m68k_ip_op (rightstart, &rightop);
6328 *rightstop = c;
6329
6330 if (rightop.mode == IMMED
6331 || ((leftop.mode == DREG || leftop.mode == AREG)
6332 && (rightop.mode != DREG && rightop.mode != AREG)))
6333 {
6334 char *temp;
6335
6336 /* Correct conditional handling:
6337 if #1 <lt> d0 then ;means if (1 < d0)
6338 ...
6339 endi
6340
6341 should assemble to:
6342
6343 cmp #1,d0 if we do *not* swap the operands
6344 bgt true we need the swapped condition!
6345 ble false
6346 true:
6347 ...
6348 false:
6349 */
6350 temp = leftstart;
6351 leftstart = rightstart;
6352 rightstart = temp;
6353 temp = leftstop;
6354 leftstop = rightstop;
6355 rightstop = temp;
6356 }
6357 else
6358 {
6359 cc = swap_mri_condition (cc);
6360 }
6361 }
6362
6363 if (truelab == NULL)
6364 {
6365 cc = reverse_mri_condition (cc);
6366 truelab = falselab;
6367 }
6368
6369 if (leftstart != NULL)
6370 {
6371 buf = (char *) xmalloc (20
6372 + (leftstop - leftstart)
6373 + (rightstop - rightstart));
6374 s = buf;
6375 *s++ = 'c';
6376 *s++ = 'm';
6377 *s++ = 'p';
6378 if (qual != '\0')
6379 *s++ = TOLOWER (qual);
6380 *s++ = ' ';
6381 memcpy (s, leftstart, leftstop - leftstart);
6382 s += leftstop - leftstart;
6383 *s++ = ',';
6384 memcpy (s, rightstart, rightstop - rightstart);
6385 s += rightstop - rightstart;
6386 *s = '\0';
6387 mri_assemble (buf);
6388 free (buf);
6389 }
6390
6391 buf = (char *) xmalloc (20 + strlen (truelab));
6392 s = buf;
6393 *s++ = 'b';
6394 *s++ = cc >> 8;
6395 *s++ = cc & 0xff;
6396 if (extent != '\0')
6397 *s++ = TOLOWER (extent);
6398 *s++ = ' ';
6399 strcpy (s, truelab);
6400 mri_assemble (buf);
6401 free (buf);
6402 }
6403
6404 /* Parse an MRI structured control expression. This generates test
6405 and branch instructions. STOP is where the expression ends. It
6406 goes to TRUELAB if the condition is true, and to FALSELAB if the
6407 condition is false. Exactly one of TRUELAB and FALSELAB will be
6408 NULL, meaning to fall through. QUAL is the size qualifier for the
6409 expression. EXTENT is the size to use for the branch. */
6410
6411 static void
parse_mri_control_expression(char * stop,int qual,const char * truelab,const char * falselab,int extent)6412 parse_mri_control_expression (char *stop, int qual, const char *truelab,
6413 const char *falselab, int extent)
6414 {
6415 int c;
6416 int cc;
6417 char *leftstart;
6418 char *leftstop;
6419 char *rightstart;
6420 char *rightstop;
6421
6422 c = *stop;
6423 *stop = '\0';
6424
6425 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6426 &rightstart, &rightstop))
6427 {
6428 *stop = c;
6429 return;
6430 }
6431
6432 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6433 {
6434 const char *flab;
6435
6436 if (falselab != NULL)
6437 flab = falselab;
6438 else
6439 flab = mri_control_label ();
6440
6441 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6442 rightstop, (const char *) NULL, flab, extent);
6443
6444 input_line_pointer += 3;
6445 if (*input_line_pointer != '.'
6446 || input_line_pointer[1] == '\0')
6447 qual = '\0';
6448 else
6449 {
6450 qual = input_line_pointer[1];
6451 input_line_pointer += 2;
6452 }
6453
6454 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6455 &rightstart, &rightstop))
6456 {
6457 *stop = c;
6458 return;
6459 }
6460
6461 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6462 rightstop, truelab, falselab, extent);
6463
6464 if (falselab == NULL)
6465 colon (flab);
6466 }
6467 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6468 {
6469 const char *tlab;
6470
6471 if (truelab != NULL)
6472 tlab = truelab;
6473 else
6474 tlab = mri_control_label ();
6475
6476 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6477 rightstop, tlab, (const char *) NULL, extent);
6478
6479 input_line_pointer += 2;
6480 if (*input_line_pointer != '.'
6481 || input_line_pointer[1] == '\0')
6482 qual = '\0';
6483 else
6484 {
6485 qual = input_line_pointer[1];
6486 input_line_pointer += 2;
6487 }
6488
6489 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6490 &rightstart, &rightstop))
6491 {
6492 *stop = c;
6493 return;
6494 }
6495
6496 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6497 rightstop, truelab, falselab, extent);
6498
6499 if (truelab == NULL)
6500 colon (tlab);
6501 }
6502 else
6503 {
6504 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6505 rightstop, truelab, falselab, extent);
6506 }
6507
6508 *stop = c;
6509 if (input_line_pointer != stop)
6510 as_bad (_("syntax error in structured control directive"));
6511 }
6512
6513 /* Handle the MRI IF pseudo-op. This may be a structured control
6514 directive, or it may be a regular assembler conditional, depending
6515 on its operands. */
6516
6517 static void
s_mri_if(int qual)6518 s_mri_if (int qual)
6519 {
6520 char *s;
6521 int c;
6522 struct mri_control_info *n;
6523
6524 /* A structured control directive must end with THEN with an
6525 optional qualifier. */
6526 s = input_line_pointer;
6527 /* We only accept '*' as introduction of comments if preceded by white space
6528 or at first column of a line (I think this can't actually happen here?)
6529 This is important when assembling:
6530 if d0 <ne> 12(a0,d0*2) then
6531 if d0 <ne> #CONST*20 then. */
6532 while (! (is_end_of_line[(unsigned char) *s]
6533 || (flag_mri
6534 && *s == '*'
6535 && (s == input_line_pointer
6536 || *(s-1) == ' '
6537 || *(s-1) == '\t'))))
6538 ++s;
6539 --s;
6540 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6541 --s;
6542
6543 if (s - input_line_pointer > 1
6544 && s[-1] == '.')
6545 s -= 2;
6546
6547 if (s - input_line_pointer < 3
6548 || strncasecmp (s - 3, "THEN", 4) != 0)
6549 {
6550 if (qual != '\0')
6551 {
6552 as_bad (_("missing then"));
6553 ignore_rest_of_line ();
6554 return;
6555 }
6556
6557 /* It's a conditional. */
6558 s_if (O_ne);
6559 return;
6560 }
6561
6562 /* Since this might be a conditional if, this pseudo-op will be
6563 called even if we are supported to be ignoring input. Double
6564 check now. Clobber *input_line_pointer so that ignore_input
6565 thinks that this is not a special pseudo-op. */
6566 c = *input_line_pointer;
6567 *input_line_pointer = 0;
6568 if (ignore_input ())
6569 {
6570 *input_line_pointer = c;
6571 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6572 ++input_line_pointer;
6573 demand_empty_rest_of_line ();
6574 return;
6575 }
6576 *input_line_pointer = c;
6577
6578 n = push_mri_control (mri_if);
6579
6580 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6581 n->next, s[1] == '.' ? s[2] : '\0');
6582
6583 if (s[1] == '.')
6584 input_line_pointer = s + 3;
6585 else
6586 input_line_pointer = s + 1;
6587
6588 if (flag_mri)
6589 {
6590 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6591 ++input_line_pointer;
6592 }
6593
6594 demand_empty_rest_of_line ();
6595 }
6596
6597 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6598 structured IF, associate the ELSE with the IF. Otherwise, assume
6599 it is a conditional else. */
6600
6601 static void
s_mri_else(int qual)6602 s_mri_else (int qual)
6603 {
6604 int c;
6605 char *buf;
6606 char q[2];
6607
6608 if (qual == '\0'
6609 && (mri_control_stack == NULL
6610 || mri_control_stack->type != mri_if
6611 || mri_control_stack->else_seen))
6612 {
6613 s_else (0);
6614 return;
6615 }
6616
6617 c = *input_line_pointer;
6618 *input_line_pointer = 0;
6619 if (ignore_input ())
6620 {
6621 *input_line_pointer = c;
6622 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6623 ++input_line_pointer;
6624 demand_empty_rest_of_line ();
6625 return;
6626 }
6627 *input_line_pointer = c;
6628
6629 if (mri_control_stack == NULL
6630 || mri_control_stack->type != mri_if
6631 || mri_control_stack->else_seen)
6632 {
6633 as_bad (_("else without matching if"));
6634 ignore_rest_of_line ();
6635 return;
6636 }
6637
6638 mri_control_stack->else_seen = 1;
6639
6640 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6641 q[0] = TOLOWER (qual);
6642 q[1] = '\0';
6643 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6644 mri_assemble (buf);
6645 free (buf);
6646
6647 colon (mri_control_stack->next);
6648
6649 if (flag_mri)
6650 {
6651 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6652 ++input_line_pointer;
6653 }
6654
6655 demand_empty_rest_of_line ();
6656 }
6657
6658 /* Handle the MRI ENDI pseudo-op. */
6659
6660 static void
s_mri_endi(int ignore ATTRIBUTE_UNUSED)6661 s_mri_endi (int ignore ATTRIBUTE_UNUSED)
6662 {
6663 if (mri_control_stack == NULL
6664 || mri_control_stack->type != mri_if)
6665 {
6666 as_bad (_("endi without matching if"));
6667 ignore_rest_of_line ();
6668 return;
6669 }
6670
6671 /* ignore_input will not return true for ENDI, so we don't need to
6672 worry about checking it again here. */
6673
6674 if (! mri_control_stack->else_seen)
6675 colon (mri_control_stack->next);
6676 colon (mri_control_stack->bottom);
6677
6678 pop_mri_control ();
6679
6680 if (flag_mri)
6681 {
6682 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6683 ++input_line_pointer;
6684 }
6685
6686 demand_empty_rest_of_line ();
6687 }
6688
6689 /* Handle the MRI BREAK pseudo-op. */
6690
6691 static void
s_mri_break(int extent)6692 s_mri_break (int extent)
6693 {
6694 struct mri_control_info *n;
6695 char *buf;
6696 char ex[2];
6697
6698 n = mri_control_stack;
6699 while (n != NULL
6700 && n->type != mri_for
6701 && n->type != mri_repeat
6702 && n->type != mri_while)
6703 n = n->outer;
6704 if (n == NULL)
6705 {
6706 as_bad (_("break outside of structured loop"));
6707 ignore_rest_of_line ();
6708 return;
6709 }
6710
6711 buf = (char *) xmalloc (20 + strlen (n->bottom));
6712 ex[0] = TOLOWER (extent);
6713 ex[1] = '\0';
6714 sprintf (buf, "bra%s %s", ex, n->bottom);
6715 mri_assemble (buf);
6716 free (buf);
6717
6718 if (flag_mri)
6719 {
6720 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6721 ++input_line_pointer;
6722 }
6723
6724 demand_empty_rest_of_line ();
6725 }
6726
6727 /* Handle the MRI NEXT pseudo-op. */
6728
6729 static void
s_mri_next(int extent)6730 s_mri_next (int extent)
6731 {
6732 struct mri_control_info *n;
6733 char *buf;
6734 char ex[2];
6735
6736 n = mri_control_stack;
6737 while (n != NULL
6738 && n->type != mri_for
6739 && n->type != mri_repeat
6740 && n->type != mri_while)
6741 n = n->outer;
6742 if (n == NULL)
6743 {
6744 as_bad (_("next outside of structured loop"));
6745 ignore_rest_of_line ();
6746 return;
6747 }
6748
6749 buf = (char *) xmalloc (20 + strlen (n->next));
6750 ex[0] = TOLOWER (extent);
6751 ex[1] = '\0';
6752 sprintf (buf, "bra%s %s", ex, n->next);
6753 mri_assemble (buf);
6754 free (buf);
6755
6756 if (flag_mri)
6757 {
6758 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6759 ++input_line_pointer;
6760 }
6761
6762 demand_empty_rest_of_line ();
6763 }
6764
6765 /* Handle the MRI FOR pseudo-op. */
6766
6767 static void
s_mri_for(int qual)6768 s_mri_for (int qual)
6769 {
6770 const char *varstart, *varstop;
6771 const char *initstart, *initstop;
6772 const char *endstart, *endstop;
6773 const char *bystart, *bystop;
6774 int up;
6775 int by;
6776 int extent;
6777 struct mri_control_info *n;
6778 char *buf;
6779 char *s;
6780 char ex[2];
6781
6782 /* The syntax is
6783 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6784 */
6785
6786 SKIP_WHITESPACE ();
6787 varstart = input_line_pointer;
6788
6789 /* Look for the '='. */
6790 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6791 && *input_line_pointer != '=')
6792 ++input_line_pointer;
6793 if (*input_line_pointer != '=')
6794 {
6795 as_bad (_("missing ="));
6796 ignore_rest_of_line ();
6797 return;
6798 }
6799
6800 varstop = input_line_pointer;
6801 if (varstop > varstart
6802 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6803 --varstop;
6804
6805 ++input_line_pointer;
6806
6807 initstart = input_line_pointer;
6808
6809 /* Look for TO or DOWNTO. */
6810 up = 1;
6811 initstop = NULL;
6812 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6813 {
6814 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6815 && ! is_part_of_name (input_line_pointer[2]))
6816 {
6817 initstop = input_line_pointer;
6818 input_line_pointer += 2;
6819 break;
6820 }
6821 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6822 && ! is_part_of_name (input_line_pointer[6]))
6823 {
6824 initstop = input_line_pointer;
6825 up = 0;
6826 input_line_pointer += 6;
6827 break;
6828 }
6829 ++input_line_pointer;
6830 }
6831 if (initstop == NULL)
6832 {
6833 as_bad (_("missing to or downto"));
6834 ignore_rest_of_line ();
6835 return;
6836 }
6837 if (initstop > initstart
6838 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6839 --initstop;
6840
6841 SKIP_WHITESPACE ();
6842 endstart = input_line_pointer;
6843
6844 /* Look for BY or DO. */
6845 by = 0;
6846 endstop = NULL;
6847 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6848 {
6849 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6850 && ! is_part_of_name (input_line_pointer[2]))
6851 {
6852 endstop = input_line_pointer;
6853 by = 1;
6854 input_line_pointer += 2;
6855 break;
6856 }
6857 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6858 && (input_line_pointer[2] == '.'
6859 || ! is_part_of_name (input_line_pointer[2])))
6860 {
6861 endstop = input_line_pointer;
6862 input_line_pointer += 2;
6863 break;
6864 }
6865 ++input_line_pointer;
6866 }
6867 if (endstop == NULL)
6868 {
6869 as_bad (_("missing do"));
6870 ignore_rest_of_line ();
6871 return;
6872 }
6873 if (endstop > endstart
6874 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6875 --endstop;
6876
6877 if (! by)
6878 {
6879 bystart = "#1";
6880 bystop = bystart + 2;
6881 }
6882 else
6883 {
6884 SKIP_WHITESPACE ();
6885 bystart = input_line_pointer;
6886
6887 /* Look for DO. */
6888 bystop = NULL;
6889 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6890 {
6891 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6892 && (input_line_pointer[2] == '.'
6893 || ! is_part_of_name (input_line_pointer[2])))
6894 {
6895 bystop = input_line_pointer;
6896 input_line_pointer += 2;
6897 break;
6898 }
6899 ++input_line_pointer;
6900 }
6901 if (bystop == NULL)
6902 {
6903 as_bad (_("missing do"));
6904 ignore_rest_of_line ();
6905 return;
6906 }
6907 if (bystop > bystart
6908 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6909 --bystop;
6910 }
6911
6912 if (*input_line_pointer != '.')
6913 extent = '\0';
6914 else
6915 {
6916 extent = input_line_pointer[1];
6917 input_line_pointer += 2;
6918 }
6919
6920 /* We have fully parsed the FOR operands. Now build the loop. */
6921 n = push_mri_control (mri_for);
6922
6923 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6924
6925 /* Move init,var. */
6926 s = buf;
6927 *s++ = 'm';
6928 *s++ = 'o';
6929 *s++ = 'v';
6930 *s++ = 'e';
6931 if (qual != '\0')
6932 *s++ = TOLOWER (qual);
6933 *s++ = ' ';
6934 memcpy (s, initstart, initstop - initstart);
6935 s += initstop - initstart;
6936 *s++ = ',';
6937 memcpy (s, varstart, varstop - varstart);
6938 s += varstop - varstart;
6939 *s = '\0';
6940 mri_assemble (buf);
6941
6942 colon (n->top);
6943
6944 /* cmp end,var. */
6945 s = buf;
6946 *s++ = 'c';
6947 *s++ = 'm';
6948 *s++ = 'p';
6949 if (qual != '\0')
6950 *s++ = TOLOWER (qual);
6951 *s++ = ' ';
6952 memcpy (s, endstart, endstop - endstart);
6953 s += endstop - endstart;
6954 *s++ = ',';
6955 memcpy (s, varstart, varstop - varstart);
6956 s += varstop - varstart;
6957 *s = '\0';
6958 mri_assemble (buf);
6959
6960 /* bcc bottom. */
6961 ex[0] = TOLOWER (extent);
6962 ex[1] = '\0';
6963 if (up)
6964 sprintf (buf, "blt%s %s", ex, n->bottom);
6965 else
6966 sprintf (buf, "bgt%s %s", ex, n->bottom);
6967 mri_assemble (buf);
6968
6969 /* Put together the add or sub instruction used by ENDF. */
6970 s = buf;
6971 if (up)
6972 strcpy (s, "add");
6973 else
6974 strcpy (s, "sub");
6975 s += 3;
6976 if (qual != '\0')
6977 *s++ = TOLOWER (qual);
6978 *s++ = ' ';
6979 memcpy (s, bystart, bystop - bystart);
6980 s += bystop - bystart;
6981 *s++ = ',';
6982 memcpy (s, varstart, varstop - varstart);
6983 s += varstop - varstart;
6984 *s = '\0';
6985 n->incr = buf;
6986
6987 if (flag_mri)
6988 {
6989 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6990 ++input_line_pointer;
6991 }
6992
6993 demand_empty_rest_of_line ();
6994 }
6995
6996 /* Handle the MRI ENDF pseudo-op. */
6997
6998 static void
s_mri_endf(int ignore ATTRIBUTE_UNUSED)6999 s_mri_endf (int ignore ATTRIBUTE_UNUSED)
7000 {
7001 if (mri_control_stack == NULL
7002 || mri_control_stack->type != mri_for)
7003 {
7004 as_bad (_("endf without for"));
7005 ignore_rest_of_line ();
7006 return;
7007 }
7008
7009 colon (mri_control_stack->next);
7010
7011 mri_assemble (mri_control_stack->incr);
7012
7013 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
7014 mri_assemble (mri_control_stack->incr);
7015
7016 free (mri_control_stack->incr);
7017
7018 colon (mri_control_stack->bottom);
7019
7020 pop_mri_control ();
7021
7022 if (flag_mri)
7023 {
7024 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7025 ++input_line_pointer;
7026 }
7027
7028 demand_empty_rest_of_line ();
7029 }
7030
7031 /* Handle the MRI REPEAT pseudo-op. */
7032
7033 static void
s_mri_repeat(int ignore ATTRIBUTE_UNUSED)7034 s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
7035 {
7036 struct mri_control_info *n;
7037
7038 n = push_mri_control (mri_repeat);
7039 colon (n->top);
7040 if (flag_mri)
7041 {
7042 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7043 ++input_line_pointer;
7044 }
7045 demand_empty_rest_of_line ();
7046 }
7047
7048 /* Handle the MRI UNTIL pseudo-op. */
7049
7050 static void
s_mri_until(int qual)7051 s_mri_until (int qual)
7052 {
7053 char *s;
7054
7055 if (mri_control_stack == NULL
7056 || mri_control_stack->type != mri_repeat)
7057 {
7058 as_bad (_("until without repeat"));
7059 ignore_rest_of_line ();
7060 return;
7061 }
7062
7063 colon (mri_control_stack->next);
7064
7065 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
7066 ;
7067
7068 parse_mri_control_expression (s, qual, (const char *) NULL,
7069 mri_control_stack->top, '\0');
7070
7071 colon (mri_control_stack->bottom);
7072
7073 input_line_pointer = s;
7074
7075 pop_mri_control ();
7076
7077 if (flag_mri)
7078 {
7079 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7080 ++input_line_pointer;
7081 }
7082
7083 demand_empty_rest_of_line ();
7084 }
7085
7086 /* Handle the MRI WHILE pseudo-op. */
7087
7088 static void
s_mri_while(int qual)7089 s_mri_while (int qual)
7090 {
7091 char *s;
7092
7093 struct mri_control_info *n;
7094
7095 s = input_line_pointer;
7096 /* We only accept '*' as introduction of comments if preceded by white space
7097 or at first column of a line (I think this can't actually happen here?)
7098 This is important when assembling:
7099 while d0 <ne> 12(a0,d0*2) do
7100 while d0 <ne> #CONST*20 do. */
7101 while (! (is_end_of_line[(unsigned char) *s]
7102 || (flag_mri
7103 && *s == '*'
7104 && (s == input_line_pointer
7105 || *(s-1) == ' '
7106 || *(s-1) == '\t'))))
7107 s++;
7108 --s;
7109 while (*s == ' ' || *s == '\t')
7110 --s;
7111 if (s - input_line_pointer > 1
7112 && s[-1] == '.')
7113 s -= 2;
7114 if (s - input_line_pointer < 2
7115 || strncasecmp (s - 1, "DO", 2) != 0)
7116 {
7117 as_bad (_("missing do"));
7118 ignore_rest_of_line ();
7119 return;
7120 }
7121
7122 n = push_mri_control (mri_while);
7123
7124 colon (n->next);
7125
7126 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
7127 s[1] == '.' ? s[2] : '\0');
7128
7129 input_line_pointer = s + 1;
7130 if (*input_line_pointer == '.')
7131 input_line_pointer += 2;
7132
7133 if (flag_mri)
7134 {
7135 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7136 ++input_line_pointer;
7137 }
7138
7139 demand_empty_rest_of_line ();
7140 }
7141
7142 /* Handle the MRI ENDW pseudo-op. */
7143
7144 static void
s_mri_endw(int ignore ATTRIBUTE_UNUSED)7145 s_mri_endw (int ignore ATTRIBUTE_UNUSED)
7146 {
7147 char *buf;
7148
7149 if (mri_control_stack == NULL
7150 || mri_control_stack->type != mri_while)
7151 {
7152 as_bad (_("endw without while"));
7153 ignore_rest_of_line ();
7154 return;
7155 }
7156
7157 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
7158 sprintf (buf, "bra %s", mri_control_stack->next);
7159 mri_assemble (buf);
7160 free (buf);
7161
7162 colon (mri_control_stack->bottom);
7163
7164 pop_mri_control ();
7165
7166 if (flag_mri)
7167 {
7168 while (! is_end_of_line[(unsigned char) *input_line_pointer])
7169 ++input_line_pointer;
7170 }
7171
7172 demand_empty_rest_of_line ();
7173 }
7174
7175 /* md_parse_option
7176 Invocation line includes a switch not recognized by the base assembler.
7177 See if it's a processor-specific option. These are:
7178
7179 -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
7180 -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
7181 Select the architecture. Instructions or features not
7182 supported by the selected architecture cause fatal
7183 errors. More than one may be specified. The default is
7184 -m68020 -m68851 -m68881. Note that -m68008 is a synonym
7185 for -m68000, and -m68882 is a synonym for -m68881.
7186 -[A]m[c]no-68851, -[A]m[c]no-68881
7187 Don't accept 688?1 instructions. (The "c" is kind of silly,
7188 so don't use or document it, but that's the way the parsing
7189 works).
7190
7191 -pic Indicates PIC.
7192 -k Indicates PIC. (Sun 3 only.)
7193 --pcrel
7194 Never turn PC-relative branches into absolute jumps.
7195 --bitwise-or
7196 Permit `|' to be used in expressions. */
7197
7198 #ifdef OBJ_ELF
7199 const char *md_shortopts = "lSA:m:kQ:V";
7200 #else
7201 const char *md_shortopts = "lSA:m:k";
7202 #endif
7203
7204 struct option md_longopts[] = {
7205 #define OPTION_PIC (OPTION_MD_BASE)
7206 {"pic", no_argument, NULL, OPTION_PIC},
7207 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
7208 {"register-prefix-optional", no_argument, NULL,
7209 OPTION_REGISTER_PREFIX_OPTIONAL},
7210 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
7211 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
7212 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
7213 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
7214 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
7215 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
7216 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
7217 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
7218 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
7219 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
7220 #define OPTION_PCREL (OPTION_MD_BASE + 7)
7221 {"pcrel", no_argument, NULL, OPTION_PCREL},
7222 #define OPTION_SHORT_JUMPS (OPTION_MD_BASE + 8)
7223 {"short-jumps", no_argument, NULL, OPTION_SHORT_JUMPS},
7224 {NULL, no_argument, NULL, 0}
7225 };
7226 size_t md_longopts_size = sizeof (md_longopts);
7227
7228 int
md_parse_option(int c,char * arg)7229 md_parse_option (int c, char *arg)
7230 {
7231 switch (c)
7232 {
7233 case 'l': /* -l means keep external to 2 bit offset
7234 rather than 16 bit one. */
7235 flag_short_refs = 1;
7236 flag_short_jumps = 1;
7237 break;
7238
7239 case OPTION_SHORT_JUMPS: /* --short-jumps is like -l only for
7240 jumps. */
7241 flag_short_jumps = 1;
7242 break;
7243
7244 case 'S': /* -S means that jbsr's always turn into
7245 jsr's. */
7246 flag_long_jumps = 1;
7247 break;
7248
7249 case OPTION_PCREL: /* --pcrel means never turn PC-relative
7250 branches into absolute jumps. */
7251 flag_keep_pcrel = 1;
7252 break;
7253
7254 case 'A':
7255 if (*arg == 'm')
7256 arg++;
7257 /* Intentional fall-through. */
7258 case 'm':
7259
7260 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
7261 {
7262 int i;
7263 unsigned long arch;
7264
7265 arg += 3;
7266 if (*arg == 'm')
7267 {
7268 arg++;
7269 if (arg[0] == 'c' && arg[1] == '6')
7270 arg++;
7271 }
7272 for (i = 0; i < n_archs; i++)
7273 if (!strcmp (arg, archs[i].name))
7274 break;
7275 if (i == n_archs)
7276 return 0;
7277
7278 arch = archs[i].arch;
7279 if (arch == m68881)
7280 no_68881 = 1;
7281 else if (arch == m68851)
7282 no_68851 = 1;
7283 else
7284 return 0;
7285 }
7286 else
7287 {
7288 int i;
7289
7290 if (arg[0] == 'c' && arg[1] == '6')
7291 arg++;
7292
7293 for (i = 0; i < n_archs; i++)
7294 if (!strcmp (arg, archs[i].name))
7295 {
7296 unsigned long arch = archs[i].arch;
7297
7298 if (cpu_of_arch (arch))
7299 /* It's a cpu spec. */
7300 {
7301 current_architecture &= ~m68000up;
7302 current_architecture |= arch;
7303 current_chip = archs[i].chip;
7304 }
7305 else if (arch == m68881)
7306 {
7307 current_architecture |= m68881;
7308 no_68881 = 0;
7309 }
7310 else if (arch == m68851)
7311 {
7312 current_architecture |= m68851;
7313 no_68851 = 0;
7314 }
7315 else
7316 /* ??? */
7317 abort ();
7318 break;
7319 }
7320 if (i == n_archs)
7321 {
7322 as_bad (_("unrecognized architecture specification `%s'"), arg);
7323 return 0;
7324 }
7325 }
7326 break;
7327
7328 case OPTION_PIC:
7329 case 'k':
7330 flag_want_pic = 1;
7331 break; /* -pic, Position Independent Code. */
7332
7333 case OPTION_REGISTER_PREFIX_OPTIONAL:
7334 flag_reg_prefix_optional = 1;
7335 reg_prefix_optional_seen = 1;
7336 break;
7337
7338 /* -V: SVR4 argument to print version ID. */
7339 case 'V':
7340 print_version_id ();
7341 break;
7342
7343 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7344 should be emitted or not. FIXME: Not implemented. */
7345 case 'Q':
7346 break;
7347
7348 case OPTION_BITWISE_OR:
7349 {
7350 char *n, *t;
7351 const char *s;
7352
7353 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7354 t = n;
7355 for (s = m68k_comment_chars; *s != '\0'; s++)
7356 if (*s != '|')
7357 *t++ = *s;
7358 *t = '\0';
7359 m68k_comment_chars = n;
7360 }
7361 break;
7362
7363 case OPTION_BASE_SIZE_DEFAULT_16:
7364 m68k_index_width_default = SIZE_WORD;
7365 break;
7366
7367 case OPTION_BASE_SIZE_DEFAULT_32:
7368 m68k_index_width_default = SIZE_LONG;
7369 break;
7370
7371 case OPTION_DISP_SIZE_DEFAULT_16:
7372 m68k_rel32 = 0;
7373 m68k_rel32_from_cmdline = 1;
7374 break;
7375
7376 case OPTION_DISP_SIZE_DEFAULT_32:
7377 m68k_rel32 = 1;
7378 m68k_rel32_from_cmdline = 1;
7379 break;
7380
7381 default:
7382 return 0;
7383 }
7384
7385 return 1;
7386 }
7387
7388 void
md_show_usage(FILE * stream)7389 md_show_usage (FILE *stream)
7390 {
7391 const char *default_cpu = TARGET_CPU;
7392 int i;
7393 unsigned int default_arch;
7394
7395 /* Get the canonical name for the default target CPU. */
7396 if (*default_cpu == 'm')
7397 default_cpu++;
7398 for (i = 0; i < n_archs; i++)
7399 {
7400 if (strcasecmp (default_cpu, archs[i].name) == 0)
7401 {
7402 default_arch = archs[i].arch;
7403 for (i = 0; i < n_archs; i++)
7404 {
7405 if (archs[i].arch == default_arch
7406 && !archs[i].alias)
7407 {
7408 default_cpu = archs[i].name;
7409 break;
7410 }
7411 }
7412 }
7413 }
7414
7415 fprintf (stream, _("\
7416 680X0 options:\n\
7417 -l use 1 word for refs to undefined symbols [default 2]\n\
7418 --short-jumps use 1 word for jumps to undefined symbols [default 2]\n\
7419 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
7420 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
7421 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m521x | -m5249 |\n\
7422 -m528x | -m5307 | -m5407 | -m547x | -m548x | -mcfv4 | -mcfv4e\n\
7423 specify variant of 680X0 architecture [default %s]\n\
7424 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
7425 target has/lacks floating-point coprocessor\n\
7426 [default yes for 68020, 68030, and cpu32]\n"),
7427 default_cpu);
7428 fprintf (stream, _("\
7429 -m68851 | -mno-68851\n\
7430 target has/lacks memory-management unit coprocessor\n\
7431 [default yes for 68020 and up]\n\
7432 -pic, -k generate position independent code\n\
7433 -S turn jbsr into jsr\n\
7434 --pcrel never turn PC-relative branches into absolute jumps\n\
7435 --register-prefix-optional\n\
7436 recognize register names without prefix character\n\
7437 --bitwise-or do not treat `|' as a comment character\n"));
7438 fprintf (stream, _("\
7439 --base-size-default-16 base reg without size is 16 bits\n\
7440 --base-size-default-32 base reg without size is 32 bits (default)\n\
7441 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7442 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7443 }
7444
7445 #ifdef TEST2
7446
7447 /* TEST2: Test md_assemble() */
7448 /* Warning, this routine probably doesn't work anymore. */
7449 int
main(void)7450 main (void)
7451 {
7452 struct m68k_it the_ins;
7453 char buf[120];
7454 char *cp;
7455 int n;
7456
7457 m68k_ip_begin ();
7458 for (;;)
7459 {
7460 if (!gets (buf) || !*buf)
7461 break;
7462 if (buf[0] == '|' || buf[1] == '.')
7463 continue;
7464 for (cp = buf; *cp; cp++)
7465 if (*cp == '\t')
7466 *cp = ' ';
7467 if (is_label (buf))
7468 continue;
7469 memset (&the_ins, '\0', sizeof (the_ins));
7470 m68k_ip (&the_ins, buf);
7471 if (the_ins.error)
7472 {
7473 printf (_("Error %s in %s\n"), the_ins.error, buf);
7474 }
7475 else
7476 {
7477 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7478 for (n = 0; n < the_ins.numo; n++)
7479 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7480 printf (" ");
7481 print_the_insn (&the_ins.opcode[0], stdout);
7482 (void) putchar ('\n');
7483 }
7484 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7485 {
7486 if (the_ins.operands[n].error)
7487 {
7488 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7489 continue;
7490 }
7491 printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
7492 the_ins.operands[n].reg);
7493 if (the_ins.operands[n].b_const)
7494 printf ("Constant: '%.*s', ",
7495 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
7496 the_ins.operands[n].b_const);
7497 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
7498 the_ins.operands[n].isiz, the_ins.operands[n].imul);
7499 if (the_ins.operands[n].b_iadd)
7500 printf ("Iadd: '%.*s',",
7501 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
7502 the_ins.operands[n].b_iadd);
7503 putchar ('\n');
7504 }
7505 }
7506 m68k_ip_end ();
7507 return 0;
7508 }
7509
7510 int
is_label(char * str)7511 is_label (char *str)
7512 {
7513 while (*str == ' ')
7514 str++;
7515 while (*str && *str != ' ')
7516 str++;
7517 if (str[-1] == ':' || str[1] == '=')
7518 return 1;
7519 return 0;
7520 }
7521
7522 #endif
7523
7524 /* Possible states for relaxation:
7525
7526 0 0 branch offset byte (bra, etc)
7527 0 1 word
7528 0 2 long
7529
7530 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7531 1 1 word
7532 1 2 long
7533
7534 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7535 2 1 word-long
7536 2 2 long-word
7537 2 3 long-long
7538
7539 */
7540
7541 /* We have no need to default values of symbols. */
7542
7543 symbolS *
md_undefined_symbol(char * name ATTRIBUTE_UNUSED)7544 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
7545 {
7546 return 0;
7547 }
7548
7549 /* Round up a section size to the appropriate boundary. */
7550 valueT
md_section_align(segT segment ATTRIBUTE_UNUSED,valueT size)7551 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
7552 {
7553 #ifdef OBJ_AOUT
7554 #ifdef BFD_ASSEMBLER
7555 /* For a.out, force the section size to be aligned. If we don't do
7556 this, BFD will align it for us, but it will not write out the
7557 final bytes of the section. This may be a bug in BFD, but it is
7558 easier to fix it here since that is how the other a.out targets
7559 work. */
7560 int align;
7561
7562 align = bfd_get_section_alignment (stdoutput, segment);
7563 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7564 #endif
7565 #endif
7566
7567 return size;
7568 }
7569
7570 /* Exactly what point is a PC-relative offset relative TO?
7571 On the 68k, it is relative to the address of the first extension
7572 word. The difference between the addresses of the offset and the
7573 first extension word is stored in fx_pcrel_adjust. */
7574 long
md_pcrel_from(fixS * fixP)7575 md_pcrel_from (fixS *fixP)
7576 {
7577 int adjust;
7578
7579 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7580 sign extend the value here. */
7581 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7582 if (adjust == 64)
7583 adjust = -1;
7584 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7585 }
7586
7587 #ifndef BFD_ASSEMBLER
7588 #ifdef OBJ_COFF
7589
7590 void
tc_coff_symbol_emit_hook(symbolS * ignore ATTRIBUTE_UNUSED)7591 tc_coff_symbol_emit_hook (symbolS *ignore ATTRIBUTE_UNUSED)
7592 {
7593 }
7594
7595 int
tc_coff_sizemachdep(fragS * frag)7596 tc_coff_sizemachdep (fragS *frag)
7597 {
7598 switch (frag->fr_subtype & 0x3)
7599 {
7600 case BYTE:
7601 return 1;
7602 case SHORT:
7603 return 2;
7604 case LONG:
7605 return 4;
7606 default:
7607 abort ();
7608 return 0;
7609 }
7610 }
7611
7612 #endif
7613 #endif
7614
7615 #ifdef OBJ_ELF
7616 void
m68k_elf_final_processing(void)7617 m68k_elf_final_processing (void)
7618 {
7619 /* Set file-specific flags if this is a cpu32 processor. */
7620 if (cpu_of_arch (current_architecture) & cpu32)
7621 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;
7622 else if ((cpu_of_arch (current_architecture) & m68000up)
7623 && !(cpu_of_arch (current_architecture) & m68020up))
7624 elf_elfheader (stdoutput)->e_flags |= EF_M68000;
7625 }
7626 #endif
7627
7628 int
tc_m68k_regname_to_dw2regnum(const char * regname)7629 tc_m68k_regname_to_dw2regnum (const char *regname)
7630 {
7631 unsigned int regnum;
7632 static const char *const regnames[] =
7633 {
7634 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7635 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7636 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7637 "pc"
7638 };
7639
7640 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
7641 if (strcmp (regname, regnames[regnum]) == 0)
7642 return regnum;
7643
7644 return -1;
7645 }
7646
7647 void
tc_m68k_frame_initial_instructions(void)7648 tc_m68k_frame_initial_instructions (void)
7649 {
7650 static int sp_regno = -1;
7651
7652 if (sp_regno < 0)
7653 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
7654
7655 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
7656 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);
7657 }
7658