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