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