daily update
[binutils.git] / gas / config / tc-m88k.c
blobf39098c3913aa604ee671acca6cdfe1d5a3e9579
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 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
5 2000, 2001, 2002
6 Free Software Foundation, Inc.
8 This file is part of GAS, the GNU Assembler.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 02111-1307, USA. */
25 #include "as.h"
26 #include "safe-ctype.h"
27 #include "subsegs.h"
28 #include "m88k-opcode.h"
30 struct field_val_assoc
32 char *name;
33 unsigned val;
36 struct field_val_assoc cr_regs[] =
38 {"PID", 0},
39 {"PSR", 1},
40 {"EPSR", 2},
41 {"SSBR", 3},
42 {"SXIP", 4},
43 {"SNIP", 5},
44 {"SFIP", 6},
45 {"VBR", 7},
46 {"DMT0", 8},
47 {"DMD0", 9},
48 {"DMA0", 10},
49 {"DMT1", 11},
50 {"DMD1", 12},
51 {"DMA1", 13},
52 {"DMT2", 14},
53 {"DMD2", 15},
54 {"DMA2", 16},
55 {"SR0", 17},
56 {"SR1", 18},
57 {"SR2", 19},
58 {"SR3", 20},
60 {NULL, 0},
63 struct field_val_assoc fcr_regs[] =
65 {"FPECR", 0},
66 {"FPHS1", 1},
67 {"FPLS1", 2},
68 {"FPHS2", 3},
69 {"FPLS2", 4},
70 {"FPPT", 5},
71 {"FPRH", 6},
72 {"FPRL", 7},
73 {"FPIT", 8},
75 {"FPSR", 62},
76 {"FPCR", 63},
78 {NULL, 0},
81 struct field_val_assoc cmpslot[] =
83 /* Integer Floating point */
84 {"nc", 0},
85 {"cp", 1},
86 {"eq", 2},
87 {"ne", 3},
88 {"gt", 4},
89 {"le", 5},
90 {"lt", 6},
91 {"ge", 7},
92 {"hi", 8}, {"ou", 8},
93 {"ls", 9}, {"ib", 9},
94 {"lo", 10}, {"in", 10},
95 {"hs", 11}, {"ob", 11},
96 {"be", 12}, {"ue", 12},
97 {"nb", 13}, {"lg", 13},
98 {"he", 14}, {"ug", 14},
99 {"nh", 15}, {"ule", 15},
100 {"ul", 16},
101 {"uge", 17},
103 {NULL, 0},
106 struct field_val_assoc cndmsk[] =
108 {"gt0", 1},
109 {"eq0", 2},
110 {"ge0", 3},
111 {"lt0", 12},
112 {"ne0", 13},
113 {"le0", 14},
115 {NULL, 0},
118 struct m88k_insn
120 unsigned long opcode;
121 expressionS exp;
122 enum reloc_type reloc;
125 static char *get_bf PARAMS ((char *param, unsigned *valp));
126 static char *get_cmp PARAMS ((char *param, unsigned *valp));
127 static char *get_cnd PARAMS ((char *param, unsigned *valp));
128 static char *get_cr PARAMS ((char *param, unsigned *regnop));
129 static char *get_fcr PARAMS ((char *param, unsigned *regnop));
130 static char *get_imm16 PARAMS ((char *param, struct m88k_insn *insn));
131 static char *get_o6 PARAMS ((char *param, unsigned *valp));
132 static char *get_reg PARAMS ((char *param, unsigned *regnop, int reg_prefix));
133 static char *get_vec9 PARAMS ((char *param, unsigned *valp));
134 static char *getval PARAMS ((char *param, unsigned int *valp));
136 static char *get_pcr PARAMS ((char *param, struct m88k_insn *insn,
137 enum reloc_type reloc));
139 static int calcop PARAMS ((struct m88k_opcode *format,
140 char *param, struct m88k_insn *insn));
142 extern char *myname;
143 static struct hash_control *op_hash = NULL;
145 /* These bits should be turned off in the first address of every segment */
146 int md_seg_align = 7;
148 /* These chars start a comment anywhere in a source file (except inside
149 another comment. */
150 const char comment_chars[] = ";";
152 /* These chars only start a comment at the beginning of a line. */
153 const char line_comment_chars[] = "#";
155 const char line_separator_chars[] = "";
157 /* Chars that can be used to separate mant from exp in floating point nums */
158 const char EXP_CHARS[] = "eE";
160 /* Chars that mean this number is a floating point constant */
161 /* as in 0f123.456 */
162 /* or 0H1.234E-12 (see exp chars above) */
163 const char FLT_CHARS[] = "dDfF";
165 extern void float_cons (), cons (), s_globl (), s_space (),
166 s_set (), s_lcomm ();
168 const pseudo_typeS md_pseudo_table[] =
170 {"align", s_align_bytes, 4},
171 {"def", s_set, 0},
172 {"dfloat", float_cons, 'd'},
173 {"ffloat", float_cons, 'f'},
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 {NULL, NULL, 0}
184 void
185 md_begin ()
187 const char *retval = NULL;
188 unsigned int i = 0;
190 /* Initialize hash table. */
191 op_hash = hash_new ();
193 while (*m88k_opcodes[i].name)
195 char *name = m88k_opcodes[i].name;
197 /* Hash each mnemonic and record its position. */
198 retval = hash_insert (op_hash, name, &m88k_opcodes[i]);
200 if (retval != NULL)
201 as_fatal (_("Can't hash instruction '%s':%s"),
202 m88k_opcodes[i].name, retval);
204 /* Skip to next unique mnemonic or end of list. */
205 for (i++; !strcmp (m88k_opcodes[i].name, name); i++)
210 const char *md_shortopts = "";
211 struct option md_longopts[] = {
212 {NULL, no_argument, NULL, 0}
214 size_t md_longopts_size = sizeof (md_longopts);
217 md_parse_option (c, arg)
218 int c ATTRIBUTE_UNUSED;
219 char *arg ATTRIBUTE_UNUSED;
221 return 0;
224 void
225 md_show_usage (stream)
226 FILE *stream ATTRIBUTE_UNUSED;
230 void
231 md_assemble (op)
232 char *op;
234 char *param, *thisfrag;
235 char c;
236 struct m88k_opcode *format;
237 struct m88k_insn insn;
239 assert (op);
241 /* Skip over instruction to find parameters. */
242 for (param = op; *param != 0 && !ISSPACE (*param); param++)
244 c = *param;
245 *param++ = '\0';
247 /* Try to find the instruction in the hash table. */
248 if ((format = (struct m88k_opcode *) hash_find (op_hash, op)) == NULL)
250 as_bad (_("Invalid mnemonic '%s'"), op);
251 return;
254 /* Try parsing this instruction into insn. */
255 insn.exp.X_add_symbol = 0;
256 insn.exp.X_op_symbol = 0;
257 insn.exp.X_add_number = 0;
258 insn.exp.X_op = O_illegal;
259 insn.reloc = NO_RELOC;
261 while (!calcop (format, param, &insn))
263 /* If it doesn't parse try the next instruction. */
264 if (!strcmp (format[0].name, format[1].name))
265 format++;
266 else
268 as_fatal (_("Parameter syntax error"));
269 return;
273 /* Grow the current frag and plop in the opcode. */
274 thisfrag = frag_more (4);
275 md_number_to_chars (thisfrag, insn.opcode, 4);
277 /* If this instruction requires labels mark it for later. */
278 switch (insn.reloc)
280 case NO_RELOC:
281 break;
283 case RELOC_LO16:
284 case RELOC_HI16:
285 fix_new_exp (frag_now,
286 thisfrag - frag_now->fr_literal + 2,
288 &insn.exp,
290 insn.reloc);
291 break;
293 case RELOC_IW16:
294 fix_new_exp (frag_now,
295 thisfrag - frag_now->fr_literal,
297 &insn.exp,
299 insn.reloc);
300 break;
302 case RELOC_PC16:
303 fix_new_exp (frag_now,
304 thisfrag - frag_now->fr_literal + 2,
306 &insn.exp,
308 insn.reloc);
309 break;
311 case RELOC_PC26:
312 fix_new_exp (frag_now,
313 thisfrag - frag_now->fr_literal,
315 &insn.exp,
317 insn.reloc);
318 break;
320 default:
321 as_fatal (_("Unknown relocation type"));
322 break;
326 static int
327 calcop (format, param, insn)
328 struct m88k_opcode *format;
329 char *param;
330 struct m88k_insn *insn;
332 char *fmt = format->op_spec;
333 int f;
334 unsigned val;
335 unsigned opcode;
336 int reg_prefix = 'r';
338 insn->opcode = format->opcode;
339 opcode = 0;
341 for (;;)
343 if (param == 0)
344 return 0;
345 f = *fmt++;
346 switch (f)
348 case 0:
349 insn->opcode |= opcode;
350 return (*param == 0 || *param == '\n');
352 default:
353 if (f != *param++)
354 return 0;
355 break;
357 case 'd':
358 param = get_reg (param, &val, reg_prefix);
359 reg_prefix = 'r';
360 opcode |= val << 21;
361 break;
363 case 'o':
364 param = get_o6 (param, &val);
365 opcode |= ((val >> 2) << 7);
366 break;
368 case 'x':
369 reg_prefix = 'x';
370 break;
372 case '1':
373 param = get_reg (param, &val, reg_prefix);
374 reg_prefix = 'r';
375 opcode |= val << 16;
376 break;
378 case '2':
379 param = get_reg (param, &val, reg_prefix);
380 reg_prefix = 'r';
381 opcode |= val;
382 break;
384 case '3':
385 param = get_reg (param, &val, 'r');
386 opcode |= (val << 16) | val;
387 break;
389 case 'I':
390 param = get_imm16 (param, insn);
391 break;
393 case 'b':
394 param = get_bf (param, &val);
395 opcode |= val;
396 break;
398 case 'p':
399 param = get_pcr (param, insn, RELOC_PC16);
400 break;
402 case 'P':
403 param = get_pcr (param, insn, RELOC_PC26);
404 break;
406 case 'B':
407 param = get_cmp (param, &val);
408 opcode |= val;
409 break;
411 case 'M':
412 param = get_cnd (param, &val);
413 opcode |= val;
414 break;
416 case 'c':
417 param = get_cr (param, &val);
418 opcode |= val << 5;
419 break;
421 case 'f':
422 param = get_fcr (param, &val);
423 opcode |= val << 5;
424 break;
426 case 'V':
427 param = get_vec9 (param, &val);
428 opcode |= val;
429 break;
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;
440 static char *
441 match_name (param, assoc_tab, valp)
442 char *param;
443 struct field_val_assoc *assoc_tab;
444 unsigned *valp;
446 int i;
447 char *name;
448 int name_len;
450 for (i = 0;; i++)
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))
458 *valp = assoc_tab[i].val;
459 return param + name_len;
464 static char *
465 get_reg (param, regnop, reg_prefix)
466 char *param;
467 unsigned *regnop;
468 int reg_prefix;
470 unsigned c;
471 unsigned regno;
473 c = *param++;
474 if (c == reg_prefix)
476 regno = *param++ - '0';
477 if (regno < 10)
479 if (regno == 0)
481 *regnop = 0;
482 return param;
484 c = *param - '0';
485 if (c < 10)
487 regno = regno * 10 + c;
488 if (c < 32)
490 *regnop = regno;
491 return param + 1;
494 else
496 *regnop = regno;
497 return param;
500 return NULL;
502 else if (c == 's' && param[0] == 'p')
504 *regnop = 31;
505 return param + 1;
508 return 0;
511 static char *
512 get_imm16 (param, insn)
513 char *param;
514 struct m88k_insn *insn;
516 enum reloc_type reloc = NO_RELOC;
517 unsigned int val;
518 char *save_ptr;
520 if (!strncmp (param, "hi16", 4) && !ISALNUM (param[4]))
522 reloc = RELOC_HI16;
523 param += 4;
525 else if (!strncmp (param, "lo16", 4) && !ISALNUM (param[4]))
527 reloc = RELOC_LO16;
528 param += 4;
530 else if (!strncmp (param, "iw16", 4) && !ISALNUM (param[4]))
532 reloc = RELOC_IW16;
533 param += 4;
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;
542 val = insn->exp.X_add_number;
544 if (insn->exp.X_op == O_constant)
546 /* Insert the value now, and reset reloc to NO_RELOC. */
547 if (reloc == NO_RELOC)
549 /* Warn about too big expressions if not surrounded by xx16. */
550 if (val > 0xffff)
551 as_warn (_("Expression truncated to 16 bits"));
554 if (reloc == RELOC_HI16)
555 val >>= 16;
557 insn->opcode |= val & 0xffff;
558 reloc = NO_RELOC;
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;
565 insn->reloc = reloc;
567 return param;
570 static char *
571 get_pcr (param, insn, reloc)
572 char *param;
573 struct m88k_insn *insn;
574 enum reloc_type reloc;
576 char *saveptr, *saveparam;
578 saveptr = input_line_pointer;
579 input_line_pointer = param;
581 expression (&insn->exp);
583 saveparam = input_line_pointer;
584 input_line_pointer = saveptr;
586 /* Botch: We should relocate now if O_constant. */
587 insn->reloc = reloc;
589 return saveparam;
592 static char *
593 get_cmp (param, valp)
594 char *param;
595 unsigned *valp;
597 unsigned int val;
598 char *save_ptr;
600 save_ptr = param;
602 param = match_name (param, cmpslot, valp);
603 val = *valp;
605 if (param == NULL)
607 param = save_ptr;
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;
615 if (val >= 32)
617 as_warn (_("Expression truncated to 5 bits"));
618 val %= 32;
622 *valp = val << 21;
623 return param;
626 static char *
627 get_cnd (param, valp)
628 char *param;
629 unsigned *valp;
631 unsigned int val;
633 if (ISDIGIT (*param))
635 param = getval (param, &val);
637 if (val >= 32)
639 as_warn (_("Expression truncated to 5 bits"));
640 val %= 32;
643 else
645 param[0] = TOLOWER (param[0]);
646 param[1] = TOLOWER (param[1]);
648 param = match_name (param, cndmsk, valp);
650 if (param == NULL)
651 return NULL;
653 val = *valp;
656 *valp = val << 21;
657 return param;
660 static char *
661 get_bf2 (param, bc)
662 char *param;
663 int bc;
665 int depth = 0;
666 int c;
668 for (;;)
670 c = *param;
671 if (c == 0)
672 return param;
673 else if (c == '(')
674 depth++;
675 else if (c == ')')
676 depth--;
677 else if (c == bc && depth <= 0)
678 return param;
679 param++;
683 static char *
684 get_bf_offset_expression (param, offsetp)
685 char *param;
686 unsigned *offsetp;
688 unsigned offset;
690 if (ISALPHA (param[0]))
692 param[0] = TOLOWER (param[0]);
693 param[1] = TOLOWER (param[1]);
695 param = match_name (param, cmpslot, offsetp);
697 return param;
699 else
701 input_line_pointer = param;
702 offset = get_absolute_expression ();
703 param = input_line_pointer;
706 *offsetp = offset;
707 return param;
710 static char *
711 get_bf (param, valp)
712 char *param;
713 unsigned *valp;
715 unsigned offset = 0;
716 unsigned width = 0;
717 char *xp;
718 char *save_ptr;
720 xp = get_bf2 (param, '<');
722 save_ptr = input_line_pointer;
723 input_line_pointer = param;
724 if (*xp == 0)
726 /* We did not find '<'. We have an offset (width implicitly 32). */
727 param = get_bf_offset_expression (param, &offset);
728 input_line_pointer = save_ptr;
729 if (param == NULL)
730 return NULL;
732 else
734 *xp++ = 0; /* Overwrite the '<' */
735 param = get_bf2 (xp, '>');
736 if (*param == 0)
737 return NULL;
738 *param++ = 0; /* Overwrite the '>' */
740 width = get_absolute_expression ();
741 xp = get_bf_offset_expression (xp, &offset);
742 input_line_pointer = save_ptr;
744 if (xp + 1 != param)
745 return NULL;
748 *valp = ((width % 32) << 5) | (offset % 32);
750 return param;
753 static char *
754 get_cr (param, regnop)
755 char *param;
756 unsigned *regnop;
758 unsigned regno;
759 unsigned c;
761 if (!strncmp (param, "cr", 2))
763 param += 2;
765 regno = *param++ - '0';
766 if (regno < 10)
768 if (regno == 0)
770 *regnop = 0;
771 return param;
773 c = *param - '0';
774 if (c < 10)
776 regno = regno * 10 + c;
777 if (c < 64)
779 *regnop = regno;
780 return param + 1;
783 else
785 *regnop = regno;
786 return param;
789 return NULL;
792 param = match_name (param, cr_regs, regnop);
794 return param;
797 static char *
798 get_fcr (param, regnop)
799 char *param;
800 unsigned *regnop;
802 unsigned regno;
803 unsigned c;
805 if (!strncmp (param, "fcr", 3))
807 param += 3;
809 regno = *param++ - '0';
810 if (regno < 10)
812 if (regno == 0)
814 *regnop = 0;
815 return param;
817 c = *param - '0';
818 if (c < 10)
820 regno = regno * 10 + c;
821 if (c < 64)
823 *regnop = regno;
824 return param + 1;
827 else
829 *regnop = regno;
830 return param;
833 return NULL;
836 param = match_name (param, fcr_regs, regnop);
838 return param;
841 static char *
842 get_vec9 (param, valp)
843 char *param;
844 unsigned *valp;
846 unsigned val;
847 char *save_ptr;
849 save_ptr = input_line_pointer;
850 input_line_pointer = param;
851 val = get_absolute_expression ();
852 param = input_line_pointer;
853 input_line_pointer = save_ptr;
855 if (val >= 1 << 9)
856 as_warn (_("Expression truncated to 9 bits"));
858 *valp = val % (1 << 9);
860 return param;
863 static char *
864 get_o6 (param, valp)
865 char *param;
866 unsigned *valp;
868 unsigned val;
869 char *save_ptr;
871 save_ptr = input_line_pointer;
872 input_line_pointer = param;
873 val = get_absolute_expression ();
874 param = input_line_pointer;
875 input_line_pointer = save_ptr;
877 if (val & 0x3)
878 as_warn (_("Removed lower 2 bits of expression"));
880 *valp = val;
882 return (param);
885 #define hexval(z) \
886 (ISDIGIT (z) ? (z) - '0' : \
887 ISLOWER (z) ? (z) - 'a' + 10 : \
888 ISUPPER (z) ? (z) - 'A' + 10 : -1)
890 static char *
891 getval (param, valp)
892 char *param;
893 unsigned int *valp;
895 unsigned int val = 0;
896 unsigned int c;
898 c = *param++;
899 if (c == '0')
901 c = *param++;
902 if (c == 'x' || c == 'X')
904 c = *param++;
905 c = hexval (c);
906 while (c < 16)
908 val = val * 16 + c;
909 c = *param++;
910 c = hexval (c);
913 else
915 c -= '0';
916 while (c < 8)
918 val = val * 8 + c;
919 c = *param++ - '0';
923 else
925 c -= '0';
926 while (c < 10)
928 val = val * 10 + c;
929 c = *param++ - '0';
933 *valp = val;
934 return param - 1;
937 void
938 md_number_to_chars (buf, val, nbytes)
939 char *buf;
940 valueT val;
941 int nbytes;
943 number_to_chars_bigendian (buf, val, nbytes);
946 void
947 md_number_to_disp (buf, val, nbytes)
948 char *buf;
949 int val;
950 int nbytes;
952 as_fatal (_("md_number_to_disp not defined"));
953 md_number_to_chars (buf, val, nbytes);
956 void
957 md_number_to_field (buf, val, nbytes)
958 char *buf;
959 int val;
960 int nbytes;
962 as_fatal (_("md_number_to_field not defined"));
963 md_number_to_chars (buf, val, nbytes);
966 #define MAX_LITTLENUMS 6
968 /* Turn a string in input_line_pointer into a floating point constant of type
969 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
970 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
972 char *
973 md_atof (type, litP, sizeP)
974 char type;
975 char *litP;
976 int *sizeP;
978 int prec;
979 LITTLENUM_TYPE words[MAX_LITTLENUMS];
980 LITTLENUM_TYPE *wordP;
981 char *t;
983 switch (type)
985 case 'f':
986 case 'F':
987 case 's':
988 case 'S':
989 prec = 2;
990 break;
992 case 'd':
993 case 'D':
994 case 'r':
995 case 'R':
996 prec = 4;
997 break;
999 case 'x':
1000 case 'X':
1001 prec = 6;
1002 break;
1004 case 'p':
1005 case 'P':
1006 prec = 6;
1007 break;
1009 default:
1010 *sizeP = 0;
1011 return _("Bad call to MD_ATOF()");
1013 t = atof_ieee (input_line_pointer, type, words);
1014 if (t)
1015 input_line_pointer = t;
1017 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1018 for (wordP = words; prec--;)
1020 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1021 litP += sizeof (LITTLENUM_TYPE);
1023 return 0;
1026 int md_short_jump_size = 4;
1028 void
1029 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1030 char *ptr;
1031 addressT from_addr ATTRIBUTE_UNUSED;
1032 addressT to_addr ATTRIBUTE_UNUSED;
1033 fragS *frag;
1034 symbolS *to_symbol;
1036 ptr[0] = (char) 0xc0;
1037 ptr[1] = 0x00;
1038 ptr[2] = 0x00;
1039 ptr[3] = 0x00;
1040 fix_new (frag,
1041 ptr - frag->fr_literal,
1043 to_symbol,
1044 (offsetT) 0,
1046 RELOC_PC26); /* Botch: Shouldn't this be RELOC_PC16? */
1049 int md_long_jump_size = 4;
1051 void
1052 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1053 char *ptr;
1054 addressT from_addr ATTRIBUTE_UNUSED;
1055 addressT to_addr ATTRIBUTE_UNUSED;
1056 fragS *frag;
1057 symbolS *to_symbol;
1059 ptr[0] = (char) 0xc0;
1060 ptr[1] = 0x00;
1061 ptr[2] = 0x00;
1062 ptr[3] = 0x00;
1063 fix_new (frag,
1064 ptr - frag->fr_literal,
1066 to_symbol,
1067 (offsetT) 0,
1069 RELOC_PC26);
1073 md_estimate_size_before_relax (fragP, segment_type)
1074 fragS *fragP ATTRIBUTE_UNUSED;
1075 segT segment_type ATTRIBUTE_UNUSED;
1077 as_fatal (_("Relaxation should never occur"));
1078 return (-1);
1081 #ifdef M88KCOFF
1083 /* These functions are needed if we are linking with obj-coffbfd.c.
1084 That file may be replaced by a more BFD oriented version at some
1085 point. If that happens, these functions should be rexamined.
1087 Ian Lance Taylor, Cygnus Support, 13 July 1993. */
1089 /* Given a fixS structure (created by a call to fix_new, above),
1090 return the BFD relocation type to use for it. */
1092 short
1093 tc_coff_fix2rtype (fixp)
1094 fixS *fixp;
1096 switch (fixp->fx_r_type)
1098 case RELOC_LO16:
1099 return R_LVRT16;
1100 case RELOC_HI16:
1101 return R_HVRT16;
1102 case RELOC_PC16:
1103 return R_PCR16L;
1104 case RELOC_PC26:
1105 return R_PCR26L;
1106 case RELOC_32:
1107 return R_VRT32;
1108 case RELOC_IW16:
1109 return R_VRT16;
1110 default:
1111 abort ();
1115 /* Apply a fixS to the object file. Since COFF does not use addends
1116 in relocs, the addend is actually stored directly in the object
1117 file itself. */
1119 void
1120 md_apply_fix3 (fixP, valP, seg)
1121 fixS *fixP;
1122 valueT * valP;
1123 segT seg ATTRIBUTE_UNUSED;
1125 long val = * (long *) valP;
1126 char *buf;
1128 buf = fixP->fx_frag->fr_literal + fixP->fx_where;
1129 fixP->fx_offset = 0;
1131 switch (fixP->fx_r_type)
1133 case RELOC_IW16:
1134 fixP->fx_offset = val >> 16;
1135 buf[2] = val >> 8;
1136 buf[3] = val;
1137 break;
1139 case RELOC_LO16:
1140 fixP->fx_offset = val >> 16;
1141 buf[0] = val >> 8;
1142 buf[1] = val;
1143 break;
1145 case RELOC_HI16:
1146 fixP->fx_offset = val >> 16;
1147 buf[0] = val >> 8;
1148 buf[1] = val;
1149 break;
1151 case RELOC_PC16:
1152 buf[0] = val >> 10;
1153 buf[1] = val >> 2;
1154 break;
1156 case RELOC_PC26:
1157 buf[0] |= (val >> 26) & 0x03;
1158 buf[1] = val >> 18;
1159 buf[2] = val >> 10;
1160 buf[3] = val >> 2;
1161 break;
1163 case RELOC_32:
1164 buf[0] = val >> 24;
1165 buf[1] = val >> 16;
1166 buf[2] = val >> 8;
1167 buf[3] = val;
1168 break;
1170 default:
1171 abort ();
1174 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1175 fixP->fx_done = 1;
1178 /* Where a PC relative offset is calculated from. On the m88k they
1179 are calculated from just after the instruction. */
1181 long
1182 md_pcrel_from (fixp)
1183 fixS *fixp;
1185 switch (fixp->fx_r_type)
1187 case RELOC_PC16:
1188 return fixp->fx_frag->fr_address + fixp->fx_where - 2;
1189 case RELOC_PC26:
1190 return fixp->fx_frag->fr_address + fixp->fx_where;
1191 default:
1192 abort ();
1194 /*NOTREACHED*/
1197 /* Fill in rs_align_code fragments. */
1199 void
1200 m88k_handle_align (fragp)
1201 fragS *fragp;
1203 static const unsigned char nop_pattern[] = { 0xf4, 0x00, 0x58, 0x00 };
1205 int bytes;
1206 char *p;
1208 if (fragp->fr_type != rs_align_code)
1209 return;
1211 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
1212 p = fragp->fr_literal + fragp->fr_fix;
1214 if (bytes & 3)
1216 int fix = bytes & 3;
1217 memset (p, 0, fix);
1218 p += fix;
1219 bytes -= fix;
1220 fragp->fr_fix += fix;
1223 memcpy (p, nop_pattern, 4);
1224 fragp->fr_var = 4;
1227 #endif /* M88KCOFF */