1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS USED TO GENERATE fr30-asm.c.
6 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #define min(a,b) ((a) < (b) ? (a) : (b))
36 #define max(a,b) ((a) > (b) ? (a) : (b))
40 #define INLINE __inline__
45 static const char * insert_normal
46 PARAMS ((CGEN_OPCODE_DESC
, long, unsigned int, int, int, int,
47 CGEN_INSN_BYTES_PTR
));
48 static const char * parse_insn_normal
49 PARAMS ((CGEN_OPCODE_DESC
, const CGEN_INSN
*,
50 const char **, CGEN_FIELDS
*));
51 static const char * insert_insn_normal
52 PARAMS ((CGEN_OPCODE_DESC
, const CGEN_INSN
*,
53 CGEN_FIELDS
*, CGEN_INSN_BYTES_PTR
, bfd_vma
));
55 /* -- assembler routines inserted here */
57 /* Main entry point for operand parsing.
59 This function is basically just a big switch statement. Earlier versions
60 used tables to look up the function to use, but
61 - if the table contains both assembler and disassembler functions then
62 the disassembler contains much of the assembler and vice-versa,
63 - there's a lot of inlining possibilities as things grow,
64 - using a switch statement avoids the function call overhead.
66 This function could be moved into `parse_insn_normal', but keeping it
67 separate makes clear the interface between `parse_insn_normal' and each of
72 fr30_cgen_parse_operand (od
, opindex
, strp
, fields
)
82 case FR30_OPERAND_RI
:
83 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_gr
, & fields
->f_Ri
);
85 case FR30_OPERAND_RJ
:
86 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_gr
, & fields
->f_Rj
);
88 case FR30_OPERAND_RS1
:
89 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_dr
, & fields
->f_Rs1
);
91 case FR30_OPERAND_RS2
:
92 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_dr
, & fields
->f_Rs2
);
94 case FR30_OPERAND_R13
:
95 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_r13
, & fields
->f_nil
);
97 case FR30_OPERAND_R14
:
98 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_r14
, & fields
->f_nil
);
100 case FR30_OPERAND_R15
:
101 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_r15
, & fields
->f_nil
);
103 case FR30_OPERAND_PS
:
104 errmsg
= cgen_parse_keyword (od
, strp
, & fr30_cgen_opval_h_ps
, & fields
->f_nil
);
106 case FR30_OPERAND_U4
:
107 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_U4
, &fields
->f_u4
);
109 case FR30_OPERAND_M4
:
110 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_M4
, &fields
->f_m4
);
112 case FR30_OPERAND_U8
:
113 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_U8
, &fields
->f_u8
);
115 case FR30_OPERAND_I8
:
116 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_I8
, &fields
->f_i8
);
118 case FR30_OPERAND_UDISP6
:
119 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_UDISP6
, &fields
->f_udisp6
);
121 case FR30_OPERAND_DISP8
:
122 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_DISP8
, &fields
->f_disp8
);
124 case FR30_OPERAND_DISP9
:
125 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_DISP9
, &fields
->f_disp9
);
127 case FR30_OPERAND_DISP10
:
128 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_DISP10
, &fields
->f_disp10
);
130 case FR30_OPERAND_S10
:
131 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_S10
, &fields
->f_s10
);
133 case FR30_OPERAND_U10
:
134 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_U10
, &fields
->f_u10
);
136 case FR30_OPERAND_I32
:
137 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_I32
, &fields
->f_i32
);
139 case FR30_OPERAND_DIR8
:
140 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_DIR8
, &fields
->f_dir8
);
142 case FR30_OPERAND_DIR9
:
143 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_DIR9
, &fields
->f_dir9
);
145 case FR30_OPERAND_DIR10
:
146 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_DIR10
, &fields
->f_dir10
);
148 case FR30_OPERAND_LABEL9
:
149 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_LABEL9
, &fields
->f_rel9
);
151 case FR30_OPERAND_LABEL12
:
152 errmsg
= cgen_parse_signed_integer (od
, strp
, FR30_OPERAND_LABEL12
, &fields
->f_rel12
);
154 case FR30_OPERAND_CC
:
155 errmsg
= cgen_parse_unsigned_integer (od
, strp
, FR30_OPERAND_CC
, &fields
->f_cc
);
159 /* xgettext:c-format */
160 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
167 /* Main entry point for operand insertion.
169 This function is basically just a big switch statement. Earlier versions
170 used tables to look up the function to use, but
171 - if the table contains both assembler and disassembler functions then
172 the disassembler contains much of the assembler and vice-versa,
173 - there's a lot of inlining possibilities as things grow,
174 - using a switch statement avoids the function call overhead.
176 This function could be moved into `parse_insn_normal', but keeping it
177 separate makes clear the interface between `parse_insn_normal' and each of
178 the handlers. It's also needed by GAS to insert operands that couldn't be
179 resolved during parsing.
183 fr30_cgen_insert_operand (od
, opindex
, fields
, buffer
, pc
)
186 CGEN_FIELDS
* fields
;
187 CGEN_INSN_BYTES_PTR buffer
;
194 case FR30_OPERAND_RI
:
195 errmsg
= insert_normal (od
, fields
->f_Ri
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 12, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
197 case FR30_OPERAND_RJ
:
198 errmsg
= insert_normal (od
, fields
->f_Rj
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 8, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
200 case FR30_OPERAND_RS1
:
201 errmsg
= insert_normal (od
, fields
->f_Rs1
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 8, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
203 case FR30_OPERAND_RS2
:
204 errmsg
= insert_normal (od
, fields
->f_Rs2
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 12, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
206 case FR30_OPERAND_R13
:
207 errmsg
= insert_normal (od
, fields
->f_nil
, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields
), buffer
);
209 case FR30_OPERAND_R14
:
210 errmsg
= insert_normal (od
, fields
->f_nil
, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields
), buffer
);
212 case FR30_OPERAND_R15
:
213 errmsg
= insert_normal (od
, fields
->f_nil
, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields
), buffer
);
215 case FR30_OPERAND_PS
:
216 errmsg
= insert_normal (od
, fields
->f_nil
, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields
), buffer
);
218 case FR30_OPERAND_U4
:
219 errmsg
= insert_normal (od
, fields
->f_u4
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 8, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
221 case FR30_OPERAND_M4
:
223 long value
= fields
->f_m4
;
224 value
= ((value
) & (15));
225 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 8, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
228 case FR30_OPERAND_U8
:
229 errmsg
= insert_normal (od
, fields
->f_u8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
231 case FR30_OPERAND_I8
:
232 errmsg
= insert_normal (od
, fields
->f_i8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 4, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
234 case FR30_OPERAND_UDISP6
:
236 long value
= fields
->f_udisp6
;
237 value
= ((unsigned int) (value
) >> (2));
238 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 8, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
241 case FR30_OPERAND_DISP8
:
242 errmsg
= insert_normal (od
, fields
->f_disp8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 4, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
244 case FR30_OPERAND_DISP9
:
246 long value
= fields
->f_disp9
;
247 value
= ((int) (value
) >> (1));
248 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 4, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
251 case FR30_OPERAND_DISP10
:
253 long value
= fields
->f_disp10
;
254 value
= ((int) (value
) >> (2));
255 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 4, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
258 case FR30_OPERAND_S10
:
260 long value
= fields
->f_s10
;
261 value
= ((int) (value
) >> (2));
262 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
265 case FR30_OPERAND_U10
:
267 long value
= fields
->f_u10
;
268 value
= ((unsigned int) (value
) >> (2));
269 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
272 case FR30_OPERAND_I32
:
273 errmsg
= insert_normal (od
, fields
->f_i32
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGN_OPT
)|(1<<CGEN_OPERAND_UNSIGNED
), 16, 32, CGEN_FIELDS_BITSIZE (fields
), buffer
);
275 case FR30_OPERAND_DIR8
:
276 errmsg
= insert_normal (od
, fields
->f_dir8
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
278 case FR30_OPERAND_DIR9
:
280 long value
= fields
->f_dir9
;
281 value
= ((unsigned int) (value
) >> (1));
282 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
285 case FR30_OPERAND_DIR10
:
287 long value
= fields
->f_dir10
;
288 value
= ((unsigned int) (value
) >> (2));
289 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
292 case FR30_OPERAND_LABEL9
:
294 long value
= fields
->f_rel9
;
295 value
= ((int) (((value
) - (((pc
) & (-2))))) >> (1));
296 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_SIGNED
), 8, 8, CGEN_FIELDS_BITSIZE (fields
), buffer
);
299 case FR30_OPERAND_LABEL12
:
301 long value
= fields
->f_rel12
;
302 value
= ((int) (((value
) - (((pc
) & (-2))))) >> (1));
303 errmsg
= insert_normal (od
, value
, 0|(1<<CGEN_OPERAND_SIGNED
), 5, 11, CGEN_FIELDS_BITSIZE (fields
), buffer
);
306 case FR30_OPERAND_CC
:
307 errmsg
= insert_normal (od
, fields
->f_cc
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 4, 4, CGEN_FIELDS_BITSIZE (fields
), buffer
);
311 /* xgettext:c-format */
312 fprintf (stderr
, _("Unrecognized field %d while building insn.\n"),
320 cgen_parse_fn
* const fr30_cgen_parse_handlers
[] =
326 cgen_insert_fn
* const fr30_cgen_insert_handlers
[] =
333 fr30_cgen_init_asm (od
)
339 #if ! CGEN_INT_INSN_P
341 /* Subroutine of insert_normal. */
344 insert_1 (od
, value
, start
, length
, word_length
, bufp
)
347 int start
,length
,word_length
;
350 unsigned long x
,mask
;
352 int big_p
= CGEN_OPCODE_INSN_ENDIAN (od
) == CGEN_ENDIAN_BIG
;
361 x
= bfd_getb16 (bufp
);
363 x
= bfd_getl16 (bufp
);
366 /* ??? This may need reworking as these cases don't necessarily
367 want the first byte and the last two bytes handled like this. */
369 x
= (bufp
[0] << 16) | bfd_getb16 (bufp
+ 1);
371 x
= bfd_getl16 (bufp
) | (bufp
[2] << 16);
375 x
= bfd_getb32 (bufp
);
377 x
= bfd_getl32 (bufp
);
383 /* Written this way to avoid undefined behaviour. */
384 mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
385 if (CGEN_INSN_LSB0_P
)
388 shift
= (word_length
- (start
+ length
));
389 x
= (x
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
398 bfd_putb16 (x
, bufp
);
400 bfd_putl16 (x
, bufp
);
403 /* ??? This may need reworking as these cases don't necessarily
404 want the first byte and the last two bytes handled like this. */
408 bfd_putb16 (x
, bufp
+ 1);
412 bfd_putl16 (x
, bufp
);
418 bfd_putb32 (x
, bufp
);
420 bfd_putl32 (x
, bufp
);
427 #endif /* ! CGEN_INT_INSN_P */
429 /* Default insertion routine.
431 ATTRS is a mask of the boolean attributes.
432 START is the starting bit number, architecture origin.
433 LENGTH is the length of VALUE in bits.
434 TOTAL_LENGTH is the total length of the insn.
436 The result is an error message or NULL if success. */
438 /* ??? This duplicates functionality with bfd's howto table and
439 bfd_install_relocation. */
440 /* ??? For architectures where insns can be representable as ints,
441 store insn in `field' struct and add registers, etc. while parsing? */
442 /* ??? This doesn't handle bfd_vma's. Create another function when
446 insert_normal (od
, value
, attrs
, start
, length
, total_length
, buffer
)
453 CGEN_INSN_BYTES_PTR buffer
;
455 static char errbuf
[100];
456 /* Written this way to avoid undefined behaviour. */
457 unsigned long mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
459 /* If LENGTH is zero, this operand doesn't contribute to the value. */
463 /* Ensure VALUE will fit. */
464 if ((attrs
& CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED
)) != 0)
466 unsigned long maxval
= mask
;
467 if ((unsigned long) value
> maxval
)
469 /* xgettext:c-format */
471 _("operand out of range (%lu not between 0 and %lu)"),
478 long minval
= - (1L << (length
- 1));
479 long maxval
= (1L << (length
- 1)) - 1;
480 if (value
< minval
|| value
> maxval
)
483 /* xgettext:c-format */
484 (errbuf
, _("operand out of range (%ld not between %ld and %ld)"),
485 value
, minval
, maxval
);
492 if (total_length
> 32) /* 32 bits in a portable host int */
497 if (CGEN_INSN_LSB0_P
)
500 shift
= total_length
- (start
+ length
);
501 *buffer
= (*buffer
& ~(mask
<< shift
)) | ((value
& mask
) << shift
);
506 /* FIXME: unfinished and untested */
508 /* The hard case is probably too slow for the normal cases.
509 It's certainly more difficult to understand than the normal case.
510 Thus this is split into two. The hard case is defined
511 to be when a field straddles a (loosely defined) word boundary
512 (??? which may require target specific help to determine). */
516 #define HARD_CASE_P 0 /* FIXME:wip */
520 unsigned char *bufp
= (unsigned char *) buffer
;
521 int insn_length_left
= total_length
;
523 if (CGEN_INSN_LSB0_P
)
525 int word_offset
= (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
527 : start
/ CGEN_BASE_INSN_BITSIZE
);
528 bufp
+= word_offset
* (CGEN_BASE_INSN_BITSIZE
/ 8);
529 if (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
)
531 start
-= word_offset
* CGEN_BASE_INSN_BITSIZE
;
535 int word_offset
= (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
536 ? start
/ CGEN_BASE_INSN_BITSIZE
538 bufp
+= word_offset
* (CGEN_BASE_INSN_BITSIZE
/ 8);
539 if (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
)
540 start
-= word_offset
* CGEN_BASE_INSN_BITSIZE
;
544 /* Loop so we handle a field straddling an insn word boundary
545 (remember, "insn word boundary" is loosely defined here). */
549 int this_pass_length
= length
;
550 int this_pass_start
= start
;
551 int this_pass_word_length
= min (insn_length_left
,
552 (CGEN_BASE_INSN_BITSIZE
== 8
554 : CGEN_BASE_INSN_BITSIZE
));
556 insert_1 (od
, value
, attrs
,
557 this_pass_start
, this_pass_length
, this_pass_word_length
,
560 length
-= this_pass_length
;
561 insn_length_left
-= this_pass_word_length
;
572 bufp
+= this_pass_word_length
/ 8;
578 unsigned char *bufp
= (unsigned char *) buffer
;
583 /* Adjust start,total_length,bufp to point to the pseudo-word that holds
584 the value. For example in a 48 bit insn where the value to insert
585 (say an immediate value) is the last 16 bits then fetch_length here
586 would be 16. To handle a 24 bit insn with an 18 bit immediate,
587 insert_1 handles 24 bits. */
589 if (total_length
> 32)
591 int needed_width
= start
% 8 + length
;
592 int fetch_length
= (needed_width
<= 8 ? 8
593 : needed_width
<= 16 ? 16
596 if (CGEN_INSN_LSB0_P
)
598 if (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
)
604 int offset
= start
& ~7;
608 total_length
= fetch_length
;
613 if (CGEN_INSN_WORD_ENDIAN (od
) == CGEN_ENDIAN_BIG
)
615 int offset
= start
& ~7;
619 total_length
= fetch_length
;
628 insert_1 (od
, value
, start
, length
, total_length
, bufp
);
631 #endif /* ! CGEN_INT_INSN_P */
636 /* Default insn parser.
638 The syntax string is scanned and operands are parsed and stored in FIELDS.
639 Relocs are queued as we go via other callbacks.
641 ??? Note that this is currently an all-or-nothing parser. If we fail to
642 parse the instruction, we return 0 and the caller will start over from
643 the beginning. Backtracking will be necessary in parsing subexpressions,
644 but that can be handled there. Not handling backtracking here may get
645 expensive in the case of the m68k. Deal with later.
647 Returns NULL for success, an error message for failure.
651 parse_insn_normal (od
, insn
, strp
, fields
)
653 const CGEN_INSN
* insn
;
655 CGEN_FIELDS
* fields
;
657 const CGEN_SYNTAX
* syntax
= CGEN_INSN_SYNTAX (insn
);
658 const char * str
= *strp
;
661 const unsigned char * syn
;
662 #ifdef CGEN_MNEMONIC_OPERANDS
667 /* For now we assume the mnemonic is first (there are no leading operands).
668 We can parse it without needing to set up operand parsing.
669 GAS's input scrubber will ensure mnemonics are lowercase, but we may
670 not be called from GAS. */
671 p
= CGEN_INSN_MNEMONIC (insn
);
672 while (*p
&& tolower (*p
) == tolower (*str
))
675 if (* p
|| (* str
&& !isspace (* str
)))
676 return _("unrecognized instruction");
678 CGEN_INIT_PARSE (od
);
679 cgen_init_parse_operand (od
);
680 #ifdef CGEN_MNEMONIC_OPERANDS
684 /* We don't check for (*str != '\0') here because we want to parse
685 any trailing fake arguments in the syntax string. */
686 syn
= CGEN_SYNTAX_STRING (syntax
);
688 /* Mnemonics come first for now, ensure valid string. */
689 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
696 /* Non operand chars must match exactly. */
697 if (CGEN_SYNTAX_CHAR_P (* syn
))
699 if (*str
== CGEN_SYNTAX_CHAR (* syn
))
701 #ifdef CGEN_MNEMONIC_OPERANDS
710 /* Syntax char didn't match. Can't be this insn. */
711 /* FIXME: would like to return something like
712 "expected char `c'" */
713 return _("syntax error");
718 /* We have an operand of some sort. */
719 errmsg
= fr30_cgen_parse_operand (od
, CGEN_SYNTAX_FIELD (*syn
),
724 /* Done with this operand, continue with next one. */
728 /* If we're at the end of the syntax string, we're done. */
731 /* FIXME: For the moment we assume a valid `str' can only contain
732 blanks now. IE: We needn't try again with a longer version of
733 the insn and it is assumed that longer versions of insns appear
734 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
735 while (isspace (* str
))
739 return _("junk at end of line"); /* FIXME: would like to include `str' */
744 /* We couldn't parse it. */
745 return _("unrecognized instruction");
748 /* Default insn builder (insert handler).
749 The instruction is recorded in CGEN_INT_INSN_P byte order
750 (meaning that if CGEN_INT_INSN_P BUFFER is an int * and thus the value is
751 recorded in host byte order, otherwise BUFFER is an array of bytes and the
752 value is recorded in target byte order).
753 The result is an error message or NULL if success. */
756 insert_insn_normal (od
, insn
, fields
, buffer
, pc
)
758 const CGEN_INSN
* insn
;
759 CGEN_FIELDS
* fields
;
760 CGEN_INSN_BYTES_PTR buffer
;
763 const CGEN_SYNTAX
* syntax
= CGEN_INSN_SYNTAX (insn
);
765 const unsigned char * syn
;
767 CGEN_INIT_INSERT (od
);
768 value
= CGEN_INSN_VALUE (insn
);
770 /* If we're recording insns as numbers (rather than a string of bytes),
771 target byte order handling is deferred until later. */
779 cgen_put_insn_value (od
, buffer
, min (CGEN_BASE_INSN_BITSIZE
,
780 CGEN_FIELDS_BITSIZE (fields
)),
783 #endif /* ! CGEN_INT_INSN_P */
785 /* ??? Rather than scanning the syntax string again, we could store
786 in `fields' a null terminated list of the fields that are present. */
788 for (syn
= CGEN_SYNTAX_STRING (syntax
); * syn
!= '\0'; ++ syn
)
792 if (CGEN_SYNTAX_CHAR_P (* syn
))
795 errmsg
= fr30_cgen_insert_operand (od
, CGEN_SYNTAX_FIELD (*syn
),
805 This routine is called for each instruction to be assembled.
806 STR points to the insn to be assembled.
807 We assume all necessary tables have been initialized.
808 The assembled instruction, less any fixups, is stored in BUF.
809 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
810 still needs to be converted to target byte order, otherwise BUF is an array
811 of bytes in target byte order.
812 The result is a pointer to the insn's entry in the opcode table,
813 or NULL if an error occured (an error message will have already been
816 Note that when processing (non-alias) macro-insns,
817 this function recurses. */
820 fr30_cgen_assemble_insn (od
, str
, fields
, buf
, errmsg
)
823 CGEN_FIELDS
* fields
;
824 CGEN_INSN_BYTES_PTR buf
;
828 CGEN_INSN_LIST
* ilist
;
830 /* Skip leading white space. */
831 while (isspace (* str
))
834 /* The instructions are stored in hashed lists.
835 Get the first in the list. */
836 ilist
= CGEN_ASM_LOOKUP_INSN (od
, str
);
838 /* Keep looking until we find a match. */
841 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
843 const CGEN_INSN
*insn
= ilist
->insn
;
845 #if 0 /* not needed as unsupported opcodes shouldn't be in the hash lists */
846 /* Is this insn supported by the selected cpu? */
847 if (! fr30_cgen_insn_supported (od
, insn
))
851 /* If the RELAX attribute is set, this is an insn that shouldn't be
852 chosen immediately. Instead, it is used during assembler/linker
853 relaxation if possible. */
854 if (CGEN_INSN_ATTR (insn
, CGEN_INSN_RELAX
) != 0)
859 /* Record a default length for the insn. This will get set to the
860 correct value while parsing. */
862 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
864 if (! CGEN_PARSE_FN (insn
) (od
, insn
, & str
, fields
))
866 /* ??? 0 is passed for `pc' */
867 if (CGEN_INSERT_FN (insn
) (od
, insn
, fields
, buf
, (bfd_vma
) 0) != NULL
)
869 /* It is up to the caller to actually output the insn and any
874 /* Try the next entry. */
877 /* FIXME: We can return a better error message than this.
878 Need to track why it failed and pick the right one. */
880 static char errbuf
[100];
881 if (strlen (start
) > 50)
882 /* xgettext:c-format */
883 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
885 /* xgettext:c-format */
886 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);
893 #if 0 /* This calls back to GAS which we can't do without care. */
895 /* Record each member of OPVALS in the assembler's symbol table.
896 This lets GAS parse registers for us.
897 ??? Interesting idea but not currently used. */
899 /* Record each member of OPVALS in the assembler's symbol table.
900 FIXME: Not currently used. */
903 fr30_cgen_asm_hash_keywords (od
, opvals
)
905 CGEN_KEYWORD
* opvals
;
907 CGEN_KEYWORD_SEARCH search
= cgen_keyword_search_init (opvals
, NULL
);
908 const CGEN_KEYWORD_ENTRY
* ke
;
910 while ((ke
= cgen_keyword_search_next (& search
)) != NULL
)
912 #if 0 /* Unnecessary, should be done in the search routine. */
913 if (! fr30_cgen_opval_supported (ke
))
916 cgen_asm_record_register (od
, ke
->name
, ke
->value
);