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