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