inst.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 _UAPI_ASM_INST_H
  12. #define _UAPI_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. lx_op = 0x0a,
  72. bshfl_op = 0x20,
  73. dbshfl_op = 0x24,
  74. rdhwr_op = 0x3b
  75. };
  76. /*
  77. * rt field of bcond opcodes.
  78. */
  79. enum rt_op {
  80. bltz_op, bgez_op, bltzl_op, bgezl_op,
  81. spimi_op, unused_rt_op_0x05, unused_rt_op_0x06, unused_rt_op_0x07,
  82. tgei_op, tgeiu_op, tlti_op, tltiu_op,
  83. teqi_op, unused_0x0d_rt_op, tnei_op, unused_0x0f_rt_op,
  84. bltzal_op, bgezal_op, bltzall_op, bgezall_op,
  85. rt_op_0x14, rt_op_0x15, rt_op_0x16, rt_op_0x17,
  86. rt_op_0x18, rt_op_0x19, rt_op_0x1a, rt_op_0x1b,
  87. bposge32_op, rt_op_0x1d, rt_op_0x1e, rt_op_0x1f
  88. };
  89. /*
  90. * rs field of cop opcodes.
  91. */
  92. enum cop_op {
  93. mfc_op = 0x00, dmfc_op = 0x01,
  94. cfc_op = 0x02, mtc_op = 0x04,
  95. dmtc_op = 0x05, ctc_op = 0x06,
  96. bc_op = 0x08, cop_op = 0x10,
  97. copm_op = 0x18
  98. };
  99. /*
  100. * rt field of cop.bc_op opcodes
  101. */
  102. enum bcop_op {
  103. bcf_op, bct_op, bcfl_op, bctl_op
  104. };
  105. /*
  106. * func field of cop0 coi opcodes.
  107. */
  108. enum cop0_coi_func {
  109. tlbr_op = 0x01, tlbwi_op = 0x02,
  110. tlbwr_op = 0x06, tlbp_op = 0x08,
  111. rfe_op = 0x10, eret_op = 0x18
  112. };
  113. /*
  114. * func field of cop0 com opcodes.
  115. */
  116. enum cop0_com_func {
  117. tlbr1_op = 0x01, tlbw_op = 0x02,
  118. tlbp1_op = 0x08, dctr_op = 0x09,
  119. dctw_op = 0x0a
  120. };
  121. /*
  122. * fmt field of cop1 opcodes.
  123. */
  124. enum cop1_fmt {
  125. s_fmt, d_fmt, e_fmt, q_fmt,
  126. w_fmt, l_fmt
  127. };
  128. /*
  129. * func field of cop1 instructions using d, s or w format.
  130. */
  131. enum cop1_sdw_func {
  132. fadd_op = 0x00, fsub_op = 0x01,
  133. fmul_op = 0x02, fdiv_op = 0x03,
  134. fsqrt_op = 0x04, fabs_op = 0x05,
  135. fmov_op = 0x06, fneg_op = 0x07,
  136. froundl_op = 0x08, ftruncl_op = 0x09,
  137. fceill_op = 0x0a, ffloorl_op = 0x0b,
  138. fround_op = 0x0c, ftrunc_op = 0x0d,
  139. fceil_op = 0x0e, ffloor_op = 0x0f,
  140. fmovc_op = 0x11, fmovz_op = 0x12,
  141. fmovn_op = 0x13, frecip_op = 0x15,
  142. frsqrt_op = 0x16, fcvts_op = 0x20,
  143. fcvtd_op = 0x21, fcvte_op = 0x22,
  144. fcvtw_op = 0x24, fcvtl_op = 0x25,
  145. fcmp_op = 0x30
  146. };
  147. /*
  148. * func field of cop1x opcodes (MIPS IV).
  149. */
  150. enum cop1x_func {
  151. lwxc1_op = 0x00, ldxc1_op = 0x01,
  152. pfetch_op = 0x07, swxc1_op = 0x08,
  153. sdxc1_op = 0x09, madd_s_op = 0x20,
  154. madd_d_op = 0x21, madd_e_op = 0x22,
  155. msub_s_op = 0x28, msub_d_op = 0x29,
  156. msub_e_op = 0x2a, nmadd_s_op = 0x30,
  157. nmadd_d_op = 0x31, nmadd_e_op = 0x32,
  158. nmsub_s_op = 0x38, nmsub_d_op = 0x39,
  159. nmsub_e_op = 0x3a
  160. };
  161. /*
  162. * func field for mad opcodes (MIPS IV).
  163. */
  164. enum mad_func {
  165. madd_fp_op = 0x08, msub_fp_op = 0x0a,
  166. nmadd_fp_op = 0x0c, nmsub_fp_op = 0x0e
  167. };
  168. /*
  169. * func field for special3 lx opcodes (Cavium Octeon).
  170. */
  171. enum lx_func {
  172. lwx_op = 0x00,
  173. lhx_op = 0x04,
  174. lbux_op = 0x06,
  175. ldx_op = 0x08,
  176. lwux_op = 0x10,
  177. lhux_op = 0x14,
  178. lbx_op = 0x16,
  179. };
  180. /*
  181. * Damn ... bitfields depend from byteorder :-(
  182. */
  183. #ifdef __MIPSEB__
  184. #define BITFIELD_FIELD(field, more) \
  185. field; \
  186. more
  187. #elif defined(__MIPSEL__)
  188. #define BITFIELD_FIELD(field, more) \
  189. more \
  190. field;
  191. #else /* !defined (__MIPSEB__) && !defined (__MIPSEL__) */
  192. #error "MIPS but neither __MIPSEL__ nor __MIPSEB__?"
  193. #endif
  194. struct j_format {
  195. BITFIELD_FIELD(unsigned int opcode : 6, /* Jump format */
  196. BITFIELD_FIELD(unsigned int target : 26,
  197. ;))
  198. };
  199. struct i_format { /* signed immediate format */
  200. BITFIELD_FIELD(unsigned int opcode : 6,
  201. BITFIELD_FIELD(unsigned int rs : 5,
  202. BITFIELD_FIELD(unsigned int rt : 5,
  203. BITFIELD_FIELD(signed int simmediate : 16,
  204. ;))))
  205. };
  206. struct u_format { /* unsigned immediate format */
  207. BITFIELD_FIELD(unsigned int opcode : 6,
  208. BITFIELD_FIELD(unsigned int rs : 5,
  209. BITFIELD_FIELD(unsigned int rt : 5,
  210. BITFIELD_FIELD(unsigned int uimmediate : 16,
  211. ;))))
  212. };
  213. struct c_format { /* Cache (>= R6000) format */
  214. BITFIELD_FIELD(unsigned int opcode : 6,
  215. BITFIELD_FIELD(unsigned int rs : 5,
  216. BITFIELD_FIELD(unsigned int c_op : 3,
  217. BITFIELD_FIELD(unsigned int cache : 2,
  218. BITFIELD_FIELD(unsigned int simmediate : 16,
  219. ;)))))
  220. };
  221. struct r_format { /* Register format */
  222. BITFIELD_FIELD(unsigned int opcode : 6,
  223. BITFIELD_FIELD(unsigned int rs : 5,
  224. BITFIELD_FIELD(unsigned int rt : 5,
  225. BITFIELD_FIELD(unsigned int rd : 5,
  226. BITFIELD_FIELD(unsigned int re : 5,
  227. BITFIELD_FIELD(unsigned int func : 6,
  228. ;))))))
  229. };
  230. struct p_format { /* Performance counter format (R10000) */
  231. BITFIELD_FIELD(unsigned int opcode : 6,
  232. BITFIELD_FIELD(unsigned int rs : 5,
  233. BITFIELD_FIELD(unsigned int rt : 5,
  234. BITFIELD_FIELD(unsigned int rd : 5,
  235. BITFIELD_FIELD(unsigned int re : 5,
  236. BITFIELD_FIELD(unsigned int func : 6,
  237. ;))))))
  238. };
  239. struct f_format { /* FPU register format */
  240. BITFIELD_FIELD(unsigned int opcode : 6,
  241. BITFIELD_FIELD(unsigned int : 1,
  242. BITFIELD_FIELD(unsigned int fmt : 4,
  243. BITFIELD_FIELD(unsigned int rt : 5,
  244. BITFIELD_FIELD(unsigned int rd : 5,
  245. BITFIELD_FIELD(unsigned int re : 5,
  246. BITFIELD_FIELD(unsigned int func : 6,
  247. ;)))))))
  248. };
  249. struct ma_format { /* FPU multiply and add format (MIPS IV) */
  250. BITFIELD_FIELD(unsigned int opcode : 6,
  251. BITFIELD_FIELD(unsigned int fr : 5,
  252. BITFIELD_FIELD(unsigned int ft : 5,
  253. BITFIELD_FIELD(unsigned int fs : 5,
  254. BITFIELD_FIELD(unsigned int fd : 5,
  255. BITFIELD_FIELD(unsigned int func : 4,
  256. BITFIELD_FIELD(unsigned int fmt : 2,
  257. ;)))))))
  258. };
  259. struct b_format { /* BREAK and SYSCALL */
  260. BITFIELD_FIELD(unsigned int opcode : 6,
  261. BITFIELD_FIELD(unsigned int code : 20,
  262. BITFIELD_FIELD(unsigned int func : 6,
  263. ;)))
  264. };
  265. struct ps_format { /* MIPS-3D / paired single format */
  266. BITFIELD_FIELD(unsigned int opcode : 6,
  267. BITFIELD_FIELD(unsigned int rs : 5,
  268. BITFIELD_FIELD(unsigned int ft : 5,
  269. BITFIELD_FIELD(unsigned int fs : 5,
  270. BITFIELD_FIELD(unsigned int fd : 5,
  271. BITFIELD_FIELD(unsigned int func : 6,
  272. ;))))))
  273. };
  274. struct v_format { /* MDMX vector format */
  275. BITFIELD_FIELD(unsigned int opcode : 6,
  276. BITFIELD_FIELD(unsigned int sel : 4,
  277. BITFIELD_FIELD(unsigned int fmt : 1,
  278. BITFIELD_FIELD(unsigned int vt : 5,
  279. BITFIELD_FIELD(unsigned int vs : 5,
  280. BITFIELD_FIELD(unsigned int vd : 5,
  281. BITFIELD_FIELD(unsigned int func : 6,
  282. ;)))))))
  283. };
  284. union mips_instruction {
  285. unsigned int word;
  286. unsigned short halfword[2];
  287. unsigned char byte[4];
  288. struct j_format j_format;
  289. struct i_format i_format;
  290. struct u_format u_format;
  291. struct c_format c_format;
  292. struct r_format r_format;
  293. struct p_format p_format;
  294. struct f_format f_format;
  295. struct ma_format ma_format;
  296. struct b_format b_format;
  297. struct ps_format ps_format;
  298. struct v_format v_format;
  299. };
  300. #endif /* _UAPI_ASM_INST_H */