Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6642: Corrected disassembly of HCS-H12 BRN instruction

ghidorahrex21a825a05d7a
diff --git a/Ghidra/Processors/HCS12/data/languages/HCS_HC12.sinc b/Ghidra/Processors/HCS12/data/languages/HCS_HC12.sinc
index 26ff2c0eaa..646d9d4eca 100644
--- a/Ghidra/Processors/HCS12/data/languages/HCS_HC12.sinc
+++ b/Ghidra/Processors/HCS12/data/languages/HCS_HC12.sinc
@@ -271,7 +271,7 @@ macro setHCSphysPage(addr) {
(zext(isPpage) * (0x400000 | ((zext(PPAGE) << 14 ) ^ 0x8000))) +
(zext(isPpage_FF) * (0x400000 | ((0x3FC000) ^ 0xC000))) ;
}
-@elif defined(HCS12) && SIZE=="3"
+@elif defined(HCS12) && SIZE=="3"
macro setHCSphysPage(addr) {
local a3:3 = zext(addr);
@@ -1961,11 +1961,9 @@ with : XGATE=0 {
}
# branch never is a two-byte nop
-SkipNextInstr: dest is epsilon [ dest = inst_next + 1; ] { export *[RAM]:1 dest; }
-:BRN SkipNextInstr is Prefix18=0 & op8=0x21 & SkipNextInstr
+:BRN rel8 is Prefix18=0 & op8=0x21; rel8
{
- goto SkipNextInstr;
}
:BRSET opr8a_8, msk8, rel8 is Prefix18=0 & op8=0x4E; opr8a_8; msk8; rel8
diff --git a/Ghidra/Processors/HCS12/src/main/java/ghidra/app/plugin/core/analysis/HCS12ConventionAnalyzer.java b/Ghidra/Processors/HCS12/src/main/java/ghidra/app/plugin/core/analysis/HCS12ConventionAnalyzer.java
index b2c0f2f61a..79d649fd1f 100644
--- a/Ghidra/Processors/HCS12/src/main/java/ghidra/app/plugin/core/analysis/HCS12ConventionAnalyzer.java
+++ b/Ghidra/Processors/HCS12/src/main/java/ghidra/app/plugin/core/analysis/HCS12ConventionAnalyzer.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -53,8 +53,8 @@ public class HCS12ConventionAnalyzer extends AbstractAnalyzer {
public boolean canAnalyze(Program program) {
// Only analyze HCS12 Programs
Processor processor = program.getLanguage().getProcessor();
-
- boolean canDo = processor.equals(Processor.findOrPossiblyCreateProcessor("HCS12"));
+ String procName = processor.toString();
+ boolean canDo = "HCS-12".equals(procName) || "HCS-12X".equals(procName);
if (canDo) {
xgate = program.getRegister("XGATE");
}
@@ -63,12 +63,13 @@ public class HCS12ConventionAnalyzer extends AbstractAnalyzer {
}
void checkReturn(Program program, Instruction instr) {
- String mnemonic = instr.getMnemonicString().toLowerCase();
if (instr == null || !instr.getFlowType().isTerminal()) {
return;
}
+ String mnemonic = instr.getMnemonicString().toLowerCase();
+
// if XGATE set on instruction is XGATE
RegisterValue xgateValue = program.getProgramContext().getRegisterValue(xgate, instr.getMinAddress());
if (xgateValue != null && xgateValue.hasValue() && xgateValue.getUnsignedValue().equals(BigInteger.ONE)) {