cgen header file
[deliverable/binutils-gdb.git] / include / opcode / cgen.h
1 /* Header file for targets using CGEN: Cpu tools GENerator.
2
3 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
4
5 This file is part of GDB, the GNU debugger, and the GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #ifndef CGEN_H
22 #define CGEN_H
23
24 #ifndef CGEN_CAT3
25 #if defined(__STDC__) || defined(ALMOST_STDC)
26 #define CGEN_XCAT3(a,b,c) a ## b ## c
27 #define CGEN_CAT3(a,b,c) CGEN_XCAT3 (a, b, c)
28 #else
29 #define CGEN_CAT3(a,b,c) a/**/b/**/c
30 #endif
31 #endif
32
33 /* Prepend the cpu name, defined in cpu-opc.h, and _cgen_ to symbol S.
34 The lack of spaces in the arg list is important for non-stdc systems.
35 This file is included by <cpu>-opc.h.
36 It can be included independently of cpu-opc.h, in which case the cpu
37 dependent portions will be declared as "unknown_cgen_foo". */
38
39 #ifndef CGEN_SYM
40 #define CGEN_SYM(s) CGEN_CAT3 (unknown,_cgen_,s)
41 #endif
42
43 /* This file contains the static (unchanging) pieces and as much other stuff
44 as we can reasonably put here. It's generally cleaner to put stuff here
45 rather than having it machine generated if possible. */
46
47 /* The assembler syntax is made up of expressions (duh...).
48 At the lowest level the values are mnemonics, register names, numbers, etc.
49 Above that are subexpressions, if any (an example might be the
50 "effective address" in m68k cpus). At the second highest level are the
51 insns themselves. Above that are pseudo-insns, synthetic insns, and macros,
52 if any.
53 */
54 \f
55 /* Lots of cpu's have a fixed insn size, or one which rarely changes,
56 and it's generally easier to handle these by treating the insn as an
57 integer type, rather than an array of characters. So we allow targets
58 to control this. */
59
60 #ifdef CGEN_INT_INSN
61 typedef unsigned int cgen_insn_t;
62 #else
63 typedef char *cgen_insn_t;
64 #endif
65
66 #ifdef __GNUC__
67 #define CGEN_INLINE inline
68 #else
69 #define CGEN_INLINE
70 #endif
71
72 /* Perhaps we should just use bfd.h, but it's not clear
73 one would want to require that yet. */
74 enum cgen_endian {
75 CGEN_ENDIAN_UNKNOWN,
76 CGEN_ENDIAN_LITTLE,
77 CGEN_ENDIAN_BIG
78 };
79 \f
80 /* Attributes.
81 Attributes are used to describe various random things. */
82
83 /* Struct to record attribute information. */
84 typedef struct {
85 unsigned int num_nonbools;
86 unsigned int bool;
87 unsigned int nonbool[1];
88 } CGEN_ATTR;
89
90 /* Define a structure member for attributes with N non-boolean entries.
91 The attributes are sorted so that the non-boolean ones come first.
92 num_nonbools: count of nonboolean attributes
93 bool: values of boolean attributes
94 nonbool: values of non-boolean attributes
95 There is a maximum of 32 attributes total. */
96 #define CGEN_ATTR_TYPE(n) \
97 const struct { unsigned int num_nonbools; \
98 unsigned int bool; \
99 unsigned int nonbool[(n) ? (n) : 1]; }
100
101 /* Given an attribute number, return its mask. */
102 #define CGEN_ATTR_MASK(attr) (1 << (attr))
103
104 /* Return value of attribute ATTR in ATTR_TABLE for OBJ.
105 OBJ is a pointer to the entity that has the attributes.
106 It's not used at present but is reserved for future purposes. */
107 #define CGEN_ATTR_VALUE(obj, attr_table, attr) \
108 ((unsigned int) (attr) < (attr_table)->num_nonbools \
109 ? ((attr_table)->nonbool[attr]) \
110 : (((attr_table)->bool & (1 << (attr))) != 0))
111 \f
112 /* Parse result (also extraction result).
113
114 The result of parsing an insn is stored here.
115 To generate the actual insn, this is passed to the insert handler.
116 When printing an insn, the result of extraction is stored here.
117 To print the insn, this is passed to the print handler.
118
119 It is machine generated so we don't define it here,
120 but we do need a forward decl for the handler fns.
121
122 There is one member for each possible field in the insn.
123 The type depends on the field.
124 Also recorded here is the computed length of the insn for architectures
125 where it varies.
126 */
127
128 struct cgen_fields;
129
130 /* Total length of the insn, as recorded in the `fields' struct. */
131 /* ??? The field insert handler has lots of opportunities for optimization
132 if it ever gets inlined. On architectures where insns all have the same
133 size, may wish to detect that and make this macro a constant - to allow
134 further optimizations. */
135 #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)
136 \f
137 /* Associated with each insn or expression is a set of "handlers" for
138 performing operations like parsing, printing, etc. */
139
140 /* Forward decl. */
141 typedef struct cgen_insn CGEN_INSN;
142
143 /* Parse handler.
144 The first argument is a pointer to a struct describing the insn being
145 parsed.
146 The second argument is a pointer to a pointer to the text being parsed.
147 The third argument is a pointer to a cgen_fields struct
148 in which the results are placed.
149 If the expression is successfully parsed, the pointer to the text is
150 updated. If not it is left alone.
151 The result is NULL if success or an error message. */
152 typedef const char * (cgen_parse_fn) PARAMS ((const struct cgen_insn *,
153 const char **,
154 struct cgen_fields *));
155
156 /* Print handler.
157 The first argument is a pointer to the disassembly info.
158 Eg: disassemble_info. It's defined as `PTR' so this file can be included
159 without dis-asm.h.
160 The second argument is a pointer to a struct describing the insn being
161 printed.
162 The third argument is a pointer to a cgen_fields struct.
163 The fourth argument is the pc value of the insn.
164 The fifth argument is the length of the insn, in bytes. */
165 /* Don't require bfd.h unnecessarily. */
166 #ifdef BFD_VERSION
167 typedef void (cgen_print_fn) PARAMS ((PTR, const struct cgen_insn *,
168 struct cgen_fields *, bfd_vma, int));
169 #else
170 typedef void (cgen_print_fn) ();
171 #endif
172
173 /* Insert handler.
174 The first argument is a pointer to a struct describing the insn being
175 parsed.
176 The second argument is a pointer to a cgen_fields struct
177 from which the values are fetched.
178 The third argument is a pointer to a buffer in which to place the insn. */
179 typedef void (cgen_insert_fn) PARAMS ((const struct cgen_insn *,
180 struct cgen_fields *, cgen_insn_t *));
181
182 /* Extract handler.
183 The first argument is a pointer to a struct describing the insn being
184 parsed.
185 The second argument is a pointer to a struct controlling extraction
186 (only used for variable length insns).
187 The third argument is the first CGEN_BASE_INSN_SIZE bytes.
188 The fourth argument is a pointer to a cgen_fields struct
189 in which the results are placed.
190 The result is the length of the insn or zero if not recognized. */
191 typedef int (cgen_extract_fn) PARAMS ((const struct cgen_insn *,
192 void *, cgen_insn_t,
193 struct cgen_fields *));
194
195 /* The `parse' and `insert' fields are indices into these tables.
196 The elements are pointer to specialized handler functions.
197 Element 0 is special, it means use the default handler. */
198 extern cgen_parse_fn * CGEN_SYM (parse_handlers) [];
199 #define CGEN_PARSE_FN(x) (CGEN_SYM (parse_handlers)[(x)->base.parse])
200 extern cgen_insert_fn * CGEN_SYM (insert_handlers) [];
201 #define CGEN_INSERT_FN(x) (CGEN_SYM (insert_handlers)[(x)->base.insert])
202
203 /* Likewise for the `extract' and `print' fields. */
204 extern cgen_extract_fn * CGEN_SYM (extract_handlers) [];
205 #define CGEN_EXTRACT_FN(x) (CGEN_SYM (extract_handlers)[(x)->base.extract])
206 extern cgen_print_fn * CGEN_SYM (print_handlers) [];
207 #define CGEN_PRINT_FN(x) (CGEN_SYM (print_handlers)[(x)->base.print])
208 \f
209 /* Base class of parser/printer.
210 (Don't read too much into the use of the phrase "base class").
211
212 Instructions and expressions all share this data in common.
213 It's a collection of the common elements needed to parse and print
214 each of them. */
215
216 #ifndef CGEN_MAX_INSN_ATTRS
217 #define CGEN_MAX_INSN_ATTRS 1
218 #endif
219
220 struct cgen_base {
221 /* Indices into the handler tables.
222 We could use pointers here instead, but in the case of the insn table,
223 90% of them would be identical and that's a lot of redundant data.
224 0 means use the default (what the default is is up to the code). */
225 unsigned char parse, insert, extract, print;
226
227 /* Attributes. */
228 CGEN_ATTR_TYPE (CGEN_MAX_INSN_ATTRS) attrs;
229 };
230 \f
231 /* Syntax table.
232
233 Each insn and subexpression has one of these.
234
235 The syntax "string" consists of characters (n > 0 && n < 128), and operand
236 values (n >= 128), and is terminated by 0. Operand values are 128 + index
237 into the operand table. The operand table doesn't exist in C, per se, as
238 the data is recorded in the parse/insert/extract/print switch statements.
239
240 ??? Whether we want to use yacc instead is unclear, but we do make an
241 effort to not make doing that difficult. At least that's the intent.
242 */
243
244 struct cgen_syntax {
245 /* Original syntax string, for debugging purposes. */
246 char *orig;
247
248 /* Name of entry (that distinguishes it from all other entries).
249 This is used, for example, in simulator profiling results. */
250 char *name;
251
252 #if 0 /* not needed yet */
253 /* Format of this insn.
254 This doesn't closely follow the notion of instruction formats for more
255 complex instruction sets. This is the value computed at runtime. */
256 enum cgen_fmt_type fmt;
257 #endif
258
259 /* Mnemonic (or name if expression). */
260 char *mnemonic;
261
262 /* Syntax string. */
263 /* FIXME: If each insn's mnemonic is constant, do we want to record just
264 the arguments here? */
265 #ifndef CGEN_MAX_SYNTAX_BYTES
266 #define CGEN_MAX_SYNTAX_BYTES 16
267 #endif
268 unsigned char syntax[CGEN_MAX_SYNTAX_BYTES];
269
270 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
271 #define CGEN_SYNTAX_CHAR(c) (c)
272 #define CGEN_SYNTAX_FIELD(c) ((c) - 128)
273
274 /* recognize insn if (op & mask) == value
275 For architectures with variable length insns, this is just a preliminary
276 test. */
277 /* FIXME: Might want a selectable type (rather than always
278 unsigned long). */
279 unsigned long mask, value;
280
281 /* length, in bits
282 This is the size that `mask' and `value' have been calculated to.
283 Normally it is CGEN_BASE_INSN_BITSIZE. On vliw architectures where
284 the base insn size may be larger than the size of an insn, this field is
285 less than CGEN_BASE_INSN_BITSIZE.
286 On architectures like the 386 and m68k the real size of the insn may
287 be computed while parsing. */
288 /* FIXME: wip, of course */
289 int length;
290 };
291 \f
292 /* Operand values (keywords, integers, symbols, etc.) */
293
294 /* Types of assembler elements. */
295
296 enum cgen_asm_type {
297 CGEN_ASM_KEYWORD, CGEN_ASM_MAX
298 };
299
300 /* List of hardware elements. */
301
302 typedef struct cgen_hw_entry {
303 struct cgen_hw_entry *next;
304 char *name;
305 enum cgen_asm_type asm_type;
306 PTR asm_data;
307 } CGEN_HW_ENTRY;
308
309 extern CGEN_HW_ENTRY *CGEN_SYM (hw_list);
310
311 CGEN_HW_ENTRY *cgen_hw_lookup PARAMS ((const char *));
312
313 #ifndef CGEN_MAX_KEYWORD_ATTRS
314 #define CGEN_MAX_KEYWORD_ATTRS 1
315 #endif
316
317 /* This struct is used to describe things like register names, etc. */
318
319 typedef struct cgen_keyword_entry {
320 /* Name (as in register name). */
321 char *name;
322
323 /* Value (as in register number).
324 The value cannot be -1 as that is used to indicate "not found".
325 IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */
326 int value;
327
328 /* Attributes. */
329 /* FIXME: Not used yet. */
330 CGEN_ATTR_TYPE (CGEN_MAX_KEYWORD_ATTRS) attrs;
331
332 /* Next name hash table entry. */
333 struct cgen_keyword_entry *next_name;
334 /* Next value hash table entry. */
335 struct cgen_keyword_entry *next_value;
336 } CGEN_KEYWORD_ENTRY;
337
338 /* Top level struct for describing a set of related keywords
339 (e.g. register names).
340
341 This struct supports runtime entry of new values, and hashed lookups. */
342
343 typedef struct cgen_keyword {
344 /* Pointer to initial [compiled in] values. */
345 struct cgen_keyword_entry *init_entries;
346 /* Number of entries in `init_entries'. */
347 unsigned int num_init_entries;
348 /* Hash table used for name lookup. */
349 struct cgen_keyword_entry **name_hash_table;
350 /* Hash table used for value lookup. */
351 struct cgen_keyword_entry **value_hash_table;
352 /* Number of entries in the hash_tables. */
353 unsigned int hash_table_size;
354 } CGEN_KEYWORD;
355
356 /* Structure used for searching. */
357
358 typedef struct cgen_keyword_search {
359 /* Table being searched. */
360 const struct cgen_keyword *table;
361 /* Specification of what is being searched for. */
362 const char *spec;
363 /* Current index in hash table. */
364 unsigned int current_hash;
365 /* Current element in current hash chain. */
366 struct cgen_keyword_entry *current_entry;
367 } CGEN_KEYWORD_SEARCH;
368
369 /* Lookup a keyword from its name. */
370 const struct cgen_keyword_entry * cgen_keyword_lookup_name
371 PARAMS ((struct cgen_keyword *, const char *));
372 /* Lookup a keyword from its value. */
373 const struct cgen_keyword_entry * cgen_keyword_lookup_value
374 PARAMS ((struct cgen_keyword *, int));
375 /* Add a keyword. */
376 void cgen_keyword_add PARAMS ((struct cgen_keyword *,
377 struct cgen_keyword_entry *));
378 /* Keyword searching.
379 This can be used to retrieve every keyword, or a subset. */
380 struct cgen_keyword_search cgen_keyword_search_init
381 PARAMS ((struct cgen_keyword *, const char *));
382 const struct cgen_keyword_entry *cgen_keyword_search_next
383 PARAMS ((struct cgen_keyword_search *));
384
385 /* Operand value support routines. */
386 /* FIXME: some of the long's here will need to be bfd_vma or some such. */
387
388 const char * cgen_parse_keyword PARAMS ((const char **,
389 struct cgen_keyword *,
390 long *));
391 const char * cgen_parse_signed_integer PARAMS ((const char **, int,
392 long, long, long *));
393 const char * cgen_parse_unsigned_integer PARAMS ((const char **, int,
394 unsigned long, unsigned long,
395 unsigned long *));
396 const char * cgen_parse_address PARAMS ((const char **, int,
397 int, long *));
398 const char * cgen_validate_signed_integer PARAMS ((long, long, long));
399 const char * cgen_validate_unsigned_integer PARAMS ((unsigned long,
400 unsigned long,
401 unsigned long));
402 \f
403 /* This struct defines each entry in the operand table. */
404
405 #ifndef CGEN_MAX_OPERAND_ATTRS
406 #define CGEN_MAX_OPERAND_ATTRS 1
407 #endif
408
409 typedef struct cgen_operand {
410 /* For debugging. */
411 char *name;
412
413 /* Bit position (msb of first byte = bit 0).
414 May be unused for a modifier. */
415 unsigned char start;
416
417 /* The number of bits in the operand.
418 May be unused for a modifier. */
419 unsigned char length;
420
421 /* Attributes. */
422 CGEN_ATTR_TYPE (CGEN_MAX_OPERAND_ATTRS) attrs;
423 #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs)
424
425 #if 0 /* ??? Interesting idea but relocs tend to get too complicated for
426 simple table lookups to work. */
427 /* Ideally this would be the internal (external?) reloc type. */
428 int reloc_type;
429 #endif
430 } CGEN_OPERAND;
431
432 /* Return value of attribute ATTR in OPERAND. */
433 #define CGEN_OPERAND_ATTR(operand, attr) \
434 CGEN_ATTR_VALUE (operand, CGEN_OPERAND_ATTRS (operand), attr)
435
436 /* The operand table is currently a very static entity. */
437 extern const CGEN_OPERAND CGEN_SYM (operand_table)[];
438
439 enum cgen_operand_type;
440
441 #define CGEN_OPERAND_INDEX(operand) ((int) ((operand) - CGEN_SYM (operand_table)))
442 /* FIXME: Rename, cpu-opc.h defines this as the typedef of the enum. */
443 #define CGEN_OPERAND_TYPE(operand) ((enum cgen_operand_type) CGEN_OPERAND_INDEX (operand))
444 #define CGEN_OPERAND_ENTRY(n) (& CGEN_SYM (operand_table) [n])
445 \f
446 /* This struct defines each entry in the instruction table. */
447
448 struct cgen_insn {
449 struct cgen_base base;
450 /* Given a pointer to a cgen_insn struct, return a pointer to `base'. */
451 #define CGEN_INSN_BASE(insn) (&(insn)->base)
452 #define CGEN_INSN_ATTRS(insn) (&(insn)->base.attrs)
453
454 struct cgen_syntax syntax;
455 #define CGEN_INSN_SYNTAX(insn) (&(insn)->syntax)
456 #define CGEN_INSN_FMT(insn) ((insn)->syntax.fmt)
457 #define CGEN_INSN_BITSIZE(insn) ((insn)->syntax.length)
458 };
459
460 /* Return value of attribute ATTR in INSN. */
461 #define CGEN_INSN_ATTR(insn, attr) \
462 CGEN_ATTR_VALUE (insn, CGEN_INSN_ATTRS (insn), attr)
463
464 /* Instruction lists.
465 This is used for adding new entries and for creating the hash lists. */
466
467 typedef struct cgen_insn_list {
468 struct cgen_insn_list *next;
469 const struct cgen_insn *insn;
470 } CGEN_INSN_LIST;
471
472 /* The table of instructions. */
473
474 typedef struct cgen_insn_table {
475 /* Pointer to initial [compiled in] entries. */
476 const struct cgen_insn *init_entries;
477 /* Number of entries in `init_entries', including trailing NULL entry. */
478 unsigned int num_init_entries;
479 /* Values added at runtime. */
480 struct cgen_insn_list *new_entries;
481 /* Assembler hash function. */
482 unsigned int (*asm_hash) PARAMS ((const char *));
483 /* Number of entries in assembler hash table. */
484 unsigned int asm_hash_table_size;
485 /* Disassembler hash function. */
486 unsigned int (*dis_hash) PARAMS ((const char *, unsigned long));
487 /* Number of entries in disassembler hash table. */
488 unsigned int dis_hash_table_size;
489 } CGEN_INSN_TABLE;
490
491 /* ??? This is currently used by the simulator.
492 We want this to be fast and the simulator currently doesn't handle
493 runtime added instructions so this is ok. An alternative would be to
494 store the index in the table. */
495 extern const CGEN_INSN CGEN_SYM (insn_table_entries)[];
496 #define CGEN_INSN_INDEX(insn) ((int) ((insn) - CGEN_SYM (insn_table_entries)))
497 #define CGEN_INSN_ENTRY(n) (& CGEN_SYM (insn_table_entries) [n])
498
499 /* Return number of instructions. This includes any added at runtime. */
500
501 int cgen_insn_count PARAMS (());
502
503 /* The assembler insn table is hashed based on some function of the mnemonic
504 (the actually hashing done is up to the target, but we provide a few
505 examples like the first letter or a function of the entire mnemonic).
506 The index of each entry is the index of the corresponding table entry.
507 The value of each entry is the index of the next entry, with a 0
508 terminating (thus the first entry is reserved). */
509
510 #ifndef CGEN_ASM_HASH
511 #ifdef CGEN_MNEMONIC_OPERANDS
512 #define CGEN_ASM_HASH_SIZE 127
513 #define CGEN_ASM_HASH(string) (*(unsigned char *) (string) % CGEN_ASM_HASH_SIZE)
514 #else
515 #define CGEN_ASM_HASH_SIZE 128
516 #define CGEN_ASM_HASH(string) (*(unsigned char *) (string) % CGEN_ASM_HASH_SIZE) /*FIXME*/
517 #endif
518 #endif
519
520 unsigned int CGEN_SYM (asm_hash_insn) PARAMS ((const char *));
521 CGEN_INSN_LIST * cgen_asm_lookup_insn PARAMS ((const char *));
522 #define CGEN_ASM_LOOKUP_INSN(insn) cgen_asm_lookup_insn (insn)
523 #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next)
524
525 /* The disassembler insn table is hashed based on some function of machine
526 instruction (the actually hashing done is up to the target). */
527
528 /* It doesn't make much sense to provide a default here,
529 but while this is under development we do.
530 BUFFER is a pointer to the bytes of the insn.
531 INSN is the first CGEN_BASE_INSN_SIZE bytes as an int in host order. */
532 #ifndef CGEN_DIS_HASH
533 #define CGEN_DIS_HASH_SIZE 256
534 #define CGEN_DIS_HASH(buffer, insn) (*(unsigned char *) (buffer))
535 #endif
536
537 unsigned int CGEN_SYM (dis_hash_insn) PARAMS ((const char *, unsigned long));
538 CGEN_INSN_LIST * cgen_dis_lookup_insn PARAMS ((const char *, unsigned long));
539 #define CGEN_DIS_LOOKUP_INSN(buf, insn) cgen_dis_lookup_insn (buf, insn)
540 #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next)
541 \f
542 /* Top level structures and functions. */
543
544 typedef struct cgen_opcode_data {
545 CGEN_HW_ENTRY *hw_list;
546 /*CGEN_OPERAND_TABLE *operand_table; - FIXME:wip */
547 CGEN_INSN_TABLE *insn_table;
548 } CGEN_OPCODE_DATA;
549
550 /* Each CPU has one of these. */
551 extern CGEN_OPCODE_DATA CGEN_SYM (opcode_data);
552
553 /* Global state access macros.
554 Some of these are tucked away and accessed with cover fns.
555 Simpler things like the current machine and endian are not. */
556
557 extern int cgen_current_machine;
558 #define CGEN_CURRENT_MACHINE cgen_current_machine
559
560 extern enum cgen_endian cgen_current_endian;
561 #define CGEN_CURRENT_ENDIAN cgen_current_endian
562
563 /* Prototypes of major functions. */
564
565 /* Set the current cpu (+ mach number, endian, etc.). *?
566 void cgen_set_cpu PARAMS ((CGEN_OPCODE_DATA *, int, enum cgen_endian));
567
568 /* Initialize the assembler, disassembler. */
569 void cgen_asm_init PARAMS ((void));
570 void cgen_dis_init PARAMS ((void));
571
572 /* `init_tables' must be called before `xxx_supported'. */
573 void CGEN_SYM (init_tables) PARAMS ((int));
574 void CGEN_SYM (init_asm) PARAMS ((int, enum cgen_endian));
575 void CGEN_SYM (init_dis) PARAMS ((int, enum cgen_endian));
576 void CGEN_SYM (init_parse) PARAMS ((void));
577 void CGEN_SYM (init_print) PARAMS ((void));
578 void CGEN_SYM (init_insert) PARAMS ((void));
579 void CGEN_SYM (init_extract) PARAMS ((void));
580 const struct cgen_insn *
581 CGEN_SYM (assemble_insn) PARAMS ((const char *, struct cgen_fields *,
582 cgen_insn_t *));
583 int CGEN_SYM (insn_supported) PARAMS ((const struct cgen_syntax *));
584 #if 0 /* old */
585 int CGEN_SYM (opval_supported) PARAMS ((const struct cgen_opval *));
586 #endif
587
588 extern const struct cgen_keyword CGEN_SYM (operand_mach);
589 int CGEN_SYM (get_mach) PARAMS ((const char *));
590
591 CGEN_INLINE void
592 CGEN_SYM (put_operand) PARAMS ((int, const long *,
593 struct cgen_fields *));
594 CGEN_INLINE long
595 CGEN_SYM (get_operand) PARAMS ((int, const struct cgen_fields *));
596
597 CGEN_INLINE const char *
598 CGEN_SYM (parse_operand) PARAMS ((int, const char **, struct cgen_fields *));
599
600 CGEN_INLINE const char *
601 CGEN_SYM (validate_operand) PARAMS ((int, const struct cgen_fields *));
602
603 /* Default insn parser, printer. */
604 extern cgen_parse_fn CGEN_SYM (parse_insn);
605 extern cgen_insert_fn CGEN_SYM (insert_insn);
606 extern cgen_extract_fn CGEN_SYM (extract_insn);
607 extern cgen_print_fn CGEN_SYM (print_insn);
608
609 /* Read in a cpu description file. */
610 const char * cgen_read_cpu_file PARAMS ((const char *));
611 \f
612 /* The interface to the assembler is intended to be clean in the sense that
613 libopcodes.a is a standalone entity and could be used with any assembler.
614 Well, that's the intention. Given that, we define an interface between us
615 and the assembler. The interface will obviously be slanted towards gas,
616 but at least it's a start.
617
618 Parsing is controlled by the assembler which calls
619 CGEN_SYM (assemble_insn). If it can parse and build the entire insn
620 it doesn't call back to the assembler. If it needs/wants to call back
621 to the assembler, cgen_asm_parse_operand is called.
622 cgen_asm_parse_operand can either
623 - return a number to be inserted in the insn
624 - return a "register" value to be inserted
625 (the register might not be a register per pe)
626 - queue the argument and return a marker saying the expression has been
627 queued (eg: a fix-up)
628 - return an error message indicating the expression wasn't recognizable
629 After parsing is done, CGEN_SYM (assemble_insn) calls
630 cgen_asm_finish_insn to output the insn and record the relocs.
631 */
632
633 /* Call this for each insn to initialize the assembler callback interface. */
634 void cgen_asm_insn_init PARAMS ((void));
635
636 /* Add a register to the assembler's hash table.
637 This makes lets GAS parse registers for us.
638 ??? This isn't currently used, but it could be in the future. */
639 void cgen_asm_record_register PARAMS ((char *, int));
640
641 enum cgen_asm_result {
642 CGEN_ASM_NUMBER, CGEN_ASM_REGISTER, CGEN_ASM_QUEUED, CGEN_ASM_ERROR
643 };
644
645 /* Don't require bfd.h unnecessarily. */
646 #ifdef BFD_VERSION
647 const char *cgen_asm_parse_operand PARAMS ((const char **, int, int,
648 enum cgen_asm_result *,
649 bfd_vma *));
650 #endif
651
652 void cgen_asm_finish_insn PARAMS ((const struct cgen_insn *, cgen_insn_t *,
653 unsigned int));
654
655 #endif /* CGEN_H */
This page took 0.044217 seconds and 5 git commands to generate.