1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-09-30 00:56:56 +00:00

6809: Fix writing through pointers

This commit is contained in:
Karol Stasiak 2020-06-09 22:56:16 +02:00
parent a947946313
commit 2d19537ed3
4 changed files with 24 additions and 18 deletions

View File

@ -617,7 +617,7 @@ object M6809ExpressionCompiler extends AbstractExpressionCompiler[MLine] {
val variable = ctx.env.get[Variable](name)
List(MLine.variable(ctx, STB, variable))
case DerefExpression(inner, offset, _) =>
compileToX(ctx, inner) :+ MLine.indexedX(STB, NumericConstant(offset, 2))
stashBIfNeeded(ctx, compileToX(ctx, inner)) :+ MLine.indexedX(STB, NumericConstant(offset, 2))
case IndexedExpression(name, index) =>
ctx.env.getPointy(name) match {
case p: ConstantPointy =>
@ -639,7 +639,9 @@ object M6809ExpressionCompiler extends AbstractExpressionCompiler[MLine] {
v.indexType.size match {
case 1 | 2 =>
stashBIfNeeded(ctx,
compileToD(ctx, index) :+ MLine(LEAX, DAccumulatorIndexed(M6809Register.X, indirect = false), Constant.Zero)) :+
MLine.absolute(LDX, v.addr) ::
(compileToD(ctx, index) :+
MLine(LEAX, DAccumulatorIndexed(M6809Register.X, indirect = false), Constant.Zero))) :+
MLine.indexedX(STB, Constant.Zero)
}
}

View File

@ -10,7 +10,7 @@ import org.scalatest.{AppendedClues, FunSuite, Matchers}
class PointerSuite extends FunSuite with Matchers with AppendedClues {
test("Pointers outside zeropage") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| pointer p @$c004
| array output[2] @$c000
@ -25,7 +25,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Pointers on stack") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| array output[2] @$c000
| void main() {
@ -40,7 +40,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Typed byte-targeting pointers") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| enum e {}
| array(e) output [3] @$c000
@ -57,7 +57,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Typed word-targeting pointers") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| word output @$c000
| void main() {
@ -130,7 +130,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Pointer optimization") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| struct s { word a, byte b }
|
@ -154,7 +154,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("nullptr") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086)(
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| void main() {
| pointer.word pw
@ -171,7 +171,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
test("Complex pointers") {
// TODO: optimize it when inlined
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| array output[3] @$c000
| struct s {
@ -193,7 +193,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Indexing returned pointers") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8086, Cpu.Motorola6809)(
"""
| array output[10] @$c000
| pointer get() = output.addr
@ -211,7 +211,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Pointers and arrays") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| struct P {
| word i
@ -233,7 +233,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Pointers and arrays to large elements") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| struct P {
| word i
@ -255,7 +255,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Page crossing with arrays of large elements") {
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80)(
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
| import zp_reg
| struct P {
@ -287,7 +287,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Word pointers") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080) (
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Motorola6809) (
"""
|pointer.word p
|word output @$c000
@ -304,7 +304,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Word pointers and byte-to-word promotions") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080) (
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Intel8080, Cpu.Motorola6809) (
"""
|pointer.word p
|word output @$c000
@ -324,7 +324,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Fast pointer indexing") {
EmuUnoptimizedCrossPlatformRun(Cpu.Mos) (
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Motorola6809) (
"""
|pointer.word p
|array(word) input [6]
@ -341,7 +341,7 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
}
test("Modifying a word via a pointer") {
EmuUnoptimizedCrossPlatformRun(/*Cpu.Mos, Cpu.Z80,*/ Cpu.Motorola6809)(
EmuUnoptimizedCrossPlatformRun(Cpu.Mos, Cpu.Z80, Cpu.Motorola6809)(
"""
|word output @$c000
|void main () {

View File

@ -94,6 +94,8 @@ class EmuM6809Run(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimizat
CompilationFlag.SubroutineExtraction -> optimizeForSize,
CompilationFlag.OptimizeForSize -> optimizeForSize,
CompilationFlag.OptimizeForSpeed -> blastProcessing,
// CompilationFlag.SourceInAssembly -> true,
// CompilationFlag.LineNumbersInAssembly -> true,
CompilationFlag.OptimizeForSonicSpeed -> blastProcessing
// CompilationFlag.CheckIndexOutOfBounds -> true,
), None, 0, Map(), EmuPlatform.textCodecRepository, JobContext(log, new LabelGenerator))
@ -141,7 +143,7 @@ class EmuM6809Run(cpu: millfork.Cpu.Value, nodeOptimizations: List[NodeOptimizat
// compile
val env2 = new Environment(None, "", CpuFamily.M6502, options)
val env2 = new Environment(None, "", CpuFamily.M6809, options)
env2.collectDeclarations(program, options)
val assembler = new M6809Assembler(program, env2, platform)
val output = assembler.assemble(callGraph, assemblyOptimizations, options, VeryLateM6809AssemblyOptimizations.All)

View File

@ -30,6 +30,8 @@ class M6809Memory(memoryBank: MemoryBank, resetVector: Int) extends MemorySegmen
override def store(addr: Int, `val`: Int): Unit = {
if (!memoryBank.writeable(addr)) {
val start = addr & 0xff00
(0 until 0x100).grouped(16).map(range => (start + range.head).toHexString + range.map(i => memoryBank.output(start + i)).map(v => f" $v%02X").mkString("")).foreach(println)
println(s"Accessing memory for write at $$${addr.toHexString}, writing $$${`val`.toHexString}")
???
}