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