1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-26 06:49:19 +00:00

Fix handling of data formatting that overlaps with code

If you play games with code hints you can create a data operand that
overlaps with code.  This causes problems (see issue #45).  We now
check for that situation and ignore overlapping data descriptors.

Added a regression test to 2011-hinting.
This commit is contained in:
Andy McFadden 2019-09-14 11:40:32 -07:00
parent e7d693bae2
commit 62b7655a1c
10 changed files with 89 additions and 19 deletions

View File

@ -858,6 +858,31 @@ namespace SourceGen {
genLog.LogW("+" + offset.ToString("x6") +
": unexpected mid-instruction format descriptor");
continue; // ignore this one
} else {
// Data or inline data. The data analyzer hasn't run yet. We want to
// confirm that the descriptor doesn't overlap with code.
//
// Data descriptors that overlap code are problematic, for two reasons.
// First, we end up with references to hidden labels, because the code that
// tries to prevent it sees an Anattrib with code at the target address and
// assumes all is well. Second, if the overlap ends partway into an
// instruction, an Anattrib-walker will move from a data region to the middle
// of an instruction, which should never happen.
//
// All instruction bytes have been marked, so we just need to confirm that
// none of the bytes spanned by this descriptor are instructions.
bool overlap = false;
for (int i = offset; i < offset + kvp.Value.Length; i++) {
if (mAnattribs[i].IsInstruction) {
genLog.LogW("+" + offset.ToString("x6") +
": data format descriptor overlaps code at +" + i.ToString("x6"));
overlap = true;
break;
}
}
if (overlap) {
continue;
}
}
mAnattribs[offset].DataDescriptor = kvp.Value;

View File

@ -16,11 +16,13 @@
<h1>$ProjectName$ Disassembly</h1>
<div id="code-lines">
<!-- The CodeLines marker is not optional, and may only appear once -->
$CodeLines$
</div>
<h2>Symbol Table</h2>
<!-- SymbolTable is optional; remove this entire section from the template if you don't want it -->
<div id="symbol-table">
<h2>Symbol Table</h2>
$SymbolTable$
</div>
</body>

View File

@ -1,2 +1,2 @@
,,<2C><11>,<2C><><EFBFBD>
ę,˘˙ę  V$Š˘"  ( V$Š3˘D 7 :ę­V$` V$ŠU˘f`
ę,˘˙ę  V$©˘"  ( V$©3˘D : =ę­V$ E` V$©U˘f`<60><EFBFBD>©™`

View File

@ -1,8 +1,8 @@
### 6502bench SourceGen dis65 v1.0 ###
{
"_ContentVersion":1,"FileDataLength":63,"FileDataCrc32":977869194,"ProjectProps":{
"CpuName":"6502","IncludeUndocumentedInstr":false,"EntryFlags":33489103,"AnalysisParams":{
"AnalyzeUncategorizedData":true,"MinCharsForString":4,"SeekNearbyTargets":true},
"_ContentVersion":2,"FileDataLength":72,"FileDataCrc32":-800253778,"ProjectProps":{
"CpuName":"6502","IncludeUndocumentedInstr":false,"EntryFlags":33489103,"AutoLabelStyle":"Simple","AnalysisParams":{
"AnalyzeUncategorizedData":true,"DefaultTextScanMode":"LowHighAscii","MinCharsForString":4,"SeekNearbyTargets":true,"SmartPlpHandling":true},
"PlatformSymbolFileIdentifiers":[],"ExtensionScriptFileIdentifiers":["PROJ:2011-hinting.cs"],"ProjectSyms":{
}},
"AddressMap":[{
@ -27,4 +27,8 @@
},
"OperandFormats":{
"51":{
"Length":3,"Format":"Dense","SubFormat":"None","SymbolRef":null}}}
"Length":3,"Format":"Dense","SubFormat":"None","SymbolRef":null},
"66":{
"Length":4,"Format":"NumericLE","SubFormat":"Hex","SymbolRef":null}},
"LvTables":{
}}

View File

@ -22,14 +22,22 @@ L101B .dword $22a211a9
jsr L1028
jsr $2456
L1028 .dword $44a233a9
jsr L1037
jsr L103A
jsr L103D
nop
lda $2456
jsr L1045
rts
L1037 jsr $2456
L103A lda #$55
L103A jsr $2456
L103D lda #$55
ldx #$66
rts
.byte $81
.byte $82
.byte $83
L1045 lda #$99
rts

View File

@ -21,14 +21,22 @@ L101B adrl $22a211a9
jsr L1028
jsr $2456
L1028 adrl $44a233a9
jsr L1037
jsr L103A
jsr L103D
nop
lda $2456
jsr L1045
rts
L1037 jsr $2456
L103A lda #$55
L103A jsr $2456
L103D lda #$55
ldx #$66
rts
dfb $81
dfb $82
dfb $83
L1045 lda #$99
rts

View File

@ -22,14 +22,22 @@ L101B !32 $22a211a9
jsr L1028
jsr $2456
L1028 !32 $44a233a9
jsr L1037
jsr L103A
jsr L103D
nop
lda $2456
jsr L1045
rts
L1037 jsr $2456
L103A lda #$55
L103A jsr $2456
L103D lda #$55
ldx #$66
rts
!byte $81
!byte $82
!byte $83
L1045 lda #$99
rts

View File

@ -23,14 +23,22 @@ L101B: .dword $22a211a9
jsr L1028
jsr $2456
L1028: .dword $44a233a9
jsr L1037
jsr L103A
jsr L103D
nop
lda $2456
jsr L1045
rts
L1037: jsr $2456
L103A: lda #$55
L103A: jsr $2456
L103D: lda #$55
ldx #$66
rts
.byte $81
.byte $82
.byte $83
L1045: lda #$99
rts

View File

@ -1,7 +1,7 @@
# 6502bench SourceGen generated linker script for 2011-hinting
MEMORY {
MAIN: file=%O, start=%S, size=65536;
# MEM000: file=%O, start=$1000, size=63;
# MEM000: file=%O, start=$1000, size=72;
}
SEGMENTS {
CODE: load=MAIN, type=rw;

View File

@ -51,6 +51,8 @@ magic33 lda #$33
lda MAGIC ;EDIT: hint as data, format as dense hex, remove hint
jsr dataolap
rts
@ -59,3 +61,8 @@ part2 lda #$55
ldx #$66
rts
; Make sure that data descriptors that overlap with code are ignored.
hex 818283 ;EDIT: format as 4-byte int, so it overlaps with dataolap
dataolap lda #$99
rts