* config/tc-sh.h (struct sh_segment_info_type): Define.
[deliverable/binutils-gdb.git] / gas / config / tc-h8300.c
1 /* tc-h8300.c -- Assemble code for the Hitachi H8/300
2 Copyright (C) 1991, 1992 Free Software Foundation.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20
21 /*
22 Written By Steve Chamberlain
23 sac@cygnus.com
24 */
25
26 #include <stdio.h>
27 #include "as.h"
28 #include "bfd.h"
29 #define DEFINE_TABLE
30 #define h8_opcodes ops
31 #include "opcode/h8300.h"
32 #include <ctype.h>
33
34 const char comment_chars[] =
35 {';', 0};
36 const char line_separator_chars[] =
37 {0};
38 const char line_comment_chars[] = "#";
39
40 /* This table describes all the machine specific pseudo-ops the assembler
41 has to support. The fields are:
42 pseudo-op name without dot
43 function to call to execute this pseudo-op
44 Integer arg to pass to the function
45 */
46
47 void cons ();
48
49 int Hmode;
50 #define PSIZE (Hmode ? L_32 : L_16)
51 #define DMODE (L_16)
52 #define DSYMMODE (Hmode ? L_24 : L_16)
53 int bsize = L_8; /* default branch displacement */
54
55
56 void
57 h8300hmode ()
58 {
59 Hmode = 1;
60 }
61
62
63 void
64 sbranch (size)
65 int size;
66 {
67 bsize = size;
68 }
69
70 static void pint ()
71 {
72 cons (Hmode ? 4 : 2);
73 }
74
75 const pseudo_typeS md_pseudo_table[] =
76 {
77
78 {"h8300h", h8300hmode, 0},
79 {"sbranch", sbranch, L_8},
80 {"lbranch", sbranch, L_16},
81
82 {"int", pint, 0},
83 {"data.b", cons, 1},
84 {"data.w", cons, 2},
85 {"data.l", cons, 4},
86 {"form", listing_psize, 0},
87 {"heading", listing_title, 0},
88 {"import", s_ignore, 0},
89 {"page", listing_eject, 0},
90 {"program", s_ignore, 0},
91 {0, 0, 0}
92 };
93
94 const int md_reloc_size;
95
96 const char EXP_CHARS[] = "eE";
97
98 /* Chars that mean this number is a floating point constant */
99 /* As in 0f12.456 */
100 /* or 0d1.2345e12 */
101 const char FLT_CHARS[] = "rRsSfFdDxXpP";
102
103 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
104
105 /*
106 This function is called once, at assembler startup time. This should
107 set up all the tables, etc that the MD part of the assembler needs
108 */
109
110
111 void
112 md_begin ()
113 {
114 struct h8_opcode *opcode;
115 char prev_buffer[100];
116 int idx = 0;
117
118 opcode_hash_control = hash_new ();
119 prev_buffer[0] = 0;
120
121 for (opcode = h8_opcodes; opcode->name; opcode++)
122 {
123 /* Strip off any . part when inserting the opcode and only enter
124 unique codes into the hash table
125 */
126 char *src = opcode->name;
127 unsigned int len = strlen (src);
128 char *dst = malloc (len + 1);
129 char *buffer = dst;
130
131 opcode->size = 0;
132 while (*src)
133 {
134 if (*src == '.')
135 {
136 src++;
137 opcode->size = *src;
138 break;
139 }
140 *dst++ = *src++;
141 }
142 *dst++ = 0;
143 if (strcmp (buffer, prev_buffer))
144 {
145 hash_insert (opcode_hash_control, buffer, (char *) opcode);
146 strcpy (prev_buffer, buffer);
147 idx++;
148 }
149 opcode->idx = idx;
150
151
152 /* Find the number of operands */
153 opcode->noperands = 0;
154 while (opcode->args.nib[opcode->noperands] != E)
155 opcode->noperands++;
156 /* Find the length of the opcode in bytes */
157 opcode->length = 0;
158 while (opcode->data.nib[opcode->length * 2] != E)
159 opcode->length++;
160 }
161
162 linkrelax = 1;
163 }
164
165
166 struct h8_exp
167 {
168 char *e_beg;
169 char *e_end;
170 expressionS e_exp;
171 };
172 int dispreg;
173 int opsize; /* Set when a register size is seen */
174
175
176 struct h8_op
177 {
178 op_type mode;
179 unsigned reg;
180 expressionS exp;
181 };
182
183 /*
184 parse operands
185 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
186 r0l,r0h,..r7l,r7h
187 @WREG
188 @WREG+
189 @-WREG
190 #const
191
192 */
193
194 /* try and parse a reg name, returns number of chars consumed */
195 int
196 parse_reg (src, mode, reg, direction)
197 char *src;
198 op_type *mode;
199 unsigned int *reg;
200 int direction;
201
202 {
203 if (src[0] == 's' && src[1] == 'p')
204 {
205 *mode = PSIZE | REG | direction;
206 *reg = 7;
207 return 2;
208 }
209 if (src[0] == 'c' && src[1] == 'c' && src[2] == 'r')
210 {
211 *mode = CCR;
212 *reg = 0;
213 return 3;
214 }
215 if (src[0] == 'f' && src[1] == 'p')
216 {
217 *mode = PSIZE | REG | direction;
218 *reg = 6;
219 return 2;
220 }
221 if (src[0] == 'e'
222 && src[1] == 'r'
223 && src[2] >= '0' && src[2] <= '7')
224 {
225 *mode = L_32 | REG | direction;
226 *reg = src[2] - '0';
227 if (!Hmode)
228 as_warn ("Reg only legal for H8/300-H");
229
230 return 3;
231 }
232 if (src[0] == 'e'
233 && src[1] >= '0' && src[1] <= '7')
234 {
235 *mode = L_16 | REG | direction;
236 *reg = src[1] - '0' + 8;
237 if (!Hmode)
238 as_warn ("Reg only legal for H8/300-H");
239 return 2;
240 }
241
242 if (src[0] == 'r')
243 {
244 if (src[1] >= '0' && src[1] <= '7')
245 {
246 if (src[2] == 'l')
247 {
248 *mode = L_8 | REG | direction;
249 *reg = (src[1] - '0') + 8;
250 return 3;
251 }
252 if (src[2] == 'h')
253 {
254 *mode = L_8 | REG | direction;
255 *reg = (src[1] - '0');
256 return 3;
257 }
258 *mode = L_16 | REG | direction;
259 *reg = (src[1] - '0');
260 return 2;
261 }
262 }
263 return 0;
264 }
265
266 char *
267 parse_exp (s, op)
268 char *s;
269 expressionS * op;
270 {
271 char *save = input_line_pointer;
272 char *new;
273
274 input_line_pointer = s;
275 expression (op);
276 if (op->X_op == O_absent)
277 as_bad ("missing operand");
278 new = input_line_pointer;
279 input_line_pointer = save;
280 return new;
281 }
282
283 static char *
284 skip_colonthing (ptr, exp, mode)
285 char *ptr;
286 expressionS *exp;
287 int *mode;
288 {
289 if (*ptr == ':')
290 {
291 ptr++;
292 *mode &= ~SIZE;
293 if (*ptr == '8')
294 {
295 ptr++;
296 /* ff fill any 8 bit quantity */
297 /* exp->X_add_number -= 0x100;*/
298 *mode |= L_8;
299 }
300 else
301 {
302 if (*ptr == '2')
303 {
304 *mode |= L_24;
305 }
306 else if (*ptr == '1')
307 {
308 *mode |= L_16;
309 }
310 while (isdigit (*ptr))
311 ptr++;
312 }
313 }
314 return ptr;
315 }
316
317 /* The many forms of operand:
318
319 Rn Register direct
320 @Rn Register indirect
321 @(exp[:16], Rn) Register indirect with displacement
322 @Rn+
323 @-Rn
324 @aa:8 absolute 8 bit
325 @aa:16 absolute 16 bit
326 @aa absolute 16 bit
327
328 #xx[:size] immediate data
329 @(exp:[8], pc) pc rel
330 @@aa[:8] memory indirect
331
332 */
333
334 char *
335 colonmod24 (op, src)
336 struct h8_op *op;
337 char *src;
338
339 {
340 int mode = 0;
341 src = skip_colonthing (src, &op->exp, &mode);
342
343 if (!mode)
344 {
345 /* Choose a default mode */
346 if (op->exp.X_add_number < -32768
347 || op->exp.X_add_number > 32767)
348 {
349 if (Hmode)
350 mode = L_24;
351 else
352 mode = L_16;
353 }
354 else if (op->exp.X_add_symbol
355 || op->exp.X_op_symbol)
356 mode = DSYMMODE;
357 else
358 mode = DMODE;
359 }
360 op->mode |= mode;
361 return src;
362
363 }
364
365
366 static void
367 get_operand (ptr, op, dst, direction)
368 char **ptr;
369 struct h8_op *op;
370 unsigned int dst;
371 int direction;
372 {
373 char *src = *ptr;
374 op_type mode;
375 unsigned int num;
376 unsigned int len;
377
378 op->mode = E;
379
380 len = parse_reg (src, &op->mode, &op->reg, direction);
381 if (len)
382 {
383 *ptr = src + len;
384 return;
385 }
386
387 if (*src == '@')
388 {
389 src++;
390 if (*src == '@')
391 {
392 src++;
393 src = parse_exp (src, &op->exp);
394
395 src = skip_colonthing (src, &op->exp, &op->mode);
396
397 *ptr = src;
398
399 op->mode = MEMIND;
400 return;
401
402 }
403
404
405 if (*src == '-')
406 {
407 src++;
408 len = parse_reg (src, &mode, &num, direction);
409 if (len == 0)
410 {
411 /* Oops, not a reg after all, must be ordinary exp */
412 src--;
413 /* must be a symbol */
414 op->mode = ABS | PSIZE | direction;
415 *ptr = skip_colonthing (parse_exp (src, &op->exp),
416 &op->exp, &op->mode);
417
418 return;
419
420
421 }
422
423
424 if ((mode & SIZE) != PSIZE)
425 as_bad ("Wrong size pointer register for architecture.");
426 op->mode = RDDEC;
427 op->reg = num;
428 *ptr = src + len;
429 return;
430 }
431 if (*src == '(')
432 {
433 /* Disp */
434 src++;
435
436 /* Start off assuming a 16 bit offset */
437
438
439 src = parse_exp (src, &op->exp);
440
441 src = colonmod24 (op, src);
442
443 if (*src == ')')
444 {
445 src++;
446 op->mode |= ABS | direction;
447 *ptr = src;
448 return;
449 }
450
451 if (*src != ',')
452 {
453 as_bad ("expected @(exp, reg16)");
454 return;
455
456 }
457 src++;
458
459 len = parse_reg (src, &mode, &op->reg, direction);
460 if (len == 0 || !(mode & REG))
461 {
462 as_bad ("expected @(exp, reg16)");
463 return;
464 }
465 op->mode |= DISP | direction;
466 dispreg = op->reg;
467 src += len;
468 src = skip_colonthing (src, &op->exp, &op->mode);
469
470 if (*src != ')' && '(')
471 {
472 as_bad ("expected @(exp, reg16)");
473 return;
474 }
475 *ptr = src + 1;
476
477 return;
478 }
479 len = parse_reg (src, &mode, &num, direction);
480
481 if (len)
482 {
483 src += len;
484 if (*src == '+')
485 {
486 src++;
487 if ((mode & SIZE) != PSIZE)
488 as_bad ("Wrong size pointer register for architecture.");
489 op->mode = RSINC;
490 op->reg = num;
491 *ptr = src;
492 return;
493 }
494 if ((mode & SIZE) != PSIZE)
495 as_bad ("Wrong size pointer register for architecture.");
496
497 op->mode = direction | IND | PSIZE;
498 op->reg = num;
499 *ptr = src;
500
501 return;
502 }
503 else
504 {
505 /* must be a symbol */
506
507 op->mode = ABS | direction;
508 src = parse_exp (src, &op->exp);
509
510 *ptr = colonmod24 (op, src);
511
512 return;
513 }
514 }
515
516
517 if (*src == '#')
518 {
519 src++;
520 op->mode = IMM;
521 src = parse_exp (src, &op->exp);
522 *ptr = skip_colonthing (src, &op->exp, &op->mode);
523
524 return;
525 }
526 else
527 {
528 src = parse_exp (src, &op->exp);
529 /* Trailing ':' size ? */
530 if (*src == ':')
531 {
532 if (src[1] == '1' && src[2] == '6')
533 {
534 op->mode = PCREL | L_16;
535 src += 3;
536 }
537 else if (src[1] == '8')
538 {
539 op->mode = PCREL | L_8;
540 src += 2;
541 }
542 else
543 {
544 as_bad ("expect :8 or :16 here");
545 }
546 }
547 else
548 {
549 op->mode = PCREL | bsize;
550 }
551 *ptr = src;
552 }
553 }
554
555
556 static
557 char *
558 get_operands (noperands, op_end, operand)
559 unsigned int noperands;
560 char *op_end;
561 struct h8_op *operand;
562 {
563 char *ptr = op_end;
564
565 switch (noperands)
566 {
567 case 0:
568 operand[0].mode = 0;
569 operand[1].mode = 0;
570 break;
571
572 case 1:
573 ptr++;
574 get_operand (&ptr, operand + 0, 0, SRC);
575 if (*ptr == ',')
576 {
577 ptr++;
578 get_operand (&ptr, operand + 1, 1, DST);
579 }
580 else
581 {
582 operand[1].mode = 0;
583 }
584
585 break;
586 case 2:
587 ptr++;
588 get_operand (&ptr, operand + 0, 0, SRC);
589 if (*ptr == ',')
590 ptr++;
591 get_operand (&ptr, operand + 1, 1, DST);
592 break;
593
594 default:
595 abort ();
596 }
597
598
599 return ptr;
600 }
601
602 /* Passed a pointer to a list of opcodes which use different
603 addressing modes, return the opcode which matches the opcodes
604 provided
605 */
606 static
607 struct h8_opcode *
608 get_specific (opcode, operands)
609 struct h8_opcode *opcode;
610 struct h8_op *operands;
611 {
612 struct h8_opcode *this_try = opcode;
613 int found = 0;
614
615 unsigned int this_index = opcode->idx;
616
617 while (this_index == opcode->idx && !found)
618 {
619 unsigned int i;
620 found = 1;
621
622 this_try = opcode++;
623 for (i = 0; i < this_try->noperands && found; i++)
624 {
625 op_type op = this_try->args.nib[i];
626 int x = operands[i].mode;
627
628 if ((op & (DISP | REG)) == (DISP | REG)
629 && ((x & (DISP | REG)) == (DISP | REG)))
630 {
631 dispreg = operands[i].reg;
632 }
633 else if (op & REG)
634 {
635 if (!(x & REG))
636 found = 0;
637
638 if (x & L_P)
639 {
640 x = (x & ~L_P) | (Hmode ? L_32 : L_16);
641 }
642 if (op & L_P)
643 {
644 op = (op & ~L_P) | (Hmode ? L_32 : L_16);
645 }
646
647 opsize = op & SIZE;
648
649 /* The size of the reg is v important */
650 if ((op & SIZE) != (x & SIZE))
651 found = 0;
652 }
653 else if ((op & ABSJMP) && (x & ABS))
654 {
655 operands[i].mode &= ~ABS;
656 operands[i].mode |= ABSJMP;
657 /* But it may not be 24 bits long */
658 if (!Hmode)
659 {
660 operands[i].mode &= ~SIZE;
661 operands[i].mode |= L_16;
662 }
663
664
665 }
666 else if ((op & (KBIT | DBIT)) && (x & IMM))
667 {
668 /* This is ok if the immediate value is sensible */
669
670 }
671 else if (op & PCREL)
672 {
673
674 /* The size of the displacement is important */
675 if ((op & SIZE) != (x & SIZE))
676 found = 0;
677
678 }
679 else if ((op & (DISP | IMM | ABS))
680 && (op & (DISP | IMM | ABS)) == (x & (DISP | IMM | ABS)))
681 {
682 /* Got a diplacement,will fit if no size or same size as try */
683 if (op & ABS && op & L_8)
684 {
685 /* We want an 8 bit abs here, but one which looks like 16 bits will do fine */
686 if (x & L_16)
687 found= 1;
688 }
689 else
690 if ((x & SIZE) != 0
691 && ((op & SIZE) != (x & SIZE)))
692 found = 0;
693 }
694 else if ((op & MODE) != (x & MODE))
695 {
696 found = 0;
697 }
698
699 }
700 }
701 if (found)
702 return this_try;
703 else
704 return 0;
705 }
706
707 static void
708 check_operand (operand, width, string)
709 struct h8_op *operand;
710 unsigned int width;
711 char *string;
712 {
713 if (operand->exp.X_add_symbol == 0
714 && operand->exp.X_op_symbol == 0)
715 {
716
717 /* No symbol involved, let's look at offset, it's dangerous if any of
718 the high bits are not 0 or ff's, find out by oring or anding with
719 the width and seeing if the answer is 0 or all fs*/
720
721 if ((operand->exp.X_add_number & ~width) != 0 &&
722 (operand->exp.X_add_number | width) != (~0))
723 {
724 if (width == 255
725 && (operand->exp.X_add_number & 0xff00) == 0xff00)
726 {
727 /* Just ignore this one - which happens when trying to
728 fit a 16 bit address truncated into an 8 bit address
729 of something like bset. */
730 }
731 else
732 {
733 as_warn ("operand %s0x%lx out of range.", string,
734 (unsigned long) operand->exp.X_add_number);
735 }
736 }
737 }
738
739 }
740
741 static void
742 do_a_fix_imm (offset, operand, relaxing)
743 int offset;
744 struct h8_op *operand;
745 int relaxing;
746 {
747 int idx;
748 int size;
749 int where;
750
751
752 char *t = operand->mode & IMM ? "#" : "@";
753
754 if (operand->exp.X_add_symbol == 0)
755 {
756 char *bytes = frag_now->fr_literal + offset;
757 switch (operand->mode & SIZE)
758 {
759 case L_2:
760 check_operand (operand, 0x3, t);
761 bytes[0] |= (operand->exp.X_add_number) << 4;
762 break;
763 case L_3:
764 check_operand (operand, 0x7, t);
765 bytes[0] |= (operand->exp.X_add_number) << 4;
766 break;
767 case L_8:
768 check_operand (operand, 0xff, t);
769 bytes[0] = operand->exp.X_add_number;
770 break;
771 case L_16:
772 check_operand (operand, 0xffff, t);
773 bytes[0] = operand->exp.X_add_number >> 8;
774 bytes[1] = operand->exp.X_add_number >> 0;
775 break;
776 case L_24:
777 check_operand (operand, 0xffffff, t);
778 bytes[0] = operand->exp.X_add_number >> 16;
779 bytes[1] = operand->exp.X_add_number >> 8;
780 bytes[2] = operand->exp.X_add_number >> 0;
781 break;
782
783 case L_32:
784 /* This should be done with bfd */
785 bytes[0] = operand->exp.X_add_number >> 24;
786 bytes[1] = operand->exp.X_add_number >> 16;
787 bytes[2] = operand->exp.X_add_number >> 8;
788 bytes[3] = operand->exp.X_add_number >> 0;
789 break;
790 }
791
792 }
793 else
794 {
795 switch (operand->mode & SIZE)
796 {
797
798 case L_24:
799 size = 4;
800 where = -1;
801 idx = relaxing ? R_MOVLB1 : R_RELLONG;
802 break;
803 default:
804 as_bad("Can't work out size of operand.\n");
805 case L_32:
806 size = 4;
807 where = 0;
808 idx = R_RELLONG;
809 break;
810 case L_16:
811 size = 2;
812 where = 0;
813 idx = relaxing ? R_MOVB1 : R_RELWORD;
814 break;
815 case L_8:
816 size = 1;
817 where = 0;
818 idx = R_RELBYTE;
819 }
820
821 /* Sign extend any expression */
822 operand->exp.X_add_number = (short)operand->exp.X_add_number;
823 fix_new_exp (frag_now,
824 offset + where,
825 size,
826 &operand->exp,
827 0,
828 idx);
829 }
830
831 }
832
833 /* Now we know what sort of opcodes it is, lets build the bytes -
834 */
835 static void
836 build_bytes (this_try, operand)
837 struct h8_opcode *this_try;
838 struct h8_op *operand;
839 {
840 unsigned int i;
841
842 char *output = frag_more (this_try->length);
843 op_type *nibble_ptr = this_try->data.nib;
844 op_type c;
845 unsigned int nibble_count = 0;
846 int absat;
847 int immat;
848 int nib;
849 char asnibbles[30];
850 char *p = asnibbles;
851
852 if (!(this_try->inbase || Hmode))
853 {
854 as_warn ("Opcode `%s' only available in this mode on H8/300-H",
855 this_try->name);
856 }
857
858 while (*nibble_ptr != E)
859 {
860 int d;
861 c = *nibble_ptr++;
862
863 d = (c & DST) != 0;
864
865 if (c < 16)
866 {
867 nib = c;
868 }
869 else
870 {
871
872 if (c & (REG | IND | INC | DEC))
873 {
874 nib = operand[d].reg;
875 }
876 else if ((c & DISPREG) == (DISPREG))
877 {
878 nib = dispreg;
879 }
880 else if (c & ABS )
881 {
882 operand[d].mode = c;
883 absat = nibble_count / 2;
884 nib = 0;
885 }
886 else if (c & (IMM | PCREL | ABS | ABSJMP | DISP))
887 {
888 operand[d].mode = c;
889 immat = nibble_count / 2;
890 nib = 0;
891 }
892 else if (c & IGNORE)
893 {
894 nib = 0;
895 }
896 else if (c & DBIT)
897 {
898 switch (operand[0].exp.X_add_number)
899 {
900 case 1:
901 nib = c;
902 break;
903 case 2:
904 nib = 0x8 | c;
905 break;
906 default:
907 as_bad ("Need #1 or #2 here");
908 }
909 }
910 else if (c & KBIT)
911 {
912 switch (operand[0].exp.X_add_number)
913 {
914 case 1:
915 nib = 0;
916 break;
917 case 2:
918 nib = 8;
919 break;
920 case 4:
921 if (!Hmode)
922 as_warn ("#4 only valid in h8/300 mode.");
923 nib = 9;
924 break;
925
926 default:
927 as_bad ("Need #1 or #2 here");
928 break;
929 }
930 /* stop it making a fix */
931 operand[0].mode = 0;
932 }
933
934 if (c & B31)
935 {
936 nib |= 0x8;
937 }
938 }
939 nibble_count++;
940
941 *p++ = nib;
942 }
943
944 for (i = 0; i < this_try->length; i++)
945 {
946 output[i] = (asnibbles[i * 2] << 4) | asnibbles[i * 2 + 1];
947 }
948
949 /* output any fixes */
950 for (i = 0; i < 2; i++)
951 {
952 int x = operand[i].mode;
953
954 if (x & (IMM | DISP))
955 {
956 do_a_fix_imm (output - frag_now->fr_literal + immat, operand + i, 0);
957 }
958 else if (x & ABS)
959 {
960 do_a_fix_imm (output - frag_now->fr_literal + absat, operand + i, 0);
961 }
962 else if (x & PCREL)
963 {
964 int size16 = x & L_16;
965 int where = size16 ? 2 : 1;
966 int size = size16 ? 2 : 1;
967 int type = size16 ? R_PCRWORD : R_PCRBYTE;
968
969 check_operand (operand + i, size16 ? 0x7fff : 0x7f, "@");
970
971 if (operand[i].exp.X_add_number & 1)
972 {
973 as_warn ("branch operand has odd offset (%lx)\n",
974 (unsigned long) operand->exp.X_add_number);
975 }
976
977 operand[i].exp.X_add_number =
978 (char) (operand[i].exp.X_add_number - 1);
979 fix_new_exp (frag_now,
980 output - frag_now->fr_literal + where,
981 size,
982 &operand[i].exp,
983 1,
984 type);
985 }
986 else if (x & MEMIND)
987 {
988
989 check_operand (operand + i, 0xff, "@@");
990 fix_new_exp (frag_now,
991 output - frag_now->fr_literal + 1,
992 1,
993 &operand[i].exp,
994 0,
995 R_MEM_INDIRECT);
996 }
997 else if (x & ABSJMP)
998 {
999 /* This jmp may be a jump or a branch */
1000
1001 check_operand (operand + i, Hmode ? 0xffffff : 0xffff, "@");
1002 if (operand[i].exp.X_add_number & 1)
1003 {
1004 as_warn ("branch operand has odd offset (%lx)\n",
1005 (unsigned long) operand->exp.X_add_number);
1006 }
1007 if (!Hmode)
1008 operand[i].exp.X_add_number = (short) operand[i].exp.X_add_number;
1009 fix_new_exp (frag_now,
1010 output - frag_now->fr_literal,
1011 4,
1012 &operand[i].exp,
1013 0,
1014 R_JMPL1);
1015 }
1016 }
1017
1018 }
1019
1020 /*
1021 try and give an intelligent error message for common and simple to
1022 detect errors
1023 */
1024
1025 static void
1026 clever_message (opcode, operand)
1027 struct h8_opcode *opcode;
1028 struct h8_op *operand;
1029 {
1030 /* Find out if there was more than one possible opccode */
1031
1032 if ((opcode + 1)->idx != opcode->idx)
1033 {
1034 unsigned int argn;
1035
1036 /* Only one opcode of this flavour, try and guess which operand
1037 didn't match */
1038 for (argn = 0; argn < opcode->noperands; argn++)
1039 {
1040 switch (opcode->args.nib[argn])
1041 {
1042 case RD16:
1043 if (operand[argn].mode != RD16)
1044 {
1045 as_bad ("destination operand must be 16 bit register");
1046 return;
1047
1048 }
1049 break;
1050
1051 case RS8:
1052
1053 if (operand[argn].mode != RS8)
1054 {
1055 as_bad ("source operand must be 8 bit register");
1056 return;
1057 }
1058 break;
1059
1060 case ABS16DST:
1061 if (operand[argn].mode != ABS16DST)
1062 {
1063 as_bad ("destination operand must be 16bit absolute address");
1064 return;
1065 }
1066 break;
1067 case RD8:
1068 if (operand[argn].mode != RD8)
1069 {
1070 as_bad ("destination operand must be 8 bit register");
1071 return;
1072 }
1073 break;
1074
1075
1076 case ABS16SRC:
1077 if (operand[argn].mode != ABS16SRC)
1078 {
1079 as_bad ("source operand must be 16bit absolute address");
1080 return;
1081 }
1082 break;
1083
1084 }
1085 }
1086 }
1087 as_bad ("invalid operands");
1088 }
1089
1090 /* This is the guts of the machine-dependent assembler. STR points to a
1091 machine dependent instruction. This funciton is supposed to emit
1092 the frags/bytes it assembles to.
1093 */
1094
1095
1096
1097 void
1098 md_assemble (str)
1099 char *str;
1100 {
1101 char *op_start;
1102 char *op_end;
1103 struct h8_op operand[2];
1104 struct h8_opcode *opcode;
1105 struct h8_opcode *prev_opcode;
1106
1107 char *dot = 0;
1108 char c;
1109
1110 /* Drop leading whitespace */
1111 while (*str == ' ')
1112 str++;
1113
1114 /* find the op code end */
1115 for (op_start = op_end = str;
1116 *op_end != 0 && *op_end != ' ';
1117 op_end++)
1118 {
1119 if (*op_end == '.')
1120 {
1121 dot = op_end + 1;
1122 *op_end = 0;
1123 op_end += 2;
1124 break;
1125 }
1126 }
1127
1128 ;
1129
1130 if (op_end == op_start)
1131 {
1132 as_bad ("can't find opcode ");
1133 }
1134 c = *op_end;
1135
1136 *op_end = 0;
1137
1138 opcode = (struct h8_opcode *) hash_find (opcode_hash_control,
1139 op_start);
1140
1141 if (opcode == NULL)
1142 {
1143 as_bad ("unknown opcode");
1144 return;
1145 }
1146
1147 /* We use to set input_line_pointer to the result of get_operands,
1148 but that is wrong. Our caller assumes we don't change it. */
1149
1150 (void) get_operands (opcode->noperands, op_end, operand);
1151 *op_end = c;
1152 prev_opcode = opcode;
1153
1154 opcode = get_specific (opcode, operand);
1155
1156 if (opcode == 0)
1157 {
1158 /* Couldn't find an opcode which matched the operands */
1159 char *where = frag_more (2);
1160
1161 where[0] = 0x0;
1162 where[1] = 0x0;
1163 clever_message (prev_opcode, operand);
1164
1165 return;
1166 }
1167 if (opcode->size && dot)
1168 {
1169 if (opcode->size != *dot)
1170 {
1171 as_warn ("mismatch between opcode size and operand size");
1172 }
1173 }
1174
1175 build_bytes (opcode, operand);
1176
1177 }
1178
1179 void
1180 tc_crawl_symbol_chain (headers)
1181 object_headers * headers;
1182 {
1183 printf ("call to tc_crawl_symbol_chain \n");
1184 }
1185
1186 symbolS *
1187 md_undefined_symbol (name)
1188 char *name;
1189 {
1190 return 0;
1191 }
1192
1193 void
1194 tc_headers_hook (headers)
1195 object_headers * headers;
1196 {
1197 printf ("call to tc_headers_hook \n");
1198 }
1199
1200 /* Various routines to kill one day */
1201 /* Equal to MAX_PRECISION in atof-ieee.c */
1202 #define MAX_LITTLENUMS 6
1203
1204 /* Turn a string in input_line_pointer into a floating point constant of type
1205 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1206 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1207 */
1208 char *
1209 md_atof (type, litP, sizeP)
1210 char type;
1211 char *litP;
1212 int *sizeP;
1213 {
1214 int prec;
1215 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1216 LITTLENUM_TYPE *wordP;
1217 char *t;
1218 char *atof_ieee ();
1219
1220 switch (type)
1221 {
1222 case 'f':
1223 case 'F':
1224 case 's':
1225 case 'S':
1226 prec = 2;
1227 break;
1228
1229 case 'd':
1230 case 'D':
1231 case 'r':
1232 case 'R':
1233 prec = 4;
1234 break;
1235
1236 case 'x':
1237 case 'X':
1238 prec = 6;
1239 break;
1240
1241 case 'p':
1242 case 'P':
1243 prec = 6;
1244 break;
1245
1246 default:
1247 *sizeP = 0;
1248 return "Bad call to MD_ATOF()";
1249 }
1250 t = atof_ieee (input_line_pointer, type, words);
1251 if (t)
1252 input_line_pointer = t;
1253
1254 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1255 for (wordP = words; prec--;)
1256 {
1257 md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1258 litP += sizeof (LITTLENUM_TYPE);
1259 }
1260 return 0;
1261 }
1262 \f
1263 CONST char *md_shortopts = "";
1264 struct option md_longopts[] = {
1265 {NULL, no_argument, NULL, 0}
1266 };
1267 size_t md_longopts_size = sizeof(md_longopts);
1268
1269 int
1270 md_parse_option (c, arg)
1271 int c;
1272 char *arg;
1273 {
1274 return 0;
1275 }
1276
1277 void
1278 md_show_usage (stream)
1279 FILE *stream;
1280 {
1281 }
1282 \f
1283 int md_short_jump_size;
1284
1285 void
1286 tc_aout_fix_to_chars ()
1287 {
1288 printf ("call to tc_aout_fix_to_chars \n");
1289 abort ();
1290 }
1291
1292 void
1293 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1294 char *ptr;
1295 addressT from_addr;
1296 addressT to_addr;
1297 fragS *frag;
1298 symbolS *to_symbol;
1299 {
1300 as_fatal ("failed sanity check.");
1301 }
1302
1303 void
1304 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1305 char *ptr;
1306 addressT from_addr, to_addr;
1307 fragS *frag;
1308 symbolS *to_symbol;
1309 {
1310 as_fatal ("failed sanity check.");
1311 }
1312
1313 void
1314 md_convert_frag (headers, seg, fragP)
1315 object_headers *headers;
1316 segT seg;
1317 fragS *fragP;
1318 {
1319 printf ("call to md_convert_frag \n");
1320 abort ();
1321 }
1322
1323 valueT
1324 md_section_align (seg, size)
1325 segT seg;
1326 valueT size;
1327 {
1328 return ((size + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
1329
1330 }
1331
1332 void
1333 md_apply_fix (fixP, val)
1334 fixS *fixP;
1335 long val;
1336 {
1337 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1338
1339 switch (fixP->fx_size)
1340 {
1341 case 1:
1342 *buf++ = val;
1343 break;
1344 case 2:
1345 *buf++ = (val >> 8);
1346 *buf++ = val;
1347 break;
1348 case 4:
1349 *buf++ = (val >> 24);
1350 *buf++ = (val >> 16);
1351 *buf++ = (val >> 8);
1352 *buf++ = val;
1353 break;
1354 default:
1355 abort ();
1356 }
1357 }
1358
1359 int md_long_jump_size;
1360
1361 int
1362 md_estimate_size_before_relax (fragP, segment_type)
1363 register fragS *fragP;
1364 register segT segment_type;
1365 {
1366 printf ("call tomd_estimate_size_before_relax \n");
1367 abort ();
1368 }
1369
1370 /* Put number into target byte order */
1371
1372 void
1373 md_number_to_chars (ptr, use, nbytes)
1374 char *ptr;
1375 valueT use;
1376 int nbytes;
1377 {
1378 number_to_chars_bigendian (ptr, use, nbytes);
1379 }
1380 long
1381 md_pcrel_from (fixP)
1382 fixS *fixP;
1383 {
1384 abort ();
1385 }
1386
1387
1388 void
1389 tc_reloc_mangle (fix_ptr, intr, base)
1390 fixS *fix_ptr;
1391 struct internal_reloc *intr;
1392 bfd_vma base;
1393
1394 {
1395 symbolS *symbol_ptr;
1396
1397 symbol_ptr = fix_ptr->fx_addsy;
1398
1399 /* If this relocation is attached to a symbol then it's ok
1400 to output it */
1401 if (fix_ptr->fx_r_type == TC_CONS_RELOC)
1402 {
1403 /* cons likes to create reloc32's whatever the size of the reloc..
1404 */
1405 switch (fix_ptr->fx_size)
1406 {
1407 case 4:
1408 intr->r_type = R_RELLONG;
1409 break;
1410 case 2:
1411 intr->r_type = R_RELWORD;
1412 break;
1413 case 1:
1414 intr->r_type = R_RELBYTE;
1415 break;
1416 default:
1417 abort ();
1418
1419 }
1420
1421 }
1422 else
1423 {
1424 intr->r_type = fix_ptr->fx_r_type;
1425 }
1426
1427 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1428 intr->r_offset = fix_ptr->fx_offset;
1429
1430 if (symbol_ptr)
1431 intr->r_symndx = symbol_ptr->sy_number;
1432 else
1433 intr->r_symndx = -1;
1434
1435
1436 }
1437
1438 /* end of tc-h8300.c */
This page took 0.061694 seconds and 4 git commands to generate.