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