⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgen.h

📁 这个是LINUX下的GDB调度工具的源码
💻 H
📖 第 1 页 / 共 4 页
字号:
/* Header file for targets using CGEN: Cpu tools GENerator.Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002Free Software Foundation, Inc.This file is part of GDB, the GNU debugger, and the GNU Binutils.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#ifndef CGEN_H#define CGEN_H/* ??? This file requires bfd.h but only to get bfd_vma.   Seems like an awful lot to require just to get such a fundamental type.   Perhaps the definition of bfd_vma can be moved outside of bfd.h.   Or perhaps one could duplicate its definition in another file.   Until such time, this file conditionally compiles definitions that require   bfd_vma using __BFD_H_SEEN__.  *//* Enums must be defined before they can be used.   Allow them to be used in struct definitions, even though the enum must   be defined elsewhere.   If CGEN_ARCH isn't defined, this file is being included by something other   than <arch>-desc.h.  *//* Prepend the arch name, defined in <arch>-desc.h, and _cgen_ to symbol S.   The lack of spaces in the arg list is important for non-stdc systems.   This file is included by <arch>-desc.h.   It can be included independently of <arch>-desc.h, in which case the arch   dependent portions will be declared as "unknown_cgen_foo".  */#ifndef CGEN_SYM#define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s)#endif/* This file contains the static (unchanging) pieces and as much other stuff   as we can reasonably put here.  It's generally cleaner to put stuff here   rather than having it machine generated if possible.  *//* The assembler syntax is made up of expressions (duh...).   At the lowest level the values are mnemonics, register names, numbers, etc.   Above that are subexpressions, if any (an example might be the   "effective address" in m68k cpus).  Subexpressions are wip.   At the second highest level are the insns themselves.  Above that are   pseudo-insns, synthetic insns, and macros, if any.  *//* Lots of cpu's have a fixed insn size, or one which rarely changes,   and it's generally easier to handle these by treating the insn as an   integer type, rather than an array of characters.  So we allow targets   to control this.  When an integer type the value is in host byte order,   when an array of characters the value is in target byte order.  */typedef unsigned int CGEN_INSN_INT;#if CGEN_INT_INSN_Ptypedef CGEN_INSN_INT CGEN_INSN_BYTES;typedef CGEN_INSN_INT *CGEN_INSN_BYTES_PTR;#elsetypedef unsigned char *CGEN_INSN_BYTES;typedef unsigned char *CGEN_INSN_BYTES_PTR;#endif#ifdef __GNUC__#define CGEN_INLINE __inline__#else#define CGEN_INLINE#endifenum cgen_endian{  CGEN_ENDIAN_UNKNOWN,  CGEN_ENDIAN_LITTLE,  CGEN_ENDIAN_BIG};/* Forward decl.  */typedef struct cgen_insn CGEN_INSN;/* Opaque pointer version for use by external world.  */typedef struct cgen_cpu_desc *CGEN_CPU_DESC;/* Attributes.   Attributes are used to describe various random things associated with   an object (ifield, hardware, operand, insn, whatever) and are specified   as name/value pairs.   Integer attributes computed at compile time are currently all that's   supported, though adding string attributes and run-time computation is   straightforward.  Integer attribute values are always host int's   (signed or unsigned).  For portability, this means 32 bits.   Integer attributes are further categorized as boolean, bitset, integer,   and enum types.  Boolean attributes appear frequently enough that they're   recorded in one host int.  This limits the maximum number of boolean   attributes to 32, though that's a *lot* of attributes.  *//* Type of attribute values.  */typedef int CGEN_ATTR_VALUE_TYPE;/* Struct to record attribute information.  */typedef struct{  /* Boolean attributes.  */  unsigned int bool;  /* Non-boolean integer attributes.  */  CGEN_ATTR_VALUE_TYPE nonbool[1];} CGEN_ATTR;/* Define a structure member for attributes with N non-boolean entries.   There is no maximum number of non-boolean attributes.   There is a maximum of 32 boolean attributes (since they are all recorded   in one host int).  */#define CGEN_ATTR_TYPE(n) \struct { unsigned int bool; \	 CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; }/* Return the boolean attributes.  */#define CGEN_ATTR_BOOLS(a) ((a)->bool)/* Non-boolean attribute numbers are offset by this much.  */#define CGEN_ATTR_NBOOL_OFFSET 32/* Given a boolean attribute number, return its mask.  */#define CGEN_ATTR_MASK(attr) (1 << (attr))/* Return the value of boolean attribute ATTR in ATTRS.  */#define CGEN_BOOL_ATTR(attrs, attr) ((CGEN_ATTR_MASK (attr) & (attrs)) != 0)/* Return value of attribute ATTR in ATTR_TABLE for OBJ.   OBJ is a pointer to the entity that has the attributes   (??? not used at present but is reserved for future purposes - eventually   the goal is to allow recording attributes in source form and computing   them lazily at runtime, not sure of the details yet).  */#define CGEN_ATTR_VALUE(obj, attr_table, attr) \((unsigned int) (attr) < CGEN_ATTR_NBOOL_OFFSET \ ? ((CGEN_ATTR_BOOLS (attr_table) & CGEN_ATTR_MASK (attr)) != 0) \ : ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET]))/* Attribute name/value tables.   These are used to assist parsing of descriptions at run-time.  */typedef struct{  const char * name;  CGEN_ATTR_VALUE_TYPE value;} CGEN_ATTR_ENTRY;/* For each domain (ifld,hw,operand,insn), list of attributes.  */typedef struct{  const char * name;  const CGEN_ATTR_ENTRY * dfault;  const CGEN_ATTR_ENTRY * vals;} CGEN_ATTR_TABLE;/* Instruction set variants.  */typedef struct {  const char *name;  /* Default instruction size (in bits).     This is used by the assembler when it encounters an unknown insn.  */  unsigned int default_insn_bitsize;  /* Base instruction size (in bits).     For non-LIW cpus this is generally the length of the smallest insn.     For LIW cpus its wip (work-in-progress).  For the m32r its 32.  */  unsigned int base_insn_bitsize;  /* Minimum/maximum instruction size (in bits).  */  unsigned int min_insn_bitsize;  unsigned int max_insn_bitsize;} CGEN_ISA;/* Machine variants.  */typedef struct {  const char *name;  /* The argument to bfd_arch_info->scan.  */  const char *bfd_name;  /* one of enum mach_attr */  int num;  /* parameter from mach->cpu */  unsigned int insn_chunk_bitsize;} CGEN_MACH;/* Parse result (also extraction result).   The result of parsing an insn is stored here.   To generate the actual insn, this is passed to the insert handler.   When printing an insn, the result of extraction is stored here.   To print the insn, this is passed to the print handler.   It is machine generated so we don't define it here,   but we do need a forward decl for the handler fns.   There is one member for each possible field in the insn.   The type depends on the field.   Also recorded here is the computed length of the insn for architectures   where it varies.*/typedef struct cgen_fields CGEN_FIELDS;/* Total length of the insn, as recorded in the `fields' struct.  *//* ??? The field insert handler has lots of opportunities for optimization   if it ever gets inlined.  On architectures where insns all have the same   size, may wish to detect that and make this macro a constant - to allow   further optimizations.  */#define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)/* Extraction support for variable length insn sets.  *//* When disassembling we don't know the number of bytes to read at the start.   So the first CGEN_BASE_INSN_SIZE bytes are read at the start and the rest   are read when needed.  This struct controls this.  It is basically the   disassemble_info stuff, except that we provide a cache for values already   read (since bytes can typically be read several times to fetch multiple   operands that may be in them), and that extraction of fields is needed   in contexts other than disassembly.  */typedef struct {  /* A pointer to the disassemble_info struct.     We don't require dis-asm.h so we use void * for the type here.     If NULL, BYTES is full of valid data (VALID == -1).  */  void *dis_info;  /* Points to a working buffer of sufficient size.  */  unsigned char *insn_bytes;  /* Mask of bytes that are valid in INSN_BYTES.  */  unsigned int valid;} CGEN_EXTRACT_INFO;/* Associated with each insn or expression is a set of "handlers" for   performing operations like parsing, printing, etc.  These require a bfd_vma   value to be passed around but we don't want all applications to need bfd.h.   So this stuff is only provided if bfd.h has been included.  *//* Parse handler.   CD is a cpu table descriptor.   INSN is a pointer to a struct describing the insn being parsed.   STRP is a pointer to a pointer to the text being parsed.   FIELDS is a pointer to a cgen_fields struct in which the results are placed.   If the expression is successfully parsed, *STRP is updated.   If not it is left alone.   The result is NULL if success or an error message.  */typedef const char * (cgen_parse_fn)  (CGEN_CPU_DESC, const CGEN_INSN *insn_,   const char **strp_, CGEN_FIELDS *fields_);/* Insert handler.   CD is a cpu table descriptor.   INSN is a pointer to a struct describing the insn being parsed.   FIELDS is a pointer to a cgen_fields struct from which the values   are fetched.   INSNP is a pointer to a buffer in which to place the insn.   PC is the pc value of the insn.   The result is an error message or NULL if success.  */#ifdef __BFD_H_SEEN__typedef const char * (cgen_insert_fn)  (CGEN_CPU_DESC, const CGEN_INSN *insn_,   CGEN_FIELDS *fields_, CGEN_INSN_BYTES_PTR insnp_,   bfd_vma pc_);#elsetypedef const char * (cgen_insert_fn) ();#endif/* Extract handler.   CD is a cpu table descriptor.   INSN is a pointer to a struct describing the insn being parsed.   The second argument is a pointer to a struct controlling extraction   (only used for variable length insns).   EX_INFO is a pointer to a struct for controlling reading of further   bytes for the insn.   BASE_INSN is the first CGEN_BASE_INSN_SIZE bytes (host order).   FIELDS is a pointer to a cgen_fields struct in which the results are placed.   PC is the pc value of the insn.   The result is the length of the insn in bits or zero if not recognized.  */#ifdef __BFD_H_SEEN__typedef int (cgen_extract_fn)  (CGEN_CPU_DESC, const CGEN_INSN *insn_,   CGEN_EXTRACT_INFO *ex_info_, CGEN_INSN_INT base_insn_,   CGEN_FIELDS *fields_, bfd_vma pc_);#elsetypedef int (cgen_extract_fn) ();#endif/* Print handler.   CD is a cpu table descriptor.   INFO is a pointer to the disassembly info.   Eg: disassemble_info.  It's defined as `PTR' so this file can be included   without dis-asm.h.   INSN is a pointer to a struct describing the insn being printed.   FIELDS is a pointer to a cgen_fields struct.   PC is the pc value of the insn.   LEN is the length of the insn, in bits.  */#ifdef __BFD_H_SEEN__typedef void (cgen_print_fn)  (CGEN_CPU_DESC, void * info_, const CGEN_INSN *insn_,   CGEN_FIELDS *fields_, bfd_vma pc_, int len_);#elsetypedef void (cgen_print_fn) ();#endif/* Parse/insert/extract/print handlers.   Indices into the handler tables.   We could use pointers here instead, but 90% of them are generally identical   and that's a lot of redundant data.  Making these unsigned char indices   into tables of pointers saves a bit of space.   Using indices also keeps assembler code out of the disassembler and   vice versa.  */struct cgen_opcode_handler{  unsigned char parse, insert, extract, print;};/* Assembler interface.   The interface to the assembler is intended to be clean in the sense that   libopcodes.a is a standalone entity and could be used with any assembler.   Not that one would necessarily want to do that but rather that it helps   keep a clean interface.  The interface will obviously be slanted towards   GAS, but at least it's a start.   ??? Note that one possible user of the assembler besides GAS is GDB.   Parsing is controlled by the assembler which calls   CGEN_SYM (assemble_insn).  If it can parse and build the entire insn   it doesn't call back to the assembler.  If it needs/wants to call back   to the assembler, cgen_parse_operand_fn is called which can either   - return a number to be inserted in the insn   - return a "register" value to be inserted     (the register might not be a register per pe)   - queue the argument and return a marker saying the expression has been     queued (eg: a fix-up)   - return an error message indicating the expression wasn't recognizable   The result is an error message or NULL for success.   The parsed value is stored in the bfd_vma *.  *//* Values for indicating what the caller wants.  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -