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