inst.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Format of an instruction in memory.
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1996, 2000 by Ralf Baechle
  9. * Copyright (C) 2006 by Thiemo Seufer
  10. */
  11. #ifndef _ASM_INST_H
  12. #define _ASM_INST_H
  13. /*
  14. * Major opcodes; before MIPS IV cop1x was called cop3.
  15. */
  16. enum major_op {
  17. spec_op, bcond_op, j_op, jal_op,
  18. beq_op, bne_op, blez_op, bgtz_op,
  19. addi_op, addiu_op, slti_op, sltiu_op,
  20. andi_op, ori_op, xori_op, lui_op,
  21. cop0_op, cop1_op, cop2_op, cop1x_op,
  22. beql_op, bnel_op, blezl_op, bgtzl_op,
  23. daddi_op, daddiu_op, ldl_op, ldr_op,
  24. spec2_op, jalx_op, mdmx_op, spec3_op,
  25. lb_op, lh_op, lwl_op, lw_op,
  26. lbu_op, lhu_op, lwr_op, lwu_op,
  27. sb_op, sh_op, swl_op, sw_op,
  28. sdl_op, sdr_op, swr_op, cache_op,
  29. ll_op, lwc1_op, lwc2_op, pref_op,
  30. lld_op, ldc1_op, ldc2_op, ld_op,
  31. sc_op, swc1_op, swc2_op, major_3b_op,
  32. scd_op, sdc1_op, sdc2_op, sd_op
  33. };
  34. /*
  35. * func field of spec opcode.
  36. */
  37. enum spec_op {
  38. sll_op, movc_op, srl_op, sra_op,
  39. sllv_op, pmon_op, srlv_op, srav_op,
  40. jr_op, jalr_op, movz_op, movn_op,
  41. syscall_op, break_op, spim_op, sync_op,
  42. mfhi_op, mthi_op, mflo_op, mtlo_op,
  43. dsllv_op, spec2_unused_op, dsrlv_op, dsrav_op,
  44. mult_op, multu_op, div_op, divu_op,
  45. dmult_op, dmultu_op, ddiv_op, ddivu_op,
  46. add_op, addu_op, sub_op, subu_op,
  47. and_op, or_op, xor_op, nor_op,
  48. spec3_unused_op, spec4_unused_op, slt_op, sltu_op,
  49. dadd_op, daddu_op, dsub_op, dsubu_op,
  50. tge_op, tgeu_op, tlt_op, tltu_op,
  51. teq_op, spec5_unused_op, tne_op, spec6_unused_op,
  52. dsll_op, spec7_unused_op, dsrl_op, dsra_op,
  53. dsll32_op, spec8_unused_op, dsrl32_op, dsra32_op
  54. };
  55. /*
  56. * func field of spec2 opcode.
  57. */
  58. enum spec2_op {
  59. madd_op, maddu_op, mul_op, spec2_3_unused_op,
  60. msub_op, msubu_op, /* more unused ops */
  61. clz_op = 0x20, clo_op,
  62. dclz_op = 0x24, dclo_op,
  63. sdbpp_op = 0x3f
  64. };
  65. /*
  66. * func field of spec3 opcode.
  67. */
  68. enum spec3_op {
  69. ext_op, dextm_op, dextu_op, dext_op,
  70. ins_op, dinsm_op, dinsu_op, dins_op,
  71. bshfl_op = 0x20,
  72. dbshfl_op = 0x24,
  73. rdhwr_op = 0x3b
  74. };
  75. /*
  76. * rt field of bcond opcodes.
  77. */
  78. enum rt_op {
  79. bltz_op, bgez_op, bltzl_op, bgezl_op,
  80. spimi_op, unused_rt_op_0x05, unused_rt_op_0x06, unused_rt_op_0x07,
  81. tgei_op, tgeiu_op, tlti_op, tltiu_op,
  82. teqi_op, unused_0x0d_rt_op, tnei_op, unused_0x0f_rt_op,
  83. bltzal_op, bgezal_op, bltzall_op, bgezall_op,
  84. rt_op_0x14, rt_op_0x15, rt_op_0x16, rt_op_0x17,
  85. rt_op_0x18, rt_op_0x19, rt_op_0x1a, rt_op_0x1b,
  86. bposge32_op, rt_op_0x1d, rt_op_0x1e, rt_op_0x1f
  87. };
  88. /*
  89. * rs field of cop opcodes.
  90. */
  91. enum cop_op {
  92. mfc_op = 0x00, dmfc_op = 0x01,
  93. cfc_op = 0x02, mtc_op = 0x04,
  94. dmtc_op = 0x05, ctc_op = 0x06,
  95. bc_op = 0x08, cop_op = 0x10,
  96. copm_op = 0x18
  97. };
  98. /*
  99. * rt field of cop.bc_op opcodes
  100. */
  101. enum bcop_op {
  102. bcf_op, bct_op, bcfl_op, bctl_op
  103. };
  104. /*
  105. * func field of cop0 coi opcodes.
  106. */
  107. enum cop0_coi_func {
  108. tlbr_op = 0x01, tlbwi_op = 0x02,
  109. tlbwr_op = 0x06, tlbp_op = 0x08,
  110. rfe_op = 0x10, eret_op = 0x18
  111. };
  112. /*
  113. * func field of cop0 com opcodes.
  114. */
  115. enum cop0_com_func {
  116. tlbr1_op = 0x01, tlbw_op = 0x02,
  117. tlbp1_op = 0x08, dctr_op = 0x09,
  118. dctw_op = 0x0a
  119. };
  120. /*
  121. * fmt field of cop1 opcodes.
  122. */
  123. enum cop1_fmt {
  124. s_fmt, d_fmt, e_fmt, q_fmt,
  125. w_fmt, l_fmt
  126. };
  127. /*
  128. * func field of cop1 instructions using d, s or w format.
  129. */
  130. enum cop1_sdw_func {
  131. fadd_op = 0x00, fsub_op = 0x01,
  132. fmul_op = 0x02, fdiv_op = 0x03,
  133. fsqrt_op = 0x04, fabs_op = 0x05,
  134. fmov_op = 0x06, fneg_op = 0x07,
  135. froundl_op = 0x08, ftruncl_op = 0x09,
  136. fceill_op = 0x0a, ffloorl_op = 0x0b,
  137. fround_op = 0x0c, ftrunc_op = 0x0d,
  138. fceil_op = 0x0e, ffloor_op = 0x0f,
  139. fmovc_op = 0x11, fmovz_op = 0x12,
  140. fmovn_op = 0x13, frecip_op = 0x15,
  141. frsqrt_op = 0x16, fcvts_op = 0x20,
  142. fcvtd_op = 0x21, fcvte_op = 0x22,
  143. fcvtw_op = 0x24, fcvtl_op = 0x25,
  144. fcmp_op = 0x30
  145. };
  146. /*
  147. * func field of cop1x opcodes (MIPS IV).
  148. */
  149. enum cop1x_func {
  150. lwxc1_op = 0x00, ldxc1_op = 0x01,
  151. pfetch_op = 0x07, swxc1_op = 0x08,
  152. sdxc1_op = 0x09, madd_s_op = 0x20,
  153. madd_d_op = 0x21, madd_e_op = 0x22,
  154. msub_s_op = 0x28, msub_d_op = 0x29,
  155. msub_e_op = 0x2a, nmadd_s_op = 0x30,
  156. nmadd_d_op = 0x31, nmadd_e_op = 0x32,
  157. nmsub_s_op = 0x38, nmsub_d_op = 0x39,
  158. nmsub_e_op = 0x3a
  159. };
  160. /*
  161. * func field for mad opcodes (MIPS IV).
  162. */
  163. enum mad_func {
  164. madd_fp_op = 0x08, msub_fp_op = 0x0a,
  165. nmadd_fp_op = 0x0c, nmsub_fp_op = 0x0e
  166. };
  167. /*
  168. * Damn ... bitfields depend from byteorder :-(
  169. */
  170. #ifdef __MIPSEB__
  171. struct j_format { /* Jump format */
  172. unsigned int opcode : 6;
  173. unsigned int target : 26;
  174. };
  175. struct i_format { /* Immediate format (addi, lw, ...) */
  176. unsigned int opcode : 6;
  177. unsigned int rs : 5;
  178. unsigned int rt : 5;
  179. signed int simmediate : 16;
  180. };
  181. struct u_format { /* Unsigned immediate format (ori, xori, ...) */
  182. unsigned int opcode : 6;
  183. unsigned int rs : 5;
  184. unsigned int rt : 5;
  185. unsigned int uimmediate : 16;
  186. };
  187. struct c_format { /* Cache (>= R6000) format */
  188. unsigned int opcode : 6;
  189. unsigned int rs : 5;
  190. unsigned int c_op : 3;
  191. unsigned int cache : 2;
  192. unsigned int simmediate : 16;
  193. };
  194. struct r_format { /* Register format */
  195. unsigned int opcode : 6;
  196. unsigned int rs : 5;
  197. unsigned int rt : 5;
  198. unsigned int rd : 5;
  199. unsigned int re : 5;
  200. unsigned int func : 6;
  201. };
  202. struct p_format { /* Performance counter format (R10000) */
  203. unsigned int opcode : 6;
  204. unsigned int rs : 5;
  205. unsigned int rt : 5;
  206. unsigned int rd : 5;
  207. unsigned int re : 5;
  208. unsigned int func : 6;
  209. };
  210. struct f_format { /* FPU register format */
  211. unsigned int opcode : 6;
  212. unsigned int : 1;
  213. unsigned int fmt : 4;
  214. unsigned int rt : 5;
  215. unsigned int rd : 5;
  216. unsigned int re : 5;
  217. unsigned int func : 6;
  218. };
  219. struct ma_format { /* FPU multipy and add format (MIPS IV) */
  220. unsigned int opcode : 6;
  221. unsigned int fr : 5;
  222. unsigned int ft : 5;
  223. unsigned int fs : 5;
  224. unsigned int fd : 5;
  225. unsigned int func : 4;
  226. unsigned int fmt : 2;
  227. };
  228. #elif defined(__MIPSEL__)
  229. struct j_format { /* Jump format */
  230. unsigned int target : 26;
  231. unsigned int opcode : 6;
  232. };
  233. struct i_format { /* Immediate format */
  234. signed int simmediate : 16;
  235. unsigned int rt : 5;
  236. unsigned int rs : 5;
  237. unsigned int opcode : 6;
  238. };
  239. struct u_format { /* Unsigned immediate format */
  240. unsigned int uimmediate : 16;
  241. unsigned int rt : 5;
  242. unsigned int rs : 5;
  243. unsigned int opcode : 6;
  244. };
  245. struct c_format { /* Cache (>= R6000) format */
  246. unsigned int simmediate : 16;
  247. unsigned int cache : 2;
  248. unsigned int c_op : 3;
  249. unsigned int rs : 5;
  250. unsigned int opcode : 6;
  251. };
  252. struct r_format { /* Register format */
  253. unsigned int func : 6;
  254. unsigned int re : 5;
  255. unsigned int rd : 5;
  256. unsigned int rt : 5;
  257. unsigned int rs : 5;
  258. unsigned int opcode : 6;
  259. };
  260. struct p_format { /* Performance counter format (R10000) */
  261. unsigned int func : 6;
  262. unsigned int re : 5;
  263. unsigned int rd : 5;
  264. unsigned int rt : 5;
  265. unsigned int rs : 5;
  266. unsigned int opcode : 6;
  267. };
  268. struct f_format { /* FPU register format */
  269. unsigned int func : 6;
  270. unsigned int re : 5;
  271. unsigned int rd : 5;
  272. unsigned int rt : 5;
  273. unsigned int fmt : 4;
  274. unsigned int : 1;
  275. unsigned int opcode : 6;
  276. };
  277. struct ma_format { /* FPU multipy and add format (MIPS IV) */
  278. unsigned int fmt : 2;
  279. unsigned int func : 4;
  280. unsigned int fd : 5;
  281. unsigned int fs : 5;
  282. unsigned int ft : 5;
  283. unsigned int fr : 5;
  284. unsigned int opcode : 6;
  285. };
  286. #else /* !defined (__MIPSEB__) && !defined (__MIPSEL__) */
  287. #error "MIPS but neither __MIPSEL__ nor __MIPSEB__?"
  288. #endif
  289. union mips_instruction {
  290. unsigned int word;
  291. unsigned short halfword[2];
  292. unsigned char byte[4];
  293. struct j_format j_format;
  294. struct i_format i_format;
  295. struct u_format u_format;
  296. struct c_format c_format;
  297. struct r_format r_format;
  298. struct f_format f_format;
  299. struct ma_format ma_format;
  300. };
  301. /* HACHACHAHCAHC ... */
  302. /* In case some other massaging is needed, keep MIPSInst as wrapper */
  303. #define MIPSInst(x) x
  304. #define I_OPCODE_SFT 26
  305. #define MIPSInst_OPCODE(x) (MIPSInst(x) >> I_OPCODE_SFT)
  306. #define I_JTARGET_SFT 0
  307. #define MIPSInst_JTARGET(x) (MIPSInst(x) & 0x03ffffff)
  308. #define I_RS_SFT 21
  309. #define MIPSInst_RS(x) ((MIPSInst(x) & 0x03e00000) >> I_RS_SFT)
  310. #define I_RT_SFT 16
  311. #define MIPSInst_RT(x) ((MIPSInst(x) & 0x001f0000) >> I_RT_SFT)
  312. #define I_IMM_SFT 0
  313. #define MIPSInst_SIMM(x) ((int)((short)(MIPSInst(x) & 0xffff)))
  314. #define MIPSInst_UIMM(x) (MIPSInst(x) & 0xffff)
  315. #define I_CACHEOP_SFT 18
  316. #define MIPSInst_CACHEOP(x) ((MIPSInst(x) & 0x001c0000) >> I_CACHEOP_SFT)
  317. #define I_CACHESEL_SFT 16
  318. #define MIPSInst_CACHESEL(x) ((MIPSInst(x) & 0x00030000) >> I_CACHESEL_SFT)
  319. #define I_RD_SFT 11
  320. #define MIPSInst_RD(x) ((MIPSInst(x) & 0x0000f800) >> I_RD_SFT)
  321. #define I_RE_SFT 6
  322. #define MIPSInst_RE(x) ((MIPSInst(x) & 0x000007c0) >> I_RE_SFT)
  323. #define I_FUNC_SFT 0
  324. #define MIPSInst_FUNC(x) (MIPSInst(x) & 0x0000003f)
  325. #define I_FFMT_SFT 21
  326. #define MIPSInst_FFMT(x) ((MIPSInst(x) & 0x01e00000) >> I_FFMT_SFT)
  327. #define I_FT_SFT 16
  328. #define MIPSInst_FT(x) ((MIPSInst(x) & 0x001f0000) >> I_FT_SFT)
  329. #define I_FS_SFT 11
  330. #define MIPSInst_FS(x) ((MIPSInst(x) & 0x0000f800) >> I_FS_SFT)
  331. #define I_FD_SFT 6
  332. #define MIPSInst_FD(x) ((MIPSInst(x) & 0x000007c0) >> I_FD_SFT)
  333. #define I_FR_SFT 21
  334. #define MIPSInst_FR(x) ((MIPSInst(x) & 0x03e00000) >> I_FR_SFT)
  335. #define I_FMA_FUNC_SFT 2
  336. #define MIPSInst_FMA_FUNC(x) ((MIPSInst(x) & 0x0000003c) >> I_FMA_FUNC_SFT)
  337. #define I_FMA_FFMT_SFT 0
  338. #define MIPSInst_FMA_FFMT(x) (MIPSInst(x) & 0x00000003)
  339. typedef unsigned int mips_instruction;
  340. #endif /* _ASM_INST_H */