CVS says it was empty, so refresh it.
[deliverable/binutils-gdb.git] / gas / config / tc-h8300.c
1 /* tc-h8300.c -- Assemble code for the Hitachi h8/300
2 Copyright (C) 1991 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, 675 Mass Ave, Cambridge, MA 02139, 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 #include "opcode/h8300.h"
30 #include <ctype.h>
31 #include "listing.h"
32
33 char comment_chars[] = { ';',0 };
34 char line_separator_chars[] = { '$' ,0};
35
36 /* This table describes all the machine specific pseudo-ops the assembler
37 has to support. The fields are:
38 pseudo-op name without dot
39 function to call to execute this pseudo-op
40 Integer arg to pass to the function
41 */
42
43 void cons();
44
45 const pseudo_typeS md_pseudo_table[] = {
46 { "int", cons, 2 },
47 { 0,0,0 }
48 };
49
50 int md_reloc_size ;
51
52 const char EXP_CHARS[] = "eE";
53
54 /* Chars that mean this number is a floating point constant */
55 /* As in 0f12.456 */
56 /* or 0d1.2345e12 */
57 char FLT_CHARS[] = "rRsSfFdDxXpP";
58
59
60 const relax_typeS md_relax_table[1];
61
62
63 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
64
65
66 /*
67 This function is called once, at assembler startup time. This should
68 set up all the tables, etc that the MD part of the assembler needs
69 */
70
71 /* encode the size and number into the number field
72 xxnnnn
73 00 8 bit
74 01 16 bit
75 10 ccr
76 nnnnreg number
77 */
78 #define WORD_REG 0x10
79 #define BYTE_REG 0x00
80 #define CCR_REG 0x20
81 struct reg_entry
82 {
83 char *name;
84 char number;
85 };
86
87 struct reg_entry reg_list[] = {
88 "r0",WORD_REG +0,
89 "r1",WORD_REG +1,
90 "r2",WORD_REG +2,
91 "r3",WORD_REG +3,
92 "r4",WORD_REG +4,
93 "r5",WORD_REG +5,
94 "r6",WORD_REG +6,
95 "r7",WORD_REG +7,
96 "fp",WORD_REG +6,
97 "sp",WORD_REG +7,
98 "r0h",BYTE_REG + 0,
99 "r0l",BYTE_REG + 1,
100 "r1h",BYTE_REG + 2,
101 "r1l",BYTE_REG + 3,
102 "r2h",BYTE_REG + 4,
103 "r2l",BYTE_REG + 5,
104 "r3h",BYTE_REG + 6,
105 "r3l",BYTE_REG + 7,
106 "r4h",BYTE_REG + 8,
107 "r4l",BYTE_REG + 9,
108 "r5h",BYTE_REG + 10,
109 "r5l",BYTE_REG + 11,
110 "r6h",BYTE_REG + 12,
111 "r6l",BYTE_REG + 13,
112 "r7h",BYTE_REG + 14,
113 "r7l",BYTE_REG + 15,
114 "ccr",CCR_REG,
115 0,0
116 }
117 ;
118
119
120
121
122
123 void md_begin ()
124 {
125 struct h8_opcode *opcode;
126 const struct reg_entry *reg;
127 char prev_buffer[100];
128 int idx = 0;
129
130 opcode_hash_control = hash_new();
131 prev_buffer[0] = 0;
132
133 for (opcode = h8_opcodes; opcode->name; opcode++)
134 {
135 /* Strip off any . part when inserting the opcode and only enter
136 unique codes into the hash table
137 */
138 char *src= opcode->name;
139 unsigned int len = strlen(src);
140 char *dst = malloc(len+1);
141 char *buffer = dst;
142 opcode->size = 0;
143 while (*src) {
144 if (*src == '.') {
145 *dst++ = 0;
146 src++;
147 opcode->size = *src;
148 break;
149 }
150 *dst++ = *src++;
151 }
152 if (strcmp(buffer, prev_buffer))
153 {
154 hash_insert(opcode_hash_control, buffer, (char *)opcode);
155 strcpy(prev_buffer, buffer);
156 idx++;
157 }
158 opcode->idx = idx;
159
160
161 /* Find the number of operands */
162 opcode->noperands = 0;
163 while (opcode->args.nib[opcode->noperands] != E)
164 opcode->noperands ++;
165 /* Find the length of the opcode in bytes */
166 opcode->length =0;
167 while (opcode->data.nib[opcode->length*2] != E)
168 opcode->length++;
169 }
170
171 }
172
173
174 struct h8_exp {
175 char *e_beg;
176 char *e_end;
177 expressionS e_exp;
178 };
179 struct h8_op
180 {
181 unsigned int dispreg;
182 op_type mode;
183 unsigned reg;
184 expressionS exp;
185 };
186
187
188
189 /*
190 parse operands
191 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
192 r0l,r0h,..r7l,r7h
193 @WREG
194 @WREG+
195 @-WREG
196 #const
197
198 */
199
200 op_type r8_sord[] = {RS8, RD8};
201 op_type r16_sord[] = {RS16, RD16};
202 op_type rind_sord[] = {RSIND, RDIND};
203 op_type abs_sord[2] = {ABS16SRC, ABS16DST};
204 op_type disp_sord[] = {DISPSRC, DISPDST};
205
206 /* try and parse a reg name, returns number of chars consumed */
207 int
208 DEFUN(parse_reg,(src, mode, reg, dst),
209 char *src AND
210 op_type *mode AND
211 unsigned int *reg AND
212 int dst)
213 {
214 if (src[0] == 's' && src[1] == 'p')
215 {
216 *mode = r16_sord[dst];
217 *reg = 7;
218 return 2;
219 }
220 if (src[0] == 'c' && src[1] == 'c' && src[2] == 'r')
221 {
222 *mode = CCR;
223 *reg = 0;
224 return 3;
225 }
226 if (src[0] == 'f' && src[1] == 'p')
227 {
228 *mode = r16_sord[dst];
229 *reg = 6;
230 return 2;
231 }
232 if (src[0] == 'r')
233 {
234 if (src[1] >= '0' && src[1] <= '7')
235 {
236 if(src[2] == 'l')
237 {
238 *mode = r8_sord[dst];
239 *reg = (src[1] - '0') + 8;
240 return 3;
241 }
242 if(src[2] == 'h')
243 {
244 *mode = r8_sord[dst];
245 *reg = (src[1] - '0') ;
246 return 3;
247 }
248 *mode = r16_sord[dst];
249 *reg = (src[1] - '0');
250 return 2;
251 }
252 }
253 return 0;
254 }
255
256 char *
257 DEFUN(parse_exp,(s, op),
258 char *s AND
259 expressionS *op)
260 {
261 char *save = input_line_pointer;
262 char *new;
263 segT seg;
264 input_line_pointer = s;
265 seg = expr(0,op);
266 new = input_line_pointer;
267 input_line_pointer = save;
268 if (SEG_NORMAL(seg))
269 return new;
270 switch (seg) {
271 case SEG_ABSOLUTE:
272 case SEG_UNKNOWN:
273 case SEG_DIFFERENCE:
274 case SEG_BIG:
275 case SEG_REGISTER:
276 return new;
277 case SEG_ABSENT:
278 as_bad("Missing operand");
279 return new;
280 default:
281 as_bad("Don't understand operand of type %s", segment_name (seg));
282 return new;
283 }
284 }
285
286 static char *
287 DEFUN(skip_colonthing,(ptr),
288 char *ptr)
289 {
290 if (*ptr == ':') {
291 ptr++;
292 while (isdigit(*ptr))
293 ptr++;
294
295 }
296 return ptr;
297 }
298
299 /* The many forms of operand:
300
301 Rn Register direct
302 @Rn Register indirect
303 @(exp[:16], Rn) Register indirect with displacement
304 @Rn+
305 @-Rn
306 @aa:8 absolute 8 bit
307 @aa:16 absolute 16 bit
308 @aa absolute 16 bit
309
310 #xx[:size] immediate data
311 @(exp:[8], pc) pc rel
312 @@aa[:8] memory indirect
313
314 */
315
316 static void
317 DEFUN(get_operand,(ptr, op, dst),
318 char **ptr AND
319 struct h8_op *op AND
320 unsigned int dst)
321 {
322 char *src = *ptr;
323 op_type mode;
324 unsigned int num;
325 unsigned int len;
326 unsigned int size;
327 op->mode = E;
328
329 len = parse_reg(src, &op->mode, &op->reg, dst);
330 if (len) {
331 *ptr = src + len;
332 return ;
333 }
334
335 if (*src == '@')
336 {
337 src++;
338 if (*src == '@')
339 {
340 src++;
341 src = parse_exp(src,&op->exp);
342 src = skip_colonthing(src);
343
344 *ptr = src;
345
346 op->mode = MEMIND;
347 return;
348
349 }
350
351
352 if (*src == '-')
353 {
354 src++;
355 len = parse_reg(src, &mode, &num, dst);
356 if (len == 0 || mode != r16_sord[dst])
357 {
358 as_bad("@- needs word register");
359 }
360 op->mode = RDDEC;
361 op->reg = num;
362 *ptr = src + len;
363 return;
364 }
365 if (*src == '(' && ')')
366 {
367 /* Disp */
368 src++;
369 src = parse_exp(src, &op->exp);
370
371 if (*src == ')')
372 {
373 src++;
374 op->mode = abs_sord[dst];
375 *ptr = src;
376 return;
377 }
378 src = skip_colonthing(src);
379
380 if (*src != ',')
381 {
382 as_bad("expected @(exp, reg16)");
383 }
384 src++;
385 len = parse_reg(src, &mode, &op->reg, dst);
386 if (len == 0 || mode != r16_sord[dst])
387 {
388 as_bad("expected @(exp, reg16)");
389 }
390 op->mode = disp_sord[dst];
391 src += len;
392 src = skip_colonthing(src);
393
394 if (*src != ')' && '(')
395 {
396 as_bad("expected @(exp, reg16)");
397
398 }
399 *ptr = src +1;
400
401 return;
402 }
403 len = parse_reg(src, &mode, &num, dst);
404
405 if(len) {
406 src += len;
407 if (*src == '+')
408 {
409 src++;
410 if (mode != RS16)
411 {
412 as_bad("@Rn+ needs src word register");
413 }
414 op->mode = RSINC;
415 op->reg = num;
416 *ptr = src;
417 return;
418 }
419 if (mode != r16_sord[dst])
420 {
421 as_bad("@Rn needs word register");
422 }
423 op->mode =rind_sord[dst];
424 op->reg = num;
425 *ptr = src;
426 return;
427 }
428 else
429 {
430 /* must be a symbol */
431 op->mode = abs_sord[dst];
432 *ptr = skip_colonthing(parse_exp(src, &op->exp));
433
434 return;
435 }
436 }
437
438
439 if (*src == '#') {
440 src++;
441 op->mode = IMM16;
442 src = parse_exp(src, &op->exp);
443 *ptr= skip_colonthing(src);
444
445 return;
446 }
447 else {
448 *ptr = parse_exp(src, &op->exp);
449 op->mode = DISP8;
450 }
451 }
452
453
454 static
455 char *
456 DEFUN(get_operands,(noperands,op_end, operand),
457 unsigned int noperands AND
458 char *op_end AND
459 struct h8_op *operand)
460 {
461 char *ptr = op_end;
462 switch (noperands)
463 {
464 case 0:
465 operand[0].mode = 0;
466 operand[1].mode = 0;
467 break;
468
469 case 1:
470 ptr++;
471 get_operand(& ptr, operand +0,0);
472 operand[1].mode =0;
473 break;
474
475 case 2:
476 ptr++;
477 get_operand(& ptr, operand +0,0);
478 if (*ptr == ',') ptr++;
479 get_operand(& ptr, operand +1, 1);
480 break;
481
482 default:
483 abort();
484 }
485
486
487 return ptr;
488 }
489
490 /* Passed a pointer to a list of opcodes which use different
491 addressing modes, return the opcode which matches the opcodes
492 provided
493 */
494 static
495 struct h8_opcode *
496 DEFUN(get_specific,(opcode, operands),
497 struct h8_opcode *opcode AND
498 struct h8_op *operands)
499
500 {
501 struct h8_opcode *this_try = opcode ;
502 int found = 0;
503 unsigned int noperands = opcode->noperands;
504
505 unsigned int dispreg;
506 unsigned int this_index = opcode->idx;
507 while (this_index == opcode->idx && !found)
508 {
509 unsigned int i;
510
511 this_try = opcode ++;
512 for (i = 0; i < noperands; i++)
513 {
514 op_type op = (this_try->args.nib[i]) & ~(B30|B31);
515 switch (op)
516 {
517 case Hex0:
518 case Hex1:
519 case Hex2:
520 case Hex3:
521 case Hex4:
522 case Hex5:
523 case Hex6:
524 case Hex7:
525 case Hex8:
526 case Hex9:
527 case HexA:
528 case HexB:
529 case HexC:
530 case HexD:
531 case HexE:
532 case HexF:
533 break;
534 case DISPSRC:
535 case DISPDST:
536 operands[0].dispreg = operands[i].reg;
537 case RD8:
538 case RS8:
539 case RDIND:
540 case RSIND:
541 case RD16:
542 case RS16:
543 case CCR:
544 case RSINC:
545 case RDDEC:
546 if (operands[i].mode != op) goto fail;
547 break;
548 case KBIT:
549 case IMM16:
550 case IMM3:
551 case IMM8:
552 if (operands[i].mode != IMM16) goto fail;
553 break;
554 case MEMIND:
555 if (operands[i].mode != MEMIND) goto fail;
556 break;
557 case ABS16SRC:
558 case ABS8SRC:
559 case ABS16OR8SRC:
560 case ABS16ORREL8SRC:
561
562 if (operands[i].mode != ABS16SRC) goto fail;
563 break;
564 case ABS16OR8DST:
565 case ABS16DST:
566 case ABS8DST:
567 if (operands[i].mode != ABS16DST) goto fail;
568 break;
569 }
570 }
571 found =1;
572 fail: ;
573 }
574 if (found)
575 return this_try;
576 else
577 return 0;
578 }
579
580 static void
581 DEFUN(check_operand,(operand, width, string),
582 struct h8_op *operand AND
583 unsigned int width AND
584 char *string)
585 {
586 if (operand->exp.X_add_symbol == 0
587 && operand->exp.X_subtract_symbol == 0)
588 {
589
590 /* No symbol involved, let's look at offset, it's dangerous if any of
591 the high bits are not 0 or ff's, find out by oring or anding with
592 the width and seeing if the answer is 0 or all fs*/
593 if ((operand->exp.X_add_number | width) != ~0 &&
594 (operand->exp.X_add_number & ~width)!= 0)
595 {
596 as_warn("operand %s0x%x out of range.", string, operand->exp.X_add_number);
597 }
598 }
599
600 }
601
602 /* Now we know what sort of opcodes it is, lets build the bytes -
603 */
604 static void
605 DEFUN (build_bytes,(this_try, operand),
606 struct h8_opcode *this_try AND
607 struct h8_op *operand)
608
609 {
610 unsigned int i;
611
612 char *output = frag_more(this_try->length);
613 char *output_ptr = output;
614 op_type *nibble_ptr = this_try->data.nib;
615 char part;
616 op_type c;
617 char high;
618 int nib;
619 top: ;
620 while (*nibble_ptr != E)
621 {
622 int nibble;
623 for (nibble = 0; nibble <2; nibble++)
624 {
625 c = *nibble_ptr & ~(B30|B31);
626 switch (c)
627 {
628 default:
629 abort();
630 case KBIT:
631 switch (operand[0].exp.X_add_number)
632 {
633 case 1:
634 nib = 0;
635 break;
636 case 2:
637 nib = 8;
638 break;
639 default:
640 as_bad("Need #1 or #2 here");
641 break;
642 }
643 /* stop it making a fix */
644 operand[0].mode = 0;
645 break;
646 case 0:
647 case 1:
648 case 2: case 3: case 4: case 5: case 6:
649 case 7: case 8: case 9: case 10: case 11:
650 case 12: case 13: case 14: case 15:
651 nib = c;
652 break;
653 case DISPREG:
654 nib = operand[0].dispreg;
655 break;
656 case IMM8:
657 operand[0].mode = IMM8;
658 nib = 0;
659 break;
660
661 case DISPDST:
662 nib = 0;
663 break;
664 case IMM3:
665 if (operand[0].exp.X_add_symbol == 0) {
666 operand[0].mode = 0; /* stop it making a fix */
667 nib = (operand[0].exp.X_add_number);
668 }
669 else as_bad("can't have symbol for bit number");
670 if (nib < 0 || nib > 7)
671 {
672 as_bad("Bit number out of range %d", nib);
673 }
674
675 break;
676
677 case ABS16DST:
678 nib = 0;
679 break;
680 case ABS8DST:
681 operand[1].mode = ABS8DST;
682 nib = 0;
683 break;
684 case ABS8SRC:
685 operand[0].mode = ABS8SRC;
686 nib = 0;
687 break;
688 case ABS16OR8DST:
689 operand[1].mode = c;
690
691 nib = 0;
692
693 break;
694
695 case ABS16ORREL8SRC:
696 operand[0].mode = c;
697 nib=0;
698 break;
699
700 case ABS16OR8SRC:
701 operand[0].mode = ABS16OR8SRC;
702 nib = 0;
703 break;
704 case DISPSRC:
705 operand[0].mode = ABS16SRC;
706 nib = 0;
707 break;
708
709 case DISP8:
710 operand[0].mode = DISP8;
711 nib = 0;
712 break;
713
714 case ABS16SRC:
715 case IMM16:
716 case IGNORE:
717 case MEMIND:
718
719 nib=0;
720 break;
721 case RS8:
722 case RS16:
723 case RSIND:
724 case RSINC:
725 nib = operand[0].reg;
726 break;
727
728 case RD8:
729 case RD16:
730 case RDDEC:
731 case RDIND:
732 nib = operand[1].reg;
733 break;
734
735 case E:
736 abort();
737 break;
738 }
739 if (*nibble_ptr & B31) {
740 nib |=0x8;
741 }
742
743 if (nibble == 0) {
744 *output_ptr = nib << 4;
745 }
746 else {
747 *output_ptr |= nib;
748 output_ptr++;
749 }
750 nibble_ptr++;
751 }
752
753 }
754
755 /* output any fixes */
756 for (i = 0; i < 2; i++)
757 {
758 switch (operand[i].mode) {
759 case 0:
760 break;
761
762 case DISP8:
763 check_operand(operand+i, 0x7f,"@");
764
765 fix_new(frag_now,
766 output - frag_now->fr_literal + 1,
767 1,
768 operand[i].exp.X_add_symbol,
769 operand[i].exp.X_subtract_symbol,
770 operand[i].exp.X_add_number -1,
771 1,
772 R_PCRBYTE);
773 break;
774 case IMM8:
775 check_operand(operand+i, 0xff,"#");
776 /* If there is nothing else going on we can safely
777 reloc in place */
778 if (operand[i].exp.X_add_symbol == 0)
779 {
780 output[1] = operand[i].exp.X_add_number;
781 }
782 else
783 {
784 fix_new(frag_now,
785 output - frag_now->fr_literal + 1,
786 1,
787 operand[i].exp.X_add_symbol,
788 operand[i].exp.X_subtract_symbol,
789 operand[i].exp.X_add_number,
790 0,
791 R_RELBYTE);
792 }
793
794 break;
795 case MEMIND:
796 check_operand(operand+i, 0xff,"@@");
797 fix_new(frag_now,
798 output - frag_now->fr_literal + 1,
799 1,
800 operand[i].exp.X_add_symbol,
801 operand[i].exp.X_subtract_symbol,
802 operand[i].exp.X_add_number,
803 0,
804 R_RELBYTE);
805 break;
806 case ABS8DST:
807 case ABS8SRC:
808 check_operand(operand+i, 0xff,"@");
809 fix_new(frag_now,
810 output - frag_now->fr_literal + 1,
811 1,
812 operand[i].exp.X_add_symbol,
813 operand[i].exp.X_subtract_symbol,
814 operand[i].exp.X_add_number,
815 0,
816 R_RELBYTE);
817 break;
818
819 case ABS16OR8SRC:
820 case ABS16OR8DST:
821 check_operand(operand+i, 0xffff,"@");
822
823 fix_new(frag_now,
824 output - frag_now->fr_literal + 2,
825 2,
826 operand[i].exp.X_add_symbol,
827 operand[i].exp.X_subtract_symbol,
828 operand[i].exp.X_add_number,
829 0,
830 R_MOVB1);
831 break;
832
833 case ABS16ORREL8SRC:
834 check_operand(operand+i, 0xffff,"@");
835
836 fix_new(frag_now,
837 output - frag_now->fr_literal + 2,
838 2,
839 operand[i].exp.X_add_symbol,
840 operand[i].exp.X_subtract_symbol,
841 operand[i].exp.X_add_number,
842 0,
843 R_JMP1);
844 break;
845
846
847 case ABS16SRC:
848 case ABS16DST:
849 case IMM16:
850 case DISPSRC:
851 case DISPDST:
852 check_operand(operand+i, 0xffff,"@");
853 if (operand[i].exp.X_add_symbol == 0)
854 {
855 /* This should be done with bfd */
856 output[3] = operand[i].exp.X_add_number & 0xff;
857 output[2] = operand[i].exp.X_add_number >> 8;
858
859 }
860 else
861 {
862
863 fix_new(frag_now,
864 output - frag_now->fr_literal + 2,
865 2,
866 operand[i].exp.X_add_symbol,
867 operand[i].exp.X_subtract_symbol,
868 operand[i].exp.X_add_number,
869 0,
870 R_RELWORD);
871 }
872
873 break;
874 case RS8:
875 case RD8:
876 case RS16:
877 case RD16:
878 case RDDEC:
879 case KBIT:
880 case RSINC:
881 case RDIND:
882 case RSIND:
883 case CCR:
884
885 break;
886 default:
887 abort();
888 }
889 }
890
891 }
892 /* This is the guts of the machine-dependent assembler. STR points to a
893 machine dependent instruction. This funciton is supposed to emit
894 the frags/bytes it assembles to.
895 */
896
897
898 void
899 DEFUN(md_assemble,(str),
900 char *str)
901 {
902 char *op_start;
903 char *op_end;
904 unsigned int i;
905 struct h8_op operand[2];
906 struct h8_opcode * opcode;
907 char *dot = 0;
908 char c;
909 /* Drop leading whitespace */
910 while (*str == ' ')
911 str++;
912
913 /* find the op code end */
914 for (op_start = op_end = str;
915 *op_end != 0 && *op_end != ' ';
916 op_end ++)
917 {
918 if (*op_end == '.') {
919 dot = op_end+1;
920 *op_end = 0;
921 op_end+=2;
922 break;
923 }
924 }
925
926 ;
927
928 if (op_end == op_start)
929 {
930 as_bad("can't find opcode ");
931 }
932 c = *op_end;
933
934 *op_end = 0;
935
936 opcode = (struct h8_opcode *) hash_find(opcode_hash_control,
937 op_start);
938
939 if (opcode == NULL)
940 {
941 as_bad("unknown opcode");
942 return;
943 }
944
945
946 input_line_pointer = get_operands(opcode->noperands, op_end,
947 operand);
948 *op_end = c;
949 opcode = get_specific(opcode, operand);
950
951 if (opcode == 0)
952 {
953 /* Allocate 2 bytes for the insn anyway */
954 char *where =frag_more(2);
955 where[0] = 0xde;
956 where[1] = 0xad;
957
958
959 as_bad("illegal operands for opcode");
960 return;
961 }
962 if (opcode->size && dot)
963 {
964 if (opcode->size != *dot)
965 {
966 as_warn("mismatch between opcode size and operand size");
967 }
968 }
969
970 build_bytes(opcode, operand);
971
972 }
973
974 void
975 DEFUN(tc_crawl_symbol_chain, (headers),
976 object_headers *headers)
977 {
978 printf("call to tc_crawl_symbol_chain \n");
979 }
980
981 symbolS *DEFUN(md_undefined_symbol,(name),
982 char *name)
983 {
984 return 0;
985 }
986
987 void
988 DEFUN(tc_headers_hook,(headers),
989 object_headers *headers)
990 {
991 printf("call to tc_headers_hook \n");
992 }
993 void
994 DEFUN_VOID(md_end)
995 {
996 }
997
998 /* Various routines to kill one day */
999 /* Equal to MAX_PRECISION in atof-ieee.c */
1000 #define MAX_LITTLENUMS 6
1001
1002 /* Turn a string in input_line_pointer into a floating point constant of type
1003 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
1004 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
1005 */
1006 char *
1007 md_atof(type,litP,sizeP)
1008 char type;
1009 char *litP;
1010 int *sizeP;
1011 {
1012 int prec;
1013 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1014 LITTLENUM_TYPE *wordP;
1015 char *t;
1016 char *atof_ieee();
1017
1018 switch(type) {
1019 case 'f':
1020 case 'F':
1021 case 's':
1022 case 'S':
1023 prec = 2;
1024 break;
1025
1026 case 'd':
1027 case 'D':
1028 case 'r':
1029 case 'R':
1030 prec = 4;
1031 break;
1032
1033 case 'x':
1034 case 'X':
1035 prec = 6;
1036 break;
1037
1038 case 'p':
1039 case 'P':
1040 prec = 6;
1041 break;
1042
1043 default:
1044 *sizeP=0;
1045 return "Bad call to MD_ATOF()";
1046 }
1047 t=atof_ieee(input_line_pointer,type,words);
1048 if(t)
1049 input_line_pointer=t;
1050
1051 *sizeP=prec * sizeof(LITTLENUM_TYPE);
1052 for(wordP=words;prec--;) {
1053 md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
1054 litP+=sizeof(LITTLENUM_TYPE);
1055 }
1056 return ""; /* Someone should teach Dean about null pointers */
1057 }
1058
1059 int
1060 md_parse_option(argP, cntP, vecP)
1061 char **argP;
1062 int *cntP;
1063 char ***vecP;
1064
1065 {
1066 return 0;
1067
1068 }
1069
1070 int md_short_jump_size;
1071
1072 void tc_aout_fix_to_chars () { printf("call to tc_aout_fix_to_chars \n");
1073 abort(); }
1074 void md_create_short_jump(ptr, from_addr, to_addr, frag, to_symbol)
1075 char *ptr;
1076 long from_addr;
1077 long to_addr;
1078 fragS *frag;
1079 symbolS *to_symbol;
1080 {
1081 as_fatal("failed sanity check.");
1082 }
1083
1084 void
1085 md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
1086 char *ptr;
1087 long from_addr, to_addr;
1088 fragS *frag;
1089 symbolS *to_symbol;
1090 {
1091 as_fatal("failed sanity check.");
1092 }
1093
1094 void
1095 md_convert_frag(headers, fragP)
1096 object_headers *headers;
1097 fragS * fragP;
1098
1099 { printf("call to md_convert_frag \n"); abort(); }
1100
1101 long
1102 DEFUN(md_section_align,(seg, size),
1103 segT seg AND
1104 long size)
1105 {
1106 return((size + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
1107
1108 }
1109
1110 void
1111 md_apply_fix(fixP, val)
1112 fixS *fixP;
1113 long val;
1114 {
1115 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1116
1117 switch(fixP->fx_size) {
1118 case 1:
1119 *buf++=val;
1120 break;
1121 case 2:
1122 *buf++=(val>>8);
1123 *buf++=val;
1124 break;
1125 case 4:
1126 *buf++=(val>>24);
1127 *buf++=(val>>16);
1128 *buf++=(val>>8);
1129 *buf++=val;
1130 break;
1131 default:
1132 abort();
1133
1134 }
1135 }
1136
1137 void DEFUN(md_operand, (expressionP),expressionS *expressionP)
1138 { }
1139
1140 int md_long_jump_size;
1141 int
1142 md_estimate_size_before_relax(fragP, segment_type)
1143 register fragS *fragP;
1144 register segT segment_type;
1145 {
1146 printf("call tomd_estimate_size_before_relax \n"); abort(); }
1147 /* Put number into target byte order */
1148
1149 void DEFUN(md_number_to_chars,(ptr, use, nbytes),
1150 char *ptr AND
1151 long use AND
1152 int nbytes)
1153 {
1154 switch (nbytes) {
1155 case 4: *ptr++ = (use >> 24) & 0xff;
1156 case 3: *ptr++ = (use >> 16) & 0xff;
1157 case 2: *ptr++ = (use >> 8) & 0xff;
1158 case 1: *ptr++ = (use >> 0) & 0xff;
1159 break;
1160 default:
1161 abort();
1162 }
1163 }
1164 long md_pcrel_from(fixP)
1165 fixS *fixP; { abort(); }
1166
1167 void tc_coff_symbol_emit_hook() { }
1168
1169
1170 void tc_reloc_mangle(fix_ptr, intr, base)
1171 fixS *fix_ptr;
1172 struct internal_reloc *intr;
1173 bfd_vma base;
1174
1175 {
1176 symbolS *symbol_ptr;
1177
1178 symbol_ptr = fix_ptr->fx_addsy;
1179
1180 /* If this relocation is attached to a symbol then it's ok
1181 to output it */
1182 if (fix_ptr->fx_r_type == RELOC_32) {
1183 /* cons likes to create reloc32's whatever the size of the reloc..
1184 */
1185 switch (fix_ptr->fx_size)
1186 {
1187
1188 case 2:
1189 intr->r_type = R_RELWORD;
1190 break;
1191 case 1:
1192 intr->r_type = R_RELBYTE;
1193 break;
1194 default:
1195 abort();
1196
1197 }
1198
1199 }
1200 else {
1201 intr->r_type = fix_ptr->fx_r_type;
1202 }
1203
1204 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where +base;
1205 intr->r_offset = fix_ptr->fx_offset;
1206
1207 if (symbol_ptr)
1208 intr->r_symndx = symbol_ptr->sy_number;
1209 else
1210 intr->r_symndx = -1;
1211
1212
1213 }
1214 /* tc-h8300.c -- Assemble code for the Hitachi h8/300
1215 Copyright (C) 1991 Free Software Foundation.
1216
1217 This file is part of GAS, the GNU Assembler.
1218
1219 GAS is free software; you can redistribute it and/or modify
1220 it under the terms of the GNU General Public License as published by
1221 the Free Software Foundation; either version 2, or (at your option)
1222 any later version.
1223
1224 GAS is distributed in the hope that it will be useful,
1225 but WITHOUT ANY WARRANTY; without even the implied warranty of
1226 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1227 GNU General Public License for more details.
1228
1229 You should have received a copy of the GNU General Public License
1230 along with GAS; see the file COPYING. If not, write to
1231 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
1232
1233
1234 /*
1235 Written By Steve Chamberlain
1236 sac@cygnus.com
1237 */
1238
1239 #include <stdio.h>
1240 #include "as.h"
1241 #include "bfd.h"
1242 #include "opcode/h8300.h"
1243 #include <ctype.h>
1244 #include "listing.h"
1245
1246 char comment_chars[] = { ';',0 };
1247 char line_separator_chars[] = { '$' ,0};
1248
1249 /* This table describes all the machine specific pseudo-ops the assembler
1250 has to support. The fields are:
1251 pseudo-op name without dot
1252 function to call to execute this pseudo-op
1253 Integer arg to pass to the function
1254 */
1255
1256 void cons();
1257
1258 const pseudo_typeS md_pseudo_table[] = {
1259 { "int", cons, 2 },
1260 { 0,0,0 }
1261 };
1262
1263 int md_reloc_size ;
1264
1265 const char EXP_CHARS[] = "eE";
1266
1267 /* Chars that mean this number is a floating point constant */
1268 /* As in 0f12.456 */
1269 /* or 0d1.2345e12 */
1270 char FLT_CHARS[] = "rRsSfFdDxXpP";
1271
1272
1273 const relax_typeS md_relax_table[1];
1274
1275
1276 static struct hash_control *opcode_hash_control; /* Opcode mnemonics */
1277
1278
1279 /*
1280 This function is called once, at assembler startup time. This should
1281 set up all the tables, etc that the MD part of the assembler needs
1282 */
1283
1284 /* encode the size and number into the number field
1285 xxnnnn
1286 00 8 bit
1287 01 16 bit
1288 10 ccr
1289 nnnnreg number
1290 */
1291 #define WORD_REG 0x10
1292 #define BYTE_REG 0x00
1293 #define CCR_REG 0x20
1294 struct reg_entry
1295 {
1296 char *name;
1297 char number;
1298 };
1299
1300 struct reg_entry reg_list[] = {
1301 "r0",WORD_REG +0,
1302 "r1",WORD_REG +1,
1303 "r2",WORD_REG +2,
1304 "r3",WORD_REG +3,
1305 "r4",WORD_REG +4,
1306 "r5",WORD_REG +5,
1307 "r6",WORD_REG +6,
1308 "r7",WORD_REG +7,
1309 "fp",WORD_REG +6,
1310 "sp",WORD_REG +7,
1311 "r0h",BYTE_REG + 0,
1312 "r0l",BYTE_REG + 1,
1313 "r1h",BYTE_REG + 2,
1314 "r1l",BYTE_REG + 3,
1315 "r2h",BYTE_REG + 4,
1316 "r2l",BYTE_REG + 5,
1317 "r3h",BYTE_REG + 6,
1318 "r3l",BYTE_REG + 7,
1319 "r4h",BYTE_REG + 8,
1320 "r4l",BYTE_REG + 9,
1321 "r5h",BYTE_REG + 10,
1322 "r5l",BYTE_REG + 11,
1323 "r6h",BYTE_REG + 12,
1324 "r6l",BYTE_REG + 13,
1325 "r7h",BYTE_REG + 14,
1326 "r7l",BYTE_REG + 15,
1327 "ccr",CCR_REG,
1328 0,0
1329 }
1330 ;
1331
1332
1333
1334
1335
1336 void md_begin ()
1337 {
1338 struct h8_opcode *opcode;
1339 const struct reg_entry *reg;
1340 char prev_buffer[100];
1341 int idx = 0;
1342
1343 opcode_hash_control = hash_new();
1344 prev_buffer[0] = 0;
1345
1346 for (opcode = h8_opcodes; opcode->name; opcode++)
1347 {
1348 /* Strip off any . part when inserting the opcode and only enter
1349 unique codes into the hash table
1350 */
1351 char *src= opcode->name;
1352 unsigned int len = strlen(src);
1353 char *dst = malloc(len+1);
1354 char *buffer = dst;
1355 opcode->size = 0;
1356 while (*src) {
1357 if (*src == '.') {
1358 *dst++ = 0;
1359 src++;
1360 opcode->size = *src;
1361 break;
1362 }
1363 *dst++ = *src++;
1364 }
1365 if (strcmp(buffer, prev_buffer))
1366 {
1367 hash_insert(opcode_hash_control, buffer, (char *)opcode);
1368 strcpy(prev_buffer, buffer);
1369 idx++;
1370 }
1371 opcode->idx = idx;
1372
1373
1374 /* Find the number of operands */
1375 opcode->noperands = 0;
1376 while (opcode->args.nib[opcode->noperands] != E)
1377 opcode->noperands ++;
1378 /* Find the length of the opcode in bytes */
1379 opcode->length =0;
1380 while (opcode->data.nib[opcode->length*2] != E)
1381 opcode->length++;
1382 }
1383
1384 }
1385
1386
1387 struct h8_exp {
1388 char *e_beg;
1389 char *e_end;
1390 expressionS e_exp;
1391 };
1392 struct h8_op
1393 {
1394 unsigned int dispreg;
1395 op_type mode;
1396 unsigned reg;
1397 expressionS exp;
1398 };
1399
1400
1401
1402 /*
1403 parse operands
1404 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
1405 r0l,r0h,..r7l,r7h
1406 @WREG
1407 @WREG+
1408 @-WREG
1409 #const
1410
1411 */
1412
1413 op_type r8_sord[] = {RS8, RD8};
1414 op_type r16_sord[] = {RS16, RD16};
1415 op_type rind_sord[] = {RSIND, RDIND};
1416 op_type abs_sord[2] = {ABS16SRC, ABS16DST};
1417 op_type disp_sord[] = {DISPSRC, DISPDST};
1418
1419 /* try and parse a reg name, returns number of chars consumed */
1420 int
1421 DEFUN(parse_reg,(src, mode, reg, dst),
1422 char *src AND
1423 op_type *mode AND
1424 unsigned int *reg AND
1425 int dst)
1426 {
1427 if (src[0] == 's' && src[1] == 'p')
1428 {
1429 *mode = r16_sord[dst];
1430 *reg = 7;
1431 return 2;
1432 }
1433 if (src[0] == 'c' && src[1] == 'c' && src[2] == 'r')
1434 {
1435 *mode = CCR;
1436 *reg = 0;
1437 return 3;
1438 }
1439 if (src[0] == 'f' && src[1] == 'p')
1440 {
1441 *mode = r16_sord[dst];
1442 *reg = 6;
1443 return 2;
1444 }
1445 if (src[0] == 'r')
1446 {
1447 if (src[1] >= '0' && src[1] <= '7')
1448 {
1449 if(src[2] == 'l')
1450 {
1451 *mode = r8_sord[dst];
1452 *reg = (src[1] - '0') + 8;
1453 return 3;
1454 }
1455 if(src[2] == 'h')
1456 {
1457 *mode = r8_sord[dst];
1458 *reg = (src[1] - '0') ;
1459 return 3;
1460 }
1461 *mode = r16_sord[dst];
1462 *reg = (src[1] - '0');
1463 return 2;
1464 }
1465 }
1466 return 0;
1467 }
1468
1469 char *
1470 DEFUN(parse_exp,(s, op),
1471 char *s AND
1472 expressionS *op)
1473 {
1474 char *save = input_line_pointer;
1475 char *new;
1476 segT seg;
1477 input_line_pointer = s;
1478 seg = expr(0,op);
1479 new = input_line_pointer;
1480 input_line_pointer = save;
1481 if (SEG_NORMAL(seg))
1482 return new;
1483 switch (seg) {
1484 case SEG_ABSOLUTE:
1485 case SEG_UNKNOWN:
1486 case SEG_DIFFERENCE:
1487 case SEG_BIG:
1488 case SEG_REGISTER:
1489 return new;
1490 case SEG_ABSENT:
1491 as_bad("Missing operand");
1492 return new;
1493 default:
1494 as_bad("Don't understand operand of type %s", segment_name (seg));
1495 return new;
1496 }
1497 }
1498
1499 static char *
1500 DEFUN(skip_colonthing,(ptr),
1501 char *ptr)
1502 {
1503 if (*ptr == ':') {
1504 ptr++;
1505 while (isdigit(*ptr))
1506 ptr++;
1507
1508 }
1509 return ptr;
1510 }
1511
1512 /* The many forms of operand:
1513
1514 Rn Register direct
1515 @Rn Register indirect
1516 @(exp[:16], Rn) Register indirect with displacement
1517 @Rn+
1518 @-Rn
1519 @aa:8 absolute 8 bit
1520 @aa:16 absolute 16 bit
1521 @aa absolute 16 bit
1522
1523 #xx[:size] immediate data
1524 @(exp:[8], pc) pc rel
1525 @@aa[:8] memory indirect
1526
1527 */
1528
1529 static void
1530 DEFUN(get_operand,(ptr, op, dst),
1531 char **ptr AND
1532 struct h8_op *op AND
1533 unsigned int dst)
1534 {
1535 char *src = *ptr;
1536 op_type mode;
1537 unsigned int num;
1538 unsigned int len;
1539 unsigned int size;
1540 op->mode = E;
1541
1542 len = parse_reg(src, &op->mode, &op->reg, dst);
1543 if (len) {
1544 *ptr = src + len;
1545 return ;
1546 }
1547
1548 if (*src == '@')
1549 {
1550 src++;
1551 if (*src == '@')
1552 {
1553 src++;
1554 src = parse_exp(src,&op->exp);
1555 src = skip_colonthing(src);
1556
1557 *ptr = src;
1558
1559 op->mode = MEMIND;
1560 return;
1561
1562 }
1563
1564
1565 if (*src == '-')
1566 {
1567 src++;
1568 len = parse_reg(src, &mode, &num, dst);
1569 if (len == 0 || mode != r16_sord[dst])
1570 {
1571 as_bad("@- needs word register");
1572 }
1573 op->mode = RDDEC;
1574 op->reg = num;
1575 *ptr = src + len;
1576 return;
1577 }
1578 if (*src == '(' && ')')
1579 {
1580 /* Disp */
1581 src++;
1582 src = parse_exp(src, &op->exp);
1583
1584 if (*src == ')')
1585 {
1586 src++;
1587 op->mode = abs_sord[dst];
1588 *ptr = src;
1589 return;
1590 }
1591 src = skip_colonthing(src);
1592
1593 if (*src != ',')
1594 {
1595 as_bad("expected @(exp, reg16)");
1596 }
1597 src++;
1598 len = parse_reg(src, &mode, &op->reg, dst);
1599 if (len == 0 || mode != r16_sord[dst])
1600 {
1601 as_bad("expected @(exp, reg16)");
1602 }
1603 op->mode = disp_sord[dst];
1604 src += len;
1605 src = skip_colonthing(src);
1606
1607 if (*src != ')' && '(')
1608 {
1609 as_bad("expected @(exp, reg16)");
1610
1611 }
1612 *ptr = src +1;
1613
1614 return;
1615 }
1616 len = parse_reg(src, &mode, &num, dst);
1617
1618 if(len) {
1619 src += len;
1620 if (*src == '+')
1621 {
1622 src++;
1623 if (mode != RS16)
1624 {
1625 as_bad("@Rn+ needs src word register");
1626 }
1627 op->mode = RSINC;
1628 op->reg = num;
1629 *ptr = src;
1630 return;
1631 }
1632 if (mode != r16_sord[dst])
1633 {
1634 as_bad("@Rn needs word register");
1635 }
1636 op->mode =rind_sord[dst];
1637 op->reg = num;
1638 *ptr = src;
1639 return;
1640 }
1641 else
1642 {
1643 /* must be a symbol */
1644 op->mode = abs_sord[dst];
1645 *ptr = skip_colonthing(parse_exp(src, &op->exp));
1646
1647 return;
1648 }
1649 }
1650
1651
1652 if (*src == '#') {
1653 src++;
1654 op->mode = IMM16;
1655 src = parse_exp(src, &op->exp);
1656 *ptr= skip_colonthing(src);
1657
1658 return;
1659 }
1660 else {
1661 *ptr = parse_exp(src, &op->exp);
1662 op->mode = DISP8;
1663 }
1664 }
1665
1666
1667 static
1668 char *
1669 DEFUN(get_operands,(noperands,op_end, operand),
1670 unsigned int noperands AND
1671 char *op_end AND
1672 struct h8_op *operand)
1673 {
1674 char *ptr = op_end;
1675 switch (noperands)
1676 {
1677 case 0:
1678 operand[0].mode = 0;
1679 operand[1].mode = 0;
1680 break;
1681
1682 case 1:
1683 ptr++;
1684 get_operand(& ptr, operand +0,0);
1685 operand[1].mode =0;
1686 break;
1687
1688 case 2:
1689 ptr++;
1690 get_operand(& ptr, operand +0,0);
1691 if (*ptr == ',') ptr++;
1692 get_operand(& ptr, operand +1, 1);
1693 break;
1694
1695 default:
1696 abort();
1697 }
1698
1699
1700 return ptr;
1701 }
1702
1703 /* Passed a pointer to a list of opcodes which use different
1704 addressing modes, return the opcode which matches the opcodes
1705 provided
1706 */
1707 static
1708 struct h8_opcode *
1709 DEFUN(get_specific,(opcode, operands),
1710 struct h8_opcode *opcode AND
1711 struct h8_op *operands)
1712
1713 {
1714 struct h8_opcode *this_try = opcode ;
1715 int found = 0;
1716 unsigned int noperands = opcode->noperands;
1717
1718 unsigned int dispreg;
1719 unsigned int this_index = opcode->idx;
1720 while (this_index == opcode->idx && !found)
1721 {
1722 unsigned int i;
1723
1724 this_try = opcode ++;
1725 for (i = 0; i < noperands; i++)
1726 {
1727 op_type op = (this_try->args.nib[i]) & ~(B30|B31);
1728 switch (op)
1729 {
1730 case Hex0:
1731 case Hex1:
1732 case Hex2:
1733 case Hex3:
1734 case Hex4:
1735 case Hex5:
1736 case Hex6:
1737 case Hex7:
1738 case Hex8:
1739 case Hex9:
1740 case HexA:
1741 case HexB:
1742 case HexC:
1743 case HexD:
1744 case HexE:
1745 case HexF:
1746 break;
1747 case DISPSRC:
1748 case DISPDST:
1749 operands[0].dispreg = operands[i].reg;
1750 case RD8:
1751 case RS8:
1752 case RDIND:
1753 case RSIND:
1754 case RD16:
1755 case RS16:
1756 case CCR:
1757 case RSINC:
1758 case RDDEC:
1759 if (operands[i].mode != op) goto fail;
1760 break;
1761 case KBIT:
1762 case IMM16:
1763 case IMM3:
1764 case IMM8:
1765 if (operands[i].mode != IMM16) goto fail;
1766 break;
1767 case MEMIND:
1768 if (operands[i].mode != MEMIND) goto fail;
1769 break;
1770 case ABS16SRC:
1771 case ABS8SRC:
1772 case ABS16OR8SRC:
1773 case ABS16ORREL8SRC:
1774
1775 if (operands[i].mode != ABS16SRC) goto fail;
1776 break;
1777 case ABS16OR8DST:
1778 case ABS16DST:
1779 case ABS8DST:
1780 if (operands[i].mode != ABS16DST) goto fail;
1781 break;
1782 }
1783 }
1784 found =1;
1785 fail: ;
1786 }
1787 if (found)
1788 return this_try;
1789 else
1790 return 0;
1791 }
1792
1793 static void
1794 DEFUN(check_operand,(operand, width, string),
1795 struct h8_op *operand AND
1796 unsigned int width AND
1797 char *string)
1798 {
1799 if (operand->exp.X_add_symbol == 0
1800 && operand->exp.X_subtract_symbol == 0)
1801 {
1802
1803 /* No symbol involved, let's look at offset, it's dangerous if any of
1804 the high bits are not 0 or ff's, find out by oring or anding with
1805 the width and seeing if the answer is 0 or all fs*/
1806 if ((operand->exp.X_add_number | width) != ~0 &&
1807 (operand->exp.X_add_number & ~width)!= 0)
1808 {
1809 as_warn("operand %s0x%x out of range.", string, operand->exp.X_add_number);
1810 }
1811 }
1812
1813 }
1814
1815 /* Now we know what sort of opcodes it is, lets build the bytes -
1816 */
1817 static void
1818 DEFUN (build_bytes,(this_try, operand),
1819 struct h8_opcode *this_try AND
1820 struct h8_op *operand)
1821
1822 {
1823 unsigned int i;
1824
1825 char *output = frag_more(this_try->length);
1826 char *output_ptr = output;
1827 op_type *nibble_ptr = this_try->data.nib;
1828 char part;
1829 op_type c;
1830 char high;
1831 int nib;
1832 top: ;
1833 while (*nibble_ptr != E)
1834 {
1835 int nibble;
1836 for (nibble = 0; nibble <2; nibble++)
1837 {
1838 c = *nibble_ptr & ~(B30|B31);
1839 switch (c)
1840 {
1841 default:
1842 abort();
1843 case KBIT:
1844 switch (operand[0].exp.X_add_number)
1845 {
1846 case 1:
1847 nib = 0;
1848 break;
1849 case 2:
1850 nib = 8;
1851 break;
1852 default:
1853 as_bad("Need #1 or #2 here");
1854 break;
1855 }
1856 /* stop it making a fix */
1857 operand[0].mode = 0;
1858 break;
1859 case 0:
1860 case 1:
1861 case 2: case 3: case 4: case 5: case 6:
1862 case 7: case 8: case 9: case 10: case 11:
1863 case 12: case 13: case 14: case 15:
1864 nib = c;
1865 break;
1866 case DISPREG:
1867 nib = operand[0].dispreg;
1868 break;
1869 case IMM8:
1870 operand[0].mode = IMM8;
1871 nib = 0;
1872 break;
1873
1874 case DISPDST:
1875 nib = 0;
1876 break;
1877 case IMM3:
1878 if (operand[0].exp.X_add_symbol == 0) {
1879 operand[0].mode = 0; /* stop it making a fix */
1880 nib = (operand[0].exp.X_add_number);
1881 }
1882 else as_bad("can't have symbol for bit number");
1883 if (nib < 0 || nib > 7)
1884 {
1885 as_bad("Bit number out of range %d", nib);
1886 }
1887
1888 break;
1889
1890 case ABS16DST:
1891 nib = 0;
1892 break;
1893 case ABS8DST:
1894 operand[1].mode = ABS8DST;
1895 nib = 0;
1896 break;
1897 case ABS8SRC:
1898 operand[0].mode = ABS8SRC;
1899 nib = 0;
1900 break;
1901 case ABS16OR8DST:
1902 operand[1].mode = c;
1903
1904 nib = 0;
1905
1906 break;
1907
1908 case ABS16ORREL8SRC:
1909 operand[0].mode = c;
1910 nib=0;
1911 break;
1912
1913 case ABS16OR8SRC:
1914 operand[0].mode = ABS16OR8SRC;
1915 nib = 0;
1916 break;
1917 case DISPSRC:
1918 operand[0].mode = ABS16SRC;
1919 nib = 0;
1920 break;
1921
1922 case DISP8:
1923 operand[0].mode = DISP8;
1924 nib = 0;
1925 break;
1926
1927 case ABS16SRC:
1928 case IMM16:
1929 case IGNORE:
1930 case MEMIND:
1931
1932 nib=0;
1933 break;
1934 case RS8:
1935 case RS16:
1936 case RSIND:
1937 case RSINC:
1938 nib = operand[0].reg;
1939 break;
1940
1941 case RD8:
1942 case RD16:
1943 case RDDEC:
1944 case RDIND:
1945 nib = operand[1].reg;
1946 break;
1947
1948 case E:
1949 abort();
1950 break;
1951 }
1952 if (*nibble_ptr & B31) {
1953 nib |=0x8;
1954 }
1955
1956 if (nibble == 0) {
1957 *output_ptr = nib << 4;
1958 }
1959 else {
1960 *output_ptr |= nib;
1961 output_ptr++;
1962 }
1963 nibble_ptr++;
1964 }
1965
1966 }
1967
1968 /* output any fixes */
1969 for (i = 0; i < 2; i++)
1970 {
1971 switch (operand[i].mode) {
1972 case 0:
1973 break;
1974
1975 case DISP8:
1976 check_operand(operand+i, 0x7f,"@");
1977
1978 fix_new(frag_now,
1979 output - frag_now->fr_literal + 1,
1980 1,
1981 operand[i].exp.X_add_symbol,
1982 operand[i].exp.X_subtract_symbol,
1983 operand[i].exp.X_add_number -1,
1984 1,
1985 R_PCRBYTE);
1986 break;
1987 case IMM8:
1988 check_operand(operand+i, 0xff,"#");
1989 /* If there is nothing else going on we can safely
1990 reloc in place */
1991 if (operand[i].exp.X_add_symbol == 0)
1992 {
1993 output[1] = operand[i].exp.X_add_number;
1994 }
1995 else
1996 {
1997 fix_new(frag_now,
1998 output - frag_now->fr_literal + 1,
1999 1,
2000 operand[i].exp.X_add_symbol,
2001 operand[i].exp.X_subtract_symbol,
2002 operand[i].exp.X_add_number,
2003 0,
2004 R_RELBYTE);
2005 }
2006
2007 break;
2008 case MEMIND:
2009 check_operand(operand+i, 0xff,"@@");
2010 fix_new(frag_now,
2011 output - frag_now->fr_literal + 1,
2012 1,
2013 operand[i].exp.X_add_symbol,
2014 operand[i].exp.X_subtract_symbol,
2015 operand[i].exp.X_add_number,
2016 0,
2017 R_RELBYTE);
2018 break;
2019 case ABS8DST:
2020 case ABS8SRC:
2021 check_operand(operand+i, 0xff,"@");
2022 fix_new(frag_now,
2023 output - frag_now->fr_literal + 1,
2024 1,
2025 operand[i].exp.X_add_symbol,
2026 operand[i].exp.X_subtract_symbol,
2027 operand[i].exp.X_add_number,
2028 0,
2029 R_RELBYTE);
2030 break;
2031
2032 case ABS16OR8SRC:
2033 case ABS16OR8DST:
2034 check_operand(operand+i, 0xffff,"@");
2035
2036 fix_new(frag_now,
2037 output - frag_now->fr_literal + 2,
2038 2,
2039 operand[i].exp.X_add_symbol,
2040 operand[i].exp.X_subtract_symbol,
2041 operand[i].exp.X_add_number,
2042 0,
2043 R_MOVB1);
2044 break;
2045
2046 case ABS16ORREL8SRC:
2047 check_operand(operand+i, 0xffff,"@");
2048
2049 fix_new(frag_now,
2050 output - frag_now->fr_literal + 2,
2051 2,
2052 operand[i].exp.X_add_symbol,
2053 operand[i].exp.X_subtract_symbol,
2054 operand[i].exp.X_add_number,
2055 0,
2056 R_JMP1);
2057 break;
2058
2059
2060 case ABS16SRC:
2061 case ABS16DST:
2062 case IMM16:
2063 case DISPSRC:
2064 case DISPDST:
2065 check_operand(operand+i, 0xffff,"@");
2066 if (operand[i].exp.X_add_symbol == 0)
2067 {
2068 /* This should be done with bfd */
2069 output[3] = operand[i].exp.X_add_number & 0xff;
2070 output[2] = operand[i].exp.X_add_number >> 8;
2071
2072 }
2073 else
2074 {
2075
2076 fix_new(frag_now,
2077 output - frag_now->fr_literal + 2,
2078 2,
2079 operand[i].exp.X_add_symbol,
2080 operand[i].exp.X_subtract_symbol,
2081 operand[i].exp.X_add_number,
2082 0,
2083 R_RELWORD);
2084 }
2085
2086 break;
2087 case RS8:
2088 case RD8:
2089 case RS16:
2090 case RD16:
2091 case RDDEC:
2092 case KBIT:
2093 case RSINC:
2094 case RDIND:
2095 case RSIND:
2096 case CCR:
2097
2098 break;
2099 default:
2100 abort();
2101 }
2102 }
2103
2104 }
2105 /* This is the guts of the machine-dependent assembler. STR points to a
2106 machine dependent instruction. This funciton is supposed to emit
2107 the frags/bytes it assembles to.
2108 */
2109
2110
2111 void
2112 DEFUN(md_assemble,(str),
2113 char *str)
2114 {
2115 char *op_start;
2116 char *op_end;
2117 unsigned int i;
2118 struct h8_op operand[2];
2119 struct h8_opcode * opcode;
2120 char *dot = 0;
2121 char c;
2122 /* Drop leading whitespace */
2123 while (*str == ' ')
2124 str++;
2125
2126 /* find the op code end */
2127 for (op_start = op_end = str;
2128 *op_end != 0 && *op_end != ' ';
2129 op_end ++)
2130 {
2131 if (*op_end == '.') {
2132 dot = op_end+1;
2133 *op_end = 0;
2134 op_end+=2;
2135 break;
2136 }
2137 }
2138
2139 ;
2140
2141 if (op_end == op_start)
2142 {
2143 as_bad("can't find opcode ");
2144 }
2145 c = *op_end;
2146
2147 *op_end = 0;
2148
2149 opcode = (struct h8_opcode *) hash_find(opcode_hash_control,
2150 op_start);
2151
2152 if (opcode == NULL)
2153 {
2154 as_bad("unknown opcode");
2155 return;
2156 }
2157
2158
2159 input_line_pointer = get_operands(opcode->noperands, op_end,
2160 operand);
2161 *op_end = c;
2162 opcode = get_specific(opcode, operand);
2163
2164 if (opcode == 0)
2165 {
2166 /* Allocate 2 bytes for the insn anyway */
2167 char *where =frag_more(2);
2168 where[0] = 0xde;
2169 where[1] = 0xad;
2170
2171
2172 as_bad("illegal operands for opcode");
2173 return;
2174 }
2175 if (opcode->size && dot)
2176 {
2177 if (opcode->size != *dot)
2178 {
2179 as_warn("mismatch between opcode size and operand size");
2180 }
2181 }
2182
2183 build_bytes(opcode, operand);
2184
2185 }
2186
2187 void
2188 DEFUN(tc_crawl_symbol_chain, (headers),
2189 object_headers *headers)
2190 {
2191 printf("call to tc_crawl_symbol_chain \n");
2192 }
2193
2194 symbolS *DEFUN(md_undefined_symbol,(name),
2195 char *name)
2196 {
2197 return 0;
2198 }
2199
2200 void
2201 DEFUN(tc_headers_hook,(headers),
2202 object_headers *headers)
2203 {
2204 printf("call to tc_headers_hook \n");
2205 }
2206 void
2207 DEFUN_VOID(md_end)
2208 {
2209 }
2210
2211 /* Various routines to kill one day */
2212 /* Equal to MAX_PRECISION in atof-ieee.c */
2213 #define MAX_LITTLENUMS 6
2214
2215 /* Turn a string in input_line_pointer into a floating point constant of type
2216 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2217 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
2218 */
2219 char *
2220 md_atof(type,litP,sizeP)
2221 char type;
2222 char *litP;
2223 int *sizeP;
2224 {
2225 int prec;
2226 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2227 LITTLENUM_TYPE *wordP;
2228 char *t;
2229 char *atof_ieee();
2230
2231 switch(type) {
2232 case 'f':
2233 case 'F':
2234 case 's':
2235 case 'S':
2236 prec = 2;
2237 break;
2238
2239 case 'd':
2240 case 'D':
2241 case 'r':
2242 case 'R':
2243 prec = 4;
2244 break;
2245
2246 case 'x':
2247 case 'X':
2248 prec = 6;
2249 break;
2250
2251 case 'p':
2252 case 'P':
2253 prec = 6;
2254 break;
2255
2256 default:
2257 *sizeP=0;
2258 return "Bad call to MD_ATOF()";
2259 }
2260 t=atof_ieee(input_line_pointer,type,words);
2261 if(t)
2262 input_line_pointer=t;
2263
2264 *sizeP=prec * sizeof(LITTLENUM_TYPE);
2265 for(wordP=words;prec--;) {
2266 md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
2267 litP+=sizeof(LITTLENUM_TYPE);
2268 }
2269 return ""; /* Someone should teach Dean about null pointers */
2270 }
2271
2272 int
2273 md_parse_option(argP, cntP, vecP)
2274 char **argP;
2275 int *cntP;
2276 char ***vecP;
2277
2278 {
2279 return 0;
2280
2281 }
2282
2283 int md_short_jump_size;
2284
2285 void tc_aout_fix_to_chars () { printf("call to tc_aout_fix_to_chars \n");
2286 abort(); }
2287 void md_create_short_jump(ptr, from_addr, to_addr, frag, to_symbol)
2288 char *ptr;
2289 long from_addr;
2290 long to_addr;
2291 fragS *frag;
2292 symbolS *to_symbol;
2293 {
2294 as_fatal("failed sanity check.");
2295 }
2296
2297 void
2298 md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
2299 char *ptr;
2300 long from_addr, to_addr;
2301 fragS *frag;
2302 symbolS *to_symbol;
2303 {
2304 as_fatal("failed sanity check.");
2305 }
2306
2307 void
2308 md_convert_frag(headers, fragP)
2309 object_headers *headers;
2310 fragS * fragP;
2311
2312 { printf("call to md_convert_frag \n"); abort(); }
2313
2314 long
2315 DEFUN(md_section_align,(seg, size),
2316 segT seg AND
2317 long size)
2318 {
2319 return((size + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
2320
2321 }
2322
2323 void
2324 md_apply_fix(fixP, val)
2325 fixS *fixP;
2326 long val;
2327 {
2328 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2329
2330 switch(fixP->fx_size) {
2331 case 1:
2332 *buf++=val;
2333 break;
2334 case 2:
2335 *buf++=(val>>8);
2336 *buf++=val;
2337 break;
2338 case 4:
2339 *buf++=(val>>24);
2340 *buf++=(val>>16);
2341 *buf++=(val>>8);
2342 *buf++=val;
2343 break;
2344 default:
2345 abort();
2346
2347 }
2348 }
2349
2350 void DEFUN(md_operand, (expressionP),expressionS *expressionP)
2351 { }
2352
2353 int md_long_jump_size;
2354 int
2355 md_estimate_size_before_relax(fragP, segment_type)
2356 register fragS *fragP;
2357 register segT segment_type;
2358 {
2359 printf("call tomd_estimate_size_before_relax \n"); abort(); }
2360 /* Put number into target byte order */
2361
2362 void DEFUN(md_number_to_chars,(ptr, use, nbytes),
2363 char *ptr AND
2364 long use AND
2365 int nbytes)
2366 {
2367 switch (nbytes) {
2368 case 4: *ptr++ = (use >> 24) & 0xff;
2369 case 3: *ptr++ = (use >> 16) & 0xff;
2370 case 2: *ptr++ = (use >> 8) & 0xff;
2371 case 1: *ptr++ = (use >> 0) & 0xff;
2372 break;
2373 default:
2374 abort();
2375 }
2376 }
2377 long md_pcrel_from(fixP)
2378 fixS *fixP; { abort(); }
2379
2380 void tc_coff_symbol_emit_hook() { }
2381
2382
2383 void tc_reloc_mangle(fix_ptr, intr, base)
2384 fixS *fix_ptr;
2385 struct internal_reloc *intr;
2386 bfd_vma base;
2387
2388 {
2389 symbolS *symbol_ptr;
2390
2391 symbol_ptr = fix_ptr->fx_addsy;
2392
2393 /* If this relocation is attached to a symbol then it's ok
2394 to output it */
2395 if (fix_ptr->fx_r_type == RELOC_32) {
2396 /* cons likes to create reloc32's whatever the size of the reloc..
2397 */
2398 switch (fix_ptr->fx_size)
2399 {
2400
2401 case 2:
2402 intr->r_type = R_RELWORD;
2403 break;
2404 case 1:
2405 intr->r_type = R_RELBYTE;
2406 break;
2407 default:
2408 abort();
2409
2410 }
2411
2412 }
2413 else {
2414 intr->r_type = fix_ptr->fx_r_type;
2415 }
2416
2417 intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where +base;
2418 intr->r_offset = fix_ptr->fx_offset;
2419
2420 if (symbol_ptr)
2421 intr->r_symndx = symbol_ptr->sy_number;
2422 else
2423 intr->r_symndx = -1;
2424
2425
2426 }
This page took 0.077776 seconds and 5 git commands to generate.