Skip to content

Commit

Permalink
Address region isolation, part 3 (of 3)
Browse files Browse the repository at this point in the history
If an address resolves to a user label in an isolated region, we
don't want to use it.  However, we still want to try to match it
to a project/platform symbol.

For example, suppose the isolated code wants to reference address
$1C00, which is a memory-mapped I/O location in one area, but a
regular bunch of code in the other.  We don't want it to map to
the regular code, but we do want it to resolve to our table of
platform I/O addresses.

We now handle this correctly.  The regression test has been updated
to check this.  The current implementation does a linear scan through
the symbol table, but I'm hoping this is not a common situation.

The reference manual has been updated to describe the new feature.
  • Loading branch information
fadden committed May 21, 2024
1 parent e137db2 commit 7a7ff44
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 101 deletions.
18 changes: 11 additions & 7 deletions SourceGen/DisasmProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,12 +1445,12 @@ private void GeneratePlatformSymbolRefs() {
//
// It might seem unwise to examine the full symbol table, because it has
// non-project non-platform symbols in it. However, any matching user
// labels would have been applied already. Also, we want to ensure that
// conflicting user labels take precedence, e.g. creating a user label "COUT"
// will prevent a platform symbol with the same name from being visible.
// Using the full symbol table is potentially a tad less efficient than
// looking for a match exclusively in project/platform symbols, but it's
// the correct thing to do.
// labels would have been applied already (unless blocked by address region
// isolation). Also, we want to ensure that conflicting user labels take
// precedence, e.g. creating a user label "COUT" will prevent a platform
// symbol with the same name from being visible. Using the full symbol
// table is potentially a tad less efficient than looking for a match
// exclusively in project/platform symbols, but it's the correct thing to do.
OpDef op = CpuDef.GetOpDef(FileData[offset]);
accType = op.MemEffect;
address = attr.OperandAddress;
Expand Down Expand Up @@ -1508,7 +1508,11 @@ private void GeneratePlatformSymbolRefs() {
} else {
Debug.WriteLine("GeneratePlatform not applying at +" +
offset.ToString("x6") + ": " + sym);
sym = null;
// Do a secondary scan, looking only at project/platform/pre-labels.
sym = SymbolTable.FindProjPlatPreByAddress(address, accType);
if (sym != null) {
Debug.WriteLine(" ...found matching proj/plat: " + sym);
}
}
}

Expand Down
Binary file modified SourceGen/SGTestData/20290-region-isolation
Binary file not shown.
94 changes: 92 additions & 2 deletions SourceGen/SGTestData/20290-region-isolation.dis65
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"_ContentVersion":6,
"FileDataLength":1537,
"FileDataCrc32":950074699,
"FileDataCrc32":-1543685807,
"ProjectProps":{
"CpuName":"6502",
"IncludeUndocumentedInstr":false,
Expand All @@ -21,7 +21,90 @@
"PlatformSymbolFileIdentifiers":[],
"ExtensionScriptFileIdentifiers":[],
"ProjectSyms":{
}},
"IN_1":{
"DataDescriptor":{
"Length":256,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},

"Comment":"",
"HasWidth":true,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"IN_1",
"Value":36864,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"},

"IN_2":{
"DataDescriptor":{
"Length":256,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},

"Comment":"",
"HasWidth":true,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"IN_2",
"Value":40960,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"},

"IN_3":{
"DataDescriptor":{
"Length":256,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},

"Comment":"",
"HasWidth":true,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"IN_3",
"Value":45056,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"},

"IN_4":{
"DataDescriptor":{
"Length":256,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},

"Comment":"",
"HasWidth":true,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"IN_4",
"Value":49152,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"},

"THREE_K":{
"DataDescriptor":{
"Length":1,
"Format":"NumericLE",
"SubFormat":"Hex",
"SymbolRef":null},

"Comment":"project symbol test",
"HasWidth":false,
"Direction":"ReadWrite",
"MultiMask":null,
"Label":"THREE_K",
"Value":12288,
"Source":"Project",
"Type":"ExternalAddr",
"LabelAnno":"None"}}},

"AddressMap":[{
"Offset":0,
Expand Down Expand Up @@ -303,6 +386,13 @@
"Value":2072,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"},

"1319":{
"Label":"_checkit",
"Value":49166,
"Source":"User",
"Type":"GlobalAddr",
"LabelAnno":"None"}},

"OperandFormats":{
Expand Down
54 changes: 36 additions & 18 deletions SourceGen/SGTestData/Expected/20290-region-isolation_64tass.S
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
.cpu "6502"
THREE_K = $3000 ;project symbol test
IN_1 = $9000
IN_2 = $a000
IN_3 = $b000
IN_4 = $c000

* = $0800
jsr region1
jsr region2
jsr $3000
jsr THREE_K
jsr $4000
lda inner1
lda inner2
lda $b000
lda $c000
lda L9005
lda LA008
lda IN_3+11
lda IN_4+14
self .byte $ad,$ea
L081A nop
jsr altbnk1
jsr altbnk2
jmp done

altbnk1 bit $c080
altbnk1 bit $ffc0
lda self+1
bne L081A
rts

.logical *+$0000
altbnk2 bit $c080
altbnk2 bit $ffc0
lda $0819
bne $081a
ldx $081b
Expand Down Expand Up @@ -106,7 +112,7 @@ inner1_pre
.logical $9000
inner1 ldx inner1
ldy #$aa
ldy finish1
L9005 ldy finish1
ldy finish2
ldy $302b
ldy $402b
Expand All @@ -116,12 +122,12 @@ inner1 ldx inner1
finish1 ldy finish1
ldx region1
ldx region2
ldx $3000
ldx THREE_K
ldx $4000
lda inner1
lda inner2
lda $b000
lda $c000
lda IN_3
lda IN_4
pla
rts

Expand All @@ -146,7 +152,7 @@ inner2_pre
inner2 ldx inner2
ldy #$aa
ldy $102b
ldy finish2
LA008 ldy finish2
ldy $302b
ldy $402b
rts
Expand All @@ -155,12 +161,16 @@ inner2 ldx inner2
finish2 ldy finish2
ldx $1000
ldx region2
ldx $3000
ldx THREE_K
ldx $4000
lda IN_1
lda inner2
lda IN_3
lda IN_4
pla
rts

.fill 196,$00
.fill 184,$00
.here

.logical $3000
Expand Down Expand Up @@ -192,10 +202,14 @@ finish3 ldy finish3
ldx region2
ldx region3
ldx $4000
lda inner1
lda inner2
lda inner3
lda IN_4
pla
rts

.fill 196,$00
.fill 184,$00
.here

.logical $4000
Expand All @@ -218,19 +232,23 @@ inner4 ldx inner4
ldy $102b
ldy $202b
ldy $302b
ldy finish4
X_checkit ldy finish4
rts

.here
finish4 ldy finish4
ldx $1000
ldx $2000
ldx $3000
ldx THREE_K
ldx region4
lda IN_1
lda IN_2
lda IN_3
lda inner4
pla
rts

.fill 196,$00
.fill 184,$00
.here
.logical $0000
.byte $ff
Expand Down
Loading

0 comments on commit 7a7ff44

Please sign in to comment.