OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_MIPS_CONSTANTS_H_ | 5 #ifndef V8_MIPS_CONSTANTS_H_ |
6 #define V8_MIPS_CONSTANTS_H_ | 6 #define V8_MIPS_CONSTANTS_H_ |
7 #include "src/globals.h" | 7 #include "src/globals.h" |
8 // UNIMPLEMENTED_ macro for MIPS. | 8 // UNIMPLEMENTED_ macro for MIPS. |
9 #ifdef DEBUG | 9 #ifdef DEBUG |
10 #define UNIMPLEMENTED_MIPS() \ | 10 #define UNIMPLEMENTED_MIPS() \ |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 extern const Instr kRtMask; | 813 extern const Instr kRtMask; |
814 extern const Instr kLwSwInstrTypeMask; | 814 extern const Instr kLwSwInstrTypeMask; |
815 extern const Instr kLwSwInstrArgumentMask; | 815 extern const Instr kLwSwInstrArgumentMask; |
816 extern const Instr kLwSwOffsetMask; | 816 extern const Instr kLwSwOffsetMask; |
817 | 817 |
818 // Break 0xfffff, reserved for redirected real time call. | 818 // Break 0xfffff, reserved for redirected real time call. |
819 const Instr rtCallRedirInstr = SPECIAL | BREAK | call_rt_redirected << 6; | 819 const Instr rtCallRedirInstr = SPECIAL | BREAK | call_rt_redirected << 6; |
820 // A nop instruction. (Encoding of sll 0 0 0). | 820 // A nop instruction. (Encoding of sll 0 0 0). |
821 const Instr nopInstr = 0; | 821 const Instr nopInstr = 0; |
822 | 822 |
| 823 |
823 class Instruction { | 824 class Instruction { |
824 public: | 825 public: |
825 enum { | 826 enum { |
826 kInstrSize = 4, | 827 kInstrSize = 4, |
827 kInstrSizeLog2 = 2, | 828 kInstrSizeLog2 = 2, |
828 // On MIPS PC cannot actually be directly accessed. We behave as if PC was | 829 // On MIPS PC cannot actually be directly accessed. We behave as if PC was |
829 // always the value of the current instruction being executed. | 830 // always the value of the current instruction being executed. |
830 kPCReadOffset = 0 | 831 kPCReadOffset = 0 |
831 }; | 832 }; |
832 | 833 |
(...skipping 18 matching lines...) Expand all Loading... |
851 } | 852 } |
852 | 853 |
853 // Instruction type. | 854 // Instruction type. |
854 enum Type { | 855 enum Type { |
855 kRegisterType, | 856 kRegisterType, |
856 kImmediateType, | 857 kImmediateType, |
857 kJumpType, | 858 kJumpType, |
858 kUnsupported = -1 | 859 kUnsupported = -1 |
859 }; | 860 }; |
860 | 861 |
| 862 enum TypeChecks { NORMAL, EXTRA }; |
| 863 |
| 864 |
| 865 #define OpcodeToBitNumber(opcode) \ |
| 866 (1ULL << (static_cast<uint32_t>(opcode) >> kOpcodeShift)) |
| 867 |
| 868 static const uint64_t kOpcodeImmediateTypeMask = |
| 869 OpcodeToBitNumber(REGIMM) | OpcodeToBitNumber(BEQ) | |
| 870 OpcodeToBitNumber(BNE) | OpcodeToBitNumber(BLEZ) | |
| 871 OpcodeToBitNumber(BGTZ) | OpcodeToBitNumber(ADDI) | |
| 872 OpcodeToBitNumber(DADDI) | OpcodeToBitNumber(ADDIU) | |
| 873 OpcodeToBitNumber(SLTI) | OpcodeToBitNumber(SLTIU) | |
| 874 OpcodeToBitNumber(ANDI) | OpcodeToBitNumber(ORI) | |
| 875 OpcodeToBitNumber(XORI) | OpcodeToBitNumber(LUI) | |
| 876 OpcodeToBitNumber(BEQL) | OpcodeToBitNumber(BNEL) | |
| 877 OpcodeToBitNumber(BLEZL) | OpcodeToBitNumber(BGTZL) | |
| 878 OpcodeToBitNumber(POP66) | OpcodeToBitNumber(POP76) | |
| 879 OpcodeToBitNumber(LB) | OpcodeToBitNumber(LH) | OpcodeToBitNumber(LWL) | |
| 880 OpcodeToBitNumber(LW) | OpcodeToBitNumber(LBU) | OpcodeToBitNumber(LHU) | |
| 881 OpcodeToBitNumber(LWR) | OpcodeToBitNumber(SB) | OpcodeToBitNumber(SH) | |
| 882 OpcodeToBitNumber(SWL) | OpcodeToBitNumber(SW) | OpcodeToBitNumber(SWR) | |
| 883 OpcodeToBitNumber(LWC1) | OpcodeToBitNumber(LDC1) | |
| 884 OpcodeToBitNumber(SWC1) | OpcodeToBitNumber(SDC1) | |
| 885 OpcodeToBitNumber(PCREL) | OpcodeToBitNumber(BC) | |
| 886 OpcodeToBitNumber(BALC); |
| 887 |
| 888 #define FunctionFieldToBitNumber(function) (1ULL << function) |
| 889 |
| 890 static const uint64_t kFunctionFieldRegisterTypeMask = |
| 891 FunctionFieldToBitNumber(JR) | FunctionFieldToBitNumber(JALR) | |
| 892 FunctionFieldToBitNumber(BREAK) | FunctionFieldToBitNumber(SLL) | |
| 893 FunctionFieldToBitNumber(SRL) | FunctionFieldToBitNumber(SRA) | |
| 894 FunctionFieldToBitNumber(SLLV) | FunctionFieldToBitNumber(SRLV) | |
| 895 FunctionFieldToBitNumber(SRAV) | FunctionFieldToBitNumber(MFHI) | |
| 896 FunctionFieldToBitNumber(MFLO) | FunctionFieldToBitNumber(MULT) | |
| 897 FunctionFieldToBitNumber(MULTU) | FunctionFieldToBitNumber(DIV) | |
| 898 FunctionFieldToBitNumber(DIVU) | FunctionFieldToBitNumber(ADD) | |
| 899 FunctionFieldToBitNumber(ADDU) | FunctionFieldToBitNumber(SUB) | |
| 900 FunctionFieldToBitNumber(SUBU) | FunctionFieldToBitNumber(AND) | |
| 901 FunctionFieldToBitNumber(OR) | FunctionFieldToBitNumber(XOR) | |
| 902 FunctionFieldToBitNumber(NOR) | FunctionFieldToBitNumber(SLT) | |
| 903 FunctionFieldToBitNumber(SLTU) | FunctionFieldToBitNumber(TGE) | |
| 904 FunctionFieldToBitNumber(TGEU) | FunctionFieldToBitNumber(TLT) | |
| 905 FunctionFieldToBitNumber(TLTU) | FunctionFieldToBitNumber(TEQ) | |
| 906 FunctionFieldToBitNumber(TNE) | FunctionFieldToBitNumber(MOVZ) | |
| 907 FunctionFieldToBitNumber(MOVN) | FunctionFieldToBitNumber(MOVCI) | |
| 908 FunctionFieldToBitNumber(SELEQZ_S) | FunctionFieldToBitNumber(SELNEZ_S); |
| 909 |
| 910 |
861 // Get the encoding type of the instruction. | 911 // Get the encoding type of the instruction. |
862 Type InstructionType() const; | 912 inline Type InstructionType(TypeChecks checks = NORMAL) const; |
863 | |
864 | 913 |
865 // Accessors for the different named fields used in the MIPS encoding. | 914 // Accessors for the different named fields used in the MIPS encoding. |
866 inline Opcode OpcodeValue() const { | 915 inline Opcode OpcodeValue() const { |
867 return static_cast<Opcode>( | 916 return static_cast<Opcode>( |
868 Bits(kOpcodeShift + kOpcodeBits - 1, kOpcodeShift)); | 917 Bits(kOpcodeShift + kOpcodeBits - 1, kOpcodeShift)); |
869 } | 918 } |
870 | 919 |
871 inline int RsValue() const { | 920 inline int RsValue() const { |
872 DCHECK(InstructionType() == kRegisterType || | 921 DCHECK(InstructionType() == kRegisterType || |
873 InstructionType() == kImmediateType); | 922 InstructionType() == kImmediateType); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 const int kCArgSlotCount = 4; | 1086 const int kCArgSlotCount = 4; |
1038 const int kCArgsSlotsSize = kCArgSlotCount * Instruction::kInstrSize; | 1087 const int kCArgsSlotsSize = kCArgSlotCount * Instruction::kInstrSize; |
1039 const int kInvalidStackOffset = -1; | 1088 const int kInvalidStackOffset = -1; |
1040 // JS argument slots size. | 1089 // JS argument slots size. |
1041 const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize; | 1090 const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize; |
1042 // Assembly builtins argument slots size. | 1091 // Assembly builtins argument slots size. |
1043 const int kBArgsSlotsSize = 0 * Instruction::kInstrSize; | 1092 const int kBArgsSlotsSize = 0 * Instruction::kInstrSize; |
1044 | 1093 |
1045 const int kBranchReturnOffset = 2 * Instruction::kInstrSize; | 1094 const int kBranchReturnOffset = 2 * Instruction::kInstrSize; |
1046 | 1095 |
| 1096 |
| 1097 Instruction::Type Instruction::InstructionType(TypeChecks checks) const { |
| 1098 if (checks == EXTRA) { |
| 1099 if (OpcodeToBitNumber(OpcodeFieldRaw()) & kOpcodeImmediateTypeMask) { |
| 1100 return kImmediateType; |
| 1101 } |
| 1102 } |
| 1103 switch (OpcodeFieldRaw()) { |
| 1104 case SPECIAL: |
| 1105 if (checks == EXTRA) { |
| 1106 if (FunctionFieldToBitNumber(FunctionFieldRaw()) & |
| 1107 kFunctionFieldRegisterTypeMask) { |
| 1108 return kRegisterType; |
| 1109 } else { |
| 1110 return kUnsupported; |
| 1111 } |
| 1112 } else { |
| 1113 return kRegisterType; |
| 1114 } |
| 1115 break; |
| 1116 case SPECIAL2: |
| 1117 switch (FunctionFieldRaw()) { |
| 1118 case MUL: |
| 1119 case CLZ: |
| 1120 return kRegisterType; |
| 1121 default: |
| 1122 return kUnsupported; |
| 1123 } |
| 1124 break; |
| 1125 case SPECIAL3: |
| 1126 switch (FunctionFieldRaw()) { |
| 1127 case INS: |
| 1128 case EXT: |
| 1129 return kRegisterType; |
| 1130 case BSHFL: { |
| 1131 int sa = SaFieldRaw() >> kSaShift; |
| 1132 switch (sa) { |
| 1133 case BITSWAP: |
| 1134 return kRegisterType; |
| 1135 case WSBH: |
| 1136 case SEB: |
| 1137 case SEH: |
| 1138 return kUnsupported; |
| 1139 } |
| 1140 sa >>= kBp2Bits; |
| 1141 switch (sa) { |
| 1142 case ALIGN: |
| 1143 return kRegisterType; |
| 1144 default: |
| 1145 return kUnsupported; |
| 1146 } |
| 1147 } |
| 1148 default: |
| 1149 return kUnsupported; |
| 1150 } |
| 1151 break; |
| 1152 case COP1: // Coprocessor instructions. |
| 1153 switch (RsFieldRawNoAssert()) { |
| 1154 case BC1: // Branch on coprocessor condition. |
| 1155 case BC1EQZ: |
| 1156 case BC1NEZ: |
| 1157 return kImmediateType; |
| 1158 default: |
| 1159 return kRegisterType; |
| 1160 } |
| 1161 break; |
| 1162 case COP1X: |
| 1163 return kRegisterType; |
| 1164 |
| 1165 // 26 bits immediate type instructions. e.g.: j imm26. |
| 1166 case J: |
| 1167 case JAL: |
| 1168 return kJumpType; |
| 1169 |
| 1170 default: |
| 1171 if (checks == NORMAL) { |
| 1172 return kImmediateType; |
| 1173 } else { |
| 1174 return kUnsupported; |
| 1175 } |
| 1176 } |
| 1177 } |
| 1178 |
| 1179 #undef OpcodeToBitNumber |
| 1180 #undef FunctionFieldToBitNumber |
1047 } } // namespace v8::internal | 1181 } } // namespace v8::internal |
1048 | 1182 |
1049 #endif // #ifndef V8_MIPS_CONSTANTS_H_ | 1183 #endif // #ifndef V8_MIPS_CONSTANTS_H_ |
OLD | NEW |