00001 /* 00002 * Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* Header file for targets using CGEN: Cpu tools GENerator. 00006 00007 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 00008 Free Software Foundation, Inc. 00009 00010 This file is part of GDB, the GNU debugger, and the GNU Binutils. 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License along 00023 with this program; if not, write to the Free Software Foundation, Inc., 00024 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00025 00026 #ifndef CGEN_H 00027 #define CGEN_H 00028 00029 /* ??? This file requires bfd.h but only to get bfd_vma. 00030 Seems like an awful lot to require just to get such a fundamental type. 00031 Perhaps the definition of bfd_vma can be moved outside of bfd.h. 00032 Or perhaps one could duplicate its definition in another file. 00033 Until such time, this file conditionally compiles definitions that require 00034 bfd_vma using __BFD_H_SEEN__. */ 00035 00036 /* Enums must be defined before they can be used. 00037 Allow them to be used in struct definitions, even though the enum must 00038 be defined elsewhere. 00039 If CGEN_ARCH isn't defined, this file is being included by something other 00040 than <arch>-desc.h. */ 00041 00042 /* Prepend the arch name, defined in <arch>-desc.h, and _cgen_ to symbol S. 00043 The lack of spaces in the arg list is important for non-stdc systems. 00044 This file is included by <arch>-desc.h. 00045 It can be included independently of <arch>-desc.h, in which case the arch 00046 dependent portions will be declared as "unknown_cgen_foo". */ 00047 00048 #ifndef CGEN_SYM 00049 #define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s) 00050 #endif 00051 00052 /* This file contains the static (unchanging) pieces and as much other stuff 00053 as we can reasonably put here. It's generally cleaner to put stuff here 00054 rather than having it machine generated if possible. */ 00055 00056 /* The assembler syntax is made up of expressions (duh...). 00057 At the lowest level the values are mnemonics, register names, numbers, etc. 00058 Above that are subexpressions, if any (an example might be the 00059 "effective address" in m68k cpus). Subexpressions are wip. 00060 At the second highest level are the insns themselves. Above that are 00061 pseudo-insns, synthetic insns, and macros, if any. */ 00062 00063 /* Lots of cpu's have a fixed insn size, or one which rarely changes, 00064 and it's generally easier to handle these by treating the insn as an 00065 integer type, rather than an array of characters. So we allow targets 00066 to control this. When an integer type the value is in host byte order, 00067 when an array of characters the value is in target byte order. */ 00068 00069 typedef unsigned int CGEN_INSN_INT; 00070 #if CGEN_INT_INSN_P 00071 typedef CGEN_INSN_INT CGEN_INSN_BYTES; 00072 typedef CGEN_INSN_INT *CGEN_INSN_BYTES_PTR; 00073 #else 00074 typedef unsigned char *CGEN_INSN_BYTES; 00075 typedef unsigned char *CGEN_INSN_BYTES_PTR; 00076 #endif 00077 00078 #ifdef __GNUC__ 00079 #define CGEN_INLINE __inline__ 00080 #else 00081 #define CGEN_INLINE 00082 #endif 00083 00084 enum cgen_endian 00085 { 00086 CGEN_ENDIAN_UNKNOWN, 00087 CGEN_ENDIAN_LITTLE, 00088 CGEN_ENDIAN_BIG 00089 }; 00090 00091 /* Forward decl. */ 00092 00093 typedef struct cgen_insn CGEN_INSN; 00094 00095 /* Opaque pointer version for use by external world. */ 00096 00097 typedef struct cgen_cpu_desc *CGEN_CPU_DESC; 00098 00099 /* Attributes. 00100 Attributes are used to describe various random things associated with 00101 an object (ifield, hardware, operand, insn, whatever) and are specified 00102 as name/value pairs. 00103 Integer attributes computed at compile time are currently all that's 00104 supported, though adding string attributes and run-time computation is 00105 straightforward. Integer attribute values are always host int's 00106 (signed or unsigned). For portability, this means 32 bits. 00107 Integer attributes are further categorized as boolean, bitset, integer, 00108 and enum types. Boolean attributes appear frequently enough that they're 00109 recorded in one host int. This limits the maximum number of boolean 00110 attributes to 32, though that's a *lot* of attributes. */ 00111 00112 /* Type of attribute values. */ 00113 00114 typedef int CGEN_ATTR_VALUE_TYPE; 00115 00116 /* Struct to record attribute information. */ 00117 00118 typedef struct 00119 { 00120 /* Boolean attributes. */ 00121 unsigned int bool; 00122 /* Non-boolean integer attributes. */ 00123 CGEN_ATTR_VALUE_TYPE nonbool[1]; 00124 } CGEN_ATTR; 00125 00126 /* Define a structure member for attributes with N non-boolean entries. 00127 There is no maximum number of non-boolean attributes. 00128 There is a maximum of 32 boolean attributes (since they are all recorded 00129 in one host int). */ 00130 00131 #define CGEN_ATTR_TYPE(n) \ 00132 struct { unsigned int bool; \ 00133 CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; } 00134 00135 /* Return the boolean attributes. */ 00136 00137 #define CGEN_ATTR_BOOLS(a) ((a)->bool) 00138 00139 /* Non-boolean attribute numbers are offset by this much. */ 00140 00141 #define CGEN_ATTR_NBOOL_OFFSET 32 00142 00143 /* Given a boolean attribute number, return its mask. */ 00144 00145 #define CGEN_ATTR_MASK(attr) (1 << (attr)) 00146 00147 /* Return the value of boolean attribute ATTR in ATTRS. */ 00148 00149 #define CGEN_BOOL_ATTR(attrs, attr) ((CGEN_ATTR_MASK (attr) & (attrs)) != 0) 00150 00151 /* Return value of attribute ATTR in ATTR_TABLE for OBJ. 00152 OBJ is a pointer to the entity that has the attributes 00153 (??? not used at present but is reserved for future purposes - eventually 00154 the goal is to allow recording attributes in source form and computing 00155 them lazily at runtime, not sure of the details yet). */ 00156 00157 #define CGEN_ATTR_VALUE(obj, attr_table, attr) \ 00158 ((unsigned int) (attr) < CGEN_ATTR_NBOOL_OFFSET \ 00159 ? ((CGEN_ATTR_BOOLS (attr_table) & CGEN_ATTR_MASK (attr)) != 0) \ 00160 : ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET])) 00161 00162 /* Attribute name/value tables. 00163 These are used to assist parsing of descriptions at run-time. */ 00164 00165 typedef struct 00166 { 00167 const char * name; 00168 CGEN_ATTR_VALUE_TYPE value; 00169 } CGEN_ATTR_ENTRY; 00170 00171 /* For each domain (ifld,hw,operand,insn), list of attributes. */ 00172 00173 typedef struct 00174 { 00175 const char * name; 00176 const CGEN_ATTR_ENTRY * dfault; 00177 const CGEN_ATTR_ENTRY * vals; 00178 } CGEN_ATTR_TABLE; 00179 00180 /* Instruction set variants. */ 00181 00182 typedef struct { 00183 const char *name; 00184 00185 /* Default instruction size (in bits). 00186 This is used by the assembler when it encounters an unknown insn. */ 00187 unsigned int default_insn_bitsize; 00188 00189 /* Base instruction size (in bits). 00190 For non-LIW cpus this is generally the length of the smallest insn. 00191 For LIW cpus its wip (work-in-progress). For the m32r its 32. */ 00192 unsigned int base_insn_bitsize; 00193 00194 /* Minimum/maximum instruction size (in bits). */ 00195 unsigned int min_insn_bitsize; 00196 unsigned int max_insn_bitsize; 00197 } CGEN_ISA; 00198 00199 /* Machine variants. */ 00200 00201 typedef struct { 00202 const char *name; 00203 /* The argument to bfd_arch_info->scan. */ 00204 const char *bfd_name; 00205 /* one of enum mach_attr */ 00206 int num; 00207 /* parameter from mach->cpu */ 00208 unsigned int insn_chunk_bitsize; 00209 } CGEN_MACH; 00210 00211 /* Parse result (also extraction result). 00212 00213 The result of parsing an insn is stored here. 00214 To generate the actual insn, this is passed to the insert handler. 00215 When printing an insn, the result of extraction is stored here. 00216 To print the insn, this is passed to the print handler. 00217 00218 It is machine generated so we don't define it here, 00219 but we do need a forward decl for the handler fns. 00220 00221 There is one member for each possible field in the insn. 00222 The type depends on the field. 00223 Also recorded here is the computed length of the insn for architectures 00224 where it varies. 00225 */ 00226 00227 typedef struct cgen_fields CGEN_FIELDS; 00228 00229 /* Total length of the insn, as recorded in the `fields' struct. */ 00230 /* ??? The field insert handler has lots of opportunities for optimization 00231 if it ever gets inlined. On architectures where insns all have the same 00232 size, may wish to detect that and make this macro a constant - to allow 00233 further optimizations. */ 00234 00235 #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length) 00236 00237 /* Extraction support for variable length insn sets. */ 00238 00239 /* When disassembling we don't know the number of bytes to read at the start. 00240 So the first CGEN_BASE_INSN_SIZE bytes are read at the start and the rest 00241 are read when needed. This struct controls this. It is basically the 00242 disassemble_info stuff, except that we provide a cache for values already 00243 read (since bytes can typically be read several times to fetch multiple 00244 operands that may be in them), and that extraction of fields is needed 00245 in contexts other than disassembly. */ 00246 00247 typedef struct { 00248 /* A pointer to the disassemble_info struct. 00249 We don't require dis-asm.h so we use void * for the type here. 00250 If NULL, BYTES is full of valid data (VALID == -1). */ 00251 void *dis_info; 00252 /* Points to a working buffer of sufficient size. */ 00253 unsigned char *insn_bytes; 00254 /* Mask of bytes that are valid in INSN_BYTES. */ 00255 unsigned int valid; 00256 } CGEN_EXTRACT_INFO; 00257 00258 /* Associated with each insn or expression is a set of "handlers" for 00259 performing operations like parsing, printing, etc. These require a bfd_vma 00260 value to be passed around but we don't want all applications to need bfd.h. 00261 So this stuff is only provided if bfd.h has been included. */ 00262 00263 /* Parse handler. 00264 CD is a cpu table descriptor. 00265 INSN is a pointer to a struct describing the insn being parsed. 00266 STRP is a pointer to a pointer to the text being parsed. 00267 FIELDS is a pointer to a cgen_fields struct in which the results are placed. 00268 If the expression is successfully parsed, *STRP is updated. 00269 If not it is left alone. 00270 The result is NULL if success or an error message. */ 00271 typedef const char * (cgen_parse_fn) 00272 (CGEN_CPU_DESC, const CGEN_INSN *insn_, 00273 const char **strp_, CGEN_FIELDS *fields_); 00274 00275 /* Insert handler. 00276 CD is a cpu table descriptor. 00277 INSN is a pointer to a struct describing the insn being parsed. 00278 FIELDS is a pointer to a cgen_fields struct from which the values 00279 are fetched. 00280 INSNP is a pointer to a buffer in which to place the insn. 00281 PC is the pc value of the insn. 00282 The result is an error message or NULL if success. */ 00283 00284 #ifdef __BFD_H_SEEN__ 00285 typedef const char * (cgen_insert_fn) 00286 (CGEN_CPU_DESC, const CGEN_INSN *insn_, 00287 CGEN_FIELDS *fields_, CGEN_INSN_BYTES_PTR insnp_, 00288 bfd_vma pc_); 00289 #else 00290 typedef const char * (cgen_insert_fn) (); 00291 #endif 00292 00293 /* Extract handler. 00294 CD is a cpu table descriptor. 00295 INSN is a pointer to a struct describing the insn being parsed. 00296 The second argument is a pointer to a struct controlling extraction 00297 (only used for variable length insns). 00298 EX_INFO is a pointer to a struct for controlling reading of further 00299 bytes for the insn. 00300 BASE_INSN is the first CGEN_BASE_INSN_SIZE bytes (host order). 00301 FIELDS is a pointer to a cgen_fields struct in which the results are placed. 00302 PC is the pc value of the insn. 00303 The result is the length of the insn in bits or zero if not recognized. */ 00304 00305 #ifdef __BFD_H_SEEN__ 00306 typedef int (cgen_extract_fn) 00307 (CGEN_CPU_DESC, const CGEN_INSN *insn_, 00308 CGEN_EXTRACT_INFO *ex_info_, CGEN_INSN_INT base_insn_, 00309 CGEN_FIELDS *fields_, bfd_vma pc_); 00310 #else 00311 typedef int (cgen_extract_fn) (); 00312 #endif 00313 00314 /* Print handler. 00315 CD is a cpu table descriptor. 00316 INFO is a pointer to the disassembly info. 00317 Eg: disassemble_info. It's defined as `PTR' so this file can be included 00318 without dis-asm.h. 00319 INSN is a pointer to a struct describing the insn being printed. 00320 FIELDS is a pointer to a cgen_fields struct. 00321 PC is the pc value of the insn. 00322 LEN is the length of the insn, in bits. */ 00323 00324 #ifdef __BFD_H_SEEN__ 00325 typedef void (cgen_print_fn) 00326 (CGEN_CPU_DESC, void * info_, const CGEN_INSN *insn_, 00327 CGEN_FIELDS *fields_, bfd_vma pc_, int len_); 00328 #else 00329 typedef void (cgen_print_fn) (); 00330 #endif 00331 00332 /* Parse/insert/extract/print handlers. 00333 00334 Indices into the handler tables. 00335 We could use pointers here instead, but 90% of them are generally identical 00336 and that's a lot of redundant data. Making these unsigned char indices 00337 into tables of pointers saves a bit of space. 00338 Using indices also keeps assembler code out of the disassembler and 00339 vice versa. */ 00340 00341 struct cgen_opcode_handler 00342 { 00343 unsigned char parse, insert, extract, print; 00344 }; 00345 00346 /* Assembler interface. 00347 00348 The interface to the assembler is intended to be clean in the sense that 00349 libopcodes.a is a standalone entity and could be used with any assembler. 00350 Not that one would necessarily want to do that but rather that it helps 00351 keep a clean interface. The interface will obviously be slanted towards 00352 GAS, but at least it's a start. 00353 ??? Note that one possible user of the assembler besides GAS is GDB. 00354 00355 Parsing is controlled by the assembler which calls 00356 CGEN_SYM (assemble_insn). If it can parse and build the entire insn 00357 it doesn't call back to the assembler. If it needs/wants to call back 00358 to the assembler, cgen_parse_operand_fn is called which can either 00359 00360 - return a number to be inserted in the insn 00361 - return a "register" value to be inserted 00362 (the register might not be a register per pe) 00363 - queue the argument and return a marker saying the expression has been 00364 queued (eg: a fix-up) 00365 - return an error message indicating the expression wasn't recognizable 00366 00367 The result is an error message or NULL for success. 00368 The parsed value is stored in the bfd_vma *. */ 00369 00370 /* Values for indicating what the caller wants. */ 00371 00372 enum cgen_parse_operand_type 00373 { 00374 CGEN_PARSE_OPERAND_INIT, 00375 CGEN_PARSE_OPERAND_INTEGER, 00376 CGEN_PARSE_OPERAND_ADDRESS, 00377 CGEN_PARSE_OPERAND_SYMBOLIC 00378 }; 00379 00380 /* Values for indicating what was parsed. */ 00381 00382 enum cgen_parse_operand_result 00383 { 00384 CGEN_PARSE_OPERAND_RESULT_NUMBER, 00385 CGEN_PARSE_OPERAND_RESULT_REGISTER, 00386 CGEN_PARSE_OPERAND_RESULT_QUEUED, 00387 CGEN_PARSE_OPERAND_RESULT_ERROR 00388 }; 00389 00390 #ifdef __BFD_H_SEEN__ /* Don't require bfd.h unnecessarily. */ 00391 typedef const char * (cgen_parse_operand_fn) 00392 (CGEN_CPU_DESC, 00393 enum cgen_parse_operand_type, const char **, int, int, 00394 enum cgen_parse_operand_result *, bfd_vma *); 00395 #else 00396 typedef const char * (cgen_parse_operand_fn) (); 00397 #endif 00398 00399 /* Set the cgen_parse_operand_fn callback. */ 00400 00401 extern void cgen_set_parse_operand_fn 00402 (CGEN_CPU_DESC, cgen_parse_operand_fn); 00403 00404 /* Called before trying to match a table entry with the insn. */ 00405 00406 extern void cgen_init_parse_operand (CGEN_CPU_DESC); 00407 00408 /* Operand values (keywords, integers, symbols, etc.) */ 00409 00410 /* Types of assembler elements. */ 00411 00412 enum cgen_asm_type 00413 { 00414 CGEN_ASM_NONE, CGEN_ASM_KEYWORD, CGEN_ASM_MAX 00415 }; 00416 00417 #ifndef CGEN_ARCH 00418 enum cgen_hw_type { CGEN_HW_MAX }; 00419 #endif 00420 00421 /* List of hardware elements. */ 00422 00423 typedef struct 00424 { 00425 char *name; 00426 enum cgen_hw_type type; 00427 /* There is currently no example where both index specs and value specs 00428 are required, so for now both are clumped under "asm_data". */ 00429 enum cgen_asm_type asm_type; 00430 void *asm_data; 00431 #ifndef CGEN_HW_NBOOL_ATTRS 00432 #define CGEN_HW_NBOOL_ATTRS 1 00433 #endif 00434 CGEN_ATTR_TYPE (CGEN_HW_NBOOL_ATTRS) attrs; 00435 #define CGEN_HW_ATTRS(hw) (&(hw)->attrs) 00436 } CGEN_HW_ENTRY; 00437 00438 /* Return value of attribute ATTR in HW. */ 00439 00440 #define CGEN_HW_ATTR_VALUE(hw, attr) \ 00441 CGEN_ATTR_VALUE ((hw), CGEN_HW_ATTRS (hw), (attr)) 00442 00443 /* Table of hardware elements for selected mach, computed at runtime. 00444 enum cgen_hw_type is an index into this table (specifically `entries'). */ 00445 00446 typedef struct { 00447 /* Pointer to null terminated table of all compiled in entries. */ 00448 const CGEN_HW_ENTRY *init_entries; 00449 unsigned int entry_size; /* since the attribute member is variable sized */ 00450 /* Array of all entries, initial and run-time added. */ 00451 const CGEN_HW_ENTRY **entries; 00452 /* Number of elements in `entries'. */ 00453 unsigned int num_entries; 00454 /* For now, xrealloc is called each time a new entry is added at runtime. 00455 ??? May wish to keep track of some slop to reduce the number of calls to 00456 xrealloc, except that there's unlikely to be many and not expected to be 00457 in speed critical code. */ 00458 } CGEN_HW_TABLE; 00459 00460 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_name 00461 (CGEN_CPU_DESC, const char *); 00462 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_num 00463 (CGEN_CPU_DESC, unsigned int); 00464 00465 /* This struct is used to describe things like register names, etc. */ 00466 00467 typedef struct cgen_keyword_entry 00468 { 00469 /* Name (as in register name). */ 00470 char * name; 00471 00472 /* Value (as in register number). 00473 The value cannot be -1 as that is used to indicate "not found". 00474 IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */ 00475 int value; 00476 00477 /* Attributes. 00478 This should, but technically needn't, appear last. It is a variable sized 00479 array in that one architecture may have 1 nonbool attribute and another 00480 may have more. Having this last means the non-architecture specific code 00481 needn't care. The goal is to eventually record 00482 attributes in their raw form, evaluate them at run-time, and cache the 00483 values, so this worry will go away anyway. */ 00484 /* ??? Moving this last should be done by treating keywords like insn lists 00485 and moving the `next' fields into a CGEN_KEYWORD_LIST struct. */ 00486 /* FIXME: Not used yet. */ 00487 #ifndef CGEN_KEYWORD_NBOOL_ATTRS 00488 #define CGEN_KEYWORD_NBOOL_ATTRS 1 00489 #endif 00490 CGEN_ATTR_TYPE (CGEN_KEYWORD_NBOOL_ATTRS) attrs; 00491 00492 /* ??? Putting these here means compiled in entries can't be const. 00493 Not a really big deal, but something to consider. */ 00494 /* Next name hash table entry. */ 00495 struct cgen_keyword_entry *next_name; 00496 /* Next value hash table entry. */ 00497 struct cgen_keyword_entry *next_value; 00498 } CGEN_KEYWORD_ENTRY; 00499 00500 /* Top level struct for describing a set of related keywords 00501 (e.g. register names). 00502 00503 This struct supports run-time entry of new values, and hashed lookups. */ 00504 00505 typedef struct cgen_keyword 00506 { 00507 /* Pointer to initial [compiled in] values. */ 00508 CGEN_KEYWORD_ENTRY *init_entries; 00509 00510 /* Number of entries in `init_entries'. */ 00511 unsigned int num_init_entries; 00512 00513 /* Hash table used for name lookup. */ 00514 CGEN_KEYWORD_ENTRY **name_hash_table; 00515 00516 /* Hash table used for value lookup. */ 00517 CGEN_KEYWORD_ENTRY **value_hash_table; 00518 00519 /* Number of entries in the hash_tables. */ 00520 unsigned int hash_table_size; 00521 00522 /* Pointer to null keyword "" entry if present. */ 00523 const CGEN_KEYWORD_ENTRY *null_entry; 00524 00525 /* String containing non-alphanumeric characters used 00526 in keywords. 00527 At present, the highest number of entries used is 1. */ 00528 char nonalpha_chars[8]; 00529 } CGEN_KEYWORD; 00530 00531 /* Structure used for searching. */ 00532 00533 typedef struct 00534 { 00535 /* Table being searched. */ 00536 const CGEN_KEYWORD *table; 00537 00538 /* Specification of what is being searched for. */ 00539 const char *spec; 00540 00541 /* Current index in hash table. */ 00542 unsigned int current_hash; 00543 00544 /* Current element in current hash chain. */ 00545 CGEN_KEYWORD_ENTRY *current_entry; 00546 } CGEN_KEYWORD_SEARCH; 00547 00548 /* Lookup a keyword from its name. */ 00549 00550 const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_name 00551 (CGEN_KEYWORD *, const char *); 00552 00553 /* Lookup a keyword from its value. */ 00554 00555 const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_value 00556 (CGEN_KEYWORD *, int); 00557 00558 /* Add a keyword. */ 00559 00560 void cgen_keyword_add (CGEN_KEYWORD *, CGEN_KEYWORD_ENTRY *); 00561 00562 /* Keyword searching. 00563 This can be used to retrieve every keyword, or a subset. */ 00564 00565 CGEN_KEYWORD_SEARCH cgen_keyword_search_init 00566 (CGEN_KEYWORD *, const char *); 00567 const CGEN_KEYWORD_ENTRY *cgen_keyword_search_next 00568 (CGEN_KEYWORD_SEARCH *); 00569 00570 /* Operand value support routines. */ 00571 00572 extern const char *cgen_parse_keyword 00573 (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *); 00574 #ifdef __BFD_H_SEEN__ /* Don't require bfd.h unnecessarily. */ 00575 extern const char *cgen_parse_signed_integer 00576 (CGEN_CPU_DESC, const char **, int, long *); 00577 extern const char *cgen_parse_unsigned_integer 00578 (CGEN_CPU_DESC, const char **, int, unsigned long *); 00579 extern const char *cgen_parse_address 00580 (CGEN_CPU_DESC, const char **, int, int, 00581 enum cgen_parse_operand_result *, bfd_vma *); 00582 extern const char *cgen_validate_signed_integer 00583 (long, long, long); 00584 extern const char *cgen_validate_unsigned_integer 00585 (unsigned long, unsigned long, unsigned long); 00586 #endif 00587 00588 /* Operand modes. */ 00589 00590 /* ??? This duplicates the values in arch.h. Revisit. 00591 These however need the CGEN_ prefix [as does everything in this file]. */ 00592 /* ??? Targets may need to add their own modes so we may wish to move this 00593 to <arch>-opc.h, or add a hook. */ 00594 00595 enum cgen_mode { 00596 CGEN_MODE_VOID, /* ??? rename simulator's VM to VOID? */ 00597 CGEN_MODE_BI, CGEN_MODE_QI, CGEN_MODE_HI, CGEN_MODE_SI, CGEN_MODE_DI, 00598 CGEN_MODE_UBI, CGEN_MODE_UQI, CGEN_MODE_UHI, CGEN_MODE_USI, CGEN_MODE_UDI, 00599 CGEN_MODE_SF, CGEN_MODE_DF, CGEN_MODE_XF, CGEN_MODE_TF, 00600 CGEN_MODE_TARGET_MAX, 00601 CGEN_MODE_INT, CGEN_MODE_UINT, 00602 CGEN_MODE_MAX 00603 }; 00604 00605 /* FIXME: Until simulator is updated. */ 00606 00607 #define CGEN_MODE_VM CGEN_MODE_VOID 00608 00609 /* Operands. */ 00610 00611 #ifndef CGEN_ARCH 00612 enum cgen_operand_type { CGEN_OPERAND_MAX }; 00613 #endif 00614 00615 /* "nil" indicator for the operand instance table */ 00616 #define CGEN_OPERAND_NIL CGEN_OPERAND_MAX 00617 00618 /* A tree of these structs represents the multi-ifield 00619 structure of an operand's hw-index value, if it exists. */ 00620 00621 struct cgen_ifld; 00622 00623 typedef struct cgen_maybe_multi_ifield 00624 { 00625 int count; /* 0: indexed by single cgen_ifld (possibly null: dead entry); 00626 n: indexed by array of more cgen_maybe_multi_ifields. */ 00627 union 00628 { 00629 const void *p; 00630 const struct cgen_maybe_multi_ifield * multi; 00631 const struct cgen_ifld * leaf; 00632 } val; 00633 } 00634 CGEN_MAYBE_MULTI_IFLD; 00635 00636 /* This struct defines each entry in the operand table. */ 00637 00638 typedef struct 00639 { 00640 /* Name as it appears in the syntax string. */ 00641 char *name; 00642 00643 /* Operand type. */ 00644 enum cgen_operand_type type; 00645 00646 /* The hardware element associated with this operand. */ 00647 enum cgen_hw_type hw_type; 00648 00649 /* FIXME: We don't yet record ifield definitions, which we should. 00650 When we do it might make sense to delete start/length (since they will 00651 be duplicated in the ifield's definition) and replace them with a 00652 pointer to the ifield entry. */ 00653 00654 /* Bit position. 00655 This is just a hint, and may be unused in more complex operands. 00656 May be unused for a modifier. */ 00657 unsigned char start; 00658 00659 /* The number of bits in the operand. 00660 This is just a hint, and may be unused in more complex operands. 00661 May be unused for a modifier. */ 00662 unsigned char length; 00663 00664 /* The (possibly-multi) ifield used as an index for this operand, if it 00665 is indexed by a field at all. This substitutes / extends the start and 00666 length fields above, but unsure at this time whether they are used 00667 anywhere. */ 00668 CGEN_MAYBE_MULTI_IFLD index_fields; 00669 #if 0 /* ??? Interesting idea but relocs tend to get too complicated, 00670 and ABI dependent, for simple table lookups to work. */ 00671 /* Ideally this would be the internal (external?) reloc type. */ 00672 int reloc_type; 00673 #endif 00674 00675 /* Attributes. 00676 This should, but technically needn't, appear last. It is a variable sized 00677 array in that one architecture may have 1 nonbool attribute and another 00678 may have more. Having this last means the non-architecture specific code 00679 needn't care, now or tomorrow. The goal is to eventually record 00680 attributes in their raw form, evaluate them at run-time, and cache the 00681 values, so this worry will go away anyway. */ 00682 #ifndef CGEN_OPERAND_NBOOL_ATTRS 00683 #define CGEN_OPERAND_NBOOL_ATTRS 1 00684 #endif 00685 CGEN_ATTR_TYPE (CGEN_OPERAND_NBOOL_ATTRS) attrs; 00686 #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs) 00687 } CGEN_OPERAND; 00688 00689 /* Return value of attribute ATTR in OPERAND. */ 00690 00691 #define CGEN_OPERAND_ATTR_VALUE(operand, attr) \ 00692 CGEN_ATTR_VALUE ((operand), CGEN_OPERAND_ATTRS (operand), (attr)) 00693 00694 /* Table of operands for selected mach/isa, computed at runtime. 00695 enum cgen_operand_type is an index into this table (specifically 00696 `entries'). */ 00697 00698 typedef struct { 00699 /* Pointer to null terminated table of all compiled in entries. */ 00700 const CGEN_OPERAND *init_entries; 00701 unsigned int entry_size; /* since the attribute member is variable sized */ 00702 /* Array of all entries, initial and run-time added. */ 00703 const CGEN_OPERAND **entries; 00704 /* Number of elements in `entries'. */ 00705 unsigned int num_entries; 00706 /* For now, xrealloc is called each time a new entry is added at runtime. 00707 ??? May wish to keep track of some slop to reduce the number of calls to 00708 xrealloc, except that there's unlikely to be many and not expected to be 00709 in speed critical code. */ 00710 } CGEN_OPERAND_TABLE; 00711 00712 extern const CGEN_OPERAND * cgen_operand_lookup_by_name 00713 (CGEN_CPU_DESC, const char *); 00714 extern const CGEN_OPERAND * cgen_operand_lookup_by_num 00715 (CGEN_CPU_DESC, int); 00716 00717 /* Instruction operand instances. 00718 00719 For each instruction, a list of the hardware elements that are read and 00720 written are recorded. */ 00721 00722 /* The type of the instance. */ 00723 00724 enum cgen_opinst_type { 00725 /* End of table marker. */ 00726 CGEN_OPINST_END = 0, 00727 CGEN_OPINST_INPUT, CGEN_OPINST_OUTPUT 00728 }; 00729 00730 typedef struct 00731 { 00732 /* Input or output indicator. */ 00733 enum cgen_opinst_type type; 00734 00735 /* Name of operand. */ 00736 const char *name; 00737 00738 /* The hardware element referenced. */ 00739 enum cgen_hw_type hw_type; 00740 00741 /* The mode in which the operand is being used. */ 00742 enum cgen_mode mode; 00743 00744 /* The operand table entry CGEN_OPERAND_NIL if there is none 00745 (i.e. an explicit hardware reference). */ 00746 enum cgen_operand_type op_type; 00747 00748 /* If `operand' is "nil", the index (e.g. into array of registers). */ 00749 int index; 00750 00751 /* Attributes. 00752 ??? This perhaps should be a real attribute struct but there's 00753 no current need, so we save a bit of space and just have a set of 00754 flags. The interface is such that this can easily be made attributes 00755 should it prove useful. */ 00756 unsigned int attrs; 00757 #define CGEN_OPINST_ATTRS(opinst) ((opinst)->attrs) 00758 /* Return value of attribute ATTR in OPINST. */ 00759 #define CGEN_OPINST_ATTR(opinst, attr) \ 00760 ((CGEN_OPINST_ATTRS (opinst) & (attr)) != 0) 00761 /* Operand is conditionally referenced (read/written). */ 00762 #define CGEN_OPINST_COND_REF 1 00763 } CGEN_OPINST; 00764 00765 /* Syntax string. 00766 00767 Each insn format and subexpression has one of these. 00768 00769 The syntax "string" consists of characters (n > 0 && n < 128), and operand 00770 values (n >= 128), and is terminated by 0. Operand values are 128 + index 00771 into the operand table. The operand table doesn't exist in C, per se, as 00772 the data is recorded in the parse/insert/extract/print switch statements. */ 00773 00774 /* This should be at least as large as necessary for any target. */ 00775 #define CGEN_MAX_SYNTAX_ELEMENTS 48 00776 00777 /* A target may know its own precise maximum. Assert that it falls below 00778 the above limit. */ 00779 #ifdef CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS 00780 #if CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS > CGEN_MAX_SYNTAX_ELEMENTS 00781 #error "CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS too high - enlarge CGEN_MAX_SYNTAX_ELEMENTS" 00782 #endif 00783 #endif 00784 00785 typedef unsigned short CGEN_SYNTAX_CHAR_TYPE; 00786 00787 typedef struct 00788 { 00789 CGEN_SYNTAX_CHAR_TYPE syntax[CGEN_MAX_SYNTAX_ELEMENTS]; 00790 } CGEN_SYNTAX; 00791 00792 #define CGEN_SYNTAX_STRING(syn) (syn->syntax) 00793 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128) 00794 #define CGEN_SYNTAX_CHAR(c) ((unsigned char)c) 00795 #define CGEN_SYNTAX_FIELD(c) ((c) - 128) 00796 #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128) 00797 00798 /* ??? I can't currently think of any case where the mnemonic doesn't come 00799 first [and if one ever doesn't building the hash tables will be tricky]. 00800 However, we treat mnemonics as just another operand of the instruction. 00801 A value of 1 means "this is where the mnemonic appears". 1 isn't 00802 special other than it's a non-printable ASCII char. */ 00803 00804 #define CGEN_SYNTAX_MNEMONIC 1 00805 #define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == CGEN_SYNTAX_MNEMONIC) 00806 00807 /* Instruction fields. 00808 00809 ??? We currently don't allow adding fields at run-time. 00810 Easy to fix when needed. */ 00811 00812 typedef struct cgen_ifld { 00813 /* Enum of ifield. */ 00814 int num; 00815 #define CGEN_IFLD_NUM(f) ((f)->num) 00816 00817 /* Name of the field, distinguishes it from all other fields. */ 00818 const char *name; 00819 #define CGEN_IFLD_NAME(f) ((f)->name) 00820 00821 /* Default offset, in bits, from the start of the insn to the word 00822 containing the field. */ 00823 int word_offset; 00824 #define CGEN_IFLD_WORD_OFFSET(f) ((f)->word_offset) 00825 00826 /* Default length of the word containing the field. */ 00827 int word_size; 00828 #define CGEN_IFLD_WORD_SIZE(f) ((f)->word_size) 00829 00830 /* Default starting bit number. 00831 Whether lsb=0 or msb=0 is determined by CGEN_INSN_LSB0_P. */ 00832 int start; 00833 #define CGEN_IFLD_START(f) ((f)->start) 00834 00835 /* Length of the field, in bits. */ 00836 int length; 00837 #define CGEN_IFLD_LENGTH(f) ((f)->length) 00838 00839 #ifndef CGEN_IFLD_NBOOL_ATTRS 00840 #define CGEN_IFLD_NBOOL_ATTRS 1 00841 #endif 00842 CGEN_ATTR_TYPE (CGEN_IFLD_NBOOL_ATTRS) attrs; 00843 #define CGEN_IFLD_ATTRS(f) (&(f)->attrs) 00844 } CGEN_IFLD; 00845 00846 /* Return value of attribute ATTR in IFLD. */ 00847 #define CGEN_IFLD_ATTR_VALUE(ifld, attr) \ 00848 CGEN_ATTR_VALUE ((ifld), CGEN_IFLD_ATTRS (ifld), (attr)) 00849 00850 /* Instruction data. */ 00851 00852 /* Instruction formats. 00853 00854 Instructions are grouped by format. Associated with an instruction is its 00855 format. Each insn's opcode table entry contains a format table entry. 00856 ??? There is usually very few formats compared with the number of insns, 00857 so one can reduce the size of the opcode table by recording the format table 00858 as a separate entity. Given that we currently don't, format table entries 00859 are also distinguished by their operands. This increases the size of the 00860 table, but reduces the number of tables. It's all minutiae anyway so it 00861 doesn't really matter [at this point in time]. 00862 00863 ??? Support for variable length ISA's is wip. */ 00864 00865 /* Accompanying each iformat description is a list of its fields. */ 00866 00867 typedef struct { 00868 const CGEN_IFLD *ifld; 00869 #define CGEN_IFMT_IFLD_IFLD(ii) ((ii)->ifld) 00870 } CGEN_IFMT_IFLD; 00871 00872 /* This should be at least as large as necessary for any target. */ 00873 #define CGEN_MAX_IFMT_OPERANDS 16 00874 00875 /* A target may know its own precise maximum. Assert that it falls below 00876 the above limit. */ 00877 #ifdef CGEN_ACTUAL_MAX_IFMT_OPERANDS 00878 #if CGEN_ACTUAL_MAX_IFMT_OPERANDS > CGEN_MAX_IFMT_OPERANDS 00879 #error "CGEN_ACTUAL_MAX_IFMT_OPERANDS too high - enlarge CGEN_MAX_IFMT_OPERANDS" 00880 #endif 00881 #endif 00882 00883 00884 typedef struct 00885 { 00886 /* Length that MASK and VALUE have been calculated to 00887 [VALUE is recorded elsewhere]. 00888 Normally it is base_insn_bitsize. On [V]LIW architectures where the base 00889 insn size may be larger than the size of an insn, this field is less than 00890 base_insn_bitsize. */ 00891 unsigned char mask_length; 00892 #define CGEN_IFMT_MASK_LENGTH(ifmt) ((ifmt)->mask_length) 00893 00894 /* Total length of instruction, in bits. */ 00895 unsigned char length; 00896 #define CGEN_IFMT_LENGTH(ifmt) ((ifmt)->length) 00897 00898 /* Mask to apply to the first MASK_LENGTH bits. 00899 Each insn's value is stored with the insn. 00900 The first step in recognizing an insn for disassembly is 00901 (opcode & mask) == value. */ 00902 CGEN_INSN_INT mask; 00903 #define CGEN_IFMT_MASK(ifmt) ((ifmt)->mask) 00904 00905 /* Instruction fields. 00906 +1 for trailing NULL. */ 00907 CGEN_IFMT_IFLD iflds[CGEN_MAX_IFMT_OPERANDS + 1]; 00908 #define CGEN_IFMT_IFLDS(ifmt) ((ifmt)->iflds) 00909 } CGEN_IFMT; 00910 00911 /* Instruction values. */ 00912 00913 typedef struct 00914 { 00915 /* The opcode portion of the base insn. */ 00916 CGEN_INSN_INT base_value; 00917 00918 #ifdef CGEN_MAX_EXTRA_OPCODE_OPERANDS 00919 /* Extra opcode values beyond base_value. */ 00920 unsigned long ifield_values[CGEN_MAX_EXTRA_OPCODE_OPERANDS]; 00921 #endif 00922 } CGEN_IVALUE; 00923 00924 /* Instruction opcode table. 00925 This contains the syntax and format data of an instruction. */ 00926 00927 /* ??? Some ports already have an opcode table yet still need to use the rest 00928 of what cgen_insn has. Plus keeping the opcode data with the operand 00929 instance data can create a pretty big file. So we keep them separately. 00930 Not sure this is a good idea in the long run. */ 00931 00932 typedef struct 00933 { 00934 /* Indices into parse/insert/extract/print handler tables. */ 00935 struct cgen_opcode_handler handlers; 00936 #define CGEN_OPCODE_HANDLERS(opc) (& (opc)->handlers) 00937 00938 /* Syntax string. */ 00939 CGEN_SYNTAX syntax; 00940 #define CGEN_OPCODE_SYNTAX(opc) (& (opc)->syntax) 00941 00942 /* Format entry. */ 00943 const CGEN_IFMT *format; 00944 #define CGEN_OPCODE_FORMAT(opc) ((opc)->format) 00945 #define CGEN_OPCODE_MASK_BITSIZE(opc) CGEN_IFMT_MASK_LENGTH (CGEN_OPCODE_FORMAT (opc)) 00946 #define CGEN_OPCODE_BITSIZE(opc) CGEN_IFMT_LENGTH (CGEN_OPCODE_FORMAT (opc)) 00947 #define CGEN_OPCODE_IFLDS(opc) CGEN_IFMT_IFLDS (CGEN_OPCODE_FORMAT (opc)) 00948 00949 /* Instruction opcode value. */ 00950 CGEN_IVALUE value; 00951 #define CGEN_OPCODE_VALUE(opc) (& (opc)->value) 00952 #define CGEN_OPCODE_BASE_VALUE(opc) (CGEN_OPCODE_VALUE (opc)->base_value) 00953 #define CGEN_OPCODE_BASE_MASK(opc) CGEN_IFMT_MASK (CGEN_OPCODE_FORMAT (opc)) 00954 } CGEN_OPCODE; 00955 00956 /* Instruction attributes. 00957 This is made a published type as applications can cache a pointer to 00958 the attributes for speed. */ 00959 00960 #ifndef CGEN_INSN_NBOOL_ATTRS 00961 #define CGEN_INSN_NBOOL_ATTRS 1 00962 #endif 00963 typedef CGEN_ATTR_TYPE (CGEN_INSN_NBOOL_ATTRS) CGEN_INSN_ATTR_TYPE; 00964 00965 /* Enum of architecture independent attributes. */ 00966 00967 #ifndef CGEN_ARCH 00968 /* ??? Numbers here are recorded in two places. */ 00969 typedef enum cgen_insn_attr { 00970 CGEN_INSN_ALIAS = 0 00971 } CGEN_INSN_ATTR; 00972 #endif 00973 00974 /* This struct defines each entry in the instruction table. */ 00975 00976 typedef struct 00977 { 00978 /* Each real instruction is enumerated. */ 00979 /* ??? This may go away in time. */ 00980 int num; 00981 #define CGEN_INSN_NUM(insn) ((insn)->base->num) 00982 00983 /* Name of entry (that distinguishes it from all other entries). */ 00984 /* ??? If mnemonics have operands, try to print full mnemonic. */ 00985 const char *name; 00986 #define CGEN_INSN_NAME(insn) ((insn)->base->name) 00987 00988 /* Mnemonic. This is used when parsing and printing the insn. 00989 In the case of insns that have operands on the mnemonics, this is 00990 only the constant part. E.g. for conditional execution of an `add' insn, 00991 where the full mnemonic is addeq, addne, etc., and the condition is 00992 treated as an operand, this is only "add". */ 00993 const char *mnemonic; 00994 #define CGEN_INSN_MNEMONIC(insn) ((insn)->base->mnemonic) 00995 00996 /* Total length of instruction, in bits. */ 00997 int bitsize; 00998 #define CGEN_INSN_BITSIZE(insn) ((insn)->base->bitsize) 00999 01000 #if 0 /* ??? Disabled for now as there is a problem with embedded newlines 01001 and the table is already pretty big. Should perhaps be moved 01002 to a file of its own. */ 01003 /* Semantics, as RTL. */ 01004 /* ??? Plain text or bytecodes? */ 01005 /* ??? Note that the operand instance table could be computed at run-time 01006 if we parse this and cache the results. Something to eventually do. */ 01007 const char *rtx; 01008 #define CGEN_INSN_RTX(insn) ((insn)->base->rtx) 01009 #endif 01010 01011 /* Attributes. 01012 This must appear last. It is a variable sized array in that one 01013 architecture may have 1 nonbool attribute and another may have more. 01014 Having this last means the non-architecture specific code needn't 01015 care. The goal is to eventually record attributes in their raw form, 01016 evaluate them at run-time, and cache the values, so this worry will go 01017 away anyway. */ 01018 CGEN_INSN_ATTR_TYPE attrs; 01019 #define CGEN_INSN_ATTRS(insn) (&(insn)->base->attrs) 01020 /* Return value of attribute ATTR in INSN. */ 01021 #define CGEN_INSN_ATTR_VALUE(insn, attr) \ 01022 CGEN_ATTR_VALUE ((insn), CGEN_INSN_ATTRS (insn), (attr)) 01023 } CGEN_IBASE; 01024 01025 /* Return non-zero if INSN is the "invalid" insn marker. */ 01026 01027 #define CGEN_INSN_INVALID_P(insn) (CGEN_INSN_MNEMONIC (insn) == 0) 01028 01029 /* Main struct contain instruction information. 01030 BASE is always present, the rest is present only if asked for. */ 01031 01032 struct cgen_insn 01033 { 01034 /* ??? May be of use to put a type indicator here. 01035 Then this struct could different info for different classes of insns. */ 01036 /* ??? A speedup can be had by moving `base' into this struct. 01037 Maybe later. */ 01038 const CGEN_IBASE *base; 01039 const CGEN_OPCODE *opcode; 01040 const CGEN_OPINST *opinst; 01041 01042 /* Regex to disambiguate overloaded opcodes */ 01043 void *rx; 01044 #define CGEN_INSN_RX(insn) ((insn)->rx) 01045 #define CGEN_MAX_RX_ELEMENTS (CGEN_MAX_SYNTAX_ELEMENTS * 5) 01046 }; 01047 01048 /* Instruction lists. 01049 This is used for adding new entries and for creating the hash lists. */ 01050 01051 typedef struct cgen_insn_list 01052 { 01053 struct cgen_insn_list *next; 01054 const CGEN_INSN *insn; 01055 } CGEN_INSN_LIST; 01056 01057 /* Table of instructions. */ 01058 01059 typedef struct 01060 { 01061 const CGEN_INSN *init_entries; 01062 unsigned int entry_size; /* since the attribute member is variable sized */ 01063 unsigned int num_init_entries; 01064 CGEN_INSN_LIST *new_entries; 01065 } CGEN_INSN_TABLE; 01066 01067 /* Return number of instructions. This includes any added at run-time. */ 01068 01069 extern int cgen_insn_count (CGEN_CPU_DESC); 01070 extern int cgen_macro_insn_count (CGEN_CPU_DESC); 01071 01072 /* Macros to access the other insn elements not recorded in CGEN_IBASE. */ 01073 01074 /* Fetch INSN's operand instance table. */ 01075 /* ??? Doesn't handle insns added at runtime. */ 01076 #define CGEN_INSN_OPERANDS(insn) ((insn)->opinst) 01077 01078 /* Return INSN's opcode table entry. */ 01079 #define CGEN_INSN_OPCODE(insn) ((insn)->opcode) 01080 01081 /* Return INSN's handler data. */ 01082 #define CGEN_INSN_HANDLERS(insn) CGEN_OPCODE_HANDLERS (CGEN_INSN_OPCODE (insn)) 01083 01084 /* Return INSN's syntax. */ 01085 #define CGEN_INSN_SYNTAX(insn) CGEN_OPCODE_SYNTAX (CGEN_INSN_OPCODE (insn)) 01086 01087 /* Return size of base mask in bits. */ 01088 #define CGEN_INSN_MASK_BITSIZE(insn) \ 01089 CGEN_OPCODE_MASK_BITSIZE (CGEN_INSN_OPCODE (insn)) 01090 01091 /* Return mask of base part of INSN. */ 01092 #define CGEN_INSN_BASE_MASK(insn) \ 01093 CGEN_OPCODE_BASE_MASK (CGEN_INSN_OPCODE (insn)) 01094 01095 /* Return value of base part of INSN. */ 01096 #define CGEN_INSN_BASE_VALUE(insn) \ 01097 CGEN_OPCODE_BASE_VALUE (CGEN_INSN_OPCODE (insn)) 01098 01099 /* Standard way to test whether INSN is supported by MACH. 01100 MACH is one of enum mach_attr. 01101 The "|1" is because the base mach is always selected. */ 01102 #define CGEN_INSN_MACH_HAS_P(insn, mach) \ 01103 ((CGEN_INSN_ATTR_VALUE ((insn), CGEN_INSN_MACH) & ((1 << (mach)) | 1)) != 0) 01104 01105 /* Macro instructions. 01106 Macro insns aren't real insns, they map to one or more real insns. 01107 E.g. An architecture's "nop" insn may actually be an "mv r0,r0" or 01108 some such. 01109 01110 Macro insns can expand to nothing (e.g. a nop that is optimized away). 01111 This is useful in multi-insn macros that build a constant in a register. 01112 Of course this isn't the default behaviour and must be explicitly enabled. 01113 01114 Assembly of macro-insns is relatively straightforward. Disassembly isn't. 01115 However, disassembly of at least some kinds of macro insns is important 01116 in order that the disassembled code preserve the readability of the original 01117 insn. What is attempted here is to disassemble all "simple" macro-insns, 01118 where "simple" is currently defined to mean "expands to one real insn". 01119 01120 Simple macro-insns are handled specially. They are emitted as ALIAS's 01121 of real insns. This simplifies their handling since there's usually more 01122 of them than any other kind of macro-insn, and proper disassembly of them 01123 falls out for free. */ 01124 01125 /* For each macro-insn there may be multiple expansion possibilities, 01126 depending on the arguments. This structure is accessed via the `data' 01127 member of CGEN_INSN. */ 01128 01129 typedef struct cgen_minsn_expansion { 01130 /* Function to do the expansion. 01131 If the expansion fails (e.g. "no match") NULL is returned. 01132 Space for the expansion is obtained with malloc. 01133 It is up to the caller to free it. */ 01134 const char * (* fn) 01135 (const struct cgen_minsn_expansion *, 01136 const char *, const char **, int *, 01137 CGEN_OPERAND **); 01138 #define CGEN_MIEXPN_FN(ex) ((ex)->fn) 01139 01140 /* Instruction(s) the macro expands to. 01141 The format of STR is defined by FN. 01142 It is typically the assembly code of the real insn, but it could also be 01143 the original Scheme expression or a tokenized form of it (with FN being 01144 an appropriate interpreter). */ 01145 const char * str; 01146 #define CGEN_MIEXPN_STR(ex) ((ex)->str) 01147 } CGEN_MINSN_EXPANSION; 01148 01149 /* Normal expander. 01150 When supported, this function will convert the input string to another 01151 string and the parser will be invoked recursively. The output string 01152 may contain further macro invocations. */ 01153 01154 extern const char * cgen_expand_macro_insn 01155 (CGEN_CPU_DESC, const struct cgen_minsn_expansion *, 01156 const char *, const char **, int *, CGEN_OPERAND **); 01157 01158 /* The assembler insn table is hashed based on some function of the mnemonic 01159 (the actually hashing done is up to the target, but we provide a few 01160 examples like the first letter or a function of the entire mnemonic). */ 01161 01162 extern CGEN_INSN_LIST * cgen_asm_lookup_insn 01163 (CGEN_CPU_DESC, const char *); 01164 #define CGEN_ASM_LOOKUP_INSN(cd, string) cgen_asm_lookup_insn ((cd), (string)) 01165 #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next) 01166 01167 /* The disassembler insn table is hashed based on some function of machine 01168 instruction (the actually hashing done is up to the target). */ 01169 01170 extern CGEN_INSN_LIST * cgen_dis_lookup_insn 01171 (CGEN_CPU_DESC, const char *, CGEN_INSN_INT); 01172 /* FIXME: delete these two */ 01173 #define CGEN_DIS_LOOKUP_INSN(cd, buf, value) cgen_dis_lookup_insn ((cd), (buf), (value)) 01174 #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next) 01175 01176 /* The CPU description. 01177 A copy of this is created when the cpu table is "opened". 01178 All global state information is recorded here. 01179 Access macros are provided for "public" members. */ 01180 01181 typedef struct cgen_cpu_desc 01182 { 01183 /* Bitmap of selected machine(s) (a la BFD machine number). */ 01184 int machs; 01185 01186 /* Bitmap of selected isa(s). 01187 ??? Simultaneous multiple isas might not make sense, but it's not (yet) 01188 precluded. */ 01189 int isas; 01190 01191 /* Current endian. */ 01192 enum cgen_endian endian; 01193 #define CGEN_CPU_ENDIAN(cd) ((cd)->endian) 01194 01195 /* Current insn endian. */ 01196 enum cgen_endian insn_endian; 01197 #define CGEN_CPU_INSN_ENDIAN(cd) ((cd)->insn_endian) 01198 01199 /* Word size (in bits). */ 01200 /* ??? Or maybe maximum word size - might we ever need to allow a cpu table 01201 to be opened for both sparc32/sparc64? 01202 ??? Another alternative is to create a table of selected machs and 01203 lazily fetch the data from there. */ 01204 unsigned int word_bitsize; 01205 01206 /* Instruction chunk size (in bits), for purposes of endianness 01207 conversion. */ 01208 unsigned int insn_chunk_bitsize; 01209 01210 /* Indicator if sizes are unknown. 01211 This is used by default_insn_bitsize,base_insn_bitsize if there is a 01212 difference between the selected isa's. */ 01213 #define CGEN_SIZE_UNKNOWN 65535 01214 01215 /* Default instruction size (in bits). 01216 This is used by the assembler when it encounters an unknown insn. */ 01217 unsigned int default_insn_bitsize; 01218 01219 /* Base instruction size (in bits). 01220 For non-LIW cpus this is generally the length of the smallest insn. 01221 For LIW cpus its wip (work-in-progress). For the m32r its 32. */ 01222 unsigned int base_insn_bitsize; 01223 01224 /* Minimum/maximum instruction size (in bits). */ 01225 unsigned int min_insn_bitsize; 01226 unsigned int max_insn_bitsize; 01227 01228 /* Instruction set variants. */ 01229 const CGEN_ISA *isa_table; 01230 01231 /* Machine variants. */ 01232 const CGEN_MACH *mach_table; 01233 01234 /* Hardware elements. */ 01235 CGEN_HW_TABLE hw_table; 01236 01237 /* Instruction fields. */ 01238 const CGEN_IFLD *ifld_table; 01239 01240 /* Operands. */ 01241 CGEN_OPERAND_TABLE operand_table; 01242 01243 /* Main instruction table. */ 01244 CGEN_INSN_TABLE insn_table; 01245 #define CGEN_CPU_INSN_TABLE(cd) (& (cd)->insn_table) 01246 01247 /* Macro instructions are defined separately and are combined with real 01248 insns during hash table computation. */ 01249 CGEN_INSN_TABLE macro_insn_table; 01250 01251 /* Copy of CGEN_INT_INSN_P. */ 01252 int int_insn_p; 01253 01254 /* Called to rebuild the tables after something has changed. */ 01255 void (*rebuild_tables) (CGEN_CPU_DESC); 01256 01257 /* Operand parser callback. */ 01258 cgen_parse_operand_fn * parse_operand_fn; 01259 01260 /* Parse/insert/extract/print cover fns for operands. */ 01261 const char * (*parse_operand) 01262 (CGEN_CPU_DESC, int opindex_, const char **, CGEN_FIELDS *fields_); 01263 #ifdef __BFD_H_SEEN__ 01264 const char * (*insert_operand) 01265 (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, 01266 CGEN_INSN_BYTES_PTR, bfd_vma pc_); 01267 int (*extract_operand) 01268 (CGEN_CPU_DESC, int opindex_, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, 01269 CGEN_FIELDS *fields_, bfd_vma pc_); 01270 void (*print_operand) 01271 (CGEN_CPU_DESC, int opindex_, void * info_, CGEN_FIELDS * fields_, 01272 void const *attrs_, bfd_vma pc_, int length_); 01273 #else 01274 const char * (*insert_operand) (); 01275 int (*extract_operand) (); 01276 void (*print_operand) (); 01277 #endif 01278 #define CGEN_CPU_PARSE_OPERAND(cd) ((cd)->parse_operand) 01279 #define CGEN_CPU_INSERT_OPERAND(cd) ((cd)->insert_operand) 01280 #define CGEN_CPU_EXTRACT_OPERAND(cd) ((cd)->extract_operand) 01281 #define CGEN_CPU_PRINT_OPERAND(cd) ((cd)->print_operand) 01282 01283 /* Size of CGEN_FIELDS struct. */ 01284 unsigned int sizeof_fields; 01285 #define CGEN_CPU_SIZEOF_FIELDS(cd) ((cd)->sizeof_fields) 01286 01287 /* Set the bitsize field. */ 01288 void (*set_fields_bitsize) (CGEN_FIELDS *fields_, int size_); 01289 #define CGEN_CPU_SET_FIELDS_BITSIZE(cd) ((cd)->set_fields_bitsize) 01290 01291 /* CGEN_FIELDS accessors. */ 01292 int (*get_int_operand) 01293 (CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_); 01294 void (*set_int_operand) 01295 (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, int value_); 01296 #ifdef __BFD_H_SEEN__ 01297 bfd_vma (*get_vma_operand) 01298 (CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_); 01299 void (*set_vma_operand) 01300 (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, bfd_vma value_); 01301 #else 01302 long (*get_vma_operand) (); 01303 void (*set_vma_operand) (); 01304 #endif 01305 #define CGEN_CPU_GET_INT_OPERAND(cd) ((cd)->get_int_operand) 01306 #define CGEN_CPU_SET_INT_OPERAND(cd) ((cd)->set_int_operand) 01307 #define CGEN_CPU_GET_VMA_OPERAND(cd) ((cd)->get_vma_operand) 01308 #define CGEN_CPU_SET_VMA_OPERAND(cd) ((cd)->set_vma_operand) 01309 01310 /* Instruction parse/insert/extract/print handlers. */ 01311 /* FIXME: make these types uppercase. */ 01312 cgen_parse_fn * const *parse_handlers; 01313 cgen_insert_fn * const *insert_handlers; 01314 cgen_extract_fn * const *extract_handlers; 01315 cgen_print_fn * const *print_handlers; 01316 #define CGEN_PARSE_FN(cd, insn) (cd->parse_handlers[(insn)->opcode->handlers.parse]) 01317 #define CGEN_INSERT_FN(cd, insn) (cd->insert_handlers[(insn)->opcode->handlers.insert]) 01318 #define CGEN_EXTRACT_FN(cd, insn) (cd->extract_handlers[(insn)->opcode->handlers.extract]) 01319 #define CGEN_PRINT_FN(cd, insn) (cd->print_handlers[(insn)->opcode->handlers.print]) 01320 01321 /* Return non-zero if insn should be added to hash table. */ 01322 int (* asm_hash_p) (const CGEN_INSN *); 01323 01324 /* Assembler hash function. */ 01325 unsigned int (* asm_hash) (const char *); 01326 01327 /* Number of entries in assembler hash table. */ 01328 unsigned int asm_hash_size; 01329 01330 /* Return non-zero if insn should be added to hash table. */ 01331 int (* dis_hash_p) (const CGEN_INSN *); 01332 01333 /* Disassembler hash function. */ 01334 unsigned int (* dis_hash) (const char *, CGEN_INSN_INT); 01335 01336 /* Number of entries in disassembler hash table. */ 01337 unsigned int dis_hash_size; 01338 01339 /* Assembler instruction hash table. */ 01340 CGEN_INSN_LIST **asm_hash_table; 01341 CGEN_INSN_LIST *asm_hash_table_entries; 01342 01343 /* Disassembler instruction hash table. */ 01344 CGEN_INSN_LIST **dis_hash_table; 01345 CGEN_INSN_LIST *dis_hash_table_entries; 01346 01347 /* This field could be turned into a bitfield if room for other flags is needed. */ 01348 unsigned int signed_overflow_ok_p; 01349 01350 } CGEN_CPU_TABLE; 01351 01352 /* wip */ 01353 #ifndef CGEN_WORD_ENDIAN 01354 #define CGEN_WORD_ENDIAN(cd) CGEN_CPU_ENDIAN (cd) 01355 #endif 01356 #ifndef CGEN_INSN_WORD_ENDIAN 01357 #define CGEN_INSN_WORD_ENDIAN(cd) CGEN_CPU_INSN_ENDIAN (cd) 01358 #endif 01359 01360 /* Prototypes of major functions. */ 01361 /* FIXME: Move more CGEN_SYM-defined functions into CGEN_CPU_DESC. 01362 Not the init fns though, as that would drag in things that mightn't be 01363 used and might not even exist. */ 01364 01365 /* Argument types to cpu_open. */ 01366 01367 enum cgen_cpu_open_arg { 01368 CGEN_CPU_OPEN_END, 01369 /* Select instruction set(s), arg is bitmap or 0 meaning "unspecified". */ 01370 CGEN_CPU_OPEN_ISAS, 01371 /* Select machine(s), arg is bitmap or 0 meaning "unspecified". */ 01372 CGEN_CPU_OPEN_MACHS, 01373 /* Select machine, arg is mach's bfd name. 01374 Multiple machines can be specified by repeated use. */ 01375 CGEN_CPU_OPEN_BFDMACH, 01376 /* Select endian, arg is CGEN_ENDIAN_*. */ 01377 CGEN_CPU_OPEN_ENDIAN 01378 }; 01379 01380 /* Open a cpu descriptor table for use. 01381 ??? We only support ISO C stdargs here, not K&R. 01382 Laziness, plus experiment to see if anything requires K&R - eventually 01383 K&R will no longer be supported - e.g. GDB is currently trying this. */ 01384 01385 extern CGEN_CPU_DESC CGEN_SYM (cpu_open) (enum cgen_cpu_open_arg, ...); 01386 01387 /* Cover fn to handle simple case. */ 01388 01389 extern CGEN_CPU_DESC CGEN_SYM (cpu_open_1) 01390 (const char *mach_name_, enum cgen_endian endian_); 01391 01392 /* Close it. */ 01393 01394 extern void CGEN_SYM (cpu_close) (CGEN_CPU_DESC); 01395 01396 /* Initialize the opcode table for use. 01397 Called by init_asm/init_dis. */ 01398 01399 extern void CGEN_SYM (init_opcode_table) (CGEN_CPU_DESC cd_); 01400 01401 /* build the insn selection regex. 01402 called by init_opcode_table */ 01403 01404 extern char * CGEN_SYM(build_insn_regex) (CGEN_INSN *insn_); 01405 01406 /* Initialize the ibld table for use. 01407 Called by init_asm/init_dis. */ 01408 01409 extern void CGEN_SYM (init_ibld_table) (CGEN_CPU_DESC cd_); 01410 01411 /* Initialize an cpu table for assembler or disassembler use. 01412 These must be called immediately after cpu_open. */ 01413 01414 extern void CGEN_SYM (init_asm) (CGEN_CPU_DESC); 01415 extern void CGEN_SYM (init_dis) (CGEN_CPU_DESC); 01416 01417 /* Initialize the operand instance table for use. */ 01418 01419 extern void CGEN_SYM (init_opinst_table) (CGEN_CPU_DESC cd_); 01420 01421 /* Assemble an instruction. */ 01422 01423 extern const CGEN_INSN * CGEN_SYM (assemble_insn) 01424 (CGEN_CPU_DESC, const char *, CGEN_FIELDS *, 01425 CGEN_INSN_BYTES_PTR, char **); 01426 01427 extern const CGEN_KEYWORD CGEN_SYM (operand_mach); 01428 extern int CGEN_SYM (get_mach) (const char *); 01429 01430 /* Operand index computation. */ 01431 extern const CGEN_INSN * cgen_lookup_insn 01432 (CGEN_CPU_DESC, const CGEN_INSN * insn_, 01433 CGEN_INSN_INT int_value_, unsigned char *bytes_value_, 01434 int length_, CGEN_FIELDS *fields_, int alias_p_); 01435 extern void cgen_get_insn_operands 01436 (CGEN_CPU_DESC, const CGEN_INSN * insn_, 01437 const CGEN_FIELDS *fields_, int *indices_); 01438 extern const CGEN_INSN * cgen_lookup_get_insn_operands 01439 (CGEN_CPU_DESC, const CGEN_INSN *insn_, 01440 CGEN_INSN_INT int_value_, unsigned char *bytes_value_, 01441 int length_, int *indices_, CGEN_FIELDS *fields_); 01442 01443 /* Cover fns to bfd_get/set. */ 01444 01445 extern CGEN_INSN_INT cgen_get_insn_value 01446 (CGEN_CPU_DESC, unsigned char *, int); 01447 extern void cgen_put_insn_value 01448 (CGEN_CPU_DESC, unsigned char *, int, CGEN_INSN_INT); 01449 01450 /* Read in a cpu description file. 01451 ??? For future concerns, including adding instructions to the assembler/ 01452 disassembler at run-time. */ 01453 01454 extern const char * cgen_read_cpu_file (CGEN_CPU_DESC, const char * filename_); 01455 01456 /* Allow signed overflow of instruction fields. */ 01457 extern void cgen_set_signed_overflow_ok (CGEN_CPU_DESC); 01458 01459 /* Generate an error message if a signed field in an instruction overflows. */ 01460 extern void cgen_clear_signed_overflow_ok (CGEN_CPU_DESC); 01461 01462 /* Will an error message be generated if a signed field in an instruction overflows ? */ 01463 extern unsigned int cgen_signed_overflow_ok_p (CGEN_CPU_DESC); 01464 01465 #endif /* CGEN_H */
1.5.6