Add vax-linux-gnu target
[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
28bab82b 249 if (src[0] == 's' && src[1] == 'p' && (src[2] == 0 || src[2] == ','))
252b5132
RH
250 {
251 if (segmented_mode)
e0c6ed95
AM
252 {
253 *mode = CLASS_REG_LONG;
254 *reg = 14;
255 }
252b5132 256 else
e0c6ed95
AM
257 {
258 *mode = CLASS_REG_WORD;
259 *reg = 15;
260 }
252b5132
RH
261 return src + 2;
262 }
263 if (src[0] == 'r')
264 {
265 if (src[1] == 'r')
e0c6ed95 266 {
28bab82b
NC
267 if (src[2] < '0' || src[2] > '9')
268 return res; /* Assume no register name but a label starting with 'rr'. */
e0c6ed95
AM
269 *mode = CLASS_REG_LONG;
270 res = whatreg (reg, src + 2);
252b5132
RH
271 regno = *reg;
272 if (regno > 14)
f590b86e
CG
273 as_bad (_("register rr%d out of range"), regno);
274 if (regno & 1)
275 as_bad (_("register rr%d does not exist"), regno);
e0c6ed95 276 }
252b5132 277 else if (src[1] == 'h')
e0c6ed95 278 {
28bab82b
NC
279 if (src[2] < '0' || src[2] > '9')
280 return res; /* Assume no register name but a label starting with 'rh'. */
e0c6ed95
AM
281 *mode = CLASS_REG_BYTE;
282 res = whatreg (reg, src + 2);
252b5132
RH
283 regno = *reg;
284 if (regno > 7)
f590b86e 285 as_bad (_("register rh%d out of range"), regno);
e0c6ed95 286 }
252b5132 287 else if (src[1] == 'l')
e0c6ed95 288 {
28bab82b
NC
289 if (src[2] < '0' || src[2] > '9')
290 return res; /* Assume no register name but a label starting with 'rl'. */
e0c6ed95
AM
291 *mode = CLASS_REG_BYTE;
292 res = whatreg (reg, src + 2);
252b5132
RH
293 regno = *reg;
294 if (regno > 7)
f590b86e 295 as_bad (_("register rl%d out of range"), regno);
e0c6ed95
AM
296 *reg += 8;
297 }
252b5132 298 else if (src[1] == 'q')
e0c6ed95 299 {
28bab82b
NC
300 if (src[2] < '0' || src[2] > '9')
301 return res; /* Assume no register name but a label starting with 'rq'. */
e0c6ed95
AM
302 *mode = CLASS_REG_QUAD;
303 res = whatreg (reg, src + 2);
252b5132
RH
304 regno = *reg;
305 if (regno > 12)
f590b86e
CG
306 as_bad (_("register rq%d out of range"), regno);
307 if (regno & 3)
308 as_bad (_("register rq%d does not exist"), regno);
e0c6ed95 309 }
252b5132 310 else
e0c6ed95 311 {
28bab82b
NC
312 if (src[1] < '0' || src[1] > '9')
313 return res; /* Assume no register name but a label starting with 'r'. */
e0c6ed95
AM
314 *mode = CLASS_REG_WORD;
315 res = whatreg (reg, src + 1);
252b5132
RH
316 regno = *reg;
317 if (regno > 15)
f590b86e 318 as_bad (_("register r%d out of range"), regno);
e0c6ed95 319 }
252b5132
RH
320 }
321 return res;
252b5132
RH
322}
323
78a33af2 324static char *
464800ca 325parse_exp (char *s, expressionS *op)
252b5132
RH
326{
327 char *save = input_line_pointer;
328 char *new;
329
330 input_line_pointer = s;
331 expression (op);
332 if (op->X_op == O_absent)
333 as_bad (_("missing operand"));
334 new = input_line_pointer;
335 input_line_pointer = save;
336 return new;
337}
338
339/* The many forms of operand:
340
341 <rb>
342 <r>
343 <rr>
344 <rq>
345 @r
346 #exp
347 exp
348 exp(r)
349 r(#exp)
350 r(r)
252b5132
RH
351 */
352
e0c6ed95 353static char *
464800ca 354checkfor (char *ptr, char what)
252b5132
RH
355{
356 if (*ptr == what)
357 ptr++;
358 else
e0c6ed95
AM
359 as_bad (_("expected %c"), what);
360
252b5132
RH
361 return ptr;
362}
363
e0c6ed95
AM
364/* Make sure the mode supplied is the size of a word. */
365
252b5132 366static void
464800ca 367regword (int mode, char *string)
252b5132
RH
368{
369 int ok;
370
371 ok = CLASS_REG_WORD;
372 if (ok != mode)
373 {
374 as_bad (_("register is wrong size for a word %s"), string);
375 }
376}
377
e0c6ed95
AM
378/* Make sure the mode supplied is the size of an address. */
379
252b5132 380static void
464800ca 381regaddr (int mode, char *string)
252b5132
RH
382{
383 int ok;
384
385 ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
386 if (ok != mode)
387 {
388 as_bad (_("register is wrong size for address %s"), string);
389 }
390}
391
19d63e5d 392struct ctrl_names {
e0c6ed95
AM
393 int value;
394 char *name;
252b5132
RH
395};
396
464800ca 397static struct ctrl_names ctrl_table[] = {
879db8be
NC
398 { 0x2, "fcw" },
399 { 0x3, "refresh" },
400 { 0x4, "psapseg" },
401 { 0x5, "psapoff" },
402 { 0x5, "psap" },
403 { 0x6, "nspseg" },
404 { 0x7, "nspoff" },
405 { 0x7, "nsp" },
406 { 0 , 0 }
252b5132 407};
e0c6ed95 408
252b5132 409static void
464800ca 410get_ctrl_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
411{
412 char *src = *ptr;
252b5132
RH
413 int i;
414
415 while (*src == ' ')
416 src++;
417
418 mode->mode = CLASS_CTRL;
419 for (i = 0; ctrl_table[i].name; i++)
420 {
421 int j;
422
423 for (j = 0; ctrl_table[i].name[j]; j++)
e0c6ed95
AM
424 {
425 if (ctrl_table[i].name[j] != src[j])
426 goto fail;
427 }
252b5132
RH
428 the_ctrl = ctrl_table[i].value;
429 *ptr = src + j;
430 return;
e0c6ed95
AM
431 fail:
432 ;
252b5132
RH
433 }
434 the_ctrl = 0;
435 return;
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
RH
482 *ptr = src + j;
483 return;
484}
485
19d63e5d 486struct interrupt_names {
252b5132
RH
487 int value;
488 char *name;
252b5132
RH
489};
490
464800ca 491static struct interrupt_names intr_table[] = {
879db8be
NC
492 { 0x1, "nvi" },
493 { 0x2, "vi" },
494 { 0x3, "both" },
495 { 0x3, "all" },
496 { 0, 0 }
252b5132
RH
497};
498
499static void
464800ca 500get_interrupt_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
501{
502 char *src = *ptr;
252b5132
RH
503 int i;
504
505 while (*src == ' ')
506 src++;
507
508 mode->mode = CLASS_IMM;
509 for (i = 0; intr_table[i].name; i++)
510 {
511 int j;
512
513 for (j = 0; intr_table[i].name[j]; j++)
e0c6ed95
AM
514 {
515 if (intr_table[i].name[j] != src[j])
516 goto fail;
517 }
252b5132
RH
518 the_interrupt = intr_table[i].value;
519 *ptr = src + j;
520 return;
e0c6ed95
AM
521 fail:
522 ;
252b5132 523 }
7f31df7c 524 /* No interrupt type specified, opcode won't do anything. */
f590b86e 525 as_warn (_("opcode has no effect"));
252b5132
RH
526 the_interrupt = 0x0;
527 return;
528}
529
19d63e5d 530struct cc_names {
252b5132
RH
531 int value;
532 char *name;
252b5132
RH
533};
534
464800ca 535static struct cc_names table[] = {
879db8be
NC
536 { 0x0, "f" },
537 { 0x1, "lt" },
538 { 0x2, "le" },
539 { 0x3, "ule" },
d5bf5799 540 { 0x4, "ov/pe" },
879db8be 541 { 0x4, "ov" },
d5bf5799 542 { 0x4, "pe/ov" },
879db8be
NC
543 { 0x4, "pe" },
544 { 0x5, "mi" },
545 { 0x6, "eq" },
546 { 0x6, "z" },
d5bf5799 547 { 0x7, "c/ult" },
879db8be 548 { 0x7, "c" },
d5bf5799 549 { 0x7, "ult/c" },
879db8be
NC
550 { 0x7, "ult" },
551 { 0x8, "t" },
552 { 0x9, "ge" },
553 { 0xa, "gt" },
554 { 0xb, "ugt" },
d5bf5799 555 { 0xc, "nov/po" },
879db8be 556 { 0xc, "nov" },
d5bf5799 557 { 0xc, "po/nov" },
879db8be
NC
558 { 0xc, "po" },
559 { 0xd, "pl" },
560 { 0xe, "ne" },
561 { 0xe, "nz" },
d5bf5799 562 { 0xf, "nc/uge" },
879db8be 563 { 0xf, "nc" },
d5bf5799 564 { 0xf, "uge/nc" },
879db8be
NC
565 { 0xf, "uge" },
566 { 0 , 0 }
252b5132
RH
567};
568
569static void
464800ca 570get_cc_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
571{
572 char *src = *ptr;
d5bf5799 573 int i, l;
252b5132
RH
574
575 while (*src == ' ')
576 src++;
577
578 mode->mode = CLASS_CC;
579 for (i = 0; table[i].name; i++)
580 {
d5bf5799
CG
581 l = strlen (table[i].name);
582 if (! strncasecmp (table[i].name, src, l))
583 {
584 the_cc = table[i].value;
585 if (*(src + l) && *(src + l) != ',')
586 break;
587 *ptr = src + l; /* Valid cc found: "consume" it. */
588 return;
589 }
252b5132 590 }
d5bf5799 591 the_cc = 0x8; /* Not recognizing the cc defaults to t. (Assuming no cc present.) */
252b5132
RH
592}
593
594static void
464800ca 595get_operand (char **ptr, struct z8k_op *mode, unsigned int dst ATTRIBUTE_UNUSED)
252b5132
RH
596{
597 char *src = *ptr;
598 char *end;
252b5132
RH
599
600 mode->mode = 0;
601
602 while (*src == ' ')
603 src++;
604 if (*src == '#')
605 {
606 mode->mode = CLASS_IMM;
607 imm_operand = &(mode->exp);
608 src = parse_exp (src + 1, &(mode->exp));
609 }
610 else if (*src == '@')
611 {
252b5132 612 mode->mode = CLASS_IR;
f590b86e 613 src = parse_reg (src + 1, &mode->regsize, &mode->reg);
252b5132
RH
614 }
615 else
616 {
617 int regn;
618
619 end = parse_reg (src, &mode->mode, &regn);
620
621 if (end)
622 {
623 int nw, nr;
624
625 src = end;
626 if (*src == '(')
627 {
628 src++;
629 end = parse_reg (src, &nw, &nr);
630 if (end)
631 {
e0c6ed95 632 /* Got Ra(Rb). */
252b5132
RH
633 src = end;
634
635 if (*src != ')')
e0c6ed95 636 as_bad (_("Missing ) in ra(rb)"));
252b5132 637 else
e0c6ed95 638 src++;
252b5132
RH
639
640 regaddr (mode->mode, "ra(rb) ra");
e0c6ed95
AM
641#if 0
642 regword (mode->mode, "ra(rb) rb");
643#endif
252b5132
RH
644 mode->mode = CLASS_BX;
645 mode->reg = regn;
646 mode->x_reg = nr;
647 reg[ARG_RX] = nr;
648 }
649 else
650 {
e0c6ed95 651 /* Got Ra(disp). */
252b5132
RH
652 if (*src == '#')
653 src++;
654 src = parse_exp (src, &(mode->exp));
655 src = checkfor (src, ')');
656 mode->mode = CLASS_BA;
657 mode->reg = regn;
658 mode->x_reg = 0;
659 imm_operand = &(mode->exp);
660 }
661 }
662 else
663 {
664 mode->reg = regn;
665 mode->x_reg = 0;
666 }
667 }
668 else
669 {
e0c6ed95 670 /* No initial reg. */
252b5132
RH
671 src = parse_exp (src, &(mode->exp));
672 if (*src == '(')
673 {
674 src++;
675 end = parse_reg (src, &(mode->mode), &regn);
676 regword (mode->mode, "addr(Ra) ra");
677 mode->mode = CLASS_X;
678 mode->reg = regn;
679 mode->x_reg = 0;
680 da_operand = &(mode->exp);
681 src = checkfor (end, ')');
682 }
683 else
684 {
e0c6ed95 685 /* Just an address. */
252b5132
RH
686 mode->mode = CLASS_DA;
687 mode->reg = 0;
688 mode->x_reg = 0;
689 da_operand = &(mode->exp);
690 }
691 }
692 }
693 *ptr = src;
694}
695
e0c6ed95 696static char *
464800ca 697get_operands (const opcode_entry_type *opcode, char *op_end, op_type *operand)
252b5132
RH
698{
699 char *ptr = op_end;
e0c6ed95
AM
700 char *savptr;
701
252b5132
RH
702 switch (opcode->noperands)
703 {
704 case 0:
705 operand[0].mode = 0;
706 operand[1].mode = 0;
d5bf5799
CG
707 while (*ptr == ' ')
708 ptr++;
252b5132
RH
709 break;
710
711 case 1:
252b5132 712 if (opcode->arg_info[0] == CLASS_CC)
d5bf5799
CG
713 {
714 get_cc_operand (&ptr, operand + 0, 0);
715 while (*ptr == ' ')
716 ptr++;
717 if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
718 {
719 as_bad (_("invalid condition code '%s'"), ptr);
720 while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
721 ptr++; /* Consume rest of line. */
722 }
723 }
14899840 724
252b5132 725 else if (opcode->arg_info[0] == CLASS_FLAGS)
14899840
NC
726 get_flags_operand (&ptr, operand + 0, 0);
727
e0c6ed95 728 else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
14899840
NC
729 get_interrupt_operand (&ptr, operand + 0, 0);
730
252b5132 731 else
14899840
NC
732 get_operand (&ptr, operand + 0, 0);
733
252b5132
RH
734 operand[1].mode = 0;
735 break;
736
737 case 2:
252b5132
RH
738 savptr = ptr;
739 if (opcode->arg_info[0] == CLASS_CC)
d5bf5799
CG
740 {
741 get_cc_operand (&ptr, operand + 0, 0);
742 while (*ptr == ' ')
743 ptr++;
744 if (*ptr != ',' && strchr (ptr + 1, ','))
745 {
746 savptr = ptr;
747 while (*ptr != ',')
748 ptr++;
749 *ptr = 0;
750 ptr++;
751 as_bad (_("invalid condition code '%s'"), savptr);
752 }
753 }
14899840 754
252b5132 755 else if (opcode->arg_info[0] == CLASS_CTRL)
e0c6ed95
AM
756 {
757 get_ctrl_operand (&ptr, operand + 0, 0);
14899840 758
e0c6ed95
AM
759 if (the_ctrl == 0)
760 {
761 ptr = savptr;
762 get_operand (&ptr, operand + 0, 0);
14899840 763
e0c6ed95 764 if (ptr == 0)
879db8be 765 return NULL;
e0c6ed95
AM
766 if (*ptr == ',')
767 ptr++;
768 get_ctrl_operand (&ptr, operand + 1, 1);
769 return ptr;
770 }
771 }
252b5132 772 else
14899840
NC
773 get_operand (&ptr, operand + 0, 0);
774
252b5132 775 if (ptr == 0)
879db8be 776 return NULL;
252b5132 777 if (*ptr == ',')
e0c6ed95 778 ptr++;
252b5132
RH
779 get_operand (&ptr, operand + 1, 1);
780 break;
781
782 case 3:
252b5132
RH
783 get_operand (&ptr, operand + 0, 0);
784 if (*ptr == ',')
785 ptr++;
786 get_operand (&ptr, operand + 1, 1);
787 if (*ptr == ',')
788 ptr++;
789 get_operand (&ptr, operand + 2, 2);
790 break;
791
792 case 4:
252b5132
RH
793 get_operand (&ptr, operand + 0, 0);
794 if (*ptr == ',')
795 ptr++;
796 get_operand (&ptr, operand + 1, 1);
797 if (*ptr == ',')
798 ptr++;
799 get_operand (&ptr, operand + 2, 2);
800 if (*ptr == ',')
801 ptr++;
802 get_cc_operand (&ptr, operand + 3, 3);
803 break;
e0c6ed95 804
252b5132
RH
805 default:
806 abort ();
807 }
808
809 return ptr;
810}
811
812/* Passed a pointer to a list of opcodes which use different
e0c6ed95
AM
813 addressing modes. Return the opcode which matches the opcodes
814 provided. */
252b5132 815
e0c6ed95 816static opcode_entry_type *
464800ca 817get_specific (opcode_entry_type *opcode, op_type *operands)
252b5132
RH
818{
819 opcode_entry_type *this_try = opcode;
820 int found = 0;
821 unsigned int noperands = opcode->noperands;
822
879db8be 823 int this_index = opcode->idx;
252b5132
RH
824
825 while (this_index == opcode->idx && !found)
826 {
827 unsigned int i;
828
829 this_try = opcode++;
830 for (i = 0; i < noperands; i++)
831 {
879db8be 832 unsigned int mode = operands[i].mode;
252b5132 833
f590b86e
CG
834 if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
835 {
836 mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
837 }
838
252b5132
RH
839 if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
840 {
c03099e6 841 /* It could be a pc rel operand, if this is a da mode
e0c6ed95 842 and we like disps, then insert it. */
252b5132
RH
843
844 if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
845 {
e0c6ed95 846 /* This is the case. */
252b5132
RH
847 operands[i].mode = CLASS_DISP;
848 }
849 else if (mode == CLASS_BA && this_try->arg_info[i])
850 {
e0c6ed95
AM
851 /* Can't think of a way to turn what we've been
852 given into something that's OK. */
252b5132
RH
853 goto fail;
854 }
855 else if (this_try->arg_info[i] & CLASS_PR)
856 {
857 if (mode == CLASS_REG_LONG && segmented_mode)
858 {
e0c6ed95 859 /* OK. */
252b5132
RH
860 }
861 else if (mode == CLASS_REG_WORD && !segmented_mode)
862 {
e0c6ed95 863 /* OK. */
252b5132
RH
864 }
865 else
866 goto fail;
867 }
868 else
869 goto fail;
870 }
871 switch (mode & CLASS_MASK)
872 {
873 default:
874 break;
f590b86e
CG
875 case CLASS_IRO:
876 if (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;
252b5132 880 case CLASS_IR:
f590b86e
CG
881 if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
882 || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
883 as_bad (_("invalid indirect register size"));
884 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
885 break;
886 case CLASS_X:
252b5132
RH
887 case CLASS_BA:
888 case CLASS_BX:
889 case CLASS_DISP:
890 case CLASS_REG:
891 case CLASS_REG_WORD:
892 case CLASS_REG_BYTE:
893 case CLASS_REG_QUAD:
894 case CLASS_REG_LONG:
895 case CLASS_REGN0:
896 reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
897 break;
898 }
899 }
900
901 found = 1;
e0c6ed95
AM
902 fail:
903 ;
252b5132
RH
904 }
905 if (found)
906 return this_try;
907 else
908 return 0;
909}
910
252b5132
RH
911static char buffer[20];
912
913static void
464800ca 914newfix (int ptr, int type, int size, expressionS *operand)
252b5132 915{
a72d6b4e
CG
916 int is_pcrel = 0;
917
464800ca
CG
918 /* size is in nibbles. */
919
252b5132
RH
920 if (operand->X_add_symbol
921 || operand->X_op_symbol
922 || operand->X_add_number)
923 {
a72d6b4e
CG
924 switch(type)
925 {
926 case R_JR:
927 case R_DISP7:
928 case R_CALLR:
929 is_pcrel = 1;
930 }
252b5132
RH
931 fix_new_exp (frag_now,
932 ptr,
7f31df7c 933 size / 2,
252b5132 934 operand,
a72d6b4e 935 is_pcrel,
252b5132
RH
936 type);
937 }
938}
939
940static char *
464800ca 941apply_fix (char *ptr, int type, expressionS *operand, int size)
252b5132 942{
7f31df7c 943 long n = operand->X_add_number;
252b5132 944
464800ca
CG
945 /* size is in nibbles. */
946
7f31df7c 947 newfix ((ptr - buffer) / 2, type, size + 1, operand);
252b5132
RH
948 switch (size)
949 {
879db8be 950 case 8: /* 8 nibbles == 32 bits. */
252b5132
RH
951 *ptr++ = n >> 28;
952 *ptr++ = n >> 24;
953 *ptr++ = n >> 20;
954 *ptr++ = n >> 16;
879db8be 955 case 4: /* 4 nibbles == 16 bits. */
252b5132
RH
956 *ptr++ = n >> 12;
957 *ptr++ = n >> 8;
958 case 2:
959 *ptr++ = n >> 4;
960 case 1:
961 *ptr++ = n >> 0;
962 break;
963 }
252b5132 964 return ptr;
252b5132
RH
965}
966
e0c6ed95
AM
967/* Now we know what sort of opcodes it is. Let's build the bytes. */
968
252b5132 969#define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
19d63e5d 970
252b5132 971static void
464800ca 972build_bytes (opcode_entry_type *this_try, struct z8k_op *operand ATTRIBUTE_UNUSED)
252b5132 973{
252b5132 974 char *output_ptr = buffer;
252b5132 975 int c;
252b5132
RH
976 int nibble;
977 unsigned int *class_ptr;
978
979 frag_wane (frag_now);
980 frag_new (0);
981
25d3fb58 982 memset (buffer, 0, sizeof (buffer));
252b5132 983 class_ptr = this_try->byte_info;
252b5132 984
879db8be 985 for (nibble = 0; (c = *class_ptr++); nibble++)
252b5132
RH
986 {
987
988 switch (c & CLASS_MASK)
989 {
990 default:
252b5132 991 abort ();
e0c6ed95 992
252b5132 993 case CLASS_ADDRESS:
e0c6ed95 994 /* Direct address, we don't cope with the SS mode right now. */
252b5132
RH
995 if (segmented_mode)
996 {
879db8be 997 /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */
252b5132
RH
998 output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
999 }
1000 else
1001 {
1002 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1003 }
1004 da_operand = 0;
1005 break;
1006 case CLASS_DISP8:
e0c6ed95 1007 /* pc rel 8 bit */
252b5132
RH
1008 output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
1009 da_operand = 0;
1010 break;
1011
1012 case CLASS_0DISP7:
e0c6ed95 1013 /* pc rel 7 bit */
252b5132
RH
1014 *output_ptr = 0;
1015 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1016 da_operand = 0;
1017 break;
1018
1019 case CLASS_1DISP7:
e0c6ed95 1020 /* pc rel 7 bit */
252b5132
RH
1021 *output_ptr = 0x80;
1022 output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
e0c6ed95 1023 output_ptr[-2] = 0x8;
252b5132
RH
1024 da_operand = 0;
1025 break;
1026
1027 case CLASS_BIT_1OR2:
1028 *output_ptr = c & 0xf;
1029 if (imm_operand)
1030 {
1031 if (imm_operand->X_add_number == 2)
e0c6ed95 1032 *output_ptr |= 2;
252b5132 1033 else if (imm_operand->X_add_number != 1)
e0c6ed95 1034 as_bad (_("immediate must be 1 or 2"));
252b5132
RH
1035 }
1036 else
e0c6ed95 1037 as_bad (_("immediate 1 or 2 expected"));
252b5132
RH
1038 output_ptr++;
1039 break;
1040 case CLASS_CC:
1041 *output_ptr++ = the_cc;
1042 break;
e0c6ed95
AM
1043 case CLASS_0CCC:
1044 *output_ptr++ = the_ctrl;
1045 break;
1046 case CLASS_1CCC:
1047 *output_ptr++ = the_ctrl | 0x8;
1048 break;
1049 case CLASS_00II:
1050 *output_ptr++ = (~the_interrupt & 0x3);
1051 break;
1052 case CLASS_01II:
1053 *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1054 break;
1055 case CLASS_FLAGS:
1056 *output_ptr++ = the_flags;
1057 break;
3c25c5f6 1058 case CLASS_IGNORE:
252b5132
RH
1059 case CLASS_BIT:
1060 *output_ptr++ = c & 0xf;
1061 break;
1062 case CLASS_REGN0:
1063 if (reg[c & 0xf] == 0)
e0c6ed95
AM
1064 as_bad (_("can't use R0 here"));
1065 /* Fall through. */
252b5132
RH
1066 case CLASS_REG:
1067 case CLASS_REG_BYTE:
1068 case CLASS_REG_WORD:
1069 case CLASS_REG_LONG:
1070 case CLASS_REG_QUAD:
e0c6ed95 1071 /* Insert bit mattern of right reg. */
252b5132
RH
1072 *output_ptr++ = reg[c & 0xf];
1073 break;
1074 case CLASS_DISP:
6840198f
NC
1075 switch (c & ARG_MASK)
1076 {
1077 case ARG_DISP12:
1078 output_ptr = apply_fix (output_ptr, R_CALLR, da_operand, 4);
1079 break;
1080 case ARG_DISP16:
879db8be
NC
1081 output_ptr = apply_fix (output_ptr, R_REL16, da_operand, 4);
1082 break;
1083 default:
1084 output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1085 }
252b5132
RH
1086 da_operand = 0;
1087 break;
1088
1089 case CLASS_IMM:
1090 {
252b5132
RH
1091 switch (c & ARG_MASK)
1092 {
3c25c5f6 1093 case ARG_NIM4:
7f31df7c
CG
1094 if (imm_operand->X_add_number > 15)
1095 {
1096 as_bad (_("immediate value out of range"));
1097 }
3c25c5f6 1098 imm_operand->X_add_number = -imm_operand->X_add_number;
252b5132
RH
1099 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1100 break;
7f31df7c 1101 /*case ARG_IMMNMINUS1: not used. */
252b5132
RH
1102 case ARG_IMM4M1:
1103 imm_operand->X_add_number--;
7f31df7c
CG
1104 /* Drop through. */
1105 case ARG_IMM4:
1106 if (imm_operand->X_add_number > 15)
1107 {
1108 as_bad (_("immediate value out of range"));
1109 }
252b5132
RH
1110 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1111 break;
1112 case ARG_NIM8:
1113 imm_operand->X_add_number = -imm_operand->X_add_number;
7f31df7c 1114 /* Drop through. */
252b5132
RH
1115 case ARG_IMM8:
1116 output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
1117 break;
1118 case ARG_IMM16:
1119 output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
1120 break;
252b5132
RH
1121 case ARG_IMM32:
1122 output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
1123 break;
252b5132
RH
1124 default:
1125 abort ();
1126 }
1127 }
1128 }
1129 }
1130
e0c6ed95 1131 /* Copy from the nibble buffer into the frag. */
252b5132
RH
1132 {
1133 int length = (output_ptr - buffer) / 2;
1134 char *src = buffer;
1135 char *fragp = frag_more (length);
1136
1137 while (src < output_ptr)
1138 {
1139 *fragp = (src[0] << 4) | src[1];
1140 src += 2;
1141 fragp++;
1142 }
252b5132 1143 }
252b5132
RH
1144}
1145
1146/* This is the guts of the machine-dependent assembler. STR points to a
1994a7c7
NC
1147 machine dependent instruction. This function is supposed to emit
1148 the frags/bytes it assembles to. */
252b5132
RH
1149
1150void
464800ca 1151md_assemble (char *str)
252b5132 1152{
879db8be 1153 char c;
252b5132
RH
1154 char *op_start;
1155 char *op_end;
252b5132
RH
1156 struct z8k_op operand[3];
1157 opcode_entry_type *opcode;
252b5132 1158
e0c6ed95 1159 /* Drop leading whitespace. */
252b5132
RH
1160 while (*str == ' ')
1161 str++;
1162
e0c6ed95 1163 /* Find the op code end. */
252b5132 1164 for (op_start = op_end = str;
d5bf5799 1165 *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
252b5132 1166 op_end++)
e0c6ed95 1167 ;
252b5132
RH
1168
1169 if (op_end == op_start)
1170 {
1171 as_bad (_("can't find opcode "));
1172 }
1173 c = *op_end;
1174
d5bf5799 1175 *op_end = 0; /* Zero-terminate op code string for hash_find() call. */
252b5132 1176
e0c6ed95 1177 opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
252b5132
RH
1178
1179 if (opcode == NULL)
1180 {
1181 as_bad (_("unknown opcode"));
1182 return;
1183 }
1184
d5bf5799
CG
1185 *op_end = c; /* Restore original string. */
1186
252b5132
RH
1187 if (opcode->opcode == 250)
1188 {
252b5132
RH
1189 pseudo_typeS *p;
1190 char oc;
252b5132 1191 char *old = input_line_pointer;
252b5132 1192
3c25c5f6
NC
1193 /* Was really a pseudo op. */
1194
252b5132
RH
1195 input_line_pointer = op_end;
1196
1197 oc = *old;
1198 *old = '\n';
1199 while (*input_line_pointer == ' ')
1200 input_line_pointer++;
1201 p = (pseudo_typeS *) (opcode->func);
1202
1203 (p->poc_handler) (p->poc_val);
1204 input_line_pointer = old;
1205 *old = oc;
1206 }
1207 else
1208 {
3c25c5f6
NC
1209 char *new_input_line_pointer;
1210
1211 new_input_line_pointer = get_operands (opcode, op_end, operand);
1212 if (new_input_line_pointer)
1213 input_line_pointer = new_input_line_pointer;
252b5132
RH
1214
1215 opcode = get_specific (opcode, operand);
1216
1217 if (opcode == 0)
1218 {
e0c6ed95 1219 /* Couldn't find an opcode which matched the operands. */
252b5132
RH
1220 char *where = frag_more (2);
1221
1222 where[0] = 0x0;
1223 where[1] = 0x0;
1224
1225 as_bad (_("Can't find opcode to match operands"));
1226 return;
1227 }
1228
1229 build_bytes (opcode, operand);
1230 }
1231}
1232
1233void
464800ca 1234tc_crawl_symbol_chain (object_headers *headers ATTRIBUTE_UNUSED)
252b5132
RH
1235{
1236 printf (_("call to tc_crawl_symbol_chain \n"));
1237}
1238
7f31df7c
CG
1239/* We have no need to default values of symbols. */
1240
252b5132 1241symbolS *
464800ca 1242md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
252b5132
RH
1243{
1244 return 0;
1245}
1246
1247void
464800ca 1248tc_headers_hook (object_headers *headers ATTRIBUTE_UNUSED)
252b5132
RH
1249{
1250 printf (_("call to tc_headers_hook \n"));
1251}
1252
e0c6ed95
AM
1253/* Various routines to kill one day. */
1254/* Equal to MAX_PRECISION in atof-ieee.c. */
252b5132
RH
1255#define MAX_LITTLENUMS 6
1256
e0c6ed95
AM
1257/* Turn a string in input_line_pointer into a floating point constant
1258 of type TYPE, and store the appropriate bytes in *LITP. The number
1259 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1260 returned, or NULL on OK. */
1261
252b5132 1262char *
464800ca 1263md_atof (int type, char *litP, int *sizeP)
252b5132
RH
1264{
1265 int prec;
1266 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1267 LITTLENUM_TYPE *wordP;
1268 char *t;
252b5132
RH
1269
1270 switch (type)
1271 {
1272 case 'f':
1273 case 'F':
1274 case 's':
1275 case 'S':
1276 prec = 2;
1277 break;
1278
1279 case 'd':
1280 case 'D':
1281 case 'r':
1282 case 'R':
1283 prec = 4;
1284 break;
1285
1286 case 'x':
1287 case 'X':
1288 prec = 6;
1289 break;
1290
1291 case 'p':
1292 case 'P':
1293 prec = 6;
1294 break;
1295
1296 default:
1297 *sizeP = 0;
1298 return _("Bad call to MD_ATOF()");
1299 }
1300 t = atof_ieee (input_line_pointer, type, words);
1301 if (t)
1302 input_line_pointer = t;
1303
1304 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1305 for (wordP = words; prec--;)
1306 {
1307 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1308 litP += sizeof (LITTLENUM_TYPE);
1309 }
1310 return 0;
1311}
1312\f
5a38dc70 1313const char *md_shortopts = "z:";
e0c6ed95 1314
3c25c5f6
NC
1315struct option md_longopts[] =
1316 {
7f31df7c
CG
1317#define OPTION_RELAX (OPTION_MD_BASE)
1318 {"linkrelax", no_argument, NULL, OPTION_RELAX},
3c25c5f6
NC
1319 {NULL, no_argument, NULL, 0}
1320 };
e0c6ed95
AM
1321
1322size_t md_longopts_size = sizeof (md_longopts);
252b5132
RH
1323
1324int
464800ca 1325md_parse_option (int c, char *arg)
252b5132
RH
1326{
1327 switch (c)
1328 {
1329 case 'z':
1330 if (!strcmp (arg, "8001"))
7f31df7c 1331 s_segm (1);
252b5132 1332 else if (!strcmp (arg, "8002"))
7f31df7c 1333 s_segm (0);
252b5132
RH
1334 else
1335 {
1336 as_bad (_("invalid architecture -z%s"), arg);
1337 return 0;
1338 }
7f31df7c
CG
1339 z8k_target_from_cmdline = 1;
1340 break;
1341
1342 case OPTION_RELAX:
1343 linkrelax = 1;
252b5132
RH
1344 break;
1345
1346 default:
1347 return 0;
1348 }
1349
1350 return 1;
1351}
1352
1353void
464800ca 1354md_show_usage (FILE *stream)
252b5132 1355{
e0c6ed95 1356 fprintf (stream, _("\
7f31df7c
CG
1357 Z8K options:\n\
1358 -z8001 generate segmented code\n\
1359 -z8002 generate unsegmented code\n\
1360 -linkrelax create linker relaxable code\n"));
252b5132
RH
1361}
1362\f
252b5132 1363void
464800ca
CG
1364md_convert_frag (object_headers *headers ATTRIBUTE_UNUSED,
1365 segT seg ATTRIBUTE_UNUSED,
1366 fragS *fragP ATTRIBUTE_UNUSED)
252b5132 1367{
7f31df7c 1368 printf (_("call to md_convert_frag\n"));
252b5132
RH
1369 abort ();
1370}
1371
1372valueT
464800ca 1373md_section_align (segT seg, valueT size)
252b5132 1374{
e0c6ed95
AM
1375 return ((size + (1 << section_alignment[(int) seg]) - 1)
1376 & (-1 << section_alignment[(int) seg]));
252b5132
RH
1377}
1378
a72d6b4e
CG
1379/* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1380 has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1381 we will have to generate a reloc entry. */
252b5132 1382void
464800ca 1383md_apply_fix3 (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
252b5132 1384{
94f592af 1385 long val = * (long *) valP;
252b5132
RH
1386 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1387
1388 switch (fixP->fx_r_type)
1389 {
1390 case R_IMM4L:
7f31df7c 1391 buf[0] = (buf[0] & 0xf0) | (val & 0xf);
252b5132
RH
1392 break;
1393
1394 case R_JR:
a72d6b4e
CG
1395 if (fixP->fx_addsy)
1396 {
1397 fixP->fx_no_overflow = 1;
1398 fixP->fx_done = 0;
1399 }
1400 else
1401 {
7f31df7c
CG
1402 if (val & 1)
1403 as_bad (_("cannot branch to odd address"));
1404 val /= 2;
1405 if (val > 127 || val < -128)
a72d6b4e 1406 as_warn (_("relative jump out of range"));
252b5132 1407 *buf++ = val;
7f31df7c 1408 fixP->fx_no_overflow = 1;
a72d6b4e
CG
1409 fixP->fx_done = 1;
1410 }
252b5132
RH
1411 break;
1412
1413 case R_DISP7:
a72d6b4e
CG
1414 if (fixP->fx_addsy)
1415 {
1416 fixP->fx_no_overflow = 1;
1417 fixP->fx_done = 0;
1418 }
1419 else
1420 {
d5bf5799
CG
1421 if (val & 1)
1422 as_bad (_("cannot branch to odd address"));
1423 val /= 2;
a72d6b4e 1424 if (val > 0 || val < -127)
d5bf5799 1425 as_bad (_("relative jump out of range"));
a72d6b4e 1426 *buf = (*buf & 0x80) | (-val & 0x7f);
d5bf5799 1427 fixP->fx_no_overflow = 1;
a72d6b4e
CG
1428 fixP->fx_done = 1;
1429 }
7f31df7c 1430 break;
252b5132 1431
7f31df7c 1432 case R_CALLR:
a72d6b4e
CG
1433 if (fixP->fx_addsy)
1434 {
1435 fixP->fx_no_overflow = 1;
1436 fixP->fx_done = 0;
1437 }
1438 else
1439 {
1440 if (val & 1)
1441 as_bad (_("cannot branch to odd address"));
1442 if (val > 4096 || val < -4095)
d5bf5799 1443 as_bad (_("relative call out of range"));
a72d6b4e 1444 val = -val / 2;
d5bf5799
CG
1445 *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1446 buf++;
1447 *buf++ = val & 0xff;
a72d6b4e
CG
1448 fixP->fx_no_overflow = 1;
1449 fixP->fx_done = 1;
1450 }
252b5132
RH
1451 break;
1452
1453 case R_IMM8:
7f31df7c 1454 *buf++ = val;
252b5132 1455 break;
7f31df7c 1456
252b5132
RH
1457 case R_IMM16:
1458 *buf++ = (val >> 8);
1459 *buf++ = val;
1460 break;
7f31df7c 1461
252b5132
RH
1462 case R_IMM32:
1463 *buf++ = (val >> 24);
1464 *buf++ = (val >> 16);
1465 *buf++ = (val >> 8);
1466 *buf++ = val;
1467 break;
7f31df7c
CG
1468
1469 case R_REL16:
1470 val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1471 if (val > 32767 || val < -32768)
1472 as_bad (_("relative address out of range"));
1473 *buf++ = (val >> 8);
1474 *buf++ = val;
1475 fixP->fx_no_overflow = 1;
1476 break;
1477
252b5132
RH
1478#if 0
1479 case R_DA | R_SEG:
1480 *buf++ = (val >> 16);
1481 *buf++ = 0x00;
1482 *buf++ = (val >> 8);
1483 *buf++ = val;
1484 break;
1485#endif
1486
1487 case 0:
1488 md_number_to_chars (buf, val, fixP->fx_size);
1489 break;
1490
1491 default:
7f31df7c 1492 printf(_("md_apply_fix3: unknown r_type 0x%x\n"), fixP->fx_r_type);
252b5132 1493 abort ();
252b5132 1494 }
94f592af
NC
1495
1496 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1497 fixP->fx_done = 1;
252b5132
RH
1498}
1499
1500int
464800ca
CG
1501md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1502 segT segment_type ATTRIBUTE_UNUSED)
252b5132 1503{
7f31df7c 1504 printf (_("call to md_estimate_size_before_relax\n"));
252b5132
RH
1505 abort ();
1506}
1507
e0c6ed95 1508/* Put number into target byte order. */
252b5132
RH
1509
1510void
464800ca 1511md_number_to_chars (char *ptr, valueT use, int nbytes)
252b5132
RH
1512{
1513 number_to_chars_bigendian (ptr, use, nbytes);
1514}
e0c6ed95 1515
a72d6b4e
CG
1516/* On the Z8000, a PC-relative offset is relative to the address of the
1517 instruction plus its size. */
252b5132 1518long
464800ca 1519md_pcrel_from (fixS *fixP)
252b5132 1520{
a72d6b4e 1521 return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
252b5132
RH
1522}
1523
1524void
464800ca 1525tc_coff_symbol_emit_hook (symbolS *s ATTRIBUTE_UNUSED)
252b5132
RH
1526{
1527}
1528
1529void
464800ca 1530tc_reloc_mangle (fixS *fix_ptr, struct internal_reloc *intr, bfd_vma base)
252b5132
RH
1531{
1532 symbolS *symbol_ptr;
1533
e0c6ed95
AM
1534 if (fix_ptr->fx_addsy
1535 && fix_ptr->fx_subsy)
252b5132
RH
1536 {
1537 symbolS *add = fix_ptr->fx_addsy;
1538 symbolS *sub = fix_ptr->fx_subsy;
e0c6ed95
AM
1539
1540 if (S_GET_SEGMENT (add) != S_GET_SEGMENT (sub))
1541 as_bad (_("Can't subtract symbols in different sections %s %s"),
1542 S_GET_NAME (add), S_GET_NAME (sub));
1543 else
252b5132 1544 {
e0c6ed95
AM
1545 int diff = S_GET_VALUE (add) - S_GET_VALUE (sub);
1546
1547 fix_ptr->fx_addsy = 0;
1548 fix_ptr->fx_subsy = 0;
1549 fix_ptr->fx_offset += diff;
252b5132 1550 }
252b5132
RH
1551 }
1552 symbol_ptr = fix_ptr->fx_addsy;
1553
1554 /* If this relocation is attached to a symbol then it's ok
e0c6ed95 1555 to output it. */
252b5132
RH
1556 if (fix_ptr->fx_r_type == 0)
1557 {
e0c6ed95 1558 /* cons likes to create reloc32's whatever the size of the reloc. */
252b5132
RH
1559 switch (fix_ptr->fx_size)
1560 {
1561 case 2:
1562 intr->r_type = R_IMM16;
1563 break;
1564 case 1:
1565 intr->r_type = R_IMM8;
1566 break;
1567 case 4:
1568 intr->r_type = R_IMM32;
1569 break;
1570 default:
1571 abort ();
1572 }
252b5132
RH
1573 }
1574 else
e0c6ed95 1575 intr->r_type = fix_ptr->fx_r_type;
252b5132
RH
1576
1577 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1578 intr->r_offset = fix_ptr->fx_offset;
1579
1580 if (symbol_ptr)
1581 intr->r_symndx = symbol_ptr->sy_number;
1582 else
1583 intr->r_symndx = -1;
1584}
This page took 0.279475 seconds and 4 git commands to generate.