From 4639af8b0e5d6ddad7461d1a4155430a2e2f20dd Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 5 Oct 2018 11:10:03 -0700 Subject: [PATCH] Strip single-byte format items on single-byte instructions It's possible to have format descriptors on instructions that are left over from when the bytes were treated as data. Single-byte formats were being allowed on single-byte instructions, which confused things later when the code tried to apply the format to an instruction with no operand. --- SourceGen/DisasmProject.cs | 17 +++++++++++++---- SourceGen/DisplayList.cs | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index e73f15a..b32b77d 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -532,20 +532,29 @@ namespace SourceGen { } if (mAnattribs[offset].IsInstructionStart) { - // Check length for instruction formatters. + // Check length for instruction formatters. This can happen if you format + // a bunch of bytes as single-byte data items and then add a code entry + // point. if (kvp.Value.Length != mAnattribs[offset].Length) { - genLog.LogW("Unexpected length on instr format descriptor (" + + genLog.LogW("+" + offset.ToString("x6") + + ": unexpected length on instr format descriptor (" + kvp.Value.Length + " vs " + mAnattribs[offset].Length + ")"); continue; // ignore this one } + if (kvp.Value.Length == 1) { + // No operand to format! + genLog.LogW("+" + offset.ToString("x6") + + ": unexpected format descriptor on single-byte op"); + continue; // ignore this one + } if (!kvp.Value.IsValidForInstruction) { genLog.LogW("Descriptor not valid for instruction: " + kvp.Value); continue; // ignore this one } } else if (mAnattribs[offset].IsInstruction) { // Mid-instruction format. - genLog.LogW("Unexpected mid-instruction format descriptor at +" + - offset.ToString("x6")); + genLog.LogW("+" + offset.ToString("x6") + + ": unexpected mid-instruction format descriptor"); continue; // ignore this one } diff --git a/SourceGen/DisplayList.cs b/SourceGen/DisplayList.cs index 4d2858e..ba0086f 100644 --- a/SourceGen/DisplayList.cs +++ b/SourceGen/DisplayList.cs @@ -1096,8 +1096,11 @@ namespace SourceGen { operandForSymbol = attr.OperandAddress; } - // Check Length to watch for bogus descriptors (?) + // Check Length to watch for bogus descriptors. ApplyFormatDescriptors() should + // have discarded anything appropriate, so we might be able to eliminate this test. if (attr.DataDescriptor != null && attr.Length == attr.DataDescriptor.Length) { + Debug.Assert(operandLen > 0); + // Format operand as directed. if (op.AddrMode == OpDef.AddressMode.BlockMove) { // Special handling for the double-operand block move.