Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

ppcopc.h

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      ppcopc.cc
00004  *
00005  *      Copyright (C) 1999-2002 Sebastian Biallas (sb@web-productions.de)
00006  *      Copyright 1994 Free Software Foundation, Inc.
00007  *      Written by Ian Lance Taylor, Cygnus Support
00008  *
00009  *      This program is free software; you can redistribute it and/or modify
00010  *      it under the terms of the GNU General Public License version 2 as
00011  *      published by the Free Software Foundation.
00012  *
00013  *      This program is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *      GNU General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU General Public License
00019  *      along with this program; if not, write to the Free Software
00020  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021  */
00022 
00023 #ifndef __PPC_OPC_H__
00024 #define __PPC_OPC_H__
00025 
00026 #include "global.h"
00027 
00028 /* The opcode table is an array of struct powerpc_opcode.  */
00029 struct powerpc_opcode
00030 {
00031   /* The opcode name.  */
00032   const char *name;
00033 
00034   /* The opcode itself.  Those bits which will be filled in with
00035      operands are zeroes.  */
00036   uint32 opcode;
00037 
00038   /* The opcode mask.  This is used by the disassembler.  This is a
00039      mask containing ones indicating those bits which must match the
00040      opcode field, and zeroes indicating those bits which need not
00041      match (and are presumably filled in by operands).  */
00042   uint32 mask;
00043 
00044   /* One bit flags for the opcode.  These are used to indicate which
00045      specific processors support the instructions.  The defined values
00046      are listed below.  */
00047   uint32 flags;
00048 
00049   /* An array of operand codes.  Each code is an index into the
00050      operand table.  They appear in the order which the operands must
00051      appear in assembly code, and are terminated by a zero.  */
00052   byte operands[8];
00053 };
00054 
00055 /* The table itself is sorted by major opcode number, and is otherwise
00056    in the order in which the disassembler should consider
00057    instructions.  */
00058 extern const struct powerpc_opcode powerpc_opcodes[];
00059 extern const int powerpc_num_opcodes;
00060 
00061 /* Values defined for the flags field of a struct powerpc_opcode.  */
00062 
00063 /* Opcode is defined for the PowerPC architecture.  */
00064 #define PPC_OPCODE_PPC (01)
00065 
00066 /* Opcode is defined for the POWER (RS/6000) architecture.  */
00067 #define PPC_OPCODE_POWER (02)
00068 
00069 /* Opcode is defined for the POWER2 (Rios 2) architecture.  */
00070 #define PPC_OPCODE_POWER2 (04)
00071 
00072 /* Opcode is only defined on 32 bit architectures.  */
00073 #define PPC_OPCODE_32 (010)
00074 
00075 /* Opcode is only defined on 64 bit architectures.  */
00076 #define PPC_OPCODE_64 (020)
00077 
00078 /* Opcode is supported by the Motorola PowerPC 601 processor.  The 601
00079    is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
00080    but it also supports many additional POWER instructions.  */
00081 #define PPC_OPCODE_601 (040)
00082 
00083 /* A macro to extract the major opcode from an instruction.  */
00084 #define PPC_OP(i) (((i) >> 26) & 0x3f)
00085 
00086 /* The operands table is an array of struct powerpc_operand.  */
00087 
00088 struct powerpc_operand
00089 {
00090   /* The number of bits in the operand.  */
00091   byte bits;
00092 
00093   /* How far the operand is left shifted in the instruction.  */
00094   byte shift;
00095 
00096   /* Extraction function.  This is used by the disassembler.  To
00097      extract this operand type from an instruction, check this field.
00098 
00099      If it is NULL, compute
00100          op = ((i) >> o->shift) & ((1 << o->bits) - 1);
00101          if ((o->flags & PPC_OPERAND_SIGNED) != 0
00102              && (op & (1 << (o->bits - 1))) != 0)
00103            op -= 1 << o->bits;
00104      (i is the instruction, o is a pointer to this structure, and op
00105      is the result; this assumes twos complement arithmetic).
00106 
00107      If this field is not NULL, then simply call it with the
00108      instruction value.  It will return the value of the operand.  If
00109      the INVALID argument is not NULL, *INVALID will be set to
00110      non-zero if this operand type can not actually be extracted from
00111      this operand (i.e., the instruction does not match).  If the
00112      operand is valid, *INVALID will not be changed.  */
00113   uint32 (*extract)(uint32 instruction, bool *invalid);
00114 
00115   /* One bit syntax flags.  */
00116   uint32 flags;
00117 };
00118 
00119 /* Elements in the table are retrieved by indexing with values from
00120    the operands field of the powerpc_opcodes table.  */
00121 
00122 extern const struct powerpc_operand powerpc_operands[];
00123 
00124 /* Values defined for the flags field of a struct powerpc_operand.  */
00125 
00126 /* This operand takes signed values.  */
00127 #define PPC_OPERAND_SIGNED (01)
00128 
00129 /* This operand takes signed values, but also accepts a full positive
00130    range of values when running in 32 bit mode.  That is, if bits is
00131    16, it takes any value from -0x8000 to 0xffff.  In 64 bit mode,
00132    this flag is ignored.  */
00133 #define PPC_OPERAND_SIGNOPT (02)
00134 
00135 /* This operand does not actually exist in the assembler input.  This
00136    is used to support extended mnemonics such as mr, for which two
00137    operands fields are identical.  The assembler should call the
00138    insert function with any op value.  The disassembler should call
00139    the extract function, ignore the return value, and check the value
00140    placed in the valid argument.  */
00141 #define PPC_OPERAND_FAKE (04)
00142 
00143 /* The next operand should be wrapped in parentheses rather than
00144    separated from this one by a comma.  This is used for the load and
00145    store instructions which want their operands to look like
00146        reg,displacement(reg)
00147    */
00148 #define PPC_OPERAND_PARENS (010)
00149 
00150 /* This operand may use the symbolic names for the CR fields, which
00151    are
00152        lt  0    gt  1   eq  2   so  3   un  3
00153        cr0 0    cr1 1   cr2 2   cr3 3
00154        cr4 4    cr5 5   cr6 6   cr7 7
00155    These may be combined arithmetically, as in cr2*4+gt.  These are
00156    only supported on the PowerPC, not the POWER.  */
00157 #define PPC_OPERAND_CR (020)
00158 
00159 /* This operand names a register.  The disassembler uses this to print
00160    register names with a leading 'r'.  */
00161 #define PPC_OPERAND_GPR (040)
00162 
00163 /* This operand names a floating point register.  The disassembler
00164    prints these with a leading 'f'.  */
00165 #define PPC_OPERAND_FPR (0100)
00166 
00167 /* This operand is a relative branch displacement.  The disassembler
00168    prints these symbolically if possible.  */
00169 #define PPC_OPERAND_RELATIVE (0200)
00170 
00171 /* This operand is an absolute branch address.  The disassembler
00172    prints these symbolically if possible.  */
00173 #define PPC_OPERAND_ABSOLUTE (0400)
00174 
00175 /* This operand is optional, and is zero if omitted.  This is used for
00176    the optional BF and L fields in the comparison instructions.  The
00177    assembler must count the number of operands remaining on the line,
00178    and the number of operands remaining for the opcode, and decide
00179    whether this operand is present or not.  The disassembler should
00180    print this operand out only if it is not zero.  */
00181 #define PPC_OPERAND_OPTIONAL (01000)
00182 
00183 /* This flag is only used with PPC_OPERAND_OPTIONAL.  If this operand
00184    is omitted, then for the next operand use this operand value plus
00185    1, ignoring the next operand field for the opcode.  This wretched
00186    hack is needed because the Power rotate instructions can take
00187    either 4 or 5 operands.  The disassembler should print this operand
00188    out regardless of the PPC_OPERAND_OPTIONAL field.  */
00189 #define PPC_OPERAND_NEXT (02000)
00190 
00191 /* This operand should be regarded as a negative number for the
00192    purposes of overflow checking (i.e., the normal most negative
00193    number is disallowed and one more than the normal most positive
00194    number is allowed).  This flag will only be set for a signed
00195    operand.  */
00196 #define PPC_OPERAND_NEGATIVE (04000)
00197 
00198 #endif

Generated on Fri May 7 21:15:42 2004 by doxygen 1.3.5