* gas/mri/char.d: Fix for little endian machines.
[deliverable/binutils-gdb.git] / gas / config / tc-m68k.c
CommitLineData
a1c7c0f3
ILT
1/* tc-m68k.c -- Assemble for the m68k family
2 Copyright (C) 1987, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
6d27d3a2 3
a39116f1 4 This file is part of GAS, the GNU Assembler.
6d27d3a2 5
a39116f1
RP
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
6d27d3a2 10
a39116f1
RP
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
6d27d3a2 15
a39116f1 16 You should have received a copy of the GNU General Public License
a1c7c0f3
ILT
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
fecd2382
RP
20
21#include <ctype.h>
f8701a3f 22#define NO_RELOC 0
fecd2382 23#include "as.h"
fecd2382
RP
24#include "obstack.h"
25
e0982afe 26#include "opcode/m68k.h"
a1c7c0f3 27#include "m68k-parse.h"
3ad9ec6a 28
fecd2382
RP
29/* This array holds the chars that always start a comment. If the
30 pre-processor is disabled, these aren't very useful */
5f8cb05e
ILT
31#ifdef OBJ_ELF
32CONST char comment_chars[] = "|#";
33#else
49864cfa 34CONST char comment_chars[] = "|";
5f8cb05e 35#endif
fecd2382
RP
36
37/* This array holds the chars that only start a comment at the beginning of
38 a line. If the line seems to have the form '# 123 filename'
39 .line and .file directives will appear in the pre-processed output */
40/* Note that input_file.c hand checks for '#' at the beginning of the
41 first line of the input file. This is because the compiler outputs
42 #NO_APP at the beginning of its output. */
43/* Also note that comments like this one will always work. */
49864cfa 44CONST char line_comment_chars[] = "#";
fecd2382 45
49864cfa 46CONST char line_separator_chars[] = "";
587c4264 47
fecd2382 48/* Chars that can be used to separate mant from exp in floating point nums */
49864cfa 49CONST char EXP_CHARS[] = "eE";
fecd2382 50
49864cfa
KR
51/* Chars that mean this number is a floating point constant, as
52 in "0f12.456" or "0d1.2345e12". */
fecd2382 53
49864cfa 54CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
fecd2382
RP
55
56/* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
57 changed in read.c . Ideally it shouldn't have to know about it at all,
49864cfa 58 but nothing is ideal around here. */
fecd2382 59
49864cfa 60const int md_reloc_size = 8; /* Size of relocation record */
fecd2382 61
b80d39a0 62/* Are we trying to generate PIC code? If so, absolute references
dff60b7d
ILT
63 ought to be made into linkage table references or pc-relative
64 references. */
b80d39a0
KR
65int flag_want_pic;
66
9ad5755f
KR
67static int flag_short_refs; /* -l option */
68static int flag_long_jumps; /* -S option */
69
82489ea0
KR
70#ifdef REGISTER_PREFIX_OPTIONAL
71int flag_reg_prefix_optional = REGISTER_PREFIX_OPTIONAL;
72#else
73int flag_reg_prefix_optional;
74#endif
75
27a53b88
ILT
76/* The floating point coprocessor to use by default. */
77static enum m68k_register m68k_float_copnum = COP1;
78
6700d36e
ILT
79/* If this is non-zero, then references to number(%pc) will be taken
80 to refer to number, rather than to %pc + number. */
81static int m68k_abspcadd;
82
83/* If this is non-zero, then the quick forms of the move, add, and sub
84 instructions are used when possible. */
85static int m68k_quick = 1;
86
87/* If this is non-zero, then if the size is not specified for a base
88 or outer displacement, the assembler assumes that the size should
89 be 32 bits. */
90static int m68k_rel32 = 1;
91
fecd2382
RP
92/* Its an arbitrary name: This means I don't approve of it */
93/* See flames below */
94static struct obstack robyn;
95
96#define TAB(x,y) (((x)<<2)+(y))
97#define TABTYPE(xy) ((xy) >> 2)
98#define BYTE 0
99#define SHORT 1
100#define LONG 2
101#define SZ_UNDEF 3
3ad9ec6a 102#undef BRANCH
04ef74bb 103/* Case `g' except when BCC68000 is applicable. */
3ad9ec6a 104#define ABRANCH 1
04ef74bb 105/* Coprocessor branches. */
fecd2382 106#define FBRANCH 2
04ef74bb
KR
107/* Mode 7.2 -- program counter indirect with (16-bit) displacement,
108 supported on all cpus. Widens to 32-bit absolute. */
fecd2382 109#define PCREL 3
04ef74bb
KR
110/* For inserting an extra jmp instruction with long offset on 68000,
111 for expanding conditional branches. (Not bsr or bra.) Since the
112 68000 doesn't support 32-bit displacements for conditional
113 branches, we fake it by reversing the condition and branching
114 around a jmp with an absolute long operand. */
fecd2382 115#define BCC68000 4
04ef74bb
KR
116/* For the DBcc "instructions". If the displacement requires 32 bits,
117 the branch-around-a-jump game is played here too. */
fecd2382 118#define DBCC 5
04ef74bb 119/* Not currently used? */
fecd2382 120#define PCLEA 6
04ef74bb
KR
121/* Mode AINDX (apc-relative) using PC, with variable target, might fit
122 in 16 or 8 bits. */
123#define PCINDEX 7
fecd2382 124
bcb8dff8
KR
125struct m68k_incant
126 {
a1c7c0f3 127 const char *m_operands;
bcb8dff8
KR
128 unsigned long m_opcode;
129 short m_opnum;
130 short m_codenum;
131 int m_arch;
132 struct m68k_incant *m_next;
133 };
134
135#define getone(x) ((((x)->m_opcode)>>16)&0xffff)
136#define gettwo(x) (((x)->m_opcode)&0xffff)
137
a1c7c0f3
ILT
138static const enum m68k_register m68000_control_regs[] = { 0 };
139static const enum m68k_register m68010_control_regs[] = {
82489ea0
KR
140 SFC, DFC, USP, VBR,
141 0
142};
a1c7c0f3 143static const enum m68k_register m68020_control_regs[] = {
82489ea0
KR
144 SFC, DFC, USP, VBR, CACR, CAAR, MSP, ISP,
145 0
146};
a1c7c0f3 147static const enum m68k_register m68040_control_regs[] = {
82489ea0
KR
148 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1,
149 USP, VBR, MSP, ISP, MMUSR, URP, SRP,
150 0
151};
a1c7c0f3 152static const enum m68k_register m68060_control_regs[] = {
82489ea0
KR
153 SFC, DFC, CACR, TC, ITT0, ITT1, DTT0, DTT1, BUSCR,
154 USP, VBR, URP, SRP, PCR,
155 0
156};
b79de3a1 157#define cpu32_control_regs m68010_control_regs
82489ea0 158
a1c7c0f3 159static const enum m68k_register *control_regs;
fecd2382
RP
160
161/* internal form of a 68020 instruction */
355afbcd 162struct m68k_it
a1c7c0f3
ILT
163{
164 const char *error;
165 const char *args; /* list of opcode info */
166 int numargs;
355afbcd 167
a1c7c0f3
ILT
168 int numo; /* Number of shorts in opcode */
169 short opcode[11];
355afbcd 170
a1c7c0f3 171 struct m68k_op operands[6];
355afbcd 172
a1c7c0f3
ILT
173 int nexp; /* number of exprs in use */
174 struct m68k_exp exprs[4];
355afbcd 175
a1c7c0f3
ILT
176 int nfrag; /* Number of frags we have to produce */
177 struct
178 {
179 int fragoff; /* Where in the current opcode the frag ends */
180 symbolS *fadd;
181 long foff;
182 int fragty;
183 }
184 fragb[4];
355afbcd 185
a1c7c0f3
ILT
186 int nrel; /* Num of reloc strucs in use */
187 struct
188 {
189 int n;
190 expressionS exp;
191 char wid;
192 char pcrel;
193 /* In a pc relative address the difference between the address
194 of the offset and the address that the offset is relative
195 to. This depends on the addressing mode. Basically this
196 is the value to put in the offset field to address the
197 first byte of the offset, without regarding the special
198 significance of some values (in the branch instruction, for
199 example). */
200 int pcrel_fix;
201 }
202 reloc[5]; /* Five is enough??? */
203};
fecd2382 204
865a2edf
MT
205#define cpu_of_arch(x) ((x) & m68000up)
206#define float_of_arch(x) ((x) & mfloat)
207#define mmu_of_arch(x) ((x) & mmmu)
208
355afbcd 209static struct m68k_it the_ins; /* the instruction being assembled */
fecd2382 210
a1c7c0f3
ILT
211#define op(ex) ((ex)->exp.X_op)
212#define adds(ex) ((ex)->exp.X_add_symbol)
213#define subs(ex) ((ex)->exp.X_op_symbol)
214#define offs(ex) ((ex)->exp.X_add_number)
49864cfa 215
7c15cbe8 216/* Macros for adding things to the m68k_it struct */
fecd2382
RP
217
218#define addword(w) the_ins.opcode[the_ins.numo++]=(w)
219
220/* Like addword, but goes BEFORE general operands */
bcb8dff8
KR
221static void
222insop (w, opcode)
223 int w;
224 struct m68k_incant *opcode;
225{
226 int z;
227 for(z=the_ins.numo;z>opcode->m_codenum;--z)
228 the_ins.opcode[z]=the_ins.opcode[z-1];
229 for(z=0;z<the_ins.nrel;z++)
230 the_ins.reloc[z].n+=2;
5f8cb05e
ILT
231 for (z = 0; z < the_ins.nfrag; z++)
232 the_ins.fragb[z].fragoff++;
bcb8dff8
KR
233 the_ins.opcode[opcode->m_codenum]=w;
234 the_ins.numo++;
235}
fecd2382 236
1404ef23
KR
237/* The numo+1 kludge is so we can hit the low order byte of the prev word.
238 Blecch. */
49864cfa 239static void
5f8cb05e 240add_fix (width, exp, pc_rel, pc_fix)
49864cfa
KR
241 char width;
242 struct m68k_exp *exp;
243 int pc_rel;
5f8cb05e 244 int pc_fix;
49864cfa
KR
245{
246 the_ins.reloc[the_ins.nrel].n = (((width)=='B')
247 ? (the_ins.numo*2-1)
248 : (((width)=='b')
5f8cb05e 249 ? (the_ins.numo*2+1)
49864cfa 250 : (the_ins.numo*2)));
a1c7c0f3 251 the_ins.reloc[the_ins.nrel].exp = exp->exp;
49864cfa 252 the_ins.reloc[the_ins.nrel].wid = width;
5f8cb05e 253 the_ins.reloc[the_ins.nrel].pcrel_fix = pc_fix;
49864cfa 254 the_ins.reloc[the_ins.nrel++].pcrel = pc_rel;
1404ef23
KR
255}
256
5f8cb05e
ILT
257/* Cause an extra frag to be generated here, inserting up to 10 bytes
258 (that value is chosen in the frag_var call in md_assemble). TYPE
259 is the subtype of the frag to be generated; its primary type is
260 rs_machine_dependent.
261
262 The TYPE parameter is also used by md_convert_frag_1 and
263 md_estimate_size_before_relax. The appropriate type of fixup will
264 be emitted by md_convert_frag_1.
265
266 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
49864cfa
KR
267static void
268add_frag(add,off,type)
269 symbolS *add;
270 long off;
271 int type;
272{
273 the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;
274 the_ins.fragb[the_ins.nfrag].fadd=add;
275 the_ins.fragb[the_ins.nfrag].foff=off;
276 the_ins.fragb[the_ins.nfrag++].fragty=type;
1404ef23 277}
fecd2382 278
a1c7c0f3
ILT
279#define isvar(ex) \
280 (op (ex) != O_constant && op (ex) != O_big)
fecd2382 281
49864cfa
KR
282static char *crack_operand PARAMS ((char *str, struct m68k_op *opP));
283static int get_num PARAMS ((struct m68k_exp *exp, int ok));
49864cfa
KR
284static int reverse_16_bits PARAMS ((int in));
285static int reverse_8_bits PARAMS ((int in));
49864cfa
KR
286static void install_gen_operand PARAMS ((int mode, int val));
287static void install_operand PARAMS ((int mode, int val));
bcb8dff8
KR
288static void s_bss PARAMS ((int));
289static void s_data1 PARAMS ((int));
290static void s_data2 PARAMS ((int));
291static void s_even PARAMS ((int));
292static void s_proc PARAMS ((int));
e9bb39b4
ILT
293static void mri_chip PARAMS ((void));
294static void s_chip PARAMS ((int));
27a53b88 295static void s_fopt PARAMS ((int));
6700d36e
ILT
296static void s_opt PARAMS ((int));
297static void s_reg PARAMS ((int));
49864cfa
KR
298
299static int current_architecture;
7c15cbe8 300
b79de3a1
KR
301struct m68k_cpu {
302 unsigned long arch;
303 const char *name;
304};
305
306static const struct m68k_cpu archs[] = {
307 { m68000, "68000" },
308 { m68010, "68010" },
309 { m68020, "68020" },
310 { m68030, "68030" },
311 { m68040, "68040" },
312 { m68060, "68060" },
313 { cpu32, "cpu32" },
314 { m68881, "68881" },
315 { m68851, "68851" },
316 /* Aliases (effectively, so far as gas is concerned) for the above
317 cpus. */
318 { m68020, "68k" },
319 { m68000, "68302" },
320 { m68000, "68008" },
e9bb39b4
ILT
321 { m68000, "68ec000" },
322 { m68000, "68hc000" },
323 { m68000, "68hc001" },
324 { m68020, "68ec020" },
325 { m68030, "68ec030" },
326 { m68040, "68ec040" },
327 { cpu32, "68330" },
b79de3a1
KR
328 { cpu32, "68331" },
329 { cpu32, "68332" },
330 { cpu32, "68333" },
331 { cpu32, "68340" },
5f8cb05e 332 { cpu32, "68360" },
b79de3a1
KR
333 { m68881, "68882" },
334};
335
336static const int n_archs = sizeof (archs) / sizeof (archs[0]);
337
fecd2382
RP
338/* BCC68000 is for patching in an extra jmp instruction for long offsets
339 on the 68000. The 68000 doesn't support long branches with branchs */
340
341/* This table desribes how you change sizes for the various types of variable
342 size expressions. This version only supports two kinds. */
343
49864cfa
KR
344/* Note that calls to frag_var need to specify the maximum expansion
345 needed; this is currently 10 bytes for DBCC. */
fecd2382
RP
346
347/* The fields are:
a39116f1
RP
348 How far Forward this mode will reach:
349 How far Backward this mode will reach:
350 How many bytes this mode will add to the size of the frag
351 Which mode to go to if the offset won't fit in this one
352 */
04ef74bb 353relax_typeS md_relax_table[] =
355afbcd
KR
354{
355 {1, 1, 0, 0}, /* First entries aren't used */
356 {1, 1, 0, 0}, /* For no good reason except */
357 {1, 1, 0, 0}, /* that the VAX doesn't either */
358 {1, 1, 0, 0},
359
360 {(127), (-128), 0, TAB (ABRANCH, SHORT)},
361 {(32767), (-32768), 2, TAB (ABRANCH, LONG)},
362 {0, 0, 4, 0},
363 {1, 1, 0, 0},
364
365 {1, 1, 0, 0}, /* FBRANCH doesn't come BYTE */
366 {(32767), (-32768), 2, TAB (FBRANCH, LONG)},
367 {0, 0, 4, 0},
368 {1, 1, 0, 0},
369
370 {1, 1, 0, 0}, /* PCREL doesn't come BYTE */
371 {(32767), (-32768), 2, TAB (PCREL, LONG)},
372 {0, 0, 4, 0},
373 {1, 1, 0, 0},
374
375 {(127), (-128), 0, TAB (BCC68000, SHORT)},
376 {(32767), (-32768), 2, TAB (BCC68000, LONG)},
377 {0, 0, 6, 0}, /* jmp long space */
378 {1, 1, 0, 0},
379
380 {1, 1, 0, 0}, /* DBCC doesn't come BYTE */
381 {(32767), (-32768), 2, TAB (DBCC, LONG)},
382 {0, 0, 10, 0}, /* bra/jmp long space */
383 {1, 1, 0, 0},
384
385 {1, 1, 0, 0}, /* PCLEA doesn't come BYTE */
386 {32767, -32768, 2, TAB (PCLEA, LONG)},
387 {0, 0, 6, 0},
388 {1, 1, 0, 0},
389
04ef74bb
KR
390 /* For, e.g., jmp pcrel indexed. */
391 {125, -130, 0, TAB (PCINDEX, SHORT)},
392 {32765, -32770, 2, TAB (PCINDEX, LONG)},
393 {0, 0, 4, 0},
394 {1, 1, 0, 0},
355afbcd 395};
fecd2382
RP
396
397/* These are the machine dependent pseudo-ops. These are included so
398 the assembler can work on the output from the SUN C compiler, which
399 generates these.
a39116f1 400 */
fecd2382
RP
401
402/* This table describes all the machine specific pseudo-ops the assembler
403 has to support. The fields are:
a39116f1
RP
404 pseudo-op name without dot
405 function to call to execute this pseudo-op
406 Integer arg to pass to the function
407 */
49864cfa 408CONST pseudo_typeS md_pseudo_table[] =
355afbcd
KR
409{
410 {"data1", s_data1, 0},
411 {"data2", s_data2, 0},
412 {"bss", s_bss, 0},
413 {"even", s_even, 0},
414 {"skip", s_space, 0},
415 {"proc", s_proc, 0},
bec66218 416#ifdef TE_SUN3
355afbcd 417 {"align", s_align_bytes, 0},
5f8cb05e
ILT
418#endif
419#ifdef OBJ_ELF
420 {"swbeg", s_ignore, 0},
bec66218 421#endif
e9bb39b4
ILT
422
423 /* The following pseudo-ops are supported for MRI compatibility. */
424 {"chip", s_chip, 0},
425 {"comline", s_space, 1},
27a53b88
ILT
426 {"fopt", s_fopt, 0},
427 {"mask2", s_ignore, 0},
6700d36e
ILT
428 {"opt", s_opt, 0},
429 {"reg", s_reg, 0},
e9bb39b4 430
355afbcd 431 {0, 0, 0}
fecd2382
RP
432};
433
434
3ad9ec6a 435/* The mote pseudo ops are put into the opcode table, since they
355afbcd 436 don't start with a . they look like opcodes to gas.
3ad9ec6a 437 */
355afbcd 438extern void obj_coff_section ();
3ad9ec6a 439
49864cfa 440CONST pseudo_typeS mote_pseudo_table[] =
3ad9ec6a
ILT
441{
442
b79de3a1 443 {"dcl", cons, 4},
355afbcd 444 {"dc", cons, 2},
b79de3a1
KR
445 {"dcw", cons, 2},
446 {"dcb", cons, 1},
3ad9ec6a 447
b79de3a1 448 {"dsl", s_space, 4},
355afbcd 449 {"ds", s_space, 2},
b79de3a1
KR
450 {"dsw", s_space, 2},
451 {"dsb", s_space, 1},
3ad9ec6a 452
355afbcd
KR
453 {"xdef", s_globl, 0},
454 {"align", s_align_ptwo, 0},
3ad9ec6a 455#ifdef M68KCOFF
355afbcd
KR
456 {"sect", obj_coff_section, 0},
457 {"section", obj_coff_section, 0},
3ad9ec6a 458#endif
bcb8dff8 459 {0, 0, 0}
3ad9ec6a
ILT
460};
461
fecd2382
RP
462#define issbyte(x) ((x)>=-128 && (x)<=127)
463#define isubyte(x) ((x)>=0 && (x)<=255)
464#define issword(x) ((x)>=-32768 && (x)<=32767)
465#define isuword(x) ((x)>=0 && (x)<=65535)
f8701a3f 466
e284846a 467#define isbyte(x) ((x)>= -255 && (x)<=255)
fecd2382
RP
468#define isword(x) ((x)>=-32768 && (x)<=65535)
469#define islong(x) (1)
f8701a3f
SC
470
471extern char *input_line_pointer;
fecd2382 472
fecd2382
RP
473static char mklower_table[256];
474#define mklower(c) (mklower_table[(unsigned char)(c)])
f8701a3f 475static char notend_table[256];
fecd2382 476static char alt_notend_table[256];
a1c7c0f3
ILT
477#define notend(s) \
478 (! (notend_table[(unsigned char) *s] \
479 || (*s == ':' \
480 && alt_notend_table[(unsigned char) s[1]])))
7c15cbe8 481
49864cfa 482#if defined (M68KCOFF) && !defined (BFD_ASSEMBLER)
3ad9ec6a 483
82489ea0
KR
484#ifdef NO_PCREL_RELOCS
485
486int
487make_pcrel_absolute(fixP, add_number)
488 fixS *fixP;
489 long *add_number;
490{
491 register unsigned char *opcode = fixP->fx_frag->fr_opcode;
492
493 /* rewrite the PC relative instructions to absolute address ones.
494 * these are rumoured to be faster, and the apollo linker refuses
495 * to deal with the PC relative relocations.
496 */
497 if (opcode[0] == 0x60 && opcode[1] == 0xff) /* BRA -> JMP */
498 {
499 opcode[0] = 0x4e;
500 opcode[1] = 0xf9;
501 }
502 else if (opcode[0] == 0x61 && opcode[1] == 0xff) /* BSR -> JSR */
503 {
504 opcode[0] = 0x4e;
505 opcode[1] = 0xb9;
506 }
507 else
508 as_fatal ("Unknown PC relative instruction");
509 *add_number -= 4;
510 return 0;
511}
512
513#endif /* NO_PCREL_RELOCS */
514
355afbcd
KR
515short
516tc_coff_fix2rtype (fixP)
517 fixS *fixP;
fecd2382 518{
82489ea0
KR
519#ifdef NO_PCREL_RELOCS
520 know (fixP->fx_pcrel == 0);
521 return (fixP->fx_size == 1 ? R_RELBYTE
522 : fixP->fx_size == 2 ? R_DIR16
523 : R_DIR32);
524#else
355afbcd
KR
525 return (fixP->fx_pcrel ?
526 (fixP->fx_size == 1 ? R_PCRBYTE :
527 fixP->fx_size == 2 ? R_PCRWORD :
528 R_PCRLONG) :
529 (fixP->fx_size == 1 ? R_RELBYTE :
530 fixP->fx_size == 2 ? R_RELWORD :
531 R_RELLONG));
82489ea0 532#endif
3ad9ec6a
ILT
533}
534
535#endif
fecd2382 536
49864cfa
KR
537#ifdef BFD_ASSEMBLER
538
539arelent *
540tc_gen_reloc (section, fixp)
541 asection *section;
542 fixS *fixp;
543{
544 arelent *reloc;
545 bfd_reloc_code_real_type code;
546
547#define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
548 switch (F (fixp->fx_size, fixp->fx_pcrel))
549 {
550#define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
551 MAP (1, 0, BFD_RELOC_8);
552 MAP (2, 0, BFD_RELOC_16);
553 MAP (4, 0, BFD_RELOC_32);
554 MAP (1, 1, BFD_RELOC_8_PCREL);
555 MAP (2, 1, BFD_RELOC_16_PCREL);
556 MAP (4, 1, BFD_RELOC_32_PCREL);
557 default:
558 abort ();
559 }
560
561 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
562 assert (reloc != 0);
563 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
564 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
565 if (fixp->fx_pcrel)
566 reloc->addend = fixp->fx_addnumber;
567 else
568 reloc->addend = 0;
569
570 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
571 assert (reloc->howto != 0);
572
573 return reloc;
574}
575
576#endif /* BFD_ASSEMBLER */
577
49864cfa
KR
578/* Handle of the OPCODE hash table. NULL means any use before
579 m68k_ip_begin() will crash. */
580static struct hash_control *op_hash;
fecd2382 581\f
a1c7c0f3 582/* Assemble an m68k instruction. */
355afbcd 583
355afbcd
KR
584void
585m68k_ip (instring)
6d27d3a2 586 char *instring;
fecd2382 587{
6d27d3a2
KR
588 register char *p;
589 register struct m68k_op *opP;
590 register struct m68k_incant *opcode;
a1c7c0f3 591 register const char *s;
6d27d3a2 592 register int tmpreg = 0, baseo = 0, outro = 0, nextword;
3ad9ec6a 593 char *pdot, *pdotmove;
a1c7c0f3 594 enum m68k_size siz1, siz2;
355afbcd
KR
595 char c;
596 int losing;
597 int opsfound;
598 char *crack_operand ();
6d27d3a2
KR
599 LITTLENUM_TYPE words[6];
600 LITTLENUM_TYPE *wordp;
8be74775 601 unsigned long ok_arch = 0;
6d27d3a2
KR
602
603 if (*instring == ' ')
604 instring++; /* skip leading whitespace */
605
606 /* Scan up to end of operation-code, which MUST end in end-of-string
607 or exactly 1 space. */
3ad9ec6a 608 pdot = 0;
355afbcd
KR
609 for (p = instring; *p != '\0'; p++)
610 {
611 if (*p == ' ')
612 break;
613 if (*p == '.')
614 pdot = p;
615 }
6d27d3a2 616
355afbcd
KR
617 if (p == instring)
618 {
619 the_ins.error = "No operator";
355afbcd
KR
620 return;
621 }
6d27d3a2
KR
622
623 /* p now points to the end of the opcode name, probably whitespace.
a1c7c0f3
ILT
624 Make sure the name is null terminated by clobbering the
625 whitespace, look it up in the hash table, then fix it back.
3ad9ec6a 626 Remove a dot, first, since the opcode tables have none. */
355afbcd
KR
627 if (pdot != NULL)
628 {
629 for (pdotmove = pdot; pdotmove < p; pdotmove++)
630 *pdotmove = pdotmove[1];
631 p--;
632 }
3ad9ec6a 633
6d27d3a2
KR
634 c = *p;
635 *p = '\0';
355afbcd 636 opcode = (struct m68k_incant *) hash_find (op_hash, instring);
6d27d3a2
KR
637 *p = c;
638
355afbcd
KR
639 if (pdot != NULL)
640 {
641 for (pdotmove = p; pdotmove > pdot; pdotmove--)
642 *pdotmove = pdotmove[-1];
643 *pdot = '.';
644 ++p;
645 }
3ad9ec6a 646
355afbcd
KR
647 if (opcode == NULL)
648 {
649 the_ins.error = "Unknown operator";
355afbcd
KR
650 return;
651 }
6d27d3a2
KR
652
653 /* found a legitimate opcode, start matching operands */
355afbcd
KR
654 while (*p == ' ')
655 ++p;
6d27d3a2 656
355afbcd
KR
657 if (opcode->m_operands == 0)
658 {
659 char *old = input_line_pointer;
660 *old = '\n';
661 input_line_pointer = p;
662 /* Ahh - it's a motorola style psuedo op */
663 mote_pseudo_table[opcode->m_opnum].poc_handler
664 (mote_pseudo_table[opcode->m_opnum].poc_val);
665 input_line_pointer = old;
666 *old = 0;
3ad9ec6a 667
355afbcd
KR
668 return;
669 }
3ad9ec6a 670
355afbcd
KR
671 for (opP = &the_ins.operands[0]; *p; opP++)
672 {
355afbcd 673 p = crack_operand (p, opP);
6d27d3a2 674
355afbcd
KR
675 if (opP->error)
676 {
677 the_ins.error = opP->error;
678 return;
679 }
6d27d3a2 680 }
6d27d3a2
KR
681
682 opsfound = opP - &the_ins.operands[0];
683
a1c7c0f3
ILT
684 /* This ugly hack is to support the floating pt opcodes in their
685 standard form. Essentially, we fake a first enty of type COP#1 */
355afbcd
KR
686 if (opcode->m_operands[0] == 'I')
687 {
688 int n;
6d27d3a2 689
355afbcd
KR
690 for (n = opsfound; n > 0; --n)
691 the_ins.operands[n] = the_ins.operands[n - 1];
6d27d3a2 692
a1c7c0f3
ILT
693 memset ((char *) (&the_ins.operands[0]), '\0',
694 sizeof (the_ins.operands[0]));
695 the_ins.operands[0].mode = CONTROL;
27a53b88 696 the_ins.operands[0].reg = m68k_float_copnum;
355afbcd
KR
697 opsfound++;
698 }
6d27d3a2
KR
699
700 /* We've got the operands. Find an opcode that'll accept them */
355afbcd
KR
701 for (losing = 0;;)
702 {
49864cfa
KR
703 /* If we didn't get the right number of ops, or we have no
704 common model with this pattern then reject this pattern. */
6d27d3a2 705
355afbcd
KR
706 if (opsfound != opcode->m_opnum
707 || ((opcode->m_arch & current_architecture) == 0))
708 {
709 ++losing;
710 ok_arch |= opcode->m_arch;
711 }
712 else
713 {
a1c7c0f3
ILT
714 for (s = opcode->m_operands, opP = &the_ins.operands[0];
715 *s && !losing;
716 s += 2, opP++)
355afbcd
KR
717 {
718 /* Warning: this switch is huge! */
49864cfa
KR
719 /* I've tried to organize the cases into this order:
720 non-alpha first, then alpha by letter. Lower-case
721 goes directly before uppercase counterpart. */
722 /* Code with multiple case ...: gets sorted by the lowest
723 case ... it belongs to. I hope this makes sense. */
355afbcd
KR
724 switch (*s)
725 {
a1c7c0f3
ILT
726 case '!':
727 switch (opP->mode)
728 {
729 case IMMED:
730 case DREG:
731 case AREG:
732 case FPREG:
733 case CONTROL:
734 case AINC:
735 case ADEC:
736 case REGLST:
737 losing++;
738 break;
739 default:
740 break;
741 }
355afbcd
KR
742 break;
743
744 case '`':
745 switch (opP->mode)
746 {
355afbcd
KR
747 case IMMED:
748 case DREG:
749 case AREG:
a1c7c0f3
ILT
750 case FPREG:
751 case CONTROL:
355afbcd
KR
752 case AINC:
753 case REGLST:
754 case AINDR:
755 losing++;
bcb8dff8
KR
756 break;
757 default:
758 break;
355afbcd
KR
759 }
760 break;
8be74775 761
355afbcd
KR
762 case '#':
763 if (opP->mode != IMMED)
764 losing++;
a1c7c0f3
ILT
765 else if (s[1] == 'b'
766 && ! isvar (&opP->disp)
767 && ! expr8 (&opP->disp))
768 losing++;
769 else if (s[1] == 'w'
770 && ! isvar (&opP->disp)
771 && ! expr16 (&opP->disp))
772 losing++;
355afbcd
KR
773 break;
774
775 case '^':
776 case 'T':
777 if (opP->mode != IMMED)
778 losing++;
779 break;
780
781 case '$':
a1c7c0f3
ILT
782 if (opP->mode == AREG
783 || opP->mode == CONTROL
784 || opP->mode == FPREG
785 || opP->mode == IMMED
786 || opP->mode == REGLST
787 || (opP->mode != ABSL
788 && (opP->reg == PC
789 || opP->reg == ZPC)))
355afbcd
KR
790 losing++;
791 break;
792
793 case '%':
a1c7c0f3
ILT
794 if (opP->mode == CONTROL
795 || opP->mode == FPREG
796 || opP->mode == REGLST
797 || (opP->mode != ABSL
798 && opP->mode != IMMED
799 && (opP->reg == PC
800 || opP->reg == ZPC)))
355afbcd
KR
801 losing++;
802 break;
803
355afbcd 804 case '&':
a1c7c0f3
ILT
805 switch (opP->mode)
806 {
807 case DREG:
808 case AREG:
809 case FPREG:
810 case CONTROL:
811 case IMMED:
812 case AINC:
813 case ADEC:
814 case REGLST:
815 losing++;
816 break;
817 case ABSL:
818 break;
819 default:
820 if (opP->reg == PC
821 || opP->reg == ZPC)
822 losing++;
823 break;
824 }
355afbcd
KR
825 break;
826
827 case '*':
a1c7c0f3
ILT
828 if (opP->mode == CONTROL
829 || opP->mode == FPREG
830 || opP->mode == REGLST)
355afbcd
KR
831 losing++;
832 break;
833
834 case '+':
835 if (opP->mode != AINC)
836 losing++;
837 break;
838
839 case '-':
840 if (opP->mode != ADEC)
841 losing++;
842 break;
843
844 case '/':
a1c7c0f3
ILT
845 switch (opP->mode)
846 {
847 case AREG:
848 case CONTROL:
849 case FPREG:
850 case AINC:
851 case ADEC:
852 case IMMED:
853 case REGLST:
854 losing++;
855 break;
856 default:
857 break;
858 }
355afbcd
KR
859 break;
860
861 case ';':
a1c7c0f3
ILT
862 switch (opP->mode)
863 {
864 case AREG:
865 case CONTROL:
866 case FPREG:
867 case REGLST:
868 losing++;
869 break;
870 default:
871 break;
872 }
355afbcd
KR
873 break;
874
875 case '?':
a1c7c0f3
ILT
876 switch (opP->mode)
877 {
878 case AREG:
879 case CONTROL:
880 case FPREG:
881 case AINC:
882 case ADEC:
883 case IMMED:
884 case REGLST:
885 losing++;
886 break;
887 case ABSL:
888 break;
889 default:
890 if (opP->reg == PC || opP->reg == ZPC)
891 losing++;
892 break;
893 }
355afbcd
KR
894 break;
895
896 case '@':
a1c7c0f3
ILT
897 switch (opP->mode)
898 {
899 case AREG:
900 case CONTROL:
901 case FPREG:
902 case IMMED:
903 case REGLST:
904 losing++;
905 break;
906 default:
907 break;
908 }
355afbcd
KR
909 break;
910
911 case '~': /* For now! (JF FOO is this right?) */
a1c7c0f3
ILT
912 switch (opP->mode)
913 {
914 case DREG:
915 case AREG:
916 case CONTROL:
917 case FPREG:
918 case IMMED:
919 case REGLST:
920 losing++;
921 break;
922 case ABSL:
923 break;
924 default:
925 if (opP->reg == PC
926 || opP->reg == ZPC)
927 losing++;
928 break;
929 }
355afbcd
KR
930 break;
931
932 case '3':
a1c7c0f3
ILT
933 if (opP->mode != CONTROL
934 || (opP->reg != TT0 && opP->reg != TT1))
355afbcd
KR
935 losing++;
936 break;
937
938 case 'A':
939 if (opP->mode != AREG)
940 losing++;
941 break;
a1c7c0f3 942
355afbcd
KR
943 case 'a':
944 if (opP->mode != AINDR)
a1c7c0f3 945 ++losing;
355afbcd 946 break;
a1c7c0f3 947
355afbcd 948 case 'B': /* FOO */
a1c7c0f3
ILT
949 if (opP->mode != ABSL
950 || (flag_long_jumps
951 && strncmp (instring, "jbsr", 4) == 0))
355afbcd
KR
952 losing++;
953 break;
954
955 case 'C':
a1c7c0f3 956 if (opP->mode != CONTROL || opP->reg != CCR)
355afbcd
KR
957 losing++;
958 break;
959
a1c7c0f3
ILT
960 case 'd':
961 if (opP->mode != DISP
962 || opP->reg < ADDR0
963 || opP->reg > ADDR7)
355afbcd
KR
964 losing++;
965 break;
966
967 case 'D':
968 if (opP->mode != DREG)
969 losing++;
970 break;
971
972 case 'F':
a1c7c0f3 973 if (opP->mode != FPREG)
355afbcd
KR
974 losing++;
975 break;
976
977 case 'I':
a1c7c0f3 978 if (opP->mode != CONTROL
27a53b88
ILT
979 || opP->reg < COP0
980 || opP->reg > COP7)
355afbcd
KR
981 losing++;
982 break;
983
984 case 'J':
a1c7c0f3 985 if (opP->mode != CONTROL
355afbcd 986 || opP->reg < USP
82489ea0
KR
987 || opP->reg > last_movec_reg)
988 losing++;
989 else
355afbcd 990 {
a1c7c0f3 991 const enum m68k_register *rp;
82489ea0
KR
992 for (rp = control_regs; *rp; rp++)
993 if (*rp == opP->reg)
994 break;
995 if (*rp == 0)
996 losing++;
997 }
355afbcd
KR
998 break;
999
1000 case 'k':
1001 if (opP->mode != IMMED)
1002 losing++;
1003 break;
8be74775 1004
355afbcd
KR
1005 case 'l':
1006 case 'L':
a1c7c0f3
ILT
1007 if (opP->mode == DREG
1008 || opP->mode == AREG
1009 || opP->mode == FPREG)
355afbcd
KR
1010 {
1011 if (s[1] == '8')
1012 losing++;
1013 else
1014 {
a1c7c0f3
ILT
1015 switch (opP->mode)
1016 {
1017 case DREG:
1018 opP->mask = 1 << (opP->reg - DATA0);
1019 break;
1020 case AREG:
1021 opP->mask = 1 << (opP->reg - ADDR0 + 8);
1022 break;
1023 case FPREG:
1024 opP->mask = 1 << (opP->reg - FP0 + 16);
1025 break;
1026 default:
1027 abort ();
1028 }
355afbcd 1029 opP->mode = REGLST;
355afbcd
KR
1030 }
1031 }
a1c7c0f3 1032 else if (opP->mode == CONTROL)
355afbcd 1033 {
a1c7c0f3
ILT
1034 if (s[1] != '8')
1035 losing++;
1036 else
1037 {
1038 switch (opP->reg)
1039 {
1040 case FPI:
1041 opP->mask = 1 << 24;
1042 break;
1043 case FPS:
1044 opP->mask = 1 << 25;
1045 break;
1046 case FPC:
1047 opP->mask = 1 << 26;
1048 break;
1049 default:
1050 losing++;
1051 break;
1052 }
1053 opP->mode = REGLST;
1054 }
355afbcd 1055 }
6700d36e
ILT
1056 else if (opP->mode == ABSL
1057 && opP->disp.size == SIZE_UNSPEC
1058 && opP->disp.exp.X_op == O_constant)
1059 {
1060 /* This is what the MRI REG pseudo-op generates. */
1061 opP->mode = REGLST;
1062 opP->mask = opP->disp.exp.X_add_number;
1063 }
a1c7c0f3 1064 else if (opP->mode != REGLST)
355afbcd 1065 losing++;
a1c7c0f3
ILT
1066 else if (s[1] == '8' && (opP->mask & 0x0ffffff) != 0)
1067 losing++;
1068 else if (s[1] == '3' && (opP->mask & 0x7000000) != 0)
355afbcd
KR
1069 losing++;
1070 break;
1071
1072 case 'M':
1073 if (opP->mode != IMMED)
1074 losing++;
a1c7c0f3
ILT
1075 else if (! expr8 (&opP->disp))
1076 losing++;
6700d36e
ILT
1077 else if (! m68k_quick
1078 && instring[3] != 'q'
1079 && instring[4] != 'q')
1080 losing++;
355afbcd 1081 break;
8be74775 1082
355afbcd
KR
1083 case 'O':
1084 if (opP->mode != DREG && opP->mode != IMMED)
1085 losing++;
1086 break;
6d27d3a2 1087
355afbcd
KR
1088 case 'Q':
1089 if (opP->mode != IMMED)
1090 losing++;
a1c7c0f3
ILT
1091 else if (! expr8 (&opP->disp)
1092 || opP->disp.exp.X_add_number < 1
1093 || opP->disp.exp.X_add_number > 8)
1094 losing++;
6700d36e
ILT
1095 else if (! m68k_quick
1096 && (strncmp (instring, "add", 3) == 0
1097 || strncmp (instring, "sub", 3) == 0)
1098 && instring[3] != 'q')
1099 losing++;
355afbcd 1100 break;
8be74775 1101
355afbcd
KR
1102 case 'R':
1103 if (opP->mode != DREG && opP->mode != AREG)
1104 losing++;
1105 break;
8be74775 1106
355afbcd 1107 case 'r':
a1c7c0f3
ILT
1108 if (opP->mode != AINDR
1109 && (opP->mode != BASE
1110 || (opP->reg != 0
1111 && opP->reg != ZADDR0)
1112 || opP->disp.exp.X_op != O_absent
1113 || ((opP->index.reg < DATA0
1114 || opP->index.reg > DATA7)
1115 && (opP->index.reg < ADDR0
1116 || opP->index.reg > ADDR7))
1117 || opP->index.size != SIZE_UNSPEC
1118 || opP->index.scale != 1))
355afbcd
KR
1119 losing++;
1120 break;
c50140c8 1121
355afbcd 1122 case 's':
a1c7c0f3
ILT
1123 if (opP->mode != CONTROL
1124 || ! (opP->reg == FPI
1125 || opP->reg == FPS
1126 || opP->reg == FPC))
355afbcd
KR
1127 losing++;
1128 break;
8be74775 1129
355afbcd 1130 case 'S':
a1c7c0f3 1131 if (opP->mode != CONTROL || opP->reg != SR)
355afbcd
KR
1132 losing++;
1133 break;
8be74775 1134
355afbcd
KR
1135 case 't':
1136 if (opP->mode != IMMED)
1137 losing++;
a1c7c0f3
ILT
1138 else if (! expr8 (&opP->disp)
1139 || opP->disp.exp.X_add_number < 0
1140 || opP->disp.exp.X_add_number > 7)
1141 losing++;
355afbcd 1142 break;
4134a793 1143
355afbcd 1144 case 'U':
a1c7c0f3 1145 if (opP->mode != CONTROL || opP->reg != USP)
355afbcd
KR
1146 losing++;
1147 break;
8be74775 1148
355afbcd 1149 /* JF these are out of order. We could put them
1404ef23
KR
1150 in order if we were willing to put up with
1151 bunches of #ifdef m68851s in the code.
4134a793 1152
1404ef23
KR
1153 Don't forget that you need these operands
1154 to use 68030 MMU instructions. */
f8701a3f 1155#ifndef NO_68851
355afbcd
KR
1156 /* Memory addressing mode used by pflushr */
1157 case '|':
a1c7c0f3
ILT
1158 if (opP->mode == CONTROL
1159 || opP->mode == FPREG
1160 || opP->mode == DREG
1161 || opP->mode == AREG
1162 || opP->mode == REGLST)
355afbcd
KR
1163 losing++;
1164 break;
1165
1166 case 'f':
a1c7c0f3
ILT
1167 if (opP->mode != CONTROL
1168 || (opP->reg != SFC && opP->reg != DFC))
355afbcd
KR
1169 losing++;
1170 break;
1171
1172 case 'P':
a1c7c0f3
ILT
1173 if (opP->mode != CONTROL
1174 || (opP->reg != TC
1175 && opP->reg != CAL
1176 && opP->reg != VAL
1177 && opP->reg != SCC
1178 && opP->reg != AC))
355afbcd
KR
1179 losing++;
1180 break;
1181
1182 case 'V':
a1c7c0f3
ILT
1183 if (opP->mode != CONTROL
1184 || opP->reg != VAL)
355afbcd
KR
1185 losing++;
1186 break;
8be74775 1187
355afbcd 1188 case 'W':
a1c7c0f3
ILT
1189 if (opP->mode != CONTROL
1190 || (opP->reg != DRP
1191 && opP->reg != SRP
355afbcd
KR
1192 && opP->reg != CRP))
1193 losing++;
1194 break;
1195
1196 case 'X':
a1c7c0f3
ILT
1197 if (opP->mode != CONTROL
1198 || (!(opP->reg >= BAD && opP->reg <= BAD + 7)
1199 && !(opP->reg >= BAC && opP->reg <= BAC + 7)))
355afbcd
KR
1200 losing++;
1201 break;
1202
1203 case 'Y':
a1c7c0f3 1204 if (opP->mode != CONTROL || opP->reg != PSR)
355afbcd
KR
1205 losing++;
1206 break;
1207
1208 case 'Z':
a1c7c0f3 1209 if (opP->mode != CONTROL || opP->reg != PCSR)
355afbcd
KR
1210 losing++;
1211 break;
f8701a3f 1212#endif
355afbcd 1213 case 'c':
a1c7c0f3
ILT
1214 if (opP->mode != CONTROL
1215 || (opP->reg != NC
1216 && opP->reg != IC
1217 && opP->reg != DC
1218 && opP->reg != BC))
355afbcd
KR
1219 {
1220 losing++;
1221 } /* not a cache specifier. */
1222 break;
1223
1224 case '_':
1225 if (opP->mode != ABSL)
a1c7c0f3 1226 ++losing;
355afbcd 1227 break;
8be74775 1228
355afbcd 1229 default:
a1c7c0f3 1230 abort ();
355afbcd 1231 } /* switch on type of operand */
6d27d3a2 1232
355afbcd
KR
1233 if (losing)
1234 break;
1235 } /* for each operand */
1236 } /* if immediately wrong */
6d27d3a2 1237
355afbcd
KR
1238 if (!losing)
1239 {
8be74775 1240 break;
355afbcd 1241 } /* got it. */
6d27d3a2 1242
355afbcd 1243 opcode = opcode->m_next;
6d27d3a2 1244
355afbcd 1245 if (!opcode)
8be74775 1246 {
355afbcd
KR
1247 if (ok_arch
1248 && !(ok_arch & current_architecture))
8be74775 1249 {
355afbcd
KR
1250 char buf[200], *cp;
1251 int len;
a1c7c0f3
ILT
1252 strcpy (buf,
1253 "invalid instruction for this architecture; needs ");
355afbcd
KR
1254 cp = buf + strlen (buf);
1255 switch (ok_arch)
1256 {
1257 case mfloat:
82489ea0 1258 strcpy (cp, "fpu (68040, 68060 or 68881/68882)");
355afbcd
KR
1259 break;
1260 case mmmu:
1261 strcpy (cp, "mmu (68030 or 68851)");
1262 break;
1263 case m68020up:
1264 strcpy (cp, "68020 or higher");
1265 break;
1266 case m68000up:
1267 strcpy (cp, "68000 or higher");
1268 break;
1269 case m68010up:
1270 strcpy (cp, "68010 or higher");
1271 break;
1272 default:
8be74775 1273 {
355afbcd 1274 int got_one = 0, idx;
a1c7c0f3
ILT
1275 for (idx = 0; idx < sizeof (archs) / sizeof (archs[0]);
1276 idx++)
8be74775 1277 {
355afbcd 1278 if (archs[idx].arch & ok_arch)
8be74775 1279 {
355afbcd
KR
1280 if (got_one)
1281 {
1282 strcpy (cp, " or ");
1283 cp += strlen (cp);
1284 }
1285 got_one = 1;
1286 strcpy (cp, archs[idx].name);
8be74775
KR
1287 cp += strlen (cp);
1288 }
8be74775
KR
1289 }
1290 }
355afbcd
KR
1291 }
1292 len = cp - buf + 1;
1293 cp = malloc (len);
1294 strcpy (cp, buf);
1295 the_ins.error = cp;
8be74775 1296 }
355afbcd
KR
1297 else
1298 the_ins.error = "operands mismatch";
1299 return;
1300 } /* Fell off the end */
6d27d3a2 1301
355afbcd
KR
1302 losing = 0;
1303 }
6d27d3a2
KR
1304
1305 /* now assemble it */
1306
355afbcd
KR
1307 the_ins.args = opcode->m_operands;
1308 the_ins.numargs = opcode->m_opnum;
1309 the_ins.numo = opcode->m_codenum;
1310 the_ins.opcode[0] = getone (opcode);
1311 the_ins.opcode[1] = gettwo (opcode);
6d27d3a2 1312
355afbcd
KR
1313 for (s = the_ins.args, opP = &the_ins.operands[0]; *s; s += 2, opP++)
1314 {
1315 /* This switch is a doozy.
6d27d3a2 1316 Watch the first step; its a big one! */
355afbcd
KR
1317 switch (s[0])
1318 {
6d27d3a2 1319
355afbcd
KR
1320 case '*':
1321 case '~':
1322 case '%':
1323 case ';':
1324 case '@':
1325 case '!':
1326 case '&':
1327 case '$':
1328 case '?':
1329 case '/':
1330 case '`':
1331#ifndef NO_68851
1332 case '|':
1333#endif
1334 switch (opP->mode)
1335 {
1336 case IMMED:
1337 tmpreg = 0x3c; /* 7.4 */
1338 if (strchr ("bwl", s[1]))
a1c7c0f3 1339 nextword = get_num (&opP->disp, 80);
355afbcd 1340 else
a1c7c0f3
ILT
1341 nextword = get_num (&opP->disp, 0);
1342 if (isvar (&opP->disp))
1343 add_fix (s[1], &opP->disp, 0, 0);
355afbcd
KR
1344 switch (s[1])
1345 {
1346 case 'b':
1347 if (!isbyte (nextword))
1348 opP->error = "operand out of range";
1349 addword (nextword);
1350 baseo = 0;
1351 break;
1352 case 'w':
1353 if (!isword (nextword))
1354 opP->error = "operand out of range";
1355 addword (nextword);
1356 baseo = 0;
1357 break;
1358 case 'l':
1359 addword (nextword >> 16);
1360 addword (nextword);
1361 baseo = 0;
1362 break;
1363
1364 case 'f':
1365 baseo = 2;
1366 outro = 8;
1367 break;
1368 case 'F':
1369 baseo = 4;
1370 outro = 11;
1371 break;
1372 case 'x':
1373 baseo = 6;
1374 outro = 15;
1375 break;
1376 case 'p':
1377 baseo = 6;
1378 outro = -1;
1379 break;
1380 default:
a1c7c0f3 1381 abort ();
355afbcd
KR
1382 }
1383 if (!baseo)
1384 break;
6d27d3a2 1385
355afbcd 1386 /* We gotta put out some float */
a1c7c0f3 1387 if (op (&opP->disp) != O_big)
355afbcd 1388 {
bcb8dff8
KR
1389 valueT val;
1390 int gencnt;
1391
1392 /* Can other cases happen here? */
a1c7c0f3 1393 if (op (&opP->disp) != O_constant)
bcb8dff8 1394 abort ();
82489ea0 1395
a1c7c0f3 1396 val = (valueT) offs (&opP->disp);
bcb8dff8
KR
1397 gencnt = 0;
1398 do
1399 {
1400 generic_bignum[gencnt] = (LITTLENUM_TYPE) val;
1401 val >>= LITTLENUM_NUMBER_OF_BITS;
1402 ++gencnt;
1403 }
1404 while (val != 0);
a1c7c0f3 1405 offs (&opP->disp) = gencnt;
355afbcd 1406 }
a1c7c0f3 1407 if (offs (&opP->disp) > 0)
355afbcd 1408 {
a1c7c0f3 1409 if (offs (&opP->disp) > baseo)
355afbcd 1410 {
a1c7c0f3
ILT
1411 as_warn ("Bignum too big for %c format; truncated",
1412 s[1]);
1413 offs (&opP->disp) = baseo;
355afbcd 1414 }
a1c7c0f3 1415 baseo -= offs (&opP->disp);
355afbcd
KR
1416 while (baseo--)
1417 addword (0);
a1c7c0f3
ILT
1418 for (wordp = generic_bignum + offs (&opP->disp) - 1;
1419 offs (&opP->disp)--;
1420 --wordp)
bcb8dff8 1421 addword (*wordp);
355afbcd
KR
1422 break;
1423 }
1424 gen_to_words (words, baseo, (long) outro);
1425 for (wordp = words; baseo--; wordp++)
1426 addword (*wordp);
1427 break;
1428 case DREG:
1429 tmpreg = opP->reg - DATA; /* 0.dreg */
1430 break;
1431 case AREG:
1432 tmpreg = 0x08 + opP->reg - ADDR; /* 1.areg */
1433 break;
1434 case AINDR:
1435 tmpreg = 0x10 + opP->reg - ADDR; /* 2.areg */
1436 break;
1437 case ADEC:
1438 tmpreg = 0x20 + opP->reg - ADDR; /* 4.areg */
1439 break;
1440 case AINC:
1441 tmpreg = 0x18 + opP->reg - ADDR; /* 3.areg */
1442 break;
a1c7c0f3 1443 case DISP:
6d27d3a2 1444
a1c7c0f3 1445 nextword = get_num (&opP->disp, 80);
6700d36e
ILT
1446
1447 if (opP->reg == PC
1448 && ! isvar (&opP->disp)
1449 && m68k_abspcadd)
1450 {
1451 opP->disp.exp.X_op = O_symbol;
1452#ifndef BFD_ASSEMBLER
1453 opP->disp.exp.X_add_symbol = &abs_symbol;
1454#else
1455 opP->disp.exp.X_add_symbol =
1456 section_symbol (absolute_section);
1457#endif
1458 }
1459
355afbcd 1460 /* Force into index mode. Hope this works */
6d27d3a2 1461
1404ef23
KR
1462 /* We do the first bit for 32-bit displacements, and the
1463 second bit for 16 bit ones. It is possible that we
1464 should make the default be WORD instead of LONG, but
1465 I think that'd break GCC, so we put up with a little
1466 inefficiency for the sake of working output. */
6d27d3a2 1467
355afbcd 1468 if (!issword (nextword)
a1c7c0f3
ILT
1469 || (isvar (&opP->disp)
1470 && ((opP->disp.size == SIZE_UNSPEC
b79de3a1
KR
1471 && flag_short_refs == 0
1472 && cpu_of_arch (current_architecture) >= m68020)
a1c7c0f3 1473 || opP->disp.size == SIZE_LONG)))
355afbcd 1474 {
355afbcd
KR
1475 if (opP->reg == PC)
1476 tmpreg = 0x3B; /* 7.3 */
1477 else
1478 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
a1c7c0f3 1479 if (isvar (&opP->disp))
355afbcd
KR
1480 {
1481 if (opP->reg == PC)
1482 {
04ef74bb 1483#if 0
b80d39a0 1484 addword (0x0170);
a1c7c0f3 1485 add_fix ('l', &opP->disp, 1, 2);
b80d39a0 1486 addword (0), addword (0);
04ef74bb 1487#else
a1c7c0f3
ILT
1488 add_frag (adds (&opP->disp),
1489 offs (&opP->disp),
04ef74bb
KR
1490 TAB (PCLEA, SZ_UNDEF));
1491#endif
355afbcd
KR
1492 break;
1493 }
1494 else
1495 {
1496 addword (0x0170);
a1c7c0f3 1497 add_fix ('l', &opP->disp, 0, 0);
355afbcd
KR
1498 }
1499 }
1500 else
1501 addword (0x0170);
1502 addword (nextword >> 16);
1503 }
1504 else
1505 {
1506 if (opP->reg == PC)
1507 tmpreg = 0x3A; /* 7.2 */
1508 else
1509 tmpreg = 0x28 + opP->reg - ADDR; /* 5.areg */
1510
a1c7c0f3 1511 if (isvar (&opP->disp))
355afbcd
KR
1512 {
1513 if (opP->reg == PC)
1514 {
a1c7c0f3 1515 add_fix ('w', &opP->disp, 1, 0);
355afbcd
KR
1516 }
1517 else
a1c7c0f3 1518 add_fix ('w', &opP->disp, 0, 0);
355afbcd
KR
1519 }
1520 }
1521 addword (nextword);
6d27d3a2 1522 break;
6d27d3a2 1523
a1c7c0f3
ILT
1524 case POST:
1525 case PRE:
1526 case BASE:
355afbcd 1527 nextword = 0;
a1c7c0f3
ILT
1528 baseo = get_num (&opP->disp, 80);
1529 if (opP->mode == POST || opP->mode == PRE)
1530 outro = get_num (&opP->odisp, 80);
49864cfa
KR
1531 /* Figure out the `addressing mode'.
1532 Also turn on the BASE_DISABLE bit, if needed. */
355afbcd
KR
1533 if (opP->reg == PC || opP->reg == ZPC)
1534 {
a1c7c0f3 1535 tmpreg = 0x3b; /* 7.3 */
355afbcd
KR
1536 if (opP->reg == ZPC)
1537 nextword |= 0x80;
1538 }
a1c7c0f3
ILT
1539 else if (opP->reg == 0)
1540 {
1541 nextword |= 0x80;
1542 tmpreg = 0x30; /* 6.garbage */
1543 }
1544 else if (opP->reg >= ZADDR0 && opP->reg <= ZADDR7)
355afbcd
KR
1545 {
1546 nextword |= 0x80;
a1c7c0f3 1547 tmpreg = 0x30 + opP->reg - ZADDR0;
355afbcd
KR
1548 }
1549 else
1550 tmpreg = 0x30 + opP->reg - ADDR; /* 6.areg */
1551
a1c7c0f3
ILT
1552 siz1 = opP->disp.size;
1553 if (opP->mode == POST || opP->mode == PRE)
1554 siz2 = opP->odisp.size;
1555 else
1556 siz2 = SIZE_UNSPEC;
355afbcd
KR
1557
1558 /* Index register stuff */
a1c7c0f3
ILT
1559 if (opP->index.reg != 0
1560 && opP->index.reg >= DATA
1561 && opP->index.reg <= ADDR7)
355afbcd 1562 {
a1c7c0f3 1563 nextword |= (opP->index.reg - DATA) << 12;
355afbcd 1564
a1c7c0f3
ILT
1565 if (opP->index.size == SIZE_UNSPEC
1566 || opP->index.size == SIZE_LONG)
355afbcd 1567 nextword |= 0x800;
a1c7c0f3
ILT
1568
1569 if (cpu_of_arch (current_architecture) < m68020)
1570 {
1571 if (opP->index.scale != 1)
1572 {
1573 opP->error =
1574 "scale factor invalid on this architecture; needs 68020 or higher";
1575 }
1576 }
1577
1578 switch (opP->index.scale)
355afbcd
KR
1579 {
1580 case 1:
1581 break;
1582 case 2:
1583 nextword |= 0x200;
1584 break;
1585 case 4:
1586 nextword |= 0x400;
1587 break;
1588 case 8:
1589 nextword |= 0x600;
1590 break;
1591 default:
a1c7c0f3 1592 abort ();
355afbcd
KR
1593 }
1594 /* IF its simple,
49864cfa 1595 GET US OUT OF HERE! */
6d27d3a2 1596
04ef74bb
KR
1597 /* Must be INDEX, with an index register. Address
1598 register cannot be ZERO-PC, and either :b was
1599 forced, or we know it will fit. For a 68000 or
1600 68010, force this mode anyways, because the
1601 larger modes aren't supported. */
a1c7c0f3
ILT
1602 if (opP->mode == BASE
1603 && ((opP->reg >= ADDR0
1604 && opP->reg <= ADDR7)
1605 || opP->reg == PC))
355afbcd 1606 {
a1c7c0f3
ILT
1607 if (siz1 == SIZE_BYTE
1608 || cpu_of_arch (current_architecture) < m68020
1609 || (siz1 == SIZE_UNSPEC
1610 && ! isvar (&opP->disp)
1611 && issbyte (baseo)))
1612 {
5f8cb05e
ILT
1613 nextword += baseo & 0xff;
1614 addword (nextword);
a1c7c0f3 1615 if (isvar (&opP->disp))
04ef74bb 1616 {
a1c7c0f3
ILT
1617 /* Do a byte relocation. If it doesn't
1618 fit (possible on m68000) let the
1619 fixup processing complain later. */
5f8cb05e 1620 if (opP->reg == PC)
a1c7c0f3 1621 add_fix ('B', &opP->disp, 1, 1);
5f8cb05e 1622 else
a1c7c0f3 1623 add_fix ('B', &opP->disp, 0, 0);
04ef74bb 1624 }
a1c7c0f3
ILT
1625 else if (siz1 != SIZE_BYTE)
1626 {
1627 if (siz1 != SIZE_UNSPEC)
1628 as_warn ("Forcing byte displacement");
1629 if (! issbyte (baseo))
1630 opP->error = "byte displacement out of range";
1631 }
1632
1633 break;
1634 }
1635 else if (siz1 == SIZE_UNSPEC
1636 && opP->reg == PC
1637 && isvar (&opP->disp)
1638 && subs (&opP->disp) == NULL)
1639 {
5f8cb05e
ILT
1640 nextword += baseo & 0xff;
1641 addword (nextword);
a1c7c0f3 1642 add_frag (adds (&opP->disp), offs (&opP->disp),
5f8cb05e 1643 TAB (PCINDEX, SZ_UNDEF));
a1c7c0f3
ILT
1644
1645 break;
5f8cb05e 1646 }
355afbcd
KR
1647 }
1648 }
1649 else
a1c7c0f3
ILT
1650 {
1651 nextword |= 0x40; /* No index reg */
1652 if (opP->index.reg >= ZDATA0
1653 && opP->index.reg <= ZDATA7)
1654 nextword |= (opP->index.reg - ZDATA0) << 12;
1655 else if (opP->index.reg >= ZADDR0
1656 || opP->index.reg <= ZADDR7)
1657 nextword |= (opP->index.reg - ZADDR0 + 8) << 12;
1658 }
6d27d3a2 1659
49864cfa 1660 /* It isn't simple. */
a1c7c0f3
ILT
1661
1662 if (cpu_of_arch (current_architecture) < m68020)
1663 opP->error =
1664 "invalid operand mode for this architecture; needs 68020 or higher";
1665
355afbcd 1666 nextword |= 0x100;
49864cfa
KR
1667 /* If the guy specified a width, we assume that it is
1668 wide enough. Maybe it isn't. If so, we lose. */
355afbcd
KR
1669 switch (siz1)
1670 {
a1c7c0f3 1671 case SIZE_UNSPEC:
6700d36e
ILT
1672 if (isvar (&opP->disp)
1673 ? m68k_rel32
1674 : ! issword (baseo))
355afbcd 1675 {
a1c7c0f3 1676 siz1 = SIZE_LONG;
355afbcd
KR
1677 nextword |= 0x30;
1678 }
6700d36e 1679 else if (! isvar (&opP->disp) && baseo == 0)
355afbcd
KR
1680 nextword |= 0x10;
1681 else
1682 {
1683 nextword |= 0x20;
a1c7c0f3 1684 siz1 = SIZE_WORD;
355afbcd
KR
1685 }
1686 break;
a1c7c0f3
ILT
1687 case SIZE_BYTE:
1688 as_warn (":b not permitted; defaulting to :w");
1689 /* Fall through. */
1690 case SIZE_WORD:
355afbcd
KR
1691 nextword |= 0x20;
1692 break;
a1c7c0f3 1693 case SIZE_LONG:
355afbcd
KR
1694 nextword |= 0x30;
1695 break;
1696 }
6d27d3a2 1697
355afbcd 1698 /* Figure out innner displacement stuff */
a1c7c0f3 1699 if (opP->mode == POST || opP->mode == PRE)
355afbcd
KR
1700 {
1701 switch (siz2)
1702 {
a1c7c0f3 1703 case SIZE_UNSPEC:
6700d36e
ILT
1704 if (isvar (&opP->odisp)
1705 ? m68k_rel32
1706 : ! issword (outro))
355afbcd 1707 {
a1c7c0f3 1708 siz2 = SIZE_LONG;
355afbcd
KR
1709 nextword |= 0x3;
1710 }
6700d36e 1711 else if (! isvar (&opP->disp) && outro == 0)
355afbcd
KR
1712 nextword |= 0x1;
1713 else
1714 {
1715 nextword |= 0x2;
a1c7c0f3 1716 siz2 = SIZE_WORD;
355afbcd
KR
1717 }
1718 break;
1719 case 1:
a1c7c0f3
ILT
1720 as_warn (":b not permitted; defaulting to :w");
1721 /* Fall through. */
355afbcd
KR
1722 case 2:
1723 nextword |= 0x2;
1724 break;
1725 case 3:
1726 nextword |= 0x3;
1727 break;
1728 }
a1c7c0f3 1729 if (opP->mode == POST)
355afbcd 1730 nextword |= 0x04;
355afbcd
KR
1731 }
1732 addword (nextword);
1733
a1c7c0f3 1734 if (siz1 != SIZE_UNSPEC && isvar (&opP->disp))
355afbcd
KR
1735 {
1736 if (opP->reg == PC || opP->reg == ZPC)
a1c7c0f3 1737 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 1, 2);
355afbcd 1738 else
a1c7c0f3 1739 add_fix (siz1 == SIZE_LONG ? 'l' : 'w', &opP->disp, 0, 0);
355afbcd 1740 }
a1c7c0f3 1741 if (siz1 == SIZE_LONG)
355afbcd 1742 addword (baseo >> 16);
a1c7c0f3 1743 if (siz1 != SIZE_UNSPEC)
355afbcd
KR
1744 addword (baseo);
1745
a1c7c0f3
ILT
1746 if (siz2 != SIZE_UNSPEC && isvar (&opP->odisp))
1747 add_fix (siz2 == SIZE_LONG ? 'l' : 'w', &opP->odisp, 0, 0);
1748 if (siz2 == SIZE_LONG)
355afbcd 1749 addword (outro >> 16);
a1c7c0f3 1750 if (siz2 != SIZE_UNSPEC)
355afbcd 1751 addword (outro);
6d27d3a2 1752
355afbcd 1753 break;
6d27d3a2 1754
355afbcd 1755 case ABSL:
a1c7c0f3
ILT
1756 nextword = get_num (&opP->disp, 80);
1757 switch (opP->disp.size)
355afbcd
KR
1758 {
1759 default:
a1c7c0f3
ILT
1760 abort ();
1761 case SIZE_UNSPEC:
1762 if (!isvar (&opP->disp) && issword (offs (&opP->disp)))
355afbcd
KR
1763 {
1764 tmpreg = 0x38; /* 7.0 */
1765 addword (nextword);
1766 break;
1767 }
bcb8dff8
KR
1768 /* Don't generate pc relative code on 68010 and
1769 68000. */
a1c7c0f3
ILT
1770 if (isvar (&opP->disp)
1771 && !subs (&opP->disp)
1772 && adds (&opP->disp)
1773 && (S_GET_SEGMENT (adds (&opP->disp)) == text_section)
49864cfa 1774 && now_seg == text_section
355afbcd 1775 && cpu_of_arch (current_architecture) >= m68020
9ad5755f 1776 && !flag_long_jumps
355afbcd
KR
1777 && !strchr ("~%&$?", s[0]))
1778 {
1779 tmpreg = 0x3A; /* 7.2 */
a1c7c0f3
ILT
1780 add_frag (adds (&opP->disp),
1781 offs (&opP->disp),
355afbcd
KR
1782 TAB (PCREL, SZ_UNDEF));
1783 break;
1784 }
04ef74bb 1785 /* Fall through into long */
a1c7c0f3
ILT
1786 case SIZE_LONG:
1787 if (isvar (&opP->disp))
1788 add_fix ('l', &opP->disp, 0, 0);
355afbcd
KR
1789
1790 tmpreg = 0x39;/* 7.1 mode */
1791 addword (nextword >> 16);
1792 addword (nextword);
1793 break;
1794
a1c7c0f3
ILT
1795 case SIZE_WORD: /* Word */
1796 if (isvar (&opP->disp))
1797 add_fix ('w', &opP->disp, 0, 0);
355afbcd
KR
1798
1799 tmpreg = 0x38;/* 7.0 mode */
1800 addword (nextword);
1801 break;
1802 }
1803 break;
a1c7c0f3
ILT
1804 case CONTROL:
1805 case FPREG:
355afbcd
KR
1806 default:
1807 as_bad ("unknown/incorrect operand");
1808 /* abort(); */
1809 }
1810 install_gen_operand (s[1], tmpreg);
6d27d3a2 1811 break;
6d27d3a2 1812
355afbcd
KR
1813 case '#':
1814 case '^':
1815 switch (s[1])
1816 { /* JF: I hate floating point! */
1817 case 'j':
1818 tmpreg = 70;
1819 break;
1820 case '8':
1821 tmpreg = 20;
1822 break;
1823 case 'C':
1824 tmpreg = 50;
1825 break;
1826 case '3':
1827 default:
1828 tmpreg = 80;
1829 break;
1830 }
a1c7c0f3
ILT
1831 tmpreg = get_num (&opP->disp, tmpreg);
1832 if (isvar (&opP->disp))
1833 add_fix (s[1], &opP->disp, 0, 0);
355afbcd
KR
1834 switch (s[1])
1835 {
1836 case 'b': /* Danger: These do no check for
6d27d3a2
KR
1837 certain types of overflow.
1838 user beware! */
355afbcd
KR
1839 if (!isbyte (tmpreg))
1840 opP->error = "out of range";
bcb8dff8 1841 insop (tmpreg, opcode);
a1c7c0f3 1842 if (isvar (&opP->disp))
355afbcd
KR
1843 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
1844 break;
1845 case 'w':
1846 if (!isword (tmpreg))
1847 opP->error = "out of range";
bcb8dff8 1848 insop (tmpreg, opcode);
a1c7c0f3 1849 if (isvar (&opP->disp))
355afbcd
KR
1850 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
1851 break;
1852 case 'l':
bcb8dff8
KR
1853 /* Because of the way insop works, we put these two out
1854 backwards. */
1855 insop (tmpreg, opcode);
1856 insop (tmpreg >> 16, opcode);
a1c7c0f3 1857 if (isvar (&opP->disp))
355afbcd
KR
1858 the_ins.reloc[the_ins.nrel - 1].n = (opcode->m_codenum) * 2;
1859 break;
1860 case '3':
1861 tmpreg &= 0xFF;
1862 case '8':
1863 case 'C':
1864 install_operand (s[1], tmpreg);
1865 break;
1866 default:
a1c7c0f3 1867 abort ();
355afbcd
KR
1868 }
1869 break;
6d27d3a2 1870
355afbcd
KR
1871 case '+':
1872 case '-':
1873 case 'A':
1874 case 'a':
1875 install_operand (s[1], opP->reg - ADDR);
1876 break;
6d27d3a2 1877
355afbcd 1878 case 'B':
a1c7c0f3 1879 tmpreg = get_num (&opP->disp, 80);
355afbcd
KR
1880 switch (s[1])
1881 {
1882 case 'B':
a1c7c0f3 1883 add_fix ('B', &opP->disp, 1, -1);
355afbcd
KR
1884 break;
1885 case 'W':
a1c7c0f3 1886 add_fix ('w', &opP->disp, 1, 0);
355afbcd
KR
1887 addword (0);
1888 break;
1889 case 'L':
1890 long_branch:
a1c7c0f3 1891 if (cpu_of_arch (current_architecture) < m68020)
355afbcd
KR
1892 as_warn ("Can't use long branches on 68000/68010");
1893 the_ins.opcode[the_ins.numo - 1] |= 0xff;
a1c7c0f3 1894 add_fix ('l', &opP->disp, 1, 0);
355afbcd
KR
1895 addword (0);
1896 addword (0);
1897 break;
1898 case 'g':
a1c7c0f3 1899 if (subs (&opP->disp)) /* We can't relax it */
355afbcd 1900 goto long_branch;
6d27d3a2 1901
a1c7c0f3
ILT
1902 /* This could either be a symbol, or an absolute
1903 address. No matter, the frag hacking will finger it
1904 out. Not quite: it can't switch from BRANCH to
1905 BCC68000 for the case where opnd is absolute (it
1906 needs to use the 68000 hack since no conditional abs
1907 jumps). */
b79de3a1 1908 if (((cpu_of_arch (current_architecture) < m68020)
a1c7c0f3 1909 || (0 == adds (&opP->disp)))
355afbcd
KR
1910 && (the_ins.opcode[0] >= 0x6200)
1911 && (the_ins.opcode[0] <= 0x6f00))
a1c7c0f3
ILT
1912 add_frag (adds (&opP->disp), offs (&opP->disp),
1913 TAB (BCC68000, SZ_UNDEF));
355afbcd 1914 else
a1c7c0f3
ILT
1915 add_frag (adds (&opP->disp), offs (&opP->disp),
1916 TAB (ABRANCH, SZ_UNDEF));
355afbcd
KR
1917 break;
1918 case 'w':
a1c7c0f3 1919 if (isvar (&opP->disp))
355afbcd 1920 {
49864cfa 1921#if 1
355afbcd
KR
1922 /* check for DBcc instruction */
1923 if ((the_ins.opcode[0] & 0xf0f8) == 0x50c8)
1924 {
1925 /* size varies if patch */
1926 /* needed for long form */
a1c7c0f3 1927 add_frag (adds (&opP->disp), offs (&opP->disp),
b79de3a1 1928 TAB (DBCC, SZ_UNDEF));
355afbcd
KR
1929 break;
1930 }
49864cfa 1931#endif
a1c7c0f3 1932 add_fix ('w', &opP->disp, 1, 0);
355afbcd
KR
1933 }
1934 addword (0);
1935 break;
1936 case 'C': /* Fixed size LONG coproc branches */
a1c7c0f3 1937 add_fix ('l', &opP->disp, 1, 0);
355afbcd
KR
1938 addword (0);
1939 addword (0);
1940 break;
1941 case 'c': /* Var size Coprocesssor branches */
a1c7c0f3 1942 if (subs (&opP->disp))
355afbcd 1943 {
a1c7c0f3 1944 add_fix ('l', &opP->disp, 1, 0);
355afbcd
KR
1945 add_frag ((symbolS *) 0, (long) 0, TAB (FBRANCH, LONG));
1946 }
a1c7c0f3
ILT
1947 else if (adds (&opP->disp))
1948 add_frag (adds (&opP->disp), offs (&opP->disp),
1949 TAB (FBRANCH, SZ_UNDEF));
355afbcd
KR
1950 else
1951 {
a1c7c0f3
ILT
1952 /* add_frag((symbolS *) 0, offs(&opP->disp),
1953 TAB(FBRANCH,SHORT)); */
355afbcd 1954 the_ins.opcode[the_ins.numo - 1] |= 0x40;
a1c7c0f3 1955 add_fix ('l', &opP->disp, 1, 0);
5f8cb05e 1956 addword (0);
355afbcd 1957 addword (0);
355afbcd
KR
1958 }
1959 break;
1960 default:
a1c7c0f3 1961 abort ();
355afbcd
KR
1962 }
1963 break;
6d27d3a2 1964
355afbcd
KR
1965 case 'C': /* Ignore it */
1966 break;
6d27d3a2 1967
355afbcd 1968 case 'd': /* JF this is a kludge */
a1c7c0f3
ILT
1969 install_operand ('s', opP->reg - ADDR);
1970 tmpreg = get_num (&opP->disp, 80);
355afbcd
KR
1971 if (!issword (tmpreg))
1972 {
1973 as_warn ("Expression out of range, using 0");
1974 tmpreg = 0;
1975 }
1976 addword (tmpreg);
1977 break;
6d27d3a2 1978
355afbcd
KR
1979 case 'D':
1980 install_operand (s[1], opP->reg - DATA);
1981 break;
6d27d3a2 1982
355afbcd 1983 case 'F':
a1c7c0f3 1984 install_operand (s[1], opP->reg - FP0);
355afbcd 1985 break;
6d27d3a2 1986
355afbcd 1987 case 'I':
27a53b88 1988 tmpreg = opP->reg - COP0;
355afbcd
KR
1989 install_operand (s[1], tmpreg);
1990 break;
6d27d3a2 1991
355afbcd
KR
1992 case 'J': /* JF foo */
1993 switch (opP->reg)
1994 {
1995 case SFC:
1996 tmpreg = 0x000;
1997 break;
1998 case DFC:
1999 tmpreg = 0x001;
2000 break;
2001 case CACR:
2002 tmpreg = 0x002;
2003 break;
2004 case TC:
2005 tmpreg = 0x003;
2006 break;
2007 case ITT0:
2008 tmpreg = 0x004;
2009 break;
2010 case ITT1:
2011 tmpreg = 0x005;
2012 break;
2013 case DTT0:
2014 tmpreg = 0x006;
2015 break;
2016 case DTT1:
2017 tmpreg = 0x007;
2018 break;
9ad5755f
KR
2019 case BUSCR:
2020 tmpreg = 0x008;
2021 break;
6d27d3a2 2022
355afbcd
KR
2023 case USP:
2024 tmpreg = 0x800;
2025 break;
2026 case VBR:
2027 tmpreg = 0x801;
2028 break;
2029 case CAAR:
2030 tmpreg = 0x802;
2031 break;
2032 case MSP:
2033 tmpreg = 0x803;
2034 break;
2035 case ISP:
2036 tmpreg = 0x804;
2037 break;
2038 case MMUSR:
2039 tmpreg = 0x805;
2040 break;
2041 case URP:
2042 tmpreg = 0x806;
2043 break;
2044 case SRP:
2045 tmpreg = 0x807;
2046 break;
9ad5755f
KR
2047 case PCR:
2048 tmpreg = 0x808;
2049 break;
355afbcd 2050 default:
a1c7c0f3 2051 abort ();
355afbcd
KR
2052 }
2053 install_operand (s[1], tmpreg);
2054 break;
6d27d3a2 2055
355afbcd 2056 case 'k':
a1c7c0f3 2057 tmpreg = get_num (&opP->disp, 55);
355afbcd
KR
2058 install_operand (s[1], tmpreg & 0x7f);
2059 break;
6d27d3a2 2060
355afbcd 2061 case 'l':
a1c7c0f3 2062 tmpreg = opP->mask;
355afbcd
KR
2063 if (s[1] == 'w')
2064 {
2065 if (tmpreg & 0x7FF0000)
2066 as_bad ("Floating point register in register list");
bcb8dff8 2067 insop (reverse_16_bits (tmpreg), opcode);
355afbcd
KR
2068 }
2069 else
2070 {
2071 if (tmpreg & 0x700FFFF)
2072 as_bad ("Wrong register in floating-point reglist");
2073 install_operand (s[1], reverse_8_bits (tmpreg >> 16));
2074 }
2075 break;
6d27d3a2 2076
355afbcd 2077 case 'L':
a1c7c0f3 2078 tmpreg = opP->mask;
355afbcd
KR
2079 if (s[1] == 'w')
2080 {
2081 if (tmpreg & 0x7FF0000)
2082 as_bad ("Floating point register in register list");
bcb8dff8 2083 insop (tmpreg, opcode);
355afbcd
KR
2084 }
2085 else if (s[1] == '8')
2086 {
2087 if (tmpreg & 0x0FFFFFF)
2088 as_bad ("incorrect register in reglist");
2089 install_operand (s[1], tmpreg >> 24);
2090 }
2091 else
2092 {
2093 if (tmpreg & 0x700FFFF)
2094 as_bad ("wrong register in floating-point reglist");
2095 else
2096 install_operand (s[1], tmpreg >> 16);
2097 }
2098 break;
6d27d3a2 2099
355afbcd 2100 case 'M':
a1c7c0f3 2101 install_operand (s[1], get_num (&opP->disp, 60));
355afbcd 2102 break;
6d27d3a2 2103
355afbcd 2104 case 'O':
a1c7c0f3
ILT
2105 tmpreg = ((opP->mode == DREG)
2106 ? 0x20 + opP->reg - DATA
2107 : (get_num (&opP->disp, 40) & 0x1F));
355afbcd
KR
2108 install_operand (s[1], tmpreg);
2109 break;
6d27d3a2 2110
355afbcd 2111 case 'Q':
a1c7c0f3 2112 tmpreg = get_num (&opP->disp, 10);
355afbcd
KR
2113 if (tmpreg == 8)
2114 tmpreg = 0;
2115 install_operand (s[1], tmpreg);
2116 break;
2117
2118 case 'R':
a1c7c0f3
ILT
2119 /* This depends on the fact that ADDR registers are eight
2120 more than their corresponding DATA regs, so the result
2121 will have the ADDR_REG bit set */
355afbcd
KR
2122 install_operand (s[1], opP->reg - DATA);
2123 break;
6d27d3a2 2124
a1c7c0f3
ILT
2125 case 'r':
2126 if (opP->mode == AINDR)
2127 install_operand (s[1], opP->reg - DATA);
2128 else
2129 install_operand (s[1], opP->index.reg - DATA);
2130 break;
2131
355afbcd
KR
2132 case 's':
2133 if (opP->reg == FPI)
2134 tmpreg = 0x1;
2135 else if (opP->reg == FPS)
2136 tmpreg = 0x2;
2137 else if (opP->reg == FPC)
2138 tmpreg = 0x4;
2139 else
a1c7c0f3 2140 abort ();
355afbcd
KR
2141 install_operand (s[1], tmpreg);
2142 break;
6d27d3a2 2143
355afbcd
KR
2144 case 'S': /* Ignore it */
2145 break;
6d27d3a2 2146
355afbcd 2147 case 'T':
a1c7c0f3 2148 install_operand (s[1], get_num (&opP->disp, 30));
355afbcd 2149 break;
6d27d3a2 2150
355afbcd
KR
2151 case 'U': /* Ignore it */
2152 break;
6d27d3a2 2153
355afbcd
KR
2154 case 'c':
2155 switch (opP->reg)
2156 {
2157 case NC:
2158 tmpreg = 0;
2159 break;
2160 case DC:
2161 tmpreg = 1;
2162 break;
2163 case IC:
2164 tmpreg = 2;
2165 break;
2166 case BC:
2167 tmpreg = 3;
2168 break;
2169 default:
2170 as_fatal ("failed sanity check");
2171 } /* switch on cache token */
2172 install_operand (s[1], tmpreg);
2173 break;
a39116f1 2174#ifndef NO_68851
355afbcd
KR
2175 /* JF: These are out of order, I fear. */
2176 case 'f':
2177 switch (opP->reg)
2178 {
2179 case SFC:
2180 tmpreg = 0;
2181 break;
2182 case DFC:
2183 tmpreg = 1;
2184 break;
2185 default:
a1c7c0f3 2186 abort ();
355afbcd
KR
2187 }
2188 install_operand (s[1], tmpreg);
2189 break;
6d27d3a2 2190
355afbcd
KR
2191 case 'P':
2192 switch (opP->reg)
2193 {
2194 case TC:
2195 tmpreg = 0;
2196 break;
2197 case CAL:
2198 tmpreg = 4;
2199 break;
2200 case VAL:
2201 tmpreg = 5;
2202 break;
2203 case SCC:
2204 tmpreg = 6;
2205 break;
2206 case AC:
2207 tmpreg = 7;
2208 break;
2209 default:
a1c7c0f3 2210 abort ();
355afbcd
KR
2211 }
2212 install_operand (s[1], tmpreg);
2213 break;
6d27d3a2 2214
355afbcd
KR
2215 case 'V':
2216 if (opP->reg == VAL)
2217 break;
a1c7c0f3 2218 abort ();
6d27d3a2 2219
355afbcd
KR
2220 case 'W':
2221 switch (opP->reg)
2222 {
355afbcd
KR
2223 case DRP:
2224 tmpreg = 1;
2225 break;
2226 case SRP:
2227 tmpreg = 2;
2228 break;
2229 case CRP:
2230 tmpreg = 3;
2231 break;
2232 default:
a1c7c0f3 2233 abort ();
355afbcd
KR
2234 }
2235 install_operand (s[1], tmpreg);
2236 break;
6d27d3a2 2237
355afbcd
KR
2238 case 'X':
2239 switch (opP->reg)
2240 {
2241 case BAD:
2242 case BAD + 1:
2243 case BAD + 2:
2244 case BAD + 3:
2245 case BAD + 4:
2246 case BAD + 5:
2247 case BAD + 6:
2248 case BAD + 7:
2249 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
2250 break;
6d27d3a2 2251
355afbcd
KR
2252 case BAC:
2253 case BAC + 1:
2254 case BAC + 2:
2255 case BAC + 3:
2256 case BAC + 4:
2257 case BAC + 5:
2258 case BAC + 6:
2259 case BAC + 7:
2260 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
2261 break;
6d27d3a2 2262
355afbcd 2263 default:
a1c7c0f3 2264 abort ();
355afbcd
KR
2265 }
2266 install_operand (s[1], tmpreg);
2267 break;
2268 case 'Y':
2269 know (opP->reg == PSR);
2270 break;
2271 case 'Z':
2272 know (opP->reg == PCSR);
2273 break;
f8701a3f 2274#endif /* m68851 */
355afbcd
KR
2275 case '3':
2276 switch (opP->reg)
2277 {
2278 case TT0:
2279 tmpreg = 2;
2280 break;
2281 case TT1:
2282 tmpreg = 3;
2283 break;
2284 default:
a1c7c0f3 2285 abort ();
355afbcd
KR
2286 }
2287 install_operand (s[1], tmpreg);
2288 break;
2289 case 't':
a1c7c0f3 2290 tmpreg = get_num (&opP->disp, 20);
355afbcd 2291 install_operand (s[1], tmpreg);
4134a793 2292 break;
a1c7c0f3
ILT
2293 case '_': /* used only for move16 absolute 32-bit address */
2294 tmpreg = get_num (&opP->disp, 80);
355afbcd
KR
2295 addword (tmpreg >> 16);
2296 addword (tmpreg & 0xFFFF);
4134a793
KR
2297 break;
2298 default:
a1c7c0f3 2299 abort ();
4134a793 2300 }
6d27d3a2 2301 }
3ad9ec6a 2302
6d27d3a2
KR
2303 /* By the time whe get here (FINALLY) the_ins contains the complete
2304 instruction, ready to be emitted. . . */
a1c7c0f3 2305}
fecd2382 2306
355afbcd
KR
2307static int
2308reverse_16_bits (in)
2309 int in;
fecd2382 2310{
355afbcd
KR
2311 int out = 0;
2312 int n;
6d27d3a2 2313
355afbcd
KR
2314 static int mask[16] =
2315 {
2316 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2317 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000
2318 };
2319 for (n = 0; n < 16; n++)
2320 {
2321 if (in & mask[n])
2322 out |= mask[15 - n];
2323 }
2324 return out;
2325} /* reverse_16_bits() */
fecd2382 2326
355afbcd
KR
2327static int
2328reverse_8_bits (in)
2329 int in;
fecd2382 2330{
355afbcd
KR
2331 int out = 0;
2332 int n;
6d27d3a2 2333
355afbcd
KR
2334 static int mask[8] =
2335 {
2336 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
2337 };
6d27d3a2 2338
355afbcd
KR
2339 for (n = 0; n < 8; n++)
2340 {
2341 if (in & mask[n])
2342 out |= mask[7 - n];
2343 }
2344 return out;
2345} /* reverse_8_bits() */
fecd2382 2346
04ef74bb
KR
2347/* Cause an extra frag to be generated here, inserting up to 10 bytes
2348 (that value is chosen in the frag_var call in md_assemble). TYPE
2349 is the subtype of the frag to be generated; its primary type is
2350 rs_machine_dependent.
2351
2352 The TYPE parameter is also used by md_convert_frag_1 and
2353 md_estimate_size_before_relax. The appropriate type of fixup will
2354 be emitted by md_convert_frag_1.
2355
2356 ADD becomes the FR_SYMBOL field of the frag, and OFF the FR_OFFSET. */
355afbcd
KR
2357static void
2358install_operand (mode, val)
2359 int mode;
2360 int val;
fecd2382 2361{
355afbcd
KR
2362 switch (mode)
2363 {
2364 case 's':
2365 the_ins.opcode[0] |= val & 0xFF; /* JF FF is for M kludge */
2366 break;
2367 case 'd':
2368 the_ins.opcode[0] |= val << 9;
2369 break;
2370 case '1':
2371 the_ins.opcode[1] |= val << 12;
2372 break;
2373 case '2':
2374 the_ins.opcode[1] |= val << 6;
2375 break;
2376 case '3':
2377 the_ins.opcode[1] |= val;
2378 break;
2379 case '4':
2380 the_ins.opcode[2] |= val << 12;
2381 break;
2382 case '5':
2383 the_ins.opcode[2] |= val << 6;
2384 break;
2385 case '6':
bcb8dff8
KR
2386 /* DANGER! This is a hack to force cas2l and cas2w cmds to be
2387 three words long! */
355afbcd
KR
2388 the_ins.numo++;
2389 the_ins.opcode[2] |= val;
2390 break;
2391 case '7':
2392 the_ins.opcode[1] |= val << 7;
2393 break;
2394 case '8':
2395 the_ins.opcode[1] |= val << 10;
2396 break;
f8701a3f 2397#ifndef NO_68851
355afbcd
KR
2398 case '9':
2399 the_ins.opcode[1] |= val << 5;
2400 break;
f8701a3f 2401#endif
6d27d3a2 2402
355afbcd
KR
2403 case 't':
2404 the_ins.opcode[1] |= (val << 10) | (val << 7);
2405 break;
2406 case 'D':
2407 the_ins.opcode[1] |= (val << 12) | val;
2408 break;
2409 case 'g':
2410 the_ins.opcode[0] |= val = 0xff;
2411 break;
2412 case 'i':
2413 the_ins.opcode[0] |= val << 9;
2414 break;
2415 case 'C':
2416 the_ins.opcode[1] |= val;
2417 break;
2418 case 'j':
2419 the_ins.opcode[1] |= val;
2420 the_ins.numo++; /* What a hack */
2421 break;
2422 case 'k':
2423 the_ins.opcode[1] |= val << 4;
2424 break;
2425 case 'b':
2426 case 'w':
2427 case 'l':
2428 break;
2429 case 'e':
2430 the_ins.opcode[0] |= (val << 6);
2431 break;
2432 case 'L':
2433 the_ins.opcode[1] = (val >> 16);
2434 the_ins.opcode[2] = val & 0xffff;
2435 break;
2436 case 'c':
2437 default:
2438 as_fatal ("failed sanity check.");
2439 }
2440} /* install_operand() */
fecd2382 2441
355afbcd
KR
2442static void
2443install_gen_operand (mode, val)
2444 int mode;
2445 int val;
fecd2382 2446{
355afbcd
KR
2447 switch (mode)
2448 {
2449 case 's':
2450 the_ins.opcode[0] |= val;
2451 break;
2452 case 'd':
2453 /* This is a kludge!!! */
2454 the_ins.opcode[0] |= (val & 0x07) << 9 | (val & 0x38) << 3;
2455 break;
2456 case 'b':
2457 case 'w':
2458 case 'l':
2459 case 'f':
2460 case 'F':
2461 case 'x':
2462 case 'p':
2463 the_ins.opcode[0] |= val;
2464 break;
2465 /* more stuff goes here */
2466 default:
2467 as_fatal ("failed sanity check.");
2468 }
2469} /* install_gen_operand() */
fecd2382 2470
7c15cbe8
RP
2471/*
2472 * verify that we have some number of paren pairs, do m68k_ip_op(), and
2473 * then deal with the bitfield hack.
2474 */
2475
355afbcd
KR
2476static char *
2477crack_operand (str, opP)
2478 register char *str;
2479 register struct m68k_op *opP;
fecd2382 2480{
355afbcd
KR
2481 register int parens;
2482 register int c;
2483 register char *beg_str;
6d27d3a2 2484
355afbcd
KR
2485 if (!str)
2486 {
2487 return str;
2488 }
2489 beg_str = str;
2490 for (parens = 0; *str && (parens > 0 || notend (str)); str++)
2491 {
2492 if (*str == '(')
2493 parens++;
2494 else if (*str == ')')
2495 {
2496 if (!parens)
2497 { /* ERROR */
2498 opP->error = "Extra )";
2499 return str;
2500 }
2501 --parens;
f8701a3f 2502 }
355afbcd
KR
2503 }
2504 if (!*str && parens)
2505 { /* ERROR */
2506 opP->error = "Missing )";
2507 return str;
2508 }
2509 c = *str;
2510 *str = '\0';
a1c7c0f3 2511 if (m68k_ip_op (beg_str, opP) != 0)
355afbcd
KR
2512 {
2513 *str = c;
2514 return str;
2515 }
2516 *str = c;
2517 if (c == '}')
2518 c = *++str; /* JF bitfield hack */
2519 if (c)
2520 {
2521 c = *++str;
2522 if (!c)
2523 as_bad ("Missing operand");
2524 }
2525 return str;
fecd2382
RP
2526}
2527
fecd2382 2528/* This is the guts of the machine-dependent assembler. STR points to a
7c15cbe8 2529 machine dependent instruction. This function is supposed to emit
fecd2382 2530 the frags/bytes it assembles to.
a39116f1 2531 */
a933d598
SC
2532
2533void
355afbcd
KR
2534insert_reg (regname, regnum)
2535 char *regname;
2536 int regnum;
a933d598
SC
2537{
2538 char buf[100];
2539 int i;
355afbcd
KR
2540
2541#ifdef REGISTER_PREFIX
82489ea0
KR
2542 if (!flag_reg_prefix_optional)
2543 {
2544 buf[0] = REGISTER_PREFIX;
2545 strcpy (buf + 1, regname);
2546 regname = buf;
2547 }
355afbcd
KR
2548#endif
2549
82489ea0
KR
2550 symbol_table_insert (symbol_new (regname, reg_section, regnum,
2551 &zero_address_frag));
a933d598
SC
2552
2553 for (i = 0; regname[i]; i++)
355afbcd 2554 buf[i] = islower (regname[i]) ? toupper (regname[i]) : regname[i];
a933d598 2555 buf[i] = '\0';
6d27d3a2 2556
82489ea0
KR
2557 symbol_table_insert (symbol_new (buf, reg_section, regnum,
2558 &zero_address_frag));
a933d598
SC
2559}
2560
49864cfa 2561struct init_entry
355afbcd 2562 {
bcb8dff8 2563 const char *name;
355afbcd 2564 int number;
49864cfa 2565 };
355afbcd 2566
bcb8dff8 2567static const struct init_entry init_table[] =
355afbcd 2568{
bcb8dff8
KR
2569 { "d0", DATA0 },
2570 { "d1", DATA1 },
2571 { "d2", DATA2 },
2572 { "d3", DATA3 },
2573 { "d4", DATA4 },
2574 { "d5", DATA5 },
2575 { "d6", DATA6 },
2576 { "d7", DATA7 },
2577 { "a0", ADDR0 },
2578 { "a1", ADDR1 },
2579 { "a2", ADDR2 },
2580 { "a3", ADDR3 },
2581 { "a4", ADDR4 },
2582 { "a5", ADDR5 },
2583 { "a6", ADDR6 },
2584 { "fp", ADDR6 },
2585 { "a7", ADDR7 },
2586 { "sp", ADDR7 },
a1c7c0f3 2587 { "ssp", ADDR7 },
bcb8dff8
KR
2588 { "fp0", FP0 },
2589 { "fp1", FP1 },
2590 { "fp2", FP2 },
2591 { "fp3", FP3 },
2592 { "fp4", FP4 },
2593 { "fp5", FP5 },
2594 { "fp6", FP6 },
2595 { "fp7", FP7 },
2596 { "fpi", FPI },
2597 { "fpiar", FPI },
2598 { "fpc", FPI },
2599 { "fps", FPS },
2600 { "fpsr", FPS },
2601 { "fpc", FPC },
2602 { "fpcr", FPC },
064ba683
ILT
2603 { "control", FPC },
2604 { "status", FPS },
2605 { "iaddr", FPI },
bcb8dff8
KR
2606
2607 { "cop0", COP0 },
2608 { "cop1", COP1 },
2609 { "cop2", COP2 },
2610 { "cop3", COP3 },
2611 { "cop4", COP4 },
2612 { "cop5", COP5 },
2613 { "cop6", COP6 },
2614 { "cop7", COP7 },
2615 { "pc", PC },
2616 { "zpc", ZPC },
2617 { "sr", SR },
2618
2619 { "ccr", CCR },
2620 { "cc", CCR },
2621
2622 { "usp", USP },
2623 { "isp", ISP },
2624 { "sfc", SFC },
064ba683 2625 { "sfcr", SFC },
bcb8dff8 2626 { "dfc", DFC },
064ba683 2627 { "dfcr", DFC },
bcb8dff8
KR
2628 { "cacr", CACR },
2629 { "caar", CAAR },
2630
2631 { "vbr", VBR },
2632
2633 { "msp", MSP },
2634 { "itt0", ITT0 },
2635 { "itt1", ITT1 },
2636 { "dtt0", DTT0 },
2637 { "dtt1", DTT1 },
2638 { "mmusr", MMUSR },
2639 { "tc", TC },
2640 { "srp", SRP },
2641 { "urp", URP },
9ad5755f
KR
2642 { "buscr", BUSCR },
2643 { "pcr", PCR },
bcb8dff8
KR
2644
2645 { "ac", AC },
2646 { "bc", BC },
2647 { "cal", CAL },
2648 { "crp", CRP },
2649 { "drp", DRP },
2650 { "pcsr", PCSR },
2651 { "psr", PSR },
2652 { "scc", SCC },
2653 { "val", VAL },
2654 { "bad0", BAD0 },
2655 { "bad1", BAD1 },
2656 { "bad2", BAD2 },
2657 { "bad3", BAD3 },
2658 { "bad4", BAD4 },
2659 { "bad5", BAD5 },
2660 { "bad6", BAD6 },
2661 { "bad7", BAD7 },
2662 { "bac0", BAC0 },
2663 { "bac1", BAC1 },
2664 { "bac2", BAC2 },
2665 { "bac3", BAC3 },
2666 { "bac4", BAC4 },
2667 { "bac5", BAC5 },
2668 { "bac6", BAC6 },
2669 { "bac7", BAC7 },
2670
2671 { "ic", IC },
2672 { "dc", DC },
2673 { "nc", NC },
2674
2675 { "tt0", TT0 },
2676 { "tt1", TT1 },
4134a793 2677 /* 68ec030 versions of same */
bcb8dff8
KR
2678 { "ac0", TT0 },
2679 { "ac1", TT1 },
4134a793 2680 /* 68ec030 access control unit, identical to 030 MMU status reg */
bcb8dff8 2681 { "acusr", PSR },
a933d598 2682
a1c7c0f3
ILT
2683 /* Suppressed data and address registers. */
2684 { "zd0", ZDATA0 },
2685 { "zd1", ZDATA1 },
2686 { "zd2", ZDATA2 },
2687 { "zd3", ZDATA3 },
2688 { "zd4", ZDATA4 },
2689 { "zd5", ZDATA5 },
2690 { "zd6", ZDATA6 },
2691 { "zd7", ZDATA7 },
2692 { "za0", ZADDR0 },
2693 { "za1", ZADDR1 },
2694 { "za2", ZADDR2 },
2695 { "za3", ZADDR3 },
2696 { "za4", ZADDR4 },
2697 { "za5", ZADDR5 },
2698 { "za6", ZADDR6 },
2699 { "za7", ZADDR7 },
2700
bcb8dff8 2701 { 0, 0 }
a933d598
SC
2702};
2703
a933d598 2704void
355afbcd 2705init_regtable ()
a933d598
SC
2706{
2707 int i;
6d27d3a2 2708 for (i = 0; init_table[i].name; i++)
355afbcd 2709 insert_reg (init_table[i].name, init_table[i].number);
a933d598 2710}
6d27d3a2 2711
df3768fb 2712static int no_68851, no_68881;
a933d598 2713
dff60b7d
ILT
2714#ifdef OBJ_AOUT
2715/* a.out machine type. Default to 68020. */
2716int m68k_aout_machtype = 2;
2717#endif
2718
fecd2382 2719void
355afbcd 2720md_assemble (str)
6d27d3a2 2721 char *str;
fecd2382 2722{
a1c7c0f3 2723 const char *er;
355afbcd
KR
2724 short *fromP;
2725 char *toP = NULL;
2726 int m, n = 0;
2727 char *to_beg_P;
2728 int shorts_this_frag;
5f8cb05e 2729 fixS *fixP;
6d27d3a2 2730
e284846a 2731 memset ((char *) (&the_ins), '\0', sizeof (the_ins));
355afbcd
KR
2732 m68k_ip (str);
2733 er = the_ins.error;
2734 if (!er)
2735 {
a1c7c0f3 2736 for (n = 0; n < the_ins.numargs; n++)
355afbcd
KR
2737 if (the_ins.operands[n].error)
2738 {
2739 er = the_ins.operands[n].error;
2740 break;
2741 }
2742 }
2743 if (er)
2744 {
2745 as_bad ("%s -- statement `%s' ignored", er, str);
2746 return;
2747 }
6d27d3a2 2748
355afbcd 2749 if (the_ins.nfrag == 0)
49864cfa
KR
2750 {
2751 /* No frag hacking involved; just put it out */
355afbcd
KR
2752 toP = frag_more (2 * the_ins.numo);
2753 fromP = &the_ins.opcode[0];
2754 for (m = the_ins.numo; m; --m)
2755 {
2756 md_number_to_chars (toP, (long) (*fromP), 2);
2757 toP += 2;
2758 fromP++;
f8701a3f 2759 }
355afbcd
KR
2760 /* put out symbol-dependent info */
2761 for (m = 0; m < the_ins.nrel; m++)
2762 {
2763 switch (the_ins.reloc[m].wid)
2764 {
2765 case 'B':
2766 n = 1;
2767 break;
2768 case 'b':
2769 n = 1;
2770 break;
2771 case '3':
2772 n = 2;
2773 break;
2774 case 'w':
2775 n = 2;
2776 break;
2777 case 'l':
2778 n = 4;
2779 break;
2780 default:
49864cfa
KR
2781 as_fatal ("Don't know how to figure width of %c in md_assemble()",
2782 the_ins.reloc[m].wid);
355afbcd 2783 }
6d27d3a2 2784
5f8cb05e
ILT
2785 fixP = fix_new_exp (frag_now,
2786 ((toP - frag_now->fr_literal)
2787 - the_ins.numo * 2 + the_ins.reloc[m].n),
2788 n,
2789 &the_ins.reloc[m].exp,
2790 the_ins.reloc[m].pcrel,
2791 NO_RELOC);
2792 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
f8701a3f 2793 }
355afbcd
KR
2794 return;
2795 }
2796
2797 /* There's some frag hacking */
2798 for (n = 0, fromP = &the_ins.opcode[0]; n < the_ins.nfrag; n++)
2799 {
2800 int wid;
2801
2802 if (n == 0)
2803 wid = 2 * the_ins.fragb[n].fragoff;
2804 else
2805 wid = 2 * (the_ins.numo - the_ins.fragb[n - 1].fragoff);
2806 toP = frag_more (wid);
2807 to_beg_P = toP;
2808 shorts_this_frag = 0;
2809 for (m = wid / 2; m; --m)
2810 {
2811 md_number_to_chars (toP, (long) (*fromP), 2);
2812 toP += 2;
2813 fromP++;
2814 shorts_this_frag++;
2815 }
2816 for (m = 0; m < the_ins.nrel; m++)
2817 {
49864cfa 2818 if ((the_ins.reloc[m].n) >= 2 * shorts_this_frag)
355afbcd 2819 {
49864cfa 2820 the_ins.reloc[m].n -= 2 * shorts_this_frag;
355afbcd
KR
2821 break;
2822 }
2823 wid = the_ins.reloc[m].wid;
2824 if (wid == 0)
2825 continue;
2826 the_ins.reloc[m].wid = 0;
2827 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
2828
5f8cb05e
ILT
2829 fixP = fix_new_exp (frag_now,
2830 ((toP - frag_now->fr_literal)
2831 - the_ins.numo * 2 + the_ins.reloc[m].n),
2832 wid,
2833 &the_ins.reloc[m].exp,
2834 the_ins.reloc[m].pcrel,
2835 NO_RELOC);
2836 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
fecd2382 2837 }
49864cfa
KR
2838 (void) frag_var (rs_machine_dependent, 10, 0,
2839 (relax_substateT) (the_ins.fragb[n].fragty),
2840 the_ins.fragb[n].fadd, the_ins.fragb[n].foff, to_beg_P);
355afbcd
KR
2841 }
2842 n = (the_ins.numo - the_ins.fragb[n - 1].fragoff);
2843 shorts_this_frag = 0;
2844 if (n)
2845 {
2846 toP = frag_more (n * sizeof (short));
2847 while (n--)
2848 {
2849 md_number_to_chars (toP, (long) (*fromP), 2);
2850 toP += 2;
2851 fromP++;
2852 shorts_this_frag++;
fecd2382 2853 }
355afbcd
KR
2854 }
2855 for (m = 0; m < the_ins.nrel; m++)
2856 {
2857 int wid;
2858
2859 wid = the_ins.reloc[m].wid;
2860 if (wid == 0)
2861 continue;
2862 the_ins.reloc[m].wid = 0;
2863 wid = (wid == 'b') ? 1 : (wid == 'w') ? 2 : (wid == 'l') ? 4 : 4000;
2864
5f8cb05e
ILT
2865 fixP = fix_new_exp (frag_now,
2866 ((the_ins.reloc[m].n + toP - frag_now->fr_literal)
2867 - shorts_this_frag * 2),
2868 wid,
2869 &the_ins.reloc[m].exp,
2870 the_ins.reloc[m].pcrel,
2871 NO_RELOC);
2872 fixP->fx_pcrel_adjust = the_ins.reloc[m].pcrel_fix;
355afbcd 2873 }
fecd2382
RP
2874}
2875
fecd2382 2876void
355afbcd 2877md_begin ()
fecd2382 2878{
355afbcd 2879 /*
e284846a
KR
2880 * md_begin -- set up hash tables with 68000 instructions.
2881 * similar to what the vax assembler does. ---phr
2882 */
355afbcd 2883 /* RMS claims the thing to do is take the m68k-opcode.h table, and make
e284846a
KR
2884 a copy of it at runtime, adding in the information we want but isn't
2885 there. I think it'd be better to have an awk script hack the table
2886 at compile time. Or even just xstr the table and use it as-is. But
2887 my lord ghod hath spoken, so we do it this way. Excuse the ugly var
2888 names. */
6d27d3a2 2889
b79de3a1 2890 register const struct m68k_opcode *ins;
355afbcd 2891 register struct m68k_incant *hack, *slak;
bcb8dff8 2892 register const char *retval = 0; /* empty string, or error msg text */
355afbcd
KR
2893 register unsigned int i;
2894 register char c;
2895
064ba683 2896 if (flag_mri)
6700d36e
ILT
2897 {
2898 flag_reg_prefix_optional = 1;
2899 m68k_abspcadd = 1;
2900 m68k_rel32 = 0;
2901 }
064ba683 2902
82489ea0 2903 op_hash = hash_new ();
355afbcd
KR
2904
2905 obstack_begin (&robyn, 4000);
a1c7c0f3 2906 for (i = 0; i < m68k_numopcodes; i++)
355afbcd
KR
2907 {
2908 hack = slak = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
2909 do
2910 {
a1c7c0f3 2911 ins = &m68k_opcodes[i];
e284846a
KR
2912 /* We *could* ignore insns that don't match our arch here
2913 but just leaving them out of the hash. */
355afbcd
KR
2914 slak->m_operands = ins->args;
2915 slak->m_opnum = strlen (slak->m_operands) / 2;
2916 slak->m_arch = ins->arch;
2917 slak->m_opcode = ins->opcode;
2918 /* This is kludgey */
2919 slak->m_codenum = ((ins->match) & 0xffffL) ? 2 : 1;
a1c7c0f3
ILT
2920 if (i + 1 != m68k_numopcodes
2921 && !strcmp (ins->name, m68k_opcodes[i + 1].name))
355afbcd
KR
2922 {
2923 slak->m_next = (struct m68k_incant *) obstack_alloc (&robyn, sizeof (struct m68k_incant));
e284846a 2924 i++;
355afbcd
KR
2925 }
2926 else
2927 slak->m_next = 0;
2928 slak = slak->m_next;
f8701a3f 2929 }
355afbcd
KR
2930 while (slak);
2931
2932 retval = hash_insert (op_hash, ins->name, (char *) hack);
dff60b7d 2933 if (retval)
b79de3a1
KR
2934 as_fatal ("Internal Error: Can't hash %s: %s", ins->name, retval);
2935 }
2936
a1c7c0f3 2937 for (i = 0; i < m68k_numaliases; i++)
b79de3a1
KR
2938 {
2939 const char *name = m68k_opcode_aliases[i].primary;
2940 const char *alias = m68k_opcode_aliases[i].alias;
2941 PTR val = hash_find (op_hash, name);
2942 if (!val)
2943 as_fatal ("Internal Error: Can't find %s in hash table", name);
2944 retval = hash_insert (op_hash, alias, val);
2945 if (retval)
2946 as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
355afbcd 2947 }
6d27d3a2 2948
6700d36e
ILT
2949 /* In MRI mode, all unsized branches are variable sized. Normally,
2950 they are word sized. */
2951 if (flag_mri)
2952 {
2953 static struct m68k_opcode_alias mri_aliases[] =
2954 {
2955 { "bhi", "jhi", },
2956 { "bls", "jls", },
2957 { "bcc", "jcc", },
2958 { "bcs", "jcs", },
2959 { "bne", "jne", },
2960 { "beq", "jeq", },
2961 { "bvc", "jvc", },
2962 { "bvs", "jvs", },
2963 { "bpl", "jpl", },
2964 { "bmi", "jmi", },
2965 { "bge", "jge", },
2966 { "blt", "jlt", },
2967 { "bgt", "jgt", },
2968 { "ble", "jle", },
2969 { "bra", "jra", },
2970 { "bsr", "jbsr", },
2971 };
2972
2973 for (i = 0; i < sizeof mri_aliases / sizeof mri_aliases[0]; i++)
2974 {
2975 const char *name = mri_aliases[i].primary;
2976 const char *alias = mri_aliases[i].alias;
2977 PTR val = hash_find (op_hash, name);
2978 if (!val)
2979 as_fatal ("Internal Error: Can't find %s in hash table", name);
2980 retval = hash_jam (op_hash, alias, val);
2981 if (retval)
2982 as_fatal ("Internal Error: Can't hash %s: %s", alias, retval);
2983 }
2984 }
2985
355afbcd
KR
2986 for (i = 0; i < sizeof (mklower_table); i++)
2987 mklower_table[i] = (isupper (c = (char) i)) ? tolower (c) : c;
6d27d3a2 2988
355afbcd
KR
2989 for (i = 0; i < sizeof (notend_table); i++)
2990 {
2991 notend_table[i] = 0;
2992 alt_notend_table[i] = 0;
2993 }
2994 notend_table[','] = 1;
2995 notend_table['{'] = 1;
2996 notend_table['}'] = 1;
2997 alt_notend_table['a'] = 1;
2998 alt_notend_table['A'] = 1;
2999 alt_notend_table['d'] = 1;
3000 alt_notend_table['D'] = 1;
3001 alt_notend_table['#'] = 1;
5f8cb05e 3002 alt_notend_table['&'] = 1;
355afbcd
KR
3003 alt_notend_table['f'] = 1;
3004 alt_notend_table['F'] = 1;
fecd2382 3005#ifdef REGISTER_PREFIX
355afbcd 3006 alt_notend_table[REGISTER_PREFIX] = 1;
fecd2382 3007#endif
f8701a3f 3008
a1c7c0f3
ILT
3009 /* We need to put '(' in alt_notend_table to handle
3010 cas2 %d0:%d2,%d3:%d4,(%a0):(%a1)
3011 */
3012 alt_notend_table['('] = 1;
3013
3014 /* We need to put '@' in alt_notend_table to handle
3015 cas2 %d0:%d2,%d3:%d4,@(%d0):@(%d1)
3016 */
3017 alt_notend_table['@'] = 1;
3018
3ad9ec6a 3019#ifndef MIT_SYNTAX_ONLY
355afbcd 3020 /* Insert pseudo ops, these have to go into the opcode table since
bcb8dff8 3021 gas expects pseudo ops to start with a dot */
355afbcd
KR
3022 {
3023 int n = 0;
3024 while (mote_pseudo_table[n].poc_name)
3025 {
3026 hack = (struct m68k_incant *)
3027 obstack_alloc (&robyn, sizeof (struct m68k_incant));
3028 hash_insert (op_hash,
3029 mote_pseudo_table[n].poc_name, (char *) hack);
3030 hack->m_operands = 0;
3031 hack->m_opnum = n;
3032 n++;
3033 }
3034 }
3ad9ec6a
ILT
3035#endif
3036
355afbcd 3037 init_regtable ();
fecd2382
RP
3038}
3039
82489ea0
KR
3040void
3041m68k_init_after_args ()
3042{
3043 if (cpu_of_arch (current_architecture) == 0)
3044 {
064ba683 3045 int i;
b79de3a1 3046 const char *default_cpu = TARGET_CPU;
82489ea0 3047
b79de3a1
KR
3048 if (*default_cpu == 'm')
3049 default_cpu++;
3050 for (i = 0; i < n_archs; i++)
e9bb39b4 3051 if (strcasecmp (default_cpu, archs[i].name) == 0)
b79de3a1
KR
3052 break;
3053 if (i == n_archs)
3054 {
3055 as_bad ("unrecognized default cpu `%s' ???", TARGET_CPU);
3056 current_architecture |= m68020;
3057 }
3058 else
3059 current_architecture |= archs[i].arch;
82489ea0 3060 }
b79de3a1
KR
3061 /* Permit m68881 specification with all cpus; those that can't work
3062 with a coprocessor could be doing emulation. */
82489ea0
KR
3063 if (current_architecture & m68851)
3064 {
3065 if (current_architecture & m68040)
3066 {
3067 as_warn ("68040 and 68851 specified; mmu instructions may assemble incorrectly");
3068 }
3069 }
3070 /* What other incompatibilities could we check for? */
3071
3072 /* Toss in some default assumptions about coprocessors. */
3073 if (!no_68881
3074 && (cpu_of_arch (current_architecture)
3075 /* Can CPU32 have a 68881 coprocessor?? */
3076 & (m68020 | m68030 | cpu32)))
3077 {
3078 current_architecture |= m68881;
3079 }
3080 if (!no_68851
3081 && (cpu_of_arch (current_architecture) & m68020up) != 0
3082 && (cpu_of_arch (current_architecture) & m68040up) == 0)
3083 {
3084 current_architecture |= m68851;
3085 }
3086 if (no_68881 && (current_architecture & m68881))
3087 as_bad ("options for 68881 and no-68881 both given");
3088 if (no_68851 && (current_architecture & m68851))
3089 as_bad ("options for 68851 and no-68851 both given");
3090
3091#ifdef OBJ_AOUT
3092 /* Work out the magic number. This isn't very general. */
3093 if (current_architecture & m68000)
3094 m68k_aout_machtype = 0;
3095 else if (current_architecture & m68010)
3096 m68k_aout_machtype = 1;
3097 else if (current_architecture & m68020)
3098 m68k_aout_machtype = 2;
3099 else
3100 m68k_aout_machtype = 2;
3101#endif
3102
3103 /* Note which set of "movec" control registers is available. */
3104 switch (cpu_of_arch (current_architecture))
3105 {
3106 case m68000:
3107 control_regs = m68000_control_regs;
3108 break;
3109 case m68010:
3110 control_regs = m68010_control_regs;
3111 break;
3112 case m68020:
3113 case m68030:
3114 control_regs = m68020_control_regs;
3115 break;
3116 case m68040:
3117 control_regs = m68040_control_regs;
3118 break;
3119 case m68060:
3120 control_regs = m68060_control_regs;
3121 break;
b79de3a1
KR
3122 case cpu32:
3123 control_regs = cpu32_control_regs;
3124 break;
82489ea0
KR
3125 default:
3126 abort ();
3127 }
04ef74bb
KR
3128
3129 if (cpu_of_arch (current_architecture) < m68020)
3130 md_relax_table[TAB (PCINDEX, BYTE)].rlx_more = 0;
82489ea0
KR
3131}
3132
fecd2382
RP
3133/* Equal to MAX_PRECISION in atof-ieee.c */
3134#define MAX_LITTLENUMS 6
3135
a1c7c0f3
ILT
3136/* Turn a string in input_line_pointer into a floating point constant
3137 of type type, and store the appropriate bytes in *litP. The number
3138 of LITTLENUMS emitted is stored in *sizeP . An error message is
3139 returned, or NULL on OK. */
3140
fecd2382 3141char *
355afbcd
KR
3142md_atof (type, litP, sizeP)
3143 char type;
3144 char *litP;
3145 int *sizeP;
fecd2382 3146{
355afbcd
KR
3147 int prec;
3148 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3149 LITTLENUM_TYPE *wordP;
3150 char *t;
3151 char *atof_ieee ();
6d27d3a2 3152
355afbcd
KR
3153 switch (type)
3154 {
3155 case 'f':
3156 case 'F':
3157 case 's':
3158 case 'S':
3159 prec = 2;
3160 break;
6d27d3a2 3161
355afbcd
KR
3162 case 'd':
3163 case 'D':
3164 case 'r':
3165 case 'R':
3166 prec = 4;
3167 break;
6d27d3a2 3168
355afbcd
KR
3169 case 'x':
3170 case 'X':
3171 prec = 6;
3172 break;
6d27d3a2 3173
355afbcd
KR
3174 case 'p':
3175 case 'P':
3176 prec = 6;
3177 break;
6d27d3a2 3178
355afbcd
KR
3179 default:
3180 *sizeP = 0;
3181 return "Bad call to MD_ATOF()";
3182 }
3183 t = atof_ieee (input_line_pointer, type, words);
3184 if (t)
3185 input_line_pointer = t;
3186
3187 *sizeP = prec * sizeof (LITTLENUM_TYPE);
3188 for (wordP = words; prec--;)
3189 {
3190 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
3191 litP += sizeof (LITTLENUM_TYPE);
3192 }
49864cfa 3193 return 0;
fecd2382
RP
3194}
3195
fecd2382 3196void
355afbcd
KR
3197md_number_to_chars (buf, val, n)
3198 char *buf;
025b0302 3199 valueT val;
355afbcd 3200 int n;
fecd2382 3201{
82489ea0 3202 number_to_chars_bigendian (buf, val, n);
fecd2382
RP
3203}
3204
49864cfa
KR
3205static void
3206md_apply_fix_2 (fixP, val)
355afbcd 3207 fixS *fixP;
9ad5755f 3208 offsetT val;
fecd2382 3209{
9ad5755f
KR
3210 addressT upper_limit;
3211 offsetT lower_limit;
49864cfa 3212
9ad5755f
KR
3213 /* This is unnecessary but it convinces the native rs6000 compiler
3214 to generate the code we want. */
355afbcd
KR
3215 char *buf = fixP->fx_frag->fr_literal;
3216 buf += fixP->fx_where;
9ad5755f
KR
3217 /* end ibm compiler workaround */
3218
3219 if (val & 0x80000000)
3220 val |= ~(addressT)0x7fffffff;
3221 else
3222 val &= 0x7fffffff;
6d27d3a2 3223
355afbcd
KR
3224 switch (fixP->fx_size)
3225 {
b79de3a1
KR
3226 /* The cast to offsetT below are necessary to make code correct for
3227 machines where ints are smaller than offsetT */
355afbcd
KR
3228 case 1:
3229 *buf++ = val;
49864cfa 3230 upper_limit = 0x7f;
b79de3a1 3231 lower_limit = - (offsetT) 0x80;
355afbcd
KR
3232 break;
3233 case 2:
3234 *buf++ = (val >> 8);
3235 *buf++ = val;
49864cfa 3236 upper_limit = 0x7fff;
b79de3a1 3237 lower_limit = - (offsetT) 0x8000;
355afbcd
KR
3238 break;
3239 case 4:
3240 *buf++ = (val >> 24);
3241 *buf++ = (val >> 16);
3242 *buf++ = (val >> 8);
3243 *buf++ = val;
49864cfa 3244 upper_limit = 0x7fffffff;
b79de3a1 3245 lower_limit = - (offsetT) 0x7fffffff - 1; /* avoid constant overflow */
355afbcd
KR
3246 break;
3247 default:
3248 BAD_CASE (fixP->fx_size);
3249 }
49864cfa
KR
3250
3251 /* For non-pc-relative values, it's conceivable we might get something
3252 like "0xff" for a byte field. So extend the upper part of the range
3253 to accept such numbers. We arbitrarily disallow "-0xff" or "0xff+0xff",
3254 so that we can do any range checking at all. */
3255 if (!fixP->fx_pcrel)
3256 upper_limit = upper_limit * 2 + 1;
3257
9ad5755f
KR
3258 if ((addressT) val > upper_limit
3259 && (val > 0 || val < lower_limit))
f3751617
ILT
3260 as_bad_where (fixP->fx_file, fixP->fx_line, "value out of range");
3261
3262 /* A one byte PC-relative reloc means a short branch. We can't use
3263 a short branch with a value of 0 or -1, because those indicate
3264 different opcodes (branches with longer offsets). */
3265 if (fixP->fx_pcrel
3266 && fixP->fx_size == 1
3267 && (fixP->fx_addsy == NULL
3268 || S_IS_DEFINED (fixP->fx_addsy))
3269 && (val == 0 || val == -1))
3270 as_bad_where (fixP->fx_file, fixP->fx_line, "invalid byte branch offset");
fecd2382
RP
3271}
3272
49864cfa
KR
3273#ifdef BFD_ASSEMBLER
3274int
3275md_apply_fix (fixP, valp)
3276 fixS *fixP;
5f8cb05e 3277 valueT *valp;
49864cfa 3278{
9ad5755f 3279 md_apply_fix_2 (fixP, (addressT) *valp);
49864cfa
KR
3280 return 1;
3281}
3282#else
3283void md_apply_fix (fixP, val)
3284 fixS *fixP;
3285 long val;
3286{
9ad5755f 3287 md_apply_fix_2 (fixP, (addressT) val);
49864cfa
KR
3288}
3289#endif
fecd2382
RP
3290
3291/* *fragP has been relaxed to its final size, and now needs to have
3292 the bytes inside it modified to conform to the new size There is UGLY
3293 MAGIC here. ..
a39116f1 3294 */
fecd2382 3295void
49864cfa 3296md_convert_frag_1 (fragP)
355afbcd 3297 register fragS *fragP;
fecd2382 3298{
355afbcd
KR
3299 long disp;
3300 long ext = 0;
5f8cb05e 3301 fixS *fixP;
6d27d3a2 3302
355afbcd
KR
3303 /* Address in object code of the displacement. */
3304 register int object_address = fragP->fr_fix + fragP->fr_address;
6d27d3a2 3305
9ad5755f
KR
3306 /* Address in gas core of the place to store the displacement. */
3307 /* This convinces the native rs6000 compiler to generate the code we
3308 want. */
355afbcd
KR
3309 register char *buffer_address = fragP->fr_literal;
3310 buffer_address += fragP->fr_fix;
9ad5755f 3311 /* end ibm compiler workaround */
6d27d3a2 3312
355afbcd
KR
3313 /* The displacement of the address, from current location. */
3314 disp = fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0;
3315 disp = (disp + fragP->fr_offset) - object_address;
6d27d3a2 3316
5f8cb05e
ILT
3317#ifdef BFD_ASSEMBLER
3318 disp += fragP->fr_symbol->sy_frag->fr_address;
3319#endif
3320
355afbcd
KR
3321 switch (fragP->fr_subtype)
3322 {
3323 case TAB (BCC68000, BYTE):
3324 case TAB (ABRANCH, BYTE):
3325 know (issbyte (disp));
3326 if (disp == 0)
3327 as_bad ("short branch with zero offset: use :w");
3328 fragP->fr_opcode[1] = disp;
3329 ext = 0;
3330 break;
3331 case TAB (DBCC, SHORT):
3332 know (issword (disp));
3333 ext = 2;
3334 break;
3335 case TAB (BCC68000, SHORT):
3336 case TAB (ABRANCH, SHORT):
3337 know (issword (disp));
3338 fragP->fr_opcode[1] = 0x00;
3339 ext = 2;
3340 break;
3341 case TAB (ABRANCH, LONG):
3342 if (cpu_of_arch (current_architecture) < m68020)
3343 {
3344 if (fragP->fr_opcode[0] == 0x61)
04ef74bb 3345 /* BSR */
355afbcd
KR
3346 {
3347 fragP->fr_opcode[0] = 0x4E;
bcb8dff8 3348 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
49864cfa 3349 subseg_change (text_section, 0); /* @@ */
355afbcd
KR
3350
3351 fix_new (fragP,
3352 fragP->fr_fix,
3353 4,
3354 fragP->fr_symbol,
355afbcd
KR
3355 fragP->fr_offset,
3356 0,
3357 NO_RELOC);
3358
3359 fragP->fr_fix += 4;
3360 ext = 0;
3361 }
04ef74bb 3362 /* BRA */
355afbcd
KR
3363 else if (fragP->fr_opcode[0] == 0x60)
3364 {
3365 fragP->fr_opcode[0] = 0x4E;
bcb8dff8 3366 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
49864cfa 3367 subseg_change (text_section, 0); /* @@ */
bcb8dff8
KR
3368 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
3369 fragP->fr_offset, 0, NO_RELOC);
355afbcd
KR
3370 fragP->fr_fix += 4;
3371 ext = 0;
3372 }
3373 else
3374 {
3375 as_bad ("Long branch offset not supported.");
3376 }
3377 }
3378 else
3379 {
bcb8dff8 3380 fragP->fr_opcode[1] = (char) 0xff;
355afbcd
KR
3381 ext = 4;
3382 }
3383 break;
3384 case TAB (BCC68000, LONG):
3385 /* only Bcc 68000 instructions can come here */
3386 /* change bcc into b!cc/jmp absl long */
3387 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
3388 fragP->fr_opcode[1] = 0x6;/* branch offset = 6 */
6d27d3a2 3389
355afbcd 3390 /* JF: these used to be fr_opcode[2,3], but they may be in a
fecd2382
RP
3391 different frag, in which case refering to them is a no-no.
3392 Only fr_opcode[0,1] are guaranteed to work. */
355afbcd 3393 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
bcb8dff8 3394 *buffer_address++ = (char) 0xf9;
355afbcd 3395 fragP->fr_fix += 2; /* account for jmp instruction */
49864cfa 3396 subseg_change (text_section, 0);
bcb8dff8
KR
3397 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
3398 fragP->fr_offset, 0, NO_RELOC);
355afbcd
KR
3399 fragP->fr_fix += 4;
3400 ext = 0;
3401 break;
3402 case TAB (DBCC, LONG):
3403 /* only DBcc 68000 instructions can come here */
3404 /* change dbcc into dbcc/jmp absl long */
3405 /* JF: these used to be fr_opcode[2-7], but that's wrong */
3406 *buffer_address++ = 0x00; /* branch offset = 4 */
3407 *buffer_address++ = 0x04;
3408 *buffer_address++ = 0x60; /* put in bra pc+6 */
3409 *buffer_address++ = 0x06;
3410 *buffer_address++ = 0x4e; /* put in jmp long (0x4ef9) */
bcb8dff8 3411 *buffer_address++ = (char) 0xf9;
355afbcd
KR
3412
3413 fragP->fr_fix += 6; /* account for bra/jmp instructions */
49864cfa 3414 subseg_change (text_section, 0);
bcb8dff8 3415 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
49864cfa 3416 fragP->fr_offset, 0, NO_RELOC);
355afbcd
KR
3417 fragP->fr_fix += 4;
3418 ext = 0;
3419 break;
3420 case TAB (FBRANCH, SHORT):
3421 know ((fragP->fr_opcode[1] & 0x40) == 0);
3422 ext = 2;
3423 break;
3424 case TAB (FBRANCH, LONG):
3425 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
3426 ext = 4;
3427 break;
3428 case TAB (PCREL, SHORT):
3429 ext = 2;
3430 break;
3431 case TAB (PCREL, LONG):
3432 /* The thing to do here is force it to ABSOLUTE LONG, since
f8701a3f 3433 PCREL is really trying to shorten an ABSOLUTE address anyway */
355afbcd 3434 /* JF FOO This code has not been tested */
49864cfa 3435 subseg_change (text_section, 0);
bcb8dff8 3436 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol, fragP->fr_offset,
49864cfa 3437 0, NO_RELOC);
355afbcd 3438 if ((fragP->fr_opcode[1] & 0x3F) != 0x3A)
bcb8dff8
KR
3439 as_bad ("Internal error (long PC-relative operand) for insn 0x%04x at 0x%lx",
3440 (unsigned) fragP->fr_opcode[0],
3441 (unsigned long) fragP->fr_address);
355afbcd
KR
3442 fragP->fr_opcode[1] &= ~0x3F;
3443 fragP->fr_opcode[1] |= 0x39; /* Mode 7.1 */
3444 fragP->fr_fix += 4;
355afbcd
KR
3445 ext = 0;
3446 break;
3447 case TAB (PCLEA, SHORT):
49864cfa
KR
3448 subseg_change (text_section, 0);
3449 fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
bcb8dff8 3450 fragP->fr_offset, 1, NO_RELOC);
355afbcd 3451 fragP->fr_opcode[1] &= ~0x3F;
04ef74bb 3452 fragP->fr_opcode[1] |= 0x3A; /* 072 - mode 7.2 */
355afbcd
KR
3453 ext = 2;
3454 break;
3455 case TAB (PCLEA, LONG):
49864cfa 3456 subseg_change (text_section, 0);
5f8cb05e
ILT
3457 fixP = fix_new (fragP, (int) (fragP->fr_fix) + 2, 4, fragP->fr_symbol,
3458 fragP->fr_offset, 1, NO_RELOC);
3459 fixP->fx_pcrel_adjust = 2;
04ef74bb
KR
3460 /* Already set to mode 7.3; this indicates: PC indirect with
3461 suppressed index, 32-bit displacement. */
355afbcd
KR
3462 *buffer_address++ = 0x01;
3463 *buffer_address++ = 0x70;
3464 fragP->fr_fix += 2;
355afbcd
KR
3465 ext = 4;
3466 break;
04ef74bb
KR
3467
3468 case TAB (PCINDEX, BYTE):
3469 disp += 2;
3470 if (!issbyte (disp))
3471 {
3472 as_bad ("displacement doesn't fit in one byte");
3473 disp = 0;
3474 }
5f8cb05e
ILT
3475 assert (fragP->fr_fix >= 2);
3476 buffer_address[-2] &= ~1;
3477 buffer_address[-1] = disp;
04ef74bb
KR
3478 ext = 0;
3479 break;
3480 case TAB (PCINDEX, SHORT):
3481 subseg_change (text_section, 0);
3482 disp += 2;
3483 assert (issword (disp));
5f8cb05e
ILT
3484 assert (fragP->fr_fix >= 2);
3485 buffer_address[-2] |= 0x1;
3486 buffer_address[-1] = 0x20;
3487 fixP = fix_new (fragP, (int) (fragP->fr_fix), 2, fragP->fr_symbol,
3488 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
3489 NO_RELOC);
3490 fixP->fx_pcrel_adjust = 2;
04ef74bb
KR
3491 ext = 2;
3492 break;
3493 case TAB (PCINDEX, LONG):
3494 subseg_change (text_section, 0);
3495 disp += 2;
5f8cb05e
ILT
3496 fixP = fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
3497 fragP->fr_offset, (fragP->fr_opcode[1] & 077) == 073,
3498 NO_RELOC);
3499 fixP->fx_pcrel_adjust = 2;
3500 assert (fragP->fr_fix >= 2);
3501 buffer_address[-2] |= 0x1;
3502 buffer_address[-1] = 0x30;
04ef74bb
KR
3503 ext = 4;
3504 break;
49864cfa 3505 }
355afbcd
KR
3506
3507 if (ext)
3508 {
3509 md_number_to_chars (buffer_address, (long) disp, (int) ext);
3510 fragP->fr_fix += ext;
49864cfa
KR
3511 }
3512}
355afbcd 3513
49864cfa
KR
3514#ifndef BFD_ASSEMBLER
3515
3516void
064ba683 3517md_convert_frag (headers, sec, fragP)
49864cfa 3518 object_headers *headers;
064ba683 3519 segT sec;
49864cfa
KR
3520 fragS *fragP;
3521{
3522 md_convert_frag_1 (fragP);
3523}
3524
3525#else
3526
3527void
3528md_convert_frag (abfd, sec, fragP)
3529 bfd *abfd;
5f8cb05e 3530 segT sec;
49864cfa
KR
3531 fragS *fragP;
3532{
3533 md_convert_frag_1 (fragP);
3534}
3535#endif
355afbcd
KR
3536
3537/* Force truly undefined symbols to their maximum size, and generally set up
3538 the frag list to be relaxed
3539 */
3540int
3541md_estimate_size_before_relax (fragP, segment)
3542 register fragS *fragP;
3543 segT segment;
3544{
3545 int old_fix;
3546 register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
3547
3548 old_fix = fragP->fr_fix;
3549
3550 /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
3551 switch (fragP->fr_subtype)
3552 {
3553
3554 case TAB (ABRANCH, SZ_UNDEF):
3555 {
3556 if ((fragP->fr_symbol != NULL) /* Not absolute */
3557 && S_GET_SEGMENT (fragP->fr_symbol) == segment)
3558 {
3559 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), BYTE);
3560 break;
3561 }
3562 else if ((fragP->fr_symbol == 0) || (cpu_of_arch (current_architecture) < m68020))
3563 {
3564 /* On 68000, or for absolute value, switch to abs long */
3565 /* FIXME, we should check abs val, pick short or long */
3566 if (fragP->fr_opcode[0] == 0x61)
3567 {
3568 fragP->fr_opcode[0] = 0x4E;
bcb8dff8 3569 fragP->fr_opcode[1] = (char) 0xB9; /* JBSR with ABSL LONG offset */
49864cfa 3570 subseg_change (text_section, 0);
355afbcd 3571 fix_new (fragP, fragP->fr_fix, 4,
bcb8dff8 3572 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
355afbcd
KR
3573 fragP->fr_fix += 4;
3574 frag_wane (fragP);
3575 }
3576 else if (fragP->fr_opcode[0] == 0x60)
3577 {
3578 fragP->fr_opcode[0] = 0x4E;
bcb8dff8 3579 fragP->fr_opcode[1] = (char) 0xF9; /* JMP with ABSL LONG offset */
49864cfa 3580 subseg_change (text_section, 0);
355afbcd 3581 fix_new (fragP, fragP->fr_fix, 4,
bcb8dff8 3582 fragP->fr_symbol, fragP->fr_offset, 0, NO_RELOC);
355afbcd
KR
3583 fragP->fr_fix += 4;
3584 frag_wane (fragP);
3585 }
3586 else
3587 {
3588 as_warn ("Long branch offset to extern symbol not supported.");
3589 }
3590 }
3591 else
3592 { /* Symbol is still undefined. Make it simple */
3593 fix_new (fragP, (int) (fragP->fr_fix), 4, fragP->fr_symbol,
5f8cb05e 3594 fragP->fr_offset, 1, NO_RELOC);
355afbcd 3595 fragP->fr_fix += 4;
bcb8dff8 3596 fragP->fr_opcode[1] = (char) 0xff;
355afbcd
KR
3597 frag_wane (fragP);
3598 break;
3599 }
3600
a39116f1 3601 break;
355afbcd 3602 } /* case TAB(ABRANCH,SZ_UNDEF) */
6d27d3a2 3603
355afbcd
KR
3604 case TAB (FBRANCH, SZ_UNDEF):
3605 {
9ad5755f 3606 if (S_GET_SEGMENT (fragP->fr_symbol) == segment || flag_short_refs)
355afbcd
KR
3607 {
3608 fragP->fr_subtype = TAB (FBRANCH, SHORT);
3609 fragP->fr_var += 2;
3610 }
3611 else
3612 {
5f8cb05e
ILT
3613 fix_new (fragP, (int) fragP->fr_fix, 4, fragP->fr_symbol,
3614 fragP->fr_offset, 1, NO_RELOC);
3615 fragP->fr_fix += 4;
3616 fragP->fr_opcode[1] |= 0x40; /* Turn on LONG bit */
3617 frag_wane (fragP);
355afbcd
KR
3618 }
3619 break;
3620 } /* TAB(FBRANCH,SZ_UNDEF) */
6d27d3a2 3621
355afbcd
KR
3622 case TAB (PCREL, SZ_UNDEF):
3623 {
b79de3a1
KR
3624 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
3625 || flag_short_refs
3626 || cpu_of_arch (current_architecture) < m68020)
355afbcd
KR
3627 {
3628 fragP->fr_subtype = TAB (PCREL, SHORT);
3629 fragP->fr_var += 2;
3630 }
3631 else
3632 {
3633 fragP->fr_subtype = TAB (PCREL, LONG);
3634 fragP->fr_var += 4;
3635 }
3636 break;
3637 } /* TAB(PCREL,SZ_UNDEF) */
6d27d3a2 3638
355afbcd
KR
3639 case TAB (BCC68000, SZ_UNDEF):
3640 {
3641 if ((fragP->fr_symbol != NULL)
3642 && S_GET_SEGMENT (fragP->fr_symbol) == segment)
3643 {
3644 fragP->fr_subtype = TAB (BCC68000, BYTE);
3645 break;
3646 }
3647 /* only Bcc 68000 instructions can come here */
3648 /* change bcc into b!cc/jmp absl long */
3649 fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
9ad5755f 3650 if (flag_short_refs)
355afbcd
KR
3651 {
3652 fragP->fr_opcode[1] = 0x04; /* branch offset = 6 */
3653 /* JF: these were fr_opcode[2,3] */
3654 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
bcb8dff8 3655 buffer_address[1] = (char) 0xf8;
355afbcd 3656 fragP->fr_fix += 2; /* account for jmp instruction */
49864cfa 3657 subseg_change (text_section, 0);
bcb8dff8 3658 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
355afbcd
KR
3659 fragP->fr_offset, 0, NO_RELOC);
3660 fragP->fr_fix += 2;
3661 }
3662 else
3663 {
3664 fragP->fr_opcode[1] = 0x06; /* branch offset = 6 */
3665 /* JF: these were fr_opcode[2,3] */
3666 buffer_address[0] = 0x4e; /* put in jmp long (0x4ef9) */
bcb8dff8 3667 buffer_address[1] = (char) 0xf9;
355afbcd 3668 fragP->fr_fix += 2; /* account for jmp instruction */
49864cfa 3669 subseg_change (text_section, 0);
bcb8dff8 3670 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
355afbcd
KR
3671 fragP->fr_offset, 0, NO_RELOC);
3672 fragP->fr_fix += 4;
3673 }
3674 frag_wane (fragP);
3675 break;
3676 } /* case TAB(BCC68000,SZ_UNDEF) */
f8701a3f 3677
355afbcd
KR
3678 case TAB (DBCC, SZ_UNDEF):
3679 {
3680 if (fragP->fr_symbol != NULL && S_GET_SEGMENT (fragP->fr_symbol) == segment)
3681 {
3682 fragP->fr_subtype = TAB (DBCC, SHORT);
3683 fragP->fr_var += 2;
3684 break;
3685 }
3686 /* only DBcc 68000 instructions can come here */
3687 /* change dbcc into dbcc/jmp absl long */
3688 /* JF: these used to be fr_opcode[2-4], which is wrong. */
3689 buffer_address[0] = 0x00; /* branch offset = 4 */
3690 buffer_address[1] = 0x04;
3691 buffer_address[2] = 0x60; /* put in bra pc + ... */
3692
9ad5755f 3693 if (flag_short_refs)
355afbcd
KR
3694 {
3695 /* JF: these were fr_opcode[5-7] */
3696 buffer_address[3] = 0x04; /* plus 4 */
3697 buffer_address[4] = 0x4e; /* Put in Jump Word */
bcb8dff8 3698 buffer_address[5] = (char) 0xf8;
355afbcd 3699 fragP->fr_fix += 6; /* account for bra/jmp instruction */
49864cfa 3700 subseg_change (text_section, 0);
bcb8dff8 3701 fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
355afbcd
KR
3702 fragP->fr_offset, 0, NO_RELOC);
3703 fragP->fr_fix += 2;
3704 }
3705 else
3706 {
3707 /* JF: these were fr_opcode[5-7] */
3708 buffer_address[3] = 0x06; /* Plus 6 */
3709 buffer_address[4] = 0x4e; /* put in jmp long (0x4ef9) */
bcb8dff8 3710 buffer_address[5] = (char) 0xf9;
355afbcd 3711 fragP->fr_fix += 6; /* account for bra/jmp instruction */
49864cfa 3712 subseg_change (text_section, 0);
bcb8dff8 3713 fix_new (fragP, fragP->fr_fix, 4, fragP->fr_symbol,
355afbcd
KR
3714 fragP->fr_offset, 0, NO_RELOC);
3715 fragP->fr_fix += 4;
3716 }
6d27d3a2 3717
355afbcd
KR
3718 frag_wane (fragP);
3719 break;
3720 } /* case TAB(DBCC,SZ_UNDEF) */
6d27d3a2 3721
355afbcd
KR
3722 case TAB (PCLEA, SZ_UNDEF):
3723 {
b79de3a1
KR
3724 if ((S_GET_SEGMENT (fragP->fr_symbol)) == segment
3725 || flag_short_refs
3726 || cpu_of_arch (current_architecture) < m68020)
355afbcd
KR
3727 {
3728 fragP->fr_subtype = TAB (PCLEA, SHORT);
3729 fragP->fr_var += 2;
3730 }
3731 else
3732 {
3733 fragP->fr_subtype = TAB (PCLEA, LONG);
3734 fragP->fr_var += 6;
3735 }
3736 break;
3737 } /* TAB(PCLEA,SZ_UNDEF) */
6d27d3a2 3738
04ef74bb
KR
3739 case TAB (PCINDEX, SZ_UNDEF):
3740 if (S_GET_SEGMENT (fragP->fr_symbol) == segment
3741 || cpu_of_arch (current_architecture) < m68020)
3742 {
3743 fragP->fr_subtype = TAB (PCINDEX, BYTE);
3744 }
3745 else
3746 {
3747 fragP->fr_subtype = TAB (PCINDEX, LONG);
5f8cb05e 3748 fragP->fr_var += 4;
04ef74bb 3749 }
355afbcd 3750 break;
6d27d3a2 3751
04ef74bb
KR
3752 default:
3753 break;
3754 }
6d27d3a2 3755
355afbcd
KR
3756 /* now that SZ_UNDEF are taken care of, check others */
3757 switch (fragP->fr_subtype)
3758 {
3759 case TAB (BCC68000, BYTE):
3760 case TAB (ABRANCH, BYTE):
3761 /* We can't do a short jump to the next instruction,
a39116f1 3762 so we force word mode. */
355afbcd
KR
3763 if (fragP->fr_symbol && S_GET_VALUE (fragP->fr_symbol) == 0 &&
3764 fragP->fr_symbol->sy_frag == fragP->fr_next)
3765 {
3766 fragP->fr_subtype = TAB (TABTYPE (fragP->fr_subtype), SHORT);
3767 fragP->fr_var += 2;
fecd2382 3768 }
355afbcd
KR
3769 break;
3770 default:
3771 break;
3772 }
3773 return fragP->fr_var + fragP->fr_fix - old_fix;
fecd2382
RP
3774}
3775
3776#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
6d27d3a2 3777/* the bit-field entries in the relocation_info struct plays hell
fecd2382
RP
3778 with the byte-order problems of cross-assembly. So as a hack,
3779 I added this mach. dependent ri twiddler. Ugly, but it gets
3780 you there. -KWK */
3781/* on m68k: first 4 bytes are normal unsigned long, next three bytes
a39116f1
RP
3782 are symbolnum, most sig. byte first. Last byte is broken up with
3783 bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
3784 nibble as nuthin. (on Sun 3 at least) */
fecd2382
RP
3785/* Translate the internal relocation information into target-specific
3786 format. */
a79c6033 3787#ifdef comment
fecd2382 3788void
355afbcd
KR
3789md_ri_to_chars (the_bytes, ri)
3790 char *the_bytes;
3791 struct reloc_info_generic *ri;
fecd2382 3792{
355afbcd
KR
3793 /* this is easy */
3794 md_number_to_chars (the_bytes, ri->r_address, 4);
3795 /* now the fun stuff */
3796 the_bytes[4] = (ri->r_symbolnum >> 16) & 0x0ff;
3797 the_bytes[5] = (ri->r_symbolnum >> 8) & 0x0ff;
3798 the_bytes[6] = ri->r_symbolnum & 0x0ff;
3799 the_bytes[7] = (((ri->r_pcrel << 7) & 0x80) | ((ri->r_length << 5) & 0x60) |
3800 ((ri->r_extern << 4) & 0x10));
fecd2382 3801}
355afbcd 3802
a79c6033
RP
3803#endif /* comment */
3804
49864cfa 3805#ifndef BFD_ASSEMBLER
355afbcd
KR
3806void
3807tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
3808 char *where;
3809 fixS *fixP;
3810 relax_addressT segment_address_in_file;
a79c6033 3811{
355afbcd 3812 /*
1404ef23
KR
3813 * In: length of relocation (or of address) in chars: 1, 2 or 4.
3814 * Out: GNU LD relocation length code: 0, 1, or 2.
3815 */
6d27d3a2 3816
82489ea0 3817 static CONST unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
355afbcd 3818 long r_symbolnum;
6d27d3a2 3819
355afbcd 3820 know (fixP->fx_addsy != NULL);
6d27d3a2 3821
355afbcd
KR
3822 md_number_to_chars (where,
3823 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
3824 4);
6d27d3a2 3825
355afbcd
KR
3826 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
3827 ? S_GET_TYPE (fixP->fx_addsy)
3828 : fixP->fx_addsy->sy_number);
6d27d3a2 3829
355afbcd
KR
3830 where[4] = (r_symbolnum >> 16) & 0x0ff;
3831 where[5] = (r_symbolnum >> 8) & 0x0ff;
3832 where[6] = r_symbolnum & 0x0ff;
3833 where[7] = (((fixP->fx_pcrel << 7) & 0x80) | ((nbytes_r_length[fixP->fx_size] << 5) & 0x60) |
3834 (((!S_IS_DEFINED (fixP->fx_addsy)) << 4) & 0x10));
49864cfa
KR
3835}
3836#endif
a79c6033 3837
fecd2382
RP
3838#endif /* OBJ_AOUT or OBJ_BOUT */
3839
3840#ifndef WORKING_DOT_WORD
49864cfa
KR
3841CONST int md_short_jump_size = 4;
3842CONST int md_long_jump_size = 6;
fecd2382
RP
3843
3844void
355afbcd
KR
3845md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
3846 char *ptr;
025b0302 3847 addressT from_addr, to_addr;
355afbcd
KR
3848 fragS *frag;
3849 symbolS *to_symbol;
fecd2382 3850{
025b0302 3851 valueT offset;
6d27d3a2 3852
355afbcd 3853 offset = to_addr - (from_addr + 2);
6d27d3a2 3854
025b0302
ME
3855 md_number_to_chars (ptr, (valueT) 0x6000, 2);
3856 md_number_to_chars (ptr + 2, (valueT) offset, 2);
fecd2382
RP
3857}
3858
3859void
355afbcd
KR
3860md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
3861 char *ptr;
025b0302 3862 addressT from_addr, to_addr;
355afbcd
KR
3863 fragS *frag;
3864 symbolS *to_symbol;
fecd2382 3865{
025b0302 3866 valueT offset;
355afbcd
KR
3867
3868 if (cpu_of_arch (current_architecture) < m68020)
3869 {
3870 offset = to_addr - S_GET_VALUE (to_symbol);
025b0302
ME
3871 md_number_to_chars (ptr, (valueT) 0x4EF9, 2);
3872 md_number_to_chars (ptr + 2, (valueT) offset, 4);
bcb8dff8
KR
3873 fix_new (frag, (ptr + 2) - frag->fr_literal, 4, to_symbol, (offsetT) 0,
3874 0, NO_RELOC);
355afbcd
KR
3875 }
3876 else
3877 {
3878 offset = to_addr - (from_addr + 2);
025b0302
ME
3879 md_number_to_chars (ptr, (valueT) 0x60ff, 2);
3880 md_number_to_chars (ptr + 2, (valueT) offset, 4);
355afbcd 3881 }
fecd2382
RP
3882}
3883
3884#endif
a1c7c0f3
ILT
3885
3886/* Different values of OK tell what its OK to return. Things that
3887 aren't OK are an error (what a shock, no?)
6d27d3a2 3888
a39116f1
RP
3889 0: Everything is OK
3890 10: Absolute 1:8 only
3891 20: Absolute 0:7 only
3892 30: absolute 0:15 only
3893 40: Absolute 0:31 only
3894 50: absolute 0:127 only
3895 55: absolute -64:63 only
3896 60: absolute -128:127 only
3897 70: absolute 0:4095 only
3898 80: No bignums
6d27d3a2 3899
a39116f1 3900 */
fecd2382 3901
355afbcd
KR
3902static int
3903get_num (exp, ok)
3904 struct m68k_exp *exp;
3905 int ok;
fecd2382 3906{
a1c7c0f3 3907 if (exp->exp.X_op == O_absent)
49864cfa 3908 {
355afbcd 3909 /* Do the same thing the VAX asm does */
bcb8dff8 3910 op (exp) = O_constant;
355afbcd
KR
3911 adds (exp) = 0;
3912 subs (exp) = 0;
3913 offs (exp) = 0;
3914 if (ok == 10)
3915 {
3916 as_warn ("expression out of range: defaulting to 1");
3917 offs (exp) = 1;
3918 }
49864cfa 3919 }
a1c7c0f3 3920 else if (exp->exp.X_op == O_constant)
49864cfa 3921 {
355afbcd
KR
3922 switch (ok)
3923 {
3924 case 10:
3925 if (offs (exp) < 1 || offs (exp) > 8)
3926 {
3927 as_warn ("expression out of range: defaulting to 1");
3928 offs (exp) = 1;
3929 }
3930 break;
3931 case 20:
3932 if (offs (exp) < 0 || offs (exp) > 7)
3933 goto outrange;
3934 break;
3935 case 30:
3936 if (offs (exp) < 0 || offs (exp) > 15)
3937 goto outrange;
3938 break;
3939 case 40:
3940 if (offs (exp) < 0 || offs (exp) > 32)
3941 goto outrange;
3942 break;
3943 case 50:
3944 if (offs (exp) < 0 || offs (exp) > 127)
3945 goto outrange;
3946 break;
3947 case 55:
3948 if (offs (exp) < -64 || offs (exp) > 63)
3949 goto outrange;
3950 break;
3951 case 60:
3952 if (offs (exp) < -128 || offs (exp) > 127)
3953 goto outrange;
3954 break;
3955 case 70:
3956 if (offs (exp) < 0 || offs (exp) > 4095)
3957 {
3958 outrange:
3959 as_warn ("expression out of range: defaulting to 0");
3960 offs (exp) = 0;
3961 }
3962 break;
fecd2382 3963 default:
355afbcd
KR
3964 break;
3965 }
49864cfa 3966 }
a1c7c0f3 3967 else if (exp->exp.X_op == O_big)
49864cfa 3968 {
bcb8dff8 3969 if (offs (exp) <= 0 /* flonum */
355afbcd
KR
3970 && (ok == 80 /* no bignums */
3971 || (ok > 10 /* small-int ranges including 0 ok */
1404ef23
KR
3972 /* If we have a flonum zero, a zero integer should
3973 do as well (e.g., in moveq). */
355afbcd
KR
3974 && generic_floating_point_number.exponent == 0
3975 && generic_floating_point_number.low[0] == 0)))
3976 {
3977 /* HACK! Turn it into a long */
3978 LITTLENUM_TYPE words[6];
3979
3980 gen_to_words (words, 2, 8L); /* These numbers are magic! */
bcb8dff8 3981 op (exp) = O_constant;
355afbcd
KR
3982 adds (exp) = 0;
3983 subs (exp) = 0;
3984 offs (exp) = words[1] | (words[0] << 16);
3985 }
3986 else if (ok != 0)
3987 {
bcb8dff8 3988 op (exp) = O_constant;
355afbcd
KR
3989 adds (exp) = 0;
3990 subs (exp) = 0;
3991 offs (exp) = (ok == 10) ? 1 : 0;
a1c7c0f3
ILT
3992 as_warn ("Can't deal with expression; defaulting to %ld",
3993 offs (exp));
355afbcd 3994 }
49864cfa
KR
3995 }
3996 else
3997 {
355afbcd
KR
3998 if (ok >= 10 && ok <= 70)
3999 {
bcb8dff8 4000 op (exp) = O_constant;
355afbcd
KR
4001 adds (exp) = 0;
4002 subs (exp) = 0;
4003 offs (exp) = (ok == 10) ? 1 : 0;
a1c7c0f3
ILT
4004 as_warn ("Can't deal with expression; defaulting to %ld",
4005 offs (exp));
355afbcd 4006 }
355afbcd 4007 }
49864cfa 4008
a1c7c0f3 4009 if (exp->size != SIZE_UNSPEC)
355afbcd 4010 {
a1c7c0f3 4011 switch (exp->size)
355afbcd 4012 {
a1c7c0f3
ILT
4013 case SIZE_UNSPEC:
4014 case SIZE_LONG:
4015 break;
4016 case SIZE_BYTE:
355afbcd
KR
4017 if (!isbyte (offs (exp)))
4018 as_warn ("expression doesn't fit in BYTE");
4019 break;
a1c7c0f3 4020 case SIZE_WORD:
355afbcd
KR
4021 if (!isword (offs (exp)))
4022 as_warn ("expression doesn't fit in WORD");
4023 break;
a39116f1 4024 }
355afbcd 4025 }
a1c7c0f3 4026
355afbcd 4027 return offs (exp);
49864cfa 4028}
fecd2382
RP
4029
4030/* These are the back-ends for the various machine dependent pseudo-ops. */
355afbcd 4031void demand_empty_rest_of_line (); /* Hate those extra verbose names */
fecd2382 4032
355afbcd 4033static void
bcb8dff8
KR
4034s_data1 (ignore)
4035 int ignore;
355afbcd 4036{
bcb8dff8 4037 subseg_set (data_section, 1);
355afbcd 4038 demand_empty_rest_of_line ();
49864cfa 4039}
fecd2382 4040
355afbcd 4041static void
bcb8dff8
KR
4042s_data2 (ignore)
4043 int ignore;
355afbcd 4044{
bcb8dff8 4045 subseg_set (data_section, 2);
355afbcd 4046 demand_empty_rest_of_line ();
49864cfa 4047}
fecd2382 4048
355afbcd 4049static void
bcb8dff8
KR
4050s_bss (ignore)
4051 int ignore;
a1765cf0 4052{
355afbcd 4053 /* We don't support putting frags in the BSS segment, we fake it
49864cfa 4054 by marking in_bss, then looking at s_skip for clues. */
a1765cf0 4055
bcb8dff8 4056 subseg_set (bss_section, 0);
355afbcd 4057 demand_empty_rest_of_line ();
49864cfa 4058}
6d27d3a2 4059
355afbcd 4060static void
bcb8dff8
KR
4061s_even (ignore)
4062 int ignore;
355afbcd
KR
4063{
4064 register int temp;
4065 register long temp_fill;
4066
4067 temp = 1; /* JF should be 2? */
4068 temp_fill = get_absolute_expression ();
4069 if (!need_pass_2) /* Never make frag if expect extra pass. */
4070 frag_align (temp, (int) temp_fill);
4071 demand_empty_rest_of_line ();
49864cfa 4072}
355afbcd
KR
4073
4074static void
bcb8dff8
KR
4075s_proc (ignore)
4076 int ignore;
355afbcd
KR
4077{
4078 demand_empty_rest_of_line ();
49864cfa 4079}
e9bb39b4
ILT
4080\f
4081/* Pseudo-ops handled for MRI compatibility. */
4082
4083/* Handle an MRI style chip specification. */
fecd2382 4084
e9bb39b4
ILT
4085static void
4086mri_chip ()
4087{
4088 char *s;
4089 char c;
4090 int i;
4091
4092 s = input_line_pointer;
4093 c = get_symbol_end ();
4094 for (i = 0; i < n_archs; i++)
4095 if (strcasecmp (s, archs[i].name) == 0)
4096 break;
4097 if (i >= n_archs)
4098 {
4099 as_bad ("%s: unrecognized processor name", s);
4100 *input_line_pointer = c;
4101 ignore_rest_of_line ();
4102 return;
4103 }
4104 *input_line_pointer = c;
fecd2382 4105
e9bb39b4
ILT
4106 if (*input_line_pointer == '/')
4107 current_architecture = 0;
4108 else
4109 current_architecture &= m68881 | m68851;
4110 current_architecture |= archs[i].arch;
4111
4112 while (*input_line_pointer == '/')
4113 {
4114 ++input_line_pointer;
4115 s = input_line_pointer;
4116 c = get_symbol_end ();
4117 if (strcmp (s, "68881") == 0)
4118 current_architecture |= m68881;
4119 else if (strcmp (s, "68851") == 0)
4120 current_architecture |= m68851;
4121 *input_line_pointer = c;
4122 }
4123}
4124
4125/* The MRI CHIP pseudo-op. */
4126
4127static void
4128s_chip (ignore)
4129 int ignore;
4130{
4131 mri_chip ();
4132 demand_empty_rest_of_line ();
4133}
27a53b88
ILT
4134
4135/* The MRI FOPT pseudo-op. */
4136
4137static void
4138s_fopt (ignore)
4139 int ignore;
4140{
4141 SKIP_WHITESPACE ();
4142
4143 if (strncasecmp (input_line_pointer, "ID=", 3) == 0)
4144 {
4145 int temp;
4146
4147 input_line_pointer += 3;
4148 temp = get_absolute_expression ();
4149 if (temp < 0 || temp > 7)
4150 as_bad ("bad coprocessor id");
4151 else
4152 m68k_float_copnum = COP0 + temp;
4153 }
4154 else
4155 {
4156 as_bad ("unrecognized fopt option");
4157 ignore_rest_of_line ();
4158 return;
4159 }
4160
4161 demand_empty_rest_of_line ();
4162}
6700d36e
ILT
4163
4164/* The structure used to handle the MRI OPT pseudo-op. */
4165
4166struct opt_action
4167{
4168 /* The name of the option. */
4169 const char *name;
4170
4171 /* If this is not NULL, just call this function. The first argument
4172 is the ARG field of this structure, the second argument is
4173 whether the option was negated. */
4174 void (*pfn) PARAMS ((int arg, int on));
4175
4176 /* If this is not NULL, and the PFN field is NULL, set the variable
4177 this points to. Set it to the ARG field if the option was not
4178 negated, and the NOTARG field otherwise. */
4179 int *pvar;
4180
4181 /* The value to pass to PFN or to assign to *PVAR. */
4182 int arg;
4183
4184 /* The value to assign to *PVAR if the option is negated. If PFN is
4185 NULL, and PVAR is not NULL, and ARG and NOTARG are the same, then
4186 the option may not be negated. */
4187 int notarg;
4188};
4189
4190/* The table used to handle the MRI OPT pseudo-op. */
4191
4192static void skip_to_comma PARAMS ((int, int));
4193static void opt_chip PARAMS ((int, int));
4194static void opt_list PARAMS ((int, int));
4195static void opt_list_symbols PARAMS ((int, int));
4196
4197static const struct opt_action opt_table[] =
4198{
4199 { "abspcadd", 0, &m68k_abspcadd, 1, 0 },
4200
4201 /* We do relaxing, so there is little use for these options. */
4202 { "b", 0, 0, 0, 0 },
4203 { "brs", 0, 0, 0, 0 },
4204 { "brb", 0, 0, 0, 0 },
4205 { "brl", 0, 0, 0, 0 },
4206 { "brw", 0, 0, 0, 0 },
4207
4208 { "c", 0, 0, 0, 0 },
4209 { "cex", 0, 0, 0, 0 },
4210 { "case", 0, &symbols_case_sensitive, 1, 0 },
4211 { "cl", 0, 0, 0, 0 },
4212 { "cre", 0, 0, 0, 0 },
4213 { "d", 0, &flag_keep_locals, 1, 0 },
4214 { "e", 0, 0, 0, 0 },
4215 { "f", 0, &flag_short_refs, 1, 0 },
4216 { "frs", 0, &flag_short_refs, 1, 0 },
4217 { "frl", 0, &flag_short_refs, 0, 1 },
4218 { "g", 0, 0, 0, 0 },
4219 { "i", 0, 0, 0, 0 },
4220 { "m", 0, 0, 0, 0 },
4221 { "mex", 0, 0, 0, 0 },
4222 { "mc", 0, 0, 0, 0 },
4223 { "md", 0, 0, 0, 0 },
4224 { "next", skip_to_comma, 0, 0, 0 },
4225 { "o", 0, 0, 0, 0 },
4226 { "old", 0, 0, 0, 0 },
4227 { "op", skip_to_comma, 0, 0, 0 },
4228 { "pco", 0, 0, 0, 0 },
4229 { "p", opt_chip, 0, 0, 0 },
4230 { "pcr", 0, 0, 0, 0 },
4231 { "pcs", 0, 0, 0, 0 },
4232 { "r", 0, 0, 0, 0 },
4233 { "quick", 0, &m68k_quick, 1, 0 },
4234 { "rel32", 0, &m68k_rel32, 1, 0 },
4235 { "s", opt_list, 0, 0, 0 },
4236 { "t", opt_list_symbols, 0, 0, 0 },
4237 { "w", 0, &flag_no_warnings, 0, 1 },
4238 { "x", 0, 0, 0, 0 }
4239};
4240
4241#define OPTCOUNT (sizeof opt_table / sizeof opt_table[0])
4242
4243/* The MRI OPT pseudo-op. */
4244
4245static void
4246s_opt (ignore)
4247 int ignore;
4248{
4249 do
4250 {
4251 int t;
4252 char *s;
4253 char c;
4254 int i;
4255 const struct opt_action *o;
4256
4257 SKIP_WHITESPACE ();
4258
4259 t = 1;
4260 if (*input_line_pointer == '-')
4261 {
4262 ++input_line_pointer;
4263 t = 0;
4264 }
4265 else if (strncasecmp (input_line_pointer, "NO", 2) == 0)
4266 {
4267 input_line_pointer += 2;
4268 t = 0;
4269 }
4270
4271 s = input_line_pointer;
4272 c = get_symbol_end ();
4273
4274 for (i = 0, o = opt_table; i < OPTCOUNT; i++, o++)
4275 {
4276 if (strcasecmp (s, o->name) == 0)
4277 {
4278 if (o->pfn)
4279 {
4280 /* Restore input_line_pointer now in case the option
4281 takes arguments. */
4282 *input_line_pointer = c;
4283 (*o->pfn) (o->arg, t);
4284 }
4285 else if (o->pvar != NULL)
4286 {
4287 if (! t && o->arg == o->notarg)
4288 as_bad ("option `%s' may not be negated", s);
4289 *input_line_pointer = c;
4290 *o->pvar = t ? o->arg : o->notarg;
4291 }
4292 break;
4293 }
4294 }
4295 if (i >= OPTCOUNT)
4296 {
4297 as_bad ("option `%s' not recognized", s);
4298 *input_line_pointer = c;
4299 }
4300 }
4301 while (*input_line_pointer++ == ',');
4302
4303 /* Move back to terminating character. */
4304 --input_line_pointer;
4305 demand_empty_rest_of_line ();
4306}
4307
4308/* Skip ahead to a comma. This is used for OPT options which we do
4309 not suppor tand which take arguments. */
4310
4311static void
4312skip_to_comma (arg, on)
4313 int arg;
4314 int on;
4315{
4316 while (*input_line_pointer != ','
4317 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4318 ++input_line_pointer;
4319}
4320
4321/* Handle the OPT P=chip option. */
4322
4323static void
4324opt_chip (arg, on)
4325 int arg;
4326 int on;
4327{
4328 if (*input_line_pointer != '=')
4329 {
4330 /* This is just OPT P, which we do not support. */
4331 return;
4332 }
4333
4334 ++input_line_pointer;
4335 mri_chip ();
4336}
4337
4338/* Handle the OPT S option. */
4339
4340static void
4341opt_list (arg, on)
4342 int arg;
4343 int on;
4344{
4345 listing_list (on);
4346}
4347
4348/* Handle the OPT T option. */
4349
4350static void
4351opt_list_symbols (arg, on)
4352 int arg;
4353 int on;
4354{
4355 if (on)
4356 listing |= LISTING_SYMBOLS;
4357 else
4358 listing &=~ LISTING_SYMBOLS;
4359}
4360
4361/* Handle the MRI REG pseudo-op. */
4362
4363static void
4364s_reg (ignore)
4365 int ignore;
4366{
4367 char *s;
4368 int c;
4369 struct m68k_op op;
4370 unsigned long mask;
4371
4372 if (mri_line_label == NULL)
4373 {
4374 as_bad ("missing label");
4375 ignore_rest_of_line ();
4376 return;
4377 }
4378
4379 SKIP_WHITESPACE ();
4380
4381 s = input_line_pointer;
4382 while (isalnum ((unsigned char) *input_line_pointer)
4383#ifdef REGISTER_PREFIX
4384 || *input_line_pointer == REGISTER_PREFIX
4385#endif
4386 || *input_line_pointer == '/'
4387 || *input_line_pointer == '-')
4388 ++input_line_pointer;
4389 c = *input_line_pointer;
4390 *input_line_pointer = '\0';
4391
4392 if (m68k_ip_op (s, &op) != 0)
4393 {
4394 if (op.error == NULL)
4395 as_bad ("bad register list");
4396 else
4397 as_bad ("bad register list: %s", op.error);
4398 *input_line_pointer = c;
4399 ignore_rest_of_line ();
4400 return;
4401 }
4402
4403 *input_line_pointer = c;
4404
4405 if (op.mode == REGLST)
4406 mask = op.mask;
4407 else if (op.mode == DREG)
4408 mask = 1 << (op.reg - DATA0);
4409 else if (op.mode == AREG)
4410 mask = 1 << (op.reg - ADDR0 + 8);
4411 else if (op.mode == FPREG)
4412 mask = 1 << (op.reg - FP0 + 16);
4413 else if (op.mode == CONTROL
4414 && op.reg == FPI)
4415 mask = 1 << 24;
4416 else if (op.mode == CONTROL
4417 && op.reg == FPS)
4418 mask = 1 << 25;
4419 else if (op.mode == CONTROL
4420 && op.reg == FPC)
4421 mask = 1 << 26;
4422 else
4423 {
4424 as_bad ("bad register list");
4425 ignore_rest_of_line ();
4426 return;
4427 }
4428
4429 S_SET_SEGMENT (mri_line_label, absolute_section);
4430 S_SET_VALUE (mri_line_label, mask);
4431 mri_line_label->sy_frag = &zero_address_frag;
4432
4433 demand_empty_rest_of_line ();
4434}
f3d817d8 4435\f
7c15cbe8
RP
4436/*
4437 * md_parse_option
4438 * Invocation line includes a switch not recognized by the base assembler.
4439 * See if it's a processor-specific option. These are:
4440 *
4441 * -[A]m[c]68000, -[A]m[c]68008, -[A]m[c]68010, -[A]m[c]68020, -[A]m[c]68030, -[A]m[c]68040
4442 * -[A]m[c]68881, -[A]m[c]68882, -[A]m[c]68851
4443 * Select the architecture. Instructions or features not
4444 * supported by the selected architecture cause fatal
4445 * errors. More than one may be specified. The default is
4446 * -m68020 -m68851 -m68881. Note that -m68008 is a synonym
4447 * for -m68000, and -m68882 is a synonym for -m68881.
df3768fb
KR
4448 * -[A]m[c]no-68851, -[A]m[c]no-68881
4449 * Don't accept 688?1 instructions. (The "c" is kind of silly,
4450 * so don't use or document it, but that's the way the parsing
4451 * works).
7c15cbe8 4452 *
dff60b7d
ILT
4453 * -pic Indicates PIC.
4454 * -k Indicates PIC. (Sun 3 only.)
b80d39a0 4455 *
7c15cbe8
RP
4456 */
4457
5f8cb05e
ILT
4458#ifdef OBJ_ELF
4459CONST char *md_shortopts = "lSA:m:kQ:V";
4460#else
f3d817d8 4461CONST char *md_shortopts = "lSA:m:k";
5f8cb05e
ILT
4462#endif
4463
f3d817d8
DM
4464struct option md_longopts[] = {
4465#define OPTION_PIC (OPTION_MD_BASE)
4466 {"pic", no_argument, NULL, OPTION_PIC},
4467#define OPTION_REGISTER_PREFIX_OPTIONAL (OPTION_MD_BASE + 1)
4468 {"register-prefix-optional", no_argument, NULL,
4469 OPTION_REGISTER_PREFIX_OPTIONAL},
4470 {NULL, no_argument, NULL, 0}
4471};
4472size_t md_longopts_size = sizeof(md_longopts);
82489ea0 4473
355afbcd 4474int
f3d817d8
DM
4475md_parse_option (c, arg)
4476 int c;
4477 char *arg;
fecd2382 4478{
f3d817d8 4479 switch (c)
355afbcd
KR
4480 {
4481 case 'l': /* -l means keep external to 2 bit offset
e284846a 4482 rather than 16 bit one */
9ad5755f 4483 flag_short_refs = 1;
355afbcd 4484 break;
6d27d3a2 4485
e284846a
KR
4486 case 'S': /* -S means that jbsr's always turn into
4487 jsr's. */
9ad5755f 4488 flag_long_jumps = 1;
355afbcd 4489 break;
6d27d3a2 4490
355afbcd 4491 case 'A':
f3d817d8
DM
4492 if (*arg == 'm')
4493 arg++;
355afbcd
KR
4494 /* intentional fall-through */
4495 case 'm':
355afbcd 4496
b79de3a1 4497 if (arg[0] == 'n' && arg[1] == 'o' && arg[2] == '-')
e284846a 4498 {
064ba683
ILT
4499 int i;
4500 unsigned long arch;
b79de3a1
KR
4501 const char *oarg = arg;
4502
4503 arg += 3;
4504 if (*arg == 'm')
4505 {
4506 arg++;
4507 if (arg[0] == 'c' && arg[1] == '6')
4508 arg++;
4509 }
4510 for (i = 0; i < n_archs; i++)
4511 if (!strcmp (arg, archs[i].name))
4512 break;
4513 if (i == n_archs)
4514 {
4515 unknown:
4516 as_bad ("unrecognized option `%s'", oarg);
4517 return 0;
4518 }
4519 arch = archs[i].arch;
4520 if (arch == m68881)
4521 no_68881 = 1;
4522 else if (arch == m68851)
4523 no_68851 = 1;
4524 else
4525 goto unknown;
355afbcd
KR
4526 }
4527 else
4528 {
b79de3a1
KR
4529 int i;
4530
4531 if (arg[0] == 'c' && arg[1] == '6')
4532 arg++;
4533
4534 for (i = 0; i < n_archs; i++)
4535 if (!strcmp (arg, archs[i].name))
4536 {
4537 unsigned long arch = archs[i].arch;
4538 if (cpu_of_arch (arch))
4539 /* It's a cpu spec. */
4540 {
4541 current_architecture &= ~m68000up;
4542 current_architecture |= arch;
4543 }
4544 else if (arch == m68881)
4545 {
4546 current_architecture |= m68881;
4547 no_68881 = 0;
4548 }
4549 else if (arch == m68851)
4550 {
4551 current_architecture |= m68851;
4552 no_68851 = 0;
4553 }
4554 else
4555 /* ??? */
4556 abort ();
4557 break;
4558 }
4559 if (i == n_archs)
4560 {
4561 as_bad ("unrecognized architecture specification `%s'", arg);
4562 return 0;
4563 }
f8701a3f 4564 }
f3d817d8 4565 break;
dff60b7d 4566
f3d817d8 4567 case OPTION_PIC:
dff60b7d
ILT
4568 case 'k':
4569 flag_want_pic = 1;
f3d817d8
DM
4570 break; /* -pic, Position Independent Code */
4571
4572 case OPTION_REGISTER_PREFIX_OPTIONAL:
4573 flag_reg_prefix_optional = 1;
dff60b7d 4574 break;
355afbcd 4575
5f8cb05e
ILT
4576 case 'Q':
4577 case 'V':
4578 break;
4579
355afbcd
KR
4580 default:
4581 return 0;
4582 }
f3d817d8 4583
355afbcd 4584 return 1;
fecd2382
RP
4585}
4586
f3d817d8
DM
4587void
4588md_show_usage (stream)
4589 FILE *stream;
4590{
4591 fprintf(stream, "\
4592680X0 options:\n\
4593-l use 1 word for refs to undefined symbols [default 2]\n\
5f8cb05e
ILT
4594-m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040 | -m68060\n\
4595 | -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -m68360\n\
4596 | -mcpu32\n\
f3d817d8
DM
4597 specify variant of 680X0 architecture [default 68020]\n\
4598-m68881 | -m68882 | -mno-68881 | -mno-68882\n\
4599 target has/lacks floating-point coprocessor\n\
4600 [default yes for 68020, 68030, and cpu32]\n\
4601-m68851 | -mno-68851\n\
4602 target has/lacks memory-management unit coprocessor\n\
4603 [default yes for 68020 and up]\n\
4604-pic, -k generate position independent code\n\
4605-S turn jbsr into jsr\n\
4606--register-prefix-optional\n\
4607 recognize register names without prefix character\n");
4608}
4609\f
fecd2382
RP
4610#ifdef TEST2
4611
4612/* TEST2: Test md_assemble() */
4613/* Warning, this routine probably doesn't work anymore */
4614
355afbcd 4615main ()
fecd2382 4616{
355afbcd
KR
4617 struct m68k_it the_ins;
4618 char buf[120];
4619 char *cp;
4620 int n;
4621
4622 m68k_ip_begin ();
4623 for (;;)
4624 {
4625 if (!gets (buf) || !*buf)
4626 break;
4627 if (buf[0] == '|' || buf[1] == '.')
4628 continue;
4629 for (cp = buf; *cp; cp++)
4630 if (*cp == '\t')
4631 *cp = ' ';
4632 if (is_label (buf))
4633 continue;
4634 memset (&the_ins, '\0', sizeof (the_ins));
4635 m68k_ip (&the_ins, buf);
4636 if (the_ins.error)
4637 {
4638 printf ("Error %s in %s\n", the_ins.error, buf);
4639 }
4640 else
4641 {
4642 printf ("Opcode(%d.%s): ", the_ins.numo, the_ins.args);
4643 for (n = 0; n < the_ins.numo; n++)
4644 printf (" 0x%x", the_ins.opcode[n] & 0xffff);
4645 printf (" ");
4646 print_the_insn (&the_ins.opcode[0], stdout);
4647 (void) putchar ('\n');
4648 }
4649 for (n = 0; n < strlen (the_ins.args) / 2; n++)
4650 {
4651 if (the_ins.operands[n].error)
4652 {
4653 printf ("op%d Error %s in %s\n", n, the_ins.operands[n].error, buf);
4654 continue;
4655 }
4656 printf ("mode %d, reg %d, ", the_ins.operands[n].mode, the_ins.operands[n].reg);
4657 if (the_ins.operands[n].b_const)
4658 printf ("Constant: '%.*s', ", 1 + the_ins.operands[n].e_const - the_ins.operands[n].b_const, the_ins.operands[n].b_const);
4659 printf ("ireg %d, isiz %d, imul %d, ", the_ins.operands[n].ireg, the_ins.operands[n].isiz, the_ins.operands[n].imul);
4660 if (the_ins.operands[n].b_iadd)
4661 printf ("Iadd: '%.*s',", 1 + the_ins.operands[n].e_iadd - the_ins.operands[n].b_iadd, the_ins.operands[n].b_iadd);
4662 (void) putchar ('\n');
a39116f1 4663 }
355afbcd
KR
4664 }
4665 m68k_ip_end ();
4666 return 0;
fecd2382
RP
4667}
4668
355afbcd
KR
4669is_label (str)
4670 char *str;
fecd2382 4671{
355afbcd
KR
4672 while (*str == ' ')
4673 str++;
4674 while (*str && *str != ' ')
4675 str++;
4676 if (str[-1] == ':' || str[1] == '=')
4677 return 1;
4678 return 0;
fecd2382
RP
4679}
4680
4681#endif
4682
4683/* Possible states for relaxation:
6d27d3a2 4684
a39116f1
RP
4685 0 0 branch offset byte (bra, etc)
4686 0 1 word
4687 0 2 long
6d27d3a2 4688
a39116f1
RP
4689 1 0 indexed offsets byte a0@(32,d4:w:1) etc
4690 1 1 word
4691 1 2 long
6d27d3a2 4692
a39116f1
RP
4693 2 0 two-offset index word-word a0@(32,d4)@(45) etc
4694 2 1 word-long
4695 2 2 long-word
4696 2 3 long-long
6d27d3a2 4697
a39116f1 4698 */
fecd2382 4699
fecd2382
RP
4700/* We have no need to default values of symbols. */
4701
4702/* ARGSUSED */
4703symbolS *
355afbcd
KR
4704md_undefined_symbol (name)
4705 char *name;
fecd2382 4706{
355afbcd 4707 return 0;
fecd2382
RP
4708}
4709
fecd2382 4710/* Round up a section size to the appropriate boundary. */
025b0302 4711valueT
355afbcd
KR
4712md_section_align (segment, size)
4713 segT segment;
025b0302 4714 valueT size;
fecd2382 4715{
355afbcd 4716 return size; /* Byte alignment is fine */
fecd2382
RP
4717}
4718
4719/* Exactly what point is a PC-relative offset relative TO?
5f8cb05e
ILT
4720 On the 68k, it is relative to the address of the first extension
4721 word. The difference between the addresses of the offset and the
4722 first extension word is stored in fx_pcrel_adjust. */
fecd2382 4723long
355afbcd
KR
4724md_pcrel_from (fixP)
4725 fixS *fixP;
fecd2382 4726{
5f8cb05e 4727 return (fixP->fx_where + fixP->fx_frag->fr_address - fixP->fx_pcrel_adjust);
fecd2382
RP
4728}
4729
49864cfa 4730#ifndef BFD_ASSEMBLER
9ad5755f 4731/*ARGSUSED*/
355afbcd 4732void
9ad5755f
KR
4733tc_coff_symbol_emit_hook (ignore)
4734 symbolS *ignore;
3ad9ec6a
ILT
4735{
4736}
4737
355afbcd
KR
4738int
4739tc_coff_sizemachdep (frag)
4740 fragS *frag;
3ad9ec6a 4741{
355afbcd
KR
4742 switch (frag->fr_subtype & 0x3)
4743 {
4744 case BYTE:
4745 return 1;
4746 case SHORT:
4747 return 2;
4748 case LONG:
4749 return 4;
4750 default:
4751 abort ();
064ba683 4752 return 0;
355afbcd 4753 }
3ad9ec6a 4754}
49864cfa 4755#endif
355afbcd 4756
fecd2382 4757/* end of tc-m68k.c */
This page took 0.41942 seconds and 4 git commands to generate.