inst.h 9.1 KB

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