[AArch64][SVE 08/32] Generalise aarch64_double_precision_fmovable
[deliverable/binutils-gdb.git] / gas / config / tc-z8k.c
CommitLineData
252b5132 1/* tc-z8k.c -- Assemble code for the Zilog Z800n
6f2750fe 2 Copyright (C) 1992-2016 Free Software Foundation, Inc.
252b5132
RH
3
4 This file is part of GAS, the GNU Assembler.
5
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
ec2655a6 8 the Free Software Foundation; either version 3, or (at your option)
252b5132
RH
9 any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
4b4da160
NC
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
252b5132 20
e0c6ed95
AM
21/* Written By Steve Chamberlain <sac@cygnus.com>. */
22
252b5132 23#include "as.h"
3882b010 24#include "safe-ctype.h"
c0524131 25#define DEFINE_TABLE
a5d2034a 26#include "opcodes/z8k-opc.h"
252b5132 27
63a0b638
AM
28const char comment_chars[] = "!";
29const char line_comment_chars[] = "#";
30const char line_separator_chars[] = ";";
252b5132
RH
31
32extern int machine;
33extern int coff_flags;
34int segmented_mode;
252b5132 35
00a3147e
CG
36/* This is non-zero if target was set from the command line.
37 If non-zero, 1 means Z8002 (non-segmented), 2 means Z8001 (segmented). */
7f31df7c
CG
38static int z8k_target_from_cmdline;
39
78a33af2 40static void
464800ca 41s_segm (int segm)
252b5132 42{
7f31df7c
CG
43 if (segm)
44 {
d5bf5799 45 segmented_mode = 1;
c0524131 46 bfd_set_arch_mach (stdoutput, TARGET_ARCH, bfd_mach_z8001);
7f31df7c
CG
47 }
48 else
49 {
d5bf5799 50 segmented_mode = 0;
c0524131 51 bfd_set_arch_mach (stdoutput, TARGET_ARCH, bfd_mach_z8002);
7f31df7c 52 }
252b5132
RH
53}
54
e0c6ed95 55static void
464800ca 56even (int ignore ATTRIBUTE_UNUSED)
252b5132
RH
57{
58 frag_align (1, 0, 0);
59 record_alignment (now_seg, 1);
60}
61
78a33af2 62static int
464800ca 63tohex (int c)
252b5132 64{
3882b010 65 if (ISDIGIT (c))
252b5132 66 return c - '0';
3882b010 67 if (ISLOWER (c))
252b5132
RH
68 return c - 'a' + 10;
69 return c - 'A' + 10;
70}
71
78a33af2 72static void
464800ca 73sval (int ignore ATTRIBUTE_UNUSED)
252b5132 74{
252b5132
RH
75 SKIP_WHITESPACE ();
76 if (*input_line_pointer == '\'')
77 {
78 int c;
79 input_line_pointer++;
80 c = *input_line_pointer++;
81 while (c != '\'')
82 {
83 if (c == '%')
84 {
85 c = (tohex (input_line_pointer[0]) << 4)
86 | tohex (input_line_pointer[1]);
87 input_line_pointer += 2;
88 }
89 FRAG_APPEND_1_CHAR (c);
90 c = *input_line_pointer++;
91 }
92 demand_empty_rest_of_line ();
93 }
252b5132 94}
e0c6ed95
AM
95
96/* This table describes all the machine specific pseudo-ops the assembler
97 has to support. The fields are:
98 pseudo-op name without dot
99 function to call to execute this pseudo-op
100 Integer arg to pass to the function
101 */
102
103const pseudo_typeS md_pseudo_table[] = {
104 {"int" , cons , 2},
105 {"data.b" , cons , 1},
106 {"data.w" , cons , 2},
107 {"data.l" , cons , 4},
108 {"form" , listing_psize , 0},
109 {"heading", listing_title , 0},
110 {"import" , s_ignore , 0},
111 {"page" , listing_eject , 0},
112 {"program", s_ignore , 0},
7f31df7c
CG
113 {"z8001" , s_segm , 1},
114 {"z8002" , s_segm , 0},
e0c6ed95 115
7f31df7c
CG
116 {"segm" , s_segm , 1},
117 {"unsegm" , s_segm , 0},
118 {"unseg" , s_segm , 0},
e0c6ed95
AM
119 {"name" , s_app_file , 0},
120 {"global" , s_globl , 0},
121 {"wval" , cons , 2},
122 {"lval" , cons , 4},
123 {"bval" , cons , 1},
124 {"sval" , sval , 0},
125 {"rsect" , obj_coff_section, 0},
126 {"sect" , obj_coff_section, 0},
127 {"block" , s_space , 0},
128 {"even" , even , 0},
129 {0 , 0 , 0}
252b5132
RH
130};
131
132const char EXP_CHARS[] = "eE";
133
e0c6ed95
AM
134/* Chars that mean this number is a floating point constant.
135 As in 0f12.456
136 or 0d1.2345e12 */
252b5132
RH
137const char FLT_CHARS[] = "rRsSfFdDxXpP";
138
e0c6ed95
AM
139/* Opcode mnemonics. */
140static struct hash_control *opcode_hash_control;
252b5132
RH
141
142void
464800ca 143md_begin (void)
252b5132 144{
78a33af2
AM
145 const opcode_entry_type *opcode;
146 int idx = -1;
252b5132
RH
147
148 opcode_hash_control = hash_new ();
149
150 for (opcode = z8k_table; opcode->name; opcode++)
151 {
e0c6ed95 152 /* Only enter unique codes into the table. */
78a33af2
AM
153 if (idx != opcode->idx)
154 hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
155 idx = opcode->idx;
252b5132
RH
156 }
157
e0c6ed95 158 /* Default to z8002. */
00a3147e 159 s_segm (z8k_target_from_cmdline ? z8k_target_from_cmdline - 1 : 0);
252b5132 160
e0c6ed95 161 /* Insert the pseudo ops, too. */
252b5132
RH
162 for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
163 {
164 opcode_entry_type *fake_opcode;
325801bd 165 fake_opcode = XNEW (opcode_entry_type);
879db8be
NC
166 fake_opcode->name = md_pseudo_table[idx].poc_name;
167 fake_opcode->func = (void *) (md_pseudo_table + idx);
252b5132
RH
168 fake_opcode->opcode = 250;
169 hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
170 }
252b5132
RH
171}
172
19d63e5d 173typedef struct z8k_op {
f590b86e
CG
174 /* CLASS_REG_xxx. */
175 int regsize;
e0c6ed95
AM
176
177 /* 0 .. 15. */
178 unsigned int reg;
252b5132
RH
179
180 int mode;
181
e0c6ed95
AM
182 /* Any other register associated with the mode. */
183 unsigned int x_reg;
184
185 /* Any expression. */
186 expressionS exp;
19d63e5d 187} op_type;
252b5132
RH
188
189static expressionS *da_operand;
190static expressionS *imm_operand;
191
464800ca
CG
192static int reg[16];
193static int the_cc;
194static int the_ctrl;
195static int the_flags;
196static int the_interrupt;
78a33af2 197
41d3b056
CG
198/* Determine register number. src points to the ascii number
199 (after "rl", "rh", "r", "rr", or "rq"). If a character
200 outside the set of {0,',',')','('} follows the number,
201 return NULL to indicate that it's not a valid register
202 number. */
203
78a33af2 204static char *
91d6fa6a 205whatreg (unsigned int *preg, char *src)
252b5132 206{
41d3b056
CG
207 unsigned int new_reg;
208
209 /* src[0] is already known to be a digit. */
3882b010 210 if (ISDIGIT (src[1]))
252b5132 211 {
41d3b056
CG
212 new_reg = (src[0] - '0') * 10 + src[1] - '0';
213 src += 2;
252b5132
RH
214 }
215 else
216 {
41d3b056
CG
217 new_reg = (src[0] - '0');
218 src += 1;
252b5132 219 }
41d3b056
CG
220
221 if (src[0] != 0 && src[0] != ',' && src[0] != '(' && src[0] != ')')
222 return NULL;
223
91d6fa6a 224 *preg = new_reg;
41d3b056 225 return src;
252b5132
RH
226}
227
e0c6ed95 228/* Parse operands
252b5132 229
e0c6ed95
AM
230 rh0-rh7, rl0-rl7
231 r0-r15
232 rr0-rr14
233 rq0--rq12
234 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
235 r0l,r0h,..r7l,r7h
236 @WREG
237 @WREG+
238 @-WREG
239 #const
240*/
252b5132 241
bc0d738a
NC
242/* Try to parse a reg name. Return a pointer to the first character
243 in SRC after the reg name. */
244
78a33af2 245static char *
91d6fa6a 246parse_reg (char *src, int *mode, unsigned int *preg)
252b5132 247{
41d3b056 248 char *res = NULL;
252b5132
RH
249 char regno;
250
f69532ae
CG
251 /* Check for stack pointer "sp" alias. */
252 if ((src[0] == 's' || src[0] == 'S')
253 && (src[1] == 'p' || src[1] == 'P')
254 && (src[2] == 0 || src[2] == ','))
252b5132
RH
255 {
256 if (segmented_mode)
e0c6ed95
AM
257 {
258 *mode = CLASS_REG_LONG;
91d6fa6a 259 *preg = 14;
e0c6ed95 260 }
252b5132 261 else
e0c6ed95
AM
262 {
263 *mode = CLASS_REG_WORD;
91d6fa6a 264 *preg = 15;
e0c6ed95 265 }
252b5132
RH
266 return src + 2;
267 }
f69532ae
CG
268
269 if (src[0] == 'r' || src[0] == 'R')
252b5132 270 {
f69532ae 271 if (src[1] == 'r' || src[1] == 'R')
e0c6ed95 272 {
28bab82b 273 if (src[2] < '0' || src[2] > '9')
41d3b056 274 return NULL; /* Assume no register name but a label starting with 'rr'. */
e0c6ed95 275 *mode = CLASS_REG_LONG;
91d6fa6a 276 res = whatreg (preg, src + 2);
41d3b056
CG
277 if (res == NULL)
278 return NULL; /* Not a valid register name. */
91d6fa6a 279 regno = *preg;
252b5132 280 if (regno > 14)
f590b86e
CG
281 as_bad (_("register rr%d out of range"), regno);
282 if (regno & 1)
283 as_bad (_("register rr%d does not exist"), regno);
e0c6ed95 284 }
f69532ae 285 else if (src[1] == 'h' || src[1] == 'H')
e0c6ed95 286 {
28bab82b 287 if (src[2] < '0' || src[2] > '9')
41d3b056 288 return NULL; /* Assume no register name but a label starting with 'rh'. */
e0c6ed95 289 *mode = CLASS_REG_BYTE;
91d6fa6a 290 res = whatreg (preg, src + 2);
41d3b056
CG
291 if (res == NULL)
292 return NULL; /* Not a valid register name. */
91d6fa6a 293 regno = *preg;
252b5132 294 if (regno > 7)
f590b86e 295 as_bad (_("register rh%d out of range"), regno);
e0c6ed95 296 }
f69532ae 297 else if (src[1] == 'l' || src[1] == 'L')
e0c6ed95 298 {
28bab82b 299 if (src[2] < '0' || src[2] > '9')
41d3b056 300 return NULL; /* Assume no register name but a label starting with 'rl'. */
e0c6ed95 301 *mode = CLASS_REG_BYTE;
91d6fa6a 302 res = whatreg (preg, src + 2);
41d3b056
CG
303 if (res == NULL)
304 return NULL; /* Not a valid register name. */
91d6fa6a 305 regno = *preg;
252b5132 306 if (regno > 7)
f590b86e 307 as_bad (_("register rl%d out of range"), regno);
91d6fa6a 308 *preg += 8;
e0c6ed95 309 }
f69532ae 310 else if (src[1] == 'q' || src[1] == 'Q')
e0c6ed95 311 {
28bab82b 312 if (src[2] < '0' || src[2] > '9')
41d3b056 313 return NULL; /* Assume no register name but a label starting with 'rq'. */
e0c6ed95 314 *mode = CLASS_REG_QUAD;
91d6fa6a 315 res = whatreg (preg, src + 2);
41d3b056
CG
316 if (res == NULL)
317 return NULL; /* Not a valid register name. */
91d6fa6a 318 regno = *preg;
252b5132 319 if (regno > 12)
f590b86e
CG
320 as_bad (_("register rq%d out of range"), regno);
321 if (regno & 3)
322 as_bad (_("register rq%d does not exist"), regno);
e0c6ed95 323 }
252b5132 324 else
e0c6ed95 325 {
28bab82b 326 if (src[1] < '0' || src[1] > '9')
41d3b056 327 return NULL; /* Assume no register name but a label starting with 'r'. */
e0c6ed95 328 *mode = CLASS_REG_WORD;
91d6fa6a 329 res = whatreg (preg, src + 1);
41d3b056
CG
330 if (res == NULL)
331 return NULL; /* Not a valid register name. */
91d6fa6a 332 regno = *preg;
252b5132 333 if (regno > 15)
f590b86e 334 as_bad (_("register r%d out of range"), regno);
e0c6ed95 335 }
252b5132
RH
336 }
337 return res;
252b5132
RH
338}
339
78a33af2 340static char *
464800ca 341parse_exp (char *s, expressionS *op)
252b5132
RH
342{
343 char *save = input_line_pointer;
d3ce72d0 344 char *new_pointer;
252b5132
RH
345
346 input_line_pointer = s;
347 expression (op);
348 if (op->X_op == O_absent)
349 as_bad (_("missing operand"));
d3ce72d0 350 new_pointer = input_line_pointer;
252b5132 351 input_line_pointer = save;
d3ce72d0 352 return new_pointer;
252b5132
RH
353}
354
355/* The many forms of operand:
356
357 <rb>
358 <r>
359 <rr>
360 <rq>
361 @r
362 #exp
363 exp
364 exp(r)
365 r(#exp)
366 r(r)
252b5132
RH
367 */
368
e0c6ed95 369static char *
464800ca 370checkfor (char *ptr, char what)
252b5132
RH
371{
372 if (*ptr == what)
373 ptr++;
374 else
e0c6ed95
AM
375 as_bad (_("expected %c"), what);
376
252b5132
RH
377 return ptr;
378}
379
e0c6ed95
AM
380/* Make sure the mode supplied is the size of a word. */
381
252b5132 382static void
e0471c16 383regword (int mode, const char *string)
252b5132
RH
384{
385 int ok;
386
387 ok = CLASS_REG_WORD;
388 if (ok != mode)
389 {
390 as_bad (_("register is wrong size for a word %s"), string);
391 }
392}
393
e0c6ed95
AM
394/* Make sure the mode supplied is the size of an address. */
395
252b5132 396static void
e0471c16 397regaddr (int mode, const char *string)
252b5132
RH
398{
399 int ok;
400
401 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
402 if (ok != mode)
403 {
404 as_bad (_("register is wrong size for address %s"), string);
405 }
406}
407
19d63e5d 408struct ctrl_names {
e0c6ed95 409 int value;
e0471c16 410 const char *name;
252b5132
RH
411};
412
464800ca 413static struct ctrl_names ctrl_table[] = {
bb5737a7
CG
414 { 0x1, "flags" }, /* ldctlb only. */
415 { 0x2, "fcw" }, /* ldctl only. Applies to all remaining control registers. */
879db8be
NC
416 { 0x3, "refresh" },
417 { 0x4, "psapseg" },
418 { 0x5, "psapoff" },
419 { 0x5, "psap" },
420 { 0x6, "nspseg" },
421 { 0x7, "nspoff" },
422 { 0x7, "nsp" },
423 { 0 , 0 }
252b5132 424};
e0c6ed95 425
252b5132 426static void
464800ca 427get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
428{
429 char *src = *ptr;
f69532ae 430 int i, l;
252b5132
RH
431
432 while (*src == ' ')
433 src++;
434
435 mode->mode = CLASS_CTRL;
436 for (i = 0; ctrl_table[i].name; i++)
437 {
f69532ae
CG
438 l = strlen (ctrl_table[i].name);
439 if (! strncasecmp (ctrl_table[i].name, src, l))
440 {
441 the_ctrl = ctrl_table[i].value;
442 if (*(src + l) && *(src + l) != ',')
443 break;
444 *ptr = src + l; /* Valid control name found: "consume" it. */
445 return;
446 }
252b5132
RH
447 }
448 the_ctrl = 0;
252b5132
RH
449}
450
19d63e5d 451struct flag_names {
252b5132 452 int value;
e0471c16 453 const char *name;
252b5132
RH
454};
455
464800ca 456static struct flag_names flag_table[] = {
bb5737a7
CG
457 { 0x1, "P" },
458 { 0x1, "V" },
459 { 0x2, "S" },
460 { 0x4, "Z" },
461 { 0x8, "C" },
879db8be 462 { 0x0, "+" },
bb5737a7 463 { 0x0, "," },
879db8be 464 { 0, 0 }
252b5132
RH
465};
466
467static void
464800ca 468get_flags_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
469{
470 char *src = *ptr;
bb5737a7 471 char c;
252b5132
RH
472 int i;
473 int j;
474
475 while (*src == ' ')
476 src++;
477
478 mode->mode = CLASS_FLAGS;
479 the_flags = 0;
480 for (j = 0; j <= 9; j++)
481 {
e0c6ed95 482 if (!src[j])
252b5132 483 goto done;
bb5737a7 484 c = TOUPPER(src[j]);
e0c6ed95
AM
485 for (i = 0; flag_table[i].name; i++)
486 {
bb5737a7 487 if (flag_table[i].name[0] == c)
e0c6ed95
AM
488 {
489 the_flags = the_flags | flag_table[i].value;
490 goto match;
491 }
492 }
252b5132
RH
493 goto done;
494 match:
e0c6ed95 495 ;
252b5132 496 }
e0c6ed95 497 done:
252b5132 498 *ptr = src + j;
252b5132
RH
499}
500
19d63e5d 501struct interrupt_names {
252b5132 502 int value;
e0471c16 503 const char *name;
252b5132
RH
504};
505
464800ca 506static struct interrupt_names intr_table[] = {
879db8be
NC
507 { 0x1, "nvi" },
508 { 0x2, "vi" },
509 { 0x3, "both" },
510 { 0x3, "all" },
511 { 0, 0 }
252b5132
RH
512};
513
514static void
464800ca 515get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
516{
517 char *src = *ptr;
bb5737a7 518 int i, l;
252b5132
RH
519
520 while (*src == ' ')
521 src++;
522
523 mode->mode = CLASS_IMM;
bb5737a7 524 the_interrupt = 0;
252b5132 525
bb5737a7
CG
526 while (*src)
527 {
528 for (i = 0; intr_table[i].name; i++)
529 {
530 l = strlen (intr_table[i].name);
531 if (! strncasecmp (intr_table[i].name, src, l))
532 {
533 the_interrupt |= intr_table[i].value;
534 if (*(src + l) && *(src + l) != ',')
535 {
536 *ptr = src + l;
537 invalid:
538 as_bad (_("unknown interrupt %s"), src);
539 while (**ptr && ! is_end_of_line[(unsigned char) **ptr])
540 (*ptr)++; /* Consume rest of line. */
541 return;
542 }
543 src += l;
544 if (! *src)
545 {
546 *ptr = src;
547 return;
548 }
549 }
550 }
551 if (*src == ',')
552 src++;
553 else
e0c6ed95 554 {
bb5737a7
CG
555 *ptr = src;
556 goto invalid;
e0c6ed95 557 }
252b5132 558 }
bb5737a7 559
7f31df7c 560 /* No interrupt type specified, opcode won't do anything. */
f590b86e 561 as_warn (_("opcode has no effect"));
252b5132 562 the_interrupt = 0x0;
252b5132
RH
563}
564
19d63e5d 565struct cc_names {
252b5132 566 int value;
e0471c16 567 const char *name;
252b5132
RH
568};
569
464800ca 570static struct cc_names table[] = {
879db8be
NC
571 { 0x0, "f" },
572 { 0x1, "lt" },
573 { 0x2, "le" },
574 { 0x3, "ule" },
d5bf5799 575 { 0x4, "ov/pe" },
879db8be 576 { 0x4, "ov" },
d5bf5799 577 { 0x4, "pe/ov" },
879db8be
NC
578 { 0x4, "pe" },
579 { 0x5, "mi" },
580 { 0x6, "eq" },
581 { 0x6, "z" },
d5bf5799 582 { 0x7, "c/ult" },
879db8be 583 { 0x7, "c" },
d5bf5799 584 { 0x7, "ult/c" },
879db8be
NC
585 { 0x7, "ult" },
586 { 0x8, "t" },
587 { 0x9, "ge" },
588 { 0xa, "gt" },
589 { 0xb, "ugt" },
d5bf5799 590 { 0xc, "nov/po" },
879db8be 591 { 0xc, "nov" },
d5bf5799 592 { 0xc, "po/nov" },
879db8be
NC
593 { 0xc, "po" },
594 { 0xd, "pl" },
595 { 0xe, "ne" },
596 { 0xe, "nz" },
d5bf5799 597 { 0xf, "nc/uge" },
879db8be 598 { 0xf, "nc" },
d5bf5799 599 { 0xf, "uge/nc" },
879db8be
NC
600 { 0xf, "uge" },
601 { 0 , 0 }
252b5132
RH
602};
603
604static void
464800ca 605get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
606{
607 char *src = *ptr;
d5bf5799 608 int i, l;
252b5132
RH
609
610 while (*src == ' ')
611 src++;
612
613 mode->mode = CLASS_CC;
614 for (i = 0; table[i].name; i++)
615 {
d5bf5799
CG
616 l = strlen (table[i].name);
617 if (! strncasecmp (table[i].name, src, l))
618 {
619 the_cc = table[i].value;
620 if (*(src + l) && *(src + l) != ',')
621 break;
622 *ptr = src + l; /* Valid cc found: "consume" it. */
623 return;
624 }
252b5132 625 }
d5bf5799 626 the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
252b5132
RH
627}
628
629static void
464800ca 630get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
631{
632 char *src = *ptr;
633 char *end;
252b5132
RH
634
635 mode->mode = 0;
636
637 while (*src == ' ')
638 src++;
639 if (*src == '#')
640 {
641 mode->mode = CLASS_IMM;
642 imm_operand = &(mode->exp);
643 src = parse_exp (src + 1, &(mode->exp));
644 }
645 else if (*src == '@')
646 {
252b5132 647 mode->mode = CLASS_IR;
f590b86e 648 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
252b5132
RH
649 }
650 else
651 {
2132e3a3 652 unsigned int regn;
252b5132
RH
653
654 end = parse_reg (src, &mode->mode, &regn);
655
656 if (end)
657 {
2132e3a3
AM
658 int nw;
659 unsigned int nr;
252b5132
RH
660
661 src = end;
662 if (*src == '(')
663 {
664 src++;
665 end = parse_reg (src, &nw, &nr);
666 if (end)
667 {
e0c6ed95 668 /* Got Ra(Rb). */
252b5132
RH
669 src = end;
670
671 if (*src != ')')
e0c6ed95 672 as_bad (_("Missing ) in ra(rb)"));
252b5132 673 else
e0c6ed95 674 src++;
252b5132
RH
675
676 regaddr (mode->mode, "ra(rb) ra");
252b5132
RH
677 mode->mode = CLASS_BX;
678 mode->reg = regn;
679 mode->x_reg = nr;
680 reg[ARG_RX] = nr;
681 }
682 else
683 {
e0c6ed95 684 /* Got Ra(disp). */
252b5132
RH
685 if (*src == '#')
686 src++;
687 src = parse_exp (src, &(mode->exp));
688 src = checkfor (src, ')');
689 mode->mode = CLASS_BA;
690 mode->reg = regn;
691 mode->x_reg = 0;
692 imm_operand = &(mode->exp);
693 }
694 }
695 else
696 {
697 mode->reg = regn;
698 mode->x_reg = 0;
699 }
700 }
701 else
702 {
e0c6ed95 703 /* No initial reg. */
252b5132
RH
704 src = parse_exp (src, &(mode->exp));
705 if (*src == '(')
706 {
707 src++;
708 end = parse_reg (src, &(mode->mode), &regn);
709 regword (mode->mode, "addr(Ra) ra");
710 mode->mode = CLASS_X;
711 mode->reg = regn;
712 mode->x_reg = 0;
713 da_operand = &(mode->exp);
714 src = checkfor (end, ')');
715 }
716 else
717 {
e0c6ed95 718 /* Just an address. */
252b5132
RH
719 mode->mode = CLASS_DA;
720 mode->reg = 0;
721 mode->x_reg = 0;
722 da_operand = &(mode->exp);
723 }
724 }
725 }
726 *ptr = src;
727}
728
e0c6ed95 729static char *
464800ca 730get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
252b5132
RH
731{
732 char *ptr = op_end;
e0c6ed95
AM
733 char *savptr;
734
252b5132
RH
735 switch (opcode->noperands)
736 {
737 case 0:
738 operand[0].mode = 0;
739 operand[1].mode = 0;
d5bf5799
CG
740 while (*ptr == ' ')
741 ptr++;
252b5132
RH
742 break;
743
744 case 1:
252b5132 745 if (opcode->arg_info[0] == CLASS_CC)
d5bf5799
CG
746 {
747 get_cc_operand (&ptr, operand + 0, 0);
748 while (*ptr == ' ')
749 ptr++;
750 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
751 {
752 as_bad (_("invalid condition code '%s'"), ptr);
753 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
754 ptr++; /* Consume rest of line. */
755 }
756 }
252b5132 757 else if (opcode->arg_info[0] == CLASS_FLAGS)
bb5737a7
CG
758 {
759 get_flags_operand (&ptr, operand + 0, 0);
760 while (*ptr == ' ')
761 ptr++;
762 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
763 {
764 as_bad (_("invalid flag '%s'"), ptr);
765 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
766 ptr++; /* Consume rest of line. */
767 }
768 }
e0c6ed95 769 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
14899840 770 get_interrupt_operand (&ptr, operand + 0, 0);
252b5132 771 else
14899840
NC
772 get_operand (&ptr, operand + 0, 0);
773
252b5132
RH
774 operand[1].mode = 0;
775 break;
776
777 case 2:
252b5132
RH
778 savptr = ptr;
779 if (opcode->arg_info[0] == CLASS_CC)
d5bf5799
CG
780 {
781 get_cc_operand (&ptr, operand + 0, 0);
782 while (*ptr == ' ')
783 ptr++;
784 if (*ptr != ',' && strchr (ptr + 1, ','))
785 {
786 savptr = ptr;
787 while (*ptr != ',')
788 ptr++;
789 *ptr = 0;
790 ptr++;
791 as_bad (_("invalid condition code '%s'"), savptr);
792 }
793 }
252b5132 794 else if (opcode->arg_info[0] == CLASS_CTRL)
e0c6ed95
AM
795 {
796 get_ctrl_operand (&ptr, operand + 0, 0);
14899840 797
e0c6ed95
AM
798 if (the_ctrl == 0)
799 {
800 ptr = savptr;
801 get_operand (&ptr, operand + 0, 0);
14899840 802
e0c6ed95 803 if (ptr == 0)
879db8be 804 return NULL;
e0c6ed95
AM
805 if (*ptr == ',')
806 ptr++;
807 get_ctrl_operand (&ptr, operand + 1, 1);
bb5737a7
CG
808 if (the_ctrl == 0)
809 return NULL;
e0c6ed95
AM
810 return ptr;
811 }
812 }
252b5132 813 else
14899840
NC
814 get_operand (&ptr, operand + 0, 0);
815
252b5132 816 if (ptr == 0)
879db8be 817 return NULL;
252b5132 818 if (*ptr == ',')
e0c6ed95 819 ptr++;
252b5132
RH
820 get_operand (&ptr, operand + 1, 1);
821 break;
822
823 case 3:
252b5132
RH
824 get_operand (&ptr, operand + 0, 0);
825 if (*ptr == ',')
826 ptr++;
827 get_operand (&ptr, operand + 1, 1);
828 if (*ptr == ',')
829 ptr++;
830 get_operand (&ptr, operand + 2, 2);
831 break;
832
833 case 4:
252b5132
RH
834 get_operand (&ptr, operand + 0, 0);
835 if (*ptr == ',')
836 ptr++;
837 get_operand (&ptr, operand + 1, 1);
838 if (*ptr == ',')
839 ptr++;
840 get_operand (&ptr, operand + 2, 2);
841 if (*ptr == ',')
842 ptr++;
843 get_cc_operand (&ptr, operand + 3, 3);
844 break;
e0c6ed95 845
252b5132
RH
846 default:
847 abort ();
848 }
849
850 return ptr;
851}
852
853/* Passed a pointer to a list of opcodes which use different
e0c6ed95
AM
854 addressing modes. Return the opcode which matches the opcodes
855 provided. */
252b5132 856
e0c6ed95 857static opcode_entry_type *
464800ca 858get_specific (opcode_entry_type *opcode, op_type *operands)
252b5132
RH
859{
860 opcode_entry_type *this_try = opcode;
861 int found = 0;
862 unsigned int noperands = opcode->noperands;
863
879db8be 864 int this_index = opcode->idx;
252b5132
RH
865
866 while (this_index == opcode->idx && !found)
867 {
868 unsigned int i;
869
870 this_try = opcode++;
871 for (i = 0; i < noperands; i++)
872 {
879db8be 873 unsigned int mode = operands[i].mode;
252b5132 874
f590b86e
CG
875 if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
876 {
877 mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
878 }
879
252b5132
RH
880 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
881 {
c03099e6 882 /* It could be a pc rel operand, if this is a da mode
e0c6ed95 883 and we like disps, then insert it. */
252b5132
RH
884
885 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
886 {
e0c6ed95 887 /* This is the case. */
252b5132
RH
888 operands[i].mode = CLASS_DISP;
889 }
890 else if (mode == CLASS_BA && this_try->arg_info[i])
891 {
e0c6ed95
AM
892 /* Can't think of a way to turn what we've been
893 given into something that's OK. */
252b5132
RH
894 goto fail;
895 }
896 else if (this_try->arg_info[i] & CLASS_PR)
897 {
898 if (mode == CLASS_REG_LONG && segmented_mode)
899 {
e0c6ed95 900 /* OK. */
252b5132
RH
901 }
902 else if (mode == CLASS_REG_WORD && !segmented_mode)
903 {
e0c6ed95 904 /* OK. */
252b5132
RH
905 }
906 else
907 goto fail;
908 }
909 else
910 goto fail;
911 }
912 switch (mode & CLASS_MASK)
913 {
914 default:
915 break;
f590b86e
CG
916 case CLASS_IRO:
917 if (operands[i].regsize != CLASS_REG_WORD)
918 as_bad (_("invalid indirect register size"));
919 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
920 break;
252b5132 921 case CLASS_IR:
f590b86e
CG
922 if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
923 || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
924 as_bad (_("invalid indirect register size"));
925 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
926 break;
927 case CLASS_X:
252b5132
RH
928 case CLASS_BA:
929 case CLASS_BX:
930 case CLASS_DISP:
931 case CLASS_REG:
932 case CLASS_REG_WORD:
933 case CLASS_REG_BYTE:
934 case CLASS_REG_QUAD:
935 case CLASS_REG_LONG:
936 case CLASS_REGN0:
937 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
938 break;
bb5737a7
CG
939 case CLASS_CTRL:
940 if (this_try->opcode == OPC_ldctlb && the_ctrl != 1)
941 as_bad (_("invalid control register name"));
942 break;
252b5132
RH
943 }
944 }
945
946 found = 1;
e0c6ed95
AM
947 fail:
948 ;
252b5132
RH
949 }
950 if (found)
951 return this_try;
952 else
953 return 0;
954}
955
252b5132
RH
956static char buffer[20];
957
958static void
35fec4ff 959newfix (int ptr, bfd_reloc_code_real_type type, int size, expressionS *operand)
252b5132 960{
c0524131 961 fixS *fixP;
a72d6b4e 962
c0524131 963 /* Size is in nibbles. */
252b5132
RH
964 if (operand->X_add_symbol
965 || operand->X_op_symbol
966 || operand->X_add_number)
967 {
35fec4ff 968 int is_pcrel;
a72d6b4e
CG
969 switch(type)
970 {
c0524131
NC
971 case BFD_RELOC_8_PCREL:
972 case BFD_RELOC_Z8K_CALLR:
973 case BFD_RELOC_Z8K_DISP7:
a72d6b4e 974 is_pcrel = 1;
35fec4ff
TS
975 break;
976 default:
977 is_pcrel = 0;
978 break;
a72d6b4e 979 }
c0524131
NC
980 fixP = fix_new_exp (frag_now, ptr, size / 2,
981 operand, is_pcrel, type);
982 if (is_pcrel)
983 fixP->fx_no_overflow = 1;
252b5132
RH
984 }
985}
986
987static char *
35fec4ff
TS
988apply_fix (char *ptr, bfd_reloc_code_real_type type, expressionS *operand,
989 int size)
252b5132 990{
7f31df7c 991 long n = operand->X_add_number;
252b5132 992
464800ca
CG
993 /* size is in nibbles. */
994
7f31df7c 995 newfix ((ptr - buffer) / 2, type, size + 1, operand);
252b5132
RH
996 switch (size)
997 {
879db8be 998 case 8: /* 8 nibbles == 32 bits. */
252b5132
RH
999 *ptr++ = n >> 28;
1000 *ptr++ = n >> 24;
1001 *ptr++ = n >> 20;
1002 *ptr++ = n >> 16;
879db8be 1003 case 4: /* 4 nibbles == 16 bits. */
252b5132
RH
1004 *ptr++ = n >> 12;
1005 *ptr++ = n >> 8;
1006 case 2:
1007 *ptr++ = n >> 4;
1008 case 1:
1009 *ptr++ = n >> 0;
1010 break;
1011 }
252b5132 1012 return ptr;
252b5132
RH
1013}
1014
e0c6ed95
AM
1015/* Now we know what sort of opcodes it is. Let's build the bytes. */
1016
252b5132 1017static void
464800ca 1018build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
252b5132 1019{
252b5132 1020 char *output_ptr = buffer;
252b5132 1021 int c;
252b5132
RH
1022 int nibble;
1023 unsigned int *class_ptr;
1024
1025 frag_wane (frag_now);
1026 frag_new (0);
1027
c0524131
NC
1028 if (frag_room () < 8)
1029 frag_grow (8); /* Make room for maximum instruction size. */
1030
25d3fb58 1031 memset (buffer, 0, sizeof (buffer));
252b5132 1032 class_ptr = this_try->byte_info;
252b5132 1033
879db8be 1034 for (nibble = 0; (c = *class_ptr++); nibble++)
252b5132
RH
1035 {
1036
1037 switch (c & CLASS_MASK)
1038 {
1039 default:
252b5132 1040 abort ();
e0c6ed95 1041
252b5132 1042 case CLASS_ADDRESS:
e0c6ed95 1043 /* Direct address, we don't cope with the SS mode right now. */
252b5132
RH
1044 if (segmented_mode)
1045 {
879db8be 1046 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
c0524131 1047 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, da_operand, 8);
252b5132
RH
1048 }
1049 else
1050 {
c0524131 1051 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
252b5132
RH
1052 }
1053 da_operand = 0;
1054 break;
1055 case CLASS_DISP8:
e0c6ed95 1056 /* pc rel 8 bit */
c0524131 1057 output_ptr = apply_fix (output_ptr, BFD_RELOC_8_PCREL, da_operand, 2);
252b5132
RH
1058 da_operand = 0;
1059 break;
1060
1061 case CLASS_0DISP7:
e0c6ed95 1062 /* pc rel 7 bit */
252b5132 1063 *output_ptr = 0;
c0524131 1064 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
252b5132
RH
1065 da_operand = 0;
1066 break;
1067
1068 case CLASS_1DISP7:
e0c6ed95 1069 /* pc rel 7 bit */
252b5132 1070 *output_ptr = 0x80;
c0524131 1071 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_DISP7, da_operand, 2);
e0c6ed95 1072 output_ptr[-2] = 0x8;
252b5132
RH
1073 da_operand = 0;
1074 break;
1075
1076 case CLASS_BIT_1OR2:
1077 *output_ptr = c & 0xf;
1078 if (imm_operand)
1079 {
1080 if (imm_operand->X_add_number == 2)
e0c6ed95 1081 *output_ptr |= 2;
252b5132 1082 else if (imm_operand->X_add_number != 1)
e0c6ed95 1083 as_bad (_("immediate must be 1 or 2"));
252b5132
RH
1084 }
1085 else
e0c6ed95 1086 as_bad (_("immediate 1 or 2 expected"));
252b5132
RH
1087 output_ptr++;
1088 break;
1089 case CLASS_CC:
1090 *output_ptr++ = the_cc;
1091 break;
e0c6ed95 1092 case CLASS_0CCC:
bb5737a7
CG
1093 if (the_ctrl < 2 || the_ctrl > 7)
1094 as_bad (_("invalid control register name"));
e0c6ed95
AM
1095 *output_ptr++ = the_ctrl;
1096 break;
1097 case CLASS_1CCC:
bb5737a7
CG
1098 if (the_ctrl < 2 || the_ctrl > 7)
1099 as_bad (_("invalid control register name"));
e0c6ed95
AM
1100 *output_ptr++ = the_ctrl | 0x8;
1101 break;
1102 case CLASS_00II:
1103 *output_ptr++ = (~the_interrupt & 0x3);
1104 break;
1105 case CLASS_01II:
1106 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1107 break;
1108 case CLASS_FLAGS:
1109 *output_ptr++ = the_flags;
1110 break;
3c25c5f6 1111 case CLASS_IGNORE:
252b5132
RH
1112 case CLASS_BIT:
1113 *output_ptr++ = c & 0xf;
1114 break;
1115 case CLASS_REGN0:
1116 if (reg[c & 0xf] == 0)
e0c6ed95
AM
1117 as_bad (_("can't use R0 here"));
1118 /* Fall through. */
252b5132
RH
1119 case CLASS_REG:
1120 case CLASS_REG_BYTE:
1121 case CLASS_REG_WORD:
1122 case CLASS_REG_LONG:
1123 case CLASS_REG_QUAD:
e0c6ed95 1124 /* Insert bit mattern of right reg. */
252b5132
RH
1125 *output_ptr++ = reg[c & 0xf];
1126 break;
1127 case CLASS_DISP:
6840198f
NC
1128 switch (c & ARG_MASK)
1129 {
1130 case ARG_DISP12:
c0524131 1131 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_CALLR, da_operand, 4);
6840198f
NC
1132 break;
1133 case ARG_DISP16:
c0524131 1134 output_ptr = apply_fix (output_ptr, BFD_RELOC_16_PCREL, da_operand, 4);
879db8be
NC
1135 break;
1136 default:
c0524131 1137 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, da_operand, 4);
879db8be 1138 }
252b5132
RH
1139 da_operand = 0;
1140 break;
1141
1142 case CLASS_IMM:
1143 {
252b5132
RH
1144 switch (c & ARG_MASK)
1145 {
3c25c5f6 1146 case ARG_NIM4:
7f31df7c 1147 if (imm_operand->X_add_number > 15)
c0524131 1148 as_bad (_("immediate value out of range"));
3c25c5f6 1149 imm_operand->X_add_number = -imm_operand->X_add_number;
c0524131 1150 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
252b5132 1151 break;
7f31df7c 1152 /*case ARG_IMMNMINUS1: not used. */
252b5132
RH
1153 case ARG_IMM4M1:
1154 imm_operand->X_add_number--;
7f31df7c
CG
1155 /* Drop through. */
1156 case ARG_IMM4:
1157 if (imm_operand->X_add_number > 15)
c0524131
NC
1158 as_bad (_("immediate value out of range"));
1159 output_ptr = apply_fix (output_ptr, BFD_RELOC_Z8K_IMM4L, imm_operand, 1);
252b5132
RH
1160 break;
1161 case ARG_NIM8:
1162 imm_operand->X_add_number = -imm_operand->X_add_number;
7f31df7c 1163 /* Drop through. */
252b5132 1164 case ARG_IMM8:
c0524131 1165 output_ptr = apply_fix (output_ptr, BFD_RELOC_8, imm_operand, 2);
252b5132
RH
1166 break;
1167 case ARG_IMM16:
c0524131 1168 output_ptr = apply_fix (output_ptr, BFD_RELOC_16, imm_operand, 4);
252b5132 1169 break;
252b5132 1170 case ARG_IMM32:
c0524131 1171 output_ptr = apply_fix (output_ptr, BFD_RELOC_32, imm_operand, 8);
252b5132 1172 break;
252b5132
RH
1173 default:
1174 abort ();
1175 }
1176 }
1177 }
1178 }
1179
e0c6ed95 1180 /* Copy from the nibble buffer into the frag. */
252b5132
RH
1181 {
1182 int length = (output_ptr - buffer) / 2;
1183 char *src = buffer;
1184 char *fragp = frag_more (length);
1185
1186 while (src < output_ptr)
1187 {
1188 *fragp = (src[0] << 4) | src[1];
1189 src += 2;
1190 fragp++;
1191 }
252b5132 1192 }
252b5132
RH
1193}
1194
1195/* This is the guts of the machine-dependent assembler. STR points to a
1994a7c7
NC
1196 machine dependent instruction. This function is supposed to emit
1197 the frags/bytes it assembles to. */
252b5132
RH
1198
1199void
464800ca 1200md_assemble (char *str)
252b5132 1201{
879db8be 1202 char c;
252b5132
RH
1203 char *op_start;
1204 char *op_end;
d8cbebfd 1205 struct z8k_op operand[4];
252b5132 1206 opcode_entry_type *opcode;
252b5132 1207
e0c6ed95 1208 /* Drop leading whitespace. */
252b5132
RH
1209 while (*str == ' ')
1210 str++;
1211
e0c6ed95 1212 /* Find the op code end. */
252b5132 1213 for (op_start = op_end = str;
d5bf5799 1214 *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
252b5132 1215 op_end++)
e0c6ed95 1216 ;
252b5132
RH
1217
1218 if (op_end == op_start)
1219 {
1220 as_bad (_("can't find opcode "));
1221 }
1222 c = *op_end;
1223
d5bf5799 1224 *op_end = 0; /* Zero-terminate op code string for hash_find() call. */
252b5132 1225
e0c6ed95 1226 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
252b5132
RH
1227
1228 if (opcode == NULL)
1229 {
1230 as_bad (_("unknown opcode"));
1231 return;
1232 }
1233
d5bf5799
CG
1234 *op_end = c; /* Restore original string. */
1235
252b5132
RH
1236 if (opcode->opcode == 250)
1237 {
252b5132
RH
1238 pseudo_typeS *p;
1239 char oc;
252b5132 1240 char *old = input_line_pointer;
252b5132 1241
3c25c5f6
NC
1242 /* Was really a pseudo op. */
1243
252b5132
RH
1244 input_line_pointer = op_end;
1245
1246 oc = *old;
1247 *old = '\n';
1248 while (*input_line_pointer == ' ')
1249 input_line_pointer++;
1250 p = (pseudo_typeS *) (opcode->func);
1251
1252 (p->poc_handler) (p->poc_val);
1253 input_line_pointer = old;
1254 *old = oc;
1255 }
1256 else
1257 {
3c25c5f6
NC
1258 char *new_input_line_pointer;
1259
1260 new_input_line_pointer = get_operands (opcode, op_end, operand);
1261 if (new_input_line_pointer)
7af0dfc7
CG
1262 {
1263 input_line_pointer = new_input_line_pointer;
1264 opcode = get_specific (opcode, operand);
1265 }
252b5132 1266
7af0dfc7 1267 if (new_input_line_pointer == NULL || opcode == NULL)
252b5132 1268 {
e0c6ed95 1269 /* Couldn't find an opcode which matched the operands. */
252b5132
RH
1270 char *where = frag_more (2);
1271
1272 where[0] = 0x0;
1273 where[1] = 0x0;
1274
1275 as_bad (_("Can't find opcode to match operands"));
1276 return;
1277 }
1278
1279 build_bytes (opcode, operand);
1280 }
1281}
1282
7f31df7c
CG
1283/* We have no need to default values of symbols. */
1284
252b5132 1285symbolS *
464800ca 1286md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
252b5132
RH
1287{
1288 return 0;
1289}
1290
e0c6ed95 1291/* Various routines to kill one day. */
e0c6ed95 1292
6d4af3c2 1293const char *
464800ca 1294md_atof (int type, char *litP, int *sizeP)
252b5132 1295{
499ac353 1296 return ieee_md_atof (type, litP, sizeP, TRUE);
252b5132
RH
1297}
1298\f
5a38dc70 1299const char *md_shortopts = "z:";
e0c6ed95 1300
3c25c5f6
NC
1301struct option md_longopts[] =
1302 {
7f31df7c
CG
1303#define OPTION_RELAX (OPTION_MD_BASE)
1304 {"linkrelax", no_argument, NULL, OPTION_RELAX},
3c25c5f6
NC
1305 {NULL, no_argument, NULL, 0}
1306 };
e0c6ed95
AM
1307
1308size_t md_longopts_size = sizeof (md_longopts);
252b5132
RH
1309
1310int
17b9d67d 1311md_parse_option (int c, const char *arg)
252b5132
RH
1312{
1313 switch (c)
1314 {
1315 case 'z':
1316 if (!strcmp (arg, "8001"))
00a3147e 1317 z8k_target_from_cmdline = 2;
252b5132 1318 else if (!strcmp (arg, "8002"))
00a3147e 1319 z8k_target_from_cmdline = 1;
252b5132
RH
1320 else
1321 {
1322 as_bad (_("invalid architecture -z%s"), arg);
1323 return 0;
1324 }
7f31df7c
CG
1325 break;
1326
1327 case OPTION_RELAX:
1328 linkrelax = 1;
252b5132
RH
1329 break;
1330
1331 default:
1332 return 0;
1333 }
1334
1335 return 1;
1336}
1337
1338void
464800ca 1339md_show_usage (FILE *stream)
252b5132 1340{
e0c6ed95 1341 fprintf (stream, _("\
7f31df7c
CG
1342 Z8K options:\n\
1343 -z8001 generate segmented code\n\
1344 -z8002 generate unsegmented code\n\
1345 -linkrelax create linker relaxable code\n"));
252b5132
RH
1346}
1347\f
252b5132 1348void
c0524131
NC
1349md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1350 segT sec ATTRIBUTE_UNUSED,
464800ca 1351 fragS *fragP ATTRIBUTE_UNUSED)
252b5132 1352{
7f31df7c 1353 printf (_("call to md_convert_frag\n"));
252b5132
RH
1354 abort ();
1355}
1356
c0524131
NC
1357/* Generate a machine dependent reloc from a fixup. */
1358
1359arelent*
1360tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1361 fixS *fixp ATTRIBUTE_UNUSED)
1362{
1363 arelent *reloc;
1364
325801bd
TS
1365 reloc = XNEW (arelent);
1366 reloc->sym_ptr_ptr = XNEW (asymbol *);
c0524131
NC
1367 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1368 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1369 reloc->addend = fixp->fx_offset;
1370 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1371
1372 if (! reloc->howto)
1373 {
1374 as_bad_where (fixp->fx_file, fixp->fx_line,
20203fb9 1375 _("Cannot represent %s relocation in object file"),
c0524131
NC
1376 bfd_get_reloc_code_name (fixp->fx_r_type));
1377 abort ();
1378 }
1379 return reloc;
1380}
1381
252b5132 1382valueT
464800ca 1383md_section_align (segT seg, valueT size)
252b5132 1384{
c0524131
NC
1385 int align = bfd_get_section_alignment (stdoutput, seg);
1386 valueT mask = ((valueT) 1 << align) - 1;
1387
1388 return (size + mask) & ~mask;
252b5132
RH
1389}
1390
a72d6b4e
CG
1391/* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1392 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1393 we will have to generate a reloc entry. */
252b5132 1394void
55cf6793 1395md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
252b5132 1396{
94f592af 1397 long val = * (long *) valP;
252b5132
RH
1398 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1399
1400 switch (fixP->fx_r_type)
1401 {
c0524131
NC
1402 case BFD_RELOC_Z8K_IMM4L:
1403 if (fixP->fx_addsy)
1404 {
1405 fixP->fx_no_overflow = 1;
1406 fixP->fx_done = 0;
1407 }
1408 else
1409 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1410 break;
1411
1412 case BFD_RELOC_8:
1413 if (fixP->fx_addsy)
1414 {
1415 fixP->fx_no_overflow = 1;
1416 fixP->fx_done = 0;
1417 }
1418 else
1419 *buf++ = val;
1420 break;
1421
1422 case BFD_RELOC_16:
1423 if (fixP->fx_addsy)
1424 {
1425 fixP->fx_no_overflow = 1;
1426 fixP->fx_done = 0;
1427 }
1428 else
1429 {
1430 *buf++ = (val >> 8);
1431 *buf++ = val;
1432 }
1433 break;
1434
1435 case BFD_RELOC_32:
1436 if (fixP->fx_addsy)
1437 {
1438 fixP->fx_no_overflow = 1;
1439 fixP->fx_done = 0;
1440 }
1441 else
1442 {
1443 *buf++ = (val >> 24);
1444 *buf++ = (val >> 16);
1445 *buf++ = (val >> 8);
1446 *buf++ = val;
1447 }
252b5132
RH
1448 break;
1449
c0524131 1450 case BFD_RELOC_8_PCREL:
a72d6b4e
CG
1451 if (fixP->fx_addsy)
1452 {
1453 fixP->fx_no_overflow = 1;
1454 fixP->fx_done = 0;
1455 }
1456 else
1457 {
f87a1e0c
CG
1458 if (val & 1)
1459 as_bad_where (fixP->fx_file, fixP->fx_line,
1460 _("cannot branch to odd address"));
1461 val /= 2;
1462 if (val > 127 || val < -128)
befd69ef
CG
1463 as_bad_where (fixP->fx_file, fixP->fx_line,
1464 _("relative jump out of range"));
f87a1e0c
CG
1465 *buf++ = val;
1466 fixP->fx_no_overflow = 1;
a72d6b4e
CG
1467 fixP->fx_done = 1;
1468 }
252b5132
RH
1469 break;
1470
c0524131 1471 case BFD_RELOC_16_PCREL:
a72d6b4e
CG
1472 if (fixP->fx_addsy)
1473 {
1474 fixP->fx_no_overflow = 1;
1475 fixP->fx_done = 0;
1476 }
1477 else
1478 {
c0524131
NC
1479 val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1480 if (val > 32767 || val < -32768)
f87a1e0c 1481 as_bad_where (fixP->fx_file, fixP->fx_line,
c0524131
NC
1482 _("relative address out of range"));
1483 *buf++ = (val >> 8);
1484 *buf++ = val;
d5bf5799 1485 fixP->fx_no_overflow = 1;
a72d6b4e
CG
1486 fixP->fx_done = 1;
1487 }
7f31df7c 1488 break;
252b5132 1489
c0524131 1490 case BFD_RELOC_Z8K_CALLR:
a72d6b4e
CG
1491 if (fixP->fx_addsy)
1492 {
1493 fixP->fx_no_overflow = 1;
1494 fixP->fx_done = 0;
1495 }
1496 else
1497 {
1498 if (val & 1)
f87a1e0c
CG
1499 as_bad_where (fixP->fx_file, fixP->fx_line,
1500 _("cannot branch to odd address"));
a72d6b4e 1501 if (val > 4096 || val < -4095)
f87a1e0c
CG
1502 as_bad_where (fixP->fx_file, fixP->fx_line,
1503 _("relative call out of range"));
a72d6b4e 1504 val = -val / 2;
d5bf5799
CG
1505 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1506 buf++;
1507 *buf++ = val & 0xff;
a72d6b4e
CG
1508 fixP->fx_no_overflow = 1;
1509 fixP->fx_done = 1;
1510 }
252b5132
RH
1511 break;
1512
c0524131
NC
1513 case BFD_RELOC_Z8K_DISP7:
1514 if (fixP->fx_addsy)
1515 {
1516 fixP->fx_no_overflow = 1;
1517 fixP->fx_done = 0;
1518 }
1519 else
1520 {
1521 if (val & 1)
1522 as_bad_where (fixP->fx_file, fixP->fx_line,
1523 _("cannot branch to odd address"));
1524 val /= 2;
1525 if (val > 0 || val < -127)
1526 as_bad_where (fixP->fx_file, fixP->fx_line,
1527 _("relative jump out of range"));
1528 *buf = (*buf & 0x80) | (-val & 0x7f);
1529 fixP->fx_no_overflow = 1;
1530 fixP->fx_done = 1;
1531 }
252b5132
RH
1532 break;
1533
1534 default:
55cf6793 1535 printf(_("md_apply_fix: unknown r_type 0x%x\n"), fixP->fx_r_type);
252b5132 1536 abort ();
252b5132 1537 }
94f592af
NC
1538
1539 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1540 fixP->fx_done = 1;
252b5132
RH
1541}
1542
1543int
464800ca
CG
1544md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1545 segT segment_type ATTRIBUTE_UNUSED)
252b5132 1546{
7f31df7c 1547 printf (_("call to md_estimate_size_before_relax\n"));
252b5132
RH
1548 abort ();
1549}
1550
e0c6ed95 1551/* Put number into target byte order. */
252b5132
RH
1552
1553void
464800ca 1554md_number_to_chars (char *ptr, valueT use, int nbytes)
252b5132
RH
1555{
1556 number_to_chars_bigendian (ptr, use, nbytes);
1557}
e0c6ed95 1558
a72d6b4e
CG
1559/* On the Z8000, a PC-relative offset is relative to the address of the
1560 instruction plus its size. */
252b5132 1561long
464800ca 1562md_pcrel_from (fixS *fixP)
252b5132 1563{
a72d6b4e 1564 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
252b5132
RH
1565}
1566
1567void
464800ca 1568tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)
252b5132
RH
1569{
1570}
This page took 0.801487 seconds and 4 git commands to generate.