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