diff --git a/Ghidra/Processors/MIPS/data/languages/mips.sinc b/Ghidra/Processors/MIPS/data/languages/mips.sinc index f039573cf0..6f0a6d40ae 100755 --- a/Ghidra/Processors/MIPS/data/languages/mips.sinc +++ b/Ghidra/Processors/MIPS/data/languages/mips.sinc @@ -369,7 +369,9 @@ define register offset=0x3200 size=$(REGSIZE) [ HW_RES28 HW_ULR HW_RESIM30 HW_RESIM31 ]; +@ifdef ISA_VARIANT define register offset=0x3F00 size=1 [ ISAModeSwitch ]; +@endif # Define context bits define register offset=0x4000 size=4 contextreg; @@ -798,12 +800,14 @@ DXuPos: pos is lsb [ pos = lsb + 32; ] { tmp:1 DinsXSize: mysize is msbd & lsb [ mysize = msbd - lsb + 1 + 32; ] { tmp:1 = mysize; export tmp; } @endif +@ifdef ISA_VARIANT macro JXWritePC(addr) { ISAModeSwitch = (addr & 0x1) != 0; tmp:$(REGSIZE) = -2; tmp = tmp & addr; pc = tmp; } +@endif # Floating point formats #fmt: "S" is format=0x10 { } diff --git a/Ghidra/Processors/MIPS/src/main/java/ghidra/program/emulation/MIPSEmulateInstructionStateModifier.java b/Ghidra/Processors/MIPS/src/main/java/ghidra/program/emulation/MIPSEmulateInstructionStateModifier.java index 5301e44638..a47332f564 100644 --- a/Ghidra/Processors/MIPS/src/main/java/ghidra/program/emulation/MIPSEmulateInstructionStateModifier.java +++ b/Ghidra/Processors/MIPS/src/main/java/ghidra/program/emulation/MIPSEmulateInstructionStateModifier.java @@ -37,14 +37,17 @@ public class MIPSEmulateInstructionStateModifier extends EmulateInstructionState public MIPSEmulateInstructionStateModifier(Emulate emu) { super(emu); - ismReg = language.getRegister("ISAModeSwitch"); isaModeReg = language.getRegister("ISA_MODE"); - if (ismReg == null || isaModeReg == null) { - throw new RuntimeException("Expected language " + language.getLanguageID() + - " to have ISM and ISA_MODE registers defined"); + if (isaModeReg != null) { + ismReg = language.getRegister("ISAModeSwitch"); + if (ismReg == null) { + throw new RuntimeException( + "Expected ISA_VARIANT language " + language.getLanguageID() + + " to have ISAModeSwitch register defined"); + } + ISA_MODE1 = new RegisterValue(isaModeReg, BigInteger.ONE); + ISA_MODE0 = new RegisterValue(isaModeReg, BigInteger.ZERO); } - ISA_MODE1 = new RegisterValue(isaModeReg, BigInteger.ONE); - ISA_MODE0 = new RegisterValue(isaModeReg, BigInteger.ZERO); // These classes are defined here: // ghidra/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcode/emulate/callother @@ -79,6 +82,9 @@ public class MIPSEmulateInstructionStateModifier extends EmulateInstructionState @Override public void initialExecuteCallback(Emulate emulate, Address current_address, RegisterValue contextRegisterValue) throws LowlevelError { + if (ismReg == null) { + return; + } BigInteger isaModeValue = BigInteger.ZERO; if (contextRegisterValue != null) { isaModeValue = @@ -102,6 +108,9 @@ public class MIPSEmulateInstructionStateModifier extends EmulateInstructionState public void postExecuteCallback(Emulate emulate, Address lastExecuteAddress, PcodeOp[] lastExecutePcode, int lastPcodeIndex, Address currentAddress) throws LowlevelError { + if (ismReg == null) { + return; + } if (lastPcodeIndex < 0) { // ignore fall-through condition return;