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