]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/config/tc-m88k.c
* config/tc-m88k.c (omagic): Removed unused variable.
[thirdparty/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 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_subtract_symbol = 0;
278 insn.exp.X_add_number = 0;
279 insn.exp.X_seg = 0;
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 (frag_now,
310 thisfrag - frag_now->fr_literal + 2,
311 2,
312 insn.exp.X_add_symbol,
313 insn.exp.X_subtract_symbol,
314 insn.exp.X_add_number,
315 0,
316 insn.reloc);
317 break;
318
319 case RELOC_IW16:
320 fix_new (frag_now,
321 thisfrag - frag_now->fr_literal,
322 4,
323 insn.exp.X_add_symbol,
324 insn.exp.X_subtract_symbol,
325 insn.exp.X_add_number,
326 0,
327 insn.reloc);
328 break;
329
330 case RELOC_PC16:
331 fix_new (frag_now,
332 thisfrag - frag_now->fr_literal + 2,
333 2,
334 insn.exp.X_add_symbol,
335 insn.exp.X_subtract_symbol,
336 insn.exp.X_add_number,
337 1,
338 insn.reloc);
339 break;
340
341 case RELOC_PC26:
342 fix_new (frag_now,
343 thisfrag - frag_now->fr_literal,
344 4,
345 insn.exp.X_add_symbol,
346 insn.exp.X_subtract_symbol,
347 insn.exp.X_add_number,
348 1,
349 insn.reloc);
350 break;
351
352 default:
353 as_fatal ("Unknown relocation type");
354 break;
355 }
356 }
357
358 int
359 calcop (format, param, insn)
360 struct m88k_opcode *format;
361 char *param;
362 struct m88k_insn *insn;
363 {
364 char *fmt = format->op_spec;
365 int f;
366 unsigned val;
367 unsigned opcode;
368 int reg_prefix = 'r';
369
370 insn->opcode = format->opcode;
371 opcode = 0;
372
373 for (;;)
374 {
375 if (param == 0)
376 return 0;
377 f = *fmt++;
378 switch (f)
379 {
380 case 0:
381 insn->opcode |= opcode;
382 return *param == 0;
383
384 default:
385 if (f != *param++)
386 return 0;
387 break;
388
389 case 'd':
390 param = get_reg (param, &val, reg_prefix);
391 reg_prefix = 'r';
392 opcode |= val << 21;
393 break;
394
395 case 'x':
396 reg_prefix = 'x';
397 break;
398
399 case '1':
400 param = get_reg (param, &val, reg_prefix);
401 reg_prefix = 'r';
402 opcode |= val << 16;
403 break;
404
405 case '2':
406 param = get_reg (param, &val, reg_prefix);
407 reg_prefix = 'r';
408 opcode |= val;
409 break;
410
411 case '3':
412 param = get_reg (param, &val, 'r');
413 opcode |= (val << 16) | val;
414 break;
415
416 case 'I':
417 param = get_imm16 (param, insn);
418 break;
419
420 case 'b':
421 param = get_bf (param, &val);
422 opcode |= val;
423 break;
424
425 case 'p':
426 param = get_pcr (param, insn, RELOC_PC16);
427 break;
428
429 case 'P':
430 param = get_pcr (param, insn, RELOC_PC26);
431 break;
432
433 case 'B':
434 param = get_cmp (param, &val);
435 opcode |= val;
436 break;
437
438 case 'M':
439 param = get_cnd (param, &val);
440 opcode |= val;
441 break;
442
443 case 'c':
444 param = get_cr (param, &val);
445 opcode |= val << 5;
446 break;
447
448 case 'f':
449 param = get_fcr (param, &val);
450 opcode |= val << 5;
451 break;
452
453 case 'V':
454 param = get_vec9 (param, &val);
455 opcode |= val;
456 break;
457
458 case '?':
459 /* Having this here repeats the warning somtimes.
460 But can't we stand that? */
461 as_warn ("Use of obsolete instruction");
462 break;
463 }
464 }
465 }
466
467 char *
468 match_name (param, assoc_tab, valp)
469 char *param;
470 struct field_val_assoc *assoc_tab;
471 unsigned *valp;
472 {
473 int i;
474 char *name;
475 int name_len;
476
477 for (i = 0;; i++)
478 {
479 name = assoc_tab[i].name;
480 if (name == NULL)
481 return NULL;
482 name_len = strlen (name);
483 if (!strncmp (param, name, name_len))
484 {
485 *valp = assoc_tab[i].val;
486 return param + name_len;
487 }
488 }
489 }
490
491 char *
492 get_reg (param, regnop, reg_prefix)
493 char *param;
494 unsigned *regnop;
495 int reg_prefix;
496 {
497 unsigned c;
498 unsigned regno;
499
500 c = *param++;
501 if (c == reg_prefix)
502 {
503 regno = *param++ - '0';
504 if (regno < 10)
505 {
506 if (regno == 0)
507 {
508 *regnop = 0;
509 return param;
510 }
511 c = *param - '0';
512 if (c < 10)
513 {
514 regno = regno * 10 + c;
515 if (c < 32)
516 {
517 *regnop = regno;
518 return param + 1;
519 }
520 }
521 else
522 {
523 *regnop = regno;
524 return param;
525 }
526 }
527 return NULL;
528 }
529 else if (c == 's' && param[0] == 'p')
530 {
531 *regnop = 31;
532 return param + 1;
533 }
534
535 return 0;
536 }
537
538 char *
539 get_imm16 (param, insn)
540 char *param;
541 struct m88k_insn *insn;
542 {
543 enum reloc_type reloc = NO_RELOC;
544 unsigned int val;
545 segT seg;
546 char *save_ptr;
547
548 if (!strncmp (param, "hi16", 4) && !isalnum (param[4]))
549 {
550 reloc = RELOC_HI16;
551 param += 4;
552 }
553 else if (!strncmp (param, "lo16", 4) && !isalnum (param[4]))
554 {
555 reloc = RELOC_LO16;
556 param += 4;
557 }
558 else if (!strncmp (param, "iw16", 4) && !isalnum (param[4]))
559 {
560 reloc = RELOC_IW16;
561 param += 4;
562 }
563
564 save_ptr = input_line_pointer;
565 input_line_pointer = param;
566 seg = expression (&insn->exp);
567 param = input_line_pointer;
568 input_line_pointer = save_ptr;
569
570 val = insn->exp.X_add_number;
571
572 if (seg == SEG_ABSOLUTE)
573 {
574 /* Insert the value now, and reset reloc to NO_RELOC. */
575 if (reloc == NO_RELOC)
576 {
577 /* Warn about too big expressions if not surrounded by xx16. */
578 if (val > 0xffff)
579 as_warn ("Expression truncated to 16 bits");
580 }
581
582 if (reloc == RELOC_HI16)
583 val >>= 16;
584
585 insn->opcode |= val & 0xffff;
586 reloc = NO_RELOC;
587 }
588 else if (reloc == NO_RELOC)
589 /* We accept a symbol even without lo16, hi16, etc, and assume
590 lo16 was intended. */
591 reloc = RELOC_LO16;
592
593 insn->reloc = reloc;
594
595 return param;
596 }
597
598 char *
599 get_pcr (param, insn, reloc)
600 char *param;
601 struct m88k_insn *insn;
602 enum reloc_type reloc;
603 {
604 char *saveptr, *saveparam;
605 segT seg;
606
607 saveptr = input_line_pointer;
608 input_line_pointer = param;
609
610 seg = expression (&insn->exp);
611
612 saveparam = input_line_pointer;
613 input_line_pointer = saveptr;
614
615 /* Botch: We should relocate now if SEG_ABSOLUTE. */
616 insn->reloc = reloc;
617
618 return saveparam;
619 }
620
621 char *
622 get_cmp (param, valp)
623 char *param;
624 unsigned *valp;
625 {
626 unsigned int val;
627 char *save_ptr;
628
629 save_ptr = param;
630
631 param = match_name (param, cmpslot, valp);
632 val = *valp;
633
634 if (param == NULL)
635 {
636 param = save_ptr;
637
638 save_ptr = input_line_pointer;
639 input_line_pointer = param;
640 val = get_absolute_expression ();
641 param = input_line_pointer;
642 input_line_pointer = save_ptr;
643
644 if (val >= 32)
645 {
646 as_warn ("Expression truncated to 5 bits");
647 val %= 32;
648 }
649 }
650
651 *valp = val << 21;
652 return param;
653 }
654
655 char *
656 get_cnd (param, valp)
657 char *param;
658 unsigned *valp;
659 {
660 unsigned int val;
661
662 if (isdigit (*param))
663 {
664 param = getval (param, &val);
665
666 if (val >= 32)
667 {
668 as_warn ("Expression truncated to 5 bits");
669 val %= 32;
670 }
671 }
672 else
673 {
674 if (isupper (*param))
675 *param = tolower (*param);
676
677 if (isupper (param[1]))
678 param[1] = tolower (param[1]);
679
680 param = match_name (param, cndmsk, valp);
681
682 if (param == NULL)
683 return NULL;
684
685 val = *valp;
686 }
687
688 *valp = val << 21;
689 return param;
690 }
691
692 char *
693 get_bf2 (param, bc)
694 char *param;
695 int bc;
696 {
697 int depth = 0;
698 int c;
699
700 for (;;)
701 {
702 c = *param;
703 if (c == 0)
704 return param;
705 else if (c == '(')
706 depth++;
707 else if (c == ')')
708 depth--;
709 else if (c == bc && depth <= 0)
710 return param;
711 param++;
712 }
713 }
714
715 char *
716 get_bf_offset_expression (param, offsetp)
717 char *param;
718 unsigned *offsetp;
719 {
720 unsigned offset;
721
722 if (isalpha (param[0]))
723 {
724 if (isupper (param[0]))
725 param[0] = tolower (param[0]);
726 if (isupper (param[1]))
727 param[1] = tolower (param[1]);
728
729 param = match_name (param, cmpslot, offsetp);
730
731 return param;
732 }
733 else
734 {
735 input_line_pointer = param;
736 offset = get_absolute_expression ();
737 param = input_line_pointer;
738 }
739
740 *offsetp = offset;
741 return param;
742 }
743
744 char *
745 get_bf (param, valp)
746 char *param;
747 unsigned *valp;
748 {
749 unsigned offset = 0;
750 unsigned width = 0;
751 char *xp;
752 char *save_ptr;
753
754 xp = get_bf2 (param, '<');
755
756 save_ptr = input_line_pointer;
757 input_line_pointer = param;
758 if (*xp == 0)
759 {
760 /* We did not find '<'. We have an offset (width implicitly 32). */
761 param = get_bf_offset_expression (param, &offset);
762 input_line_pointer = save_ptr;
763 if (param == NULL)
764 return NULL;
765 }
766 else
767 {
768 *xp++ = 0; /* Overwrite the '<' */
769 param = get_bf2 (xp, '>');
770 if (*param == 0)
771 return NULL;
772 *param++ = 0; /* Overwrite the '>' */
773
774 width = get_absolute_expression ();
775 xp = get_bf_offset_expression (xp, &offset);
776 input_line_pointer = save_ptr;
777
778 if (xp + 1 != param)
779 return NULL;
780 }
781
782 *valp = ((width % 32) << 5) | (offset % 32);
783
784 return param;
785 }
786
787 char *
788 get_cr (param, regnop)
789 char *param;
790 unsigned *regnop;
791 {
792 unsigned regno;
793 unsigned c;
794 int i;
795 int name_len;
796
797 if (!strncmp (param, "cr", 2))
798 {
799 param += 2;
800
801 regno = *param++ - '0';
802 if (regno < 10)
803 {
804 if (regno == 0)
805 {
806 *regnop = 0;
807 return param;
808 }
809 c = *param - '0';
810 if (c < 10)
811 {
812 regno = regno * 10 + c;
813 if (c < 64)
814 {
815 *regnop = regno;
816 return param + 1;
817 }
818 }
819 else
820 {
821 *regnop = regno;
822 return param;
823 }
824 }
825 return NULL;
826 }
827
828 param = match_name (param, cr_regs, regnop);
829
830 return param;
831 }
832
833 char *
834 get_fcr (param, regnop)
835 char *param;
836 unsigned *regnop;
837 {
838 unsigned regno;
839 unsigned c;
840 int i;
841 int name_len;
842
843 if (!strncmp (param, "fcr", 3))
844 {
845 param += 3;
846
847 regno = *param++ - '0';
848 if (regno < 10)
849 {
850 if (regno == 0)
851 {
852 *regnop = 0;
853 return param;
854 }
855 c = *param - '0';
856 if (c < 10)
857 {
858 regno = regno * 10 + c;
859 if (c < 64)
860 {
861 *regnop = regno;
862 return param + 1;
863 }
864 }
865 else
866 {
867 *regnop = regno;
868 return param;
869 }
870 }
871 return NULL;
872 }
873
874 param = match_name (param, fcr_regs, regnop);
875
876 return param;
877 }
878
879 char *
880 get_vec9 (param, valp)
881 char *param;
882 unsigned *valp;
883 {
884 unsigned val;
885 char *save_ptr;
886
887 save_ptr = input_line_pointer;
888 input_line_pointer = param;
889 val = get_absolute_expression ();
890 param = input_line_pointer;
891 input_line_pointer = save_ptr;
892
893 if (val >= 1 << 9)
894 as_warn ("Expression truncated to 9 bits");
895
896 *valp = val % (1 << 9);
897
898 return param;
899 }
900
901 #define hexval(z) \
902 (isdigit (z) ? (z) - '0' : \
903 islower (z) ? (z) - 'a' + 10 : \
904 isupper (z) ? (z) - 'A' + 10 : -1)
905
906 char *
907 getval (param, valp)
908 char *param;
909 unsigned int *valp;
910 {
911 unsigned int val = 0;
912 unsigned int c;
913
914 c = *param++;
915 if (c == '0')
916 {
917 c = *param++;
918 if (c == 'x' || c == 'X')
919 {
920 c = *param++;
921 c = hexval (c);
922 while (c < 16)
923 {
924 val = val * 16 + c;
925 c = *param++;
926 c = hexval (c);
927 }
928 }
929 else
930 {
931 c -= '0';
932 while (c < 8)
933 {
934 val = val * 8 + c;
935 c = *param++ - '0';
936 }
937 }
938 }
939 else
940 {
941 c -= '0';
942 while (c < 10)
943 {
944 val = val * 10 + c;
945 c = *param++ - '0';
946 }
947 }
948
949 *valp = val;
950 return param - 1;
951 }
952
953 void
954 md_number_to_chars (buf, val, nbytes)
955 char *buf;
956 valueT val;
957 int nbytes;
958 {
959 switch (nbytes)
960 {
961 case 4:
962 *buf++ = val >> 24;
963 *buf++ = val >> 16;
964 case 2:
965 *buf++ = val >> 8;
966 case 1:
967 *buf = val;
968 break;
969
970 default:
971 abort ();
972 }
973 }
974
975 #if 0
976
977 /* This routine is never called. What is it for?
978 Ian Taylor, Cygnus Support 13 Jul 1993 */
979
980 void
981 md_number_to_imm (buf, val, nbytes, fixP, seg_type)
982 unsigned char *buf;
983 unsigned int val;
984 int nbytes;
985 fixS *fixP;
986 int seg_type;
987 {
988 if (seg_type != N_TEXT || fixP->fx_r_type == NO_RELOC)
989 {
990 switch (nbytes)
991 {
992 case 4:
993 *buf++ = val >> 24;
994 *buf++ = val >> 16;
995 case 2:
996 *buf++ = val >> 8;
997 case 1:
998 *buf = val;
999 break;
1000
1001 default:
1002 abort ();
1003 }
1004 return;
1005 }
1006
1007 switch (fixP->fx_r_type)
1008 {
1009 case RELOC_IW16:
1010 buf[2] = val >> 8;
1011 buf[3] = val;
1012 break;
1013
1014 case RELOC_LO16:
1015 buf[0] = val >> 8;
1016 buf[1] = val;
1017 break;
1018
1019 case RELOC_HI16:
1020 buf[0] = val >> 24;
1021 buf[1] = val >> 16;
1022 break;
1023
1024 case RELOC_PC16:
1025 val += 4;
1026 buf[0] = val >> 10;
1027 buf[1] = val >> 2;
1028 break;
1029
1030 case RELOC_PC26:
1031 val += 4;
1032 buf[0] |= (val >> 26) & 0x03;
1033 buf[1] = val >> 18;
1034 buf[2] = val >> 10;
1035 buf[3] = val >> 2;
1036 break;
1037
1038 case RELOC_32:
1039 buf[0] = val >> 24;
1040 buf[1] = val >> 16;
1041 buf[2] = val >> 8;
1042 buf[3] = val;
1043 break;
1044
1045 default:
1046 as_fatal ("Bad relocation type");
1047 break;
1048 }
1049 }
1050
1051 #endif /* 0 */
1052
1053 void
1054 md_number_to_disp (buf, val, nbytes)
1055 char *buf;
1056 int val;
1057 int nbytes;
1058 {
1059 as_fatal ("md_number_to_disp not defined");
1060 md_number_to_chars (buf, val, nbytes);
1061 }
1062
1063 void
1064 md_number_to_field (buf, val, nbytes)
1065 char *buf;
1066 int val;
1067 int nbytes;
1068 {
1069 as_fatal ("md_number_to_field not defined");
1070 md_number_to_chars (buf, val, nbytes);
1071 }
1072
1073 #define MAX_LITTLENUMS 6
1074
1075 /* Turn a string in input_line_pointer into a floating point constant of type
1076 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1077 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1078 */
1079 char *
1080 md_atof (type, litP, sizeP)
1081 char type;
1082 char *litP;
1083 int *sizeP;
1084 {
1085 int prec;
1086 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1087 LITTLENUM_TYPE *wordP;
1088 char *t;
1089 char *atof_ieee ();
1090
1091 switch (type)
1092 {
1093 case 'f':
1094 case 'F':
1095 case 's':
1096 case 'S':
1097 prec = 2;
1098 break;
1099
1100 case 'd':
1101 case 'D':
1102 case 'r':
1103 case 'R':
1104 prec = 4;
1105 break;
1106
1107 case 'x':
1108 case 'X':
1109 prec = 6;
1110 break;
1111
1112 case 'p':
1113 case 'P':
1114 prec = 6;
1115 break;
1116
1117 default:
1118 *sizeP = 0;
1119 return "Bad call to MD_ATOF()";
1120 }
1121 t = atof_ieee (input_line_pointer, type, words);
1122 if (t)
1123 input_line_pointer = t;
1124
1125 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1126 for (wordP = words; prec--;)
1127 {
1128 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1129 litP += sizeof (LITTLENUM_TYPE);
1130 }
1131 return ""; /* Someone should teach Dean about null pointers */
1132 }
1133
1134 int md_short_jump_size = 4;
1135
1136 void
1137 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1138 char *ptr;
1139 addressT from_addr, to_addr;
1140 fragS *frag;
1141 symbolS *to_symbol;
1142 {
1143 ptr[0] = (char) 0xc0;
1144 ptr[1] = 0x00;
1145 ptr[2] = 0x00;
1146 ptr[3] = 0x00;
1147 fix_new (frag,
1148 ptr - frag->fr_literal,
1149 4,
1150 to_symbol,
1151 (symbolS *) 0,
1152 (long int) 0,
1153 0,
1154 RELOC_PC26); /* Botch: Shouldn't this be RELOC_PC16? */
1155 }
1156
1157 int md_long_jump_size = 4;
1158
1159 void
1160 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1161 char *ptr;
1162 addressT from_addr, to_addr;
1163 fragS *frag;
1164 symbolS *to_symbol;
1165 {
1166 ptr[0] = (char) 0xc0;
1167 ptr[1] = 0x00;
1168 ptr[2] = 0x00;
1169 ptr[3] = 0x00;
1170 fix_new (frag,
1171 ptr - frag->fr_literal,
1172 4,
1173 to_symbol,
1174 (symbolS *) 0,
1175 (long int) 0,
1176 0,
1177 RELOC_PC26);
1178 }
1179
1180 int
1181 md_estimate_size_before_relax (fragP, segment_type)
1182 fragS *fragP;
1183 segT segment_type;
1184 {
1185 as_fatal ("Relaxation should never occur");
1186 }
1187
1188 const relax_typeS md_relax_table[] =
1189 {0};
1190
1191 void
1192 md_end ()
1193 {
1194 }
1195
1196 #if 0
1197
1198 /* As far as I can tell, this routine is never called. What is it
1199 doing here?
1200 Ian Taylor, Cygnus Support 13 Jul 1993 */
1201
1202
1203 /*
1204 * Risc relocations are completely different, so it needs
1205 * this machine dependent routine to emit them.
1206 */
1207 void
1208 emit_relocations (fixP, segment_address_in_file)
1209 fixS *fixP;
1210 relax_addressT segment_address_in_file;
1211 {
1212 struct reloc_info_m88k ri;
1213 symbolS *symbolP;
1214 extern char *next_object_file_charP;
1215
1216 bzero ((char *) &ri, sizeof (ri));
1217 for (; fixP; fixP = fixP->fx_next)
1218 {
1219 if (fixP->fx_r_type >= NO_RELOC)
1220 {
1221 fprintf (stderr, "fixP->fx_r_type = %d\n", fixP->fx_r_type);
1222 abort ();
1223 }
1224
1225 if ((symbolP = fixP->fx_addsy) != NULL)
1226 {
1227 ri.r_address = fixP->fx_frag->fr_address +
1228 fixP->fx_where - segment_address_in_file;
1229 if ((symbolP->sy_type & N_TYPE) == N_UNDF)
1230 {
1231 ri.r_extern = 1;
1232 ri.r_symbolnum = symbolP->sy_number;
1233 }
1234 else
1235 {
1236 ri.r_extern = 0;
1237 ri.r_symbolnum = symbolP->sy_type & N_TYPE;
1238 }
1239 if (symbolP && symbolP->sy_frag)
1240 {
1241 ri.r_addend = symbolP->sy_frag->fr_address;
1242 }
1243 ri.r_type = fixP->fx_r_type;
1244 if (fixP->fx_pcrel)
1245 {
1246 ri.r_addend -= ri.r_address;
1247 }
1248 else
1249 {
1250 ri.r_addend = fixP->fx_addnumber;
1251 }
1252
1253 append (&next_object_file_charP, (char *) &ri, sizeof (ri));
1254 }
1255 }
1256 return;
1257 }
1258
1259 #endif /* 0 */
1260
1261 #if 0
1262
1263 /* This routine can be subsumed by s_lcomm in read.c.
1264 Ian Taylor, Cygnus Support 13 Jul 1993 */
1265
1266
1267 static void
1268 s_bss ()
1269 {
1270 char *name;
1271 char c;
1272 char *p;
1273 int temp, bss_align;
1274 symbolS *symbolP;
1275
1276 name = input_line_pointer;
1277 c = get_symbol_end ();
1278 p = input_line_pointer;
1279 *p = c;
1280 SKIP_WHITESPACE ();
1281 if (*input_line_pointer != ',')
1282 {
1283 as_warn ("Expected comma after name");
1284 ignore_rest_of_line ();
1285 return;
1286 }
1287 input_line_pointer++;
1288 if ((temp = get_absolute_expression ()) < 0)
1289 {
1290 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1291 ignore_rest_of_line ();
1292 return;
1293 }
1294 *p = 0;
1295 symbolP = symbol_find_or_make (name);
1296 *p = c;
1297 if (*input_line_pointer == ',')
1298 {
1299 input_line_pointer++;
1300 bss_align = get_absolute_expression ();
1301 }
1302 else
1303 bss_align = 0;
1304
1305 if (!S_IS_DEFINED(symbolP)
1306 || S_GET_SEGMENT(symbolP) == SEG_BSS)
1307 {
1308 if (! need_pass_2)
1309 {
1310 char *p;
1311 segT current_seg = now_seg;
1312 subsegT current_subseg = now_subseg;
1313
1314 subseg_new (SEG_BSS, 1); /* switch to bss */
1315
1316 if (bss_align)
1317 frag_align (bss_align, 0);
1318
1319 /* detach from old frag */
1320 if (symbolP->sy_type == N_BSS && symbolP->sy_frag != NULL)
1321 symbolP->sy_frag->fr_symbol = NULL;
1322
1323 symbolP->sy_frag = frag_now;
1324 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1325 temp, (char *)0);
1326 *p = 0;
1327 S_SET_SEGMENT (symbolP, SEG_BSS);
1328
1329 subseg_new (current_seg, current_subseg);
1330 }
1331 }
1332 else
1333 {
1334 as_warn ("Ignoring attempt to re-define symbol %s.", name);
1335 }
1336
1337 while (!is_end_of_line[*input_line_pointer])
1338 {
1339 input_line_pointer++;
1340 }
1341
1342 return;
1343 }
1344
1345 #endif /* 0 */
1346
1347 #ifdef M88KCOFF
1348
1349 /* These functions are needed if we are linking with obj-coffbfd.c.
1350 That file may be replaced by a more BFD oriented version at some
1351 point. If that happens, these functions should be rexamined.
1352
1353 Ian Lance Taylor, Cygnus Support, 13 July 1993. */
1354
1355 /* Given a fixS structure (created by a call to fix_new, above),
1356 return the BFD relocation type to use for it. */
1357
1358 short
1359 tc_coff_fix2rtype (fixp)
1360 fixS *fixp;
1361 {
1362 switch (fixp->fx_r_type)
1363 {
1364 case RELOC_LO16:
1365 return R_LVRT16;
1366 case RELOC_HI16:
1367 return R_HVRT16;
1368 case RELOC_PC16:
1369 return R_PCR16L;
1370 case RELOC_PC26:
1371 return R_PCR26L;
1372 case RELOC_32:
1373 return R_VRT32;
1374 case RELOC_IW16:
1375 return R_VRT16;
1376 default:
1377 abort ();
1378 }
1379 }
1380
1381 /* Apply a fixS to the object file. Since COFF does not use addends
1382 in relocs, the addend is actually stored directly in the object
1383 file itself. */
1384
1385 void
1386 md_apply_fix (fixp, val)
1387 fixS *fixp;
1388 long val;
1389 {
1390 char *buf;
1391
1392 buf = fixp->fx_frag->fr_literal + fixp->fx_where;
1393
1394 switch (fixp->fx_r_type)
1395 {
1396 case RELOC_IW16:
1397 buf[2] = val >> 8;
1398 buf[3] = val;
1399 break;
1400
1401 case RELOC_LO16:
1402 buf[0] = val >> 8;
1403 buf[1] = val;
1404 break;
1405
1406 case RELOC_HI16:
1407 buf[0] = val >> 24;
1408 buf[1] = val >> 16;
1409 break;
1410
1411 case RELOC_PC16:
1412 buf[0] = val >> 10;
1413 buf[1] = val >> 2;
1414 break;
1415
1416 case RELOC_PC26:
1417 buf[0] |= (val >> 26) & 0x03;
1418 buf[1] = val >> 18;
1419 buf[2] = val >> 10;
1420 buf[3] = val >> 2;
1421 break;
1422
1423 case RELOC_32:
1424 buf[0] = val >> 24;
1425 buf[1] = val >> 16;
1426 buf[2] = val >> 8;
1427 buf[3] = val;
1428 break;
1429
1430 default:
1431 abort ();
1432 }
1433 }
1434
1435 /* Where a PC relative offset is calculated from. On the m88k they
1436 are calculated from just after the instruction. */
1437
1438 long
1439 md_pcrel_from (fixp)
1440 fixS *fixp;
1441 {
1442 switch (fixp->fx_r_type)
1443 {
1444 case RELOC_PC16:
1445 return fixp->fx_frag->fr_address + fixp->fx_where - 2;
1446 case RELOC_PC26:
1447 return fixp->fx_frag->fr_address + fixp->fx_where;
1448 default:
1449 abort ();
1450 }
1451 /*NOTREACHED*/
1452 }
1453
1454 #endif /* M88KCOFF */