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