1 /* tc-h8300.c -- Assemble code for the Hitachi h8/300
2 Copyright (C) 1991 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
22 Written By Steve Chamberlain
30 #include "h8300-opcode.h"
33 char comment_chars
[] = { ';',0 };
35 /* This table describes all the machine specific pseudo-ops the assembler
36 has to support. The fields are:
37 pseudo-op name without dot
38 function to call to execute this pseudo-op
39 Integer arg to pass to the function
41 const pseudo_typeS md_pseudo_table
[] = {
47 const char EXP_CHARS
[] = "eE";
49 /* Chars that mean this number is a floating point constant */
52 char FLT_CHARS
[] = "rRsSfFdDxXpP";
55 const relax_typeS md_relax_table
[1];
58 static struct hash_control
*opcode_hash_control
; /* Opcode mnemonics */
59 static struct hash_control
*register_hash_control
; /* Register name hash table */
63 This function is called once, at assembler startup time. This should
64 set up all the tables, etc that the MD part of the assembler needs
67 reloc_howto_type
*r16
;
69 reloc_howto_type
*r8ff
;
70 reloc_howto_type
*r8pcrel
;
74 bfd_arch_info_type
*ai
;
75 const struct h8_opcode
*opcode
;
77 opcode_hash_control
= hash_new();
78 for (opcode
= h8_opcodes
; opcode
->name
; opcode
++) {
79 hash_insert(opcode_hash_control
, opcode
->name
, (char *)opcode
);
82 ai
= bfd_lookup_arch(bfd_arch_h8300
,0);
84 r16
= ai
->reloc_type_lookup(ai
, BFD_RELOC_16
);
85 r8
= ai
->reloc_type_lookup(ai
, BFD_RELOC_8
);
86 r8ff
= ai
->reloc_type_lookup(ai
, BFD_RELOC_8_FFnn
);
87 r8pcrel
= ai
->reloc_type_lookup(ai
, BFD_RELOC_8_PCREL
);
109 WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
118 op_type r8_sord
[] = {RS8
, RD8
};
119 op_type r16_sord
[] = {RS16
, RD16
};
120 op_type rind_sord
[] = {RSIND
, RDIND
};
121 op_type abs_sord
[2] = {ABS16SRC
, ABS16DST
};
122 op_type disp_sord
[] = {DISPSRC
, DISPDST
};
123 /* try and parse a reg name, returns number of chars consumed */
124 int DEFUN(parse_reg
,(src
, mode
, reg
, dst
),
127 unsigned int *reg AND
130 if (src
[0] == 's' && src
[1] == 'p') {
131 *mode
= r16_sord
[dst
];
135 if (src
[0] == 'c' && src
[1] == 'c' && src
[2] == 'r') {
140 if (src
[0] == 'f' && src
[1] == 'p') {
141 *mode
= r16_sord
[dst
];
146 if (src
[1] >= '0' && src
[1] <= '7') {
148 *mode
= r8_sord
[dst
];
149 *reg
= (src
[1] - '0') + 8;
153 *mode
= r8_sord
[dst
];
154 *reg
= (src
[1] - '0') ;
157 *mode
= r16_sord
[dst
];
158 *reg
= (src
[1] - '0');
166 DEFUN(parse_exp
,(s
, op
),
170 char *save
= input_line_pointer
;
173 input_line_pointer
= s
;
175 new = input_line_pointer
;
176 input_line_pointer
= save
;
187 as_bad("Missing operand");
190 as_bad("Don't understand operand of type %s", segment_name (seg
));
197 DEFUN(get_operand
,(ptr
, op
, dst
),
208 while (*src
== ' ') src
++;
209 len
= parse_reg(src
, &op
->mode
, &op
->reg
, dst
);
219 len
= parse_reg(src
, &mode
, &num
, dst
);
220 if (len
== 0 || mode
!= r16_sord
[dst
]) {
221 as_bad("@- needs word register");
228 if (*src
== '(' && ')') {
231 src
= parse_exp(src
, &op
->exp
);
235 op
->mode
= abs_sord
[dst
];
240 as_bad("expected @(exp, reg16)");
243 len
= parse_reg(src
, &mode
, &op
->reg
, dst
);
244 if (len
== 0 || mode
!= r16_sord
[dst
])
246 as_bad("expected @(exp, reg16)");
248 op
->mode
= disp_sord
[dst
];
250 if (*src
!= ')' && '(') {
251 as_bad("expected @(exp, reg16)");
258 len
= parse_reg(src
, &mode
, &num
, dst
);
265 as_bad("@Rn+ needs word register");
272 if (mode
!= r16_sord
[dst
]) {
273 as_bad("@Rn needs word register");
275 op
->mode
=rind_sord
[dst
];
281 /* must be a symbol */
282 op
->mode
= abs_sord
[dst
];
283 *ptr
= parse_exp(src
, &op
->exp
);
292 *ptr
= parse_exp(src
, &op
->exp
);
296 *ptr
= parse_exp(src
, &op
->exp
);
301 /* This is the guts of the machine-dependent assembler. STR points to a
302 machine dependent instruction. This funciton is supposed to emit
303 the frags/bytes it assembles to.
308 DEFUN(md_assemble
,(str
),
315 struct h8_opcode
* opcode
;
316 /* Drop leading whitespace */
321 /* find the op code end */
322 for (op_start
= op_end
= str
;
323 *op_end
!= 0 && *op_end
!= ' ';
327 if (op_end
== op_start
) {
328 as_bad("can't find opcode ");
331 opcode
= (struct h8_opcode
*) hash_find(opcode_hash_control
,
334 if (opcode
== NULL
) {
335 as_bad("unknown opcode");
344 struct h8_op operand
[2];
345 char *ptr
= op_end
+1;
346 if (opcode
->noperands
)
347 get_operand(& ptr
, &operand
[0],0);
348 else operand
[0].mode
= 0;
349 if (opcode
->noperands
==2) {
350 if (*ptr
== ',') ptr
++;
351 get_operand(& ptr
, &operand
[1], 1);
353 else operand
[1].mode
= 0;
358 struct h8_opcode
*this_try
;
360 for (j
= 0; j
< opcode
->nopcodes
&& !found
; j
++) {
361 this_try
= opcode
+ j
;
362 for (i
= 0; i
< opcode
->noperands
; i
++) {
363 op_type op
= (this_try
->args
.nib
[i
]) & ~(B30
|B31
);
384 dispreg
= operand
[i
].reg
;
394 if (operand
[i
].mode
!= op
) goto fail
;
397 /* We have an expression, called IMM16, but we know we
398 want an 8 bit value here */
399 if (operand
[i
].mode
!= IMM16
) goto fail
;
400 operand
[i
].mode
= IMM8
;
405 if (operand
[i
].mode
!= IMM16
) goto fail
;
409 if (operand
[i
].mode
!= ABS16SRC
) goto fail
;
413 if (operand
[i
].mode
!= ABS16DST
) goto fail
;
422 as_bad("illegal operands for opcode");
425 /* Now we know what sort of opcodes etc, lets build the bytes -
426 actually we know how big the instruction will be too. So we
430 char *output
= frag_more(this_try
->length
);
431 char *output_ptr
= output
;
432 op_type
*nibble_ptr
= this_try
->data
.nib
;
438 while (*nibble_ptr
!= E
) {
440 for (nibble
= 0; nibble
<2; nibble
++) {
441 c
= *nibble_ptr
& ~(B30
|B31
);
446 switch (operand
[0].exp
.X_add_number
) {
454 as_bad("Need #1 or #2 here");
457 /* stop it making a fix */
462 case 2: case 3: case 4: case 5: case 6:
463 case 7: case 8: case 9: case 10: case 11:
464 case 12: case 13: case 14: case 15:
478 if (operand
[0].exp
.X_add_symbol
== 0) {
479 operand
[0].mode
= 0; /* stop it making a fix */
480 nib
= (operand
[0].exp
.X_add_number
);
482 else as_bad("can't have symbol for bit number");
518 nib
= operand
[1].reg
;
525 if (*nibble_ptr
& B31
) nib
|=0x8;
527 *output_ptr
= nib
<< 4;
538 /* output any fixes */
539 for (i
= 0; i
< 2; i
++)
541 switch (operand
[i
].mode
) {
546 output
- frag_now
->fr_literal
+ 1,
548 operand
[i
].exp
.X_add_symbol
,
549 operand
[i
].exp
.X_subtract_symbol
,
550 operand
[i
].exp
.X_add_number
-1,
556 output
- frag_now
->fr_literal
+ 1,
558 operand
[i
].exp
.X_add_symbol
,
559 operand
[i
].exp
.X_subtract_symbol
,
560 operand
[i
].exp
.X_add_number
,
571 output
- frag_now
->fr_literal
+ 2,
573 operand
[i
].exp
.X_add_symbol
,
574 operand
[i
].exp
.X_subtract_symbol
,
575 operand
[i
].exp
.X_add_number
,
601 DEFUN(tc_crawl_symbol_chain
, (headers
),
602 object_headers
*headers
)
604 printf("call to tc_crawl_symbol_chain \n");
607 symbolS
*DEFUN(md_undefined_symbol
,(name
),
614 DEFUN(tc_headers_hook
,(headers
),
615 object_headers
*headers
)
617 printf("call to tc_headers_hook \n");
624 /* Various routines to kill one day */
625 /* Equal to MAX_PRECISION in atof-ieee.c */
626 #define MAX_LITTLENUMS 6
628 /* Turn a string in input_line_pointer into a floating point constant of type
629 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
630 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
633 md_atof(type
,litP
,sizeP
)
639 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
640 LITTLENUM_TYPE
*wordP
;
671 return "Bad call to MD_ATOF()";
673 t
=atof_ieee(input_line_pointer
,type
,words
);
675 input_line_pointer
=t
;
677 *sizeP
=prec
* sizeof(LITTLENUM_TYPE
);
678 for(wordP
=words
;prec
--;) {
679 md_number_to_chars(litP
,(long)(*wordP
++),sizeof(LITTLENUM_TYPE
));
680 litP
+=sizeof(LITTLENUM_TYPE
);
682 return ""; /* Someone should teach Dean about null pointers */
686 md_parse_option(argP
, cntP
, vecP
)
694 int md_short_jump_size
;
696 void tc_aout_fix_to_chars () { printf("call to tc_aout_fix_to_chars \n");
698 void md_create_short_jump(ptr
, from_addr
, to_addr
, frag
, to_symbol
)
705 as_fatal("failed sanity check.");
709 md_create_long_jump(ptr
,from_addr
,to_addr
,frag
,to_symbol
)
711 long from_addr
, to_addr
;
715 as_fatal("failed sanity check.");
719 md_convert_frag(headers
, fragP
)
720 object_headers
*headers
;
723 { printf("call to md_convert_frag \n"); abort(); }
726 DEFUN(md_section_align
,(seg
, size
),
730 return((size
+ (1 << section_alignment
[(int) seg
]) - 1) & (-1 << section_alignment
[(int) seg
]));
735 md_apply_fix(fixP
, val
)
739 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
741 switch(fixP
->fx_size
) {
761 void DEFUN(md_operand
, (expressionP
),expressionS
*expressionP
)
764 int md_long_jump_size
;
766 md_estimate_size_before_relax(fragP
, segment_type
)
767 register fragS
*fragP
;
768 register segT segment_type
;
769 { printf("call tomd_estimate_size_before_relax \n"); abort(); }
770 /* Put number into target byte order */
772 void DEFUN(md_number_to_chars
,(ptr
, use
, nbytes
),
778 case 4: *ptr
++ = (use
>> 24) & 0xff;
779 case 3: *ptr
++ = (use
>> 16) & 0xff;
780 case 2: *ptr
++ = (use
>> 8) & 0xff;
781 case 1: *ptr
++ = (use
>> 0) & 0xff;
787 long md_pcrel_from(fixP
)
788 fixS
*fixP
; { abort(); }
790 void tc_coff_symbol_emit_hook() { }