Home | History | Annotate | Download | only in bedbug
      1 /* $Id$ */
      2 
      3 #ifndef _PPC_H
      4 #define _PPC_H
      5 
      6 /*======================================================================
      7  *
      8  *  OPERANDS
      9  *
     10  *======================================================================*/
     11 
     12 enum OP_FIELD {
     13   O_AA = 1, O_BD, O_BI, O_BO, O_crbD, O_crbA, O_crbB, O_CRM, O_d, O_frC, O_frD,
     14   O_frS, O_IMM, O_LI, O_LK, O_MB, O_ME, O_NB, O_OE, O_rA, O_rB, O_Rc, O_rD,
     15   O_rS, O_SH, O_SIMM, O_SR, O_TO, O_UIMM, O_crfD, O_crfS, O_L, O_spr, O_tbr,
     16   O_cr2 };
     17 
     18 struct operand {
     19   enum OP_FIELD	field;		/* The operand identifier from the
     20 				   enum above */
     21 
     22   char *	name;		/* Symbolic name of this operand */
     23 
     24   unsigned int	bits;		/* The number of bits used by this
     25 				   operand */
     26 
     27   unsigned int	shift;		/* How far to the right the operand
     28 				   should be shifted so that it is
     29 				   aligned at the beginning of the
     30 				   word */
     31 
     32   unsigned int	hint;		/* A bitwise-inclusive-OR of the
     33 				   values shown below.  These are used
     34 				   tell the disassembler how to print
     35 				   this operand */
     36 };
     37 
     38 /* Values for operand hint */
     39 #define OH_SILENT	0x01	/* dont print this operand */
     40 #define OH_ADDR		0x02	/* this operand is an address */
     41 #define OH_REG		0x04	/* this operand is a register */
     42 #define OH_SPR		0x08	/* this operand is an SPR */
     43 #define OH_TBR		0x10	/* this operand is a TBR */
     44 #define OH_OFFSET	0x20	/* this operand is an offset */
     45 #define OH_LITERAL      0x40    /* a literal string */
     46 
     47 
     48 /*======================================================================
     50  *
     51  *  OPCODES
     52  *
     53  *======================================================================*/
     54 
     55 /* From the MPCxxx instruction set documentation, all instructions are
     56  * 32 bits long and word aligned.  Bits 0-5 always specify the primary
     57  * opcode.  Many instructions also have an extended opcode.
     58  */
     59 
     60 #define GET_OPCD(i) (((unsigned long)(i) >> 26) & 0x3f)
     61 #define MAKE_OPCODE(i) ((((unsigned long)(i)) & 0x3f) << 26)
     62 
     63 /* The MPC860 User's Manual, Appendix D.4 contains the definitions of the
     64  * instruction forms
     65  */
     66 
     67 
     68 /*-------------------------------------------------
     69  *              I-Form Instructions:
     70  * bX
     71  *-------------------------------------------------
     72  * OPCD |           LI                       |AA|LK
     73  *-------------------------------------------------*/
     74 
     75 #define I_OPCODE(i,aa,lk) (MAKE_OPCODE(i) | (((aa) & 0x1) << 1) | ((lk) & 0x1))
     76 #define I_MASK I_OPCODE(0x3f,0x1,0x1)
     77 
     78 
     79 /*-------------------------------------------------
     80  *              B-Form Instructions:
     81  * bcX
     82  *-------------------------------------------------
     83  * OPCD |    BO   |  BI  |   BD              |AA|LK
     84  *-------------------------------------------------*/
     85 
     86 #define B_OPCODE(i,aa,lk) (MAKE_OPCODE(i) | (((aa) & 0x1) << 1) | ((lk) & 0x1))
     87 #define B_MASK B_OPCODE(0x3f,0x1,0x1)
     88 
     89 
     90 /*-------------------------------------------------
     91  *             SC-Form Instructions:
     92  * sc
     93  *-------------------------------------------------
     94  * OPCD | 00000 | 00000 | 00000000000000       |1|0
     95  *-------------------------------------------------*/
     96 
     97 #define SC_OPCODE(i) (MAKE_OPCODE(i) | 0x2)
     98 #define SC_MASK SC_OPCODE(0x3f)
     99 
    100 
    101 /*-------------------------------------------------
    102  *             D-Form Instructions:
    103  * addi addic addic. addis andi. andis. cmpi cmpli
    104  * lbz lbzu lha lhau lhz lhzu lmw lwz lwzu mulli
    105  * ori oris stb stbu sth sthu stmw stw stwu subfic
    106  * twi xori xoris
    107  *-------------------------------------------------
    108  * OPCD |   D    |   A   |            d
    109  * OPCD |   D    |   A   |           SIMM
    110  * OPCD |   S    |   A   |            d
    111  * OPCD |   S    |   A   |           UIMM
    112  * OPCD |crfD|0|L|   A   |           SIMM
    113  * OPCD |crfD|0|L|   A   |           UIMM
    114  * OPCD |   TO   |   A   |           SIMM
    115  *-------------------------------------------------*/
    116 
    117 #define D_OPCODE(i) MAKE_OPCODE(i)
    118 #define D_MASK MAKE_OPCODE(0x3f)
    119 
    120 
    121 /*-------------------------------------------------
    122  *            DS-Form Instructions:
    123  * (none supported by MPC860)
    124  *-------------------------------------------------
    125  * OPCD |   D    |   A   |          ds          |XO
    126  * OPCD |   S    |   A   |          ds          |XO
    127  *-------------------------------------------------*/
    128 
    129 #define DS_OPCODE(i,xo) (MAKE_OPCODE(i) | ((xo) & 0x3))
    130 #define DS_MASK DS_OPCODE(0x3f,0x1)
    131 
    132 
    133 /*---------------------------------------------------
    134  *            X-Form Instructions:
    135  * andX andcX cmp cmpl cntlzwX dcbf dcbi dcbst dcbt
    136  * dcbtst dcbz eciwx ecowx eieio eqvX extsbX extshX
    137  * icbi lbzux lbxz lhaux lhax lhbrx lhzux lhxz lswi
    138  * lswx lwarx lwbrx lwzux lwxz mcrfs mcrxr mfcr
    139  * mfmsr mfsr mfsrin mtmsr mtsr mtsrin nandX norX
    140  * orX orcX slwX srawX srawiX srwX stbux stbx
    141  * sthbrx sthuxsthx stswi stswx stwbrx stwcx. stwux
    142  * stwx sync tlbie tlbld tlbli tlbsync tw xorX
    143  *---------------------------------------------------
    144  * OPCD |   D    |    A   |    B   |      XO      |0
    145  * OPCD |   D    |    A   |   NB   |      XO      |0
    146  * OPCD |   D    |  00000 |    B   |      XO      |0
    147  * OPCD |   D    |  00000 |  00000 |      XO      |0
    148  * OPCD |   D    |0|  SR  |  00000 |      XO      |0
    149  * OPCD |   S    |    A   |    B   |      XO      |Rc
    150  * OPCD |   S    |    A   |    B   |      XO      |1
    151  * OPCD |   S    |    A   |    B   |      XO      |0
    152  * OPCD |   S    |    A   |   NB   |      XO      |0
    153  * OPCD |   S    |    A   |  00000 |      XO      |Rc
    154  * OPCD |   S    |  00000 |    B   |      XO      |0
    155  * OPCD |   S    |  00000 |  00000 |      XO      |0
    156  * OPCD |   S    |0|  SR  |  00000 |      XO      |0
    157  * OPCD |   S    |    A   |   SH   |      XO      |Rc
    158  * OPCD |crfD|0|L|    A   |   SH   |      XO      |0
    159  * OPCD |crfD |00|    A   |    B   |      XO      |0
    160  * OPCD |crfD |00|crfS |00|  00000 |      XO      |0
    161  * OPCD |crfD |00|  00000 |  00000 |      XO      |0
    162  * OPCD |crfD |00|  00000 | IMM  |0|      XO      |Rc
    163  * OPCD |   TO   |    A   |    B   |      XO      |0
    164  * OPCD |   D    |  00000 |    B   |      XO      |Rc
    165  * OPCD |   D    |  00000 |  00000 |      XO      |Rc
    166  * OPCD |  crbD  |  00000 |  00000 |      XO      |Rc
    167  * OPCD |  00000 |    A   |    B   |      XO      |0
    168  * OPCD |  00000 |  00000 |    B   |      XO      |0
    169  * OPCD |  00000 |  00000 |  00000 |      XO      |0
    170  *---------------------------------------------------*/
    171 
    172 #define X_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x3ff) << 1) | \
    173 			   ((rc) & 0x1))
    174 #define X_MASK X_OPCODE(0x3f,0x3ff,0x1)
    175 
    176 
    177 /*---------------------------------------------------
    178  *            XL-Form Instructions:
    179  * bcctrX bclrX crand crandc creqv crnand crnor cror
    180  * croc crxorisync mcrf rfi
    181  *---------------------------------------------------
    182  * OPCD |   BO   |  BI    |  00000 |      XO      |LK
    183  * OPCD |  crbD  | crbA   |  crbB  |      XO      |0
    184  * OPCD |crfD |00|crfS |00|  00000 |      XO      |0
    185  * OPCD |  00000 |  00000 |  00000 |      XO      |0
    186  *---------------------------------------------------*/
    187 
    188 #define XL_OPCODE(i,xo,lk) (MAKE_OPCODE(i) | (((xo) & 0x3ff) << 1) | \
    189 			    ((lk) & 0x1))
    190 #define XL_MASK XL_OPCODE(0x3f,0x3ff,0x1)
    191 
    192 
    193 /*---------------------------------------------------
    194  *            XFX-Form Instructions:
    195  * mfspr mftb mtcrf mtspr
    196  *---------------------------------------------------
    197  * OPCD |   D    |      spr        |      XO       |0
    198  * OPCD |   D    |0|    CRM      |0|      XO       |0
    199  * OPCD |   S    |      spr        |      XO       |0
    200  * OPCD |   D    |      tbr        |      XO       |0
    201  *---------------------------------------------------*/
    202 
    203 #define XFX_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x3ff) << 1) | \
    204 			     ((rc) & 0x1))
    205 #define XFX_MASK XFX_OPCODE(0x3f,0x3ff,0x1)
    206 
    207 
    208 /*---------------------------------------------------
    209  *            XFL-Form Instructions:
    210  * (none supported by MPC860)
    211  *---------------------------------------------------
    212  * OPCD |0|      FM     |0|   B    |      XO       |0
    213  *---------------------------------------------------*/
    214 
    215 #define XFL_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x3ff) << 1) | \
    216 			     ((rc) & 0x1))
    217 #define XFL_MASK XFL_OPCODE(0x3f,0x3ff,0x1)
    218 
    219 
    220 /*---------------------------------------------------
    221  *            XS-Form Instructions:
    222  * (none supported by MPC860)
    223  *---------------------------------------------------
    224  * OPCD |    S   |   A    |   sh   |      XO   |sh|LK
    225  *---------------------------------------------------*/
    226 
    227 #define XS_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x1ff) << 2) | \
    228 			     ((rc) & 0x1))
    229 #define XS_MASK XS_OPCODE(0x3f,0x1ff,0x1)
    230 
    231 
    232 /*---------------------------------------------------
    233  *            XO-Form Instructions:
    234  * addX addcXaddeX addmeX addzeX divwX divwuX mulhwX
    235  * mulhwuX mullwX negX subfX subfcX subfeX subfmeX
    236  * subfzeX
    237  *---------------------------------------------------
    238  * OPCD |    D   |   A    |    B   |OE|     XO    |Rc
    239  * OPCD |    D   |   A    |    B   |0 |     XO    |Rc
    240  * OPCD |    D   |   A    |  00000 |OE|     XO    |Rc
    241  *---------------------------------------------------*/
    242 
    243 #define XO_OPCODE(i,xo,oe,rc) (MAKE_OPCODE(i) | (((oe) & 0x1) << 10) | \
    244 			       (((xo) & 0x1ff) << 1) | ((rc) & 0x1))
    245 #define XO_MASK XO_OPCODE(0x3f,0x1ff,0x1,0x1)
    246 
    247 
    248 /*---------------------------------------------------
    249  *            A-Form Instructions:
    250  * (none supported by MPC860)
    251  *---------------------------------------------------
    252  * OPCD |    D   |   A    |    B   |00000|  XO    |Rc
    253  * OPCD |    D   |   A    |    B   |  C  |  XO    |Rc
    254  * OPCD |    D   |   A    |  00000 |  C  |  XO    |Rc
    255  * OPCD |    D   |  00000 |    B   |00000|  XO    |Rc
    256  *---------------------------------------------------*/
    257 
    258 #define A_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x1f) << 1) | \
    259 			   ((rc) & 0x1))
    260 #define A_MASK A_OPCODE(0x3f,0x1f,0x1)
    261 
    262 
    263 /*---------------------------------------------------
    264  *            M-Form Instructions:
    265  * rlwimiX rlwinmX rlwnmX
    266  *---------------------------------------------------
    267  * OPCD |    S   |   A    |    SH   |  MB |  ME   |Rc
    268  * OPCD |    S   |   A    |     B   |  MB |  ME   |Rc
    269  *---------------------------------------------------*/
    270 
    271 #define M_OPCODE(i,rc) (MAKE_OPCODE(i) | ((rc) & 0x1))
    272 #define M_MASK M_OPCODE(0x3f,0x1)
    273 
    274 
    275 /*---------------------------------------------------
    276  *            MD-Form Instructions:
    277  * (none supported by MPC860)
    278  *---------------------------------------------------
    279  * OPCD |    S   |   A    |    sh   |  mb | XO |sh|Rc
    280  * OPCD |    S   |   A    |    sh   |  me | XO |sh|Rc
    281  *---------------------------------------------------*/
    282 
    283 #define MD_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0x7) << 2) | \
    284 			   ((rc) & 0x1))
    285 #define MD_MASK MD_OPCODE(0x3f,0x7,0x1)
    286 
    287 
    288 /*---------------------------------------------------
    289  *            MDS-Form Instructions:
    290  * (none supported by MPC860)
    291  *---------------------------------------------------
    292  * OPCD |    S   |   A    |    B    |  mb | XO    |Rc
    293  * OPCD |    S   |   A    |    B    |  me | XO    |Rc
    294  *---------------------------------------------------*/
    295 
    296 #define MDS_OPCODE(i,xo,rc) (MAKE_OPCODE(i) | (((xo) & 0xf) << 1) | \
    297 			   ((rc) & 0x1))
    298 #define MDS_MASK MDS_OPCODE(0x3f,0xf,0x1)
    299 
    300 #define INSTRUCTION( memaddr ) ntohl(*(unsigned long *)(memaddr))
    301 
    302 #define MAX_OPERANDS  8
    303 
    304 struct ppc_ctx;
    305 
    306 struct opcode {
    307   unsigned long	opcode;		/* The complete opcode as produced by
    308 				   one of the XXX_OPCODE macros above */
    309 
    310   unsigned long	mask;		/* The mask to use on an instruction
    311 				   before comparing with the opcode
    312 				   field to see if it matches */
    313 
    314   enum OP_FIELD	fields[MAX_OPERANDS];
    315 				/* An array defining the operands for
    316 				   this opcode.  The values of the
    317 				   array are the operand identifiers */
    318 
    319   int (*hfunc)(struct ppc_ctx *);
    320 				/* Address of a function to handle the given
    321 				   mnemonic */
    322 
    323   char *	name;		/* The symbolic name of this opcode */
    324 
    325   unsigned int	hint;		/* A bitwise-inclusive-OR of the
    326 				   values shown below.  These are used
    327 				   tell the disassembler how to print
    328 				   some operands for this opcode */
    329 };
    330 
    331 /* values for opcode hints */
    332 #define H_RELATIVE	0x1	/* The address operand is relative */
    333 #define H_IMM_HIGH	0x2	/* [U|S]IMM field shifted high */
    334 #define H_RA0_IS_0	0x4	/* If rA = 0 then treat as literal 0 */
    335 
    336 struct ppc_ctx {
    337   struct opcode *	op;
    338   unsigned long		instr;
    339   unsigned int		flags;
    340   int			datalen;
    341   char			data[ 256 ];
    342   char			radix_fmt[ 8 ];
    343   unsigned char *	virtual;
    344 };
    345 
    346 
    347 /*======================================================================
    348  *
    349  *  FUNCTIONS
    350  *
    351  *======================================================================*/
    352 
    353 /* Values for flags as passed to various ppc routines */
    354 #define F_RADOCTAL	0x1	/* output radix = unsigned octal */
    355 #define F_RADUDECIMAL	0x2	/* output radix = unsigned decimal */
    356 #define F_RADSDECIMAL	0x4	/* output radix = signed decimal */
    357 #define F_RADHEX	0x8	/* output radix = unsigned hex */
    358 #define F_SIMPLE	0x10	/* use simplified mnemonics */
    359 #define F_SYMBOL	0x20	/* use symbol lookups for addresses */
    360 #define F_INSTR		0x40	/* output the raw instruction */
    361 #define F_LOCALMEM	0x80	/* retrieve opcodes from local memory
    362 				   rather than from the HMI */
    363 #define F_LINENO	0x100	/* show line number info if available */
    364 #define F_VALIDONLY	0x200	/* cache: valid entries only */
    365 
    366 /* Values for assembler error codes */
    367 #define E_ASM_BAD_OPCODE	1
    368 #define E_ASM_NUM_OPERANDS	2
    369 #define E_ASM_BAD_REGISTER	3
    370 #define E_ASM_BAD_SPR		4
    371 #define E_ASM_BAD_TBR		5
    372 
    373 extern int disppc __P((unsigned char *,unsigned char *,int,
    374 		       int (*)(const char *), unsigned long));
    375 extern int print_source_line __P((char *,char *,int,
    376 				  int (*pfunc)(const char *)));
    377 extern int find_next_address __P((unsigned char *,int,struct pt_regs *));
    378 extern int handle_bc __P((struct ppc_ctx *));
    379 extern unsigned long asmppc __P((unsigned long,char*,int*));
    380 extern char *asm_error_str __P((int));
    381 
    382 /*======================================================================
    383  *
    384  *  GLOBAL VARIABLES
    385  *
    386  *======================================================================*/
    387 
    388 extern struct operand operands[];
    389 extern const unsigned int n_operands;
    390 extern struct opcode opcodes[];
    391 extern const unsigned int n_opcodes;
    392 
    393 #endif /* _PPC_H */
    394 
    395 
    396 /*
    397  * Copyright (c) 2000 William L. Pitts and W. Gerald Hicks
    398  * All rights reserved.
    399  *
    400  * Redistribution and use in source and binary forms are freely
    401  * permitted provided that the above copyright notice and this
    402  * paragraph and the following disclaimer are duplicated in all
    403  * such forms.
    404  *
    405  * This software is provided "AS IS" and without any express or
    406  * implied warranties, including, without limitation, the implied
    407  * warranties of merchantability and fitness for a particular
    408  * purpose.
    409  */
    410