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