ppc.h 14 KB

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