* dwarf2dbg.c (struct line_entry): Replace frag and frag_ofs
[binutils.git] / gas / config / tc-m68k.c
blob761cdd458a308e5a479cdb311f436cc72ea67c92
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.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
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"
29 #include "opcode/m68k.h"
30 #include "m68k-parse.h"
32 #if defined (OBJ_ELF)
33 #include "elf/m68k.h"
34 #endif
36 #ifdef M68KCOFF
37 #include "obj-coff.h"
38 #endif
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
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[] = "#*";
59 const char line_separator_chars[] = ";";
61 /* Chars that can be used to separate mant from exp in floating point nums. */
62 const char EXP_CHARS[] = "eE";
64 /* Chars that mean this number is a floating point constant, as
65 in "0f12.456" or "0d1.2345e12". */
67 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
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. */
73 /* Are we trying to generate PIC code? If so, absolute references
74 ought to be made into linkage table references or pc-relative
75 references. Not implemented. For ELF there are other means
76 to denote pic relocations. */
77 int flag_want_pic;
79 static int flag_short_refs; /* -l option. */
80 static int flag_long_jumps; /* -S option. */
81 static int flag_keep_pcrel; /* --pcrel option. */
83 #ifdef REGISTER_PREFIX_OPTIONAL
84 int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
85 #else
86 int flag_reg_prefix_optional;
87 #endif
89 /* Whether --register-prefix-optional was used on the command line. */
90 static int reg_prefix_optional_seen;
92 /* The floating point coprocessor to use by default. */
93 static enum m68k_register m68k_float_copnum = COP1;
95 /* If this is non-zero, then references to number(%pc) will be taken
96 to refer to number, rather than to %pc + number. */
97 static int m68k_abspcadd;
99 /* If this is non-zero, then the quick forms of the move, add, and sub
100 instructions are used when possible. */
101 static int m68k_quick = 1;
103 /* If this is non-zero, then if the size is not specified for a base
104 or outer displacement, the assembler assumes that the size should
105 be 32 bits. */
106 static int m68k_rel32 = 1;
108 /* This is non-zero if m68k_rel32 was set from the command line. */
109 static int m68k_rel32_from_cmdline;
111 /* The default width to use for an index register when using a base
112 displacement. */
113 static enum m68k_size m68k_index_width_default = SIZE_LONG;
115 /* We want to warn if any text labels are misaligned. In order to get
116 the right line number, we need to record the line number for each
117 label. */
118 struct label_line
120 struct label_line *next;
121 symbolS *label;
122 char *file;
123 unsigned int line;
124 int text;
127 /* The list of labels. */
129 static struct label_line *labels;
131 /* The current label. */
133 static struct label_line *current_label;
135 /* Pointer to list holding the opcodes sorted by name. */
136 static struct m68k_opcode const ** m68k_sorted_opcodes;
138 /* Its an arbitrary name: This means I don't approve of it.
139 See flames below. */
140 static struct obstack robyn;
142 struct m68k_incant
144 const char *m_operands;
145 unsigned long m_opcode;
146 short m_opnum;
147 short m_codenum;
148 int m_arch;
149 struct m68k_incant *m_next;
152 #define getone(x) ((((x)->m_opcode)>>16)&0xffff)
153 #define gettwo(x) (((x)->m_opcode)&0xffff)
155 static const enum m68k_register m68000_control_regs[] = { 0 };
156 static const enum m68k_register m68010_control_regs[] = {
157 SFC, DFC, USP, VBR,
160 static const enum m68k_register m68020_control_regs[] = {
161 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
164 static const enum m68k_register m68040_control_regs[] = {
165 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
166 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
169 static const enum m68k_register m68060_control_regs[] = {
170 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
171 USP, VBR, URP, SRP, PCR,
174 static const enum m68k_register mcf_control_regs[] = {
175 CACR, TC, ACR0, ACR1, ACR2, ACR3, VBR, ROMBAR,
176 RAMBAR0, RAMBAR1, MBAR,
179 static const enum m68k_register mcf5249_control_regs[] = {
180 CACR, ACR0, ACR1, VBR, RAMBAR0, RAMBAR1, MBAR, MBAR2,
183 static const enum m68k_register mcf528x_control_regs[] = {
184 CACR, ACR0, ACR1, VBR, FLASHBAR, RAMBAR,
187 static const enum m68k_register mcfv4e_control_regs[] = {
188 CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR, VBR, PC, ROMBAR,
189 ROMBAR1, RAMBAR0, RAMBAR1, MPCR, EDRAMBAR, SECMBAR, MBAR, MBAR0, MBAR1,
190 PCR1U0, PCR1L0, PCR1U1, PCR1L1, PCR2U0, PCR2L0, PCR2U1, PCR2L1,
191 PCR3U0, PCR3L0, PCR3U1, PCR3L1,
194 #define cpu32_control_regs m68010_control_regs
196 static const enum m68k_register *control_regs;
198 /* Internal form of a 68020 instruction. */
199 struct m68k_it
201 const char *error;
202 const char *args; /* List of opcode info. */
203 int numargs;
205 int numo; /* Number of shorts in opcode. */
206 short opcode[11];
208 struct m68k_op operands[6];
210 int nexp; /* Number of exprs in use. */
211 struct m68k_exp exprs[4];
213 int nfrag; /* Number of frags we have to produce. */
214 struct
216 int fragoff; /* Where in the current opcode the frag ends. */
217 symbolS *fadd;
218 offsetT foff;
219 int fragty;
221 fragb[4];
223 int nrel; /* Num of reloc strucs in use. */
224 struct
226 int n;
227 expressionS exp;
228 char wid;
229 char pcrel;
230 /* In a pc relative address the difference between the address
231 of the offset and the address that the offset is relative
232 to. This depends on the addressing mode. Basically this
233 is the value to put in the offset field to address the
234 first byte of the offset, without regarding the special
235 significance of some values (in the branch instruction, for
236 example). */
237 int pcrel_fix;
238 #ifdef OBJ_ELF
239 /* Whether this expression needs special pic relocation, and if
240 so, which. */
241 enum pic_relocation pic_reloc;
242 #endif
244 reloc[5]; /* Five is enough??? */
247 #define cpu_of_arch(x) ((x) & (m68000up | mcfisa_a))
248 #define float_of_arch(x) ((x) & mfloat)
249 #define mmu_of_arch(x) ((x) & mmmu)
250 #define arch_coldfire_p(x) ((x) & mcfisa_a)
251 #define arch_coldfire_fpu(x) ((x) & cfloat)
253 /* Macros for determining if cpu supports a specific addressing mode. */
254 #define HAVE_LONG_BRANCH(x) ((x) & (m68020|m68030|m68040|m68060|cpu32|mcfisa_b))
256 static struct m68k_it the_ins; /* The instruction being assembled. */
258 #define op(ex) ((ex)->exp.X_op)
259 #define adds(ex) ((ex)->exp.X_add_symbol)
260 #define subs(ex) ((ex)->exp.X_op_symbol)
261 #define offs(ex) ((ex)->exp.X_add_number)
263 /* Macros for adding things to the m68k_it struct. */
264 #define addword(w) (the_ins.opcode[the_ins.numo++] = (w))
266 /* Like addword, but goes BEFORE general operands. */
268 static void
269 insop (int w, const struct m68k_incant *opcode)
271 int z;
272 for (z = the_ins.numo; z > opcode->m_codenum; --z)
273 the_ins.opcode[z] = the_ins.opcode[z - 1];
274 for (z = 0; z < the_ins.nrel; z++)
275 the_ins.reloc[z].n += 2;
276 for (z = 0; z < the_ins.nfrag; z++)
277 the_ins.fragb[z].fragoff++;
278 the_ins.opcode[opcode->m_codenum] = w;
279 the_ins.numo++;
282 /* The numo+1 kludge is so we can hit the low order byte of the prev word.
283 Blecch. */
284 static void
285 add_fix (int width, struct m68k_exp *exp, int pc_rel, int pc_fix)
287 the_ins.reloc[the_ins.nrel].n = (width == 'B' || width == '3'
288 ? the_ins.numo * 2 - 1
289 : (width == 'b'
290 ? the_ins.numo * 2 + 1
291 : the_ins.numo * 2));
292 the_ins.reloc[the_ins.nrel].exp = exp->exp;
293 the_ins.reloc[the_ins.nrel].wid = width;
294 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
295 #ifdef OBJ_ELF
296 the_ins.reloc[the_ins.nrel].pic_reloc = exp->pic_reloc;
297 #endif
298 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
301 /* Cause an extra frag to be generated here, inserting up to 10 bytes
302 (that value is chosen in the frag_var call in md_assemble). TYPE
303 is the subtype of the frag to be generated; its primary type is
304 rs_machine_dependent.
306 The TYPE parameter is also used by md_convert_frag_1 and
307 md_estimate_size_before_relax. The appropriate type of fixup will
308 be emitted by md_convert_frag_1.
310 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
311 static void
312 add_frag (symbolS *add, offsetT off, int type)
314 the_ins.fragb[the_ins.nfrag].fragoff = the_ins.numo;
315 the_ins.fragb[the_ins.nfrag].fadd = add;
316 the_ins.fragb[the_ins.nfrag].foff = off;
317 the_ins.fragb[the_ins.nfrag++].fragty = type;
320 #define isvar(ex) \
321 (op (ex) != O_constant && op (ex) != O_big)
323 static char *crack_operand (char *str, struct m68k_op *opP);
324 static int get_num (struct m68k_exp *exp, int ok);
325 static int reverse_16_bits (int in);
326 static int reverse_8_bits (int in);
327 static void install_gen_operand (int mode, int val);
328 static void install_operand (int mode, int val);
329 static void s_bss (int);
330 static void s_data1 (int);
331 static void s_data2 (int);
332 static void s_even (int);
333 static void s_proc (int);
334 static void s_chip (int);
335 static void s_fopt (int);
336 static void s_opt (int);
337 static void s_reg (int);
338 static void s_restore (int);
339 static void s_save (int);
340 static void s_mri_if (int);
341 static void s_mri_else (int);
342 static void s_mri_endi (int);
343 static void s_mri_break (int);
344 static void s_mri_next (int);
345 static void s_mri_for (int);
346 static void s_mri_endf (int);
347 static void s_mri_repeat (int);
348 static void s_mri_until (int);
349 static void s_mri_while (int);
350 static void s_mri_endw (int);
352 static int current_architecture;
353 static int current_chip;
355 struct m68k_cpu
357 unsigned long arch;
358 unsigned long chip;
359 const char *name;
360 int alias;
363 static const struct m68k_cpu archs[] =
365 { m68000, m68000, "68000", 0 },
366 { m68010, m68010, "68010", 0 },
367 { m68020, m68020, "68020", 0 },
368 { m68030, m68030, "68030", 0 },
369 { m68040, m68040, "68040", 0 },
370 { m68060, m68060, "68060", 0 },
371 { cpu32, cpu32, "cpu32", 0 },
372 { m68881, m68881, "68881", 0 },
373 { m68851, m68851, "68851", 0 },
374 { mcfisa_a, mcf5200, "5200", 0 },
375 { mcfisa_a|mcfhwdiv|mcfmac, mcf5206e, "5206e", 0 },
376 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf521x, "521x", 0 },
377 { mcfisa_a|mcfhwdiv|mcfemac, mcf5249, "5249", 0 },
378 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac|mcfusp, mcf528x, "528x", 0 },
379 { mcfisa_a|mcfhwdiv|mcfmac, mcf5307, "5307", 0 },
380 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "5407", 0 },
381 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "547x", 0 },
382 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5480, "548x", 0 },
383 /* Aliases (effectively, so far as gas is concerned) for the above
384 cpus. */
385 { m68020, m68020, "68k", 1 },
386 { m68000, m68000, "68008", 1 },
387 { m68000, m68000, "68302", 1 },
388 { m68000, m68000, "68306", 1 },
389 { m68000, m68000, "68307", 1 },
390 { m68000, m68000, "68322", 1 },
391 { m68000, m68000, "68356", 1 },
392 { m68000, m68000, "68ec000", 1 },
393 { m68000, m68000, "68hc000", 1 },
394 { m68000, m68000, "68hc001", 1 },
395 { m68020, m68020, "68ec020", 1 },
396 { m68030, m68030, "68ec030", 1 },
397 { m68040, m68040, "68ec040", 1 },
398 { m68060, m68060, "68ec060", 1 },
399 { cpu32, cpu32, "68330", 1 },
400 { cpu32, cpu32, "68331", 1 },
401 { cpu32, cpu32, "68332", 1 },
402 { cpu32, cpu32, "68333", 1 },
403 { cpu32, cpu32, "68334", 1 },
404 { cpu32, cpu32, "68336", 1 },
405 { cpu32, cpu32, "68340", 1 },
406 { cpu32, cpu32, "68341", 1 },
407 { cpu32, cpu32, "68349", 1 },
408 { cpu32, cpu32, "68360", 1 },
409 { m68881, m68881, "68882", 1 },
410 { mcfisa_a, mcf5200, "5202", 1 },
411 { mcfisa_a, mcf5200, "5204", 1 },
412 { mcfisa_a, mcf5200, "5206", 1 },
413 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5214", 1 },
414 { mcfisa_a|mcfhwdiv|mcfisa_aa|mcfemac, mcf521x, "5216", 1 },
415 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5280", 1 },
416 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5281", 1 },
417 { mcfisa_a|mcfisa_aa|mcfhwdiv|mcfemac, mcf528x, "5282", 1 },
418 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfmac, mcf5407, "cfv4", 1 },
419 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5470", 1 },
420 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5471", 1 },
421 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5472", 1 },
422 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5473", 1 },
423 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5474", 1 },
424 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5475", 1 },
425 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5480", 1 },
426 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5481", 1 },
427 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5482", 1 },
428 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5483", 1 },
429 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5484", 1 },
430 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "5485", 1 },
431 { mcfisa_a|mcfhwdiv|mcfisa_b|mcfemac|mcfusp|cfloat, mcf5470, "cfv4e", 1 },
434 static const int n_archs = sizeof (archs) / sizeof (archs[0]);
436 /* This is the assembler relaxation table for m68k. m68k is a rich CISC
437 architecture and we have a lot of relaxation modes. */
439 /* Macros used in the relaxation code. */
440 #define TAB(x,y) (((x) << 2) + (y))
441 #define TABTYPE(x) ((x) >> 2)
443 /* Relaxation states. */
444 #define BYTE 0
445 #define SHORT 1
446 #define LONG 2
447 #define SZ_UNDEF 3
449 /* Here are all the relaxation modes we support. First we can relax ordinary
450 branches. On 68020 and higher and on CPU32 all branch instructions take
451 three forms, so on these CPUs all branches always remain as such. When we
452 have to expand to the LONG form on a 68000, though, we substitute an
453 absolute jump instead. This is a direct replacement for unconditional
454 branches and a branch over a jump for conditional branches. However, if the
455 user requires PIC and disables this with --pcrel, we can only relax between
456 BYTE and SHORT forms, punting if that isn't enough. This gives us four
457 different relaxation modes for branches: */
459 #define BRANCHBWL 0 /* Branch byte, word, or long. */
460 #define BRABSJUNC 1 /* Absolute jump for LONG, unconditional. */
461 #define BRABSJCOND 2 /* Absolute jump for LONG, conditional. */
462 #define BRANCHBW 3 /* Branch byte or word. */
464 /* We also relax coprocessor branches and DBcc's. All CPUs that support
465 coprocessor branches support them in word and long forms, so we have only
466 one relaxation mode for them. DBcc's are word only on all CPUs. We can
467 relax them to the LONG form with a branch-around sequence. This sequence
468 can use a long branch (if available) or an absolute jump (if acceptable).
469 This gives us two relaxation modes. If long branches are not available and
470 absolute jumps are not acceptable, we don't relax DBcc's. */
472 #define FBRANCH 4 /* Coprocessor branch. */
473 #define DBCCLBR 5 /* DBcc relaxable with a long branch. */
474 #define DBCCABSJ 6 /* DBcc relaxable with an absolute jump. */
476 /* That's all for instruction relaxation. However, we also relax PC-relative
477 operands. Specifically, we have three operand relaxation modes. On the
478 68000 PC-relative operands can only be 16-bit, but on 68020 and higher and
479 on CPU32 they may be 16-bit or 32-bit. For the latter we relax between the
480 two. Also PC+displacement+index operands in their simple form (with a non-
481 suppressed index without memory indirection) are supported on all CPUs, but
482 on the 68000 the displacement can be 8-bit only, whereas on 68020 and higher
483 and on CPU32 we relax it to SHORT and LONG forms as well using the extended
484 form of the PC+displacement+index operand. Finally, some absolute operands
485 can be relaxed down to 16-bit PC-relative. */
487 #define PCREL1632 7 /* 16-bit or 32-bit PC-relative. */
488 #define PCINDEX 8 /* PC + displacement + index. */
489 #define ABSTOPCREL 9 /* Absolute relax down to 16-bit PC-relative. */
491 /* Note that calls to frag_var need to specify the maximum expansion
492 needed; this is currently 10 bytes for DBCC. */
494 /* The fields are:
495 How far Forward this mode will reach:
496 How far Backward this mode will reach:
497 How many bytes this mode will add to the size of the frag
498 Which mode to go to if the offset won't fit in this one
500 Please check tc-m68k.h:md_prepare_relax_scan if changing this table. */
501 relax_typeS md_relax_table[] =
503 { 127, -128, 0, TAB (BRANCHBWL, SHORT) },
504 { 32767, -32768, 2, TAB (BRANCHBWL, LONG) },
505 { 0, 0, 4, 0 },
506 { 1, 1, 0, 0 },
508 { 127, -128, 0, TAB (BRABSJUNC, SHORT) },
509 { 32767, -32768, 2, TAB (BRABSJUNC, LONG) },
510 { 0, 0, 4, 0 },
511 { 1, 1, 0, 0 },
513 { 127, -128, 0, TAB (BRABSJCOND, SHORT) },
514 { 32767, -32768, 2, TAB (BRABSJCOND, LONG) },
515 { 0, 0, 6, 0 },
516 { 1, 1, 0, 0 },
518 { 127, -128, 0, TAB (BRANCHBW, SHORT) },
519 { 0, 0, 2, 0 },
520 { 1, 1, 0, 0 },
521 { 1, 1, 0, 0 },
523 { 1, 1, 0, 0 }, /* FBRANCH doesn't come BYTE. */
524 { 32767, -32768, 2, TAB (FBRANCH, LONG) },
525 { 0, 0, 4, 0 },
526 { 1, 1, 0, 0 },
528 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
529 { 32767, -32768, 2, TAB (DBCCLBR, LONG) },
530 { 0, 0, 10, 0 },
531 { 1, 1, 0, 0 },
533 { 1, 1, 0, 0 }, /* DBCC doesn't come BYTE. */
534 { 32767, -32768, 2, TAB (DBCCABSJ, LONG) },
535 { 0, 0, 10, 0 },
536 { 1, 1, 0, 0 },
538 { 1, 1, 0, 0 }, /* PCREL1632 doesn't come BYTE. */
539 { 32767, -32768, 2, TAB (PCREL1632, LONG) },
540 { 0, 0, 6, 0 },
541 { 1, 1, 0, 0 },
543 { 125, -130, 0, TAB (PCINDEX, SHORT) },
544 { 32765, -32770, 2, TAB (PCINDEX, LONG) },
545 { 0, 0, 4, 0 },
546 { 1, 1, 0, 0 },
548 { 1, 1, 0, 0 }, /* ABSTOPCREL doesn't come BYTE. */
549 { 32767, -32768, 2, TAB (ABSTOPCREL, LONG) },
550 { 0, 0, 4, 0 },
551 { 1, 1, 0, 0 },
554 /* These are the machine dependent pseudo-ops. These are included so
555 the assembler can work on the output from the SUN C compiler, which
556 generates these. */
558 /* This table describes all the machine specific pseudo-ops the assembler
559 has to support. The fields are:
560 pseudo-op name without dot
561 function to call to execute this pseudo-op
562 Integer arg to pass to the function. */
563 const pseudo_typeS md_pseudo_table[] =
565 {"data1", s_data1, 0},
566 {"data2", s_data2, 0},
567 {"bss", s_bss, 0},
568 {"even", s_even, 0},
569 {"skip", s_space, 0},
570 {"proc", s_proc, 0},
571 #if defined (TE_SUN3) || defined (OBJ_ELF)
572 {"align", s_align_bytes, 0},
573 #endif
574 #ifdef OBJ_ELF
575 {"swbeg", s_ignore, 0},
576 #endif
577 {"extend", float_cons, 'x'},
578 {"ldouble", float_cons, 'x'},
580 /* The following pseudo-ops are supported for MRI compatibility. */
581 {"chip", s_chip, 0},
582 {"comline", s_space, 1},
583 {"fopt", s_fopt, 0},
584 {"mask2", s_ignore, 0},
585 {"opt", s_opt, 0},
586 {"reg", s_reg, 0},
587 {"restore", s_restore, 0},
588 {"save", s_save, 0},
590 {"if", s_mri_if, 0},
591 {"if.b", s_mri_if, 'b'},
592 {"if.w", s_mri_if, 'w'},
593 {"if.l", s_mri_if, 'l'},
594 {"else", s_mri_else, 0},
595 {"else.s", s_mri_else, 's'},
596 {"else.l", s_mri_else, 'l'},
597 {"endi", s_mri_endi, 0},
598 {"break", s_mri_break, 0},
599 {"break.s", s_mri_break, 's'},
600 {"break.l", s_mri_break, 'l'},
601 {"next", s_mri_next, 0},
602 {"next.s", s_mri_next, 's'},
603 {"next.l", s_mri_next, 'l'},
604 {"for", s_mri_for, 0},
605 {"for.b", s_mri_for, 'b'},
606 {"for.w", s_mri_for, 'w'},
607 {"for.l", s_mri_for, 'l'},
608 {"endf", s_mri_endf, 0},
609 {"repeat", s_mri_repeat, 0},
610 {"until", s_mri_until, 0},
611 {"until.b", s_mri_until, 'b'},
612 {"until.w", s_mri_until, 'w'},
613 {"until.l", s_mri_until, 'l'},
614 {"while", s_mri_while, 0},
615 {"while.b", s_mri_while, 'b'},
616 {"while.w", s_mri_while, 'w'},
617 {"while.l", s_mri_while, 'l'},
618 {"endw", s_mri_endw, 0},
620 {0, 0, 0}
623 /* The mote pseudo ops are put into the opcode table, since they
624 don't start with a . they look like opcodes to gas. */
626 const pseudo_typeS mote_pseudo_table[] =
629 {"dcl", cons, 4},
630 {"dc", cons, 2},
631 {"dcw", cons, 2},
632 {"dcb", cons, 1},
634 {"dsl", s_space, 4},
635 {"ds", s_space, 2},
636 {"dsw", s_space, 2},
637 {"dsb", s_space, 1},
639 {"xdef", s_globl, 0},
640 #ifdef OBJ_ELF
641 {"align", s_align_bytes, 0},
642 #else
643 {"align", s_align_ptwo, 0},
644 #endif
645 #ifdef M68KCOFF
646 {"sect", obj_coff_section, 0},
647 {"section", obj_coff_section, 0},
648 #endif
649 {0, 0, 0}
652 /* Truncate and sign-extend at 32 bits, so that building on a 64-bit host
653 gives identical results to a 32-bit host. */
654 #define TRUNC(X) ((valueT) (X) & 0xffffffff)
655 #define SEXT(X) ((TRUNC (X) ^ 0x80000000) - 0x80000000)
657 #define issbyte(x) ((valueT) SEXT (x) + 0x80 < 0x100)
658 #define isubyte(x) ((valueT) TRUNC (x) < 0x100)
659 #define issword(x) ((valueT) SEXT (x) + 0x8000 < 0x10000)
660 #define isuword(x) ((valueT) TRUNC (x) < 0x10000)
662 #define isbyte(x) ((valueT) SEXT (x) + 0xff < 0x1ff)
663 #define isword(x) ((valueT) SEXT (x) + 0xffff < 0x1ffff)
664 #define islong(x) (1)
666 static char notend_table[256];
667 static char alt_notend_table[256];
668 #define notend(s) \
669 (! (notend_table[(unsigned char) *s] \
670 || (*s == ':' \
671 && alt_notend_table[(unsigned char) s[1]])))
673 /* Return a human readable string holding the list of chips that are
674 valid for a particular architecture, suppressing aliases (unless
675 there is only one of them). */
677 static char *
678 find_cf_chip (int architecture)
680 static char buf[1024];
681 int i, j, n_chips, n_alias;
682 char *cp;
684 strcpy (buf, " (");
685 cp = buf + strlen (buf);
687 for (i = 0, n_chips = 0, n_alias = 0; i < n_archs; ++i)
688 if (archs[i].arch & architecture)
690 n_chips++;
691 if (archs[i].alias)
692 n_alias++;
695 if (n_chips == 0)
696 as_fatal (_("no matching ColdFire architectures found"));
698 if (n_alias > 1)
699 n_chips -= n_alias;
701 for (i = 0, j = 0; i < n_archs && j < n_chips; ++i)
702 if (archs[i].arch & architecture)
704 if (j)
706 if ((j == n_chips - 1 && !(n_alias > 1)) || ! n_alias)
708 if (n_chips == 2)
710 strncpy (cp, _(" or "), (sizeof (buf) - (cp - buf)));
711 cp += strlen (cp);
713 else
715 strncpy (cp, _(", or "), (sizeof (buf) - (cp - buf)));
716 cp += strlen (cp);
719 else
721 strncpy (cp, ", ", (sizeof (buf) - (cp - buf)));
722 cp += strlen (cp);
725 strncpy (cp, archs[i].name, (sizeof (buf) - (cp - buf)));
726 cp += strlen (cp);
727 j++;
730 if (n_alias > 1)
732 strncpy (cp, _(", or aliases"), (sizeof (buf) - (cp - buf)));
733 cp += strlen (cp);
736 strncpy (cp, ")", (sizeof (buf) - (cp - buf)));
738 return buf;
741 #ifdef OBJ_ELF
743 /* Return zero if the reference to SYMBOL from within the same segment may
744 be relaxed. */
746 /* On an ELF system, we can't relax an externally visible symbol,
747 because it may be overridden by a shared library. However, if
748 TARGET_OS is "elf", then we presume that we are assembling for an
749 embedded system, in which case we don't have to worry about shared
750 libraries, and we can relax any external sym. */
752 #define relaxable_symbol(symbol) \
753 (!((S_IS_EXTERNAL (symbol) && EXTERN_FORCE_RELOC) \
754 || S_IS_WEAK (symbol)))
756 /* Compute the relocation code for a fixup of SIZE bytes, using pc
757 relative relocation if PCREL is non-zero. PIC says whether a special
758 pic relocation was requested. */
760 static bfd_reloc_code_real_type
761 get_reloc_code (int size, int pcrel, enum pic_relocation pic)
763 switch (pic)
765 case pic_got_pcrel:
766 switch (size)
768 case 1:
769 return BFD_RELOC_8_GOT_PCREL;
770 case 2:
771 return BFD_RELOC_16_GOT_PCREL;
772 case 4:
773 return BFD_RELOC_32_GOT_PCREL;
775 break;
777 case pic_got_off:
778 switch (size)
780 case 1:
781 return BFD_RELOC_8_GOTOFF;
782 case 2:
783 return BFD_RELOC_16_GOTOFF;
784 case 4:
785 return BFD_RELOC_32_GOTOFF;
787 break;
789 case pic_plt_pcrel:
790 switch (size)
792 case 1:
793 return BFD_RELOC_8_PLT_PCREL;
794 case 2:
795 return BFD_RELOC_16_PLT_PCREL;
796 case 4:
797 return BFD_RELOC_32_PLT_PCREL;
799 break;
801 case pic_plt_off:
802 switch (size)
804 case 1:
805 return BFD_RELOC_8_PLTOFF;
806 case 2:
807 return BFD_RELOC_16_PLTOFF;
808 case 4:
809 return BFD_RELOC_32_PLTOFF;
811 break;
813 case pic_none:
814 if (pcrel)
816 switch (size)
818 case 1:
819 return BFD_RELOC_8_PCREL;
820 case 2:
821 return BFD_RELOC_16_PCREL;
822 case 4:
823 return BFD_RELOC_32_PCREL;
826 else
828 switch (size)
830 case 1:
831 return BFD_RELOC_8;
832 case 2:
833 return BFD_RELOC_16;
834 case 4:
835 return BFD_RELOC_32;
840 if (pcrel)
842 if (pic == pic_none)
843 as_bad (_("Can not do %d byte pc-relative relocation"), size);
844 else
845 as_bad (_("Can not do %d byte pc-relative pic relocation"), size);
847 else
849 if (pic == pic_none)
850 as_bad (_("Can not do %d byte relocation"), size);
851 else
852 as_bad (_("Can not do %d byte pic relocation"), size);
855 return BFD_RELOC_NONE;
858 /* Here we decide which fixups can be adjusted to make them relative
859 to the beginning of the section instead of the symbol. Basically
860 we need to make sure that the dynamic relocations are done
861 correctly, so in some cases we force the original symbol to be
862 used. */
864 tc_m68k_fix_adjustable (fixS *fixP)
866 /* Adjust_reloc_syms doesn't know about the GOT. */
867 switch (fixP->fx_r_type)
869 case BFD_RELOC_8_GOT_PCREL:
870 case BFD_RELOC_16_GOT_PCREL:
871 case BFD_RELOC_32_GOT_PCREL:
872 case BFD_RELOC_8_GOTOFF:
873 case BFD_RELOC_16_GOTOFF:
874 case BFD_RELOC_32_GOTOFF:
875 case BFD_RELOC_8_PLT_PCREL:
876 case BFD_RELOC_16_PLT_PCREL:
877 case BFD_RELOC_32_PLT_PCREL:
878 case BFD_RELOC_8_PLTOFF:
879 case BFD_RELOC_16_PLTOFF:
880 case BFD_RELOC_32_PLTOFF:
881 return 0;
883 case BFD_RELOC_VTABLE_INHERIT:
884 case BFD_RELOC_VTABLE_ENTRY:
885 return 0;
887 default:
888 return 1;
892 #else /* !OBJ_ELF */
894 #define get_reloc_code(SIZE,PCREL,OTHER) NO_RELOC
896 #define relaxable_symbol(symbol) 1
898 #endif /* OBJ_ELF */
900 arelent *
901 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
903 arelent *reloc;
904 bfd_reloc_code_real_type code;
906 /* If the tcbit is set, then this was a fixup of a negative value
907 that was never resolved. We do not have a reloc to handle this,
908 so just return. We assume that other code will have detected this
909 situation and produced a helpful error message, so we just tell the
910 user that the reloc cannot be produced. */
911 if (fixp->fx_tcbit)
913 if (fixp->fx_addsy)
914 as_bad_where (fixp->fx_file, fixp->fx_line,
915 _("Unable to produce reloc against symbol '%s'"),
916 S_GET_NAME (fixp->fx_addsy));
917 return NULL;
920 if (fixp->fx_r_type != BFD_RELOC_NONE)
922 code = fixp->fx_r_type;
924 /* Since DIFF_EXPR_OK is defined in tc-m68k.h, it is possible
925 that fixup_segment converted a non-PC relative reloc into a
926 PC relative reloc. In such a case, we need to convert the
927 reloc code. */
928 if (fixp->fx_pcrel)
930 switch (code)
932 case BFD_RELOC_8:
933 code = BFD_RELOC_8_PCREL;
934 break;
935 case BFD_RELOC_16:
936 code = BFD_RELOC_16_PCREL;
937 break;
938 case BFD_RELOC_32:
939 code = BFD_RELOC_32_PCREL;
940 break;
941 case BFD_RELOC_8_PCREL:
942 case BFD_RELOC_16_PCREL:
943 case BFD_RELOC_32_PCREL:
944 case BFD_RELOC_8_GOT_PCREL:
945 case BFD_RELOC_16_GOT_PCREL:
946 case BFD_RELOC_32_GOT_PCREL:
947 case BFD_RELOC_8_GOTOFF:
948 case BFD_RELOC_16_GOTOFF:
949 case BFD_RELOC_32_GOTOFF:
950 case BFD_RELOC_8_PLT_PCREL:
951 case BFD_RELOC_16_PLT_PCREL:
952 case BFD_RELOC_32_PLT_PCREL:
953 case BFD_RELOC_8_PLTOFF:
954 case BFD_RELOC_16_PLTOFF:
955 case BFD_RELOC_32_PLTOFF:
956 break;
957 default:
958 as_bad_where (fixp->fx_file, fixp->fx_line,
959 _("Cannot make %s relocation PC relative"),
960 bfd_get_reloc_code_name (code));
964 else
966 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
967 switch (F (fixp->fx_size, fixp->fx_pcrel))
969 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
970 MAP (1, 0, BFD_RELOC_8);
971 MAP (2, 0, BFD_RELOC_16);
972 MAP (4, 0, BFD_RELOC_32);
973 MAP (1, 1, BFD_RELOC_8_PCREL);
974 MAP (2, 1, BFD_RELOC_16_PCREL);
975 MAP (4, 1, BFD_RELOC_32_PCREL);
976 default:
977 abort ();
980 #undef F
981 #undef MAP
983 reloc = (arelent *) xmalloc (sizeof (arelent));
984 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
985 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
986 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
987 #ifndef OBJ_ELF
988 if (fixp->fx_pcrel)
989 reloc->addend = fixp->fx_addnumber;
990 else
991 reloc->addend = 0;
992 #else
993 if (!fixp->fx_pcrel)
994 reloc->addend = fixp->fx_addnumber;
995 else
996 reloc->addend = (section->vma
997 /* Explicit sign extension in case char is
998 unsigned. */
999 + ((fixp->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80
1000 + fixp->fx_addnumber
1001 + md_pcrel_from (fixp));
1002 #endif
1004 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1005 assert (reloc->howto != 0);
1007 return reloc;
1010 /* Handle of the OPCODE hash table. NULL means any use before
1011 m68k_ip_begin() will crash. */
1012 static struct hash_control *op_hash;
1014 /* Assemble an m68k instruction. */
1016 static void
1017 m68k_ip (char *instring)
1019 register char *p;
1020 register struct m68k_op *opP;
1021 register const struct m68k_incant *opcode;
1022 register const char *s;
1023 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
1024 char *pdot, *pdotmove;
1025 enum m68k_size siz1, siz2;
1026 char c;
1027 int losing;
1028 int opsfound;
1029 struct m68k_op operands_backup[6];
1030 LITTLENUM_TYPE words[6];
1031 LITTLENUM_TYPE *wordp;
1032 unsigned long ok_arch = 0;
1034 if (*instring == ' ')
1035 instring++; /* Skip leading whitespace. */
1037 /* Scan up to end of operation-code, which MUST end in end-of-string
1038 or exactly 1 space. */
1039 pdot = 0;
1040 for (p = instring; *p != '\0'; p++)
1042 if (*p == ' ')
1043 break;
1044 if (*p == '.')
1045 pdot = p;
1048 if (p == instring)
1050 the_ins.error = _("No operator");
1051 return;
1054 /* p now points to the end of the opcode name, probably whitespace.
1055 Make sure the name is null terminated by clobbering the
1056 whitespace, look it up in the hash table, then fix it back.
1057 Remove a dot, first, since the opcode tables have none. */
1058 if (pdot != NULL)
1060 for (pdotmove = pdot; pdotmove < p; pdotmove++)
1061 *pdotmove = pdotmove[1];
1062 p--;
1065 c = *p;
1066 *p = '\0';
1067 opcode = (const struct m68k_incant *) hash_find (op_hash, instring);
1068 *p = c;
1070 if (pdot != NULL)
1072 for (pdotmove = p; pdotmove > pdot; pdotmove--)
1073 *pdotmove = pdotmove[-1];
1074 *pdot = '.';
1075 ++p;
1078 if (opcode == NULL)
1080 the_ins.error = _("Unknown operator");
1081 return;
1084 /* Found a legitimate opcode, start matching operands. */
1085 while (*p == ' ')
1086 ++p;
1088 if (opcode->m_operands == 0)
1090 char *old = input_line_pointer;
1091 *old = '\n';
1092 input_line_pointer = p;
1093 /* Ahh - it's a motorola style psuedo op. */
1094 mote_pseudo_table[opcode->m_opnum].poc_handler
1095 (mote_pseudo_table[opcode->m_opnum].poc_val);
1096 input_line_pointer = old;
1097 *old = 0;
1099 return;
1102 if (flag_mri && opcode->m_opnum == 0)
1104 /* In MRI mode, random garbage is allowed after an instruction
1105 which accepts no operands. */
1106 the_ins.args = opcode->m_operands;
1107 the_ins.numargs = opcode->m_opnum;
1108 the_ins.numo = opcode->m_codenum;
1109 the_ins.opcode[0] = getone (opcode);
1110 the_ins.opcode[1] = gettwo (opcode);
1111 return;
1114 for (opP = &the_ins.operands[0]; *p; opP++)
1116 p = crack_operand (p, opP);
1118 if (opP->error)
1120 the_ins.error = opP->error;
1121 return;
1125 opsfound = opP - &the_ins.operands[0];
1127 /* This ugly hack is to support the floating pt opcodes in their
1128 standard form. Essentially, we fake a first enty of type COP#1 */
1129 if (opcode->m_operands[0] == 'I')
1131 int n;
1133 for (n = opsfound; n > 0; --n)
1134 the_ins.operands[n] = the_ins.operands[n - 1];
1136 memset (&the_ins.operands[0], '\0', sizeof (the_ins.operands[0]));
1137 the_ins.operands[0].mode = CONTROL;
1138 the_ins.operands[0].reg = m68k_float_copnum;
1139 opsfound++;
1142 /* We've got the operands. Find an opcode that'll accept them. */
1143 for (losing = 0;;)
1145 /* If we didn't get the right number of ops, or we have no
1146 common model with this pattern then reject this pattern. */
1148 ok_arch |= opcode->m_arch;
1149 if (opsfound != opcode->m_opnum
1150 || ((opcode->m_arch & current_architecture) == 0))
1151 ++losing;
1152 else
1154 int i;
1156 /* Make a copy of the operands of this insn so that
1157 we can modify them safely, should we want to. */
1158 assert (opsfound <= (int) ARRAY_SIZE (operands_backup));
1159 for (i = 0; i < opsfound; i++)
1160 operands_backup[i] = the_ins.operands[i];
1162 for (s = opcode->m_operands, opP = &operands_backup[0];
1163 *s && !losing;
1164 s += 2, opP++)
1166 /* Warning: this switch is huge! */
1167 /* I've tried to organize the cases into this order:
1168 non-alpha first, then alpha by letter. Lower-case
1169 goes directly before uppercase counterpart. */
1170 /* Code with multiple case ...: gets sorted by the lowest
1171 case ... it belongs to. I hope this makes sense. */
1172 switch (*s)
1174 case '!':
1175 switch (opP->mode)
1177 case IMMED:
1178 case DREG:
1179 case AREG:
1180 case FPREG:
1181 case CONTROL:
1182 case AINC:
1183 case ADEC:
1184 case REGLST:
1185 losing++;
1186 break;
1187 default:
1188 break;
1190 break;
1192 case '<':
1193 switch (opP->mode)
1195 case DREG:
1196 case AREG:
1197 case FPREG:
1198 case CONTROL:
1199 case IMMED:
1200 case ADEC:
1201 case REGLST:
1202 losing++;
1203 break;
1204 default:
1205 break;
1207 break;
1209 case '>':
1210 switch (opP->mode)
1212 case DREG:
1213 case AREG:
1214 case FPREG:
1215 case CONTROL:
1216 case IMMED:
1217 case AINC:
1218 case REGLST:
1219 losing++;
1220 break;
1221 case ABSL:
1222 break;
1223 default:
1224 if (opP->reg == PC
1225 || opP->reg == ZPC)
1226 losing++;
1227 break;
1229 break;
1231 case 'm':
1232 switch (opP->mode)
1234 case DREG:
1235 case AREG:
1236 case AINDR:
1237 case AINC:
1238 case ADEC:
1239 break;
1240 default:
1241 losing++;
1243 break;
1245 case 'n':
1246 switch (opP->mode)
1248 case DISP:
1249 break;
1250 default:
1251 losing++;
1253 break;
1255 case 'o':
1256 switch (opP->mode)
1258 case BASE:
1259 case ABSL:
1260 case IMMED:
1261 break;
1262 default:
1263 losing++;
1265 break;
1267 case 'p':
1268 switch (opP->mode)
1270 case DREG:
1271 case AREG:
1272 case AINDR:
1273 case AINC:
1274 case ADEC:
1275 break;
1276 case DISP:
1277 if (opP->reg == PC || opP->reg == ZPC)
1278 losing++;
1279 break;
1280 default:
1281 losing++;
1283 break;
1285 case 'q':
1286 switch (opP->mode)
1288 case DREG:
1289 case AINDR:
1290 case AINC:
1291 case ADEC:
1292 break;
1293 case DISP:
1294 if (opP->reg == PC || opP->reg == ZPC)
1295 losing++;
1296 break;
1297 default:
1298 losing++;
1299 break;
1301 break;
1303 case 'v':
1304 switch (opP->mode)
1306 case DREG:
1307 case AINDR:
1308 case AINC:
1309 case ADEC:
1310 case ABSL:
1311 break;
1312 case DISP:
1313 if (opP->reg == PC || opP->reg == ZPC)
1314 losing++;
1315 break;
1316 default:
1317 losing++;
1318 break;
1320 break;
1322 case '#':
1323 if (opP->mode != IMMED)
1324 losing++;
1325 else if (s[1] == 'b'
1326 && ! isvar (&opP->disp)
1327 && (opP->disp.exp.X_op != O_constant
1328 || ! isbyte (opP->disp.exp.X_add_number)))
1329 losing++;
1330 else if (s[1] == 'B'
1331 && ! isvar (&opP->disp)
1332 && (opP->disp.exp.X_op != O_constant
1333 || ! issbyte (opP->disp.exp.X_add_number)))
1334 losing++;
1335 else if (s[1] == 'w'
1336 && ! isvar (&opP->disp)
1337 && (opP->disp.exp.X_op != O_constant
1338 || ! isword (opP->disp.exp.X_add_number)))
1339 losing++;
1340 else if (s[1] == 'W'
1341 && ! isvar (&opP->disp)
1342 && (opP->disp.exp.X_op != O_constant
1343 || ! issword (opP->disp.exp.X_add_number)))
1344 losing++;
1345 break;
1347 case '^':
1348 case 'T':
1349 if (opP->mode != IMMED)
1350 losing++;
1351 break;
1353 case '$':
1354 if (opP->mode == AREG
1355 || opP->mode == CONTROL
1356 || opP->mode == FPREG
1357 || opP->mode == IMMED
1358 || opP->mode == REGLST
1359 || (opP->mode != ABSL
1360 && (opP->reg == PC
1361 || opP->reg == ZPC)))
1362 losing++;
1363 break;
1365 case '%':
1366 if (opP->mode == CONTROL
1367 || opP->mode == FPREG
1368 || opP->mode == REGLST
1369 || opP->mode == IMMED
1370 || (opP->mode != ABSL
1371 && (opP->reg == PC
1372 || opP->reg == ZPC)))
1373 losing++;
1374 break;
1376 case '&':
1377 switch (opP->mode)
1379 case DREG:
1380 case AREG:
1381 case FPREG:
1382 case CONTROL:
1383 case IMMED:
1384 case AINC:
1385 case ADEC:
1386 case REGLST:
1387 losing++;
1388 break;
1389 case ABSL:
1390 break;
1391 default:
1392 if (opP->reg == PC
1393 || opP->reg == ZPC)
1394 losing++;
1395 break;
1397 break;
1399 case '*':
1400 if (opP->mode == CONTROL
1401 || opP->mode == FPREG
1402 || opP->mode == REGLST)
1403 losing++;
1404 break;
1406 case '+':
1407 if (opP->mode != AINC)
1408 losing++;
1409 break;
1411 case '-':
1412 if (opP->mode != ADEC)
1413 losing++;
1414 break;
1416 case '/':
1417 switch (opP->mode)
1419 case AREG:
1420 case CONTROL:
1421 case FPREG:
1422 case AINC:
1423 case ADEC:
1424 case IMMED:
1425 case REGLST:
1426 losing++;
1427 break;
1428 default:
1429 break;
1431 break;
1433 case ';':
1434 switch (opP->mode)
1436 case AREG:
1437 case CONTROL:
1438 case FPREG:
1439 case REGLST:
1440 losing++;
1441 break;
1442 default:
1443 break;
1445 break;
1447 case '?':
1448 switch (opP->mode)
1450 case AREG:
1451 case CONTROL:
1452 case FPREG:
1453 case AINC:
1454 case ADEC:
1455 case IMMED:
1456 case REGLST:
1457 losing++;
1458 break;
1459 case ABSL:
1460 break;
1461 default:
1462 if (opP->reg == PC || opP->reg == ZPC)
1463 losing++;
1464 break;
1466 break;
1468 case '@':
1469 switch (opP->mode)
1471 case AREG:
1472 case CONTROL:
1473 case FPREG:
1474 case IMMED:
1475 case REGLST:
1476 losing++;
1477 break;
1478 default:
1479 break;
1481 break;
1483 case '~': /* For now! (JF FOO is this right?) */
1484 switch (opP->mode)
1486 case DREG:
1487 case AREG:
1488 case CONTROL:
1489 case FPREG:
1490 case IMMED:
1491 case REGLST:
1492 losing++;
1493 break;
1494 case ABSL:
1495 break;
1496 default:
1497 if (opP->reg == PC
1498 || opP->reg == ZPC)
1499 losing++;
1500 break;
1502 break;
1504 case '3':
1505 if (opP->mode != CONTROL
1506 || (opP->reg != TT0 && opP->reg != TT1))
1507 losing++;
1508 break;
1510 case 'A':
1511 if (opP->mode != AREG)
1512 losing++;
1513 break;
1515 case 'a':
1516 if (opP->mode != AINDR)
1517 ++losing;
1518 break;
1520 case '4':
1521 if (opP->mode != AINDR && opP->mode != AINC && opP->mode != ADEC
1522 && (opP->mode != DISP
1523 || opP->reg < ADDR0
1524 || opP->reg > ADDR7))
1525 ++losing;
1526 break;
1528 case 'B': /* FOO */
1529 if (opP->mode != ABSL
1530 || (flag_long_jumps
1531 && strncmp (instring, "jbsr", 4) == 0))
1532 losing++;
1533 break;
1535 case 'b':
1536 switch (opP->mode)
1538 case IMMED:
1539 case ABSL:
1540 case AREG:
1541 case FPREG:
1542 case CONTROL:
1543 case POST:
1544 case PRE:
1545 case REGLST:
1546 losing++;
1547 break;
1548 default:
1549 break;
1551 break;
1553 case 'C':
1554 if (opP->mode != CONTROL || opP->reg != CCR)
1555 losing++;
1556 break;
1558 case 'd':
1559 if (opP->mode != DISP
1560 || opP->reg < ADDR0
1561 || opP->reg > ADDR7)
1562 losing++;
1563 break;
1565 case 'D':
1566 if (opP->mode != DREG)
1567 losing++;
1568 break;
1570 case 'E':
1571 if (opP->reg != ACC)
1572 losing++;
1573 break;
1575 case 'e':
1576 if (opP->reg != ACC && opP->reg != ACC1
1577 && opP->reg != ACC2 && opP->reg != ACC3)
1578 losing++;
1579 break;
1581 case 'F':
1582 if (opP->mode != FPREG)
1583 losing++;
1584 break;
1586 case 'G':
1587 if (opP->reg != MACSR)
1588 losing++;
1589 break;
1591 case 'g':
1592 if (opP->reg != ACCEXT01 && opP->reg != ACCEXT23)
1593 losing++;
1594 break;
1596 case 'H':
1597 if (opP->reg != MASK)
1598 losing++;
1599 break;
1601 case 'I':
1602 if (opP->mode != CONTROL
1603 || opP->reg < COP0
1604 || opP->reg > COP7)
1605 losing++;
1606 break;
1608 case 'i':
1609 if (opP->mode != LSH && opP->mode != RSH)
1610 losing++;
1611 break;
1613 case 'J':
1614 if (opP->mode != CONTROL
1615 || opP->reg < USP
1616 || opP->reg > last_movec_reg)
1617 losing++;
1618 else
1620 const enum m68k_register *rp;
1621 for (rp = control_regs; *rp; rp++)
1622 if (*rp == opP->reg)
1623 break;
1624 if (*rp == 0)
1625 losing++;
1627 break;
1629 case 'k':
1630 if (opP->mode != IMMED)
1631 losing++;
1632 break;
1634 case 'l':
1635 case 'L':
1636 if (opP->mode == DREG
1637 || opP->mode == AREG
1638 || opP->mode == FPREG)
1640 if (s[1] == '8')
1641 losing++;
1642 else
1644 switch (opP->mode)
1646 case DREG:
1647 opP->mask = 1 << (opP->reg - DATA0);
1648 break;
1649 case AREG:
1650 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1651 break;
1652 case FPREG:
1653 opP->mask = 1 << (opP->reg - FP0 + 16);
1654 break;
1655 default:
1656 abort ();
1658 opP->mode = REGLST;
1661 else if (opP->mode == CONTROL)
1663 if (s[1] != '8')
1664 losing++;
1665 else
1667 switch (opP->reg)
1669 case FPI:
1670 opP->mask = 1 << 24;
1671 break;
1672 case FPS:
1673 opP->mask = 1 << 25;
1674 break;
1675 case FPC:
1676 opP->mask = 1 << 26;
1677 break;
1678 default:
1679 losing++;
1680 break;
1682 opP->mode = REGLST;
1685 else if (opP->mode != REGLST)
1686 losing++;
1687 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1688 losing++;
1689 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
1690 losing++;
1691 break;
1693 case 'M':
1694 if (opP->mode != IMMED)
1695 losing++;
1696 else if (opP->disp.exp.X_op != O_constant
1697 || ! issbyte (opP->disp.exp.X_add_number))
1698 losing++;
1699 else if (! m68k_quick
1700 && instring[3] != 'q'
1701 && instring[4] != 'q')
1702 losing++;
1703 break;
1705 case 'O':
1706 if (opP->mode != DREG
1707 && opP->mode != IMMED
1708 && opP->mode != ABSL)
1709 losing++;
1710 break;
1712 case 'Q':
1713 if (opP->mode != IMMED)
1714 losing++;
1715 else if (opP->disp.exp.X_op != O_constant
1716 || TRUNC (opP->disp.exp.X_add_number) - 1 > 7)
1717 losing++;
1718 else if (! m68k_quick
1719 && (strncmp (instring, "add", 3) == 0
1720 || strncmp (instring, "sub", 3) == 0)
1721 && instring[3] != 'q')
1722 losing++;
1723 break;
1725 case 'R':
1726 if (opP->mode != DREG && opP->mode != AREG)
1727 losing++;
1728 break;
1730 case 'r':
1731 if (opP->mode != AINDR
1732 && (opP->mode != BASE
1733 || (opP->reg != 0
1734 && opP->reg != ZADDR0)
1735 || opP->disp.exp.X_op != O_absent
1736 || ((opP->index.reg < DATA0
1737 || opP->index.reg > DATA7)
1738 && (opP->index.reg < ADDR0
1739 || opP->index.reg > ADDR7))
1740 || opP->index.size != SIZE_UNSPEC
1741 || opP->index.scale != 1))
1742 losing++;
1743 break;
1745 case 's':
1746 if (opP->mode != CONTROL
1747 || ! (opP->reg == FPI
1748 || opP->reg == FPS
1749 || opP->reg == FPC))
1750 losing++;
1751 break;
1753 case 'S':
1754 if (opP->mode != CONTROL || opP->reg != SR)
1755 losing++;
1756 break;
1758 case 't':
1759 if (opP->mode != IMMED)
1760 losing++;
1761 else if (opP->disp.exp.X_op != O_constant
1762 || TRUNC (opP->disp.exp.X_add_number) > 7)
1763 losing++;
1764 break;
1766 case 'U':
1767 if (opP->mode != CONTROL || opP->reg != USP)
1768 losing++;
1769 break;
1771 case 'x':
1772 if (opP->mode != IMMED)
1773 losing++;
1774 else if (opP->disp.exp.X_op != O_constant
1775 || (TRUNC (opP->disp.exp.X_add_number) != 0xffffffff
1776 && TRUNC (opP->disp.exp.X_add_number) - 1 > 6))
1777 losing++;
1778 break;
1780 /* JF these are out of order. We could put them
1781 in order if we were willing to put up with
1782 bunches of #ifdef m68851s in the code.
1784 Don't forget that you need these operands
1785 to use 68030 MMU instructions. */
1786 #ifndef NO_68851
1787 /* Memory addressing mode used by pflushr. */
1788 case '|':
1789 if (opP->mode == CONTROL
1790 || opP->mode == FPREG
1791 || opP->mode == DREG
1792 || opP->mode == AREG
1793 || opP->mode == REGLST)
1794 losing++;
1795 /* We should accept immediate operands, but they
1796 supposedly have to be quad word, and we don't
1797 handle that. I would like to see what a Motorola
1798 assembler does before doing something here. */
1799 if (opP->mode == IMMED)
1800 losing++;
1801 break;
1803 case 'f':
1804 if (opP->mode != CONTROL
1805 || (opP->reg != SFC && opP->reg != DFC))
1806 losing++;
1807 break;
1809 case '0':
1810 if (opP->mode != CONTROL || opP->reg != TC)
1811 losing++;
1812 break;
1814 case '1':
1815 if (opP->mode != CONTROL || opP->reg != AC)
1816 losing++;
1817 break;
1819 case '2':
1820 if (opP->mode != CONTROL
1821 || (opP->reg != CAL
1822 && opP->reg != VAL
1823 && opP->reg != SCC))
1824 losing++;
1825 break;
1827 case 'V':
1828 if (opP->mode != CONTROL
1829 || opP->reg != VAL)
1830 losing++;
1831 break;
1833 case 'W':
1834 if (opP->mode != CONTROL
1835 || (opP->reg != DRP
1836 && opP->reg != SRP
1837 && opP->reg != CRP))
1838 losing++;
1839 break;
1841 case 'w':
1842 switch (opP->mode)
1844 case IMMED:
1845 case ABSL:
1846 case AREG:
1847 case DREG:
1848 case FPREG:
1849 case CONTROL:
1850 case POST:
1851 case PRE:
1852 case REGLST:
1853 losing++;
1854 break;
1855 default:
1856 break;
1858 break;
1860 case 'X':
1861 if (opP->mode != CONTROL
1862 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1863 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
1864 losing++;
1865 break;
1867 case 'Y':
1868 if (opP->mode != CONTROL || opP->reg != PSR)
1869 losing++;
1870 break;
1872 case 'Z':
1873 if (opP->mode != CONTROL || opP->reg != PCSR)
1874 losing++;
1875 break;
1876 #endif
1877 case 'c':
1878 if (opP->mode != CONTROL
1879 || (opP->reg != NC
1880 && opP->reg != IC
1881 && opP->reg != DC
1882 && opP->reg != BC))
1883 losing++;
1884 break;
1886 case '_':
1887 if (opP->mode != ABSL)
1888 ++losing;
1889 break;
1891 case 'u':
1892 if (opP->reg < DATA0L || opP->reg > ADDR7U)
1893 losing++;
1894 /* FIXME: kludge instead of fixing parser:
1895 upper/lower registers are *not* CONTROL
1896 registers, but ordinary ones. */
1897 if ((opP->reg >= DATA0L && opP->reg <= DATA7L)
1898 || (opP->reg >= DATA0U && opP->reg <= DATA7U))
1899 opP->mode = DREG;
1900 else
1901 opP->mode = AREG;
1902 break;
1904 case 'y':
1905 if (!(opP->mode == AINDR
1906 || (opP->mode == DISP
1907 && !(opP->reg == PC || opP->reg == ZPC))))
1908 losing++;
1909 break;
1911 case 'z':
1912 if (!(opP->mode == AINDR || opP->mode == DISP))
1913 losing++;
1914 break;
1916 default:
1917 abort ();
1920 if (losing)
1921 break;
1924 /* Since we have found the correct instruction, copy
1925 in the modifications that we may have made. */
1926 if (!losing)
1927 for (i = 0; i < opsfound; i++)
1928 the_ins.operands[i] = operands_backup[i];
1931 if (!losing)
1932 break;
1934 opcode = opcode->m_next;
1936 if (!opcode)
1938 if (ok_arch
1939 && !(ok_arch & current_architecture))
1941 char buf[200], *cp;
1943 strncpy (buf,
1944 _("invalid instruction for this architecture; needs "),
1945 sizeof (buf));
1946 cp = buf + strlen (buf);
1947 switch (ok_arch)
1949 case mcfisa_a:
1950 strncpy (cp, _("ColdFire ISA_A"),
1951 sizeof (buf) - (cp - buf));
1952 cp += strlen (cp);
1953 strncpy (cp, find_cf_chip (ok_arch),
1954 sizeof (buf) - (cp - buf));
1955 cp += strlen (cp);
1956 break;
1957 case mcfhwdiv:
1958 strncpy (cp, _("ColdFire hardware divide"),
1959 sizeof (buf) - (cp - buf));
1960 cp += strlen (cp);
1961 strncpy (cp, find_cf_chip (ok_arch),
1962 sizeof (buf) - (cp - buf));
1963 cp += strlen (cp);
1964 break;
1965 case mcfisa_aa:
1966 strncpy (cp, _("ColdFire ISA_A+"),
1967 sizeof (buf) - (cp - buf));
1968 cp += strlen (cp);
1969 strncpy (cp, find_cf_chip (ok_arch),
1970 sizeof (buf) - (cp - buf));
1971 cp += strlen (cp);
1972 break;
1973 case mcfisa_b:
1974 strncpy (cp, _("ColdFire ISA_B"),
1975 sizeof (buf) - (cp - buf));
1976 cp += strlen (cp);
1977 strncpy (cp, find_cf_chip (ok_arch),
1978 sizeof (buf) - (cp - buf));
1979 cp += strlen (cp);
1980 break;
1981 case cfloat:
1982 strncpy (cp, _("ColdFire fpu"), sizeof (buf) - (cp - buf));
1983 cp += strlen (cp);
1984 strncpy (cp, find_cf_chip (ok_arch),
1985 sizeof (buf) - (cp - buf));
1986 cp += strlen (cp);
1987 break;
1988 case mfloat:
1989 strcpy (cp, _("fpu (68040, 68060 or 68881/68882)"));
1990 break;
1991 case mmmu:
1992 strcpy (cp, _("mmu (68030 or 68851)"));
1993 break;
1994 case m68020up:
1995 strcpy (cp, _("68020 or higher"));
1996 break;
1997 case m68000up:
1998 strcpy (cp, _("68000 or higher"));
1999 break;
2000 case m68010up:
2001 strcpy (cp, _("68010 or higher"));
2002 break;
2003 default:
2005 int got_one = 0, idx;
2007 for (idx = 0; idx < n_archs; idx++)
2009 if ((archs[idx].arch & ok_arch)
2010 && ! archs[idx].alias)
2012 if (got_one)
2014 strcpy (cp, " or ");
2015 cp += strlen (cp);
2017 got_one = 1;
2018 strcpy (cp, archs[idx].name);
2019 cp += strlen (cp);
2024 cp = xmalloc (strlen (buf) + 1);
2025 strcpy (cp, buf);
2026 the_ins.error = cp;
2028 else
2029 the_ins.error = _("operands mismatch");
2030 return;
2033 losing = 0;
2036 /* Now assemble it. */
2037 the_ins.args = opcode->m_operands;
2038 the_ins.numargs = opcode->m_opnum;
2039 the_ins.numo = opcode->m_codenum;
2040 the_ins.opcode[0] = getone (opcode);
2041 the_ins.opcode[1] = gettwo (opcode);
2043 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
2045 /* This switch is a doozy.
2046 Watch the first step; its a big one! */
2047 switch (s[0])
2050 case '*':
2051 case '~':
2052 case '%':
2053 case ';':
2054 case '@':
2055 case '!':
2056 case '&':
2057 case '$':
2058 case '?':
2059 case '/':
2060 case '<':
2061 case '>':
2062 case 'b':
2063 case 'm':
2064 case 'n':
2065 case 'o':
2066 case 'p':
2067 case 'q':
2068 case 'v':
2069 case 'w':
2070 case 'y':
2071 case 'z':
2072 case '4':
2073 #ifndef NO_68851
2074 case '|':
2075 #endif
2076 switch (opP->mode)
2078 case IMMED:
2079 tmpreg = 0x3c; /* 7.4 */
2080 if (strchr ("bwl", s[1]))
2081 nextword = get_num (&opP->disp, 90);
2082 else
2083 nextword = get_num (&opP->disp, 0);
2084 if (isvar (&opP->disp))
2085 add_fix (s[1], &opP->disp, 0, 0);
2086 switch (s[1])
2088 case 'b':
2089 if (!isbyte (nextword))
2090 opP->error = _("operand out of range");
2091 addword (nextword);
2092 baseo = 0;
2093 break;
2094 case 'w':
2095 if (!isword (nextword))
2096 opP->error = _("operand out of range");
2097 addword (nextword);
2098 baseo = 0;
2099 break;
2100 case 'W':
2101 if (!issword (nextword))
2102 opP->error = _("operand out of range");
2103 addword (nextword);
2104 baseo = 0;
2105 break;
2106 case 'l':
2107 addword (nextword >> 16);
2108 addword (nextword);
2109 baseo = 0;
2110 break;
2112 case 'f':
2113 baseo = 2;
2114 outro = 8;
2115 break;
2116 case 'F':
2117 baseo = 4;
2118 outro = 11;
2119 break;
2120 case 'x':
2121 baseo = 6;
2122 outro = 15;
2123 break;
2124 case 'p':
2125 baseo = 6;
2126 outro = -1;
2127 break;
2128 default:
2129 abort ();
2131 if (!baseo)
2132 break;
2134 /* We gotta put out some float. */
2135 if (op (&opP->disp) != O_big)
2137 valueT val;
2138 int gencnt;
2140 /* Can other cases happen here? */
2141 if (op (&opP->disp) != O_constant)
2142 abort ();
2144 val = (valueT) offs (&opP->disp);
2145 gencnt = 0;
2148 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
2149 val >>= LITTLENUM_NUMBER_OF_BITS;
2150 ++gencnt;
2152 while (val != 0);
2153 offs (&opP->disp) = gencnt;
2155 if (offs (&opP->disp) > 0)
2157 if (offs (&opP->disp) > baseo)
2159 as_warn (_("Bignum too big for %c format; truncated"),
2160 s[1]);
2161 offs (&opP->disp) = baseo;
2163 baseo -= offs (&opP->disp);
2164 while (baseo--)
2165 addword (0);
2166 for (wordp = generic_bignum + offs (&opP->disp) - 1;
2167 offs (&opP->disp)--;
2168 --wordp)
2169 addword (*wordp);
2170 break;
2172 gen_to_words (words, baseo, (long) outro);
2173 for (wordp = words; baseo--; wordp++)
2174 addword (*wordp);
2175 break;
2176 case DREG:
2177 tmpreg = opP->reg - DATA; /* 0.dreg */
2178 break;
2179 case AREG:
2180 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
2181 break;
2182 case AINDR:
2183 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2184 break;
2185 case ADEC:
2186 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
2187 break;
2188 case AINC:
2189 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
2190 break;
2191 case DISP:
2193 nextword = get_num (&opP->disp, 90);
2195 /* Convert mode 5 addressing with a zero offset into
2196 mode 2 addressing to reduce the instruction size by a
2197 word. */
2198 if (! isvar (&opP->disp)
2199 && (nextword == 0)
2200 && (opP->disp.size == SIZE_UNSPEC)
2201 && (opP->reg >= ADDR0)
2202 && (opP->reg <= ADDR7))
2204 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
2205 break;
2208 if (opP->reg == PC
2209 && ! isvar (&opP->disp)
2210 && m68k_abspcadd)
2212 opP->disp.exp.X_op = O_symbol;
2213 opP->disp.exp.X_add_symbol =
2214 section_symbol (absolute_section);
2217 /* Force into index mode. Hope this works. */
2219 /* We do the first bit for 32-bit displacements, and the
2220 second bit for 16 bit ones. It is possible that we
2221 should make the default be WORD instead of LONG, but
2222 I think that'd break GCC, so we put up with a little
2223 inefficiency for the sake of working output. */
2225 if (!issword (nextword)
2226 || (isvar (&opP->disp)
2227 && ((opP->disp.size == SIZE_UNSPEC
2228 && flag_short_refs == 0
2229 && cpu_of_arch (current_architecture) >= m68020
2230 && ! arch_coldfire_p (current_architecture))
2231 || opP->disp.size == SIZE_LONG)))
2233 if (cpu_of_arch (current_architecture) < m68020
2234 || arch_coldfire_p (current_architecture))
2235 opP->error =
2236 _("displacement too large for this architecture; needs 68020 or higher");
2237 if (opP->reg == PC)
2238 tmpreg = 0x3B; /* 7.3 */
2239 else
2240 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2241 if (isvar (&opP->disp))
2243 if (opP->reg == PC)
2245 if (opP->disp.size == SIZE_LONG
2246 #ifdef OBJ_ELF
2247 /* If the displacement needs pic
2248 relocation it cannot be relaxed. */
2249 || opP->disp.pic_reloc != pic_none
2250 #endif
2253 addword (0x0170);
2254 add_fix ('l', &opP->disp, 1, 2);
2256 else
2258 add_frag (adds (&opP->disp),
2259 SEXT (offs (&opP->disp)),
2260 TAB (PCREL1632, SZ_UNDEF));
2261 break;
2264 else
2266 addword (0x0170);
2267 add_fix ('l', &opP->disp, 0, 0);
2270 else
2271 addword (0x0170);
2272 addword (nextword >> 16);
2274 else
2276 if (opP->reg == PC)
2277 tmpreg = 0x3A; /* 7.2 */
2278 else
2279 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
2281 if (isvar (&opP->disp))
2283 if (opP->reg == PC)
2285 add_fix ('w', &opP->disp, 1, 0);
2287 else
2288 add_fix ('w', &opP->disp, 0, 0);
2291 addword (nextword);
2292 break;
2294 case POST:
2295 case PRE:
2296 case BASE:
2297 nextword = 0;
2298 baseo = get_num (&opP->disp, 90);
2299 if (opP->mode == POST || opP->mode == PRE)
2300 outro = get_num (&opP->odisp, 90);
2301 /* Figure out the `addressing mode'.
2302 Also turn on the BASE_DISABLE bit, if needed. */
2303 if (opP->reg == PC || opP->reg == ZPC)
2305 tmpreg = 0x3b; /* 7.3 */
2306 if (opP->reg == ZPC)
2307 nextword |= 0x80;
2309 else if (opP->reg == 0)
2311 nextword |= 0x80;
2312 tmpreg = 0x30; /* 6.garbage */
2314 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
2316 nextword |= 0x80;
2317 tmpreg = 0x30 + opP->reg - ZADDR0;
2319 else
2320 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
2322 siz1 = opP->disp.size;
2323 if (opP->mode == POST || opP->mode == PRE)
2324 siz2 = opP->odisp.size;
2325 else
2326 siz2 = SIZE_UNSPEC;
2328 /* Index register stuff. */
2329 if (opP->index.reg != 0
2330 && opP->index.reg >= DATA
2331 && opP->index.reg <= ADDR7)
2333 nextword |= (opP->index.reg - DATA) << 12;
2335 if (opP->index.size == SIZE_LONG
2336 || (opP->index.size == SIZE_UNSPEC
2337 && m68k_index_width_default == SIZE_LONG))
2338 nextword |= 0x800;
2340 if ((opP->index.scale != 1
2341 && cpu_of_arch (current_architecture) < m68020)
2342 || (opP->index.scale == 8
2343 && (arch_coldfire_p (current_architecture)
2344 && !arch_coldfire_fpu (current_architecture))))
2346 opP->error =
2347 _("scale factor invalid on this architecture; needs cpu32 or 68020 or higher");
2350 if (arch_coldfire_p (current_architecture)
2351 && opP->index.size == SIZE_WORD)
2352 opP->error = _("invalid index size for coldfire");
2354 switch (opP->index.scale)
2356 case 1:
2357 break;
2358 case 2:
2359 nextword |= 0x200;
2360 break;
2361 case 4:
2362 nextword |= 0x400;
2363 break;
2364 case 8:
2365 nextword |= 0x600;
2366 break;
2367 default:
2368 abort ();
2370 /* IF its simple,
2371 GET US OUT OF HERE! */
2373 /* Must be INDEX, with an index register. Address
2374 register cannot be ZERO-PC, and either :b was
2375 forced, or we know it will fit. For a 68000 or
2376 68010, force this mode anyways, because the
2377 larger modes aren't supported. */
2378 if (opP->mode == BASE
2379 && ((opP->reg >= ADDR0
2380 && opP->reg <= ADDR7)
2381 || opP->reg == PC))
2383 if (siz1 == SIZE_BYTE
2384 || cpu_of_arch (current_architecture) < m68020
2385 || arch_coldfire_p (current_architecture)
2386 || (siz1 == SIZE_UNSPEC
2387 && ! isvar (&opP->disp)
2388 && issbyte (baseo)))
2390 nextword += baseo & 0xff;
2391 addword (nextword);
2392 if (isvar (&opP->disp))
2394 /* Do a byte relocation. If it doesn't
2395 fit (possible on m68000) let the
2396 fixup processing complain later. */
2397 if (opP->reg == PC)
2398 add_fix ('B', &opP->disp, 1, 1);
2399 else
2400 add_fix ('B', &opP->disp, 0, 0);
2402 else if (siz1 != SIZE_BYTE)
2404 if (siz1 != SIZE_UNSPEC)
2405 as_warn (_("Forcing byte displacement"));
2406 if (! issbyte (baseo))
2407 opP->error = _("byte displacement out of range");
2410 break;
2412 else if (siz1 == SIZE_UNSPEC
2413 && opP->reg == PC
2414 && isvar (&opP->disp)
2415 && subs (&opP->disp) == NULL
2416 #ifdef OBJ_ELF
2417 /* If the displacement needs pic
2418 relocation it cannot be relaxed. */
2419 && opP->disp.pic_reloc == pic_none
2420 #endif
2423 /* The code in md_convert_frag_1 needs to be
2424 able to adjust nextword. Call frag_grow
2425 to ensure that we have enough space in
2426 the frag obstack to make all the bytes
2427 contiguous. */
2428 frag_grow (14);
2429 nextword += baseo & 0xff;
2430 addword (nextword);
2431 add_frag (adds (&opP->disp),
2432 SEXT (offs (&opP->disp)),
2433 TAB (PCINDEX, SZ_UNDEF));
2435 break;
2439 else
2441 nextword |= 0x40; /* No index reg. */
2442 if (opP->index.reg >= ZDATA0
2443 && opP->index.reg <= ZDATA7)
2444 nextword |= (opP->index.reg - ZDATA0) << 12;
2445 else if (opP->index.reg >= ZADDR0
2446 || opP->index.reg <= ZADDR7)
2447 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
2450 /* It isn't simple. */
2452 if (cpu_of_arch (current_architecture) < m68020
2453 || arch_coldfire_p (current_architecture))
2454 opP->error =
2455 _("invalid operand mode for this architecture; needs 68020 or higher");
2457 nextword |= 0x100;
2458 /* If the guy specified a width, we assume that it is
2459 wide enough. Maybe it isn't. If so, we lose. */
2460 switch (siz1)
2462 case SIZE_UNSPEC:
2463 if (isvar (&opP->disp)
2464 ? m68k_rel32
2465 : ! issword (baseo))
2467 siz1 = SIZE_LONG;
2468 nextword |= 0x30;
2470 else if (! isvar (&opP->disp) && baseo == 0)
2471 nextword |= 0x10;
2472 else
2474 nextword |= 0x20;
2475 siz1 = SIZE_WORD;
2477 break;
2478 case SIZE_BYTE:
2479 as_warn (_(":b not permitted; defaulting to :w"));
2480 /* Fall through. */
2481 case SIZE_WORD:
2482 nextword |= 0x20;
2483 break;
2484 case SIZE_LONG:
2485 nextword |= 0x30;
2486 break;
2489 /* Figure out inner displacement stuff. */
2490 if (opP->mode == POST || opP->mode == PRE)
2492 if (cpu_of_arch (current_architecture) & cpu32)
2493 opP->error = _("invalid operand mode for this architecture; needs 68020 or higher");
2494 switch (siz2)
2496 case SIZE_UNSPEC:
2497 if (isvar (&opP->odisp)
2498 ? m68k_rel32
2499 : ! issword (outro))
2501 siz2 = SIZE_LONG;
2502 nextword |= 0x3;
2504 else if (! isvar (&opP->odisp) && outro == 0)
2505 nextword |= 0x1;
2506 else
2508 nextword |= 0x2;
2509 siz2 = SIZE_WORD;
2511 break;
2512 case 1:
2513 as_warn (_(":b not permitted; defaulting to :w"));
2514 /* Fall through. */
2515 case 2:
2516 nextword |= 0x2;
2517 break;
2518 case 3:
2519 nextword |= 0x3;
2520 break;
2522 if (opP->mode == POST
2523 && (nextword & 0x40) == 0)
2524 nextword |= 0x04;
2526 addword (nextword);
2528 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
2530 if (opP->reg == PC || opP->reg == ZPC)
2531 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
2532 else
2533 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
2535 if (siz1 == SIZE_LONG)
2536 addword (baseo >> 16);
2537 if (siz1 != SIZE_UNSPEC)
2538 addword (baseo);
2540 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
2541 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
2542 if (siz2 == SIZE_LONG)
2543 addword (outro >> 16);
2544 if (siz2 != SIZE_UNSPEC)
2545 addword (outro);
2547 break;
2549 case ABSL:
2550 nextword = get_num (&opP->disp, 90);
2551 switch (opP->disp.size)
2553 default:
2554 abort ();
2555 case SIZE_UNSPEC:
2556 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
2558 tmpreg = 0x38; /* 7.0 */
2559 addword (nextword);
2560 break;
2562 if (isvar (&opP->disp)
2563 && !subs (&opP->disp)
2564 && adds (&opP->disp)
2565 #ifdef OBJ_ELF
2566 /* If the displacement needs pic relocation it
2567 cannot be relaxed. */
2568 && opP->disp.pic_reloc == pic_none
2569 #endif
2570 && !flag_long_jumps
2571 && !strchr ("~%&$?", s[0]))
2573 tmpreg = 0x3A; /* 7.2 */
2574 add_frag (adds (&opP->disp),
2575 SEXT (offs (&opP->disp)),
2576 TAB (ABSTOPCREL, SZ_UNDEF));
2577 break;
2579 /* Fall through into long. */
2580 case SIZE_LONG:
2581 if (isvar (&opP->disp))
2582 add_fix ('l', &opP->disp, 0, 0);
2584 tmpreg = 0x39;/* 7.1 mode */
2585 addword (nextword >> 16);
2586 addword (nextword);
2587 break;
2589 case SIZE_BYTE:
2590 as_bad (_("unsupported byte value; use a different suffix"));
2591 /* Fall through. */
2593 case SIZE_WORD:
2594 if (isvar (&opP->disp))
2595 add_fix ('w', &opP->disp, 0, 0);
2597 tmpreg = 0x38;/* 7.0 mode */
2598 addword (nextword);
2599 break;
2601 break;
2602 case CONTROL:
2603 case FPREG:
2604 default:
2605 as_bad (_("unknown/incorrect operand"));
2606 /* abort (); */
2609 /* If s[0] is '4', then this is for the mac instructions
2610 that can have a trailing_ampersand set. If so, set 0x100
2611 bit on tmpreg so install_gen_operand can check for it and
2612 set the appropriate bit (word2, bit 5). */
2613 if (s[0] == '4')
2615 if (opP->trailing_ampersand)
2616 tmpreg |= 0x100;
2618 install_gen_operand (s[1], tmpreg);
2619 break;
2621 case '#':
2622 case '^':
2623 switch (s[1])
2624 { /* JF: I hate floating point! */
2625 case 'j':
2626 tmpreg = 70;
2627 break;
2628 case '8':
2629 tmpreg = 20;
2630 break;
2631 case 'C':
2632 tmpreg = 50;
2633 break;
2634 case '3':
2635 default:
2636 tmpreg = 90;
2637 break;
2639 tmpreg = get_num (&opP->disp, tmpreg);
2640 if (isvar (&opP->disp))
2641 add_fix (s[1], &opP->disp, 0, 0);
2642 switch (s[1])
2644 case 'b': /* Danger: These do no check for
2645 certain types of overflow.
2646 user beware! */
2647 if (!isbyte (tmpreg))
2648 opP->error = _("out of range");
2649 insop (tmpreg, opcode);
2650 if (isvar (&opP->disp))
2651 the_ins.reloc[the_ins.nrel - 1].n =
2652 (opcode->m_codenum) * 2 + 1;
2653 break;
2654 case 'B':
2655 if (!issbyte (tmpreg))
2656 opP->error = _("out of range");
2657 the_ins.opcode[the_ins.numo - 1] |= tmpreg & 0xff;
2658 if (isvar (&opP->disp))
2659 the_ins.reloc[the_ins.nrel - 1].n = opcode->m_codenum * 2 - 1;
2660 break;
2661 case 'w':
2662 if (!isword (tmpreg))
2663 opP->error = _("out of range");
2664 insop (tmpreg, opcode);
2665 if (isvar (&opP->disp))
2666 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2667 break;
2668 case 'W':
2669 if (!issword (tmpreg))
2670 opP->error = _("out of range");
2671 insop (tmpreg, opcode);
2672 if (isvar (&opP->disp))
2673 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2674 break;
2675 case 'l':
2676 /* Because of the way insop works, we put these two out
2677 backwards. */
2678 insop (tmpreg, opcode);
2679 insop (tmpreg >> 16, opcode);
2680 if (isvar (&opP->disp))
2681 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
2682 break;
2683 case '3':
2684 tmpreg &= 0xFF;
2685 case '8':
2686 case 'C':
2687 case 'j':
2688 install_operand (s[1], tmpreg);
2689 break;
2690 default:
2691 abort ();
2693 break;
2695 case '+':
2696 case '-':
2697 case 'A':
2698 case 'a':
2699 install_operand (s[1], opP->reg - ADDR);
2700 break;
2702 case 'B':
2703 tmpreg = get_num (&opP->disp, 90);
2704 switch (s[1])
2706 case 'B':
2707 add_fix ('B', &opP->disp, 1, -1);
2708 break;
2709 case 'W':
2710 add_fix ('w', &opP->disp, 1, 0);
2711 addword (0);
2712 break;
2713 case 'L':
2714 long_branch:
2715 if (! HAVE_LONG_BRANCH (current_architecture))
2716 as_warn (_("Can't use long branches on 68000/68010/5200"));
2717 the_ins.opcode[0] |= 0xff;
2718 add_fix ('l', &opP->disp, 1, 0);
2719 addword (0);
2720 addword (0);
2721 break;
2722 case 'g':
2723 if (subs (&opP->disp)) /* We can't relax it. */
2724 goto long_branch;
2726 #ifdef OBJ_ELF
2727 /* If the displacement needs pic relocation it cannot be
2728 relaxed. */
2729 if (opP->disp.pic_reloc != pic_none)
2730 goto long_branch;
2731 #endif
2732 /* This could either be a symbol, or an absolute
2733 address. If it's an absolute address, turn it into
2734 an absolute jump right here and keep it out of the
2735 relaxer. */
2736 if (adds (&opP->disp) == 0)
2738 if (the_ins.opcode[0] == 0x6000) /* jbra */
2739 the_ins.opcode[0] = 0x4EF9;
2740 else if (the_ins.opcode[0] == 0x6100) /* jbsr */
2741 the_ins.opcode[0] = 0x4EB9;
2742 else /* jCC */
2744 the_ins.opcode[0] ^= 0x0100;
2745 the_ins.opcode[0] |= 0x0006;
2746 addword (0x4EF9);
2748 add_fix ('l', &opP->disp, 0, 0);
2749 addword (0);
2750 addword (0);
2751 break;
2754 /* Now we know it's going into the relaxer. Now figure
2755 out which mode. We try in this order of preference:
2756 long branch, absolute jump, byte/word branches only. */
2757 if (HAVE_LONG_BRANCH (current_architecture))
2758 add_frag (adds (&opP->disp),
2759 SEXT (offs (&opP->disp)),
2760 TAB (BRANCHBWL, SZ_UNDEF));
2761 else if (! flag_keep_pcrel)
2763 if ((the_ins.opcode[0] == 0x6000)
2764 || (the_ins.opcode[0] == 0x6100))
2765 add_frag (adds (&opP->disp),
2766 SEXT (offs (&opP->disp)),
2767 TAB (BRABSJUNC, SZ_UNDEF));
2768 else
2769 add_frag (adds (&opP->disp),
2770 SEXT (offs (&opP->disp)),
2771 TAB (BRABSJCOND, SZ_UNDEF));
2773 else
2774 add_frag (adds (&opP->disp),
2775 SEXT (offs (&opP->disp)),
2776 TAB (BRANCHBW, SZ_UNDEF));
2777 break;
2778 case 'w':
2779 if (isvar (&opP->disp))
2781 /* Check for DBcc instructions. We can relax them,
2782 but only if we have long branches and/or absolute
2783 jumps. */
2784 if (((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
2785 && (HAVE_LONG_BRANCH (current_architecture)
2786 || (! flag_keep_pcrel)))
2788 if (HAVE_LONG_BRANCH (current_architecture))
2789 add_frag (adds (&opP->disp),
2790 SEXT (offs (&opP->disp)),
2791 TAB (DBCCLBR, SZ_UNDEF));
2792 else
2793 add_frag (adds (&opP->disp),
2794 SEXT (offs (&opP->disp)),
2795 TAB (DBCCABSJ, SZ_UNDEF));
2796 break;
2798 add_fix ('w', &opP->disp, 1, 0);
2800 addword (0);
2801 break;
2802 case 'C': /* Fixed size LONG coproc branches. */
2803 add_fix ('l', &opP->disp, 1, 0);
2804 addword (0);
2805 addword (0);
2806 break;
2807 case 'c': /* Var size Coprocesssor branches. */
2808 if (subs (&opP->disp) || (adds (&opP->disp) == 0))
2810 the_ins.opcode[the_ins.numo - 1] |= 0x40;
2811 add_fix ('l', &opP->disp, 1, 0);
2812 addword (0);
2813 addword (0);
2815 else
2816 add_frag (adds (&opP->disp),
2817 SEXT (offs (&opP->disp)),
2818 TAB (FBRANCH, SZ_UNDEF));
2819 break;
2820 default:
2821 abort ();
2823 break;
2825 case 'C': /* Ignore it. */
2826 break;
2828 case 'd': /* JF this is a kludge. */
2829 install_operand ('s', opP->reg - ADDR);
2830 tmpreg = get_num (&opP->disp, 90);
2831 if (!issword (tmpreg))
2833 as_warn (_("Expression out of range, using 0"));
2834 tmpreg = 0;
2836 addword (tmpreg);
2837 break;
2839 case 'D':
2840 install_operand (s[1], opP->reg - DATA);
2841 break;
2843 case 'e': /* EMAC ACCx, reg/reg. */
2844 install_operand (s[1], opP->reg - ACC);
2845 break;
2847 case 'E': /* Ignore it. */
2848 break;
2850 case 'F':
2851 install_operand (s[1], opP->reg - FP0);
2852 break;
2854 case 'g': /* EMAC ACCEXTx. */
2855 install_operand (s[1], opP->reg - ACCEXT01);
2856 break;
2858 case 'G': /* Ignore it. */
2859 case 'H':
2860 break;
2862 case 'I':
2863 tmpreg = opP->reg - COP0;
2864 install_operand (s[1], tmpreg);
2865 break;
2867 case 'i': /* MAC/EMAC scale factor. */
2868 install_operand (s[1], opP->mode == LSH ? 0x1 : 0x3);
2869 break;
2871 case 'J': /* JF foo. */
2872 switch (opP->reg)
2874 case SFC:
2875 tmpreg = 0x000;
2876 break;
2877 case DFC:
2878 tmpreg = 0x001;
2879 break;
2880 case CACR:
2881 tmpreg = 0x002;
2882 break;
2883 case TC:
2884 tmpreg = 0x003;
2885 break;
2886 case ACR0:
2887 case ITT0:
2888 tmpreg = 0x004;
2889 break;
2890 case ACR1:
2891 case ITT1:
2892 tmpreg = 0x005;
2893 break;
2894 case ACR2:
2895 case DTT0:
2896 tmpreg = 0x006;
2897 break;
2898 case ACR3:
2899 case DTT1:
2900 tmpreg = 0x007;
2901 break;
2902 case BUSCR:
2903 tmpreg = 0x008;
2904 break;
2906 case USP:
2907 tmpreg = 0x800;
2908 break;
2909 case VBR:
2910 tmpreg = 0x801;
2911 break;
2912 case CAAR:
2913 tmpreg = 0x802;
2914 break;
2915 case MSP:
2916 tmpreg = 0x803;
2917 break;
2918 case ISP:
2919 tmpreg = 0x804;
2920 break;
2921 case MMUSR:
2922 tmpreg = 0x805;
2923 break;
2924 case URP:
2925 tmpreg = 0x806;
2926 break;
2927 case SRP:
2928 tmpreg = 0x807;
2929 break;
2930 case PCR:
2931 tmpreg = 0x808;
2932 break;
2933 case ROMBAR:
2934 tmpreg = 0xC00;
2935 break;
2936 case ROMBAR1:
2937 tmpreg = 0xC01;
2938 break;
2939 case FLASHBAR:
2940 case RAMBAR0:
2941 tmpreg = 0xC04;
2942 break;
2943 case RAMBAR:
2944 case RAMBAR1:
2945 tmpreg = 0xC05;
2946 break;
2947 case MPCR:
2948 tmpreg = 0xC0C;
2949 break;
2950 case EDRAMBAR:
2951 tmpreg = 0xC0D;
2952 break;
2953 case MBAR0:
2954 case MBAR2:
2955 case SECMBAR:
2956 tmpreg = 0xC0E;
2957 break;
2958 case MBAR1:
2959 case MBAR:
2960 tmpreg = 0xC0F;
2961 break;
2962 case PCR1U0:
2963 tmpreg = 0xD02;
2964 break;
2965 case PCR1L0:
2966 tmpreg = 0xD03;
2967 break;
2968 case PCR2U0:
2969 tmpreg = 0xD04;
2970 break;
2971 case PCR2L0:
2972 tmpreg = 0xD05;
2973 break;
2974 case PCR3U0:
2975 tmpreg = 0xD06;
2976 break;
2977 case PCR3L0:
2978 tmpreg = 0xD07;
2979 break;
2980 case PCR1L1:
2981 tmpreg = 0xD0A;
2982 break;
2983 case PCR1U1:
2984 tmpreg = 0xD0B;
2985 break;
2986 case PCR2L1:
2987 tmpreg = 0xD0C;
2988 break;
2989 case PCR2U1:
2990 tmpreg = 0xD0D;
2991 break;
2992 case PCR3L1:
2993 tmpreg = 0xD0E;
2994 break;
2995 case PCR3U1:
2996 tmpreg = 0xD0F;
2997 break;
2998 default:
2999 abort ();
3001 install_operand (s[1], tmpreg);
3002 break;
3004 case 'k':
3005 tmpreg = get_num (&opP->disp, 55);
3006 install_operand (s[1], tmpreg & 0x7f);
3007 break;
3009 case 'l':
3010 tmpreg = opP->mask;
3011 if (s[1] == 'w')
3013 if (tmpreg & 0x7FF0000)
3014 as_bad (_("Floating point register in register list"));
3015 insop (reverse_16_bits (tmpreg), opcode);
3017 else
3019 if (tmpreg & 0x700FFFF)
3020 as_bad (_("Wrong register in floating-point reglist"));
3021 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
3023 break;
3025 case 'L':
3026 tmpreg = opP->mask;
3027 if (s[1] == 'w')
3029 if (tmpreg & 0x7FF0000)
3030 as_bad (_("Floating point register in register list"));
3031 insop (tmpreg, opcode);
3033 else if (s[1] == '8')
3035 if (tmpreg & 0x0FFFFFF)
3036 as_bad (_("incorrect register in reglist"));
3037 install_operand (s[1], tmpreg >> 24);
3039 else
3041 if (tmpreg & 0x700FFFF)
3042 as_bad (_("wrong register in floating-point reglist"));
3043 else
3044 install_operand (s[1], tmpreg >> 16);
3046 break;
3048 case 'M':
3049 install_operand (s[1], get_num (&opP->disp, 60));
3050 break;
3052 case 'O':
3053 tmpreg = ((opP->mode == DREG)
3054 ? 0x20 + (int) (opP->reg - DATA)
3055 : (get_num (&opP->disp, 40) & 0x1F));
3056 install_operand (s[1], tmpreg);
3057 break;
3059 case 'Q':
3060 tmpreg = get_num (&opP->disp, 10);
3061 if (tmpreg == 8)
3062 tmpreg = 0;
3063 install_operand (s[1], tmpreg);
3064 break;
3066 case 'R':
3067 /* This depends on the fact that ADDR registers are eight
3068 more than their corresponding DATA regs, so the result
3069 will have the ADDR_REG bit set. */
3070 install_operand (s[1], opP->reg - DATA);
3071 break;
3073 case 'r':
3074 if (opP->mode == AINDR)
3075 install_operand (s[1], opP->reg - DATA);
3076 else
3077 install_operand (s[1], opP->index.reg - DATA);
3078 break;
3080 case 's':
3081 if (opP->reg == FPI)
3082 tmpreg = 0x1;
3083 else if (opP->reg == FPS)
3084 tmpreg = 0x2;
3085 else if (opP->reg == FPC)
3086 tmpreg = 0x4;
3087 else
3088 abort ();
3089 install_operand (s[1], tmpreg);
3090 break;
3092 case 'S': /* Ignore it. */
3093 break;
3095 case 'T':
3096 install_operand (s[1], get_num (&opP->disp, 30));
3097 break;
3099 case 'U': /* Ignore it. */
3100 break;
3102 case 'c':
3103 switch (opP->reg)
3105 case NC:
3106 tmpreg = 0;
3107 break;
3108 case DC:
3109 tmpreg = 1;
3110 break;
3111 case IC:
3112 tmpreg = 2;
3113 break;
3114 case BC:
3115 tmpreg = 3;
3116 break;
3117 default:
3118 as_fatal (_("failed sanity check"));
3119 } /* switch on cache token. */
3120 install_operand (s[1], tmpreg);
3121 break;
3122 #ifndef NO_68851
3123 /* JF: These are out of order, I fear. */
3124 case 'f':
3125 switch (opP->reg)
3127 case SFC:
3128 tmpreg = 0;
3129 break;
3130 case DFC:
3131 tmpreg = 1;
3132 break;
3133 default:
3134 abort ();
3136 install_operand (s[1], tmpreg);
3137 break;
3139 case '0':
3140 case '1':
3141 case '2':
3142 switch (opP->reg)
3144 case TC:
3145 tmpreg = 0;
3146 break;
3147 case CAL:
3148 tmpreg = 4;
3149 break;
3150 case VAL:
3151 tmpreg = 5;
3152 break;
3153 case SCC:
3154 tmpreg = 6;
3155 break;
3156 case AC:
3157 tmpreg = 7;
3158 break;
3159 default:
3160 abort ();
3162 install_operand (s[1], tmpreg);
3163 break;
3165 case 'V':
3166 if (opP->reg == VAL)
3167 break;
3168 abort ();
3170 case 'W':
3171 switch (opP->reg)
3173 case DRP:
3174 tmpreg = 1;
3175 break;
3176 case SRP:
3177 tmpreg = 2;
3178 break;
3179 case CRP:
3180 tmpreg = 3;
3181 break;
3182 default:
3183 abort ();
3185 install_operand (s[1], tmpreg);
3186 break;
3188 case 'X':
3189 switch (opP->reg)
3191 case BAD:
3192 case BAD + 1:
3193 case BAD + 2:
3194 case BAD + 3:
3195 case BAD + 4:
3196 case BAD + 5:
3197 case BAD + 6:
3198 case BAD + 7:
3199 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
3200 break;
3202 case BAC:
3203 case BAC + 1:
3204 case BAC + 2:
3205 case BAC + 3:
3206 case BAC + 4:
3207 case BAC + 5:
3208 case BAC + 6:
3209 case BAC + 7:
3210 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
3211 break;
3213 default:
3214 abort ();
3216 install_operand (s[1], tmpreg);
3217 break;
3218 case 'Y':
3219 know (opP->reg == PSR);
3220 break;
3221 case 'Z':
3222 know (opP->reg == PCSR);
3223 break;
3224 #endif /* m68851 */
3225 case '3':
3226 switch (opP->reg)
3228 case TT0:
3229 tmpreg = 2;
3230 break;
3231 case TT1:
3232 tmpreg = 3;
3233 break;
3234 default:
3235 abort ();
3237 install_operand (s[1], tmpreg);
3238 break;
3239 case 't':
3240 tmpreg = get_num (&opP->disp, 20);
3241 install_operand (s[1], tmpreg);
3242 break;
3243 case '_': /* used only for move16 absolute 32-bit address. */
3244 if (isvar (&opP->disp))
3245 add_fix ('l', &opP->disp, 0, 0);
3246 tmpreg = get_num (&opP->disp, 90);
3247 addword (tmpreg >> 16);
3248 addword (tmpreg & 0xFFFF);
3249 break;
3250 case 'u':
3251 install_operand (s[1], opP->reg - DATA0L);
3252 opP->reg -= (DATA0L);
3253 opP->reg &= 0x0F; /* remove upper/lower bit. */
3254 break;
3255 case 'x':
3256 tmpreg = get_num (&opP->disp, 80);
3257 if (tmpreg == -1)
3258 tmpreg = 0;
3259 install_operand (s[1], tmpreg);
3260 break;
3261 default:
3262 abort ();
3266 /* By the time whe get here (FINALLY) the_ins contains the complete
3267 instruction, ready to be emitted. . . */
3270 static int
3271 reverse_16_bits (int in)
3273 int out = 0;
3274 int n;
3276 static int mask[16] =
3278 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3279 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
3281 for (n = 0; n < 16; n++)
3283 if (in & mask[n])
3284 out |= mask[15 - n];
3286 return out;
3287 } /* reverse_16_bits() */
3289 static int
3290 reverse_8_bits (int in)
3292 int out = 0;
3293 int n;
3295 static int mask[8] =
3297 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
3300 for (n = 0; n < 8; n++)
3302 if (in & mask[n])
3303 out |= mask[7 - n];
3305 return out;
3306 } /* reverse_8_bits() */
3308 /* Cause an extra frag to be generated here, inserting up to 10 bytes
3309 (that value is chosen in the frag_var call in md_assemble). TYPE
3310 is the subtype of the frag to be generated; its primary type is
3311 rs_machine_dependent.
3313 The TYPE parameter is also used by md_convert_frag_1 and
3314 md_estimate_size_before_relax. The appropriate type of fixup will
3315 be emitted by md_convert_frag_1.
3317 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
3318 static void
3319 install_operand (int mode, int val)
3321 switch (mode)
3323 case 's':
3324 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge. */
3325 break;
3326 case 'd':
3327 the_ins.opcode[0] |= val << 9;
3328 break;
3329 case '1':
3330 the_ins.opcode[1] |= val << 12;
3331 break;
3332 case '2':
3333 the_ins.opcode[1] |= val << 6;
3334 break;
3335 case '3':
3336 the_ins.opcode[1] |= val;
3337 break;
3338 case '4':
3339 the_ins.opcode[2] |= val << 12;
3340 break;
3341 case '5':
3342 the_ins.opcode[2] |= val << 6;
3343 break;
3344 case '6':
3345 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
3346 three words long! */
3347 the_ins.numo++;
3348 the_ins.opcode[2] |= val;
3349 break;
3350 case '7':
3351 the_ins.opcode[1] |= val << 7;
3352 break;
3353 case '8':
3354 the_ins.opcode[1] |= val << 10;
3355 break;
3356 #ifndef NO_68851
3357 case '9':
3358 the_ins.opcode[1] |= val << 5;
3359 break;
3360 #endif
3362 case 't':
3363 the_ins.opcode[1] |= (val << 10) | (val << 7);
3364 break;
3365 case 'D':
3366 the_ins.opcode[1] |= (val << 12) | val;
3367 break;
3368 case 'g':
3369 the_ins.opcode[0] |= val = 0xff;
3370 break;
3371 case 'i':
3372 the_ins.opcode[0] |= val << 9;
3373 break;
3374 case 'C':
3375 the_ins.opcode[1] |= val;
3376 break;
3377 case 'j':
3378 the_ins.opcode[1] |= val;
3379 the_ins.numo++; /* What a hack. */
3380 break;
3381 case 'k':
3382 the_ins.opcode[1] |= val << 4;
3383 break;
3384 case 'b':
3385 case 'w':
3386 case 'W':
3387 case 'l':
3388 break;
3389 case 'e':
3390 the_ins.opcode[0] |= (val << 6);
3391 break;
3392 case 'L':
3393 the_ins.opcode[1] = (val >> 16);
3394 the_ins.opcode[2] = val & 0xffff;
3395 break;
3396 case 'm':
3397 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3398 the_ins.opcode[0] |= ((val & 0x7) << 9);
3399 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3400 break;
3401 case 'n': /* MAC/EMAC Rx on !load. */
3402 the_ins.opcode[0] |= ((val & 0x8) << (6 - 3));
3403 the_ins.opcode[0] |= ((val & 0x7) << 9);
3404 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3405 break;
3406 case 'o': /* MAC/EMAC Rx on load. */
3407 the_ins.opcode[1] |= val << 12;
3408 the_ins.opcode[1] |= ((val & 0x10) << (7 - 4));
3409 break;
3410 case 'M': /* MAC/EMAC Ry on !load. */
3411 the_ins.opcode[0] |= (val & 0xF);
3412 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3413 break;
3414 case 'N': /* MAC/EMAC Ry on load. */
3415 the_ins.opcode[1] |= (val & 0xF);
3416 the_ins.opcode[1] |= ((val & 0x10) << (6 - 4));
3417 break;
3418 case 'h':
3419 the_ins.opcode[1] |= ((val != 1) << 10);
3420 break;
3421 case 'F':
3422 the_ins.opcode[0] |= ((val & 0x3) << 9);
3423 break;
3424 case 'f':
3425 the_ins.opcode[0] |= ((val & 0x3) << 0);
3426 break;
3427 case 'G': /* EMAC accumulator in a EMAC load instruction. */
3428 the_ins.opcode[0] |= ((~val & 0x1) << 7);
3429 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3430 break;
3431 case 'H': /* EMAC accumulator in a EMAC non-load instruction. */
3432 the_ins.opcode[0] |= ((val & 0x1) << 7);
3433 the_ins.opcode[1] |= ((val & 0x2) << (4 - 1));
3434 break;
3435 case 'I':
3436 the_ins.opcode[1] |= ((val & 0x3) << 9);
3437 break;
3438 case ']':
3439 the_ins.opcode[0] |= (val & 0x1) <<10;
3440 break;
3441 case 'c':
3442 default:
3443 as_fatal (_("failed sanity check."));
3447 static void
3448 install_gen_operand (int mode, int val)
3450 switch (mode)
3452 case '/': /* Special for mask loads for mac/msac insns with
3453 possible mask; trailing_ampersend set in bit 8. */
3454 the_ins.opcode[0] |= (val & 0x3f);
3455 the_ins.opcode[1] |= (((val & 0x100) >> 8) << 5);
3456 break;
3457 case 's':
3458 the_ins.opcode[0] |= val;
3459 break;
3460 case 'd':
3461 /* This is a kludge!!! */
3462 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
3463 break;
3464 case 'b':
3465 case 'w':
3466 case 'l':
3467 case 'f':
3468 case 'F':
3469 case 'x':
3470 case 'p':
3471 the_ins.opcode[0] |= val;
3472 break;
3473 /* more stuff goes here. */
3474 default:
3475 as_fatal (_("failed sanity check."));
3479 /* Verify that we have some number of paren pairs, do m68k_ip_op(), and
3480 then deal with the bitfield hack. */
3482 static char *
3483 crack_operand (char *str, struct m68k_op *opP)
3485 register int parens;
3486 register int c;
3487 register char *beg_str;
3488 int inquote = 0;
3490 if (!str)
3492 return str;
3494 beg_str = str;
3495 for (parens = 0; *str && (parens > 0 || inquote || notend (str)); str++)
3497 if (! inquote)
3499 if (*str == '(')
3500 parens++;
3501 else if (*str == ')')
3503 if (!parens)
3504 { /* ERROR. */
3505 opP->error = _("Extra )");
3506 return str;
3508 --parens;
3511 if (flag_mri && *str == '\'')
3512 inquote = ! inquote;
3514 if (!*str && parens)
3515 { /* ERROR. */
3516 opP->error = _("Missing )");
3517 return str;
3519 c = *str;
3520 *str = '\0';
3521 if (m68k_ip_op (beg_str, opP) != 0)
3523 *str = c;
3524 return str;
3526 *str = c;
3527 if (c == '}')
3528 c = *++str; /* JF bitfield hack. */
3529 if (c)
3531 c = *++str;
3532 if (!c)
3533 as_bad (_("Missing operand"));
3536 /* Detect MRI REG symbols and convert them to REGLSTs. */
3537 if (opP->mode == CONTROL && (int)opP->reg < 0)
3539 opP->mode = REGLST;
3540 opP->mask = ~(int)opP->reg;
3541 opP->reg = 0;
3544 return str;
3547 /* This is the guts of the machine-dependent assembler. STR points to a
3548 machine dependent instruction. This function is supposed to emit
3549 the frags/bytes it assembles to.
3552 static void
3553 insert_reg (const char *regname, int regnum)
3555 char buf[100];
3556 int i;
3558 #ifdef REGISTER_PREFIX
3559 if (!flag_reg_prefix_optional)
3561 buf[0] = REGISTER_PREFIX;
3562 strcpy (buf + 1, regname);
3563 regname = buf;
3565 #endif
3567 symbol_table_insert (symbol_new (regname, reg_section, regnum,
3568 &zero_address_frag));
3570 for (i = 0; regname[i]; i++)
3571 buf[i] = TOUPPER (regname[i]);
3572 buf[i] = '\0';
3574 symbol_table_insert (symbol_new (buf, reg_section, regnum,
3575 &zero_address_frag));
3578 struct init_entry
3580 const char *name;
3581 int number;
3584 static const struct init_entry init_table[] =
3586 { "d0", DATA0 },
3587 { "d1", DATA1 },
3588 { "d2", DATA2 },
3589 { "d3", DATA3 },
3590 { "d4", DATA4 },
3591 { "d5", DATA5 },
3592 { "d6", DATA6 },
3593 { "d7", DATA7 },
3594 { "a0", ADDR0 },
3595 { "a1", ADDR1 },
3596 { "a2", ADDR2 },
3597 { "a3", ADDR3 },
3598 { "a4", ADDR4 },
3599 { "a5", ADDR5 },
3600 { "a6", ADDR6 },
3601 { "fp", ADDR6 },
3602 { "a7", ADDR7 },
3603 { "sp", ADDR7 },
3604 { "ssp", ADDR7 },
3605 { "fp0", FP0 },
3606 { "fp1", FP1 },
3607 { "fp2", FP2 },
3608 { "fp3", FP3 },
3609 { "fp4", FP4 },
3610 { "fp5", FP5 },
3611 { "fp6", FP6 },
3612 { "fp7", FP7 },
3613 { "fpi", FPI },
3614 { "fpiar", FPI },
3615 { "fpc", FPI },
3616 { "fps", FPS },
3617 { "fpsr", FPS },
3618 { "fpc", FPC },
3619 { "fpcr", FPC },
3620 { "control", FPC },
3621 { "status", FPS },
3622 { "iaddr", FPI },
3624 { "cop0", COP0 },
3625 { "cop1", COP1 },
3626 { "cop2", COP2 },
3627 { "cop3", COP3 },
3628 { "cop4", COP4 },
3629 { "cop5", COP5 },
3630 { "cop6", COP6 },
3631 { "cop7", COP7 },
3632 { "pc", PC },
3633 { "zpc", ZPC },
3634 { "sr", SR },
3636 { "ccr", CCR },
3637 { "cc", CCR },
3639 { "acc", ACC },
3640 { "acc0", ACC },
3641 { "acc1", ACC1 },
3642 { "acc2", ACC2 },
3643 { "acc3", ACC3 },
3644 { "accext01", ACCEXT01 },
3645 { "accext23", ACCEXT23 },
3646 { "macsr", MACSR },
3647 { "mask", MASK },
3649 /* Control registers. */
3650 { "sfc", SFC }, /* Source Function Code. */
3651 { "sfcr", SFC },
3652 { "dfc", DFC }, /* Destination Function Code. */
3653 { "dfcr", DFC },
3654 { "cacr", CACR }, /* Cache Control Register. */
3655 { "caar", CAAR }, /* Cache Address Register. */
3657 { "usp", USP }, /* User Stack Pointer. */
3658 { "vbr", VBR }, /* Vector Base Register. */
3659 { "msp", MSP }, /* Master Stack Pointer. */
3660 { "isp", ISP }, /* Interrupt Stack Pointer. */
3662 { "itt0", ITT0 }, /* Instruction Transparent Translation Reg 0. */
3663 { "itt1", ITT1 }, /* Instruction Transparent Translation Reg 1. */
3664 { "dtt0", DTT0 }, /* Data Transparent Translation Register 0. */
3665 { "dtt1", DTT1 }, /* Data Transparent Translation Register 1. */
3667 /* 68ec040 versions of same */
3668 { "iacr0", ITT0 }, /* Instruction Access Control Register 0. */
3669 { "iacr1", ITT1 }, /* Instruction Access Control Register 0. */
3670 { "dacr0", DTT0 }, /* Data Access Control Register 0. */
3671 { "dacr1", DTT1 }, /* Data Access Control Register 0. */
3673 /* mcf5200 versions of same. The ColdFire programmer's reference
3674 manual indicated that the order is 2,3,0,1, but Ken Rose
3675 <rose@netcom.com> says that 0,1,2,3 is the correct order. */
3676 { "acr0", ACR0 }, /* Access Control Unit 0. */
3677 { "acr1", ACR1 }, /* Access Control Unit 1. */
3678 { "acr2", ACR2 }, /* Access Control Unit 2. */
3679 { "acr3", ACR3 }, /* Access Control Unit 3. */
3681 { "tc", TC }, /* MMU Translation Control Register. */
3682 { "tcr", TC },
3684 { "mmusr", MMUSR }, /* MMU Status Register. */
3685 { "srp", SRP }, /* User Root Pointer. */
3686 { "urp", URP }, /* Supervisor Root Pointer. */
3688 { "buscr", BUSCR },
3689 { "pcr", PCR },
3691 { "rombar", ROMBAR }, /* ROM Base Address Register. */
3692 { "rambar0", RAMBAR0 }, /* ROM Base Address Register. */
3693 { "rambar1", RAMBAR1 }, /* ROM Base Address Register. */
3694 { "mbar", MBAR }, /* Module Base Address Register. */
3696 { "mbar0", MBAR0 }, /* mcfv4e registers. */
3697 { "mbar1", MBAR1 }, /* mcfv4e registers. */
3698 { "rombar0", ROMBAR }, /* mcfv4e registers. */
3699 { "rombar1", ROMBAR1 }, /* mcfv4e registers. */
3700 { "mpcr", MPCR }, /* mcfv4e registers. */
3701 { "edrambar", EDRAMBAR }, /* mcfv4e registers. */
3702 { "secmbar", SECMBAR }, /* mcfv4e registers. */
3703 { "asid", TC }, /* mcfv4e registers. */
3704 { "mmubar", BUSCR }, /* mcfv4e registers. */
3705 { "pcr1u0", PCR1U0 }, /* mcfv4e registers. */
3706 { "pcr1l0", PCR1L0 }, /* mcfv4e registers. */
3707 { "pcr2u0", PCR2U0 }, /* mcfv4e registers. */
3708 { "pcr2l0", PCR2L0 }, /* mcfv4e registers. */
3709 { "pcr3u0", PCR3U0 }, /* mcfv4e registers. */
3710 { "pcr3l0", PCR3L0 }, /* mcfv4e registers. */
3711 { "pcr1u1", PCR1U1 }, /* mcfv4e registers. */
3712 { "pcr1l1", PCR1L1 }, /* mcfv4e registers. */
3713 { "pcr2u1", PCR2U1 }, /* mcfv4e registers. */
3714 { "pcr2l1", PCR2L1 }, /* mcfv4e registers. */
3715 { "pcr3u1", PCR3U1 }, /* mcfv4e registers. */
3716 { "pcr3l1", PCR3L1 }, /* mcfv4e registers. */
3718 { "flashbar", FLASHBAR }, /* mcf528x registers. */
3719 { "rambar", RAMBAR }, /* mcf528x registers. */
3721 { "mbar2", MBAR2 }, /* mcf5249 registers. */
3722 /* End of control registers. */
3724 { "ac", AC },
3725 { "bc", BC },
3726 { "cal", CAL },
3727 { "crp", CRP },
3728 { "drp", DRP },
3729 { "pcsr", PCSR },
3730 { "psr", PSR },
3731 { "scc", SCC },
3732 { "val", VAL },
3733 { "bad0", BAD0 },
3734 { "bad1", BAD1 },
3735 { "bad2", BAD2 },
3736 { "bad3", BAD3 },
3737 { "bad4", BAD4 },
3738 { "bad5", BAD5 },
3739 { "bad6", BAD6 },
3740 { "bad7", BAD7 },
3741 { "bac0", BAC0 },
3742 { "bac1", BAC1 },
3743 { "bac2", BAC2 },
3744 { "bac3", BAC3 },
3745 { "bac4", BAC4 },
3746 { "bac5", BAC5 },
3747 { "bac6", BAC6 },
3748 { "bac7", BAC7 },
3750 { "ic", IC },
3751 { "dc", DC },
3752 { "nc", NC },
3754 { "tt0", TT0 },
3755 { "tt1", TT1 },
3756 /* 68ec030 versions of same. */
3757 { "ac0", TT0 },
3758 { "ac1", TT1 },
3759 /* 68ec030 access control unit, identical to 030 MMU status reg. */
3760 { "acusr", PSR },
3762 /* Suppressed data and address registers. */
3763 { "zd0", ZDATA0 },
3764 { "zd1", ZDATA1 },
3765 { "zd2", ZDATA2 },
3766 { "zd3", ZDATA3 },
3767 { "zd4", ZDATA4 },
3768 { "zd5", ZDATA5 },
3769 { "zd6", ZDATA6 },
3770 { "zd7", ZDATA7 },
3771 { "za0", ZADDR0 },
3772 { "za1", ZADDR1 },
3773 { "za2", ZADDR2 },
3774 { "za3", ZADDR3 },
3775 { "za4", ZADDR4 },
3776 { "za5", ZADDR5 },
3777 { "za6", ZADDR6 },
3778 { "za7", ZADDR7 },
3780 /* Upper and lower data and address registers, used by macw and msacw. */
3781 { "d0l", DATA0L },
3782 { "d1l", DATA1L },
3783 { "d2l", DATA2L },
3784 { "d3l", DATA3L },
3785 { "d4l", DATA4L },
3786 { "d5l", DATA5L },
3787 { "d6l", DATA6L },
3788 { "d7l", DATA7L },
3790 { "a0l", ADDR0L },
3791 { "a1l", ADDR1L },
3792 { "a2l", ADDR2L },
3793 { "a3l", ADDR3L },
3794 { "a4l", ADDR4L },
3795 { "a5l", ADDR5L },
3796 { "a6l", ADDR6L },
3797 { "a7l", ADDR7L },
3799 { "d0u", DATA0U },
3800 { "d1u", DATA1U },
3801 { "d2u", DATA2U },
3802 { "d3u", DATA3U },
3803 { "d4u", DATA4U },
3804 { "d5u", DATA5U },
3805 { "d6u", DATA6U },
3806 { "d7u", DATA7U },
3808 { "a0u", ADDR0U },
3809 { "a1u", ADDR1U },
3810 { "a2u", ADDR2U },
3811 { "a3u", ADDR3U },
3812 { "a4u", ADDR4U },
3813 { "a5u", ADDR5U },
3814 { "a6u", ADDR6U },
3815 { "a7u", ADDR7U },
3817 { 0, 0 }
3820 static void
3821 init_regtable (void)
3823 int i;
3824 for (i = 0; init_table[i].name; i++)
3825 insert_reg (init_table[i].name, init_table[i].number);
3828 static int no_68851, no_68881;
3830 void
3831 md_assemble (char *str)
3833 const char *er;
3834 short *fromP;
3835 char *toP = NULL;
3836 int m, n = 0;
3837 char *to_beg_P;
3838 int shorts_this_frag;
3839 fixS *fixP;
3841 /* In MRI mode, the instruction and operands are separated by a
3842 space. Anything following the operands is a comment. The label
3843 has already been removed. */
3844 if (flag_mri)
3846 char *s;
3847 int fields = 0;
3848 int infield = 0;
3849 int inquote = 0;
3851 for (s = str; *s != '\0'; s++)
3853 if ((*s == ' ' || *s == '\t') && ! inquote)
3855 if (infield)
3857 ++fields;
3858 if (fields >= 2)
3860 *s = '\0';
3861 break;
3863 infield = 0;
3866 else
3868 if (! infield)
3869 infield = 1;
3870 if (*s == '\'')
3871 inquote = ! inquote;
3876 memset (&the_ins, '\0', sizeof (the_ins));
3877 m68k_ip (str);
3878 er = the_ins.error;
3879 if (!er)
3881 for (n = 0; n < the_ins.numargs; n++)
3882 if (the_ins.operands[n].error)
3884 er = the_ins.operands[n].error;
3885 break;
3888 if (er)
3890 as_bad (_("%s -- statement `%s' ignored"), er, str);
3891 return;
3894 /* If there is a current label, record that it marks an instruction. */
3895 if (current_label != NULL)
3897 current_label->text = 1;
3898 current_label = NULL;
3901 #ifdef OBJ_ELF
3902 /* Tie dwarf2 debug info to the address at the start of the insn. */
3903 dwarf2_emit_insn (0);
3904 #endif
3906 if (the_ins.nfrag == 0)
3908 /* No frag hacking involved; just put it out. */
3909 toP = frag_more (2 * the_ins.numo);
3910 fromP = &the_ins.opcode[0];
3911 for (m = the_ins.numo; m; --m)
3913 md_number_to_chars (toP, (long) (*fromP), 2);
3914 toP += 2;
3915 fromP++;
3917 /* Put out symbol-dependent info. */
3918 for (m = 0; m < the_ins.nrel; m++)
3920 switch (the_ins.reloc[m].wid)
3922 case 'B':
3923 n = 1;
3924 break;
3925 case 'b':
3926 n = 1;
3927 break;
3928 case '3':
3929 n = 1;
3930 break;
3931 case 'w':
3932 case 'W':
3933 n = 2;
3934 break;
3935 case 'l':
3936 n = 4;
3937 break;
3938 default:
3939 as_fatal (_("Don't know how to figure width of %c in md_assemble()"),
3940 the_ins.reloc[m].wid);
3943 fixP = fix_new_exp (frag_now,
3944 ((toP - frag_now->fr_literal)
3945 - the_ins.numo * 2 + the_ins.reloc[m].n),
3947 &the_ins.reloc[m].exp,
3948 the_ins.reloc[m].pcrel,
3949 get_reloc_code (n, the_ins.reloc[m].pcrel,
3950 the_ins.reloc[m].pic_reloc));
3951 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
3952 if (the_ins.reloc[m].wid == 'B')
3953 fixP->fx_signed = 1;
3955 return;
3958 /* There's some frag hacking. */
3960 /* Calculate the max frag size. */
3961 int wid;
3963 wid = 2 * the_ins.fragb[0].fragoff;
3964 for (n = 1; n < the_ins.nfrag; n++)
3965 wid += 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3966 /* frag_var part. */
3967 wid += 10;
3968 /* Make sure the whole insn fits in one chunk, in particular that
3969 the var part is attached, as we access one byte before the
3970 variable frag for byte branches. */
3971 frag_grow (wid);
3974 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
3976 int wid;
3978 if (n == 0)
3979 wid = 2 * the_ins.fragb[n].fragoff;
3980 else
3981 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
3982 toP = frag_more (wid);
3983 to_beg_P = toP;
3984 shorts_this_frag = 0;
3985 for (m = wid / 2; m; --m)
3987 md_number_to_chars (toP, (long) (*fromP), 2);
3988 toP += 2;
3989 fromP++;
3990 shorts_this_frag++;
3992 for (m = 0; m < the_ins.nrel; m++)
3994 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
3996 the_ins.reloc[m].n -= 2 * shorts_this_frag;
3997 break;
3999 wid = the_ins.reloc[m].wid;
4000 if (wid == 0)
4001 continue;
4002 the_ins.reloc[m].wid = 0;
4003 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4005 fixP = fix_new_exp (frag_now,
4006 ((toP - frag_now->fr_literal)
4007 - the_ins.numo * 2 + the_ins.reloc[m].n),
4008 wid,
4009 &the_ins.reloc[m].exp,
4010 the_ins.reloc[m].pcrel,
4011 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4012 the_ins.reloc[m].pic_reloc));
4013 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4015 (void) frag_var (rs_machine_dependent, 10, 0,
4016 (relax_substateT) (the_ins.fragb[n].fragty),
4017 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
4019 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
4020 shorts_this_frag = 0;
4021 if (n)
4023 toP = frag_more (n * 2);
4024 while (n--)
4026 md_number_to_chars (toP, (long) (*fromP), 2);
4027 toP += 2;
4028 fromP++;
4029 shorts_this_frag++;
4032 for (m = 0; m < the_ins.nrel; m++)
4034 int wid;
4036 wid = the_ins.reloc[m].wid;
4037 if (wid == 0)
4038 continue;
4039 the_ins.reloc[m].wid = 0;
4040 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
4042 fixP = fix_new_exp (frag_now,
4043 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
4044 - shorts_this_frag * 2),
4045 wid,
4046 &the_ins.reloc[m].exp,
4047 the_ins.reloc[m].pcrel,
4048 get_reloc_code (wid, the_ins.reloc[m].pcrel,
4049 the_ins.reloc[m].pic_reloc));
4050 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
4054 /* Comparison function used by qsort to rank the opcode entries by name. */
4056 static int
4057 m68k_compare_opcode (const void * v1, const void * v2)
4059 struct m68k_opcode * op1, * op2;
4060 int ret;
4062 if (v1 == v2)
4063 return 0;
4065 op1 = *(struct m68k_opcode **) v1;
4066 op2 = *(struct m68k_opcode **) v2;
4068 /* Compare the two names. If different, return the comparison.
4069 If the same, return the order they are in the opcode table. */
4070 ret = strcmp (op1->name, op2->name);
4071 if (ret)
4072 return ret;
4073 if (op1 < op2)
4074 return -1;
4075 return 1;
4078 void
4079 md_begin (void)
4081 const struct m68k_opcode *ins;
4082 struct m68k_incant *hack, *slak;
4083 const char *retval = 0; /* Empty string, or error msg text. */
4084 int i;
4086 /* Set up hash tables with 68000 instructions.
4087 similar to what the vax assembler does. */
4088 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
4089 a copy of it at runtime, adding in the information we want but isn't
4090 there. I think it'd be better to have an awk script hack the table
4091 at compile time. Or even just xstr the table and use it as-is. But
4092 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
4093 names. */
4095 if (flag_mri)
4097 flag_reg_prefix_optional = 1;
4098 m68k_abspcadd = 1;
4099 if (! m68k_rel32_from_cmdline)
4100 m68k_rel32 = 0;
4103 /* First sort the opcode table into alphabetical order to seperate
4104 the order that the assembler wants to see the opcodes from the
4105 order that the disassembler wants to see them. */
4106 m68k_sorted_opcodes = xmalloc (m68k_numopcodes * sizeof (* m68k_sorted_opcodes));
4107 if (!m68k_sorted_opcodes)
4108 as_fatal (_("Internal Error: Can't allocate m68k_sorted_opcodes of size %d"),
4109 m68k_numopcodes * ((int) sizeof (* m68k_sorted_opcodes)));
4111 for (i = m68k_numopcodes; i--;)
4112 m68k_sorted_opcodes[i] = m68k_opcodes + i;
4114 qsort (m68k_sorted_opcodes, m68k_numopcodes,
4115 sizeof (m68k_sorted_opcodes[0]), m68k_compare_opcode);
4117 op_hash = hash_new ();
4119 obstack_begin (&robyn, 4000);
4120 for (i = 0; i < m68k_numopcodes; i++)
4122 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
4125 ins = m68k_sorted_opcodes[i];
4127 /* We *could* ignore insns that don't match our
4128 arch here by just leaving them out of the hash. */
4129 slak->m_operands = ins->args;
4130 slak->m_opnum = strlen (slak->m_operands) / 2;
4131 slak->m_arch = ins->arch;
4132 slak->m_opcode = ins->opcode;
4133 /* This is kludgey. */
4134 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
4135 if (i + 1 != m68k_numopcodes
4136 && !strcmp (ins->name, m68k_sorted_opcodes[i + 1]->name))
4138 slak->m_next = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4139 i++;
4141 else
4142 slak->m_next = 0;
4143 slak = slak->m_next;
4145 while (slak);
4147 retval = hash_insert (op_hash, ins->name, (char *) hack);
4148 if (retval)
4149 as_fatal (_("Internal Error: Can't hash %s: %s"), ins->name, retval);
4152 for (i = 0; i < m68k_numaliases; i++)
4154 const char *name = m68k_opcode_aliases[i].primary;
4155 const char *alias = m68k_opcode_aliases[i].alias;
4156 PTR val = hash_find (op_hash, name);
4158 if (!val)
4159 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4160 retval = hash_insert (op_hash, alias, val);
4161 if (retval)
4162 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4165 /* In MRI mode, all unsized branches are variable sized. Normally,
4166 they are word sized. */
4167 if (flag_mri)
4169 static struct m68k_opcode_alias mri_aliases[] =
4171 { "bhi", "jhi", },
4172 { "bls", "jls", },
4173 { "bcc", "jcc", },
4174 { "bcs", "jcs", },
4175 { "bne", "jne", },
4176 { "beq", "jeq", },
4177 { "bvc", "jvc", },
4178 { "bvs", "jvs", },
4179 { "bpl", "jpl", },
4180 { "bmi", "jmi", },
4181 { "bge", "jge", },
4182 { "blt", "jlt", },
4183 { "bgt", "jgt", },
4184 { "ble", "jle", },
4185 { "bra", "jra", },
4186 { "bsr", "jbsr", },
4189 for (i = 0;
4190 i < (int) (sizeof mri_aliases / sizeof mri_aliases[0]);
4191 i++)
4193 const char *name = mri_aliases[i].primary;
4194 const char *alias = mri_aliases[i].alias;
4195 PTR val = hash_find (op_hash, name);
4197 if (!val)
4198 as_fatal (_("Internal Error: Can't find %s in hash table"), name);
4199 retval = hash_jam (op_hash, alias, val);
4200 if (retval)
4201 as_fatal (_("Internal Error: Can't hash %s: %s"), alias, retval);
4205 for (i = 0; i < (int) sizeof (notend_table); i++)
4207 notend_table[i] = 0;
4208 alt_notend_table[i] = 0;
4211 notend_table[','] = 1;
4212 notend_table['{'] = 1;
4213 notend_table['}'] = 1;
4214 alt_notend_table['a'] = 1;
4215 alt_notend_table['A'] = 1;
4216 alt_notend_table['d'] = 1;
4217 alt_notend_table['D'] = 1;
4218 alt_notend_table['#'] = 1;
4219 alt_notend_table['&'] = 1;
4220 alt_notend_table['f'] = 1;
4221 alt_notend_table['F'] = 1;
4222 #ifdef REGISTER_PREFIX
4223 alt_notend_table[REGISTER_PREFIX] = 1;
4224 #endif
4226 /* We need to put '(' in alt_notend_table to handle
4227 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1) */
4228 alt_notend_table['('] = 1;
4230 /* We need to put '@' in alt_notend_table to handle
4231 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1) */
4232 alt_notend_table['@'] = 1;
4234 /* We need to put digits in alt_notend_table to handle
4235 bfextu %d0{24:1},%d0 */
4236 alt_notend_table['0'] = 1;
4237 alt_notend_table['1'] = 1;
4238 alt_notend_table['2'] = 1;
4239 alt_notend_table['3'] = 1;
4240 alt_notend_table['4'] = 1;
4241 alt_notend_table['5'] = 1;
4242 alt_notend_table['6'] = 1;
4243 alt_notend_table['7'] = 1;
4244 alt_notend_table['8'] = 1;
4245 alt_notend_table['9'] = 1;
4247 #ifndef MIT_SYNTAX_ONLY
4248 /* Insert pseudo ops, these have to go into the opcode table since
4249 gas expects pseudo ops to start with a dot. */
4251 int n = 0;
4253 while (mote_pseudo_table[n].poc_name)
4255 hack = obstack_alloc (&robyn, sizeof (struct m68k_incant));
4256 hash_insert (op_hash,
4257 mote_pseudo_table[n].poc_name, (char *) hack);
4258 hack->m_operands = 0;
4259 hack->m_opnum = n;
4260 n++;
4263 #endif
4265 init_regtable ();
4267 #ifdef OBJ_ELF
4268 record_alignment (text_section, 2);
4269 record_alignment (data_section, 2);
4270 record_alignment (bss_section, 2);
4271 #endif
4274 static void
4275 select_control_regs (void)
4277 /* Note which set of "movec" control registers is available. */
4278 switch (current_chip)
4280 case 0:
4281 if (verbose)
4282 as_warn (_("architecture not yet selected: defaulting to 68020"));
4283 control_regs = m68020_control_regs;
4284 break;
4286 case m68000:
4287 control_regs = m68000_control_regs;
4288 break;
4289 case m68010:
4290 control_regs = m68010_control_regs;
4291 break;
4292 case m68020:
4293 case m68030:
4294 control_regs = m68020_control_regs;
4295 break;
4296 case m68040:
4297 control_regs = m68040_control_regs;
4298 break;
4299 case m68060:
4300 control_regs = m68060_control_regs;
4301 break;
4302 case cpu32:
4303 control_regs = cpu32_control_regs;
4304 break;
4305 case mcf5200:
4306 case mcf5206e:
4307 case mcf5307:
4308 case mcf5407:
4309 control_regs = mcf_control_regs;
4310 break;
4311 case mcf5249:
4312 control_regs = mcf5249_control_regs;
4313 break;
4314 case mcf528x:
4315 case mcf521x:
4316 control_regs = mcf528x_control_regs;
4317 break;
4318 case mcf5470:
4319 case mcf5480:
4320 control_regs = mcfv4e_control_regs;
4321 break;
4322 default:
4323 abort ();
4327 void
4328 m68k_init_after_args (void)
4330 if (cpu_of_arch (current_architecture) == 0)
4332 int i;
4333 const char *default_cpu = TARGET_CPU;
4335 if (*default_cpu == 'm')
4336 default_cpu++;
4337 for (i = 0; i < n_archs; i++)
4338 if (strcasecmp (default_cpu, archs[i].name) == 0)
4339 break;
4340 if (i == n_archs)
4342 as_bad (_("unrecognized default cpu `%s' ???"), TARGET_CPU);
4343 current_architecture |= m68020;
4345 else
4346 current_architecture |= archs[i].arch;
4348 /* Permit m68881 specification with all cpus; those that can't work
4349 with a coprocessor could be doing emulation. */
4350 if (current_architecture & m68851)
4352 if (current_architecture & m68040)
4353 as_warn (_("68040 and 68851 specified; mmu instructions may assemble incorrectly"));
4355 /* What other incompatibilities could we check for? */
4357 /* Toss in some default assumptions about coprocessors. */
4358 if (!no_68881
4359 && (cpu_of_arch (current_architecture)
4360 /* Can CPU32 have a 68881 coprocessor?? */
4361 & (m68020 | m68030 | cpu32)))
4362 current_architecture |= m68881;
4364 if (!no_68851
4365 && (cpu_of_arch (current_architecture) & m68020up) != 0
4366 && (cpu_of_arch (current_architecture) & m68040up) == 0)
4367 current_architecture |= m68851;
4369 if (no_68881 && (current_architecture & m68881))
4370 as_bad (_("options for 68881 and no-68881 both given"));
4372 if (no_68851 && (current_architecture & m68851))
4373 as_bad (_("options for 68851 and no-68851 both given"));
4375 /* Note which set of "movec" control registers is available. */
4376 select_control_regs ();
4378 if (cpu_of_arch (current_architecture) < m68020
4379 || arch_coldfire_p (current_architecture))
4380 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
4383 /* This is called when a label is defined. */
4385 void
4386 m68k_frob_label (symbolS *sym)
4388 struct label_line *n;
4390 n = (struct label_line *) xmalloc (sizeof *n);
4391 n->next = labels;
4392 n->label = sym;
4393 as_where (&n->file, &n->line);
4394 n->text = 0;
4395 labels = n;
4396 current_label = n;
4398 #ifdef OBJ_ELF
4399 dwarf2_emit_label (sym);
4400 #endif
4403 /* This is called when a value that is not an instruction is emitted. */
4405 void
4406 m68k_flush_pending_output (void)
4408 current_label = NULL;
4411 /* This is called at the end of the assembly, when the final value of
4412 the label is known. We warn if this is a text symbol aligned at an
4413 odd location. */
4415 void
4416 m68k_frob_symbol (symbolS *sym)
4418 if (S_GET_SEGMENT (sym) == reg_section
4419 && (int) S_GET_VALUE (sym) < 0)
4421 S_SET_SEGMENT (sym, absolute_section);
4422 S_SET_VALUE (sym, ~(int)S_GET_VALUE (sym));
4424 else if ((S_GET_VALUE (sym) & 1) != 0)
4426 struct label_line *l;
4428 for (l = labels; l != NULL; l = l->next)
4430 if (l->label == sym)
4432 if (l->text)
4433 as_warn_where (l->file, l->line,
4434 _("text label `%s' aligned to odd boundary"),
4435 S_GET_NAME (sym));
4436 break;
4442 /* This is called if we go in or out of MRI mode because of the .mri
4443 pseudo-op. */
4445 void
4446 m68k_mri_mode_change (int on)
4448 if (on)
4450 if (! flag_reg_prefix_optional)
4452 flag_reg_prefix_optional = 1;
4453 #ifdef REGISTER_PREFIX
4454 init_regtable ();
4455 #endif
4457 m68k_abspcadd = 1;
4458 if (! m68k_rel32_from_cmdline)
4459 m68k_rel32 = 0;
4461 else
4463 if (! reg_prefix_optional_seen)
4465 #ifdef REGISTER_PREFIX_OPTIONAL
4466 flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
4467 #else
4468 flag_reg_prefix_optional = 0;
4469 #endif
4470 #ifdef REGISTER_PREFIX
4471 init_regtable ();
4472 #endif
4474 m68k_abspcadd = 0;
4475 if (! m68k_rel32_from_cmdline)
4476 m68k_rel32 = 1;
4480 /* Equal to MAX_PRECISION in atof-ieee.c. */
4481 #define MAX_LITTLENUMS 6
4483 /* Turn a string in input_line_pointer into a floating point constant
4484 of type TYPE, and store the appropriate bytes in *LITP. The number
4485 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4486 returned, or NULL on OK. */
4488 char *
4489 md_atof (int type, char *litP, int *sizeP)
4491 int prec;
4492 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4493 LITTLENUM_TYPE *wordP;
4494 char *t;
4496 switch (type)
4498 case 'f':
4499 case 'F':
4500 case 's':
4501 case 'S':
4502 prec = 2;
4503 break;
4505 case 'd':
4506 case 'D':
4507 case 'r':
4508 case 'R':
4509 prec = 4;
4510 break;
4512 case 'x':
4513 case 'X':
4514 prec = 6;
4515 break;
4517 case 'p':
4518 case 'P':
4519 prec = 6;
4520 break;
4522 default:
4523 *sizeP = 0;
4524 return _("Bad call to MD_ATOF()");
4526 t = atof_ieee (input_line_pointer, type, words);
4527 if (t)
4528 input_line_pointer = t;
4530 *sizeP = prec * sizeof (LITTLENUM_TYPE);
4531 for (wordP = words; prec--;)
4533 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
4534 litP += sizeof (LITTLENUM_TYPE);
4536 return 0;
4539 void
4540 md_number_to_chars (char *buf, valueT val, int n)
4542 number_to_chars_bigendian (buf, val, n);
4545 void
4546 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
4548 offsetT val = *valP;
4549 addressT upper_limit;
4550 offsetT lower_limit;
4552 /* This is unnecessary but it convinces the native rs6000 compiler
4553 to generate the code we want. */
4554 char *buf = fixP->fx_frag->fr_literal;
4555 buf += fixP->fx_where;
4556 /* End ibm compiler workaround. */
4558 val = SEXT (val);
4560 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
4561 fixP->fx_done = 1;
4563 #ifdef OBJ_ELF
4564 if (fixP->fx_addsy)
4566 memset (buf, 0, fixP->fx_size);
4567 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
4569 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4570 && !S_IS_DEFINED (fixP->fx_addsy)
4571 && !S_IS_WEAK (fixP->fx_addsy))
4572 S_SET_WEAK (fixP->fx_addsy);
4573 return;
4575 #endif
4577 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
4578 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
4579 return;
4581 switch (fixP->fx_size)
4583 /* The cast to offsetT below are necessary to make code
4584 correct for machines where ints are smaller than offsetT. */
4585 case 1:
4586 *buf++ = val;
4587 upper_limit = 0x7f;
4588 lower_limit = - (offsetT) 0x80;
4589 break;
4590 case 2:
4591 *buf++ = (val >> 8);
4592 *buf++ = val;
4593 upper_limit = 0x7fff;
4594 lower_limit = - (offsetT) 0x8000;
4595 break;
4596 case 4:
4597 *buf++ = (val >> 24);
4598 *buf++ = (val >> 16);
4599 *buf++ = (val >> 8);
4600 *buf++ = val;
4601 upper_limit = 0x7fffffff;
4602 lower_limit = - (offsetT) 0x7fffffff - 1; /* Avoid constant overflow. */
4603 break;
4604 default:
4605 BAD_CASE (fixP->fx_size);
4608 /* Fix up a negative reloc. */
4609 if (fixP->fx_addsy == NULL && fixP->fx_subsy != NULL)
4611 fixP->fx_addsy = fixP->fx_subsy;
4612 fixP->fx_subsy = NULL;
4613 fixP->fx_tcbit = 1;
4616 /* For non-pc-relative values, it's conceivable we might get something
4617 like "0xff" for a byte field. So extend the upper part of the range
4618 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
4619 so that we can do any range checking at all. */
4620 if (! fixP->fx_pcrel && ! fixP->fx_signed)
4621 upper_limit = upper_limit * 2 + 1;
4623 if ((addressT) val > upper_limit
4624 && (val > 0 || val < lower_limit))
4625 as_bad_where (fixP->fx_file, fixP->fx_line, _("value out of range"));
4627 /* A one byte PC-relative reloc means a short branch. We can't use
4628 a short branch with a value of 0 or -1, because those indicate
4629 different opcodes (branches with longer offsets). fixup_segment
4630 in write.c may have clobbered fx_pcrel, so we need to examine the
4631 reloc type. */
4632 if ((fixP->fx_pcrel
4633 || fixP->fx_r_type == BFD_RELOC_8_PCREL)
4634 && fixP->fx_size == 1
4635 && (fixP->fx_addsy == NULL
4636 || S_IS_DEFINED (fixP->fx_addsy))
4637 && (val == 0 || val == -1))
4638 as_bad_where (fixP->fx_file, fixP->fx_line, _("invalid byte branch offset"));
4641 /* *fragP has been relaxed to its final size, and now needs to have
4642 the bytes inside it modified to conform to the new size There is UGLY
4643 MAGIC here. ..
4645 static void
4646 md_convert_frag_1 (fragS *fragP)
4648 long disp;
4649 fixS *fixP;
4651 /* Address in object code of the displacement. */
4652 register int object_address = fragP->fr_fix + fragP->fr_address;
4654 /* Address in gas core of the place to store the displacement. */
4655 /* This convinces the native rs6000 compiler to generate the code we
4656 want. */
4657 register char *buffer_address = fragP->fr_literal;
4658 buffer_address += fragP->fr_fix;
4659 /* End ibm compiler workaround. */
4661 /* The displacement of the address, from current location. */
4662 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
4663 disp = (disp + fragP->fr_offset) - object_address;
4665 switch (fragP->fr_subtype)
4667 case TAB (BRANCHBWL, BYTE):
4668 case TAB (BRABSJUNC, BYTE):
4669 case TAB (BRABSJCOND, BYTE):
4670 case TAB (BRANCHBW, BYTE):
4671 know (issbyte (disp));
4672 if (disp == 0)
4673 as_bad_where (fragP->fr_file, fragP->fr_line,
4674 _("short branch with zero offset: use :w"));
4675 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4676 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4677 fixP->fx_pcrel_adjust = -1;
4678 break;
4679 case TAB (BRANCHBWL, SHORT):
4680 case TAB (BRABSJUNC, SHORT):
4681 case TAB (BRABSJCOND, SHORT):
4682 case TAB (BRANCHBW, SHORT):
4683 fragP->fr_opcode[1] = 0x00;
4684 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4685 1, RELAX_RELOC_PC16);
4686 fragP->fr_fix += 2;
4687 break;
4688 case TAB (BRANCHBWL, LONG):
4689 fragP->fr_opcode[1] = (char) 0xFF;
4690 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4691 1, RELAX_RELOC_PC32);
4692 fragP->fr_fix += 4;
4693 break;
4694 case TAB (BRABSJUNC, LONG):
4695 if (fragP->fr_opcode[0] == 0x61) /* jbsr */
4697 if (flag_keep_pcrel)
4698 as_fatal (_("Tried to convert PC relative BSR to absolute JSR"));
4699 fragP->fr_opcode[0] = 0x4E;
4700 fragP->fr_opcode[1] = (char) 0xB9; /* JSR with ABSL LONG operand. */
4701 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4702 0, RELAX_RELOC_ABS32);
4703 fragP->fr_fix += 4;
4705 else if (fragP->fr_opcode[0] == 0x60) /* jbra */
4707 if (flag_keep_pcrel)
4708 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
4709 fragP->fr_opcode[0] = 0x4E;
4710 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG operand. */
4711 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4712 0, RELAX_RELOC_ABS32);
4713 fragP->fr_fix += 4;
4715 else
4717 /* This cannot happen, because jbsr and jbra are the only two
4718 unconditional branches. */
4719 abort ();
4721 break;
4722 case TAB (BRABSJCOND, LONG):
4723 if (flag_keep_pcrel)
4724 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4726 /* Only Bcc 68000 instructions can come here
4727 Change bcc into b!cc/jmp absl long. */
4728 fragP->fr_opcode[0] ^= 0x01; /* Invert bcc. */
4729 fragP->fr_opcode[1] = 0x06; /* Branch offset = 6. */
4731 /* JF: these used to be fr_opcode[2,3], but they may be in a
4732 different frag, in which case referring to them is a no-no.
4733 Only fr_opcode[0,1] are guaranteed to work. */
4734 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
4735 *buffer_address++ = (char) 0xf9;
4736 fragP->fr_fix += 2; /* Account for jmp instruction. */
4737 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
4738 fragP->fr_offset, 0, RELAX_RELOC_ABS32);
4739 fragP->fr_fix += 4;
4740 break;
4741 case TAB (FBRANCH, SHORT):
4742 know ((fragP->fr_opcode[1] & 0x40) == 0);
4743 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4744 1, RELAX_RELOC_PC16);
4745 fragP->fr_fix += 2;
4746 break;
4747 case TAB (FBRANCH, LONG):
4748 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit. */
4749 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4750 1, RELAX_RELOC_PC32);
4751 fragP->fr_fix += 4;
4752 break;
4753 case TAB (DBCCLBR, SHORT):
4754 case TAB (DBCCABSJ, SHORT):
4755 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4756 1, RELAX_RELOC_PC16);
4757 fragP->fr_fix += 2;
4758 break;
4759 case TAB (DBCCLBR, LONG):
4760 /* Only DBcc instructions can come here.
4761 Change dbcc into dbcc/bral.
4762 JF: these used to be fr_opcode[2-7], but that's wrong. */
4763 if (flag_keep_pcrel)
4764 as_fatal (_("Tried to convert DBcc to absolute jump"));
4766 *buffer_address++ = 0x00; /* Branch offset = 4. */
4767 *buffer_address++ = 0x04;
4768 *buffer_address++ = 0x60; /* Put in bra pc+6. */
4769 *buffer_address++ = 0x06;
4770 *buffer_address++ = 0x60; /* Put in bral (0x60ff). */
4771 *buffer_address++ = (char) 0xff;
4773 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4774 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 1,
4775 RELAX_RELOC_PC32);
4776 fragP->fr_fix += 4;
4777 break;
4778 case TAB (DBCCABSJ, LONG):
4779 /* Only DBcc instructions can come here.
4780 Change dbcc into dbcc/jmp.
4781 JF: these used to be fr_opcode[2-7], but that's wrong. */
4782 if (flag_keep_pcrel)
4783 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4785 *buffer_address++ = 0x00; /* Branch offset = 4. */
4786 *buffer_address++ = 0x04;
4787 *buffer_address++ = 0x60; /* Put in bra pc + 6. */
4788 *buffer_address++ = 0x06;
4789 *buffer_address++ = 0x4e; /* Put in jmp long (0x4ef9). */
4790 *buffer_address++ = (char) 0xf9;
4792 fragP->fr_fix += 6; /* Account for bra/jmp instructions. */
4793 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset, 0,
4794 RELAX_RELOC_ABS32);
4795 fragP->fr_fix += 4;
4796 break;
4797 case TAB (PCREL1632, SHORT):
4798 fragP->fr_opcode[1] &= ~0x3F;
4799 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
4800 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4801 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4802 fragP->fr_fix += 2;
4803 break;
4804 case TAB (PCREL1632, LONG):
4805 /* Already set to mode 7.3; this indicates: PC indirect with
4806 suppressed index, 32-bit displacement. */
4807 *buffer_address++ = 0x01;
4808 *buffer_address++ = 0x70;
4809 fragP->fr_fix += 2;
4810 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4811 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4812 fixP->fx_pcrel_adjust = 2;
4813 fragP->fr_fix += 4;
4814 break;
4815 case TAB (PCINDEX, BYTE):
4816 assert (fragP->fr_fix >= 2);
4817 buffer_address[-2] &= ~1;
4818 fixP = fix_new (fragP, fragP->fr_fix - 1, 1, fragP->fr_symbol,
4819 fragP->fr_offset, 1, RELAX_RELOC_PC8);
4820 fixP->fx_pcrel_adjust = 1;
4821 break;
4822 case TAB (PCINDEX, SHORT):
4823 assert (fragP->fr_fix >= 2);
4824 buffer_address[-2] |= 0x1;
4825 buffer_address[-1] = 0x20;
4826 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
4827 fragP->fr_offset, 1, RELAX_RELOC_PC16);
4828 fixP->fx_pcrel_adjust = 2;
4829 fragP->fr_fix += 2;
4830 break;
4831 case TAB (PCINDEX, LONG):
4832 assert (fragP->fr_fix >= 2);
4833 buffer_address[-2] |= 0x1;
4834 buffer_address[-1] = 0x30;
4835 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
4836 fragP->fr_offset, 1, RELAX_RELOC_PC32);
4837 fixP->fx_pcrel_adjust = 2;
4838 fragP->fr_fix += 4;
4839 break;
4840 case TAB (ABSTOPCREL, SHORT):
4841 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
4842 1, RELAX_RELOC_PC16);
4843 fragP->fr_fix += 2;
4844 break;
4845 case TAB (ABSTOPCREL, LONG):
4846 if (flag_keep_pcrel)
4847 as_fatal (_("Tried to convert PC relative conditional branch to absolute jump"));
4848 /* The thing to do here is force it to ABSOLUTE LONG, since
4849 ABSTOPCREL is really trying to shorten an ABSOLUTE address anyway. */
4850 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
4851 abort ();
4852 fragP->fr_opcode[1] &= ~0x3F;
4853 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
4854 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
4855 0, RELAX_RELOC_ABS32);
4856 fragP->fr_fix += 4;
4857 break;
4861 void
4862 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
4863 segT sec ATTRIBUTE_UNUSED,
4864 fragS *fragP)
4866 md_convert_frag_1 (fragP);
4869 /* Force truly undefined symbols to their maximum size, and generally set up
4870 the frag list to be relaxed
4873 md_estimate_size_before_relax (fragS *fragP, segT segment)
4875 /* Handle SZ_UNDEF first, it can be changed to BYTE or SHORT. */
4876 switch (fragP->fr_subtype)
4878 case TAB (BRANCHBWL, SZ_UNDEF):
4879 case TAB (BRABSJUNC, SZ_UNDEF):
4880 case TAB (BRABSJCOND, SZ_UNDEF):
4882 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4883 && relaxable_symbol (fragP->fr_symbol))
4885 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4887 else if (flag_short_refs)
4889 /* Symbol is undefined and we want short ref. */
4890 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4892 else
4894 /* Symbol is still undefined. Make it LONG. */
4895 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4897 break;
4900 case TAB (BRANCHBW, SZ_UNDEF):
4902 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
4903 && relaxable_symbol (fragP->fr_symbol))
4905 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
4907 else
4909 /* Symbol is undefined and we don't have long branches. */
4910 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4912 break;
4915 case TAB (FBRANCH, SZ_UNDEF):
4916 case TAB (DBCCLBR, SZ_UNDEF):
4917 case TAB (DBCCABSJ, SZ_UNDEF):
4918 case TAB (PCREL1632, SZ_UNDEF):
4920 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4921 && relaxable_symbol (fragP->fr_symbol))
4922 || flag_short_refs)
4924 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4926 else
4928 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), LONG);
4930 break;
4933 case TAB (PCINDEX, SZ_UNDEF):
4934 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4935 && relaxable_symbol (fragP->fr_symbol)))
4937 fragP->fr_subtype = TAB (PCINDEX, BYTE);
4939 else
4941 fragP->fr_subtype = TAB (PCINDEX, LONG);
4943 break;
4945 case TAB (ABSTOPCREL, SZ_UNDEF):
4947 if ((S_GET_SEGMENT (fragP->fr_symbol) == segment
4948 && relaxable_symbol (fragP->fr_symbol)))
4950 fragP->fr_subtype = TAB (ABSTOPCREL, SHORT);
4952 else
4954 fragP->fr_subtype = TAB (ABSTOPCREL, LONG);
4956 break;
4959 default:
4960 break;
4963 /* Now that SZ_UNDEF are taken care of, check others. */
4964 switch (fragP->fr_subtype)
4966 case TAB (BRANCHBWL, BYTE):
4967 case TAB (BRABSJUNC, BYTE):
4968 case TAB (BRABSJCOND, BYTE):
4969 case TAB (BRANCHBW, BYTE):
4970 /* We can't do a short jump to the next instruction, so in that
4971 case we force word mode. If the symbol is at the start of a
4972 frag, and it is the next frag with any data in it (usually
4973 this is just the next frag, but assembler listings may
4974 introduce empty frags), we must use word mode. */
4975 if (fragP->fr_symbol)
4977 fragS *sym_frag;
4979 sym_frag = symbol_get_frag (fragP->fr_symbol);
4980 if (S_GET_VALUE (fragP->fr_symbol) == sym_frag->fr_address)
4982 fragS *l;
4984 for (l = fragP->fr_next; l && l != sym_frag; l = l->fr_next)
4985 if (l->fr_fix != 0)
4986 break;
4987 if (l == sym_frag)
4988 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
4991 break;
4992 default:
4993 break;
4995 return md_relax_table[fragP->fr_subtype].rlx_length;
4998 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
4999 /* the bit-field entries in the relocation_info struct plays hell
5000 with the byte-order problems of cross-assembly. So as a hack,
5001 I added this mach. dependent ri twiddler. Ugly, but it gets
5002 you there. -KWK */
5003 /* on m68k: first 4 bytes are normal unsigned long, next three bytes
5004 are symbolnum, most sig. byte first. Last byte is broken up with
5005 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
5006 nibble as nuthin. (on Sun 3 at least) */
5007 /* Translate the internal relocation information into target-specific
5008 format. */
5009 #ifdef comment
5010 void
5011 md_ri_to_chars (char *the_bytes, struct reloc_info_generic *ri)
5013 /* This is easy. */
5014 md_number_to_chars (the_bytes, ri->r_address, 4);
5015 /* Now the fun stuff. */
5016 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
5017 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
5018 the_bytes[6] = ri->r_symbolnum & 0x0ff;
5019 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80)
5020 | ((ri->r_length << 5) & 0x60)
5021 | ((ri->r_extern << 4) & 0x10));
5024 #endif
5026 #endif /* OBJ_AOUT or OBJ_BOUT */
5028 #ifndef WORKING_DOT_WORD
5029 int md_short_jump_size = 4;
5030 int md_long_jump_size = 6;
5032 void
5033 md_create_short_jump (char *ptr, addressT from_addr, addressT to_addr,
5034 fragS *frag ATTRIBUTE_UNUSED,
5035 symbolS *to_symbol ATTRIBUTE_UNUSED)
5037 valueT offset;
5039 offset = to_addr - (from_addr + 2);
5041 md_number_to_chars (ptr, (valueT) 0x6000, 2);
5042 md_number_to_chars (ptr + 2, (valueT) offset, 2);
5045 void
5046 md_create_long_jump (char *ptr, addressT from_addr, addressT to_addr,
5047 fragS *frag, symbolS *to_symbol)
5049 valueT offset;
5051 if (!HAVE_LONG_BRANCH (current_architecture))
5053 if (flag_keep_pcrel)
5054 as_fatal (_("Tried to convert PC relative branch to absolute jump"));
5055 offset = to_addr - S_GET_VALUE (to_symbol);
5056 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
5057 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5058 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
5059 0, NO_RELOC);
5061 else
5063 offset = to_addr - (from_addr + 2);
5064 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
5065 md_number_to_chars (ptr + 2, (valueT) offset, 4);
5069 #endif
5071 /* Different values of OK tell what its OK to return. Things that
5072 aren't OK are an error (what a shock, no?)
5074 0: Everything is OK
5075 10: Absolute 1:8 only
5076 20: Absolute 0:7 only
5077 30: absolute 0:15 only
5078 40: Absolute 0:31 only
5079 50: absolute 0:127 only
5080 55: absolute -64:63 only
5081 60: absolute -128:127 only
5082 70: absolute 0:4095 only
5083 80: absolute -1, 1:7 only
5084 90: No bignums. */
5086 static int
5087 get_num (struct m68k_exp *exp, int ok)
5089 if (exp->exp.X_op == O_absent)
5091 /* Do the same thing the VAX asm does. */
5092 op (exp) = O_constant;
5093 adds (exp) = 0;
5094 subs (exp) = 0;
5095 offs (exp) = 0;
5096 if (ok == 10)
5098 as_warn (_("expression out of range: defaulting to 1"));
5099 offs (exp) = 1;
5102 else if (exp->exp.X_op == O_constant)
5104 switch (ok)
5106 case 10:
5107 if ((valueT) TRUNC (offs (exp)) - 1 > 7)
5109 as_warn (_("expression out of range: defaulting to 1"));
5110 offs (exp) = 1;
5112 break;
5113 case 20:
5114 if ((valueT) TRUNC (offs (exp)) > 7)
5115 goto outrange;
5116 break;
5117 case 30:
5118 if ((valueT) TRUNC (offs (exp)) > 15)
5119 goto outrange;
5120 break;
5121 case 40:
5122 if ((valueT) TRUNC (offs (exp)) > 32)
5123 goto outrange;
5124 break;
5125 case 50:
5126 if ((valueT) TRUNC (offs (exp)) > 127)
5127 goto outrange;
5128 break;
5129 case 55:
5130 if ((valueT) SEXT (offs (exp)) + 64 > 127)
5131 goto outrange;
5132 break;
5133 case 60:
5134 if ((valueT) SEXT (offs (exp)) + 128 > 255)
5135 goto outrange;
5136 break;
5137 case 70:
5138 if ((valueT) TRUNC (offs (exp)) > 4095)
5140 outrange:
5141 as_warn (_("expression out of range: defaulting to 0"));
5142 offs (exp) = 0;
5144 break;
5145 case 80:
5146 if ((valueT) TRUNC (offs (exp)) != 0xffffffff
5147 && (valueT) TRUNC (offs (exp)) - 1 > 6)
5149 as_warn (_("expression out of range: defaulting to 1"));
5150 offs (exp) = 1;
5152 break;
5153 default:
5154 break;
5157 else if (exp->exp.X_op == O_big)
5159 if (offs (exp) <= 0 /* flonum. */
5160 && (ok == 90 /* no bignums */
5161 || (ok > 10 /* Small-int ranges including 0 ok. */
5162 /* If we have a flonum zero, a zero integer should
5163 do as well (e.g., in moveq). */
5164 && generic_floating_point_number.exponent == 0
5165 && generic_floating_point_number.low[0] == 0)))
5167 /* HACK! Turn it into a long. */
5168 LITTLENUM_TYPE words[6];
5170 gen_to_words (words, 2, 8L); /* These numbers are magic! */
5171 op (exp) = O_constant;
5172 adds (exp) = 0;
5173 subs (exp) = 0;
5174 offs (exp) = words[1] | (words[0] << 16);
5176 else if (ok != 0)
5178 op (exp) = O_constant;
5179 adds (exp) = 0;
5180 subs (exp) = 0;
5181 offs (exp) = (ok == 10) ? 1 : 0;
5182 as_warn (_("Can't deal with expression; defaulting to %ld"),
5183 (long) offs (exp));
5186 else
5188 if (ok >= 10 && ok <= 80)
5190 op (exp) = O_constant;
5191 adds (exp) = 0;
5192 subs (exp) = 0;
5193 offs (exp) = (ok == 10) ? 1 : 0;
5194 as_warn (_("Can't deal with expression; defaulting to %ld"),
5195 (long) offs (exp));
5199 if (exp->size != SIZE_UNSPEC)
5201 switch (exp->size)
5203 case SIZE_UNSPEC:
5204 case SIZE_LONG:
5205 break;
5206 case SIZE_BYTE:
5207 if (!isbyte (offs (exp)))
5208 as_warn (_("expression doesn't fit in BYTE"));
5209 break;
5210 case SIZE_WORD:
5211 if (!isword (offs (exp)))
5212 as_warn (_("expression doesn't fit in WORD"));
5213 break;
5217 return offs (exp);
5220 /* These are the back-ends for the various machine dependent pseudo-ops. */
5222 static void
5223 s_data1 (int ignore ATTRIBUTE_UNUSED)
5225 subseg_set (data_section, 1);
5226 demand_empty_rest_of_line ();
5229 static void
5230 s_data2 (int ignore ATTRIBUTE_UNUSED)
5232 subseg_set (data_section, 2);
5233 demand_empty_rest_of_line ();
5236 static void
5237 s_bss (int ignore ATTRIBUTE_UNUSED)
5239 /* We don't support putting frags in the BSS segment, we fake it
5240 by marking in_bss, then looking at s_skip for clues. */
5242 subseg_set (bss_section, 0);
5243 demand_empty_rest_of_line ();
5246 static void
5247 s_even (int ignore ATTRIBUTE_UNUSED)
5249 register int temp;
5250 register long temp_fill;
5252 temp = 1; /* JF should be 2? */
5253 temp_fill = get_absolute_expression ();
5254 if (!need_pass_2) /* Never make frag if expect extra pass. */
5255 frag_align (temp, (int) temp_fill, 0);
5256 demand_empty_rest_of_line ();
5257 record_alignment (now_seg, temp);
5260 static void
5261 s_proc (int ignore ATTRIBUTE_UNUSED)
5263 demand_empty_rest_of_line ();
5266 /* Pseudo-ops handled for MRI compatibility. */
5268 /* This function returns non-zero if the argument is a conditional
5269 pseudo-op. This is called when checking whether a pending
5270 alignment is needed. */
5273 m68k_conditional_pseudoop (pseudo_typeS *pop)
5275 return (pop->poc_handler == s_mri_if
5276 || pop->poc_handler == s_mri_else);
5279 /* Handle an MRI style chip specification. */
5281 static void
5282 mri_chip (void)
5284 char *s;
5285 char c;
5286 int i;
5288 s = input_line_pointer;
5289 /* We can't use get_symbol_end since the processor names are not proper
5290 symbols. */
5291 while (is_part_of_name (c = *input_line_pointer++))
5293 *--input_line_pointer = 0;
5294 for (i = 0; i < n_archs; i++)
5295 if (strcasecmp (s, archs[i].name) == 0)
5296 break;
5297 if (i >= n_archs)
5299 as_bad (_("%s: unrecognized processor name"), s);
5300 *input_line_pointer = c;
5301 ignore_rest_of_line ();
5302 return;
5304 *input_line_pointer = c;
5306 if (*input_line_pointer == '/')
5307 current_architecture = 0;
5308 else
5309 current_architecture &= m68881 | m68851;
5310 current_architecture |= archs[i].arch;
5311 current_chip = archs[i].chip;
5313 while (*input_line_pointer == '/')
5315 ++input_line_pointer;
5316 s = input_line_pointer;
5317 /* We can't use get_symbol_end since the processor names are not
5318 proper symbols. */
5319 while (is_part_of_name (c = *input_line_pointer++))
5321 *--input_line_pointer = 0;
5322 if (strcmp (s, "68881") == 0)
5323 current_architecture |= m68881;
5324 else if (strcmp (s, "68851") == 0)
5325 current_architecture |= m68851;
5326 *input_line_pointer = c;
5329 /* Update info about available control registers. */
5330 select_control_regs ();
5333 /* The MRI CHIP pseudo-op. */
5335 static void
5336 s_chip (int ignore ATTRIBUTE_UNUSED)
5338 char *stop = NULL;
5339 char stopc;
5341 if (flag_mri)
5342 stop = mri_comment_field (&stopc);
5343 mri_chip ();
5344 if (flag_mri)
5345 mri_comment_end (stop, stopc);
5346 demand_empty_rest_of_line ();
5349 /* The MRI FOPT pseudo-op. */
5351 static void
5352 s_fopt (int ignore ATTRIBUTE_UNUSED)
5354 SKIP_WHITESPACE ();
5356 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
5358 int temp;
5360 input_line_pointer += 3;
5361 temp = get_absolute_expression ();
5362 if (temp < 0 || temp > 7)
5363 as_bad (_("bad coprocessor id"));
5364 else
5365 m68k_float_copnum = COP0 + temp;
5367 else
5369 as_bad (_("unrecognized fopt option"));
5370 ignore_rest_of_line ();
5371 return;
5374 demand_empty_rest_of_line ();
5377 /* The structure used to handle the MRI OPT pseudo-op. */
5379 struct opt_action
5381 /* The name of the option. */
5382 const char *name;
5384 /* If this is not NULL, just call this function. The first argument
5385 is the ARG field of this structure, the second argument is
5386 whether the option was negated. */
5387 void (*pfn) (int arg, int on);
5389 /* If this is not NULL, and the PFN field is NULL, set the variable
5390 this points to. Set it to the ARG field if the option was not
5391 negated, and the NOTARG field otherwise. */
5392 int *pvar;
5394 /* The value to pass to PFN or to assign to *PVAR. */
5395 int arg;
5397 /* The value to assign to *PVAR if the option is negated. If PFN is
5398 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
5399 the option may not be negated. */
5400 int notarg;
5403 /* The table used to handle the MRI OPT pseudo-op. */
5405 static void skip_to_comma (int, int);
5406 static void opt_nest (int, int);
5407 static void opt_chip (int, int);
5408 static void opt_list (int, int);
5409 static void opt_list_symbols (int, int);
5411 static const struct opt_action opt_table[] =
5413 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
5415 /* We do relaxing, so there is little use for these options. */
5416 { "b", 0, 0, 0, 0 },
5417 { "brs", 0, 0, 0, 0 },
5418 { "brb", 0, 0, 0, 0 },
5419 { "brl", 0, 0, 0, 0 },
5420 { "brw", 0, 0, 0, 0 },
5422 { "c", 0, 0, 0, 0 },
5423 { "cex", 0, 0, 0, 0 },
5424 { "case", 0, &symbols_case_sensitive, 1, 0 },
5425 { "cl", 0, 0, 0, 0 },
5426 { "cre", 0, 0, 0, 0 },
5427 { "d", 0, &flag_keep_locals, 1, 0 },
5428 { "e", 0, 0, 0, 0 },
5429 { "f", 0, &flag_short_refs, 1, 0 },
5430 { "frs", 0, &flag_short_refs, 1, 0 },
5431 { "frl", 0, &flag_short_refs, 0, 1 },
5432 { "g", 0, 0, 0, 0 },
5433 { "i", 0, 0, 0, 0 },
5434 { "m", 0, 0, 0, 0 },
5435 { "mex", 0, 0, 0, 0 },
5436 { "mc", 0, 0, 0, 0 },
5437 { "md", 0, 0, 0, 0 },
5438 { "nest", opt_nest, 0, 0, 0 },
5439 { "next", skip_to_comma, 0, 0, 0 },
5440 { "o", 0, 0, 0, 0 },
5441 { "old", 0, 0, 0, 0 },
5442 { "op", skip_to_comma, 0, 0, 0 },
5443 { "pco", 0, 0, 0, 0 },
5444 { "p", opt_chip, 0, 0, 0 },
5445 { "pcr", 0, 0, 0, 0 },
5446 { "pcs", 0, 0, 0, 0 },
5447 { "r", 0, 0, 0, 0 },
5448 { "quick", 0, &m68k_quick, 1, 0 },
5449 { "rel32", 0, &m68k_rel32, 1, 0 },
5450 { "s", opt_list, 0, 0, 0 },
5451 { "t", opt_list_symbols, 0, 0, 0 },
5452 { "w", 0, &flag_no_warnings, 0, 1 },
5453 { "x", 0, 0, 0, 0 }
5456 #define OPTCOUNT ((int) (sizeof opt_table / sizeof opt_table[0]))
5458 /* The MRI OPT pseudo-op. */
5460 static void
5461 s_opt (int ignore ATTRIBUTE_UNUSED)
5465 int t;
5466 char *s;
5467 char c;
5468 int i;
5469 const struct opt_action *o;
5471 SKIP_WHITESPACE ();
5473 t = 1;
5474 if (*input_line_pointer == '-')
5476 ++input_line_pointer;
5477 t = 0;
5479 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
5481 input_line_pointer += 2;
5482 t = 0;
5485 s = input_line_pointer;
5486 c = get_symbol_end ();
5488 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
5490 if (strcasecmp (s, o->name) == 0)
5492 if (o->pfn)
5494 /* Restore input_line_pointer now in case the option
5495 takes arguments. */
5496 *input_line_pointer = c;
5497 (*o->pfn) (o->arg, t);
5499 else if (o->pvar != NULL)
5501 if (! t && o->arg == o->notarg)
5502 as_bad (_("option `%s' may not be negated"), s);
5503 *input_line_pointer = c;
5504 *o->pvar = t ? o->arg : o->notarg;
5506 else
5507 *input_line_pointer = c;
5508 break;
5511 if (i >= OPTCOUNT)
5513 as_bad (_("option `%s' not recognized"), s);
5514 *input_line_pointer = c;
5517 while (*input_line_pointer++ == ',');
5519 /* Move back to terminating character. */
5520 --input_line_pointer;
5521 demand_empty_rest_of_line ();
5524 /* Skip ahead to a comma. This is used for OPT options which we do
5525 not support and which take arguments. */
5527 static void
5528 skip_to_comma (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5530 while (*input_line_pointer != ','
5531 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5532 ++input_line_pointer;
5535 /* Handle the OPT NEST=depth option. */
5537 static void
5538 opt_nest (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5540 if (*input_line_pointer != '=')
5542 as_bad (_("bad format of OPT NEST=depth"));
5543 return;
5546 ++input_line_pointer;
5547 max_macro_nest = get_absolute_expression ();
5550 /* Handle the OPT P=chip option. */
5552 static void
5553 opt_chip (int arg ATTRIBUTE_UNUSED, int on ATTRIBUTE_UNUSED)
5555 if (*input_line_pointer != '=')
5557 /* This is just OPT P, which we do not support. */
5558 return;
5561 ++input_line_pointer;
5562 mri_chip ();
5565 /* Handle the OPT S option. */
5567 static void
5568 opt_list (int arg ATTRIBUTE_UNUSED, int on)
5570 listing_list (on);
5573 /* Handle the OPT T option. */
5575 static void
5576 opt_list_symbols (int arg ATTRIBUTE_UNUSED, int on)
5578 if (on)
5579 listing |= LISTING_SYMBOLS;
5580 else
5581 listing &= ~LISTING_SYMBOLS;
5584 /* Handle the MRI REG pseudo-op. */
5586 static void
5587 s_reg (int ignore ATTRIBUTE_UNUSED)
5589 char *s;
5590 int c;
5591 struct m68k_op rop;
5592 int mask;
5593 char *stop = NULL;
5594 char stopc;
5596 if (line_label == NULL)
5598 as_bad (_("missing label"));
5599 ignore_rest_of_line ();
5600 return;
5603 if (flag_mri)
5604 stop = mri_comment_field (&stopc);
5606 SKIP_WHITESPACE ();
5608 s = input_line_pointer;
5609 while (ISALNUM (*input_line_pointer)
5610 #ifdef REGISTER_PREFIX
5611 || *input_line_pointer == REGISTER_PREFIX
5612 #endif
5613 || *input_line_pointer == '/'
5614 || *input_line_pointer == '-')
5615 ++input_line_pointer;
5616 c = *input_line_pointer;
5617 *input_line_pointer = '\0';
5619 if (m68k_ip_op (s, &rop) != 0)
5621 if (rop.error == NULL)
5622 as_bad (_("bad register list"));
5623 else
5624 as_bad (_("bad register list: %s"), rop.error);
5625 *input_line_pointer = c;
5626 ignore_rest_of_line ();
5627 return;
5630 *input_line_pointer = c;
5632 if (rop.mode == REGLST)
5633 mask = rop.mask;
5634 else if (rop.mode == DREG)
5635 mask = 1 << (rop.reg - DATA0);
5636 else if (rop.mode == AREG)
5637 mask = 1 << (rop.reg - ADDR0 + 8);
5638 else if (rop.mode == FPREG)
5639 mask = 1 << (rop.reg - FP0 + 16);
5640 else if (rop.mode == CONTROL
5641 && rop.reg == FPI)
5642 mask = 1 << 24;
5643 else if (rop.mode == CONTROL
5644 && rop.reg == FPS)
5645 mask = 1 << 25;
5646 else if (rop.mode == CONTROL
5647 && rop.reg == FPC)
5648 mask = 1 << 26;
5649 else
5651 as_bad (_("bad register list"));
5652 ignore_rest_of_line ();
5653 return;
5656 S_SET_SEGMENT (line_label, reg_section);
5657 S_SET_VALUE (line_label, ~mask);
5658 symbol_set_frag (line_label, &zero_address_frag);
5660 if (flag_mri)
5661 mri_comment_end (stop, stopc);
5663 demand_empty_rest_of_line ();
5666 /* This structure is used for the MRI SAVE and RESTORE pseudo-ops. */
5668 struct save_opts
5670 struct save_opts *next;
5671 int abspcadd;
5672 int symbols_case_sensitive;
5673 int keep_locals;
5674 int short_refs;
5675 int architecture;
5676 int chip;
5677 int quick;
5678 int rel32;
5679 int listing;
5680 int no_warnings;
5681 /* FIXME: We don't save OPT S. */
5684 /* This variable holds the stack of saved options. */
5686 static struct save_opts *save_stack;
5688 /* The MRI SAVE pseudo-op. */
5690 static void
5691 s_save (int ignore ATTRIBUTE_UNUSED)
5693 struct save_opts *s;
5695 s = (struct save_opts *) xmalloc (sizeof (struct save_opts));
5696 s->abspcadd = m68k_abspcadd;
5697 s->symbols_case_sensitive = symbols_case_sensitive;
5698 s->keep_locals = flag_keep_locals;
5699 s->short_refs = flag_short_refs;
5700 s->architecture = current_architecture;
5701 s->chip = current_chip;
5702 s->quick = m68k_quick;
5703 s->rel32 = m68k_rel32;
5704 s->listing = listing;
5705 s->no_warnings = flag_no_warnings;
5707 s->next = save_stack;
5708 save_stack = s;
5710 demand_empty_rest_of_line ();
5713 /* The MRI RESTORE pseudo-op. */
5715 static void
5716 s_restore (int ignore ATTRIBUTE_UNUSED)
5718 struct save_opts *s;
5720 if (save_stack == NULL)
5722 as_bad (_("restore without save"));
5723 ignore_rest_of_line ();
5724 return;
5727 s = save_stack;
5728 save_stack = s->next;
5730 m68k_abspcadd = s->abspcadd;
5731 symbols_case_sensitive = s->symbols_case_sensitive;
5732 flag_keep_locals = s->keep_locals;
5733 flag_short_refs = s->short_refs;
5734 current_architecture = s->architecture;
5735 current_chip = s->chip;
5736 m68k_quick = s->quick;
5737 m68k_rel32 = s->rel32;
5738 listing = s->listing;
5739 flag_no_warnings = s->no_warnings;
5741 free (s);
5743 demand_empty_rest_of_line ();
5746 /* Types of MRI structured control directives. */
5748 enum mri_control_type
5750 mri_for,
5751 mri_if,
5752 mri_repeat,
5753 mri_while
5756 /* This structure is used to stack the MRI structured control
5757 directives. */
5759 struct mri_control_info
5761 /* The directive within which this one is enclosed. */
5762 struct mri_control_info *outer;
5764 /* The type of directive. */
5765 enum mri_control_type type;
5767 /* Whether an ELSE has been in an IF. */
5768 int else_seen;
5770 /* The add or sub statement at the end of a FOR. */
5771 char *incr;
5773 /* The label of the top of a FOR or REPEAT loop. */
5774 char *top;
5776 /* The label to jump to for the next iteration, or the else
5777 expression of a conditional. */
5778 char *next;
5780 /* The label to jump to to break out of the loop, or the label past
5781 the end of a conditional. */
5782 char *bottom;
5785 /* The stack of MRI structured control directives. */
5787 static struct mri_control_info *mri_control_stack;
5789 /* The current MRI structured control directive index number, used to
5790 generate label names. */
5792 static int mri_control_index;
5794 /* Assemble an instruction for an MRI structured control directive. */
5796 static void
5797 mri_assemble (char *str)
5799 char *s;
5801 /* md_assemble expects the opcode to be in lower case. */
5802 for (s = str; *s != ' ' && *s != '\0'; s++)
5803 *s = TOLOWER (*s);
5805 md_assemble (str);
5808 /* Generate a new MRI label structured control directive label name. */
5810 static char *
5811 mri_control_label (void)
5813 char *n;
5815 n = (char *) xmalloc (20);
5816 sprintf (n, "%smc%d", FAKE_LABEL_NAME, mri_control_index);
5817 ++mri_control_index;
5818 return n;
5821 /* Create a new MRI structured control directive. */
5823 static struct mri_control_info *
5824 push_mri_control (enum mri_control_type type)
5826 struct mri_control_info *n;
5828 n = (struct mri_control_info *) xmalloc (sizeof (struct mri_control_info));
5830 n->type = type;
5831 n->else_seen = 0;
5832 if (type == mri_if || type == mri_while)
5833 n->top = NULL;
5834 else
5835 n->top = mri_control_label ();
5836 n->next = mri_control_label ();
5837 n->bottom = mri_control_label ();
5839 n->outer = mri_control_stack;
5840 mri_control_stack = n;
5842 return n;
5845 /* Pop off the stack of MRI structured control directives. */
5847 static void
5848 pop_mri_control (void)
5850 struct mri_control_info *n;
5852 n = mri_control_stack;
5853 mri_control_stack = n->outer;
5854 if (n->top != NULL)
5855 free (n->top);
5856 free (n->next);
5857 free (n->bottom);
5858 free (n);
5861 /* Recognize a condition code in an MRI structured control expression. */
5863 static int
5864 parse_mri_condition (int *pcc)
5866 char c1, c2;
5868 know (*input_line_pointer == '<');
5870 ++input_line_pointer;
5871 c1 = *input_line_pointer++;
5872 c2 = *input_line_pointer++;
5874 if (*input_line_pointer != '>')
5876 as_bad (_("syntax error in structured control directive"));
5877 return 0;
5880 ++input_line_pointer;
5881 SKIP_WHITESPACE ();
5883 c1 = TOLOWER (c1);
5884 c2 = TOLOWER (c2);
5886 *pcc = (c1 << 8) | c2;
5888 return 1;
5891 /* Parse a single operand in an MRI structured control expression. */
5893 static int
5894 parse_mri_control_operand (int *pcc, char **leftstart, char **leftstop,
5895 char **rightstart, char **rightstop)
5897 char *s;
5899 SKIP_WHITESPACE ();
5901 *pcc = -1;
5902 *leftstart = NULL;
5903 *leftstop = NULL;
5904 *rightstart = NULL;
5905 *rightstop = NULL;
5907 if (*input_line_pointer == '<')
5909 /* It's just a condition code. */
5910 return parse_mri_condition (pcc);
5913 /* Look ahead for the condition code. */
5914 for (s = input_line_pointer; *s != '\0'; ++s)
5916 if (*s == '<' && s[1] != '\0' && s[2] != '\0' && s[3] == '>')
5917 break;
5919 if (*s == '\0')
5921 as_bad (_("missing condition code in structured control directive"));
5922 return 0;
5925 *leftstart = input_line_pointer;
5926 *leftstop = s;
5927 if (*leftstop > *leftstart
5928 && ((*leftstop)[-1] == ' ' || (*leftstop)[-1] == '\t'))
5929 --*leftstop;
5931 input_line_pointer = s;
5932 if (! parse_mri_condition (pcc))
5933 return 0;
5935 /* Look ahead for AND or OR or end of line. */
5936 for (s = input_line_pointer; *s != '\0'; ++s)
5938 /* We must make sure we don't misinterpret AND/OR at the end of labels!
5939 if d0 <eq> #FOOAND and d1 <ne> #BAROR then
5940 ^^^ ^^ */
5941 if ((s == input_line_pointer
5942 || *(s-1) == ' '
5943 || *(s-1) == '\t')
5944 && ((strncasecmp (s, "AND", 3) == 0
5945 && (s[3] == '.' || ! is_part_of_name (s[3])))
5946 || (strncasecmp (s, "OR", 2) == 0
5947 && (s[2] == '.' || ! is_part_of_name (s[2])))))
5948 break;
5951 *rightstart = input_line_pointer;
5952 *rightstop = s;
5953 if (*rightstop > *rightstart
5954 && ((*rightstop)[-1] == ' ' || (*rightstop)[-1] == '\t'))
5955 --*rightstop;
5957 input_line_pointer = s;
5959 return 1;
5962 #define MCC(b1, b2) (((b1) << 8) | (b2))
5964 /* Swap the sense of a condition. This changes the condition so that
5965 it generates the same result when the operands are swapped. */
5967 static int
5968 swap_mri_condition (int cc)
5970 switch (cc)
5972 case MCC ('h', 'i'): return MCC ('c', 's');
5973 case MCC ('l', 's'): return MCC ('c', 'c');
5974 /* <HS> is an alias for <CC>. */
5975 case MCC ('h', 's'):
5976 case MCC ('c', 'c'): return MCC ('l', 's');
5977 /* <LO> is an alias for <CS>. */
5978 case MCC ('l', 'o'):
5979 case MCC ('c', 's'): return MCC ('h', 'i');
5980 case MCC ('p', 'l'): return MCC ('m', 'i');
5981 case MCC ('m', 'i'): return MCC ('p', 'l');
5982 case MCC ('g', 'e'): return MCC ('l', 'e');
5983 case MCC ('l', 't'): return MCC ('g', 't');
5984 case MCC ('g', 't'): return MCC ('l', 't');
5985 case MCC ('l', 'e'): return MCC ('g', 'e');
5986 /* Issue a warning for conditions we can not swap. */
5987 case MCC ('n', 'e'): return MCC ('n', 'e'); // no problem here
5988 case MCC ('e', 'q'): return MCC ('e', 'q'); // also no problem
5989 case MCC ('v', 'c'):
5990 case MCC ('v', 's'):
5991 default :
5992 as_warn (_("Condition <%c%c> in structured control directive can not be encoded correctly"),
5993 (char) (cc >> 8), (char) (cc));
5994 break;
5996 return cc;
5999 /* Reverse the sense of a condition. */
6001 static int
6002 reverse_mri_condition (int cc)
6004 switch (cc)
6006 case MCC ('h', 'i'): return MCC ('l', 's');
6007 case MCC ('l', 's'): return MCC ('h', 'i');
6008 /* <HS> is an alias for <CC> */
6009 case MCC ('h', 's'): return MCC ('l', 'o');
6010 case MCC ('c', 'c'): return MCC ('c', 's');
6011 /* <LO> is an alias for <CS> */
6012 case MCC ('l', 'o'): return MCC ('h', 's');
6013 case MCC ('c', 's'): return MCC ('c', 'c');
6014 case MCC ('n', 'e'): return MCC ('e', 'q');
6015 case MCC ('e', 'q'): return MCC ('n', 'e');
6016 case MCC ('v', 'c'): return MCC ('v', 's');
6017 case MCC ('v', 's'): return MCC ('v', 'c');
6018 case MCC ('p', 'l'): return MCC ('m', 'i');
6019 case MCC ('m', 'i'): return MCC ('p', 'l');
6020 case MCC ('g', 'e'): return MCC ('l', 't');
6021 case MCC ('l', 't'): return MCC ('g', 'e');
6022 case MCC ('g', 't'): return MCC ('l', 'e');
6023 case MCC ('l', 'e'): return MCC ('g', 't');
6025 return cc;
6028 /* Build an MRI structured control expression. This generates test
6029 and branch instructions. It goes to TRUELAB if the condition is
6030 true, and to FALSELAB if the condition is false. Exactly one of
6031 TRUELAB and FALSELAB will be NULL, meaning to fall through. QUAL
6032 is the size qualifier for the expression. EXTENT is the size to
6033 use for the branch. */
6035 static void
6036 build_mri_control_operand (int qual, int cc, char *leftstart, char *leftstop,
6037 char *rightstart, char *rightstop,
6038 const char *truelab, const char *falselab,
6039 int extent)
6041 char *buf;
6042 char *s;
6044 if (leftstart != NULL)
6046 struct m68k_op leftop, rightop;
6047 char c;
6049 /* Swap the compare operands, if necessary, to produce a legal
6050 m68k compare instruction. Comparing a register operand with
6051 a non-register operand requires the register to be on the
6052 right (cmp, cmpa). Comparing an immediate value with
6053 anything requires the immediate value to be on the left
6054 (cmpi). */
6056 c = *leftstop;
6057 *leftstop = '\0';
6058 (void) m68k_ip_op (leftstart, &leftop);
6059 *leftstop = c;
6061 c = *rightstop;
6062 *rightstop = '\0';
6063 (void) m68k_ip_op (rightstart, &rightop);
6064 *rightstop = c;
6066 if (rightop.mode == IMMED
6067 || ((leftop.mode == DREG || leftop.mode == AREG)
6068 && (rightop.mode != DREG && rightop.mode != AREG)))
6070 char *temp;
6072 /* Correct conditional handling:
6073 if #1 <lt> d0 then ;means if (1 < d0)
6075 endi
6077 should assemble to:
6079 cmp #1,d0 if we do *not* swap the operands
6080 bgt true we need the swapped condition!
6081 ble false
6082 true:
6084 false:
6086 temp = leftstart;
6087 leftstart = rightstart;
6088 rightstart = temp;
6089 temp = leftstop;
6090 leftstop = rightstop;
6091 rightstop = temp;
6093 else
6095 cc = swap_mri_condition (cc);
6099 if (truelab == NULL)
6101 cc = reverse_mri_condition (cc);
6102 truelab = falselab;
6105 if (leftstart != NULL)
6107 buf = (char *) xmalloc (20
6108 + (leftstop - leftstart)
6109 + (rightstop - rightstart));
6110 s = buf;
6111 *s++ = 'c';
6112 *s++ = 'm';
6113 *s++ = 'p';
6114 if (qual != '\0')
6115 *s++ = TOLOWER (qual);
6116 *s++ = ' ';
6117 memcpy (s, leftstart, leftstop - leftstart);
6118 s += leftstop - leftstart;
6119 *s++ = ',';
6120 memcpy (s, rightstart, rightstop - rightstart);
6121 s += rightstop - rightstart;
6122 *s = '\0';
6123 mri_assemble (buf);
6124 free (buf);
6127 buf = (char *) xmalloc (20 + strlen (truelab));
6128 s = buf;
6129 *s++ = 'b';
6130 *s++ = cc >> 8;
6131 *s++ = cc & 0xff;
6132 if (extent != '\0')
6133 *s++ = TOLOWER (extent);
6134 *s++ = ' ';
6135 strcpy (s, truelab);
6136 mri_assemble (buf);
6137 free (buf);
6140 /* Parse an MRI structured control expression. This generates test
6141 and branch instructions. STOP is where the expression ends. It
6142 goes to TRUELAB if the condition is true, and to FALSELAB if the
6143 condition is false. Exactly one of TRUELAB and FALSELAB will be
6144 NULL, meaning to fall through. QUAL is the size qualifier for the
6145 expression. EXTENT is the size to use for the branch. */
6147 static void
6148 parse_mri_control_expression (char *stop, int qual, const char *truelab,
6149 const char *falselab, int extent)
6151 int c;
6152 int cc;
6153 char *leftstart;
6154 char *leftstop;
6155 char *rightstart;
6156 char *rightstop;
6158 c = *stop;
6159 *stop = '\0';
6161 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6162 &rightstart, &rightstop))
6164 *stop = c;
6165 return;
6168 if (strncasecmp (input_line_pointer, "AND", 3) == 0)
6170 const char *flab;
6172 if (falselab != NULL)
6173 flab = falselab;
6174 else
6175 flab = mri_control_label ();
6177 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6178 rightstop, (const char *) NULL, flab, extent);
6180 input_line_pointer += 3;
6181 if (*input_line_pointer != '.'
6182 || input_line_pointer[1] == '\0')
6183 qual = '\0';
6184 else
6186 qual = input_line_pointer[1];
6187 input_line_pointer += 2;
6190 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6191 &rightstart, &rightstop))
6193 *stop = c;
6194 return;
6197 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6198 rightstop, truelab, falselab, extent);
6200 if (falselab == NULL)
6201 colon (flab);
6203 else if (strncasecmp (input_line_pointer, "OR", 2) == 0)
6205 const char *tlab;
6207 if (truelab != NULL)
6208 tlab = truelab;
6209 else
6210 tlab = mri_control_label ();
6212 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6213 rightstop, tlab, (const char *) NULL, extent);
6215 input_line_pointer += 2;
6216 if (*input_line_pointer != '.'
6217 || input_line_pointer[1] == '\0')
6218 qual = '\0';
6219 else
6221 qual = input_line_pointer[1];
6222 input_line_pointer += 2;
6225 if (! parse_mri_control_operand (&cc, &leftstart, &leftstop,
6226 &rightstart, &rightstop))
6228 *stop = c;
6229 return;
6232 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6233 rightstop, truelab, falselab, extent);
6235 if (truelab == NULL)
6236 colon (tlab);
6238 else
6240 build_mri_control_operand (qual, cc, leftstart, leftstop, rightstart,
6241 rightstop, truelab, falselab, extent);
6244 *stop = c;
6245 if (input_line_pointer != stop)
6246 as_bad (_("syntax error in structured control directive"));
6249 /* Handle the MRI IF pseudo-op. This may be a structured control
6250 directive, or it may be a regular assembler conditional, depending
6251 on its operands. */
6253 static void
6254 s_mri_if (int qual)
6256 char *s;
6257 int c;
6258 struct mri_control_info *n;
6260 /* A structured control directive must end with THEN with an
6261 optional qualifier. */
6262 s = input_line_pointer;
6263 /* We only accept '*' as introduction of comments if preceded by white space
6264 or at first column of a line (I think this can't actually happen here?)
6265 This is important when assembling:
6266 if d0 <ne> 12(a0,d0*2) then
6267 if d0 <ne> #CONST*20 then. */
6268 while (! (is_end_of_line[(unsigned char) *s]
6269 || (flag_mri
6270 && *s == '*'
6271 && (s == input_line_pointer
6272 || *(s-1) == ' '
6273 || *(s-1) == '\t'))))
6274 ++s;
6275 --s;
6276 while (s > input_line_pointer && (*s == ' ' || *s == '\t'))
6277 --s;
6279 if (s - input_line_pointer > 1
6280 && s[-1] == '.')
6281 s -= 2;
6283 if (s - input_line_pointer < 3
6284 || strncasecmp (s - 3, "THEN", 4) != 0)
6286 if (qual != '\0')
6288 as_bad (_("missing then"));
6289 ignore_rest_of_line ();
6290 return;
6293 /* It's a conditional. */
6294 s_if (O_ne);
6295 return;
6298 /* Since this might be a conditional if, this pseudo-op will be
6299 called even if we are supported to be ignoring input. Double
6300 check now. Clobber *input_line_pointer so that ignore_input
6301 thinks that this is not a special pseudo-op. */
6302 c = *input_line_pointer;
6303 *input_line_pointer = 0;
6304 if (ignore_input ())
6306 *input_line_pointer = c;
6307 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6308 ++input_line_pointer;
6309 demand_empty_rest_of_line ();
6310 return;
6312 *input_line_pointer = c;
6314 n = push_mri_control (mri_if);
6316 parse_mri_control_expression (s - 3, qual, (const char *) NULL,
6317 n->next, s[1] == '.' ? s[2] : '\0');
6319 if (s[1] == '.')
6320 input_line_pointer = s + 3;
6321 else
6322 input_line_pointer = s + 1;
6324 if (flag_mri)
6326 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6327 ++input_line_pointer;
6330 demand_empty_rest_of_line ();
6333 /* Handle the MRI else pseudo-op. If we are currently doing an MRI
6334 structured IF, associate the ELSE with the IF. Otherwise, assume
6335 it is a conditional else. */
6337 static void
6338 s_mri_else (int qual)
6340 int c;
6341 char *buf;
6342 char q[2];
6344 if (qual == '\0'
6345 && (mri_control_stack == NULL
6346 || mri_control_stack->type != mri_if
6347 || mri_control_stack->else_seen))
6349 s_else (0);
6350 return;
6353 c = *input_line_pointer;
6354 *input_line_pointer = 0;
6355 if (ignore_input ())
6357 *input_line_pointer = c;
6358 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6359 ++input_line_pointer;
6360 demand_empty_rest_of_line ();
6361 return;
6363 *input_line_pointer = c;
6365 if (mri_control_stack == NULL
6366 || mri_control_stack->type != mri_if
6367 || mri_control_stack->else_seen)
6369 as_bad (_("else without matching if"));
6370 ignore_rest_of_line ();
6371 return;
6374 mri_control_stack->else_seen = 1;
6376 buf = (char *) xmalloc (20 + strlen (mri_control_stack->bottom));
6377 q[0] = TOLOWER (qual);
6378 q[1] = '\0';
6379 sprintf (buf, "bra%s %s", q, mri_control_stack->bottom);
6380 mri_assemble (buf);
6381 free (buf);
6383 colon (mri_control_stack->next);
6385 if (flag_mri)
6387 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6388 ++input_line_pointer;
6391 demand_empty_rest_of_line ();
6394 /* Handle the MRI ENDI pseudo-op. */
6396 static void
6397 s_mri_endi (int ignore ATTRIBUTE_UNUSED)
6399 if (mri_control_stack == NULL
6400 || mri_control_stack->type != mri_if)
6402 as_bad (_("endi without matching if"));
6403 ignore_rest_of_line ();
6404 return;
6407 /* ignore_input will not return true for ENDI, so we don't need to
6408 worry about checking it again here. */
6410 if (! mri_control_stack->else_seen)
6411 colon (mri_control_stack->next);
6412 colon (mri_control_stack->bottom);
6414 pop_mri_control ();
6416 if (flag_mri)
6418 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6419 ++input_line_pointer;
6422 demand_empty_rest_of_line ();
6425 /* Handle the MRI BREAK pseudo-op. */
6427 static void
6428 s_mri_break (int extent)
6430 struct mri_control_info *n;
6431 char *buf;
6432 char ex[2];
6434 n = mri_control_stack;
6435 while (n != NULL
6436 && n->type != mri_for
6437 && n->type != mri_repeat
6438 && n->type != mri_while)
6439 n = n->outer;
6440 if (n == NULL)
6442 as_bad (_("break outside of structured loop"));
6443 ignore_rest_of_line ();
6444 return;
6447 buf = (char *) xmalloc (20 + strlen (n->bottom));
6448 ex[0] = TOLOWER (extent);
6449 ex[1] = '\0';
6450 sprintf (buf, "bra%s %s", ex, n->bottom);
6451 mri_assemble (buf);
6452 free (buf);
6454 if (flag_mri)
6456 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6457 ++input_line_pointer;
6460 demand_empty_rest_of_line ();
6463 /* Handle the MRI NEXT pseudo-op. */
6465 static void
6466 s_mri_next (int extent)
6468 struct mri_control_info *n;
6469 char *buf;
6470 char ex[2];
6472 n = mri_control_stack;
6473 while (n != NULL
6474 && n->type != mri_for
6475 && n->type != mri_repeat
6476 && n->type != mri_while)
6477 n = n->outer;
6478 if (n == NULL)
6480 as_bad (_("next outside of structured loop"));
6481 ignore_rest_of_line ();
6482 return;
6485 buf = (char *) xmalloc (20 + strlen (n->next));
6486 ex[0] = TOLOWER (extent);
6487 ex[1] = '\0';
6488 sprintf (buf, "bra%s %s", ex, n->next);
6489 mri_assemble (buf);
6490 free (buf);
6492 if (flag_mri)
6494 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6495 ++input_line_pointer;
6498 demand_empty_rest_of_line ();
6501 /* Handle the MRI FOR pseudo-op. */
6503 static void
6504 s_mri_for (int qual)
6506 const char *varstart, *varstop;
6507 const char *initstart, *initstop;
6508 const char *endstart, *endstop;
6509 const char *bystart, *bystop;
6510 int up;
6511 int by;
6512 int extent;
6513 struct mri_control_info *n;
6514 char *buf;
6515 char *s;
6516 char ex[2];
6518 /* The syntax is
6519 FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
6522 SKIP_WHITESPACE ();
6523 varstart = input_line_pointer;
6525 /* Look for the '='. */
6526 while (! is_end_of_line[(unsigned char) *input_line_pointer]
6527 && *input_line_pointer != '=')
6528 ++input_line_pointer;
6529 if (*input_line_pointer != '=')
6531 as_bad (_("missing ="));
6532 ignore_rest_of_line ();
6533 return;
6536 varstop = input_line_pointer;
6537 if (varstop > varstart
6538 && (varstop[-1] == ' ' || varstop[-1] == '\t'))
6539 --varstop;
6541 ++input_line_pointer;
6543 initstart = input_line_pointer;
6545 /* Look for TO or DOWNTO. */
6546 up = 1;
6547 initstop = NULL;
6548 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6550 if (strncasecmp (input_line_pointer, "TO", 2) == 0
6551 && ! is_part_of_name (input_line_pointer[2]))
6553 initstop = input_line_pointer;
6554 input_line_pointer += 2;
6555 break;
6557 if (strncasecmp (input_line_pointer, "DOWNTO", 6) == 0
6558 && ! is_part_of_name (input_line_pointer[6]))
6560 initstop = input_line_pointer;
6561 up = 0;
6562 input_line_pointer += 6;
6563 break;
6565 ++input_line_pointer;
6567 if (initstop == NULL)
6569 as_bad (_("missing to or downto"));
6570 ignore_rest_of_line ();
6571 return;
6573 if (initstop > initstart
6574 && (initstop[-1] == ' ' || initstop[-1] == '\t'))
6575 --initstop;
6577 SKIP_WHITESPACE ();
6578 endstart = input_line_pointer;
6580 /* Look for BY or DO. */
6581 by = 0;
6582 endstop = NULL;
6583 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6585 if (strncasecmp (input_line_pointer, "BY", 2) == 0
6586 && ! is_part_of_name (input_line_pointer[2]))
6588 endstop = input_line_pointer;
6589 by = 1;
6590 input_line_pointer += 2;
6591 break;
6593 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6594 && (input_line_pointer[2] == '.'
6595 || ! is_part_of_name (input_line_pointer[2])))
6597 endstop = input_line_pointer;
6598 input_line_pointer += 2;
6599 break;
6601 ++input_line_pointer;
6603 if (endstop == NULL)
6605 as_bad (_("missing do"));
6606 ignore_rest_of_line ();
6607 return;
6609 if (endstop > endstart
6610 && (endstop[-1] == ' ' || endstop[-1] == '\t'))
6611 --endstop;
6613 if (! by)
6615 bystart = "#1";
6616 bystop = bystart + 2;
6618 else
6620 SKIP_WHITESPACE ();
6621 bystart = input_line_pointer;
6623 /* Look for DO. */
6624 bystop = NULL;
6625 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6627 if (strncasecmp (input_line_pointer, "DO", 2) == 0
6628 && (input_line_pointer[2] == '.'
6629 || ! is_part_of_name (input_line_pointer[2])))
6631 bystop = input_line_pointer;
6632 input_line_pointer += 2;
6633 break;
6635 ++input_line_pointer;
6637 if (bystop == NULL)
6639 as_bad (_("missing do"));
6640 ignore_rest_of_line ();
6641 return;
6643 if (bystop > bystart
6644 && (bystop[-1] == ' ' || bystop[-1] == '\t'))
6645 --bystop;
6648 if (*input_line_pointer != '.')
6649 extent = '\0';
6650 else
6652 extent = input_line_pointer[1];
6653 input_line_pointer += 2;
6656 /* We have fully parsed the FOR operands. Now build the loop. */
6657 n = push_mri_control (mri_for);
6659 buf = (char *) xmalloc (50 + (input_line_pointer - varstart));
6661 /* Move init,var. */
6662 s = buf;
6663 *s++ = 'm';
6664 *s++ = 'o';
6665 *s++ = 'v';
6666 *s++ = 'e';
6667 if (qual != '\0')
6668 *s++ = TOLOWER (qual);
6669 *s++ = ' ';
6670 memcpy (s, initstart, initstop - initstart);
6671 s += initstop - initstart;
6672 *s++ = ',';
6673 memcpy (s, varstart, varstop - varstart);
6674 s += varstop - varstart;
6675 *s = '\0';
6676 mri_assemble (buf);
6678 colon (n->top);
6680 /* cmp end,var. */
6681 s = buf;
6682 *s++ = 'c';
6683 *s++ = 'm';
6684 *s++ = 'p';
6685 if (qual != '\0')
6686 *s++ = TOLOWER (qual);
6687 *s++ = ' ';
6688 memcpy (s, endstart, endstop - endstart);
6689 s += endstop - endstart;
6690 *s++ = ',';
6691 memcpy (s, varstart, varstop - varstart);
6692 s += varstop - varstart;
6693 *s = '\0';
6694 mri_assemble (buf);
6696 /* bcc bottom. */
6697 ex[0] = TOLOWER (extent);
6698 ex[1] = '\0';
6699 if (up)
6700 sprintf (buf, "blt%s %s", ex, n->bottom);
6701 else
6702 sprintf (buf, "bgt%s %s", ex, n->bottom);
6703 mri_assemble (buf);
6705 /* Put together the add or sub instruction used by ENDF. */
6706 s = buf;
6707 if (up)
6708 strcpy (s, "add");
6709 else
6710 strcpy (s, "sub");
6711 s += 3;
6712 if (qual != '\0')
6713 *s++ = TOLOWER (qual);
6714 *s++ = ' ';
6715 memcpy (s, bystart, bystop - bystart);
6716 s += bystop - bystart;
6717 *s++ = ',';
6718 memcpy (s, varstart, varstop - varstart);
6719 s += varstop - varstart;
6720 *s = '\0';
6721 n->incr = buf;
6723 if (flag_mri)
6725 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6726 ++input_line_pointer;
6729 demand_empty_rest_of_line ();
6732 /* Handle the MRI ENDF pseudo-op. */
6734 static void
6735 s_mri_endf (int ignore ATTRIBUTE_UNUSED)
6737 if (mri_control_stack == NULL
6738 || mri_control_stack->type != mri_for)
6740 as_bad (_("endf without for"));
6741 ignore_rest_of_line ();
6742 return;
6745 colon (mri_control_stack->next);
6747 mri_assemble (mri_control_stack->incr);
6749 sprintf (mri_control_stack->incr, "bra %s", mri_control_stack->top);
6750 mri_assemble (mri_control_stack->incr);
6752 free (mri_control_stack->incr);
6754 colon (mri_control_stack->bottom);
6756 pop_mri_control ();
6758 if (flag_mri)
6760 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6761 ++input_line_pointer;
6764 demand_empty_rest_of_line ();
6767 /* Handle the MRI REPEAT pseudo-op. */
6769 static void
6770 s_mri_repeat (int ignore ATTRIBUTE_UNUSED)
6772 struct mri_control_info *n;
6774 n = push_mri_control (mri_repeat);
6775 colon (n->top);
6776 if (flag_mri)
6778 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6779 ++input_line_pointer;
6781 demand_empty_rest_of_line ();
6784 /* Handle the MRI UNTIL pseudo-op. */
6786 static void
6787 s_mri_until (int qual)
6789 char *s;
6791 if (mri_control_stack == NULL
6792 || mri_control_stack->type != mri_repeat)
6794 as_bad (_("until without repeat"));
6795 ignore_rest_of_line ();
6796 return;
6799 colon (mri_control_stack->next);
6801 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
6804 parse_mri_control_expression (s, qual, (const char *) NULL,
6805 mri_control_stack->top, '\0');
6807 colon (mri_control_stack->bottom);
6809 input_line_pointer = s;
6811 pop_mri_control ();
6813 if (flag_mri)
6815 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6816 ++input_line_pointer;
6819 demand_empty_rest_of_line ();
6822 /* Handle the MRI WHILE pseudo-op. */
6824 static void
6825 s_mri_while (int qual)
6827 char *s;
6829 struct mri_control_info *n;
6831 s = input_line_pointer;
6832 /* We only accept '*' as introduction of comments if preceded by white space
6833 or at first column of a line (I think this can't actually happen here?)
6834 This is important when assembling:
6835 while d0 <ne> 12(a0,d0*2) do
6836 while d0 <ne> #CONST*20 do. */
6837 while (! (is_end_of_line[(unsigned char) *s]
6838 || (flag_mri
6839 && *s == '*'
6840 && (s == input_line_pointer
6841 || *(s-1) == ' '
6842 || *(s-1) == '\t'))))
6843 s++;
6844 --s;
6845 while (*s == ' ' || *s == '\t')
6846 --s;
6847 if (s - input_line_pointer > 1
6848 && s[-1] == '.')
6849 s -= 2;
6850 if (s - input_line_pointer < 2
6851 || strncasecmp (s - 1, "DO", 2) != 0)
6853 as_bad (_("missing do"));
6854 ignore_rest_of_line ();
6855 return;
6858 n = push_mri_control (mri_while);
6860 colon (n->next);
6862 parse_mri_control_expression (s - 1, qual, (const char *) NULL, n->bottom,
6863 s[1] == '.' ? s[2] : '\0');
6865 input_line_pointer = s + 1;
6866 if (*input_line_pointer == '.')
6867 input_line_pointer += 2;
6869 if (flag_mri)
6871 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6872 ++input_line_pointer;
6875 demand_empty_rest_of_line ();
6878 /* Handle the MRI ENDW pseudo-op. */
6880 static void
6881 s_mri_endw (int ignore ATTRIBUTE_UNUSED)
6883 char *buf;
6885 if (mri_control_stack == NULL
6886 || mri_control_stack->type != mri_while)
6888 as_bad (_("endw without while"));
6889 ignore_rest_of_line ();
6890 return;
6893 buf = (char *) xmalloc (20 + strlen (mri_control_stack->next));
6894 sprintf (buf, "bra %s", mri_control_stack->next);
6895 mri_assemble (buf);
6896 free (buf);
6898 colon (mri_control_stack->bottom);
6900 pop_mri_control ();
6902 if (flag_mri)
6904 while (! is_end_of_line[(unsigned char) *input_line_pointer])
6905 ++input_line_pointer;
6908 demand_empty_rest_of_line ();
6911 /* md_parse_option
6912 Invocation line includes a switch not recognized by the base assembler.
6913 See if it's a processor-specific option. These are:
6915 -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
6916 -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
6917 Select the architecture. Instructions or features not
6918 supported by the selected architecture cause fatal
6919 errors. More than one may be specified. The default is
6920 -m68020 -m68851 -m68881. Note that -m68008 is a synonym
6921 for -m68000, and -m68882 is a synonym for -m68881.
6922 -[A]m[c]no-68851, -[A]m[c]no-68881
6923 Don't accept 688?1 instructions. (The "c" is kind of silly,
6924 so don't use or document it, but that's the way the parsing
6925 works).
6927 -pic Indicates PIC.
6928 -k Indicates PIC. (Sun 3 only.)
6929 --pcrel
6930 Never turn PC-relative branches into absolute jumps.
6931 --bitwise-or
6932 Permit `|' to be used in expressions. */
6934 #ifdef OBJ_ELF
6935 const char *md_shortopts = "lSA:m:kQ:V";
6936 #else
6937 const char *md_shortopts = "lSA:m:k";
6938 #endif
6940 struct option md_longopts[] = {
6941 #define OPTION_PIC (OPTION_MD_BASE)
6942 {"pic", no_argument, NULL, OPTION_PIC},
6943 #define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
6944 {"register-prefix-optional", no_argument, NULL,
6945 OPTION_REGISTER_PREFIX_OPTIONAL},
6946 #define OPTION_BITWISE_OR (OPTION_MD_BASE + 2)
6947 {"bitwise-or", no_argument, NULL, OPTION_BITWISE_OR},
6948 #define OPTION_BASE_SIZE_DEFAULT_16 (OPTION_MD_BASE + 3)
6949 {"base-size-default-16", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_16},
6950 #define OPTION_BASE_SIZE_DEFAULT_32 (OPTION_MD_BASE + 4)
6951 {"base-size-default-32", no_argument, NULL, OPTION_BASE_SIZE_DEFAULT_32},
6952 #define OPTION_DISP_SIZE_DEFAULT_16 (OPTION_MD_BASE + 5)
6953 {"disp-size-default-16", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_16},
6954 #define OPTION_DISP_SIZE_DEFAULT_32 (OPTION_MD_BASE + 6)
6955 {"disp-size-default-32", no_argument, NULL, OPTION_DISP_SIZE_DEFAULT_32},
6956 #define OPTION_PCREL (OPTION_MD_BASE + 7)
6957 {"pcrel", no_argument, NULL, OPTION_PCREL},
6958 {NULL, no_argument, NULL, 0}
6960 size_t md_longopts_size = sizeof (md_longopts);
6963 md_parse_option (int c, char *arg)
6965 switch (c)
6967 case 'l': /* -l means keep external to 2 bit offset
6968 rather than 16 bit one. */
6969 flag_short_refs = 1;
6970 break;
6972 case 'S': /* -S means that jbsr's always turn into
6973 jsr's. */
6974 flag_long_jumps = 1;
6975 break;
6977 case OPTION_PCREL: /* --pcrel means never turn PC-relative
6978 branches into absolute jumps. */
6979 flag_keep_pcrel = 1;
6980 break;
6982 case 'A':
6983 if (*arg == 'm')
6984 arg++;
6985 /* Intentional fall-through. */
6986 case 'm':
6988 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
6990 int i;
6991 unsigned long arch;
6993 arg += 3;
6994 if (*arg == 'm')
6996 arg++;
6997 if (arg[0] == 'c' && arg[1] == '6')
6998 arg++;
7000 for (i = 0; i < n_archs; i++)
7001 if (!strcmp (arg, archs[i].name))
7002 break;
7003 if (i == n_archs)
7004 return 0;
7006 arch = archs[i].arch;
7007 if (arch == m68881)
7008 no_68881 = 1;
7009 else if (arch == m68851)
7010 no_68851 = 1;
7011 else
7012 return 0;
7014 else
7016 int i;
7018 if (arg[0] == 'c' && arg[1] == '6')
7019 arg++;
7021 for (i = 0; i < n_archs; i++)
7022 if (!strcmp (arg, archs[i].name))
7024 unsigned long arch = archs[i].arch;
7026 if (cpu_of_arch (arch))
7027 /* It's a cpu spec. */
7029 current_architecture &= ~m68000up;
7030 current_architecture |= arch;
7031 current_chip = archs[i].chip;
7033 else if (arch == m68881)
7035 current_architecture |= m68881;
7036 no_68881 = 0;
7038 else if (arch == m68851)
7040 current_architecture |= m68851;
7041 no_68851 = 0;
7043 else
7044 /* ??? */
7045 abort ();
7046 break;
7048 if (i == n_archs)
7050 as_bad (_("unrecognized architecture specification `%s'"), arg);
7051 return 0;
7054 break;
7056 case OPTION_PIC:
7057 case 'k':
7058 flag_want_pic = 1;
7059 break; /* -pic, Position Independent Code. */
7061 case OPTION_REGISTER_PREFIX_OPTIONAL:
7062 flag_reg_prefix_optional = 1;
7063 reg_prefix_optional_seen = 1;
7064 break;
7066 /* -V: SVR4 argument to print version ID. */
7067 case 'V':
7068 print_version_id ();
7069 break;
7071 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
7072 should be emitted or not. FIXME: Not implemented. */
7073 case 'Q':
7074 break;
7076 case OPTION_BITWISE_OR:
7078 char *n, *t;
7079 const char *s;
7081 n = (char *) xmalloc (strlen (m68k_comment_chars) + 1);
7082 t = n;
7083 for (s = m68k_comment_chars; *s != '\0'; s++)
7084 if (*s != '|')
7085 *t++ = *s;
7086 *t = '\0';
7087 m68k_comment_chars = n;
7089 break;
7091 case OPTION_BASE_SIZE_DEFAULT_16:
7092 m68k_index_width_default = SIZE_WORD;
7093 break;
7095 case OPTION_BASE_SIZE_DEFAULT_32:
7096 m68k_index_width_default = SIZE_LONG;
7097 break;
7099 case OPTION_DISP_SIZE_DEFAULT_16:
7100 m68k_rel32 = 0;
7101 m68k_rel32_from_cmdline = 1;
7102 break;
7104 case OPTION_DISP_SIZE_DEFAULT_32:
7105 m68k_rel32 = 1;
7106 m68k_rel32_from_cmdline = 1;
7107 break;
7109 default:
7110 return 0;
7113 return 1;
7116 void
7117 md_show_usage (FILE *stream)
7119 const char *default_cpu = TARGET_CPU;
7120 int i;
7121 unsigned int default_arch;
7123 /* Get the canonical name for the default target CPU. */
7124 if (*default_cpu == 'm')
7125 default_cpu++;
7126 for (i = 0; i < n_archs; i++)
7128 if (strcasecmp (default_cpu, archs[i].name) == 0)
7130 default_arch = archs[i].arch;
7131 for (i = 0; i < n_archs; i++)
7133 if (archs[i].arch == default_arch
7134 && !archs[i].alias)
7136 default_cpu = archs[i].name;
7137 break;
7143 fprintf (stream, _("\
7144 680X0 options:\n\
7145 -l use 1 word for refs to undefined symbols [default 2]\n\
7146 -m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060 |\n\
7147 -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360 | -mcpu32 |\n\
7148 -m5200 | -m5202 | -m5204 | -m5206 | -m5206e | -m521x | -m5249 |\n\
7149 -m528x | -m5307 | -m5407 | -m547x | -m548x | -mcfv4 | -mcfv4e\n\
7150 specify variant of 680X0 architecture [default %s]\n\
7151 -m68881 | -m68882 | -mno-68881 | -mno-68882\n\
7152 target has/lacks floating-point coprocessor\n\
7153 [default yes for 68020, 68030, and cpu32]\n"),
7154 default_cpu);
7155 fprintf (stream, _("\
7156 -m68851 | -mno-68851\n\
7157 target has/lacks memory-management unit coprocessor\n\
7158 [default yes for 68020 and up]\n\
7159 -pic, -k generate position independent code\n\
7160 -S turn jbsr into jsr\n\
7161 --pcrel never turn PC-relative branches into absolute jumps\n\
7162 --register-prefix-optional\n\
7163 recognize register names without prefix character\n\
7164 --bitwise-or do not treat `|' as a comment character\n"));
7165 fprintf (stream, _("\
7166 --base-size-default-16 base reg without size is 16 bits\n\
7167 --base-size-default-32 base reg without size is 32 bits (default)\n\
7168 --disp-size-default-16 displacement with unknown size is 16 bits\n\
7169 --disp-size-default-32 displacement with unknown size is 32 bits (default)\n"));
7172 #ifdef TEST2
7174 /* TEST2: Test md_assemble() */
7175 /* Warning, this routine probably doesn't work anymore. */
7177 main (void)
7179 struct m68k_it the_ins;
7180 char buf[120];
7181 char *cp;
7182 int n;
7184 m68k_ip_begin ();
7185 for (;;)
7187 if (!gets (buf) || !*buf)
7188 break;
7189 if (buf[0] == '|' || buf[1] == '.')
7190 continue;
7191 for (cp = buf; *cp; cp++)
7192 if (*cp == '\t')
7193 *cp = ' ';
7194 if (is_label (buf))
7195 continue;
7196 memset (&the_ins, '\0', sizeof (the_ins));
7197 m68k_ip (&the_ins, buf);
7198 if (the_ins.error)
7200 printf (_("Error %s in %s\n"), the_ins.error, buf);
7202 else
7204 printf (_("Opcode(%d.%s): "), the_ins.numo, the_ins.args);
7205 for (n = 0; n < the_ins.numo; n++)
7206 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
7207 printf (" ");
7208 print_the_insn (&the_ins.opcode[0], stdout);
7209 (void) putchar ('\n');
7211 for (n = 0; n < strlen (the_ins.args) / 2; n++)
7213 if (the_ins.operands[n].error)
7215 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
7216 continue;
7218 printf ("mode %d, reg %d, ", the_ins.operands[n].mode,
7219 the_ins.operands[n].reg);
7220 if (the_ins.operands[n].b_const)
7221 printf ("Constant: '%.*s', ",
7222 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const,
7223 the_ins.operands[n].b_const);
7224 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg,
7225 the_ins.operands[n].isiz, the_ins.operands[n].imul);
7226 if (the_ins.operands[n].b_iadd)
7227 printf ("Iadd: '%.*s',",
7228 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd,
7229 the_ins.operands[n].b_iadd);
7230 putchar ('\n');
7233 m68k_ip_end ();
7234 return 0;
7238 is_label (char *str)
7240 while (*str == ' ')
7241 str++;
7242 while (*str && *str != ' ')
7243 str++;
7244 if (str[-1] == ':' || str[1] == '=')
7245 return 1;
7246 return 0;
7249 #endif
7251 /* Possible states for relaxation:
7253 0 0 branch offset byte (bra, etc)
7254 0 1 word
7255 0 2 long
7257 1 0 indexed offsets byte a0@(32,d4:w:1) etc
7258 1 1 word
7259 1 2 long
7261 2 0 two-offset index word-word a0@(32,d4)@(45) etc
7262 2 1 word-long
7263 2 2 long-word
7264 2 3 long-long
7268 /* We have no need to default values of symbols. */
7270 symbolS *
7271 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
7273 return 0;
7276 /* Round up a section size to the appropriate boundary. */
7277 valueT
7278 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
7280 #ifdef OBJ_AOUT
7281 /* For a.out, force the section size to be aligned. If we don't do
7282 this, BFD will align it for us, but it will not write out the
7283 final bytes of the section. This may be a bug in BFD, but it is
7284 easier to fix it here since that is how the other a.out targets
7285 work. */
7286 int align;
7288 align = bfd_get_section_alignment (stdoutput, segment);
7289 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
7290 #endif
7292 return size;
7295 /* Exactly what point is a PC-relative offset relative TO?
7296 On the 68k, it is relative to the address of the first extension
7297 word. The difference between the addresses of the offset and the
7298 first extension word is stored in fx_pcrel_adjust. */
7299 long
7300 md_pcrel_from (fixS *fixP)
7302 int adjust;
7304 /* Because fx_pcrel_adjust is a char, and may be unsigned, we explicitly
7305 sign extend the value here. */
7306 adjust = ((fixP->fx_pcrel_adjust & 0xff) ^ 0x80) - 0x80;
7307 if (adjust == 64)
7308 adjust = -1;
7309 return fixP->fx_where + fixP->fx_frag->fr_address - adjust;
7312 #ifdef OBJ_ELF
7313 void
7314 m68k_elf_final_processing (void)
7316 /* Set file-specific flags if this is a cpu32 processor. */
7317 if (arch_coldfire_fpu (current_architecture))
7318 elf_elfheader (stdoutput)->e_flags |= EF_CFV4E;
7319 if (cpu_of_arch (current_architecture) & cpu32)
7320 elf_elfheader (stdoutput)->e_flags |= EF_CPU32;
7321 else if ((cpu_of_arch (current_architecture) & m68000up)
7322 && !(cpu_of_arch (current_architecture) & m68020up))
7323 elf_elfheader (stdoutput)->e_flags |= EF_M68000;
7325 #endif
7328 tc_m68k_regname_to_dw2regnum (const char *regname)
7330 unsigned int regnum;
7331 static const char *const regnames[] =
7333 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
7334 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
7335 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
7336 "pc"
7339 for (regnum = 0; regnum < ARRAY_SIZE (regnames); regnum++)
7340 if (strcmp (regname, regnames[regnum]) == 0)
7341 return regnum;
7343 return -1;
7346 void
7347 tc_m68k_frame_initial_instructions (void)
7349 static int sp_regno = -1;
7351 if (sp_regno < 0)
7352 sp_regno = tc_m68k_regname_to_dw2regnum ("sp");
7354 cfi_add_CFA_def_cfa (sp_regno, -DWARF2_CIE_DATA_ALIGNMENT);
7355 cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, DWARF2_CIE_DATA_ALIGNMENT);