From f1fc3a29caca835ec09b3e67257405742ee785a3 Mon Sep 17 00:00:00 2001 From: VGKintsugi <7758500+VGKintsugi@users.noreply.github.com> Date: Thu, 25 Mar 2021 02:08:22 -0400 Subject: [PATCH] SuperH: Delay slot fix for bf/s and and bt/s Code now caches the value of the $(T_FLAG) before executing the delay slot. Previously the instruction executed in delay slot could potentially change the value of $(T_FLAG) and thereby resulting in incorrect behavior. Credit to Slinga and Waterfuell from SegaXtreme for reporting the issue. --- Ghidra/Processors/SuperH/data/languages/superh.sinc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Ghidra/Processors/SuperH/data/languages/superh.sinc b/Ghidra/Processors/SuperH/data/languages/superh.sinc index ee7e5a7c41..417d55c8fd 100644 --- a/Ghidra/Processors/SuperH/data/languages/superh.sinc +++ b/Ghidra/Processors/SuperH/data/languages/superh.sinc @@ -1653,8 +1653,9 @@ MovMUReg2: MovMUReg2_15 is MovMUReg2_15 { @if (SH_VERSION == "2") || (SH_VERSION == "2A") :bf"/s" target00_07 is opcode_08_15=0b10001111 & target00_07 { + local cond = $(T_FLAG); delayslot(1); - if ($(T_FLAG)==0) goto target00_07; + if (cond==0) goto target00_07; } @endif @@ -1666,8 +1667,9 @@ MovMUReg2: MovMUReg2_15 is MovMUReg2_15 { @if (SH_VERSION == "2") || (SH_VERSION == "2A") :bt"/s" target00_07 is opcode_08_15=0b10001101 & target00_07 { + local cond = $(T_FLAG); delayslot(1); - if ($(T_FLAG)==1) goto target00_07; + if (cond==1) goto target00_07; } @endif