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