instr.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* $OpenBSD: instr.h,v 1.4 2003/07/14 00:45:20 jason Exp $ */
  2. /* $NetBSD: instr.h,v 1.3 1997/03/14 23:54:07 christos Exp $ */
  3. /*
  4. * Copyright (c) 1992, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This software was developed by the Computer Systems Engineering group
  8. * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
  9. * contributed to Berkeley.
  10. *
  11. * All advertising materials mentioning features or use of this software
  12. * must display the following acknowledgement:
  13. * This product includes software developed by the University of
  14. * California, Lawrence Berkeley Laboratory.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions
  18. * are met:
  19. * 1. Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * 3. Neither the name of the University nor the names of its contributors
  25. * may be used to endorse or promote products derived from this software
  26. * without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  29. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. * SUCH DAMAGE.
  39. *
  40. * @(#)instr.h 8.1 (Berkeley) 6/11/93
  41. */
  42. /* see also Appendix F of the SPARC version 8 document */
  43. enum IOP { IOP_OP2, IOP_CALL, IOP_reg, IOP_mem };
  44. enum IOP2 { IOP2_UNIMP, IOP2_err1, IOP2_Bicc, IOP2_err3,
  45. IOP2_SETHI, IOP2_err5, IOP2_FBfcc, IOP2_CBccc };
  46. enum IOP3_reg {
  47. IOP3_ADD, IOP3_AND, IOP3_OR, IOP3_XOR,
  48. IOP3_SUB, IOP3_ANDN, IOP3_ORN, IOP3_XNOR,
  49. IOP3_ADDX, IOP3_rerr09, IOP3_UMUL, IOP3_SMUL,
  50. IOP3_SUBX, IOP3_rerr0d, IOP3_UDIV, IOP3_SDIV,
  51. IOP3_ADDcc, IOP3_ANDcc, IOP3_ORcc, IOP3_XORcc,
  52. IOP3_SUBcc, IOP3_ANDNcc, IOP3_ORNcc, IOP3_XNORcc,
  53. IOP3_ADDXcc, IOP3_rerr19, IOP3_UMULcc, IOP3_SMULcc,
  54. IOP3_SUBXcc, IOP3_rerr1d, IOP3_UDIVcc, IOP3_SDIVcc,
  55. IOP3_TADDcc, IOP3_TSUBcc, IOP3_TADDccTV, IOP3_TSUBccTV,
  56. IOP3_MULScc, IOP3_SLL, IOP3_SRL, IOP3_SRA,
  57. IOP3_RDASR_RDY_STBAR, IOP3_RDPSR, IOP3_RDWIM, IOP3_RDTGBR,
  58. IOP3_rerr2c, IOP3_rerr2d, IOP3_rerr2e, IOP3_rerr2f,
  59. IOP3_WRASR_WRY, IOP3_WRPSR, IOP3_WRWIM, IOP3_WRTBR,
  60. IOP3_FPop1, IOP3_FPop2, IOP3_CPop1, IOP3_CPop2,
  61. IOP3_JMPL, IOP3_RETT, IOP3_Ticc, IOP3_FLUSH,
  62. IOP3_SAVE, IOP3_RESTORE, IOP3_rerr3e, IOP3_rerr3f
  63. };
  64. enum IOP3_mem {
  65. IOP3_LD, IOP3_LDUB, IOP3_LDUH, IOP3_LDD,
  66. IOP3_ST, IOP3_STB, IOP3_STH, IOP3_STD,
  67. IOP3_merr08, IOP3_LDSB, IOP3_LDSH, IOP3_merr0b,
  68. IOP3_merr0c, IOP3_LDSTUB, IOP3_merr0f, IOP3_SWAP,
  69. IOP3_LDA, IOP3_LDUBA, IOP3_LDUHA, IOP3_LDDA,
  70. IOP3_STA, IOP3_STBA, IOP3_STHA, IOP3_STDA,
  71. IOP3_merr18, IOP3_LDSBA, IOP3_LDSHA, IOP3_merr1b,
  72. IOP3_merr1c, IOP3_LDSTUBA, IOP3_merr1f, IOP3_SWAPA,
  73. IOP3_LDF, IOP3_LDFSR, IOP3_merr22, IOP3_LDDF,
  74. IOP3_STF, IOP3_STFSR, IOP3_STDFQ, IOP3_STDF,
  75. IOP3_merr28, IOP3_merr29, IOP3_merr2a, IOP3_merr2b,
  76. IOP3_merr2c, IOP3_merr2d, IOP3_merr2e, IOP3_merr2f,
  77. IOP3_LFC, IOP3_LDCSR, IOP3_merr32, IOP3_LDDC,
  78. IOP3_STC, IOP3_STCSR, IOP3_STDCQ, IOP3_STDC,
  79. IOP3_merr38, IOP3_merr39, IOP3_merr3a, IOP3_merr3b,
  80. IOP3_merr3c, IOP3_merr3d, IOP3_merr3e, IOP3_merr3f
  81. };
  82. /*
  83. * Integer condition codes.
  84. */
  85. #define Icc_N 0x0 /* never */
  86. #define Icc_E 0x1 /* equal (equiv. zero) */
  87. #define Icc_LE 0x2 /* less or equal */
  88. #define Icc_L 0x3 /* less */
  89. #define Icc_LEU 0x4 /* less or equal unsigned */
  90. #define Icc_CS 0x5 /* carry set (equiv. less unsigned) */
  91. #define Icc_NEG 0x6 /* negative */
  92. #define Icc_VS 0x7 /* overflow set */
  93. #define Icc_A 0x8 /* always */
  94. #define Icc_NE 0x9 /* not equal (equiv. not zero) */
  95. #define Icc_G 0xa /* greater */
  96. #define Icc_GE 0xb /* greater or equal */
  97. #define Icc_GU 0xc /* greater unsigned */
  98. #define Icc_CC 0xd /* carry clear (equiv. gtr or eq unsigned) */
  99. #define Icc_POS 0xe /* positive */
  100. #define Icc_VC 0xf /* overflow clear */
  101. /*
  102. * Integer registers.
  103. */
  104. #define I_G0 0
  105. #define I_G1 1
  106. #define I_G2 2
  107. #define I_G3 3
  108. #define I_G4 4
  109. #define I_G5 5
  110. #define I_G6 6
  111. #define I_G7 7
  112. #define I_O0 8
  113. #define I_O1 9
  114. #define I_O2 10
  115. #define I_O3 11
  116. #define I_O4 12
  117. #define I_O5 13
  118. #define I_O6 14
  119. #define I_O7 15
  120. #define I_L0 16
  121. #define I_L1 17
  122. #define I_L2 18
  123. #define I_L3 19
  124. #define I_L4 20
  125. #define I_L5 21
  126. #define I_L6 22
  127. #define I_L7 23
  128. #define I_I0 24
  129. #define I_I1 25
  130. #define I_I2 26
  131. #define I_I3 27
  132. #define I_I4 28
  133. #define I_I5 29
  134. #define I_I6 30
  135. #define I_I7 31
  136. /*
  137. * An instruction.
  138. */
  139. union instr {
  140. int i_int; /* as a whole */
  141. /*
  142. * The first level of decoding is to use the top 2 bits.
  143. * This gives us one of three `formats', which usually give
  144. * a second level of decoding.
  145. */
  146. struct {
  147. u_int i_op:2; /* first-level decode */
  148. u_int :30;
  149. } i_any;
  150. /*
  151. * Format 1 instructions: CALL (undifferentiated).
  152. */
  153. struct {
  154. u_int :2; /* 01 */
  155. int i_disp:30; /* displacement */
  156. } i_call;
  157. /*
  158. * Format 2 instructions (SETHI, UNIMP, and branches, plus illegal
  159. * unused codes).
  160. */
  161. struct {
  162. u_int :2; /* 00 */
  163. u_int :5;
  164. u_int i_op2:3; /* second-level decode */
  165. u_int :22;
  166. } i_op2;
  167. /* UNIMP, SETHI */
  168. struct {
  169. u_int :2; /* 00 */
  170. u_int i_rd:5; /* destination register */
  171. u_int i_op2:3; /* opcode: UNIMP or SETHI */
  172. u_int i_imm:22; /* immediate value */
  173. } i_imm22;
  174. /* branches: Bicc, FBfcc, CBccc */
  175. struct {
  176. u_int :2; /* 00 */
  177. u_int i_annul:1; /* annul bit */
  178. u_int i_cond:4; /* condition codes */
  179. u_int i_op2:3; /* opcode: {Bi,FBf,CBc}cc */
  180. int i_disp:22; /* branch displacement */
  181. } i_branch;
  182. /*
  183. * Format 3 instructions (memory reference; arithmetic, logical,
  184. * shift, and other miscellaneous operations). The second-level
  185. * decode almost always makes use of an `rd' and `rs1', however
  186. * (see also IOP3_reg and IOP3_mem).
  187. *
  188. * Beyond that, the low 14 bits may be broken up in one of three
  189. * different ways, if at all:
  190. * 1 bit of imm=0 + 8 bits of asi + 5 bits of rs2 [reg & mem]
  191. * 1 bit of imm=1 + 13 bits of signed immediate [reg & mem]
  192. * 9 bits of copressor `opf' opcode + 5 bits of rs2 [reg only]
  193. */
  194. struct {
  195. u_int :2; /* 10 or 11 */
  196. u_int i_rd:5; /* destination register */
  197. u_int i_op3:6; /* second-level decode */
  198. u_int i_rs1:5; /* source register 1 */
  199. u_int i_low14:14; /* varies */
  200. } i_op3;
  201. /*
  202. * Memory forms. These set i_op=3 and use simm13 or asi layout.
  203. * Memory references without an ASI should use 0, but the actual
  204. * ASI field is simply ignored.
  205. */
  206. struct {
  207. u_int :2; /* 11 only */
  208. u_int i_rd:5; /* destination register */
  209. u_int i_op3:6; /* second-level decode (see IOP3_mem) */
  210. u_int i_rs1:5; /* source register 1 */
  211. u_int i_i:1; /* immediate vs asi */
  212. u_int i_low13:13; /* depend on i bit */
  213. } i_loadstore;
  214. /*
  215. * Memory and register forms.
  216. * These come in quite a variety and we do not
  217. * attempt to break them down much.
  218. */
  219. struct {
  220. u_int :2; /* 10 or 11 */
  221. u_int i_rd:5; /* destination register */
  222. u_int i_op3:6; /* second-level decode */
  223. u_int i_rs1:5; /* source register 1 */
  224. u_int i_i:1; /* immediate bit (1) */
  225. int i_simm13:13; /* signed immediate */
  226. } i_simm13;
  227. struct {
  228. u_int :2; /* 10 or 11 */
  229. u_int i_rd:5; /* destination register */
  230. u_int i_op3:6; /* second-level decode */
  231. u_int i_rs1:5; /* source register 1 */
  232. u_int i_i:1; /* immediate vs asi */
  233. u_int i_asi:8; /* asi */
  234. u_int i_rs2:5; /* source register 2 */
  235. } i_asi;
  236. struct {
  237. u_int :2; /* 10 only (register, no memory) */
  238. u_int i_rd:5; /* destination register */
  239. u_int i_op3:6; /* second-level decode (see IOP3_reg) */
  240. u_int i_rs1:5; /* source register 1 */
  241. u_int i_opf:9; /* coprocessor 3rd-level decode */
  242. u_int i_rs2:5; /* source register 2 */
  243. } i_opf;
  244. };
  245. /*
  246. * Internal macros for building instructions. These correspond 1-to-1 to
  247. * the names above. Note that x << y | z == (x << y) | z.
  248. */
  249. #define _I_ANY(op, b) ((op) << 30 | (b))
  250. #define _I_OP2(high, op2, low) \
  251. _I_ANY(IOP_OP2, (high) << 25 | (op2) << 22 | (low))
  252. #define _I_IMM22(rd, op2, imm) \
  253. _I_ANY(IOP_OP2, (rd) << 25 | (op2) << 22 | (imm))
  254. #define _I_BRANCH(a, c, op2, disp) \
  255. _I_ANY(IOP_OP2, (a) << 29 | (c) << 25 | (op2) << 22 | (disp))
  256. #define _I_FBFCC(a, cond, disp) \
  257. _I_BRANCH(a, cond, IOP2_FBfcc, disp)
  258. #define _I_CBCCC(a, cond, disp) \
  259. _I_BRANCH(a, cond, IOP2_CBccc, disp)
  260. #define _I_SIMM(simm) (1 << 13 | ((simm) & 0x1fff))
  261. #define _I_OP3_GEN(form, rd, op3, rs1, low14) \
  262. _I_ANY(form, (rd) << 25 | (op3) << 19 | (rs1) << 14 | (low14))
  263. #define _I_OP3_LS_RAR(rd, op3, rs1, asi, rs2) \
  264. _I_OP3_GEN(IOP_mem, rd, op3, rs1, (asi) << 5 | (rs2))
  265. #define _I_OP3_LS_RI(rd, op3, rs1, simm13) \
  266. _I_OP3_GEN(IOP_mem, rd, op3, rs1, _I_SIMM(simm13))
  267. #define _I_OP3_LS_RR(rd, op3, rs1, rs2) \
  268. _I_OP3_GEN(IOP_mem, rd, op3, rs1, rs2)
  269. #define _I_OP3_R_RAR(rd, op3, rs1, asi, rs2) \
  270. _I_OP3_GEN(IOP_reg, rd, op3, rs1, (asi) << 5 | (rs2))
  271. #define _I_OP3_R_RI(rd, op3, rs1, simm13) \
  272. _I_OP3_GEN(IOP_reg, rd, op3, rs1, _I_SIMM(simm13))
  273. #define _I_OP3_R_RR(rd, op3, rs1, rs2) \
  274. _I_OP3_GEN(IOP_reg, rd, op3, rs1, rs2)
  275. #define I_CALL(d) _I_ANY(IOP_CALL, d)
  276. #define I_UNIMP(v) _I_IMM22(0, IOP2_UNIMP, v)
  277. #define I_BN(a, d) _I_BRANCH(a, Icc_N, IOP2_Bicc, d)
  278. #define I_BE(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d)
  279. #define I_BZ(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d)
  280. #define I_BLE(a, d) _I_BRANCH(a, Icc_LE, IOP2_Bicc, d)
  281. #define I_BL(a, d) _I_BRANCH(a, Icc_L, IOP2_Bicc, d)
  282. #define I_BLEU(a, d) _I_BRANCH(a, Icc_LEU, IOP2_Bicc, d)
  283. #define I_BCS(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d)
  284. #define I_BLU(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d)
  285. #define I_BNEG(a, d) _I_BRANCH(a, Icc_NEG, IOP2_Bicc, d)
  286. #define I_BVS(a, d) _I_BRANCH(a, Icc_VS, IOP2_Bicc, d)
  287. #define I_BA(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d)
  288. #define I_B(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d)
  289. #define I_BNE(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d)
  290. #define I_BNZ(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d)
  291. #define I_BG(a, d) _I_BRANCH(a, Icc_G, IOP2_Bicc, d)
  292. #define I_BGE(a, d) _I_BRANCH(a, Icc_GE, IOP2_Bicc, d)
  293. #define I_BGU(a, d) _I_BRANCH(a, Icc_GU, IOP2_Bicc, d)
  294. #define I_BCC(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d)
  295. #define I_BGEU(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d)
  296. #define I_BPOS(a, d) _I_BRANCH(a, Icc_POS, IOP2_Bicc, d)
  297. #define I_BVC(a, d) _I_BRANCH(a, Icc_VC, IOP2_Bicc, d)
  298. #define I_SETHI(r, v) _I_IMM22(r, 4, v)
  299. #define I_ORri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_OR, rs1, imm)
  300. #define I_ORrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_OR, rs1, rs2)
  301. #define I_MOVi(rd, imm) _I_OP3_R_RI(rd, IOP3_OR, I_G0, imm)
  302. #define I_MOVr(rd, rs) _I_OP3_R_RR(rd, IOP3_OR, I_G0, rs)
  303. #define I_RDPSR(rd) _I_OP3_R_RR(rd, IOP3_RDPSR, 0, 0)
  304. #define I_JMPLri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_JMPL, rs1, imm)
  305. #define I_JMPLrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_JMPL, rs1, rs2)
  306. /*
  307. * (Since these are sparse, we skip the enumerations for now.)
  308. * FPop values. All appear in both FPop1 and FPop2 spaces, but arithmetic
  309. * ops should happen only with FPop1 and comparison only with FPop2.
  310. * The type sits in the low two bits; those bits are given as zero here.
  311. */
  312. #define FMOV 0x00
  313. #define FNEG 0x04
  314. #define FABS 0x08
  315. #define FSQRT 0x28
  316. #define FADD 0x40
  317. #define FSUB 0x44
  318. #define FMUL 0x48
  319. #define FDIV 0x4c
  320. #define FCMP 0x50
  321. #define FCMPE 0x54
  322. #define FSMULD 0x68
  323. #define FDMULX 0x6c
  324. #define FTOS 0xc4
  325. #define FTOD 0xc8
  326. #define FTOX 0xcc
  327. #define FTOI 0xd0
  328. /*
  329. * FPU data types.
  330. */
  331. #define FTYPE_INT 0 /* data = 32-bit signed integer */
  332. #define FTYPE_SNG 1 /* data = 32-bit float */
  333. #define FTYPE_DBL 2 /* data = 64-bit double */
  334. #define FTYPE_EXT 3 /* data = 128-bit extended (quad-prec) */