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