* v850-opc.c: Close unterminated comment.
[deliverable/binutils-gdb.git] / gas / config / tc-m88k.c
CommitLineData
90d85bc4
RP
1/* m88k.c -- Assembler for the Motorola 88000
2 Contributed by Devon Bowen of Buffalo University
3 and Torbjorn Granlund of the Swedish Institute of Computer Science.
71dd3c40
ILT
4 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 1996
5 Free Software Foundation, Inc.
90d85bc4
RP
6
7This file is part of GAS, the GNU Assembler.
8
9GAS is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 1, or (at your option)
12any later version.
13
14GAS is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with GAS; see the file COPYING. If not, write to
a2a5a4fa 21the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
90d85bc4
RP
22
23#include <ctype.h>
90d85bc4 24#include "as.h"
a75f31ce 25#include "subsegs.h"
9317b3fa 26#include "m88k-opcode.h"
90d85bc4 27
90d85bc4
RP
28struct field_val_assoc
29{
30 char *name;
31 unsigned val;
32};
33
34struct field_val_assoc cr_regs[] =
35{
36 {"PID", 0},
37 {"PSR", 1},
38 {"EPSR", 2},
39 {"SSBR", 3},
40 {"SXIP", 4},
41 {"SNIP", 5},
42 {"SFIP", 6},
43 {"VBR", 7},
44 {"DMT0", 8},
45 {"DMD0", 9},
46 {"DMA0", 10},
47 {"DMT1", 11},
48 {"DMD1", 12},
49 {"DMA1", 13},
50 {"DMT2", 14},
51 {"DMD2", 15},
52 {"DMA2", 16},
53 {"SR0", 17},
54 {"SR1", 18},
55 {"SR2", 19},
56 {"SR3", 20},
57
58 {NULL, 0},
59};
60
61struct field_val_assoc fcr_regs[] =
62{
63 {"FPECR", 0},
64 {"FPHS1", 1},
65 {"FPLS1", 2},
66 {"FPHS2", 3},
67 {"FPLS2", 4},
68 {"FPPT", 5},
69 {"FPRH", 6},
70 {"FPRL", 7},
71 {"FPIT", 8},
72
73 {"FPSR", 62},
74 {"FPCR", 63},
75
76 {NULL, 0},
77};
78
79struct field_val_assoc cmpslot[] =
80{
9317b3fa 81/* Integer Floating point */
355afbcd
KR
82 {"nc", 0},
83 {"cp", 1},
90d85bc4
RP
84 {"eq", 2},
85 {"ne", 3},
86 {"gt", 4},
87 {"le", 5},
88 {"lt", 6},
89 {"ge", 7},
9317b3fa
KR
90 {"hi", 8}, {"ou", 8},
91 {"ls", 9}, {"ib", 9},
92 {"lo", 10}, {"in", 10},
93 {"hs", 11}, {"ob", 11},
94 {"be", 12}, {"ue", 12},
95 {"nb", 13}, {"lg", 13},
96 {"he", 14}, {"ug", 14},
97 {"nh", 15}, {"ule", 15},
98 {"ul", 16},
99 {"uge", 17},
90d85bc4
RP
100
101 {NULL, 0},
102};
103
104struct field_val_assoc cndmsk[] =
105{
106 {"gt0", 1},
107 {"eq0", 2},
108 {"ge0", 3},
109 {"lt0", 12},
110 {"ne0", 13},
111 {"le0", 14},
112
113 {NULL, 0},
114};
115
116struct m88k_insn
117{
118 unsigned long opcode;
119 expressionS exp;
120 enum reloc_type reloc;
121};
122
58f3e8a9
RP
123static char *get_bf PARAMS ((char *param, unsigned *valp));
124static char *get_cmp PARAMS ((char *param, unsigned *valp));
125static char *get_cnd PARAMS ((char *param, unsigned *valp));
126static char *get_cr PARAMS ((char *param, unsigned *regnop));
127static char *get_fcr PARAMS ((char *param, unsigned *regnop));
128static char *get_imm16 PARAMS ((char *param, struct m88k_insn *insn));
129static char *get_o6 PARAMS ((char *param, unsigned *valp));
130static char *get_reg PARAMS ((char *param, unsigned *regnop, int reg_prefix));
131static char *get_vec9 PARAMS ((char *param, unsigned *valp));
132static char *getval PARAMS ((char *param, unsigned int *valp));
133
134static char *get_pcr PARAMS ((char *param, struct m88k_insn *insn,
135 enum reloc_type reloc));
136
137static int calcop PARAMS ((struct m88k_opcode *format,
138 char *param, struct m88k_insn *insn));
139
140
90d85bc4
RP
141extern char *myname;
142static struct hash_control *op_hash = NULL;
143
144/* These bits should be turned off in the first address of every segment */
145int md_seg_align = 7;
146
90d85bc4
RP
147/* These chars start a comment anywhere in a source file (except inside
148 another comment */
587c4264 149const char comment_chars[] = ";";
90d85bc4
RP
150
151/* These chars only start a comment at the beginning of a line. */
587c4264
ILT
152const char line_comment_chars[] = "#";
153
154const char line_separator_chars[] = "";
90d85bc4
RP
155
156/* Chars that can be used to separate mant from exp in floating point nums */
587c4264 157const char EXP_CHARS[] = "eE";
90d85bc4
RP
158
159/* Chars that mean this number is a floating point constant */
160/* as in 0f123.456 */
161/* or 0H1.234E-12 (see exp chars above) */
587c4264 162const char FLT_CHARS[] = "dDfF";
90d85bc4 163
c978e704 164extern void float_cons (), cons (), s_globl (), s_space (),
36d656a6 165 s_set (), s_lcomm ();
90d85bc4
RP
166
167const pseudo_typeS md_pseudo_table[] =
168{
c978e704 169 {"align", s_align_bytes, 4},
90d85bc4
RP
170 {"def", s_set, 0},
171 {"dfloat", float_cons, 'd'},
172 {"ffloat", float_cons, 'f'},
173 {"global", s_globl, 0},
355afbcd 174 {"half", cons, 2},
c978e704 175 {"bss", s_lcomm, 1},
90d85bc4 176 {"string", stringer, 0},
355afbcd 177 {"word", cons, 4},
cf897ce2
ILT
178 /* Force set to be treated as an instruction. */
179 {"set", NULL, 0},
ca046e34 180 {".set", s_set, 0},
90d85bc4
RP
181 {0}
182};
183
184void
185md_begin ()
186{
58f3e8a9 187 const char *retval = NULL;
90d85bc4
RP
188 unsigned int i = 0;
189
190 /* initialize hash table */
191
192 op_hash = hash_new ();
90d85bc4
RP
193
194 /* loop until you see the end of the list */
195
196 while (*m88k_opcodes[i].name)
197 {
198 char *name = m88k_opcodes[i].name;
199
200 /* hash each mnemonic and record its position */
201
202 retval = hash_insert (op_hash, name, &m88k_opcodes[i]);
203
43029a8f 204 if (retval != NULL)
90d85bc4 205 as_fatal ("Can't hash instruction '%s':%s",
355afbcd 206 m88k_opcodes[i].name, retval);
90d85bc4
RP
207
208 /* skip to next unique mnemonic or end of list */
209
210 for (i++; !strcmp (m88k_opcodes[i].name, name); i++)
211 ;
212 }
213}
f3d817d8
DM
214\f
215CONST char *md_shortopts = "";
216struct option md_longopts[] = {
217 {NULL, no_argument, NULL, 0}
218};
219size_t md_longopts_size = sizeof(md_longopts);
90d85bc4 220
332fc09f 221int
f3d817d8
DM
222md_parse_option (c, arg)
223 int c;
224 char *arg;
90d85bc4 225{
332fc09f 226 return 0;
90d85bc4
RP
227}
228
f3d817d8
DM
229void
230md_show_usage (stream)
231 FILE *stream;
232{
233}
234\f
90d85bc4
RP
235void
236md_assemble (op)
237 char *op;
238{
239 char *param, *thisfrag;
c978e704 240 char c;
90d85bc4
RP
241 struct m88k_opcode *format;
242 struct m88k_insn insn;
243
244 assert (op);
245
246 /* skip over instruction to find parameters */
247
248 for (param = op; *param != 0 && !isspace (*param); param++)
249 ;
c978e704
ILT
250 c = *param;
251 *param++ = '\0';
90d85bc4
RP
252
253 /* try to find the instruction in the hash table */
254
255 if ((format = (struct m88k_opcode *) hash_find (op_hash, op)) == NULL)
256 {
8ff6f40e 257 as_bad ("Invalid mnemonic '%s'", op);
90d85bc4
RP
258 return;
259 }
260
261 /* try parsing this instruction into insn */
262
263 insn.exp.X_add_symbol = 0;
5ac34ac3 264 insn.exp.X_op_symbol = 0;
90d85bc4 265 insn.exp.X_add_number = 0;
5ac34ac3 266 insn.exp.X_op = O_illegal;
90d85bc4
RP
267 insn.reloc = NO_RELOC;
268
269 while (!calcop (format, param, &insn))
270 {
271 /* if it doesn't parse try the next instruction */
272
273 if (!strcmp (format[0].name, format[1].name))
274 format++;
275 else
276 {
277 as_fatal ("Parameter syntax error");
278 return;
279 }
280 }
281
282 /* grow the current frag and plop in the opcode */
283
284 thisfrag = frag_more (4);
285 md_number_to_chars (thisfrag, insn.opcode, 4);
286
287 /* if this instruction requires labels mark it for later */
288
289 switch (insn.reloc)
290 {
291 case NO_RELOC:
292 break;
293
294 case RELOC_LO16:
295 case RELOC_HI16:
5ac34ac3
ILT
296 fix_new_exp (frag_now,
297 thisfrag - frag_now->fr_literal + 2,
298 2,
299 &insn.exp,
300 0,
301 insn.reloc);
90d85bc4
RP
302 break;
303
304 case RELOC_IW16:
5ac34ac3
ILT
305 fix_new_exp (frag_now,
306 thisfrag - frag_now->fr_literal,
307 4,
308 &insn.exp,
309 0,
310 insn.reloc);
90d85bc4
RP
311 break;
312
313 case RELOC_PC16:
5ac34ac3
ILT
314 fix_new_exp (frag_now,
315 thisfrag - frag_now->fr_literal + 2,
316 2,
317 &insn.exp,
318 1,
319 insn.reloc);
90d85bc4
RP
320 break;
321
322 case RELOC_PC26:
5ac34ac3
ILT
323 fix_new_exp (frag_now,
324 thisfrag - frag_now->fr_literal,
325 4,
326 &insn.exp,
327 1,
328 insn.reloc);
90d85bc4
RP
329 break;
330
331 default:
332 as_fatal ("Unknown relocation type");
333 break;
334 }
335}
336
58f3e8a9 337static int
90d85bc4
RP
338calcop (format, param, insn)
339 struct m88k_opcode *format;
340 char *param;
341 struct m88k_insn *insn;
342{
343 char *fmt = format->op_spec;
344 int f;
345 unsigned val;
346 unsigned opcode;
9317b3fa 347 int reg_prefix = 'r';
90d85bc4
RP
348
349 insn->opcode = format->opcode;
350 opcode = 0;
351
352 for (;;)
353 {
354 if (param == 0)
355 return 0;
356 f = *fmt++;
357 switch (f)
358 {
359 case 0:
360 insn->opcode |= opcode;
58f3e8a9 361 return (*param == 0 || *param == '\n');
90d85bc4
RP
362
363 default:
364 if (f != *param++)
365 return 0;
366 break;
367
368 case 'd':
9317b3fa
KR
369 param = get_reg (param, &val, reg_prefix);
370 reg_prefix = 'r';
90d85bc4
RP
371 opcode |= val << 21;
372 break;
373
58f3e8a9
RP
374 case 'o':
375 param = get_o6 (param, &val);
376 opcode |= ((val >> 2) << 7);
377 break;
378
9317b3fa
KR
379 case 'x':
380 reg_prefix = 'x';
381 break;
382
90d85bc4 383 case '1':
9317b3fa
KR
384 param = get_reg (param, &val, reg_prefix);
385 reg_prefix = 'r';
90d85bc4
RP
386 opcode |= val << 16;
387 break;
388
389 case '2':
9317b3fa
KR
390 param = get_reg (param, &val, reg_prefix);
391 reg_prefix = 'r';
90d85bc4
RP
392 opcode |= val;
393 break;
394
395 case '3':
9317b3fa 396 param = get_reg (param, &val, 'r');
90d85bc4
RP
397 opcode |= (val << 16) | val;
398 break;
399
400 case 'I':
401 param = get_imm16 (param, insn);
402 break;
403
404 case 'b':
405 param = get_bf (param, &val);
406 opcode |= val;
407 break;
408
409 case 'p':
410 param = get_pcr (param, insn, RELOC_PC16);
411 break;
412
413 case 'P':
414 param = get_pcr (param, insn, RELOC_PC26);
415 break;
416
417 case 'B':
418 param = get_cmp (param, &val);
419 opcode |= val;
420 break;
421
422 case 'M':
423 param = get_cnd (param, &val);
424 opcode |= val;
425 break;
426
427 case 'c':
428 param = get_cr (param, &val);
429 opcode |= val << 5;
430 break;
431
432 case 'f':
433 param = get_fcr (param, &val);
434 opcode |= val << 5;
435 break;
436
437 case 'V':
438 param = get_vec9 (param, &val);
439 opcode |= val;
440 break;
441
442 case '?':
443 /* Having this here repeats the warning somtimes.
444 But can't we stand that? */
445 as_warn ("Use of obsolete instruction");
446 break;
447 }
448 }
449}
450
58f3e8a9 451static char *
90d85bc4
RP
452match_name (param, assoc_tab, valp)
453 char *param;
454 struct field_val_assoc *assoc_tab;
455 unsigned *valp;
456{
457 int i;
458 char *name;
459 int name_len;
460
461 for (i = 0;; i++)
462 {
463 name = assoc_tab[i].name;
464 if (name == NULL)
465 return NULL;
466 name_len = strlen (name);
467 if (!strncmp (param, name, name_len))
468 {
469 *valp = assoc_tab[i].val;
470 return param + name_len;
471 }
472 }
473}
474
58f3e8a9 475static char *
9317b3fa 476get_reg (param, regnop, reg_prefix)
90d85bc4
RP
477 char *param;
478 unsigned *regnop;
9317b3fa 479 int reg_prefix;
90d85bc4
RP
480{
481 unsigned c;
482 unsigned regno;
483
484 c = *param++;
9317b3fa 485 if (c == reg_prefix)
90d85bc4
RP
486 {
487 regno = *param++ - '0';
488 if (regno < 10)
489 {
490 if (regno == 0)
491 {
492 *regnop = 0;
493 return param;
494 }
495 c = *param - '0';
496 if (c < 10)
497 {
498 regno = regno * 10 + c;
499 if (c < 32)
500 {
501 *regnop = regno;
502 return param + 1;
503 }
504 }
505 else
506 {
507 *regnop = regno;
508 return param;
509 }
510 }
511 return NULL;
512 }
513 else if (c == 's' && param[0] == 'p')
514 {
515 *regnop = 31;
516 return param + 1;
517 }
518
519 return 0;
520}
521
58f3e8a9 522static char *
90d85bc4
RP
523get_imm16 (param, insn)
524 char *param;
525 struct m88k_insn *insn;
526{
527 enum reloc_type reloc = NO_RELOC;
528 unsigned int val;
90d85bc4
RP
529 char *save_ptr;
530
531 if (!strncmp (param, "hi16", 4) && !isalnum (param[4]))
532 {
533 reloc = RELOC_HI16;
534 param += 4;
535 }
536 else if (!strncmp (param, "lo16", 4) && !isalnum (param[4]))
537 {
538 reloc = RELOC_LO16;
539 param += 4;
540 }
541 else if (!strncmp (param, "iw16", 4) && !isalnum (param[4]))
542 {
543 reloc = RELOC_IW16;
544 param += 4;
545 }
546
547 save_ptr = input_line_pointer;
548 input_line_pointer = param;
5ac34ac3 549 expression (&insn->exp);
90d85bc4
RP
550 param = input_line_pointer;
551 input_line_pointer = save_ptr;
552
553 val = insn->exp.X_add_number;
554
5ac34ac3 555 if (insn->exp.X_op == O_constant)
90d85bc4
RP
556 {
557 /* Insert the value now, and reset reloc to NO_RELOC. */
558 if (reloc == NO_RELOC)
559 {
560 /* Warn about too big expressions if not surrounded by xx16. */
561 if (val > 0xffff)
562 as_warn ("Expression truncated to 16 bits");
563 }
564
565 if (reloc == RELOC_HI16)
566 val >>= 16;
567
568 insn->opcode |= val & 0xffff;
569 reloc = NO_RELOC;
570 }
571 else if (reloc == NO_RELOC)
572 /* We accept a symbol even without lo16, hi16, etc, and assume
573 lo16 was intended. */
574 reloc = RELOC_LO16;
575
576 insn->reloc = reloc;
577
578 return param;
579}
580
58f3e8a9 581static char *
90d85bc4
RP
582get_pcr (param, insn, reloc)
583 char *param;
584 struct m88k_insn *insn;
585 enum reloc_type reloc;
586{
587 char *saveptr, *saveparam;
90d85bc4
RP
588
589 saveptr = input_line_pointer;
590 input_line_pointer = param;
591
5ac34ac3 592 expression (&insn->exp);
90d85bc4
RP
593
594 saveparam = input_line_pointer;
595 input_line_pointer = saveptr;
596
5ac34ac3 597 /* Botch: We should relocate now if O_constant. */
90d85bc4
RP
598 insn->reloc = reloc;
599
600 return saveparam;
601}
602
58f3e8a9 603static char *
90d85bc4
RP
604get_cmp (param, valp)
605 char *param;
606 unsigned *valp;
607{
608 unsigned int val;
609 char *save_ptr;
610
611 save_ptr = param;
612
613 param = match_name (param, cmpslot, valp);
614 val = *valp;
615
616 if (param == NULL)
617 {
618 param = save_ptr;
619
620 save_ptr = input_line_pointer;
621 input_line_pointer = param;
622 val = get_absolute_expression ();
623 param = input_line_pointer;
624 input_line_pointer = save_ptr;
625
626 if (val >= 32)
627 {
628 as_warn ("Expression truncated to 5 bits");
629 val %= 32;
630 }
631 }
632
633 *valp = val << 21;
634 return param;
635}
636
58f3e8a9 637static char *
90d85bc4
RP
638get_cnd (param, valp)
639 char *param;
640 unsigned *valp;
641{
642 unsigned int val;
643
644 if (isdigit (*param))
645 {
646 param = getval (param, &val);
647
648 if (val >= 32)
649 {
650 as_warn ("Expression truncated to 5 bits");
651 val %= 32;
652 }
653 }
654 else
655 {
656 if (isupper (*param))
657 *param = tolower (*param);
658
659 if (isupper (param[1]))
660 param[1] = tolower (param[1]);
661
662 param = match_name (param, cndmsk, valp);
663
664 if (param == NULL)
665 return NULL;
666
667 val = *valp;
668 }
669
670 *valp = val << 21;
671 return param;
672}
673
58f3e8a9 674static char *
90d85bc4
RP
675get_bf2 (param, bc)
676 char *param;
677 int bc;
678{
679 int depth = 0;
680 int c;
681
682 for (;;)
683 {
684 c = *param;
685 if (c == 0)
686 return param;
687 else if (c == '(')
688 depth++;
689 else if (c == ')')
690 depth--;
691 else if (c == bc && depth <= 0)
692 return param;
693 param++;
694 }
695}
696
58f3e8a9 697static char *
90d85bc4
RP
698get_bf_offset_expression (param, offsetp)
699 char *param;
700 unsigned *offsetp;
701{
702 unsigned offset;
703
704 if (isalpha (param[0]))
705 {
706 if (isupper (param[0]))
707 param[0] = tolower (param[0]);
708 if (isupper (param[1]))
709 param[1] = tolower (param[1]);
710
711 param = match_name (param, cmpslot, offsetp);
712
713 return param;
714 }
715 else
716 {
717 input_line_pointer = param;
718 offset = get_absolute_expression ();
719 param = input_line_pointer;
720 }
721
722 *offsetp = offset;
723 return param;
724}
725
58f3e8a9 726static char *
90d85bc4
RP
727get_bf (param, valp)
728 char *param;
729 unsigned *valp;
730{
731 unsigned offset = 0;
732 unsigned width = 0;
733 char *xp;
734 char *save_ptr;
735
736 xp = get_bf2 (param, '<');
737
738 save_ptr = input_line_pointer;
739 input_line_pointer = param;
740 if (*xp == 0)
741 {
742 /* We did not find '<'. We have an offset (width implicitly 32). */
743 param = get_bf_offset_expression (param, &offset);
9317b3fa 744 input_line_pointer = save_ptr;
90d85bc4
RP
745 if (param == NULL)
746 return NULL;
90d85bc4
RP
747 }
748 else
749 {
750 *xp++ = 0; /* Overwrite the '<' */
751 param = get_bf2 (xp, '>');
752 if (*param == 0)
753 return NULL;
754 *param++ = 0; /* Overwrite the '>' */
755
756 width = get_absolute_expression ();
355afbcd 757 xp = get_bf_offset_expression (xp, &offset);
90d85bc4
RP
758 input_line_pointer = save_ptr;
759
760 if (xp + 1 != param)
761 return NULL;
762 }
763
764 *valp = ((width % 32) << 5) | (offset % 32);
765
766 return param;
767}
768
58f3e8a9 769static char *
90d85bc4
RP
770get_cr (param, regnop)
771 char *param;
772 unsigned *regnop;
773{
774 unsigned regno;
775 unsigned c;
90d85bc4
RP
776
777 if (!strncmp (param, "cr", 2))
778 {
779 param += 2;
780
781 regno = *param++ - '0';
782 if (regno < 10)
783 {
784 if (regno == 0)
785 {
786 *regnop = 0;
787 return param;
788 }
789 c = *param - '0';
790 if (c < 10)
791 {
792 regno = regno * 10 + c;
793 if (c < 64)
794 {
795 *regnop = regno;
796 return param + 1;
797 }
798 }
799 else
800 {
801 *regnop = regno;
802 return param;
803 }
804 }
805 return NULL;
806 }
807
808 param = match_name (param, cr_regs, regnop);
809
810 return param;
811}
812
58f3e8a9 813static char *
90d85bc4
RP
814get_fcr (param, regnop)
815 char *param;
816 unsigned *regnop;
817{
818 unsigned regno;
819 unsigned c;
90d85bc4
RP
820
821 if (!strncmp (param, "fcr", 3))
822 {
823 param += 3;
824
825 regno = *param++ - '0';
826 if (regno < 10)
827 {
828 if (regno == 0)
829 {
830 *regnop = 0;
831 return param;
832 }
833 c = *param - '0';
834 if (c < 10)
835 {
836 regno = regno * 10 + c;
837 if (c < 64)
838 {
839 *regnop = regno;
840 return param + 1;
841 }
842 }
843 else
844 {
845 *regnop = regno;
846 return param;
847 }
848 }
849 return NULL;
850 }
851
852 param = match_name (param, fcr_regs, regnop);
853
854 return param;
855}
856
58f3e8a9 857static char *
90d85bc4
RP
858get_vec9 (param, valp)
859 char *param;
860 unsigned *valp;
861{
862 unsigned val;
863 char *save_ptr;
864
865 save_ptr = input_line_pointer;
866 input_line_pointer = param;
867 val = get_absolute_expression ();
868 param = input_line_pointer;
869 input_line_pointer = save_ptr;
870
871 if (val >= 1 << 9)
872 as_warn ("Expression truncated to 9 bits");
873
874 *valp = val % (1 << 9);
875
876 return param;
877}
355afbcd 878
58f3e8a9
RP
879static char *
880get_o6 (param, valp)
881 char *param;
882 unsigned *valp;
883{
884 unsigned val;
885 char *save_ptr;
886
887 save_ptr = input_line_pointer;
888 input_line_pointer = param;
889 val = get_absolute_expression ();
890 param = input_line_pointer;
891 input_line_pointer = save_ptr;
892
893 if (val & 0x3)
894 as_warn ("Removed lower 2 bits of expression");
895
896 *valp = val;
897
898 return(param);
899}
900
90d85bc4
RP
901#define hexval(z) \
902 (isdigit (z) ? (z) - '0' : \
903 islower (z) ? (z) - 'a' + 10 : \
904 isupper (z) ? (z) - 'A' + 10 : -1)
905
58f3e8a9 906static char *
90d85bc4
RP
907getval (param, valp)
908 char *param;
909 unsigned int *valp;
910{
911 unsigned int val = 0;
912 unsigned int c;
913
914 c = *param++;
915 if (c == '0')
916 {
917 c = *param++;
918 if (c == 'x' || c == 'X')
919 {
920 c = *param++;
921 c = hexval (c);
922 while (c < 16)
923 {
924 val = val * 16 + c;
925 c = *param++;
926 c = hexval (c);
927 }
928 }
929 else
930 {
931 c -= '0';
932 while (c < 8)
933 {
934 val = val * 8 + c;
935 c = *param++ - '0';
936 }
937 }
938 }
939 else
940 {
941 c -= '0';
942 while (c < 10)
943 {
944 val = val * 10 + c;
945 c = *param++ - '0';
946 }
947 }
948
949 *valp = val;
950 return param - 1;
951}
952
953void
954md_number_to_chars (buf, val, nbytes)
355afbcd 955 char *buf;
332fc09f 956 valueT val;
355afbcd 957 int nbytes;
90d85bc4 958{
bfbfba45 959 number_to_chars_bigendian (buf, val, nbytes);
90d85bc4
RP
960}
961
c978e704
ILT
962#if 0
963
964/* This routine is never called. What is it for?
965 Ian Taylor, Cygnus Support 13 Jul 1993 */
966
90d85bc4
RP
967void
968md_number_to_imm (buf, val, nbytes, fixP, seg_type)
355afbcd
KR
969 unsigned char *buf;
970 unsigned int val;
971 int nbytes;
972 fixS *fixP;
973 int seg_type;
90d85bc4
RP
974{
975 if (seg_type != N_TEXT || fixP->fx_r_type == NO_RELOC)
976 {
977 switch (nbytes)
978 {
979 case 4:
980 *buf++ = val >> 24;
981 *buf++ = val >> 16;
982 case 2:
983 *buf++ = val >> 8;
984 case 1:
985 *buf = val;
986 break;
987
988 default:
989 abort ();
990 }
991 return;
992 }
993
994 switch (fixP->fx_r_type)
995 {
996 case RELOC_IW16:
997 buf[2] = val >> 8;
998 buf[3] = val;
999 break;
1000
1001 case RELOC_LO16:
1002 buf[0] = val >> 8;
1003 buf[1] = val;
1004 break;
1005
1006 case RELOC_HI16:
1007 buf[0] = val >> 24;
1008 buf[1] = val >> 16;
1009 break;
1010
1011 case RELOC_PC16:
1012 val += 4;
1013 buf[0] = val >> 10;
1014 buf[1] = val >> 2;
1015 break;
1016
1017 case RELOC_PC26:
1018 val += 4;
1019 buf[0] |= (val >> 26) & 0x03;
1020 buf[1] = val >> 18;
1021 buf[2] = val >> 10;
1022 buf[3] = val >> 2;
1023 break;
1024
1025 case RELOC_32:
1026 buf[0] = val >> 24;
1027 buf[1] = val >> 16;
1028 buf[2] = val >> 8;
1029 buf[3] = val;
1030 break;
1031
1032 default:
1033 as_fatal ("Bad relocation type");
1034 break;
1035 }
1036}
1037
c978e704
ILT
1038#endif /* 0 */
1039
90d85bc4
RP
1040void
1041md_number_to_disp (buf, val, nbytes)
355afbcd
KR
1042 char *buf;
1043 int val;
1044 int nbytes;
90d85bc4
RP
1045{
1046 as_fatal ("md_number_to_disp not defined");
1047 md_number_to_chars (buf, val, nbytes);
1048}
1049
1050void
1051md_number_to_field (buf, val, nbytes)
355afbcd
KR
1052 char *buf;
1053 int val;
1054 int nbytes;
90d85bc4
RP
1055{
1056 as_fatal ("md_number_to_field not defined");
1057 md_number_to_chars (buf, val, nbytes);
1058}
1059
1060#define MAX_LITTLENUMS 6
1061
1062/* Turn a string in input_line_pointer into a floating point constant of type
1063 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1064 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1065 */
1066char *
1067md_atof (type, litP, sizeP)
1068 char type;
1069 char *litP;
1070 int *sizeP;
1071{
355afbcd 1072 int prec;
90d85bc4
RP
1073 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1074 LITTLENUM_TYPE *wordP;
355afbcd
KR
1075 char *t;
1076 char *atof_ieee ();
90d85bc4
RP
1077
1078 switch (type)
1079 {
1080 case 'f':
1081 case 'F':
1082 case 's':
1083 case 'S':
1084 prec = 2;
1085 break;
1086
1087 case 'd':
1088 case 'D':
1089 case 'r':
1090 case 'R':
1091 prec = 4;
1092 break;
1093
1094 case 'x':
1095 case 'X':
1096 prec = 6;
1097 break;
1098
1099 case 'p':
1100 case 'P':
1101 prec = 6;
1102 break;
1103
1104 default:
355afbcd 1105 *sizeP = 0;
90d85bc4
RP
1106 return "Bad call to MD_ATOF()";
1107 }
355afbcd 1108 t = atof_ieee (input_line_pointer, type, words);
90d85bc4 1109 if (t)
355afbcd 1110 input_line_pointer = t;
90d85bc4 1111
355afbcd
KR
1112 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1113 for (wordP = words; prec--;)
90d85bc4
RP
1114 {
1115 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
355afbcd 1116 litP += sizeof (LITTLENUM_TYPE);
90d85bc4 1117 }
99024047 1118 return 0;
90d85bc4
RP
1119}
1120
1121int md_short_jump_size = 4;
1122
1123void
1124md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1125 char *ptr;
332fc09f 1126 addressT from_addr, to_addr;
90d85bc4
RP
1127 fragS *frag;
1128 symbolS *to_symbol;
1129{
332fc09f 1130 ptr[0] = (char) 0xc0;
355afbcd
KR
1131 ptr[1] = 0x00;
1132 ptr[2] = 0x00;
1133 ptr[3] = 0x00;
90d85bc4
RP
1134 fix_new (frag,
1135 ptr - frag->fr_literal,
1136 4,
1137 to_symbol,
5ac34ac3 1138 (offsetT) 0,
90d85bc4
RP
1139 0,
1140 RELOC_PC26); /* Botch: Shouldn't this be RELOC_PC16? */
1141}
1142
1143int md_long_jump_size = 4;
1144
1145void
1146md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1147 char *ptr;
332fc09f 1148 addressT from_addr, to_addr;
90d85bc4
RP
1149 fragS *frag;
1150 symbolS *to_symbol;
1151{
332fc09f 1152 ptr[0] = (char) 0xc0;
355afbcd
KR
1153 ptr[1] = 0x00;
1154 ptr[2] = 0x00;
1155 ptr[3] = 0x00;
90d85bc4
RP
1156 fix_new (frag,
1157 ptr - frag->fr_literal,
1158 4,
1159 to_symbol,
5ac34ac3 1160 (offsetT) 0,
90d85bc4
RP
1161 0,
1162 RELOC_PC26);
1163}
1164
1165int
1166md_estimate_size_before_relax (fragP, segment_type)
1167 fragS *fragP;
332fc09f 1168 segT segment_type;
90d85bc4
RP
1169{
1170 as_fatal ("Relaxation should never occur");
58f3e8a9 1171 return (-1);
90d85bc4
RP
1172}
1173
c978e704
ILT
1174#if 0
1175
1176/* As far as I can tell, this routine is never called. What is it
1177 doing here?
1178 Ian Taylor, Cygnus Support 13 Jul 1993 */
1179
1180
90d85bc4
RP
1181/*
1182 * Risc relocations are completely different, so it needs
1183 * this machine dependent routine to emit them.
1184 */
1185void
1186emit_relocations (fixP, segment_address_in_file)
355afbcd
KR
1187 fixS *fixP;
1188 relax_addressT segment_address_in_file;
90d85bc4 1189{
355afbcd
KR
1190 struct reloc_info_m88k ri;
1191 symbolS *symbolP;
1192 extern char *next_object_file_charP;
90d85bc4 1193
355afbcd
KR
1194 bzero ((char *) &ri, sizeof (ri));
1195 for (; fixP; fixP = fixP->fx_next)
1196 {
355afbcd
KR
1197 if (fixP->fx_r_type >= NO_RELOC)
1198 {
1199 fprintf (stderr, "fixP->fx_r_type = %d\n", fixP->fx_r_type);
1200 abort ();
90d85bc4
RP
1201 }
1202
355afbcd
KR
1203 if ((symbolP = fixP->fx_addsy) != NULL)
1204 {
1205 ri.r_address = fixP->fx_frag->fr_address +
1206 fixP->fx_where - segment_address_in_file;
1207 if ((symbolP->sy_type & N_TYPE) == N_UNDF)
1208 {
1209 ri.r_extern = 1;
1210 ri.r_symbolnum = symbolP->sy_number;
1211 }
1212 else
1213 {
1214 ri.r_extern = 0;
1215 ri.r_symbolnum = symbolP->sy_type & N_TYPE;
1216 }
1217 if (symbolP && symbolP->sy_frag)
1218 {
1219 ri.r_addend = symbolP->sy_frag->fr_address;
90d85bc4 1220 }
355afbcd
KR
1221 ri.r_type = fixP->fx_r_type;
1222 if (fixP->fx_pcrel)
1223 {
355afbcd 1224 ri.r_addend -= ri.r_address;
90d85bc4 1225 }
355afbcd
KR
1226 else
1227 {
1228 ri.r_addend = fixP->fx_addnumber;
90d85bc4
RP
1229 }
1230
355afbcd 1231 append (&next_object_file_charP, (char *) &ri, sizeof (ri));
90d85bc4
RP
1232 }
1233 }
90d85bc4
RP
1234}
1235
c978e704
ILT
1236#endif /* 0 */
1237
1238#if 0
1239
1240/* This routine can be subsumed by s_lcomm in read.c.
1241 Ian Taylor, Cygnus Support 13 Jul 1993 */
1242
1243
90d85bc4 1244static void
355afbcd 1245s_bss ()
90d85bc4
RP
1246{
1247 char *name;
1248 char c;
1249 char *p;
9a75dc1f 1250 int temp, bss_align;
90d85bc4 1251 symbolS *symbolP;
90d85bc4
RP
1252
1253 name = input_line_pointer;
355afbcd 1254 c = get_symbol_end ();
90d85bc4
RP
1255 p = input_line_pointer;
1256 *p = c;
355afbcd
KR
1257 SKIP_WHITESPACE ();
1258 if (*input_line_pointer != ',')
90d85bc4 1259 {
355afbcd
KR
1260 as_warn ("Expected comma after name");
1261 ignore_rest_of_line ();
90d85bc4
RP
1262 return;
1263 }
355afbcd
KR
1264 input_line_pointer++;
1265 if ((temp = get_absolute_expression ()) < 0)
90d85bc4 1266 {
355afbcd
KR
1267 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1268 ignore_rest_of_line ();
90d85bc4
RP
1269 return;
1270 }
1271 *p = 0;
355afbcd 1272 symbolP = symbol_find_or_make (name);
90d85bc4
RP
1273 *p = c;
1274 if (*input_line_pointer == ',')
1275 {
1276 input_line_pointer++;
355afbcd 1277 bss_align = get_absolute_expression ();
90d85bc4 1278 }
9a75dc1f
ILT
1279 else
1280 bss_align = 0;
90d85bc4 1281
9a75dc1f
ILT
1282 if (!S_IS_DEFINED(symbolP)
1283 || S_GET_SEGMENT(symbolP) == SEG_BSS)
90d85bc4 1284 {
9a75dc1f
ILT
1285 if (! need_pass_2)
1286 {
1287 char *p;
1288 segT current_seg = now_seg;
1289 subsegT current_subseg = now_subseg;
1290
604633ae 1291 subseg_set (SEG_BSS, 1); /* switch to bss */
9a75dc1f
ILT
1292
1293 if (bss_align)
1294 frag_align (bss_align, 0);
1295
1296 /* detach from old frag */
1297 if (symbolP->sy_type == N_BSS && symbolP->sy_frag != NULL)
1298 symbolP->sy_frag->fr_symbol = NULL;
1299
1300 symbolP->sy_frag = frag_now;
1301 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1302 temp, (char *)0);
1303 *p = 0;
1304 S_SET_SEGMENT (symbolP, SEG_BSS);
1305
604633ae 1306 subseg_set (current_seg, current_subseg);
9a75dc1f 1307 }
90d85bc4
RP
1308 }
1309 else
1310 {
9a75dc1f 1311 as_warn ("Ignoring attempt to re-define symbol %s.", name);
90d85bc4 1312 }
9a75dc1f 1313
90d85bc4
RP
1314 while (!is_end_of_line[*input_line_pointer])
1315 {
1316 input_line_pointer++;
1317 }
90d85bc4 1318}
c978e704
ILT
1319
1320#endif /* 0 */
1321
1322#ifdef M88KCOFF
1323
1324/* These functions are needed if we are linking with obj-coffbfd.c.
1325 That file may be replaced by a more BFD oriented version at some
1326 point. If that happens, these functions should be rexamined.
1327
1328 Ian Lance Taylor, Cygnus Support, 13 July 1993. */
1329
1330/* Given a fixS structure (created by a call to fix_new, above),
1331 return the BFD relocation type to use for it. */
1332
1333short
1334tc_coff_fix2rtype (fixp)
1335 fixS *fixp;
1336{
1337 switch (fixp->fx_r_type)
1338 {
1339 case RELOC_LO16:
1340 return R_LVRT16;
1341 case RELOC_HI16:
1342 return R_HVRT16;
1343 case RELOC_PC16:
1344 return R_PCR16L;
1345 case RELOC_PC26:
1346 return R_PCR26L;
1347 case RELOC_32:
1348 return R_VRT32;
1349 case RELOC_IW16:
1350 return R_VRT16;
1351 default:
1352 abort ();
1353 }
1354}
1355
1356/* Apply a fixS to the object file. Since COFF does not use addends
1357 in relocs, the addend is actually stored directly in the object
1358 file itself. */
1359
1360void
1361md_apply_fix (fixp, val)
1362 fixS *fixp;
1363 long val;
1364{
1365 char *buf;
1366
1367 buf = fixp->fx_frag->fr_literal + fixp->fx_where;
8ff6f40e 1368 fixp->fx_offset = 0;
c978e704
ILT
1369
1370 switch (fixp->fx_r_type)
1371 {
1372 case RELOC_IW16:
8ff6f40e 1373 fixp->fx_offset = val >> 16;
c978e704
ILT
1374 buf[2] = val >> 8;
1375 buf[3] = val;
1376 break;
1377
1378 case RELOC_LO16:
8ff6f40e 1379 fixp->fx_offset = val >> 16;
c978e704
ILT
1380 buf[0] = val >> 8;
1381 buf[1] = val;
1382 break;
1383
1384 case RELOC_HI16:
8ff6f40e
ILT
1385 fixp->fx_offset = val >> 16;
1386 buf[0] = val >> 8;
1387 buf[1] = val;
c978e704
ILT
1388 break;
1389
1390 case RELOC_PC16:
1391 buf[0] = val >> 10;
1392 buf[1] = val >> 2;
1393 break;
1394
1395 case RELOC_PC26:
1396 buf[0] |= (val >> 26) & 0x03;
1397 buf[1] = val >> 18;
1398 buf[2] = val >> 10;
1399 buf[3] = val >> 2;
1400 break;
1401
1402 case RELOC_32:
1403 buf[0] = val >> 24;
1404 buf[1] = val >> 16;
1405 buf[2] = val >> 8;
1406 buf[3] = val;
1407 break;
1408
1409 default:
1410 abort ();
1411 }
1412}
1413
1414/* Where a PC relative offset is calculated from. On the m88k they
1415 are calculated from just after the instruction. */
1416
1417long
1418md_pcrel_from (fixp)
1419 fixS *fixp;
1420{
2368ec63
ILT
1421 switch (fixp->fx_r_type)
1422 {
1423 case RELOC_PC16:
1424 return fixp->fx_frag->fr_address + fixp->fx_where - 2;
1425 case RELOC_PC26:
1426 return fixp->fx_frag->fr_address + fixp->fx_where;
1427 default:
1428 abort ();
1429 }
1430 /*NOTREACHED*/
c978e704
ILT
1431}
1432
a75f31ce
ILT
1433/* When we align the .init section, insert the correct NOP pattern. */
1434
1435int
71dd3c40 1436m88k_do_align (n, fill, len)
a75f31ce
ILT
1437 int n;
1438 const char *fill;
71dd3c40 1439 int len;
a75f31ce 1440{
71dd3c40 1441 if ((fill == NULL || (*fill == 0 && len == 1))
a75f31ce
ILT
1442 && strcmp (obj_segment_name (now_seg), ".init") == 0)
1443 {
1444 static const unsigned char nop_pattern[] = { 0xf4, 0x00, 0x58, 0x00 };
1445 frag_align_pattern (n, nop_pattern, sizeof (nop_pattern));
1446 return 1;
1447 }
1448 return 0;
1449}
1450
c978e704 1451#endif /* M88KCOFF */
This page took 0.229347 seconds and 4 git commands to generate.