GP-2366 handle MIPS emulation when ISA_VARIANT not enabled

This commit is contained in:
ghidra1 2022-07-25 16:25:30 -04:00
parent 590d74f2e9
commit 062551ae9a
2 changed files with 19 additions and 6 deletions

View file

@ -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 { }

View file

@ -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;