1 /* $NetBSD: mips_opcode.h,v 1.12 2005/12/11 12:18:09 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)mips_opcode.h 8.1 (Berkeley) 6/10/93 35 */ 36 37 /* 38 * Define the instruction formats and opcode values for the 39 * MIPS instruction set. 40 */ 41 42 #include <endian.h> 43 44 /* 45 * Define the instruction formats. 46 */ 47 typedef union { 48 unsigned word; 49 50 #if BYTE_ORDER == LITTLE_ENDIAN 51 struct { 52 unsigned imm: 16; 53 unsigned rt: 5; 54 unsigned rs: 5; 55 unsigned op: 6; 56 } IType; 57 58 struct { 59 unsigned target: 26; 60 unsigned op: 6; 61 } JType; 62 63 struct { 64 unsigned func: 6; 65 unsigned shamt: 5; 66 unsigned rd: 5; 67 unsigned rt: 5; 68 unsigned rs: 5; 69 unsigned op: 6; 70 } RType; 71 72 struct { 73 unsigned func: 6; 74 unsigned fd: 5; 75 unsigned fs: 5; 76 unsigned ft: 5; 77 unsigned fmt: 4; 78 unsigned : 1; /* always '1' */ 79 unsigned op: 6; /* always '0x11' */ 80 } FRType; 81 #endif 82 #if BYTE_ORDER == BIG_ENDIAN 83 struct { 84 unsigned op: 6; 85 unsigned rs: 5; 86 unsigned rt: 5; 87 unsigned imm: 16; 88 } IType; 89 90 struct { 91 unsigned op: 6; 92 unsigned target: 26; 93 } JType; 94 95 struct { 96 unsigned op: 6; 97 unsigned rs: 5; 98 unsigned rt: 5; 99 unsigned rd: 5; 100 unsigned shamt: 5; 101 unsigned func: 6; 102 } RType; 103 104 struct { 105 unsigned op: 6; /* always '0x11' */ 106 unsigned : 1; /* always '1' */ 107 unsigned fmt: 4; 108 unsigned ft: 5; 109 unsigned fs: 5; 110 unsigned fd: 5; 111 unsigned func: 6; 112 } FRType; 113 #endif 114 } InstFmt; 115 116 /* 117 * Values for the 'op' field. 118 */ 119 #define OP_SPECIAL 000 120 #define OP_BCOND 001 121 #define OP_J 002 122 #define OP_JAL 003 123 #define OP_BEQ 004 124 #define OP_BNE 005 125 #define OP_BLEZ 006 126 #define OP_BGTZ 007 127 128 #if __mips_isa_rev < 6 129 #define OP_ADDI 010 130 #else 131 #define OP_POP10 010 132 #endif 133 134 #define OP_ADDIU 011 135 #define OP_SLTI 012 136 #define OP_SLTIU 013 137 #define OP_ANDI 014 138 #define OP_ORI 015 139 #define OP_XORI 016 140 141 #if __mips_isa_rev < 6 142 #define OP_LUI 017 143 #else 144 #define OP_AUI 017 145 #endif 146 147 #define OP_COP0 020 148 #define OP_COP1 021 149 #define OP_COP2 022 150 151 #if __mips_isa_rev < 6 152 #define OP_COP3 023 153 #define OP_BEQL 024 154 #define OP_BNEL 025 155 #define OP_BLEZL 026 156 #define OP_BGTZL 027 157 #define OP_DADDI 030 158 #else 159 #define OP_POP26 026 160 #define OP_POP27 027 161 #define OP_POP30 030 162 #endif 163 164 #define OP_DADDIU 031 165 166 #if __mips_isa_rev < 6 167 #define OP_LDL 032 168 #define OP_LDR 033 169 #define OP_SPECIAL2 034 170 #else 171 #define OP_DAUI 035 172 #endif 173 174 #define OP_SPECIAL3 037 175 176 #define OP_LB 040 177 #define OP_LH 041 178 179 #if __mips_isa_rev < 6 180 #define OP_LWL 042 181 #endif 182 183 #define OP_LW 043 184 #define OP_LBU 044 185 #define OP_LHU 045 186 #define OP_LWR 046 187 #define OP_LHU 045 188 189 #if __mips_isa_rev < 6 190 #define OP_LWR 046 191 #endif 192 193 #define OP_LWU 047 194 195 #define OP_SB 050 196 #define OP_SH 051 197 198 #if __mips_isa_rev < 6 199 #define OP_SWL 052 200 #endif 201 202 #define OP_SW 053 203 204 #if __mips_isa_rev < 6 205 #define OP_SDL 054 206 #define OP_SDR 055 207 #define OP_SWR 056 208 #define OP_CACHE 057 209 #define OP_LL 060 210 #define OP_LWC0 OP_LL 211 #define OP_LWC1 061 212 #define OP_LWC2 062 213 #define OP_LWC3 063 214 #define OP_LLD 064 215 #else 216 #define OP_LWC1 061 217 #define OP_BC 062 218 #endif 219 220 #define OP_LDC1 065 221 #define OP_LD 067 222 223 #if __mips_isa_rev < 6 224 #define OP_SC 070 225 #define OP_SWC0 OP_SC 226 #endif 227 228 #define OP_SWC1 071 229 230 #if __mips_isa_rev < 6 231 #define OP_SWC2 072 232 #define OP_SWC3 073 233 #define OP_SCD 074 234 #else 235 #define OP_BALC 072 236 #endif 237 238 #define OP_SDC1 075 239 #define OP_SD 077 240 241 /* 242 * Values for the 'func' field when 'op' == OP_SPECIAL. 243 */ 244 #define OP_SLL 000 245 #define OP_SRL 002 246 #define OP_SRA 003 247 #define OP_SLLV 004 248 #define OP_SRLV 006 249 #define OP_SRAV 007 250 251 #if __mips_isa_rev < 6 252 #define OP_JR 010 253 #endif 254 255 #define OP_JALR 011 256 #define OP_SYSCALL 014 257 #define OP_BREAK 015 258 #define OP_SYNC 017 259 260 #if __mips_isa_rev < 6 261 #define OP_MFHI 020 262 #define OP_MTHI 021 263 #define OP_MFLO 022 264 #define OP_MTLO 023 265 #else 266 #define OP_CLZ 020 267 #define OP_CLO 021 268 #define OP_DCLZ 022 269 #define OP_DCLO 023 270 #endif 271 272 #define OP_DSLLV 024 273 #define OP_DSRLV 026 274 #define OP_DSRAV 027 275 276 #if __mips_isa_rev < 6 277 #define OP_MULT 030 278 #define OP_MULTU 031 279 #define OP_DIV 032 280 #define OP_DIVU 033 281 #define OP_DMULT 034 282 #define OP_DMULTU 035 283 #define OP_DDIV 036 284 #define OP_DDIVU 037 285 #else 286 #define OP_SOP30 030 287 #define OP_SOP31 031 288 #define OP_SOP32 032 289 #define OP_SOP33 033 290 #define OP_SOP34 034 291 #define OP_SOP35 035 292 #define OP_SOP36 036 293 #define OP_SOP37 037 294 #endif 295 296 #define OP_ADD 040 297 #define OP_ADDU 041 298 #define OP_SUB 042 299 #define OP_SUBU 043 300 #define OP_AND 044 301 #define OP_OR 045 302 #define OP_XOR 046 303 #define OP_NOR 047 304 305 #define OP_SLT 052 306 #define OP_SLTU 053 307 #define OP_DADD 054 308 #define OP_DADDU 055 309 #define OP_DSUB 056 310 #define OP_DSUBU 057 311 312 #define OP_TGE 060 313 #define OP_TGEU 061 314 #define OP_TLT 062 315 #define OP_TLTU 063 316 #define OP_TEQ 064 317 #define OP_TNE 066 318 319 #define OP_DSLL 070 320 #define OP_DSRL 072 321 #define OP_DSRA 073 322 #define OP_DSLL32 074 323 #define OP_DSRL32 076 324 #define OP_DSRA32 077 325 326 #if __mips_isa_rev < 6 327 /* 328 * Values for the 'func' field when 'op' == OP_SPECIAL2. 329 * OP_SPECIAL2 opcodes are removed in mips32r6 330 */ 331 #define OP_MAD 000 /* QED */ 332 #define OP_MADU 001 /* QED */ 333 #define OP_MUL 002 /* QED */ 334 #endif 335 336 /* 337 * Values for the 'func' field when 'op' == OP_SPECIAL3. 338 */ 339 #define OP_EXT 000 340 #define OP_DEXTM 001 341 #define OP_DEXTU 002 342 #define OP_DEXT 003 343 #define OP_INS 004 344 #define OP_DINSM 005 345 #define OP_DINSU 006 346 #define OP_DINS 007 347 #define OP_BSHFL 040 348 #define OP_RDHWR 073 349 350 /* 351 * Values for the 'shamt' field when OP_SPECIAL3 && func OP_BSHFL. 352 */ 353 354 #define OP_WSBH 002 355 #define OP_SEB 020 356 #define OP_SEH 030 357 358 #if __mips_isa_rev == 6 359 /* 360 * Values for the 'shamt' field when OP_SOP30. 361 */ 362 #define OP_MUL 002 363 #define OP_MUH 003 364 #endif 365 366 /* 367 * Values for the 'func' field when 'op' == OP_BCOND. 368 */ 369 #define OP_BLTZ 000 370 #define OP_BGEZ 001 371 372 #if __mips_isa_rev < 6 373 #define OP_BLTZL 002 374 #define OP_BGEZL 003 375 #define OP_TGEI 010 376 #define OP_TGEIU 011 377 #define OP_TLTI 012 378 #define OP_TLTIU 013 379 #define OP_TEQI 014 380 #define OP_TNEI 016 381 #define OP_BLTZAL 020 382 #define OP_BGEZAL 021 383 #define OP_BLTZALL 022 384 #define OP_BGEZALL 023 385 #else 386 #define OP_NAL 020 387 #define OP_BAL 021 388 #endif 389 390 /* 391 * Values for the 'rs' field when 'op' == OP_COPz. 392 */ 393 #define OP_MF 000 394 #define OP_DMF 001 395 #define OP_MT 004 396 #define OP_DMT 005 397 #define OP_BCx 010 398 #define OP_BCy 014 399 #define OP_CF 002 400 #define OP_CT 006 401 402 /* 403 * Values for the 'rt' field when 'op' == OP_COPz. 404 */ 405 #define COPz_BC_TF_MASK 0x01 406 #define COPz_BC_TRUE 0x01 407 #define COPz_BC_FALSE 0x00 408 #define COPz_BCL_TF_MASK 0x02 409 #define COPz_BCL_TRUE 0x02 410 #define COPz_BCL_FALSE 0x00 411