Lots of changes for:
[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 {"zero", s_space, 0},
177 /* Force set to be treated as an instruction. */
178 {"set", NULL, 0},
179 {0}
180 };
181
182 void
183 md_begin ()
184 {
185 const char *retval = NULL;
186 unsigned int i = 0;
187
188 /* initialize hash table */
189
190 op_hash = hash_new ();
191 if (op_hash == NULL)
192 as_fatal ("Could not initialize hash table");
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
204 if (retval != NULL)
205 as_fatal ("Can't hash instruction '%s':%s",
206 m88k_opcodes[i].name, retval);
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 }
214
215 int
216 md_parse_option (argP, cntP, vecP)
217 char **argP;
218 int *cntP;
219 char ***vecP;
220 {
221 return 0;
222 }
223
224 void
225 md_assemble (op)
226 char *op;
227 {
228 char *param, *thisfrag;
229 char c;
230 struct m88k_opcode *format;
231 struct m88k_insn insn;
232
233 assert (op);
234
235 /* skip over instruction to find parameters */
236
237 for (param = op; *param != 0 && !isspace (*param); param++)
238 ;
239 c = *param;
240 *param++ = '\0';
241
242 /* try to find the instruction in the hash table */
243
244 if ((format = (struct m88k_opcode *) hash_find (op_hash, op)) == NULL)
245 {
246 as_bad ("Invalid mnemonic '%s'", op);
247 return;
248 }
249
250 /* try parsing this instruction into insn */
251
252 insn.exp.X_add_symbol = 0;
253 insn.exp.X_op_symbol = 0;
254 insn.exp.X_add_number = 0;
255 insn.exp.X_op = O_illegal;
256 insn.reloc = NO_RELOC;
257
258 while (!calcop (format, param, &insn))
259 {
260 /* if it doesn't parse try the next instruction */
261
262 if (!strcmp (format[0].name, format[1].name))
263 format++;
264 else
265 {
266 as_fatal ("Parameter syntax error");
267 return;
268 }
269 }
270
271 /* grow the current frag and plop in the opcode */
272
273 thisfrag = frag_more (4);
274 md_number_to_chars (thisfrag, insn.opcode, 4);
275
276 /* if this instruction requires labels mark it for later */
277
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 #if 0
952
953 /* This routine is never called. What is it for?
954 Ian Taylor, Cygnus Support 13 Jul 1993 */
955
956 void
957 md_number_to_imm (buf, val, nbytes, fixP, seg_type)
958 unsigned char *buf;
959 unsigned int val;
960 int nbytes;
961 fixS *fixP;
962 int seg_type;
963 {
964 if (seg_type != N_TEXT || fixP->fx_r_type == NO_RELOC)
965 {
966 switch (nbytes)
967 {
968 case 4:
969 *buf++ = val >> 24;
970 *buf++ = val >> 16;
971 case 2:
972 *buf++ = val >> 8;
973 case 1:
974 *buf = val;
975 break;
976
977 default:
978 abort ();
979 }
980 return;
981 }
982
983 switch (fixP->fx_r_type)
984 {
985 case RELOC_IW16:
986 buf[2] = val >> 8;
987 buf[3] = val;
988 break;
989
990 case RELOC_LO16:
991 buf[0] = val >> 8;
992 buf[1] = val;
993 break;
994
995 case RELOC_HI16:
996 buf[0] = val >> 24;
997 buf[1] = val >> 16;
998 break;
999
1000 case RELOC_PC16:
1001 val += 4;
1002 buf[0] = val >> 10;
1003 buf[1] = val >> 2;
1004 break;
1005
1006 case RELOC_PC26:
1007 val += 4;
1008 buf[0] |= (val >> 26) & 0x03;
1009 buf[1] = val >> 18;
1010 buf[2] = val >> 10;
1011 buf[3] = val >> 2;
1012 break;
1013
1014 case RELOC_32:
1015 buf[0] = val >> 24;
1016 buf[1] = val >> 16;
1017 buf[2] = val >> 8;
1018 buf[3] = val;
1019 break;
1020
1021 default:
1022 as_fatal ("Bad relocation type");
1023 break;
1024 }
1025 }
1026
1027 #endif /* 0 */
1028
1029 void
1030 md_number_to_disp (buf, val, nbytes)
1031 char *buf;
1032 int val;
1033 int nbytes;
1034 {
1035 as_fatal ("md_number_to_disp not defined");
1036 md_number_to_chars (buf, val, nbytes);
1037 }
1038
1039 void
1040 md_number_to_field (buf, val, nbytes)
1041 char *buf;
1042 int val;
1043 int nbytes;
1044 {
1045 as_fatal ("md_number_to_field not defined");
1046 md_number_to_chars (buf, val, nbytes);
1047 }
1048
1049 #define MAX_LITTLENUMS 6
1050
1051 /* Turn a string in input_line_pointer into a floating point constant of type
1052 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1053 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1054 */
1055 char *
1056 md_atof (type, litP, sizeP)
1057 char type;
1058 char *litP;
1059 int *sizeP;
1060 {
1061 int prec;
1062 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1063 LITTLENUM_TYPE *wordP;
1064 char *t;
1065 char *atof_ieee ();
1066
1067 switch (type)
1068 {
1069 case 'f':
1070 case 'F':
1071 case 's':
1072 case 'S':
1073 prec = 2;
1074 break;
1075
1076 case 'd':
1077 case 'D':
1078 case 'r':
1079 case 'R':
1080 prec = 4;
1081 break;
1082
1083 case 'x':
1084 case 'X':
1085 prec = 6;
1086 break;
1087
1088 case 'p':
1089 case 'P':
1090 prec = 6;
1091 break;
1092
1093 default:
1094 *sizeP = 0;
1095 return "Bad call to MD_ATOF()";
1096 }
1097 t = atof_ieee (input_line_pointer, type, words);
1098 if (t)
1099 input_line_pointer = t;
1100
1101 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1102 for (wordP = words; prec--;)
1103 {
1104 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1105 litP += sizeof (LITTLENUM_TYPE);
1106 }
1107 return 0;
1108 }
1109
1110 int md_short_jump_size = 4;
1111
1112 void
1113 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1114 char *ptr;
1115 addressT from_addr, to_addr;
1116 fragS *frag;
1117 symbolS *to_symbol;
1118 {
1119 ptr[0] = (char) 0xc0;
1120 ptr[1] = 0x00;
1121 ptr[2] = 0x00;
1122 ptr[3] = 0x00;
1123 fix_new (frag,
1124 ptr - frag->fr_literal,
1125 4,
1126 to_symbol,
1127 (offsetT) 0,
1128 0,
1129 RELOC_PC26); /* Botch: Shouldn't this be RELOC_PC16? */
1130 }
1131
1132 int md_long_jump_size = 4;
1133
1134 void
1135 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1136 char *ptr;
1137 addressT from_addr, to_addr;
1138 fragS *frag;
1139 symbolS *to_symbol;
1140 {
1141 ptr[0] = (char) 0xc0;
1142 ptr[1] = 0x00;
1143 ptr[2] = 0x00;
1144 ptr[3] = 0x00;
1145 fix_new (frag,
1146 ptr - frag->fr_literal,
1147 4,
1148 to_symbol,
1149 (offsetT) 0,
1150 0,
1151 RELOC_PC26);
1152 }
1153
1154 int
1155 md_estimate_size_before_relax (fragP, segment_type)
1156 fragS *fragP;
1157 segT segment_type;
1158 {
1159 as_fatal ("Relaxation should never occur");
1160 return (-1);
1161 }
1162
1163 const relax_typeS md_relax_table[] =
1164 {0};
1165
1166 void
1167 md_end ()
1168 {
1169 }
1170
1171 #if 0
1172
1173 /* As far as I can tell, this routine is never called. What is it
1174 doing here?
1175 Ian Taylor, Cygnus Support 13 Jul 1993 */
1176
1177
1178 /*
1179 * Risc relocations are completely different, so it needs
1180 * this machine dependent routine to emit them.
1181 */
1182 void
1183 emit_relocations (fixP, segment_address_in_file)
1184 fixS *fixP;
1185 relax_addressT segment_address_in_file;
1186 {
1187 struct reloc_info_m88k ri;
1188 symbolS *symbolP;
1189 extern char *next_object_file_charP;
1190
1191 bzero ((char *) &ri, sizeof (ri));
1192 for (; fixP; fixP = fixP->fx_next)
1193 {
1194 if (fixP->fx_r_type >= NO_RELOC)
1195 {
1196 fprintf (stderr, "fixP->fx_r_type = %d\n", fixP->fx_r_type);
1197 abort ();
1198 }
1199
1200 if ((symbolP = fixP->fx_addsy) != NULL)
1201 {
1202 ri.r_address = fixP->fx_frag->fr_address +
1203 fixP->fx_where - segment_address_in_file;
1204 if ((symbolP->sy_type & N_TYPE) == N_UNDF)
1205 {
1206 ri.r_extern = 1;
1207 ri.r_symbolnum = symbolP->sy_number;
1208 }
1209 else
1210 {
1211 ri.r_extern = 0;
1212 ri.r_symbolnum = symbolP->sy_type & N_TYPE;
1213 }
1214 if (symbolP && symbolP->sy_frag)
1215 {
1216 ri.r_addend = symbolP->sy_frag->fr_address;
1217 }
1218 ri.r_type = fixP->fx_r_type;
1219 if (fixP->fx_pcrel)
1220 {
1221 ri.r_addend -= ri.r_address;
1222 }
1223 else
1224 {
1225 ri.r_addend = fixP->fx_addnumber;
1226 }
1227
1228 append (&next_object_file_charP, (char *) &ri, sizeof (ri));
1229 }
1230 }
1231 return;
1232 }
1233
1234 #endif /* 0 */
1235
1236 #if 0
1237
1238 /* This routine can be subsumed by s_lcomm in read.c.
1239 Ian Taylor, Cygnus Support 13 Jul 1993 */
1240
1241
1242 static void
1243 s_bss ()
1244 {
1245 char *name;
1246 char c;
1247 char *p;
1248 int temp, bss_align;
1249 symbolS *symbolP;
1250
1251 name = input_line_pointer;
1252 c = get_symbol_end ();
1253 p = input_line_pointer;
1254 *p = c;
1255 SKIP_WHITESPACE ();
1256 if (*input_line_pointer != ',')
1257 {
1258 as_warn ("Expected comma after name");
1259 ignore_rest_of_line ();
1260 return;
1261 }
1262 input_line_pointer++;
1263 if ((temp = get_absolute_expression ()) < 0)
1264 {
1265 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1266 ignore_rest_of_line ();
1267 return;
1268 }
1269 *p = 0;
1270 symbolP = symbol_find_or_make (name);
1271 *p = c;
1272 if (*input_line_pointer == ',')
1273 {
1274 input_line_pointer++;
1275 bss_align = get_absolute_expression ();
1276 }
1277 else
1278 bss_align = 0;
1279
1280 if (!S_IS_DEFINED(symbolP)
1281 || S_GET_SEGMENT(symbolP) == SEG_BSS)
1282 {
1283 if (! need_pass_2)
1284 {
1285 char *p;
1286 segT current_seg = now_seg;
1287 subsegT current_subseg = now_subseg;
1288
1289 subseg_set (SEG_BSS, 1); /* switch to bss */
1290
1291 if (bss_align)
1292 frag_align (bss_align, 0);
1293
1294 /* detach from old frag */
1295 if (symbolP->sy_type == N_BSS && symbolP->sy_frag != NULL)
1296 symbolP->sy_frag->fr_symbol = NULL;
1297
1298 symbolP->sy_frag = frag_now;
1299 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1300 temp, (char *)0);
1301 *p = 0;
1302 S_SET_SEGMENT (symbolP, SEG_BSS);
1303
1304 subseg_set (current_seg, current_subseg);
1305 }
1306 }
1307 else
1308 {
1309 as_warn ("Ignoring attempt to re-define symbol %s.", name);
1310 }
1311
1312 while (!is_end_of_line[*input_line_pointer])
1313 {
1314 input_line_pointer++;
1315 }
1316
1317 return;
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 */