Skip to content

Commit

Permalink
Fix: various problems causing #1236
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Mar 31, 2023
1 parent 949258f commit e5a8a2b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/Arch/Padauk/PadaukRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public IEnumerator<RtlInstructionCluster> GetEnumerator()
case Mnemonic.sl: RewriteShift(m.Shl); break;
case Mnemonic.slc: RewriteSlc(); break;
case Mnemonic.sr: RewriteShift(m.Shr); break;
case Mnemonic.stopexe: RewriteStopexe(); break;
case Mnemonic.sub: RewriteAddSub(m.ISub); break;
case Mnemonic.subc: RewriteAddcSubc(m.ISubC, m.ISub); break;
case Mnemonic.swap: RewriteSwap();break;
case Mnemonic.swap: RewriteSwap(); break;
case Mnemonic.t0sn: RewriteTsn(true); break;
case Mnemonic.t1sn: RewriteTsn(false); break;
case Mnemonic.xch: RewriteXch(); break;
Expand Down Expand Up @@ -332,7 +333,7 @@ private void RewriteSetBit(Constant value, IntrinsicProcedure intrinsic)
}
else
{
var mem = (MemoryOperand)instr.Operands[0];
var mem = (MemoryOperand) instr.Operands[0];
var tmp = binder.CreateTemporary(PrimitiveType.Byte);
var ea = m.Ptr16((ushort) mem.Offset);
m.Assign(tmp, m.Mem8(ea));
Expand All @@ -347,6 +348,11 @@ private void RewriteShift(Func<Expression, Expression, Expression> shift)
EmitCc(Registers.C, dst);
}

private void RewriteStopexe()
{
m.SideEffect(m.Fn(stopexe_instrinsic));
}

private Expression Rolc(Expression a, Expression b)
{
var C = binder.EnsureFlagGroup(Registers.C);
Expand Down Expand Up @@ -433,6 +439,9 @@ private void SkipIf(Expression cond)
.Param(PrimitiveType.Bool)
.Void();

private static readonly IntrinsicProcedure stopexe_instrinsic = new IntrinsicBuilder("__stopexe", true)
.Void();

private static readonly IntrinsicProcedure swap_intrinsic = new IntrinsicBuilder("__swap_nybbles", false)
.Param(PrimitiveType.Byte)
.Returns(PrimitiveType.Byte);
Expand Down
18 changes: 11 additions & 7 deletions src/Drivers/CmdLine/CmdLineDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public static bool OverridesRequested(Dictionary<string,object> pArgs)
// User must supply these arguments for a meaningful
// decompilation.
if (pArgs.ContainsKey("--arch") &&
pArgs.ContainsKey("--base") &&
(pArgs.ContainsKey("filename") || pArgs.ContainsKey("--data")))
{
return true;
Expand Down Expand Up @@ -319,14 +318,19 @@ private void DecompileRawImage(Dictionary<string, object> pArgs)
{
try
{
var arch = config.GetArchitecture((string) pArgs["--arch"]);
if (arch is null)
throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));
Dictionary<string, object> archOptions;
if (pArgs.TryGetValue("--arch-options", out var oArchOptions))
{
var archOptions = (Dictionary<string, object>) oArchOptions;
arch.LoadUserOptions(archOptions);
archOptions = (Dictionary<string, object>) oArchOptions;
}
else
{
archOptions = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}
var arch = config.GetArchitecture((string) pArgs["--arch"], archOptions);
if (arch is null)
throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));

pArgs.TryGetValue("--env", out object sEnv);

if (!pArgs.TryGetValue("--base", out var oAddrBase))
Expand All @@ -347,7 +351,7 @@ private void DecompileRawImage(Dictionary<string, object> pArgs)
: null,
LoaderName = (string) sLoader,
ArchitectureName = (string) pArgs["--arch"],
ArchitectureOptions = null, //$TODO: How do we handle options for command line?
ArchitectureOptions = archOptions,
PlatformName = (string) sEnv,
LoadAddress = oAddrBase.ToString(),
EntryPoint = new EntryPointDefinition { Address = (string) oAddrEntry }
Expand Down
9 changes: 9 additions & 0 deletions src/UnitTests/Arch/Padauk/PDK15/PadaukRewriter_PDK15Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,14 @@ public void Pdk15Rw_xor()
"2|L--|Mem0[0x008A<p16>:byte] = v3",
"3|L--|Z = cond(v3)");
}

[Test]
public void Pdk15Rw_stopexe()
{
Given_HexString("7700");
AssertCode( // stopexe
"0|L--|0100(1): 1 instructions",
"1|L--|__stopexe()");
}
}
}

0 comments on commit e5a8a2b

Please sign in to comment.