| 1 | /* |
| 2 | * z64 |
| 3 | * |
| 4 | * Copyright (C) 2007 ziggy |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | **/ |
| 21 | |
| 22 | #include "rsp.h" |
| 23 | |
| 24 | struct rsp_regmask_t { |
| 25 | //UINT32 r; |
| 26 | UINT8 v[32]; |
| 27 | UINT32 accu; |
| 28 | UINT8 flag; |
| 29 | }; |
| 30 | |
| 31 | #define RSP_GET_REG_I(i, R) ( (i).r & (1<<(R)) ) |
| 32 | #define RSP_SET_REG_I(i, R) (i).r |= (1<<(R)) |
| 33 | #define RSP_CLEAR_REG_I(i, R) (i).r &= ~(1<<(R)) |
| 34 | |
| 35 | #define RSP_GET_VEC_I(i, R, I) ( (i).v[R] & (1<<(I)) ) |
| 36 | #define RSP_SET_VEC_I(i, R, I) (i).v[R] |= (1<<(I)) |
| 37 | #define RSP_CLEAR_VEC_I(i, R, I) (i).v[R] &= ~(1<<(I)) |
| 38 | |
| 39 | #define RSP_GET_ACCU_I(i, I, P) ( (i).accu & ((P)<<(I)*4) ) |
| 40 | #define RSP_SET_ACCU_I(i, I, P) (i).accu |= ((P)<<(I)*4) |
| 41 | #define RSP_CLEAR_ACCU_I(i, I, P) (i).accu &= ~((P)<<(I)*4) |
| 42 | |
| 43 | #define RSP_GET_FLAG_I(i, R) ( (i).flag & (1<<(R)) ) |
| 44 | #define RSP_SET_FLAG_I(i, R) (i).flag |= (1<<(R)) |
| 45 | #define RSP_CLEAR_FLAG_I(i, R) (i).flag &= ~(1<<(R)) |
| 46 | |
| 47 | #define RSP_OPINFO_JUMP 1 |
| 48 | #define RSP_OPINFO_BREAK 2 |
| 49 | #define RSP_OPINFO_COND 4 |
| 50 | #define RSP_OPINFO_LINK 8 |
| 51 | #define RSP_OPINFO_USEPC 16 |
| 52 | struct rsp_opinfo_t { |
| 53 | UINT32 op; // original opcode |
| 54 | int op2; // simplified opcode |
| 55 | rsp_regmask_t used; |
| 56 | rsp_regmask_t set; |
| 57 | int flags; |
| 58 | }; |
| 59 | |
| 60 | void rsp_get_opinfo(UINT32 op, rsp_opinfo_t * info); |
| 61 | |
| 62 | #define RSP_BASIC_OFFS 0x000 |
| 63 | #define RSP_SPECIAL_OFFS 0x040 |
| 64 | #define RSP_LWC2_OFFS 0x0a0 |
| 65 | #define RSP_SWC2_OFFS 0x0c0 |
| 66 | #define RSP_COP2_1_OFFS 0x080 |
| 67 | #define RSP_COP2_2_OFFS 0x100 |
| 68 | #define RSP_CONTROL_OFFS 0x140 |
| 69 | |
| 70 | |
| 71 | #define RSP_STOP (RSP_CONTROL_OFFS + 0x00) |
| 72 | #define RSP_LOOP (RSP_CONTROL_OFFS + 0x01) |
| 73 | #define RSP_JUMP (RSP_CONTROL_OFFS + 0x02) |
| 74 | #define RSP_CONDJUMP (RSP_CONTROL_OFFS + 0x03) |
| 75 | #define RSP_JUMPLOCAL (RSP_CONTROL_OFFS + 0x04) |
| 76 | #define RSP_CONDJUMPLOCAL (RSP_CONTROL_OFFS + 0x05) |
| 77 | |
| 78 | |
| 79 | #define RSP_SPECIAL (RSP_BASIC_OFFS + 0x00) |
| 80 | #define RSP_REGIMM (RSP_BASIC_OFFS + 0x01) |
| 81 | #define RSP_J (RSP_BASIC_OFFS + 0x02) |
| 82 | #define RSP_JAL (RSP_BASIC_OFFS + 0x03) |
| 83 | #define RSP_BEQ (RSP_BASIC_OFFS + 0x04) |
| 84 | #define RSP_BNE (RSP_BASIC_OFFS + 0x05) |
| 85 | #define RSP_BLEZ (RSP_BASIC_OFFS + 0x06) |
| 86 | #define RSP_BGTZ (RSP_BASIC_OFFS + 0x07) |
| 87 | #define RSP_ADDI (RSP_BASIC_OFFS + 0x08) |
| 88 | #define RSP_ADDIU (RSP_BASIC_OFFS + 0x09) |
| 89 | #define RSP_SLTI (RSP_BASIC_OFFS + 0x0a) |
| 90 | #define RSP_SLTIU (RSP_BASIC_OFFS + 0x0b) |
| 91 | #define RSP_ANDI (RSP_BASIC_OFFS + 0x0c) |
| 92 | #define RSP_ORI (RSP_BASIC_OFFS + 0x0d) |
| 93 | #define RSP_XORI (RSP_BASIC_OFFS + 0x0e) |
| 94 | #define RSP_LUI (RSP_BASIC_OFFS + 0x0f) |
| 95 | #define RSP_COP0 (RSP_BASIC_OFFS + 0x10) |
| 96 | #define RSP_COP2 (RSP_BASIC_OFFS + 0x12) |
| 97 | #define RSP_LB (RSP_BASIC_OFFS + 0x20) |
| 98 | #define RSP_LH (RSP_BASIC_OFFS + 0x21) |
| 99 | #define RSP_LW (RSP_BASIC_OFFS + 0x23) |
| 100 | #define RSP_LBU (RSP_BASIC_OFFS + 0x24) |
| 101 | #define RSP_LHU (RSP_BASIC_OFFS + 0x25) |
| 102 | #define RSP_SB (RSP_BASIC_OFFS + 0x28) |
| 103 | #define RSP_SH (RSP_BASIC_OFFS + 0x29) |
| 104 | #define RSP_SW (RSP_BASIC_OFFS + 0x2b) |
| 105 | #define RSP_LWC2 (RSP_BASIC_OFFS + 0x32) |
| 106 | #define RSP_SWC2 (RSP_BASIC_OFFS + 0x3a) |
| 107 | #define RSP_BLTZ (RSP_BASIC_OFFS + 0x3b) |
| 108 | #define RSP_BGEZ (RSP_BASIC_OFFS + 0x3c) |
| 109 | #define RSP_BGEZAL (RSP_BASIC_OFFS + 0x3d) |
| 110 | |
| 111 | #define RSP_SLL (RSP_SPECIAL_OFFS + 0x00) |
| 112 | #define RSP_SRL (RSP_SPECIAL_OFFS + 0x02) |
| 113 | #define RSP_SRA (RSP_SPECIAL_OFFS + 0x03) |
| 114 | #define RSP_SLLV (RSP_SPECIAL_OFFS + 0x04) |
| 115 | #define RSP_SRLV (RSP_SPECIAL_OFFS + 0x06) |
| 116 | #define RSP_SRAV (RSP_SPECIAL_OFFS + 0x07) |
| 117 | #define RSP_JR (RSP_SPECIAL_OFFS + 0x08) |
| 118 | #define RSP_JALR (RSP_SPECIAL_OFFS + 0x09) |
| 119 | #define RSP_BREAK (RSP_SPECIAL_OFFS + 0x0d) |
| 120 | #define RSP_ADD (RSP_SPECIAL_OFFS + 0x20) |
| 121 | #define RSP_ADDU (RSP_SPECIAL_OFFS + 0x21) |
| 122 | #define RSP_SUB (RSP_SPECIAL_OFFS + 0x22) |
| 123 | #define RSP_SUBU (RSP_SPECIAL_OFFS + 0x23) |
| 124 | #define RSP_AND (RSP_SPECIAL_OFFS + 0x24) |
| 125 | #define RSP_OR (RSP_SPECIAL_OFFS + 0x25) |
| 126 | #define RSP_XOR (RSP_SPECIAL_OFFS + 0x26) |
| 127 | #define RSP_NOR (RSP_SPECIAL_OFFS + 0x27) |
| 128 | #define RSP_SLT (RSP_SPECIAL_OFFS + 0x2a) |
| 129 | #define RSP_SLTU (RSP_SPECIAL_OFFS + 0x2b) |
| 130 | |
| 131 | #define RSP_MFC2 (RSP_COP2_1_OFFS + 0x00) |
| 132 | #define RSP_CFC2 (RSP_COP2_1_OFFS + 0x02) |
| 133 | #define RSP_MTC2 (RSP_COP2_1_OFFS + 0x04) |
| 134 | #define RSP_CTC2 (RSP_COP2_1_OFFS + 0x06) |
| 135 | |
| 136 | |
| 137 | #define RSP_LBV (RSP_LWC2_OFFS + 0x00) |
| 138 | #define RSP_LSV (RSP_LWC2_OFFS + 0x01) |
| 139 | #define RSP_LLV (RSP_LWC2_OFFS + 0x02) |
| 140 | #define RSP_LDV (RSP_LWC2_OFFS + 0x03) |
| 141 | #define RSP_LQV (RSP_LWC2_OFFS + 0x04) |
| 142 | #define RSP_LRV (RSP_LWC2_OFFS + 0x05) |
| 143 | #define RSP_LPV (RSP_LWC2_OFFS + 0x06) |
| 144 | #define RSP_LUV (RSP_LWC2_OFFS + 0x07) |
| 145 | #define RSP_LHV (RSP_LWC2_OFFS + 0x08) |
| 146 | #define RSP_LFV (RSP_LWC2_OFFS + 0x09) |
| 147 | #define RSP_LWV (RSP_LWC2_OFFS + 0x0a) |
| 148 | #define RSP_LTV (RSP_LWC2_OFFS + 0x0b) |
| 149 | |
| 150 | #define RSP_SBV (RSP_SWC2_OFFS + 0x00) |
| 151 | #define RSP_SSV (RSP_SWC2_OFFS + 0x01) |
| 152 | #define RSP_SLV (RSP_SWC2_OFFS + 0x02) |
| 153 | #define RSP_SDV (RSP_SWC2_OFFS + 0x03) |
| 154 | #define RSP_SQV (RSP_SWC2_OFFS + 0x04) |
| 155 | #define RSP_SRV (RSP_SWC2_OFFS + 0x05) |
| 156 | #define RSP_SPV (RSP_SWC2_OFFS + 0x06) |
| 157 | #define RSP_SUV (RSP_SWC2_OFFS + 0x07) |
| 158 | #define RSP_SHV (RSP_SWC2_OFFS + 0x08) |
| 159 | #define RSP_SFV (RSP_SWC2_OFFS + 0x09) |
| 160 | #define RSP_SWV (RSP_SWC2_OFFS + 0x0a) |
| 161 | #define RSP_STV (RSP_SWC2_OFFS + 0x0b) |
| 162 | |
| 163 | #define RSP_VMULF (RSP_COP2_2_OFFS + 0x00) |
| 164 | #define RSP_VMULU (RSP_COP2_2_OFFS + 0x01) |
| 165 | #define RSP_VMUDL (RSP_COP2_2_OFFS + 0x04) |
| 166 | #define RSP_VMUDM (RSP_COP2_2_OFFS + 0x05) |
| 167 | #define RSP_VMUDN (RSP_COP2_2_OFFS + 0x06) |
| 168 | #define RSP_VMUDH (RSP_COP2_2_OFFS + 0x07) |
| 169 | #define RSP_VMACF (RSP_COP2_2_OFFS + 0x08) |
| 170 | #define RSP_VMACU (RSP_COP2_2_OFFS + 0x09) |
| 171 | #define RSP_VMADL (RSP_COP2_2_OFFS + 0x0c) |
| 172 | #define RSP_VMADM (RSP_COP2_2_OFFS + 0x0d) |
| 173 | #define RSP_VMADN (RSP_COP2_2_OFFS + 0x0e) |
| 174 | #define RSP_VMADH (RSP_COP2_2_OFFS + 0x0f) |
| 175 | #define RSP_VADD (RSP_COP2_2_OFFS + 0x10) |
| 176 | #define RSP_VSUB (RSP_COP2_2_OFFS + 0x11) |
| 177 | #define RSP_VABS (RSP_COP2_2_OFFS + 0x13) |
| 178 | #define RSP_VADDC (RSP_COP2_2_OFFS + 0x14) |
| 179 | #define RSP_VSUBC (RSP_COP2_2_OFFS + 0x15) |
| 180 | #define RSP_VSAW (RSP_COP2_2_OFFS + 0x1d) |
| 181 | #define RSP_VLT (RSP_COP2_2_OFFS + 0x20) |
| 182 | #define RSP_VEQ (RSP_COP2_2_OFFS + 0x21) |
| 183 | #define RSP_VNE (RSP_COP2_2_OFFS + 0x22) |
| 184 | #define RSP_VGE (RSP_COP2_2_OFFS + 0x23) |
| 185 | #define RSP_VCL (RSP_COP2_2_OFFS + 0x24) |
| 186 | #define RSP_VCH (RSP_COP2_2_OFFS + 0x25) |
| 187 | #define RSP_VCR (RSP_COP2_2_OFFS + 0x26) |
| 188 | #define RSP_VMRG (RSP_COP2_2_OFFS + 0x27) |
| 189 | #define RSP_VAND (RSP_COP2_2_OFFS + 0x28) |
| 190 | #define RSP_VNAND (RSP_COP2_2_OFFS + 0x29) |
| 191 | #define RSP_VOR (RSP_COP2_2_OFFS + 0x2a) |
| 192 | #define RSP_VNOR (RSP_COP2_2_OFFS + 0x2b) |
| 193 | #define RSP_VXOR (RSP_COP2_2_OFFS + 0x2c) |
| 194 | #define RSP_VNXOR (RSP_COP2_2_OFFS + 0x2d) |
| 195 | #define RSP_VRCP (RSP_COP2_2_OFFS + 0x30) |
| 196 | #define RSP_VRCPL (RSP_COP2_2_OFFS + 0x31) |
| 197 | #define RSP_VRCPH (RSP_COP2_2_OFFS + 0x32) |
| 198 | #define RSP_VMOV (RSP_COP2_2_OFFS + 0x33) |
| 199 | #define RSP_VRSQL (RSP_COP2_2_OFFS + 0x35) |
| 200 | #define RSP_VRSQH (RSP_COP2_2_OFFS + 0x36) |