1*3d8817e4Smiod /* Header file for targets using CGEN: Cpu tools GENerator. 2*3d8817e4Smiod 3*3d8817e4Smiod Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005 4*3d8817e4Smiod Free Software Foundation, Inc. 5*3d8817e4Smiod 6*3d8817e4Smiod This file is part of GDB, the GNU debugger, and the GNU Binutils. 7*3d8817e4Smiod 8*3d8817e4Smiod This program is free software; you can redistribute it and/or modify 9*3d8817e4Smiod it under the terms of the GNU General Public License as published by 10*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or 11*3d8817e4Smiod (at your option) any later version. 12*3d8817e4Smiod 13*3d8817e4Smiod This program is distributed in the hope that it will be useful, 14*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of 15*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*3d8817e4Smiod GNU General Public License for more details. 17*3d8817e4Smiod 18*3d8817e4Smiod You should have received a copy of the GNU General Public License along 19*3d8817e4Smiod with this program; if not, write to the Free Software Foundation, Inc., 20*3d8817e4Smiod 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 21*3d8817e4Smiod 22*3d8817e4Smiod #ifndef CGEN_H 23*3d8817e4Smiod #define CGEN_H 24*3d8817e4Smiod 25*3d8817e4Smiod #include "symcat.h" 26*3d8817e4Smiod #include "cgen-bitset.h" 27*3d8817e4Smiod /* ??? This file requires bfd.h but only to get bfd_vma. 28*3d8817e4Smiod Seems like an awful lot to require just to get such a fundamental type. 29*3d8817e4Smiod Perhaps the definition of bfd_vma can be moved outside of bfd.h. 30*3d8817e4Smiod Or perhaps one could duplicate its definition in another file. 31*3d8817e4Smiod Until such time, this file conditionally compiles definitions that require 32*3d8817e4Smiod bfd_vma using __BFD_H_SEEN__. */ 33*3d8817e4Smiod 34*3d8817e4Smiod /* Enums must be defined before they can be used. 35*3d8817e4Smiod Allow them to be used in struct definitions, even though the enum must 36*3d8817e4Smiod be defined elsewhere. 37*3d8817e4Smiod If CGEN_ARCH isn't defined, this file is being included by something other 38*3d8817e4Smiod than <arch>-desc.h. */ 39*3d8817e4Smiod 40*3d8817e4Smiod /* Prepend the arch name, defined in <arch>-desc.h, and _cgen_ to symbol S. 41*3d8817e4Smiod The lack of spaces in the arg list is important for non-stdc systems. 42*3d8817e4Smiod This file is included by <arch>-desc.h. 43*3d8817e4Smiod It can be included independently of <arch>-desc.h, in which case the arch 44*3d8817e4Smiod dependent portions will be declared as "unknown_cgen_foo". */ 45*3d8817e4Smiod 46*3d8817e4Smiod #ifndef CGEN_SYM 47*3d8817e4Smiod #define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s) 48*3d8817e4Smiod #endif 49*3d8817e4Smiod 50*3d8817e4Smiod /* This file contains the static (unchanging) pieces and as much other stuff 51*3d8817e4Smiod as we can reasonably put here. It's generally cleaner to put stuff here 52*3d8817e4Smiod rather than having it machine generated if possible. */ 53*3d8817e4Smiod 54*3d8817e4Smiod /* The assembler syntax is made up of expressions (duh...). 55*3d8817e4Smiod At the lowest level the values are mnemonics, register names, numbers, etc. 56*3d8817e4Smiod Above that are subexpressions, if any (an example might be the 57*3d8817e4Smiod "effective address" in m68k cpus). Subexpressions are wip. 58*3d8817e4Smiod At the second highest level are the insns themselves. Above that are 59*3d8817e4Smiod pseudo-insns, synthetic insns, and macros, if any. */ 60*3d8817e4Smiod 61*3d8817e4Smiod /* Lots of cpu's have a fixed insn size, or one which rarely changes, 62*3d8817e4Smiod and it's generally easier to handle these by treating the insn as an 63*3d8817e4Smiod integer type, rather than an array of characters. So we allow targets 64*3d8817e4Smiod to control this. When an integer type the value is in host byte order, 65*3d8817e4Smiod when an array of characters the value is in target byte order. */ 66*3d8817e4Smiod 67*3d8817e4Smiod typedef unsigned int CGEN_INSN_INT; 68*3d8817e4Smiod #if CGEN_INT_INSN_P 69*3d8817e4Smiod typedef CGEN_INSN_INT CGEN_INSN_BYTES; 70*3d8817e4Smiod typedef CGEN_INSN_INT *CGEN_INSN_BYTES_PTR; 71*3d8817e4Smiod #else 72*3d8817e4Smiod typedef unsigned char *CGEN_INSN_BYTES; 73*3d8817e4Smiod typedef unsigned char *CGEN_INSN_BYTES_PTR; 74*3d8817e4Smiod #endif 75*3d8817e4Smiod 76*3d8817e4Smiod #ifdef __GNUC__ 77*3d8817e4Smiod #define CGEN_INLINE __inline__ 78*3d8817e4Smiod #else 79*3d8817e4Smiod #define CGEN_INLINE 80*3d8817e4Smiod #endif 81*3d8817e4Smiod 82*3d8817e4Smiod enum cgen_endian 83*3d8817e4Smiod { 84*3d8817e4Smiod CGEN_ENDIAN_UNKNOWN, 85*3d8817e4Smiod CGEN_ENDIAN_LITTLE, 86*3d8817e4Smiod CGEN_ENDIAN_BIG 87*3d8817e4Smiod }; 88*3d8817e4Smiod 89*3d8817e4Smiod /* Forward decl. */ 90*3d8817e4Smiod 91*3d8817e4Smiod typedef struct cgen_insn CGEN_INSN; 92*3d8817e4Smiod 93*3d8817e4Smiod /* Opaque pointer version for use by external world. */ 94*3d8817e4Smiod 95*3d8817e4Smiod typedef struct cgen_cpu_desc *CGEN_CPU_DESC; 96*3d8817e4Smiod 97*3d8817e4Smiod /* Attributes. 98*3d8817e4Smiod Attributes are used to describe various random things associated with 99*3d8817e4Smiod an object (ifield, hardware, operand, insn, whatever) and are specified 100*3d8817e4Smiod as name/value pairs. 101*3d8817e4Smiod Integer attributes computed at compile time are currently all that's 102*3d8817e4Smiod supported, though adding string attributes and run-time computation is 103*3d8817e4Smiod straightforward. Integer attribute values are always host int's 104*3d8817e4Smiod (signed or unsigned). For portability, this means 32 bits. 105*3d8817e4Smiod Integer attributes are further categorized as boolean, bitset, integer, 106*3d8817e4Smiod and enum types. Boolean attributes appear frequently enough that they're 107*3d8817e4Smiod recorded in one host int. This limits the maximum number of boolean 108*3d8817e4Smiod attributes to 32, though that's a *lot* of attributes. */ 109*3d8817e4Smiod 110*3d8817e4Smiod /* Type of attribute values. */ 111*3d8817e4Smiod 112*3d8817e4Smiod typedef CGEN_BITSET CGEN_ATTR_VALUE_BITSET_TYPE; 113*3d8817e4Smiod typedef int CGEN_ATTR_VALUE_ENUM_TYPE; 114*3d8817e4Smiod typedef union 115*3d8817e4Smiod { 116*3d8817e4Smiod CGEN_ATTR_VALUE_BITSET_TYPE bitset; 117*3d8817e4Smiod CGEN_ATTR_VALUE_ENUM_TYPE nonbitset; 118*3d8817e4Smiod } CGEN_ATTR_VALUE_TYPE; 119*3d8817e4Smiod 120*3d8817e4Smiod /* Struct to record attribute information. */ 121*3d8817e4Smiod 122*3d8817e4Smiod typedef struct 123*3d8817e4Smiod { 124*3d8817e4Smiod /* Boolean attributes. */ 125*3d8817e4Smiod unsigned int bool; 126*3d8817e4Smiod /* Non-boolean integer attributes. */ 127*3d8817e4Smiod CGEN_ATTR_VALUE_TYPE nonbool[1]; 128*3d8817e4Smiod } CGEN_ATTR; 129*3d8817e4Smiod 130*3d8817e4Smiod /* Define a structure member for attributes with N non-boolean entries. 131*3d8817e4Smiod There is no maximum number of non-boolean attributes. 132*3d8817e4Smiod There is a maximum of 32 boolean attributes (since they are all recorded 133*3d8817e4Smiod in one host int). */ 134*3d8817e4Smiod 135*3d8817e4Smiod #define CGEN_ATTR_TYPE(n) \ 136*3d8817e4Smiod struct { unsigned int bool; \ 137*3d8817e4Smiod CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; } 138*3d8817e4Smiod 139*3d8817e4Smiod /* Return the boolean attributes. */ 140*3d8817e4Smiod 141*3d8817e4Smiod #define CGEN_ATTR_BOOLS(a) ((a)->bool) 142*3d8817e4Smiod 143*3d8817e4Smiod /* Non-boolean attribute numbers are offset by this much. */ 144*3d8817e4Smiod 145*3d8817e4Smiod #define CGEN_ATTR_NBOOL_OFFSET 32 146*3d8817e4Smiod 147*3d8817e4Smiod /* Given a boolean attribute number, return its mask. */ 148*3d8817e4Smiod 149*3d8817e4Smiod #define CGEN_ATTR_MASK(attr) (1 << (attr)) 150*3d8817e4Smiod 151*3d8817e4Smiod /* Return the value of boolean attribute ATTR in ATTRS. */ 152*3d8817e4Smiod 153*3d8817e4Smiod #define CGEN_BOOL_ATTR(attrs, attr) ((CGEN_ATTR_MASK (attr) & (attrs)) != 0) 154*3d8817e4Smiod 155*3d8817e4Smiod /* Return value of attribute ATTR in ATTR_TABLE for OBJ. 156*3d8817e4Smiod OBJ is a pointer to the entity that has the attributes 157*3d8817e4Smiod (??? not used at present but is reserved for future purposes - eventually 158*3d8817e4Smiod the goal is to allow recording attributes in source form and computing 159*3d8817e4Smiod them lazily at runtime, not sure of the details yet). */ 160*3d8817e4Smiod 161*3d8817e4Smiod #define CGEN_ATTR_VALUE(obj, attr_table, attr) \ 162*3d8817e4Smiod ((unsigned int) (attr) < CGEN_ATTR_NBOOL_OFFSET \ 163*3d8817e4Smiod ? ((CGEN_ATTR_BOOLS (attr_table) & CGEN_ATTR_MASK (attr)) != 0) \ 164*3d8817e4Smiod : ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET].nonbitset)) 165*3d8817e4Smiod #define CGEN_BITSET_ATTR_VALUE(obj, attr_table, attr) \ 166*3d8817e4Smiod ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET].bitset) 167*3d8817e4Smiod 168*3d8817e4Smiod /* Attribute name/value tables. 169*3d8817e4Smiod These are used to assist parsing of descriptions at run-time. */ 170*3d8817e4Smiod 171*3d8817e4Smiod typedef struct 172*3d8817e4Smiod { 173*3d8817e4Smiod const char * name; 174*3d8817e4Smiod unsigned value; 175*3d8817e4Smiod } CGEN_ATTR_ENTRY; 176*3d8817e4Smiod 177*3d8817e4Smiod /* For each domain (ifld,hw,operand,insn), list of attributes. */ 178*3d8817e4Smiod 179*3d8817e4Smiod typedef struct 180*3d8817e4Smiod { 181*3d8817e4Smiod const char * name; 182*3d8817e4Smiod const CGEN_ATTR_ENTRY * dfault; 183*3d8817e4Smiod const CGEN_ATTR_ENTRY * vals; 184*3d8817e4Smiod } CGEN_ATTR_TABLE; 185*3d8817e4Smiod 186*3d8817e4Smiod /* Instruction set variants. */ 187*3d8817e4Smiod 188*3d8817e4Smiod typedef struct { 189*3d8817e4Smiod const char *name; 190*3d8817e4Smiod 191*3d8817e4Smiod /* Default instruction size (in bits). 192*3d8817e4Smiod This is used by the assembler when it encounters an unknown insn. */ 193*3d8817e4Smiod unsigned int default_insn_bitsize; 194*3d8817e4Smiod 195*3d8817e4Smiod /* Base instruction size (in bits). 196*3d8817e4Smiod For non-LIW cpus this is generally the length of the smallest insn. 197*3d8817e4Smiod For LIW cpus its wip (work-in-progress). For the m32r its 32. */ 198*3d8817e4Smiod unsigned int base_insn_bitsize; 199*3d8817e4Smiod 200*3d8817e4Smiod /* Minimum/maximum instruction size (in bits). */ 201*3d8817e4Smiod unsigned int min_insn_bitsize; 202*3d8817e4Smiod unsigned int max_insn_bitsize; 203*3d8817e4Smiod } CGEN_ISA; 204*3d8817e4Smiod 205*3d8817e4Smiod /* Machine variants. */ 206*3d8817e4Smiod 207*3d8817e4Smiod typedef struct { 208*3d8817e4Smiod const char *name; 209*3d8817e4Smiod /* The argument to bfd_arch_info->scan. */ 210*3d8817e4Smiod const char *bfd_name; 211*3d8817e4Smiod /* one of enum mach_attr */ 212*3d8817e4Smiod int num; 213*3d8817e4Smiod /* parameter from mach->cpu */ 214*3d8817e4Smiod unsigned int insn_chunk_bitsize; 215*3d8817e4Smiod } CGEN_MACH; 216*3d8817e4Smiod 217*3d8817e4Smiod /* Parse result (also extraction result). 218*3d8817e4Smiod 219*3d8817e4Smiod The result of parsing an insn is stored here. 220*3d8817e4Smiod To generate the actual insn, this is passed to the insert handler. 221*3d8817e4Smiod When printing an insn, the result of extraction is stored here. 222*3d8817e4Smiod To print the insn, this is passed to the print handler. 223*3d8817e4Smiod 224*3d8817e4Smiod It is machine generated so we don't define it here, 225*3d8817e4Smiod but we do need a forward decl for the handler fns. 226*3d8817e4Smiod 227*3d8817e4Smiod There is one member for each possible field in the insn. 228*3d8817e4Smiod The type depends on the field. 229*3d8817e4Smiod Also recorded here is the computed length of the insn for architectures 230*3d8817e4Smiod where it varies. 231*3d8817e4Smiod */ 232*3d8817e4Smiod 233*3d8817e4Smiod typedef struct cgen_fields CGEN_FIELDS; 234*3d8817e4Smiod 235*3d8817e4Smiod /* Total length of the insn, as recorded in the `fields' struct. */ 236*3d8817e4Smiod /* ??? The field insert handler has lots of opportunities for optimization 237*3d8817e4Smiod if it ever gets inlined. On architectures where insns all have the same 238*3d8817e4Smiod size, may wish to detect that and make this macro a constant - to allow 239*3d8817e4Smiod further optimizations. */ 240*3d8817e4Smiod 241*3d8817e4Smiod #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length) 242*3d8817e4Smiod 243*3d8817e4Smiod /* Extraction support for variable length insn sets. */ 244*3d8817e4Smiod 245*3d8817e4Smiod /* When disassembling we don't know the number of bytes to read at the start. 246*3d8817e4Smiod So the first CGEN_BASE_INSN_SIZE bytes are read at the start and the rest 247*3d8817e4Smiod are read when needed. This struct controls this. It is basically the 248*3d8817e4Smiod disassemble_info stuff, except that we provide a cache for values already 249*3d8817e4Smiod read (since bytes can typically be read several times to fetch multiple 250*3d8817e4Smiod operands that may be in them), and that extraction of fields is needed 251*3d8817e4Smiod in contexts other than disassembly. */ 252*3d8817e4Smiod 253*3d8817e4Smiod typedef struct { 254*3d8817e4Smiod /* A pointer to the disassemble_info struct. 255*3d8817e4Smiod We don't require dis-asm.h so we use void * for the type here. 256*3d8817e4Smiod If NULL, BYTES is full of valid data (VALID == -1). */ 257*3d8817e4Smiod void *dis_info; 258*3d8817e4Smiod /* Points to a working buffer of sufficient size. */ 259*3d8817e4Smiod unsigned char *insn_bytes; 260*3d8817e4Smiod /* Mask of bytes that are valid in INSN_BYTES. */ 261*3d8817e4Smiod unsigned int valid; 262*3d8817e4Smiod } CGEN_EXTRACT_INFO; 263*3d8817e4Smiod 264*3d8817e4Smiod /* Associated with each insn or expression is a set of "handlers" for 265*3d8817e4Smiod performing operations like parsing, printing, etc. These require a bfd_vma 266*3d8817e4Smiod value to be passed around but we don't want all applications to need bfd.h. 267*3d8817e4Smiod So this stuff is only provided if bfd.h has been included. */ 268*3d8817e4Smiod 269*3d8817e4Smiod /* Parse handler. 270*3d8817e4Smiod CD is a cpu table descriptor. 271*3d8817e4Smiod INSN is a pointer to a struct describing the insn being parsed. 272*3d8817e4Smiod STRP is a pointer to a pointer to the text being parsed. 273*3d8817e4Smiod FIELDS is a pointer to a cgen_fields struct in which the results are placed. 274*3d8817e4Smiod If the expression is successfully parsed, *STRP is updated. 275*3d8817e4Smiod If not it is left alone. 276*3d8817e4Smiod The result is NULL if success or an error message. */ 277*3d8817e4Smiod typedef const char * (cgen_parse_fn) 278*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *insn_, 279*3d8817e4Smiod const char **strp_, CGEN_FIELDS *fields_); 280*3d8817e4Smiod 281*3d8817e4Smiod /* Insert handler. 282*3d8817e4Smiod CD is a cpu table descriptor. 283*3d8817e4Smiod INSN is a pointer to a struct describing the insn being parsed. 284*3d8817e4Smiod FIELDS is a pointer to a cgen_fields struct from which the values 285*3d8817e4Smiod are fetched. 286*3d8817e4Smiod INSNP is a pointer to a buffer in which to place the insn. 287*3d8817e4Smiod PC is the pc value of the insn. 288*3d8817e4Smiod The result is an error message or NULL if success. */ 289*3d8817e4Smiod 290*3d8817e4Smiod #ifdef __BFD_H_SEEN__ 291*3d8817e4Smiod typedef const char * (cgen_insert_fn) 292*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *insn_, 293*3d8817e4Smiod CGEN_FIELDS *fields_, CGEN_INSN_BYTES_PTR insnp_, 294*3d8817e4Smiod bfd_vma pc_); 295*3d8817e4Smiod #else 296*3d8817e4Smiod typedef const char * (cgen_insert_fn) (); 297*3d8817e4Smiod #endif 298*3d8817e4Smiod 299*3d8817e4Smiod /* Extract handler. 300*3d8817e4Smiod CD is a cpu table descriptor. 301*3d8817e4Smiod INSN is a pointer to a struct describing the insn being parsed. 302*3d8817e4Smiod The second argument is a pointer to a struct controlling extraction 303*3d8817e4Smiod (only used for variable length insns). 304*3d8817e4Smiod EX_INFO is a pointer to a struct for controlling reading of further 305*3d8817e4Smiod bytes for the insn. 306*3d8817e4Smiod BASE_INSN is the first CGEN_BASE_INSN_SIZE bytes (host order). 307*3d8817e4Smiod FIELDS is a pointer to a cgen_fields struct in which the results are placed. 308*3d8817e4Smiod PC is the pc value of the insn. 309*3d8817e4Smiod The result is the length of the insn in bits or zero if not recognized. */ 310*3d8817e4Smiod 311*3d8817e4Smiod #ifdef __BFD_H_SEEN__ 312*3d8817e4Smiod typedef int (cgen_extract_fn) 313*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *insn_, 314*3d8817e4Smiod CGEN_EXTRACT_INFO *ex_info_, CGEN_INSN_INT base_insn_, 315*3d8817e4Smiod CGEN_FIELDS *fields_, bfd_vma pc_); 316*3d8817e4Smiod #else 317*3d8817e4Smiod typedef int (cgen_extract_fn) (); 318*3d8817e4Smiod #endif 319*3d8817e4Smiod 320*3d8817e4Smiod /* Print handler. 321*3d8817e4Smiod CD is a cpu table descriptor. 322*3d8817e4Smiod INFO is a pointer to the disassembly info. 323*3d8817e4Smiod Eg: disassemble_info. It's defined as `PTR' so this file can be included 324*3d8817e4Smiod without dis-asm.h. 325*3d8817e4Smiod INSN is a pointer to a struct describing the insn being printed. 326*3d8817e4Smiod FIELDS is a pointer to a cgen_fields struct. 327*3d8817e4Smiod PC is the pc value of the insn. 328*3d8817e4Smiod LEN is the length of the insn, in bits. */ 329*3d8817e4Smiod 330*3d8817e4Smiod #ifdef __BFD_H_SEEN__ 331*3d8817e4Smiod typedef void (cgen_print_fn) 332*3d8817e4Smiod (CGEN_CPU_DESC, void * info_, const CGEN_INSN *insn_, 333*3d8817e4Smiod CGEN_FIELDS *fields_, bfd_vma pc_, int len_); 334*3d8817e4Smiod #else 335*3d8817e4Smiod typedef void (cgen_print_fn) (); 336*3d8817e4Smiod #endif 337*3d8817e4Smiod 338*3d8817e4Smiod /* Parse/insert/extract/print handlers. 339*3d8817e4Smiod 340*3d8817e4Smiod Indices into the handler tables. 341*3d8817e4Smiod We could use pointers here instead, but 90% of them are generally identical 342*3d8817e4Smiod and that's a lot of redundant data. Making these unsigned char indices 343*3d8817e4Smiod into tables of pointers saves a bit of space. 344*3d8817e4Smiod Using indices also keeps assembler code out of the disassembler and 345*3d8817e4Smiod vice versa. */ 346*3d8817e4Smiod 347*3d8817e4Smiod struct cgen_opcode_handler 348*3d8817e4Smiod { 349*3d8817e4Smiod unsigned char parse, insert, extract, print; 350*3d8817e4Smiod }; 351*3d8817e4Smiod 352*3d8817e4Smiod /* Assembler interface. 353*3d8817e4Smiod 354*3d8817e4Smiod The interface to the assembler is intended to be clean in the sense that 355*3d8817e4Smiod libopcodes.a is a standalone entity and could be used with any assembler. 356*3d8817e4Smiod Not that one would necessarily want to do that but rather that it helps 357*3d8817e4Smiod keep a clean interface. The interface will obviously be slanted towards 358*3d8817e4Smiod GAS, but at least it's a start. 359*3d8817e4Smiod ??? Note that one possible user of the assembler besides GAS is GDB. 360*3d8817e4Smiod 361*3d8817e4Smiod Parsing is controlled by the assembler which calls 362*3d8817e4Smiod CGEN_SYM (assemble_insn). If it can parse and build the entire insn 363*3d8817e4Smiod it doesn't call back to the assembler. If it needs/wants to call back 364*3d8817e4Smiod to the assembler, cgen_parse_operand_fn is called which can either 365*3d8817e4Smiod 366*3d8817e4Smiod - return a number to be inserted in the insn 367*3d8817e4Smiod - return a "register" value to be inserted 368*3d8817e4Smiod (the register might not be a register per pe) 369*3d8817e4Smiod - queue the argument and return a marker saying the expression has been 370*3d8817e4Smiod queued (eg: a fix-up) 371*3d8817e4Smiod - return an error message indicating the expression wasn't recognizable 372*3d8817e4Smiod 373*3d8817e4Smiod The result is an error message or NULL for success. 374*3d8817e4Smiod The parsed value is stored in the bfd_vma *. */ 375*3d8817e4Smiod 376*3d8817e4Smiod /* Values for indicating what the caller wants. */ 377*3d8817e4Smiod 378*3d8817e4Smiod enum cgen_parse_operand_type 379*3d8817e4Smiod { 380*3d8817e4Smiod CGEN_PARSE_OPERAND_INIT, 381*3d8817e4Smiod CGEN_PARSE_OPERAND_INTEGER, 382*3d8817e4Smiod CGEN_PARSE_OPERAND_ADDRESS, 383*3d8817e4Smiod CGEN_PARSE_OPERAND_SYMBOLIC 384*3d8817e4Smiod }; 385*3d8817e4Smiod 386*3d8817e4Smiod /* Values for indicating what was parsed. */ 387*3d8817e4Smiod 388*3d8817e4Smiod enum cgen_parse_operand_result 389*3d8817e4Smiod { 390*3d8817e4Smiod CGEN_PARSE_OPERAND_RESULT_NUMBER, 391*3d8817e4Smiod CGEN_PARSE_OPERAND_RESULT_REGISTER, 392*3d8817e4Smiod CGEN_PARSE_OPERAND_RESULT_QUEUED, 393*3d8817e4Smiod CGEN_PARSE_OPERAND_RESULT_ERROR 394*3d8817e4Smiod }; 395*3d8817e4Smiod 396*3d8817e4Smiod #ifdef __BFD_H_SEEN__ /* Don't require bfd.h unnecessarily. */ 397*3d8817e4Smiod typedef const char * (cgen_parse_operand_fn) 398*3d8817e4Smiod (CGEN_CPU_DESC, 399*3d8817e4Smiod enum cgen_parse_operand_type, const char **, int, int, 400*3d8817e4Smiod enum cgen_parse_operand_result *, bfd_vma *); 401*3d8817e4Smiod #else 402*3d8817e4Smiod typedef const char * (cgen_parse_operand_fn) (); 403*3d8817e4Smiod #endif 404*3d8817e4Smiod 405*3d8817e4Smiod /* Set the cgen_parse_operand_fn callback. */ 406*3d8817e4Smiod 407*3d8817e4Smiod extern void cgen_set_parse_operand_fn 408*3d8817e4Smiod (CGEN_CPU_DESC, cgen_parse_operand_fn); 409*3d8817e4Smiod 410*3d8817e4Smiod /* Called before trying to match a table entry with the insn. */ 411*3d8817e4Smiod 412*3d8817e4Smiod extern void cgen_init_parse_operand (CGEN_CPU_DESC); 413*3d8817e4Smiod 414*3d8817e4Smiod /* Operand values (keywords, integers, symbols, etc.) */ 415*3d8817e4Smiod 416*3d8817e4Smiod /* Types of assembler elements. */ 417*3d8817e4Smiod 418*3d8817e4Smiod enum cgen_asm_type 419*3d8817e4Smiod { 420*3d8817e4Smiod CGEN_ASM_NONE, CGEN_ASM_KEYWORD, CGEN_ASM_MAX 421*3d8817e4Smiod }; 422*3d8817e4Smiod 423*3d8817e4Smiod #ifndef CGEN_ARCH 424*3d8817e4Smiod enum cgen_hw_type { CGEN_HW_MAX }; 425*3d8817e4Smiod #endif 426*3d8817e4Smiod 427*3d8817e4Smiod /* List of hardware elements. */ 428*3d8817e4Smiod 429*3d8817e4Smiod typedef struct 430*3d8817e4Smiod { 431*3d8817e4Smiod char *name; 432*3d8817e4Smiod enum cgen_hw_type type; 433*3d8817e4Smiod /* There is currently no example where both index specs and value specs 434*3d8817e4Smiod are required, so for now both are clumped under "asm_data". */ 435*3d8817e4Smiod enum cgen_asm_type asm_type; 436*3d8817e4Smiod void *asm_data; 437*3d8817e4Smiod #ifndef CGEN_HW_NBOOL_ATTRS 438*3d8817e4Smiod #define CGEN_HW_NBOOL_ATTRS 1 439*3d8817e4Smiod #endif 440*3d8817e4Smiod CGEN_ATTR_TYPE (CGEN_HW_NBOOL_ATTRS) attrs; 441*3d8817e4Smiod #define CGEN_HW_ATTRS(hw) (&(hw)->attrs) 442*3d8817e4Smiod } CGEN_HW_ENTRY; 443*3d8817e4Smiod 444*3d8817e4Smiod /* Return value of attribute ATTR in HW. */ 445*3d8817e4Smiod 446*3d8817e4Smiod #define CGEN_HW_ATTR_VALUE(hw, attr) \ 447*3d8817e4Smiod CGEN_ATTR_VALUE ((hw), CGEN_HW_ATTRS (hw), (attr)) 448*3d8817e4Smiod 449*3d8817e4Smiod /* Table of hardware elements for selected mach, computed at runtime. 450*3d8817e4Smiod enum cgen_hw_type is an index into this table (specifically `entries'). */ 451*3d8817e4Smiod 452*3d8817e4Smiod typedef struct { 453*3d8817e4Smiod /* Pointer to null terminated table of all compiled in entries. */ 454*3d8817e4Smiod const CGEN_HW_ENTRY *init_entries; 455*3d8817e4Smiod unsigned int entry_size; /* since the attribute member is variable sized */ 456*3d8817e4Smiod /* Array of all entries, initial and run-time added. */ 457*3d8817e4Smiod const CGEN_HW_ENTRY **entries; 458*3d8817e4Smiod /* Number of elements in `entries'. */ 459*3d8817e4Smiod unsigned int num_entries; 460*3d8817e4Smiod /* For now, xrealloc is called each time a new entry is added at runtime. 461*3d8817e4Smiod ??? May wish to keep track of some slop to reduce the number of calls to 462*3d8817e4Smiod xrealloc, except that there's unlikely to be many and not expected to be 463*3d8817e4Smiod in speed critical code. */ 464*3d8817e4Smiod } CGEN_HW_TABLE; 465*3d8817e4Smiod 466*3d8817e4Smiod extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_name 467*3d8817e4Smiod (CGEN_CPU_DESC, const char *); 468*3d8817e4Smiod extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_num 469*3d8817e4Smiod (CGEN_CPU_DESC, unsigned int); 470*3d8817e4Smiod 471*3d8817e4Smiod /* This struct is used to describe things like register names, etc. */ 472*3d8817e4Smiod 473*3d8817e4Smiod typedef struct cgen_keyword_entry 474*3d8817e4Smiod { 475*3d8817e4Smiod /* Name (as in register name). */ 476*3d8817e4Smiod char * name; 477*3d8817e4Smiod 478*3d8817e4Smiod /* Value (as in register number). 479*3d8817e4Smiod The value cannot be -1 as that is used to indicate "not found". 480*3d8817e4Smiod IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */ 481*3d8817e4Smiod int value; 482*3d8817e4Smiod 483*3d8817e4Smiod /* Attributes. 484*3d8817e4Smiod This should, but technically needn't, appear last. It is a variable sized 485*3d8817e4Smiod array in that one architecture may have 1 nonbool attribute and another 486*3d8817e4Smiod may have more. Having this last means the non-architecture specific code 487*3d8817e4Smiod needn't care. The goal is to eventually record 488*3d8817e4Smiod attributes in their raw form, evaluate them at run-time, and cache the 489*3d8817e4Smiod values, so this worry will go away anyway. */ 490*3d8817e4Smiod /* ??? Moving this last should be done by treating keywords like insn lists 491*3d8817e4Smiod and moving the `next' fields into a CGEN_KEYWORD_LIST struct. */ 492*3d8817e4Smiod /* FIXME: Not used yet. */ 493*3d8817e4Smiod #ifndef CGEN_KEYWORD_NBOOL_ATTRS 494*3d8817e4Smiod #define CGEN_KEYWORD_NBOOL_ATTRS 1 495*3d8817e4Smiod #endif 496*3d8817e4Smiod CGEN_ATTR_TYPE (CGEN_KEYWORD_NBOOL_ATTRS) attrs; 497*3d8817e4Smiod 498*3d8817e4Smiod /* ??? Putting these here means compiled in entries can't be const. 499*3d8817e4Smiod Not a really big deal, but something to consider. */ 500*3d8817e4Smiod /* Next name hash table entry. */ 501*3d8817e4Smiod struct cgen_keyword_entry *next_name; 502*3d8817e4Smiod /* Next value hash table entry. */ 503*3d8817e4Smiod struct cgen_keyword_entry *next_value; 504*3d8817e4Smiod } CGEN_KEYWORD_ENTRY; 505*3d8817e4Smiod 506*3d8817e4Smiod /* Top level struct for describing a set of related keywords 507*3d8817e4Smiod (e.g. register names). 508*3d8817e4Smiod 509*3d8817e4Smiod This struct supports run-time entry of new values, and hashed lookups. */ 510*3d8817e4Smiod 511*3d8817e4Smiod typedef struct cgen_keyword 512*3d8817e4Smiod { 513*3d8817e4Smiod /* Pointer to initial [compiled in] values. */ 514*3d8817e4Smiod CGEN_KEYWORD_ENTRY *init_entries; 515*3d8817e4Smiod 516*3d8817e4Smiod /* Number of entries in `init_entries'. */ 517*3d8817e4Smiod unsigned int num_init_entries; 518*3d8817e4Smiod 519*3d8817e4Smiod /* Hash table used for name lookup. */ 520*3d8817e4Smiod CGEN_KEYWORD_ENTRY **name_hash_table; 521*3d8817e4Smiod 522*3d8817e4Smiod /* Hash table used for value lookup. */ 523*3d8817e4Smiod CGEN_KEYWORD_ENTRY **value_hash_table; 524*3d8817e4Smiod 525*3d8817e4Smiod /* Number of entries in the hash_tables. */ 526*3d8817e4Smiod unsigned int hash_table_size; 527*3d8817e4Smiod 528*3d8817e4Smiod /* Pointer to null keyword "" entry if present. */ 529*3d8817e4Smiod const CGEN_KEYWORD_ENTRY *null_entry; 530*3d8817e4Smiod 531*3d8817e4Smiod /* String containing non-alphanumeric characters used 532*3d8817e4Smiod in keywords. 533*3d8817e4Smiod At present, the highest number of entries used is 1. */ 534*3d8817e4Smiod char nonalpha_chars[8]; 535*3d8817e4Smiod } CGEN_KEYWORD; 536*3d8817e4Smiod 537*3d8817e4Smiod /* Structure used for searching. */ 538*3d8817e4Smiod 539*3d8817e4Smiod typedef struct 540*3d8817e4Smiod { 541*3d8817e4Smiod /* Table being searched. */ 542*3d8817e4Smiod const CGEN_KEYWORD *table; 543*3d8817e4Smiod 544*3d8817e4Smiod /* Specification of what is being searched for. */ 545*3d8817e4Smiod const char *spec; 546*3d8817e4Smiod 547*3d8817e4Smiod /* Current index in hash table. */ 548*3d8817e4Smiod unsigned int current_hash; 549*3d8817e4Smiod 550*3d8817e4Smiod /* Current element in current hash chain. */ 551*3d8817e4Smiod CGEN_KEYWORD_ENTRY *current_entry; 552*3d8817e4Smiod } CGEN_KEYWORD_SEARCH; 553*3d8817e4Smiod 554*3d8817e4Smiod /* Lookup a keyword from its name. */ 555*3d8817e4Smiod 556*3d8817e4Smiod const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_name 557*3d8817e4Smiod (CGEN_KEYWORD *, const char *); 558*3d8817e4Smiod 559*3d8817e4Smiod /* Lookup a keyword from its value. */ 560*3d8817e4Smiod 561*3d8817e4Smiod const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_value 562*3d8817e4Smiod (CGEN_KEYWORD *, int); 563*3d8817e4Smiod 564*3d8817e4Smiod /* Add a keyword. */ 565*3d8817e4Smiod 566*3d8817e4Smiod void cgen_keyword_add (CGEN_KEYWORD *, CGEN_KEYWORD_ENTRY *); 567*3d8817e4Smiod 568*3d8817e4Smiod /* Keyword searching. 569*3d8817e4Smiod This can be used to retrieve every keyword, or a subset. */ 570*3d8817e4Smiod 571*3d8817e4Smiod CGEN_KEYWORD_SEARCH cgen_keyword_search_init 572*3d8817e4Smiod (CGEN_KEYWORD *, const char *); 573*3d8817e4Smiod const CGEN_KEYWORD_ENTRY *cgen_keyword_search_next 574*3d8817e4Smiod (CGEN_KEYWORD_SEARCH *); 575*3d8817e4Smiod 576*3d8817e4Smiod /* Operand value support routines. */ 577*3d8817e4Smiod 578*3d8817e4Smiod extern const char *cgen_parse_keyword 579*3d8817e4Smiod (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *); 580*3d8817e4Smiod #ifdef __BFD_H_SEEN__ /* Don't require bfd.h unnecessarily. */ 581*3d8817e4Smiod extern const char *cgen_parse_signed_integer 582*3d8817e4Smiod (CGEN_CPU_DESC, const char **, int, long *); 583*3d8817e4Smiod extern const char *cgen_parse_unsigned_integer 584*3d8817e4Smiod (CGEN_CPU_DESC, const char **, int, unsigned long *); 585*3d8817e4Smiod extern const char *cgen_parse_address 586*3d8817e4Smiod (CGEN_CPU_DESC, const char **, int, int, 587*3d8817e4Smiod enum cgen_parse_operand_result *, bfd_vma *); 588*3d8817e4Smiod extern const char *cgen_validate_signed_integer 589*3d8817e4Smiod (long, long, long); 590*3d8817e4Smiod extern const char *cgen_validate_unsigned_integer 591*3d8817e4Smiod (unsigned long, unsigned long, unsigned long); 592*3d8817e4Smiod #endif 593*3d8817e4Smiod 594*3d8817e4Smiod /* Operand modes. */ 595*3d8817e4Smiod 596*3d8817e4Smiod /* ??? This duplicates the values in arch.h. Revisit. 597*3d8817e4Smiod These however need the CGEN_ prefix [as does everything in this file]. */ 598*3d8817e4Smiod /* ??? Targets may need to add their own modes so we may wish to move this 599*3d8817e4Smiod to <arch>-opc.h, or add a hook. */ 600*3d8817e4Smiod 601*3d8817e4Smiod enum cgen_mode { 602*3d8817e4Smiod CGEN_MODE_VOID, /* ??? rename simulator's VM to VOID? */ 603*3d8817e4Smiod CGEN_MODE_BI, CGEN_MODE_QI, CGEN_MODE_HI, CGEN_MODE_SI, CGEN_MODE_DI, 604*3d8817e4Smiod CGEN_MODE_UBI, CGEN_MODE_UQI, CGEN_MODE_UHI, CGEN_MODE_USI, CGEN_MODE_UDI, 605*3d8817e4Smiod CGEN_MODE_SF, CGEN_MODE_DF, CGEN_MODE_XF, CGEN_MODE_TF, 606*3d8817e4Smiod CGEN_MODE_TARGET_MAX, 607*3d8817e4Smiod CGEN_MODE_INT, CGEN_MODE_UINT, 608*3d8817e4Smiod CGEN_MODE_MAX 609*3d8817e4Smiod }; 610*3d8817e4Smiod 611*3d8817e4Smiod /* FIXME: Until simulator is updated. */ 612*3d8817e4Smiod 613*3d8817e4Smiod #define CGEN_MODE_VM CGEN_MODE_VOID 614*3d8817e4Smiod 615*3d8817e4Smiod /* Operands. */ 616*3d8817e4Smiod 617*3d8817e4Smiod #ifndef CGEN_ARCH 618*3d8817e4Smiod enum cgen_operand_type { CGEN_OPERAND_MAX }; 619*3d8817e4Smiod #endif 620*3d8817e4Smiod 621*3d8817e4Smiod /* "nil" indicator for the operand instance table */ 622*3d8817e4Smiod #define CGEN_OPERAND_NIL CGEN_OPERAND_MAX 623*3d8817e4Smiod 624*3d8817e4Smiod /* A tree of these structs represents the multi-ifield 625*3d8817e4Smiod structure of an operand's hw-index value, if it exists. */ 626*3d8817e4Smiod 627*3d8817e4Smiod struct cgen_ifld; 628*3d8817e4Smiod 629*3d8817e4Smiod typedef struct cgen_maybe_multi_ifield 630*3d8817e4Smiod { 631*3d8817e4Smiod int count; /* 0: indexed by single cgen_ifld (possibly null: dead entry); 632*3d8817e4Smiod n: indexed by array of more cgen_maybe_multi_ifields. */ 633*3d8817e4Smiod union 634*3d8817e4Smiod { 635*3d8817e4Smiod const void *p; 636*3d8817e4Smiod const struct cgen_maybe_multi_ifield * multi; 637*3d8817e4Smiod const struct cgen_ifld * leaf; 638*3d8817e4Smiod } val; 639*3d8817e4Smiod } 640*3d8817e4Smiod CGEN_MAYBE_MULTI_IFLD; 641*3d8817e4Smiod 642*3d8817e4Smiod /* This struct defines each entry in the operand table. */ 643*3d8817e4Smiod 644*3d8817e4Smiod typedef struct 645*3d8817e4Smiod { 646*3d8817e4Smiod /* Name as it appears in the syntax string. */ 647*3d8817e4Smiod char *name; 648*3d8817e4Smiod 649*3d8817e4Smiod /* Operand type. */ 650*3d8817e4Smiod enum cgen_operand_type type; 651*3d8817e4Smiod 652*3d8817e4Smiod /* The hardware element associated with this operand. */ 653*3d8817e4Smiod enum cgen_hw_type hw_type; 654*3d8817e4Smiod 655*3d8817e4Smiod /* FIXME: We don't yet record ifield definitions, which we should. 656*3d8817e4Smiod When we do it might make sense to delete start/length (since they will 657*3d8817e4Smiod be duplicated in the ifield's definition) and replace them with a 658*3d8817e4Smiod pointer to the ifield entry. */ 659*3d8817e4Smiod 660*3d8817e4Smiod /* Bit position. 661*3d8817e4Smiod This is just a hint, and may be unused in more complex operands. 662*3d8817e4Smiod May be unused for a modifier. */ 663*3d8817e4Smiod unsigned char start; 664*3d8817e4Smiod 665*3d8817e4Smiod /* The number of bits in the operand. 666*3d8817e4Smiod This is just a hint, and may be unused in more complex operands. 667*3d8817e4Smiod May be unused for a modifier. */ 668*3d8817e4Smiod unsigned char length; 669*3d8817e4Smiod 670*3d8817e4Smiod /* The (possibly-multi) ifield used as an index for this operand, if it 671*3d8817e4Smiod is indexed by a field at all. This substitutes / extends the start and 672*3d8817e4Smiod length fields above, but unsure at this time whether they are used 673*3d8817e4Smiod anywhere. */ 674*3d8817e4Smiod CGEN_MAYBE_MULTI_IFLD index_fields; 675*3d8817e4Smiod #if 0 /* ??? Interesting idea but relocs tend to get too complicated, 676*3d8817e4Smiod and ABI dependent, for simple table lookups to work. */ 677*3d8817e4Smiod /* Ideally this would be the internal (external?) reloc type. */ 678*3d8817e4Smiod int reloc_type; 679*3d8817e4Smiod #endif 680*3d8817e4Smiod 681*3d8817e4Smiod /* Attributes. 682*3d8817e4Smiod This should, but technically needn't, appear last. It is a variable sized 683*3d8817e4Smiod array in that one architecture may have 1 nonbool attribute and another 684*3d8817e4Smiod may have more. Having this last means the non-architecture specific code 685*3d8817e4Smiod needn't care, now or tomorrow. The goal is to eventually record 686*3d8817e4Smiod attributes in their raw form, evaluate them at run-time, and cache the 687*3d8817e4Smiod values, so this worry will go away anyway. */ 688*3d8817e4Smiod #ifndef CGEN_OPERAND_NBOOL_ATTRS 689*3d8817e4Smiod #define CGEN_OPERAND_NBOOL_ATTRS 1 690*3d8817e4Smiod #endif 691*3d8817e4Smiod CGEN_ATTR_TYPE (CGEN_OPERAND_NBOOL_ATTRS) attrs; 692*3d8817e4Smiod #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs) 693*3d8817e4Smiod } CGEN_OPERAND; 694*3d8817e4Smiod 695*3d8817e4Smiod /* Return value of attribute ATTR in OPERAND. */ 696*3d8817e4Smiod 697*3d8817e4Smiod #define CGEN_OPERAND_ATTR_VALUE(operand, attr) \ 698*3d8817e4Smiod CGEN_ATTR_VALUE ((operand), CGEN_OPERAND_ATTRS (operand), (attr)) 699*3d8817e4Smiod 700*3d8817e4Smiod /* Table of operands for selected mach/isa, computed at runtime. 701*3d8817e4Smiod enum cgen_operand_type is an index into this table (specifically 702*3d8817e4Smiod `entries'). */ 703*3d8817e4Smiod 704*3d8817e4Smiod typedef struct { 705*3d8817e4Smiod /* Pointer to null terminated table of all compiled in entries. */ 706*3d8817e4Smiod const CGEN_OPERAND *init_entries; 707*3d8817e4Smiod unsigned int entry_size; /* since the attribute member is variable sized */ 708*3d8817e4Smiod /* Array of all entries, initial and run-time added. */ 709*3d8817e4Smiod const CGEN_OPERAND **entries; 710*3d8817e4Smiod /* Number of elements in `entries'. */ 711*3d8817e4Smiod unsigned int num_entries; 712*3d8817e4Smiod /* For now, xrealloc is called each time a new entry is added at runtime. 713*3d8817e4Smiod ??? May wish to keep track of some slop to reduce the number of calls to 714*3d8817e4Smiod xrealloc, except that there's unlikely to be many and not expected to be 715*3d8817e4Smiod in speed critical code. */ 716*3d8817e4Smiod } CGEN_OPERAND_TABLE; 717*3d8817e4Smiod 718*3d8817e4Smiod extern const CGEN_OPERAND * cgen_operand_lookup_by_name 719*3d8817e4Smiod (CGEN_CPU_DESC, const char *); 720*3d8817e4Smiod extern const CGEN_OPERAND * cgen_operand_lookup_by_num 721*3d8817e4Smiod (CGEN_CPU_DESC, int); 722*3d8817e4Smiod 723*3d8817e4Smiod /* Instruction operand instances. 724*3d8817e4Smiod 725*3d8817e4Smiod For each instruction, a list of the hardware elements that are read and 726*3d8817e4Smiod written are recorded. */ 727*3d8817e4Smiod 728*3d8817e4Smiod /* The type of the instance. */ 729*3d8817e4Smiod 730*3d8817e4Smiod enum cgen_opinst_type { 731*3d8817e4Smiod /* End of table marker. */ 732*3d8817e4Smiod CGEN_OPINST_END = 0, 733*3d8817e4Smiod CGEN_OPINST_INPUT, CGEN_OPINST_OUTPUT 734*3d8817e4Smiod }; 735*3d8817e4Smiod 736*3d8817e4Smiod typedef struct 737*3d8817e4Smiod { 738*3d8817e4Smiod /* Input or output indicator. */ 739*3d8817e4Smiod enum cgen_opinst_type type; 740*3d8817e4Smiod 741*3d8817e4Smiod /* Name of operand. */ 742*3d8817e4Smiod const char *name; 743*3d8817e4Smiod 744*3d8817e4Smiod /* The hardware element referenced. */ 745*3d8817e4Smiod enum cgen_hw_type hw_type; 746*3d8817e4Smiod 747*3d8817e4Smiod /* The mode in which the operand is being used. */ 748*3d8817e4Smiod enum cgen_mode mode; 749*3d8817e4Smiod 750*3d8817e4Smiod /* The operand table entry CGEN_OPERAND_NIL if there is none 751*3d8817e4Smiod (i.e. an explicit hardware reference). */ 752*3d8817e4Smiod enum cgen_operand_type op_type; 753*3d8817e4Smiod 754*3d8817e4Smiod /* If `operand' is "nil", the index (e.g. into array of registers). */ 755*3d8817e4Smiod int index; 756*3d8817e4Smiod 757*3d8817e4Smiod /* Attributes. 758*3d8817e4Smiod ??? This perhaps should be a real attribute struct but there's 759*3d8817e4Smiod no current need, so we save a bit of space and just have a set of 760*3d8817e4Smiod flags. The interface is such that this can easily be made attributes 761*3d8817e4Smiod should it prove useful. */ 762*3d8817e4Smiod unsigned int attrs; 763*3d8817e4Smiod #define CGEN_OPINST_ATTRS(opinst) ((opinst)->attrs) 764*3d8817e4Smiod /* Return value of attribute ATTR in OPINST. */ 765*3d8817e4Smiod #define CGEN_OPINST_ATTR(opinst, attr) \ 766*3d8817e4Smiod ((CGEN_OPINST_ATTRS (opinst) & (attr)) != 0) 767*3d8817e4Smiod /* Operand is conditionally referenced (read/written). */ 768*3d8817e4Smiod #define CGEN_OPINST_COND_REF 1 769*3d8817e4Smiod } CGEN_OPINST; 770*3d8817e4Smiod 771*3d8817e4Smiod /* Syntax string. 772*3d8817e4Smiod 773*3d8817e4Smiod Each insn format and subexpression has one of these. 774*3d8817e4Smiod 775*3d8817e4Smiod The syntax "string" consists of characters (n > 0 && n < 128), and operand 776*3d8817e4Smiod values (n >= 128), and is terminated by 0. Operand values are 128 + index 777*3d8817e4Smiod into the operand table. The operand table doesn't exist in C, per se, as 778*3d8817e4Smiod the data is recorded in the parse/insert/extract/print switch statements. */ 779*3d8817e4Smiod 780*3d8817e4Smiod /* This should be at least as large as necessary for any target. */ 781*3d8817e4Smiod #define CGEN_MAX_SYNTAX_ELEMENTS 48 782*3d8817e4Smiod 783*3d8817e4Smiod /* A target may know its own precise maximum. Assert that it falls below 784*3d8817e4Smiod the above limit. */ 785*3d8817e4Smiod #ifdef CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS 786*3d8817e4Smiod #if CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS > CGEN_MAX_SYNTAX_ELEMENTS 787*3d8817e4Smiod #error "CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS too high - enlarge CGEN_MAX_SYNTAX_ELEMENTS" 788*3d8817e4Smiod #endif 789*3d8817e4Smiod #endif 790*3d8817e4Smiod 791*3d8817e4Smiod typedef unsigned short CGEN_SYNTAX_CHAR_TYPE; 792*3d8817e4Smiod 793*3d8817e4Smiod typedef struct 794*3d8817e4Smiod { 795*3d8817e4Smiod CGEN_SYNTAX_CHAR_TYPE syntax[CGEN_MAX_SYNTAX_ELEMENTS]; 796*3d8817e4Smiod } CGEN_SYNTAX; 797*3d8817e4Smiod 798*3d8817e4Smiod #define CGEN_SYNTAX_STRING(syn) (syn->syntax) 799*3d8817e4Smiod #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128) 800*3d8817e4Smiod #define CGEN_SYNTAX_CHAR(c) ((unsigned char)c) 801*3d8817e4Smiod #define CGEN_SYNTAX_FIELD(c) ((c) - 128) 802*3d8817e4Smiod #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128) 803*3d8817e4Smiod 804*3d8817e4Smiod /* ??? I can't currently think of any case where the mnemonic doesn't come 805*3d8817e4Smiod first [and if one ever doesn't building the hash tables will be tricky]. 806*3d8817e4Smiod However, we treat mnemonics as just another operand of the instruction. 807*3d8817e4Smiod A value of 1 means "this is where the mnemonic appears". 1 isn't 808*3d8817e4Smiod special other than it's a non-printable ASCII char. */ 809*3d8817e4Smiod 810*3d8817e4Smiod #define CGEN_SYNTAX_MNEMONIC 1 811*3d8817e4Smiod #define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == CGEN_SYNTAX_MNEMONIC) 812*3d8817e4Smiod 813*3d8817e4Smiod /* Instruction fields. 814*3d8817e4Smiod 815*3d8817e4Smiod ??? We currently don't allow adding fields at run-time. 816*3d8817e4Smiod Easy to fix when needed. */ 817*3d8817e4Smiod 818*3d8817e4Smiod typedef struct cgen_ifld { 819*3d8817e4Smiod /* Enum of ifield. */ 820*3d8817e4Smiod int num; 821*3d8817e4Smiod #define CGEN_IFLD_NUM(f) ((f)->num) 822*3d8817e4Smiod 823*3d8817e4Smiod /* Name of the field, distinguishes it from all other fields. */ 824*3d8817e4Smiod const char *name; 825*3d8817e4Smiod #define CGEN_IFLD_NAME(f) ((f)->name) 826*3d8817e4Smiod 827*3d8817e4Smiod /* Default offset, in bits, from the start of the insn to the word 828*3d8817e4Smiod containing the field. */ 829*3d8817e4Smiod int word_offset; 830*3d8817e4Smiod #define CGEN_IFLD_WORD_OFFSET(f) ((f)->word_offset) 831*3d8817e4Smiod 832*3d8817e4Smiod /* Default length of the word containing the field. */ 833*3d8817e4Smiod int word_size; 834*3d8817e4Smiod #define CGEN_IFLD_WORD_SIZE(f) ((f)->word_size) 835*3d8817e4Smiod 836*3d8817e4Smiod /* Default starting bit number. 837*3d8817e4Smiod Whether lsb=0 or msb=0 is determined by CGEN_INSN_LSB0_P. */ 838*3d8817e4Smiod int start; 839*3d8817e4Smiod #define CGEN_IFLD_START(f) ((f)->start) 840*3d8817e4Smiod 841*3d8817e4Smiod /* Length of the field, in bits. */ 842*3d8817e4Smiod int length; 843*3d8817e4Smiod #define CGEN_IFLD_LENGTH(f) ((f)->length) 844*3d8817e4Smiod 845*3d8817e4Smiod #ifndef CGEN_IFLD_NBOOL_ATTRS 846*3d8817e4Smiod #define CGEN_IFLD_NBOOL_ATTRS 1 847*3d8817e4Smiod #endif 848*3d8817e4Smiod CGEN_ATTR_TYPE (CGEN_IFLD_NBOOL_ATTRS) attrs; 849*3d8817e4Smiod #define CGEN_IFLD_ATTRS(f) (&(f)->attrs) 850*3d8817e4Smiod } CGEN_IFLD; 851*3d8817e4Smiod 852*3d8817e4Smiod /* Return value of attribute ATTR in IFLD. */ 853*3d8817e4Smiod #define CGEN_IFLD_ATTR_VALUE(ifld, attr) \ 854*3d8817e4Smiod CGEN_ATTR_VALUE ((ifld), CGEN_IFLD_ATTRS (ifld), (attr)) 855*3d8817e4Smiod 856*3d8817e4Smiod /* Instruction data. */ 857*3d8817e4Smiod 858*3d8817e4Smiod /* Instruction formats. 859*3d8817e4Smiod 860*3d8817e4Smiod Instructions are grouped by format. Associated with an instruction is its 861*3d8817e4Smiod format. Each insn's opcode table entry contains a format table entry. 862*3d8817e4Smiod ??? There is usually very few formats compared with the number of insns, 863*3d8817e4Smiod so one can reduce the size of the opcode table by recording the format table 864*3d8817e4Smiod as a separate entity. Given that we currently don't, format table entries 865*3d8817e4Smiod are also distinguished by their operands. This increases the size of the 866*3d8817e4Smiod table, but reduces the number of tables. It's all minutiae anyway so it 867*3d8817e4Smiod doesn't really matter [at this point in time]. 868*3d8817e4Smiod 869*3d8817e4Smiod ??? Support for variable length ISA's is wip. */ 870*3d8817e4Smiod 871*3d8817e4Smiod /* Accompanying each iformat description is a list of its fields. */ 872*3d8817e4Smiod 873*3d8817e4Smiod typedef struct { 874*3d8817e4Smiod const CGEN_IFLD *ifld; 875*3d8817e4Smiod #define CGEN_IFMT_IFLD_IFLD(ii) ((ii)->ifld) 876*3d8817e4Smiod } CGEN_IFMT_IFLD; 877*3d8817e4Smiod 878*3d8817e4Smiod /* This should be at least as large as necessary for any target. */ 879*3d8817e4Smiod #define CGEN_MAX_IFMT_OPERANDS 16 880*3d8817e4Smiod 881*3d8817e4Smiod /* A target may know its own precise maximum. Assert that it falls below 882*3d8817e4Smiod the above limit. */ 883*3d8817e4Smiod #ifdef CGEN_ACTUAL_MAX_IFMT_OPERANDS 884*3d8817e4Smiod #if CGEN_ACTUAL_MAX_IFMT_OPERANDS > CGEN_MAX_IFMT_OPERANDS 885*3d8817e4Smiod #error "CGEN_ACTUAL_MAX_IFMT_OPERANDS too high - enlarge CGEN_MAX_IFMT_OPERANDS" 886*3d8817e4Smiod #endif 887*3d8817e4Smiod #endif 888*3d8817e4Smiod 889*3d8817e4Smiod 890*3d8817e4Smiod typedef struct 891*3d8817e4Smiod { 892*3d8817e4Smiod /* Length that MASK and VALUE have been calculated to 893*3d8817e4Smiod [VALUE is recorded elsewhere]. 894*3d8817e4Smiod Normally it is base_insn_bitsize. On [V]LIW architectures where the base 895*3d8817e4Smiod insn size may be larger than the size of an insn, this field is less than 896*3d8817e4Smiod base_insn_bitsize. */ 897*3d8817e4Smiod unsigned char mask_length; 898*3d8817e4Smiod #define CGEN_IFMT_MASK_LENGTH(ifmt) ((ifmt)->mask_length) 899*3d8817e4Smiod 900*3d8817e4Smiod /* Total length of instruction, in bits. */ 901*3d8817e4Smiod unsigned char length; 902*3d8817e4Smiod #define CGEN_IFMT_LENGTH(ifmt) ((ifmt)->length) 903*3d8817e4Smiod 904*3d8817e4Smiod /* Mask to apply to the first MASK_LENGTH bits. 905*3d8817e4Smiod Each insn's value is stored with the insn. 906*3d8817e4Smiod The first step in recognizing an insn for disassembly is 907*3d8817e4Smiod (opcode & mask) == value. */ 908*3d8817e4Smiod CGEN_INSN_INT mask; 909*3d8817e4Smiod #define CGEN_IFMT_MASK(ifmt) ((ifmt)->mask) 910*3d8817e4Smiod 911*3d8817e4Smiod /* Instruction fields. 912*3d8817e4Smiod +1 for trailing NULL. */ 913*3d8817e4Smiod CGEN_IFMT_IFLD iflds[CGEN_MAX_IFMT_OPERANDS + 1]; 914*3d8817e4Smiod #define CGEN_IFMT_IFLDS(ifmt) ((ifmt)->iflds) 915*3d8817e4Smiod } CGEN_IFMT; 916*3d8817e4Smiod 917*3d8817e4Smiod /* Instruction values. */ 918*3d8817e4Smiod 919*3d8817e4Smiod typedef struct 920*3d8817e4Smiod { 921*3d8817e4Smiod /* The opcode portion of the base insn. */ 922*3d8817e4Smiod CGEN_INSN_INT base_value; 923*3d8817e4Smiod 924*3d8817e4Smiod #ifdef CGEN_MAX_EXTRA_OPCODE_OPERANDS 925*3d8817e4Smiod /* Extra opcode values beyond base_value. */ 926*3d8817e4Smiod unsigned long ifield_values[CGEN_MAX_EXTRA_OPCODE_OPERANDS]; 927*3d8817e4Smiod #endif 928*3d8817e4Smiod } CGEN_IVALUE; 929*3d8817e4Smiod 930*3d8817e4Smiod /* Instruction opcode table. 931*3d8817e4Smiod This contains the syntax and format data of an instruction. */ 932*3d8817e4Smiod 933*3d8817e4Smiod /* ??? Some ports already have an opcode table yet still need to use the rest 934*3d8817e4Smiod of what cgen_insn has. Plus keeping the opcode data with the operand 935*3d8817e4Smiod instance data can create a pretty big file. So we keep them separately. 936*3d8817e4Smiod Not sure this is a good idea in the long run. */ 937*3d8817e4Smiod 938*3d8817e4Smiod typedef struct 939*3d8817e4Smiod { 940*3d8817e4Smiod /* Indices into parse/insert/extract/print handler tables. */ 941*3d8817e4Smiod struct cgen_opcode_handler handlers; 942*3d8817e4Smiod #define CGEN_OPCODE_HANDLERS(opc) (& (opc)->handlers) 943*3d8817e4Smiod 944*3d8817e4Smiod /* Syntax string. */ 945*3d8817e4Smiod CGEN_SYNTAX syntax; 946*3d8817e4Smiod #define CGEN_OPCODE_SYNTAX(opc) (& (opc)->syntax) 947*3d8817e4Smiod 948*3d8817e4Smiod /* Format entry. */ 949*3d8817e4Smiod const CGEN_IFMT *format; 950*3d8817e4Smiod #define CGEN_OPCODE_FORMAT(opc) ((opc)->format) 951*3d8817e4Smiod #define CGEN_OPCODE_MASK_BITSIZE(opc) CGEN_IFMT_MASK_LENGTH (CGEN_OPCODE_FORMAT (opc)) 952*3d8817e4Smiod #define CGEN_OPCODE_BITSIZE(opc) CGEN_IFMT_LENGTH (CGEN_OPCODE_FORMAT (opc)) 953*3d8817e4Smiod #define CGEN_OPCODE_IFLDS(opc) CGEN_IFMT_IFLDS (CGEN_OPCODE_FORMAT (opc)) 954*3d8817e4Smiod 955*3d8817e4Smiod /* Instruction opcode value. */ 956*3d8817e4Smiod CGEN_IVALUE value; 957*3d8817e4Smiod #define CGEN_OPCODE_VALUE(opc) (& (opc)->value) 958*3d8817e4Smiod #define CGEN_OPCODE_BASE_VALUE(opc) (CGEN_OPCODE_VALUE (opc)->base_value) 959*3d8817e4Smiod #define CGEN_OPCODE_BASE_MASK(opc) CGEN_IFMT_MASK (CGEN_OPCODE_FORMAT (opc)) 960*3d8817e4Smiod } CGEN_OPCODE; 961*3d8817e4Smiod 962*3d8817e4Smiod /* Instruction attributes. 963*3d8817e4Smiod This is made a published type as applications can cache a pointer to 964*3d8817e4Smiod the attributes for speed. */ 965*3d8817e4Smiod 966*3d8817e4Smiod #ifndef CGEN_INSN_NBOOL_ATTRS 967*3d8817e4Smiod #define CGEN_INSN_NBOOL_ATTRS 1 968*3d8817e4Smiod #endif 969*3d8817e4Smiod typedef CGEN_ATTR_TYPE (CGEN_INSN_NBOOL_ATTRS) CGEN_INSN_ATTR_TYPE; 970*3d8817e4Smiod 971*3d8817e4Smiod /* Enum of architecture independent attributes. */ 972*3d8817e4Smiod 973*3d8817e4Smiod #ifndef CGEN_ARCH 974*3d8817e4Smiod /* ??? Numbers here are recorded in two places. */ 975*3d8817e4Smiod typedef enum cgen_insn_attr { 976*3d8817e4Smiod CGEN_INSN_ALIAS = 0 977*3d8817e4Smiod } CGEN_INSN_ATTR; 978*3d8817e4Smiod #define CGEN_ATTR_CGEN_INSN_ALIAS_VALUE(attrs) ((attrs)->bool & (1 << CGEN_INSN_ALIAS)) 979*3d8817e4Smiod #endif 980*3d8817e4Smiod 981*3d8817e4Smiod /* This struct defines each entry in the instruction table. */ 982*3d8817e4Smiod 983*3d8817e4Smiod typedef struct 984*3d8817e4Smiod { 985*3d8817e4Smiod /* Each real instruction is enumerated. */ 986*3d8817e4Smiod /* ??? This may go away in time. */ 987*3d8817e4Smiod int num; 988*3d8817e4Smiod #define CGEN_INSN_NUM(insn) ((insn)->base->num) 989*3d8817e4Smiod 990*3d8817e4Smiod /* Name of entry (that distinguishes it from all other entries). */ 991*3d8817e4Smiod /* ??? If mnemonics have operands, try to print full mnemonic. */ 992*3d8817e4Smiod const char *name; 993*3d8817e4Smiod #define CGEN_INSN_NAME(insn) ((insn)->base->name) 994*3d8817e4Smiod 995*3d8817e4Smiod /* Mnemonic. This is used when parsing and printing the insn. 996*3d8817e4Smiod In the case of insns that have operands on the mnemonics, this is 997*3d8817e4Smiod only the constant part. E.g. for conditional execution of an `add' insn, 998*3d8817e4Smiod where the full mnemonic is addeq, addne, etc., and the condition is 999*3d8817e4Smiod treated as an operand, this is only "add". */ 1000*3d8817e4Smiod const char *mnemonic; 1001*3d8817e4Smiod #define CGEN_INSN_MNEMONIC(insn) ((insn)->base->mnemonic) 1002*3d8817e4Smiod 1003*3d8817e4Smiod /* Total length of instruction, in bits. */ 1004*3d8817e4Smiod int bitsize; 1005*3d8817e4Smiod #define CGEN_INSN_BITSIZE(insn) ((insn)->base->bitsize) 1006*3d8817e4Smiod 1007*3d8817e4Smiod #if 0 /* ??? Disabled for now as there is a problem with embedded newlines 1008*3d8817e4Smiod and the table is already pretty big. Should perhaps be moved 1009*3d8817e4Smiod to a file of its own. */ 1010*3d8817e4Smiod /* Semantics, as RTL. */ 1011*3d8817e4Smiod /* ??? Plain text or bytecodes? */ 1012*3d8817e4Smiod /* ??? Note that the operand instance table could be computed at run-time 1013*3d8817e4Smiod if we parse this and cache the results. Something to eventually do. */ 1014*3d8817e4Smiod const char *rtx; 1015*3d8817e4Smiod #define CGEN_INSN_RTX(insn) ((insn)->base->rtx) 1016*3d8817e4Smiod #endif 1017*3d8817e4Smiod 1018*3d8817e4Smiod /* Attributes. 1019*3d8817e4Smiod This must appear last. It is a variable sized array in that one 1020*3d8817e4Smiod architecture may have 1 nonbool attribute and another may have more. 1021*3d8817e4Smiod Having this last means the non-architecture specific code needn't 1022*3d8817e4Smiod care. The goal is to eventually record attributes in their raw form, 1023*3d8817e4Smiod evaluate them at run-time, and cache the values, so this worry will go 1024*3d8817e4Smiod away anyway. */ 1025*3d8817e4Smiod CGEN_INSN_ATTR_TYPE attrs; 1026*3d8817e4Smiod #define CGEN_INSN_ATTRS(insn) (&(insn)->base->attrs) 1027*3d8817e4Smiod /* Return value of attribute ATTR in INSN. */ 1028*3d8817e4Smiod #define CGEN_INSN_ATTR_VALUE(insn, attr) \ 1029*3d8817e4Smiod CGEN_ATTR_VALUE ((insn), CGEN_INSN_ATTRS (insn), (attr)) 1030*3d8817e4Smiod #define CGEN_INSN_BITSET_ATTR_VALUE(insn, attr) \ 1031*3d8817e4Smiod CGEN_BITSET_ATTR_VALUE ((insn), CGEN_INSN_ATTRS (insn), (attr)) 1032*3d8817e4Smiod } CGEN_IBASE; 1033*3d8817e4Smiod 1034*3d8817e4Smiod /* Return non-zero if INSN is the "invalid" insn marker. */ 1035*3d8817e4Smiod 1036*3d8817e4Smiod #define CGEN_INSN_INVALID_P(insn) (CGEN_INSN_MNEMONIC (insn) == 0) 1037*3d8817e4Smiod 1038*3d8817e4Smiod /* Main struct contain instruction information. 1039*3d8817e4Smiod BASE is always present, the rest is present only if asked for. */ 1040*3d8817e4Smiod 1041*3d8817e4Smiod struct cgen_insn 1042*3d8817e4Smiod { 1043*3d8817e4Smiod /* ??? May be of use to put a type indicator here. 1044*3d8817e4Smiod Then this struct could different info for different classes of insns. */ 1045*3d8817e4Smiod /* ??? A speedup can be had by moving `base' into this struct. 1046*3d8817e4Smiod Maybe later. */ 1047*3d8817e4Smiod const CGEN_IBASE *base; 1048*3d8817e4Smiod const CGEN_OPCODE *opcode; 1049*3d8817e4Smiod const CGEN_OPINST *opinst; 1050*3d8817e4Smiod 1051*3d8817e4Smiod /* Regex to disambiguate overloaded opcodes */ 1052*3d8817e4Smiod void *rx; 1053*3d8817e4Smiod #define CGEN_INSN_RX(insn) ((insn)->rx) 1054*3d8817e4Smiod #define CGEN_MAX_RX_ELEMENTS (CGEN_MAX_SYNTAX_ELEMENTS * 5) 1055*3d8817e4Smiod }; 1056*3d8817e4Smiod 1057*3d8817e4Smiod /* Instruction lists. 1058*3d8817e4Smiod This is used for adding new entries and for creating the hash lists. */ 1059*3d8817e4Smiod 1060*3d8817e4Smiod typedef struct cgen_insn_list 1061*3d8817e4Smiod { 1062*3d8817e4Smiod struct cgen_insn_list *next; 1063*3d8817e4Smiod const CGEN_INSN *insn; 1064*3d8817e4Smiod } CGEN_INSN_LIST; 1065*3d8817e4Smiod 1066*3d8817e4Smiod /* Table of instructions. */ 1067*3d8817e4Smiod 1068*3d8817e4Smiod typedef struct 1069*3d8817e4Smiod { 1070*3d8817e4Smiod const CGEN_INSN *init_entries; 1071*3d8817e4Smiod unsigned int entry_size; /* since the attribute member is variable sized */ 1072*3d8817e4Smiod unsigned int num_init_entries; 1073*3d8817e4Smiod CGEN_INSN_LIST *new_entries; 1074*3d8817e4Smiod } CGEN_INSN_TABLE; 1075*3d8817e4Smiod 1076*3d8817e4Smiod /* Return number of instructions. This includes any added at run-time. */ 1077*3d8817e4Smiod 1078*3d8817e4Smiod extern int cgen_insn_count (CGEN_CPU_DESC); 1079*3d8817e4Smiod extern int cgen_macro_insn_count (CGEN_CPU_DESC); 1080*3d8817e4Smiod 1081*3d8817e4Smiod /* Macros to access the other insn elements not recorded in CGEN_IBASE. */ 1082*3d8817e4Smiod 1083*3d8817e4Smiod /* Fetch INSN's operand instance table. */ 1084*3d8817e4Smiod /* ??? Doesn't handle insns added at runtime. */ 1085*3d8817e4Smiod #define CGEN_INSN_OPERANDS(insn) ((insn)->opinst) 1086*3d8817e4Smiod 1087*3d8817e4Smiod /* Return INSN's opcode table entry. */ 1088*3d8817e4Smiod #define CGEN_INSN_OPCODE(insn) ((insn)->opcode) 1089*3d8817e4Smiod 1090*3d8817e4Smiod /* Return INSN's handler data. */ 1091*3d8817e4Smiod #define CGEN_INSN_HANDLERS(insn) CGEN_OPCODE_HANDLERS (CGEN_INSN_OPCODE (insn)) 1092*3d8817e4Smiod 1093*3d8817e4Smiod /* Return INSN's syntax. */ 1094*3d8817e4Smiod #define CGEN_INSN_SYNTAX(insn) CGEN_OPCODE_SYNTAX (CGEN_INSN_OPCODE (insn)) 1095*3d8817e4Smiod 1096*3d8817e4Smiod /* Return size of base mask in bits. */ 1097*3d8817e4Smiod #define CGEN_INSN_MASK_BITSIZE(insn) \ 1098*3d8817e4Smiod CGEN_OPCODE_MASK_BITSIZE (CGEN_INSN_OPCODE (insn)) 1099*3d8817e4Smiod 1100*3d8817e4Smiod /* Return mask of base part of INSN. */ 1101*3d8817e4Smiod #define CGEN_INSN_BASE_MASK(insn) \ 1102*3d8817e4Smiod CGEN_OPCODE_BASE_MASK (CGEN_INSN_OPCODE (insn)) 1103*3d8817e4Smiod 1104*3d8817e4Smiod /* Return value of base part of INSN. */ 1105*3d8817e4Smiod #define CGEN_INSN_BASE_VALUE(insn) \ 1106*3d8817e4Smiod CGEN_OPCODE_BASE_VALUE (CGEN_INSN_OPCODE (insn)) 1107*3d8817e4Smiod 1108*3d8817e4Smiod /* Standard way to test whether INSN is supported by MACH. 1109*3d8817e4Smiod MACH is one of enum mach_attr. 1110*3d8817e4Smiod The "|1" is because the base mach is always selected. */ 1111*3d8817e4Smiod #define CGEN_INSN_MACH_HAS_P(insn, mach) \ 1112*3d8817e4Smiod ((CGEN_INSN_ATTR_VALUE ((insn), CGEN_INSN_MACH) & ((1 << (mach)) | 1)) != 0) 1113*3d8817e4Smiod 1114*3d8817e4Smiod /* Macro instructions. 1115*3d8817e4Smiod Macro insns aren't real insns, they map to one or more real insns. 1116*3d8817e4Smiod E.g. An architecture's "nop" insn may actually be an "mv r0,r0" or 1117*3d8817e4Smiod some such. 1118*3d8817e4Smiod 1119*3d8817e4Smiod Macro insns can expand to nothing (e.g. a nop that is optimized away). 1120*3d8817e4Smiod This is useful in multi-insn macros that build a constant in a register. 1121*3d8817e4Smiod Of course this isn't the default behaviour and must be explicitly enabled. 1122*3d8817e4Smiod 1123*3d8817e4Smiod Assembly of macro-insns is relatively straightforward. Disassembly isn't. 1124*3d8817e4Smiod However, disassembly of at least some kinds of macro insns is important 1125*3d8817e4Smiod in order that the disassembled code preserve the readability of the original 1126*3d8817e4Smiod insn. What is attempted here is to disassemble all "simple" macro-insns, 1127*3d8817e4Smiod where "simple" is currently defined to mean "expands to one real insn". 1128*3d8817e4Smiod 1129*3d8817e4Smiod Simple macro-insns are handled specially. They are emitted as ALIAS's 1130*3d8817e4Smiod of real insns. This simplifies their handling since there's usually more 1131*3d8817e4Smiod of them than any other kind of macro-insn, and proper disassembly of them 1132*3d8817e4Smiod falls out for free. */ 1133*3d8817e4Smiod 1134*3d8817e4Smiod /* For each macro-insn there may be multiple expansion possibilities, 1135*3d8817e4Smiod depending on the arguments. This structure is accessed via the `data' 1136*3d8817e4Smiod member of CGEN_INSN. */ 1137*3d8817e4Smiod 1138*3d8817e4Smiod typedef struct cgen_minsn_expansion { 1139*3d8817e4Smiod /* Function to do the expansion. 1140*3d8817e4Smiod If the expansion fails (e.g. "no match") NULL is returned. 1141*3d8817e4Smiod Space for the expansion is obtained with malloc. 1142*3d8817e4Smiod It is up to the caller to free it. */ 1143*3d8817e4Smiod const char * (* fn) 1144*3d8817e4Smiod (const struct cgen_minsn_expansion *, 1145*3d8817e4Smiod const char *, const char **, int *, 1146*3d8817e4Smiod CGEN_OPERAND **); 1147*3d8817e4Smiod #define CGEN_MIEXPN_FN(ex) ((ex)->fn) 1148*3d8817e4Smiod 1149*3d8817e4Smiod /* Instruction(s) the macro expands to. 1150*3d8817e4Smiod The format of STR is defined by FN. 1151*3d8817e4Smiod It is typically the assembly code of the real insn, but it could also be 1152*3d8817e4Smiod the original Scheme expression or a tokenized form of it (with FN being 1153*3d8817e4Smiod an appropriate interpreter). */ 1154*3d8817e4Smiod const char * str; 1155*3d8817e4Smiod #define CGEN_MIEXPN_STR(ex) ((ex)->str) 1156*3d8817e4Smiod } CGEN_MINSN_EXPANSION; 1157*3d8817e4Smiod 1158*3d8817e4Smiod /* Normal expander. 1159*3d8817e4Smiod When supported, this function will convert the input string to another 1160*3d8817e4Smiod string and the parser will be invoked recursively. The output string 1161*3d8817e4Smiod may contain further macro invocations. */ 1162*3d8817e4Smiod 1163*3d8817e4Smiod extern const char * cgen_expand_macro_insn 1164*3d8817e4Smiod (CGEN_CPU_DESC, const struct cgen_minsn_expansion *, 1165*3d8817e4Smiod const char *, const char **, int *, CGEN_OPERAND **); 1166*3d8817e4Smiod 1167*3d8817e4Smiod /* The assembler insn table is hashed based on some function of the mnemonic 1168*3d8817e4Smiod (the actually hashing done is up to the target, but we provide a few 1169*3d8817e4Smiod examples like the first letter or a function of the entire mnemonic). */ 1170*3d8817e4Smiod 1171*3d8817e4Smiod extern CGEN_INSN_LIST * cgen_asm_lookup_insn 1172*3d8817e4Smiod (CGEN_CPU_DESC, const char *); 1173*3d8817e4Smiod #define CGEN_ASM_LOOKUP_INSN(cd, string) cgen_asm_lookup_insn ((cd), (string)) 1174*3d8817e4Smiod #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next) 1175*3d8817e4Smiod 1176*3d8817e4Smiod /* The disassembler insn table is hashed based on some function of machine 1177*3d8817e4Smiod instruction (the actually hashing done is up to the target). */ 1178*3d8817e4Smiod 1179*3d8817e4Smiod extern CGEN_INSN_LIST * cgen_dis_lookup_insn 1180*3d8817e4Smiod (CGEN_CPU_DESC, const char *, CGEN_INSN_INT); 1181*3d8817e4Smiod /* FIXME: delete these two */ 1182*3d8817e4Smiod #define CGEN_DIS_LOOKUP_INSN(cd, buf, value) cgen_dis_lookup_insn ((cd), (buf), (value)) 1183*3d8817e4Smiod #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next) 1184*3d8817e4Smiod 1185*3d8817e4Smiod /* The CPU description. 1186*3d8817e4Smiod A copy of this is created when the cpu table is "opened". 1187*3d8817e4Smiod All global state information is recorded here. 1188*3d8817e4Smiod Access macros are provided for "public" members. */ 1189*3d8817e4Smiod 1190*3d8817e4Smiod typedef struct cgen_cpu_desc 1191*3d8817e4Smiod { 1192*3d8817e4Smiod /* Bitmap of selected machine(s) (a la BFD machine number). */ 1193*3d8817e4Smiod int machs; 1194*3d8817e4Smiod 1195*3d8817e4Smiod /* Bitmap of selected isa(s). */ 1196*3d8817e4Smiod CGEN_BITSET *isas; 1197*3d8817e4Smiod #define CGEN_CPU_ISAS(cd) ((cd)->isas) 1198*3d8817e4Smiod 1199*3d8817e4Smiod /* Current endian. */ 1200*3d8817e4Smiod enum cgen_endian endian; 1201*3d8817e4Smiod #define CGEN_CPU_ENDIAN(cd) ((cd)->endian) 1202*3d8817e4Smiod 1203*3d8817e4Smiod /* Current insn endian. */ 1204*3d8817e4Smiod enum cgen_endian insn_endian; 1205*3d8817e4Smiod #define CGEN_CPU_INSN_ENDIAN(cd) ((cd)->insn_endian) 1206*3d8817e4Smiod 1207*3d8817e4Smiod /* Word size (in bits). */ 1208*3d8817e4Smiod /* ??? Or maybe maximum word size - might we ever need to allow a cpu table 1209*3d8817e4Smiod to be opened for both sparc32/sparc64? 1210*3d8817e4Smiod ??? Another alternative is to create a table of selected machs and 1211*3d8817e4Smiod lazily fetch the data from there. */ 1212*3d8817e4Smiod unsigned int word_bitsize; 1213*3d8817e4Smiod 1214*3d8817e4Smiod /* Instruction chunk size (in bits), for purposes of endianness 1215*3d8817e4Smiod conversion. */ 1216*3d8817e4Smiod unsigned int insn_chunk_bitsize; 1217*3d8817e4Smiod 1218*3d8817e4Smiod /* Indicator if sizes are unknown. 1219*3d8817e4Smiod This is used by default_insn_bitsize,base_insn_bitsize if there is a 1220*3d8817e4Smiod difference between the selected isa's. */ 1221*3d8817e4Smiod #define CGEN_SIZE_UNKNOWN 65535 1222*3d8817e4Smiod 1223*3d8817e4Smiod /* Default instruction size (in bits). 1224*3d8817e4Smiod This is used by the assembler when it encounters an unknown insn. */ 1225*3d8817e4Smiod unsigned int default_insn_bitsize; 1226*3d8817e4Smiod 1227*3d8817e4Smiod /* Base instruction size (in bits). 1228*3d8817e4Smiod For non-LIW cpus this is generally the length of the smallest insn. 1229*3d8817e4Smiod For LIW cpus its wip (work-in-progress). For the m32r its 32. */ 1230*3d8817e4Smiod unsigned int base_insn_bitsize; 1231*3d8817e4Smiod 1232*3d8817e4Smiod /* Minimum/maximum instruction size (in bits). */ 1233*3d8817e4Smiod unsigned int min_insn_bitsize; 1234*3d8817e4Smiod unsigned int max_insn_bitsize; 1235*3d8817e4Smiod 1236*3d8817e4Smiod /* Instruction set variants. */ 1237*3d8817e4Smiod const CGEN_ISA *isa_table; 1238*3d8817e4Smiod 1239*3d8817e4Smiod /* Machine variants. */ 1240*3d8817e4Smiod const CGEN_MACH *mach_table; 1241*3d8817e4Smiod 1242*3d8817e4Smiod /* Hardware elements. */ 1243*3d8817e4Smiod CGEN_HW_TABLE hw_table; 1244*3d8817e4Smiod 1245*3d8817e4Smiod /* Instruction fields. */ 1246*3d8817e4Smiod const CGEN_IFLD *ifld_table; 1247*3d8817e4Smiod 1248*3d8817e4Smiod /* Operands. */ 1249*3d8817e4Smiod CGEN_OPERAND_TABLE operand_table; 1250*3d8817e4Smiod 1251*3d8817e4Smiod /* Main instruction table. */ 1252*3d8817e4Smiod CGEN_INSN_TABLE insn_table; 1253*3d8817e4Smiod #define CGEN_CPU_INSN_TABLE(cd) (& (cd)->insn_table) 1254*3d8817e4Smiod 1255*3d8817e4Smiod /* Macro instructions are defined separately and are combined with real 1256*3d8817e4Smiod insns during hash table computation. */ 1257*3d8817e4Smiod CGEN_INSN_TABLE macro_insn_table; 1258*3d8817e4Smiod 1259*3d8817e4Smiod /* Copy of CGEN_INT_INSN_P. */ 1260*3d8817e4Smiod int int_insn_p; 1261*3d8817e4Smiod 1262*3d8817e4Smiod /* Called to rebuild the tables after something has changed. */ 1263*3d8817e4Smiod void (*rebuild_tables) (CGEN_CPU_DESC); 1264*3d8817e4Smiod 1265*3d8817e4Smiod /* Operand parser callback. */ 1266*3d8817e4Smiod cgen_parse_operand_fn * parse_operand_fn; 1267*3d8817e4Smiod 1268*3d8817e4Smiod /* Parse/insert/extract/print cover fns for operands. */ 1269*3d8817e4Smiod const char * (*parse_operand) 1270*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, const char **, CGEN_FIELDS *fields_); 1271*3d8817e4Smiod #ifdef __BFD_H_SEEN__ 1272*3d8817e4Smiod const char * (*insert_operand) 1273*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, 1274*3d8817e4Smiod CGEN_INSN_BYTES_PTR, bfd_vma pc_); 1275*3d8817e4Smiod int (*extract_operand) 1276*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, CGEN_EXTRACT_INFO *, CGEN_INSN_INT, 1277*3d8817e4Smiod CGEN_FIELDS *fields_, bfd_vma pc_); 1278*3d8817e4Smiod void (*print_operand) 1279*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, void * info_, CGEN_FIELDS * fields_, 1280*3d8817e4Smiod void const *attrs_, bfd_vma pc_, int length_); 1281*3d8817e4Smiod #else 1282*3d8817e4Smiod const char * (*insert_operand) (); 1283*3d8817e4Smiod int (*extract_operand) (); 1284*3d8817e4Smiod void (*print_operand) (); 1285*3d8817e4Smiod #endif 1286*3d8817e4Smiod #define CGEN_CPU_PARSE_OPERAND(cd) ((cd)->parse_operand) 1287*3d8817e4Smiod #define CGEN_CPU_INSERT_OPERAND(cd) ((cd)->insert_operand) 1288*3d8817e4Smiod #define CGEN_CPU_EXTRACT_OPERAND(cd) ((cd)->extract_operand) 1289*3d8817e4Smiod #define CGEN_CPU_PRINT_OPERAND(cd) ((cd)->print_operand) 1290*3d8817e4Smiod 1291*3d8817e4Smiod /* Size of CGEN_FIELDS struct. */ 1292*3d8817e4Smiod unsigned int sizeof_fields; 1293*3d8817e4Smiod #define CGEN_CPU_SIZEOF_FIELDS(cd) ((cd)->sizeof_fields) 1294*3d8817e4Smiod 1295*3d8817e4Smiod /* Set the bitsize field. */ 1296*3d8817e4Smiod void (*set_fields_bitsize) (CGEN_FIELDS *fields_, int size_); 1297*3d8817e4Smiod #define CGEN_CPU_SET_FIELDS_BITSIZE(cd) ((cd)->set_fields_bitsize) 1298*3d8817e4Smiod 1299*3d8817e4Smiod /* CGEN_FIELDS accessors. */ 1300*3d8817e4Smiod int (*get_int_operand) 1301*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_); 1302*3d8817e4Smiod void (*set_int_operand) 1303*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, int value_); 1304*3d8817e4Smiod #ifdef __BFD_H_SEEN__ 1305*3d8817e4Smiod bfd_vma (*get_vma_operand) 1306*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_); 1307*3d8817e4Smiod void (*set_vma_operand) 1308*3d8817e4Smiod (CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, bfd_vma value_); 1309*3d8817e4Smiod #else 1310*3d8817e4Smiod long (*get_vma_operand) (); 1311*3d8817e4Smiod void (*set_vma_operand) (); 1312*3d8817e4Smiod #endif 1313*3d8817e4Smiod #define CGEN_CPU_GET_INT_OPERAND(cd) ((cd)->get_int_operand) 1314*3d8817e4Smiod #define CGEN_CPU_SET_INT_OPERAND(cd) ((cd)->set_int_operand) 1315*3d8817e4Smiod #define CGEN_CPU_GET_VMA_OPERAND(cd) ((cd)->get_vma_operand) 1316*3d8817e4Smiod #define CGEN_CPU_SET_VMA_OPERAND(cd) ((cd)->set_vma_operand) 1317*3d8817e4Smiod 1318*3d8817e4Smiod /* Instruction parse/insert/extract/print handlers. */ 1319*3d8817e4Smiod /* FIXME: make these types uppercase. */ 1320*3d8817e4Smiod cgen_parse_fn * const *parse_handlers; 1321*3d8817e4Smiod cgen_insert_fn * const *insert_handlers; 1322*3d8817e4Smiod cgen_extract_fn * const *extract_handlers; 1323*3d8817e4Smiod cgen_print_fn * const *print_handlers; 1324*3d8817e4Smiod #define CGEN_PARSE_FN(cd, insn) (cd->parse_handlers[(insn)->opcode->handlers.parse]) 1325*3d8817e4Smiod #define CGEN_INSERT_FN(cd, insn) (cd->insert_handlers[(insn)->opcode->handlers.insert]) 1326*3d8817e4Smiod #define CGEN_EXTRACT_FN(cd, insn) (cd->extract_handlers[(insn)->opcode->handlers.extract]) 1327*3d8817e4Smiod #define CGEN_PRINT_FN(cd, insn) (cd->print_handlers[(insn)->opcode->handlers.print]) 1328*3d8817e4Smiod 1329*3d8817e4Smiod /* Return non-zero if insn should be added to hash table. */ 1330*3d8817e4Smiod int (* asm_hash_p) (const CGEN_INSN *); 1331*3d8817e4Smiod 1332*3d8817e4Smiod /* Assembler hash function. */ 1333*3d8817e4Smiod unsigned int (* asm_hash) (const char *); 1334*3d8817e4Smiod 1335*3d8817e4Smiod /* Number of entries in assembler hash table. */ 1336*3d8817e4Smiod unsigned int asm_hash_size; 1337*3d8817e4Smiod 1338*3d8817e4Smiod /* Return non-zero if insn should be added to hash table. */ 1339*3d8817e4Smiod int (* dis_hash_p) (const CGEN_INSN *); 1340*3d8817e4Smiod 1341*3d8817e4Smiod /* Disassembler hash function. */ 1342*3d8817e4Smiod unsigned int (* dis_hash) (const char *, CGEN_INSN_INT); 1343*3d8817e4Smiod 1344*3d8817e4Smiod /* Number of entries in disassembler hash table. */ 1345*3d8817e4Smiod unsigned int dis_hash_size; 1346*3d8817e4Smiod 1347*3d8817e4Smiod /* Assembler instruction hash table. */ 1348*3d8817e4Smiod CGEN_INSN_LIST **asm_hash_table; 1349*3d8817e4Smiod CGEN_INSN_LIST *asm_hash_table_entries; 1350*3d8817e4Smiod 1351*3d8817e4Smiod /* Disassembler instruction hash table. */ 1352*3d8817e4Smiod CGEN_INSN_LIST **dis_hash_table; 1353*3d8817e4Smiod CGEN_INSN_LIST *dis_hash_table_entries; 1354*3d8817e4Smiod 1355*3d8817e4Smiod /* This field could be turned into a bitfield if room for other flags is needed. */ 1356*3d8817e4Smiod unsigned int signed_overflow_ok_p; 1357*3d8817e4Smiod 1358*3d8817e4Smiod } CGEN_CPU_TABLE; 1359*3d8817e4Smiod 1360*3d8817e4Smiod /* wip */ 1361*3d8817e4Smiod #ifndef CGEN_WORD_ENDIAN 1362*3d8817e4Smiod #define CGEN_WORD_ENDIAN(cd) CGEN_CPU_ENDIAN (cd) 1363*3d8817e4Smiod #endif 1364*3d8817e4Smiod #ifndef CGEN_INSN_WORD_ENDIAN 1365*3d8817e4Smiod #define CGEN_INSN_WORD_ENDIAN(cd) CGEN_CPU_INSN_ENDIAN (cd) 1366*3d8817e4Smiod #endif 1367*3d8817e4Smiod 1368*3d8817e4Smiod /* Prototypes of major functions. */ 1369*3d8817e4Smiod /* FIXME: Move more CGEN_SYM-defined functions into CGEN_CPU_DESC. 1370*3d8817e4Smiod Not the init fns though, as that would drag in things that mightn't be 1371*3d8817e4Smiod used and might not even exist. */ 1372*3d8817e4Smiod 1373*3d8817e4Smiod /* Argument types to cpu_open. */ 1374*3d8817e4Smiod 1375*3d8817e4Smiod enum cgen_cpu_open_arg { 1376*3d8817e4Smiod CGEN_CPU_OPEN_END, 1377*3d8817e4Smiod /* Select instruction set(s), arg is bitmap or 0 meaning "unspecified". */ 1378*3d8817e4Smiod CGEN_CPU_OPEN_ISAS, 1379*3d8817e4Smiod /* Select machine(s), arg is bitmap or 0 meaning "unspecified". */ 1380*3d8817e4Smiod CGEN_CPU_OPEN_MACHS, 1381*3d8817e4Smiod /* Select machine, arg is mach's bfd name. 1382*3d8817e4Smiod Multiple machines can be specified by repeated use. */ 1383*3d8817e4Smiod CGEN_CPU_OPEN_BFDMACH, 1384*3d8817e4Smiod /* Select endian, arg is CGEN_ENDIAN_*. */ 1385*3d8817e4Smiod CGEN_CPU_OPEN_ENDIAN 1386*3d8817e4Smiod }; 1387*3d8817e4Smiod 1388*3d8817e4Smiod /* Open a cpu descriptor table for use. 1389*3d8817e4Smiod ??? We only support ISO C stdargs here, not K&R. 1390*3d8817e4Smiod Laziness, plus experiment to see if anything requires K&R - eventually 1391*3d8817e4Smiod K&R will no longer be supported - e.g. GDB is currently trying this. */ 1392*3d8817e4Smiod 1393*3d8817e4Smiod extern CGEN_CPU_DESC CGEN_SYM (cpu_open) (enum cgen_cpu_open_arg, ...); 1394*3d8817e4Smiod 1395*3d8817e4Smiod /* Cover fn to handle simple case. */ 1396*3d8817e4Smiod 1397*3d8817e4Smiod extern CGEN_CPU_DESC CGEN_SYM (cpu_open_1) 1398*3d8817e4Smiod (const char *mach_name_, enum cgen_endian endian_); 1399*3d8817e4Smiod 1400*3d8817e4Smiod /* Close it. */ 1401*3d8817e4Smiod 1402*3d8817e4Smiod extern void CGEN_SYM (cpu_close) (CGEN_CPU_DESC); 1403*3d8817e4Smiod 1404*3d8817e4Smiod /* Initialize the opcode table for use. 1405*3d8817e4Smiod Called by init_asm/init_dis. */ 1406*3d8817e4Smiod 1407*3d8817e4Smiod extern void CGEN_SYM (init_opcode_table) (CGEN_CPU_DESC cd_); 1408*3d8817e4Smiod 1409*3d8817e4Smiod /* build the insn selection regex. 1410*3d8817e4Smiod called by init_opcode_table */ 1411*3d8817e4Smiod 1412*3d8817e4Smiod extern char * CGEN_SYM(build_insn_regex) (CGEN_INSN *insn_); 1413*3d8817e4Smiod 1414*3d8817e4Smiod /* Initialize the ibld table for use. 1415*3d8817e4Smiod Called by init_asm/init_dis. */ 1416*3d8817e4Smiod 1417*3d8817e4Smiod extern void CGEN_SYM (init_ibld_table) (CGEN_CPU_DESC cd_); 1418*3d8817e4Smiod 1419*3d8817e4Smiod /* Initialize an cpu table for assembler or disassembler use. 1420*3d8817e4Smiod These must be called immediately after cpu_open. */ 1421*3d8817e4Smiod 1422*3d8817e4Smiod extern void CGEN_SYM (init_asm) (CGEN_CPU_DESC); 1423*3d8817e4Smiod extern void CGEN_SYM (init_dis) (CGEN_CPU_DESC); 1424*3d8817e4Smiod 1425*3d8817e4Smiod /* Initialize the operand instance table for use. */ 1426*3d8817e4Smiod 1427*3d8817e4Smiod extern void CGEN_SYM (init_opinst_table) (CGEN_CPU_DESC cd_); 1428*3d8817e4Smiod 1429*3d8817e4Smiod /* Assemble an instruction. */ 1430*3d8817e4Smiod 1431*3d8817e4Smiod extern const CGEN_INSN * CGEN_SYM (assemble_insn) 1432*3d8817e4Smiod (CGEN_CPU_DESC, const char *, CGEN_FIELDS *, 1433*3d8817e4Smiod CGEN_INSN_BYTES_PTR, char **); 1434*3d8817e4Smiod 1435*3d8817e4Smiod extern const CGEN_KEYWORD CGEN_SYM (operand_mach); 1436*3d8817e4Smiod extern int CGEN_SYM (get_mach) (const char *); 1437*3d8817e4Smiod 1438*3d8817e4Smiod /* Operand index computation. */ 1439*3d8817e4Smiod extern const CGEN_INSN * cgen_lookup_insn 1440*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN * insn_, 1441*3d8817e4Smiod CGEN_INSN_INT int_value_, unsigned char *bytes_value_, 1442*3d8817e4Smiod int length_, CGEN_FIELDS *fields_, int alias_p_); 1443*3d8817e4Smiod extern void cgen_get_insn_operands 1444*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN * insn_, 1445*3d8817e4Smiod const CGEN_FIELDS *fields_, int *indices_); 1446*3d8817e4Smiod extern const CGEN_INSN * cgen_lookup_get_insn_operands 1447*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *insn_, 1448*3d8817e4Smiod CGEN_INSN_INT int_value_, unsigned char *bytes_value_, 1449*3d8817e4Smiod int length_, int *indices_, CGEN_FIELDS *fields_); 1450*3d8817e4Smiod 1451*3d8817e4Smiod /* Cover fns to bfd_get/set. */ 1452*3d8817e4Smiod 1453*3d8817e4Smiod extern CGEN_INSN_INT cgen_get_insn_value 1454*3d8817e4Smiod (CGEN_CPU_DESC, unsigned char *, int); 1455*3d8817e4Smiod extern void cgen_put_insn_value 1456*3d8817e4Smiod (CGEN_CPU_DESC, unsigned char *, int, CGEN_INSN_INT); 1457*3d8817e4Smiod 1458*3d8817e4Smiod /* Read in a cpu description file. 1459*3d8817e4Smiod ??? For future concerns, including adding instructions to the assembler/ 1460*3d8817e4Smiod disassembler at run-time. */ 1461*3d8817e4Smiod 1462*3d8817e4Smiod extern const char * cgen_read_cpu_file (CGEN_CPU_DESC, const char * filename_); 1463*3d8817e4Smiod 1464*3d8817e4Smiod /* Allow signed overflow of instruction fields. */ 1465*3d8817e4Smiod extern void cgen_set_signed_overflow_ok (CGEN_CPU_DESC); 1466*3d8817e4Smiod 1467*3d8817e4Smiod /* Generate an error message if a signed field in an instruction overflows. */ 1468*3d8817e4Smiod extern void cgen_clear_signed_overflow_ok (CGEN_CPU_DESC); 1469*3d8817e4Smiod 1470*3d8817e4Smiod /* Will an error message be generated if a signed field in an instruction overflows ? */ 1471*3d8817e4Smiod extern unsigned int cgen_signed_overflow_ok_p (CGEN_CPU_DESC); 1472*3d8817e4Smiod 1473*3d8817e4Smiod #endif /* CGEN_H */ 1474